Skip to content

Commit 027e603

Browse files
[KVM] Disconnect the volumes with the proper storage adaptor. (apache#6029)
* [KVM] Disconnect the volumes with the proper storage adaptor. * Improved / Added logs
1 parent 19b8da2 commit 027e603

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ private List<Map<String, String>> getVolumesToDisconnect(VirtualMachine vm) {
16811681
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
16821682

16831683
if (storagePool != null && storagePool.isManaged()) {
1684-
Map<String, String> info = new HashMap<>(3);
1684+
Map<String, String> info = new HashMap<>();
16851685

16861686
info.put(DiskTO.STORAGE_HOST, storagePool.getHostAddress());
16871687
info.put(DiskTO.STORAGE_PORT, String.valueOf(storagePool.getPort()));

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,7 @@ public boolean cleanupDisk(Map<String, String> volumeToDisconnect) {
30243024
public boolean cleanupDisk(final DiskDef disk) {
30253025
final String path = disk.getDiskPath();
30263026

3027-
if (path == null) {
3027+
if (org.apache.commons.lang.StringUtils.isBlank(path)) {
30283028
s_logger.debug("Unable to clean up disk with null path (perhaps empty cdrom drive):" + disk);
30293029
return false;
30303030
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,6 @@ public boolean disconnectPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
331331

332332
@Override
333333
public boolean disconnectPhysicalDisk(Map<String, String> volumeToDisconnect) {
334-
String poolType = volumeToDisconnect.get(DiskTO.PROTOCOL_TYPE);
335-
// Unsupported pool types
336-
if (poolType != null && poolType.equalsIgnoreCase(StoragePoolType.PowerFlex.toString())) {
337-
return false;
338-
}
339-
340334
String host = volumeToDisconnect.get(DiskTO.STORAGE_HOST);
341335
String port = volumeToDisconnect.get(DiskTO.STORAGE_PORT);
342336
String path = volumeToDisconnect.get(DiskTO.IQN);

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
3030
import org.apache.cloudstack.storage.to.VolumeObjectTO;
3131
import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
32+
import org.apache.commons.collections.MapUtils;
3233
import org.apache.log4j.Logger;
3334
import org.reflections.Reflections;
3435

@@ -165,10 +166,27 @@ public boolean connectPhysicalDisksViaVmSpec(VirtualMachineTO vmSpec) {
165166
}
166167

167168
public boolean disconnectPhysicalDisk(Map<String, String> volumeToDisconnect) {
169+
s_logger.debug(String.format("Disconnect physical disks using volume map: %s", volumeToDisconnect.toString()));
170+
if (MapUtils.isEmpty(volumeToDisconnect)) {
171+
return false;
172+
}
173+
174+
if (volumeToDisconnect.get(DiskTO.PROTOCOL_TYPE) != null) {
175+
String poolType = volumeToDisconnect.get(DiskTO.PROTOCOL_TYPE);
176+
StorageAdaptor adaptor = _storageMapper.get(poolType);
177+
if (adaptor != null) {
178+
s_logger.info(String.format("Disconnecting physical disk using the storage adaptor found for pool type: %s", poolType));
179+
return adaptor.disconnectPhysicalDisk(volumeToDisconnect);
180+
}
181+
182+
s_logger.debug(String.format("Couldn't find the storage adaptor for pool type: %s to disconnect the physical disk, trying with others", poolType));
183+
}
184+
168185
for (Map.Entry<String, StorageAdaptor> set : _storageMapper.entrySet()) {
169186
StorageAdaptor adaptor = set.getValue();
170187

171188
if (adaptor.disconnectPhysicalDisk(volumeToDisconnect)) {
189+
s_logger.debug(String.format("Disconnected physical disk using the storage adaptor for pool type: %s", set.getKey()));
172190
return true;
173191
}
174192
}
@@ -177,10 +195,12 @@ public boolean disconnectPhysicalDisk(Map<String, String> volumeToDisconnect) {
177195
}
178196

179197
public boolean disconnectPhysicalDiskByPath(String path) {
198+
s_logger.debug(String.format("Disconnect physical disk by path: %s", path));
180199
for (Map.Entry<String, StorageAdaptor> set : _storageMapper.entrySet()) {
181200
StorageAdaptor adaptor = set.getValue();
182201

183202
if (adaptor.disconnectPhysicalDiskByPath(path)) {
203+
s_logger.debug(String.format("Disconnected physical disk by local path: %s, using the storage adaptor for pool type: %s", path, set.getKey()));
184204
return true;
185205
}
186206
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ public boolean disconnectPhysicalDisk(String volumePath, KVMStoragePool pool)
288288
@Override
289289
public boolean disconnectPhysicalDisk(Map<String, String> volumeToDisconnect)
290290
{
291-
s_logger.debug("Linstor: disconnectPhysicalDisk map");
292-
return true;
291+
return false;
293292
}
294293

295294
private Optional<ResourceWithVolumes> getResourceByPath(final List<ResourceWithVolumes> resources, String path) {
@@ -309,10 +308,10 @@ private Optional<ResourceWithVolumes> getResourceByPath(final List<ResourceWithV
309308
@Override
310309
public boolean disconnectPhysicalDiskByPath(String localPath)
311310
{
312-
s_logger.debug("Linstor: disconnectPhysicalDiskByPath " + localPath);
313311
// get first storage pool from the map, as we don't know any better:
314312
if (!MapStorageUuidToStoragePool.isEmpty())
315313
{
314+
s_logger.debug("Linstor: disconnectPhysicalDiskByPath " + localPath);
316315
String firstKey = MapStorageUuidToStoragePool.keySet().stream().findFirst().get();
317316
final KVMStoragePool pool = MapStorageUuidToStoragePool.get(firstKey);
318317

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ public boolean disconnectPhysicalDisk(String volumePath, KVMStoragePool pool) {
214214

215215
@Override
216216
public boolean disconnectPhysicalDisk(Map<String, String> volumeToDisconnect) {
217-
return true;
217+
return false;
218218
}
219219

220220
@Override
221221
public boolean disconnectPhysicalDiskByPath(String localPath) {
222-
return true;
222+
return false;
223223
}
224224

225225
@Override

0 commit comments

Comments
 (0)