From nobody Mon Feb 9 16:16:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1588283013; cv=none; d=zohomail.com; s=zohoarc; b=DJhYjsmSrXUDSUDuYn0AqTk0hYh5tpPoz0PeZbc2eDppKzVXoyCNKIQk0OdWK6927TtyhY/XBvwYUHCfp8hTZxe92N1ueV4W4LnJ7lzlY5RGiVdplr/ZDZ1rGy8fkHL0BpiKESEcy+V0BmKYOqpnEaKuNCqf4/RH5071QTX6Bz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588283013; 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=RFlfg2FVx3m+VAoCe+lVapK+FWDOB1GQIsILdRH4J2o=; b=llCgxUzZg6uOLlNc+mK1VWkZ+vjAeUVtXuexQpdImn02t0N7R/YYpq4D2zeQv6BEVyB2A5OGnI0Ijl/LbhXxUFXxzAR7pgr01maa455r3jfkODJkV6gexG7LhPx1T90NuaKHC/clZflgt0SM2GKcF+DJ6AizdMh2/T7KMy7BDPw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1588283013414739.9639246940378; Thu, 30 Apr 2020 14:43:33 -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-309-ywiQrHSRNLKSG174muz5pg-1; Thu, 30 Apr 2020 17:43:29 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 689238014D5; Thu, 30 Apr 2020 21:43:24 +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 40AB610013BD; Thu, 30 Apr 2020 21:43:24 +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 03F2A4A71F; Thu, 30 Apr 2020 21:43:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03ULh1pQ003310 for ; Thu, 30 Apr 2020 17:43:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id C1B8E1001281; Thu, 30 Apr 2020 21:43:01 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-99.phx2.redhat.com [10.3.112.99]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8674A10013BD for ; Thu, 30 Apr 2020 21:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588283012; 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=RFlfg2FVx3m+VAoCe+lVapK+FWDOB1GQIsILdRH4J2o=; b=bnMXF/7zY3JDiFwyv+cV7OGkapic9Qrq4tx+Yk5oOnSMXYXFrrWe2+Psf7uOk7QVWSI+1g HzidrvPorICr3x89gdvEvAIdNYXIqUDZomkUSQYN66wTCU70t0eJQxWjRnNVoZqJzKrXxi v+lApCPkLEEwhVIOEAvrGdh5dYjCWhU= X-MC-Unique: ywiQrHSRNLKSG174muz5pg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 1/6] nodedev: factor out nodeDeviceHasCapability() Date: Thu, 30 Apr 2020 16:42:53 -0500 Message-Id: <20200430214258.18498-2-jjongsma@redhat.com> In-Reply-To: <20200430214258.18498-1-jjongsma@redhat.com> References: <20200430214258.18498-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Currently nodeDeviceCreateXML() and nodeDeviceDestroy() only support NPIV HBAs, but we want to be able to create mdev devices as well. This is a first step to enabling that support. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 90 ++++++++++++++++++---------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index ee175e1095..6a96a77d92 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -487,6 +487,20 @@ nodeDeviceFindNewDevice(virConnectPtr conn, return device; } =20 +static bool +nodeDeviceHasCapability(virNodeDeviceDefPtr def, virNodeDevCapType type) +{ + virNodeDevCapsDefPtr cap =3D NULL; + + cap =3D def->caps; + while (cap !=3D NULL) { + if (cap->data.type =3D=3D type) + return true; + cap =3D cap->next; + } + + return false; +} =20 virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn, @@ -513,24 +527,29 @@ nodeDeviceCreateXML(virConnectPtr conn, if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0) return NULL; =20 - if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) - return NULL; + if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_SCSI_HOST)) { + if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) + return NULL; =20 - if ((parent_host =3D virNodeDeviceObjListGetParentHost(driver->devs, d= ef)) < 0) - return NULL; + if ((parent_host =3D virNodeDeviceObjListGetParentHost(driver->dev= s, def)) < 0) + return NULL; =20 - if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) - return NULL; + if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) + return NULL; =20 - device =3D nodeDeviceFindNewDevice(conn, wwnn, wwpn); - /* We don't check the return value, because one way or another, - * we're returning what we get... */ + device =3D nodeDeviceFindNewDevice(conn, wwnn, wwpn); + /* We don't check the return value, because one way or another, + * we're returning what we get... */ =20 - if (device =3D=3D NULL) - virReportError(VIR_ERR_NO_NODE_DEVICE, - _("no node device for '%s' with matching " - "wwnn '%s' and wwpn '%s'"), - def->name, wwnn, wwpn); + if (device =3D=3D NULL) + virReportError(VIR_ERR_NO_NODE_DEVICE, + _("no node device for '%s' with matching " + "wwnn '%s' and wwpn '%s'"), + def->name, wwnn, wwpn); + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + } =20 return device; } @@ -557,31 +576,36 @@ nodeDeviceDestroy(virNodeDevicePtr device) if (virNodeDeviceDestroyEnsureACL(device->conn, def) < 0) goto cleanup; =20 - if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) < 0) - goto cleanup; + if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_SCSI_HOST)) { + if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) < 0) + goto cleanup; =20 - /* Because we're about to release the lock and thus run into a race - * possibility (however improbable) with a udevAddOneDevice change - * event which would essentially free the existing @def (obj->def) and - * replace it with something new, we need to grab the parent field - * and then find the parent obj in order to manage the vport */ - parent =3D g_strdup(def->parent); + /* Because we're about to release the lock and thus run into a race + * possibility (however improbable) with a udevAddOneDevice change + * event which would essentially free the existing @def (obj->def)= and + * replace it with something new, we need to grab the parent field + * and then find the parent obj in order to manage the vport */ + parent =3D g_strdup(def->parent); =20 - virNodeDeviceObjEndAPI(&obj); + virNodeDeviceObjEndAPI(&obj); =20 - if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, parent))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot find parent '%s' definition"), parent); - goto cleanup; - } + if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, parent)= )) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot find parent '%s' definition"), parent= ); + goto cleanup; + } =20 - if (virSCSIHostGetNumber(parent, &parent_host) < 0) - goto cleanup; + if (virSCSIHostGetNumber(parent, &parent_host) < 0) + goto cleanup; =20 - if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0) - goto cleanup; + if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0) + goto cleanup; =20 - ret =3D 0; + ret =3D 0; + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + } =20 cleanup: virNodeDeviceObjEndAPI(&obj); --=20 2.21.1