From nobody Thu May 2 23:14:54 2024 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 Reviewed-by: Michal Privoznik --- 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 From nobody Thu May 2 23:14:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1588282998; cv=none; d=zohomail.com; s=zohoarc; b=CKGWomXFcu9ISnnu7Z4gIbcAoqBnfhrQejQL3uRpEOZRabzXCg/9DNGZooqkBOzhphU+HIZ9ZBAbIMvUrx/RBqBR0hKBjsCth7oZkkRr+N0DyhCVgcq9D7x28rpNo1bSwQ9AqYCL2nEClhBQWB25fKssj5GnyFkr5t+M5+GpUDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588282998; 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=tv5/JreCppXAUrcpaaa3Mtf45OnqAS2s/LPN5Wq1zGI=; b=I2amiq/r/wZ7BTjTkhxnzfYEZgK5Q3mLaBrbVtafUucsMFCo9Q95A0XUNrgfbBknoOn1a1UMuDidBcm05tAW9fnhTpx4pjTHDHXjpqtGI0z50hf3iyRLrJfhqt01mKJ0zgVslccGAUlgUfcdu+Y2C2Hmo/jj7tDgWdnBvSTDK40= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1588282998010961.376708674762; Thu, 30 Apr 2020 14:43:18 -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-118-zGpbyzCZOuyXekosSLlgqQ-1; Thu, 30 Apr 2020 17:43:13 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 81F7319200C3; Thu, 30 Apr 2020 21:43:08 +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 922535D777; Thu, 30 Apr 2020 21:43:07 +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 7C44D4CAA0; Thu, 30 Apr 2020 21:43:03 +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 03ULh2bO003316 for ; Thu, 30 Apr 2020 17:43:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 18B841001281; Thu, 30 Apr 2020 21:43:02 +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 DE95210013BD 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=1588282996; 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=tv5/JreCppXAUrcpaaa3Mtf45OnqAS2s/LPN5Wq1zGI=; b=Xfydm/T82RFQjylHXAD1v7w4KQXbGfmssA+TH46sVX3nsep8ruT4HtHvEt0Zs1y97huk9J Xms1Egg0Eox9dXbzV4FCBaSm2Ttcl9DkfKt/kneEKVPxv93g83RIgxD8aqHxg+Kot5vDAn ql9GUE6Ukd1ylNi+8Y/3s8Y/kw56sew= X-MC-Unique: zGpbyzCZOuyXekosSLlgqQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 2/6] nodedev: add support for mdev attributes Date: Thu, 30 Apr 2020 16:42:54 -0500 Message-Id: <20200430214258.18498-3-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.79 on 10.5.11.15 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" Mediated devices support arbitrary vendor-specific attributes that can be attached to a mediated device. These attributes are ordered, and are written to sysfs in order after a device is created. This patch adds support for these attributes to the mdev data types and XML schema. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- docs/schemas/nodedev.rng | 6 ++++ src/conf/node_device_conf.c | 58 +++++++++++++++++++++++++++++++++++-- src/conf/node_device_conf.h | 2 ++ src/libvirt_private.syms | 2 ++ src/util/virmdev.c | 12 ++++++++ src/util/virmdev.h | 11 +++++++ 6 files changed, 88 insertions(+), 3 deletions(-) diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index fe6ffa0b53..a1ce09af54 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -634,6 +634,12 @@ + + + + + + =20 diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 4cf5b6e3d7..8cffe48d23 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -500,6 +500,20 @@ virNodeDeviceCapStorageDefFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); } =20 +static void +virNodeDeviceCapMdevDefFormat(virBufferPtr buf, + const virNodeDevCapData *data) +{ + size_t i; + virBufferEscapeString(buf, "\n", data->mdev.type); + virBufferAsprintf(buf, "\n", + data->mdev.iommuGroupNumber); + for (i =3D 0; i < data->mdev.nattributes; i++) { + virMediatedDeviceAttrPtr attr =3D data->mdev.attributes[i]; + virBufferAsprintf(buf, "\n", + attr->name, attr->value); + } +} =20 char * virNodeDeviceDefFormat(const virNodeDeviceDef *def) @@ -583,9 +597,7 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) virBufferEscapeString(&buf, "%s\n", virNodeDevDRM= TypeToString(data->drm.type)); break; case VIR_NODE_DEV_CAP_MDEV: - virBufferEscapeString(&buf, "\n", data->mdev.= type); - virBufferAsprintf(&buf, "\n", - data->mdev.iommuGroupNumber); + virNodeDeviceCapMdevDefFormat(&buf, data); break; case VIR_NODE_DEV_CAP_CCW_DEV: virBufferAsprintf(&buf, "0x%x\n", @@ -1788,6 +1800,35 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, return ret; } =20 +static int +virNodeDevCapMdevAttributeParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr node, + virNodeDevCapMdevPtr mdev) +{ + xmlNodePtr orig_node =3D node; + ctxt->node =3D node; + int ret =3D -1; + + g_autoptr(virMediatedDeviceAttr) attr =3D virMediatedDeviceAttrNew(); + attr->name =3D virXPathString("string(./@name)", ctxt); + attr->value =3D virXPathString("string(./@value)", ctxt); + if (!attr->name || !attr->value) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("mdev attribute missing name or value")); + goto cleanup; + } + + if (VIR_EXPAND_N(mdev->attributes, mdev->nattributes, 1) < 0) + goto cleanup; + + mdev->attributes[mdev->nattributes - 1] =3D g_steal_pointer(&attr); + + ret =3D 0; + + cleanup: + ctxt->node =3D orig_node; + return ret; +} =20 static int virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, @@ -1797,6 +1838,9 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, { xmlNodePtr orignode; int ret =3D -1; + int nattrs =3D 0; + xmlNodePtr *attrs; + size_t i; =20 orignode =3D ctxt->node; ctxt->node =3D node; @@ -1815,6 +1859,11 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, "'%s'")) < 0) goto out; =20 + if ((nattrs =3D virXPathNodeSet("./attribute", ctxt, &attrs)) < 0) + goto out; + for (i =3D 0; i < nattrs; i++) + virNodeDevCapMdevAttributeParseXML(ctxt, attrs[i], mdev); + ret =3D 0; out: ctxt->node =3D orignode; @@ -2205,6 +2254,9 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) break; case VIR_NODE_DEV_CAP_MDEV: VIR_FREE(data->mdev.type); + for (i =3D 0; i < data->mdev.nattributes; i++) + virMediatedDeviceAttrFree(data->mdev.attributes[i]); + VIR_FREE(data->mdev.attributes); break; case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_DRM: diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 9e4b0847fb..e3e1e788d4 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -141,6 +141,8 @@ typedef virNodeDevCapMdev *virNodeDevCapMdevPtr; struct _virNodeDevCapMdev { char *type; unsigned int iommuGroupNumber; + virMediatedDeviceAttrPtr *attributes; + size_t nattributes; }; =20 typedef struct _virNodeDevCapPCIDev virNodeDevCapPCIDev; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 935ef7303b..94b206aa21 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2482,6 +2482,8 @@ virMacMapRemove; virMacMapWriteFile; =20 # util/virmdev.h +virMediatedDeviceAttrFree; +virMediatedDeviceAttrNew; virMediatedDeviceFree; virMediatedDeviceGetIOMMUGroupDev; virMediatedDeviceGetIOMMUGroupNum; diff --git a/src/util/virmdev.c b/src/util/virmdev.c index c2499c0a20..6c37eae00b 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -518,3 +518,15 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath, =20 return 0; } + +virMediatedDeviceAttrPtr virMediatedDeviceAttrNew(void) +{ + return g_new0(virMediatedDeviceAttr, 1); +} + +void virMediatedDeviceAttrFree(virMediatedDeviceAttrPtr attr) +{ + g_free(attr->name); + g_free(attr->value); + g_free(attr); +} diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 51f7f608a2..eb167ccb48 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -37,6 +37,17 @@ typedef struct _virMediatedDevice virMediatedDevice; typedef virMediatedDevice *virMediatedDevicePtr; typedef struct _virMediatedDeviceList virMediatedDeviceList; typedef virMediatedDeviceList *virMediatedDeviceListPtr; +typedef struct _virMediatedDeviceAttr virMediatedDeviceAttr; +typedef virMediatedDeviceAttr *virMediatedDeviceAttrPtr; + +struct _virMediatedDeviceAttr { + char *name; + char *value; +}; + +virMediatedDeviceAttrPtr virMediatedDeviceAttrNew(void); +void virMediatedDeviceAttrFree(virMediatedDeviceAttrPtr attr); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceAttr, virMediatedDeviceAttr= Free); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceList, virObjectUnref); =20 --=20 2.21.1 From nobody Thu May 2 23:14:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1588283046; cv=none; d=zohomail.com; s=zohoarc; b=n9A3FpGzM3vaYCzS545AfnTi/mrXe18QQG3GI8VKKYL1Ifr1ssoGflITKERE07xG5ugpTxvVFUwjQjnJF5mc9bgkdnJOKxLvwAVIDLx4vHD4lYVIgkUJ0/w+io6HfQm9lB/n8e9SCuMHOzeQ9WdvQjB/N68TGLDr6StIbJSKNqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588283046; 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=lvXJ0vfBRAP5gp78GjopOeb4DTiehGR/jy5SAktIa5c=; b=KROQBs77Dm8XVVAdl4siT08v0c4T8ErPt0PSSMVygI6esHZpzjCncvUWRyR1k6GJlC87pPrb2MdF4ByO47w/bYl/QQbrUB1R/2ZN7YwDgNIXTF+6l3sAKJGE8MwWZwWPLien3vvIFLxKiE3xm+OS53jcTC23BKE8t/ap2pnWzHQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1588283046306439.61169223960985; Thu, 30 Apr 2020 14:44:06 -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-qyPu7xMVNHOJzo5rHAFGIA-1; Thu, 30 Apr 2020 17:43:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C48E19200C1; 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 463D65C1D0; 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 004B44CAB0; Thu, 30 Apr 2020 21:43:23 +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 03ULh2dZ003322 for ; Thu, 30 Apr 2020 17:43:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 645251001281; Thu, 30 Apr 2020 21:43:02 +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 36C8B10013BD for ; Thu, 30 Apr 2020 21:43:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588283044; 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=lvXJ0vfBRAP5gp78GjopOeb4DTiehGR/jy5SAktIa5c=; b=PybDYUDcaH9NjNfkdTBG9ELjeza6bnXtpDWsAVJpMgScmUpIxNwEd9AZNRq2P6t2zOhTka f0EwJ76mgyZxX5MaVkUs3bICLN25eG3rk40ORNO5DfqLjtBS/hCqQHz8NQVso9PLAhF2eA 7vzSq0ApO+bClodJ1yC5DS8e13cxyHg= X-MC-Unique: qyPu7xMVNHOJzo5rHAFGIA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 3/6] nodedev: refactor nodeDeviceFindNewDevice() Date: Thu, 30 Apr 2020 16:42:55 -0500 Message-Id: <20200430214258.18498-4-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.79 on 10.5.11.16 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" In preparation for creating mediated devices in libvirt, we will need to wait for new mediated devices to be created as well. Refactor nodeDeviceFindNewDevice() so that we can re-use the main logic from this function to wait for different device types by passing a different 'find' function. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/node_device/node_device_driver.c | 33 +++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 6a96a77d92..f948dfbf69 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -446,7 +446,8 @@ nodeDeviceGetTime(time_t *t) return ret; } =20 - +typedef virNodeDevicePtr (*nodeDeviceFindNewDeviceFunc)(virConnectPtr conn, + const void* opaque= ); /* When large numbers of devices are present on the host, it's * possible for udev not to realize that it has work to do before we * get here. We thus keep trying to find the new device we just @@ -462,8 +463,8 @@ nodeDeviceGetTime(time_t *t) */ static virNodeDevicePtr nodeDeviceFindNewDevice(virConnectPtr conn, - const char *wwnn, - const char *wwpn) + nodeDeviceFindNewDeviceFunc func, + const void *opaque) { virNodeDevicePtr device =3D NULL; time_t start =3D 0, now =3D 0; @@ -474,7 +475,7 @@ nodeDeviceFindNewDevice(virConnectPtr conn, =20 virWaitForDevices(); =20 - device =3D nodeDeviceLookupSCSIHostByWWN(conn, wwnn, wwpn, 0); + device =3D func(conn, opaque); =20 if (device !=3D NULL) break; @@ -487,6 +488,28 @@ nodeDeviceFindNewDevice(virConnectPtr conn, return device; } =20 +typedef struct _NewSCISHostFuncData +{ + const char *wwnn; + const char *wwpn; +} NewSCSIHostFuncData; +static virNodeDevicePtr +nodeDeviceFindNewSCSIHostFunc(virConnectPtr conn, + const void *opaque) +{ + const NewSCSIHostFuncData *data =3D opaque; + return nodeDeviceLookupSCSIHostByWWN(conn, data->wwnn, data->wwpn, 0); +} + +static virNodeDevicePtr +nodeDeviceFindNewSCSIHost(virConnectPtr conn, + const char *wwnn, + const char *wwpn) +{ + NewSCSIHostFuncData data =3D { .wwnn =3D wwnn, .wwpn =3D wwpn}; + return nodeDeviceFindNewDevice(conn, nodeDeviceFindNewSCSIHostFunc, &d= ata); +} + static bool nodeDeviceHasCapability(virNodeDeviceDefPtr def, virNodeDevCapType type) { @@ -537,7 +560,7 @@ nodeDeviceCreateXML(virConnectPtr conn, if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) return NULL; =20 - device =3D nodeDeviceFindNewDevice(conn, wwnn, wwpn); + device =3D nodeDeviceFindNewSCSIHost(conn, wwnn, wwpn); /* We don't check the return value, because one way or another, * we're returning what we get... */ =20 --=20 2.21.1 From nobody Thu May 2 23:14:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1588282998; cv=none; d=zohomail.com; s=zohoarc; b=FBquoQr6phupjhVC+062BRJvbp0G8HWdnksA1KzAKTaMd2GIn6P0LrB/LQlc1XMeXYyLtRBJB/zxhqau44ieSGP4HzbDt1a5LPKYgkhr+KbwbRlfdOLq27MbCJ403Jqhwk68PpfEEUs9/XCIOoNdQHRxZISnNbX6eQgQ4n8rwEg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588282998; 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=SDGEB0Z9FoEDUxmYo1ioaf344113B91nsyoqu/Qo3L0=; b=U6Ge0Ai6fCBHa9UsPi4I/lPtyzISVMB6DOpcHJsLrPeih9VKgJqPdV09O+oUiSySAzGiNUK2KJKCgOYHMcQ14EpUfq5hZPCiqnx7YS93EfbV1SWwM7/vytevqQlgwL+09v4fmoAaTWInBcVqS9j7DW30TKyh01N+6JaB6ILiyU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1588282998908933.2993365386728; Thu, 30 Apr 2020 14:43:18 -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-98-s7yXj28QPziDdM73sWs8Vg-1; Thu, 30 Apr 2020 17:43:14 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B084100CCC2; Thu, 30 Apr 2020 21:43:09 +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 20BD938A; Thu, 30 Apr 2020 21:43:09 +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 CB8004CAA0; Thu, 30 Apr 2020 21:43:08 +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 03ULh2Jw003328 for ; Thu, 30 Apr 2020 17:43:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id AF97D1001281; Thu, 30 Apr 2020 21:43:02 +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 8218310013BD for ; Thu, 30 Apr 2020 21:43:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588282997; 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=SDGEB0Z9FoEDUxmYo1ioaf344113B91nsyoqu/Qo3L0=; b=T3yWPBrJWNoE5n9U93/6xw5zoQZ15RgmhKwEXzuydXiMPlZ2X6PqAZ36G+VhmSoW5P7dfm tirx7UKCO2nx/KWflJeMnk/5w6gGkeXdEfN1OIfyziu8MLhml4c8RxJZKxe/RM2aATdqkq qre0qnQZvbtafUcCCP5lF9C99LeK2jQ= X-MC-Unique: s7yXj28QPziDdM73sWs8Vg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 4/6] nodedev: store mdev UUID in mdev caps Date: Thu, 30 Apr 2020 16:42:56 -0500 Message-Id: <20200430214258.18498-5-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.23 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" In order to allow libvirt to create and start new mediated devices, we need to be able to verify that the device has been started. In order to do this, we'll need to save the UUID of newly-discovered devices within the virNodeDevCapMdev structure. This allows us to search the device list by UUID and verify whether the expected device has been started. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/conf/node_device_conf.c | 1 + src/conf/node_device_conf.h | 1 + src/node_device/node_device_udev.c | 5 ++--- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 8cffe48d23..88e1e84f1c 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2254,6 +2254,7 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) break; case VIR_NODE_DEV_CAP_MDEV: VIR_FREE(data->mdev.type); + VIR_FREE(data->mdev.uuid); for (i =3D 0; i < data->mdev.nattributes; i++) virMediatedDeviceAttrFree(data->mdev.attributes[i]); VIR_FREE(data->mdev.attributes); diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index e3e1e788d4..9b8c7aadea 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -141,6 +141,7 @@ typedef virNodeDevCapMdev *virNodeDevCapMdevPtr; struct _virNodeDevCapMdev { char *type; unsigned int iommuGroupNumber; + char *uuid; virMediatedDeviceAttrPtr *attributes; size_t nattributes; }; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 386f23ef3a..bdf0b03add 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1013,7 +1013,6 @@ udevProcessMediatedDevice(struct udev_device *dev, virNodeDeviceDefPtr def) { int ret =3D -1; - const char *uuidstr =3D NULL; int iommugrp =3D -1; char *linkpath =3D NULL; char *canonicalpath =3D NULL; @@ -1041,8 +1040,8 @@ udevProcessMediatedDevice(struct udev_device *dev, =20 data->type =3D g_path_get_basename(canonicalpath); =20 - uuidstr =3D udev_device_get_sysname(dev); - if ((iommugrp =3D virMediatedDeviceGetIOMMUGroupNum(uuidstr)) < 0) + data->uuid =3D g_strdup(udev_device_get_sysname(dev)); + if ((iommugrp =3D virMediatedDeviceGetIOMMUGroupNum(data->uuid)) < 0) goto cleanup; =20 if (udevGenerateDeviceName(dev, def, NULL) !=3D 0) --=20 2.21.1 From nobody Thu May 2 23:14:54 2024 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=1588283014; cv=none; d=zohomail.com; s=zohoarc; b=hKU9TJx2h23PuxG/GHcKAdS9MC0iAhO/hKnLdtqm6tWXwrG5Qu80v/aJ2cSPao0W/t+5n9azpG8U/18mGhSKCvwOqwzNL+HoPTN4bgGCvrY6M3fcZxLjW+4QkjSaqOeqPMga+1fTgjgbyIhSAI+NpFw3C2urwebocvqdxej2T/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588283014; 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=ovpH6OaVWiyUVnvbIBQ6cDd+0twXhNfwpVwWimvrfK0=; b=brskAN7FzMa9thTs/7BxFJhHJeTP5YCUw4XDliIX4q1UlXY9Ro5Xa7/w5fTSEtyEt1QNytxK0lTVCXJ3BQa5xki/DXH5TQga4nZf/g0MmnyrgpKmSMly8bQ4s5mH7VZ//Sy38YhUpbMypeOUVWCuKwXVXl6wH2UGoj9duouBXyM= 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 1588283014319910.9871340079444; Thu, 30 Apr 2020 14:43:34 -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-159-e07i2U4nMVuEPVTbYY54Lw-1; Thu, 30 Apr 2020 17:43:30 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFCD9872FEF; Thu, 30 Apr 2020 21:43:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4259B5D9F5; 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 035F8180954D; 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 03ULh36G003334 for ; Thu, 30 Apr 2020 17:43:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14C521001281; Thu, 30 Apr 2020 21:43:03 +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 CD24810013BD for ; Thu, 30 Apr 2020 21:43:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588283013; 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=ovpH6OaVWiyUVnvbIBQ6cDd+0twXhNfwpVwWimvrfK0=; b=h+fD5vrDbYloOLakHq0h9jlB6cTwULVRoEwLXueHg+o0aeOn0CY3xm1Rab8qEmxlZLqbp8 x88Qo2KlxvMikTfwMCWV0iBhaGaJmXhYVOAQsviw8YSYnqN/Y0QWKVRuFpZm7bs3OqPIzJ I1Hmjt45K+SvGfHQy2wQfT/TPdL1B9M= X-MC-Unique: e07i2U4nMVuEPVTbYY54Lw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 5/6] nodedev: add mdev support to virNodeDeviceCreateXML() Date: Thu, 30 Apr 2020 16:42:57 -0500 Message-Id: <20200430214258.18498-6-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.79 on 10.5.11.14 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" With recent additions to the node device xml schema, an xml schema can now describe a mdev device sufficiently for libvirt to create and start the device using the mdevctl utility. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- libvirt.spec.in | 3 + m4/virt-external-programs.m4 | 3 + src/conf/virnodedeviceobj.c | 34 +++++ src/conf/virnodedeviceobj.h | 3 + src/libvirt_private.syms | 1 + src/node_device/node_device_driver.c | 177 +++++++++++++++++++++++++++ 6 files changed, 221 insertions(+) diff --git a/libvirt.spec.in b/libvirt.spec.in index 6abf97df85..411846a9fc 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -466,6 +466,9 @@ Requires: dbus # For uid creation during pre Requires(pre): shadow-utils =20 +# For managing persistent mediated devices +Recommends: mdevctl + %description daemon Server side daemon required to manage the virtualization capabilities of recent versions of Linux. Requires a hypervisor specific sub-RPM diff --git a/m4/virt-external-programs.m4 b/m4/virt-external-programs.m4 index 9046e3bf07..bd3cb1f757 100644 --- a/m4/virt-external-programs.m4 +++ b/m4/virt-external-programs.m4 @@ -65,6 +65,7 @@ AC_DEFUN([LIBVIRT_CHECK_EXTERNAL_PROGRAMS], [ AC_PATH_PROG([OVSVSCTL], [ovs-vsctl], [ovs-vsctl], [$LIBVIRT_SBIN_PATH]) AC_PATH_PROG([SCRUB], [scrub], [scrub], [$LIBVIRT_SBIN_PATH]) AC_PATH_PROG([ADDR2LINE], [addr2line], [addr2line], [$LIBVIRT_SBIN_PATH]) + AC_PATH_PROG([MDEVCTL], [mdevctl], [mdevctl], [$LIBVIRT_SBIN_PATH]) =20 AC_DEFINE_UNQUOTED([DMIDECODE], ["$DMIDECODE"], [Location or name of the dmidecode program]) @@ -88,6 +89,8 @@ AC_DEFUN([LIBVIRT_CHECK_EXTERNAL_PROGRAMS], [ [Location or name of the scrub program (for wiping al= gorithms)]) AC_DEFINE_UNQUOTED([ADDR2LINE], ["$ADDR2LINE"], [Location of addr2line program]) + AC_DEFINE_UNQUOTED([MDEVCTL], ["$MDEVCTL"], + [Location or name of the mdevctl program]) =20 AC_PATH_PROG([IP_PATH], [ip], [/sbin/ip], [$LIBVIRT_SBIN_PATH]) AC_DEFINE_UNQUOTED([IP_PATH], ["$IP_PATH"], [path to ip binary]) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 3a34a324ca..fd20d5f9e2 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -399,6 +399,40 @@ virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceOb= jListPtr devs, &data); } =20 +static int +virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(const void *payload, + const void *name G_GN= UC_UNUSED, + const void *opaque G_= GNUC_UNUSED) +{ + virNodeDeviceObjPtr obj =3D (virNodeDeviceObjPtr) payload; + const char *uuid =3D (const char *) opaque; + virNodeDevCapsDefPtr cap; + int want =3D 0; + + virObjectLock(obj); + + for (cap =3D obj->def->caps; cap !=3D NULL; cap =3D cap->next) { + if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) { + if (STREQ(cap->data.mdev.uuid, uuid)) { + want =3D 1; + break; + } + } + } + + virObjectUnlock(obj); + return want; +} + + +virNodeDeviceObjPtr +virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjListPtr devs, + const char *uuid) +{ + return virNodeDeviceObjListSearch(devs, + virNodeDeviceObjListFindMediatedDevi= ceByUUIDCallback, + uuid); +} =20 static void virNodeDeviceObjListDispose(void *obj) diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index c9df8dedab..6efdb23d36 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -118,3 +118,6 @@ virNodeDeviceObjListExport(virConnectPtr conn, void virNodeDeviceObjSetSkipUpdateCaps(virNodeDeviceObjPtr obj, bool skipUpdateCaps); +virNodeDeviceObjPtr +virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjListPtr devs, + const char *uuid); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 94b206aa21..0468f68f52 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1178,6 +1178,7 @@ virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; virNodeDeviceObjListFindByName; virNodeDeviceObjListFindBySysfsPath; +virNodeDeviceObjListFindMediatedDeviceByUUID; virNodeDeviceObjListFindSCSIHostByWWNs; virNodeDeviceObjListFree; virNodeDeviceObjListGetNames; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index f948dfbf69..c271f3bae5 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -30,6 +30,7 @@ #include "datatypes.h" #include "viralloc.h" #include "virfile.h" +#include "virjson.h" #include "virstring.h" #include "node_device_conf.h" #include "node_device_event.h" @@ -40,6 +41,7 @@ #include "viraccessapicheck.h" #include "virnetdev.h" #include "virutil.h" +#include "vircommand.h" =20 #define VIR_FROM_THIS VIR_FROM_NODEDEV =20 @@ -304,6 +306,30 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, return device; } =20 +static virNodeDevicePtr +nodeDeviceLookupMediatedDeviceByUUID(virConnectPtr conn, + const char *uuid, + unsigned int flags) +{ + virNodeDeviceObjPtr obj =3D NULL; + virNodeDeviceDefPtr def; + virNodeDevicePtr device =3D NULL; + + virCheckFlags(0, NULL); + + if (!(obj =3D virNodeDeviceObjListFindMediatedDeviceByUUID(driver->dev= s, + uuid))) + return NULL; + + def =3D virNodeDeviceObjGetDef(obj); + + if ((device =3D virGetNodeDevice(conn, def->name))) + device->parentName =3D g_strdup(def->parent); + + virNodeDeviceObjEndAPI(&obj); + return device; +} + =20 char * nodeDeviceGetXMLDesc(virNodeDevicePtr device, @@ -488,6 +514,23 @@ nodeDeviceFindNewDevice(virConnectPtr conn, return device; } =20 +static virNodeDevicePtr +nodeDeviceFindNewMediatedDeviceFunc(virConnectPtr conn, + const void *opaque) +{ + const char *uuid =3D opaque; + return nodeDeviceLookupMediatedDeviceByUUID(conn, uuid, 0); +} + +static virNodeDevicePtr +nodeDeviceFindNewMediatedDevice(virConnectPtr conn, + const char *mdev_uuid) +{ + return nodeDeviceFindNewDevice(conn, + nodeDeviceFindNewMediatedDeviceFunc, + mdev_uuid); +} + typedef struct _NewSCISHostFuncData { const char *wwnn; @@ -525,6 +568,68 @@ nodeDeviceHasCapability(virNodeDeviceDefPtr def, virNo= deDevCapType type) return false; } =20 +static int +virNodeDeviceDefToMdevctlConfig(virNodeDeviceDefPtr def, char **buf) +{ + size_t i; + virNodeDevCapMdevPtr mdev =3D &def->caps->data.mdev; + g_autoptr(virJSONValue) json =3D virJSONValueNewObject(); + + if (virJSONValueObjectAppendString(json, "mdev_type", mdev->type) < 0) + return -1; + if (virJSONValueObjectAppendString(json, "start", "manual") < 0) + return -1; + if (mdev->attributes) { + g_autoptr(virJSONValue) attributes =3D virJSONValueNewArray(); + for (i =3D 0; i < mdev->nattributes; i++) { + virMediatedDeviceAttrPtr attr =3D mdev->attributes[i]; + g_autoptr(virJSONValue) jsonattr =3D virJSONValueNewObject(); + + if (virJSONValueObjectAppendString(jsonattr, attr->name, attr-= >value) < 0) + return -1; + if (virJSONValueArrayAppend(attributes, g_steal_pointer(&jsona= ttr)) < 0) + return -1; + } + if (virJSONValueObjectAppend(json, "attrs", g_steal_pointer(&attri= butes)) < 0) + return -1; + } + + *buf =3D virJSONValueToString(json, false); + if (*buf =3D=3D NULL) + return -1; + + return 0; +} + +static int +virMdevctlStart(const char *parent, const char *json_file, char **uuid) +{ + int status; + g_autofree char *mdevctl =3D virFindFileInPath(MDEVCTL); + if (!mdevctl) + return -1; + + g_autoptr(virCommand) cmd =3D virCommandNewArgList(mdevctl, + "start", + "-p", + parent, + "--jsonfile", + json_file, + NULL); + virCommandAddEnvPassCommon(cmd); + virCommandSetOutputBuffer(cmd, uuid); + + /* an auto-generated uuid is returned via stdout if no uuid is specifi= ed in + * the mdevctl args */ + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + /* remove newline */ + *uuid =3D g_strstrip(*uuid); + + return 0; +} + virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, @@ -569,6 +674,78 @@ nodeDeviceCreateXML(virConnectPtr conn, _("no node device for '%s' with matching " "wwnn '%s' and wwpn '%s'"), def->name, wwnn, wwpn); + } else if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + virNodeDeviceObjPtr parent_dev =3D NULL; + virNodeDeviceDefPtr parent_def =3D NULL; + virNodeDevCapsDefPtr parent_caps =3D NULL; + g_autofree char *uuid =3D NULL; + g_autofree char *parent_pci =3D NULL; + + if (def->parent =3D=3D NULL) { + virReportError(VIR_ERR_NO_NODE_DEVICE, "%s", + _("cannot create a mediated device without a pa= rent")); + return NULL; + } + + if ((parent_dev =3D virNodeDeviceObjListFindByName(driver->devs, d= ef->parent)) =3D=3D NULL) { + virReportError(VIR_ERR_NO_NODE_DEVICE, + _("could not find parent device '%s'"), def->pa= rent); + return NULL; + } + + parent_def =3D virNodeDeviceObjGetDef(parent_dev); + for (parent_caps =3D parent_def->caps; parent_caps !=3D NULL; pare= nt_caps =3D parent_caps->next) { + if (parent_caps->data.type =3D=3D VIR_NODE_DEV_CAP_PCI_DEV) { + virPCIDeviceAddress addr =3D { + .domain =3D parent_caps->data.pci_dev.domain, + .bus =3D parent_caps->data.pci_dev.bus, + .slot =3D parent_caps->data.pci_dev.slot, + .function =3D parent_caps->data.pci_dev.function + }; + + parent_pci =3D virPCIDeviceAddressAsString(&addr); + break; + } + } + + virNodeDeviceObjEndAPI(&parent_dev); + + if (parent_pci =3D=3D NULL) { + virReportError(VIR_ERR_NO_NODE_DEVICE, + _("unable to find PCI address for parent device= '%s'"), def->parent); + return NULL; + } + + /* Convert node device definition to a JSON string formatted for + * mdevctl */ + g_autofree char *json =3D NULL; + if (virNodeDeviceDefToMdevctlConfig(def, &json) < 0) { + virReportError(VIR_ERR_NO_NODE_DEVICE, "%s", + _("couldn't convert node device def to mdevctl = JSON")); + return NULL; + } + + g_autofree char *tmp =3D g_build_filename(driver->stateDir, "mdev-= json-XXXXXX", NULL); + gint tmpfd; + + if ((tmpfd =3D g_mkstemp_full(tmp, O_RDWR | O_CLOEXEC, S_IRUSR | S= _IWUSR)) < 0) { + virReportSystemError(errno, "%s", _("Failed to open temp file = for write")); + return NULL; + } + if (safewrite(tmpfd, json, strlen(json)) !=3D strlen(json) || + VIR_CLOSE(tmpfd) < 0) { + virReportSystemError(errno, "%s", _("Failed to write temp file= ")); + return NULL; + } + + if (virMdevctlStart(parent_pci, tmp, &uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to start mediated device")); + return NULL; + } + + if (uuid && uuid[0] !=3D '\0') + device =3D nodeDeviceFindNewMediatedDevice(conn, uuid); } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Unsupported device type")); --=20 2.21.1 From nobody Thu May 2 23:14:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1588283139; cv=none; d=zohomail.com; s=zohoarc; b=UhFFz++Rf4lb+SDIZ81YCk4U3EaOd5n9r06WpQd4XsgX1vRkGloRKVjCevjrp19ktxjuuUQ6BqgZeEdfeEQAyvOzvH71kJ5/kV1qTdK9yXSZ1MZn9HxBykpACTMq1dxyX7n3lcpnuN93bGf8CWGf1iEzrmwl9fX370W3AyGfzeY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588283139; 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=fs2vG45hlNEy8fZRrxyMQpfWxd6bCZ1m+1mmIbUdE2Q=; b=QfWsIaJYF+GoSGUqV9ZT0aAZp3rOvT1nGVNySSY+qZK6qB1fGA3AVLAH8Tha6W8DFBYLsMGCe3EdXnk/ZEanWELZtpUDecD8AOFA94Xx1HEGNzUxcATxfs7yx1i/UQ2oqhAqpk0OXgfp7VLGag0yqWE13noR9L1+jwIRy0Y7vsc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1588283139332342.4810788531762; Thu, 30 Apr 2020 14:45:39 -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-303-RZMT_N5HMJWibfTPPQO4iQ-1; Thu, 30 Apr 2020 17:45:36 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F1B318005B7; Thu, 30 Apr 2020 21:45:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7AA738A; Thu, 30 Apr 2020 21:45:30 +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 821541809542; Thu, 30 Apr 2020 21:45:30 +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 03ULh37W003339 for ; Thu, 30 Apr 2020 17:43:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5F6F31001281; Thu, 30 Apr 2020 21:43:03 +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 315AD10013BD for ; Thu, 30 Apr 2020 21:43:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588283138; 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=fs2vG45hlNEy8fZRrxyMQpfWxd6bCZ1m+1mmIbUdE2Q=; b=IiGDiyRMHR84ym2fPev26r0wA0b0YmqG+DZZoYwdF7dOYvltWTt0X+aSUWeCn7tYkoahSL saVII+lzhbrfA6k3OyTyrhnp9xyqsZSPT4snEv0suzn+ptD33MtjMELxFzdb7Kc3l5Ek1m b0P/8gf2ApSlOiQXTys4VuCAvmeoveI= X-MC-Unique: RZMT_N5HMJWibfTPPQO4iQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 6/6] nodedev: add mdev support to virNodeDeviceDestroy() Date: Thu, 30 Apr 2020 16:42:58 -0500 Message-Id: <20200430214258.18498-7-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.23 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" Add the ability to destroy mdev node devices via the mdevctl utility. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/node_device/node_device_driver.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index c271f3bae5..113cc063df 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -630,6 +630,27 @@ virMdevctlStart(const char *parent, const char *json_f= ile, char **uuid) return 0; } =20 +static int +virMdevctlStop(const char *uuid) +{ + int status; + g_autofree char *mdevctl =3D virFindFileInPath(MDEVCTL); + if (!mdevctl) + return -1; + + g_autoptr(virCommand) cmd =3D virCommandNewArgList(mdevctl, + "stop", + "-u", + uuid, + NULL); + virCommandAddEnvPassCommon(cmd); + + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + return 0; +} + virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, @@ -801,6 +822,13 @@ nodeDeviceDestroy(virNodeDevicePtr device) if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0) goto cleanup; =20 + ret =3D 0; + } else if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + if (virMdevctlStop(def->caps->data.mdev.uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to stop mediated device")); + goto cleanup; + } ret =3D 0; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", --=20 2.21.1