summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Lopez Garcia <aloga@ifca.unican.es>2012-05-10 10:30:29 +0200
committerMark McLoughlin <markmc@redhat.com>2012-06-01 11:40:31 +0100
commit84a43e140568c4806c5962b273297439db2a5199 (patch)
tree3097a7b0878dd71539e0c90390bfec48e01bb45a
parent4aea7f1e31faceb3449372e81fce1a1b8bc64863 (diff)
downloadnova-84a43e140568c4806c5962b273297439db2a5199.tar.gz
Report memory correctly on Xen. Fixes bug 997014
/proc/meminfo may show wrong values for the memory when using Xen, so this correctly computes the memory by querying libvirt. Change-Id: I188e2d34bcee13954653b93b9b816cf4530b8859
-rw-r--r--nova/virt/libvirt/connection.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py
index 31e6511e29..77e15bc501 100644
--- a/nova/virt/libvirt/connection.py
+++ b/nova/virt/libvirt/connection.py
@@ -1707,10 +1707,15 @@ class LibvirtConnection(driver.ComputeDriver):
if sys.platform.upper() not in ['LINUX2', 'LINUX3']:
return 0
- meminfo = open('/proc/meminfo').read().split()
- idx = meminfo.index('MemTotal:')
- # transforming kb to mb.
- return int(meminfo[idx + 1]) / 1024
+ if FLAGS.libvirt_type == 'xen':
+ meminfo = self._conn.getInfo()[1]
+ # this is in MB
+ return meminfo
+ else:
+ meminfo = open('/proc/meminfo').read().split()
+ idx = meminfo.index('MemTotal:')
+ # transforming KB to MB
+ return int(meminfo[idx + 1]) / 1024
@staticmethod
def get_local_gb_total():
@@ -1759,8 +1764,26 @@ class LibvirtConnection(driver.ComputeDriver):
idx1 = m.index('MemFree:')
idx2 = m.index('Buffers:')
idx3 = m.index('Cached:')
- avail = (int(m[idx1 + 1]) + int(m[idx2 + 1]) + int(m[idx3 + 1])) / 1024
- return self.get_memory_mb_total() - avail
+ if FLAGS.libvirt_type == 'xen':
+ used = 0
+ for domain_id in self._conn.listDomainsID():
+ # skip dom0
+ dom_mem = int(self._conn.lookupByID(domain_id).info()[2])
+ if domain_id != 0:
+ used += dom_mem
+ else:
+ # the mem reported by dom0 is be greater of what
+ # it is being used
+ used += (dom_mem -
+ (int(m[idx1 + 1]) +
+ int(m[idx2 + 1]) +
+ int(m[idx3 + 1])))
+ # Convert it to MB
+ return used / 1024
+ else:
+ avail = (int(m[idx1 + 1]) + int(m[idx2 + 1]) + int(m[idx3 + 1]))
+ # Convert it to MB
+ return self.get_memory_mb_total() - avail / 1024
def get_local_gb_used(self):
"""Get the free hdd size(GB) of physical computer.