idle times wrong

Matthew Dillon dillon at apollo.backplane.com
Sun Feb 13 10:12:04 PST 2005


    Yes, Jeff reported this effect on leaf too.

    It's due to the specfs bypass.  The device inodes in /dev are not being
    updated by reads and writes.  I have a tentitive patch set.. more a
    hack then a fix, and I haven't tested it with buildworld yet.  It 
    records the time in the device read and write and then modifies the 
    returned attribute based on the additional information.

					-Matt
					Matthew Dillon 
					<dillon at xxxxxxxxxxxxx>

Index: kern/kern_device.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_device.c,v
retrieving revision 1.13
diff -u -r1.13 kern_device.c
--- kern/kern_device.c	15 Sep 2004 03:21:03 -0000	1.13
+++ kern/kern_device.c	12 Feb 2005 23:30:03 -0000
@@ -262,13 +262,17 @@
 {
     struct cdevmsg_read msg;
     lwkt_port_t port;
+    int error;
 
     port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_READ);
     if (port == NULL)
 	return(ENXIO);
     msg.uio = uio;
     msg.ioflag = ioflag;
-    return(lwkt_domsg(port, &msg.msg.msg));
+    error = lwkt_domsg(port, &msg.msg.msg);
+    if (error == 0)
+	dev->si_lastread = time_second;
+    return (error);
 }
 
 int
@@ -280,6 +284,7 @@
     port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_WRITE);
     if (port == NULL)
 	return(ENXIO);
+    dev->si_lastwrite = time_second;
     msg.uio = uio;
     msg.ioflag = ioflag;
     return(lwkt_domsg(port, &msg.msg.msg));
Index: kern/vfs_vnops.c
===================================================================
RCS file: /cvs/src/sys/kern/vfs_vnops.c,v
retrieving revision 1.28
diff -u -r1.28 vfs_vnops.c
--- kern/vfs_vnops.c	30 Nov 2004 18:59:52 -0000	1.28
+++ kern/vfs_vnops.c	12 Feb 2005 23:18:01 -0000
@@ -724,6 +724,7 @@
 	struct vattr *vap;
 	int error;
 	u_short mode;
+	dev_t dev;
 
 	vap = &vattr;
 	error = VOP_GETATTR(vp, vap, td);
@@ -786,6 +787,24 @@
 	sb->st_mtimespec = vap->va_mtime;
 	sb->st_ctimespec = vap->va_ctime;
 
+	/*
+	 * A VCHR and VBLK device may track the last access and last modified
+	 * time independantly of the filesystem.  This is particularly true
+	 * because device read and write calls may bypass the filesystem.
+	 */
+	if (vp->v_type == VCHR || vp->v_type == VBLK) {
+		if ((dev = vp->v_rdev) != NULL) {
+			if (dev->si_lastread) {
+				sb->st_atimespec.tv_sec = dev->si_lastread;
+				sb->st_atimespec.tv_nsec = 0;
+			}
+			if (dev->si_lastwrite) {
+				sb->st_atimespec.tv_sec = dev->si_lastwrite;
+				sb->st_atimespec.tv_nsec = 0;
+			}
+		}
+	}
+
         /*
 	 * According to www.opengroup.org, the meaning of st_blksize is 
 	 *   "a filesystem-specific preferred I/O block size for this 
Index: sys/conf.h
===================================================================
RCS file: /cvs/src/sys/sys/conf.h,v
retrieving revision 1.8
diff -u -r1.8 conf.h
--- sys/conf.h	4 Jul 2004 05:16:32 -0000	1.8
+++ sys/conf.h	12 Feb 2005 22:42:13 -0000
@@ -43,7 +43,12 @@
 #ifndef _SYS_CONF_H_
 #define	_SYS_CONF_H_
 
+#if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES)
+#error "This file shouldn't be included from userland programs"
+#endif
+
 #include <sys/queue.h>
+#include <sys/time.h>
 
 #define SPECNAMELEN	15
 
@@ -75,6 +80,8 @@
 			int __sid_bsize_best; /* optimal block size */
 		} __si_disk;
 	} __si_u;
+	time_t		si_lastread;		/* time_second */
+	time_t		si_lastwrite;		/* time_second */
 };
 
 #define SI_STASHED	0x0001	/* created in stashed storage */





More information about the Bugs mailing list