From nobody Mon Feb 9 13:57:10 2026 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 1489000706411201.51873762051025; Wed, 8 Mar 2017 11:18:26 -0800 (PST) Received: from localhost ([::1]:58027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clh6N-00054I-PY for importer@patchew.org; Wed, 08 Mar 2017 14:18:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clh42-0003yN-Sz for qemu-devel@nongnu.org; Wed, 08 Mar 2017 14:16:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clh41-0008KS-9c for qemu-devel@nongnu.org; Wed, 08 Mar 2017 14:15:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41386) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clh3x-0008I2-2C; Wed, 08 Mar 2017 14:15:53 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4DCAEC04D2B4; Wed, 8 Mar 2017 19:15:53 +0000 (UTC) Received: from localhost (ovpn-204-172.brq.redhat.com [10.40.204.172]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v28JFn6E006626 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 8 Mar 2017 14:15:51 -0500 From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 8 Mar 2017 20:15:44 +0100 Message-Id: <20170308191544.3025-2-mreitz@redhat.com> In-Reply-To: <20170308191434.2413-1-mreitz@redhat.com> References: <20170308191434.2413-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Mar 2017 19:15:53 +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 v2 for-2.10 4/4] block: Add some bdrv_truncate() error messages 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 , qemu-devel@nongnu.org, Max Reitz 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 error messages for the drivers I am comfortable to do this in. Since one of these changes touches a mis-indented block in block/file-posix.c, this patch fixes that coding style issue along the way. Signed-off-by: Max Reitz --- block/file-posix.c | 17 ++++++++++++----- block/qcow2.c | 2 ++ block/qed.c | 4 +++- block/raw-format.c | 2 ++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 9d2bea730d..013aa07437 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1341,20 +1341,27 @@ static int raw_truncate(BlockDriverState *bs, int64= _t offset, Error **errp) { BDRVRawState *s =3D bs->opaque; struct stat st; + int ret; =20 if (fstat(s->fd, &st)) { - return -errno; + ret =3D -errno; + error_setg_errno(errp, -ret, "Failed to fstat() the file"); + return ret; } =20 if (S_ISREG(st.st_mode)) { if (ftruncate(s->fd, offset) < 0) { - return -errno; + ret =3D -errno; + error_setg_errno(errp, -ret, "Failed to resize the file"); + return ret; } } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { - if (offset > raw_getlength(bs)) { - return -EINVAL; - } + if (offset > raw_getlength(bs)) { + error_setg(errp, "Cannot grow device files"); + return -EINVAL; + } } else { + error_setg(errp, "Resizing this file is not supported"); return -ENOTSUP; } =20 diff --git a/block/qcow2.c b/block/qcow2.c index 17585fbb89..53b0bd61a7 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2550,6 +2550,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, Error **errp) new_l1_size =3D size_to_l1(s, offset); ret =3D qcow2_grow_l1_table(bs, new_l1_size, true); if (ret < 0) { + error_setg(errp, "Failed to grow the L1 table"); return ret; } =20 @@ -2558,6 +2559,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, Error **errp) ret =3D bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size), &offset, sizeof(uint64_t)); if (ret < 0) { + error_setg(errp, "Failed to update the image size"); return ret; } =20 diff --git a/block/qed.c b/block/qed.c index fa2aeee471..eb346d645b 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1526,11 +1526,12 @@ static int bdrv_qed_truncate(BlockDriverState *bs, = int64_t offset, Error **errp) =20 if (!qed_is_image_size_valid(offset, s->header.cluster_size, s->header.table_size)) { + error_setg(errp, "Invalid image size specified"); return -EINVAL; } =20 - /* Shrinking is currently not supported */ if ((uint64_t)offset < s->header.image_size) { + error_setg(errp, "Shrinking images is currently not supported"); return -ENOTSUP; } =20 @@ -1539,6 +1540,7 @@ static int bdrv_qed_truncate(BlockDriverState *bs, in= t64_t offset, Error **errp) ret =3D qed_write_header_sync(s); if (ret < 0) { s->header.image_size =3D old_image_size; + error_setg(errp, "Failed to update the image size"); } return ret; } diff --git a/block/raw-format.c b/block/raw-format.c index 9761bdaff8..36e65036f0 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -332,10 +332,12 @@ static int raw_truncate(BlockDriverState *bs, int64_t= offset, Error **errp) BDRVRawState *s =3D bs->opaque; =20 if (s->has_size) { + error_setg(errp, "Cannot resize fixed-size raw disks"); return -ENOTSUP; } =20 if (INT64_MAX - offset < s->offset) { + error_setg(errp, "Disk size too large for the chosen offset"); return -EINVAL; } =20 --=20 2.12.0