From nobody Mon Feb 9 02:27:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575995162; cv=none; d=zohomail.com; s=zohoarc; b=KueCAOhBmcE9OiZQ35nXJjJ1z8V7GBI7e10cOKgMK+eu6N3mqyoB3feAqJnZAn4KM+q8Aa7r8rZBSEWTiRdEV4qBQynQvaufg5/CTyZOBjsBkUp3X1nkmliaTPWexZ1TxkMV1zwfSBNMhsJDJaMVmGQLQvHc2qqBnj0LvRTasT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575995162; 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=OR5jijFjP61naTHUrkpQIGk9YhodlcrvVu/nO444Xjs=; b=IJmaz4eivb1dvDKGwi4QV807ohbgwLNa/Fjs0tXU1A+/AqnP5ZtANLrgfcssM8i0N22CCr5tg1SoAljcHyTrdqD7qq8jt2MRhsW3EIunGoLkJoCt56Ik0IfQtEz8EcXXLDFztPo2GfXcRqcX7cnHx8x2/R1RxuCRNV5wNmme48I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575995162107939.3868879319659; Tue, 10 Dec 2019 08:26:02 -0800 (PST) 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-79-bADXsOTENLWXdd5jxZ_iVw-1; Tue, 10 Dec 2019 11:25:56 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97466189DF47; Tue, 10 Dec 2019 16:25:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 628B35C219; Tue, 10 Dec 2019 16:25:50 +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 131CA18034E9; Tue, 10 Dec 2019 16:25:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBAGPm1Y006214 for ; Tue, 10 Dec 2019 11:25:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3BFAC19486; Tue, 10 Dec 2019 16:25:48 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E6A819C6A; Tue, 10 Dec 2019 16:25:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575995158; 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=OR5jijFjP61naTHUrkpQIGk9YhodlcrvVu/nO444Xjs=; b=edrzFATb4f8xyArn/2hLoxlWD0iJ2rei/UDN6yS3dmd1YNglc+RF4EidqNpINT/Zr8gn7L ypCMR1RxE/KXql4wCIHfqnEWrUcktsF2ggphRi3/t4lekQT18tT/yXu474SzuQEXPrkHTU LPsF/VPIHu4gyBvqXxF1D+5mgNW9Fg8= From: Pavel Mores To: libvir-list@redhat.com Date: Tue, 10 Dec 2019 17:25:39 +0100 Message-Id: <20191210162541.15432-3-pmores@redhat.com> In-Reply-To: <20191210162541.15432-1-pmores@redhat.com> References: <20191210162541.15432-1-pmores@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Pavel Mores Subject: [libvirt] [PATCH v4 2/4] qemu: block: use the delete flag to delete snapshot images if requested 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.16 X-MC-Unique: bADXsOTENLWXdd5jxZ_iVw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When blockcommit finishes successfully, one of the qemuBlockJobProcessEventCompletedCommit() and qemuBlockJobProcessEventCompletedActiveCommit() event handlers is called. This is where the delete flag (stored in qemuBlockJobCommitData since the previous commit) can actually be used to delete the committed snapshot images if requested. We use virFileRemove() instead of a simple unlink() to cover the case where the image to be removed is on an NFS volume. Signed-off-by: Pavel Mores Reviewed-by: Peter Krempa --- src/qemu/qemu_blockjob.c | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index 718e311213..498e2a716f 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -1004,6 +1004,44 @@ qemuBlockJobProcessEventCompletedPull(virQEMUDriverP= tr driver, } =20 =20 +/** + * qemuBlockJobDeleteImages: + * @driver: qemu driver object + * @vm: domain object + * @disk: disk object that the chain to be deleted is associated with + * @top: top snapshot of the chain to be deleted + * + * Helper for removing snapshot images. Intended for callers like + * qemuBlockJobProcessEventCompletedCommit() and + * qemuBlockJobProcessEventCompletedActiveCommit() as it relies on adjustm= ents + * these functions perform on the 'backingStore' chain to function correct= ly. + * + * TODO look into removing backing store for non-local snapshots too + */ +static void +qemuBlockJobDeleteImages(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDiskDefPtr disk, + virStorageSourcePtr top) +{ + virStorageSourcePtr p =3D top; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + uid_t uid; + gid_t gid; + + for (; p !=3D NULL; p =3D p->backingStore) { + if (virStorageSourceGetActualType(p) =3D=3D VIR_STORAGE_TYPE_FILE)= { + + qemuDomainGetImageIds(cfg, vm, p, disk->src, &uid, &gid); + + if (virFileRemove(p->path, uid, gid) < 0) { + VIR_WARN("Unable to remove snapshot image file '%s' (%s)", + p->path, g_strerror(errno)); + } + } + } +} + /** * qemuBlockJobProcessEventCompletedCommit: * @driver: qemu driver object @@ -1070,6 +1108,10 @@ qemuBlockJobProcessEventCompletedCommit(virQEMUDrive= rPtr driver, job->data.commit.topparent->backingStore =3D job->data.commit.base; =20 qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job= ->data.commit.top); + + if (job->data.commit.deleteCommittedImages) + qemuBlockJobDeleteImages(driver, vm, job->disk, job->data.commit.t= op); + virObjectUnref(job->data.commit.top); job->data.commit.top =3D NULL; =20 @@ -1160,6 +1202,10 @@ qemuBlockJobProcessEventCompletedActiveCommit(virQEM= UDriverPtr driver, job->disk->src->readonly =3D job->data.commit.top->readonly; =20 qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job= ->data.commit.top); + + if (job->data.commit.deleteCommittedImages) + qemuBlockJobDeleteImages(driver, vm, job->disk, job->data.commit.t= op); + virObjectUnref(job->data.commit.top); job->data.commit.top =3D NULL; /* the mirror element does not serve functional purpose for the commit= job */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list