Skip to content

Commit 7988bb8

Browse files
committed
Fix VM migration with attached ISO
1 parent a3970bb commit 7988bb8

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ public void storagePoolRefresh(StoragePool pool) {
279279

280280
private void checkNetfsStoragePoolMounted(String uuid) {
281281
String targetPath = _mountPoint + File.separator + uuid;
282-
int mountpointResult = Script.runSimpleBashScriptForExitValue("mountpoint -q " + targetPath);
283-
if (mountpointResult != 0) {
282+
if (!isStoragePoolMounted(targetPath)) {
284283
String errMsg = String.format("libvirt failed to mount storage pool %s at %s", uuid, targetPath);
285284
logger.error(errMsg);
286285
throw new CloudRuntimeException(errMsg);
@@ -295,9 +294,8 @@ private StoragePool createNetfsStoragePool(PoolType fsType, Connect conn, String
295294
try {
296295
logger.debug(spd.toString());
297296
// check whether the pool is already mounted
298-
int mountpointResult = Script.runSimpleBashScriptForExitValue("mountpoint -q " + targetPath);
299297
// if the pool is mounted, try to unmount it
300-
if(mountpointResult == 0) {
298+
if (isStoragePoolMounted(targetPath)) {
301299
logger.info("Attempting to unmount old mount at " + targetPath);
302300
String result = Script.runSimpleBashScript("umount -l " + targetPath);
303301
if (result == null) {
@@ -830,6 +828,12 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri
830828
} else if (type == StoragePoolType.CLVM) {
831829
sp = createCLVMStoragePool(conn, name, host, path);
832830
}
831+
} else {
832+
String targetPath = _mountPoint + File.separator + name;
833+
if (type == StoragePoolType.NetworkFilesystem && !isPrimaryStorage && !isStoragePoolMounted(targetPath)) {
834+
String storageMountPoint = host + ":" + path;
835+
mountNfsStoragePool(storageMountPoint, targetPath, nfsMountOpts);
836+
}
833837
}
834838

835839
if (sp == null) {
@@ -866,6 +870,16 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri
866870
}
867871
}
868872

873+
private boolean isStoragePoolMounted(String path) {
874+
return Script.runSimpleBashScriptForExitValue("mountpoint -q " + path) == 0;
875+
}
876+
877+
private void mountNfsStoragePool(String storageMountPoint, String targetPath, List<String> nfsMountOptions) {
878+
String mountOptions = CollectionUtils.isNotEmpty(nfsMountOptions) ? String.format("-o %s", String.join(",", nfsMountOptions)) : "";
879+
logger.debug("Attempting to mount NFS storage [{}] at [{}] with options [{}].", storageMountPoint, targetPath, mountOptions);
880+
Script.runSimpleBashScript(String.format("mount -t nfs %s %s %s", mountOptions, storageMountPoint, targetPath));
881+
}
882+
869883
private boolean destroyStoragePool(Connect conn, String uuid) throws LibvirtException {
870884
StoragePool sp;
871885
try {

0 commit comments

Comments
 (0)