From owner-dev-commits-src-main@freebsd.org Thu Aug 26 12:02:50 2021 Return-Path: Delivered-To: dev-commits-src-main@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 9E21D668D25; Thu, 26 Aug 2021 12:02:50 +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 4GwM1646Pkz3MZJ; Thu, 26 Aug 2021 12:02:50 +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 6AFFA7C16; Thu, 26 Aug 2021 12:02:50 +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 17QC2oEp080407; Thu, 26 Aug 2021 12:02:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17QC2oHH080406; Thu, 26 Aug 2021 12:02:50 GMT (envelope-from git) Date: Thu, 26 Aug 2021 12:02:50 GMT Message-Id: <202108261202.17QC2oHH080406@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: 0d28d014c855 - main - vfs: refactor kern_unmount MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0d28d014c8552520879d3c4f75b3e89dd116eaa5 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Aug 2021 12:02:50 -0000 The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=0d28d014c8552520879d3c4f75b3e89dd116eaa5 commit 0d28d014c8552520879d3c4f75b3e89dd116eaa5 Author: Mateusz Guzik AuthorDate: 2021-08-26 11:49:41 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-26 11:58:28 +0000 vfs: refactor kern_unmount Split unmounting by path and id in preparation for other changes. Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/kern/vfs_mount.c | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 2d955fc4889f..40581d9e6e79 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -1588,7 +1588,7 @@ kern_unmount(struct thread *td, const char *path, int flags) { struct nameidata nd; struct mount *mp; - char *pathbuf; + char *fsidbuf, *pathbuf; fsid_t fsid; int error; @@ -1599,22 +1599,34 @@ kern_unmount(struct thread *td, const char *path, int flags) return (error); } - pathbuf = malloc(MNAMELEN, M_TEMP, M_WAITOK); - error = copyinstr(path, pathbuf, MNAMELEN, NULL); - if (error) { - free(pathbuf, M_TEMP); - return (error); - } if (flags & MNT_BYFSID) { - AUDIT_ARG_TEXT(pathbuf); + fsidbuf = malloc(MNAMELEN, M_TEMP, M_WAITOK); + error = copyinstr(path, fsidbuf, MNAMELEN, NULL); + if (error) { + free(fsidbuf, M_TEMP); + return (error); + } + + AUDIT_ARG_TEXT(fsidbuf); /* Decode the filesystem ID. */ - if (sscanf(pathbuf, "FSID:%d:%d", &fsid.val[0], &fsid.val[1]) != 2) { - free(pathbuf, M_TEMP); + if (sscanf(fsidbuf, "FSID:%d:%d", &fsid.val[0], &fsid.val[1]) != 2) { + free(fsidbuf, M_TEMP); return (EINVAL); } mp = vfs_getvfs(&fsid); + free(fsidbuf, M_TEMP); + if (mp == NULL) { + return (ENOENT); + } } else { + pathbuf = malloc(MNAMELEN, M_TEMP, M_WAITOK); + error = copyinstr(path, pathbuf, MNAMELEN, NULL); + if (error) { + free(pathbuf, M_TEMP); + return (error); + } + /* * Try to find global path for path argument. */ @@ -1635,16 +1647,16 @@ kern_unmount(struct thread *td, const char *path, int flags) } } mtx_unlock(&mountlist_mtx); - } - free(pathbuf, M_TEMP); - if (mp == NULL) { - /* - * Previously we returned ENOENT for a nonexistent path and - * EINVAL for a non-mountpoint. We cannot tell these apart - * now, so in the !MNT_BYFSID case return the more likely - * EINVAL for compatibility. - */ - return ((flags & MNT_BYFSID) ? ENOENT : EINVAL); + free(pathbuf, M_TEMP); + if (mp == NULL) { + /* + * Previously we returned ENOENT for a nonexistent path and + * EINVAL for a non-mountpoint. We cannot tell these apart + * now, so in the !MNT_BYFSID case return the more likely + * EINVAL for compatibility. + */ + return (EINVAL); + } } /*