diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index cba4fa54c64bfeedfc36e7bb2bfb3b336cc46941..5605a94969fe6b8533f0ec06617c45dd40219a4f 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -4097,4 +4097,9 @@ int virDomainRename(virDomainPtr dom, const char *new_name, unsigned int flags); +int virDomainGetGuestVcpus(virDomainPtr domain, + virTypedParameterPtr *params, + unsigned int *nparams, + unsigned int flags); + #endif /* __VIR_LIBVIRT_DOMAIN_H__ */ diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 5ab5775b65a3564e3a77d98c60f739ac65d55653..93af2b664e9d1350168edde5ab2046b76d7cd4cf 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1239,6 +1239,12 @@ typedef int (*virDrvConnectUnregisterCloseCallback)(virConnectPtr conn, virConnectCloseFunc cb); +typedef int +(*virDrvDomainGetGuestVcpus)(virDomainPtr domain, + virTypedParameterPtr *params, + unsigned int *nparams, + unsigned int flags); + typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; @@ -1475,6 +1481,7 @@ struct _virHypervisorDriver { virDrvConnectRegisterCloseCallback connectRegisterCloseCallback; virDrvConnectUnregisterCloseCallback connectUnregisterCloseCallback; virDrvDomainMigrateStartPostCopy domainMigrateStartPostCopy; + virDrvDomainGetGuestVcpus domainGetGuestVcpus; }; diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 73ae369de0b038f08f3f5c5f262218aa9aa49eab..eb995b570f5b726d6e613a7d92eb8442b33e92bc 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11835,3 +11835,59 @@ virDomainInterfaceFree(virDomainInterfacePtr iface) VIR_FREE(iface); } + + +/** + * virDomainGetGuestVcpus: + * @domain: pointer to domain object + * @params: pointer that will be filled with an array of typed parameters + * @nparams: pointer filled with number of elements in @params + * @flags: currently unused, callers shall pass 0 + * + * Queries the guest agent for state and information regarding vCPUs from + * guest's perspective. The reported data depends on the guest agent + * implementation. + * + * Reported fields stored in @params: + * 'vcpus': string containing bitmap representing vCPU ids as reported by the + * guest + * 'online': string containing bitmap representing online vCPUs as reported + * by the guest agent. + * 'offlinable': string containing bitmap representing ids of vCPUs that can be + * offlined + * + * This API requires the VM to run. The caller is responsible for calling + * virTypedParamsFree to free memory returned in @params. + * + * Returns 0 on success, -1 on error. + */ +int +virDomainGetGuestVcpus(virDomainPtr domain, + virTypedParameterPtr *params, + unsigned int *nparams, + unsigned int flags) +{ + VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%p, flags=%x", + params, nparams, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + virCheckNonNullArgGoto(params, error); + virCheckNonNullArgGoto(nparams, error); + + if (domain->conn->driver->domainGetGuestVcpus) { + int ret; + ret = domain->conn->driver->domainGetGuestVcpus(domain, params, nparams, + flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(domain->conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 06011ce489e9a3140fb33f1fb00e318b2f74fab8..30801c5a5430057deb5dce50aefaff4ba14946de 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -736,6 +736,7 @@ LIBVIRT_2.0.0 { global: virConnectStoragePoolEventRegisterAny; virConnectStoragePoolEventDeregisterAny; + virDomainGetGuestVcpus; } LIBVIRT_1.3.3; # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 84b6d58c1131536e994ae798c6584fc23906e0c6..6a580c6c01d0a99a728efab85dab8f7b197225ea 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -7981,6 +7981,7 @@ static virHypervisorDriver hypervisor_driver = { .connectRegisterCloseCallback = remoteConnectRegisterCloseCallback, /* 1.3.2 */ .connectUnregisterCloseCallback = remoteConnectUnregisterCloseCallback, /* 1.3.2 */ .domainMigrateStartPostCopy = remoteDomainMigrateStartPostCopy, /* 1.3.3 */ + .domainGetGuestVcpus = remoteDomainGetGuestVcpus, /* 2.0.0 */ }; static virNetworkDriver network_driver = { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index cec6bd2fb19c63e82bef228ec8aa0fe1d6ae4ee3..f72918d2e36bfad8080a9ea95cd7cb1aab633581 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -250,6 +250,9 @@ const REMOTE_DOMAIN_INTERFACE_MAX = 2048; /* Upper limit on number of IP addresses per interface */ const REMOTE_DOMAIN_IP_ADDR_MAX = 2048; +/* Upper limit on number of guest vcpu information entries */ +const REMOTE_DOMAIN_GUEST_VCPU_PARAMS_MAX = 64; + /* UUID. VIR_UUID_BUFLEN definition comes from libvirt.h */ typedef opaque remote_uuid[VIR_UUID_BUFLEN]; @@ -3292,6 +3295,16 @@ struct remote_domain_event_callback_device_removal_failed_msg { remote_nonnull_string devAlias; }; +struct remote_domain_get_guest_vcpus_args { + remote_nonnull_domain dom; + unsigned int flags; +}; + +struct remote_domain_get_guest_vcpus_ret { + remote_typed_param params; /* alloc@1@unsigned int@2 */ +}; + + /*----- Protocol. -----*/ /* Define the program number, protocol version and procedure numbers here. */ @@ -5839,5 +5852,11 @@ enum remote_procedure { * @generate: both * @acl: none */ - REMOTE_PROC_STORAGE_POOL_EVENT_LIFECYCLE = 370 + REMOTE_PROC_STORAGE_POOL_EVENT_LIFECYCLE = 370, + + /** + * @generate: both + * @acl: domain:write + */ + REMOTE_PROC_DOMAIN_GET_GUEST_VCPUS = 371 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 3934e0751b283b4891bf7e4b96c90564eefa99c0..4e603dbe520adfae6a7cadf4425ef50e647f65b7 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -2751,6 +2751,16 @@ struct remote_domain_event_callback_device_removal_failed_msg { remote_nonnull_domain dom; remote_nonnull_string devAlias; }; +struct remote_domain_get_guest_vcpus_args { + remote_nonnull_domain dom; + u_int flags; +}; +struct remote_domain_get_guest_vcpus_ret { + struct { + u_int params_len; + remote_typed_param * params_val; + } params; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN = 1, REMOTE_PROC_CONNECT_CLOSE = 2, @@ -3122,4 +3132,5 @@ enum remote_procedure { REMOTE_PROC_CONNECT_STORAGE_POOL_EVENT_REGISTER_ANY = 368, REMOTE_PROC_CONNECT_STORAGE_POOL_EVENT_DEREGISTER_ANY = 369, REMOTE_PROC_STORAGE_POOL_EVENT_LIFECYCLE = 370, + REMOTE_PROC_DOMAIN_GET_GUEST_VCPUS = 371, };