Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <bfoster@redhat.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

authored by

Brian Foster and committed by
Kent Overstreet
d8d81958 a7dc10ce

+12 -23
+12 -23
fs/bcachefs/io_misc.c
··· 34 34 struct open_buckets open_buckets = { 0 }; 35 35 struct bkey_s_c k; 36 36 struct bkey_buf old, new; 37 - unsigned sectors_allocated = 0; 38 - bool have_reservation = false; 37 + unsigned sectors_allocated = 0, new_replicas; 39 38 bool unwritten = opts.nocow && 40 39 c->sb.version >= bcachefs_metadata_version_unwritten_extents; 41 40 int ret; ··· 49 50 return ret; 50 51 51 52 sectors = min_t(u64, sectors, k.k->p.offset - iter->pos.offset); 53 + new_replicas = max(0, (int) opts.data_replicas - 54 + (int) bch2_bkey_nr_ptrs_fully_allocated(k)); 52 55 53 - if (!have_reservation) { 54 - unsigned new_replicas = 55 - max(0, (int) opts.data_replicas - 56 - (int) bch2_bkey_nr_ptrs_fully_allocated(k)); 57 - /* 58 - * Get a disk reservation before (in the nocow case) calling 59 - * into the allocator: 60 - */ 61 - ret = bch2_disk_reservation_get(c, &disk_res, sectors, new_replicas, 0); 62 - if (unlikely(ret)) 63 - goto err_noprint; 56 + /* 57 + * Get a disk reservation before (in the nocow case) calling 58 + * into the allocator: 59 + */ 60 + ret = bch2_disk_reservation_get(c, &disk_res, sectors, new_replicas, 0); 61 + if (unlikely(ret)) 62 + goto err_noprint; 64 63 65 - bch2_bkey_buf_reassemble(&old, c, k); 66 - } 64 + bch2_bkey_buf_reassemble(&old, c, k); 67 65 68 - if (have_reservation) { 69 - if (!bch2_extents_match(k, bkey_i_to_s_c(old.k))) 70 - goto err; 71 - 72 - bch2_key_resize(&new.k->k, sectors); 73 - } else if (!unwritten) { 66 + if (!unwritten) { 74 67 struct bkey_i_reservation *reservation; 75 68 76 69 bch2_bkey_buf_realloc(&new, c, sizeof(*reservation) / sizeof(u64)); ··· 108 117 extent_for_each_ptr(extent_i_to_s(e), ptr) 109 118 ptr->unwritten = true; 110 119 } 111 - 112 - have_reservation = true; 113 120 114 121 ret = bch2_extent_update(trans, inum, iter, new.k, &disk_res, 115 122 0, i_sectors_delta, true);