Skip to content

Commit 49d3e54

Browse files
committed
linstor: Provide /dev/drbd/by-res/ resource paths to CloudStack
Instead of using the basic /dev/drbd1000 minor number block device path, provide CloudStack with the actual resource path, that can also be linked back to the CloudStack volume.path
1 parent e8200a0 commit 49d3e54

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

plugins/storage/volume/linstor/CHANGELOG.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ All notable changes to Linstor CloudStack plugin will be documented in this file
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [2025-10-03]
8+
## [2025-12-18]
99

1010
### Changed
11+
- Provide /dev/drbd/by-res/ resource paths to CloudStack for usage.
12+
13+
## [2025-10-03]
1114

15+
### Changed
1216
- Revert qcow2 snapshot now use sparse/discard options to convert on thin devices.
1317

1418
## [2025-08-05]
1519

1620
### Fixed
17-
1821
- getVolumeStats wasn't correctly working if multiple Linstor clusters/primary storages are used.
1922

2023
## [2025-07-01]
2124

2225
### Fixed
23-
2426
- Regression in 4.19.3 and 4.21.0 with templates from snapshots
2527

2628
## [2025-05-07]
@@ -31,25 +33,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3133
## [2025-03-13]
3234

3335
### Fixed
34-
3536
- Implemented missing delete datastore, to correctly cleanup on datastore removal
3637

3738
## [2025-02-21]
3839

3940
### Fixed
40-
4141
- Always try to delete cs-...-rst resource before doing a snapshot backup
4242

4343
## [2025-01-27]
4444

4545
### Fixed
46-
4746
- Use of multiple primary storages on the same linstor controller
4847

4948
## [2025-01-20]
5049

5150
### Fixed
52-
5351
- Volume snapshots on zfs used the wrong dataset path to hide/unhide snapdev
5452

5553
## [2024-12-19]
@@ -60,13 +58,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6058
## [2024-12-13]
6159

6260
### Fixed
63-
6461
- Linstor heartbeat check now also ask linstor-controller if there is no connection between nodes
6562

6663
## [2024-12-11]
6764

6865
### Fixed
69-
7066
- Only set allow-two-primaries if a live migration is performed
7167

7268
## [2024-10-28]
@@ -79,17 +75,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7975
## [2024-10-14]
8076

8177
### Added
82-
8378
- Support for ISO direct download to primary storage
8479

8580
## [2024-10-04]
8681

8782
### Added
88-
8983
- Enable qemu discard="unmap" for Linstor block disks
9084

9185
## [2024-08-27]
9286

9387
### Changed
94-
9588
- Allow two primaries(+protocol c) is now set on resource-connection level instead of rd

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, Qemu
232232
makeResourceAvailable(api, foundRscName, false);
233233

234234
if (!resources.isEmpty() && !resources.get(0).getVolumes().isEmpty()) {
235-
final String devPath = resources.get(0).getVolumes().get(0).getDevicePath();
235+
final String devPath = LinstorUtil.getDevicePathFromResource(resources.get(0));
236236
logger.info("Linstor: Created drbd device: " + devPath);
237237
final KVMPhysicalDisk kvmDisk = new KVMPhysicalDisk(devPath, name, pool);
238238
kvmDisk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
@@ -455,8 +455,9 @@ public boolean disconnectPhysicalDisk(Map<String, String> volumeToDisconnect)
455455
private Optional<ResourceWithVolumes> getResourceByPathOrName(
456456
final List<ResourceWithVolumes> resources, String path) {
457457
return resources.stream()
458-
.filter(rsc -> getLinstorRscName(path).equalsIgnoreCase(rsc.getName()) || rsc.getVolumes().stream()
459-
.anyMatch(v -> path.equals(v.getDevicePath())))
458+
.filter(rsc -> getLinstorRscName(path).equalsIgnoreCase(rsc.getName()) ||
459+
path.equals(LinstorUtil.formatDrbdByResDevicePath(rsc.getName())) ||
460+
rsc.getVolumes().stream().anyMatch(v -> path.equals(v.getDevicePath())))
460461
.findFirst();
461462
}
462463

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ public static boolean areResourcesDiskless(DevelopersApi api, String rscName, Co
264264
return false;
265265
}
266266

267+
/**
268+
* Format the device path for DRBD resources.
269+
* @param rscName
270+
* @return
271+
*/
272+
public static String formatDrbdByResDevicePath(String rscName)
273+
{
274+
return String.format("/dev/drbd/by-res/%s/0", rscName);
275+
}
276+
267277
/**
268278
* Try to get the device path for the given resource name.
269279
* This could be made a bit more direct after java-linstor api is fixed for layer data subtypes.
@@ -283,12 +293,7 @@ public static String getDevicePath(DevelopersApi api, String rscName) throws Api
283293
null);
284294
for (ResourceWithVolumes rsc : resources) {
285295
if (!rsc.getVolumes().isEmpty()) {
286-
// CloudStack resource always only have 1 volume
287-
String devicePath = rsc.getVolumes().get(0).getDevicePath();
288-
if (devicePath != null && !devicePath.isEmpty()) {
289-
LOGGER.debug("getDevicePath: {} -> {}", rscName, devicePath);
290-
return devicePath;
291-
}
296+
return LinstorUtil.getDevicePathFromResource(rsc);
292297
}
293298
}
294299

@@ -297,6 +302,24 @@ public static String getDevicePath(DevelopersApi api, String rscName) throws Api
297302
throw new CloudRuntimeException("Linstor: " + errMsg);
298303
}
299304

305+
/**
306+
* Check if the resource has DRBD or not and deliver the correct device path.
307+
* @param rsc
308+
* @return
309+
*/
310+
public static String getDevicePathFromResource(ResourceWithVolumes rsc) {
311+
if (!rsc.getVolumes().isEmpty()) {
312+
// CloudStack resource always only have 1 volume
313+
if (rsc.getLayerObject().getDrbd() != null) {
314+
return formatDrbdByResDevicePath(rsc.getName());
315+
} else {
316+
return rsc.getVolumes().get(0).getDevicePath();
317+
}
318+
}
319+
throw new CloudRuntimeException(
320+
String.format("getDevicePath: Resource %s/%s doesn't have volumes", rsc.getNodeName(), rsc.getName()));
321+
}
322+
300323
public static ApiCallRcList applyAuxProps(DevelopersApi api, String rscName, String dispName, String vmName)
301324
throws ApiException
302325
{

0 commit comments

Comments
 (0)