api: add virNodeDeviceIsPersistent()/IsActive()

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@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Jonathon Jongsma 2021-06-03 13:21:00 -05:00
parent 16d078eded
commit 6d0b85d792
7 changed files with 127 additions and 1 deletions

View File

@ -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:
*

View File

@ -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;
};

View File

@ -1056,3 +1056,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;
}

View File

@ -906,6 +906,8 @@ LIBVIRT_7.8.0 {
global:
virNodeDeviceSetAutostart;
virNodeDeviceGetAutostart;
virNodeDeviceIsPersistent;
virNodeDeviceIsActive;
} LIBVIRT_7.7.0;
# .... define new API here using predicted next version number ....

View File

@ -8676,6 +8676,8 @@ static virNodeDeviceDriver node_device_driver = {
.nodeDeviceDestroy = remoteNodeDeviceDestroy, /* 0.6.3 */
.nodeDeviceGetAutostart = remoteNodeDeviceGetAutostart, /* 7.8.0 */
.nodeDeviceSetAutostart = remoteNodeDeviceSetAutostart, /* 7.8.0 */
.nodeDeviceIsPersistent = remoteNodeDeviceIsPersistent, /* 7.8.0 */
.nodeDeviceIsActive = remoteNodeDeviceIsActive, /* 7.8.0 */
};
static virNWFilterDriver nwfilter_driver = {

View File

@ -2195,6 +2195,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:
@ -6845,5 +6861,20 @@ enum remote_procedure {
* @priority: high
* @acl: node_device:write
*/
REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 434
REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 434,
/**
* @generate: both
* @priority: high
* @acl: node_device:read
*/
REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT = 435,
/**
* @generate: both
* @priority: high
* @acl: node_device:read
*/
REMOTE_PROC_NODE_DEVICE_IS_ACTIVE = 436
};

View File

@ -1639,6 +1639,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;
};
@ -3651,4 +3663,6 @@ enum remote_procedure {
REMOTE_PROC_NETWORK_DEFINE_XML_FLAGS = 432,
REMOTE_PROC_NODE_DEVICE_GET_AUTOSTART = 433,
REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 434,
REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT = 435,
REMOTE_PROC_NODE_DEVICE_IS_ACTIVE = 436,
};