代码拉取完成,页面将自动刷新
From 59d89e4fe793d5ef3dfb2fadca4e0f5315b2d86b Mon Sep 17 00:00:00 2001
From: Robert Altnoeder <robert.altnoeder@linbit.com>
Date: Tue, 19 Mar 2024 16:39:33 +0100
Subject: [PATCH 084/100] DRBDmon: Disable DRBD actions/commands when showing
an events log file
---
user/drbdmon/terminal/ComponentsHub.h | 2 +
user/drbdmon/terminal/DisplayController.cpp | 3 +
user/drbdmon/terminal/DrbdCommandsImpl.cpp | 52 +++++----
.../terminal/MDspConnectionActions.cpp | 16 ++-
user/drbdmon/terminal/MDspConnectionActions.h | 2 +
user/drbdmon/terminal/MDspMainMenu.cpp | 109 ++++++++++--------
.../terminal/MDspPeerVolumeActions.cpp | 15 +++
user/drbdmon/terminal/MDspPeerVolumeActions.h | 2 +
user/drbdmon/terminal/MDspResourceActions.cpp | 15 +++
user/drbdmon/terminal/MDspResourceActions.h | 2 +
user/drbdmon/terminal/MDspVolumeActions.cpp | 15 +++
user/drbdmon/terminal/MDspVolumeActions.h | 2 +
12 files changed, 164 insertions(+), 71 deletions(-)
diff --git a/user/drbdmon/terminal/ComponentsHub.h b/user/drbdmon/terminal/ComponentsHub.h
index 2266214f..1611a785 100644
--- a/user/drbdmon/terminal/ComponentsHub.h
+++ b/user/drbdmon/terminal/ComponentsHub.h
@@ -56,6 +56,8 @@ class ComponentsHub
uint16_t term_cols {100};
uint16_t term_rows {30};
+ bool enable_drbd_actions {true};
+
ComponentsHub();
virtual ~ComponentsHub() noexcept;
diff --git a/user/drbdmon/terminal/DisplayController.cpp b/user/drbdmon/terminal/DisplayController.cpp
index ccf3e7bc..4e301d6d 100644
--- a/user/drbdmon/terminal/DisplayController.cpp
+++ b/user/drbdmon/terminal/DisplayController.cpp
@@ -63,6 +63,9 @@ DisplayController::DisplayController(
ansi_ctl_mgr = std::unique_ptr<AnsiControl>(new AnsiControl());
sub_proc_queue_mgr = std::unique_ptr<SubProcessQueue>(new SubProcessQueue());
+ // Enable DRBD actions/commands if tracking live events, and not an events log file
+ dsp_comp_hub_mgr->enable_drbd_actions = events_file.empty();
+
dsp_comp_hub_mgr->core_instance = &core_instance;
dsp_comp_hub_mgr->sys_api = mon_env.sys_api.get();
dsp_comp_hub_mgr->dsp_selector = dynamic_cast<DisplaySelector*> (this);
diff --git a/user/drbdmon/terminal/DrbdCommandsImpl.cpp b/user/drbdmon/terminal/DrbdCommandsImpl.cpp
index 78ef870c..8b75a2aa 100644
--- a/user/drbdmon/terminal/DrbdCommandsImpl.cpp
+++ b/user/drbdmon/terminal/DrbdCommandsImpl.cpp
@@ -83,30 +83,42 @@ DrbdCommandsImpl::~DrbdCommandsImpl() noexcept
bool DrbdCommandsImpl::execute_command(const std::string& command, StringTokenizer& tokenizer)
{
bool processed = false;
- Entry* const cmd_entry = cmd_map->get(&command);
- if (cmd_entry != nullptr)
+ if (dsp_comp_hub.enable_drbd_actions)
{
- cmd_func_type cmd_func = cmd_entry->cmd_func;
- try
- {
- dsp_comp_hub.dsp_selector->synchronize_displays();
- processed = (this->*cmd_func)(command, tokenizer);
- }
- catch (SubProcessQueue::QueueCapacityException&)
+ Entry* const cmd_entry = cmd_map->get(&command);
+ if (cmd_entry != nullptr)
{
- dsp_comp_hub.log->add_entry(
- MessageLog::log_level::ALERT,
- "Cannot execute command, insufficient queue capacity"
- );
- }
- catch (SubProcess::Exception&)
- {
- dsp_comp_hub.log->add_entry(
- MessageLog::log_level::ALERT,
- "Command failed: Sub-process execution error"
- );
+ cmd_func_type cmd_func = cmd_entry->cmd_func;
+ try
+ {
+ dsp_comp_hub.dsp_selector->synchronize_displays();
+ processed = (this->*cmd_func)(command, tokenizer);
+ }
+ catch (SubProcessQueue::QueueCapacityException&)
+ {
+ dsp_comp_hub.log->add_entry(
+ MessageLog::log_level::ALERT,
+ "Cannot execute command, insufficient queue capacity"
+ );
+ }
+ catch (SubProcess::Exception&)
+ {
+ dsp_comp_hub.log->add_entry(
+ MessageLog::log_level::ALERT,
+ "Command failed: Sub-process execution error"
+ );
+ }
}
}
+ else
+ {
+ const uint64_t msg_id = dsp_comp_hub.log->add_entry(
+ MessageLog::log_level::WARN,
+ "DRBD commands are currently disabled"
+ );
+ dsp_comp_hub.dsp_shared->message_id = msg_id;
+ dsp_comp_hub.dsp_selector->switch_to_display(DisplayId::display_page::MSG_VIEWER);
+ }
return processed;
}
diff --git a/user/drbdmon/terminal/MDspConnectionActions.cpp b/user/drbdmon/terminal/MDspConnectionActions.cpp
index a492c65a..82f651ca 100644
--- a/user/drbdmon/terminal/MDspConnectionActions.cpp
+++ b/user/drbdmon/terminal/MDspConnectionActions.cpp
@@ -67,8 +67,22 @@ MDspConnectionActions::~MDspConnectionActions() noexcept
{
}
-
void MDspConnectionActions::display_content()
+{
+ if (dsp_comp_hub.enable_drbd_actions)
+ {
+ show_actions();
+ }
+ else
+ {
+ dsp_comp_hub.dsp_common->display_page_id(DisplayId::MDSP_CON_ACT);
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, DisplayConsts::PAGE_NAV_Y + 3);
+ dsp_comp_hub.dsp_io->write_text("This page is currently disabled");
+ }
+}
+
+void MDspConnectionActions::show_actions()
{
dsp_comp_hub.dsp_common->display_page_id(DisplayId::MDSP_CON_ACT);
diff --git a/user/drbdmon/terminal/MDspConnectionActions.h b/user/drbdmon/terminal/MDspConnectionActions.h
index 4aff96a4..6e6e3f5b 100644
--- a/user/drbdmon/terminal/MDspConnectionActions.h
+++ b/user/drbdmon/terminal/MDspConnectionActions.h
@@ -28,6 +28,8 @@ class MDspConnectionActions : public MDspMenuBase
std::unique_ptr<ClickableCommand> cmd_disconnect;
std::unique_ptr<ClickableCommand> cmd_discard;
+ void show_actions();
+
void selection_action(const action_func_type action_func);
void action_connect(const std::string& rsc_name, const std::string& con_name);
diff --git a/user/drbdmon/terminal/MDspMainMenu.cpp b/user/drbdmon/terminal/MDspMainMenu.cpp
index f87950d8..d09f958f 100644
--- a/user/drbdmon/terminal/MDspMainMenu.cpp
+++ b/user/drbdmon/terminal/MDspMainMenu.cpp
@@ -188,8 +188,11 @@ void MDspMainMenu::display_content()
display_option(" 8 ", "About DRBDmon", *cmd_about, std_color);
display_option(" 9 ", "DRBDmon configuration", *cmd_configuration, std_color);
- display_option("90 ", "Start/adjust all resources", *cmd_start_all_rsc, std_color);
- display_option("99 ", "Stop all resources", *cmd_stop_all_rsc, caution_color);
+ if (dsp_comp_hub.enable_drbd_actions)
+ {
+ display_option("90 ", "Start/adjust all resources", *cmd_start_all_rsc, std_color);
+ display_option("99 ", "Stop all resources", *cmd_stop_all_rsc, caution_color);
+ }
display_option(" X ", "Exit DRBDmon", *cmd_exit, std_color);
@@ -281,68 +284,74 @@ void MDspMainMenu::opt_configuration()
void MDspMainMenu::opt_start_all_resources()
{
- try
+ if (dsp_comp_hub.enable_drbd_actions)
{
- std::unique_ptr<CmdLine> command(new CmdLine());
- command->add_argument(drbdcmd::DRBDADM_CMD);
- command->add_argument(drbdcmd::ARG_ADJUST);
- command->add_argument(drbdcmd::ARG_ALL);
+ try
+ {
+ std::unique_ptr<CmdLine> command(new CmdLine());
+ command->add_argument(drbdcmd::DRBDADM_CMD);
+ command->add_argument(drbdcmd::ARG_ADJUST);
+ command->add_argument(drbdcmd::ARG_ALL);
- std::string text("Start all resources");
+ std::string text("Start all resources");
- command->set_description(text);
+ command->set_description(text);
- dsp_comp_hub.sub_proc_queue->add_entry(command, dsp_comp_hub.dsp_shared->activate_tasks);
- }
- catch (SubProcessQueue::QueueCapacityException&)
- {
- dsp_comp_hub.log->add_entry(
- MessageLog::log_level::ALERT,
- "Command start all resources: Cannot execute, insufficient queue capacity"
- );
- }
- catch (SubProcess::Exception&)
- {
- dsp_comp_hub.log->add_entry(
- MessageLog::log_level::ALERT,
- "Command start all resources: Sub-process execution failed"
- );
- }
+ dsp_comp_hub.sub_proc_queue->add_entry(command, dsp_comp_hub.dsp_shared->activate_tasks);
+ }
+ catch (SubProcessQueue::QueueCapacityException&)
+ {
+ dsp_comp_hub.log->add_entry(
+ MessageLog::log_level::ALERT,
+ "Command start all resources: Cannot execute, insufficient queue capacity"
+ );
+ }
+ catch (SubProcess::Exception&)
+ {
+ dsp_comp_hub.log->add_entry(
+ MessageLog::log_level::ALERT,
+ "Command start all resources: Sub-process execution failed"
+ );
+ }
- dsp_comp_hub.dsp_selector->switch_to_display(DisplayId::display_page::RSC_LIST);
+ dsp_comp_hub.dsp_selector->switch_to_display(DisplayId::display_page::RSC_LIST);
+ }
}
void MDspMainMenu::opt_stop_all_resources()
{
- try
+ if (dsp_comp_hub.enable_drbd_actions)
{
- std::unique_ptr<CmdLine> command(new CmdLine());
- command->add_argument(drbdcmd::DRBDSETUP_CMD);
- command->add_argument(drbdcmd::ARG_STOP);
- command->add_argument(drbdcmd::ARG_ALL);
+ try
+ {
+ std::unique_ptr<CmdLine> command(new CmdLine());
+ command->add_argument(drbdcmd::DRBDSETUP_CMD);
+ command->add_argument(drbdcmd::ARG_STOP);
+ command->add_argument(drbdcmd::ARG_ALL);
- std::string text("Stop all resources");
+ std::string text("Stop all resources");
- command->set_description(text);
+ command->set_description(text);
- dsp_comp_hub.sub_proc_queue->add_entry(command, dsp_comp_hub.dsp_shared->activate_tasks);
- }
- catch (SubProcessQueue::QueueCapacityException&)
- {
- dsp_comp_hub.log->add_entry(
- MessageLog::log_level::ALERT,
- "Command stop all resources: Cannot execute, insufficient queue capacity"
- );
- }
- catch (SubProcess::Exception&)
- {
- dsp_comp_hub.log->add_entry(
- MessageLog::log_level::ALERT,
- "Command stop all resources: Sub-process execution failed"
- );
- }
+ dsp_comp_hub.sub_proc_queue->add_entry(command, dsp_comp_hub.dsp_shared->activate_tasks);
+ }
+ catch (SubProcessQueue::QueueCapacityException&)
+ {
+ dsp_comp_hub.log->add_entry(
+ MessageLog::log_level::ALERT,
+ "Command stop all resources: Cannot execute, insufficient queue capacity"
+ );
+ }
+ catch (SubProcess::Exception&)
+ {
+ dsp_comp_hub.log->add_entry(
+ MessageLog::log_level::ALERT,
+ "Command stop all resources: Sub-process execution failed"
+ );
+ }
- dsp_comp_hub.dsp_selector->switch_to_display(DisplayId::display_page::RSC_LIST);
+ dsp_comp_hub.dsp_selector->switch_to_display(DisplayId::display_page::RSC_LIST);
+ }
}
void MDspMainMenu::opt_exit()
diff --git a/user/drbdmon/terminal/MDspPeerVolumeActions.cpp b/user/drbdmon/terminal/MDspPeerVolumeActions.cpp
index a9c77cdb..f82ad7c0 100644
--- a/user/drbdmon/terminal/MDspPeerVolumeActions.cpp
+++ b/user/drbdmon/terminal/MDspPeerVolumeActions.cpp
@@ -83,6 +83,21 @@ MDspPeerVolumeActions::~MDspPeerVolumeActions() noexcept
}
void MDspPeerVolumeActions::display_content()
+{
+ if (dsp_comp_hub.enable_drbd_actions)
+ {
+ show_actions();
+ }
+ else
+ {
+ dsp_comp_hub.dsp_common->display_page_id(DisplayId::MDSP_CON_ACT);
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, DisplayConsts::PAGE_NAV_Y + 3);
+ dsp_comp_hub.dsp_io->write_text("This page is currently disabled");
+ }
+}
+
+void MDspPeerVolumeActions::show_actions()
{
dsp_comp_hub.dsp_common->display_page_id(DisplayId::MDSP_PEER_VLM_ACT);
diff --git a/user/drbdmon/terminal/MDspPeerVolumeActions.h b/user/drbdmon/terminal/MDspPeerVolumeActions.h
index c18cb871..a3587f31 100644
--- a/user/drbdmon/terminal/MDspPeerVolumeActions.h
+++ b/user/drbdmon/terminal/MDspPeerVolumeActions.h
@@ -34,6 +34,8 @@ class MDspPeerVolumeActions : public MDspMenuBase
std::unique_ptr<ClickableCommand> cmd_verify;
std::unique_ptr<ClickableCommand> cmd_invalidate_remote;
+ void show_actions();
+
void selection_action(const action_func_type action_func);
void action_pause_sync(const std::string& rsc_name, const std::string& con_name, const uint16_t vlm_nr);
diff --git a/user/drbdmon/terminal/MDspResourceActions.cpp b/user/drbdmon/terminal/MDspResourceActions.cpp
index 1fab05e8..fe7af6aa 100644
--- a/user/drbdmon/terminal/MDspResourceActions.cpp
+++ b/user/drbdmon/terminal/MDspResourceActions.cpp
@@ -216,6 +216,21 @@ MDspResourceActions::~MDspResourceActions() noexcept
}
void MDspResourceActions::display_content()
+{
+ if (dsp_comp_hub.enable_drbd_actions)
+ {
+ show_actions();
+ }
+ else
+ {
+ dsp_comp_hub.dsp_common->display_page_id(DisplayId::MDSP_CON_ACT);
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, DisplayConsts::PAGE_NAV_Y + 3);
+ dsp_comp_hub.dsp_io->write_text("This page is currently disabled");
+ }
+}
+
+void MDspResourceActions::show_actions()
{
dsp_comp_hub.dsp_common->display_page_id(DisplayId::MDSP_RSC_ACT);
diff --git a/user/drbdmon/terminal/MDspResourceActions.h b/user/drbdmon/terminal/MDspResourceActions.h
index 85c16a84..70dde3e2 100644
--- a/user/drbdmon/terminal/MDspResourceActions.h
+++ b/user/drbdmon/terminal/MDspResourceActions.h
@@ -48,6 +48,8 @@ class MDspResourceActions: public MDspMenuBase
std::unique_ptr<ClickableCommand> cmd_connect_discard;
std::unique_ptr<ClickableCommand> cmd_invalidate;
+ void show_actions();
+
void selection_action(const action_func_type action_func);
void action_start(const std::string& rsc_name);
diff --git a/user/drbdmon/terminal/MDspVolumeActions.cpp b/user/drbdmon/terminal/MDspVolumeActions.cpp
index 63aa8f0a..6e0400a1 100644
--- a/user/drbdmon/terminal/MDspVolumeActions.cpp
+++ b/user/drbdmon/terminal/MDspVolumeActions.cpp
@@ -87,6 +87,21 @@ MDspVolumeActions::~MDspVolumeActions() noexcept
}
void MDspVolumeActions::display_content()
+{
+ if (dsp_comp_hub.enable_drbd_actions)
+ {
+ show_actions();
+ }
+ else
+ {
+ dsp_comp_hub.dsp_common->display_page_id(DisplayId::MDSP_CON_ACT);
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, DisplayConsts::PAGE_NAV_Y + 3);
+ dsp_comp_hub.dsp_io->write_text("This page is currently disabled");
+ }
+}
+
+void MDspVolumeActions::show_actions()
{
dsp_comp_hub.dsp_common->display_page_id(DisplayId::MDSP_VLM_ACT);
diff --git a/user/drbdmon/terminal/MDspVolumeActions.h b/user/drbdmon/terminal/MDspVolumeActions.h
index 8d6410e1..3547a279 100644
--- a/user/drbdmon/terminal/MDspVolumeActions.h
+++ b/user/drbdmon/terminal/MDspVolumeActions.h
@@ -30,6 +30,8 @@ class MDspVolumeActions : public MDspMenuBase
std::unique_ptr<ClickableCommand> cmd_resize;
std::unique_ptr<ClickableCommand> cmd_invalidate;
+ void show_actions();
+
void selection_action(const action_func_type action_func);
void action_attach(const std::string& rsc_name, const uint16_t vlm_nr);
--
2.33.1.windows.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。