]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - Incremental.c
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 struct dev_policy
*policy
= NULL
;
103 struct map_ent target_array
;
105 char *devname
= devlist
->devname
;
106 int journal_device_missing
= 0;
108 struct createinfo
*ci
= conf_get_create_info();
110 if (!stat_is_blkdev(devname
, &rdev
))
112 dfd
= dev_open(devname
, O_RDONLY
);
115 pr_err("cannot open %s: %s.\n",
116 devname
, strerror(errno
));
119 /* If the device is a container, we do something very different */
120 if (must_be_container(dfd
)) {
122 st
= super_by_fd(dfd
, NULL
);
123 if (st
&& st
->ss
->load_container
)
124 rv
= st
->ss
->load_container(st
, dfd
, NULL
);
127 if (!rv
&& st
->ss
->container_content
) {
129 pr_err("failed to get exclusive lock on mapfile\n");
131 printf("MD_DEVNAME=%s\n", devname
);
132 rv
= Incremental_container(st
, devname
, c
, NULL
);
137 pr_err("%s is not part of an md array.\n",
142 /* 1/ Check if device is permitted by mdadm.conf */
144 for (;devlist
; devlist
= devlist
->next
)
145 if (conf_test_dev(devlist
->devname
))
148 devlist
= conf_get_devs();
149 for (;devlist
; devlist
= devlist
->next
) {
150 if (stat_is_blkdev(devlist
->devname
, &rdev2
) &&
157 pr_err("%s not permitted by mdadm.conf.\n",
162 /* 2/ Find metadata, reject if none appropriate (check
163 * version/name from args) */
165 if (!fstat_is_blkdev(dfd
, devname
, &rdev
))
168 dinfo
.disk
.major
= major(rdev
);
169 dinfo
.disk
.minor
= minor(rdev
);
171 policy
= disk_policy(&dinfo
);
172 have_target
= policy_check_path(&dinfo
, &target_array
);
174 if (st
== NULL
&& (st
= guess_super_type(dfd
, guess_array
)) == NULL
) {
176 pr_err("no recognisable superblock on %s.\n",
178 rv
= try_spare(devname
, &dfd
, policy
,
179 have_target
? &target_array
: NULL
,
183 st
->ignore_hw_compat
= 0;
185 if (st
->ss
->compare_super
== NULL
||
186 st
->ss
->load_super(st
, dfd
, c
->verbose
>= 0 ? devname
: NULL
)) {
188 pr_err("no RAID superblock on %s.\n",
190 rv
= try_spare(devname
, &dfd
, policy
,
191 have_target
? &target_array
: NULL
,
196 close (dfd
); dfd
= -1;
198 st
->ss
->getinfo_super(st
, &info
, NULL
);
200 /* 3/ Check if there is a match in mdadm.conf */
201 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
202 if (!match
&& rv
== 2)
205 if (match
&& match
->devname
&& is_devname_ignore(match
->devname
) == true) {
207 pr_err("array containing %s is explicitly ignored by mdadm.conf\n",
212 /* 3a/ if not, check for homehost match. If no match, continue
213 * but don't trust the 'name' in the array. Thus a 'random' minor
214 * number will be assigned, and the device name will be based
218 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
220 else if (st
->ss
->match_home(st
, "any") == 1)
221 trustworthy
= LOCAL_ANY
;
223 trustworthy
= FOREIGN
;
225 if (!match
&& !conf_test_metadata(st
->ss
->name
, policy
,
226 (trustworthy
== LOCAL
))) {
228 pr_err("%s has metadata type %s for which auto-assembly is disabled\n",
229 devname
, st
->ss
->name
);
232 if (trustworthy
== LOCAL_ANY
)
235 /* There are three possible sources for 'autof': command line,
236 * ARRAY line in mdadm.conf, or CREATE line in mdadm.conf.
237 * ARRAY takes precedence, then command line, then
240 if (match
&& match
->autof
)
241 c
->autof
= match
->autof
;
243 c
->autof
= ci
->autof
;
245 name_to_use
= info
.name
;
246 if (name_to_use
[0] == 0 && is_container(info
.array
.level
)) {
247 name_to_use
= info
.text_version
;
248 trustworthy
= METADATA
;
250 if (name_to_use
[0] && trustworthy
!= LOCAL
&&
251 ! c
->require_homehost
&&
252 conf_name_is_free(name_to_use
))
255 /* strip "hostname:" prefix from name if we have decided
256 * to treat it as LOCAL
258 if (trustworthy
== LOCAL
&& strchr(name_to_use
, ':') != NULL
)
259 name_to_use
= strchr(name_to_use
, ':')+1;
261 /* 4/ Check if array exists.
264 pr_err("failed to get exclusive lock on mapfile\n");
265 /* Now check we can get O_EXCL. If not, probably "mdadm -A" has
268 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
271 pr_err("cannot reopen %s: %s.\n",
272 devname
, strerror(errno
));
275 /* Cannot hold it open while we add the device to the array,
276 * so we must release the O_EXCL and depend on the map_lock()
277 * So now is the best time to remove any partitions.
279 remove_partitions(dfd
);
283 mp
= map_by_uuid(&map
, info
.uuid
);
285 mdfd
= open_dev(mp
->devnm
);
291 /* Skip the clustered ones. This should be started by
292 * clustering resource agents
294 if (info
.array
.state
& (1 << MD_SB_CLUSTERED
))
297 /* Couldn't find an existing array, maybe make a new one */
298 mdfd
= create_mddev(match
? match
->devname
: NULL
,
299 name_to_use
, c
->autof
, trustworthy
, chosen_name
, 0);
304 if (sysfs_init(&info
, mdfd
, NULL
)) {
305 pr_err("unable to initialize sysfs for %s\n",
311 if (set_array_info(mdfd
, st
, &info
) != 0) {
312 pr_err("failed to set array info for %s: %s\n",
313 chosen_name
, strerror(errno
));
319 dinfo
.disk
.major
= major(rdev
);
320 dinfo
.disk
.minor
= minor(rdev
);
321 if (add_disk(mdfd
, st
, &info
, &dinfo
) != 0) {
322 pr_err("failed to add %s to new array %s: %s.\n",
323 devname
, chosen_name
, strerror(errno
));
324 ioctl(mdfd
, STOP_ARRAY
, 0);
328 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
329 GET_OFFSET
| GET_SIZE
));
331 if (!sra
|| !sra
->devs
|| sra
->devs
->disk
.raid_disk
>= 0) {
332 /* It really should be 'none' - must be old buggy
333 * kernel, and mdadm -I may not be able to complete.
336 ioctl(mdfd
, STOP_ARRAY
, NULL
);
337 pr_err("You have an old buggy kernel which cannot support\n --incremental reliably. Aborting.\n");
341 info
.array
.working_disks
= 1;
342 /* 6/ Make sure /var/run/mdadm.map contains this array. */
343 map_update(&map
, fd2devnm(mdfd
),
345 info
.uuid
, chosen_name
);
348 /* - check one drive in array to make sure metadata is a reasonably */
349 /* close match. Reject if not (e.g. different type) */
350 /* - add the device */
354 struct supertype
*st2
;
355 struct mdinfo info2
, *d
;
357 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
358 GET_OFFSET
| GET_SIZE
));
361 strcpy(chosen_name
, mp
->path
);
363 strcpy(chosen_name
, mp
->devnm
);
365 /* It is generally not OK to add non-spare drives to a
366 * running array as they are probably missing because
367 * they failed. However if runstop is 1, then the
368 * array was possibly started early and our best bet is
369 * to add this anyway.
370 * Also if action policy is re-add or better we allow
372 * This doesn't apply to containers as the 'non-spare'
373 * flag has a different meaning. The test has to happen
374 * at the device level there
376 if (!st
->ss
->external
&&
377 (info
.disk
.state
& (1 << MD_DISK_SYNC
)) != 0 &&
378 !policy_action_allows(policy
, st
->ss
->name
, act_re_add
) &&
380 if (md_array_active(mdfd
)) {
381 pr_err("not adding %s to active array (without --run) %s\n",
382 devname
, chosen_name
);
392 sprintf(dn
, "%d:%d", sra
->devs
->disk
.major
,
393 sra
->devs
->disk
.minor
);
394 dfd2
= dev_open(dn
, O_RDONLY
);
396 pr_err("unable to open %s\n", devname
);
401 if (st2
->ss
->load_super(st2
, dfd2
, NULL
) ||
402 st
->ss
->compare_super(st
, st2
, 1) != 0) {
403 pr_err("metadata mismatch between %s and chosen array %s\n",
404 devname
, chosen_name
);
410 st2
->ss
->getinfo_super(st2
, &info2
, NULL
);
411 st2
->ss
->free_super(st2
);
412 if (info
.array
.level
!= info2
.array
.level
||
413 memcmp(info
.uuid
, info2
.uuid
, 16) != 0 ||
414 info
.array
.raid_disks
!= info2
.array
.raid_disks
) {
415 pr_err("unexpected difference between %s and %s.\n",
416 chosen_name
, devname
);
421 info
.disk
.major
= major(rdev
);
422 info
.disk
.minor
= minor(rdev
);
423 /* add disk needs to know about containers */
424 if (st
->ss
->external
)
425 sra
->array
.level
= LEVEL_CONTAINER
;
427 if (info
.array
.state
& (1 << MD_SB_CLUSTERED
))
428 info
.disk
.state
|= (1 << MD_DISK_CLUSTER_ADD
);
430 err
= add_disk(mdfd
, st
, sra
, &info
);
431 if (err
< 0 && errno
== EBUSY
) {
432 /* could be another device present with the same
433 * disk.number. Find and reject any such
435 find_reject(mdfd
, st
, sra
, info
.disk
.number
,
436 info
.events
, c
->verbose
, chosen_name
);
437 err
= add_disk(mdfd
, st
, sra
, &info
);
439 if (err
< 0 && errno
== EINVAL
&&
440 info
.disk
.state
& (1<<MD_DISK_SYNC
)) {
441 /* Maybe it needs to be added as a spare */
442 if (policy_action_allows(policy
, st
->ss
->name
,
444 info
.disk
.state
&= ~(1<<MD_DISK_SYNC
);
445 err
= add_disk(mdfd
, st
, sra
, &info
);
448 pr_err("can only add %s to %s as a spare, and force-spare is not set.\n",
449 devname
, chosen_name
);
452 pr_err("failed to add %s to existing array %s: %s.\n",
453 devname
, chosen_name
, strerror(errno
));
457 info
.array
.working_disks
= 0;
458 for (d
= sra
->devs
; d
; d
=d
->next
)
459 info
.array
.working_disks
++;
462 if (strncmp(chosen_name
, DEV_MD_DIR
, DEV_MD_DIR_LEN
) == 0)
463 md_devname
= chosen_name
+ DEV_MD_DIR_LEN
;
465 md_devname
= chosen_name
;
467 printf("MD_DEVICE=%s\n", fd2devnm(mdfd
));
468 printf("MD_DEVNAME=%s\n", md_devname
);
469 printf("MD_FOREIGN=%s\n", trustworthy
== FOREIGN
? "yes" : "no");
472 /* 7/ Is there enough devices to possibly start the array? */
473 /* 7a/ if not, finish with success. */
474 if (is_container(info
.array
.level
)) {
476 /* Try to assemble within the container */
477 sysfs_uevent(sra
, "change");
478 if (!c
->export
&& c
->verbose
>= 0)
479 pr_err("container %s now has %d device%s\n",
480 chosen_name
, info
.array
.working_disks
,
481 info
.array
.working_disks
== 1?"":"s");
482 sysfs_rules_apply(chosen_name
, &info
);
483 wait_for(chosen_name
, mdfd
);
484 if (st
->ss
->external
)
485 strcpy(devnm
, fd2devnm(mdfd
));
486 if (st
->ss
->load_container
)
487 rv
= st
->ss
->load_container(st
, mdfd
, NULL
);
491 rv
= Incremental_container(st
, chosen_name
, c
, NULL
);
493 /* after spare is added, ping monitor for external metadata
494 * so that it can eg. try to rebuild degraded array */
495 if (st
->ss
->external
)
500 /* We have added something to the array, so need to re-read the
501 * state. Eventually this state should be kept up-to-date as
505 sra
= sysfs_read(mdfd
, NULL
, (GET_DEVS
| GET_STATE
|
506 GET_OFFSET
| GET_SIZE
));
507 active_disks
= count_active(st
, sra
, mdfd
, &avail
, &info
);
512 journal_device_missing
= (info
.journal_device_required
) && (info
.journal_clean
== 0);
514 if (info
.consistency_policy
== CONSISTENCY_POLICY_PPL
)
515 info
.array
.state
|= 1;
517 if (enough(info
.array
.level
, info
.array
.raid_disks
,
518 info
.array
.layout
, info
.array
.state
& 1, avail
) == 0) {
520 printf("MD_STARTED=no\n");
521 } else if (c
->verbose
>= 0)
522 pr_err("%s attached to %s, not enough to start (%d).\n",
523 devname
, chosen_name
, active_disks
);
529 /* - if number of OK devices match expected, or -R and there */
531 /* + add any bitmap file */
532 /* + start the array (auto-readonly). */
534 if (md_array_active(mdfd
)) {
536 printf("MD_STARTED=already\n");
537 } else if (c
->verbose
>= 0)
538 pr_err("%s attached to %s which is already active.\n",
539 devname
, chosen_name
);
545 if (c
->runstop
> 0 || (!journal_device_missing
&& active_disks
>= info
.array
.working_disks
)) {
547 /* Let's try to start it */
549 if (journal_device_missing
)
550 pr_err("Trying to run with missing journal device\n");
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
,
606 add_disk(mdfd
, st
, sra
, dsk
) == 0)
607 pr_err("%s re-added to %s\n",
608 dsk
->sys_name
, chosen_name
);
611 pr_err("%s attached to %s, but failed to start: %s.\n",
612 devname
, chosen_name
, strerror(errno
));
617 printf("MD_STARTED=unsafe\n");
618 } else if (journal_device_missing
) {
619 pr_err("Journal device is missing, not safe to start yet.\n");
620 } else if (c
->verbose
>= 0)
621 pr_err("%s attached to %s, not enough to start safely.\n",
622 devname
, chosen_name
);
632 dev_policy_free(policy
);
640 static void find_reject(int mdfd
, struct supertype
*st
, struct mdinfo
*sra
,
641 int number
, __u64 events
, int verbose
,
644 /* Find a device attached to this array with a disk.number of number
645 * and events less than the passed events, and remove the device.
649 if (md_array_active(mdfd
))
650 return; /* not safe to remove from active arrays
651 * without thinking more */
653 for (d
= sra
->devs
; d
; d
= d
->next
) {
654 char dn
[24]; // 2*11 bytes for ints (including sign) + colon + null byte
657 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
658 dfd
= dev_open(dn
, O_RDONLY
);
661 if (st
->ss
->load_super(st
, dfd
, NULL
)) {
665 st
->ss
->getinfo_super(st
, &info
, NULL
);
666 st
->ss
->free_super(st
);
669 if (info
.disk
.number
!= number
|| info
.events
>= events
)
672 if (d
->disk
.raid_disk
> -1)
673 sysfs_set_str(sra
, d
, "slot", STR_COMMON_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;
690 __u64 max_journal_events
= 0;
702 for (d
= sra
->devs
; d
; d
= d
->next
)
704 for (d
= sra
->devs
, devnum
= 0 ; d
; d
= d
->next
, devnum
++) {
710 sprintf(dn
, "%d:%d", d
->disk
.major
, d
->disk
.minor
);
711 dfd
= dev_open(dn
, O_RDONLY
);
714 ok
= st
->ss
->load_super(st
, dfd
, NULL
);
719 info
.array
.raid_disks
= raid_disks
;
720 st
->ss
->getinfo_super(st
, &info
, devmap
+ raid_disks
* devnum
);
721 if (info
.disk
.raid_disk
== MD_DISK_ROLE_JOURNAL
&&
722 info
.events
> max_journal_events
)
723 max_journal_events
= info
.events
;
725 raid_disks
= info
.array
.raid_disks
;
726 avail
= xcalloc(raid_disks
, 1);
729 best
= xcalloc(raid_disks
, sizeof(int));
730 devmap
= xcalloc(raid_disks
, numdevs
);
732 st
->ss
->getinfo_super(st
, &info
, devmap
);
735 if (info
.disk
.state
& (1<<MD_DISK_SYNC
))
739 max_events
= info
.events
;
740 avail
[info
.disk
.raid_disk
] = 2;
741 best
[info
.disk
.raid_disk
] = devnum
;
742 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
743 } else if (info
.events
== max_events
) {
744 avail
[info
.disk
.raid_disk
] = 2;
745 best
[info
.disk
.raid_disk
] = devnum
;
746 } else if (info
.events
== max_events
-1) {
747 if (avail
[info
.disk
.raid_disk
] == 0) {
748 avail
[info
.disk
.raid_disk
] = 1;
749 best
[info
.disk
.raid_disk
] = devnum
;
751 } else if (info
.events
< max_events
- 1)
753 else if (info
.events
== max_events
+1) {
755 max_events
= info
.events
;
756 for (i
= 0; i
< raid_disks
; i
++)
759 avail
[info
.disk
.raid_disk
] = 2;
760 best
[info
.disk
.raid_disk
] = devnum
;
761 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
762 } else { /* info.events much bigger */
763 memset(avail
, 0, raid_disks
);
764 max_events
= info
.events
;
765 avail
[info
.disk
.raid_disk
] = 2;
766 best
[info
.disk
.raid_disk
] = devnum
;
767 st
->ss
->getinfo_super(st
, bestinfo
, NULL
);
769 } else if (info
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
771 st
->ss
->free_super(st
);
773 if (max_journal_events
>= max_events
- 1)
774 bestinfo
->journal_clean
= 1;
778 /* We need to reject any device that thinks the best device is
779 * failed or missing */
780 for (b
= 0; b
< raid_disks
; b
++)
784 for (i
= 0 ; i
< raid_disks
; i
++) {
785 if (i
!= b
&& avail
[i
])
786 if (devmap
[raid_disks
* best
[i
] + b
] == 0) {
787 /* This device thinks 'b' is failed -
790 for (d
=sra
->devs
; devnum
; d
= d
->next
)
792 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
798 /* Also need to reject any spare device with an event count that
801 for (d
= sra
->devs
; d
; d
= d
->next
) {
802 if (!(d
->disk
.state
& (1<<MD_DISK_SYNC
)) &&
803 d
->events
> max_events
)
804 d
->disk
.state
|= (1 << MD_DISK_REMOVED
);
808 return cnt
+ replcnt
;
811 /* test if container has degraded member(s) */
813 container_members_max_degradation(struct map_ent
*map
, struct map_ent
*me
)
816 int degraded
, max_degraded
= 0;
818 for(; map
; map
= map
->next
) {
819 if (!metadata_container_matches(map
->metadata
, me
->devnm
))
821 /* most accurate information regarding array degradation */
822 sra
= sysfs_read(-1, map
->devnm
,
823 GET_DISKS
| GET_DEVS
| GET_STATE
);
826 degraded
= sra
->array
.raid_disks
- sra
->array
.active_disks
-
827 sra
->array
.spare_disks
;
828 if (degraded
> max_degraded
)
829 max_degraded
= degraded
;
837 * incremental_external_test_spare_criteria() - helper to test spare criteria.
838 * @st: supertype, must be not NULL, it is duplicated here.
839 * @container_devnm: devnm of the container.
840 * @disk_fd: file descriptor of device to tested.
841 * @verbose: verbose flag.
843 * The function is used on new drive verification path to check if it can be added to external
844 * container. To test spare criteria, metadata must be loaded. It duplicates super to not mess in
846 * Function is executed if superblock supports get_spare_criteria(), otherwise success is returned.
848 mdadm_status_t
incremental_external_test_spare_criteria(struct supertype
*st
, char *container_devnm
,
849 int disk_fd
, int verbose
)
851 mdadm_status_t rv
= MDADM_STATUS_ERROR
;
852 char container_devname
[PATH_MAX
];
853 struct spare_criteria sc
= {0};
854 struct supertype
*dup
;
856 if (!st
->ss
->get_spare_criteria
)
857 return MDADM_STATUS_SUCCESS
;
860 snprintf(container_devname
, PATH_MAX
, "/dev/%s", container_devnm
);
862 if (dup
->ss
->get_spare_criteria(dup
, container_devname
, &sc
) != 0) {
864 pr_err("Failed to get spare criteria for %s\n", container_devname
);
868 if (!disk_fd_matches_criteria(disk_fd
, &sc
)) {
870 pr_err("Disk does not match spare criteria for %s\n", container_devname
);
874 rv
= MDADM_STATUS_SUCCESS
;
877 dup
->ss
->free_super(dup
);
883 static int array_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
884 struct map_ent
*target
, int bare
,
885 struct supertype
*st
, int verbose
)
887 /* This device doesn't have any md metadata
888 * The device policy allows 'spare' and if !bare, it allows spare-same-slot.
889 * If 'st' is not set, then we only know that some metadata allows this,
890 * others possibly don't.
891 * So look for a container or array to attach the device to.
892 * Prefer 'target' if that is set and the array is found.
894 * If st is set, then only arrays of that type are considered
895 * Return 0 on success, or some exit code on failure, probably 1.
899 struct map_ent
*mp
, *map
= NULL
;
900 struct mdinfo
*chosen
= NULL
;
903 if (!fstat_is_blkdev(dfd
, devname
, &rdev
))
907 * Now we need to find a suitable array to add this to.
908 * We only accept arrays that:
910 * - are in the same domains as the device
911 * - are of an size for which the device will be useful
912 * and we choose the one that is the most degraded
915 if (map_lock(&map
)) {
916 pr_err("failed to get exclusive lock on mapfile\n");
919 for (mp
= map
; mp
; mp
= mp
->next
) {
920 struct supertype
*st2
;
921 struct domainlist
*dl
= NULL
;
923 unsigned long long freesize
= 0;
925 if (is_subarray(mp
->metadata
))
928 st2
= st
->ss
->match_metadata_desc(mp
->metadata
);
930 (st
->minor_version
>= 0 &&
931 st
->minor_version
!= st2
->minor_version
)) {
933 pr_err("not adding %s to %s as metadata type doesn't match\n",
940 sra
= sysfs_read(-1, mp
->devnm
,
941 GET_DEVS
|GET_OFFSET
|GET_SIZE
|GET_STATE
|
942 GET_COMPONENT
|GET_VERSION
);
944 sra
->array
.failed_disks
= -1;
950 for(i
= 0; !st2
&& superlist
[i
]; i
++)
951 st2
= superlist
[i
]->match_metadata_desc(
955 pr_err("not adding %s to %s as metadata not recognised.\n",
959 /* Need to double check the 'act_spare' permissions applies
962 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
964 if (!bare
&& !policy_action_allows(pol
, st2
->ss
->name
,
965 act_spare_same_slot
))
969 /* update number of failed disks for mostly degraded
970 * container member */
971 if (sra
->array
.failed_disks
== -1)
972 sra
->array
.failed_disks
= container_members_max_degradation(map
, mp
);
974 if (sra
->component_size
== 0) {
975 /* true for containers */
976 if (incremental_external_test_spare_criteria(st2
, mp
->devnm
, dfd
, verbose
))
980 if (sra
->component_size
> 0 &&
981 st2
->ss
->validate_geometry(st2
, sra
->array
.level
, sra
->array
.layout
,
982 sra
->array
.raid_disks
, &sra
->array
.chunk_size
,
984 sra
->devs
? sra
->devs
->data_offset
: INVALID_SECTORS
,
985 devname
, &freesize
, sra
->consistency_policy
,
986 0) && freesize
< sra
->component_size
) {
988 pr_err("not adding %s to %s as it is too small\n",
992 /* test against target.
993 * If 'target' is set and 'bare' is false, we only accept
994 * arrays/containers that match 'target'.
995 * If 'target' is set and 'bare' is true, we prefer the
996 * array which matches 'target'.
997 * target is considered only if we deal with degraded array
999 if (target
&& policy_action_allows(pol
, st2
->ss
->name
,
1000 act_spare_same_slot
)) {
1001 if (strcmp(target
->metadata
, mp
->metadata
) == 0 &&
1002 memcmp(target
->uuid
, mp
->uuid
,
1003 sizeof(target
->uuid
)) == 0 &&
1004 sra
->array
.failed_disks
> 0) {
1005 /* This is our target!! */
1009 /* skip to end so we don't check any more */
1014 /* not our target */
1019 dl
= domain_from_array(sra
, st2
->ss
->name
);
1020 if (domain_test(dl
, pol
, st2
->ss
->name
) != 1) {
1021 /* domain test fails */
1023 pr_err("not adding %s to %s as it is not in a compatible domain\n",
1028 /* all tests passed, OK to add to this array */
1032 } else if (chosen
->array
.failed_disks
< sra
->array
.failed_disks
) {
1045 /* add current device to chosen array as a spare */
1046 int mdfd
= open_dev(chosen
->sys_name
);
1048 struct mddev_dev devlist
;
1049 char chosen_devname
[24]; // 2*11 for int (including signs) + colon + null
1050 devlist
.next
= NULL
;
1052 devlist
.writemostly
= FlagDefault
;
1053 devlist
.failfast
= FlagDefault
;
1054 devlist
.devname
= chosen_devname
;
1055 sprintf(chosen_devname
, "%d:%d", major(rdev
),
1057 devlist
.disposition
= 'a';
1060 rv
= Manage_subdevs(chosen
->sys_name
, mdfd
, &devlist
,
1061 -1, 0, UOPT_UNDEFINED
, 0);
1066 pr_err("added %s as spare for %s\n",
1067 devname
, chosen
->sys_name
);
1069 pr_err("failed to add %s as spare for %s\n",
1070 devname
, chosen
->sys_name
);
1078 static int partition_try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1079 struct supertype
*st
, int verbose
)
1081 /* we know that at least one partition virtual-metadata is
1082 * allowed to incorporate spares like this device. We need to
1083 * find a suitable device to copy partition information from.
1085 * Getting a list of all disk (not partition) devices is
1086 * slightly non-trivial. We could look at /sys/block, but
1087 * that is theoretically due to be removed. Maybe best to use
1088 * /dev/disk/by-path/?* and ignore names ending '-partNN' as
1089 * we depend on this directory of 'path' info. But that fails
1090 * to find loop devices and probably others. Maybe don't
1091 * worry about that, they aren't the real target.
1093 * So: check things in /dev/disk/by-path to see if they are in
1094 * a compatible domain, then load the partition table and see
1095 * if it is OK for the new device, and choose the largest
1096 * partition table that fits.
1100 char *chosen
= NULL
;
1101 unsigned long long chosen_size
= 0;
1102 struct supertype
*chosen_st
= NULL
;
1105 dir
= opendir("/dev/disk/by-path");
1108 while ((de
= readdir(dir
)) != NULL
) {
1110 struct dev_policy
*pol2
= NULL
;
1111 struct domainlist
*domlist
= NULL
;
1114 struct supertype
*st2
= NULL
;
1115 char *devname
= NULL
;
1116 unsigned long long devsectors
;
1119 if (de
->d_ino
== 0 || de
->d_name
[0] == '.' ||
1120 (de
->d_type
!= DT_LNK
&& de
->d_type
!= DT_UNKNOWN
))
1123 ep
= de
->d_name
+ strlen(de
->d_name
);
1124 while (ep
> de
->d_name
&&
1127 if (ep
> de
->d_name
+ 5 &&
1128 strncmp(ep
-5, "-part", 5) == 0)
1129 /* This is a partition - skip it */
1132 pathlist
[0] = de
->d_name
;
1134 pol2
= path_policy(pathlist
, type_disk
);
1136 domain_merge(&domlist
, pol2
, st
? st
->ss
->name
: NULL
);
1137 if (domain_test(domlist
, pol
, st
? st
->ss
->name
: NULL
) != 1)
1138 /* new device is incompatible with this device. */
1141 domain_free(domlist
);
1144 if (asprintf(&devname
, "/dev/disk/by-path/%s", de
->d_name
) != 1) {
1148 fd
= open(devname
, O_RDONLY
);
1151 if (get_dev_size(fd
, devname
, &devsectors
) == 0)
1156 st2
= dup_super(st
);
1158 st2
= guess_super_type(fd
, guess_partitions
);
1159 if (st2
== NULL
|| st2
->ss
->load_super(st2
, fd
, NULL
) < 0)
1161 st2
->ignore_hw_compat
= 0;
1164 /* Check domain policy again, this time referring to metadata */
1165 domain_merge(&domlist
, pol2
, st2
->ss
->name
);
1166 if (domain_test(domlist
, pol
, st2
->ss
->name
) != 1)
1167 /* Incompatible devices for this metadata type */
1169 if (!policy_action_allows(pol
, st2
->ss
->name
, act_spare
))
1170 /* Some partition types allow sparing, but not
1176 st2
->ss
->getinfo_super(st2
, &info
, NULL
);
1177 if (info
.component_size
> devsectors
)
1178 /* This partitioning doesn't fit in the device */
1181 /* This is an acceptable device to copy partition
1182 * metadata from. We could just stop here, but I
1183 * think I want to keep looking incase a larger
1184 * metadata which makes better use of the device can
1187 if (chosen
== NULL
|| chosen_size
< info
.component_size
) {
1188 chosen_size
= info
.component_size
;
1193 chosen_st
->ss
->free_super(chosen_st
);
1202 domain_free(domlist
);
1203 dev_policy_free(pol2
);
1205 st2
->ss
->free_super(st2
);
1217 /* 'chosen' is the best device we can find. Let's write its
1218 * metadata to devname dfd is read-only so don't use that
1220 fd
= open(devname
, O_RDWR
);
1222 chosen_st
->ss
->store_super(chosen_st
, fd
);
1226 chosen_st
->ss
->free_super(chosen_st
);
1231 static int is_bare(int dfd
)
1233 unsigned long long size
= 0;
1234 char bufpad
[4096 + 4096];
1235 char *buf
= (char*)(((long)bufpad
+ 4096) & ~4095);
1237 if (lseek(dfd
, 0, SEEK_SET
) != 0 ||
1238 read(dfd
, buf
, 4096) != 4096)
1241 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1243 if (memcmp(buf
, buf
+1, 4095) != 0)
1246 /* OK, first 4K appear blank, try the end. */
1247 get_dev_size(dfd
, NULL
, &size
);
1248 if (lseek(dfd
, size
-4096, SEEK_SET
) < 0 ||
1249 read(dfd
, buf
, 4096) != 4096)
1252 if (buf
[0] != '\0' && buf
[0] != '\x5a' && buf
[0] != '\xff')
1254 if (memcmp(buf
, buf
+1, 4095) != 0)
1260 /* adding a spare to a regular array is quite different from adding one to
1261 * a set-of-partitions virtual array.
1262 * This function determines which is worth trying and tries as appropriate.
1263 * Arrays are given priority over partitions.
1265 static int try_spare(char *devname
, int *dfdp
, struct dev_policy
*pol
,
1266 struct map_ent
*target
,
1267 struct supertype
*st
, int verbose
)
1272 int partitions_ok
= 0;
1276 /* Can only add a spare if device has at least one domain */
1277 if (pol_find(pol
, pol_domain
) == NULL
)
1279 /* And only if some action allows spares */
1280 if (!policy_action_allows(pol
, st
?st
->ss
->name
:NULL
, act_spare
))
1283 /* Now check if the device is bare.
1284 * bare devices can always be added as a spare
1285 * non-bare devices can only be added if spare-same-slot is permitted,
1286 * and this device is replacing a previous device - in which case 'target'
1289 if (!is_bare(dfd
)) {
1290 /* Must have a target and allow same_slot */
1291 /* Later - may allow force_spare without target */
1293 !policy_action_allows(pol
, st
?st
->ss
->name
:NULL
,
1294 act_spare_same_slot
)) {
1296 pr_err("%s is not bare, so not considering as a spare\n",
1304 /* It might be OK to add this device to an array - need to see
1305 * what arrays might be candidates.
1308 /* just try to add 'array' or 'partition' based on this metadata */
1309 if (st
->ss
->add_to_super
)
1310 return array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1313 return partition_try_spare(devname
, dfdp
, pol
,
1316 /* No metadata was specified or found so options are open.
1317 * Check for whether any array metadata, or any partition metadata
1318 * might allow adding the spare. This check is just help to avoid
1319 * a more costly scan of all arrays when we can be sure that will
1322 for (i
= 0; (!arrays_ok
|| !partitions_ok
) && superlist
[i
] ; i
++) {
1323 if (superlist
[i
]->add_to_super
&& !arrays_ok
&&
1324 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1326 if (superlist
[i
]->add_to_super
== NULL
&& !partitions_ok
&&
1327 policy_action_allows(pol
, superlist
[i
]->name
, act_spare
))
1332 rv
= array_try_spare(devname
, dfdp
, pol
, target
, bare
,
1334 if (rv
!= 0 && partitions_ok
)
1335 rv
= partition_try_spare(devname
, dfdp
, pol
, st
, verbose
);
1339 int IncrementalScan(struct context
*c
, char *devnm
)
1341 /* look at every device listed in the 'map' file.
1342 * If one is found that is not running then:
1343 * look in mdadm.conf for bitmap file.
1344 * if one exists, but array has none, add it.
1345 * try to start array in auto-readonly mode
1347 struct map_ent
*mapl
= NULL
;
1349 struct mddev_ident
*devs
, *mddev
;
1355 devs
= conf_get_ident(NULL
);
1358 for (me
= mapl
; me
; me
= me
->next
) {
1362 if (devnm
&& strcmp(devnm
, me
->devnm
) != 0)
1364 if (me
->metadata
[0] == '/') {
1370 /* member array, need to work on container */
1371 strncpy(container
, me
->metadata
+1, 32);
1373 sl
= strchr(container
, '/');
1380 mdfd
= open_dev(me
->devnm
);
1382 if (!is_fd_valid(mdfd
))
1384 if (!isdigit(me
->metadata
[0])) {
1385 /* must be a container */
1386 struct supertype
*st
= super_by_fd(mdfd
, NULL
);
1388 struct map_ent
*map
= NULL
;
1390 if (st
&& st
->ss
->load_container
)
1391 ret
= st
->ss
->load_container(st
, mdfd
, NULL
);
1393 if (!ret
&& st
&& st
->ss
->container_content
) {
1395 pr_err("failed to get exclusive lock on mapfile\n");
1396 ret
= Incremental_container(st
, me
->path
, c
, only
);
1403 if (md_array_active(mdfd
)) {
1407 /* Ok, we can try this one. Maybe it needs a bitmap */
1408 for (mddev
= devs
; mddev
; mddev
= mddev
->next
)
1409 if (mddev
->devname
&& me
->path
&&
1410 devname_matches(mddev
->devname
, me
->path
))
1412 if (mddev
&& mddev
->bitmap_file
) {
1414 * Note: early kernels will wrongly fail this, so it
1420 bmfd
= open(mddev
->bitmap_file
, O_RDWR
);
1421 if (is_fd_valid(bmfd
)) {
1422 added
= ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
);
1425 if (c
->verbose
>= 0) {
1427 pr_err("Added bitmap %s to %s\n",
1428 mddev
->bitmap_file
, me
->path
);
1429 else if (errno
!= EEXIST
)
1430 pr_err("Failed to add bitmap to %s: %s\n",
1431 me
->path
, strerror(errno
));
1434 /* FIXME check for reshape_active and consider not
1437 sra
= sysfs_read(mdfd
, NULL
, 0);
1439 if (sysfs_set_str(sra
, NULL
,
1440 "array_state", "read-auto") == 0) {
1441 if (c
->verbose
>= 0)
1442 pr_err("started array %s\n",
1443 me
->path
?: me
->devnm
);
1445 pr_err("failed to start array %s: %s\n",
1446 me
->path
?: me
->devnm
,
1458 static char *container2devname(char *devname
)
1460 char *mdname
= NULL
;
1462 if (devname
[0] == '/') {
1463 int fd
= open(devname
, O_RDONLY
);
1465 mdname
= xstrdup(fd2devnm(fd
));
1470 struct map_ent
*mp
, *map
= NULL
;
1472 if (!parse_uuid(devname
, uuid
))
1474 mp
= map_by_uuid(&map
, uuid
);
1476 mdname
= xstrdup(mp
->devnm
);
1483 static int Incremental_container(struct supertype
*st
, char *devname
,
1484 struct context
*c
, char *only
)
1486 /* Collect the contents of this container and for each
1487 * array, choose a device name and assemble the array.
1490 struct mdinfo
*list
;
1492 struct map_ent
*map
= NULL
;
1495 struct mddev_ident
*match
;
1499 st
->ss
->getinfo_super(st
, &info
, NULL
);
1501 if (info
.container_enough
< 0 || (info
.container_enough
== 0 && c
->runstop
< 1)) {
1503 printf("MD_STARTED=no\n");
1504 else if (c
->verbose
)
1505 pr_err("Not enough devices to start the container.\n");
1510 match
= conf_match(st
, &info
, devname
, c
->verbose
, &rv
);
1511 if (match
== NULL
&& rv
== 2)
1514 /* Need to compute 'trustworthy' */
1516 trustworthy
= LOCAL
;
1517 else if (st
->ss
->match_home(st
, c
->homehost
) == 1)
1518 trustworthy
= LOCAL
;
1519 else if (st
->ss
->match_home(st
, "any") == 1)
1520 trustworthy
= LOCAL
;
1522 trustworthy
= FOREIGN
;
1524 list
= st
->ss
->container_content(st
, NULL
);
1525 /* when nothing to activate - quit */
1528 printf("MD_STARTED=nothing\n");
1532 for (ra
= list
; ra
; ra
= ra
->next
) {
1534 char chosen_name
[1024];
1536 struct mddev_ident
*match
= NULL
;
1538 /* do not activate arrays blocked by metadata handler */
1539 if (ra
->array
.state
& (1 << MD_SB_BLOCK_VOLUME
)) {
1540 pr_err("Cannot activate array %s in %s.\n",
1541 ra
->text_version
, devname
);
1544 mp
= map_by_uuid(&map
, ra
->uuid
);
1547 mdfd
= open_dev(mp
->devnm
);
1548 if (!is_fd_valid(mdfd
)) {
1549 pr_err("failed to open %s: %s.\n",
1550 mp
->devnm
, strerror(errno
));
1555 strcpy(chosen_name
, mp
->path
);
1557 strcpy(chosen_name
, mp
->devnm
);
1560 /* Check in mdadm.conf for container == devname and
1561 * member == ra->text_version after second slash.
1563 char *sub
= strchr(ra
->text_version
+1, '/');
1564 struct mddev_ident
*array_list
;
1567 array_list
= conf_get_ident(NULL
);
1570 for(; array_list
; array_list
= array_list
->next
) {
1572 if (array_list
->member
== NULL
||
1573 array_list
->container
== NULL
)
1575 if (strcmp(array_list
->member
, sub
) != 0)
1577 if (array_list
->uuid_set
&&
1578 !same_uuid(ra
->uuid
, array_list
->uuid
, st
->ss
->swapuuid
))
1580 dn
= container2devname(array_list
->container
);
1583 if (strncmp(dn
, ra
->text_version
+1,
1585 ra
->text_version
[strlen(dn
)+1] != '/') {
1590 /* we have a match */
1593 pr_err("match found for member %s\n",
1594 array_list
->member
);
1598 if (match
&& match
->devname
&& is_devname_ignore(match
->devname
) == true) {
1600 pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
1601 match
->container
, match
->member
);
1605 trustworthy
= LOCAL
;
1607 mdfd
= create_mddev(match
? match
->devname
: NULL
,
1613 if (!is_fd_valid(mdfd
)) {
1614 pr_err("create_mddev failed with chosen name %s: %s.\n",
1615 chosen_name
, strerror(errno
));
1621 if (only
&& (!mp
|| strcmp(mp
->devnm
, only
) != 0)) {
1626 assemble_container_content(st
, mdfd
, ra
, c
,
1627 chosen_name
, &result
);
1632 if (c
->export
&& result
) {
1634 printf("MD_STARTED");
1635 if (result
& INCR_NO
) {
1636 printf("%cno", sep
);
1639 if (result
& INCR_UNSAFE
) {
1640 printf("%cunsafe", sep
);
1643 if (result
& INCR_ALREADY
) {
1644 printf("%calready", sep
);
1647 if (result
& INCR_YES
) {
1648 printf("%cyes", sep
);
1660 static void remove_from_member_array(struct mdstat_ent
*memb
,
1661 struct mddev_dev
*devlist
, int verbose
)
1663 int subfd
= open_dev(memb
->devnm
);
1667 * Ignore the return value because it's necessary
1668 * to handle failure condition here.
1670 Manage_subdevs(memb
->devnm
, subfd
, devlist
, verbose
,
1671 0, UOPT_UNDEFINED
, 0);
1677 * IncrementalRemove - Attempt to see if the passed in device belongs to any
1678 * raid arrays, and if so first fail (if needed) and then remove the device.
1680 * @devname - The device we want to remove
1681 * @id_path - name as found in /dev/disk/by-path for this device
1683 * Note: the device name must be a kernel name like "sda", so
1684 * that we can find it in /proc/mdstat
1686 int IncrementalRemove(char *devname
, char *id_path
, int verbose
)
1690 struct mdstat_ent
*ent
;
1691 struct mddev_dev devlist
;
1693 char buf
[SYSFS_MAX_BUF_SIZE
];
1696 dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
1698 if (strchr(devname
, '/')) {
1699 pr_err("incremental removal requires a kernel device name, not a file: %s\n", devname
);
1702 ent
= mdstat_by_component(devname
);
1705 pr_err("%s does not appear to be a component of any array\n", devname
);
1708 if (sysfs_init(&mdi
, -1, ent
->devnm
)) {
1709 pr_err("unable to initialize sysfs for: %s\n", devname
);
1712 mdfd
= open_dev_excl(ent
->devnm
);
1713 if (is_fd_valid(mdfd
)) {
1715 if (sysfs_get_str(&mdi
, NULL
, "array_state",
1716 buf
, sizeof(buf
)) > 0) {
1717 if (strncmp(buf
, "active", 6) == 0 ||
1718 strncmp(buf
, "clean", 5) == 0)
1719 sysfs_set_str(&mdi
, NULL
,
1720 "array_state", "read-auto");
1723 mdfd
= open_dev(ent
->devnm
);
1726 pr_err("Cannot open array %s!!\n", ent
->devnm
);
1732 struct map_ent
*map
= NULL
, *me
;
1733 me
= map_by_devnm(&map
, ent
->devnm
);
1735 policy_save_path(id_path
, me
);
1739 memset(&devlist
, 0, sizeof(devlist
));
1740 devlist
.devname
= devname
;
1741 devlist
.disposition
= 'I';
1742 /* for a container, we must fail each member array */
1743 if (ent
->metadata_version
&&
1744 strncmp(ent
->metadata_version
, "external:", 9) == 0) {
1745 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
1746 struct mdstat_ent
*memb
;
1747 for (memb
= mdstat
; memb
; memb
= memb
->next
) {
1748 if (is_container_member(memb
, ent
->devnm
))
1749 remove_from_member_array(memb
,
1752 free_mdstat(mdstat
);
1755 * This 'I' incremental remove is a try-best effort,
1756 * the failure condition can be safely ignored
1757 * because of the following up 'r' remove.
1759 Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1760 verbose
, 0, UOPT_UNDEFINED
, 0);
1763 devlist
.disposition
= 'r';
1764 rv
= Manage_subdevs(ent
->devnm
, mdfd
, &devlist
,
1765 verbose
, 0, UOPT_UNDEFINED
, 0);