Commit da63bb4e authored by René Nussbaumer's avatar René Nussbaumer
Browse files

Second iteration over backend.BlockdevWipe



This patch now uses dd entirely to wipe the disk, make it
much easier to wipe in blocks so we can give interactive feedback
about the status.
Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent f2165b8a
......@@ -1287,32 +1287,50 @@ def BlockdevCreate(disk, size, owner, on_primary, info):
return device.unique_id
def _WipeDevice(path):
def _WipeDevice(path, offset, size):
"""This function actually wipes the device.
@param path: The path to the device to wipe
@param offset: The offset in MiB in the file
@param size: The size in MiB to write
"""
result = utils.RunCmd("%s%s" % (constants.WIPE_CMD, utils.ShellQuote(path)))
cmd = [constants.DD_CMD, "if=/dev/zero", "seek=%d" % offset,
"bs=%d" % constants.WIPE_BLOCK_SIZE, "oflag=direct", "of=%s" % path,
"count=%d" % size]
result = utils.RunCmd(cmd)
if result.failed:
_Fail("Wipe command '%s' exited with error: %s; output: %s", result.cmd,
result.fail_reason, result.output)
def BlockdevWipe(disk):
def BlockdevWipe(disk, offset, size):
"""Wipes a block device.
@type disk: L{objects.Disk}
@param disk: the disk object we want to wipe
@type offset: int
@param offset: The offset in MiB in the file
@type size: int
@param size: The size in MiB to write
"""
try:
rdev = _RecursiveFindBD(disk)
except errors.BlockDeviceError, err:
_Fail("Cannot execute wipe for device %s: device not found", err)
except errors.BlockDeviceError:
rdev = None
if not rdev:
_Fail("Cannot execute wipe for device %s: device not found", disk.iv_name)
# Do cross verify some of the parameters
if offset > rdev.size:
_Fail("Offset is bigger than device size")
if (offset + size) > rdev.size:
_Fail("The provided offset and size to wipe is bigger than device size")
_WipeDevice(rdev.dev_path)
_WipeDevice(rdev.dev_path, offset, size)
def BlockdevRemove(disk):
......
......@@ -96,7 +96,8 @@ CONFD_GROUP = _autoconf.CONFD_GROUP
NODED_USER = _autoconf.NODED_USER
# Wipe
WIPE_CMD = _autoconf.WIPE_CMD
DD_CMD = "dd"
WIPE_BLOCK_SIZE = 1024**2
# file paths
DATA_DIR = _autoconf.LOCALSTATEDIR + "/lib/ganeti"
......
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