bectl: Implement -D ("space if origin datasets were deleted")
This also accomplishes the following: - Proxy through zfs_nicenum as be_nicenum, because it looks better than humanize_number and would presumably be useful to other libbe consumers. - Rename be_get_snapshot_props to be_get_dataset_props, make it more useful
This commit is contained in:
parent
05fd3946e6
commit
411563c444
@ -171,6 +171,15 @@ libbe_close(libbe_handle_t *lbh)
|
||||
free(lbh);
|
||||
}
|
||||
|
||||
/*
|
||||
* Proxy through to libzfs for the moment.
|
||||
*/
|
||||
void
|
||||
be_nicenum(uint64_t num, char *buf, size_t buflen)
|
||||
{
|
||||
|
||||
zfs_nicenum(num, buf, buflen);
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy the boot environment or snapshot specified by the name
|
||||
|
@ -67,7 +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_get_dataset_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);
|
||||
|
||||
@ -116,5 +116,6 @@ int be_export(libbe_handle_t *, char *, int fd);
|
||||
int be_import(libbe_handle_t *, char *, int fd);
|
||||
|
||||
int be_add_child(libbe_handle_t *, char *, bool);
|
||||
void be_nicenum(uint64_t num, char *buf, size_t buflen);
|
||||
|
||||
#endif /* _LIBBE_H */
|
||||
|
@ -99,7 +99,7 @@ be_get_bootenv_props(libbe_handle_t *lbh, nvlist_t *dsnvl)
|
||||
}
|
||||
|
||||
int
|
||||
be_get_snapshot_props(libbe_handle_t *lbh, const char *name, nvlist_t *props)
|
||||
be_get_dataset_props(libbe_handle_t *lbh, const char *name, nvlist_t *props)
|
||||
{
|
||||
zfs_handle_t *snap_hdl;
|
||||
prop_data_t data;
|
||||
@ -109,7 +109,7 @@ be_get_snapshot_props(libbe_handle_t *lbh, const char *name, nvlist_t *props)
|
||||
data.list = props;
|
||||
data.single_object = true;
|
||||
if ((snap_hdl = zfs_open(lbh->lzh, name,
|
||||
ZFS_TYPE_SNAPSHOT)) == NULL)
|
||||
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT)) == NULL)
|
||||
return (BE_ERR_ZFSOPEN);
|
||||
|
||||
ret = prop_list_builder_cb(snap_hdl, &data);
|
||||
|
@ -88,6 +88,9 @@ of state to be retained, such as errors from previous operations.
|
||||
.Ft int
|
||||
.Fn be_destroy "libbe_handle_t *, char *, int" ;
|
||||
.Pp
|
||||
.Ft void
|
||||
.Fn be_nicenum "uint64_t, char *, size_t" ;
|
||||
.Pp
|
||||
.\" TODO: Write up of mount options
|
||||
.\" typedef enum {
|
||||
.\" BE_MNT_FORCE = 1 << 0,
|
||||
@ -139,7 +142,7 @@ of state to be retained, such as errors from previous operations.
|
||||
.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 *" ;
|
||||
.Fn be_get_dataset_props "libbe_handle_t *, const char *, nvlist_t *" ;
|
||||
.Pp
|
||||
.Ft void
|
||||
.Fn be_prop_list_free "nvlist_t *" ;
|
||||
|
@ -445,7 +445,7 @@ get_origin_props(nvlist_t *dsprops, nvlist_t **originprops)
|
||||
"bectl list: failed to allocate origin prop nvlist\n");
|
||||
return (NULL);
|
||||
}
|
||||
if (be_get_snapshot_props(be, propstr, *originprops) != 0) {
|
||||
if (be_get_dataset_props(be, propstr, *originprops) != 0) {
|
||||
/* XXX TODO: Real errors */
|
||||
fprintf(stderr,
|
||||
"bectl list: failed to fetch origin properties\n");
|
||||
@ -471,6 +471,40 @@ print_padding(const char *fval, int colsz, struct printc *pc)
|
||||
printf("%*s ", colsz, "");
|
||||
}
|
||||
|
||||
static unsigned long long
|
||||
dataset_space(const char *oname)
|
||||
{
|
||||
unsigned long long space;
|
||||
char *dsname, *propstr, *sep;
|
||||
nvlist_t *dsprops;
|
||||
|
||||
space = 0;
|
||||
dsname = strdup(oname);
|
||||
if (dsname == NULL)
|
||||
return (0);
|
||||
|
||||
if ((sep = strchr(dsname, '@')) != NULL)
|
||||
*sep = '\0';
|
||||
|
||||
if (be_prop_list_alloc(&dsprops) != 0) {
|
||||
free(dsname);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (be_get_dataset_props(be, dsname, dsprops) != 0) {
|
||||
nvlist_free(dsprops);
|
||||
free(dsname);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (nvlist_lookup_string(dsprops, "used", &propstr) == 0)
|
||||
space = strtoull(propstr, NULL, 10);
|
||||
|
||||
nvlist_free(dsprops);
|
||||
free(dsname);
|
||||
return (space);
|
||||
}
|
||||
|
||||
static void
|
||||
print_info(const char *name, nvlist_t *dsprops, struct printc *pc)
|
||||
{
|
||||
@ -529,7 +563,7 @@ print_info(const char *name, nvlist_t *dsprops, struct printc *pc)
|
||||
print_padding("-", pc->mount_colsz, pc);
|
||||
}
|
||||
|
||||
get_origin_props(dsprops, &originprops);
|
||||
oname = get_origin_props(dsprops, &originprops);
|
||||
|
||||
if (nvlist_lookup_string(dsprops, "used", &propstr) == 0) {
|
||||
space = strtoull(propstr, NULL, 10);
|
||||
@ -538,9 +572,12 @@ print_info(const char *name, nvlist_t *dsprops, struct printc *pc)
|
||||
nvlist_lookup_string(originprops, "used", &propstr) == 0)
|
||||
space += strtoull(propstr, NULL, 10);
|
||||
|
||||
if (!pc->show_all_datasets && pc->show_space && oname != NULL)
|
||||
/* Get the used space of the origin's dataset, too. */
|
||||
space += dataset_space(oname);
|
||||
|
||||
/* Alas, there's more to it,. */
|
||||
humanize_number(buf, 6, space, "", HN_AUTOSCALE,
|
||||
HN_DECIMAL | HN_NOSPACE | HN_B);
|
||||
be_nicenum(space, buf, 6);
|
||||
printf("%s", buf);
|
||||
print_padding(buf, pc->space_colsz, pc);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user