gluster: add support for PREALLOC_MODE_FALLOC
Add missing support for "preallocation=falloc" to the Gluster block driver. This change bases its logic on that of block/file-posix.c and removed the gluster_supports_zerofill() and qemu_gluster_zerofill() functions in favour of #ifdef checks in an easy to read switch-statement. Both glfs_zerofill() and glfs_fallocate() have been introduced with GlusterFS 3.5.0 (pkg-config glusterfs-api = 6). A #define for the availability of glfs_fallocate() has been added to ./configure. Reported-by: Satheesaran Sundaramoorthi <sasundar@redhat.com> Signed-off-by: Niels de Vos <ndevos@redhat.com> Message-id: 20170528063114.28691-1-ndevos@redhat.com URL: https://bugzilla.redhat.com/1450759 Signed-off-by: Niels de Vos <ndevos@redhat.com> Signed-off-by: Jeff Cody <jcody@redhat.com>
This commit is contained in:
parent
d47a851cae
commit
df3a429ae8
|
@ -964,29 +964,6 @@ static coroutine_fn int qemu_gluster_co_pwrite_zeroes(BlockDriverState *bs,
|
||||||
qemu_coroutine_yield();
|
qemu_coroutine_yield();
|
||||||
return acb.ret;
|
return acb.ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool gluster_supports_zerofill(void)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset,
|
|
||||||
int64_t size)
|
|
||||||
{
|
|
||||||
return glfs_zerofill(fd, offset, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
static inline bool gluster_supports_zerofill(void)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset,
|
|
||||||
int64_t size)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int qemu_gluster_create(const char *filename,
|
static int qemu_gluster_create(const char *filename,
|
||||||
|
@ -996,9 +973,10 @@ static int qemu_gluster_create(const char *filename,
|
||||||
struct glfs *glfs;
|
struct glfs *glfs;
|
||||||
struct glfs_fd *fd;
|
struct glfs_fd *fd;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int prealloc = 0;
|
PreallocMode prealloc;
|
||||||
int64_t total_size = 0;
|
int64_t total_size = 0;
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
|
Error *local_err = NULL;
|
||||||
|
|
||||||
gconf = g_new0(BlockdevOptionsGluster, 1);
|
gconf = g_new0(BlockdevOptionsGluster, 1);
|
||||||
gconf->debug = qemu_opt_get_number_del(opts, GLUSTER_OPT_DEBUG,
|
gconf->debug = qemu_opt_get_number_del(opts, GLUSTER_OPT_DEBUG,
|
||||||
|
@ -1026,13 +1004,12 @@ static int qemu_gluster_create(const char *filename,
|
||||||
BDRV_SECTOR_SIZE);
|
BDRV_SECTOR_SIZE);
|
||||||
|
|
||||||
tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
|
tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
|
||||||
if (!tmp || !strcmp(tmp, "off")) {
|
prealloc = qapi_enum_parse(PreallocMode_lookup, tmp,
|
||||||
prealloc = 0;
|
PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
|
||||||
} else if (!strcmp(tmp, "full") && gluster_supports_zerofill()) {
|
&local_err);
|
||||||
prealloc = 1;
|
g_free(tmp);
|
||||||
} else {
|
if (local_err) {
|
||||||
error_setg(errp, "Invalid preallocation mode: '%s'"
|
error_propagate(errp, local_err);
|
||||||
" or GlusterFS doesn't support zerofill API", tmp);
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -1041,21 +1018,48 @@ static int qemu_gluster_create(const char *filename,
|
||||||
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR);
|
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR);
|
||||||
if (!fd) {
|
if (!fd) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
} else {
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (prealloc) {
|
||||||
|
#ifdef CONFIG_GLUSTERFS_FALLOCATE
|
||||||
|
case PREALLOC_MODE_FALLOC:
|
||||||
|
if (glfs_fallocate(fd, 0, 0, total_size)) {
|
||||||
|
error_setg(errp, "Could not preallocate data for the new file");
|
||||||
|
ret = -errno;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif /* CONFIG_GLUSTERFS_FALLOCATE */
|
||||||
|
#ifdef CONFIG_GLUSTERFS_ZEROFILL
|
||||||
|
case PREALLOC_MODE_FULL:
|
||||||
if (!glfs_ftruncate(fd, total_size)) {
|
if (!glfs_ftruncate(fd, total_size)) {
|
||||||
if (prealloc && qemu_gluster_zerofill(fd, 0, total_size)) {
|
if (glfs_zerofill(fd, 0, total_size)) {
|
||||||
|
error_setg(errp, "Could not zerofill the new file");
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
error_setg(errp, "Could not resize file");
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
#endif /* CONFIG_GLUSTERFS_ZEROFILL */
|
||||||
|
case PREALLOC_MODE_OFF:
|
||||||
|
if (glfs_ftruncate(fd, total_size) != 0) {
|
||||||
|
ret = -errno;
|
||||||
|
error_setg(errp, "Could not resize file");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret = -EINVAL;
|
||||||
|
error_setg(errp, "Unsupported preallocation mode: %s",
|
||||||
|
PreallocMode_lookup[prealloc]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (glfs_close(fd) != 0) {
|
if (glfs_close(fd) != 0) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
g_free(tmp);
|
|
||||||
qapi_free_BlockdevOptionsGluster(gconf);
|
qapi_free_BlockdevOptionsGluster(gconf);
|
||||||
glfs_clear_preopened(glfs);
|
glfs_clear_preopened(glfs);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -300,6 +300,7 @@ seccomp=""
|
||||||
glusterfs=""
|
glusterfs=""
|
||||||
glusterfs_xlator_opt="no"
|
glusterfs_xlator_opt="no"
|
||||||
glusterfs_discard="no"
|
glusterfs_discard="no"
|
||||||
|
glusterfs_fallocate="no"
|
||||||
glusterfs_zerofill="no"
|
glusterfs_zerofill="no"
|
||||||
gtk=""
|
gtk=""
|
||||||
gtkabi=""
|
gtkabi=""
|
||||||
|
@ -3583,6 +3584,7 @@ if test "$glusterfs" != "no" ; then
|
||||||
glusterfs_discard="yes"
|
glusterfs_discard="yes"
|
||||||
fi
|
fi
|
||||||
if $pkg_config --atleast-version=6 glusterfs-api; then
|
if $pkg_config --atleast-version=6 glusterfs-api; then
|
||||||
|
glusterfs_fallocate="yes"
|
||||||
glusterfs_zerofill="yes"
|
glusterfs_zerofill="yes"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -5757,6 +5759,10 @@ if test "$glusterfs_discard" = "yes" ; then
|
||||||
echo "CONFIG_GLUSTERFS_DISCARD=y" >> $config_host_mak
|
echo "CONFIG_GLUSTERFS_DISCARD=y" >> $config_host_mak
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test "$glusterfs_fallocate" = "yes" ; then
|
||||||
|
echo "CONFIG_GLUSTERFS_FALLOCATE=y" >> $config_host_mak
|
||||||
|
fi
|
||||||
|
|
||||||
if test "$glusterfs_zerofill" = "yes" ; then
|
if test "$glusterfs_zerofill" = "yes" ; then
|
||||||
echo "CONFIG_GLUSTERFS_ZEROFILL=y" >> $config_host_mak
|
echo "CONFIG_GLUSTERFS_ZEROFILL=y" >> $config_host_mak
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue