Skip to contentSkip to conversation

dlm-tool: pending fixes/cleanups dlm-tool patches

PATCH New Alexander Aring 1 participant 10 messages Mar 7, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover dlm-tool: pending fixes/cleanups dlm-tool patches

Hi,

this is a resend of a subset of pending dlm-tool patches just without the dlm_controld functionality to plot the dlm_controld posix cluster-wide lock states over time. I split this feature out to have at first those cleanups in fixes/dlm userspace instead of doing a new feature at the same time now which has more things to dicuss about.

- Alex

Alexander Aring (9):
dlm_tool: add fail functionality if dump failed
dlm_controld: always create logdir
dlm_controld: move processing of saved messages to plock level
dlm_controld: remove ls parameter
dlm_controld: constify timeval of dt_usec()
dlm_controld: add gcc format printf attribute to log_level
dlm_controld: use write_result()
dlm_controld: be sure we stop lockspaces before shutdown
dlm_controld: constify name_in in log_level()

 dlm_controld/daemon_cpg.c    | 16 ++++++++--
 dlm_controld/dlm_daemon.h    |  3 +-
 dlm_controld/lib.c           | 25 +++++++++-------
 dlm_controld/libdlmcontrol.h | 10 +++----
 dlm_controld/logging.c       | 36 +++++++++++------------
 dlm_controld/plock.c         | 25 ++++++++--------
 dlm_tool/main.c              | 57 +++++++++++++++++++++++++++---------
 7 files changed, 108 insertions(+), 64 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/9 dlm_tool: add fail functionality if dump failed

Currently dlm_controld sets a embedded data int value of dlm_controld dump functionality failed for e.g. if lockspace cannot be found. The dlm_tool does not parse this possible error functionality and will exit successfully. This patch will add dlm_tool fail functionality if dlm_controld sets an embedded data error value.

---
 dlm_controld/lib.c           | 25 +++++++++-------
 dlm_controld/libdlmcontrol.h | 10 +++----
 dlm_tool/main.c              | 57 +++++++++++++++++++++++++++---------
 3 files changed, 62 insertions(+), 30 deletions(-)
dlm_controld/lib.c +14 -11
index 2888ad05..a21150f2 100644
@@ -109,7 +109,7 @@ static void init_header(struct dlmc_header *h, int cmd, char *name,
 
 static char copy_buf[DLMC_DUMP_SIZE];
 
-static int do_dump(int cmd, char *name, char *buf)
+static int do_dump(int cmd, char *name, char *buf, int *data)
 {
 	struct dlmc_header h;
 	int fd, rv, len;
@@ -118,6 +118,8 @@ static int do_dump(int cmd, char *name, char *buf)
 
 	init_header(&h, cmd, name, 0);
 
+	*data = 0;
+
 	fd = do_connect(DLMC_QUERY_SOCK_PATH);
 	if (fd < 0) {
 		rv = fd;
@@ -134,6 +136,7 @@ static int do_dump(int cmd, char *name, char *buf)
 	if (rv < 0)
 		goto out_close;
 
+	*data = h.data;
 	len = h.len - sizeof(h);
 
 	if (len <= 0 || len > DLMC_DUMP_SIZE)
@@ -150,29 +153,29 @@ static int do_dump(int cmd, char *name, char *buf)
 	return rv;
 }
 
-int dlmc_dump_debug(char *buf)
+int dlmc_dump_debug(char *buf, int *data)
 {
-	return do_dump(DLMC_CMD_DUMP_DEBUG, NULL, buf);
+	return do_dump(DLMC_CMD_DUMP_DEBUG, NULL, buf, data);
 }
 
-int dlmc_dump_config(char *buf)
+int dlmc_dump_config(char *buf, int *data)
 {
-	return do_dump(DLMC_CMD_DUMP_CONFIG, NULL, buf);
+	return do_dump(DLMC_CMD_DUMP_CONFIG, NULL, buf, data);
 }
 
-int dlmc_dump_log_plock(char *buf)
+int dlmc_dump_log_plock(char *buf, int *data)
 {
-	return do_dump(DLMC_CMD_DUMP_LOG_PLOCK, NULL, buf);
+	return do_dump(DLMC_CMD_DUMP_LOG_PLOCK, NULL, buf, data);
 }
 
-int dlmc_dump_plocks(char *name, char *buf)
+int dlmc_dump_plocks(char *name, char *buf, int *data)
 {
-	return do_dump(DLMC_CMD_DUMP_PLOCKS, name, buf);
+	return do_dump(DLMC_CMD_DUMP_PLOCKS, name, buf, data);
 }
 
-int dlmc_dump_run(char *buf)
+int dlmc_dump_run(char *buf, int *data)
 {
-	return do_dump(DLMC_CMD_DUMP_RUN, NULL, buf);
+	return do_dump(DLMC_CMD_DUMP_RUN, NULL, buf, data);
 }
 
 int dlmc_reload_config(void)
dlm_controld/libdlmcontrol.h +5 -5
index a8654f3e..08f04c39 100644
@@ -80,11 +80,11 @@ struct dlmc_lockspace {
 
 #define DLMC_STATUS_VERBOSE	0x00000001
 
-int dlmc_dump_debug(char *buf);
-int dlmc_dump_config(char *buf);
-int dlmc_dump_run(char *buf);
-int dlmc_dump_log_plock(char *buf);
-int dlmc_dump_plocks(char *name, char *buf);
+int dlmc_dump_debug(char *buf, int *data);
+int dlmc_dump_config(char *buf, int *data);
+int dlmc_dump_run(char *buf, int *data);
+int dlmc_dump_log_plock(char *buf, int *data);
+int dlmc_dump_plocks(char *name, char *buf, int *data);
 int dlmc_lockspace_info(char *lsname, struct dlmc_lockspace *ls);
 int dlmc_node_info(char *lsname, int nodeid, struct dlmc_node *node);
 /* caller need to free *lss */
dlm_tool/main.c +43 -14

134 lines not on this page · raw message

Signature · 1 line
2.31.1
#2 lore raw

PATCH v2 2/9 dlm_controld: always create logdir

In reply to Alexander Aring

Currently the logdir will be created only if logfile does contain a string. To add another logfiles we simple create the logdir always on startup.

---
 dlm_controld/logging.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
dlm_controld/logging.c +17 -17
index 2c57138c..3298ef99 100644
@@ -38,27 +38,27 @@ void init_logging(void)
 
 	set_logfile_priority();
 
-	if (logfile[0]) {
-		old_umask = umask(0077);
-		rv = mkdir(SYS_VARDIR, 0700);
-		if (rv < 0 && errno != EEXIST) {
-			umask(old_umask);
-			goto skip_logfile;
-		}
+	old_umask = umask(0077);
+	rv = mkdir(SYS_VARDIR, 0700);
+	if (rv < 0 && errno != EEXIST) {
+		umask(old_umask);
+		goto skip_logfile;
+	}
 
-		rv = mkdir(SYS_LOGDIR, 0700);
-		if (rv < 0 && errno != EEXIST) {
-			umask(old_umask);
-			goto skip_logfile;
-		}
+	rv = mkdir(SYS_LOGDIR, 0700);
+	if (rv < 0 && errno != EEXIST) {
+		umask(old_umask);
+		goto skip_logfile;
+	}
 
-		rv = mkdir(LOGDIR, 0700);
-		if (rv < 0 && errno != EEXIST) {
-			umask(old_umask);
-			goto skip_logfile;
-		}
+	rv = mkdir(LOGDIR, 0700);
+	if (rv < 0 && errno != EEXIST) {
 		umask(old_umask);
+		goto skip_logfile;
+	}
+	umask(old_umask);
 
+	if (logfile[0]) {
 		logfile_fp = fopen(logfile, "a+");
 		if (logfile_fp != NULL) {
 			int fd = fileno(logfile_fp);
Signature · 1 line
2.31.1
#3 lore raw

PATCH v2 3/9 dlm_controld: move processing of saved messages to plock level

In reply to Alexander Aring

Ad the loglevel is for save plock messages during corosync resource membership upate. This patch will put the processing of saved messages on the same loglevel.

---
 dlm_controld/plock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
dlm_controld/plock.c +2 -2
index 692787e2..c2c80360 100644
@@ -1612,7 +1612,7 @@ void process_saved_plocks(struct lockspace *ls)
 	struct dlm_header *hd;
 	int count = 0;
 
-	log_dlock(ls, "process_saved_plocks begin");
+	log_plock(ls, "process_saved_plocks begin");
 
 	if (list_empty(&ls->saved_messages))
 		goto out;
@@ -1643,7 +1643,7 @@ void process_saved_plocks(struct lockspace *ls)
 		count++;
 	}
  out:
-	log_dlock(ls, "process_saved_plocks %d done", count);
+	log_plock(ls, "process_saved_plocks %d done", count);
 }
 
 /* locks still marked SYNCING should not go into the ckpt; the new node
Signature · 1 line
2.31.1
#4 lore raw

PATCH v2 4/9 dlm_controld: remove ls parameter

In reply to Alexander Aring

The ls parameter in write_result() is not used, so we can remove it.

---
 dlm_controld/plock.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
dlm_controld/plock.c +6 -7
index c2c80360..462c9212 100644
@@ -684,8 +684,7 @@ static int add_waiter(struct lockspace *ls, struct resource *r,
 	return 0;
 }
 
-static void write_result(struct lockspace *ls, struct dlm_plock_info *in,
-			 int rv)
+static void write_result(struct dlm_plock_info *in, int rv)
 {
 	int write_rv;
 
@@ -719,7 +718,7 @@ static void do_waiters(struct lockspace *ls, struct resource *r)
 		rv = lock_internal(ls, r, in);
 
 		if (in->nodeid == our_nodeid)
-			write_result(ls, in, rv);
+			write_result(in, rv);
 
 		free(w);
 	}
@@ -744,7 +743,7 @@ static void do_lock(struct lockspace *ls, struct dlm_plock_info *in,
 
  out:
 	if (in->nodeid == our_nodeid && rv != -EINPROGRESS)
-		write_result(ls, in, rv);
+		write_result(in, rv);
 
 	do_waiters(ls, r);
 	put_resource(ls, r);
@@ -768,7 +767,7 @@ static void do_unlock(struct lockspace *ls, struct dlm_plock_info *in,
 	}
 
 	if (in->nodeid == our_nodeid)
-		write_result(ls, in, rv);
+		write_result(in, rv);
 
  skip_result:
 	do_waiters(ls, r);
@@ -787,7 +786,7 @@ static void do_get(struct lockspace *ls, struct dlm_plock_info *in,
 	else
 		rv = 0;
 
-	write_result(ls, in, rv);
+	write_result(in, rv);
 	put_resource(ls, r);
 }
 
@@ -830,7 +829,7 @@ static void __receive_plock(struct lockspace *ls, struct dlm_plock_info *in,
 		log_elock(ls, "receive_plock error from %d optype %d",
 			  from, in->optype);
 		if (from == our_nodeid)
-			write_result(ls, in, -EINVAL);
+			write_result(in, -EINVAL);
 	}
 }
 
Signature · 1 line
2.31.1
#5 lore raw

PATCH v2 5/9 dlm_controld: constify timeval of dt_usec()

In reply to Alexander Aring

Those parameters are only used read only. We don't change any data where those pointers point to.

---
 dlm_controld/plock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
dlm_controld/plock.c +1 -1
index 462c9212..8b052a94 100644
@@ -198,7 +198,7 @@ static unsigned long time_diff_ms(struct timeval *begin, struct timeval *end)
 	return (result.tv_sec * 1000) + (result.tv_usec / 1000);
 }
 
-static uint64_t dt_usec(struct timeval *start, struct timeval *stop)
+static uint64_t dt_usec(const struct timeval *start, const struct timeval *stop)
 {
 	uint64_t dt;
 
Signature · 1 line
2.31.1
#6 lore raw

PATCH v2 6/9 dlm_controld: add gcc format printf attribute to log_level

In reply to Alexander Aring

This patch will add __attribute__ (( format( printf, 3, 4 ) ) to log_level() functionality which has a format string as parameter. With this change we enable compiler warnings if format string and applied parameters do not match. We had some couple of warnings which this patch fixes as well.

---
 dlm_controld/daemon_cpg.c | 2 +-
 dlm_controld/dlm_daemon.h | 1 +
 dlm_controld/plock.c      | 3 ++-
 3 files changed, 4 insertions(+), 2 deletions(-)
dlm_controld/daemon_cpg.c +1 -1
index e6a03a28..2e0634d4 100644
@@ -2080,7 +2080,7 @@ int receive_run_reply(struct dlm_header *hd, int len)
 		return 0;
 
 	if (len != sizeof(struct run_reply)) {
-		log_debug("receive_run_reply %s bad len %s expect %d",
+		log_debug("receive_run_reply %s bad len %d expect %zu",
 			  rep->uuid, len, sizeof(struct run_reply));
 		run->info.reply_count++;
 		run->info.need_replies--;
dlm_controld/dlm_daemon.h +1 -0
index f0bad90f..94a9238f 100644
@@ -216,6 +216,7 @@ EXTERN struct list_head run_ops;
 #define LOG_PLOCK 0x00010000
 #define LOG_NONE  0x00001111
 
+__attribute__ (( format( printf, 3, 4 ) ))
 void log_level(char *name_in, uint32_t level_in, const char *fmt, ...);
 
 #define log_error(fmt, args...) log_level(NULL, LOG_ERR, fmt, ##args)
dlm_controld/plock.c +2 -1
index 8b052a94..2f0392c3 100644
@@ -1925,7 +1925,8 @@ void receive_plocks_data(struct lockspace *ls, struct dlm_header *hd, int len)
 		/* no locks should be included for owned resources */
 
 		if (owner && count) {
-			log_elock(ls, "recv_plocks_data %d:%u n %llu o %d bad count %u",
+			log_elock(ls, "recv_plocks_data %d:%u n %llu o %d bad count %" PRIu32,
+				  hd->nodeid, hd->msgdata,
 				  (unsigned long long)num, owner, count);
 			goto fail_free;
 		}
Signature · 1 line
2.31.1
#7 lore raw

PATCH v2 7/9 dlm_controld: use write_result()

In reply to Alexander Aring

This patch will use write_result() instead of code the same code again what write_result() is doing.

---
 dlm_controld/plock.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
dlm_controld/plock.c +1 -2
index 2f0392c3..24ad777a 100644
@@ -1600,8 +1600,7 @@ void process_plocks(int ci)
 #else
 	if (!(info.flags & DLM_PLOCK_FL_CLOSE)) {
 #endif
-		info.rv = rv;
-		rv = write(plock_device_fd, &info, sizeof(info));
+		write_result(&info, rv);
 	}
 }
 
Signature · 1 line
2.31.1
#8 lore raw

PATCH v2 8/9 dlm_controld: be sure we stop lockspaces before shutdown

In reply to Alexander Aring

The dlm_controld shutdown process will drop all dlm configfs entries of dlm communication settings regarding corosync address configuration. This will end in an socket close in the dlm subsystem of the connection which belongs to it. Newly introduced kernel warnings will check if the lockspace is stopped before we close the socket connection. This is necessary because no new dlm messages should be triggered afterwards. To be sure dlm_controld does stop the lockspaces we will make sure that it does it always in close_cpg_daemon. Currently there is a missing handle to stop all lockspaces when there is no cpg_handle_daemon anymore.

---
 dlm_controld/daemon_cpg.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
dlm_controld/daemon_cpg.c +13 -1
index 2e0634d4..10c80ddc 100644
@@ -2527,6 +2527,15 @@ int setup_cpg_daemon(void)
 	return -1;
 }
 
+static void stop_lockspaces(void)
+{
+	struct lockspace *ls;
+
+	list_for_each_entry(ls, &lockspaces, list) {
+		cpg_stop_kernel(ls);
+	}
+}
+
 void close_cpg_daemon(void)
 {
 	struct lockspace *ls;
@@ -2534,8 +2543,11 @@ void close_cpg_daemon(void)
 	struct cpg_name name;
 	int i = 0;
 
-	if (!cpg_handle_daemon)
+	if (!cpg_handle_daemon) {
+		stop_lockspaces();
 		return;
+	}
+
 	if (cluster_down)
 		goto fin;
 
Signature · 1 line
2.31.1
#9 lore raw

PATCH v2 9/9 dlm_controld: constify name_in in log_level()

In reply to Alexander Aring

This patch will constify the name_in parameter of log_level() which is only used as readonly pointer.

---
 dlm_controld/dlm_daemon.h | 2 +-
 dlm_controld/logging.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
dlm_controld/dlm_daemon.h +1 -1
index 94a9238f..86b37603 100644
@@ -217,7 +217,7 @@ EXTERN struct list_head run_ops;
 #define LOG_NONE  0x00001111
 
 __attribute__ (( format( printf, 3, 4 ) ))
-void log_level(char *name_in, uint32_t level_in, const char *fmt, ...);
+void log_level(const char *name_in, uint32_t level_in, const char *fmt, ...);
 
 #define log_error(fmt, args...) log_level(NULL, LOG_ERR, fmt, ##args)
 #define log_debug(fmt, args...) log_level(NULL, LOG_DEBUG, fmt, ##args)
dlm_controld/logging.c +1 -1
index 3298ef99..f1f23f3f 100644
@@ -151,7 +151,7 @@ static void log_save_str(int len, char *log_buf, unsigned int *point,
 	*wrap = w;
 }
 
-void log_level(char *name_in, uint32_t level_in, const char *fmt, ...)
+void log_level(const char *name_in, uint32_t level_in, const char *fmt, ...)
 {
 	va_list ap;
 	char name[NAME_ID_SIZE + 2];
Signature · 1 line
2.31.1