summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChrister Ekholm <che@chrekh.se>2021-03-28 18:23:12 +0000
committerDan McDonald <danmcd@joyent.com>2021-05-13 00:23:20 -0400
commit3dfe801733ea71102fa4b1f79dddf16ee3ea546f (patch)
treee76dee400accabf5af289720e61b787798687df9
parent860b5cc8ca1cde8ee07c510e06bf21ad9103bb69 (diff)
downloadillumos-gate-3dfe801733ea71102fa4b1f79dddf16ee3ea546f.tar.gz
13678 Make zpool list -vp print individual vdev sizes parsable.
8883 zpool list parsable output is inconsistent Reviewed by: Toomas Soome <tsoome@me.com> Reviewed by: Andy Fiddaman <andy@omnios.org> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/cmd/zpool/zpool_main.c45
-rw-r--r--usr/src/lib/libzfs/common/libzfs_pool.c14
2 files changed, 42 insertions, 17 deletions
diff --git a/usr/src/cmd/zpool/zpool_main.c b/usr/src/cmd/zpool/zpool_main.c
index 605962a575..b0b407d4ac 100644
--- a/usr/src/cmd/zpool/zpool_main.c
+++ b/usr/src/cmd/zpool/zpool_main.c
@@ -5149,7 +5149,7 @@ print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
static void
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];
boolean_t fixed;
@@ -5161,23 +5161,32 @@ print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted,
if (value == 0)
(void) strlcpy(propval, "-", sizeof (propval));
else
- zfs_nicenum(value, propval, sizeof (propval));
+ zfs_nicenum_format(value, propval, sizeof (propval),
+ format);
break;
case ZPOOL_PROP_FRAGMENTATION:
if (value == ZFS_FRAG_INVALID) {
(void) strlcpy(propval, "-", sizeof (propval));
+ } else if (format == ZFS_NICENUM_RAW) {
+ (void) snprintf(propval, sizeof (propval), "%llu",
+ (unsigned long long)value);
} else {
(void) snprintf(propval, sizeof (propval), "%llu%%",
- value);
+ (unsigned long long)value);
}
break;
case ZPOOL_PROP_CAPACITY:
- (void) snprintf(propval, sizeof (propval),
- value < 1000 ? "%1.2f%%" : value < 10000 ?
- "%2.1f%%" : "%3.0f%%", value / 100.0);
+ if (format == ZFS_NICENUM_RAW)
+ (void) snprintf(propval, sizeof (propval), "%llu",
+ (unsigned long long)value / 100);
+
+ else
+ (void) snprintf(propval, sizeof (propval),
+ value < 1000 ? "%1.2f%%" : value < 10000 ?
+ "%2.1f%%" : "%3.0f%%", value / 100.0);
break;
default:
- zfs_nicenum(value, propval, sizeof (propval));
+ zfs_nicenum_format(value, propval, sizeof (propval), format);
}
if (!valid)
@@ -5210,6 +5219,12 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
if (name != NULL) {
boolean_t toplevel = (vs->vs_space != 0);
uint64_t cap;
+ enum zfs_nicenum_format format;
+
+ if (cb->cb_literal)
+ format = ZFS_NICENUM_RAW;
+ else
+ format = ZFS_NICENUM_1024;
if (strcmp(name, VDEV_TYPE_INDIRECT) == 0)
return;
@@ -5229,21 +5244,23 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
* to indicate that the value is valid.
*/
print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, scripted,
- toplevel);
+ toplevel, format);
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,
- scripted, toplevel);
+ scripted, toplevel, format);
print_one_column(ZPOOL_PROP_CHECKPOINT,
- vs->vs_checkpoint_space, scripted, toplevel);
+ vs->vs_checkpoint_space, scripted, toplevel, format);
print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, scripted,
- B_TRUE);
+ B_TRUE, format);
print_one_column(ZPOOL_PROP_FRAGMENTATION,
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 :
(vs->vs_alloc * 10000 / 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");
}
diff --git a/usr/src/lib/libzfs/common/libzfs_pool.c b/usr/src/lib/libzfs/common/libzfs_pool.c
index effca2bfd1..99b1d94d30 100644
--- a/usr/src/lib/libzfs/common/libzfs_pool.c
+++ b/usr/src/lib/libzfs/common/libzfs_pool.c
@@ -342,15 +342,23 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len,
case ZPOOL_PROP_FRAGMENTATION:
if (intval == UINT64_MAX) {
(void) strlcpy(buf, "-", len);
+ } else if (literal) {
+ (void) snprintf(buf, len, "%llu",
+ (u_longlong_t)intval);
} else {
(void) snprintf(buf, len, "%llu%%",
(u_longlong_t)intval);
}
break;
case ZPOOL_PROP_DEDUPRATIO:
- (void) snprintf(buf, len, "%llu.%02llux",
- (u_longlong_t)(intval / 100),
- (u_longlong_t)(intval % 100));
+ 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",
+ (u_longlong_t)(intval / 100),
+ (u_longlong_t)(intval % 100));
break;
case ZPOOL_PROP_HEALTH:
verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL),