From: Peter Krempa <[email protected]> The API will provide a central point to query for runtime information about support of APIs, flags, typed parameters and in future possibly other information for current connection object.
The intofmation can be used to e.g. see which flags are supported for which API. Signed-off-by: Peter Krempa <[email protected]> --- include/libvirt/libvirt-host.h | 5 ++++ src/driver-hypervisor.h | 7 +++++ src/libvirt-host.c | 48 ++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 21 ++++++++++++++- src/remote_protocol-structs | 11 ++++++++ src/rpc/gendispatch.pl | 4 ++- 8 files changed, 96 insertions(+), 2 deletions(-) diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h index 5b448e7954..d2c038a2d3 100644 --- a/include/libvirt/libvirt-host.h +++ b/include/libvirt/libvirt-host.h @@ -1041,5 +1041,10 @@ int virNodeAllocPages(virConnectPtr conn, unsigned int cellCount, unsigned int flags); +char *virConnectGetIntrospection(virConnectPtr conn, + virTypedParameterPtr params, + int nparams, + unsigned int flags); + #endif /* LIBVIRT_HOST_H */ diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 0add95de96..9c90482f19 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1480,6 +1480,12 @@ typedef int int nparams, unsigned int flags); +typedef char * +(*virDrvConnectGetIntrospection)(virConnectPtr conn, + virTypedParameterPtr params, + int nparams, + unsigned int flags); + typedef struct _virHypervisorDriver virHypervisorDriver; /** @@ -1758,4 +1764,5 @@ struct _virHypervisorDriver { virDrvDomainSetThrottleGroup domainSetThrottleGroup; virDrvDomainDelThrottleGroup domainDelThrottleGroup; virDrvDomainAnnounceInterface domainAnnounceInterface; + virDrvConnectGetIntrospection connectGetIntrospection; }; diff --git a/src/libvirt-host.c b/src/libvirt-host.c index 6b4345b09d..951da4f89d 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -142,6 +142,54 @@ virConnectSupportsFeature(virConnectPtr conn, int feature) } +/** + * virConnectGetIntrospection: + * @conn: pointer to the hypervisor connection + * @params: typed parameters (currently unused) + * @nparams: number of paramters in @params + * @flags: currently unused, pass 0 + * + * Request a XML containing introspection information for the current + * connection. The introspection XML contains information about supported APIs, + * flags, and other information which depends on what the current driver + * associated with the connection supports. + * + * Additional information may be later passed in via @params, but it's currently + * unused. + * + * Returns: XML string containing the introspection data. Caller is responsible + * for freeing the associated memory. On error NULL is returned. + * + * Since: 12.5.0 + */ +char * +virConnectGetIntrospection(virConnectPtr conn, + virTypedParameterPtr params, + int nparams, + unsigned int flags) +{ + VIR_DEBUG("conn=%p, flags=0x%x", conn, flags); + VIR_TYPED_PARAMS_DEBUG(params, nparams); + + virResetLastError(); + + virCheckConnectReturn(conn, NULL); + + if (conn->driver->connectGetIntrospection) { + char *ret = conn->driver->connectGetIntrospection(conn, params, nparams, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return NULL; +} + + /** * virConnectGetType: * @conn: pointer to the hypervisor connection diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 64ed641b7f..5ce85bde76 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -959,6 +959,7 @@ LIBVIRT_11.2.0 { LIBVIRT_12.5.0 { global: virDomainAnnounceInterface; + virConnectGetIntrospection; } LIBVIRT_11.2.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 5c358d58c4..43f194acde 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8027,6 +8027,7 @@ static virHypervisorDriver hypervisor_driver = { .domainSetThrottleGroup = remoteDomainSetThrottleGroup, /* 11.2.0 */ .domainDelThrottleGroup = remoteDomainDelThrottleGroup, /* 11.2.0 */ .domainAnnounceInterface = remoteDomainAnnounceInterface, /* 12.5.0 */ + .connectGetIntrospection = remoteConnectGetIntrospection, /* 12.5.0 */ }; static virNetworkDriver network_driver = { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 32185fde2f..8f113e8f17 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -298,6 +298,11 @@ const REMOTE_DOMAIN_MESSAGES_MAX = 2048; */ const REMOTE_DOMAIN_ANNOUNCE_INTERFACE_PARAMS_MAX = 16; +/* + * Upper limit on number of API introspection parameters + */ +const REMOTE_CONNECT_GET_INTROSPECTION_PARAMS_MAX = 16; + /* UUID. VIR_UUID_BUFLEN definition comes from libvirt.h */ typedef opaque remote_uuid[VIR_UUID_BUFLEN]; @@ -4034,6 +4039,14 @@ struct remote_domain_announce_interface_args { unsigned int flags; }; +struct remote_connect_get_introspection_args { + remote_typed_param params<REMOTE_CONNECT_GET_INTROSPECTION_PARAMS_MAX>; + unsigned int flags; +}; + +struct remote_connect_get_introspection_ret { + remote_nonnull_string xml; +}; /*----- Protocol. -----*/ /* Define the program number, protocol version and procedure numbers here. */ @@ -7163,5 +7176,11 @@ enum remote_procedure { * @generate: both * @acl: domain:write */ - REMOTE_PROC_DOMAIN_ANNOUNCE_INTERFACE = 456 + REMOTE_PROC_DOMAIN_ANNOUNCE_INTERFACE = 456, + + /** + * @generate: both + * @acl: connect:read + */ + REMOTE_PROC_CONNECT_GET_INTROSPECTION = 457 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 6093a85c98..de6031d71f 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -3358,6 +3358,16 @@ struct remote_domain_announce_interface_args { } params; u_int flags; }; +struct remote_connect_get_introspection_args { + struct { + u_int params_len; + remote_typed_param * params_val; + } params; + u_int flags; +}; +struct remote_connect_get_introspection_ret { + remote_nonnull_string xml; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN = 1, REMOTE_PROC_CONNECT_CLOSE = 2, @@ -3815,4 +3825,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_EVENT_VCPU_REMOVED = 454, REMOTE_PROC_DOMAIN_EVENT_CALLBACK_CHANNEL_LIFECYCLE = 455, REMOTE_PROC_DOMAIN_ANNOUNCE_INTERFACE = 456, + REMOTE_PROC_CONNECT_GET_INTROSPECTION = 457, }; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 8cb7d7eda2..1d8d00b469 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -633,7 +633,9 @@ elsif ($mode eq "server") { # NB: if your new API starts with remote_typed_params, enter it here if you need # the conn arg to be passed first! - if ($call->{ProcName} eq "NodeSetMemoryParameters" || $call->{ProcName} eq "DomainRestoreParams") { + if ($call->{ProcName} eq "NodeSetMemoryParameters" || + $call->{ProcName} eq "DomainRestoreParams" || + $call->{ProcName} eq "ConnectGetIntrospection") { push(@args_list, $conn_var); } push(@args_list, "$1"); -- 2.54.0
