From 2ffc9907f7b0d371737e39b7649f7af23026f5cf Mon Sep 17 00:00:00 2001 From: Wido den Hollander Date: Wed, 1 Aug 2012 17:18:11 +0200 Subject: [PATCH] kvm: Use libvirt for polling storage pool capacity and allocation Since we are using libvirt for handling our storage pools we should rely on that information as well. Before fetching the capacity we refresh the pool so libvirt has the most up-to-date information. This is not needed with newly created pools since libvirt does a refresh on creation. --- .../kvm/storage/LibvirtStorageAdaptor.java | 37 +++---------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java index 90003f9cc2b..4efffd6caad 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java @@ -446,25 +446,6 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { return pool; } - private void getStats(LibvirtStoragePool pool) { - Script statsScript = new Script("/bin/bash", s_logger); - statsScript.add("-c"); - statsScript.add("stats=$(df --total " + pool.getLocalPath() - + " |grep total|awk '{print $2,$3}');echo $stats"); - final OutputInterpreter.OneLineParser statsParser = new OutputInterpreter.OneLineParser(); - String result = statsScript.execute(statsParser); - if (result == null) { - String stats = statsParser.getLine(); - if (stats != null && !stats.isEmpty()) { - String sizes[] = stats.trim().split(" "); - if (sizes.length == 2) { - pool.setCapacity(Long.parseLong(sizes[0]) * 1024); - pool.setUsed(Long.parseLong(sizes[1]) * 1024); - } - } - } - } - @Override public KVMStoragePool getStoragePool(String uuid) { StoragePool storage = null; @@ -503,12 +484,9 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } } - if (pool.getType() == StoragePoolType.RBD) { - pool.setCapacity(storage.getInfo().capacity); - pool.setUsed(storage.getInfo().allocation); - } else { - getStats(pool); - } + pool.refresh(); + pool.setCapacity(storage.getInfo().capacity); + pool.setUsed(storage.getInfo().allocation); return pool; } catch (LibvirtException e) { @@ -593,12 +571,9 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { pool.setLocalPath(""); } - if (pool.getType() == StoragePoolType.RBD) { - pool.setCapacity(sp.getInfo().capacity); - pool.setUsed(sp.getInfo().allocation); - } else { - getStats(pool); - } + pool.setCapacity(sp.getInfo().capacity); + pool.setUsed(sp.getInfo().allocation); + return pool; } catch (LibvirtException e) { throw new CloudRuntimeException(e.toString());