From nobody Sat May 18 08:14:23 2024 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=1673271776; cv=none; d=zohomail.com; s=zohoarc; b=R3Zc83ThSYludcgaJFpynbD4Go7ypacPkwP2yAkNargiZHN60XQ9UHCw2BM8a9t0bH9B9D3WhEp8JdphgOVz7eHml9cJo+zAu4RF/CMoBp86QXchfyKiIYu1G6cQ4vZDd+4hnKBOjIiQ+1EfSWx0DKLT6bFOdt+hAFDz0v3mME8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673271776; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=3kGAoJulpK5h8zBoAyqoKPFpGOLVc4H/0RrChYENlfE=; b=EJ0aMNVVRxX6zcJkvIGjzvQnHI3nNSfGq3HcZ/O6CAhoVumFYhagTXqJ38y+u0KfAxk8DRHnK3fhri3NwPw3paKuabKLaVRB9852rBeiuovVi+hTs4cgdAW+Cf8Af0slTsmX0C9LE+0Nv6N28f5zpYIQSmxJFD0VVBwjLSOgZb4= 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 1673271776939766.2471296806532; Mon, 9 Jan 2023 05:42:56 -0800 (PST) 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-410-_n7AuHSbN7SSii5XLAvlGQ-1; Mon, 09 Jan 2023 08:42:50 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 94C46857A89; Mon, 9 Jan 2023 13:42:48 +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 C58F4492C14; Mon, 9 Jan 2023 13:42:47 +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 9010B1947BA8; Mon, 9 Jan 2023 13:42:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AAD701947B94 for ; Mon, 9 Jan 2023 13:42:46 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8C7ED4078904; Mon, 9 Jan 2023 13:42:46 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-20.brq.redhat.com [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id F255E4078903 for ; Mon, 9 Jan 2023 13:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673271776; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3kGAoJulpK5h8zBoAyqoKPFpGOLVc4H/0RrChYENlfE=; b=AplLG2ozo+jU0sImALieuXdIf3Y+s0aUN22CnytRsmAb5Rn5oV/sHY5ynNjYmpr9lRFAUl JlIVJOvdywocTwSoArGJuTBCtiiq6y5w0pMJhVmtv+zI/iNFjgl4WEI3mZzXVUfzkddCRQ lM8Hg64LeT0tYYo0lBMF3r80mmqB7hE= X-MC-Unique: _n7AuHSbN7SSii5XLAvlGQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH (pushed)] qemu: Fix variable sizing issues with 'bandwidth' argument of qemuBlockCommit Date: Mon, 9 Jan 2023 14:42:44 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673271779096100005 The patch moving the code didn't faithfully represent the typecasting of the 'bandwidth' variable needed to properly convert from the legacy 'unsigned long' argument which resulted in a build failure on 32 bit systems: ../src/qemu/qemu_block.c: In function =E2=80=98qemuBlockCommit=E2=80=99: ../src/qemu/qemu_block.c:3249:23: error: comparison is always false due to = limited range of data type [-Werror=3Dtype-limits] 3249 | if (bandwidth > LLONG_MAX >> 20) { | ^ Fix it by returning the check into qemuDomainBlockCommit as it's needed only because of the legacy argument type in the old API and use 'unsigned long long' for qemuBlockCommit. Fixes: f5a77198bf9 Signed-off-by: Peter Krempa --- Pushed under the build-breaker rule. src/qemu/qemu_block.c | 15 ++------------- src/qemu/qemu_block.h | 2 +- src/qemu/qemu_driver.c | 14 +++++++++++++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 7ea42961b6..9bfb06ac08 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3205,7 +3205,7 @@ qemuBlockExportAddNBD(virDomainObj *vm, * @baseSource: disk source within backing chain to commit data into * @topSource: disk source within backing chain with data we will commit * @top_parent: disk source that has @topSource as backing disk - * @bandwidth: bandwidth limit, flags determine the unit + * @bandwidth: bandwidth limit in bytes/s * @asyncJob: qemu async job type * @autofinalize: virTristateBool controlling qemu block job finalization * @flags: bitwise-OR of virDomainBlockCommitFlags @@ -3227,7 +3227,7 @@ qemuBlockCommit(virDomainObj *vm, virStorageSource *baseSource, virStorageSource *topSource, virStorageSource *top_parent, - unsigned long bandwidth, + unsigned long long bandwidth, virDomainAsyncJob asyncJob, virTristateBool autofinalize, unsigned int flags) @@ -3244,17 +3244,6 @@ qemuBlockCommit(virDomainObj *vm, if (virDomainObjCheckActive(vm) < 0) return NULL; - /* Convert bandwidth MiB to bytes, if necessary */ - if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)) { - if (bandwidth > LLONG_MAX >> 20) { - virReportError(VIR_ERR_OVERFLOW, - _("bandwidth must be less than %llu"), - LLONG_MAX >> 20); - return NULL; - } - bandwidth <<=3D 20; - } - if (!qemuDomainDiskBlockJobIsSupported(disk)) return NULL; diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index a8079c2207..eac986e0f0 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -283,7 +283,7 @@ qemuBlockCommit(virDomainObj *vm, virStorageSource *baseSource, virStorageSource *topSource, virStorageSource *top_parent, - unsigned long bandwidth, + unsigned long long bandwidth, virDomainAsyncJob asyncJob, virTristateBool autofinalize, unsigned int flags); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3ea48c9049..d9f7ce234e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14994,6 +14994,7 @@ qemuDomainBlockCommit(virDomainPtr dom, virStorageSource *topSource; virStorageSource *baseSource =3D NULL; virStorageSource *top_parent =3D NULL; + unsigned long long speed =3D bandwidth; g_autoptr(qemuBlockJobData) job =3D NULL; virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW | @@ -15011,6 +15012,17 @@ qemuDomainBlockCommit(virDomainPtr dom, if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) goto cleanup; + /* Convert bandwidth MiB to bytes, if necessary */ + if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)) { + if (speed > LLONG_MAX >> 20) { + virReportError(VIR_ERR_OVERFLOW, + _("bandwidth must be less than %llu"), + LLONG_MAX >> 20); + goto endjob; + } + speed <<=3D 20; + } + if (!(disk =3D qemuDomainDiskByName(vm->def, path))) goto endjob; @@ -15027,7 +15039,7 @@ qemuDomainBlockCommit(virDomainPtr dom, goto endjob; job =3D qemuBlockCommit(vm, disk, baseSource, topSource, top_parent, - bandwidth, VIR_ASYNC_JOB_NONE, VIR_TRISTATE_BOOL= _YES, + speed, VIR_ASYNC_JOB_NONE, VIR_TRISTATE_BOOL_YES, flags); if (job) ret =3D 0; --=20 2.38.1