From nobody Mon Feb 9 09:15:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1633624088; cv=none; d=zohomail.com; s=zohoarc; b=DMqjxDCDv7FSEYEg34PtGQ2Q3rRBiGzGfcDfPUbrYavlzdEnz7Bw9dXRCHajk8L7gw37wLuKN1G0YMOsRkpLxKvSlo8KpJTUeA6wi+ThuNKtmGQJ5pfnRvtnv2YczlvOdW8JIikgjLp9Zu+4TfJyi6VexYwGxsB9GkP0vC24oxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633624088; 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=6wM0sWxsbqUF9YujCdaVMMm3XrlQMRMDkYkd5xkI+hk=; b=JvuLoTwQWQ9iXfFEwyMUY8aitjc2R81d8qlcBTHk6VhjYN/uihFPC1TpOi5tnORR9D4PPgdP6Qa9u48hYeyAM1s3zB7aPAjrFhmkq5SrFBQqBido+7uhvBfwoQ9hAlNjBRjuI9qEXp/9t6RW8qkGG37OMTT0reK/J9bzk/oKfAw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633624088525999.8164232716482; Thu, 7 Oct 2021 09:28:08 -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-421-2YSLYdPXMT-CRU5pGyg7ZQ-1; Thu, 07 Oct 2021 12:28:05 -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 D7413147BB4; Thu, 7 Oct 2021 15:58:46 +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 5AD3FA34EA; Thu, 7 Oct 2021 15:57:14 +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 028A44EA29; Thu, 7 Oct 2021 15:57:14 +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 197FLA6m024513 for ; Thu, 7 Oct 2021 11:21:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 90B9A5D6BA; Thu, 7 Oct 2021 15:21:10 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA87E5D6D5 for ; Thu, 7 Oct 2021 15:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633624087; 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=6wM0sWxsbqUF9YujCdaVMMm3XrlQMRMDkYkd5xkI+hk=; b=UBPvIiyGt+Cq/iZjD1k9LH89pXKS/ag0K/htGz0LPa/uF/GTQK3GFwjOHBinUGiqBWh0cn p4b6rgYKmB88COp4lk/T0AE6a5YKs7WkW1hSwhdactwv1RARmdm8Si01wDRgZC31tB2Aha QruMRZDGYD/l1USWDo/K2jZPYgzN6SA= X-MC-Unique: 2YSLYdPXMT-CRU5pGyg7ZQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 088/103] qemuBuildUSBControllerDevStr: Split out validation of USB controller Date: Thu, 7 Oct 2021 17:18:16 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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: 1633624090266100001 Content-Type: text/plain; charset="utf-8" Move the validation code into a separate function. For now the validation is still kept in the commandline format step as simply just moving it to the validator causes failures in the test suite, which will need to be investigated deeper. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 62 ++++++++++--------- ...sb-controller-explicit-unavailable-q35.err | 2 +- .../usb-controller-qemu-xhci-unavailable.err | 2 +- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 68b6bf868e..f7a2304d5c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2771,6 +2771,38 @@ qemuControllerModelUSBToCaps(int model) } +static int +qemuValidateDomainDeviceDefControllerUSB(const virDomainControllerDef *def, + virQEMUCaps *qemuCaps) +{ + if (def->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("no model provided for USB controller")); + return -1; + } + + if (!virQEMUCapsGet(qemuCaps, qemuControllerModelUSBToCaps(def->model)= )) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("USB controller model '%s' not supported in this = QEMU binary"), + virDomainControllerModelUSBTypeToString(def->model)= ); + return -1; + } + + if (def->opts.usbopts.ports !=3D -1) { + if ((def->model !=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI || + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI_PORTS)) && + def->model !=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("usb controller type '%s' doesn't support 'po= rts' with this QEMU binary"), + virDomainControllerModelUSBTypeToString(def->mo= del)); + return -1; + } + } + + return 0; +} + + static const char * qemuBuildUSBControllerFindMasterAlias(const virDomainDef *domainDef, const virDomainControllerDef *def) @@ -2802,38 +2834,12 @@ qemuBuildUSBControllerDevStr(const virDomainDef *do= mainDef, virQEMUCaps *qemuCaps, virBuffer *buf) { - const char *smodel; - int model, flags; - - model =3D def->model; - - if (model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", _("no model provided for USB controller")); - return -1; - } - - smodel =3D qemuControllerModelUSBTypeToString(model); - flags =3D qemuControllerModelUSBToCaps(model); - - if (flags =3D=3D -1 || !virQEMUCapsGet(qemuCaps, flags)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("%s not supported in this QEMU binary"), smodel); + if (qemuValidateDomainDeviceDefControllerUSB(def, qemuCaps) < 0) return -1; - } - virBufferAsprintf(buf, "%s", smodel); + virBufferAsprintf(buf, "%s", qemuControllerModelUSBTypeToString(def->m= odel)); if (def->opts.usbopts.ports !=3D -1) { - if ((model !=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI || - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI_PORTS)) && - model !=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("usb controller type %s doesn't support 'port= s' " - "with this QEMU binary"), smodel); - return -1; - } - virBufferAsprintf(buf, ",p2=3D%d,p3=3D%d", def->opts.usbopts.ports, def->opts.usbopts.ports= ); } diff --git a/tests/qemuxml2argvdata/usb-controller-explicit-unavailable-q35= .err b/tests/qemuxml2argvdata/usb-controller-explicit-unavailable-q35.err index 4940f896cc..6907a51505 100644 --- a/tests/qemuxml2argvdata/usb-controller-explicit-unavailable-q35.err +++ b/tests/qemuxml2argvdata/usb-controller-explicit-unavailable-q35.err @@ -1 +1 @@ -unsupported configuration: nec-usb-xhci not supported in this QEMU binary +unsupported configuration: USB controller model 'nec-xhci' not supported i= n this QEMU binary diff --git a/tests/qemuxml2argvdata/usb-controller-qemu-xhci-unavailable.er= r b/tests/qemuxml2argvdata/usb-controller-qemu-xhci-unavailable.err index 1b797dd343..aec91f7559 100644 --- a/tests/qemuxml2argvdata/usb-controller-qemu-xhci-unavailable.err +++ b/tests/qemuxml2argvdata/usb-controller-qemu-xhci-unavailable.err @@ -1 +1 @@ -unsupported configuration: qemu-xhci not supported in this QEMU binary +unsupported configuration: USB controller model 'qemu-xhci' not supported = in this QEMU binary --=20 2.31.1