aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/cmd
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2019-06-03 19:15:06 +0000
committerAlexander Motin <mav@FreeBSD.org>2019-06-03 19:15:06 +0000
commitce88141b274fbc7bab015938bcb07c1b1c9f0558 (patch)
tree7aa793a7797e9d29cd0cfd0c3ac395e086dc2e3b /cddl/contrib/opensolaris/cmd
parent63acab6a5bc61b9d47d03f21d339fa4dda6779e0 (diff)
parent1425be644a4b132c371589ffb6f83dc10b4ee59e (diff)
downloadsrc-ce88141b274fbc7bab015938bcb07c1b1c9f0558.tar.gz
src-ce88141b274fbc7bab015938bcb07c1b1c9f0558.zip
MFV r348568: 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=/head/; revision=348570
Diffstat (limited to 'cddl/contrib/opensolaris/cmd')
-rw-r--r--cddl/contrib/opensolaris/cmd/zfs/zfs-program.88
-rw-r--r--cddl/contrib/opensolaris/cmd/zfs/zfs.810
-rw-r--r--cddl/contrib/opensolaris/cmd/zfs/zfs_main.c22
3 files changed, 30 insertions, 10 deletions
diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs-program.8 b/cddl/contrib/opensolaris/cmd/zfs/zfs-program.8
index f7587a57c098..b0b007236eb1 100644
--- a/cddl/contrib/opensolaris/cmd/zfs/zfs-program.8
+++ b/cddl/contrib/opensolaris/cmd/zfs/zfs-program.8
@@ -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
diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs.8 b/cddl/contrib/opensolaris/cmd/zfs/zfs.8
index 3656f799ea98..d90bec46d06a 100644
--- a/cddl/contrib/opensolaris/cmd/zfs/zfs.8
+++ b/cddl/contrib/opensolaris/cmd/zfs/zfs.8
@@ -29,6 +29,7 @@
.\" Copyright (c) 2014, Xin LI <delphij@FreeBSD.org>
.\" 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 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
@@ -3387,6 +3388,11 @@ For full documentation of the ZFS channel program interface, see the manual
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
diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c
index 61c97834a312..232181a87345 100644
--- a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c
+++ b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c
@@ -30,6 +30,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>
@@ -351,7 +352,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"));
}
@@ -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);
}
}