summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Czarnowska <anna.czarnowska@intel.com>2010-11-22 20:58:06 +1100
committerNeilBrown <neilb@suse.de>2010-11-22 20:58:06 +1100
commitedde9560fa19af53928059784c81a0cf5badefa2 (patch)
tree45876ccbf0fcbd2d51e8324b276481d08f91f758
parent0eac199a2ce5d7febc071616450c26882779ed09 (diff)
mdadm: added --no-sharing option for Monitor mode
--no-sharing option disables moving spares between arrays/containers. Without the option spares are moved if needed according to config rules. We only allow one process moving spares started with --scan option. If there is such process running and another instance of Monitor is starting without --scan, then we issue a warning but allow it to continue. Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
-rw-r--r--Monitor.c44
-rw-r--r--ReadMe.c2
-rw-r--r--mdadm.c8
-rw-r--r--mdadm.h6
4 files changed, 54 insertions, 6 deletions
diff --git a/Monitor.c b/Monitor.c
index c4256815..2f43b125 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -41,7 +41,8 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail
int Monitor(struct mddev_dev *devlist,
char *mailaddr, char *alert_cmd,
int period, int daemonise, int scan, int oneshot,
- int dosyslog, int test, char* pidfile, int increments)
+ int dosyslog, int test, char *pidfile, int increments,
+ int share)
{
/*
* Every few seconds, scan every md device looking for changes
@@ -149,6 +150,45 @@ int Monitor(struct mddev_dev *devlist,
setsid();
}
+ if (share) {
+ int pid, rv;
+ FILE *fp;
+ char dir[20];
+ struct stat buf;
+ fp = fopen("/var/run/mdadm/autorebuild.pid", "r");
+ if (fp) {
+ fscanf(fp, "%d", &pid);
+ sprintf(dir, "/proc/%d", pid);
+ rv = stat(dir, &buf);
+ if (rv != -1) {
+ if (scan) {
+ fprintf(stderr, Name ": Only one "
+ "autorebuild process allowed"
+ " in scan mode, aborting\n");
+ fclose(fp);
+ return 1;
+ } else {
+ fprintf(stderr, Name ": Warning: One"
+ " autorebuild process already"
+ " running.");
+ }
+ }
+ fclose(fp);
+ }
+ if (scan) {
+ fp = fopen("/var/run/mdadm/autorebuild.pid", "w");
+ if (!fp)
+ fprintf(stderr, Name ": Cannot create"
+ " autorebuild.pid "
+ "file\n");
+ else {
+ pid = getpid();
+ fprintf(fp, "%d\n", pid);
+ fclose(fp);
+ }
+ }
+ }
+
if (devlist == NULL) {
struct mddev_ident *mdlist = conf_get_ident(NULL);
for (; mdlist; mdlist=mdlist->next) {
@@ -453,7 +493,7 @@ int Monitor(struct mddev_dev *devlist,
* Look for another array with spare > 0 and active == raid and same spare_group
* if found, choose a device and hotremove/hotadd
*/
- for (st = statelist; st; st=st->next)
+ if (share) for (st = statelist; st; st=st->next)
if (st->active < st->raid &&
st->spare == 0 &&
st->spare_group != NULL) {
diff --git a/ReadMe.c b/ReadMe.c
index 07abdb7d..54a19986 100644
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -185,6 +185,8 @@ struct option long_options[] = {
{"oneshot", 0, 0, '1'},
{"pid-file", 1, 0, 'i'},
{"syslog", 0, 0, 'y'},
+ {"no-sharing", 0, 0, NoSharing},
+
/* For Grow */
{"backup-file", 1,0, BackupFile},
{"array-size", 1, 0, 'Z'},
diff --git a/mdadm.c b/mdadm.c
index 0eef6bc8..07460c6a 100644
--- a/mdadm.c
+++ b/mdadm.c
@@ -96,6 +96,7 @@ int main(int argc, char *argv[])
int daemonise = 0;
char *pidfile = NULL;
int oneshot = 0;
+ int spare_sharing = 1;
struct supertype *ss = NULL;
int writemostly = 0;
int re_add = 0;
@@ -228,6 +229,7 @@ int main(int argc, char *argv[])
subarray = optarg;
}
case 'K': if (!mode) newmode = MISC; break;
+ case NoSharing: newmode = MONITOR; break;
}
if (mode && newmode == mode) {
/* everybody happy ! */
@@ -777,7 +779,9 @@ int main(int argc, char *argv[])
openlog("mdadm", LOG_PID, SYSLOG_FACILITY);
dosyslog = 1;
continue;
-
+ case O(MONITOR, NoSharing):
+ spare_sharing = 0;
+ continue;
/* now the general management options. Some are applicable
* to other modes. None have arguments.
*/
@@ -1494,7 +1498,7 @@ int main(int argc, char *argv[])
}
rv= Monitor(devlist, mailaddr, program,
delay?delay:60, daemonise, scan, oneshot,
- dosyslog, test, pidfile, increments);
+ dosyslog, test, pidfile, increments, spare_sharing);
break;
case GROW:
diff --git a/mdadm.h b/mdadm.h
index 6b54249f..daaf628d 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -288,7 +288,8 @@ enum special_options {
DetailPlatform,
KillSubarray,
UpdateSubarray, /* 16 */
- IncrementalPath
+ IncrementalPath,
+ NoSharing
};
/* structures read from config file */
@@ -930,7 +931,8 @@ extern int Examine(struct mddev_dev *devlist, int brief, int export, int scan,
extern int Monitor(struct mddev_dev *devlist,
char *mailaddr, char *alert_cmd,
int period, int daemonise, int scan, int oneshot,
- int dosyslog, int test, char *pidfile, int increments);
+ int dosyslog, int test, char *pidfile, int increments,
+ int share);
extern int Kill(char *dev, struct supertype *st, int force, int quiet, int noexcl);
extern int Kill_subarray(char *dev, char *subarray, int quiet);