bcachefs: bch2_ec_stripe_head_get() takes alloc_request
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 31 Mar 2025 19:37:28 +0000 (15:37 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:13:32 +0000 (20:13 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_foreground.c
fs/bcachefs/alloc_foreground.h
fs/bcachefs/ec.c
fs/bcachefs/ec.h

index ca8df935f198242b981cb401d247c3904f568f54..aef27d40d3548700de737811338bf17ccd3db75e 100644 (file)
@@ -495,9 +495,8 @@ static noinline void trace_bucket_alloc2(struct bch_fs *c, struct bch_dev *ca,
 /**
  * bch2_bucket_alloc_trans - allocate a single bucket from a specific device
  * @trans:     transaction object
+ * @req:       state for the entire allocation
  * @ca:                device to allocate from
- * @watermark: how important is this allocation?
- * @data_type: BCH_DATA_journal, btree, user...
  * @cl:                if not NULL, closure to be used to wait if buckets not available
  * @nowait:    if true, do not wait for buckets to become available
  * @usage:     for secondarily also returning the current device usage
@@ -782,7 +781,7 @@ static int bucket_alloc_from_stripe(struct btree_trans *trans,
                return 0;
 
        struct ec_stripe_head *h =
-               bch2_ec_stripe_head_get(trans, req->target, 0, req->nr_replicas - 1, req->watermark, cl);
+               bch2_ec_stripe_head_get(trans, req, 0, cl);
        if (IS_ERR(h))
                return PTR_ERR(h);
        if (!h)
index 24d6e58637374600050f4a6881a2544734eeaa0f..27219cd1368fea8f379ac1d26d336ca5d6e75bc8 100644 (file)
@@ -32,12 +32,11 @@ struct alloc_request {
        enum bch_write_flags    flags;
        enum bch_data_type      data_type;
        struct bch_devs_list    *devs_have;
-
        struct write_point      *wp;
-       struct open_buckets     ptrs;
-       unsigned                nr_effective;
-       bool                    have_cache;
 
+       struct open_buckets     ptrs;
+       unsigned                nr_effective;   /* sum of @ptrs durability */
+       bool                    have_cache;     /* have we allocated from a 0 durability dev */
        struct bch_devs_mask    devs_may_alloc;
 };
 
index 0865fb8a6f36ce0c6aa2edb63c96866eb67abd2f..6f977e134d089aa284e7214e6ff266a2c2b4dc04 100644 (file)
@@ -1977,17 +1977,15 @@ err:
 }
 
 struct ec_stripe_head *bch2_ec_stripe_head_get(struct btree_trans *trans,
-                                              unsigned target,
+                                              struct alloc_request *req,
                                               unsigned algo,
-                                              unsigned redundancy,
-                                              enum bch_watermark watermark,
                                               struct closure *cl)
 {
        struct bch_fs *c = trans->c;
-       struct ec_stripe_head *h;
-       bool waiting = false;
+       unsigned redundancy = req->nr_replicas - 1;
        unsigned disk_label = 0;
-       struct target t = target_decode(target);
+       struct target t = target_decode(req->target);
+       bool waiting = false;
        int ret;
 
        if (t.type == TARGET_GROUP) {
@@ -1998,7 +1996,9 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct btree_trans *trans,
                disk_label = t.group + 1; /* 0 == no label */
        }
 
-       h = __bch2_ec_stripe_head_get(trans, disk_label, algo, redundancy, watermark);
+       struct ec_stripe_head *h =
+               __bch2_ec_stripe_head_get(trans, disk_label, algo,
+                                         redundancy, req->watermark);
        if (IS_ERR_OR_NULL(h))
                return h;
 
@@ -2041,8 +2041,8 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct btree_trans *trans,
                if (waiting || !cl || ret != -BCH_ERR_stripe_alloc_blocked)
                        goto err;
 
-               if (watermark == BCH_WATERMARK_copygc) {
-                       ret =   new_stripe_alloc_buckets(trans, h, s, watermark, NULL) ?:
+               if (req->watermark == BCH_WATERMARK_copygc) {
+                       ret =   new_stripe_alloc_buckets(trans, h, s, req->watermark, NULL) ?:
                                __bch2_ec_stripe_head_reserve(trans, h, s);
                        if (ret)
                                goto err;
@@ -2061,7 +2061,7 @@ alloc_existing:
         * Retry allocating buckets, with the watermark for this
         * particular write:
         */
-       ret = new_stripe_alloc_buckets(trans, h, s, watermark, cl);
+       ret = new_stripe_alloc_buckets(trans, h, s, req->watermark, cl);
        if (ret)
                goto err;
 
index 51893e1ee874f0a21b5d04100e32696e34db6313..83d37bcb548a29e20e24a560da37e5e714ffd6a8 100644 (file)
@@ -255,9 +255,10 @@ void bch2_ec_bucket_cancel(struct bch_fs *, struct open_bucket *, int);
 int bch2_ec_stripe_new_alloc(struct bch_fs *, struct ec_stripe_head *);
 
 void bch2_ec_stripe_head_put(struct bch_fs *, struct ec_stripe_head *);
+
+struct alloc_request;
 struct ec_stripe_head *bch2_ec_stripe_head_get(struct btree_trans *,
-                       unsigned, unsigned, unsigned,
-                       enum bch_watermark, struct closure *);
+                       struct alloc_request *, unsigned, struct closure *);
 
 void bch2_do_stripe_deletes(struct bch_fs *);
 void bch2_ec_do_stripe_creates(struct bch_fs *);