summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlvaro Lopez Garcia <aloga@ifca.unican.es>2012-05-10 10:30:29 +0200
committerAlvaro Lopez Garcia <aloga@ifca.unican.es>2012-05-10 18:00:31 +0200
commit5b93a576583d8830fd6636df73d65349017bb617 (patch)
treeb87141366abfa76bf39e5b3304909a0bb20d8c69
parent1d53273d67f38a096ee334a46d5cae2b3f0b4bd2 (diff)
Report memory correctly on Xen. Fixes bug 997014
/proc/meminfo may show wrong values for the memory when using Xen, so this fix computes the memory quering libivrt. 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 5ceca9f48..e60cda0cd 100644
--- a/nova/virt/libvirt/connection.py
+++ b/nova/virt/libvirt/connection.py
@@ -1859,10 +1859,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():
@@ -1911,8 +1916,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.