From nobody Wed May 15 03:51:23 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=1608819305; cv=none; d=zohomail.com; s=zohoarc; b=WfClRZJlUUefIj94xaqyX1ERr3+fAO7jf5ueH6NcvbpCb9taNuOOHxZluB34bGQIyxJzEGD3Ii/RwVk8hI5WrtrY/W6e+0AJC/tJaniBNmooa63aB14epfkN254JCnJCms9F4cIChDOIEdeFOtgnHM0oBEoRboKWbSKLkBOU7d8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819305; 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=dA8aisR3DWw4Z0tSc6/ttOJO0aw2shKyR/+/i41lbCQ=; b=gZKLtuJ9b39whVlWlYEynnWjlR74KM+rCIZJGRvV82Xl+80VH2my0xDoxi5HmardpWTU/CQZ9Fh63cXkQAqkaEm5S/BUForQv7J1JCMWPrWCYTW0y3ujVpJRqGyvN4dumfCUw2seWLGNdvbFmhbTj+Ijtaq1u0kG3u0268M4H3w= 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 160881930536166.12663199996393; Thu, 24 Dec 2020 06:15:05 -0800 (PST) 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-28-IB99YBSIP7iggAuEHVk_9w-1; Thu, 24 Dec 2020 09:15:01 -0500 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 918B98030BA; Thu, 24 Dec 2020 14:14:56 +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 6F2AD5D9C6; Thu, 24 Dec 2020 14:14:56 +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 CC9261809C9F; Thu, 24 Dec 2020 14:14:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEoKM005608 for ; Thu, 24 Dec 2020 09:14:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7A5F163747; Thu, 24 Dec 2020 14:14:50 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 350A75C1A3; Thu, 24 Dec 2020 14:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819304; 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=dA8aisR3DWw4Z0tSc6/ttOJO0aw2shKyR/+/i41lbCQ=; b=Xdwt9HSJbOs5SWz+k+EjAu4SYYRW2Fnjck0ZyKbm+1X4UAj7c+pPr2m5uZqyxdpguzGO+c Y+F0wb/+5u/2gtmp8HfX3jC5m1/YkcbR120xc6p9MMpEFb4q5LKv3VhQ1qDMRDZbFKpOdf MPkbXBCwRhXV4Oq1nLxu4FJgIvHjUx4= X-MC-Unique: IB99YBSIP7iggAuEHVk_9w-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 01/21] tests: remove extra trailing semicolon Date: Thu, 24 Dec 2020 08:14:25 -0600 Message-Id: <20201224141445.163819-2-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Tested-by: Yan Fu tested-by should not be given. --- tests/nodedevmdevctltest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index dab4b487b9..1d3cb00400 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -271,7 +271,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 Wed May 15 03:51:23 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=1608819323; cv=none; d=zohomail.com; s=zohoarc; b=czQffHX9IxyVzhJzPi6RxVtCgpkSgE10ehG4N2ljcolkWYLHML/3QWQGWE1/BNnmcwaDFceigzdhgUbDK4dcpVT8kezdFykjt+SEOWSsVjd3qXEx6Qz7K21WqkDORzK3x5KDJhNi8Pi/XrHWVb2uqM7ZraOFJ2dlOkaM0Tce7bI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819323; 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=JsHSEg5EFQc9VrE92VNvmQqUV8hrLCkFBFh+kmvIERE=; b=CAsMEEdgpLQHEXCz4rbDixm992IeY9mc1vaBTRW/Zge+pPvR9dM2ploOfK6nskdDN36Fii/Qoj1qGus3AYqY9l1/cHHI2K/Khn2FT0wGcxChHd1JufK7/Pgcban+hTUT8AU5locPQ1LuUJZoUmMgROO0uDZngFahqdMHWFRQBDM= 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 1608819323632954.2632871837257; Thu, 24 Dec 2020 06:15:23 -0800 (PST) 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-126-oPWMfWUuPayoJsRxeBxIGw-1; Thu, 24 Dec 2020 09:15:19 -0500 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 4E99C105207B; Thu, 24 Dec 2020 14:15:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2895662665; Thu, 24 Dec 2020 14:15:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E7EE41809CA4; Thu, 24 Dec 2020 14:15:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEoRZ005613 for ; Thu, 24 Dec 2020 09:14:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id D916A57; Thu, 24 Dec 2020 14:14:50 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9426A5C1A3; Thu, 24 Dec 2020 14:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819322; 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=JsHSEg5EFQc9VrE92VNvmQqUV8hrLCkFBFh+kmvIERE=; b=eKuAEfI91OdtTGgQ605cl/ka6F5XgdsDiad6LnKSpY9b0cDOdkbUiyArt1UCRfciryjJ5+ xpOVP5P/EoAf9axuZqsCl+5zs4ED++bBDeKdRY8AYB6M57rsSiJ2Lcwey5Rm5up/hwNVbs B/kgAxffmikA+9I8aqzAq9FU8Fj3L/k= X-MC-Unique: oPWMfWUuPayoJsRxeBxIGw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 02/21] nodedev: introduce concept of 'active' node devices Date: Thu, 24 Dec 2020 08:14:26 -0600 Message-Id: <20201224141445.163819-3-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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" 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 Tested-by: Yan Fu tested-by should not be given. --- 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 c9bda77b2e..92f58dbf7d 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 { @@ -976,3 +977,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 583fc5800e..fecd012300 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1203,6 +1203,7 @@ virNetworkPortDefSaveStatus; # conf/virnodedeviceobj.h virNodeDeviceObjEndAPI; virNodeDeviceObjGetDef; +virNodeDeviceObjIsActive; virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; virNodeDeviceObjListFindByName; @@ -1215,6 +1216,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 55a2731681..208f256895 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1536,6 +1536,7 @@ udevAddOneDevice(struct udev_device *device) else event =3D virNodeDeviceEventUpdateNew(objdef->name); =20 + virNodeDeviceObjSetActive(obj, true); virNodeDeviceObjEndAPI(&obj); =20 ret =3D 0; @@ -1921,6 +1922,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 Wed May 15 03:51:23 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=1608819305; cv=none; d=zohomail.com; s=zohoarc; b=nogvuBTRvYh6gRvAgBUmePuyh8EO2iPMmF4EOidLB0OaPhXfp/k+i14qWigOQIYUHxxLRfnOSvsXsil0gdcDmz64dKke6F00SEhLC7sbfuFyJVKPzSHwRJs7K2UWJ5Ufz/VKveGrMaK9AJnVPkfdNvCRM/w8eeoktvJcxNHLpZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819305; 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=KVvRbRoY4XHNFIx6IovVBpXmEg6GPmSqR/+5ZZfKPro=; b=SvUwqXYDXygYC/D2HA9vnOidwcUd9NBSOKLO0hvhQJka9MIAm7ocC9rD6lOsrk1++ccjbpKSjVB5DVUYT2LOv/L4MCB0mc22cTY4ZKd304ZsPPtBlOrhMxrbUnp4aC+07LMpn+0YSPFmVavasvHPLwEkHsnh/YDjAZ52IY+X2MU= 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 1608819305716997.4688148781228; Thu, 24 Dec 2020 06:15:05 -0800 (PST) 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-52-RTImEAnZNrupvfcl1owKgg-1; Thu, 24 Dec 2020 09:15:01 -0500 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 C2E0D100D690; Thu, 24 Dec 2020 14:14:55 +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 7A03D5D9C6; Thu, 24 Dec 2020 14:14:55 +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 7BF65180954D; Thu, 24 Dec 2020 14:14:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEpID005618 for ; Thu, 24 Dec 2020 09:14:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4637763747; Thu, 24 Dec 2020 14:14:51 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F35965C1A3; Thu, 24 Dec 2020 14:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819304; 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=KVvRbRoY4XHNFIx6IovVBpXmEg6GPmSqR/+5ZZfKPro=; b=K1mwxzlrnrxSo4be47LO6JQLcjHSnVWYNkfGyCzTCl3Fi3aZzUytS0u+CNQdflVU5JybxF njKUXnxvzCRAylvs3WYM736x+zR5jGm5YFeJAjrNHxnvjymKm6900FXQp4x/GyquvpOtBr 7fQu4TXBmbHo7ExkNrvqvjp4hTyQJRA= X-MC-Unique: RTImEAnZNrupvfcl1owKgg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 03/21] nodedev: Add ability to filter by active state Date: Thu, 24 Dec 2020 08:14:27 -0600 Message-Id: <20201224141445.163819-4-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Reviewed-by: Erik Skultety Tested-by: Yan Fu tested-by should not be given. --- include/libvirt/libvirt-nodedev.h | 9 +++-- src/conf/node_device_conf.h | 8 ++++ src/conf/virnodedeviceobj.c | 56 ++++++++++++++++------------ src/libvirt-nodedev.c | 2 + src/node_device/node_device_driver.c | 2 +- 5 files changed, 50 insertions(+), 27 deletions(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index eab8abf6ab..d304283871 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 */ @@ -86,6 +85,10 @@ typedef enum { VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_CARD =3D 1 << 18, /* s390 A= P Card device */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE =3D 1 << 19, /* s390 A= P Queue */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX =3D 1 << 20, /* s390 A= P Matrix */ + + /* filter the devices by active state */ + VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE =3D 1 << 29, /* Inacti= ve devices */ + VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE =3D 1 << 30, /* 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 c67b8e2aeb..3d7872fd6e 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -422,6 +422,14 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX) =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 92f58dbf7d..6e9291264a 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -848,8 +848,10 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr d= evs, } =20 =20 -#define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)= ) && \ - virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_ ## FLAG= )) +#define MATCH_CAP(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## F= LAG)) && \ + virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_ ## = FLAG)) +#define MATCH(FLAG) (flags & (FLAG)) + static bool virNodeDeviceObjMatch(virNodeDeviceObjPtr obj, unsigned int flags) @@ -861,33 +863,41 @@ virNodeDeviceObjMatch(virNodeDeviceObjPtr obj, =20 /* filter by cap type */ if (flags & VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP) { - if (!(MATCH(SYSTEM) || - MATCH(PCI_DEV) || - MATCH(USB_DEV) || - MATCH(USB_INTERFACE) || - MATCH(NET) || - MATCH(SCSI_HOST) || - MATCH(SCSI_TARGET) || - MATCH(SCSI) || - MATCH(STORAGE) || - MATCH(FC_HOST) || - MATCH(VPORTS) || - MATCH(SCSI_GENERIC) || - MATCH(DRM) || - MATCH(MDEV_TYPES) || - MATCH(MDEV) || - MATCH(CCW_DEV) || - MATCH(CSS_DEV) || - MATCH(VDPA) || - MATCH(AP_CARD) || - MATCH(AP_QUEUE) || - MATCH(AP_MATRIX))) + if (!(MATCH_CAP(SYSTEM) || + MATCH_CAP(PCI_DEV) || + MATCH_CAP(USB_DEV) || + MATCH_CAP(USB_INTERFACE) || + MATCH_CAP(NET) || + MATCH_CAP(SCSI_HOST) || + MATCH_CAP(SCSI_TARGET) || + MATCH_CAP(SCSI) || + MATCH_CAP(STORAGE) || + MATCH_CAP(FC_HOST) || + MATCH_CAP(VPORTS) || + MATCH_CAP(SCSI_GENERIC) || + MATCH_CAP(DRM) || + MATCH_CAP(MDEV_TYPES) || + MATCH_CAP(MDEV) || + MATCH_CAP(CCW_DEV) || + MATCH_CAP(CSS_DEV) || + MATCH_CAP(VDPA) || + MATCH_CAP(AP_CARD) || + MATCH_CAP(AP_QUEUE) || + MATCH_CAP(AP_MATRIX))) return false; } =20 + 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 +#undef MATCH_CAP =20 =20 typedef struct _virNodeDeviceObjListExportData virNodeDeviceObjListExportD= ata; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index eb8c735a8c..375b907852 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -105,6 +105,8 @@ virNodeNumOfDevices(virConnectPtr conn, const char *cap= , unsigned int flags) * VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_CARD * VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE * VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX + * 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 51b20848ce..c992251121 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -217,7 +217,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 Wed May 15 03:51:23 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=1608819436; cv=none; d=zohomail.com; s=zohoarc; b=YBU7bMuaaYIVCyRdEvdugLfyIBzHSol6+YA62RRVqTuk4ac35SG/OKXGtHE5lEZu8aE1XN41W/8aDrtWWazEjcqtWxTGgPm4hwokt6+H4GlahP8v3K/nR+RwNEsBrsiUoKVwiaErdQCncI12Tt5xeyxUD2sKTdttRGebkcpvf8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819436; 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=bYxD7b+SCVLOpSwQqT3N/TQTOkoWp9xKg0eBz/N9Eh0=; b=GpNcrcFZgvrrbX9mNb8hQaveZc6/OOyZkdypj9r4oXVhmRGxvT4YIckVs+qWgyTz+8yvXZ/wQ3AvhztJYBiDrZBmRIT7YXRV5g/DmFmSREiQrCr+F+gJl0ixFDqnRQxHLG/XN7i5+RsbfbWjnf1g2bN88K2gbHgqDBC/swKqjZA= 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 1608819436246112.60207553182795; Thu, 24 Dec 2020 06:17:16 -0800 (PST) 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-62-Ms6ZHCxSPKuPKz_bFdYsPg-1; Thu, 24 Dec 2020 09:15:28 -0500 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 0A8A2801B1F; Thu, 24 Dec 2020 14:15:16 +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 DCB516E71E; Thu, 24 Dec 2020 14:15:15 +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 A68645002D; Thu, 24 Dec 2020 14:15:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEpvr005632 for ; Thu, 24 Dec 2020 09:14:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id A80C85C253; Thu, 24 Dec 2020 14:14:51 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 603E65C1A3; Thu, 24 Dec 2020 14:14:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819435; 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=bYxD7b+SCVLOpSwQqT3N/TQTOkoWp9xKg0eBz/N9Eh0=; b=KFIO8EQkLM0ZasIv9NvQCU2Zy39TBKkqaPcHiwn+fzW77Uyk06LOCagTRJAHs2f1RrOCv9 ETLNW3ip3kKsE6YAgkNNu8y2wPAz50/fnznRFSMYiQso3gTQ4yN1ccQkz6vw+eNQHSPDt7 TfD7ZpNJLaa9kwr2d5EWLC9QB1J9yCI= X-MC-Unique: Ms6ZHCxSPKuPKz_bFdYsPg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 04/21] nodedev: expose internal helper for naming devices Date: Thu, 24 Dec 2020 08:14:28 -0600 Message-Id: <20201224141445.163819-5-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Expose a helper function that can be used by udev and mdevctl to generate device names for node devices. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety Tested-by: Yan Fu tested-by should not be given. --- src/node_device/node_device_driver.c | 25 +++++++++++++++++++++++++ src/node_device/node_device_driver.h | 6 ++++++ src/node_device/node_device_udev.c | 19 +++---------------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index c992251121..6143459618 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -968,3 +968,28 @@ nodedevRegister(void) return udevNodeRegister(); #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 2113d2b0a5..02baf56dab 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -118,3 +118,9 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr de= f, char **uuid_out); virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid); + +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 208f256895..be59e6c6bc 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -308,22 +308,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; } --=20 2.26.2 From nobody Wed May 15 03:51:23 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=1608819322; cv=none; d=zohomail.com; s=zohoarc; b=UYaEmetfBMHFDjW8Bgg7dkDWK0GFGrI1RVzeQj3ki8J0q8m342dUb5k47QRm7qamvssUONEEavERnGqmB2aR3rGk656LYHN9SDJKzOSJ5qxfpslCeX7+0DiDwUPCX1VmChy6pNjTIhqbzOkJsOgcIXCaM5mMqqwet1uTV/Dp/0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819322; 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=Ao4Tb+tjv3WxuZBqcDy/EUd3f17q5/uMmni64J/Dy4c=; b=SAqsohZquIymE1cU0ZqIh3ISfBA4uWm9rOe7m6jv7hysV9aRnfBjhelJxAAhKvw4jxnrAtdP/+4TpOfMCPAH9Qug87129eZ2TxSxpRtD1lQYrkFHKpgtguFb3wLccQgJnfJ3siRNMunpxQgM7s7nTwwwPK0gXp5/pyg1OmqCoGA= 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 160881932208893.07629235557943; Thu, 24 Dec 2020 06:15:22 -0800 (PST) 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-336-PeLAU9h4OF2Mpd0tz4oLAw-1; Thu, 24 Dec 2020 09:15:18 -0500 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 23042190D34A; Thu, 24 Dec 2020 14:15:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A594660C47; Thu, 24 Dec 2020 14:15:12 +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 721865002C; Thu, 24 Dec 2020 14:15:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEqjU005640 for ; Thu, 24 Dec 2020 09:14:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1F8AA57; Thu, 24 Dec 2020 14:14:52 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1ED25C1A3; Thu, 24 Dec 2020 14:14:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819320; 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=Ao4Tb+tjv3WxuZBqcDy/EUd3f17q5/uMmni64J/Dy4c=; b=HYw172bU01qumKfNm7r/uQtcbCr4g1awSAdA+eZ7BwNXKhQ1FCy3ygsg4VuQP+febMEK+6 /CLOgb6QcaJtqDQlrLI+dgoS1VX0+lITVuOBeKjt83xuaJoZZB2SErXXz2+0KCe560/EzD BLwxW5XefK4jJ/Ur+XLkdCDzBCGHvTI= X-MC-Unique: PeLAU9h4OF2Mpd0tz4oLAw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 05/21] nodedev: add ability to list and parse defined mdevs Date: Thu, 24 Dec 2020 08:14:29 -0600 Message-Id: <20201224141445.163819-6-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 the other test verifies that we can parse the returned JSON and convert it to our own internal node device representations. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety Tested-by: Yan Fu tested-by should not be given. --- src/node_device/node_device_driver.c | 150 ++++++++++++++++++ src/node_device/node_device_driver.h | 7 + .../mdevctl-list-defined.argv | 1 + .../mdevctl-list-multiple.json | 59 +++++++ .../mdevctl-list-multiple.out.xml | 39 +++++ tests/nodedevmdevctltest.c | 95 ++++++++++- 6 files changed, 349 insertions(+), 2 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdevctl-list-defined.argv create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple.json create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 6143459618..bbd373e32e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -853,6 +853,156 @@ 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); +} + + +static virNodeDeviceDefPtr +nodeDeviceParseMdevctlChildDevice(const char *parent, + virJSONValuePtr json) +{ + virNodeDevCapMdevPtr mdev; + const char *uuid; + virJSONValuePtr props, attrs; + g_autoptr(virNodeDeviceDef) child =3D g_new0(virNodeDeviceDef, 1); + + /* 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(json) !=3D 1) + return NULL; + + uuid =3D virJSONValueObjectGetKey(json, 0); + props =3D virJSONValueObjectGetValue(json, 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")); + + attrs =3D virJSONValueObjectGet(props, "attrs"); + + if (attrs && virJSONValueIsArray(attrs)) { + size_t i; + int nattrs =3D virJSONValueArraySize(attrs); + + mdev->attributes =3D g_new0(virMediatedDeviceAttrPtr, nattrs); + mdev->nattributes =3D nattrs; + + for (i =3D 0; i < nattrs; i++) { + virJSONValuePtr attr =3D virJSONValueArrayGet(attrs, i); + virMediatedDeviceAttrPtr attribute; + virJSONValuePtr value; + + if (!virJSONValueIsObject(attr) || + virJSONValueObjectKeysNumber(attr) !=3D 1) + return NULL; + + attribute =3D g_new0(virMediatedDeviceAttr, 1); + attribute->name =3D g_strdup(virJSONValueObjectGetKey(attr, 0)= ); + value =3D virJSONValueObjectGetValue(attr, 0); + attribute->value =3D g_strdup(virJSONValueGetString(value)); + mdev->attributes[i] =3D attribute; + } + } + mdevGenerateDeviceName(child); + + return g_steal_pointer(&child); +} + + +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; + + 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); + const char *parent; + virJSONValuePtr child_array; + int nchildren; + + if (!virJSONValueIsObject(obj)) + goto parsefailure; + + /* mdevctl returns an array of objects. Each object is a parent d= evice + * object containing a single key-value pair which maps from the n= ame + * of the parent device to an array of child devices */ + if (virJSONValueObjectKeysNumber(obj) !=3D 1) + goto parsefailure; + + parent =3D virJSONValueObjectGetKey(obj, 0); + child_array =3D virJSONValueObjectGetValue(obj, 0); + + if (!virJSONValueIsArray(child_array)) + goto parsefailure; + + nchildren =3D virJSONValueArraySize(child_array); + + for (j =3D 0; j < nchildren; j++) { + g_autoptr(virNodeDeviceDef) child =3D NULL; + virJSONValuePtr child_obj =3D virJSONValueArrayGet(child_array= , j); + + if (!(child =3D nodeDeviceParseMdevctlChildDevice(parent, chil= d_obj))) + goto parsefailure; + + if (VIR_APPEND_ELEMENT(outdevs, noutdevs, child) < 0) + goto parsefailure; + } + } + + *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) { diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 02baf56dab..80ac7c5320 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -119,6 +119,13 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr d= ef, virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid); =20 +virCommandPtr +nodeDeviceGetMdevctlListCommand(bool defined, char **output); + +int +nodeDeviceParseMdevctlJSON(const char *jsonstring, + virNodeDeviceDefPtr **devs); + void nodeDeviceGenerateName(virNodeDeviceDefPtr def, const char *subsystem, 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.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/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 1d3cb00400..8bc464d59f 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -143,6 +143,87 @@ 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); + 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) { @@ -263,13 +344,13 @@ mymain(void) } =20 #define DO_TEST_FULL(desc, func, info) \ - if (virTestRun(desc, func, &info) < 0) \ + if (virTestRun(desc, func, info) < 0) \ ret =3D -1; =20 #define DO_TEST_START_FULL(virt_type, create, filename) \ do { \ struct startTestInfo info =3D { virt_type, create, filename }; \ - DO_TEST_FULL("mdevctl start " filename, testMdevctlStartHelper, in= fo); \ + DO_TEST_FULL("mdevctl start " filename, testMdevctlStartHelper, &i= nfo); \ } \ while (0) =20 @@ -279,6 +360,12 @@ mymain(void) #define DO_TEST_STOP(uuid) \ DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid) =20 +#define DO_TEST_LIST_DEFINED() \ + DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) + +#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"); @@ -287,6 +374,10 @@ 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-multiple"); + done: nodedevTestDriverFree(driver); =20 --=20 2.26.2 From nobody Wed May 15 03:51:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1608819323; cv=none; d=zohomail.com; s=zohoarc; b=VRrCrZJk1Tk9mcrwpBMT7AVnXVUyql3f3Z0BMbLvwXQjzBXS7m59yB1o34FQy4am6otsOSi7IOzCATaNwzMslPzSoujCwDXm95qtGQpB92uSuDByDurYmeGbmLAEAXwWUoZo1z+uRQ/zzdFPVOr6Gdo48l1b737NmNoRoYTkE+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819323; 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=p6/X3PPRNY5kgkhLnMc5Yo+XSgkLiw5zO6jFOmzjYhY=; b=J138DlX6aZ7Su2R0oNlR7EkPpAnFz2KqJ++gLwvhRZfEQVY8a4anX5trtsClPFoskMoF0rdpQESWQtxeOvCl8rXz06hGtdOH6nzEhmVRqGOt1yzqbxOUhadB234O0mdc/n/q2cGprRKz+mtEmtzv5Z9BSf/9ypa9Gyrb0P6vGEc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1608819323143798.0257377583067; Thu, 24 Dec 2020 06:15:23 -0800 (PST) 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-4-dXw1m5S_OyGLWXhXu7ttKg-1; Thu, 24 Dec 2020 09:15:18 -0500 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 BA286107ACE8; Thu, 24 Dec 2020 14:15:12 +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 9B5145C1A3; Thu, 24 Dec 2020 14:15:12 +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 6563F4EBC6; Thu, 24 Dec 2020 14:15:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEqLa005646 for ; Thu, 24 Dec 2020 09:14:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7F0FC57; Thu, 24 Dec 2020 14:14:52 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 39C005C1A3; Thu, 24 Dec 2020 14:14:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819320; 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=p6/X3PPRNY5kgkhLnMc5Yo+XSgkLiw5zO6jFOmzjYhY=; b=XzYZNIeTyjhKcK95BlwvDsbkbhXn4ZcdoxMzkRXGYu/G+XkzkAeGv7ZUAmdG2wOM0wkS5M SzyGYUi8xuCI3zu2WRvnjqMXJ4Wq7z75vNAa8LdKR26gZyfdZPgpRizSnpklhmTK+/6JoK T4AaK+OQHPaD1MwEpUk3NQ/mJFc4w1g= X-MC-Unique: dXw1m5S_OyGLWXhXu7ttKg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 06/21] nodedev: add STOPPED/STARTED lifecycle events Date: Thu, 24 Dec 2020 08:14:30 -0600 Message-Id: <20201224141445.163819-7-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Tested-by: Yan Fu tested-by should not be given. --- 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 f164e825e1..d6eec648ec 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 d304283871..a473563857 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -197,6 +197,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 3d7872fd6e..bbc28cf2b9 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -157,6 +157,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 bbd373e32e..5309b8abd5 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -899,6 +899,7 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, 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 be59e6c6bc..632413d046 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1401,6 +1401,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'= ", @@ -1409,13 +1411,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 69422e20f5..35117585ff 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -775,7 +775,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 Wed May 15 03:51:23 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=1608819371; cv=none; d=zohomail.com; s=zohoarc; b=eb/8Vs6kOV/a0W/OFo2wKLjXQf6R0yy9pF1Wa8GA5yPeZSmqkDjHlUHWqupfffRIYJxg38fwzj8Op3vMA5RI2TlnazjDOYBD2VqonZoOzUmzFOsprGjv3lcDM+hn1L2RxECmLIxVUY1d/nr3yeG8mtragJFBYeUQKXyytGMxVEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819371; 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=+di+rPhrdYF8SvWZj90o1h/Ne4ePSbLkY52RnINuOPc=; b=R2kzoWSs82vZ+gqCHO8PdpPyeaAOOaR6jTq0Ct7zJ8TbzG4RpcPENn0FG1vqNVTMdG0hNqn9g/nyq9wWOB+EOUe3CnjUZ/Yk1OjJZfPnBxQKgWvg7P+ga3akwP+Vrq/hJdzVmEaRDZjLDUWFyuikD8XYNMPq6gMBApBwNhQeuDE= 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 1608819371004987.0149703354658; Thu, 24 Dec 2020 06:16:11 -0800 (PST) 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-352-8wCfCUltPuelXg7a7LBgAw-1; Thu, 24 Dec 2020 09:15:23 -0500 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 73243100D694; Thu, 24 Dec 2020 14:15:15 +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 4E5716F929; Thu, 24 Dec 2020 14:15:15 +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 1936F1809CA5; Thu, 24 Dec 2020 14:15:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEq1V005651 for ; Thu, 24 Dec 2020 09:14:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id DE9FC71C8D; Thu, 24 Dec 2020 14:14:52 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9976D5C1A3; Thu, 24 Dec 2020 14:14:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819369; 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=+di+rPhrdYF8SvWZj90o1h/Ne4ePSbLkY52RnINuOPc=; b=RhnYGHUgn6XFjxAIURVAk/9UiWU3K15Zgf6rUNULnVwaegxDnlDSKNvs4ocfdLTsH7UoMj 6mfEC7dBivWhJ+FxR0JQva0pLops/lq89ooJYGepCMslDu369xnOlavg3/2rsI+TzKcao8 NCJRV5GRP4HDskvARL1Mzqr/KCQ7oXA= X-MC-Unique: 8wCfCUltPuelXg7a7LBgAw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 07/21] nodedev: add mdevctl devices to node device list Date: Thu, 24 Dec 2020 08:14:31 -0600 Message-Id: <20201224141445.163819-8-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Tested-by: Yan Fu tested-by should not be given. --- src/node_device/node_device_driver.c | 76 ++++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 3 ++ src/node_device/node_device_udev.c | 48 ++++++++++++++++++ 3 files changed, 127 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 5309b8abd5..0267005af1 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1144,3 +1144,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 +nodeDeviceUpdateMediatedDevices(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]; + bool new_device =3D true; + + 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 */ + 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 80ac7c5320..4315f6d6ed 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -126,6 +126,9 @@ int nodeDeviceParseMdevctlJSON(const char *jsonstring, virNodeDeviceDefPtr **devs); =20 +int +nodeDeviceUpdateMediatedDevices(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 632413d046..223ee5a2ff 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1494,6 +1494,50 @@ 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; + + ret =3D g_new0(virMediatedDeviceAttrPtr, nattrs); + + 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; + virNodeDevCapMdevPtr dstmdev; + + if (dst->caps->data.type !=3D VIR_NODE_DEV_CAP_MDEV) + return; + + srcmdev =3D &src->caps->data.mdev; + 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) @@ -1527,6 +1571,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; } @@ -1953,6 +1999,8 @@ nodeStateInitializeEnumerate(void *opaque) /* Populate with known devices */ if (udevEnumerateDevices(udev) !=3D 0) goto error; + if (nodeDeviceUpdateMediatedDevices() !=3D 0) + goto error; =20 nodeDeviceLock(); driver->initialized =3D true; --=20 2.26.2 From nobody Wed May 15 03:51:23 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=1608819365; cv=none; d=zohomail.com; s=zohoarc; b=SHoH8W9KNc74yZI8GR/K7JR7ROY37CxnnclTr3vmOs9SZTj/OJemHTGdhQFidn4uFpHcOg47zQtAjOSHrHaSnRLjd2Ui5TlfUoMoTTleoqEZIPlr7s5kT7fnLX65Br0UokSAQCCOS1l+C9LKAVMvAgPNTrytDVw05kQ8j+Idw2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819365; 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=gBTlJuMMHhIlBdsQPgvcAc1sTvuKCSX2bhckF3RCibQ=; b=TCKyZULmISuBRzBv0QSRs7i3NXUmNFhs1su8CP4AI8+Of/XhvGvuquw2gzN3BFG3yWI2K66lqgGeGEzg+XXu/NvevPqHd5g1SaKfhKjwQSxkovlgxcDcS7bEjOcQXBXLUaAxeMeC2YY8zili14cEUq1T+BIvZ+El4GE1J0jPoYQ= 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 1608819365209160.60361202447177; Thu, 24 Dec 2020 06:16:05 -0800 (PST) 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-62-F_tO1OsWOwqzosMDnA0Sdg-1; Thu, 24 Dec 2020 09:15:28 -0500 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 E86B18030B0; Thu, 24 Dec 2020 14:15:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BFEB05D747; Thu, 24 Dec 2020 14:15:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7721350038; Thu, 24 Dec 2020 14:15:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEr55005656 for ; Thu, 24 Dec 2020 09:14:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4A1A057; Thu, 24 Dec 2020 14:14:53 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0491E5C1A3; Thu, 24 Dec 2020 14:14:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819363; 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=gBTlJuMMHhIlBdsQPgvcAc1sTvuKCSX2bhckF3RCibQ=; b=GfuQuS6Xrnlj7Z5Buqn7IkZEMsRYhMRslYDWjd5oiQLBUcmwdyDrTF9udj7quTJqCO36ra eHqY6/1vmjcNY2mWBIsVCghitCyr6FnJ24VTh2jcMNqyXoFcDlEpR4Xty3h8xvPJgW1Xan dppzvPUz7qmtuXJtgOIZ6i8MxnnVlis= X-MC-Unique: F_tO1OsWOwqzosMDnA0Sdg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 08/21] nodedev: add helper functions to remove node devices Date: Thu, 24 Dec 2020 08:14:32 -0600 Message-Id: <20201224141445.163819-9-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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" When a mediated device is stopped or undefined by an application outside of libvirt, we need to remove it from our list of node devices within libvirt. This patch introduces virNodeDeviceObjListRemoveLocked() and virNodeDeviceObjListForEach() (which are analogous to other types of object lists in libvirt) to facilitate that. They will be used in coming commits. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety Tested-by: Yan Fu tested-by should not be given. --- src/conf/virnodedeviceobj.c | 62 ++++++++++++++++++++++++++++++++++--- src/conf/virnodedeviceobj.h | 12 +++++++ src/libvirt_private.syms | 2 ++ 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 6e9291264a..5f0b21f8bf 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -506,23 +506,29 @@ void virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr obj) { - virNodeDeviceDefPtr def; - if (!obj) return; - def =3D obj->def; =20 virObjectRef(obj); virObjectUnlock(obj); virObjectRWLockWrite(devs); virObjectLock(obj); - virHashRemoveEntry(devs->objs, def->name); + virNodeDeviceObjListRemoveLocked(devs, obj); virObjectUnlock(obj); virObjectUnref(obj); virObjectRWUnlock(devs); } =20 =20 +/* The caller must hold lock on 'devs' */ +void +virNodeDeviceObjListRemoveLocked(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr dev) +{ + virHashRemoveEntry(devs->objs, dev->def->name); +} + + /* * Return the NPIV dev's parent device name */ @@ -1000,3 +1006,51 @@ virNodeDeviceObjSetActive(virNodeDeviceObjPtr obj, { obj->active =3D active; } + +struct _virNodeDeviceObjListForEachData { + virNodeDeviceObjListIterator iter; + const void *opaque; +}; + +static int +virNodeDeviceObjListForEachCb(void *payload, + const char *name G_GNUC_UNUSED, + void *opaque) +{ + virNodeDeviceObjPtr obj =3D payload; + struct _virNodeDeviceObjListForEachData *data =3D opaque; + + /* Grab a reference so that we don't rely only on references grabbed by + * hash table earlier. Remember, an iterator can remove object from the + * hash table. */ + virObjectRef(obj); + virObjectLock(obj); + data->iter(obj, data->opaque); + virNodeDeviceObjEndAPI(&obj); + + return 0; +} + +/** + * virNodeDeviceObjListForEach + * @devs: Pointer to object list + * @iter: Callback iteration helper + * @opaque: Opaque data to use as argument to helper + * + * For each object in @devs, call the @iter helper using @opaque as + * an argument. + */ +void +virNodeDeviceObjListForEach(virNodeDeviceObjListPtr devs, + virNodeDeviceObjListIterator iter, + const void *opaque) +{ + struct _virNodeDeviceObjListForEachData data =3D { + .iter =3D iter, + .opaque =3D opaque + }; + + virObjectRWLockWrite(devs); + virHashForEach(devs->objs, virNodeDeviceObjListForEachCb, &data); + virObjectRWUnlock(devs); +} diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index c119f4c51f..e672d8af61 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -80,6 +80,10 @@ void virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr dev); =20 +void +virNodeDeviceObjListRemoveLocked(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr dev); + int virNodeDeviceObjListGetParentHost(virNodeDeviceObjListPtr devs, virNodeDeviceDefPtr def); @@ -128,3 +132,11 @@ virNodeDeviceObjIsActive(virNodeDeviceObjPtr obj); void virNodeDeviceObjSetActive(virNodeDeviceObjPtr obj, bool active); + +typedef void +(*virNodeDeviceObjListIterator)(virNodeDeviceObjPtr obj, + const void *opaque); + +void virNodeDeviceObjListForEach(virNodeDeviceObjListPtr devs, + virNodeDeviceObjListIterator iter, + const void *opaque); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fecd012300..181d91792e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1210,12 +1210,14 @@ virNodeDeviceObjListFindByName; virNodeDeviceObjListFindBySysfsPath; virNodeDeviceObjListFindMediatedDeviceByUUID; virNodeDeviceObjListFindSCSIHostByWWNs; +virNodeDeviceObjListForEach; virNodeDeviceObjListFree; virNodeDeviceObjListGetNames; virNodeDeviceObjListGetParentHost; virNodeDeviceObjListNew; virNodeDeviceObjListNumOfDevices; virNodeDeviceObjListRemove; +virNodeDeviceObjListRemoveLocked; virNodeDeviceObjSetActive; =20 =20 --=20 2.26.2 From nobody Wed May 15 03:51:23 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=1608819424; cv=none; d=zohomail.com; s=zohoarc; b=dUCpN0M4Mf0J41aKrfit3NcbxQ4NoHSaTN93wDr5yXCepaHGmbycthFqaUeZFMskmgrw2r4HTF9kac72XFM9Sz7d00WOGW02Yenciqz8WG4A+yk1dAT5EpxM7EAu08KWOZSntcjs4ep+MBz59rUr66d8C3Qdyr4Idf1ZkBY3EIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819424; 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=9ah1pVd995bsdt1yaWGT6N6b9pwT427LXJxa37nOvfw=; b=cRdFbrMVluiOLW/ibdXpq4BxVopxSkc5C2YOZYJLcG83qg96x9oWMsfP3GI86TPc4aAP4NypQP6TwhXg8ZPzkSlek9vYm/YJTMa/bWHjxZTN6v5XECts8ZA3qx8Ew+Oc7DCXKCwhdh7Tb9PgGzxcLKhv5h3/MT0hsbCuMg42YKU= 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 1608819424032929.1543686247805; Thu, 24 Dec 2020 06:17:04 -0800 (PST) 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-97-lxkVC6LKOhS52ZbsNYyJGQ-1; Thu, 24 Dec 2020 09:15:28 -0500 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 A9508801B13; Thu, 24 Dec 2020 14:15:15 +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 89B2B6F816; Thu, 24 Dec 2020 14:15:15 +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 28ECD18095C7; Thu, 24 Dec 2020 14:15:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEErTW005661 for ; Thu, 24 Dec 2020 09:14:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id AACBF5C253; Thu, 24 Dec 2020 14:14:53 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 637E45C1A3; Thu, 24 Dec 2020 14:14:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819422; 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=9ah1pVd995bsdt1yaWGT6N6b9pwT427LXJxa37nOvfw=; b=cBjwlIaLmwpeSwL8wa7BaLH5/ZZgSCNeq2yHprwuhCqUWA3kS6uVJFwZXh8Z+QRU2h6Jj1 7xrampbz3Nh5xs/84WZ9JFo2N4YCfSJc9U3Jd264OTjsaRZc/hR0pYXki4qSjo7y84OGi9 cIM67SDerhGwq0BCqJRH25A+q1eqw3Y= X-MC-Unique: lxkVC6LKOhS52ZbsNYyJGQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 09/21] nodedev: handle mdevs that disappear from mdevctl Date: Thu, 24 Dec 2020 08:14:33 -0600 Message-Id: <20201224141445.163819-10-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Reviewed-by: Erik Skultety Tested-by: Yan Fu tested-by should not be given. --- src/node_device/node_device_driver.c | 67 +++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 0267005af1..0bebd534d0 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1163,23 +1163,73 @@ virMdevctlListDefined(virNodeDeviceDefPtr **devs) } =20 =20 +typedef struct _virMdevctlForEachData virMdevctlForEachData; +struct _virMdevctlForEachData { + int ndevs; + virNodeDeviceDefPtr *devs; +}; + + +/* This function keeps the list of persistent mediated devices consistent + * between the nodedev driver and mdevctl. + * @obj is a device that is currently known by the nodedev driver, and @op= aque + * contains the most recent list of devices defined by mdevctl. If @obj is= no + * longer defined in mdevctl, remove it from the driver as well. */ +static void +removeMissingPersistentMdevs(virNodeDeviceObjPtr obj, + const void *opaque) +{ + const virMdevctlForEachData *data =3D opaque; + size_t i; + virNodeDeviceDefPtr def =3D virNodeDeviceObjGetDef(obj); + virObjectEventPtr event; + + /* transient mdevs are populated via udev, so don't remove them from t= he + * nodedev driver just because they are not reported by by mdevctl */ + if (!(def->caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV && + def->caps->data.mdev.persistent)) + return; + + for (i =3D 0; i < data->ndevs; i++) { + /* OK, this mdev is still defined by mdevctl */ + if (STREQ(data->devs[i]->name, def->name)) + return; + } + + if (virNodeDeviceObjIsActive(obj)) { + /* The device is active, but no longer defined by mdevctl. Keep + * the device in the list, but mark it as non-persistent */ + def->caps->data.mdev.persistent =3D false; + return; + } + + /* the device is not active, and it is no longer defined by mdevctl, so + * remove it. */ + event =3D virNodeDeviceEventLifecycleNew(def->name, + VIR_NODE_DEVICE_EVENT_DELETED, + 0); + + virNodeDeviceObjListRemoveLocked(driver->devs, obj); + virObjectEventStateQueue(driver->nodeDeviceEventState, event); +} + + int nodeDeviceUpdateMediatedDevices(void) { - g_autofree virNodeDeviceDefPtr *devs =3D NULL; - int ndevs; size_t i; + virMdevctlForEachData data =3D { 0, }; =20 - if ((ndevs =3D virMdevctlListDefined(&devs)) < 0) { + if ((data.ndevs =3D virMdevctlListDefined(&data.devs)) < 0) { virReportSystemError(errno, "%s", _("failed to query mdevs from mdevctl")); return -1; } =20 - for (i =3D 0; i < ndevs; i++) { + for (i =3D 0; i < data.ndevs; i++) { virNodeDeviceObjPtr obj; virObjectEventPtr event; - virNodeDeviceDefPtr dev =3D devs[i]; + virNodeDeviceDefPtr dev =3D data.devs[i]; bool new_device =3D true; =20 dev->driver =3D g_strdup("vfio_mdev"); @@ -1218,5 +1268,12 @@ nodeDeviceUpdateMediatedDevices(void) virObjectEventStateQueue(driver->nodeDeviceEventState, event); } =20 + /* 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 */ + virNodeDeviceObjListForEach(driver->devs, removeMissingPersistentMdevs= , &data); + + g_free(data.devs); + return 0; } --=20 2.26.2 From nobody Wed May 15 03:51:23 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=1608819333; cv=none; d=zohomail.com; s=zohoarc; b=YrqFJ3XLy2+qkqQXSqDmlOPkgOF9MIIVQTfjMRtdl/fAwOnU9gLKagT6/bmf1bVsLk5d1r4PTELpISgMgzpBg/TXXcpKy8xtACmIY3D4AblG4twwS9JnBM14sSGgTGvNPB/Dwjabs9suo9QzKdgxC5L/AxOPfpu5VS5cUG/LwQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819333; 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=0MrSwo/kIms/4qmsPVNUXXoMn3W6NWY16vi2lZ4JDBw=; b=gPzrJKW3hfvVkcEhlSt+WQPJYvlRaHUSvE/TtBghplZ/TxGjDsbnTkONzyXWBhe++d5tn8QVAqKpejIj8WW+X9l7ozmzpydqGMeIHIVOEQwOqG6p7RohL2uKMSQ9pkSy00S083hghiqdAFRzuPwRGCbiOYiclceiw97VBz6TGPw= 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 1608819333657255.1335417391498; Thu, 24 Dec 2020 06:15:33 -0800 (PST) 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-125-Z_VJw_98Oy-bT1BK0DfiFw-1; Thu, 24 Dec 2020 09:15:29 -0500 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 89F1D801B1C; Thu, 24 Dec 2020 14:15:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 58D256F93D; Thu, 24 Dec 2020 14:15:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E9C1750032; Thu, 24 Dec 2020 14:15:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEsmL005667 for ; Thu, 24 Dec 2020 09:14:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 167AF57; Thu, 24 Dec 2020 14:14:54 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4FF85C1A3; Thu, 24 Dec 2020 14:14:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819332; 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=0MrSwo/kIms/4qmsPVNUXXoMn3W6NWY16vi2lZ4JDBw=; b=IyyNU3UR+mqeG0adLDRuUHgvCCOeSCX0EfKppgMDcPnM7AQdFCPGuBI99akszcZfuz2sO6 vxOM0W0Qaa4lffd6p+e0VIlLq4/Vr8oG08FcaVbdjGX8+nUNrxgwNDzwcCZhXuOpBnNU+d UC7fMFpe07hyTZg2M0ePjvZpyvUwyVo= X-MC-Unique: Z_VJw_98Oy-bT1BK0DfiFw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 10/21] nodedev: rename dataReady to udevReady Date: Thu, 24 Dec 2020 08:14:34 -0600 Message-Id: <20201224141445.163819-11-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 udev thread handles received udev events. This is accomplished by setting dataReady to 'true' and signalling the thread. We also want to use this thread to handle mdev events, so we'll need to add another variable to indicate which event has woken the thread. To prepare for this, rename 'dataReady' so that it is clear that when this variable is set, the udev event needs to be handled. Mdevctl events will use a different variable name. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety Tested-by: Yan Fu tested-by should not be given. --- src/node_device/node_device_udev.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 223ee5a2ff..d7f7ab4370 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -65,7 +65,7 @@ struct _udevEventData { virThread th; virCond threadCond; bool threadQuit; - bool dataReady; + bool udevReady; }; =20 static virClassPtr udevEventDataClass; @@ -1809,7 +1809,7 @@ udevEventMonitorSanityCheck(udevEventDataPtr priv, * NB: Some older distros, such as CentOS 6, libudev opens sockets * without the NONBLOCK flag which might cause issues with event * based algorithm. Although the issue can be mitigated by resetting - * priv->dataReady for each event found; however, the scheduler issues + * priv->udevReady for each event found; however, the scheduler issues * would still come into play. */ static void @@ -1821,7 +1821,7 @@ udevEventHandleThread(void *opaque G_GNUC_UNUSED) /* continue rather than break from the loop on non-fatal errors */ while (1) { virObjectLock(priv); - while (!priv->dataReady && !priv->threadQuit) { + while (!priv->udevReady && !priv->threadQuit) { if (virCondWait(&priv->threadCond, &priv->parent.lock)) { virReportSystemError(errno, "%s", _("handler failed to wait on conditio= n")); @@ -1858,11 +1858,11 @@ udevEventHandleThread(void *opaque G_GNUC_UNUSED) return; } =20 - /* Trying to move the reset of the @priv->dataReady flag to + /* Trying to move the reset of the @priv->udevReady flag to * after the udev_monitor_receive_device wouldn't help much * due to event mgmt and scheduler timing. */ virObjectLock(priv); - priv->dataReady =3D false; + priv->udevReady =3D false; virObjectUnlock(priv); =20 continue; @@ -1892,7 +1892,7 @@ udevEventHandleCallback(int watch G_GNUC_UNUSED, if (!udevEventMonitorSanityCheck(priv, fd)) priv->threadQuit =3D true; else - priv->dataReady =3D true; + priv->udevReady =3D true; =20 virCondSignal(&priv->threadCond); virObjectUnlock(priv); --=20 2.26.2 From nobody Wed May 15 03:51:23 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=1608819436; cv=none; d=zohomail.com; s=zohoarc; b=Vk9FjQhmg37QMGydVt/wNs4F9hVH2fXMHVsXO6SQ2ji4YzyMKq0hTyH5eNCrf4poAXxqU0dHXUXZm8KvwTejGuyhvF/ADog9/eoUSVsdsy11pvxIsA5N0e3sUxv/qXk5HWLjxbtyvLYjKADmtoUFzNDOhW3TnFg1TLeEqE+qAWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819436; 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=XCxUpLUD7Wz1AobkrQJOvIRf42ZIjdIKuaezo1GK6NA=; b=mw5UNNxpLrp6/JCofure+gORj5jl2Du26NE+86TAbtRtR3NOBFQtWr0R6ANFvT7SUHl62Ce5yXAN3dS/Fz1kItVEtO6SyBtyrxfNUaz5z/02ASJuyhh2lFp/9c91Wa5VhYOj4NarjIC5las2KCjyOjnVgQdHLlo6qUQy8fEMpPU= 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 1608819435988261.52398967802924; Thu, 24 Dec 2020 06:17:15 -0800 (PST) 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-473-JX-4aVuAPBGGB2_xWcyunQ-1; Thu, 24 Dec 2020 09:15:29 -0500 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 287CF8030B3; Thu, 24 Dec 2020 14:15:22 +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 01AC0271AD; Thu, 24 Dec 2020 14:15:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C3B7E1809CAC; Thu, 24 Dec 2020 14:15:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEse1005672 for ; Thu, 24 Dec 2020 09:14:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7714563747; Thu, 24 Dec 2020 14:14:54 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30CF05C1A3; Thu, 24 Dec 2020 14:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819434; 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=XCxUpLUD7Wz1AobkrQJOvIRf42ZIjdIKuaezo1GK6NA=; b=eW8axEYT2U+c5LQdnA31tJ8S+mNznsUs2i66Re8g++iIzB5ZF1GXpP3uHMle/jq57MMgNl d3IGIOX3vFNVIwpygDaOPnwoVYsGkwVyFqslQg3mDDAiYWTsFPXmO+VwSEfeU13H0NJAkh 2LYwOrxlzjVQ7jXczlXF3O2zXC6F1H4= X-MC-Unique: JX-4aVuAPBGGB2_xWcyunQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 11/21] nodedev: Refresh mdev devices when changes are detected Date: Thu, 24 Dec 2020 08:14:35 -0600 Message-Id: <20201224141445.163819-12-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 periodically query mdevctl for changes to device definitions since an administrator can define new devices with mdevctl outside of libvirt. 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. The mdevctl querying is handled by the existing udev thread. Signed-off-by: Jonathon Jongsma Tested-by: Yan Fu tested-by should not be given. --- src/node_device/node_device_udev.c | 204 ++++++++++++++++++++++++----- 1 file changed, 171 insertions(+), 33 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index d7f7ab4370..5729fea264 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,10 @@ struct _udevEventData { virCond threadCond; bool threadQuit; bool udevReady; + bool mdevReady; + + GList *mdevctlMonitors; + int mdevctlTimeout; }; =20 static virClassPtr udevEventDataClass; @@ -85,6 +90,7 @@ 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->mdevctlMonitors, g_object_unref); =20 virCondDestroy(&priv->threadCond); } @@ -1821,7 +1827,7 @@ udevEventHandleThread(void *opaque G_GNUC_UNUSED) /* continue rather than break from the loop on non-fatal errors */ while (1) { virObjectLock(priv); - while (!priv->udevReady && !priv->threadQuit) { + while (!priv->udevReady && !priv->mdevReady && !priv->threadQuit) { if (virCondWait(&priv->threadCond, &priv->parent.lock)) { virReportSystemError(errno, "%s", _("handler failed to wait on conditio= n")); @@ -1835,46 +1841,58 @@ udevEventHandleThread(void *opaque G_GNUC_UNUSED) return; } =20 - errno =3D 0; - device =3D udev_monitor_receive_device(priv->udev_monitor); - virObjectUnlock(priv); + if (priv->udevReady) { + errno =3D 0; + device =3D udev_monitor_receive_device(priv->udev_monitor); + virObjectUnlock(priv); =20 - if (!device) { - if (errno =3D=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to receive device from udev monit= or")); - return; - } + if (!device) { + if (errno =3D=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to receive device from udev m= onitor")); + return; + } + + /* POSIX allows both EAGAIN and EWOULDBLOCK to be used + * interchangeably when the read would block or timeout wa= s fired + */ + VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR + if (errno !=3D EAGAIN && errno !=3D EWOULDBLOCK) { + VIR_WARNINGS_RESET + virReportSystemError(errno, "%s", + _("failed to receive device from = udev " + "monitor")); + return; + } + + /* Trying to move the reset of the @priv->udevReady flag to + * after the udev_monitor_receive_device wouldn't help much + * due to event mgmt and scheduler timing. */ + virObjectLock(priv); + priv->udevReady =3D false; + virObjectUnlock(priv); =20 - /* POSIX allows both EAGAIN and EWOULDBLOCK to be used - * interchangeably when the read would block or timeout was fi= red - */ - VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR - if (errno !=3D EAGAIN && errno !=3D EWOULDBLOCK) { - VIR_WARNINGS_RESET - virReportSystemError(errno, "%s", - _("failed to receive device from udev= " - "monitor")); - return; + continue; } =20 - /* Trying to move the reset of the @priv->udevReady flag to - * after the udev_monitor_receive_device wouldn't help much - * due to event mgmt and scheduler timing. */ - virObjectLock(priv); - priv->udevReady =3D false; - virObjectUnlock(priv); + udevHandleOneDevice(device); + udev_device_unref(device); =20 - continue; + /* Instead of waiting for the next event after processing @dev= ice + * data, let's keep reading from the udev monitor and only wait + * for the next event once either a EAGAIN or a EWOULDBLOCK er= ror + * is encountered. */ } =20 - udevHandleOneDevice(device); - udev_device_unref(device); + if (priv->mdevReady) { + virObjectUnlock(priv); + if (nodeDeviceUpdateMediatedDevices() < 0) + VIR_WARN("mdevctl failed to updated mediated devices"); =20 - /* Instead of waiting for the next event after processing @device - * data, let's keep reading from the udev monitor and only wait - * for the next event once either a EAGAIN or a EWOULDBLOCK error - * is encountered. */ + virObjectLock(priv); + priv->mdevReady =3D false; + virObjectUnlock(priv); + } } } =20 @@ -1899,6 +1917,117 @@ udevEventHandleCallback(int watch G_GNUC_UNUSED, } =20 =20 +static void +scheduleMdevctlHandler(int timer G_GNUC_UNUSED, void *opaque) +{ + udevEventDataPtr priv =3D opaque; + + if (priv->mdevctlTimeout > 0) { + virEventRemoveTimeout(priv->mdevctlTimeout); + priv->mdevctlTimeout =3D -1; + } + + virObjectLock(priv); + priv->mdevReady =3D true; + virCondSignal(&priv->threadCond); + virObjectUnlock(priv); +} + + +static void +mdevctlEventHandleCallback(GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, + gpointer user_data); + + +/* Recursively monitors a directory and its subdirectories for file change= s and + * returns a GList of GFileMonitor objects */ +static GList* +monitorFileRecursively(udevEventDataPtr udev, + GFile *file) +{ + GList *monitors =3D NULL; + g_autoptr(GError) error =3D NULL; + g_autoptr(GFileEnumerator) children =3D NULL; + GFileMonitor *mon; + + if (!(children =3D g_file_enumerate_children(file, "standard::*", + G_FILE_QUERY_INFO_NONE, NUL= L, &error))) { + if (error->code =3D=3D G_IO_ERROR_NOT_DIRECTORY) + return NULL; + goto error; + } + + if (!(mon =3D g_file_monitor(file, G_FILE_MONITOR_NONE, NULL, &error))) + goto error; + + g_signal_connect(mon, "changed", + G_CALLBACK(mdevctlEventHandleCallback), udev); + 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 error; + if (!info) + break; + + child_monitors =3D monitorFileRecursively(udev, child); + if (child_monitors) + monitors =3D g_list_concat(monitors, child_monitors); + } + + return monitors; + + error: + g_list_free_full(monitors, g_object_unref); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to monitor directory: %s"), error->message); + return NULL; +} + + +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 (event_type =3D=3D G_FILE_MONITOR_EVENT_CREATED && + g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL) =3D=3D + G_FILE_TYPE_DIRECTORY) { + GList *newmonitors =3D monitorFileRecursively(priv, file); + priv->mdevctlMonitors =3D g_list_concat(priv->mdevctlMonitors, new= monitors); + } + + /* When mdevctl creates a device, it can result in multiple notify eve= nts + * emitted for a single logical change (e.g. several CHANGED events, o= r a + * CREATED and CHANGED event followed by CHANGES_DONE_HINT). To avoid + * spawning a mdevctl thread multiple times for a single logical + * configuration change, try to coalesce these changes by waiting for = the + * CHANGES_DONE_HINT event. As a fallback, add a timeout to trigger t= he + * signal if that event never comes */ + if (event_type !=3D G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { + if (priv->mdevctlTimeout > 0) + virEventRemoveTimeout(priv->mdevctlTimeout); + priv->mdevctlTimeout =3D virEventAddTimeout(100, scheduleMdevctlHa= ndler, + priv, NULL); + return; + } + + scheduleMdevctlHandler(-1, priv); +} + + /* DMI is intel-compatible specific */ #if defined(__x86_64__) || defined(__i386__) || defined(__amd64__) static void @@ -2052,6 +2181,7 @@ nodeStateInitialize(bool privileged, udevEventDataPtr priv =3D NULL; struct udev *udev =3D NULL; virThread enumThread; + 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", @@ -2153,6 +2283,14 @@ nodeStateInitialize(bool privileged, if (priv->watch =3D=3D -1) goto unlock; =20 + /* 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->mdevctlMonitors =3D monitorFileRecursively(priv, mdevctlConfigDi= r); + virObjectUnlock(priv); =20 /* Create a fictional 'computer' device to root the device tree. */ --=20 2.26.2 From nobody Wed May 15 03:51:23 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=1608819333; cv=none; d=zohomail.com; s=zohoarc; b=FVjzY6PdxRoT73MdWPpFlenEiREuTfi51f/6OjxUXj/sI+SVyEuWQYxqDCg+IWJ0ntgO7m3PoElwc+Am4vtJkkiNHCHTyJILConc7voHbgFTX25TsTT/XjTSm/atIMWb7M0bLDhTbgcVuZwKEzIQOYcyEx8xdnYm6osKHByIJIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819333; 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=RxRUOTezU3UMlfa+EPqtYzd0yLJQyF0y9QV65NZqYLA=; b=Me+UscKdNkkM5qa0mguLzN2FcxUPY2JLHrXfZwfyHw6vsFIK/808Quyqowm6qnvIw8doNhANJBOzbbtzyueIrx9eRP72ulVu7Oap8QCFgxLgnf1ZKTW+0+nnnPFOP9o3qGpprLkAPkGWOtzyerjkWiG/tyL3E5e/0Vy+YOTUva4= 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 1608819333904721.4604415389649; Thu, 24 Dec 2020 06:15:33 -0800 (PST) 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-129-eMKr3-DPO5yuWLfBzTqOXw-1; Thu, 24 Dec 2020 09:15:29 -0500 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 9E6128030A3; Thu, 24 Dec 2020 14:15:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79C797093E; Thu, 24 Dec 2020 14:15:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 41FA45003A; Thu, 24 Dec 2020 14:15:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEs70005680 for ; Thu, 24 Dec 2020 09:14:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id E2B1357; Thu, 24 Dec 2020 14:14:54 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 90A825C1A3; Thu, 24 Dec 2020 14:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819332; 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=RxRUOTezU3UMlfa+EPqtYzd0yLJQyF0y9QV65NZqYLA=; b=Cx3LWAAv31cHDo1qGywWAOQz4l45UhAH6/y1LJdUNqmLF90cNc8b7WKnmllJoKSK9Of/06 CeLG6LFD8vrwEs3W56SlHoLr/MPJ7SK//87jBs4Tc5vCfmwDmRNGj6VNjZGRMxt+FGwbnN 2lb0yg8WFSXJh/0LBe2GbHU7u4NpKWg= X-MC-Unique: eMKr3-DPO5yuWLfBzTqOXw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 12/21] api: add virNodeDeviceDefineXML() Date: Thu, 24 Dec 2020 08:14:36 -0600 Message-Id: <20201224141445.163819-13-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Tested-by: Yan Fu tested-by should not be given. --- include/libvirt/libvirt-nodedev.h | 4 + src/driver-nodedev.h | 6 ++ src/libvirt-nodedev.c | 42 ++++++++ src/libvirt_public.syms | 1 + 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 | 17 +++- 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, 239 insertions(+), 23 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 a473563857..3e57e9522a 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -132,6 +132,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 375b907852..15eb70218a 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -765,6 +765,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 cf31f937d5..8fae4352ff 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -877,6 +877,7 @@ LIBVIRT_6.10.0 { global: virDomainAuthorizedSSHKeysGet; virDomainAuthorizedSSHKeysSet; + virNodeDeviceDefineXML; } LIBVIRT_6.0.0; =20 # .... 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 0bebd534d0..4fbe8743b4 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -698,9 +698,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; @@ -718,7 +722,7 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr de= f, return NULL; } =20 - cmd =3D virCommandNewArgList(MDEVCTL, "start", + cmd =3D virCommandNewArgList(MDEVCTL, subcommand, "-p", parent_addr, "--jsonfile", "/dev/stdin", NULL); @@ -729,6 +733,22 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr d= ef, 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) { @@ -749,6 +769,26 @@ virMdevctlStart(virNodeDeviceDefPtr def, char **uuid) } =20 =20 +static int +virMdevctlDefine(virNodeDeviceDefPtr def, char **uuid) +{ + int status; + g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlDefineCommand(def, u= uid); + if (!cmd) + return -1; + + /* an auto-generated uuid is returned via stdout if no uuid is specifi= ed in + * the mdevctl args */ + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + /* remove newline */ + *uuid =3D g_strstrip(*uuid); + + return 0; +} + + static virNodeDevicePtr nodeDeviceCreateXMLMdev(virConnectPtr conn, virNodeDeviceDefPtr def) @@ -1068,6 +1108,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; + g_autofree char *uuid =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)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + return NULL; + } + + if (!def->parent) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("cannot define a mediated device without a parent= ")); + 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); + + 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 4315f6d6ed..e58bb0f124 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -102,6 +102,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, @@ -116,6 +121,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 5729fea264..2532c3189e 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2338,6 +2338,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 b0af3ee88e..f826b6f73e 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8665,6 +8665,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 2df38cef77..d2250502b4 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2142,6 +2142,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: @@ -6714,5 +6723,11 @@ enum remote_procedure { * @generate: none * @acl: domain:write */ - REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET =3D 425 + REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET =3D 425, + + /** + * @generate: both + * @acl: node_device:write + */ + REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 426 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 9bcd14603d..565c1673f1 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; }; @@ -3588,4 +3595,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_EVENT_MEMORY_FAILURE =3D 423, REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_GET =3D 424, REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET =3D 425, + REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 426, }; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 0020273d9e..30108272f1 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 8bc464d59f..981276d180 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 @@ -347,15 +372,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, &i= nfo); \ + 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) @@ -378,6 +406,10 @@ mymain(void) =20 DO_TEST_PARSE_JSON("mdevctl-list-multiple"); =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 Wed May 15 03:51:23 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=1608819331; cv=none; d=zohomail.com; s=zohoarc; b=RVRfKHab3Go1K2wnZWEAnzfC1biK3p/mFqXpu5z2kaSYsDRw1Xa8PARiSg54ZexpNzPnuBbwejd53OmS53GpVGL3nhqXpeB/jWqtEqsKm2Xq9dbR+kioCR01FgFvXR6tDBzVrt0nsb6K41jFbjUt4b2Vmzo55KF48ssbBwuH3Vc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819331; 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=ndJUFCi0yS35mmQtkIyTGiPcPHe9dHsAfltIi5ogTIU=; b=kAp0tHWbjnPTs+25hFc4CaPucEJqESjsgj0veSDsEEzFh6rV9677jW3sJs62h8X40i7fLocii9n6Nnr2Vbv3soxFmwvbYIg0mRzKsBG6ec7Hr/vDrCOiSQZp2K7Dkgmv1ng7s+w4i/gBrBRuxKhjA/CoRPGme2Wwl1IC7tdu0a0= 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 1608819331756763.9055890303216; Thu, 24 Dec 2020 06:15:31 -0800 (PST) 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-97-fDn9Tj7kPriBg4sw_kKatg-1; Thu, 24 Dec 2020 09:15:28 -0500 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 9319B190D34E; Thu, 24 Dec 2020 14:15:21 +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 1EDD65D9C6; Thu, 24 Dec 2020 14:15:21 +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 DAEC51809CA6; Thu, 24 Dec 2020 14:15:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEtse005690 for ; Thu, 24 Dec 2020 09:14:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4CA5D57; Thu, 24 Dec 2020 14:14:55 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07C435C1A3; Thu, 24 Dec 2020 14:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819330; 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=ndJUFCi0yS35mmQtkIyTGiPcPHe9dHsAfltIi5ogTIU=; b=e5WaUjKtOEGkdS4JFROmqqf8FKVMdJjz4GVvgxhD/3iKFvCs7aQGtd17dGCMja0wTdxzV4 7ylTOBXM5JN6k3WygXWU0KV9GUgBpSmvlJMBUCUKyNPCiQQJb3odl+6tIQamAfgMc3YWif sXb7sBhO5EQTmh5utMqWPc49IP3z0Cc= X-MC-Unique: fDn9Tj7kPriBg4sw_kKatg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 13/21] virsh: Add --active, --inactive, --all to nodedev-list Date: Thu, 24 Dec 2020 08:14:37 -0600 Message-Id: <20201224141445.163819-14-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Reviewed-by: Erik Skultety Tested-by: Yan Fu tested-by should not be given. --- tools/virsh-nodedev.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 35117585ff..e3261747e3 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -378,6 +378,14 @@ static const vshCmdOptDef opts_node_list_devices[] =3D= { .completer =3D virshNodeDeviceCapabilityNameCompleter, .help =3D N_("capability names, separated by comma") }, + {.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 +401,27 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd= G_GNUC_UNUSED) int ncaps =3D 0; virshNodeDeviceListPtr list =3D NULL; int cap_type =3D -1; + bool inactive, all; =20 + 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) { + vshError(ctl, "%s", _("Option --all is incompatible with --inactiv= e")); + return false; + } + + if (tree && (cap_str || 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")); @@ -481,6 +498,11 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd = G_GNUC_UNUSED) } } =20 + if (inactive || all) + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE; + if (!inactive) + 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 Wed May 15 03:51:23 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=1608819333; cv=none; d=zohomail.com; s=zohoarc; b=bs+4Fm8YWZjoUY14SgeTYvzqGWdZwIo/PE1WG7qwJzaoZuFPrB2dY3nMMZYzEzrNu4rVRR80pPP9Oz41XbGesYCMQfFBQvBO8RVt/Vdd/h4DcU5O1snUtgoN+y6h+GF17PSob5fkAk8KVZHRLcBHtwtbwl2uNlc/qLjoPuqKBjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819333; 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=CjGK0cfCJON6imimMmReyj21T2DwQbsURdyhSYBMAXo=; b=GKZOK2ZxsnLpNF1e9qcsl2OyfkL6lra+FDdcM8TIRxBd5VZE8vwqVP9Td3hNEngjwQuazvbXD3dwnmYHIC2611pt9XFPZi5ucn74hL5Mo+X0jmbrwSTAETqlDXUtrRF8HLAAH0TMBNNPwLknUKI91kwmq8UVupBfrL72mN9j5Iw= 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 1608819333115547.8817753801414; Thu, 24 Dec 2020 06:15:33 -0800 (PST) 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-66-exa5JQrDOHG44TUxTxbrGQ-1; Thu, 24 Dec 2020 09:15:29 -0500 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 D343C1052079; Thu, 24 Dec 2020 14:15:23 +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 B23B171C97; Thu, 24 Dec 2020 14:15:23 +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 7B3751809CAF; Thu, 24 Dec 2020 14:15:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEtDl005695 for ; Thu, 24 Dec 2020 09:14:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id ABB975C1A3; Thu, 24 Dec 2020 14:14:55 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 669FB71C8D; Thu, 24 Dec 2020 14:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819332; 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=CjGK0cfCJON6imimMmReyj21T2DwQbsURdyhSYBMAXo=; b=jOvrrBkyCQUOKyraU8yLpBjv8+3tD51EeUWULP76H3wjNi2fJDHAbafGDi4c8C6gfNo++M h1P8KpObGcfdnb4GTEr5H+AosDGlmjdv39bLPTlTFxiHXJCz9QJHl3z0hpfjmVVZ44KhVz IJqYXTpYKo+i+kOcZMZYHdpA9JjOWQY= X-MC-Unique: exa5JQrDOHG44TUxTxbrGQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 14/21] virsh: add nodedev-define command Date: Thu, 24 Dec 2020 08:14:38 -0600 Message-Id: <20201224141445.163819-15-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Reviewed-by: Erik Skultety Tested-by: Yan Fu tested-by should not be given. --- tools/virsh-nodedev.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index e3261747e3..07d48bbfbe 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1014,6 +1014,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, @@ -1067,5 +1119,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 Wed May 15 03:51:23 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=1608819456; cv=none; d=zohomail.com; s=zohoarc; b=aMHKy3LNXH+6rpD/s70d4Dnl7qAOC/PU4nKGt2HQHnplUv2UyAL2xucpEPSMq4LUrhprbVK8oxxvttCvzxr1uvoObbRhXxzVaTXSEuX5YZqJPIWWARb8Siv5ZPC8IcUWRuW5p52r/mqLX6PF9+ckxu0DAaaUQ+D9EQwBDciy650= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819456; 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=mXZ1QBrb+x+fZbNzKDMIAcPEEvRpCugTZMn9zwUVkEk=; b=dOs8wnxUWbyEcU9dzL/bBfXuKWrloi9Nv4AExpuRXV+6AJlTJOm8s9RqSJrctiTlSREW+FJSBzwzA9YEhwq5BZvZVKh9oaponUtQaW2dJ6V7/rTZKU6FxC11k94QIGFwh94uFz8D9Tis+MuvRn5JmGsLPVvMhI/RWz+qu6LZ/gI= 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 1608819456855299.2961932434134; Thu, 24 Dec 2020 06:17:36 -0800 (PST) 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-335-YsQRnPmNMi-Xa7OCWadtFA-1; Thu, 24 Dec 2020 09:15:33 -0500 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 B8C9D8030AF; Thu, 24 Dec 2020 14:15:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9832E5C1A3; Thu, 24 Dec 2020 14:15:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6327D5003F; Thu, 24 Dec 2020 14:15:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEubx005705 for ; Thu, 24 Dec 2020 09:14:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1998171C8D; Thu, 24 Dec 2020 14:14:56 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5DC55C1A3; Thu, 24 Dec 2020 14:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819455; 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=mXZ1QBrb+x+fZbNzKDMIAcPEEvRpCugTZMn9zwUVkEk=; b=dIebGfIdbffsgdAPYIOg6VRqKzv+vtCb8rsuIcfJ9b9Adr6TOoVezr1YW+QvajRdklQH0K z6fUMxGadXaKfM/2DrwYRcm9HdjUK2RGbpzlwi9m1oLmAlqdsjyuvCCpsMgiqwTXaBMG9n 9HNeS5VseZqAicKn87MOW2y50rG/5vE= X-MC-Unique: YsQRnPmNMi-Xa7OCWadtFA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 15/21] nodedev: refactor tests to support mdev undefine Date: Thu, 24 Dec 2020 08:14:39 -0600 Message-Id: <20201224141445.163819-16-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 'stop' and 'undefine' commands take the same uuid parameter, so refactor the test infrastructure to share common implementation for both of these commands. The 'undefine' command will be introduced in a following patch. Signed-off-by: Jonathon Jongsma Tested-by: Yan Fu tested-by should not be given. --- tests/nodedevmdevctltest.c | 48 +++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 981276d180..56265cfaea 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,27 @@ 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 { + 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) { @@ -385,8 +410,15 @@ 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) =20 #define DO_TEST_LIST_DEFINED() \ DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) --=20 2.26.2 From nobody Wed May 15 03:51:23 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=1608819364; cv=none; d=zohomail.com; s=zohoarc; b=j2fL4MN6NIgHj87J/rulGcZFBBU3dQVtnCaXCalg/2EFr6Dk2D0h58ne2tZftI2hIKSWzTpFs/QURrNLXNzI0R3BJFrSShWd9kWeKpB/pSpVKkpKr4S4UChk5rxUfRX3b4g7V2osx7u53eZjVuRwYW+j5mRnWpmrLaqwhJSp378= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819364; 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=sSRl9nnnCZVjnf2vhuH+b7VNuVA44ynjxT5L9Kw9EIk=; b=c1EOHfm1ThHZAV6ygxmQEI/0UxCBw1MmzrkHJiplaxD6Nj589fMEEdYWQTrjSrspmEU1+8CmkArqRxq3gU1f4ETdrQRadaYPCwmHbT9ljsKNGqVxZ2kMyq9aQx5EOOdlz01eXr+V6kPE3X/MxEgod/C2QrIoH0tNKTPhNujrRJs= 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 1608819364468880.8690817651292; Thu, 24 Dec 2020 06:16:04 -0800 (PST) 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-372-Ck_zTYU3MdKgJuiHnIgj0A-1; Thu, 24 Dec 2020 09:15:33 -0500 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 AA680190D353; Thu, 24 Dec 2020 14:15:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A7ED7093E; Thu, 24 Dec 2020 14:15: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 52C8E1809CB2; Thu, 24 Dec 2020 14:15:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEuaU005710 for ; Thu, 24 Dec 2020 09:14:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 790DD57; Thu, 24 Dec 2020 14:14:56 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3218D71C8F; Thu, 24 Dec 2020 14:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819363; 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=sSRl9nnnCZVjnf2vhuH+b7VNuVA44ynjxT5L9Kw9EIk=; b=BWY4arLESWnZc1rE8oNN1CE2V/fNBSQzP2aVqOMd3XiquFojvaGJxp2hXyaHvG2RBd9bjo YE+wroV27ouY46dcVk5QHKrdFQ3m0PCd1fq4GtIjyPafV1Dadj7IfLBw3xHQbRFVV1I6FN QEMfU2yECSFMcx3ozhjxwvxz3uxUTDw= X-MC-Unique: Ck_zTYU3MdKgJuiHnIgj0A-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 16/21] api: add virNodeDeviceUndefine() Date: Thu, 24 Dec 2020 08:14:40 -0600 Message-Id: <20201224141445.163819-17-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Tested-by: Yan Fu tested-by should not be given. --- include/libvirt/libvirt-nodedev.h | 2 + src/access/viraccessperm.c | 2 +- src/access/viraccessperm.h | 6 +++ src/driver-nodedev.h | 4 ++ src/libvirt-nodedev.c | 36 +++++++++++++++ src/libvirt_public.syms | 1 + src/node_device/node_device_driver.c | 67 ++++++++++++++++++++++++++++ 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/nodedevmdevctltest.c | 8 ++++ 13 files changed, 150 insertions(+), 2 deletions(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 3e57e9522a..d9dac97147 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -136,6 +136,8 @@ virNodeDevicePtr virNodeDeviceDefineXML(virConnectPtr c= onn, const char *xmlDesc, unsigned int flags); =20 +int virNodeDeviceUndefine(virNodeDevicePtr dev); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/access/viraccessperm.c b/src/access/viraccessperm.c index 33db7752b6..d4a0c98b9b 100644 --- a/src/access/viraccessperm.c +++ b/src/access/viraccessperm.c @@ -70,7 +70,7 @@ VIR_ENUM_IMPL(virAccessPermNodeDevice, VIR_ACCESS_PERM_NODE_DEVICE_LAST, "getattr", "read", "write", "start", "stop", - "detach", + "detach", "delete", ); =20 VIR_ENUM_IMPL(virAccessPermNWFilter, diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h index 42996b9741..051246a7b6 100644 --- a/src/access/viraccessperm.h +++ b/src/access/viraccessperm.h @@ -500,6 +500,12 @@ typedef enum { */ VIR_ACCESS_PERM_NODE_DEVICE_DETACH, =20 + /** + * @desc: Delete node device + * @message: Deleting node device driver requires authorization + */ + VIR_ACCESS_PERM_NODE_DEVICE_DELETE, + VIR_ACCESS_PERM_NODE_DEVICE_LAST } virAccessPermNodeDevice; =20 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 15eb70218a..618778517b 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -807,6 +807,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 8fae4352ff..16022a74bf 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -878,6 +878,7 @@ LIBVIRT_6.10.0 { virDomainAuthorizedSSHKeysGet; virDomainAuthorizedSSHKeysSet; virNodeDeviceDefineXML; + virNodeDeviceUndefine; } LIBVIRT_6.0.0; =20 # .... 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 4fbe8743b4..e38aef0656 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -878,6 +878,17 @@ nodeDeviceGetMdevctlStopCommand(const char *uuid) =20 } =20 +virCommandPtr +nodeDeviceGetMdevctlUndefineCommand(const char *uuid) +{ + return virCommandNewArgList(MDEVCTL, + "undefine", + "-u", + uuid, + NULL); + +} + static int virMdevctlStop(virNodeDeviceDefPtr def) { @@ -893,6 +904,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) @@ -1157,6 +1183,47 @@ nodeDeviceDefineXML(virConnectPtr conn, } =20 =20 +int +nodeDeviceUndefine(virNodeDevicePtr device) +{ + int ret =3D -1; + virNodeDeviceObjPtr obj =3D NULL; + virNodeDeviceDefPtr def; + + 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 e58bb0f124..e06d62cee6 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -107,6 +107,9 @@ nodeDeviceDefineXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags); =20 +int +nodeDeviceUndefine(virNodeDevicePtr dev); + int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, virNodeDevicePtr dev, @@ -129,6 +132,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 2532c3189e..d7521a9c18 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2339,6 +2339,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 f826b6f73e..de569b74e5 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8666,6 +8666,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 d2250502b4..7fee7539f0 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2151,6 +2151,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: @@ -6729,5 +6733,13 @@ enum remote_procedure { * @generate: both * @acl: node_device:write */ - REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 426 + REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 426, + + /** + * @generate: both + * @priority: high + * @acl: node_device:delete + */ + REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 427 + }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 565c1673f1..6d136bdb66 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; }; @@ -3596,4 +3599,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_GET =3D 424, REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET =3D 425, REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 426, + REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 427, }; diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 56265cfaea..753cfd273e 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -183,6 +183,9 @@ testMdevctlUuidCommandHelper(const void *data) 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; } @@ -420,6 +423,9 @@ mymain(void) #define DO_TEST_STOP(uuid) \ DO_TEST_UUID_COMMAND_FULL("mdevctl stop " uuid, uuid, MDEVCTL_CMD_STOP) =20 +#define DO_TEST_UNDEFINE(uuid) \ + DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " uuid, uuid, MDEVCTL_CMD_= UNDEFINE) + #define DO_TEST_LIST_DEFINED() \ DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) =20 @@ -442,6 +448,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 Wed May 15 03:51:23 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=1608819373; cv=none; d=zohomail.com; s=zohoarc; b=aHi4J0Tad5e/7PNbJTeqsO6c8aZvOPLQZTC4DrOBhO7pXo3StlM4tLx5jB/IicPfLXd9w9osvM8MVxqjAk0q2UjT6CDV0OoFWgsSAutgTtGno2EECHw9i3YKavyIr8FCML40CJ1xS9Wunr2xBpuR7FbB25fcyRxzai3dGosTNOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819373; 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=UE+hG/XZvz2vFHQtYunIaWJUCMaBaDQ02o40E0I2j+0=; b=lyNfMhKgGO4Ev71tNDM1c2gN3EaqCTnTlFHuXNxySt03ykAsOAdj8rrL5ISXU8nMZXXgtHPPS/foAv3oJM6/DyaMnf0+nMp60KPfD7x+Zp+t4Hk6WcO4qd+0aKkx7RbE/hsW+8AnYGq2icolojpq/j8agtNnzJ9Vv2xQnTXNReA= 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 1608819373088829.3484948717198; Thu, 24 Dec 2020 06:16:13 -0800 (PST) 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-124-wMhjrWkeMjuyw7QN7nI0fA-1; Thu, 24 Dec 2020 09:15:35 -0500 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 93F5D801B15; Thu, 24 Dec 2020 14:15: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 0F98F271AD; Thu, 24 Dec 2020 14:15: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 D00461809CB8; Thu, 24 Dec 2020 14:15:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEuv1005720 for ; Thu, 24 Dec 2020 09:14:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id D6DD95C253; Thu, 24 Dec 2020 14:14:56 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 927D85C1A3; Thu, 24 Dec 2020 14:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819372; 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=UE+hG/XZvz2vFHQtYunIaWJUCMaBaDQ02o40E0I2j+0=; b=UJYVSzRnb06HUHjKu/p+GQ24onipvnAOH8QHoD8A9mmfrwSnIysGbqNNu/Djh8i3AJRQ/E cVBx090kmZMnV5XaXVcSf9Rxkexa6zhMeDnDfospa9i/kMfmq7+bZAw1B29YhxpouPK530 7NctT8cpNhDSx6dQcJl11HBxPfPqBd4= X-MC-Unique: wMhjrWkeMjuyw7QN7nI0fA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 17/21] virsh: Factor out function to find node device Date: Thu, 24 Dec 2020 08:14:41 -0600 Message-Id: <20201224141445.163819-18-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Tested-by: Yan Fu tested-by should not be given. --- 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 07d48bbfbe..5df75013de 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; @@ -579,28 +594,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); @@ -614,7 +613,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 Wed May 15 03:51:23 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=1608819484; cv=none; d=zohomail.com; s=zohoarc; b=g73wnuSzytOAGHeGLSz+rEVPbcBRGxojkMD8cfAaqHeLl/C7sqYTij2FsKwhasJAVP9o6coSsKKxccOhX6K6Jg7fIw+c6TigkSZC7OoL4/zZIjEuNdlMCk2RkGhF4/OMoUjfcHY1tp5E2gfeVdAntmEJBYPmqoYy/pUnawEMRik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819484; 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=2odeIo/PkFoTZWAhph0M4hfG+X2GuLgSFW71dGNypk8=; b=c4lkSTZjTfZ9gG916sEQTwsoxWBy7aABs55d6lXyK3oHv+QbY39nCDsyado+cNnrox1s6ds7ljRyE73xn4h5oOkCDttWIs2Z6ByZvNEOE9JoVXLp8UC145rgLC7+SoXSMdivGhhvSOQEoDyaLYSx6KvBjpB97zwQEBKOz4yDeF8= 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 1608819484280106.3362873336157; Thu, 24 Dec 2020 06:18:04 -0800 (PST) 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-240-9YKgt5e6OACUMEVzbwtFTA-1; Thu, 24 Dec 2020 09:15:28 -0500 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 2B77A190D349; Thu, 24 Dec 2020 14:15:23 +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 095F45D9C6; Thu, 24 Dec 2020 14:15:23 +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 C673C5003D; Thu, 24 Dec 2020 14:15:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEvjm005725 for ; Thu, 24 Dec 2020 09:14:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 41CCC5C253; Thu, 24 Dec 2020 14:14:57 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F0E265C1A3; Thu, 24 Dec 2020 14:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819483; 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=2odeIo/PkFoTZWAhph0M4hfG+X2GuLgSFW71dGNypk8=; b=NeMVEIPfexnVws7PIH0qOdASpDkLelyNJLl5i4Kyy4lFf/ACh2Z1gS5/FCrDPx/2iIzYIy Crr6EojlirqGjahZ1UHIipUwIZNT8tojHsoVYZL6EWrjr5/pNpomRW3ldc64TaUSbNc82S 8xME79vnyyPDK5uTzMxt4KRk9dN+5KQ= X-MC-Unique: 9YKgt5e6OACUMEVzbwtFTA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 18/21] virsh: add nodedev-undefine command Date: Thu, 24 Dec 2020 08:14:42 -0600 Message-Id: <20201224141445.163819-19-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Tested-by: Yan Fu tested-by should not be given. --- tools/virsh-nodedev.c | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 5df75013de..97d2a34056 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1012,6 +1012,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 */ @@ -1123,5 +1182,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 Wed May 15 03:51:23 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=1608819343; cv=none; d=zohomail.com; s=zohoarc; b=nEM3OjEjX16d7+b/Z1NT0NtphQWiyJAdYEOo9+psrOkDnaIexVm3ACvcchDf4QskWQwlRfOIVRt/nEqK4wJdIcJWNbwvlmhehIeFS2mTQzJXP5T8zG0PYP1S2X/OGLGD1HtkBcwuTYeHbbH1QttgeSb4goKVSdUgLXG3sMeNG1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819343; 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=DLKLmsbFEmosE/oYVGDzejldUB3T1O1eir12+4xOP2o=; b=O0O0ppWPOYxgrGs0IuNy+WGe6yJa2AGpFYSnRdDwM/zfr+0cT0TJi5+hxmo1IAguKIxPvw+15LoCT4k7BQlyXNDbIdCIFZ3SP4Fc+KGcQAOEr0vlBGtxuPZsjnKhHW/HNNZNl0X4w5byi9hs4umiBYEGKUqWqMx7PC52fdroIiw= 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 1608819342908531.0958018191362; Thu, 24 Dec 2020 06:15:42 -0800 (PST) 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-479-RSGmIg0NPIq9OGl0lqnelw-1; Thu, 24 Dec 2020 09:15:35 -0500 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 8D4E08030A5; Thu, 24 Dec 2020 14:15: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 684EF5D747; Thu, 24 Dec 2020 14:15:27 +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 349AD1809CB4; Thu, 24 Dec 2020 14:15:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEvDT005730 for ; Thu, 24 Dec 2020 09:14:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id A258C5C253; Thu, 24 Dec 2020 14:14:57 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C9C85C1A3; Thu, 24 Dec 2020 14:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819339; 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=DLKLmsbFEmosE/oYVGDzejldUB3T1O1eir12+4xOP2o=; b=PTbhgF8+AKXeSR8XWck/K1Zc/XhY583mqdYNLqhVBb0RgupNZwB8ASGh+9RlsgyHHJ2hi6 u5Js24YhpfImADf0rpLhLe8ZcGMjhi+RKwc9EjYJb9OR0CZFB9DfOkNoVOcLxmLo4T7wUa WEMD72E0StG1MRvjG6s/bGFnS4S08Wk= X-MC-Unique: RSGmIg0NPIq9OGl0lqnelw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 19/21] api: add virNodeDeviceCreate() Date: Thu, 24 Dec 2020 08:14:43 -0600 Message-Id: <20201224141445.163819-20-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 Tested-by: Yan Fu tested-by should not be given. --- 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 | 63 ++++++++++++++++++++ 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 | 13 +++- src/remote_protocol-structs | 4 ++ tests/nodedevmdevctldata/mdevctl-create.argv | 1 + tests/nodedevmdevctltest.c | 11 +++- 12 files changed, 140 insertions(+), 2 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 d9dac97147..71626bd837 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -138,6 +138,8 @@ virNodeDevicePtr virNodeDeviceDefineXML(virConnectPtr c= onn, =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 618778517b..1d13466fc1 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -843,6 +843,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 16022a74bf..7c812ebb6e 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -879,6 +879,7 @@ LIBVIRT_6.10.0 { virDomainAuthorizedSSHKeysSet; virNodeDeviceDefineXML; virNodeDeviceUndefine; + virNodeDeviceCreate; } LIBVIRT_6.0.0; =20 # .... 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 e38aef0656..dc41e937cd 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -889,6 +889,17 @@ nodeDeviceGetMdevctlUndefineCommand(const char *uuid) =20 } =20 +virCommandPtr +nodeDeviceGetMdevctlCreateCommand(const char *uuid) +{ + return virCommandNewArgList(MDEVCTL, + "start", + "-u", + uuid, + NULL); + +} + static int virMdevctlStop(virNodeDeviceDefPtr def) { @@ -919,6 +930,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) @@ -1225,6 +1251,43 @@ nodeDeviceUndefine(virNodeDevicePtr device) } =20 =20 +int nodeDeviceCreate(virNodeDevicePtr device) +{ + int ret =3D -1; + virNodeDeviceObjPtr obj =3D NULL; + virNodeDeviceDefPtr def; + + 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 e06d62cee6..58a5958f02 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -150,3 +150,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 d7521a9c18..54c9bb5f2b 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2340,6 +2340,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 de569b74e5..a592fcb31d 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8665,6 +8665,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 7fee7539f0..a7cf227e53 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2155,6 +2155,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: @@ -6740,6 +6744,13 @@ enum remote_procedure { * @priority: high * @acl: node_device:delete */ - REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 427 + REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 427, + + /** + * @generate: both + * @priority: high + * @acl: node_device:start + */ + REMOTE_PROC_NODE_DEVICE_CREATE =3D 428 =20 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 6d136bdb66..0f35efc5b3 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; }; @@ -3600,4 +3603,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET =3D 425, REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 426, REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 427, + REMOTE_PROC_NODE_DEVICE_CREATE =3D 428, }; 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 753cfd273e..bc0b94f441 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; } @@ -426,6 +430,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_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) =20 @@ -450,6 +457,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 Wed May 15 03:51:23 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=1608819341; cv=none; d=zohomail.com; s=zohoarc; b=LxyJDNHXxBac6m10zJ4DquzdgpT4TFmo4lOUngSd65PF7wlwI/wMVwS2f6JQ1J5RbiUkBZtq288lah33FlwXQf9Nyc/q2sHxAUp8BxZ7+o2KrO4cu5hujjC769y/vknLmNSpflFnkT5eOfeaBxRCe/7/iVmxj3mIkorxhDW2J3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819341; 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=fRDipcH+ruq2FyH9DDVPWqCvi6kz7bING98KMNyTIUY=; b=A7Kc0pGr3Q5mz2pEJMwK4B2JFEch/IQa6DTTk1A88sQN3Nub2wk4E5sIzDj9nYiRXuZG2KpaLeBWA0D3SJ9PLgc1LHs8XuiiRE6EVzaiPQTQLJqG28/VIpnlHgkvC0Mmns/fDAmr0aPfETT9+CHED7deUBw2rSA8Ogr1tzzD0uY= 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 1608819341622294.1275913434441; Thu, 24 Dec 2020 06:15:41 -0800 (PST) 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-128-EpoySuoXPeGN1ltdHq4hFg-1; Thu, 24 Dec 2020 09:15:37 -0500 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 3D5E4801B30; Thu, 24 Dec 2020 14:15:30 +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 194366E71E; Thu, 24 Dec 2020 14:15:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DBB7550042; Thu, 24 Dec 2020 14:15:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEwmw005735 for ; Thu, 24 Dec 2020 09:14:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0C3075C253; Thu, 24 Dec 2020 14:14:58 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBAA75C1A3; Thu, 24 Dec 2020 14:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819339; 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=fRDipcH+ruq2FyH9DDVPWqCvi6kz7bING98KMNyTIUY=; b=Hb8XsDm7HfCrI5Q55HGMUg3RNBTYGjgBtEtj/zfx2aUFviLN8hWG8psCt6Fnxdo9pCpkWD mJsXbXFHdm2tCb8p/gnxhH7OjCOwt9F1PwhFlaC8loJgf+DPxHKRnZSUF0Q0BbeQzUbe4/ ETt7NPnq3D2byFpX4KZZezTO6/JNLYE= X-MC-Unique: EpoySuoXPeGN1ltdHq4hFg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 20/21] virsh: add "nodedev-start" command Date: Thu, 24 Dec 2020 08:14:44 -0600 Message-Id: <20201224141445.163819-21-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Reviewed-by: Erik Skultety Tested-by: Yan Fu tested-by should not be given. --- tools/virsh-nodedev.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 97d2a34056..861c3259f1 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1123,6 +1123,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 an inactive node device") + }, + {.name =3D "desc", + .data =3D N_("Starts an inactive node device that was previously defi= ned") + }, + {.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, @@ -1188,5 +1243,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 From nobody Wed May 15 03:51:23 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=1608819373; cv=none; d=zohomail.com; s=zohoarc; b=mlM8SaM++5kiUMaI/Z7cS8D/aUj9LyAVOMAHIHxb3aS7USqWszC/45ZwWDE1QOVrIRgJgWOHJdY8WYnRYWvOinQYPa7Lt+g82PUp5S+mMhkzQu+4f7eJynEo2qmEozcpp86Hqx2Jiu81NBepNk6ymZI+R/UZtz48PibCU62WqM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608819373; 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=yYLIwegSJuX7mtmfIRR6GvFrosZIj1DELkeOyyzQp8U=; b=Kp41VkKuiYmSHaOSAR39dsZFSJm2WAcW4mURvt3bsPvhRhIRRYmEFabaYQg7Jtd8C1JCByw3OJL4cD5iN/VbhpmZ/CctFqnsZJS9br5YcDsTr8Pt3BCMY6lM3akc6xTKpRW7Y6Fay2O25SAP2dcPFNhvyAXA+CIOSaK3gkTwRd4= 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 1608819373283568.2393877950476; Thu, 24 Dec 2020 06:16:13 -0800 (PST) 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-576-oGIh3ouRMn6f6uROGSR89Q-1; Thu, 24 Dec 2020 09:15:38 -0500 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 ABD29801B1C; Thu, 24 Dec 2020 14:15: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 897D671C95; Thu, 24 Dec 2020 14:15: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 568E11809CA3; Thu, 24 Dec 2020 14:15:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BOEEwOw005740 for ; Thu, 24 Dec 2020 09:14:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6B3035C1A3; Thu, 24 Dec 2020 14:14:58 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-15.phx2.redhat.com [10.3.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2662E63747; Thu, 24 Dec 2020 14:14:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608819372; 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=yYLIwegSJuX7mtmfIRR6GvFrosZIj1DELkeOyyzQp8U=; b=cd8Ag9/h5uMoe0475hAeQ634zqEan6kNzwT37bRg0/VTaeIqOkYvnoUR7GB5rT5pdzFcm3 5HmWMeucW+T7J4TvHzkOPfK19pCIE3vtoXQ8TacKQur0Hctg/Dxg8lt/ndoMkld++oaRPh fUydMIm2z1EYVBZ9bnXieBTFdSyi29c= X-MC-Unique: oGIh3ouRMn6f6uROGSR89Q-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 21/21] libvirt-nodedev.h: remove space-padded alignment Date: Thu, 24 Dec 2020 08:14:45 -0600 Message-Id: <20201224141445.163819-22-jjongsma@redhat.com> In-Reply-To: <20201224141445.163819-1-jjongsma@redhat.com> References: <20201224141445.163819-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Most of the header files no longer use the space-padded function name and parameter alignment. Update the style to be more consistent with other headers. Signed-off-by: Jonathon Jongsma Tested-by: Yan Fu tested-by should not be given. --- include/libvirt/libvirt-nodedev.h | 79 ++++++++++++++++--------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 71626bd837..663e8a9e5b 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -48,15 +48,14 @@ typedef struct _virNodeDevice virNodeDevice; typedef virNodeDevice *virNodeDevicePtr; =20 =20 -int virNodeNumOfDevices (virConnectPtr conn, - const char *cap, - unsigned int flags); - -int virNodeListDevices (virConnectPtr conn, - const char *cap, - char **const names, - int maxnames, - unsigned int flags); +int virNodeNumOfDevices(virConnectPtr conn, + const char *cap, + unsigned int flags); + +int virNodeListDevices(virConnectPtr conn, + const char *cap, + char **const names, + int maxnames, unsigned int flags); /* * virConnectListAllNodeDevices: * @@ -91,46 +90,50 @@ typedef enum { VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE =3D 1 << 30, /* Active= devices */ } virConnectListAllNodeDeviceFlags; =20 -int virConnectListAllNodeDevices (virConnectPtr conn, - virNodeDevicePtr **d= evices, - unsigned int flags); +int virConnectListAllNodeDevices(virConnectPtr conn, + virNodeDevicePtr **devices, + unsigned int flags); =20 -virNodeDevicePtr virNodeDeviceLookupByName (virConnectPtr conn, - const char *name); +virNodeDevicePtr virNodeDeviceLookupByName(virConnectPtr conn, + const char *name); =20 -virNodeDevicePtr virNodeDeviceLookupSCSIHostByWWN (virConnectPtr co= nn, - const char *wwnn, - const char *wwpn, - unsigned int fla= gs); +virNodeDevicePtr virNodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, + const char *wwnn, + const char *wwpn, + unsigned int flags); =20 -const char * virNodeDeviceGetName (virNodeDevicePtr dev); +const char *virNodeDeviceGetName(virNodeDevicePtr dev); =20 -const char * virNodeDeviceGetParent (virNodeDevicePtr dev); +const char *virNodeDeviceGetParent(virNodeDevicePtr dev); =20 -int virNodeDeviceNumOfCaps (virNodeDevicePtr dev); +int virNodeDeviceNumOfCaps(virNodeDevicePtr dev); =20 -int virNodeDeviceListCaps (virNodeDevicePtr dev, - char **const names, - int maxnames); +int virNodeDeviceListCaps(virNodeDevicePtr dev, + char **const names, + int maxnames); =20 -char * virNodeDeviceGetXMLDesc (virNodeDevicePtr dev, - unsigned int flags); +char * virNodeDeviceGetXMLDesc(virNodeDevicePtr dev, + unsigned int flags); =20 -int virNodeDeviceRef (virNodeDevicePtr dev); -int virNodeDeviceFree (virNodeDevicePtr dev); +int virNodeDeviceRef(virNodeDevicePtr dev); =20 -int virNodeDeviceDettach (virNodeDevicePtr dev); -int virNodeDeviceDetachFlags(virNodeDevicePtr dev, - const char *driverName, - unsigned int flags); -int virNodeDeviceReAttach (virNodeDevicePtr dev); -int virNodeDeviceReset (virNodeDevicePtr dev); +int virNodeDeviceFree(virNodeDevicePtr dev); =20 -virNodeDevicePtr virNodeDeviceCreateXML (virConnectPtr conn, - const char *xmlDesc, - unsigned int flags); +int virNodeDeviceDettach(virNodeDevicePtr dev); =20 -int virNodeDeviceDestroy (virNodeDevicePtr dev); +int virNodeDeviceDetachFlags(virNodeDevicePtr dev, + const char *driverName, + unsigned int flags); + +int virNodeDeviceReAttach(virNodeDevicePtr dev); + +int virNodeDeviceReset(virNodeDevicePtr dev); + +virNodeDevicePtr virNodeDeviceCreateXML(virConnectPtr conn, + const char *xmlDesc, + unsigned int flags); + +int virNodeDeviceDestroy(virNodeDevicePtr dev); =20 virNodeDevicePtr virNodeDeviceDefineXML(virConnectPtr conn, const char *xmlDesc, --=20 2.26.2