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
;
108 struct createinfo
*ci
= conf_get_create_info();
110 if (stat(devname
, &stb
) < 0) {
112 pr_err("stat failed for %s: %s.\n",
113 devname
, strerror(errno
));
116 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
118 pr_err("%s is not a block device.\n",
122 dfd
= dev_open(devname
, O_RDONLY
);
125 pr_err("cannot open %s: %s.\n",
126 devname
, strerror(errno
));
129 /* If the device is a container, we do something very different */
130 if (must_be_container(dfd
)) {
132 st
= super_by_fd(dfd
, NULL
);
133 if (st
&& st
->ss
->load_container
)
134 rv
= st
->ss
->load_container(st
, dfd
, NULL
);
137 if (!rv
&& st
->ss
->container_content
) {
139 pr_err("failed to get exclusive lock on mapfile\n");
141 printf("MD_DEVNAME=%s\n", devname
);
142 rv
= Incremental_container(st
, devname
, c
, NULL
);
147 pr_err("%s is not part of an md array.\n",
152 /* 1/ Check if device is permitted by mdadm.conf */
154 for (;devlist
; devlist
= devlist
->next
)
155 if (conf_test_dev(devlist
->devname
))
158 devlist
= conf_get_devs();
159 for (;devlist
; devlist
= devlist
->next
) {
161 if (stat(devlist
->devname
, &st2
) == 0 &&
162 (st2
.st_mode
& S_IFMT
) == S_IFBLK
&&
163 st2
.st_rdev
== stb
.st_rdev
)
169 pr_err("%s not permitted by mdadm.conf.\n",
174 /* 2/ Find metadata, reject if none appropriate (check
175 * version/name from args) */
177 if (fstat(dfd
, &stb
) < 0) {
179 pr_err("fstat failed for %s: %s.\n",
180 devname
, strerror(errno
));
183 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
185 pr_err("%s is not a block device.\n",
190 dinfo
.disk
.major
= major(stb
.st_rdev
);
191 dinfo
.disk
.minor
= minor(stb
.st_rdev
);
193 policy
= disk_policy(&dinfo
);
194 have_target
= policy_check_path(&dinfo
, &target_array
);
196 if (st
== NULL
&& (st
= guess_super_type(dfd
, guess_array
)) == NULL
) {
198 pr_err("no recognisable superblock on %s.\n",
200 rv
= try_spare(devname
, &dfd
, policy
,
201 have_target
? &target_array
: NULL
,
205 st
->ignore_hw_compat
= 0;
207 if (st
->ss
->compare_super
== NULL
||
208 st
->ss
->load_super(st
, dfd
, c
->verbose
>= 0 ? devname
: NULL
)) {
210 pr_err("no RAID superblock on %s.\n",
212 rv
= try_spare(devname
, &dfd
, policy
,
213 have_target
? &target_array
: NULL
,
218 close (dfd
); dfd
= -1;
220 st
->ss
->getinfo_super(st
, &info
, NULL
);
222 /* 3/ Check if there is a match in mdadm.conf */
223 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
224 if (!match
&& rv
== 2)
227 if (match
&& match
->devname
228 && strcasecmp(match
->devname
, "<ignore>") == 0) {
230 pr_err("array containing %s is explicitly ignored by mdadm.conf\n",
235 /* 3a/ if not, check for homehost match. If no match, continue
236 * but don't trust the 'name' in the array. Thus a 'random' minor
237 * number will be assigned, and the device name will be based
241 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
243 else if (st
->ss
->match_home(st
, "any") == 1)
244 trustworthy
= LOCAL_ANY
;
246 trustworthy
= FOREIGN
;
248 if (!match
&& !conf_test_metadata(st
->ss
->name
, policy
,
249 (trustworthy
== LOCAL
))) {
251 pr_err("%s has metadata type %s for which auto-assembly is disabled\n",
252 devname
, st
->ss
->name
);
255 if (trustworthy
== LOCAL_ANY
)
258 /* There are three possible sources for 'autof': command line,
259 * ARRAY line in mdadm.conf, or CREATE line in mdadm.conf.
260 * ARRAY takes precedence, then command line, then
263 if (match
&& match
->autof
)
264 c
->autof
= match
->autof
;
266 c
->autof
= ci
->autof
;
268 name_to_use
= info
.name
;
269 if (name_to_use
[0] == 0 &&
270 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 sysfs_init(&info
, mdfd
, NULL
);
330 if (set_array_info(mdfd
, st
, &info
) != 0) {
331 pr_err("failed to set array info for %s: %s\n",
332 chosen_name
, strerror(errno
));
338 dinfo
.disk
.major
= major(stb
.st_rdev
);
339 dinfo
.disk
.minor
= minor(stb
.st_rdev
);
340 if (add_disk(mdfd
, st
, &info
, &dinfo
) != 0) {
341 pr_err("failed to add %s to new array %s: %s.\n",
342 devname
, chosen_name
, strerror(errno
));
343 ioctl(mdfd
, STOP_ARRAY
, 0);
347 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
348 GET_OFFSET
| GET_SIZE
));
350 if (!sra
|| !sra
->devs
|| sra
->devs
->disk
.raid_disk
>= 0) {
351 /* It really should be 'none' - must be old buggy
352 * kernel, and mdadm -I may not be able to complete.
355 ioctl(mdfd
, STOP_ARRAY
, NULL
);
356 pr_err("You have an old buggy kernel which cannot support\n --incremental reliably. Aborting.\n");
360 info
.array
.working_disks
= 1;
361 /* 6/ Make sure /var/run/mdadm.map contains this array. */
362 map_update(&map
, fd2devnm(mdfd
),
364 info
.uuid
, chosen_name
);
367 /* - check one drive in array to make sure metadata is a reasonably */
368 /* close match. Reject if not (e.g. different type) */
369 /* - add the device */
373 struct supertype
*st2
;
374 struct mdinfo info2
, *d
;
376 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
377 GET_OFFSET
| GET_SIZE
));
380 strcpy(chosen_name
, mp
->path
);
382 strcpy(chosen_name
, mp
->devnm
);
384 /* It is generally not OK to add non-spare drives to a
385 * running array as they are probably missing because
386 * they failed. However if runstop is 1, then the
387 * array was possibly started early and our best bet is
388 * to add this anyway.
389 * Also if action policy is re-add or better we allow
391 * This doesn't apply to containers as the 'non-spare'
392 * flag has a different meaning. The test has to happen
393 * at the device level there
395 if (!st
->ss
->external
396 && (info
.disk
.state
& (1<<MD_DISK_SYNC
)) != 0
397 && ! policy_action_allows(policy
, st
->ss
->name
,
400 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ainf
) == 0) {
401 pr_err("not adding %s to active array (without --run) %s\n",
402 devname
, chosen_name
);
412 sprintf(dn
, "%d:%d", sra
->devs
->disk
.major
,
413 sra
->devs
->disk
.minor
);
414 dfd2
= dev_open(dn
, O_RDONLY
);
416 pr_err("unable to open %s\n", devname
);
421 if (st2
->ss
->load_super(st2
, dfd2
, NULL
) ||
422 st
->ss
->compare_super(st
, st2
) != 0) {
423 pr_err("metadata mismatch between %s and chosen array %s\n",
424 devname
, chosen_name
);
430 st2
->ss
->getinfo_super(st2
, &info2
, NULL
);
431 st2
->ss
->free_super(st2
);
432 if (info
.array
.level
!= info2
.array
.level
||
433 memcmp(info
.uuid
, info2
.uuid
, 16) != 0 ||
434 info
.array
.raid_disks
!= info2
.array
.raid_disks
) {
435 pr_err("unexpected difference between %s and %s.\n",
436 chosen_name
, devname
);
441 info
.disk
.major
= major(stb
.st_rdev
);
442 info
.disk
.minor
= minor(stb
.st_rdev
);
443 /* add disk needs to know about containers */
444 if (st
->ss
->external
)
445 sra
->array
.level
= LEVEL_CONTAINER
;
446 err
= add_disk(mdfd
, st
, sra
, &info
);
447 if (err
< 0 && errno
== EBUSY
) {
448 /* could be another device present with the same
449 * disk.number. Find and reject any such
451 find_reject(mdfd
, st
, sra
, info
.disk
.number
,
452 info
.events
, c
->verbose
, chosen_name
);
453 err
= add_disk(mdfd
, st
, sra
, &info
);
455 if (err
< 0 && errno
== EINVAL
&&
456 info
.disk
.state
& (1<<MD_DISK_SYNC
)) {
457 /* Maybe it needs to be added as a spare */
458 if (policy_action_allows(policy
, st
->ss
->name
,
460 info
.disk
.state
&= ~(1<<MD_DISK_SYNC
);
461 err
= add_disk(mdfd
, st
, sra
, &info
);
464 pr_err("can only add %s to %s as a spare, and force-spare is not set.\n",
465 devname
, chosen_name
);
468 pr_err("failed to add %s to existing array %s: %s.\n",
469 devname
, chosen_name
, strerror(errno
));
473 info
.array
.working_disks
= 0;
474 for (d
= sra
->devs
; d
; d
=d
->next
)
475 info
.array
.working_disks
++;
478 if (strncmp(chosen_name
, "/dev/md/", 8) == 0)
479 md_devname
= chosen_name
+8;
481 md_devname
= chosen_name
;
483 printf("MD_DEVICE=%s\n", fd2devnm(mdfd
));
484 printf("MD_DEVNAME=%s\n", md_devname
);
485 printf("MD_FOREIGN=%s\n", trustworthy
== FOREIGN
? "yes" : "no");
488 /* 7/ Is there enough devices to possibly start the array? */
489 /* 7a/ if not, finish with success. */
490 if (info
.array
.level
== LEVEL_CONTAINER
) {
492 /* Try to assemble within the container */
493 sysfs_uevent(sra
, "change");
494 if (!c
->export
&& c
->verbose
>= 0)
495 pr_err("container %s now has %d device%s\n",
496 chosen_name
, info
.array
.working_disks
,
497 info
.array
.working_disks
== 1?"":"s");
498 wait_for(chosen_name
, mdfd
);
499 if (st
->ss
->external
)
500 strcpy(devnm
, fd2devnm(mdfd
));
501 if (st
->ss
->load_container
)
502 rv
= st
->ss
->load_container(st
, mdfd
, NULL
);
506 rv
= Incremental_container(st
, chosen_name
, c
, NULL
);
508 /* after spare is added, ping monitor for external metadata
509 * so that it can eg. try to rebuild degraded array */
510 if (st
->ss
->external
)
515 /* We have added something to the array, so need to re-read the
516 * state. Eventually this state should be kept up-to-date as
520 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
521 GET_OFFSET
| GET_SIZE
));
522 active_disks
= count_active(st
, sra
, mdfd
, &avail
, &info
);
523 if (enough(info
.array
.level
, info
.array
.raid_disks
,
524 info
.array
.layout
, info
.array
.state
& 1,
527 printf("MD_STARTED=no\n");
528 } else if (c
->verbose
>= 0)
529 pr_err("%s attached to %s, not enough to start (%d).\n",
530 devname
, chosen_name
, active_disks
);
536 /* - if number of OK devices match expected, or -R and there */
538 /* + add any bitmap file */
539 /* + start the array (auto-readonly). */
541 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ainf
) == 0) {
543 printf("MD_STARTED=already\n");
544 } else if (c
->verbose
>= 0)
545 pr_err("%s attached to %s which is already active.\n",
546 devname
, chosen_name
);
552 if (c
->runstop
> 0 || active_disks
>= info
.array
.working_disks
) {
554 /* Let's try to start it */
556 if (info
.reshape_active
&& !(info
.reshape_active
& RESHAPE_NO_BACKUP
)) {
557 pr_err("%s: This array is being reshaped and cannot be started\n",
559 cont_err("by --incremental. Please use --assemble\n");
562 if (match
&& match
->bitmap_file
) {
563 int bmfd
= open(match
->bitmap_file
, O_RDWR
);
565 pr_err("Could not open bitmap file %s.\n",
569 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
571 pr_err("Failed to set bitmapfile for %s.\n",
577 /* Need to remove from the array any devices which
578 * 'count_active' discerned were too old or inappropriate
580 for (d
= sra
? sra
->devs
: NULL
; d
; d
= d
->next
)
581 if (d
->disk
.state
& (1<<MD_DISK_REMOVED
))
582 remove_disk(mdfd
, st
, sra
, d
);
584 if ((sra
== NULL
|| active_disks
>= info
.array
.working_disks
)
585 && trustworthy
!= FOREIGN
)
586 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
588 rv
= sysfs_set_str(sra
, NULL
,
589 "array_state", "read-auto");
590 /* Array might be O_EXCL which will interfere with
591 * fsck and mount. So re-open without O_EXCL.
596 printf("MD_STARTED=yes\n");
597 } else if (c
->verbose
>= 0)
598 pr_err("%s attached to %s, which has been started.\n",
599 devname
, chosen_name
);
601 wait_for(chosen_name
, mdfd
);
602 /* We just started the array, so some devices
603 * might have been evicted from the array
604 * because their event counts were too old.
605 * If the action=re-add policy is in-force for
606 * those devices we should re-add them now.
608 for (dsk
= sra
->devs
; dsk
; dsk
= dsk
->next
) {
609 if (disk_action_allows(dsk
, st
->ss
->name
, act_re_add
) &&
610 add_disk(mdfd
, st
, sra
, dsk
) == 0)
611 pr_err("%s re-added to %s\n",
612 dsk
->sys_name
, chosen_name
);
615 pr_err("%s attached to %s, but failed to start: %s.\n",
616 devname
, chosen_name
, strerror(errno
));
621 printf("MD_STARTED=unsafe\n");
622 } else if (c
->verbose
>= 0)
623 pr_err("%s attached to %s, not enough to start safely.\n",
624 devname
, chosen_name
);
634 dev_policy_free(policy
);
643 static void find_reject(int mdfd
, struct supertype
*st
, struct mdinfo
*sra
,
644 int number
, __u64 events
, int verbose
,
647 /* Find a device attached to this array with a disk.number of number
648 * and events less than the passed events, and remove the device.
653 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ra
) == 0)
654 return; /* not safe to remove from active arrays
655 * without thinking more */
657 for (d
= sra
->devs
; d
; d
= d
->next
) {
661 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
662 dfd
= dev_open(dn
, O_RDONLY
);
665 if (st
->ss
->load_super(st
, dfd
, NULL
)) {
669 st
->ss
->getinfo_super(st
, &info
, NULL
);
670 st
->ss
->free_super(st
);
673 if (info
.disk
.number
!= number
||
674 info
.events
>= events
)
677 if (d
->disk
.raid_disk
> -1)
678 sysfs_set_str(sra
, d
, "slot", "none");
679 if (sysfs_set_str(sra
, d
, "state", "remove") == 0)
681 pr_err("removing old device %s from %s\n",
682 d
->sys_name
+4, array_name
);
686 static int count_active(struct supertype
*st
, struct mdinfo
*sra
,
687 int mdfd
, char **availp
,
688 struct mdinfo
*bestinfo
)
690 /* count how many devices in sra think they are active */
694 __u64 max_events
= 0;
706 for (d
= sra
->devs
; d
; d
= d
->next
)
708 for (d
= sra
->devs
, devnum
= 0 ; d
; d
= d
->next
, devnum
++) {
714 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
715 dfd
= dev_open(dn
, O_RDONLY
);
718 ok
= st
->ss
->load_super(st
, dfd
, NULL
);
722 info
.array
.raid_disks
= raid_disks
;
723 st
->ss
->getinfo_super(st
, &info
, devmap
+ raid_disks
* devnum
);
725 raid_disks
= info
.array
.raid_disks
;
726 avail
= xcalloc(raid_disks
, 1);
729 best
= xcalloc(raid_disks
, sizeof(int));
730 devmap
= xcalloc(raid_disks
, numdevs
);
732 st
->ss
->getinfo_super(st
, &info
, devmap
);
735 if (info
.disk
.state
& (1<<MD_DISK_SYNC
))
739 max_events
= info
.events
;
740 avail
[info
.disk
.raid_disk
] = 2;
741 best
[info
.disk
.raid_disk
] = devnum
;
742 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
743 } else if (info
.events
== max_events
) {
744 avail
[info
.disk
.raid_disk
] = 2;
745 best
[info
.disk
.raid_disk
] = devnum
;
746 } else if (info
.events
== max_events
-1) {
747 if (avail
[info
.disk
.raid_disk
] == 0) {
748 avail
[info
.disk
.raid_disk
] = 1;
749 best
[info
.disk
.raid_disk
] = devnum
;
751 } else if (info
.events
< max_events
- 1)
753 else if (info
.events
== max_events
+1) {
755 max_events
= info
.events
;
756 for (i
= 0; i
< raid_disks
; i
++)
759 avail
[info
.disk
.raid_disk
] = 2;
760 best
[info
.disk
.raid_disk
] = devnum
;
761 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
762 } else { /* info.events much bigger */
763 memset(avail
, 0, raid_disks
);
764 max_events
= info
.events
;
765 avail
[info
.disk
.raid_disk
] = 2;
766 best
[info
.disk
.raid_disk
] = devnum
;
767 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
769 } else if (info
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
771 st
->ss
->free_super(st
);
775 /* We need to reject any device that thinks the best device is
776 * failed or missing */
777 for (b
= 0; b
< raid_disks
; b
++)
781 for (i
= 0 ; i
< raid_disks
; i
++) {
782 if (i
!= b
&& avail
[i
])
783 if (devmap
[raid_disks
* best
[i
] + b
] == 0) {
784 /* This device thinks 'b' is failed -
787 for (d
=sra
->devs
; devnum
; d
= d
->next
)
789 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
795 /* Also need to reject any spare device with an event count that
798 for (d
= sra
->devs
; d
; d
= d
->next
) {
799 if (!(d
->disk
.state
& (1<<MD_DISK_SYNC
)) &&
800 d
->events
> max_events
)
801 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
805 return cnt
+ replcnt
;
808 /* test if container has degraded member(s) */
809 static int container_members_max_degradation(struct map_ent
*map
, struct map_ent
*me
)
811 mdu_array_info_t array
;
813 int max_degraded
= 0;
815 for(; map
; map
= map
->next
) {
816 if (!metadata_container_matches(map
->metadata
, me
->devnm
))
818 afd
= open_dev(map
->devnm
);
821 /* most accurate information regarding array degradation */
822 if (ioctl(afd
, GET_ARRAY_INFO
, &array
) >= 0) {
823 int degraded
= array
.raid_disks
- array
.active_disks
-
825 if (degraded
> max_degraded
)
826 max_degraded
= degraded
;
830 return (max_degraded
);
833 static int array_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
834 struct map_ent
*target
, int bare
,
835 struct supertype
*st
, int verbose
)
837 /* This device doesn't have any md metadata
838 * The device policy allows 'spare' and if !bare, it allows spare-same-slot.
839 * If 'st' is not set, then we only know that some metadata allows this,
840 * others possibly don't.
841 * So look for a container or array to attach the device to.
842 * Prefer 'target' if that is set and the array is found.
844 * If st is set, then only arrays of that type are considered
845 * Return 0 on success, or some exit code on failure, probably 1.
849 struct map_ent
*mp
, *map
= NULL
;
850 struct mdinfo
*chosen
= NULL
;
853 if (fstat(dfd
, &stb
) != 0)
857 * Now we need to find a suitable array to add this to.
858 * We only accept arrays that:
860 * - are in the same domains as the device
861 * - are of an size for which the device will be useful
862 * and we choose the one that is the most degraded
865 if (map_lock(&map
)) {
866 pr_err("failed to get exclusive lock on mapfile\n");
869 for (mp
= map
; mp
; mp
= mp
->next
) {
870 struct supertype
*st2
;
871 struct domainlist
*dl
= NULL
;
873 unsigned long long devsize
;
874 unsigned long long component_size
= 0;
876 if (is_subarray(mp
->metadata
))
879 st2
= st
->ss
->match_metadata_desc(mp
->metadata
);
881 (st
->minor_version
>= 0 &&
882 st
->minor_version
!= st2
->minor_version
)) {
884 pr_err("not adding %s to %s as metadata type doesn't match\n",
891 sra
= sysfs_read(-1, mp
->devnm
,
892 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
893 GET_DEGRADED
|GET_COMPONENT
|GET_VERSION
);
895 /* Probably a container - no degraded info */
896 sra
= sysfs_read(-1, mp
->devnm
,
897 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
898 GET_COMPONENT
|GET_VERSION
);
900 sra
->array
.failed_disks
= -1;
907 for(i
= 0; !st2
&& superlist
[i
]; i
++)
908 st2
= superlist
[i
]->match_metadata_desc(
912 pr_err("not adding %s to %s as metadata not recognised.\n",
916 /* Need to double check the 'act_spare' permissions applies
919 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
921 if (!bare
&& !policy_action_allows(pol
, st2
->ss
->name
,
922 act_spare_same_slot
))
926 /* update number of failed disks for mostly degraded
927 * container member */
928 if (sra
->array
.failed_disks
== -1)
929 sra
->array
.failed_disks
= container_members_max_degradation(map
, mp
);
931 get_dev_size(dfd
, NULL
, &devsize
);
932 if (sra
->component_size
== 0) {
933 /* true for containers, here we must read superblock
934 * to obtain minimum spare size */
935 struct supertype
*st3
= dup_super(st2
);
936 int mdfd
= open_dev(mp
->devnm
);
941 if (st3
->ss
->load_container
&&
942 !st3
->ss
->load_container(st3
, mdfd
, mp
->path
)) {
943 component_size
= st3
->ss
->min_acceptable_spare_size(st3
);
944 st3
->ss
->free_super(st3
);
949 if ((sra
->component_size
> 0 &&
950 st2
->ss
->avail_size(st2
, devsize
,
952 ? sra
->devs
->data_offset
954 < sra
->component_size
)
956 (sra
->component_size
== 0 && devsize
< component_size
)) {
958 pr_err("not adding %s to %s as it is too small\n",
962 /* test against target.
963 * If 'target' is set and 'bare' is false, we only accept
964 * arrays/containers that match 'target'.
965 * If 'target' is set and 'bare' is true, we prefer the
966 * array which matches 'target'.
967 * target is considered only if we deal with degraded array
969 if (target
&& policy_action_allows(pol
, st2
->ss
->name
,
970 act_spare_same_slot
)) {
971 if (strcmp(target
->metadata
, mp
->metadata
) == 0 &&
972 memcmp(target
->uuid
, mp
->uuid
,
973 sizeof(target
->uuid
)) == 0 &&
974 sra
->array
.failed_disks
> 0) {
975 /* This is our target!! */
980 /* skip to end so we don't check any more */
990 dl
= domain_from_array(sra
, st2
->ss
->name
);
991 if (domain_test(dl
, pol
, st2
->ss
->name
) != 1) {
992 /* domain test fails */
994 pr_err("not adding %s to %s as it is not in a compatible domain\n",
999 /* all tests passed, OK to add to this array */
1003 } else if (chosen
->array
.failed_disks
< sra
->array
.failed_disks
) {
1017 /* add current device to chosen array as a spare */
1018 int mdfd
= open_dev(chosen
->sys_name
);
1020 struct mddev_dev devlist
;
1022 devlist
.next
= NULL
;
1024 devlist
.writemostly
= 0;
1025 devlist
.devname
= devname
;
1026 sprintf(devname
, "%d:%d", major(stb
.st_rdev
),
1027 minor(stb
.st_rdev
));
1028 devlist
.disposition
= 'a';
1031 rv
= Manage_subdevs(chosen
->sys_name
, mdfd
, &devlist
,
1037 pr_err("added %s as spare for %s\n",
1038 devname
, chosen
->sys_name
);
1040 pr_err("failed to add %s as spare for %s\n",
1041 devname
, chosen
->sys_name
);
1049 static int partition_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1050 struct supertype
*st
, int verbose
)
1052 /* we know that at least one partition virtual-metadata is
1053 * allowed to incorporate spares like this device. We need to
1054 * find a suitable device to copy partition information from.
1056 * Getting a list of all disk (not partition) devices is
1057 * slightly non-trivial. We could look at /sys/block, but
1058 * that is theoretically due to be removed. Maybe best to use
1059 * /dev/disk/by-path/?* and ignore names ending '-partNN' as
1060 * we depend on this directory of 'path' info. But that fails
1061 * to find loop devices and probably others. Maybe don't
1062 * worry about that, they aren't the real target.
1064 * So: check things in /dev/disk/by-path to see if they are in
1065 * a compatible domain, then load the partition table and see
1066 * if it is OK for the new device, and choose the largest
1067 * partition table that fits.
1071 char *chosen
= NULL
;
1072 unsigned long long chosen_size
= 0;
1073 struct supertype
*chosen_st
= NULL
;
1076 dir
= opendir("/dev/disk/by-path");
1079 while ((de
= readdir(dir
)) != NULL
) {
1081 struct dev_policy
*pol2
= NULL
;
1082 struct domainlist
*domlist
= NULL
;
1085 struct supertype
*st2
= NULL
;
1086 char *devname
= NULL
;
1087 unsigned long long devsectors
;
1089 if (de
->d_ino
== 0 ||
1090 de
->d_name
[0] == '.' ||
1091 (de
->d_type
!= DT_LNK
&& de
->d_type
!= DT_UNKNOWN
))
1094 ep
= de
->d_name
+ strlen(de
->d_name
);
1095 while (ep
> de
->d_name
&&
1098 if (ep
> de
->d_name
+ 5 &&
1099 strncmp(ep
-5, "-part", 5) == 0)
1100 /* This is a partition - skip it */
1103 pol2
= path_policy(de
->d_name
, type_disk
);
1105 domain_merge(&domlist
, pol2
, st
? st
->ss
->name
: NULL
);
1106 if (domain_test(domlist
, pol
, st
? st
->ss
->name
: NULL
) != 1)
1107 /* new device is incompatible with this device. */
1110 domain_free(domlist
);
1113 if (asprintf(&devname
, "/dev/disk/by-path/%s", de
->d_name
) != 1) {
1117 fd
= open(devname
, O_RDONLY
);
1120 if (get_dev_size(fd
, devname
, &devsectors
) == 0)
1125 st2
= dup_super(st
);
1127 st2
= guess_super_type(fd
, guess_partitions
);
1129 st2
->ss
->load_super(st2
, fd
, NULL
) < 0)
1131 st2
->ignore_hw_compat
= 0;
1134 /* Check domain policy again, this time referring to metadata */
1135 domain_merge(&domlist
, pol2
, st2
->ss
->name
);
1136 if (domain_test(domlist
, pol
, st2
->ss
->name
) != 1)
1137 /* Incompatible devices for this metadata type */
1139 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
1140 /* Some partition types allow sparing, but not
1146 st2
->ss
->getinfo_super(st2
, &info
, NULL
);
1147 if (info
.component_size
> devsectors
)
1148 /* This partitioning doesn't fit in the device */
1151 /* This is an acceptable device to copy partition
1152 * metadata from. We could just stop here, but I
1153 * think I want to keep looking incase a larger
1154 * metadata which makes better use of the device can
1157 if (chosen
== NULL
||
1158 chosen_size
< info
.component_size
) {
1159 chosen_size
= info
.component_size
;
1164 chosen_st
->ss
->free_super(chosen_st
);
1173 domain_free(domlist
);
1174 dev_policy_free(pol2
);
1176 st2
->ss
->free_super(st2
);
1188 /* 'chosen' is the best device we can find. Let's write its
1189 * metadata to devname dfd is read-only so don't use that
1191 fd
= open(devname
, O_RDWR
);
1193 chosen_st
->ss
->store_super(chosen_st
, fd
);
1197 chosen_st
->ss
->free_super(chosen_st
);
1202 static int is_bare(int dfd
)
1204 unsigned long long size
= 0;
1205 char bufpad
[4096 + 4096];
1206 char *buf
= (char*)(((long)bufpad
+ 4096) & ~4095);
1208 if (lseek(dfd
, 0, SEEK_SET
) != 0 ||
1209 read(dfd
, buf
, 4096) != 4096)
1212 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1214 if (memcmp(buf
, buf
+1, 4095) != 0)
1217 /* OK, first 4K appear blank, try the end. */
1218 get_dev_size(dfd
, NULL
, &size
);
1219 if (lseek(dfd
, size
-4096, SEEK_SET
) < 0 ||
1220 read(dfd
, buf
, 4096) != 4096)
1223 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1225 if (memcmp(buf
, buf
+1, 4095) != 0)
1231 /* adding a spare to a regular array is quite different from adding one to
1232 * a set-of-partitions virtual array.
1233 * This function determines which is worth trying and tries as appropriate.
1234 * Arrays are given priority over partitions.
1236 static int try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1237 struct map_ent
*target
,
1238 struct supertype
*st
, int verbose
)
1243 int partitions_ok
= 0;
1247 /* Can only add a spare if device has at least one domain */
1248 if (pol_find(pol
, pol_domain
) == NULL
)
1250 /* And only if some action allows spares */
1251 if (!policy_action_allows(pol
, st
?st
->ss
->name
:NULL
, act_spare
))
1254 /* Now check if the device is bare.
1255 * bare devices can always be added as a spare
1256 * non-bare devices can only be added if spare-same-slot is permitted,
1257 * and this device is replacing a previous device - in which case 'target'
1260 if (!is_bare(dfd
)) {
1261 /* Must have a target and allow same_slot */
1262 /* Later - may allow force_spare without target */
1264 !policy_action_allows(pol
, st
?st
->ss
->name
:NULL
,
1265 act_spare_same_slot
)) {
1267 pr_err("%s is not bare, so not considering as a spare\n",
1275 /* It might be OK to add this device to an array - need to see
1276 * what arrays might be candidates.
1279 /* just try try 'array' or 'partition' based on this metadata */
1280 if (st
->ss
->add_to_super
)
1281 return array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1284 return partition_try_spare(devname
, dfdp
, pol
,
1287 /* No metadata was specified or found so options are open.
1288 * Check for whether any array metadata, or any partition metadata
1289 * might allow adding the spare. This check is just help to avoid
1290 * a more costly scan of all arrays when we can be sure that will
1293 for (i
= 0; (!arrays_ok
|| !partitions_ok
) && superlist
[i
] ; i
++) {
1294 if (superlist
[i
]->add_to_super
&& !arrays_ok
&&
1295 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1297 if (superlist
[i
]->add_to_super
== NULL
&& !partitions_ok
&&
1298 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1303 rv
= array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1305 if (rv
!= 0 && partitions_ok
)
1306 rv
= partition_try_spare(devname
, dfdp
, pol
, st
, verbose
);
1310 int IncrementalScan(struct context
*c
, char *devnm
)
1312 /* look at every device listed in the 'map' file.
1313 * If one is found that is not running then:
1314 * look in mdadm.conf for bitmap file.
1315 * if one exists, but array has none, add it.
1316 * try to start array in auto-readonly mode
1318 struct map_ent
*mapl
= NULL
;
1320 struct mddev_ident
*devs
, *mddev
;
1326 devs
= conf_get_ident(NULL
);
1329 for (me
= mapl
; me
; me
= me
->next
) {
1330 mdu_array_info_t array
;
1331 mdu_bitmap_file_t bmf
;
1335 if (devnm
&& strcmp(devnm
, me
->devnm
) != 0)
1337 if (devnm
&& me
->metadata
[0] == '/') {
1339 /* member array, need to work on container */
1340 strncpy(container
, me
->metadata
+1, 32);
1342 sl
= strchr(container
, '/');
1349 mdfd
= open_dev(me
->devnm
);
1353 if (!isdigit(me
->metadata
[0])) {
1354 /* must be a container */
1355 struct supertype
*st
= super_by_fd(mdfd
, NULL
);
1357 struct map_ent
*map
= NULL
;
1359 if (st
&& st
->ss
->load_container
)
1360 ret
= st
->ss
->load_container(st
, mdfd
, NULL
);
1362 if (!ret
&& st
&& st
->ss
->container_content
) {
1364 pr_err("failed to get exclusive lock on mapfile\n");
1365 ret
= Incremental_container(st
, me
->path
, c
, only
);
1372 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
) == 0 ||
1377 /* Ok, we can try this one. Maybe it needs a bitmap */
1378 for (mddev
= devs
; mddev
; mddev
= mddev
->next
)
1379 if (mddev
->devname
&& me
->path
1380 && devname_matches(mddev
->devname
, me
->path
))
1382 if (mddev
&& mddev
->bitmap_file
) {
1384 * Note: early kernels will wrongly fail this, so it
1388 if (ioctl(mdfd
, GET_ARRAY_INFO
, &bmf
) < 0) {
1389 int bmfd
= open(mddev
->bitmap_file
, O_RDWR
);
1391 added
= ioctl(mdfd
, SET_BITMAP_FILE
,
1396 if (c
->verbose
>= 0) {
1398 pr_err("Added bitmap %s to %s\n",
1399 mddev
->bitmap_file
, me
->path
);
1400 else if (errno
!= EEXIST
)
1401 pr_err("Failed to add bitmap to %s: %s\n",
1402 me
->path
, strerror(errno
));
1405 /* FIXME check for reshape_active and consider not
1408 sra
= sysfs_read(mdfd
, NULL
, 0);
1410 if (sysfs_set_str(sra
, NULL
,
1411 "array_state", "read-auto") == 0) {
1412 if (c
->verbose
>= 0)
1413 pr_err("started array %s\n",
1414 me
->path
?: me
->devnm
);
1416 pr_err("failed to start array %s: %s\n",
1417 me
->path
?: me
->devnm
,
1427 static char *container2devname(char *devname
)
1429 char *mdname
= NULL
;
1431 if (devname
[0] == '/') {
1432 int fd
= open(devname
, O_RDONLY
);
1434 mdname
= xstrdup(fd2devnm(fd
));
1439 struct map_ent
*mp
, *map
= NULL
;
1441 if (!parse_uuid(devname
, uuid
))
1443 mp
= map_by_uuid(&map
, uuid
);
1445 mdname
= xstrdup(mp
->devnm
);
1452 static int Incremental_container(struct supertype
*st
, char *devname
,
1453 struct context
*c
, char *only
)
1455 /* Collect the contents of this container and for each
1456 * array, choose a device name and assemble the array.
1459 struct mdinfo
*list
;
1461 struct map_ent
*map
= NULL
;
1464 struct mddev_ident
*match
;
1466 struct domainlist
*domains
;
1467 struct map_ent
*smp
;
1474 st
->ss
->getinfo_super(st
, &info
, NULL
);
1476 if ((c
->runstop
> 0 && info
.container_enough
>= 0) ||
1477 info
.container_enough
> 0)
1481 printf("MD_STARTED=no\n");
1482 } else if (c
->verbose
)
1483 pr_err("not enough devices to start the container\n");
1487 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
1488 if (match
== NULL
&& rv
== 2)
1491 /* Need to compute 'trustworthy' */
1493 trustworthy
= LOCAL
;
1494 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
1495 trustworthy
= LOCAL
;
1496 else if (st
->ss
->match_home(st
, "any") == 1)
1497 trustworthy
= LOCAL
;
1499 trustworthy
= FOREIGN
;
1501 list
= st
->ss
->container_content(st
, NULL
);
1502 /* when nothing to activate - quit */
1505 printf("MD_STARTED=nothing\n");
1509 for (ra
= list
; ra
; ra
= ra
->next
) {
1511 char chosen_name
[1024];
1513 struct mddev_ident
*match
= NULL
;
1516 /* do not activate arrays blocked by metadata handler */
1517 if (ra
->array
.state
& (1 << MD_SB_BLOCK_VOLUME
)) {
1518 pr_err("Cannot activate array %s in %s.\n",
1519 ra
->text_version
, devname
);
1523 mp
= map_by_uuid(&map
, ra
->uuid
);
1526 mdfd
= open_dev(mp
->devnm
);
1528 strcpy(chosen_name
, mp
->path
);
1530 strcpy(chosen_name
, mp
->devnm
);
1533 /* Check in mdadm.conf for container == devname and
1534 * member == ra->text_version after second slash.
1536 char *sub
= strchr(ra
->text_version
+1, '/');
1537 struct mddev_ident
*array_list
;
1540 array_list
= conf_get_ident(NULL
);
1543 for(; array_list
; array_list
= array_list
->next
) {
1545 if (array_list
->member
== NULL
||
1546 array_list
->container
== NULL
)
1548 if (strcmp(array_list
->member
, sub
) != 0)
1550 if (array_list
->uuid_set
&&
1551 !same_uuid(ra
->uuid
, array_list
->uuid
, st
->ss
->swapuuid
))
1553 dn
= container2devname(array_list
->container
);
1556 if (strncmp(dn
, ra
->text_version
+1,
1558 ra
->text_version
[strlen(dn
)+1] != '/') {
1563 /* we have a match */
1566 pr_err("match found for member %s\n",
1567 array_list
->member
);
1571 if (match
&& match
->devname
&&
1572 strcasecmp(match
->devname
, "<ignore>") == 0) {
1574 pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
1575 match
->container
, match
->member
);
1579 trustworthy
= LOCAL
;
1581 mdfd
= create_mddev(match
? match
->devname
: NULL
,
1587 if (only
&& (!mp
|| strcmp(mp
->devnm
, only
) != 0))
1591 pr_err("failed to open %s: %s.\n",
1592 chosen_name
, strerror(errno
));
1596 assemble_container_content(st
, mdfd
, ra
, c
,
1597 chosen_name
, &result
);
1600 if (c
->export
&& result
) {
1602 printf("MD_STARTED");
1603 if (result
& INCR_NO
) {
1604 printf("%cno", sep
);
1607 if (result
& INCR_UNSAFE
) {
1608 printf("%cunsafe", sep
);
1611 if (result
& INCR_ALREADY
) {
1612 printf("%calready", sep
);
1615 if (result
& INCR_YES
) {
1616 printf("%cyes", sep
);
1622 /* don't move spares to container with volume being activated
1623 when all volumes are blocked */
1624 if (ra_all
== ra_blocked
)
1627 /* Now move all suitable spares from spare container */
1628 domains
= domain_from_array(list
, st
->ss
->name
);
1629 memcpy(suuid
, uuid_zero
, sizeof(int[4]));
1631 (smp
= map_by_uuid(&map
, suuid
)) != NULL
&&
1632 (sfd
= open(smp
->path
, O_RDONLY
)) >= 0) {
1633 /* spare container found */
1634 struct supertype
*sst
=
1635 super_imsm
.match_metadata_desc("imsm");
1636 struct mdinfo
*sinfo
;
1637 unsigned long long min_size
= 0;
1638 if (st
->ss
->min_acceptable_spare_size
)
1639 min_size
= st
->ss
->min_acceptable_spare_size(st
);
1640 if (!sst
->ss
->load_container(sst
, sfd
, NULL
)) {
1642 sinfo
= container_choose_spares(sst
, min_size
,
1645 sst
->ss
->free_super(sst
);
1648 struct mdinfo
*disks
= sinfo
->devs
;
1650 /* move spare from spare
1651 * container to currently
1657 makedev(disks
->disk
.major
,
1658 disks
->disk
.minor
)))
1660 disks
= disks
->next
;
1663 pr_err("Added %d spare%s to %s\n",
1664 count
, count
>1?"s":"", devname
);
1670 domain_free(domains
);
1674 static void run_udisks(char *arg1
, char *arg2
)
1679 execl("/usr/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1680 execl("/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1683 while (pid
> 0 && wait(&status
) != pid
)
1688 * IncrementalRemove - Attempt to see if the passed in device belongs to any
1689 * raid arrays, and if so first fail (if needed) and then remove the device.
1691 * @devname - The device we want to remove
1692 * @id_path - name as found in /dev/disk/by-path for this device
1694 * Note: the device name must be a kernel name like "sda", so
1695 * that we can find it in /proc/mdstat
1697 int IncrementalRemove(char *devname
, char *id_path
, int verbose
)
1701 struct mdstat_ent
*ent
;
1702 struct mddev_dev devlist
;
1707 dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
1709 if (strchr(devname
, '/')) {
1710 pr_err("incremental removal requires a kernel device name, not a file: %s\n", devname
);
1713 ent
= mdstat_by_component(devname
);
1716 pr_err("%s does not appear to be a component of any array\n", devname
);
1719 sysfs_init(&mdi
, -1, ent
->devnm
);
1720 mdfd
= open_dev_excl(ent
->devnm
);
1723 if (sysfs_get_str(&mdi
, NULL
, "array_state",
1724 buf
, sizeof(buf
)) > 0) {
1725 if (strncmp(buf
, "active", 6) == 0 ||
1726 strncmp(buf
, "clean", 5) == 0)
1727 sysfs_set_str(&mdi
, NULL
,
1728 "array_state", "read-auto");
1731 mdfd
= open_dev(ent
->devnm
);
1734 pr_err("Cannot open array %s!!\n", ent
->devnm
);
1740 struct map_ent
*map
= NULL
, *me
;
1741 me
= map_by_devnm(&map
, ent
->devnm
);
1743 policy_save_path(id_path
, me
);
1747 memset(&devlist
, 0, sizeof(devlist
));
1748 devlist
.devname
= devname
;
1749 devlist
.disposition
= 'f';
1750 /* for a container, we must fail each member array */
1751 if (ent
->metadata_version
&&
1752 strncmp(ent
->metadata_version
, "external:", 9) == 0) {
1753 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
1754 struct mdstat_ent
*memb
;
1755 for (memb
= mdstat
; memb
; memb
= memb
->next
)
1756 if (is_container_member(memb
, ent
->devnm
)) {
1757 int subfd
= open_dev(memb
->devnm
);
1759 rv
|= Manage_subdevs(
1761 &devlist
, verbose
, 0,
1766 free_mdstat(mdstat
);
1768 rv
|= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1769 verbose
, 0, NULL
, 0);
1771 /* Failed due to EBUSY, try to stop the array.
1772 * Give udisks a chance to unmount it first.
1774 int devid
= devnm2devid(ent
->devnm
);
1775 run_udisks("--unmount", map_dev(major(devid
),minor(devid
), 0));
1776 rv
= Manage_stop(ent
->devnm
, mdfd
, verbose
, 1);
1778 /* At least we can try to trigger a 'remove' */
1779 sysfs_uevent(&mdi
, "remove");
1782 pr_err("Fail to stop %s too.\n", ent
->devnm
);
1785 devlist
.disposition
= 'r';
1786 rv
= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1787 verbose
, 0, NULL
, 0);