From ee11130d8f62b6f8ad2d71a1aaa3869708061722 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Tue, 29 Oct 2019 14:05:32 +0000 Subject: [PATCH] rbd: make libcurses optional libcurses may not be available on some platforms (e.g. Windows), so we'll make it optional. If libcurses is not available, we'll disable the rbd iotop command. Signed-off-by: Lucian Petrut --- src/tools/rbd/CMakeLists.txt | 9 +++++++-- src/tools/rbd/action/Perf.cc | 13 ++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/tools/rbd/CMakeLists.txt b/src/tools/rbd/CMakeLists.txt index cf069e8f58b40..f1ee02c2ba801 100644 --- a/src/tools/rbd/CMakeLists.txt +++ b/src/tools/rbd/CMakeLists.txt @@ -1,5 +1,6 @@ set(CURSES_NEED_NCURSES TRUE) -find_package(Curses REQUIRED) +# libcurses may not be available on some platforms (e.g. Windows). +find_package(Curses) set(rbd_srcs rbd.cc @@ -61,8 +62,12 @@ target_link_libraries(rbd librbd journal libneorados librados - ceph-common global ${CURSES_LIBRARIES} + ceph-common global ${BLKID_LIBRARIES} ${CMAKE_DL_LIBS}) +if(CURSES_FOUND) + target_compile_definitions(rbd PRIVATE HAVE_CURSES) + target_link_libraries(rbd ${CURSES_LIBRARIES}) +endif() if(WITH_KRBD) target_link_libraries(rbd krbd) diff --git a/src/tools/rbd/action/Perf.cc b/src/tools/rbd/action/Perf.cc index 64e9fd21067da..c30121021595b 100644 --- a/src/tools/rbd/action/Perf.cc +++ b/src/tools/rbd/action/Perf.cc @@ -11,7 +11,9 @@ #include "common/Formatter.h" #include "common/TextTable.h" #include "global/global_context.h" +#ifdef HAVE_CURSES #include +#endif #include #include #include @@ -338,6 +340,7 @@ void format(const ImageStats& image_stats, Formatter* f, bool global_search) { } // namespace iostat +#ifdef HAVE_CURSES namespace iotop { class MainWindow { @@ -560,6 +563,7 @@ private: }; } // namespace iotop +#endif // HAVE_CURSES void get_arguments_iostat(po::options_description *positional, @@ -651,6 +655,7 @@ int execute_iostat(const po::variables_map &vm, return 0; } +#ifdef HAVE_CURSES void get_arguments_iotop(po::options_description *positional, po::options_description *options) { at::add_pool_options(positional, options, true); @@ -688,13 +693,15 @@ int execute_iotop(const po::variables_map &vm, return 0; } -Shell::Action stat_action( - {"perf", "image", "iostat"}, {}, "Display image IO statistics.", "", - &get_arguments_iostat, &execute_iostat); Shell::Action top_action( {"perf", "image", "iotop"}, {}, "Display a top-like IO monitor.", "", &get_arguments_iotop, &execute_iotop); +#endif // HAVE_CURSES + +Shell::Action stat_action( + {"perf", "image", "iostat"}, {}, "Display image IO statistics.", "", + &get_arguments_iostat, &execute_iostat); } // namespace perf } // namespace action } // namespace rbd -- 2.39.5