commit b12354befee9f8e88d3d5d96390856af8f05eb2f Author: Jim Fehlig Date: Fri Aug 26 12:10:21 2011 -0600 Add public API for getting migration speed Includes impl of python binding since the generator was not able to cope. Note: Requires gendispatch.pl patch from Matthias Bolte https://www.redhat.com/archives/libvir-list/2011-August/msg01367.html Index: libvirt-0.9.4/docs/apibuild.py =================================================================== --- libvirt-0.9.4.orig/docs/apibuild.py +++ libvirt-0.9.4/docs/apibuild.py @@ -1643,7 +1643,8 @@ class CParser: "virDomainSetMemory" : (False, ("memory")), "virDomainSetMemoryFlags" : (False, ("memory")), "virDomainBlockJobSetSpeed" : (False, ("bandwidth")), - "virDomainBlockPull" : (False, ("bandwidth")) } + "virDomainBlockPull" : (False, ("bandwidth")), + "virDomainMigrateGetMaxSpeed" : (False, ("bandwidth")) } def checkLongLegacyFunction(self, name, return_type, signature): if "long" in return_type and "long long" not in return_type: Index: libvirt-0.9.4/include/libvirt/libvirt.h.in =================================================================== --- libvirt-0.9.4.orig/include/libvirt/libvirt.h.in +++ libvirt-0.9.4/include/libvirt/libvirt.h.in @@ -711,6 +711,10 @@ int virDomainMigrateSetMaxSpeed(virDomai unsigned long bandwidth, unsigned int flags); +int virDomainMigrateGetMaxSpeed(virDomainPtr domain, + unsigned long *bandwidth, + unsigned int flags); + /** * VIR_NODEINFO_MAXCPUS: * @nodeinfo: virNodeInfo instance Index: libvirt-0.9.4/python/generator.py =================================================================== --- libvirt-0.9.4.orig/python/generator.py +++ libvirt-0.9.4/python/generator.py @@ -372,6 +372,7 @@ skip_impl = ( 'virNodeGetCPUStats', 'virNodeGetMemoryStats', 'virDomainGetBlockJobInfo', + 'virDomainMigrateGetMaxSpeed', ) Index: libvirt-0.9.4/python/libvirt-override-api.xml =================================================================== --- libvirt-0.9.4.orig/python/libvirt-override-api.xml +++ libvirt-0.9.4/python/libvirt-override-api.xml @@ -356,5 +356,11 @@ + + Get currently configured maximum migration speed for a domain + + + + Index: libvirt-0.9.4/python/libvirt-override.c =================================================================== --- libvirt-0.9.4.orig/python/libvirt-override.c +++ libvirt-0.9.4/python/libvirt-override.c @@ -4543,6 +4543,29 @@ libvirt_virDomainSendKey(PyObject *self return py_retval; } +static PyObject * +libvirt_virDomainMigrateGetMaxSpeed(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + int c_retval; + unsigned long bandwidth; + virDomainPtr domain; + PyObject *pyobj_domain; + + if (!PyArg_ParseTuple(args, (char *)"O:virDomainMigrateGetMaxSpeed", &pyobj_domain)) + return(NULL); + + domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virDomainMigrateGetMaxSpeed(domain, &bandwidth, 0); + LIBVIRT_END_ALLOW_THREADS; + + if (c_retval < 0) + return VIR_PY_INT_FAIL; + py_retval = libvirt_ulongWrap(bandwidth); + return(py_retval); +} + /************************************************************************ * * * The registration stuff * @@ -4632,6 +4655,7 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL}, {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo, METH_VARARGS, NULL}, {(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS, NULL}, + {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; Index: libvirt-0.9.4/src/driver.h =================================================================== --- libvirt-0.9.4.orig/src/driver.h +++ libvirt-0.9.4/src/driver.h @@ -531,6 +531,11 @@ typedef int unsigned int flags); typedef int + (*virDrvDomainMigrateGetMaxSpeed)(virDomainPtr domain, + unsigned long *bandwidth, + unsigned int flags); + +typedef int (*virDrvDomainEventRegisterAny)(virConnectPtr conn, virDomainPtr dom, int eventID, @@ -827,6 +832,7 @@ struct _virDriver { virDrvDomainGetJobInfo domainGetJobInfo; virDrvDomainAbortJob domainAbortJob; virDrvDomainMigrateSetMaxDowntime domainMigrateSetMaxDowntime; + virDrvDomainMigrateGetMaxSpeed domainMigrateGetMaxSpeed; virDrvDomainMigrateSetMaxSpeed domainMigrateSetMaxSpeed; virDrvDomainEventRegisterAny domainEventRegisterAny; virDrvDomainEventDeregisterAny domainEventDeregisterAny; Index: libvirt-0.9.4/src/libvirt.c =================================================================== --- libvirt-0.9.4.orig/src/libvirt.c +++ libvirt-0.9.4/src/libvirt.c @@ -15157,6 +15157,57 @@ error: } /** + * virDomainMigrateGetMaxSpeed: + * @domain: a domain object + * @bandwidth: return value of current migration bandwidth limit in Mbps + * @flags: fine-tuning flags, currently unused, use 0 + * + * Get the current maximum bandwidth (in Mbps) that will be used if the + * domain is migrated. Not all hypervisors will support a bandwidth limit. + * + * Returns 0 in case of success, -1 otherwise. + */ +int +virDomainMigrateGetMaxSpeed(virDomainPtr domain, + unsigned long *bandwidth, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "bandwidth = %p, flags=%x", bandwidth, flags); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + virDispatchError(NULL); + return -1; + } + + if (!bandwidth) { + virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__); + goto error; + } + + conn = domain->conn; + if (conn->flags & VIR_CONNECT_RO) { + virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__); + goto error; + } + + if (conn->driver->domainMigrateGetMaxSpeed) { + if (conn->driver->domainMigrateGetMaxSpeed(domain, bandwidth, flags) < 0) + goto error; + return 0; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + virDispatchError(conn); + return -1; +} + +/** * virConnectDomainEventRegisterAny: * @conn: pointer to the connection * @dom: pointer to the domain Index: libvirt-0.9.4/src/libvirt_public.syms =================================================================== --- libvirt-0.9.4.orig/src/libvirt_public.syms +++ libvirt-0.9.4/src/libvirt_public.syms @@ -480,4 +480,9 @@ LIBVIRT_0.9.4 { virDomainBlockPull; } LIBVIRT_0.9.3; +LIBVIRT_0.9.5 { + global: + virDomainMigrateGetMaxSpeed; +} LIBVIRT_0.9.4; + # .... define new API here using predicted next version number .... Index: libvirt-0.9.4/src/remote/remote_driver.c =================================================================== --- libvirt-0.9.4.orig/src/remote/remote_driver.c +++ libvirt-0.9.4/src/remote/remote_driver.c @@ -4327,6 +4327,7 @@ static virDriver remote_driver = { .domainAbortJob = remoteDomainAbortJob, /* 0.7.7 */ .domainMigrateSetMaxDowntime = remoteDomainMigrateSetMaxDowntime, /* 0.8.0 */ .domainMigrateSetMaxSpeed = remoteDomainMigrateSetMaxSpeed, /* 0.9.0 */ + .domainMigrateGetMaxSpeed = remoteDomainMigrateGetMaxSpeed, /* 0.9.5 */ .domainEventRegisterAny = remoteDomainEventRegisterAny, /* 0.8.0 */ .domainEventDeregisterAny = remoteDomainEventDeregisterAny, /* 0.8.0 */ .domainManagedSave = remoteDomainManagedSave, /* 0.8.0 */ Index: libvirt-0.9.4/src/remote/remote_protocol.x =================================================================== --- libvirt-0.9.4.orig/src/remote/remote_protocol.x +++ libvirt-0.9.4/src/remote/remote_protocol.x @@ -1913,6 +1913,16 @@ struct remote_domain_migrate_set_max_spe unsigned int flags; }; +struct remote_domain_migrate_get_max_speed_args { + remote_nonnull_domain dom; + unsigned int flags; +}; + +struct remote_domain_migrate_get_max_speed_ret { + unsigned hyper bandwidth; /* insert@1 */ +}; + + struct remote_domain_events_register_any_args { int eventID; }; @@ -2475,7 +2485,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_BLOCK_JOB_SET_SPEED = 239, /* autogen autogen */ REMOTE_PROC_DOMAIN_BLOCK_PULL = 240, /* autogen autogen */ - REMOTE_PROC_DOMAIN_EVENT_BLOCK_JOB = 241 /* skipgen skipgen */ + REMOTE_PROC_DOMAIN_EVENT_BLOCK_JOB = 241, /* skipgen skipgen */ + REMOTE_PROC_DOMAIN_MIGRATE_GET_MAX_SPEED = 242 /* autogen autogen */ /* * Notice how the entries are grouped in sets of 10 ? Index: libvirt-0.9.4/src/remote_protocol-structs =================================================================== --- libvirt-0.9.4.orig/src/remote_protocol-structs +++ libvirt-0.9.4/src/remote_protocol-structs @@ -1429,6 +1429,14 @@ struct remote_domain_migrate_set_max_spe uint64_t bandwidth; u_int flags; }; +struct remote_domain_migrate_get_max_speed_args { + remote_nonnull_domain dom; + u_int flags; +}; +struct remote_domain_migrate_get_max_speed_ret { + uint64_t bandwidth; +}; + struct remote_domain_events_register_any_args { int eventID; }; @@ -1936,4 +1944,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_BLOCK_JOB_SET_SPEED = 239, REMOTE_PROC_DOMAIN_BLOCK_PULL = 240, REMOTE_PROC_DOMAIN_EVENT_BLOCK_JOB = 241, + REMOTE_PROC_DOMAIN_MIGRATE_GET_MAX_SPEED = 242, }; Index: libvirt-0.9.4/src/rpc/gendispatch.pl =================================================================== --- libvirt-0.9.4.orig/src/rpc/gendispatch.pl +++ libvirt-0.9.4/src/rpc/gendispatch.pl @@ -222,6 +222,7 @@ my $long_legacy = { NodeGetInfo => { ret => { memory => 1 } }, DomainBlockPull => { arg => { bandwidth => 1 } }, DomainBlockJobSetSpeed => { arg => { bandwidth => 1 } }, + DomainMigrateGetMaxSpeed => { ret => { bandwidth => 1 } }, }; sub hyper_to_long