summaryrefslogtreecommitdiff
path: root/fs/bcachefs/io.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-11-14 02:54:37 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:51 +0300
commit70de7a47e2c56adbd76c24c80e95cf2203a9e74f (patch)
tree1c04941412ef562c56d415b3c1a6226620e6f532 /fs/bcachefs/io.c
parent9bcbc0307d9cbaae5836a8051c91b468fe1571c9 (diff)
downloadlinux-70de7a47e2c56adbd76c24c80e95cf2203a9e74f.tar.xz
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>
Diffstat (limited to 'fs/bcachefs/io.c')
-rw-r--r--fs/bcachefs/io.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c
index af6b9a7456f5..bde3a4c42189 100644
--- a/fs/bcachefs/io.c
+++ b/fs/bcachefs/io.c
@@ -360,6 +360,36 @@ err:
return ret;
}
+/* Overwrites whatever was present with zeroes: */
+int bch2_extent_fallocate(struct btree_trans *trans,
+ subvol_inum inum,
+ struct btree_iter *iter,
+ unsigned sectors,
+ struct bch_io_opts opts,
+ s64 *i_sectors_delta,
+ struct write_point_specifier write_point)
+{
+ int ret;
+ struct bch_fs *c = trans->c;
+ struct disk_reservation disk_res = { 0 };
+ struct bkey_i_reservation *reservation =
+ bch2_trans_kmalloc(trans, sizeof(*reservation));
+
+ ret = PTR_ERR_OR_ZERO(reservation);
+ if (ret)
+ return ret;
+
+ bkey_reservation_init(&reservation->k_i);
+ reservation->k.p = iter->pos;
+ bch2_key_resize(&reservation->k, sectors);
+ reservation->v.nr_replicas = opts.data_replicas;
+
+ ret = bch2_extent_update(trans, inum, iter, &reservation->k_i, &disk_res,
+ 0, i_sectors_delta, true);
+ bch2_disk_reservation_put(c, &disk_res);
+ return ret;
+}
+
/*
* Returns -BCH_ERR_transacton_restart if we had to drop locks:
*/