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):
# be assembled
device = bdev.FindDevice(disk.dev_type, disk.physical_id, clist)
if device is not None:"removing existing device %s", disk)
except errors.BlockDeviceError, err:
device = bdev.Create(disk.dev_type, disk.physical_id,
clist, size)
if device is None:
raise ValueError("Can't create child device for %s, %s" %
(disk, size))
device = bdev.Create(disk.dev_type, disk.physical_id, clist, size)
if on_primary or disk.AssembleOnSecondary():
if not device.Assemble():
errorstring = "Can't assemble device after creation"
......@@ -275,7 +275,8 @@ class LogicalVolume(BlockDev):
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" %
vg_name, lv_name = unique_id
pvs_info = cls.GetPVInfo(vg_name)
if not pvs_info:
......@@ -295,8 +296,8 @@ class LogicalVolume(BlockDev):
result = utils.RunCmd(["lvcreate", "-L%dm" % size, "-n%s" % lv_name,
vg_name] + pvlist)
if result.failed:
raise errors.BlockDeviceError("%s - %s" % (result.fail_reason,
raise errors.BlockDeviceError("LV create failed (%s): %s" %
(result.fail_reason, result.output))
return LogicalVolume(unique_id, children)
......@@ -1646,16 +1647,17 @@ class FileStorage(BlockDev):
@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:
raise ValueError("Invalid configuration data %s" % str(unique_id))
dev_path = unique_id[1]
f = open(dev_path, 'w')
except IOError, err:
raise errors.BlockDeviceError("Could not create '%'" % err)
f.truncate(size * 1024 * 1024)
except IOError, err:
raise errors.BlockDeviceError("Error in file creation: %" % str(err))
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