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>
---
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-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 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 = {
.nodeDeviceDestroy = remoteNodeDeviceDestroy, /* 0.6.3 */
.nodeDeviceGetAutostart = remoteNodeDeviceGetAutostart, /* 7.5.0 */
.nodeDeviceSetAutostart = remoteNodeDeviceSetAutostart, /* 7.5.0 */
+ .nodeDeviceIsPersistent = remoteNodeDeviceIsPersistent, /* 7.5.0 */
+ .nodeDeviceIsActive = remoteNodeDeviceIsActive, /* 7.5.0 */
};
static virNWFilterDriver nwfilter_driver = {
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;
};
+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:
@@ -6811,6 +6827,20 @@ enum remote_procedure {
* @priority: high
* @acl: node_device:write
*/
- REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 432
+ REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 432,
+
+ /**
+ * @generate: both
+ * @priority: high
+ * @acl: node_device:read
+ */
+ REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT = 433,
+
+ /**
+ * @generate: both
+ * @priority: high
+ * @acl: node_device:read
+ */
+ REMOTE_PROC_NODE_DEVICE_IS_ACTIVE = 434
};
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 = 430,
REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART = 431,
REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 432,
+ REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT = 433,
+ REMOTE_PROC_NODE_DEVICE_IS_ACTIVE = 434,
};
--
2.31.1