[libvirt] [PATCH 0/5] RFC: configure inactive domains' maximum memory size

Hi all, This patchset enables us to configure inactive domain's maximum memory size. The basic technique is the same as that of "virsh setmem" command. => http://www.redhat.com/archives/libvir-list/2011-March/msg00013.html *[PATCH 1/5] [RESEND] setmaxmem: remove the code to invoke virDomainSetMemory in cmdSetmaxmem => http://www.redhat.com/archives/libvir-list/2011-March/msg00747.html *[PATCH 2/5] setmaxmem: introduce a new libvirt API (virDomainSetMaxMemoryFlags) *[PATCH 3/5] setmaxmem: implement the code to address the new API in the qemu driver *[PATCH 4/5] setmaxmem: implement the remote protocol to address the new API *[PATCH 5/5] setmaxmem: add the new options to "virsh setmaxmem" command Best regards, Taku Izumi

This patch removes the code which invokes virDomainSetMemory() in cmdSetmaxmem(). When the new maximum memory size becomes less than the current memory size, I think it is not the libvirt client but the each driver that decides the behavior (reject the operation or shrink the current memory size). Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com> --- tools/virsh.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) Index: libvirt/tools/virsh.c =================================================================== --- libvirt.orig/tools/virsh.c +++ libvirt/tools/virsh.c @@ -3034,15 +3034,7 @@ cmdSetmaxmem(vshControl *ctl, const vshC if (virDomainSetMaxMemory(dom, kilobytes) != 0) { vshError(ctl, "%s", _("Unable to change MaxMemorySize")); - virDomainFree(dom); - return FALSE; - } - - if (kilobytes < info.memory) { - if (virDomainSetMemory(dom, kilobytes) != 0) { - vshError(ctl, "%s", _("Unable to shrink current MemorySize")); - ret = FALSE; - } + ret = FALSE; } virDomainFree(dom);

This patch introduces a new libvirt API (virDomainSetMaxMemoryFlags). Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com> --- 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 */

At 03/18/2011 10:44 AM, Taku Izumi Write:
This patch introduces a new libvirt API (virDomainSetMaxMemoryFlags).
Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com> --- 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__);
'goto error' is required here.
+ } + + 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@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

This patch implements the code to address the new API (virDomainSetMaxMemoryFlags) and virDomainSetMaxMemory API in the qemu driver. Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com> --- src/qemu/qemu_driver.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) Index: libvirt/src/qemu/qemu_driver.c =================================================================== --- libvirt.orig/src/qemu/qemu_driver.c +++ libvirt/src/qemu/qemu_driver.c @@ -1569,6 +1569,65 @@ cleanup: return ret; } +static int qemudDomainSetMaxMemoryFlags(virDomainPtr dom, unsigned long memory, + unsigned int flags) { + + struct qemud_driver *driver = dom->conn->privateData; + virDomainObjPtr vm = NULL; + virDomainDefPtr persistentDef = NULL; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_MEM_LIVE | + VIR_DOMAIN_MEM_CONFIG, -1); + + if (flags & VIR_DOMAIN_MEM_LIVE) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + _("cannot resize the maximum memory on active domain")); + goto cleanup; + } + + qemuDriverLock(driver); + vm = virDomainFindByUUID(&driver->domains, dom->uuid); + qemuDriverUnlock(driver); + if (!vm) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virUUIDFormat(dom->uuid, uuidstr); + qemuReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s'"), uuidstr); + goto cleanup; + } + + if (qemuDomainObjBeginJob(vm) < 0) + goto cleanup; + + if (flags & VIR_DOMAIN_MEM_CONFIG) { + persistentDef = virDomainObjGetPersistentDef(driver->caps, vm); + if (!persistentDef) + goto endjob; + + persistentDef->mem.max_balloon = memory; + if (persistentDef->mem.cur_balloon > memory) + persistentDef->mem.cur_balloon = memory; + + ret = virDomainSaveConfig(driver->configDir, persistentDef); + goto endjob; + } + +endjob: + if (qemuDomainObjEndJob(vm) == 0) + vm = NULL; + +cleanup: + if (vm) + virDomainObjUnlock(vm); + return ret; + +} + +static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long memory) { + return qemudDomainSetMaxMemoryFlags(dom, memory, VIR_DOMAIN_MEM_LIVE); +} + static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, unsigned int flags) { struct qemud_driver *driver = dom->conn->privateData; @@ -7044,8 +7103,8 @@ static virDriver qemuDriver = { qemudDomainDestroy, /* domainDestroy */ qemudDomainGetOSType, /* domainGetOSType */ qemudDomainGetMaxMemory, /* domainGetMaxMemory */ - NULL, /* domainSetMaxMemory */ - NULL, /* domainSetMaxMemoryFlags */ + qemudDomainSetMaxMemory, /* domainSetMaxMemory */ + qemudDomainSetMaxMemoryFlags, /* domainSetMaxMemoryFlags */ qemudDomainSetMemory, /* domainSetMemory */ qemudDomainSetMemoryFlags, /* domainSetMemoryFlags */ qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */

At 03/18/2011 10:45 AM, Taku Izumi Write:
This patch implements the code to address the new API (virDomainSetMaxMemoryFlags) and virDomainSetMaxMemory API in the qemu driver.
Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com> --- src/qemu/qemu_driver.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-)
Index: libvirt/src/qemu/qemu_driver.c =================================================================== --- libvirt.orig/src/qemu/qemu_driver.c +++ libvirt/src/qemu/qemu_driver.c @@ -1569,6 +1569,65 @@ cleanup: return ret; }
+static int qemudDomainSetMaxMemoryFlags(virDomainPtr dom, unsigned long memory, + unsigned int flags) { + + struct qemud_driver *driver = dom->conn->privateData; + virDomainObjPtr vm = NULL; + virDomainDefPtr persistentDef = NULL; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_MEM_LIVE | + VIR_DOMAIN_MEM_CONFIG, -1); + + if (flags & VIR_DOMAIN_MEM_LIVE) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + _("cannot resize the maximum memory on active domain")); + goto cleanup; + } + + qemuDriverLock(driver); + vm = virDomainFindByUUID(&driver->domains, dom->uuid); + qemuDriverUnlock(driver); + if (!vm) { + char uuidstr[VIR_UUID_STRING_BUFLEN];
Please use space instead of tab.
+ virUUIDFormat(dom->uuid, uuidstr); + qemuReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s'"), uuidstr); + goto cleanup; + } + + if (qemuDomainObjBeginJob(vm) < 0) + goto cleanup; + + if (flags & VIR_DOMAIN_MEM_CONFIG) { + persistentDef = virDomainObjGetPersistentDef(driver->caps, vm); + if (!persistentDef) + goto endjob; + + persistentDef->mem.max_balloon = memory; + if (persistentDef->mem.cur_balloon > memory) + persistentDef->mem.cur_balloon = memory; + + ret = virDomainSaveConfig(driver->configDir, persistentDef); + goto endjob; + } + +endjob: + if (qemuDomainObjEndJob(vm) == 0) + vm = NULL; + +cleanup: + if (vm) + virDomainObjUnlock(vm); + return ret; + +} + +static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long memory) { + return qemudDomainSetMaxMemoryFlags(dom, memory, VIR_DOMAIN_MEM_LIVE); +} + static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, unsigned int flags) { struct qemud_driver *driver = dom->conn->privateData; @@ -7044,8 +7103,8 @@ static virDriver qemuDriver = { qemudDomainDestroy, /* domainDestroy */ qemudDomainGetOSType, /* domainGetOSType */ qemudDomainGetMaxMemory, /* domainGetMaxMemory */ - NULL, /* domainSetMaxMemory */ - NULL, /* domainSetMaxMemoryFlags */ + qemudDomainSetMaxMemory, /* domainSetMaxMemory */ + qemudDomainSetMaxMemoryFlags, /* domainSetMaxMemoryFlags */ qemudDomainSetMemory, /* domainSetMemory */ qemudDomainSetMemoryFlags, /* domainSetMemoryFlags */ qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

This patch implements the remote protocol to address the new API (virDomainSetMaxMemoryFlags). Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com> --- daemon/remote.c | 26 ++++++++++++++++++++++++++ daemon/remote_dispatch_args.h | 1 + daemon/remote_dispatch_prototypes.h | 8 ++++++++ daemon/remote_dispatch_table.h | 5 +++++ src/remote/remote_driver.c | 29 ++++++++++++++++++++++++++++- src/remote/remote_protocol.c | 13 +++++++++++++ src/remote/remote_protocol.h | 10 ++++++++++ src/remote/remote_protocol.x | 9 ++++++++- src/remote_protocol-structs | 5 +++++ 9 files changed, 104 insertions(+), 2 deletions(-) Index: libvirt/daemon/remote.c =================================================================== --- libvirt.orig/daemon/remote.c +++ libvirt/daemon/remote.c @@ -2358,6 +2358,32 @@ remoteDispatchDomainSetMaxMemory (struct } static int +remoteDispatchDomainSetMaxMemoryFlags (struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *rerr, + remote_domain_set_max_memory_flags_args *args, + void *ret ATTRIBUTE_UNUSED) +{ + virDomainPtr dom; + + dom = get_nonnull_domain (conn, args->dom); + if (dom == NULL) { + remoteDispatchConnError(rerr, conn); + return -1; + } + + if (virDomainSetMaxMemoryFlags (dom, args->memory, args->flags) == -1) { + virDomainFree(dom); + remoteDispatchConnError(rerr, conn); + return -1; + } + virDomainFree(dom); + return 0; +} + +static int remoteDispatchDomainSetMemory (struct qemud_server *server ATTRIBUTE_UNUSED, struct qemud_client *client ATTRIBUTE_UNUSED, virConnectPtr conn, Index: libvirt/daemon/remote_dispatch_args.h =================================================================== --- libvirt.orig/daemon/remote_dispatch_args.h +++ libvirt/daemon/remote_dispatch_args.h @@ -26,6 +26,7 @@ remote_domain_resume_args val_remote_domain_resume_args; remote_domain_set_autostart_args val_remote_domain_set_autostart_args; remote_domain_set_max_memory_args val_remote_domain_set_max_memory_args; + remote_domain_set_max_memory_flags_args val_remote_domain_set_max_memory_flags_args; remote_domain_set_memory_args val_remote_domain_set_memory_args; remote_domain_set_vcpus_args val_remote_domain_set_vcpus_args; remote_domain_shutdown_args val_remote_domain_shutdown_args; Index: libvirt/daemon/remote_dispatch_prototypes.h =================================================================== --- libvirt.orig/daemon/remote_dispatch_prototypes.h +++ libvirt/daemon/remote_dispatch_prototypes.h @@ -562,6 +562,14 @@ static int remoteDispatchDomainSetMaxMem remote_error *err, remote_domain_set_max_memory_args *args, void *ret); +static int remoteDispatchDomainSetMaxMemoryFlags( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_domain_set_max_memory_flags_args *args, + void *ret); static int remoteDispatchDomainSetMemory( struct qemud_server *server, struct qemud_client *client, Index: libvirt/daemon/remote_dispatch_table.h =================================================================== --- libvirt.orig/daemon/remote_dispatch_table.h +++ libvirt/daemon/remote_dispatch_table.h @@ -1037,3 +1037,8 @@ .args_filter = (xdrproc_t) xdr_remote_domain_get_blkio_parameters_args, .ret_filter = (xdrproc_t) xdr_remote_domain_get_blkio_parameters_ret, }, +{ /* DomainSetMaxMemoryFlags => 207 */ + .fn = (dispatch_fn) remoteDispatchDomainSetMaxMemoryFlags, + .args_filter = (xdrproc_t) xdr_remote_domain_set_max_memory_flags_args, + .ret_filter = (xdrproc_t) xdr_void, +}, Index: libvirt/src/remote/remote_driver.c =================================================================== --- libvirt.orig/src/remote/remote_driver.c +++ libvirt/src/remote/remote_driver.c @@ -2427,6 +2427,33 @@ done: } static int +remoteDomainSetMaxMemoryFlags (virDomainPtr domain, unsigned long memory, + unsigned int flags) { + int rv = -1; + remote_domain_set_max_memory_flags_args args; + struct private_data *priv = domain->conn->privateData; + + remoteDriverLock(priv); + + make_nonnull_domain (&args.dom, domain); + args.memory = memory; + args.flags = flags; + + if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_SET_MAX_MEMORY_FLAGS, + (xdrproc_t) xdr_remote_domain_set_max_memory_flags_args, + (char *) &args, + (xdrproc_t) xdr_void, + (char *) NULL) == -1) + goto done; + + rv = 0; + +done: + remoteDriverUnlock(priv); + return rv; +} + +static int remoteDomainSetMemory (virDomainPtr domain, unsigned long memory) { int rv = -1; @@ -11076,7 +11103,7 @@ static virDriver remote_driver = { remoteDomainGetOSType, /* domainGetOSType */ remoteDomainGetMaxMemory, /* domainGetMaxMemory */ remoteDomainSetMaxMemory, /* domainSetMaxMemory */ - NULL, /* domainSetMaxMemoryFlags */ + remoteDomainSetMaxMemoryFlags, /* domainSetMaxMemoryFlags */ remoteDomainSetMemory, /* domainSetMemory */ remoteDomainSetMemoryFlags, /* domainSetMemoryFlags */ remoteDomainSetMemoryParameters, /* domainSetMemoryParameters */ Index: libvirt/src/remote/remote_protocol.c =================================================================== --- libvirt.orig/src/remote/remote_protocol.c +++ libvirt/src/remote/remote_protocol.c @@ -1147,6 +1147,19 @@ xdr_remote_domain_set_max_memory_args (X } bool_t +xdr_remote_domain_set_max_memory_flags_args (XDR *xdrs, + remote_domain_set_max_memory_flags_args *objp) +{ + if (!xdr_remote_nonnull_domain (xdrs, &objp->dom)) + return FALSE; + if (!xdr_uint64_t (xdrs, &objp->memory)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->flags)) + return FALSE; + return TRUE; +} + +bool_t xdr_remote_domain_set_memory_args (XDR *xdrs, remote_domain_set_memory_args *objp) { Index: libvirt/src/remote/remote_protocol.h =================================================================== --- libvirt.orig/src/remote/remote_protocol.h +++ libvirt/src/remote/remote_protocol.h @@ -621,6 +621,13 @@ struct remote_domain_set_max_memory_args }; typedef struct remote_domain_set_max_memory_args remote_domain_set_max_memory_args; +struct remote_domain_set_max_memory_flags_args { + remote_nonnull_domain dom; + uint64_t memory; + u_int flags; +}; +typedef struct remote_domain_set_max_memory_flags_args remote_domain_set_max_memory_flags_args; + struct remote_domain_set_memory_args { remote_nonnull_domain dom; uint64_t memory; @@ -2387,6 +2394,7 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_SET_MEMORY_FLAGS = 204, REMOTE_PROC_DOMAIN_SET_BLKIO_PARAMETERS = 205, REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206, + REMOTE_PROC_DOMAIN_SET_MAX_MEMORY_FLAGS = 207, }; typedef enum remote_procedure remote_procedure; @@ -2508,6 +2516,7 @@ extern bool_t xdr_remote_domain_get_os_ extern bool_t xdr_remote_domain_get_max_memory_args (XDR *, remote_domain_get_max_memory_args*); extern bool_t xdr_remote_domain_get_max_memory_ret (XDR *, remote_domain_get_max_memory_ret*); extern bool_t xdr_remote_domain_set_max_memory_args (XDR *, remote_domain_set_max_memory_args*); +extern bool_t xdr_remote_domain_set_max_memory_flags_args (XDR *, remote_domain_set_max_memory_flags_args*); extern bool_t xdr_remote_domain_set_memory_args (XDR *, remote_domain_set_memory_args*); extern bool_t xdr_remote_domain_set_memory_flags_args (XDR *, remote_domain_set_memory_flags_args*); extern bool_t xdr_remote_domain_get_info_args (XDR *, remote_domain_get_info_args*); @@ -2862,6 +2871,7 @@ extern bool_t xdr_remote_domain_get_os_t extern bool_t xdr_remote_domain_get_max_memory_args (); extern bool_t xdr_remote_domain_get_max_memory_ret (); extern bool_t xdr_remote_domain_set_max_memory_args (); +extern bool_t xdr_remote_domain_set_max_memory_flags_args (); extern bool_t xdr_remote_domain_set_memory_args (); extern bool_t xdr_remote_domain_set_memory_flags_args (); extern bool_t xdr_remote_domain_get_info_args (); Index: libvirt/src/remote/remote_protocol.x =================================================================== --- libvirt.orig/src/remote/remote_protocol.x +++ libvirt/src/remote/remote_protocol.x @@ -676,6 +676,12 @@ struct remote_domain_set_max_memory_args unsigned hyper memory; }; +struct remote_domain_set_max_memory_flags_args { + remote_nonnull_domain dom; + unsigned hyper memory; + unsigned int flags; +}; + struct remote_domain_set_memory_args { remote_nonnull_domain dom; unsigned hyper memory; @@ -2152,7 +2158,8 @@ enum remote_procedure { REMOTE_PROC_GET_SYSINFO = 203, REMOTE_PROC_DOMAIN_SET_MEMORY_FLAGS = 204, REMOTE_PROC_DOMAIN_SET_BLKIO_PARAMETERS = 205, - REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206 + REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206, + REMOTE_PROC_DOMAIN_SET_MAX_MEMORY_FLAGS = 207 /* * Notice how the entries are grouped in sets of 10 ? Index: libvirt/src/remote_protocol-structs =================================================================== --- libvirt.orig/src/remote_protocol-structs +++ libvirt/src/remote_protocol-structs @@ -371,6 +371,11 @@ struct remote_domain_set_max_memory_args remote_nonnull_domain dom; uint64_t memory; }; +struct remote_domain_set_max_memory_flags_args { + remote_nonnull_domain dom; + uint64_t memory; + u_int flags; +}; struct remote_domain_set_memory_args { remote_nonnull_domain dom; uint64_t memory;

At 03/18/2011 10:46 AM, Taku Izumi Write:
This patch implements the remote protocol to address the new API (virDomainSetMaxMemoryFlags).
Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com> --- daemon/remote.c | 26 ++++++++++++++++++++++++++ daemon/remote_dispatch_args.h | 1 + daemon/remote_dispatch_prototypes.h | 8 ++++++++ daemon/remote_dispatch_table.h | 5 +++++ src/remote/remote_driver.c | 29 ++++++++++++++++++++++++++++- src/remote/remote_protocol.c | 13 +++++++++++++ src/remote/remote_protocol.h | 10 ++++++++++ src/remote/remote_protocol.x | 9 ++++++++- src/remote_protocol-structs | 5 +++++ 9 files changed, 104 insertions(+), 2 deletions(-)
Index: libvirt/daemon/remote.c =================================================================== --- libvirt.orig/daemon/remote.c +++ libvirt/daemon/remote.c @@ -2358,6 +2358,32 @@ remoteDispatchDomainSetMaxMemory (struct }
static int +remoteDispatchDomainSetMaxMemoryFlags (struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *rerr, + remote_domain_set_max_memory_flags_args *args, + void *ret ATTRIBUTE_UNUSED) +{ + virDomainPtr dom; + + dom = get_nonnull_domain (conn, args->dom); + if (dom == NULL) { + remoteDispatchConnError(rerr, conn); + return -1; + } + + if (virDomainSetMaxMemoryFlags (dom, args->memory, args->flags) == -1) { + virDomainFree(dom); + remoteDispatchConnError(rerr, conn); + return -1; + } + virDomainFree(dom); + return 0; +} + +static int remoteDispatchDomainSetMemory (struct qemud_server *server ATTRIBUTE_UNUSED, struct qemud_client *client ATTRIBUTE_UNUSED, virConnectPtr conn, Index: libvirt/daemon/remote_dispatch_args.h =================================================================== --- libvirt.orig/daemon/remote_dispatch_args.h +++ libvirt/daemon/remote_dispatch_args.h @@ -26,6 +26,7 @@ remote_domain_resume_args val_remote_domain_resume_args; remote_domain_set_autostart_args val_remote_domain_set_autostart_args; remote_domain_set_max_memory_args val_remote_domain_set_max_memory_args; + remote_domain_set_max_memory_flags_args val_remote_domain_set_max_memory_flags_args; remote_domain_set_memory_args val_remote_domain_set_memory_args; remote_domain_set_vcpus_args val_remote_domain_set_vcpus_args; remote_domain_shutdown_args val_remote_domain_shutdown_args; Index: libvirt/daemon/remote_dispatch_prototypes.h =================================================================== --- libvirt.orig/daemon/remote_dispatch_prototypes.h +++ libvirt/daemon/remote_dispatch_prototypes.h @@ -562,6 +562,14 @@ static int remoteDispatchDomainSetMaxMem remote_error *err, remote_domain_set_max_memory_args *args, void *ret); +static int remoteDispatchDomainSetMaxMemoryFlags( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_domain_set_max_memory_flags_args *args, + void *ret); static int remoteDispatchDomainSetMemory( struct qemud_server *server, struct qemud_client *client, Index: libvirt/daemon/remote_dispatch_table.h =================================================================== --- libvirt.orig/daemon/remote_dispatch_table.h +++ libvirt/daemon/remote_dispatch_table.h @@ -1037,3 +1037,8 @@ .args_filter = (xdrproc_t) xdr_remote_domain_get_blkio_parameters_args, .ret_filter = (xdrproc_t) xdr_remote_domain_get_blkio_parameters_ret, }, +{ /* DomainSetMaxMemoryFlags => 207 */ + .fn = (dispatch_fn) remoteDispatchDomainSetMaxMemoryFlags, + .args_filter = (xdrproc_t) xdr_remote_domain_set_max_memory_flags_args, + .ret_filter = (xdrproc_t) xdr_void, +}, Index: libvirt/src/remote/remote_driver.c =================================================================== --- libvirt.orig/src/remote/remote_driver.c +++ libvirt/src/remote/remote_driver.c @@ -2427,6 +2427,33 @@ done: }
static int +remoteDomainSetMaxMemoryFlags (virDomainPtr domain, unsigned long memory, + unsigned int flags) { + int rv = -1; + remote_domain_set_max_memory_flags_args args; + struct private_data *priv = domain->conn->privateData; + + remoteDriverLock(priv); + + make_nonnull_domain (&args.dom, domain); + args.memory = memory; + args.flags = flags; + + if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_SET_MAX_MEMORY_FLAGS, + (xdrproc_t) xdr_remote_domain_set_max_memory_flags_args, + (char *) &args, + (xdrproc_t) xdr_void, + (char *) NULL) == -1) + goto done; + + rv = 0; + +done: + remoteDriverUnlock(priv); + return rv; +} + +static int remoteDomainSetMemory (virDomainPtr domain, unsigned long memory) { int rv = -1; @@ -11076,7 +11103,7 @@ static virDriver remote_driver = { remoteDomainGetOSType, /* domainGetOSType */ remoteDomainGetMaxMemory, /* domainGetMaxMemory */ remoteDomainSetMaxMemory, /* domainSetMaxMemory */ - NULL, /* domainSetMaxMemoryFlags */ + remoteDomainSetMaxMemoryFlags, /* domainSetMaxMemoryFlags */ remoteDomainSetMemory, /* domainSetMemory */ remoteDomainSetMemoryFlags, /* domainSetMemoryFlags */ remoteDomainSetMemoryParameters, /* domainSetMemoryParameters */ Index: libvirt/src/remote/remote_protocol.c =================================================================== --- libvirt.orig/src/remote/remote_protocol.c +++ libvirt/src/remote/remote_protocol.c @@ -1147,6 +1147,19 @@ xdr_remote_domain_set_max_memory_args (X }
bool_t +xdr_remote_domain_set_max_memory_flags_args (XDR *xdrs, + remote_domain_set_max_memory_flags_args *objp)
Please check the setting of your mail client. This patch is broken by your mail client.
+{ + if (!xdr_remote_nonnull_domain (xdrs, &objp->dom)) + return FALSE; + if (!xdr_uint64_t (xdrs, &objp->memory)) + return FALSE; + if (!xdr_u_int (xdrs, &objp->flags)) + return FALSE; + return TRUE; +} + +bool_t xdr_remote_domain_set_memory_args (XDR *xdrs, remote_domain_set_memory_args *objp) {
Index: libvirt/src/remote/remote_protocol.h =================================================================== --- libvirt.orig/src/remote/remote_protocol.h +++ libvirt/src/remote/remote_protocol.h @@ -621,6 +621,13 @@ struct remote_domain_set_max_memory_args }; typedef struct remote_domain_set_max_memory_args remote_domain_set_max_memory_args;
+struct remote_domain_set_max_memory_flags_args { + remote_nonnull_domain dom; + uint64_t memory; + u_int flags; +}; +typedef struct remote_domain_set_max_memory_flags_args remote_domain_set_max_memory_flags_args;
The same as above
+ struct remote_domain_set_memory_args { remote_nonnull_domain dom; uint64_t memory; @@ -2387,6 +2394,7 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_SET_MEMORY_FLAGS = 204, REMOTE_PROC_DOMAIN_SET_BLKIO_PARAMETERS = 205, REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206, + REMOTE_PROC_DOMAIN_SET_MAX_MEMORY_FLAGS = 207, }; typedef enum remote_procedure remote_procedure;
@@ -2508,6 +2516,7 @@ extern bool_t xdr_remote_domain_get_os_ extern bool_t xdr_remote_domain_get_max_memory_args (XDR *, remote_domain_get_max_memory_args*); extern bool_t xdr_remote_domain_get_max_memory_ret (XDR *, remote_domain_get_max_memory_ret*); extern bool_t xdr_remote_domain_set_max_memory_args (XDR *, remote_domain_set_max_memory_args*); +extern bool_t xdr_remote_domain_set_max_memory_flags_args (XDR *, remote_domain_set_max_memory_flags_args*); extern bool_t xdr_remote_domain_set_memory_args (XDR *, remote_domain_set_memory_args*); extern bool_t xdr_remote_domain_set_memory_flags_args (XDR *, remote_domain_set_memory_flags_args*); extern bool_t xdr_remote_domain_get_info_args (XDR *, remote_domain_get_info_args*); @@ -2862,6 +2871,7 @@ extern bool_t xdr_remote_domain_get_os_t extern bool_t xdr_remote_domain_get_max_memory_args (); extern bool_t xdr_remote_domain_get_max_memory_ret (); extern bool_t xdr_remote_domain_set_max_memory_args (); +extern bool_t xdr_remote_domain_set_max_memory_flags_args (); extern bool_t xdr_remote_domain_set_memory_args (); extern bool_t xdr_remote_domain_set_memory_flags_args (); extern bool_t xdr_remote_domain_get_info_args (); Index: libvirt/src/remote/remote_protocol.x =================================================================== --- libvirt.orig/src/remote/remote_protocol.x +++ libvirt/src/remote/remote_protocol.x @@ -676,6 +676,12 @@ struct remote_domain_set_max_memory_args unsigned hyper memory; };
+struct remote_domain_set_max_memory_flags_args { + remote_nonnull_domain dom; + unsigned hyper memory; + unsigned int flags; +}; + struct remote_domain_set_memory_args { remote_nonnull_domain dom; unsigned hyper memory; @@ -2152,7 +2158,8 @@ enum remote_procedure { REMOTE_PROC_GET_SYSINFO = 203, REMOTE_PROC_DOMAIN_SET_MEMORY_FLAGS = 204, REMOTE_PROC_DOMAIN_SET_BLKIO_PARAMETERS = 205, - REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206 + REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206, + REMOTE_PROC_DOMAIN_SET_MAX_MEMORY_FLAGS = 207
/* * Notice how the entries are grouped in sets of 10 ? Index: libvirt/src/remote_protocol-structs =================================================================== --- libvirt.orig/src/remote_protocol-structs +++ libvirt/src/remote_protocol-structs @@ -371,6 +371,11 @@ struct remote_domain_set_max_memory_args remote_nonnull_domain dom; uint64_t memory; }; +struct remote_domain_set_max_memory_flags_args { + remote_nonnull_domain dom; + uint64_t memory; + u_int flags; +}; struct remote_domain_set_memory_args { remote_nonnull_domain dom; uint64_t memory;
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

This patch adds the new options (--live and --config) to "virsh setmaxmem" command. The behavior of above options is the same as that of "virsh setmem". When the --config option is specified, a modofication is effective for the persistent domain, while --live option is specified, a modification is effective for an active domain. Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com> --- tools/virsh.c | 27 ++++++++++++++++++++++++--- tools/virsh.pod | 12 ++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) Index: libvirt/tools/virsh.c =================================================================== --- libvirt.orig/tools/virsh.c +++ libvirt/tools/virsh.c @@ -2998,6 +2998,8 @@ static const vshCmdInfo info_setmaxmem[] static const vshCmdOptDef opts_setmaxmem[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"kilobytes", VSH_OT_INT, VSH_OFLAG_REQ, N_("maximum memory limit in kilobytes")}, + {"config", VSH_OT_BOOL, 0, N_("affect next boot")}, + {"live", VSH_OT_BOOL, 0, N_("affect running domain")}, {NULL, 0, 0, NULL} }; @@ -3008,6 +3010,18 @@ cmdSetmaxmem(vshControl *ctl, const vshC virDomainInfo info; int kilobytes = 0; int ret = TRUE; + int config = vshCommandOptBool(cmd, "config"); + int live = vshCommandOptBool(cmd, "live"); + int flags = 0; + + /* + * Need to use flags if config was specified, but prefer older api + * for live-only behavior otherwise */ + if (config) { + flags = VIR_DOMAIN_MEM_CONFIG; + if (live) + flags |= VIR_DOMAIN_MEM_LIVE; + } if (!vshConnectionUsability(ctl, ctl->conn)) return FALSE; @@ -3032,9 +3046,16 @@ cmdSetmaxmem(vshControl *ctl, const vshC return FALSE; } - if (virDomainSetMaxMemory(dom, kilobytes) != 0) { - vshError(ctl, "%s", _("Unable to change MaxMemorySize")); - ret = FALSE; + if (!flags) { + if (virDomainSetMaxMemory(dom, kilobytes) != 0) { + vshError(ctl, "%s", _("Unable to change MaxMemorySize")); + ret = FALSE; + } + } else { + if (virDomainSetMaxMemoryFlags(dom, kilobytes, flags) < 0) { + vshError(ctl, "%s", _("Unable to change MaxMemorySize")); + ret = FALSE; + } } virDomainFree(dom); Index: libvirt/tools/virsh.pod =================================================================== --- libvirt.orig/tools/virsh.pod +++ libvirt/tools/virsh.pod @@ -593,12 +593,14 @@ rounds the parameter up unless the kB ar For Xen, you can only adjust the memory of a running domain if the domain is paravirtualized or running the PV balloon driver. -=item B<setmaxmem> I<domain-id> B<kilobytes> +=item B<setmaxmem> I<domain-id> B<kilobytes> optional I<--config> I<--live> -Change the maximum memory allocation limit for an inactive guest domain. +Change the maximum memory allocation limit for a guest domain. +If I<--live> is specified, affect a running guest. +If I<--config> is specified, affect the next boot of a persistent guest. +Both flags may be given. If neither flag is given, I<--live> is assumed. -This command works for at least the Xen and vSphere/ESX hypervisors, -but not for QEMU/KVM. +This command works for at least the Xen, QEMU/KVM and vSphere/ESX hypervisors. Some hypervisors require a larger granularity than kilobytes, rounding up requests that are not an even multiple of the desired amount. vSphere/ESX @@ -606,8 +608,6 @@ is one of these, requiring the parameter vSphere/ESX, 263168 (257MB) would be rounded up because it's not a multiple of 4MB, while 266240 (260MB) is valid without rounding. -Note, to change the maximum memory allocation for a QEMU/KVM guest domain, -use the virsh B<edit> command instead to update its XML <memory> element. =item B<memtune> I<domain-id> optional I<--hard-limit> B<kilobytes> optional I<--soft-limit> B<kilobytes> optional I<--swap-hard-limit>

On Fri, Mar 18, 2011 at 11:25:42AM +0900, Taku Izumi wrote:
Hi all,
This patchset enables us to configure inactive domain's maximum memory size.
The basic technique is the same as that of "virsh setmem" command. => http://www.redhat.com/archives/libvir-list/2011-March/msg00013.html
*[PATCH 1/5] [RESEND] setmaxmem: remove the code to invoke virDomainSetMemory in cmdSetmaxmem => http://www.redhat.com/archives/libvir-list/2011-March/msg00747.html *[PATCH 2/5] setmaxmem: introduce a new libvirt API (virDomainSetMaxMemoryFlags) *[PATCH 3/5] setmaxmem: implement the code to address the new API in the qemu driver *[PATCH 4/5] setmaxmem: implement the remote protocol to address the new API *[PATCH 5/5] setmaxmem: add the new options to "virsh setmaxmem" command
Rather than add a new API, now that we have virDomainSetMemoryFlags() I don't see why we could not use and extra flag on that API, VIR_DOMAIN_MAX_MEM and use the same entry point. virDomainSetMaxMemory and virDomainSetMemory are separate because we didn't add a flag for them, that was a mistake, but now we can tunnel maximum memory changes though virDomainSetMemoryFlags() We would then allow VIR_DOMAIN_MEM_LIVE -> change live memory target VIR_DOMAIN_MEM_CONFIG -> change memory target on config i.e. next reboot VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MAX_MEM -> change live max memory (if feasible) VIR_DOMAIN_MEM_CONFIG | VIR_DOMAIN_MAX_MEM -> change max memory on config Adding more API may lead to more confusion than one API with all various cases explained at a single place. Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On 03/21/2011 01:58 AM, Daniel Veillard wrote:
Rather than add a new API, now that we have virDomainSetMemoryFlags() I don't see why we could not use and extra flag on that API, VIR_DOMAIN_MAX_MEM and use the same entry point.
Agreed, and this was how I handled the vcpu issue (we had separate calls for max vcpus vs. current vcpus, but the new vcpuFlag api covers both cases).
virDomainSetMaxMemory and virDomainSetMemory are separate because we didn't add a flag for them, that was a mistake, but now we can tunnel maximum memory changes though virDomainSetMemoryFlags()
We would then allow VIR_DOMAIN_MEM_LIVE -> change live memory target VIR_DOMAIN_MEM_CONFIG -> change memory target on config i.e. next reboot VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MAX_MEM -> change live max memory (if feasible)
This would imply memory hot-plugging, which is in itself an interesting topic not currently supported by qemu, but which might be worth adding someday in the future. Of course, the API would fail where it is not supported, but I agree that this flag combination might become useful in the future. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Daniel, Eric, Wen, Thank you for reviewing. I'll respin according to Daniel's point. Thank you. Taku Izumi
participants (4)
-
Daniel Veillard
-
Eric Blake
-
Taku Izumi
-
Wen Congyang