Skip to content

Commit 427e49c

Browse files
committed
Fix VM migration with attached ISO
1 parent 7308dad commit 427e49c

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
@@ -282,8 +282,7 @@ public void storagePoolRefresh(StoragePool pool) {
282282

283283
private void checkNetfsStoragePoolMounted(String uuid) {
284284
String targetPath = _mountPoint + File.separator + uuid;
285-
int mountpointResult = Script.runSimpleBashScriptForExitValue("mountpoint -q " + targetPath);
286-
if (mountpointResult != 0) {
285+
if (!isStoragePoolMounted(targetPath)) {
287286
String errMsg = String.format("libvirt failed to mount storage pool %s at %s", uuid, targetPath);
288287
logger.error(errMsg);
289288
throw new CloudRuntimeException(errMsg);
@@ -298,9 +297,8 @@ private StoragePool createNetfsStoragePool(PoolType fsType, Connect conn, String
298297
try {
299298
logger.debug(spd.toString());
300299
// check whether the pool is already mounted
301-
int mountpointResult = Script.runSimpleBashScriptForExitValue("mountpoint -q " + targetPath);
302300
// if the pool is mounted, try to unmount it
303-
if(mountpointResult == 0) {
301+
if (isStoragePoolMounted(targetPath)) {
304302
logger.info("Attempting to unmount old mount at " + targetPath);
305303
String result = Script.runSimpleBashScript("umount -l " + targetPath);
306304
if (result == null) {
@@ -833,6 +831,12 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri
833831
} else if (type == StoragePoolType.CLVM) {
834832
sp = createCLVMStoragePool(conn, name, host, path);
835833
}
834+
} else {
835+
String targetPath = _mountPoint + File.separator + name;
836+
if (type == StoragePoolType.NetworkFilesystem && !isPrimaryStorage && !isStoragePoolMounted(targetPath)) {
837+
String storageMountPoint = host + ":" + path;
838+
mountNfsStoragePool(storageMountPoint, targetPath, nfsMountOpts);
839+
}
836840
}
837841

838842
if (sp == null) {
@@ -869,6 +873,16 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri
869873
}
870874
}
871875

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

0 commit comments

Comments
 (0)