From nobody Tue Feb 10 04:13:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1588765389; cv=none; d=zohomail.com; s=zohoarc; b=fVKKwmRGnm0MIL4FqrNbj5NgkMeEyfmLta1hVVDGpHTR7J71Q1nX8ghP8TsIiBo1YXzeSQovUwg8LxuxA7rYiyXJyaR3ID8LxhKRyuV+sZrnrxPVdzo0YpQ0HMxFn/Pe1qTd41/YZuTPaqulfitVbWRVaE4bkS0Ey32Mkgd2uYw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588765389; h=Content-Type:Content-Transfer-Encoding:Cc: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=4VBEPpVclKw/bSdKgq0HigI16KCALYLYi3jeNfR7C7c=; b=a0Lnm6a8kKgmRSToEp4bQUZKbzcHJ+fodhWaQLJAFhfc9gfC8SDVMfwdiaf3SMHfhGQLsxPFCSqw3eEF98LXO0EZSzZHmSq0xQ7yZV6n9++dTF0uxDw6C96Zp9gLqx8+pyzd2xy3XiOELRuz+4ZfIumf1pHEXvabWRggvwqcWJU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1588765389299369.67269012925976; Wed, 6 May 2020 04:43:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-177-wqd6mypTMpSJ_wXGgrBA4Q-1; Wed, 06 May 2020 07:43:05 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C831B1B18BC0; Wed, 6 May 2020 11:42:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A337C5D9C5; Wed, 6 May 2020 11:42:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 653E64CAA7; Wed, 6 May 2020 11:42:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 046Bgc1i026822 for ; Wed, 6 May 2020 07:42:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id B2113100239A; Wed, 6 May 2020 11:42:38 +0000 (UTC) Received: from ibm-p8-15-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (unknown [10.40.195.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAFFB10013D9; Wed, 6 May 2020 11:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588765388; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=4VBEPpVclKw/bSdKgq0HigI16KCALYLYi3jeNfR7C7c=; b=Gi6tZJDwxJwDFmLaMAJ2Hn65fKy4J/LnOBlMEn9PH/yInDstWvm+YQJYbei5n85L+ZgmSz GU8Zr3t3gJqCOjnace+VunLLMfXhPuke0s/oQUUCub4K/j/2zHlLoNtEyNw8gTUIoGVwyf Ct2iDpnjsd6Xc4HXBZpvHuRCtPtM7lc= X-MC-Unique: wqd6mypTMpSJ_wXGgrBA4Q-1 From: Pavel Mores To: libvir-list@redhat.com Subject: [libvirt PATCH v2 09/10] qemu: block: add external snapshot-delete top-level algorithm Date: Wed, 6 May 2020 13:42:25 +0200 Message-Id: <20200506114226.2538196-10-pmores@redhat.com> In-Reply-To: <20200506114226.2538196-1-pmores@redhat.com> References: <20200506114226.2538196-1-pmores@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Pavel Mores X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This uses the helpers introduced in previous three commits and assembles the top-level snapshot deletion algorithm in their terms. Note that the third phase - waiting for blockcommits to finish - is conceptually optional and a flag/parameter might be exposed to the user in the future to skip the third phase. This would make the whole operation asynchronous and let the user deal with concluding the blockcommits manually, using the generic blockjob tools. Signed-off-by: Pavel Mores --- src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 935ef7303b..f68eb500ec 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1049,6 +1049,7 @@ virDomainListCheckpoints; # conf/virdomainmomentobjlist.h virDomainMomentDropChildren; virDomainMomentDropParent; +virDomainMomentFindLeaf; virDomainMomentForEachChild; virDomainMomentForEachDescendant; virDomainMomentMoveChildren; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a2629e9002..57e81e3720 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17000,6 +17000,70 @@ qemuDomainSnapshotDeleteExternalWaitForJobs(virDom= ainObjPtr vm, } =20 =20 +static int +qemuDomainSnapshotDeleteExternal(virDomainObjPtr vm, + virQEMUDriverPtr driver, + virDomainMomentObjPtr snap, + unsigned int flags) +{ + /* TODO Apr 29, 2020: ultimately, use 'flags' to set this. Until that + * is supported, just run always synchronously. */ + bool async =3D false; + virDomainSnapshotDefPtr snapdef =3D virDomainSnapshotObjGetDef(snap); + virDomainMomentObjPtr leaf =3D snap->nchildren ? virDomainMomentFindLe= af(snap) : snap; + virDomainMomentObjPtr parent =3D snap->parent; + g_autofree virBlockCommitDesc *blockCommitDescs =3D NULL; + int numBlockCommits =3D snapdef->ndisks; + + /* This function only works if the chain below 'snap' is linear. If + * there's no unique leaf it means the chain of 'snap's children + * branches at some point. Also, if there *is* a leaf but it's not + * the current snapshot, bail out as well. */ + if (leaf =3D=3D NULL) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("can't delete '%s', snapshot chain branches"), + snapdef->parent.name); + return -1; + } + if (leaf !=3D virDomainSnapshotGetCurrent(vm->snapshots)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("can't delete '%s', leaf snapshot is not current"= ), + snapdef->parent.name); + return -1; + } + if (parent->nchildren > 1) { + /* TODO 'snap's parent has multiple children, meaning it's a + * branching point in snapshot tree. This means we can't + * delete 'snap' by commiting into its parent as doing so would + * corrupt the other branches rooted in the parent. We might + * still be able to delete 'snap' though by pulling into its + * child/children. */ + + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("can't delete %s, its parent has multiple childre= n"), + snapdef->parent.name); + return -1; + } + + if (!virDomainObjIsActive(vm)) + return -1; + + blockCommitDescs =3D qemuDomainSnapshotDeleteExternalGetJobDescriptors= (vm, snap, flags); + if (blockCommitDescs =3D=3D NULL) + return -1; + + if (qemuDomainSnapshotDeleteExternalLaunchJobs(vm, driver, blockCommit= Descs, numBlockCommits) < 0) + return -1; + + if (!async) { + if (qemuDomainSnapshotDeleteExternalWaitForJobs(vm, driver, blockC= ommitDescs, numBlockCommits) < 0) + return -1; + } + + return 0; +} + + static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags) --=20 2.24.1