2 * Incremental.c - support --incremental. Part of:
3 * mdadm - manage Linux "md" devices aka RAID arrays.
5 * Copyright (C) 2006-2013 Neil Brown <neilb@suse.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Email: <neilb@suse.de>
27 * QVB Post Office, NSW 1230
36 static int count_active(struct supertype
*st
, struct mdinfo
*sra
,
37 int mdfd
, char **availp
,
39 static void find_reject(int mdfd
, struct supertype
*st
, struct mdinfo
*sra
,
40 int number
, __u64 events
, int verbose
,
42 static int try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
43 struct map_ent
*target
,
44 struct supertype
*st
, int verbose
);
46 static int Incremental_container(struct supertype
*st
, char *devname
,
47 struct context
*c
, char *only
);
49 int Incremental(struct mddev_dev
*devlist
, struct context
*c
,
52 /* Add this device to an array, creating the array if necessary
53 * and starting the array if sensible or - if runstop>0 - if possible.
55 * This has several steps:
57 * 1/ Check if device is permitted by mdadm.conf, reject if not.
58 * 2/ Find metadata, reject if none appropriate (check
59 * version/name from args)
60 * 3/ Check if there is a match in mdadm.conf
61 * 3a/ if not, check for homehost match. If no match, assemble as
63 * 4/ Determine device number.
64 * - If in mdadm.conf with std name, use that
65 * - UUID in /var/run/mdadm.map use that
66 * - If name is suggestive, use that. unless in use with different uuid.
67 * - Choose a free, high number.
68 * - Use a partitioned device unless strong suggestion not to.
70 * Don't choose partitioned for containers.
71 * 5/ Find out if array already exists
73 * - choose a name, from mdadm.conf or 'name' field in array.
77 * - check one drive in array to make sure metadata is a reasonably
78 * close match. Reject if not (e.g. different type)
80 * 6/ Make sure /var/run/mdadm.map contains this array.
81 * 7/ Is there enough devices to possibly start the array?
82 * For a container, this means running Incremental_container.
83 * 7a/ if not, finish with success.
85 * - read all metadata and arrange devices like -A does
86 * - if number of OK devices match expected, or -R and there are enough,
87 * start the array (auto-readonly).
90 struct mdinfo info
, dinfo
;
91 struct mdinfo
*sra
= NULL
, *d
;
92 struct mddev_ident
*match
;
93 char chosen_name
[1024];
96 struct map_ent
*mp
, *map
= NULL
;
97 int dfd
= -1, mdfd
= -1;
102 mdu_array_info_t ainf
;
103 struct dev_policy
*policy
= NULL
;
104 struct map_ent target_array
;
106 char *devname
= devlist
->devname
;
107 int journal_device_missing
= 0;
109 struct createinfo
*ci
= conf_get_create_info();
111 if (stat(devname
, &stb
) < 0) {
113 pr_err("stat failed for %s: %s.\n",
114 devname
, strerror(errno
));
117 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
119 pr_err("%s is not a block device.\n",
123 dfd
= dev_open(devname
, O_RDONLY
);
126 pr_err("cannot open %s: %s.\n",
127 devname
, strerror(errno
));
130 /* If the device is a container, we do something very different */
131 if (must_be_container(dfd
)) {
133 st
= super_by_fd(dfd
, NULL
);
134 if (st
&& st
->ss
->load_container
)
135 rv
= st
->ss
->load_container(st
, dfd
, NULL
);
138 if (!rv
&& st
->ss
->container_content
) {
140 pr_err("failed to get exclusive lock on mapfile\n");
142 printf("MD_DEVNAME=%s\n", devname
);
143 rv
= Incremental_container(st
, devname
, c
, NULL
);
148 pr_err("%s is not part of an md array.\n",
153 /* 1/ Check if device is permitted by mdadm.conf */
155 for (;devlist
; devlist
= devlist
->next
)
156 if (conf_test_dev(devlist
->devname
))
159 devlist
= conf_get_devs();
160 for (;devlist
; devlist
= devlist
->next
) {
162 if (stat(devlist
->devname
, &st2
) == 0 &&
163 (st2
.st_mode
& S_IFMT
) == S_IFBLK
&&
164 st2
.st_rdev
== stb
.st_rdev
)
170 pr_err("%s not permitted by mdadm.conf.\n",
175 /* 2/ Find metadata, reject if none appropriate (check
176 * version/name from args) */
178 if (fstat(dfd
, &stb
) < 0) {
180 pr_err("fstat failed for %s: %s.\n",
181 devname
, strerror(errno
));
184 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
186 pr_err("%s is not a block device.\n",
191 dinfo
.disk
.major
= major(stb
.st_rdev
);
192 dinfo
.disk
.minor
= minor(stb
.st_rdev
);
194 policy
= disk_policy(&dinfo
);
195 have_target
= policy_check_path(&dinfo
, &target_array
);
197 if (st
== NULL
&& (st
= guess_super_type(dfd
, guess_array
)) == NULL
) {
199 pr_err("no recognisable superblock on %s.\n",
201 rv
= try_spare(devname
, &dfd
, policy
,
202 have_target
? &target_array
: NULL
,
206 st
->ignore_hw_compat
= 0;
208 if (st
->ss
->compare_super
== NULL
||
209 st
->ss
->load_super(st
, dfd
, c
->verbose
>= 0 ? devname
: NULL
)) {
211 pr_err("no RAID superblock on %s.\n",
213 rv
= try_spare(devname
, &dfd
, policy
,
214 have_target
? &target_array
: NULL
,
219 close (dfd
); dfd
= -1;
221 st
->ss
->getinfo_super(st
, &info
, NULL
);
223 /* 3/ Check if there is a match in mdadm.conf */
224 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
225 if (!match
&& rv
== 2)
228 if (match
&& match
->devname
229 && strcasecmp(match
->devname
, "<ignore>") == 0) {
231 pr_err("array containing %s is explicitly ignored by mdadm.conf\n",
236 /* 3a/ if not, check for homehost match. If no match, continue
237 * but don't trust the 'name' in the array. Thus a 'random' minor
238 * number will be assigned, and the device name will be based
242 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
244 else if (st
->ss
->match_home(st
, "any") == 1)
245 trustworthy
= LOCAL_ANY
;
247 trustworthy
= FOREIGN
;
249 if (!match
&& !conf_test_metadata(st
->ss
->name
, policy
,
250 (trustworthy
== LOCAL
))) {
252 pr_err("%s has metadata type %s for which auto-assembly is disabled\n",
253 devname
, st
->ss
->name
);
256 if (trustworthy
== LOCAL_ANY
)
259 /* There are three possible sources for 'autof': command line,
260 * ARRAY line in mdadm.conf, or CREATE line in mdadm.conf.
261 * ARRAY takes precedence, then command line, then
264 if (match
&& match
->autof
)
265 c
->autof
= match
->autof
;
267 c
->autof
= ci
->autof
;
269 name_to_use
= info
.name
;
270 if (name_to_use
[0] == 0 &&
271 info
.array
.level
== LEVEL_CONTAINER
) {
272 name_to_use
= info
.text_version
;
273 trustworthy
= METADATA
;
275 if (name_to_use
[0] && trustworthy
!= LOCAL
&&
276 ! c
->require_homehost
&&
277 conf_name_is_free(name_to_use
))
280 /* strip "hostname:" prefix from name if we have decided
281 * to treat it as LOCAL
283 if (trustworthy
== LOCAL
&& strchr(name_to_use
, ':') != NULL
)
284 name_to_use
= strchr(name_to_use
, ':')+1;
286 /* 4/ Check if array exists.
289 pr_err("failed to get exclusive lock on mapfile\n");
290 /* Now check we can get O_EXCL. If not, probably "mdadm -A" has
293 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
296 pr_err("cannot reopen %s: %s.\n",
297 devname
, strerror(errno
));
300 /* Cannot hold it open while we add the device to the array,
301 * so we must release the O_EXCL and depend on the map_lock()
302 * So now is the best time to remove any partitions.
304 remove_partitions(dfd
);
308 mp
= map_by_uuid(&map
, info
.uuid
);
310 mdfd
= open_dev(mp
->devnm
);
316 /* Skip the clustered ones. This should be started by
317 * clustering resource agents
319 if (info
.array
.state
& (1 << MD_SB_CLUSTERED
))
322 /* Couldn't find an existing array, maybe make a new one */
323 mdfd
= create_mddev(match
? match
->devname
: NULL
,
324 name_to_use
, c
->autof
, trustworthy
, chosen_name
);
329 sysfs_init(&info
, mdfd
, NULL
);
331 if (set_array_info(mdfd
, st
, &info
) != 0) {
332 pr_err("failed to set array info for %s: %s\n",
333 chosen_name
, strerror(errno
));
339 dinfo
.disk
.major
= major(stb
.st_rdev
);
340 dinfo
.disk
.minor
= minor(stb
.st_rdev
);
341 if (add_disk(mdfd
, st
, &info
, &dinfo
) != 0) {
342 pr_err("failed to add %s to new array %s: %s.\n",
343 devname
, chosen_name
, strerror(errno
));
344 ioctl(mdfd
, STOP_ARRAY
, 0);
348 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
349 GET_OFFSET
| GET_SIZE
));
351 if (!sra
|| !sra
->devs
|| sra
->devs
->disk
.raid_disk
>= 0) {
352 /* It really should be 'none' - must be old buggy
353 * kernel, and mdadm -I may not be able to complete.
356 ioctl(mdfd
, STOP_ARRAY
, NULL
);
357 pr_err("You have an old buggy kernel which cannot support\n --incremental reliably. Aborting.\n");
361 info
.array
.working_disks
= 1;
362 /* 6/ Make sure /var/run/mdadm.map contains this array. */
363 map_update(&map
, fd2devnm(mdfd
),
365 info
.uuid
, chosen_name
);
368 /* - check one drive in array to make sure metadata is a reasonably */
369 /* close match. Reject if not (e.g. different type) */
370 /* - add the device */
374 struct supertype
*st2
;
375 struct mdinfo info2
, *d
;
377 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
378 GET_OFFSET
| GET_SIZE
));
381 strcpy(chosen_name
, mp
->path
);
383 strcpy(chosen_name
, mp
->devnm
);
385 /* It is generally not OK to add non-spare drives to a
386 * running array as they are probably missing because
387 * they failed. However if runstop is 1, then the
388 * array was possibly started early and our best bet is
389 * to add this anyway.
390 * Also if action policy is re-add or better we allow
392 * This doesn't apply to containers as the 'non-spare'
393 * flag has a different meaning. The test has to happen
394 * at the device level there
396 if (!st
->ss
->external
397 && (info
.disk
.state
& (1<<MD_DISK_SYNC
)) != 0
398 && ! policy_action_allows(policy
, st
->ss
->name
,
401 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ainf
) == 0) {
402 pr_err("not adding %s to active array (without --run) %s\n",
403 devname
, chosen_name
);
413 sprintf(dn
, "%d:%d", sra
->devs
->disk
.major
,
414 sra
->devs
->disk
.minor
);
415 dfd2
= dev_open(dn
, O_RDONLY
);
417 pr_err("unable to open %s\n", devname
);
422 if (st2
->ss
->load_super(st2
, dfd2
, NULL
) ||
423 st
->ss
->compare_super(st
, st2
) != 0) {
424 pr_err("metadata mismatch between %s and chosen array %s\n",
425 devname
, chosen_name
);
431 st2
->ss
->getinfo_super(st2
, &info2
, NULL
);
432 st2
->ss
->free_super(st2
);
433 if (info
.array
.level
!= info2
.array
.level
||
434 memcmp(info
.uuid
, info2
.uuid
, 16) != 0 ||
435 info
.array
.raid_disks
!= info2
.array
.raid_disks
) {
436 pr_err("unexpected difference between %s and %s.\n",
437 chosen_name
, devname
);
442 info
.disk
.major
= major(stb
.st_rdev
);
443 info
.disk
.minor
= minor(stb
.st_rdev
);
444 /* add disk needs to know about containers */
445 if (st
->ss
->external
)
446 sra
->array
.level
= LEVEL_CONTAINER
;
447 err
= add_disk(mdfd
, st
, sra
, &info
);
448 if (err
< 0 && errno
== EBUSY
) {
449 /* could be another device present with the same
450 * disk.number. Find and reject any such
452 find_reject(mdfd
, st
, sra
, info
.disk
.number
,
453 info
.events
, c
->verbose
, chosen_name
);
454 err
= add_disk(mdfd
, st
, sra
, &info
);
456 if (err
< 0 && errno
== EINVAL
&&
457 info
.disk
.state
& (1<<MD_DISK_SYNC
)) {
458 /* Maybe it needs to be added as a spare */
459 if (policy_action_allows(policy
, st
->ss
->name
,
461 info
.disk
.state
&= ~(1<<MD_DISK_SYNC
);
462 err
= add_disk(mdfd
, st
, sra
, &info
);
465 pr_err("can only add %s to %s as a spare, and force-spare is not set.\n",
466 devname
, chosen_name
);
469 pr_err("failed to add %s to existing array %s: %s.\n",
470 devname
, chosen_name
, strerror(errno
));
474 info
.array
.working_disks
= 0;
475 for (d
= sra
->devs
; d
; d
=d
->next
)
476 info
.array
.working_disks
++;
479 if (strncmp(chosen_name
, "/dev/md/", 8) == 0)
480 md_devname
= chosen_name
+8;
482 md_devname
= chosen_name
;
484 printf("MD_DEVICE=%s\n", fd2devnm(mdfd
));
485 printf("MD_DEVNAME=%s\n", md_devname
);
486 printf("MD_FOREIGN=%s\n", trustworthy
== FOREIGN
? "yes" : "no");
489 /* 7/ Is there enough devices to possibly start the array? */
490 /* 7a/ if not, finish with success. */
491 if (info
.array
.level
== LEVEL_CONTAINER
) {
493 /* Try to assemble within the container */
494 sysfs_uevent(sra
, "change");
495 if (!c
->export
&& c
->verbose
>= 0)
496 pr_err("container %s now has %d device%s\n",
497 chosen_name
, info
.array
.working_disks
,
498 info
.array
.working_disks
== 1?"":"s");
499 wait_for(chosen_name
, mdfd
);
500 if (st
->ss
->external
)
501 strcpy(devnm
, fd2devnm(mdfd
));
502 if (st
->ss
->load_container
)
503 rv
= st
->ss
->load_container(st
, mdfd
, NULL
);
507 rv
= Incremental_container(st
, chosen_name
, c
, NULL
);
509 /* after spare is added, ping monitor for external metadata
510 * so that it can eg. try to rebuild degraded array */
511 if (st
->ss
->external
)
516 /* We have added something to the array, so need to re-read the
517 * state. Eventually this state should be kept up-to-date as
521 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
522 GET_OFFSET
| GET_SIZE
));
523 active_disks
= count_active(st
, sra
, mdfd
, &avail
, &info
);
525 journal_device_missing
= (info
.journal_device_required
) && (info
.journal_clean
== 0);
527 if (enough(info
.array
.level
, info
.array
.raid_disks
,
528 info
.array
.layout
, info
.array
.state
& 1,
531 printf("MD_STARTED=no\n");
532 } else if (c
->verbose
>= 0)
533 pr_err("%s attached to %s, not enough to start (%d).\n",
534 devname
, chosen_name
, active_disks
);
540 /* - if number of OK devices match expected, or -R and there */
542 /* + add any bitmap file */
543 /* + start the array (auto-readonly). */
545 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ainf
) == 0) {
547 printf("MD_STARTED=already\n");
548 } else if (c
->verbose
>= 0)
549 pr_err("%s attached to %s which is already active.\n",
550 devname
, chosen_name
);
556 if (c
->runstop
> 0 || (!journal_device_missing
&& active_disks
>= info
.array
.working_disks
)) {
558 /* Let's try to start it */
560 if (journal_device_missing
)
561 pr_err("Trying to run with missing journal device\n");
562 if (info
.reshape_active
&& !(info
.reshape_active
& RESHAPE_NO_BACKUP
)) {
563 pr_err("%s: This array is being reshaped and cannot be started\n",
565 cont_err("by --incremental. Please use --assemble\n");
568 if (match
&& match
->bitmap_file
) {
569 int bmfd
= open(match
->bitmap_file
, O_RDWR
);
571 pr_err("Could not open bitmap file %s.\n",
575 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
577 pr_err("Failed to set bitmapfile for %s.\n",
583 /* Need to remove from the array any devices which
584 * 'count_active' discerned were too old or inappropriate
586 for (d
= sra
? sra
->devs
: NULL
; d
; d
= d
->next
)
587 if (d
->disk
.state
& (1<<MD_DISK_REMOVED
))
588 remove_disk(mdfd
, st
, sra
, d
);
590 if ((sra
== NULL
|| active_disks
>= info
.array
.working_disks
)
591 && trustworthy
!= FOREIGN
)
592 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
594 rv
= sysfs_set_str(sra
, NULL
,
595 "array_state", "read-auto");
596 /* Array might be O_EXCL which will interfere with
597 * fsck and mount. So re-open without O_EXCL.
602 printf("MD_STARTED=yes\n");
603 } else if (c
->verbose
>= 0)
604 pr_err("%s attached to %s, which has been started.\n",
605 devname
, chosen_name
);
607 wait_for(chosen_name
, mdfd
);
608 /* We just started the array, so some devices
609 * might have been evicted from the array
610 * because their event counts were too old.
611 * If the action=re-add policy is in-force for
612 * those devices we should re-add them now.
614 for (dsk
= sra
->devs
; dsk
; dsk
= dsk
->next
) {
615 if (disk_action_allows(dsk
, st
->ss
->name
, act_re_add
) &&
616 add_disk(mdfd
, st
, sra
, dsk
) == 0)
617 pr_err("%s re-added to %s\n",
618 dsk
->sys_name
, chosen_name
);
621 pr_err("%s attached to %s, but failed to start: %s.\n",
622 devname
, chosen_name
, strerror(errno
));
627 printf("MD_STARTED=unsafe\n");
628 } else if (journal_device_missing
) {
629 pr_err("Journal device is missing, not safe to start yet.\n");
630 } else if (c
->verbose
>= 0)
631 pr_err("%s attached to %s, not enough to start safely.\n",
632 devname
, chosen_name
);
642 dev_policy_free(policy
);
651 static void find_reject(int mdfd
, struct supertype
*st
, struct mdinfo
*sra
,
652 int number
, __u64 events
, int verbose
,
655 /* Find a device attached to this array with a disk.number of number
656 * and events less than the passed events, and remove the device.
661 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ra
) == 0)
662 return; /* not safe to remove from active arrays
663 * without thinking more */
665 for (d
= sra
->devs
; d
; d
= d
->next
) {
669 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
670 dfd
= dev_open(dn
, O_RDONLY
);
673 if (st
->ss
->load_super(st
, dfd
, NULL
)) {
677 st
->ss
->getinfo_super(st
, &info
, NULL
);
678 st
->ss
->free_super(st
);
681 if (info
.disk
.number
!= number
||
682 info
.events
>= events
)
685 if (d
->disk
.raid_disk
> -1)
686 sysfs_set_str(sra
, d
, "slot", "none");
687 if (sysfs_set_str(sra
, d
, "state", "remove") == 0)
689 pr_err("removing old device %s from %s\n",
690 d
->sys_name
+4, array_name
);
694 static int count_active(struct supertype
*st
, struct mdinfo
*sra
,
695 int mdfd
, char **availp
,
696 struct mdinfo
*bestinfo
)
698 /* count how many devices in sra think they are active */
702 __u64 max_events
= 0;
714 for (d
= sra
->devs
; d
; d
= d
->next
)
716 for (d
= sra
->devs
, devnum
= 0 ; d
; d
= d
->next
, devnum
++) {
722 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
723 dfd
= dev_open(dn
, O_RDONLY
);
726 ok
= st
->ss
->load_super(st
, dfd
, NULL
);
731 info
.array
.raid_disks
= raid_disks
;
732 st
->ss
->getinfo_super(st
, &info
, devmap
+ raid_disks
* devnum
);
733 if (info
.disk
.raid_disk
== MD_DISK_ROLE_JOURNAL
)
734 bestinfo
->journal_clean
= 1;
736 raid_disks
= info
.array
.raid_disks
;
737 avail
= xcalloc(raid_disks
, 1);
740 best
= xcalloc(raid_disks
, sizeof(int));
741 devmap
= xcalloc(raid_disks
, numdevs
);
743 st
->ss
->getinfo_super(st
, &info
, devmap
);
746 if (info
.disk
.state
& (1<<MD_DISK_SYNC
))
750 max_events
= info
.events
;
751 avail
[info
.disk
.raid_disk
] = 2;
752 best
[info
.disk
.raid_disk
] = devnum
;
753 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
754 } else if (info
.events
== max_events
) {
755 avail
[info
.disk
.raid_disk
] = 2;
756 best
[info
.disk
.raid_disk
] = devnum
;
757 } else if (info
.events
== max_events
-1) {
758 if (avail
[info
.disk
.raid_disk
] == 0) {
759 avail
[info
.disk
.raid_disk
] = 1;
760 best
[info
.disk
.raid_disk
] = devnum
;
762 } else if (info
.events
< max_events
- 1)
764 else if (info
.events
== max_events
+1) {
766 max_events
= info
.events
;
767 for (i
= 0; i
< raid_disks
; i
++)
770 avail
[info
.disk
.raid_disk
] = 2;
771 best
[info
.disk
.raid_disk
] = devnum
;
772 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
773 } else { /* info.events much bigger */
774 memset(avail
, 0, raid_disks
);
775 max_events
= info
.events
;
776 avail
[info
.disk
.raid_disk
] = 2;
777 best
[info
.disk
.raid_disk
] = devnum
;
778 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
780 } else if (info
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
782 st
->ss
->free_super(st
);
787 /* We need to reject any device that thinks the best device is
788 * failed or missing */
789 for (b
= 0; b
< raid_disks
; b
++)
793 for (i
= 0 ; i
< raid_disks
; i
++) {
794 if (i
!= b
&& avail
[i
])
795 if (devmap
[raid_disks
* best
[i
] + b
] == 0) {
796 /* This device thinks 'b' is failed -
799 for (d
=sra
->devs
; devnum
; d
= d
->next
)
801 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
807 /* Also need to reject any spare device with an event count that
810 for (d
= sra
->devs
; d
; d
= d
->next
) {
811 if (!(d
->disk
.state
& (1<<MD_DISK_SYNC
)) &&
812 d
->events
> max_events
)
813 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
817 return cnt
+ replcnt
;
820 /* test if container has degraded member(s) */
821 static int container_members_max_degradation(struct map_ent
*map
, struct map_ent
*me
)
823 mdu_array_info_t array
;
825 int max_degraded
= 0;
827 for(; map
; map
= map
->next
) {
828 if (!metadata_container_matches(map
->metadata
, me
->devnm
))
830 afd
= open_dev(map
->devnm
);
833 /* most accurate information regarding array degradation */
834 if (ioctl(afd
, GET_ARRAY_INFO
, &array
) >= 0) {
835 int degraded
= array
.raid_disks
- array
.active_disks
-
837 if (degraded
> max_degraded
)
838 max_degraded
= degraded
;
842 return (max_degraded
);
845 static int array_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
846 struct map_ent
*target
, int bare
,
847 struct supertype
*st
, int verbose
)
849 /* This device doesn't have any md metadata
850 * The device policy allows 'spare' and if !bare, it allows spare-same-slot.
851 * If 'st' is not set, then we only know that some metadata allows this,
852 * others possibly don't.
853 * So look for a container or array to attach the device to.
854 * Prefer 'target' if that is set and the array is found.
856 * If st is set, then only arrays of that type are considered
857 * Return 0 on success, or some exit code on failure, probably 1.
861 struct map_ent
*mp
, *map
= NULL
;
862 struct mdinfo
*chosen
= NULL
;
865 if (fstat(dfd
, &stb
) != 0)
869 * Now we need to find a suitable array to add this to.
870 * We only accept arrays that:
872 * - are in the same domains as the device
873 * - are of an size for which the device will be useful
874 * and we choose the one that is the most degraded
877 if (map_lock(&map
)) {
878 pr_err("failed to get exclusive lock on mapfile\n");
881 for (mp
= map
; mp
; mp
= mp
->next
) {
882 struct supertype
*st2
;
883 struct domainlist
*dl
= NULL
;
885 unsigned long long devsize
;
886 unsigned long long component_size
= 0;
888 if (is_subarray(mp
->metadata
))
891 st2
= st
->ss
->match_metadata_desc(mp
->metadata
);
893 (st
->minor_version
>= 0 &&
894 st
->minor_version
!= st2
->minor_version
)) {
896 pr_err("not adding %s to %s as metadata type doesn't match\n",
903 sra
= sysfs_read(-1, mp
->devnm
,
904 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
905 GET_DEGRADED
|GET_COMPONENT
|GET_VERSION
);
907 /* Probably a container - no degraded info */
908 sra
= sysfs_read(-1, mp
->devnm
,
909 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
910 GET_COMPONENT
|GET_VERSION
);
912 sra
->array
.failed_disks
= -1;
919 for(i
= 0; !st2
&& superlist
[i
]; i
++)
920 st2
= superlist
[i
]->match_metadata_desc(
924 pr_err("not adding %s to %s as metadata not recognised.\n",
928 /* Need to double check the 'act_spare' permissions applies
931 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
933 if (!bare
&& !policy_action_allows(pol
, st2
->ss
->name
,
934 act_spare_same_slot
))
938 /* update number of failed disks for mostly degraded
939 * container member */
940 if (sra
->array
.failed_disks
== -1)
941 sra
->array
.failed_disks
= container_members_max_degradation(map
, mp
);
943 get_dev_size(dfd
, NULL
, &devsize
);
944 if (sra
->component_size
== 0) {
945 /* true for containers, here we must read superblock
946 * to obtain minimum spare size */
947 struct supertype
*st3
= dup_super(st2
);
948 int mdfd
= open_dev(mp
->devnm
);
953 if (st3
->ss
->load_container
&&
954 !st3
->ss
->load_container(st3
, mdfd
, mp
->path
)) {
955 component_size
= st3
->ss
->min_acceptable_spare_size(st3
);
956 st3
->ss
->free_super(st3
);
961 if ((sra
->component_size
> 0 &&
962 st2
->ss
->avail_size(st2
, devsize
,
964 ? sra
->devs
->data_offset
966 < sra
->component_size
)
968 (sra
->component_size
== 0 && devsize
< component_size
)) {
970 pr_err("not adding %s to %s as it is too small\n",
974 /* test against target.
975 * If 'target' is set and 'bare' is false, we only accept
976 * arrays/containers that match 'target'.
977 * If 'target' is set and 'bare' is true, we prefer the
978 * array which matches 'target'.
979 * target is considered only if we deal with degraded array
981 if (target
&& policy_action_allows(pol
, st2
->ss
->name
,
982 act_spare_same_slot
)) {
983 if (strcmp(target
->metadata
, mp
->metadata
) == 0 &&
984 memcmp(target
->uuid
, mp
->uuid
,
985 sizeof(target
->uuid
)) == 0 &&
986 sra
->array
.failed_disks
> 0) {
987 /* This is our target!! */
992 /* skip to end so we don't check any more */
1002 dl
= domain_from_array(sra
, st2
->ss
->name
);
1003 if (domain_test(dl
, pol
, st2
->ss
->name
) != 1) {
1004 /* domain test fails */
1006 pr_err("not adding %s to %s as it is not in a compatible domain\n",
1011 /* all tests passed, OK to add to this array */
1015 } else if (chosen
->array
.failed_disks
< sra
->array
.failed_disks
) {
1029 /* add current device to chosen array as a spare */
1030 int mdfd
= open_dev(chosen
->sys_name
);
1032 struct mddev_dev devlist
;
1034 devlist
.next
= NULL
;
1036 devlist
.writemostly
= 0;
1037 devlist
.devname
= devname
;
1038 sprintf(devname
, "%d:%d", major(stb
.st_rdev
),
1039 minor(stb
.st_rdev
));
1040 devlist
.disposition
= 'a';
1043 rv
= Manage_subdevs(chosen
->sys_name
, mdfd
, &devlist
,
1049 pr_err("added %s as spare for %s\n",
1050 devname
, chosen
->sys_name
);
1052 pr_err("failed to add %s as spare for %s\n",
1053 devname
, chosen
->sys_name
);
1061 static int partition_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1062 struct supertype
*st
, int verbose
)
1064 /* we know that at least one partition virtual-metadata is
1065 * allowed to incorporate spares like this device. We need to
1066 * find a suitable device to copy partition information from.
1068 * Getting a list of all disk (not partition) devices is
1069 * slightly non-trivial. We could look at /sys/block, but
1070 * that is theoretically due to be removed. Maybe best to use
1071 * /dev/disk/by-path/?* and ignore names ending '-partNN' as
1072 * we depend on this directory of 'path' info. But that fails
1073 * to find loop devices and probably others. Maybe don't
1074 * worry about that, they aren't the real target.
1076 * So: check things in /dev/disk/by-path to see if they are in
1077 * a compatible domain, then load the partition table and see
1078 * if it is OK for the new device, and choose the largest
1079 * partition table that fits.
1083 char *chosen
= NULL
;
1084 unsigned long long chosen_size
= 0;
1085 struct supertype
*chosen_st
= NULL
;
1088 dir
= opendir("/dev/disk/by-path");
1091 while ((de
= readdir(dir
)) != NULL
) {
1093 struct dev_policy
*pol2
= NULL
;
1094 struct domainlist
*domlist
= NULL
;
1097 struct supertype
*st2
= NULL
;
1098 char *devname
= NULL
;
1099 unsigned long long devsectors
;
1101 if (de
->d_ino
== 0 ||
1102 de
->d_name
[0] == '.' ||
1103 (de
->d_type
!= DT_LNK
&& de
->d_type
!= DT_UNKNOWN
))
1106 ep
= de
->d_name
+ strlen(de
->d_name
);
1107 while (ep
> de
->d_name
&&
1110 if (ep
> de
->d_name
+ 5 &&
1111 strncmp(ep
-5, "-part", 5) == 0)
1112 /* This is a partition - skip it */
1115 pol2
= path_policy(de
->d_name
, type_disk
);
1117 domain_merge(&domlist
, pol2
, st
? st
->ss
->name
: NULL
);
1118 if (domain_test(domlist
, pol
, st
? st
->ss
->name
: NULL
) != 1)
1119 /* new device is incompatible with this device. */
1122 domain_free(domlist
);
1125 if (asprintf(&devname
, "/dev/disk/by-path/%s", de
->d_name
) != 1) {
1129 fd
= open(devname
, O_RDONLY
);
1132 if (get_dev_size(fd
, devname
, &devsectors
) == 0)
1137 st2
= dup_super(st
);
1139 st2
= guess_super_type(fd
, guess_partitions
);
1141 st2
->ss
->load_super(st2
, fd
, NULL
) < 0)
1143 st2
->ignore_hw_compat
= 0;
1146 /* Check domain policy again, this time referring to metadata */
1147 domain_merge(&domlist
, pol2
, st2
->ss
->name
);
1148 if (domain_test(domlist
, pol
, st2
->ss
->name
) != 1)
1149 /* Incompatible devices for this metadata type */
1151 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
1152 /* Some partition types allow sparing, but not
1158 st2
->ss
->getinfo_super(st2
, &info
, NULL
);
1159 if (info
.component_size
> devsectors
)
1160 /* This partitioning doesn't fit in the device */
1163 /* This is an acceptable device to copy partition
1164 * metadata from. We could just stop here, but I
1165 * think I want to keep looking incase a larger
1166 * metadata which makes better use of the device can
1169 if (chosen
== NULL
||
1170 chosen_size
< info
.component_size
) {
1171 chosen_size
= info
.component_size
;
1176 chosen_st
->ss
->free_super(chosen_st
);
1185 domain_free(domlist
);
1186 dev_policy_free(pol2
);
1188 st2
->ss
->free_super(st2
);
1200 /* 'chosen' is the best device we can find. Let's write its
1201 * metadata to devname dfd is read-only so don't use that
1203 fd
= open(devname
, O_RDWR
);
1205 chosen_st
->ss
->store_super(chosen_st
, fd
);
1209 chosen_st
->ss
->free_super(chosen_st
);
1214 static int is_bare(int dfd
)
1216 unsigned long long size
= 0;
1217 char bufpad
[4096 + 4096];
1218 char *buf
= (char*)(((long)bufpad
+ 4096) & ~4095);
1220 if (lseek(dfd
, 0, SEEK_SET
) != 0 ||
1221 read(dfd
, buf
, 4096) != 4096)
1224 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1226 if (memcmp(buf
, buf
+1, 4095) != 0)
1229 /* OK, first 4K appear blank, try the end. */
1230 get_dev_size(dfd
, NULL
, &size
);
1231 if (lseek(dfd
, size
-4096, SEEK_SET
) < 0 ||
1232 read(dfd
, buf
, 4096) != 4096)
1235 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1237 if (memcmp(buf
, buf
+1, 4095) != 0)
1243 /* adding a spare to a regular array is quite different from adding one to
1244 * a set-of-partitions virtual array.
1245 * This function determines which is worth trying and tries as appropriate.
1246 * Arrays are given priority over partitions.
1248 static int try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1249 struct map_ent
*target
,
1250 struct supertype
*st
, int verbose
)
1255 int partitions_ok
= 0;
1259 /* Can only add a spare if device has at least one domain */
1260 if (pol_find(pol
, pol_domain
) == NULL
)
1262 /* And only if some action allows spares */
1263 if (!policy_action_allows(pol
, st
?st
->ss
->name
:NULL
, act_spare
))
1266 /* Now check if the device is bare.
1267 * bare devices can always be added as a spare
1268 * non-bare devices can only be added if spare-same-slot is permitted,
1269 * and this device is replacing a previous device - in which case 'target'
1272 if (!is_bare(dfd
)) {
1273 /* Must have a target and allow same_slot */
1274 /* Later - may allow force_spare without target */
1276 !policy_action_allows(pol
, st
?st
->ss
->name
:NULL
,
1277 act_spare_same_slot
)) {
1279 pr_err("%s is not bare, so not considering as a spare\n",
1287 /* It might be OK to add this device to an array - need to see
1288 * what arrays might be candidates.
1291 /* just try try 'array' or 'partition' based on this metadata */
1292 if (st
->ss
->add_to_super
)
1293 return array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1296 return partition_try_spare(devname
, dfdp
, pol
,
1299 /* No metadata was specified or found so options are open.
1300 * Check for whether any array metadata, or any partition metadata
1301 * might allow adding the spare. This check is just help to avoid
1302 * a more costly scan of all arrays when we can be sure that will
1305 for (i
= 0; (!arrays_ok
|| !partitions_ok
) && superlist
[i
] ; i
++) {
1306 if (superlist
[i
]->add_to_super
&& !arrays_ok
&&
1307 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1309 if (superlist
[i
]->add_to_super
== NULL
&& !partitions_ok
&&
1310 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1315 rv
= array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1317 if (rv
!= 0 && partitions_ok
)
1318 rv
= partition_try_spare(devname
, dfdp
, pol
, st
, verbose
);
1322 int IncrementalScan(struct context
*c
, char *devnm
)
1324 /* look at every device listed in the 'map' file.
1325 * If one is found that is not running then:
1326 * look in mdadm.conf for bitmap file.
1327 * if one exists, but array has none, add it.
1328 * try to start array in auto-readonly mode
1330 struct map_ent
*mapl
= NULL
;
1332 struct mddev_ident
*devs
, *mddev
;
1338 devs
= conf_get_ident(NULL
);
1341 for (me
= mapl
; me
; me
= me
->next
) {
1342 mdu_array_info_t array
;
1343 mdu_bitmap_file_t bmf
;
1347 if (devnm
&& strcmp(devnm
, me
->devnm
) != 0)
1349 if (devnm
&& me
->metadata
[0] == '/') {
1351 /* member array, need to work on container */
1352 strncpy(container
, me
->metadata
+1, 32);
1354 sl
= strchr(container
, '/');
1361 mdfd
= open_dev(me
->devnm
);
1365 if (!isdigit(me
->metadata
[0])) {
1366 /* must be a container */
1367 struct supertype
*st
= super_by_fd(mdfd
, NULL
);
1369 struct map_ent
*map
= NULL
;
1371 if (st
&& st
->ss
->load_container
)
1372 ret
= st
->ss
->load_container(st
, mdfd
, NULL
);
1374 if (!ret
&& st
&& st
->ss
->container_content
) {
1376 pr_err("failed to get exclusive lock on mapfile\n");
1377 ret
= Incremental_container(st
, me
->path
, c
, only
);
1384 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
) == 0 ||
1389 /* Ok, we can try this one. Maybe it needs a bitmap */
1390 for (mddev
= devs
; mddev
; mddev
= mddev
->next
)
1391 if (mddev
->devname
&& me
->path
1392 && devname_matches(mddev
->devname
, me
->path
))
1394 if (mddev
&& mddev
->bitmap_file
) {
1396 * Note: early kernels will wrongly fail this, so it
1400 if (ioctl(mdfd
, GET_ARRAY_INFO
, &bmf
) < 0) {
1401 int bmfd
= open(mddev
->bitmap_file
, O_RDWR
);
1403 added
= ioctl(mdfd
, SET_BITMAP_FILE
,
1408 if (c
->verbose
>= 0) {
1410 pr_err("Added bitmap %s to %s\n",
1411 mddev
->bitmap_file
, me
->path
);
1412 else if (errno
!= EEXIST
)
1413 pr_err("Failed to add bitmap to %s: %s\n",
1414 me
->path
, strerror(errno
));
1417 /* FIXME check for reshape_active and consider not
1420 sra
= sysfs_read(mdfd
, NULL
, 0);
1422 if (sysfs_set_str(sra
, NULL
,
1423 "array_state", "read-auto") == 0) {
1424 if (c
->verbose
>= 0)
1425 pr_err("started array %s\n",
1426 me
->path
?: me
->devnm
);
1428 pr_err("failed to start array %s: %s\n",
1429 me
->path
?: me
->devnm
,
1439 static char *container2devname(char *devname
)
1441 char *mdname
= NULL
;
1443 if (devname
[0] == '/') {
1444 int fd
= open(devname
, O_RDONLY
);
1446 mdname
= xstrdup(fd2devnm(fd
));
1451 struct map_ent
*mp
, *map
= NULL
;
1453 if (!parse_uuid(devname
, uuid
))
1455 mp
= map_by_uuid(&map
, uuid
);
1457 mdname
= xstrdup(mp
->devnm
);
1464 static int Incremental_container(struct supertype
*st
, char *devname
,
1465 struct context
*c
, char *only
)
1467 /* Collect the contents of this container and for each
1468 * array, choose a device name and assemble the array.
1471 struct mdinfo
*list
;
1473 struct map_ent
*map
= NULL
;
1476 struct mddev_ident
*match
;
1478 struct domainlist
*domains
;
1479 struct map_ent
*smp
;
1486 st
->ss
->getinfo_super(st
, &info
, NULL
);
1488 if ((c
->runstop
> 0 && info
.container_enough
>= 0) ||
1489 info
.container_enough
> 0)
1493 printf("MD_STARTED=no\n");
1494 } else if (c
->verbose
)
1495 pr_err("not enough devices to start the container\n");
1499 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
1500 if (match
== NULL
&& rv
== 2)
1503 /* Need to compute 'trustworthy' */
1505 trustworthy
= LOCAL
;
1506 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
1507 trustworthy
= LOCAL
;
1508 else if (st
->ss
->match_home(st
, "any") == 1)
1509 trustworthy
= LOCAL
;
1511 trustworthy
= FOREIGN
;
1513 list
= st
->ss
->container_content(st
, NULL
);
1514 /* when nothing to activate - quit */
1517 printf("MD_STARTED=nothing\n");
1521 for (ra
= list
; ra
; ra
= ra
->next
) {
1523 char chosen_name
[1024];
1525 struct mddev_ident
*match
= NULL
;
1528 /* do not activate arrays blocked by metadata handler */
1529 if (ra
->array
.state
& (1 << MD_SB_BLOCK_VOLUME
)) {
1530 pr_err("Cannot activate array %s in %s.\n",
1531 ra
->text_version
, devname
);
1535 mp
= map_by_uuid(&map
, ra
->uuid
);
1538 mdfd
= open_dev(mp
->devnm
);
1540 strcpy(chosen_name
, mp
->path
);
1542 strcpy(chosen_name
, mp
->devnm
);
1545 /* Check in mdadm.conf for container == devname and
1546 * member == ra->text_version after second slash.
1548 char *sub
= strchr(ra
->text_version
+1, '/');
1549 struct mddev_ident
*array_list
;
1552 array_list
= conf_get_ident(NULL
);
1555 for(; array_list
; array_list
= array_list
->next
) {
1557 if (array_list
->member
== NULL
||
1558 array_list
->container
== NULL
)
1560 if (strcmp(array_list
->member
, sub
) != 0)
1562 if (array_list
->uuid_set
&&
1563 !same_uuid(ra
->uuid
, array_list
->uuid
, st
->ss
->swapuuid
))
1565 dn
= container2devname(array_list
->container
);
1568 if (strncmp(dn
, ra
->text_version
+1,
1570 ra
->text_version
[strlen(dn
)+1] != '/') {
1575 /* we have a match */
1578 pr_err("match found for member %s\n",
1579 array_list
->member
);
1583 if (match
&& match
->devname
&&
1584 strcasecmp(match
->devname
, "<ignore>") == 0) {
1586 pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
1587 match
->container
, match
->member
);
1591 trustworthy
= LOCAL
;
1593 mdfd
= create_mddev(match
? match
->devname
: NULL
,
1599 if (only
&& (!mp
|| strcmp(mp
->devnm
, only
) != 0))
1603 pr_err("failed to open %s: %s.\n",
1604 chosen_name
, strerror(errno
));
1608 assemble_container_content(st
, mdfd
, ra
, c
,
1609 chosen_name
, &result
);
1612 if (c
->export
&& result
) {
1614 printf("MD_STARTED");
1615 if (result
& INCR_NO
) {
1616 printf("%cno", sep
);
1619 if (result
& INCR_UNSAFE
) {
1620 printf("%cunsafe", sep
);
1623 if (result
& INCR_ALREADY
) {
1624 printf("%calready", sep
);
1627 if (result
& INCR_YES
) {
1628 printf("%cyes", sep
);
1634 /* don't move spares to container with volume being activated
1635 when all volumes are blocked */
1636 if (ra_all
== ra_blocked
)
1639 /* Now move all suitable spares from spare container */
1640 domains
= domain_from_array(list
, st
->ss
->name
);
1641 memcpy(suuid
, uuid_zero
, sizeof(int[4]));
1643 (smp
= map_by_uuid(&map
, suuid
)) != NULL
&&
1644 (sfd
= open(smp
->path
, O_RDONLY
)) >= 0) {
1645 /* spare container found */
1646 struct supertype
*sst
=
1647 super_imsm
.match_metadata_desc("imsm");
1648 struct mdinfo
*sinfo
;
1649 unsigned long long min_size
= 0;
1650 if (st
->ss
->min_acceptable_spare_size
)
1651 min_size
= st
->ss
->min_acceptable_spare_size(st
);
1652 if (!sst
->ss
->load_container(sst
, sfd
, NULL
)) {
1654 sinfo
= container_choose_spares(sst
, min_size
,
1657 sst
->ss
->free_super(sst
);
1660 struct mdinfo
*disks
= sinfo
->devs
;
1662 /* move spare from spare
1663 * container to currently
1669 makedev(disks
->disk
.major
,
1670 disks
->disk
.minor
)))
1672 disks
= disks
->next
;
1675 pr_err("Added %d spare%s to %s\n",
1676 count
, count
>1?"s":"", devname
);
1682 domain_free(domains
);
1686 static void run_udisks(char *arg1
, char *arg2
)
1691 execl("/usr/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1692 execl("/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1695 while (pid
> 0 && wait(&status
) != pid
)
1700 * IncrementalRemove - Attempt to see if the passed in device belongs to any
1701 * raid arrays, and if so first fail (if needed) and then remove the device.
1703 * @devname - The device we want to remove
1704 * @id_path - name as found in /dev/disk/by-path for this device
1706 * Note: the device name must be a kernel name like "sda", so
1707 * that we can find it in /proc/mdstat
1709 int IncrementalRemove(char *devname
, char *id_path
, int verbose
)
1713 struct mdstat_ent
*ent
;
1714 struct mddev_dev devlist
;
1719 dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
1721 if (strchr(devname
, '/')) {
1722 pr_err("incremental removal requires a kernel device name, not a file: %s\n", devname
);
1725 ent
= mdstat_by_component(devname
);
1728 pr_err("%s does not appear to be a component of any array\n", devname
);
1731 sysfs_init(&mdi
, -1, ent
->devnm
);
1732 mdfd
= open_dev_excl(ent
->devnm
);
1735 if (sysfs_get_str(&mdi
, NULL
, "array_state",
1736 buf
, sizeof(buf
)) > 0) {
1737 if (strncmp(buf
, "active", 6) == 0 ||
1738 strncmp(buf
, "clean", 5) == 0)
1739 sysfs_set_str(&mdi
, NULL
,
1740 "array_state", "read-auto");
1743 mdfd
= open_dev(ent
->devnm
);
1746 pr_err("Cannot open array %s!!\n", ent
->devnm
);
1752 struct map_ent
*map
= NULL
, *me
;
1753 me
= map_by_devnm(&map
, ent
->devnm
);
1755 policy_save_path(id_path
, me
);
1759 memset(&devlist
, 0, sizeof(devlist
));
1760 devlist
.devname
= devname
;
1761 devlist
.disposition
= 'f';
1762 /* for a container, we must fail each member array */
1763 if (ent
->metadata_version
&&
1764 strncmp(ent
->metadata_version
, "external:", 9) == 0) {
1765 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
1766 struct mdstat_ent
*memb
;
1767 for (memb
= mdstat
; memb
; memb
= memb
->next
)
1768 if (is_container_member(memb
, ent
->devnm
)) {
1769 int subfd
= open_dev(memb
->devnm
);
1771 rv
|= Manage_subdevs(
1773 &devlist
, verbose
, 0,
1778 free_mdstat(mdstat
);
1780 rv
|= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1781 verbose
, 0, NULL
, 0);
1783 /* Failed due to EBUSY, try to stop the array.
1784 * Give udisks a chance to unmount it first.
1786 int devid
= devnm2devid(ent
->devnm
);
1787 run_udisks("--unmount", map_dev(major(devid
),minor(devid
), 0));
1788 rv
= Manage_stop(ent
->devnm
, mdfd
, verbose
, 1);
1790 /* At least we can try to trigger a 'remove' */
1791 sysfs_uevent(&mdi
, "remove");
1794 pr_err("Fail to stop %s too.\n", ent
->devnm
);
1797 devlist
.disposition
= 'r';
1798 rv
= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1799 verbose
, 0, NULL
, 0);