summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorManuel Bentele2021-09-10 08:12:14 +0200
committerManuel Bentele2021-09-10 08:12:14 +0200
commitddfa85ff602109524ecf057ab1c61a89d3c404c3 (patch)
tree24bcf7fa4ee03209bc6f30226153342c8b007d56 /core
parent[dhcpc-busybox] Use gawk (diff)
downloadmltk-ddfa85ff602109524ecf057ab1c61a89d3c404c3.tar.gz
mltk-ddfa85ff602109524ecf057ab1c61a89d3c404c3.tar.xz
mltk-ddfa85ff602109524ecf057ab1c61a89d3c404c3.zip
[qemu] Fix invalid disk storage type for CDROMs
Diffstat (limited to 'core')
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericDiskCdromDevices.java67
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericDiskCdromDevicesTest.java2
-rw-r--r--core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java4
3 files changed, 53 insertions, 20 deletions
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericDiskCdromDevices.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericDiskCdromDevices.java
index 643c40ed..64b279de 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericDiskCdromDevices.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericDiskCdromDevices.java
@@ -1,5 +1,10 @@
package org.openslx.runvirt.plugin.qemu.configuration;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import org.openslx.libvirt.domain.Domain;
@@ -48,6 +53,49 @@ public class TransformationGenericDiskCdromDevices extends TransformationGeneric
}
/**
+ * Sets the storage of a CDROM drive from a virtualization configuration.
+ *
+ * @param disk CDROM drive from a virtualization configuration.
+ * @param fileName path to a storage that is set for the specified CDROM drive (e.g. block device
+ * or image)
+ */
+ private void setDiskCdromStorage( DiskCdrom disk, String fileName )
+ {
+ if ( fileName == null ) {
+ // remove disk storage device if disk image file name is not set
+ disk.remove();
+ } else if ( fileName.isEmpty() ) {
+ // remove storage source if empty string is specified to emulate an empty CDROM drive
+ disk.removeStorage();
+ } else {
+ // set disk image file as storage source of the disk CDROM drive
+ // check before, whether the referenced file is a regular file or a block device file
+ final Path diskFilePath = Paths.get( fileName );
+ BasicFileAttributes diskFileAttrs = null;
+
+ // get file attributes from referenced file
+ try {
+ diskFileAttrs = Files.readAttributes( diskFilePath, BasicFileAttributes.class );
+ } catch ( IOException e ) {
+ diskFileAttrs = null;
+ }
+
+ // set storage type according to the file attributes of the referenced file
+ if ( diskFileAttrs != null ) {
+ if ( diskFileAttrs.isOther() && !diskFileAttrs.isRegularFile() ) {
+ // referenced file is a block device file
+ // set block device storage type
+ disk.setStorage( StorageType.BLOCK, fileName );
+ } else {
+ // referenced file is a regular file
+ // set file storage type
+ disk.setStorage( StorageType.FILE, fileName );
+ }
+ }
+ }
+ }
+
+ /**
* Transforms a CDROM drive in a virtualization configuration selected by its {@code index}.
*
* @param config virtualization configuration for the transformation.
@@ -68,26 +116,11 @@ public class TransformationGenericDiskCdromDevices extends TransformationGeneric
String targetDevName = VirtualizationConfigurationQemuUtils.createAlphabeticalDeviceName( "sd", index );
newDisk.setTargetDevice( targetDevName );
- if ( fileName.isEmpty() ) {
- // remove storage source if empty string is specified to emulate an empty CDROM drive
- newDisk.removeStorage();
- } else {
- // set disk image file as storage source of the disk CDROM drive
- newDisk.setStorage( StorageType.FILE, fileName );
- }
+ this.setDiskCdromStorage( newDisk, fileName );
}
} else {
// CDROM drive exists, so update existing CDROM drive
- if ( fileName == null ) {
- // remove disk storage device if disk image file name is not set
- disk.remove();
- } else if ( fileName.isEmpty() ) {
- // remove storage source if empty string is specified to emulate an empty CDROM drive
- disk.removeStorage();
- } else {
- // set disk image file as storage source of the disk CDROM drive
- disk.setStorage( StorageType.FILE, fileName );
- }
+ this.setDiskCdromStorage( disk, fileName );
}
}
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericDiskCdromDevicesTest.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericDiskCdromDevicesTest.java
index 73b37c36..012f132c 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericDiskCdromDevicesTest.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericDiskCdromDevicesTest.java
@@ -36,7 +36,7 @@ public class TransformationGenericDiskCdromDevicesTest
assertEquals( 2, devicesAfterTransformation.size() );
final DiskCdrom cdromDevice1AfterTransformation = devicesAfterTransformation.get( 0 );
final DiskCdrom cdromDevice2AfterTransformation = devicesAfterTransformation.get( 1 );
- assertEquals( StorageType.FILE, cdromDevice1AfterTransformation.getStorageType() );
+ assertEquals( StorageType.BLOCK, cdromDevice1AfterTransformation.getStorageType() );
assertEquals( TransformationTestUtils.DEFAULT_VM_CDROM0, cdromDevice1AfterTransformation.getStorageSource() );
assertEquals( StorageType.FILE, cdromDevice2AfterTransformation.getStorageType() );
assertEquals( TransformationTestUtils.DEFAULT_VM_CDROM1, cdromDevice2AfterTransformation.getStorageSource() );
diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java
index fe4d4596..2a811f2a 100644
--- a/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java
+++ b/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationTestUtils.java
@@ -24,8 +24,8 @@ public class TransformationTestUtils
public static final String DEFAULT_VM_HDD0 = "/mnt/vm/windows.qcow2";
public static final String DEFAULT_VM_FLOPPY0 = "/mnt/vm/floppy0.qcow2";
public static final String DEFAULT_VM_FLOPPY1 = "/mnt/vm/floppy1.qcow2";
- public static final String DEFAULT_VM_CDROM0 = "/dev/sr0";
- public static final String DEFAULT_VM_CDROM1 = "/mnt/vm/cdrom1.qcow2";
+ public static final String DEFAULT_VM_CDROM0 = "/dev/mem";
+ public static final String DEFAULT_VM_CDROM1 = "/etc/passwd";
public static final String DEFAULT_VM_PARALLEL0 = "/dev/parport0";
public static final String DEFAULT_VM_SERIAL0 = "/dev/ttyS0";
public static final String DEFAULT_VM_MAC0 = "ca:06:29:84:f0:6d";