qvm-grow-root: add --allow-start option

In some (most) cases VM needs to be started to complete resize
operation. This may be unexpected, so make it clear and do not start the
VM when the user did not explicitly allow that.

Fixes QubesOS/qubes-issues#1268
This commit is contained in:
Marek Marczykowski-Górecki 2015-12-26 04:10:20 +01:00
parent 49c1ab2f99
commit 1b5daea771
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 17 additions and 5 deletions

View File

@ -36,7 +36,7 @@ from time import sleep
class QubesResizableVm(QubesVm):
def resize_root_img(self, size):
def resize_root_img(self, size, allow_start=False):
if self.template:
raise QubesException("Cannot resize root.img of template-based VM"
". Resize the root.img of the template "
@ -57,8 +57,14 @@ class QubesResizableVm(QubesVm):
class QubesResizableVmWithResize2fs(QubesResizableVm):
def resize_root_img(self, size):
super(QubesResizableVmWithResize2fs, self).resize_root_img(size)
def resize_root_img(self, size, allow_start=False):
super(QubesResizableVmWithResize2fs, self).\
resize_root_img(size, allow_start=allow_start)
if not allow_start:
raise QubesException("VM start required to complete the "
"operation, but not allowed. Either run the "
"operation again allowing VM start this "
"time, or run resize2fs in the VM manually.")
self.start(start_guid=False)
self.run("resize2fs /dev/mapper/dmroot", user="root", wait=True,
gui=False)

View File

@ -34,6 +34,10 @@ def main():
usage = "usage: %prog <vm-name> <size>"
parser = OptionParser (usage)
parser.add_option("--allow-start", action="store_true",
dest="allow_start", default=False,
help="Allow VM to be started to complete the operation")
(options, args) = parser.parse_args ()
if (len (args) != 2):
parser.error ("You must specify VM name and new size!")
@ -57,7 +61,7 @@ def main():
exit(1)
try:
vm.resize_root_img(size_bytes)
vm.resize_root_img(size_bytes, allow_start=options.allow_start)
except (IOError, OSError, QubesException) as err:
print >> sys.stderr, "ERROR: {0}".format(err)
exit (1)

View File

@ -731,7 +731,9 @@ class TC_05_StandaloneVM(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase
source_template=self.qc.get_default_template())
self.qc.save()
self.qc.unlock_db()
testvm1.resize_root_img(20*1024**3)
with self.assertRaises(QubesException):
testvm1.resize_root_img(20*1024**3)
testvm1.resize_root_img(20*1024**3, allow_start=True)
timeout = 60
while testvm1.is_running():
time.sleep(1)