From nobody Tue Dec 16 11:08:59 2025 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=1673027600; cv=none; d=zohomail.com; s=zohoarc; b=E9PhTpHl3AaOUwlnc9mR62gbtc4e3DqQCdFxAcRSPS42M18bmUB8ZdwcABgohKjQb0FxohJ3KvjcDMa7nIg6zg4w0rqY9EVeBqCiMCxrO+nIoLwAdKFwXZXZkAkEKGnrrOjgZVQou3RmXonK0AQkymxFhWUeEdKnYDt4k/rfolg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673027600; 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=ZqLC/OhzVfwHrLRey9maong1T76x4IObgQ1sJPb8ESk=; b=a2ywRZPWTNx2wfHhW1fejA2/Icf1Lq0ltjnMlVGkHqjdbyml5pzn/cINUVY6E0bbJJL6sigp6EeuTReLGv0XbsGh2M1Gh1wARs6F5O7dkvKwB/rpw/1H/MSW1kNJHbv6PHxEXI+uqUwyz574Qz9jbbmW0yp8+BV8lqwLwpvykqE= 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 1673027600480600.043596511889; Fri, 6 Jan 2023 09:53:20 -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-170-RhsRJa4UNY6Yy-5vGPiH1Q-1; Fri, 06 Jan 2023 12:52:31 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4360D1833FDF; Fri, 6 Jan 2023 17:52:26 +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 2E54B40C2004; Fri, 6 Jan 2023 17:52:26 +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 21D42194707C; Fri, 6 Jan 2023 17:52:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B09501946586 for ; Fri, 6 Jan 2023 17:52:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9612040C2004; Fri, 6 Jan 2023 17:52:24 +0000 (UTC) Received: from antique-work.redhat.com (ovpn-193-172.brq.redhat.com [10.40.193.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34A0940C2064 for ; Fri, 6 Jan 2023 17:52:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673027599; 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=ZqLC/OhzVfwHrLRey9maong1T76x4IObgQ1sJPb8ESk=; b=bTmLqnrJI0zQ6XnWTt2gHI2dCdk3HljRM8tTHJbibW+GkOC0+2FK0nngJiejhKrg5ajhIO deYRXdMIvxYLjhibJrKILpt0R5OL4atNjJIpX5HPO0HaH68iDZu6PaAhtx233+R8c57un9 ys6QA1mcXN7fiHkkxMIe7mD6cmdGwtY= X-MC-Unique: RhsRJa4UNY6Yy-5vGPiH1Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 15/32] qemu_snapshot: introduce qemuSnapshotDeleteChildren Date: Fri, 6 Jan 2023 18:51:50 +0100 Message-Id: <1e683f8c4e32d81c076a5ceeb79775d64646ec1d.1673027206.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.1 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: 1673027601355100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Extract code that deletes children of specific snapshot to separate function. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 109 ++++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index e85655924a..e65eef8a0d 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2311,18 +2311,76 @@ qemuSnapshotDeleteSingle(virDomainObj *vm, } =20 =20 -int -qemuSnapshotDelete(virDomainObj *vm, - virDomainSnapshotPtr snapshot, - unsigned int flags) +/** + * qemuSnapshotDeleteChildren: + * @vm: domain object + * @snap: snapshot object + * @metadata_only: if true only snapshots metadata are deleted + * @children_only: if true only snapshot children are deleted + * + * Delete children snapshots of snapshot provided by @snap. If @metadata_o= nly + * is true only snapshot metadata files are delete, disk data are left int= act. + * If @children_only is true it will delete only children snapshots of @sn= ap + * and leave @snap intact. + * + * Returns 0 on success, -1 on error. + */ +static int +qemuSnapshotDeleteChildren(virDomainObj *vm, + virDomainMomentObj *snap, + bool metadata_only, + bool children_only) { - virQEMUDriver *driver =3D snapshot->domain->conn->privateData; - int ret =3D -1; - virDomainMomentObj *snap =3D NULL; virQEMUMomentRemove rem; + qemuDomainObjPrivate *priv =3D vm->privateData; + virQEMUDriver *driver =3D priv->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + + 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); + + 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 (children_only) { + virDomainMomentDropChildren(snap); + return 0; + } + + return qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only= ); +} + + +int +qemuSnapshotDelete(virDomainObj *vm, + virDomainSnapshotPtr snapshot, + unsigned int flags) +{ + int ret =3D -1; + virDomainMomentObj *snap =3D NULL; bool metadata_only =3D !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_= ONLY); int external =3D 0; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); =20 virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY | @@ -2353,39 +2411,8 @@ qemuSnapshotDelete(virDomainObj *vm, =20 if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { - 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) - goto endjob; - if (rem.found) { - qemuSnapshotSetCurrent(vm, snap); - - 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 curre= nt"), - snap->def->name); - virDomainSnapshotSetCurrent(vm->snapshots, NULL); - goto endjob; - } - } - } - - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { - virDomainMomentDropChildren(snap); - ret =3D 0; - } else { - ret =3D qemuDomainSnapshotDiscard(driver, vm, snap, true, meta= data_only); - } + bool children_only =3D !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILD= REN_ONLY); + ret =3D qemuSnapshotDeleteChildren(vm, snap, metadata_only, childr= en_only); } else { ret =3D qemuSnapshotDeleteSingle(vm, snap, metadata_only); } --=20 2.39.0