]> xenbits.xensource.com Git - libvirt.git/commitdiff
setmem: introduce a new libvirt API (virDomainSetMemoryFlags)
authorTaku Izumi <izumi.taku@jp.fujitsu.com>
Wed, 2 Mar 2011 08:07:48 +0000 (17:07 +0900)
committerEric Blake <eblake@redhat.com>
Thu, 10 Mar 2011 22:02:58 +0000 (15:02 -0700)
This patch introduces a new libvirt API (virDomainSetMemoryFlags) and
a flag (virDomainMemoryModFlags).

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
18 files changed:
AUTHORS
include/libvirt/libvirt.h.in
src/driver.h
src/esx/esx_driver.c
src/libvirt.c
src/libvirt_public.syms
src/lxc/lxc_driver.c
src/opennebula/one_driver.c
src/openvz/openvz_driver.c
src/phyp/phyp_driver.c
src/qemu/qemu_driver.c
src/remote/remote_driver.c
src/test/test_driver.c
src/uml/uml_driver.c
src/vbox/vbox_tmpl.c
src/vmware/vmware_driver.c
src/xen/xen_driver.c
src/xenapi/xenapi_driver.c

diff --git a/AUTHORS b/AUTHORS
index f2292074e3b7b311d31186c2d5bb364a499bdd18..c0c1780a099ba9ddbd20b1d3eaaa272dc9f42640 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -157,6 +157,7 @@ Patches have also been contributed by:
   Christophe Fergeau   <teuf@gnome.org>
   Markus Groß          <gross@univention.de>
   Phil Petty           <phpetty@cisco.com>
+  Taku Izumi           <izumi.taku@jp.fujitsu.com>
 
   [....send patches to get your name here....]
 
index 618b350c35d6d2b072dc01d46b34e101d6dcce5f..10f896604566b3f72583d560929b45c4bb0b4ced 100644 (file)
@@ -780,6 +780,13 @@ int     virDomainGetMemoryParameters(virDomainPtr domain,
                                      virMemoryParameterPtr params,
                                      int *nparams, unsigned int flags);
 
+/* Memory size modification flags. */
+typedef enum {
+    VIR_DOMAIN_MEM_LIVE   = (1 << 0), /* affect active domain */
+    VIR_DOMAIN_MEM_CONFIG = (1 << 1), /* affect next boot */
+} virDomainMemoryModFlags;
+
+
 /*
  * Dynamic control of domains
  */
@@ -795,6 +802,9 @@ int                     virDomainSetMaxMemory   (virDomainPtr domain,
                                                  unsigned long memory);
 int                     virDomainSetMemory      (virDomainPtr domain,
                                                  unsigned long memory);
+int                     virDomainSetMemoryFlags (virDomainPtr domain,
+                                                 unsigned long memory,
+                                                 unsigned int flags);
 int                     virDomainGetMaxVcpus    (virDomainPtr domain);
 int                     virDomainGetSecurityLabel (virDomainPtr domain,
                                                    virSecurityLabelPtr seclabel);
index c65a4b99469790d69bd56d89c79888bab3573808..da792d004014c8be0b2d127851772c8ca6ed1573 100644 (file)
@@ -133,6 +133,10 @@ typedef int
 typedef int
         (*virDrvDomainSetMemory)       (virDomainPtr domain,
                                          unsigned long memory);
+typedef int
+        (*virDrvDomainSetMemoryFlags)  (virDomainPtr domain,
+                                         unsigned long memory,
+                                         unsigned int flags);
 typedef int
         (*virDrvDomainSetMemoryParameters)
                                         (virDomainPtr domain,
@@ -536,6 +540,7 @@ struct _virDriver {
     virDrvDomainGetMaxMemory   domainGetMaxMemory;
     virDrvDomainSetMaxMemory   domainSetMaxMemory;
     virDrvDomainSetMemory              domainSetMemory;
+    virDrvDomainSetMemoryFlags  domainSetMemoryFlags;
     virDrvDomainGetInfo                domainGetInfo;
     virDrvDomainSave           domainSave;
     virDrvDomainRestore                domainRestore;
index 13374b75e4ba30b41e5de60434883f00a00d26e4..37e104e902fba04496a27da19e6a958322f999c1 100644 (file)
@@ -4593,6 +4593,7 @@ static virDriver esxDriver = {
     esxDomainGetMaxMemory,           /* domainGetMaxMemory */
     esxDomainSetMaxMemory,           /* domainSetMaxMemory */
     esxDomainSetMemory,              /* domainSetMemory */
+    NULL,                            /* domainSetMemoryFlags */
     esxDomainGetInfo,                /* domainGetInfo */
     NULL,                            /* domainSave */
     NULL,                            /* domainRestore */
index e4b451e3b30747e534740e1c87ecc53491a51bec..1b3b884b215bd63fccbb809582c3ada4e407acf8 100644 (file)
@@ -2846,6 +2846,68 @@ error:
     return -1;
 }
 
+/*
+ * virDomainSetMemoryFlags
+ * @domain: a domain object or NULL
+ * @memory: the memory size in kilobytes
+ * @flags: an OR'ed set of virDomainMemoryModFlags
+ *
+ * Dynamically change the target 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 funcation may 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, -1 in case of failure.
+ */
+
+int
+virDomainSetMemoryFlags(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;
+    }
+
+    conn = domain->conn;
+
+    if (conn->driver->domainSetMemoryFlags) {
+        int ret;
+        ret = conn->driver->domainSetMemoryFlags(domain, memory, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+
 /**
  * virDomainSetMemoryParameters:
  * @domain: pointer to domain object
index cca8d085e763e485e68119b436fda7b70ae8ca15..cfbd8dfe2991c237d2a71a293cebf7a97a45cb04 100644 (file)
@@ -426,6 +426,7 @@ LIBVIRT_0.8.8 {
 
 LIBVIRT_0.9.0 {
     global:
+        virDomainSetMemoryFlags;
         virEventRegisterDefaultImpl;
         virEventRunDefaultImpl;
 } LIBVIRT_0.8.8;
index 5b6f78471060ec437ccf03a5cd92b1cfb7df61f5..4ddeffd50e27e0dd900dda0fd9ccd4ee1c2dfbff 100644 (file)
@@ -2851,6 +2851,7 @@ static virDriver lxcDriver = {
     lxcDomainGetMaxMemory, /* domainGetMaxMemory */
     lxcDomainSetMaxMemory, /* domainSetMaxMemory */
     lxcDomainSetMemory, /* domainSetMemory */
+    NULL, /* domainSetMemoryFlags */
     lxcDomainGetInfo, /* domainGetInfo */
     NULL, /* domainSave */
     NULL, /* domainRestore */
index a0654e245a980e8268663b64889a282856b11a0f..163d0081496d6f5e0e30e4df9795b3a74e49e1ab 100644 (file)
@@ -750,6 +750,7 @@ static virDriver oneDriver = {
     NULL, /* domainGetMaxMemory */
     NULL, /* domainSetMaxMemory */
     NULL, /* domainSetMemory */
+    NULL, /* domainSetMemoryFlags */
     oneDomainGetInfo, /* domainGetInfo */
     NULL, /* domainSave */
     NULL, /* domainRestore */
index 9ee6de517f1b3574b5b96658db5e002733d14606..7119bde62096f18d9f543a76ef327f3f12da4e9f 100644 (file)
@@ -1571,6 +1571,7 @@ static virDriver openvzDriver = {
     NULL, /* domainGetMaxMemory */
     NULL, /* domainSetMaxMemory */
     NULL, /* domainSetMemory */
+    NULL, /* domainSetMemoryFlags */
     openvzDomainGetInfo, /* domainGetInfo */
     NULL, /* domainSave */
     NULL, /* domainRestore */
index d954f2a9645e1e33de31b4d8e2a2c8242da434b7..84323a7e0b9195d7b1ef7856e7fa7f8501edb57e 100644 (file)
@@ -3973,6 +3973,7 @@ static virDriver phypDriver = {
     NULL,                       /* domainGetMaxMemory */
     NULL,                       /* domainSetMaxMemory */
     NULL,                       /* domainSetMemory */
+    NULL,                       /* domainSetMemoryFlags */
     phypDomainGetInfo,          /* domainGetInfo */
     NULL,                       /* domainSave */
     NULL,                       /* domainRestore */
index 2208b12d37ac7bd88f504f5409eefe607731d07b..2f151445b4f9404aed0e415b62b178ce2cc7ddee 100644 (file)
@@ -6854,6 +6854,7 @@ static virDriver qemuDriver = {
     qemudDomainGetMaxMemory, /* domainGetMaxMemory */
     NULL, /* domainSetMaxMemory */
     qemudDomainSetMemory, /* domainSetMemory */
+    NULL, /* domainSetMemoryFlags */
     qemudDomainGetInfo, /* domainGetInfo */
     qemudDomainSave, /* domainSave */
     qemudDomainRestore, /* domainRestore */
index 58d7f9642b8894d94b081b8eb615b224b7a9f66e..e2e00eb1b98e62b50ac290aa8f63b3b6cde9f1e0 100644 (file)
@@ -10876,6 +10876,7 @@ static virDriver remote_driver = {
     remoteDomainGetMaxMemory, /* domainGetMaxMemory */
     remoteDomainSetMaxMemory, /* domainSetMaxMemory */
     remoteDomainSetMemory, /* domainSetMemory */
+    NULL, /* domainSetMemoryFlags */
     remoteDomainGetInfo, /* domainGetInfo */
     remoteDomainSave, /* domainSave */
     remoteDomainRestore, /* domainRestore */
index b168570298ebf229829f6a4045fa279586649376..438f5a3cb6373a11ca732053e6df9e66225b47a0 100644 (file)
@@ -5365,6 +5365,7 @@ static virDriver testDriver = {
     testGetMaxMemory, /* domainGetMaxMemory */
     testSetMaxMemory, /* domainSetMaxMemory */
     testSetMemory, /* domainSetMemory */
+    NULL, /* domainSetMemoryFlags */
     testGetDomainInfo, /* domainGetInfo */
     testDomainSave, /* domainSave */
     testDomainRestore, /* domainRestore */
index 7cacadbbbdc75b3aaf15dfca17c29637600ae810..671fcc5c86ed2ea950da37d9b1deb501c90e3729 100644 (file)
@@ -2167,6 +2167,7 @@ static virDriver umlDriver = {
     umlDomainGetMaxMemory, /* domainGetMaxMemory */
     umlDomainSetMaxMemory, /* domainSetMaxMemory */
     umlDomainSetMemory, /* domainSetMemory */
+    NULL, /* domainSetMemoryFlags */
     umlDomainGetInfo, /* domainGetInfo */
     NULL, /* domainSave */
     NULL, /* domainRestore */
index 8848cc0933eb0f536b59a9447046916089f4dd49..342ab5ec97fe4f2bcc91668104d37b65f6244a5a 100644 (file)
@@ -8555,6 +8555,7 @@ virDriver NAME(Driver) = {
     NULL, /* domainGetMaxMemory */
     NULL, /* domainSetMaxMemory */
     vboxDomainSetMemory, /* domainSetMemory */
+    NULL, /* domainSetMemoryFlags */
     vboxDomainGetInfo, /* domainGetInfo */
     vboxDomainSave, /* domainSave */
     NULL, /* domainRestore */
index 2b07b13c376885433b486221cd9d9d46b2560b27..064b4cbd0541753cfc93ba95e26d27893c9dad2c 100644 (file)
@@ -925,6 +925,7 @@ static virDriver vmwareDriver = {
     NULL,                       /* domainGetMaxMemory */
     NULL,                       /* domainSetMaxMemory */
     NULL,                       /* domainSetMemory */
+    NULL,                       /* domainSetMemoryFlags */
     vmwareDomainGetInfo,        /* domainGetInfo */
     NULL,                       /* domainSave */
     NULL,                       /* domainRestore */
index 979f9e085f6a6caa2da3e28aa8b331931220459f..a777225204429f92a17c06be166f3b429b1ab23e 100644 (file)
@@ -2034,6 +2034,7 @@ static virDriver xenUnifiedDriver = {
     xenUnifiedDomainGetMaxMemory, /* domainGetMaxMemory */
     xenUnifiedDomainSetMaxMemory, /* domainSetMaxMemory */
     xenUnifiedDomainSetMemory, /* domainSetMemory */
+    NULL, /*domainSetMemoryFlags */
     xenUnifiedDomainGetInfo, /* domainGetInfo */
     xenUnifiedDomainSave, /* domainSave */
     xenUnifiedDomainRestore, /* domainRestore */
index 7851e931d703036fcfd87cdcba6aebc37407479c..91c91cd73eb062ec91062bffe9bb9c01a268a34d 100644 (file)
@@ -1803,6 +1803,7 @@ static virDriver xenapiDriver = {
     xenapiDomainGetMaxMemory, /* domainGetMaxMemory */
     xenapiDomainSetMaxMemory, /* domainSetMaxMemory */
     NULL, /* domainSetMemory */
+    NULL, /* domainSetMemoryFlags */
     xenapiDomainGetInfo, /* domainGetInfo */
     NULL, /* domainSave */
     NULL, /* domainRestore */