From 37dfc3d638aee1fe3ae6d6b4aa0e648e1a9d61ca Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 14 Dec 2006 17:31:25 +1100 Subject: [PATCH] When resync finished, report the mismatch count if there is one. This doesn't get mailed out, but will appear in syslog... Maybe it should be mailed if it was a 'check' or 'repair' pass... --- Monitor.c | 22 +++++++++++++++++++--- mdadm.h | 2 ++ super1.c | 2 +- sysfs.c | 6 ++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Monitor.c b/Monitor.c index 5091c51b..f7bb48ce 100644 --- a/Monitor.c +++ b/Monitor.c @@ -303,8 +303,22 @@ int Monitor(mddev_dev_t devlist, if (mse && mse->percent == -1 && - st->percent >= 0) - alert("RebuildFinished", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog); + st->percent >= 0) { + /* Rebuild/sync/whatever just finished. + * If there is a number in /mismatch_cnt, + * we should report that. + */ + struct sysarray *sra = + sysfs_read(-1, st->devnum, GET_MISMATCH); + if (sra && sra->mismatch_cnt > 0) { + char cnt[40]; + sprintf(cnt, " mismatches found: %d", sra->mismatch_cnt); + alert("RebuildFinished", dev, cnt, mailaddr, mailfrom, alert_cmd, dosyslog); + } else + alert("RebuildFinished", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog); + if (sra) + free(sra); + } if (mse) st->percent = mse->percent; @@ -510,8 +524,10 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail fprintf(mp, "A %s event had been detected on md device %s.\n\n", event, dev); - if (disc) + 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"); diff --git a/mdadm.h b/mdadm.h index f1768a53..f6350e18 100644 --- a/mdadm.h +++ b/mdadm.h @@ -258,6 +258,7 @@ struct sysarray { int level; int spares; int cache_size; + int mismatch_cnt; }; /* various details can be requested */ #define GET_LEVEL 1 @@ -265,6 +266,7 @@ struct sysarray { #define GET_COMPONENT 4 #define GET_CHUNK 8 #define GET_CACHE 16 +#define GET_MISMATCH 32 #define GET_DEVS 1024 /* gets role, major, minor */ #define GET_OFFSET 2048 diff --git a/super1.c b/super1.c index b7d1c996..be1a0e5b 100644 --- a/super1.c +++ b/super1.c @@ -1164,7 +1164,7 @@ add_internal_bitmap1(struct supertype *st, void *sbv, unsigned long long min_chunk; long offset; int chunk = *chunkp; - int room; + int room = 0; struct mdp_superblock_1 *sb = sbv; bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + 1024); diff --git a/sysfs.c b/sysfs.c index 166481f1..25ede6b7 100644 --- a/sysfs.c +++ b/sysfs.c @@ -113,6 +113,12 @@ struct sysarray *sysfs_read(int fd, int devnum, unsigned long options) goto abort; sra->cache_size = strtoul(buf, NULL, 0); } + if (options & GET_MISMATCH) { + strcpy(base, "mismatch_cnt"); + if (load_sys(fname, buf)) + goto abort; + sra->mismatch_cnt = strtoul(buf, NULL, 0); + } if (! (options & GET_DEVS)) return sra; -- 2.39.2