The branch main has been updated by mjg:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=0d28d014c8552520879d3c4f75b3e89dd116eaa5

commit 0d28d014c8552520879d3c4f75b3e89dd116eaa5
Author:     Mateusz Guzik <[email protected]>
AuthorDate: 2021-08-26 11:49:41 +0000
Commit:     Mateusz Guzik <[email protected]>
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);
+               }
        }
 
        /*
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to