aboutsummaryrefslogtreecommitdiff
path: root/lib/libbe
diff options
context:
space:
mode:
authorR. Christian McDonald <rcm@FreeBSD.org>2024-01-26 16:39:38 +0000
committerR. Christian McDonald <rcm@FreeBSD.org>2024-01-29 15:07:49 +0000
commit5086b6ec32d5c82c3d0894eb7bd74a9b81480644 (patch)
tree16dc9ad1ba4ec2ecc793488a2d8759110b4cb69f /lib/libbe
parent31828075e456c042cabd47ff4eb127c5c19f16e0 (diff)
downloadsrc-5086b6ec32d5c82c3d0894eb7bd74a9b81480644.tar.gz
src-5086b6ec32d5c82c3d0894eb7bd74a9b81480644.zip
Diffstat (limited to 'lib/libbe')
-rw-r--r--lib/libbe/be.c23
-rw-r--r--lib/libbe/be_impl.h1
-rw-r--r--lib/libbe/be_info.c7
3 files changed, 23 insertions, 8 deletions
diff --git a/lib/libbe/be.c b/lib/libbe/be.c
index c74ec9b0f3dc..e61cfc9d68ae 100644
--- a/lib/libbe/be.c
+++ b/lib/libbe/be.c
@@ -175,6 +175,9 @@ libbe_init(const char *root)
strcmp(altroot, "-") != 0)
lbh->altroot_len = strlen(altroot);
+ (void) lzbe_get_boot_device(zpool_get_name(lbh->active_phandle),
+ &lbh->bootonce);
+
return (lbh);
err:
if (lbh != NULL) {
@@ -199,6 +202,8 @@ libbe_close(libbe_handle_t *lbh)
if (lbh->active_phandle != NULL)
zpool_close(lbh->active_phandle);
libzfs_fini(lbh->lzh);
+
+ free(lbh->bootonce);
free(lbh);
}
@@ -443,6 +448,12 @@ be_destroy_internal(libbe_handle_t *lbh, const char *name, int options,
return (set_error(lbh, BE_ERR_DESTROYMNT));
}
}
+
+ /* Handle destroying bootonce */
+ if (lbh->bootonce != NULL &&
+ strcmp(path, lbh->bootonce) == 0)
+ (void) lzbe_set_boot_device(
+ zpool_get_name(lbh->active_phandle), lzbe_add, NULL);
} else {
/*
* If we're initially destroying a snapshot, origin options do
@@ -1021,11 +1032,17 @@ be_rename(libbe_handle_t *lbh, const char *old, const char *new)
.nounmount = 1,
};
err = zfs_rename(zfs_hdl, full_new, flags);
+ if (err != 0)
+ goto error;
+
+ /* handle renaming bootonce */
+ if (lbh->bootonce != NULL &&
+ strcmp(full_old, lbh->bootonce) == 0)
+ err = be_activate(lbh, new, true);
+error:
zfs_close(zfs_hdl);
- if (err != 0)
- return (set_error(lbh, BE_ERR_UNKNOWN));
- return (0);
+ return (set_error(lbh, err));
}
diff --git a/lib/libbe/be_impl.h b/lib/libbe/be_impl.h
index d5fd26c4f072..0327f8abaa0a 100644
--- a/lib/libbe/be_impl.h
+++ b/lib/libbe/be_impl.h
@@ -36,6 +36,7 @@ struct libbe_handle {
char root[BE_MAXPATHLEN];
char rootfs[BE_MAXPATHLEN];
char bootfs[BE_MAXPATHLEN];
+ char *bootonce;
size_t altroot_len;
zpool_handle_t *active_phandle;
libzfs_handle_t *lzh;
diff --git a/lib/libbe/be_info.c b/lib/libbe/be_info.c
index 88a9b17bf421..509b56cb8cf5 100644
--- a/lib/libbe/be_info.c
+++ b/lib/libbe/be_info.c
@@ -181,8 +181,8 @@ prop_list_builder_cb(zfs_handle_t *zfs_hdl, void *data_p)
dataset = zfs_get_name(zfs_hdl);
nvlist_add_string(props, "dataset", dataset);
- if (data->bootonce != NULL &&
- strcmp(dataset, data->bootonce) == 0)
+ if (data->lbh->bootonce != NULL &&
+ strcmp(dataset, data->lbh->bootonce) == 0)
nvlist_add_boolean_value(props, "bootonce", true);
name = strrchr(dataset, '/') + 1;
@@ -252,9 +252,6 @@ be_proplist_update(prop_data_t *data)
ZFS_TYPE_FILESYSTEM)) == NULL)
return (BE_ERR_ZFSOPEN);
- (void) lzbe_get_boot_device(zpool_get_name(data->lbh->active_phandle),
- &data->bootonce);
-
/* XXX TODO: some error checking here */
zfs_iter_filesystems(root_hdl, prop_list_builder_cb, data);