1 Star 0 Fork 40

yangshx/lvm2

forked from src-openEuler/lvm2 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0009-enhancement-add-dfx-log.patch 10.12 KB
一键复制 编辑 原始数据 按行查看 历史
wj196 提交于 2020-07-16 14:44 . update lvm2 version to 2.03.09-1
From fd36f54943e58db6483472519c118bde68b6ee60 Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Tue, 19 Mar 2019 16:43:16 +0800
Subject: [PATCH] add dfx log when error occur, or lvm resource change, it will
print the cmdline and ppid
---
conf/example.conf.in | 4 ++++
conf/example.conf.in.rej | 13 +++++++++++++
lib/commands/toolcontext.c | 16 ++++++++++++++++
lib/commands/toolcontext.h | 4 ++++
lib/config/config_settings.h | 5 +++++
lib/log/log.c | 21 +++++++++++++++++++--
lib/log/log.h | 4 +++-
lib/misc/lvm-globals.c | 11 +++++++++++
lib/misc/lvm-globals.h | 2 ++
tools/lvmcmdline.c | 1 +
10 files changed, 78 insertions(+), 3 deletions(-)
create mode 100644 conf/example.conf.in.rej
diff --git a/conf/example.conf.in b/conf/example.conf.in
index f310789..d715d12 100644
--- a/conf/example.conf.in
+++ b/conf/example.conf.in
@@ -775,6 +775,10 @@ log {
# There are 6 syslog-like log levels currently in use: 2 to 7 inclusive.
# 7 is the most verbose (LOG_DEBUG).
level = 3
+ #When the level of log messages is set as 2 or 3, set log_unless_silent
+ #to 1, it will also log some important warning level messages, such as,
+ #create/delete/change a lv/vg/pv, 0 is close this option.
+ log_unless_silent = 1
# Configuration option log/indent.
# Indent messages according to their severity.
diff --git a/conf/example.conf.in.rej b/conf/example.conf.in.rej
new file mode 100644
index 0000000..d90332a
--- /dev/null
+++ b/conf/example.conf.in.rej
@@ -0,0 +1,13 @@
+diff a/conf/example.conf.in b/conf/example.conf.in (rejected hunks)
+@@ -587,6 +587,11 @@ log {
+ # 7 is the most verbose (LOG_DEBUG).
+ level = 3
+
++ #When the level of log messages is set as 2 or 3, set log_unless_silent
++ #to 1, it will also log some important warning level messages, such as,
++ #create/delete/change a lv/vg/pv, 0 is close this option.
++ log_unless_silent = 1
++
+ # Configuration option log/indent.
+ # Indent messages according to their severity.
+ indent = 1
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 479d499..894c91d 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -46,6 +46,8 @@
static const size_t _linebuffer_size = 4096;
+char *global_cmdline = NULL;
+
/*
* Copy the input string, removing invalid characters.
*/
@@ -348,6 +350,9 @@ static void _init_logging(struct cmd_context *cmd)
find_config_tree_bool(cmd, log_silent_CFG, NULL);
init_silent(cmd->default_settings.silent);
+ cmd->default_settings.log_unless_silent = find_config_tree_bool(cmd, log_unless_silent_CFG, NULL);
+ init_log_unless_silent(cmd->default_settings.log_unless_silent);
+
/* Verbose level for tty output */
cmd->default_settings.verbose = find_config_tree_int(cmd, log_verbose_CFG, NULL);
init_verbose(cmd->default_settings.verbose + VERBOSE_BASE_LEVEL);
@@ -1962,6 +1967,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
_destroy_segtypes(&cmd->segtypes);
_destroy_formats(cmd, &cmd->formats);
_destroy_filters(cmd);
+ set_global_cmdline(NULL);
if (cmd->mem)
dm_pool_destroy(cmd->mem);
dev_cache_exit();
@@ -2014,3 +2020,13 @@ void destroy_toolcontext(struct cmd_context *cmd)
fin_syslog();
reset_lvm_errno(0);
}
+
+char *get_global_cmdline()
+{
+ return global_cmdline;
+}
+
+void set_global_cmdline(char *cmdline)
+{
+ global_cmdline = cmdline;
+}
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index c09558a..a91174d 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -47,6 +47,7 @@ struct config_info {
mode_t umask;
char unit_type;
char _padding[1];
+ int log_unless_silent;
};
struct dm_config_tree;
@@ -275,4 +276,7 @@ struct format_type *get_format_by_name(struct cmd_context *cmd, const char *form
const char *system_id_from_string(struct cmd_context *cmd, const char *str);
+char *get_global_cmdline();
+
+void set_global_cmdline(char *cmdline);
#endif
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index f280156..1b05163 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -850,6 +850,11 @@ cfg(log_level_CFG, "level", log_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_LOGLEVEL,
"There are 6 syslog-like log levels currently in use: 2 to 7 inclusive.\n"
"7 is the most verbose (LOG_DEBUG).\n")
+cfg(log_unless_silent_CFG, "log_unless_silent", log_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 178), NULL, 0, NULL,
+ "When the level of log messages is set as 2 or 3, set log_unless_silent\n"
+ "to 1, it will also log some important warning level messages, such as,\n"
+ "create/delete/change a lv/vg/pv, 0 is close this option.\n")
+
cfg(log_indent_CFG, "indent", log_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_BOOL, DEFAULT_INDENT, vsn(1, 0, 0), NULL, 0, NULL,
"Indent messages according to their severity.\n")
diff --git a/lib/log/log.c b/lib/log/log.c
index ebf26b4..136959e 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -19,6 +19,7 @@
#include "lib/config/defaults.h"
#include "lib/report/report.h"
#include "lib/misc/lvm-file.h"
+#include "lib/commands/toolcontext.h"
#include <stdio.h>
#include <stdarg.h>
@@ -494,6 +495,7 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
const char *trformat; /* Translated format string */
char *newbuf;
int use_stderr = log_stderr(level);
+ int force_syslog = (level & _LOG_IMPORTANT_TO_SYSLOG) ? 1 : 0;
int log_once = log_once(level);
int log_bypass_report = log_bypass_report(level);
int fatal_internal_error = 0;
@@ -506,7 +508,9 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
struct dm_report *orig_report;
int logged_via_report = 0;
+ static int printcmdline = 1;
level = log_level(level);
+ force_syslog = (level!=0 && get_log_unless_silent()) ? force_syslog : 0;
if (_abort_on_internal_errors_env_present < 0) {
if ((env_str = getenv("DM_ABORT_ON_INTERNAL_ERRORS"))) {
@@ -670,8 +674,8 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
va_end(ap);
}
- if ((level > debug_level()) ||
- (level >= _LOG_DEBUG && !debug_class_is_logged(dm_errno_or_class))) {
+ if (!force_syslog && ((level > debug_level()) ||
+ (level >= _LOG_DEBUG && !debug_class_is_logged(dm_errno_or_class)))) {
if (fatal_internal_error)
abort();
return;
@@ -714,6 +718,19 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
if (_syslog && (_log_while_suspended || !critical_section())) {
va_copy(ap, orig_ap);
+
+ if (level <= _LOG_WARN && printcmdline) {
+ char *cmdline = get_global_cmdline();
+ if (cmdline) {
+ printcmdline = 0;
+ char msg_addcmd[4096] = {0};
+
+ snprintf(msg_addcmd, sizeof(msg_addcmd),
+ "ppid=%lu, cmdline:%s", getppid(), cmdline);
+ syslog(level, "%s", msg_addcmd);
+ }
+ }
+
vsyslog(level, trformat, ap);
va_end(ap);
}
diff --git a/lib/log/log.h b/lib/log/log.h
index d3848a4..07f2eb4 100644
--- a/lib/log/log.h
+++ b/lib/log/log.h
@@ -50,6 +50,8 @@
#define _LOG_STDERR 0x0080 /* force things to go to stderr, even if loglevel would make them go to stdout */
#define _LOG_ONCE 0x0100 /* downgrade to NOTICE if this has been already logged */
#define _LOG_BYPASS_REPORT 0x0200 /* do not log through report even if report available */
+#define _LOG_IMPORTANT_TO_SYSLOG 0x10000 /*log to syslog even if loglevel number is bigger than _debug_level configuration,
+ unless _debug_level is 0*/
#define log_level(x) ((x) & 0x0f) /* obtain message level */
#define log_stderr(x) ((x) & _LOG_STDERR) /* obtain stderr bit */
#define log_once(x) ((x) & _LOG_ONCE) /* obtain once bit */
@@ -107,7 +109,7 @@
#define log_very_verbose(args...) log_info(args)
#define log_verbose(args...) log_notice(args)
#define log_print(args...) LOG_LINE(_LOG_WARN, args)
-#define log_print_unless_silent(args...) LOG_LINE(silent_mode() ? _LOG_NOTICE : _LOG_WARN, args)
+#define log_print_unless_silent(args...) LOG_LINE(silent_mode() ? _LOG_NOTICE : _LOG_WARN | _LOG_IMPORTANT_TO_SYSLOG, args)
#define log_error(args...) log_err(args)
#define log_error_suppress(s, args...) log_err_suppress(s, args)
#define log_error_once(args...) log_err_once(args)
diff --git a/lib/misc/lvm-globals.c b/lib/misc/lvm-globals.c
index 06855ff..37d2fae 100644
--- a/lib/misc/lvm-globals.c
+++ b/lib/misc/lvm-globals.c
@@ -54,12 +54,23 @@ static char _sysfs_dir_path[PATH_MAX] = "";
static uint64_t _pv_min_size = (DEFAULT_PV_MIN_SIZE_KB * 1024L >> SECTOR_SHIFT);
static const char *_unknown_device_name = DEFAULT_UNKNOWN_DEVICE_NAME;
static int _io_memory_size_kb = DEFAULT_IO_MEMORY_SIZE_KB;
+static int _log_unless_silent = 1;
void init_verbose(int level)
{
_verbose_level = level;
}
+void init_log_unless_silent(int unless_silent)
+{
+ _log_unless_silent = unless_silent;
+}
+
+int get_log_unless_silent(void)
+{
+ return _log_unless_silent;
+}
+
void init_silent(int silent)
{
_silent = silent;
diff --git a/lib/misc/lvm-globals.h b/lib/misc/lvm-globals.h
index a54001c..8ae55f6 100644
--- a/lib/misc/lvm-globals.h
+++ b/lib/misc/lvm-globals.h
@@ -89,4 +89,6 @@ int io_memory_size(void);
#define DMEVENTD_MONITOR_IGNORE -1
int dmeventd_monitor_mode(void);
+void init_log_unless_silent(int unless_silent);
+int get_log_unless_silent(void);
#endif
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index f147be3..650eff8 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -2973,6 +2973,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
/* The cmd_line string is only used for logging, not processing. */
if (!(cmd->cmd_line = _copy_command_line(cmd, argc, argv)))
return_ECMD_FAILED;
+ set_global_cmdline(cmd->cmd_line);
/* Look up command - will be NULL if not recognised */
if (!(cmd->cname = _find_command_name(cmd->name)))
--
1.8.3.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangshaoxing1001/lvm2.git
git@gitee.com:yangshaoxing1001/lvm2.git
yangshaoxing1001
lvm2
lvm2
master

搜索帮助