parent
e1d08abce6
commit
f0d40589eb
@ -1,31 +0,0 @@
|
||||
From 75f23f662fdfd6709be3d1d554d435cc0aa33443 Mon Sep 17 00:00:00 2001
|
||||
From: Logan Gunthorpe <logang@deltatee.com>
|
||||
Date: Wed, 21 Sep 2022 14:43:50 -0600
|
||||
Subject: [PATCH 62/63] Create: goto abort_locked instead of return 1 in error
|
||||
path
|
||||
|
||||
The return 1 after the fstat_is_blkdev() check should be replaced
|
||||
with an error return that goes through the error path to unlock
|
||||
resources locked by this function.
|
||||
|
||||
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
|
||||
---
|
||||
Create.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/Create.c b/Create.c
|
||||
index 953e7372..2e8203ec 100644
|
||||
--- a/Create.c
|
||||
+++ b/Create.c
|
||||
@@ -939,7 +939,7 @@ int Create(struct supertype *st, char *mddev,
|
||||
goto abort_locked;
|
||||
}
|
||||
if (!fstat_is_blkdev(fd, dv->devname, &rdev))
|
||||
- return 1;
|
||||
+ goto abort_locked;
|
||||
inf->disk.major = major(rdev);
|
||||
inf->disk.minor = minor(rdev);
|
||||
}
|
||||
--
|
||||
2.38.1
|
||||
|
@ -0,0 +1,233 @@
|
||||
From 3698867194f27fdd7824b8bdd172d619a2c087cc Mon Sep 17 00:00:00 2001
|
||||
From: Mateusz Grzonka <mateusz.grzonka@intel.com>
|
||||
Date: Wed, 7 Sep 2022 14:56:49 +0200
|
||||
Subject: [PATCH 62/83] Mdmonitor: Split alert() into separate functions
|
||||
|
||||
Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
|
||||
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
|
||||
---
|
||||
Monitor.c | 186 ++++++++++++++++++++++++++++--------------------------
|
||||
1 file changed, 95 insertions(+), 91 deletions(-)
|
||||
|
||||
diff --git a/Monitor.c b/Monitor.c
|
||||
index 7d7dc4d2..0036e8cd 100644
|
||||
--- a/Monitor.c
|
||||
+++ b/Monitor.c
|
||||
@@ -66,7 +66,7 @@ struct alert_info {
|
||||
static int make_daemon(char *pidfile);
|
||||
static int check_one_sharer(int scan);
|
||||
static void write_autorebuild_pid(void);
|
||||
-static void alert(char *event, char *dev, char *disc, struct alert_info *info);
|
||||
+static void alert(const char *event, const char *dev, const char *disc, struct alert_info *info);
|
||||
static int check_array(struct state *st, struct mdstat_ent *mdstat,
|
||||
int test, struct alert_info *info,
|
||||
int increments, char *prefer);
|
||||
@@ -407,111 +407,115 @@ static void write_autorebuild_pid()
|
||||
}
|
||||
}
|
||||
|
||||
-static void alert(char *event, char *dev, char *disc, struct alert_info *info)
|
||||
+static void execute_alert_cmd(const char *event, const char *dev, const char *disc, struct alert_info *info)
|
||||
+{
|
||||
+ int pid = fork();
|
||||
+
|
||||
+ switch (pid) {
|
||||
+ default:
|
||||
+ waitpid(pid, NULL, 0);
|
||||
+ break;
|
||||
+ case -1:
|
||||
+ pr_err("Cannot fork to execute alert command");
|
||||
+ break;
|
||||
+ case 0:
|
||||
+ execl(info->alert_cmd, info->alert_cmd, event, dev, disc, NULL);
|
||||
+ exit(2);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void send_event_email(const char *event, const char *dev, const char *disc, struct alert_info *info)
|
||||
+{
|
||||
+ FILE *mp, *mdstat;
|
||||
+ char hname[256];
|
||||
+ char buf[BUFSIZ];
|
||||
+ int n;
|
||||
+
|
||||
+ mp = popen(Sendmail, "w");
|
||||
+ if (!mp) {
|
||||
+ pr_err("Cannot open pipe stream for sendmail.\n");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ gethostname(hname, sizeof(hname));
|
||||
+ signal(SIGPIPE, SIG_IGN);
|
||||
+ if (info->mailfrom)
|
||||
+ fprintf(mp, "From: %s\n", info->mailfrom);
|
||||
+ else
|
||||
+ fprintf(mp, "From: %s monitoring <root>\n", Name);
|
||||
+ fprintf(mp, "To: %s\n", info->mailaddr);
|
||||
+ fprintf(mp, "Subject: %s event on %s:%s\n\n", event, dev, hname);
|
||||
+ fprintf(mp, "This is an automatically generated mail message. \n");
|
||||
+ fprintf(mp, "A %s event had been detected on md device %s.\n\n", event, dev);
|
||||
+
|
||||
+ if (disc && disc[0] != ' ')
|
||||
+ fprintf(mp,
|
||||
+ "It could be related to component device %s.\n\n", disc);
|
||||
+ if (disc && disc[0] == ' ')
|
||||
+ fprintf(mp, "Extra information:%s.\n\n", disc);
|
||||
+
|
||||
+ mdstat = fopen("/proc/mdstat", "r");
|
||||
+ if (!mdstat) {
|
||||
+ pr_err("Cannot open /proc/mdstat\n");
|
||||
+ pclose(mp);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ fprintf(mp, "The /proc/mdstat file currently contains the following:\n\n");
|
||||
+ while ((n = fread(buf, 1, sizeof(buf), mdstat)) > 0)
|
||||
+ n = fwrite(buf, 1, n, mp);
|
||||
+ fclose(mdstat);
|
||||
+ pclose(mp);
|
||||
+}
|
||||
+
|
||||
+static void log_event_to_syslog(const char *event, const char *dev, const char *disc)
|
||||
{
|
||||
int priority;
|
||||
+ /* Log at a different severity depending on the event.
|
||||
+ *
|
||||
+ * These are the critical events: */
|
||||
+ if (strncmp(event, "Fail", 4) == 0 ||
|
||||
+ strncmp(event, "Degrade", 7) == 0 ||
|
||||
+ strncmp(event, "DeviceDisappeared", 17) == 0)
|
||||
+ priority = LOG_CRIT;
|
||||
+ /* Good to know about, but are not failures: */
|
||||
+ else if (strncmp(event, "Rebuild", 7) == 0 ||
|
||||
+ strncmp(event, "MoveSpare", 9) == 0 ||
|
||||
+ strncmp(event, "Spares", 6) != 0)
|
||||
+ priority = LOG_WARNING;
|
||||
+ /* Everything else: */
|
||||
+ else
|
||||
+ priority = LOG_INFO;
|
||||
|
||||
+ if (disc && disc[0] != ' ')
|
||||
+ syslog(priority,
|
||||
+ "%s event detected on md device %s, component device %s", event, dev, disc);
|
||||
+ else if (disc)
|
||||
+ syslog(priority, "%s event detected on md device %s: %s", event, dev, disc);
|
||||
+ else
|
||||
+ syslog(priority, "%s event detected on md device %s", event, dev);
|
||||
+}
|
||||
+
|
||||
+static void alert(const char *event, const char *dev, const char *disc, struct alert_info *info)
|
||||
+{
|
||||
if (!info->alert_cmd && !info->mailaddr && !info->dosyslog) {
|
||||
time_t now = time(0);
|
||||
|
||||
printf("%1.15s: %s on %s %s\n", ctime(&now) + 4,
|
||||
event, dev, disc?disc:"unknown device");
|
||||
}
|
||||
- if (info->alert_cmd) {
|
||||
- int pid = fork();
|
||||
- switch(pid) {
|
||||
- default:
|
||||
- waitpid(pid, NULL, 0);
|
||||
- break;
|
||||
- case -1:
|
||||
- break;
|
||||
- case 0:
|
||||
- execl(info->alert_cmd, info->alert_cmd,
|
||||
- event, dev, disc, NULL);
|
||||
- exit(2);
|
||||
- }
|
||||
- }
|
||||
+ if (info->alert_cmd)
|
||||
+ execute_alert_cmd(event, dev, disc, info);
|
||||
+
|
||||
if (info->mailaddr && (strncmp(event, "Fail", 4) == 0 ||
|
||||
strncmp(event, "Test", 4) == 0 ||
|
||||
strncmp(event, "Spares", 6) == 0 ||
|
||||
strncmp(event, "Degrade", 7) == 0)) {
|
||||
- FILE *mp = popen(Sendmail, "w");
|
||||
- if (mp) {
|
||||
- FILE *mdstat;
|
||||
- char hname[256];
|
||||
-
|
||||
- gethostname(hname, sizeof(hname));
|
||||
- signal_s(SIGPIPE, SIG_IGN);
|
||||
-
|
||||
- if (info->mailfrom)
|
||||
- fprintf(mp, "From: %s\n", info->mailfrom);
|
||||
- else
|
||||
- fprintf(mp, "From: %s monitoring <root>\n",
|
||||
- Name);
|
||||
- fprintf(mp, "To: %s\n", info->mailaddr);
|
||||
- fprintf(mp, "Subject: %s event on %s:%s\n\n",
|
||||
- event, dev, hname);
|
||||
-
|
||||
- fprintf(mp,
|
||||
- "This is an automatically generated mail message from %s\n", Name);
|
||||
- fprintf(mp, "running on %s\n\n", hname);
|
||||
-
|
||||
- fprintf(mp,
|
||||
- "A %s event had been detected on md device %s.\n\n", event, dev);
|
||||
-
|
||||
- if (disc && disc[0] != ' ')
|
||||
- fprintf(mp,
|
||||
- "It could be related to component device %s.\n\n", disc);
|
||||
- if (disc && disc[0] == ' ')
|
||||
- fprintf(mp, "Extra information:%s.\n\n", disc);
|
||||
-
|
||||
- fprintf(mp, "Faithfully yours, etc.\n");
|
||||
-
|
||||
- mdstat = fopen("/proc/mdstat", "r");
|
||||
- if (mdstat) {
|
||||
- char buf[8192];
|
||||
- int n;
|
||||
- fprintf(mp,
|
||||
- "\nP.S. The /proc/mdstat file currently contains the following:\n\n");
|
||||
- while ((n = fread(buf, 1, sizeof(buf),
|
||||
- mdstat)) > 0)
|
||||
- n = fwrite(buf, 1, n, mp);
|
||||
- fclose(mdstat);
|
||||
- }
|
||||
- pclose(mp);
|
||||
- }
|
||||
+ send_event_email(event, dev, disc, info);
|
||||
}
|
||||
|
||||
- /* log the event to syslog maybe */
|
||||
- if (info->dosyslog) {
|
||||
- /* Log at a different severity depending on the event.
|
||||
- *
|
||||
- * These are the critical events: */
|
||||
- if (strncmp(event, "Fail", 4) == 0 ||
|
||||
- strncmp(event, "Degrade", 7) == 0 ||
|
||||
- strncmp(event, "DeviceDisappeared", 17) == 0)
|
||||
- priority = LOG_CRIT;
|
||||
- /* Good to know about, but are not failures: */
|
||||
- else if (strncmp(event, "Rebuild", 7) == 0 ||
|
||||
- strncmp(event, "MoveSpare", 9) == 0 ||
|
||||
- strncmp(event, "Spares", 6) != 0)
|
||||
- priority = LOG_WARNING;
|
||||
- /* Everything else: */
|
||||
- else
|
||||
- priority = LOG_INFO;
|
||||
-
|
||||
- if (disc && disc[0] != ' ')
|
||||
- syslog(priority,
|
||||
- "%s event detected on md device %s, component device %s", event, dev, disc);
|
||||
- else if (disc)
|
||||
- syslog(priority,
|
||||
- "%s event detected on md device %s: %s",
|
||||
- event, dev, disc);
|
||||
- else
|
||||
- syslog(priority,
|
||||
- "%s event detected on md device %s",
|
||||
- event, dev);
|
||||
- }
|
||||
+ if (info->dosyslog)
|
||||
+ log_event_to_syslog(event, dev, disc);
|
||||
}
|
||||
|
||||
static int check_array(struct state *st, struct mdstat_ent *mdstat,
|
||||
--
|
||||
2.38.1
|
||||
|
@ -1,59 +0,0 @@
|
||||
From 249da94563dddb852ccb52164411ff99a6c90489 Mon Sep 17 00:00:00 2001
|
||||
From: Logan Gunthorpe <logang@deltatee.com>
|
||||
Date: Wed, 21 Sep 2022 14:43:51 -0600
|
||||
Subject: [PATCH 63/63] Create: remove safe_mode_delay local variable
|
||||
|
||||
All .getinfo_super() call sets the info.safe_mode_delay variables
|
||||
to a constant value, so no matter what the current state is
|
||||
that function will always set it to the same value.
|
||||
|
||||
Create() calls .getinfo_super() multiple times while creating the array.
|
||||
The value is stored in a local variable for every disk in the loop
|
||||
to add disks (so the last disc call takes precedence). The local
|
||||
variable is then used in the call to sysfs_set_safemode().
|
||||
|
||||
This can be simplified by using info.safe_mode_delay directly. The info
|
||||
variable had .getinfo_super() called on it early in the function so, by the
|
||||
reasoning above, it will have the same value as the local variable which
|
||||
can thus be removed.
|
||||
|
||||
Doing this allows for factoring out code from Create() in a subsequent
|
||||
patch.
|
||||
|
||||
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
|
||||
---
|
||||
Create.c | 4 +---
|
||||
1 file changed, 1 insertion(+), 3 deletions(-)
|
||||
|
||||
diff --git a/Create.c b/Create.c
|
||||
index 2e8203ec..8ded81dc 100644
|
||||
--- a/Create.c
|
||||
+++ b/Create.c
|
||||
@@ -137,7 +137,6 @@ int Create(struct supertype *st, char *mddev,
|
||||
int did_default = 0;
|
||||
int do_default_layout = 0;
|
||||
int do_default_chunk = 0;
|
||||
- unsigned long safe_mode_delay = 0;
|
||||
char chosen_name[1024];
|
||||
struct map_ent *map = NULL;
|
||||
unsigned long long newsize;
|
||||
@@ -952,7 +951,6 @@ int Create(struct supertype *st, char *mddev,
|
||||
goto abort_locked;
|
||||
}
|
||||
st->ss->getinfo_super(st, inf, NULL);
|
||||
- safe_mode_delay = inf->safe_mode_delay;
|
||||
|
||||
if (have_container && c->verbose > 0)
|
||||
pr_err("Using %s for device %d\n",
|
||||
@@ -1065,7 +1063,7 @@ int Create(struct supertype *st, char *mddev,
|
||||
"readonly");
|
||||
break;
|
||||
}
|
||||
- sysfs_set_safemode(&info, safe_mode_delay);
|
||||
+ sysfs_set_safemode(&info, info.safe_mode_delay);
|
||||
if (err) {
|
||||
pr_err("failed to activate array.\n");
|
||||
ioctl(mdfd, STOP_ARRAY, NULL);
|
||||
--
|
||||
2.38.1
|
||||
|
@ -0,0 +1,41 @@
|
||||
From f40ac0e7e6043361ad12e9db97c07e56c3977cf6 Mon Sep 17 00:00:00 2001
|
||||
From: Blazej Kucman <blazej.kucman@intel.com>
|
||||
Date: Mon, 19 Dec 2022 11:21:57 +0100
|
||||
Subject: [PATCH 63/83] Monitor: block if monitor modes are combined.
|
||||
|
||||
Block monitoring start if --scan mode and MD devices list are combined.
|
||||
|
||||
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
|
||||
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
|
||||
---
|
||||
Monitor.c | 7 ++++++-
|
||||
1 file changed, 6 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/Monitor.c b/Monitor.c
|
||||
index 0036e8cd..188cb8be 100644
|
||||
--- a/Monitor.c
|
||||
+++ b/Monitor.c
|
||||
@@ -123,7 +123,7 @@ int Monitor(struct mddev_dev *devlist,
|
||||
* and if we can get_disk_info and find a name
|
||||
* Then we hot-remove and hot-add to the other array
|
||||
*
|
||||
- * If devlist is NULL, then we can monitor everything because --scan
|
||||
+ * If devlist is NULL, then we can monitor everything if --scan
|
||||
* was given. We get an initial list from config file and add anything
|
||||
* that appears in /proc/mdstat
|
||||
*/
|
||||
@@ -136,6 +136,11 @@ int Monitor(struct mddev_dev *devlist,
|
||||
struct mddev_ident *mdlist;
|
||||
int delay_for_event = c->delay;
|
||||
|
||||
+ if (devlist && c->scan) {
|
||||
+ pr_err("Devices list and --scan option cannot be combined - not monitoring.\n");
|
||||
+ return 1;
|
||||
+ }
|
||||
+
|
||||
if (!mailaddr)
|
||||
mailaddr = conf_get_mailaddr();
|
||||
|
||||
--
|
||||
2.38.1
|
||||
|
@ -0,0 +1,119 @@
|
||||
From 725e37cd14866906ba28c970394b9f7a4cd97413 Mon Sep 17 00:00:00 2001
|
||||
From: Blazej Kucman <blazej.kucman@intel.com>
|
||||
Date: Mon, 19 Dec 2022 11:21:58 +0100
|
||||
Subject: [PATCH 64/83] Update mdadm Monitor manual.
|
||||
|
||||
- describe monitor work modes,
|
||||
- clarify the turning off condition,
|
||||
- describe the mdmonitor.service as a prefered management way.
|
||||
|
||||
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
|
||||
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
|
||||
---
|
||||
mdadm.8.in | 71 ++++++++++++++++++++++++ |