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 <jjongsma(a)redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
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-nodedev.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);
+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);
+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=%p", dev);
+
+ virResetLastError();
+
+ virCheckNodeDeviceReturn(dev, -1);
+
+ if (dev->conn->nodeDeviceDriver &&
+ dev->conn->nodeDeviceDriver->nodeDeviceIsPersistent) {
+ int ret;
+ ret = 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=%p", dev);
+
+ virResetLastError();
+
+ virCheckNodeDeviceReturn(dev, -1);
+
+ if (dev->conn->nodeDeviceDriver &&
+ dev->conn->nodeDeviceDriver->nodeDeviceIsActive) {
+ int ret;
+ ret = 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;
# .... 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 = {
.nodeDeviceDestroy = remoteNodeDeviceDestroy, /* 0.6.3 */
.nodeDeviceGetAutostart = remoteNodeDeviceGetAutostart, /* 7.7.0 */
.nodeDeviceSetAutostart = remoteNodeDeviceSetAutostart, /* 7.7.0 */
+ .nodeDeviceIsPersistent = remoteNodeDeviceIsPersistent, /* 7.7.0 */
+ .nodeDeviceIsActive = remoteNodeDeviceIsActive, /* 7.7.0 */
};
static virNWFilterDriver nwfilter_driver = {
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;
};
+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;
+};
+
/*
* Events Register/Deregister:
@@ -6828,5 +6844,20 @@ enum remote_procedure {
* @priority: high
* @acl: node_device:write
*/
- REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 433
+ REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 433,
+
+ /**
+ * @generate: both
+ * @priority: high
+ * @acl: node_device:read
+ */
+ REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT = 434,
+
+ /**
+ * @generate: both
+ * @priority: high
+ * @acl: node_device:read
+ */
+ REMOTE_PROC_NODE_DEVICE_IS_ACTIVE = 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 = 431,
REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART = 432,
REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 433,
+ REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT = 434,
+ REMOTE_PROC_NODE_DEVICE_IS_ACTIVE = 435,
};
--
2.31.1