btrfs-progs: switch more error messages to common helpers
authorDavid Sterba <dsterba@suse.com>
Wed, 2 Mar 2016 14:47:19 +0000 (15:47 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 14 Mar 2016 12:42:47 +0000 (13:42 +0100)
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-fi-du.c
cmds-inspect-dump-super.c
cmds-inspect-dump-tree.c
cmds-inspect.c

index 236318b..09d4a65 100644 (file)
@@ -427,8 +427,7 @@ static int du_add_file(const char *filename, int dirfd,
                return 0;
 
        if (len > (path_max - pathp)) {
-               fprintf(stderr, "ERROR: Path max exceeded: %s %s\n", path,
-                       filename);
+               error("path too long: %s %s", path, filename);
                return ENAMETOOLONG;
        }
 
@@ -534,7 +533,7 @@ const char * const cmd_filesystem_du_usage[] = {
 
 int cmd_filesystem_du(int argc, char **argv)
 {
-       int ret = 0, error = 0;
+       int ret = 0, err = 0;
        int i;
 
        unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
@@ -566,14 +565,14 @@ int cmd_filesystem_du(int argc, char **argv)
        for (i = optind; i < argc; i++) {
                ret = du_add_file(argv[i], AT_FDCWD, NULL, NULL, NULL, 1);
                if (ret) {
-                       fprintf(stderr, "ERROR: can't check space of '%s': %s\n",
-                               argv[i], strerror(ret));
-                       error = 1;
+                       error("cannot check space of '%s': %s", argv[i],
+                                       strerror(ret));
+                       err = 1;
                }
 
                /* reset hard-link detection for each argument */
                clear_seen_inodes();
        }
 
-       return error;
+       return err;
 }
index 12d93c5..ff7257e 100644 (file)
@@ -62,7 +62,7 @@ static void print_sys_chunk_array(struct btrfs_super_block *sb)
 
        buf = malloc(sizeof(*buf) + sizeof(*sb));
        if (!buf) {
-               fprintf(stderr, "%s\n", strerror(ENOMEM));
+               error("not enough memory");
                goto out;
        }
        write_extent_buffer(buf, sb, 0, sizeof(*sb));
@@ -424,19 +424,16 @@ static int load_and_dump_sb(char *filename, int fd, u64 sb_bytenr, int full,
                if (ret == 0 && errno == 0)
                        return 0;
 
-               fprintf(stderr,
-                  "ERROR: Failed to read the superblock on %s at %llu\n",
-                  filename, (unsigned long long)sb_bytenr);
-               fprintf(stderr,
-                  "ERROR: error = '%s', errno = %d\n", strerror(errno), errno);
+               error("failed to read the superblock on %s at %llu",
+                               filename, (unsigned long long)sb_bytenr);
+               error("error = '%s', errno = %d", strerror(errno), errno);
                return 1;
        }
        printf("superblock: bytenr=%llu, device=%s\n", sb_bytenr, filename);
        printf("---------------------------------------------------------\n");
        if (btrfs_super_magic(sb) != BTRFS_MAGIC && !force) {
-               fprintf(stderr,
-                   "ERROR: bad magic on superblock on %s at %llu\n",
-                   filename, (unsigned long long)sb_bytenr);
+               error("bad magic on superblock on %s at %llu",
+                               filename, (unsigned long long)sb_bytenr);
        } else {
                dump_superblock(sb, full);
        }
@@ -472,9 +469,8 @@ int cmd_inspect_dump_super(int argc, char **argv)
                case 'i':
                        arg = arg_strtou64(optarg);
                        if (arg >= BTRFS_SUPER_MIRROR_MAX) {
-                               fprintf(stderr,
-                                       "Illegal super_mirror %llu\n",
-                                       arg);
+                               error("super mirror too big: %llu >= %d",
+                                       arg, BTRFS_SUPER_MIRROR_MAX);
                                usage(cmd_inspect_dump_super_usage);
                        }
                        sb_bytenr = btrfs_sb_offset(arg);
@@ -505,7 +501,7 @@ int cmd_inspect_dump_super(int argc, char **argv)
                filename = argv[i];
                fd = open(filename, O_RDONLY, 0666);
                if (fd < 0) {
-                       fprintf(stderr, "Could not open %s\n", filename);
+                       error("cannot open %s: %s", filename, strerror(errno));
                        ret = 1;
                        goto out;
                }
index 6ce6edc..17f9700 100644 (file)
@@ -191,20 +191,19 @@ int cmd_inspect_dump_tree(int argc, char **argv)
 
        ret = check_arg_type(argv[optind]);
        if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) {
-               fprintf(stderr, "'%s' is not a block device or regular file\n",
-                       argv[optind]);
+               error("not a block device or regular file: %s", argv[optind]);
                goto out;
        }
 
        info = open_ctree_fs_info(argv[optind], 0, 0, OPEN_CTREE_PARTIAL);
        if (!info) {
-               fprintf(stderr, "unable to open %s\n", argv[optind]);
+               error("unable to open %s", argv[optind]);
                goto out;
        }
 
        root = info->fs_root;
        if (!root) {
-               fprintf(stderr, "unable to open %s\n", argv[optind]);
+               error("unable to open %s", argv[optind]);
                goto out;
        }
 
@@ -225,7 +224,7 @@ int cmd_inspect_dump_tree(int argc, char **argv)
                                              root->nodesize, 0);
                }
                if (!extent_buffer_uptodate(leaf)) {
-                       fprintf(stderr, "failed to read %llu\n",
+                       error("failed to read %llu",
                                (unsigned long long)block_only);
                        goto close_root;
                }
index 3e753e4..04e1ae8 100644 (file)
@@ -53,7 +53,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 +192,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;
        }
 
@@ -283,8 +283,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;
        }
@@ -323,7 +322,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;
        }
 
@@ -521,9 +520,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;
                }
@@ -559,7 +556,7 @@ static int print_min_dev_size(int fd, u64 devid)
                                ret = add_dev_extent(&holes, last_pos,
                                                     sh->offset - 1, 1);
                        if (ret) {
-                               fprintf(stderr, "Error: %s\n", strerror(-ret));
+                               error("add device extent: %s", strerror(-ret));
                                ret = 1;
                                goto out;
                        }