Source-Changes-HG archive

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

[src/trunk]: src/sys/fs/union Operation union_readdirhook() stores the lower ...



details:   https://anonhg.NetBSD.org/src/rev/365a992639c0
branches:  trunk
changeset: 942751:365a992639c0
user:      hannken <hannken%NetBSD.org@localhost>
date:      Tue Aug 18 09:44:07 2020 +0000

description:
Operation union_readdirhook() stores the lower directory as un_uppervp.
This breaks the assumption that un_uppervp->v_mount is the upper mount.

Fix by storing the directory as un_lowervp and adapt union_readdir().

Should fix PR kern/55552: panic with union mount

diffstat:

 sys/fs/union/union.h       |   3 ++-
 sys/fs/union/union_subr.c  |  11 +++++++----
 sys/fs/union/union_vnops.c |  30 +++++++++++++++++++++++-------
 3 files changed, 32 insertions(+), 12 deletions(-)

diffs (119 lines):

diff -r d2fd38c87afc -r 365a992639c0 sys/fs/union/union.h
--- a/sys/fs/union/union.h      Tue Aug 18 07:53:24 2020 +0000
+++ b/sys/fs/union/union.h      Tue Aug 18 09:44:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: union.h,v 1.29 2017/07/17 09:22:36 hannken Exp $       */
+/*     $NetBSD: union.h,v 1.30 2020/08/18 09:44:07 hannken Exp $       */
 
 /*
  * Copyright (c) 1994 The Regents of the University of California.
@@ -130,6 +130,7 @@
        char                    *un_path;       /* v: saved component name */
        int                     un_openl;       /* v: # of opens on lowervp */
        unsigned int            un_cflags;      /* c: cache flags */
+       bool                    un_hooknode;    /* :: from union_readdirhook */
        struct vnode            **un_dircache;  /* v: cached union stack */
        off_t                   un_uppersz;     /* l: size of upper object */
        off_t                   un_lowersz;     /* l: size of lower object */
diff -r d2fd38c87afc -r 365a992639c0 sys/fs/union/union_subr.c
--- a/sys/fs/union/union_subr.c Tue Aug 18 07:53:24 2020 +0000
+++ b/sys/fs/union/union_subr.c Tue Aug 18 09:44:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: union_subr.c,v 1.78 2020/02/23 15:46:41 ad Exp $       */
+/*     $NetBSD: union_subr.c,v 1.79 2020/08/18 09:44:07 hannken Exp $  */
 
 /*
  * Copyright (c) 1994
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: union_subr.c,v 1.78 2020/02/23 15:46:41 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_subr.c,v 1.79 2020/08/18 09:44:07 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -480,6 +480,7 @@
        un->un_dircache = 0;
        un->un_openl = 0;
        un->un_cflags = 0;
+       un->un_hooknode = false;
 
        un->un_uppersz = VNOVAL;
        un->un_lowersz = VNOVAL;
@@ -1067,7 +1068,7 @@
        } else {
                vpp = dircache;
                do {
-                       if (*vpp++ == VTOUNION(vp)->un_uppervp)
+                       if (*vpp++ == VTOUNION(vp)->un_lowervp)
                                break;
                } while (*vpp != NULLVP);
        }
@@ -1076,10 +1077,12 @@
                goto out;
 
        vref(*vpp);
-       error = union_allocvp(&nvp, vp->v_mount, NULLVP, NULLVP, 0, *vpp, NULLVP, 0);
+       error = union_allocvp(&nvp, vp->v_mount, NULLVP, NULLVP, 0,
+           NULLVP, *vpp, 0);
        if (!error) {
                vn_lock(nvp, LK_EXCLUSIVE | LK_RETRY);
                VTOUNION(vp)->un_dircache = 0;
+               VTOUNION(nvp)->un_hooknode = true;
                VTOUNION(nvp)->un_dircache = dircache;
        }
 
diff -r d2fd38c87afc -r 365a992639c0 sys/fs/union/union_vnops.c
--- a/sys/fs/union/union_vnops.c        Tue Aug 18 07:53:24 2020 +0000
+++ b/sys/fs/union/union_vnops.c        Tue Aug 18 09:44:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: union_vnops.c,v 1.73 2020/05/16 18:31:50 christos Exp $        */
+/*     $NetBSD: union_vnops.c,v 1.74 2020/08/18 09:44:07 hannken Exp $ */
 
 /*
  * Copyright (c) 1992, 1993, 1994, 1995
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.73 2020/05/16 18:31:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.74 2020/08/18 09:44:07 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1493,13 +1493,29 @@
                int a_ncookies;
        } */ *ap = v;
        struct union_node *un = VTOUNION(ap->a_vp);
-       struct vnode *uvp = un->un_uppervp;
+       struct vnode *vp;
+       int dolock, error;
 
-       if (uvp == NULLVP)
-               return (0);
+       if (un->un_hooknode) {
+               KASSERT(un->un_uppervp == NULLVP);
+               KASSERT(un->un_lowervp != NULLVP);
+               vp = un->un_lowervp;
+               dolock = 1;
+       } else {
+               vp = un->un_uppervp;
+               dolock = 0;
+       }
+       if (vp == NULLVP)
+               return 0;
 
-       ap->a_vp = uvp;
-       return (VCALL(uvp, VOFFSET(vop_readdir), ap));
+       if (dolock)
+               vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+       ap->a_vp = vp;
+       error = VCALL(vp, VOFFSET(vop_readdir), ap);
+       if (dolock)
+               VOP_UNLOCK(vp);
+
+       return error;
 }
 
 int



Home | Main Index | Thread Index | Old Index