]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: bch2_fs_open() now takes a darray
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 28 Apr 2025 18:50:07 +0000 (14:50 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:37 +0000 (20:14 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/darray.h
fs/bcachefs/fs.c
fs/bcachefs/fsck.c
fs/bcachefs/super.c
fs/bcachefs/super.h
fs/bcachefs/util.c
fs/bcachefs/util.h

index 88f0ca3f0af51a8d67fdf58259c4b3d16d772230..50ec3decfe8c32e8e70211cc1ad539b2ee150018 100644 (file)
@@ -21,6 +21,7 @@ struct {                                                              \
 
 typedef DARRAY(char)   darray_char;
 typedef DARRAY(char *) darray_str;
+typedef DARRAY(const char *) darray_const_str;
 
 typedef DARRAY(u8)     darray_u8;
 typedef DARRAY(u16)    darray_u16;
index cdf84180829a045ca4ab80df2f92c040caa9edd3..9916bd38a599e85b03944ee765e47489be56cba9 100644 (file)
@@ -2441,7 +2441,7 @@ static int bch2_fs_get_tree(struct fs_context *fc)
        struct inode *vinode;
        struct bch2_opts_parse *opts_parse = fc->fs_private;
        struct bch_opts opts = opts_parse->opts;
-       darray_str devs;
+       darray_const_str devs;
        darray_fs devs_to_fs = {};
        int ret;
 
@@ -2465,7 +2465,7 @@ static int bch2_fs_get_tree(struct fs_context *fc)
        if (!IS_ERR(sb))
                goto got_sb;
 
-       c = bch2_fs_open(devs.data, devs.nr, opts);
+       c = bch2_fs_open(&devs, &opts);
        ret = PTR_ERR_OR_ZERO(c);
        if (ret)
                goto err;
index d927fdafd43ac6545f1d02edba55cbec162e1495..ef2d6cbffcc28f63d8ce2342fc1e3c62fcd0e7fd 100644 (file)
@@ -3059,7 +3059,7 @@ long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_arg)
 {
        struct bch_ioctl_fsck_offline arg;
        struct fsck_thread *thr = NULL;
-       darray_str(devs) = {};
+       darray_const_str devs = {};
        long ret = 0;
 
        if (copy_from_user(&arg, user_arg, sizeof(arg)))
@@ -3117,7 +3117,7 @@ long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_arg)
 
        bch2_thread_with_stdio_init(&thr->thr, &bch2_offline_fsck_ops);
 
-       thr->c = bch2_fs_open(devs.data, arg.nr_devs, thr->opts);
+       thr->c = bch2_fs_open(&devs, &thr->opts);
 
        if (!IS_ERR(thr->c) &&
            thr->c->opts.errors == BCH_ON_ERROR_panic)
index f29965469b28f8cd082153c6934ab321cdc5224c..5fcd7099bc6af614a6f66b43a0dd8b052e898f6a 100644 (file)
@@ -807,7 +807,7 @@ static int bch2_fs_init_rw(struct bch_fs *c)
        return 0;
 }
 
-static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts,
+static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts *opts,
                                    bch_sb_handles *sbs)
 {
        struct bch_fs *c;
@@ -821,7 +821,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts,
                goto out;
        }
 
-       c->stdio = (void *)(unsigned long) opts.stdio;
+       c->stdio = (void *)(unsigned long) opts->stdio;
 
        __module_get(THIS_MODULE);
 
@@ -921,7 +921,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts,
        if (ret)
                goto err;
 
-       bch2_opts_apply(&c->opts, opts);
+       bch2_opts_apply(&c->opts, *opts);
 
        c->btree_key_cache_btrees |= 1U << BTREE_ID_alloc;
        if (c->opts.inodes_use_key_cache)
@@ -2273,8 +2273,8 @@ static inline int sb_cmp(struct bch_sb *l, struct bch_sb *r)
                cmp_int(le64_to_cpu(l->write_time), le64_to_cpu(r->write_time));
 }
 
-struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
-                           struct bch_opts opts)
+struct bch_fs *bch2_fs_open(darray_const_str *devices,
+                           struct bch_opts *opts)
 {
        bch_sb_handles sbs = {};
        struct bch_fs *c = NULL;
@@ -2285,26 +2285,26 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
        if (!try_module_get(THIS_MODULE))
                return ERR_PTR(-ENODEV);
 
-       if (!nr_devices) {
+       if (!devices->nr) {
                ret = -EINVAL;
                goto err;
        }
 
-       ret = darray_make_room(&sbs, nr_devices);
+       ret = darray_make_room(&sbs, devices->nr);
        if (ret)
                goto err;
 
-       for (unsigned i = 0; i < nr_devices; i++) {
+       darray_for_each(*devices, i) {
                struct bch_sb_handle sb = { NULL };
 
-               ret = bch2_read_super(devices[i], &opts, &sb);
+               ret = bch2_read_super(*i, opts, &sb);
                if (ret)
                        goto err;
 
                BUG_ON(darray_push(&sbs, sb));
        }
 
-       if (opts.nochanges && !opts.read_only) {
+       if (opts->nochanges && !opts->read_only) {
                ret = -BCH_ERR_erofs_nochanges;
                goto err_print;
        }
@@ -2314,7 +2314,7 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
                        best = sb;
 
        darray_for_each_reverse(sbs, sb) {
-               ret = bch2_dev_in_fs(best, sb, &opts);
+               ret = bch2_dev_in_fs(best, sb, opts);
 
                if (ret == -BCH_ERR_device_has_been_removed ||
                    ret == -BCH_ERR_device_splitbrain) {
@@ -2358,7 +2358,7 @@ out:
        return c;
 err_print:
        pr_err("bch_fs_open err opening %s: %s",
-              devices[0], bch2_err_str(ret));
+              devices->data[0], bch2_err_str(ret));
 err:
        if (!IS_ERR_OR_NULL(c))
                bch2_fs_stop(c);
index a1566f2d77c33f348b6fbc60541bc2f42e9f3d5f..be75603fefe90bb0e2b70cfc3e727aa171468706 100644 (file)
@@ -45,7 +45,7 @@ void bch2_fs_free(struct bch_fs *);
 void bch2_fs_stop(struct bch_fs *);
 
 int bch2_fs_start(struct bch_fs *);
-struct bch_fs *bch2_fs_open(char * const *, unsigned, struct bch_opts);
+struct bch_fs *bch2_fs_open(darray_const_str *, struct bch_opts *);
 
 extern const struct blk_holder_ops bch2_sb_handle_bdev_ops;
 
index 1cff407c8c9dcecba9d3af99d5fc3abf25d6ca42..dc3817f545fa7eb657f108012e66ba03391c5630 100644 (file)
@@ -1016,14 +1016,14 @@ u64 *bch2_acc_percpu_u64s(u64 __percpu *p, unsigned nr)
        return ret;
 }
 
-void bch2_darray_str_exit(darray_str *d)
+void bch2_darray_str_exit(darray_const_str *d)
 {
        darray_for_each(*d, i)
                kfree(*i);
        darray_exit(d);
 }
 
-int bch2_split_devs(const char *_dev_name, darray_str *ret)
+int bch2_split_devs(const char *_dev_name, darray_const_str *ret)
 {
        darray_init(ret);
 
index 7a93e187a49ad3956ac62055fd0a09f5ed0cdbee..14cb2c7dfda4396f97b3b7ed66434d21ad82ab93 100644 (file)
@@ -690,8 +690,8 @@ static inline bool qstr_eq(const struct qstr l, const struct qstr r)
        return l.len == r.len && !memcmp(l.name, r.name, l.len);
 }
 
-void bch2_darray_str_exit(darray_str *);
-int bch2_split_devs(const char *, darray_str *);
+void bch2_darray_str_exit(darray_const_str *);
+int bch2_split_devs(const char *, darray_const_str *);
 
 #ifdef __KERNEL__