From owner-dev-commits-src-all@freebsd.org Thu Apr 15 09:50:07 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C688B5E8F05; Thu, 15 Apr 2021 09:50:07 +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 4FLZMM2gqmz3Q7K; Thu, 15 Apr 2021 09:50:07 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 1A1F76C7B; Thu, 15 Apr 2021 09:50:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13F9o7NH069104; Thu, 15 Apr 2021 09:50:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13F9o79v069100; Thu, 15 Apr 2021 09:50:07 GMT (envelope-from git) Date: Thu, 15 Apr 2021 09:50:07 GMT Message-Id: <202104150950.13F9o79v069100@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: a5970a529c2d - main - Make files opened with O_PATH to not block non-forced unmount MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a5970a529c2d952714f20e4bc6e529c74fd2b3b5 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Apr 2021 09:50:08 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a5970a529c2d952714f20e4bc6e529c74fd2b3b5 commit a5970a529c2d952714f20e4bc6e529c74fd2b3b5 Author: Konstantin Belousov AuthorDate: 2021-04-03 18:55:11 +0000 Commit: Konstantin Belousov CommitDate: 2021-04-15 09:48:27 +0000 Make files opened with O_PATH to not block non-forced unmount by only keeping hold count on the vnode, instead of the use count. Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D29323 --- lib/libc/sys/open.2 | 3 +++ sys/kern/kern_descrip.c | 6 +++--- sys/kern/vfs_lookup.c | 2 +- sys/kern/vfs_syscalls.c | 11 ++++++++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2 index f9c54bfc7581..06a877e34460 100644 --- a/lib/libc/sys/open.2 +++ b/lib/libc/sys/open.2 @@ -349,6 +349,9 @@ But operations like and any other that operate on file and not on file descriptor (except .Xr fstat 2 ), are not allowed. +File opened with the +.Dv O_PATH +flag does not prevent non-forced unmount of the volume it belongs to. See also the description of .Dv AT_EMPTY_PATH flag for diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 81af58fbddd1..a28e94634326 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -3430,7 +3430,7 @@ _fgetvp(struct thread *td, int fd, int flags, cap_rights_t *needrightsp, error = EINVAL; } else { *vpp = fp->f_vnode; - vrefact(*vpp); + vref(*vpp); } fdrop(fp, td); @@ -3466,7 +3466,7 @@ fgetvp_rights(struct thread *td, int fd, cap_rights_t *needrightsp, *havecaps = caps; *vpp = fp->f_vnode; - vrefact(*vpp); + vref(*vpp); fdrop(fp, td); return (0); @@ -4978,7 +4978,7 @@ path_close(struct file *fp, struct thread *td) { MPASS(fp->f_type == DTYPE_VNODE); fp->f_ops = &badfileops; - vrele(fp->f_vnode); + vdrop(fp->f_vnode); return (0); } diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index f979676f4c7d..3050275c1b6f 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -380,7 +380,7 @@ namei_setup(struct nameidata *ndp, struct vnode **dpp, struct pwd **pwdp) error = ENOTDIR; } else { *dpp = dfp->f_vnode; - vrefact(*dpp); + vref(*dpp); if ((dfp->f_flag & FSEARCH) != 0) cnp->cn_flags |= NOEXECCHECK; diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 5a1efcdec467..9130843f6761 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -896,7 +896,7 @@ sys_fchdir(struct thread *td, struct fchdir_args *uap) if (error != 0) return (error); vp = fp->f_vnode; - vrefact(vp); + vref(vp); fdrop(fp, td); vn_lock(vp, LK_SHARED | LK_RETRY); AUDIT_ARG_VNODE1(vp); @@ -1191,8 +1191,13 @@ kern_openat(struct thread *td, int fd, const char *path, enum uio_seg pathseg, if (fp->f_ops == &badfileops) { KASSERT(vp->v_type != VFIFO || (flags & O_PATH) != 0, ("Unexpected fifo fp %p vp %p", fp, vp)); - finit_vnode(fp, flags, NULL, (flags & O_PATH) != 0 ? - &path_fileops : &vnops); + if ((flags & O_PATH) != 0) { + finit_vnode(fp, flags, NULL, &path_fileops); + vhold(vp); + vunref(vp); + } else { + finit_vnode(fp, flags, NULL, &vnops); + } } VOP_UNLOCK(vp);