From 4a86a0d2339bbd809d87e7179f510e018030cbbc Mon Sep 17 00:00:00 2001 From: Peinthor Rene Date: Tue, 17 Oct 2023 13:35:42 +0200 Subject: [PATCH] linstor: Fix template volume missing on copy node (#8082) A TODO was overseen and never implemented, which could trigger the following bug: If Linstor didn't create a resource (diskless or diskfull) on the cloudstack choosen node, it would not be able to copy the template data there, it even seems no error was triggered and the new template file silently just became empty/corrupt. --- .../kvm/storage/LinstorStorageAdaptor.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java index 271f961765b..08226478270 100644 --- a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java +++ b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java @@ -197,6 +197,19 @@ public class LinstorStorageAdaptor implements StorageAdaptor { return deleteStoragePool(pool.getUuid()); } + private void makeResourceAvailable(DevelopersApi api, String rscName, boolean diskfull) throws ApiException + { + ResourceMakeAvailable rma = new ResourceMakeAvailable(); + rma.diskful(diskfull); + ApiCallRcList answers = api.resourceMakeAvailableOnNode(rscName, localNodeName, rma); + handleLinstorApiAnswers(answers, + String.format("Linstor: Unable to make resource %s available on node: %s", rscName, localNodeName)); + } + + /** + * createPhysicalDisk will check if the resource wasn't yet created and do so, also it will make sure + * it is accessible from this node (MakeAvailable). + */ @Override public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, QemuImg.PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, byte[] passphrase) @@ -214,7 +227,7 @@ public class LinstorStorageAdaptor implements StorageAdaptor { rgSpawn.setResourceDefinitionName(rscName); rgSpawn.addVolumeSizesItem(size / 1024); // linstor uses KiB - s_logger.debug("Linstor: Spawn resource " + rscName); + s_logger.info("Linstor: Spawn resource " + rscName); ApiCallRcList answers = api.resourceGroupSpawn(lpool.getResourceGroup(), rgSpawn); handleLinstorApiAnswers(answers, "Linstor: Unable to spawn resource."); } @@ -228,7 +241,7 @@ public class LinstorStorageAdaptor implements StorageAdaptor { null, null); - // TODO make available on node + makeResourceAvailable(api, rscName, true); if (!resources.isEmpty() && !resources.get(0).getVolumes().isEmpty()) { final String devPath = resources.get(0).getVolumes().get(0).getDevicePath(); @@ -418,7 +431,7 @@ public class LinstorStorageAdaptor implements StorageAdaptor { final QemuImgFile srcFile = new QemuImgFile(sourcePath, sourceFormat); final KVMPhysicalDisk dstDisk = destPools.createPhysicalDisk( - name, QemuImg.PhysicalDiskFormat.RAW, Storage.ProvisioningType.FAT, disk.getVirtualSize(), null); + name, QemuImg.PhysicalDiskFormat.RAW, provisioningType, disk.getVirtualSize(), null); final QemuImgFile destFile = new QemuImgFile(dstDisk.getPath()); destFile.setFormat(dstDisk.getFormat());