Skip to content

Commit

Permalink
linstor: use added KVMPhysicalDisk info for Aux properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rp- committed Aug 14, 2024
1 parent c118e98 commit 8ad53a6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,21 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt
final KVMPhysicalDisk dstDisk = destPools.createPhysicalDisk(
name, QemuImg.PhysicalDiskFormat.RAW, provisioningType, disk.getVirtualSize(), null);

final DevelopersApi api = getLinstorAPI(destPools);
final String rscName = LinstorUtil.RSC_PREFIX + name;
try {
LinstorUtil.applyAuxProps(api, rscName, disk.getDispName(), disk.getVmName());
} catch (ApiException apiExc) {
s_logger.error(String.format("Error setting aux properties for %s", rscName));
logLinstorAnswers(apiExc.getApiCallRcList());
}

s_logger.debug(String.format("Linstor.copyPhysicalDisk: dstPath: %s", dstDisk.getPath()));
final QemuImgFile destFile = new QemuImgFile(dstDisk.getPath());
destFile.setFormat(dstDisk.getFormat());
destFile.setSize(disk.getVirtualSize());

boolean zeroedDevice = resourceSupportZeroBlocks(destPools, LinstorUtil.RSC_PREFIX + name);
boolean zeroedDevice = resourceSupportZeroBlocks(destPools, rscName);

try {
final QemuImg qemu = new QemuImg(timeout, zeroedDevice, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.linbit.linstor.api.model.ResourceDefinitionCloneRequest;
import com.linbit.linstor.api.model.ResourceDefinitionCloneStarted;
import com.linbit.linstor.api.model.ResourceDefinitionCreate;
import com.linbit.linstor.api.model.ResourceDefinitionModify;
import com.linbit.linstor.api.model.ResourceGroupSpawn;
import com.linbit.linstor.api.model.ResourceMakeAvailable;
import com.linbit.linstor.api.model.Snapshot;
Expand Down Expand Up @@ -62,8 +61,8 @@
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.ResizeVolumePayload;
import com.cloud.storage.SnapshotVO;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePool;
import com.cloud.storage.VMTemplateStoragePoolVO;
Expand Down Expand Up @@ -389,27 +388,6 @@ private void applyQoSSettings(StoragePoolVO storagePool, DevelopersApi api, Stri
}
}

private void applyAuxProps(DevelopersApi api, String rscName, String dispName, String vmName)
throws ApiException
{
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
Properties props = new Properties();
if (dispName != null)
{
props.put("Aux/cs-name", dispName);
}
if (vmName != null)
{
props.put("Aux/cs-vm-name", vmName);
}
if (!props.isEmpty())
{
rdm.setOverrideProps(props);
ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
checkLinstorAnswersThrow(answers);
}
}

private String getRscGrp(StoragePoolVO storagePoolVO) {
return storagePoolVO.getUserInfo() != null && !storagePoolVO.getUserInfo().isEmpty() ?
storagePoolVO.getUserInfo() : "DfltRscGrp";
Expand All @@ -427,7 +405,8 @@ private String createResourceBase(
ApiCallRcList answers = api.resourceGroupSpawn(rscGrp, rscGrpSpawn);
checkLinstorAnswersThrow(answers);

applyAuxProps(api, rscName, volName, vmName);
answers = LinstorUtil.applyAuxProps(api, rscName, volName, vmName);
checkLinstorAnswersThrow(answers);

return LinstorUtil.getDevicePath(api, rscName);
} catch (ApiException apiEx)
Expand Down Expand Up @@ -499,7 +478,7 @@ private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolV
resizeResource(linstorApi, rscName, volumeInfo.getSize());
}

applyAuxProps(linstorApi, rscName, volumeInfo.getName(), volumeInfo.getAttachedVmName());
LinstorUtil.applyAuxProps(linstorApi, rscName, volumeInfo.getName(), volumeInfo.getAttachedVmName());
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeInfo.getMaxIops());

return LinstorUtil.getDevicePath(linstorApi, rscName);
Expand Down Expand Up @@ -551,7 +530,7 @@ private String createResourceFromSnapshot(long csSnapshotId, String rscName, Sto
answers = linstorApi.resourceSnapshotRestore(cloneRes, snapName, snapshotRestore);
checkLinstorAnswersThrow(answers);

applyAuxProps(linstorApi, rscName, volumeVO.getName(), null);
LinstorUtil.applyAuxProps(linstorApi, rscName, volumeVO.getName(), null);
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeVO.getMaxIops());

return LinstorUtil.getDevicePath(linstorApi, rscName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import com.linbit.linstor.api.model.ApiCallRc;
import com.linbit.linstor.api.model.ApiCallRcList;
import com.linbit.linstor.api.model.Node;
import com.linbit.linstor.api.model.Properties;
import com.linbit.linstor.api.model.ProviderKind;
import com.linbit.linstor.api.model.Resource;
import com.linbit.linstor.api.model.ResourceDefinitionModify;
import com.linbit.linstor.api.model.ResourceGroup;
import com.linbit.linstor.api.model.ResourceWithVolumes;
import com.linbit.linstor.api.model.StoragePool;
Expand Down Expand Up @@ -236,4 +238,26 @@ public static String getDevicePath(DevelopersApi api, String rscName) throws Api
s_logger.error(errMsg);
throw new CloudRuntimeException("Linstor: " + errMsg);
}

public static ApiCallRcList applyAuxProps(DevelopersApi api, String rscName, String dispName, String vmName)
throws ApiException
{
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
Properties props = new Properties();
if (dispName != null)
{
props.put("Aux/cs-name", dispName);
}
if (vmName != null)
{
props.put("Aux/cs-vm-name", vmName);
}
ApiCallRcList answers = new ApiCallRcList();
if (!props.isEmpty())
{
rdm.setOverrideProps(props);
answers = api.resourceDefinitionModify(rscName, rdm);
}
return answers;
}
}

0 comments on commit 8ad53a6

Please sign in to comment.