From nobody Sun Feb 8 16:05:50 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=1672919348; cv=none; d=zohomail.com; s=zohoarc; b=DU+6szYiuIUSHRGu6yUd6t/3B8wvJY90fMNgm+pAoj0dPoIqjaeNETsJZAyxnSPE+JUjbpBuLhtJ56udBzQ6dLRfMVx+Ct/7x04v25UA+eFBpB3v2CEEnMCRF4zH+6xchWGqeBf3nuHwOe8FxASXuB8A3nqXJrcmDpiK0tdOo3A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1672919348; 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=ZZpPmiUt/t0OwCv9bXcBED2sysXhP+il9/ySsTkUU0Q=; b=Ipo39dV9z7BplVC8xVV2c2ffQ9oyXDezhUXkPkt6Vup+kgJsCg7ApU5slu403XswX/yfSFnfGjqxkEP5dTyroxwdUgg/z6L6pLQongwfVrp+KanpszE+iwZcvHmKEMGBYQiRCwnxvsc90KCnrJ3QU5T+TsFADN+WoqIutRWgrlI= 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 1672919348137513.0001819058023; Thu, 5 Jan 2023 03:49:08 -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-440-iOWm4cSzNayC-pYitYZwHQ-1; Thu, 05 Jan 2023 06:47:36 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 75C7F85D07B; Thu, 5 Jan 2023 11:47:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61A882166B30; Thu, 5 Jan 2023 11:47:31 +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 5398219465A2; Thu, 5 Jan 2023 11:47:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4255B1946586 for ; Thu, 5 Jan 2023 11:47:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 347EF492D8B; Thu, 5 Jan 2023 11:47:27 +0000 (UTC) Received: from localhost.localdomain (ovpn-194-38.brq.redhat.com [10.40.194.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id C776849BB6A for ; Thu, 5 Jan 2023 11:47:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672919346; 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=ZZpPmiUt/t0OwCv9bXcBED2sysXhP+il9/ySsTkUU0Q=; b=ghzkhNisNBZUIGJFESPv0qDqGax9SySscyRyAXaingncb0SJ3LSxRceNlX8ostuW9eJiFN piaMgtqECt0XBGQ0aFGFg0AR2gEU7qg1u92zCwsVCiifHDGprHEtCTz+yFOr11X7n7bede 4ZJ5TCNxgkXKpG028GHyhlI9j1qwknQ= X-MC-Unique: iOWm4cSzNayC-pYitYZwHQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v2 16/31] qemu_snapshot: rework snapshot children deletion Date: Thu, 5 Jan 2023 12:46:52 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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.6 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: 1672919349576100001 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 a3ff195685..ce25d17c99 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 +qemuSnapshotDeleteAllHelper(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, bool children_only) { - 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, qemuSnapshotDeleteAllHelper, &d= ata); =20 - if (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 (children_only) { - virDomainMomentDropChildren(snap); - return 0; + if (!children_only && + qemuSnapshotDeleteSingle(vm, snap, metadata_only) < 0) { + return -1; } =20 - return qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only= ); + return 0; } =20 =20 --=20 2.39.0