libvirt-xen: Fix block device prefix and disk bus.

For a disk on a Xen guest, sda and xvda are not interchangeable. A "xen"
disk bus indicates a PV disk, and the prefix for it is xvdX.

An "ide" disk can not work with a Xen PV guest, so the function
get_disk_bus_for_device_type is made aware of the kind of guest and will
return the right disk bus, "ide" for an HVM guest, and "xen" for a PV
guest.

Change-Id: I0617151a30c2b1825938a0bd1978aae4cdbef1df
This commit is contained in:
Anthony PERARD 2014-11-24 17:12:50 +00:00
parent e4d4283119
commit 91dcdb5c6c
2 changed files with 16 additions and 10 deletions

View File

@ -5459,7 +5459,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
'xen': [
(lambda t: t.find('.').get('type'), 'xen'),
(lambda t: t.find('./devices/disk/target').get('dev'),
_get_prefix(prefix, 'sda'))],
_get_prefix(prefix, 'xvda'))],
'kvm': [
(lambda t: t.find('.').get('type'), 'kvm'),
(lambda t: t.find('./devices/disk/target').get('dev'),

View File

@ -76,6 +76,7 @@ from oslo.config import cfg
from nova import block_device
from nova.compute import arch
from nova.compute import vm_mode
from nova import exception
from nova.i18n import _
from nova.objects import base as obj_base
@ -127,9 +128,7 @@ def get_dev_prefix_for_disk_bus(disk_bus):
elif disk_bus == "virtio":
return "vd"
elif disk_bus == "xen":
# Two possible mappings for Xen, xvda or sda
# which are interchangeable, so we pick sda
return "sd"
return "xvd"
elif disk_bus == "scsi":
return "sd"
elif disk_bus == "usb":
@ -214,7 +213,8 @@ def is_disk_bus_valid_for_virt(virt_type, disk_bus):
def get_disk_bus_for_device_type(virt_type,
image_meta,
device_type="disk"):
device_type="disk",
instance=None):
"""Determine the best disk bus to use for a device type.
Considering the currently configured virtualization
@ -243,9 +243,12 @@ def get_disk_bus_for_device_type(virt_type,
elif virt_type == "lxc":
return "lxc"
elif virt_type == "xen":
if device_type == "cdrom":
guest_vm_mode = None
if instance:
guest_vm_mode = vm_mode.get_from_instance(instance)
if guest_vm_mode == vm_mode.HVM:
return "ide"
elif device_type == "disk":
else:
return "xen"
elif virt_type in ("qemu", "kvm"):
if device_type == "cdrom":
@ -589,7 +592,8 @@ def get_disk_mapping(virt_type, instance,
device_type = get_config_drive_type()
disk_bus = get_disk_bus_for_device_type(virt_type,
image_meta,
device_type)
device_type,
instance=instance)
config_info = get_next_disk_info(mapping,
disk_bus,
device_type,
@ -614,8 +618,10 @@ def get_disk_info(virt_type, instance, image_meta,
Returns the disk mapping disk.
"""
disk_bus = get_disk_bus_for_device_type(virt_type, image_meta, "disk")
cdrom_bus = get_disk_bus_for_device_type(virt_type, image_meta, "cdrom")
disk_bus = get_disk_bus_for_device_type(virt_type, image_meta, "disk",
instance=instance)
cdrom_bus = get_disk_bus_for_device_type(virt_type, image_meta, "cdrom",
instance=instance)
mapping = get_disk_mapping(virt_type, instance,
disk_bus, cdrom_bus,
image_meta,