From 2fc5a50bd67ec1d8d7930bbf9dfe03e86884277a Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Fri, 10 Dec 2021 14:07:31 -0500 Subject: [PATCH] Fix device add for kernel sysfs changes Also slightly improve some error messages Signed-off-by: Kent Overstreet --- cmd_device.c | 9 ++++----- libbcachefs.c | 4 +++- tools-util.c | 6 ++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd_device.c b/cmd_device.c index e7e33367..c5d516bf 100644 --- a/cmd_device.c +++ b/cmd_device.c @@ -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, diff --git a/libbcachefs.c b/libbcachefs.c index beba6f33..fbf4c6e3 100644 --- a/libbcachefs.c +++ b/libbcachefs.c @@ -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) diff --git a/tools-util.c b/tools-util.c index 3cc0de44..acae27d0 100644 --- a/tools-util.c +++ b/tools-util.c @@ -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;