]> git.proxmox.com Git - mirror_zfs.git/blobdiff - cmd/zdb/zdb.c
cstyle: Resolve C style issues
[mirror_zfs.git] / cmd / zdb / zdb.c
index 060498ae2c5029d70b12e1f07fdeae4ed8690f43..8e60b9b1a879bd47a3838bf3235d86cc64e4f6d4 100644 (file)
@@ -165,7 +165,8 @@ usage(void)
        (void) fprintf(stderr, "        -t <txg> -- highest txg to use when "
            "searching for uberblocks\n");
        (void) fprintf(stderr, "        -M <number of inflight I/Os> -- "
-           "specify the maximum number of checksumming I/Os [default is 200]\n");
+           "specify the maximum number of checksumming I/Os "
+           "[default is 200]\n");
        (void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
            "to make only that option verbose\n");
        (void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
@@ -1233,41 +1234,67 @@ dump_bpobj_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
 }
 
 static void
-dump_bpobj(bpobj_t *bpo, char *name)
+dump_bpobj(bpobj_t *bpo, char *name, int indent)
 {
        char bytes[32];
        char comp[32];
        char uncomp[32];
+       uint64_t i;
 
        if (dump_opt['d'] < 3)
                return;
 
        zdb_nicenum(bpo->bpo_phys->bpo_bytes, bytes);
-       if (bpo->bpo_havesubobj) {
+       if (bpo->bpo_havesubobj && bpo->bpo_phys->bpo_subobjs != 0) {
                zdb_nicenum(bpo->bpo_phys->bpo_comp, comp);
                zdb_nicenum(bpo->bpo_phys->bpo_uncomp, uncomp);
-               (void) printf("\n    %s: %llu local blkptrs, %llu subobjs, "
-                   "%s (%s/%s comp)\n",
-                   name, (u_longlong_t)bpo->bpo_phys->bpo_num_blkptrs,
+               (void) printf("    %*s: object %llu, %llu local blkptrs, "
+                   "%llu subobjs, %s (%s/%s comp)\n",
+                   indent * 8, name,
+                   (u_longlong_t)bpo->bpo_object,
+                   (u_longlong_t)bpo->bpo_phys->bpo_num_blkptrs,
                    (u_longlong_t)bpo->bpo_phys->bpo_num_subobjs,
                    bytes, comp, uncomp);
+
+               for (i = 0; i < bpo->bpo_phys->bpo_num_subobjs; i++) {
+                       uint64_t subobj;
+                       bpobj_t subbpo;
+                       int error;
+                       VERIFY0(dmu_read(bpo->bpo_os,
+                           bpo->bpo_phys->bpo_subobjs,
+                           i * sizeof (subobj), sizeof (subobj), &subobj, 0));
+                       error = bpobj_open(&subbpo, bpo->bpo_os, subobj);
+                       if (error != 0) {
+                               (void) printf("ERROR %u while trying to open "
+                                   "subobj id %llu\n",
+                                   error, (u_longlong_t)subobj);
+                               continue;
+                       }
+                       dump_bpobj(&subbpo, "subobj", indent + 1);
+               }
        } else {
-               (void) printf("\n    %s: %llu blkptrs, %s\n",
-                   name, (u_longlong_t)bpo->bpo_phys->bpo_num_blkptrs, bytes);
+               (void) printf("    %*s: object %llu, %llu blkptrs, %s\n",
+                   indent * 8, name,
+                   (u_longlong_t)bpo->bpo_object,
+                   (u_longlong_t)bpo->bpo_phys->bpo_num_blkptrs,
+                   bytes);
        }
 
        if (dump_opt['d'] < 5)
                return;
 
-       (void) printf("\n");
 
-       (void) bpobj_iterate_nofree(bpo, dump_bpobj_cb, NULL, NULL);
+       if (indent == 0) {
+               (void) bpobj_iterate_nofree(bpo, dump_bpobj_cb, NULL, NULL);
+               (void) printf("\n");
+       }
 }
 
 static void
 dump_deadlist(dsl_deadlist_t *dl)
 {
        dsl_deadlist_entry_t *dle;
+       uint64_t unused;
        char bytes[32];
        char comp[32];
        char uncomp[32];
@@ -1286,14 +1313,25 @@ dump_deadlist(dsl_deadlist_t *dl)
 
        (void) printf("\n");
 
+       /* force the tree to be loaded */
+       dsl_deadlist_space_range(dl, 0, UINT64_MAX, &unused, &unused, &unused);
+
        for (dle = avl_first(&dl->dl_tree); dle;
            dle = AVL_NEXT(&dl->dl_tree, dle)) {
-               (void) printf("      mintxg %llu -> obj %llu\n",
-                   (longlong_t)dle->dle_mintxg,
-                   (longlong_t)dle->dle_bpobj.bpo_object);
+               if (dump_opt['d'] >= 5) {
+                       char buf[128];
+                       (void) snprintf(buf, sizeof (buf),
+                           "mintxg %llu -> obj %llu",
+                           (longlong_t)dle->dle_mintxg,
+                           (longlong_t)dle->dle_bpobj.bpo_object);
+
+                       dump_bpobj(&dle->dle_bpobj, buf, 0);
+               } else {
+                       (void) printf("mintxg %llu -> obj %llu\n",
+                           (longlong_t)dle->dle_mintxg,
+                           (longlong_t)dle->dle_bpobj.bpo_object);
 
-               if (dump_opt['d'] >= 5)
-                       dump_bpobj(&dle->dle_bpobj, "");
+               }
        }
 }
 
@@ -1316,7 +1354,7 @@ fuid_table_destroy(void)
  * print uid or gid information.
  * For normal POSIX id just the id is printed in decimal format.
  * For CIFS files with FUID the fuid is printed in hex followed by
- * the doman-rid string.
+ * the domain-rid string.
  */
 static void
 print_idstr(uint64_t id, const char *id_type)
@@ -1400,7 +1438,7 @@ dump_znode_sa_xattr(sa_handle_t *hdl)
 
                (void) printf("\t\t%s = ", nvpair_name(elem));
                nvpair_value_byte_array(elem, &value, &cnt);
-               for (idx = 0 ; idx < cnt ; ++idx) {
+               for (idx = 0; idx < cnt; ++idx) {
                        if (isprint(value[idx]))
                                (void) putchar(value[idx]);
                        else
@@ -1725,7 +1763,9 @@ dump_dir(objset_t *os)
        int print_header = 1;
        int i, error;
 
+       dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
        dmu_objset_fast_stat(os, &dds);
+       dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
 
        if (dds.dds_type < DMU_OST_NUMTYPES)
                type = objset_types[dds.dds_type];
@@ -2171,7 +2211,6 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
 
                zio_nowait(zio_read(NULL, spa, bp, data, size,
                    zdb_blkptr_done, zcb, ZIO_PRIORITY_ASYNC_READ, flags, zb));
-
        }
 
        zcb->zcb_readfails = 0;
@@ -2357,7 +2396,7 @@ dump_block_stats(spa_t *spa)
         * it's not part of any space map) is a double allocation,
         * reference to a freed block, or an unclaimed log block.
         */
-       bzero(&zcb, sizeof(zdb_cb_t));
+       bzero(&zcb, sizeof (zdb_cb_t));
        zdb_leak_init(spa, &zcb);
 
        /*
@@ -2365,8 +2404,10 @@ dump_block_stats(spa_t *spa)
         */
        (void) bpobj_iterate_nofree(&spa->spa_deferred_bpobj,
            count_block_cb, &zcb, NULL);
-       (void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj,
-           count_block_cb, &zcb, NULL);
+       if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
+               (void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj,
+                   count_block_cb, &zcb, NULL);
+       }
        if (spa_feature_is_active(spa,
            &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
                VERIFY3U(0, ==, bptree_iterate(spa->spa_meta_objset,
@@ -2666,10 +2707,11 @@ dump_zpool(spa_t *spa)
        if (dump_opt['d'] || dump_opt['i']) {
                dump_dir(dp->dp_meta_objset);
                if (dump_opt['d'] >= 3) {
-                       dump_bpobj(&spa->spa_deferred_bpobj, "Deferred frees");
+                       dump_bpobj(&spa->spa_deferred_bpobj,
+                           "Deferred frees", 0);
                        if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
                                dump_bpobj(&spa->spa_dsl_pool->dp_free_bpobj,
-                                   "Pool snapshot frees");
+                                   "Pool snapshot frees", 0);
                        }
 
                        if (spa_feature_is_active(spa,