From owner-svn-src-all@FreeBSD.ORG Mon Mar 30 10:34:02 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 89C76C6C; Mon, 30 Mar 2015 10:34:02 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2ABC4A3F; Mon, 30 Mar 2015 10:34:01 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id t2UAXuJ1082143 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 30 Mar 2015 13:33:56 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t2UAXuJ1082143 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id t2UAXtcE082142; Mon, 30 Mar 2015 13:33:55 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 30 Mar 2015 13:33:55 +0300 From: Konstantin Belousov To: Bruce Evans Subject: Re: svn commit: r280308 - head/sys/fs/devfs Message-ID: <20150330103355.GD2379@kib.kiev.ua> References: <20150322162507.GD2379@kib.kiev.ua> <201503221825.t2MIP7jv096531@gw.catspoiler.org> <20150329175137.GD95224@stack.nl> <20150329184238.GB2379@kib.kiev.ua> <20150330145148.C1660@besplex.bde.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150330145148.C1660@besplex.bde.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: src-committers@freebsd.org, Jilles Tjoelker , Don Lewis , delphij@freebsd.org, svn-src-head@freebsd.org, svn-src-all@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Mar 2015 10:34:02 -0000 On Mon, Mar 30, 2015 at 03:14:10PM +1100, Bruce Evans wrote: > File timestamps use CLOCK_REALTIME, so they are supposed to go backwards > sometimes. More importantly, if the time is set to a future time (by > utimes(), etc., not due to a clock step), this prevents it being correted. > I think you only want to do a null update if tv_nsec is nonzero due to a > previous setting with vfs_timestamp(), and the new second hasn't arrived > yet. Something like: > > if (tsp->tv_sec != ts) ... > > If '<', then as above. If '>', it means a correction by >= 1 second > (strictly greater if tv_nsec != 0). The initial value tv_nsec is > irrelevant in both cases. Below is the updated patch. I also added a comment to devfs_timestamp(), please reformulate it to your liking. diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c index 941f92c..552ddd2 100644 --- a/sys/fs/devfs/devfs_vnops.c +++ b/sys/fs/devfs/devfs_vnops.c @@ -84,7 +84,27 @@ SYSCTL_DECL(_vfs_devfs); static int devfs_dotimes; SYSCTL_INT(_vfs_devfs, OID_AUTO, dotimes, CTLFLAG_RW, - &devfs_dotimes, 0, "Update timestamps on DEVFS"); + &devfs_dotimes, 0, "Update timestamps on DEVFS with default precision"); + +/* + * Update devfs node timestamp. Note that updates are unlocked and + * stat(2) could see partially updated times. + */ +static void +devfs_timestamp(struct timespec *tsp) +{ + time_t ts; + + if (devfs_dotimes) { + vfs_timestamp(tsp); + } else { + ts = time_second; + if (tsp->tv_sec != ts) { + tsp->tv_sec = ts; + tsp->tv_nsec = 0; + } + } +} static int devfs_fp_check(struct file *fp, struct cdev **devp, struct cdevsw **dswp, @@ -1228,9 +1248,8 @@ devfs_read_f(struct file *fp, struct uio *uio, struct ucred *cred, foffset_lock_uio(fp, uio, flags | FOF_NOLOCK); error = dsw->d_read(dev, uio, ioflag); - if (devfs_dotimes && - (uio->uio_resid != resid || (error == 0 && resid != 0))) - vfs_timestamp(&dev->si_atime); + if (uio->uio_resid != resid || (error == 0 && resid != 0)) + devfs_timestamp(&dev->si_atime); td->td_fpop = fpop; dev_relthread(dev, ref); @@ -1708,9 +1727,8 @@ devfs_write_f(struct file *fp, struct uio *uio, struct ucred *cred, resid = uio->uio_resid; error = dsw->d_write(dev, uio, ioflag); - if (devfs_dotimes && - (uio->uio_resid != resid || (error == 0 && resid != 0))) { - vfs_timestamp(&dev->si_ctime); + if (uio->uio_resid != resid || (error == 0 && resid != 0)) { + devfs_timestamp(&dev->si_ctime); dev->si_mtime = dev->si_ctime; } td->td_fpop = fpop;