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

bcachefs: bch2_extent_fallocate()

This factors out part of __bchfs_fallocate() in fs-io.c into an new,
lower level io.c helper, which creates a single extent reservation.

This is prep work for nocow support - the new helper will shortly gain
the ability to create unwritten extents.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

+38 -26
+5 -26
fs/bcachefs/fs-io.c
··· 3074 3074 3075 3075 while (!ret && bkey_lt(iter.pos, end_pos)) { 3076 3076 s64 i_sectors_delta = 0; 3077 - struct disk_reservation disk_res = { 0 }; 3078 3077 struct quota_res quota_res = { 0 }; 3079 - struct bkey_i_reservation reservation; 3080 3078 struct bkey_s_c k; 3081 3079 unsigned sectors; 3082 3080 u32 snapshot; ··· 3105 3107 continue; 3106 3108 } 3107 3109 3108 - bkey_reservation_init(&reservation.k_i); 3109 - reservation.k.type = KEY_TYPE_reservation; 3110 - reservation.k.p = k.k->p; 3111 - reservation.k.size = k.k->size; 3112 - 3113 - bch2_cut_front(iter.pos, &reservation.k_i); 3114 - bch2_cut_back(end_pos, &reservation.k_i); 3115 - 3116 - sectors = reservation.k.size; 3117 - reservation.v.nr_replicas = bch2_bkey_nr_ptrs_allocated(k); 3110 + sectors = bpos_min(k.k->p, end_pos).offset - iter.pos.offset; 3118 3111 3119 3112 if (!bkey_extent_is_allocation(k.k)) { 3120 3113 ret = bch2_quota_reservation_add(c, inode, ··· 3115 3126 goto bkey_err; 3116 3127 } 3117 3128 3118 - if (reservation.v.nr_replicas < opts.data_replicas || 3119 - bch2_bkey_sectors_compressed(k)) { 3120 - ret = bch2_disk_reservation_get(c, &disk_res, sectors, 3121 - opts.data_replicas, 0); 3122 - if (unlikely(ret)) 3123 - goto bkey_err; 3124 - 3125 - reservation.v.nr_replicas = disk_res.nr_replicas; 3126 - } 3127 - 3128 - ret = bch2_extent_update(&trans, inode_inum(inode), &iter, 3129 - &reservation.k_i, &disk_res, 3130 - 0, &i_sectors_delta, true); 3129 + ret = bch2_extent_fallocate(&trans, inode_inum(inode), &iter, 3130 + sectors, opts, &i_sectors_delta, 3131 + writepoint_hashed((unsigned long) current)); 3131 3132 if (ret) 3132 3133 goto bkey_err; 3134 + 3133 3135 i_sectors_acct(c, inode, &quota_res, i_sectors_delta); 3134 3136 bkey_err: 3135 3137 bch2_quota_reservation_put(c, inode, &quota_res); 3136 - bch2_disk_reservation_put(c, &disk_res); 3137 3138 if (bch2_err_matches(ret, BCH_ERR_transaction_restart)) 3138 3139 ret = 0; 3139 3140 }
+30
fs/bcachefs/io.c
··· 360 360 return ret; 361 361 } 362 362 363 + /* Overwrites whatever was present with zeroes: */ 364 + int bch2_extent_fallocate(struct btree_trans *trans, 365 + subvol_inum inum, 366 + struct btree_iter *iter, 367 + unsigned sectors, 368 + struct bch_io_opts opts, 369 + s64 *i_sectors_delta, 370 + struct write_point_specifier write_point) 371 + { 372 + int ret; 373 + struct bch_fs *c = trans->c; 374 + struct disk_reservation disk_res = { 0 }; 375 + struct bkey_i_reservation *reservation = 376 + bch2_trans_kmalloc(trans, sizeof(*reservation)); 377 + 378 + ret = PTR_ERR_OR_ZERO(reservation); 379 + if (ret) 380 + return ret; 381 + 382 + bkey_reservation_init(&reservation->k_i); 383 + reservation->k.p = iter->pos; 384 + bch2_key_resize(&reservation->k, sectors); 385 + reservation->v.nr_replicas = opts.data_replicas; 386 + 387 + ret = bch2_extent_update(trans, inum, iter, &reservation->k_i, &disk_res, 388 + 0, i_sectors_delta, true); 389 + bch2_disk_reservation_put(c, &disk_res); 390 + return ret; 391 + } 392 + 363 393 /* 364 394 * Returns -BCH_ERR_transacton_restart if we had to drop locks: 365 395 */
+3
fs/bcachefs/io.h
··· 74 74 int bch2_extent_update(struct btree_trans *, subvol_inum, 75 75 struct btree_iter *, struct bkey_i *, 76 76 struct disk_reservation *, u64, s64 *, bool); 77 + int bch2_extent_fallocate(struct btree_trans *, subvol_inum, struct btree_iter *, 78 + unsigned, struct bch_io_opts, s64 *, 79 + struct write_point_specifier); 77 80 78 81 int bch2_fpunch_at(struct btree_trans *, struct btree_iter *, 79 82 subvol_inum, u64, s64 *);