Skip to content

Commit cc54e44

Browse files
rp-dhslove
authored andcommitted
Linstor: add support for ISO block devices and direct download (apache#9792)
1 parent 1420c76 commit cc54e44

File tree

7 files changed

+165
-88
lines changed

7 files changed

+165
-88
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,6 +3275,17 @@ public String getVolumePath(final Connect conn, final DiskTO volume, boolean dis
32753275
return dataPath;
32763276
}
32773277

3278+
public static boolean useBLOCKDiskType(KVMPhysicalDisk physicalDisk) {
3279+
return physicalDisk != null &&
3280+
physicalDisk.getPool().getType() == StoragePoolType.Linstor &&
3281+
physicalDisk.getFormat() != null &&
3282+
physicalDisk.getFormat()== PhysicalDiskFormat.RAW;
3283+
}
3284+
3285+
public static DiskDef.DiskType getDiskType(KVMPhysicalDisk physicalDisk) {
3286+
return useBLOCKDiskType(physicalDisk) ? DiskDef.DiskType.BLOCK : DiskDef.DiskType.FILE;
3287+
}
3288+
32783289
public void createVbd(final Connect conn, final VirtualMachineTO vmSpec, final String vmName, final LibvirtVMDef vm) throws InternalErrorException, LibvirtException, URISyntaxException {
32793290
final Map<String, String> details = vmSpec.getDetails();
32803291
final List<DiskTO> disks = Arrays.asList(vmSpec.getDisks());
@@ -3320,7 +3331,8 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
33203331
physicalDisk = getPhysicalDiskFromNfsStore(dataStoreUrl, data);
33213332
} else if (primaryDataStoreTO.getPoolType().equals(StoragePoolType.SharedMountPoint) ||
33223333
primaryDataStoreTO.getPoolType().equals(StoragePoolType.Filesystem) ||
3323-
primaryDataStoreTO.getPoolType().equals(StoragePoolType.StorPool)) {
3334+
primaryDataStoreTO.getPoolType().equals(StoragePoolType.StorPool) ||
3335+
primaryDataStoreTO.getPoolType().equals(StoragePoolType.Linstor)) {
33243336
physicalDisk = getPhysicalDiskPrimaryStore(primaryDataStoreTO, data);
33253337
}
33263338
}
@@ -3370,8 +3382,8 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
33703382
final DiskDef disk = new DiskDef();
33713383
int devId = volume.getDiskSeq().intValue();
33723384
if (volume.getType() == Volume.Type.ISO) {
3373-
3374-
disk.defISODisk(volPath, devId, isUefiEnabled);
3385+
final DiskDef.DiskType diskType = getDiskType(physicalDisk);
3386+
disk.defISODisk(volPath, devId, isUefiEnabled, diskType);
33753387

33763388
if (guestCpuArch != null && guestCpuArch.equals("aarch64")) {
33773389
disk.setBusType(DiskDef.DiskBus.SCSI);
@@ -3505,7 +3517,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
35053517

35063518
if (vmSpec.getType() != VirtualMachine.Type.User) {
35073519
final DiskDef iso = new DiskDef();
3508-
iso.defISODisk(sysvmISOPath);
3520+
iso.defISODisk(sysvmISOPath, DiskDef.DiskType.FILE);
35093521
if (guestCpuArch != null && guestCpuArch.equals("aarch64")) {
35103522
iso.setBusType(DiskDef.DiskBus.SCSI);
35113523
}
@@ -3718,7 +3730,7 @@ public void detachAndAttachConfigDriveISO(final Connect conn, final String vmNam
37183730
List<DiskDef> disks = getDisks(conn, vmName);
37193731
DiskDef configdrive = null;
37203732
for (DiskDef disk : disks) {
3721-
if (disk.getDeviceType() == DiskDef.DeviceType.CDROM && disk.getDiskLabel() == CONFIG_DRIVE_ISO_DISK_LABEL) {
3733+
if (disk.getDeviceType() == DiskDef.DeviceType.CDROM && CONFIG_DRIVE_ISO_DISK_LABEL.equals(disk.getDiskLabel())) {
37223734
configdrive = disk;
37233735
}
37243736
}
@@ -3748,19 +3760,20 @@ public synchronized String attachOrDetachISO(final Connect conn, final String vm
37483760
final String name = isoPath.substring(index + 1);
37493761
final KVMStoragePool secondaryPool = storagePoolManager.getStoragePoolByURI(path);
37503762
final KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
3763+
final DiskDef.DiskType diskType = getDiskType(isoVol);
37513764
isoPath = isoVol.getPath();
37523765

3753-
iso.defISODisk(isoPath, diskSeq);
3766+
iso.defISODisk(isoPath, diskSeq, diskType);
37543767
} else {
3755-
iso.defISODisk(null, diskSeq);
3768+
iso.defISODisk(null, diskSeq, DiskDef.DiskType.FILE);
37563769
}
37573770

37583771
final String result = attachOrDetachDevice(conn, true, vmName, iso.toString());
37593772
if (result == null && !isAttach) {
37603773
final List<DiskDef> disks = getDisks(conn, vmName);
37613774
for (final DiskDef disk : disks) {
37623775
if (disk.getDeviceType() == DiskDef.DeviceType.CDROM
3763-
&& (diskSeq == null || disk.getDiskLabel() == iso.getDiskLabel())) {
3776+
&& (diskSeq == null || disk.getDiskLabel().equals(iso.getDiskLabel()))) {
37643777
cleanupDisk(disk);
37653778
}
37663779
}
@@ -4363,7 +4376,7 @@ public String stopVM(final Connect conn, final String vmName, final boolean forc
43634376
return stopVMInternal(conn, vmName, true);
43644377
}
43654378
String ret = stopVMInternal(conn, vmName, false);
4366-
if (ret == Script.ERR_TIMEOUT) {
4379+
if (Script.ERR_TIMEOUT.equals(ret)) {
43674380
ret = stopVMInternal(conn, vmName, true);
43684381
} else if (ret != null) {
43694382
/*

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,10 @@ public boolean parseDomainXML(String domXML) {
127127
}
128128
def.defFileBasedDisk(diskFile, diskLabel, DiskDef.DiskBus.valueOf(bus.toUpperCase()), fmt);
129129
} else if (device.equalsIgnoreCase("cdrom")) {
130-
def.defISODisk(diskFile, i+1, diskLabel);
130+
def.defISODisk(diskFile, i+1, diskLabel, DiskDef.DiskType.FILE);
131131
}
132132
} else if (type.equalsIgnoreCase("block")) {
133-
def.defBlockBasedDisk(diskDev, diskLabel,
134-
DiskDef.DiskBus.valueOf(bus.toUpperCase()));
133+
parseDiskBlock(def, device, diskDev, diskLabel, bus, diskFile, i);
135134
}
136135
if (StringUtils.isNotBlank(diskCacheMode)) {
137136
def.setCacheMode(DiskDef.DiskCacheMode.valueOf(diskCacheMode.toUpperCase()));
@@ -450,6 +449,25 @@ private static String getAttrValue(String tag, String attr, Element eElement) {
450449
return node.getAttribute(attr);
451450
}
452451

452+
/**
453+
* Parse the disk block part of the libvirt XML.
454+
* @param def
455+
* @param device
456+
* @param diskDev
457+
* @param diskLabel
458+
* @param bus
459+
* @param diskFile
460+
* @param curDiskIndex
461+
*/
462+
private void parseDiskBlock(DiskDef def, String device, String diskDev, String diskLabel, String bus,
463+
String diskFile, int curDiskIndex) {
464+
if (device.equalsIgnoreCase("disk")) {
465+
def.defBlockBasedDisk(diskDev, diskLabel, DiskDef.DiskBus.valueOf(bus.toUpperCase()));
466+
} else if (device.equalsIgnoreCase("cdrom")) {
467+
def.defISODisk(diskFile, curDiskIndex+1, diskLabel, DiskDef.DiskType.BLOCK);
468+
}
469+
}
470+
453471
public Integer getVncPort() {
454472
return vncPort;
455473
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,8 @@ public void defFileBasedDisk(String filePath, int devId, DiskFmtType diskFmtType
922922
}
923923
}
924924

925-
public void defISODisk(String volPath) {
926-
_diskType = DiskType.FILE;
925+
public void defISODisk(String volPath, DiskType diskType) {
926+
_diskType = diskType;
927927
_deviceType = DeviceType.CDROM;
928928
_sourcePath = volPath;
929929
_diskLabel = getDevLabel(3, DiskBus.IDE, true);
@@ -932,8 +932,8 @@ public void defISODisk(String volPath) {
932932
_bus = DiskBus.IDE;
933933
}
934934

935-
public void defISODisk(String volPath, boolean isUefiEnabled) {
936-
_diskType = DiskType.FILE;
935+
public void defISODisk(String volPath, boolean isUefiEnabled, DiskType diskType) {
936+
_diskType = diskType;
937937
_deviceType = DeviceType.CDROM;
938938
_sourcePath = volPath;
939939
_bus = isUefiEnabled ? DiskBus.SATA : DiskBus.IDE;
@@ -942,18 +942,18 @@ public void defISODisk(String volPath, boolean isUefiEnabled) {
942942
_diskCacheMode = DiskCacheMode.NONE;
943943
}
944944

945-
public void defISODisk(String volPath, Integer devId) {
946-
defISODisk(volPath, devId, null);
945+
public void defISODisk(String volPath, Integer devId, DiskType diskType) {
946+
defISODisk(volPath, devId, null, diskType);
947947
}
948948

949-
public void defISODisk(String volPath, Integer devId, String diskLabel) {
949+
public void defISODisk(String volPath, Integer devId, String diskLabel, DiskType diskType) {
950950
if (devId == null && StringUtils.isBlank(diskLabel)) {
951951
LOGGER.debug(String.format("No ID or label informed for volume [%s].", volPath));
952-
defISODisk(volPath);
952+
defISODisk(volPath, diskType);
953953
return;
954954
}
955955

956-
_diskType = DiskType.FILE;
956+
_diskType = diskType;
957957
_deviceType = DeviceType.CDROM;
958958
_sourcePath = volPath;
959959

@@ -970,11 +970,11 @@ public void defISODisk(String volPath, Integer devId, String diskLabel) {
970970
_bus = DiskBus.IDE;
971971
}
972972

973-
public void defISODisk(String volPath, Integer devId,boolean isSecure) {
973+
public void defISODisk(String volPath, Integer devId, boolean isSecure, DiskType diskType) {
974974
if (!isSecure) {
975-
defISODisk(volPath, devId);
975+
defISODisk(volPath, devId, diskType);
976976
} else {
977-
_diskType = DiskType.FILE;
977+
_diskType = diskType;
978978
_deviceType = DeviceType.CDROM;
979979
_sourcePath = volPath;
980980
_diskLabel = getDevLabel(devId, DiskBus.SATA, true);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,11 +1141,12 @@ protected synchronized void attachOrDetachISO(final Connect conn, final String v
11411141
storagePool = storagePoolMgr.getStoragePoolByURI(path);
11421142
}
11431143
final KVMPhysicalDisk isoVol = storagePool.getPhysicalDisk(name);
1144+
final DiskDef.DiskType isoDiskType = LibvirtComputingResource.getDiskType(isoVol);
11441145
isoPath = isoVol.getPath();
11451146

1146-
iso.defISODisk(isoPath, isUefiEnabled);
1147+
iso.defISODisk(isoPath, isUefiEnabled, isoDiskType);
11471148
} else {
1148-
iso.defISODisk(null, isUefiEnabled);
1149+
iso.defISODisk(null, isUefiEnabled, DiskDef.DiskType.FILE);
11491150
}
11501151

11511152
final List<DiskDef> disks = resource.getDisks(conn, vmName);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, S
175175
* Checks if downloaded template is extractable
176176
* @return true if it should be extracted, false if not
177177
*/
178-
private boolean isTemplateExtractable(String templatePath) {
178+
public static boolean isTemplateExtractable(String templatePath) {
179179
String type = Script.runSimpleBashScript("file " + templatePath + " | awk -F' ' '{print $2}'");
180180
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip") || type.equalsIgnoreCase("zip");
181181
}
@@ -185,7 +185,7 @@ private boolean isTemplateExtractable(String templatePath) {
185185
* @param downloadedTemplateFile
186186
* @param templateUuid
187187
*/
188-
private String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String templateUuid) {
188+
public static String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String templateUuid) {
189189
if (downloadedTemplateFile.endsWith(".zip")) {
190190
return "unzip -p " + downloadedTemplateFile + " | cat > " + templateUuid;
191191
} else if (downloadedTemplateFile.endsWith(".bz2")) {
@@ -200,7 +200,7 @@ private String getExtractCommandForDownloadedFile(String downloadedTemplateFile,
200200
/**
201201
* Extract downloaded template into installPath, remove compressed file
202202
*/
203-
private void extractDownloadedTemplate(String downloadedTemplateFile, KVMStoragePool destPool, String destinationFile) {
203+
public static void extractDownloadedTemplate(String downloadedTemplateFile, KVMStoragePool destPool, String destinationFile) {
204204
String extractCommand = getExtractCommandForDownloadedFile(downloadedTemplateFile, destinationFile);
205205
Script.runSimpleBashScript(extractCommand);
206206
Script.runSimpleBashScript("rm -f " + downloadedTemplateFile);

plugins/storage/volume/linstor/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Disable discard="unmap" for ide devices and qemu < 7.0
1313
https://bugzilla.redhat.com/show_bug.cgi?id=2029980
1414

15+
## [2024-10-14]
16+
17+
### Added
18+
19+
- Support for ISO direct download to primary storage
20+
1521
## [2024-10-04]
1622

1723
### Added

0 commit comments

Comments
 (0)