[Libguestfs] [PATCH v2] file: Add missing include for FALLOC_FL_*

Nir Soffer nirsof at gmail.com
Mon Jul 30 18:04:04 UTC 2018


On RHEL 7.5 we need to include <linux/falloc.h> for FALLOC_FL_* macros.
Without the macros, fallocate is never used and we fall back to manual
zeroing.

Here are examples runs with this change with a local file on ext4:

$ export SOCK=/tmp/nbd.sock
$ export FILE=/var/tmp/nbd.img
$ export BLOCK=/dev/loop2

$ src/nbdkit -f plugins/file/.libs/nbdkit-file-plugin.so file=$FILE -U $SOCK
$ time qemu-img convert -n -f raw -O raw /var/tmp/fedora-27.img nbd:unix:$SOCK

real    0m13.361s
user    0m0.127s
sys     0m0.668s

$ src/nbdkit -f plugins/file/.libs/nbdkit-file-plugin.so file=$BLOCK -U $SOCK
$ time qemu-img convert -n -f raw -O raw /var/tmp/fedora-27.img nbd:unix:$SOCK

real    0m13.491s
user    0m0.129s
sys     0m0.612s

Tested on Fedora 28 and RHEL 7.5.
---

v2:
- Include <linux/falloc.h> only on Linux

v1 was here:
https://www.redhat.com/archives/libguestfs/2018-July/msg00083.html

 plugins/file/file.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/plugins/file/file.c b/plugins/file/file.c
index a8a6253..0345115 100644
--- a/plugins/file/file.c
+++ b/plugins/file/file.c
@@ -42,6 +42,10 @@
 #include <sys/stat.h>
 #include <errno.h>
 
+#if defined(__linux__)
+#include <linux/falloc.h>   /* For FALLOC_FL_* on RHEL, glibc < 2.18 */
+#endif
+
 #include <nbdkit-plugin.h>
 
 #ifndef O_CLOEXEC
-- 
2.17.1




More information about the Libguestfs mailing list