[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/10] block/export/fuse: Rearrange if-else-if ladder in fuse_fall
From: |
Kevin Wolf |
Subject: |
[PULL 04/10] block/export/fuse: Rearrange if-else-if ladder in fuse_fallocate() |
Date: |
Tue, 1 Feb 2022 16:21:02 +0100 |
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
In order to safely maintain a mixture of #ifdef'ry with if-else-if
ladder, rearrange the last statement (!mode) first. Since it is
mutually exclusive with the other conditions, checking it first
doesn't make any logical difference, but allows to add #ifdef'ry
around in a more cleanly way.
Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220201112655.344373-2-f4bug@amsat.org>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/export/fuse.c | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/block/export/fuse.c b/block/export/fuse.c
index 6710d8aed8..d25e478c0a 100644
--- a/block/export/fuse.c
+++ b/block/export/fuse.c
@@ -629,7 +629,26 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t
inode, int mode,
length = MIN(length, blk_len - offset);
}
- if (mode & FALLOC_FL_PUNCH_HOLE) {
+ 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 if (mode & FALLOC_FL_PUNCH_HOLE) {
if (!(mode & FALLOC_FL_KEEP_SIZE)) {
fuse_reply_err(req, EINVAL);
return;
@@ -665,25 +684,7 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t
inode, int mode,
} while (ret == 0 && length > 0);
}
#endif /* CONFIG_FALLOCATE_ZERO_RANGE */
- 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 {
+ else {
ret = -EOPNOTSUPP;
}
--
2.31.1
- [PULL 00/10] Block layer patches, Kevin Wolf, 2022/02/01
- [PULL 02/10] block: bdrv_set_backing_hd(): use drained section, Kevin Wolf, 2022/02/01
- [PULL 03/10] block/export: Fix vhost-user-blk shutdown with requests in flight, Kevin Wolf, 2022/02/01
- [PULL 04/10] block/export/fuse: Rearrange if-else-if ladder in fuse_fallocate(),
Kevin Wolf <=
- [PULL 05/10] block/export/fuse: Fix build failure on FreeBSD, Kevin Wolf, 2022/02/01
- [PULL 07/10] qsd: Document fuse's allow-other option, Kevin Wolf, 2022/02/01
- [PULL 08/10] qemu-img: Unify [-b [-F]] documentation, Kevin Wolf, 2022/02/01
- [PULL 01/10] qemu-storage-daemon: Fix typo in vhost-user-blk help, Kevin Wolf, 2022/02/01
- [PULL 10/10] block/rbd: workaround for ceph issue #53784, Kevin Wolf, 2022/02/01
- [PULL 09/10] block/rbd: fix handling of holes in .bdrv_co_block_status, Kevin Wolf, 2022/02/01
- [PULL 06/10] block.h: remove outdated comment, Kevin Wolf, 2022/02/01
- Re: [PULL 00/10] Block layer patches, Peter Maydell, 2022/02/02