From nobody Sat Feb 7 06:21:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1670506323; cv=none; d=zohomail.com; s=zohoarc; b=dHqGPK2TjLYCRLkthYGHDgLk57xpdCQ1naPLTdcXy2Oby7f8fFj9qDZm6FacPNjCDXF0zDfgQE3/e+iVzH8pXa+/45UmDK8sH8nJF5DDNbszpCvk1U00yk8cGslK9FY+Tbxs0wzHqRQ5vCpy4L/K9h7G318YCmCu7tHI0OqJew8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670506323; 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=jcmXE2Kfmd14v4O83v7FRsodonEhJBN64bNV1qEGhds=; b=fxVrKCBHfRaEcoVfKK8HeOXDYdbbqy+XU5RRFen9vMBYD1kslW5h7DBXcPw/aS9O5yS7zwOZx9A6Lswyjt83Vtom1LKFrVq83cXJLjSgwsYDO/DX4oGF5xjl8UpdADEbZ6c7eiyk1QHsrSMypdddxbKQFUBRwGoNcKV6kmhHmdE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1670506323838419.9218351848667; Thu, 8 Dec 2022 05:32:03 -0800 (PST) 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-356-WHmZrh33MHujAJ3aIAG0CA-1; Thu, 08 Dec 2022 08:31:57 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4284C857FAB; Thu, 8 Dec 2022 13:31:52 +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 2BFE4111F3BB; Thu, 8 Dec 2022 13:31:52 +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 475131947050; Thu, 8 Dec 2022 13:31:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 35944194706F for ; Thu, 8 Dec 2022 13:31:28 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 21E9140C6EC2; Thu, 8 Dec 2022 13:31:28 +0000 (UTC) Received: from localhost.localdomain (ovpn-194-45.brq.redhat.com [10.40.194.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id B02AB40C6EC3 for ; Thu, 8 Dec 2022 13:31:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670506322; 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=jcmXE2Kfmd14v4O83v7FRsodonEhJBN64bNV1qEGhds=; b=BS/s22WK0t/HhnlM5AERGogQz5w1kl0ZpmXMcUQF0VDx0SvTJwWqEUnfyVthQa0IY+PhA6 W1vxu1+Y/qUdfvBIzgr/7vaZhBGNaj6Re5GfqDs/PQDEotkrAvuyzx4wmhUKYFwSHJP3Yb uMKJfIC10opNFimd2weXO85mgcNv4qM= X-MC-Unique: WHmZrh33MHujAJ3aIAG0CA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 18/30] qemu_snapshot: introduce qemuSnapshotDiscardMetadata Date: Thu, 8 Dec 2022 14:30:54 +0100 Message-Id: <1cb74d2bb546374f3fcc5cc25dee155a8d4b9f21.1670505852.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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.3 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: 1670506324404100008 Content-Type: text/plain; charset="utf-8"; x-default="true" Extract the code deleting external snapshot metadata to separate function. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 91 +++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 5418496c1e..4ea3f578e9 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2281,47 +2281,15 @@ qemuSnapshotChildrenReparent(void *payload, } =20 =20 -/* Discard one snapshot (or its metadata), without reparenting any childre= n. */ static int -qemuSnapshotDiscard(virQEMUDriver *driver, - virDomainObj *vm, - virDomainMomentObj *snap, - bool update_parent, - bool metadata_only) +qemuSnapshotDiscardMetadata(virDomainObj *vm, + virDomainMomentObj *snap, + bool update_parent) { + qemuDomainObjPrivate *priv =3D vm->privateData; + virQEMUDriver *driver =3D priv->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); g_autofree char *snapFile =3D NULL; - qemuDomainObjPrivate *priv; - virDomainMomentObj *parentsnap =3D NULL; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - - if (!metadata_only) { - if (!virDomainObjIsActive(vm)) { - size_t i; - /* Ignore any skipped disks */ - - /* Prefer action on the disks in use at the time the snapshot = was - * created; but fall back to current definition if dealing wit= h a - * snapshot created prior to libvirt 0.9.5. */ - virDomainDef *def =3D snap->def->dom; - - if (!def) - def =3D vm->def; - - for (i =3D 0; i < def->ndisks; i++) { - if (virDomainDiskTranslateSourcePool(def->disks[i]) < 0) - return -1; - } - - if (qemuDomainSnapshotForEachQcow2(driver, def, snap, "-d", tr= ue) < 0) - return -1; - } else { - priv =3D vm->privateData; - qemuDomainObjEnterMonitor(vm); - /* we continue on even in the face of error */ - qemuMonitorDeleteSnapshot(priv->mon, snap->def->name); - qemuDomainObjExitMonitor(vm); - } - } =20 if (update_parent) { if (snap->nchildren) { @@ -2348,6 +2316,7 @@ qemuSnapshotDiscard(virQEMUDriver *driver, if (snap =3D=3D virDomainSnapshotGetCurrent(vm->snapshots)) { virDomainSnapshotSetCurrent(vm->snapshots, NULL); if (update_parent && snap->def->parent_name) { + virDomainMomentObj *parentsnap =3D NULL; parentsnap =3D virDomainSnapshotFindByName(vm->snapshots, snap->def->parent_nam= e); if (!parentsnap) { @@ -2376,6 +2345,52 @@ qemuSnapshotDiscard(virQEMUDriver *driver, } =20 =20 +/* Discard one snapshot (or its metadata), without reparenting any childre= n. */ +static int +qemuSnapshotDiscard(virQEMUDriver *driver, + virDomainObj *vm, + virDomainMomentObj *snap, + bool update_parent, + bool metadata_only) +{ + qemuDomainObjPrivate *priv; + + if (!metadata_only) { + if (!virDomainObjIsActive(vm)) { + size_t i; + /* Ignore any skipped disks */ + + /* Prefer action on the disks in use at the time the snapshot = was + * created; but fall back to current definition if dealing wit= h a + * snapshot created prior to libvirt 0.9.5. */ + virDomainDef *def =3D snap->def->dom; + + if (!def) + def =3D vm->def; + + for (i =3D 0; i < def->ndisks; i++) { + if (virDomainDiskTranslateSourcePool(def->disks[i]) < 0) + return -1; + } + + if (qemuDomainSnapshotForEachQcow2(driver, def, snap, "-d", tr= ue) < 0) + return -1; + } else { + priv =3D vm->privateData; + qemuDomainObjEnterMonitor(vm); + /* we continue on even in the face of error */ + qemuMonitorDeleteSnapshot(priv->mon, snap->def->name); + qemuDomainObjExitMonitor(vm); + } + } + + if (qemuSnapshotDiscardMetadata(vm, snap, update_parent) < 0) + return -1; + + return 0; +} + + int qemuSnapshotDiscardAllMetadata(virQEMUDriver *driver, virDomainObj *vm) --=20 2.38.1