]> granicus.if.org Git - zfs/commitdiff
Illumos 5147 - zpool list -v should show individual disk capacity
authorGeorge Wilson <george.wilson@delphix.com>
Fri, 12 Sep 2014 03:07:20 +0000 (05:07 +0200)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 23 Sep 2014 17:10:42 +0000 (10:10 -0700)
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
  https://github.com/illumos/illumos-gate/commit/7a09f97

Ported by: Turbo Fredriksson <turbo@bayour.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #2688

cmd/zpool/zpool_main.c
lib/libzfs/libzfs_pool.c

index 1086f955561d08ae56cfb6447a6bc23470c6925d..d197e3d6420fdfd3c49956983f58438bad9ce164 100644 (file)
@@ -2955,10 +2955,7 @@ print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
 
                right_justify = B_FALSE;
                if (pl->pl_prop != ZPROP_INVAL) {
-                       if (pl->pl_prop == ZPOOL_PROP_EXPANDSZ &&
-                           zpool_get_prop_int(zhp, pl->pl_prop, NULL) == 0)
-                               propstr = "-";
-                       else if (zpool_get_prop(zhp, pl->pl_prop, property,
+                       if (zpool_get_prop(zhp, pl->pl_prop, property,
                            sizeof (property), NULL) != 0)
                                propstr = "-";
                        else
@@ -2992,22 +2989,38 @@ 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)
+print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted,
+    boolean_t valid)
 {
        char propval[64];
        boolean_t fixed;
        size_t width = zprop_width(prop, &fixed, ZFS_TYPE_POOL);
 
-
-       if (prop == ZPOOL_PROP_EXPANDSZ && value == 0)
-               (void) strlcpy(propval, "-", sizeof (propval));
-       else if (prop == ZPOOL_PROP_FRAGMENTATION && value == ZFS_FRAG_INVALID)
-               (void) strlcpy(propval, "-", sizeof (propval));
-       else if (prop == ZPOOL_PROP_FRAGMENTATION)
+       switch (prop) {
+       case ZPOOL_PROP_EXPANDSZ:
+               if (value == 0)
+                       (void) strlcpy(propval, "-", sizeof (propval));
+               else
+                       zfs_nicenum(value, propval, sizeof (propval));
+               break;
+       case ZPOOL_PROP_FRAGMENTATION:
+               if (value == ZFS_FRAG_INVALID) {
+                       (void) strlcpy(propval, "-", sizeof (propval));
+               } else {
+                       (void) snprintf(propval, sizeof (propval), "%llu%%",
+                           (unsigned long long)value);
+               }
+               break;
+       case ZPOOL_PROP_CAPACITY:
                (void) snprintf(propval, sizeof (propval), "%llu%%",
                    (unsigned long long)value);
-       else
+               break;
+       default:
                zfs_nicenum(value, propval, sizeof (propval));
+       }
+
+       if (!valid)
+               (void) strlcpy(propval, "-", sizeof (propval));
 
        if (scripted)
                (void) printf("\t%s", propval);
@@ -3029,6 +3042,9 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
            (uint64_t **)&vs, &c) == 0);
 
        if (name != NULL) {
+               boolean_t toplevel = (vs->vs_space != 0);
+               uint64_t cap;
+
                if (scripted)
                        (void) printf("\t%s", name);
                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,
                        (void) printf("%*s%s%*s", depth, "", name,
                            (int)(cb->cb_namewidth - strlen(name) - depth), "");
 
-               /* only toplevel vdevs have capacity stats */
-               if (vs->vs_space == 0) {
-                       if (scripted)
-                               (void) printf("\t-\t-\t-\t-");
-                       else
-                               (void) printf("      -      -      -      -");
-               } else {
-                       print_one_column(ZPOOL_PROP_SIZE, vs->vs_space,
-                           scripted);
-                       print_one_column(ZPOOL_PROP_CAPACITY, vs->vs_alloc,
-                           scripted);
-                       print_one_column(ZPOOL_PROP_FREE,
-                           vs->vs_space - vs->vs_alloc, scripted);
-                       print_one_column(ZPOOL_PROP_FRAGMENTATION,
-                           vs->vs_fragmentation, scripted);
-               }
-               print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize,
-                   scripted);
+               /*
+                * Print the properties for the individual vdevs. Some
+                * properties are only applicable to toplevel vdevs. The
+                * 'toplevel' boolean value is passed to the print_one_column()
+                * to indicate that the value is valid.
+                */
+               print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, scripted,
+                   toplevel);
+               print_one_column(ZPOOL_PROP_ALLOCATED, vs->vs_alloc, scripted,
+                   toplevel);
+               print_one_column(ZPOOL_PROP_FREE, vs->vs_space - vs->vs_alloc,
+                   scripted, toplevel);
+               print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, scripted,
+                   B_TRUE);
+               print_one_column(ZPOOL_PROP_FRAGMENTATION,
+                   vs->vs_fragmentation, scripted,
+                   (vs->vs_fragmentation != ZFS_FRAG_INVALID && toplevel));
+               cap = (vs->vs_space == 0) ? 0 :
+                   (vs->vs_alloc * 100 / vs->vs_space);
+               print_one_column(ZPOOL_PROP_CAPACITY, cap, scripted, toplevel);
                (void) printf("\n");
        }
 
@@ -3123,7 +3141,8 @@ list_callback(zpool_handle_t *zhp, void *data)
  *     -H      Scripted mode.  Don't display headers, and separate properties
  *             by a single tab.
  *     -o      List of properties to display.  Defaults to
- *             "name,size,allocated,free,capacity,health,altroot"
+ *             "name,size,allocated,free,expandsize,fragmentation,capacity,"
+ *             "dedupratio,health,altroot"
  *     -T      Display a timestamp in date(1) or Unix format
  *
  * 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)
        int ret = 0;
        list_cbdata_t cb = { 0 };
        static char default_props[] =
-           "name,size,allocated,free,fragmentation,capacity,"
+           "name,size,allocated,free,expandsize,fragmentation,capacity,"
            "dedupratio,health,altroot";
        char *props = default_props;
        unsigned long interval = 0, count = 0;
index d50b9c9ccf17d5e95ac8f78a0ca3546f2cc1a27b..00ed1a3e33c5b60d602a36917ab5fe8e6109c102 100644 (file)
@@ -22,7 +22,7 @@
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
- * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2014 by Delphix. All rights reserved.
  */
 
 #include <ctype.h>
@@ -317,7 +317,6 @@ zpool_get_prop_literal(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
                case ZPOOL_PROP_FREE:
                case ZPOOL_PROP_FREEING:
                case ZPOOL_PROP_LEAKED:
-               case ZPOOL_PROP_EXPANDSZ:
                case ZPOOL_PROP_ASHIFT:
                        if (literal)
                                (void) snprintf(buf, len, "%llu",
@@ -326,6 +325,17 @@ zpool_get_prop_literal(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
                                (void) zfs_nicenum(intval, buf, len);
                        break;
 
+               case ZPOOL_PROP_EXPANDSZ:
+                       if (intval == 0) {
+                               (void) strlcpy(buf, "-", len);
+                       } else if (literal) {
+                               (void) snprintf(buf, len, "%llu",
+                                   (u_longlong_t)intval);
+                       } else {
+                               (void) zfs_nicenum(intval, buf, len);
+                       }
+                       break;
+
                case ZPOOL_PROP_CAPACITY:
                        (void) snprintf(buf, len, "%llu%%",
                            (u_longlong_t)intval);