From nobody Mon Feb 9 09:22:36 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1598527243; cv=none; d=zohomail.com; s=zohoarc; b=ihhsCL/wW3etq5Yc7UWIMijNMTRku29ovC6RLaDubRa1+cwG2KFgmQI24a/2yTIEQ+87PqNd3dL4BghuYX92/KuWWjHF+QUqhQkpALyyUsSCmFZ3lkyBmtgb2NXTEptSU99sbxnLlltotNeYxHLTEbiJvVXAftVc0TDHXMfKGp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598527243; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pH0aMo2pBShZudod285fqHKNj1KmjnYdwcJsClAlFus=; b=Z3ofZm/HNsp+yi46JCSZzwjY/pjIOR828y2ZKMFGlxgz+lUieQtbkzqE5MrQ/w2fkYJY/Poex5BvDHnFwuJMpiQyWaJU3xZ8DfZ4ef1NaoVn0O6GRC5JHGGQ+Aeqs6BHf9ZgsUSD47RV6qIz8A0idridXisovikLvhp6HENHUyc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598527243656993.9453613559624; Thu, 27 Aug 2020 04:20:43 -0700 (PDT) Received: from localhost ([::1]:41450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kBFxS-0001dW-Ca for importer@patchew.org; Thu, 27 Aug 2020 07:20:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kBFtZ-0004pQ-Tl for qemu-devel@nongnu.org; Thu, 27 Aug 2020 07:16:41 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:60738 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kBFtX-0000pj-Jd for qemu-devel@nongnu.org; Thu, 27 Aug 2020 07:16:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-570-wH0FzQ0NPZm8nRbtCV6DXg-1; Thu, 27 Aug 2020 07:16:35 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 375E1801AC2; Thu, 27 Aug 2020 11:16:34 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05A61757EC; Thu, 27 Aug 2020 11:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598526998; 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=pH0aMo2pBShZudod285fqHKNj1KmjnYdwcJsClAlFus=; b=boNanlPTzPqRROKLyV9C5yMzhFrk4BRNz7/iwVuE00SPwyL+Y4IGLt/lRNCnhaO/9DIcxJ MIBTSULAYXxDp/Gj4TCxhPRiPMlMLxHdYrKNwgLAOfNEiNYj2lP1EuEMYnFh0rcNQxpPbF DZkpIPKlo6lvqbQqHt4zMYLyQLBZomU= X-MC-Unique: wH0FzQ0NPZm8nRbtCV6DXg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 4/7] block: add ability to specify list of blockdevs during snapshot Date: Thu, 27 Aug 2020 12:16:03 +0100 Message-Id: <20200827111606.1408275-5-berrange@redhat.com> In-Reply-To: <20200827111606.1408275-1-berrange@redhat.com> References: <20200827111606.1408275-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0.003 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=berrange@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/27 00:13:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.959, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Krempa , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , "Denis V. Lunev" , qemu-block@nongnu.org, Juan Quintela , John Snow , Markus Armbruster , "Dr. David Alan Gilbert" , Pavel Dovgalyuk , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) When running snapshot operations, there are various rules for which blockdevs are included/excluded. While this provides reasonable default behaviour, there are scenarios that are not well handled by the default logic. Some of the conditions do not have a single correct answer. Thus there needs to be a way for the mgmt app to provide an explicit list of blockdevs to perform snapshots across. This can be achieved by passing a list of node names that should be used. Signed-off-by: Daniel P. Berrang=C3=A9 --- block/monitor/block-hmp-cmds.c | 4 +- block/snapshot.c | 167 +++++++++++++++++++++++---------- include/block/snapshot.h | 13 +-- migration/savevm.c | 16 ++-- monitor/hmp-cmds.c | 2 +- 5 files changed, 138 insertions(+), 64 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 9df11494d6..db76c43cc2 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -900,7 +900,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdic= t) SnapshotEntry *snapshot_entry; Error *err =3D NULL; =20 - bs =3D bdrv_all_find_vmstate_bs(&err); + bs =3D bdrv_all_find_vmstate_bs(NULL, &err); if (!bs) { error_report_err(err); return; @@ -952,7 +952,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, NULL) =3D=3D 0) { + if (bdrv_all_find_snapshot(sn_tab[i].name, NULL, 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 6839060622..5691cdc6cb 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -385,6 +385,36 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverSt= ate *bs, return ret; } =20 + +static int bdrv_all_get_snapshot_devices(strList *devices, + GList **all_bdrvs, + Error **errp) +{ + g_autoptr(GList) bdrvs =3D NULL; + + if (devices) { + while (devices) { + BlockDriverState *bs =3D bdrv_find_node(devices->value); + if (!bs) { + error_setg(errp, "No block device node '%s'", devices->val= ue); + return -1; + } + bdrvs =3D g_list_append(bdrvs, bs); + devices =3D devices->next; + } + } else { + BlockDriverState *bs; + BdrvNextIterator it; + for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + bdrvs =3D g_list_append(bdrvs, bs); + } + } + + *all_bdrvs =3D g_steal_pointer(&bdrvs); + return 0; +} + + static bool bdrv_all_snapshots_includes_bs(BlockDriverState *bs) { if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) { @@ -400,43 +430,56 @@ 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(Error **errp) +bool bdrv_all_can_snapshot(strList *devices, Error **errp) { - BlockDriverState *bs; - BdrvNextIterator it; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + if (bdrv_all_get_snapshot_devices(devices, &bdrvs, errp) < 0) { + return false; + } + + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); bool ok; =20 aio_context_acquire(ctx); - if (bdrv_all_snapshots_includes_bs(bs)) { + if (devices || bdrv_all_snapshots_includes_bs(bs)) { ok =3D bdrv_can_snapshot(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); return false; } + + iterbdrvs =3D iterbdrvs->next; } =20 return true; } =20 -int bdrv_all_delete_snapshot(const char *name, Error **errp) +int bdrv_all_delete_snapshot(const char *name, strList *devices, Error **e= rrp) { - BlockDriverState *bs; - BdrvNextIterator it; - QEMUSnapshotInfo sn1, *snapshot =3D &sn1; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + if (bdrv_all_get_snapshot_devices(devices, &bdrvs, errp) < 0) { + return -1; + } + + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); - int ret; + QEMUSnapshotInfo sn1, *snapshot =3D &sn1; + int ret =3D 0; =20 aio_context_acquire(ctx); - if (bdrv_all_snapshots_includes_bs(bs) && + if ((devices || bdrv_all_snapshots_includes_bs(bs)) && bdrv_snapshot_find(bs, snapshot, name) >=3D 0) { ret =3D bdrv_snapshot_delete(bs, snapshot->id_str, @@ -446,61 +489,76 @@ int bdrv_all_delete_snapshot(const char *name, Error = **errp) 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); return -1; } + + iterbdrvs =3D iterbdrvs->next; } =20 return 0; } =20 =20 -int bdrv_all_goto_snapshot(const char *name, Error **errp) +int bdrv_all_goto_snapshot(const char *name, strList *devices, Error **err= p) { - BlockDriverState *bs; - BdrvNextIterator it; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + if (bdrv_all_get_snapshot_devices(devices, &bdrvs, errp) < 0) { + return -1; + } + + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); - int ret; + int ret =3D 0; =20 aio_context_acquire(ctx); - if (bdrv_all_snapshots_includes_bs(bs)) { + if (devices || bdrv_all_snapshots_includes_bs(bs)) { ret =3D bdrv_snapshot_goto(bs, name, errp); } 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); return -1; } + + iterbdrvs =3D iterbdrvs->next; } =20 return 0; } =20 -int bdrv_all_find_snapshot(const char *name, Error **errp) +int bdrv_all_find_snapshot(const char *name, strList *devices, Error **err= p) { - QEMUSnapshotInfo sn; - BlockDriverState *bs; - BdrvNextIterator it; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + if (bdrv_all_get_snapshot_devices(devices, &bdrvs, errp) < 0) { + return -1; + } + + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); - int ret; + QEMUSnapshotInfo sn; + int ret =3D 0; =20 aio_context_acquire(ctx); - if (bdrv_all_snapshots_includes_bs(bs)) { + if (devices || bdrv_all_snapshots_includes_bs(bs)) { ret =3D bdrv_snapshot_find(bs, &sn, name); } aio_context_release(ctx); 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); return -1; } + + iterbdrvs =3D iterbdrvs->next; } =20 return 0; @@ -509,20 +567,27 @@ 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, + strList *devices, Error **errp) { - BlockDriverState *bs; - BdrvNextIterator it; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + if (bdrv_all_get_snapshot_devices(devices, &bdrvs, errp) < 0) { + return -1; + } + + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); - int ret; + int ret =3D 0; =20 aio_context_acquire(ctx); if (bs =3D=3D vm_state_bs) { sn->vm_state_size =3D vm_state_size; ret =3D bdrv_snapshot_create(bs, sn); - } else if (bdrv_all_snapshots_includes_bs(bs)) { + } else if (devices || bdrv_all_snapshots_includes_bs(bs)) { sn->vm_state_size =3D 0; ret =3D bdrv_snapshot_create(bs, sn); } @@ -530,34 +595,42 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, 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); return -1; } + + iterbdrvs =3D iterbdrvs->next; } =20 return 0; } =20 -BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp) +BlockDriverState *bdrv_all_find_vmstate_bs(strList *devices, Error **errp) { - BlockDriverState *bs; - BdrvNextIterator it; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; + + if (bdrv_all_get_snapshot_devices(devices, &bdrvs, errp) < 0) { + return NULL; + } =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); - bool found; + bool found =3D false; =20 aio_context_acquire(ctx); - found =3D bdrv_all_snapshots_includes_bs(bs) && bdrv_can_snapshot(= bs); + found =3D (devices || bdrv_all_snapshots_includes_bs(bs)) && + bdrv_can_snapshot(bs); aio_context_release(ctx); =20 if (found) { - bdrv_next_cleanup(&it); - break; + return bs; } + + iterbdrvs =3D iterbdrvs->next; } - if (!bs) { - error_setg(errp, "No block device supports snapshots"); - } - return bs; + + error_setg(errp, "No block device supports snapshots"); + return NULL; } diff --git a/include/block/snapshot.h b/include/block/snapshot.h index ba1528eee0..1c5b0705a9 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -25,7 +25,7 @@ #ifndef SNAPSHOT_H #define SNAPSHOT_H =20 - +#include "qapi/qapi-builtin-types.h" =20 #define SNAPSHOT_OPT_BASE "snapshot." #define SNAPSHOT_OPT_ID "snapshot.id" @@ -76,15 +76,16 @@ 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(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); +bool bdrv_all_can_snapshot(strList *devices, Error **errp); +int bdrv_all_delete_snapshot(const char *name, strList *devices, Error **e= rrp); +int bdrv_all_goto_snapshot(const char *name, strList *devices, Error **err= p); +int bdrv_all_find_snapshot(const char *name, strList *devices, Error **err= p); int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, BlockDriverState *vm_state_bs, uint64_t vm_state_size, + strList *devices, Error **errp); =20 -BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp); +BlockDriverState *bdrv_all_find_vmstate_bs(strList *devices, Error **errp); =20 #endif diff --git a/migration/savevm.c b/migration/savevm.c index 711137bcbe..ae56de1a85 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2680,18 +2680,18 @@ int save_snapshot(const char *name, Error **errp) return ret; } =20 - if (!bdrv_all_can_snapshot(errp)) { + if (!bdrv_all_can_snapshot(NULL, errp)) { return ret; } =20 /* Delete old snapshots of the same name */ if (name) { - if (bdrv_all_delete_snapshot(name, errp) < 0) { + if (bdrv_all_delete_snapshot(name, NULL, errp) < 0) { return ret; } } =20 - bs =3D bdrv_all_find_vmstate_bs(errp); + bs =3D bdrv_all_find_vmstate_bs(NULL, errp); if (bs =3D=3D NULL) { return ret; } @@ -2757,7 +2757,7 @@ 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, errp); + ret =3D bdrv_all_create_snapshot(sn, bs, vm_state_size, NULL, errp); if (ret < 0) { goto the_end; } @@ -2873,15 +2873,15 @@ int load_snapshot(const char *name, Error **errp) return -1; } =20 - if (!bdrv_all_can_snapshot(errp)) { + if (!bdrv_all_can_snapshot(NULL, errp)) { return -1; } - ret =3D bdrv_all_find_snapshot(name, errp); + ret =3D bdrv_all_find_snapshot(name, NULL, errp); if (ret < 0) { return -1; } =20 - bs_vm_state =3D bdrv_all_find_vmstate_bs(errp); + bs_vm_state =3D bdrv_all_find_vmstate_bs(NULL, errp); if (!bs_vm_state) { return -1; } @@ -2902,7 +2902,7 @@ 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, errp); + ret =3D bdrv_all_goto_snapshot(name, NULL, errp); if (ret < 0) { goto err_drain; } diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 9bb50b9abf..51f624b5ea 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1140,7 +1140,7 @@ void hmp_delvm(Monitor *mon, const QDict *qdict) Error *err =3D NULL; const char *name =3D qdict_get_str(qdict, "name"); =20 - bdrv_all_delete_snapshot(name, &err); + bdrv_all_delete_snapshot(name, NULL, &err); hmp_handle_error(mon, err); } =20 --=20 2.26.2