Commit 9332fd8a authored by Iustin Pop's avatar Iustin Pop
Browse files

Create symlinks to intances' block devices

This is a forward-port of commit 1148 on the 1.2 branch:
  Change the _GatherBlockDevs private function, called only one time by
  StartInstance, to _GatherAndLinkBlockDevs, and make it transform the
  device returned even more by calling the new _SimlinkBlockDev auxiliary
  function.

  This makes sure that every time an instance is started symlinks to its
  block devices are created, and the instance is started off them, rather
  than the underlying block devices.

  Reviewed-by: iustinp

The changes we make to the patch is related to newer function signatures
in 2.0, and to the fact that iv_name is deprecated and we use instead
disk%d based on the disk index.

Original-Author: ultrotter
parent 069cfbf1
......@@ -733,7 +733,38 @@ def _GetVGInfo(vg_name):
return retdic
def _GatherBlockDevs(instance):
def _SymlinkBlockDev(instance_name, device_path, device_name):
"""Set up symlinks to a instance's block device.
This is an auxiliary function run when an instance is start (on the primary
node) or when an instance is migrated (on the target node).
Args:
instance_name: the name of the target instance
device_path: path of the physical block device, on the node
device_name: 'virtual' name of the device
Returns:
absolute path to the disk's symlink
"""
link_basename = "%s-%s" % (instance_name, device_name)
link_name = os.path.join(constants.DISK_LINKS_DIR, link_basename)
try:
os.symlink(device_path, link_name)
except OSError, e:
if e.errno == errno.EEXIST:
if (not os.path.islink(link_name) or
os.readlink(link_name) != device_path):
os.remove(link_name)
os.symlink(device_path, link_name)
else:
raise
return link_name
def _GatherAndLinkBlockDevs(instance):
"""Set up an instance's block device(s).
This is run on the primary node at instance startup. The block
......@@ -746,13 +777,21 @@ def _GatherBlockDevs(instance):
"""
block_devices = []
for disk in instance.disks:
for idx, disk in enumerate(instance.disks):
device = _RecursiveFindBD(disk)
if device is None:
raise errors.BlockDeviceError("Block device '%s' is not set up." %
str(disk))
device.Open()
block_devices.append((disk, device.dev_path))
try:
link_name = _SymlinkBlockDev(instance.name, device.dev_path,
"disk%d" % idx)
except OSError, e:
raise errors.BlockDeviceError("Cannot create block device symlink: %s" %
e.strerror)
block_devices.append((disk, link_name))
return block_devices
......@@ -770,7 +809,7 @@ def StartInstance(instance, extra_args):
if instance.name in running_instances:
return True
block_devices = _GatherBlockDevs(instance)
block_devices = _GatherAndLinkBlockDevs(instance)
hyper = hypervisor.GetHypervisor(instance.hypervisor)
try:
......
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