From nobody Sun May 5 10:19:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494875642272848.6936707567344; Mon, 15 May 2017 12:14:02 -0700 (PDT) Received: from localhost ([::1]:38269 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dALRQ-0004IH-6R for importer@patchew.org; Mon, 15 May 2017 15:14:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dALQH-0003nG-Po for qemu-devel@nongnu.org; Mon, 15 May 2017 15:12:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dALQG-000192-QH for qemu-devel@nongnu.org; Mon, 15 May 2017 15:12:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35794) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dALQC-00011q-0U; Mon, 15 May 2017 15:12:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96EBA80C0D; Mon, 15 May 2017 19:12:31 +0000 (UTC) Received: from localhost (ovpn-117-110.ams2.redhat.com [10.36.117.110]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB6A862926; Mon, 15 May 2017 19:12:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 96EBA80C0D Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ndevos@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 96EBA80C0D From: Niels de Vos To: Jeff Cody , Kevin Wolf , qemu-block@nongnu.org Date: Mon, 15 May 2017 21:11:36 +0200 Message-Id: <20170515191136.24314-1-ndevos@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 15 May 2017 19:12:31 +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] [PATCH] 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: qemu-devel@nongnu.org, Niels de Vos Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add missing support for "preallocation=3Dfalloc" to the Gluster block driver. This change bases its logic on that of block/file-posix.c and removed the gluster_supports_zerofill() function in favour of an #ifdef check in an easy to read switch-statement. Reported-by: Satheesaran Sundaramoorthi URL: https://bugzilla.redhat.com/1450759 Signed-off-by: Niels de Vos --- block/gluster.c | 61 +++++++++++++++++++++++++++++++++++------------------= ---- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 7c76cd0..566166f 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -965,11 +965,6 @@ static coroutine_fn int qemu_gluster_co_pwrite_zeroes(= BlockDriverState *bs, return acb.ret; } =20 -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) { @@ -977,11 +972,6 @@ static inline int qemu_gluster_zerofill(struct glfs_fd= *fd, int64_t offset, } =20 #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) { @@ -996,9 +986,10 @@ static int qemu_gluster_create(const char *filename, struct glfs *glfs; struct glfs_fd *fd; int ret =3D 0; - int prealloc =3D 0; + PreallocMode prealloc; int64_t total_size =3D 0; char *tmp =3D NULL; + Error *local_err =3D NULL; =20 gconf =3D g_new0(BlockdevOptionsGluster, 1); gconf->debug =3D qemu_opt_get_number_del(opts, GLUSTER_OPT_DEBUG, @@ -1026,13 +1017,12 @@ static int qemu_gluster_create(const char *filename, BDRV_SECTOR_SIZE); =20 tmp =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); - if (!tmp || !strcmp(tmp, "off")) { - prealloc =3D 0; - } else if (!strcmp(tmp, "full") && gluster_supports_zerofill()) { - prealloc =3D 1; - } else { - error_setg(errp, "Invalid preallocation mode: '%s'" - " or GlusterFS doesn't support zerofill API", tmp= ); + prealloc =3D 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 =3D -EINVAL; goto out; } @@ -1041,21 +1031,46 @@ static int qemu_gluster_create(const char *filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_I= WUSR); if (!fd) { ret =3D -errno; - } else { + goto out; + } + + switch (prealloc) { + case PREALLOC_MODE_FALLOC: + if (!glfs_fallocate(fd, 0, 0, total_size)) { + error_setg(errp, "Could not preallocate data for the new file"= ); + ret =3D -errno; + } + break; +#ifdef CONFIG_GLUSTERFS_ZEROFILL + case PREALLOC_MODE_FULL: if (!glfs_ftruncate(fd, total_size)) { - if (prealloc && qemu_gluster_zerofill(fd, 0, total_size)) { + if (qemu_gluster_zerofill(fd, 0, total_size)) { + error_setg(errp, "Could not zerofill the new file"); ret =3D -errno; } } else { + error_setg(errp, "Could not resize file"); ret =3D -errno; } - - if (glfs_close(fd) !=3D 0) { + break; +#endif /* CONFIG_GLUSTERFS_ZEROFILL */ + case PREALLOC_MODE_OFF: + if (glfs_ftruncate(fd, total_size) !=3D 0) { ret =3D -errno; + error_setg(errp, "Could not resize file"); } + break; + default: + ret =3D -EINVAL; + error_setg(errp, "Unsupported preallocation mode: %s", + PreallocMode_lookup[prealloc]); + break; + } + + if (glfs_close(fd) !=3D 0) { + ret =3D -errno; } out: - g_free(tmp); qapi_free_BlockdevOptionsGluster(gconf); glfs_clear_preopened(glfs); return ret; --=20 2.9.3