bcachefs: bch2_trigger_alloc() -> bch2_dev_tryget()
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 30 Apr 2024 19:53:03 +0000 (15:53 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 8 May 2024 21:29:23 +0000 (17:29 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c

index e61f00efe619b77ffcd8546b7f3b1b095211ffb5..41f2e19aa8fe69e53fae667bb25ffa70adbd812d 100644 (file)
@@ -739,12 +739,10 @@ int bch2_trigger_alloc(struct btree_trans *trans,
        struct bch_fs *c = trans->c;
        int ret = 0;
 
-       if (bch2_trans_inconsistent_on(!bch2_dev_bucket_exists(c, new.k->p), trans,
-                                      "alloc key for invalid device or bucket"))
+       struct bch_dev *ca = bch2_dev_bucket_tryget(c, new.k->p);
+       if (!ca)
                return -EIO;
 
-       struct bch_dev *ca = bch2_dev_bkey_exists(c, new.k->p.inode);
-
        struct bch_alloc_v4 old_a_convert;
        const struct bch_alloc_v4 *old_a = bch2_alloc_to_v4(old, &old_a_convert);
 
@@ -773,7 +771,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
                        ret =   bch2_bucket_do_index(trans, ca, old, old_a, false) ?:
                                bch2_bucket_do_index(trans, ca, new.s_c, new_a, true);
                        if (ret)
-                               return ret;
+                               goto err;
                }
 
                if (new_a->data_type == BCH_DATA_cached &&
@@ -787,7 +785,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
                                              bucket_to_u64(new.k->p),
                                              old_lru, new_lru);
                        if (ret)
-                               return ret;
+                               goto err;
                }
 
                new_a->fragmentation_lru = alloc_lru_idx_fragmentation(*new_a, ca);
@@ -797,13 +795,13 @@ int bch2_trigger_alloc(struct btree_trans *trans,
                                        bucket_to_u64(new.k->p),
                                        old_a->fragmentation_lru, new_a->fragmentation_lru);
                        if (ret)
-                               return ret;
+                               goto err;
                }
 
                if (old_a->gen != new_a->gen) {
                        ret = bch2_bucket_gen_update(trans, new.k->p, new_a->gen);
                        if (ret)
-                               return ret;
+                               goto err;
                }
 
                /*
@@ -816,7 +814,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
                        ret = bch2_update_cached_sectors_list(trans, new.k->p.inode,
                                                              -((s64) old_a->cached_sectors));
                        if (ret)
-                               return ret;
+                               goto err;
                }
        }
 
@@ -853,7 +851,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
                        if (ret) {
                                bch2_fs_fatal_error(c,
                                        "setting bucket_needs_journal_commit: %s", bch2_err_str(ret));
-                               return ret;
+                               goto err;
                        }
                }
 
@@ -907,8 +905,9 @@ int bch2_trigger_alloc(struct btree_trans *trans,
                bucket_unlock(g);
                percpu_up_read(&c->mark_lock);
        }
-
-       return 0;
+err:
+       bch2_dev_put(ca);
+       return ret;
 }
 
 /*