aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2019-06-03 19:09:39 +0000
committerAlexander Motin <mav@FreeBSD.org>2019-06-03 19:09:39 +0000
commit1425be644a4b132c371589ffb6f83dc10b4ee59e (patch)
tree948406ef4617250e15b35fa0b082b194c85d3dcf
parent299ed57f93e3bb2d334f247bcfc0cc77a169a65b (diff)
downloadsrc-1425be644a4b132c371589ffb6f83dc10b4ee59e.tar.gz
src-1425be644a4b132c371589ffb6f83dc10b4ee59e.zip
9466 add JSON output support to channel programs
illumos/illumos-gate@5267591016146502784860802129b16dab6f135c Reviewed by: Matt Ahrens <matt@delphix.com> Reviewed by: Serapheim Dimitropoulos <serapheim.dimitro@delphix.com> Reviewed by: Sara Hartse <sara.hartse@delphix.com> Reviewed by: John Kennedy <john.kennedy@delphix.com> Approved by: Dan McDonald <danmcd@joyent.com> Author: Alek Pinchuk <apinchuk@datto.com>
Notes
Notes: svn path=/vendor/illumos/dist/; revision=348568
-rw-r--r--cmd/zfs/zfs_main.c22
-rw-r--r--man/man1m/zfs-program.1m8
-rw-r--r--man/man1m/zfs.1m10
3 files changed, 30 insertions, 10 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c
index 9bea435f27e8..c071734a41c5 100644
--- a/cmd/zfs/zfs_main.c
+++ b/cmd/zfs/zfs_main.c
@@ -29,6 +29,7 @@
* Copyright (c) 2014 Integros [integros.com]
* Copyright 2016 Igor Kozhukhov <ikozhukhov@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);
}
}
diff --git a/man/man1m/zfs-program.1m b/man/man1m/zfs-program.1m
index 5fd4302fb8dc..98d9240ff8ad 100644
--- a/man/man1m/zfs-program.1m
+++ b/man/man1m/zfs-program.1m
@@ -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
diff --git a/man/man1m/zfs.1m b/man/man1m/zfs.1m
index 4ce0ddcad7f1..d27a3ee49f49 100644
--- a/man/man1m/zfs.1m
+++ b/man/man1m/zfs.1m
@@ -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 column of output.
.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