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