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 && info
.array
.level
== LEVEL_CONTAINER
) {
271 name_to_use
= info
.text_version
;
272 trustworthy
= METADATA
;
274 if (name_to_use
[0] && trustworthy
!= LOCAL
&&
275 ! c
->require_homehost
&&
276 conf_name_is_free(name_to_use
))
279 /* strip "hostname:" prefix from name if we have decided
280 * to treat it as LOCAL
282 if (trustworthy
== LOCAL
&& strchr(name_to_use
, ':') != NULL
)
283 name_to_use
= strchr(name_to_use
, ':')+1;
285 /* 4/ Check if array exists.
288 pr_err("failed to get exclusive lock on mapfile\n");
289 /* Now check we can get O_EXCL. If not, probably "mdadm -A" has
292 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
295 pr_err("cannot reopen %s: %s.\n",
296 devname
, strerror(errno
));
299 /* Cannot hold it open while we add the device to the array,
300 * so we must release the O_EXCL and depend on the map_lock()
301 * So now is the best time to remove any partitions.
303 remove_partitions(dfd
);
307 mp
= map_by_uuid(&map
, info
.uuid
);
309 mdfd
= open_dev(mp
->devnm
);
315 /* Skip the clustered ones. This should be started by
316 * clustering resource agents
318 if (info
.array
.state
& (1 << MD_SB_CLUSTERED
))
321 /* Couldn't find an existing array, maybe make a new one */
322 mdfd
= create_mddev(match
? match
->devname
: NULL
,
323 name_to_use
, c
->autof
, trustworthy
, chosen_name
);
328 if (sysfs_init(&info
, mdfd
, NULL
)) {
329 pr_err("unable to initialize sysfs for %s\n",
335 if (set_array_info(mdfd
, st
, &info
) != 0) {
336 pr_err("failed to set array info for %s: %s\n",
337 chosen_name
, strerror(errno
));
343 dinfo
.disk
.major
= major(stb
.st_rdev
);
344 dinfo
.disk
.minor
= minor(stb
.st_rdev
);
345 if (add_disk(mdfd
, st
, &info
, &dinfo
) != 0) {
346 pr_err("failed to add %s to new array %s: %s.\n",
347 devname
, chosen_name
, strerror(errno
));
348 ioctl(mdfd
, STOP_ARRAY
, 0);
352 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
353 GET_OFFSET
| GET_SIZE
));
355 if (!sra
|| !sra
->devs
|| sra
->devs
->disk
.raid_disk
>= 0) {
356 /* It really should be 'none' - must be old buggy
357 * kernel, and mdadm -I may not be able to complete.
360 ioctl(mdfd
, STOP_ARRAY
, NULL
);
361 pr_err("You have an old buggy kernel which cannot support\n --incremental reliably. Aborting.\n");
365 info
.array
.working_disks
= 1;
366 /* 6/ Make sure /var/run/mdadm.map contains this array. */
367 map_update(&map
, fd2devnm(mdfd
),
369 info
.uuid
, chosen_name
);
372 /* - check one drive in array to make sure metadata is a reasonably */
373 /* close match. Reject if not (e.g. different type) */
374 /* - add the device */
378 struct supertype
*st2
;
379 struct mdinfo info2
, *d
;
381 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
382 GET_OFFSET
| GET_SIZE
));
385 strcpy(chosen_name
, mp
->path
);
387 strcpy(chosen_name
, mp
->devnm
);
389 /* It is generally not OK to add non-spare drives to a
390 * running array as they are probably missing because
391 * they failed. However if runstop is 1, then the
392 * array was possibly started early and our best bet is
393 * to add this anyway.
394 * Also if action policy is re-add or better we allow
396 * This doesn't apply to containers as the 'non-spare'
397 * flag has a different meaning. The test has to happen
398 * at the device level there
400 if (!st
->ss
->external
&&
401 (info
.disk
.state
& (1 << MD_DISK_SYNC
)) != 0 &&
402 !policy_action_allows(policy
, st
->ss
->name
, act_re_add
) &&
404 if (md_array_active(mdfd
)) {
405 pr_err("not adding %s to active array (without --run) %s\n",
406 devname
, chosen_name
);
416 sprintf(dn
, "%d:%d", sra
->devs
->disk
.major
,
417 sra
->devs
->disk
.minor
);
418 dfd2
= dev_open(dn
, O_RDONLY
);
420 pr_err("unable to open %s\n", devname
);
425 if (st2
->ss
->load_super(st2
, dfd2
, NULL
) ||
426 st
->ss
->compare_super(st
, st2
) != 0) {
427 pr_err("metadata mismatch between %s and chosen array %s\n",
428 devname
, chosen_name
);
434 st2
->ss
->getinfo_super(st2
, &info2
, NULL
);
435 st2
->ss
->free_super(st2
);
436 if (info
.array
.level
!= info2
.array
.level
||
437 memcmp(info
.uuid
, info2
.uuid
, 16) != 0 ||
438 info
.array
.raid_disks
!= info2
.array
.raid_disks
) {
439 pr_err("unexpected difference between %s and %s.\n",
440 chosen_name
, devname
);
445 info
.disk
.major
= major(stb
.st_rdev
);
446 info
.disk
.minor
= minor(stb
.st_rdev
);
447 /* add disk needs to know about containers */
448 if (st
->ss
->external
)
449 sra
->array
.level
= LEVEL_CONTAINER
;
451 if (info
.array
.state
& (1 << MD_SB_CLUSTERED
))
452 info
.disk
.state
|= (1 << MD_DISK_CLUSTER_ADD
);
454 err
= add_disk(mdfd
, st
, sra
, &info
);
455 if (err
< 0 && errno
== EBUSY
) {
456 /* could be another device present with the same
457 * disk.number. Find and reject any such
459 find_reject(mdfd
, st
, sra
, info
.disk
.number
,
460 info
.events
, c
->verbose
, chosen_name
);
461 err
= add_disk(mdfd
, st
, sra
, &info
);
463 if (err
< 0 && errno
== EINVAL
&&
464 info
.disk
.state
& (1<<MD_DISK_SYNC
)) {
465 /* Maybe it needs to be added as a spare */
466 if (policy_action_allows(policy
, st
->ss
->name
,
468 info
.disk
.state
&= ~(1<<MD_DISK_SYNC
);
469 err
= add_disk(mdfd
, st
, sra
, &info
);
472 pr_err("can only add %s to %s as a spare, and force-spare is not set.\n",
473 devname
, chosen_name
);
476 pr_err("failed to add %s to existing array %s: %s.\n",
477 devname
, chosen_name
, strerror(errno
));
481 info
.array
.working_disks
= 0;
482 for (d
= sra
->devs
; d
; d
=d
->next
)
483 info
.array
.working_disks
++;
486 if (strncmp(chosen_name
, "/dev/md/", 8) == 0)
487 md_devname
= chosen_name
+8;
489 md_devname
= chosen_name
;
491 printf("MD_DEVICE=%s\n", fd2devnm(mdfd
));
492 printf("MD_DEVNAME=%s\n", md_devname
);
493 printf("MD_FOREIGN=%s\n", trustworthy
== FOREIGN
? "yes" : "no");
496 /* 7/ Is there enough devices to possibly start the array? */
497 /* 7a/ if not, finish with success. */
498 if (info
.array
.level
== LEVEL_CONTAINER
) {
500 /* Try to assemble within the container */
501 sysfs_uevent(sra
, "change");
502 if (!c
->export
&& c
->verbose
>= 0)
503 pr_err("container %s now has %d device%s\n",
504 chosen_name
, info
.array
.working_disks
,
505 info
.array
.working_disks
== 1?"":"s");
506 wait_for(chosen_name
, mdfd
);
507 if (st
->ss
->external
)
508 strcpy(devnm
, fd2devnm(mdfd
));
509 if (st
->ss
->load_container
)
510 rv
= st
->ss
->load_container(st
, mdfd
, NULL
);
514 rv
= Incremental_container(st
, chosen_name
, c
, NULL
);
516 /* after spare is added, ping monitor for external metadata
517 * so that it can eg. try to rebuild degraded array */
518 if (st
->ss
->external
)
523 /* We have added something to the array, so need to re-read the
524 * state. Eventually this state should be kept up-to-date as
528 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
529 GET_OFFSET
| GET_SIZE
));
530 active_disks
= count_active(st
, sra
, mdfd
, &avail
, &info
);
532 journal_device_missing
= (info
.journal_device_required
) && (info
.journal_clean
== 0);
534 if (info
.consistency_policy
== CONSISTENCY_POLICY_PPL
)
535 info
.array
.state
|= 1;
537 if (enough(info
.array
.level
, info
.array
.raid_disks
,
538 info
.array
.layout
, info
.array
.state
& 1, avail
) == 0) {
540 printf("MD_STARTED=no\n");
541 } else if (c
->verbose
>= 0)
542 pr_err("%s attached to %s, not enough to start (%d).\n",
543 devname
, chosen_name
, active_disks
);
549 /* - if number of OK devices match expected, or -R and there */
551 /* + add any bitmap file */
552 /* + start the array (auto-readonly). */
554 if (md_get_array_info(mdfd
, &ainf
) == 0) {
556 printf("MD_STARTED=already\n");
557 } else if (c
->verbose
>= 0)
558 pr_err("%s attached to %s which is already active.\n",
559 devname
, chosen_name
);
565 if (c
->runstop
> 0 || (!journal_device_missing
&& active_disks
>= info
.array
.working_disks
)) {
567 /* Let's try to start it */
569 if (journal_device_missing
)
570 pr_err("Trying to run with missing journal device\n");
571 if (info
.reshape_active
&& !(info
.reshape_active
& RESHAPE_NO_BACKUP
)) {
572 pr_err("%s: This array is being reshaped and cannot be started\n",
574 cont_err("by --incremental. Please use --assemble\n");
577 if (match
&& match
->bitmap_file
) {
578 int bmfd
= open(match
->bitmap_file
, O_RDWR
);
580 pr_err("Could not open bitmap file %s.\n",
584 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
586 pr_err("Failed to set bitmapfile for %s.\n",
592 /* Need to remove from the array any devices which
593 * 'count_active' discerned were too old or inappropriate
595 for (d
= sra
? sra
->devs
: NULL
; d
; d
= d
->next
)
596 if (d
->disk
.state
& (1<<MD_DISK_REMOVED
))
597 remove_disk(mdfd
, st
, sra
, d
);
599 if ((sra
== NULL
|| active_disks
>= info
.array
.working_disks
) &&
600 trustworthy
!= FOREIGN
)
601 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
603 rv
= sysfs_set_str(sra
, NULL
,
604 "array_state", "read-auto");
605 /* Array might be O_EXCL which will interfere with
606 * fsck and mount. So re-open without O_EXCL.
611 printf("MD_STARTED=yes\n");
612 } else if (c
->verbose
>= 0)
613 pr_err("%s attached to %s, which has been started.\n",
614 devname
, chosen_name
);
616 wait_for(chosen_name
, mdfd
);
617 /* We just started the array, so some devices
618 * might have been evicted from the array
619 * because their event counts were too old.
620 * If the action=re-add policy is in-force for
621 * those devices we should re-add them now.
623 for (dsk
= sra
->devs
; dsk
; dsk
= dsk
->next
) {
624 if (disk_action_allows(dsk
, st
->ss
->name
,
626 add_disk(mdfd
, st
, sra
, dsk
) == 0)
627 pr_err("%s re-added to %s\n",
628 dsk
->sys_name
, chosen_name
);
631 pr_err("%s attached to %s, but failed to start: %s.\n",
632 devname
, chosen_name
, strerror(errno
));
637 printf("MD_STARTED=unsafe\n");
638 } else if (journal_device_missing
) {
639 pr_err("Journal device is missing, not safe to start yet.\n");
640 } else if (c
->verbose
>= 0)
641 pr_err("%s attached to %s, not enough to start safely.\n",
642 devname
, chosen_name
);
652 dev_policy_free(policy
);
660 static void find_reject(int mdfd
, struct supertype
*st
, struct mdinfo
*sra
,
661 int number
, __u64 events
, int verbose
,
664 /* Find a device attached to this array with a disk.number of number
665 * and events less than the passed events, and remove the device.
669 if (md_array_active(mdfd
))
670 return; /* not safe to remove from active arrays
671 * without thinking more */
673 for (d
= sra
->devs
; d
; d
= d
->next
) {
674 char dn
[24]; // 2*11 bytes for ints (including sign) + colon + null byte
677 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
678 dfd
= dev_open(dn
, O_RDONLY
);
681 if (st
->ss
->load_super(st
, dfd
, NULL
)) {
685 st
->ss
->getinfo_super(st
, &info
, NULL
);
686 st
->ss
->free_super(st
);
689 if (info
.disk
.number
!= number
|| info
.events
>= events
)
692 if (d
->disk
.raid_disk
> -1)
693 sysfs_set_str(sra
, d
, "slot", "none");
694 if (sysfs_set_str(sra
, d
, "state", "remove") == 0)
696 pr_err("removing old device %s from %s\n",
697 d
->sys_name
+4, array_name
);
701 static int count_active(struct supertype
*st
, struct mdinfo
*sra
,
702 int mdfd
, char **availp
,
703 struct mdinfo
*bestinfo
)
705 /* count how many devices in sra think they are active */
709 __u64 max_events
= 0;
721 for (d
= sra
->devs
; d
; d
= d
->next
)
723 for (d
= sra
->devs
, devnum
= 0 ; d
; d
= d
->next
, devnum
++) {
729 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
730 dfd
= dev_open(dn
, O_RDONLY
);
733 ok
= st
->ss
->load_super(st
, dfd
, NULL
);
738 info
.array
.raid_disks
= raid_disks
;
739 st
->ss
->getinfo_super(st
, &info
, devmap
+ raid_disks
* devnum
);
740 if (info
.disk
.raid_disk
== MD_DISK_ROLE_JOURNAL
)
741 bestinfo
->journal_clean
= 1;
743 raid_disks
= info
.array
.raid_disks
;
744 avail
= xcalloc(raid_disks
, 1);
747 best
= xcalloc(raid_disks
, sizeof(int));
748 devmap
= xcalloc(raid_disks
, numdevs
);
750 st
->ss
->getinfo_super(st
, &info
, devmap
);
753 if (info
.disk
.state
& (1<<MD_DISK_SYNC
))
757 max_events
= info
.events
;
758 avail
[info
.disk
.raid_disk
] = 2;
759 best
[info
.disk
.raid_disk
] = devnum
;
760 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
761 } else if (info
.events
== max_events
) {
762 avail
[info
.disk
.raid_disk
] = 2;
763 best
[info
.disk
.raid_disk
] = devnum
;
764 } else if (info
.events
== max_events
-1) {
765 if (avail
[info
.disk
.raid_disk
] == 0) {
766 avail
[info
.disk
.raid_disk
] = 1;
767 best
[info
.disk
.raid_disk
] = devnum
;
769 } else if (info
.events
< max_events
- 1)
771 else if (info
.events
== max_events
+1) {
773 max_events
= info
.events
;
774 for (i
= 0; i
< raid_disks
; i
++)
777 avail
[info
.disk
.raid_disk
] = 2;
778 best
[info
.disk
.raid_disk
] = devnum
;
779 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
780 } else { /* info.events much bigger */
781 memset(avail
, 0, raid_disks
);
782 max_events
= info
.events
;
783 avail
[info
.disk
.raid_disk
] = 2;
784 best
[info
.disk
.raid_disk
] = devnum
;
785 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
787 } else if (info
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
789 st
->ss
->free_super(st
);
794 /* We need to reject any device that thinks the best device is
795 * failed or missing */
796 for (b
= 0; b
< raid_disks
; b
++)
800 for (i
= 0 ; i
< raid_disks
; i
++) {
801 if (i
!= b
&& avail
[i
])
802 if (devmap
[raid_disks
* best
[i
] + b
] == 0) {
803 /* This device thinks 'b' is failed -
806 for (d
=sra
->devs
; devnum
; d
= d
->next
)
808 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
814 /* Also need to reject any spare device with an event count that
817 for (d
= sra
->devs
; d
; d
= d
->next
) {
818 if (!(d
->disk
.state
& (1<<MD_DISK_SYNC
)) &&
819 d
->events
> max_events
)
820 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
824 return cnt
+ replcnt
;
827 /* test if container has degraded member(s) */
828 static int container_members_max_degradation(struct map_ent
*map
, struct map_ent
*me
)
830 mdu_array_info_t array
;
832 int max_degraded
= 0;
834 for(; map
; map
= map
->next
) {
835 if (!metadata_container_matches(map
->metadata
, me
->devnm
))
837 afd
= open_dev(map
->devnm
);
840 /* most accurate information regarding array degradation */
841 if (md_get_array_info(afd
, &array
) >= 0) {
842 int degraded
= array
.raid_disks
- array
.active_disks
-
844 if (degraded
> max_degraded
)
845 max_degraded
= degraded
;
849 return (max_degraded
);
852 static int array_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
853 struct map_ent
*target
, int bare
,
854 struct supertype
*st
, int verbose
)
856 /* This device doesn't have any md metadata
857 * The device policy allows 'spare' and if !bare, it allows spare-same-slot.
858 * If 'st' is not set, then we only know that some metadata allows this,
859 * others possibly don't.
860 * So look for a container or array to attach the device to.
861 * Prefer 'target' if that is set and the array is found.
863 * If st is set, then only arrays of that type are considered
864 * Return 0 on success, or some exit code on failure, probably 1.
868 struct map_ent
*mp
, *map
= NULL
;
869 struct mdinfo
*chosen
= NULL
;
872 if (fstat(dfd
, &stb
) != 0)
876 * Now we need to find a suitable array to add this to.
877 * We only accept arrays that:
879 * - are in the same domains as the device
880 * - are of an size for which the device will be useful
881 * and we choose the one that is the most degraded
884 if (map_lock(&map
)) {
885 pr_err("failed to get exclusive lock on mapfile\n");
888 for (mp
= map
; mp
; mp
= mp
->next
) {
889 struct supertype
*st2
;
890 struct domainlist
*dl
= NULL
;
892 unsigned long long devsize
;
893 unsigned long long component_size
= 0;
895 if (is_subarray(mp
->metadata
))
898 st2
= st
->ss
->match_metadata_desc(mp
->metadata
);
900 (st
->minor_version
>= 0 &&
901 st
->minor_version
!= st2
->minor_version
)) {
903 pr_err("not adding %s to %s as metadata type doesn't match\n",
910 sra
= sysfs_read(-1, mp
->devnm
,
911 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
912 GET_DEGRADED
|GET_COMPONENT
|GET_VERSION
);
914 /* Probably a container - no degraded info */
915 sra
= sysfs_read(-1, mp
->devnm
,
916 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
917 GET_COMPONENT
|GET_VERSION
);
919 sra
->array
.failed_disks
= -1;
926 for(i
= 0; !st2
&& superlist
[i
]; i
++)
927 st2
= superlist
[i
]->match_metadata_desc(
931 pr_err("not adding %s to %s as metadata not recognised.\n",
935 /* Need to double check the 'act_spare' permissions applies
938 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
940 if (!bare
&& !policy_action_allows(pol
, st2
->ss
->name
,
941 act_spare_same_slot
))
945 /* update number of failed disks for mostly degraded
946 * container member */
947 if (sra
->array
.failed_disks
== -1)
948 sra
->array
.failed_disks
= container_members_max_degradation(map
, mp
);
950 get_dev_size(dfd
, NULL
, &devsize
);
951 if (sra
->component_size
== 0) {
952 /* true for containers, here we must read superblock
953 * to obtain minimum spare size */
954 struct supertype
*st3
= dup_super(st2
);
955 int mdfd
= open_dev(mp
->devnm
);
960 if (st3
->ss
->load_container
&&
961 !st3
->ss
->load_container(st3
, mdfd
, mp
->path
)) {
962 component_size
= st3
->ss
->min_acceptable_spare_size(st3
);
963 st3
->ss
->free_super(st3
);
968 if ((sra
->component_size
> 0 &&
969 st2
->ss
->avail_size(st2
, devsize
,
970 sra
->devs
? sra
->devs
->data_offset
:
972 sra
->component_size
) ||
973 (sra
->component_size
== 0 && devsize
< component_size
)) {
975 pr_err("not adding %s to %s as it is too small\n",
979 /* test against target.
980 * If 'target' is set and 'bare' is false, we only accept
981 * arrays/containers that match 'target'.
982 * If 'target' is set and 'bare' is true, we prefer the
983 * array which matches 'target'.
984 * target is considered only if we deal with degraded array
986 if (target
&& policy_action_allows(pol
, st2
->ss
->name
,
987 act_spare_same_slot
)) {
988 if (strcmp(target
->metadata
, mp
->metadata
) == 0 &&
989 memcmp(target
->uuid
, mp
->uuid
,
990 sizeof(target
->uuid
)) == 0 &&
991 sra
->array
.failed_disks
> 0) {
992 /* This is our target!! */
996 /* skip to end so we don't check any more */
1001 /* not our target */
1006 dl
= domain_from_array(sra
, st2
->ss
->name
);
1007 if (domain_test(dl
, pol
, st2
->ss
->name
) != 1) {
1008 /* domain test fails */
1010 pr_err("not adding %s to %s as it is not in a compatible domain\n",
1015 /* all tests passed, OK to add to this array */
1019 } else if (chosen
->array
.failed_disks
< sra
->array
.failed_disks
) {
1032 /* add current device to chosen array as a spare */
1033 int mdfd
= open_dev(chosen
->sys_name
);
1035 struct mddev_dev devlist
;
1036 char chosen_devname
[24]; // 2*11 for int (including signs) + colon + null
1037 devlist
.next
= NULL
;
1039 devlist
.writemostly
= FlagDefault
;
1040 devlist
.failfast
= FlagDefault
;
1041 devlist
.devname
= chosen_devname
;
1042 sprintf(chosen_devname
, "%d:%d", major(stb
.st_rdev
),
1043 minor(stb
.st_rdev
));
1044 devlist
.disposition
= 'a';
1047 rv
= Manage_subdevs(chosen
->sys_name
, mdfd
, &devlist
,
1053 pr_err("added %s as spare for %s\n",
1054 devname
, chosen
->sys_name
);
1056 pr_err("failed to add %s as spare for %s\n",
1057 devname
, chosen
->sys_name
);
1065 static int partition_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1066 struct supertype
*st
, int verbose
)
1068 /* we know that at least one partition virtual-metadata is
1069 * allowed to incorporate spares like this device. We need to
1070 * find a suitable device to copy partition information from.
1072 * Getting a list of all disk (not partition) devices is
1073 * slightly non-trivial. We could look at /sys/block, but
1074 * that is theoretically due to be removed. Maybe best to use
1075 * /dev/disk/by-path/?* and ignore names ending '-partNN' as
1076 * we depend on this directory of 'path' info. But that fails
1077 * to find loop devices and probably others. Maybe don't
1078 * worry about that, they aren't the real target.
1080 * So: check things in /dev/disk/by-path to see if they are in
1081 * a compatible domain, then load the partition table and see
1082 * if it is OK for the new device, and choose the largest
1083 * partition table that fits.
1087 char *chosen
= NULL
;
1088 unsigned long long chosen_size
= 0;
1089 struct supertype
*chosen_st
= NULL
;
1092 dir
= opendir("/dev/disk/by-path");
1095 while ((de
= readdir(dir
)) != NULL
) {
1097 struct dev_policy
*pol2
= NULL
;
1098 struct domainlist
*domlist
= NULL
;
1101 struct supertype
*st2
= NULL
;
1102 char *devname
= NULL
;
1103 unsigned long long devsectors
;
1105 if (de
->d_ino
== 0 || de
->d_name
[0] == '.' ||
1106 (de
->d_type
!= DT_LNK
&& de
->d_type
!= DT_UNKNOWN
))
1109 ep
= de
->d_name
+ strlen(de
->d_name
);
1110 while (ep
> de
->d_name
&&
1113 if (ep
> de
->d_name
+ 5 &&
1114 strncmp(ep
-5, "-part", 5) == 0)
1115 /* This is a partition - skip it */
1118 pol2
= path_policy(de
->d_name
, type_disk
);
1120 domain_merge(&domlist
, pol2
, st
? st
->ss
->name
: NULL
);
1121 if (domain_test(domlist
, pol
, st
? st
->ss
->name
: NULL
) != 1)
1122 /* new device is incompatible with this device. */
1125 domain_free(domlist
);
1128 if (asprintf(&devname
, "/dev/disk/by-path/%s", de
->d_name
) != 1) {
1132 fd
= open(devname
, O_RDONLY
);
1135 if (get_dev_size(fd
, devname
, &devsectors
) == 0)
1140 st2
= dup_super(st
);
1142 st2
= guess_super_type(fd
, guess_partitions
);
1143 if (st2
== NULL
|| st2
->ss
->load_super(st2
, fd
, NULL
) < 0)
1145 st2
->ignore_hw_compat
= 0;
1148 /* Check domain policy again, this time referring to metadata */
1149 domain_merge(&domlist
, pol2
, st2
->ss
->name
);
1150 if (domain_test(domlist
, pol
, st2
->ss
->name
) != 1)
1151 /* Incompatible devices for this metadata type */
1153 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
1154 /* Some partition types allow sparing, but not
1160 st2
->ss
->getinfo_super(st2
, &info
, NULL
);
1161 if (info
.component_size
> devsectors
)
1162 /* This partitioning doesn't fit in the device */
1165 /* This is an acceptable device to copy partition
1166 * metadata from. We could just stop here, but I
1167 * think I want to keep looking incase a larger
1168 * metadata which makes better use of the device can
1171 if (chosen
== NULL
|| chosen_size
< info
.component_size
) {
1172 chosen_size
= info
.component_size
;
1177 chosen_st
->ss
->free_super(chosen_st
);
1186 domain_free(domlist
);
1187 dev_policy_free(pol2
);
1189 st2
->ss
->free_super(st2
);
1201 /* 'chosen' is the best device we can find. Let's write its
1202 * metadata to devname dfd is read-only so don't use that
1204 fd
= open(devname
, O_RDWR
);
1206 chosen_st
->ss
->store_super(chosen_st
, fd
);
1210 chosen_st
->ss
->free_super(chosen_st
);
1215 static int is_bare(int dfd
)
1217 unsigned long long size
= 0;
1218 char bufpad
[4096 + 4096];
1219 char *buf
= (char*)(((long)bufpad
+ 4096) & ~4095);
1221 if (lseek(dfd
, 0, SEEK_SET
) != 0 ||
1222 read(dfd
, buf
, 4096) != 4096)
1225 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1227 if (memcmp(buf
, buf
+1, 4095) != 0)
1230 /* OK, first 4K appear blank, try the end. */
1231 get_dev_size(dfd
, NULL
, &size
);
1232 if (lseek(dfd
, size
-4096, SEEK_SET
) < 0 ||
1233 read(dfd
, buf
, 4096) != 4096)
1236 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1238 if (memcmp(buf
, buf
+1, 4095) != 0)
1244 /* adding a spare to a regular array is quite different from adding one to
1245 * a set-of-partitions virtual array.
1246 * This function determines which is worth trying and tries as appropriate.
1247 * Arrays are given priority over partitions.
1249 static int try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1250 struct map_ent
*target
,
1251 struct supertype
*st
, int verbose
)
1256 int partitions_ok
= 0;
1260 /* Can only add a spare if device has at least one domain */
1261 if (pol_find(pol
, pol_domain
) == NULL
)
1263 /* And only if some action allows spares */
1264 if (!policy_action_allows(pol
, st
?st
->ss
->name
:NULL
, act_spare
))
1267 /* Now check if the device is bare.
1268 * bare devices can always be added as a spare
1269 * non-bare devices can only be added if spare-same-slot is permitted,
1270 * and this device is replacing a previous device - in which case 'target'
1273 if (!is_bare(dfd
)) {
1274 /* Must have a target and allow same_slot */
1275 /* Later - may allow force_spare without target */
1277 !policy_action_allows(pol
, st
?st
->ss
->name
:NULL
,
1278 act_spare_same_slot
)) {
1280 pr_err("%s is not bare, so not considering as a spare\n",
1288 /* It might be OK to add this device to an array - need to see
1289 * what arrays might be candidates.
1292 /* just try try 'array' or 'partition' based on this metadata */
1293 if (st
->ss
->add_to_super
)
1294 return array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1297 return partition_try_spare(devname
, dfdp
, pol
,
1300 /* No metadata was specified or found so options are open.
1301 * Check for whether any array metadata, or any partition metadata
1302 * might allow adding the spare. This check is just help to avoid
1303 * a more costly scan of all arrays when we can be sure that will
1306 for (i
= 0; (!arrays_ok
|| !partitions_ok
) && superlist
[i
] ; i
++) {
1307 if (superlist
[i
]->add_to_super
&& !arrays_ok
&&
1308 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1310 if (superlist
[i
]->add_to_super
== NULL
&& !partitions_ok
&&
1311 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1316 rv
= array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1318 if (rv
!= 0 && partitions_ok
)
1319 rv
= partition_try_spare(devname
, dfdp
, pol
, st
, verbose
);
1323 int IncrementalScan(struct context
*c
, char *devnm
)
1325 /* look at every device listed in the 'map' file.
1326 * If one is found that is not running then:
1327 * look in mdadm.conf for bitmap file.
1328 * if one exists, but array has none, add it.
1329 * try to start array in auto-readonly mode
1331 struct map_ent
*mapl
= NULL
;
1333 struct mddev_ident
*devs
, *mddev
;
1339 devs
= conf_get_ident(NULL
);
1342 for (me
= mapl
; me
; me
= me
->next
) {
1343 mdu_array_info_t array
;
1347 if (devnm
&& strcmp(devnm
, me
->devnm
) != 0)
1349 if (me
->metadata
[0] == '/') {
1355 /* member array, need to work on container */
1356 strncpy(container
, me
->metadata
+1, 32);
1358 sl
= strchr(container
, '/');
1365 mdfd
= open_dev(me
->devnm
);
1369 if (!isdigit(me
->metadata
[0])) {
1370 /* must be a container */
1371 struct supertype
*st
= super_by_fd(mdfd
, NULL
);
1373 struct map_ent
*map
= NULL
;
1375 if (st
&& st
->ss
->load_container
)
1376 ret
= st
->ss
->load_container(st
, mdfd
, NULL
);
1378 if (!ret
&& st
&& st
->ss
->container_content
) {
1380 pr_err("failed to get exclusive lock on mapfile\n");
1381 ret
= Incremental_container(st
, me
->path
, c
, only
);
1388 if (md_get_array_info(mdfd
, &array
) == 0 || errno
!= ENODEV
) {
1392 /* Ok, we can try this one. Maybe it needs a bitmap */
1393 for (mddev
= devs
; mddev
; mddev
= mddev
->next
)
1394 if (mddev
->devname
&& me
->path
&&
1395 devname_matches(mddev
->devname
, me
->path
))
1397 if (mddev
&& mddev
->bitmap_file
) {
1399 * Note: early kernels will wrongly fail this, so it
1405 bmfd
= open(mddev
->bitmap_file
, O_RDWR
);
1407 added
= ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
);
1410 if (c
->verbose
>= 0) {
1412 pr_err("Added bitmap %s to %s\n",
1413 mddev
->bitmap_file
, me
->path
);
1414 else if (errno
!= EEXIST
)
1415 pr_err("Failed to add bitmap to %s: %s\n",
1416 me
->path
, strerror(errno
));
1419 /* FIXME check for reshape_active and consider not
1422 sra
= sysfs_read(mdfd
, NULL
, 0);
1424 if (sysfs_set_str(sra
, NULL
,
1425 "array_state", "read-auto") == 0) {
1426 if (c
->verbose
>= 0)
1427 pr_err("started array %s\n",
1428 me
->path
?: me
->devnm
);
1430 pr_err("failed to start array %s: %s\n",
1431 me
->path
?: me
->devnm
,
1441 static char *container2devname(char *devname
)
1443 char *mdname
= NULL
;
1445 if (devname
[0] == '/') {
1446 int fd
= open(devname
, O_RDONLY
);
1448 mdname
= xstrdup(fd2devnm(fd
));
1453 struct map_ent
*mp
, *map
= NULL
;
1455 if (!parse_uuid(devname
, uuid
))
1457 mp
= map_by_uuid(&map
, uuid
);
1459 mdname
= xstrdup(mp
->devnm
);
1466 static int Incremental_container(struct supertype
*st
, char *devname
,
1467 struct context
*c
, char *only
)
1469 /* Collect the contents of this container and for each
1470 * array, choose a device name and assemble the array.
1473 struct mdinfo
*list
;
1475 struct map_ent
*map
= NULL
;
1478 struct mddev_ident
*match
;
1480 struct domainlist
*domains
;
1481 struct map_ent
*smp
;
1488 st
->ss
->getinfo_super(st
, &info
, NULL
);
1490 if ((c
->runstop
> 0 && info
.container_enough
>= 0) ||
1491 info
.container_enough
> 0)
1495 printf("MD_STARTED=no\n");
1496 } else if (c
->verbose
)
1497 pr_err("not enough devices to start the container\n");
1501 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
1502 if (match
== NULL
&& rv
== 2)
1505 /* Need to compute 'trustworthy' */
1507 trustworthy
= LOCAL
;
1508 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
1509 trustworthy
= LOCAL
;
1510 else if (st
->ss
->match_home(st
, "any") == 1)
1511 trustworthy
= LOCAL
;
1513 trustworthy
= FOREIGN
;
1515 list
= st
->ss
->container_content(st
, NULL
);
1516 /* when nothing to activate - quit */
1519 printf("MD_STARTED=nothing\n");
1523 for (ra
= list
; ra
; ra
= ra
->next
) {
1525 char chosen_name
[1024];
1527 struct mddev_ident
*match
= NULL
;
1530 /* do not activate arrays blocked by metadata handler */
1531 if (ra
->array
.state
& (1 << MD_SB_BLOCK_VOLUME
)) {
1532 pr_err("Cannot activate array %s in %s.\n",
1533 ra
->text_version
, devname
);
1537 mp
= map_by_uuid(&map
, ra
->uuid
);
1540 mdfd
= open_dev(mp
->devnm
);
1542 strcpy(chosen_name
, mp
->path
);
1544 strcpy(chosen_name
, mp
->devnm
);
1547 /* Check in mdadm.conf for container == devname and
1548 * member == ra->text_version after second slash.
1550 char *sub
= strchr(ra
->text_version
+1, '/');
1551 struct mddev_ident
*array_list
;
1554 array_list
= conf_get_ident(NULL
);
1557 for(; array_list
; array_list
= array_list
->next
) {
1559 if (array_list
->member
== NULL
||
1560 array_list
->container
== NULL
)
1562 if (strcmp(array_list
->member
, sub
) != 0)
1564 if (array_list
->uuid_set
&&
1565 !same_uuid(ra
->uuid
, array_list
->uuid
, st
->ss
->swapuuid
))
1567 dn
= container2devname(array_list
->container
);
1570 if (strncmp(dn
, ra
->text_version
+1,
1572 ra
->text_version
[strlen(dn
)+1] != '/') {
1577 /* we have a match */
1580 pr_err("match found for member %s\n",
1581 array_list
->member
);
1585 if (match
&& match
->devname
&&
1586 strcasecmp(match
->devname
, "<ignore>") == 0) {
1588 pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
1589 match
->container
, match
->member
);
1593 trustworthy
= LOCAL
;
1595 mdfd
= create_mddev(match
? match
->devname
: NULL
,
1601 if (only
&& (!mp
|| strcmp(mp
->devnm
, only
) != 0))
1605 pr_err("failed to open %s: %s.\n",
1606 chosen_name
, strerror(errno
));
1610 assemble_container_content(st
, mdfd
, ra
, c
,
1611 chosen_name
, &result
);
1614 if (c
->export
&& result
) {
1616 printf("MD_STARTED");
1617 if (result
& INCR_NO
) {
1618 printf("%cno", sep
);
1621 if (result
& INCR_UNSAFE
) {
1622 printf("%cunsafe", sep
);
1625 if (result
& INCR_ALREADY
) {
1626 printf("%calready", sep
);
1629 if (result
& INCR_YES
) {
1630 printf("%cyes", sep
);
1636 /* don't move spares to container with volume being activated
1637 when all volumes are blocked */
1638 if (ra_all
== ra_blocked
)
1641 /* Now move all suitable spares from spare container */
1642 domains
= domain_from_array(list
, st
->ss
->name
);
1643 memcpy(suuid
, uuid_zero
, sizeof(int[4]));
1645 (smp
= map_by_uuid(&map
, suuid
)) != NULL
&&
1646 (sfd
= open(smp
->path
, O_RDONLY
)) >= 0) {
1647 /* spare container found */
1648 struct supertype
*sst
=
1649 super_imsm
.match_metadata_desc("imsm");
1650 struct mdinfo
*sinfo
;
1651 unsigned long long min_size
= 0;
1652 if (st
->ss
->min_acceptable_spare_size
)
1653 min_size
= st
->ss
->min_acceptable_spare_size(st
);
1654 if (!sst
->ss
->load_container(sst
, sfd
, NULL
)) {
1656 sinfo
= container_choose_spares(sst
, min_size
,
1659 sst
->ss
->free_super(sst
);
1662 struct mdinfo
*disks
= sinfo
->devs
;
1664 /* move spare from spare
1665 * container to currently
1671 makedev(disks
->disk
.major
,
1672 disks
->disk
.minor
)))
1674 disks
= disks
->next
;
1677 pr_err("Added %d spare%s to %s\n",
1678 count
, count
>1?"s":"", devname
);
1684 domain_free(domains
);
1688 static void run_udisks(char *arg1
, char *arg2
)
1693 execl("/usr/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1694 execl("/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1697 while (pid
> 0 && wait(&status
) != pid
)
1702 * IncrementalRemove - Attempt to see if the passed in device belongs to any
1703 * raid arrays, and if so first fail (if needed) and then remove the device.
1705 * @devname - The device we want to remove
1706 * @id_path - name as found in /dev/disk/by-path for this device
1708 * Note: the device name must be a kernel name like "sda", so
1709 * that we can find it in /proc/mdstat
1711 int IncrementalRemove(char *devname
, char *id_path
, int verbose
)
1715 struct mdstat_ent
*ent
;
1716 struct mddev_dev devlist
;
1721 dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
1723 if (strchr(devname
, '/')) {
1724 pr_err("incremental removal requires a kernel device name, not a file: %s\n", devname
);
1727 ent
= mdstat_by_component(devname
);
1730 pr_err("%s does not appear to be a component of any array\n", devname
);
1733 if (sysfs_init(&mdi
, -1, ent
->devnm
)) {
1734 pr_err("unable to initialize sysfs for: %s\n", devname
);
1737 mdfd
= open_dev_excl(ent
->devnm
);
1740 if (sysfs_get_str(&mdi
, NULL
, "array_state",
1741 buf
, sizeof(buf
)) > 0) {
1742 if (strncmp(buf
, "active", 6) == 0 ||
1743 strncmp(buf
, "clean", 5) == 0)
1744 sysfs_set_str(&mdi
, NULL
,
1745 "array_state", "read-auto");
1748 mdfd
= open_dev(ent
->devnm
);
1751 pr_err("Cannot open array %s!!\n", ent
->devnm
);
1757 struct map_ent
*map
= NULL
, *me
;
1758 me
= map_by_devnm(&map
, ent
->devnm
);
1760 policy_save_path(id_path
, me
);
1764 memset(&devlist
, 0, sizeof(devlist
));
1765 devlist
.devname
= devname
;
1766 devlist
.disposition
= 'f';
1767 /* for a container, we must fail each member array */
1768 if (ent
->metadata_version
&&
1769 strncmp(ent
->metadata_version
, "external:", 9) == 0) {
1770 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
1771 struct mdstat_ent
*memb
;
1772 for (memb
= mdstat
; memb
; memb
= memb
->next
)
1773 if (is_container_member(memb
, ent
->devnm
)) {
1774 int subfd
= open_dev(memb
->devnm
);
1776 rv
|= Manage_subdevs(
1778 &devlist
, verbose
, 0,
1783 free_mdstat(mdstat
);
1785 rv
|= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1786 verbose
, 0, NULL
, 0);
1788 /* Failed due to EBUSY, try to stop the array.
1789 * Give udisks a chance to unmount it first.
1791 int devid
= devnm2devid(ent
->devnm
);
1792 run_udisks("--unmount", map_dev(major(devid
),minor(devid
), 0));
1793 rv
= Manage_stop(ent
->devnm
, mdfd
, verbose
, 1);
1795 /* At least we can try to trigger a 'remove' */
1796 sysfs_uevent(&mdi
, "remove");
1799 pr_err("Fail to stop %s too.\n", ent
->devnm
);
1802 devlist
.disposition
= 'r';
1803 rv
= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1804 verbose
, 0, NULL
, 0);