Skip to content

Commit 7a09f97

Browse files
grwilsonChristopher Siden
authored andcommitted
5147 zpool list -v should show individual disk capacity
Reviewed by: Adam Leventhal <adam.leventhal@delphix.com> Reviewed by: Christopher Siden <christopher.siden@delphix.com> Reviewed by: Matthew Ahrens <matthew.ahrens@delphix.com> Reviewed by: Richard Elling <richard.elling@gmail.com> Approved by: Dan McDonald <danmcd@omniti.com>
1 parent 3ce9ce3 commit 7a09f97

File tree

2 files changed

+62
-37
lines changed

2 files changed

+62
-37
lines changed

usr/src/cmd/zpool/zpool_main.c

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,10 +2711,7 @@ print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
27112711

27122712
right_justify = B_FALSE;
27132713
if (pl->pl_prop != ZPROP_INVAL) {
2714-
if (pl->pl_prop == ZPOOL_PROP_EXPANDSZ &&
2715-
zpool_get_prop_int(zhp, pl->pl_prop, NULL) == 0)
2716-
propstr = "-";
2717-
else if (zpool_get_prop(zhp, pl->pl_prop, property,
2714+
if (zpool_get_prop(zhp, pl->pl_prop, property,
27182715
sizeof (property), NULL, cb->cb_literal) != 0)
27192716
propstr = "-";
27202717
else
@@ -2748,21 +2745,37 @@ print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
27482745
}
27492746

27502747
static void
2751-
print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted)
2748+
print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted,
2749+
boolean_t valid)
27522750
{
27532751
char propval[64];
27542752
boolean_t fixed;
27552753
size_t width = zprop_width(prop, &fixed, ZFS_TYPE_POOL);
27562754

2757-
2758-
if (prop == ZPOOL_PROP_EXPANDSZ && value == 0)
2759-
(void) strlcpy(propval, "-", sizeof (propval));
2760-
else if (prop == ZPOOL_PROP_FRAGMENTATION && value == ZFS_FRAG_INVALID)
2761-
(void) strlcpy(propval, "-", sizeof (propval));
2762-
else if (prop == ZPOOL_PROP_FRAGMENTATION)
2755+
switch (prop) {
2756+
case ZPOOL_PROP_EXPANDSZ:
2757+
if (value == 0)
2758+
(void) strlcpy(propval, "-", sizeof (propval));
2759+
else
2760+
zfs_nicenum(value, propval, sizeof (propval));
2761+
break;
2762+
case ZPOOL_PROP_FRAGMENTATION:
2763+
if (value == ZFS_FRAG_INVALID) {
2764+
(void) strlcpy(propval, "-", sizeof (propval));
2765+
} else {
2766+
(void) snprintf(propval, sizeof (propval), "%llu%%",
2767+
value);
2768+
}
2769+
break;
2770+
case ZPOOL_PROP_CAPACITY:
27632771
(void) snprintf(propval, sizeof (propval), "%llu%%", value);
2764-
else
2772+
break;
2773+
default:
27652774
zfs_nicenum(value, propval, sizeof (propval));
2775+
}
2776+
2777+
if (!valid)
2778+
(void) strlcpy(propval, "-", sizeof (propval));
27662779

27672780
if (scripted)
27682781
(void) printf("\t%s", propval);
@@ -2784,6 +2797,9 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
27842797
(uint64_t **)&vs, &c) == 0);
27852798

27862799
if (name != NULL) {
2800+
boolean_t toplevel = (vs->vs_space != 0);
2801+
uint64_t cap;
2802+
27872803
if (scripted)
27882804
(void) printf("\t%s", name);
27892805
else if (strlen(name) + depth > cb->cb_namewidth)
@@ -2792,24 +2808,26 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
27922808
(void) printf("%*s%s%*s", depth, "", name,
27932809
(int)(cb->cb_namewidth - strlen(name) - depth), "");
27942810

2795-
/* only toplevel vdevs have capacity stats */
2796-
if (vs->vs_space == 0) {
2797-
if (scripted)
2798-
(void) printf("\t-\t-\t-\t-");
2799-
else
2800-
(void) printf(" - - - -");
2801-
} else {
2802-
print_one_column(ZPOOL_PROP_SIZE, vs->vs_space,
2803-
scripted);
2804-
print_one_column(ZPOOL_PROP_CAPACITY, vs->vs_alloc,
2805-
scripted);
2806-
print_one_column(ZPOOL_PROP_FREE,
2807-
vs->vs_space - vs->vs_alloc, scripted);
2808-
print_one_column(ZPOOL_PROP_FRAGMENTATION,
2809-
vs->vs_fragmentation, scripted);
2810-
}
2811-
print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize,
2812-
scripted);
2811+
/*
2812+
* Print the properties for the individual vdevs. Some
2813+
* properties are only applicable to toplevel vdevs. The
2814+
* 'toplevel' boolean value is passed to the print_one_column()
2815+
* to indicate that the value is valid.
2816+
*/
2817+
print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, scripted,
2818+
toplevel);
2819+
print_one_column(ZPOOL_PROP_ALLOCATED, vs->vs_alloc, scripted,
2820+
toplevel);
2821+
print_one_column(ZPOOL_PROP_FREE, vs->vs_space - vs->vs_alloc,
2822+
scripted, toplevel);
2823+
print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, scripted,
2824+
B_TRUE);
2825+
print_one_column(ZPOOL_PROP_FRAGMENTATION,
2826+
vs->vs_fragmentation, scripted,
2827+
(vs->vs_fragmentation != ZFS_FRAG_INVALID && toplevel));
2828+
cap = (vs->vs_space == 0) ? 0 :
2829+
(vs->vs_alloc * 100 / vs->vs_space);
2830+
print_one_column(ZPOOL_PROP_CAPACITY, cap, scripted, toplevel);
28132831
(void) printf("\n");
28142832
}
28152833

@@ -2878,7 +2896,8 @@ list_callback(zpool_handle_t *zhp, void *data)
28782896
* -H Scripted mode. Don't display headers, and separate properties
28792897
* by a single tab.
28802898
* -o List of properties to display. Defaults to
2881-
* "name,size,allocated,free,capacity,health,altroot"
2899+
* "name,size,allocated,free,expandsize,fragmentation,capacity,"
2900+
* "dedupratio,health,altroot"
28822901
* -p Diplay values in parsable (exact) format.
28832902
* -T Display a timestamp in date(1) or Unix format
28842903
*
@@ -2892,7 +2911,7 @@ zpool_do_list(int argc, char **argv)
28922911
int ret;
28932912
list_cbdata_t cb = { 0 };
28942913
static char default_props[] =
2895-
"name,size,allocated,free,fragmentation,expandsize,capacity,"
2914+
"name,size,allocated,free,expandsize,fragmentation,capacity,"
28962915
"dedupratio,health,altroot";
28972916
char *props = default_props;
28982917
unsigned long interval = 0, count = 0;

usr/src/lib/libzfs/common/libzfs_pool.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/*
2323
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2424
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25-
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
25+
* Copyright (c) 2011, 2014 by Delphix. All rights reserved.
2626
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
2727
*/
2828

@@ -276,15 +276,23 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len,
276276
case ZPOOL_PROP_FREE:
277277
case ZPOOL_PROP_FREEING:
278278
case ZPOOL_PROP_LEAKED:
279-
case ZPOOL_PROP_EXPANDSZ:
280279
if (literal) {
281280
(void) snprintf(buf, len, "%llu",
282281
(u_longlong_t)intval);
283282
} else {
284283
(void) zfs_nicenum(intval, buf, len);
285284
}
286285
break;
287-
286+
case ZPOOL_PROP_EXPANDSZ:
287+
if (intval == 0) {
288+
(void) strlcpy(buf, "-", len);
289+
} else if (literal) {
290+
(void) snprintf(buf, len, "%llu",
291+
(u_longlong_t)intval);
292+
} else {
293+
(void) zfs_nicenum(intval, buf, len);
294+
}
295+
break;
288296
case ZPOOL_PROP_CAPACITY:
289297
if (literal) {
290298
(void) snprintf(buf, len, "%llu",
@@ -302,13 +310,11 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len,
302310
(u_longlong_t)intval);
303311
}
304312
break;
305-
306313
case ZPOOL_PROP_DEDUPRATIO:
307314
(void) snprintf(buf, len, "%llu.%02llux",
308315
(u_longlong_t)(intval / 100),
309316
(u_longlong_t)(intval % 100));
310317
break;
311-
312318
case ZPOOL_PROP_HEALTH:
313319
verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL),
314320
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);

0 commit comments

Comments
 (0)