ceph/src/csyn.cc

105 lines
2.6 KiB
C++
Raw Normal View History

// -*- 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;
#include "config.h"
#include "client/SyntheticClient.h"
#include "client/Client.h"
#include "msg/SimpleMessenger.h"
#include "mon/MonClient.h"
#include "common/Timer.h"
2009-02-09 23:46:02 +00:00
#include "common/common_init.h"
#ifndef DARWIN
#include <envz.h>
#endif // DARWIN
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, const char **argv, char *envp[])
{
2008-01-01 22:04:31 +00:00
//cerr << "csyn starting" << std::endl;
vector<const char*> args;
argv_to_vec(argc, argv, args);
common_set_defaults(false);
common_init(args, "csyn", true);
set_foreground_logging();
parse_syn_options(args); // for SyntheticClient
vec_to_argv(args, argc, argv);
if (g_conf.clock_tare) g_clock.tare();
// get monmap
MonClient mc;
if (mc.build_initial_monmap() < 0)
return -1;
list<Client*> clients;
list<SyntheticClient*> synclients;
2010-01-08 21:42:46 +00:00
SimpleMessenger* messengers[g_conf.num_client];
MonClient* mclients[g_conf.num_client];
2010-02-11 17:06:18 +00:00
cout << "csyn: starting " << g_conf.num_client << " syn client(s)" << std::endl;
for (int i=0; i<g_conf.num_client; i++) {
2010-01-08 21:42:46 +00:00
messengers[i] = new SimpleMessenger();
messengers[i]->register_entity(entity_name_t(entity_name_t::TYPE_CLIENT,-1));
messengers[i]->bind();
mclients[i] = new MonClient();
mclients[i]->build_initial_monmap();
Client *client = new Client(messengers[i], mclients[i]);
SyntheticClient *syn = new SyntheticClient(client);
clients.push_back(client);
synclients.push_back(syn);
2010-01-08 21:42:46 +00:00
messengers[i]->start();
}
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;
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();
syn->join_thread();
delete syn;
delete client;
}
2010-01-08 21:42:46 +00:00
for (int i = 0; i < g_conf.num_client; ++i) {
// wait for messenger to finish
delete mclients[i];
messengers[i]->wait();
messengers[i]->destroy();
}
return 0;
}