From nobody Mon May 6 18:18:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1585646329; cv=none; d=zohomail.com; s=zohoarc; b=Tyr0B0pAB32BLe9HaBYXyOY0JE167PuchhzW378jt0Wen48PN33dm1OhREEYZ8D9+hueATM5Uf8h/OSFKY8s6MNI090wl8FAdEkpGYjYw5UiSTIrMr/aS/5SfrpDZ8yqEOLS0WKfN6jBIIxU9B/D/1U6NC9m7PHxPdNprm5ZIm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585646329; 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=wXRADFluN0HUKtEDQwxMJuCa9vnrNSPlxpUfcSDruLQ=; b=e/AB0+avjWclB8um1/YZTYerdPxlwJsuMTXekN+eAFQdHl8daCQQcETVxj1mlgeVb33htbxLK37INDqgz27ue9j6+Ge/W8UQmgDlB0fbj5Fn3fE7FU8y2N42F9nImQX3lqI/mwDjWL/jHd7iCOF7PyUxfJPKQd5xm5YL1HFSbhc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1585646329013924.2018040655188; Tue, 31 Mar 2020 02:18:49 -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-320-R-h-VlFKPw-u5Mio_lEHQg-1; Tue, 31 Mar 2020 05:18:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B8668017CE; Tue, 31 Mar 2020 09:18:40 +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 D3ED560BE0; Tue, 31 Mar 2020 09:18:39 +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 5D58B18095FF; Tue, 31 Mar 2020 09:18:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02V9Iara024665 for ; Tue, 31 Mar 2020 05:18:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7976D953D6; Tue, 31 Mar 2020 09:18:36 +0000 (UTC) Received: from ibm-p8-15-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (unknown [10.40.195.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC4316EF9F; Tue, 31 Mar 2020 09:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585646327; 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=wXRADFluN0HUKtEDQwxMJuCa9vnrNSPlxpUfcSDruLQ=; b=fqTVH/ggNEAax2Qy5l0q19Cb6bCniOgAx+knJ10Go5f61nrt33zWYXrDUkYzopD/bq5y/J RThB+OnR7oaco2xuhm7o0iYRU/NoPu8qSWrIkGQe8wMhdeZf2FSBvSWoJZnIEx3uu9izKT EvCA6+z1o18T/Y8KIH5330k278S0ZD4= X-MC-Unique: R-h-VlFKPw-u5Mio_lEHQg-1 From: Pavel Mores To: libvir-list@redhat.com Subject: [libvirt PATCH 1/3] qemu: block: factor implementation out of qemuDomainBlockCommit() Date: Tue, 31 Mar 2020 11:18:27 +0200 Message-Id: <20200331091829.521427-2-pmores@redhat.com> In-Reply-To: <20200331091829.521427-1-pmores@redhat.com> References: <20200331091829.521427-1-pmores@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.12 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" The idea is to make block commit callable from within the QEMU driver. Signed-off-by: Pavel Mores --- src/qemu/qemu_driver.c | 84 +++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e9a62684f0..f94636f651 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -154,6 +154,15 @@ static int qemuOpenFileAs(uid_t fallback_uid, gid_t fa= llback_gid, =20 static virQEMUDriverPtr qemu_driver; =20 +static int +qemuDomainBlockCommitImpl(virDomainObjPtr vm, + virQEMUDriverPtr driver, + const char *path, + const char *base, + const char *top, + unsigned long bandwidth, + unsigned int flags); + /* Looks up the domain object from snapshot and unlocks the * driver. The returned domain object is locked and ref'd and the * caller must call virDomainObjEndAPI() on it. */ @@ -18314,18 +18323,16 @@ qemuDomainBlockPull(virDomainPtr dom, const char = *path, unsigned long bandwidth, return qemuDomainBlockPullCommon(vm, path, NULL, bandwidth, flags); } =20 - static int -qemuDomainBlockCommit(virDomainPtr dom, - const char *path, - const char *base, - const char *top, - unsigned long bandwidth, - unsigned int flags) +qemuDomainBlockCommitImpl(virDomainObjPtr vm, + virQEMUDriverPtr driver, + const char *path, + const char *base, + const char *top, + unsigned long bandwidth, + unsigned int flags) { - virQEMUDriverPtr driver =3D dom->conn->privateData; - qemuDomainObjPrivatePtr priv; - virDomainObjPtr vm =3D NULL; + qemuDomainObjPrivatePtr priv =3D vm->privateData; const char *device =3D NULL; const char *jobname =3D NULL; int ret =3D -1; @@ -18347,25 +18354,6 @@ qemuDomainBlockCommit(virDomainPtr dom, bool persistjob =3D false; bool blockdev =3D false; =20 - virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW | - VIR_DOMAIN_BLOCK_COMMIT_ACTIVE | - VIR_DOMAIN_BLOCK_COMMIT_RELATIVE | - VIR_DOMAIN_BLOCK_COMMIT_DELETE | - VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES, -1); - - if (!(vm =3D qemuDomainObjFromDomain(dom))) - goto cleanup; - priv =3D vm->privateData; - - if (virDomainBlockCommitEnsureACL(dom->conn, vm->def) < 0) - goto cleanup; - - if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0) - goto cleanup; - - if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) - goto cleanup; - if (virDomainObjCheckActive(vm) < 0) goto endjob; =20 @@ -18558,6 +18546,43 @@ qemuDomainBlockCommit(virDomainPtr dom, virErrorRestore(&orig_err); } qemuBlockJobStartupFinalize(vm, job); + + return ret; +} + + +static int +qemuDomainBlockCommit(virDomainPtr dom, + const char *path, + const char *base, + const char *top, + unsigned long bandwidth, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D dom->conn->privateData; + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + + virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW | + VIR_DOMAIN_BLOCK_COMMIT_ACTIVE | + VIR_DOMAIN_BLOCK_COMMIT_RELATIVE | + VIR_DOMAIN_BLOCK_COMMIT_DELETE | + VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES, -1); + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + goto cleanup; + + if (virDomainBlockCommitEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0) + goto cleanup; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + + ret =3D qemuDomainBlockCommitImpl(vm, driver, path, base, top, bandwid= th, flags); + qemuDomainObjEndJob(driver, vm); =20 cleanup: @@ -18565,6 +18590,7 @@ qemuDomainBlockCommit(virDomainPtr dom, return ret; } =20 + static int qemuDomainOpenGraphics(virDomainPtr dom, unsigned int idx, --=20 2.24.1 From nobody Mon May 6 18:18:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1585646339; cv=none; d=zohomail.com; s=zohoarc; b=hFioVwfgRhdNMjT6uS64HvB7Hix2pnIw1OYPWiEMYMNfGTQI+Otd0CLgUZyqz/hgkFvQGNcG3EiBg5KXWCydu7QovXMU/f6YEaSoBQ1m0lt6XMS6bzqiT1fa2Folruojny5OBRVYlJrt3qgfO6jIgwqr3KlJuIQTP8G9pBSR4h0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585646339; 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=kAb4CEMN8j7WGF1cszxJbAX00wmk4WH7JkGFVoM8ziw=; b=PgVpQZ7qJsBA/ZfebIfj31RBy0TxPES+T0sdf5dDlzScIWlavaHemYPLQTXmNgAEaoTT6ccNaiIipU1ppCAhsyxENY4gzYPBikbxH73LS//JOpauMm/EATn1+1pXcLmRZGUl8846H4LXnxSTHrCSxPkgazM7bioY/ZC/pRFBSa0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1585646339263318.758826770012; Tue, 31 Mar 2020 02:18:59 -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-492-b3sGglq-PJijfQAwkaT3KA-1; Tue, 31 Mar 2020 05:18:56 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 671F18018A4; Tue, 31 Mar 2020 09:18:49 +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 35526D7692; Tue, 31 Mar 2020 09:18:49 +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 DDD1886BFF; Tue, 31 Mar 2020 09:18:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02V9IbM6024672 for ; Tue, 31 Mar 2020 05:18:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 96E1996B6C; Tue, 31 Mar 2020 09:18:37 +0000 (UTC) Received: from ibm-p8-15-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (unknown [10.40.195.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3DD06EF9F; Tue, 31 Mar 2020 09:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585646338; 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=kAb4CEMN8j7WGF1cszxJbAX00wmk4WH7JkGFVoM8ziw=; b=AALhngYJWekqdaWIhl5yo0PlyDxlDDG7h6ltHQDrjDH9K5bIMlX1jw+cr95Bn5W5SLmKqq EComeL98X+Y0rqgHl2+GmGmws7ukI2/xR6lhziUFJ4HGRdR423XIh57K8/SOQfuI4UIUC5 5mYs1fmBXJbRahmIuPBtIbF71KX7TDU= X-MC-Unique: b3sGglq-PJijfQAwkaT3KA-1 From: Pavel Mores To: libvir-list@redhat.com Subject: [libvirt PATCH 2/3] qemu: block: factor implementation out of qemuDomainBlockJobAbort() Date: Tue, 31 Mar 2020 11:18:28 +0200 Message-Id: <20200331091829.521427-3-pmores@redhat.com> In-Reply-To: <20200331091829.521427-1-pmores@redhat.com> References: <20200331091829.521427-1-pmores@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.11 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" As with the previous commit, this should primarily make qemuDomainBlockJobAbort() callable from within the QEMU driver. Signed-off-by: Pavel Mores --- src/qemu/qemu_driver.c | 62 ++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f94636f651..b981745ecf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -163,6 +163,12 @@ qemuDomainBlockCommitImpl(virDomainObjPtr vm, unsigned long bandwidth, unsigned int flags); =20 +static int +qemuDomainBlockJobAbortImpl(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *path, + unsigned int flags); + /* Looks up the domain object from snapshot and unlocks the * driver. The returned domain object is locked and ref'd and the * caller must call virDomainObjEndAPI() on it. */ @@ -17440,45 +17446,31 @@ qemuDomainBlockPullCommon(virDomainObjPtr vm, return ret; } =20 - static int -qemuDomainBlockJobAbort(virDomainPtr dom, - const char *path, - unsigned int flags) +qemuDomainBlockJobAbortImpl(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *path, + unsigned int flags) { - virQEMUDriverPtr driver =3D dom->conn->privateData; virDomainDiskDefPtr disk =3D NULL; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); bool pivot =3D !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT); bool async =3D !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC); g_autoptr(qemuBlockJobData) job =3D NULL; - virDomainObjPtr vm; qemuDomainObjPrivatePtr priv =3D NULL; bool blockdev =3D false; int ret =3D -1; =20 - virCheckFlags(VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC | - VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT, -1); - - if (!(vm =3D qemuDomainObjFromDomain(dom))) - return -1; - - if (virDomainBlockJobAbortEnsureACL(dom->conn, vm->def) < 0) - goto cleanup; - - if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) - goto cleanup; - if (virDomainObjCheckActive(vm) < 0) - goto endjob; + return -1; =20 if (!(disk =3D qemuDomainDiskByName(vm->def, path))) - goto endjob; + return -1; =20 if (!(job =3D qemuBlockJobDiskGetJob(disk))) { virReportError(VIR_ERR_INVALID_ARG, _("disk %s does not have an active block job"), dis= k->dst); - goto endjob; + return -1; } =20 priv =3D vm->privateData; @@ -17549,6 +17541,34 @@ qemuDomainBlockJobAbort(virDomainPtr dom, endjob: if (job && !async) qemuBlockJobSyncEnd(vm, job, QEMU_ASYNC_JOB_NONE); + + return ret; +} + + +static int +qemuDomainBlockJobAbort(virDomainPtr dom, + const char *path, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D dom->conn->privateData; + virDomainObjPtr vm; + int ret =3D -1; + + virCheckFlags(VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC | + VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT, -1); + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + return -1; + + if (virDomainBlockJobAbortEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + + ret =3D qemuDomainBlockJobAbortImpl(driver, vm, path, flags); + qemuDomainObjEndJob(driver, vm); =20 cleanup: --=20 2.24.1 From nobody Mon May 6 18:18:28 2024 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=1585646342; cv=none; d=zohomail.com; s=zohoarc; b=IsQxjxfX3pJqloSTuaHEVlU3BmGgTn+kL2hASYF7/oLkpifurCJcTcVT/mVC8CA9rmPW7QwNLQ9vwlu7aric/au5CwhMiZ/3kod1Ufpd2YebY+fgizq6VW1jm+SJH70P96dxny9DriIF8eMlLF3r+Z36L3zz8g6NgEBnWWYsEpY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585646342; 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=F+sY28JaAs4vFdOqq6cqPprjrPKRek647X0LPCDPvbI=; b=H5COOeqggFJUg2ZZRUcZVWclKW23R8bP8Fjn1oWjGECgYWfvwMq3o68xaz8IY4gDltqqulS9RkzXPE8c91INcCZJACYelHnqIGd2/7OttVJkgGUSIHSuvk+9yik01hJEk/cdvknlnoDCt//kJY0cEodDynFAmsw6SDNLvQIzfdA= 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-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1585646342468996.8913232070065; Tue, 31 Mar 2020 02:19:02 -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-253-LCAnjXh3OGybx4HldmvXjA-1; Tue, 31 Mar 2020 05:18:58 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3ACDA13FA; Tue, 31 Mar 2020 09:18:53 +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 08BC619C6A; Tue, 31 Mar 2020 09:18:53 +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 AD59018089CE; Tue, 31 Mar 2020 09:18:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02V9Icr3024680 for ; Tue, 31 Mar 2020 05:18:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id B678996B6C; Tue, 31 Mar 2020 09:18:38 +0000 (UTC) Received: from ibm-p8-15-fsp.mgmt.pnr.lab.eng.rdu2.redhat.com (unknown [10.40.195.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id F39C96EF9F; Tue, 31 Mar 2020 09:18:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585646341; 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=F+sY28JaAs4vFdOqq6cqPprjrPKRek647X0LPCDPvbI=; b=dmk67KEHxwzGCMPMVvgEp2bg+Vmq24Qlo6fhCCG+AjGxczBdPcZo6qW1vOswug+9rThJ2T e4MsZBj9eeQmSmQEwwIUVuJcBmJKJBYDgBNu+9J1c/cexbuV1PuWvhXxAzqIot7LZlnTda GF6JDrLx2H3SWwF6pzgwO6em41l6Be0= X-MC-Unique: LCAnjXh3OGybx4HldmvXjA-1 From: Pavel Mores To: libvir-list@redhat.com Subject: [libvirt PATCH 3/3] qemu: block: external snapshot-delete implementation for straightforward cases Date: Tue, 31 Mar 2020 11:18:29 +0200 Message-Id: <20200331091829.521427-4-pmores@redhat.com> In-Reply-To: <20200331091829.521427-1-pmores@redhat.com> References: <20200331091829.521427-1-pmores@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.23 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" Works by blockcommitting the snapshot to be deleted into its parent. Handl= es both deleting children as well and deleting children only (commits the children into the snapshot referred to by snapshot-delete argument). If the necessary block commit operation turns out to be active (the snapshot refer= red to by snapshot-delete argument is current, or deleting children is requeste= d) pivot is performed as well. This implemetation is limited to the straightforward case which assumes no branching snapshot chains below the snapshot to be deleted, and the current snapshot has to be the leaf of the (linear) chain starting at the snapshot = to be deleted. These requirements are checked and enforced at the top of qemuDomainSnapshotDeleteExternal(). They might even be too restrictive for the case where deletion of children is not requested as in that case, requiring that the parent of the snapshot to be deleted not be a branching point in snapshot tree should be enough. The above limitations do not appear to be too severe under the current state of matters where a major source of branching snapshot structures, snapshot-revert, is not even implemented for external snapshots yet. The o= nly other known cause of branching in external snapshots thus seems to be if a user creates branching by manually creating snapshot images and metadata and applies them using snapshot-create --redefine. At any rate, this work shou= ld be understood as just a first step to a full support of deleting external snapshots. Signed-off-by: Pavel Mores --- src/qemu/qemu_driver.c | 149 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 145 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b981745ecf..4d4f3f069f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16707,6 +16707,149 @@ qemuDomainMomentReparentChildren(void *payload, } =20 =20 +/* + * We can't use virDomainMomentFindLeaf() as it takes a + * virDomainMomentObjListPtr which we don't have. It might be a good idea= to + * move this function to a library of virDomainMomentObj helpers, then + * reimplement virDomainMomentFindLeaf() in terms of this function as it o= nly + * uses its virDomainMomentObjListPtr parameter to fish a virDomainMomentO= bjPtr + * out of it. Then it just runs this function's algorithm on it. + */ +static virDomainMomentObjPtr +myDomainMomentFindLeaf(virDomainMomentObjPtr moment) +{ + if (moment->nchildren !=3D 1) + return NULL; + while (moment->nchildren =3D=3D 1) + moment =3D moment->first_child; + if (moment->nchildren =3D=3D 0) + return moment; + return NULL; +} + + +static int +qemuDomainSnapshotDeleteExternal(virDomainObjPtr vm, + virQEMUDriverPtr driver, + virDomainMomentObjPtr snap, + unsigned int flags) +{ + int ret =3D -1; + bool isActive; + virDomainSnapshotDefPtr snapdef =3D virDomainSnapshotObjGetDef(snap); + virDomainMomentObjPtr leaf =3D snap->nchildren ? myDomainMomentFindLea= f(snap) : snap; + virDomainMomentObjPtr parent =3D snap->parent; + virDomainSnapshotDefPtr parentdef =3D virDomainSnapshotObjGetDef(paren= t); + size_t i; + + /* 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, + "%s", _("can't delete, snapshot chain branches")); + goto cleanup; + } + if (leaf !=3D virDomainSnapshotGetCurrent(vm->snapshots)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + "%s", _("can't delete, leaf snapshot is not current= ")); + goto cleanup; + } + + if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | + VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { + isActive =3D true; + } else { + isActive =3D snap =3D=3D virDomainSnapshotGetCurrent(vm->snapshots= ); + } + + for (i =3D 0; i < snapdef->ndisks; i++) { + virDomainSnapshotDiskDefPtr snapdisk =3D &(snapdef->disks[i]); + const char *diskName =3D snapdisk->name; + const char *basePath =3D NULL; + const char *topPath =3D snapdisk->src->path; + int blockCommitFlags =3D VIR_DOMAIN_BLOCK_COMMIT_DELETE; + virDomainDiskDefPtr disk; + + if (!(disk =3D qemuDomainDiskByName(vm->def, diskName))) + goto cleanup; + + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { + basePath =3D snapdisk->src->path; + topPath =3D disk->src->path; + } else { + if (parent->nchildren =3D=3D 1) { + if (parentdef =3D=3D NULL) { + virStorageSourcePtr baseSrc =3D virStorageFileChainLoo= kup(disk->src, NULL, NULL, 0, NULL); + if (!baseSrc) + goto cleanup; + basePath =3D baseSrc->path; + } else { + virDomainSnapshotDiskDefPtr parentdisk =3D &(parentdef= ->disks[i]); + basePath =3D parentdisk->src->path; + } + } else { + /* 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 mi= ght + * still be able to delete 'snap' though by pulling into i= ts + * child/children. */ + + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("can't delete, parent has multiple childr= en")); + } + + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) + topPath =3D disk->src->path; + else + topPath =3D snapdisk->src->path; + } + + if (isActive) + blockCommitFlags |=3D VIR_DOMAIN_BLOCK_COMMIT_ACTIVE; + + if (qemuDomainBlockCommitImpl(vm, driver, diskName, basePath, topP= ath, + 0, blockCommitFlags) < 0) + goto cleanup; + + if (isActive) { + /* wait for the blockcommit job to finish (in particular, reac= h the + * QEMU_BLOCKJOB_STATE_READY state)... */ + qemuBlockJobDataPtr job; + + if (!(job =3D qemuBlockJobDiskGetJob(disk))) { + virReportError(VIR_ERR_INVALID_ARG, + _("disk %s does not have an active block job")= , disk->dst); + goto cleanup; + } + + qemuBlockJobSyncBegin(job); + qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE); + while (job->state !=3D QEMU_BLOCKJOB_STATE_READY) { + if (virDomainObjWait(vm) < 0) { + ret =3D -1; + goto cleanup; + } + qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE); + } + qemuBlockJobSyncEnd(vm, job, QEMU_ASYNC_JOB_NONE); + + /* ... and pivot */ + if (qemuDomainBlockJobAbortImpl(driver, vm, diskName, + VIR_DOMAIN_BLOCK_JOB_ABORT_PIV= OT) < 0) + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + return ret; +} + + static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags) @@ -16749,10 +16892,8 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snap= shot, qemuDomainSnapshotCountExtern= al, &external); if (external) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("deletion of %d external disk snapshots not " - "supported yet"), external); - goto endjob; + if (qemuDomainSnapshotDeleteExternal(vm, driver, snap, flags) = < 0) + goto endjob; } } =20 --=20 2.24.1