From: Dave Chinner <david@fromorbit.com>
To: Dmitry Monakhov <dmonakhov@openvz.org>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
jens.axboe@oracle.com
Subject: Re: Direct aio_write/truncate question
Date: Tue, 27 Apr 2010 09:55:03 +1000 [thread overview]
Message-ID: <20100426235503.GA9703@dastard> (raw)
In-Reply-To: <87633hdr6n.fsf@openvz.org>
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
prev parent reply other threads:[~2010-04-26 23:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-24 11:29 Direct aio_write/truncate question Dmitry Monakhov
2010-04-26 23:55 ` Dave Chinner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100426235503.GA9703@dastard \
--to=david@fromorbit.com \
--cc=akpm@linux-foundation.org \
--cc=dmonakhov@openvz.org \
--cc=jens.axboe@oracle.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).