From owner-svn-src-projects@freebsd.org Sat Aug 4 06:29:48 2018 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DA723105FADD for ; Sat, 4 Aug 2018 06:29:47 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8006C87184; Sat, 4 Aug 2018 06:29:47 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5B3003C8E; Sat, 4 Aug 2018 06:29:47 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w746Tl83071291; Sat, 4 Aug 2018 06:29:47 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w746Tl0O071290; Sat, 4 Aug 2018 06:29:47 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808040629.w746Tl0O071290@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 4 Aug 2018 06:29:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r337284 - projects/bectl/sbin/bectl X-SVN-Group: projects X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: projects/bectl/sbin/bectl X-SVN-Commit-Revision: 337284 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Aug 2018 06:29:48 -0000 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);