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: v11.1.0~256^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5c79074ffaee34b2956d9dfc67b1eff9f39b47f3;p=ceph.git common: Move cleanbin() function to common/util.cc Signed-off-by: David Zafman --- diff --git a/src/common/util.cc b/src/common/util.cc index ec3881afad89..5ab1e441a30b 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -267,3 +267,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 30c2e30895da..6a85f1b894a1 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -82,4 +82,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/CMakeLists.txt b/src/tools/CMakeLists.txt index 9478ee227246..0d53ca6cd645 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -3,6 +3,7 @@ set(rados_srcs RadosDump.cc rados/RadosImport.cc rados/PoolDump.cc + ${PROJECT_SOURCE_DIR}/src/common/util.cc ${PROJECT_SOURCE_DIR}/src/common/obj_bencher.cc) add_executable(rados ${rados_srcs}) target_link_libraries(rados librados global ${BLKID_LIBRARIES} ${CMAKE_DL_LIBS} radosstriper) diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index ab1ae81dc808..b120fadc5960 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -42,6 +42,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; @@ -298,29 +299,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;