From nobody Sat Feb 7 06:13:32 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=1670506315; cv=none; d=zohomail.com; s=zohoarc; b=CK49z1eDbionZtyNIEtFyek9cDFk8pggonxsBELryi8G1OiBX2+pK54NjpobOgjjgiCT6hx+7u6hOCwJdThyty2z4olzlZz/YMPRKLFVT2Ga2Kjgi5HQCJdWmcQxbjV/3HtozHvQjE30LezNp8Qweh3m2FPCMnh8zYrxBubobG0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670506315; 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=eV8cthKNxCIwh8+2LzPLW8vEOgztsXwezBAGpiDELYU=; b=NJyImhVUVCXAiPYpwtSIQeoHWoJuu4Ih1JYaX3ESfJFx3kHuT62uS1P7yj60ud9+Qy2nzuYhRPmx/RmnPoi9rjeCFZwD+ySRfaUdbMJr+9Ji4aM8wbUKN6q75RJJmMU0fc5mqmUOthvQzWkPCQxIdNPQXkB/9GSqZxtP7ioirT8= 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 1670506315485961.0653866971523; Thu, 8 Dec 2022 05:31:55 -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-423-hKe_8GSWPGybf3JtZZB76g-1; Thu, 08 Dec 2022 08:31:39 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8CE0686C044; Thu, 8 Dec 2022 13:31:32 +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 6B149477F64; Thu, 8 Dec 2022 13:31:32 +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 004511946A7E; Thu, 8 Dec 2022 13:31:31 +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 212111946A4B for ; Thu, 8 Dec 2022 13:31:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7F3A840C6F73; Thu, 8 Dec 2022 13:31:25 +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 162E440C6DC7 for ; Thu, 8 Dec 2022 13:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670506314; 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=eV8cthKNxCIwh8+2LzPLW8vEOgztsXwezBAGpiDELYU=; b=W8DvBRb1PR1k3OSy5z3u7XdEeAxlbiFFJO6XeM4AQmuAnK9JIXcDNbKFFYkNN7+PKGhJSX FcpxK5uuwtgEq6KtygbXIo+fRrwypl7oln1miEhxbDWVbvHAp/MCnTtjrULzezyA4sGS7Q xrGlGTC+Bxr+X6pP2ZxMR2sBpdSASns= X-MC-Unique: hKe_8GSWPGybf3JtZZB76g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 15/30] qemu_snapshot: rework snapshot children deletion Date: Thu, 8 Dec 2022 14:30:51 +0100 Message-Id: <6534c24cbf4dd932edf8c1923ca9bafe28f656d9.1670505851.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.9 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: 1670506316356100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This simplifies the code a bit by reusing existing parts that deletes a single snapshot. The drawback of this change is that we will now call the re-parent bits to keep the metadata in sync for every child even though it will get deleted as well. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 69 +++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 3d5467457b..846f6e9e53 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2311,6 +2311,31 @@ qemuSnapshotDeleteSingle(virDomainObj *vm, } =20 =20 +struct qemuSnapshotDeleteAllData { + virDomainObj *vm; + bool metadata_only; + int error; +}; + + +static int +qemuSnapshotDeleteAll(void *payload, + const char *name G_GNUC_UNUSED, + void *opaque) +{ + int error; + virDomainMomentObj *snap =3D payload; + struct qemuSnapshotDeleteAllData *data =3D opaque; + + error =3D qemuSnapshotDeleteSingle(data->vm, snap, data->metadata_only= ); + + if (error !=3D 0) + data->error =3D error; + + return 0; +} + + /** * qemuSnapshotDeleteChildren: * @vm: domain object @@ -2331,44 +2356,22 @@ qemuSnapshotDeleteChildren(virDomainObj *vm, bool metadata_only, unsigned int flags) { - virQEMUMomentRemove rem; - qemuDomainObjPrivate *priv =3D vm->privateData; - virQEMUDriver *driver =3D priv->driver; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + struct qemuSnapshotDeleteAllData data =3D { + .vm =3D vm, + .metadata_only =3D metadata_only, + }; =20 - rem.driver =3D driver; - rem.vm =3D vm; - rem.metadata_only =3D metadata_only; - rem.err =3D 0; - rem.current =3D virDomainSnapshotGetCurrent(vm->snapshots); - rem.found =3D false; - rem.momentDiscard =3D qemuDomainSnapshotDiscard; - virDomainMomentForEachDescendant(snap, qemuDomainMomentDiscardAll, - &rem); - if (rem.err < 0) - return -1; - if (rem.found) { - qemuSnapshotSetCurrent(vm, snap); + virDomainMomentForEachDescendant(snap, qemuSnapshotDeleteAll, &data); =20 - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { - if (qemuDomainSnapshotWriteMetadata(vm, snap, - driver->xmlopt, - cfg->snapshotDir) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to set snapshot '%s' as current"), - snap->def->name); - virDomainSnapshotSetCurrent(vm->snapshots, NULL); - return -1; - } - } - } + if (data.error < 0) + return -1; =20 - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { - virDomainMomentDropChildren(snap); - return 0; + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN && + qemuSnapshotDeleteSingle(vm, snap, metadata_only) < 0) { + return -1; } =20 - return qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only= ); + return 0; } =20 =20 --=20 2.38.1