From nobody Thu May 2 03:10:53 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=1597762108; cv=none; d=zohomail.com; s=zohoarc; b=EraS87M0eTloYIoVVXnPtO7ix5DZNBdpd21r7+INX7HEAccyYxSL+wDFs7TVxGmn63mv/wpbOXVO5JgcvQtUkUNIbMKoNmESaQechmp8wFTJV831NQ1hx4dSZXJ3RTBRJiXK2yDSW2nhbCXyIo05LK0Vfnedq/pw1uAgwNoxCrE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762108; 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=lWGN7OcaC182WGJ0C2Cj/XTgt3hxlo3P5gfu6TdJvWo=; b=Vz2UAMCBfS0HCbdGzYAXdc1SROjI5qkNhPKCki5juT/YIi4MMkH5HHmz2xq7QZGFAJ48q6IEyV9gR8/xbbITiLWfEJwOv+A64iIVhPXWNrYc3V6Kwu6BpTDHGN0IKfzYy93mnw1vx8sj2tOaRtOSyZFABZPg7EwJuW4wCOvTuhM= 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-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 159776210809280.93916252689621; Tue, 18 Aug 2020 07:48: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-277-5E6F76N1MHaLROe7dFGV0w-1; Tue, 18 Aug 2020 10:48:25 -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 C2F251DDF9; Tue, 18 Aug 2020 14:48:15 +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 AAFCE5D9DC; Tue, 18 Aug 2020 14:48:14 +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 6ADCB6034D; Tue, 18 Aug 2020 14:48:12 +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 07IEmAYw002715 for ; Tue, 18 Aug 2020 10:48:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E64E5D757; Tue, 18 Aug 2020 14:48:10 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 313725D6BD; Tue, 18 Aug 2020 14:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762107; 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=lWGN7OcaC182WGJ0C2Cj/XTgt3hxlo3P5gfu6TdJvWo=; b=Gl6TderQbQ6P/JLsoxXSlnDylnqhBR3dqMZBcNqIb6ZDWiG+SLuJ4tlk6LRztTL4z2Tw2i sDvPJl4UN1lksuPxfKSm+I0Ed7ue1TVvOw0EPV8xZwGd+6lZlPuWEwPs+zrx3mhnJ1f7fB C6O05ORuTdD+3AOSovGN0jFEAb68dbo= X-MC-Unique: 5E6F76N1MHaLROe7dFGV0w-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 01/16] tests: remove extra trailing semicolon Date: Tue, 18 Aug 2020 09:47:51 -0500 Message-Id: <20200818144806.134738-2-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The macro should not have a trailing semicolon so that when the macro is used, the user can add a semicolon themselves. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- tests/nodedevmdevctltest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 9780553a3a..d75dfb1d3e 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -276,7 +276,7 @@ mymain(void) struct startTestInfo info =3D { virt_type, create, filename }; \ DO_TEST_FULL("mdevctl start " filename, testMdevctlStartHelper, in= fo); \ } \ - while (0); + while (0) =20 #define DO_TEST_START(filename) \ DO_TEST_START_FULL("QEMU", CREATE_DEVICE, filename) --=20 2.26.2 From nobody Thu May 2 03:10:53 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=1597762116; cv=none; d=zohomail.com; s=zohoarc; b=dIOs0ihROa8HldABEbB1OoE9/gGlUxzn+rHNf2Oi8wbQNGbwdien82gdJ+FvgaJswDg0E/lBOVkLZkQ1pKJNm3Dvr3PjtcJhvcmr7MAyxzyINwnOSLg9jMVu6/5KfLzUkYn3vmOHwvM0L78bRC2RL2OUNu3WPXKC7d4VIW/9ygo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762116; 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=rtSWEJsD4xCObkR/PoWMP1z2mPM0sbsfPENZEauWvrc=; b=L8/Z5g82ErvHpaBflG8u5FSitbfxrpukWg6xgq/9d4DmOmtPwMK6fGemCqFIAZ/bnb4Wriod+/lkyQNFPIUVbddIhx//vQiAXfNzP3E5npKtZrRsNWdyMpwVzLJcEKFcODGrIYIlwaC9BQ2HwLSo2kwn2B5gJS5Z2JHZPgg0bXI= 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-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1597762116548150.48985275921223; Tue, 18 Aug 2020 07:48:36 -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-435-nn2dyfbhMZecAu1ILex8iA-1; Tue, 18 Aug 2020 10:48:33 -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 98A271DDF9; Tue, 18 Aug 2020 14:48:26 +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 7A1D7702F1; Tue, 18 Aug 2020 14:48: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 4633760374; Tue, 18 Aug 2020 14:48: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 07IEmA2C002721 for ; Tue, 18 Aug 2020 10:48:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id C784F5D757; Tue, 18 Aug 2020 14:48:10 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89E915D6BD; Tue, 18 Aug 2020 14:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762115; 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=rtSWEJsD4xCObkR/PoWMP1z2mPM0sbsfPENZEauWvrc=; b=F5NSXk+s7/yoX/zEXILHYq6gCSZbqWca/vEgOne8gX60BzzoTxpKHwwhTf+jum+wIYrbrk lkhXwJUWMzhat8oExstLius7E563qclD8W2sYSvnfd7cpr6/xlmsI7mbIzbdnM6qSnmfc/ qaBalET+QrfZChKgAhq+aPtPgsD3t0Y= X-MC-Unique: nn2dyfbhMZecAu1ILex8iA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 02/16] nodedev: introduce concept of 'active' node devices Date: Tue, 18 Aug 2020 09:47:52 -0500 Message-Id: <20200818144806.134738-3-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" we will be able to define mediated devices that can be started or stopped, so we need to be able to indicate whether the device is active or not, similar to other resources (storage pools, domains, etc.) Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/conf/virnodedeviceobj.c | 14 ++++++++++++++ src/conf/virnodedeviceobj.h | 7 +++++++ src/libvirt_private.syms | 2 ++ src/node_device/node_device_udev.c | 3 +++ 4 files changed, 26 insertions(+) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index bfd524121c..88a7746b27 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -39,6 +39,7 @@ struct _virNodeDeviceObj { virNodeDeviceDefPtr def; /* device definition */ bool skipUpdateCaps; /* whether to skip checking host c= aps, used by testdriver */ + bool active; }; =20 struct _virNodeDeviceObjList { @@ -959,3 +960,16 @@ virNodeDeviceObjSetSkipUpdateCaps(virNodeDeviceObjPtr = obj, { obj->skipUpdateCaps =3D skipUpdateCaps; } + +bool +virNodeDeviceObjIsActive(virNodeDeviceObjPtr obj) +{ + return obj->active; +} + +void +virNodeDeviceObjSetActive(virNodeDeviceObjPtr obj, + bool active) +{ + obj->active =3D active; +} diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 6efdb23d36..c119f4c51f 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -121,3 +121,10 @@ virNodeDeviceObjSetSkipUpdateCaps(virNodeDeviceObjPtr = obj, virNodeDeviceObjPtr virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjListPtr devs, const char *uuid); + +bool +virNodeDeviceObjIsActive(virNodeDeviceObjPtr obj); + +void +virNodeDeviceObjSetActive(virNodeDeviceObjPtr obj, + bool active); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 01c2e710cd..9e102e328a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1189,6 +1189,7 @@ virNetworkPortDefSaveStatus; # conf/virnodedeviceobj.h virNodeDeviceObjEndAPI; virNodeDeviceObjGetDef; +virNodeDeviceObjIsActive; virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; virNodeDeviceObjListFindByName; @@ -1201,6 +1202,7 @@ virNodeDeviceObjListGetParentHost; virNodeDeviceObjListNew; virNodeDeviceObjListNumOfDevices; virNodeDeviceObjListRemove; +virNodeDeviceObjSetActive; =20 =20 # conf/virnwfilterbindingdef.h diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index ff558efb83..bce5466131 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1350,6 +1350,7 @@ udevAddOneDevice(struct udev_device *device) else event =3D virNodeDeviceEventUpdateNew(objdef->name); =20 + virNodeDeviceObjSetActive(obj, true); virNodeDeviceObjEndAPI(&obj); =20 ret =3D 0; @@ -1741,6 +1742,8 @@ udevSetupSystemDev(void) if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; =20 + virNodeDeviceObjSetActive(obj, true); + virNodeDeviceObjEndAPI(&obj); =20 ret =3D 0; --=20 2.26.2 From nobody Thu May 2 03:10:53 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=1597762115; cv=none; d=zohomail.com; s=zohoarc; b=D+9H4ySPZiCnVLr6sOe2yMOrS1J0tKTcVFQsotQzwlBWAe3gvn2dGC1Kq+7go5Faib/gWsnNVDIZ/G73cDGkqudupoid6/d7m5NW/8hwuhxHwxgVhuqy4wCL4herCzMjomfKUGA6jVJXpl50kVacB80TrkRfzQaZzE/e5AsuhlQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762115; 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=RqrNBaIllUh02Lp/rblO9gCiEELYcteveYaModtkjsc=; b=nBkvyx4jLLkJcCNt7LqLd0W2pQAfDd7ztxnKYUFlHhDlwmkyZfQWLQiJWl1eYSFL4b3pPVN+8/nyJlPFZS1GS1exBuL58YFrD8CYdZpLJeA8ZBijANybMaWdST89KpNJCNWNyAkslfrRsxPUdbOe/zFfA0NzaAevJCfbH/kQvaw= 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 1597762115614167.1934037427303; Tue, 18 Aug 2020 07:48:35 -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-256-DEGUVpxAMbKUlHyzsB9m8A-1; Tue, 18 Aug 2020 10:48:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 926AC18686C2; Tue, 18 Aug 2020 14:48:26 +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 6F5B2BA63; Tue, 18 Aug 2020 14:48: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 3BFCB60372; Tue, 18 Aug 2020 14:48: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 07IEmBdX002728 for ; Tue, 18 Aug 2020 10:48:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2BBDC5D757; Tue, 18 Aug 2020 14:48:11 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E34885D6BD; Tue, 18 Aug 2020 14:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762114; 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=RqrNBaIllUh02Lp/rblO9gCiEELYcteveYaModtkjsc=; b=VAB0EL7Hyfkc1onOWCAg+iWueq9+dsIF7SHe2psWmRYzG89i1h2hiacv2GEDqYergB0hfc G9SvKHWE0GYXWQ9Q6kG0IIM+MuLYk3vYz311+uniQfSvNfFQFSrK6Wedzdo2UqaTwWnsLM ZB9GjItddxZb70w0ogJplxCu1XwfZwE= X-MC-Unique: DEGUVpxAMbKUlHyzsB9m8A-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 03/16] nodedev: Add ability to filter by active state Date: Tue, 18 Aug 2020 09:47:53 -0500 Message-Id: <20200818144806.134738-4-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.002 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 two flag values for virConnectListAllNodeDevices() so that we can list only node devices that are active or inactive. Signed-off-by: Jonathon Jongsma --- include/libvirt/libvirt-nodedev.h | 9 ++++++--- src/conf/node_device_conf.h | 8 ++++++++ src/conf/virnodedeviceobj.c | 10 ++++++++++ src/libvirt-nodedev.c | 2 ++ src/node_device/node_device_driver.c | 2 +- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index a2ad61ac6d..98a972e60d 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -61,10 +61,9 @@ int virNodeListDevices (virConn= ectPtr conn, * virConnectListAllNodeDevices: * * Flags used to filter the returned node devices. Flags in each group - * are exclusive. Currently only one group to filter the devices by cap - * type. - */ + * are exclusive. */ typedef enum { + /* filter the devices by cap type */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM =3D 1 << 0, /* System= capability */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV =3D 1 << 1, /* PCI de= vice */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV =3D 1 << 2, /* USB de= vice */ @@ -81,6 +80,10 @@ typedef enum { VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES =3D 1 << 13, /* Capabl= e of mediated devices */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV =3D 1 << 14, /* Mediat= ed device */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV =3D 1 << 15, /* CCW de= vice */ + + /* filter the devices by active state */ + VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE =3D 1 << 16, /* Inacti= ve devices */ + VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE =3D 1 << 17, /* Active= devices */ } virConnectListAllNodeDeviceFlags; =20 int virConnectListAllNodeDevices (virConnectPtr conn, diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 9b8c7aadea..353dbebaf0 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -369,6 +369,14 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV) =20 +#define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE \ + VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE |\ + VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE + +#define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ALL \ + VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP | \ + VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE + int virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host); =20 diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 88a7746b27..9838513b69 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -865,6 +865,16 @@ virNodeDeviceObjMatch(virNodeDeviceObjPtr obj, return false; } =20 +#undef MATCH +#define MATCH(FLAG) (flags & (FLAG)) + + if (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE) && + !((MATCH(VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE) && + virNodeDeviceObjIsActive(obj)) || + (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE) && + !virNodeDeviceObjIsActive(obj)))) + return false; + return true; } #undef MATCH diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index ca6c2bb057..6dc61304a0 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -101,6 +101,8 @@ virNodeNumOfDevices(virConnectPtr conn, const char *cap= , unsigned int flags) * VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES * VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV * VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV + * VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE + * VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE * * Returns the number of node devices found or -1 and sets @devices to NUL= L in * case of error. On success, the array stored into @devices is guarantee= d to diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index e89c8b0ee5..f766fd9f32 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -218,7 +218,7 @@ nodeConnectListAllNodeDevices(virConnectPtr conn, virNodeDevicePtr **devices, unsigned int flags) { - virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP, -1); + virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ALL, -1); =20 if (virConnectListAllNodeDevicesEnsureACL(conn) < 0) return -1; --=20 2.26.2 From nobody Thu May 2 03:10:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597762122; cv=none; d=zohomail.com; s=zohoarc; b=NuBA7nxace8TxIC9Q6FwbCbIx8KdNZDI54yGYdp7HqyMK0dwUeQzdGaJssVWDf2JqwIO7y8yEju1rgUhSNPWV635WZVK7yE+U5PSdDEMoemjdDijAVfxyKmDQg2bU5j/caGqZqOEpHwGLNWe7/hjD2x+zOBN8cYFhviLxTD184E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762122; 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=WXYAK0huD5TjaMKndBZheWE88uJZdhprvv4sewZYC0M=; b=ZFM0calNLsqPjyAKWhRSZe9d+0IYPE51rC5pagbJUlFZs/YLPo6b9HT13FFA9QBmdjsyDmtt7MLFBgOgnfS8JIJuO3aDX+KqneKBsYjknDqQ126NR7e/yF+KY7dcaYdbtv+UqaqOkCrxGYghZf2JqV173a+7hwgSGxFrWn5COYQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1597762122149810.9435264630234; Tue, 18 Aug 2020 07:48:42 -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-451-jMOyIkAeMbq3N3lTLUuqUw-1; Tue, 18 Aug 2020 10:48:39 -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 5F8541DE03; Tue, 18 Aug 2020 14:48:29 +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 3D7C22CFC6; Tue, 18 Aug 2020 14:48:29 +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 DC806181A07C; Tue, 18 Aug 2020 14:48:28 +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 07IEmBi5002736 for ; Tue, 18 Aug 2020 10:48:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 853AC5D6BD; Tue, 18 Aug 2020 14:48:11 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 48F937DFC2; Tue, 18 Aug 2020 14:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762121; 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=WXYAK0huD5TjaMKndBZheWE88uJZdhprvv4sewZYC0M=; b=gcmQ3ri1lZeXdunhnGWGKUcBoTeuHBUlJJWqDQ6ZOmKbg7bv3Ckx7v2xHoxaFEhL+HdEwn wzNmZgmfDD6ekL608YdQZ+WK7S+jaRy+CmtwTFt9HiXATztmpCTE98sBY1H829hPeTzJcF yn2Ab/T51x5DS9ZN/L/f0yGCg2uBDls= X-MC-Unique: jMOyIkAeMbq3N3lTLUuqUw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 04/16] virsh: Add --active, --inactive, --all to nodedev-list Date: Tue, 18 Aug 2020 09:47:54 -0500 Message-Id: <20200818144806.134738-5-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Now that we can filter active and inactive node devices in virConnectListAllNodeDevices(), add these switches to the virsh command. Eventual output (once everything is hooked up): virsh # nodedev-list --inactive --cap mdev mdev_07d8b8b0_7e04_4c0f_97ed_9214ce12723c mdev_927c040f_ae7d_4a35_966e_286ba6ebbe1c virsh # nodedev-list --active --cap mdev mdev_bd2ea955_3402_4252_8c17_7468083a0f26 virsh # nodedev-list --all --cap mdev mdev_07d8b8b0_7e04_4c0f_97ed_9214ce12723c mdev_927c040f_ae7d_4a35_966e_286ba6ebbe1c mdev_bd2ea955_3402_4252_8c17_7468083a0f26 Signed-off-by: Jonathon Jongsma --- tools/virsh-nodedev.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index e576b3c847..e87761188f 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -378,6 +378,18 @@ static const vshCmdOptDef opts_node_list_devices[] =3D= { .completer =3D virshNodeDeviceCapabilityNameCompleter, .help =3D N_("capability names, separated by comma") }, + {.name =3D "active", + .type =3D VSH_OT_BOOL, + .help =3D N_("list active devices") + }, + {.name =3D "inactive", + .type =3D VSH_OT_BOOL, + .help =3D N_("list inactive devices") + }, + {.name =3D "all", + .type =3D VSH_OT_BOOL, + .help =3D N_("list inactive & active devices") + }, {.name =3D NULL} }; =20 @@ -393,18 +405,28 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd= G_GNUC_UNUSED) int ncaps =3D 0; virshNodeDeviceListPtr list =3D NULL; int cap_type =3D -1; + bool active, inactive, all; =20 + active =3D vshCommandOptBool(cmd, "active"); + inactive =3D vshCommandOptBool(cmd, "inactive"); + all =3D vshCommandOptBool(cmd, "all"); ignore_value(vshCommandOptStringQuiet(ctl, cmd, "cap", &cap_str)); =20 if (cap_str) { - if (tree) { - vshError(ctl, "%s", _("Options --tree and --cap are incompatib= le")); - return false; - } if ((ncaps =3D vshStringToArray(cap_str, &caps)) < 0) return false; } =20 + if (all && (inactive || active)) { + vshError(ctl, "%s", _("Option --all is incompatible with --active = and --inactive")); + return false; + } + + if (tree && (cap_str || active || inactive)) { + vshError(ctl, "%s", _("Option --tree is incompatible with other op= tions")); + return false; + } + for (i =3D 0; i < ncaps; i++) { if ((cap_type =3D virNodeDevCapTypeFromString(caps[i])) < 0) { vshError(ctl, "%s", _("Invalid capability type")); @@ -466,6 +488,11 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd = G_GNUC_UNUSED) } } =20 + if (inactive || all) + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE; + if (active || all) + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE; + if (!(list =3D virshNodeDeviceListCollect(ctl, caps, ncaps, flags))) { ret =3D false; goto cleanup; --=20 2.26.2 From nobody Thu May 2 03:10:53 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=1597762118; cv=none; d=zohomail.com; s=zohoarc; b=BTG+QM2evf9BhUSy5p4Yk+/d5gF5gAwuXISoVRTozvsKa9nuwSBOsPbdSpMOAg0iX80Wdw9wY0yJuzhNMfFxNdokdEc69XYG6z4t5oeeVSeMOkUl6V6ilVstY/p1UAKzK9snsUDJes95AprPk59RvbTDO2ajzZ9Ns/kVaeNu2dE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762118; 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=Qmd55J5RD13ms8ngIgCFZFlnpoIf6ZFSwwa6IZI+mUQ=; b=dgRSgjmyiX/2xe7PVSoGcILfAEFXgmrrdBsC9LQ6LvJUMTsuXK5pIEUGXtc1EusBpk6dUhmjn0P9CzawmY+UonkFkP98GjESs/hapVMdMZKAERKBTwlCWBcZ3K54uFrh+KQ0CQUhFsz1OlV75iwkIrJ+HmgbPe7yH+eqafWSN0U= 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 1597762118343695.9040622441435; Tue, 18 Aug 2020 07:48:38 -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-65-7LYCPYe5Oz6DyXWa4GbHhA-1; Tue, 18 Aug 2020 10:48:35 -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 A0A0A1006701; Tue, 18 Aug 2020 14:48:29 +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 7C7717A1FA; Tue, 18 Aug 2020 14:48:29 +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 462BF6036C; Tue, 18 Aug 2020 14:48:29 +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 07IEmCNu002742 for ; Tue, 18 Aug 2020 10:48:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 084015D757; Tue, 18 Aug 2020 14:48:12 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A54185D6BD; Tue, 18 Aug 2020 14:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762117; 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=Qmd55J5RD13ms8ngIgCFZFlnpoIf6ZFSwwa6IZI+mUQ=; b=folHQ2krWFwerLHhf03iUrU4wbqsLYQfncCvVPaw0biEdAJG05KDKwK9e1neuMDDdVhrer PrMlWIB2trPVZZF+wEpSX0P7cYPIqvuj79V8IEv4i97P2eMlqz/EPsbk84cwUn8n++lkNA 4YrUndyxe1BgiIjJVoEw9fufKHL3uew= X-MC-Unique: 7LYCPYe5Oz6DyXWa4GbHhA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 05/16] nodedev: add ability to list and parse defined mdevs Date: Tue, 18 Aug 2020 09:47:55 -0500 Message-Id: <20200818144806.134738-6-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This adds some internal API to query for persistent mediated devices that are defined by mdevctl. Following commits will make use of this information. This just provides the infrastructure and tests for this feature. One test verifies that we are executing mdevctl with the proper arguments, and other tests verify that we can parse the returned JSON and convert it to our own internal node device representations. Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_driver.c | 156 ++++++++++++++++++ src/node_device/node_device_driver.h | 13 ++ src/node_device/node_device_udev.c | 19 +-- .../mdevctl-list-defined.argv | 1 + .../mdevctl-list-multiple-parents.json | 59 +++++++ .../mdevctl-list-multiple-parents.out.xml | 39 +++++ .../mdevctl-list-multiple.json | 59 +++++++ .../mdevctl-list-multiple.out.xml | 39 +++++ .../mdevctl-list-single-noattr.json | 11 ++ .../mdevctl-list-single-noattr.out.xml | 8 + .../mdevctl-list-single.json | 31 ++++ .../mdevctl-list-single.out.xml | 14 ++ tests/nodedevmdevctltest.c | 98 +++++++++++ 13 files changed, 531 insertions(+), 16 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdevctl-list-defined.argv create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple-parents.= json create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple-parents.= out.xml create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple.json create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single-noattr.json create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single-noattr.out= .xml create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single.json create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single.out.xml diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index f766fd9f32..3b042e9a45 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -812,6 +812,137 @@ virMdevctlStop(virNodeDeviceDefPtr def) } =20 =20 +virCommandPtr +nodeDeviceGetMdevctlListCommand(bool defined, + char **output) +{ + virCommandPtr cmd =3D virCommandNewArgList(MDEVCTL, + "list", + "--dumpjson", + NULL); + + if (defined) + virCommandAddArg(cmd, "--defined"); + + virCommandSetOutputBuffer(cmd, output); + + return cmd; +} + + +static void mdevGenerateDeviceName(virNodeDeviceDefPtr dev) +{ + nodeDeviceGenerateName(dev, "mdev", dev->caps->data.mdev.uuid, NULL); +} + +int +nodeDeviceParseMdevctlJSON(const char *jsonstring, + virNodeDeviceDefPtr **devs) +{ + int n; + g_autoptr(virJSONValue) json_devicelist =3D NULL; + virNodeDeviceDefPtr *outdevs =3D NULL; + size_t noutdevs =3D 0; + size_t i, j, k, m; + + json_devicelist =3D virJSONValueFromString(jsonstring); + + if (!json_devicelist) + goto parsefailure; + + if (!virJSONValueIsArray(json_devicelist)) + goto parsefailure; + + n =3D virJSONValueArraySize(json_devicelist); + + for (i =3D 0; i < n; i++) { + virJSONValuePtr obj =3D virJSONValueArrayGet(json_devicelist, i); + int nparents; + + if (!virJSONValueIsObject(obj)) + goto parsefailure; + + nparents =3D virJSONValueObjectKeysNumber(obj); + + for (j =3D 0; j < nparents; j++) { + const char *parent =3D virJSONValueObjectGetKey(obj, j); + virJSONValuePtr child_array =3D virJSONValueObjectGetValue(obj= , j); + int nchildren; + + if (!virJSONValueIsArray(child_array)) + goto parsefailure; + + nchildren =3D virJSONValueArraySize(child_array); + + for (k =3D 0; k < nchildren; k++) { + virNodeDevCapMdevPtr mdev; + const char *uuid; + virJSONValuePtr props; + g_autoptr(virNodeDeviceDef) child =3D g_new0(virNodeDevice= Def, 1); + virJSONValuePtr child_obj =3D virJSONValueArrayGet(child_a= rray, k); + + /* the child object should have a single key equal to its = uuid. + * The value is an object describing the properties of the= mdev */ + if (virJSONValueObjectKeysNumber(child_obj) !=3D 1) + goto parsefailure; + + uuid =3D virJSONValueObjectGetKey(child_obj, 0); + props =3D virJSONValueObjectGetValue(child_obj, 0); + + child->parent =3D g_strdup(parent); + child->caps =3D g_new0(virNodeDevCapsDef, 1); + child->caps->data.type =3D VIR_NODE_DEV_CAP_MDEV; + + mdev =3D &child->caps->data.mdev; + mdev->uuid =3D g_strdup(uuid); + mdev->type =3D + g_strdup(virJSONValueObjectGetString(props, "mdev_type= ")); + + virJSONValuePtr attrs =3D virJSONValueObjectGet(props, "at= trs"); + + if (attrs && virJSONValueIsArray(attrs)) { + int nattrs =3D virJSONValueArraySize(attrs); + + mdev->attributes =3D g_new0(virMediatedDeviceAttrPtr, = nattrs); + mdev->nattributes =3D nattrs; + + for (m =3D 0; m < nattrs; m++) { + virJSONValuePtr attr =3D virJSONValueArrayGet(attr= s, m); + virMediatedDeviceAttrPtr attribute; + + if (!virJSONValueIsObject(attr) || + virJSONValueObjectKeysNumber(attr) !=3D 1) + goto parsefailure; + + attribute =3D g_new0(virMediatedDeviceAttr, 1); + attribute->name =3D g_strdup(virJSONValueObjectGet= Key(attr, 0)); + virJSONValuePtr value =3D virJSONValueObjectGetVal= ue(attr, 0); + attribute->value =3D g_strdup(virJSONValueGetStrin= g(value)); + mdev->attributes[m] =3D attribute; + } + } + mdevGenerateDeviceName(child); + + if (VIR_APPEND_ELEMENT(outdevs, noutdevs, child) < 0) + child =3D NULL; + } + } + } + + *devs =3D outdevs; + return noutdevs; + + parsefailure: + for (i =3D 0; i < noutdevs; i++) + virNodeDeviceDefFree(outdevs[i]); + VIR_FREE(outdevs); + + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("unable to parse JSON response")); + return -1; +} + + int nodeDeviceDestroy(virNodeDevicePtr device) { @@ -931,3 +1062,28 @@ nodedevRegister(void) # endif #endif } + + +void +nodeDeviceGenerateName(virNodeDeviceDefPtr def, + const char *subsystem, + const char *sysname, + const char *s) +{ + size_t i; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, "%s_%s", + subsystem, + sysname); + + if (s !=3D NULL) + virBufferAsprintf(&buf, "_%s", s); + + def->name =3D virBufferContentAndReset(&buf); + + for (i =3D 0; i < strlen(def->name); i++) { + if (!(g_ascii_isalnum(*(def->name + i)))) + *(def->name + i) =3D '_'; + } +} diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index be5d397828..e7317fd67a 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -123,3 +123,16 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr d= ef, char **uuid_out); virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid); + +virCommandPtr +nodeDeviceGetMdevctlListCommand(bool defined, char **output); + +int +nodeDeviceParseMdevctlJSON(const char *jsonstring, + virNodeDeviceDefPtr **devs); + +void +nodeDeviceGenerateName(virNodeDeviceDefPtr def, + const char *subsystem, + const char *sysname, + const char *s); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index bce5466131..93b74b1f24 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -293,22 +293,9 @@ udevGenerateDeviceName(struct udev_device *device, virNodeDeviceDefPtr def, const char *s) { - size_t i; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, "%s_%s", - udev_device_get_subsystem(device), - udev_device_get_sysname(device)); - - if (s !=3D NULL) - virBufferAsprintf(&buf, "_%s", s); - - def->name =3D virBufferContentAndReset(&buf); - - for (i =3D 0; i < strlen(def->name); i++) { - if (!(g_ascii_isalnum(*(def->name + i)))) - *(def->name + i) =3D '_'; - } + nodeDeviceGenerateName(def, + udev_device_get_subsystem(device), + udev_device_get_sysname(device), s); =20 return 0; } diff --git a/tests/nodedevmdevctldata/mdevctl-list-defined.argv b/tests/nod= edevmdevctldata/mdevctl-list-defined.argv new file mode 100644 index 0000000000..72b5906e9e --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-defined.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ list --dumpjson --defined diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple-parents.json b/= tests/nodedevmdevctldata/mdevctl-list-multiple-parents.json new file mode 100644 index 0000000000..eefcd90c62 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple-parents.json @@ -0,0 +1,59 @@ +[ + { + "0000:00:02.0": [ + { + "200f228a-c80a-4d50-bfb7-f5a0e4e34045": { + "mdev_type": "i915-GVTg_V5_4", + "start": "manual" + } + }, + { + "de807ffc-1923-4d5f-b6c9-b20ecebc6d4b": { + "mdev_type": "i915-GVTg_V5_4", + "start": "auto" + } + }, + { + "435722ea-5f43-468a-874f-da34f1217f13": { + "mdev_type": "i915-GVTg_V5_8", + "start": "manual", + "attrs": [ + { + "testattr": "42" + } + ] + } + } + ] + }, + { + "matrix": [ + { "783e6dbb-ea0e-411f-94e2-717eaad438bf": { + "mdev_type": "vfio_ap-passthrough", + "start": "manual", + "attrs": [ + { + "assign_adapter": "5" + }, + { + "assign_adapter": "6" + }, + { + "assign_domain": "0xab" + }, + { + "assign_control_domain": "0xab" + }, + { + "assign_domain": "4" + }, + { + "assign_control_domain": "4" + } + ] + } + } + ] + } +] + diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple-parents.out.xml= b/tests/nodedevmdevctldata/mdevctl-list-multiple-parents.out.xml new file mode 100644 index 0000000000..543ad916b7 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple-parents.out.xml @@ -0,0 +1,39 @@ + + mdev_200f228a_c80a_4d50_bfb7_f5a0e4e34045 + 0000:00:02.0 + + + + + + + mdev_de807ffc_1923_4d5f_b6c9_b20ecebc6d4b + 0000:00:02.0 + + + + + + + mdev_435722ea_5f43_468a_874f_da34f1217f13 + 0000:00:02.0 + + + + + + + + mdev_783e6dbb_ea0e_411f_94e2_717eaad438bf + matrix + + + + + + + + + + + diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple.json b/tests/no= dedevmdevctldata/mdevctl-list-multiple.json new file mode 100644 index 0000000000..eefcd90c62 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple.json @@ -0,0 +1,59 @@ +[ + { + "0000:00:02.0": [ + { + "200f228a-c80a-4d50-bfb7-f5a0e4e34045": { + "mdev_type": "i915-GVTg_V5_4", + "start": "manual" + } + }, + { + "de807ffc-1923-4d5f-b6c9-b20ecebc6d4b": { + "mdev_type": "i915-GVTg_V5_4", + "start": "auto" + } + }, + { + "435722ea-5f43-468a-874f-da34f1217f13": { + "mdev_type": "i915-GVTg_V5_8", + "start": "manual", + "attrs": [ + { + "testattr": "42" + } + ] + } + } + ] + }, + { + "matrix": [ + { "783e6dbb-ea0e-411f-94e2-717eaad438bf": { + "mdev_type": "vfio_ap-passthrough", + "start": "manual", + "attrs": [ + { + "assign_adapter": "5" + }, + { + "assign_adapter": "6" + }, + { + "assign_domain": "0xab" + }, + { + "assign_control_domain": "0xab" + }, + { + "assign_domain": "4" + }, + { + "assign_control_domain": "4" + } + ] + } + } + ] + } +] + diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml b/tests= /nodedevmdevctldata/mdevctl-list-multiple.out.xml new file mode 100644 index 0000000000..543ad916b7 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml @@ -0,0 +1,39 @@ + + mdev_200f228a_c80a_4d50_bfb7_f5a0e4e34045 + 0000:00:02.0 + + + + + + + mdev_de807ffc_1923_4d5f_b6c9_b20ecebc6d4b + 0000:00:02.0 + + + + + + + mdev_435722ea_5f43_468a_874f_da34f1217f13 + 0000:00:02.0 + + + + + + + + mdev_783e6dbb_ea0e_411f_94e2_717eaad438bf + matrix + + + + + + + + + + + diff --git a/tests/nodedevmdevctldata/mdevctl-list-single-noattr.json b/tes= ts/nodedevmdevctldata/mdevctl-list-single-noattr.json new file mode 100644 index 0000000000..acee3eb628 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-single-noattr.json @@ -0,0 +1,11 @@ +[ + { + "matrix": [ + { "783e6dbb-ea0e-411f-94e2-717eaad438bf": { + "mdev_type": "vfio_ap-passthrough", + "start": "manual" + } + } + ] + } +] diff --git a/tests/nodedevmdevctldata/mdevctl-list-single-noattr.out.xml b/= tests/nodedevmdevctldata/mdevctl-list-single-noattr.out.xml new file mode 100644 index 0000000000..85958695da --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-single-noattr.out.xml @@ -0,0 +1,8 @@ + + mdev_783e6dbb_ea0e_411f_94e2_717eaad438bf + matrix + + + + + diff --git a/tests/nodedevmdevctldata/mdevctl-list-single.json b/tests/node= devmdevctldata/mdevctl-list-single.json new file mode 100644 index 0000000000..a1843c2c8e --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-single.json @@ -0,0 +1,31 @@ +[ + { + "matrix": [ + { "783e6dbb-ea0e-411f-94e2-717eaad438bf": { + "mdev_type": "vfio_ap-passthrough", + "start": "manual", + "attrs": [ + { + "assign_adapter": "5" + }, + { + "assign_adapter": "6" + }, + { + "assign_domain": "0xab" + }, + { + "assign_control_domain": "0xab" + }, + { + "assign_domain": "4" + }, + { + "assign_control_domain": "4" + } + ] + } + } + ] + } +] diff --git a/tests/nodedevmdevctldata/mdevctl-list-single.out.xml b/tests/n= odedevmdevctldata/mdevctl-list-single.out.xml new file mode 100644 index 0000000000..cb443346ef --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-single.out.xml @@ -0,0 +1,14 @@ + + mdev_783e6dbb_ea0e_411f_94e2_717eaad438bf + matrix + + + + + + + + + + + diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index d75dfb1d3e..cee0d913dd 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -143,6 +143,88 @@ testMdevctlStop(const void *data) return ret; } =20 +static int +testMdevctlListDefined(const void *data G_GNUC_UNUSED) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + const char *actualCmdline =3D NULL; + int ret =3D -1; + g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *output =3D NULL; + g_autofree char *cmdlinefile =3D + g_strdup_printf("%s/nodedevmdevctldata/mdevctl-list-defined.argv", + abs_srcdir); + + cmd =3D nodeDeviceGetMdevctlListCommand(true, &output); + + 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 int +testMdevctlParse(const void *data) +{ + g_autofree char *buf =3D NULL; + const char *filename =3D data; + g_autofree char *jsonfile =3D g_strdup_printf("%s/nodedevmdevctldata/%= s.json", + abs_srcdir, filename); + g_autofree char *xmloutfile =3D g_strdup_printf("%s/nodedevmdevctldata= /%s.out.xml", + abs_srcdir, filename); + g_autofree char *actualxml =3D NULL; + int ret =3D -1; + int nmdevs =3D 0; + virNodeDeviceDefPtr *mdevs =3D NULL; + virBuffer xmloutbuf =3D VIR_BUFFER_INITIALIZER; + size_t i; + + if (virFileReadAll(jsonfile, 1024*1024, &buf) < 0) { + VIR_TEST_DEBUG("Unable to read file %s", jsonfile); + return -1; + } + + if ((nmdevs =3D nodeDeviceParseMdevctlJSON(buf, &mdevs)) < 0) { + VIR_TEST_DEBUG("Unable to parse json for %s", filename); + return -1; + } + + for (i =3D 0; i < nmdevs; i++) { + g_autofree char *devxml =3D virNodeDeviceDefFormat(mdevs[i]); + if (!devxml) + goto cleanup; + virBufferAddStr(&xmloutbuf, devxml); + } + + if (nodedevCompareToFile(virBufferCurrentContent(&xmloutbuf), xmloutfi= le) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&xmloutbuf); + for (i =3D 0; i < nmdevs; i++) + virNodeDeviceDefFree(mdevs[i]); + g_free(mdevs); + + return ret; +} + static void nodedevTestDriverFree(virNodeDeviceDriverStatePtr drv) { @@ -284,6 +366,15 @@ mymain(void) #define DO_TEST_STOP(uuid) \ DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid) =20 +#define DO_TEST_LIST_DEFINED() \ + do { \ + if (virTestRun("mdevctl list --defined", testMdevctlListDefined, N= ULL) < 0) \ + ret =3D -1; \ + } while (0) + +#define DO_TEST_PARSE_JSON(filename) \ + DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filenam= e) + /* Test mdevctl start commands */ DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); DO_TEST_START("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); @@ -292,6 +383,13 @@ mymain(void) /* Test mdevctl stop command, pass an arbitrary uuid */ DO_TEST_STOP("e2451f73-c95b-4124-b900-e008af37c576"); =20 + DO_TEST_LIST_DEFINED(); + + DO_TEST_PARSE_JSON("mdevctl-list-single"); + DO_TEST_PARSE_JSON("mdevctl-list-single-noattr"); + DO_TEST_PARSE_JSON("mdevctl-list-multiple"); + DO_TEST_PARSE_JSON("mdevctl-list-multiple-parents"); + done: nodedevTestDriverFree(driver); =20 --=20 2.26.2 From nobody Thu May 2 03:10:53 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=1597762108; cv=none; d=zohomail.com; s=zohoarc; b=kDHyRdYe5mkySQAJToKPG5vMJTeoZ3dpEqPks1gQoYPHHJvW8P+gh0dNoejRW9bb7pmYPuf6Ymx7HqkdNo0fgHMffBxJm95xZoEy14mQjFiYUjgfwARRKa++CRkV8A9KCHg03wvuOmTtbOLmrvbxrqz8hWBABdPehPMBBtFn61I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762108; 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=/lRuz6rB1Dq4j9GzIqvpYKSmJZWsdyKUlSkOqvzxIZw=; b=glOt3i2pPnFwM369uA7q5c3jJTur18NiopTx0Y8+owges6qY/T+ySrUNM/D9JcibC/baJNeaUCO1aGi25idWAB+tVCqXjqsrxm8HVJslXtFsjrnKlKAGA5fGXaMWAZNuos3F2XKhR2uKKsn1BZz/HVw5rZhqK62tU1OAeXb38tw= 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 1597762108640427.4128415750796; Tue, 18 Aug 2020 07:48: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-469-CfxCinIyPZW0TN6I55sD2g-1; Tue, 18 Aug 2020 10:48: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 E529C1DDF4; Tue, 18 Aug 2020 14:48: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 BD2C9165D8; Tue, 18 Aug 2020 14:48: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 7A82A181A06D; Tue, 18 Aug 2020 14:48:17 +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 07IEmCEl002753 for ; Tue, 18 Aug 2020 10:48:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 606575D757; Tue, 18 Aug 2020 14:48:12 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 240795D6BD; Tue, 18 Aug 2020 14:48:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762107; 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=/lRuz6rB1Dq4j9GzIqvpYKSmJZWsdyKUlSkOqvzxIZw=; b=XJ+7Koz2iWoemOB6Uz10Zsn8xmfJvjjRk+yRs4imAo420g/Yp6pAmHaPGs9aIRje2HHAdO 0Efy9G1guxr3wFb3HgtDpSbEAxQKUK1g6JVv1SIH4AD4oLDU+4PJqxxIRrfdz0n4w/+o7K xUoyq1m0ePpDDa/6uNeazEcMPD61p50= X-MC-Unique: CfxCinIyPZW0TN6I55sD2g-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 06/16] nodedev: add STOPPED/STARTED lifecycle events Date: Tue, 18 Aug 2020 09:47:56 -0500 Message-Id: <20200818144806.134738-7-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Since a mediated device can be persistently defined by the mdevctl backend, we need additional lifecycle events beyond CREATED/DELETED to indicate that e.g. the device has been stopped but the device definition still exists. Signed-off-by: Jonathon Jongsma --- examples/c/misc/event-test.c | 4 ++++ include/libvirt/libvirt-nodedev.h | 2 ++ src/conf/node_device_conf.h | 1 + src/node_device/node_device_driver.c | 1 + src/node_device/node_device_udev.c | 25 +++++++++++++++++++++++-- tools/virsh-nodedev.c | 4 +++- 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c index 52caa8ffa8..c40819969c 100644 --- a/examples/c/misc/event-test.c +++ b/examples/c/misc/event-test.c @@ -381,6 +381,10 @@ nodeDeviceEventToString(int event) return "Created"; case VIR_NODE_DEVICE_EVENT_DELETED: return "Deleted"; + case VIR_NODE_DEVICE_EVENT_STOPPED: + return "Stopped"; + case VIR_NODE_DEVICE_EVENT_STARTED: + return "Started"; case VIR_NODE_DEVICE_EVENT_LAST: break; } diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 98a972e60d..423a583d45 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -192,6 +192,8 @@ int virConnectNodeDeviceEventDeregisterAny(virConnectPt= r conn, typedef enum { VIR_NODE_DEVICE_EVENT_CREATED =3D 0, VIR_NODE_DEVICE_EVENT_DELETED =3D 1, + VIR_NODE_DEVICE_EVENT_STOPPED =3D 2, + VIR_NODE_DEVICE_EVENT_STARTED =3D 3, =20 # ifdef VIR_ENUM_SENTINELS VIR_NODE_DEVICE_EVENT_LAST diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 353dbebaf0..7e825ca6a9 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -144,6 +144,7 @@ struct _virNodeDevCapMdev { char *uuid; virMediatedDeviceAttrPtr *attributes; size_t nattributes; + bool persistent; }; =20 typedef struct _virNodeDevCapPCIDev virNodeDevCapPCIDev; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 3b042e9a45..b47ecba10a 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -894,6 +894,7 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring, child->caps->data.type =3D VIR_NODE_DEV_CAP_MDEV; =20 mdev =3D &child->caps->data.mdev; + mdev->persistent =3D true; mdev->uuid =3D g_strdup(uuid); mdev->type =3D g_strdup(virJSONValueObjectGetString(props, "mdev_type= ")); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 93b74b1f24..ac7986bc70 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1213,6 +1213,8 @@ udevRemoveOneDeviceSysPath(const char *path) virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr def; virObjectEventPtr event =3D NULL; + virNodeDevCapsDefPtr cap; + int event_type =3D VIR_NODE_DEVICE_EVENT_DELETED; =20 if (!(obj =3D virNodeDeviceObjListFindBySysfsPath(driver->devs, path))= ) { VIR_DEBUG("Failed to find device to remove that has udev path '%s'= ", @@ -1221,13 +1223,32 @@ udevRemoveOneDeviceSysPath(const char *path) } def =3D virNodeDeviceObjGetDef(obj); =20 + /* If the device is a mediated device that has been 'stopped', it may = still + * be defined by mdevctl and can therefore be started again. Don't dro= p it + * from the list of node devices */ + cap =3D def->caps; + while (cap !=3D NULL) { + if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) { + if (cap->data.mdev.persistent) { + VIR_FREE(def->sysfs_path); + event_type =3D VIR_NODE_DEVICE_EVENT_STOPPED; + break; + } + } + cap =3D cap->next; + } + event =3D virNodeDeviceEventLifecycleNew(def->name, - VIR_NODE_DEVICE_EVENT_DELETED, + event_type, 0); =20 VIR_DEBUG("Removing device '%s' with sysfs path '%s'", def->name, path); - virNodeDeviceObjListRemove(driver->devs, obj); + + if (event_type =3D=3D VIR_NODE_DEVICE_EVENT_DELETED) + virNodeDeviceObjListRemove(driver->devs, obj); + else + virNodeDeviceObjSetActive(obj, false); virNodeDeviceObjEndAPI(&obj); =20 virObjectEventStateQueue(driver->nodeDeviceEventState, event); diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index e87761188f..f078ce6516 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -787,7 +787,9 @@ VIR_ENUM_DECL(virshNodeDeviceEvent); VIR_ENUM_IMPL(virshNodeDeviceEvent, VIR_NODE_DEVICE_EVENT_LAST, N_("Created"), - N_("Deleted")); + N_("Deleted"), + N_("Stopped"), + N_("Started")); =20 static const char * virshNodeDeviceEventToString(int event) --=20 2.26.2 From nobody Thu May 2 03:10:53 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=1597762117; cv=none; d=zohomail.com; s=zohoarc; b=Qf3OCuhvehrWbLF8ttAAUIOO1VXgudkhJx6TdiEuvHeq4/GNaoWHZiQk2z0u/NBgX5bZeGE8wgRCV/5SC0YNUF9LDkonQeuTdB4OS5atAu/fHkBdDJd5xJxyaD/ZJmVnHb1aaq2TgpCkvJubvgnJvAplX17dgD5geh7wmOYQtec= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762117; 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=FqmoN36KdIPUEigRfXdFEqWecbECSBWhTmdc5pas1AQ=; b=FIkZtvZ2xvuSj+608GwNx5MoztuEaSLwKpyZJ6/t5x+QuC3J+63CmjXIjKZJKgq9mxFvHeQKUJjVVxex9C17FkHyVNIGKR8XELsPY9unw1XQtei7wF/HERdAKzA7tSQkbfuMSHEMGlm1tTPUZ6S9PfjF3WbkSyVv+cQLpyHq5zA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1597762117452725.0139822504055; Tue, 18 Aug 2020 07:48:37 -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-84-gYddtTWjMDSWd1Oys8dGVQ-1; Tue, 18 Aug 2020 10:48:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C4F3100CF72; Tue, 18 Aug 2020 14:48:27 +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 C39A9196B6; Tue, 18 Aug 2020 14:48: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 8E3EF181A07B; Tue, 18 Aug 2020 14:48: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 07IEmCa8002762 for ; Tue, 18 Aug 2020 10:48:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id B8AD15D6BD; Tue, 18 Aug 2020 14:48:12 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C6A57DFC2; Tue, 18 Aug 2020 14:48:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762116; 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=FqmoN36KdIPUEigRfXdFEqWecbECSBWhTmdc5pas1AQ=; b=CYpgtva1m1ytPqbKkEy/8H9oM8a2z873v4ssDQvQVtl53t5aaxFdCQkJpHyf5KTHopMLSq WgAgWoeuyjF9Dtmf0k67SjlEeLqUUAQgApdbBkDosNgQax9+oxfwDGjtzOvbdvuKvTE+El K7GF5uduxQYvk4/dh1Puf6hN8mlwDTY= X-MC-Unique: gYddtTWjMDSWd1Oys8dGVQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 07/16] nodedev: add mdevctl devices to node device list Date: Tue, 18 Aug 2020 09:47:57 -0500 Message-Id: <20200818144806.134738-8-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" At startup, query devices that are defined by 'mdevctl' and add them to the node device list. This adds a complication: we now have two potential sources of information for a node device: - udev for all devices and for activated mediated devices - mdevctl for persistent mediated devices Unfortunately, neither backend returns full information for a mediated device. For example, if a persistent mediated device in the list (with information provided from mdevctl) is 'started', that same device will now be detected by udev. If we simply overwrite the existing device definition with the new one provided by the udev backend, we will lose extra information that was provided by mdevctl (e.g. attributes, etc). To avoid this, make sure to copy the extra information into the new device definition. Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_driver.c | 76 ++++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 3 ++ src/node_device/node_device_udev.c | 43 ++++++++++++++++ 3 files changed, 122 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index b47ecba10a..349426757e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1088,3 +1088,79 @@ nodeDeviceGenerateName(virNodeDeviceDefPtr def, *(def->name + i) =3D '_'; } } + + +static int +virMdevctlListDefined(virNodeDeviceDefPtr **devs) +{ + int status; + g_autofree char *output =3D NULL; + g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlListCommand(true, &o= utput); + + if (virCommandRun(cmd, &status) < 0) + return -1; + + if (!output) + return -1; + + return nodeDeviceParseMdevctlJSON(output, devs); +} + + +int +mdevctlEnumerateDevices(void) +{ + g_autofree virNodeDeviceDefPtr *devs =3D NULL; + int ndevs; + size_t i; + + if ((ndevs =3D virMdevctlListDefined(&devs)) < 0) { + virReportSystemError(errno, "%s", + _("failed to query mdevs from mdevctl")); + return -1; + } + + for (i =3D 0; i < ndevs; i++) { + virNodeDeviceObjPtr obj; + virObjectEventPtr event; + virNodeDeviceDefPtr dev =3D devs[i]; + + dev->driver =3D g_strdup("vfio_mdev"); + + /* If a device defined by mdevctl is already in the list, that mea= ns + * that it was found via the normal device discovery process and t= hus + * is already activated. Active devices contain some additional + * information (e.g. sysfs path) that is not provided by mdevctl, = so + * preserve that info */ + bool new_device =3D true; + if ((obj =3D virNodeDeviceObjListFindByName(driver->devs, dev->nam= e))) { + virNodeDeviceDefPtr olddef =3D virNodeDeviceObjGetDef(obj); + + /* Copy any data from the existing device */ + dev->sysfs_path =3D g_strdup(olddef->sysfs_path); + dev->parent_sysfs_path =3D g_strdup(olddef->parent_sysfs_path); + dev->driver =3D g_strdup(olddef->driver); + dev->devnode =3D g_strdup(olddef->devnode); + dev->caps->data.mdev.iommuGroupNumber =3D olddef->caps->data.m= dev.iommuGroupNumber; + + virNodeDeviceObjEndAPI(&obj); + new_device =3D false; + } + + if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, dev))) { + virNodeDeviceDefFree(dev); + return -1; + } + + if (new_device) + event =3D virNodeDeviceEventLifecycleNew(dev->name, + VIR_NODE_DEVICE_EVENT_C= REATED, + 0); + else + event =3D virNodeDeviceEventUpdateNew(dev->name); + virNodeDeviceObjEndAPI(&obj); + virObjectEventStateQueue(driver->nodeDeviceEventState, event); + } + + return 0; +} diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index e7317fd67a..b5c1da4ff3 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -131,6 +131,9 @@ int nodeDeviceParseMdevctlJSON(const char *jsonstring, virNodeDeviceDefPtr **devs); =20 +int +mdevctlEnumerateDevices(void); + void nodeDeviceGenerateName(virNodeDeviceDefPtr def, const char *subsystem, diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index ac7986bc70..e06584a3dc 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1306,6 +1306,45 @@ udevSetParent(struct udev_device *device, return 0; } =20 +static virMediatedDeviceAttrPtr * +virMediatedDeviceAttrsCopy(virMediatedDeviceAttrPtr *attrs, + size_t nattrs) +{ + size_t i; + size_t j =3D 0; + g_autofree virMediatedDeviceAttrPtr *ret =3D NULL; + + if (nattrs =3D=3D 0) + return NULL; + + if (VIR_ALLOC_N(ret, nattrs) < 0) + return NULL; + + for (i =3D 0; i < nattrs; i++) { + virMediatedDeviceAttrPtr attr =3D virMediatedDeviceAttrNew(); + attr->name =3D g_strdup(attrs[i]->name); + attr->value =3D g_strdup(attrs[i]->value); + VIR_APPEND_ELEMENT_INPLACE(ret, j, attr); + } + + return g_steal_pointer(ret); +} + +/* An existing device definition may have additional info from mdevctl tha= t is + * not available from udev. Transfer this data to the new definition */ +static void +nodeDeviceDefCopyExtraData(virNodeDeviceDefPtr dst, + virNodeDeviceDefPtr src) +{ + virNodeDevCapMdevPtr srcmdev =3D &src->caps->data.mdev; + virNodeDevCapMdevPtr dstmdev =3D &dst->caps->data.mdev; + + dstmdev->persistent =3D srcmdev->persistent; + dstmdev->nattributes =3D srcmdev->nattributes; + dstmdev->attributes =3D virMediatedDeviceAttrsCopy(srcmdev->attributes, + srcmdev->nattributes); +} + =20 static int udevAddOneDevice(struct udev_device *device) @@ -1341,6 +1380,8 @@ udevAddOneDevice(struct udev_device *device) goto cleanup; =20 if ((obj =3D virNodeDeviceObjListFindByName(driver->devs, def->name)))= { + nodeDeviceDefCopyExtraData(def, virNodeDeviceObjGetDef(obj)); + virNodeDeviceObjEndAPI(&obj); new_device =3D false; } @@ -1773,6 +1814,8 @@ nodeStateInitializeEnumerate(void *opaque) /* Populate with known devices */ if (udevEnumerateDevices(udev) !=3D 0) goto error; + if (mdevctlEnumerateDevices() !=3D 0) + goto error; =20 nodeDeviceLock(); driver->initialized =3D true; --=20 2.26.2 From nobody Thu May 2 03:10:53 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=1597762154; cv=none; d=zohomail.com; s=zohoarc; b=XTaWrkzUfICBjKFMbuHwCqWn4gim0RwACGS0R9UwSrNpGmKSj2FZLH3wE2MvzNF51SsSzx8ZaKwqfdm9GpSygBW0jsnn2evIE9P1XSRi39wxapr96mVeinwFvh1YZDRVGDPRD3azpmLC9Q4DqMHLwhN5GNvM11ep1pih1Pwscco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762154; 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=ULe1pEjIBJ5NpX/nyaw18uhHIpWTOHjTFfWOXZShdfQ=; b=nqyYHdJJSqHy/sxsbO1dJWUfZAWcX189PTE+fH2zVmTWFCe/L/WSq64FOFIWWuHlD0tQwb7ApwHTeDGMWoz2JUf6KfHuStyAMUrZRekxkac5CSL/6fUJuflNqUA2he3mtboOCUXoB86KjeOkrfz+88nRpBaix0I0tLjaGeAs41M= 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 159776215406369.1511916433866; Tue, 18 Aug 2020 07:49:14 -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-512-IoCS1u6KOjaLK_6aQBz2DQ-1; Tue, 18 Aug 2020 10:48:39 -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 0B0D381F030; Tue, 18 Aug 2020 14:48:32 +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 E03B97BE68; Tue, 18 Aug 2020 14:48:31 +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 A8714181A272; Tue, 18 Aug 2020 14:48:31 +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 07IEmDdg002772 for ; Tue, 18 Aug 2020 10:48:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1CCAB5D757; Tue, 18 Aug 2020 14:48:13 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4CF65D6BD; Tue, 18 Aug 2020 14:48:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762153; 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=ULe1pEjIBJ5NpX/nyaw18uhHIpWTOHjTFfWOXZShdfQ=; b=F1cu6MMEAF0l4Fy04A9NS+lmbOnQaNvp7r47CBZ4bsj6f9JrpOkEeWj1pl7JGE9nZ0K6y4 +1aUg7NKvJ9C4NS+LeX3XHuTiO5W0o7W7m47+qj9AoRf4aPP1jdR7NL2Rifh+I052cgYjd 0QNEUHnsVBg+8Un6TY67SKMdhYwmpFI= X-MC-Unique: IoCS1u6KOjaLK_6aQBz2DQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 08/16] nodedev: handle mdevs that disappear from mdevctl Date: Tue, 18 Aug 2020 09:47:58 -0500 Message-Id: <20200818144806.134738-9-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" mdevctl does not currently provide any events when the list of defined devices changes, so we will need to poll mdevctl for the list of defined devices periodically. When a mediated device no longer exists from one iteration to the next, we need to treat it as an "undefine" event. When we get such an event, we remove the device from the list if it's not active. Otherwise, we simply mark it as non-persistent. Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_driver.c | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 349426757e..affd707a65 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1089,6 +1089,37 @@ nodeDeviceGenerateName(virNodeDeviceDefPtr def, } } =20 +static bool +mdevMatchPersistentDevices(virConnectPtr conn G_GNUC_UNUSED, + virNodeDeviceDefPtr def) +{ + return (def->caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV && + def->caps->data.mdev.persistent); + + +} + +/* returns a null-terminated array of strings. Free with virStringListFree= () */ +static char ** +nodeDeviceGetMdevPersistentDevices(virNodeDeviceObjListPtr devlist) +{ + char **ret =3D NULL; + int ndevs =3D virNodeDeviceObjListNumOfDevices(devlist, + NULL, + "mdev", + mdevMatchPersistentDevice= s); + if (VIR_ALLOC_N(ret, ndevs+1) < 0) + return NULL; + + if (virNodeDeviceObjListGetNames(devlist, NULL, + mdevMatchPersistentDevices, + "mdev", + ret, + ndevs) < 0) + VIR_FREE(ret); + + return ret; +} =20 static int virMdevctlListDefined(virNodeDeviceDefPtr **devs) @@ -1113,6 +1144,7 @@ mdevctlEnumerateDevices(void) g_autofree virNodeDeviceDefPtr *devs =3D NULL; int ndevs; size_t i; + char **oldmdevs =3D nodeDeviceGetMdevPersistentDevices(driver->devs); =20 if ((ndevs =3D virMdevctlListDefined(&devs)) < 0) { virReportSystemError(errno, "%s", @@ -1160,7 +1192,36 @@ mdevctlEnumerateDevices(void) event =3D virNodeDeviceEventUpdateNew(dev->name); virNodeDeviceObjEndAPI(&obj); virObjectEventStateQueue(driver->nodeDeviceEventState, event); + + virStringListRemove(&oldmdevs, dev->name); + } + + /* Any mdevs that were previously defined but were not returned by mde= vctl + * this time will need to be checked to see if they should be removed = from + * the device list */ + for (i =3D 0; i < virStringListLength((const char **)oldmdevs); i++) { + const char *name =3D oldmdevs[i]; + virNodeDeviceObjPtr obj =3D NULL; + if ((obj =3D virNodeDeviceObjListFindByName(driver->devs, name))) { + if (!virNodeDeviceObjIsActive(obj)) { + /* An existing device is not active and is no longer defin= ed by + * mdevctl, so remove it */ + virObjectEventPtr event =3D virNodeDeviceEventLifecycleNew= (name, + V= IR_NODE_DEVICE_EVENT_DELETED, + 0= ); + + virNodeDeviceObjListRemove(driver->devs, obj); + virObjectEventStateQueue(driver->nodeDeviceEventState, eve= nt); + } else { + /* An existing device is active, but no longer defined. Ke= ep + * the device in the list, but mark it as non-persistent */ + virNodeDeviceDefPtr def =3D virNodeDeviceObjGetDef(obj); + def->caps->data.mdev.persistent =3D false; + } + virNodeDeviceObjEndAPI(&obj); + } } + g_strfreev(oldmdevs); =20 return 0; } --=20 2.26.2 From nobody Thu May 2 03:10:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597762124; cv=none; d=zohomail.com; s=zohoarc; b=VdpQPssfl93IFyYcKHCqC/l4FhR4tSDZCWjAZpXHfkTUCPrcJ96ZFPMjGBEtrtzQep554MOl42mH+NVUYx4YK+MOBzr0iq4FCLsABdayz338aK9NEmy57Q2OquOjjUW7kwFWuxxrO/RgY/dClnSTQwFMoxoeatmCx+RJYV75vQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762124; 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=eTzgXA0ZMxft+b6yoCQDzN0MC+N4yDUgR6+wnZZUuio=; b=icdi280qWZPD8GULQJreLPPlXdCfUI+EMfVa7RP+EG5+WqGehhKUM93jKnrN8VKRIAZZwZYbIzwcN4tQlOXFjXHUXTJ0oSLTOTR0mNGC+QCdooirNe08KEyFa93yvLVPpOLdUyiz001wIRwJMQWDMmGy+hADdlLPNFcwcHvEi30= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1597762124442217.41760280118808; Tue, 18 Aug 2020 07:48:44 -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-512-QEHf1rgXNs247ct9XuSyJA-1; Tue, 18 Aug 2020 10:48:41 -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 3544681F025; Tue, 18 Aug 2020 14:48:32 +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 133635D9E8; Tue, 18 Aug 2020 14:48:32 +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 CF7A4181A2E6; Tue, 18 Aug 2020 14:48:31 +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 07IEmDIc002795 for ; Tue, 18 Aug 2020 10:48:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 76DDA5D6BD; Tue, 18 Aug 2020 14:48:13 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A6247DFC2; Tue, 18 Aug 2020 14:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762123; 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=eTzgXA0ZMxft+b6yoCQDzN0MC+N4yDUgR6+wnZZUuio=; b=eVFRE6ObC/VKm4cJsM5If8EWNsGK6gWvjGPqyDdryRHgh/oOzuKE1Tgy2D37l7pqXOMGqr i4gIgg07DmVU5rbtwftrXP5PVOLFqZeGtGyJkwSBEgnIFTsw1lJ/7RDyOBKi0VYCb97aCh kfo+s80wUtZt4ogzK7df7qNlEOY8QTk= X-MC-Unique: QEHf1rgXNs247ct9XuSyJA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 09/16] nodedev: add an mdevctl thread Date: Tue, 18 Aug 2020 09:47:59 -0500 Message-Id: <20200818144806.134738-10-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.003 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We need to peridocally query mdevctl for changes to device definitions since an administrator can define new devices with mdevctl outside of libvirt. In order to do this, a new thread is created to handle the querying. In the future, mdevctl may add a way to signal device add / remove via events, but for now we resort to a bit of a workaround: monitoring the mdevctl config directories for changes to files. When a change is detected, we query mdevctl and update our device list. Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 182 +++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index e06584a3dc..a85418e549 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -41,6 +41,7 @@ #include "virnetdev.h" #include "virmdev.h" #include "virutil.h" +#include =20 #include "configmake.h" =20 @@ -66,6 +67,11 @@ struct _udevEventData { virCond threadCond; bool threadQuit; bool dataReady; + + virThread mdevctlThread; + virCond mdevctlCond; + bool mdevctlReady; + GList *mdevctl_monitors; }; =20 static virClassPtr udevEventDataClass; @@ -85,8 +91,10 @@ udevEventDataDispose(void *obj) udev =3D udev_monitor_get_udev(priv->udev_monitor); udev_monitor_unref(priv->udev_monitor); udev_unref(udev); + g_list_free_full(priv->mdevctl_monitors, g_object_unref); =20 virCondDestroy(&priv->threadCond); + virCondDestroy(&priv->mdevctlCond); } =20 =20 @@ -117,6 +125,11 @@ udevEventDataNew(void) return NULL; } =20 + if (virCondInit(&ret->mdevctlCond) < 0) { + virObjectUnref(ret); + return NULL; + } + ret->watch =3D -1; return ret; } @@ -1520,6 +1533,7 @@ nodeStateCleanup(void) virObjectLock(priv); priv->threadQuit =3D true; virCondSignal(&priv->threadCond); + virCondSignal(&priv->mdevctlCond); virObjectUnlock(priv); virThreadJoin(&priv->th); } @@ -1601,6 +1615,40 @@ udevEventMonitorSanityCheck(udevEventDataPtr priv, } =20 =20 +/* Thread to query mdevctl for the current state of persistent mediated de= vice + * defintions when any changes are detected */ +static +void mdevctlThread(void *opaque G_GNUC_UNUSED) +{ + udevEventDataPtr priv =3D driver->privateData; + + while (1) { + virObjectLock(priv); + while (!priv->mdevctlReady && !priv->threadQuit) { + if (virCondWait(&priv->mdevctlCond, &priv->parent.lock)) { + virReportSystemError(errno, "%s", + _("handler failed to wait on conditio= n")); + virObjectUnlock(priv); + return; + } + } + + if (priv->threadQuit) { + virObjectUnlock(priv); + return; + } + + virObjectUnlock(priv); + + mdevctlEnumerateDevices(); + + virObjectLock(priv); + priv->mdevctlReady =3D false; + virObjectUnlock(priv); + } +} + + /** * udevEventHandleThread * @opaque: unused @@ -1708,6 +1756,69 @@ udevEventHandleCallback(int watch G_GNUC_UNUSED, } =20 =20 +static int timeout_id; + +static gboolean +signalMdevctlThread(void *user_data) +{ + udevEventDataPtr priv =3D user_data; + + if (timeout_id) { + g_source_remove(timeout_id); + timeout_id =3D 0; + } + + virObjectLock(priv); + priv->mdevctlReady =3D true; + virCondSignal(&priv->mdevctlCond); + virObjectUnlock(priv); + + return G_SOURCE_REMOVE; +} + + +static void +mdevctlEventHandleCallback(GFileMonitor *monitor G_GNUC_UNUSED, + GFile *file, + GFile *other_file G_GNUC_UNUSED, + GFileMonitorEvent event_type, + gpointer user_data) +{ + udevEventDataPtr priv =3D user_data; + + /* if a new directory appears, monitor that directory for changes */ + if (g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL) =3D=3D + G_FILE_TYPE_DIRECTORY) { + GFileMonitor *mon; + + if ((mon =3D g_file_monitor(file, G_FILE_MONITOR_NONE, NULL, NULL)= )) { + g_signal_connect(mon, "changed", + G_CALLBACK(mdevctlEventHandleCallback), + user_data); + virObjectLock(priv); + priv->mdevctl_monitors =3D g_list_append(priv->mdevctl_monitor= s, mon); + virObjectUnlock(priv); + } + } + + /* Sometimes a single configuration change results in multiple notify + * events (e.g. several CHANGED events, or a CREATED and CHANGED event + * followed by CHANGES_DONE_HINT). To avoid triggering the mdevctl th= read + * multiple times for a single configuration change, try to coalesce t= hese + * changes by waiting for the CHANGES_DONE_HINT event. As a fallback, = add + * a timeout to trigger the signal if that event never comes */ + if (event_type =3D=3D G_FILE_MONITOR_EVENT_CREATED || + event_type =3D=3D G_FILE_MONITOR_EVENT_CHANGED) { + if (timeout_id) + g_source_remove(timeout_id); + timeout_id =3D g_timeout_add(100, signalMdevctlThread, priv); + return; + } + + signalMdevctlThread(priv); +} + + /* DMI is intel-compatible specific */ #if defined(__x86_64__) || defined(__i386__) || defined(__amd64__) static void @@ -1858,6 +1969,58 @@ udevPCITranslateInit(bool privileged G_GNUC_UNUSED) } =20 =20 +/* Recursively monitors dir and any subdirectory for file changes and retu= rns a + * GList of GFileMonitor objects */ +static GList* +monitorDirRecursively(GFile *dir, + GCallback changed_cb, + gpointer user_data) +{ + GList *monitors =3D NULL; + g_autoptr(GFileInfo) dirinfo =3D NULL; + g_autoptr(GError) error =3D NULL; + g_autoptr(GFileEnumerator) children =3D NULL; + GFileMonitor *mon; + + if (!(children =3D g_file_enumerate_children(dir, "standard::*", + G_FILE_QUERY_INFO_NONE, NUL= L, &error))) { + if (error->code =3D=3D G_IO_ERROR_NOT_DIRECTORY) + return NULL; + goto bail; + } + + if (!(mon =3D g_file_monitor(dir, G_FILE_MONITOR_NONE, NULL, &error))) + goto bail; + + g_signal_connect(mon, "changed", changed_cb, user_data); + monitors =3D g_list_append(monitors, mon); + + while (true) { + GFileInfo *info; + GFile *child; + GList *child_monitors =3D NULL; + + if (!g_file_enumerator_iterate(children, &info, &child, NULL, &err= or)) + goto bail; + if (!info) + break; + + child_monitors =3D monitorDirRecursively(child, changed_cb, user_d= ata); + if (child_monitors) + monitors =3D g_list_concat(monitors, child_monitors); + } + + return monitors; + + bail: + if (error) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to monitor directory: %s"), error->messag= e); + + g_list_free_full(monitors, g_object_unref); + return NULL; +} + static int nodeStateInitialize(bool privileged, const char *root, @@ -1867,6 +2030,8 @@ nodeStateInitialize(bool privileged, udevEventDataPtr priv =3D NULL; struct udev *udev =3D NULL; virThread enumThread; + g_autoptr(GError) error =3D NULL; + g_autoptr(GFile) mdevctlConfigDir =3D g_file_new_for_path("/etc/mdevct= l.d"); =20 if (root !=3D NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -1969,6 +2134,23 @@ nodeStateInitialize(bool privileged, if (priv->watch =3D=3D -1) goto unlock; =20 + if (virThreadCreateFull(&priv->mdevctlThread, true, mdevctlThread, + "mdevctl-event", false, NULL) < 0) { + virReportSystemError(errno, "%s", + _("failed to create mdevctl handler thread")); + goto unlock; + } + + /* mdevctl may add notification events in the future: + * https://github.com/mdevctl/mdevctl/issues/27. For now, fall back to + * monitoring the mdevctl configuration directory for changes. + * mdevctl configuration is stored in a directory tree within + * /etc/mdevctl.d/. There is a directory for each parent device, which + * contains a file defining each mediated device */ + priv->mdevctl_monitors =3D monitorDirRecursively(mdevctlConfigDir, + G_CALLBACK(mdevctlEvent= HandleCallback), + priv); + virObjectUnlock(priv); =20 /* Create a fictional 'computer' device to root the device tree. */ --=20 2.26.2 From nobody Thu May 2 03:10:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597762124; cv=none; d=zohomail.com; s=zohoarc; b=ccO6/vx+Su72XDNsZ+hNJEYPYEACKIdki8KwJ5VbgF1ER0qzyISpG98punRzt1TPVc3kvbGlReFwgczu6mVoMygPhWthltvr7O4mWb6A6U1tzdWVQrfGfPD/NbkMCuayrE7GRPZrd+/dc6YxboA36/+CmdXvEUw9ttFA7pfGPOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762124; 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=antHtu4OqXSmXpp53kD8G8oySEpePqjpDthGZxPvDuA=; b=e7Ad4V6DOTsNTiXs9au7U1js0NdpuDUmRenRzbO/Y/P7b2NsEgNkkuDd4qXfeFs4eHnRscvglVpSoyOlj7I+EF09eE+S0NNX7lQMbWdrRexw2miIUq7NKCz9AK0pskmumTBqyq8wmnQM54Sc17DyKVnwS/sSyJz9NvGdlvMdCv8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1597762124255383.5767716289753; Tue, 18 Aug 2020 07:48:44 -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-556-B2mT7m2YMqmrIvhV5EO8HA-1; Tue, 18 Aug 2020 10:48:41 -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 B1FE61006713; Tue, 18 Aug 2020 14:48:34 +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 8E2465C70C; Tue, 18 Aug 2020 14:48:34 +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 5A8B760377; Tue, 18 Aug 2020 14:48:34 +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 07IEmD84002800 for ; Tue, 18 Aug 2020 10:48:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id DF31E5D757; Tue, 18 Aug 2020 14:48:13 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 94BE35D6BD; Tue, 18 Aug 2020 14:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762123; 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=antHtu4OqXSmXpp53kD8G8oySEpePqjpDthGZxPvDuA=; b=Y1EnaZNIWkp+R/nvnEuVMbuvZtvRj/7C7t9hmADo1hnJuNA9TU4++kSpb8IRxtYpVi+ww5 7oOdqsikO+jM9v61ZhQLuBXptA5wREe4DstWLvO7jVWGnCxsVDP2CRg63AxWz59c9mKbIX 5Xf5an5ki8R+q74e1j9vLxjIlGc4hO0= X-MC-Unique: B2mT7m2YMqmrIvhV5EO8HA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 10/16] api: add virNodeDeviceDefineXML() Date: Tue, 18 Aug 2020 09:48:00 -0500 Message-Id: <20200818144806.134738-11-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.002 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 mediated devices, we can now define persistent node devices that can be started and stopped. In order to take advantage of this, we need an API to define new node devices. Signed-off-by: Jonathon Jongsma --- include/libvirt/libvirt-nodedev.h | 4 + src/driver-nodedev.h | 6 ++ src/libvirt-nodedev.c | 42 ++++++++ src/libvirt_public.syms | 4 + src/node_device/node_device_driver.c | 97 +++++++++++++++++-- src/node_device/node_device_driver.h | 10 ++ src/node_device/node_device_udev.c | 1 + src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 18 +++- src/remote_protocol-structs | 8 ++ src/rpc/gendispatch.pl | 1 + ...19_36ea_4111_8f0a_8c9a70e21366-define.argv | 1 + ...19_36ea_4111_8f0a_8c9a70e21366-define.json | 1 + ...39_495e_4243_ad9f_beb3f14c23d9-define.argv | 1 + ...39_495e_4243_ad9f_beb3f14c23d9-define.json | 1 + ...16_1ca8_49ac_b176_871d16c13076-define.argv | 1 + ...16_1ca8_49ac_b176_871d16c13076-define.json | 1 + tests/nodedevmdevctltest.c | 68 +++++++++---- 18 files changed, 241 insertions(+), 25 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8= c9a70e21366-define.argv create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8= c9a70e21366-define.json create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_b= eb3f14c23d9-define.argv create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_b= eb3f14c23d9-define.json create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_8= 71d16c13076-define.argv create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_8= 71d16c13076-define.json diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 423a583d45..02aa9d9750 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -127,6 +127,10 @@ virNodeDevicePtr virNodeDeviceCreateXML (virCo= nnectPtr conn, =20 int virNodeDeviceDestroy (virNodeDevicePtr dev); =20 +virNodeDevicePtr virNodeDeviceDefineXML (virConnectPtr conn, + const char *xmlDesc, + unsigned int flags); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h index d0fc7f19cf..16d787f3fc 100644 --- a/src/driver-nodedev.h +++ b/src/driver-nodedev.h @@ -74,6 +74,11 @@ typedef virNodeDevicePtr typedef int (*virDrvNodeDeviceDestroy)(virNodeDevicePtr dev); =20 +typedef virNodeDevicePtr +(*virDrvNodeDeviceDefineXML)(virConnectPtr conn, + const char *xmlDesc, + unsigned int flags); + typedef int (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn, virNodeDevicePtr dev, @@ -113,4 +118,5 @@ struct _virNodeDeviceDriver { virDrvNodeDeviceListCaps nodeDeviceListCaps; virDrvNodeDeviceCreateXML nodeDeviceCreateXML; virDrvNodeDeviceDestroy nodeDeviceDestroy; + virDrvNodeDeviceDefineXML nodeDeviceDefineXML; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index 6dc61304a0..1704de929e 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -761,6 +761,48 @@ virNodeDeviceDestroy(virNodeDevicePtr dev) } =20 =20 +/** + * virNodeDeviceDefineXML: + * @conn: pointer to the hypervisor connection + * @xmlDesc: string containing an XML description of the device to be defi= ned + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Define a new device on the VM host machine, for example, a mediated dev= ice + * + * virNodeDeviceFree should be used to free the resources after the + * node device object is no longer needed. + * + * Returns a node device object if successful, NULL in case of failure + */ +virNodeDevicePtr +virNodeDeviceDefineXML(virConnectPtr conn, + const char *xmlDesc, + unsigned int flags) +{ + VIR_DEBUG("conn=3D%p, xmlDesc=3D%s, flags=3D0x%x", conn, NULLSTR(xmlDe= sc), flags); + + virResetLastError(); + + virCheckConnectReturn(conn, NULL); + virCheckReadOnlyGoto(conn->flags, error); + virCheckNonNullArgGoto(xmlDesc, error); + + if (conn->nodeDeviceDriver && + conn->nodeDeviceDriver->nodeDeviceDefineXML) { + virNodeDevicePtr dev =3D conn->nodeDeviceDriver->nodeDeviceDefineX= ML(conn, xmlDesc, flags); + if (dev =3D=3D NULL) + goto error; + return dev; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return NULL; +} + + /** * virConnectNodeDeviceEventRegisterAny: * @conn: pointer to the connection diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 539d2e3943..27c637e37c 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -873,4 +873,8 @@ LIBVIRT_6.0.0 { virDomainBackupGetXMLDesc; } LIBVIRT_5.10.0; =20 +LIBVIRT_6.5.0 { + global: + virNodeDeviceDefineXML; +} LIBVIRT_6.0.0; # .... define new API here using predicted next version number .... diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index affd707a65..16f3537776 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -658,9 +658,13 @@ nodeDeviceFindAddressByName(const char *name) } =20 =20 -virCommandPtr -nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, - char **uuid_out) +/* the mdevctl 'start' and 'define' commands accept almost the exact same + * arguments, so provide a common implementation that can be wrapped by a = more + * specific function */ +static virCommandPtr +nodeDeviceGetMdevctlDefineStartCommand(virNodeDeviceDefPtr def, + const char *subcommand, + char **uuid_out) { virCommandPtr cmd; g_autofree char *json =3D NULL; @@ -678,7 +682,7 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr de= f, return NULL; } =20 - cmd =3D virCommandNewArgList(MDEVCTL, "start", + cmd =3D virCommandNewArgList(MDEVCTL, subcommand, "-p", parent_pci, "--jsonfile", "/dev/stdin", NULL); @@ -689,11 +693,29 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr = def, return cmd; } =20 +virCommandPtr +nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, + char **uuid_out) +{ + return nodeDeviceGetMdevctlDefineStartCommand(def, "start", uuid_out); +} + +virCommandPtr +nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDefPtr def, + char **uuid_out) +{ + return nodeDeviceGetMdevctlDefineStartCommand(def, "define", uuid_out); +} + + + static int -virMdevctlStart(virNodeDeviceDefPtr def, char **uuid) +virMdevctlDefineCommon(virNodeDeviceDefPtr def, + virCommandPtr (*func)(virNodeDeviceDefPtr, char**), + char **uuid) { int status; - g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlStartCommand(def, uu= id); + g_autoptr(virCommand) cmd =3D func(def, uuid); if (!cmd) return -1; =20 @@ -709,6 +731,20 @@ virMdevctlStart(virNodeDeviceDefPtr def, char **uuid) } =20 =20 +static int +virMdevctlStart(virNodeDeviceDefPtr def, char **uuid) +{ + return virMdevctlDefineCommon(def, nodeDeviceGetMdevctlStartCommand, u= uid); +} + + +static int +virMdevctlDefine(virNodeDeviceDefPtr def, char **uuid) +{ + return virMdevctlDefineCommon(def, nodeDeviceGetMdevctlDefineCommand, = uuid); +} + + static virNodeDevicePtr nodeDeviceCreateXMLMdev(virConnectPtr conn, virNodeDeviceDefPtr def) @@ -1008,6 +1044,55 @@ nodeDeviceDestroy(virNodeDevicePtr device) return ret; } =20 +virNodeDevicePtr +nodeDeviceDefineXML(virConnectPtr conn, + const char *xmlDesc, + unsigned int flags) +{ + g_autoptr(virNodeDeviceDef) def =3D NULL; + virNodeDevicePtr device =3D NULL; + const char *virt_type =3D NULL; + + virCheckFlags(0, NULL); + + if (nodeDeviceWaitInit() < 0) + return NULL; + + virt_type =3D virConnectGetType(conn); + + if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt= _type))) + return NULL; + + if (virNodeDeviceDefineXMLEnsureACL(conn, def) < 0) + return NULL; + + if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + g_autofree char *uuid =3D NULL; + + if (!def->parent) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("cannot define a mediated device without a pa= rent")); + return NULL; + } + + if (virMdevctlDefine(def, &uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to define mediated device")); + return NULL; + } + + def->caps->data.mdev.uuid =3D g_strdup(uuid); + mdevGenerateDeviceName(def); + device =3D nodeDeviceFindNewMediatedDevice(conn, uuid); + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + } + + return device; +} + + =20 int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index b5c1da4ff3..cf03e0b3cf 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -107,6 +107,11 @@ nodeDeviceCreateXML(virConnectPtr conn, int nodeDeviceDestroy(virNodeDevicePtr dev); =20 +virNodeDevicePtr +nodeDeviceDefineXML(virConnectPtr conn, + const char *xmlDesc, + unsigned int flags); + int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, virNodeDevicePtr dev, @@ -121,6 +126,11 @@ nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr = conn, virCommandPtr nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, char **uuid_out); + +virCommandPtr +nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDefPtr def, + char **uuid_out); + virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid); =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index a85418e549..5101fff146 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2198,6 +2198,7 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceListCaps =3D nodeDeviceListCaps, /* 0.7.3 */ .nodeDeviceCreateXML =3D nodeDeviceCreateXML, /* 0.7.3 */ .nodeDeviceDestroy =3D nodeDeviceDestroy, /* 0.7.3 */ + .nodeDeviceDefineXML =3D nodeDeviceDefineXML, /* 6.5.0 */ }; =20 =20 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 0331060a2d..64d0d0c49b 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8814,6 +8814,7 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceNumOfCaps =3D remoteNodeDeviceNumOfCaps, /* 0.5.0 */ .nodeDeviceListCaps =3D remoteNodeDeviceListCaps, /* 0.5.0 */ .nodeDeviceCreateXML =3D remoteNodeDeviceCreateXML, /* 0.6.3 */ + .nodeDeviceDefineXML =3D remoteNodeDeviceDefineXML, /* 6.5.0 */ .nodeDeviceDestroy =3D remoteNodeDeviceDestroy /* 0.6.3 */ }; =20 diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index d4393680e9..ddfdb9c084 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2139,6 +2139,15 @@ struct remote_node_device_destroy_args { remote_nonnull_string name; }; =20 +struct remote_node_device_define_xml_args { + remote_nonnull_string xml_desc; + unsigned int flags; +}; + +struct remote_node_device_define_xml_ret { + remote_nonnull_node_device dev; +}; + =20 /* * Events Register/Deregister: @@ -6664,5 +6673,12 @@ enum remote_procedure { * @priority: high * @acl: domain:read */ - REMOTE_PROC_DOMAIN_BACKUP_GET_XML_DESC =3D 422 + REMOTE_PROC_DOMAIN_BACKUP_GET_XML_DESC =3D 422, + + /** + * @generate: both + * @acl: node_device:write + * @acl: node_device:start + */ + REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 423 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index bae0f0b545..c325923eaf 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1600,6 +1600,13 @@ struct remote_node_device_create_xml_ret { struct remote_node_device_destroy_args { remote_nonnull_string name; }; +struct remote_node_device_define_xml_args { + remote_nonnull_string xml_desc; + u_int flags; +}; +struct remote_node_device_define_xml_ret { + remote_nonnull_node_device dev; +}; struct remote_connect_domain_event_register_ret { int cb_registered; }; @@ -3558,4 +3565,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_AGENT_SET_RESPONSE_TIMEOUT =3D 420, REMOTE_PROC_DOMAIN_BACKUP_BEGIN =3D 421, REMOTE_PROC_DOMAIN_BACKUP_GET_XML_DESC =3D 422, + REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 423, }; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 0b2ae59910..fa409fe3ab 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -567,6 +567,7 @@ elsif ($mode eq "server") { if ($argtype =3D~ m/^remote_node_device_/ and !($argtype =3D~ m/^remote_node_device_lookup_by_name_/) and !($argtype =3D~ m/^remote_node_device_create_xml_/) and + !($argtype =3D~ m/^remote_node_device_define_xml_/) and !($argtype =3D~ m/^remote_node_device_lookup_scsi_host_by_= wwn_/)) { $has_node_device =3D 1; push(@vars_list, "virNodeDevicePtr dev =3D NULL"); diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2= 1366-define.argv b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c= 9a70e21366-define.argv new file mode 100644 index 0000000000..773e98b963 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-de= fine.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2= 1366-define.json b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c= 9a70e21366-define.json new file mode 100644 index 0000000000..bfc6dcace3 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-de= fine.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-define.argv b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_be= b3f14c23d9-define.argv new file mode 100644 index 0000000000..773e98b963 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-de= fine.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin diff --git a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c= 23d9-define.json b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_be= b3f14c23d9-define.json new file mode 100644 index 0000000000..e5b22b2c44 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-de= fine.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-define.argv b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_87= 1d16c13076-define.argv new file mode 100644 index 0000000000..773e98b963 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-de= fine.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin diff --git a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c1= 3076-define.json b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_87= 1d16c13076-define.json new file mode 100644 index 0000000000..2e03d0bd8e --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-de= fine.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 index cee0d913dd..f821622ff6 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -10,10 +10,16 @@ =20 #define VIR_FROM_THIS VIR_FROM_NODEDEV =20 +typedef enum { + MDEVCTL_CMD_START, + MDEVCTL_CMD_DEFINE, +} MdevctlCmd; + struct startTestInfo { const char *virt_type; int create; const char *filename; + MdevctlCmd command; }; =20 /* capture stdin passed to command */ @@ -45,12 +51,17 @@ nodedevCompareToFile(const char *actual, return virTestCompareToFile(replacedCmdline, filename); } =20 + +typedef virCommandPtr (*GetStartDefineCmdFunc)(virNodeDeviceDefPtr, char *= *); + + static int testMdevctlStart(const char *virt_type, int create, + GetStartDefineCmdFunc get_cmd_func, const char *mdevxml, - const char *startcmdfile, - const char *startjsonfile) + const char *cmdfile, + const char *jsonfile) { g_autoptr(virNodeDeviceDef) def =3D NULL; virNodeDeviceObjPtr obj =3D NULL; @@ -66,7 +77,7 @@ testMdevctlStart(const char *virt_type, =20 /* 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, &uuid); + cmd =3D get_cmd_func(def, &uuid); =20 if (!cmd) goto cleanup; @@ -78,10 +89,10 @@ testMdevctlStart(const char *virt_type, if (!(actualCmdline =3D virBufferCurrentContent(&buf))) goto cleanup; =20 - if (nodedevCompareToFile(actualCmdline, startcmdfile) < 0) + if (nodedevCompareToFile(actualCmdline, cmdfile) < 0) goto cleanup; =20 - if (virTestCompareToFile(stdinbuf, startjsonfile) < 0) + if (virTestCompareToFile(stdinbuf, jsonfile) < 0) goto cleanup; =20 ret =3D 0; @@ -96,17 +107,31 @@ static int testMdevctlStartHelper(const void *data) { const struct startTestInfo *info =3D data; + const char *cmd; + GetStartDefineCmdFunc func; + g_autofree char *mdevxml =3D NULL; + g_autofree char *cmdlinefile =3D NULL; + g_autofree char *jsonfile =3D NULL; + + if (info->command =3D=3D MDEVCTL_CMD_START) { + cmd =3D "start"; + func =3D nodeDeviceGetMdevctlStartCommand; + } else if (info->command =3D=3D MDEVCTL_CMD_DEFINE) { + cmd =3D "define"; + func =3D nodeDeviceGetMdevctlDefineCommand; + } else { + return -1; + } =20 - 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); + mdevxml =3D g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir, + info->filename); + cmdlinefile =3D g_strdup_printf("%s/nodedevmdevctldata/%s-%s.argv", + abs_srcdir, info->filename, cmd); + jsonfile =3D g_strdup_printf("%s/nodedevmdevctldata/%s-%s.json", abs_s= rcdir, + info->filename, cmd); =20 - return testMdevctlStart(info->virt_type, - info->create, mdevxml, cmdlinefile, - jsonfile); + return testMdevctlStart(info->virt_type, info->create, func, + mdevxml, cmdlinefile, jsonfile); } =20 static int @@ -353,15 +378,18 @@ mymain(void) if (virTestRun(desc, func, &info) < 0) \ ret =3D -1; =20 -#define DO_TEST_START_FULL(virt_type, create, filename) \ +#define DO_TEST_START_FULL(desc, virt_type, create, filename, command) \ do { \ - struct startTestInfo info =3D { virt_type, create, filename }; \ - DO_TEST_FULL("mdevctl start " filename, testMdevctlStartHelper, in= fo); \ + struct startTestInfo info =3D { virt_type, create, filename, comma= nd }; \ + DO_TEST_FULL(desc, testMdevctlStartHelper, info); \ } \ while (0) =20 #define DO_TEST_START(filename) \ - DO_TEST_START_FULL("QEMU", CREATE_DEVICE, filename) + DO_TEST_START_FULL("mdevctl start " filename, "QEMU", CREATE_DEVICE, f= ilename, MDEVCTL_CMD_START) + +#define DO_TEST_DEFINE(filename) \ + DO_TEST_START_FULL("mdevctl define " filename, "QEMU", CREATE_DEVICE, = filename, MDEVCTL_CMD_DEFINE) =20 #define DO_TEST_STOP(uuid) \ DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid) @@ -390,6 +418,10 @@ mymain(void) DO_TEST_PARSE_JSON("mdevctl-list-multiple"); DO_TEST_PARSE_JSON("mdevctl-list-multiple-parents"); =20 + DO_TEST_DEFINE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); + DO_TEST_DEFINE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); + DO_TEST_DEFINE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); + done: nodedevTestDriverFree(driver); =20 --=20 2.26.2 From nobody Thu May 2 03:10:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597762203; cv=none; d=zohomail.com; s=zohoarc; b=k3hIpyeAbmIJj1c9+mX1NOVLHUW6G6Yuc8lf5WlpeChAveCrm7JsI88NzedV0NDNOC+zKjwdmiaEwJqITokamPitqBWd2mr9WvOj6XKSZBpAbCdS+N5eHLQHADIb4N/XPS8ouUEYYTkw0d3ufEnBuQ4eSZgfed66hdN9edQUKV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762203; 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=KvlWmlTmF32Zl2uY3wOyi4b+ftuHFXVRCfH/T0/xwkw=; b=jAB93peUdU9LR/mlqVCFUpAiPzAglRbcnMNSbXZo2LxSGSsd1Oca28EGV57Vlq3cYCsAaft4yylJ5X95VrgKedH+m6T/AhDP2M4hywwJ9nV5GFEXrC1SnZe0RT1uWs8ZrARu+Pbk+TsLApRSLOka0Tfik3bKPgSJDwS62tIm6AY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1597762203205139.37666679343874; Tue, 18 Aug 2020 07:50:03 -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-219-i8xWom_FNSGLOKqcaVUZJQ-1; Tue, 18 Aug 2020 10:48:45 -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 493AA1DE02; Tue, 18 Aug 2020 14:48:37 +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 29C825C70C; Tue, 18 Aug 2020 14:48:37 +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 E2B6A181A86E; Tue, 18 Aug 2020 14:48:36 +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 07IEmE93002807 for ; Tue, 18 Aug 2020 10:48:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4316E7DFC0; Tue, 18 Aug 2020 14:48:14 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06B415D6BD; Tue, 18 Aug 2020 14:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762202; 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=KvlWmlTmF32Zl2uY3wOyi4b+ftuHFXVRCfH/T0/xwkw=; b=CagbPuBDo7qrzMkUs+Ls7GF6jDqbtn9dSEuxL2hzc80Mfdz1x7A7JzCNG7SU8Q4NQri3YR ObXMiki3TKfVyU8I0ZoGbT2qdFtlkHGQb8ERBVK/4yRjFbZfC15yfCSv617qLTbtZTmXZ9 +7sWrehQ/hoSeRK/q8vSsLppNo1l3h8= X-MC-Unique: i8xWom_FNSGLOKqcaVUZJQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 11/16] virsh: add nodedev-define command Date: Tue, 18 Aug 2020 09:48:01 -0500 Message-Id: <20200818144806.134738-12-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 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 a virsh command that maps to virNodeDeviceDefineXML(). Signed-off-by: Jonathon Jongsma --- tools/virsh-nodedev.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index f078ce6516..45d6c7b493 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1004,6 +1004,58 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cm= d) } =20 =20 +/* + * "nodedev-define" command + */ +static const vshCmdInfo info_node_device_define[] =3D { + {.name =3D "help", + .data =3D N_("Define a device by an xml file on a node") + }, + {.name =3D "desc", + .data =3D N_("Defines a persistent device on the node that can be " + "assigned to a domain. The device must be started before " + "it can be assigned to a domain.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_node_device_define[] =3D { + VIRSH_COMMON_OPT_FILE(N_("file containing an XML description " + "of the device")), + {.name =3D NULL} +}; + +static bool +cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) +{ + virNodeDevicePtr dev =3D NULL; + const char *from =3D NULL; + bool ret =3D true; + char *buffer; + virshControlPtr priv =3D ctl->privData; + + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) + return false; + + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) + return false; + + dev =3D virNodeDeviceDefineXML(priv->conn, buffer, 0); + VIR_FREE(buffer); + + if (dev !=3D NULL) { + vshPrintExtra(ctl, _("Node device %s defined from %s\n"), + virNodeDeviceGetName(dev), from); + virNodeDeviceFree(dev); + } else { + vshError(ctl, _("Failed to define node device from %s"), from); + ret =3D false; + } + + return ret; +} + + const vshCmdDef nodedevCmds[] =3D { {.name =3D "nodedev-create", .handler =3D cmdNodeDeviceCreate, @@ -1057,5 +1109,11 @@ const vshCmdDef nodedevCmds[] =3D { .info =3D info_node_device_event, .flags =3D 0 }, + {.name =3D "nodedev-define", + .handler =3D cmdNodeDeviceDefine, + .opts =3D opts_node_device_define, + .info =3D info_node_device_define, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.26.2 From nobody Thu May 2 03:10:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597762129; cv=none; d=zohomail.com; s=zohoarc; b=Av0pbUN+Q8HZ28FnZ/ick2mUN0BQ5wJnb/5FmjjTkIKKKL75+9pbE2XitxfZccxGkLn+FydbChHhXZoZbe3d4saj6hH+e1b+FYgDbFuz0jmxQrE0DDy6PQOj3uRZqS31LNlmHOwAkf/ZtuZTQNTNMSL28YMHFcCmCscN76LLc5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762129; 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=xznGvJpnVXkNecyVoffKxosl+rjYPCiD6MU5U+ALEDg=; b=CDri1Epgjo65tGDKt3jkxNj8UMueLXrpNc4SB90zou8EY4rsa2LG/x77HvvXMIupDzPvGUyT8ZfPN8oCEd6/XnUVsre/GUgVjxGkAo0BcliSrB1q+u5e7X4G5ap3ovOdNXCbfq9D8KXpEuNCPOILGPKEr9mmBKLZ7qNWOVzsrRE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 159776212904654.90278409930613; Tue, 18 Aug 2020 07:48:49 -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-438-0iBHVkJKPfyEIqalhHDLbQ-1; Tue, 18 Aug 2020 10:48:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 113E0100CF73; Tue, 18 Aug 2020 14:48:40 +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 DF3CD18A49; Tue, 18 Aug 2020 14:48:39 +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 ACEB66037D; Tue, 18 Aug 2020 14:48:39 +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 07IEmEXB002814 for ; Tue, 18 Aug 2020 10:48:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9BA9A7DFC0; Tue, 18 Aug 2020 14:48:14 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EE445D6BD; Tue, 18 Aug 2020 14:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762128; 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=xznGvJpnVXkNecyVoffKxosl+rjYPCiD6MU5U+ALEDg=; b=bQydrqMRAGagApRyC1M8w0Snz/5crH5TKsA6mMqTy+YjAdy8X04c3tS+VDmTVoBCIROlHd pPhCB7HjQvejvYGtRtmvDt0YjqyT6ge9upkrxBSnMZ9h4raFhnhSq0gwLzRI25KtvOkzF8 5vPGyHg2uOS546qhhIJTdXXgOdmGE7w= X-MC-Unique: 0iBHVkJKPfyEIqalhHDLbQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 12/16] api: add virNodeDeviceUndefine() Date: Tue, 18 Aug 2020 09:48:02 -0500 Message-Id: <20200818144806.134738-13-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This interface allows you to undefine a persistently defined (but inactive) mediated devices. It is implemented via 'mdevctl' Signed-off-by: Jonathon Jongsma --- include/libvirt/libvirt-nodedev.h | 2 + src/driver-nodedev.h | 4 ++ src/libvirt-nodedev.c | 36 ++++++++++ src/libvirt_public.syms | 1 + src/node_device/node_device_driver.c | 68 +++++++++++++++++++ src/node_device/node_device_driver.h | 6 ++ src/node_device/node_device_udev.c | 1 + src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 14 +++- src/remote_protocol-structs | 4 ++ .../nodedevmdevctldata/mdevctl-undefine.argv | 1 + tests/nodedevmdevctltest.c | 56 ++++++++++++--- 12 files changed, 185 insertions(+), 9 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdevctl-undefine.argv diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 02aa9d9750..f7957499ae 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -131,6 +131,8 @@ virNodeDevicePtr virNodeDeviceDefineXML (virCon= nectPtr conn, const char *xmlDesc, unsigned int flags); =20 +int virNodeDeviceUndefine (virNodeDevicePtr dev); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h index 16d787f3fc..e18029ab48 100644 --- a/src/driver-nodedev.h +++ b/src/driver-nodedev.h @@ -79,6 +79,9 @@ typedef virNodeDevicePtr const char *xmlDesc, unsigned int flags); =20 +typedef int +(*virDrvNodeDeviceUndefine)(virNodeDevicePtr dev); + typedef int (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn, virNodeDevicePtr dev, @@ -119,4 +122,5 @@ struct _virNodeDeviceDriver { virDrvNodeDeviceCreateXML nodeDeviceCreateXML; virDrvNodeDeviceDestroy nodeDeviceDestroy; virDrvNodeDeviceDefineXML nodeDeviceDefineXML; + virDrvNodeDeviceUndefine nodeDeviceUndefine; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index 1704de929e..eb01ceb8b0 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -803,6 +803,42 @@ virNodeDeviceDefineXML(virConnectPtr conn, } =20 =20 +/** + * virNodeDeviceUndefine: + * @dev: a device object + * + * Undefine the device object. The virtual device is removed from the host + * operating system. This function may require privileged access. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virNodeDeviceUndefine(virNodeDevicePtr dev) +{ + VIR_DEBUG("dev=3D%p", dev); + + virResetLastError(); + + virCheckNodeDeviceReturn(dev, -1); + virCheckReadOnlyGoto(dev->conn->flags, error); + + if (dev->conn->nodeDeviceDriver && + dev->conn->nodeDeviceDriver->nodeDeviceUndefine) { + int retval =3D dev->conn->nodeDeviceDriver->nodeDeviceUndefine(dev= ); + if (retval < 0) + goto error; + + return 0; + } + + virReportUnsupportedError(); + + error: + virDispatchError(dev->conn); + return -1; +} + + /** * virConnectNodeDeviceEventRegisterAny: * @conn: pointer to the connection diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 27c637e37c..35c88ec4b7 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -876,5 +876,6 @@ LIBVIRT_6.0.0 { LIBVIRT_6.5.0 { global: virNodeDeviceDefineXML; + virNodeDeviceUndefine; } LIBVIRT_6.0.0; # .... define new API here using predicted next version number .... diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 16f3537776..60a360e4b5 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -833,6 +833,17 @@ nodeDeviceGetMdevctlStopCommand(const char *uuid) =20 } =20 +virCommandPtr +nodeDeviceGetMdevctlUndefineCommand(const char *uuid) +{ + return virCommandNewArgList(MDEVCTL, + "undefine", + "-u", + uuid, + NULL); + +} + static int virMdevctlStop(virNodeDeviceDefPtr def) { @@ -848,6 +859,21 @@ virMdevctlStop(virNodeDeviceDefPtr def) } =20 =20 +static int +virMdevctlUndefine(virNodeDeviceDefPtr def) +{ + int status; + g_autoptr(virCommand) cmd =3D NULL; + + cmd =3D nodeDeviceGetMdevctlUndefineCommand(def->caps->data.mdev.uuid); + + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + return 0; +} + + virCommandPtr nodeDeviceGetMdevctlListCommand(bool defined, char **output) @@ -1093,6 +1119,48 @@ nodeDeviceDefineXML(virConnectPtr conn, } =20 =20 +int +nodeDeviceUndefine(virNodeDevicePtr device) +{ + int ret =3D -1; + virNodeDeviceObjPtr obj =3D NULL; + virNodeDeviceDefPtr def; + g_autofree char *parent =3D NULL; + + if (nodeDeviceWaitInit() < 0) + return -1; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + def =3D virNodeDeviceObjGetDef(obj); + + if (virNodeDeviceUndefineEnsureACL(device->conn, def) < 0) + goto cleanup; + + if (virNodeDeviceObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("node device '%s' is still active"), + def->name); + goto cleanup; + } + + if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + if (virMdevctlUndefine(def) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to undefine mediated device")); + goto cleanup; + } + ret =3D 0; + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + } + + cleanup: + virNodeDeviceObjEndAPI(&obj); + return ret; +} + =20 int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index cf03e0b3cf..2adb3a8073 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -112,6 +112,9 @@ nodeDeviceDefineXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags); =20 +int +nodeDeviceUndefine(virNodeDevicePtr dev); + int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, virNodeDevicePtr dev, @@ -134,6 +137,9 @@ nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDefPtr d= ef, virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid); =20 +virCommandPtr +nodeDeviceGetMdevctlUndefineCommand(const char *uuid); + virCommandPtr nodeDeviceGetMdevctlListCommand(bool defined, char **output); =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 5101fff146..19d6642b21 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2199,6 +2199,7 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceCreateXML =3D nodeDeviceCreateXML, /* 0.7.3 */ .nodeDeviceDestroy =3D nodeDeviceDestroy, /* 0.7.3 */ .nodeDeviceDefineXML =3D nodeDeviceDefineXML, /* 6.5.0 */ + .nodeDeviceUndefine =3D nodeDeviceUndefine, /* 6.5.0 */ }; =20 =20 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 64d0d0c49b..fc27278c4d 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8815,6 +8815,7 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceListCaps =3D remoteNodeDeviceListCaps, /* 0.5.0 */ .nodeDeviceCreateXML =3D remoteNodeDeviceCreateXML, /* 0.6.3 */ .nodeDeviceDefineXML =3D remoteNodeDeviceDefineXML, /* 6.5.0 */ + .nodeDeviceUndefine =3D remoteNodeDeviceUndefine, /* 6.5.0 */ .nodeDeviceDestroy =3D remoteNodeDeviceDestroy /* 0.6.3 */ }; =20 diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index ddfdb9c084..d668074204 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2148,6 +2148,10 @@ struct remote_node_device_define_xml_ret { remote_nonnull_node_device dev; }; =20 +struct remote_node_device_undefine_args { + remote_nonnull_string name; +}; + =20 /* * Events Register/Deregister: @@ -6680,5 +6684,13 @@ enum remote_procedure { * @acl: node_device:write * @acl: node_device:start */ - REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 423 + REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 423, + + /** + * @generate: both + * @priority: high + * @acl: node_device:stop + */ + REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 424 + }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index c325923eaf..3d450a6de9 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1607,6 +1607,9 @@ struct remote_node_device_define_xml_args { struct remote_node_device_define_xml_ret { remote_nonnull_node_device dev; }; +struct remote_node_device_undefine_args { + remote_nonnull_string name; +}; struct remote_connect_domain_event_register_ret { int cb_registered; }; @@ -3566,4 +3569,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_BACKUP_BEGIN =3D 421, REMOTE_PROC_DOMAIN_BACKUP_GET_XML_DESC =3D 422, REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 423, + REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 424, }; diff --git a/tests/nodedevmdevctldata/mdevctl-undefine.argv b/tests/nodedev= mdevctldata/mdevctl-undefine.argv new file mode 100644 index 0000000000..54717455f7 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-undefine.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ undefine -u d76a6b78-45ed-4149-a325-005f9abc5281 diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index f821622ff6..216c70f1b8 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -12,7 +12,9 @@ =20 typedef enum { MDEVCTL_CMD_START, + MDEVCTL_CMD_STOP, MDEVCTL_CMD_DEFINE, + MDEVCTL_CMD_UNDEFINE } MdevctlCmd; =20 struct startTestInfo { @@ -134,19 +136,21 @@ testMdevctlStartHelper(const void *data) mdevxml, cmdlinefile, jsonfile); } =20 +typedef virCommandPtr (*GetStopUndefineCmdFunc)(const char *uuid); +struct UuidCommandTestInfo { + const char *uuid; + MdevctlCmd command; +}; + static int -testMdevctlStop(const void *data) +testMdevctlUuidCommand(const char *uuid, GetStopUndefineCmdFunc func, cons= t char *outfile) { - const char *uuid =3D data; g_auto(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); =20 - cmd =3D nodeDeviceGetMdevctlStopCommand(uuid); + cmd =3D func(uuid); =20 if (!cmd) goto cleanup; @@ -158,7 +162,7 @@ testMdevctlStop(const void *data) if (!(actualCmdline =3D virBufferCurrentContent(&buf))) goto cleanup; =20 - if (nodedevCompareToFile(actualCmdline, cmdlinefile) < 0) + if (nodedevCompareToFile(actualCmdline, outfile) < 0) goto cleanup; =20 ret =3D 0; @@ -168,6 +172,30 @@ testMdevctlStop(const void *data) return ret; } =20 +static int +testMdevctlUuidCommandHelper(const void *data) +{ + const struct UuidCommandTestInfo *info =3D data; + GetStopUndefineCmdFunc func; + const char *cmd; + g_autofree char *cmdlinefile =3D NULL; + + if (info->command =3D=3D MDEVCTL_CMD_STOP) { + cmd =3D "stop"; + func =3D nodeDeviceGetMdevctlStopCommand; + }else if (info->command =3D=3D MDEVCTL_CMD_UNDEFINE) { + cmd =3D "undefine"; + func =3D nodeDeviceGetMdevctlUndefineCommand; + } else { + return -1; + } + + cmdlinefile =3D g_strdup_printf("%s/nodedevmdevctldata/mdevctl-%s.argv= ", + abs_srcdir, cmd); + + return testMdevctlUuidCommand(info->uuid, func, cmdlinefile); +} + static int testMdevctlListDefined(const void *data G_GNUC_UNUSED) { @@ -391,8 +419,18 @@ mymain(void) #define DO_TEST_DEFINE(filename) \ DO_TEST_START_FULL("mdevctl define " filename, "QEMU", CREATE_DEVICE, = filename, MDEVCTL_CMD_DEFINE) =20 +#define DO_TEST_UUID_COMMAND_FULL(desc, uuid, command) \ + do { \ + struct UuidCommandTestInfo info =3D { uuid, command }; \ + DO_TEST_FULL(desc, testMdevctlUuidCommandHelper, info); \ + } \ + while (0) + #define DO_TEST_STOP(uuid) \ - DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid) + DO_TEST_UUID_COMMAND_FULL("mdevctl stop " uuid, uuid, MDEVCTL_CMD_STOP) + +#define DO_TEST_UNDEFINE(uuid) \ + DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " uuid, uuid, MDEVCTL_CMD_= UNDEFINE) =20 #define DO_TEST_LIST_DEFINED() \ do { \ @@ -422,6 +460,8 @@ mymain(void) DO_TEST_DEFINE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); DO_TEST_DEFINE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); =20 + DO_TEST_UNDEFINE("d76a6b78-45ed-4149-a325-005f9abc5281"); + done: nodedevTestDriverFree(driver); =20 --=20 2.26.2 From nobody Thu May 2 03:10:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597762131; cv=none; d=zohomail.com; s=zohoarc; b=TvGbIrr28cxCEo/3HkqahX55MrsDTNTL8j1COhS05Y0Tj08LIChi9VbR2GRVtjkoj8wYsxuViTUg+4JFOa3GoTqLFdv9AodYqO5JqF1M636QgGXRV1/gBhAInpu7eNPH1POUMavFe7WxMN7LZ9nGvm/KsqMr4Mf7nhMUV7wM6Ls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762131; 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=gFdniBLD0iMsPPOq7L6VN1a4DSf4qRp/OQtzmfxE088=; b=MsgOKHgCMQeJRLa4wSj8SQGxH+a8zigBxysYfFy7akGjXH7wOEs2t2krTLmCMqJEseDwUHoyyl5y3hpguOYtB2LMp+tSjO4RCDcjfQdIyRYKYmUBI5VKSkwfWFj1kQGap3EXDKCtus7D7B2giQVXPkyjtQWbLSw1C35A05NGxxA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 159776213113454.82851139081333; Tue, 18 Aug 2020 07:48:51 -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-187-U7SmZN-cMz2bqS0SfvMpGQ-1; Tue, 18 Aug 2020 10:48:48 -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 9F1161DDFA; Tue, 18 Aug 2020 14:48:42 +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 7E78A7DFCD; Tue, 18 Aug 2020 14:48:42 +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 4648E181A884; Tue, 18 Aug 2020 14:48:42 +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 07IEmFrG002820 for ; Tue, 18 Aug 2020 10:48:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 015D27DFC0; Tue, 18 Aug 2020 14:48:15 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B85325D6BD; Tue, 18 Aug 2020 14:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762130; 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=gFdniBLD0iMsPPOq7L6VN1a4DSf4qRp/OQtzmfxE088=; b=gffg0vxhD2H87oNgNX8eIIt49dd4YIy2YoMV5QiMoKr//flC3uE8VuJIpQ2xjebGkO8MxL lJUSQZI6TFibj2T4niMHd86zjuHx59NQRC+vF9bEzyZPQdzHMjcrrZ4MaAeYaGd/HVoJui LzkwgHd3tcrDGS5neFGmyzKtyHxwTMU= X-MC-Unique: U7SmZN-cMz2bqS0SfvMpGQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 13/16] virsh: Factor out function to find node device Date: Tue, 18 Aug 2020 09:48:03 -0500 Message-Id: <20200818144806.134738-14-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Several functions accept providing a node device by name or by wwnn,wwpn pair. Extract the logic to do this into a function that can be used by both callers. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- tools/virsh-nodedev.c | 58 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 45d6c7b493..34203c0e91 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -111,23 +111,18 @@ static const vshCmdOptDef opts_node_device_destroy[] = =3D { {.name =3D NULL} }; =20 -static bool -cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) +static virNodeDevicePtr +vshFindNodeDevice(vshControl *ctl, const char *value) { virNodeDevicePtr dev =3D NULL; - bool ret =3D false; - const char *device_value =3D NULL; char **arr =3D NULL; int narr; virshControlPtr priv =3D ctl->privData; =20 - if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) - return false; - - if (strchr(device_value, ',')) { - narr =3D vshStringToArray(device_value, &arr); + if (strchr(value, ',')) { + narr =3D vshStringToArray(value, &arr); if (narr !=3D 2) { - vshError(ctl, _("Malformed device value '%s'"), device_value); + vshError(ctl, _("Malformed device value '%s'"), value); goto cleanup; } =20 @@ -136,9 +131,30 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cm= d) =20 dev =3D virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], arr[1= ], 0); } else { - dev =3D virNodeDeviceLookupByName(priv->conn, device_value); + dev =3D virNodeDeviceLookupByName(priv->conn, value); } =20 + if (!dev) { + vshError(ctl, "%s '%s'", _("Could not find matching device"), valu= e); + goto cleanup; + } + + cleanup: + g_strfreev(arr); + return dev; +} + +static bool +cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) +{ + virNodeDevicePtr dev =3D NULL; + bool ret =3D false; + const char *device_value =3D NULL; + + if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) + return false; + + dev =3D vshFindNodeDevice(ctl, device_value); if (!dev) { vshError(ctl, "%s '%s'", _("Could not find matching device"), devi= ce_value); goto cleanup; @@ -153,7 +169,6 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - g_strfreev(arr); if (dev) virNodeDeviceFree(dev); return ret; @@ -569,28 +584,12 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *c= md) virNodeDevicePtr device =3D NULL; char *xml =3D NULL; const char *device_value =3D NULL; - char **arr =3D NULL; - int narr; bool ret =3D false; - virshControlPtr priv =3D ctl->privData; =20 if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) return false; =20 - if (strchr(device_value, ',')) { - narr =3D vshStringToArray(device_value, &arr); - if (narr !=3D 2) { - vshError(ctl, _("Malformed device value '%s'"), device_value); - goto cleanup; - } - - if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1])) - goto cleanup; - - device =3D virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], ar= r[1], 0); - } else { - device =3D virNodeDeviceLookupByName(priv->conn, device_value); - } + device =3D vshFindNodeDevice(ctl, device_value); =20 if (!device) { vshError(ctl, "%s '%s'", _("Could not find matching device"), devi= ce_value); @@ -604,7 +603,6 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - g_strfreev(arr); VIR_FREE(xml); if (device) virNodeDeviceFree(device); --=20 2.26.2 From nobody Thu May 2 03:10:53 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=1597762144; cv=none; d=zohomail.com; s=zohoarc; b=l1duMBtSHTnJsX0fRzqQXnWZf/1LjV8KVaHAsoVtczsUhJFmwg3G46dmVBMlzl3AFQDyZdt5czmxwRmRTyuIWbQ1L9xDXGiP7WBewwucVVDIovFqtP3g3pLjwML5DttW9044z6JsROwwtfMiwJqLhHScCUPnBYK6SZvCNWuEgY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762144; 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=uPVNIkR+lG/d3zRavKPVZrlgI+e4XgP8pbqD3Qo0axk=; b=m4UAKv42/eLpuk/aRawWIfajzITVlCB/lOTZ8Zky/DExtN3Idr0NJVopzlrGo9aRv4eh/kdBI+42bSxmqvfKzY9ZHTBF4rRPRDKaOYif2h7u6C9fPs3J7HwHlphNBSyNv9JXRWDA1LCSp0KI7uEdjNPLcIHbEFb6n/AsoQyQRC4= 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 1597762144318988.6927515716851; Tue, 18 Aug 2020 07:49:04 -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-476-wDI537bAN5CTjFBarECFjA-1; Tue, 18 Aug 2020 10:48:37 -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 72FEE81F02C; Tue, 18 Aug 2020 14:48:31 +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 528117DFCB; Tue, 18 Aug 2020 14:48:31 +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 1652360372; Tue, 18 Aug 2020 14:48:31 +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 07IEmFrh002827 for ; Tue, 18 Aug 2020 10:48:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5919E7DFC2; Tue, 18 Aug 2020 14:48:15 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C6885D757; Tue, 18 Aug 2020 14:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762143; 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=uPVNIkR+lG/d3zRavKPVZrlgI+e4XgP8pbqD3Qo0axk=; b=bvdjsP4qpy7I5YaKPiinFo97pcqd6ZYeIVglwju5l7qRDjaJvn1F8PWZe1VtrCzYg0+PqK 3fiwFtNIrd2EwqkgXh9Fa+ojk3egGqCYBPbPi+3w/uZsMd485kPAWWlDkOzBMrmoZECCi2 3ziGx6Ml50C0MJCrXUTH6wZBbhtHiG4= X-MC-Unique: wDI537bAN5CTjFBarECFjA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 14/16] virsh: add nodedev-undefine command Date: Tue, 18 Aug 2020 09:48:04 -0500 Message-Id: <20200818144806.134738-15-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 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 a virsh command that maps to virNodeDeviceUndefine(). Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- tools/virsh-nodedev.c | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 34203c0e91..db56fbc5e9 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1002,6 +1002,65 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cm= d) } =20 =20 +/* + * "nodedev-undefine" command + */ +static const vshCmdInfo info_node_device_undefine[] =3D { + {.name =3D "help", + .data =3D N_("Undefine an inactive node device") + }, + {.name =3D "desc", + .data =3D N_("Undefines the configuration for an inactive node device= ") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_node_device_undefine[] =3D { + {.name =3D "name", + .type =3D VSH_OT_ALIAS, + .help =3D "device" + }, + {.name =3D "device", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("device name or wwn pair in 'wwnn,wwpn' format"), + .completer =3D virshNodeDeviceNameCompleter, + }, + {.name =3D NULL} +}; + +static bool +cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) +{ + virNodeDevicePtr dev =3D NULL; + bool ret =3D false; + const char *device_value =3D NULL; + + if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) + return false; + + dev =3D vshFindNodeDevice(ctl, device_value); + + if (!dev) { + vshError(ctl, "%s '%s'", _("Could not find matching device"), devi= ce_value); + goto cleanup; + } + + if (virNodeDeviceUndefine(dev) =3D=3D 0) { + vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value= ); + } else { + vshError(ctl, _("Failed to undefine node device '%s'"), device_val= ue); + goto cleanup; + } + + ret =3D true; + cleanup: + if (dev) + virNodeDeviceFree(dev); + return ret; +} + + /* * "nodedev-define" command */ @@ -1113,5 +1172,11 @@ const vshCmdDef nodedevCmds[] =3D { .info =3D info_node_device_define, .flags =3D 0 }, + {.name =3D "nodedev-undefine", + .handler =3D cmdNodeDeviceUndefine, + .opts =3D opts_node_device_undefine, + .info =3D info_node_device_undefine, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.26.2 From nobody Thu May 2 03:10:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597762124; cv=none; d=zohomail.com; s=zohoarc; b=hjzca3wmLc0yBanL9QbMjjzt40/FiJpSE/pY3R2IyuhS6FNRPflJCOQkhBBqAksIkD6QHxFvlSj4M32CEfY/vS6prGGYbODIFggF/SedJTLG50/tOKBtyoydoj414ymS8XchuXuwYQ5tqoejd4D4eeIomya3AEbsAsHOCZPY3jY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762124; 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=L/oDV4jDD7FiGoMVYnnRQm7WAcHCkAxwAmTOlzALfKs=; b=hwsxpRDKTJtyEg39/99WKP6ZzlRwCK7R8s9LWc9uPVLpTwVs1Ywi1Cg0qKtEUBUmD7eP9XUOJ8GvRwnJc9tYf1r+3mAFQr04wE8d1lnh+ip1hzCXYttH4Zxu7g5yRyIMtO9ckXF+yV5qr+ARGJaBZ0PMpKNXPv1868Mm2iHTW14= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1597762124796421.06377979780723; Tue, 18 Aug 2020 07:48:44 -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-562-OqEY_jGCOlGAE-s9CNQ41A-1; Tue, 18 Aug 2020 10:48:41 -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 F2A31100CF6F; Tue, 18 Aug 2020 14:48:34 +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 CBF4F7DFC2; Tue, 18 Aug 2020 14:48:34 +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 935086037B; Tue, 18 Aug 2020 14:48:34 +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 07IEmF1A002838 for ; Tue, 18 Aug 2020 10:48:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id B29667DFC2; Tue, 18 Aug 2020 14:48:15 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7654B5D757; Tue, 18 Aug 2020 14:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762124; 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=L/oDV4jDD7FiGoMVYnnRQm7WAcHCkAxwAmTOlzALfKs=; b=St3iIOFtkFQbEDqq4CkevJGHcpge5JZyRgaaUXg5LkDTb4vD3L38GVcDsUw379nUMBk0PP GU6fv2O8nW2KlD6pER5ENmIdTvPYTuzrlZeOwPRzO4YaTGdz3yp0sqlQJ8lbHkbW02Z7J7 ntCNr6LPmX6WcOhyYYg0O0/MqjlXZaQ= X-MC-Unique: OqEY_jGCOlGAE-s9CNQ41A-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 15/16] api: add virNodeDeviceCreate() Date: Tue, 18 Aug 2020 09:48:05 -0500 Message-Id: <20200818144806.134738-16-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 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" This new API function provides a way to start a persistently-defined mediate device that was defined by virNodeDeviceDefineXML() (or one that was defined externally via mdevctl) Signed-off-by: Jonathon Jongsma --- include/libvirt/libvirt-nodedev.h | 2 + src/driver-nodedev.h | 4 ++ src/libvirt-nodedev.c | 35 +++++++++++ src/libvirt_public.syms | 1 + src/node_device/node_device_driver.c | 64 ++++++++++++++++++++ src/node_device/node_device_driver.h | 6 ++ src/node_device/node_device_udev.c | 1 + src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 14 ++++- src/remote_protocol-structs | 4 ++ tests/nodedevmdevctldata/mdevctl-create.argv | 1 + tests/nodedevmdevctltest.c | 11 +++- 12 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdevctl-create.argv diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index f7957499ae..cc6d4c8732 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -133,6 +133,8 @@ virNodeDevicePtr virNodeDeviceDefineXML (virCon= nectPtr conn, =20 int virNodeDeviceUndefine (virNodeDevicePtr dev); =20 +int virNodeDeviceCreate (virNodeDevicePtr dev); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h index e18029ab48..d00dd5845c 100644 --- a/src/driver-nodedev.h +++ b/src/driver-nodedev.h @@ -82,6 +82,9 @@ typedef virNodeDevicePtr typedef int (*virDrvNodeDeviceUndefine)(virNodeDevicePtr dev); =20 +typedef int +(*virDrvNodeDeviceCreate)(virNodeDevicePtr def); + typedef int (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn, virNodeDevicePtr dev, @@ -123,4 +126,5 @@ struct _virNodeDeviceDriver { virDrvNodeDeviceDestroy nodeDeviceDestroy; virDrvNodeDeviceDefineXML nodeDeviceDefineXML; virDrvNodeDeviceUndefine nodeDeviceUndefine; + virDrvNodeDeviceCreate nodeDeviceCreate; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index eb01ceb8b0..9340ca8410 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -839,6 +839,41 @@ virNodeDeviceUndefine(virNodeDevicePtr dev) } =20 =20 +/** + * virNodeDeviceCreate: + * @dev: a device object + * + * Start a defined node device: + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virNodeDeviceCreate(virNodeDevicePtr dev) +{ + VIR_DEBUG("dev=3D%p", dev); + + virResetLastError(); + + virCheckNodeDeviceReturn(dev, -1); + virCheckReadOnlyGoto(dev->conn->flags, error); + + if (dev->conn->nodeDeviceDriver && + dev->conn->nodeDeviceDriver->nodeDeviceCreate) { + int retval =3D dev->conn->nodeDeviceDriver->nodeDeviceCreate(dev); + if (retval < 0) + goto error; + + return 0; + } + + virReportUnsupportedError(); + + error: + virDispatchError(dev->conn); + return -1; +} + + /** * virConnectNodeDeviceEventRegisterAny: * @conn: pointer to the connection diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 35c88ec4b7..fa7144cec1 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -877,5 +877,6 @@ LIBVIRT_6.5.0 { global: virNodeDeviceDefineXML; virNodeDeviceUndefine; + virNodeDeviceCreate; } LIBVIRT_6.0.0; # .... define new API here using predicted next version number .... diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 60a360e4b5..c25a77c231 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -844,6 +844,17 @@ nodeDeviceGetMdevctlUndefineCommand(const char *uuid) =20 } =20 +virCommandPtr +nodeDeviceGetMdevctlCreateCommand(const char *uuid) +{ + return virCommandNewArgList(MDEVCTL, + "start", + "-u", + uuid, + NULL); + +} + static int virMdevctlStop(virNodeDeviceDefPtr def) { @@ -874,6 +885,21 @@ virMdevctlUndefine(virNodeDeviceDefPtr def) } =20 =20 +static int +virMdevctlCreate(virNodeDeviceDefPtr def) +{ + int status; + g_autoptr(virCommand) cmd =3D NULL; + + cmd =3D nodeDeviceGetMdevctlCreateCommand(def->caps->data.mdev.uuid); + + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + return 0; +} + + virCommandPtr nodeDeviceGetMdevctlListCommand(bool defined, char **output) @@ -1162,6 +1188,44 @@ nodeDeviceUndefine(virNodeDevicePtr device) } =20 =20 +int nodeDeviceCreate(virNodeDevicePtr device) +{ + int ret =3D -1; + virNodeDeviceObjPtr obj =3D NULL; + virNodeDeviceDefPtr def; + g_autofree char *parent =3D NULL; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + + if (virNodeDeviceObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("Device is already active")); + goto cleanup; + } + def =3D virNodeDeviceObjGetDef(obj); + + if (virNodeDeviceCreateEnsureACL(device->conn, def) < 0) + goto cleanup; + + if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + if (virMdevctlCreate(def) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to create mediated device")); + goto cleanup; + } + ret =3D 0; + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + } + + cleanup: + virNodeDeviceObjEndAPI(&obj); + return ret; +} + + int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, virNodeDevicePtr device, diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 2adb3a8073..939718effb 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -155,3 +155,9 @@ nodeDeviceGenerateName(virNodeDeviceDefPtr def, const char *subsystem, const char *sysname, const char *s); + +virCommandPtr +nodeDeviceGetMdevctlCreateCommand(const char *uuid); + +int +nodeDeviceCreate(virNodeDevicePtr dev); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 19d6642b21..6dd8ea8ac9 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2200,6 +2200,7 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceDestroy =3D nodeDeviceDestroy, /* 0.7.3 */ .nodeDeviceDefineXML =3D nodeDeviceDefineXML, /* 6.5.0 */ .nodeDeviceUndefine =3D nodeDeviceUndefine, /* 6.5.0 */ + .nodeDeviceCreate =3D nodeDeviceCreate, /* 6.5.0 */ }; =20 =20 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index fc27278c4d..3264573261 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8814,6 +8814,7 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceNumOfCaps =3D remoteNodeDeviceNumOfCaps, /* 0.5.0 */ .nodeDeviceListCaps =3D remoteNodeDeviceListCaps, /* 0.5.0 */ .nodeDeviceCreateXML =3D remoteNodeDeviceCreateXML, /* 0.6.3 */ + .nodeDeviceCreate =3D remoteNodeDeviceCreate, /* 6.5.0 */ .nodeDeviceDefineXML =3D remoteNodeDeviceDefineXML, /* 6.5.0 */ .nodeDeviceUndefine =3D remoteNodeDeviceUndefine, /* 6.5.0 */ .nodeDeviceDestroy =3D remoteNodeDeviceDestroy /* 0.6.3 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index d668074204..b019f38efd 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2152,6 +2152,10 @@ struct remote_node_device_undefine_args { remote_nonnull_string name; }; =20 +struct remote_node_device_create_args { + remote_nonnull_string name; +}; + =20 /* * Events Register/Deregister: @@ -6682,7 +6686,6 @@ enum remote_procedure { /** * @generate: both * @acl: node_device:write - * @acl: node_device:start */ REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 423, =20 @@ -6691,6 +6694,13 @@ enum remote_procedure { * @priority: high * @acl: node_device:stop */ - REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 424 + REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 424, + + /** + * @generate: both + * @priority: high + * @acl: node_device:start + */ + REMOTE_PROC_NODE_DEVICE_CREATE =3D 425 =20 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 3d450a6de9..a3cfe2572e 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1610,6 +1610,9 @@ struct remote_node_device_define_xml_ret { struct remote_node_device_undefine_args { remote_nonnull_string name; }; +struct remote_node_device_create_args { + remote_nonnull_string name; +}; struct remote_connect_domain_event_register_ret { int cb_registered; }; @@ -3570,4 +3573,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_BACKUP_GET_XML_DESC =3D 422, REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 423, REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 424, + REMOTE_PROC_NODE_DEVICE_CREATE =3D 425, }; diff --git a/tests/nodedevmdevctldata/mdevctl-create.argv b/tests/nodedevmd= evctldata/mdevctl-create.argv new file mode 100644 index 0000000000..802109340c --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-create.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ start -u 8a05ad83-3472-497d-8631-8142f31460e8 diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 216c70f1b8..a6726616dc 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -14,7 +14,8 @@ typedef enum { MDEVCTL_CMD_START, MDEVCTL_CMD_STOP, MDEVCTL_CMD_DEFINE, - MDEVCTL_CMD_UNDEFINE + MDEVCTL_CMD_UNDEFINE, + MDEVCTL_CMD_CREATE } MdevctlCmd; =20 struct startTestInfo { @@ -186,6 +187,9 @@ testMdevctlUuidCommandHelper(const void *data) }else if (info->command =3D=3D MDEVCTL_CMD_UNDEFINE) { cmd =3D "undefine"; func =3D nodeDeviceGetMdevctlUndefineCommand; + }else if (info->command =3D=3D MDEVCTL_CMD_CREATE) { + cmd =3D "create"; + func =3D nodeDeviceGetMdevctlCreateCommand; } else { return -1; } @@ -432,6 +436,9 @@ mymain(void) #define DO_TEST_UNDEFINE(uuid) \ DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " uuid, uuid, MDEVCTL_CMD_= UNDEFINE) =20 +#define DO_TEST_CREATE(uuid) \ + DO_TEST_UUID_COMMAND_FULL("mdevctl create " uuid, uuid, MDEVCTL_CMD_CR= EATE) + #define DO_TEST_LIST_DEFINED() \ do { \ if (virTestRun("mdevctl list --defined", testMdevctlListDefined, N= ULL) < 0) \ @@ -462,6 +469,8 @@ mymain(void) =20 DO_TEST_UNDEFINE("d76a6b78-45ed-4149-a325-005f9abc5281"); =20 + DO_TEST_CREATE("8a05ad83-3472-497d-8631-8142f31460e8"); + done: nodedevTestDriverFree(driver); =20 --=20 2.26.2 From nobody Thu May 2 03:10:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597762123; cv=none; d=zohomail.com; s=zohoarc; b=dAxNu5swtne4/MORE5QNBEiMMjc7QjhRxs2dw9r3VSZ7gxHZUOESlZeGZcSMaMbEk0NjQ7jD0dv7xauM6KjYOVlIF4W7dnWfkqBG/KYnJwjSNOiHkD6dXCzy8LSHYWoyqnRtjMvbKXEIzz0MqhF6sVuzneEjObl9JFLiW86+exs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597762123; 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=2tc68zbhlnCF6NnmT0MnKHV+5FwKMJ8m/veS8+Zxuqc=; b=FkTyfquCh9wXmEV86hiymW65ECRCJErrlJPAhWbSe9qSs9wg744FX6D3Yc7rj3do3ojH1RPshLRz/0w38AJBiUkwKP7L+GMqiJjKOIezFoSTjYX5drmaeWhIDktgImH0T1gBc2xJy/J5B69adcyWdtYzBDVNsi/Hy846+DkYyRQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 159776212376935.338731251313106; Tue, 18 Aug 2020 07:48:43 -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-152-KHZaca0GPT-rCsq5W3ZvuQ-1; Tue, 18 Aug 2020 10:48:40 -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 0CD7F18686D0; Tue, 18 Aug 2020 14:48:34 +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 E00495D757; Tue, 18 Aug 2020 14:48:33 +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 A6849181A71F; Tue, 18 Aug 2020 14:48:33 +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 07IEmGh1002846 for ; Tue, 18 Aug 2020 10:48:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 175087DFC0; Tue, 18 Aug 2020 14:48:16 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-237.phx2.redhat.com [10.3.113.237]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CEEB65D757; Tue, 18 Aug 2020 14:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597762122; 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=2tc68zbhlnCF6NnmT0MnKHV+5FwKMJ8m/veS8+Zxuqc=; b=NI5M8YpG4OVMA347Bae+JzbuqrqmzqQYXQqY6z8xEI1ofBFM7UdtTBtIG6uAnFKvryFtPj 1OsB+4NN+M85BvabbFlbLnk01hUvG3fFUuBPD4tc/zAgOdBndTipJuzFb2pj9socLvVHEh HyMF/j8/wFGRciUjnc3qR5kO1npIEbA= X-MC-Unique: KHZaca0GPT-rCsq5W3ZvuQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 16/16] virsh: add "nodedev-start" command Date: Tue, 18 Aug 2020 09:48:06 -0500 Message-Id: <20200818144806.134738-17-jjongsma@redhat.com> In-Reply-To: <20200818144806.134738-1-jjongsma@redhat.com> References: <20200818144806.134738-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: 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This virsh command maps to virNodeDeviceCreate(), which starts a node device that has been previously defined by virNodeDeviceDefineXML(). This is only supported for mediated devices. Signed-off-by: Jonathon Jongsma --- tools/virsh-nodedev.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index db56fbc5e9..eea576ff89 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1113,6 +1113,61 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *c= md G_GNUC_UNUSED) } =20 =20 +/* + * "nodedev-start" command + */ +static const vshCmdInfo info_node_device_start[] =3D { + {.name =3D "help", + .data =3D N_("Start a previously defined inactive node device") + }, + {.name =3D "desc", + .data =3D N_("Starts the configuration for an inactive node device") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_node_device_start[] =3D { + {.name =3D "name", + .type =3D VSH_OT_ALIAS, + .help =3D "device" + }, + {.name =3D "device", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("device name"), + .completer =3D virshNodeDeviceNameCompleter, + }, + {.name =3D NULL} +}; + +static bool +cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cmd) +{ + const char *name =3D NULL; + virNodeDevicePtr device; + bool ret =3D true; + virshControlPtr priv =3D ctl->privData; + + if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) + return false; + + if (!(device =3D virNodeDeviceLookupByName(priv->conn, name))) { + vshError(ctl, _("Could not find matching device '%s'"), name); + return false; + } + + if (virNodeDeviceCreate(device) =3D=3D 0) { + vshPrintExtra(ctl, _("Device %s started\n"), name); + } else { + vshError(ctl, _("Failed to start device %s"), name); + ret =3D false; + } + + virNodeDeviceFree(device); + return ret; +} + + const vshCmdDef nodedevCmds[] =3D { {.name =3D "nodedev-create", .handler =3D cmdNodeDeviceCreate, @@ -1178,5 +1233,11 @@ const vshCmdDef nodedevCmds[] =3D { .info =3D info_node_device_undefine, .flags =3D 0 }, + {.name =3D "nodedev-start", + .handler =3D cmdNodeDeviceStart, + .opts =3D opts_node_device_start, + .info =3D info_node_device_start, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.26.2