Skip to content

Commit

Permalink
bectl(8): Start dumping out BE information with bectl list
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevans91 committed Jul 25, 2018
1 parent b4e1235 commit 9927174
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
3 changes: 2 additions & 1 deletion lib/libbe/be.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#ifndef _LIBBE_H
#define _LIBBE_H

#include <libnvpair.h>
#include <stdbool.h>

#define BE_MAXPATHLEN 512
Expand Down Expand Up @@ -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);

Expand Down
17 changes: 6 additions & 11 deletions lib/libbe/be_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions sbin/bectl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bsd.prog.mk>
19 changes: 16 additions & 3 deletions sbin/bectl/bectl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <sys/param.h>
#include <sys/jail.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <errno.h>
#include <stdbool.h>
Expand All @@ -38,7 +39,6 @@
#include <sysexits.h>
#include <unistd.h>

#include <sys/nv.h>
#include <be.h>

static int bectl_cmd_activate(int argc, char *argv[]);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 9927174

Please sign in to comment.