NetBSD Problem Report #51762

From martin@duskware.de  Mon Jan  2 16:14:15 2017
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id A84D57A2C8
	for <gnats-bugs@gnats.NetBSD.org>; Mon,  2 Jan 2017 16:14:15 +0000 (UTC)
Message-Id: <20170102161404.923975CC761@emmas.aprisoft.de>
Date: Mon,  2 Jan 2017 17:14:04 +0100 (CET)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: mtime not updated by open(O_TRUNC)
X-Send-Pr-Version: 3.95

>Number:         51762
>Category:       kern
>Synopsis:       mtime not updated by open(O_TRUNC)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 02 16:15:00 +0000 2017
>Closed-Date:    Mon Nov 20 17:04:49 +0000 2017
>Last-Modified:  Mon Feb 26 01:20:01 +0000 2018
>Originator:     Martin Husemann
>Release:        NetBSD 7.99.53
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD night-owl.duskware.de 7.99.53 NetBSD 7.99.53 (NIGHT-OWL) #450: Wed Dec 28 12:18:50 CET 2016 martin@night-owl.duskware.de:/usr/src/sys/arch/amd64/compile/NIGHT-OWL amd64
Architecture: x86_64
Machine: amd64
>Description:

Opening an existing file with O_TRUNC should update the mtime of the file,
but does not do this in -current.

This came up during debugging a firefox "Welcome back" warning at startup.

>How-To-Repeat:

Run this test program. The seconds printed should montonically increase.

#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>

static time_t
lock_it(const char *file)
{
	struct stat st;

	if (stat(file, &st) != 0)
		st.st_mtime = 0;

	int f = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
	if (f == -1) return 0;
	close(f);

	return st.st_mtime;
}

int
main(int argc, char **argv)
{
	char buf[1000];

	sprintf(buf, "/tmp/test%d.lock", getpid());

	printf("lock file: %s\n", buf);

	for (int i = 0; i < 10; i++) {
		time_t l = lock_it(buf);
		printf("last lock: %ld\n", (long)l);
		sleep(2);
	}

	unlink(buf);

	return 0;
}


>Fix:
n/a

>Release-Note:

>Audit-Trail:
From: "J. Hannken-Illjes" <hannken@eis.cs.tu-bs.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/51762: mtime not updated by open(O_TRUNC)
Date: Tue, 3 Jan 2017 14:27:52 +0100

 This machine has /tmp on a ffs file system?

 --
 J. Hannken-Illjes - hannken@eis.cs.tu-bs.de - TU Braunschweig (Germany)

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/51762: mtime not updated by open(O_TRUNC)
Date: Tue, 3 Jan 2017 14:37:48 +0100

 On Tue, Jan 03, 2017 at 01:30:01PM +0000, J. Hannken-Illjes wrote:
 >  This machine has /tmp on a ffs file system?

 No, tmpfs - but the original effect happens in the firefox profile, which
 is on ffs.

 Martin

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org, "J. Hannken-Illjes" <hannken@eis.cs.tu-bs.de>
Cc: 
Subject: Re: kern/51762: mtime not updated by open(O_TRUNC)
Date: Wed, 04 Jan 2017 02:22:39 +0700

     Date:        Tue,  3 Jan 2017 13:30:01 +0000 (UTC)
     From:        "J. Hannken-Illjes" <hannken@eis.cs.tu-bs.de>
     Message-ID:  <20170103133001.6B5847A338@mollari.NetBSD.org>

   |  This machine has /tmp on a ffs file system?

 I also wondered if that might be related, and ran the test program with the 
 file on both tmpfs and ffs ... no change in symptom.

 For the record in the PR, I observed the incorrect (according to POSIX -- one
 might argue that if the file is obviously not changed, nor should the
 mtime be, but let's not go there) behaviour on 6.99.30, 7.99.23 and 7,99,44
 and correct behaviour in 7.0_STABLE (Dec 13, 2016)

 kre

From: "Juergen Hannken-Illjes" <hannken@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51762 CVS commit: src/sys/ufs/ufs
Date: Wed, 4 Jan 2017 10:04:18 +0000

 Module Name:	src
 Committed By:	hannken
 Date:		Wed Jan  4 10:04:17 UTC 2017

 Modified Files:
 	src/sys/ufs/ufs: ufs_inode.c

 Log Message:
 Change ufs_truncate_retry() to call UFS_TRUNCATE() at least once.
 Even with "newsize == ip->i_size" it must set mtime etc.

 Adresses PR kern/51762 "mtime not updated by open(O_TRUNC)"


 To generate a diff of this commit:
 cvs rdiff -u -r1.97 -r1.98 src/sys/ufs/ufs/ufs_inode.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Juergen Hannken-Illjes" <hannken@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51762 CVS commit: src/sys/fs/tmpfs
Date: Wed, 4 Jan 2017 10:06:43 +0000

 Module Name:	src
 Committed By:	hannken
 Date:		Wed Jan  4 10:06:43 UTC 2017

 Modified Files:
 	src/sys/fs/tmpfs: tmpfs_subr.c

 Log Message:
 Change tmpfs_chsize() to update mtime etc. even if "length == node->tn_size".

 Adresses PR kern/51762 "mtime not updated by open(O_TRUNC)"


 To generate a diff of this commit:
 cvs rdiff -u -r1.101 -r1.102 src/sys/fs/tmpfs/tmpfs_subr.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "J. Hannken-Illjes" <hannken@eis.cs.tu-bs.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/51762: mtime not updated by open(O_TRUNC)
Date: Wed, 4 Jan 2017 11:25:30 +0100

 This issue should be fixed for FFS and TMPFS.  This PR should become
 an ATF test.

 --
 J. Hannken-Illjes - hannken@eis.cs.tu-bs.de - TU Braunschweig (Germany)

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/51762: mtime not updated by open(O_TRUNC)
Date: Wed, 4 Jan 2017 11:32:16 +0100

 On Wed, Jan 04, 2017 at 10:30:01AM +0000, J. Hannken-Illjes wrote:
 >  This issue should be fixed for FFS and TMPFS.  This PR should become
 >  an ATF test.

 I am working on the test.

 Martin

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/51762: truncating an empty file does not cause mtime updates
Date: Thu, 2 Feb 2017 21:25:00 +0100

 I am about to commit the atf test for this, and a few other file systems
 fail:

 Failed test cases:
     t_mtime_otrunc:lfs_otrunc_mtime_update,
     t_mtime_otrunc:puffs_otrunc_mtime_update,
     t_mtime_otrunc:rumpfs_otrunc_mtime_update,
     t_mtime_otrunc:v7fs_otrunc_mtime_update

 Summary for 1 test programs:
     10 passed test cases.
     4 failed test cases.
     0 expected failed test cases.
     0 skipped test cases.

 Martin

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51762 CVS commit: src/tests/fs/vfs
Date: Thu, 2 Feb 2017 22:07:05 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Thu Feb  2 22:07:05 UTC 2017

 Modified Files:
 	src/tests/fs/vfs: Makefile
 Added Files:
 	src/tests/fs/vfs: t_mtime_otrunc.c

 Log Message:
 PR kern/51762: add a test program


 To generate a diff of this commit:
 cvs rdiff -u -r1.23 -r1.24 src/tests/fs/vfs/Makefile
 cvs rdiff -u -r0 -r1.1 src/tests/fs/vfs/t_mtime_otrunc.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51762 CVS commit: src/distrib/sets/lists
Date: Thu, 2 Feb 2017 22:07:33 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Thu Feb  2 22:07:33 UTC 2017

 Modified Files:
 	src/distrib/sets/lists/debug: mi
 	src/distrib/sets/lists/tests: mi

 Log Message:
 Add test program for PR kern/51762


 To generate a diff of this commit:
 cvs rdiff -u -r1.194 -r1.195 src/distrib/sets/lists/debug/mi
 cvs rdiff -u -r1.715 -r1.716 src/distrib/sets/lists/tests/mi

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Maya Rashish" <maya@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51762 CVS commit: src/sys/ufs/lfs
Date: Tue, 21 Mar 2017 09:53:01 +0000

 Module Name:	src
 Committed By:	maya
 Date:		Tue Mar 21 09:53:01 UTC 2017

 Modified Files:
 	src/sys/ufs/lfs: lfs_inode.c

 Log Message:
 Update mtime even if oip->i_size == length

 PR kern/51762, LFS version.


 To generate a diff of this commit:
 cvs rdiff -u -r1.152 -r1.153 src/sys/ufs/lfs/lfs_inode.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Juergen Hannken-Illjes" <hannken@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51762 CVS commit: src/sys/fs/puffs
Date: Sat, 8 Apr 2017 08:49:45 +0000

 Module Name:	src
 Committed By:	hannken
 Date:		Sat Apr  8 08:49:44 UTC 2017

 Modified Files:
 	src/sys/fs/puffs: puffs_vnops.c

 Log Message:
 Update mtime when updating file size.

 PR kern/51762 (mtime not updated by open(O_TRUNC))


 To generate a diff of this commit:
 cvs rdiff -u -r1.207 -r1.208 src/sys/fs/puffs/puffs_vnops.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Juergen Hannken-Illjes" <hannken@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51762 CVS commit: src/sys/fs/v7fs
Date: Sat, 8 Apr 2017 08:51:02 +0000

 Module Name:	src
 Committed By:	hannken
 Date:		Sat Apr  8 08:51:02 UTC 2017

 Modified Files:
 	src/sys/fs/v7fs: v7fs_vnops.c

 Log Message:
 Update mtime when updating file size.

 PR kern/51762 (mtime not updated by open(O_TRUNC))


 To generate a diff of this commit:
 cvs rdiff -u -r1.22 -r1.23 src/sys/fs/v7fs/v7fs_vnops.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Mon, 20 Nov 2017 17:04:49 +0000
State-Changed-Why:
Test passes for all filesystems now


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51762 CVS commit: src/sys/rump/librump/rumpvfs
Date: Mon, 20 Nov 2017 17:00:36 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Mon Nov 20 17:00:36 UTC 2017

 Modified Files:
 	src/sys/rump/librump/rumpvfs: rumpfs.c

 Log Message:
 When truncating a file make sure to update mtime.
 This fixes PR kern/51762 for rumpfs.


 To generate a diff of this commit:
 cvs rdiff -u -r1.151 -r1.152 src/sys/rump/librump/rumpvfs/rumpfs.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Soren Jacobsen" <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51762 CVS commit: [netbsd-8] src/sys/rump/librump/rumpvfs
Date: Mon, 26 Feb 2018 01:18:28 +0000

 Module Name:	src
 Committed By:	snj
 Date:		Mon Feb 26 01:18:28 UTC 2018

 Modified Files:
 	src/sys/rump/librump/rumpvfs [netbsd-8]: rumpfs.c

 Log Message:
 Pull up following revision(s) (requested by maya in ticket #581):
 	sys/rump/librump/rumpvfs/rumpfs.c: 1.151-1.152
 PR/52738: Martin Husemann: rumpfs does not support mtime
 --
 When truncating a file make sure to update mtime.
 This fixes PR kern/51762 for rumpfs.


 To generate a diff of this commit:
 cvs rdiff -u -r1.150 -r1.150.2.1 src/sys/rump/librump/rumpvfs/rumpfs.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.