mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Document file->f_pos as thread-unsafe
@ 2008-10-10 19:17 dcg
  0 siblings, 0 replies; only message in thread
From: dcg @ 2008-10-10 19:17 UTC (permalink / raw)
  To: Nick Piggin
  Cc: Peter Zijlstra, Hisashi Hifumi, torvalds, Andrew Morton,
	Andi Kleen, linux-kernel, linux-fsdevel, Aneesh Kumar K.V,
	Theodore Ts'o

El Fri, 10 Oct 2008 13:25:15 +1100, Nick Piggin <nickpiggin@yahoo.com.au> escribió:

> Note that I don't think we'd want to explicitly guarantee that it is atomic
> on 64-bit machines either. It does happen to be, but I don't think we want
> anybody to rely on that...

Easily fixable. Performance testing of this new version didn't find
regressions.




Document that it is not safe to play with file->f_pos from multiple processes
if they aren't synchronizing themselves.

Signed-off-by: Diego Calleja <diegocg@gmail.com>

Index: 2.6/include/linux/fs.h
===================================================================
--- 2.6.orig/include/linux/fs.h	2008-10-10 21:07:29.000000000 +0200
+++ 2.6/include/linux/fs.h	2008-10-10 21:08:25.000000000 +0200
@@ -821,6 +821,17 @@
 	atomic_long_t		f_count;
 	unsigned int 		f_flags;
 	mode_t			f_mode;
+	/*
+	 * Linux does NOT guarantee atomic reading/writing to file->f_pos in
+	 * multithreaded apps. There're several reasons for this behaviour:
+	 *  - Specifications don't say it must be implemented that way.
+	 *  - This behaviour is part of the Linux semantics.
+	 *  - Any application that does multithreaded access to file->f_pos
+	 *    should be doing its own locking: the processes should synchronize
+	 *    themselves when accessing a file descriptor. If an application
+	 *    doesn't do that, its file descriptor handling is buggy anyway and
+	 *    must be fixed to do its accesses to file->f_pos properly.
+	 */
 	loff_t			f_pos;
 	struct fown_struct	f_owner;
 	unsigned int		f_uid, f_gid;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-10-10 19:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-10 19:17 [PATCH] Document file->f_pos as thread-unsafe dcg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®