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
, 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 /* Couldn't find an existing array, maybe make a new one */
316 mdfd
= create_mddev(match
? match
->devname
: NULL
,
317 name_to_use
, c
->autof
, trustworthy
, chosen_name
);
322 sysfs_init(&info
, mdfd
, NULL
);
324 if (set_array_info(mdfd
, st
, &info
) != 0) {
325 pr_err("failed to set array info for %s: %s\n",
326 chosen_name
, strerror(errno
));
332 dinfo
.disk
.major
= major(stb
.st_rdev
);
333 dinfo
.disk
.minor
= minor(stb
.st_rdev
);
334 if (add_disk(mdfd
, st
, &info
, &dinfo
) != 0) {
335 pr_err("failed to add %s to new array %s: %s.\n",
336 devname
, chosen_name
, strerror(errno
));
337 ioctl(mdfd
, STOP_ARRAY
, 0);
341 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
342 GET_OFFSET
| GET_SIZE
));
344 if (!sra
|| !sra
->devs
|| sra
->devs
->disk
.raid_disk
>= 0) {
345 /* It really should be 'none' - must be old buggy
346 * kernel, and mdadm -I may not be able to complete.
349 ioctl(mdfd
, STOP_ARRAY
, NULL
);
350 pr_err("You have an old buggy kernel which cannot support\n --incremental reliably. Aborting.\n");
354 info
.array
.working_disks
= 1;
355 /* 6/ Make sure /var/run/mdadm.map contains this array. */
356 map_update(&map
, fd2devnm(mdfd
),
358 info
.uuid
, chosen_name
);
361 /* - check one drive in array to make sure metadata is a reasonably */
362 /* close match. Reject if not (e.g. different type) */
363 /* - add the device */
367 struct supertype
*st2
;
368 struct mdinfo info2
, *d
;
370 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
371 GET_OFFSET
| GET_SIZE
));
374 strcpy(chosen_name
, mp
->path
);
376 strcpy(chosen_name
, mp
->devnm
);
378 /* It is generally not OK to add non-spare drives to a
379 * running array as they are probably missing because
380 * they failed. However if runstop is 1, then the
381 * array was possibly started early and our best bet is
382 * to add this anyway.
383 * Also if action policy is re-add or better we allow
385 * This doesn't apply to containers as the 'non-spare'
386 * flag has a different meaning. The test has to happen
387 * at the device level there
389 if (!st
->ss
->external
390 && (info
.disk
.state
& (1<<MD_DISK_SYNC
)) != 0
391 && ! policy_action_allows(policy
, st
->ss
->name
,
394 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ainf
) == 0) {
395 pr_err("not adding %s to active array (without --run) %s\n",
396 devname
, chosen_name
);
406 sprintf(dn
, "%d:%d", sra
->devs
->disk
.major
,
407 sra
->devs
->disk
.minor
);
408 dfd2
= dev_open(dn
, O_RDONLY
);
410 pr_err("unable to open %s\n", devname
);
415 if (st2
->ss
->load_super(st2
, dfd2
, NULL
) ||
416 st
->ss
->compare_super(st
, st2
) != 0) {
417 pr_err("metadata mismatch between %s and chosen array %s\n",
418 devname
, chosen_name
);
424 st2
->ss
->getinfo_super(st2
, &info2
, NULL
);
425 st2
->ss
->free_super(st2
);
426 if (info
.array
.level
!= info2
.array
.level
||
427 memcmp(info
.uuid
, info2
.uuid
, 16) != 0 ||
428 info
.array
.raid_disks
!= info2
.array
.raid_disks
) {
429 pr_err("unexpected difference between %s and %s.\n",
430 chosen_name
, devname
);
435 info
.disk
.major
= major(stb
.st_rdev
);
436 info
.disk
.minor
= minor(stb
.st_rdev
);
437 /* add disk needs to know about containers */
438 if (st
->ss
->external
)
439 sra
->array
.level
= LEVEL_CONTAINER
;
440 err
= add_disk(mdfd
, st
, sra
, &info
);
441 if (err
< 0 && errno
== EBUSY
) {
442 /* could be another device present with the same
443 * disk.number. Find and reject any such
445 find_reject(mdfd
, st
, sra
, info
.disk
.number
,
446 info
.events
, c
->verbose
, chosen_name
);
447 err
= add_disk(mdfd
, st
, sra
, &info
);
449 if (err
< 0 && errno
== EINVAL
&&
450 info
.disk
.state
& (1<<MD_DISK_SYNC
)) {
451 /* Maybe it needs to be added as a spare */
452 if (policy_action_allows(policy
, st
->ss
->name
,
454 info
.disk
.state
&= ~(1<<MD_DISK_SYNC
);
455 err
= add_disk(mdfd
, st
, sra
, &info
);
458 pr_err("can only add %s to %s as a spare, and force-spare is not set.\n",
459 devname
, chosen_name
);
462 pr_err("failed to add %s to existing array %s: %s.\n",
463 devname
, chosen_name
, strerror(errno
));
467 info
.array
.working_disks
= 0;
468 for (d
= sra
->devs
; d
; d
=d
->next
)
469 info
.array
.working_disks
++;
472 if (strncmp(chosen_name
, "/dev/md/", 8) == 0)
473 md_devname
= chosen_name
+8;
475 md_devname
= chosen_name
;
477 printf("MD_DEVICE=%s\n", fd2devnm(mdfd
));
478 printf("MD_DEVNAME=%s\n", md_devname
);
479 printf("MD_FOREIGN=%s\n", trustworthy
== FOREIGN
? "yes" : "no");
482 /* 7/ Is there enough devices to possibly start the array? */
483 /* 7a/ if not, finish with success. */
484 if (info
.array
.level
== LEVEL_CONTAINER
) {
486 /* Try to assemble within the container */
487 sysfs_uevent(sra
, "change");
488 if (!c
->export
&& c
->verbose
>= 0)
489 pr_err("container %s now has %d device%s\n",
490 chosen_name
, info
.array
.working_disks
,
491 info
.array
.working_disks
== 1?"":"s");
492 wait_for(chosen_name
, mdfd
);
493 if (st
->ss
->external
)
494 strcpy(devnm
, fd2devnm(mdfd
));
495 if (st
->ss
->load_container
)
496 rv
= st
->ss
->load_container(st
, mdfd
, NULL
);
500 rv
= Incremental_container(st
, chosen_name
, c
, NULL
);
502 /* after spare is added, ping monitor for external metadata
503 * so that it can eg. try to rebuild degraded array */
504 if (st
->ss
->external
)
509 /* We have added something to the array, so need to re-read the
510 * state. Eventually this state should be kept up-to-date as
514 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
515 GET_OFFSET
| GET_SIZE
));
516 active_disks
= count_active(st
, sra
, mdfd
, &avail
, &info
);
517 if (enough(info
.array
.level
, info
.array
.raid_disks
,
518 info
.array
.layout
, info
.array
.state
& 1,
521 printf("MD_STARTED=no\n");
522 } else if (c
->verbose
>= 0)
523 pr_err("%s attached to %s, not enough to start (%d).\n",
524 devname
, chosen_name
, active_disks
);
530 /* - if number of OK devices match expected, or -R and there */
532 /* + add any bitmap file */
533 /* + start the array (auto-readonly). */
535 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ainf
) == 0) {
537 printf("MD_STARTED=already\n");
538 } else if (c
->verbose
>= 0)
539 pr_err("%s attached to %s which is already active.\n",
540 devname
, chosen_name
);
546 if (c
->runstop
> 0 || active_disks
>= info
.array
.working_disks
) {
548 /* Let's try to start it */
550 if (info
.reshape_active
&& !(info
.reshape_active
& RESHAPE_NO_BACKUP
)) {
551 pr_err("%s: This array is being reshaped and cannot be started\n",
553 cont_err("by --incremental. Please use --assemble\n");
556 if (match
&& match
->bitmap_file
) {
557 int bmfd
= open(match
->bitmap_file
, O_RDWR
);
559 pr_err("Could not open bitmap file %s.\n",
563 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
565 pr_err("Failed to set bitmapfile for %s.\n",
571 /* Need to remove from the array any devices which
572 * 'count_active' discerned were too old or inappropriate
574 for (d
= sra
? sra
->devs
: NULL
; d
; d
= d
->next
)
575 if (d
->disk
.state
& (1<<MD_DISK_REMOVED
))
576 remove_disk(mdfd
, st
, sra
, d
);
578 if ((sra
== NULL
|| active_disks
>= info
.array
.working_disks
)
579 && trustworthy
!= FOREIGN
)
580 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
582 rv
= sysfs_set_str(sra
, NULL
,
583 "array_state", "read-auto");
584 /* Array might be O_EXCL which will interfere with
585 * fsck and mount. So re-open without O_EXCL.
590 printf("MD_STARTED=yes\n");
591 } else if (c
->verbose
>= 0)
592 pr_err("%s attached to %s, which has been started.\n",
593 devname
, chosen_name
);
595 wait_for(chosen_name
, mdfd
);
596 /* We just started the array, so some devices
597 * might have been evicted from the array
598 * because their event counts were too old.
599 * If the action=re-add policy is in-force for
600 * those devices we should re-add them now.
602 for (dsk
= sra
->devs
; dsk
; dsk
= dsk
->next
) {
603 if (disk_action_allows(dsk
, st
->ss
->name
, act_re_add
) &&
604 add_disk(mdfd
, st
, sra
, dsk
) == 0)
605 pr_err("%s re-added to %s\n",
606 dsk
->sys_name
, chosen_name
);
609 pr_err("%s attached to %s, but failed to start: %s.\n",
610 devname
, chosen_name
, strerror(errno
));
615 printf("MD_STARTED=unsafe\n");
616 } else if (c
->verbose
>= 0)
617 pr_err("%s attached to %s, not enough to start safely.\n",
618 devname
, chosen_name
);
628 dev_policy_free(policy
);
637 static void find_reject(int mdfd
, struct supertype
*st
, struct mdinfo
*sra
,
638 int number
, __u64 events
, int verbose
,
641 /* Find a device attached to this array with a disk.number of number
642 * and events less than the passed events, and remove the device.
647 if (ioctl(mdfd
, GET_ARRAY_INFO
, &ra
) == 0)
648 return; /* not safe to remove from active arrays
649 * without thinking more */
651 for (d
= sra
->devs
; d
; d
= d
->next
) {
655 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
656 dfd
= dev_open(dn
, O_RDONLY
);
659 if (st
->ss
->load_super(st
, dfd
, NULL
)) {
663 st
->ss
->getinfo_super(st
, &info
, NULL
);
664 st
->ss
->free_super(st
);
667 if (info
.disk
.number
!= number
||
668 info
.events
>= events
)
671 if (d
->disk
.raid_disk
> -1)
672 sysfs_set_str(sra
, d
, "slot", "none");
673 if (sysfs_set_str(sra
, d
, "state", "remove") == 0)
675 pr_err("removing old device %s from %s\n",
676 d
->sys_name
+4, array_name
);
680 static int count_active(struct supertype
*st
, struct mdinfo
*sra
,
681 int mdfd
, char **availp
,
682 struct mdinfo
*bestinfo
)
684 /* count how many devices in sra think they are active */
688 __u64 max_events
= 0;
700 for (d
= sra
->devs
; d
; d
= d
->next
)
702 for (d
= sra
->devs
, devnum
= 0 ; d
; d
= d
->next
, devnum
++) {
708 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
709 dfd
= dev_open(dn
, O_RDONLY
);
712 ok
= st
->ss
->load_super(st
, dfd
, NULL
);
716 info
.array
.raid_disks
= raid_disks
;
717 st
->ss
->getinfo_super(st
, &info
, devmap
+ raid_disks
* devnum
);
719 raid_disks
= info
.array
.raid_disks
;
720 avail
= xcalloc(raid_disks
, 1);
723 best
= xcalloc(raid_disks
, sizeof(int));
724 devmap
= xcalloc(raid_disks
, numdevs
);
726 st
->ss
->getinfo_super(st
, &info
, devmap
);
729 if (info
.disk
.state
& (1<<MD_DISK_SYNC
))
733 max_events
= info
.events
;
734 avail
[info
.disk
.raid_disk
] = 2;
735 best
[info
.disk
.raid_disk
] = devnum
;
736 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
737 } else if (info
.events
== max_events
) {
738 avail
[info
.disk
.raid_disk
] = 2;
739 best
[info
.disk
.raid_disk
] = devnum
;
740 } else if (info
.events
== max_events
-1) {
741 if (avail
[info
.disk
.raid_disk
] == 0) {
742 avail
[info
.disk
.raid_disk
] = 1;
743 best
[info
.disk
.raid_disk
] = devnum
;
745 } else if (info
.events
< max_events
- 1)
747 else if (info
.events
== max_events
+1) {
749 max_events
= info
.events
;
750 for (i
= 0; i
< raid_disks
; i
++)
753 avail
[info
.disk
.raid_disk
] = 2;
754 best
[info
.disk
.raid_disk
] = devnum
;
755 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
756 } else { /* info.events much bigger */
757 memset(avail
, 0, raid_disks
);
758 max_events
= info
.events
;
759 avail
[info
.disk
.raid_disk
] = 2;
760 best
[info
.disk
.raid_disk
] = devnum
;
761 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
763 } else if (info
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
765 st
->ss
->free_super(st
);
769 /* We need to reject any device that thinks the best device is
770 * failed or missing */
771 for (b
= 0; b
< raid_disks
; b
++)
775 for (i
= 0 ; i
< raid_disks
; i
++) {
776 if (i
!= b
&& avail
[i
])
777 if (devmap
[raid_disks
* best
[i
] + b
] == 0) {
778 /* This device thinks 'b' is failed -
781 for (d
=sra
->devs
; devnum
; d
= d
->next
)
783 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
789 /* Also need to reject any spare device with an event count that
792 for (d
= sra
->devs
; d
; d
= d
->next
) {
793 if (!(d
->disk
.state
& (1<<MD_DISK_SYNC
)) &&
794 d
->events
> max_events
)
795 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
799 return cnt
+ replcnt
;
802 /* test if container has degraded member(s) */
803 static int container_members_max_degradation(struct map_ent
*map
, struct map_ent
*me
)
805 mdu_array_info_t array
;
807 int max_degraded
= 0;
809 for(; map
; map
= map
->next
) {
810 if (!metadata_container_matches(map
->metadata
, me
->devnm
))
812 afd
= open_dev(map
->devnm
);
815 /* most accurate information regarding array degradation */
816 if (ioctl(afd
, GET_ARRAY_INFO
, &array
) >= 0) {
817 int degraded
= array
.raid_disks
- array
.active_disks
-
819 if (degraded
> max_degraded
)
820 max_degraded
= degraded
;
824 return (max_degraded
);
827 static int array_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
828 struct map_ent
*target
, int bare
,
829 struct supertype
*st
, int verbose
)
831 /* This device doesn't have any md metadata
832 * The device policy allows 'spare' and if !bare, it allows spare-same-slot.
833 * If 'st' is not set, then we only know that some metadata allows this,
834 * others possibly don't.
835 * So look for a container or array to attach the device to.
836 * Prefer 'target' if that is set and the array is found.
838 * If st is set, then only arrays of that type are considered
839 * Return 0 on success, or some exit code on failure, probably 1.
843 struct map_ent
*mp
, *map
= NULL
;
844 struct mdinfo
*chosen
= NULL
;
847 if (fstat(dfd
, &stb
) != 0)
851 * Now we need to find a suitable array to add this to.
852 * We only accept arrays that:
854 * - are in the same domains as the device
855 * - are of an size for which the device will be useful
856 * and we choose the one that is the most degraded
859 if (map_lock(&map
)) {
860 pr_err("failed to get exclusive lock on mapfile\n");
863 for (mp
= map
; mp
; mp
= mp
->next
) {
864 struct supertype
*st2
;
865 struct domainlist
*dl
= NULL
;
867 unsigned long long devsize
;
868 unsigned long long component_size
= 0;
870 if (is_subarray(mp
->metadata
))
873 st2
= st
->ss
->match_metadata_desc(mp
->metadata
);
875 (st
->minor_version
>= 0 &&
876 st
->minor_version
!= st2
->minor_version
)) {
878 pr_err("not adding %s to %s as metadata type doesn't match\n",
885 sra
= sysfs_read(-1, mp
->devnm
,
886 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
887 GET_DEGRADED
|GET_COMPONENT
|GET_VERSION
);
889 /* Probably a container - no degraded info */
890 sra
= sysfs_read(-1, mp
->devnm
,
891 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
892 GET_COMPONENT
|GET_VERSION
);
894 sra
->array
.failed_disks
= -1;
901 for(i
= 0; !st2
&& superlist
[i
]; i
++)
902 st2
= superlist
[i
]->match_metadata_desc(
906 pr_err("not adding %s to %s as metadata not recognised.\n",
910 /* Need to double check the 'act_spare' permissions applies
913 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
915 if (!bare
&& !policy_action_allows(pol
, st2
->ss
->name
,
916 act_spare_same_slot
))
920 /* update number of failed disks for mostly degraded
921 * container member */
922 if (sra
->array
.failed_disks
== -1)
923 sra
->array
.failed_disks
= container_members_max_degradation(map
, mp
);
925 get_dev_size(dfd
, NULL
, &devsize
);
926 if (sra
->component_size
== 0) {
927 /* true for containers, here we must read superblock
928 * to obtain minimum spare size */
929 struct supertype
*st3
= dup_super(st2
);
930 int mdfd
= open_dev(mp
->devnm
);
935 if (st3
->ss
->load_container
&&
936 !st3
->ss
->load_container(st3
, mdfd
, mp
->path
)) {
937 component_size
= st3
->ss
->min_acceptable_spare_size(st3
);
938 st3
->ss
->free_super(st3
);
943 if ((sra
->component_size
> 0 &&
944 st2
->ss
->avail_size(st2
, devsize
,
946 ? sra
->devs
->data_offset
948 < sra
->component_size
)
950 (sra
->component_size
== 0 && devsize
< component_size
)) {
952 pr_err("not adding %s to %s as it is too small\n",
956 /* test against target.
957 * If 'target' is set and 'bare' is false, we only accept
958 * arrays/containers that match 'target'.
959 * If 'target' is set and 'bare' is true, we prefer the
960 * array which matches 'target'.
961 * target is considered only if we deal with degraded array
963 if (target
&& policy_action_allows(pol
, st2
->ss
->name
,
964 act_spare_same_slot
)) {
965 if (strcmp(target
->metadata
, mp
->metadata
) == 0 &&
966 memcmp(target
->uuid
, mp
->uuid
,
967 sizeof(target
->uuid
)) == 0 &&
968 sra
->array
.failed_disks
> 0) {
969 /* This is our target!! */
974 /* skip to end so we don't check any more */
984 dl
= domain_from_array(sra
, st2
->ss
->name
);
985 if (domain_test(dl
, pol
, st2
->ss
->name
) != 1) {
986 /* domain test fails */
988 pr_err("not adding %s to %s as it is not in a compatible domain\n",
993 /* all tests passed, OK to add to this array */
997 } else if (chosen
->array
.failed_disks
< sra
->array
.failed_disks
) {
1011 /* add current device to chosen array as a spare */
1012 int mdfd
= open_dev(chosen
->sys_name
);
1014 struct mddev_dev devlist
;
1016 devlist
.next
= NULL
;
1018 devlist
.writemostly
= 0;
1019 devlist
.devname
= devname
;
1020 sprintf(devname
, "%d:%d", major(stb
.st_rdev
),
1021 minor(stb
.st_rdev
));
1022 devlist
.disposition
= 'a';
1025 rv
= Manage_subdevs(chosen
->sys_name
, mdfd
, &devlist
,
1031 pr_err("added %s as spare for %s\n",
1032 devname
, chosen
->sys_name
);
1034 pr_err("failed to add %s as spare for %s\n",
1035 devname
, chosen
->sys_name
);
1043 static int partition_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1044 struct supertype
*st
, int verbose
)
1046 /* we know that at least one partition virtual-metadata is
1047 * allowed to incorporate spares like this device. We need to
1048 * find a suitable device to copy partition information from.
1050 * Getting a list of all disk (not partition) devices is
1051 * slightly non-trivial. We could look at /sys/block, but
1052 * that is theoretically due to be removed. Maybe best to use
1053 * /dev/disk/by-path/?* and ignore names ending '-partNN' as
1054 * we depend on this directory of 'path' info. But that fails
1055 * to find loop devices and probably others. Maybe don't
1056 * worry about that, they aren't the real target.
1058 * So: check things in /dev/disk/by-path to see if they are in
1059 * a compatible domain, then load the partition table and see
1060 * if it is OK for the new device, and choose the largest
1061 * partition table that fits.
1065 char *chosen
= NULL
;
1066 unsigned long long chosen_size
= 0;
1067 struct supertype
*chosen_st
= NULL
;
1070 dir
= opendir("/dev/disk/by-path");
1073 while ((de
= readdir(dir
)) != NULL
) {
1075 struct dev_policy
*pol2
= NULL
;
1076 struct domainlist
*domlist
= NULL
;
1079 struct supertype
*st2
= NULL
;
1080 char *devname
= NULL
;
1081 unsigned long long devsectors
;
1083 if (de
->d_ino
== 0 ||
1084 de
->d_name
[0] == '.' ||
1085 (de
->d_type
!= DT_LNK
&& de
->d_type
!= DT_UNKNOWN
))
1088 ep
= de
->d_name
+ strlen(de
->d_name
);
1089 while (ep
> de
->d_name
&&
1092 if (ep
> de
->d_name
+ 5 &&
1093 strncmp(ep
-5, "-part", 5) == 0)
1094 /* This is a partition - skip it */
1097 pol2
= path_policy(de
->d_name
, type_disk
);
1099 domain_merge(&domlist
, pol2
, st
? st
->ss
->name
: NULL
);
1100 if (domain_test(domlist
, pol
, st
? st
->ss
->name
: NULL
) != 1)
1101 /* new device is incompatible with this device. */
1104 domain_free(domlist
);
1107 if (asprintf(&devname
, "/dev/disk/by-path/%s", de
->d_name
) != 1) {
1111 fd
= open(devname
, O_RDONLY
);
1114 if (get_dev_size(fd
, devname
, &devsectors
) == 0)
1119 st2
= dup_super(st
);
1121 st2
= guess_super_type(fd
, guess_partitions
);
1123 st2
->ss
->load_super(st2
, fd
, NULL
) < 0)
1125 st2
->ignore_hw_compat
= 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 if (st
&& st
->ss
->load_container
)
1354 ret
= st
->ss
->load_container(st
, mdfd
, NULL
);
1356 if (!ret
&& st
&& st
->ss
->container_content
) {
1358 pr_err("failed to get exclusive lock on mapfile\n");
1359 ret
= Incremental_container(st
, me
->path
, c
, only
);
1366 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
) == 0 ||
1371 /* Ok, we can try this one. Maybe it needs a bitmap */
1372 for (mddev
= devs
; mddev
; mddev
= mddev
->next
)
1373 if (mddev
->devname
&& me
->path
1374 && devname_matches(mddev
->devname
, me
->path
))
1376 if (mddev
&& mddev
->bitmap_file
) {
1378 * Note: early kernels will wrongly fail this, so it
1382 if (ioctl(mdfd
, GET_ARRAY_INFO
, &bmf
) < 0) {
1383 int bmfd
= open(mddev
->bitmap_file
, O_RDWR
);
1385 added
= ioctl(mdfd
, SET_BITMAP_FILE
,
1390 if (c
->verbose
>= 0) {
1392 pr_err("Added bitmap %s to %s\n",
1393 mddev
->bitmap_file
, me
->path
);
1394 else if (errno
!= EEXIST
)
1395 pr_err("Failed to add bitmap to %s: %s\n",
1396 me
->path
, strerror(errno
));
1399 /* FIXME check for reshape_active and consider not
1402 sra
= sysfs_read(mdfd
, NULL
, 0);
1404 if (sysfs_set_str(sra
, NULL
,
1405 "array_state", "read-auto") == 0) {
1406 if (c
->verbose
>= 0)
1407 pr_err("started array %s\n",
1408 me
->path
?: me
->devnm
);
1410 pr_err("failed to start array %s: %s\n",
1411 me
->path
?: me
->devnm
,
1421 static char *container2devname(char *devname
)
1423 char *mdname
= NULL
;
1425 if (devname
[0] == '/') {
1426 int fd
= open(devname
, O_RDONLY
);
1428 mdname
= xstrdup(fd2devnm(fd
));
1433 struct map_ent
*mp
, *map
= NULL
;
1435 if (!parse_uuid(devname
, uuid
))
1437 mp
= map_by_uuid(&map
, uuid
);
1439 mdname
= xstrdup(mp
->devnm
);
1446 static int Incremental_container(struct supertype
*st
, char *devname
,
1447 struct context
*c
, char *only
)
1449 /* Collect the contents of this container and for each
1450 * array, choose a device name and assemble the array.
1453 struct mdinfo
*list
;
1455 struct map_ent
*map
= NULL
;
1458 struct mddev_ident
*match
;
1460 struct domainlist
*domains
;
1461 struct map_ent
*smp
;
1468 st
->ss
->getinfo_super(st
, &info
, NULL
);
1470 if ((c
->runstop
> 0 && info
.container_enough
>= 0) ||
1471 info
.container_enough
> 0)
1475 printf("MD_STARTED=no\n");
1476 } else if (c
->verbose
)
1477 pr_err("not enough devices to start the container\n");
1481 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
1482 if (match
== NULL
&& rv
== 2)
1485 /* Need to compute 'trustworthy' */
1487 trustworthy
= LOCAL
;
1488 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
1489 trustworthy
= LOCAL
;
1490 else if (st
->ss
->match_home(st
, "any") == 1)
1491 trustworthy
= LOCAL
;
1493 trustworthy
= FOREIGN
;
1495 list
= st
->ss
->container_content(st
, NULL
);
1496 /* when nothing to activate - quit */
1499 printf("MD_STARTED=nothing\n");
1503 for (ra
= list
; ra
; ra
= ra
->next
) {
1505 char chosen_name
[1024];
1507 struct mddev_ident
*match
= NULL
;
1510 /* do not activate arrays blocked by metadata handler */
1511 if (ra
->array
.state
& (1 << MD_SB_BLOCK_VOLUME
)) {
1512 pr_err("Cannot activate array %s in %s.\n",
1513 ra
->text_version
, devname
);
1517 mp
= map_by_uuid(&map
, ra
->uuid
);
1520 mdfd
= open_dev(mp
->devnm
);
1522 strcpy(chosen_name
, mp
->path
);
1524 strcpy(chosen_name
, mp
->devnm
);
1527 /* Check in mdadm.conf for container == devname and
1528 * member == ra->text_version after second slash.
1530 char *sub
= strchr(ra
->text_version
+1, '/');
1531 struct mddev_ident
*array_list
;
1534 array_list
= conf_get_ident(NULL
);
1537 for(; array_list
; array_list
= array_list
->next
) {
1539 if (array_list
->member
== NULL
||
1540 array_list
->container
== NULL
)
1542 if (strcmp(array_list
->member
, sub
) != 0)
1544 if (array_list
->uuid_set
&&
1545 !same_uuid(ra
->uuid
, array_list
->uuid
, st
->ss
->swapuuid
))
1547 dn
= container2devname(array_list
->container
);
1550 if (strncmp(dn
, ra
->text_version
+1,
1552 ra
->text_version
[strlen(dn
)+1] != '/') {
1557 /* we have a match */
1560 pr_err("match found for member %s\n",
1561 array_list
->member
);
1565 if (match
&& match
->devname
&&
1566 strcasecmp(match
->devname
, "<ignore>") == 0) {
1568 pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
1569 match
->container
, match
->member
);
1573 trustworthy
= LOCAL
;
1575 mdfd
= create_mddev(match
? match
->devname
: NULL
,
1581 if (only
&& (!mp
|| strcmp(mp
->devnm
, only
) != 0))
1585 pr_err("failed to open %s: %s.\n",
1586 chosen_name
, strerror(errno
));
1590 assemble_container_content(st
, mdfd
, ra
, c
,
1591 chosen_name
, &result
);
1594 if (c
->export
&& result
) {
1596 printf("MD_STARTED");
1597 if (result
& INCR_NO
) {
1598 printf("%cno", sep
);
1601 if (result
& INCR_UNSAFE
) {
1602 printf("%cunsafe", sep
);
1605 if (result
& INCR_ALREADY
) {
1606 printf("%calready", sep
);
1609 if (result
& INCR_YES
) {
1610 printf("%cyes", sep
);
1616 /* don't move spares to container with volume being activated
1617 when all volumes are blocked */
1618 if (ra_all
== ra_blocked
)
1621 /* Now move all suitable spares from spare container */
1622 domains
= domain_from_array(list
, st
->ss
->name
);
1623 memcpy(suuid
, uuid_zero
, sizeof(int[4]));
1625 (smp
= map_by_uuid(&map
, suuid
)) != NULL
&&
1626 (sfd
= open(smp
->path
, O_RDONLY
)) >= 0) {
1627 /* spare container found */
1628 struct supertype
*sst
=
1629 super_imsm
.match_metadata_desc("imsm");
1630 struct mdinfo
*sinfo
;
1631 unsigned long long min_size
= 0;
1632 if (st
->ss
->min_acceptable_spare_size
)
1633 min_size
= st
->ss
->min_acceptable_spare_size(st
);
1634 if (!sst
->ss
->load_container(sst
, sfd
, NULL
)) {
1636 sinfo
= container_choose_spares(sst
, min_size
,
1639 sst
->ss
->free_super(sst
);
1642 struct mdinfo
*disks
= sinfo
->devs
;
1644 /* move spare from spare
1645 * container to currently
1651 makedev(disks
->disk
.major
,
1652 disks
->disk
.minor
)))
1654 disks
= disks
->next
;
1657 pr_err("Added %d spare%s to %s\n",
1658 count
, count
>1?"s":"", devname
);
1664 domain_free(domains
);
1668 static void run_udisks(char *arg1
, char *arg2
)
1673 execl("/usr/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1674 execl("/bin/udisks", "udisks", arg1
, arg2
, NULL
);
1677 while (pid
> 0 && wait(&status
) != pid
)
1682 * IncrementalRemove - Attempt to see if the passed in device belongs to any
1683 * raid arrays, and if so first fail (if needed) and then remove the device.
1685 * @devname - The device we want to remove
1686 * @id_path - name as found in /dev/disk/by-path for this device
1688 * Note: the device name must be a kernel name like "sda", so
1689 * that we can find it in /proc/mdstat
1691 int IncrementalRemove(char *devname
, char *id_path
, int verbose
)
1695 struct mdstat_ent
*ent
;
1696 struct mddev_dev devlist
;
1701 dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
1703 if (strchr(devname
, '/')) {
1704 pr_err("incremental removal requires a kernel device name, not a file: %s\n", devname
);
1707 ent
= mdstat_by_component(devname
);
1710 pr_err("%s does not appear to be a component of any array\n", devname
);
1713 sysfs_init(&mdi
, -1, ent
->devnm
);
1714 mdfd
= open_dev_excl(ent
->devnm
);
1717 if (sysfs_get_str(&mdi
, NULL
, "array_state",
1718 buf
, sizeof(buf
)) > 0) {
1719 if (strncmp(buf
, "active", 6) == 0 ||
1720 strncmp(buf
, "clean", 5) == 0)
1721 sysfs_set_str(&mdi
, NULL
,
1722 "array_state", "read-auto");
1725 mdfd
= open_dev(ent
->devnm
);
1728 pr_err("Cannot open array %s!!\n", ent
->devnm
);
1734 struct map_ent
*map
= NULL
, *me
;
1735 me
= map_by_devnm(&map
, ent
->devnm
);
1737 policy_save_path(id_path
, me
);
1741 memset(&devlist
, 0, sizeof(devlist
));
1742 devlist
.devname
= devname
;
1743 devlist
.disposition
= 'f';
1744 /* for a container, we must fail each member array */
1745 if (ent
->metadata_version
&&
1746 strncmp(ent
->metadata_version
, "external:", 9) == 0) {
1747 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
1748 struct mdstat_ent
*memb
;
1749 for (memb
= mdstat
; memb
; memb
= memb
->next
)
1750 if (is_container_member(memb
, ent
->devnm
)) {
1751 int subfd
= open_dev(memb
->devnm
);
1753 rv
|= Manage_subdevs(
1755 &devlist
, verbose
, 0,
1760 free_mdstat(mdstat
);
1762 rv
|= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1763 verbose
, 0, NULL
, 0);
1765 /* Failed due to EBUSY, try to stop the array.
1766 * Give udisks a chance to unmount it first.
1768 int devid
= devnm2devid(ent
->devnm
);
1769 run_udisks("--unmount", map_dev(major(devid
),minor(devid
), 0));
1770 rv
= Manage_stop(ent
->devnm
, mdfd
, verbose
, 1);
1772 /* At least we can try to trigger a 'remove' */
1773 sysfs_uevent(&mdi
, "remove");
1776 pr_err("Fail to stop %s too.\n", ent
->devnm
);
1779 devlist
.disposition
= 'r';
1780 rv
= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1781 verbose
, 0, NULL
, 0);