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).
91 struct mdinfo info
, dinfo
;
92 struct mdinfo
*sra
= NULL
, *d
;
93 struct mddev_ident
*match
;
94 char chosen_name
[1024];
97 struct map_ent
*mp
, *map
= NULL
;
98 int dfd
= -1, mdfd
= -1;
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_is_blkdev(dfd
, devname
, &rdev
))
181 dinfo
.disk
.major
= major(rdev
);
182 dinfo
.disk
.minor
= minor(rdev
);
184 policy
= disk_policy(&dinfo
);
185 have_target
= policy_check_path(&dinfo
, &target_array
);
187 if (st
== NULL
&& (st
= guess_super_type(dfd
, guess_array
)) == NULL
) {
189 pr_err("no recognisable superblock on %s.\n",
191 rv
= try_spare(devname
, &dfd
, policy
,
192 have_target
? &target_array
: NULL
,
196 st
->ignore_hw_compat
= 0;
198 if (st
->ss
->compare_super
== NULL
||
199 st
->ss
->load_super(st
, dfd
, c
->verbose
>= 0 ? devname
: NULL
)) {
201 pr_err("no RAID superblock on %s.\n",
203 rv
= try_spare(devname
, &dfd
, policy
,
204 have_target
? &target_array
: NULL
,
209 close (dfd
); dfd
= -1;
211 st
->ss
->getinfo_super(st
, &info
, NULL
);
213 /* 3/ Check if there is a match in mdadm.conf */
214 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
215 if (!match
&& rv
== 2)
218 if (match
&& match
->devname
&&
219 strcasecmp(match
->devname
, "<ignore>") == 0) {
221 pr_err("array containing %s is explicitly ignored by mdadm.conf\n",
226 /* 3a/ if not, check for homehost match. If no match, continue
227 * but don't trust the 'name' in the array. Thus a 'random' minor
228 * number will be assigned, and the device name will be based
232 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
234 else if (st
->ss
->match_home(st
, "any") == 1)
235 trustworthy
= LOCAL_ANY
;
237 trustworthy
= FOREIGN
;
239 if (!match
&& !conf_test_metadata(st
->ss
->name
, policy
,
240 (trustworthy
== LOCAL
))) {
242 pr_err("%s has metadata type %s for which auto-assembly is disabled\n",
243 devname
, st
->ss
->name
);
246 if (trustworthy
== LOCAL_ANY
)
249 /* There are three possible sources for 'autof': command line,
250 * ARRAY line in mdadm.conf, or CREATE line in mdadm.conf.
251 * ARRAY takes precedence, then command line, then
254 if (match
&& match
->autof
)
255 c
->autof
= match
->autof
;
257 c
->autof
= ci
->autof
;
259 name_to_use
= info
.name
;
260 if (name_to_use
[0] == 0 && info
.array
.level
== LEVEL_CONTAINER
) {
261 name_to_use
= info
.text_version
;
262 trustworthy
= METADATA
;
264 if (name_to_use
[0] && trustworthy
!= LOCAL
&&
265 ! c
->require_homehost
&&
266 conf_name_is_free(name_to_use
))
269 /* strip "hostname:" prefix from name if we have decided
270 * to treat it as LOCAL
272 if (trustworthy
== LOCAL
&& strchr(name_to_use
, ':') != NULL
)
273 name_to_use
= strchr(name_to_use
, ':')+1;
275 /* 4/ Check if array exists.
278 pr_err("failed to get exclusive lock on mapfile\n");
279 /* Now check we can get O_EXCL. If not, probably "mdadm -A" has
282 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
285 pr_err("cannot reopen %s: %s.\n",
286 devname
, strerror(errno
));
289 /* Cannot hold it open while we add the device to the array,
290 * so we must release the O_EXCL and depend on the map_lock()
291 * So now is the best time to remove any partitions.
293 remove_partitions(dfd
);
297 mp
= map_by_uuid(&map
, info
.uuid
);
299 mdfd
= open_dev(mp
->devnm
);
305 /* Skip the clustered ones. This should be started by
306 * clustering resource agents
308 if (info
.array
.state
& (1 << MD_SB_CLUSTERED
))
311 /* Couldn't find an existing array, maybe make a new one */
312 mdfd
= create_mddev(match
? match
->devname
: NULL
,
313 name_to_use
, c
->autof
, trustworthy
, chosen_name
, 0);
318 if (sysfs_init(&info
, mdfd
, NULL
)) {
319 pr_err("unable to initialize sysfs for %s\n",
325 if (set_array_info(mdfd
, st
, &info
) != 0) {
326 pr_err("failed to set array info for %s: %s\n",
327 chosen_name
, strerror(errno
));
333 dinfo
.disk
.major
= major(rdev
);
334 dinfo
.disk
.minor
= minor(rdev
);
335 if (add_disk(mdfd
, st
, &info
, &dinfo
) != 0) {
336 pr_err("failed to add %s to new array %s: %s.\n",
337 devname
, chosen_name
, strerror(errno
));
338 ioctl(mdfd
, STOP_ARRAY
, 0);
342 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
343 GET_OFFSET
| GET_SIZE
));
345 if (!sra
|| !sra
->devs
|| sra
->devs
->disk
.raid_disk
>= 0) {
346 /* It really should be 'none' - must be old buggy
347 * kernel, and mdadm -I may not be able to complete.
350 ioctl(mdfd
, STOP_ARRAY
, NULL
);
351 pr_err("You have an old buggy kernel which cannot support\n --incremental reliably. Aborting.\n");
355 info
.array
.working_disks
= 1;
356 /* 6/ Make sure /var/run/mdadm.map contains this array. */
357 map_update(&map
, fd2devnm(mdfd
),
359 info
.uuid
, chosen_name
);
362 /* - check one drive in array to make sure metadata is a reasonably */
363 /* close match. Reject if not (e.g. different type) */
364 /* - add the device */
368 struct supertype
*st2
;
369 struct mdinfo info2
, *d
;
371 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
372 GET_OFFSET
| GET_SIZE
));
375 strcpy(chosen_name
, mp
->path
);
377 strcpy(chosen_name
, mp
->devnm
);
379 /* It is generally not OK to add non-spare drives to a
380 * running array as they are probably missing because
381 * they failed. However if runstop is 1, then the
382 * array was possibly started early and our best bet is
383 * to add this anyway.
384 * Also if action policy is re-add or better we allow
386 * This doesn't apply to containers as the 'non-spare'
387 * flag has a different meaning. The test has to happen
388 * at the device level there
390 if (!st
->ss
->external
&&
391 (info
.disk
.state
& (1 << MD_DISK_SYNC
)) != 0 &&
392 !policy_action_allows(policy
, st
->ss
->name
, act_re_add
) &&
394 if (md_array_active(mdfd
)) {
395 pr_err("not adding %s to active array (without --run) %s\n",
396 devname
, chosen_name
);
406 sprintf(dn
, "%d:%d", sra
->devs
->disk
.major
,
407 sra
->devs
->disk
.minor
);
408 dfd2
= dev_open(dn
, O_RDONLY
);
410 pr_err("unable to open %s\n", devname
);
415 if (st2
->ss
->load_super(st2
, dfd2
, NULL
) ||
416 st
->ss
->compare_super(st
, st2
) != 0) {
417 pr_err("metadata mismatch between %s and chosen array %s\n",
418 devname
, chosen_name
);
424 st2
->ss
->getinfo_super(st2
, &info2
, NULL
);
425 st2
->ss
->free_super(st2
);
426 if (info
.array
.level
!= info2
.array
.level
||
427 memcmp(info
.uuid
, info2
.uuid
, 16) != 0 ||
428 info
.array
.raid_disks
!= info2
.array
.raid_disks
) {
429 pr_err("unexpected difference between %s and %s.\n",
430 chosen_name
, devname
);
435 info
.disk
.major
= major(rdev
);
436 info
.disk
.minor
= minor(rdev
);
437 /* add disk needs to know about containers */
438 if (st
->ss
->external
)
439 sra
->array
.level
= LEVEL_CONTAINER
;
441 if (info
.array
.state
& (1 << MD_SB_CLUSTERED
))
442 info
.disk
.state
|= (1 << MD_DISK_CLUSTER_ADD
);
444 err
= add_disk(mdfd
, st
, sra
, &info
);
445 if (err
< 0 && errno
== EBUSY
) {
446 /* could be another device present with the same
447 * disk.number. Find and reject any such
449 find_reject(mdfd
, st
, sra
, info
.disk
.number
,
450 info
.events
, c
->verbose
, chosen_name
);
451 err
= add_disk(mdfd
, st
, sra
, &info
);
453 if (err
< 0 && errno
== EINVAL
&&
454 info
.disk
.state
& (1<<MD_DISK_SYNC
)) {
455 /* Maybe it needs to be added as a spare */
456 if (policy_action_allows(policy
, st
->ss
->name
,
458 info
.disk
.state
&= ~(1<<MD_DISK_SYNC
);
459 err
= add_disk(mdfd
, st
, sra
, &info
);
462 pr_err("can only add %s to %s as a spare, and force-spare is not set.\n",
463 devname
, chosen_name
);
466 pr_err("failed to add %s to existing array %s: %s.\n",
467 devname
, chosen_name
, strerror(errno
));
471 info
.array
.working_disks
= 0;
472 for (d
= sra
->devs
; d
; d
=d
->next
)
473 info
.array
.working_disks
++;
476 if (strncmp(chosen_name
, "/dev/md/", 8) == 0)
477 md_devname
= chosen_name
+8;
479 md_devname
= chosen_name
;
481 printf("MD_DEVICE=%s\n", fd2devnm(mdfd
));
482 printf("MD_DEVNAME=%s\n", md_devname
);
483 printf("MD_FOREIGN=%s\n", trustworthy
== FOREIGN
? "yes" : "no");
486 /* 7/ Is there enough devices to possibly start the array? */
487 /* 7a/ if not, finish with success. */
488 if (info
.array
.level
== LEVEL_CONTAINER
) {
490 /* Try to assemble within the container */
491 sysfs_uevent(sra
, "change");
492 if (!c
->export
&& c
->verbose
>= 0)
493 pr_err("container %s now has %d device%s\n",
494 chosen_name
, info
.array
.working_disks
,
495 info
.array
.working_disks
== 1?"":"s");
496 wait_for(chosen_name
, mdfd
);
497 if (st
->ss
->external
)
498 strcpy(devnm
, fd2devnm(mdfd
));
499 if (st
->ss
->load_container
)
500 rv
= st
->ss
->load_container(st
, mdfd
, NULL
);
504 rv
= Incremental_container(st
, chosen_name
, c
, NULL
);
506 /* after spare is added, ping monitor for external metadata
507 * so that it can eg. try to rebuild degraded array */
508 if (st
->ss
->external
)
513 /* We have added something to the array, so need to re-read the
514 * state. Eventually this state should be kept up-to-date as
518 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
519 GET_OFFSET
| GET_SIZE
));
520 active_disks
= count_active(st
, sra
, mdfd
, &avail
, &info
);
522 journal_device_missing
= (info
.journal_device_required
) && (info
.journal_clean
== 0);
524 if (info
.consistency_policy
== CONSISTENCY_POLICY_PPL
)
525 info
.array
.state
|= 1;
527 if (enough(info
.array
.level
, info
.array
.raid_disks
,
528 info
.array
.layout
, info
.array
.state
& 1, avail
) == 0) {
530 printf("MD_STARTED=no\n");
531 } else if (c
->verbose
>= 0)
532 pr_err("%s attached to %s, not enough to start (%d).\n",
533 devname
, chosen_name
, active_disks
);
539 /* - if number of OK devices match expected, or -R and there */
541 /* + add any bitmap file */
542 /* + start the array (auto-readonly). */
544 if (md_array_active(mdfd
)) {
546 printf("MD_STARTED=already\n");
547 } else if (c
->verbose
>= 0)
548 pr_err("%s attached to %s which is already active.\n",
549 devname
, chosen_name
);
555 if (c
->runstop
> 0 || (!journal_device_missing
&& active_disks
>= info
.array
.working_disks
)) {
557 /* Let's try to start it */
559 if (journal_device_missing
)
560 pr_err("Trying to run with missing journal device\n");
561 if (info
.reshape_active
&& !(info
.reshape_active
& RESHAPE_NO_BACKUP
)) {
562 pr_err("%s: This array is being reshaped and cannot be started\n",
564 cont_err("by --incremental. Please use --assemble\n");
567 if (match
&& match
->bitmap_file
) {
568 int bmfd
= open(match
->bitmap_file
, O_RDWR
);
570 pr_err("Could not open bitmap file %s.\n",
574 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
576 pr_err("Failed to set bitmapfile for %s.\n",
582 /* Need to remove from the array any devices which
583 * 'count_active' discerned were too old or inappropriate
585 for (d
= sra
? sra
->devs
: NULL
; d
; d
= d
->next
)
586 if (d
->disk
.state
& (1<<MD_DISK_REMOVED
))
587 remove_disk(mdfd
, st
, sra
, d
);
589 if ((sra
== NULL
|| active_disks
>= info
.array
.working_disks
) &&
590 trustworthy
!= FOREIGN
)
591 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
593 rv
= sysfs_set_str(sra
, NULL
,
594 "array_state", "read-auto");
595 /* Array might be O_EXCL which will interfere with
596 * fsck and mount. So re-open without O_EXCL.
601 printf("MD_STARTED=yes\n");
602 } else if (c
->verbose
>= 0)
603 pr_err("%s attached to %s, which has been started.\n",
604 devname
, chosen_name
);
606 wait_for(chosen_name
, mdfd
);
607 /* We just started the array, so some devices
608 * might have been evicted from the array
609 * because their event counts were too old.
610 * If the action=re-add policy is in-force for
611 * those devices we should re-add them now.
613 for (dsk
= sra
->devs
; dsk
; dsk
= dsk
->next
) {
614 if (disk_action_allows(dsk
, st
->ss
->name
,
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
);
650 static void find_reject(int mdfd
, struct supertype
*st
, struct mdinfo
*sra
,
651 int number
, __u64 events
, int verbose
,
654 /* Find a device attached to this array with a disk.number of number
655 * and events less than the passed events, and remove the device.
659 if (md_array_active(mdfd
))
660 return; /* not safe to remove from active arrays
661 * without thinking more */
663 for (d
= sra
->devs
; d
; d
= d
->next
) {
664 char dn
[24]; // 2*11 bytes for ints (including sign) + colon + null byte
667 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
668 dfd
= dev_open(dn
, O_RDONLY
);
671 if (st
->ss
->load_super(st
, dfd
, NULL
)) {
675 st
->ss
->getinfo_super(st
, &info
, NULL
);
676 st
->ss
->free_super(st
);
679 if (info
.disk
.number
!= number
|| info
.events
>= events
)
682 if (d
->disk
.raid_disk
> -1)
683 sysfs_set_str(sra
, d
, "slot", "none");
684 if (sysfs_set_str(sra
, d
, "state", "remove") == 0)
686 pr_err("removing old device %s from %s\n",
687 d
->sys_name
+4, array_name
);
691 static int count_active(struct supertype
*st
, struct mdinfo
*sra
,
692 int mdfd
, char **availp
,
693 struct mdinfo
*bestinfo
)
695 /* count how many devices in sra think they are active */
699 __u64 max_events
= 0;
711 for (d
= sra
->devs
; d
; d
= d
->next
)
713 for (d
= sra
->devs
, devnum
= 0 ; d
; d
= d
->next
, devnum
++) {
719 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
720 dfd
= dev_open(dn
, O_RDONLY
);
723 ok
= st
->ss
->load_super(st
, dfd
, NULL
);
728 info
.array
.raid_disks
= raid_disks
;
729 st
->ss
->getinfo_super(st
, &info
, devmap
+ raid_disks
* devnum
);
730 if (info
.disk
.raid_disk
== MD_DISK_ROLE_JOURNAL
)
731 bestinfo
->journal_clean
= 1;
733 raid_disks
= info
.array
.raid_disks
;
734 avail
= xcalloc(raid_disks
, 1);
737 best
= xcalloc(raid_disks
, sizeof(int));
738 devmap
= xcalloc(raid_disks
, numdevs
);
740 st
->ss
->getinfo_super(st
, &info
, devmap
);
743 if (info
.disk
.state
& (1<<MD_DISK_SYNC
))
747 max_events
= info
.events
;
748 avail
[info
.disk
.raid_disk
] = 2;
749 best
[info
.disk
.raid_disk
] = devnum
;
750 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
751 } else if (info
.events
== max_events
) {
752 avail
[info
.disk
.raid_disk
] = 2;
753 best
[info
.disk
.raid_disk
] = devnum
;
754 } else if (info
.events
== max_events
-1) {
755 if (avail
[info
.disk
.raid_disk
] == 0) {
756 avail
[info
.disk
.raid_disk
] = 1;
757 best
[info
.disk
.raid_disk
] = devnum
;
759 } else if (info
.events
< max_events
- 1)
761 else if (info
.events
== max_events
+1) {
763 max_events
= info
.events
;
764 for (i
= 0; i
< raid_disks
; i
++)
767 avail
[info
.disk
.raid_disk
] = 2;
768 best
[info
.disk
.raid_disk
] = devnum
;
769 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
770 } else { /* info.events much bigger */
771 memset(avail
, 0, raid_disks
);
772 max_events
= info
.events
;
773 avail
[info
.disk
.raid_disk
] = 2;
774 best
[info
.disk
.raid_disk
] = devnum
;
775 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
777 } else if (info
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
779 st
->ss
->free_super(st
);
784 /* We need to reject any device that thinks the best device is
785 * failed or missing */
786 for (b
= 0; b
< raid_disks
; b
++)
790 for (i
= 0 ; i
< raid_disks
; i
++) {
791 if (i
!= b
&& avail
[i
])
792 if (devmap
[raid_disks
* best
[i
] + b
] == 0) {
793 /* This device thinks 'b' is failed -
796 for (d
=sra
->devs
; devnum
; d
= d
->next
)
798 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
804 /* Also need to reject any spare device with an event count that
807 for (d
= sra
->devs
; d
; d
= d
->next
) {
808 if (!(d
->disk
.state
& (1<<MD_DISK_SYNC
)) &&
809 d
->events
> max_events
)
810 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
814 return cnt
+ replcnt
;
817 /* test if container has degraded member(s) */
818 static int container_members_max_degradation(struct map_ent
*map
, struct map_ent
*me
)
820 mdu_array_info_t array
;
822 int max_degraded
= 0;
824 for(; map
; map
= map
->next
) {
825 if (!metadata_container_matches(map
->metadata
, me
->devnm
))
827 afd
= open_dev(map
->devnm
);
830 /* most accurate information regarding array degradation */
831 if (md_get_array_info(afd
, &array
) >= 0) {
832 int degraded
= array
.raid_disks
- array
.active_disks
-
834 if (degraded
> max_degraded
)
835 max_degraded
= degraded
;
839 return (max_degraded
);
842 static int array_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
843 struct map_ent
*target
, int bare
,
844 struct supertype
*st
, int verbose
)
846 /* This device doesn't have any md metadata
847 * The device policy allows 'spare' and if !bare, it allows spare-same-slot.
848 * If 'st' is not set, then we only know that some metadata allows this,
849 * others possibly don't.
850 * So look for a container or array to attach the device to.
851 * Prefer 'target' if that is set and the array is found.
853 * If st is set, then only arrays of that type are considered
854 * Return 0 on success, or some exit code on failure, probably 1.
858 struct map_ent
*mp
, *map
= NULL
;
859 struct mdinfo
*chosen
= NULL
;
862 if (!fstat_is_blkdev(dfd
, devname
, &rdev
))
866 * Now we need to find a suitable array to add this to.
867 * We only accept arrays that:
869 * - are in the same domains as the device
870 * - are of an size for which the device will be useful
871 * and we choose the one that is the most degraded
874 if (map_lock(&map
)) {
875 pr_err("failed to get exclusive lock on mapfile\n");
878 for (mp
= map
; mp
; mp
= mp
->next
) {
879 struct supertype
*st2
;
880 struct domainlist
*dl
= NULL
;
882 unsigned long long devsize
;
883 unsigned long long component_size
= 0;
885 if (is_subarray(mp
->metadata
))
888 st2
= st
->ss
->match_metadata_desc(mp
->metadata
);
890 (st
->minor_version
>= 0 &&
891 st
->minor_version
!= st2
->minor_version
)) {
893 pr_err("not adding %s to %s as metadata type doesn't match\n",
900 sra
= sysfs_read(-1, mp
->devnm
,
901 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
902 GET_DEGRADED
|GET_COMPONENT
|GET_VERSION
);
904 /* Probably a container - no degraded info */
905 sra
= sysfs_read(-1, mp
->devnm
,
906 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
907 GET_COMPONENT
|GET_VERSION
);
909 sra
->array
.failed_disks
= -1;
916 for(i
= 0; !st2
&& superlist
[i
]; i
++)
917 st2
= superlist
[i
]->match_metadata_desc(
921 pr_err("not adding %s to %s as metadata not recognised.\n",
925 /* Need to double check the 'act_spare' permissions applies
928 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
930 if (!bare
&& !policy_action_allows(pol
, st2
->ss
->name
,
931 act_spare_same_slot
))
935 /* update number of failed disks for mostly degraded
936 * container member */
937 if (sra
->array
.failed_disks
== -1)
938 sra
->array
.failed_disks
= container_members_max_degradation(map
, mp
);
940 get_dev_size(dfd
, NULL
, &devsize
);
941 if (sra
->component_size
== 0) {
942 /* true for containers, here we must read superblock
943 * to obtain minimum spare size */
944 struct supertype
*st3
= dup_super(st2
);
945 int mdfd
= open_dev(mp
->devnm
);
950 if (st3
->ss
->load_container
&&
951 !st3
->ss
->load_container(st3
, mdfd
, mp
->path
)) {
952 component_size
= st3
->ss
->min_acceptable_spare_size(st3
);
953 st3
->ss
->free_super(st3
);
958 if ((sra
->component_size
> 0 &&
959 st2
->ss
->avail_size(st2
, devsize
,
960 sra
->devs
? sra
->devs
->data_offset
:
962 sra
->component_size
) ||
963 (sra
->component_size
== 0 && devsize
< component_size
)) {
965 pr_err("not adding %s to %s as it is too small\n",
969 /* test against target.
970 * If 'target' is set and 'bare' is false, we only accept
971 * arrays/containers that match 'target'.
972 * If 'target' is set and 'bare' is true, we prefer the
973 * array which matches 'target'.
974 * target is considered only if we deal with degraded array
976 if (target
&& policy_action_allows(pol
, st2
->ss
->name
,
977 act_spare_same_slot
)) {
978 if (strcmp(target
->metadata
, mp
->metadata
) == 0 &&
979 memcmp(target
->uuid
, mp
->uuid
,
980 sizeof(target
->uuid
)) == 0 &&
981 sra
->array
.failed_disks
> 0) {
982 /* This is our target!! */
986 /* skip to end so we don't check any more */
996 dl
= domain_from_array(sra
, st2
->ss
->name
);
997 if (domain_test(dl
, pol
, st2
->ss
->name
) != 1) {
998 /* domain test fails */
1000 pr_err("not adding %s to %s as it is not in a compatible domain\n",
1005 /* all tests passed, OK to add to this array */
1009 } else if (chosen
->array
.failed_disks
< sra
->array
.failed_disks
) {
1022 /* add current device to chosen array as a spare */
1023 int mdfd
= open_dev(chosen
->sys_name
);
1025 struct mddev_dev devlist
;
1026 char chosen_devname
[24]; // 2*11 for int (including signs) + colon + null
1027 devlist
.next
= NULL
;
1029 devlist
.writemostly
= FlagDefault
;
1030 devlist
.failfast
= FlagDefault
;
1031 devlist
.devname
= chosen_devname
;
1032 sprintf(chosen_devname
, "%d:%d", major(rdev
),
1034 devlist
.disposition
= 'a';
1037 rv
= Manage_subdevs(chosen
->sys_name
, mdfd
, &devlist
,
1043 pr_err("added %s as spare for %s\n",
1044 devname
, chosen
->sys_name
);
1046 pr_err("failed to add %s as spare for %s\n",
1047 devname
, chosen
->sys_name
);
1055 static int partition_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1056 struct supertype
*st
, int verbose
)
1058 /* we know that at least one partition virtual-metadata is
1059 * allowed to incorporate spares like this device. We need to
1060 * find a suitable device to copy partition information from.
1062 * Getting a list of all disk (not partition) devices is
1063 * slightly non-trivial. We could look at /sys/block, but
1064 * that is theoretically due to be removed. Maybe best to use
1065 * /dev/disk/by-path/?* and ignore names ending '-partNN' as
1066 * we depend on this directory of 'path' info. But that fails
1067 * to find loop devices and probably others. Maybe don't
1068 * worry about that, they aren't the real target.
1070 * So: check things in /dev/disk/by-path to see if they are in
1071 * a compatible domain, then load the partition table and see
1072 * if it is OK for the new device, and choose the largest
1073 * partition table that fits.
1077 char *chosen
= NULL
;
1078 unsigned long long chosen_size
= 0;
1079 struct supertype
*chosen_st
= NULL
;
1082 dir
= opendir("/dev/disk/by-path");
1085 while ((de
= readdir(dir
)) != NULL
) {
1087 struct dev_policy
*pol2
= NULL
;
1088 struct domainlist
*domlist
= NULL
;
1091 struct supertype
*st2
= NULL
;
1092 char *devname
= NULL
;
1093 unsigned long long devsectors
;
1095 if (de
->d_ino
== 0 || de
->d_name
[0] == '.' ||
1096 (de
->d_type
!= DT_LNK
&& de
->d_type
!= DT_UNKNOWN
))
1099 ep
= de
->d_name
+ strlen(de
->d_name
);
1100 while (ep
> de
->d_name
&&
1103 if (ep
> de
->d_name
+ 5 &&
1104 strncmp(ep
-5, "-part", 5) == 0)
1105 /* This is a partition - skip it */
1108 pol2
= path_policy(de
->d_name
, type_disk
);
1110 domain_merge(&domlist
, pol2
, st
? st
->ss
->name
: NULL
);
1111 if (domain_test(domlist
, pol
, st
? st
->ss
->name
: NULL
) != 1)
1112 /* new device is incompatible with this device. */
1115 domain_free(domlist
);
1118 if (asprintf(&devname
, "/dev/disk/by-path/%s", de
->d_name
) != 1) {
1122 fd
= open(devname
, O_RDONLY
);
1125 if (get_dev_size(fd
, devname
, &devsectors
) == 0)
1130 st2
= dup_super(st
);
1132 st2
= guess_super_type(fd
, guess_partitions
);
1133 if (st2
== NULL
|| st2
->ss
->load_super(st2
, fd
, NULL
) < 0)
1135 st2
->ignore_hw_compat
= 0;
1138 /* Check domain policy again, this time referring to metadata */
1139 domain_merge(&domlist
, pol2
, st2
->ss
->name
);
1140 if (domain_test(domlist
, pol
, st2
->ss
->name
) != 1)
1141 /* Incompatible devices for this metadata type */
1143 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
1144 /* Some partition types allow sparing, but not
1150 st2
->ss
->getinfo_super(st2
, &info
, NULL
);
1151 if (info
.component_size
> devsectors
)
1152 /* This partitioning doesn't fit in the device */
1155 /* This is an acceptable device to copy partition
1156 * metadata from. We could just stop here, but I
1157 * think I want to keep looking incase a larger
1158 * metadata which makes better use of the device can
1161 if (chosen
== NULL
|| chosen_size
< info
.component_size
) {
1162 chosen_size
= info
.component_size
;
1167 chosen_st
->ss
->free_super(chosen_st
);
1176 domain_free(domlist
);
1177 dev_policy_free(pol2
);
1179 st2
->ss
->free_super(st2
);
1191 /* 'chosen' is the best device we can find. Let's write its
1192 * metadata to devname dfd is read-only so don't use that
1194 fd
= open(devname
, O_RDWR
);
1196 chosen_st
->ss
->store_super(chosen_st
, fd
);
1200 chosen_st
->ss
->free_super(chosen_st
);
1205 static int is_bare(int dfd
)
1207 unsigned long long size
= 0;
1208 char bufpad
[4096 + 4096];
1209 char *buf
= (char*)(((long)bufpad
+ 4096) & ~4095);
1211 if (lseek(dfd
, 0, SEEK_SET
) != 0 ||
1212 read(dfd
, buf
, 4096) != 4096)
1215 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1217 if (memcmp(buf
, buf
+1, 4095) != 0)
1220 /* OK, first 4K appear blank, try the end. */
1221 get_dev_size(dfd
, NULL
, &size
);
1222 if (lseek(dfd
, size
-4096, SEEK_SET
) < 0 ||
1223 read(dfd
, buf
, 4096) != 4096)
1226 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1228 if (memcmp(buf
, buf
+1, 4095) != 0)
1234 /* adding a spare to a regular array is quite different from adding one to
1235 * a set-of-partitions virtual array.
1236 * This function determines which is worth trying and tries as appropriate.
1237 * Arrays are given priority over partitions.
1239 static int try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1240 struct map_ent
*target
,
1241 struct supertype
*st
, int verbose
)
1246 int partitions_ok
= 0;
1250 /* Can only add a spare if device has at least one domain */
1251 if (pol_find(pol
, pol_domain
) == NULL
)
1253 /* And only if some action allows spares */
1254 if (!policy_action_allows(pol
, st
?st
->ss
->name
:NULL
, act_spare
))
1257 /* Now check if the device is bare.
1258 * bare devices can always be added as a spare
1259 * non-bare devices can only be added if spare-same-slot is permitted,
1260 * and this device is replacing a previous device - in which case 'target'
1263 if (!is_bare(dfd
)) {
1264 /* Must have a target and allow same_slot */
1265 /* Later - may allow force_spare without target */
1267 !policy_action_allows(pol
, st
?st
->ss
->name
:NULL
,
1268 act_spare_same_slot
)) {
1270 pr_err("%s is not bare, so not considering as a spare\n",
1278 /* It might be OK to add this device to an array - need to see
1279 * what arrays might be candidates.
1282 /* just try try 'array' or 'partition' based on this metadata */
1283 if (st
->ss
->add_to_super
)
1284 return array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1287 return partition_try_spare(devname
, dfdp
, pol
,
1290 /* No metadata was specified or found so options are open.
1291 * Check for whether any array metadata, or any partition metadata
1292 * might allow adding the spare. This check is just help to avoid
1293 * a more costly scan of all arrays when we can be sure that will
1296 for (i
= 0; (!arrays_ok
|| !partitions_ok
) && superlist
[i
] ; i
++) {
1297 if (superlist
[i
]->add_to_super
&& !arrays_ok
&&
1298 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1300 if (superlist
[i
]->add_to_super
== NULL
&& !partitions_ok
&&
1301 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1306 rv
= array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1308 if (rv
!= 0 && partitions_ok
)
1309 rv
= partition_try_spare(devname
, dfdp
, pol
, st
, verbose
);
1313 int IncrementalScan(struct context
*c
, char *devnm
)
1315 /* look at every device listed in the 'map' file.
1316 * If one is found that is not running then:
1317 * look in mdadm.conf for bitmap file.
1318 * if one exists, but array has none, add it.
1319 * try to start array in auto-readonly mode
1321 struct map_ent
*mapl
= NULL
;
1323 struct mddev_ident
*devs
, *mddev
;
1329 devs
= conf_get_ident(NULL
);
1332 for (me
= mapl
; me
; me
= me
->next
) {
1333 mdu_array_info_t array
;
1337 if (devnm
&& strcmp(devnm
, me
->devnm
) != 0)
1339 if (me
->metadata
[0] == '/') {
1345 /* member array, need to work on container */
1346 strncpy(container
, me
->metadata
+1, 32);
1348 sl
= strchr(container
, '/');
1355 mdfd
= open_dev(me
->devnm
);
1359 if (!isdigit(me
->metadata
[0])) {
1360 /* must be a container */
1361 struct supertype
*st
= super_by_fd(mdfd
, NULL
);
1363 struct map_ent
*map
= NULL
;
1365 if (st
&& st
->ss
->load_container
)
1366 ret
= st
->ss
->load_container(st
, mdfd
, NULL
);
1368 if (!ret
&& st
&& st
->ss
->container_content
) {
1370 pr_err("failed to get exclusive lock on mapfile\n");
1371 ret
= Incremental_container(st
, me
->path
, c
, only
);
1378 if (md_get_array_info(mdfd
, &array
) == 0 || errno
!= ENODEV
) {
1382 /* Ok, we can try this one. Maybe it needs a bitmap */
1383 for (mddev
= devs
; mddev
; mddev
= mddev
->next
)
1384 if (mddev
->devname
&& me
->path
&&
1385 devname_matches(mddev
->devname
, me
->path
))
1387 if (mddev
&& mddev
->bitmap_file
) {
1389 * Note: early kernels will wrongly fail this, so it
1395 bmfd
= open(mddev
->bitmap_file
, O_RDWR
);
1397 added
= ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
);
1400 if (c
->verbose
>= 0) {
1402 pr_err("Added bitmap %s to %s\n",
1403 mddev
->bitmap_file
, me
->path
);
1404 else if (errno
!= EEXIST
)
1405 pr_err("Failed to add bitmap to %s: %s\n",
1406 me
->path
, strerror(errno
));
1409 /* FIXME check for reshape_active and consider not
1412 sra
= sysfs_read(mdfd
, NULL
, 0);
1414 if (sysfs_set_str(sra
, NULL
,
1415 "array_state", "read-auto") == 0) {
1416 if (c
->verbose
>= 0)
1417 pr_err("started array %s\n",
1418 me
->path
?: me
->devnm
);
1420 pr_err("failed to start array %s: %s\n",
1421 me
->path
?: me
->devnm
,
1431 static char *container2devname(char *devname
)
1433 char *mdname
= NULL
;
1435 if (devname
[0] == '/') {
1436 int fd
= open(devname
, O_RDONLY
);
1438 mdname
= xstrdup(fd2devnm(fd
));
1443 struct map_ent
*mp
, *map
= NULL
;
1445 if (!parse_uuid(devname
, uuid
))
1447 mp
= map_by_uuid(&map
, uuid
);
1449 mdname
= xstrdup(mp
->devnm
);
1456 static int Incremental_container(struct supertype
*st
, char *devname
,
1457 struct context
*c
, char *only
)
1459 /* Collect the contents of this container and for each
1460 * array, choose a device name and assemble the array.
1463 struct mdinfo
*list
;
1465 struct map_ent
*map
= NULL
;
1468 struct mddev_ident
*match
;
1470 struct domainlist
*domains
;
1471 struct map_ent
*smp
;
1478 st
->ss
->getinfo_super(st
, &info
, NULL
);
1480 if ((c
->runstop
> 0 && info
.container_enough
>= 0) ||
1481 info
.container_enough
> 0)
1485 printf("MD_STARTED=no\n");
1486 } else if (c
->verbose
)
1487 pr_err("not enough devices to start the container\n");
1491 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
1492 if (match
== NULL
&& rv
== 2)
1495 /* Need to compute 'trustworthy' */
1497 trustworthy
= LOCAL
;
1498 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
1499 trustworthy
= LOCAL
;
1500 else if (st
->ss
->match_home(st
, "any") == 1)
1501 trustworthy
= LOCAL
;
1503 trustworthy
= FOREIGN
;
1505 list
= st
->ss
->container_content(st
, NULL
);
1506 /* when nothing to activate - quit */
1509 printf("MD_STARTED=nothing\n");
1513 for (ra
= list
; ra
; ra
= ra
->next
) {
1515 char chosen_name
[1024];
1517 struct mddev_ident
*match
= NULL
;
1520 /* do not activate arrays blocked by metadata handler */
1521 if (ra
->array
.state
& (1 << MD_SB_BLOCK_VOLUME
)) {
1522 pr_err("Cannot activate array %s in %s.\n",
1523 ra
->text_version
, devname
);
1527 mp
= map_by_uuid(&map
, ra
->uuid
);
1530 mdfd
= open_dev(mp
->devnm
);
1532 strcpy(chosen_name
, mp
->path
);
1534 strcpy(chosen_name
, mp
->devnm
);
1537 /* Check in mdadm.conf for container == devname and
1538 * member == ra->text_version after second slash.
1540 char *sub
= strchr(ra
->text_version
+1, '/');
1541 struct mddev_ident
*array_list
;
1544 array_list
= conf_get_ident(NULL
);
1547 for(; array_list
; array_list
= array_list
->next
) {
1549 if (array_list
->member
== NULL
||
1550 array_list
->container
== NULL
)
1552 if (strcmp(array_list
->member
, sub
) != 0)
1554 if (array_list
->uuid_set
&&
1555 !same_uuid(ra
->uuid
, array_list
->uuid
, st
->ss
->swapuuid
))
1557 dn
= container2devname(array_list
->container
);
1560 if (strncmp(dn
, ra
->text_version
+1,
1562 ra
->text_version
[strlen(dn
)+1] != '/') {
1567 /* we have a match */
1570 pr_err("match found for member %s\n",
1571 array_list
->member
);
1575 if (match
&& match
->devname
&&
1576 strcasecmp(match
->devname
, "<ignore>") == 0) {
1578 pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
1579 match
->container
, match
->member
);
1583 trustworthy
= LOCAL
;
1585 mdfd
= create_mddev(match
? match
->devname
: NULL
,
1591 if (only
&& (!mp
|| strcmp(mp
->devnm
, only
) != 0))
1595 pr_err("failed to open %s: %s.\n",
1596 chosen_name
, strerror(errno
));
1600 assemble_container_content(st
, mdfd
, ra
, c
,
1601 chosen_name
, &result
);
1604 if (c
->export
&& result
) {
1606 printf("MD_STARTED");
1607 if (result
& INCR_NO
) {
1608 printf("%cno", sep
);
1611 if (result
& INCR_UNSAFE
) {
1612 printf("%cunsafe", sep
);
1615 if (result
& INCR_ALREADY
) {
1616 printf("%calready", sep
);
1619 if (result
& INCR_YES
) {
1620 printf("%cyes", sep
);
1626 /* don't move spares to container with volume being activated
1627 when all volumes are blocked */
1628 if (ra_all
== ra_blocked
)
1631 /* Now move all suitable spares from spare container */
1632 domains
= domain_from_array(list
, st
->ss
->name
);
1633 memcpy(suuid
, uuid_zero
, sizeof(int[4]));
1635 (smp
= map_by_uuid(&map
, suuid
)) != NULL
&&
1636 (sfd
= open(smp
->path
, O_RDONLY
)) >= 0) {
1637 /* spare container found */
1638 struct supertype
*sst
=
1639 super_imsm
.match_metadata_desc("imsm");
1640 struct mdinfo
*sinfo
;
1641 unsigned long long min_size
= 0;
1642 if (st
->ss
->min_acceptable_spare_size
)
1643 min_size
= st
->ss
->min_acceptable_spare_size(st
);
1644 if (!sst
->ss
->load_container(sst
, sfd
, NULL
)) {
1646 sinfo
= container_choose_spares(sst
, min_size
,
1649 sst
->ss
->free_super(sst
);
1652 struct mdinfo
*disks
= sinfo
->devs
;
1654 /* move spare from spare
1655 * container to currently
1661 makedev(disks
->disk
.major
,
1662 disks
->disk
.minor
)))
1664 disks
= disks
->next
;
1667 pr_err("Added %d spare%s to %s\n",
1668 count
, count
>1?"s":"", devname
);
1674 domain_free(domains
);
1678 static void run_udisks(char *arg1
, char *arg2
)
1683 execl("/usr/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1684 execl("/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1687 while (pid
> 0 && wait(&status
) != pid
)
1692 * IncrementalRemove - Attempt to see if the passed in device belongs to any
1693 * raid arrays, and if so first fail (if needed) and then remove the device.
1695 * @devname - The device we want to remove
1696 * @id_path - name as found in /dev/disk/by-path for this device
1698 * Note: the device name must be a kernel name like "sda", so
1699 * that we can find it in /proc/mdstat
1701 int IncrementalRemove(char *devname
, char *id_path
, int verbose
)
1705 struct mdstat_ent
*ent
;
1706 struct mddev_dev devlist
;
1711 dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
1713 if (strchr(devname
, '/')) {
1714 pr_err("incremental removal requires a kernel device name, not a file: %s\n", devname
);
1717 ent
= mdstat_by_component(devname
);
1720 pr_err("%s does not appear to be a component of any array\n", devname
);
1723 if (sysfs_init(&mdi
, -1, ent
->devnm
)) {
1724 pr_err("unable to initialize sysfs for: %s\n", devname
);
1727 mdfd
= open_dev_excl(ent
->devnm
);
1730 if (sysfs_get_str(&mdi
, NULL
, "array_state",
1731 buf
, sizeof(buf
)) > 0) {
1732 if (strncmp(buf
, "active", 6) == 0 ||
1733 strncmp(buf
, "clean", 5) == 0)
1734 sysfs_set_str(&mdi
, NULL
,
1735 "array_state", "read-auto");
1738 mdfd
= open_dev(ent
->devnm
);
1741 pr_err("Cannot open array %s!!\n", ent
->devnm
);
1747 struct map_ent
*map
= NULL
, *me
;
1748 me
= map_by_devnm(&map
, ent
->devnm
);
1750 policy_save_path(id_path
, me
);
1754 memset(&devlist
, 0, sizeof(devlist
));
1755 devlist
.devname
= devname
;
1756 devlist
.disposition
= 'f';
1757 /* for a container, we must fail each member array */
1758 if (ent
->metadata_version
&&
1759 strncmp(ent
->metadata_version
, "external:", 9) == 0) {
1760 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
1761 struct mdstat_ent
*memb
;
1762 for (memb
= mdstat
; memb
; memb
= memb
->next
)
1763 if (is_container_member(memb
, ent
->devnm
)) {
1764 int subfd
= open_dev(memb
->devnm
);
1766 rv
|= Manage_subdevs(
1768 &devlist
, verbose
, 0,
1773 free_mdstat(mdstat
);
1775 rv
|= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1776 verbose
, 0, NULL
, 0);
1778 /* Failed due to EBUSY, try to stop the array.
1779 * Give udisks a chance to unmount it first.
1781 int devid
= devnm2devid(ent
->devnm
);
1782 run_udisks("--unmount", map_dev(major(devid
),minor(devid
), 0));
1783 rv
= Manage_stop(ent
->devnm
, mdfd
, verbose
, 1);
1785 /* At least we can try to trigger a 'remove' */
1786 sysfs_uevent(&mdi
, "remove");
1789 pr_err("Fail to stop %s too.\n", ent
->devnm
);
1792 devlist
.disposition
= 'r';
1793 rv
= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1794 verbose
, 0, NULL
, 0);