From nobody Thu May 2 16:47:59 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=1629498880; cv=none; d=zohomail.com; s=zohoarc; b=ITTvhljKoGUftj/6PgoEoIosY2OGgHFyajflYaJDEZnOHwK9Af4K4Y66N7+75Bn8rkNiq1nUQl1NEuzNwZ9diHV3HeB6WT8Xfwpz19oaiTqm71ENQFGMkhfZqKcZJlNRfIg4LPrBTEBzCG1V3sIH4Isr15gbmbr1JJaUSbVlTBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629498880; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v9aBS8vzwLhXihyCdV0EpLVWV44klfGx+xxhucVVeBw=; b=ezLs6sIldqH7LCcAOYohqUkcBlP7Ntt63l2Cc9EZ2DRaWXIdafxOu04u9UoSykWu9GRI9Hr1xPbw7mszlUsTR/tjtLvsAc+MBE801xMYHcdmmXSfThR+bDdyYnzwj6Nr/OXkKnRO1oMnvWSqizqnvxqBofosLxX6da5UPJDWUT8= 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) 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 1629498880220413.1092038979824; Fri, 20 Aug 2021 15:34:40 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-GHtb9mZNOeShrfXVdDxinA-1; Fri, 20 Aug 2021 18:34:37 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B011E2E76; Fri, 20 Aug 2021 22:34:32 +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 4EC371F5; Fri, 20 Aug 2021 22:34: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 CB6514A7CA; Fri, 20 Aug 2021 22:34:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17KMTeZG028144 for ; Fri, 20 Aug 2021 18:29:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id E57511F5; Fri, 20 Aug 2021 22:29:40 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-57.phx2.redhat.com [10.3.114.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 980141971B; Fri, 20 Aug 2021 22:29:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629498879; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=v9aBS8vzwLhXihyCdV0EpLVWV44klfGx+xxhucVVeBw=; b=HzDdMro2RuOB6ZcLgsPhjRtsPtkWMSMwniLAO1A9QLDRRlL+WUuYm6lpjDsgO39/+LX43z WQ/m9fGv/lgqbaHK9AmVunAfmCJWoq7h3MKWZYrhoITzqhiDgyGmzfTkLequyuL6UFWvjn 9gc0BwGsXbo23XKStkYribbJzs8aLug= X-MC-Unique: GHtb9mZNOeShrfXVdDxinA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 1/7] api: add virNodeDevice(Get|Set)Autostart() Date: Fri, 20 Aug 2021 17:29:29 -0500 Message-Id: <20210820222935.3414029-2-jjongsma@redhat.com> In-Reply-To: <20210820222935.3414029-1-jjongsma@redhat.com> References: <20210820222935.3414029-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629498881139100001 This will allow persistent mediated devices to be configured to be restarted automatically when the host reboots. Signed-off-by: Jonathon Jongsma Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- include/libvirt/libvirt-nodedev.h | 6 +++ src/driver-nodedev.h | 10 ++++ src/libvirt-nodedev.c | 76 +++++++++++++++++++++++++++++++ src/libvirt_public.syms | 2 + src/remote/remote_driver.c | 4 +- src/remote/remote_protocol.x | 29 +++++++++++- src/remote_protocol-structs | 12 +++++ 7 files changed, 137 insertions(+), 2 deletions(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 067d914d37..0e841ada8a 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -141,6 +141,12 @@ int virNodeDeviceUndefine(virNodeDevicePtr dev, int virNodeDeviceCreate(virNodeDevicePtr dev, unsigned int flags); =20 +int virNodeDeviceSetAutostart(virNodeDevicePtr dev, + int autostart); + +int virNodeDeviceGetAutostart(virNodeDevicePtr dev, + int *autostart); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h index dd56421a54..125f4cfd9e 100644 --- a/src/driver-nodedev.h +++ b/src/driver-nodedev.h @@ -87,6 +87,14 @@ typedef int (*virDrvNodeDeviceCreate)(virNodeDevicePtr dev, unsigned int flags); =20 +typedef int +(*virDrvNodeDeviceSetAutostart)(virNodeDevicePtr dev, + int autostart); + +typedef int +(*virDrvNodeDeviceGetAutostart)(virNodeDevicePtr dev, + int *autostart); + typedef int (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn, virNodeDevicePtr dev, @@ -128,4 +136,6 @@ struct _virNodeDeviceDriver { virDrvNodeDeviceDefineXML nodeDeviceDefineXML; virDrvNodeDeviceUndefine nodeDeviceUndefine; virDrvNodeDeviceCreate nodeDeviceCreate; + virDrvNodeDeviceSetAutostart nodeDeviceSetAutostart; + virDrvNodeDeviceGetAutostart nodeDeviceGetAutostart; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index e416c12534..68fc83203d 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -979,3 +979,79 @@ virConnectNodeDeviceEventDeregisterAny(virConnectPtr c= onn, virDispatchError(conn); return -1; } + +/** + * virNodeDeviceSetAutostart: + * @dev: the device object + * @autostart: whether the device should be automatically started + * + * Configure the node device to be automatically started when the host mac= hine + * boots or the parent device becomes available. + * + * Returns -1 in case of error, 0 in case of success + */ +int +virNodeDeviceSetAutostart(virNodeDevicePtr dev, + int autostart) +{ + VIR_DEBUG("dev=3D%p", dev); + + virResetLastError(); + + virCheckNodeDeviceReturn(dev, -1); + virCheckReadOnlyGoto(dev->conn->flags, error); + + if (dev->conn->nodeDeviceDriver && + dev->conn->nodeDeviceDriver->nodeDeviceSetAutostart) { + int retval =3D dev->conn->nodeDeviceDriver->nodeDeviceSetAutostart= (dev, autostart); + if (retval < 0) + goto error; + + return 0; + } + + virReportUnsupportedError(); + + error: + virDispatchError(dev->conn); + return -1; +} + + +/** + * virNodeDeviceGetAutostart: + * @dev: the device object + * @autostart: the value returned + * + * Provides a boolean value indicating whether the node device is configur= ed to + * be automatically started when the host machine boots or the parent devi= ce + * becomes available. + * + * Returns -1 in case of error, 0 in case of success + */ +int +virNodeDeviceGetAutostart(virNodeDevicePtr dev, + int *autostart) +{ + VIR_DEBUG("dev=3D%p", dev); + + virResetLastError(); + + virCheckNodeDeviceReturn(dev, -1); + virCheckReadOnlyGoto(dev->conn->flags, error); + + if (dev->conn->nodeDeviceDriver && + dev->conn->nodeDeviceDriver->nodeDeviceGetAutostart) { + int retval =3D dev->conn->nodeDeviceDriver->nodeDeviceGetAutostart= (dev, autostart); + if (retval < 0) + goto error; + + return 0; + } + + virReportUnsupportedError(); + + error: + virDispatchError(dev->conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 68f5e9c900..206b20f773 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -899,6 +899,8 @@ LIBVIRT_7.3.0 { LIBVIRT_7.7.0 { global: virNWFilterDefineXMLFlags; + virNodeDeviceSetAutostart; + virNodeDeviceGetAutostart; } LIBVIRT_7.3.0; =20 # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 9ee22e7e15..d8febcf46f 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8672,7 +8672,9 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceCreate =3D remoteNodeDeviceCreate, /* 7.3.0 */ .nodeDeviceDefineXML =3D remoteNodeDeviceDefineXML, /* 7.3.0 */ .nodeDeviceUndefine =3D remoteNodeDeviceUndefine, /* 7.3.0 */ - .nodeDeviceDestroy =3D remoteNodeDeviceDestroy /* 0.6.3 */ + .nodeDeviceDestroy =3D remoteNodeDeviceDestroy, /* 0.6.3 */ + .nodeDeviceGetAutostart =3D remoteNodeDeviceGetAutostart, /* 7.7.0 */ + .nodeDeviceSetAutostart =3D remoteNodeDeviceSetAutostart, /* 7.7.0 */ }; =20 static virNWFilterDriver nwfilter_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 56f610839e..c4f26ecb4c 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2173,6 +2173,19 @@ struct remote_node_device_create_args { unsigned int flags; }; =20 +struct remote_node_device_get_autostart_args { + remote_nonnull_string name; +}; + +struct remote_node_device_get_autostart_ret { + int autostart; +}; + +struct remote_node_device_set_autostart_args { + remote_nonnull_string name; + int autostart; +}; + =20 /* * Events Register/Deregister: @@ -6801,5 +6814,19 @@ enum remote_procedure { * @acl: nwfilter:write * @acl: nwfilter:save */ - REMOTE_PROC_NWFILTER_DEFINE_XML_FLAGS =3D 431 + REMOTE_PROC_NWFILTER_DEFINE_XML_FLAGS =3D 431, + + /** + * @generate: both + * @priority: high + * @acl: node_device:read + */ + REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART =3D 432, + + /** + * @generate: both + * @priority: high + * @acl: node_device:write + */ + REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART =3D 433 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index d51f12f781..dad3a418cb 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1622,6 +1622,16 @@ struct remote_node_device_create_args { remote_nonnull_string name; u_int flags; }; +struct remote_node_device_get_autostart_args { + remote_nonnull_string name; +}; +struct remote_node_device_get_autostart_ret { + int autostart; +}; +struct remote_node_device_set_autostart_args { + remote_nonnull_string name; + int autostart; +}; struct remote_connect_domain_event_register_ret { int cb_registered; }; @@ -3631,4 +3641,6 @@ enum remote_procedure { REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 429, REMOTE_PROC_NODE_DEVICE_CREATE =3D 430, REMOTE_PROC_NWFILTER_DEFINE_XML_FLAGS =3D 431, + REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART =3D 432, + REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART =3D 433, }; --=20 2.31.1 From nobody Thu May 2 16:47:59 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=1629498888; cv=none; d=zohomail.com; s=zohoarc; b=RCqqazfSgdCI4kbIrIFnIHv2+ovlV6c1xuN6maHAl4tMGCtW7zkFXqCytRJRzh7HFVBLCM/YDSDoQnFG/CRJvZ0pcaK4ALlNQgeB0PnlrBIuTPepvhEXu6HW7BUK61ZZ0oL4nUeTi/JtXZMdHSUTHmL3vhZOO4OT1hKJ+ejRGj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629498888; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=e5TDpanF1goXMzfROILLvxAPP7RCExB23e8ojX/RDPg=; b=U3Qff8mW4jQPgldsVQz0ilzDN4qlRoMMO+RbNtvdlknITrqCWLb0q6orBSsHFsJ7x9AtaHsHKKiORHrxQvbJZkj0EfCm7LpdCg9VImekoarwI44FHQuQFll1bauVlf9AwWnBmT+gru1TZPQzobSn7tgZNoD3yblwZ0w2DJc2WJ8= 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) 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 1629498888058563.463347017599; Fri, 20 Aug 2021 15:34:48 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-yvuIwHu-MqmZUMdMsQGphA-1; Fri, 20 Aug 2021 18:34:44 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B08EE1008064; Fri, 20 Aug 2021 22:34:39 +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 84A79E2C6; Fri, 20 Aug 2021 22:34:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D1600181A0F7; Fri, 20 Aug 2021 22:34:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17KMTfJm028149 for ; Fri, 20 Aug 2021 18:29:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 52E4E1971B; Fri, 20 Aug 2021 22:29:41 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-57.phx2.redhat.com [10.3.114.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F0931F5 for ; Fri, 20 Aug 2021 22:29:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629498887; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=e5TDpanF1goXMzfROILLvxAPP7RCExB23e8ojX/RDPg=; b=DrXF4UOJybBcS5riaUab9Lv/hvynJ0u8yYbmylSvH5RYzlAs3aHzWWU78iXPyiU5CZL8TC HsuWd+xFuPFoQOpXLv4Pq/3Huxb6TyB9RpCSJNrBGJyfwca6le5TLc3oof4Xv2pt2O0LpL 12ABi++E27dU7EWgjVccnaB/wxvjdCQ= X-MC-Unique: yvuIwHu-MqmZUMdMsQGphA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 2/7] nodedev: implement virNodeDevice(Get|Set)Autostart() Date: Fri, 20 Aug 2021 17:29:30 -0500 Message-Id: <20210820222935.3414029-3-jjongsma@redhat.com> In-Reply-To: <20210820222935.3414029-1-jjongsma@redhat.com> References: <20210820222935.3414029-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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) X-ZM-MESSAGEID: 1629498889687100001 Content-Type: text/plain; charset="utf-8" Implement autostart functionality for mediated devices. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/conf/node_device_conf.h | 1 + src/conf/virnodedeviceobj.c | 16 +++ src/conf/virnodedeviceobj.h | 6 ++ src/libvirt_private.syms | 2 + src/node_device/node_device_driver.c | 139 ++++++++++++++++++++++++++- src/node_device/node_device_driver.h | 13 +++ src/node_device/node_device_udev.c | 12 ++- 7 files changed, 185 insertions(+), 4 deletions(-) diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 786de85060..5a4d9c7a55 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -154,6 +154,7 @@ struct _virNodeDevCapMdev { virMediatedDeviceAttr **attributes; size_t nattributes; char *parent_addr; + bool autostart; }; =20 typedef struct _virNodeDevCapPCIDev virNodeDevCapPCIDev; diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 87e180f3ef..9a9841576a 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -41,6 +41,7 @@ struct _virNodeDeviceObj { used by testdriver */ bool active; bool persistent; + bool autostart; }; =20 struct _virNodeDeviceObjList { @@ -1034,6 +1035,21 @@ virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, } =20 =20 +bool +virNodeDeviceObjIsAutostart(virNodeDeviceObj *obj) +{ + return obj->autostart; +} + + +void +virNodeDeviceObjSetAutostart(virNodeDeviceObj *obj, + bool autostart) +{ + obj->autostart =3D autostart; +} + + typedef struct _PredicateHelperData PredicateHelperData; struct _PredicateHelperData { virNodeDeviceObjListPredicate predicate; diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 068c7c6f34..5f6d22e1f6 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -137,6 +137,12 @@ virNodeDeviceObjIsPersistent(virNodeDeviceObj *obj); void virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, bool persistent); +bool +virNodeDeviceObjIsAutostart(virNodeDeviceObj *obj); + +void +virNodeDeviceObjSetAutostart(virNodeDeviceObj *obj, + bool autostart); =20 typedef bool (*virNodeDeviceObjListPredicate)(virNodeDeviceObj *obj, const void *opaque); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 090ac80691..e78a8c8631 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1287,6 +1287,7 @@ virNetworkPortDefSaveStatus; virNodeDeviceObjEndAPI; virNodeDeviceObjGetDef; virNodeDeviceObjIsActive; +virNodeDeviceObjIsAutostart; virNodeDeviceObjIsPersistent; virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; @@ -1304,6 +1305,7 @@ virNodeDeviceObjListNumOfDevices; virNodeDeviceObjListRemove; virNodeDeviceObjListRemoveLocked; virNodeDeviceObjSetActive; +virNodeDeviceObjSetAutostart; virNodeDeviceObjSetPersistent; =20 =20 diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index db619aa2d8..bb18b24e53 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -621,11 +621,12 @@ nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, c= har **buf) size_t i; virNodeDevCapMdev *mdev =3D &def->caps->data.mdev; g_autoptr(virJSONValue) json =3D virJSONValueNewObject(); + const char *startval =3D mdev->autostart ? "auto" : "manual"; =20 if (virJSONValueObjectAppendString(json, "mdev_type", mdev->type) < 0) return -1; =20 - if (virJSONValueObjectAppendString(json, "start", "manual") < 0) + if (virJSONValueObjectAppendString(json, "start", startval) < 0) return -1; =20 if (mdev->attributes) { @@ -1014,6 +1015,46 @@ virMdevctlStart(virNodeDeviceDef *def) } =20 =20 +/* gets a virCommand object that executes a mdevctl command to set the + * 'autostart' property of the device to the specified value + */ +virCommand* +nodeDeviceGetMdevctlSetAutostartCommand(virNodeDeviceDef *def, + bool autostart, + char **errmsg) +{ + virCommand *cmd =3D virCommandNewArgList(MDEVCTL, + "modify", + "--uuid", + def->caps->data.mdev.uuid, + NULL); + + if (autostart) + virCommandAddArg(cmd, "--auto"); + else + virCommandAddArg(cmd, "--manual"); + + virCommandSetErrorBuffer(cmd, errmsg); + + return cmd; +} + + +static int +virMdevctlSetAutostart(virNodeDeviceDef *def, bool autostart, char **errms= g) +{ + int status; + g_autoptr(virCommand) cmd =3D NULL; + + cmd =3D nodeDeviceGetMdevctlSetAutostartCommand(def, autostart, errmsg= ); + + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + return 0; +} + + virCommand* nodeDeviceGetMdevctlListCommand(bool defined, char **output, @@ -1066,6 +1107,7 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, virJSONValue *attrs; g_autoptr(virNodeDeviceDef) child =3D g_new0(virNodeDeviceDef, 1); virNodeDeviceObj *parent_obj; + const char *start =3D NULL; =20 /* the child object should have a single key equal to its uuid. * The value is an object describing the properties of the mdev */ @@ -1094,6 +1136,8 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, mdev->parent_addr =3D g_strdup(parent); mdev->type =3D g_strdup(virJSONValueObjectGetString(props, "mdev_type")); + start =3D virJSONValueObjectGetString(props, "start"); + mdev->autostart =3D STREQ_NULLABLE(start, "auto"); =20 attrs =3D virJSONValueObjectGet(props, "attrs"); =20 @@ -1346,6 +1390,7 @@ nodeDeviceUpdateMediatedDevice(virNodeDeviceDef *def) =20 /* all devices returned by virMdevctlListDefined() are persistent */ virNodeDeviceObjSetPersistent(obj, true); + virNodeDeviceObjSetAutostart(obj, def->caps->data.mdev.autostart); =20 if (!defined) event =3D virNodeDeviceEventLifecycleNew(name, @@ -1649,10 +1694,12 @@ removeMissingPersistentMdev(virNodeDeviceObj *obj, =20 /* The device is active, but no longer defined by mdevctl. Keep the de= vice * in the list, but mark it as non-persistent */ - if (virNodeDeviceObjIsActive(obj)) + if (virNodeDeviceObjIsActive(obj)) { + virNodeDeviceObjSetAutostart(obj, false); virNodeDeviceObjSetPersistent(obj, false); - else + } else { remove =3D true; + } =20 virObjectEventStateQueue(driver->nodeDeviceEventState, event); =20 @@ -1762,6 +1809,92 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, if (virMediatedDeviceAttrsCopy(dstmdev, srcmdev)) ret =3D true; =20 + if (dstmdev->autostart !=3D srcmdev->autostart) { + ret =3D true; + dstmdev->autostart =3D srcmdev->autostart; + } + + return ret; +} + + +int +nodeDeviceSetAutostart(virNodeDevice *device, + int autostart) +{ + int ret =3D -1; + virNodeDeviceObj *obj =3D NULL; + virNodeDeviceDef *def =3D NULL; + + if (nodeDeviceInitWait() < 0) + return -1; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + def =3D virNodeDeviceObjGetDef(obj); + + if (virNodeDeviceSetAutostartEnsureACL(device->conn, def) < 0) + goto cleanup; + + if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + if (!virNodeDeviceObjIsPersistent(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cannot set autostart for transient dev= ice")); + goto cleanup; + } + + if (autostart !=3D virNodeDeviceObjIsAutostart(obj)) { + g_autofree char *errmsg =3D NULL; + + if (virMdevctlSetAutostart(def, autostart, &errmsg) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to set autostart on '%s': %s"), + def->name, + errmsg && errmsg[0] !=3D '\0' ? errmsg : _(= "Unknown Error")); + goto cleanup; + } + /* Due to mdevctl performance issues, it may take several seco= nds + * to re-query mdevctl for the defined devices. Because the md= evctl + * command returned without an error status, assume it was + * successful and set the object status directly here rather t= han + * waiting for the next query */ + virNodeDeviceObjSetAutostart(obj, autostart); + } + ret =3D 0; + } else { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("Unsupported device type")); + } + + cleanup: + virNodeDeviceObjEndAPI(&obj); + return ret; +} + + +int +nodeDeviceGetAutostart(virNodeDevice *device, + int *autostart) +{ + virNodeDeviceObj *obj =3D NULL; + virNodeDeviceDef *def =3D NULL; + int ret =3D -1; + + if (nodeDeviceInitWait() < 0) + return -1; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + def =3D virNodeDeviceObjGetDef(obj); + + if (virNodeDeviceGetAutostartEnsureACL(device->conn, def) < 0) + goto cleanup; + + *autostart =3D virNodeDeviceObjIsAutostart(obj); + ret =3D 0; + + cleanup: + virNodeDeviceObjEndAPI(&obj); return ret; } =20 diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index fdc92b8aef..17c7473d85 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -177,3 +177,16 @@ int nodeDeviceDefPostParse(virNodeDeviceDef *def, =20 int nodeDeviceDefValidate(virNodeDeviceDef *def, void *opaque); + +int +nodeDeviceSetAutostart(virNodeDevice *dev, + int autostart); + +int +nodeDeviceGetAutostart(virNodeDevice *dev, + int *autostart); + +virCommand* +nodeDeviceGetMdevctlSetAutostartCommand(virNodeDeviceDef *def, + bool autostart, + char **errmsg); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 90a64f16b0..73334c1cc7 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1504,6 +1504,8 @@ udevAddOneDevice(struct udev_device *device) bool new_device =3D true; int ret =3D -1; bool was_persistent =3D false; + bool autostart =3D false; + bool is_mdev; =20 def =3D g_new0(virNodeDeviceDef, 1); =20 @@ -1525,12 +1527,16 @@ udevAddOneDevice(struct udev_device *device) if (udevSetParent(device, def) !=3D 0) goto cleanup; =20 + is_mdev =3D def->caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV; + if ((obj =3D virNodeDeviceObjListFindByName(driver->devs, def->name)))= { objdef =3D virNodeDeviceObjGetDef(obj); =20 - if (def->caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) + if (is_mdev) nodeDeviceDefCopyFromMdevctl(def, objdef); was_persistent =3D virNodeDeviceObjIsPersistent(obj); + autostart =3D virNodeDeviceObjIsAutostart(obj); + /* If the device was defined by mdevctl and was never instantiated= , it * won't have a sysfs path. We need to emit a CREATED event... */ new_device =3D (objdef->sysfs_path =3D=3D NULL); @@ -1543,6 +1549,7 @@ udevAddOneDevice(struct udev_device *device) if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; virNodeDeviceObjSetPersistent(obj, was_persistent); + virNodeDeviceObjSetAutostart(obj, autostart); objdef =3D virNodeDeviceObjGetDef(obj); =20 if (new_device) @@ -1946,6 +1953,7 @@ udevSetupSystemDev(void) goto cleanup; =20 virNodeDeviceObjSetActive(obj, true); + virNodeDeviceObjSetAutostart(obj, true); =20 virNodeDeviceObjEndAPI(&obj); =20 @@ -2350,6 +2358,8 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceDefineXML =3D nodeDeviceDefineXML, /* 7.3.0 */ .nodeDeviceUndefine =3D nodeDeviceUndefine, /* 7.3.0 */ .nodeDeviceCreate =3D nodeDeviceCreate, /* 7.3.0 */ + .nodeDeviceSetAutostart =3D nodeDeviceSetAutostart, /* 7.7.0 */ + .nodeDeviceGetAutostart =3D nodeDeviceGetAutostart, /* 7.7.0 */ }; =20 =20 --=20 2.31.1 From nobody Thu May 2 16:47:59 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=1629498919; cv=none; d=zohomail.com; s=zohoarc; b=gPo2fZOtIiV/6n/pgimDkjd7q9mC8Utps6gpZMd++nfYmGFfhgywwVnDCb8haYE+K1ZX0kPkT4d2VZO8lOK5C9/JwjDhet1oWuWQfFL9ZFyrx3bRdUykD0OLxFGvJh0X/RpGNHe9BCZtoTADbVevB6v2+vcM1nyJTW7MQ2WKx6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629498919; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lhHDeF+VML76Y20EQiEVyYAz8gcltG4ezpT6xtYNohA=; b=Lw/9lMKjBAAfdqh5VQFcnyB+rFxvxI/GjouuOdsK1Jj+Ki1FfPzZhZwrHnIcSty4zdtG+OMabJHPluVKnvYnfkImaIUlOCqeCM6+34WDP9jBi0vnUNWtUlnuejDXZQmnFJqnAwHmaxRWHpkmlibNO6k2pr9FSX1YRj10NspsNmk= 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) 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 1629498919601104.3628571662972; Fri, 20 Aug 2021 15:35:19 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-496-sLwKngzdOfK9AfGUnNkFFg-1; Fri, 20 Aug 2021 18:35:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34FB28015C7; Fri, 20 Aug 2021 22:35:11 +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 9927A6A905; Fri, 20 Aug 2021 22:35:10 +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 5C5844A7C9; Fri, 20 Aug 2021 22:35:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17KMTfCG028154 for ; Fri, 20 Aug 2021 18:29:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id B00371F5; Fri, 20 Aug 2021 22:29:41 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-57.phx2.redhat.com [10.3.114.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7060F1971B; Fri, 20 Aug 2021 22:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629498918; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=lhHDeF+VML76Y20EQiEVyYAz8gcltG4ezpT6xtYNohA=; b=cJsMXEoowy1BEYilnoQAMm0zJwccD1edyDrfSY1jWu6tnXSR9dyVo7VShcn4VRqyPpZpjT 7HG6aHLv25v3Arev6t+nIMFkAUxJ2T+ilTv/nBm4fWM6OugNr53X7GmSjHSuLkXoVUhSQC f4YfHFcUWKYrDzTHSPrkVfRnmXSk8RA= X-MC-Unique: sLwKngzdOfK9AfGUnNkFFg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 3/7] nodedev: Add tests for mdevctl autostart command Date: Fri, 20 Aug 2021 17:29:31 -0500 Message-Id: <20210820222935.3414029-4-jjongsma@redhat.com> In-Reply-To: <20210820222935.3414029-1-jjongsma@redhat.com> References: <20210820222935.3414029-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629498919964100001 Signed-off-by: Jonathon Jongsma Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- .../nodedevmdevctldata/mdevctl-autostart.argv | 8 +++ tests/nodedevmdevctltest.c | 55 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 tests/nodedevmdevctldata/mdevctl-autostart.argv diff --git a/tests/nodedevmdevctldata/mdevctl-autostart.argv b/tests/nodede= vmdevctldata/mdevctl-autostart.argv new file mode 100644 index 0000000000..9b441e9466 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-autostart.argv @@ -0,0 +1,8 @@ +mdevctl \ +modify \ +--uuid d069d019-36ea-4111-8f0a-8c9a70e21366 \ +--auto +mdevctl \ +modify \ +--uuid d069d019-36ea-4111-8f0a-8c9a70e21366 \ +--manual diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 3d1a7e4b6c..92d3c75766 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -124,6 +124,56 @@ testMdevctlHelper(const void *data) } =20 =20 +static int +testMdevctlAutostart(const void *data G_GNUC_UNUSED) +{ + g_autoptr(virNodeDeviceDef) def =3D NULL; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + const char *actualCmdline =3D NULL; + int ret =3D -1; + g_autoptr(virCommand) enablecmd =3D NULL; + g_autoptr(virCommand) disablecmd =3D NULL; + g_autofree char *errmsg =3D NULL; + /* just concatenate both calls into the same output file */ + g_autofree char *cmdlinefile =3D + g_strdup_printf("%s/nodedevmdevctldata/mdevctl-autostart.argv", + abs_srcdir); + g_autofree char *mdevxml =3D + g_strdup_printf("%s/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a= _8c9a70e21366.xml", + abs_srcdir); + g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); + + if (!(def =3D virNodeDeviceDefParseFile(mdevxml, CREATE_DEVICE, VIRT_T= YPE, + &parser_callbacks, NULL))) + return -1; + + virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL); + + if (!(enablecmd =3D nodeDeviceGetMdevctlSetAutostartCommand(def, true,= &errmsg))) + goto cleanup; + + if (virCommandRun(enablecmd, NULL) < 0) + goto cleanup; + + if (!(disablecmd =3D nodeDeviceGetMdevctlSetAutostartCommand(def, fals= e, &errmsg))) + goto cleanup; + + if (virCommandRun(disablecmd, NULL) < 0) + goto cleanup; + + if (!(actualCmdline =3D virBufferCurrentContent(&buf))) + goto cleanup; + + if (virTestCompareToFileFull(actualCmdline, cmdlinefile, false) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&buf); + return ret; +} + static int testMdevctlListDefined(const void *data G_GNUC_UNUSED) { @@ -378,6 +428,9 @@ mymain(void) #define DO_TEST_LIST_DEFINED() \ DO_TEST_FULL("list defined mdevs", testMdevctlListDefined, NULL) =20 +#define DO_TEST_AUTOSTART() \ + DO_TEST_FULL("autostart mdevs", testMdevctlAutostart, NULL) + #define DO_TEST_PARSE_JSON(filename) \ DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filenam= e) =20 @@ -401,6 +454,8 @@ mymain(void) =20 DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); =20 + DO_TEST_AUTOSTART(); + done: nodedevTestDriverFree(driver); =20 --=20 2.31.1 From nobody Thu May 2 16:47:59 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=1629498964; cv=none; d=zohomail.com; s=zohoarc; b=k3BsBi2PmUgxZ8+SFoDoL4A7oZS/M4K6GYrGSPoDZvKgPBJ3g+rp9AH7gjuvaFxn9mU/JY6oyoKmBx9QtFVR9PiZSYm4bOauwlXqZeRz7NQ/M3DYLRsNecoJLU6Nl04Jo+t3lnh4FPCprm/uL2iZxI0CZCE827o5IphUu6pXkKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629498964; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0M0yX9VUg+Q25cDgIxUHrCufNOWAbjPWpuG2EsSaU78=; b=Rf1vqErsteRQY/bi5Q7tdasKW1HcAs2sL+0871PpkMLX8F22DViKavgMr/oC/ZPjXFvy+xoENTToZKY7Wo3EEOi7ojGs6nt2vKcFYoeHrozInewJEu03ckqyb3QsGGeuf49MU2u8Ev23Nfobry3P/k2GZc8rxxPFqknvwBNC/gA= 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) 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 1629498964138973.9726411153073; Fri, 20 Aug 2021 15:36:04 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-453-mTYEMwp3OWq1PyVk5nfV5w-1; Fri, 20 Aug 2021 18:35:18 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DAE6E1082921; Fri, 20 Aug 2021 22:35: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 B52EB10190AA; Fri, 20 Aug 2021 22:35: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 7EB58181A1D3; Fri, 20 Aug 2021 22:35:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17KMTgXU028161 for ; Fri, 20 Aug 2021 18:29:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 16F8590BA; Fri, 20 Aug 2021 22:29:42 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-57.phx2.redhat.com [10.3.114.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD4281F5; Fri, 20 Aug 2021 22:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629498963; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=0M0yX9VUg+Q25cDgIxUHrCufNOWAbjPWpuG2EsSaU78=; b=WVF4sOyPS58WqVwPItonORQPliWB+UHIjtx/0xNnm2QYwzpwRicD+RLkdPBuV8U/ORyICs pU4HFVHj7c8HUzqvhe3mYskhBfZvfwrucy48CVJVKWjY0CUzJ3rDRCtAfVcA5rvGJNdhni TipAhKExnOovwmXY9Fr/vYyAw2Klo1g= X-MC-Unique: mTYEMwp3OWq1PyVk5nfV5w-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 4/7] virsh: add nodedev-autostart Date: Fri, 20 Aug 2021 17:29:32 -0500 Message-Id: <20210820222935.3414029-5-jjongsma@redhat.com> In-Reply-To: <20210820222935.3414029-1-jjongsma@redhat.com> References: <20210820222935.3414029-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629498965042100001 Add ability to set node devices to autostart on boot or parent device availability. Signed-off-by: Jonathon Jongsma Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- docs/manpages/virsh.rst | 15 +++++++++ tools/virsh-nodedev.c | 71 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index e0cdabf3aa..08097a45bf 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5131,6 +5131,21 @@ When *--timestamp* is used, a human-readable timesta= mp will be printed before the event. =20 =20 +nodedev-autostart +----------------- + +**Syntax:** + +:: + + nodedev-autostart [--disable] device + +Configure a device to be automatically started when the host machine boots= or +the parent device becomes available. With *--disable*, the device will be = set +to manual mode and will no longer be automatically started by the host. Th= is +command is only supported for persistently-defined mediated devices. + + VIRTUAL NETWORK COMMANDS =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 945ccc7f45..0a70029fc7 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1153,6 +1153,71 @@ cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cm= d) } =20 =20 +/* + * "nodedev-autostart" command + */ +static const vshCmdInfo info_node_device_autostart[] =3D { + {.name =3D "help", + .data =3D N_("autostart a defined node device") + }, + {.name =3D "desc", + .data =3D N_("Configure a node device to be automatically started at = boot.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_node_device_autostart[] =3D { + {.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 "disable", + .type =3D VSH_OT_BOOL, + .help =3D N_("disable autostarting") + }, + {.name =3D NULL} +}; + +static bool +cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd) +{ + virNodeDevice *dev =3D NULL; + bool ret =3D false; + const char *name =3D NULL; + int autostart; + + if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) + return false; + + dev =3D vshFindNodeDevice(ctl, name); + + if (!dev) goto cleanup; + + autostart =3D !vshCommandOptBool(cmd, "disable"); + + if (virNodeDeviceSetAutostart(dev, autostart) < 0) { + if (autostart) + vshError(ctl, _("failed to mark device %s as autostarted"), na= me); + else + vshError(ctl, _("failed to unmark device %s as autostarted"), = name); + goto cleanup; + } + + if (autostart) + vshPrintExtra(ctl, _("Device %s marked as autostarted\n"), name); + else + vshPrintExtra(ctl, _("Device %s unmarked as autostarted\n"), name); + + ret =3D true; + cleanup: + if (dev) + virNodeDeviceFree(dev); + return ret; +} + + const vshCmdDef nodedevCmds[] =3D { {.name =3D "nodedev-create", .handler =3D cmdNodeDeviceCreate, @@ -1224,5 +1289,11 @@ const vshCmdDef nodedevCmds[] =3D { .info =3D info_node_device_start, .flags =3D 0 }, + {.name =3D "nodedev-autostart", + .handler =3D cmdNodeDeviceAutostart, + .opts =3D opts_node_device_autostart, + .info =3D info_node_device_autostart, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.31.1 From nobody Thu May 2 16:47:59 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=1629498891; cv=none; d=zohomail.com; s=zohoarc; b=l4tAcNeV0PqPRED2PlUGMGzEz7UMzGFZZPCGC1vtsfP4yTtaD5/1Pdh9Tp+K5NOPHgMAUE2FHfHvjOoPunLif2lViyVbNLRkGXrxSgyfqtW0EcU6tACfcXLCtklRG/3V2UvYGU+JDyg2KgzXycYXrndKW4/M7bwujKnpzPZg4sY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629498891; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2tkKqq3x3Bw5gQR0DaLLdnYaJpW28ozZ6NDxZ32JPRQ=; b=FOlAAX7lUhQ0acsKM0/Twtuc/H7eK4R0ngj7j3ZDUCl4pW0ui5nwe5fzK6JZTkErQh9LaRDZuOCE9NwcrecIQ8qcsognSTFooi9QFkBuLhjcpaC/eQuZ1+v4gyo0GatZ6/XXLmhQrctwZrCATHWEf4PMQCYq88Ghu0wkgUS5fLU= 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) 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 1629498891724688.0545439396873; Fri, 20 Aug 2021 15:34:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-542-pWte2ulZPmWqp7Q7zi5tfw-1; Fri, 20 Aug 2021 18:34:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA3F587180F; Fri, 20 Aug 2021 22:34:43 +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 B896813AC8; Fri, 20 Aug 2021 22:34:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 87285181A12D; Fri, 20 Aug 2021 22:34:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17KMTgla028168 for ; Fri, 20 Aug 2021 18:29:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 749791A26A; Fri, 20 Aug 2021 22:29:42 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-57.phx2.redhat.com [10.3.114.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 351CE1971B; Fri, 20 Aug 2021 22:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629498890; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=2tkKqq3x3Bw5gQR0DaLLdnYaJpW28ozZ6NDxZ32JPRQ=; b=Fft7sedNG/byXmZexmIfjP7wXyHpow2T2D7lRnSz0omDjgXLdUQWB5KpdI2mQ6pepwehvv Q/hF9pueH2LECHre5aOwTU7jWLEzcpdQVJ6Zn9QIrNaP30SwTSkbYQVdMlB6o1TCizdPrQ mtCD7O957fRs8MM3uyqD92LfeaZHEGw= X-MC-Unique: pWte2ulZPmWqp7Q7zi5tfw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 5/7] api: add virNodeDeviceIsPersistent()/IsActive() Date: Fri, 20 Aug 2021 17:29:33 -0500 Message-Id: <20210820222935.3414029-6-jjongsma@redhat.com> In-Reply-To: <20210820222935.3414029-1-jjongsma@redhat.com> References: <20210820222935.3414029-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629498892030100001 These two public APIs are implemented for almost all other objects that have a concept of persistent definition and activatability. Now that we have node devices (mdevs) that can be defined and inactive, it will be useful to query the persistent/active state of node devices as well. Signed-off-by: Jonathon Jongsma Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- include/libvirt/libvirt-nodedev.h | 4 ++ src/driver-nodedev.h | 8 ++++ src/libvirt-nodedev.c | 65 +++++++++++++++++++++++++++++++ src/libvirt_public.syms | 2 + src/remote/remote_driver.c | 2 + src/remote/remote_protocol.x | 33 +++++++++++++++- src/remote_protocol-structs | 14 +++++++ 7 files changed, 127 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 0e841ada8a..e492634217 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -147,6 +147,10 @@ int virNodeDeviceSetAutostart(virNodeDevicePtr dev, int virNodeDeviceGetAutostart(virNodeDevicePtr dev, int *autostart); =20 +int virNodeDeviceIsPersistent(virNodeDevicePtr dev); + +int virNodeDeviceIsActive(virNodeDevicePtr dev); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h index 125f4cfd9e..167a8166dd 100644 --- a/src/driver-nodedev.h +++ b/src/driver-nodedev.h @@ -95,6 +95,12 @@ typedef int (*virDrvNodeDeviceGetAutostart)(virNodeDevicePtr dev, int *autostart); =20 +typedef int +(*virDrvNodeDeviceIsPersistent)(virNodeDevicePtr dev); + +typedef int +(*virDrvNodeDeviceIsActive)(virNodeDevicePtr dev); + typedef int (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn, virNodeDevicePtr dev, @@ -138,4 +144,6 @@ struct _virNodeDeviceDriver { virDrvNodeDeviceCreate nodeDeviceCreate; virDrvNodeDeviceSetAutostart nodeDeviceSetAutostart; virDrvNodeDeviceGetAutostart nodeDeviceGetAutostart; + virDrvNodeDeviceIsPersistent nodeDeviceIsPersistent; + virDrvNodeDeviceIsActive nodeDeviceIsActive; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index 68fc83203d..8ad1e9cb9e 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -1055,3 +1055,68 @@ virNodeDeviceGetAutostart(virNodeDevicePtr dev, virDispatchError(dev->conn); return -1; } + +/** + * virNodeDeviceIsPersistent: + * @dev: pointer to the nodedev object + * + * Determine if the node device has a persistent configuration + * which means it will still exist after shutting down + * + * Returns 1 if persistent, 0 if transient, -1 on error + */ +int +virNodeDeviceIsPersistent(virNodeDevicePtr dev) +{ + VIR_DEBUG("dev=3D%p", dev); + + virResetLastError(); + + virCheckNodeDeviceReturn(dev, -1); + + if (dev->conn->nodeDeviceDriver && + dev->conn->nodeDeviceDriver->nodeDeviceIsPersistent) { + int ret; + ret =3D dev->conn->nodeDeviceDriver->nodeDeviceIsPersistent(dev); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(dev->conn); + return -1; +} + + +/** + * virNodeDeviceIsActive: + * @dev: pointer to the node device object + * + * Determine if the node device is currently active + * + * Returns 1 if active, 0 if inactive, -1 on error + */ +int virNodeDeviceIsActive(virNodeDevicePtr dev) +{ + VIR_DEBUG("dev=3D%p", dev); + + virResetLastError(); + + virCheckNodeDeviceReturn(dev, -1); + + if (dev->conn->nodeDeviceDriver && + dev->conn->nodeDeviceDriver->nodeDeviceIsActive) { + int ret; + ret =3D dev->conn->nodeDeviceDriver->nodeDeviceIsActive(dev); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(dev->conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 206b20f773..a4ae48a6c3 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -901,6 +901,8 @@ LIBVIRT_7.7.0 { virNWFilterDefineXMLFlags; virNodeDeviceSetAutostart; virNodeDeviceGetAutostart; + virNodeDeviceIsPersistent; + virNodeDeviceIsActive; } LIBVIRT_7.3.0; =20 # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index d8febcf46f..ba1999f468 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8675,6 +8675,8 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceDestroy =3D remoteNodeDeviceDestroy, /* 0.6.3 */ .nodeDeviceGetAutostart =3D remoteNodeDeviceGetAutostart, /* 7.7.0 */ .nodeDeviceSetAutostart =3D remoteNodeDeviceSetAutostart, /* 7.7.0 */ + .nodeDeviceIsPersistent =3D remoteNodeDeviceIsPersistent, /* 7.7.0 */ + .nodeDeviceIsActive =3D remoteNodeDeviceIsActive, /* 7.7.0 */ }; =20 static virNWFilterDriver nwfilter_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index c4f26ecb4c..1815867b12 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2186,6 +2186,22 @@ struct remote_node_device_set_autostart_args { int autostart; }; =20 +struct remote_node_device_is_persistent_args { + remote_nonnull_string name; +}; + +struct remote_node_device_is_persistent_ret { + int persistent; +}; + +struct remote_node_device_is_active_args { + remote_nonnull_string name; +}; + +struct remote_node_device_is_active_ret { + int active; +}; + =20 /* * Events Register/Deregister: @@ -6828,5 +6844,20 @@ enum remote_procedure { * @priority: high * @acl: node_device:write */ - REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART =3D 433 + REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART =3D 433, + + /** + * @generate: both + * @priority: high + * @acl: node_device:read + */ + REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT =3D 434, + + /** + * @generate: both + * @priority: high + * @acl: node_device:read + */ + REMOTE_PROC_NODE_DEVICE_IS_ACTIVE =3D 435 + }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index dad3a418cb..86cccff048 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1632,6 +1632,18 @@ struct remote_node_device_set_autostart_args { remote_nonnull_string name; int autostart; }; +struct remote_node_device_is_persistent_args { + remote_nonnull_string name; +}; +struct remote_node_device_is_persistent_ret { + int persistent; +}; +struct remote_node_device_is_active_args { + remote_nonnull_string name; +}; +struct remote_node_device_is_active_ret { + int active; +}; struct remote_connect_domain_event_register_ret { int cb_registered; }; @@ -3643,4 +3655,6 @@ enum remote_procedure { REMOTE_PROC_NWFILTER_DEFINE_XML_FLAGS =3D 431, REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART =3D 432, REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART =3D 433, + REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT =3D 434, + REMOTE_PROC_NODE_DEVICE_IS_ACTIVE =3D 435, }; --=20 2.31.1 From nobody Thu May 2 16:47:59 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=1629498925; cv=none; d=zohomail.com; s=zohoarc; b=LuZ3xw1hBtCyzbWd1/KCh3sdthtK3iWiPA0jYiZVDEV+aBg3XZ1D4Lwo8wrTpx7DFIrWLxOMSlggSx88OzeIBL+iwMW3Q88DwF8faRehJ04CZAi2nPpS7uWCiXNwhL3v+qWeWfRTTeE4gtzStMZmRarGZXzzbuG5MPIyYC+PdMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629498925; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=avDiUmgWwqTQ6N+zqzpsNEbuX2Y7LL94w8Sh7BpUIwA=; b=X9+MTZK/WKRp/MjihJN7ht9BXcoFap18zYWFoyVhVttz6wEAKFRj4ZT4w+jvzK/yeuBn4jXzJjDYutCW/qMn+Z+6iiYzlxEfApw8s1SwX8ul9OcIB8ENzMe0ClWNjVty30sMSRgVNwSc22iVyWRKZzZBw6q/kZ1YGKKiArDIR30= 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) 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 1629498925224779.6852741208153; Fri, 20 Aug 2021 15:35:25 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-306-r-fDyrhMOZmtikcoWfC_Jg-1; Fri, 20 Aug 2021 18:35:21 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30BD0871812; Fri, 20 Aug 2021 22:35:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 11EC869FAE; Fri, 20 Aug 2021 22:35:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D159F4A7CD; Fri, 20 Aug 2021 22:35:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17KMTgFK028176 for ; Fri, 20 Aug 2021 18:29:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id D13991A26A; Fri, 20 Aug 2021 22:29:42 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-57.phx2.redhat.com [10.3.114.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 934451F5; Fri, 20 Aug 2021 22:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629498924; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=avDiUmgWwqTQ6N+zqzpsNEbuX2Y7LL94w8Sh7BpUIwA=; b=boNHfYaprvBEKZFua7pbMxoFZBp192tsEEspCNmGxVaJpYqLQIchfYTwBWZZRl48X/FQVO 1SIMh/1jeHeR8N+rHvA2GHobtU6ALkf5l98jICw/IUukesxqbHGMu1UeA0+VF3Kdan4av8 ShUnwpfO1zXNQS1fCJW74jKUo4LSIeY= X-MC-Unique: r-fDyrhMOZmtikcoWfC_Jg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 6/7] nodedev: Implement virNodeDeviceIsPersistent()/IsActive() Date: Fri, 20 Aug 2021 17:29:34 -0500 Message-Id: <20210820222935.3414029-7-jjongsma@redhat.com> In-Reply-To: <20210820222935.3414029-1-jjongsma@redhat.com> References: <20210820222935.3414029-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629498926389100001 Implement these new API functions in the nodedev driver. Signed-off-by: Jonathon Jongsma Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/node_device/node_device_driver.c | 50 ++++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 6 ++++ src/node_device/node_device_udev.c | 10 ++++-- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index bb18b24e53..3bc6eb1c11 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1989,3 +1989,53 @@ int nodeDeviceDefValidate(virNodeDeviceDef *def, } return 0; } + + +int +nodeDeviceIsPersistent(virNodeDevice *device) +{ + virNodeDeviceObj *obj =3D NULL; + virNodeDeviceDef *def =3D NULL; + int ret =3D -1; + + if (nodeDeviceInitWait() < 0) + return -1; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + def =3D virNodeDeviceObjGetDef(obj); + + if (virNodeDeviceIsPersistentEnsureACL(device->conn, def) < 0) + goto cleanup; + + ret =3D virNodeDeviceObjIsPersistent(obj); + + cleanup: + virNodeDeviceObjEndAPI(&obj); + return ret; +} + + +int +nodeDeviceIsActive(virNodeDevice *device) +{ + virNodeDeviceObj *obj =3D NULL; + virNodeDeviceDef *def =3D NULL; + int ret =3D -1; + + if (nodeDeviceInitWait() < 0) + return -1; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + def =3D virNodeDeviceObjGetDef(obj); + + if (virNodeDeviceIsActiveEnsureACL(device->conn, def) < 0) + goto cleanup; + + ret =3D virNodeDeviceObjIsActive(obj); + + cleanup: + virNodeDeviceObjEndAPI(&obj); + return ret; +} diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 17c7473d85..7311b603ac 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -186,6 +186,12 @@ int nodeDeviceGetAutostart(virNodeDevice *dev, int *autostart); =20 +int +nodeDeviceIsPersistent(virNodeDevice *dev); + +int +nodeDeviceIsActive(virNodeDevice *dev); + virCommand* nodeDeviceGetMdevctlSetAutostartCommand(virNodeDeviceDef *def, bool autostart, diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 73334c1cc7..0f1770f771 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1503,7 +1503,7 @@ udevAddOneDevice(struct udev_device *device) virObjectEvent *event =3D NULL; bool new_device =3D true; int ret =3D -1; - bool was_persistent =3D false; + bool persistent =3D false; bool autostart =3D false; bool is_mdev; =20 @@ -1534,7 +1534,8 @@ udevAddOneDevice(struct udev_device *device) =20 if (is_mdev) nodeDeviceDefCopyFromMdevctl(def, objdef); - was_persistent =3D virNodeDeviceObjIsPersistent(obj); + + persistent =3D virNodeDeviceObjIsPersistent(obj); autostart =3D virNodeDeviceObjIsAutostart(obj); =20 /* If the device was defined by mdevctl and was never instantiated= , it @@ -1548,7 +1549,7 @@ udevAddOneDevice(struct udev_device *device) * and the current definition will take its place. */ if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; - virNodeDeviceObjSetPersistent(obj, was_persistent); + virNodeDeviceObjSetPersistent(obj, persistent); virNodeDeviceObjSetAutostart(obj, autostart); objdef =3D virNodeDeviceObjGetDef(obj); =20 @@ -1954,6 +1955,7 @@ udevSetupSystemDev(void) =20 virNodeDeviceObjSetActive(obj, true); virNodeDeviceObjSetAutostart(obj, true); + virNodeDeviceObjSetPersistent(obj, true); =20 virNodeDeviceObjEndAPI(&obj); =20 @@ -2360,6 +2362,8 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceCreate =3D nodeDeviceCreate, /* 7.3.0 */ .nodeDeviceSetAutostart =3D nodeDeviceSetAutostart, /* 7.7.0 */ .nodeDeviceGetAutostart =3D nodeDeviceGetAutostart, /* 7.7.0 */ + .nodeDeviceIsPersistent =3D nodeDeviceIsPersistent, /* 7.7.0 */ + .nodeDeviceIsActive =3D nodeDeviceIsActive, /* 7.7.0 */ }; =20 =20 --=20 2.31.1 From nobody Thu May 2 16:47:59 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=1629498928; cv=none; d=zohomail.com; s=zohoarc; b=UwA1Pp6Q+c4aj2AG9t5U+LO2DP8NyrJPwcVO9dv9RWU7e4WG1TlgsfNQfDvrkcrL30A9lqtGfMLWmoz6Atc70/aM6poapO1KSujNX4PAAaf236SKpVVnSoeb1V+bqZqrKxEQGFVjmu9AGqYcDkNfUGyRJDovKxEMY3v7KLOngIQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629498928; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mWocI7j3vAnFDj0gN77u7Qy0XQP+cC5U0qlO1bhHEew=; b=KYo1+wNZe+tL06ruLofOtIwpEM3eAaQJQubYHLhGvXuZoCCKm3BGC8RY516GL0kRt15F1uRcLHE13Qn8FtUUpDGbS3eng1uxbQTWuW3ljWhqxTkK8PGBH4Gupw3cP6yiTS9SQlXMBwYD9fLykSs7DH2qrN3EhAE951UbmYxL1G4= 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) 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 1629498928711207.3625188863175; Fri, 20 Aug 2021 15:35:28 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-500-CaP_FD1TOISGJbdK3EEKLw-1; Fri, 20 Aug 2021 18:35:25 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1443C1082921; Fri, 20 Aug 2021 22:35: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 E2F9F10190AA; Fri, 20 Aug 2021 22:35:19 +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 AB4804A707; Fri, 20 Aug 2021 22:35:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17KMThpB028183 for ; Fri, 20 Aug 2021 18:29:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 389521971B; Fri, 20 Aug 2021 22:29:43 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-57.phx2.redhat.com [10.3.114.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF3EF1A26A; Fri, 20 Aug 2021 22:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629498927; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=mWocI7j3vAnFDj0gN77u7Qy0XQP+cC5U0qlO1bhHEew=; b=TS7FM/85E0CRgKa6TXvio3EKu9fT8aHbIj5D48gPqsWniBFxcw0p7jAYboE6goxvrPRuAR uR4yNb56q5+i4jPosLyNd/lXmoTO1HeffypML4lmoenLwkY51+Nnx/gNpQEcDl85qc7Xbq bbcxte/XmTNuI6hNumQql92CAALI4Qw= X-MC-Unique: CaP_FD1TOISGJbdK3EEKLw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 7/7] virsh: add nodedev-info Date: Fri, 20 Aug 2021 17:29:35 -0500 Message-Id: <20210820222935.3414029-8-jjongsma@redhat.com> In-Reply-To: <20210820222935.3414029-1-jjongsma@redhat.com> References: <20210820222935.3414029-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629498930739100001 This is currently the only way to view the 'autostart' property for a node device in virsh. Signed-off-by: Jonathon Jongsma Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- docs/manpages/virsh.rst | 12 ++++++++ tools/virsh-nodedev.c | 68 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 08097a45bf..af8c4cb9eb 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5057,6 +5057,18 @@ be either device name or wwn pair in "wwnn,wwpn" for= mat (only works for HBA). =20 =20 +nodedev-info +------------ + +**Syntax:** + +:: + + nodedev-info device + +Returns basic information about the *device* object. + + nodedev-list ------------ =20 diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 0a70029fc7..f1b4eb94bf 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1218,6 +1218,68 @@ cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd= *cmd) } =20 =20 +/* + * "nodedev-info" command + */ +static const vshCmdInfo info_node_device_info[] =3D { + {.name =3D "help", + .data =3D N_("node device information") + }, + {.name =3D "desc", + .data =3D N_("Returns basic information about the node device") + }, + {.name =3D NULL} +}; + + +static const vshCmdOptDef opts_node_device_info[] =3D { + {.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 +cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd) +{ + virNodeDevicePtr device =3D NULL; + const char *device_value =3D NULL; + bool ret =3D false; + int autostart; + const char *parent =3D NULL; + + if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) + return false; + + device =3D vshFindNodeDevice(ctl, device_value); + + if (!device) + goto cleanup; + + parent =3D virNodeDeviceGetParent(device); + vshPrint(ctl, "%-15s %s\n", _("Name:"), virNodeDeviceGetName(device)); + vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : ""); + vshPrint(ctl, "%-15s %s\n", _("Active:"), virNodeDeviceIsActive(device= ) ? + _("yes") : _("no")); + vshPrint(ctl, "%-15s %s\n", _("Persistent:"), + virNodeDeviceIsPersistent(device) ? _("yes") : _("no")); + if (virNodeDeviceGetAutostart(device, &autostart) < 0) + vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("no autostart")); + else + vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") = : _("no")); + + ret =3D true; + cleanup: + if (device) + virNodeDeviceFree(device); + return ret; +} + + + const vshCmdDef nodedevCmds[] =3D { {.name =3D "nodedev-create", .handler =3D cmdNodeDeviceCreate, @@ -1295,5 +1357,11 @@ const vshCmdDef nodedevCmds[] =3D { .info =3D info_node_device_autostart, .flags =3D 0 }, + {.name =3D "nodedev-info", + .handler =3D cmdNodeDeviceInfo, + .opts =3D opts_node_device_info, + .info =3D info_node_device_info, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.31.1