]>
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 | #include <sys/stat.h> | |
16 | #include <iostream> | |
17 | #include <string> | |
7c673cae FG |
18 | |
19 | #include "common/config.h" | |
20 | ||
21 | #include "client/SyntheticClient.h" | |
22 | #include "client/Client.h" | |
23 | ||
24 | #include "msg/Messenger.h" | |
25 | ||
26 | #include "mon/MonClient.h" | |
27 | ||
28 | #include "common/Timer.h" | |
29 | #include "global/global_init.h" | |
30 | #include "common/ceph_argparse.h" | |
31 | #include "common/pick_address.h" | |
32 | ||
33 | #include <sys/types.h> | |
34 | #include <fcntl.h> | |
35 | ||
36 | extern int syn_filer_flags; | |
37 | ||
38 | int main(int argc, const char **argv, char *envp[]) | |
39 | { | |
40 | //cerr << "ceph-syn starting" << std::endl; | |
41 | vector<const char*> args; | |
42 | argv_to_vec(argc, argv, args); | |
43 | ||
44 | auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, | |
45 | CODE_ENVIRONMENT_UTILITY, 0); | |
46 | common_init_finish(g_ceph_context); | |
47 | ||
48 | parse_syn_options(args); // for SyntheticClient | |
49 | ||
50 | pick_addresses(g_ceph_context, CEPH_PICK_ADDRESS_PUBLIC); | |
51 | ||
52 | // get monmap | |
53 | MonClient mc(g_ceph_context); | |
54 | if (mc.build_initial_monmap() < 0) | |
55 | return -1; | |
56 | ||
57 | list<Client*> clients; | |
58 | list<SyntheticClient*> synclients; | |
11fdf7f2 TL |
59 | vector<Messenger*> messengers{static_cast<unsigned>(num_client), nullptr}; |
60 | vector<MonClient*> mclients{static_cast<unsigned>(num_client), nullptr}; | |
7c673cae | 61 | |
c07f9fc5 FG |
62 | cout << "ceph-syn: starting " << num_client << " syn client(s)" << std::endl; |
63 | for (int i=0; i<num_client; i++) { | |
7c673cae FG |
64 | messengers[i] = Messenger::create_client_messenger(g_ceph_context, |
65 | "synclient"); | |
11fdf7f2 | 66 | messengers[i]->bind(g_conf()->public_addr); |
7c673cae FG |
67 | mclients[i] = new MonClient(g_ceph_context); |
68 | mclients[i]->build_initial_monmap(); | |
69 | auto client = new StandaloneClient(messengers[i], mclients[i]); | |
70 | client->set_filer_flags(syn_filer_flags); | |
71 | SyntheticClient *syn = new SyntheticClient(client); | |
72 | clients.push_back(client); | |
73 | synclients.push_back(syn); | |
74 | messengers[i]->start(); | |
75 | } | |
76 | ||
77 | for (list<SyntheticClient*>::iterator p = synclients.begin(); | |
78 | p != synclients.end(); | |
79 | ++p) | |
80 | (*p)->start_thread(); | |
81 | ||
82 | //cout << "waiting for client(s) to finish" << std::endl; | |
83 | while (!clients.empty()) { | |
84 | Client *client = clients.front(); | |
85 | SyntheticClient *syn = synclients.front(); | |
86 | clients.pop_front(); | |
87 | synclients.pop_front(); | |
88 | syn->join_thread(); | |
89 | delete syn; | |
90 | delete client; | |
91 | } | |
92 | ||
c07f9fc5 | 93 | for (int i = 0; i < num_client; ++i) { |
7c673cae FG |
94 | // wait for messenger to finish |
95 | delete mclients[i]; | |
96 | messengers[i]->shutdown(); | |
97 | messengers[i]->wait(); | |
98 | delete messengers[i]; | |
99 | } | |
100 | return 0; | |
101 | } | |
102 |