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