2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Email: <neilb@suse.de>
33 /* The largest number of disks current arrays can manage is 384
34 * This really should be dynamically, but that will have to wait
35 * At least it isn't MD_SB_DISKS.
40 int devnum; /* to sync with mdstat info */
44 int active, working, failed, spare, raid;
46 int devstate[MaxDisks];
47 dev_t devid[MaxDisks];
49 int parent_dev; /* For subarray, devnum of parent.
52 struct supertype *metadata;
53 struct state *subarray;/* for a container it is a link to first subarray
54 * for a subarray it is a link to next subarray
55 * in the same container */
56 struct state *parent; /* for a subarray it is a link to its container
67 static int make_daemon(char *pidfile);
68 static int check_one_sharer(int scan);
69 static void alert(char *event, char *dev, char *disc, struct alert_info *info);
70 static int check_array(struct state *st, struct mdstat_ent *mdstat,
71 int test, struct alert_info *info,
73 static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
74 int test, struct alert_info *info);
75 static void try_spare_migration(struct state *statelist, struct alert_info *info);
76 static void link_containers_with_subarrays(struct state *list);
78 int Monitor(struct mddev_dev *devlist,
79 char *mailaddr, char *alert_cmd,
80 int period, int daemonise, int scan, int oneshot,
81 int dosyslog, int test, char *pidfile, int increments,
85 * Every few seconds, scan every md device looking for changes
86 * When a change is found, log it, possibly run the alert command,
87 * and possibly send Email
89 * For each array, we record:
91 * active/working/failed/spare drives
92 * State of each device.
93 * %rebuilt if rebuilding
95 * If the update time changes, check out all the data again
96 * It is possible that we cannot get the state of each device
97 * due to bugs in the md kernel module.
98 * We also read /proc/mdstat to get rebuild percent,
99 * and to get state on all active devices incase of kernel bug.
103 * An active device had Faulty set or Active/Sync removed
105 * A spare device had Faulty set
107 * An active device had a reverse transition
109 * percent went from -1 to +ve
111 * percent went from below to not-below NN%
113 * Couldn't access a device which was previously visible
115 * if we detect an array with active<raid and spare==0
116 * we look at other arrays that have same spare-group
117 * If we find one with active==raid and spare>0,
118 * and if we can get_disk_info and find a name
119 * Then we hot-remove and hot-add to the other array
121 * If devlist is NULL, then we can monitor everything because --scan
122 * was given. We get an initial list from config file and add anything
123 * that appears in /proc/mdstat
126 struct state *statelist = NULL;
128 struct mdstat_ent *mdstat = NULL;
129 char *mailfrom = NULL;
130 struct alert_info info;
133 mailaddr = conf_get_mailaddr();
134 if (mailaddr && ! scan)
135 fprintf(stderr, Name ": Monitor using email address \"%s\" from config file\n",
138 mailfrom = conf_get_mailfrom();
141 alert_cmd = conf_get_program();
142 if (alert_cmd && ! scan)
143 fprintf(stderr, Name ": Monitor using program \"%s\" from config file\n",
146 if (scan && !mailaddr && !alert_cmd && !dosyslog) {
147 fprintf(stderr, Name ": No mail address or alert command - not monitoring.\n");
150 info.alert_cmd = alert_cmd;
151 info.mailaddr = mailaddr;
152 info.mailfrom = mailfrom;
153 info.dosyslog = dosyslog;
156 int rv = make_daemon(pidfile);
162 if (check_one_sharer(scan))
165 if (devlist == NULL) {
166 struct mddev_ident *mdlist = conf_get_ident(NULL);
167 for (; mdlist; mdlist=mdlist->next) {
169 if (mdlist->devname == NULL)
171 if (strcasecmp(mdlist->devname, "<ignore>") == 0)
173 st = calloc(1, sizeof *st);
176 if (mdlist->devname[0] == '/')
177 st->devname = strdup(mdlist->devname);
179 st->devname = malloc(8+strlen(mdlist->devname)+1);
180 strcpy(strcpy(st->devname, "/dev/md/"),
183 st->next = statelist;
184 st->devnum = INT_MAX;
186 st->expected_spares = mdlist->spare_disks;
187 if (mdlist->spare_group)
188 st->spare_group = strdup(mdlist->spare_group);
192 struct mddev_dev *dv;
193 for (dv=devlist ; dv; dv=dv->next) {
194 struct mddev_ident *mdlist = conf_get_ident(dv->devname);
195 struct state *st = calloc(1, sizeof *st);
198 st->devname = strdup(dv->devname);
199 st->next = statelist;
200 st->devnum = INT_MAX;
202 st->expected_spares = -1;
204 st->expected_spares = mdlist->spare_disks;
205 if (mdlist->spare_group)
206 st->spare_group = strdup(mdlist->spare_group);
220 mdstat = mdstat_read(oneshot?0:1, 0);
222 for (st=statelist; st; st=st->next)
223 if (check_array(st, mdstat, test, &info, increments))
226 /* now check if there are any new devices found in mdstat */
228 new_found = add_new_arrays(mdstat, &statelist, test,
231 /* If an array has active < raid && spare == 0 && spare_group != NULL
232 * Look for another array with spare > 0 and active == raid and same spare_group
233 * if found, choose a device and hotremove/hotadd
235 if (share && anydegraded)
236 try_spare_migration(statelist, &info);
250 static int make_daemon(char *pidfile)
253 * -1 in the forked daemon
256 * so a none-negative becomes the exit code.
264 pid_file=fopen(pidfile, "w");
266 perror("cannot create pid file");
268 fprintf(pid_file,"%d\n", pid);
279 open("/dev/null", O_RDWR);
286 static int check_one_sharer(int scan)
292 fp = fopen("/var/run/mdadm/autorebuild.pid", "r");
294 if (fscanf(fp, "%d", &pid) != 1)
296 sprintf(dir, "/proc/%d", pid);
297 rv = stat(dir, &buf);
300 fprintf(stderr, Name ": Only one "
301 "autorebuild process allowed"
302 " in scan mode, aborting\n");
306 fprintf(stderr, Name ": Warning: One"
307 " autorebuild process already"
314 if (mkdir("/var/run/mdadm", S_IRWXU) < 0 &&
316 fprintf(stderr, Name ": Can't create "
317 "autorebuild.pid file\n");
319 fp = fopen("/var/run/mdadm/autorebuild.pid", "w");
321 fprintf(stderr, Name ": Cannot create"
326 fprintf(fp, "%d\n", pid);
334 static void alert(char *event, char *dev, char *disc, struct alert_info *info)
338 if (!info->alert_cmd && !info->mailaddr && !info->dosyslog) {
339 time_t now = time(0);
341 printf("%1.15s: %s on %s %s\n", ctime(&now)+4, event, dev, disc?disc:"unknown device");
343 if (info->alert_cmd) {
347 waitpid(pid, NULL, 0);
352 execl(info->alert_cmd, info->alert_cmd,
353 event, dev, disc, NULL);
357 if (info->mailaddr &&
358 (strncmp(event, "Fail", 4)==0 ||
359 strncmp(event, "Test", 4)==0 ||
360 strncmp(event, "Spares", 6)==0 ||
361 strncmp(event, "Degrade", 7)==0)) {
362 FILE *mp = popen(Sendmail, "w");
366 gethostname(hname, sizeof(hname));
367 signal(SIGPIPE, SIG_IGN);
369 fprintf(mp, "From: %s\n", info->mailfrom);
371 fprintf(mp, "From: " Name " monitoring <root>\n");
372 fprintf(mp, "To: %s\n", info->mailaddr);
373 fprintf(mp, "Subject: %s event on %s:%s\n\n",
377 "This is an automatically generated"
378 " mail message from " Name "\n");
379 fprintf(mp, "running on %s\n\n", hname);
382 "A %s event had been detected on"
383 " md device %s.\n\n", event, dev);
385 if (disc && disc[0] != ' ')
387 "It could be related to"
388 " component device %s.\n\n", disc);
389 if (disc && disc[0] == ' ')
390 fprintf(mp, "Extra information:%s.\n\n", disc);
392 fprintf(mp, "Faithfully yours, etc.\n");
394 mdstat = fopen("/proc/mdstat", "r");
399 "\nP.S. The /proc/mdstat file"
400 " currently contains the following:\n\n");
401 while ( (n=fread(buf, 1, sizeof(buf), mdstat)) > 0)
402 n=fwrite(buf, 1, n, mp);
409 /* log the event to syslog maybe */
410 if (info->dosyslog) {
411 /* Log at a different severity depending on the event.
413 * These are the critical events: */
414 if (strncmp(event, "Fail", 4)==0 ||
415 strncmp(event, "Degrade", 7)==0 ||
416 strncmp(event, "DeviceDisappeared", 17)==0)
418 /* Good to know about, but are not failures: */
419 else if (strncmp(event, "Rebuild", 7)==0 ||
420 strncmp(event, "MoveSpare", 9)==0 ||
421 strncmp(event, "Spares", 6) != 0)
422 priority = LOG_WARNING;
423 /* Everything else: */
429 "%s event detected on md device %s,"
430 " component device %s", event, dev, disc);
433 "%s event detected on md device %s",
438 static int check_array(struct state *st, struct mdstat_ent *mdstat,
439 int test, struct alert_info *ainfo,
442 /* Update the state 'st' to reflect any changes shown in mdstat,
443 * or found by directly examining the array, and return
444 * '1' if the array is degraded, or '0' if it is optimal (or dead).
446 struct { int state, major, minor; } info[MaxDisks];
447 mdu_array_info_t array;
448 struct mdstat_ent *mse = NULL, *mse2;
449 char *dev = st->devname;
454 alert("TestMessage", dev, NULL, ainfo);
455 fd = open(dev, O_RDONLY);
458 alert("DeviceDisappeared", dev, NULL, ainfo);
462 fcntl(fd, F_SETFD, FD_CLOEXEC);
463 if (ioctl(fd, GET_ARRAY_INFO, &array)<0) {
465 alert("DeviceDisappeared", dev, NULL, ainfo);
470 /* It's much easier to list what array levels can't
471 * have a device disappear than all of them that can
473 if (array.level == 0 || array.level == -1) {
475 alert("DeviceDisappeared", dev, "Wrong-Level", ainfo);
480 if (st->devnum == INT_MAX) {
482 if (fstat(fd, &stb) == 0 &&
483 (S_IFMT&stb.st_mode)==S_IFBLK) {
484 if (major(stb.st_rdev) == MD_MAJOR)
485 st->devnum = minor(stb.st_rdev);
487 st->devnum = -1- (minor(stb.st_rdev)>>6);
491 for (mse2 = mdstat ; mse2 ; mse2=mse2->next)
492 if (mse2->devnum == st->devnum) {
493 mse2->devnum = INT_MAX; /* flag it as "used" */
498 /* duplicated array in statelist
499 * or re-created after reading mdstat*/
504 /* this array is in /proc/mdstat */
505 if (array.utime == 0)
506 /* external arrays don't update utime, so
507 * just make sure it is always different. */
508 array.utime = st->utime + 1;;
510 if (st->utime == array.utime &&
511 st->failed == array.failed_disks &&
512 st->working == array.working_disks &&
513 st->spare == array.spare_disks &&
515 mse->percent == st->percent
519 if ((st->active < st->raid) && st->spare == 0)
524 if (st->utime == 0 && /* new array */
525 mse->pattern && strchr(mse->pattern, '_') /* degraded */
527 alert("DegradedArray", dev, NULL, ainfo);
529 if (st->utime == 0 && /* new array */
530 st->expected_spares > 0 &&
531 array.spare_disks < st->expected_spares)
532 alert("SparesMissing", dev, NULL, ainfo);
533 if (st->percent == -1 &&
535 alert("RebuildStarted", dev, NULL, ainfo);
536 if (st->percent >= 0 &&
538 (mse->percent / increments) > (st->percent / increments)) {
539 char percentalert[15]; // "RebuildNN" (10 chars) or "RebuildStarted" (15 chars)
541 if((mse->percent / increments) == 0)
542 snprintf(percentalert, sizeof(percentalert), "RebuildStarted");
544 snprintf(percentalert, sizeof(percentalert), "Rebuild%02d", mse->percent);
546 alert(percentalert, dev, NULL, ainfo);
549 if (mse->percent == -1 &&
551 /* Rebuild/sync/whatever just finished.
552 * If there is a number in /mismatch_cnt,
553 * we should report that.
556 sysfs_read(-1, st->devnum, GET_MISMATCH);
557 if (sra && sra->mismatch_cnt > 0) {
559 sprintf(cnt, " mismatches found: %d", sra->mismatch_cnt);
560 alert("RebuildFinished", dev, cnt, ainfo);
562 alert("RebuildFinished", dev, NULL, ainfo);
566 st->percent = mse->percent;
568 for (i=0; i<MaxDisks && i <= array.raid_disks + array.nr_disks;
570 mdu_disk_info_t disc;
572 if (ioctl(fd, GET_DISK_INFO, &disc) >= 0) {
573 info[i].state = disc.state;
574 info[i].major = disc.major;
575 info[i].minor = disc.minor;
577 info[i].major = info[i].minor = 0;
580 if (mse->metadata_version &&
581 strncmp(mse->metadata_version, "external:", 9) == 0 &&
582 is_subarray(mse->metadata_version+9))
584 devname2devnum(mse->metadata_version+10);
586 st->parent_dev = NoMdDev;
587 if (st->metadata == NULL &&
588 st->parent_dev == NoMdDev)
589 st->metadata = super_by_fd(fd, NULL);
593 for (i=0; i<MaxDisks; i++) {
594 mdu_disk_info_t disc = {0,0,0,0,0};
599 if (i > array.raid_disks + array.nr_disks) {
601 disc.major = disc.minor = 0;
602 } else if (info[i].major || info[i].minor) {
603 newstate = info[i].state;
604 dv = map_dev(info[i].major, info[i].minor, 1);
605 disc.state = newstate;
606 disc.major = info[i].major;
607 disc.minor = info[i].minor;
608 } else if (mse && mse->pattern && i < (int)strlen(mse->pattern)) {
609 switch(mse->pattern[i]) {
610 case 'U': newstate = 6 /* ACTIVE/SYNC */; break;
611 case '_': newstate = 8 /* REMOVED */; break;
613 disc.major = disc.minor = 0;
615 if (dv == NULL && st->devid[i])
616 dv = map_dev(major(st->devid[i]),
617 minor(st->devid[i]), 1);
618 change = newstate ^ st->devstate[i];
619 if (st->utime && change && !st->err) {
620 if (i < array.raid_disks &&
621 (((newstate&change)&(1<<MD_DISK_FAULTY)) ||
622 ((st->devstate[i]&change)&(1<<MD_DISK_ACTIVE)) ||
623 ((st->devstate[i]&change)&(1<<MD_DISK_SYNC)))
625 alert("Fail", dev, dv, ainfo);
626 else if (i >= array.raid_disks &&
627 (disc.major || disc.minor) &&
628 st->devid[i] == makedev(disc.major, disc.minor) &&
629 ((newstate&change)&(1<<MD_DISK_FAULTY))
631 alert("FailSpare", dev, dv, ainfo);
632 else if (i < array.raid_disks &&
633 ! (newstate & (1<<MD_DISK_REMOVED)) &&
634 (((st->devstate[i]&change)&(1<<MD_DISK_FAULTY)) ||
635 ((newstate&change)&(1<<MD_DISK_ACTIVE)) ||
636 ((newstate&change)&(1<<MD_DISK_SYNC)))
638 alert("SpareActive", dev, dv, ainfo);
640 st->devstate[i] = newstate;
641 st->devid[i] = makedev(disc.major, disc.minor);
643 st->active = array.active_disks;
644 st->working = array.working_disks;
645 st->spare = array.spare_disks;
646 st->failed = array.failed_disks;
647 st->utime = array.utime;
648 st->raid = array.raid_disks;
650 if ((st->active < st->raid) && st->spare == 0)
655 static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
656 int test, struct alert_info *info)
658 struct mdstat_ent *mse;
661 for (mse=mdstat; mse; mse=mse->next)
662 if (mse->devnum != INT_MAX &&
663 (!mse->level || /* retrieve containers */
664 (strcmp(mse->level, "raid0") != 0 &&
665 strcmp(mse->level, "linear") != 0))
667 struct state *st = calloc(1, sizeof *st);
668 mdu_array_info_t array;
672 st->devname = strdup(get_md_name(mse->devnum));
673 if ((fd = open(st->devname, O_RDONLY)) < 0 ||
674 ioctl(fd, GET_ARRAY_INFO, &array)< 0) {
676 if (fd >=0) close(fd);
677 put_md_name(st->devname);
680 st->metadata->ss->free_super(st->metadata);
687 st->next = *statelist;
689 st->devnum = mse->devnum;
691 st->expected_spares = -1;
692 if (mse->metadata_version &&
693 strncmp(mse->metadata_version, "external:", 9) == 0 &&
694 is_subarray(mse->metadata_version+9))
696 devname2devnum(mse->metadata_version+10);
698 st->parent_dev = NoMdDev;
701 alert("TestMessage", st->devname, NULL, info);
702 alert("NewArray", st->devname, NULL, info);
708 static int get_min_spare_size_required(struct state *st, unsigned long long *sizep)
713 !st->metadata->ss->min_acceptable_spare_size) {
718 fd = open(st->devname, O_RDONLY);
721 if (st->metadata->ss->external)
722 st->metadata->ss->load_container(st->metadata, fd, st->devname);
724 st->metadata->ss->load_super(st->metadata, fd, st->devname);
726 if (!st->metadata->sb)
728 *sizep = st->metadata->ss->min_acceptable_spare_size(st->metadata);
729 st->metadata->ss->free_super(st->metadata);
734 static int check_donor(struct state *from, struct state *to)
741 /* Cannot move from a member */
745 for (sub = from->subarray; sub; sub = sub->subarray)
746 /* If source array has degraded subarrays, don't
749 if (sub->active < sub->raid)
751 if (from->metadata->ss->external == 0)
752 if (from->active < from->raid)
754 if (from->spare <= 0)
759 static dev_t choose_spare(struct state *from, struct state *to,
760 struct domainlist *domlist, unsigned long long min_size)
765 for (d = from->raid; !dev && d < MaxDisks; d++) {
766 if (from->devid[d] > 0 &&
767 from->devstate[d] == 0) {
768 struct dev_policy *pol;
769 unsigned long long dev_size;
771 if (to->metadata->ss->external &&
772 test_partition_from_id(from->devid[d]))
776 dev_size_from_id(from->devid[d], &dev_size) &&
780 pol = devnum_policy(from->devid[d]);
781 if (from->spare_group)
782 pol_add(&pol, pol_domain,
783 from->spare_group, NULL);
784 if (domain_test(domlist, pol, to->metadata->ss->name) == 1)
785 dev = from->devid[d];
786 dev_policy_free(pol);
792 static dev_t container_choose_spare(struct state *from, struct state *to,
793 struct domainlist *domlist,
794 unsigned long long min_size, int active)
796 /* This is similar to choose_spare, but we cannot trust devstate,
797 * so we need to read the metadata instead
800 struct supertype *st = from->metadata;
801 int fd = open(from->devname, O_RDONLY);
807 if (!st->ss->getinfo_super_disks) {
812 err = st->ss->load_container(st, fd, NULL);
818 /* We must check if number of active disks has not increased
819 * since ioctl in main loop. mdmon may have added spare
820 * to subarray. If so we do not need to look for more spares
821 * so return non zero value */
824 list = st->ss->getinfo_super_disks(st);
826 st->ss->free_super(st);
831 if (dp->disk.state & (1<<MD_DISK_SYNC) &&
832 !(dp->disk.state & (1<<MD_DISK_FAULTY)))
837 if (active < active_cnt) {
838 /* Spare just activated.*/
839 st->ss->free_super(st);
844 /* We only need one spare so full list not needed */
845 list = container_choose_spares(st, min_size, domlist, from->spare_group,
846 to->metadata->ss->name, 1);
848 struct mdinfo *disks = list->devs;
850 dev = makedev(disks->disk.major, disks->disk.minor);
853 st->ss->free_super(st);
858 static void try_spare_migration(struct state *statelist, struct alert_info *info)
863 link_containers_with_subarrays(statelist);
864 for (st = statelist; st; st = st->next)
865 if (st->active < st->raid &&
866 st->spare == 0 && !st->err) {
867 struct domainlist *domlist = NULL;
869 struct state *to = st;
870 unsigned long long min_size;
872 if (to->parent_dev != NoMdDev && !to->parent)
873 /* subarray monitored without parent container
874 * we can't move spares here */
878 /* member of a container */
881 if (get_min_spare_size_required(to, &min_size))
883 if (to->metadata->ss->external) {
884 /* We must make sure there is
885 * no suitable spare in container already.
886 * If there is we don't add more */
887 dev_t devid = container_choose_spare(
888 to, to, NULL, min_size, st->active);
892 for (d = 0; d < MaxDisks; d++)
894 domainlist_add_dev(&domlist,
896 to->metadata->ss->name);
898 domain_add(&domlist, to->spare_group);
900 * No spare migration if the destination
901 * has no domain. Skip this array.
905 for (from=statelist ; from ; from=from->next) {
907 if (!check_donor(from, to))
909 if (from->metadata->ss->external)
910 devid = container_choose_spare(
911 from, to, domlist, min_size, 0);
913 devid = choose_spare(from, to, domlist,
916 && move_spare(from->devname, to->devname, devid)) {
917 alert("MoveSpare", to->devname, from->devname, info);
921 domain_free(domlist);
925 /* search the statelist to connect external
926 * metadata subarrays with their containers
927 * We always completely rebuild the tree from scratch as
928 * that is safest considering the possibility of entries
929 * disappearing or changing.
931 static void link_containers_with_subarrays(struct state *list)
935 for (st = list; st; st = st->next) {
939 for (st = list; st; st = st->next)
940 if (st->parent_dev != NoMdDev)
941 for (cont = list; cont; cont = cont->next)
943 cont->parent_dev == NoMdDev &&
944 cont->devnum == st->parent_dev) {
946 st->subarray = cont->subarray;
952 /* Not really Monitor but ... */
959 if (stat(dev, &stb) != 0) {
960 fprintf(stderr, Name ": Cannot find %s: %s\n", dev,
964 devnum = stat2devnum(&stb);
967 struct mdstat_ent *ms = mdstat_read(1, 0);
968 struct mdstat_ent *e;
970 for (e=ms ; e; e=e->next)
971 if (e->devnum == devnum)
974 if (!e || e->percent < 0) {
975 if (e && e->metadata_version &&
976 strncmp(e->metadata_version, "external:", 9) == 0) {
977 if (is_subarray(&e->metadata_version[9]))
978 ping_monitor(&e->metadata_version[9]);
980 ping_monitor_by_id(devnum);
993 static char *clean_states[] = {
994 "clear", "inactive", "readonly", "read-auto", "clean", NULL };
996 int WaitClean(char *dev, int sock, int verbose)
1003 fd = open(dev, O_RDONLY);
1006 fprintf(stderr, Name ": Couldn't open %s: %s\n", dev, strerror(errno));
1010 devnum = fd2devnum(fd);
1011 mdi = sysfs_read(fd, devnum, GET_VERSION|GET_LEVEL|GET_SAFEMODE);
1014 fprintf(stderr, Name ": Failed to read sysfs attributes for "
1020 switch(mdi->array.level) {
1022 case LEVEL_MULTIPATH:
1024 /* safemode delay is irrelevant for these levels */
1028 /* for internal metadata the kernel handles the final clean
1029 * transition, containers can never be dirty
1031 if (!is_subarray(mdi->text_version))
1034 /* safemode disabled ? */
1035 if (mdi->safe_mode_delay == 0)
1039 int state_fd = sysfs_open(fd2devnum(fd), NULL, "array_state");
1044 /* minimize the safe_mode_delay and prepare to wait up to 5s
1045 * for writes to quiesce
1047 sysfs_set_safemode(mdi, 1);
1053 /* wait for array_state to be clean */
1055 rv = read(state_fd, buf, sizeof(buf));
1058 if (sysfs_match_word(buf, clean_states) <= 4)
1060 FD_SET(state_fd, &fds);
1061 rv = select(state_fd + 1, NULL, NULL, &fds, &tm);
1062 if (rv < 0 && errno != EINTR)
1064 lseek(state_fd, 0, SEEK_SET);
1068 else if (fping_monitor(sock) == 0 ||
1069 ping_monitor(mdi->text_version) == 0) {
1070 /* we need to ping to close the window between array
1071 * state transitioning to clean and the metadata being
1078 fprintf(stderr, Name ": Error waiting for %s to be clean\n",
1081 /* restore the original safe_mode_delay */
1082 sysfs_set_safemode(mdi, mdi->safe_mode_delay);
1091 #endif /* MDASSEMBLE */