diff options
author | Anna Czarnowska <anna.czarnowska@intel.com> | 2010-11-22 20:58:06 +1100 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2010-11-22 20:58:06 +1100 |
commit | edde9560fa19af53928059784c81a0cf5badefa2 (patch) | |
tree | 45876ccbf0fcbd2d51e8324b276481d08f91f758 /Monitor.c | |
parent | 0eac199a2ce5d7febc071616450c26882779ed09 (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>
Diffstat (limited to 'Monitor.c')
-rw-r--r-- | Monitor.c | 44 |
1 files changed, 42 insertions, 2 deletions
@@ -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) { |