From 41bbdb520dd57fa5e28479be9758e6da24340a5a Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Fri, 4 Jun 2010 11:12:41 +0100
Subject: [PATCH] LUGrowDisk: fix operation on down instances

Currently it's impossible to grow a disk if an instance is shutdown,
because the disk could not be assembled. Now we take care of assembling
it, and shutting it down after.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/cmdlib.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index eb1f478e8..b89a25aa3 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -7943,6 +7943,11 @@ class LUGrowDisk(LogicalUnit):
     """
     instance = self.instance
     disk = self.disk
+
+    disks_ok, _ = _AssembleInstanceDisks(self, self.instance, disks=[disk])
+    if not disks_ok:
+      raise errors.OpExecError("Cannot activate block device to grow")
+
     for node in instance.all_nodes:
       self.cfg.SetDiskID(disk, node)
       result = self.rpc.call_blockdev_grow(node, disk, self.op.amount)
@@ -7958,10 +7963,16 @@ class LUGrowDisk(LogicalUnit):
     disk.RecordGrow(self.op.amount)
     self.cfg.Update(instance, feedback_fn)
     if self.op.wait_for_sync:
-      disk_abort = not _WaitForSync(self, instance)
+      disk_abort = not _WaitForSync(self, instance, disks=[disk])
       if disk_abort:
         self.proc.LogWarning("Warning: disk sync-ing has not returned a good"
                              " status.\nPlease check the instance.")
+      if not instance.admin_up:
+        _SafeShutdownInstanceDisks(self, instance, disks=[disk])
+    elif not instance.admin_up:
+      self.proc.LogWarning("Not shutting down the disk even if the instance is"
+                           " not supposed to be running because no wait for"
+                           " sync mode was requested.")
 
 
 class LUQueryInstanceData(NoHooksLU):
-- 
GitLab