Make zpool list -vp print individual vdev sizes parsable.

Add argument format to print_one_column(), and use it to call
zfs_nicenum_format with, instead of just zfs_nicenum. Don't print "%"
for fragmentation or capacity percent values.

The calls to print_one_colum is made with ZFS_NICENUM_RAW if
cb->cb_literal (zpool list called with -p), and ZFS_NICENUM_1024 if not.

Also zpool_get_prop is modified to don't add "%" or "x" if literal.

Signed-off-by: Christer Ekholm <che@chrekh.se>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tony Hutter <hutter2@llnl.gov
Closes #4657
This commit is contained in:
Christer Ekholm 2016-05-16 21:29:54 +02:00 committed by Brian Behlendorf
parent 81b4c075ec
commit bc2d809387
2 changed files with 38 additions and 14 deletions

View File

@ -4268,7 +4268,7 @@ print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
static void static void
print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted, print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted,
boolean_t valid) boolean_t valid, enum zfs_nicenum_format format)
{ {
char propval[64]; char propval[64];
boolean_t fixed; boolean_t fixed;
@ -4279,22 +4279,30 @@ print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted,
if (value == 0) if (value == 0)
(void) strlcpy(propval, "-", sizeof (propval)); (void) strlcpy(propval, "-", sizeof (propval));
else else
zfs_nicenum(value, propval, sizeof (propval)); zfs_nicenum_format(value, propval, sizeof (propval),
format);
break; break;
case ZPOOL_PROP_FRAGMENTATION: case ZPOOL_PROP_FRAGMENTATION:
if (value == ZFS_FRAG_INVALID) { if (value == ZFS_FRAG_INVALID) {
(void) strlcpy(propval, "-", sizeof (propval)); (void) strlcpy(propval, "-", sizeof (propval));
} else if (format == ZFS_NICENUM_RAW) {
(void) snprintf(propval, sizeof (propval), "%llu",
(unsigned long long)value);
} else { } else {
(void) snprintf(propval, sizeof (propval), "%llu%%", (void) snprintf(propval, sizeof (propval), "%llu%%",
(unsigned long long)value); (unsigned long long)value);
} }
break; break;
case ZPOOL_PROP_CAPACITY: case ZPOOL_PROP_CAPACITY:
if (format == ZFS_NICENUM_RAW)
(void) snprintf(propval, sizeof (propval), "%llu",
(unsigned long long)value);
else
(void) snprintf(propval, sizeof (propval), "%llu%%", (void) snprintf(propval, sizeof (propval), "%llu%%",
(unsigned long long)value); (unsigned long long)value);
break; break;
default: default:
zfs_nicenum(value, propval, sizeof (propval)); zfs_nicenum_format(value, propval, sizeof (propval), format);
} }
if (!valid) if (!valid)
@ -4325,6 +4333,12 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
if (name != NULL) { if (name != NULL) {
boolean_t toplevel = (vs->vs_space != 0); boolean_t toplevel = (vs->vs_space != 0);
uint64_t cap; uint64_t cap;
enum zfs_nicenum_format format;
if (cb->cb_literal)
format = ZFS_NICENUM_RAW;
else
format = ZFS_NICENUM_1024;
if (scripted) if (scripted)
(void) printf("\t%s", name); (void) printf("\t%s", name);
@ -4341,19 +4355,21 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
* to indicate that the value is valid. * to indicate that the value is valid.
*/ */
print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, scripted, print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, scripted,
toplevel); toplevel, format);
print_one_column(ZPOOL_PROP_ALLOCATED, vs->vs_alloc, scripted, print_one_column(ZPOOL_PROP_ALLOCATED, vs->vs_alloc, scripted,
toplevel); toplevel, format);
print_one_column(ZPOOL_PROP_FREE, vs->vs_space - vs->vs_alloc, print_one_column(ZPOOL_PROP_FREE, vs->vs_space - vs->vs_alloc,
scripted, toplevel); scripted, toplevel, format);
print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, scripted, print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, scripted,
B_TRUE); B_TRUE, format);
print_one_column(ZPOOL_PROP_FRAGMENTATION, print_one_column(ZPOOL_PROP_FRAGMENTATION,
vs->vs_fragmentation, scripted, vs->vs_fragmentation, scripted,
(vs->vs_fragmentation != ZFS_FRAG_INVALID && toplevel)); (vs->vs_fragmentation != ZFS_FRAG_INVALID && toplevel),
format);
cap = (vs->vs_space == 0) ? 0 : cap = (vs->vs_space == 0) ? 0 :
(vs->vs_alloc * 100 / vs->vs_space); (vs->vs_alloc * 100 / vs->vs_space);
print_one_column(ZPOOL_PROP_CAPACITY, cap, scripted, toplevel); print_one_column(ZPOOL_PROP_CAPACITY, cap, scripted, toplevel,
format);
(void) printf("\n"); (void) printf("\n");
} }

View File

@ -337,6 +337,9 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
case ZPOOL_PROP_FRAGMENTATION: case ZPOOL_PROP_FRAGMENTATION:
if (intval == UINT64_MAX) { if (intval == UINT64_MAX) {
(void) strlcpy(buf, "-", len); (void) strlcpy(buf, "-", len);
} else if (literal) {
(void) snprintf(buf, len, "%llu",
(u_longlong_t)intval);
} else { } else {
(void) snprintf(buf, len, "%llu%%", (void) snprintf(buf, len, "%llu%%",
(u_longlong_t)intval); (u_longlong_t)intval);
@ -344,6 +347,11 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
break; break;
case ZPOOL_PROP_DEDUPRATIO: case ZPOOL_PROP_DEDUPRATIO:
if (literal)
(void) snprintf(buf, len, "%llu.%02llu",
(u_longlong_t)(intval / 100),
(u_longlong_t)(intval % 100));
else
(void) snprintf(buf, len, "%llu.%02llux", (void) snprintf(buf, len, "%llu.%02llux",
(u_longlong_t)(intval / 100), (u_longlong_t)(intval / 100),
(u_longlong_t)(intval % 100)); (u_longlong_t)(intval % 100));