1 Star 0 Fork 7

gaochang/rasdaemon

forked from src-anolis-os/rasdaemon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1001-rasdaemon-Add-notification-support-when-page-goes-of.patch 6.85 KB
一键复制 编辑 原始数据 按行查看 历史
diff -Nur rasdaemon-0.6.7/Makefile.am rasdaemon-0.6.7_new/Makefile.am
--- rasdaemon-0.6.7/Makefile.am 2023-06-02 15:14:06.995338446 +0800
+++ rasdaemon-0.6.7_new/Makefile.am 2023-06-02 15:14:33.789545754 +0800
@@ -2,7 +2,7 @@
SUBDIRS = libtrace util man
SYSTEMD_SERVICES_IN = misc/rasdaemon.service.in misc/ras-mc-ctl.service.in
SYSTEMD_SERVICES = $(SYSTEMD_SERVICES_IN:.service.in=.service)
-EXTRA_DIST = $(SYSTEMD_SERVICES_IN) misc/rasdaemon.env
+EXTRA_DIST = $(SYSTEMD_SERVICES_IN) misc/rasdaemon.env misc/notices
# This rule is needed because \@sbindir\@ is expanded to \${exec_prefix\}/sbin
# during ./configure phase, therefore it is not possible to add .service.in
diff -Nur rasdaemon-0.6.7/misc/notices/page-ce-offline-post-notice rasdaemon-0.6.7_new/misc/notices/page-ce-offline-post-notice
--- rasdaemon-0.6.7/misc/notices/page-ce-offline-post-notice 1970-01-01 08:00:00.000000000 +0800
+++ rasdaemon-0.6.7_new/misc/notices/page-ce-offline-post-notice 2023-06-02 15:16:14.456324620 +0800
@@ -0,0 +1,17 @@
+#!/bin/sh
+# This shell script can be executed by rasdaemon after a page goes offline.
+
+cd `dirname $0`
+
+[ -x ./page-ce-offline-post-notice.local ] && . ./page-ce-offline-post-notice.local $1
+
+if [ -d page-ce-offline-post-notice.extern ]
+then
+ ls page-ce-offline-post-notice.extern |
+ while read item
+ do
+ [ -x ./page-ce-offline-post-notice.extern/$item ] && . ./page-ce-offline-post-notice.extern/$item $1
+ done
+fi
+
+exit 0
diff -Nur rasdaemon-0.6.7/misc/notices/page-ce-offline-pre-notice rasdaemon-0.6.7_new/misc/notices/page-ce-offline-pre-notice
--- rasdaemon-0.6.7/misc/notices/page-ce-offline-pre-notice 1970-01-01 08:00:00.000000000 +0800
+++ rasdaemon-0.6.7_new/misc/notices/page-ce-offline-pre-notice 2023-06-02 15:16:39.440517924 +0800
@@ -0,0 +1,17 @@
+#!/bin/sh
+# This shell script can be executed by rasdaemon before a page goes offline.
+
+cd `dirname $0`
+
+[ -x ./page-ce-offline-pre-notice.local ] && . ./page-ce-offline-pre-notice.local $1
+
+if [ -d page-ce-offline-pre-notice.extern ]
+then
+ ls page-ce-offline-pre-notice.extern |
+ while read item
+ do
+ [ -x ./page-ce-offline-pre-notice.extern/$item ] && . ./page-ce-offline-pre-notice.extern/$item $1
+ done
+fi
+
+exit 0
diff -Nur rasdaemon-0.6.7/misc/rasdaemon.env rasdaemon-0.6.7_new/misc/rasdaemon.env
--- rasdaemon-0.6.7/misc/rasdaemon.env 2023-06-02 15:14:06.994338438 +0800
+++ rasdaemon-0.6.7_new/misc/rasdaemon.env 2023-06-02 15:17:54.307097173 +0800
@@ -27,3 +27,7 @@
# soft-then-hard First try to soft offline, then try hard offlining.
# Note: default offline choice is "soft".
PAGE_CE_ACTION="soft"
+
+# Notices script when doing memory offline
+PAGE_CE_OFFLINE_PRE_NOTICE="page-ce-offline-pre-notice"
+PAGE_CE_OFFLINE_POST_NOTICE="page-ce-offline-post-notice"
diff -Nur rasdaemon-0.6.7/misc/rasdaemon.spec.in rasdaemon-0.6.7_new/misc/rasdaemon.spec.in
--- rasdaemon-0.6.7/misc/rasdaemon.spec.in 2023-06-02 15:14:06.994338438 +0800
+++ rasdaemon-0.6.7_new/misc/rasdaemon.spec.in 2023-06-02 15:19:03.105629470 +0800
@@ -46,6 +46,8 @@
make install DESTDIR=%{buildroot}
install -D -p -m 0644 misc/rasdaemon.service %{buildroot}/%{_unitdir}/rasdaemon.service
install -D -p -m 0644 misc/ras-mc-ctl.service %{buildroot}%{_unitdir}/ras-mc-ctl.service
+install -d %{buildroot}%{_sysconfdir}/rasdaemon_notices/
+install -D -p -m 0755 misc/notices/* %{buildroot}%{_sysconfdir}/rasdaemon_notices/
rm INSTALL %{buildroot}/usr/include/*.h
%files
@@ -57,6 +59,7 @@
%{_sysconfdir}/ras/dimm_labels.d
@SYSCONFDEFDIR@/%{name}
%config(noreplace) @SYSCONFDEFDIR@/%{name}
+%config(noreplace) %{_sysconfdir}/rasdaemon_notices/*
%changelog
diff -Nur rasdaemon-0.6.7/ras-page-isolation.c rasdaemon-0.6.7_new/ras-page-isolation.c
--- rasdaemon-0.6.7/ras-page-isolation.c 2023-06-02 15:14:06.995338446 +0800
+++ rasdaemon-0.6.7_new/ras-page-isolation.c 2023-06-02 16:06:28.020663355 +0800
@@ -17,12 +17,16 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include "ras-logger.h"
#include "ras-page-isolation.h"
+#define MAX_PATH_LEN 64
#define PARSED_ENV_LEN 50
static const struct config threshold_units[] = {
{ "m", 1000 },
@@ -76,6 +80,8 @@
static enum otype offline = OFFLINE_SOFT;
static struct rb_root page_records;
+static char pre_notice[MAX_PATH_LEN];
+static char post_notice[MAX_PATH_LEN];
static void page_offline_init(void)
{
@@ -205,16 +211,94 @@
threshold_string, cycle_string);
}
+static void page_notice_init(void)
+{
+ char *notice_root = "/etc/rasdaemon_notices";
+ char *pre_re = getenv("PAGE_CE_OFFLINE_PRE_NOTICE");
+ char *post_re = getenv("PAGE_CE_OFFLINE_POST_NOTICE");
+
+ if (offline <= OFFLINE_ACCOUNT)
+ return;
+
+ snprintf(pre_notice, sizeof(pre_notice), "%s/%s", notice_root, pre_re);
+ if (access(pre_notice, R_OK|X_OK) < 0)
+ log(TERM, LOG_ERR, "cannot access page notice '%s'\n", pre_notice);
+
+ snprintf(post_notice, sizeof(post_notice), "%s/%s", notice_root, post_re);
+ if (access(post_notice, R_OK|X_OK) < 0)
+ log(TERM, LOG_ERR, "cannot access page notice '%s'\n", post_notice);
+}
+
void ras_page_account_init(void)
{
page_offline_init();
page_isolation_init();
+ page_notice_init();
+}
+
+static void finish_child(pid_t child, int status)
+{
+ if (WIFEXITED(status) && WEXITSTATUS(status)) {
+ log(TERM, LOG_INFO, "notice exited with status %d\n", WEXITSTATUS(status));
+ } else if (WIFSIGNALED(status)) {
+ log(TERM, LOG_INFO,"notice died with signal %s\n", strsignal(WTERMSIG(status)));
+ }
+
+ return;
}
+static void __run_notice(char *argv[], char **env)
+{
+ pid_t child;
+ int status;
+
+ child = fork();
+ if (child < 0) {
+ log(TERM, LOG_ERR, "Cannot create process for offline notice");
+ return;
+ }
+ if (child == 0) {
+ execve(argv[0], argv, env);
+ _exit(127);
+ }
+ else {
+ waitpid(child, &status, 0);
+ finish_child(child, status);
+ }
+}
+
+static void run_notice(char *argv[])
+{
+ int MAX_ENV = 20;
+ char *env[MAX_ENV];
+ int ei = 0;
+ int i;
+
+ asprintf(&env[ei++], "PATH=%s", getenv("PATH") ?: "/sbin:/usr/sbin:/bin:/usr/bin");
+ env[ei] = NULL;
+ assert(ei < MAX_ENV);
+
+ __run_notice(argv, env);
+
+ for (i = 0; i < ei; i++)
+ free(env[i]);
+ }
+
static int do_page_offline(unsigned long long addr, enum otype type)
{
int fd, rc;
char buf[20];
+ char *args;
+ char *argv[] = {
+ NULL,
+ NULL,
+ NULL,
+ };
+
+ asprintf(&args, "%llu", addr);
+ argv[0] = (char*)&pre_notice;
+ argv[1] = args;
+ run_notice(argv);
fd = open(kernel_offline[type], O_WRONLY);
if (fd == -1) {
@@ -228,6 +312,12 @@
log(TERM, LOG_ERR, "page offline addr(%s) by %s failed, errno:%d\n", buf, kernel_offline[type], errno);
}
close(fd);
+
+ argv[0] = (char*)&post_notice;
+ run_notice(argv);
+
+ free(args);
+
return rc;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gcdota930915/rasdaemon.git
[email protected]:gcdota930915/rasdaemon.git
gcdota930915
rasdaemon
rasdaemon
a8

搜索帮助