[sheepdog] [PATCH 3/6] vditest: remove error() and use built-in function

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Mon Feb 4 07:38:02 CET 2013


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

diff --git a/script/vditest b/script/vditest
index 080d93a..cc411ba 100755
--- a/script/vditest
+++ b/script/vditest
@@ -140,7 +140,7 @@ sub vdi_open {
     } else {
 	$cmd = "stdbuf -o0 qemu-io -t $cache sheepdog:$vdiname";
     }
-    open2 *QEMU_OUT, *QEMU, $cmd or die "cannot run qemu-io\n"  if !$no_act;
+    open2 *QEMU_OUT, *QEMU, $cmd or die "cannot run qemu-io" if !$no_act;
     <QEMU_OUT>;
 }
 
@@ -199,18 +199,18 @@ sub parse_opts {
 	    to_bytes($hblk);
 	    $hblk = $lblk  if $hblk == 0;
 
-	    error("$lblk is not sector aligned\n")  if $lblk % 512 != 0;
-	    error("$lblk is not valid\n")  if $lblk == 0;
-	    error("$hblk is not sector aligned\n")  if $hblk % 512 != 0;
-	    error("$hblk is too large\n")  if $lblk > (64 * 1024 ** 2);
-	    error("transfer range is invalid\n")  if $lblk > $hblk;
+	    die "$lblk is not sector aligned" if $lblk % 512 != 0;
+	    die "$lblk is not valid" if $lblk == 0;
+	    die "$hblk is not sector aligned" if $hblk % 512 != 0;
+	    die "$hblk is too large" if $lblk > (64 * 1024 ** 2);
+	    die "transfer range is invalid" if $lblk > $hblk;
 	} elsif ($key eq 'c') {
 	    if ($val !~ /(none|write(back|through))/) {
-		error("\"$val\" is not valid\n");
+		die "'$val' is not valid";
 	    }
 	    $cache = $val;
 	} elsif ($key eq 'C') {
-	    error("\"$val\" is not valid\n")  if ($val <= 0);
+	    die "'$val' is not valid" if $val <= 0;
 	    $concurrency = $val;
 	} elsif ($key eq 'D') {
 	    ($rrate, $wrate) = ($val =~ /(\d+)\%?:?(\d*)\%?/);
@@ -219,13 +219,13 @@ sub parse_opts {
 	} elsif ($key eq 'F') {
 	    $file = 1;
 	} elsif ($key eq 'h') {
-	    error("\"$val\" is not valid\n")  if ($val <= 0);
+	    die "'$val' is not valid" if $val <= 0;
 	    $hbeat = $val;
 	} elsif ($key eq 'n') {
 	    $no_act = 1;
 	    $verbose = 1;
 	} elsif ($key eq 'o') {
-	    error("\"$val\" is not valid\n")  if ($val < 0);
+	    die "'$val' is not valid" if $val < 0;
 	    $offset = $val;
 	} elsif ($key eq 'p') {
 	    if ($val =~ /^l/) {
@@ -233,7 +233,7 @@ sub parse_opts {
 	    } elsif ($val =~ /^r/) {
 		$seek_pattern = "random";
 	    } else {
-		error("\"$val\" is not valid\n");
+		die "'$val' is not valid";
 	    }
 	} elsif ($key eq 'r') {
 	    $read_test = 1;
@@ -249,10 +249,10 @@ sub parse_opts {
 	    to_bytes($sblk);
 	    to_bytes($eblk);
 
-	    error("$sblk is not sector aligned\n")  if $sblk % 512 != 0;
-	    error("$eblk is not sector aligned\n")  if $eblk % 512 != 0;
+	    die "$sblk is not sector aligned" if $sblk % 512 != 0;
+	    die "$eblk is not sector aligned" if $eblk % 512 != 0;
 	} elsif ($key eq 'T') {
-	    error("\"$val\" is not valid\n")  if ($val < 0);
+	    die "'$val' is not valid" if $val < 0;
 	    $runtime = $val;
 	} elsif ($key eq 'v') {
 	    $verbose = 1;
@@ -270,14 +270,14 @@ sub parse_opts {
 sub parse {
     parse_opts();
     if (@ARGV == 0) {
-	error("vdiname must be specified\n");
+	die "vdiname must be specified";
     } else {
 	$vdiname = shift @ARGV;
 
 	# process the rest of options
 	parse_opts()  if (@ARGV > 0);
     }
-    error("too many arguments\n")  if @ARGV > 0;
+    die "too many arguments" if @ARGV > 0;
 
     if ($file) {
 	$vdisize = `qemu-io -c length $vdiname`;
@@ -286,12 +286,12 @@ sub parse {
     }
     to_bytes($vdisize);
 
-    error("cannot get vdi size\n")  if $vdisize == 0;
+    die "cannot get vdi size" if $vdisize == 0;
 
     $eblk = $vdisize  if $eblk == 0;
 
-    error("test block range is invalid\n")  if $sblk >= $eblk;
-    error("transfer size is too large\n")  if $hblk > $eblk - $sblk;
+    die "test block range is invalid" if $sblk >= $eblk;
+    die "transfer size is too large" if $hblk > $eblk - $sblk;
 }
 
 sub vdi_main {
@@ -422,11 +422,3 @@ Usage: $program [OPTION] vdiname
 END_OF_HELP
     exit($status);
 }
-
-sub error {
-    my ($msg) = @_;
-
-    print STDERR $msg;
-
-    exit(1);
-}
-- 
1.7.2.5




More information about the sheepdog mailing list