]> git.proxmox.com Git - ceph.git/blame - ceph/src/mon/MonCommand.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / mon / MonCommand.h
CommitLineData
c07f9fc5
FG
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) 2017 John Spray <john.spray@redhat.com>
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#pragma once
15
16#include <string>
17#include "include/encoding.h"
18
19struct MonCommand {
20 std::string cmdstring;
21 std::string helpstring;
22 std::string module;
23 std::string req_perms;
c07f9fc5
FG
24 uint64_t flags;
25
26 // MonCommand flags
27 static const uint64_t FLAG_NONE = 0;
28 static const uint64_t FLAG_NOFORWARD = 1 << 0;
29 static const uint64_t FLAG_OBSOLETE = 1 << 1;
30 static const uint64_t FLAG_DEPRECATED = 1 << 2;
31 static const uint64_t FLAG_MGR = 1 << 3;
11fdf7f2
TL
32 static const uint64_t FLAG_POLL = 1 << 4;
33 static const uint64_t FLAG_HIDDEN = 1 << 5;
c07f9fc5
FG
34
35 bool has_flag(uint64_t flag) const { return (flags & flag) != 0; }
36 void set_flag(uint64_t flag) { flags |= flag; }
37 void unset_flag(uint64_t flag) { flags &= ~flag; }
38
39 void encode(bufferlist &bl) const {
40 ENCODE_START(1, 1, bl);
41 encode_bare(bl);
11fdf7f2 42 encode(flags, bl);
c07f9fc5
FG
43 ENCODE_FINISH(bl);
44 }
45
11fdf7f2 46 void decode(bufferlist::const_iterator &bl) {
c07f9fc5
FG
47 DECODE_START(1, bl);
48 decode_bare(bl);
11fdf7f2 49 decode(flags, bl);
c07f9fc5
FG
50 DECODE_FINISH(bl);
51 }
52
53 /**
54 * Unversioned encoding for use within encode_array.
55 */
56 void encode_bare(bufferlist &bl) const {
11fdf7f2
TL
57 using ceph::encode;
58 encode(cmdstring, bl);
59 encode(helpstring, bl);
60 encode(module, bl);
61 encode(req_perms, bl);
62 std::string availability = "cli,rest"; // Removed field, for backward compat
63 encode(availability, bl);
c07f9fc5 64 }
11fdf7f2
TL
65 void decode_bare(bufferlist::const_iterator &bl) {
66 using ceph::decode;
67 decode(cmdstring, bl);
68 decode(helpstring, bl);
69 decode(module, bl);
70 decode(req_perms, bl);
71 std::string availability; // Removed field, for backward compat
72 decode(availability, bl);
c07f9fc5
FG
73 }
74 bool is_compat(const MonCommand* o) const {
75 return cmdstring == o->cmdstring &&
11fdf7f2 76 module == o->module && req_perms == o->req_perms;
c07f9fc5
FG
77 }
78
79 bool is_noforward() const {
80 return has_flag(MonCommand::FLAG_NOFORWARD);
81 }
82
83 bool is_obsolete() const {
84 return has_flag(MonCommand::FLAG_OBSOLETE);
85 }
86
87 bool is_deprecated() const {
88 return has_flag(MonCommand::FLAG_DEPRECATED);
89 }
90
91 bool is_mgr() const {
92 return has_flag(MonCommand::FLAG_MGR);
93 }
94
11fdf7f2
TL
95 bool is_hidden() const {
96 return has_flag(MonCommand::FLAG_HIDDEN);
97 }
98
c07f9fc5
FG
99 static void encode_array(const MonCommand *cmds, int size, bufferlist &bl) {
100 ENCODE_START(2, 1, bl);
101 uint16_t s = size;
11fdf7f2 102 encode(s, bl);
c07f9fc5
FG
103 for (int i = 0; i < size; ++i) {
104 cmds[i].encode_bare(bl);
105 }
106 for (int i = 0; i < size; i++) {
11fdf7f2 107 encode(cmds[i].flags, bl);
c07f9fc5
FG
108 }
109 ENCODE_FINISH(bl);
110 }
111 static void decode_array(MonCommand **cmds, int *size,
11fdf7f2 112 bufferlist::const_iterator &bl) {
c07f9fc5
FG
113 DECODE_START(2, bl);
114 uint16_t s = 0;
11fdf7f2 115 decode(s, bl);
c07f9fc5
FG
116 *size = s;
117 *cmds = new MonCommand[*size];
118 for (int i = 0; i < *size; ++i) {
119 (*cmds)[i].decode_bare(bl);
120 }
121 if (struct_v >= 2) {
122 for (int i = 0; i < *size; i++)
11fdf7f2 123 decode((*cmds)[i].flags, bl);
c07f9fc5
FG
124 } else {
125 for (int i = 0; i < *size; i++)
126 (*cmds)[i].flags = 0;
127 }
128 DECODE_FINISH(bl);
129 }
130
d2e6a577
FG
131 // this uses a u16 for the count, so we need a special encoder/decoder.
132 static void encode_vector(const std::vector<MonCommand>& cmds,
133 bufferlist &bl) {
134 ENCODE_START(2, 1, bl);
135 uint16_t s = cmds.size();
11fdf7f2 136 encode(s, bl);
d2e6a577
FG
137 for (unsigned i = 0; i < s; ++i) {
138 cmds[i].encode_bare(bl);
139 }
140 for (unsigned i = 0; i < s; i++) {
11fdf7f2 141 encode(cmds[i].flags, bl);
d2e6a577
FG
142 }
143 ENCODE_FINISH(bl);
144 }
145 static void decode_vector(std::vector<MonCommand> &cmds,
11fdf7f2 146 bufferlist::const_iterator &bl) {
d2e6a577
FG
147 DECODE_START(2, bl);
148 uint16_t s = 0;
11fdf7f2 149 decode(s, bl);
d2e6a577
FG
150 cmds.resize(s);
151 for (unsigned i = 0; i < s; ++i) {
152 cmds[i].decode_bare(bl);
153 }
154 if (struct_v >= 2) {
155 for (unsigned i = 0; i < s; i++)
11fdf7f2 156 decode(cmds[i].flags, bl);
d2e6a577
FG
157 } else {
158 for (unsigned i = 0; i < s; i++)
159 cmds[i].flags = 0;
160 }
161 DECODE_FINISH(bl);
162 }
163
c07f9fc5
FG
164 bool requires_perm(char p) const {
165 return (req_perms.find(p) != std::string::npos);
166 }
167};
168WRITE_CLASS_ENCODER(MonCommand)