Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<String> 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 {
Expand Down
Loading