]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/alloc_foreground.c
Move c_src dirs back to toplevel
[bcachefs-tools-debian] / libbcachefs / alloc_foreground.c
index 317391fe972d36db1c34b7da702e4a224a76d745..b0ff47998a9440912f940dc09e27b34e6341cb9e 100644 (file)
@@ -958,8 +958,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 +1360,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 +1384,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,