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
);
134 st
->ignore_hw_compat
= 1;
135 if (st
&& st
->ss
->load_container
)
136 rv
= st
->ss
->load_container(st
, dfd
, NULL
);
139 if (!rv
&& st
->ss
->container_content
) {
141 pr_err("failed to get exclusive lock on mapfile\n");
143 printf("MD_DEVNAME=%s\n", devname
);
144 rv
= Incremental_container(st
, devname
, c
, NULL
);
149 pr_err("%s is not part of an md array.\n",
154 /* 1/ Check if device is permitted by mdadm.conf */
156 for (;devlist
; devlist
= devlist
->next
)
157 if (conf_test_dev(devlist
->devname
))
160 devlist
= conf_get_devs();
161 for (;devlist
; devlist
= devlist
->next
) {
163 if (stat(devlist
->devname
, &st2
) == 0 &&
164 (st2
.st_mode
& S_IFMT
) == S_IFBLK
&&
165 st2
.st_rdev
== stb
.st_rdev
)
171 pr_err("%s not permitted by mdadm.conf.\n",
176 /* 2/ Find metadata, reject if none appropriate (check
177 * version/name from args) */
179 if (fstat(dfd
, &stb
) < 0) {
181 pr_err("fstat failed for %s: %s.\n",
182 devname
, strerror(errno
));
185 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
187 pr_err("%s is not a block device.\n",
192 dinfo
.disk
.major
= major(stb
.st_rdev
);
193 dinfo
.disk
.minor
= minor(stb
.st_rdev
);
195 policy
= disk_policy(&dinfo
);
196 have_target
= policy_check_path(&dinfo
, &target_array
);
198 if (st
== NULL
&& (st
= guess_super_type(dfd
, guess_array
)) == NULL
) {
200 pr_err("no recognisable superblock on %s.\n",
202 rv
= try_spare(devname
, &dfd
, policy
,
203 have_target
? &target_array
: NULL
,
207 st
->ignore_hw_compat
= 1;
208 if (st
->ss
->compare_super
== NULL
||
209 st
->ss
->load_super(st
, dfd
, NULL
)) {
211 pr_err("no RAID superblock on %s.\n",
213 rv
= try_spare(devname
, &dfd
, policy
,
214 have_target
? &target_array
: NULL
,
219 close (dfd
); dfd
= -1;
221 st
->ss
->getinfo_super(st
, &info
, NULL
);
223 /* 3/ Check if there is a match in mdadm.conf */
224 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
225 if (!match
&& rv
== 2)
228 if (match
&& match
->devname
229 && strcasecmp(match
->devname
, "<ignore>") == 0) {
231 pr_err("array containing %s is explicitly ignored by mdadm.conf\n",
236 /* 3a/ if not, check for homehost match. If no match, continue
237 * but don't trust the 'name' in the array. Thus a 'random' minor
238 * number will be assigned, and the device name will be based
242 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
244 else if (st
->ss
->match_home(st
, "any") == 1)
245 trustworthy
= LOCAL_ANY
;
247 trustworthy
= FOREIGN
;
249 if (!match
&& !conf_test_metadata(st
->ss
->name
, policy
,
250 (trustworthy
== LOCAL
))) {
252 pr_err("%s has metadata type %s for which auto-assembly is disabled\n",
253 devname
, st
->ss
->name
);
256 if (trustworthy
== LOCAL_ANY
)
259 /* There are three possible sources for 'autof': command line,
260 * ARRAY line in mdadm.conf, or CREATE line in mdadm.conf.
261 * ARRAY takes precedence, then command line, then
264 if (match
&& match
->autof
)
265 c
->autof
= match
->autof
;
267 c
->autof
= ci
->autof
;
269 name_to_use
= info
.name
;
270 if (name_to_use
[0] == 0 &&
271 info
.array
.level
== LEVEL_CONTAINER
) {
272 name_to_use
= info
.text_version
;
273 trustworthy
= METADATA
;
275 if (name_to_use
[0] && trustworthy
!= LOCAL
&&
276 ! c
->require_homehost
&&
277 conf_name_is_free(name_to_use
))
280 /* strip "hostname:" prefix from name if we have decided
281 * to treat it as LOCAL
283 if (trustworthy
== LOCAL
&& strchr(name_to_use
, ':') != NULL
)
284 name_to_use
= strchr(name_to_use
, ':')+1;
286 /* 4/ Check if array exists.
289 pr_err("failed to get exclusive lock on mapfile\n");
290 /* Now check we can get O_EXCL. If not, probably "mdadm -A" has
293 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
296 pr_err("cannot reopen %s: %s.\n",
297 devname
, strerror(errno
));
300 /* Cannot hold it open while we add the device to the array,
301 * so we must release the O_EXCL and depend on the map_lock()
302 * So now is the best time to remove any partitions.
304 remove_partitions(dfd
);
308 mp
= map_by_uuid(&map
, info
.uuid
);
310 mdfd
= open_dev(mp
->devnm
);
316 /* Couldn't find an existing array, maybe make a new one */
317 mdfd
= create_mddev(match
? match
->devname
: NULL
,
318 name_to_use
, c
->autof
, trustworthy
, chosen_name
);
323 sysfs_init(&info
, mdfd
, NULL
);
325 if (set_array_info(mdfd
, st
, &info
) != 0) {
326 pr_err("failed to set array info for %s: %s\n",
327 chosen_name
, strerror(errno
));
333 dinfo
.disk
.major
= major(stb
.st_rdev
);
334 dinfo
.disk
.minor
= minor(stb
.st_rdev
);
335 if (add_disk(mdfd
, st
, &info
, &dinfo
) != 0) {
336 pr_err("failed to add %s to new array %s: %s.\n",
337 devname
, chosen_name
, strerror(errno
));
338 ioctl(mdfd
, STOP_ARRAY
, 0);
342 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
343 GET_OFFSET
| GET_SIZE
));
345 if (!sra
|| !sra
->devs
|| sra
->devs
->disk
.raid_disk
>= 0) {
346 /* It really should be 'none' - must be old buggy
347 * kernel, and mdadm -I may not be able to complete.
350 ioctl(mdfd
, STOP_ARRAY
, NULL
);
351 pr_err("You have an old buggy kernel which cannot support\n --incremental reliably. Aborting.\n");
355 info
.array
.working_disks
= 1;
356 /* 6/ Make sure /var/run/mdadm.map contains this array. */
357 map_update(&map
, fd2devnm(mdfd
),
359 info
.uuid
, chosen_name
);
362 /* - check one drive in array to make sure metadata is a reasonably */
363 /* close match. Reject if not (e.g. different type) */
364 /* - add the device */
368 struct supertype
*st2
;
369 struct mdinfo info2
, *d
;
371 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
372 GET_OFFSET
| GET_SIZE
));
375 strcpy(chosen_name
, mp
->path
);
377 strcpy(chosen_name
, mp
->devnm
);
379 /* It is generally not OK to add non-spare drives to a
380 * running array as they are probably missing because
381 * they failed. However if runstop is 1, then the
382 * array was possibly started early and our best bet is
383 * to add this anyway.
384 * Also if action policy is re-add or better we allow
386 * This doesn't apply to containers as the 'non-spare'
387 * flag has a different meaning. The test has to happen
388 * at the device level there
390 if (!st
->ss
->external
391 && (info
.disk
.state
& (1<<MD_DISK_SYNC
)) != 0
392 && ! policy_action_allows(policy
, st
->ss
->name
,
395 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ainf
) == 0) {
396 pr_err("not adding %s to active array (without --run) %s\n",
397 devname
, chosen_name
);
407 sprintf(dn
, "%d:%d", sra
->devs
->disk
.major
,
408 sra
->devs
->disk
.minor
);
409 dfd2
= dev_open(dn
, O_RDONLY
);
411 pr_err("unable to open %s\n", devname
);
416 if (st2
->ss
->load_super(st2
, dfd2
, NULL
) ||
417 st
->ss
->compare_super(st
, st2
) != 0) {
418 pr_err("metadata mismatch between %s and chosen array %s\n",
419 devname
, chosen_name
);
425 st2
->ss
->getinfo_super(st2
, &info2
, NULL
);
426 st2
->ss
->free_super(st2
);
427 if (info
.array
.level
!= info2
.array
.level
||
428 memcmp(info
.uuid
, info2
.uuid
, 16) != 0 ||
429 info
.array
.raid_disks
!= info2
.array
.raid_disks
) {
430 pr_err("unexpected difference between %s and %s.\n",
431 chosen_name
, devname
);
436 info
.disk
.major
= major(stb
.st_rdev
);
437 info
.disk
.minor
= minor(stb
.st_rdev
);
438 /* add disk needs to know about containers */
439 if (st
->ss
->external
)
440 sra
->array
.level
= LEVEL_CONTAINER
;
441 err
= add_disk(mdfd
, st
, sra
, &info
);
442 if (err
< 0 && errno
== EBUSY
) {
443 /* could be another device present with the same
444 * disk.number. Find and reject any such
446 find_reject(mdfd
, st
, sra
, info
.disk
.number
,
447 info
.events
, c
->verbose
, chosen_name
);
448 err
= add_disk(mdfd
, st
, sra
, &info
);
450 if (err
< 0 && errno
== EINVAL
&&
451 info
.disk
.state
& (1<<MD_DISK_SYNC
)) {
452 /* Maybe it needs to be added as a spare */
453 if (policy_action_allows(policy
, st
->ss
->name
,
455 info
.disk
.state
&= ~(1<<MD_DISK_SYNC
);
456 err
= add_disk(mdfd
, st
, sra
, &info
);
459 pr_err("can only add %s to %s as a spare, and force-spare is not set.\n",
460 devname
, chosen_name
);
463 pr_err("failed to add %s to existing array %s: %s.\n",
464 devname
, chosen_name
, strerror(errno
));
468 info
.array
.working_disks
= 0;
469 for (d
= sra
->devs
; d
; d
=d
->next
)
470 info
.array
.working_disks
++;
473 if (strncmp(chosen_name
, "/dev/md/", 8) == 0)
474 md_devname
= chosen_name
+8;
476 md_devname
= chosen_name
;
478 printf("MD_DEVICE=%s\n", fd2devnm(mdfd
));
479 printf("MD_DEVNAME=%s\n", md_devname
);
480 printf("MD_FOREIGN=%s\n", trustworthy
== FOREIGN
? "yes" : "no");
483 /* 7/ Is there enough devices to possibly start the array? */
484 /* 7a/ if not, finish with success. */
485 if (info
.array
.level
== LEVEL_CONTAINER
) {
487 /* Try to assemble within the container */
488 sysfs_uevent(sra
, "change");
489 if (!c
->export
&& c
->verbose
>= 0)
490 pr_err("container %s now has %d device%s\n",
491 chosen_name
, info
.array
.working_disks
,
492 info
.array
.working_disks
== 1?"":"s");
493 wait_for(chosen_name
, mdfd
);
494 if (st
->ss
->external
)
495 strcpy(devnm
, fd2devnm(mdfd
));
496 if (st
->ss
->load_container
)
497 rv
= st
->ss
->load_container(st
, mdfd
, NULL
);
501 rv
= Incremental_container(st
, chosen_name
, c
, NULL
);
503 /* after spare is added, ping monitor for external metadata
504 * so that it can eg. try to rebuild degraded array */
505 if (st
->ss
->external
)
510 /* We have added something to the array, so need to re-read the
511 * state. Eventually this state should be kept up-to-date as
515 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
516 GET_OFFSET
| GET_SIZE
));
517 active_disks
= count_active(st
, sra
, mdfd
, &avail
, &info
);
518 if (enough(info
.array
.level
, info
.array
.raid_disks
,
519 info
.array
.layout
, info
.array
.state
& 1,
522 printf("MD_STARTED=no\n");
523 } else if (c
->verbose
>= 0)
524 pr_err("%s attached to %s, not enough to start (%d).\n",
525 devname
, chosen_name
, active_disks
);
531 /* - if number of OK devices match expected, or -R and there */
533 /* + add any bitmap file */
534 /* + start the array (auto-readonly). */
536 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ainf
) == 0) {
538 printf("MD_STARTED=already\n");
539 } else if (c
->verbose
>= 0)
540 pr_err("%s attached to %s which is already active.\n",
541 devname
, chosen_name
);
547 if (c
->runstop
> 0 || active_disks
>= info
.array
.working_disks
) {
549 /* Let's try to start it */
551 if (info
.reshape_active
&& !(info
.reshape_active
& RESHAPE_NO_BACKUP
)) {
552 pr_err("%s: This array is being reshaped and cannot be started\n",
554 cont_err("by --incremental. Please use --assemble\n");
557 if (match
&& match
->bitmap_file
) {
558 int bmfd
= open(match
->bitmap_file
, O_RDWR
);
560 pr_err("Could not open bitmap file %s.\n",
564 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
566 pr_err("Failed to set bitmapfile for %s.\n",
572 /* Need to remove from the array any devices which
573 * 'count_active' discerned were too old or inappropriate
575 for (d
= sra
? sra
->devs
: NULL
; d
; d
= d
->next
)
576 if (d
->disk
.state
& (1<<MD_DISK_REMOVED
))
577 remove_disk(mdfd
, st
, sra
, d
);
579 if ((sra
== NULL
|| active_disks
>= info
.array
.working_disks
)
580 && trustworthy
!= FOREIGN
)
581 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
583 rv
= sysfs_set_str(sra
, NULL
,
584 "array_state", "read-auto");
585 /* Array might be O_EXCL which will interfere with
586 * fsck and mount. So re-open without O_EXCL.
591 printf("MD_STARTED=yes\n");
592 } else if (c
->verbose
>= 0)
593 pr_err("%s attached to %s, which has been started.\n",
594 devname
, chosen_name
);
596 wait_for(chosen_name
, mdfd
);
597 /* We just started the array, so some devices
598 * might have been evicted from the array
599 * because their event counts were too old.
600 * If the action=re-add policy is in-force for
601 * those devices we should re-add them now.
603 for (dsk
= sra
->devs
; dsk
; dsk
= dsk
->next
) {
604 if (disk_action_allows(dsk
, st
->ss
->name
, act_re_add
) &&
605 add_disk(mdfd
, st
, sra
, dsk
) == 0)
606 pr_err("%s re-added to %s\n",
607 dsk
->sys_name
, chosen_name
);
610 pr_err("%s attached to %s, but failed to start: %s.\n",
611 devname
, chosen_name
, strerror(errno
));
616 printf("MD_STARTED=unsafe\n");
617 } else if (c
->verbose
>= 0)
618 pr_err("%s attached to %s, not enough to start safely.\n",
619 devname
, chosen_name
);
629 dev_policy_free(policy
);
638 static void find_reject(int mdfd
, struct supertype
*st
, struct mdinfo
*sra
,
639 int number
, __u64 events
, int verbose
,
642 /* Find a device attached to this array with a disk.number of number
643 * and events less than the passed events, and remove the device.
648 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ra
) == 0)
649 return; /* not safe to remove from active arrays
650 * without thinking more */
652 for (d
= sra
->devs
; d
; d
= d
->next
) {
656 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
657 dfd
= dev_open(dn
, O_RDONLY
);
660 if (st
->ss
->load_super(st
, dfd
, NULL
)) {
664 st
->ss
->getinfo_super(st
, &info
, NULL
);
665 st
->ss
->free_super(st
);
668 if (info
.disk
.number
!= number
||
669 info
.events
>= events
)
672 if (d
->disk
.raid_disk
> -1)
673 sysfs_set_str(sra
, d
, "slot", "none");
674 if (sysfs_set_str(sra
, d
, "state", "remove") == 0)
676 pr_err("removing old device %s from %s\n",
677 d
->sys_name
+4, array_name
);
681 static int count_active(struct supertype
*st
, struct mdinfo
*sra
,
682 int mdfd
, char **availp
,
683 struct mdinfo
*bestinfo
)
685 /* count how many devices in sra think they are active */
689 __u64 max_events
= 0;
701 for (d
= sra
->devs
; d
; d
= d
->next
)
703 for (d
= sra
->devs
, devnum
= 0 ; d
; d
= d
->next
, devnum
++) {
709 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
710 dfd
= dev_open(dn
, O_RDONLY
);
713 ok
= st
->ss
->load_super(st
, dfd
, NULL
);
717 info
.array
.raid_disks
= raid_disks
;
718 st
->ss
->getinfo_super(st
, &info
, devmap
+ raid_disks
* devnum
);
720 raid_disks
= info
.array
.raid_disks
;
721 avail
= xcalloc(raid_disks
, 1);
724 best
= xcalloc(raid_disks
, sizeof(int));
725 devmap
= xcalloc(raid_disks
, numdevs
);
727 st
->ss
->getinfo_super(st
, &info
, devmap
);
730 if (info
.disk
.state
& (1<<MD_DISK_SYNC
))
734 max_events
= info
.events
;
735 avail
[info
.disk
.raid_disk
] = 2;
736 best
[info
.disk
.raid_disk
] = devnum
;
737 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
738 } else if (info
.events
== max_events
) {
739 avail
[info
.disk
.raid_disk
] = 2;
740 best
[info
.disk
.raid_disk
] = devnum
;
741 } else if (info
.events
== max_events
-1) {
742 if (avail
[info
.disk
.raid_disk
] == 0) {
743 avail
[info
.disk
.raid_disk
] = 1;
744 best
[info
.disk
.raid_disk
] = devnum
;
746 } else if (info
.events
< max_events
- 1)
748 else if (info
.events
== max_events
+1) {
750 max_events
= info
.events
;
751 for (i
= 0; i
< raid_disks
; i
++)
754 avail
[info
.disk
.raid_disk
] = 2;
755 best
[info
.disk
.raid_disk
] = devnum
;
756 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
757 } else { /* info.events much bigger */
758 memset(avail
, 0, raid_disks
);
759 max_events
= info
.events
;
760 avail
[info
.disk
.raid_disk
] = 2;
761 best
[info
.disk
.raid_disk
] = devnum
;
762 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
764 } else if (info
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
766 st
->ss
->free_super(st
);
770 /* We need to reject any device that thinks the best device is
771 * failed or missing */
772 for (b
= 0; b
< raid_disks
; b
++)
776 for (i
= 0 ; i
< raid_disks
; i
++) {
777 if (i
!= b
&& avail
[i
])
778 if (devmap
[raid_disks
* best
[i
] + b
] == 0) {
779 /* This device thinks 'b' is failed -
782 for (d
=sra
->devs
; devnum
; d
= d
->next
)
784 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
790 /* Also need to reject any spare device with an event count that
793 for (d
= sra
->devs
; d
; d
= d
->next
) {
794 if (!(d
->disk
.state
& (1<<MD_DISK_SYNC
)) &&
795 d
->events
> max_events
)
796 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
800 return cnt
+ replcnt
;
803 /* test if container has degraded member(s) */
804 static int container_members_max_degradation(struct map_ent
*map
, struct map_ent
*me
)
806 mdu_array_info_t array
;
808 int max_degraded
= 0;
810 for(; map
; map
= map
->next
) {
811 if (!metadata_container_matches(map
->metadata
, me
->devnm
))
813 afd
= open_dev(map
->devnm
);
816 /* most accurate information regarding array degradation */
817 if (ioctl(afd
, GET_ARRAY_INFO
, &array
) >= 0) {
818 int degraded
= array
.raid_disks
- array
.active_disks
-
820 if (degraded
> max_degraded
)
821 max_degraded
= degraded
;
825 return (max_degraded
);
828 static int array_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
829 struct map_ent
*target
, int bare
,
830 struct supertype
*st
, int verbose
)
832 /* This device doesn't have any md metadata
833 * The device policy allows 'spare' and if !bare, it allows spare-same-slot.
834 * If 'st' is not set, then we only know that some metadata allows this,
835 * others possibly don't.
836 * So look for a container or array to attach the device to.
837 * Prefer 'target' if that is set and the array is found.
839 * If st is set, then only arrays of that type are considered
840 * Return 0 on success, or some exit code on failure, probably 1.
844 struct map_ent
*mp
, *map
= NULL
;
845 struct mdinfo
*chosen
= NULL
;
848 if (fstat(dfd
, &stb
) != 0)
852 * Now we need to find a suitable array to add this to.
853 * We only accept arrays that:
855 * - are in the same domains as the device
856 * - are of an size for which the device will be useful
857 * and we choose the one that is the most degraded
860 if (map_lock(&map
)) {
861 pr_err("failed to get exclusive lock on mapfile\n");
864 for (mp
= map
; mp
; mp
= mp
->next
) {
865 struct supertype
*st2
;
866 struct domainlist
*dl
= NULL
;
868 unsigned long long devsize
;
869 unsigned long long component_size
= 0;
871 if (is_subarray(mp
->metadata
))
874 st2
= st
->ss
->match_metadata_desc(mp
->metadata
);
876 (st
->minor_version
>= 0 &&
877 st
->minor_version
!= st2
->minor_version
)) {
879 pr_err("not adding %s to %s as metadata type doesn't match\n",
886 sra
= sysfs_read(-1, mp
->devnm
,
887 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
888 GET_DEGRADED
|GET_COMPONENT
|GET_VERSION
);
890 /* Probably a container - no degraded info */
891 sra
= sysfs_read(-1, mp
->devnm
,
892 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
893 GET_COMPONENT
|GET_VERSION
);
895 sra
->array
.failed_disks
= -1;
902 for(i
= 0; !st2
&& superlist
[i
]; i
++)
903 st2
= superlist
[i
]->match_metadata_desc(
907 pr_err("not adding %s to %s as metadata not recognised.\n",
911 /* Need to double check the 'act_spare' permissions applies
914 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
916 if (!bare
&& !policy_action_allows(pol
, st2
->ss
->name
,
917 act_spare_same_slot
))
921 /* update number of failed disks for mostly degraded
922 * container member */
923 if (sra
->array
.failed_disks
== -1)
924 sra
->array
.failed_disks
= container_members_max_degradation(map
, mp
);
926 get_dev_size(dfd
, NULL
, &devsize
);
927 if (sra
->component_size
== 0) {
928 /* true for containers, here we must read superblock
929 * to obtain minimum spare size */
930 struct supertype
*st3
= dup_super(st2
);
931 int mdfd
= open_dev(mp
->devnm
);
936 if (st3
->ss
->load_container
&&
937 !st3
->ss
->load_container(st3
, mdfd
, mp
->path
)) {
938 component_size
= st3
->ss
->min_acceptable_spare_size(st3
);
939 st3
->ss
->free_super(st3
);
944 if ((sra
->component_size
> 0 &&
945 st2
->ss
->avail_size(st2
, devsize
,
947 ? sra
->devs
->data_offset
949 < sra
->component_size
)
951 (sra
->component_size
== 0 && devsize
< component_size
)) {
953 pr_err("not adding %s to %s as it is too small\n",
957 /* test against target.
958 * If 'target' is set and 'bare' is false, we only accept
959 * arrays/containers that match 'target'.
960 * If 'target' is set and 'bare' is true, we prefer the
961 * array which matches 'target'.
962 * target is considered only if we deal with degraded array
964 if (target
&& policy_action_allows(pol
, st2
->ss
->name
,
965 act_spare_same_slot
)) {
966 if (strcmp(target
->metadata
, mp
->metadata
) == 0 &&
967 memcmp(target
->uuid
, mp
->uuid
,
968 sizeof(target
->uuid
)) == 0 &&
969 sra
->array
.failed_disks
> 0) {
970 /* This is our target!! */
975 /* skip to end so we don't check any more */
985 dl
= domain_from_array(sra
, st2
->ss
->name
);
986 if (domain_test(dl
, pol
, st2
->ss
->name
) != 1) {
987 /* domain test fails */
989 pr_err("not adding %s to %s as it is not in a compatible domain\n",
994 /* all tests passed, OK to add to this array */
998 } else if (chosen
->array
.failed_disks
< sra
->array
.failed_disks
) {
1012 /* add current device to chosen array as a spare */
1013 int mdfd
= open_dev(chosen
->sys_name
);
1015 struct mddev_dev devlist
;
1017 devlist
.next
= NULL
;
1019 devlist
.writemostly
= 0;
1020 devlist
.devname
= devname
;
1021 sprintf(devname
, "%d:%d", major(stb
.st_rdev
),
1022 minor(stb
.st_rdev
));
1023 devlist
.disposition
= 'a';
1026 rv
= Manage_subdevs(chosen
->sys_name
, mdfd
, &devlist
,
1032 pr_err("added %s as spare for %s\n",
1033 devname
, chosen
->sys_name
);
1035 pr_err("failed to add %s as spare for %s\n",
1036 devname
, chosen
->sys_name
);
1044 static int partition_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1045 struct supertype
*st
, int verbose
)
1047 /* we know that at least one partition virtual-metadata is
1048 * allowed to incorporate spares like this device. We need to
1049 * find a suitable device to copy partition information from.
1051 * Getting a list of all disk (not partition) devices is
1052 * slightly non-trivial. We could look at /sys/block, but
1053 * that is theoretically due to be removed. Maybe best to use
1054 * /dev/disk/by-path/?* and ignore names ending '-partNN' as
1055 * we depend on this directory of 'path' info. But that fails
1056 * to find loop devices and probably others. Maybe don't
1057 * worry about that, they aren't the real target.
1059 * So: check things in /dev/disk/by-path to see if they are in
1060 * a compatible domain, then load the partition table and see
1061 * if it is OK for the new device, and choose the largest
1062 * partition table that fits.
1066 char *chosen
= NULL
;
1067 unsigned long long chosen_size
= 0;
1068 struct supertype
*chosen_st
= NULL
;
1071 dir
= opendir("/dev/disk/by-path");
1074 while ((de
= readdir(dir
)) != NULL
) {
1076 struct dev_policy
*pol2
= NULL
;
1077 struct domainlist
*domlist
= NULL
;
1080 struct supertype
*st2
= NULL
;
1081 char *devname
= NULL
;
1082 unsigned long long devsectors
;
1084 if (de
->d_ino
== 0 ||
1085 de
->d_name
[0] == '.' ||
1086 (de
->d_type
!= DT_LNK
&& de
->d_type
!= DT_UNKNOWN
))
1089 ep
= de
->d_name
+ strlen(de
->d_name
);
1090 while (ep
> de
->d_name
&&
1093 if (ep
> de
->d_name
+ 5 &&
1094 strncmp(ep
-5, "-part", 5) == 0)
1095 /* This is a partition - skip it */
1098 pol2
= path_policy(de
->d_name
, type_disk
);
1100 domain_merge(&domlist
, pol2
, st
? st
->ss
->name
: NULL
);
1101 if (domain_test(domlist
, pol
, st
? st
->ss
->name
: NULL
) != 1)
1102 /* new device is incompatible with this device. */
1105 domain_free(domlist
);
1108 if (asprintf(&devname
, "/dev/disk/by-path/%s", de
->d_name
) != 1) {
1112 fd
= open(devname
, O_RDONLY
);
1115 if (get_dev_size(fd
, devname
, &devsectors
) == 0)
1120 st2
= dup_super(st
);
1122 st2
= guess_super_type(fd
, guess_partitions
);
1124 st2
->ss
->load_super(st2
, fd
, NULL
) < 0)
1128 /* Check domain policy again, this time referring to metadata */
1129 domain_merge(&domlist
, pol2
, st2
->ss
->name
);
1130 if (domain_test(domlist
, pol
, st2
->ss
->name
) != 1)
1131 /* Incompatible devices for this metadata type */
1133 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
1134 /* Some partition types allow sparing, but not
1140 st2
->ss
->getinfo_super(st2
, &info
, NULL
);
1141 if (info
.component_size
> devsectors
)
1142 /* This partitioning doesn't fit in the device */
1145 /* This is an acceptable device to copy partition
1146 * metadata from. We could just stop here, but I
1147 * think I want to keep looking incase a larger
1148 * metadata which makes better use of the device can
1151 if (chosen
== NULL
||
1152 chosen_size
< info
.component_size
) {
1153 chosen_size
= info
.component_size
;
1158 chosen_st
->ss
->free_super(chosen_st
);
1167 domain_free(domlist
);
1168 dev_policy_free(pol2
);
1170 st2
->ss
->free_super(st2
);
1182 /* 'chosen' is the best device we can find. Let's write its
1183 * metadata to devname dfd is read-only so don't use that
1185 fd
= open(devname
, O_RDWR
);
1187 chosen_st
->ss
->store_super(chosen_st
, fd
);
1191 chosen_st
->ss
->free_super(chosen_st
);
1196 static int is_bare(int dfd
)
1198 unsigned long long size
= 0;
1199 char bufpad
[4096 + 4096];
1200 char *buf
= (char*)(((long)bufpad
+ 4096) & ~4095);
1202 if (lseek(dfd
, 0, SEEK_SET
) != 0 ||
1203 read(dfd
, buf
, 4096) != 4096)
1206 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1208 if (memcmp(buf
, buf
+1, 4095) != 0)
1211 /* OK, first 4K appear blank, try the end. */
1212 get_dev_size(dfd
, NULL
, &size
);
1213 if (lseek(dfd
, size
-4096, SEEK_SET
) < 0 ||
1214 read(dfd
, buf
, 4096) != 4096)
1217 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1219 if (memcmp(buf
, buf
+1, 4095) != 0)
1225 /* adding a spare to a regular array is quite different from adding one to
1226 * a set-of-partitions virtual array.
1227 * This function determines which is worth trying and tries as appropriate.
1228 * Arrays are given priority over partitions.
1230 static int try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1231 struct map_ent
*target
,
1232 struct supertype
*st
, int verbose
)
1237 int partitions_ok
= 0;
1241 /* Can only add a spare if device has at least one domain */
1242 if (pol_find(pol
, pol_domain
) == NULL
)
1244 /* And only if some action allows spares */
1245 if (!policy_action_allows(pol
, st
?st
->ss
->name
:NULL
, act_spare
))
1248 /* Now check if the device is bare.
1249 * bare devices can always be added as a spare
1250 * non-bare devices can only be added if spare-same-slot is permitted,
1251 * and this device is replacing a previous device - in which case 'target'
1254 if (!is_bare(dfd
)) {
1255 /* Must have a target and allow same_slot */
1256 /* Later - may allow force_spare without target */
1258 !policy_action_allows(pol
, st
?st
->ss
->name
:NULL
,
1259 act_spare_same_slot
)) {
1261 pr_err("%s is not bare, so not considering as a spare\n",
1269 /* It might be OK to add this device to an array - need to see
1270 * what arrays might be candidates.
1273 /* just try try 'array' or 'partition' based on this metadata */
1274 if (st
->ss
->add_to_super
)
1275 return array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1278 return partition_try_spare(devname
, dfdp
, pol
,
1281 /* No metadata was specified or found so options are open.
1282 * Check for whether any array metadata, or any partition metadata
1283 * might allow adding the spare. This check is just help to avoid
1284 * a more costly scan of all arrays when we can be sure that will
1287 for (i
= 0; (!arrays_ok
|| !partitions_ok
) && superlist
[i
] ; i
++) {
1288 if (superlist
[i
]->add_to_super
&& !arrays_ok
&&
1289 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1291 if (superlist
[i
]->add_to_super
== NULL
&& !partitions_ok
&&
1292 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1297 rv
= array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1299 if (rv
!= 0 && partitions_ok
)
1300 rv
= partition_try_spare(devname
, dfdp
, pol
, st
, verbose
);
1304 int IncrementalScan(struct context
*c
, char *devnm
)
1306 /* look at every device listed in the 'map' file.
1307 * If one is found that is not running then:
1308 * look in mdadm.conf for bitmap file.
1309 * if one exists, but array has none, add it.
1310 * try to start array in auto-readonly mode
1312 struct map_ent
*mapl
= NULL
;
1314 struct mddev_ident
*devs
, *mddev
;
1320 devs
= conf_get_ident(NULL
);
1323 for (me
= mapl
; me
; me
= me
->next
) {
1324 mdu_array_info_t array
;
1325 mdu_bitmap_file_t bmf
;
1329 if (devnm
&& strcmp(devnm
, me
->devnm
) != 0)
1331 if (devnm
&& me
->metadata
[0] == '/') {
1333 /* member array, need to work on container */
1334 strncpy(container
, me
->metadata
+1, 32);
1336 sl
= strchr(container
, '/');
1343 mdfd
= open_dev(me
->devnm
);
1347 if (!isdigit(me
->metadata
[0])) {
1348 /* must be a container */
1349 struct supertype
*st
= super_by_fd(mdfd
, NULL
);
1351 struct map_ent
*map
= NULL
;
1353 st
->ignore_hw_compat
= 1;
1354 if (st
&& st
->ss
->load_container
)
1355 ret
= st
->ss
->load_container(st
, mdfd
, NULL
);
1357 if (!ret
&& st
&& st
->ss
->container_content
) {
1359 pr_err("failed to get exclusive lock on mapfile\n");
1360 ret
= Incremental_container(st
, me
->path
, c
, only
);
1367 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
) == 0 ||
1372 /* Ok, we can try this one. Maybe it needs a bitmap */
1373 for (mddev
= devs
; mddev
; mddev
= mddev
->next
)
1374 if (mddev
->devname
&& me
->path
1375 && devname_matches(mddev
->devname
, me
->path
))
1377 if (mddev
&& mddev
->bitmap_file
) {
1379 * Note: early kernels will wrongly fail this, so it
1383 if (ioctl(mdfd
, GET_ARRAY_INFO
, &bmf
) < 0) {
1384 int bmfd
= open(mddev
->bitmap_file
, O_RDWR
);
1386 added
= ioctl(mdfd
, SET_BITMAP_FILE
,
1391 if (c
->verbose
>= 0) {
1393 pr_err("Added bitmap %s to %s\n",
1394 mddev
->bitmap_file
, me
->path
);
1395 else if (errno
!= EEXIST
)
1396 pr_err("Failed to add bitmap to %s: %s\n",
1397 me
->path
, strerror(errno
));
1400 /* FIXME check for reshape_active and consider not
1403 sra
= sysfs_read(mdfd
, NULL
, 0);
1405 if (sysfs_set_str(sra
, NULL
,
1406 "array_state", "read-auto") == 0) {
1407 if (c
->verbose
>= 0)
1408 pr_err("started array %s\n",
1409 me
->path
?: me
->devnm
);
1411 pr_err("failed to start array %s: %s\n",
1412 me
->path
?: me
->devnm
,
1422 static char *container2devname(char *devname
)
1424 char *mdname
= NULL
;
1426 if (devname
[0] == '/') {
1427 int fd
= open(devname
, O_RDONLY
);
1429 mdname
= xstrdup(fd2devnm(fd
));
1434 struct map_ent
*mp
, *map
= NULL
;
1436 if (!parse_uuid(devname
, uuid
))
1438 mp
= map_by_uuid(&map
, uuid
);
1440 mdname
= xstrdup(mp
->devnm
);
1447 static int Incremental_container(struct supertype
*st
, char *devname
,
1448 struct context
*c
, char *only
)
1450 /* Collect the contents of this container and for each
1451 * array, choose a device name and assemble the array.
1454 struct mdinfo
*list
;
1456 struct map_ent
*map
= NULL
;
1459 struct mddev_ident
*match
;
1461 struct domainlist
*domains
;
1462 struct map_ent
*smp
;
1469 st
->ss
->getinfo_super(st
, &info
, NULL
);
1471 if ((c
->runstop
> 0 && info
.container_enough
>= 0) ||
1472 info
.container_enough
> 0)
1476 printf("MD_STARTED=no\n");
1477 } else if (c
->verbose
)
1478 pr_err("not enough devices to start the container\n");
1482 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
1483 if (match
== NULL
&& rv
== 2)
1486 /* Need to compute 'trustworthy' */
1488 trustworthy
= LOCAL
;
1489 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
1490 trustworthy
= LOCAL
;
1491 else if (st
->ss
->match_home(st
, "any") == 1)
1492 trustworthy
= LOCAL
;
1494 trustworthy
= FOREIGN
;
1496 list
= st
->ss
->container_content(st
, NULL
);
1497 /* when nothing to activate - quit */
1500 printf("MD_STARTED=nothing\n");
1504 for (ra
= list
; ra
; ra
= ra
->next
) {
1506 char chosen_name
[1024];
1508 struct mddev_ident
*match
= NULL
;
1511 /* do not activate arrays blocked by metadata handler */
1512 if (ra
->array
.state
& (1 << MD_SB_BLOCK_VOLUME
)) {
1513 pr_err("Cannot activate array %s in %s.\n",
1514 ra
->text_version
, devname
);
1518 mp
= map_by_uuid(&map
, ra
->uuid
);
1521 mdfd
= open_dev(mp
->devnm
);
1523 strcpy(chosen_name
, mp
->path
);
1525 strcpy(chosen_name
, mp
->devnm
);
1528 /* Check in mdadm.conf for container == devname and
1529 * member == ra->text_version after second slash.
1531 char *sub
= strchr(ra
->text_version
+1, '/');
1532 struct mddev_ident
*array_list
;
1535 array_list
= conf_get_ident(NULL
);
1538 for(; array_list
; array_list
= array_list
->next
) {
1540 if (array_list
->member
== NULL
||
1541 array_list
->container
== NULL
)
1543 if (strcmp(array_list
->member
, sub
) != 0)
1545 if (array_list
->uuid_set
&&
1546 !same_uuid(ra
->uuid
, array_list
->uuid
, st
->ss
->swapuuid
))
1548 dn
= container2devname(array_list
->container
);
1551 if (strncmp(dn
, ra
->text_version
+1,
1553 ra
->text_version
[strlen(dn
)+1] != '/') {
1558 /* we have a match */
1561 pr_err("match found for member %s\n",
1562 array_list
->member
);
1566 if (match
&& match
->devname
&&
1567 strcasecmp(match
->devname
, "<ignore>") == 0) {
1569 pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
1570 match
->container
, match
->member
);
1574 trustworthy
= LOCAL
;
1576 mdfd
= create_mddev(match
? match
->devname
: NULL
,
1582 if (only
&& (!mp
|| strcmp(mp
->devnm
, only
) != 0))
1586 pr_err("failed to open %s: %s.\n",
1587 chosen_name
, strerror(errno
));
1591 assemble_container_content(st
, mdfd
, ra
, c
,
1592 chosen_name
, &result
);
1595 if (c
->export
&& result
) {
1597 printf("MD_STARTED");
1598 if (result
& INCR_NO
) {
1599 printf("%cno", sep
);
1602 if (result
& INCR_UNSAFE
) {
1603 printf("%cunsafe", sep
);
1606 if (result
& INCR_ALREADY
) {
1607 printf("%calready", sep
);
1610 if (result
& INCR_YES
) {
1611 printf("%cyes", sep
);
1617 /* don't move spares to container with volume being activated
1618 when all volumes are blocked */
1619 if (ra_all
== ra_blocked
)
1622 /* Now move all suitable spares from spare container */
1623 domains
= domain_from_array(list
, st
->ss
->name
);
1624 memcpy(suuid
, uuid_zero
, sizeof(int[4]));
1626 (smp
= map_by_uuid(&map
, suuid
)) != NULL
&&
1627 (sfd
= open(smp
->path
, O_RDONLY
)) >= 0) {
1628 /* spare container found */
1629 struct supertype
*sst
=
1630 super_imsm
.match_metadata_desc("imsm");
1631 struct mdinfo
*sinfo
;
1632 unsigned long long min_size
= 0;
1633 if (st
->ss
->min_acceptable_spare_size
)
1634 min_size
= st
->ss
->min_acceptable_spare_size(st
);
1635 if (!sst
->ss
->load_container(sst
, sfd
, NULL
)) {
1637 sinfo
= container_choose_spares(sst
, min_size
,
1640 sst
->ss
->free_super(sst
);
1643 struct mdinfo
*disks
= sinfo
->devs
;
1645 /* move spare from spare
1646 * container to currently
1652 makedev(disks
->disk
.major
,
1653 disks
->disk
.minor
)))
1655 disks
= disks
->next
;
1658 pr_err("Added %d spare%s to %s\n",
1659 count
, count
>1?"s":"", devname
);
1665 domain_free(domains
);
1669 static void run_udisks(char *arg1
, char *arg2
)
1674 execl("/usr/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1675 execl("/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1678 while (pid
> 0 && wait(&status
) != pid
)
1683 * IncrementalRemove - Attempt to see if the passed in device belongs to any
1684 * raid arrays, and if so first fail (if needed) and then remove the device.
1686 * @devname - The device we want to remove
1687 * @id_path - name as found in /dev/disk/by-path for this device
1689 * Note: the device name must be a kernel name like "sda", so
1690 * that we can find it in /proc/mdstat
1692 int IncrementalRemove(char *devname
, char *id_path
, int verbose
)
1696 struct mdstat_ent
*ent
;
1697 struct mddev_dev devlist
;
1702 dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
1704 if (strchr(devname
, '/')) {
1705 pr_err("incremental removal requires a kernel device name, not a file: %s\n", devname
);
1708 ent
= mdstat_by_component(devname
);
1711 pr_err("%s does not appear to be a component of any array\n", devname
);
1714 sysfs_init(&mdi
, -1, ent
->devnm
);
1715 mdfd
= open_dev_excl(ent
->devnm
);
1718 if (sysfs_get_str(&mdi
, NULL
, "array_state",
1719 buf
, sizeof(buf
)) > 0) {
1720 if (strncmp(buf
, "active", 6) == 0 ||
1721 strncmp(buf
, "clean", 5) == 0)
1722 sysfs_set_str(&mdi
, NULL
,
1723 "array_state", "read-auto");
1726 mdfd
= open_dev(ent
->devnm
);
1729 pr_err("Cannot open array %s!!\n", ent
->devnm
);
1735 struct map_ent
*map
= NULL
, *me
;
1736 me
= map_by_devnm(&map
, ent
->devnm
);
1738 policy_save_path(id_path
, me
);
1742 memset(&devlist
, 0, sizeof(devlist
));
1743 devlist
.devname
= devname
;
1744 devlist
.disposition
= 'f';
1745 /* for a container, we must fail each member array */
1746 if (ent
->metadata_version
&&
1747 strncmp(ent
->metadata_version
, "external:", 9) == 0) {
1748 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
1749 struct mdstat_ent
*memb
;
1750 for (memb
= mdstat
; memb
; memb
= memb
->next
)
1751 if (is_container_member(memb
, ent
->devnm
)) {
1752 int subfd
= open_dev(memb
->devnm
);
1754 rv
|= Manage_subdevs(
1756 &devlist
, verbose
, 0,
1761 free_mdstat(mdstat
);
1763 rv
|= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1764 verbose
, 0, NULL
, 0);
1766 /* Failed due to EBUSY, try to stop the array.
1767 * Give udisks a chance to unmount it first.
1769 int devid
= devnm2devid(ent
->devnm
);
1770 run_udisks("--unmount", map_dev(major(devid
),minor(devid
), 0));
1771 rv
= Manage_stop(ent
->devnm
, mdfd
, verbose
, 1);
1773 /* At least we can try to trigger a 'remove' */
1774 sysfs_uevent(&mdi
, "remove");
1777 pr_err("Fail to stop %s too.\n", ent
->devnm
);
1780 devlist
.disposition
= 'r';
1781 rv
= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1782 verbose
, 0, NULL
, 0);