cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chipchild...@apache.org
Subject git commit: refs/heads/4.0 - CLOUDSTACK-1648 - KVM - make storage pools non-persistent in libvirt. Persisting cloud-defined resources on the host has caused various problems. As a backward compatible fix, if an existing pool with a different name collide
Date Thu, 14 Mar 2013 19:36:43 GMT
Updated Branches:
  refs/heads/4.0 43631f9f4 -> 8a50bac8a


CLOUDSTACK-1648 - KVM - make storage pools non-persistent in libvirt. Persisting
cloud-defined resources on the host has caused various problems. As a backward
compatible fix, if an existing pool with a different name collides with a pool
being created (by path), the pool will be redefined with the name cloudstack
knows about. This is actually what brought up the bug, a persisted storage pool
cloudstack wasn't managing.

Signed-off-by: Marcus Sorensen <marcus@betterservers.com> 1363210149 -0600


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/8a50bac8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/8a50bac8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/8a50bac8

Branch: refs/heads/4.0
Commit: 8a50bac8a9958311f30de574d7d26c163f06c707
Parents: 43631f9
Author: Marcus Sorensen <marcus@betterservers.com>
Authored: Wed Mar 13 15:29:09 2013 -0600
Committer: Chip Childers <chip.childers@gmail.com>
Committed: Thu Mar 14 15:36:07 2013 -0400

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java     |    2 +-
 .../kvm/storage/LibvirtStorageAdaptor.java         |  109 ++++++++++++---
 2 files changed, 91 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8a50bac8/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index b8cce1e..4729fd6 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -3283,7 +3283,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
             sscmd.setDataCenter(_dcId);
             sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
         } catch (CloudRuntimeException e) {
-
+            s_logger.debug("Unable to initialize local storage pool: " + e);
         }
 
         if (sscmd != null) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8a50bac8/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
----------------------------------------------------------------------
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 6c55743..d065e90 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
@@ -120,14 +120,18 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
         StoragePool sp = null;
         try {
             s_logger.debug(spd.toString());
-            sp = conn.storagePoolDefineXML(spd.toString(), 0);
-            sp.create(0);
+            sp = conn.storagePoolCreateXML(spd.toString(), 0);
             return sp;
         } catch (LibvirtException e) {
             s_logger.error(e.toString());
             if (sp != null) {
                 try {
-                    sp.undefine();
+                    if (sp.isPersistent() == 1) {
+                        sp.destroy();
+                        sp.undefine();
+                    } else {
+                        sp.destroy();
+                    }
                     sp.free();
                 } catch (LibvirtException l) {
                     s_logger.debug("Failed to define nfs storage pool with: "
@@ -150,15 +154,18 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
         StoragePool sp = null;
         try {
             s_logger.debug(spd.toString());
-            sp = conn.storagePoolDefineXML(spd.toString(), 0);
-            sp.create(0);
-
+            sp = conn.storagePoolCreateXML(spd.toString(), 0);
             return sp;
         } catch (LibvirtException e) {
             s_logger.error(e.toString());
             if (sp != null) {
                 try {
-                    sp.undefine();
+                    if (sp.isPersistent() == 1) {
+                        sp.destroy();
+                        sp.undefine();
+                    } else {
+                        sp.destroy();
+                    }
                     sp.free();
                 } catch (LibvirtException l) {
                     s_logger.debug("Failed to define shared mount point storage pool with:
"
@@ -181,14 +188,18 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
         StoragePool sp = null;
         try {
             s_logger.debug(spd.toString());
-            sp = conn.storagePoolDefineXML(spd.toString(), 0);
-            sp.create(0);
+            sp = conn.storagePoolCreateXML(spd.toString(), 0);
             return sp;
         } catch (LibvirtException e) {
             s_logger.error(e.toString());
             if (sp != null) {
                 try {
-                    sp.undefine();
+                    if (sp.isPersistent() == 1) {
+                        sp.destroy();
+                        sp.undefine();
+                    } else {
+                        sp.destroy();
+                    }
                     sp.free();
                 } catch (LibvirtException l) {
                     s_logger.debug("Failed to define clvm storage pool with: "
@@ -236,14 +247,18 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
 
         try {
             s_logger.debug(spd.toString());
-            sp = conn.storagePoolDefineXML(spd.toString(), 0);
-            sp.create(0);
+            sp = conn.storagePoolCreateXML(spd.toString(), 0);
             return sp;
         } catch (LibvirtException e) {
             s_logger.debug(e.toString());
             if (sp != null) {
                 try {
-                    sp.undefine();
+                    if (sp.isPersistent() == 1) {
+                        sp.destroy();
+                        sp.undefine();
+                    } else {
+                        sp.destroy();
+                    }
                     sp.free();
                 } catch (LibvirtException l) {
                     s_logger.debug("Failed to define RBD storage pool with: " + l.toString());
@@ -437,15 +452,59 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
 
         try {
             sp = conn.storagePoolLookupByUUIDString(name);
-            if (sp.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
+            if (sp != null && sp.isActive() == 0) {
                 sp.undefine();
                 sp = null;
+                s_logger.debug("Found existing defined storage pool " + name + ". It wasn't
running, so we undefined it.");
+            }
+            if (sp != null) {
+                s_logger.debug("Found existing defined storage pool " + name + ", using it.");
             }
         } catch (LibvirtException e) {
+            sp = null;
+            s_logger.debug("createStoragePool didn't find existing running pool: " + e +
", need to create it");
+        }
 
+        // libvirt strips trailing slashes off of path, we will too in order to match
+        // existing paths
+        if (path.endsWith("/")) {
+            path = path.substring(0, path.length() - 1);
         }
 
         if (sp == null) {
+            // see if any existing pool by another name is using our storage path.
+            // if anyone is, undefine the pool so we can define it as requested.
+            // This should be safe since a pool in use can't be removed, and no
+            // volumes are affected by unregistering the pool with libvirt.
+            s_logger.debug("Didn't find an existing storage pool " + name 
+                            + " by UUID, checking for pools with duplicate paths");
+
+            try {
+                String[] poolnames = conn.listStoragePools();
+                for (String poolname : poolnames) {
+                    s_logger.debug("Checking path of existing pool " + poolname 
+                                    + " against pool we want to create");
+                    StoragePool p = conn.storagePoolLookupByName(poolname);
+                    LibvirtStoragePoolDef pdef = getStoragePoolDef(conn, p);
+
+                    if (pdef.getTargetPath().equals(path)) {
+                        s_logger.debug("Storage pool utilizing path '" + path + "' already
exists as pool "
+                                       + poolname + ", undefining so we can re-define with
correct name " + name);
+                        if (p.isPersistent() == 1) {
+                            p.destroy();
+                            p.undefine();
+                        } else {
+                            p.destroy();
+                        }
+                    }
+                }
+            } catch (LibvirtException e) {
+                s_logger.error("Failure in attempting to see if an existing storage pool
might " 
+                               + "be using the path of the pool to be created:" + e);
+            }
+
+            s_logger.debug("Attempting to create storage pool " + name);
+
             if (type == StoragePoolType.NetworkFilesystem) {
                 sp = createNfsStoragePool(conn, name, host, path);
             } else if (type == StoragePoolType.SharedMountPoint
@@ -459,8 +518,8 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
         }
 
         try {
-            StoragePoolInfo spi = sp.getInfo();
-            if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
+            if (sp.isActive() == 0) {
+                s_logger.debug("attempting to activate pool " + name);
                 sp.create(0);
             }
 
@@ -479,7 +538,15 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
   
             return pool;
         } catch (LibvirtException e) {
-            throw new CloudRuntimeException(e.toString());
+            String error = e.toString();
+            if (error.contains("Storage source conflict")) {
+                throw new CloudRuntimeException("A pool matching this location already exists
in libvirt, "
+                                  + " but has a different UUID/Name. Cannot create new pool
without first " 
+                                  + " removing it. Check for inactive pools via 'virsh pool-list
--all'. " 
+                                  + error);
+            } else {
+                throw new CloudRuntimeException(error);
+            }
         }
     }
 
@@ -511,8 +578,12 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
         }
 
         try {
-            sp.destroy();
-            sp.undefine();
+            if (sp.isPersistent() == 1) {
+                sp.destroy();
+                sp.undefine();
+            } else {
+                sp.destroy();
+            }
             sp.free();
             if (s != null) {
                 s.undefine();


Mime
View raw message