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) 2011 New Dream Network
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.
15 #ifndef CEPH_COMMON_ADMIN_SOCKET_H
16 #define CEPH_COMMON_ADMIN_SOCKET_H
18 #include "common/Cond.h"
23 #define CEPH_ADMIN_SOCK_VERSION "2"
25 class AdminSocketHook {
27 virtual bool call(std::string command, cmdmap_t &cmdmap, std::string format,
29 virtual ~AdminSocketHook() {}
32 class AdminSocket : public Thread
35 AdminSocket(CephContext *cct);
36 ~AdminSocket() override;
39 * register an admin socket command
41 * The command is registered under a command string. Incoming
42 * commands are split by space and matched against the longest
43 * registered command. For example, if 'foo' and 'foo bar' are
44 * registered, and an incoming command is 'foo bar baz', it is
45 * matched with 'foo bar', while 'foo fud' will match 'foo'.
47 * The entire incoming command string is passed to the registred
50 * @param command command string
51 * @param cmddesc command syntax descriptor
52 * @param hook implementaiton
53 * @param help help text. if empty, command will not be included in 'help' output.
55 * @return 0 for success, -EEXIST if command already registered.
57 int register_command(std::string command, std::string cmddesc, AdminSocketHook *hook, std::string help);
60 * unregister an admin socket command.
62 * If a command is currently in progress, this will block until it
63 * is done. For that reason, you must not hold any locks required
64 * by your hook while you call this.
66 * @param command command string
67 * @return 0 on succest, -ENOENT if command dne.
69 int unregister_command(std::string command);
71 bool init(const std::string &path);
73 void chown(uid_t uid, gid_t gid);
74 void chmod(mode_t mode);
77 AdminSocket(const AdminSocket& rhs);
78 AdminSocket& operator=(const AdminSocket &rhs);
82 std::string create_shutdown_pipe(int *pipe_rd, int *pipe_wr);
83 std::string destroy_shutdown_pipe();
84 std::string bind_and_listen(const std::string &sock_path, int *fd);
86 void *entry() override;
97 Mutex m_lock; // protects m_hooks, m_descs, m_help
98 AdminSocketHook *m_version_hook, *m_help_hook, *m_getdescs_hook;
100 std::map<std::string,AdminSocketHook*> m_hooks;
101 std::map<std::string,std::string> m_descs;
102 std::map<std::string,std::string> m_help;
104 friend class AdminSocketTest;
105 friend class HelpHook;
106 friend class GetdescsHook;