Skip to content

Commit d8d8195

Browse files
Brian FosterKent Overstreet
authored andcommitted
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: Brian Foster <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent a7dc10c commit d8d8195

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

fs/bcachefs/io_misc.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ int bch2_extent_fallocate(struct btree_trans *trans,
3434
struct open_buckets open_buckets = { 0 };
3535
struct bkey_s_c k;
3636
struct bkey_buf old, new;
37-
unsigned sectors_allocated = 0;
38-
bool have_reservation = false;
37+
unsigned sectors_allocated = 0, new_replicas;
3938
bool unwritten = opts.nocow &&
4039
c->sb.version >= bcachefs_metadata_version_unwritten_extents;
4140
int ret;
@@ -50,28 +49,20 @@ int bch2_extent_fallocate(struct btree_trans *trans,
5049
return ret;
5150

5251
sectors = min_t(u64, sectors, k.k->p.offset - iter->pos.offset);
52+
new_replicas = max(0, (int) opts.data_replicas -
53+
(int) bch2_bkey_nr_ptrs_fully_allocated(k));
5354

54-
if (!have_reservation) {
55-
unsigned new_replicas =
56-
max(0, (int) opts.data_replicas -
57-
(int) bch2_bkey_nr_ptrs_fully_allocated(k));
58-
/*
59-
* Get a disk reservation before (in the nocow case) calling
60-
* into the allocator:
61-
*/
62-
ret = bch2_disk_reservation_get(c, &disk_res, sectors, new_replicas, 0);
63-
if (unlikely(ret))
64-
goto err_noprint;
65-
66-
bch2_bkey_buf_reassemble(&old, c, k);
67-
}
55+
/*
56+
* Get a disk reservation before (in the nocow case) calling
57+
* into the allocator:
58+
*/
59+
ret = bch2_disk_reservation_get(c, &disk_res, sectors, new_replicas, 0);
60+
if (unlikely(ret))
61+
goto err_noprint;
6862

69-
if (have_reservation) {
70-
if (!bch2_extents_match(k, bkey_i_to_s_c(old.k)))
71-
goto err;
63+
bch2_bkey_buf_reassemble(&old, c, k);
7264

73-
bch2_key_resize(&new.k->k, sectors);
74-
} else if (!unwritten) {
65+
if (!unwritten) {
7566
struct bkey_i_reservation *reservation;
7667

7768
bch2_bkey_buf_realloc(&new, c, sizeof(*reservation) / sizeof(u64));
@@ -118,8 +109,6 @@ int bch2_extent_fallocate(struct btree_trans *trans,
118109
ptr->unwritten = true;
119110
}
120111

121-
have_reservation = true;
122-
123112
ret = bch2_extent_update(trans, inum, iter, new.k, &disk_res,
124113
0, i_sectors_delta, true);
125114
err:

0 commit comments

Comments
 (0)