From ff8676cc4e02c6e138f2f3b68a6903dc418e5cc4 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Wed, 25 Jul 2018 14:45:00 +0000 Subject: [PATCH] libbe(3): Add nextboot flag to returned BE information --- lib/libbe/be.c | 3 +++ lib/libbe/be.h | 2 ++ lib/libbe/be_info.c | 24 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/libbe/be.c b/lib/libbe/be.c index c4e31b3b9a3e..934cdaf21f9f 100644 --- a/lib/libbe/be.c +++ b/lib/libbe/be.c @@ -138,6 +138,9 @@ libbe_init(void) zfs_iter_filesystems(rootds, be_locate_rootfs, lbh); zfs_close(rootds); + rootds = NULL; + if (lbh->rootfs == NULL) + goto err; return (lbh); err: diff --git a/lib/libbe/be.h b/lib/libbe/be.h index 66ac8c104714..2727c1cdfeee 100644 --- a/lib/libbe/be.h +++ b/lib/libbe/be.h @@ -62,6 +62,8 @@ void libbe_close(libbe_handle_t *); /* Bootenv information functions: be_info.c */ const char *be_active_name(libbe_handle_t *); const char *be_active_path(libbe_handle_t *); +const char *be_nextboot_name(libbe_handle_t *); +const char *be_nextboot_path(libbe_handle_t *); const char *be_root_path(libbe_handle_t *); int be_get_bootenv_props(libbe_handle_t *, nvlist_t *); diff --git a/lib/libbe/be_info.c b/lib/libbe/be_info.c index 9219d7a75f98..6a7e445a5d56 100644 --- a/lib/libbe/be_info.c +++ b/lib/libbe/be_info.c @@ -58,6 +58,27 @@ be_active_path(libbe_handle_t *lbh) return (lbh->rootfs); } +/* + * Returns the name of the next active boot environment + */ +const char * +be_nextboot_name(libbe_handle_t *lbh) +{ + + return (strrchr(lbh->bootfs, '/') + sizeof(char)); +} + + +/* + * Returns full path of the active boot environment + */ +const char * +be_nextboot_path(libbe_handle_t *lbh) +{ + + return (lbh->bootfs); +} + /* * Returns the path of the boot environment root dataset @@ -157,7 +178,8 @@ prop_list_builder_cb(zfs_handle_t *zfs_hdl, void *data_p) NULL, NULL, 0, 1)) nvlist_add_string(props, "referenced", buf); - /* XXX TODO: Add bootfs info */ + nvlist_add_boolean_value(props, "nextboot", + (strcmp(be_nextboot_path(lbh), dataset) == 0)); nvlist_add_nvlist(data->list, name, props);