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>
|
|
|
|
using namespace std;
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
#include "msg/SimpleMessenger.h"
|
|
|
|
|
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"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2011-09-22 03:59:58 +00:00
|
|
|
#if !defined(DARWIN) && !defined(__FreeBSD__)
|
2007-10-17 23:34:54 +00:00
|
|
|
#include <envz.h>
|
2011-09-22 03:59:58 +00:00
|
|
|
#endif // DARWIN || __FreeBSD__
|
2007-10-17 23:34:54 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.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
|
|
|
|
2011-06-17 03:15:24 +00:00
|
|
|
global_init(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
|
|
|
|
|
|
|
|
vec_to_argv(args, argc, argv);
|
|
|
|
|
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;
|
2011-06-07 17:38:54 +00:00
|
|
|
SimpleMessenger* messengers[g_conf->num_client];
|
|
|
|
MonClient* mclients[g_conf->num_client];
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2011-09-21 23:28:43 +00:00
|
|
|
cout << "ceph-syn: starting " << g_conf->num_client << " syn client(s)" << std::endl;
|
2011-06-07 17:38:54 +00:00
|
|
|
for (int i=0; i<g_conf->num_client; i++) {
|
2011-06-21 19:28:16 +00:00
|
|
|
messengers[i] = new SimpleMessenger(g_ceph_context);
|
2010-01-08 21:42:46 +00:00
|
|
|
messengers[i]->register_entity(entity_name_t(entity_name_t::TYPE_CLIENT,-1));
|
2011-11-21 18:12:29 +00:00
|
|
|
messengers[i]->bind(g_conf->public_addr, i * 1000000 + getpid());
|
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();
|
|
|
|
Client *client = new Client(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();
|
|
|
|
p++)
|
|
|
|
(*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
|
|
|
|
2011-06-07 17:38:54 +00:00
|
|
|
for (int i = 0; i < g_conf->num_client; ++i) {
|
2010-01-08 21:42:46 +00:00
|
|
|
// wait for messenger to finish
|
|
|
|
delete mclients[i];
|
|
|
|
messengers[i]->wait();
|
|
|
|
messengers[i]->destroy();
|
|
|
|
}
|
2007-10-17 23:34:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|