diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/mon/MonCommand.h | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/mon/MonCommand.h')
-rw-r--r-- | src/mon/MonCommand.h | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/src/mon/MonCommand.h b/src/mon/MonCommand.h new file mode 100644 index 00000000..97c49127 --- /dev/null +++ b/src/mon/MonCommand.h @@ -0,0 +1,168 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2017 John Spray <john.spray@redhat.com> + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + +#pragma once + +#include <string> +#include "include/encoding.h" + +struct MonCommand { + std::string cmdstring; + std::string helpstring; + std::string module; + std::string req_perms; + uint64_t flags; + + // MonCommand flags + static const uint64_t FLAG_NONE = 0; + static const uint64_t FLAG_NOFORWARD = 1 << 0; + static const uint64_t FLAG_OBSOLETE = 1 << 1; + static const uint64_t FLAG_DEPRECATED = 1 << 2; + static const uint64_t FLAG_MGR = 1 << 3; + static const uint64_t FLAG_POLL = 1 << 4; + static const uint64_t FLAG_HIDDEN = 1 << 5; + + bool has_flag(uint64_t flag) const { return (flags & flag) != 0; } + void set_flag(uint64_t flag) { flags |= flag; } + void unset_flag(uint64_t flag) { flags &= ~flag; } + + void encode(bufferlist &bl) const { + ENCODE_START(1, 1, bl); + encode_bare(bl); + encode(flags, bl); + ENCODE_FINISH(bl); + } + + void decode(bufferlist::const_iterator &bl) { + DECODE_START(1, bl); + decode_bare(bl); + decode(flags, bl); + DECODE_FINISH(bl); + } + + /** + * Unversioned encoding for use within encode_array. + */ + void encode_bare(bufferlist &bl) const { + using ceph::encode; + encode(cmdstring, bl); + encode(helpstring, bl); + encode(module, bl); + encode(req_perms, bl); + std::string availability = "cli,rest"; // Removed field, for backward compat + encode(availability, bl); + } + void decode_bare(bufferlist::const_iterator &bl) { + using ceph::decode; + decode(cmdstring, bl); + decode(helpstring, bl); + decode(module, bl); + decode(req_perms, bl); + std::string availability; // Removed field, for backward compat + decode(availability, bl); + } + bool is_compat(const MonCommand* o) const { + return cmdstring == o->cmdstring && + module == o->module && req_perms == o->req_perms; + } + + bool is_noforward() const { + return has_flag(MonCommand::FLAG_NOFORWARD); + } + + bool is_obsolete() const { + return has_flag(MonCommand::FLAG_OBSOLETE); + } + + bool is_deprecated() const { + return has_flag(MonCommand::FLAG_DEPRECATED); + } + + bool is_mgr() const { + return has_flag(MonCommand::FLAG_MGR); + } + + bool is_hidden() const { + return has_flag(MonCommand::FLAG_HIDDEN); + } + + static void encode_array(const MonCommand *cmds, int size, bufferlist &bl) { + ENCODE_START(2, 1, bl); + uint16_t s = size; + encode(s, bl); + for (int i = 0; i < size; ++i) { + cmds[i].encode_bare(bl); + } + for (int i = 0; i < size; i++) { + encode(cmds[i].flags, bl); + } + ENCODE_FINISH(bl); + } + static void decode_array(MonCommand **cmds, int *size, + bufferlist::const_iterator &bl) { + DECODE_START(2, bl); + uint16_t s = 0; + decode(s, bl); + *size = s; + *cmds = new MonCommand[*size]; + for (int i = 0; i < *size; ++i) { + (*cmds)[i].decode_bare(bl); + } + if (struct_v >= 2) { + for (int i = 0; i < *size; i++) + decode((*cmds)[i].flags, bl); + } else { + for (int i = 0; i < *size; i++) + (*cmds)[i].flags = 0; + } + DECODE_FINISH(bl); + } + + // this uses a u16 for the count, so we need a special encoder/decoder. + static void encode_vector(const std::vector<MonCommand>& cmds, + bufferlist &bl) { + ENCODE_START(2, 1, bl); + uint16_t s = cmds.size(); + encode(s, bl); + for (unsigned i = 0; i < s; ++i) { + cmds[i].encode_bare(bl); + } + for (unsigned i = 0; i < s; i++) { + encode(cmds[i].flags, bl); + } + ENCODE_FINISH(bl); + } + static void decode_vector(std::vector<MonCommand> &cmds, + bufferlist::const_iterator &bl) { + DECODE_START(2, bl); + uint16_t s = 0; + decode(s, bl); + cmds.resize(s); + for (unsigned i = 0; i < s; ++i) { + cmds[i].decode_bare(bl); + } + if (struct_v >= 2) { + for (unsigned i = 0; i < s; i++) + decode(cmds[i].flags, bl); + } else { + for (unsigned i = 0; i < s; i++) + cmds[i].flags = 0; + } + DECODE_FINISH(bl); + } + + bool requires_perm(char p) const { + return (req_perms.find(p) != std::string::npos); + } +}; +WRITE_CLASS_ENCODER(MonCommand) |