From: Jiri Olsa <jolsa@redhat.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de,
eric.dumazet@gmail.com, Alexander Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH] time/fs - file's time race with vgettimeofday
Date: Sat, 3 Jul 2010 01:58:36 +0200 [thread overview]
Message-ID: <20100702235836.GA1948@jolsa.Belkin> (raw)
In-Reply-To: <20100702161422.GA31733@redhat.com>
On Fri, Jul 02, 2010 at 06:14:22PM +0200, Oleg Nesterov wrote:
> In no way I can review this patch, but I am curious and have the questions.
> Also, I think it makes sense to cc the fs/ developers, I've added Al.
thanks
>
> On 07/02, Jiri Olsa wrote:
> >
> > there's a race among calling gettimeofday(2) and a file's time
> > updates. Following test program expose the race.
> >
> > run it in the while loop
> > while [ 1 ]; do ./test1 || break; done
> >
> > --- SNIP ---
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <fcntl.h>
> >
> > int main (void)
> > {
> > struct stat st;
> > struct timeval tv;
> >
> > unlink("./file");
> >
> > gettimeofday(&tv, NULL);
> >
> > if (-1 == creat("./file", O_RDWR)) {
> > perror("creat");
> > return -1;
> > }
> >
> > if (stat("./file", &st) != 0) {
> > perror("stat");
> > return -1;
> > }
> >
> > printf("USER gtod: %ld\n", (long)tv.tv_sec);
> > printf("USER file: %ld.%09u\n",
> > (long) st.st_mtime,
> > (unsigned) st.st_mtim.tv_nsec);
> >
> > return tv.tv_sec <= st.st_mtime ? 0 : -1;
> > }
>
> Interesting. To the point, I actually compiled this code and yes,
> it triggers the problem on ext3 ;)
>
> > The following patch will prevent the race by adding the
> > CURRENT_TIME_SEC_REAL macro, which will return seconds from
> > the getnstimeofday call, ensuring it's computed on current tick.
> > It fixes the 'creat' case for ext4.
>
> What about other filesystems? Perhaps it makes sense to change
> CURRENT_TIME_SEC instead of adding CURRENT_TIME_SEC_REAL?
>
> Once again, I am asking. It is not that I suggest to change your patch.
well, the patch is more or less to prove the problem exists and
it could be fixed :) also I'm not sure that all the places using
CURRENT_TIME_SEC suffer the same issue..
I'm currenty looking to the code and trying to come up with better
solution.. any ideas are welcome :)
jirka
next prev parent reply other threads:[~2010-07-02 23:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-02 7:41 [PATCH] time/fs - file's time race with vgettimeofday Jiri Olsa
2010-07-02 16:14 ` Oleg Nesterov
2010-07-02 16:20 ` Oleg Nesterov
2010-07-02 23:58 ` Jiri Olsa [this message]
2010-07-06 23:03 ` john stultz
2010-07-06 23:11 ` john stultz
2010-07-07 10:47 ` Jiri Olsa
2010-07-07 16:20 ` john stultz
2010-07-07 17:11 ` Jiri Olsa
2010-07-07 17:20 ` john stultz
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=20100702235836.GA1948@jolsa.Belkin \
--to=jolsa@redhat.com \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=tglx@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
/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