]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Update bcachefs sources to c6d45169c6 bcachefs: Convert split_devs() to darray
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 23 Dec 2023 02:21:14 +0000 (21:21 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 23 Dec 2023 02:21:14 +0000 (21:21 -0500)
21 files changed:
.bcachefs_revision
libbcachefs/bcachefs_format.h
libbcachefs/btree_gc.c
libbcachefs/btree_io.c
libbcachefs/btree_trans_commit.c
libbcachefs/btree_update.c
libbcachefs/btree_update_interior.c
libbcachefs/darray.h
libbcachefs/data_update.c
libbcachefs/ec.c
libbcachefs/extents.c
libbcachefs/extents.h
libbcachefs/fs.c
libbcachefs/io_misc.c
libbcachefs/io_write.c
libbcachefs/journal_io.c
libbcachefs/keylist.c
libbcachefs/keylist.h
libbcachefs/move.c
libbcachefs/util.c
libbcachefs/util.h

index f6757060767a41ef31b2cba8d64c7a77f76ff746..9e8cc23aa66de7028da4d79d751922c11768d37a 100644 (file)
@@ -1 +1 @@
-df6415fefb2790c3b95fa87ead779e7d2c654379
+c6d45169c6e3b4e42a189c9e87d1d14070033f01
index ebd4f25e094b016eba098b842bd8d25b47a686d4..c6b09501c7a8859c2a2591cf0cbc9f8b93ea366c 100644 (file)
@@ -2147,6 +2147,19 @@ enum {
        BCH_JSET_ENTRY_NR
 };
 
+static inline bool jset_entry_is_key(struct jset_entry *e)
+{
+       switch (e->type) {
+       case BCH_JSET_ENTRY_btree_keys:
+       case BCH_JSET_ENTRY_btree_root:
+       case BCH_JSET_ENTRY_overwrite:
+       case BCH_JSET_ENTRY_write_buffer_keys:
+               return true;
+       }
+
+       return false;
+}
+
 /*
  * Journal sequence numbers can be blacklisted: bsets record the max sequence
  * number of all the journal entries they contain updates for, so that on
index ea1d0ed70f5022e2793d9d4c01b075c6568a112b..9f27cb3ea5633c355dc07a936408908389ac10d7 100644 (file)
@@ -1844,7 +1844,6 @@ static int gc_btree_gens_key(struct btree_trans *trans,
 {
        struct bch_fs *c = trans->c;
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
        struct bkey_i *u;
        int ret;
 
index f0cbc9158e4cbdc3f985f72c016d3bb97365823d..d9abf90e1f8182d83117215e5bab1988755666b3 100644 (file)
@@ -934,7 +934,6 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
        struct sort_iter *iter;
        struct btree_node *sorted;
        struct bkey_packed *k;
-       struct bch_extent_ptr *ptr;
        struct bset *i;
        bool used_mempool, blacklisted;
        bool updated_range = b->key.k.type == KEY_TYPE_btree_ptr_v2 &&
@@ -1894,7 +1893,6 @@ static int validate_bset_for_write(struct bch_fs *c, struct btree *b,
 static void btree_write_submit(struct work_struct *work)
 {
        struct btree_write_bio *wbio = container_of(work, struct btree_write_bio, work);
-       struct bch_extent_ptr *ptr;
        BKEY_PADDED_ONSTACK(k, BKEY_BTREE_PTR_VAL_U64s_MAX) tmp;
 
        bkey_copy(&tmp.k, &wbio->key);
index 2ec9ff06f1a69e99f8b9c1f64579645f9f437c7b..3472882bf9db794f3fc2f8566f02c71f7ecf8297 100644 (file)
@@ -12,6 +12,7 @@
 #include "errcode.h"
 #include "error.h"
 #include "journal.h"
+#include "journal_io.h"
 #include "journal_reclaim.h"
 #include "replicas.h"
 #include "snapshot.h"
@@ -798,6 +799,27 @@ static noinline int bch2_trans_commit_bkey_invalid(struct btree_trans *trans,
        return -EINVAL;
 }
 
+static noinline int bch2_trans_commit_journal_entry_invalid(struct btree_trans *trans,
+                                                  struct jset_entry *i)
+{
+       struct bch_fs *c = trans->c;
+       struct printbuf buf = PRINTBUF;
+
+       prt_printf(&buf, "invalid bkey on insert from %s", trans->fn);
+       prt_newline(&buf);
+       printbuf_indent_add(&buf, 2);
+
+       bch2_journal_entry_to_text(&buf, c, i);
+       prt_newline(&buf);
+
+       bch2_print_string_as_lines(KERN_ERR, buf.buf);
+
+       bch2_inconsistent_error(c);
+       bch2_dump_trans_updates(trans);
+
+       return -EINVAL;
+}
+
 static int bch2_trans_commit_journal_pin_flush(struct journal *j,
                                struct journal_entry_pin *_pin, u64 seq)
 {
@@ -998,6 +1020,26 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
                        return ret;
        }
 
+       for (struct jset_entry *i = trans->journal_entries;
+            i != (void *) ((u64 *) trans->journal_entries + trans->journal_entries_u64s);
+            i = vstruct_next(i)) {
+               if (!jset_entry_is_key(i))
+                       continue;
+
+               enum bkey_invalid_flags invalid_flags = 0;
+
+               if (!(flags & BCH_TRANS_COMMIT_no_journal_res))
+                       invalid_flags |= BKEY_INVALID_WRITE|BKEY_INVALID_COMMIT;
+
+               if (unlikely(bch2_journal_entry_validate(c, NULL, i,
+                                       bcachefs_metadata_version_current,
+                                       CPU_BIG_ENDIAN, invalid_flags)))
+                       ret = bch2_trans_commit_journal_entry_invalid(trans, i);
+
+               if (ret)
+                       return ret;
+       }
+
        if (unlikely(!test_bit(BCH_FS_may_go_rw, &c->flags))) {
                ret = do_bch2_trans_commit_to_journal_replay(trans);
                goto out_reset;
index 695a5c6f0ba04390cb6c49012ae4aa92b0322b67..83aa0fb8ba939412bc7c645eeeb15cb3cdae2962 100644 (file)
@@ -186,8 +186,11 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
        enum btree_id btree_id = iter->btree_id;
        struct bkey_i *update;
        struct bpos new_start = bkey_start_pos(new.k);
-       bool front_split = bkey_lt(bkey_start_pos(old.k), new_start);
-       bool back_split  = bkey_gt(old.k->p, new.k->p);
+       unsigned front_split = bkey_lt(bkey_start_pos(old.k), new_start);
+       unsigned back_split  = bkey_gt(old.k->p, new.k->p);
+       unsigned middle_split = (front_split || back_split) &&
+               old.k->p.snapshot != new.k->p.snapshot;
+       unsigned nr_splits = front_split + back_split + middle_split;
        int ret = 0, compressed_sectors;
 
        /*
@@ -195,10 +198,9 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
         * so that __bch2_trans_commit() can increase our disk
         * reservation:
         */
-       if (((front_split && back_split) ||
-            ((front_split || back_split) && old.k->p.snapshot != new.k->p.snapshot)) &&
+       if (nr_splits > 1 &&
            (compressed_sectors = bch2_bkey_sectors_compressed(old)))
-               trans->extra_disk_res += compressed_sectors;
+               trans->extra_disk_res += compressed_sectors * (nr_splits - 1);
 
        if (front_split) {
                update = bch2_bkey_make_mut_noupdate(trans, old);
@@ -216,8 +218,7 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
        }
 
        /* If we're overwriting in a different snapshot - middle split: */
-       if (old.k->p.snapshot != new.k->p.snapshot &&
-           (front_split || back_split)) {
+       if (middle_split) {
                update = bch2_bkey_make_mut_noupdate(trans, old);
                if ((ret = PTR_ERR_OR_ZERO(update)))
                        return ret;
index 99e9902fc1e08496af33913dd70625559ce142c3..2a93eb92d1129680724681ef62c12bd207c56ae9 100644 (file)
@@ -556,8 +556,6 @@ static void btree_update_add_key(struct btree_update *as,
 static int btree_update_nodes_written_trans(struct btree_trans *trans,
                                            struct btree_update *as)
 {
-       struct bkey_i *k;
-
        struct jset_entry *e = bch2_trans_jset_entry_alloc(trans, as->journal_u64s);
        int ret = PTR_ERR_OR_ZERO(e);
        if (ret)
index e3aba5b61d19b3ec468f66fe6429545a08631110..e49be3ad858a9efd8c5683a23b65a328a6ea6bc3 100644 (file)
@@ -17,6 +17,7 @@ struct {                                                              \
 }
 
 typedef DARRAY(void) darray_void;
+typedef DARRAY(char *) darray_str;
 
 int __bch2_darray_resize(darray_void *, size_t, size_t, gfp_t);
 
index 5665d6318194b27f24329ac9c291bdeb58851281..cafd8915c3c3df2ee0048badf63390006beadca8 100644 (file)
@@ -356,7 +356,6 @@ void bch2_data_update_exit(struct data_update *update)
        struct bch_fs *c = update->op.c;
        struct bkey_ptrs_c ptrs =
                bch2_bkey_ptrs_c(bkey_i_to_s_c(update->k.k));
-       const struct bch_extent_ptr *ptr;
 
        bkey_for_each_ptr(ptrs, ptr) {
                if (c->opts.nocow_enabled)
@@ -377,7 +376,6 @@ static void bch2_update_unwritten_extent(struct btree_trans *trans,
        struct bio *bio = &update->op.wbio.bio;
        struct bkey_i_extent *e;
        struct write_point *wp;
-       struct bch_extent_ptr *ptr;
        struct closure cl;
        struct btree_iter iter;
        struct bkey_s_c k;
@@ -509,7 +507,6 @@ int bch2_data_update_init(struct btree_trans *trans,
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
        const union bch_extent_entry *entry;
        struct extent_ptr_decoded p;
-       const struct bch_extent_ptr *ptr;
        unsigned i, reserve_sectors = k.k->size * data_opts.extra_replicas;
        unsigned ptrs_locked = 0;
        int ret = 0;
@@ -654,7 +651,6 @@ done:
 void bch2_data_update_opts_normalize(struct bkey_s_c k, struct data_update_opts *opts)
 {
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
        unsigned i = 0;
 
        bkey_for_each_ptr(ptrs, ptr) {
index 0e5c455557a93edf6f0b4c988f4842f9bb067c10..e89185a28e0899e2b0ff8a973ae3326209e2f6ce 100644 (file)
@@ -161,7 +161,6 @@ static const struct bch_extent_ptr *bkey_matches_stripe(struct bch_stripe *s,
                                                struct bkey_s_c k, unsigned *block)
 {
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
        unsigned i, nr_data = s->nr_blocks - s->nr_redundant;
 
        bkey_for_each_ptr(ptrs, ptr)
index 9d8afcb5979a12456c032a00faf5514962b9aa05..82ec056f4cdbb1f4e4234fce274939b61b7a5015 100644 (file)
@@ -843,7 +843,6 @@ void bch2_bkey_drop_device_noerror(struct bkey_s k, unsigned dev)
 const struct bch_extent_ptr *bch2_bkey_has_device_c(struct bkey_s_c k, unsigned dev)
 {
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
 
        bkey_for_each_ptr(ptrs, ptr)
                if (ptr->dev == dev)
@@ -855,7 +854,6 @@ const struct bch_extent_ptr *bch2_bkey_has_device_c(struct bkey_s_c k, unsigned
 bool bch2_bkey_has_target(struct bch_fs *c, struct bkey_s_c k, unsigned target)
 {
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
 
        bkey_for_each_ptr(ptrs, ptr)
                if (bch2_dev_in_target(c, ptr->dev, target) &&
@@ -1065,7 +1063,6 @@ static int extent_ptr_invalid(struct bch_fs *c,
                              struct printbuf *err)
 {
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr2;
        u64 bucket;
        u32 bucket_offset;
        struct bch_dev *ca;
@@ -1307,7 +1304,6 @@ unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c, struct bkey_s_c k,
        }
 incompressible:
        if (target && bch2_target_accepts_data(c, BCH_DATA_user, target)) {
-               const struct bch_extent_ptr *ptr;
                unsigned i = 0;
 
                bkey_for_each_ptr(ptrs, ptr) {
index a2ce8a3be13ca418a001d8ff93d9091565aed800..5f31cbe754c9575a26921a968a23b231e64e0b6a 100644 (file)
@@ -300,7 +300,7 @@ static inline struct bkey_ptrs bch2_bkey_ptrs(struct bkey_s k)
        bkey_extent_entry_for_each_from(_p, _entry, _p.start)
 
 #define __bkey_for_each_ptr(_start, _end, _ptr)                                \
-       for ((_ptr) = (_start);                                         \
+       for (typeof(_start) (_ptr) = (_start);                          \
             ((_ptr) = __bkey_ptr_next(_ptr, _end));                    \
             (_ptr)++)
 
@@ -547,7 +547,6 @@ static inline bool bkey_extent_is_allocation(const struct bkey *k)
 static inline bool bkey_extent_is_unwritten(struct bkey_s_c k)
 {
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
 
        bkey_for_each_ptr(ptrs, ptr)
                if (ptr->unwritten)
@@ -565,7 +564,6 @@ static inline struct bch_devs_list bch2_bkey_devs(struct bkey_s_c k)
 {
        struct bch_devs_list ret = (struct bch_devs_list) { 0 };
        struct bkey_ptrs_c p = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
 
        bkey_for_each_ptr(p, ptr)
                ret.devs[ret.nr++] = ptr->dev;
@@ -577,7 +575,6 @@ static inline struct bch_devs_list bch2_bkey_dirty_devs(struct bkey_s_c k)
 {
        struct bch_devs_list ret = (struct bch_devs_list) { 0 };
        struct bkey_ptrs_c p = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
 
        bkey_for_each_ptr(p, ptr)
                if (!ptr->cached)
@@ -590,7 +587,6 @@ static inline struct bch_devs_list bch2_bkey_cached_devs(struct bkey_s_c k)
 {
        struct bch_devs_list ret = (struct bch_devs_list) { 0 };
        struct bkey_ptrs_c p = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
 
        bkey_for_each_ptr(p, ptr)
                if (ptr->cached)
index bc280a0a957d7dc74ed9800a0ebd30745241b936..01960b36cd4d894bfe6850febdf1bd9f7db38c49 100644 (file)
@@ -1596,31 +1596,6 @@ static struct bch_fs *bch2_path_to_fs(const char *path)
        return c ?: ERR_PTR(-ENOENT);
 }
 
-static char **split_devs(const char *_dev_name, unsigned *nr)
-{
-       char *dev_name = NULL, **devs = NULL, *s;
-       size_t i = 0, nr_devs = 0;
-
-       dev_name = kstrdup(_dev_name, GFP_KERNEL);
-       if (!dev_name)
-               return NULL;
-
-       for (s = dev_name; s; s = strchr(s + 1, ':'))
-               nr_devs++;
-
-       devs = kcalloc(nr_devs + 1, sizeof(const char *), GFP_KERNEL);
-       if (!devs) {
-               kfree(dev_name);
-               return NULL;
-       }
-
-       while ((s = strsep(&dev_name, ":")))
-               devs[i++] = s;
-
-       *nr = nr_devs;
-       return devs;
-}
-
 static int bch2_remount(struct super_block *sb, int *flags, char *data)
 {
        struct bch_fs *c = sb->s_fs_info;
@@ -1773,17 +1748,18 @@ static int bch2_noset_super(struct super_block *s, void *data)
        return -EBUSY;
 }
 
+typedef DARRAY(struct bch_fs *) darray_fs;
+
 static int bch2_test_super(struct super_block *s, void *data)
 {
        struct bch_fs *c = s->s_fs_info;
-       struct bch_fs **devs = data;
-       unsigned i;
+       darray_fs *d = data;
 
        if (!c)
                return false;
 
-       for (i = 0; devs[i]; i++)
-               if (c != devs[i])
+       darray_for_each(*d, i)
+               if (c != *i)
                        return false;
        return true;
 }
@@ -1795,9 +1771,6 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
        struct super_block *sb;
        struct inode *vinode;
        struct bch_opts opts = bch2_opts_empty();
-       char **devs;
-       struct bch_fs **devs_to_fs = NULL;
-       unsigned nr_devs;
        int ret;
 
        opt_set(opts, read_only, (flags & SB_RDONLY) != 0);
@@ -1809,25 +1782,25 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
        if (!dev_name || strlen(dev_name) == 0)
                return ERR_PTR(-EINVAL);
 
-       devs = split_devs(dev_name, &nr_devs);
-       if (!devs)
-               return ERR_PTR(-ENOMEM);
+       darray_str devs;
+       ret = bch2_split_devs(dev_name, &devs);
+       if (ret)
+               return ERR_PTR(ret);
 
-       devs_to_fs = kcalloc(nr_devs + 1, sizeof(void *), GFP_KERNEL);
-       if (!devs_to_fs) {
-               sb = ERR_PTR(-ENOMEM);
-               goto got_sb;
+       darray_fs devs_to_fs = {};
+       darray_for_each(devs, i) {
+               ret = darray_push(&devs_to_fs, bch2_path_to_fs(*i));
+               if (ret) {
+                       sb = ERR_PTR(ret);
+                       goto got_sb;
+               }
        }
 
-       for (unsigned i = 0; i < nr_devs; i++)
-               devs_to_fs[i] = bch2_path_to_fs(devs[i]);
-
-       sb = sget(fs_type, bch2_test_super, bch2_noset_super,
-                 flags|SB_NOSEC, devs_to_fs);
+       sb = sget(fs_type, bch2_test_super, bch2_noset_super, flags|SB_NOSEC, &devs_to_fs);
        if (!IS_ERR(sb))
                goto got_sb;
 
-       c = bch2_fs_open(devs, nr_devs, opts);
+       c = bch2_fs_open(devs.data, devs.nr, opts);
        if (IS_ERR(c)) {
                sb = ERR_CAST(c);
                goto got_sb;
@@ -1847,9 +1820,8 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
        if (IS_ERR(sb))
                bch2_fs_stop(c);
 got_sb:
-       kfree(devs_to_fs);
-       kfree(devs[0]);
-       kfree(devs);
+       darray_exit(&devs_to_fs);
+       bch2_darray_str_exit(&devs);
 
        if (IS_ERR(sb)) {
                ret = PTR_ERR(sb);
index 8f2da02fe078cb5a3b5e6929a68adb61ad207f84..197ff7a4c5415636fd9328043c3a3ddb68563f0b 100644 (file)
@@ -74,7 +74,6 @@ int bch2_extent_fallocate(struct btree_trans *trans,
                struct bkey_i_extent *e;
                struct bch_devs_list devs_have;
                struct write_point *wp;
-               struct bch_extent_ptr *ptr;
 
                devs_have.nr = 0;
 
index abad1d9d20665c267208498a16475c46c6a4c5f5..c5961bac19f0087772b2dbc01b386ea173c6b09f 100644 (file)
@@ -396,16 +396,14 @@ void bch2_submit_wbio_replicas(struct bch_write_bio *wbio, struct bch_fs *c,
                               bool nocow)
 {
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(k));
-       const struct bch_extent_ptr *ptr;
        struct bch_write_bio *n;
-       struct bch_dev *ca;
 
        BUG_ON(c->opts.nochanges);
 
        bkey_for_each_ptr(ptrs, ptr) {
                BUG_ON(!bch2_dev_exists2(c, ptr->dev));
 
-               ca = bch_dev_bkey_exists(c, ptr->dev);
+               struct bch_dev *ca = bch_dev_bkey_exists(c, ptr->dev);
 
                if (to_entry(ptr + 1) < ptrs.end) {
                        n = to_wbio(bio_alloc_clone(NULL, &wbio->bio,
@@ -1108,16 +1106,14 @@ static bool bch2_extent_is_writeable(struct bch_write_op *op,
 static inline void bch2_nocow_write_unlock(struct bch_write_op *op)
 {
        struct bch_fs *c = op->c;
-       const struct bch_extent_ptr *ptr;
-       struct bkey_i *k;
 
        for_each_keylist_key(&op->insert_keys, k) {
                struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(k));
 
                bkey_for_each_ptr(ptrs, ptr)
                        bch2_bucket_nocow_unlock(&c->nocow_locks,
-                                              PTR_BUCKET_POS(c, ptr),
-                                              BUCKET_NOCOW_LOCK_UPDATE);
+                                                PTR_BUCKET_POS(c, ptr),
+                                                BUCKET_NOCOW_LOCK_UPDATE);
        }
 }
 
@@ -1127,25 +1123,20 @@ static int bch2_nocow_write_convert_one_unwritten(struct btree_trans *trans,
                                                  struct bkey_s_c k,
                                                  u64 new_i_size)
 {
-       struct bkey_i *new;
-       struct bkey_ptrs ptrs;
-       struct bch_extent_ptr *ptr;
-       int ret;
-
        if (!bch2_extents_match(bkey_i_to_s_c(orig), k)) {
                /* trace this */
                return 0;
        }
 
-       new = bch2_bkey_make_mut_noupdate(trans, k);
-       ret = PTR_ERR_OR_ZERO(new);
+       struct bkey_i *new = bch2_bkey_make_mut_noupdate(trans, k);
+       int ret = PTR_ERR_OR_ZERO(new);
        if (ret)
                return ret;
 
        bch2_cut_front(bkey_start_pos(&orig->k), new);
        bch2_cut_back(orig->k.p, new);
 
-       ptrs = bch2_bkey_ptrs(bkey_i_to_s(new));
+       struct bkey_ptrs ptrs = bch2_bkey_ptrs(bkey_i_to_s(new));
        bkey_for_each_ptr(ptrs, ptr)
                ptr->unwritten = 0;
 
@@ -1166,11 +1157,9 @@ static void bch2_nocow_write_convert_unwritten(struct bch_write_op *op)
 {
        struct bch_fs *c = op->c;
        struct btree_trans *trans = bch2_trans_get(c);
-       struct bkey_i *orig;
-       int ret;
 
        for_each_keylist_key(&op->insert_keys, orig) {
-               ret = for_each_btree_key_upto_commit(trans, iter, BTREE_ID_extents,
+               int ret = for_each_btree_key_upto_commit(trans, iter, BTREE_ID_extents,
                                     bkey_start_pos(&orig->k), orig->k.p,
                                     BTREE_ITER_INTENT, k,
                                     NULL, NULL, BCH_TRANS_COMMIT_no_enospc, ({
@@ -1219,8 +1208,6 @@ static void bch2_nocow_write(struct bch_write_op *op)
        struct btree_trans *trans;
        struct btree_iter iter;
        struct bkey_s_c k;
-       struct bkey_ptrs_c ptrs;
-       const struct bch_extent_ptr *ptr;
        struct {
                struct bpos     b;
                unsigned        gen;
@@ -1266,7 +1253,7 @@ retry:
                        break;
 
                /* Get iorefs before dropping btree locks: */
-               ptrs = bch2_bkey_ptrs_c(k);
+               struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
                bkey_for_each_ptr(ptrs, ptr) {
                        buckets[nr_buckets].b = PTR_BUCKET_POS(c, ptr);
                        buckets[nr_buckets].gen = ptr->gen;
index 65e58edb975a0259de3c6918dde1c9501c2c2da4..c5bc58247146a2cdbc1eecb987db7ba667e9677f 100644 (file)
@@ -409,8 +409,10 @@ static int journal_entry_btree_root_validate(struct bch_fs *c,
                return 0;
        }
 
-       return journal_validate_key(c, jset, entry, 1, entry->btree_id, k,
-                                   version, big_endian, flags);
+       ret = journal_validate_key(c, jset, entry, 1, entry->btree_id, k,
+                                  version, big_endian, flags);
+       if (ret == FSCK_DELETED_KEY)
+               ret = 0;
 fsck_err:
        return ret;
 }
@@ -1676,7 +1678,6 @@ static CLOSURE_CALLBACK(do_journal_write)
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
        struct bch_dev *ca;
        struct journal_buf *w = journal_last_unwritten_buf(j);
-       struct bch_extent_ptr *ptr;
        struct bio *bio;
        unsigned sectors = vstruct_sectors(w->data, c->block_bits);
 
index 5699cd4873c81d3c393aa59f339c328b051f90b8..1b828bddd11bf1d0184c9af3cca50b68ad293212 100644 (file)
@@ -43,8 +43,6 @@ void bch2_keylist_pop_front(struct keylist *l)
 #ifdef CONFIG_BCACHEFS_DEBUG
 void bch2_verify_keylist_sorted(struct keylist *l)
 {
-       struct bkey_i *k;
-
        for_each_keylist_key(l, k)
                BUG_ON(bkey_next(k) != l->top &&
                       bpos_ge(k->k.p, bkey_next(k)->k.p));
index fe759c7031e0403a0fe0da6d61b2c8432f819451..e687e0e9aede1cb2f7bb7252d16d58ec2774ebd1 100644 (file)
@@ -50,18 +50,16 @@ static inline struct bkey_i *bch2_keylist_front(struct keylist *l)
 }
 
 #define for_each_keylist_key(_keylist, _k)                     \
-       for (_k = (_keylist)->keys;                             \
+       for (struct bkey_i *_k = (_keylist)->keys;              \
             _k != (_keylist)->top;                             \
             _k = bkey_next(_k))
 
 static inline u64 keylist_sectors(struct keylist *keys)
 {
-       struct bkey_i *k;
        u64 ret = 0;
 
        for_each_keylist_key(keys, k)
                ret += k->k.size;
-
        return ret;
 }
 
index 6cb38484fa7770818a4e0ddbe113601925132634..7a33319dcd168001594f6532bafe0caf92f83c22 100644 (file)
@@ -695,9 +695,6 @@ int bch2_evacuate_bucket(struct moving_context *ctxt,
                        break;
 
                if (!bp.level) {
-                       const struct bch_extent_ptr *ptr;
-                       unsigned i = 0;
-
                        k = bch2_backpointer_get_key(trans, &iter, bp_pos, bp, 0);
                        ret = bkey_err(k);
                        if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
@@ -720,6 +717,7 @@ int bch2_evacuate_bucket(struct moving_context *ctxt,
                        data_opts.target        = io_opts.background_target;
                        data_opts.rewrite_ptrs = 0;
 
+                       unsigned i = 0;
                        bkey_for_each_ptr(bch2_bkey_ptrs_c(k), ptr) {
                                if (ptr->dev == bucket.inode) {
                                        data_opts.rewrite_ptrs |= 1U << i;
@@ -890,7 +888,6 @@ static bool migrate_pred(struct bch_fs *c, void *arg,
                         struct data_update_opts *data_opts)
 {
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
        struct bch_ioctl_data *op = arg;
        unsigned i = 0;
 
index 00ddd91ddfcc8eecc920114bdd3290d3ffa913e0..d4a2389111599b25460d7276617ffb72cbdf75c4 100644 (file)
@@ -1174,3 +1174,37 @@ u64 *bch2_acc_percpu_u64s(u64 __percpu *p, unsigned nr)
 
        return ret;
 }
+
+void bch2_darray_str_exit(darray_str *d)
+{
+       darray_for_each(*d, i)
+               kfree(*i);
+       darray_exit(d);
+}
+
+int bch2_split_devs(const char *_dev_name, darray_str *ret)
+{
+       darray_init(ret);
+
+       char *dev_name = kstrdup(_dev_name, GFP_KERNEL), *s = dev_name;
+       if (!dev_name)
+               return -ENOMEM;
+
+       while ((s = strsep(&dev_name, ":"))) {
+               char *p = kstrdup(s, GFP_KERNEL);
+               if (!p)
+                       goto err;
+
+               if (darray_push(ret, p)) {
+                       kfree(p);
+                       goto err;
+               }
+       }
+
+       kfree(dev_name);
+       return 0;
+err:
+       bch2_darray_str_exit(ret);
+       kfree(dev_name);
+       return -ENOMEM;
+}
index a4db93a2a8ec8f93ae5114d5e5a7a6c85870a385..4525fb51e34f981a969d5e38ef97db08ac668f81 100644 (file)
@@ -862,4 +862,7 @@ 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 *);
+
 #endif /* _BCACHEFS_UTIL_H */