From nobody Thu May 2 19:05:37 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151852850669120.008544408287207; Tue, 13 Feb 2018 05:28:26 -0800 (PST) Received: from localhost ([::1]:59254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eladC-00045Q-O0 for importer@patchew.org; Tue, 13 Feb 2018 08:28:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaFs-0007bD-Kg for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elaFr-0006UO-PO for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:16 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60206 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elaFj-0006NI-KE; Tue, 13 Feb 2018 08:04:07 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B12F34084FEF; Tue, 13 Feb 2018 13:04:04 +0000 (UTC) Received: from localhost (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 665531008578; Tue, 13 Feb 2018 13:04:04 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 13 Feb 2018 14:03:50 +0100 Message-Id: <20180213130356.8885-2-mreitz@redhat.com> In-Reply-To: <20180213130356.8885-1-mreitz@redhat.com> References: <20180213130356.8885-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Feb 2018 13:04:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Feb 2018 13:04:04 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 1/7] gluster: Move glfs_close() to create's clean-up 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: Kevin Wolf , sheepdog@lists.wpkg.org, Hitoshi Mitake , Jeff Cody , qemu-devel@nongnu.org, Max Reitz , Liu Yuan 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" glfs_close() is a classical clean-up operation, as can be seen by the fact that it is executed even if the truncation before it failed. Also, moving it to clean-up makes it more clear that if it fails, we do not want it to overwrite the current ret value if that signifies an error already. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/gluster.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index d8decc41ad..7fab2dfa12 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -970,7 +970,7 @@ static int qemu_gluster_create(const char *filename, { BlockdevOptionsGluster *gconf; struct glfs *glfs; - struct glfs_fd *fd; + struct glfs_fd *fd =3D NULL; int ret =3D 0; PreallocMode prealloc; int64_t total_size =3D 0; @@ -1054,10 +1054,12 @@ static int qemu_gluster_create(const char *filename, break; } =20 - if (glfs_close(fd) !=3D 0) { - ret =3D -errno; - } out: + if (fd) { + if (glfs_close(fd) !=3D 0 && ret =3D=3D 0) { + ret =3D -errno; + } + } qapi_free_BlockdevOptionsGluster(gconf); glfs_clear_preopened(glfs); return ret; --=20 2.14.3 From nobody Thu May 2 19:05:37 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518528698160117.15988911780732; Tue, 13 Feb 2018 05:31:38 -0800 (PST) Received: from localhost ([::1]:59834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elagL-00072l-AP for importer@patchew.org; Tue, 13 Feb 2018 08:31:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaFq-0007Yd-3t for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elaFp-0006SF-71 for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:14 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41626 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elaFj-0006NJ-KH; Tue, 13 Feb 2018 08:04:07 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43BC87D85D; Tue, 13 Feb 2018 13:04:06 +0000 (UTC) Received: from localhost (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE1032166BB3; Tue, 13 Feb 2018 13:04:05 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 13 Feb 2018 14:03:51 +0100 Message-Id: <20180213130356.8885-3-mreitz@redhat.com> In-Reply-To: <20180213130356.8885-1-mreitz@redhat.com> References: <20180213130356.8885-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Feb 2018 13:04:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Feb 2018 13:04:06 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 2/7] gluster: Pull truncation from qemu_gluster_create 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: Kevin Wolf , sheepdog@lists.wpkg.org, Hitoshi Mitake , Jeff Cody , qemu-devel@nongnu.org, Max Reitz , Liu Yuan 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" Pull out the truncation code from the qemu_cluster_create() function so we can later reuse it in qemu_gluster_truncate(). Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/gluster.c | 74 +++++++++++++++++++++++++++++++----------------------= ---- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 7fab2dfa12..8178541416 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -965,6 +965,45 @@ static coroutine_fn int qemu_gluster_co_pwrite_zeroes(= BlockDriverState *bs, } #endif =20 +static int qemu_gluster_do_truncate(struct glfs_fd *fd, int64_t offset, + PreallocMode prealloc, Error **errp) +{ + switch (prealloc) { +#ifdef CONFIG_GLUSTERFS_FALLOCATE + case PREALLOC_MODE_FALLOC: + if (glfs_fallocate(fd, 0, 0, offset)) { + error_setg_errno(errp, errno, "Could not preallocate data"); + return -errno; + } + break; +#endif /* CONFIG_GLUSTERFS_FALLOCATE */ +#ifdef CONFIG_GLUSTERFS_ZEROFILL + case PREALLOC_MODE_FULL: + if (glfs_ftruncate(fd, offset)) { + error_setg_errno(errp, errno, "Could not resize file"); + return -errno; + } + if (glfs_zerofill(fd, 0, offset)) { + error_setg_errno(errp, errno, "Could not zerofill the new area= "); + return -errno; + } + break; +#endif /* CONFIG_GLUSTERFS_ZEROFILL */ + case PREALLOC_MODE_OFF: + if (glfs_ftruncate(fd, offset)) { + error_setg_errno(errp, errno, "Could not resize file"); + return -errno; + } + break; + default: + error_setg(errp, "Unsupported preallocation mode: %s", + PreallocMode_str(prealloc)); + return -EINVAL; + } + + return 0; +} + static int qemu_gluster_create(const char *filename, QemuOpts *opts, Error **errp) { @@ -1019,40 +1058,7 @@ static int qemu_gluster_create(const char *filename, goto out; } =20 - 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 =3D -errno; - } - break; -#endif /* CONFIG_GLUSTERFS_FALLOCATE */ -#ifdef CONFIG_GLUSTERFS_ZEROFILL - case PREALLOC_MODE_FULL: - if (!glfs_ftruncate(fd, total_size)) { - if (glfs_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; - } - 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_str(prealloc)); - break; - } + ret =3D qemu_gluster_do_truncate(fd, total_size, prealloc, errp); =20 out: if (fd) { --=20 2.14.3 From nobody Thu May 2 19:05:37 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518528895755479.3255775263593; Tue, 13 Feb 2018 05:34:55 -0800 (PST) Received: from localhost ([::1]:60429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elajR-0001eu-Tx for importer@patchew.org; Tue, 13 Feb 2018 08:34:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaFz-0007iT-1V for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elaFw-0006cK-IN for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:23 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60212 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elaFk-0006OB-8t; Tue, 13 Feb 2018 08:04:08 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D497E4040852; Tue, 13 Feb 2018 13:04:07 +0000 (UTC) Received: from localhost (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8761EB0789; Tue, 13 Feb 2018 13:04:07 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 13 Feb 2018 14:03:52 +0100 Message-Id: <20180213130356.8885-4-mreitz@redhat.com> In-Reply-To: <20180213130356.8885-1-mreitz@redhat.com> References: <20180213130356.8885-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Feb 2018 13:04:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 13 Feb 2018 13:04:07 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 3/7] gluster: Query current size in do_truncate() 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: Kevin Wolf , sheepdog@lists.wpkg.org, Hitoshi Mitake , Jeff Cody , qemu-devel@nongnu.org, Max Reitz , Liu Yuan 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" Instead of expecting the current size to be 0, query it and allocate only the area [current_size, offset) if preallocation is requested. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/gluster.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 8178541416..806b894bc8 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -968,10 +968,27 @@ static coroutine_fn int qemu_gluster_co_pwrite_zeroes= (BlockDriverState *bs, static int qemu_gluster_do_truncate(struct glfs_fd *fd, int64_t offset, PreallocMode prealloc, Error **errp) { + int64_t current_length; + + current_length =3D glfs_lseek(fd, 0, SEEK_END); + if (current_length < 0) { + error_setg_errno(errp, errno, "Failed to determine current size"); + return -errno; + } + + if (current_length > offset && prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Cannot use preallocation for shrinking files"); + return -ENOTSUP; + } + + if (current_length =3D=3D offset) { + return 0; + } + switch (prealloc) { #ifdef CONFIG_GLUSTERFS_FALLOCATE case PREALLOC_MODE_FALLOC: - if (glfs_fallocate(fd, 0, 0, offset)) { + if (glfs_fallocate(fd, 0, current_length, offset - current_length)= ) { error_setg_errno(errp, errno, "Could not preallocate data"); return -errno; } @@ -983,7 +1000,7 @@ static int qemu_gluster_do_truncate(struct glfs_fd *fd= , int64_t offset, error_setg_errno(errp, errno, "Could not resize file"); return -errno; } - if (glfs_zerofill(fd, 0, offset)) { + if (glfs_zerofill(fd, current_length, offset - current_length)) { error_setg_errno(errp, errno, "Could not zerofill the new area= "); return -errno; } --=20 2.14.3 From nobody Thu May 2 19:05:37 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518527900772823.8375674293851; Tue, 13 Feb 2018 05:18:20 -0800 (PST) Received: from localhost ([::1]:56937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaTN-0002nr-Uc for importer@patchew.org; Tue, 13 Feb 2018 08:18:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaFq-0007Yb-34 for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elaFp-0006SK-80 for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:14 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50086 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elaFl-0006P4-Rt; Tue, 13 Feb 2018 08:04:09 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6816040FB645; Tue, 13 Feb 2018 13:04:09 +0000 (UTC) Received: from localhost (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 245402166BB3; Tue, 13 Feb 2018 13:04:09 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 13 Feb 2018 14:03:53 +0100 Message-Id: <20180213130356.8885-5-mreitz@redhat.com> In-Reply-To: <20180213130356.8885-1-mreitz@redhat.com> References: <20180213130356.8885-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Feb 2018 13:04:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Feb 2018 13:04:09 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 4/7] gluster: Add preallocated truncation 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: Kevin Wolf , sheepdog@lists.wpkg.org, Hitoshi Mitake , Jeff Cody , qemu-devel@nongnu.org, Max Reitz , Liu Yuan 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" By using qemu_do_cluster_truncate() in qemu_cluster_truncate(), we now automatically have preallocated truncation. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/gluster.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 806b894bc8..3f17b7819d 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1122,23 +1122,8 @@ static coroutine_fn int qemu_gluster_co_rw(BlockDriv= erState *bs, static int qemu_gluster_truncate(BlockDriverState *bs, int64_t offset, PreallocMode prealloc, Error **errp) { - int ret; BDRVGlusterState *s =3D bs->opaque; - - if (prealloc !=3D PREALLOC_MODE_OFF) { - error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_str(prealloc)); - return -ENOTSUP; - } - - ret =3D glfs_ftruncate(s->fd, offset); - if (ret < 0) { - ret =3D -errno; - error_setg_errno(errp, -ret, "Failed to truncate file"); - return ret; - } - - return 0; + return qemu_gluster_do_truncate(s->fd, offset, prealloc, errp); } =20 static coroutine_fn int qemu_gluster_co_readv(BlockDriverState *bs, --=20 2.14.3 From nobody Thu May 2 19:05:37 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518527756220723.4787423253114; Tue, 13 Feb 2018 05:15:56 -0800 (PST) Received: from localhost ([::1]:56715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaQz-0000z6-VP for importer@patchew.org; Tue, 13 Feb 2018 08:15:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaFz-0007iO-0R for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elaFv-0006Zn-1d for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:22 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50092 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elaFn-0006QA-DY; Tue, 13 Feb 2018 08:04:11 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0476E40FB646; Tue, 13 Feb 2018 13:04:11 +0000 (UTC) Received: from localhost (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A9DDA2026DFD; Tue, 13 Feb 2018 13:04:10 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 13 Feb 2018 14:03:54 +0100 Message-Id: <20180213130356.8885-6-mreitz@redhat.com> In-Reply-To: <20180213130356.8885-1-mreitz@redhat.com> References: <20180213130356.8885-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Feb 2018 13:04:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 13 Feb 2018 13:04:11 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 5/7] sheepdog: Make sd_prealloc() take a BDS 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: Kevin Wolf , sheepdog@lists.wpkg.org, Hitoshi Mitake , Jeff Cody , qemu-devel@nongnu.org, Max Reitz , Liu Yuan 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" We want to use this function in sd_truncate() later on, so taking a filename is not exactly ideal. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/sheepdog.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index af125a2c8d..cc1d37b3da 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1826,10 +1826,10 @@ static int do_sd_create(BDRVSheepdogState *s, uint3= 2_t *vdi_id, int snapshot, return 0; } =20 -static int sd_prealloc(const char *filename, Error **errp) +static int sd_prealloc(BlockDriverState *bs, Error **errp) { BlockBackend *blk =3D NULL; - BDRVSheepdogState *base =3D NULL; + BDRVSheepdogState *base =3D bs->opaque; unsigned long buf_size; uint32_t idx, max_idx; uint32_t object_size; @@ -1837,10 +1837,11 @@ static int sd_prealloc(const char *filename, Error = **errp) void *buf =3D NULL; int ret; =20 - blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, errp= ); - if (blk =3D=3D NULL) { - ret =3D -EIO; + blk =3D blk_new(BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | BLK_PERM_R= ESIZE, + BLK_PERM_ALL); + + ret =3D blk_insert_bs(blk, bs, errp); + if (ret < 0) { goto out_with_err_set; } =20 @@ -1852,7 +1853,6 @@ static int sd_prealloc(const char *filename, Error **= errp) goto out; } =20 - base =3D blk_bs(blk)->opaque; object_size =3D (UINT32_C(1) << base->inode.block_size_shift); buf_size =3D MIN(object_size, SD_DATA_OBJ_SIZE); buf =3D g_malloc0(buf_size); @@ -2108,7 +2108,20 @@ static int sd_create(const char *filename, QemuOpts = *opts, } =20 if (prealloc) { - ret =3D sd_prealloc(filename, errp); + BlockDriverState *bs; + QDict *opts; + + opts =3D qdict_new(); + qdict_put_str(opts, "driver", "sheepdog"); + bs =3D bdrv_open(filename, NULL, opts, BDRV_O_PROTOCOL | BDRV_O_RD= WR, + errp); + if (!bs) { + goto out; + } + + ret =3D sd_prealloc(bs, errp); + + bdrv_unref(bs); } out: g_free(backing_file); --=20 2.14.3 From nobody Thu May 2 19:05:37 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518528167280349.75876377785653; Tue, 13 Feb 2018 05:22:47 -0800 (PST) Received: from localhost ([::1]:58460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaXm-0007Oz-3l for importer@patchew.org; Tue, 13 Feb 2018 08:22:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaG0-0007kS-8L for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elaFz-0006hy-54 for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:24 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41484 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elaFp-0006Rg-0b; Tue, 13 Feb 2018 08:04:13 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B980EB6ED; Tue, 13 Feb 2018 13:04:12 +0000 (UTC) Received: from localhost (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 446F5B0790; Tue, 13 Feb 2018 13:04:12 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 13 Feb 2018 14:03:55 +0100 Message-Id: <20180213130356.8885-7-mreitz@redhat.com> In-Reply-To: <20180213130356.8885-1-mreitz@redhat.com> References: <20180213130356.8885-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Feb 2018 13:04:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Feb 2018 13:04:12 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 6/7] sheepdog: Pass old and new size to sd_prealloc() 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: Kevin Wolf , sheepdog@lists.wpkg.org, Hitoshi Mitake , Jeff Cody , qemu-devel@nongnu.org, Max Reitz , Liu Yuan 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" sd_prealloc() will now preallocate the area [old_size, new_size). As before, it rounds to buf_size and may thus overshoot and preallocate areas that were not requested to be preallocated. For image creation, this is no change in behavior. For truncation, this is in accordance with the documentation for preallocated truncation. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/sheepdog.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index cc1d37b3da..d300fb69c0 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1826,14 +1826,14 @@ static int do_sd_create(BDRVSheepdogState *s, uint3= 2_t *vdi_id, int snapshot, return 0; } =20 -static int sd_prealloc(BlockDriverState *bs, Error **errp) +static int sd_prealloc(BlockDriverState *bs, int64_t old_size, int64_t new= _size, + Error **errp) { BlockBackend *blk =3D NULL; BDRVSheepdogState *base =3D bs->opaque; unsigned long buf_size; uint32_t idx, max_idx; uint32_t object_size; - int64_t vdi_size; void *buf =3D NULL; int ret; =20 @@ -1847,19 +1847,13 @@ static int sd_prealloc(BlockDriverState *bs, Error = **errp) =20 blk_set_allow_write_beyond_eof(blk, true); =20 - vdi_size =3D blk_getlength(blk); - if (vdi_size < 0) { - ret =3D vdi_size; - goto out; - } - object_size =3D (UINT32_C(1) << base->inode.block_size_shift); buf_size =3D MIN(object_size, SD_DATA_OBJ_SIZE); buf =3D g_malloc0(buf_size); =20 - max_idx =3D DIV_ROUND_UP(vdi_size, buf_size); + max_idx =3D DIV_ROUND_UP(new_size, buf_size); =20 - for (idx =3D 0; idx < max_idx; idx++) { + for (idx =3D old_size / buf_size; idx < max_idx; idx++) { /* * The created image can be a cloned image, so we need to read * a data from the source image. @@ -2119,7 +2113,7 @@ static int sd_create(const char *filename, QemuOpts *= opts, goto out; } =20 - ret =3D sd_prealloc(bs, errp); + ret =3D sd_prealloc(bs, 0, s->inode.vdi_size, errp); =20 bdrv_unref(bs); } --=20 2.14.3 From nobody Thu May 2 19:05:37 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518527533828887.2467760312736; Tue, 13 Feb 2018 05:12:13 -0800 (PST) Received: from localhost ([::1]:56392 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaNU-0006FA-N0 for importer@patchew.org; Tue, 13 Feb 2018 08:12:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elaFz-0007iV-1t for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elaFv-0006b6-G9 for qemu-devel@nongnu.org; Tue, 13 Feb 2018 08:04:22 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33354 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elaFq-0006T2-Iu; Tue, 13 Feb 2018 08:04:14 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2778A818532A; Tue, 13 Feb 2018 13:04:14 +0000 (UTC) Received: from localhost (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6F111008570; Tue, 13 Feb 2018 13:04:13 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 13 Feb 2018 14:03:56 +0100 Message-Id: <20180213130356.8885-8-mreitz@redhat.com> In-Reply-To: <20180213130356.8885-1-mreitz@redhat.com> References: <20180213130356.8885-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 13 Feb 2018 13:04:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 13 Feb 2018 13:04:14 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 7/7] sheepdog: Allow fully preallocated truncation 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: Kevin Wolf , sheepdog@lists.wpkg.org, Hitoshi Mitake , Jeff Cody , qemu-devel@nongnu.org, Max Reitz , Liu Yuan 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" Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/sheepdog.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index d300fb69c0..ac02b10fe0 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2180,15 +2180,16 @@ static int sd_truncate(BlockDriverState *bs, int64_= t offset, int ret, fd; unsigned int datalen; uint64_t max_vdi_size; + int64_t old_size =3D s->inode.vdi_size; =20 - if (prealloc !=3D PREALLOC_MODE_OFF) { + if (prealloc !=3D PREALLOC_MODE_OFF && prealloc !=3D PREALLOC_MODE_FUL= L) { error_setg(errp, "Unsupported preallocation mode '%s'", PreallocMode_str(prealloc)); return -ENOTSUP; } =20 max_vdi_size =3D (UINT64_C(1) << s->inode.block_size_shift) * MAX_DATA= _OBJS; - if (offset < s->inode.vdi_size) { + if (offset < old_size) { error_setg(errp, "shrinking is not supported"); return -EINVAL; } else if (offset > max_vdi_size) { @@ -2211,9 +2212,17 @@ static int sd_truncate(BlockDriverState *bs, int64_t= offset, =20 if (ret < 0) { error_setg_errno(errp, -ret, "failed to update an inode"); + return ret; } =20 - return ret; + if (prealloc =3D=3D PREALLOC_MODE_FULL) { + ret =3D sd_prealloc(bs, old_size, offset, errp); + if (ret < 0) { + return ret; + } + } + + return 0; } =20 /* --=20 2.14.3