From caf3ed1ae4a8f2781cffb753a48bc9dd77607ab2 Mon Sep 17 00:00:00 2001 From: Alexandre Bezroutchko Date: Mon, 8 Oct 2012 00:46:30 +0200 Subject: [PATCH 1/3] cosmetic --- dom0/qvm-tools/qvm-block | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom0/qvm-tools/qvm-block b/dom0/qvm-tools/qvm-block index f7417561..1d1d1305 100755 --- a/dom0/qvm-tools/qvm-block +++ b/dom0/qvm-tools/qvm-block @@ -34,7 +34,7 @@ def main(): "usage: %prog -A [options] :\n"\ "usage: %prog -d [options] :\n"\ "usage: %prog -d [options] \n"\ - "List/set VM PCI devices." + "List/set VM block devices." parser = OptionParser (usage) parser.add_option ("-l", "--list", action="store_true", dest="do_list", default=False) From abfe99756f51f478f2879eedf80d437edeeface7 Mon Sep 17 00:00:00 2001 From: Alexandre Bezroutchko Date: Mon, 8 Oct 2012 00:48:20 +0200 Subject: [PATCH 2/3] start XS transaction before getting the list of domains --- dom0/qvm-core/qubesutils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dom0/qvm-core/qubesutils.py b/dom0/qvm-core/qubesutils.py index 6a3a0313..8c015039 100644 --- a/dom0/qvm-core/qubesutils.py +++ b/dom0/qvm-core/qubesutils.py @@ -196,6 +196,8 @@ def block_list(vm = None, system_disks = False): desc_re = re.compile(r"^.{1,255}$") mode_re = re.compile(r"^[rw]$") + xs_trans = xs.transaction_start() + vm_list = [] if vm is not None: if not vm.is_running(): @@ -205,7 +207,6 @@ def block_list(vm = None, system_disks = False): else: vm_list = xs.ls('', '/local/domain') - xs_trans = xs.transaction_start() devices_list = {} for xid in vm_list: vm_name = xs.read(xs_trans, '/local/domain/%s/name' % xid) From ca4367821ee2d8b9139993b9a7523fcec5151204 Mon Sep 17 00:00:00 2001 From: Alexandre Bezroutchko Date: Mon, 15 Oct 2012 11:40:08 +0200 Subject: [PATCH 3/3] Improve handling of command line parameters, don't silently ignore unexpected arguments. This is to avoid following behavior: [abb@dom0 qubes-core]$ qvm-block -l netvm:sda STORAGE_DEVICE () 0 B dom0:sdb1 Cruzer () 3 GiB dom0:sdb Cruzer () 3 GiB [abb@dom0 qubes-core]$ qvm-block -l netvm:sda STORAGE_DEVICE () 0 B dom0:sdb1 Cruzer () 3 GiB dom0:sdb Cruzer () 3 GiB [abb@dom0 qubes-core]$ qvm-block -a qdvp dom0:sdb [abb@dom0 qubes-core]$ qvm-block -l netvm:sda STORAGE_DEVICE () 0 B dom0:sdb1 Cruzer () 3 GiB dom0:sdb Cruzer () 3 GiB (attached to 'qdvp' as 'xvdi') [abb@dom0 qubes-core]$ qvm-block -d qdvp BLAHBLAH ^^^^^^^^^^^^^ >>> The last parameter is silently ignored and all devices get detached [abb@dom0 qubes-core]$ qvm-block -l netvm:sda STORAGE_DEVICE () 0 B dom0:sdb1 Cruzer () 3 GiB dom0:sdb Cruzer () 3 GiB --- dom0/qvm-tools/qvm-block | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dom0/qvm-tools/qvm-block b/dom0/qvm-tools/qvm-block index 1d1d1305..24f83f73 100755 --- a/dom0/qvm-tools/qvm-block +++ b/dom0/qvm-tools/qvm-block @@ -76,8 +76,8 @@ def main(): qvm_collection.unlock_db() if options.do_attach: - if (len (args) < 2): - parser.error ("You must provide device and vm name!") + if (len (args) != 2): + parser.error ("You must provide vm name and device!") vm = qvm_collection.get_vm_by_name(args[0]) if vm is None: parser.error ("Invalid VM name: %s" % args[0]) @@ -111,6 +111,8 @@ def main(): elif options.do_detach: if (len (args) < 1): parser.error ("You must provide device or vm name!") + if len(args) > 1: + parser.error ("Too many parameters") # Check if provided name is VM vm = qvm_collection.get_vm_by_name(args[0]) if vm is not None: @@ -133,6 +135,8 @@ def main(): block_detach(None, attached_to['devid'], vm_xid=attached_to['xid']) else: # do_list + if len(args) > 0: + parser.error ("Too many parameters") kwargs = {} kwargs['system_disks'] = options.system_disks for dev in block_list(**kwargs).values():