]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/extra/0026-gluster-add-support-for-PREALLOC_MODE_FALLOC.patch
f794745a7e5ada9b10e50188a8a1b5053637230c
[pve-qemu.git] / debian / patches / extra / 0026-gluster-add-support-for-PREALLOC_MODE_FALLOC.patch
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
5
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
10 switch-statement.
11
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.
15
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>
22 ---
23 block/gluster.c | 76 ++++++++++++++++++++++++++++++---------------------------
24 configure | 6 +++++
25 2 files changed, 46 insertions(+), 36 deletions(-)
26
27 diff --git a/block/gluster.c b/block/gluster.c
28 index 06421ef79d..8108c89c7f 100644
29 --- a/block/gluster.c
30 +++ b/block/gluster.c
31 @@ -975,29 +975,6 @@ static coroutine_fn int qemu_gluster_co_pwrite_zeroes(BlockDriverState *bs,
32 qemu_coroutine_yield();
33 return acb.ret;
34 }
35 -
36 -static inline bool gluster_supports_zerofill(void)
37 -{
38 - return 1;
39 -}
40 -
41 -static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset,
42 - int64_t size)
43 -{
44 - return glfs_zerofill(fd, offset, size);
45 -}
46 -
47 -#else
48 -static inline bool gluster_supports_zerofill(void)
49 -{
50 - return 0;
51 -}
52 -
53 -static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset,
54 - int64_t size)
55 -{
56 - return 0;
57 -}
58 #endif
59
60 static int qemu_gluster_create(const char *filename,
61 @@ -1007,9 +984,10 @@ static int qemu_gluster_create(const char *filename,
62 struct glfs *glfs;
63 struct glfs_fd *fd;
64 int ret = 0;
65 - int prealloc = 0;
66 + PreallocMode prealloc;
67 int64_t total_size = 0;
68 char *tmp = NULL;
69 + Error *local_err = NULL;
70
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,
74 BDRV_SECTOR_SIZE);
75
76 tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
77 - if (!tmp || !strcmp(tmp, "off")) {
78 - prealloc = 0;
79 - } else if (!strcmp(tmp, "full") && gluster_supports_zerofill()) {
80 - prealloc = 1;
81 - } else {
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,
86 + &local_err);
87 + g_free(tmp);
88 + if (local_err) {
89 + error_propagate(errp, local_err);
90 ret = -EINVAL;
91 goto out;
92 }
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);
95 if (!fd) {
96 ret = -errno;
97 - } else {
98 + goto out;
99 + }
100 +
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");
106 + ret = -errno;
107 + }
108 + break;
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");
116 ret = -errno;
117 }
118 } else {
119 + error_setg(errp, "Could not resize file");
120 ret = -errno;
121 }
122 -
123 - if (glfs_close(fd) != 0) {
124 + break;
125 +#endif /* CONFIG_GLUSTERFS_ZEROFILL */
126 + case PREALLOC_MODE_OFF:
127 + if (glfs_ftruncate(fd, total_size) != 0) {
128 ret = -errno;
129 + error_setg(errp, "Could not resize file");
130 }
131 + break;
132 + default:
133 + ret = -EINVAL;
134 + error_setg(errp, "Unsupported preallocation mode: %s",
135 + PreallocMode_lookup[prealloc]);
136 + break;
137 + }
138 +
139 + if (glfs_close(fd) != 0) {
140 + ret = -errno;
141 }
142 out:
143 - g_free(tmp);
144 qapi_free_BlockdevOptionsGluster(gconf);
145 glfs_clear_preopened(glfs);
146 return ret;
147 diff --git a/configure b/configure
148 index 841f7a8fae..3667da6f07 100755
149 --- a/configure
150 +++ b/configure
151 @@ -300,6 +300,7 @@ seccomp=""
152 glusterfs=""
153 glusterfs_xlator_opt="no"
154 glusterfs_discard="no"
155 +glusterfs_fallocate="no"
156 glusterfs_zerofill="no"
157 gtk=""
158 gtkabi=""
159 @@ -3537,6 +3538,7 @@ if test "$glusterfs" != "no" ; then
160 glusterfs_discard="yes"
161 fi
162 if $pkg_config --atleast-version=6 glusterfs-api; then
163 + glusterfs_fallocate="yes"
164 glusterfs_zerofill="yes"
165 fi
166 else
167 @@ -5717,6 +5719,10 @@ if test "$glusterfs_discard" = "yes" ; then
168 echo "CONFIG_GLUSTERFS_DISCARD=y" >> $config_host_mak
169 fi
170
171 +if test "$glusterfs_fallocate" = "yes" ; then
172 + echo "CONFIG_GLUSTERFS_FALLOCATE=y" >> $config_host_mak
173 +fi
174 +
175 if test "$glusterfs_zerofill" = "yes" ; then
176 echo "CONFIG_GLUSTERFS_ZEROFILL=y" >> $config_host_mak
177 fi
178 --
179 2.11.0
180