[sheepdog] [PATCH 04/10] vditest: allow specifying vdi name before command line options

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Mon Oct 22 04:54:07 CEST 2012


Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 script/vditest |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/script/vditest b/script/vditest
index 96c22b5..67201b2 100755
--- a/script/vditest
+++ b/script/vditest
@@ -14,7 +14,6 @@ use Getopt::Std;
 use Switch;
 
 my $program = "vditest";
-my %opts = ();
 my ($vdiname, $vdisize);
 
 my $use_aio = 0;
@@ -143,7 +142,9 @@ sub vdi_flush {
     }
 }
 
-sub parse {
+sub parse_opts {
+    my %opts = ();
+
     getopts("aB:c:C:D:f:hno:p:s:S:t:v", \%opts) or help(1);
 
     foreach my $key (keys %opts) {
@@ -216,11 +217,20 @@ sub parse {
 	    }
 	}
     }
+}
 
-    error("vdiname must be specified\n")  if @ARGV == 0;
-    error("too many arguments\n")  if @ARGV > 1;
+sub parse {
+    parse_opts();
+    if (@ARGV == 0) {
+	error("vdiname must be specified\n");
+    } else {
+	$vdiname = shift @ARGV;
+
+	# process the rest of options
+	parse_opts()  if (@ARGV > 0);
+    }
+    error("too many arguments\n")  if @ARGV > 0;
 
-    $vdiname = $ARGV[0];
     $vdisize = `qemu-io -c length sheepdog:$vdiname`;
     to_bytes($vdisize);
 
-- 
1.7.2.5




More information about the sheepdog mailing list