linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tmpfs time granularity fix for [acm]time going backwards. Also VFS time granularity bug on creat(). (Repost, more content)
@ 2006-06-11 11:54 Robin H. Johnson
  2006-06-11 18:10 ` Hugh Dickins
  2006-06-12 12:22 ` [PATCH] tmpfs time granularity fix for [acm]time going backwards. Also VFS time granularity bug on creat(). (Repost, more content) Andi Kleen
  0 siblings, 2 replies; 10+ messages in thread
From: Robin H. Johnson @ 2006-06-11 11:54 UTC (permalink / raw)
  To: linux-kernel; +Cc: Al Viro, linux-fsdevel

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

[Please CC me on replies].

This patch should probably be included for 2.6.17, despite how long the
bug has been around. It's a one-liner, with no side-effects.

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

The output above of jfs/xfs/ramfs having identical ctime/mtime in the
utime/creat calls is just co-incidence, my box is reasonably fast, on a
slower machine, they do diverge more. My box is just fast enough that
they happened in the same tick (I have HZ=1000).

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: The further bug:
I believe this also indicates there is another bug at the VFS layer,
where the initial timestamp from the creat() operation did not have the
granularity applied to it. I haven't traced this problem down yet,
others that are more familiar with the VFS might have a bit better luck.
Unless this is fixed, similar issues may crop up with other filesystems.
It just needs a bit of code like this:
inode->i_[acm]time = current_fs_time(inode->i_sb);

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

--- mm/shmem.c
+++ 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 --]

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

end of thread, other threads:[~2006-06-13  3:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-11 11:54 [PATCH] tmpfs time granularity fix for [acm]time going backwards. Also VFS time granularity bug on creat(). (Repost, more content) Robin H. Johnson
2006-06-11 18:10 ` Hugh Dickins
2006-06-12  5:10   ` Robin H. Johnson
2006-06-12  7:19     ` Jan Engelhardt
2006-06-12 19:24     ` Hugh Dickins
2006-06-12 20:50       ` [PATCH] tmpfs: time granularity fix for [acm]time going backwards Hugh Dickins
2006-06-13  3:38         ` Andi Kleen
2006-06-12 12:22 ` [PATCH] tmpfs time granularity fix for [acm]time going backwards. Also VFS time granularity bug on creat(). (Repost, more content) Andi Kleen
2006-06-12 19:38   ` Hugh Dickins
2006-06-13  3:49     ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).