Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934066AbdC3RaM convert rfc822-to-8bit (ORCPT ); Thu, 30 Mar 2017 13:30:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45254 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933259AbdC3RaK (ORCPT ); Thu, 30 Mar 2017 13:30:10 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6CBA675ED6 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dhowells@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6CBA675ED6 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 From: David Howells 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 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22213.1490895007.1@warthog.procyon.org.uk> Content-Transfer-Encoding: 8BIT Date: Thu, 30 Mar 2017 18:30:07 +0100 Message-ID: <22214.1490895007@warthog.procyon.org.uk> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 30 Mar 2017 17:30:09 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1524 Lines: 55 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 #include #include int main(int argc, char *argv[]) { struct stat st; if (argc != 2) { fprintf(stderr, "Format: %s \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; }