From patchwork Fri Jun 2 15:33:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9762859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 93F5660365 for ; Fri, 2 Jun 2017 15:34:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85F8F2852E for ; Fri, 2 Jun 2017 15:34:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A07D28546; Fri, 2 Jun 2017 15:34:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DF8422852E for ; Fri, 2 Jun 2017 15:34:56 +0000 (UTC) Received: from localhost ([::1]:50307 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGobH-0003WI-VV for patchwork-qemu-devel@patchwork.kernel.org; Fri, 02 Jun 2017 11:34:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGoaB-0003Fs-PA for qemu-devel@nongnu.org; Fri, 02 Jun 2017 11:33:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGoaA-0001Ay-Ez for qemu-devel@nongnu.org; Fri, 02 Jun 2017 11:33:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34736) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGoa6-00017K-VM; Fri, 02 Jun 2017 11:33:43 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1EAF7AE81; Fri, 2 Jun 2017 15:33:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F1EAF7AE81 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com F1EAF7AE81 Received: from localhost (ovpn-117-1.phx2.redhat.com [10.3.117.1]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2A6B97F468; Fri, 2 Jun 2017 15:33:40 +0000 (UTC) From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 2 Jun 2017 11:33:36 -0400 Message-Id: <20170602153336.18951-2-jcody@redhat.com> In-Reply-To: <20170602153336.18951-1-jcody@redhat.com> References: <20170602153336.18951-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 02 Jun 2017 15:33:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/1] gluster: add support for PREALLOC_MODE_FALLOC X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, Niels de Vos Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Niels de Vos 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 Signed-off-by: Niels de Vos Message-id: 20170528063114.28691-1-ndevos@redhat.com URL: https://bugzilla.redhat.com/1450759 Signed-off-by: Niels de Vos Signed-off-by: Jeff Cody --- block/gluster.c | 78 ++++++++++++++++++++++++++++++--------------------------- configure | 6 +++++ 2 files changed, 47 insertions(+), 37 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 8ba3bcc..031596a 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -964,29 +964,6 @@ static coroutine_fn int qemu_gluster_co_pwrite_zeroes(BlockDriverState *bs, qemu_coroutine_yield(); 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 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_fd *fd; int ret = 0; - int prealloc = 0; + PreallocMode prealloc; int64_t total_size = 0; char *tmp = NULL; + Error *local_err = NULL; gconf = g_new0(BlockdevOptionsGluster, 1); 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); tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); - if (!tmp || !strcmp(tmp, "off")) { - prealloc = 0; - } else if (!strcmp(tmp, "full") && gluster_supports_zerofill()) { - prealloc = 1; - } else { - error_setg(errp, "Invalid preallocation mode: '%s'" - " or GlusterFS doesn't support zerofill API", tmp); + prealloc = qapi_enum_parse(PreallocMode_lookup, tmp, + PREALLOC_MODE__MAX, PREALLOC_MODE_OFF, + &local_err); + g_free(tmp); + if (local_err) { + error_propagate(errp, local_err); ret = -EINVAL; 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); if (!fd) { 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 (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; } } else { + error_setg(errp, "Could not resize file"); 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) { - ret = -errno; - } + if (glfs_close(fd) != 0) { + ret = -errno; } out: - g_free(tmp); qapi_free_BlockdevOptionsGluster(gconf); glfs_clear_preopened(glfs); return ret; diff --git a/configure b/configure index 0586ec9..21944ea 100755 --- a/configure +++ b/configure @@ -300,6 +300,7 @@ seccomp="" glusterfs="" glusterfs_xlator_opt="no" glusterfs_discard="no" +glusterfs_fallocate="no" glusterfs_zerofill="no" gtk="" gtkabi="" @@ -3583,6 +3584,7 @@ if test "$glusterfs" != "no" ; then glusterfs_discard="yes" fi if $pkg_config --atleast-version=6 glusterfs-api; then + glusterfs_fallocate="yes" glusterfs_zerofill="yes" fi else @@ -5757,6 +5759,10 @@ if test "$glusterfs_discard" = "yes" ; then echo "CONFIG_GLUSTERFS_DISCARD=y" >> $config_host_mak fi +if test "$glusterfs_fallocate" = "yes" ; then + echo "CONFIG_GLUSTERFS_FALLOCATE=y" >> $config_host_mak +fi + if test "$glusterfs_zerofill" = "yes" ; then echo "CONFIG_GLUSTERFS_ZEROFILL=y" >> $config_host_mak fi