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.
This commit is contained in:
Kyle Evans 2018-07-26 03:13:07 +00:00
parent 734e362fa1
commit 843e39ce7b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/bectl/; revision=336729
5 changed files with 77 additions and 11 deletions

View File

@ -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 *);

View File

@ -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
*/

View File

@ -33,7 +33,6 @@
#include "be.h"
struct libbe_handle {
libzfs_handle_t *lzh;
zpool_handle_t *active_phandle;
@ -56,6 +55,14 @@ struct libbe_dccb {
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);
#endif /* _LIBBE_IMPL_H */

View File

@ -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 *dsnvl)
* 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_p)
* 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;

View File

@ -97,6 +97,9 @@ of state to be retained, such as errors from previous operations.
.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