From: David Zafman Date: Tue, 30 Aug 2016 18:05:16 +0000 (-0700) Subject: common: Move cleanbin() function to common/util.cc X-Git-Tag: v10.2.7~24^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=83ea077ee560d31a5c302a62b55451a2571fda8d;p=ceph.git common: Move cleanbin() function to common/util.cc Signed-off-by: David Zafman (cherry picked from commit 5c79074ffaee34b2956d9dfc67b1eff9f39b47f3) Conflicts: src/tools/CMakeLists.txt (changes goes in src/CMakeLists.txt) --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca0319456a80..868d65df4481 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -476,6 +476,7 @@ set(rados_srcs tools/RadosDump.cc tools/rados/RadosImport.cc tools/rados/PoolDump.cc + common/util.cc common/obj_bencher.cc) add_executable(rados ${rados_srcs}) target_link_libraries(rados librados global ${BLKID_LIBRARIES} ${CMAKE_DL_LIBS} libradosstriper) diff --git a/src/common/util.cc b/src/common/util.cc index ee4b84e87b51..a3a42b362d8f 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -263,3 +263,26 @@ void dump_services(Formatter* f, const map >& services, const } f->close_section(); } + +// Convert non-printable characters to '\###' +void cleanbin(string &str) +{ + bool cleaned = false; + string clean; + + for (string::iterator it = str.begin(); it != str.end(); ++it) { + if (!isprint(*it)) { + clean.push_back('\\'); + clean.push_back('0' + ((*it >> 6) & 7)); + clean.push_back('0' + ((*it >> 3) & 7)); + clean.push_back('0' + (*it & 7)); + cleaned = true; + } else { + clean.push_back(*it); + } + } + + if (cleaned) + str = clean; + return; +} diff --git a/src/include/util.h b/src/include/util.h index fa8dd244f06e..13339c7bd310 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -81,4 +81,5 @@ void collect_sys_info(map *m, CephContext *cct); /// @param type the service type of given @p services, for example @p osd or @p mon. void dump_services(Formatter* f, const map >& services, const char* type); +void cleanbin(string &str); #endif /* CEPH_UTIL_H */ diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index f3714a655499..908327810a69 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -41,6 +41,7 @@ #include "rebuild_mondb.h" #include "ceph_objectstore_tool.h" #include "include/compat.h" +#include "include/util.h" namespace po = boost::program_options; using namespace std; @@ -295,29 +296,6 @@ bool debug = false; super_header sh; uint64_t testalign; -// Convert non-printable characters to '\###' -static void cleanbin(string &str) -{ - bool cleaned = false; - string clean; - - for (string::iterator it = str.begin(); it != str.end(); ++it) { - if (!isprint(*it)) { - clean.push_back('\\'); - clean.push_back('0' + ((*it >> 6) & 7)); - clean.push_back('0' + ((*it >> 3) & 7)); - clean.push_back('0' + (*it & 7)); - cleaned = true; - } else { - clean.push_back(*it); - } - } - - if (cleaned) - str = clean; - return; -} - static int get_fd_data(int fd, bufferlist &bl) { uint64_t total = 0;