1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Niels de Vos <ndevos@redhat.com>
3 Date: Sun, 28 May 2017 12:01:14 +0530
4 Subject: [PATCH] gluster: add support for PREALLOC_MODE_FALLOC
6 Add missing support for "preallocation=falloc" to the Gluster block
7 driver. This change bases its logic on that of block/file-posix.c and
8 removed the gluster_supports_zerofill() and qemu_gluster_zerofill()
9 functions in favour of #ifdef checks in an easy to read
12 Both glfs_zerofill() and glfs_fallocate() have been introduced with
13 GlusterFS 3.5.0 (pkg-config glusterfs-api = 6). A #define for the
14 availability of glfs_fallocate() has been added to ./configure.
16 Reported-by: Satheesaran Sundaramoorthi <sasundar@redhat.com>
17 Signed-off-by: Niels de Vos <ndevos@redhat.com>
18 Message-id: 20170528063114.28691-1-ndevos@redhat.com
19 URL: https://bugzilla.redhat.com/1450759
20 Signed-off-by: Niels de Vos <ndevos@redhat.com>
21 Signed-off-by: Jeff Cody <jcody@redhat.com>
23 block/gluster.c | 76 ++++++++++++++++++++++++++++++---------------------------
25 2 files changed, 46 insertions(+), 36 deletions(-)
27 diff --git a/block/gluster.c b/block/gluster.c
28 index 06421ef79d..8108c89c7f 100644
31 @@ -975,29 +975,6 @@ static coroutine_fn int qemu_gluster_co_pwrite_zeroes(BlockDriverState *bs,
32 qemu_coroutine_yield();
36 -static inline bool gluster_supports_zerofill(void)
41 -static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset,
44 - return glfs_zerofill(fd, offset, size);
48 -static inline bool gluster_supports_zerofill(void)
53 -static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset,
60 static int qemu_gluster_create(const char *filename,
61 @@ -1007,9 +984,10 @@ static int qemu_gluster_create(const char *filename,
66 + PreallocMode prealloc;
67 int64_t total_size = 0;
69 + Error *local_err = NULL;
71 gconf = g_new0(BlockdevOptionsGluster, 1);
72 gconf->debug = qemu_opt_get_number_del(opts, GLUSTER_OPT_DEBUG,
73 @@ -1037,13 +1015,12 @@ static int qemu_gluster_create(const char *filename,
76 tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
77 - if (!tmp || !strcmp(tmp, "off")) {
79 - } else if (!strcmp(tmp, "full") && gluster_supports_zerofill()) {
82 - error_setg(errp, "Invalid preallocation mode: '%s'"
83 - " or GlusterFS doesn't support zerofill API", tmp);
84 + prealloc = qapi_enum_parse(PreallocMode_lookup, tmp,
85 + PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
89 + error_propagate(errp, local_err);
93 @@ -1052,21 +1029,48 @@ static int qemu_gluster_create(const char *filename,
94 O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR);
101 + switch (prealloc) {
102 +#ifdef CONFIG_GLUSTERFS_FALLOCATE
103 + case PREALLOC_MODE_FALLOC:
104 + if (glfs_fallocate(fd, 0, 0, total_size)) {
105 + error_setg(errp, "Could not preallocate data for the new file");
109 +#endif /* CONFIG_GLUSTERFS_FALLOCATE */
110 +#ifdef CONFIG_GLUSTERFS_ZEROFILL
111 + case PREALLOC_MODE_FULL:
112 if (!glfs_ftruncate(fd, total_size)) {
113 - if (prealloc && qemu_gluster_zerofill(fd, 0, total_size)) {
114 + if (glfs_zerofill(fd, 0, total_size)) {
115 + error_setg(errp, "Could not zerofill the new file");
119 + error_setg(errp, "Could not resize file");
123 - if (glfs_close(fd) != 0) {
125 +#endif /* CONFIG_GLUSTERFS_ZEROFILL */
126 + case PREALLOC_MODE_OFF:
127 + if (glfs_ftruncate(fd, total_size) != 0) {
129 + error_setg(errp, "Could not resize file");
134 + error_setg(errp, "Unsupported preallocation mode: %s",
135 + PreallocMode_lookup[prealloc]);
139 + if (glfs_close(fd) != 0) {
144 qapi_free_BlockdevOptionsGluster(gconf);
145 glfs_clear_preopened(glfs);
147 diff --git a/configure b/configure
148 index 841f7a8fae..3667da6f07 100755
151 @@ -300,6 +300,7 @@ seccomp=""
153 glusterfs_xlator_opt="no"
154 glusterfs_discard="no"
155 +glusterfs_fallocate="no"
156 glusterfs_zerofill="no"
159 @@ -3537,6 +3538,7 @@ if test "$glusterfs" != "no" ; then
160 glusterfs_discard="yes"
162 if $pkg_config --atleast-version=6 glusterfs-api; then
163 + glusterfs_fallocate="yes"
164 glusterfs_zerofill="yes"
167 @@ -5717,6 +5719,10 @@ if test "$glusterfs_discard" = "yes" ; then
168 echo "CONFIG_GLUSTERFS_DISCARD=y" >> $config_host_mak
171 +if test "$glusterfs_fallocate" = "yes" ; then
172 + echo "CONFIG_GLUSTERFS_FALLOCATE=y" >> $config_host_mak
175 if test "$glusterfs_zerofill" = "yes" ; then
176 echo "CONFIG_GLUSTERFS_ZEROFILL=y" >> $config_host_mak