5 This is the rfs program
\r
7 After run nfsscan, you will get a file-list file in the output
\r
9 This perl program do post processing based on this file
\r
14 $writebuf = "R" x 8193;
\r
15 $writeBlockSize = 8192;
\r
19 sub rfsCreateSymlink()
\r
21 my ($path, $pathcnt, $sizeHexStr) = @_;
\r
22 $sizeHexStr = "0x".$sizeHexStr;
\r
28 $dir =~ /(^.*)\/(.*)/;
\r
31 if (!$dir) {$dir = ".";}
\r
32 die "name is empty\n" if (!$name);
\r
33 #print "path($path) dir($dir) name($name)\n";
\r
36 $cmdbuf = "mkdir -p $dir";
\r
38 print "RFS: Warning: the directory should be created already: $path\n";
\r
40 die "warning: directory name exist but not a directory: $path\n" if (!(-d $dir));
\r
43 my $size = hex($sizeHexStr);
\r
44 #print "size($sizeHexStr) lp($lp) rem($remSize)\n";
\r
46 my $pathnamebuf = $sizeHexStr;
\r
47 symlink ($pathnamebuf, $path);
\r
48 #if (! symlink ($pathnamebuf, $path) ) {
\r
49 # print STDERR "JIAWU: WARNING: failed to create symlink: $path -> $pathnamebuf\n";
\r
56 my ($path, $pathcnt, $sizeHexStr) = @_;
\r
57 $sizeHexStr = "0x".$sizeHexStr;
\r
63 $dir =~ /(^.*)\/(.*)/;
\r
66 if (!$dir) {$dir = ".";}
\r
67 die "name is empty\n" if (!$name);
\r
68 #print "path($path) dir($dir) name($name)\n";
\r
71 $cmdbuf = "mkdir -p $dir";
\r
73 print "RFS: Warning: the directory should be created already: $path\n";
\r
75 die "warning: directory name exist but not a directory: $path\n" if (!(-d $dir));
\r
78 my $size = hex($sizeHexStr);
\r
79 my $remSize = $size % $writeBlockSize;
\r
80 my $lp = ($size - $remSize) / $writeBlockSize;
\r
81 #print "size($sizeHexStr) lp($lp) rem($remSize)\n";
\r
83 open RFSTMPWRITE, ">$path" || die "RFS: can not open file for write";
\r
85 # the eight lines below should not be commented out
\r
87 #for ($i = 0; $i < $lp; $i++) {
\r
88 # syswrite(RFSTMPWRITE, $writebuf, $writeBlockSize);
\r
91 # syswrite(RFSTMPWRITE, $writebuf, $remSize);
\r
92 # #print "write ($remSize) byte\n";
\r
98 # sort -n -k a,b -c -u
\r
100 # *** WARNING *** The locale specified by the environment affects sort
\r
101 # order. Set LC_ALL=C or LC_ALL=POSIX to get the traditional sort order that uses native
\r
108 # format of lines in test.fil:
\r
109 # "F(1) $type(2) $state(3) $fh(4) $path(5) $pathcnt(6) $attrOrig(7-14) $attr()
\r
110 # attrOrig: ($size(7) $mode(8) $op(9) $atime(10) $mtime(11) $ctime(12) $nlink(13) $ts(14))
\r
111 # attrLast: ($size(15) $mode(16) $op(17) $atime(18) $mtime(19) $ctime(20) $nlink(21) $ts(22))
\r
113 # skip comment lines
\r
114 # if (path_count ($6) == 0 or original_op($9) == "create" or "mkdir" or "symlink") skip the file
\r
116 $cmdbuf = 'gawk \' !/^[#]/ { if ($6 != "0") print $0 }\' test.fil > all.fil';
\r
120 # sort the test.fil according to path name
\r
121 $cmdbuf = 'export LC_ALL=C; sort -k 5,5 all.fil > all.fil.order; echo $LC_ALL';
\r
125 # keep the interested field only
\r
126 # 2(D/F) 4(FH) 5(path) 6(count) 15(size_last) 21(nlink_last) 14(ts_s) 22(ts_e)
\r
127 $cmdbuf = 'gawk \' { print $14, $22, $4, $5, $15, $21}\' all.fil.order > fh-path-map-all';
\r
131 # skip comment lines
\r
132 # if (path_count ($6) == 0 or original_op($9) == "create" or "mkdir" or "symlink") skip the file
\r
134 $cmdbuf = 'gawk \' !/^[#]/ { if ($6 != "0" && $9 != "create" && $9 != "mkdir" && $9 != "symlink") print $0 }\' test.fil > active.fil';
\r
138 # sort the active.fil according to path name
\r
139 $cmdbuf = 'export LC_ALL=C; sort -k 5,5 active.fil > active.fil.order; echo $LC_ALL';
\r
143 # keep the interested field only
\r
144 # 2(D/F) 4(FH) 5(path) 6(count) 7(size) 8(mode) 13(nlink)
\r
145 $cmdbuf = 'gawk \' { print $2, $4, $5, $6, $7, $8 }\' active.fil.order > active';
\r
148 $cmdbuf = 'gawk \' { print $4, $5, $7, $13}\' active.fil.order > fh-path-map';
\r
152 # format output files
\r
153 $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
157 $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
161 #$cmdbuf = 'mv noattrdirdiscard noattrdirdiscard-tmp; cat noattrdirdiscard-tmp missdiscardfh >noattrdirdiscard; rm -f noattrdirdiscard-tmp missdiscardfh';
\r
162 $cmdbuf = 'mv noattrdirdiscard noattrdirdiscard-tmp; cat noattrdirdiscard-tmp missdiscardfh >noattrdirdiscard; rm -f noattrdirdiscard-tmp';
\r
168 # so far, you got the following information
\r
169 # in active: all files/dirs active
\r
170 # in noattrdir-root: a set of fhs pointing to RFSNN0
\r
171 # in rfsinfo: a set of dir fhs refer to RFSNNxxx(>0)
\r
172 # a set of file fhs should be discard due to short of information
\r
174 # create the active fs
\r
175 # 1. BASEDIR/RFSNN0
\r
176 # 2. BASEDIR/active
\r
177 $cmdbuf = "mkdir -p RFSFS/RFSNN0";
\r
179 open RFS_ACTIVE, "active" || die "open active failed\n";
\r
180 while (<RFS_ACTIVE>) {
\r
182 my ($type, $fh, $path, $pathcnt, $sizeHexStr, $mode) = split (' ', $_, 7);
\r
184 $cmdbuf = "mkdir -p RFSFS$path";
\r
187 &rfsCreateFile("RFSFS$path", $pathcnt, $sizeHexStr);
\r
189 #print STDERR "SYMLINK: $type fh: $fh path: $path\n";
\r
190 &rfsCreateSymlink("RFSFS$path", $pathcnt, $sizeHexStr);
\r
192 print STDERR "special file: $type fh: $fh path: $path\n";
\r
197 if ( ($line_num %100)==0 ) {
\r
198 print STDERR "$line_num\n";
\r
203 # create map table: key (fh), value (path/fn)
\r
205 # check whether there is fh that is not mapped to any path/fn in the trace
\r
207 # simulate a replay of trace
\r