From nobody Sat Feb 7 05:44:49 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=1681479873; cv=none; d=zohomail.com; s=zohoarc; b=DnPlZoQ+M/a7lJ5KZ80ag5mmWzUPmCnuxyQlpLG5CZvRByA03L44Om51WVjdGOgdrW44efCWBaSHZOaKSmq7vpbXDprqektIrY+1h9kByLJcMERniSHjycMXC3iJzPAu/xj9wiTH5gAxPHntc2sbVJoWsF0jzUd1yt0rNjnp2pg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681479873; 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=PiP+5w/oak1vhktilMg4OyNptfUPbQRtEgkmElqDsRs=; b=C6jUJRVxqYc2xKgH+I9FUcnF1A3GBYnURZZOjMzxjOEe4bTqF32mEpk1JkAX1Uu8Auwm9sSiqHTDn4EJRP3pp0Ifwbim2XoZGYHGHEuKMy4Ixg+s9TX+Ftjn1lYzGYTtxbA7cX4VYh5oMsWY5B2MB4SEMMLmKAtHsILmIeR+rHU= 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 1681479873056206.15212108244918; Fri, 14 Apr 2023 06:44:33 -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-58-JY4vVXIOMlm28cv3NIiacQ-1; Fri, 14 Apr 2023 09:44:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1175788B7BC; Fri, 14 Apr 2023 13:44:24 +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 EE7BE40C94AC; Fri, 14 Apr 2023 13:44:23 +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 BDA0219472C0; Fri, 14 Apr 2023 13:44:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DEBE21946A7F for ; Fri, 14 Apr 2023 13:44:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B692E492C14; Fri, 14 Apr 2023 13:44:20 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44C71492C13; Fri, 14 Apr 2023 13:44:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681479872; 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=PiP+5w/oak1vhktilMg4OyNptfUPbQRtEgkmElqDsRs=; b=eqs4gCgkqjf/OTbdaqbw4pNJX717P29P2I6wBZUH0sjvGDU6jHMzf2GbGq1DDzEx2ujYWV cXhnWbgqDHp3zzhvRfNV/uNjvba5OMopJab3dFN8RxvRiNqcclVmWo9gEX2Hnl7xfQnUfY 27Rhlq1z7/LwJLMPMpleEif2M7LZrBk= X-MC-Unique: JY4vVXIOMlm28cv3NIiacQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/4] qemuDomainAttachHostDevice: Prepare device early and for all types Date: Fri, 14 Apr 2023 15:44:15 +0200 Message-Id: <680e1ed23b40f27d3ac28e551fce90c9f2356092.1681479711.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: , Cc: zhenzhong.duan@intel.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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: 1681479874012100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When attaching a hostdev of a SCSI subsys, qemuDomainPrepareHostdev() is called. This makes sense because the function prepares just SCSI hostdevs ignoring others. But this will soon change. Thefore, move the function call out of qemuDomainAttachHostSCSIDevice() and into qemuDomainAttachHostDevice(). Signed-off-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3f45a48393..8902b40815 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2484,9 +2484,6 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriver *driver, =20 qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1); =20 - if (qemuDomainPrepareHostdev(hostdev, priv) < 0) - goto cleanup; - if (qemuProcessPrepareHostHostdev(hostdev) < 0) goto cleanup; =20 @@ -2768,6 +2765,9 @@ qemuDomainAttachHostDevice(virQEMUDriver *driver, return -1; } =20 + if (qemuDomainPrepareHostdev(hostdev, vm->privateData) < 0) + return -1; + switch (hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (qemuDomainAttachHostPCIDevice(driver, vm, --=20 2.39.2 From nobody Sat Feb 7 05:44:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1681479907; cv=none; d=zohomail.com; s=zohoarc; b=GZNI32Qvw/ar6+mBf5CqTQWVzzpefLxjCXco/6SvfRskIQXB300dyClrdnGNEcqBQpN//PPQZeXiGrS0LsP3aKXdJLdYFS5/4ZRQ91nuimRs+SR55iUnbMAg4gLS79YbaKXntR95Xay7/fLuFHHvj9fFELkRSG8K9xFLXWN+Tqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681479907; 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=kog9dFSWWLIusJyo54Co8mQX0zCCFrHrF4rw2Tp44Fo=; b=AwyGQmm2BQ6ZM1V7TvwJdN8f+Xt5bfK576mTYDtV5lFnx+WdxPzhDcW2TYKUeXEjgPpDAU+xMaS1Nqqe3K+g8AZDIgRGegAxA+Tc4Xu0ISuytE1LJ8f4iRaG2nwjsKyXklbQVnmrdGE9utYbdWiScuIaJrogASrw73osP+DrzDo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1681479907684217.25174698515445; Fri, 14 Apr 2023 06:45:07 -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-509-HgsucKOOPFKBL66JUzE03Q-1; Fri, 14 Apr 2023 09:44:26 -0400 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 8363510334A7; Fri, 14 Apr 2023 13:44:23 +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 6F325492C3A; Fri, 14 Apr 2023 13:44:23 +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 4F02319459FC; Fri, 14 Apr 2023 13:44:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 769A319472C0 for ; Fri, 14 Apr 2023 13:44:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6B152492C18; Fri, 14 Apr 2023 13:44:21 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECD05492C13; Fri, 14 Apr 2023 13:44:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681479906; 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=kog9dFSWWLIusJyo54Co8mQX0zCCFrHrF4rw2Tp44Fo=; b=dPTTeUttw1mfTH5O7ye2Ega2pA1rzTm4UkCUP4D5oG1qLABQ4/jeAMGtGklkup/k4dMQ3d /Gsl6TZbSkJKQYNVhsVfdwmPxG6ebGZvvWosv7/yB9fGw/xgWMGXtMs4EM2eOhs2raRosS QBb/IapFxWr3lDtV7P8fix5s+jmats4= X-MC-Unique: HgsucKOOPFKBL66JUzE03Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/4] qemu: Move PCI backend setting into qemuDomainPrepareHostdev() Date: Fri, 14 Apr 2023 15:44:16 +0200 Message-Id: <52c0978dbcb5c633318ec58cc8702ad5c9e7adb2.1681479711.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: , Cc: zhenzhong.duan@intel.com 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681479908302100001 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Zhenzhong Duan virsh command domxml-to-native failed with below error but start command succeed for same domain xml. "internal error: invalid PCI passthrough type 'default'" If a PCI backend is not set in the XML, the supported one is then chosen in qemuHostdevPreparePCIDevicesCheckSupport(). But this function is not called anywhere from qemuConnectDomainXMLToNative(). But qemuDomainPrepareHostdev() is. And it is also called from domain startup/hotplug code. Therefore, move the backend setting to the common path. And since qemuDomainPrepareHostdev() is called transitively from our qemuxml2argvtest, we can just drop the code in testCompareXMLToArgvCreateArgs() that preselects the backend (if a mock for qemuHostdevHostSupportsPassthroughVFIO() is provided. Signed-off-by: Zhenzhong Duan Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 12 ++++++++++++ src/qemu/qemu_hostdev.c | 16 +++++++--------- src/qemu/qemu_hotplug.c | 2 +- tests/qemuxml2argvmock.c | 7 +++++++ tests/qemuxml2argvtest.c | 6 ------ 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 63b13b6875..6de846f158 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11275,6 +11275,18 @@ qemuDomainPrepareHostdev(virDomainHostdevDef *host= dev, } } =20 + if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI) { + bool supportsPassthroughVFIO =3D qemuHostdevHostSupportsPassthroug= hVFIO(); + virDomainHostdevSubsysPCIBackendType *backend =3D &hostdev->source= .subsys.u.pci.backend; + + if (*backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT && + supportsPassthroughVFIO && + virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { + *backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; + } + } + return 0; } =20 diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 45cd1066f0..8408928c00 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -156,7 +156,7 @@ qemuHostdevHostSupportsPassthroughVFIO(void) static bool qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDef **hostdevs, size_t nhostdevs, - virQEMUCaps *qemuCaps) + virQEMUCaps *qemuCaps G_GNUC_UNUS= ED) { bool supportsPassthroughVFIO =3D qemuHostdevHostSupportsPassthroughVFI= O(); size_t i; @@ -173,17 +173,15 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHos= tdevDef **hostdevs, =20 switch (*backend) { case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT: - if (supportsPassthroughVFIO && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { - *backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; + /* qemuDomainPrepareHostdev() should have set different value = */ + if (supportsPassthroughVFIO) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("QEMU doesn't support VFIO PCI passthroug= h")); } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("host doesn't support passthrough of " - "host PCI devices")); - return false; + _("host doesn't support passthrough of host= PCI devices")); } - - break; + return false; =20 case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO: if (!supportsPassthroughVFIO) { diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 8902b40815..95ac0fd754 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1478,7 +1478,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver, &hostdev, 1, priv->qemuCaps, flags) <= 0) return -1; =20 - /* this could have been changed by qemuHostdevPreparePCIDevices */ + /* this could have been changed by qemuDomainPrepareHostdev */ backend =3D hostdev->source.subsys.u.pci.backend; =20 switch (backend) { diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index f566ec539a..863fdf0351 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -33,6 +33,7 @@ #include "virscsivhost.h" #include "virtpm.h" #include "virutil.h" +#include "qemu/qemu_hostdev.h" #include "qemu/qemu_interface.h" #include "qemu/qemu_command.h" #include @@ -82,6 +83,12 @@ virSCSIVHostOpenVhostSCSI(int *vhostfd) return 0; } =20 +bool +qemuHostdevHostSupportsPassthroughVFIO(void) +{ + return true; +} + int virNetDevTapCreate(char **ifname, const char *tunpath G_GNUC_UNUSED, diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 1808d9fc02..8333749eea 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -407,12 +407,6 @@ testCompareXMLToArgvCreateArgs(virQEMUDriver *drv, for (i =3D 0; i < vm->def->nhostdevs; i++) { virDomainHostdevDef *hostdev =3D vm->def->hostdevs[i]; =20 - if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_T= YPE_PCI && - hostdev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV= _PCI_BACKEND_DEFAULT) { - hostdev->source.subsys.u.pci.backend =3D VIR_DOMAIN_HOSTDEV_PC= I_BACKEND_VFIO; - } - if (virHostdevIsSCSIDevice(hostdev)) { virDomainHostdevSubsysSCSI *scsisrc =3D &hostdev->source.subsy= s.u.scsi; =20 --=20 2.39.2 From nobody Sat Feb 7 05:44:49 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=1681479874; cv=none; d=zohomail.com; s=zohoarc; b=Fp04O+iT0rZuA+f4w0Nm3BvwYapFUk6YrC3XQNUYCrOcn4+999P1MMqK/j2jvJN8ItI6k80eX08oW5WQ2a2i1yNQ3kQ6cgkL1WwxW3wRKdezjgRxQzzl1ddN+nRJy/DW18bF7KXFxTJaGDnfxmj/VrqeV6MAHHHsNPRhAPjFnvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681479874; 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=eyFTkRYtLDFNBQzHjl5VrQXvjd5gm4Ia/kO5JxacpXA=; b=cp6p9uRQytnJpmOgBzfmpt/SpszXDyYJbe/xka/rzo79LZwX0A7VTx13IIUlXgEpzSv7hG5yZOcMbUH7PDimZ08RenhTCWChpZ73Yp+Fh1s7sf97PH7bF0beJVUvBdGNhchoSWBRUgteBZEMlf3sZHQh/8ZzZrh9MtcrsAvTQxo= 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 1681479874661425.23572288662524; Fri, 14 Apr 2023 06:44:34 -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-258-lJBQ5UQXOhKyilS6alQuNg-1; Fri, 14 Apr 2023 09:44:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4805C8021C3; Fri, 14 Apr 2023 13:44:24 +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 3557D2166B29; Fri, 14 Apr 2023 13:44:24 +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 0123219472CC; Fri, 14 Apr 2023 13:44:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 404E319472C9 for ; Fri, 14 Apr 2023 13:44:22 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2029A492C1B; Fri, 14 Apr 2023 13:44:22 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1993492C13; Fri, 14 Apr 2023 13:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681479873; 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=eyFTkRYtLDFNBQzHjl5VrQXvjd5gm4Ia/kO5JxacpXA=; b=HRGMpFe2sUdaRVVoJYJcl+A+St902+R4RYrc5wz/maltZZkhwFeFBXqBSGzXOkQ1A/c2Jm 8CECD+LNxwU8AMpTHz8Sifx1Sr5fmCd5gU+v9oVc3WRUGAn2n/euLjsLyvPUmX9aZouFcd VwjLpCjP71u1kC1OfJNG7ag7WWN4iMQ= X-MC-Unique: lJBQ5UQXOhKyilS6alQuNg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/4] qemu: Move SCSI path generation into qemuDomainPrepareHostdev() Date: Fri, 14 Apr 2023 15:44:17 +0200 Message-Id: <1b68e0a822699a3a73dfd20ab92f3c79652cc800.1681479711.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: , Cc: zhenzhong.duan@intel.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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: 1681479875332100003 Content-Type: text/plain; charset="utf-8"; x-default="true" When preparing a SCSI with passthrough of a host SCSI adapter (i.e. no protocol), a virStorageSource structure is initialized and stored inside virDomainHostdevDef. But the source structure is filled in many places, with almost the same code. Firstly, qemuProcessPrepareHostHostdev() and qemuConnectDomainXMLToNativePrepareHostHostdev() are the same. Secondly, qemuDomainPrepareHostdev() allocates the src structure, only to let qemuProcessPrepareHostHostdev() fill src->path later. Well, src->path can be filled at the same place where the src structure is allocated (qemuDomainPrepareHostdev()) which renders the other two functions needless. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 10 ++++++++++ src/qemu/qemu_driver.c | 32 +------------------------------- src/qemu/qemu_process.c | 32 +------------------------------- tests/qemuxml2argvmock.c | 10 ++++++++++ tests/qemuxml2argvtest.c | 22 ---------------------- 5 files changed, 22 insertions(+), 84 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 6de846f158..3925de4d49 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11230,7 +11230,9 @@ qemuDomainPrepareHostdev(virDomainHostdevDef *hostd= ev, { if (virHostdevIsSCSIDevice(hostdev)) { virDomainHostdevSubsysSCSI *scsisrc =3D &hostdev->source.subsys.u.= scsi; + virDomainHostdevSubsysSCSIHost *scsihostsrc =3D &scsisrc->u.host; virStorageSource *src =3D NULL; + g_autofree char *devstr =3D NULL; =20 switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: @@ -11238,7 +11240,15 @@ qemuDomainPrepareHostdev(virDomainHostdevDef *host= dev, scsisrc->u.host.src =3D virStorageSourceNew(); src =3D scsisrc->u.host.src; =20 + if (!(devstr =3D virSCSIDeviceGetSgName(NULL, + scsihostsrc->adapter, + scsihostsrc->bus, + scsihostsrc->target, + scsihostsrc->unit))) + return -1; + src->type =3D VIR_STORAGE_TYPE_BLOCK; + src->path =3D g_strdup_printf("/dev/%s", devstr); =20 break; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 28e470e4a2..701656696b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6166,38 +6166,8 @@ static char =20 =20 static int -qemuConnectDomainXMLToNativePrepareHostHostdev(virDomainHostdevDef *hostde= v) +qemuConnectDomainXMLToNativePrepareHostHostdev(virDomainHostdevDef *hostde= v G_GNUC_UNUSED) { - if (virHostdevIsSCSIDevice(hostdev)) { - virDomainHostdevSubsysSCSI *scsisrc =3D &hostdev->source.subsys.u.= scsi; - - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: { - virDomainHostdevSubsysSCSIHost *scsihostsrc =3D &scsisrc->u.ho= st; - virStorageSource *src =3D scsisrc->u.host.src; - g_autofree char *devstr =3D NULL; - - if (!(devstr =3D virSCSIDeviceGetSgName(NULL, - scsihostsrc->adapter, - scsihostsrc->bus, - scsihostsrc->target, - scsihostsrc->unit))) - return -1; - - src->path =3D g_strdup_printf("/dev/%s", devstr); - break; - } - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: - break; - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST: - default: - virReportEnumRangeError(virDomainHostdevSCSIProtocolType, scsi= src->protocol); - return -1; - } - } - return 0; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b9e9a7d320..ec07f86d35 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6510,38 +6510,8 @@ qemuProcessPrepareDomainHostdevs(virDomainObj *vm, =20 =20 int -qemuProcessPrepareHostHostdev(virDomainHostdevDef *hostdev) +qemuProcessPrepareHostHostdev(virDomainHostdevDef *hostdev G_GNUC_UNUSED) { - if (virHostdevIsSCSIDevice(hostdev)) { - virDomainHostdevSubsysSCSI *scsisrc =3D &hostdev->source.subsys.u.= scsi; - - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: { - virDomainHostdevSubsysSCSIHost *scsihostsrc =3D &scsisrc->u.ho= st; - virStorageSource *src =3D scsisrc->u.host.src; - g_autofree char *devstr =3D NULL; - - if (!(devstr =3D virSCSIDeviceGetSgName(NULL, - scsihostsrc->adapter, - scsihostsrc->bus, - scsihostsrc->target, - scsihostsrc->unit))) - return -1; - - src->path =3D g_strdup_printf("/dev/%s", devstr); - break; - } - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: - break; - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST: - default: - virReportEnumRangeError(virDomainHostdevSCSIProtocolType, scsi= src->protocol); - return -1; - } - } - return 0; } =20 diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index 863fdf0351..2b37b6c258 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -89,6 +89,16 @@ qemuHostdevHostSupportsPassthroughVFIO(void) return true; } =20 +char * +virSCSIDeviceGetSgName(const char *sysfs_prefix G_GNUC_UNUSED, + const char *adapter G_GNUC_UNUSED, + unsigned int bus G_GNUC_UNUSED, + unsigned int target G_GNUC_UNUSED, + unsigned long long unit G_GNUC_UNUSED) +{ + return g_strdup_printf("sg0"); +} + int virNetDevTapCreate(char **ifname, const char *tunpath G_GNUC_UNUSED, diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 8333749eea..919e69e306 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -404,28 +404,6 @@ testCompareXMLToArgvCreateArgs(virQEMUDriver *drv, disk->src->hostcdrom =3D true; } =20 - for (i =3D 0; i < vm->def->nhostdevs; i++) { - virDomainHostdevDef *hostdev =3D vm->def->hostdevs[i]; - - if (virHostdevIsSCSIDevice(hostdev)) { - virDomainHostdevSubsysSCSI *scsisrc =3D &hostdev->source.subsy= s.u.scsi; - - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: - scsisrc->u.host.src->path =3D g_strdup("/dev/sg0"); - break; - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: - break; - - case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST: - default: - virReportEnumRangeError(virDomainHostdevSCSIProtocolType, = scsisrc->protocol); - return NULL; - } - } - } - if (vm->def->vsock) { virDomainVsockDef *vsock =3D vm->def->vsock; qemuDomainVsockPrivate *vsockPriv =3D --=20 2.39.2 From nobody Sat Feb 7 05:44:49 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=1681479958; cv=none; d=zohomail.com; s=zohoarc; b=dLhbo/+M9Q3+pGritxnb2nXSfCIompQLFvtp1MOznaRvmx5INcZvUcNhHPF2zSKqbSS6ppkqUjrqeuNTYL+a5gSZ6G72JbhticAxzGoyGjXB6xMLrWqlxYUOOyBPNMlllveXmcp3s957YLYNa5N/ZcOS2E2z9td0LkWSxkTi4BE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681479958; 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=3jVunjFYUiHh9oW0dbZ+/7WpaEGScqNI5A3MRrI0ox0=; b=lVClK3Y2BRhBGHTuM0r15C9Bsw0wSk5ER8PEmyWIMJRnPUBU9xTXDiI4H262bCK/c7apUNCh+u7zYmtF8Kr7gZ6tSqvNQpBD/37fWkz2+x151uEIsbT8gU0wd3cQesE2DOrgT9hrwL4FyQOsUVfM41xp+AQ+iYCL/+lVAcPS8WU= 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 1681479958690852.2167545997735; Fri, 14 Apr 2023 06:45:58 -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-552-MZIZXKgaOLunuN9W8KnkPQ-1; Fri, 14 Apr 2023 09:44:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9945F88B7DA; Fri, 14 Apr 2023 13:44:24 +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 840602166B29; Fri, 14 Apr 2023 13:44:24 +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 3883D19472D1; Fri, 14 Apr 2023 13:44:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E60AF1946A7F for ; Fri, 14 Apr 2023 13:44:22 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D6DCA492C13; Fri, 14 Apr 2023 13:44:22 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63CE6492C14; Fri, 14 Apr 2023 13:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681479957; 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=3jVunjFYUiHh9oW0dbZ+/7WpaEGScqNI5A3MRrI0ox0=; b=YFA5O5TA0RZSJsIUTpoe+RYjfeK925VVwBlr5EO1I50SiPgiuXsaYIz78R10f6LjDqr1B2 v1yEqhayM4DCzCwJ42EC+erExJlkf4X3Z9tpYvCPAG4UWU/zBhWgPQZWY1UyzNVmHEo1yN SK7UpeYJyJ9KU4HktszZs95BlGV1yug= X-MC-Unique: MZIZXKgaOLunuN9W8KnkPQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/4] qemu: Remove empty functions Date: Fri, 14 Apr 2023 15:44:18 +0200 Message-Id: <162756b6da81aa637e2004f48b3224be07e1223c.1681479711.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: , Cc: zhenzhong.duan@intel.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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: 1681479960716100001 Content-Type: text/plain; charset="utf-8"; x-default="true" After previous cleanup, there are some functions that do nothing: qemuConnectDomainXMLToNativePrepareHostHostdev() qemuConnectDomainXMLToNativePrepareHost() qemuProcessPrepareHostHostdev() qemuProcessPrepareHostHostdevs() Remove them. Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 26 -------------------------- src/qemu/qemu_hotplug.c | 3 --- src/qemu/qemu_process.c | 27 --------------------------- src/qemu/qemu_process.h | 3 --- 4 files changed, 59 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 701656696b..f38847cf02 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6165,29 +6165,6 @@ static char } =20 =20 -static int -qemuConnectDomainXMLToNativePrepareHostHostdev(virDomainHostdevDef *hostde= v G_GNUC_UNUSED) -{ - return 0; -} - - -static int -qemuConnectDomainXMLToNativePrepareHost(virDomainObj *vm) -{ - size_t i; - - for (i =3D 0; i < vm->def->nhostdevs; i++) { - virDomainHostdevDef *hostdev =3D vm->def->hostdevs[i]; - - if (qemuConnectDomainXMLToNativePrepareHostHostdev(hostdev) < 0) - return -1; - } - - return 0; -} - - static char *qemuConnectDomainXMLToNative(virConnectPtr conn, const char *format, const char *xmlData, @@ -6244,9 +6221,6 @@ static char *qemuConnectDomainXMLToNative(virConnectP= tr conn, VIR_QEMU_PROCESS_START_COLD) < = 0) return NULL; =20 - if (qemuConnectDomainXMLToNativePrepareHost(vm) < 0) - return NULL; - if (!(cmd =3D qemuProcessCreatePretendCmdBuild(vm, NULL))) return NULL; =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 95ac0fd754..fc4406c1b5 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2484,9 +2484,6 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriver *driver, =20 qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1); =20 - if (qemuProcessPrepareHostHostdev(hostdev) < 0) - goto cleanup; - if (!(data =3D qemuBuildHostdevSCSIAttachPrepare(hostdev, &backendalia= s, priv->qemuCaps))) goto cleanup; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ec07f86d35..8414302f7c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6509,29 +6509,6 @@ qemuProcessPrepareDomainHostdevs(virDomainObj *vm, } =20 =20 -int -qemuProcessPrepareHostHostdev(virDomainHostdevDef *hostdev G_GNUC_UNUSED) -{ - return 0; -} - - -static int -qemuProcessPrepareHostHostdevs(virDomainObj *vm) -{ - size_t i; - - for (i =3D 0; i < vm->def->nhostdevs; i++) { - virDomainHostdevDef *hostdev =3D vm->def->hostdevs[i]; - - if (qemuProcessPrepareHostHostdev(hostdev) < 0) - return -1; - } - - return 0; -} - - /** * qemuProcessRebootAllowed: * @def: domain definition @@ -7233,10 +7210,6 @@ qemuProcessPrepareHost(virQEMUDriver *driver, if (qemuProcessPrepareHostStorage(driver, vm, flags) < 0) return -1; =20 - VIR_DEBUG("Preparing hostdevs (host-side)"); - if (qemuProcessPrepareHostHostdevs(vm) < 0) - return -1; - VIR_DEBUG("Preparing external devices"); if (qemuExtDevicesPrepareHost(driver, vm) < 0) return -1; diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index b171f0464c..5d1b24a038 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -111,9 +111,6 @@ int qemuProcessPrepareDomain(virQEMUDriver *driver, =20 int qemuProcessOpenVhostVsock(virDomainVsockDef *vsock); =20 -int qemuProcessPrepareHostHostdev(virDomainHostdevDef *hostdev); - - int qemuProcessPrepareHostBackendChardevHotplug(virDomainObj *vm, virDomainDeviceDef *dev) G_NO_INLINE; --=20 2.39.2