From 3682d5e902c1b159611c14dc3ef16c436b18b8a8 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Wed, 25 Jul 2018 14:30:47 +0000 Subject: [PATCH] bectl(8): Start dumping out BE information with `bectl list` For the moment, this is a primitive nvlist dump of what we get back from be_get_bootenv_props as a proof-of-concept and to make sure that we're getting back the kind of information we want to see from list. --- lib/libbe/be.h | 3 ++- lib/libbe/be_info.c | 17 ++++++----------- sbin/bectl/Makefile | 6 ++++++ sbin/bectl/bectl.c | 19 ++++++++++++++++--- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/lib/libbe/be.h b/lib/libbe/be.h index 8a352ad9a642..66ac8c104714 100644 --- a/lib/libbe/be.h +++ b/lib/libbe/be.h @@ -29,6 +29,7 @@ #ifndef _LIBBE_H #define _LIBBE_H +#include #include #define BE_MAXPATHLEN 512 @@ -63,7 +64,7 @@ const char *be_active_name(libbe_handle_t *); const char *be_active_path(libbe_handle_t *); const char *be_root_path(libbe_handle_t *); -/* nvlist_t *be_get_bootenv_props(libbe_handle_t *); */ +int be_get_bootenv_props(libbe_handle_t *, nvlist_t *); int be_activate(libbe_handle_t *, char *, bool); diff --git a/lib/libbe/be_info.c b/lib/libbe/be_info.c index 1576ca58e635..9219d7a75f98 100644 --- a/lib/libbe/be_info.c +++ b/lib/libbe/be_info.c @@ -71,18 +71,17 @@ be_root_path(libbe_handle_t *lbh) /* - * Returns an nvlist of the bootenv's properties - * TODO: the nvlist should be passed as a param and ints should return status + * Populates dsnvl with one nvlist per bootenv dataset describing the properties + * of that dataset that we've declared ourselves to care about. */ -nvlist_t * -be_get_bootenv_props(libbe_handle_t *lbh) +int +be_get_bootenv_props(libbe_handle_t *lbh, nvlist_t *dsnvl) { prop_data_t data; data.lbh = lbh; - prop_list_builder(&data); - - return (data.list); + data.list = dsnvl; + return (prop_list_builder(&data)); } @@ -177,10 +176,6 @@ prop_list_builder(prop_data_t *data) { zfs_handle_t *root_hdl; - if (nvlist_alloc(&(data->list), NV_UNIQUE_NAME, KM_SLEEP) != 0) - /* XXX TODO: actually handle error */ - return (1); - if ((root_hdl = zfs_open(data->lbh->lzh, data->lbh->root, ZFS_TYPE_FILESYSTEM)) == NULL) return (BE_ERR_ZFSOPEN); diff --git a/sbin/bectl/Makefile b/sbin/bectl/Makefile index a97df7241dee..6f635a71d9bf 100644 --- a/sbin/bectl/Makefile +++ b/sbin/bectl/Makefile @@ -7,4 +7,10 @@ MAN= bectl.8 LIBADD+= be LIBADD+= nvpair +CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzfs/common +CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris +CFLAGS+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common + +CFLAGS+= -DNEED_SOLARIS_BOOLEAN + .include diff --git a/sbin/bectl/bectl.c b/sbin/bectl/bectl.c index cc47399b7ac8..d0ef1422051b 100644 --- a/sbin/bectl/bectl.c +++ b/sbin/bectl/bectl.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -38,7 +39,6 @@ #include #include -#include #include static int bectl_cmd_activate(int argc, char *argv[]); @@ -417,8 +417,8 @@ bectl_cmd_jail(int argc, char *argv[]) static int bectl_cmd_list(int argc, char *argv[]) { - char *bootenv; nvlist_t *props; + char *bootenv; int opt; bool show_all_datasets, show_space, hide_headers, show_snaps; @@ -451,7 +451,20 @@ bectl_cmd_list(int argc, char *argv[]) return (usage(false)); } - /* props = be_get_bootenv_props(be); */ + + if (nvlist_alloc(&props, NV_UNIQUE_NAME, M_WAITOK) != 0) { + fprintf(stderr, "bectl list: failed to allocate prop nvlist\n"); + return (1); + } + if (be_get_bootenv_props(be, props) != 0) { + /* XXX TODO: Real errors */ + fprintf(stderr, "bectl list: failed to fetch boot environments\n"); + return (1); + } + + dump_nvlist(props, 0); + nvlist_free(props); + return (0); }