]>
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 lock("MDSUtility::lock"),
25 finisher(g_ceph_context
, "MDSUtility", "fn_mds_utility"),
26 waiting_for_mds_map(NULL
)
28 monc
= new MonClient(g_ceph_context
);
29 messenger
= Messenger::create_client_messenger(g_ceph_context
, "mds");
31 objecter
= new Objecter(g_ceph_context
, messenger
, monc
, NULL
, 0, 0);
35 MDSUtility::~MDSUtility()
41 assert(waiting_for_mds_map
== NULL
);
45 int MDSUtility::init()
47 // Initialize Messenger
48 int r
= messenger
->bind(g_conf
->public_addr
);
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 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 Mutex
init_lock("MDSUtility:init");
93 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
;
104 cond
.Wait(init_lock
);
106 dout(4) << "Got MDS map " << fsmap
->get_epoch() << dendl
;
114 void MDSUtility::shutdown()
119 objecter
->shutdown();
122 messenger
->shutdown();
127 bool MDSUtility::ms_dispatch(Message
*m
)
129 Mutex::Locker
locker(lock
);
130 switch (m
->get_type()) {
131 case CEPH_MSG_FS_MAP
:
132 handle_fs_map((MFSMap
*)m
);
134 case CEPH_MSG_OSD_MAP
:
144 void MDSUtility::handle_fs_map(MFSMap
* m
)
146 *fsmap
= m
->get_fsmap();
147 if (waiting_for_mds_map
) {
148 waiting_for_mds_map
->complete(0);
149 waiting_for_mds_map
= NULL
;
154 bool MDSUtility::ms_get_authorizer(int dest_type
, AuthAuthorizer
**authorizer
,
157 if (dest_type
== CEPH_ENTITY_TYPE_MON
)
161 if (monc
->wait_auth_rotating(10) < 0)
165 *authorizer
= monc
->build_authorizer(dest_type
);
166 return *authorizer
!= NULL
;