Date: Sat, 4 Aug 2018 06:29:47 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r337284 - projects/bectl/sbin/bectl Message-ID: <201808040629.w746Tl0O071290@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Sat Aug 4 06:29:46 2018 New Revision: 337284 URL: https://svnweb.freebsd.org/changeset/base/337284 Log: 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. Modified: projects/bectl/sbin/bectl/bectl.c Modified: projects/bectl/sbin/bectl/bectl.c ============================================================================== --- projects/bectl/sbin/bectl/bectl.c Sat Aug 4 06:14:54 2018 (r337283) +++ projects/bectl/sbin/bectl/bectl.c Sat Aug 4 06:29:46 2018 (r337284) @@ -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 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); - 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++; + } + + /* Now pull everything else */ + 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++; } be_prop_list_free(props);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808040629.w746Tl0O071290>