8 This program runs after nfsscan.pl. It outputs the file system hierarchy (RFSFS) as well as
\r
9 the file system hierarchy map (stored in three files: fh-path-map, noattrdirdiscard, noattrdir-root).
\r
11 This perl program do post processing based on this file
\r
13 Command line options:
\r
15 -h Print Usage message and exit.
\r
17 -S The file in file system hierarchy are all of size 0.
\r
18 Without -S, the files are written to it full length.
\r
23 $writebuf = "R" x 8193;
\r
24 $writeBlockSize = 8192;
\r
28 sub rfsCreateSymlink()
\r
30 my ($path, $pathcnt, $sizeHexStr) = @_;
\r
31 $sizeHexStr = "0x".$sizeHexStr;
\r
37 $dir =~ /(^.*)\/(.*)/;
\r
40 if (!$dir) {$dir = ".";}
\r
41 die "name is empty\n" if (!$name);
\r
42 #print "path($path) dir($dir) name($name)\n";
\r
45 $cmdbuf = "mkdir -p $dir";
\r
47 print "RFS: Warning: the directory should be created already: $path\n";
\r
49 die "warning: directory name exist but not a directory: $path\n" if (!(-d $dir));
\r
52 my $size = hex($sizeHexStr);
\r
53 #print "size($sizeHexStr) lp($lp) rem($remSize)\n";
\r
55 my $pathnamebuf = $sizeHexStr;
\r
56 symlink ($pathnamebuf, $path);
\r
57 #if (! symlink ($pathnamebuf, $path) ) {
\r
58 # print STDERR "JIAWU: WARNING: failed to create symlink: $path -> $pathnamebuf\n";
\r
65 my ($path, $pathcnt, $sizeHexStr) = @_;
\r
66 $sizeHexStr = "0x".$sizeHexStr;
\r
72 $dir =~ /(^.*)\/(.*)/;
\r
75 if (!$dir) {$dir = ".";}
\r
76 die "name is empty\n" if (!$name);
\r
77 #print "path($path) dir($dir) name($name)\n";
\r
80 $cmdbuf = "mkdir -p $dir";
\r
82 print "RFS: Warning: the directory should be created already: $path\n";
\r
84 die "warning: directory name exist but not a directory: $path\n" if (!(-d $dir));
\r
87 my $size = hex($sizeHexStr);
\r
88 my $remSize = $size % $writeBlockSize;
\r
89 my $lp = ($size - $remSize) / $writeBlockSize;
\r
90 #print "size($sizeHexStr) lp($lp) rem($remSize)\n";
\r
92 open RFSTMPWRITE, ">$path" || die "RFS: can not open file for write";
\r
94 # the eight lines below should not be commented out
\r
95 if (!defined $opt_S) {
\r
97 for ($i = 0; $i < $lp; $i++) {
\r
98 syswrite(RFSTMPWRITE, $writebuf, $writeBlockSize);
\r
101 syswrite(RFSTMPWRITE, $writebuf, $remSize);
\r
102 #print "write ($remSize) byte\n";
\r
109 # sort -n -k a,b -c -u
\r
111 # *** WARNING *** The locale specified by the environment affects sort
\r
112 # order. Set LC_ALL=C or LC_ALL=POSIX to get the traditional sort order that uses native
\r
117 if (! getopts($Options)) {
\r
118 print STDERR "$0: Incorrect usage.\n";
\r
119 print STDERR $Usage;
\r
130 # format of lines in test.fil:
\r
131 # "F(1) $type(2) $state(3) $fh(4) $path(5) $pathcnt(6) $attrOrig(7-14) $attr()
\r
132 # attrOrig: ($size(7) $mode(8) $op(9) $atime(10) $mtime(11) $ctime(12) $nlink(13) $ts(14))
\r
133 # attrLast: ($size(15) $mode(16) $op(17) $atime(18) $mtime(19) $ctime(20) $nlink(21) $ts(22))
\r
135 # skip comment lines
\r
136 # if (path_count ($6) == 0 or original_op($9) == "create" or "mkdir" or "symlink") skip the file
\r
138 $cmdbuf = 'gawk \' !/^[#]/ { if ($6 != "0") print $0 }\' test.fil > all.fil';
\r
142 # sort the test.fil according to path name
\r
143 $cmdbuf = 'export LC_ALL=C; sort -k 5,5 all.fil > all.fil.order; echo $LC_ALL';
\r
147 # keep the interested field only
\r
148 # 2(D/F) 4(FH) 5(path) 6(count) 15(size_last) 21(nlink_last) 14(ts_s) 22(ts_e)
\r
149 $cmdbuf = 'gawk \' { print $14, $22, $4, $5, $15, $21}\' all.fil.order > fh-path-map-all';
\r
153 # skip comment lines
\r
154 # if (path_count ($6) == 0 or original_op($9) == "create" or "mkdir" or "symlink") skip the file
\r
156 $cmdbuf = 'gawk \' !/^[#]/ { if ($6 != "0" && $9 != "create" && $9 != "mkdir" && $9 != "symlink") print $0 }\' test.fil > active.fil';
\r
160 # sort the active.fil according to path name
\r
161 $cmdbuf = 'export LC_ALL=C; sort -k 5,5 active.fil > active.fil.order; echo $LC_ALL';
\r
165 # keep the interested field only
\r
166 # 2(D/F) 4(FH) 5(path) 6(count) 7(size) 8(mode) 13(nlink)
\r
167 $cmdbuf = 'gawk \' { print $2, $4, $5, $6, $7, $8 }\' active.fil.order > active';
\r
170 $cmdbuf = 'gawk \' { print $4, $5, $7, $13}\' active.fil.order > fh-path-map';
\r
174 # format output files
\r
175 $cmdbuf = 'export LC_ALL=C; mv noattrdirdiscard noattrdirdiscard-tmp; sort -u -k 1,1 noattrdirdiscard-tmp > noattrdirdiscard; echo $LC_ALL; rm -f noattrdirdiscard-tmp';
\r
179 $cmdbuf = 'export LC_ALL=C; mv noattrdir-root noattrdir-root-tmp; sort -u -k 1,1 noattrdir-root-tmp > noattrdir-root; echo $LC_ALL; rm -f noattrdir-root-tmp';
\r
183 #$cmdbuf = 'mv noattrdirdiscard noattrdirdiscard-tmp; cat noattrdirdiscard-tmp missdiscardfh >noattrdirdiscard; rm -f noattrdirdiscard-tmp missdiscardfh';
\r
184 $cmdbuf = 'mv noattrdirdiscard noattrdirdiscard-tmp; cat noattrdirdiscard-tmp missdiscardfh >noattrdirdiscard; rm -f noattrdirdiscard-tmp';
\r
188 $cmdbuf = "cut -d ' ' -f '1 2' fh-path-map > fh-path-map-tmp";
\r
192 $cmdbuf = 'cat noattrdirdiscard noattrdir-root fh-path-map-tmp > fh-path-map-play; rm -rf fh-path-map-tmp';
\r
198 # so far, you got the following information
\r
199 # in active: all files/dirs active
\r
200 # in noattrdir-root: a set of fhs pointing to RFSNN0
\r
201 # in rfsinfo: a set of dir fhs refer to RFSNNxxx(>0)
\r
202 # a set of file fhs should be discard due to short of information
\r
204 # create the active fs
\r
205 # 1. BASEDIR/RFSNN0
\r
206 # 2. BASEDIR/active
\r
207 $cmdbuf = "mkdir -p RFSFS/RFSNN0";
\r
209 open RFS_ACTIVE, "active" || die "open active failed\n";
\r
210 while (<RFS_ACTIVE>) {
\r
212 my ($type, $fh, $path, $pathcnt, $sizeHexStr, $mode) = split (' ', $_, 7);
\r
214 $cmdbuf = "mkdir -p RFSFS$path";
\r
217 &rfsCreateFile("RFSFS$path", $pathcnt, $sizeHexStr);
\r
219 #print STDERR "SYMLINK: $type fh: $fh path: $path\n";
\r
220 &rfsCreateSymlink("RFSFS$path", $pathcnt, $sizeHexStr);
\r
222 print STDERR "special file: $type fh: $fh path: $path\n";
\r
227 if ( ($line_num %100)==0 ) {
\r
228 print STDERR "$line_num\n";
\r
233 # create map table: key (fh), value (path/fn)
\r
235 # check whether there is fh that is not mapped to any path/fn in the trace
\r
237 # simulate a replay of trace
\r