Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Nov 2018 19:19:37 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r340508 - head/lib/libbe
Message-ID:  <201811171919.wAHJJbXB026635@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Sat Nov 17 19:19:37 2018
New Revision: 340508
URL: https://svnweb.freebsd.org/changeset/base/340508

Log:
  libbe(3): Rewrite be_unmount to stop mucking with getmntinfo(2)
  
  Go through the ZFS layer instead; given a BE, we can derive the dataset,
  zfs_open it, then zfs_unmount. ZFS takes care of the dirty details and
  likely gets it more correct than we did for more interesting setups.
  
  MFC after:	3 days

Modified:
  head/lib/libbe/be_access.c

Modified: head/lib/libbe/be_access.c
==============================================================================
--- head/lib/libbe/be_access.c	Sat Nov 17 19:15:29 2018	(r340507)
+++ head/lib/libbe/be_access.c	Sat Nov 17 19:19:37 2018	(r340508)
@@ -164,37 +164,18 @@ be_unmount(libbe_handle_t *lbh, char *bootenv, int fla
 {
 	int err, mntflags;
 	char be[BE_MAXPATHLEN];
-	struct statfs *mntbuf;
-	int mntsize;
-	char *mntpath;
+	zfs_handle_t *root_hdl;
 
 	if ((err = be_root_concat(lbh, bootenv, be)) != 0)
 		return (set_error(lbh, err));
 
-	if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
-		if (errno == EIO)
-			return (set_error(lbh, BE_ERR_IO));
-		return (set_error(lbh, BE_ERR_NOMOUNT));
-	}
+	if ((root_hdl = zfs_open(lbh->lzh, be, ZFS_TYPE_FILESYSTEM)) == NULL)
+		return (set_error(lbh, BE_ERR_ZFSOPEN));
 
-	mntpath = NULL;
-	for (int i = 0; i < mntsize; ++i) {
-		/* 0x000000de is the type number of zfs */
-		if (mntbuf[i].f_type != 0x000000de)
-			continue;
+	mntflags = (flags & BE_MNT_FORCE) ? MS_FORCE : 0;
 
-		if (strcmp(mntbuf[i].f_mntfromname, be) == 0) {
-			mntpath = mntbuf[i].f_mntonname;
-			break;
-		}
-	}
-
-	if (mntpath == NULL)
-		return (set_error(lbh, BE_ERR_NOMOUNT));
-
-	mntflags = (flags & BE_MNT_FORCE) ? MNT_FORCE : 0;
-
-	if ((err = unmount(mntpath, mntflags)) != 0) {
+	if (zfs_unmount(root_hdl, NULL, mntflags) != 0) {
+		zfs_close(root_hdl);
 		switch (errno) {
 		case ENAMETOOLONG:
 			return (set_error(lbh, BE_ERR_PATHLEN));
@@ -210,6 +191,7 @@ be_unmount(libbe_handle_t *lbh, char *bootenv, int fla
 			return (set_error(lbh, BE_ERR_UNKNOWN));
 		}
 	}
+	zfs_close(root_hdl);
 
-	return (set_error(lbh, BE_ERR_SUCCESS));
+	return (BE_ERR_SUCCESS);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201811171919.wAHJJbXB026635>