From nobody Wed May 1 06:22:20 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=1591739048; cv=none; d=zohomail.com; s=zohoarc; b=mePOcBz8kzrNWdChhbRKBVlgHIsdBxN1yfUWy0iuRuTbcNpDvhownCNizg0x7VY+VWroVa7QZwXg639B9zHqQ7+e7ZD7UoxfTzzSrdUleXP2YkxMTcSqzqbB2DCUHAqtFhWGgTqlJ9+RA1UkzT4oeT9JIgj8x21QPMSWVZN/EeE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591739048; 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=N3hTaVGVwHUqmVte6DOVoXYX5lLb6NrzDQlJ+l2SDvM=; b=izcaw5E0CLr8T1Mbu8AUiwVMnknZHHRGz9bo+84kUSHodSxg1uoWRSjycifMSDvZpZc2QP9VvIyH5uq1/75lwaOvZvpO+dR0ys5RJLrl6yBTooFiiYfyLBcQvTqVOAivzgrLs/EiLeYeOYcJB7p02K9FDhcT1YXBipPABmdNRmk= 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 1591739048600161.2322979664698; Tue, 9 Jun 2020 14:44:08 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-488-dF9N-pNpP0qc7lMuc-V7Mg-1; Tue, 09 Jun 2020 17:44:04 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0AF5464; Tue, 9 Jun 2020 21:43:59 +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 A50F289296; Tue, 9 Jun 2020 21:43:58 +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 527EFB3495; Tue, 9 Jun 2020 21:43:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059LhswX030066 for ; Tue, 9 Jun 2020 17:43:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 080707BFE9; Tue, 9 Jun 2020 21:43:54 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-112.phx2.redhat.com [10.3.115.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CFBA57BFE3 for ; Tue, 9 Jun 2020 21:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591739047; 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=N3hTaVGVwHUqmVte6DOVoXYX5lLb6NrzDQlJ+l2SDvM=; b=HLKG4LigBzFwcT8Ru2IJCrmTVCc4CMVyzkzkjiT5E3n05ueWZx9IoxyojrfluMWvPMOnGN gbOssbTJ/UnZ+G57CkvFtUOP58B8G/YONiTSMjATzPqGPMhoWOJJhXnoTNM2YDyWKq1lGr OiSkGfkHlCBQAcXbCIZNP/DSOvjFG+U= X-MC-Unique: dF9N-pNpP0qc7lMuc-V7Mg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 01/10] nodedev: factor out nodeDeviceHasCapability() Date: Tue, 9 Jun 2020 16:43:41 -0500 Message-Id: <20200609214350.14156-2-jjongsma@redhat.com> In-Reply-To: <20200609214350.14156-1-jjongsma@redhat.com> References: <20200609214350.14156-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 | 91 ++++++++++++++++++---------- 1 file changed, 58 insertions(+), 33 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index ee175e1095..ba7ea50e5b 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -488,6 +488,21 @@ nodeDeviceFindNewDevice(virConnectPtr conn, } =20 =20 +static bool +nodeDeviceHasCapability(virNodeDeviceDefPtr def, virNodeDevCapType type) +{ + virNodeDevCapsDefPtr cap =3D def->caps; + + while (cap !=3D NULL) { + if (cap->data.type =3D=3D type) + return true; + cap =3D cap->next; + } + + return false; +} + + virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, @@ -513,24 +528,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 +577,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.3 From nobody Wed May 1 06:22:20 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=1591739062; cv=none; d=zohomail.com; s=zohoarc; b=hmMZWSX/vtXoRfMzTLmu6BnkoaCUk+HePqx4BGZYJ6Vnq2zQ5TNkDQk1ciaV2N5so36Cd+Jv6giYS9it2NEiuZUYQ8KJ2EqqoezB46YiHxBXlCpj5UTFSJaxzLBuKui0BDifHWgpEDo9jqLrgZA8nFKzNND+Fi6Ji8wYOngO9io= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591739062; 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=XPI9oQnL7NUy9ZoNIfXWVsOHTdRQ57Ke9Vmcvzd3nLY=; b=ZO4YT6SM4iUtqMLlN1hhdVABpKz2Ftc0pDE1l5P+qigetuXLSO1HqZ9lWGqAe3H2b+BoSkjhDCOIecSjksfD7TmKPjB4fmdsg8PaNgJiqiRMa2/il1voD1nbIkcgaHDG4pToVrieglU2taed1qBCcKRVNn4OQNEhnwS303EBKsw= 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 1591739062827284.6219609637949; Tue, 9 Jun 2020 14:44:22 -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-505-PXSAqoYyPy692u5O4sb_Bw-1; Tue, 09 Jun 2020 17:44:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D64E31007275; Tue, 9 Jun 2020 21:44:13 +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 B5E2C7A8C9; Tue, 9 Jun 2020 21:44:13 +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 7989B1809547; Tue, 9 Jun 2020 21:44:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059Lhsai030072 for ; Tue, 9 Jun 2020 17:43:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5DF5B7BFE9; Tue, 9 Jun 2020 21:43:54 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-112.phx2.redhat.com [10.3.115.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23E2C7BFE3 for ; Tue, 9 Jun 2020 21:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591739061; 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=XPI9oQnL7NUy9ZoNIfXWVsOHTdRQ57Ke9Vmcvzd3nLY=; b=iCR/UqI9K4gRCtDGe1n6fpYB7BsjN5OV52I4jMVrOBS3moS33tOd3+L/zSR8GuiRIhBAfi 9bVNoW7uUIPC3G+zu12K0Cbo+v4xKOW5fODD7WmTZo2U7pStWdpoHbUBMFn0KmGO+DXmk2 9GkJtorMEdQqnQJTB9lQlmMcmhlTPZs= X-MC-Unique: PXSAqoYyPy692u5O4sb_Bw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 02/10] nodedev: add support for mdev attributes Date: Tue, 9 Jun 2020 16:43:42 -0500 Message-Id: <20200609214350.14156-3-jjongsma@redhat.com> In-Reply-To: <20200609214350.14156-1-jjongsma@redhat.com> References: <20200609214350.14156-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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: Erik Skultety Reviewed-by: Michal Privoznik --- docs/formatnode.html.in | 7 +++++ docs/schemas/nodedev.rng | 6 ++++ src/conf/node_device_conf.c | 59 +++++++++++++++++++++++++++++++++++-- src/conf/node_device_conf.h | 2 ++ src/libvirt_private.syms | 2 ++ src/util/virmdev.c | 12 ++++++++ src/util/virmdev.h | 11 +++++++ 7 files changed, 96 insertions(+), 3 deletions(-) diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index 76eae928de..a46b73254b 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -393,6 +393,13 @@ which holds the IOMMU group number the mediated device bel= ongs to. +
attr
+
+ This optional element can occur multiple times. It represe= nts a + vendor-specific attribute that is used to configure this + mediated device. It has two required attributes: + name and value. +
ccw
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 bccdbd0af8..045d146433 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -500,6 +500,21 @@ 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 +598,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", @@ -1757,6 +1770,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_APPEND_ELEMENT(mdev->attributes, + mdev->nattributes, + attr) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + ctxt->node =3D orig_node; + return ret; +} =20 static int virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, @@ -1766,6 +1808,9 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, { VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; + int nattrs =3D 0; + xmlNodePtr *attrs; + size_t i; =20 ctxt->node =3D node; =20 @@ -1783,6 +1828,11 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, "'%s'")) < 0) goto out; =20 + if ((nattrs =3D virXPathNodeSet("./attr", ctxt, &attrs)) < 0) + goto out; + for (i =3D 0; i < nattrs; i++) + virNodeDevCapMdevAttributeParseXML(ctxt, attrs[i], mdev); + ret =3D 0; out: return ret; @@ -2172,6 +2222,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 a6af44fe1c..b8e6f058c3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2486,6 +2486,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 51a88a91d7..b8023dd991 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -512,3 +512,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.3 From nobody Wed May 1 06:22:20 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=1591739065; cv=none; d=zohomail.com; s=zohoarc; b=D55KtyDYXbBHm51hrIVC+26IqSU8F4ghYa1LBFUD5QkawEpyEnkL9pYEujFXGNt2xfT3Ddh3PF7/rKCHwy9WFNkIhyjgeiGpeNR2vEo0bd48o3GTH1AbvkArO60OSBIvXitkHImkTyGqmKFhbQlyvT4XDYVpqEd9kf0JTd+/7DY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591739065; 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=5lGC7CPzBqUeau0wkem9GXtfUh47cOpncobTRU/QsZg=; b=X3rIG1FRjZvut7Puxf8eWo15KbP1m5zN9OPKgyqvhPkJU0E1Cr/suZgi9NOn429U6KR2f9B4zidW33pLa2K/WS3+mwpFF23cCWpY47wK3wDC64aGgc1vfTc5eiflude5MAsyx7S8dsugXrlejUhgxCJ+ZPfCtAEZECBPJNDrICA= 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 1591739065004324.308720619488; Tue, 9 Jun 2020 14:44:25 -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-404-Wgkt5bWwPISz0zAuGhGxrA-1; Tue, 09 Jun 2020 17:44:21 -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 294CE835B43; Tue, 9 Jun 2020 21:44:16 +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 0ADA65C1BD; Tue, 9 Jun 2020 21:44:16 +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 CE0E81809563; Tue, 9 Jun 2020 21:44:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059Lhs7D030078 for ; Tue, 9 Jun 2020 17:43:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id A4F467BFE9; Tue, 9 Jun 2020 21:43:54 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-112.phx2.redhat.com [10.3.115.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78F437BFE3 for ; Tue, 9 Jun 2020 21:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591739063; 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=5lGC7CPzBqUeau0wkem9GXtfUh47cOpncobTRU/QsZg=; b=MX+jUMPawmUlbuPRrEX4l8j1nLRs0v0/UJyo3wR573/eMH5/OXoZl9RXabRjyG4Eyw1J2j xUgk3RSHLP5JX6KDuLLm5m1XjnGge7YWjXtbtaEeKwc+laNoT7OOOpJiSNYmq+WWskuQzU UIPfBOcLHN6YiYLTgRUeqQQDzuD5faY= X-MC-Unique: Wgkt5bWwPISz0zAuGhGxrA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 03/10] nodedev: refactor nodeDeviceFindNewDevice() Date: Tue, 9 Jun 2020 16:43:43 -0500 Message-Id: <20200609214350.14156-4-jjongsma@redhat.com> In-Reply-To: <20200609214350.14156-1-jjongsma@redhat.com> References: <20200609214350.14156-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.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: Erik Skultety Reviewed-by: Michal Privoznik --- src/node_device/node_device_driver.c | 39 +++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index ba7ea50e5b..629d4bcf91 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -447,6 +447,10 @@ nodeDeviceGetTime(time_t *t) } =20 =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 +466,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 +478,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; @@ -488,6 +492,33 @@ nodeDeviceFindNewDevice(virConnectPtr conn, } =20 =20 +typedef struct _NewSCSIHostFuncData NewSCSIHostFuncData; +struct _NewSCSIHostFuncData +{ + const char *wwnn; + const char *wwpn; +}; + + +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) { @@ -538,7 +569,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.3 From nobody Wed May 1 06:22:20 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=1591739110; cv=none; d=zohomail.com; s=zohoarc; b=HMCz1k5iih58266Qj7bMdIKhk4qgzLi5dz6HiWGTOBY8iKnt7goUUD34x5feEuoAXLQ0kVzt+dWZxkOazPcnloMVxJ6aYXnXiv12iUlM3SE5nqfXcQKSoini1NIWX5i0w/7gbNrCjBmXtIqrwD5x7MeE0w58FIYp2NUyzT6Ihes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591739110; 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=nUprATTtjIVveCsxaoaWJuyiZRPhRBVyoZOCMJ47qpU=; b=hZimOIuz2jvQ0S0cGrQ+E05biAfvWP/CwH8jqYJSs1sy/9ErtJyRBnbAeeFlCr5Emi2AKPOvbHDlirUWKRsiPAXund7tpNXK+CSoj53u3K8Hi85aVlJDScV6l8A2zo43jbu3oP8VCJ5VcsskJlPPYmqUUr70UE4DM+LLLcxf7BY= 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 15917391100431011.9395429108456; Tue, 9 Jun 2020 14:45:10 -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-407-pyDSzJYAP62qG27GY7Lk3Q-1; Tue, 09 Jun 2020 17:44:47 -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 B88E4107ACF5; Tue, 9 Jun 2020 21:44:41 +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 99BC95FC1B; Tue, 9 Jun 2020 21:44:41 +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 6D175180043B; Tue, 9 Jun 2020 21:44:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059Lhsoe030085 for ; Tue, 9 Jun 2020 17:43:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id EBF3D7BFE9; Tue, 9 Jun 2020 21:43:54 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-112.phx2.redhat.com [10.3.115.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C02867BFE3 for ; Tue, 9 Jun 2020 21:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591739108; 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=nUprATTtjIVveCsxaoaWJuyiZRPhRBVyoZOCMJ47qpU=; b=MP8OekWMH0BjWgi2Dl0sZsCwDIscfEENXokmUlwTYsmkiAC2XruJRMvMh3n/11B8w4i9e0 OHeFgvE3qUaxWVzf7mDHwD90eIH+Vp3SjdL2YMb7brOy8wrMXzvSc/8Qc/hD9OyRxq1CDU iJenUl+b6XztGa92dReO4V2WyTTLEP8= X-MC-Unique: pyDSzJYAP62qG27GY7Lk3Q-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 04/10] nodedev: store mdev UUID in mdev caps Date: Tue, 9 Jun 2020 16:43:44 -0500 Message-Id: <20200609214350.14156-5-jjongsma@redhat.com> In-Reply-To: <20200609214350.14156-1-jjongsma@redhat.com> References: <20200609214350.14156-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.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 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: Erik Skultety 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 045d146433..7bf00bb5bc 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2222,6 +2222,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.3 From nobody Wed May 1 06:22:20 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=1591739093; cv=none; d=zohomail.com; s=zohoarc; b=jahXgicq0c498hZZjoT1vvsqovjRqRxUg3UwQ0/exTy2LtPui08lYZY51zEi7rnhkSNuTVV7p+u4Wi6DX7ex/8A4f3wJiI8EqbpEJrSipwU98NZ7hiJ6KWu64XSAMToqZGI2JtpHfsqHdtA9RcF8tZbqjMmn2QUfHIXapOoebhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591739093; 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=bcG5k7cq8kXeFAIejYtwU3vm4CBs6ELwDP2yQzrrKhQ=; b=RyNkAVpVfUAu2OGhXaFojzB+KFYVhpa+x2pRAhwXf6tQkbIpiR9r8zzJdw0vGvNzA6wLIPs7CkGQHKJ09jr9ESJ6bDU8lY3hq3RTb9qTtI1XOMAXYbnQW2GrlewLBguwnxtOmuL0nt39d35B4kFt2j4y3U6Vc5rlfv9c97RCOrQ= 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 1591739093071705.5591048744253; Tue, 9 Jun 2020 14:44:53 -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-491-i6ouRnUrM9SBZ2yM_f4Hng-1; Tue, 09 Jun 2020 17:44:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 12BBA188360A; Tue, 9 Jun 2020 21:44:44 +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 E7B8882052; Tue, 9 Jun 2020 21:44:43 +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 B50401806B0A; Tue, 9 Jun 2020 21:44:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059Lht4Y030095 for ; Tue, 9 Jun 2020 17:43:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4D1927BFE9; Tue, 9 Jun 2020 21:43:55 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-112.phx2.redhat.com [10.3.115.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 133B97BFE3 for ; Tue, 9 Jun 2020 21:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591739091; 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=bcG5k7cq8kXeFAIejYtwU3vm4CBs6ELwDP2yQzrrKhQ=; b=D6fNQ4vV6astjfDaKn/45x+CSA3b8TM4N+jz7g0gBhrHpfWgs7HC1zgFz92buE7HXr8HIr UiPkQ8dEkCB1NfrDPLAZnrMn00ahhGlYx3UBzqGB6saoJWGUJtPT9PakHDLH2oENNRtUOB /oKymge3pmRVKbRlD1D8BzGtp+vBpF0= X-MC-Unique: i6ouRnUrM9SBZ2yM_f4Hng-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 05/10] nodedev: add mdev support to virNodeDeviceCreateXML() Date: Tue, 9 Jun 2020 16:43:45 -0500 Message-Id: <20200609214350.14156-6-jjongsma@redhat.com> In-Reply-To: <20200609214350.14156-1-jjongsma@redhat.com> References: <20200609214350.14156-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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. Note that some of the the configuration for a mediated device must be passed to mdevctl as a JSON-formatted file. In order to avoid creating and cleaning up temporary files, the JSON is instead fed to stdin and we pass the filename /dev/stdin to mdevctl. While this may not be portable, neither are mediated devices, so I don't believe it should cause any problems. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- libvirt.spec.in | 2 + 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 | 203 +++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 6 + 7 files changed, 252 insertions(+) diff --git a/libvirt.spec.in b/libvirt.spec.in index 262e66f3cc..2b3a4d2e71 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -522,6 +522,8 @@ Requires: libvirt-daemon =3D %{version}-%{release} Requires: libvirt-libs =3D %{version}-%{release} # needed for device enumeration Requires: systemd >=3D 185 +# For managing persistent mediated devices +Requires: mdevctl =20 %description daemon-driver-nodedev The nodedev driver plugin for the libvirtd daemon, providing 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 b8e6f058c3..532169d93d 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 629d4bcf91..dbc7eb4d1e 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, @@ -492,6 +518,25 @@ nodeDeviceFindNewDevice(virConnectPtr conn, } =20 =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 _NewSCSIHostFuncData NewSCSIHostFuncData; struct _NewSCSIHostFuncData { @@ -534,6 +579,162 @@ nodeDeviceHasCapability(virNodeDeviceDefPtr def, virN= odeDevCapType type) } =20 =20 +/* format a json string that provides configuration information about this= mdev + * to the mdevctl utility */ +static int +nodeDeviceDefToMdevctlConfig(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) + return -1; + + return 0; +} + + +static char * +nodeDeviceFindAddressByName(const char *name) +{ + virNodeDeviceDefPtr def =3D NULL; + virNodeDevCapsDefPtr caps =3D NULL; + char *pci_addr =3D NULL; + virNodeDeviceObjPtr dev =3D virNodeDeviceObjListFindByName(driver->dev= s, name); + + if (!dev) { + virReportError(VIR_ERR_NO_NODE_DEVICE, + _("could not find device '%s'"), name); + return NULL; + } + + def =3D virNodeDeviceObjGetDef(dev); + for (caps =3D def->caps; caps !=3D NULL; caps =3D caps->next) { + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_PCI_DEV) { + virPCIDeviceAddress addr =3D { + .domain =3D caps->data.pci_dev.domain, + .bus =3D caps->data.pci_dev.bus, + .slot =3D caps->data.pci_dev.slot, + .function =3D caps->data.pci_dev.function + }; + + pci_addr =3D virPCIDeviceAddressAsString(&addr); + break; + } + } + + virNodeDeviceObjEndAPI(&dev); + + return pci_addr; +} + + +virCommandPtr +nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, + bool persist, + char **uuid_out) +{ + virCommandPtr cmd; + const char *subcommand; + g_autofree char *json =3D NULL; + g_autofree char *mdevctl =3D virFindFileInPath(MDEVCTL); + g_autofree char *parent_pci =3D nodeDeviceFindAddressByName(def->paren= t); + + if (!mdevctl) + return NULL; + + if (!parent_pci) { + virReportError(VIR_ERR_NO_NODE_DEVICE, + _("unable to find PCI address for parent device '%s= '"), def->parent); + return NULL; + } + + if (nodeDeviceDefToMdevctlConfig(def, &json) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("couldn't convert node device def to mdevctl JSON= ")); + return NULL; + } + + if (persist) + subcommand =3D "define"; + else + subcommand =3D "start"; + + cmd =3D virCommandNewArgList(mdevctl, subcommand, + "-p", parent_pci, + "--jsonfile", "/dev/stdin", + NULL); + + virCommandSetInputBuffer(cmd, json); + virCommandSetOutputBuffer(cmd, uuid_out); + + return cmd; +} + +static int +virMdevctlStart(virNodeDeviceDefPtr def, char **uuid) +{ + int status; + g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlStartCommand(def, fa= lse, + uuid); + if (!cmd) + return -1; + + /* 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; +} + + +static virNodeDevicePtr +nodeDeviceCreateXMLMdev(virConnectPtr conn, + virNodeDeviceDefPtr def) +{ + g_autofree char *uuid =3D NULL; + + if (!def->parent) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("cannot create a mediated device without a parent= ")); + return NULL; + } + + if (virMdevctlStart(def, &uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to start mediated device")); + return NULL; + } + + return nodeDeviceFindNewMediatedDevice(conn, uuid); +} + + virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, @@ -578,6 +779,8 @@ 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)) { + device =3D nodeDeviceCreateXMLMdev(conn, def); } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Unsupported device type")); diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index eae5e2cb17..576f75375f 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -24,6 +24,7 @@ #include "internal.h" #include "driver.h" #include "virnodedeviceobj.h" +#include "vircommand.h" =20 #define LINUX_NEW_DEVICE_WAIT_TIME 60 =20 @@ -116,3 +117,8 @@ nodeConnectNodeDeviceEventRegisterAny(virConnectPtr con= n, int nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn, int callbackID); + +virCommandPtr +nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, + bool persist, + char **uuid_out); --=20 2.21.3 From nobody Wed May 1 06:22:20 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=1591739050; cv=none; d=zohomail.com; s=zohoarc; b=JuOCyRVk85dgyTe3Fnf+bsgFZd2yZntlgpx9hG7xgrucgxsVfQrkvoYTkLXVojRXLn1wm0fr4WI84v/DrOM/BQCYCwCWRAA1BH9wgTh0XWcblTDuBSG6/+UKNI6NQRPxuct5Iu63QyUVEuFSJWcn79ap61qW6ncCDqOFUUMSmak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591739050; 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=hA2cs+ARia4N4iPiv2vKi8AxcNC/kt7VVjomey0pTy4=; b=FaQrnoyTeee8feSz57Wbd5z3qWrEPDmYJCxlObcuAcaziRgFiUc30rDLvtYKIPBsbh+ltXbEbo+9LlA83pQcii6im0k2GghzovdMSwxESPfqOtdwTOQx4/MpANv7FKnvyYll4oVIrltfObXdHzs7A/pjX3yMxayCL9stumWIMek= 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 1591739050414376.7936082406778; Tue, 9 Jun 2020 14:44:10 -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-239--GvSaBcTPgClx5ZBseBbtg-1; Tue, 09 Jun 2020 17:44:05 -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 9A594461; Tue, 9 Jun 2020 21:43:59 +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 DC4547BFE3; Tue, 9 Jun 2020 21:43:58 +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 9401AB349E; Tue, 9 Jun 2020 21:43:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059Lht2V030105 for ; Tue, 9 Jun 2020 17:43:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 94E927BFE3; Tue, 9 Jun 2020 21:43:55 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-112.phx2.redhat.com [10.3.115.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 680F17C002 for ; Tue, 9 Jun 2020 21:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591739049; 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=hA2cs+ARia4N4iPiv2vKi8AxcNC/kt7VVjomey0pTy4=; b=EwOW9G2OYzwtdZHuIM5TRaWKBCxudY18yv8IHmtUQGu1ihk1UJcFuCs3Ij7dl7WU9ew6/w zQRfLA/dgCeKldiNqATN132rfvgEVA4LM2w39G5F8oEy5Wqd8ibBXJNmG/WRPNsS3sJ+rZ W5hmufncXJkJWjWhw8Tqv/lVLSZcEXw= X-MC-Unique: -GvSaBcTPgClx5ZBseBbtg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 06/10] nodedev: Build a non-loadable driver lib Date: Tue, 9 Jun 2020 16:43:46 -0500 Message-Id: <20200609214350.14156-7-jjongsma@redhat.com> In-Reply-To: <20200609214350.14156-1-jjongsma@redhat.com> References: <20200609214350.14156-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.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" In order to test the nodedev driver, we need to link against a non-loadable module. Similar to other loadable modules already in the repository, create an _impl library that can be linked against the unit tests and then create a loadable module from that. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety Reviewed-by: Michal Privoznik --- src/node_device/Makefile.inc.am | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/node_device/Makefile.inc.am b/src/node_device/Makefile.inc= .am index 788563665f..5993165b56 100644 --- a/src/node_device/Makefile.inc.am +++ b/src/node_device/Makefile.inc.am @@ -34,34 +34,37 @@ EXTRA_DIST +=3D \ =20 if WITH_NODE_DEVICES # Needed to keep automake quiet about conditionals +noinst_LTLIBRARIES +=3D libvirt_driver_nodedev_impl.la +libvirt_driver_nodedev_la_SOURCES =3D +libvirt_driver_nodedev_la_LIBADD =3D libvirt_driver_nodedev_impl.la mod_LTLIBRARIES +=3D libvirt_driver_nodedev.la -libvirt_driver_nodedev_la_SOURCES =3D $(NODE_DEVICE_DRIVER_SOURCES) +libvirt_driver_nodedev_impl_la_SOURCES =3D $(NODE_DEVICE_DRIVER_SOURCES) =20 -libvirt_driver_nodedev_la_CFLAGS =3D \ +libvirt_driver_nodedev_impl_la_CFLAGS =3D \ -I$(srcdir)/access \ -I$(builddir)/access \ -I$(srcdir)/conf \ $(AM_CFLAGS) \ $(LIBNL_CFLAGS) \ $(NULL) -libvirt_driver_nodedev_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) -libvirt_driver_nodedev_la_LIBADD =3D \ +libvirt_driver_nodedev_impl_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) +libvirt_driver_nodedev_impl_la_LIBADD =3D \ libvirt.la \ $(GLIB_LIBS) \ $(NULL) =20 if WITH_HAL -libvirt_driver_nodedev_la_SOURCES +=3D $(NODE_DEVICE_DRIVER_HAL_SOURCES) -libvirt_driver_nodedev_la_CFLAGS +=3D $(HAL_CFLAGS) -libvirt_driver_nodedev_la_LIBADD +=3D $(HAL_LIBS) +libvirt_driver_nodedev_impl_la_SOURCES +=3D $(NODE_DEVICE_DRIVER_HAL_SOURC= ES) +libvirt_driver_nodedev_impl_la_CFLAGS +=3D $(HAL_CFLAGS) +libvirt_driver_nodedev_impl_la_LIBADD +=3D $(HAL_LIBS) endif WITH_HAL if WITH_UDEV -libvirt_driver_nodedev_la_SOURCES +=3D $(NODE_DEVICE_DRIVER_UDEV_SOURCES) -libvirt_driver_nodedev_la_CFLAGS +=3D \ +libvirt_driver_nodedev_impl_la_SOURCES +=3D $(NODE_DEVICE_DRIVER_UDEV_SOUR= CES) +libvirt_driver_nodedev_impl_la_CFLAGS +=3D \ $(UDEV_CFLAGS) \ $(PCIACCESS_CFLAGS) \ $(NULL) -libvirt_driver_nodedev_la_LIBADD +=3D \ +libvirt_driver_nodedev_impl_la_LIBADD +=3D \ $(UDEV_LIBS) \ $(PCIACCESS_LIBS) \ $(NULL) --=20 2.21.3 From nobody Wed May 1 06:22:20 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=1591739069; cv=none; d=zohomail.com; s=zohoarc; b=GtcaCjN3JfsHpMu0iET7ZYA3rl6IGXJLt1lulB1FzbsfLvv3/o45QBCi5RYv0J1RWgbyGuMNodcGsvq19wbyrIvBQCIKYNlyHKq8i0embZDX44YxlGks9xAlP9h3+jI+Hiv/5iQkQZSH1BVWKjeid/VvJKJwsFg0Atfe2xLtfd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591739069; 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=Lz7vjrZ62cYoqobKLDLBF7MREsgF5eBNQ9U+T94FPZk=; b=QI+1yokI61kV2QIjXUxAMi1EUs8LraDgvj8/KQIY1MzVq+FDRk6vLHrp0Ax6FoWHL7uZu2FwTlCzDd2OQHGLlGO5KzFl9dTKvkldHiQ3/0OKBKVk4UnKbCTq0ID7o3wz8dHed0Jm7sQvabm6QCUc/KInLJyngSWrMDHyNX+AsH4= 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 1591739069167995.9277154975298; Tue, 9 Jun 2020 14:44:29 -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-398-zGDFktqcO-Wb_eRXQe6a3g-1; Tue, 09 Jun 2020 17:44:23 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 76ABD107ACF7; Tue, 9 Jun 2020 21:44:18 +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 5863A7F0BE; Tue, 9 Jun 2020 21:44:18 +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 2A6C0B34A2; Tue, 9 Jun 2020 21:44:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059Lhtsx030112 for ; Tue, 9 Jun 2020 17:43:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id DC7207BFE9; Tue, 9 Jun 2020 21:43:55 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-112.phx2.redhat.com [10.3.115.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFF917BFE3 for ; Tue, 9 Jun 2020 21:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591739066; 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=Lz7vjrZ62cYoqobKLDLBF7MREsgF5eBNQ9U+T94FPZk=; b=bBq3FI9A3lq8RQsqhuQ0jBszLaynH5uTAD4sTNr9hFl73Mbxb+tPVLUXXjY9qCjCQfR4Sr ql9b2VhQs0/Gd+xT2edA6LEJl0/xhylIRde3DPIGUd3/kWdFemIJN/HHAy1PcKxVtg5rI8 jg+EWZpLUOfMmJ4TsmmLeQbaoZWBUeM= X-MC-Unique: zGDFktqcO-Wb_eRXQe6a3g-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 07/10] nodedev: Add testing for 'mdevctl start' Date: Tue, 9 Jun 2020 16:43:47 -0500 Message-Id: <20200609214350.14156-8-jjongsma@redhat.com> In-Reply-To: <20200609214350.14156-1-jjongsma@redhat.com> References: <20200609214350.14156-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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" Test that we run 'mdevctl' with the proper arguments when creating new mediated devices with virNodeDeviceCreateXML(). Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety Reviewed-by: Michal Privoznik --- build-aux/syntax-check.mk | 2 +- tests/Makefile.am | 14 + ...019_36ea_4111_8f0a_8c9a70e21366-start.argv | 1 + ...019_36ea_4111_8f0a_8c9a70e21366-start.json | 1 + ...d39_495e_4243_ad9f_beb3f14c23d9-start.argv | 1 + ...d39_495e_4243_ad9f_beb3f14c23d9-start.json | 1 + ...916_1ca8_49ac_b176_871d16c13076-start.argv | 1 + ...916_1ca8_49ac_b176_871d16c13076-start.json | 1 + tests/nodedevmdevctltest.c | 257 ++++++++++++++++++ ...v_d069d019_36ea_4111_8f0a_8c9a70e21366.xml | 8 + ...v_d2441d39_495e_4243_ad9f_beb3f14c23d9.xml | 10 + ...v_fedc4916_1ca8_49ac_b176_871d16c13076.xml | 9 + 12 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8= c9a70e21366-start.argv create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8= c9a70e21366-start.json create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_b= eb3f14c23d9-start.argv create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_b= eb3f14c23d9-start.json create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_8= 71d16c13076-start.argv create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_8= 71d16c13076-start.json create mode 100644 tests/nodedevmdevctltest.c create mode 100644 tests/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c= 9a70e21366.xml create mode 100644 tests/nodedevschemadata/mdev_d2441d39_495e_4243_ad9f_be= b3f14c23d9.xml create mode 100644 tests/nodedevschemadata/mdev_fedc4916_1ca8_49ac_b176_87= 1d16c13076.xml diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index bf8832a2a5..d47a92b530 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -2015,7 +2015,7 @@ exclude_file_name_regexp--sc_prohibit_close =3D \ (\.p[yl]$$|\.spec\.in$$|^docs/|^(src/util/vir(file|event)\.c|src/libvirt= -stream\.c|tests/(vir.+mock\.c|commandhelper\.c|qemusecuritymock\.c)|tools/= nss/libvirt_nss_(leases|macs)\.c)$$) =20 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF =3D \ - (^tests/(virhostcpu|virpcitest)data/|docs/js/.*\.js|docs/fonts/.*\.woff|= \.diff|tests/virconfdata/no-newline\.conf$$) + (^tests/(nodedevmdevctl|virhostcpu|virpcitest)data/|docs/js/.*\.js|docs/= fonts/.*\.woff|\.diff|tests/virconfdata/no-newline\.conf$$) =20 exclude_file_name_regexp--sc_prohibit_fork_wrappers =3D \ (^(src/(util/(vircommand|virdaemon)|lxc/lxc_controller)|tests/testutils)= \.c$$) diff --git a/tests/Makefile.am b/tests/Makefile.am index f5766a7790..13cbdbb31e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -388,6 +388,10 @@ test_programs +=3D storagevolxml2xmltest =20 test_programs +=3D nodedevxml2xmltest =20 +if WITH_NODE_DEVICES +test_programs +=3D nodedevmdevctltest +endif WITH_NODE_DEVICES + test_programs +=3D interfacexml2xmltest =20 test_programs +=3D cputest @@ -970,6 +974,16 @@ nodedevxml2xmltest_SOURCES =3D \ testutils.c testutils.h nodedevxml2xmltest_LDADD =3D $(LDADDS) =20 +if WITH_NODE_DEVICES +nodedevmdevctltest_SOURCES =3D \ + nodedevmdevctltest.c \ + testutils.c testutils.h + +nodedevmdevctltest_LDADD =3D \ + ../src/libvirt_driver_nodedev_impl.la \ + $(LDADDS) +endif WITH_NODE_DEVICES + interfacexml2xmltest_SOURCES =3D \ interfacexml2xmltest.c \ testutils.c testutils.h diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2= 1366-start.argv b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9= a70e21366-start.argv new file mode 100644 index 0000000000..dae6dedf7f --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-st= art.argv @@ -0,0 +1 @@ +/usr/sbin/mdevctl start -p 0000:00:02.0 --jsonfile /dev/stdin diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2= 1366-start.json b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9= a70e21366-start.json new file mode 100644 index 0000000000..bfc6dcace3 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-st= art.json @@ -0,0 +1 @@ +{"mdev_type":"i915-GVTg_V5_8","start":"manual"} \ No newline at end of file diff --git a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c= 23d9-start.argv b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb= 3f14c23d9-start.argv new file mode 100644 index 0000000000..dae6dedf7f --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-st= art.argv @@ -0,0 +1 @@ +/usr/sbin/mdevctl start -p 0000:00:02.0 --jsonfile /dev/stdin diff --git a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c= 23d9-start.json b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb= 3f14c23d9-start.json new file mode 100644 index 0000000000..e5b22b2c44 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-st= art.json @@ -0,0 +1 @@ +{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribut= e-1":"attribute-value-1"},{"example-attribute-2":"attribute-value-2"}]} \ No newline at end of file diff --git a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c1= 3076-start.argv b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871= d16c13076-start.argv new file mode 100644 index 0000000000..dae6dedf7f --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-st= art.argv @@ -0,0 +1 @@ +/usr/sbin/mdevctl start -p 0000:00:02.0 --jsonfile /dev/stdin diff --git a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c1= 3076-start.json b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871= d16c13076-start.json new file mode 100644 index 0000000000..2e03d0bd8e --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-st= art.json @@ -0,0 +1 @@ +{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribut= e":"attribute-value"}]} \ No newline at end of file diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c new file mode 100644 index 0000000000..32a22246c2 --- /dev/null +++ b/tests/nodedevmdevctltest.c @@ -0,0 +1,257 @@ +#include + +#include "internal.h" +#include "testutils.h" +#include "datatypes.h" +#include "node_device/node_device_driver.h" +#include "vircommand.h" +#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW +#include "vircommandpriv.h" + +#define VIR_FROM_THIS VIR_FROM_NODEDEV + +struct testInfo { + bool shouldFail; + const char *virt_type; + int create; + const char *filename; +}; + +// capture stdin passed to command +static void +testCommandDryRunCallback(const char *const*args G_GNUC_UNUSED, + const char *const*env G_GNUC_UNUSED, + const char *input, + char **output G_GNUC_UNUSED, + char **error G_GNUC_UNUSED, + int *status G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + char **stdinbuf =3D opaque; + + *stdinbuf =3D g_strdup(input); +} + +static int +testMdevctlStart(bool shouldFail G_GNUC_UNUSED, + const char *virt_type, + int create, + const char *mdevxml, + const char *startcmdfile, + const char *startjsonfile) +{ + virNodeDeviceDefPtr def =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + const char *actualCmdline =3D NULL; + int ret =3D -1; + g_autofree char *uuid =3D NULL; + g_autofree char *stdinbuf =3D NULL; + g_autoptr(virCommand) cmd =3D NULL; + + if (!(def =3D virNodeDeviceDefParseFile(mdevxml, create, virt_type))) + goto cleanup; + + // this function will set a stdin buffer containing the json configura= tion + // of the device. This json value is captured in the mock wrapper above + cmd =3D nodeDeviceGetMdevctlStartCommand(def, false, &uuid); + + if (!cmd) + goto cleanup; + + virCommandSetDryRun(&buf, testCommandDryRunCallback, &stdinbuf); + if (virCommandRun(cmd, NULL) < 0) + goto cleanup; + + if (!(actualCmdline =3D virBufferCurrentContent(&buf))) + goto cleanup; + + if (virTestCompareToFile(actualCmdline, startcmdfile) < 0) + goto cleanup; + + if (virTestCompareToFile(stdinbuf, startjsonfile) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&buf); + virCommandSetDryRun(NULL, NULL, NULL); + virNodeDeviceObjEndAPI(&obj); + return ret; +} + +static int +testMdevctlStartHelper(const void *data) +{ + const struct testInfo *info =3D data; + + g_autofree char *mdevxml =3D g_strdup_printf("%s/nodedevschemadata/%s.= xml", + abs_srcdir, info->filename); + g_autofree char *cmdlinefile =3D g_strdup_printf("%s/nodedevmdevctldat= a/%s-start.argv", + abs_srcdir, info->filen= ame); + g_autofree char *jsonfile =3D g_strdup_printf("%s/nodedevmdevctldata/%= s-start.json", + abs_srcdir, info->filen= ame); + + return testMdevctlStart(info->shouldFail, info->virt_type, + info->create, mdevxml, cmdlinefile, + jsonfile); +} + +static void +nodedevTestDriverFree(virNodeDeviceDriverStatePtr drv) +{ + if (!drv) + return; + + virCondDestroy(&drv->initCond); + virMutexDestroy(&drv->lock); + VIR_FREE(drv->stateDir); + VIR_FREE(drv); +} + +/* Add a fake root 'computer' device */ +static virNodeDeviceDefPtr +fakeRootDevice(void) +{ + virNodeDeviceDefPtr def =3D NULL; + + if (VIR_ALLOC(def) !=3D 0 || VIR_ALLOC(def->caps) !=3D 0) { + virNodeDeviceDefFree(def); + return NULL; + } + + def->name =3D g_strdup("computer"); + + return def; +} + +/* Add a fake pci device that can be used as a parent device for mediated + * devices. For our purposes, it only needs to have a name that matches the + * parent of the mdev, and it needs a PCI address + */ +static virNodeDeviceDefPtr +fakeParentDevice(void) +{ + virNodeDeviceDefPtr def =3D NULL; + virNodeDevCapPCIDevPtr pci_dev; + + if (VIR_ALLOC(def) !=3D 0 || VIR_ALLOC(def->caps) !=3D 0) { + virNodeDeviceDefFree(def); + return NULL; + } + + def->name =3D g_strdup("pci_0000_00_02_0"); + def->parent =3D g_strdup("computer"); + + def->caps->data.type =3D VIR_NODE_DEV_CAP_PCI_DEV; + pci_dev =3D &def->caps->data.pci_dev; + pci_dev->domain =3D 0; + pci_dev->bus =3D 0; + pci_dev->slot =3D 2; + pci_dev->function =3D 0; + + return def; +} + +static int +addDevice(virNodeDeviceDefPtr def) +{ + if (!def) + return -1; + + virNodeDeviceObjPtr obj =3D virNodeDeviceObjListAssignDef(driver->devs= , def); + + if (!obj) { + virNodeDeviceDefFree(def); + return -1; + } + + virNodeDeviceObjEndAPI(&obj); + return 0; +} + +static int +nodedevTestDriverAddTestDevices(void) +{ + if (addDevice(fakeRootDevice()) < 0 || + addDevice(fakeParentDevice()) < 0) + return -1; + + return 0; +} + +/* Bare minimum driver init to be able to test nodedev functionality */ +static int +nodedevTestDriverInit(void) +{ + int ret =3D -1; + char statedir[] =3D abs_builddir "/nodedevstatedir-XXXXXX"; + if (VIR_ALLOC(driver) < 0) + return -1; + + if (!g_mkdtemp(statedir)) { + fprintf(stderr, "Cannot create fake stateDir"); + goto error; + } + + driver->stateDir =3D g_strdup(statedir); + driver->lockFD =3D -1; + if (virMutexInit(&driver->lock) < 0 || + virCondInit(&driver->initCond) < 0) { + VIR_TEST_DEBUG("Unable to initialize test nodedev driver"); + goto error; + } + + if (!(driver->devs =3D virNodeDeviceObjListNew())) + goto error; + + return 0; + + error: + nodedevTestDriverFree(driver); + return ret; +} + +static int +mymain(void) +{ + int ret =3D 0; + + if (nodedevTestDriverInit() < 0) + return EXIT_FAILURE; + + if (nodedevTestDriverAddTestDevices() < 0) { + ret =3D EXIT_FAILURE; + goto done; + } + + // add a mock device to the device list so it can be used as a parent + // reference + +#define DO_TEST_FULL(shouldFail, virt_type, create, filename) \ + do { \ + struct testInfo info =3D { shouldFail, virt_type, create, filename= , }; \ + if (virTestRun("mdevctl start " filename, \ + testMdevctlStartHelper, &info) < 0) \ + ret =3D -1; \ + } \ + while (0); + +#define DO_TEST(...) \ + DO_TEST_FULL(false, "QEMU", CREATE_DEVICE, __VA_ARGS__) +#define DO_TEST_FAIL(...) \ + DO_TEST_FULL(true, "QEMU", CREATE_DEVICE, __VA_ARGS__) + + // Test mdevctl start commands + DO_TEST("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); + DO_TEST("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); + DO_TEST("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); + + done: + nodedevTestDriverFree(driver); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) diff --git a/tests/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21= 366.xml b/tests/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366= .xml new file mode 100644 index 0000000000..36d50630e4 --- /dev/null +++ b/tests/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366.xml @@ -0,0 +1,8 @@ + + mdev_d069d019_36ea_4111_8f0a_8c9a70e21366 + pci_0000_00_02_0 + + + + + diff --git a/tests/nodedevschemadata/mdev_d2441d39_495e_4243_ad9f_beb3f14c2= 3d9.xml b/tests/nodedevschemadata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9= .xml new file mode 100644 index 0000000000..1aa0afe085 --- /dev/null +++ b/tests/nodedevschemadata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9.xml @@ -0,0 +1,10 @@ + + mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9 + pci_0000_00_02_0 + + + + + + + diff --git a/tests/nodedevschemadata/mdev_fedc4916_1ca8_49ac_b176_871d16c13= 076.xml b/tests/nodedevschemadata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076= .xml new file mode 100644 index 0000000000..da2a702304 --- /dev/null +++ b/tests/nodedevschemadata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076.xml @@ -0,0 +1,9 @@ + + mdev_fedc4916_1ca8_49ac_b176_871d16c13076 + pci_0000_00_02_0 + + + + + + --=20 2.21.3 From nobody Wed May 1 06:22:20 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=1591739108; cv=none; d=zohomail.com; s=zohoarc; b=Vkc6v2CyoXHbjt9+ceOlXeAL07hoWXUHkyn8xpNps5KeuUPT64Rq3pYSBdX23CxBmDNS2lGs56qtYWogQv46TkipK+DYyLjMNGMhPf1mZOMl83blo+gybvGCL8E2Gh39TmRpz6NibOxs9HyySfVMJxi+5lFDauQxGQayLz0MqsU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591739108; 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=z4WhAHiq0JPKmAGtAgOfNnJ+MQ9PAfg3u4j7PifPvrM=; b=SW7oh6qS0hUMrOVDGuANeaeM/gtaDXPldGFH3mNFpcsXa1l8U6KLsFRbLGMbrwl7BbiQN0HYP78zMJDUmNHespW+4Pha3hChtTRGVtNX3b+soz62FzkCES+I3Tx49r5WiA9onycrGf5SqzPII9zdoyWLY7jqOR+sDVaUJiTuo5E= 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 1591739108244261.94602960024383; Tue, 9 Jun 2020 14:45:08 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-38-1aZ2Dn5QMFSoOqEaeklvYw-1; Tue, 09 Jun 2020 17:44:25 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A109010082F9; Tue, 9 Jun 2020 21:44:20 +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 80FE48929B; Tue, 9 Jun 2020 21:44:20 +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 53E94B34A9; Tue, 9 Jun 2020 21:44:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059LhuQH030117 for ; Tue, 9 Jun 2020 17:43:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 308BD7BFE9; Tue, 9 Jun 2020 21:43:56 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-112.phx2.redhat.com [10.3.115.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 03BC97BFE3 for ; Tue, 9 Jun 2020 21:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591739107; 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=z4WhAHiq0JPKmAGtAgOfNnJ+MQ9PAfg3u4j7PifPvrM=; b=WatOL8wm2iXuDOY3BVS3AR2f6bY6UxidTxqp0+TwV1bvOGq8iqkR3OgDVyIzjLI1k8i470 8HjePjh5rEdNuaDwYv4yrcEnFRlM4aBtk0MLOLgMBZtzpWWHdZnJMt4T9XorRFkyL8m3WV CkYhKndoqeNmvz6IfPCjlyHjMNixtCg= X-MC-Unique: 1aZ2Dn5QMFSoOqEaeklvYw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 08/10] nodedev: add mdev support to virNodeDeviceDestroy() Date: Tue, 9 Jun 2020 16:43:48 -0500 Message-Id: <20200609214350.14156-9-jjongsma@redhat.com> In-Reply-To: <20200609214350.14156-1-jjongsma@redhat.com> References: <20200609214350.14156-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 | 46 ++++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 3 ++ 2 files changed, 49 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index dbc7eb4d1e..c956bb55fc 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -790,6 +790,45 @@ nodeDeviceCreateXML(virConnectPtr conn, } =20 =20 +virCommandPtr +nodeDeviceGetMdevctlStopCommand(const char *uuid, + bool persist) +{ + g_autofree char *mdevctl =3D virFindFileInPath(MDEVCTL); + const char *subcommand; + + if (!mdevctl) + return NULL; + + if (persist) + subcommand =3D "undefine"; + else + subcommand =3D "stop"; + + virCommandPtr cmd =3D virCommandNewArgList(mdevctl, + subcommand, + "-u", + uuid, + NULL); + + return cmd; +} + +static int +virMdevctlStop(virNodeDeviceDefPtr def) +{ + int status; + g_autoptr(virCommand) cmd =3D NULL; + + cmd =3D nodeDeviceGetMdevctlStopCommand(def->caps->data.mdev.uuid, fal= se); + + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + return 0; +} + + int nodeDeviceDestroy(virNodeDevicePtr device) { @@ -836,6 +875,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) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to stop mediated device")); + goto cleanup; + } ret =3D 0; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 576f75375f..794cb5dc1c 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -122,3 +122,6 @@ virCommandPtr nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, bool persist, char **uuid_out); +virCommandPtr +nodeDeviceGetMdevctlStopCommand(const char *uuid, + bool persist); --=20 2.21.3 From nobody Wed May 1 06:22:20 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=1591739062; cv=none; d=zohomail.com; s=zohoarc; b=eju0b1FXseRYzvKJqX+QjWV2/ITOgAIi+XbOqTyeqo2reSeSaTwKKb5XUQWVoZGesgohzkd+RJYCdkgH0hPQiw/QvTuGAi8ZtRJWb8pNHT6tAiG4cnGyuYTefP8N/ejOSYUxUpB2VsEn7y1kFeLagQLyO8hX+Ao7Fdczgw4zA5I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591739062; 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=Lmo/CAPhHHPjnc9G2kGb/geS2zxx7eChy819ql1P6uM=; b=Pv74L+8VyNWyRJzX74O64mu0J0khDhxruuZVqXxvzmLLlGZUUOmujwiG2fPJoN8oXHVMA5zNVWF/yQGXvozGC9t9eOM1/VysdSHVV5Zm758unxUQ4fRRthgJgBaErzisGRLHk82gYWQVEOHDktr5Y5beWdmieqLkhliOeWK3vWk= 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 159173906279512.941167303785846; Tue, 9 Jun 2020 14:44:22 -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-44-BCS6Zk54MG6bWm4nl7t4Dw-1; Tue, 09 Jun 2020 17:44:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C02341005510; Tue, 9 Jun 2020 21:44:13 +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 9DED860BF3; Tue, 9 Jun 2020 21:44:13 +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 6F520B34A1; Tue, 9 Jun 2020 21:44:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059Lhu9x030122 for ; Tue, 9 Jun 2020 17:43:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 787697BFE9; Tue, 9 Jun 2020 21:43:56 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-112.phx2.redhat.com [10.3.115.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C3117BFE3 for ; Tue, 9 Jun 2020 21:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591739061; 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=Lmo/CAPhHHPjnc9G2kGb/geS2zxx7eChy819ql1P6uM=; b=OCeI/B8xJj8NEDZV4chmK9wJEKxXIrL1d7pyVsjsfnRqeakzgAfvD1GdkR6IGyaxcsSe5D mM317p1Zcmjggt8JAqouls5H/gPBs0H+0hVzICskps3yFw/10dnHgswqpUD9IP+fMUHvSR sX6moPKV3pYn0blimE9agNOOjLgjePE= X-MC-Unique: BCS6Zk54MG6bWm4nl7t4Dw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 09/10] nodedev: Add testing for 'mdevctl stop' Date: Tue, 9 Jun 2020 16:43:49 -0500 Message-Id: <20200609214350.14156-10-jjongsma@redhat.com> In-Reply-To: <20200609214350.14156-1-jjongsma@redhat.com> References: <20200609214350.14156-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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" Test that we run 'mdevctl' with the proper arguments when we destroy mediated devices with virNodeDeviceDestroy() Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- tests/nodedevmdevctldata/mdevctl-stop.argv | 1 + tests/nodedevmdevctltest.c | 43 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/nodedevmdevctldata/mdevctl-stop.argv diff --git a/tests/nodedevmdevctldata/mdevctl-stop.argv b/tests/nodedevmdev= ctldata/mdevctl-stop.argv new file mode 100644 index 0000000000..25ee7145ce --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-stop.argv @@ -0,0 +1 @@ +/usr/sbin/mdevctl stop -u e2451f73-c95b-4124-b900-e008af37c576 diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 32a22246c2..58ebf976e2 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -98,6 +98,42 @@ testMdevctlStartHelper(const void *data) jsonfile); } =20 +static int +testMdevctlStopHelper(const void *data) +{ + const char *uuid =3D data; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + const char *actualCmdline =3D NULL; + int ret =3D -1; + g_autoptr(virCommand) cmd =3D NULL; + + g_autofree char *cmdlinefile =3D + g_strdup_printf("%s/nodedevmdevctldata/mdevctl-stop.argv", + abs_srcdir); + + cmd =3D nodeDeviceGetMdevctlStopCommand(uuid, false); + + if (!cmd) + goto cleanup; + + virCommandSetDryRun(&buf, NULL, NULL); + if (virCommandRun(cmd, NULL) < 0) + goto cleanup; + + if (!(actualCmdline =3D virBufferCurrentContent(&buf))) + goto cleanup; + + if (virTestCompareToFile(actualCmdline, cmdlinefile) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&buf); + virCommandSetDryRun(NULL, NULL, NULL); + return ret; +} + static void nodedevTestDriverFree(virNodeDeviceDriverStatePtr drv) { @@ -248,6 +284,13 @@ mymain(void) DO_TEST("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); DO_TEST("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); =20 + // Test mdevctl stop command, pass an arbitrary uuid + if (virTestRun("mdevctl stop", testMdevctlStopHelper, + "e2451f73-c95b-4124-b900-e008af37c576") < 0) + + + ret =3D -1; + done: nodedevTestDriverFree(driver); =20 --=20 2.21.3 From nobody Wed May 1 06:22:20 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=1591739095; cv=none; d=zohomail.com; s=zohoarc; b=Jsj+ajv77q00ZMQ8XAtf8O6TjD60Cj6Q7OnnOhA4Luqo+20DHP+PImnKOljT6bHEtbUOyHDIjtYjkOl25vSCGnI9GbgQgJNVtiOcRTFPhECWxOTiEgN9xVfJzjz3jDUh2hq1p3kIvbNrI1kxP9GnPLDT1ocBwzWMl8SEbE1SWHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591739095; 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=eZ1WJT7aT7krd2ROnE8JTss7cmDyffFfms1ytEtP2S8=; b=W4L0Wn3/SSA7db9CGbUAdmttD87XAxtFQjDEU/+eFhZwVnyfWzljbbzXALcmY8nxdPnEtxZZMe6rQI8euSJ0GKbbqBU3htjtOln0w9PwD8djlfteiOBCoB9GocghiSeX+YFJAPeAddvHCg/4TVzL+T53Upo9b8RZG+0SAYwYSaA= 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 1591739095474903.6530923687292; Tue, 9 Jun 2020 14:44:55 -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-110-xppZruRWPM6J-y_kz5SnSg-1; Tue, 09 Jun 2020 17:44:51 -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 581B18015CB; Tue, 9 Jun 2020 21:44:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 37B995DA73; Tue, 9 Jun 2020 21:44:46 +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 05072B34B5; Tue, 9 Jun 2020 21:44:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059LhuTk030127 for ; Tue, 9 Jun 2020 17:43:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id C09EF7BFE3; Tue, 9 Jun 2020 21:43:56 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-112.phx2.redhat.com [10.3.115.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 93C697C002 for ; Tue, 9 Jun 2020 21:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591739094; 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=eZ1WJT7aT7krd2ROnE8JTss7cmDyffFfms1ytEtP2S8=; b=h8FJrxGhyz9oB1G1d0pac5mKI6jZuU90fhBgwPZW+i/+33na3HYxb+S8TNVhcjk+VV0M4u tnQB+fQCHYj+mLzRqs1zLKPzJNxck1yqjYwmlAK+1jcwGUZ9WFSsRlqXQLO4uSA86CeCyZ fnFvNrkSOHcnLo31f2bVtYHNje2wFbg= X-MC-Unique: xppZruRWPM6J-y_kz5SnSg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 10/10] docs: note node device fields that are read-only Date: Tue, 9 Jun 2020 16:43:50 -0500 Message-Id: <20200609214350.14156-11-jjongsma@redhat.com> In-Reply-To: <20200609214350.14156-1-jjongsma@redhat.com> References: <20200609214350.14156-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.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" As noted by Erik Skultety, we use the same XML schema to report existing devices and to define new devices. However, some schema elements are "read-only". In other words, they are used to report information from the node device driver and cannot be used to define a new device. Note these in the documentation. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety Reviewed-by: Michal Privoznik --- docs/formatnode.html.in | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index a46b73254b..651411502c 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -31,11 +31,16 @@ name is just the bus type and address, as in "pci_0000_00_02_1" or "usb_1_5_3", but some devices are able to provide more specific names, such as - "net_eth1_00_27_13_6a_fe_00". + "net_eth1_00_27_13_6a_fe_00". This is a read-only field that is + reported by the device driver. If this element is set when definin= g a + new device, it will be ignored. +
path
- Fully qualified sysfs path to the device. + Fully qualified sysfs path to the device. This is a read-only field + that is reported by the device driver. If this element is set when + defining a new device, it will be ignored.
parent
--=20 2.21.3