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