On Fri, 20 Apr 2007 14:31:02 +0100 "Daniel P. Berrange" wrote: > > > If we ignore case B, I think we still have lots of interesting > > > combos to think about: > > > > > > 1. Static - change persistent config > > > 2. Dynamic - change live VM config > > > 3. Static and Dynamic - change persistent config, and live VM > > > 4. Static or Dynamic - if domain is inactive, change persistent > > > config, if it is active, change live VM > > > > > This is already possible today actually. In Xen 3.0.4 or later there is the > lifecycle management APIs, so there is an API which lets you define a config > for a guest. So in this case we just convert from XML -> SEXPR, in the same > way that we do to boot a guest. For older Xen, we simply write files straight > into /etc/xen. The QEMUD daemon stores the XML files for QEMU/KVM in the > native libvirt format, so that's easy. So it will be possible following way using new API right ? new API: virDomainSetMemoryScope(virDomainPtr dom, int mem, int scope); > virsh setmem foo 500 -> VIR_DOMAIN_SCOPE_CURRENT(4) > virsh --static setmem foo 500 -> VIR_DOMAIN_SCOPE_STATIC(1) > virsh --dynamic setmem foo 500 -> VIR_DOMAIN_SCOPE_DYNAMIC(2) > virsh --static --dynamic setmem foo 500 -> VIR_DOMAIN_SCOPE_BOTH(3) When scope is VIR_DOMAIN_SCOPE_CURRENT, execute current handling. When scope is other, execute as follows: 1. get the config using domainDumpXML 2. change the value of memory -> When scope is VIR_DOMAIN_SCOPE_STATIC or VIR_DOMAIN_SCOPE_BOTH: - change the value of currentMemory on the config -> When scope is VIR_DOMAIN_SCOPE_DYNAMIC or VIR_DOMAIN_SCOPE_BOTH: - change the actual memory allocation using domainSetMemory 3. define the config using domainDefineXML Here is example. (NOTE: not compiled or tested. need error handling) Index: virsh.c =================================================================== RCS file: /data/cvs/libvirt/src/virsh.c,v retrieving revision 1.73 diff -u -p -r1.73 virsh.c --- virsh.c 13 Apr 2007 08:04:08 -0000 1.73 +++ virsh.c 23 Apr 2007 08:55:55 -0000 @@ -1461,6 +1461,9 @@ cmdSetmem(vshControl * ctl, vshCmd * cmd virDomainPtr dom; int kilobytes; int ret = TRUE; + int op_static = vshCommandOptBool(cmd, "static"); + int op_dynamic = vshCommandOptBool(cmd, "dynamic"); + int flag = VIR_DOMAIN_SCOPE_CURRENT; if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) return FALSE; @@ -1475,7 +1478,14 @@ cmdSetmem(vshControl * ctl, vshCmd * cmd return FALSE; } - if (virDomainSetMemory(dom, kilobytes) != 0) { + if (op_static && op_dynamic) { + flag = VIR_DOMAIN_SCOPE_BOTH; + } else if (op_static) { + flag = VIR_DOMAIN_SCOPE_STATIC; + } else if (op_static) { + flag = VIR_DOMAIN_SCOPE_DYNAMIC; + } + if (virDomainSetMemoryScope(dom, kilobytes, flag) !=0) { ret = FALSE; } Index: libvirt.c =================================================================== RCS file: /data/cvs/libvirt/src/libvirt.c,v retrieving revision 1.68 diff -u -p -r1.68 libvirt.c --- libvirt.c 18 Apr 2007 10:14:07 -0000 1.68 +++ libvirt.c 23 Apr 2007 08:56:14 -0000 @@ -1304,6 +1304,55 @@ virDomainSetMemory(virDomainPtr domain, return -1; } +int +virDomainSetMemoryScope(virDomainPtr domain, unsigned long memory, int scope) +{ + virConnectPtr conn; + char *dump; + virDomainPtr dom; + + if (domain == NULL) { + TODO + return (-1); + } + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + return (-1); + } + if (domain->conn->flags & VIR_CONNECT_RO) { + virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__); + return (-1); + } + if (memory < 4096) { + virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__); + return (-1); + } + + conn = domain->conn; + + if (scope == VIR_DOMAIN_SCOPE_CURRENT){ + if (conn->driver->domainSetMemory) + return conn->driver->domainSetMemory (domain, memory); + } else { + if (conn->driver->domainDumpXML) + dump = conn->driver->domainDumpXML (domain, 0); + switch (scope) { + case VIR_DOMAIN_SCOPE_STATIC: + /* change the value of currentMemory */ + case VIR_DOMAIN_SCOPE_DYNAMIC: + /* change the actual memory allocation using domainSetMemory */ + case VIR_DOMAIN_SCOPE_BOTH: + /* change the value of currentMemory */ + } + if (conn->driver->domainDefineXML) + dom = conn->driver->domainDefineXML (conn, dump); + } + + virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__); + return -1; +} Thanks, Saori Fukuta.