]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mon/MonCommand.h
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) 2017 John Spray <john.spray@redhat.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.
17 #include "include/encoding.h"
20 std::string cmdstring
;
21 std::string helpstring
;
23 std::string req_perms
;
24 std::string availability
;
28 static const uint64_t FLAG_NONE
= 0;
29 static const uint64_t FLAG_NOFORWARD
= 1 << 0;
30 static const uint64_t FLAG_OBSOLETE
= 1 << 1;
31 static const uint64_t FLAG_DEPRECATED
= 1 << 2;
32 static const uint64_t FLAG_MGR
= 1 << 3;
34 bool has_flag(uint64_t flag
) const { return (flags
& flag
) != 0; }
35 void set_flag(uint64_t flag
) { flags
|= flag
; }
36 void unset_flag(uint64_t flag
) { flags
&= ~flag
; }
38 void encode(bufferlist
&bl
) const {
39 ENCODE_START(1, 1, bl
);
45 void decode(bufferlist::iterator
&bl
) {
53 * Unversioned encoding for use within encode_array.
55 void encode_bare(bufferlist
&bl
) const {
56 ::encode(cmdstring
, bl
);
57 ::encode(helpstring
, bl
);
59 ::encode(req_perms
, bl
);
60 ::encode(availability
, bl
);
62 void decode_bare(bufferlist::iterator
&bl
) {
63 ::decode(cmdstring
, bl
);
64 ::decode(helpstring
, bl
);
66 ::decode(req_perms
, bl
);
67 ::decode(availability
, bl
);
69 bool is_compat(const MonCommand
* o
) const {
70 return cmdstring
== o
->cmdstring
&&
71 module
== o
->module
&& req_perms
== o
->req_perms
&&
72 availability
== o
->availability
;
75 bool is_noforward() const {
76 return has_flag(MonCommand::FLAG_NOFORWARD
);
79 bool is_obsolete() const {
80 return has_flag(MonCommand::FLAG_OBSOLETE
);
83 bool is_deprecated() const {
84 return has_flag(MonCommand::FLAG_DEPRECATED
);
88 return has_flag(MonCommand::FLAG_MGR
);
91 static void encode_array(const MonCommand
*cmds
, int size
, bufferlist
&bl
) {
92 ENCODE_START(2, 1, bl
);
95 for (int i
= 0; i
< size
; ++i
) {
96 cmds
[i
].encode_bare(bl
);
98 for (int i
= 0; i
< size
; i
++) {
99 ::encode(cmds
[i
].flags
, bl
);
103 static void decode_array(MonCommand
**cmds
, int *size
,
104 bufferlist::iterator
&bl
) {
109 *cmds
= new MonCommand
[*size
];
110 for (int i
= 0; i
< *size
; ++i
) {
111 (*cmds
)[i
].decode_bare(bl
);
114 for (int i
= 0; i
< *size
; i
++)
115 ::decode((*cmds
)[i
].flags
, bl
);
117 for (int i
= 0; i
< *size
; i
++)
118 (*cmds
)[i
].flags
= 0;
123 // this uses a u16 for the count, so we need a special encoder/decoder.
124 static void encode_vector(const std::vector
<MonCommand
>& cmds
,
126 ENCODE_START(2, 1, bl
);
127 uint16_t s
= cmds
.size();
129 for (unsigned i
= 0; i
< s
; ++i
) {
130 cmds
[i
].encode_bare(bl
);
132 for (unsigned i
= 0; i
< s
; i
++) {
133 ::encode(cmds
[i
].flags
, bl
);
137 static void decode_vector(std::vector
<MonCommand
> &cmds
,
138 bufferlist::iterator
&bl
) {
143 for (unsigned i
= 0; i
< s
; ++i
) {
144 cmds
[i
].decode_bare(bl
);
147 for (unsigned i
= 0; i
< s
; i
++)
148 ::decode(cmds
[i
].flags
, bl
);
150 for (unsigned i
= 0; i
< s
; i
++)
156 bool requires_perm(char p
) const {
157 return (req_perms
.find(p
) != std::string::npos
);
160 WRITE_CLASS_ENCODER(MonCommand
)