From nobody Wed Dec 4 09:02:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1731660173406857.5754442001318; Fri, 15 Nov 2024 00:42:53 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2B74B13E0; Fri, 15 Nov 2024 03:42:52 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1CBDA1A38; Fri, 15 Nov 2024 03:40:02 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id C78DF1A01; Fri, 15 Nov 2024 03:39:56 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 4DB221A02 for ; Fri, 15 Nov 2024 03:39:44 -0500 (EST) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-17-BbcOk2QuNfqd9DZYB6YRsg-1; Fri, 15 Nov 2024 03:39:42 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7E0CA1955EB3 for ; Fri, 15 Nov 2024 08:39:41 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.6]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AD35419560A3 for ; Fri, 15 Nov 2024 08:39:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731659984; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uK0va/UUXJd4zNHiiHmjeGYP++RbZK4Lf14rfa8wwKg=; b=CbrvWEbP1oEenu/uD7SLpoLBOLlO/ibh0Vz4hDXKuoaPV3XrXdgb0yd3QZUfQEHtbhO13/ vRZuwvJz+0dE+gi0SJzWYynTnagMNnYCkgaM25dlXb/U9BpPcjG2BE+ML6+uZ86amHXcvY 2hXhyigPwaem8go9aYvczVPpPTCy9KI= X-MC-Unique: BbcOk2QuNfqd9DZYB6YRsg-1 X-Mimecast-MFC-AGG-ID: BbcOk2QuNfqd9DZYB6YRsg From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 6/9] qemu: monitor: Add monitor infrastructure for 'snapshot-load' QMP command Date: Fri, 15 Nov 2024 09:39:27 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zuP8R-23kbQ2VQaHmKvsRnVqGfo-Up_UN1sF3ylfMWU_1731659981 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: HWUKKGZB2FFY2XIJGGXWAXWFOJNHM2HO X-Message-ID-Hash: HWUKKGZB2FFY2XIJGGXWAXWFOJNHM2HO X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1731660174779116600 Content-Type: text/plain; charset="utf-8" Libvirt currently loads snapshots via the '-loadvm' commandline option but that uses the same logic as the 'loadvm' text monitor command used to pick the disk image with the 'vmstate' section. Since libvirt now implements our own logic to pick the 'vmstate' device it can happen that we pick a different than qemu and thus qemu would fail to load the snapshot. This happens currently on VMs with UEFI firmware with NVRAM image in qcow2 format. To fix this libvirt will need to use the 'snapshot-load' QMP command instead of relying on '-savevm'. Implement the monitor bits for 'snapshot-load'. Signed-off-by: Peter Krempa --- src/qemu/qemu_monitor.c | 16 ++++++++++++++++ src/qemu/qemu_monitor.h | 7 +++++++ src/qemu/qemu_monitor_json.c | 31 +++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 7 +++++++ 4 files changed, 61 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index fd888e2468..73f37d26eb 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2780,6 +2780,22 @@ qemuMonitorSnapshotSave(qemuMonitor *mon, } +int +qemuMonitorSnapshotLoad(qemuMonitor *mon, + const char *jobname, + const char *snapshotname, + const char *vmstate_disk, + const char **disks) +{ + VIR_DEBUG("jobname=3D'%s', snapshotname=3D'%s', vmstate_disk=3D'%s'", + jobname, snapshotname, vmstate_disk); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONSnapshotLoad(mon, jobname, snapshotname, vmstate= _disk, disks); +} + + int qemuMonitorSnapshotDelete(qemuMonitor *mon, const char *jobname, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 035c9a7e3c..aded771315 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1626,6 +1626,13 @@ qemuMonitorSnapshotSave(qemuMonitor *mon, const char *vmstate_disk, const char **disks); +int +qemuMonitorSnapshotLoad(qemuMonitor *mon, + const char *jobname, + const char *snapshotname, + const char *vmstate_disk, + const char **disks); + int qemuMonitorSnapshotDelete(qemuMonitor *mon, const char *jobname, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index c594b33106..b3924461a9 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8754,6 +8754,37 @@ qemuMonitorJSONSnapshotSave(qemuMonitor *mon, } +int +qemuMonitorJSONSnapshotLoad(qemuMonitor *mon, + const char *jobname, + const char *snapshotname, + const char *vmstate_disk, + const char **disks) +{ + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; + g_autoptr(virJSONValue) devices =3D virJSONValueNewArray(); + + for (; *disks; disks++) { + if (virJSONValueArrayAppendString(devices, *disks) < 0) + return -1; + } + + if (!(cmd =3D qemuMonitorJSONMakeCommand("snapshot-load", + "s:job-id", jobname, + "s:tag", snapshotname, + "s:vmstate", vmstate_disk, + "a:devices", &devices, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return -1; + + return qemuMonitorJSONCheckError(cmd, reply); +} + + int qemuMonitorJSONSnapshotDelete(qemuMonitor *mon, const char *jobname, diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index ab3c2cb7c8..0214e9e9ff 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -804,6 +804,13 @@ qemuMonitorJSONSnapshotSave(qemuMonitor *mon, const char *vmstate_disk, const char **disks); +int +qemuMonitorJSONSnapshotLoad(qemuMonitor *mon, + const char *jobname, + const char *snapshotname, + const char *vmstate_disk, + const char **disks); + int qemuMonitorJSONSnapshotDelete(qemuMonitor *mon, const char *jobname, --=20 2.47.0