From nobody Sun Feb 8 10:17:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1661272390; cv=none; d=zohomail.com; s=zohoarc; b=a8RPvmmCdlkIHMSjBhMF3f9NiYI5K2Tf7LolFT8PzhPMB+sJgLt6Tqi5wayrhd5ZjR4AhtKP3A3AmMbGtGI5hO961VbNHRuJK1sFccnIHuxh/t7brGoMI2O17RxoFSkgd6muqNeR1RUbnMowbGGGVI6AOPnRtpEgIC5Efs/tyxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272390; 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=seGCeKehGFVzEtPhladpZXbM+vsayDwelHBM3qk29Js=; b=TNeGBZpxsvTchxwPiqpl7Iov2frlpnGwf5YRfYHBjNejJ8g1l/0N3iX/30ADQOqaJCGFlDZK20Ul4FejsqEXj4C1aPlIO0GA8Mx1QZvu/N6x/w9F2FFyYcSt0A2gZEL+jID/24HWpuXCZdXxJoET+XoSu6AuUwm37vEausXVWx0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1661272390851683.3304457371594; Tue, 23 Aug 2022 09:33:10 -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-286-LXMQ3TKVOOGfGxOdDCNk5Q-1; Tue, 23 Aug 2022 12:32:46 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 502EC8037AF; Tue, 23 Aug 2022 16:32:37 +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 3DB8D1121315; Tue, 23 Aug 2022 16:32:37 +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 280D61946A58; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2A7A71946A40 for ; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0F9FC403349; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4AC8492C3B for ; Tue, 23 Aug 2022 16:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272388; 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=seGCeKehGFVzEtPhladpZXbM+vsayDwelHBM3qk29Js=; b=UiqW3/jTBK78y8AC2sRXWUbetIE4XmkQ9V0vtsjZvr9LXW3uiSWZ+lTyMCwMoU+VySBrTj xlAL/90HS64apk5Igd0WVoU5RMrSLDWXomLIMLjOR4k1NPtiB+p+aamRbWIXnyY68BCaSb UkjPLH8Sjny3p9YZgZRa/Swql6RUANw= X-MC-Unique: LXMQ3TKVOOGfGxOdDCNk5Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 03/24] qemu_block: extract qemuBlockCommit impl to separate function Date: Tue, 23 Aug 2022 18:32:06 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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 2.78 on 10.11.54.3 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: 1661272391466100005 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_block.c | 78 ++++++++++++++++++++++++++----------------- src/qemu/qemu_block.h | 10 ++++++ 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 5b34461853..902ec7b2a5 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3204,28 +3204,22 @@ qemuBlockExportAddNBD(virDomainObj *vm, =20 =20 int -qemuBlockCommit(virDomainObj *vm, - virQEMUDriver *driver, - const char *path, - const char *base, - const char *top, - unsigned long bandwidth, - unsigned int flags) +qemuBlockCommitImpl(virDomainObj *vm, + virQEMUDriver *driver, + virDomainDiskDef *disk, + virStorageSource *baseSource, + virStorageSource *topSource, + virStorageSource *top_parent, + unsigned long bandwidth, + unsigned int flags) { qemuDomainObjPrivate *priv =3D vm->privateData; int rc =3D -1; - virDomainDiskDef *disk =3D NULL; - virStorageSource *topSource; - virStorageSource *baseSource =3D NULL; - virStorageSource *top_parent =3D NULL; bool clean_access =3D false; g_autofree char *backingPath =3D NULL; qemuBlockJobData *job =3D NULL; g_autoptr(virStorageSource) mirror =3D NULL; =20 - if (virDomainObjCheckActive(vm) < 0) - return -1; - /* Convert bandwidth MiB to bytes, if necessary */ if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)) { if (bandwidth > LLONG_MAX >> 20) { @@ -3237,9 +3231,6 @@ qemuBlockCommit(virDomainObj *vm, bandwidth <<=3D 20; } =20 - if (!(disk =3D qemuDomainDiskByName(vm->def, path))) - return -1; - if (!qemuDomainDiskBlockJobIsSupported(disk)) return -1; =20 @@ -3256,12 +3247,6 @@ qemuBlockCommit(virDomainObj *vm, if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0) return -1; =20 - if (!top || STREQ(top, disk->dst)) - topSource =3D disk->src; - else if (!(topSource =3D virStorageSourceChainLookup(disk->src, NULL, = top, - disk->dst, &top_par= ent))) - return -1; - if (topSource =3D=3D disk->src) { /* XXX Should we auto-pivot when COMMIT_ACTIVE is not specified? */ if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)) { @@ -3280,22 +3265,16 @@ qemuBlockCommit(virDomainObj *vm, if (!virStorageSourceHasBacking(topSource)) { virReportError(VIR_ERR_INVALID_ARG, _("top '%s' in chain for '%s' has no backing file"), - topSource->path, path); + topSource->path, disk->src->path); return -1; } =20 - if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW)) - baseSource =3D topSource->backingStore; - else if (!(baseSource =3D virStorageSourceChainLookup(disk->src, topSo= urce, - base, disk->dst, N= ULL))) - return -1; - if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) && baseSource !=3D topSource->backingStore) { virReportError(VIR_ERR_INVALID_ARG, _("base '%s' is not immediately below '%s' in chain= " "for '%s'"), - base, topSource->path, path); + baseSource->path, topSource->path, disk->src->path); return -1; } =20 @@ -3400,6 +3379,43 @@ qemuBlockCommit(virDomainObj *vm, } =20 =20 +int +qemuBlockCommit(virDomainObj *vm, + virQEMUDriver *driver, + const char *path, + const char *base, + const char *top, + unsigned long bandwidth, + unsigned int flags) +{ + virDomainDiskDef *disk =3D NULL; + virStorageSource *topSource; + virStorageSource *baseSource =3D NULL; + virStorageSource *top_parent =3D NULL; + + if (virDomainObjCheckActive(vm) < 0) + return -1; + + if (!(disk =3D qemuDomainDiskByName(vm->def, path))) + return -1; + + if (!top || STREQ(top, disk->dst)) + topSource =3D disk->src; + else if (!(topSource =3D virStorageSourceChainLookup(disk->src, NULL, = top, + disk->dst, &top_par= ent))) + return -1; + + if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW)) + baseSource =3D topSource->backingStore; + else if (!(baseSource =3D virStorageSourceChainLookup(disk->src, topSo= urce, + base, disk->dst, N= ULL))) + return -1; + + return qemuBlockCommitImpl(vm, driver, disk, baseSource, topSource, + top_parent, bandwidth, flags); +} + + /* Called while holding the VM job lock, to implement a block job * abort with pivot; this updates the VM definition as appropriate, on * either success or failure. */ diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index d4b564e177..35f7718697 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -277,6 +277,16 @@ qemuBlockExportAddNBD(virDomainObj *vm, bool writable, const char *bitmap); =20 +int +qemuBlockCommitImpl(virDomainObj *vm, + virQEMUDriver *driver, + virDomainDiskDef *disk, + virStorageSource *baseSource, + virStorageSource *topSource, + virStorageSource *top_parent, + unsigned long bandwidth, + unsigned int flags); + int qemuBlockCommit(virDomainObj *vm, virQEMUDriver *driver, --=20 2.37.2