From nobody Tue Feb 10 19:47:55 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.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511277420671407.0672586374553; Tue, 21 Nov 2017 07:17:00 -0800 (PST) Received: from localhost ([::1]:35039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHAI6-0000rv-Rm for importer@patchew.org; Tue, 21 Nov 2017 10:16:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHAC9-0003CJ-9r for qemu-devel@nongnu.org; Tue, 21 Nov 2017 10:10:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eHAC3-0005Dy-8G for qemu-devel@nongnu.org; Tue, 21 Nov 2017 10:10:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48516) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eHABx-00058o-6m; Tue, 21 Nov 2017 10:10:29 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76CB7C059752; Tue, 21 Nov 2017 15:10:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-148.ams2.redhat.com [10.36.117.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id A11E77A1E6; Tue, 21 Nov 2017 15:10:26 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Nov 2017 16:10:13 +0100 Message-Id: <20171121151017.28158-4-kwolf@redhat.com> In-Reply-To: <20171121151017.28158-1-kwolf@redhat.com> References: <20171121151017.28158-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 21 Nov 2017 15:10:28 +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 3/7] block: Add errp to bdrv_snapshot_goto() 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, peter.maydell@linaro.org, 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" Signed-off-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow --- include/block/snapshot.h | 3 ++- block/snapshot.c | 23 +++++++++++++++++------ qemu-img.c | 6 +++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/block/snapshot.h b/include/block/snapshot.h index e5c0553115..aeb80405e8 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -57,7 +57,8 @@ int bdrv_can_snapshot(BlockDriverState *bs); int bdrv_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info); int bdrv_snapshot_goto(BlockDriverState *bs, - const char *snapshot_id); + const char *snapshot_id, + Error **errp); int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id, const char *name, diff --git a/block/snapshot.c b/block/snapshot.c index be0743abac..75562df4cc 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -177,18 +177,21 @@ int bdrv_snapshot_create(BlockDriverState *bs, } =20 int bdrv_snapshot_goto(BlockDriverState *bs, - const char *snapshot_id) + const char *snapshot_id, + Error **errp) { BlockDriver *drv =3D bs->drv; int ret, open_ret; int64_t len; =20 if (!drv) { + error_setg(errp, "Block driver is closed"); return -ENOMEDIUM; } =20 len =3D bdrv_getlength(bs); if (len < 0) { + error_setg_errno(errp, -len, "Cannot get block device size"); return len; } /* We should set all bits in all enabled dirty bitmaps, because dirty @@ -200,13 +203,18 @@ int bdrv_snapshot_goto(BlockDriverState *bs, bdrv_set_dirty(bs, 0, len); =20 if (drv->bdrv_snapshot_goto) { - return drv->bdrv_snapshot_goto(bs, snapshot_id); + ret =3D drv->bdrv_snapshot_goto(bs, snapshot_id); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to load snapshot"); + } + return ret; } =20 if (bs->file) { BlockDriverState *file; QDict *options =3D qdict_clone_shallow(bs->options); QDict *file_options; + Error *local_err =3D NULL; =20 file =3D bs->file->bs; /* Prevent it from getting deleted when detached from bs */ @@ -220,13 +228,15 @@ int bdrv_snapshot_goto(BlockDriverState *bs, bdrv_unref_child(bs, bs->file); bs->file =3D NULL; =20 - ret =3D bdrv_snapshot_goto(file, snapshot_id); - open_ret =3D drv->bdrv_open(bs, options, bs->open_flags, NULL); + ret =3D bdrv_snapshot_goto(file, snapshot_id, errp); + open_ret =3D drv->bdrv_open(bs, options, bs->open_flags, &local_er= r); QDECREF(options); if (open_ret < 0) { bdrv_unref(file); bs->drv =3D NULL; - return open_ret; + /* A bdrv_snapshot_goto() error takes precedence */ + error_propagate(errp, local_err); + return ret < 0 ? ret : open_ret; } =20 assert(bs->file->bs =3D=3D file); @@ -234,6 +244,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs, return ret; } =20 + error_setg(errp, "Block driver does not support snapshots"); return -ENOTSUP; } =20 @@ -467,7 +478,7 @@ int bdrv_all_goto_snapshot(const char *name, BlockDrive= rState **first_bad_bs) =20 aio_context_acquire(ctx); if (bdrv_can_snapshot(bs)) { - err =3D bdrv_snapshot_goto(bs, name); + err =3D bdrv_snapshot_goto(bs, name, NULL); } aio_context_release(ctx); if (err < 0) { diff --git a/qemu-img.c b/qemu-img.c index 02a6e27beb..68b375f998 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2989,10 +2989,10 @@ static int img_snapshot(int argc, char **argv) break; =20 case SNAPSHOT_APPLY: - ret =3D bdrv_snapshot_goto(bs, snapshot_name); + ret =3D bdrv_snapshot_goto(bs, snapshot_name, &err); if (ret) { - error_report("Could not apply snapshot '%s': %d (%s)", - snapshot_name, ret, strerror(-ret)); + error_reportf_err(err, "Could not apply snapshot '%s': ", + snapshot_name); } break; =20 --=20 2.13.6