]> git.proxmox.com Git - ceph.git/blob - ceph/src/ceph_syn.cc
import ceph 16.2.6
[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
19 #include "common/config.h"
20
21 #include "common/async/context_pool.h"
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 ceph::async::io_context_pool poolctx(1);
55 MonClient mc(g_ceph_context, poolctx);
56 if (mc.build_initial_monmap() < 0)
57 return -1;
58
59 list<Client*> clients;
60 list<SyntheticClient*> synclients;
61 vector<Messenger*> messengers{static_cast<unsigned>(num_client), nullptr};
62 vector<MonClient*> mclients{static_cast<unsigned>(num_client), nullptr};
63
64 cout << "ceph-syn: starting " << num_client << " syn client(s)" << std::endl;
65 for (int i=0; i<num_client; i++) {
66 messengers[i] = Messenger::create_client_messenger(g_ceph_context,
67 "synclient");
68 mclients[i] = new MonClient(g_ceph_context, poolctx);
69 mclients[i]->build_initial_monmap();
70 auto client = new StandaloneClient(messengers[i], mclients[i], poolctx);
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 poolctx.stop();
84
85 //cout << "waiting for client(s) to finish" << std::endl;
86 while (!clients.empty()) {
87 Client *client = clients.front();
88 SyntheticClient *syn = synclients.front();
89 clients.pop_front();
90 synclients.pop_front();
91 syn->join_thread();
92 delete syn;
93 delete client;
94 }
95
96 for (int i = 0; i < num_client; ++i) {
97 // wait for messenger to finish
98 delete mclients[i];
99 messengers[i]->shutdown();
100 messengers[i]->wait();
101 delete messengers[i];
102 }
103 return 0;
104 }