8 Star 1 Fork 7

src-anolis-os/rasdaemon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1064-ras-events-make-returned-error-code-consistent.patch 10.06 KB
一键复制 编辑 原始数据 按行查看 历史
From 4c0758c36fc189fe33467030dbf3b5438b206d59 Mon Sep 17 00:00:00 2001
From: Mauro Carvalho Chehab <[email protected]>
Date: Fri, 19 Jul 2024 08:24:25 +0200
Subject: [PATCH 64/85] ras-events: make returned error code consistent
- Rework the returned code logic to be more consistent;
- error codes will be using negative values;
- positive values indicate special return codes.
- Don't bloat the logs with lots of error messages due to
unsupported traces;
- Ensure that the number of CPUs will probably retrieved or bail out;
- Don't bail if it can't setup a monotone clock: it is better
to have a wrong timestamp than no log at all.
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
---
ras-events.c | 91 +++++++++++++++++++++++++++++++---------------------
1 file changed, 54 insertions(+), 37 deletions(-)
diff --git a/ras-events.c b/ras-events.c
index acde772..0c4fe60 100644
--- a/ras-events.c
+++ b/ras-events.c
@@ -78,7 +78,7 @@ static int get_debugfs_dir(char *tracing_dir, size_t len)
fp = fopen("/proc/mounts", "r");
if (!fp) {
log(ALL, LOG_INFO, "Can't open /proc/mounts");
- return errno;
+ return -errno;
}
do {
@@ -124,7 +124,11 @@ static int open_trace(struct ras_events *ras, char *name, int flags)
if (rc < 0)
return rc;
- return open(fname, flags);
+ rc = open(fname, flags);
+ if (rc)
+ return -errno;
+
+ return 0;
}
static int get_tracing_dir(struct ras_events *ras)
@@ -145,7 +149,7 @@ static int get_tracing_dir(struct ras_events *ras)
dir = opendir(fname);
if (!dir)
- return -1;
+ return -EINVAL;
for (entry = readdir(dir); entry; entry = readdir(dir)) {
if (strstr(entry->d_name, "instances")) {
@@ -168,13 +172,13 @@ static int get_tracing_dir(struct ras_events *ras)
log(ALL, LOG_INFO,
"Unable to create " TOOL_NAME " instance at %s\n",
ras->tracing);
- return -1;
+ return -EINVAL;
}
}
return 0;
}
-static int is_disabled_event(char *group, char *event)
+static bool is_disabled_event(char *group, char *event)
{
char ras_event_name[MAX_PATH + 1];
@@ -183,9 +187,9 @@ static int is_disabled_event(char *group, char *event)
if (choices_disable && strlen(choices_disable) != 0 &&
strstr(choices_disable, ras_event_name)) {
- return 1;
+ return true;
}
- return 0;
+ return false;
}
/*
@@ -208,7 +212,7 @@ static int __toggle_ras_mc_event(struct ras_events *ras,
fd = open_trace(ras, "set_event", O_RDWR | O_APPEND);
if (fd < 0) {
log(ALL, LOG_WARNING, "Can't open set_event\n");
- return errno;
+ return -errno;
}
rc = write(fd, fname, strlen(fname));
@@ -220,7 +224,7 @@ static int __toggle_ras_mc_event(struct ras_events *ras,
close(fd);
if (!rc) {
log(ALL, LOG_WARNING, "Nothing was written on set_event\n");
- return EIO;
+ return -EIO;
}
log(ALL, LOG_INFO, "%s:%s event %s\n",
@@ -238,7 +242,7 @@ int toggle_ras_mc_event(int enable)
ras = calloc(1, sizeof(*ras));
if (!ras) {
log(TERM, LOG_ERR, "Can't allocate memory for ras struct\n");
- return errno;
+ return -errno;
}
rc = get_tracing_dir(ras);
@@ -283,7 +287,10 @@ int toggle_ras_mc_event(int enable)
free_ras:
free(ras);
- return rc;
+ if (rc)
+ return -EINVAL;
+
+ return 0;
}
static void setup_event_trigger(char *event)
@@ -421,17 +428,26 @@ static int set_buffer_percent(struct ras_events *ras, int percent)
size = write(fd, buf, strlen(buf));
if (size <= 0) {
log(TERM, LOG_WARNING, "can't write to buffer_percent\n");
- res = -1;
+ res = -EINVAL;
}
close(fd);
} else {
log(TERM, LOG_WARNING, "Can't open buffer_percent\n");
- res = -1;
+ res = -EINVAL;
}
return res;
}
+/*
+ * Kernel tracepoint had an incompatible change in 2019, causing polling
+ * tracepoints to fail. Rasdaemon can support both legacy and newer versions,
+ * with the help of a backup-compatibility legacy kernel mode.
+ *
+ * The LEGACY_KERNEL flag indicates the need to enable such code.
+ */
+#define LEGACY_KERNEL 255
+
static int read_ras_event_all_cpus(struct pthread_data *pdata,
unsigned int n_cpus)
{
@@ -621,9 +637,9 @@ error:
}
if (legacy_kernel)
- return -255;
- else
- return -1;
+ return LEGACY_KERNEL;
+
+ return -EINVAL;
}
static int read_ras_event(int fd,
@@ -644,7 +660,7 @@ static int read_ras_event(int fd,
size = read(fd, page, pdata->ras->page_size);
if (size < 0) {
log(TERM, LOG_WARNING, "read\n");
- return -1;
+ return -EINVAL;
} else if (size > 0) {
kbuffer_load_subbuffer(kbuf, page);
@@ -745,13 +761,13 @@ static int select_tracing_timestamp(struct ras_events *ras)
fd = open_trace(ras, "trace_clock", O_RDONLY);
if (fd < 0) {
log(TERM, LOG_ERR, "Can't open trace_clock\n");
- return -1;
+ return -EINVAL;
}
size = read(fd, buf, sizeof(buf));
close(fd);
if (!size) {
log(TERM, LOG_ERR, "trace_clock is empty!\n");
- return -1;
+ return -EINVAL;
}
if (!strstr(buf, UPTIME)) {
@@ -786,7 +802,7 @@ static int select_tracing_timestamp(struct ras_events *ras)
fclose(fp);
if (rc <= 0) {
log(TERM, LOG_ERR, "Can't parse /proc/uptime!\n");
- return -1;
+ return -EINVAL;
}
now = time(NULL);
@@ -796,6 +812,7 @@ static int select_tracing_timestamp(struct ras_events *ras)
return 0;
}
+#define EVENT_DISABLED 1
static int add_event_handler(struct ras_events *ras, struct pevent *pevent,
unsigned page_size, char *group, char *event,
pevent_event_handler_func func, char *filter_str, int id)
@@ -811,14 +828,14 @@ static int add_event_handler(struct ras_events *ras, struct pevent *pevent,
log(TERM, LOG_ERR,
"Can't get %s:%s traces. Perhaps this feature is not supported on your system.\n",
group, event);
- return errno;
+ return -errno;
}
page = malloc(page_size);
if (!page) {
log(TERM, LOG_ERR, "Can't allocate page to read %s:%s format\n",
group, event);
- rc = errno;
+ rc = -errno;
close(fd);
return rc;
}
@@ -837,14 +854,14 @@ static int add_event_handler(struct ras_events *ras, struct pevent *pevent,
log(TERM, LOG_ERR, "Can't register event handler for %s:%s\n",
group, event);
free(page);
- return EINVAL;
+ return -EINVAL;
}
rc = pevent_parse_event(pevent, page, size, group);
if (rc) {
log(TERM, LOG_ERR, "Can't parse event %s:%s\n", group, event);
free(page);
- return EINVAL;
+ return -EINVAL;
}
if (filter_str) {
@@ -855,7 +872,7 @@ static int add_event_handler(struct ras_events *ras, struct pevent *pevent,
log(TERM, LOG_ERR,
"Failed to allocate filter for %s/%s.\n", group, event);
free(page);
- return EINVAL;
+ return -EINVAL;
}
rc = pevent_filter_add_filter_str(filter, filter_str, &error);
if (rc) {
@@ -872,7 +889,7 @@ static int add_event_handler(struct ras_events *ras, struct pevent *pevent,
if (is_disabled_event(group, event)) {
log(ALL, LOG_INFO, "Disabled %s:%s tracing from config\n",
group, event);
- return -EINVAL;
+ return EVENT_DISABLED;
}
/* Enable RAS events */
@@ -882,7 +899,7 @@ static int add_event_handler(struct ras_events *ras, struct pevent *pevent,
log(TERM, LOG_ERR, "Can't enable %s:%s tracing\n",
group, event);
- return EINVAL;
+ return -EINVAL;
}
setup_event_trigger(event);
@@ -907,7 +924,7 @@ int handle_ras_events(int record_events)
ras = calloc(1, sizeof(*ras));
if (!ras) {
log(TERM, LOG_ERR, "Can't allocate memory for ras struct\n");
- return errno;
+ return -errno;
}
rc = get_tracing_dir(ras);
@@ -925,7 +942,7 @@ int handle_ras_events(int record_events)
pevent = pevent_alloc();
if (!pevent) {
log(TERM, LOG_ERR, "Can't allocate pevent\n");
- rc = errno;
+ rc = -errno;
goto err;
}
@@ -944,7 +961,7 @@ int handle_ras_events(int record_events)
ras_mc_event_handler, NULL, MC_EVENT);
if (!rc)
num_events++;
- else if (rc != -EINVAL)
+ else if (rc != EVENT_DISABLED)
log(ALL, LOG_ERR, "Can't get traces from %s:%s\n",
"ras", "mc_event");
@@ -953,7 +970,7 @@ int handle_ras_events(int record_events)
ras_aer_event_handler, NULL, AER_EVENT);
if (!rc)
num_events++;
- else if (rc != -EINVAL)
+ else if (rc != EVENT_DISABLED)
log(ALL, LOG_ERR, "Can't get traces from %s:%s\n",
"ras", "aer_event");
#endif
@@ -963,7 +980,7 @@ int handle_ras_events(int record_events)
ras_non_standard_event_handler, NULL, NON_STANDARD_EVENT);
if (!rc)
num_events++;
- else if (rc != -EINVAL)
+ else if (rc != EVENT_DISABLED)
log(ALL, LOG_ERR, "Can't get traces from %s:%s\n",
"ras", "non_standard_event");
#endif
@@ -973,7 +990,7 @@ int handle_ras_events(int record_events)
ras_arm_event_handler, NULL, ARM_EVENT);
if (!rc)
num_events++;
- else if (rc != -EINVAL)
+ else if (rc != EVENT_DISABLED)
log(ALL, LOG_ERR, "Can't get traces from %s:%s\n",
"ras", "arm_event");
#endif
@@ -1007,7 +1024,7 @@ int handle_ras_events(int record_events)
/* tell kernel we are listening, so don't printk to console */
(void)open("/sys/kernel/debug/ras/daemon_active", 0);
num_events++;
- } else if (rc != -EINVAL)
+ } else if (rc != EVENT_DISABLED)
log(ALL, LOG_ERR, "Can't get traces from %s:%s\n",
"ras", "extlog_mem_event");
#endif
@@ -1024,7 +1041,7 @@ int handle_ras_events(int record_events)
ras_devlink_event_handler, filter_str, DEVLINK_EVENT);
if (!rc)
num_events++;
- else if (rc != -EINVAL)
+ else if (rc != EVENT_DISABLED)
log(ALL, LOG_ERR, "Can't get traces from %s:%s\n",
"devlink", "devlink_health_report");
#endif
@@ -1048,7 +1065,7 @@ int handle_ras_events(int record_events)
ras_memory_failure_event_handler, NULL, MF_EVENT);
if (!rc)
num_events++;
- else if (rc != -EINVAL)
+ else if (rc != EVENT_DISABLED)
log(ALL, LOG_ERR, "Can't get traces from %s:%s\n",
"ras", "memory_failure_event");
#endif
@@ -1071,7 +1088,7 @@ int handle_ras_events(int record_events)
rc = read_ras_event_all_cpus(data, cpus);
/* Poll doesn't work on this kernel. Fallback to pthread way */
- if (rc == -255) {
+ if (rc == LEGACY_KERNEL) {
if (pthread_mutex_init(&ras->db_lock, NULL) != 0) {
log(SYSLOG, LOG_INFO, "sqlite db lock init has failed\n");
goto err;
--
2.33.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-anolis-os/rasdaemon.git
[email protected]:src-anolis-os/rasdaemon.git
src-anolis-os
rasdaemon
rasdaemon
a8

搜索帮助