From nobody Tue Jan 20 04:09:42 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dwDP30jhbz6Nw9Q for ; Tue, 20 Jan 2026 04:09:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dwDP25lFYz3W3B for ; Tue, 20 Jan 2026 04:09:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768882182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CKcDFUBZu6eHayp8j/LylxdJ2QrZgOLzaSc6N1IjJJY=; b=S49NvalBn3Ff5hw8KJjvWc+4S5JwTLUitQBAcgXbVA1AY+iemTluII3MPSZwZGTYGSSmQB eNbiKM5ztqSySj06Cc75GowzFmKFLxENqMu1n5SE6cuqvCKc5TLOYqB7tm3C69y1w+pjFS krJlD59wpRkGNC3pXYgwdS5665eXtTcD1zmhz4zUbJbBoEgy3GidhGUmAHNMW9Cb/XiKDt Xi0sXpVTHveV8dvnme+9fn0Aja5sj3dQ6EO+sxqOtFNjM73T9f+kC7DGlipu4V8De5/UOg hla9zkSVMaoOe5ORkhtj3+T2/SRZF+8sscfUY79Twd4wMEumTMawj+q9cfZhdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768882182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CKcDFUBZu6eHayp8j/LylxdJ2QrZgOLzaSc6N1IjJJY=; b=KJxUhR3X0aIx/c7j+TKT2Lg3QKv4zDmOZxtpWM8HXdVD34JULWmoQ59o/LUxwukTU8ZVRa 2DZE2FxdEjHHnTCuLpU1QhbtxWFBOd62W9EQ6tr90WnkbTThoDiHB8Q8SerTFwxVlaKUBb 99UJuhRH/0+LQl9aN8eJob3PEBboojoQsour1kEd+ZlwOLgB/MTYH2FYBDW8OrWYiBaUSA x0kCEqMuJAiJjdFVZwn+uUbgt96+9XURYVVPOBLi58gcVLTDPr3zMxNLbvKVCnD74eWetQ bNwPD4XPKwCnLN46StNWsfPiaXjfvWrUxmV04JUAua4Qo2GSl2C3C5kMgXwafA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1768882182; a=rsa-sha256; cv=none; b=f88w64Y2uNV8JEp61AkduI3LnIXCTXLDtuvTSbSgd0kNL9EdvA6k7KaT6ajiJVUgJQM0Yd HcG+ZiJMakXJYW5Spl6tWERaShcV3Y4EuHQTUrqz4HILUVIOtTQlVF98sI7RfrPGOc3ZmC xfIIEHMmnfHzJhljzM0NudHw0/8IcFpjNzIWqijsTIH2IOAD2NkqdkiZITrWjpKTYDCMKL VeN/MVoM+kI71XRgfEzh2SMVow1RR95pY+afb3VKBIHjE4ThB25mMyOvs/AwoHvOPLRSWV UcmmLQM5l+RLDn/z9lfqDta4RmsJ0qJw+ME9aXmIS4hW02PAf1eqrz86ZFA/Fw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dwDP254xLz120Z for ; Tue, 20 Jan 2026 04:09:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2795c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 20 Jan 2026 04:09:42 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Rob Norris From: Kyle Evans Subject: git: 919c1e19058d - stable/14 - bectl: log modifying functions to zpool history List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 919c1e19058d2e214fa3c33498123adb6ca3366c Auto-Submitted: auto-generated Date: Tue, 20 Jan 2026 04:09:42 +0000 Message-Id: <696f0006.2795c.2a070bf1@gitrepo.freebsd.org> The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=919c1e19058d2e214fa3c33498123adb6ca3366c commit 919c1e19058d2e214fa3c33498123adb6ca3366c Author: Rob Norris AuthorDate: 2025-12-17 17:00:47 +0000 Commit: Kyle Evans CommitDate: 2026-01-20 04:08:09 +0000 bectl: log modifying functions to zpool history Modeled directly after the method used by the zfs/zpool commands: flag commands with a "please log me" flag, and when there, reconstruct the command line. On success, call the library function to add it to the log. (Majority of the change by Rob; minor edits by kevans@) Signed-off-by: Rob Norris Co-authored-by: Kyle Evans Sponsored by: Modirum MDPay Sponsored by: Klara, Inc. (cherry picked from commit 2a87929671e6e6919c18f2c25d60f2c73c3d18f4) --- lib/libbe/be.c | 12 +++++++++ lib/libbe/be.h | 2 ++ lib/libbe/libbe.3 | 16 ++++++++++-- sbin/bectl/bectl.c | 73 ++++++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 85 insertions(+), 18 deletions(-) diff --git a/lib/libbe/be.c b/lib/libbe/be.c index de98f3b5e69e..0eaf0e6a5477 100644 --- a/lib/libbe/be.c +++ b/lib/libbe/be.c @@ -1327,3 +1327,15 @@ be_activate(libbe_handle_t *lbh, const char *bootenv, bool temporary) return (BE_ERR_SUCCESS); } + +int +be_log_history(libbe_handle_t *lbh, const char *message) +{ + int err; + + err = zpool_log_history(lbh->lzh, message); + if (err) + return (set_error(lbh, BE_ERR_UNKNOWN)); + + return (BE_ERR_SUCCESS); +} diff --git a/lib/libbe/be.h b/lib/libbe/be.h index 01ee94fd03ca..d3f47c0604fe 100644 --- a/lib/libbe/be.h +++ b/lib/libbe/be.h @@ -107,6 +107,8 @@ int be_exists(libbe_handle_t *, const char *); int be_export(libbe_handle_t *, const char *, int fd); int be_import(libbe_handle_t *, const char *, int fd); +int be_log_history(libbe_handle_t *, const char *); + #if SOON int be_add_child(libbe_handle_t *, const char *, bool); #endif diff --git a/lib/libbe/libbe.3 b/lib/libbe/libbe.3 index c1bf52e42324..032a95a00c9d 100644 --- a/lib/libbe/libbe.3 +++ b/lib/libbe/libbe.3 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd April 25, 2025 +.Dd January 19, 2026 .Dt LIBBE 3 .Os .Sh NAME @@ -144,6 +144,9 @@ .Pp .Ft void .Fn be_prop_list_free "nvlist_t *prop_list" +.Pp +.Ft int +.Fn be_log_history "libbe_handle_t *hdl" "const char *message" .Sh DESCRIPTION .Nm interfaces with libzfs to provide a set of functions for various operations @@ -536,6 +539,14 @@ exactly as specified by The .Fn be_prop_list_free function will free the property list. +.Pp +The +.Fn be_log_history +function will log the given +.Fa message +to the zpool history, which can be later retrieved using the +.Xr zpool-history 8 +command. .Sh DIAGNOSTICS Upon error, one of the following values will be returned: .Bl -bullet -offset indent -compact @@ -583,7 +594,8 @@ BE_ERR_UNKNOWN BE_ERR_INVORIGIN .El .Sh SEE ALSO -.Xr bectl 8 +.Xr bectl 8 , +.Xr zpool-history 8 .Sh HISTORY .Nm and its corresponding command, diff --git a/sbin/bectl/bectl.c b/sbin/bectl/bectl.c index f37a1473680e..94bb9c6e5ea6 100644 --- a/sbin/bectl/bectl.c +++ b/sbin/bectl/bectl.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -77,27 +78,28 @@ struct command_map_entry { int (*fn)(int argc, char *argv[]); /* True if libbe_print_on_error should be disabled */ bool silent; + bool save_history; }; static struct command_map_entry command_map[] = { - { "activate", bectl_cmd_activate,false }, - { "create", bectl_cmd_create, false }, - { "destroy", bectl_cmd_destroy, false }, - { "export", bectl_cmd_export, false }, - { "import", bectl_cmd_import, false }, + { "activate", bectl_cmd_activate,false, true }, + { "create", bectl_cmd_create, false, true }, + { "destroy", bectl_cmd_destroy, false, true }, + { "export", bectl_cmd_export, false, true }, + { "import", bectl_cmd_import, false, true }, #if SOON - { "add", bectl_cmd_add, false }, + { "add", bectl_cmd_add, false, true }, #endif - { "jail", bectl_cmd_jail, false }, - { "list", bectl_cmd_list, false }, - { "mount", bectl_cmd_mount, false }, - { "rename", bectl_cmd_rename, false }, - { "unjail", bectl_cmd_unjail, false }, - { "ujail", bectl_cmd_unjail, false }, - { "unmount", bectl_cmd_unmount, false }, - { "umount", bectl_cmd_unmount, false }, - { "check", bectl_cmd_check, true }, + { "jail", bectl_cmd_jail, false, false }, + { "list", bectl_cmd_list, false, false }, + { "mount", bectl_cmd_mount, false, false }, + { "rename", bectl_cmd_rename, false, true }, + { "unjail", bectl_cmd_unjail, false, false }, + { "ujail", bectl_cmd_unjail, false, false }, + { "unmount", bectl_cmd_unmount, false, false }, + { "umount", bectl_cmd_unmount, false, false }, + { "check", bectl_cmd_check, true, false }, }; static struct command_map_entry * @@ -524,12 +526,42 @@ bectl_cmd_check(int argc, char *argv[] __unused) return (0); } +static char * +save_cmdline(int argc, char *argv[]) +{ + char *cmdline, *basename, *p; + int len, n, i; + + len = MAXPATHLEN * 2 + 1; /* HIS_MAX_RECORD_LEN from zfs.h */ + cmdline = p = malloc(len); + if (cmdline == NULL) + err(2, "malloc"); + + basename = strrchr(argv[0], '/'); + if (basename == NULL) + basename = argv[0]; + else + basename++; + + n = strlcpy(p, basename, len); + for (i = 1; i < argc; i++) { + if (n >= len) + break; + p += n; + *p++ = ' '; + len -= (n + 1); + n = strlcpy(p, argv[i], len); + } + + return (cmdline); +} + int main(int argc, char *argv[]) { struct command_map_entry *cmd; const char *command; - char *root = NULL; + char *root = NULL, *cmdline = NULL; int opt, rc; while ((opt = getopt(argc, argv, "hr:")) != -1) { @@ -566,10 +598,19 @@ main(int argc, char *argv[]) return (-1); } + if (cmd->save_history) + cmdline = save_cmdline(argc+optind, argv-optind); + libbe_print_on_error(be, !cmd->silent); rc = cmd->fn(argc, argv); + if (cmd->save_history) { + if (rc == 0) + be_log_history(be, cmdline); + free(cmdline); + } + libbe_close(be); return (rc); }