You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ml...@apache.org on 2014/03/04 22:27:50 UTC

[15/17] git commit: updated refs/heads/resize-root to caf9de6

kvm: Fix a NullPointerException which occurs when storage pool creation fails

Also make the logging around creating a RBD storage pool a bit better when creating
that fails.


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

Branch: refs/heads/resize-root
Commit: 1f9649bc3beee63e877c14e6d76107b4d75a92a1
Parents: 8dca59d
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Tue Mar 4 16:03:11 2014 +0100
Committer: Wido den Hollander <wi...@widodh.nl>
Committed: Tue Mar 4 16:03:11 2014 +0100

----------------------------------------------------------------------
 .../kvm/storage/LibvirtStorageAdaptor.java      | 27 +++++++++++++++-----
 1 file changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1f9649bc/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 4a8f1f1..38ce32b 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
@@ -244,13 +244,12 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
 
         LibvirtStoragePoolDef spd;
         StoragePool sp = null;
+        Secret s = null;
 
         String[] userInfoTemp = userInfo.split(":");
         if (userInfoTemp.length == 2) {
             LibvirtSecretDef sd = new LibvirtSecretDef(usage.CEPH, uuid);
 
-            Secret s = null;
-
             sd.setCephName(userInfoTemp[0] + "@" + host + ":" + port + "/" + path);
 
             try {
@@ -258,15 +257,16 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
                 s = conn.secretDefineXML(sd.toString());
                 s.setValue(Base64.decodeBase64(userInfoTemp[1]));
             } catch (LibvirtException e) {
-                s_logger.error(e.toString());
+                s_logger.error("Failed to define the libvirt secret: " + e.toString());
                 if (s != null) {
                     try {
                         s.undefine();
                         s.free();
                     } catch (LibvirtException l) {
-                        s_logger.debug("Failed to define secret with: " + l.toString());
+                        s_logger.debug("Failed to undefine the libvirt secret: " + l.toString());
                     }
                 }
+                return null;
             }
             spd = new LibvirtStoragePoolDef(poolType.RBD, uuid, uuid, host, port, path, userInfoTemp[0], authType.CEPH, uuid);
         } else {
@@ -278,7 +278,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
             sp = conn.storagePoolCreateXML(spd.toString(), 0);
             return sp;
         } catch (LibvirtException e) {
-            s_logger.debug(e.toString());
+            s_logger.debug("Failed to create RBD storage pool: " + e.toString());
             if (sp != null) {
                 try {
                     if (sp.isPersistent() == 1) {
@@ -289,9 +289,20 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
                     }
                     sp.free();
                 } catch (LibvirtException l) {
-                    s_logger.debug("Failed to define RBD storage pool with: " + l.toString());
+                    s_logger.debug("Failed to undefine RBD storage pool: " + l.toString());
                 }
             }
+
+            if (s != null) {
+                try {
+                    s_logger.debug("Failed to create the RBD storage pool, cleaning up the libvirt secret");
+                    s.undefine();
+                    s.free();
+                } catch (LibvirtException se) {
+                    s_logger.debug("Failed to remove the libvirt secret: " + se.toString());
+                }
+            }
+
             return null;
         }
     }
@@ -512,6 +523,10 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
             }
         }
 
+        if (sp == null) {
+            throw new CloudRuntimeException("Failed to create storage pool: " + name);
+        }
+
         try {
             if (sp.isActive() == 0) {
                 s_logger.debug("attempting to activate pool " + name);