Whamcloud - gitweb
Merge b_md into HEAD
[fs/lustre-release.git] / lustre / tests / create.pl
1 #!/usr/bin/perl
2 use Getopt::Long;
3
4 my $silent = 0;
5 my $mcreate = 1; # should we use mcreate or open?
6 my $files = 5;
7
8 GetOptions("silent!" => \$silent,
9            "mcreate=i" => \$mcreate,
10            "files=i" => \$files);
11
12 my $mtpt = shift || usage();
13 my $mount_count = shift || usage();
14 my $i = shift || usage();
15 my $count = $i;
16
17 sub usage () {
18     print "Usage: $0 [--silent] [--mcreate=n] [--files=n] <mnt prefix> <mnt count> <iterations>\n";
19     print "example: $0 /mnt/lustre 2 50\n";
20     print "         will test in /mnt/lustre1 and /mnt/lustre2\n";
21     print "         $0 /mnt/lustre -1 50\n";
22     print "         will test in /mnt/lustre only\n";
23     exit;
24 }
25
26 sub do_open($) {
27     my $path = shift;
28
29     if ($mcreate) {
30         my $tmp = `./mcreate $path`;
31         if ($tmp) {
32             print  "Creating $path [" . $$."]...\n" if !$silent;
33             $tmp =~ /.*error: (.*)\n/;
34             print  "Create done [$$] $path: $!\n" if !$silent;
35         } else {
36             print  "Create done [$$] $path: Success\n"if !$silent;
37         }
38     } else {
39         print  "Opening $path [" . $$."]...\n"if !$silent;
40         open(FH, ">$path") || die "open($PATH): $!";
41         print  "Open done [$$] $path: Success\n"if !$silent;
42         close(FH) || die;
43     }
44 }
45
46 while ($i--) {
47     my $which = "";
48     if ($mount_count > 0) {
49         $which = int(rand() * $mount_count) + 1;
50     }
51     $d = int(rand() * $files);
52     do_open("$mtpt$which/$d");
53
54     if ($mount_count > 0) {
55         $which = int(rand() * $mount_count) + 1;
56     }
57     $d = int(rand() * $files);
58     $path = "$mtpt$which/$d";
59     print  "Unlink $path start [" . $$."]...\n"if !$silent;
60     if (unlink($path)) {
61         print  "Unlink done [$$] $path: Success\n"if !$silent;
62     } else {
63         print  "Unlink done [$$] $path: $!\n"if !$silent;
64     }
65     if (($count - $i) % 100 == 0) {
66         print STDERR ($count - $i) . " operations [" . $$ . "]\n";
67     }
68 }
69
70 my $which = "";
71 if ($mount_count > 0) {
72     $which = int(rand() * $mount_count) + 1;
73 }
74 for ($d = 0; $d < $files; $d++) {
75     unlink("$mtpt$which/$d");
76 }
77
78 print "Done.\n";