Skip to content

Commit b9145be

Browse files
committed
Fix CID 1116267 Don't modify the set while the iterator is still in use.
1 parent 362b481 commit b9145be

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package com.cloud.hypervisor.kvm.resource;
1818

1919
import java.util.ArrayList;
20+
import java.util.HashSet;
2021
import java.util.List;
2122
import java.util.Map;
23+
import java.util.Set;
2224
import java.util.concurrent.ConcurrentHashMap;
2325

2426
import org.apache.log4j.Logger;
@@ -39,24 +41,24 @@ public class KVMHAMonitor extends KVMHABase implements Runnable {
3941

4042
public KVMHAMonitor(NfsStoragePool pool, String host, String scriptPath) {
4143
if (pool != null) {
42-
this._storagePool.put(pool._poolUUID, pool);
44+
_storagePool.put(pool._poolUUID, pool);
4345
}
44-
this._hostIP = host;
46+
_hostIP = host;
4547
KVMHABase.s_heartBeatPath = scriptPath;
4648
}
4749

4850
public void addStoragePool(NfsStoragePool pool) {
4951
synchronized (_storagePool) {
50-
this._storagePool.put(pool._poolUUID, pool);
52+
_storagePool.put(pool._poolUUID, pool);
5153
}
5254
}
5355

5456
public void removeStoragePool(String uuid) {
5557
synchronized (_storagePool) {
56-
NfsStoragePool pool = this._storagePool.get(uuid);
58+
NfsStoragePool pool = _storagePool.get(uuid);
5759
if (pool != null) {
5860
Script.runSimpleBashScript("umount " + pool._mountDestPath);
59-
this._storagePool.remove(uuid);
61+
_storagePool.remove(uuid);
6062
}
6163
}
6264
}
@@ -72,6 +74,7 @@ private class Monitor extends ManagedContextRunnable {
7274
@Override
7375
protected void runInContext() {
7476
synchronized (_storagePool) {
77+
Set<String> removedPools = new HashSet<String>();
7578
for (String uuid : _storagePool.keySet()) {
7679
NfsStoragePool primaryStoragePool = _storagePool.get(uuid);
7780

@@ -84,13 +87,13 @@ protected void runInContext() {
8487
storage = conn.storagePoolLookupByUUIDString(uuid);
8588
if (storage == null) {
8689
s_logger.debug("Libvirt storage pool " + uuid + " not found, removing from HA list");
87-
removeStoragePool(uuid);
90+
removedPools.add(uuid);
8891
continue;
8992

9093
} else if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
9194
s_logger.debug("Libvirt storage pool " + uuid + " found, but not running, removing from HA list");
9295

93-
removeStoragePool(uuid);
96+
removedPools.add(uuid);
9497
continue;
9598
}
9699
s_logger.debug("Found NFS storage pool " + uuid + " in libvirt, continuing");
@@ -102,7 +105,7 @@ protected void runInContext() {
102105
// connection fails
103106
if (e.toString().contains("pool not found")) {
104107
s_logger.debug("removing pool from HA monitor since it was deleted");
105-
removeStoragePool(uuid);
108+
removedPools.add(uuid);
106109
continue;
107110
}
108111
}
@@ -132,6 +135,12 @@ protected void runInContext() {
132135
result = cmd.execute();
133136
}
134137
}
138+
139+
if (!removedPools.isEmpty()) {
140+
for (String uuid : removedPools) {
141+
removeStoragePool(uuid);
142+
}
143+
}
135144
}
136145

137146
}

0 commit comments

Comments
 (0)