aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-08-04 06:29:46 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-08-04 06:29:46 +0000
commit344342064652974127eea595ac5aed37dd31c20d (patch)
tree1396d7e4d3ec8edc101b213cf5def3124523aaca /sbin
parent77d5a868a0a7c16bb2a478516bfbb0fd8883b924 (diff)
downloadsrc-344342064652974127eea595ac5aed37dd31c20d.tar.gz
src-344342064652974127eea595ac5aed37dd31c20d.zip
bectl(8): Sort BEs lightly by active (now or later) BE, then others
While it could be preferred to do this at insert in libbe(3), there's no convenient way to insert at the head of an nvlist. Instead, we'll make two passes over- once to print anything active either now or at nextboot, and another to print everything else. This doesn't actually impact performance in a significant way here, so we'll worry about further optimizations if the need actually arises.
Notes
Notes: svn path=/projects/bectl/; revision=337284
Diffstat (limited to 'sbin')
-rw-r--r--sbin/bectl/bectl.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/sbin/bectl/bectl.c b/sbin/bectl/bectl.c
index 59174d8ad5fa..9764ea6e443c 100644
--- a/sbin/bectl/bectl.c
+++ b/sbin/bectl/bectl.c
@@ -59,7 +59,6 @@ struct printc {
int current_indent;
int mount_colsz;
int space_colsz;
- bool final_be;
bool hide_headers;
bool show_all_datasets;
bool show_snaps;
@@ -489,8 +488,6 @@ print_info(const char *name, nvlist_t *dsprops, struct printc *pc)
nvlist_free(originprops);
}
pc->current_indent = 0;
- if (!pc->final_be)
- printf("\n");
return;
}
@@ -600,9 +597,11 @@ bectl_cmd_list(int argc, char *argv[])
struct printc pc;
nvpair_t *cur;
nvlist_t *dsprops, *props;
- int opt;
+ int opt, printed;
+ boolean_t active_now, active_reboot;
props = NULL;
+ printed = 0;
bzero(&pc, sizeof(pc));
while ((opt = getopt(argc, argv, "aDHs")) != -1) {
switch (opt) {
@@ -643,11 +642,38 @@ bectl_cmd_list(int argc, char *argv[])
}
print_headers(props, &pc);
+ /* Do a first pass to print active and next active first */
+ for (cur = nvlist_next_nvpair(props, NULL); cur != NULL;
+ cur = nvlist_next_nvpair(props, cur)) {
+ nvpair_value_nvlist(cur, &dsprops);
+ active_now = active_reboot = false;
+
+ nvlist_lookup_boolean_value(dsprops, "active", &active_now);
+ nvlist_lookup_boolean_value(dsprops, "nextboot",
+ &active_reboot);
+ if (!active_now && !active_reboot)
+ continue;
+ if (printed > 0 && (pc.show_all_datasets || pc.show_snaps))
+ printf("\n");
+ print_info(nvpair_name(cur), dsprops, &pc);
+ printed++;
+ }
+
+ /* Now pull everything else */
for (cur = nvlist_next_nvpair(props, NULL); cur != NULL;
cur = nvlist_next_nvpair(props, cur)) {
nvpair_value_nvlist(cur, &dsprops);
- pc.final_be = nvlist_next_nvpair(props, cur) == NULL;
+ active_now = active_reboot = false;
+
+ nvlist_lookup_boolean_value(dsprops, "active", &active_now);
+ nvlist_lookup_boolean_value(dsprops, "nextboot",
+ &active_reboot);
+ if (active_now || active_reboot)
+ continue;
+ if (printed > 0 && (pc.show_all_datasets || pc.show_snaps))
+ printf("\n");
print_info(nvpair_name(cur), dsprops, &pc);
+ printed++;
}
be_prop_list_free(props);