Skip to content

Commit

Permalink
Add JSON output to zpool status
Browse files Browse the repository at this point in the history
Add a new option j to the zpool status command to cause json dump
of pool status to stdout

Co-authored-by: Stuart Maybee <[email protected]>
Co-authored-by: Olaf Faaland <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
  • Loading branch information
3 people committed May 16, 2024
1 parent 2566592 commit 7c96bcd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 13 additions & 3 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ get_usage(zpool_help_t idx)
"[<device> ...]\n"));
case HELP_STATUS:
return (gettext("\tstatus [--power] [-c [script1,script2,...]] "
"[-DegiLpPstvx] [-T d|u] [pool] ...\n"
"[-DegijLpPstvx] [-T d|u] [pool] ...\n"
"\t [interval [count]]\n"));
case HELP_UPGRADE:
return (gettext("\tupgrade\n"
Expand Down Expand Up @@ -2211,6 +2211,7 @@ typedef struct status_cbdata {
boolean_t cb_print_vdev_trim;
vdev_cmd_data_list_t *vcdl;
boolean_t cb_print_power;
boolean_t cb_print_json;
} status_cbdata_t;

/* Return 1 if string is NULL, empty, or whitespace; return 0 otherwise. */
Expand Down Expand Up @@ -8629,6 +8630,11 @@ status_callback(zpool_handle_t *zhp, void *data)

cbp->cb_count++;

if (cbp->cb_print__json) {
(void) nvlist_print_json(stdout, config);
return (0);
}

/*
* If we were given 'zpool status -x', only report those pools with
* problems.
Expand Down Expand Up @@ -9110,14 +9116,15 @@ status_callback(zpool_handle_t *zhp, void *data)
}

/*
* zpool status [-c [script1,script2,...]] [-DegiLpPstvx] [--power] [-T d|u] ...
* zpool status [-c [script1,script2,...]] [-DegijLpPstvx] [--power] [-T d|u]
* [pool] [interval [count]]
*
* -c CMD For each vdev, run command CMD
* -D Display dedup status (undocumented)
* -e Display only unhealthy vdevs
* -g Display guid for individual vdev name.
* -i Display vdev initialization status.
* -j Output json rather than formatted text.
* -L Follow links when resolving vdev path name.
* -p Display values in parsable (exact) format.
* -P Display full path for vdev name.
Expand Down Expand Up @@ -9146,7 +9153,7 @@ zpool_do_status(int argc, char **argv)
};

/* check options */
while ((c = getopt_long(argc, argv, "c:DegiLpPstT:vx", long_options,
while ((c = getopt_long(argc, argv, "c:DegijLpPstT:vx", long_options,
NULL)) != -1) {
switch (c) {
case 'c':
Expand Down Expand Up @@ -9185,6 +9192,9 @@ zpool_do_status(int argc, char **argv)
case 'i':
cb.cb_print_vdev_init = B_TRUE;
break;
case 'j':
cb.cb_print_json = B_TRUE;
break;
case 'L':
cb.cb_name_flags |= VDEV_NAME_FOLLOW_LINKS;
break;
Expand Down
6 changes: 5 additions & 1 deletion man/man8/zpool-status.8
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
.Sh SYNOPSIS
.Nm zpool
.Cm status
.Op Fl DegiLpPstvx
.Op Fl DegijLpPstvx
.Op Fl T Sy u Ns | Ns Sy d
.Op Fl c Op Ar SCRIPT1 Ns Oo , Ns Ar SCRIPT2 Oc Ns
.Oo Ar pool Oc Ns
Expand Down Expand Up @@ -83,6 +83,10 @@ These GUIDs can be used in place of device names for the zpool
detach/offline/remove/replace commands.
.It Fl i
Display vdev initialization status.
.It Fl j
Provides a JSON formatted dump of the given pools complete status on stdout
rather than output formatted for easy human readability.
Selecting JSON output causes other status display options to be ignored.
.It Fl L
Display real paths for vdevs resolving all symbolic links.
This can be used to look up the current block device name regardless of the
Expand Down

0 comments on commit 7c96bcd

Please sign in to comment.