From nobody Sat Jul 27 04:01:22 2024 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=1695043812; cv=none; d=zohomail.com; s=zohoarc; b=atGKWD3If0sPP8l17lyifkc+4Q7QKaDUJCxayjwR2AWtsKLb+tYJ2w9L4me7zmwjTNPp2QqHUt3nzdQlmFf0cglcdCR6GZzpasm1CAk06QKDpRsQABn8T2v6URR/Ft41ppTeHymMCy2g0yQQ2eSglVORvV65EDWy86W0+iI8zRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695043812; 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=Tt/HsJPBA8C6d19pDh4GV8o+7pttS9LWb0ctzpS5/EQ=; b=UZbD7mfQOzhfBK41Dg12w7k2Bb16KMT786h0B4vnMXieJHNxy6ZbXJxBEmkoA+C6Q31SMS9BVoGUEKpbAUpjkZF9IvY+HeIoRj7fX2eiHZvHQYQNYqdpuy05YGoToNecbZYant8DfMQZsZVgKc21tQDSTiTS3liJb2uidsbJZ0E= 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 1695043812469370.8096028110093; Mon, 18 Sep 2023 06:30:12 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-435-mM6204tMNmuYU1I9jBhXRA-1; Mon, 18 Sep 2023 09:30:07 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD7F4945935; Mon, 18 Sep 2023 13:30:04 +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 994F940C200B; Mon, 18 Sep 2023 13:30:04 +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 680ED1946A72; Mon, 18 Sep 2023 13:29:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 84BB619465B7 for ; Mon, 18 Sep 2023 13:29:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 731DB1C646; Mon, 18 Sep 2023 13:29:38 +0000 (UTC) Received: from localhost.localdomain (unknown [10.45.226.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id 163411C554 for ; Mon, 18 Sep 2023 13:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695043811; 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=Tt/HsJPBA8C6d19pDh4GV8o+7pttS9LWb0ctzpS5/EQ=; b=I+4lu21CRXdo5o2mCTUWBrssaaxw9kpktF7dQk5XO5ZnS3PvlAE4VVak3Jp20d7UACnrXa BxtoVP5txoHR6IUPqEYn5CE4K2hnovpqDfnlhEcdPgYw/EGT+tlla1g7EZRgpKNR0SEata /nnCreQ1IxC/qLNXhruv0eVLZd730Wo= X-MC-Unique: mM6204tMNmuYU1I9jBhXRA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 08/10] qemu_snapshot: correctly load the saved memory state file Date: Mon, 18 Sep 2023 15:29:25 +0200 Message-ID: <1be2a537616735c3ea4261258d4ac07c1df715b2.1695043512.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: 1695043814008100001 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 --- src/qemu/qemu_snapshot.c | 79 ++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 44bd97e564..e52d264826 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2000,6 +2000,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 @@ -2007,15 +2022,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. */ @@ -2025,8 +2038,7 @@ qemuSnapshotRevertExternalPrepare(virDomainObj *vm, virDomainMomentObj *snap, virDomainDef *config, virDomainDef *inactiveConfig, - int *memsnapFD, - char **memsnapPath) + qemuSnapshotRevertMemoryData *memdata) { size_t i; bool active =3D virDomainObjIsActive(vm); @@ -2061,12 +2073,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; @@ -2250,13 +2271,12 @@ 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 @@ -2280,7 +2300,7 @@ qemuSnapshotRevertActive(virDomainObj *vm, =20 if (qemuSnapshotRevertExternalPrepare(vm, tmpsnapdef, snap, *config, *inactiveConfig, - &memsnapFD, &memsnapPath) < = 0) { + &memdata) < 0) { return -1; } } else { @@ -2294,28 +2314,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 (qemuProcessStartWithMemoryState(snapshot->domain->conn, driver, vm, + &memdata.fd, memdata.path, loadSna= p, + memdata.data, VIR_ASYNC_JOB_SNAPSH= OT, + start_flags, "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) @@ -2423,8 +2439,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