]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
cmd_list improvements; use %m
authorKent Overstreet <kent.overstreet@gmail.com>
Sat, 15 Apr 2017 04:40:50 +0000 (20:40 -0800)
committerKent Overstreet <kent.overstreet@gmail.com>
Sat, 15 Apr 2017 04:40:50 +0000 (20:40 -0800)
cmd_assemble.c
cmd_debug.c
cmd_device.c
cmd_migrate.c
crypto.c
libbcachefs.c
linux/blkdev.c
tools-util.c
tools-util.h

index 5f981d711ebc2a16e579ca58aa0e97015495ea45..735b368aa9043f8b43ebefc0c76c9dbba84c4284 100644 (file)
@@ -26,10 +26,7 @@ int cmd_assemble(int argc, char *argv[])
        for (unsigned i = 1; i < argc; i++)
             assemble->devs[i] = (__u64) argv[i];
 
-       int ret = ioctl(bcachectl_open(), BCH_IOCTL_ASSEMBLE, assemble);
-       if (ret < 0)
-               die("BCH_IOCTL_ASSEMBLE error: %s", strerror(errno));
-
+       xioctl(bcachectl_open(), BCH_IOCTL_ASSEMBLE, assemble);
        return 0;
 }
 
@@ -42,9 +39,6 @@ int cmd_incremental(int argc, char *argv[])
                .dev = (__u64) argv[1],
        };
 
-       int ret = ioctl(bcachectl_open(), BCH_IOCTL_INCREMENTAL, &incremental);
-       if (ret < 0)
-               die("BCH_IOCTL_INCREMENTAL error: %s", strerror(errno));
-
+       xioctl(bcachectl_open(), BCH_IOCTL_INCREMENTAL, &incremental);
        return 0;
 }
index ef4fa8481904f08e337c1c719c8f8e7968dc4f90..d825753d011bf225e208d0c806db12686346af37 100644 (file)
@@ -13,6 +13,7 @@
 #include "btree_cache.h"
 #include "btree_iter.h"
 #include "buckets.h"
+#include "error.h"
 #include "journal.h"
 #include "super.h"
 
@@ -153,7 +154,7 @@ int cmd_dump(int argc, char *argv[])
 }
 
 static void list_keys(struct bch_fs *c, enum btree_id btree_id,
-                     struct bpos start, struct bpos end, int mode)
+                     struct bpos start, struct bpos end)
 {
        struct btree_iter iter;
        struct bkey_s_c k;
@@ -171,7 +172,7 @@ static void list_keys(struct bch_fs *c, enum btree_id btree_id,
 }
 
 static void list_btree_formats(struct bch_fs *c, enum btree_id btree_id,
-                              struct bpos start, struct bpos end, int mode)
+                              struct bpos start, struct bpos end)
 {
        struct btree_iter iter;
        struct btree *b;
@@ -187,6 +188,36 @@ static void list_btree_formats(struct bch_fs *c, enum btree_id btree_id,
        bch2_btree_iter_unlock(&iter);
 }
 
+static void list_nodes_keys(struct bch_fs *c, enum btree_id btree_id,
+                           struct bpos start, struct bpos end)
+{
+       struct btree_iter iter;
+       struct btree_node_iter node_iter;
+       struct bkey unpacked;
+       struct bkey_s_c k;
+       struct btree *b;
+       char buf[4096];
+
+       for_each_btree_node(&iter, c, btree_id, start, 0, b) {
+               if (bkey_cmp(b->key.k.p, end) > 0)
+                       break;
+
+               bch2_print_btree_node(c, b, buf, sizeof(buf));
+               fputs(buf, stdout);
+
+               buf[0] = '\t';
+
+               for_each_btree_node_key_unpack(b, k, &node_iter,
+                                              btree_node_is_extents(b),
+                                              &unpacked) {
+                       bch2_bkey_val_to_text(c, bkey_type(0, btree_id),
+                                             buf + 1, sizeof(buf) - 1, k);
+                       puts(buf);
+               }
+       }
+       bch2_btree_iter_unlock(&iter);
+}
+
 static struct bpos parse_pos(char *buf)
 {
        char *s = buf, *field;
@@ -224,6 +255,7 @@ static void list_keys_usage(void)
 static const char * const list_modes[] = {
        "keys",
        "formats",
+       "nodes",
        NULL
 };
 
@@ -241,7 +273,7 @@ int cmd_list(int argc, char *argv[])
        opts.norecovery = true;
        opts.errors     = BCH_ON_ERROR_CONTINUE;
 
-       while ((opt = getopt(argc, argv, "b:s:e:i:m:h")) != -1)
+       while ((opt = getopt(argc, argv, "b:s:e:i:m:fvh")) != -1)
                switch (opt) {
                case 'b':
                        btree_id = read_string_list_or_die(optarg,
@@ -263,6 +295,13 @@ int cmd_list(int argc, char *argv[])
                        mode = read_string_list_or_die(optarg,
                                                list_modes, "list mode");
                        break;
+               case 'f':
+                       opts.fix_errors = FSCK_ERR_YES;
+                       opts.norecovery = false;
+                       break;
+               case 'v':
+                       opts.verbose_recovery = true;
+                       break;
                case 'h':
                        list_keys_usage();
                        exit(EXIT_SUCCESS);
@@ -277,10 +316,13 @@ int cmd_list(int argc, char *argv[])
 
        switch (mode) {
        case 0:
-               list_keys(c, btree_id, start, end, mode);
+               list_keys(c, btree_id, start, end);
                break;
        case 1:
-               list_btree_formats(c, btree_id, start, end, mode);
+               list_btree_formats(c, btree_id, start, end);
+               break;
+       case 2:
+               list_nodes_keys(c, btree_id, start, end);
                break;
        default:
                die("Invalid mode");
index 2f7a7bc1246185a21c47b82b6a0e924ac22c61f3..d45d18ba2da958483088ad6d8d3df273bdfa65d3 100644 (file)
@@ -119,7 +119,7 @@ int cmd_device_show(int argc, char *argv[])
                char link[PATH_MAX];
                if (readlinkat(dirfd(fs.sysfs), entry->d_name,
                               link, sizeof(link)) < 0)
-                       die("readlink error: %s\n", strerror(errno));
+                       die("readlink error: %m\n");
 
                char *dev_name = basename(dirname(link));
 
index 8ce84d657076ff5a0e1052c59c6c58649884b0be..a18aae10b5b7e107c7da51553fe373e814f83875 100644 (file)
@@ -45,7 +45,7 @@ static char *dev_t_to_path(dev_t dev)
        free(sysfs_dev);
 
        if (ret < 0 || ret >= sizeof(link))
-               die("readlink error while looking up block device: %s", strerror(errno));
+               die("readlink error while looking up block device: %m");
 
        link[ret] = '\0';
 
@@ -222,7 +222,7 @@ static void copy_xattrs(struct bch_fs *c, struct bch_inode_unpacked *dst,
        char attrs[XATTR_LIST_MAX];
        ssize_t attrs_size = llistxattr(src, attrs, sizeof(attrs));
        if (attrs_size < 0)
-               die("listxattr error: %s", strerror(errno));
+               die("listxattr error: %m");
 
        for (const char *next, *attr = attrs;
             attr < attrs + attrs_size;
@@ -233,7 +233,7 @@ static void copy_xattrs(struct bch_fs *c, struct bch_inode_unpacked *dst,
                ssize_t val_size = lgetxattr(src, attr, val, sizeof(val));
 
                if (val_size < 0)
-                       die("error getting xattr val: %s", strerror(errno));
+                       die("error getting xattr val: %m");
 
                const struct xattr_handler *h = xattr_resolve_name(&attr);
 
@@ -356,7 +356,7 @@ static void copy_link(struct bch_fs *c, struct bch_inode_unpacked *dst,
 {
        ssize_t ret = readlink(src, buf, sizeof(buf));
        if (ret < 0)
-               die("readlink error: %s", strerror(errno));
+               die("readlink error: %m");
 
        write_data(c, dst, 0, buf, round_up(ret, block_bytes(c)));
 }
@@ -428,7 +428,7 @@ static void copy_dir(struct copy_fs_state *s,
                int fd;
 
                if (fchdir(src_fd))
-                       die("chdir error: %s", strerror(errno));
+                       die("chdir error: %m");
 
                struct stat stat =
                        xfstatat(src_fd, d->d_name, AT_SYMLINK_NOFOLLOW);
@@ -499,7 +499,7 @@ next:
        }
 
        if (errno)
-               die("readdir error: %s", strerror(errno));
+               die("readdir error: %m");
 }
 
 static ranges reserve_new_fs_space(const char *file_path, unsigned block_size,
@@ -510,8 +510,8 @@ static ranges reserve_new_fs_space(const char *file_path, unsigned block_size,
                ? open(file_path, O_RDWR|O_CREAT, 0600)
                : open(file_path, O_RDWR|O_CREAT|O_EXCL, 0600);
        if (fd < 0)
-               die("Error creating %s for bcachefs metadata: %s",
-                   file_path, strerror(errno));
+               die("Error creating %s for bcachefs metadata: %m",
+                   file_path);
 
        struct stat statbuf = xfstat(fd);
 
@@ -521,8 +521,7 @@ static ranges reserve_new_fs_space(const char *file_path, unsigned block_size,
        *bcachefs_inum = statbuf.st_ino;
 
        if (fallocate(fd, 0, 0, size))
-               die("Error reserving space for bcachefs metadata: %s",
-                   strerror(errno));
+               die("Error reserving space for bcachefs metadata: %m");
 
        fsync(fd);
 
@@ -581,7 +580,7 @@ static void copy_fs(struct bch_fs *c, int src_fd, const char *src_path,
                die("error looking up root directory: %s", strerror(-ret));
 
        if (fchdir(src_fd))
-               die("chdir error: %s", strerror(errno));
+               die("chdir error: %m");
 
        struct stat stat = xfstat(src_fd);
        copy_times(c, &root_inode, &stat);
index c692c59ab9f01660f770438d3aa09aac0c932f6c..f9ac57f7bf5ce9253c86677e983989f12606df74 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -109,7 +109,7 @@ void bch2_add_key(struct bch_sb *sb, const char *passphrase)
            add_key("user", description,
                    &passphrase_key, sizeof(passphrase_key),
                    KEY_SPEC_USER_KEYRING) < 0)
-               die("add_key error: %s", strerror(errno));
+               die("add_key error: %m");
 
        memzero_explicit(description, strlen(description));
        free(description);
index 16bcd0c6e836432aad00ced8e808048bd60664a9..73ea2d131b227d6faac057e4950e0db5a4c375b3 100644 (file)
@@ -186,7 +186,7 @@ struct bch_sb *bch2_format(struct format_opts opts,
 
        struct timespec now;
        if (clock_gettime(CLOCK_REALTIME, &now))
-               die("error getting current time: %s", strerror(errno));
+               die("error getting current time: %m");
 
        sb->time_base_lo        = cpu_to_le64(now.tv_sec * NSEC_PER_SEC + now.tv_nsec);
        sb->time_precision      = cpu_to_le32(1);
index 93459d0b84c92dddf414a1de94f6a3620cece485..c72df60fdf10e8bb1a605bb9a7b88c34780fa46b 100644 (file)
@@ -23,8 +23,7 @@ int submit_bio_wait(struct bio *bio)
        if (bio->bi_opf & REQ_PREFLUSH) {
                ret = fdatasync(bio->bi_bdev->bd_fd);
                if (ret) {
-                       fprintf(stderr, "fsync error: %s\n",
-                               strerror(errno));
+                       fprintf(stderr, "fsync error: %m\n");
                        return -EIO;
                }
        }
@@ -56,16 +55,14 @@ int submit_bio_wait(struct bio *bio)
        }
 
        if (ret != bio->bi_iter.bi_size) {
-               fprintf(stderr, "IO error: %li (%s)\n",
-                       ret, strerror(errno));
+               fprintf(stderr, "IO error: %li (%m)\n", ret);
                return -EIO;
        }
 
        if (bio->bi_opf & REQ_FUA) {
                ret = fdatasync(bio->bi_bdev->bd_fd);
                if (ret) {
-                       fprintf(stderr, "fsync error: %s\n",
-                               strerror(errno));
+                       fprintf(stderr, "fsync error: %m\n");
                        return -EIO;
                }
        }
index bd114af31b7e07ed2f1782493f020fb54f1f8fdf..f48b015b1d32febe2728446139a94e651455b139 100644 (file)
@@ -67,7 +67,7 @@ char *read_file_str(int dirfd, const char *path)
 
        len = read(fd, buf, len);
        if (len < 0)
-               die("read error: %s", strerror(errno));
+               die("read error: %m");
 
        buf[len] = '\0';
        if (len && buf[len - 1] == '\n')
index 732c5108272cf3877ce5e7ebee28b3ed1bb643fd..8f4e3d7368da353aa1279b594c777d49d4468114 100644 (file)
@@ -66,14 +66,14 @@ static inline void xpwrite(int fd, const void *buf, size_t count, off_t offset)
        ssize_t r = pwrite(fd, buf, count, offset);
 
        if (r != count)
-               die("write error (ret %zi err %s)", r, strerror(errno));
+               die("write error (ret %zi err %m)", r);
 }
 
 #define xopenat(_dirfd, _path, ...)                                    \
 ({                                                                     \
        int _fd = openat((_dirfd), (_path), __VA_ARGS__);               \
        if (_fd < 0)                                                    \
-               die("Error opening %s: %s", (_path), strerror(errno));  \
+               die("Error opening %s: %m", (_path));                   \
        _fd;                                                            \
 })
 
@@ -83,7 +83,7 @@ static inline struct stat xfstatat(int dirfd, const char *path, int flags)
 {
        struct stat stat;
        if (fstatat(dirfd, path, &stat, flags))
-               die("stat error: %s", strerror(errno));
+               die("stat error: %m");
        return stat;
 }
 
@@ -91,14 +91,14 @@ static inline struct stat xfstat(int fd)
 {
        struct stat stat;
        if (fstat(fd, &stat))
-               die("stat error: %s", strerror(errno));
+               die("stat error: %m");
        return stat;
 }
 
 #define xioctl(_fd, _nr, ...)                                          \
 do {                                                                   \
        if (ioctl((_fd), (_nr), ##__VA_ARGS__))                         \
-               die(#_nr " ioctl error: %s", strerror(errno));          \
+               die(#_nr " ioctl error: %m");                           \
 } while (0)
 
 enum units {