Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/kernel/kqueue Overhaul of the EVFILT_VNODE kevent(2) f...



details:   https://anonhg.NetBSD.org/src/rev/4cea3c34a2d2
branches:  trunk
changeset: 1024346:4cea3c34a2d2
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Oct 20 03:08:16 2021 +0000

description:
Overhaul of the EVFILT_VNODE kevent(2) filter:

- Centralize vnode kevent handling in the VOP_*() wrappers, rather than
  forcing each individual file system to deal with it (except VOP_RENAME(),
  because VOP_RENAME() is a mess and we currently have 2 different ways
  of handling it; at least it's reasonably well-centralized in the "new"
  way).
- Add support for NOTE_OPEN, NOTE_CLOSE, NOTE_CLOSE_WRITE, and NOTE_READ,
  compatible with the same events in FreeBSD.
- Track which kevent notifications clients are interested in receiving
  to avoid doing work for events no one cares about (avoiding, e.g.
  taking locks and traversing the klist to send a NOTE_WRITE when
  someone is merely watching for a file to be deleted, for example).

In support of the above:

- Add support in vnode_if.sh for specifying PRE- and POST-op handlers,
  to be invoked before and after vop_pre() and vop_post(), respectively.
  Basic idea from FreeBSD, but implemented differently.
- Add support in vnode_if.sh for specifying CONTEXT fields in the
  vop_*_args structures.  These context fields are used to convey information
  between the file system VOP function and the VOP wrapper, but do not
  occupy an argument slot in the VOP_*() call itself.  These context fields
  are initialized and subsequently interpreted by PRE- and POST-op handlers.
- Version VOP_REMOVE(), uses the a context field for the file system to report
  back the resulting link count of the target vnode.  Return this in tmpfs,
  udf, nfs, chfs, ext2fs, lfs, and ufs.

NetBSD 9.99.92.

diffstat:

 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c |   36 +-
 lib/libc/sys/kqueue.2                                  |   22 +-
 sys/coda/coda_vnops.c                                  |    6 +-
 sys/fs/msdosfs/msdosfs_vnops.c                         |   19 +-
 sys/fs/nilfs/nilfs_vnops.c                             |   24 +-
 sys/fs/ptyfs/ptyfs_vnops.c                             |    5 +-
 sys/fs/puffs/puffs_vnops.c                             |    9 +-
 sys/fs/sysvbfs/sysvbfs_vnops.c                         |   13 +-
 sys/fs/tmpfs/tmpfs_rename.c                            |   24 +-
 sys/fs/tmpfs/tmpfs_subr.c                              |   22 +-
 sys/fs/tmpfs/tmpfs_vnops.c                             |   14 +-
 sys/fs/udf/udf_rename.c                                |   26 +-
 sys/fs/udf/udf_vnops.c                                 |   32 +-
 sys/fs/union/union_vnops.c                             |    9 +-
 sys/fs/unionfs/unionfs_vnops.c                         |    2 +-
 sys/fs/v7fs/v7fs_vnops.c                               |    7 +-
 sys/kern/vfs_vnode.c                                   |    8 +-
 sys/kern/vfs_vnops.c                                   |   92 ++++-
 sys/kern/vnode_if.sh                                   |  308 +++++++++++++++-
 sys/kern/vnode_if.src                                  |   22 +-
 sys/miscfs/deadfs/dead_vnops.c                         |    7 +-
 sys/miscfs/genfs/genfs.h                               |    8 +-
 sys/miscfs/genfs/genfs_rename.c                        |   36 +-
 sys/miscfs/genfs/genfs_vnops.c                         |   12 +-
 sys/miscfs/genfs/layer_vnops.c                         |    9 +-
 sys/miscfs/umapfs/umap_vnops.c                         |    6 +-
 sys/nfs/nfs_bio.c                                      |    9 +-
 sys/nfs/nfs_kq.c                                       |   13 +-
 sys/nfs/nfs_vnops.c                                    |   27 +-
 sys/rump/librump/rumpvfs/rumpfs.c                      |    7 +-
 sys/sys/event.h                                        |    6 +-
 sys/sys/param.h                                        |    4 +-
 sys/sys/vnode.h                                        |   30 +-
 sys/ufs/chfs/chfs_vnops.c                              |   44 +-
 sys/ufs/ext2fs/ext2fs_readwrite.c                      |   20 +-
 sys/ufs/ext2fs/ext2fs_rename.c                         |   20 +-
 sys/ufs/ext2fs/ext2fs_vnops.c                          |   19 +-
 sys/ufs/lfs/lfs_rename.c                               |   30 +-
 sys/ufs/lfs/lfs_vnops.c                                |   11 +-
 sys/ufs/lfs/ulfs_readwrite.c                           |   20 +-
 sys/ufs/lfs/ulfs_vnops.c                               |   17 +-
 sys/ufs/ufs/ufs_acl.c                                  |    5 +-
 sys/ufs/ufs/ufs_extern.h                               |    8 +-
 sys/ufs/ufs/ufs_readwrite.c                            |   20 +-
 sys/ufs/ufs/ufs_rename.c                               |   31 +-
 sys/ufs/ufs/ufs_vnops.c                                |   21 +-
 tests/kernel/kqueue/t_vnode.c                          |  173 +++++++++
 47 files changed, 873 insertions(+), 440 deletions(-)

diffs (truncated from 3568 to 300 lines):

diff -r 97ba429b7546 -r 4cea3c34a2d2 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c    Wed Oct 20 02:12:36 2021 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c    Wed Oct 20 03:08:16 2021 +0000
@@ -4477,7 +4477,7 @@
                                    NOTE_DELETE : NOTE_LINK));
                        } else {
                                genfs_rename_knote(sdvp, *svpp, tdvp, *tvpp,
-                                   ((tzp != NULL) && (tzp->z_links == 0)));
+                                   tzp != NULL ? tzp->z_links : 0);
                        }
 #endif
                }
@@ -5147,9 +5147,6 @@
 
        resid = uio->uio_resid;
        error = zfs_write(vp, uio, ioflags(ap->a_ioflag), ap->a_cred, NULL);
-       if (resid > uio->uio_resid)
-               VN_KNOTE(vp, NOTE_WRITE |
-                   (zp->z_size > osize ? NOTE_EXTEND : 0));
 
        return error;
 }
@@ -5342,8 +5339,6 @@
 
        KASSERT((error == 0) == (*vpp != NULL));
        KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
-       if (error == 0)
-               VN_KNOTE(dvp, NOTE_WRITE);
        if (*vpp != NULL)
                VOP_UNLOCK(*vpp, 0);
 
@@ -5383,8 +5378,6 @@
 
        KASSERT((error == 0) == (*vpp != NULL));
        KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
-       if (error == 0)
-               VN_KNOTE(dvp, NOTE_WRITE);
        if (*vpp != NULL)
                VOP_UNLOCK(*vpp, 0);
 
@@ -5394,10 +5387,11 @@
 static int
 zfs_netbsd_remove(void *v)
 {
-       struct vop_remove_v2_args /* {
+       struct vop_remove_v3_args /* {
                struct vnode *a_dvp;
                struct vnode *a_vp;
                struct componentname *a_cnp;
+               nlink_t ctx_vp_new_nlink;
        } */ *ap = v;
        struct vnode *dvp = ap->a_dvp;
        struct vnode *vp = ap->a_vp;
@@ -5414,11 +5408,12 @@
 
        error = zfs_remove(dvp, vp, nm, cnp->cn_cred);
 
+       /*
+        * XXX Should update ctx_vp_new_nlink, but for now the
+        * XXX the kevent sent on "vp"  matches historical behavior.
+        */
+
        PNBUF_PUT(nm);
-       if (error == 0) {
-               VN_KNOTE(vp, NOTE_DELETE);
-               VN_KNOTE(dvp, NOTE_WRITE);
-       }
        vput(vp);
        KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
        return (error);
@@ -5454,8 +5449,6 @@
 
        KASSERT((error == 0) == (*vpp != NULL));
        KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
-       if (error == 0)
-               VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
        if (*vpp != NULL)
                VOP_UNLOCK(*vpp, 0);
 
@@ -5486,10 +5479,6 @@
        error = zfs_rmdir(dvp, vp, nm, cnp->cn_cred);
 
        PNBUF_PUT(nm);
-       if (error == 0) {
-               VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
-               VN_KNOTE(vp, NOTE_DELETE);
-       }
        vput(vp);
        KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
        return error;
@@ -5653,7 +5642,6 @@
        if (error)
                return error;
 
-       VN_KNOTE(vp, NOTE_ATTRIB);
        cache_enter_id(vp, zp->z_mode, zp->z_uid, zp->z_gid, true);
 
        return error;
@@ -5662,7 +5650,7 @@
 static int
 zfs_netbsd_rename(void *v)
 {
-       struct vop_rename_args  /* {
+       struct vop_rename_args /* {
                struct vnode *a_fdvp;
                struct vnode *a_fvp;
                struct componentname *a_fcnp;
@@ -5760,8 +5748,6 @@
        error = zfs_symlink(dvp, vpp, nm, vap, target, cnp->cn_cred, 0);
 
        PNBUF_PUT(nm);
-       if (error == 0)
-               VN_KNOTE(ap->a_dvp, NOTE_WRITE);
        KASSERT((error == 0) == (*vpp != NULL));
        KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
        if (*vpp != NULL)
@@ -5803,10 +5789,6 @@
            NULL, 0);
 
        PNBUF_PUT(nm);
-       if (error == 0) {
-               VN_KNOTE(vp, NOTE_LINK);
-               VN_KNOTE(dvp, NOTE_WRITE);
-       }
        VOP_UNLOCK(vp, 0);
        return error;
 }
diff -r 97ba429b7546 -r 4cea3c34a2d2 lib/libc/sys/kqueue.2
--- a/lib/libc/sys/kqueue.2     Wed Oct 20 02:12:36 2021 +0000
+++ b/lib/libc/sys/kqueue.2     Wed Oct 20 03:08:16 2021 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: kqueue.2,v 1.54 2021/10/13 04:57:19 thorpej Exp $
+.\"    $NetBSD: kqueue.2,v 1.55 2021/10/20 03:08:19 thorpej Exp $
 .\"
 .\" Copyright (c) 2000 Jonathan Lemon
 .\" All rights reserved.
@@ -32,7 +32,7 @@
 .\"
 .\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.22 2001/06/27 19:55:57 dd Exp $
 .\"
-.Dd October 11, 2021
+.Dd October 15, 2021
 .Dt KQUEUE 2
 .Os
 .Sh NAME
@@ -440,24 +440,32 @@
 .Va fflags ,
 and returns when one or more of the requested events occurs on the descriptor.
 The events to monitor are:
-.Bl -tag -width XXNOTE_RENAME
+.Bl -tag -width NOTE_CLOSE_WRITE
+.It Dv NOTE_ATTRIB
+The file referenced by the descriptor had its attributes changed.
+.It Dv NOTE_CLOSE
+A file descriptor without write access referencing the file was closed.
+.It Dv NOTE_CLOSE_WRITE
+A file descriptor with write access referencing the file was closed.
 .It Dv NOTE_DELETE
 .Xr unlink 2
 was called on the file referenced by the descriptor.
-.It Dv NOTE_WRITE
-A write occurred on the file referenced by the descriptor.
 .It Dv NOTE_EXTEND
 The file referenced by the descriptor was extended.
-.It Dv NOTE_ATTRIB
-The file referenced by the descriptor had its attributes changed.
 .It Dv NOTE_LINK
 The link count on the file changed.
+.It Dv NOTE_OPEN
+The file refrenced by the descriptor was opened.
+.It Dv NOTE_READ
+A read occurred on the file referenced by the descriptor.
 .It Dv NOTE_RENAME
 The file referenced by the descriptor was renamed.
 .It Dv NOTE_REVOKE
 Access to the file was revoked via
 .Xr revoke 2
 or the underlying file system was unmounted.
+.It Dv NOTE_WRITE
+A write occurred on the file referenced by the descriptor.
 .El
 .Pp
 On return,
diff -r 97ba429b7546 -r 4cea3c34a2d2 sys/coda/coda_vnops.c
--- a/sys/coda/coda_vnops.c     Wed Oct 20 02:12:36 2021 +0000
+++ b/sys/coda/coda_vnops.c     Wed Oct 20 03:08:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: coda_vnops.c,v 1.115 2021/06/29 22:34:05 dholland Exp $        */
+/*     $NetBSD: coda_vnops.c,v 1.116 2021/10/20 03:08:16 thorpej Exp $ */
 
 /*
  *
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.115 2021/06/29 22:34:05 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.116 2021/10/20 03:08:16 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1075,7 +1075,7 @@
 coda_remove(void *v)
 {
 /* true args */
-    struct vop_remove_v2_args *ap = v;
+    struct vop_remove_v3_args *ap = v;
     vnode_t *dvp = ap->a_dvp;
     struct cnode *cp = VTOC(dvp);
     vnode_t *vp = ap->a_vp;
diff -r 97ba429b7546 -r 4cea3c34a2d2 sys/fs/msdosfs/msdosfs_vnops.c
--- a/sys/fs/msdosfs/msdosfs_vnops.c    Wed Oct 20 02:12:36 2021 +0000
+++ b/sys/fs/msdosfs/msdosfs_vnops.c    Wed Oct 20 03:08:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_vnops.c,v 1.106 2021/07/18 23:57:14 dholland Exp $     */
+/*     $NetBSD: msdosfs_vnops.c,v 1.107 2021/10/20 03:08:17 thorpej Exp $      */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.106 2021/07/18 23:57:14 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.107 2021/10/20 03:08:17 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -151,7 +151,6 @@
        DETIMES(&ndirent, NULL, NULL, NULL, pdep->de_pmp->pm_gmtoff);
        if ((error = createde(&ndirent, pdep, &dep, cnp)) != 0)
                goto bad;
-       VN_KNOTE(ap->a_dvp, NOTE_WRITE);
        *ap->a_vpp = DETOV(dep);
        cache_enter(ap->a_dvp, *ap->a_vpp, cnp->cn_nameptr, cnp->cn_namelen,
            cnp->cn_flags);
@@ -427,7 +426,6 @@
        }
 
        if (de_changed) {
-               VN_KNOTE(vp, NOTE_ATTRIB);
                error = deupdat(dep, 1);
                if (error)
                        goto bad;
@@ -545,7 +543,7 @@
                int a_ioflag;
                kauth_cred_t a_cred;
        } */ *ap = v;
-       int resid, extended = 0;
+       int resid;
        int error = 0;
        int ioflag = ap->a_ioflag;
        u_long osize;
@@ -625,7 +623,6 @@
                if (rem > 0)
                        ubc_zerorange(&vp->v_uobj, (off_t)dep->de_FileSize,
                            rem, UBC_VNODE_FLAGS(vp));
-               extended = 1;
        }
 
        do {
@@ -664,8 +661,6 @@
         * to the size it was before the write was attempted.
         */
 errexit:
-       if (resid > uio->uio_resid)
-               VN_KNOTE(vp, NOTE_WRITE | (extended ? NOTE_EXTEND : 0));
        if (error) {
                detrunc(dep, osize, ioflag & IO_SYNC, NOCRED);
                uio->uio_offset -= resid - uio->uio_resid;
@@ -717,10 +712,11 @@
 int
 msdosfs_remove(void *v)
 {
-       struct vop_remove_v2_args /* {
+       struct vop_remove_v3_args /* {
                struct vnode *a_dvp;
                struct vnode *a_vp;
                struct componentname *a_cnp;
+               nlink_t ctx_vp_new_nlink;
        } */ *ap = v;
        struct denode *dep = VTODE(ap->a_vp);
        struct denode *ddep = VTODE(ap->a_dvp);
@@ -734,8 +730,6 @@
        printf("msdosfs_remove(), dep %p, usecount %d\n",
                dep, vrefcnt(ap->a_vp));
 #endif
-       VN_KNOTE(ap->a_vp, NOTE_DELETE);
-       VN_KNOTE(ap->a_dvp, NOTE_WRITE);
        if (ddep == dep)
                vrele(ap->a_vp);
        else
@@ -1255,7 +1249,6 @@
        ndirent.de_devvp = pdep->de_devvp;
        if ((error = createde(&ndirent, pdep, &dep, cnp)) != 0)
                goto bad;
-       VN_KNOTE(ap->a_dvp, NOTE_WRITE | NOTE_LINK);
        *ap->a_vpp = DETOV(dep);
        return (0);
 



Home | Main Index | Thread Index | Old Index