From patchwork Tue Nov 21 15:10:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 840091 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yh8Lb3j23z9s72 for ; Wed, 22 Nov 2017 02:16:23 +1100 (AEDT) Received: from localhost ([::1]:35032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHAHd-0000NH-Lr for incoming@patchwork.ozlabs.org; Tue, 21 Nov 2017 10:16:21 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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, } int bdrv_snapshot_goto(BlockDriverState *bs, - const char *snapshot_id) + const char *snapshot_id, + Error **errp) { BlockDriver *drv = bs->drv; int ret, open_ret; int64_t len; if (!drv) { + error_setg(errp, "Block driver is closed"); return -ENOMEDIUM; } len = 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); if (drv->bdrv_snapshot_goto) { - return drv->bdrv_snapshot_goto(bs, snapshot_id); + ret = drv->bdrv_snapshot_goto(bs, snapshot_id); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to load snapshot"); + } + return ret; } if (bs->file) { BlockDriverState *file; QDict *options = qdict_clone_shallow(bs->options); QDict *file_options; + Error *local_err = NULL; file = 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 = NULL; - ret = bdrv_snapshot_goto(file, snapshot_id); - open_ret = drv->bdrv_open(bs, options, bs->open_flags, NULL); + ret = bdrv_snapshot_goto(file, snapshot_id, errp); + open_ret = drv->bdrv_open(bs, options, bs->open_flags, &local_err); QDECREF(options); if (open_ret < 0) { bdrv_unref(file); bs->drv = NULL; - return open_ret; + /* A bdrv_snapshot_goto() error takes precedence */ + error_propagate(errp, local_err); + return ret < 0 ? ret : open_ret; } assert(bs->file->bs == file); @@ -234,6 +244,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs, return ret; } + error_setg(errp, "Block driver does not support snapshots"); return -ENOTSUP; } @@ -467,7 +478,7 @@ int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs) aio_context_acquire(ctx); if (bdrv_can_snapshot(bs)) { - err = bdrv_snapshot_goto(bs, name); + err = 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; case SNAPSHOT_APPLY: - ret = bdrv_snapshot_goto(bs, snapshot_name); + ret = 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;