bcachefs: bkey_for_each_ptr() now declares loop iter
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 21 Dec 2023 20:47:15 +0000 (15:47 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 1 Jan 2024 16:47:43 +0000 (11:47 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_gc.c
fs/bcachefs/btree_io.c
fs/bcachefs/data_update.c
fs/bcachefs/ec.c
fs/bcachefs/extents.c
fs/bcachefs/extents.h
fs/bcachefs/io_misc.c
fs/bcachefs/io_write.c
fs/bcachefs/journal_io.c
fs/bcachefs/move.c

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 d7cac6a805072279fe2d925a1190e3037a57fcac..38d27cae49ea5421a00b976c4e0bfbe1f8991d72 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 &&
@@ -1896,7 +1895,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 1e6d162753fb834602c8e203b39f2bc7d53c6654..6f13477ff652e9e0552b9fbbb49009a5651d6d76 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;
@@ -655,7 +652,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 4295e93984c42b9f0158991b99f7c8410451ea7d..77ae4476578b1a7721cceee22be4ded1b1db90a1 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.data[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 92e7f765f9cf6ff062e8f7dcf39adf5bc145ed80..ca6d5f516aa2be80824e7479e73d1cbfc2607117 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 0af39b5626660e0ffc57e56ced52b896b58c207a..628b3e966c1d3d569b67b628ac721a5497d90754 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,7 +1106,6 @@ 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) {
@@ -1127,25 +1124,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;
 
@@ -1225,8 +1217,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;
        DARRAY_PREALLOCATED(struct bucket_to_lock, 3) buckets;
        u32 snapshot;
        struct bucket_to_lock *stale_at;
@@ -1269,7 +1259,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) {
                        struct bpos b = PTR_BUCKET_POS(c, ptr);
                        struct nocow_lock_bucket *l =
index 671a6820bc0cd3dfc7a9f9246da1018cf298ad6b..c5bc58247146a2cdbc1eecb987db7ba667e9677f 100644 (file)
@@ -1678,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 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;