• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Metadata stress testing program for file system
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License as published by the Free Software Foundation; version
7  * 2.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should find a copy of v2 of the GNU General Public License somewhere
15  * on your Linux system; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * This program helps you to traverse each node in the k tree
19  * Do the i-node operations on the all file entries in recursive
20  *
21  * Copyright (C) 2009, Intel Corp.
22  * Author: Shaohui Zheng <shaohui.zheng@intel.com>
23  */
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <dirent.h>
28 #include <unistd.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 
32 #define MAX_PATH 8192
33 
34 /*
35  * Traverse a k-tree in recusive
36  *
37  * parameters:
38  * lvl: tree level number from button to top
39  * node_nr: the maximun nodes number
40  * return val: if it is leaf, return 0, or return 1
41  */
42 
k_tree_trav(int lvl,int node_nr)43 int k_tree_trav(int lvl, int node_nr)
44 {
45 	int cnt;
46 	char dir[MAX_PATH], cwd[MAX_PATH], f1[MAX_PATH], f2[MAX_PATH],
47 	    ln[MAX_PATH];
48 	if (lvl <= 0)
49 		return 0;
50 
51 	for (cnt = 0; cnt < node_nr; cnt++) {
52 		sprintf(dir, "%d-d", cnt);
53 		sprintf(f1, "%d-f", cnt);
54 		sprintf(f2, "%d-f-t", cnt);
55 		sprintf(ln, "%d-l", cnt);
56 
57 		// link and unlink testing for each file i-node
58 		link(f1, f2);
59 		unlink(f1);
60 		rename(f2, f1);
61 
62 		// symlink testing
63 		symlink(ln, f1);
64 		unlink(ln);
65 
66 		getcwd(cwd, sizeof(cwd));
67 		chmod(dir, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
68 		chdir(dir);
69 		k_tree_trav(lvl - 1, node_nr);
70 		chdir(cwd);
71 	}
72 
73 	return 1;
74 }
75 
main(int argc,char ** argv)76 int main(int argc, char **argv)
77 {
78 	if (argc < 2) {
79 		printf("Usage: %s tree_depth tree_width\n", argv[0]);
80 		return 1;
81 	}
82 
83 	printf("Traverse k tree (depth: %s, width: %s)...\n", argv[1], argv[2]);
84 	k_tree_trav(atoi(argv[1]), atoi(argv[2]));
85 	printf("Traverse k tree (depth: %s, width: %s), done\n", argv[1],
86 	       argv[2]);
87 	return 0;
88 }
89