The current plock logging is limited due a in-memory log buffer which can be dumped via dlm_contol log_plock functionality. To trace plock performance issues it's necessary to log plock activity in a bigger log buffer such as a file. This patch will add functionality that plock logging information will be appended into a log file.
WARNING: depending on plock activity the resulting log file can be resulting in enormous file size. This option should be used for debugging purpose only. --- dlm_controld/dlm_daemon.h | 4 ++++ dlm_controld/logging.c | 39 +++++++++++++++++++++++++++++++-------- dlm_controld/main.c | 5 +++++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/dlm_controld/dlm_daemon.h b/dlm_controld/dlm_daemon.h index f0bad90f..c74f684a 100644 --- a/dlm_controld/dlm_daemon.h +++ b/dlm_controld/dlm_daemon.h @@ -76,10 +76,12 @@ #define RUN_FILE_NAME "dlm_controld.pid" #define LOG_FILE_NAME "dlm_controld.log" +#define PLOCK_LOG_FILE_NAME "plock.log" #define CONF_FILE_NAME "dlm.conf" #define RUN_FILE_PATH RUNDIR "/" RUN_FILE_NAME #define LOG_FILE_PATH LOGDIR "/" LOG_FILE_NAME +#define PLOCK_LOG_FILE_PATH LOGDIR "/" PLOCK_LOG_FILE_NAME #define CONF_FILE_PATH CONFDIR "/" CONF_FILE_NAME #define DEFAULT_LOG_MODE LOG_MODE_OUTPUT_FILE | LOG_MODE_OUTPUT_SYSLOG @@ -87,6 +89,7 @@ #define DEFAULT_SYSLOG_PRIORITY LOG_INFO #define DEFAULT_LOGFILE_PRIORITY LOG_INFO #define DEFAULT_LOGFILE LOG_FILE_PATH +#define DEFAULT_PLOCK_LOGFILE PLOCK_LOG_FILE_PATH #define DEFAULT_NETLINK_RCVBUF (2 * 1024 * 1024) @@ -110,6 +113,7 @@ enum { enable_fscontrol_ind, enable_plock_ind, plock_debug_ind, + plock_debug_logfile_ind, plock_rate_limit_ind, plock_ownership_ind, drop_resources_time_ind, diff --git a/dlm_controld/logging.c b/dlm_controld/logging.c index 3298ef99..83de2da4 100644 --- a/dlm_controld/logging.c +++ b/dlm_controld/logging.c @@ -12,7 +12,9 @@ static int syslog_facility; static int syslog_priority; static int logfile_priority; static char logfile[PATH_MAX]; +static char plock_logfile[PATH_MAX]; static FILE *logfile_fp; +static FILE *plock_logfile_fp; /* logfile_priority is the only one of these options that can be controlled from command line, environment variable @@ -35,6 +37,7 @@ void init_logging(void) syslog_priority = DEFAULT_SYSLOG_PRIORITY; logfile_priority = DEFAULT_LOGFILE_PRIORITY; strcpy(logfile, DEFAULT_LOGFILE); + strcpy(plock_logfile, DEFAULT_PLOCK_LOGFILE); set_logfile_priority(); @@ -66,6 +69,15 @@ void init_logging(void) } } + if (dlm_options[plock_debug_logfile_ind].use_int && + plock_logfile[0]) { + plock_logfile_fp = fopen(plock_logfile, "a+"); + if (plock_logfile_fp != NULL) { + int fd = fileno(plock_logfile_fp); + fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC); + } + } + skip_logfile: openlog(DAEMON_NAME, LOG_CONS | LOG_PID, syslog_facility); } @@ -75,6 +87,8 @@ void close_logging(void) closelog(); if (logfile_fp) fclose(logfile_fp); + if (plock_logfile_fp) + fclose(plock_logfile_fp); } #define NAME_ID_SIZE 32 @@ -151,6 +165,16 @@ static void log_save_str(int len, char *log_buf, unsigned int *point, *wrap = w; } +static void log_str_to_file(FILE *fp) +{ + time_t logtime = time(NULL); + char tbuf[64]; + + strftime(tbuf, sizeof(tbuf), "%b %d %T", localtime(&logtime)); + fprintf(fp, "%s %s", tbuf, log_str); + fflush(fp); +} + void log_level(char *name_in, uint32_t level_in, const char *fmt, ...) { va_list ap; @@ -191,19 +215,18 @@ void log_level(char *name_in, uint32_t level_in, const char *fmt, ...) if (level < LOG_NONE) log_save_str(pos - 1, log_dump, &log_point, &log_wrap); - if (plock) + if (plock) { log_save_str(pos - 1, log_dump_plock, &log_point_plock, &log_wrap_plock); + if (plock_logfile_fp) + log_str_to_file(plock_logfile_fp); + } + if (level <= syslog_priority) syslog(level, "%s", log_str); - if (level <= logfile_priority && logfile_fp) { - time_t logtime = time(NULL); - char tbuf[64]; - strftime(tbuf, sizeof(tbuf), "%b %d %T", localtime(&logtime)); - fprintf(logfile_fp, "%s %s", tbuf, log_str); - fflush(logfile_fp); - } + if (level <= logfile_priority && logfile_fp) + log_str_to_file(logfile_fp); if (!dlm_options[daemon_debug_ind].use_int) return; diff --git a/dlm_controld/main.c b/dlm_controld/main.c index c9d1c5f1..8e8d4038 100644 --- a/dlm_controld/main.c +++ b/dlm_controld/main.c @@ -1854,6 +1854,11 @@ static void set_opt_defaults(void) 0, NULL, 0, 1, "enable plock debugging"); + set_opt_default(plock_debug_logfile_ind, + "plock_debug_logfile", 'O', req_arg_bool, + 0, NULL, 0, 1, + "write plock debugging to log file. Note: resulting log file can take enormous space."); + set_opt_default(plock_rate_limit_ind, "plock_rate_limit", 'l', req_arg_int, 0, NULL, 0, 1, -- 2.31.1