* Direct aio_write/truncate question
@ 2010-04-24 11:29 Dmitry Monakhov
2010-04-26 23:55 ` Dave Chinner
0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Monakhov @ 2010-04-24 11:29 UTC (permalink / raw)
To: linux-kernel, linux-fsdevel; +Cc: Andrew Morton, jens.axboe
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?
Or even corrupt fs because old blocks may be used as metadata now.
Seems unmap_underlying_metadata() can not help us here because async
io context does not dirty or locked any bh because they was already
allocated. Fairly to say. I can not reproduce rewrite effect.
I use ext4 with external journal, so where a io_barriers in fs_dev's
blktrace log.
Seems what rewrite effect no happens only because blklayer does not
reorganized issued requests. But nothing is preventing this right?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Direct aio_write/truncate question
2010-04-24 11:29 Direct aio_write/truncate question Dmitry Monakhov
@ 2010-04-26 23:55 ` Dave Chinner
0 siblings, 0 replies; 2+ messages in thread
From: Dave Chinner @ 2010-04-26 23:55 UTC (permalink / raw)
To: Dmitry Monakhov; +Cc: linux-kernel, linux-fsdevel, Andrew Morton, jens.axboe
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-04-26 23:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-24 11:29 Direct aio_write/truncate question Dmitry Monakhov
2010-04-26 23:55 ` Dave Chinner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).