On Tue, Sep 04, 2012 at 02:44:48PM +0200, Christophe Fergeau wrote:
libvirt will insert a <currentMemory> node when setting the
domain
maximum memory. If we want to be able to later increase the domain
maximum memory, libvirt-gconfig needs to be able to set this
currentMemory node as well, otherwise this will cap the available
memory in the domain.
---
libvirt-gconfig/libvirt-gconfig-domain.c | 64 +++++++++++++++++++++++++++++++-
libvirt-gconfig/libvirt-gconfig-domain.h | 2 +
libvirt-gconfig/libvirt-gconfig.sym | 6 +++
3 files changed, 71 insertions(+), 1 deletion(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c
b/libvirt-gconfig/libvirt-gconfig-domain.c
index dd4e232..e679e3a 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -43,7 +43,8 @@ enum {
PROP_DESCRIPTION,
PROP_MEMORY,
PROP_VCPU,
- PROP_FEATURES
+ PROP_FEATURES,
+ PROP_CURRENT_MEMORY
};
static void gvir_config_domain_get_property(GObject *object,
@@ -66,6 +67,9 @@ static void gvir_config_domain_get_property(GObject *object,
case PROP_MEMORY:
g_value_set_uint64(value, gvir_config_domain_get_memory(domain));
break;
+ case PROP_CURRENT_MEMORY:
+ g_value_set_uint64(value, gvir_config_domain_get_current_memory(domain));
+ break;
case PROP_VCPU:
g_value_set_uint64(value, gvir_config_domain_get_vcpus(domain));
break;
@@ -98,6 +102,9 @@ static void gvir_config_domain_set_property(GObject *object,
case PROP_MEMORY:
gvir_config_domain_set_memory(domain, g_value_get_uint64(value));
break;
+ case PROP_CURRENT_MEMORY:
+ gvir_config_domain_set_current_memory(domain, g_value_get_uint64(value));
+ break;
case PROP_VCPU:
gvir_config_domain_set_vcpus(domain, g_value_get_uint64(value));
break;
@@ -153,6 +160,15 @@ static void gvir_config_domain_class_init(GVirConfigDomainClass
*klass)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property(object_class,
+ PROP_CURRENT_MEMORY,
+ g_param_spec_uint64("current-memory",
+ "Current memory",
+ "Current Guest Memory (in
kilobytes)",
+ 0, G_MAXUINT64,
+ 0,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property(object_class,
PROP_VCPU,
g_param_spec_uint64("vcpu",
"Virtual CPUs",
@@ -361,6 +377,27 @@ guint64 gvir_config_domain_get_memory(GVirConfigDomain *domain)
}
/**
+ * gvir_config_domain_get_current_memory:
+ * @domain: a #GVirConfigDomain
+ *
+ * Returns: current amount of RAM in kilobytes (i.e. blocks of 1024 bytes).
+ */
+guint64 gvir_config_domain_get_current_memory(GVirConfigDomain *domain)
+{
+ const char *unit;
+ guint64 unit_base;
+ guint64 memory;
+
+ unit = gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(domain),
"currentMemory", "unit");
+ unit_base = get_unit_base(unit, 1024);
+
+ memory = gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(domain),
+ "currentMemory");
+
+ return memory * unit_base / 1024;
+}
+
+/**
* gvir_config_domain_set_memory:
* @domain: a #GVirConfigDomain
* @memory: The maximum amount of RAM in kilobytes.
@@ -380,6 +417,31 @@ void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64
memory)
g_object_notify(G_OBJECT(domain), "memory");
}
+/**
+ * gvir_config_domain_set_current_memory:
+ * @domain: a #GVirConfigDomain
+ * @memory: The current amount of RAM in kilobytes.
+ *
+ * Sets the current amount of RAM allocated to @domain in kilobytes (i.e.
+ * blocks of 1024 bytes). This can be set to less than the maximum domain
+ * memory to allow to balloon the guest memory on the fly. Be aware that
+ * libvirt will set it automatically if it's not explictly set, which means
+ * you may need to set this value in addition to 'memory' if you want to
+ * change the available domain memory after creation.
+ */
+void gvir_config_domain_set_current_memory(GVirConfigDomain *domain,
+ guint64 memory)
+{
+ GVirConfigObject *node;
+
+ node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(domain),
"currentMemory");
+ gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(node), NULL, memory);
+ gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(node),
+ "unit", "KiB",
+ NULL);
+ g_object_notify(G_OBJECT(domain), "current-memory");
+}
+
guint64 gvir_config_domain_get_vcpus(GVirConfigDomain *domain)
{
return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(domain),
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h
b/libvirt-gconfig/libvirt-gconfig-domain.h
index b9a0dce..a7bd73b 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain.h
@@ -108,6 +108,8 @@ const char *gvir_config_domain_get_description(GVirConfigDomain
*domain);
void gvir_config_domain_set_description(GVirConfigDomain *domain, const char
*description);
guint64 gvir_config_domain_get_memory(GVirConfigDomain *domain);
void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory);
+guint64 gvir_config_domain_get_current_memory(GVirConfigDomain *domain);
+void gvir_config_domain_set_current_memory(GVirConfigDomain *domain, guint64 memory);
guint64 gvir_config_domain_get_vcpus(GVirConfigDomain *domain);
void gvir_config_domain_set_vcpus(GVirConfigDomain *domain,
guint64 vcpu_count);
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 7507d45..f83eabb 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -460,4 +460,10 @@ LIBVIRT_GCONFIG_0.1.0 {
gvir_config_domain_cpu_feature_set_policy;
} LIBVIRT_GCONFIG_0.0.9;
+LIBVIRT_GCONFIG_0.1.3 {
+ global:
+ gvir_config_domain_get_current_memory;
+ gvir_config_domain_set_current_memory;
+} LIBVIRT_GCONFIG_0.1.0;
+
# .... define new API here using predicted next version number ....
ACK
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|