From nobody Tue May 7 14:39:51 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=1592317695; cv=none; d=zohomail.com; s=zohoarc; b=U0ACa6f85NYiLLV7zh2VhoJnzS4jkVEMsZHi2wBtlvaH8zejtnNnqW8Q1K1B0kcfHonZmDPnP2vnU3Z22K8H+ENoNUY/wo0kphxy51Yd2Jbe4PaNh6d5UR5IUsOvvEujHnF8FWI7eCs7HQZHLq+iiWQoQ/zkE+nUeOuTuzo0mHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317695; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HKEoo7N2XG0D8GMcgOHEjlQCJ1m/A3fkt33Xw53Q3aw=; b=g9aggWQRpy0b4fXY6RxqURVqw7tnea5vuyATKrfUD/JsZhJR6u+2VTArB5gFgBq0NZL1occYpOjs/tQq+QVPHSHLb+Hlid6P24pjiNXcIEYFKYQNUeyZ/T/RaWd7KsQItbvfTn9Zki8+TFKAPoG/LIwoVjL9Ml63IbTOuzipo5M= 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 1592317695865567.145547639129; Tue, 16 Jun 2020 07:28:15 -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-104-VfTYG1E6NS6xAtUBCkxHZA-1; Tue, 16 Jun 2020 10:28:12 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C36F9106B252; Tue, 16 Jun 2020 14:28:06 +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 4FC2A19C71; Tue, 16 Jun 2020 14:28:06 +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 C5A231809547; Tue, 16 Jun 2020 14:28:04 +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 05GES3H8020322 for ; Tue, 16 Jun 2020 10:28:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id B24297BA14; Tue, 16 Jun 2020 14:28:03 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 674F47890A; Tue, 16 Jun 2020 14:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317694; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HKEoo7N2XG0D8GMcgOHEjlQCJ1m/A3fkt33Xw53Q3aw=; b=WNzG/y6fI61KFhc2t7cidcPL0HVPCfYyFkl4cTTIsJe7est8E2KsPwra30g1lW1gdN6kT7 /M4sAsPWjxXMDjodIlRN8s9yZA34IGF9ncFbrgrRoS9a0MkxIzs7/Onaivky76WiCE93QG waBcBOuGwAL890gV3DegLf8k8vpP0iU= X-MC-Unique: VfTYG1E6NS6xAtUBCkxHZA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 01/11] nodedev: make iommuGroup optional for mdevs Date: Tue, 16 Jun 2020 09:27:49 -0500 Message-Id: <20200616142759.4625-2-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When parsing a nodedev xml file, the iommuGroup element should be optional. This element should be read-only and is determined by the device driver. While this is a change to existing behavior, it doesn't break backwards-compatibility because it makes the parser less strict. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety Reviewed-by: Michal Privoznik --- docs/formatnode.html.in | 5 +++-- docs/schemas/nodedev.rng | 12 +++++++----- src/conf/node_device_conf.c | 12 ++++++------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index 76eae928de..4ed43ec0cb 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -390,8 +390,9 @@
iommuGroup
This element supports a single attribute number - which holds the IOMMU group number the mediated device bel= ongs - to. + which holds the IOMMU group number to which the mediated d= evice + belongs. This is a read-only field that is reported by the + device driver.
diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index fe6ffa0b53..ca3a79db87 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -629,11 +629,13 @@ - - - - - + + + + + + + =20 diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bccdbd0af8..4b3b04b7b8 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1775,13 +1775,13 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, goto out; } =20 - if (virNodeDevCapsDefParseULong("number(./iommuGroup[1]/@number)", ctx= t, - &mdev->iommuGroupNumber, def, - _("missing iommuGroup number attribute= for " - "'%s'"), - _("invalid iommuGroup number attribute= for " - "'%s'")) < 0) + /* 'iommuGroup' is optional, only report an error if the supplied valu= e is + * invalid (-2), not if it's missing (-1) */ + if (virXPathUInt("number(./iommuGroup[1]/@number)", ctxt, &mdev->iommu= GroupNumber) < -1) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid iommuGroup number attribute for '%s'"), = def->name); goto out; + } =20 ret =3D 0; out: --=20 2.21.3 From nobody Tue May 7 14:39:51 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=1592317708; cv=none; d=zohomail.com; s=zohoarc; b=io9MKfpHMzTft4l+E9KWYy71H5tkxWJlCJyYOcrxf5BJBOhEgaPmOuHvem/p/ynOpc3/9MDVL2k7LPOL5aGoAR1ijuuTFbGKYd4+tMHV3K97Ob2Jcoq4O3hBxk0iDxrChpxqQGHQqYVeMuSslbTg+XahinBeLJkNedd6nRD3Hr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317708; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N3hTaVGVwHUqmVte6DOVoXYX5lLb6NrzDQlJ+l2SDvM=; b=gqPvjJJtpvskdkfzD9GYIj71iqcq06I/MuJUdoGaOCth25RslYJf1kH+2koef4dmzqOZShlN54eWjrQ2PUVsFzGOFuB/pSJ6CYxPMJGJZd/HkWgCWSLz6yS9M/ww3kCjsHdLxFrXpmr/Zv/+FFsH3CQ30MliXgJcEYD+oB2zPLo= 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 159231770829279.468993397595; Tue, 16 Jun 2020 07:28:28 -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-31-uSKIbPRzN9SXAUJBCZYGtg-1; Tue, 16 Jun 2020 10:28:24 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7AF1918585D3; Tue, 16 Jun 2020 14:28:17 +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 5267919C71; Tue, 16 Jun 2020 14:28:17 +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 BBF351800456; Tue, 16 Jun 2020 14:28:16 +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 05GES4so020327 for ; Tue, 16 Jun 2020 10:28:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 23EDF7890A; Tue, 16 Jun 2020 14:28:04 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD7BB78F0F; Tue, 16 Jun 2020 14:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317707; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=N3hTaVGVwHUqmVte6DOVoXYX5lLb6NrzDQlJ+l2SDvM=; b=VBU4eHTAG+SihFQnKnYvEsZHfKzcJpMbKPEUc675ETQkt3tMa2YPS2mZTYJ7M5WUWuBOzq W5E+VU+7rUi/HZFtqkVKkJ2T6MvQt08WsN9EFMN4hjlE+pcnJSL6wYp/UbEVdzhoMjkzu8 HfE9+4FvAihLx0rlDz8VLQPspIgshT0= X-MC-Unique: uSKIbPRzN9SXAUJBCZYGtg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 02/11] nodedev: factor out nodeDeviceHasCapability() Date: Tue, 16 Jun 2020 09:27:50 -0500 Message-Id: <20200616142759.4625-3-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Tue May 7 14:39:51 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=1592317696; cv=none; d=zohomail.com; s=zohoarc; b=OMxcfabWIhsGkPc7yIy6zsAPBGNa4fipWKxIGmiXtwyAqnyWv3Dl5ZBdKqTUFAPM8MwxNr3rBIgO4zIUO9VvUTNJEDk/PG6pnOptEnUtm21CTLIrVYmzrmZNHXtUORMmNrV3SWxqRd1yBliJAC9fkxLZaF+YTcvn2jMBP9njbp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317696; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HQoTl+MtAjR/0BC1GX6vKPRDvYNtU7vEKq65RioJVa0=; b=NBc1hv6jbS7BV9mBTIjjIueFAFIKN19LQNbjXDLsr/Fxe9WY4X6B12zSeDmjgd7wYnmN7xCw7jYPJpyuHpZ5Kra04/jracmFvpP3Tl1zYD7KIJ822yqvM6W2Z0UvfPKIVIWP7bOrKjlLswiWdJ0zbskRf26Rltew7TC15biJ8rM= 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 1592317696481109.16991116913584; Tue, 16 Jun 2020 07:28:16 -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-328-F6YJd1tyMJ69hybPGs6hxw-1; Tue, 16 Jun 2020 10:28:13 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CE59118585C7; Tue, 16 Jun 2020 14:28:07 +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 ABD151002393; Tue, 16 Jun 2020 14:28:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7EF40833BD; Tue, 16 Jun 2020 14:28:07 +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 05GES4f5020332 for ; Tue, 16 Jun 2020 10:28:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8ABA678F0F; Tue, 16 Jun 2020 14:28:04 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FECD7890A; Tue, 16 Jun 2020 14:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317695; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HQoTl+MtAjR/0BC1GX6vKPRDvYNtU7vEKq65RioJVa0=; b=DIDdqz3chsMCOMXaH06Zjo/spLLkjiX5ihynR6yQtsn79OYJj+vl5tLeUU+isSuinX7TCh FvspAWVEGYhy1j/BpZ6WBpmgGZhfsViuaqthDzTppFboveN8v8anwb+TBEzn3GDzs6HUaH EDdTer9S4pDet4OeLGFi6lel5DaxuCo= X-MC-Unique: F6YJd1tyMJ69hybPGs6hxw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 03/11] nodedev: add support for mdev attributes Date: Tue, 16 Jun 2020 09:27:51 -0500 Message-Id: <20200616142759.4625-4-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 | 51 ++++++++++++++++++++++++++++++++++--- 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, 88 insertions(+), 3 deletions(-) diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index 4ed43ec0cb..0637d457ee 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -394,6 +394,13 @@ belongs. This is a read-only field that is reported by the device driver. +
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 ca3a79db87..4b2b350fd8 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -636,6 +636,12 @@ + + + + + +
=20 diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 4b3b04b7b8..b1dfe81653 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,27 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, return ret; } =20 +static int +virNodeDevCapMdevAttributeParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr node, + virNodeDevCapMdevPtr mdev) +{ + VIR_XPATH_NODE_AUTORESTORE(ctxt); + g_autoptr(virMediatedDeviceAttr) attr =3D virMediatedDeviceAttrNew(); + + ctxt->node =3D node; + 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")); + return -1; + } + + return VIR_APPEND_ELEMENT(mdev->attributes, + mdev->nattributes, + attr); +} =20 static int virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, @@ -1766,6 +1800,9 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, { VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; + int nattrs =3D 0; + g_autofree xmlNodePtr *attrs =3D NULL; + size_t i; =20 ctxt->node =3D node; =20 @@ -1783,6 +1820,11 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, 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 +2214,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 fc7406f2b7..97d790aced 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2487,6 +2487,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 Tue May 7 14:39:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1592317706; cv=none; d=zohomail.com; s=zohoarc; b=efvt2rehe2j1sn4t8jJ2pbzLP1IhGUZ+HKabBGrFhkVqDm/1zlVfDW6TPE1i2OlbI2AKMpZIzqOIHbT8Oy2AzdDpouVNKqDSR6sRpSujhuDhCuEGW5tLrhd/m3PmDM1I5ldRfrRN/9V9M6r//sLWejasa7YNv8XlK1Qq0qTgsZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317706; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5lGC7CPzBqUeau0wkem9GXtfUh47cOpncobTRU/QsZg=; b=ilrZGL/JSbK5M3cOZfnwP2QsWZ8PehR85jxSd4w0/8utMZ7drcm0qWNjvjIIQ/xZtjV7oMrmmvvZBHAtOXiBsWfVcxkWLm1+SAZ3tco07Q5MeyQ6M3AFJT0C0xh0MyDnbLF+U3vFVkRpZXyPvs6/AhvS10uuxUiVgBM0iv/2AMk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1592317706161877.0764338373276; Tue, 16 Jun 2020 07:28:26 -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-439-dBV3hGlYP46QBwI6hTroug-1; Tue, 16 Jun 2020 10:28:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F51018585D2; Tue, 16 Jun 2020 14:28:17 +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 3B3B31002394; Tue, 16 Jun 2020 14:28:17 +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 BDB5B833CA; Tue, 16 Jun 2020 14:28:16 +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 05GES5QN020337 for ; Tue, 16 Jun 2020 10:28:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id F39DB7A029; Tue, 16 Jun 2020 14:28:04 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A67007890A; Tue, 16 Jun 2020 14:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317704; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5lGC7CPzBqUeau0wkem9GXtfUh47cOpncobTRU/QsZg=; b=TUlWSp2JH6l3sKJye4b9VEN8cEGhFOG0yDaRaiqQR7cGbyG3DlvH2TnSNaJ8GpepdEVW3p DhaL4pza6soKPqIddCBcjjShgIdo9FVmTpMVfB5nt/MH6cGf3D0P4S71uQUFgdu7NCHCsh rjjo68xR9xvDo4uZUNll4lolirVl4lw= X-MC-Unique: dBV3hGlYP46QBwI6hTroug-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 04/11] nodedev: refactor nodeDeviceFindNewDevice() Date: Tue, 16 Jun 2020 09:27:52 -0500 Message-Id: <20200616142759.4625-5-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 Tue May 7 14:39:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1592317811; cv=none; d=zohomail.com; s=zohoarc; b=g8wFCdaVMr2zhVb5pPdVEZbQN1+HHPjmql2MMG+bpx8OWmU8OgdEEkhp9xsFW53F663tEcmRC9Ah3xUvYeJaLI4IA1nfzCpTpR0nnZGIzMtvhmhwkYaxSaDSuWsbrBTCHAFTVDeeOGetvxzRGIViFtc8Pix1NKV/gyRNaRhCN3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317811; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ii+olbe2Uy4miVLjoo4ZwYcv5CUj4ARLvGz4FjcW1is=; b=SBfgaKqmsjR+LuxmJ5PzxVeQm6lxwpo13yoahZ572gNcUAWB6oW0nLu+mpVISQ6zLLVC8o69VuQtpeABak62hNdXtYc5DQR1q+hl3gW1CUWoc9CYCCYH/cR5651e4SyhqgoYsUEK3/oMgZg/nJ/neBnzmhJ98l1vj0DZzn4vWn0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1592317811383576.6184229767024; Tue, 16 Jun 2020 07:30:11 -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--P8900ISNRCy1ePFg2TxUQ-1; Tue, 16 Jun 2020 10:28:27 -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 610898B62F0; Tue, 16 Jun 2020 14:28:20 +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 40B2A707C6; Tue, 16 Jun 2020 14:28: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 09E73180599D; Tue, 16 Jun 2020 14:28: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 05GES5Fc020346 for ; Tue, 16 Jun 2020 10:28:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id A355178F0F; Tue, 16 Jun 2020 14:28:05 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 58AB37890A; Tue, 16 Jun 2020 14:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317809; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ii+olbe2Uy4miVLjoo4ZwYcv5CUj4ARLvGz4FjcW1is=; b=Ky6JjJveEGvgMmNVEw9UCO+r+gHNr4jCSnyh/3FGt467poc8PMx+sosp0QesyGmlReLcy2 RgcCYcF3PLo/kp9V/1vdt8369hIy19VP7fnW+y1g1VHHQLB/zaNXTW5CnjJIvFLnpDm6DY PNfBuMsF2VdooLoEZcDeD/amK9q6R9o= X-MC-Unique: -P8900ISNRCy1ePFg2TxUQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 05/11] nodedev: store mdev UUID in mdev caps Date: Tue, 16 Jun 2020 09:27:53 -0500 Message-Id: <20200616142759.4625-6-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@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" 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 b1dfe81653..06e5924bef 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2214,6 +2214,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 Tue May 7 14:39:51 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=1592317712; cv=none; d=zohomail.com; s=zohoarc; b=J7m38HbR/3l3tJxRnHIpVPQy8ppmnzhMdjxi/cit8eOGVUVtOXZmaMSJUus4STwhy04QbGvftPr1t98K0gxtIwq9Utm1/w6bbVVRuUWnITNTh8IKmn/jQbwK/CXm0Uix4OV+F4z9H8OQnAwy6COh7iJf048Bzmt2ry/crmAM2kM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317712; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1gEg/tBnJx3OgakClEq/4uSX1uusb5DQR98zV1xHAQU=; b=IxFAPdHyO9g2Weowd7M1v9nGgH/u1gGwSoggDupBgS1Qm2XMf5jeC1g0ovtiTBzu1MB+Yn+4IaHc2Cy0n0SDL6ioBaQGJvmxVxBX1cIye6ZM1sB9956kS++fr8PKuF/hzbo9hlcUszXcdn3yMGihyBtZntCB5/9p43/ioOKgtNo= 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 1592317712851389.6688401127607; Tue, 16 Jun 2020 07:28:32 -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-166-94ghiCWWNyaKXBhTJVVIWw-1; Tue, 16 Jun 2020 10:28:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6AEA2E926; Tue, 16 Jun 2020 14:28: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 487A219D82; Tue, 16 Jun 2020 14:28: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 166C2833B1; Tue, 16 Jun 2020 14:28: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 05GES6LA020356 for ; Tue, 16 Jun 2020 10:28:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2241A78F0F; Tue, 16 Jun 2020 14:28:06 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BEEAE7890A; Tue, 16 Jun 2020 14:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317711; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1gEg/tBnJx3OgakClEq/4uSX1uusb5DQR98zV1xHAQU=; b=B3cjoKbUubIS5EZfA0WfE8fDLv57Waa+xIt8F36ICf1+1YpFlZv2omn7y7KDYMGWdLOrcr i79E6JCPUKC+ZFPvlaxybFt4v3dr6gBlgL9gGZMGbatADorwQtE0ESQLbMhhef2J/69653 BUT479Hr20SWlt0gkKtJEsWxsq9LROI= X-MC-Unique: 94ghiCWWNyaKXBhTJVVIWw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 06/11] nodedev: add mdev support to virNodeDeviceCreateXML() Date: Tue, 16 Jun 2020 09:27:54 -0500 Message-Id: <20200616142759.4625-7-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 | 199 +++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 6 + 7 files changed, 248 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 97d790aced..9092d2b7ae 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..dd00b4ddf7 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,158 @@ 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 *parent_pci =3D nodeDeviceFindAddressByName(def->paren= t); + + 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 +775,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 Tue May 7 14:39:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1592317733; cv=none; d=zohomail.com; s=zohoarc; b=KMxbt3rjcNmtbpeCfWR0suz+UTFpMuKUrhFdjusNqCU/aKerIkvxFMk6ClU1+scMOlqN4kyiE6UKKDua8bCTg/UorRJcNrtZZy46TTxz3DRMd7XjohWty2xqojV+sssjNJ+Ijn070l/H8j/WDCyw+/szZ8XHi5VKcbzNRx4Ww/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317733; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hA2cs+ARia4N4iPiv2vKi8AxcNC/kt7VVjomey0pTy4=; b=jjQv2QcIKIOmqKQKkruyucXEzwdDDpRz0TJdvptLYOkssMeRfWTOcN4lZUYe4qEY4+6rYCbWn2py78E8JlaQTC9l4olkZf92jmQki0ixwleAXIt1zTDfukD4isanK/ppWeruT1Aqx/36LSSAsMvaeVchDGim+jUbWsRJAflA6fs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 159231773380378.39534641476041; Tue, 16 Jun 2020 07:28: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-59-NIEpLf9HN2qhhRYvo-ZOfg-1; Tue, 16 Jun 2020 10:28:35 -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 A0CAFE917; Tue, 16 Jun 2020 14:28:22 +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 81A255C1D4; Tue, 16 Jun 2020 14:28:22 +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 53B1E833D0; Tue, 16 Jun 2020 14:28:22 +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 05GES68n020366 for ; Tue, 16 Jun 2020 10:28:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8AB5478F0F; Tue, 16 Jun 2020 14:28:06 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3EA647FE90; Tue, 16 Jun 2020 14:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317732; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=hA2cs+ARia4N4iPiv2vKi8AxcNC/kt7VVjomey0pTy4=; b=UVNViuEABklinakcmUkStm/NPy1XPCKxJJ9CHEJV5mauYQBrcjRJ2Ny12pRE0Mqln3SFmB 3jDM/odmakkvywSv3N5F0lic8c+w3As1OKG6+9eHJHuBusgUqxuWhCSZ0SQglli6SLVa2X TpGLsGcjO7U0urgKC41YZoMaPfI15wU= X-MC-Unique: NIEpLf9HN2qhhRYvo-ZOfg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 07/11] nodedev: Build a non-loadable driver lib Date: Tue, 16 Jun 2020 09:27:55 -0500 Message-Id: <20200616142759.4625-8-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@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 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 Tue May 7 14:39:51 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=1592317709; cv=none; d=zohomail.com; s=zohoarc; b=Ulx5Y9NYoxVWQL02yHCpCxMnfjzUG6TBHSpY2UlBoB3UZa/LvnSDdqwJQ1Q+J/oTBuKPs9tC3PfuxD/ZVmiQuaF8Wjjx5uJLBP50PNURmZjj2IJ0wP9kUAXdwmi8t0lfDfzWG7M1ydpviknyAqrM9VeoOXkSsL8h5eUfgR41L9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317709; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FGSaVE0EY3OK5AuTogufbjr4bV4Lh7vUwX+0ccH4ffs=; b=basNyC55OBXjEEmVp1WT4xA4fO3CtP/koXdJavA7BSiX1a8b3KxBgW0ynkf/B706KKJCbsNXbDzoyT+awtrfnrVfIr8fn6Uomu2aO3tF8xtL6OrNf7mYKoJ63WF5fAtYfT7yRpToRu6l85jIGqD+QIYwonEhExWP80glVNqTV1s= 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 1592317709349402.55278808317314; Tue, 16 Jun 2020 07:28: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-364--29AQ2GnMX6R_az9u00qIw-1; Tue, 16 Jun 2020 10:28:23 -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 726A5106B256; Tue, 16 Jun 2020 14:28:17 +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 524C35C1D4; Tue, 16 Jun 2020 14:28:17 +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 C59EF180BACF; Tue, 16 Jun 2020 14:28:16 +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 05GES6B6020375 for ; Tue, 16 Jun 2020 10:28:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id F239E78F0F; Tue, 16 Jun 2020 14:28:06 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6583768DC; Tue, 16 Jun 2020 14:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317706; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FGSaVE0EY3OK5AuTogufbjr4bV4Lh7vUwX+0ccH4ffs=; b=iw/rv+azhpzh7exjnidOucmgCRbVF6OjSYJ28XuKDp276Jie2r7y2oXu9PwzMSzw/weQQd 3q0kwZiNc5wIAwK2ygQyCvWq2P8ErqUdhoYwtt4efP3Vcvs0VfQELexArKyNkUbpBO29Yo Zbf807SYF5DqdS7ekORzByPijmGj9iI= X-MC-Unique: -29AQ2GnMX6R_az9u00qIw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 08/11] nodedev: Add testing for 'mdevctl start' Date: Tue, 16 Jun 2020 09:27:56 -0500 Message-Id: <20200616142759.4625-9-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@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" 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 | 262 ++++++++++++++++++ ...v_d069d019_36ea_4111_8f0a_8c9a70e21366.xml | 7 + ...v_d2441d39_495e_4243_ad9f_beb3f14c23d9.xml | 9 + ...v_fedc4916_1ca8_49ac_b176_871d16c13076.xml | 8 + 12 files changed, 307 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..eb7262035e --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-st= art.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ 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..eb7262035e --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-st= art.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ 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..eb7262035e --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-st= art.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ 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..8d226e012b --- /dev/null +++ b/tests/nodedevmdevctltest.c @@ -0,0 +1,262 @@ +#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 startTestInfo { + 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); +} + +/* We don't want the result of the test to depend on the path to the mdevc= tl + * binary on the developer's machine, so replace the path to mdevctl with a + * placeholder string before comparing to the expected output */ +static int +nodedevCompareToFile(const char *actual, + const char *filename) +{ + g_autofree char *replacedCmdline =3D NULL; + + replacedCmdline =3D virStringReplace(actual, MDEVCTL, "$MDEVCTL_BINARY= $"); + + return virTestCompareToFile(replacedCmdline, filename); +} + +static int +testMdevctlStart(const char *virt_type, + int create, + const char *mdevxml, + const char *startcmdfile, + const char *startjsonfile) +{ + g_autoptr(virNodeDeviceDef) 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. The json value is captured in the callback 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 (nodedevCompareToFile(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 startTestInfo *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->virt_type, + info->create, mdevxml, cmdlinefile, + jsonfile); +} + +static void +nodedevTestDriverFree(virNodeDeviceDriverStatePtr drv) +{ + if (!drv) + return; + + virNodeDeviceObjListFree(drv->devs); + 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; + if (VIR_ALLOC(driver) < 0) + return -1; + + 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; + + /* add a mock device to the device list so it can be used as a parent + * reference */ + if (nodedevTestDriverAddTestDevices() < 0) { + ret =3D EXIT_FAILURE; + goto done; + } + +#define DO_TEST_FULL(desc, func, info) \ + if (virTestRun(desc, func, &info) < 0) \ + ret =3D -1; + +#define DO_TEST_START_FULL(virt_type, create, filename) \ + do { \ + struct startTestInfo info =3D { virt_type, create, filename }; \ + DO_TEST_FULL("mdevctl start " filename, testMdevctlStartHelper, in= fo); \ + } \ + while (0); + +#define DO_TEST_START(filename) \ + DO_TEST_START_FULL("QEMU", CREATE_DEVICE, filename) + + /* Test mdevctl start commands */ + DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); + DO_TEST_START("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); + DO_TEST_START("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..d6a2e99edc --- /dev/null +++ b/tests/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366.xml @@ -0,0 +1,7 @@ + + 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..89568d06ce --- /dev/null +++ b/tests/nodedevschemadata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9.xml @@ -0,0 +1,9 @@ + + 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..7cd0a46e3d --- /dev/null +++ b/tests/nodedevschemadata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076.xml @@ -0,0 +1,8 @@ + + mdev_fedc4916_1ca8_49ac_b176_871d16c13076 + pci_0000_00_02_0 + + + + + --=20 2.21.3 From nobody Tue May 7 14:39:51 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=1592317756; cv=none; d=zohomail.com; s=zohoarc; b=lcJeUpD1Ybjth12sfpsIHRp+MxHyZOFwgoyrfEDtFKEmm52snuASlc2FHopHs+Yal+GfNk5mdabCAUJv1Xub7EzMF1UPREDYb4UBepjn7eXEr6mfc4F0E00ZMsgMwgXtLodWDza2YArGz1xB8BMxTMlVm6rWEM9VXaYRKyvfv0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317756; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dLXbYhHW0RloSKScLzcnm8X17e0mcj76uNExdqktOVY=; b=QRPcnPnU0KVOQ37rqdtejijNt3cHsDI0OtwRIL/7wd3TfZokFUPNx4KBD01hXa5RraTSQKzPHinDArt2gg8NFZ0KpX/26ryiJ3znK8pS8eHKIkxAye10vNSn0bu01Tm8ul1IdwagVyViW260bXEflwnKsbnzWVBN3MhaZBopMiY= 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 1592317756552933.6050932848872; Tue, 16 Jun 2020 07:29:16 -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-202-AAYg_uNuOh6zRfCxWp7puA-1; Tue, 16 Jun 2020 10:28:35 -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 A5D9C100962C; Tue, 16 Jun 2020 14:28:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 842547FE9D; Tue, 16 Jun 2020 14:28:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4E749833D0; Tue, 16 Jun 2020 14:28:24 +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 05GES7Wi020380 for ; Tue, 16 Jun 2020 10:28:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6488478F0F; Tue, 16 Jun 2020 14:28:07 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 19D6778FDB; Tue, 16 Jun 2020 14:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317755; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dLXbYhHW0RloSKScLzcnm8X17e0mcj76uNExdqktOVY=; b=cfocVYew2Q+ojK+RLVmzU1FgcHO/twqjGsJOcgoYQd9Ib4sl8d6rlH1xAohHKuVxkOs2N8 ZHij5xxJnedcccPzeGFCR5a1n/bXPEhCC3J04DeFtYTxq0TCEorQn70aDFC8KM6wVXepbZ 9YEXkXjyHMlRXDBbYQVpsz5TgJi0uPM= X-MC-Unique: AAYg_uNuOh6zRfCxWp7puA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 09/11] nodedev: add mdev support to virNodeDeviceDestroy() Date: Tue, 16 Jun 2020 09:27:57 -0500 Message-Id: <20200616142759.4625-10-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@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" Add the ability to destroy mdev node devices via the mdevctl utility. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety Reviewed-by: Michal Privoznik --- src/node_device/node_device_driver.c | 33 ++++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index dd00b4ddf7..774307ac34 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -786,6 +786,32 @@ nodeDeviceCreateXML(virConnectPtr conn, } =20 =20 +virCommandPtr +nodeDeviceGetMdevctlStopCommand(const char *uuid) +{ + return virCommandNewArgList(MDEVCTL, + "stop", + "-u", + uuid, + NULL); + +} + +static int +virMdevctlStop(virNodeDeviceDefPtr def) +{ + int status; + g_autoptr(virCommand) cmd =3D NULL; + + cmd =3D nodeDeviceGetMdevctlStopCommand(def->caps->data.mdev.uuid); + + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + return 0; +} + + int nodeDeviceDestroy(virNodeDevicePtr device) { @@ -832,6 +858,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..624369bc2d 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -122,3 +122,5 @@ virCommandPtr nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, bool persist, char **uuid_out); +virCommandPtr +nodeDeviceGetMdevctlStopCommand(const char *uuid); --=20 2.21.3 From nobody Tue May 7 14:39:51 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=1592317709; cv=none; d=zohomail.com; s=zohoarc; b=DBHHUc94FgUF3QpOJ9PhrFBT8ye4Zd1r048pD9zm9rnGmXhJQYkQyReQ0vg4WlgvyoXxP4L+kdZJrkXOzbZM7G/QODbHEPNZbAGku6dfOSHMjwEPFlGfaO3dh37oMvyKOj+sbthw2enh9MFtgiFlX4jiZ5a6j7/NQqjqiREzHQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317709; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KCBNOtfb4DmAgZpBgu3dWMRXy5NDDWQ8DIhe6ya0X24=; b=eaICx0Rk12/RahjwWlWV3RA+ZcHVLVczbbW8Jy8lcMpfpS9jClPHUQ64RWKIRENSo0oWYrYIijoh4wKp+UjnrivV1v/0H11BZmIdoi/k0IgnzXzkK+gTAoSOgQ3h0VcCw3ABtSc8gU6EyEsUVutI8xSOOTmoxEYE6njg3kLDgo4= 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 1592317709476251.38670021681298; Tue, 16 Jun 2020 07:28: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-385-iBerbKuyOuuGMpdzelwwNQ-1; Tue, 16 Jun 2020 10:28:26 -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 67A8C8B62FD; Tue, 16 Jun 2020 14:28:20 +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 46A595D9DA; Tue, 16 Jun 2020 14:28: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 109BB1805309; Tue, 16 Jun 2020 14:28: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 05GES7dl020385 for ; Tue, 16 Jun 2020 10:28:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id CACC87BA19; Tue, 16 Jun 2020 14:28:07 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 800EE768DC; Tue, 16 Jun 2020 14:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317708; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=KCBNOtfb4DmAgZpBgu3dWMRXy5NDDWQ8DIhe6ya0X24=; b=KXn1Q/PVYKL2Q0YYuqwgHH/lJfGldmSbyga1fOVH+AaiN6eF7/ALUMZHGwrSidghnuNZiJ a6WVaoqyFiYZBCGB/mp2KJ0JpFm3FY9rfITRIAjWGRIMwnks8UK5WU28BXdd3RkFpTCSfZ vb6aMOVl1fPyzFrayo1kFqjigZVsLo4= X-MC-Unique: iBerbKuyOuuGMpdzelwwNQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 10/11] nodedev: Add testing for 'mdevctl stop' Date: Tue, 16 Jun 2020 09:27:58 -0500 Message-Id: <20200616142759.4625-11-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@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" Test that we run 'mdevctl' with the proper arguments when we destroy mediated devices with virNodeDeviceDestroy() Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety Reviewed-by: Michal Privoznik --- tests/nodedevmdevctldata/mdevctl-stop.argv | 1 + tests/nodedevmdevctltest.c | 42 ++++++++++++++++++++++ 2 files changed, 43 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..3dbaab671b --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-stop.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ stop -u e2451f73-c95b-4124-b900-e008af37c576 diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 8d226e012b..dbaaa9756e 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -110,6 +110,42 @@ testMdevctlStartHelper(const void *data) jsonfile); } =20 +static int +testMdevctlStop(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); + + if (!cmd) + goto cleanup; + + virCommandSetDryRun(&buf, NULL, NULL); + if (virCommandRun(cmd, NULL) < 0) + goto cleanup; + + if (!(actualCmdline =3D virBufferCurrentContent(&buf))) + goto cleanup; + + if (nodedevCompareToFile(actualCmdline, cmdlinefile) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&buf); + virCommandSetDryRun(NULL, NULL, NULL); + return ret; +} + static void nodedevTestDriverFree(virNodeDeviceDriverStatePtr drv) { @@ -248,11 +284,17 @@ mymain(void) #define DO_TEST_START(filename) \ DO_TEST_START_FULL("QEMU", CREATE_DEVICE, filename) =20 +#define DO_TEST_STOP(uuid) \ + DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid) + /* Test mdevctl start commands */ DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); DO_TEST_START("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); DO_TEST_START("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); =20 + /* Test mdevctl stop command, pass an arbitrary uuid */ + DO_TEST_STOP("e2451f73-c95b-4124-b900-e008af37c576"); + done: nodedevTestDriverFree(driver); =20 --=20 2.21.3 From nobody Tue May 7 14:39:51 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=1592317720; cv=none; d=zohomail.com; s=zohoarc; b=kzvlC5Mjn6JJwLi+moe+sepETITmmDCUoMxwQKFdJXT0p9G08u+NELxBk4vnp2BT+c3rtxMXNd/+Gu6UHOpiRuROg8OqlxKjNbYwpB6co+KFqChhWz73NnBCYND0YhOcPeUfxYX8zWFvzz51GPJkMAdi1m2P/4MC9MIshMJ/xkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317720; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r4DNHlA8fsqMtQU+EbXPBoNIuB3HI8aX4Q2ByrCrXNI=; b=LwSujoNQRmRdHKrVTJbr6t+Dv2fp+TvGRK6R9tPSkWSFirAqEIJXPgZdd++yaY2zsKUIcDshQ6LlKLc+PkFdlODVVPgfEdKhEQl4/QNdDd1juC4rgMYIgqtDG+ITu3GwgPuRJ74vYrgB58gy2LlW5l+r6w23l5NwHpiLDf1l5lo= 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 1592317720556433.82621320614567; Tue, 16 Jun 2020 07:28:40 -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-406-_tK0CQDVNIWcFXqzrTmyUQ-1; Tue, 16 Jun 2020 10:28:34 -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 EF8708B631A; Tue, 16 Jun 2020 14:28:26 +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 C137A79312; Tue, 16 Jun 2020 14:28:26 +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 8CF331805310; Tue, 16 Jun 2020 14:28:26 +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 05GES8U1020393 for ; Tue, 16 Jun 2020 10:28:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C72178F0F; Tue, 16 Jun 2020 14:28:08 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E616D768DC; Tue, 16 Jun 2020 14:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317719; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=r4DNHlA8fsqMtQU+EbXPBoNIuB3HI8aX4Q2ByrCrXNI=; b=BTKo7enKequ/yQ2J5WSNyh2nOfwme0eeTmOiOetoycDlT34HEub0qOUGsGZcfq7d/jaQJe orTUHGmuHmTqo7LJGmi7QgfQ85LkVyfNLo3g4QIgWKb+DP/2B5IJZyHhtTAEw7UbCUnS7Y MWNIZdehtIfq1Lsj4R1M4mihDMpcSjA= X-MC-Unique: _tK0CQDVNIWcFXqzrTmyUQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 11/11] docs: note node device fields that are read-only Date: Tue, 16 Jun 2020 09:27:59 -0500 Message-Id: <20200616142759.4625-12-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-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 Cc: mprivozn@redhat.com, eskultet@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" 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 0637d457ee..e4328fedbe 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