[lkml]   [2014]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Update of file offset on write() etc. is non-atomic with I/O
On 03/03/2014 06:36 PM, Linus Torvalds wrote:
> Ok, sorry for the long delay, I was distracted (and hoping that Al
> would come up with a patch).
> Anyway, attached is the patch I think we should do for this issue. It
> is fairly simple:
> - it adds a "f_pos_mutex" to the "struct file".
> - it adds a new FMODE_ATOMIC_POS flag to the file mode flags to mark
> things that need atomic f_pos updates
> - it makes the "struct fd" flags be two flags rather than one: the
> second flag is for "unlock f_pos_mutex when done"
> - it introduces "fd[get,put]_pos()" which gets the f_pos_mutex when required
> - it makes read/write/lseek use that.
> It's pretty damn straightforward, I think, and is minimally serializing.
> Al, comments? Yongzhi Pan, this is pretty much untested, but it's
> pretty simple and it does fix your test-case.

The original code (where Yongzhi Pan reported an issue) and
the multi_writer.c test code where both mine actually. Anyway,
I applied the patch to 3.14-rc5, and I (not withstanding the other
points raised by Al about the patch) I confirm that this patch makes
the problem that I'm seeing go away.

Thanks for looking at this, Linus.



Michael Kerrisk
Linux man-pages maintainer;
Linux/UNIX System Programming Training:

 \ /
  Last update: 2014-03-06 16:41    [W:0.127 / U:1.644 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site