From owner-svn-src-projects@freebsd.org Thu Jul 26 18:56:51 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 3FFC110573EC for ; Thu, 26 Jul 2018 18:56:51 +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 E5B8C744E2; Thu, 26 Jul 2018 18:56:50 +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 C3F145489; Thu, 26 Jul 2018 18:56:50 +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 w6QIuoY9090935; Thu, 26 Jul 2018 18:56:50 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6QIuo6C090934; Thu, 26 Jul 2018 18:56:50 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201807261856.w6QIuo6C090934@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 26 Jul 2018 18:56:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r336747 - 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: 336747 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: Thu, 26 Jul 2018 18:56:51 -0000 Author: kevans Date: Thu Jul 26 18:56:50 2018 New Revision: 336747 URL: https://svnweb.freebsd.org/changeset/base/336747 Log: bectl(8): Hack together a more proper `bectl list` Note that the space is currently just the 'used' property of the dataset. Modified: projects/bectl/sbin/bectl/Makefile projects/bectl/sbin/bectl/bectl.c Modified: projects/bectl/sbin/bectl/Makefile ============================================================================== --- projects/bectl/sbin/bectl/Makefile Thu Jul 26 18:34:38 2018 (r336746) +++ projects/bectl/sbin/bectl/Makefile Thu Jul 26 18:56:50 2018 (r336747) @@ -6,6 +6,7 @@ MAN= bectl.8 LIBADD+= be LIBADD+= jail LIBADD+= nvpair +LIBADD+= util CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libzfs/common CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris Modified: projects/bectl/sbin/bectl/bectl.c ============================================================================== --- projects/bectl/sbin/bectl/bectl.c Thu Jul 26 18:34:38 2018 (r336746) +++ projects/bectl/sbin/bectl/bectl.c Thu Jul 26 18:56:50 2018 (r336747) @@ -31,16 +31,24 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include +#define HEADER_BE "BE" +#define HEADER_ACTIVE "Active" +#define HEADER_MOUNT "Mountpoint" +#define HEADER_SPACE "Space" +#define HEADER_CREATED "Created" + static int bectl_cmd_activate(int argc, char *argv[]); static int bectl_cmd_create(int argc, char *argv[]); static int bectl_cmd_destroy(int argc, char *argv[]); @@ -406,8 +414,14 @@ bectl_cmd_jail(int argc, char *argv[]) static int bectl_cmd_list(int argc, char *argv[]) { - nvlist_t *props; - int opt; +#define BUFSZ 64 + nvpair_t *cur; + nvlist_t *props, *dsprops; + unsigned long long ctimenum, space; + size_t be_maxcol; + int active_colsz, active_colsz_def, be_colsz, mount_colsz, opt, space_colsz; + char buf[BUFSZ], *creation, *mnt, *spacestr; + boolean_t active_now, active_reboot; bool show_all_datasets, show_space, hide_headers, show_snaps; props = NULL; @@ -450,10 +464,69 @@ bectl_cmd_list(int argc, char *argv[]) return (1); } - dump_nvlist(props, 0); + be_maxcol = strlen(HEADER_BE); + for (cur = nvlist_next_nvpair(props, NULL); cur != NULL; + cur = nvlist_next_nvpair(props, cur)) { + be_maxcol = MAX(be_maxcol, strlen(nvpair_name(cur))); + } + + be_colsz = -be_maxcol; + /* To be made negative after calculating final col sz */ + active_colsz_def = strlen(HEADER_ACTIVE); + mount_colsz = -(int)strlen(HEADER_MOUNT); + space_colsz = -(int)strlen(HEADER_SPACE); + printf("%*s %s %s %s %s\n", be_colsz, HEADER_BE, HEADER_ACTIVE, + HEADER_MOUNT, HEADER_SPACE, HEADER_CREATED); + buf[5] = '\0'; + cur = NULL; + for (cur = nvlist_next_nvpair(props, NULL); cur != NULL; + cur = nvlist_next_nvpair(props, cur)) { + printf("%*s ", be_colsz, nvpair_name(cur)); + // NR + active_colsz = active_colsz_def; + nvpair_value_nvlist(cur, &dsprops); + if (nvlist_lookup_boolean_value(dsprops, "active", + &active_now) == 0 && active_now) { + printf("N"); + active_colsz--; + } + if (nvlist_lookup_boolean_value(dsprops, "nextboot", + &active_reboot) == 0 && active_reboot) { + printf("R"); + active_colsz--; + } + if (active_colsz == active_colsz_def) { + printf("-"); + active_colsz--; + } + printf("%*s ", -active_colsz, " "); + if (nvlist_lookup_string(dsprops, "mountpoint", &mnt) == 0) + printf("%*s ", mount_colsz, mnt); + else + printf("%*s ", mount_colsz, "-"); + // used + if (nvlist_lookup_string(dsprops, "used", &spacestr) == 0) { + space = strtoull(spacestr, NULL, 10); + humanize_number(buf, 6, space, "", HN_AUTOSCALE, + HN_DECIMAL | HN_NOSPACE | HN_B); + printf("%*s ", space_colsz, buf); + } else + printf("%*s ", space_colsz, "-"); + + if (nvlist_lookup_string(dsprops, "creation", &creation) == 0) { + ctimenum = strtoull(creation, NULL, 10); + strftime(buf, BUFSZ, "%Y-%m-%d %H:%M", + localtime((time_t *)&ctimenum)); + printf("%s", buf); + } + + // creation + printf("\n"); + } be_prop_list_free(props); return (0); +#undef BUFSZ }