From nobody Mon Nov 17 01:24:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602179295; cv=none; d=zohomail.com; s=zohoarc; b=g/u1iB31pqMnwjPY0bzCf4CJ6fXBMyYcUm4nWOKWAUtXoUP0LYWBuBDJ3xHl3jhH9rJD7nvtarwpjQK3ci3CiOKGe44I6aNY3yHnwUkBGLuJI11IawH6AFvjBw7YLxwNbasOuZ12JlQgdFU4bQ9eWD5CuyeyY5Qj57oKlEitM94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602179295; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ovB74Si3ek3jQLoyWkkaLDVrBy+bYBEfB0/xyEBcs9k=; b=Ck+zd3ebTeK62cydWf78uvUQGh5Xw1p/p8P09CCGJpcEHDHaR8NLKu6MtDcx04hrFZtKYAMMOzXiGR7n6gNUCQkIRrBrBzBZyA6mva8Iob1IH640Hltm3vFbfIMjhd1coBHWhqBoT8hfMt46QRQbuGbNm6+VPUvoP1DondpzVic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602179295024821.6297421710269; Thu, 8 Oct 2020 10:48:15 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-jS-KyYfOORejvtWlWaD78A-1; Thu, 08 Oct 2020 13:48:12 -0400 Received: by mail-wm1-f72.google.com with SMTP id s25so3340758wmj.7 for ; Thu, 08 Oct 2020 10:48:12 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (106.red-83-59-162.dynamicip.rima-tde.net. [83.59.162.106]) by smtp.gmail.com with ESMTPSA id o6sm8521316wrm.69.2020.10.08.10.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602179293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ovB74Si3ek3jQLoyWkkaLDVrBy+bYBEfB0/xyEBcs9k=; b=T//05fopa+WPwdBeT2zxs1i1se7IByhJojPhqZakmntK1BLNTUmT+GCJMXkCXish48dSnM /888uaBwwkBJ5tFfVXdUuF38H2i3sGP5rNFYnBXMTNaCn2jAGcjyc1kaJeDyp4Dtr0JBWV +1fwLXtmrPCKAoBR7EoJlw9aYHI4GGY= X-MC-Unique: jS-KyYfOORejvtWlWaD78A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ovB74Si3ek3jQLoyWkkaLDVrBy+bYBEfB0/xyEBcs9k=; b=rVjh2Q/BKhoeaznO6JN9MfruX79qIHiin6btnjP4xtiktI7HtCVLnLv+xp07/6dWH6 3v+C8zOGd1OdpHgPUMnhiLHD2w7MBiZDh9si5TQorCuvGAr9PWaaxo5BhNe+DWsemBg1 YyvXMqzbD4sWelCWTl+L1ofa9YLJXSRqwnlvXeP4ZOKdBVs+Z1se1d3+JWYwFErXu3L2 qUvM22aQWdxY4aKS3rmO3K8vfV0T4CvfYFdbQAMREs5AZlAHat5JVM2Swp4tZPD5p13f nd0+IoTjjIfptQLHcZj+Ni5OAxulQ0i4WRIhWQBG/+rZ6mbxV//CHTRkawRoNr4SAZ82 8hrA== X-Gm-Message-State: AOAM531erRPonfRrAEadfTlLmxruoUT62UjzAzDuO6AWNkLU23cIaboo Ne9wN5Z6lJJWlGVtnXDvfegpo0EA7zfadrmeFs7GGEy5pSQAnNUO/GseUgCkMHk3Lo4ut73yRFc vGCQsj5/wpXjv8Q== X-Received: by 2002:a05:600c:210f:: with SMTP id u15mr10493467wml.53.1602179290737; Thu, 08 Oct 2020 10:48:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWDjBcOeMvqZWHrhqZXsdV4t5gL1MWWGg0AArzzD8hxpTLuoSvxI8/x1XCbOMuQc4sl3/7vA== X-Received: by 2002:a05:600c:210f:: with SMTP id u15mr10493443wml.53.1602179290458; Thu, 08 Oct 2020 10:48:10 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Max Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pavel Dovgalyuk , Paolo Bonzini , "Dr. David Alan Gilbert" , Juan Quintela , Kevin Wolf Subject: [PATCH 1/3] block: push error reporting into bdrv_all_*_snapshot functions Date: Thu, 8 Oct 2020 19:48:01 +0200 Message-Id: <20201008174803.2696619-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201008174803.2696619-1-philmd@redhat.com> References: <20201008174803.2696619-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 The bdrv_all_*_snapshot functions return a BlockDriverState pointer for the invalid backend, which the callers then use to report an error message. In some cases multiple callers are reporting the same error message, but with slightly different text. In the future there will be more error scenarios for some of these methods, which will benefit from fine grained error message reporting. So it is helpful to push error reporting down a level. Signed-off-by: Daniel P. Berrang=C3=A9 --- include/block/snapshot.h | 14 +++---- block/monitor/block-hmp-cmds.c | 7 ++-- block/snapshot.c | 77 +++++++++++++++++----------------- migration/savevm.c | 37 +++++----------- monitor/hmp-cmds.c | 7 +--- replay/replay-debugging.c | 4 +- tests/qemu-iotests/267.out | 10 ++--- 7 files changed, 67 insertions(+), 89 deletions(-) diff --git a/include/block/snapshot.h b/include/block/snapshot.h index b0fe42993d..5cb2b696ad 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -77,17 +77,15 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverSta= te *bs, * These functions will properly handle dataplane (take aio_context_acquire * when appropriate for appropriate block drivers */ =20 -bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs); -int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bs= d_bs, - Error **errp); -int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_= bs, - Error **errp); -int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_= bs); +bool bdrv_all_can_snapshot(Error **errp); +int bdrv_all_delete_snapshot(const char *name, Error **errp); +int bdrv_all_goto_snapshot(const char *name, Error **errp); +int bdrv_all_find_snapshot(const char *name, Error **errp); int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, BlockDriverState *vm_state_bs, uint64_t vm_state_size, - BlockDriverState **first_bad_bs); + Error **errp); =20 -BlockDriverState *bdrv_all_find_vmstate_bs(void); +BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp); =20 #endif diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index d15a2be827..548bb6b5e3 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -899,10 +899,11 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qd= ict) =20 ImageEntry *image_entry, *next_ie; SnapshotEntry *snapshot_entry; + Error *err =3D NULL; =20 - bs =3D bdrv_all_find_vmstate_bs(); + bs =3D bdrv_all_find_vmstate_bs(&err); if (!bs) { - monitor_printf(mon, "No available block device supports snapshots\= n"); + error_report_err(err); return; } aio_context =3D bdrv_get_aio_context(bs); @@ -952,7 +953,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdic= t) total =3D 0; for (i =3D 0; i < nb_sns; i++) { SnapshotEntry *next_sn; - if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) =3D=3D 0) { + if (bdrv_all_find_snapshot(sn_tab[i].name, NULL) =3D=3D 0) { global_snapshots[total] =3D i; total++; QTAILQ_FOREACH(image_entry, &image_list, next) { diff --git a/block/snapshot.c b/block/snapshot.c index a2bf3a54eb..50e35bb9fa 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -462,14 +462,14 @@ static bool bdrv_all_snapshots_includes_bs(BlockDrive= rState *bs) * These functions will properly handle dataplane (take aio_context_acquire * when appropriate for appropriate block drivers) */ =20 -bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs) +bool bdrv_all_can_snapshot(Error **errp) { - bool ok =3D true; BlockDriverState *bs; BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *ctx =3D bdrv_get_aio_context(bs); + bool ok; =20 aio_context_acquire(ctx); if (bdrv_all_snapshots_includes_bs(bs)) { @@ -477,26 +477,25 @@ bool bdrv_all_can_snapshot(BlockDriverState **first_b= ad_bs) } aio_context_release(ctx); if (!ok) { + error_setg(errp, "Device '%s' is writable but does not support= " + "snapshots", bdrv_get_device_or_node_name(bs)); bdrv_next_cleanup(&it); - goto fail; + return false; } } =20 -fail: - *first_bad_bs =3D bs; - return ok; + return true; } =20 -int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_ba= d_bs, - Error **errp) +int bdrv_all_delete_snapshot(const char *name, Error **errp) { - int ret =3D 0; BlockDriverState *bs; BdrvNextIterator it; QEMUSnapshotInfo sn1, *snapshot =3D &sn1; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *ctx =3D bdrv_get_aio_context(bs); + int ret; =20 aio_context_acquire(ctx); if (bdrv_all_snapshots_includes_bs(bs) && @@ -507,26 +506,25 @@ int bdrv_all_delete_snapshot(const char *name, BlockD= riverState **first_bad_bs, } aio_context_release(ctx); if (ret < 0) { + error_prepend(errp, "Could not delete snapshot '%s' on '%s': ", + name, bdrv_get_device_or_node_name(bs)); bdrv_next_cleanup(&it); - goto fail; + return -1; } } =20 -fail: - *first_bad_bs =3D bs; - return ret; + return 0; } =20 =20 -int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_= bs, - Error **errp) +int bdrv_all_goto_snapshot(const char *name, Error **errp) { - int ret =3D 0; BlockDriverState *bs; BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *ctx =3D bdrv_get_aio_context(bs); + int ret; =20 aio_context_acquire(ctx); if (bdrv_all_snapshots_includes_bs(bs)) { @@ -534,75 +532,75 @@ int bdrv_all_goto_snapshot(const char *name, BlockDri= verState **first_bad_bs, } aio_context_release(ctx); if (ret < 0) { + error_prepend(errp, "Could not load snapshot '%s' on '%s': ", + name, bdrv_get_device_or_node_name(bs)); bdrv_next_cleanup(&it); - goto fail; + return -1; } } =20 -fail: - *first_bad_bs =3D bs; - return ret; + return 0; } =20 -int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_= bs) +int bdrv_all_find_snapshot(const char *name, Error **errp) { QEMUSnapshotInfo sn; - int err =3D 0; BlockDriverState *bs; BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *ctx =3D bdrv_get_aio_context(bs); + int ret; =20 aio_context_acquire(ctx); if (bdrv_all_snapshots_includes_bs(bs)) { - err =3D bdrv_snapshot_find(bs, &sn, name); + ret =3D bdrv_snapshot_find(bs, &sn, name); } aio_context_release(ctx); - if (err < 0) { + if (ret < 0) { + error_setg(errp, "Could not find snapshot '%s' on '%s'", + name, bdrv_get_device_or_node_name(bs)); bdrv_next_cleanup(&it); - goto fail; + return -1; } } =20 -fail: - *first_bad_bs =3D bs; - return err; + return 0; } =20 int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, BlockDriverState *vm_state_bs, uint64_t vm_state_size, - BlockDriverState **first_bad_bs) + Error **errp) { - int err =3D 0; BlockDriverState *bs; BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *ctx =3D bdrv_get_aio_context(bs); + int ret; =20 aio_context_acquire(ctx); if (bs =3D=3D vm_state_bs) { sn->vm_state_size =3D vm_state_size; - err =3D bdrv_snapshot_create(bs, sn); + ret =3D bdrv_snapshot_create(bs, sn); } else if (bdrv_all_snapshots_includes_bs(bs)) { sn->vm_state_size =3D 0; - err =3D bdrv_snapshot_create(bs, sn); + ret =3D bdrv_snapshot_create(bs, sn); } aio_context_release(ctx); - if (err < 0) { + if (ret < 0) { + error_setg(errp, "Could not create snapshot '%s' on '%s'", + sn->name, bdrv_get_device_or_node_name(bs)); bdrv_next_cleanup(&it); - goto fail; + return -1; } } =20 -fail: - *first_bad_bs =3D bs; - return err; + return 0; } =20 -BlockDriverState *bdrv_all_find_vmstate_bs(void) +BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp) { BlockDriverState *bs; BdrvNextIterator it; @@ -620,5 +618,8 @@ BlockDriverState *bdrv_all_find_vmstate_bs(void) break; } } + if (!bs) { + error_setg(errp, "No block device supports snapshots"); + } return bs; } diff --git a/migration/savevm.c b/migration/savevm.c index d2e141f7b1..a52da440f4 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2660,7 +2660,7 @@ int qemu_load_device_state(QEMUFile *f) =20 int save_snapshot(const char *name, Error **errp) { - BlockDriverState *bs, *bs1; + BlockDriverState *bs; QEMUSnapshotInfo sn1, *sn =3D &sn1, old_sn1, *old_sn =3D &old_sn1; int ret =3D -1, ret2; QEMUFile *f; @@ -2680,25 +2680,19 @@ int save_snapshot(const char *name, Error **errp) return ret; } =20 - if (!bdrv_all_can_snapshot(&bs)) { - error_setg(errp, "Device '%s' is writable but does not support " - "snapshots", bdrv_get_device_or_node_name(bs)); + if (!bdrv_all_can_snapshot(errp)) { return ret; } =20 /* Delete old snapshots of the same name */ if (name) { - ret =3D bdrv_all_delete_snapshot(name, &bs1, errp); - if (ret < 0) { - error_prepend(errp, "Error while deleting snapshot on device " - "'%s': ", bdrv_get_device_or_node_name(bs1)); + if (bdrv_all_delete_snapshot(name, errp) < 0) { return ret; } } =20 - bs =3D bdrv_all_find_vmstate_bs(); + bs =3D bdrv_all_find_vmstate_bs(errp); if (bs =3D=3D NULL) { - error_setg(errp, "No block device can accept snapshots"); return ret; } aio_context =3D bdrv_get_aio_context(bs); @@ -2768,10 +2762,8 @@ int save_snapshot(const char *name, Error **errp) aio_context_release(aio_context); aio_context =3D NULL; =20 - ret =3D bdrv_all_create_snapshot(sn, bs, vm_state_size, &bs); + ret =3D bdrv_all_create_snapshot(sn, bs, vm_state_size, errp); if (ret < 0) { - error_setg(errp, "Error while creating snapshot on '%s'", - bdrv_get_device_or_node_name(bs)); goto the_end; } =20 @@ -2874,30 +2866,23 @@ void qmp_xen_load_devices_state(const char *filenam= e, Error **errp) =20 int load_snapshot(const char *name, Error **errp) { - BlockDriverState *bs, *bs_vm_state; + BlockDriverState *bs_vm_state; QEMUSnapshotInfo sn; QEMUFile *f; int ret; AioContext *aio_context; MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 - if (!bdrv_all_can_snapshot(&bs)) { - error_setg(errp, - "Device '%s' is writable but does not support snapshots= ", - bdrv_get_device_or_node_name(bs)); + if (!bdrv_all_can_snapshot(errp)) { return -ENOTSUP; } - ret =3D bdrv_all_find_snapshot(name, &bs); + ret =3D bdrv_all_find_snapshot(name, errp); if (ret < 0) { - error_setg(errp, - "Device '%s' does not have the requested snapshot '%s'", - bdrv_get_device_or_node_name(bs), name); return ret; } =20 - bs_vm_state =3D bdrv_all_find_vmstate_bs(); + bs_vm_state =3D bdrv_all_find_vmstate_bs(errp); if (!bs_vm_state) { - error_setg(errp, "No block device supports snapshots"); return -ENOTSUP; } aio_context =3D bdrv_get_aio_context(bs_vm_state); @@ -2923,10 +2908,8 @@ int load_snapshot(const char *name, Error **errp) /* Flush all IO requests so they don't interfere with the new state. = */ bdrv_drain_all_begin(); =20 - ret =3D bdrv_all_goto_snapshot(name, &bs, errp); + ret =3D bdrv_all_goto_snapshot(name, errp); if (ret < 0) { - error_prepend(errp, "Could not load snapshot '%s' on '%s': ", - name, bdrv_get_device_or_node_name(bs)); goto err_drain; } =20 diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index dc0de39219..14848a3381 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1139,15 +1139,10 @@ void hmp_savevm(Monitor *mon, const QDict *qdict) =20 void hmp_delvm(Monitor *mon, const QDict *qdict) { - BlockDriverState *bs; Error *err =3D NULL; const char *name =3D qdict_get_str(qdict, "name"); =20 - if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) { - error_prepend(&err, - "deleting snapshot on device '%s': ", - bdrv_get_device_name(bs)); - } + bdrv_all_delete_snapshot(name, &err); hmp_handle_error(mon, err); } =20 diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index ee9e86daa9..8785489c02 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -149,7 +149,7 @@ static char *replay_find_nearest_snapshot(int64_t icoun= t, =20 *snapshot_icount =3D -1; =20 - bs =3D bdrv_all_find_vmstate_bs(); + bs =3D bdrv_all_find_vmstate_bs(NULL); if (!bs) { goto fail; } @@ -160,7 +160,7 @@ static char *replay_find_nearest_snapshot(int64_t icoun= t, aio_context_release(aio_context); =20 for (i =3D 0; i < nb_sns; i++) { - if (bdrv_all_find_snapshot(sn_tab[i].name, &bs) =3D=3D 0) { + if (bdrv_all_find_snapshot(sn_tab[i].name, NULL) =3D=3D 0) { if (sn_tab[i].icount !=3D -1ULL && sn_tab[i].icount <=3D icount && (!nearest || nearest->icount < sn_tab[i].icount)) { diff --git a/tests/qemu-iotests/267.out b/tests/qemu-iotests/267.out index 27471ffae8..6149029b25 100644 --- a/tests/qemu-iotests/267.out +++ b/tests/qemu-iotests/267.out @@ -6,9 +6,9 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1342177= 28 Testing: QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 -Error: No block device can accept snapshots +Error: No block device supports snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: No block device supports snapshots (qemu) quit @@ -22,7 +22,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'none0' is writable but does not support snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: Device 'none0' is writable but does not support snapshots (qemu) quit @@ -58,7 +58,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'virtio0' is writable but does not support snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: Device 'virtio0' is writable but does not support snapshots (qemu) quit @@ -83,7 +83,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'file' is writable but does not support snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: Device 'file' is writable but does not support snapshots (qemu) quit --=20 2.26.2