From nobody Thu May 2 10:41:08 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=1622751137; cv=none; d=zohomail.com; s=zohoarc; b=mZWLhmmoNWYt4m6s24gkPLvjJbzufw2PjBiSxFWBUF2uspv2yqOtWJz+YbPVrUHNBKOTG5dl8g8kOQjyvs6kU2YmdHOERBVy/SDnC8d3d49zBxaRhUUZ1NzNuhKC4sbAN7oxQSEXcefp/PvkYAw/t160BvknR5xO90BSXmQTmY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622751137; 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=41dnZ9HGYOjV/IHjELCpwnfsOKyPgUhpLtp3IlAp0LU=; b=jl9LBvzvaJU3KD4xnP4C2yPpzp426BFNfjj1NQfa3wN5Kmf3dlc6LRPBxMkTcf9AmbDIVJjc9D/QXszWitc0iHRHo2qXgO1pkYFiSSKnHYtcrukmBhQEaDAeGmE/Nz5Nzhmb6lbXMmi38qQo4lpXXo6u0GZ7QHWvHkzExLji5Mg= 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 1622751137786778.6339129216873; Thu, 3 Jun 2021 13:12:17 -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-55-PDVF4f8rOjqtsc0-97ZS3Q-1; Thu, 03 Jun 2021 16:12:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E346A180FD6F; Thu, 3 Jun 2021 20:12:06 +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 3A312579B1; Thu, 3 Jun 2021 20:12:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DF05444A58; Thu, 3 Jun 2021 20:12:01 +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 153KC03e000728 for ; Thu, 3 Jun 2021 16:12:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id B9B0E19D7D; Thu, 3 Jun 2021 20:12:00 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-235.phx2.redhat.com [10.3.114.235]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AE8719C44 for ; Thu, 3 Jun 2021 20:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622751136; 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=41dnZ9HGYOjV/IHjELCpwnfsOKyPgUhpLtp3IlAp0LU=; b=I6QkAD2xE4G1C2nJ9Eh1hhwrT+w9vWSBYY6IWl9qI/S7T44u7su/iDT9Lk0vmW543OnsXT HVKW88IxtrWhCtmHUrlOAxgqX78WSvqh9y8j4d4uSGz7P5ANtKHXJvdKIGmb6lzYPDJx6d sf+iHsv0NaayA1pxuI7RLx0+RaFGUBg= X-MC-Unique: PDVF4f8rOjqtsc0-97ZS3Q-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 1/7] api: add virNodeDevice(Get|Set)Autostart() Date: Thu, 3 Jun 2021 15:11:50 -0500 Message-Id: <20210603201156.3571972-2-jjongsma@redhat.com> In-Reply-To: <20210603201156.3571972-1-jjongsma@redhat.com> References: <20210603201156.3571972-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.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 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 --- include/libvirt/libvirt-nodedev.h | 6 +++ src/driver-nodedev.h | 10 ++++ src/libvirt-nodedev.c | 76 +++++++++++++++++++++++++++++++ src/libvirt_public.syms | 4 ++ src/remote/remote_driver.c | 4 +- src/remote/remote_protocol.x | 29 +++++++++++- src/remote_protocol-structs | 12 +++++ 7 files changed, 139 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 5678a13cda..a21bd6ac7d 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -896,4 +896,8 @@ LIBVIRT_7.3.0 { virNodeDeviceCreate; } LIBVIRT_7.2.0; =20 +LIBVIRT_7.5.0 { + virNodeDeviceSetAutostart; + virNodeDeviceGetAutostart; +} LIBVIRT_7.3.0; # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 48423f3619..9070f648e2 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8717,7 +8717,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.5.0 */ + .nodeDeviceSetAutostart =3D remoteNodeDeviceSetAutostart, /* 7.5.0 */ }; =20 static virNWFilterDriver nwfilter_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index de69704b68..a98ab49f2e 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2164,6 +2164,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: @@ -6784,6 +6797,20 @@ enum remote_procedure { * @priority: high * @acl: node_device:start */ - REMOTE_PROC_NODE_DEVICE_CREATE =3D 430 + REMOTE_PROC_NODE_DEVICE_CREATE =3D 430, + + /** + * @generate: both + * @priority: high + * @acl: node_device:read + */ + REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART =3D 431, + + /** + * @generate: both + * @priority: high + * @acl: node_device:write + */ + REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART =3D 432 =20 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 6b46328adc..b17372537b 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1615,6 +1615,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; }; @@ -3623,4 +3633,6 @@ enum remote_procedure { REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 428, REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 429, REMOTE_PROC_NODE_DEVICE_CREATE =3D 430, + REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART =3D 431, + REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART =3D 432, }; --=20 2.31.1 From nobody Thu May 2 10:41:08 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=1622751150; cv=none; d=zohomail.com; s=zohoarc; b=GIfZjn99IN4d30dPcAjwg/2+3OjNBTxU9DC8nL9Hj9lP8NqBGwyb7LS+WFm9DMVCQJ4+9D0ipGeAOB0woiJX+MelzlnqUPK7AntGetF1yRABbTRvkqEo8N+7QfMuwiBjEn541TQynFnBpN9MuZDGQCzopJKjinPZzm9OI726zPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622751150; 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=HLAIJ611Qmt/XxsHm+2I19pGRW3QSBK7buC5QCMbxF8=; b=nu1EByp/HZClWNObvcTWWpcYRKtG78pH+kwhYtVXxgiW4OE/Hapr8P+LbNPyyK8Vs8jXqaBQd5CI8T7NsfSX1EJud5vIvhlgXmybOHFgWyedTdOSWtVIDouumS9/X+i0PqvXPylwwsK3xS535+3ua6G8JrLTjCGPZCuBBbAopYQ= 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 16227511509585.428352551805915; Thu, 3 Jun 2021 13:12:30 -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-351-qa9dteHjNVmUaOqIsfcu8g-1; Thu, 03 Jun 2021 16:12:26 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7268800D62; Thu, 3 Jun 2021 20:12:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92A951B428; Thu, 3 Jun 2021 20:12: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 5903E180B7B6; Thu, 3 Jun 2021 20:12:20 +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 153KC1x9000733 for ; Thu, 3 Jun 2021 16:12:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2260E19D7D; Thu, 3 Jun 2021 20:12:01 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-235.phx2.redhat.com [10.3.114.235]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D879F19C44 for ; Thu, 3 Jun 2021 20:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622751149; 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=HLAIJ611Qmt/XxsHm+2I19pGRW3QSBK7buC5QCMbxF8=; b=JLunJdVGsf+aNF8Cw9UkQdPcZv2TJuePK7bSqXzku58SMhk3eAsiwA7re7Olp5OIDT2IUN VUoHIJBofCGj2VCFJbB4kIQTixsFMBpCPlCs4xWQXmm7OYUC2qs+ozKbUkiJVYeJqgsXcw 9mmPW+a788NllLePd7pojFrGxBSE0Fc= X-MC-Unique: qa9dteHjNVmUaOqIsfcu8g-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 2/7] nodedev: implement virNodeDevice(Get|Set)Autostart() Date: Thu, 3 Jun 2021 15:11:51 -0500 Message-Id: <20210603201156.3571972-3-jjongsma@redhat.com> In-Reply-To: <20210603201156.3571972-1-jjongsma@redhat.com> References: <20210603201156.3571972-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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Implement autostart functionality for mediated devices. Signed-off-by: Jonathon Jongsma --- src/conf/virnodedeviceobj.c | 16 ++++ src/conf/virnodedeviceobj.h | 6 ++ src/libvirt_private.syms | 2 + src/node_device/node_device_driver.c | 116 +++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 13 +++ src/node_device/node_device_udev.c | 19 ++++- 6 files changed, 171 insertions(+), 1 deletion(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index b213592b56..deee796440 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 { @@ -1026,6 +1027,21 @@ virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, } =20 =20 +bool +virNodeDeviceObjIsAutostart(virNodeDeviceObj *obj) +{ + return obj->autostart; +} + + +void +virNodeDeviceObjSetAutostart(virNodeDeviceObj *obj, + bool autostart) +{ + obj->autostart =3D autostart; +} + + struct virNodeDeviceObjListRemoveHelperData { virNodeDeviceObjListRemoveIterator callback; diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 7353e4619b..78188be2a2 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -135,6 +135,12 @@ virNodeDeviceObjIsPersistent(virNodeDeviceObj *obj); void virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, bool persistent); +bool +virNodeDeviceObjIsAutostart(virNodeDeviceObj *obj); + +void +virNodeDeviceObjSetAutostart(virNodeDeviceObj *obj, + bool autostart); =20 typedef bool (*virNodeDeviceObjListRemoveIterator)(virNodeDeviceObj *obj, const void *opaque); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0ced2a7990..dd46fe8750 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1278,6 +1278,7 @@ virNetworkPortDefSaveStatus; virNodeDeviceObjEndAPI; virNodeDeviceObjGetDef; virNodeDeviceObjIsActive; +virNodeDeviceObjIsAutostart; virNodeDeviceObjIsPersistent; virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; @@ -1294,6 +1295,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 8a0a2c3847..9ebe609aa4 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -962,6 +962,46 @@ virMdevctlStart(virNodeDeviceDef *def, char **errmsg) } =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, @@ -1688,3 +1728,79 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, =20 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; + } + 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; +} diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index edd763f0e4..d178a18180 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -171,3 +171,16 @@ bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *ds= t, int nodeDeviceCreate(virNodeDevice *dev, unsigned int flags); + +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 f99578414d..21273083a6 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1488,6 +1488,8 @@ udevAddOneDevice(struct udev_device *device) bool new_device =3D true; int ret =3D -1; bool was_persistent =3D false; + bool autostart =3D true; + bool is_mdev; =20 def =3D g_new0(virNodeDeviceDef, 1); =20 @@ -1509,17 +1511,28 @@ 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); =20 virNodeDeviceObjEndAPI(&obj); + } else { + /* All non-mdev devices report themselves as autostart since they + * should still be present and active after a reboot unless the de= vice + * is removed from the host. Mediated devices can only be persiste= nt if + * they are in already in the device list from parsing the mdevctl + * output. */ + autostart =3D !is_mdev; } =20 /* If this is a device change, the old definition will be freed @@ -1527,6 +1540,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) @@ -1930,6 +1944,7 @@ udevSetupSystemDev(void) goto cleanup; =20 virNodeDeviceObjSetActive(obj, true); + virNodeDeviceObjSetAutostart(obj, true); =20 virNodeDeviceObjEndAPI(&obj); =20 @@ -2331,6 +2346,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.5.0 */ + .nodeDeviceGetAutostart =3D nodeDeviceGetAutostart, /* 7.5.0 */ }; =20 =20 --=20 2.31.1 From nobody Thu May 2 10:41:08 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=1622751135; cv=none; d=zohomail.com; s=zohoarc; b=h/8xDZC9xR8EhGxNgyu52cJQBEzVQuw6Ofi2QoEwB4cnjyh9F9tOMKZBkV9WQW/euCUnGjRy9EDZTheRC7dH8JybSCoY4Y1ouNZ/lJfY6syeB3HIRrCemkbV8QUmT85woE+vgJgVNFDvnZxuhKMq9ovxjZhpZLfGWtXaAdgs2FY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622751135; 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=YMCZftYmR7hboq71RLMl61vzQGWM/lkAwmCCd/z9T3g=; b=WDccyiNP5fq6GQzebJXOWxdMZj7xomlO7p3+lzgTipbFYrhL8VGWiv3qcqmAT5itDSlSipzzWel8eyxPcrG/OJjDGwRHEBMliUDw7IidfkSah6W31Ox7GUWmEwS6ZhiviPY/A9hyuOMS1XiRVuNulRgosjCDiTfyv41+oOF7uAo= 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 1622751135953518.1467398796457; Thu, 3 Jun 2021 13:12:15 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-280-5yKSEZ71O5mtAPdO1ViSAQ-1; Thu, 03 Jun 2021 16:12:13 -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 F02148189C3; Thu, 3 Jun 2021 20:12:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B9915D6AB; Thu, 3 Jun 2021 20:12:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BC0191801264; Thu, 3 Jun 2021 20:12:02 +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 153KC10W000738 for ; Thu, 3 Jun 2021 16:12:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6F55919D7D; Thu, 3 Jun 2021 20:12:01 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-235.phx2.redhat.com [10.3.114.235]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4082019C44 for ; Thu, 3 Jun 2021 20:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622751135; 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=YMCZftYmR7hboq71RLMl61vzQGWM/lkAwmCCd/z9T3g=; b=LhJPFfxGRGDWL0a+5QXEGK9GpM23xq6Ch6NCzzM5SJpi3GJwTAST/DT0aSeBd7iBEWcHSn qHNMFeY6I9jYf6naE7F7WD62kvslq+jlWiv/0qFjQLzhOS45MHbhPiTbt6HIzHYIuC7Hm6 JVqXz3kqHQp1zDr1ZdKrH3WGTpbZG+I= X-MC-Unique: 5yKSEZ71O5mtAPdO1ViSAQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 3/7] nodedev: Add tests for mdevctl autostart command Date: Thu, 3 Jun 2021 15:11:52 -0500 Message-Id: <20210603201156.3571972-4-jjongsma@redhat.com> In-Reply-To: <20210603201156.3571972-1-jjongsma@redhat.com> References: <20210603201156.3571972-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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Jonathon Jongsma Reviewed-by: Daniel P. Berrang=C3=A9 --- .../nodedevmdevctldata/mdevctl-autostart.argv | 8 +++ tests/nodedevmdevctltest.c | 54 +++++++++++++++++++ 2 files changed, 62 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 8ba1d2da70..3f9d4c84b9 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -118,6 +118,55 @@ 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))) + 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) { @@ -348,6 +397,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 @@ -370,6 +422,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 10:41:08 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=1622751152; cv=none; d=zohomail.com; s=zohoarc; b=WubCWoTmik09toeM4YrILxAJeBge1o+8OBnrXxGRlEIEf2EY5LHVXieSO0/gYLjAUqTAUtAETSgI02EOSKLdQhmpRQMW8Nzd00fzdiCY4vnwGVCXrtagAEFA0bMNQyVctH8t5Au+zPlh3vC/gKEi2L76XG2jTWbu4nYImYYufS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622751152; 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=+h4Z24w9yHMs1mIFJBbfAcLFUk7M3mtOfwXEtJe7VGY=; b=iXuseNBRrnWM3aMRvCKprLo8C7OlkIfggzJq7iyzTI+1jW8dAzDDSFKgaDLkDYbAyIKK+jEBvXVe9RW4oeaLimGIwIwM7ysi6ZO9qwzrmYx8F+c5e6NOYSyPZC6llOLFcTEbULNDJpMfkn7LrBnyk7nNaXn5r/y942JLaD9LTbY= 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 1622751152802842.2178158781545; Thu, 3 Jun 2021 13:12:32 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-548-k6AtxCsUPBKYXkzTHdUHWA-1; Thu, 03 Jun 2021 16:12:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 71E11107AD30; Thu, 3 Jun 2021 20:12: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 4B47E500DB; Thu, 3 Jun 2021 20:12: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 0BFC41801268; Thu, 3 Jun 2021 20:12:23 +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 153KC1xp000746 for ; Thu, 3 Jun 2021 16:12:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id BD0CD19D7D; Thu, 3 Jun 2021 20:12:01 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-235.phx2.redhat.com [10.3.114.235]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8DC4E19C44 for ; Thu, 3 Jun 2021 20:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622751151; 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=+h4Z24w9yHMs1mIFJBbfAcLFUk7M3mtOfwXEtJe7VGY=; b=QLzJib0pvZXHwzwKv6SFDyNEoowxQngBJkBQjCkjszYY6q4osNylqZ9hAXxvkLH8coWI1C S8VBVdjlh8rVWgkrHk+WNiHjG8Thodxcyay4GZdawezYWZ4AvmSIFjc0DejRTa6Vkt9t1w fMNP8CA75KK5x3PfKo7ulKUl95vg5fw= X-MC-Unique: k6AtxCsUPBKYXkzTHdUHWA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 4/7] virsh: add nodedev-autostart Date: Thu, 3 Jun 2021 15:11:53 -0500 Message-Id: <20210603201156.3571972-5-jjongsma@redhat.com> In-Reply-To: <20210603201156.3571972-1-jjongsma@redhat.com> References: <20210603201156.3571972-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.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" 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 --- 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 87668f2b9a..e9023ba17b 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5135,6 +5135,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 8c2086b71f..845effcb81 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1162,6 +1162,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, @@ -1233,5 +1298,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 10:41:08 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=1622751156; cv=none; d=zohomail.com; s=zohoarc; b=cabvYEiFARw5Cpdt92115rAQPFcR/vyzWEDqHb9AuHwCXpdRM/rpFiNsExyZaJYBnPc7qgcjqgZVpuKNnEdCAjRlUE8M7DNfGNEyrTqtPCcw/wMdEE80dOggH59yul2UQ8Cs1/5tMszqggIT9XIB7XQn1narIHstcy5yYoTBgqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622751156; 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=njL2VYpOxxOWgUYbgQcrfh6jWb1Nye/jRgDOpD2AQHc=; b=KA6nldchvlQ5+X3+56vFsPKnuASJpfhJPfHUlETwj5WlYZ58dFpKE9T06v7EsFX6O6J8jEBHCSQ1eTLklYl8JjIu3S41+bTvy4Cpj19H+txC4M9WoRa/ce+lmgJHmV3oyAkp+b54Aj/vClfs0Q1/h+5TtOcdNqXNeTlbfj6LRZI= 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 1622751156852535.3838489481504; Thu, 3 Jun 2021 13:12:36 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-253-0eI3UbTYNT6ck4oFDTP4Zg-1; Thu, 03 Jun 2021 16:12:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5902E180FD6D; Thu, 3 Jun 2021 20:12: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 3CCA3579B1; Thu, 3 Jun 2021 20:12: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 D5A871813CA5; Thu, 3 Jun 2021 20:12:25 +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 153KC2Vb000756 for ; Thu, 3 Jun 2021 16:12:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1699419D7D; Thu, 3 Jun 2021 20:12:02 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-235.phx2.redhat.com [10.3.114.235]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB9C219C44 for ; Thu, 3 Jun 2021 20:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622751155; 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=njL2VYpOxxOWgUYbgQcrfh6jWb1Nye/jRgDOpD2AQHc=; b=MPOFB51fwsaNEr6vktSKu/NyJg79ue2WiCVUcWoFoY4XVb0Ep2uwUsMAxpSMekZ9VJsLSZ bWkZ1IfXnwdCVNc7dIaSob5iPEpeBD/HgVOKgjG23UY5KLQa34KVMuM/1zIIXHpZksZ04N jXMmiHAAtM8Esf25DZocRNlYMb66mDc= X-MC-Unique: 0eI3UbTYNT6ck4oFDTP4Zg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 5/7] api: add virNodeDeviceIsPersistent()/IsActive() Date: Thu, 3 Jun 2021 15:11:54 -0500 Message-Id: <20210603201156.3571972-6-jjongsma@redhat.com> In-Reply-To: <20210603201156.3571972-1-jjongsma@redhat.com> References: <20210603201156.3571972-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.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" 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 --- 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 | 32 ++++++++++++++- src/remote_protocol-structs | 14 +++++++ 7 files changed, 126 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 a21bd6ac7d..c2b4b46a92 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -899,5 +899,7 @@ LIBVIRT_7.3.0 { LIBVIRT_7.5.0 { virNodeDeviceSetAutostart; virNodeDeviceGetAutostart; + virNodeDeviceIsPersistent; + virNodeDeviceIsActive; } LIBVIRT_7.3.0; # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 9070f648e2..edc01437e3 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8720,6 +8720,8 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceDestroy =3D remoteNodeDeviceDestroy, /* 0.6.3 */ .nodeDeviceGetAutostart =3D remoteNodeDeviceGetAutostart, /* 7.5.0 */ .nodeDeviceSetAutostart =3D remoteNodeDeviceSetAutostart, /* 7.5.0 */ + .nodeDeviceIsPersistent =3D remoteNodeDeviceIsPersistent, /* 7.5.0 */ + .nodeDeviceIsActive =3D remoteNodeDeviceIsActive, /* 7.5.0 */ }; =20 static virNWFilterDriver nwfilter_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index a98ab49f2e..49218cb1df 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2177,6 +2177,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: @@ -6811,6 +6827,20 @@ enum remote_procedure { * @priority: high * @acl: node_device:write */ - REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART =3D 432 + REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART =3D 432, + + /** + * @generate: both + * @priority: high + * @acl: node_device:read + */ + REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT =3D 433, + + /** + * @generate: both + * @priority: high + * @acl: node_device:read + */ + REMOTE_PROC_NODE_DEVICE_IS_ACTIVE =3D 434 =20 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index b17372537b..7717b04804 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1625,6 +1625,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; }; @@ -3635,4 +3647,6 @@ enum remote_procedure { REMOTE_PROC_NODE_DEVICE_CREATE =3D 430, REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART =3D 431, REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART =3D 432, + REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT =3D 433, + REMOTE_PROC_NODE_DEVICE_IS_ACTIVE =3D 434, }; --=20 2.31.1 From nobody Thu May 2 10:41:08 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=1622751183; cv=none; d=zohomail.com; s=zohoarc; b=KLFYqPYwQ8Da5tulj9UbOjb0G+uLsq1VHpVtQkBRvkLtvVGzUuTfaFqyi1GWeHKGdM4FxJf9jGkZnSGkmW34k0UWoj4LuB/Kcy/9y0UM6JzvB/4at/axyVKGgW/TqrZ2nFddoy/GvA6hg3eD6NWrKVkSS2GOwM10SrutCFEyZF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622751183; 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=WAjNdMEYNL1MfAHimsZUdP6ICxe2+qrsvcdbW9uKiO0=; b=Fxl2B9aelGLAN+rxY/Py4LsLo7USqtMDe7MSvC4f/5xiJE9/yOwSt+c/krXFv+FBSnRFpU8Xg6SY445QBqZIFKbkk1INYvPvzmb+CzK4m7lSX9JQnRpu4dJ3j9/uMX9+emiASE9uobIbua7GQdDNkpkMeK0hTen5xJdnkXRz8dM= 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 1622751183000647.739206495051; Thu, 3 Jun 2021 13:13:03 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-351-ro00oS-LPPOVH8J7qH1m6Q-1; Thu, 03 Jun 2021 16:12:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF142107ACE3; Thu, 3 Jun 2021 20:12:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91259687C5; Thu, 3 Jun 2021 20:12: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 5688D180B651; Thu, 3 Jun 2021 20:12:20 +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 153KC2WX000768 for ; Thu, 3 Jun 2021 16:12:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 64C5119D7D; Thu, 3 Jun 2021 20:12:02 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-235.phx2.redhat.com [10.3.114.235]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 353B019C44 for ; Thu, 3 Jun 2021 20:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622751182; 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=WAjNdMEYNL1MfAHimsZUdP6ICxe2+qrsvcdbW9uKiO0=; b=PejUFeaHFXCYIaAkYSHlcYa50jo+omXSuYCl6blppgyMhRLQYNeVxcK6sELTGhAHOusxTh u5qVWrXOjmzxuBKpQOeM5R4qXzZUBFfCfwA+khpc/9zIuZtyHgkjT8VwF4uusZxP0tOOti x40xW56ESAGAKa+ZOQKpdXlHH30Dvb0= X-MC-Unique: ro00oS-LPPOVH8J7qH1m6Q-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 6/7] nodedev: Implement virNodeDeviceIsPersistent()/IsActive() Date: Thu, 3 Jun 2021 15:11:55 -0500 Message-Id: <20210603201156.3571972-7-jjongsma@redhat.com> In-Reply-To: <20210603201156.3571972-1-jjongsma@redhat.com> References: <20210603201156.3571972-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.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" Implement these new API functions in the nodedev driver. Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_driver.c | 50 ++++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 6 ++++ src/node_device/node_device_udev.c | 21 +++++++----- 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 9ebe609aa4..75391f18b8 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1804,3 +1804,53 @@ nodeDeviceGetAutostart(virNodeDevice *device, virNodeDeviceObjEndAPI(&obj); return ret; } + + +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 d178a18180..744dd42632 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -180,6 +180,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 21273083a6..eb15ccce7f 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1487,7 +1487,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 true; bool autostart =3D true; bool is_mdev; =20 @@ -1518,7 +1518,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 @@ -1527,11 +1528,12 @@ udevAddOneDevice(struct udev_device *device) =20 virNodeDeviceObjEndAPI(&obj); } else { - /* All non-mdev devices report themselves as autostart since they - * should still be present and active after a reboot unless the de= vice - * is removed from the host. Mediated devices can only be persiste= nt if - * they are in already in the device list from parsing the mdevctl - * output. */ + /* All non-mdev devices report themselves as persistent and autost= art + * since they should still be present and active after a reboot un= less + * the device is removed from the host. Mediated devices can only = be + * persistent if they are in already in the device list from parsi= ng + * the mdevctl output. */ + persistent =3D !is_mdev; autostart =3D !is_mdev; } =20 @@ -1539,7 +1541,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 @@ -1945,6 +1947,7 @@ udevSetupSystemDev(void) =20 virNodeDeviceObjSetActive(obj, true); virNodeDeviceObjSetAutostart(obj, true); + virNodeDeviceObjSetPersistent(obj, true); =20 virNodeDeviceObjEndAPI(&obj); =20 @@ -2348,6 +2351,8 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceCreate =3D nodeDeviceCreate, /* 7.3.0 */ .nodeDeviceSetAutostart =3D nodeDeviceSetAutostart, /* 7.5.0 */ .nodeDeviceGetAutostart =3D nodeDeviceGetAutostart, /* 7.5.0 */ + .nodeDeviceIsPersistent =3D nodeDeviceIsPersistent, /* 7.5.0 */ + .nodeDeviceIsActive =3D nodeDeviceIsActive, /* 7.5.0 */ }; =20 =20 --=20 2.31.1 From nobody Thu May 2 10:41:08 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=1622751159; cv=none; d=zohomail.com; s=zohoarc; b=LfFIEDrZjtZG9N1H0HqdtGo8mWHGSpvUL9fG9aiAM5xzb5uheMjrHQPUJQ4kOiWKgbudCfBedJQRou22+4G8RRIUYBJ+RaGY9V7U4yiYYfl/DCpbvDiy3IZHJRiN7WVoC5ff/8SGOECNNM6aC6/bcdIe+QRPWx8NWjiPoGQ+l0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622751159; 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=ee/LURA89Zj1LBNfM2DyavVEHCsJW1xUiVl3KkBgets=; b=YoqeAkRNgdQAEnNcBzVMgcWZ9fgTpuV73efPbc5je+zQittv1oH4i0W2twSq+YPYqrbNPFWNaOajBMQpKrUsls5ZD8Fn5qLOGsf1oM2VksfHCLDVeyHJl5H0kp4ZpSHp3MdeUiBvSblEAP7HWaCheSSRKcgHW0gPr7h7kq9nnJk= 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 1622751159201976.4070203835712; Thu, 3 Jun 2021 13:12:39 -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-97-O2Du9WWUPCGIdJ1IEKZIDg-1; Thu, 03 Jun 2021 16:12:36 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 250A28042B4; Thu, 3 Jun 2021 20:12:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07514424D; Thu, 3 Jun 2021 20:12: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 C3C7744A5B; Thu, 3 Jun 2021 20:12:28 +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 153KC4dg000793 for ; Thu, 3 Jun 2021 16:12:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5152419C44; Thu, 3 Jun 2021 20:12:04 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-235.phx2.redhat.com [10.3.114.235]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2244C19704 for ; Thu, 3 Jun 2021 20:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622751158; 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=ee/LURA89Zj1LBNfM2DyavVEHCsJW1xUiVl3KkBgets=; b=TI592/uD2/dOPSQuF25vas643GmgrQ7Bo/FFKgiEfDCOQwFSLUBXz0U4QaSxUiK/6oh/NS Twgzlp5FznKb36rq6CSNUSdfQmFjYTl5V2u1EGQ5P41mtX6y6FVIPEHE+hScxFcwyxwv93 Apb1AoIR1y4PkmR1bxRdEUeIaIcx9do= X-MC-Unique: O2Du9WWUPCGIdJ1IEKZIDg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 7/7] virsh: add nodedev-info Date: Thu, 3 Jun 2021 15:11:56 -0500 Message-Id: <20210603201156.3571972-8-jjongsma@redhat.com> In-Reply-To: <20210603201156.3571972-1-jjongsma@redhat.com> References: <20210603201156.3571972-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.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 is currently the only way to view the 'autostart' property for a node device. Signed-off-by: Jonathon Jongsma Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 e9023ba17b..5958f6d1f7 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5061,6 +5061,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 845effcb81..c8da37f104 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1227,6 +1227,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 details in XML") + }, + {.name =3D "desc", + .data =3D N_("Output the node device details as an XML dump to stdout= .") + }, + {.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, @@ -1304,5 +1366,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