From nobody Tue Dec 16 16:42:14 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1739550761819960.591630515677; Fri, 14 Feb 2025 08:32:41 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id CC4A01B3B; Fri, 14 Feb 2025 11:32:40 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 64ED51B81; Fri, 14 Feb 2025 11:30:27 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 99F2B1994; Fri, 14 Feb 2025 11:30:20 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 2B8451BDB for ; Fri, 14 Feb 2025 11:30:03 -0500 (EST) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-v2X349hTMBuEnVZskgyC6w-1; Fri, 14 Feb 2025 11:30:00 -0500 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0BBC518EAB3A for ; Fri, 14 Feb 2025 16:30:00 +0000 (UTC) Received: from speedmetal.lan (unknown [10.44.22.26]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BE0F21955DCE; Fri, 14 Feb 2025 16:29:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739550602; h=from:from: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; bh=1TJUPAs/me0s1GbeRUM35rstjIrhjcdi3CwtDXM3v1k=; b=cILTqecuTVGYC31q7DHUiYP7eVxpOPlv/LRNNhqTIs3M2iX4OhKp5PWFzgm65nZ7aUzI+C JaNXmAmqNFv2s0nm8CoNk/ssxT5BVdOcdYUdP7W6e+RZurLYdwMD6uoKhdCZnGCMHuA/qq sUG9r7ra0HaTnr+y7f4xYu8tw01ev5g= X-MC-Unique: v2X349hTMBuEnVZskgyC6w-1 X-Mimecast-MFC-AGG-ID: v2X349hTMBuEnVZskgyC6w_1739550600 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 05/13] qemu: validate: Extract iothread mapping validation code Date: Fri, 14 Feb 2025 17:29:39 +0100 Message-ID: <8574af99453d2c03cc307112ff9bf84869771977.1739550300.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: w1zHdM2iIAe5Gs8zPRqZi_WYPJGeyMDRNdP_uszLMu8_1739550600 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: YVLSWDRF2HXYQ3CLQHJO7W6U4ZA2OMZ6 X-Message-ID-Hash: YVLSWDRF2HXYQ3CLQHJO7W6U4ZA2OMZ6 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Stefan Hajnoczi X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1739550764379019100 Content-Type: text/plain; charset="utf-8" Extract the code to 'qemuDomainValidateIothreadMapping'. It will be reused to validate the mapping for 'virtio-scsi' iothreads. Signed-off-by: Peter Krempa --- src/qemu/qemu_validate.c | 192 +++++++++++++++++++++------------------ 1 file changed, 104 insertions(+), 88 deletions(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index fb4c9bf552..8ac3e65e9d 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2764,6 +2764,102 @@ qemuValidateDomainDeviceDefDiskSerial(const char *v= alue) } +static int +qemuDomainValidateIothreadMapping(const virDomainDef *def, + GSList *iothreads, + size_t queues) +{ + virDomainIothreadMappingDef *first_ioth; + g_autoptr(virBitmap) queueMap =3D NULL; + g_autoptr(GHashTable) iothreadMap =3D virHashNew(NULL); + ssize_t unused; + GSList *n; + + if (!iothreads) + return 0; + + first_ioth =3D iothreads->data; + + if (first_ioth->queues) { + if (queues =3D=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("'queue' count must be configured for explici= t iothread to queue mapping")); + return -1; + } + + queueMap =3D virBitmapNew(queues); + } + + /* we are validating that: + * - there are no duplicate iothreads + * - there are only valid iothreads + * - if queue mapping is provided + * - queue is in range + * - it must be provided for all assigned iothreads + * - it must be provided for all queues + * - queue must be assigned only once + */ + for (n =3D iothreads; n; n =3D n->next) { + virDomainIothreadMappingDef *ioth =3D n->data; + g_autofree char *alias =3D g_strdup_printf("iothread%u", ioth->id); + size_t i; + + if (g_hash_table_contains(iothreadMap, alias)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("duplicate mapping for iothread '%1$u'"), iot= h->id); + return -1; + } + + g_hash_table_insert(iothreadMap, g_steal_pointer(&alias), NULL); + + if (!virDomainIOThreadIDFind(def, ioth->id)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("iothread '%1$u' not defined in iothreadid"), + ioth->id); + return -1; + } + + if (!!queueMap !=3D !!ioth->queues) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("iothread to queue mapping must be provided f= or all iothreads or for none")); + return -1; + } + + for (i =3D 0; i < ioth->nqueues; i++) { + bool hasMapping; + + if (virBitmapGetBit(queueMap, ioth->queues[i], &hasMapping) < = 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("iothread queue '%1$u' mapping out of ran= ge"), + ioth->queues[i]); + return -1; + } + + if (hasMapping) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("iothread queue '%1$u' is already assigne= d"), + ioth->queues[i]); + return -1; + } + + ignore_value(virBitmapSetBit(queueMap, ioth->queues[i])); + + } + } + + if (queueMap) { + if ((unused =3D virBitmapNextClearBit(queueMap, -1)) >=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("missing iothread mapping for queue '%1$zd'"), + unused); + return -1; + } + } + + return 0; +} + + static int qemuValidateDomainDeviceDefDiskIOThreads(const virDomainDef *def, const virDomainDiskDef *disk, @@ -2800,95 +2896,15 @@ qemuValidateDomainDeviceDefDiskIOThreads(const virD= omainDef *def, return -1; } - if (disk->iothreads) { - virDomainIothreadMappingDef *first_ioth =3D disk->iothreads->data; - g_autoptr(virBitmap) queueMap =3D NULL; - g_autoptr(GHashTable) iothreads =3D virHashNew(NULL); - ssize_t unused; - GSList *n; - - if (first_ioth->queues) { - if (disk->queues =3D=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("disk 'queue' count must be configured fo= r explicit iothread to queue mapping")); - return -1; - } - - queueMap =3D virBitmapNew(disk->queues); - } - - /* we are validating that: - * - there are no duplicate iothreads - * - there are only valid iothreads - * - if queue mapping is provided - * - queue is in range - * - it must be provided for all assigned iothreads - * - it must be provided for all queues - * - queue must be assigned only once - */ - for (n =3D disk->iothreads; n; n =3D n->next) { - virDomainIothreadMappingDef *ioth =3D n->data; - g_autofree char *alias =3D g_strdup_printf("iothread%u", ioth-= >id); - size_t i; - - if (g_hash_table_contains(iothreads, alias)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Duplicate mapping for iothread '%1$u'"),= ioth->id); - return -1; - } - - g_hash_table_insert(iothreads, g_steal_pointer(&alias), NULL); - - if (!virDomainIOThreadIDFind(def, ioth->id)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Disk iothread '%1$u' not defined in ioth= readid"), - ioth->id); - return -1; - } - - if (!!queueMap !=3D !!ioth->queues) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("iothread to queue mapping must be provid= ed for all iothreads or for none")); - return -1; - } - - for (i =3D 0; i < ioth->nqueues; i++) { - bool hasMapping; - - if (virBitmapGetBit(queueMap, ioth->queues[i], &hasMapping= ) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("disk iothread queue '%1$u' mapping o= ut of range"), - ioth->queues[i]); - return -1; - } - - if (hasMapping) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("disk iothread queue '%1$u' is alread= y assigned"), - ioth->queues[i]); - return -1; - } - - ignore_value(virBitmapSetBit(queueMap, ioth->queues[i])); - - } - } + if (qemuDomainValidateIothreadMapping(def, disk->iothreads, disk->queu= es) < 0) + return -1; - if (queueMap) { - if ((unused =3D virBitmapNextClearBit(queueMap, -1)) >=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("missing iothread mapping for queue '%1$z= d'"), - unused); - return -1; - } - } - } else { - if (!virDomainIOThreadIDFind(def, disk->iothread)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Disk iothread '%1$u' not defined in iothread= id"), - disk->iothread); - return -1; - } + if (disk->iothread !=3D 0 && + !virDomainIOThreadIDFind(def, disk->iothread)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Disk iothread '%1$u' not defined in iothreadid"), + disk->iothread); + return -1; } return 0; --=20 2.48.1