diff mbox series

multipathd: show pending reconfigs in 'show daemon' output

Message ID 20240806225441.3227895-1-bmarzins@redhat.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series multipathd: show pending reconfigs in 'show daemon' output | expand

Commit Message

Benjamin Marzinski Aug. 6, 2024, 10:54 p.m. UTC
Since the "multipathd reconfigure" command simply schedules a
reconfigure, and doesn't wait until it has occurred, it would be nice to
be able to query multipathd to see if the reconfigure has completed.
"multipathd show daemon" doesn't work for this. The reconfigure could be
delayed, and the output gives no indication that there is a pending
reconfigure.

Change the ouput to add " (pending reconfigure)" if a reconfigure is
pending.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 multipathd/cli_handlers.c | 11 +++++++++--
 multipathd/main.c         | 15 ++++++++-------
 multipathd/main.h         |  2 +-
 3 files changed, 18 insertions(+), 10 deletions(-)

Comments

Martin Wilck Aug. 7, 2024, 2:13 p.m. UTC | #1
On Tue, 2024-08-06 at 18:54 -0400, Benjamin Marzinski wrote:
> Since the "multipathd reconfigure" command simply schedules a
> reconfigure, and doesn't wait until it has occurred, it would be nice
> to
> be able to query multipathd to see if the reconfigure has completed.
> "multipathd show daemon" doesn't work for this. The reconfigure could
> be
> delayed, and the output gives no indication that there is a pending
> reconfigure.
> 
> Change the ouput to add " (pending reconfigure)" if a reconfigure is
> pending.
> 
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>

Reviewed-by: Martin Wilck <mwilck@suse.com>
diff mbox series

Patch

diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
index 4b6cfba2..ef5f53e2 100644
--- a/multipathd/cli_handlers.c
+++ b/multipathd/cli_handlers.c
@@ -342,8 +342,15 @@  show_status (struct strbuf *reply, struct vectors *vecs)
 static int
 show_daemon (struct strbuf *reply)
 {
-	if (print_strbuf(reply, "pid %d %s\n",
-			 daemon_pid, daemon_status()) < 0)
+	const char *status;
+	bool pending_reconfig;
+
+	status = daemon_status(&pending_reconfig);
+	if (status == NULL)
+		return 1;
+	if (print_strbuf(reply, "pid %d %s%s\n",
+			 daemon_pid, status,
+			 pending_reconfig ? " (pending reconfigure)" : "") < 0)
 		return 1;
 
 	return 0;
diff --git a/multipathd/main.c b/multipathd/main.c
index daec9e93..f43ff549 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -132,6 +132,8 @@  static int poll_dmevents = 1;
 static enum daemon_status running_state = DAEMON_INIT;
 /* Don't access this variable without holding config_lock */
 static bool __delayed_reconfig;
+/* Don't access this variable without holding config_lock */
+static enum force_reload_types reconfigure_pending = FORCE_RELOAD_NONE;
 pid_t daemon_pid;
 static pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t config_cond;
@@ -142,19 +144,21 @@  static bool check_thr_started, uevent_thr_started, uxlsnr_thr_started,
 	fpin_consumer_thr_started;
 static int pid_fd = -1;
 
-static inline enum daemon_status get_running_state(void)
+static inline enum daemon_status get_running_state(bool *pending_reconfig)
 {
 	enum daemon_status st;
 
 	pthread_mutex_lock(&config_lock);
 	st = running_state;
+	if (pending_reconfig != NULL)
+		*pending_reconfig = (reconfigure_pending != FORCE_RELOAD_NONE);
 	pthread_mutex_unlock(&config_lock);
 	return st;
 }
 
 int should_exit(void)
 {
-	return get_running_state() == DAEMON_SHUTDOWN;
+	return get_running_state(NULL) == DAEMON_SHUTDOWN;
 }
 
 /*
@@ -179,9 +183,9 @@  static const char *daemon_status_msg[DAEMON_STATUS_SIZE] = {
 };
 
 const char *
-daemon_status(void)
+daemon_status(bool *pending_reconfig)
 {
-	int status = get_running_state();
+	int status = get_running_state(pending_reconfig);
 
 	if (status < DAEMON_INIT || status >= DAEMON_STATUS_SIZE)
 		return NULL;
@@ -277,9 +281,6 @@  enum daemon_status wait_for_state_change_if(enum daemon_status oldstate,
 	return st;
 }
 
-/* Don't access this variable without holding config_lock */
-static enum force_reload_types reconfigure_pending = FORCE_RELOAD_NONE;
-
 /* must be called with config_lock held */
 static void __post_config_state(enum daemon_status state)
 {
diff --git a/multipathd/main.h b/multipathd/main.h
index 7aa93ca3..ef838a02 100644
--- a/multipathd/main.h
+++ b/multipathd/main.h
@@ -31,7 +31,7 @@  extern pid_t daemon_pid;
 extern int uxsock_timeout;
 
 void exit_daemon(void);
-const char * daemon_status(void);
+const char *daemon_status(bool *pending_reconfig);
 enum daemon_status wait_for_state_change_if(enum daemon_status oldstate,
 					    unsigned long ms);
 void schedule_reconfigure(enum force_reload_types requested_type);