Commit d8d81958 authored by Brian Foster's avatar Brian Foster Committed by Kent Overstreet

bcachefs: clean up some dead fallocate code

The have_reservation local variable in bch2_extent_fallocate() is
initialized to false and set to true further down in the function.
Between this two points, one branch of code checks for negative
value and one for positive, and nothing ever checks the variable
after it is set to true. Clean up some of the unnecessary logic and
code.
Signed-off-by: default avatarBrian Foster <bfoster@redhat.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent a7dc10ce
...@@ -34,8 +34,7 @@ int bch2_extent_fallocate(struct btree_trans *trans, ...@@ -34,8 +34,7 @@ int bch2_extent_fallocate(struct btree_trans *trans,
struct open_buckets open_buckets = { 0 }; struct open_buckets open_buckets = { 0 };
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_buf old, new; struct bkey_buf old, new;
unsigned sectors_allocated = 0; unsigned sectors_allocated = 0, new_replicas;
bool have_reservation = false;
bool unwritten = opts.nocow && bool unwritten = opts.nocow &&
c->sb.version >= bcachefs_metadata_version_unwritten_extents; c->sb.version >= bcachefs_metadata_version_unwritten_extents;
int ret; int ret;
...@@ -50,28 +49,20 @@ int bch2_extent_fallocate(struct btree_trans *trans, ...@@ -50,28 +49,20 @@ int bch2_extent_fallocate(struct btree_trans *trans,
return ret; return ret;
sectors = min_t(u64, sectors, k.k->p.offset - iter->pos.offset); sectors = min_t(u64, sectors, k.k->p.offset - iter->pos.offset);
new_replicas = max(0, (int) opts.data_replicas -
(int) bch2_bkey_nr_ptrs_fully_allocated(k));
if (!have_reservation) { /*
unsigned new_replicas = * Get a disk reservation before (in the nocow case) calling
max(0, (int) opts.data_replicas - * into the allocator:
(int) bch2_bkey_nr_ptrs_fully_allocated(k)); */
/* ret = bch2_disk_reservation_get(c, &disk_res, sectors, new_replicas, 0);
* Get a disk reservation before (in the nocow case) calling if (unlikely(ret))
* into the allocator: goto err_noprint;
*/
ret = bch2_disk_reservation_get(c, &disk_res, sectors, new_replicas, 0);
if (unlikely(ret))
goto err_noprint;
bch2_bkey_buf_reassemble(&old, c, k);
}
if (have_reservation) { bch2_bkey_buf_reassemble(&old, c, k);
if (!bch2_extents_match(k, bkey_i_to_s_c(old.k)))
goto err;
bch2_key_resize(&new.k->k, sectors); if (!unwritten) {
} else if (!unwritten) {
struct bkey_i_reservation *reservation; struct bkey_i_reservation *reservation;
bch2_bkey_buf_realloc(&new, c, sizeof(*reservation) / sizeof(u64)); bch2_bkey_buf_realloc(&new, c, sizeof(*reservation) / sizeof(u64));
...@@ -118,8 +109,6 @@ int bch2_extent_fallocate(struct btree_trans *trans, ...@@ -118,8 +109,6 @@ int bch2_extent_fallocate(struct btree_trans *trans,
ptr->unwritten = true; ptr->unwritten = true;
} }
have_reservation = true;
ret = bch2_extent_update(trans, inum, iter, new.k, &disk_res, ret = bch2_extent_update(trans, inum, iter, new.k, &disk_res,
0, i_sectors_delta, true); 0, i_sectors_delta, true);
err: err:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment