Skip to content

Commit ebd081a

Browse files
committed
Fix NPE for live vm backup
1 parent 9edae46 commit ebd081a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,17 @@ public Answer execute(TakeBackupCommand command, LibvirtComputingResource libvir
5454
KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
5555

5656
List<String> diskPaths = new ArrayList<>();
57-
for (int idx = 0; idx < volumePaths.size(); idx++) {
58-
PrimaryDataStoreTO volumePool = volumePools.get(idx);
59-
String volumePath = volumePaths.get(idx);
60-
if (volumePool.getPoolType() != Storage.StoragePoolType.RBD) {
61-
diskPaths.add(volumePath);
62-
} else {
63-
KVMStoragePool volumeStoragePool = storagePoolMgr.getStoragePool(volumePool.getPoolType(), volumePool.getUuid());
64-
String rbdDestVolumeFile = KVMPhysicalDisk.RBDStringBuilder(volumeStoragePool, volumePath);
65-
diskPaths.add(rbdDestVolumeFile);
57+
if (Objects.nonNull(volumePaths)) {
58+
for (int idx = 0; idx < volumePaths.size(); idx++) {
59+
PrimaryDataStoreTO volumePool = volumePools.get(idx);
60+
String volumePath = volumePaths.get(idx);
61+
if (volumePool.getPoolType() != Storage.StoragePoolType.RBD) {
62+
diskPaths.add(volumePath);
63+
} else {
64+
KVMStoragePool volumeStoragePool = storagePoolMgr.getStoragePool(volumePool.getPoolType(), volumePool.getUuid());
65+
String rbdDestVolumeFile = KVMPhysicalDisk.RBDStringBuilder(volumeStoragePool, volumePath);
66+
diskPaths.add(rbdDestVolumeFile);
67+
}
6668
}
6769
}
6870

@@ -76,7 +78,7 @@ public Answer execute(TakeBackupCommand command, LibvirtComputingResource libvir
7678
"-m", Objects.nonNull(mountOptions) ? mountOptions : "",
7779
"-p", backupPath,
7880
"-q", command.getQuiesce() != null && command.getQuiesce() ? "true" : "false",
79-
"-d", (Objects.nonNull(diskPaths) && !diskPaths.isEmpty()) ? String.join(",", diskPaths) : ""
81+
"-d", diskPaths.isEmpty() ? "" : String.join(",", diskPaths)
8082
});
8183

8284
Pair<Integer, String> result = Script.executePipedCommands(commands, libvirtComputingResource.getCmdsTimeout());

0 commit comments

Comments
 (0)