libbe(3): move altroot augmentation bits around a little bit
We could perhaps have a method that does this given a dataset, but it's yet clear that we'll always want to bypass the altroot when we grab the mountpoint. For now, we'll refactor things a bit so we grab the altroot length when libbe is initialized and have a common method that does the necessary augmentation (replace with / if it's the root, return a pointer to later in the string if not). This will be used in some upcoming work to make be_mount work properly for deep BEs. MFC after: 1 week
This commit is contained in:
parent
48665600ce
commit
044685cd18
@ -90,6 +90,7 @@ be_locate_rootfs(libbe_handle_t *lbh)
|
||||
libbe_handle_t *
|
||||
libbe_init(const char *root)
|
||||
{
|
||||
char altroot[MAXPATHLEN];
|
||||
libbe_handle_t *lbh;
|
||||
char *poolname, *pos;
|
||||
int pnamelen;
|
||||
@ -140,6 +141,11 @@ libbe_init(const char *root)
|
||||
sizeof(lbh->bootfs), NULL, true) != 0)
|
||||
goto err;
|
||||
|
||||
if (zpool_get_prop(lbh->active_phandle, ZPOOL_PROP_ALTROOT,
|
||||
altroot, sizeof(altroot), NULL, true) == 0 &&
|
||||
strcmp(altroot, "-") != 0)
|
||||
lbh->altroot_len = strlen(altroot);
|
||||
|
||||
return (lbh);
|
||||
err:
|
||||
if (lbh != NULL) {
|
||||
@ -314,7 +320,6 @@ be_create(libbe_handle_t *lbh, const char *name)
|
||||
return (set_error(lbh, err));
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
be_deep_clone_prop(int prop, void *cb)
|
||||
{
|
||||
@ -345,12 +350,9 @@ be_deep_clone_prop(int prop, void *cb)
|
||||
|
||||
/* Augment mountpoint with altroot, if needed */
|
||||
val = pval;
|
||||
if (prop == ZFS_PROP_MOUNTPOINT && *dccb->altroot != '\0') {
|
||||
if (pval[strlen(dccb->altroot)] == '\0')
|
||||
strlcpy(pval, "/", sizeof(pval));
|
||||
else
|
||||
val = pval + strlen(dccb->altroot);
|
||||
}
|
||||
if (prop == ZFS_PROP_MOUNTPOINT)
|
||||
val = be_mountpoint_augmented(dccb->lbh, val);
|
||||
|
||||
nvlist_add_string(dccb->props, zfs_prop_to_name(prop), val);
|
||||
|
||||
return (ZPROP_CONT);
|
||||
@ -392,12 +394,9 @@ be_deep_clone(zfs_handle_t *ds, void *data)
|
||||
nvlist_alloc(&props, NV_UNIQUE_NAME, KM_SLEEP);
|
||||
nvlist_add_string(props, "canmount", "noauto");
|
||||
|
||||
dccb.lbh = isdc->lbh;
|
||||
dccb.zhp = ds;
|
||||
dccb.props = props;
|
||||
if (zpool_get_prop(isdc->lbh->active_phandle, ZPOOL_PROP_ALTROOT,
|
||||
dccb.altroot, sizeof(dccb.altroot), NULL, true) != 0 ||
|
||||
strcmp(dccb.altroot, "-") == 0)
|
||||
*dccb.altroot = '\0';
|
||||
if (zprop_iter(be_deep_clone_prop, &dccb, B_FALSE, B_FALSE,
|
||||
ZFS_TYPE_FILESYSTEM) == ZPROP_INVAL)
|
||||
return (-1);
|
||||
|
@ -195,3 +195,25 @@ be_unmount(libbe_handle_t *lbh, char *bootenv, int flags)
|
||||
|
||||
return (BE_ERR_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will blow away the input buffer as needed if we're discovered
|
||||
* to be looking at a root-mount. If the mountpoint is naturally beyond the
|
||||
* root, however, the buffer may be left intact and a pointer to the section
|
||||
* past altroot will be returned instead for the caller's perusal.
|
||||
*/
|
||||
char *
|
||||
be_mountpoint_augmented(libbe_handle_t *lbh, char *mountpoint)
|
||||
{
|
||||
|
||||
if (lbh->altroot_len == 0)
|
||||
return (mountpoint);
|
||||
if (mountpoint == NULL || *mountpoint == '\0')
|
||||
return (mountpoint);
|
||||
|
||||
if (mountpoint[lbh->altroot_len] == '\0') {
|
||||
*(mountpoint + 1) = '\0';
|
||||
return (mountpoint);
|
||||
} else
|
||||
return (mountpoint + lbh->altroot_len);
|
||||
}
|
||||
|
@ -36,11 +36,12 @@
|
||||
#include "be.h"
|
||||
|
||||
struct libbe_handle {
|
||||
libzfs_handle_t *lzh;
|
||||
zpool_handle_t *active_phandle;
|
||||
char root[BE_MAXPATHLEN];
|
||||
char rootfs[BE_MAXPATHLEN];
|
||||
char bootfs[BE_MAXPATHLEN];
|
||||
size_t altroot_len;
|
||||
zpool_handle_t *active_phandle;
|
||||
libzfs_handle_t *lzh;
|
||||
be_error_t error;
|
||||
bool print_on_err;
|
||||
};
|
||||
@ -53,9 +54,9 @@ struct libbe_deep_clone {
|
||||
};
|
||||
|
||||
struct libbe_dccb {
|
||||
libbe_handle_t *lbh;
|
||||
zfs_handle_t *zhp;
|
||||
nvlist_t *props;
|
||||
char altroot[MAXPATHLEN];
|
||||
};
|
||||
|
||||
typedef struct prop_data {
|
||||
@ -67,6 +68,8 @@ typedef struct prop_data {
|
||||
int prop_list_builder_cb(zfs_handle_t *, void *);
|
||||
int be_proplist_update(prop_data_t *);
|
||||
|
||||
char *be_mountpoint_augmented(libbe_handle_t *lbh, char *mountpoint);
|
||||
|
||||
/* Clobbers any previous errors */
|
||||
int set_error(libbe_handle_t *, be_error_t);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user