]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | ||
16 | #ifndef CEPH_SYNTHETICCLIENT_H | |
17 | #define CEPH_SYNTHETICCLIENT_H | |
18 | ||
19 | #include <pthread.h> | |
20 | ||
21 | #include "Client.h" | |
22 | #include "include/Distribution.h" | |
23 | ||
24 | #include "Trace.h" | |
25 | ||
26 | #define SYNCLIENT_FIRST_POOL 0 | |
27 | ||
28 | #define SYNCLIENT_MODE_RANDOMWALK 1 | |
29 | #define SYNCLIENT_MODE_FULLWALK 2 | |
30 | #define SYNCLIENT_MODE_REPEATWALK 3 | |
31 | ||
32 | #define SYNCLIENT_MODE_MAKEDIRMESS 7 | |
33 | #define SYNCLIENT_MODE_MAKEDIRS 8 // dirs files depth | |
34 | #define SYNCLIENT_MODE_STATDIRS 9 // dirs files depth | |
35 | #define SYNCLIENT_MODE_READDIRS 10 // dirs files depth | |
36 | ||
37 | #define SYNCLIENT_MODE_MAKEFILES 11 // num count private | |
38 | #define SYNCLIENT_MODE_MAKEFILES2 12 // num count private | |
39 | #define SYNCLIENT_MODE_CREATESHARED 13 // num | |
40 | #define SYNCLIENT_MODE_OPENSHARED 14 // num count | |
41 | ||
42 | #define SYNCLIENT_MODE_RMFILE 19 | |
43 | #define SYNCLIENT_MODE_WRITEFILE 20 | |
44 | #define SYNCLIENT_MODE_READFILE 21 | |
45 | #define SYNCLIENT_MODE_WRITEBATCH 22 | |
46 | #define SYNCLIENT_MODE_WRSHARED 23 | |
47 | #define SYNCLIENT_MODE_READSHARED 24 | |
48 | #define SYNCLIENT_MODE_RDWRRANDOM 25 | |
49 | #define SYNCLIENT_MODE_RDWRRANDOM_EX 26 | |
50 | ||
51 | #define SYNCLIENT_MODE_LINKTEST 27 | |
52 | ||
53 | #define SYNCLIENT_MODE_OVERLOAD_OSD_0 28 // two args | |
54 | ||
55 | #define SYNCLIENT_MODE_DROPCACHE 29 | |
56 | ||
57 | #define SYNCLIENT_MODE_TRACE 30 | |
58 | ||
59 | #define SYNCLIENT_MODE_CREATEOBJECTS 35 | |
60 | #define SYNCLIENT_MODE_OBJECTRW 36 | |
61 | ||
62 | #define SYNCLIENT_MODE_OPENTEST 40 | |
63 | #define SYNCLIENT_MODE_OPTEST 41 | |
64 | ||
65 | #define SYNCLIENT_MODE_ONLY 50 | |
66 | #define SYNCLIENT_MODE_ONLYRANGE 51 | |
67 | #define SYNCLIENT_MODE_EXCLUDE 52 | |
68 | #define SYNCLIENT_MODE_EXCLUDERANGE 53 | |
69 | ||
70 | #define SYNCLIENT_MODE_UNTIL 55 | |
71 | #define SYNCLIENT_MODE_SLEEPUNTIL 56 | |
72 | ||
73 | #define SYNCLIENT_MODE_RANDOMSLEEP 61 | |
74 | #define SYNCLIENT_MODE_SLEEP 62 | |
75 | ||
76 | #define SYNCLIENT_MODE_DUMP 63 | |
77 | ||
78 | #define SYNCLIENT_MODE_LOOKUPHASH 70 | |
79 | #define SYNCLIENT_MODE_LOOKUPINO 71 | |
80 | ||
81 | #define SYNCLIENT_MODE_TRUNCATE 200 | |
82 | ||
83 | #define SYNCLIENT_MODE_FOO 100 | |
84 | #define SYNCLIENT_MODE_THRASHLINKS 101 | |
85 | ||
86 | #define SYNCLIENT_MODE_IMPORTFIND 300 | |
87 | ||
88 | #define SYNCLIENT_MODE_CHUNK 400 | |
89 | ||
90 | #define SYNCLIENT_MODE_MKSNAP 1000 | |
91 | #define SYNCLIENT_MODE_RMSNAP 1001 | |
92 | ||
93 | #define SYNCLIENT_MODE_MKSNAPFILE 1002 | |
94 | ||
95 | ||
96 | ||
20effc67 | 97 | void parse_syn_options(std::vector<const char*>& args); |
c07f9fc5 | 98 | extern int num_client; |
7c673cae FG |
99 | |
100 | class SyntheticClient { | |
31f18b77 | 101 | StandaloneClient *client; |
7c673cae FG |
102 | int whoami; |
103 | ||
104 | pthread_t thread_id; | |
105 | ||
106 | Distribution op_dist; | |
107 | ||
108 | void init_op_dist(); | |
109 | int get_op(); | |
110 | ||
111 | ||
20effc67 TL |
112 | filepath cwd; |
113 | std::map<std::string, struct stat*> contents; | |
114 | std::set<std::string> subdirs; | |
115 | bool did_readdir; | |
116 | std::set<int> open_files; | |
7c673cae FG |
117 | |
118 | void up(); | |
119 | ||
120 | void clear_dir() { | |
121 | contents.clear(); | |
122 | subdirs.clear(); | |
123 | did_readdir = false; | |
124 | } | |
125 | ||
126 | int get_random_fh() { | |
127 | int r = rand() % open_files.size(); | |
20effc67 | 128 | std::set<int>::iterator it = open_files.begin(); |
7c673cae FG |
129 | while (r--) ++it; |
130 | return *it; | |
131 | } | |
132 | ||
133 | ||
134 | filepath n1; | |
135 | const char *get_random_subdir() { | |
11fdf7f2 | 136 | ceph_assert(!subdirs.empty()); |
7c673cae | 137 | int r = ((rand() % subdirs.size()) + (rand() % subdirs.size())) / 2; // non-uniform distn |
20effc67 | 138 | std::set<std::string>::iterator it = subdirs.begin(); |
7c673cae FG |
139 | while (r--) ++it; |
140 | ||
141 | n1 = cwd; | |
142 | n1.push_dentry( *it ); | |
143 | return n1.get_path().c_str(); | |
144 | } | |
145 | filepath n2; | |
146 | const char *get_random_sub() { | |
11fdf7f2 | 147 | ceph_assert(!contents.empty()); |
7c673cae FG |
148 | int r = ((rand() % contents.size()) + (rand() % contents.size())) / 2; // non-uniform distn |
149 | if (cwd.depth() && cwd.last_dentry().length()) | |
150 | r += cwd.last_dentry().c_str()[0]; // slightly permuted | |
151 | r %= contents.size(); | |
152 | ||
20effc67 | 153 | std::map<std::string,struct stat*>::iterator it = contents.begin(); |
7c673cae FG |
154 | while (r--) ++it; |
155 | ||
156 | n2 = cwd; | |
157 | n2.push_dentry( it->first ); | |
158 | return n2.get_path().c_str(); | |
159 | } | |
160 | ||
161 | filepath sub; | |
162 | char sub_s[50]; | |
163 | const char *make_sub(const char *base) { | |
164 | snprintf(sub_s, sizeof(sub_s), "%s.%d", base, rand() % 100); | |
20effc67 | 165 | std::string f = sub_s; |
7c673cae FG |
166 | sub = cwd; |
167 | sub.push_dentry(f); | |
168 | return sub.c_str(); | |
169 | } | |
170 | ||
171 | public: | |
31f18b77 | 172 | SyntheticClient(StandaloneClient *client, int w = -1); |
7c673cae FG |
173 | |
174 | int start_thread(); | |
175 | int join_thread(); | |
176 | ||
177 | int run(); | |
178 | ||
179 | bool run_me() { | |
180 | if (run_only >= 0) { | |
181 | if (run_only == client->get_nodeid()) | |
182 | return true; | |
183 | else | |
184 | return false; | |
185 | } | |
186 | return true; | |
187 | } | |
188 | void did_run_me() { | |
189 | run_only = -1; | |
190 | run_until = utime_t(); | |
191 | } | |
192 | ||
193 | // run() will do one of these things: | |
20effc67 TL |
194 | std::list<int> modes; |
195 | std::list<std::string> sargs; | |
196 | std::list<int> iargs; | |
7c673cae FG |
197 | utime_t run_start; |
198 | utime_t run_until; | |
199 | ||
200 | client_t run_only; | |
201 | client_t exclude; | |
202 | ||
20effc67 | 203 | std::string get_sarg(int seq); |
7c673cae FG |
204 | int get_iarg() { |
205 | int i = iargs.front(); | |
206 | iargs.pop_front(); | |
207 | return i; | |
208 | } | |
209 | ||
210 | bool time_to_stop() { | |
211 | utime_t now = ceph_clock_now(); | |
20effc67 TL |
212 | if (0) std::cout << "time_to_stop .. now " << now |
213 | << " until " << run_until | |
214 | << " start " << run_start | |
215 | << std::endl; | |
7c673cae FG |
216 | if (run_until.sec() && now > run_until) |
217 | return true; | |
218 | else | |
219 | return false; | |
220 | } | |
221 | ||
20effc67 | 222 | std::string compose_path(std::string& prefix, char *rest) { |
7c673cae FG |
223 | return prefix + rest; |
224 | } | |
225 | ||
20effc67 | 226 | int full_walk(std::string& fromdir); |
7c673cae FG |
227 | int random_walk(int n); |
228 | ||
20effc67 | 229 | int dump_placement(std::string& fn); |
7c673cae FG |
230 | |
231 | ||
232 | int make_dirs(const char *basedir, int dirs, int files, int depth); | |
233 | int stat_dirs(const char *basedir, int dirs, int files, int depth); | |
234 | int read_dirs(const char *basedir, int dirs, int files, int depth); | |
235 | int make_files(int num, int count, int priv, bool more); | |
236 | int link_test(); | |
237 | ||
238 | int create_shared(int num); | |
239 | int open_shared(int num, int count); | |
240 | ||
20effc67 TL |
241 | int rm_file(std::string& fn); |
242 | int write_file(std::string& fn, int mb, loff_t chunk); | |
7c673cae FG |
243 | int write_fd(int fd, int size, int wrsize); |
244 | ||
245 | int write_batch(int nfile, int mb, int chunk); | |
246 | int read_file(const std::string& fn, int mb, int chunk, bool ignoreprint=false); | |
247 | ||
248 | int create_objects(int nobj, int osize, int inflight); | |
249 | int object_rw(int nobj, int osize, int wrpc, int overlap, | |
250 | double rskew, double wskew); | |
251 | ||
20effc67 TL |
252 | int read_random(std::string& fn, int mb, int chunk); |
253 | int read_random_ex(std::string& fn, int mb, int chunk); | |
7c673cae FG |
254 | |
255 | int overload_osd_0(int n, int sie, int wrsize); | |
256 | int check_first_primary(int fd); | |
257 | ||
20effc67 | 258 | int clean_dir(std::string& basedir); |
7c673cae | 259 | |
20effc67 | 260 | int play_trace(Trace& t, std::string& prefix, bool metadata_only=false); |
7c673cae FG |
261 | |
262 | void make_dir_mess(const char *basedir, int n); | |
263 | void foo(); | |
264 | ||
265 | int thrash_links(const char *basedir, int dirs, int files, int depth, int n); | |
266 | ||
267 | void import_find(const char *basedir, const char *find, bool writedata); | |
268 | ||
269 | int lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name, | |
270 | const UserPerm& perms); | |
271 | int lookup_ino(inodeno_t ino, const UserPerm& perms); | |
272 | ||
20effc67 | 273 | int chunk_file(std::string &filename); |
7c673cae FG |
274 | |
275 | void mksnap(const char *base, const char *name, const UserPerm& perms); | |
276 | void rmsnap(const char *base, const char *name, const UserPerm& perms); | |
277 | void mksnapfile(const char *dir); | |
278 | ||
279 | }; | |
280 | ||
281 | #endif |