xl: fix block-attach command parsing
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 21 May 2010 14:25:10 +0000 (15:25 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 21 May 2010 14:25:10 +0000 (15:25 +0100)
Fix two command-line parsing problems:
 - the argc check is wrong: it must be provided with the frontend
 device
 - the ro/rw mode is optional, so default to rw if it is absent

Also, update the usage message accordingly.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
tools/libxl/xl_cmdimpl.c
tools/libxl/xl_cmdtable.c

index 4f03e8eb6418a8a472314b9b7f4af6efc404a9fb..5c84d33e1d06c08ffaf4adf2a2eadc9bad062c31 100644 (file)
@@ -3444,7 +3444,7 @@ int main_blockattach(int argc, char **argv)
     uint32_t fe_domid, be_domid = 0;
     libxl_device_disk disk = { 0 };
 
-    if ((argc < 3) || (argc > 6)) {
+    if ((argc < 4) || (argc > 6)) {
         help("block-attach");
         exit(0);
     }
@@ -3489,7 +3489,7 @@ int main_blockattach(int argc, char **argv)
     }
     disk.virtpath = argv[3];
     disk.unpluggable = 1;
-    disk.readwrite = (argv[4][0] == 'w') ? 1 : 0;
+    disk.readwrite = (argc <= 4 || argv[4][0] == 'w') ? 1 : 0;
 
     if (domain_qualifier_to_domid(argv[1], &fe_domid, 0) < 0) {
         fprintf(stderr, "%s is an invalid domain identifier\n", argv[1]);
index d34e56988850fb9d3d61af1e263be9a95ac4b7fb..e1caca9db03d5b93a3427ae36126d5af84c9ae63 100644 (file)
@@ -216,7 +216,7 @@ struct cmd_spec cmd_table[] = {
     { "block-attach",
       &main_blockattach,
       "Create a new virtual block device",
-      "<Domain> <BackDev> <FrontDev> <Mode> [BackDomain]",
+      "<Domain> <BackDev> <FrontDev> [<Mode>] [BackDomain]",
     },
     { "block-list",
       &main_blocklist,