Fix device add for kernel sysfs changes

Also slightly improve some error messages

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2021-12-10 14:07:31 -05:00
parent 55e3496d06
commit 2fc5a50bd6
3 changed files with 11 additions and 8 deletions

View 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,

View 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)

View 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;