block/export/fuse: Fix build failure on FreeBSD
v3 cover block/export/fuse: Fix build failure on FreeBSD
Since v2:
- Rearrange if-else-if ladder first (Kevin)
Philippe Mathieu-Daudé (2):
block/export/fuse: Rearrange if-else-if ladder in fuse_fallocate() block/export/fuse: Fix build failure on FreeBSD
block/export/fuse.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/2 block/export/fuse: Rearrange if-else-if ladder in fuse_fallocate()
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.
---
One minor checkpatch error:
ERROR: else should follow close brace '}'
#29: FILE: block/export/fuse.c:651:
+ }
+ else if (mode & FALLOC_FL_PUNCH_HOLE) {
--- block/export/fuse.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-)
block/export/fuse.c +21 -20
@@ -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 ; }
Signature · 1 line
2.34.1
PATCH v3 2/2 block/export/fuse: Fix build failure on FreeBSD
In reply to Philippe Mathieu-Daudé viaWhen building on FreeBSD we get:
[816/6851] Compiling C object libblockdev.fa.p/block_export_fuse.c.o ../block/export/fuse.c:628:16: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE'
if (mode & FALLOC_FL_KEEP_SIZE) {
^
../block/export/fuse.c:651:16: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE'
if (mode & FALLOC_FL_PUNCH_HOLE) {
^
../block/export/fuse.c:652:22: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE'
if (!(mode & FALLOC_FL_KEEP_SIZE)) {
^ 3 errors generated.
FAILED: libblockdev.fa.p/block_export_fuse.c.o
Meson indeed reported FALLOC_FL_PUNCH_HOLE is not available:
C compiler for the host machine: cc (clang 10.0.1 "FreeBSD clang version 10.0.1") Checking for function "fallocate" : NO
Checking for function "posix_fallocate" : YES
Header <linux/falloc.h> has symbol "FALLOC_FL_PUNCH_HOLE" : NO Header <linux/falloc.h> has symbol "FALLOC_FL_ZERO_RANGE" : NO
...
Similarly to commit 304332039 ("block/export/fuse.c: fix musl build"), guard the code requiring FALLOC_FL_KEEP_SIZE / FALLOC_FL_PUNCH_HOLE definitions under CONFIG_FALLOCATE_PUNCH_HOLE #ifdef'ry.
--- block/export/fuse.c | 4 ++++ 1 file changed, 4 insertions(+)
block/export/fuse.c +4 -0
@@ -625,9 +625,11 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode,return ; } +#ifdef CONFIG_FALLOCATE_PUNCH_HOLE if (mode &FALLOC_FL_KEEP_SIZE ) { length =MIN (length, blk_len - offset); } +#endif /* CONFIG_FALLOCATE_PUNCH_HOLE */ if (!mode) {/* We can only fallocate at the EOF with a truncate */
@@ -648,6 +650,7 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, ret =fuse_do_truncate (exp, offset + length, true,PREALLOC_MODE_FALLOC ); } +#ifdef CONFIG_FALLOCATE_PUNCH_HOLE else if (mode & FALLOC_FL_PUNCH_HOLE) {if (!(mode &FALLOC_FL_KEEP_SIZE )) {fuse_reply_err (req,EINVAL );
@@ -662,6 +665,7 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, length -= size; }while (ret ==0 && length >0 ); } +#endif /* CONFIG_FALLOCATE_PUNCH_HOLE */ #ifdef CONFIG_FALLOCATE_ZERO_RANGE else if (mode & FALLOC_FL_ZERO_RANGE) {if (!(mode &FALLOC_FL_KEEP_SIZE ) && offset + length > blk_len) {
Signature · 1 line
2.34.1
Quoted 58 lines · Philippe Mathieu-Daudé
When building on FreeBSD we get:
[816/6851] Compiling C object libblockdev.fa.p/block_export_fuse.c.o ../block/export/fuse.c:628:16: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' if (mode & FALLOC_FL_KEEP_SIZE) { ^ ../block/export/fuse.c:651:16: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE' if (mode & FALLOC_FL_PUNCH_HOLE) { ^ ../block/export/fuse.c:652:22: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' if (!(mode & FALLOC_FL_KEEP_SIZE)) { ^ 3 errors generated. FAILED: libblockdev.fa.p/block_export_fuse.c.oMeson indeed reported
FALLOC_FL_PUNCH_HOLEis not available:C compiler for the host machine: cc (clang 10.0.1 "FreeBSD clang version 10.0.1") Checking for function "fallocate" : NO
Checking for function "posix_fallocate" : YES
Header <linux/falloc.h> has symbol "FALLOC_FL_PUNCH_HOLE" : NO Header <linux/falloc.h> has symbol "FALLOC_FL_ZERO_RANGE" : NO
...Similarly to commit 304332039 ("
block/export/fuse.c: fix musl build"), guard the code requiringFALLOC_FL_KEEP_SIZE/FALLOC_FL_PUNCH_HOLEdefinitions underCONFIG_FALLOCATE_PUNCH_HOLE#ifdef'ry.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- block/export/fuse.c | 4 ++++ 1 file changed, 4 insertions(+)block/export/fuse.c +3
-0@@ -625,9 +625,11 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode,return ; } +#ifdef CONFIG_FALLOCATE_PUNCH_HOLE if (mode &FALLOC_FL_KEEP_SIZE ) { length =MIN (length, blk_len - offset); } +#endif /* CONFIG_FALLOCATE_PUNCH_HOLE */ if (!mode) {/* We can only fallocate at the EOF with a truncate */ @@ -648,6 +650,7 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, ret =fuse_do_truncate (exp, offset + length, true,PREALLOC_MODE_FALLOC ); } +#ifdef CONFIG_FALLOCATE_PUNCH_HOLE else if (mode & FALLOC_FL_PUNCH_HOLE) {if (!(mode &FALLOC_FL_KEEP_SIZE )) {fuse_reply_err (req,EINVAL );
block/export/fuse.c static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, · line 671
Quoted 7 lines
block/export/fuse.c +1
-0@@ -662,6 +665,7 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, length -= size; }while (ret ==0 && length >0 ); } +#endif /* CONFIG_FALLOCATE_PUNCH_HOLE */ #ifdef CONFIG_FALLOCATE_ZERO_RANGE else if (mode & FALLOC_FL_ZERO_RANGE) {if (!(mode &FALLOC_FL_KEEP_SIZE ) && offset + length > blk_len) {
I believe CONFIG_FALLOCATE_ZERO_RANGE only guarantees the presence of FALLOC_FL_ZERO_RANGE, so we probably should check for CONFIG_FALLOCATE_PUNCH_HOLE, too, here.
(Maybe in practice FALLOC_FL_ZERO_RANGE guarantees that FALLOC_FL_KEEP_SIZE exists, too, but then a check just wouldn’t hurt.)
Hanna
Kevin Wolf
AppliedAm 01.02.2022 um 12:26 hat Philippe Mathieu-Daudé geschrieben:
Quoted 6 lines
Since v2:
- Rearrange if-else-if ladder first (Kevin)Philippe Mathieu-Daudé (2):
block/export/fuse: Rearrange if-else-if ladder infuse_fallocate()block/export/fuse: Fix build failure on FreeBSD
Thanks, applied to the block branch.
Kevin