]> git.proxmox.com Git - ceph.git/blame - ceph/src/client/SyntheticClient.h
bump version to 12.0.3-pve3
[ceph.git] / ceph / src / client / SyntheticClient.h
CommitLineData
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
97void parse_syn_options(vector<const char*>& args);
98
99class SyntheticClient {
100 Client *client;
101 int whoami;
102
103 pthread_t thread_id;
104
105 Distribution op_dist;
106
107 void init_op_dist();
108 int get_op();
109
110
111 filepath cwd;
112 map<string, struct stat*> contents;
113 set<string> subdirs;
114 bool did_readdir;
115 set<int> open_files;
116
117 void up();
118
119 void clear_dir() {
120 contents.clear();
121 subdirs.clear();
122 did_readdir = false;
123 }
124
125 int get_random_fh() {
126 int r = rand() % open_files.size();
127 set<int>::iterator it = open_files.begin();
128 while (r--) ++it;
129 return *it;
130 }
131
132
133 filepath n1;
134 const char *get_random_subdir() {
135 assert(!subdirs.empty());
136 int r = ((rand() % subdirs.size()) + (rand() % subdirs.size())) / 2; // non-uniform distn
137 set<string>::iterator it = subdirs.begin();
138 while (r--) ++it;
139
140 n1 = cwd;
141 n1.push_dentry( *it );
142 return n1.get_path().c_str();
143 }
144 filepath n2;
145 const char *get_random_sub() {
146 assert(!contents.empty());
147 int r = ((rand() % contents.size()) + (rand() % contents.size())) / 2; // non-uniform distn
148 if (cwd.depth() && cwd.last_dentry().length())
149 r += cwd.last_dentry().c_str()[0]; // slightly permuted
150 r %= contents.size();
151
152 map<string,struct stat*>::iterator it = contents.begin();
153 while (r--) ++it;
154
155 n2 = cwd;
156 n2.push_dentry( it->first );
157 return n2.get_path().c_str();
158 }
159
160 filepath sub;
161 char sub_s[50];
162 const char *make_sub(const char *base) {
163 snprintf(sub_s, sizeof(sub_s), "%s.%d", base, rand() % 100);
164 string f = sub_s;
165 sub = cwd;
166 sub.push_dentry(f);
167 return sub.c_str();
168 }
169
170 public:
171 SyntheticClient(Client *client, int w = -1);
172
173 int start_thread();
174 int join_thread();
175
176 int run();
177
178 bool run_me() {
179 if (run_only >= 0) {
180 if (run_only == client->get_nodeid())
181 return true;
182 else
183 return false;
184 }
185 return true;
186 }
187 void did_run_me() {
188 run_only = -1;
189 run_until = utime_t();
190 }
191
192 // run() will do one of these things:
193 list<int> modes;
194 list<string> sargs;
195 list<int> iargs;
196 utime_t run_start;
197 utime_t run_until;
198
199 client_t run_only;
200 client_t exclude;
201
202 string get_sarg(int seq);
203 int get_iarg() {
204 int i = iargs.front();
205 iargs.pop_front();
206 return i;
207 }
208
209 bool time_to_stop() {
210 utime_t now = ceph_clock_now();
211 if (0) cout << "time_to_stop .. now " << now
212 << " until " << run_until
213 << " start " << run_start
214 << std::endl;
215 if (run_until.sec() && now > run_until)
216 return true;
217 else
218 return false;
219 }
220
221 string compose_path(string& prefix, char *rest) {
222 return prefix + rest;
223 }
224
225 int full_walk(string& fromdir);
226 int random_walk(int n);
227
228 int dump_placement(string& fn);
229
230
231 int make_dirs(const char *basedir, int dirs, int files, int depth);
232 int stat_dirs(const char *basedir, int dirs, int files, int depth);
233 int read_dirs(const char *basedir, int dirs, int files, int depth);
234 int make_files(int num, int count, int priv, bool more);
235 int link_test();
236
237 int create_shared(int num);
238 int open_shared(int num, int count);
239
240 int rm_file(string& fn);
241 int write_file(string& fn, int mb, loff_t chunk);
242 int write_fd(int fd, int size, int wrsize);
243
244 int write_batch(int nfile, int mb, int chunk);
245 int read_file(const std::string& fn, int mb, int chunk, bool ignoreprint=false);
246
247 int create_objects(int nobj, int osize, int inflight);
248 int object_rw(int nobj, int osize, int wrpc, int overlap,
249 double rskew, double wskew);
250
251 int read_random(string& fn, int mb, int chunk);
252 int read_random_ex(string& fn, int mb, int chunk);
253
254 int overload_osd_0(int n, int sie, int wrsize);
255 int check_first_primary(int fd);
256
257 int clean_dir(string& basedir);
258
259 int play_trace(Trace& t, string& prefix, bool metadata_only=false);
260
261 void make_dir_mess(const char *basedir, int n);
262 void foo();
263
264 int thrash_links(const char *basedir, int dirs, int files, int depth, int n);
265
266 void import_find(const char *basedir, const char *find, bool writedata);
267
268 int lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name,
269 const UserPerm& perms);
270 int lookup_ino(inodeno_t ino, const UserPerm& perms);
271
272 int chunk_file(string &filename);
273
274 void mksnap(const char *base, const char *name, const UserPerm& perms);
275 void rmsnap(const char *base, const char *name, const UserPerm& perms);
276 void mksnapfile(const char *dir);
277
278};
279
280#endif