bectl(8): Take origin snapshot into account when calculating used space
This more closely matches the behavior for beadm. The associated libbe(3) API is still getting worked out a little bit.
This commit is contained in:
parent
7b80e16d36
commit
60ffd203c2
@ -67,6 +67,7 @@ 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 *);
|
||||
int be_get_snapshot_props(libbe_handle_t *, const char *, nvlist_t *);
|
||||
int be_prop_list_alloc(nvlist_t **be_list);
|
||||
void be_prop_list_free(nvlist_t *be_list);
|
||||
|
||||
|
@ -83,6 +83,7 @@ be_mounted_at(libbe_handle_t *lbh, const char *path, nvlist_t *details)
|
||||
|
||||
propinfo.lbh = lbh;
|
||||
propinfo.list = details;
|
||||
propinfo.single_object = false;
|
||||
prop_list_builder_cb(root_hdl, &propinfo);
|
||||
zfs_close(root_hdl);
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ struct libbe_dccb {
|
||||
typedef struct prop_data {
|
||||
nvlist_t *list;
|
||||
libbe_handle_t *lbh;
|
||||
bool single_object; /* list will contain props directly */
|
||||
} prop_data_t;
|
||||
|
||||
int prop_list_builder_cb(zfs_handle_t *, void *);
|
||||
|
@ -94,9 +94,28 @@ be_get_bootenv_props(libbe_handle_t *lbh, nvlist_t *dsnvl)
|
||||
|
||||
data.lbh = lbh;
|
||||
data.list = dsnvl;
|
||||
data.single_object = false;
|
||||
return (prop_list_builder(&data));
|
||||
}
|
||||
|
||||
int
|
||||
be_get_snapshot_props(libbe_handle_t *lbh, const char *name, nvlist_t *props)
|
||||
{
|
||||
zfs_handle_t *snap_hdl;
|
||||
prop_data_t data;
|
||||
int ret;
|
||||
|
||||
data.lbh = lbh;
|
||||
data.list = props;
|
||||
data.single_object = true;
|
||||
if ((snap_hdl = zfs_open(lbh->lzh, name,
|
||||
ZFS_TYPE_SNAPSHOT)) == NULL)
|
||||
return (BE_ERR_ZFSOPEN);
|
||||
|
||||
ret = prop_list_builder_cb(snap_hdl, &data);
|
||||
zfs_close(snap_hdl);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Internal callback function used by zfs_iter_filesystems. For each dataset in
|
||||
@ -121,7 +140,10 @@ prop_list_builder_cb(zfs_handle_t *zfs_hdl, void *data_p)
|
||||
data = (prop_data_t *)data_p;
|
||||
lbh = data->lbh;
|
||||
|
||||
nvlist_alloc(&props, NV_UNIQUE_NAME, KM_SLEEP);
|
||||
if (data->single_object)
|
||||
props = data->list;
|
||||
else
|
||||
nvlist_alloc(&props, NV_UNIQUE_NAME, KM_SLEEP);
|
||||
|
||||
dataset = zfs_get_name(zfs_hdl);
|
||||
nvlist_add_string(props, "dataset", dataset);
|
||||
@ -169,7 +191,8 @@ prop_list_builder_cb(zfs_handle_t *zfs_hdl, void *data_p)
|
||||
nvlist_add_boolean_value(props, "nextboot",
|
||||
(strcmp(be_nextboot_path(lbh), dataset) == 0));
|
||||
|
||||
nvlist_add_nvlist(data->list, name, props);
|
||||
if (!data->single_object)
|
||||
nvlist_add_nvlist(data->list, name, props);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -138,6 +138,9 @@ of state to be retained, such as errors from previous operations.
|
||||
.Ft int
|
||||
.Fn be_get_bootenv_props "libbe_handle_t *, nvlist_t *" ;
|
||||
.Pp
|
||||
.Ft int
|
||||
.Fn be_get_snapshot_props "libbe_handle_t *, const char *, nvlist_t *" ;
|
||||
.Pp
|
||||
.Ft void
|
||||
.Fn be_prop_list_free "nvlist_t *" ;
|
||||
.\" .Ft void
|
||||
|
@ -424,11 +424,12 @@ print_dataset(nvpair_t *cur, struct printc *pc)
|
||||
#define BUFSZ 64
|
||||
char buf[BUFSZ];
|
||||
unsigned long long ctimenum, space;
|
||||
nvlist_t *dsprops;
|
||||
nvlist_t *dsprops, *originprops;
|
||||
char *propstr;
|
||||
int active_colsz;
|
||||
boolean_t active_now, active_reboot;
|
||||
|
||||
originprops = NULL;
|
||||
propstr = nvpair_name(cur);
|
||||
/* XXX TODO: Some views show snapshots */
|
||||
if (strchr(propstr, '@') != NULL)
|
||||
@ -457,9 +458,27 @@ print_dataset(nvpair_t *cur, struct printc *pc)
|
||||
else
|
||||
printf("%*s ", pc->mount_colsz, "-");
|
||||
|
||||
if (nvlist_lookup_string(dsprops, "origin", &propstr) == 0) {
|
||||
if (be_prop_list_alloc(&originprops) != 0) {
|
||||
fprintf(stderr,
|
||||
"bectl list: failed to allocate origin prop nvlist\n");
|
||||
return;
|
||||
}
|
||||
if (be_get_snapshot_props(be, propstr, originprops) != 0) {
|
||||
/* XXX TODO: Real errors */
|
||||
fprintf(stderr,
|
||||
"bectl list: failed to fetch origin properties\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (nvlist_lookup_string(dsprops, "used", &propstr) == 0) {
|
||||
space = strtoull(propstr, NULL, 10);
|
||||
|
||||
if (originprops != NULL && nvlist_lookup_string(originprops,
|
||||
"used", &propstr) == 0)
|
||||
space += strtoull(propstr, NULL, 10);
|
||||
|
||||
/* Alas, there's more to it,. */
|
||||
humanize_number(buf, 6, space, "", HN_AUTOSCALE,
|
||||
HN_DECIMAL | HN_NOSPACE | HN_B);
|
||||
@ -475,6 +494,8 @@ print_dataset(nvpair_t *cur, struct printc *pc)
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
if (originprops != NULL)
|
||||
be_prop_list_free(originprops);
|
||||
#undef BUFSZ
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user