]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/MDSDaemon.cc
update sources to v12.2.0
[ceph.git] / ceph / src / mds / MDSDaemon.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
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.
12 *
13 */
14
15 #include <unistd.h>
16
17 #include "include/compat.h"
18 #include "include/types.h"
19 #include "include/str_list.h"
20
21 #include "common/Clock.h"
22 #include "common/HeartbeatMap.h"
23 #include "common/Timer.h"
24 #include "common/backport14.h"
25 #include "common/ceph_argparse.h"
26 #include "common/config.h"
27 #include "common/entity_name.h"
28 #include "common/errno.h"
29 #include "common/perf_counters.h"
30 #include "common/signal.h"
31 #include "common/version.h"
32
33 #include "global/signal_handler.h"
34
35 #include "msg/Messenger.h"
36 #include "mon/MonClient.h"
37
38 #include "osdc/Objecter.h"
39
40 #include "MDSMap.h"
41
42 #include "MDSDaemon.h"
43 #include "Server.h"
44 #include "Locker.h"
45
46 #include "SnapServer.h"
47 #include "SnapClient.h"
48
49 #include "events/ESession.h"
50 #include "events/ESubtreeMap.h"
51
52 #include "messages/MMDSMap.h"
53
54 #include "messages/MGenericMessage.h"
55
56 #include "messages/MMonCommand.h"
57 #include "messages/MCommand.h"
58 #include "messages/MCommandReply.h"
59
60 #include "auth/AuthAuthorizeHandler.h"
61 #include "auth/RotatingKeyRing.h"
62 #include "auth/KeyRing.h"
63
64 #include "perfglue/cpu_profiler.h"
65 #include "perfglue/heap_profiler.h"
66
67 #define dout_context g_ceph_context
68 #define dout_subsys ceph_subsys_mds
69 #undef dout_prefix
70 #define dout_prefix *_dout << "mds." << name << ' '
71
72
73 class MDSDaemon::C_MDS_Tick : public Context {
74 protected:
75 MDSDaemon *mds_daemon;
76 public:
77 explicit C_MDS_Tick(MDSDaemon *m) : mds_daemon(m) {}
78 void finish(int r) override {
79 assert(mds_daemon->mds_lock.is_locked_by_me());
80 mds_daemon->tick();
81 }
82 };
83
84 // cons/des
85 MDSDaemon::MDSDaemon(const std::string &n, Messenger *m, MonClient *mc) :
86 Dispatcher(m->cct),
87 mds_lock("MDSDaemon::mds_lock"),
88 stopping(false),
89 timer(m->cct, mds_lock),
90 beacon(m->cct, mc, n),
91 authorize_handler_cluster_registry(new AuthAuthorizeHandlerRegistry(m->cct,
92 m->cct->_conf->auth_supported.empty() ?
93 m->cct->_conf->auth_cluster_required :
94 m->cct->_conf->auth_supported)),
95 authorize_handler_service_registry(new AuthAuthorizeHandlerRegistry(m->cct,
96 m->cct->_conf->auth_supported.empty() ?
97 m->cct->_conf->auth_service_required :
98 m->cct->_conf->auth_supported)),
99 name(n),
100 messenger(m),
101 monc(mc),
102 mgrc(m->cct, m),
103 log_client(m->cct, messenger, &mc->monmap, LogClient::NO_FLAGS),
104 mds_rank(NULL),
105 tick_event(0),
106 asok_hook(NULL)
107 {
108 orig_argc = 0;
109 orig_argv = NULL;
110
111 clog = log_client.create_channel();
112
113 monc->set_messenger(messenger);
114
115 mdsmap = new MDSMap;
116 }
117
118 MDSDaemon::~MDSDaemon() {
119 Mutex::Locker lock(mds_lock);
120
121 delete mds_rank;
122 mds_rank = NULL;
123 delete mdsmap;
124 mdsmap = NULL;
125
126 delete authorize_handler_service_registry;
127 delete authorize_handler_cluster_registry;
128 }
129
130 class MDSSocketHook : public AdminSocketHook {
131 MDSDaemon *mds;
132 public:
133 explicit MDSSocketHook(MDSDaemon *m) : mds(m) {}
134 bool call(std::string command, cmdmap_t& cmdmap, std::string format,
135 bufferlist& out) override {
136 stringstream ss;
137 bool r = mds->asok_command(command, cmdmap, format, ss);
138 out.append(ss);
139 return r;
140 }
141 };
142
143 bool MDSDaemon::asok_command(string command, cmdmap_t& cmdmap, string format,
144 ostream& ss)
145 {
146 dout(1) << "asok_command: " << command << " (starting...)" << dendl;
147
148 Formatter *f = Formatter::create(format, "json-pretty", "json-pretty");
149 bool handled = false;
150 if (command == "status") {
151 dump_status(f);
152 handled = true;
153 } else {
154 if (mds_rank == NULL) {
155 dout(1) << "Can't run that command on an inactive MDS!" << dendl;
156 f->dump_string("error", "mds_not_active");
157 } else {
158 handled = mds_rank->handle_asok_command(command, cmdmap, f, ss);
159 }
160 }
161 f->flush(ss);
162 delete f;
163
164 dout(1) << "asok_command: " << command << " (complete)" << dendl;
165
166 return handled;
167 }
168
169 void MDSDaemon::dump_status(Formatter *f)
170 {
171 f->open_object_section("status");
172 f->dump_stream("cluster_fsid") << monc->get_fsid();
173 if (mds_rank) {
174 f->dump_int("whoami", mds_rank->get_nodeid());
175 } else {
176 f->dump_int("whoami", MDS_RANK_NONE);
177 }
178
179 f->dump_int("id", monc->get_global_id());
180 f->dump_string("want_state", ceph_mds_state_name(beacon.get_want_state()));
181 f->dump_string("state", ceph_mds_state_name(mdsmap->get_state_gid(mds_gid_t(
182 monc->get_global_id()))));
183 if (mds_rank) {
184 Mutex::Locker l(mds_lock);
185 mds_rank->dump_status(f);
186 }
187
188 f->dump_unsigned("mdsmap_epoch", mdsmap->get_epoch());
189 if (mds_rank) {
190 f->dump_unsigned("osdmap_epoch", mds_rank->get_osd_epoch());
191 f->dump_unsigned("osdmap_epoch_barrier", mds_rank->get_osd_epoch_barrier());
192 } else {
193 f->dump_unsigned("osdmap_epoch", 0);
194 f->dump_unsigned("osdmap_epoch_barrier", 0);
195 }
196 f->close_section(); // status
197 }
198
199 void MDSDaemon::set_up_admin_socket()
200 {
201 int r;
202 AdminSocket *admin_socket = g_ceph_context->get_admin_socket();
203 assert(asok_hook == nullptr);
204 asok_hook = new MDSSocketHook(this);
205 r = admin_socket->register_command("status", "status", asok_hook,
206 "high-level status of MDS");
207 assert(r == 0);
208 r = admin_socket->register_command("dump_ops_in_flight",
209 "dump_ops_in_flight", asok_hook,
210 "show the ops currently in flight");
211 assert(r == 0);
212 r = admin_socket->register_command("ops",
213 "ops", asok_hook,
214 "show the ops currently in flight");
215 assert(r == 0);
216 r = admin_socket->register_command("dump_blocked_ops", "dump_blocked_ops",
217 asok_hook,
218 "show the blocked ops currently in flight");
219 assert(r == 0);
220 r = admin_socket->register_command("dump_historic_ops", "dump_historic_ops",
221 asok_hook,
222 "show slowest recent ops");
223 assert(r == 0);
224 r = admin_socket->register_command("dump_historic_ops_by_duration", "dump_historic_ops_by_duration",
225 asok_hook,
226 "show slowest recent ops, sorted by op duration");
227 assert(r == 0);
228 r = admin_socket->register_command("scrub_path",
229 "scrub_path name=path,type=CephString "
230 "name=scrubops,type=CephChoices,"
231 "strings=force|recursive|repair,n=N,req=false",
232 asok_hook,
233 "scrub an inode and output results");
234 assert(r == 0);
235 r = admin_socket->register_command("tag path",
236 "tag path name=path,type=CephString"
237 " name=tag,type=CephString",
238 asok_hook,
239 "Apply scrub tag recursively");
240 assert(r == 0);
241 r = admin_socket->register_command("flush_path",
242 "flush_path name=path,type=CephString",
243 asok_hook,
244 "flush an inode (and its dirfrags)");
245 assert(r == 0);
246 r = admin_socket->register_command("export dir",
247 "export dir "
248 "name=path,type=CephString "
249 "name=rank,type=CephInt",
250 asok_hook,
251 "migrate a subtree to named MDS");
252 assert(r == 0);
253 r = admin_socket->register_command("dump cache",
254 "dump cache name=path,type=CephString,req=false",
255 asok_hook,
256 "dump metadata cache (optionally to a file)");
257 assert(r == 0);
258 r = admin_socket->register_command("dump tree",
259 "dump tree "
260 "name=root,type=CephString,req=true "
261 "name=depth,type=CephInt,req=false ",
262 asok_hook,
263 "dump metadata cache for subtree");
264 assert(r == 0);
265 r = admin_socket->register_command("session evict",
266 "session evict name=client_id,type=CephString",
267 asok_hook,
268 "Evict a CephFS client");
269 assert(r == 0);
270 r = admin_socket->register_command("osdmap barrier",
271 "osdmap barrier name=target_epoch,type=CephInt",
272 asok_hook,
273 "Wait until the MDS has this OSD map epoch");
274 assert(r == 0);
275 r = admin_socket->register_command("session ls",
276 "session ls",
277 asok_hook,
278 "Enumerate connected CephFS clients");
279 assert(r == 0);
280 r = admin_socket->register_command("flush journal",
281 "flush journal",
282 asok_hook,
283 "Flush the journal to the backing store");
284 assert(r == 0);
285 r = admin_socket->register_command("force_readonly",
286 "force_readonly",
287 asok_hook,
288 "Force MDS to read-only mode");
289 assert(r == 0);
290 r = admin_socket->register_command("get subtrees",
291 "get subtrees",
292 asok_hook,
293 "Return the subtree map");
294 assert(r == 0);
295 r = admin_socket->register_command("dirfrag split",
296 "dirfrag split "
297 "name=path,type=CephString,req=true "
298 "name=frag,type=CephString,req=true "
299 "name=bits,type=CephInt,req=true ",
300 asok_hook,
301 "Fragment directory by path");
302 assert(r == 0);
303 r = admin_socket->register_command("dirfrag merge",
304 "dirfrag merge "
305 "name=path,type=CephString,req=true "
306 "name=frag,type=CephString,req=true",
307 asok_hook,
308 "De-fragment directory by path");
309 assert(r == 0);
310 r = admin_socket->register_command("dirfrag ls",
311 "dirfrag ls "
312 "name=path,type=CephString,req=true",
313 asok_hook,
314 "List fragments in directory");
315 assert(r == 0);
316 }
317
318 void MDSDaemon::clean_up_admin_socket()
319 {
320 AdminSocket *admin_socket = g_ceph_context->get_admin_socket();
321 admin_socket->unregister_command("status");
322 admin_socket->unregister_command("dump_ops_in_flight");
323 admin_socket->unregister_command("ops");
324 admin_socket->unregister_command("dump_blocked_ops");
325 admin_socket->unregister_command("dump_historic_ops");
326 admin_socket->unregister_command("dump_historic_ops_by_duration");
327 admin_socket->unregister_command("scrub_path");
328 admin_socket->unregister_command("tag path");
329 admin_socket->unregister_command("flush_path");
330 admin_socket->unregister_command("export dir");
331 admin_socket->unregister_command("dump cache");
332 admin_socket->unregister_command("dump tree");
333 admin_socket->unregister_command("session evict");
334 admin_socket->unregister_command("osdmap barrier");
335 admin_socket->unregister_command("session ls");
336 admin_socket->unregister_command("flush journal");
337 admin_socket->unregister_command("force_readonly");
338 admin_socket->unregister_command("get subtrees");
339 admin_socket->unregister_command("dirfrag split");
340 admin_socket->unregister_command("dirfrag merge");
341 admin_socket->unregister_command("dirfrag ls");
342 delete asok_hook;
343 asok_hook = NULL;
344 }
345
346 const char** MDSDaemon::get_tracked_conf_keys() const
347 {
348 static const char* KEYS[] = {
349 "mds_op_complaint_time", "mds_op_log_threshold",
350 "mds_op_history_size", "mds_op_history_duration",
351 "mds_enable_op_tracker",
352 "mds_log_pause",
353 // clog & admin clog
354 "clog_to_monitors",
355 "clog_to_syslog",
356 "clog_to_syslog_facility",
357 "clog_to_syslog_level",
358 // PurgeQueue
359 "mds_max_purge_ops",
360 "mds_max_purge_ops_per_pg",
361 "mds_max_purge_files",
362 "clog_to_graylog",
363 "clog_to_graylog_host",
364 "clog_to_graylog_port",
365 "host",
366 "fsid",
367 NULL
368 };
369 return KEYS;
370 }
371
372 void MDSDaemon::handle_conf_change(const struct md_config_t *conf,
373 const std::set <std::string> &changed)
374 {
375 // We may be called within mds_lock (via `tell`) or outwith the
376 // lock (via admin socket `config set`), so handle either case.
377 const bool initially_locked = mds_lock.is_locked_by_me();
378 if (!initially_locked) {
379 mds_lock.Lock();
380 }
381
382 if (changed.count("mds_op_complaint_time") ||
383 changed.count("mds_op_log_threshold")) {
384 if (mds_rank) {
385 mds_rank->op_tracker.set_complaint_and_threshold(conf->mds_op_complaint_time,
386 conf->mds_op_log_threshold);
387 }
388 }
389 if (changed.count("mds_op_history_size") ||
390 changed.count("mds_op_history_duration")) {
391 if (mds_rank) {
392 mds_rank->op_tracker.set_history_size_and_duration(conf->mds_op_history_size,
393 conf->mds_op_history_duration);
394 }
395 }
396 if (changed.count("mds_enable_op_tracker")) {
397 if (mds_rank) {
398 mds_rank->op_tracker.set_tracking(conf->mds_enable_op_tracker);
399 }
400 }
401 if (changed.count("clog_to_monitors") ||
402 changed.count("clog_to_syslog") ||
403 changed.count("clog_to_syslog_level") ||
404 changed.count("clog_to_syslog_facility") ||
405 changed.count("clog_to_graylog") ||
406 changed.count("clog_to_graylog_host") ||
407 changed.count("clog_to_graylog_port") ||
408 changed.count("host") ||
409 changed.count("fsid")) {
410 if (mds_rank) {
411 mds_rank->update_log_config();
412 }
413 }
414
415 if (!g_conf->mds_log_pause && changed.count("mds_log_pause")) {
416 if (mds_rank) {
417 mds_rank->mdlog->kick_submitter();
418 }
419 }
420
421 if (mds_rank) {
422 mds_rank->handle_conf_change(conf, changed);
423 }
424
425 if (!initially_locked) {
426 mds_lock.Unlock();
427 }
428 }
429
430
431 int MDSDaemon::init()
432 {
433 dout(10) << sizeof(MDSCacheObject) << "\tMDSCacheObject" << dendl;
434 dout(10) << sizeof(CInode) << "\tCInode" << dendl;
435 dout(10) << sizeof(elist<void*>::item) << "\t elist<>::item *7=" << 7*sizeof(elist<void*>::item) << dendl;
436 dout(10) << sizeof(inode_t) << "\t inode_t " << dendl;
437 dout(10) << sizeof(nest_info_t) << "\t nest_info_t " << dendl;
438 dout(10) << sizeof(frag_info_t) << "\t frag_info_t " << dendl;
439 dout(10) << sizeof(SimpleLock) << "\t SimpleLock *5=" << 5*sizeof(SimpleLock) << dendl;
440 dout(10) << sizeof(ScatterLock) << "\t ScatterLock *3=" << 3*sizeof(ScatterLock) << dendl;
441 dout(10) << sizeof(CDentry) << "\tCDentry" << dendl;
442 dout(10) << sizeof(elist<void*>::item) << "\t elist<>::item" << dendl;
443 dout(10) << sizeof(SimpleLock) << "\t SimpleLock" << dendl;
444 dout(10) << sizeof(CDir) << "\tCDir " << dendl;
445 dout(10) << sizeof(elist<void*>::item) << "\t elist<>::item *2=" << 2*sizeof(elist<void*>::item) << dendl;
446 dout(10) << sizeof(fnode_t) << "\t fnode_t " << dendl;
447 dout(10) << sizeof(nest_info_t) << "\t nest_info_t *2" << dendl;
448 dout(10) << sizeof(frag_info_t) << "\t frag_info_t *2" << dendl;
449 dout(10) << sizeof(Capability) << "\tCapability " << dendl;
450 dout(10) << sizeof(xlist<void*>::item) << "\t xlist<>::item *2=" << 2*sizeof(xlist<void*>::item) << dendl;
451
452 messenger->add_dispatcher_tail(&beacon);
453 messenger->add_dispatcher_tail(this);
454
455 // get monmap
456 monc->set_messenger(messenger);
457
458 monc->set_want_keys(CEPH_ENTITY_TYPE_MON | CEPH_ENTITY_TYPE_OSD |
459 CEPH_ENTITY_TYPE_MDS | CEPH_ENTITY_TYPE_MGR);
460 int r = 0;
461 r = monc->init();
462 if (r < 0) {
463 derr << "ERROR: failed to get monmap: " << cpp_strerror(-r) << dendl;
464 mds_lock.Lock();
465 suicide();
466 mds_lock.Unlock();
467 return r;
468 }
469
470 // tell monc about log_client so it will know about mon session resets
471 monc->set_log_client(&log_client);
472
473 r = monc->authenticate();
474 if (r < 0) {
475 derr << "ERROR: failed to authenticate: " << cpp_strerror(-r) << dendl;
476 mds_lock.Lock();
477 suicide();
478 mds_lock.Unlock();
479 return r;
480 }
481
482 int rotating_auth_attempts = 0;
483 while (monc->wait_auth_rotating(30.0) < 0) {
484 if (++rotating_auth_attempts <= g_conf->max_rotating_auth_attempts) {
485 derr << "unable to obtain rotating service keys; retrying" << dendl;
486 continue;
487 }
488 derr << "ERROR: failed to refresh rotating keys, "
489 << "maximum retry time reached." << dendl;
490 mds_lock.Lock();
491 suicide();
492 mds_lock.Unlock();
493 return -ETIMEDOUT;
494 }
495
496 mgrc.init();
497 messenger->add_dispatcher_head(&mgrc);
498
499 mds_lock.Lock();
500 if (beacon.get_want_state() == CEPH_MDS_STATE_DNE) {
501 dout(4) << __func__ << ": terminated already, dropping out" << dendl;
502 mds_lock.Unlock();
503 return 0;
504 }
505
506 monc->sub_want("mdsmap", 0, 0);
507 monc->sub_want("mgrmap", 0, 0);
508 monc->renew_subs();
509
510 mds_lock.Unlock();
511
512 // Set up admin socket before taking mds_lock, so that ordering
513 // is consistent (later we take mds_lock within asok callbacks)
514 set_up_admin_socket();
515 g_conf->add_observer(this);
516 mds_lock.Lock();
517 if (beacon.get_want_state() == MDSMap::STATE_DNE) {
518 suicide(); // we could do something more graceful here
519 dout(4) << __func__ << ": terminated already, dropping out" << dendl;
520 mds_lock.Unlock();
521 return 0;
522 }
523
524 timer.init();
525
526 beacon.init(mdsmap);
527 messenger->set_myname(entity_name_t::MDS(MDS_RANK_NONE));
528
529 // schedule tick
530 reset_tick();
531 mds_lock.Unlock();
532
533 return 0;
534 }
535
536 void MDSDaemon::reset_tick()
537 {
538 // cancel old
539 if (tick_event) timer.cancel_event(tick_event);
540
541 // schedule
542 tick_event = new C_MDS_Tick(this);
543 timer.add_event_after(g_conf->mds_tick_interval, tick_event);
544 }
545
546 void MDSDaemon::tick()
547 {
548 // reschedule
549 reset_tick();
550
551 // Call through to subsystems' tick functions
552 if (mds_rank) {
553 mds_rank->tick();
554 }
555 }
556
557 void MDSDaemon::send_command_reply(MCommand *m, MDSRank *mds_rank,
558 int r, bufferlist outbl,
559 const std::string& outs)
560 {
561 Session *session = static_cast<Session *>(m->get_connection()->get_priv());
562 assert(session != NULL);
563 // If someone is using a closed session for sending commands (e.g.
564 // the ceph CLI) then we should feel free to clean up this connection
565 // as soon as we've sent them a response.
566 const bool live_session = mds_rank &&
567 mds_rank->sessionmap.get_session(session->info.inst.name) != nullptr
568 && session->get_state_seq() > 0;
569
570 if (!live_session) {
571 // This session only existed to issue commands, so terminate it
572 // as soon as we can.
573 assert(session->is_closed());
574 session->connection->mark_disposable();
575 session->put();
576 }
577
578 MCommandReply *reply = new MCommandReply(r, outs);
579 reply->set_tid(m->get_tid());
580 reply->set_data(outbl);
581 m->get_connection()->send_message(reply);
582 }
583
584 /* This function DOES put the passed message before returning*/
585 void MDSDaemon::handle_command(MCommand *m)
586 {
587 Session *session = static_cast<Session *>(m->get_connection()->get_priv());
588 assert(session != NULL);
589
590 int r = 0;
591 cmdmap_t cmdmap;
592 std::stringstream ss;
593 std::string outs;
594 bufferlist outbl;
595 Context *run_after = NULL;
596 bool need_reply = true;
597
598 if (!session->auth_caps.allow_all()) {
599 dout(1) << __func__
600 << ": received command from client without `tell` capability: "
601 << m->get_connection()->peer_addr << dendl;
602
603 ss << "permission denied";
604 r = -EPERM;
605 } else if (m->cmd.empty()) {
606 r = -EINVAL;
607 ss << "no command given";
608 outs = ss.str();
609 } else if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) {
610 r = -EINVAL;
611 outs = ss.str();
612 } else {
613 r = _handle_command(cmdmap, m, &outbl, &outs, &run_after, &need_reply);
614 }
615
616 if (need_reply) {
617 send_command_reply(m, mds_rank, r, outbl, outs);
618 }
619
620 if (run_after) {
621 run_after->complete(0);
622 }
623
624 m->put();
625 }
626
627
628 struct MDSCommand {
629 string cmdstring;
630 string helpstring;
631 string module;
632 string perm;
633 string availability;
634 } mds_commands[] = {
635
636 #define COMMAND(parsesig, helptext, module, perm, availability) \
637 {parsesig, helptext, module, perm, availability},
638
639 COMMAND("injectargs " \
640 "name=injected_args,type=CephString,n=N",
641 "inject configuration arguments into running MDS",
642 "mds", "*", "cli,rest")
643 COMMAND("config set " \
644 "name=key,type=CephString name=value,type=CephString",
645 "Set a configuration option at runtime (not persistent)",
646 "mds", "*", "cli,rest")
647 COMMAND("exit",
648 "Terminate this MDS",
649 "mds", "*", "cli,rest")
650 COMMAND("respawn",
651 "Restart this MDS",
652 "mds", "*", "cli,rest")
653 COMMAND("session kill " \
654 "name=session_id,type=CephInt",
655 "End a client session",
656 "mds", "*", "cli,rest")
657 COMMAND("cpu_profiler " \
658 "name=arg,type=CephChoices,strings=status|flush",
659 "run cpu profiling on daemon", "mds", "rw", "cli,rest")
660 COMMAND("session ls " \
661 "name=filters,type=CephString,n=N,req=false",
662 "List client sessions", "mds", "r", "cli,rest")
663 COMMAND("client ls " \
664 "name=filters,type=CephString,n=N,req=false",
665 "List client sessions", "mds", "r", "cli,rest")
666 COMMAND("session evict " \
667 "name=filters,type=CephString,n=N,req=false",
668 "Evict client session(s)", "mds", "rw", "cli,rest")
669 COMMAND("client evict " \
670 "name=filters,type=CephString,n=N,req=false",
671 "Evict client session(s)", "mds", "rw", "cli,rest")
672 COMMAND("damage ls",
673 "List detected metadata damage", "mds", "r", "cli,rest")
674 COMMAND("damage rm name=damage_id,type=CephInt",
675 "Remove a damage table entry", "mds", "rw", "cli,rest")
676 COMMAND("version", "report version of MDS", "mds", "r", "cli,rest")
677 COMMAND("heap " \
678 "name=heapcmd,type=CephChoices,strings=dump|start_profiler|stop_profiler|release|stats", \
679 "show heap usage info (available only if compiled with tcmalloc)", \
680 "mds", "*", "cli,rest")
681 };
682
683
684 int MDSDaemon::_handle_command(
685 const cmdmap_t &cmdmap,
686 MCommand *m,
687 bufferlist *outbl,
688 std::string *outs,
689 Context **run_later,
690 bool *need_reply)
691 {
692 assert(outbl != NULL);
693 assert(outs != NULL);
694
695 class SuicideLater : public Context
696 {
697 MDSDaemon *mds;
698
699 public:
700 explicit SuicideLater(MDSDaemon *mds_) : mds(mds_) {}
701 void finish(int r) override {
702 // Wait a little to improve chances of caller getting
703 // our response before seeing us disappear from mdsmap
704 sleep(1);
705
706 mds->suicide();
707 }
708 };
709
710
711 class RespawnLater : public Context
712 {
713 MDSDaemon *mds;
714
715 public:
716
717 explicit RespawnLater(MDSDaemon *mds_) : mds(mds_) {}
718 void finish(int r) override {
719 // Wait a little to improve chances of caller getting
720 // our response before seeing us disappear from mdsmap
721 sleep(1);
722
723 mds->respawn();
724 }
725 };
726
727 std::stringstream ds;
728 std::stringstream ss;
729 std::string prefix;
730 std::string format;
731 std::unique_ptr<Formatter> f(Formatter::create(format));
732 cmd_getval(cct, cmdmap, "prefix", prefix);
733
734 int r = 0;
735
736 if (prefix == "get_command_descriptions") {
737 int cmdnum = 0;
738 std::unique_ptr<JSONFormatter> f(ceph::make_unique<JSONFormatter>());
739 f->open_object_section("command_descriptions");
740 for (MDSCommand *cp = mds_commands;
741 cp < &mds_commands[ARRAY_SIZE(mds_commands)]; cp++) {
742
743 ostringstream secname;
744 secname << "cmd" << setfill('0') << std::setw(3) << cmdnum;
745 dump_cmddesc_to_json(f.get(), secname.str(), cp->cmdstring, cp->helpstring,
746 cp->module, cp->perm, cp->availability, 0);
747 cmdnum++;
748 }
749 f->close_section(); // command_descriptions
750
751 f->flush(ds);
752 goto out;
753 }
754
755 cmd_getval(cct, cmdmap, "format", format);
756 if (prefix == "version") {
757 if (f) {
758 f->open_object_section("version");
759 f->dump_string("version", pretty_version_to_str());
760 f->close_section();
761 f->flush(ds);
762 } else {
763 ds << pretty_version_to_str();
764 }
765 } else if (prefix == "injectargs") {
766 vector<string> argsvec;
767 cmd_getval(cct, cmdmap, "injected_args", argsvec);
768
769 if (argsvec.empty()) {
770 r = -EINVAL;
771 ss << "ignoring empty injectargs";
772 goto out;
773 }
774 string args = argsvec.front();
775 for (vector<string>::iterator a = ++argsvec.begin(); a != argsvec.end(); ++a)
776 args += " " + *a;
777 r = cct->_conf->injectargs(args, &ss);
778 } else if (prefix == "config set") {
779 std::string key;
780 cmd_getval(cct, cmdmap, "key", key);
781 std::string val;
782 cmd_getval(cct, cmdmap, "value", val);
783 r = cct->_conf->set_val(key, val, true, &ss);
784 if (r == 0) {
785 cct->_conf->apply_changes(nullptr);
786 }
787 } else if (prefix == "exit") {
788 // We will send response before executing
789 ss << "Exiting...";
790 *run_later = new SuicideLater(this);
791 } else if (prefix == "respawn") {
792 // We will send response before executing
793 ss << "Respawning...";
794 *run_later = new RespawnLater(this);
795 } else if (prefix == "session kill") {
796 if (mds_rank == NULL) {
797 r = -EINVAL;
798 ss << "MDS not active";
799 goto out;
800 }
801 // FIXME harmonize `session kill` with admin socket session evict
802 int64_t session_id = 0;
803 bool got = cmd_getval(cct, cmdmap, "session_id", session_id);
804 assert(got);
805 bool killed = mds_rank->evict_client(session_id, false,
806 g_conf->mds_session_blacklist_on_evict,
807 ss);
808 if (!killed)
809 r = -ENOENT;
810 } else if (prefix == "heap") {
811 if (!ceph_using_tcmalloc()) {
812 r = -EOPNOTSUPP;
813 ss << "could not issue heap profiler command -- not using tcmalloc!";
814 } else {
815 string heapcmd;
816 cmd_getval(cct, cmdmap, "heapcmd", heapcmd);
817 vector<string> heapcmd_vec;
818 get_str_vec(heapcmd, heapcmd_vec);
819 ceph_heap_profiler_handle_command(heapcmd_vec, ds);
820 }
821 } else if (prefix == "cpu_profiler") {
822 string arg;
823 cmd_getval(cct, cmdmap, "arg", arg);
824 vector<string> argvec;
825 get_str_vec(arg, argvec);
826 cpu_profiler_handle_command(argvec, ds);
827 } else {
828 // Give MDSRank a shot at the command
829 if (mds_rank) {
830 bool handled = mds_rank->handle_command(cmdmap, m, &r, &ds, &ss,
831 need_reply);
832 if (handled) {
833 goto out;
834 }
835 }
836
837 // Neither MDSDaemon nor MDSRank know this command
838 std::ostringstream ss;
839 ss << "unrecognized command! " << prefix;
840 r = -EINVAL;
841 }
842
843 out:
844 *outs = ss.str();
845 outbl->append(ds);
846 return r;
847 }
848
849 /* This function deletes the passed message before returning. */
850
851 void MDSDaemon::handle_mds_map(MMDSMap *m)
852 {
853 version_t epoch = m->get_epoch();
854 dout(5) << "handle_mds_map epoch " << epoch << " from " << m->get_source() << dendl;
855
856 // is it new?
857 if (epoch <= mdsmap->get_epoch()) {
858 dout(5) << " old map epoch " << epoch << " <= " << mdsmap->get_epoch()
859 << ", discarding" << dendl;
860 m->put();
861 return;
862 }
863
864 entity_addr_t addr;
865
866 // keep old map, for a moment
867 MDSMap *oldmap = mdsmap;
868
869 // decode and process
870 mdsmap = new MDSMap;
871 mdsmap->decode(m->get_encoded());
872 const MDSMap::DaemonState new_state = mdsmap->get_state_gid(mds_gid_t(monc->get_global_id()));
873 const int incarnation = mdsmap->get_inc_gid(mds_gid_t(monc->get_global_id()));
874
875 monc->sub_got("mdsmap", mdsmap->get_epoch());
876
877 // Calculate my effective rank (either my owned rank or my
878 // standby_for_rank if in standby replay)
879 mds_rank_t whoami = mdsmap->get_rank_gid(mds_gid_t(monc->get_global_id()));
880
881 // verify compatset
882 CompatSet mdsmap_compat(get_mdsmap_compat_set_all());
883 dout(10) << " my compat " << mdsmap_compat << dendl;
884 dout(10) << " mdsmap compat " << mdsmap->compat << dendl;
885 if (!mdsmap_compat.writeable(mdsmap->compat)) {
886 dout(0) << "handle_mds_map mdsmap compatset " << mdsmap->compat
887 << " not writeable with daemon features " << mdsmap_compat
888 << ", killing myself" << dendl;
889 suicide();
890 goto out;
891 }
892
893 // mark down any failed peers
894 for (map<mds_gid_t,MDSMap::mds_info_t>::const_iterator p = oldmap->get_mds_info().begin();
895 p != oldmap->get_mds_info().end();
896 ++p) {
897 if (mdsmap->get_mds_info().count(p->first) == 0) {
898 dout(10) << " peer mds gid " << p->first << " removed from map" << dendl;
899 messenger->mark_down(p->second.addr);
900 }
901 }
902
903 if (whoami == MDS_RANK_NONE &&
904 new_state == MDSMap::STATE_STANDBY_REPLAY) {
905 whoami = mdsmap->get_mds_info_gid(mds_gid_t(monc->get_global_id())).standby_for_rank;
906 }
907
908 // see who i am
909 addr = messenger->get_myaddr();
910 dout(10) << "map says I am " << addr << " mds." << whoami << "." << incarnation
911 << " state " << ceph_mds_state_name(new_state) << dendl;
912
913 if (whoami == MDS_RANK_NONE) {
914 if (mds_rank != NULL) {
915 const auto myid = monc->get_global_id();
916 // We have entered a rank-holding state, we shouldn't be back
917 // here!
918 if (g_conf->mds_enforce_unique_name) {
919 if (mds_gid_t existing = mdsmap->find_mds_gid_by_name(name)) {
920 const MDSMap::mds_info_t& i = mdsmap->get_info_gid(existing);
921 if (i.global_id > myid) {
922 dout(1) << "map replaced me with another mds." << whoami
923 << " with gid (" << i.global_id << ") larger than myself ("
924 << myid << "); quitting!" << dendl;
925 // Call suicide() rather than respawn() because if someone else
926 // has taken our ID, we don't want to keep restarting and
927 // fighting them for the ID.
928 suicide();
929 m->put();
930 return;
931 }
932 }
933 }
934
935 dout(1) << "map removed me (mds." << whoami << " gid:"
936 << myid << ") from cluster due to lost contact; respawning" << dendl;
937 respawn();
938 }
939 // MDSRank not active: process the map here to see if we have
940 // been assigned a rank.
941 dout(10) << __func__ << ": handling map in rankless mode" << dendl;
942 _handle_mds_map(oldmap);
943 } else {
944
945 // Did we already hold a different rank? MDSMonitor shouldn't try
946 // to change that out from under me!
947 if (mds_rank && whoami != mds_rank->get_nodeid()) {
948 derr << "Invalid rank transition " << mds_rank->get_nodeid() << "->"
949 << whoami << dendl;
950 respawn();
951 }
952
953 // Did I previously not hold a rank? Initialize!
954 if (mds_rank == NULL) {
955 mds_rank = new MDSRankDispatcher(whoami, mds_lock, clog,
956 timer, beacon, mdsmap, messenger, monc,
957 new FunctionContext([this](int r){respawn();}),
958 new FunctionContext([this](int r){suicide();}));
959 dout(10) << __func__ << ": initializing MDS rank "
960 << mds_rank->get_nodeid() << dendl;
961 mds_rank->init();
962 }
963
964 // MDSRank is active: let him process the map, we have no say.
965 dout(10) << __func__ << ": handling map as rank "
966 << mds_rank->get_nodeid() << dendl;
967 mds_rank->handle_mds_map(m, oldmap);
968 }
969
970 out:
971 beacon.notify_mdsmap(mdsmap);
972 m->put();
973 delete oldmap;
974 }
975
976 void MDSDaemon::_handle_mds_map(MDSMap *oldmap)
977 {
978 MDSMap::DaemonState new_state = mdsmap->get_state_gid(mds_gid_t(monc->get_global_id()));
979
980 // Normal rankless case, we're marked as standby
981 if (new_state == MDSMap::STATE_STANDBY) {
982 beacon.set_want_state(mdsmap, new_state);
983 dout(1) << "handle_mds_map standby" << dendl;
984
985 return;
986 }
987
988 // Case where we thought we were standby, but MDSMap disagrees
989 if (beacon.get_want_state() == MDSMap::STATE_STANDBY) {
990 dout(10) << "dropped out of mdsmap, try to re-add myself" << dendl;
991 new_state = MDSMap::STATE_BOOT;
992 beacon.set_want_state(mdsmap, new_state);
993 return;
994 }
995
996 // Case where we have sent a boot beacon that isn't reflected yet
997 if (beacon.get_want_state() == MDSMap::STATE_BOOT) {
998 dout(10) << "not in map yet" << dendl;
999 }
1000 }
1001
1002 void MDSDaemon::handle_signal(int signum)
1003 {
1004 assert(signum == SIGINT || signum == SIGTERM);
1005 derr << "*** got signal " << sig_str(signum) << " ***" << dendl;
1006 {
1007 Mutex::Locker l(mds_lock);
1008 if (stopping) {
1009 return;
1010 }
1011 suicide();
1012 }
1013 }
1014
1015 void MDSDaemon::suicide()
1016 {
1017 assert(mds_lock.is_locked());
1018
1019 // make sure we don't suicide twice
1020 assert(stopping == false);
1021 stopping = true;
1022
1023 dout(1) << "suicide. wanted state "
1024 << ceph_mds_state_name(beacon.get_want_state()) << dendl;
1025
1026 if (tick_event) {
1027 timer.cancel_event(tick_event);
1028 tick_event = 0;
1029 }
1030
1031 //because add_observer is called after set_up_admin_socket
1032 //so we can use asok_hook to avoid assert in the remove_observer
1033 if (asok_hook != NULL)
1034 g_conf->remove_observer(this);
1035
1036 clean_up_admin_socket();
1037
1038 // Inform MDS we are going away, then shut down beacon
1039 beacon.set_want_state(mdsmap, MDSMap::STATE_DNE);
1040 if (!mdsmap->is_dne_gid(mds_gid_t(monc->get_global_id()))) {
1041 // Notify the MDSMonitor that we're dying, so that it doesn't have to
1042 // wait for us to go laggy. Only do this if we're actually in the
1043 // MDSMap, because otherwise the MDSMonitor will drop our message.
1044 beacon.send_and_wait(1);
1045 }
1046 beacon.shutdown();
1047
1048 mgrc.shutdown();
1049
1050 if (mds_rank) {
1051 mds_rank->shutdown();
1052 } else {
1053 timer.shutdown();
1054
1055 monc->shutdown();
1056 messenger->shutdown();
1057 }
1058 }
1059
1060 void MDSDaemon::respawn()
1061 {
1062 dout(1) << "respawn" << dendl;
1063
1064 char *new_argv[orig_argc+1];
1065 dout(1) << " e: '" << orig_argv[0] << "'" << dendl;
1066 for (int i=0; i<orig_argc; i++) {
1067 new_argv[i] = (char *)orig_argv[i];
1068 dout(1) << " " << i << ": '" << orig_argv[i] << "'" << dendl;
1069 }
1070 new_argv[orig_argc] = NULL;
1071
1072 /* Determine the path to our executable, test if Linux /proc/self/exe exists.
1073 * This allows us to exec the same executable even if it has since been
1074 * unlinked.
1075 */
1076 char exe_path[PATH_MAX] = "";
1077 if (readlink(PROCPREFIX "/proc/self/exe", exe_path, PATH_MAX-1) == -1) {
1078 /* Print CWD for the user's interest */
1079 char buf[PATH_MAX];
1080 char *cwd = getcwd(buf, sizeof(buf));
1081 assert(cwd);
1082 dout(1) << " cwd " << cwd << dendl;
1083
1084 /* Fall back to a best-effort: just running in our CWD */
1085 strncpy(exe_path, orig_argv[0], PATH_MAX-1);
1086 } else {
1087 dout(1) << "respawning with exe " << exe_path << dendl;
1088 strcpy(exe_path, PROCPREFIX "/proc/self/exe");
1089 }
1090
1091 dout(1) << " exe_path " << exe_path << dendl;
1092
1093 unblock_all_signals(NULL);
1094 execv(exe_path, new_argv);
1095
1096 dout(0) << "respawn execv " << orig_argv[0]
1097 << " failed with " << cpp_strerror(errno) << dendl;
1098
1099 // We have to assert out here, because suicide() returns, and callers
1100 // to respawn expect it never to return.
1101 ceph_abort();
1102 }
1103
1104
1105
1106 bool MDSDaemon::ms_dispatch(Message *m)
1107 {
1108 Mutex::Locker l(mds_lock);
1109 if (stopping) {
1110 return false;
1111 }
1112
1113 // Drop out early if shutting down
1114 if (beacon.get_want_state() == CEPH_MDS_STATE_DNE) {
1115 dout(10) << " stopping, discarding " << *m << dendl;
1116 m->put();
1117 return true;
1118 }
1119
1120 // First see if it's a daemon message
1121 const bool handled_core = handle_core_message(m);
1122 if (handled_core) {
1123 return true;
1124 }
1125
1126 // Not core, try it as a rank message
1127 if (mds_rank) {
1128 return mds_rank->ms_dispatch(m);
1129 } else {
1130 return false;
1131 }
1132 }
1133
1134 bool MDSDaemon::ms_get_authorizer(int dest_type, AuthAuthorizer **authorizer, bool force_new)
1135 {
1136 dout(10) << "MDSDaemon::ms_get_authorizer type="
1137 << ceph_entity_type_name(dest_type) << dendl;
1138
1139 /* monitor authorization is being handled on different layer */
1140 if (dest_type == CEPH_ENTITY_TYPE_MON)
1141 return true;
1142
1143 if (force_new) {
1144 if (monc->wait_auth_rotating(10) < 0)
1145 return false;
1146 }
1147
1148 *authorizer = monc->build_authorizer(dest_type);
1149 return *authorizer != NULL;
1150 }
1151
1152
1153 /*
1154 * high priority messages we always process
1155 */
1156 bool MDSDaemon::handle_core_message(Message *m)
1157 {
1158 switch (m->get_type()) {
1159 case CEPH_MSG_MON_MAP:
1160 ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON);
1161 m->put();
1162 break;
1163
1164 // MDS
1165 case CEPH_MSG_MDS_MAP:
1166 ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON | CEPH_ENTITY_TYPE_MDS);
1167 handle_mds_map(static_cast<MMDSMap*>(m));
1168 break;
1169
1170 // OSD
1171 case MSG_COMMAND:
1172 handle_command(static_cast<MCommand*>(m));
1173 break;
1174 case CEPH_MSG_OSD_MAP:
1175 ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON | CEPH_ENTITY_TYPE_OSD);
1176
1177 if (mds_rank) {
1178 mds_rank->handle_osd_map();
1179 }
1180 m->put();
1181 break;
1182
1183 case MSG_MON_COMMAND:
1184 ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON);
1185 clog->warn() << "dropping `mds tell` command from legacy monitor";
1186 m->put();
1187 break;
1188
1189 default:
1190 return false;
1191 }
1192 return true;
1193 }
1194
1195 void MDSDaemon::ms_handle_connect(Connection *con)
1196 {
1197 }
1198
1199 bool MDSDaemon::ms_handle_reset(Connection *con)
1200 {
1201 if (con->get_peer_type() != CEPH_ENTITY_TYPE_CLIENT)
1202 return false;
1203
1204 Mutex::Locker l(mds_lock);
1205 if (stopping) {
1206 return false;
1207 }
1208 dout(5) << "ms_handle_reset on " << con->get_peer_addr() << dendl;
1209 if (beacon.get_want_state() == CEPH_MDS_STATE_DNE)
1210 return false;
1211
1212 Session *session = static_cast<Session *>(con->get_priv());
1213 if (session) {
1214 if (session->is_closed()) {
1215 dout(3) << "ms_handle_reset closing connection for session " << session->info.inst << dendl;
1216 con->mark_down();
1217 con->set_priv(NULL);
1218 }
1219 session->put();
1220 } else {
1221 con->mark_down();
1222 }
1223 return false;
1224 }
1225
1226
1227 void MDSDaemon::ms_handle_remote_reset(Connection *con)
1228 {
1229 if (con->get_peer_type() != CEPH_ENTITY_TYPE_CLIENT)
1230 return;
1231
1232 Mutex::Locker l(mds_lock);
1233 if (stopping) {
1234 return;
1235 }
1236
1237 dout(5) << "ms_handle_remote_reset on " << con->get_peer_addr() << dendl;
1238 if (beacon.get_want_state() == CEPH_MDS_STATE_DNE)
1239 return;
1240
1241 Session *session = static_cast<Session *>(con->get_priv());
1242 if (session) {
1243 if (session->is_closed()) {
1244 dout(3) << "ms_handle_remote_reset closing connection for session " << session->info.inst << dendl;
1245 con->mark_down();
1246 con->set_priv(NULL);
1247 }
1248 session->put();
1249 }
1250 }
1251
1252 bool MDSDaemon::ms_handle_refused(Connection *con)
1253 {
1254 // do nothing for now
1255 return false;
1256 }
1257
1258 bool MDSDaemon::ms_verify_authorizer(Connection *con, int peer_type,
1259 int protocol, bufferlist& authorizer_data, bufferlist& authorizer_reply,
1260 bool& is_valid, CryptoKey& session_key)
1261 {
1262 Mutex::Locker l(mds_lock);
1263 if (stopping) {
1264 return false;
1265 }
1266 if (beacon.get_want_state() == CEPH_MDS_STATE_DNE)
1267 return false;
1268
1269 AuthAuthorizeHandler *authorize_handler = 0;
1270 switch (peer_type) {
1271 case CEPH_ENTITY_TYPE_MDS:
1272 authorize_handler = authorize_handler_cluster_registry->get_handler(protocol);
1273 break;
1274 default:
1275 authorize_handler = authorize_handler_service_registry->get_handler(protocol);
1276 }
1277 if (!authorize_handler) {
1278 dout(0) << "No AuthAuthorizeHandler found for protocol " << protocol << dendl;
1279 is_valid = false;
1280 return true;
1281 }
1282
1283 AuthCapsInfo caps_info;
1284 EntityName name;
1285 uint64_t global_id;
1286
1287 RotatingKeyRing *keys = monc->rotating_secrets.get();
1288 if (keys) {
1289 is_valid = authorize_handler->verify_authorizer(
1290 cct, keys,
1291 authorizer_data, authorizer_reply, name, global_id, caps_info,
1292 session_key);
1293 } else {
1294 dout(10) << __func__ << " no rotating_keys (yet), denied" << dendl;
1295 is_valid = false;
1296 }
1297
1298 if (is_valid) {
1299 entity_name_t n(con->get_peer_type(), global_id);
1300
1301 // We allow connections and assign Session instances to connections
1302 // even if we have not been assigned a rank, because clients with
1303 // "allow *" are allowed to connect and do 'tell' operations before
1304 // we have a rank.
1305 Session *s = NULL;
1306 if (mds_rank) {
1307 // If we do hold a rank, see if this is an existing client establishing
1308 // a new connection, rather than a new client
1309 s = mds_rank->sessionmap.get_session(n);
1310 }
1311
1312 // Wire up a Session* to this connection
1313 // It doesn't go into a SessionMap instance until it sends an explicit
1314 // request to open a session (initial state of Session is `closed`)
1315 if (!s) {
1316 s = new Session;
1317 s->info.auth_name = name;
1318 s->info.inst.addr = con->get_peer_addr();
1319 s->info.inst.name = n;
1320 dout(10) << " new session " << s << " for " << s->info.inst << " con " << con << dendl;
1321 con->set_priv(s);
1322 s->connection = con;
1323 } else {
1324 dout(10) << " existing session " << s << " for " << s->info.inst << " existing con " << s->connection
1325 << ", new/authorizing con " << con << dendl;
1326 con->set_priv(s->get());
1327
1328
1329
1330 // Wait until we fully accept the connection before setting
1331 // s->connection. In particular, if there are multiple incoming
1332 // connection attempts, they will all get their authorizer
1333 // validated, but some of them may "lose the race" and get
1334 // dropped. We only want to consider the winner(s). See
1335 // ms_handle_accept(). This is important for Sessions we replay
1336 // from the journal on recovery that don't have established
1337 // messenger state; we want the con from only the winning
1338 // connect attempt(s). (Normal reconnects that don't follow MDS
1339 // recovery are reconnected to the existing con by the
1340 // messenger.)
1341 }
1342
1343 if (caps_info.allow_all) {
1344 // Flag for auth providers that don't provide cap strings
1345 s->auth_caps.set_allow_all();
1346 } else {
1347 bufferlist::iterator p = caps_info.caps.begin();
1348 string auth_cap_str;
1349 try {
1350 ::decode(auth_cap_str, p);
1351
1352 dout(10) << __func__ << ": parsing auth_cap_str='" << auth_cap_str << "'" << dendl;
1353 std::ostringstream errstr;
1354 if (!s->auth_caps.parse(g_ceph_context, auth_cap_str, &errstr)) {
1355 dout(1) << __func__ << ": auth cap parse error: " << errstr.str()
1356 << " parsing '" << auth_cap_str << "'" << dendl;
1357 clog->warn() << name << " mds cap '" << auth_cap_str
1358 << "' does not parse: " << errstr.str();
1359 is_valid = false;
1360 }
1361 } catch (buffer::error& e) {
1362 // Assume legacy auth, defaults to:
1363 // * permit all filesystem ops
1364 // * permit no `tell` ops
1365 dout(1) << __func__ << ": cannot decode auth caps bl of length " << caps_info.caps.length() << dendl;
1366 is_valid = false;
1367 }
1368 }
1369 }
1370
1371 return true; // we made a decision (see is_valid)
1372 }
1373
1374
1375 void MDSDaemon::ms_handle_accept(Connection *con)
1376 {
1377 Mutex::Locker l(mds_lock);
1378 if (stopping) {
1379 return;
1380 }
1381
1382 Session *s = static_cast<Session *>(con->get_priv());
1383 dout(10) << "ms_handle_accept " << con->get_peer_addr() << " con " << con << " session " << s << dendl;
1384 if (s) {
1385 if (s->connection != con) {
1386 dout(10) << " session connection " << s->connection << " -> " << con << dendl;
1387 s->connection = con;
1388
1389 // send out any queued messages
1390 while (!s->preopen_out_queue.empty()) {
1391 con->send_message(s->preopen_out_queue.front());
1392 s->preopen_out_queue.pop_front();
1393 }
1394 }
1395 s->put();
1396 }
1397 }
1398
1399 bool MDSDaemon::is_clean_shutdown()
1400 {
1401 if (mds_rank) {
1402 return mds_rank->is_stopped();
1403 } else {
1404 return true;
1405 }
1406 }