From nobody Fri Apr 11 16:01:58 2025 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 1493412742216365.431878634686; Fri, 28 Apr 2017 13:52:22 -0700 (PDT) Received: from localhost ([::1]:38802 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4CsG-00006F-Rj for importer@patchew.org; Fri, 28 Apr 2017 16:52:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4CbN-00027u-Kq for qemu-devel@nongnu.org; Fri, 28 Apr 2017 16:34:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4CbM-0001Ul-CP for qemu-devel@nongnu.org; Fri, 28 Apr 2017 16:34:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44090) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d4CbH-0001Rc-3c; Fri, 28 Apr 2017 16:34:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A07DD3C2B; Fri, 28 Apr 2017 20:34:46 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-227.ams2.redhat.com [10.36.117.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB50A96518; Fri, 28 Apr 2017 20:34:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1A07DD3C2B Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1A07DD3C2B From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 28 Apr 2017 22:33:34 +0200 Message-Id: <1493411622-5343-27-git-send-email-kwolf@redhat.com> In-Reply-To: <1493411622-5343-1-git-send-email-kwolf@redhat.com> References: <1493411622-5343-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 28 Apr 2017 20:34:46 +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 26/34] block: Add .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: kwolf@redhat.com, qemu-devel@nongnu.org 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" From: Max Reitz Add missing error messages for the block driver implementations of .bdrv_truncate(); drop the generic one from block.c's bdrv_truncate(). 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 Message-id: 20170328205129.15138-5-mreitz@redhat.com Reviewed-by: Stefan Hajnoczi Signed-off-by: Max Reitz --- block.c | 2 -- block/file-posix.c | 17 ++++++++++++----- block/gluster.c | 4 +++- block/iscsi.c | 2 ++ block/nfs.c | 10 +++++++++- block/qcow2.c | 2 ++ block/qed.c | 4 +++- block/raw-format.c | 2 ++ block/rbd.c | 1 + 9 files changed, 34 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index ff232a2..76bf00f 100644 --- a/block.c +++ b/block.c @@ -3334,8 +3334,6 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, E= rror **errp) bdrv_dirty_bitmap_truncate(bs); bdrv_parent_cb_resize(bs); ++bs->write_gen; - } else if (errp && !*errp) { - error_setg_errno(errp, -ret, "Failed to resize image"); } return ret; } diff --git a/block/file-posix.c b/block/file-posix.c index 9c0d701..1941fb6 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1411,20 +1411,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/gluster.c b/block/gluster.c index be45c08..1d4e2f7 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1100,7 +1100,9 @@ static int qemu_gluster_truncate(BlockDriverState *bs= , int64_t offset, =20 ret =3D glfs_ftruncate(s->fd, offset); if (ret < 0) { - return -errno; + ret =3D -errno; + error_setg_errno(errp, -ret, "Failed to truncate file"); + return ret; } =20 return 0; diff --git a/block/iscsi.c b/block/iscsi.c index 1ef38cf..5daa201 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2065,6 +2065,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64= _t offset, Error **errp) Error *local_err =3D NULL; =20 if (iscsilun->type !=3D TYPE_DISK) { + error_setg(errp, "Cannot resize non-disk iSCSI devices"); return -ENOTSUP; } =20 @@ -2075,6 +2076,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64= _t offset, Error **errp) } =20 if (offset > iscsi_getlength(bs)) { + error_setg(errp, "Cannot grow iSCSI devices"); return -EINVAL; } =20 diff --git a/block/nfs.c b/block/nfs.c index 5ae665a..76572ae 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -767,7 +767,15 @@ static int64_t nfs_get_allocated_file_size(BlockDriver= State *bs) static int nfs_file_truncate(BlockDriverState *bs, int64_t offset, Error *= *errp) { NFSClient *client =3D bs->opaque; - return nfs_ftruncate(client->context, client->fh, offset); + int ret; + + ret =3D nfs_ftruncate(client->context, client->fh, offset); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to truncate file"); + return ret; + } + + return 0; } =20 /* Note that this will not re-establish a connection with the NFS server diff --git a/block/qcow2.c b/block/qcow2.c index 6c34798..4ca4cf0 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2551,6 +2551,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_errno(errp, -ret, "Failed to grow the L1 table"); return ret; } =20 @@ -2559,6 +2560,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_errno(errp, -ret, "Failed to update the image size"); return ret; } =20 diff --git a/block/qed.c b/block/qed.c index fa2aeee..fd76817 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_errno(errp, -ret, "Failed to update the image size"); } return ret; } diff --git a/block/raw-format.c b/block/raw-format.c index 9761bda..36e6503 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 diff --git a/block/rbd.c b/block/rbd.c index 3e6e73e..fbf3059 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -923,6 +923,7 @@ static int qemu_rbd_truncate(BlockDriverState *bs, int6= 4_t offset, Error **errp) =20 r =3D rbd_resize(s->image, offset); if (r < 0) { + error_setg_errno(errp, -r, "Failed to resize file"); return r; } =20 --=20 1.8.3.1