Update core ZFS code from build 121 to build 141.
[zfs.git] / lib / libzfs / libzfs_status.c
index 44faf02..24725ec 100644 (file)
@@ -19,8 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -138,7 +137,7 @@ find_vdev_problem(nvlist_t *vdev, int (*func)(uint64_t, uint64_t, uint64_t))
                        if (find_vdev_problem(child[c], func))
                                return (B_TRUE);
        } else {
-               verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_STATS,
+               verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_VDEV_STATS,
                    (uint64_t **)&vs, &c) == 0);
 
                if (func(vs->vs_state, vs->vs_aux,
@@ -173,7 +172,8 @@ check_status(nvlist_t *config, boolean_t isimport)
 {
        nvlist_t *nvroot;
        vdev_stat_t *vs;
-       uint_t vsc;
+       pool_scan_stat_t *ps = NULL;
+       uint_t vsc, psc;
        uint64_t nerr;
        uint64_t version;
        uint64_t stateval;
@@ -184,15 +184,24 @@ check_status(nvlist_t *config, boolean_t isimport)
            &version) == 0);
        verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
            &nvroot) == 0);
-       verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
+       verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
            (uint64_t **)&vs, &vsc) == 0);
        verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
            &stateval) == 0);
-       (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
+
+       /*
+        * Currently resilvering a vdev
+        */
+       (void) nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_SCAN_STATS,
+           (uint64_t **)&ps, &psc);
+       if (ps && ps->pss_func == POOL_SCAN_RESILVER &&
+           ps->pss_state == DSS_SCANNING)
+               return (ZPOOL_STATUS_RESILVERING);
 
        /*
         * Pool last accessed by another system.
         */
+       (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
        if (hostid != 0 && (unsigned long)hostid != gethostid() &&
            stateval == POOL_STATE_ACTIVE)
                return (ZPOOL_STATUS_HOSTID_MISMATCH);
@@ -289,12 +298,6 @@ check_status(nvlist_t *config, boolean_t isimport)
                return (ZPOOL_STATUS_REMOVED_DEV);
 
        /*
-        * Currently resilvering
-        */
-       if (!vs->vs_scrub_complete && vs->vs_scrub_type == POOL_SCRUB_RESILVER)
-               return (ZPOOL_STATUS_RESILVERING);
-
-       /*
         * Outdated, but usable, version
         */
        if (version < SPA_VERSION)
@@ -328,3 +331,68 @@ zpool_import_status(nvlist_t *config, char **msgid)
 
        return (ret);
 }
+
+static void
+dump_ddt_stat(const ddt_stat_t *dds, int h)
+{
+       char refcnt[6];
+       char blocks[6], lsize[6], psize[6], dsize[6];
+       char ref_blocks[6], ref_lsize[6], ref_psize[6], ref_dsize[6];
+
+       if (dds == NULL || dds->dds_blocks == 0)
+               return;
+
+       if (h == -1)
+               (void) strcpy(refcnt, "Total");
+       else
+               zfs_nicenum(1ULL << h, refcnt, sizeof (refcnt));
+
+       zfs_nicenum(dds->dds_blocks, blocks, sizeof (blocks));
+       zfs_nicenum(dds->dds_lsize, lsize, sizeof (lsize));
+       zfs_nicenum(dds->dds_psize, psize, sizeof (psize));
+       zfs_nicenum(dds->dds_dsize, dsize, sizeof (dsize));
+       zfs_nicenum(dds->dds_ref_blocks, ref_blocks, sizeof (ref_blocks));
+       zfs_nicenum(dds->dds_ref_lsize, ref_lsize, sizeof (ref_lsize));
+       zfs_nicenum(dds->dds_ref_psize, ref_psize, sizeof (ref_psize));
+       zfs_nicenum(dds->dds_ref_dsize, ref_dsize, sizeof (ref_dsize));
+
+       (void) printf("%6s   %6s   %5s   %5s   %5s   %6s   %5s   %5s   %5s\n",
+           refcnt,
+           blocks, lsize, psize, dsize,
+           ref_blocks, ref_lsize, ref_psize, ref_dsize);
+}
+
+/*
+ * Print the DDT histogram and the column totals.
+ */
+void
+zpool_dump_ddt(const ddt_stat_t *dds_total, const ddt_histogram_t *ddh)
+{
+       int h;
+
+       (void) printf("\n");
+
+       (void) printf("bucket   "
+           "           allocated             "
+           "          referenced          \n");
+       (void) printf("______   "
+           "______________________________   "
+           "______________________________\n");
+
+       (void) printf("%6s   %6s   %5s   %5s   %5s   %6s   %5s   %5s   %5s\n",
+           "refcnt",
+           "blocks", "LSIZE", "PSIZE", "DSIZE",
+           "blocks", "LSIZE", "PSIZE", "DSIZE");
+
+       (void) printf("%6s   %6s   %5s   %5s   %5s   %6s   %5s   %5s   %5s\n",
+           "------",
+           "------", "-----", "-----", "-----",
+           "------", "-----", "-----", "-----");
+
+       for (h = 0; h < 64; h++)
+               dump_ddt_stat(&ddh->ddh_stat[h], h);
+
+       dump_ddt_stat(dds_total, -1);
+
+       (void) printf("\n");
+}