From nobody Sun Feb 8 21:48:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@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 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693493732; cv=none; d=zohomail.com; s=zohoarc; b=QSQLNUwJJKpPWS18dZuKBsVm1k6UVEMyaNDCF/lHcG3o/rHTqugGYpfpQcbsNn8MXfzgRcMOuKDovmomyzPfSJPOom/XcYbmybJf7iJenPR2889m0Yrmcwg04spZJgtcVrExzXjolV9zANSjWHFmbewMhjKTZCV6GgYmzzZsN18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693493732; h=Content-Type:Content-Transfer-Encoding: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=rRA45HLrgB94eq6KFcH2EGxWkOmWy1b9wW2uzOy3EFo=; b=mgVwp9guhoDk3fXxfXus+JqtcF9SfXGiRjYqMVJ/c47Dq94eTqP7wTGpvGh8og98M5vxt5B6xj66T6hQMXLSYqREIXLnTYjqozudsJsRGlxBLqg6m6zKPHEwJi+D/YmTyE2AFgk4ApFsxBL9MGXKiFExO+xaHt4AhtvFGd/84fM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1693493732053546.4451824567473; Thu, 31 Aug 2023 07:55:32 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-131-Mpw9IMS-MRmZhWqK91kE3Q-1; Thu, 31 Aug 2023 10:55:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C043F2812956; Thu, 31 Aug 2023 14:55:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB60A40C2070; Thu, 31 Aug 2023 14:55:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 11FC719452C2; Thu, 31 Aug 2023 14:55:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5C1831946587 for ; Thu, 31 Aug 2023 14:55:16 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3C9A040C207C; Thu, 31 Aug 2023 14:55:16 +0000 (UTC) Received: from localhost.localdomain (unknown [10.45.224.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id D02EE40C2063 for ; Thu, 31 Aug 2023 14:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693493731; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rRA45HLrgB94eq6KFcH2EGxWkOmWy1b9wW2uzOy3EFo=; b=Hd+MMLI0R6BFfvs+FvOkSA0Vk50MgZ+vnPzT+wLY+MkGPYd5MMGjkSsYkMFT+yTATXERFg iYrNU2FkvvAORsTO+dgLGu64hfLfBBnIt7PRvwBmFR6rGGWvDQzJgZAP+yJnhDwq6SdHRs O7Sb0PXU96u+D4EZe8iQihLitkXuguc= X-MC-Unique: Mpw9IMS-MRmZhWqK91kE3Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 6/7] qemu_snapshot: correctly load the saved memory state file Date: Thu, 31 Aug 2023 16:55:05 +0200 Message-ID: <9fdb92119dea686b507b5b9aa5786260ba11dfed.1693493289.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693493732543100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Original code assumed that the memory state file is only migration stream but it has additional metadata stored by libvirt. To correctly load the memory state file we need to reuse code that is used when restoring domain from saved image. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 78 ++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index ff85d56572..869b46a9a8 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2004,6 +2004,21 @@ qemuSnapshotRevertWriteMetadata(virDomainObj *vm, } =20 =20 +typedef struct _qemuSnapshotRevertMemoryData { + int fd; + char *path; + virQEMUSaveData *data; +} qemuSnapshotRevertMemoryData; + +static void +qemuSnapshotClearRevertMemoryData(qemuSnapshotRevertMemoryData *memdata) +{ + VIR_FORCE_CLOSE(memdata->fd); + virQEMUSaveDataFree(memdata->data); +} +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(qemuSnapshotRevertMemoryData, qemuSnapsho= tClearRevertMemoryData); + + /** * qemuSnapshotRevertExternalPrepare: * @vm: domain object @@ -2011,15 +2026,13 @@ qemuSnapshotRevertWriteMetadata(virDomainObj *vm, * @snap: snapshot object we are reverting to * @config: live domain definition * @inactiveConfig: offline domain definition - * memsnapFD: pointer to store memory state file FD or NULL - * memsnapPath: pointer to store memory state file path or NULL + * @memdata: struct with data to load memory state * * Prepare new temporary snapshot definition @tmpsnapdef that will * be used while creating new overlay files after reverting to snapshot * @snap. In case we are reverting to snapshot with memory state it will - * open it and pass FD via @memsnapFD and path to the file via - * @memsnapPath, caller is responsible for freeing both @memsnapFD and - * memsnapPath. + * open it and store necessary data in @memdata. Caller is responsible + * to clear the data by using qemuSnapshotClearRevertMemoryData(). * * Returns 0 in success, -1 on error. */ @@ -2029,8 +2042,7 @@ qemuSnapshotRevertExternalPrepare(virDomainObj *vm, virDomainMomentObj *snap, virDomainDef *config, virDomainDef *inactiveConfig, - int *memsnapFD, - char **memsnapPath) + qemuSnapshotRevertMemoryData *memdata) { size_t i; bool active =3D virDomainObjIsActive(vm); @@ -2065,12 +2077,21 @@ qemuSnapshotRevertExternalPrepare(virDomainObj *vm, return -1; } =20 - if (memsnapFD && memsnapPath && snapdef->memorysnapshotfile) { + if (memdata && snapdef->memorysnapshotfile) { virQEMUDriver *driver =3D ((qemuDomainObjPrivate *) vm->privateDat= a)->driver; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driv= er); + g_autoptr(virDomainDef) savedef =3D NULL; =20 - *memsnapPath =3D snapdef->memorysnapshotfile; - *memsnapFD =3D qemuDomainOpenFile(cfg, NULL, *memsnapPath, O_RDONL= Y, NULL); + memdata->path =3D snapdef->memorysnapshotfile; + memdata->fd =3D qemuSaveImageOpen(driver, NULL, memdata->path, + &savedef, &memdata->data, + false, NULL, + false, false); + + if (memdata->fd < 0) + return -1; + + if (!virDomainDefCheckABIStability(savedef, domdef, driver->xmlopt= )) + return -1; } =20 return 0; @@ -2254,13 +2275,13 @@ qemuSnapshotRevertActive(virDomainObj *vm, virObjectEvent *event =3D NULL; virObjectEvent *event2 =3D NULL; virDomainMomentObj *loadSnap =3D NULL; - VIR_AUTOCLOSE memsnapFD =3D -1; - char *memsnapPath =3D NULL; int detail; bool defined =3D false; qemuDomainSaveCookie *cookie =3D (qemuDomainSaveCookie *) snapdef->coo= kie; int rc; g_autoptr(virDomainSnapshotDef) tmpsnapdef =3D NULL; + g_auto(qemuSnapshotRevertMemoryData) memdata =3D { -1, NULL, NULL }; + bool started =3D false; =20 start_flags |=3D VIR_QEMU_PROCESS_START_PAUSED; =20 @@ -2284,7 +2305,7 @@ qemuSnapshotRevertActive(virDomainObj *vm, =20 if (qemuSnapshotRevertExternalPrepare(vm, tmpsnapdef, snap, *config, *inactiveConfig, - &memsnapFD, &memsnapPath) < = 0) { + &memdata) < 0) { return -1; } } else { @@ -2298,28 +2319,24 @@ qemuSnapshotRevertActive(virDomainObj *vm, =20 virDomainObjAssignDef(vm, config, true, NULL); =20 - /* No cookie means libvirt which saved the domain was too old to - * mess up the CPU definitions. - */ - if (cookie && - qemuDomainFixupCPUs(vm, &cookie->cpu) < 0) + if (qemuSaveImageStartProcess(snapshot->domain->conn, driver, vm, + &memdata.fd, memdata.path, loadSnap, + memdata.data ? &memdata.data->header : N= ULL, + cookie, VIR_ASYNC_JOB_SNAPSHOT, start_fl= ags, + "from-snapshot", &started) < 0) { + if (started) { + qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, + VIR_ASYNC_JOB_SNAPSHOT, + VIR_QEMU_PROCESS_STOP_MIGRATED); + } return -1; + } =20 - rc =3D qemuProcessStart(snapshot->domain->conn, driver, vm, - cookie ? cookie->cpu : NULL, - VIR_ASYNC_JOB_SNAPSHOT, NULL, memsnapFD, - memsnapPath, loadSnap, - VIR_NETDEV_VPORT_PROFILE_OP_CREATE, - start_flags); - virDomainAuditStart(vm, "from-snapshot", rc >=3D 0); detail =3D VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT; event =3D virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STARTED, detail); virObjectEventStateQueue(driver->domainEventState, event); - if (rc < 0) - return -1; - =20 if (virDomainSnapshotIsExternal(snap)) { if (qemuSnapshotRevertExternalActive(vm, tmpsnapdef) < 0) @@ -2427,8 +2444,7 @@ qemuSnapshotRevertInactive(virDomainObj *vm, return -1; =20 if (qemuSnapshotRevertExternalPrepare(vm, tmpsnapdef, snap, - NULL, *inactiveConfig, - NULL, NULL) < 0) { + NULL, *inactiveConfig, NULL)= < 0) { return -1; } =20 --=20 2.41.0