Commit 66d3d195 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Thomas Thrainer
Browse files

block_devices = (disk, link, uri)



Do not pass BlockDev instance to hypervisor. Instead calculate the
drive_uri (if any) in backend level and pass only the string to
hypervisor.

Hypervisor should not be aware of the entire block device but only
the final path it can be reached.

This is done also for easy manipulation of block devices inside
runtime files since hotplug support enforces separate entry and
BlockDev is not serializable.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: default avatarThomas Thrainer <thomasth@google.com>
Reviewed-by: default avatarThomas Thrainer <thomasth@google.com>
parent af5db30c
......@@ -1611,6 +1611,28 @@ def _RemoveBlockDevLinks(instance_name, disks):
logging.exception("Can't remove symlink '%s'", link_name)
def _CalculateDeviceURI(instance, disk, device):
"""Get the URI for the device.
@type instance: L{objects.Instance}
@param instance: the instance which disk belongs to
@type disk: L{objects.Disk}
@param disk: the target disk object
@type device: L{bdev.BlockDev}
@param device: the corresponding BlockDevice
@rtype: string
@return: the device uri if any else None
"""
access_mode = disk.params.get(constants.LDP_ACCESS,
constants.DISK_KERNELSPACE)
if access_mode == constants.DISK_USERSPACE:
# This can raise errors.BlockDeviceError
return device.GetUserspaceAccessUri(instance.hypervisor)
else:
return None
def _GatherAndLinkBlockDevs(instance):
"""Set up an instance's block device(s).
......@@ -1620,7 +1642,7 @@ def _GatherAndLinkBlockDevs(instance):
@type instance: L{objects.Instance}
@param instance: the instance whose disks we should assemble
@rtype: list
@return: list of (disk_object, device_path)
@return: list of (disk_object, link_name, drive_uri)
"""
block_devices = []
......@@ -1635,8 +1657,9 @@ def _GatherAndLinkBlockDevs(instance):
except OSError, e:
raise errors.BlockDeviceError("Cannot create block device symlink: %s" %
e.strerror)
uri = _CalculateDeviceURI(instance, disk, device)
block_devices.append((disk, link_name, device))
block_devices.append((disk, link_name, uri))
return block_devices
......
......@@ -1062,7 +1062,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
cache_val = ",cache=%s" % disk_cache
else:
cache_val = ""
for cfdev, dev_path, device in block_devices:
for cfdev, link_name, uri in block_devices:
if cfdev.mode != constants.DISK_RDWR:
raise errors.HypervisorError("Instance has read-only disks which"
" are not supported by KVM")
......@@ -1076,10 +1076,10 @@ class KVMHypervisor(hv_base.BaseHypervisor):
access_mode = cfdev.params.get(constants.LDP_ACCESS,
constants.DISK_KERNELSPACE)
if access_mode == constants.DISK_USERSPACE:
drive_uri = device.GetUserspaceAccessUri(constants.HT_KVM)
if (uri and access_mode == constants.DISK_USERSPACE):
drive_uri = uri
else:
drive_uri = dev_path
drive_uri = link_name
drive_val = "file=%s,format=raw%s%s%s" % \
(drive_uri, if_val, boot_val, cache_val)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment