[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 1/5] setmem: introduce a new libvirt API (virDomainSetMemoryFlags)



This patch introduces a new libvirt API (virDomainSetMemoryFlags) and
a flag (virDomainMemoryModFlags).

Signed-off-by: Taku Izumi <izumi taku jp fujitsu com>
---
 include/libvirt/libvirt.h.in |   10 ++++++
 src/libvirt.c                |   62 +++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |    5 +++
 3 files changed, 77 insertions(+)

Index: libvirt-git/include/libvirt/libvirt.h.in
===================================================================
--- libvirt-git.orig/include/libvirt/libvirt.h.in
+++ libvirt-git/include/libvirt/libvirt.h.in
@@ -780,6 +780,13 @@ int     virDomainGetMemoryParameters(vir
                                      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                     virDomainSetMaxM
                                                  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: libvirt-git/src/libvirt_public.syms
===================================================================
--- libvirt-git.orig/src/libvirt_public.syms
+++ libvirt-git/src/libvirt_public.syms
@@ -424,4 +424,9 @@ LIBVIRT_0.8.8 {
         virConnectGetSysinfo;
 } LIBVIRT_0.8.6;

+LIBVIRT_0.8.9 {
+    global:
+        virDomainSetMemoryFlags;
+} LIBVIRT_0.8.8;
+
 # .... define new API here using predicted next version number ....
Index: libvirt-git/src/libvirt.c
===================================================================
--- libvirt-git.orig/src/libvirt.c
+++ libvirt-git/src/libvirt.c
@@ -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 virDomainMemoryFlags
+ *
+ * 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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]