From 959f367f302aab4977b14c5ecd67690b9c26df2a Mon Sep 17 00:00:00 2001 From: Jos Collin Date: Fri, 11 Nov 2022 20:25:39 +0530 Subject: [PATCH] cephfs-top: run_display: clear the screen and block commands when no fs Signed-off-by: Jos Collin --- src/tools/cephfs/top/cephfs-top | 58 +++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/tools/cephfs/top/cephfs-top b/src/tools/cephfs/top/cephfs-top index 63744ea75611a..62108cd8196f5 100755 --- a/src/tools/cephfs/top/cephfs-top +++ b/src/tools/cephfs/top/cephfs-top @@ -457,7 +457,8 @@ class FSTop(object): else: self.run_display() - def set_option(self, opt): + def set_option_all_fs(self, opt): + # sets the options for 'All Filesystem Info' screen if opt == ord('m'): if fs_list: curses.wrapper(self.set_key) @@ -474,17 +475,38 @@ class FSTop(object): else: return False elif opt == ord('r'): - current_states['last_field'] = 'chit' - current_states["limit"] = None - if isinstance(current_states['last_fs'], list): - self.run_all_display() - else: - self.run_display() + if fs_list: + current_states['last_field'] = 'chit' + current_states["limit"] = None + return False # We are already in run_all_display() elif opt == ord('q'): - if self.current_screen == FS_TOP_ALL_FS_APP: - quit() + quit() + return True + + def set_option_sel_fs(self, opt, selected_fs): + # sets the options for 'Selected Filesystem Info' screen + if opt == ord('m'): + if selected_fs in fs_list: + curses.wrapper(self.set_key) else: - self.run_all_display() + return False + elif opt == ord('s'): + if selected_fs in fs_list: + curses.wrapper(self.choose_field) + else: + return False + elif opt == ord('l'): + if selected_fs in fs_list: + curses.wrapper(self.set_limit) + else: + return False + elif opt == ord('r'): + if selected_fs in fs_list: + current_states['last_field'] = 'chit' + current_states["limit"] = None + return False # we are already in run_display() + elif opt == ord('q'): + self.run_all_display() return True def verify_perf_stats_support(self): @@ -843,19 +865,21 @@ class FSTop(object): curses.halfdelay(1) cmd = self.stdscr.getch() + global fs_list, current_states while not self.exit_ev.is_set(): - if cmd in [ord('m'), ord('s'), ord('l'), ord('r'), ord('q')]: - self.set_option(cmd) - self.exit_ev.set() - - global fs_list, current_states fs_list = self.get_fs_names() fs = current_states["last_fs"] + if cmd in [ord('m'), ord('s'), ord('l'), ord('r'), ord('q')]: + if self.set_option_sel_fs(cmd, fs): + self.exit_ev.set() + stats_json = self.perf_stats_query() vscrollEnd = 0 if fs not in fs_list: - help = "Error: The selected filesystem is not available now. " + help_commands + help = f"Error: The selected filesystem '{fs}' is not available now. " \ + "[Press 'q' to go back to home (All Filesystem Info) screen]" self.header.erase() # erase previous text + self.fsstats.erase() self.create_header(stats_json, help, screen_title, 3) else: self.tablehead_y = 0 @@ -969,7 +993,7 @@ class FSTop(object): cmd = self.stdscr.getch() while not self.exit_ev.is_set(): if cmd in [ord('m'), ord('s'), ord('l'), ord('r'), ord('q')]: - if self.set_option(cmd): + if self.set_option_all_fs(cmd): self.exit_ev.set() # header display -- 2.39.5