lkml.org 
[lkml]   [2010]   [Apr]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Direct aio_write/truncate question
On Sat, Apr 24, 2010 at 03:29:36PM +0400, Dmitry Monakhov wrote:
> My be my question appeared to obvious for someone, but still
>
> fd = open("a", O_DIRECT, )
> fd2 = open("b", O_DIRECT, )
> write(fd, buf ,size) /* allocate blocks for a file */
> fsync(fd) /* Now, it is guaranteed that blocks are allocated.*/
> /* Submit async rewrite request */
> io_prep_pwrite(io, fd, io->u.c.buf, size, 0);
> io_submit(myctx, 1, io); /* Io is in flight after this */
> /* Ok, truncate the file */
> ftruncate(fd, 0)
> /* Reuse truncated block blocks for a new file */
> write(fd2,buf ,size) /* old a's blocks belongs to b now. */
>
> What protect us from aio request to rewrite content of new file?

The filesystem is supposed to serialise truncate vs write races.
i.e. the truncate will occur either before the write is executed or
after it has completed, not while it is running.

Cheers,

Dave.
--
Dave Chinner
david@fromorbit.com


\
 
 \ /
  Last update: 2010-04-27 01:57    [W:0.269 / U:0.528 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site