From nobody Fri Apr 11 15:57:59 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 1493412982437999.1589865256028; Fri, 28 Apr 2017 13:56:22 -0700 (PDT) Received: from localhost ([::1]:38827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4Cw9-0003gn-1Z for importer@patchew.org; Fri, 28 Apr 2017 16:56:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4CbO-00028M-4z for qemu-devel@nongnu.org; Fri, 28 Apr 2017 16:34:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4CbM-0001Uq-Dc for qemu-devel@nongnu.org; Fri, 28 Apr 2017 16:34:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37396) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d4CbF-0001QL-Nc; Fri, 28 Apr 2017 16:34:45 -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 723F3C00861F; Fri, 28 Apr 2017 20:34:44 +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 D4AC69533F; Fri, 28 Apr 2017 20:34:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 723F3C00861F Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 723F3C00861F From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 28 Apr 2017 22:33:33 +0200 Message-Id: <1493411622-5343-26-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.32]); Fri, 28 Apr 2017 20:34:44 +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 25/34] block: Add errp to BD.bdrv_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: 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 an Error parameter to the block drivers' bdrv_truncate() interface. If a block driver does not set this in case of an error, the generic bdrv_truncate() implementation will do so. Where it is obvious, this patch also makes some block drivers set this value. Signed-off-by: Max Reitz Message-id: 20170328205129.15138-4-mreitz@redhat.com Reviewed-by: Stefan Hajnoczi Signed-off-by: Max Reitz --- block.c | 4 ++-- block/blkdebug.c | 4 ++-- block/crypto.c | 5 +++-- block/file-posix.c | 2 +- block/file-win32.c | 6 +++--- block/gluster.c | 3 ++- block/iscsi.c | 4 ++-- block/nfs.c | 2 +- block/qcow2.c | 8 ++++---- block/qed.c | 2 +- block/raw-format.c | 4 ++-- block/rbd.c | 2 +- block/sheepdog.c | 14 ++++++-------- include/block/block_int.h | 2 +- 14 files changed, 31 insertions(+), 31 deletions(-) diff --git a/block.c b/block.c index 6a1937e..ff232a2 100644 --- a/block.c +++ b/block.c @@ -3328,13 +3328,13 @@ int bdrv_truncate(BdrvChild *child, int64_t offset,= Error **errp) return -EACCES; } =20 - ret =3D drv->bdrv_truncate(bs, offset); + ret =3D drv->bdrv_truncate(bs, offset, errp); if (ret =3D=3D 0) { ret =3D refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); bdrv_dirty_bitmap_truncate(bs); bdrv_parent_cb_resize(bs); ++bs->write_gen; - } else { + } else if (errp && !*errp) { error_setg_errno(errp, -ret, "Failed to resize image"); } return ret; diff --git a/block/blkdebug.c b/block/blkdebug.c index 9bd066e..d2a7561 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -659,9 +659,9 @@ static int64_t blkdebug_getlength(BlockDriverState *bs) return bdrv_getlength(bs->file->bs); } =20 -static int blkdebug_truncate(BlockDriverState *bs, int64_t offset) +static int blkdebug_truncate(BlockDriverState *bs, int64_t offset, Error *= *errp) { - return bdrv_truncate(bs->file, offset, NULL); + return bdrv_truncate(bs->file, offset, errp); } =20 static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) diff --git a/block/crypto.c b/block/crypto.c index 7ad64b5..6828180 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -381,7 +381,8 @@ static int block_crypto_create_generic(QCryptoBlockForm= at format, return ret; } =20 -static int block_crypto_truncate(BlockDriverState *bs, int64_t offset) +static int block_crypto_truncate(BlockDriverState *bs, int64_t offset, + Error **errp) { BlockCrypto *crypto =3D bs->opaque; size_t payload_offset =3D @@ -389,7 +390,7 @@ static int block_crypto_truncate(BlockDriverState *bs, = int64_t offset) =20 offset +=3D payload_offset; =20 - return bdrv_truncate(bs->file, offset, NULL); + return bdrv_truncate(bs->file, offset, errp); } =20 static void block_crypto_close(BlockDriverState *bs) diff --git a/block/file-posix.c b/block/file-posix.c index ade71db..9c0d701 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1407,7 +1407,7 @@ static void raw_close(BlockDriverState *bs) } } =20 -static int raw_truncate(BlockDriverState *bs, int64_t offset) +static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp) { BDRVRawState *s =3D bs->opaque; struct stat st; diff --git a/block/file-win32.c b/block/file-win32.c index e132ba1..7872e00 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -460,7 +460,7 @@ static void raw_close(BlockDriverState *bs) } } =20 -static int raw_truncate(BlockDriverState *bs, int64_t offset) +static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp) { BDRVRawState *s =3D bs->opaque; LONG low, high; @@ -475,11 +475,11 @@ static int raw_truncate(BlockDriverState *bs, int64_t= offset) */ dwPtrLow =3D SetFilePointer(s->hfile, low, &high, FILE_BEGIN); if (dwPtrLow =3D=3D INVALID_SET_FILE_POINTER && GetLastError() !=3D NO= _ERROR) { - fprintf(stderr, "SetFilePointer error: %lu\n", GetLastError()); + error_setg_win32(errp, GetLastError(), "SetFilePointer error"); return -EIO; } if (SetEndOfFile(s->hfile) =3D=3D 0) { - fprintf(stderr, "SetEndOfFile error: %lu\n", GetLastError()); + error_setg_win32(errp, GetLastError(), "SetEndOfFile error"); return -EIO; } return 0; diff --git a/block/gluster.c b/block/gluster.c index cf29b5f..be45c08 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1092,7 +1092,8 @@ static coroutine_fn int qemu_gluster_co_rw(BlockDrive= rState *bs, return acb.ret; } =20 -static int qemu_gluster_truncate(BlockDriverState *bs, int64_t offset) +static int qemu_gluster_truncate(BlockDriverState *bs, int64_t offset, + Error **errp) { int ret; BDRVGlusterState *s =3D bs->opaque; diff --git a/block/iscsi.c b/block/iscsi.c index 42fb0b0..1ef38cf 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2059,7 +2059,7 @@ static void iscsi_reopen_commit(BDRVReopenState *reop= en_state) } } =20 -static int iscsi_truncate(BlockDriverState *bs, int64_t offset) +static int iscsi_truncate(BlockDriverState *bs, int64_t offset, Error **er= rp) { IscsiLun *iscsilun =3D bs->opaque; Error *local_err =3D NULL; @@ -2070,7 +2070,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64= _t offset) =20 iscsi_readcapacity_sync(iscsilun, &local_err); if (local_err !=3D NULL) { - error_free(local_err); + error_propagate(errp, local_err); return -EIO; } =20 diff --git a/block/nfs.c b/block/nfs.c index 6541dec..5ae665a 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -764,7 +764,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverS= tate *bs) return (task.ret < 0 ? task.ret : st.st_blocks * 512); } =20 -static int nfs_file_truncate(BlockDriverState *bs, int64_t offset) +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); diff --git a/block/qcow2.c b/block/qcow2.c index 845eee4..6c34798 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2525,26 +2525,26 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriv= erState *bs, return ret; } =20 -static int qcow2_truncate(BlockDriverState *bs, int64_t offset) +static int qcow2_truncate(BlockDriverState *bs, int64_t offset, Error **er= rp) { BDRVQcow2State *s =3D bs->opaque; int64_t new_l1_size; int ret; =20 if (offset & 511) { - error_report("The new size must be a multiple of 512"); + error_setg(errp, "The new size must be a multiple of 512"); return -EINVAL; } =20 /* cannot proceed if image has snapshots */ if (s->nb_snapshots) { - error_report("Can't resize an image which has snapshots"); + error_setg(errp, "Can't resize an image which has snapshots"); return -ENOTSUP; } =20 /* shrinking is currently not supported */ if (offset < bs->total_sectors * 512) { - error_report("qcow2 doesn't support shrinking images yet"); + error_setg(errp, "qcow2 doesn't support shrinking images yet"); return -ENOTSUP; } =20 diff --git a/block/qed.c b/block/qed.c index 53199ac..fa2aeee 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1518,7 +1518,7 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(Blo= ckDriverState *bs, return cb.ret; } =20 -static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset) +static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset, Error *= *errp) { BDRVQEDState *s =3D bs->opaque; uint64_t old_image_size; diff --git a/block/raw-format.c b/block/raw-format.c index a800733..9761bda 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -327,7 +327,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Er= ror **errp) } } =20 -static int raw_truncate(BlockDriverState *bs, int64_t offset) +static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp) { BDRVRawState *s =3D bs->opaque; =20 @@ -341,7 +341,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t o= ffset) =20 s->size =3D offset; offset +=3D s->offset; - return bdrv_truncate(bs->file, offset, NULL); + return bdrv_truncate(bs->file, offset, errp); } =20 static int raw_media_changed(BlockDriverState *bs) diff --git a/block/rbd.c b/block/rbd.c index 6471f4f..3e6e73e 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -916,7 +916,7 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs) return info.size; } =20 -static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset) +static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset, Error *= *errp) { BDRVRBDState *s =3D bs->opaque; int r; diff --git a/block/sheepdog.c b/block/sheepdog.c index b2a5998..fe8fd92 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2159,9 +2159,8 @@ static int64_t sd_getlength(BlockDriverState *bs) return s->inode.vdi_size; } =20 -static int sd_truncate(BlockDriverState *bs, int64_t offset) +static int sd_truncate(BlockDriverState *bs, int64_t offset, Error **errp) { - Error *local_err =3D NULL; BDRVSheepdogState *s =3D bs->opaque; int ret, fd; unsigned int datalen; @@ -2169,16 +2168,15 @@ static int sd_truncate(BlockDriverState *bs, int64_= t offset) =20 max_vdi_size =3D (UINT64_C(1) << s->inode.block_size_shift) * MAX_DATA= _OBJS; if (offset < s->inode.vdi_size) { - error_report("shrinking is not supported"); + error_setg(errp, "shrinking is not supported"); return -EINVAL; } else if (offset > max_vdi_size) { - error_report("too big image size"); + error_setg(errp, "too big image size"); return -EINVAL; } =20 - fd =3D connect_to_sdog(s, &local_err); + fd =3D connect_to_sdog(s, errp); if (fd < 0) { - error_report_err(local_err); return fd; } =20 @@ -2191,7 +2189,7 @@ static int sd_truncate(BlockDriverState *bs, int64_t = offset) close(fd); =20 if (ret < 0) { - error_report("failed to update an inode."); + error_setg_errno(errp, -ret, "failed to update an inode"); } =20 return ret; @@ -2456,7 +2454,7 @@ static coroutine_fn int sd_co_writev(BlockDriverState= *bs, int64_t sector_num, BDRVSheepdogState *s =3D bs->opaque; =20 if (offset > s->inode.vdi_size) { - ret =3D sd_truncate(bs, offset); + ret =3D sd_truncate(bs, offset, NULL); if (ret < 0) { return ret; } diff --git a/include/block/block_int.h b/include/block/block_int.h index 4f8cd29..dcde90a 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -196,7 +196,7 @@ struct BlockDriver { int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs); =20 const char *protocol_name; - int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset); + int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset, Error **err= p); =20 int64_t (*bdrv_getlength)(BlockDriverState *bs); bool has_variable_length; --=20 1.8.3.1