]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/alloc_foreground.c
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / libbcachefs / alloc_foreground.c
index 317391fe972d36db1c34b7da702e4a224a76d745..ca58193dd90279b6d6081f06954690f214ba3a42 100644 (file)
@@ -236,8 +236,7 @@ static struct open_bucket *__try_alloc_bucket(struct bch_fs *c, struct bch_dev *
                if (cl)
                        closure_wait(&c->open_buckets_wait, cl);
 
-               track_event_change(&c->times[BCH_TIME_blocked_allocate_open_bucket],
-                                  &c->blocked_allocate_open_bucket, true);
+               track_event_change(&c->times[BCH_TIME_blocked_allocate_open_bucket], true);
                spin_unlock(&c->freelist_lock);
                return ERR_PTR(-BCH_ERR_open_buckets_empty);
        }
@@ -263,11 +262,8 @@ static struct open_bucket *__try_alloc_bucket(struct bch_fs *c, struct bch_dev *
        ca->nr_open_buckets++;
        bch2_open_bucket_hash_add(c, ob);
 
-       track_event_change(&c->times[BCH_TIME_blocked_allocate_open_bucket],
-                          &c->blocked_allocate_open_bucket, false);
-
-       track_event_change(&c->times[BCH_TIME_blocked_allocate],
-                          &c->blocked_allocate, false);
+       track_event_change(&c->times[BCH_TIME_blocked_allocate_open_bucket], false);
+       track_event_change(&c->times[BCH_TIME_blocked_allocate], false);
 
        spin_unlock(&c->freelist_lock);
        return ob;
@@ -555,8 +551,7 @@ again:
                        goto again;
                }
 
-               track_event_change(&c->times[BCH_TIME_blocked_allocate],
-                                  &c->blocked_allocate, true);
+               track_event_change(&c->times[BCH_TIME_blocked_allocate], true);
 
                ob = ERR_PTR(-BCH_ERR_freelist_empty);
                goto err;
@@ -958,8 +953,8 @@ static int __open_bucket_add_buckets(struct btree_trans *trans,
        devs = target_rw_devs(c, wp->data_type, target);
 
        /* Don't allocate from devices we already have pointers to: */
-       for (i = 0; i < devs_have->nr; i++)
-               __clear_bit(devs_have->devs[i], devs.d);
+       darray_for_each(*devs_have, i)
+               __clear_bit(*i, devs.d);
 
        open_bucket_for_each(c, ptrs, ob, i)
                __clear_bit(ob->dev, devs.d);
@@ -1360,8 +1355,17 @@ retry:
                        goto alloc_done;
 
                /* Don't retry from all devices if we're out of open buckets: */
-               if (bch2_err_matches(ret, BCH_ERR_open_buckets_empty))
-                       goto allocate_blocking;
+               if (bch2_err_matches(ret, BCH_ERR_open_buckets_empty)) {
+                       int ret = open_bucket_add_buckets(trans, &ptrs, wp, devs_have,
+                                             target, erasure_code,
+                                             nr_replicas, &nr_effective,
+                                             &have_cache, watermark,
+                                             flags, cl);
+                       if (!ret ||
+                           bch2_err_matches(ret, BCH_ERR_transaction_restart) ||
+                           bch2_err_matches(ret, BCH_ERR_open_buckets_empty))
+                               goto alloc_done;
+               }
 
                /*
                 * Only try to allocate cache (durability = 0 devices) from the
@@ -1375,7 +1379,6 @@ retry:
                                              &have_cache, watermark,
                                              flags, cl);
        } else {
-allocate_blocking:
                ret = open_bucket_add_buckets(trans, &ptrs, wp, devs_have,
                                              target, erasure_code,
                                              nr_replicas, &nr_effective,
@@ -1517,10 +1520,11 @@ static void bch2_open_bucket_to_text(struct printbuf *out, struct bch_fs *c, str
        unsigned data_type = ob->data_type;
        barrier(); /* READ_ONCE() doesn't work on bitfields */
 
-       prt_printf(out, "%zu ref %u %s %u:%llu gen %u allocated %u/%u",
+       prt_printf(out, "%zu ref %u ",
                   ob - c->open_buckets,
-                  atomic_read(&ob->pin),
-                  data_type < BCH_DATA_NR ? bch2_data_types[data_type] : "invalid data type",
+                  atomic_read(&ob->pin));
+       bch2_prt_data_type(out, data_type);
+       prt_printf(out, " %u:%llu gen %u allocated %u/%u",
                   ob->dev, ob->bucket, ob->gen,
                   ca->mi.bucket_size - ob->sectors_free, ca->mi.bucket_size);
        if (ob->ec)