[Libguestfs] [libnbd PATCH 01/20] fuse: Only support defined fallocate modes

Martin Kletzander
Tue, 08 Jun 2021 07:53:42 -0000

None of them is defined on FreeBSD, for example, and the only other way to make
the code compile would be to define it ourselves.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 fuse/operations.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fuse/operations.c b/fuse/operations.c
index de04ba7b6d72..098613f66f33 100644
--- a/fuse/operations.c
+++ b/fuse/operations.c
@@ -440,6 +440,9 @@ nbdfuse_fallocate (const char *path, int mode, off_t offset,
off_t len,
   if (readonly)
     return -EACCES;

+#if defined(FALLOC_FL_PUNCH_HOLE) || defined(FALLOC_FL_ZERO_RANGE)
+# if defined(FALLOC_FL_PUNCH_HOLE)
+
   if (mode & FALLOC_FL_PUNCH_HOLE) {
     if (!nbd_can_trim (nbd.ptr[0]))
       return -EOPNOTSUPP;       /* Trim not supported. */
@@ -448,6 +451,9 @@ nbdfuse_fallocate (const char *path, int mode, off_t offset,
off_t len,
       return 0;
     }
   }
+#endif /*# if defined(FALLOC_FL_PUNCH_HOLE) */
+
+#if defined(FALLOC_FL_ZERO_RANGE)
   /* As of FUSE 35 this is not supported by the kernel module and it
    * always returns EOPNOTSUPP.
    */
@@ -470,7 +476,9 @@ nbdfuse_fallocate (const char *path, int mode, off_t offset,
off_t len,
       return 0;
     }
   }
+#endif /* defined(FALLOC_FL_ZERO_RANGE) */
   else
+#endif /* defined(FALLOC_FL_PUNCH_HOLE) || defined(FALLOC_FL_ZERO_RANGE) */
     return -EOPNOTSUPP;
 }

--
2.31.1