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",
234 /* Skip the clustered ones. This should be started by
235 * clustering resource agents
237 if (info
.array
.state
& (1 << MD_SB_CLUSTERED
))
240 /* 3a/ if not, check for homehost match. If no match, continue
241 * but don't trust the 'name' in the array. Thus a 'random' minor
242 * number will be assigned, and the device name will be based
246 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
248 else if (st
->ss
->match_home(st
, "any") == 1)
249 trustworthy
= LOCAL_ANY
;
251 trustworthy
= FOREIGN
;
253 if (!match
&& !conf_test_metadata(st
->ss
->name
, policy
,
254 (trustworthy
== LOCAL
))) {
256 pr_err("%s has metadata type %s for which auto-assembly is disabled\n",
257 devname
, st
->ss
->name
);
260 if (trustworthy
== LOCAL_ANY
)
263 /* There are three possible sources for 'autof': command line,
264 * ARRAY line in mdadm.conf, or CREATE line in mdadm.conf.
265 * ARRAY takes precedence, then command line, then
268 if (match
&& match
->autof
)
269 c
->autof
= match
->autof
;
271 c
->autof
= ci
->autof
;
273 name_to_use
= info
.name
;
274 if (name_to_use
[0] == 0 &&
275 info
.array
.level
== LEVEL_CONTAINER
) {
276 name_to_use
= info
.text_version
;
277 trustworthy
= METADATA
;
279 if (name_to_use
[0] && trustworthy
!= LOCAL
&&
280 ! c
->require_homehost
&&
281 conf_name_is_free(name_to_use
))
284 /* strip "hostname:" prefix from name if we have decided
285 * to treat it as LOCAL
287 if (trustworthy
== LOCAL
&& strchr(name_to_use
, ':') != NULL
)
288 name_to_use
= strchr(name_to_use
, ':')+1;
290 /* 4/ Check if array exists.
293 pr_err("failed to get exclusive lock on mapfile\n");
294 /* Now check we can get O_EXCL. If not, probably "mdadm -A" has
297 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
300 pr_err("cannot reopen %s: %s.\n",
301 devname
, strerror(errno
));
304 /* Cannot hold it open while we add the device to the array,
305 * so we must release the O_EXCL and depend on the map_lock()
306 * So now is the best time to remove any partitions.
308 remove_partitions(dfd
);
312 mp
= map_by_uuid(&map
, info
.uuid
);
314 mdfd
= open_dev(mp
->devnm
);
320 /* Couldn't find an existing array, maybe make a new one */
321 mdfd
= create_mddev(match
? match
->devname
: NULL
,
322 name_to_use
, c
->autof
, trustworthy
, chosen_name
);
327 sysfs_init(&info
, mdfd
, NULL
);
329 if (set_array_info(mdfd
, st
, &info
) != 0) {
330 pr_err("failed to set array info for %s: %s\n",
331 chosen_name
, strerror(errno
));
337 dinfo
.disk
.major
= major(stb
.st_rdev
);
338 dinfo
.disk
.minor
= minor(stb
.st_rdev
);
339 if (add_disk(mdfd
, st
, &info
, &dinfo
) != 0) {
340 pr_err("failed to add %s to new array %s: %s.\n",
341 devname
, chosen_name
, strerror(errno
));
342 ioctl(mdfd
, STOP_ARRAY
, 0);
346 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
347 GET_OFFSET
| GET_SIZE
));
349 if (!sra
|| !sra
->devs
|| sra
->devs
->disk
.raid_disk
>= 0) {
350 /* It really should be 'none' - must be old buggy
351 * kernel, and mdadm -I may not be able to complete.
354 ioctl(mdfd
, STOP_ARRAY
, NULL
);
355 pr_err("You have an old buggy kernel which cannot support\n --incremental reliably. Aborting.\n");
359 info
.array
.working_disks
= 1;
360 /* 6/ Make sure /var/run/mdadm.map contains this array. */
361 map_update(&map
, fd2devnm(mdfd
),
363 info
.uuid
, chosen_name
);
366 /* - check one drive in array to make sure metadata is a reasonably */
367 /* close match. Reject if not (e.g. different type) */
368 /* - add the device */
372 struct supertype
*st2
;
373 struct mdinfo info2
, *d
;
375 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
376 GET_OFFSET
| GET_SIZE
));
379 strcpy(chosen_name
, mp
->path
);
381 strcpy(chosen_name
, mp
->devnm
);
383 /* It is generally not OK to add non-spare drives to a
384 * running array as they are probably missing because
385 * they failed. However if runstop is 1, then the
386 * array was possibly started early and our best bet is
387 * to add this anyway.
388 * Also if action policy is re-add or better we allow
390 * This doesn't apply to containers as the 'non-spare'
391 * flag has a different meaning. The test has to happen
392 * at the device level there
394 if (!st
->ss
->external
395 && (info
.disk
.state
& (1<<MD_DISK_SYNC
)) != 0
396 && ! policy_action_allows(policy
, st
->ss
->name
,
399 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ainf
) == 0) {
400 pr_err("not adding %s to active array (without --run) %s\n",
401 devname
, chosen_name
);
411 sprintf(dn
, "%d:%d", sra
->devs
->disk
.major
,
412 sra
->devs
->disk
.minor
);
413 dfd2
= dev_open(dn
, O_RDONLY
);
415 pr_err("unable to open %s\n", devname
);
420 if (st2
->ss
->load_super(st2
, dfd2
, NULL
) ||
421 st
->ss
->compare_super(st
, st2
) != 0) {
422 pr_err("metadata mismatch between %s and chosen array %s\n",
423 devname
, chosen_name
);
429 st2
->ss
->getinfo_super(st2
, &info2
, NULL
);
430 st2
->ss
->free_super(st2
);
431 if (info
.array
.level
!= info2
.array
.level
||
432 memcmp(info
.uuid
, info2
.uuid
, 16) != 0 ||
433 info
.array
.raid_disks
!= info2
.array
.raid_disks
) {
434 pr_err("unexpected difference between %s and %s.\n",
435 chosen_name
, devname
);
440 info
.disk
.major
= major(stb
.st_rdev
);
441 info
.disk
.minor
= minor(stb
.st_rdev
);
442 /* add disk needs to know about containers */
443 if (st
->ss
->external
)
444 sra
->array
.level
= LEVEL_CONTAINER
;
445 err
= add_disk(mdfd
, st
, sra
, &info
);
446 if (err
< 0 && errno
== EBUSY
) {
447 /* could be another device present with the same
448 * disk.number. Find and reject any such
450 find_reject(mdfd
, st
, sra
, info
.disk
.number
,
451 info
.events
, c
->verbose
, chosen_name
);
452 err
= add_disk(mdfd
, st
, sra
, &info
);
454 if (err
< 0 && errno
== EINVAL
&&
455 info
.disk
.state
& (1<<MD_DISK_SYNC
)) {
456 /* Maybe it needs to be added as a spare */
457 if (policy_action_allows(policy
, st
->ss
->name
,
459 info
.disk
.state
&= ~(1<<MD_DISK_SYNC
);
460 err
= add_disk(mdfd
, st
, sra
, &info
);
463 pr_err("can only add %s to %s as a spare, and force-spare is not set.\n",
464 devname
, chosen_name
);
467 pr_err("failed to add %s to existing array %s: %s.\n",
468 devname
, chosen_name
, strerror(errno
));
472 info
.array
.working_disks
= 0;
473 for (d
= sra
->devs
; d
; d
=d
->next
)
474 info
.array
.working_disks
++;
477 if (strncmp(chosen_name
, "/dev/md/", 8) == 0)
478 md_devname
= chosen_name
+8;
480 md_devname
= chosen_name
;
482 printf("MD_DEVICE=%s\n", fd2devnm(mdfd
));
483 printf("MD_DEVNAME=%s\n", md_devname
);
484 printf("MD_FOREIGN=%s\n", trustworthy
== FOREIGN
? "yes" : "no");
487 /* 7/ Is there enough devices to possibly start the array? */
488 /* 7a/ if not, finish with success. */
489 if (info
.array
.level
== LEVEL_CONTAINER
) {
491 /* Try to assemble within the container */
492 sysfs_uevent(sra
, "change");
493 if (!c
->export
&& c
->verbose
>= 0)
494 pr_err("container %s now has %d device%s\n",
495 chosen_name
, info
.array
.working_disks
,
496 info
.array
.working_disks
== 1?"":"s");
497 wait_for(chosen_name
, mdfd
);
498 if (st
->ss
->external
)
499 strcpy(devnm
, fd2devnm(mdfd
));
500 if (st
->ss
->load_container
)
501 rv
= st
->ss
->load_container(st
, mdfd
, NULL
);
505 rv
= Incremental_container(st
, chosen_name
, c
, NULL
);
507 /* after spare is added, ping monitor for external metadata
508 * so that it can eg. try to rebuild degraded array */
509 if (st
->ss
->external
)
514 /* We have added something to the array, so need to re-read the
515 * state. Eventually this state should be kept up-to-date as
519 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
520 GET_OFFSET
| GET_SIZE
));
521 active_disks
= count_active(st
, sra
, mdfd
, &avail
, &info
);
522 if (enough(info
.array
.level
, info
.array
.raid_disks
,
523 info
.array
.layout
, info
.array
.state
& 1,
526 printf("MD_STARTED=no\n");
527 } else if (c
->verbose
>= 0)
528 pr_err("%s attached to %s, not enough to start (%d).\n",
529 devname
, chosen_name
, active_disks
);
535 /* - if number of OK devices match expected, or -R and there */
537 /* + add any bitmap file */
538 /* + start the array (auto-readonly). */
540 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ainf
) == 0) {
542 printf("MD_STARTED=already\n");
543 } else if (c
->verbose
>= 0)
544 pr_err("%s attached to %s which is already active.\n",
545 devname
, chosen_name
);
551 if (c
->runstop
> 0 || active_disks
>= info
.array
.working_disks
) {
553 /* Let's try to start it */
555 if (info
.reshape_active
&& !(info
.reshape_active
& RESHAPE_NO_BACKUP
)) {
556 pr_err("%s: This array is being reshaped and cannot be started\n",
558 cont_err("by --incremental. Please use --assemble\n");
561 if (match
&& match
->bitmap_file
) {
562 int bmfd
= open(match
->bitmap_file
, O_RDWR
);
564 pr_err("Could not open bitmap file %s.\n",
568 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
570 pr_err("Failed to set bitmapfile for %s.\n",
576 /* Need to remove from the array any devices which
577 * 'count_active' discerned were too old or inappropriate
579 for (d
= sra
? sra
->devs
: NULL
; d
; d
= d
->next
)
580 if (d
->disk
.state
& (1<<MD_DISK_REMOVED
))
581 remove_disk(mdfd
, st
, sra
, d
);
583 if ((sra
== NULL
|| active_disks
>= info
.array
.working_disks
)
584 && trustworthy
!= FOREIGN
)
585 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
587 rv
= sysfs_set_str(sra
, NULL
,
588 "array_state", "read-auto");
589 /* Array might be O_EXCL which will interfere with
590 * fsck and mount. So re-open without O_EXCL.
595 printf("MD_STARTED=yes\n");
596 } else if (c
->verbose
>= 0)
597 pr_err("%s attached to %s, which has been started.\n",
598 devname
, chosen_name
);
600 wait_for(chosen_name
, mdfd
);
601 /* We just started the array, so some devices
602 * might have been evicted from the array
603 * because their event counts were too old.
604 * If the action=re-add policy is in-force for
605 * those devices we should re-add them now.
607 for (dsk
= sra
->devs
; dsk
; dsk
= dsk
->next
) {
608 if (disk_action_allows(dsk
, st
->ss
->name
, act_re_add
) &&
609 add_disk(mdfd
, st
, sra
, dsk
) == 0)
610 pr_err("%s re-added to %s\n",
611 dsk
->sys_name
, chosen_name
);
614 pr_err("%s attached to %s, but failed to start: %s.\n",
615 devname
, chosen_name
, strerror(errno
));
620 printf("MD_STARTED=unsafe\n");
621 } else if (c
->verbose
>= 0)
622 pr_err("%s attached to %s, not enough to start safely.\n",
623 devname
, chosen_name
);
633 dev_policy_free(policy
);
642 static void find_reject(int mdfd
, struct supertype
*st
, struct mdinfo
*sra
,
643 int number
, __u64 events
, int verbose
,
646 /* Find a device attached to this array with a disk.number of number
647 * and events less than the passed events, and remove the device.
652 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ra
) == 0)
653 return; /* not safe to remove from active arrays
654 * without thinking more */
656 for (d
= sra
->devs
; d
; d
= d
->next
) {
660 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
661 dfd
= dev_open(dn
, O_RDONLY
);
664 if (st
->ss
->load_super(st
, dfd
, NULL
)) {
668 st
->ss
->getinfo_super(st
, &info
, NULL
);
669 st
->ss
->free_super(st
);
672 if (info
.disk
.number
!= number
||
673 info
.events
>= events
)
676 if (d
->disk
.raid_disk
> -1)
677 sysfs_set_str(sra
, d
, "slot", "none");
678 if (sysfs_set_str(sra
, d
, "state", "remove") == 0)
680 pr_err("removing old device %s from %s\n",
681 d
->sys_name
+4, array_name
);
685 static int count_active(struct supertype
*st
, struct mdinfo
*sra
,
686 int mdfd
, char **availp
,
687 struct mdinfo
*bestinfo
)
689 /* count how many devices in sra think they are active */
693 __u64 max_events
= 0;
705 for (d
= sra
->devs
; d
; d
= d
->next
)
707 for (d
= sra
->devs
, devnum
= 0 ; d
; d
= d
->next
, devnum
++) {
713 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
714 dfd
= dev_open(dn
, O_RDONLY
);
717 ok
= st
->ss
->load_super(st
, dfd
, NULL
);
721 info
.array
.raid_disks
= raid_disks
;
722 st
->ss
->getinfo_super(st
, &info
, devmap
+ raid_disks
* devnum
);
724 raid_disks
= info
.array
.raid_disks
;
725 avail
= xcalloc(raid_disks
, 1);
728 best
= xcalloc(raid_disks
, sizeof(int));
729 devmap
= xcalloc(raid_disks
, numdevs
);
731 st
->ss
->getinfo_super(st
, &info
, devmap
);
734 if (info
.disk
.state
& (1<<MD_DISK_SYNC
))
738 max_events
= info
.events
;
739 avail
[info
.disk
.raid_disk
] = 2;
740 best
[info
.disk
.raid_disk
] = devnum
;
741 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
742 } else if (info
.events
== max_events
) {
743 avail
[info
.disk
.raid_disk
] = 2;
744 best
[info
.disk
.raid_disk
] = devnum
;
745 } else if (info
.events
== max_events
-1) {
746 if (avail
[info
.disk
.raid_disk
] == 0) {
747 avail
[info
.disk
.raid_disk
] = 1;
748 best
[info
.disk
.raid_disk
] = devnum
;
750 } else if (info
.events
< max_events
- 1)
752 else if (info
.events
== max_events
+1) {
754 max_events
= info
.events
;
755 for (i
= 0; i
< raid_disks
; i
++)
758 avail
[info
.disk
.raid_disk
] = 2;
759 best
[info
.disk
.raid_disk
] = devnum
;
760 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
761 } else { /* info.events much bigger */
762 memset(avail
, 0, raid_disks
);
763 max_events
= info
.events
;
764 avail
[info
.disk
.raid_disk
] = 2;
765 best
[info
.disk
.raid_disk
] = devnum
;
766 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
768 } else if (info
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
770 st
->ss
->free_super(st
);
774 /* We need to reject any device that thinks the best device is
775 * failed or missing */
776 for (b
= 0; b
< raid_disks
; b
++)
780 for (i
= 0 ; i
< raid_disks
; i
++) {
781 if (i
!= b
&& avail
[i
])
782 if (devmap
[raid_disks
* best
[i
] + b
] == 0) {
783 /* This device thinks 'b' is failed -
786 for (d
=sra
->devs
; devnum
; d
= d
->next
)
788 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
794 /* Also need to reject any spare device with an event count that
797 for (d
= sra
->devs
; d
; d
= d
->next
) {
798 if (!(d
->disk
.state
& (1<<MD_DISK_SYNC
)) &&
799 d
->events
> max_events
)
800 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
804 return cnt
+ replcnt
;
807 /* test if container has degraded member(s) */
808 static int container_members_max_degradation(struct map_ent
*map
, struct map_ent
*me
)
810 mdu_array_info_t array
;
812 int max_degraded
= 0;
814 for(; map
; map
= map
->next
) {
815 if (!metadata_container_matches(map
->metadata
, me
->devnm
))
817 afd
= open_dev(map
->devnm
);
820 /* most accurate information regarding array degradation */
821 if (ioctl(afd
, GET_ARRAY_INFO
, &array
) >= 0) {
822 int degraded
= array
.raid_disks
- array
.active_disks
-
824 if (degraded
> max_degraded
)
825 max_degraded
= degraded
;
829 return (max_degraded
);
832 static int array_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
833 struct map_ent
*target
, int bare
,
834 struct supertype
*st
, int verbose
)
836 /* This device doesn't have any md metadata
837 * The device policy allows 'spare' and if !bare, it allows spare-same-slot.
838 * If 'st' is not set, then we only know that some metadata allows this,
839 * others possibly don't.
840 * So look for a container or array to attach the device to.
841 * Prefer 'target' if that is set and the array is found.
843 * If st is set, then only arrays of that type are considered
844 * Return 0 on success, or some exit code on failure, probably 1.
848 struct map_ent
*mp
, *map
= NULL
;
849 struct mdinfo
*chosen
= NULL
;
852 if (fstat(dfd
, &stb
) != 0)
856 * Now we need to find a suitable array to add this to.
857 * We only accept arrays that:
859 * - are in the same domains as the device
860 * - are of an size for which the device will be useful
861 * and we choose the one that is the most degraded
864 if (map_lock(&map
)) {
865 pr_err("failed to get exclusive lock on mapfile\n");
868 for (mp
= map
; mp
; mp
= mp
->next
) {
869 struct supertype
*st2
;
870 struct domainlist
*dl
= NULL
;
872 unsigned long long devsize
;
873 unsigned long long component_size
= 0;
875 if (is_subarray(mp
->metadata
))
878 st2
= st
->ss
->match_metadata_desc(mp
->metadata
);
880 (st
->minor_version
>= 0 &&
881 st
->minor_version
!= st2
->minor_version
)) {
883 pr_err("not adding %s to %s as metadata type doesn't match\n",
890 sra
= sysfs_read(-1, mp
->devnm
,
891 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
892 GET_DEGRADED
|GET_COMPONENT
|GET_VERSION
);
894 /* Probably a container - no degraded info */
895 sra
= sysfs_read(-1, mp
->devnm
,
896 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
897 GET_COMPONENT
|GET_VERSION
);
899 sra
->array
.failed_disks
= -1;
906 for(i
= 0; !st2
&& superlist
[i
]; i
++)
907 st2
= superlist
[i
]->match_metadata_desc(
911 pr_err("not adding %s to %s as metadata not recognised.\n",
915 /* Need to double check the 'act_spare' permissions applies
918 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
920 if (!bare
&& !policy_action_allows(pol
, st2
->ss
->name
,
921 act_spare_same_slot
))
925 /* update number of failed disks for mostly degraded
926 * container member */
927 if (sra
->array
.failed_disks
== -1)
928 sra
->array
.failed_disks
= container_members_max_degradation(map
, mp
);
930 get_dev_size(dfd
, NULL
, &devsize
);
931 if (sra
->component_size
== 0) {
932 /* true for containers, here we must read superblock
933 * to obtain minimum spare size */
934 struct supertype
*st3
= dup_super(st2
);
935 int mdfd
= open_dev(mp
->devnm
);
940 if (st3
->ss
->load_container
&&
941 !st3
->ss
->load_container(st3
, mdfd
, mp
->path
)) {
942 component_size
= st3
->ss
->min_acceptable_spare_size(st3
);
943 st3
->ss
->free_super(st3
);
948 if ((sra
->component_size
> 0 &&
949 st2
->ss
->avail_size(st2
, devsize
,
951 ? sra
->devs
->data_offset
953 < sra
->component_size
)
955 (sra
->component_size
== 0 && devsize
< component_size
)) {
957 pr_err("not adding %s to %s as it is too small\n",
961 /* test against target.
962 * If 'target' is set and 'bare' is false, we only accept
963 * arrays/containers that match 'target'.
964 * If 'target' is set and 'bare' is true, we prefer the
965 * array which matches 'target'.
966 * target is considered only if we deal with degraded array
968 if (target
&& policy_action_allows(pol
, st2
->ss
->name
,
969 act_spare_same_slot
)) {
970 if (strcmp(target
->metadata
, mp
->metadata
) == 0 &&
971 memcmp(target
->uuid
, mp
->uuid
,
972 sizeof(target
->uuid
)) == 0 &&
973 sra
->array
.failed_disks
> 0) {
974 /* This is our target!! */
979 /* skip to end so we don't check any more */
989 dl
= domain_from_array(sra
, st2
->ss
->name
);
990 if (domain_test(dl
, pol
, st2
->ss
->name
) != 1) {
991 /* domain test fails */
993 pr_err("not adding %s to %s as it is not in a compatible domain\n",
998 /* all tests passed, OK to add to this array */
1002 } else if (chosen
->array
.failed_disks
< sra
->array
.failed_disks
) {
1016 /* add current device to chosen array as a spare */
1017 int mdfd
= open_dev(chosen
->sys_name
);
1019 struct mddev_dev devlist
;
1021 devlist
.next
= NULL
;
1023 devlist
.writemostly
= 0;
1024 devlist
.devname
= devname
;
1025 sprintf(devname
, "%d:%d", major(stb
.st_rdev
),
1026 minor(stb
.st_rdev
));
1027 devlist
.disposition
= 'a';
1030 rv
= Manage_subdevs(chosen
->sys_name
, mdfd
, &devlist
,
1036 pr_err("added %s as spare for %s\n",
1037 devname
, chosen
->sys_name
);
1039 pr_err("failed to add %s as spare for %s\n",
1040 devname
, chosen
->sys_name
);
1048 static int partition_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1049 struct supertype
*st
, int verbose
)
1051 /* we know that at least one partition virtual-metadata is
1052 * allowed to incorporate spares like this device. We need to
1053 * find a suitable device to copy partition information from.
1055 * Getting a list of all disk (not partition) devices is
1056 * slightly non-trivial. We could look at /sys/block, but
1057 * that is theoretically due to be removed. Maybe best to use
1058 * /dev/disk/by-path/?* and ignore names ending '-partNN' as
1059 * we depend on this directory of 'path' info. But that fails
1060 * to find loop devices and probably others. Maybe don't
1061 * worry about that, they aren't the real target.
1063 * So: check things in /dev/disk/by-path to see if they are in
1064 * a compatible domain, then load the partition table and see
1065 * if it is OK for the new device, and choose the largest
1066 * partition table that fits.
1070 char *chosen
= NULL
;
1071 unsigned long long chosen_size
= 0;
1072 struct supertype
*chosen_st
= NULL
;
1075 dir
= opendir("/dev/disk/by-path");
1078 while ((de
= readdir(dir
)) != NULL
) {
1080 struct dev_policy
*pol2
= NULL
;
1081 struct domainlist
*domlist
= NULL
;
1084 struct supertype
*st2
= NULL
;
1085 char *devname
= NULL
;
1086 unsigned long long devsectors
;
1088 if (de
->d_ino
== 0 ||
1089 de
->d_name
[0] == '.' ||
1090 (de
->d_type
!= DT_LNK
&& de
->d_type
!= DT_UNKNOWN
))
1093 ep
= de
->d_name
+ strlen(de
->d_name
);
1094 while (ep
> de
->d_name
&&
1097 if (ep
> de
->d_name
+ 5 &&
1098 strncmp(ep
-5, "-part", 5) == 0)
1099 /* This is a partition - skip it */
1102 pol2
= path_policy(de
->d_name
, type_disk
);
1104 domain_merge(&domlist
, pol2
, st
? st
->ss
->name
: NULL
);
1105 if (domain_test(domlist
, pol
, st
? st
->ss
->name
: NULL
) != 1)
1106 /* new device is incompatible with this device. */
1109 domain_free(domlist
);
1112 if (asprintf(&devname
, "/dev/disk/by-path/%s", de
->d_name
) != 1) {
1116 fd
= open(devname
, O_RDONLY
);
1119 if (get_dev_size(fd
, devname
, &devsectors
) == 0)
1124 st2
= dup_super(st
);
1126 st2
= guess_super_type(fd
, guess_partitions
);
1128 st2
->ss
->load_super(st2
, fd
, NULL
) < 0)
1130 st2
->ignore_hw_compat
= 0;
1133 /* Check domain policy again, this time referring to metadata */
1134 domain_merge(&domlist
, pol2
, st2
->ss
->name
);
1135 if (domain_test(domlist
, pol
, st2
->ss
->name
) != 1)
1136 /* Incompatible devices for this metadata type */
1138 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
1139 /* Some partition types allow sparing, but not
1145 st2
->ss
->getinfo_super(st2
, &info
, NULL
);
1146 if (info
.component_size
> devsectors
)
1147 /* This partitioning doesn't fit in the device */
1150 /* This is an acceptable device to copy partition
1151 * metadata from. We could just stop here, but I
1152 * think I want to keep looking incase a larger
1153 * metadata which makes better use of the device can
1156 if (chosen
== NULL
||
1157 chosen_size
< info
.component_size
) {
1158 chosen_size
= info
.component_size
;
1163 chosen_st
->ss
->free_super(chosen_st
);
1172 domain_free(domlist
);
1173 dev_policy_free(pol2
);
1175 st2
->ss
->free_super(st2
);
1187 /* 'chosen' is the best device we can find. Let's write its
1188 * metadata to devname dfd is read-only so don't use that
1190 fd
= open(devname
, O_RDWR
);
1192 chosen_st
->ss
->store_super(chosen_st
, fd
);
1196 chosen_st
->ss
->free_super(chosen_st
);
1201 static int is_bare(int dfd
)
1203 unsigned long long size
= 0;
1204 char bufpad
[4096 + 4096];
1205 char *buf
= (char*)(((long)bufpad
+ 4096) & ~4095);
1207 if (lseek(dfd
, 0, SEEK_SET
) != 0 ||
1208 read(dfd
, buf
, 4096) != 4096)
1211 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1213 if (memcmp(buf
, buf
+1, 4095) != 0)
1216 /* OK, first 4K appear blank, try the end. */
1217 get_dev_size(dfd
, NULL
, &size
);
1218 if (lseek(dfd
, size
-4096, SEEK_SET
) < 0 ||
1219 read(dfd
, buf
, 4096) != 4096)
1222 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1224 if (memcmp(buf
, buf
+1, 4095) != 0)
1230 /* adding a spare to a regular array is quite different from adding one to
1231 * a set-of-partitions virtual array.
1232 * This function determines which is worth trying and tries as appropriate.
1233 * Arrays are given priority over partitions.
1235 static int try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1236 struct map_ent
*target
,
1237 struct supertype
*st
, int verbose
)
1242 int partitions_ok
= 0;
1246 /* Can only add a spare if device has at least one domain */
1247 if (pol_find(pol
, pol_domain
) == NULL
)
1249 /* And only if some action allows spares */
1250 if (!policy_action_allows(pol
, st
?st
->ss
->name
:NULL
, act_spare
))
1253 /* Now check if the device is bare.
1254 * bare devices can always be added as a spare
1255 * non-bare devices can only be added if spare-same-slot is permitted,
1256 * and this device is replacing a previous device - in which case 'target'
1259 if (!is_bare(dfd
)) {
1260 /* Must have a target and allow same_slot */
1261 /* Later - may allow force_spare without target */
1263 !policy_action_allows(pol
, st
?st
->ss
->name
:NULL
,
1264 act_spare_same_slot
)) {
1266 pr_err("%s is not bare, so not considering as a spare\n",
1274 /* It might be OK to add this device to an array - need to see
1275 * what arrays might be candidates.
1278 /* just try try 'array' or 'partition' based on this metadata */
1279 if (st
->ss
->add_to_super
)
1280 return array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1283 return partition_try_spare(devname
, dfdp
, pol
,
1286 /* No metadata was specified or found so options are open.
1287 * Check for whether any array metadata, or any partition metadata
1288 * might allow adding the spare. This check is just help to avoid
1289 * a more costly scan of all arrays when we can be sure that will
1292 for (i
= 0; (!arrays_ok
|| !partitions_ok
) && superlist
[i
] ; i
++) {
1293 if (superlist
[i
]->add_to_super
&& !arrays_ok
&&
1294 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1296 if (superlist
[i
]->add_to_super
== NULL
&& !partitions_ok
&&
1297 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1302 rv
= array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1304 if (rv
!= 0 && partitions_ok
)
1305 rv
= partition_try_spare(devname
, dfdp
, pol
, st
, verbose
);
1309 int IncrementalScan(struct context
*c
, char *devnm
)
1311 /* look at every device listed in the 'map' file.
1312 * If one is found that is not running then:
1313 * look in mdadm.conf for bitmap file.
1314 * if one exists, but array has none, add it.
1315 * try to start array in auto-readonly mode
1317 struct map_ent
*mapl
= NULL
;
1319 struct mddev_ident
*devs
, *mddev
;
1325 devs
= conf_get_ident(NULL
);
1328 for (me
= mapl
; me
; me
= me
->next
) {
1329 mdu_array_info_t array
;
1330 mdu_bitmap_file_t bmf
;
1334 if (devnm
&& strcmp(devnm
, me
->devnm
) != 0)
1336 if (devnm
&& me
->metadata
[0] == '/') {
1338 /* member array, need to work on container */
1339 strncpy(container
, me
->metadata
+1, 32);
1341 sl
= strchr(container
, '/');
1348 mdfd
= open_dev(me
->devnm
);
1352 if (!isdigit(me
->metadata
[0])) {
1353 /* must be a container */
1354 struct supertype
*st
= super_by_fd(mdfd
, NULL
);
1356 struct map_ent
*map
= NULL
;
1358 if (st
&& st
->ss
->load_container
)
1359 ret
= st
->ss
->load_container(st
, mdfd
, NULL
);
1361 if (!ret
&& st
&& st
->ss
->container_content
) {
1363 pr_err("failed to get exclusive lock on mapfile\n");
1364 ret
= Incremental_container(st
, me
->path
, c
, only
);
1371 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
) == 0 ||
1376 /* Ok, we can try this one. Maybe it needs a bitmap */
1377 for (mddev
= devs
; mddev
; mddev
= mddev
->next
)
1378 if (mddev
->devname
&& me
->path
1379 && devname_matches(mddev
->devname
, me
->path
))
1381 if (mddev
&& mddev
->bitmap_file
) {
1383 * Note: early kernels will wrongly fail this, so it
1387 if (ioctl(mdfd
, GET_ARRAY_INFO
, &bmf
) < 0) {
1388 int bmfd
= open(mddev
->bitmap_file
, O_RDWR
);
1390 added
= ioctl(mdfd
, SET_BITMAP_FILE
,
1395 if (c
->verbose
>= 0) {
1397 pr_err("Added bitmap %s to %s\n",
1398 mddev
->bitmap_file
, me
->path
);
1399 else if (errno
!= EEXIST
)
1400 pr_err("Failed to add bitmap to %s: %s\n",
1401 me
->path
, strerror(errno
));
1404 /* FIXME check for reshape_active and consider not
1407 sra
= sysfs_read(mdfd
, NULL
, 0);
1409 if (sysfs_set_str(sra
, NULL
,
1410 "array_state", "read-auto") == 0) {
1411 if (c
->verbose
>= 0)
1412 pr_err("started array %s\n",
1413 me
->path
?: me
->devnm
);
1415 pr_err("failed to start array %s: %s\n",
1416 me
->path
?: me
->devnm
,
1426 static char *container2devname(char *devname
)
1428 char *mdname
= NULL
;
1430 if (devname
[0] == '/') {
1431 int fd
= open(devname
, O_RDONLY
);
1433 mdname
= xstrdup(fd2devnm(fd
));
1438 struct map_ent
*mp
, *map
= NULL
;
1440 if (!parse_uuid(devname
, uuid
))
1442 mp
= map_by_uuid(&map
, uuid
);
1444 mdname
= xstrdup(mp
->devnm
);
1451 static int Incremental_container(struct supertype
*st
, char *devname
,
1452 struct context
*c
, char *only
)
1454 /* Collect the contents of this container and for each
1455 * array, choose a device name and assemble the array.
1458 struct mdinfo
*list
;
1460 struct map_ent
*map
= NULL
;
1463 struct mddev_ident
*match
;
1465 struct domainlist
*domains
;
1466 struct map_ent
*smp
;
1473 st
->ss
->getinfo_super(st
, &info
, NULL
);
1475 if ((c
->runstop
> 0 && info
.container_enough
>= 0) ||
1476 info
.container_enough
> 0)
1480 printf("MD_STARTED=no\n");
1481 } else if (c
->verbose
)
1482 pr_err("not enough devices to start the container\n");
1486 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
1487 if (match
== NULL
&& rv
== 2)
1490 /* Need to compute 'trustworthy' */
1492 trustworthy
= LOCAL
;
1493 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
1494 trustworthy
= LOCAL
;
1495 else if (st
->ss
->match_home(st
, "any") == 1)
1496 trustworthy
= LOCAL
;
1498 trustworthy
= FOREIGN
;
1500 list
= st
->ss
->container_content(st
, NULL
);
1501 /* when nothing to activate - quit */
1504 printf("MD_STARTED=nothing\n");
1508 for (ra
= list
; ra
; ra
= ra
->next
) {
1510 char chosen_name
[1024];
1512 struct mddev_ident
*match
= NULL
;
1515 /* do not activate arrays blocked by metadata handler */
1516 if (ra
->array
.state
& (1 << MD_SB_BLOCK_VOLUME
)) {
1517 pr_err("Cannot activate array %s in %s.\n",
1518 ra
->text_version
, devname
);
1522 mp
= map_by_uuid(&map
, ra
->uuid
);
1525 mdfd
= open_dev(mp
->devnm
);
1527 strcpy(chosen_name
, mp
->path
);
1529 strcpy(chosen_name
, mp
->devnm
);
1532 /* Check in mdadm.conf for container == devname and
1533 * member == ra->text_version after second slash.
1535 char *sub
= strchr(ra
->text_version
+1, '/');
1536 struct mddev_ident
*array_list
;
1539 array_list
= conf_get_ident(NULL
);
1542 for(; array_list
; array_list
= array_list
->next
) {
1544 if (array_list
->member
== NULL
||
1545 array_list
->container
== NULL
)
1547 if (strcmp(array_list
->member
, sub
) != 0)
1549 if (array_list
->uuid_set
&&
1550 !same_uuid(ra
->uuid
, array_list
->uuid
, st
->ss
->swapuuid
))
1552 dn
= container2devname(array_list
->container
);
1555 if (strncmp(dn
, ra
->text_version
+1,
1557 ra
->text_version
[strlen(dn
)+1] != '/') {
1562 /* we have a match */
1565 pr_err("match found for member %s\n",
1566 array_list
->member
);
1570 if (match
&& match
->devname
&&
1571 strcasecmp(match
->devname
, "<ignore>") == 0) {
1573 pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
1574 match
->container
, match
->member
);
1578 trustworthy
= LOCAL
;
1580 mdfd
= create_mddev(match
? match
->devname
: NULL
,
1586 if (only
&& (!mp
|| strcmp(mp
->devnm
, only
) != 0))
1590 pr_err("failed to open %s: %s.\n",
1591 chosen_name
, strerror(errno
));
1595 assemble_container_content(st
, mdfd
, ra
, c
,
1596 chosen_name
, &result
);
1599 if (c
->export
&& result
) {
1601 printf("MD_STARTED");
1602 if (result
& INCR_NO
) {
1603 printf("%cno", sep
);
1606 if (result
& INCR_UNSAFE
) {
1607 printf("%cunsafe", sep
);
1610 if (result
& INCR_ALREADY
) {
1611 printf("%calready", sep
);
1614 if (result
& INCR_YES
) {
1615 printf("%cyes", sep
);
1621 /* don't move spares to container with volume being activated
1622 when all volumes are blocked */
1623 if (ra_all
== ra_blocked
)
1626 /* Now move all suitable spares from spare container */
1627 domains
= domain_from_array(list
, st
->ss
->name
);
1628 memcpy(suuid
, uuid_zero
, sizeof(int[4]));
1630 (smp
= map_by_uuid(&map
, suuid
)) != NULL
&&
1631 (sfd
= open(smp
->path
, O_RDONLY
)) >= 0) {
1632 /* spare container found */
1633 struct supertype
*sst
=
1634 super_imsm
.match_metadata_desc("imsm");
1635 struct mdinfo
*sinfo
;
1636 unsigned long long min_size
= 0;
1637 if (st
->ss
->min_acceptable_spare_size
)
1638 min_size
= st
->ss
->min_acceptable_spare_size(st
);
1639 if (!sst
->ss
->load_container(sst
, sfd
, NULL
)) {
1641 sinfo
= container_choose_spares(sst
, min_size
,
1644 sst
->ss
->free_super(sst
);
1647 struct mdinfo
*disks
= sinfo
->devs
;
1649 /* move spare from spare
1650 * container to currently
1656 makedev(disks
->disk
.major
,
1657 disks
->disk
.minor
)))
1659 disks
= disks
->next
;
1662 pr_err("Added %d spare%s to %s\n",
1663 count
, count
>1?"s":"", devname
);
1669 domain_free(domains
);
1673 static void run_udisks(char *arg1
, char *arg2
)
1678 execl("/usr/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1679 execl("/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1682 while (pid
> 0 && wait(&status
) != pid
)
1687 * IncrementalRemove - Attempt to see if the passed in device belongs to any
1688 * raid arrays, and if so first fail (if needed) and then remove the device.
1690 * @devname - The device we want to remove
1691 * @id_path - name as found in /dev/disk/by-path for this device
1693 * Note: the device name must be a kernel name like "sda", so
1694 * that we can find it in /proc/mdstat
1696 int IncrementalRemove(char *devname
, char *id_path
, int verbose
)
1700 struct mdstat_ent
*ent
;
1701 struct mddev_dev devlist
;
1706 dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
1708 if (strchr(devname
, '/')) {
1709 pr_err("incremental removal requires a kernel device name, not a file: %s\n", devname
);
1712 ent
= mdstat_by_component(devname
);
1715 pr_err("%s does not appear to be a component of any array\n", devname
);
1718 sysfs_init(&mdi
, -1, ent
->devnm
);
1719 mdfd
= open_dev_excl(ent
->devnm
);
1722 if (sysfs_get_str(&mdi
, NULL
, "array_state",
1723 buf
, sizeof(buf
)) > 0) {
1724 if (strncmp(buf
, "active", 6) == 0 ||
1725 strncmp(buf
, "clean", 5) == 0)
1726 sysfs_set_str(&mdi
, NULL
,
1727 "array_state", "read-auto");
1730 mdfd
= open_dev(ent
->devnm
);
1733 pr_err("Cannot open array %s!!\n", ent
->devnm
);
1739 struct map_ent
*map
= NULL
, *me
;
1740 me
= map_by_devnm(&map
, ent
->devnm
);
1742 policy_save_path(id_path
, me
);
1746 memset(&devlist
, 0, sizeof(devlist
));
1747 devlist
.devname
= devname
;
1748 devlist
.disposition
= 'f';
1749 /* for a container, we must fail each member array */
1750 if (ent
->metadata_version
&&
1751 strncmp(ent
->metadata_version
, "external:", 9) == 0) {
1752 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
1753 struct mdstat_ent
*memb
;
1754 for (memb
= mdstat
; memb
; memb
= memb
->next
)
1755 if (is_container_member(memb
, ent
->devnm
)) {
1756 int subfd
= open_dev(memb
->devnm
);
1758 rv
|= Manage_subdevs(
1760 &devlist
, verbose
, 0,
1765 free_mdstat(mdstat
);
1767 rv
|= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1768 verbose
, 0, NULL
, 0);
1770 /* Failed due to EBUSY, try to stop the array.
1771 * Give udisks a chance to unmount it first.
1773 int devid
= devnm2devid(ent
->devnm
);
1774 run_udisks("--unmount", map_dev(major(devid
),minor(devid
), 0));
1775 rv
= Manage_stop(ent
->devnm
, mdfd
, verbose
, 1);
1777 /* At least we can try to trigger a 'remove' */
1778 sysfs_uevent(&mdi
, "remove");
1781 pr_err("Fail to stop %s too.\n", ent
->devnm
);
1784 devlist
.disposition
= 'r';
1785 rv
= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1786 verbose
, 0, NULL
, 0);