From nobody Sun Feb 18 15:15:06 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Td8Np5BDfz59whg; Sun, 18 Feb 2024 15:15:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Td8Np4Xrvz44sW; Sun, 18 Feb 2024 15:15:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708269306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=H8ZYUq+y/CSOZjxB8+yvP5dk8SdcPopgA5MkJvywtD4=; b=DrF7PQo9ujxduNU5bjpw2JSJdZH+QDd/E3wMU4mSnGe/OISP9u9k3MZwlrJEIItKcylAq0 NIdLZY7N9TSVBRQkuIfLkZTW3p5Ou748VwarMKU3fCWm0JRswOvQP97A6pjyKLJt3RIz3Y bcAft5s4To3dRA0Ux53EoJKnHNRVhmEpQdO8t9hQQjmvwFqc2qUOdIVETNYATndgBZtC2q UUHL/CGxlzJ+OrfLdZGaSY0qXRe+HqI/iUnmWabiyVjTXRKafiYJFmjBWt/yqpDToZOcQq 5VRy0ADdBc5rT5pLgUiDCOjnmsOCST/SYmNLwqMTroH3z3NpQp7LYjBdY5Yniw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708269306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=H8ZYUq+y/CSOZjxB8+yvP5dk8SdcPopgA5MkJvywtD4=; b=ynmwkyYP+Td1xsccZzLuCgOtzKVyNONhp8UC1OzZ3KUzHVypDCLS0dssADGM5eIo9a+t0z WOp1FRR4pgsOp+XHdJUNXK1yWle0OULrIBIXBBzOHacPzcYp8v3jIcLEo7DMI9HK0Znlij JmkJpSAR8QnfaYWFVx8Qtkx68xQVM5mHrXhN4PMQ1SzPZQ06SZrIsvJsU5runpf7wlWSuu pXVuCj74X3zOWLybtZY4w0PJrOL1VQF4Htl3EISVzBsFo8K/DHP/XYybzB1Ccm7kVFD/2A 1iIq2ZHFc79P8JnQPXTOHR8XbQmpPJ7EZYyhaf498KGSJZg1V7++Dno7NxgYuw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708269306; a=rsa-sha256; cv=none; b=KmbIj17sTOA9Xv4d6Nm14/IWp8NPw5/y7SBFZQIo0/Tha4lPiIh5ZjI7hW42DrdiUjkOLW B6RryvjZfbizTvn8O0/rbuCYaU8VqNbhffx99nIaE8Un8Cnu4WSRUnBHfjayoDzxKtYIKB 8o1y9Oeid2+4hYuFUyx/QXWej60GhAEj4JaeMiGxBySWDTW9Ro2muxSXQfBVuVdySNDy+Y Oh5Aqo6GCU1SQx5OXa+czOOzRPQiSD8I7aVx0Di2Xh375XY9HylHe1bO7PlFMPPQqQjIHr stpDdxenolhehH8WVu52Ey8AH+Y5a1+maxggFH7u2q2fm6FIaMmZLI0mYFWdTA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Td8Np3bc6zvtf; Sun, 18 Feb 2024 15:15:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41IFF6nA008409; Sun, 18 Feb 2024 15:15:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41IFF68A008406; Sun, 18 Feb 2024 15:15:06 GMT (envelope-from git) Date: Sun, 18 Feb 2024 15:15:06 GMT Message-Id: <202402181515.41IFF68A008406@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Jason A. Harmening" Subject: git: cc3ec9f75978 - main - unionfs: cache upper/lower mount objects List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jah X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cc3ec9f7597882d36ee487fd436d1b90bed0ebfd Auto-Submitted: auto-generated The branch main has been updated by jah: URL: https://cgit.FreeBSD.org/src/commit/?id=cc3ec9f7597882d36ee487fd436d1b90bed0ebfd commit cc3ec9f7597882d36ee487fd436d1b90bed0ebfd Author: Jason A. Harmening AuthorDate: 2023-12-22 20:13:35 +0000 Commit: Jason A. Harmening CommitDate: 2024-02-18 15:14:05 +0000 unionfs: cache upper/lower mount objects Store the upper/lower FS mount objects in unionfs per-mount data and use these instead of the v_mount field of the upper/lower root vnodes. As described in the referenced PR, it is unsafe to access this field on the unionfs unmount path as ZFS rollback may have obliterated the v_mount field of the upper or lower root vnode. Use these stored objects to slightly simplify other code that needs access to the upper/lower mount objects as well. PR: 275870 Reported by: Karlo Miličević Tested by: Karlo Miličević Reviewed by: kib (prior version), olce MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D43815 --- sys/fs/unionfs/union.h | 2 ++ sys/fs/unionfs/union_vfsops.c | 37 ++++++++++++++++++++----------------- sys/fs/unionfs/union_vnops.c | 4 ++-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/sys/fs/unionfs/union.h b/sys/fs/unionfs/union.h index 01bc7185e5fc..0d678b4fed41 100644 --- a/sys/fs/unionfs/union.h +++ b/sys/fs/unionfs/union.h @@ -51,6 +51,8 @@ typedef enum _unionfs_whitemode { } unionfs_whitemode; struct unionfs_mount { + struct mount *um_lowermp; /* MNT_REFed lower mount object */ + struct mount *um_uppermp; /* MNT_REFed upper mount object */ struct vnode *um_lowervp; /* VREFed once */ struct vnode *um_uppervp; /* VREFed once */ struct vnode *um_rootvp; /* ROOT vnode */ diff --git a/sys/fs/unionfs/union_vfsops.c b/sys/fs/unionfs/union_vfsops.c index 6c801998fcfb..8635600549b1 100644 --- a/sys/fs/unionfs/union_vfsops.c +++ b/sys/fs/unionfs/union_vfsops.c @@ -71,7 +71,6 @@ static struct vfsops unionfs_vfsops; static int unionfs_domount(struct mount *mp) { - struct mount *lowermp, *uppermp; struct vnode *lowerrootvp; struct vnode *upperrootvp; struct unionfs_mount *ump; @@ -303,18 +302,18 @@ unionfs_domount(struct mount *mp) * reused until that happens. We assume the caller holds a reference * to lowerrootvp as it is the mount's covered vnode. */ - lowermp = vfs_register_upper_from_vp(ump->um_lowervp, mp, + ump->um_lowermp = vfs_register_upper_from_vp(ump->um_lowervp, mp, &ump->um_lower_link); - uppermp = vfs_register_upper_from_vp(ump->um_uppervp, mp, + ump->um_uppermp = vfs_register_upper_from_vp(ump->um_uppervp, mp, &ump->um_upper_link); vrele(upperrootvp); - if (lowermp == NULL || uppermp == NULL) { - if (lowermp != NULL) - vfs_unregister_upper(lowermp, &ump->um_lower_link); - if (uppermp != NULL) - vfs_unregister_upper(uppermp, &ump->um_upper_link); + if (ump->um_lowermp == NULL || ump->um_uppermp == NULL) { + if (ump->um_lowermp != NULL) + vfs_unregister_upper(ump->um_lowermp, &ump->um_lower_link); + if (ump->um_uppermp != NULL) + vfs_unregister_upper(ump->um_uppermp, &ump->um_upper_link); vflush(mp, 1, FORCECLOSE, curthread); free(ump, M_UNIONFSMNT); mp->mnt_data = NULL; @@ -346,8 +345,8 @@ unionfs_domount(struct mount *mp) } MNT_ILOCK(mp); - if ((lowermp->mnt_flag & MNT_LOCAL) != 0 && - (uppermp->mnt_flag & MNT_LOCAL) != 0) + if ((ump->um_lowermp->mnt_flag & MNT_LOCAL) != 0 && + (ump->um_uppermp->mnt_flag & MNT_LOCAL) != 0) mp->mnt_flag |= MNT_LOCAL; mp->mnt_kern_flag |= MNTK_NOMSYNC | MNTK_UNIONFS; MNT_IUNLOCK(mp); @@ -400,8 +399,8 @@ unionfs_unmount(struct mount *mp, int mntflags) vn_lock(mp->mnt_vnodecovered, LK_EXCLUSIVE | LK_RETRY | LK_CANRECURSE); mp->mnt_vnodecovered->v_vflag &= ~VV_CROSSLOCK; VOP_UNLOCK(mp->mnt_vnodecovered); - vfs_unregister_upper(ump->um_lowervp->v_mount, &ump->um_lower_link); - vfs_unregister_upper(ump->um_uppervp->v_mount, &ump->um_upper_link); + vfs_unregister_upper(ump->um_lowermp, &ump->um_lower_link); + vfs_unregister_upper(ump->um_uppermp, &ump->um_upper_link); free(ump, M_UNIONFSMNT); mp->mnt_data = NULL; @@ -439,7 +438,11 @@ unionfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg, bool unbusy; ump = MOUNTTOUNIONFSMOUNT(mp); - uppermp = atomic_load_ptr(&ump->um_uppervp->v_mount); + /* + * Issue a volatile load of um_uppermp here, as the mount may be + * torn down after we call vfs_unbusy(). + */ + uppermp = atomic_load_ptr(&ump->um_uppermp); KASSERT(*mp_busy == true, ("upper mount not busy")); /* * See comment in sys_quotactl() for an explanation of why the @@ -479,7 +482,7 @@ unionfs_statfs(struct mount *mp, struct statfs *sbp) mstat = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK | M_ZERO); - error = VFS_STATFS(ump->um_lowervp->v_mount, mstat); + error = VFS_STATFS(ump->um_lowermp, mstat); if (error) { free(mstat, M_STATFS); return (error); @@ -491,7 +494,7 @@ unionfs_statfs(struct mount *mp, struct statfs *sbp) lbsize = mstat->f_bsize; - error = VFS_STATFS(ump->um_uppervp->v_mount, mstat); + error = VFS_STATFS(ump->um_uppermp, mstat); if (error) { free(mstat, M_STATFS); return (error); @@ -558,10 +561,10 @@ unionfs_extattrctl(struct mount *mp, int cmd, struct vnode *filename_vp, unp = VTOUNIONFS(filename_vp); if (unp->un_uppervp != NULLVP) { - return (VFS_EXTATTRCTL(ump->um_uppervp->v_mount, cmd, + return (VFS_EXTATTRCTL(ump->um_uppermp, cmd, unp->un_uppervp, namespace, attrname)); } else { - return (VFS_EXTATTRCTL(ump->um_lowervp->v_mount, cmd, + return (VFS_EXTATTRCTL(ump->um_lowermp, cmd, unp->un_lowervp, namespace, attrname)); } } diff --git a/sys/fs/unionfs/union_vnops.c b/sys/fs/unionfs/union_vnops.c index 150fbffe0a4a..cb2bed925399 100644 --- a/sys/fs/unionfs/union_vnops.c +++ b/sys/fs/unionfs/union_vnops.c @@ -764,7 +764,7 @@ unionfs_access(struct vop_access_args *ap) if (lvp != NULLVP) { if (accmode & VWRITE) { - if (ump->um_uppervp->v_mount->mnt_flag & MNT_RDONLY) { + if ((ump->um_uppermp->mnt_flag & MNT_RDONLY) != 0) { switch (ap->a_vp->v_type) { case VREG: case VDIR: @@ -835,7 +835,7 @@ unionfs_getattr(struct vop_getattr_args *ap) error = VOP_GETATTR(lvp, ap->a_vap, ap->a_cred); - if (error == 0 && !(ump->um_uppervp->v_mount->mnt_flag & MNT_RDONLY)) { + if (error == 0 && (ump->um_uppermp->mnt_flag & MNT_RDONLY) == 0) { /* correct the attr toward shadow file/dir. */ if (ap->a_vp->v_type == VREG || ap->a_vp->v_type == VDIR) { unionfs_create_uppervattr_core(ump, ap->a_vap, &va, td);