From nobody Wed May 1 23:39:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1606138443; cv=none; d=zohomail.com; s=zohoarc; b=EO86q/jjKlchrbI6x7bp1vvC5y3OjaU1fnCUU92TfJPzKGewQvU2wx8b5buUkhpT2JWfrLJXhLua5LtdPIpZ7co2OIH0yE4Hn6HjSZPzyO2pviAsYZesKAnFlrCAwyauv0/ni7j7VxxO7IC9qBJDm2dGxmd2jUAQl9t0e202EvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606138443; 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=oYn30zsIbK8vCfp1qKiwuhWtZJCOWpf/Yf3XudSaBwc=; b=WxAGqGgkL8CPCvL+VXi3MA3XaihHDasXQjurpZh3djCWVxfCjLXQXkQdAxMl7x8qzyVC4025H4KA/gU1dMDlB6aRWCcUEDxAgPW8tJaecIessuzvr44KNkBZuAefys2LV1feaE6u0lWHf5ccdzROZsrntKohyaIIbEBlgIjZYoM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606138443758906.3119369941305; Mon, 23 Nov 2020 05:34:03 -0800 (PST) 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-341-puICQGBmONq7fIL_taNhwA-1; Mon, 23 Nov 2020 08:33:59 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 181E91012E61; Mon, 23 Nov 2020 13:33:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E0F5419D7C; Mon, 23 Nov 2020 13:33:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4E32950030; Mon, 23 Nov 2020 13:33:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0ANDXpCI029021 for ; Mon, 23 Nov 2020 08:33:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id B76361F0; Mon, 23 Nov 2020 13:33:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1679D620DE for ; Mon, 23 Nov 2020 13:33:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606138442; 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=oYn30zsIbK8vCfp1qKiwuhWtZJCOWpf/Yf3XudSaBwc=; b=ACHF6ZqCZQSe0CDLNxhWwzwbRmxH8aS2kOmQElr7mi1prSefEm2Y8iru+Wnh8wgenfLMTu DSxAYUFFctxHYeZ2yu9wAPZx0FN3IMMlcNuPbAxJCK8sp+ZMS2uxCWnX+BwguYV+yEdlpv KCV0NFYYv2vcf8Yfzk2uFRKvFuQsWSE= X-MC-Unique: puICQGBmONq7fIL_taNhwA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/2] qemu: snapshot: Write metadata of previously-'current' snapshot on update Date: Mon, 23 Nov 2020 14:33:43 +0100 Message-Id: <6f3dfeecaf869aa1783e866f9db7e0402f6c41cd.1606138386.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Whether a snapshot definition is considered 'current' or active is stored in the metadata XML libvirt writes when we create metadata. This means that if we are changing the 'current' snapshot we must re-write the metadata of the previously 'current' snapshot to update the field to prevent having multiple active snapshots. Unfortunately the snapshot creation code didn't do this properly, which resulted in the following error: error : qemuDomainSnapshotLoad:430 : internal error: Too many snapshots cla= iming to be current for domain snapshot-test being printed if libvirtd was terminated and restarted. Introduce qemuSnapshotSetCurrent which writes out the old snapshot's metadata when updating the current snapshot. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_snapshot.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 057b94e5b8..6ed2ce838c 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -47,6 +47,36 @@ VIR_LOG_INIT("qemu.qemu_snapshot"); +/** + * qemuSnapshotSetCurrent: Set currently active snapshot + * + * @vm: domain object + * @newcurrent: snapshot object to set as current/active + * + * Sets @newcurrent as the 'current' snapshot of @vm. This helper ensures = that + * the snapshot which was 'current' previously is updated. + */ +static void +qemuSnapshotSetCurrent(virDomainObjPtr vm, + virDomainMomentObjPtr newcurrent) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + virQEMUDriverPtr driver =3D priv->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + virDomainMomentObjPtr oldcurrent =3D virDomainSnapshotGetCurrent(vm->s= napshots); + + virDomainSnapshotSetCurrent(vm->snapshots, newcurrent); + + /* we need to write out metadata for the old snapshot to update the + * 'active' property */ + if (oldcurrent && + oldcurrent !=3D newcurrent) { + if (qemuDomainSnapshotWriteMetadata(vm, oldcurrent, driver->xmlopt= , cfg->snapshotDir) < 0) + VIR_WARN("failed to update old current snapshot"); + } +} + + /* Looks up snapshot object from VM and name */ virDomainMomentObjPtr qemuSnapObjFromName(virDomainObjPtr vm, @@ -1781,7 +1811,8 @@ qemuSnapshotCreateXML(virDomainPtr domain, endjob: if (snapshot && !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)) { if (update_current) - virDomainSnapshotSetCurrent(vm->snapshots, snap); + qemuSnapshotSetCurrent(vm, snap); + if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->xmlopt, cfg->snapshotDir) < 0) { @@ -2233,7 +2264,7 @@ qemuSnapshotRevert(virDomainObjPtr vm, cleanup: if (ret =3D=3D 0) { - virDomainSnapshotSetCurrent(vm->snapshots, snap); + qemuSnapshotSetCurrent(vm, snap); if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->xmlopt, cfg->snapshotDir) < 0) { @@ -2350,7 +2381,8 @@ qemuSnapshotDelete(virDomainObjPtr vm, if (rem.err < 0) goto endjob; if (rem.found) { - virDomainSnapshotSetCurrent(vm->snapshots, snap); + qemuSnapshotSetCurrent(vm, snap); + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->xmlopt, --=20 2.28.0 From nobody Wed May 1 23:39:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1606138566; cv=none; d=zohomail.com; s=zohoarc; b=fgzbBz/9fU0LMa8FppV+vflgznVEOZJV/sblXKnzmmnMg2w5sjdKNRRwnfMKFBgnCLw85IOv+uxVnNatkgddTxfqsNPwo/oAoSGOHg8BBoYBZm+L/Nmzv6WzZJnTyBInJBSNVjtY99dJQs5Bdu0O2FcPIzA8QnE3LxqM+Ih0WTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606138566; 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=E9fBB19CR9yEiVtZ98k6kFg24q5R2i53OIV1kMffRSU=; b=dk2/89+FSSZkoMbkxF1R0XCR950RotitjAZ9+d0DNaRlwoTw1NGnGXMi6LirVMIUcV19vVrJ8nIAppyX0mWXjMUkDkBrHUv1QbD7WLiiNHsFLs5o9vKwMwgRMiRK/DHNMAsmpeECHNHd6WkOSx93mFtl0oXGnD5BsLwC6tEqEFw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606138566957849.2421096222276; Mon, 23 Nov 2020 05:36:06 -0800 (PST) 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-113-B-WEbnoLPhe13wfBr5NqUQ-1; Mon, 23 Nov 2020 08:34:05 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4FCB1009610; Mon, 23 Nov 2020 13:33:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C46A85D9E3; Mon, 23 Nov 2020 13:33:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8F6FA180954D; Mon, 23 Nov 2020 13:33:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0ANDXqZK029029 for ; Mon, 23 Nov 2020 08:33:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id D2C701F0; Mon, 23 Nov 2020 13:33:52 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 263C81349A for ; Mon, 23 Nov 2020 13:33:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606138565; 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=E9fBB19CR9yEiVtZ98k6kFg24q5R2i53OIV1kMffRSU=; b=C09aMJJdY4rNboFmq75mmQ8XEyMEroE/d02mX5A4iaGoes0I06CLO93B1FIyfFklfF+MNk skIpM209Tr9FXFBye3In/SMMw9/zAJzzBuZEkR/mKoOduwgLZPboSIK9pm/BtNAl9FM2PX yyLaqzJ0IFnQLgYWgCf7DjSN3XA1O2E= X-MC-Unique: B-WEbnoLPhe13wfBr5NqUQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/2] qemu: checkpoint: Write metadata of previously-'current' checkpoint on update Date: Mon, 23 Nov 2020 14:33:44 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Similarly to previous commit dealing with snapshots we must rewrite the metadata of the previously-'current' checkpoint when changing which checkpoint is considered 'current'. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_checkpoint.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c index 8dce7d8756..e8d18b2e02 100644 --- a/src/qemu/qemu_checkpoint.c +++ b/src/qemu/qemu_checkpoint.c @@ -41,6 +41,36 @@ VIR_LOG_INIT("qemu.qemu_checkpoint"); +/** + * qemuCheckpointSetCurrent: Set currently active checkpoint + * + * @vm: domain object + * @newcurrent: checkpoint object to set as current/active + * + * Sets @newcurrent as the 'current' checkpoint of @vm. This helper ensure= s that + * the checkpoint which was 'current' previously is updated. + */ +static void +qemuCheckpointSetCurrent(virDomainObjPtr vm, + virDomainMomentObjPtr newcurrent) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + virQEMUDriverPtr driver =3D priv->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + virDomainMomentObjPtr oldcurrent =3D virDomainCheckpointGetCurrent(vm-= >checkpoints); + + virDomainCheckpointSetCurrent(vm->checkpoints, newcurrent); + + /* we need to write out metadata for the old checkpoint to update the + * 'active' property */ + if (oldcurrent && + oldcurrent !=3D newcurrent) { + if (qemuCheckpointWriteMetadata(vm, oldcurrent, driver->xmlopt, cf= g->checkpointDir) < 0) + VIR_WARN("failed to update old current checkpoint"); + } +} + + /* Looks up the domain object from checkpoint and unlocks the * driver. The returned domain object is locked and ref'd and the * caller must call virDomainObjEndAPI() on it. */ @@ -506,7 +536,7 @@ qemuCheckpointCreateFinalize(virQEMUDriverPtr driver, bool update_current) { if (update_current) - virDomainCheckpointSetCurrent(vm->checkpoints, chk); + qemuCheckpointSetCurrent(vm, chk); if (qemuCheckpointWriteMetadata(vm, chk, driver->xmlopt, @@ -848,7 +878,8 @@ qemuCheckpointDelete(virDomainObjPtr vm, if (rem.err < 0) goto endjob; if (rem.found) { - virDomainCheckpointSetCurrent(vm->checkpoints, chk); + qemuCheckpointSetCurrent(vm, chk); + if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) { if (qemuCheckpointWriteMetadata(vm, chk, driver->xmlopt, --=20 2.28.0