Skip to content

Commit a05dfd0

Browse files
grwilsonbehlendorf
authored andcommitted
Illumos 5147 - zpool list -v should show individual disk capacity
The 'zpool list -v' command displays lots of info but excludes the capacity of each disk. This should be added. 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> References: https://www.illumos.org/issues/5147 illumos/illumos-gate@7a09f97 Ported by: Turbo Fredriksson <turbo@bayour.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #2688
1 parent b8bcca1 commit a05dfd0

File tree

2 files changed

+63
-34
lines changed

2 files changed

+63
-34
lines changed

cmd/zpool/zpool_main.c

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

29562956
right_justify = B_FALSE;
29572957
if (pl->pl_prop != ZPROP_INVAL) {
2958-
if (pl->pl_prop == ZPOOL_PROP_EXPANDSZ &&
2959-
zpool_get_prop_int(zhp, pl->pl_prop, NULL) == 0)
2960-
propstr = "-";
2961-
else if (zpool_get_prop(zhp, pl->pl_prop, property,
2958+
if (zpool_get_prop(zhp, pl->pl_prop, property,
29622959
sizeof (property), NULL) != 0)
29632960
propstr = "-";
29642961
else
@@ -2992,22 +2989,38 @@ print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
29922989
}
29932990

29942991
static void
2995-
print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted)
2992+
print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted,
2993+
boolean_t valid)
29962994
{
29972995
char propval[64];
29982996
boolean_t fixed;
29992997
size_t width = zprop_width(prop, &fixed, ZFS_TYPE_POOL);
30002998

3001-
3002-
if (prop == ZPOOL_PROP_EXPANDSZ && value == 0)
3003-
(void) strlcpy(propval, "-", sizeof (propval));
3004-
else if (prop == ZPOOL_PROP_FRAGMENTATION && value == ZFS_FRAG_INVALID)
3005-
(void) strlcpy(propval, "-", sizeof (propval));
3006-
else if (prop == ZPOOL_PROP_FRAGMENTATION)
2999+
switch (prop) {
3000+
case ZPOOL_PROP_EXPANDSZ:
3001+
if (value == 0)
3002+
(void) strlcpy(propval, "-", sizeof (propval));
3003+
else
3004+
zfs_nicenum(value, propval, sizeof (propval));
3005+
break;
3006+
case ZPOOL_PROP_FRAGMENTATION:
3007+
if (value == ZFS_FRAG_INVALID) {
3008+
(void) strlcpy(propval, "-", sizeof (propval));
3009+
} else {
3010+
(void) snprintf(propval, sizeof (propval), "%llu%%",
3011+
(unsigned long long)value);
3012+
}
3013+
break;
3014+
case ZPOOL_PROP_CAPACITY:
30073015
(void) snprintf(propval, sizeof (propval), "%llu%%",
30083016
(unsigned long long)value);
3009-
else
3017+
break;
3018+
default:
30103019
zfs_nicenum(value, propval, sizeof (propval));
3020+
}
3021+
3022+
if (!valid)
3023+
(void) strlcpy(propval, "-", sizeof (propval));
30113024

30123025
if (scripted)
30133026
(void) printf("\t%s", propval);
@@ -3029,6 +3042,9 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
30293042
(uint64_t **)&vs, &c) == 0);
30303043

30313044
if (name != NULL) {
3045+
boolean_t toplevel = (vs->vs_space != 0);
3046+
uint64_t cap;
3047+
30323048
if (scripted)
30333049
(void) printf("\t%s", name);
30343050
else if (strlen(name) + depth > cb->cb_namewidth)
@@ -3037,24 +3053,26 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
30373053
(void) printf("%*s%s%*s", depth, "", name,
30383054
(int)(cb->cb_namewidth - strlen(name) - depth), "");
30393055

3040-
/* only toplevel vdevs have capacity stats */
3041-
if (vs->vs_space == 0) {
3042-
if (scripted)
3043-
(void) printf("\t-\t-\t-\t-");
3044-
else
3045-
(void) printf(" - - - -");
3046-
} else {
3047-
print_one_column(ZPOOL_PROP_SIZE, vs->vs_space,
3048-
scripted);
3049-
print_one_column(ZPOOL_PROP_CAPACITY, vs->vs_alloc,
3050-
scripted);
3051-
print_one_column(ZPOOL_PROP_FREE,
3052-
vs->vs_space - vs->vs_alloc, scripted);
3053-
print_one_column(ZPOOL_PROP_FRAGMENTATION,
3054-
vs->vs_fragmentation, scripted);
3055-
}
3056-
print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize,
3057-
scripted);
3056+
/*
3057+
* Print the properties for the individual vdevs. Some
3058+
* properties are only applicable to toplevel vdevs. The
3059+
* 'toplevel' boolean value is passed to the print_one_column()
3060+
* to indicate that the value is valid.
3061+
*/
3062+
print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, scripted,
3063+
toplevel);
3064+
print_one_column(ZPOOL_PROP_ALLOCATED, vs->vs_alloc, scripted,
3065+
toplevel);
3066+
print_one_column(ZPOOL_PROP_FREE, vs->vs_space - vs->vs_alloc,
3067+
scripted, toplevel);
3068+
print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, scripted,
3069+
B_TRUE);
3070+
print_one_column(ZPOOL_PROP_FRAGMENTATION,
3071+
vs->vs_fragmentation, scripted,
3072+
(vs->vs_fragmentation != ZFS_FRAG_INVALID && toplevel));
3073+
cap = (vs->vs_space == 0) ? 0 :
3074+
(vs->vs_alloc * 100 / vs->vs_space);
3075+
print_one_column(ZPOOL_PROP_CAPACITY, cap, scripted, toplevel);
30583076
(void) printf("\n");
30593077
}
30603078

@@ -3123,7 +3141,8 @@ list_callback(zpool_handle_t *zhp, void *data)
31233141
* -H Scripted mode. Don't display headers, and separate properties
31243142
* by a single tab.
31253143
* -o List of properties to display. Defaults to
3126-
* "name,size,allocated,free,capacity,health,altroot"
3144+
* "name,size,allocated,free,expandsize,fragmentation,capacity,"
3145+
* "dedupratio,health,altroot"
31273146
* -T Display a timestamp in date(1) or Unix format
31283147
*
31293148
* List all pools in the system, whether or not they're healthy. Output space
@@ -3136,7 +3155,7 @@ zpool_do_list(int argc, char **argv)
31363155
int ret = 0;
31373156
list_cbdata_t cb = { 0 };
31383157
static char default_props[] =
3139-
"name,size,allocated,free,fragmentation,capacity,"
3158+
"name,size,allocated,free,expandsize,fragmentation,capacity,"
31403159
"dedupratio,health,altroot";
31413160
char *props = default_props;
31423161
unsigned long interval = 0, count = 0;

lib/libzfs/libzfs_pool.c

Lines changed: 12 additions & 2 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
*/
2727

2828
#include <ctype.h>
@@ -317,7 +317,6 @@ zpool_get_prop_literal(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
317317
case ZPOOL_PROP_FREE:
318318
case ZPOOL_PROP_FREEING:
319319
case ZPOOL_PROP_LEAKED:
320-
case ZPOOL_PROP_EXPANDSZ:
321320
case ZPOOL_PROP_ASHIFT:
322321
if (literal)
323322
(void) snprintf(buf, len, "%llu",
@@ -326,6 +325,17 @@ zpool_get_prop_literal(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
326325
(void) zfs_nicenum(intval, buf, len);
327326
break;
328327

328+
case ZPOOL_PROP_EXPANDSZ:
329+
if (intval == 0) {
330+
(void) strlcpy(buf, "-", len);
331+
} else if (literal) {
332+
(void) snprintf(buf, len, "%llu",
333+
(u_longlong_t)intval);
334+
} else {
335+
(void) zfs_nicenum(intval, buf, len);
336+
}
337+
break;
338+
329339
case ZPOOL_PROP_CAPACITY:
330340
(void) snprintf(buf, len, "%llu%%",
331341
(u_longlong_t)intval);

0 commit comments

Comments
 (0)