From owner-svn-src-all@freebsd.org Tue Jun 11 14:26:15 2019 Return-Path: Delivered-To: svn-src-all@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 86A9215BCA75; Tue, 11 Jun 2019 14:26:15 +0000 (UTC) (envelope-from mav@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 20E4A8E81D; Tue, 11 Jun 2019 14:26:15 +0000 (UTC) (envelope-from mav@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 E982B2CDB; Tue, 11 Jun 2019 14:26:14 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x5BEQEvx015515; Tue, 11 Jun 2019 14:26:14 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x5BEQEmL015511; Tue, 11 Jun 2019 14:26:14 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201906111426.x5BEQEmL015511@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Tue, 11 Jun 2019 14:26:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r348917 - stable/12/cddl/contrib/opensolaris/cmd/zfs X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/12/cddl/contrib/opensolaris/cmd/zfs X-SVN-Commit-Revision: 348917 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 20E4A8E81D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.981,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jun 2019 14:26:15 -0000 Author: mav Date: Tue Jun 11 14:26:14 2019 New Revision: 348917 URL: https://svnweb.freebsd.org/changeset/base/348917 Log: MFC r348570: MFV r348568: 9466 add JSON output support to channel programs illumos/illumos-gate@5267591016146502784860802129b16dab6f135c Reviewed by: Matt Ahrens Reviewed by: Serapheim Dimitropoulos Reviewed by: Sara Hartse Reviewed by: John Kennedy Approved by: Dan McDonald Author: Alek Pinchuk Modified: stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs-program.8 stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs.8 stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c Directory Properties: stable/12/ (props changed) Modified: stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs-program.8 ============================================================================== --- stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs-program.8 Tue Jun 11 14:25:03 2019 (r348916) +++ stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs-program.8 Tue Jun 11 14:26:14 2019 (r348917) @@ -9,6 +9,7 @@ .\" .\" .\" Copyright (c) 2016, 2017 by Delphix. All rights reserved. +.\" Copyright (c) 2018 Datto Inc. .\" .Dd October 02, 2017 .Dt ZFS-PROGRAM 1M @@ -18,7 +19,7 @@ .Nd executes ZFS channel programs .Sh SYNOPSIS .Cm zfs program -.Op Fl n +.Op Fl jn .Op Fl t Ar instruction-limit .Op Fl m Ar memory-limit .Ar pool @@ -46,6 +47,11 @@ will be run on and any attempts to access or modify other pools will cause an error. .Sh OPTIONS .Bl -tag -width "-t" +.It Fl j +Display channel program output in JSON format. +When this flag is specified and standard output is empty - +channel program encountered an error. +The details of such an error will be printed to standard error in plain text. .It Fl n Executes a read-only channel program, which runs faster. The program cannot change on-disk state by calling functions from the Modified: stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs.8 ============================================================================== --- stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs.8 Tue Jun 11 14:25:03 2019 (r348916) +++ stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs.8 Tue Jun 11 14:26:14 2019 (r348917) @@ -29,6 +29,7 @@ .\" Copyright (c) 2014, Xin LI .\" Copyright (c) 2014-2015, The FreeBSD Foundation, All Rights Reserved. .\" Copyright 2018 Joyent, Inc. +.\" Copyright (c) 2018 Datto Inc. .\" .\" $FreeBSD$ .\" @@ -291,7 +292,7 @@ .Op Ar snapshot Ns | Ns Ar filesystem .Nm .Cm program -.Op Fl n +.Op Fl jn .Op Fl t Ar timeout .Op Fl m Ar memory_limit .Ar pool script @@ -3364,7 +3365,7 @@ Display the path's inode change time as the first colu .It Xo .Nm .Cm program -.Op Fl n +.Op Fl jn .Op Fl t Ar timeout .Op Fl m Ar memory_limit .Ar pool script @@ -3387,6 +3388,11 @@ For full documentation of the ZFS channel program inte page for .Xr zfs-program 8 . .Bl -tag -width indent +.It Fl j +Display channel program output in JSON format. +When this flag is specified and standard output is empty - +channel program encountered an error. +The details of such an error will be printed to standard error in plain text. .It Fl n Executes a read-only channel program, which runs faster. The program cannot change on-disk state by calling functions from Modified: stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c ============================================================================== --- stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c Tue Jun 11 14:25:03 2019 (r348916) +++ stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c Tue Jun 11 14:26:14 2019 (r348917) @@ -30,6 +30,7 @@ * Copyright (c) 2014 Integros [integros.com] * Copyright 2016 Igor Kozhukhov . * Copyright 2016 Nexenta Systems, Inc. + * Copyright (c) 2018 Datto Inc. */ #include @@ -351,7 +352,7 @@ get_usage(zfs_help_t idx) case HELP_BOOKMARK: return (gettext("\tbookmark \n")); case HELP_CHANNEL_PROGRAM: - return (gettext("\tprogram [-n] [-t ] " + return (gettext("\tprogram [-jn] [-t ] " "[-m ] " "[lua args...]\n")); } @@ -7238,12 +7239,12 @@ zfs_do_channel_program(int argc, char **argv) nvlist_t *outnvl; uint64_t instrlimit = ZCP_DEFAULT_INSTRLIMIT; uint64_t memlimit = ZCP_DEFAULT_MEMLIMIT; - boolean_t sync_flag = B_TRUE; + boolean_t sync_flag = B_TRUE, json_output = B_FALSE; zpool_handle_t *zhp; /* check options */ while (-1 != - (c = getopt(argc, argv, "nt:(instr-limit)m:(memory-limit)"))) { + (c = getopt(argc, argv, "jnt:(instr-limit)m:(memory-limit)"))) { switch (c) { case 't': case 'm': { @@ -7285,6 +7286,10 @@ zfs_do_channel_program(int argc, char **argv) sync_flag = B_FALSE; break; } + case 'j': { + json_output = B_TRUE; + break; + } case '?': (void) fprintf(stderr, gettext("invalid option '%c'\n"), optopt); @@ -7407,11 +7412,14 @@ zfs_do_channel_program(int argc, char **argv) gettext("Channel program execution failed:\n%s\n"), errstring); } else { - (void) printf("Channel program fully executed "); - if (nvlist_empty(outnvl)) { - (void) printf("with no return value.\n"); + if (json_output) { + (void) nvlist_print_json(stdout, outnvl); + } else if (nvlist_empty(outnvl)) { + (void) fprintf(stdout, gettext("Channel program fully " + "executed and did not produce output.\n")); } else { - (void) printf("with return value:\n"); + (void) fprintf(stdout, gettext("Channel program fully " + "executed and produced output:\n")); dump_nvlist(outnvl, 4); } }