1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
16 #ifndef CEPH_SYNTHETICCLIENT_H
17 #define CEPH_SYNTHETICCLIENT_H
22 #include "include/Distribution.h"
26 #define SYNCLIENT_FIRST_POOL 0
28 #define SYNCLIENT_MODE_RANDOMWALK 1
29 #define SYNCLIENT_MODE_FULLWALK 2
30 #define SYNCLIENT_MODE_REPEATWALK 3
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
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
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
51 #define SYNCLIENT_MODE_LINKTEST 27
53 #define SYNCLIENT_MODE_OVERLOAD_OSD_0 28 // two args
55 #define SYNCLIENT_MODE_DROPCACHE 29
57 #define SYNCLIENT_MODE_TRACE 30
59 #define SYNCLIENT_MODE_CREATEOBJECTS 35
60 #define SYNCLIENT_MODE_OBJECTRW 36
62 #define SYNCLIENT_MODE_OPENTEST 40
63 #define SYNCLIENT_MODE_OPTEST 41
65 #define SYNCLIENT_MODE_ONLY 50
66 #define SYNCLIENT_MODE_ONLYRANGE 51
67 #define SYNCLIENT_MODE_EXCLUDE 52
68 #define SYNCLIENT_MODE_EXCLUDERANGE 53
70 #define SYNCLIENT_MODE_UNTIL 55
71 #define SYNCLIENT_MODE_SLEEPUNTIL 56
73 #define SYNCLIENT_MODE_RANDOMSLEEP 61
74 #define SYNCLIENT_MODE_SLEEP 62
76 #define SYNCLIENT_MODE_DUMP 63
78 #define SYNCLIENT_MODE_LOOKUPHASH 70
79 #define SYNCLIENT_MODE_LOOKUPINO 71
81 #define SYNCLIENT_MODE_TRUNCATE 200
83 #define SYNCLIENT_MODE_FOO 100
84 #define SYNCLIENT_MODE_THRASHLINKS 101
86 #define SYNCLIENT_MODE_IMPORTFIND 300
88 #define SYNCLIENT_MODE_CHUNK 400
90 #define SYNCLIENT_MODE_MKSNAP 1000
91 #define SYNCLIENT_MODE_RMSNAP 1001
93 #define SYNCLIENT_MODE_MKSNAPFILE 1002
97 void parse_syn_options(vector<const char*>& args);
98 extern int num_client;
100 class SyntheticClient {
101 StandaloneClient *client;
106 Distribution op_dist;
113 map<string, struct stat*> contents;
126 int get_random_fh() {
127 int r = rand() % open_files.size();
128 set<int>::iterator it = open_files.begin();
135 const char *get_random_subdir() {
136 assert(!subdirs.empty());
137 int r = ((rand() % subdirs.size()) + (rand() % subdirs.size())) / 2; // non-uniform distn
138 set<string>::iterator it = subdirs.begin();
142 n1.push_dentry( *it );
143 return n1.get_path().c_str();
146 const char *get_random_sub() {
147 assert(!contents.empty());
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();
153 map<string,struct stat*>::iterator it = contents.begin();
157 n2.push_dentry( it->first );
158 return n2.get_path().c_str();
163 const char *make_sub(const char *base) {
164 snprintf(sub_s, sizeof(sub_s), "%s.%d", base, rand() % 100);
172 SyntheticClient(StandaloneClient *client, int w = -1);
181 if (run_only == client->get_nodeid())
190 run_until = utime_t();
193 // run() will do one of these things:
203 string get_sarg(int seq);
205 int i = iargs.front();
210 bool time_to_stop() {
211 utime_t now = ceph_clock_now();
212 if (0) cout << "time_to_stop .. now " << now
213 << " until " << run_until
214 << " start " << run_start
216 if (run_until.sec() && now > run_until)
222 string compose_path(string& prefix, char *rest) {
223 return prefix + rest;
226 int full_walk(string& fromdir);
227 int random_walk(int n);
229 int dump_placement(string& fn);
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);
238 int create_shared(int num);
239 int open_shared(int num, int count);
241 int rm_file(string& fn);
242 int write_file(string& fn, int mb, loff_t chunk);
243 int write_fd(int fd, int size, int wrsize);
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);
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);
252 int read_random(string& fn, int mb, int chunk);
253 int read_random_ex(string& fn, int mb, int chunk);
255 int overload_osd_0(int n, int sie, int wrsize);
256 int check_first_primary(int fd);
258 int clean_dir(string& basedir);
260 int play_trace(Trace& t, string& prefix, bool metadata_only=false);
262 void make_dir_mess(const char *basedir, int n);
265 int thrash_links(const char *basedir, int dirs, int files, int depth, int n);
267 void import_find(const char *basedir, const char *find, bool writedata);
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);
273 int chunk_file(string &filename);
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);