From b4ec07f86bf3e9cc58aa8593a0b9dbad8ba0a54f Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Sun, 26 Jul 2009 21:35:10 +0200
Subject: [PATCH] Implement --ignore-size in activate-disks

This patch modified OpActivateDisks, LUActivateDisks and gnt-instance
activate-disks to support and pass this option to
_AssembleInstanceDisks.

The patch is quite trivial I think; there should be no issues from it
except if used when not needed.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/cmdlib.py         |  6 +++++-
 lib/opcodes.py        |  2 +-
 man/gnt-instance.sgml | 11 +++++++++++
 scripts/gnt-instance  | 12 ++++++++++--
 4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 846ef0e2f..e57f00ada 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -2592,12 +2592,16 @@ class LUActivateInstanceDisks(NoHooksLU):
     assert self.instance is not None, \
       "Cannot retrieve locked instance %s" % self.op.instance_name
     _CheckNodeOnline(self, self.instance.primary_node)
+    if not hasattr(self.op, "ignore_size"):
+      self.op.ignore_size = False
 
   def Exec(self, feedback_fn):
     """Activate the disks.
 
     """
-    disks_ok, disks_info = _AssembleInstanceDisks(self, self.instance)
+    disks_ok, disks_info = \
+              _AssembleInstanceDisks(self, self.instance,
+                                     ignore_size=self.op.ignore_size)
     if not disks_ok:
       raise errors.OpExecError("Cannot activate block devices")
 
diff --git a/lib/opcodes.py b/lib/opcodes.py
index 535db910d..e19ad6edd 100644
--- a/lib/opcodes.py
+++ b/lib/opcodes.py
@@ -438,7 +438,7 @@ class OpActivateInstanceDisks(OpCode):
   """Activate an instance's disks."""
   OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
   OP_DSC_FIELD = "instance_name"
-  __slots__ = ["instance_name"]
+  __slots__ = ["instance_name", "ignore_size"]
 
 
 class OpDeactivateInstanceDisks(OpCode):
diff --git a/man/gnt-instance.sgml b/man/gnt-instance.sgml
index ff8b52e62..d17a4a6b2 100644
--- a/man/gnt-instance.sgml
+++ b/man/gnt-instance.sgml
@@ -1657,6 +1657,7 @@ instance5: 11225
         <cmdsynopsis>
           <command>activate-disks</command>
           <arg>--submit</arg>
+          <arg>--ignore-size</arg>
           <arg choice="req"><replaceable>instance</replaceable></arg>
         </cmdsynopsis>
         <para>
@@ -1685,6 +1686,16 @@ node1.example.com:disk/1:/dev/drbd1
           <command>gnt-job info</command>.
         </para>
 
+        <para>
+          The <option>--ignore-size</option> option can be used to
+          activate disks ignoring the currently configured size in
+          Ganeti. This can be used in cases where the configuration
+          has gotten out of sync with the real-world (e.g. after a
+          partially-failed grow-disk operation or due to rounding in
+          LVM devices). This should not be used in normal cases, but
+          only when activate-disks fails without it.
+        </para>
+
         <para>
           Note that it is safe to run this command while the instance
           is already running.
diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index e7990baf6..e16fed7b6 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -609,7 +609,8 @@ def ActivateDisks(opts, args):
 
   """
   instance_name = args[0]
-  op = opcodes.OpActivateInstanceDisks(instance_name=instance_name)
+  op = opcodes.OpActivateInstanceDisks(instance_name=instance_name,
+                                       ignore_size=opts.ignore_size)
   disks_info = SubmitOrSend(op, opts)
   for host, iname, nname in disks_info:
     ToStdout("%s:%s:%s", host, iname, nname)
@@ -1482,7 +1483,14 @@ commands = {
                SUBMIT_OPT,
                ],
             "<instance>", "Reboots an instance"),
-  'activate-disks': (ActivateDisks, ARGS_ONE, [DEBUG_OPT, SUBMIT_OPT],
+  'activate-disks': (ActivateDisks, ARGS_ONE,
+                     [DEBUG_OPT, SUBMIT_OPT,
+                      make_option("--ignore-size", dest="ignore_size",
+                                  default=False, action="store_true",
+                                  help="Ignore current recorded size"
+                                  " (useful for forcing activation when"
+                                  " the recorded size is wrong)"),
+                      ],
                      "<instance>",
                      "Activate an instance's disks"),
   'deactivate-disks': (DeactivateDisks, ARGS_ONE, [DEBUG_OPT, SUBMIT_OPT],
-- 
GitLab