From d02d77f334d8d5f627bba6082bacb24edf0a2c72 Mon Sep 17 00:00:00 2001 From: Jimyeong Lee Date: Mon, 17 Jul 2023 00:42:12 +0900 Subject: [PATCH] client: Add multi_target_id to handle libcephfs mds_spce=* command To fix multi target MDSs command result overwritten issue, add multi_target_id feature in CommandTable. Also, add multi_target_id in CommandOp to track all the multi target commands end to make formatted result Signed-off-by: Jimyeong Lee --- src/client/Client.h | 1 + src/common/CommandTable.h | 42 +++++++++++++++++++++++++++++++++++---- src/mgr/MgrClient.h | 1 + 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/client/Client.h b/src/client/Client.h index 1e4d5890d19..53df27e409e 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -97,6 +97,7 @@ class MDSCommandOp : public CommandOp mds_gid_t mds_gid; explicit MDSCommandOp(ceph_tid_t t) : CommandOp(t) {} + explicit MDSCommandOp(ceph_tid_t t, ceph_tid_t multi_id) : CommandOp(t, multi_id) {} }; /* error code for ceph_fuse */ diff --git a/src/common/CommandTable.h b/src/common/CommandTable.h index 53218d65351..672161af652 100644 --- a/src/common/CommandTable.h +++ b/src/common/CommandTable.h @@ -23,6 +23,8 @@ class CommandOp public: ConnectionRef con; ceph_tid_t tid; + // multi_target_id == 0 means single target command + ceph_tid_t multi_target_id; std::vector cmd; ceph::buffer::list inbl; @@ -48,9 +50,11 @@ class CommandOp } } - CommandOp(const ceph_tid_t t) : tid(t), on_finish(nullptr), + CommandOp(const ceph_tid_t t) : tid(t), multi_target_id(0), on_finish(nullptr), outbl(nullptr), outs(nullptr) {} CommandOp() : tid(0), on_finish(nullptr), outbl(nullptr), outs(nullptr) {} + CommandOp(const ceph_tid_t t, const ceph_tid_t multi_id) : tid(t), multi_target_id(multi_id), + on_finish(nullptr), outbl(nullptr), outs(nullptr) {} }; /** @@ -62,23 +66,36 @@ class CommandTable { protected: ceph_tid_t last_tid; + ceph_tid_t last_multi_target_id; + std::map commands; + std::map > multi_targets; public: CommandTable() - : last_tid(0) + : last_tid(0), last_multi_target_id(0) {} ~CommandTable() { ceph_assert(commands.empty()); + ceph_assert(multi_targets.empty()); + } + + ceph_tid_t get_new_multi_target_id() + { + return ++last_multi_target_id; } - T& start_command() + T& start_command(ceph_tid_t multi_id=0) { ceph_tid_t tid = last_tid++; - commands.insert(std::make_pair(tid, T(tid)) ); + commands.insert(std::make_pair(tid, T(tid, multi_id)) ); + + if (multi_id != 0) { + multi_targets[multi_id].insert(tid); + } return commands.at(tid); } @@ -93,18 +110,35 @@ public: return commands.count(tid) > 0; } + std::size_t count_multi_commands(ceph_tid_t multi_id) + { + return multi_targets[multi_id].size(); + } + T& get_command(ceph_tid_t tid) { return commands.at(tid); } + bool get_multi_target_id(ceph_tid_t tid) const + { + return commands.at(tid).multi_target_id; + } + void erase(ceph_tid_t tid) { + ceph_tid_t multi_id = commands.at(tid).multi_target_id; commands.erase(tid); + multi_targets[multi_id].erase(tid); + + if(count_multi_commands(multi_id) == 0) { + multi_targets.erase(multi_id); + } } void clear() { commands.clear(); + multi_targets.clear(); } }; diff --git a/src/mgr/MgrClient.h b/src/mgr/MgrClient.h index a48ae163e18..1f9bb397fbe 100644 --- a/src/mgr/MgrClient.h +++ b/src/mgr/MgrClient.h @@ -54,6 +54,7 @@ class MgrCommand : public CommandOp bool tell = false; explicit MgrCommand(ceph_tid_t t) : CommandOp(t) {} + explicit MgrCommand(ceph_tid_t t, ceph_tid_t multi_id) : CommandOp(t, multi_id) {} MgrCommand() : CommandOp() {} }; -- 2.39.5