From nobody Thu Apr 16 06:30:34 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=1692005811; cv=none; d=zohomail.com; s=zohoarc; b=cybJjxfJOD+1QMalZSSvAjrFWqcsyB1/0/R6+67h1R7al13NrtE7NzsIzsi7sOr6WuogmtpoPhr0uaVoMYgeQAGUNbpcz+rvhMfFS8fMyA+NTwt0wGzXcox0Q1qB05UrrlwYVz82qJEMretUb59M0/gFk8+JRAmSazZXsUVDySU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005811; 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=uPmo3WC0qoniibDb5bNxqEc8ECj2lnR0nOqdqEbt0LE=; b=PaI5BkD5UKu8yJHPVIQZLxDoRK/5hDnZfdrCD4oXeXKR5qYEdgDH5iL9nI/gIfldKZJ5EHd7zzXlXWQ3eTjo6MqwMSWaVIZTFHo0B4ekt7E57t/Mut+WnfIjn5StjIBQVHnZswhbcKWgW6mpf3Nf7Mi2BZEIPuuMSVF2qVheIT4= 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 1692005811939543.4112842876503; Mon, 14 Aug 2023 02:36:51 -0700 (PDT) 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-99-K8zdw8_3P8KUTSMOOUANuQ-1; Mon, 14 Aug 2023 05:36:45 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC33985D082; Mon, 14 Aug 2023 09:36:43 +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 9576F4021B9; Mon, 14 Aug 2023 09:36:41 +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 B31F81946595; Mon, 14 Aug 2023 09:36:39 +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 A5BF3194658D for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 36B5240C207C; Mon, 14 Aug 2023 09:36:27 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD61A40C2073 for ; Mon, 14 Aug 2023 09:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005810; 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=uPmo3WC0qoniibDb5bNxqEc8ECj2lnR0nOqdqEbt0LE=; b=HK09Ix/kGn88kjdHOptbMJKi8BdWca0Ji0bydtMVI2ZLyRdoKO7YpQkyZxrkPCPCzkJEag PiPMvdWx0VIHM3yQyg6k7s9rlnGBQTh0w0TxNx/Mn1Tr+y+W6dr+WR4D4MXMnFiXItwMZu P98WanBZg4mnyIJwDHJJj5+eHU7TUvE= X-MC-Unique: K8zdw8_3P8KUTSMOOUANuQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 14/25] qemu_snapshot: extract external snapshot delete prepare to function Date: Mon, 14 Aug 2023 11:36:06 +0200 Message-ID: <1e380eb9c863ef7d2e61173ff49bc0fa6a1e7888.1692005543.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.10 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: 1692005812885100003 Content-Type: text/plain; charset="utf-8"; x-default="true" This part of code is about to grow to make deletion work when user reverts to non-leaf snapshot. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 104 ++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 34 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index dd88e478b8..c3d17b4cee 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2706,6 +2706,73 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj *= vm, } =20 =20 +/** + * qemuSnapshotDeleteExternalPrepare: + * @vm: domain object + * @snap: snapshot object we are deleting + * @flags: flags passed to virDomainSnapshotDelete + * @externalData: pointer to GSList of qemuSnapshotDeleteExternalData + * @stop_qemu: pointer to boolean indicating QEMU process was started + * + * Validates and prepares data for snapshot @snap we are deleting and + * store it in @externalData. For offline VMs we need to start QEMU + * process in order to delete external snapshots and caller will need + * to stop that process, @stop_qemu will be set to True. + * + * Return 0 on success, -1 on error. + */ +static int +qemuSnapshotDeleteExternalPrepare(virDomainObj *vm, + virDomainMomentObj *snap, + unsigned int flags, + GSList **externalData, + bool *stop_qemu) +{ + virQEMUDriver *driver =3D ((qemuDomainObjPrivate *) vm->privateData)->= driver; + g_autoslist(qemuSnapshotDeleteExternalData) tmpData =3D NULL; + + if (!virDomainSnapshotIsExternal(snap)) + return 0; + + if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | + VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { + return 0; + } + + /* this also serves as validation whether the snapshot can be deleted = */ + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, &tmpData) < 0) + return -1; + + if (!virDomainObjIsActive(vm)) { + if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB_SNAPSHO= T, + NULL, -1, NULL, NULL, + VIR_NETDEV_VPORT_PROFILE_OP_CREATE, + VIR_QEMU_PROCESS_START_PAUSED) < 0) { + return -1; + } + + *stop_qemu =3D true; + + /* Call the prepare again as some data require that the VM is + * running to get everything we need. */ + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, externalData) = < 0) + return -1; + } else { + qemuDomainJobPrivate *jobPriv =3D vm->job->privateData; + + *externalData =3D g_steal_pointer(&tmpData); + + /* If the VM is running we need to indicate that the async snapshot + * job is snapshot delete job. */ + jobPriv->snapshotDelete =3D true; + + qemuDomainSaveStatus(vm); + } + + return 0; +} + + typedef struct _virQEMUMomentReparent virQEMUMomentReparent; struct _virQEMUMomentReparent { const char *dir; @@ -3476,40 +3543,9 @@ qemuSnapshotDelete(virDomainObj *vm, if (qemuSnapshotDeleteValidate(vm, snap, flags) < 0) goto endjob; =20 - if (virDomainSnapshotIsExternal(snap) && - !(flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | - VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY))) { - g_autoslist(qemuSnapshotDeleteExternalData) tmpData =3D NULL; - - /* this also serves as validation whether the snapshot can be = deleted */ - if (qemuSnapshotDeleteExternalPrepareData(vm, snap, &tmpData) = < 0) - goto endjob; - - if (!virDomainObjIsActive(vm)) { - if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB= _SNAPSHOT, - NULL, -1, NULL, NULL, - VIR_NETDEV_VPORT_PROFILE_OP_CREATE, - VIR_QEMU_PROCESS_START_PAUSED) < 0) { - goto endjob; - } - - stop_qemu =3D true; - - /* Call the prepare again as some data require that the VM= is - * running to get everything we need. */ - if (qemuSnapshotDeleteExternalPrepareData(vm, snap, &exter= nalData) < 0) - goto endjob; - } else { - qemuDomainJobPrivate *jobPriv =3D vm->job->privateData; - - externalData =3D g_steal_pointer(&tmpData); - - /* If the VM is running we need to indicate that the async= snapshot - * job is snapshot delete job. */ - jobPriv->snapshotDelete =3D true; - - qemuDomainSaveStatus(vm); - } + if (qemuSnapshotDeleteExternalPrepare(vm, snap, flags, + &externalData, &stop_qemu) <= 0) { + goto endjob; } } =20 --=20 2.41.0