Author: mav
Date: Mon Jun  3 19:09:39 2019
New Revision: 348568
URL: https://svnweb.freebsd.org/changeset/base/348568

Log:
  9466 add JSON output support to channel programs
  
  illumos/illumos-gate@5267591016146502784860802129b16dab6f135c
  
  Reviewed by: Matt Ahrens <m...@delphix.com>
  Reviewed by: Serapheim Dimitropoulos <serapheim.dimi...@delphix.com>
  Reviewed by: Sara Hartse <sara.har...@delphix.com>
  Reviewed by: John Kennedy <john.kenn...@delphix.com>
  Approved by: Dan McDonald <dan...@joyent.com>
  Author:     Alek Pinchuk <apinc...@datto.com>

Modified:
  vendor/illumos/dist/cmd/zfs/zfs_main.c
  vendor/illumos/dist/man/man1m/zfs-program.1m
  vendor/illumos/dist/man/man1m/zfs.1m

Modified: vendor/illumos/dist/cmd/zfs/zfs_main.c
==============================================================================
--- vendor/illumos/dist/cmd/zfs/zfs_main.c      Mon Jun  3 19:03:24 2019        
(r348567)
+++ vendor/illumos/dist/cmd/zfs/zfs_main.c      Mon Jun  3 19:09:39 2019        
(r348568)
@@ -29,6 +29,7 @@
  * Copyright (c) 2014 Integros [integros.com]
  * Copyright 2016 Igor Kozhukhov <ikozhuk...@gmail.com>.
  * Copyright 2016 Nexenta Systems, Inc.
+ * Copyright (c) 2018 Datto Inc.
  */
 
 #include <assert.h>
@@ -335,7 +336,7 @@ get_usage(zfs_help_t idx)
        case HELP_BOOKMARK:
                return (gettext("\tbookmark <snapshot> <bookmark>\n"));
        case HELP_CHANNEL_PROGRAM:
-               return (gettext("\tprogram [-n] [-t <instruction limit>] "
+               return (gettext("\tprogram [-jn] [-t <instruction limit>] "
                    "[-m <memory limit (b)>] <pool> <program file> "
                    "[lua args...]\n"));
        }
@@ -7072,12 +7073,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': {
@@ -7119,6 +7120,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);
@@ -7237,11 +7242,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);
                }
        }

Modified: vendor/illumos/dist/man/man1m/zfs-program.1m
==============================================================================
--- vendor/illumos/dist/man/man1m/zfs-program.1m        Mon Jun  3 19:03:24 
2019        (r348567)
+++ vendor/illumos/dist/man/man1m/zfs-program.1m        Mon Jun  3 19:09:39 
2019        (r348568)
@@ -9,6 +9,7 @@
 .\"
 .\"
 .\" Copyright (c) 2016, 2017 by Delphix. All rights reserved.
+.\" Copyright (c) 2018 Datto Inc.
 .\"
 .Dd January 21, 2016
 .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: vendor/illumos/dist/man/man1m/zfs.1m
==============================================================================
--- vendor/illumos/dist/man/man1m/zfs.1m        Mon Jun  3 19:03:24 2019        
(r348567)
+++ vendor/illumos/dist/man/man1m/zfs.1m        Mon Jun  3 19:09:39 2019        
(r348568)
@@ -28,6 +28,7 @@
 .\" Copyright (c) 2014 Integros [integros.com]
 .\" Copyright 2017 Nexenta Systems, Inc.
 .\" Copyright 2018 Joyent, Inc.
+.\" Copyright (c) 2018 Datto Inc.
 .\"
 .Dd Feb 10, 2018
 .Dt ZFS 1M
@@ -271,7 +272,7 @@
 .Ar snapshot 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
@@ -3472,7 +3473,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
@@ -3493,6 +3494,11 @@ Channel programs may only be run with root privileges.
 For full documentation of the ZFS channel program interface, see the manual
 page for
 .Bl -tag -width ""
+.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
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to