svn commit: r336729 - projects/bectl/lib/libbe
Kyle Evans
kevans at FreeBSD.org
Thu Jul 26 03:13:09 UTC 2018
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
More information about the svn-src-projects
mailing list