From 427e49c7f7d8514d9c7b2d022b5b0336231b4e70 Mon Sep 17 00:00:00 2001 From: Henrique Sato Date: Wed, 3 Jun 2026 09:59:23 -0300 Subject: [PATCH] Fix VM migration with attached ISO --- .../kvm/storage/LibvirtStorageAdaptor.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java index a03daeb197bf..04bed9d3ce40 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java @@ -282,8 +282,7 @@ public void storagePoolRefresh(StoragePool pool) { private void checkNetfsStoragePoolMounted(String uuid) { String targetPath = _mountPoint + File.separator + uuid; - int mountpointResult = Script.runSimpleBashScriptForExitValue("mountpoint -q " + targetPath); - if (mountpointResult != 0) { + if (!isStoragePoolMounted(targetPath)) { String errMsg = String.format("libvirt failed to mount storage pool %s at %s", uuid, targetPath); logger.error(errMsg); throw new CloudRuntimeException(errMsg); @@ -298,9 +297,8 @@ private StoragePool createNetfsStoragePool(PoolType fsType, Connect conn, String try { logger.debug(spd.toString()); // check whether the pool is already mounted - int mountpointResult = Script.runSimpleBashScriptForExitValue("mountpoint -q " + targetPath); // if the pool is mounted, try to unmount it - if(mountpointResult == 0) { + if (isStoragePoolMounted(targetPath)) { logger.info("Attempting to unmount old mount at " + targetPath); String result = Script.runSimpleBashScript("umount -l " + targetPath); if (result == null) { @@ -833,6 +831,12 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri } else if (type == StoragePoolType.CLVM) { sp = createCLVMStoragePool(conn, name, host, path); } + } else { + String targetPath = _mountPoint + File.separator + name; + if (type == StoragePoolType.NetworkFilesystem && !isPrimaryStorage && !isStoragePoolMounted(targetPath)) { + String storageMountPoint = host + ":" + path; + mountNfsStoragePool(storageMountPoint, targetPath, nfsMountOpts); + } } if (sp == null) { @@ -869,6 +873,16 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri } } + private boolean isStoragePoolMounted(String path) { + return Script.runSimpleBashScriptForExitValue("mountpoint -q " + path) == 0; + } + + private void mountNfsStoragePool(String storageMountPoint, String targetPath, List nfsMountOptions) { + String mountOptions = CollectionUtils.isNotEmpty(nfsMountOptions) ? String.format("-o %s", String.join(",", nfsMountOptions)) : ""; + logger.debug("Attempting to mount NFS storage [{}] at [{}] with options [{}].", storageMountPoint, targetPath, mountOptions); + Script.runSimpleBashScript(String.format("mount -t nfs %s %s %s", mountOptions, storageMountPoint, targetPath)); + } + private boolean destroyStoragePool(Connect conn, String uuid) throws LibvirtException { StoragePool sp; try {