mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Robin H. Johnson" <robbat2@gentoo.org>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] tmpfs time granularity fix for [acm]time moving backwards.
Date: Fri, 9 Jun 2006 15:49:36 -0700	[thread overview]
Message-ID: <20060609224936.GA30611@curie-int.vc.shawcable.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 2371 bytes --]

[Please CC me on replies].

I noticed a strange behavior in a tmpfs file system the other day, while
building packages - occasionally, and seemingly at random, make decided to
rebuild a target. However only on tmpfs.

A file would be created, and if checked, it had a sub-second timestamp.
However, after an utimes related call where sub-seconds should be set, they
were zeroed instead. In the case that a file was created, and utimes(...,NULL)
was used on it in the same second, the timestamp on the file moved backwards.

Puesdo-code of my testcase:
	int fd = creat(name,0644);
	fstat(fd,&st);
	printf("...[acm]time...",...)
	futime(fd,NULL);
	fstat(fd,&st);
	printf("...[acm]time...",...)
	close(fd);

Tested against: linus 2.6.13, linus 2.6.17-rc6.

Test output from a filesystem not supporting sub-second timestamps (ext3, reiserfs):
creat:   m=1149891410.0 c=1149891410.0 a=1149891407.0
futimes: m=1149891410.0 c=1149891410.0 a=1149891410.0

Test output from a filesystem supporting sub-second timestamps (jfs,xfs,ramfs):
creat:   m=1149891452.928796249 c=1149891452.928796249 a=1149891452.928796249
futimes: m=1149891452.928796249 c=1149891452.928796249 a=1149891452.928796249

Test output from the tmpfs filesystem before the fix:
creat:   m=1149892052.562029884 c=1149892052.562029884 a=1149892052.562029884
futimes: m=1149892052.0         c=1149892052.0         a=1149892052.0

Test output from the tmpfs filesystem with the patch below:
creat:   m=1149892086.382150894 c=1149892086.382150894 a=1149892075.473249075
futimes: m=1149892086.383150885 c=1149892086.383150885 a=1149892086.383150885

After some digging, I found that this was being caused by tmpfs not having a
time granularity set, thus inheriting the default 1s granularity.

NOTE: This also indicates there is another bug at the VFS layer, where the
initial timestamp did not have the granularity applied to it.

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>

--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2102,6 +2102,7 @@ #endif
 	sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
 	sb->s_magic = TMPFS_MAGIC;
 	sb->s_op = &shmem_ops;
+	sb->s_time_gran = 1;
 
 	inode = shmem_get_inode(sb, S_IFDIR | mode, 0);
 	if (!inode)

-- 
Robin Hugh Johnson
E-Mail     : robbat2@gentoo.org
GnuPG FP   : 11AC BA4F 4778 E3F6 E4ED  F38E B27B 944E 3488 4E85

[-- Attachment #2: Type: application/pgp-signature, Size: 241 bytes --]

             reply	other threads:[~2006-06-09 22:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-09 22:49 Robin H. Johnson [this message]
2006-06-11 10:12 ` Jan Engelhardt
2006-06-11 11:31   ` Robin H. Johnson

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=20060609224936.GA30611@curie-int.vc.shawcable.net \
    --to=robbat2@gentoo.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®