From owner-svn-src-projects@freebsd.org Thu Jul 26 03:13:09 2018 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E0EBD105D492 for ; Thu, 26 Jul 2018 03:13:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 974BD79ACA; Thu, 26 Jul 2018 03:13:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5E9F22346D; Thu, 26 Jul 2018 03:13:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6Q3D8gP008554; Thu, 26 Jul 2018 03:13:08 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6Q3D7So008550; Thu, 26 Jul 2018 03:13:07 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201807260313.w6Q3D7So008550@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 26 Jul 2018 03:13:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r336729 - projects/bectl/lib/libbe X-SVN-Group: projects X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: projects/bectl/lib/libbe X-SVN-Commit-Revision: 336729 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jul 2018 03:13:09 -0000 Author: kevans Date: Thu Jul 26 03:13:07 2018 New Revision: 336729 URL: https://svnweb.freebsd.org/changeset/base/336729 Log: libbe(3): Add be_mounted_at to check a mount point At a bare minimum, this function will return 0 if a BE is mounted at the given path or non-zero otherwise. If the optional 'details' nvlist is supplied, it is filled with an nvpair containing just the information about the BE mounted at the path. This nvpair is structured just as it is for be_get_bootenv_props, except limited to just the single mount point. Modified: projects/bectl/lib/libbe/be.h projects/bectl/lib/libbe/be_access.c projects/bectl/lib/libbe/be_impl.h projects/bectl/lib/libbe/be_info.c projects/bectl/lib/libbe/libbe.3 Modified: projects/bectl/lib/libbe/be.h ============================================================================== --- projects/bectl/lib/libbe/be.h Thu Jul 26 00:16:41 2018 (r336728) +++ projects/bectl/lib/libbe/be.h Thu Jul 26 03:13:07 2018 (r336729) @@ -98,6 +98,7 @@ typedef enum { int be_mount(libbe_handle_t *, char *, char *, int, char *); int be_unmount(libbe_handle_t *, char *, int); +int be_mounted_at(libbe_handle_t *, const char *path, nvlist_t *); /* Error related functions: be_error.c */ int libbe_errno(libbe_handle_t *); Modified: projects/bectl/lib/libbe/be_access.c ============================================================================== --- projects/bectl/lib/libbe/be_access.c Thu Jul 26 00:16:41 2018 (r336728) +++ projects/bectl/lib/libbe/be_access.c Thu Jul 26 03:13:07 2018 (r336729) @@ -29,6 +29,69 @@ #include "be.h" #include "be_impl.h" +struct be_mountcheck_info { + const char *path; + char *name; +}; + +static int +be_mountcheck_cb(zfs_handle_t *zfs_hdl, void *data) +{ + struct be_mountcheck_info *info; + char *mountpoint; + + if (data == NULL) + return (1); + info = (struct be_mountcheck_info *)data; + if (!zfs_is_mounted(zfs_hdl, &mountpoint)) + return (0); + if (strcmp(mountpoint, info->path) == 0) { + info->name = strdup(zfs_get_name(zfs_hdl)); + return (1); + } + return (0); +} + +/* + * usage + */ +int +be_mounted_at(libbe_handle_t *lbh, const char *path, nvlist_t *details) +{ + char be[BE_MAXPATHLEN + 1]; + zfs_handle_t *root_hdl; + struct be_mountcheck_info info; + prop_data_t propinfo; + + bzero(&be, BE_MAXPATHLEN + 1); + if ((root_hdl = zfs_open(lbh->lzh, lbh->root, + ZFS_TYPE_FILESYSTEM)) == NULL) + return (BE_ERR_ZFSOPEN); + + info.path = path; + info.name = NULL; + zfs_iter_filesystems(root_hdl, be_mountcheck_cb, &info); + zfs_close(root_hdl); + + if (info.name != NULL) { + if (details != NULL) { + if ((root_hdl = zfs_open(lbh->lzh, lbh->root, + ZFS_TYPE_FILESYSTEM)) == NULL) { + free(info.name); + return (BE_ERR_ZFSOPEN); + } + + propinfo.lbh = lbh; + propinfo.list = details; + prop_list_builder_cb(root_hdl, &propinfo); + zfs_close(root_hdl); + } + free(info.name); + return (0); + } + return (1); +} + /* * usage */ Modified: projects/bectl/lib/libbe/be_impl.h ============================================================================== --- projects/bectl/lib/libbe/be_impl.h Thu Jul 26 00:16:41 2018 (r336728) +++ projects/bectl/lib/libbe/be_impl.h Thu Jul 26 03:13:07 2018 (r336729) @@ -33,7 +33,6 @@ #include "be.h" - struct libbe_handle { libzfs_handle_t *lzh; zpool_handle_t *active_phandle; @@ -55,6 +54,14 @@ struct libbe_dccb { zfs_handle_t *zhp; nvlist_t *props; }; + +typedef struct prop_data { + nvlist_t *list; + libbe_handle_t *lbh; +} prop_data_t; + +int prop_list_builder_cb(zfs_handle_t *, void *); +int prop_list_builder(prop_data_t *); int set_error(libbe_handle_t *, be_error_t); Modified: projects/bectl/lib/libbe/be_info.c ============================================================================== --- projects/bectl/lib/libbe/be_info.c Thu Jul 26 00:16:41 2018 (r336728) +++ projects/bectl/lib/libbe/be_info.c Thu Jul 26 03:13:07 2018 (r336729) @@ -29,14 +29,6 @@ #include "be.h" #include "be_impl.h" -typedef struct prop_data { - nvlist_t *list; - libbe_handle_t *lbh; -} prop_data_t; - -static int prop_list_builder_cb(zfs_handle_t *, void *); -static int prop_list_builder(prop_data_t *); - /* * Returns the name of the active boot environment */ @@ -111,7 +103,7 @@ be_get_bootenv_props(libbe_handle_t *lbh, nvlist_t *ds * the bootenv root, populate an nvlist_t of its relevant properties. * TODO: should any other properties be included? */ -static int +int prop_list_builder_cb(zfs_handle_t *zfs_hdl, void *data_p) { char buf[512], *mountpoint; @@ -189,7 +181,7 @@ prop_list_builder_cb(zfs_handle_t *zfs_hdl, void *data * XXX TODO: ensure that this is always consistent (run after adds, deletes, * renames,etc */ -static int +int prop_list_builder(prop_data_t *data) { zfs_handle_t *root_hdl; Modified: projects/bectl/lib/libbe/libbe.3 ============================================================================== --- projects/bectl/lib/libbe/libbe.3 Thu Jul 26 00:16:41 2018 (r336728) +++ projects/bectl/lib/libbe/libbe.3 Thu Jul 26 03:13:07 2018 (r336729) @@ -97,6 +97,9 @@ of state to be retained, such as errors from previous .Fn be_mount "libbe_handle_t *, char *, char *, int" ; .Pp .Ft int +.Fn be_mounted_at "libbe_handle_t *, const char *, nvlist_t" ; +.Pp +.Ft int .Fn be_unmount "libbe_handle_t *, char *, int" ; .Pp .Ft int