diff options
author | kib <kib@FreeBSD.org> | 2015-04-01 08:25:40 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2015-04-01 08:25:40 +0000 |
commit | b7c417708ff3c064756f3aa8eb212b1f553578f9 (patch) | |
tree | aabd36bd6af041bd162dcdb7cf02449459de9205 /sys/fs | |
parent | d3d56db7e85c27a1a5ca5c43102147b8471ad91e (diff) | |
download | FreeBSD-src-b7c417708ff3c064756f3aa8eb212b1f553578f9.zip FreeBSD-src-b7c417708ff3c064756f3aa8eb212b1f553578f9.tar.gz |
Refine r280308. Do not completely disable timestamping of devfs nodes
on reads or writes, the time marks are used to display idle time by
w(1) [1]. Instead, use vfs.devfs.dotimes as the selector of default
precision vs. using time_second. The later gives seconds precision,
which is good enough for the purpose.
Note that timestamp updates are unlocked and the updates itself, as
well as the check in devfs_timestamp, are non-atomic.
Noted by: truckman [1]
Reviewed by: bde
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Diffstat (limited to 'sys/fs')
-rw-r--r-- | sys/fs/devfs/devfs_vnops.c | 32 |
1 files changed, 25 insertions, 7 deletions
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; |