From 1d5f1b4c8fc9468a3b67055620de25e88246f057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com> Date: Fri, 7 Jan 2011 14:24:04 +0100 Subject: [PATCH] Pause/Resume sync accordingly before wiping disk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RenΓ© Nussbaumer <rn@google.com> Reviewed-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/cmdlib.py | 72 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 8bd8b1583..8738be06b 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -6527,32 +6527,52 @@ def _WipeDisks(lu, instance): """ node = instance.primary_node - for idx, device in enumerate(instance.disks): - lu.LogInfo("* Wiping disk %d", idx) - logging.info("Wiping disk %d for instance %s", idx, instance.name) - - # The wipe size is MIN_WIPE_CHUNK_PERCENT % of the instance disk but - # MAX_WIPE_CHUNK at max - wipe_chunk_size = min(constants.MAX_WIPE_CHUNK, device.size / 100.0 * - constants.MIN_WIPE_CHUNK_PERCENT) - - offset = 0 - size = device.size - last_output = 0 - start_time = time.time() - - while offset < size: - wipe_size = min(wipe_chunk_size, size - offset) - result = lu.rpc.call_blockdev_wipe(node, device, offset, wipe_size) - result.Raise("Could not wipe disk %d at offset %d for size %d" % - (idx, offset, wipe_size)) - now = time.time() - offset += wipe_size - if now - last_output >= 60: - eta = _CalcEta(now - start_time, offset, size) - lu.LogInfo(" - done: %.1f%% ETA: %s" % - (offset / float(size) * 100, utils.FormatSeconds(eta))) - last_output = now + logging.info("Pause sync of instance %s disks", instance.name) + result = lu.rpc.call_blockdev_pause_resume_sync(node, instance.disks, True) + + for idx, success in enumerate(result.payload): + if not success: + logging.warn("pause-sync of instance %s for disks %d failed", + instance.name, idx) + + try: + for idx, device in enumerate(instance.disks): + lu.LogInfo("* Wiping disk %d", idx) + logging.info("Wiping disk %d for instance %s", idx, instance.name) + + # The wipe size is MIN_WIPE_CHUNK_PERCENT % of the instance disk but + # MAX_WIPE_CHUNK at max + wipe_chunk_size = min(constants.MAX_WIPE_CHUNK, device.size / 100.0 * + constants.MIN_WIPE_CHUNK_PERCENT) + + offset = 0 + size = device.size + last_output = 0 + start_time = time.time() + + while offset < size: + wipe_size = min(wipe_chunk_size, size - offset) + result = lu.rpc.call_blockdev_wipe(node, device, offset, wipe_size) + result.Raise("Could not wipe disk %d at offset %d for size %d" % + (idx, offset, wipe_size)) + now = time.time() + offset += wipe_size + if now - last_output >= 60: + eta = _CalcEta(now - start_time, offset, size) + lu.LogInfo(" - done: %.1f%% ETA: %s" % + (offset / float(size) * 100, utils.FormatSeconds(eta))) + last_output = now + finally: + logging.info("Resume sync of instance %s disks", instance.name) + + result = lu.rpc.call_blockdev_pause_resume_sync(node, instance.disks, False) + + for idx, success in enumerate(result.payload): + if not success: + lu.LogWarning("Warning: Resume sync of disk %d failed. Please have a" + " look at the status and troubleshoot the issue.", idx) + logging.warn("resume-sync of instance %s for disks %d failed", + instance.name, idx) def _CreateDisks(lu, instance, to_skip=None, target_node=None): -- GitLab