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. --- lib/backend.py | 28 ++++++++++++++++++++++------ lib/constants.py | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/lib/backend.py b/lib/backend.py index 8abe5a6..1edccae 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -1287,32 +1287,48 @@ 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 = ["dd", "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 + assert(offset <= rdev.size) + assert(offset + size <= rdev.size) - _WipeDevice(rdev.dev_path) + _WipeDevice(rdev.dev_path, offset, size) def BlockdevRemove(disk): diff --git a/lib/constants.py b/lib/constants.py index b66b6eb..8529295 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -96,7 +96,7 @@ CONFD_GROUP = _autoconf.CONFD_GROUP NODED_USER = _autoconf.NODED_USER # Wipe -WIPE_CMD = _autoconf.WIPE_CMD +WIPE_BLOCK_SIZE = 1024**2 # file paths DATA_DIR = _autoconf.LOCALSTATEDIR + "/lib/ganeti" -- 1.7.1