From 2da821d537c9cdfd146d6b085da983e8943afc87 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Wed, 17 Aug 2022 12:44:42 +0000 Subject: [PATCH] osd, mds: fix the "heap" admin cmd printing always to error stream Before the patch `ceph::osd_cmds::heap()` was confusing the concepts of _stderr_ and _stdout_. This was the direct cause of the differences in output between `ceph tell` and `ceph daeamon`. Thanks to Laura Flores who made the extremely useful observation noted in https://tracker.ceph.com/issues/57119#note-3. Fixes: https://tracker.ceph.com/issues/57119 Resolves: rhbz#2119101 Signed-off-by: Radoslaw Zarzynski (cherry picked from commit 94436475c4c9a11a94dd21c619c9ae0014ac393d) --- src/mds/MDSDaemon.cc | 4 +++- src/osd/OSD.cc | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index f1c2f66941b62..fef8a18e002b5 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -183,7 +183,9 @@ void MDSDaemon::asok_command( if (cmd_getval(cmdmap, "value", value)) { heapcmd_vec.push_back(value); } - ceph_heap_profiler_handle_command(heapcmd_vec, ss); + std::stringstream outss; + ceph_heap_profiler_handle_command(heapcmd_vec, outss); + outbl.append(outss); r = 0; } } else if (command == "cpu_profiler") { diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index c1b2a6503bf5a..a21b04a688db0 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1991,7 +1991,10 @@ void OSDService::_queue_for_recovery( // Commands shared between OSD's console and admin console: namespace ceph::osd_cmds { -int heap(CephContext& cct, const cmdmap_t& cmdmap, Formatter& f, std::ostream& os); +int heap(CephContext& cct, + const cmdmap_t& cmdmap, + std::ostream& outos, + std::ostream& erros); } // namespace ceph::osd_cmds @@ -2896,7 +2899,9 @@ will start to track new ops received afterwards."; } else if (prefix == "heap") { - ret = ceph::osd_cmds::heap(*cct, cmdmap, *f, ss); + std::stringstream outss; + ret = ceph::osd_cmds::heap(*cct, cmdmap, outss, ss); + outbl.append(outss); } else if (prefix == "debug dump_missing") { @@ -11222,17 +11227,19 @@ void OSD::ShardedOpWQ::stop_for_fast_shutdown() namespace ceph::osd_cmds { -int heap(CephContext& cct, const cmdmap_t& cmdmap, Formatter& f, - std::ostream& os) +int heap(CephContext& cct, + const cmdmap_t& cmdmap, + std::ostream& outos, + std::ostream& erros) { if (!ceph_using_tcmalloc()) { - os << "could not issue heap profiler command -- not using tcmalloc!"; + erros << "could not issue heap profiler command -- not using tcmalloc!"; return -EOPNOTSUPP; } string cmd; if (!cmd_getval(cmdmap, "heapcmd", cmd)) { - os << "unable to get value for command \"" << cmd << "\""; + erros << "unable to get value for command \"" << cmd << "\""; return -EINVAL; } @@ -11244,7 +11251,7 @@ int heap(CephContext& cct, const cmdmap_t& cmdmap, Formatter& f, cmd_vec.push_back(val); } - ceph_heap_profiler_handle_command(cmd_vec, os); + ceph_heap_profiler_handle_command(cmd_vec, outos); return 0; } -- 2.39.5