]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Fix device add for kernel sysfs changes
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 10 Dec 2021 19:07:31 +0000 (14:07 -0500)
committerKent Overstreet <kent.overstreet@gmail.com>
Fri, 10 Dec 2021 19:07:31 +0000 (14:07 -0500)
Also slightly improve some error messages

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
cmd_device.c
libbcachefs.c
tools-util.c

index e7e33367066ca27a08220bf6046a0439d20012b0..c5d516bf0cb6113419901bbdd52e545eb2a41197 100644 (file)
@@ -104,8 +104,8 @@ int cmd_device_add(int argc, char *argv[])
        if (!fs_path)
                die("Please supply a filesystem");
 
-       char *dev_path = arg_pop();
-       if (!dev_path)
+       dev_opts.path = arg_pop();
+       if (!dev_opts.path)
                die("Please supply a device");
 
        if (argc)
@@ -113,7 +113,6 @@ int cmd_device_add(int argc, char *argv[])
 
        struct bchfs_handle fs = bcache_fs_open(fs_path);
 
-       dev_opts.path = dev_path;
        dev_opts.fd = open_for_format(dev_opts.path, force);
 
        struct bch_opt_strs fs_opt_strs;
@@ -122,9 +121,9 @@ int cmd_device_add(int argc, char *argv[])
        struct bch_opts fs_opts = bch2_parse_opts(fs_opt_strs);
 
        opt_set(fs_opts, block_size,
-               read_file_u64(fs.sysfs_fd, "block_size") >> 9);
+               read_file_u64(fs.sysfs_fd, "options/block_size") >> 9);
        opt_set(fs_opts, btree_node_size,
-               read_file_u64(fs.sysfs_fd, "btree_node_size") >> 9);
+               read_file_u64(fs.sysfs_fd, "options/btree_node_size") >> 9);
 
        struct bch_sb *sb = bch2_format(fs_opt_strs,
                                        fs_opts,
index beba6f33dbc75198cfc3f60da94ee197b43f4d52..fbf4c6e36dc0c19e208dc6e9e47ec90fd27119ba 100644 (file)
@@ -899,7 +899,9 @@ struct bchfs_handle bcache_fs_open(const char *path)
                free(ctl);
        } else {
                /* It's a path: */
-               ret.ioctl_fd = xopen(path, O_RDONLY);
+               ret.ioctl_fd = open(path, O_RDONLY);
+               if (ret.ioctl_fd < 0)
+                       die("Error opening filesystem at %s: %m", path);
 
                struct bch_ioctl_query_uuid uuid;
                if (ioctl(ret.ioctl_fd, BCH_IOCTL_QUERY_UUID, &uuid) < 0)
index 3cc0de444cf95b32d2def2e16c476c6bd726bcb6..acae27d016b47e5db8add3b6db7de8ec903beea5 100644 (file)
@@ -211,7 +211,7 @@ u64 read_file_u64(int dirfd, const char *path)
 {
        char *buf = read_file_str(dirfd, path);
        u64 v;
-       if (kstrtou64(buf, 10, &v))
+       if (bch2_strtou64_h(buf, &v))
                die("read_file_u64: error parsing %s (got %s)", path, buf);
        free(buf);
        return v;
@@ -262,7 +262,9 @@ int open_for_format(const char *dev, bool force)
        const char *fs_type = NULL, *fs_label = NULL;
        size_t fs_type_len, fs_label_len;
 
-       int fd = xopen(dev, O_RDWR|O_EXCL);
+       int fd = open(dev, O_RDWR|O_EXCL);
+       if (fd < 0)
+               die("Error opening device to format %s: %m", dev);
 
        if (force)
                return fd;