Skip to content

Commit

Permalink
linstor: Fix volume format and make resource available on copy target
Browse files Browse the repository at this point in the history
Linstor primary storage forgot to make sure
the volume download/copy target has a Linstor resource available.
  • Loading branch information
rp- committed Mar 20, 2024
1 parent fe5d741 commit a2f5ea1
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,15 @@ private static boolean canCopyTemplateCond(DataObject srcData, DataObject dstDat
|| srcData.getDataStore().getRole() == DataStoreRole.ImageCache);
}

private static boolean canCopyVolumeCond(DataObject srcData, DataObject dstData) {
// Volume download from Linstor primary storage
return srcData.getType() == DataObjectType.VOLUME
&& (dstData.getType() == DataObjectType.VOLUME || dstData.getType() == DataObjectType.TEMPLATE)
&& srcData.getDataStore().getRole() == DataStoreRole.Primary
&& (dstData.getDataStore().getRole() == DataStoreRole.Image
|| dstData.getDataStore().getRole() == DataStoreRole.ImageCache);
}

@Override
public boolean canCopy(DataObject srcData, DataObject dstData)
{
Expand All @@ -814,6 +823,10 @@ public boolean canCopy(DataObject srcData, DataObject dstData)
return storagePoolVO != null
&& storagePoolVO.getPoolType() == Storage.StoragePoolType.Linstor
&& tInfo.getSize() != null;
} else if (canCopyVolumeCond(srcData, dstData)) {
VolumeInfo srcVolInfo = (VolumeInfo) srcData;
StoragePoolVO storagePool = _storagePoolDao.findById(srcVolInfo.getPoolId());
return storagePool.getStorageProviderName().equals(LinstorUtil.PROVIDER_NAME);
}
return false;
}
Expand Down Expand Up @@ -844,6 +857,9 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal
} else if (canCopyTemplateCond(srcData, dstData)) {
Answer answer = copyTemplate(srcData, dstData);
res = new CopyCommandResult(null, answer);
} else if (canCopyVolumeCond(srcData, dstData)) {
Answer answer = copyVolume(srcData, dstData);
res = new CopyCommandResult(null, answer);
} else {
Answer answer = new Answer(null, false, "noimpl");
res = new CopyCommandResult(null, answer);
Expand Down Expand Up @@ -965,6 +981,36 @@ private Answer copyTemplate(DataObject srcData, DataObject dstData) {
return answer;
}

private Answer copyVolume(DataObject srcData, DataObject dstData) {
VolumeInfo srcVolInfo = (VolumeInfo) srcData;
final StoragePoolVO pool = _storagePoolDao.findById(srcVolInfo.getDataStore().getId());
final DevelopersApi api = LinstorUtil.getLinstorAPI(pool.getHostAddress());
final String rscName = LinstorUtil.RSC_PREFIX + srcVolInfo.getUuid();

int nMaxExecutionMinutes = NumbersUtil.parseInt(
_configDao.getValue(Config.SecStorageCmdExecutionTimeMax.key()), 30);
CopyCommand cmd = new CopyCommand(
srcData.getTO(),
dstData.getTO(),
nMaxExecutionMinutes * 60 * 1000,
VirtualMachineManager.ExecuteInSequence.value());
Answer answer;

try {
Optional<RemoteHostEndPoint> optEP = getLinstorEP(api, rscName);
if (optEP.isPresent()) {
answer = optEP.get().sendMessage(cmd);
}
else {
answer = new Answer(cmd, false, "Unable to get matching Linstor endpoint.");
}
} catch (ApiException exc) {
s_logger.error("copy volume failed: ", exc);
throw new CloudRuntimeException(exc.getBestMessage());
}
return answer;
}

/**
* Create a temporary resource from the snapshot to backup, so we can copy the data on a diskless agent
* @param api Linstor Developer api object
Expand Down

0 comments on commit a2f5ea1

Please sign in to comment.