]>
git.proxmox.com Git - ceph.git/blob - ceph/src/tools/cephfs/MDSUtility.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 John Spray <john.spray@inktank.com>
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.
14 #include "MDSUtility.h"
15 #include "mon/MonClient.h"
17 #define dout_context g_ceph_context
18 #define dout_subsys ceph_subsys_mds
21 MDSUtility::MDSUtility() :
22 Dispatcher(g_ceph_context
),
24 finisher(g_ceph_context
, "MDSUtility", "fn_mds_utility"),
25 waiting_for_mds_map(NULL
),
28 monc
= new MonClient(g_ceph_context
, poolctx
);
29 messenger
= Messenger::create_client_messenger(g_ceph_context
, "mds");
31 objecter
= new Objecter(g_ceph_context
, messenger
, monc
, poolctx
);
35 MDSUtility::~MDSUtility()
44 ceph_assert(waiting_for_mds_map
== NULL
);
48 int MDSUtility::init()
50 // Initialize Messenger
54 objecter
->set_client_incarnation(0);
57 // Connect dispatchers before starting objecter
58 messenger
->add_dispatcher_tail(objecter
);
59 messenger
->add_dispatcher_tail(this);
61 // Initialize MonClient
62 if (monc
->build_initial_monmap() < 0) {
64 messenger
->shutdown();
69 monc
->set_want_keys(CEPH_ENTITY_TYPE_MON
|CEPH_ENTITY_TYPE_OSD
|CEPH_ENTITY_TYPE_MDS
);
70 monc
->set_messenger(messenger
);
72 int r
= monc
->authenticate();
74 derr
<< "Authentication failed, did you specify an MDS ID with a valid keyring?" << dendl
;
77 messenger
->shutdown();
82 client_t whoami
= monc
->get_global_id();
83 messenger
->set_myname(entity_name_t::CLIENT(whoami
.v
));
85 // Start Objecter and wait for OSD map
87 objecter
->wait_for_osd_map();
89 // Prepare to receive MDS map and request it
90 ceph::mutex init_lock
= ceph::make_mutex("MDSUtility:init");
91 ceph::condition_variable cond
;
93 ceph_assert(!fsmap
->get_epoch());
95 waiting_for_mds_map
= new C_SafeCond(init_lock
, cond
, &done
, NULL
);
97 monc
->sub_want("fsmap", 0, CEPH_SUBSCRIBE_ONETIME
);
101 dout(4) << "waiting for MDS map..." << dendl
;
103 std::unique_lock locker
{init_lock
};
104 cond
.wait(locker
, [&done
] { return done
; });
106 dout(4) << "Got MDS map " << fsmap
->get_epoch() << dendl
;
115 void MDSUtility::shutdown()
120 objecter
->shutdown();
123 messenger
->shutdown();
129 bool MDSUtility::ms_dispatch(Message
*m
)
131 std::lock_guard locker
{lock
};
132 switch (m
->get_type()) {
133 case CEPH_MSG_FS_MAP
:
134 handle_fs_map((MFSMap
*)m
);
136 case CEPH_MSG_OSD_MAP
:
146 void MDSUtility::handle_fs_map(MFSMap
* m
)
148 *fsmap
= m
->get_fsmap();
149 if (waiting_for_mds_map
) {
150 waiting_for_mds_map
->complete(0);
151 waiting_for_mds_map
= NULL
;