[libvirt] [PATCH v2 0/2] Detect misconfiguration between disk bus and disk address

This patch series adds the functionality to detect a misconfiguration between disk bus type and disk address type for disks that are using the address type virDomainDeviceDriveAddress. It also adds a test for it. A check for other bus types may be needed. This may require a driver specific function, as it is already implemented in virDomainDeviceDefPostParse(), for example. Changelog: - v1 -> v2: + Use full enumeration of the bus types + Add warning for unexpected bus type Marc Hartmayer (2): conf: Detect misconfiguration between disk bus and disk address tests: Add tests for disk configuration validation src/conf/domain_conf.c | 56 ++++++++++++++++++++++ .../qemuxml2argv-disk-fdc-incompatible-address.xml | 22 +++++++++ .../qemuxml2argv-disk-ide-incompatible-address.xml | 23 +++++++++ ...qemuxml2argv-disk-sata-incompatible-address.xml | 23 +++++++++ ...qemuxml2argv-disk-scsi-incompatible-address.xml | 24 ++++++++++ tests/qemuxml2argvtest.c | 8 ++++ 6 files changed, 156 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-fdc-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-ide-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-sata-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-incompatible-address.xml -- 2.5.5

This patch detects a misconfiguration between the disk bus type and disk address type for controller based disk buses (SATA, SCSI, FDC and IDE). The addresses of these bus types are all managed in common code so it's possible to decide in common code whether the disk address and bus type are compatible or not. Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com> Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com> --- src/conf/domain_conf.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5d2bc8d..0481499 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4672,6 +4672,48 @@ virDomainDefPostParse(virDomainDefPtr def, } +/** + * virDomainDiskAddressDiskBusCompatibility: + * @bus: disk bus type + * @addressType: disk address type + * + * Check if the specified disk address type @addressType is compatible + * with the specified disk bus type @bus. This function checks + * compatibility with the bus types SATA, SCSI, FDC, and IDE only, + * because only these are handled in common code. + * + * Returns true if compatible or can't be decided in common code, + * false if known to be not compatible. + */ +static bool +virDomainDiskAddressDiskBusCompatibility(virDomainDiskBus bus, + virDomainDeviceAddressType addressType) +{ + if (addressType == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) + return true; + + switch (bus) { + case VIR_DOMAIN_DISK_BUS_IDE: + case VIR_DOMAIN_DISK_BUS_FDC: + case VIR_DOMAIN_DISK_BUS_SCSI: + case VIR_DOMAIN_DISK_BUS_SATA: + return addressType == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE; + case VIR_DOMAIN_DISK_BUS_VIRTIO: + case VIR_DOMAIN_DISK_BUS_XEN: + case VIR_DOMAIN_DISK_BUS_USB: + case VIR_DOMAIN_DISK_BUS_UML: + case VIR_DOMAIN_DISK_BUS_SD: + case VIR_DOMAIN_DISK_BUS_LAST: + return true; + } + + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unexpected bus type '%d'"), + bus); + return true; +} + + static int virDomainDiskDefValidate(const virDomainDiskDef *disk) { @@ -4689,6 +4731,20 @@ virDomainDiskDefValidate(const virDomainDiskDef *disk) } } + /* Reject disks with a bus type that is not compatible with the + * given address type. The function considers only buses that are + * handled in common code. For other bus types it's not possible + * to decide compatibility in common code. + */ + if (!virDomainDiskAddressDiskBusCompatibility(disk->bus, disk->info.type)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Invalid address type '%s' for the disk '%s' with the bus type '%s'"), + virDomainDeviceAddressTypeToString(disk->info.type), + disk->dst, + virDomainDiskBusTypeToString(disk->bus)); + return -1; + } + return 0; } -- 2.5.5

Add tests for controller based disks to check disk address compatibility with disk bus types. Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com> Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com> Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com> --- .../qemuxml2argv-disk-fdc-incompatible-address.xml | 22 ++++++++++++++++++++ .../qemuxml2argv-disk-ide-incompatible-address.xml | 23 +++++++++++++++++++++ ...qemuxml2argv-disk-sata-incompatible-address.xml | 23 +++++++++++++++++++++ ...qemuxml2argv-disk-scsi-incompatible-address.xml | 24 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 8 ++++++++ 5 files changed, 100 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-fdc-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-ide-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-sata-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-incompatible-address.xml diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-fdc-incompatible-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-fdc-incompatible-address.xml new file mode 100644 index 0000000..f4aa6d5 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-fdc-incompatible-address.xml @@ -0,0 +1,22 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='fd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='floppy'> + <source dev='/dev/fd0'/> + <target dev='fda' bus='fdc'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </disk> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-incompatible-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-incompatible-address.xml new file mode 100644 index 0000000..9c2c887 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-ide-incompatible-address.xml @@ -0,0 +1,23 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </disk> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-sata-incompatible-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-sata-incompatible-address.xml new file mode 100644 index 0000000..239e12b --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-sata-incompatible-address.xml @@ -0,0 +1,23 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='sda' bus='sata'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </disk> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-incompatible-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-incompatible-address.xml new file mode 100644 index 0000000..45b41da --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-incompatible-address.xml @@ -0,0 +1,24 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='sda' bus='scsi'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </disk> + <controller type='scsi' index='0' model='virtio-scsi'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 8d1bdb7..fe12ac1 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -987,6 +987,14 @@ mymain(void) DO_TEST("disk-serial", QEMU_CAPS_KVM, QEMU_CAPS_DRIVE_SERIAL); + DO_TEST_PARSE_ERROR("disk-fdc-incompatible-address", + NONE); + DO_TEST_PARSE_ERROR("disk-ide-incompatible-address", + NONE); + DO_TEST_PARSE_ERROR("disk-sata-incompatible-address", + QEMU_CAPS_ICH9_AHCI); + DO_TEST_PARSE_ERROR("disk-scsi-incompatible-address", + QEMU_CAPS_VIRTIO_SCSI); DO_TEST("graphics-vnc", QEMU_CAPS_VNC, QEMU_CAPS_DEVICE_CIRRUS_VGA); DO_TEST("graphics-vnc-socket", QEMU_CAPS_VNC, QEMU_CAPS_DEVICE_CIRRUS_VGA); -- 2.5.5

Seasonal ping... On 11/29/2016 01:11 PM, Marc Hartmayer wrote:
This patch series adds the functionality to detect a misconfiguration between disk bus type and disk address type for disks that are using the address type virDomainDeviceDriveAddress. It also adds a test for it.
A check for other bus types may be needed. This may require a driver specific function, as it is already implemented in virDomainDeviceDefPostParse(), for example.
Changelog: - v1 -> v2: + Use full enumeration of the bus types + Add warning for unexpected bus type
Marc Hartmayer (2): conf: Detect misconfiguration between disk bus and disk address tests: Add tests for disk configuration validation
src/conf/domain_conf.c | 56 ++++++++++++++++++++++ .../qemuxml2argv-disk-fdc-incompatible-address.xml | 22 +++++++++ .../qemuxml2argv-disk-ide-incompatible-address.xml | 23 +++++++++ ...qemuxml2argv-disk-sata-incompatible-address.xml | 23 +++++++++ ...qemuxml2argv-disk-scsi-incompatible-address.xml | 24 ++++++++++ tests/qemuxml2argvtest.c | 8 ++++ 6 files changed, 156 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-fdc-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-ide-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-sata-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-incompatible-address.xml
-- Mit freundlichen Grüßen/Kind regards Boris Fiuczynski IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martina Köderitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294

On 29.11.2016 13:11, Marc Hartmayer wrote:
This patch series adds the functionality to detect a misconfiguration between disk bus type and disk address type for disks that are using the address type virDomainDeviceDriveAddress. It also adds a test for it.
A check for other bus types may be needed. This may require a driver specific function, as it is already implemented in virDomainDeviceDefPostParse(), for example.
Changelog: - v1 -> v2: + Use full enumeration of the bus types + Add warning for unexpected bus type
Marc Hartmayer (2): conf: Detect misconfiguration between disk bus and disk address tests: Add tests for disk configuration validation
src/conf/domain_conf.c | 56 ++++++++++++++++++++++ .../qemuxml2argv-disk-fdc-incompatible-address.xml | 22 +++++++++ .../qemuxml2argv-disk-ide-incompatible-address.xml | 23 +++++++++ ...qemuxml2argv-disk-sata-incompatible-address.xml | 23 +++++++++ ...qemuxml2argv-disk-scsi-incompatible-address.xml | 24 ++++++++++ tests/qemuxml2argvtest.c | 8 ++++ 6 files changed, 156 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-fdc-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-ide-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-sata-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-incompatible-address.xml
ACKed and pushed. Michal

On Tue, Dec 20, 2016 at 11:54 AM +0100, Michal Privoznik <mprivozn@redhat.com> wrote:
On 29.11.2016 13:11, Marc Hartmayer wrote:
This patch series adds the functionality to detect a misconfiguration between disk bus type and disk address type for disks that are using the address type virDomainDeviceDriveAddress. It also adds a test for it.
A check for other bus types may be needed. This may require a driver specific function, as it is already implemented in virDomainDeviceDefPostParse(), for example.
Changelog: - v1 -> v2: + Use full enumeration of the bus types + Add warning for unexpected bus type
Marc Hartmayer (2): conf: Detect misconfiguration between disk bus and disk address tests: Add tests for disk configuration validation
src/conf/domain_conf.c | 56 ++++++++++++++++++++++ .../qemuxml2argv-disk-fdc-incompatible-address.xml | 22 +++++++++ .../qemuxml2argv-disk-ide-incompatible-address.xml | 23 +++++++++ ...qemuxml2argv-disk-sata-incompatible-address.xml | 23 +++++++++ ...qemuxml2argv-disk-scsi-incompatible-address.xml | 24 ++++++++++ tests/qemuxml2argvtest.c | 8 ++++ 6 files changed, 156 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-fdc-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-ide-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-sata-incompatible-address.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-incompatible-address.xml
ACKed and pushed.
Michal
Thanks. -- Beste Grüße / Kind regards Marc Hartmayer IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294

[Added Roman to CC] On Tue, 2016-12-20 at 11:54 +0100, Michal Privoznik wrote:
This patch series adds the functionality to detect a misconfiguration between disk bus type and disk address type for disks that are using the address type virDomainDeviceDriveAddress. It also adds a test for it. A check for other bus types may be needed. This may require a driver specific function, as it is already implemented in virDomainDeviceDefPostParse(), for example. Changelog: - v1 -> v2: + Use full enumeration of the bus types + Add warning for unexpected bus type Marc Hartmayer (2): conf: Detect misconfiguration between disk bus and disk address tests: Add tests for disk configuration validation ACKed and pushed.
This seems to have broken the bhyve driver: $ VIR_TEST_DEBUG=1 ./tests/bhyvexml2argvtest TEST: bhyvexml2argvtest 1) BHYVE XML-2-ARGV base ... libvirt: Domain Config error : unsupported configuration: Invalid address type 'pci' for the disk 'hda' with the bus type 'sata' FAILED ... -- Andrea Bolognani / Red Hat / Virtualization

On Thu, Dec 22, 2016 at 07:22 PM +0100, Andrea Bolognani <abologna@redhat.com> wrote:
[Added Roman to CC]
On Tue, 2016-12-20 at 11:54 +0100, Michal Privoznik wrote:
This patch series adds the functionality to detect a misconfiguration between disk bus type and disk address type for disks that are using the address type virDomainDeviceDriveAddress. It also adds a test for it.
A check for other bus types may be needed. This may require a driver specific function, as it is already implemented in virDomainDeviceDefPostParse(), for example.
Changelog: - v1 -> v2: + Use full enumeration of the bus types + Add warning for unexpected bus type
Marc Hartmayer (2): conf: Detect misconfiguration between disk bus and disk address tests: Add tests for disk configuration validation
ACKed and pushed.
This seems to have broken the bhyve driver:
$ VIR_TEST_DEBUG=1 ./tests/bhyvexml2argvtest TEST: bhyvexml2argvtest 1) BHYVE XML-2-ARGV base ... libvirt: Domain Config error : unsupported configuration: Invalid address type 'pci' for the disk 'hda' with the bus type 'sata' FAILED ...
-- Andrea Bolognani / Red Hat / Virtualization
Ooops, sry for that :/ As far as I've read, Roman has already created a new way for the bhyve SATA address allocation in libvirt (thread mid:20170105144634.28675-1-bogorodskiy@gmail.com) -- Beste Grüße / Kind regards Marc Hartmayer IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
participants (4)
-
Andrea Bolognani
-
Boris Fiuczynski
-
Marc Hartmayer
-
Michal Privoznik