[PATCH 0 of 2] Dynamic memory ballooning

This set adds dynamic memory ballooning when a client does a ModifyResourceSettings on the Memory RASD.

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1194897180 28800 # Node ID f86d7a5bfa6b597d3909eae06f367ec640fb0a2c # Parent c7572e9cdf49a37b96375e799c7b9818ae36fd1d Add device change support (just for memory right now) Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r c7572e9cdf49 -r f86d7a5bfa6b libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Mon Nov 12 11:07:46 2007 -0800 +++ b/libxkutil/device_parsing.c Mon Nov 12 11:53:00 2007 -0800 @@ -615,9 +615,9 @@ void cleanup_dominfo(struct domain **dom *dominfo = NULL; } -static int change_device(virDomainPtr dom, - struct virt_device *dev, - bool attach) +static int _change_device(virDomainPtr dom, + struct virt_device *dev, + bool attach) { char *xml = NULL; int ret = 0; @@ -648,11 +648,28 @@ static int change_device(virDomainPtr do } +static int change_memory(virDomainPtr dom, + struct virt_device *dev) +{ + CU_DEBUG("Changing memory of %s to %llu/%llu", + virDomainGetName(dom), + dev->dev.mem.size, + dev->dev.mem.maxsize); + + if (virDomainSetMemory(dom, dev->dev.mem.size)) + return 0; + + if (virDomainSetMaxMemory(dom, dev->dev.mem.maxsize)) + return 0; + + return 1; +} + int attach_device(virDomainPtr dom, struct virt_device *dev) { if ((dev->type == VIRT_DEV_NET) || (dev->type == VIRT_DEV_DISK)) - return change_device(dom, dev, true); + return _change_device(dom, dev, true); CU_DEBUG("Unhandled device type %i", dev->type); @@ -663,7 +680,17 @@ int detach_device(virDomainPtr dom, stru { if ((dev->type == VIRT_DEV_NET) || (dev->type == VIRT_DEV_DISK)) - return change_device(dom, dev, false); + return _change_device(dom, dev, false); + + CU_DEBUG("Unhandled device type %i", dev->type); + + return 0; +} + +int change_device(virDomainPtr dom, struct virt_device *dev) +{ + if (dev->type == VIRT_DEV_MEM) + return change_memory(dom, dev); CU_DEBUG("Unhandled device type %i", dev->type); diff -r c7572e9cdf49 -r f86d7a5bfa6b libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Mon Nov 12 11:07:46 2007 -0800 +++ b/libxkutil/device_parsing.h Mon Nov 12 11:53:00 2007 -0800 @@ -113,6 +113,7 @@ int parse_fq_devid(char *devid, char **h int attach_device(virDomainPtr dom, struct virt_device *dev); int detach_device(virDomainPtr dom, struct virt_device *dev); +int change_device(virDomainPtr dom, struct virt_device *dev); #endif

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1194897181 28800 # Node ID 50be717355487fc76bd725e71201d49564b77edf # Parent f86d7a5bfa6b597d3909eae06f367ec640fb0a2c Make memory device changes dynamic Refuse to add or delete a memory device of course, but allow modify Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r f86d7a5bfa6b -r 50be71735548 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Mon Nov 12 11:53:00 2007 -0800 +++ b/src/Virt_VirtualSystemManagementService.c Mon Nov 12 11:53:01 2007 -0800 @@ -50,6 +50,12 @@ const static CMPIBroker *_BROKER; +enum ResourceAction { + RESOURCE_ADD, + RESOURCE_DEL, + RESOURCE_MOD, +}; + static int parse_str_inst_array(CMPIArray *array, const char *ns, struct inst_list *list) @@ -568,6 +574,9 @@ static struct virt_device **find_list(st } else if (type == VIRT_DEV_VCPU) { list = &dominfo->dev_vcpu; *count = &dominfo->dev_vcpu_ct; + } else if (type == VIRT_DEV_MEM) { + list = &dominfo->dev_mem; + *count = &dominfo->dev_mem_ct; } return list; @@ -575,17 +584,26 @@ static struct virt_device **find_list(st static CMPIStatus _resource_dynamic(struct domain *dominfo, struct virt_device *dev, - bool attach) + enum ResourceAction action) { CMPIStatus s; virConnectPtr conn; virDomainPtr dom; int (*func)(virDomainPtr, struct virt_device *); - if (attach) + if (action == RESOURCE_ADD) func = attach_device; - else + else if (action == RESOURCE_DEL) func = detach_device; + else if (action == RESOURCE_MOD) + func = change_device; + else { + CU_DEBUG("Unknown dynamic resource action: %i", action); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Internal error (undefined resource action)"); + return s; + } conn = lv_connect(_BROKER, &s); if (conn == NULL) { @@ -614,8 +632,8 @@ static CMPIStatus _resource_dynamic(stru if (func(dom, dev) == 0) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, - "Unable to %s device", - attach ? "attach" : "detach"); + "Unable to change (%i) device", + action); } else { CMSetStatus(&s, CMPI_RC_OK); } @@ -638,7 +656,7 @@ static CMPIStatus resource_del(struct do int i; _list = find_list(dominfo, type, &count); - if (_list != NULL) + if ((type == CIM_RASD_TYPE_MEM) || (_list != NULL)) list = *_list; else { cu_statusf(_BROKER, &s, @@ -656,7 +674,7 @@ static CMPIStatus resource_del(struct do struct virt_device *dev = &list[i]; if (STREQ(dev->id, devid)) { - s = _resource_dynamic(dominfo, dev, false); + s = _resource_dynamic(dominfo, dev, RESOURCE_DEL); dev->type = VIRT_DEV_UNKNOWN; break; } @@ -678,7 +696,7 @@ static CMPIStatus resource_add(struct do int *count; _list = find_list(dominfo, type, &count); - if (_list == NULL) { + if ((type == CIM_RASD_TYPE_MEM) || (_list == NULL)) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Cannot add resources of type %" PRIu16, @@ -713,7 +731,7 @@ static CMPIStatus resource_add(struct do dev->id = strdup(devid); rasd_to_vdev(rasd, dev); - s = _resource_dynamic(dominfo, dev, true); + s = _resource_dynamic(dominfo, dev, RESOURCE_ADD); if (s.rc != CMPI_RC_OK) goto out; @@ -755,7 +773,7 @@ static CMPIStatus resource_mod(struct do if (STREQ(dev->id, devid)) { rasd_to_vdev(rasd, dev); - CMSetStatus(&s, CMPI_RC_OK); + s = _resource_dynamic(dominfo, dev, RESOURCE_MOD); break; } }

Dan Smith wrote:
This set adds dynamic memory ballooning when a client does a ModifyResourceSettings on the Memory RASD.
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
Good set of changes. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert@us.ibm.com
participants (2)
-
Dan Smith
-
Kaitlin Rupert