This is an automated email from the ASF dual-hosted git repository.

rp9 pushed a commit to branch 4.19
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.19 by this push:
     new 21f3fde7b40 libvirtstorageadaptor: better handle failed libvirt 
storagepool destroy (#9390)
21f3fde7b40 is described below

commit 21f3fde7b404f8195b54e622b84c17d33f54639e
Author: Rene Peinthor <rene.peint...@linbit.com>
AuthorDate: Wed Aug 7 09:53:35 2024 +0200

    libvirtstorageadaptor: better handle failed libvirt storagepool destroy 
(#9390)
    
    If the libvirt mount point is still busy and can't be unmounted
    right now, it was waited 5 seconds and an plain unmount was tried,
    without cleaning up the libvirt storagepool.
    This kept libvirt thinking the storagepool
    is active and mounted (which it wasn't).
    
    Now after the plain unmount call, also
    the libvirt storagepool will be destroyed.
---
 .../kvm/storage/LibvirtStorageAdaptor.java         | 56 +++++++++++++++-------
 1 file changed, 39 insertions(+), 17 deletions(-)

diff --git 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
index e26b2c51790..df6c047e7e2 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
@@ -766,26 +766,53 @@ public class LibvirtStorageAdaptor implements 
StorageAdaptor {
         }
     }
 
+    private boolean destroyStoragePool(Connect conn, String uuid) throws 
LibvirtException {
+        StoragePool sp;
+        try {
+            sp = conn.storagePoolLookupByUUIDString(uuid);
+        } catch (LibvirtException exc) {
+            s_logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. 
Assuming it is already removed");
+            s_logger.warn(exc.getStackTrace());
+            return true;
+        }
+
+        if (sp != null) {
+            if (sp.isPersistent() == 1) {
+                sp.destroy();
+                sp.undefine();
+            } else {
+                sp.destroy();
+            }
+            sp.free();
+
+            return true;
+        } else {
+            s_logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. 
Assuming it is already removed");
+            return false;
+        }
+    }
+
+    private boolean destroyStoragePoolHandleException(Connect conn, String 
uuid)
+    {
+        try {
+            return destroyStoragePool(conn, uuid);
+        } catch (LibvirtException e) {
+            s_logger.error(String.format("Failed to destroy libvirt pool %s: 
%s", uuid, e));
+        }
+        return false;
+    }
+
     @Override
     public boolean deleteStoragePool(String uuid) {
         s_logger.info("Attempting to remove storage pool " + uuid + " from 
libvirt");
-        Connect conn = null;
+        Connect conn;
         try {
             conn = LibvirtConnection.getConnection();
         } catch (LibvirtException e) {
             throw new CloudRuntimeException(e.toString());
         }
 
-        StoragePool sp = null;
         Secret s = null;
-
-        try {
-            sp = conn.storagePoolLookupByUUIDString(uuid);
-        } catch (LibvirtException e) {
-            s_logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. 
Assuming it is already removed");
-            return true;
-        }
-
         /*
          * Some storage pools, like RBD also have 'secret' information stored 
in libvirt
          * Destroy them if they exist
@@ -797,13 +824,7 @@ public class LibvirtStorageAdaptor implements 
StorageAdaptor {
         }
 
         try {
-            if (sp.isPersistent() == 1) {
-                sp.destroy();
-                sp.undefine();
-            } else {
-                sp.destroy();
-            }
-            sp.free();
+            destroyStoragePool(conn, uuid);
             if (s != null) {
                 s.undefine();
                 s.free();
@@ -821,6 +842,7 @@ public class LibvirtStorageAdaptor implements 
StorageAdaptor {
                 String result = Script.runSimpleBashScript("sleep 5 && umount 
" + targetPath);
                 if (result == null) {
                     s_logger.info("Succeeded in unmounting " + targetPath);
+                    destroyStoragePoolHandleException(conn, uuid);
                     return true;
                 }
                 s_logger.error("Failed to unmount " + targetPath);

Reply via email to