Updated Branches: refs/heads/4.1 04f8965c2 -> 2c019cc64
CLOUDSTACK-2051 Allow KVM HA Monitor to verify that a NfsStoragePool is valid before running the script that mounts it and touches the HA files. Signed-off-by: Marcus Sorensen <mar...@betterservers.com> 1366135635 -0600 Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d1d00d54 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d1d00d54 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d1d00d54 Branch: refs/heads/4.1 Commit: d1d00d54a13fa41bf7447bea7cf0294e2b0d8eb1 Parents: 04f8965 Author: Marcus Sorensen <mar...@betterservers.com> Authored: Tue Apr 16 12:07:15 2013 -0600 Committer: Chip Childers <chip.child...@gmail.com> Committed: Wed Apr 17 01:28:17 2013 +0100 ---------------------------------------------------------------------- .../hypervisor/kvm/resource/KVMHAMonitor.java | 51 ++++++++++++++- 1 files changed, 50 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d1d00d54/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java index c4e121b..d1470d6 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java @@ -23,6 +23,15 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.log4j.Logger; import com.cloud.utils.script.Script; +import org.libvirt.Connect; +import org.libvirt.LibvirtException; +import org.libvirt.Secret; +import org.libvirt.StoragePool; +import org.libvirt.StoragePoolInfo; +import org.libvirt.StoragePoolInfo.StoragePoolState; + +import com.cloud.hypervisor.kvm.resource.LibvirtConnection; + public class KVMHAMonitor extends KVMHABase implements Runnable { private static final Logger s_logger = Logger.getLogger(KVMHAMonitor.class); private Map<String, NfsStoragePool> _storagePool = new ConcurrentHashMap<String, NfsStoragePool>(); @@ -45,6 +54,9 @@ public class KVMHAMonitor extends KVMHABase implements Runnable { public void removeStoragePool(String uuid) { synchronized (_storagePool) { + NfsStoragePool pool = this._storagePool.get(uuid); + Script.runSimpleBashScript("umount " + pool._mountDestPath); + s_logger.debug("attempted to umount '" + pool._mountDestPath + "'"); this._storagePool.remove(uuid); } } @@ -60,7 +72,44 @@ public class KVMHAMonitor extends KVMHABase implements Runnable { @Override public void run() { synchronized (_storagePool) { - for (NfsStoragePool primaryStoragePool : _storagePool.values()) { + for (String uuid : _storagePool.keySet()) { + NfsStoragePool primaryStoragePool = _storagePool.get(uuid); + + // check for any that have been deregistered with libvirt and + // skip,remove them + + StoragePool storage = null; + try { + Connect conn = LibvirtConnection.getConnection(); + storage = conn.storagePoolLookupByUUIDString(uuid); + if (storage == null) { + s_logger.debug("Libvirt storage pool " + uuid + +" not found, removing from HA list"); + removeStoragePool(uuid); + continue; + + } else if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) { + s_logger.debug("Libvirt storage pool " + uuid + +" found, but not running, removing from HA list"); + + removeStoragePool(uuid); + continue; + } + s_logger.debug("Found NFS storage pool " + uuid + " in libvirt, continuing"); + + } catch (LibvirtException e) { + s_logger.debug("Failed to lookup libvirt storage pool " + uuid + + " due to: " + e ); + + // we only want to remove pool if it's not found, not if libvirt + // connection fails + if (e.toString().contains("pool not found")) { + s_logger.debug("removing pool from HA monitor since it was deleted"); + removeStoragePool(uuid); + continue; + } + } + String result = null; for (int i = 0; i < 5; i++) { Script cmd = new Script(_heartBeatPath,