Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1613322

Apparent backward time travel in timestamps on file creation

From David Howells <dhowells@redhat.com>
Newsgroups linux.kernel
Subject Apparent backward time travel in timestamps on file creation
Date 2017-03-30 19:40 +0200
Message-ID <tqMdc-1mD-9@gated-at.bofh.it> (permalink)
Organization Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903

Show all headers | View 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;
}

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Apparent backward time travel in timestamps on file creation David Howells <dhowells@redhat.com> - 2017-03-30 19:40 +0200
  Re: Apparent backward time travel in timestamps on file creation Linus Torvalds <torvalds@linux-foundation.org> - 2017-03-30 20:20 +0200
    Re: Apparent backward time travel in timestamps on file creation David Howells <dhowells@redhat.com> - 2017-03-30 21:40 +0200
      Re: Apparent backward time travel in timestamps on file creation Linus Torvalds <torvalds@linux-foundation.org> - 2017-03-30 22:00 +0200
        Re: Apparent backward time travel in timestamps on file creation Linus Torvalds <torvalds@linux-foundation.org> - 2017-03-30 22:10 +0200
          Re: Apparent backward time travel in timestamps on file creation David Howells <dhowells@redhat.com> - 2017-03-30 22:20 +0200
            Re: Apparent backward time travel in timestamps on file creation David Lang <david@lang.hm> - 2017-03-30 22:40 +0200
            Re: Apparent backward time travel in timestamps on file creation Linus Torvalds <torvalds@linux-foundation.org> - 2017-03-30 23:20 +0200
              Re: Apparent backward time travel in timestamps on file creation David Howells <dhowells@redhat.com> - 2017-03-31 00:30 +0200
              Re: Apparent backward time travel in timestamps on file creation Bob Peterson <rpeterso@redhat.com> - 2017-03-31 14:40 +0200
      Re: Apparent backward time travel in timestamps on file creation Linus Torvalds <torvalds@linux-foundation.org> - 2017-03-30 22:10 +0200
      Re: Apparent backward time travel in timestamps on file creation John Stultz <john.stultz@linaro.org> - 2017-03-30 22:10 +0200
  Re: Apparent backward time travel in timestamps on file creation John Stultz <john.stultz@linaro.org> - 2017-03-30 20:50 +0200

csiph-web