From nobody Sun Feb 8 18:31:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1600947930; cv=none; d=zohomail.com; s=zohoarc; b=SFvM6MuLCd51b2pRuVbv77NWAej1ALWusM+fVUcPVCQGhBxKOigXiaRj7GGzBZgJT1wsIh/KGd7MObIEMnhZ2iZt3LOqwyYHWMum2Y9+975pR8xm6HvNCR8yN+nmho+ACrncuF2tbYlh4flteZerW30CJkicVBRdkWdoMvfHgJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600947930; 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=0h9w8Zu/jh3RYCX+Bo83W0x0Ja63r5shB46O+t2kal8=; b=Mx1LXRxOxAf3qYk6OMrAOSvGTXDDW2xXC+UH++61Y3V94y3wgFm1DyPhVb3cb6yK/CDOMAW76hB9dUZCKExN6GIs66pyLrG2p6TcQRdKnn/dLRVxEWBKAxINv+npdbmhVcnGCJsQg/4k3JUda7NsIbpHm7y62ldiZlUVXpaxmbk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600947930978308.7607805251497; Thu, 24 Sep 2020 04:45:30 -0700 (PDT) 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-424-cQ5xQPFTNkiRyDRCxJsFcg-1; Thu, 24 Sep 2020 07:45:27 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE4BA801001; Thu, 24 Sep 2020 11:45:21 +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 BDA835C1C7; Thu, 24 Sep 2020 11:45:21 +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 8BDA179FF7; Thu, 24 Sep 2020 11:45:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08OBi8Jx009057 for ; Thu, 24 Sep 2020 07:44:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 236D89F58; Thu, 24 Sep 2020 11:44:08 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 367046115F; Thu, 24 Sep 2020 11:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600947929; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=0h9w8Zu/jh3RYCX+Bo83W0x0Ja63r5shB46O+t2kal8=; b=D27LK9wfX8bEAisDE5Ea1bgKqNHL5J12SN1pwUX7wIm2P3zSIF36wBm5noE7zERG/Qfxml TRpBYIi/kBReWRHaZp0Zk45YFgzLEsmWNZUgXg6JZfYtrAeJvsOBakH4K93P+ZG3uNVlOf 0RBACcnGYdWIIGAkmpc1YYcQIxM4A8w= X-MC-Unique: cQ5xQPFTNkiRyDRCxJsFcg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v4 03/11] qemu: snapshot: Introduce helpers for creating overlays on disks Date: Thu, 24 Sep 2020 13:43:50 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Masayoshi Mizuma 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.16 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" To implement disks we'll need to install an overlay on top of the original disk image which will be discarded after the VM is turned off. This was initially implemented by qemu but libvirt never picked up this option. With blockdev the qemu feature became unsupported so we need to do this via the snapshot code anyways. The helpers introduced in this patch prepare a fake snapshot disk definition for a disk which is configured as and use it to create a snapshot (without actually modifying metada or persistent def). Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko Tested-by: Masayoshi Mizuma --- src/qemu/qemu_snapshot.c | 91 +++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_snapshot.h | 5 +++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index ca051071aa..d10e7b6b3a 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -986,6 +986,7 @@ qemuSnapshotDiskPrepareOne(virDomainObjPtr vm, qemuSnapshotDiskDataPtr dd, virHashTablePtr blockNamedNodeData, bool reuse, + bool updateConfig, qemuDomainAsyncJob asyncJob, virJSONValuePtr actions) { @@ -1008,7 +1009,8 @@ qemuSnapshotDiskPrepareOne(virDomainObjPtr vm, return -1; /* modify disk in persistent definition only when the source is the sa= me */ - if (vm->newDef && + if (updateConfig && + vm->newDef && (persistdisk =3D virDomainDiskByTarget(vm->newDef, dd->disk->dst))= && virStorageSourceIsSameLocation(dd->disk->src, persistdisk->src)) { @@ -1116,6 +1118,54 @@ qemuSnapshotDiskPrepareActiveExternal(virDomainObjPt= r vm, snapctxt->dd + snapctxt->ndd++, blockNamedNodeData, reuse, + true, + asyncJob, + snapctxt->actions) < 0) + return NULL; + } + + return g_steal_pointer(&snapctxt); +} + + +static qemuSnapshotDiskContextPtr +qemuSnapshotDiskPrepareDisksTransient(virDomainObjPtr vm, + virQEMUDriverConfigPtr cfg, + virHashTablePtr blockNamedNodeData, + qemuDomainAsyncJob asyncJob) +{ + g_autoptr(qemuSnapshotDiskContext) snapctxt =3D NULL; + size_t i; + + snapctxt =3D qemuSnapshotDiskContextNew(vm->def->ndisks, vm, asyncJob); + + for (i =3D 0; i < vm->def->ndisks; i++) { + virDomainDiskDefPtr domdisk =3D vm->def->disks[i]; + g_autoptr(virDomainSnapshotDiskDef) snapdisk =3D g_new0(virDomainS= napshotDiskDef, 1); + + if (!domdisk->transient) + continue; + + /* validation code makes sure that we do this only for local disks + * with a file source */ + snapdisk->name =3D g_strdup(domdisk->dst); + snapdisk->snapshot =3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL; + snapdisk->src =3D virStorageSourceNew(); + snapdisk->src->type =3D VIR_STORAGE_TYPE_FILE; + snapdisk->src->format =3D VIR_STORAGE_FILE_QCOW2; + snapdisk->src->path =3D g_strdup_printf("%s.TRANSIENT", domdisk->s= rc->path); + if (virFileExists(snapdisk->src->path)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("Overlay file '%s' for transient disk '%s' al= ready exists"), + snapdisk->src->path, domdisk->dst); + return NULL; + } + + if (qemuSnapshotDiskPrepareOne(vm, cfg, domdisk, snapdisk, + snapctxt->dd + snapctxt->ndd++, + blockNamedNodeData, + false, + false, asyncJob, snapctxt->actions) < 0) return NULL; @@ -1253,6 +1303,45 @@ qemuSnapshotCreateActiveExternalDisks(virDomainObjPt= r vm, } +/** + * qemuSnapshotCreateDisksTransient: + * @vm: domain object + * @asyncJob: qemu async job type + * + * Creates overlays on top of disks which are configured as . = Note + * that the validation code ensures that disks have appropriate + * configuration. + */ +int +qemuSnapshotCreateDisksTransient(virDomainObjPtr vm, + qemuDomainAsyncJob asyncJob) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + virQEMUDriverPtr driver =3D priv->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + g_autoptr(qemuSnapshotDiskContext) snapctxt =3D NULL; + g_autoptr(virHashTable) blockNamedNodeData =3D NULL; + + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (!(blockNamedNodeData =3D qemuBlockGetNamedNodeData(vm, asyncJo= b))) + return -1; + + if (!(snapctxt =3D qemuSnapshotDiskPrepareDisksTransient(vm, cfg, + blockNamedN= odeData, + asyncJob))) + return -1; + + if (qemuSnapshotDiskCreate(snapctxt, cfg) < 0) + return -1; + } + + /* the overlays are established, so they can be deleted on a shutdown = */ + priv->inhibitDiskTransientDelete =3D false; + + return 0; +} + + static int qemuSnapshotCreateActiveExternal(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_snapshot.h b/src/qemu/qemu_snapshot.h index 8b3ebe87b1..cf9bfec542 100644 --- a/src/qemu/qemu_snapshot.h +++ b/src/qemu/qemu_snapshot.h @@ -21,6 +21,7 @@ #include "virconftypes.h" #include "datatypes.h" #include "qemu_conf.h" +#include "qemu_domainjob.h" virDomainMomentObjPtr qemuSnapObjFromName(virDomainObjPtr vm, @@ -53,3 +54,7 @@ int qemuSnapshotDelete(virDomainObjPtr vm, virDomainSnapshotPtr snapshot, unsigned int flags); + +int +qemuSnapshotCreateDisksTransient(virDomainObjPtr vm, + qemuDomainAsyncJob asyncJob); --=20 2.26.2