Commit 6c626518 authored by Iustin Pop's avatar Iustin Pop
Browse files

Block device creation cleanup

Currently when creation LVM-based instances, we always get the
extremely-confusing message "ERROR Can't find LV /dev/xenvg/..." which
is actually expected. This behaviour was introduced before we had
UUID-style LV names, since at that point it was not a unexpected to have
such volumes laying around after a failed creation.

Today, it's much more of an error to see existing volumes, and it's
better to abort with a failure. Since bdev.LogicalVolume.Create() method
will raise an error in case it exists, we can remove this check in
backend before creating the device.

The Create methods for DRBD and FileStorage currently don't raise
exception, as behaviour is not very well defined here.

We also change some exception types raised in bdev so that all
exceptions raised by device creation are a subclass of GenericError.

Reviewed-by: ultrotter
parent e6c1ff2f
...@@ -1016,19 +1016,9 @@ def CreateBlockDevice(disk, size, owner, on_primary, info): ...@@ -1016,19 +1016,9 @@ def CreateBlockDevice(disk, size, owner, on_primary, info):
# be assembled # be assembled
crdev.Open() crdev.Open()
clist.append(crdev) clist.append(crdev)
try:
device = bdev.FindDevice(disk.dev_type, disk.physical_id, clist)
if device is not None:
logging.info("removing existing device %s", disk)
device.Remove()
except errors.BlockDeviceError, err:
pass
device = bdev.Create(disk.dev_type, disk.physical_id, device = bdev.Create(disk.dev_type, disk.physical_id, clist, size)
clist, size)
if device is None:
raise ValueError("Can't create child device for %s, %s" %
(disk, size))
if on_primary or disk.AssembleOnSecondary(): if on_primary or disk.AssembleOnSecondary():
if not device.Assemble(): if not device.Assemble():
errorstring = "Can't assemble device after creation" errorstring = "Can't assemble device after creation"
......
...@@ -275,7 +275,8 @@ class LogicalVolume(BlockDev): ...@@ -275,7 +275,8 @@ class LogicalVolume(BlockDev):
""" """
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2: if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
raise ValueError("Invalid configuration data %s" % str(unique_id)) raise errors.ProgrammerError("Invalid configuration data %s" %
str(unique_id))
vg_name, lv_name = unique_id vg_name, lv_name = unique_id
pvs_info = cls.GetPVInfo(vg_name) pvs_info = cls.GetPVInfo(vg_name)
if not pvs_info: if not pvs_info:
...@@ -295,8 +296,8 @@ class LogicalVolume(BlockDev): ...@@ -295,8 +296,8 @@ class LogicalVolume(BlockDev):
result = utils.RunCmd(["lvcreate", "-L%dm" % size, "-n%s" % lv_name, result = utils.RunCmd(["lvcreate", "-L%dm" % size, "-n%s" % lv_name,
vg_name] + pvlist) vg_name] + pvlist)
if result.failed: if result.failed:
raise errors.BlockDeviceError("%s - %s" % (result.fail_reason, raise errors.BlockDeviceError("LV create failed (%s): %s" %
result.output)) (result.fail_reason, result.output))
return LogicalVolume(unique_id, children) return LogicalVolume(unique_id, children)
@staticmethod @staticmethod
...@@ -1646,16 +1647,17 @@ class FileStorage(BlockDev): ...@@ -1646,16 +1647,17 @@ class FileStorage(BlockDev):
@return: an instance of FileStorage @return: an instance of FileStorage
""" """
# TODO: decide whether we should check for existing files and
# abort or not
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2: if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
raise ValueError("Invalid configuration data %s" % str(unique_id)) raise ValueError("Invalid configuration data %s" % str(unique_id))
dev_path = unique_id[1] dev_path = unique_id[1]
try: try:
f = open(dev_path, 'w') f = open(dev_path, 'w')
except IOError, err:
raise errors.BlockDeviceError("Could not create '%'" % err)
else:
f.truncate(size * 1024 * 1024) f.truncate(size * 1024 * 1024)
f.close() f.close()
except IOError, err:
raise errors.BlockDeviceError("Error in file creation: %" % str(err))
return FileStorage(unique_id, children) return FileStorage(unique_id, children)
......
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