From 1b5daea7711b0cd5a44ece345e86d115d783883c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 26 Dec 2015 04:10:20 +0100 Subject: [PATCH] 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 --- core-modules/001QubesResizableVm.py | 12 +++++++++--- qvm-tools/qvm-grow-root | 6 +++++- tests/vm_qrexec_gui.py | 4 +++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/core-modules/001QubesResizableVm.py b/core-modules/001QubesResizableVm.py index 5e898b40..f50ead70 100644 --- a/core-modules/001QubesResizableVm.py +++ b/core-modules/001QubesResizableVm.py @@ -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) diff --git a/qvm-tools/qvm-grow-root b/qvm-tools/qvm-grow-root index 93c55bb2..5e650ab7 100755 --- a/qvm-tools/qvm-grow-root +++ b/qvm-tools/qvm-grow-root @@ -34,6 +34,10 @@ def main(): usage = "usage: %prog " 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) diff --git a/tests/vm_qrexec_gui.py b/tests/vm_qrexec_gui.py index c64da4d4..aa4e3da4 100644 --- a/tests/vm_qrexec_gui.py +++ b/tests/vm_qrexec_gui.py @@ -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)