public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: tglx@linutronix.de, john.stultz@linaro.org
Cc: dhowells@redhat.com, torvalds@linux-foundation.org,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Apparent backward time travel in timestamps on file creation
Date: Thu, 30 Mar 2017 18:30:07 +0100	[thread overview]
Message-ID: <22214.1490895007@warthog.procyon.org.uk> (raw)

Hi Thomas, John,

I've been writing a testcase for xfstests to test statx.  However, it's turned
up what I think is a bug in the kernel's time-tracking system.  If I do:

	date +%s.%N
	touch foo
	dump-timestamps foo

such that foo is created, sometimes the atime, mtime and ctime timestamps on
foo will be *before* the time printed by 'date'.

For example:

	[root@andromeda ~]# Z=/b/zebra6; date +%s.%N; touch $Z; /tmp/dump-timestamps $Z
	1490894656.267225764
	st_atime: 1490894656.267032686
	st_mtime: 1490894656.267032686
	st_ctime: 1490894656.267032686

As can be seen, the three file timestamps are -193078 nsec from the prior
clock time.  This was with git commit:

	89970a04d70c6c9e5e4492fd4096c0b5630a478c

the current head of Linus's tree.

I'm sure I've seen a case where tv_sec differed by 1 when running my xfstests
script, but it's hard to reproduce that.  It also occurs with other file
types, not just regular files.  It occurs on both ext4 and xfs.

I've attached the source for dump-timestamps below.

David
---
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
	struct stat st;

	if (argc != 2) {
		fprintf(stderr, "Format: %s <file>\n", argv[0]);
		exit(2);
	}
	if (stat(argv[1], &st) == -1) {
		perror(argv[1]);
		exit(1);
	}
	printf("st_atime: %ld.%09ld\n", st.st_atim.tv_sec, st.st_atim.tv_nsec);
	printf("st_mtime: %ld.%09ld\n", st.st_mtim.tv_sec, st.st_mtim.tv_nsec);
	printf("st_ctime: %ld.%09ld\n", st.st_ctim.tv_sec, st.st_ctim.tv_nsec);
	return 0;
}

             reply	other threads:[~2017-03-30 17:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-30 17:30 David Howells [this message]
2017-03-30 18:07 ` Apparent backward time travel in timestamps on file creation Linus Torvalds
2017-03-30 19:35   ` David Howells
2017-03-30 19:52     ` Linus Torvalds
2017-03-30 20:04       ` Linus Torvalds
2017-03-30 20:13         ` David Howells
2017-03-30 20:16           ` David Lang
2017-03-30 21:13           ` Linus Torvalds
2017-03-30 22:22             ` David Howells
2017-03-31 12:35             ` Bob Peterson
2017-03-30 20:03     ` John Stultz
2017-03-30 20:06       ` Linus Torvalds
2017-03-30 18:49 ` 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=22214.1490895007@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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