This patch introduces a new libvirt API (virDomainSetMaxMemoryFlags). Signed-off-by: Taku Izumi <izumi.taku@xxxxxxxxxxxxxx> --- include/libvirt/libvirt.h.in | 3 ++ src/driver.h | 5 +++ src/esx/esx_driver.c | 1 src/libvirt.c | 62 +++++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 src/lxc/lxc_driver.c | 1 src/opennebula/one_driver.c | 1 src/openvz/openvz_driver.c | 1 src/phyp/phyp_driver.c | 1 src/qemu/qemu_driver.c | 1 src/remote/remote_driver.c | 1 src/test/test_driver.c | 1 src/uml/uml_driver.c | 1 src/vbox/vbox_tmpl.c | 1 src/vmware/vmware_driver.c | 1 src/xen/xen_driver.c | 1 src/xenapi/xenapi_driver.c | 1 17 files changed, 84 insertions(+) Index: libvirt/include/libvirt/libvirt.h.in =================================================================== --- libvirt.orig/include/libvirt/libvirt.h.in +++ libvirt/include/libvirt/libvirt.h.in @@ -868,6 +868,9 @@ char * virDomainGetOSTy unsigned long virDomainGetMaxMemory (virDomainPtr domain); int virDomainSetMaxMemory (virDomainPtr domain, unsigned long memory); +int virDomainSetMaxMemoryFlags (virDomainPtr domain, + unsigned long memory, + unsigned int flags); int virDomainSetMemory (virDomainPtr domain, unsigned long memory); int virDomainSetMemoryFlags (virDomainPtr domain, Index: libvirt/src/driver.h =================================================================== --- libvirt.orig/src/driver.h +++ libvirt/src/driver.h @@ -131,6 +131,10 @@ typedef int (*virDrvDomainSetMaxMemory) (virDomainPtr domain, unsigned long memory); typedef int + (*virDrvDomainSetMaxMemoryFlags)(virDomainPtr domain, + unsigned long memory, + unsigned int flags); +typedef int (*virDrvDomainSetMemory) (virDomainPtr domain, unsigned long memory); typedef int @@ -551,6 +555,7 @@ struct _virDriver { virDrvDomainGetOSType domainGetOSType; virDrvDomainGetMaxMemory domainGetMaxMemory; virDrvDomainSetMaxMemory domainSetMaxMemory; + virDrvDomainSetMaxMemoryFlags domainSetMaxMemoryFlags; virDrvDomainSetMemory domainSetMemory; virDrvDomainSetMemoryFlags domainSetMemoryFlags; virDrvDomainSetMemoryParameters domainSetMemoryParameters; Index: libvirt/src/esx/esx_driver.c =================================================================== --- libvirt.orig/src/esx/esx_driver.c +++ libvirt/src/esx/esx_driver.c @@ -4592,6 +4592,7 @@ static virDriver esxDriver = { esxDomainGetOSType, /* domainGetOSType */ esxDomainGetMaxMemory, /* domainGetMaxMemory */ esxDomainSetMaxMemory, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ esxDomainSetMemory, /* domainSetMemory */ NULL, /* domainSetMemoryFlags */ esxDomainSetMemoryParameters, /* domainSetMemoryParameters */ Index: libvirt/src/libvirt.c =================================================================== --- libvirt.orig/src/libvirt.c +++ libvirt/src/libvirt.c @@ -2791,6 +2791,68 @@ error: return -1; } +/* + * virDomainSetMaxMemoryFlags: + * @domain: a domain object or NULL + * @memory: the memory size in kilobytes + * @flags: an OR'ed set of virDomainMemoryModFlags + * + * Dynamically change the maximum amount of physical memory allocated to a + * domain. If domain is NULL, then this change the amount of memory reserved + * to Domain0 i.e. the domain where the application runs. + * This function requires privileged access to the hypervisor. + * + * @flags must include VIR_DOMAIN_MEM_LIVE to affect a running + * domain (which may fail if domain is not active), or + * VIR_DOMAIN_MEM_CONFIG to affect the next boot via the XML + * description of the domain. Both flags may be set. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainSetMaxMemoryFlags(virDomainPtr domain, unsigned long memory, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "memory=%lu flags=%u", memory, flags); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + virDispatchError(NULL); + return -1; + } + + if (domain->conn->flags & VIR_CONNECT_RO) { + virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__); + goto error; + } + + if (memory < 4096 || + (flags & (VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MEM_CONFIG)) == 0) { + virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__); + } + + conn = domain->conn; + + if (conn->driver->domainSetMaxMemoryFlags) { + int ret; + ret = conn->driver->domainSetMaxMemoryFlags (domain, memory, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + virDispatchError(domain->conn); + return -1; +} + + /** * virDomainSetMemory: * @domain: a domain object or NULL Index: libvirt/src/libvirt_public.syms =================================================================== --- libvirt.orig/src/libvirt_public.syms +++ libvirt/src/libvirt_public.syms @@ -431,6 +431,7 @@ LIBVIRT_0.9.0 { virDomainSetMemoryFlags; virEventRegisterDefaultImpl; virEventRunDefaultImpl; + virDomainSetMaxMemoryFlags; } LIBVIRT_0.8.8; # .... define new API here using predicted next version number .... Index: libvirt/src/lxc/lxc_driver.c =================================================================== --- libvirt.orig/src/lxc/lxc_driver.c +++ libvirt/src/lxc/lxc_driver.c @@ -2817,6 +2817,7 @@ static virDriver lxcDriver = { lxcGetOSType, /* domainGetOSType */ lxcDomainGetMaxMemory, /* domainGetMaxMemory */ lxcDomainSetMaxMemory, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ lxcDomainSetMemory, /* domainSetMemory */ NULL, /* domainSetMemoryFlags */ lxcDomainSetMemoryParameters, /* domainSetMemoryParameters */ Index: libvirt/src/opennebula/one_driver.c =================================================================== --- libvirt.orig/src/opennebula/one_driver.c +++ libvirt/src/opennebula/one_driver.c @@ -749,6 +749,7 @@ static virDriver oneDriver = { oneGetOSType, /* domainGetOSType */ NULL, /* domainGetMaxMemory */ NULL, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ NULL, /* domainSetMemory */ NULL, /* domainSetMemoryFlags */ NULL, /* domainSetMemoryParameters */ Index: libvirt/src/openvz/openvz_driver.c =================================================================== --- libvirt.orig/src/openvz/openvz_driver.c +++ libvirt/src/openvz/openvz_driver.c @@ -1570,6 +1570,7 @@ static virDriver openvzDriver = { openvzGetOSType, /* domainGetOSType */ NULL, /* domainGetMaxMemory */ NULL, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ NULL, /* domainSetMemory */ NULL, /* domainSetMemoryFlags */ NULL, /* domainSetMemoryParameters */ Index: libvirt/src/phyp/phyp_driver.c =================================================================== --- libvirt.orig/src/phyp/phyp_driver.c +++ libvirt/src/phyp/phyp_driver.c @@ -3972,6 +3972,7 @@ static virDriver phypDriver = { NULL, /* domainGetOSType */ NULL, /* domainGetMaxMemory */ NULL, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ NULL, /* domainSetMemory */ NULL, /* domainSetMemoryFlags */ NULL, /* domainSetMemoryParameters */ Index: libvirt/src/qemu/qemu_driver.c =================================================================== --- libvirt.orig/src/qemu/qemu_driver.c +++ libvirt/src/qemu/qemu_driver.c @@ -7045,6 +7045,7 @@ static virDriver qemuDriver = { qemudDomainGetOSType, /* domainGetOSType */ qemudDomainGetMaxMemory, /* domainGetMaxMemory */ NULL, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ qemudDomainSetMemory, /* domainSetMemory */ qemudDomainSetMemoryFlags, /* domainSetMemoryFlags */ qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */ Index: libvirt/src/remote/remote_driver.c =================================================================== --- libvirt.orig/src/remote/remote_driver.c +++ libvirt/src/remote/remote_driver.c @@ -11076,6 +11076,7 @@ static virDriver remote_driver = { remoteDomainGetOSType, /* domainGetOSType */ remoteDomainGetMaxMemory, /* domainGetMaxMemory */ remoteDomainSetMaxMemory, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ remoteDomainSetMemory, /* domainSetMemory */ remoteDomainSetMemoryFlags, /* domainSetMemoryFlags */ remoteDomainSetMemoryParameters, /* domainSetMemoryParameters */ Index: libvirt/src/test/test_driver.c =================================================================== --- libvirt.orig/src/test/test_driver.c +++ libvirt/src/test/test_driver.c @@ -5364,6 +5364,7 @@ static virDriver testDriver = { testGetOSType, /* domainGetOSType */ testGetMaxMemory, /* domainGetMaxMemory */ testSetMaxMemory, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ testSetMemory, /* domainSetMemory */ NULL, /* domainSetMemoryFlags */ NULL, /* domainSetMemoryParameters */ Index: libvirt/src/uml/uml_driver.c =================================================================== --- libvirt.orig/src/uml/uml_driver.c +++ libvirt/src/uml/uml_driver.c @@ -2166,6 +2166,7 @@ static virDriver umlDriver = { umlDomainGetOSType, /* domainGetOSType */ umlDomainGetMaxMemory, /* domainGetMaxMemory */ umlDomainSetMaxMemory, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ umlDomainSetMemory, /* domainSetMemory */ NULL, /* domainSetMemoryFlags */ NULL, /* domainSetMemoryParameters */ Index: libvirt/src/vbox/vbox_tmpl.c =================================================================== --- libvirt.orig/src/vbox/vbox_tmpl.c +++ libvirt/src/vbox/vbox_tmpl.c @@ -8554,6 +8554,7 @@ virDriver NAME(Driver) = { vboxDomainGetOSType, /* domainGetOSType */ NULL, /* domainGetMaxMemory */ NULL, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ vboxDomainSetMemory, /* domainSetMemory */ NULL, /* domainSetMemoryFlags */ NULL, /* domainSetMemoryParameters */ Index: libvirt/src/vmware/vmware_driver.c =================================================================== --- libvirt.orig/src/vmware/vmware_driver.c +++ libvirt/src/vmware/vmware_driver.c @@ -924,6 +924,7 @@ static virDriver vmwareDriver = { vmwareGetOSType, /* domainGetOSType */ NULL, /* domainGetMaxMemory */ NULL, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ NULL, /* domainSetMemory */ NULL, /* domainSetMemoryFlags */ NULL, /* domainSetMemoryParameters */ Index: libvirt/src/xen/xen_driver.c =================================================================== --- libvirt.orig/src/xen/xen_driver.c +++ libvirt/src/xen/xen_driver.c @@ -2033,6 +2033,7 @@ static virDriver xenUnifiedDriver = { xenUnifiedDomainGetOSType, /* domainGetOSType */ xenUnifiedDomainGetMaxMemory, /* domainGetMaxMemory */ xenUnifiedDomainSetMaxMemory, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ xenUnifiedDomainSetMemory, /* domainSetMemory */ NULL, /*domainSetMemoryFlags */ NULL, /* domainSetMemoryParameters */ Index: libvirt/src/xenapi/xenapi_driver.c =================================================================== --- libvirt.orig/src/xenapi/xenapi_driver.c +++ libvirt/src/xenapi/xenapi_driver.c @@ -1802,6 +1802,7 @@ static virDriver xenapiDriver = { xenapiDomainGetOSType, /* domainGetOSType */ xenapiDomainGetMaxMemory, /* domainGetMaxMemory */ xenapiDomainSetMaxMemory, /* domainSetMaxMemory */ + NULL, /* domainSetMaxMemoryFlags */ NULL, /* domainSetMemory */ NULL, /* domainSetMemoryFlags */ NULL, /* domainSetMemoryParameters */ -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list