Add -p switch to "zpool get"

This works the same as the -p switch to "zfs get", displaying full
resolution values for appropriate attributes.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1813
This commit is contained in:
Ralf Ertzinger 2013-10-23 10:50:48 +02:00 committed by Brian Behlendorf
parent 8b921f667a
commit d65e738109
2 changed files with 40 additions and 10 deletions

View File

@ -265,7 +265,7 @@ get_usage(zpool_help_t idx) {
case HELP_EVENTS: case HELP_EVENTS:
return (gettext("\tevents [-vHfc]\n")); return (gettext("\tevents [-vHfc]\n"));
case HELP_GET: case HELP_GET:
return (gettext("\tget <\"all\" | property[,...]> " return (gettext("\tget [-p] <\"all\" | property[,...]> "
"<pool> ...\n")); "<pool> ...\n"));
case HELP_SET: case HELP_SET:
return (gettext("\tset <property=value> <pool> \n")); return (gettext("\tset <property=value> <pool> \n"));
@ -5488,8 +5488,8 @@ get_callback(zpool_handle_t *zhp, void *data)
NULL, NULL); NULL, NULL);
} }
} else { } else {
if (zpool_get_prop(zhp, pl->pl_prop, value, if (zpool_get_prop_literal(zhp, pl->pl_prop, value,
sizeof (value), &srctype) != 0) sizeof (value), &srctype, cbp->cb_literal) != 0)
continue; continue;
zprop_print_one_property(zpool_get_name(zhp), cbp, zprop_print_one_property(zpool_get_name(zhp), cbp,
@ -5505,9 +5505,26 @@ zpool_do_get(int argc, char **argv)
{ {
zprop_get_cbdata_t cb = { 0 }; zprop_get_cbdata_t cb = { 0 };
zprop_list_t fake_name = { 0 }; zprop_list_t fake_name = { 0 };
int ret; int c, ret;
if (argc < 2) { /* check options */
while ((c = getopt(argc, argv, "p")) != -1) {
switch (c) {
case 'p':
cb.cb_literal = B_TRUE;
break;
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
usage(B_FALSE);
}
}
argc -= optind;
argv += optind;
if (argc < 1) {
(void) fprintf(stderr, gettext("missing property " (void) fprintf(stderr, gettext("missing property "
"argument\n")); "argument\n"));
usage(B_FALSE); usage(B_FALSE);
@ -5521,10 +5538,12 @@ zpool_do_get(int argc, char **argv)
cb.cb_columns[3] = GET_COL_SOURCE; cb.cb_columns[3] = GET_COL_SOURCE;
cb.cb_type = ZFS_TYPE_POOL; cb.cb_type = ZFS_TYPE_POOL;
if (zprop_get_list(g_zfs, argv[1], &cb.cb_proplist, if (zprop_get_list(g_zfs, argv[0], &cb.cb_proplist, ZFS_TYPE_POOL) != 0)
ZFS_TYPE_POOL) != 0)
usage(B_FALSE); usage(B_FALSE);
argc--;
argv++;
if (cb.cb_proplist != NULL) { if (cb.cb_proplist != NULL) {
fake_name.pl_prop = ZPOOL_PROP_NAME; fake_name.pl_prop = ZPOOL_PROP_NAME;
fake_name.pl_width = strlen(gettext("NAME")); fake_name.pl_width = strlen(gettext("NAME"));
@ -5532,7 +5551,7 @@ zpool_do_get(int argc, char **argv)
cb.cb_proplist = &fake_name; cb.cb_proplist = &fake_name;
} }
ret = for_each_pool(argc - 2, argv + 2, B_TRUE, &cb.cb_proplist, ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist,
get_callback, &cb); get_callback, &cb);
if (cb.cb_proplist == &fake_name) if (cb.cb_proplist == &fake_name)

View File

@ -62,7 +62,7 @@ zpool \- configures ZFS storage pools
.LP .LP
.nf .nf
\fBzpool get\fR "\fIall\fR" | \fIproperty\fR[,...] \fIpool\fR ... \fBzpool get\fR [\fB-p\fR] "\fIall\fR" | \fIproperty\fR[,...] \fIpool\fR ...
.fi .fi
.LP .LP
@ -1037,7 +1037,7 @@ This command will forcefully export the pool even if it has a shared spare that
.ne 2 .ne 2
.mk .mk
.na .na
\fB\fBzpool get\fR "\fIall\fR" | \fIproperty\fR[,...] \fIpool\fR ...\fR \fB\fBzpool get\fR [\fB-p\fR] "\fIall\fR" | \fIproperty\fR[,...] \fIpool\fR ...\fR
.ad .ad
.sp .6 .sp .6
.RS 4n .RS 4n
@ -1054,6 +1054,17 @@ Retrieves the given list of properties (or all properties if "\fBall\fR" is used
.sp .sp
See the "Properties" section for more information on the available pool properties. See the "Properties" section for more information on the available pool properties.
.sp
.ne 2
.mk
.na
\fB\fB-p\fR\fR
.ad
.RS 6n
.rt
Display numbers in parseable (exact) values.
.RE
.RE .RE
.sp .sp