rp- commented on code in PR #9498:
URL: https://github.com/apache/cloudstack/pull/9498#discussion_r1762507176


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java:
##########
@@ -637,6 +638,38 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, 
KVMStoragePool pool) {
         }
     }
 
+    /**
+     * Thread-safe increment storage pool usage refcount
+     * @param uuid UUID of the storage pool to increment the count
+     */
+    private void incStoragePoolRefCount(String uuid) {
+        synchronized (storagePoolRefCounts) {
+            int refCount = storagePoolRefCounts.computeIfAbsent(uuid, k -> 0);
+            refCount += 1;
+            storagePoolRefCounts.put(uuid, refCount);
+        }
+    }
+
+    /**
+     * Thread-safe decrement storage pool usage refcount for the given uuid 
and return if storage pool still in use.
+     * @param uuid UUID of the storage pool to decrement the count
+     * @return true if the storage pool is still used, else false.
+     */
+    private boolean decStoragePoolRefCount(String uuid) {
+        synchronized (storagePoolRefCounts) {
+            Integer refCount = storagePoolRefCounts.get(uuid);
+            if (refCount != null && refCount > 1) {
+                s_logger.debug(String.format("Storage pool %s still in use, 
refCount %d", uuid, refCount));
+                refCount -= 1;
+                storagePoolRefCounts.put(uuid, refCount);
+                return true;
+            } else {
+                storagePoolRefCounts.remove(uuid);
+                return false;
+            }
+        }
+    }

Review Comment:
   Or it just stroke me, that maybe the `LibVirtStorageAdaptor` is no singleton 
object and there could be more instances, but than it would probably be good 
enough to make the map `static`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to