Skip to content

Commit 9cfd434

Browse files
committed
CLOUDSTACK-2729: another try to solve libvirt storage pool missing issue: if the storage pool is missing, then recreate it
1 parent 2f49196 commit 9cfd434

2 files changed

Lines changed: 44 additions & 41 deletions

File tree

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java‎

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,35 @@
3333
import com.cloud.utils.exception.CloudRuntimeException;
3434

3535
public class KVMStoragePoolManager {
36+
private class StoragePoolInformation {
37+
String name;
38+
String host;
39+
int port;
40+
String path;
41+
String userInfo;
42+
boolean type;
43+
StoragePoolType poolType;
44+
45+
46+
public StoragePoolInformation(String name,
47+
String host,
48+
int port,
49+
String path,
50+
String userInfo,
51+
StoragePoolType poolType,
52+
boolean type) {
53+
this.name = name;
54+
this.host = host;
55+
this.port = port;
56+
this.path = path;
57+
this.userInfo = userInfo;
58+
this.type = type;
59+
this.poolType = poolType;
60+
}
61+
}
3662
private StorageAdaptor _storageAdaptor;
3763
private KVMHAMonitor _haMonitor;
38-
private final Map<String, Object> _storagePools = new ConcurrentHashMap<String, Object>();
64+
private final Map<String, StoragePoolInformation> _storagePools = new ConcurrentHashMap<String, StoragePoolInformation>();
3965
private final Map<String, StorageAdaptor> _storageMapper = new HashMap<String, StorageAdaptor>();
4066

4167
private StorageAdaptor getStorageAdaptor(StoragePoolType type) {
@@ -51,10 +77,10 @@ private StorageAdaptor getStorageAdaptor(StoragePoolType type) {
5177
return adaptor;
5278
}
5379

54-
private void addStoragePool(String uuid) {
80+
private void addStoragePool(String uuid, StoragePoolInformation pool) {
5581
synchronized (_storagePools) {
5682
if (!_storagePools.containsKey(uuid)) {
57-
_storagePools.put(uuid, new Object());
83+
_storagePools.put(uuid, pool);
5884
}
5985
}
6086
}
@@ -69,7 +95,16 @@ public KVMStoragePoolManager(StorageLayer storagelayer, KVMHAMonitor monitor) {
6995

7096
public KVMStoragePool getStoragePool(StoragePoolType type, String uuid) {
7197
StorageAdaptor adaptor = getStorageAdaptor(type);
72-
return adaptor.getStoragePool(uuid);
98+
KVMStoragePool pool = null;
99+
try {
100+
pool = adaptor.getStoragePool(uuid);
101+
} catch(Exception e) {
102+
StoragePoolInformation info = _storagePools.get(uuid);
103+
if (info != null) {
104+
pool = createStoragePool(info.name, info.host, info.port, info.path, info.userInfo, info.poolType, info.type);
105+
}
106+
}
107+
return pool;
73108
}
74109

75110
public KVMStoragePool getStoragePoolByURI(String uri) {
@@ -119,7 +154,8 @@ private KVMStoragePool createStoragePool( String name, String host, int port,
119154
PoolType.PrimaryStorage);
120155
_haMonitor.addStoragePool(nfspool);
121156
}
122-
addStoragePool(pool.getUuid());
157+
StoragePoolInformation info = new StoragePoolInformation(name, host, port, path, userInfo, type, primaryStorage);
158+
addStoragePool(pool.getUuid(), info);
123159
return pool;
124160
}
125161

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java‎

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,45 +1168,12 @@ public boolean deleteStoragePool(KVMStoragePool pool) {
11681168
// However, we also need to fix the issues in CloudStack source code.
11691169
// A file lock is used to prevent deleting a volume from a KVM storage pool when refresh it.
11701170
private void refreshPool(StoragePool pool) throws LibvirtException {
1171-
Connect conn = LibvirtConnection.getConnection();
1172-
LibvirtStoragePoolDef spd = getStoragePoolDef(conn, pool);
1173-
if ((! spd.getPoolType().equals(LibvirtStoragePoolDef.poolType.NETFS))
1174-
&& (! spd.getPoolType().equals(LibvirtStoragePoolDef.poolType.DIR))) {
1175-
pool.refresh(0);
1176-
return;
1177-
}
1178-
String lockFile = spd.getTargetPath() + File.separator + _lockfile;
1179-
s_logger.debug("Attempting to lock pool " + pool.getName() + " with file " + lockFile);
1180-
if (lock(lockFile, ACQUIRE_GLOBAL_FILELOCK_TIMEOUT_FOR_KVM)) {
1181-
try {
1182-
pool.refresh(0);
1183-
} finally {
1184-
s_logger.debug("Releasing the lock on pool " + pool.getName() + " with file " + lockFile);
1185-
unlock(lockFile);
1186-
}
1187-
} else {
1188-
throw new CloudRuntimeException("Can not get file lock to refresh the pool " + pool.getName());
1189-
}
1171+
pool.refresh(0);
1172+
return;
11901173
}
11911174

11921175
private void deleteVol(LibvirtStoragePool pool, StorageVol vol) throws LibvirtException {
1193-
if ((! pool.getType().equals(StoragePoolType.NetworkFilesystem))
1194-
&& (! pool.getType().equals(StoragePoolType.Filesystem))) {
1195-
vol.delete(0);
1196-
return;
1197-
}
1198-
String lockFile = pool.getLocalPath() + File.separator + _lockfile;
1199-
s_logger.debug("Attempting to lock pool " + pool.getName() + " with file " + lockFile);
1200-
if (lock(lockFile, ACQUIRE_GLOBAL_FILELOCK_TIMEOUT_FOR_KVM)) {
1201-
try {
1202-
vol.delete(0);
1203-
} finally {
1204-
s_logger.debug("Releasing the lock on pool " + pool.getName() + " with file " + lockFile);
1205-
unlock(lockFile);
1206-
}
1207-
} else {
1208-
throw new CloudRuntimeException("Can not get file lock to delete the volume " + vol.getName());
1209-
}
1176+
vol.delete(0);
12101177
}
12111178

12121179
private boolean lock(String path, int wait) {

0 commit comments

Comments
 (0)