All of lore.kernel.org
 help / color / mirror / Atom feed
* Apparent backward time travel in timestamps on file creation
@ 2017-03-30 17:30 David Howells
  2017-03-30 18:07 ` Linus Torvalds
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: David Howells @ 2017-03-30 17:30 UTC (permalink / raw)
  To: tglx, john.stultz; +Cc: dhowells, torvalds, linux-kernel, linux-fsdevel

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;
}

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-03-31 12:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-30 17:30 Apparent backward time travel in timestamps on file creation David Howells
2017-03-30 18:07 ` Linus Torvalds
2017-03-30 18:49 ` John Stultz
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-31 12:35         ` Bob Peterson
2017-03-30 22:22       ` David Howells
2017-03-30 20:03   ` John Stultz
2017-03-30 20:06     ` Linus Torvalds

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.