Skip to content

Commit c779b1c

Browse files
committed
Merge branch '4.18' into 4.19
2 parents 91c7bc7 + 2339412 commit c779b1c

40 files changed

+46
-8926
lines changed

plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,12 @@ public KVMPhysicalDisk getPhysicalDisk(String name, KVMStoragePool pool)
130130
List<VolumeDefinition> volumeDefs = api.volumeDefinitionList(rscName, null, null);
131131
final long size = volumeDefs.isEmpty() ? 0 : volumeDefs.get(0).getSizeKib() * 1024;
132132

133-
List<ResourceWithVolumes> resources = api.viewResources(
134-
Collections.emptyList(),
135-
Collections.singletonList(rscName),
136-
Collections.emptyList(),
137-
null,
138-
null,
139-
null);
140-
if (!resources.isEmpty() && !resources.get(0).getVolumes().isEmpty()) {
141-
final String devPath = resources.get(0).getVolumes().get(0).getDevicePath();
142-
final KVMPhysicalDisk kvmDisk = new KVMPhysicalDisk(devPath, name, pool);
143-
kvmDisk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
144-
kvmDisk.setSize(size);
145-
kvmDisk.setVirtualSize(size);
146-
return kvmDisk;
147-
} else {
148-
s_logger.error("Linstor: viewResources didn't return resources or volumes for " + rscName);
149-
throw new CloudRuntimeException("Linstor: viewResources didn't return resources or volumes.");
150-
}
133+
final String devicePath = LinstorUtil.getDevicePath(api, rscName);
134+
final KVMPhysicalDisk kvmDisk = new KVMPhysicalDisk(devicePath, name, pool);
135+
kvmDisk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
136+
kvmDisk.setSize(size);
137+
kvmDisk.setVirtualSize(size);
138+
return kvmDisk;
151139
} catch (ApiException apiEx) {
152140
s_logger.error(apiEx);
153141
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.linbit.linstor.api.model.ResourceDefinitionModify;
3030
import com.linbit.linstor.api.model.ResourceGroupSpawn;
3131
import com.linbit.linstor.api.model.ResourceMakeAvailable;
32-
import com.linbit.linstor.api.model.ResourceWithVolumes;
3332
import com.linbit.linstor.api.model.Snapshot;
3433
import com.linbit.linstor.api.model.SnapshotRestore;
3534
import com.linbit.linstor.api.model.VolumeDefinition;
@@ -342,25 +341,6 @@ private String checkLinstorAnswers(@Nonnull ApiCallRcList answers) {
342341
return answers.stream().filter(ApiCallRc::isError).findFirst().map(ApiCallRc::getMessage).orElse(null);
343342
}
344343

345-
private String getDeviceName(DevelopersApi linstorApi, String rscName) throws ApiException {
346-
List<ResourceWithVolumes> resources = linstorApi.viewResources(
347-
Collections.emptyList(),
348-
Collections.singletonList(rscName),
349-
Collections.emptyList(),
350-
null,
351-
null,
352-
null);
353-
if (!resources.isEmpty() && !resources.get(0).getVolumes().isEmpty())
354-
{
355-
s_logger.info("Linstor: Created drbd device: " + resources.get(0).getVolumes().get(0).getDevicePath());
356-
return resources.get(0).getVolumes().get(0).getDevicePath();
357-
} else
358-
{
359-
s_logger.error("Linstor: viewResources didn't return resources or volumes.");
360-
throw new CloudRuntimeException("Linstor: viewResources didn't return resources or volumes.");
361-
}
362-
}
363-
364344
private void applyQoSSettings(StoragePoolVO storagePool, DevelopersApi api, String rscName, Long maxIops)
365345
throws ApiException
366346
{
@@ -446,7 +426,7 @@ private String createResourceBase(
446426

447427
applyAuxProps(api, rscName, volName, vmName);
448428

449-
return getDeviceName(api, rscName);
429+
return LinstorUtil.getDevicePath(api, rscName);
450430
} catch (ApiException apiEx)
451431
{
452432
s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
@@ -466,7 +446,7 @@ private String createResource(VolumeInfo vol, StoragePoolVO storagePoolVO) {
466446
{
467447
applyQoSSettings(storagePoolVO, linstorApi, rscName, vol.getMaxIops());
468448

469-
return deviceName;
449+
return LinstorUtil.getDevicePath(linstorApi, rscName);
470450
} catch (ApiException apiEx)
471451
{
472452
s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
@@ -519,7 +499,7 @@ private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolV
519499
applyAuxProps(linstorApi, rscName, volumeInfo.getName(), volumeInfo.getAttachedVmName());
520500
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeInfo.getMaxIops());
521501

522-
return getDeviceName(linstorApi, rscName);
502+
return LinstorUtil.getDevicePath(linstorApi, rscName);
523503
} catch (ApiException apiEx) {
524504
s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
525505
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
@@ -571,7 +551,7 @@ private String createResourceFromSnapshot(long csSnapshotId, String rscName, Sto
571551
applyAuxProps(linstorApi, rscName, volumeVO.getName(), null);
572552
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeVO.getMaxIops());
573553

574-
return getDeviceName(linstorApi, rscName);
554+
return LinstorUtil.getDevicePath(linstorApi, rscName);
575555
} catch (ApiException apiEx) {
576556
s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
577557
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
@@ -940,7 +920,7 @@ private String restoreResourceFromSnapshot(
940920

941921
api.resourceSnapshotRestore(rscName, snapshotName, sr);
942922

943-
return getDeviceName(api, restoredName);
923+
return LinstorUtil.getDevicePath(api, restoredName);
944924
}
945925

946926
private Answer copyTemplate(DataObject srcData, DataObject dstData) {

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,37 @@ public static boolean isResourceInUse(DevelopersApi api, String rscName) throws
202202
s_logger.error("isResourceInUse: null returned from resourceList");
203203
return false;
204204
}
205+
206+
/**
207+
* Try to get the device path for the given resource name.
208+
* This could be made a bit more direct after java-linstor api is fixed for layer data subtypes.
209+
* @param api developer api object to use
210+
* @param rscName resource name to get the device path
211+
* @return The device path of the resource.
212+
* @throws ApiException if Linstor API call failed.
213+
* @throws CloudRuntimeException if no device path could be found.
214+
*/
215+
public static String getDevicePath(DevelopersApi api, String rscName) throws ApiException, CloudRuntimeException {
216+
List<ResourceWithVolumes> resources = api.viewResources(
217+
Collections.emptyList(),
218+
Collections.singletonList(rscName),
219+
Collections.emptyList(),
220+
null,
221+
null,
222+
null);
223+
for (ResourceWithVolumes rsc : resources) {
224+
if (!rsc.getVolumes().isEmpty()) {
225+
// CloudStack resource always only have 1 volume
226+
String devicePath = rsc.getVolumes().get(0).getDevicePath();
227+
if (devicePath != null && !devicePath.isEmpty()) {
228+
s_logger.debug(String.format("getDevicePath: %s -> %s", rscName, devicePath));
229+
return devicePath;
230+
}
231+
}
232+
}
233+
234+
final String errMsg = "viewResources didn't return resources or volumes for " + rscName;
235+
s_logger.error(errMsg);
236+
throw new CloudRuntimeException("Linstor: " + errMsg);
237+
}
205238
}

test/src-not-used/main/java/com/cloud/sample/UserCloudAPIExecutor.java

Lines changed: 0 additions & 188 deletions
This file was deleted.

0 commit comments

Comments
 (0)