btrfs-progs: fix type mismatch in backtrace dumping functions
[platform/upstream/btrfs-progs.git] / cmds-inspect.c
index 82727ab..dd7b9dd 100644 (file)
@@ -33,6 +33,7 @@
 #include "btrfs-list.h"
 #include "cmds-inspect-dump-tree.h"
 #include "cmds-inspect-dump-super.h"
+#include "cmds-inspect-tree-stats.h"
 
 static const char * const inspect_cmd_group_usage[] = {
        "btrfs inspect-internal <command> <args>",
@@ -53,7 +54,7 @@ static int __ino_to_path_fd(u64 inum, int fd, int verbose, const char *prepend)
 
        ret = ioctl(fd, BTRFS_IOC_INO_PATHS, &ipa);
        if (ret < 0) {
-               printf("ioctl ret=%d, error: %s\n", ret, strerror(errno));
+               error("ino paths ioctl: %s", strerror(errno));
                goto out;
        }
 
@@ -192,7 +193,7 @@ static int cmd_inspect_logical_resolve(int argc, char **argv)
 
        ret = ioctl(fd, BTRFS_IOC_LOGICAL_INO, &loi);
        if (ret < 0) {
-               printf("ioctl ret=%d, error: %s\n", ret, strerror(errno));
+               error("logical ino ioctl: %s", strerror(errno));
                goto out;
        }
 
@@ -273,7 +274,7 @@ static int cmd_inspect_subvolid_resolve(int argc, char **argv)
        if (check_argc_exact(argc - optind, 2))
                usage(cmd_inspect_subvolid_resolve_usage);
 
-       fd = btrfs_open_dir(argv[optind], &dirstream, 1);
+       fd = btrfs_open_dir(argv[optind + 1], &dirstream, 1);
        if (fd < 0) {
                ret = -ENOENT;
                goto out;
@@ -283,8 +284,7 @@ static int cmd_inspect_subvolid_resolve(int argc, char **argv)
        ret = btrfs_subvolid_resolve(fd, path, sizeof(path), subvol_id);
 
        if (ret) {
-               fprintf(stderr,
-                       "btrfs_subvolid_resolve(subvol_id %llu) failed with ret=%d\n",
+               error("resolving subvolid %llu error %d",
                        (unsigned long long)subvol_id, ret);
                goto out;
        }
@@ -294,7 +294,7 @@ static int cmd_inspect_subvolid_resolve(int argc, char **argv)
 
 out:
        close_file_or_dir(fd, dirstream);
-       return ret ? 1 : 0;
+       return !!ret;
 }
 
 static const char* const cmd_inspect_rootid_usage[] = {
@@ -323,7 +323,7 @@ static int cmd_inspect_rootid(int argc, char **argv)
 
        ret = lookup_ino_rootid(fd, &rootid);
        if (ret) {
-               fprintf(stderr, "rootid failed with ret=%d\n", ret);
+               error("rootid failed with ret=%d", ret);
                goto out;
        }
 
@@ -415,7 +415,7 @@ static void adjust_dev_min_size(struct list_head *extents,
        /*
         * List of device extents is sorted by descending order of the extent's
         * end offset. If some extent goes beyond the computed minimum size,
-        * which initially matches the sum of the lenghts of all extents,
+        * which initially matches the sum of the lengths of all extents,
         * we need to check if the extent can be relocated to an hole in the
         * device between [0, *min_size[ (which is what the resize ioctl does).
         */
@@ -521,9 +521,7 @@ static int print_min_dev_size(int fd, u64 devid)
 
                ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
                if (ret < 0) {
-                       fprintf(stderr,
-                               "Error invoking tree search ioctl: %s\n",
-                               strerror(errno));
+                       error("tree search ioctl: %s", strerror(errno));
                        ret = 1;
                        goto out;
                }
@@ -539,32 +537,33 @@ static int print_min_dev_size(int fd, u64 devid)
                                                                  off);
                        off += sizeof(*sh);
                        extent = (struct btrfs_dev_extent *)(args.buf + off);
-                       off += sh->len;
+                       off += btrfs_search_header_len(sh);
 
-                       sk->min_objectid = sh->objectid;
-                       sk->min_type = sh->type;
-                       sk->min_offset = sh->offset + 1;
+                       sk->min_objectid = btrfs_search_header_objectid(sh);
+                       sk->min_type = btrfs_search_header_type(sh);
+                       sk->min_offset = btrfs_search_header_offset(sh) + 1;
 
-                       if (sh->objectid != devid ||
-                           sh->type != BTRFS_DEV_EXTENT_KEY)
+                       if (btrfs_search_header_objectid(sh) != devid ||
+                           btrfs_search_header_type(sh) != BTRFS_DEV_EXTENT_KEY)
                                continue;
 
                        len = btrfs_stack_dev_extent_length(extent);
                        min_size += len;
-                       ret = add_dev_extent(&extents, sh->offset,
-                                            sh->offset + len - 1, 0);
+                       ret = add_dev_extent(&extents,
+                               btrfs_search_header_offset(sh),
+                               btrfs_search_header_offset(sh) + len - 1, 0);
 
                        if (!ret && last_pos != (u64)-1 &&
-                           last_pos != sh->offset)
+                           last_pos != btrfs_search_header_offset(sh))
                                ret = add_dev_extent(&holes, last_pos,
-                                                    sh->offset - 1, 1);
+                                       btrfs_search_header_offset(sh) - 1, 1);
                        if (ret) {
-                               fprintf(stderr, "Error: %s\n", strerror(-ret));
+                               error("add device extent: %s", strerror(-ret));
                                ret = 1;
                                goto out;
                        }
 
-                       last_pos = sh->offset + len;
+                       last_pos = btrfs_search_header_offset(sh) + len;
                }
 
                if (sk->min_type != BTRFS_DEV_EXTENT_KEY ||
@@ -624,16 +623,6 @@ out:
        return !!ret;
 }
 
-static int cmd_inspect_dump_tree_hook(int argc, char **argv)
-{
-       return cmd_inspect_dump_tree(argc, argv);
-}
-
-static int cmd_inspect_dump_super_hook(int argc, char **argv)
-{
-       return cmd_inspect_dump_super(argc, argv);
-}
-
 static const char inspect_cmd_group_info[] =
 "query various internal information";
 
@@ -649,10 +638,12 @@ const struct cmd_group inspect_cmd_group = {
                        0 },
                { "min-dev-size", cmd_inspect_min_dev_size,
                        cmd_inspect_min_dev_size_usage, NULL, 0 },
-               { "dump-tree", cmd_inspect_dump_tree_hook,
+               { "dump-tree", cmd_inspect_dump_tree,
                                cmd_inspect_dump_tree_usage, NULL, 0 },
-               { "dump-super", cmd_inspect_dump_super_hook,
+               { "dump-super", cmd_inspect_dump_super,
                                cmd_inspect_dump_super_usage, NULL, 0 },
+               { "tree-stats", cmd_inspect_tree_stats,
+                               cmd_inspect_tree_stats_usage, NULL, 0 },
                NULL_CMD_STRUCT
        }
 };