2007-10-17 23:34:54 +00:00
|
|
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
|
|
|
|
// vim: ts=8 sw=2 smarttab
|
|
|
|
/*
|
|
|
|
* Ceph - scalable distributed file system
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software
|
|
|
|
* Foundation. See file COPYING.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2011-02-22 16:38:45 +00:00
|
|
|
#include "common/config.h"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
|
|
|
#include "client/SyntheticClient.h"
|
|
|
|
#include "client/Client.h"
|
|
|
|
|
2012-03-14 23:33:39 +00:00
|
|
|
#include "msg/Messenger.h"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2008-03-08 00:26:35 +00:00
|
|
|
#include "mon/MonClient.h"
|
|
|
|
|
2007-10-17 23:34:54 +00:00
|
|
|
#include "common/Timer.h"
|
2011-06-17 03:15:24 +00:00
|
|
|
#include "global/global_init.h"
|
2011-02-20 17:18:03 +00:00
|
|
|
#include "common/ceph_argparse.h"
|
2011-11-21 21:32:45 +00:00
|
|
|
#include "common/pick_address.h"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2011-02-01 18:14:05 +00:00
|
|
|
extern int syn_filer_flags;
|
|
|
|
|
2008-07-08 23:44:43 +00:00
|
|
|
int main(int argc, const char **argv, char *envp[])
|
|
|
|
{
|
2011-09-21 23:28:43 +00:00
|
|
|
//cerr << "ceph-syn starting" << std::endl;
|
2008-01-01 22:04:31 +00:00
|
|
|
vector<const char*> args;
|
2007-10-17 23:34:54 +00:00
|
|
|
argv_to_vec(argc, argv, args);
|
2010-07-01 16:25:43 +00:00
|
|
|
|
2016-11-15 06:21:03 +00:00
|
|
|
auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
|
|
|
|
CODE_ENVIRONMENT_UTILITY, 0);
|
2011-06-21 19:28:16 +00:00
|
|
|
common_init_finish(g_ceph_context);
|
2010-07-01 16:25:43 +00:00
|
|
|
|
2007-10-17 23:34:54 +00:00
|
|
|
parse_syn_options(args); // for SyntheticClient
|
|
|
|
|
2013-05-22 16:52:27 +00:00
|
|
|
pick_addresses(g_ceph_context, CEPH_PICK_ADDRESS_PUBLIC);
|
2011-11-21 21:32:45 +00:00
|
|
|
|
2008-03-10 05:32:16 +00:00
|
|
|
// get monmap
|
2011-06-21 19:28:16 +00:00
|
|
|
MonClient mc(g_ceph_context);
|
2009-06-26 20:49:12 +00:00
|
|
|
if (mc.build_initial_monmap() < 0)
|
2008-03-10 05:32:16 +00:00
|
|
|
return -1;
|
|
|
|
|
2007-10-17 23:34:54 +00:00
|
|
|
list<Client*> clients;
|
|
|
|
list<SyntheticClient*> synclients;
|
2017-10-27 04:02:20 +00:00
|
|
|
vector<Messenger*> messengers{static_cast<unsigned>(num_client), nullptr};
|
|
|
|
vector<MonClient*> mclients{static_cast<unsigned>(num_client), nullptr};
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2017-05-12 02:49:35 +00:00
|
|
|
cout << "ceph-syn: starting " << num_client << " syn client(s)" << std::endl;
|
|
|
|
for (int i=0; i<num_client; i++) {
|
2015-09-21 22:46:42 +00:00
|
|
|
messengers[i] = Messenger::create_client_messenger(g_ceph_context,
|
|
|
|
"synclient");
|
2012-03-02 01:19:22 +00:00
|
|
|
messengers[i]->bind(g_conf->public_addr);
|
2011-06-21 19:28:16 +00:00
|
|
|
mclients[i] = new MonClient(g_ceph_context);
|
2010-01-08 21:42:46 +00:00
|
|
|
mclients[i]->build_initial_monmap();
|
2017-03-30 14:06:12 +00:00
|
|
|
auto client = new StandaloneClient(messengers[i], mclients[i]);
|
2011-02-01 18:14:05 +00:00
|
|
|
client->set_filer_flags(syn_filer_flags);
|
2007-10-17 23:34:54 +00:00
|
|
|
SyntheticClient *syn = new SyntheticClient(client);
|
|
|
|
clients.push_back(client);
|
|
|
|
synclients.push_back(syn);
|
2011-04-29 18:29:42 +00:00
|
|
|
messengers[i]->start();
|
2007-10-17 23:34:54 +00:00
|
|
|
}
|
|
|
|
|
2008-11-13 22:36:48 +00:00
|
|
|
for (list<SyntheticClient*>::iterator p = synclients.begin();
|
|
|
|
p != synclients.end();
|
2013-03-13 16:54:39 +00:00
|
|
|
++p)
|
2008-11-13 22:36:48 +00:00
|
|
|
(*p)->start_thread();
|
|
|
|
|
2010-02-11 17:06:18 +00:00
|
|
|
//cout << "waiting for client(s) to finish" << std::endl;
|
2007-10-17 23:34:54 +00:00
|
|
|
while (!clients.empty()) {
|
|
|
|
Client *client = clients.front();
|
|
|
|
SyntheticClient *syn = synclients.front();
|
|
|
|
clients.pop_front();
|
2010-01-08 21:42:46 +00:00
|
|
|
synclients.pop_front();
|
2007-10-17 23:34:54 +00:00
|
|
|
syn->join_thread();
|
|
|
|
delete syn;
|
|
|
|
delete client;
|
|
|
|
}
|
2010-01-08 21:42:46 +00:00
|
|
|
|
2017-05-12 02:49:35 +00:00
|
|
|
for (int i = 0; i < num_client; ++i) {
|
2010-01-08 21:42:46 +00:00
|
|
|
// wait for messenger to finish
|
|
|
|
delete mclients[i];
|
2012-09-24 20:31:15 +00:00
|
|
|
messengers[i]->shutdown();
|
2010-01-08 21:42:46 +00:00
|
|
|
messengers[i]->wait();
|
2012-03-02 19:08:51 +00:00
|
|
|
delete messengers[i];
|
2010-01-08 21:42:46 +00:00
|
|
|
}
|
2007-10-17 23:34:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|