[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/34] fuse: (Partially) implement fallocate()
From: |
Kevin Wolf |
Subject: |
[PULL 09/34] fuse: (Partially) implement fallocate() |
Date: |
Fri, 11 Dec 2020 18:07:47 +0100 |
From: Max Reitz <mreitz@redhat.com>
This allows allocating areas after the (old) EOF as part of a growing
resize, writing zeroes, and discarding.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20201027190600.192171-6-mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/export/fuse.c | 84 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)
diff --git a/block/export/fuse.c b/block/export/fuse.c
index 92d2f50bcc..0b9d226b2f 100644
--- a/block/export/fuse.c
+++ b/block/export/fuse.c
@@ -521,6 +521,89 @@ static void fuse_write(fuse_req_t req, fuse_ino_t inode,
const char *buf,
}
}
+/**
+ * Let clients perform various fallocate() operations.
+ */
+static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode,
+ off_t offset, off_t length,
+ struct fuse_file_info *fi)
+{
+ FuseExport *exp = fuse_req_userdata(req);
+ int64_t blk_len;
+ int ret;
+
+ if (!exp->writable) {
+ fuse_reply_err(req, EACCES);
+ return;
+ }
+
+ blk_len = blk_getlength(exp->common.blk);
+ if (blk_len < 0) {
+ fuse_reply_err(req, -blk_len);
+ return;
+ }
+
+ if (mode & FALLOC_FL_KEEP_SIZE) {
+ length = MIN(length, blk_len - offset);
+ }
+
+ if (mode & FALLOC_FL_PUNCH_HOLE) {
+ if (!(mode & FALLOC_FL_KEEP_SIZE)) {
+ fuse_reply_err(req, EINVAL);
+ return;
+ }
+
+ do {
+ int size = MIN(length, BDRV_REQUEST_MAX_BYTES);
+
+ ret = blk_pdiscard(exp->common.blk, offset, size);
+ offset += size;
+ length -= size;
+ } while (ret == 0 && length > 0);
+ } else if (mode & FALLOC_FL_ZERO_RANGE) {
+ if (!(mode & FALLOC_FL_KEEP_SIZE) && offset + length > blk_len) {
+ /* No need for zeroes, we are going to write them ourselves */
+ ret = fuse_do_truncate(exp, offset + length, false,
+ PREALLOC_MODE_OFF);
+ if (ret < 0) {
+ fuse_reply_err(req, -ret);
+ return;
+ }
+ }
+
+ do {
+ int size = MIN(length, BDRV_REQUEST_MAX_BYTES);
+
+ ret = blk_pwrite_zeroes(exp->common.blk,
+ offset, size, 0);
+ offset += size;
+ length -= size;
+ } while (ret == 0 && length > 0);
+ } else if (!mode) {
+ /* We can only fallocate at the EOF with a truncate */
+ if (offset < blk_len) {
+ fuse_reply_err(req, EOPNOTSUPP);
+ return;
+ }
+
+ if (offset > blk_len) {
+ /* No preallocation needed here */
+ ret = fuse_do_truncate(exp, offset, true, PREALLOC_MODE_OFF);
+ if (ret < 0) {
+ fuse_reply_err(req, -ret);
+ return;
+ }
+ }
+
+ ret = fuse_do_truncate(exp, offset + length, true,
+ PREALLOC_MODE_FALLOC);
+ } else {
+ ret = -EOPNOTSUPP;
+ }
+
+ fuse_reply_err(req, ret < 0 ? -ret : 0);
+}
+
/**
* Let clients fsync the exported image.
*/
@@ -552,6 +635,7 @@ static const struct fuse_lowlevel_ops fuse_ops = {
.open = fuse_open,
.read = fuse_read,
.write = fuse_write,
+ .fallocate = fuse_fallocate,
.flush = fuse_flush,
.fsync = fuse_fsync,
};
--
2.29.2
- [PULL 00/34] Block layer patches, Kevin Wolf, 2020/12/11
- [PULL 02/34] block/curl: Use lock guard macros, Kevin Wolf, 2020/12/11
- [PULL 01/34] block/accounting: Use lock guard macros, Kevin Wolf, 2020/12/11
- [PULL 04/34] block/iscsi: Use lock guard macros, Kevin Wolf, 2020/12/11
- [PULL 03/34] block/throttle-groups: Use lock guard macros, Kevin Wolf, 2020/12/11
- [PULL 06/34] fuse: Allow exporting BDSs via FUSE, Kevin Wolf, 2020/12/11
- [PULL 08/34] fuse: Allow growable exports, Kevin Wolf, 2020/12/11
- [PULL 07/34] fuse: Implement standard FUSE operations, Kevin Wolf, 2020/12/11
- [PULL 05/34] meson: Detect libfuse, Kevin Wolf, 2020/12/11
- [PULL 09/34] fuse: (Partially) implement fallocate(),
Kevin Wolf <=
- [PULL 10/34] fuse: Implement hole detection through lseek, Kevin Wolf, 2020/12/11
- [PULL 12/34] iotests: Do not pipe _make_test_img, Kevin Wolf, 2020/12/11
- [PULL 11/34] iotests: Do not needlessly filter _make_test_img, Kevin Wolf, 2020/12/11
- [PULL 13/34] iotests: Use convert -n in some cases, Kevin Wolf, 2020/12/11
- [PULL 15/34] iotests: Derive image names from $TEST_IMG, Kevin Wolf, 2020/12/11
- [PULL 14/34] iotests/046: Avoid renaming images, Kevin Wolf, 2020/12/11
- [PULL 17/34] iotests: Restrict some Python tests to file, Kevin Wolf, 2020/12/11
- [PULL 18/34] iotests: Let _make_test_img guess $TEST_IMG_FILE, Kevin Wolf, 2020/12/11
- [PULL 20/34] storage-daemon: Call bdrv_close_all() on exit, Kevin Wolf, 2020/12/11
- [PULL 16/34] iotests/091: Use _cleanup_qemu instad of "wait", Kevin Wolf, 2020/12/11