]> git.ipfire.org Git - thirdparty/mdadm.git/blame - Incremental.c
Some tidy up of 'devices' in assemble.
[thirdparty/mdadm.git] / Incremental.c
CommitLineData
8382f19b
NB
1/*
2 * Incremental.c - support --incremental. Part of:
3 * mdadm - manage Linux "md" devices aka RAID arrays.
4 *
5 * Copyright (C) 2006 Neil Brown <neilb@suse.de>
6 *
7 *
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.
12 *
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.
17 *
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
21 *
22 * Author: Neil Brown
23 * Email: <neilb@suse.de>
24 * Paper: Neil Brown
25 * Novell Inc
26 * GPO Box Q1283
27 * QVB Post Office, NSW 1230
28 * Australia
29 */
30
31#include "mdadm.h"
32
33static int count_active(struct supertype *st, int mdfd, char **availp,
34 struct mdinfo *info);
35static void find_reject(int mdfd, struct supertype *st, struct sysarray *sra,
36 int number, __u64 events, int verbose,
37 char *array_name);
38
39int Incremental(char *devname, int verbose, int runstop,
40 struct supertype *st, char *homehost, int autof)
41{
42 /* Add this device to an array, creating the array if necessary
43 * and starting the array if sensibe or - if runstop>0 - if possible.
44 *
45 * This has several steps:
46 *
47 * 1/ Check if device is permitted by mdadm.conf, reject if not.
48 * 2/ Find metadata, reject if none appropriate (check
49 * version/name from args)
50 * 3/ Check if there is a match in mdadm.conf
51 * 3a/ if not, check for homehost match. If no match, reject.
52 * 4/ Determine device number.
53 * - If in mdadm.conf with std name, use that
54 * - UUID in /var/run/mdadm.map use that
55 * - If name is suggestive, use that. unless in use with different uuid.
56 * - Choose a free, high number.
57 * - Use a partitioned device unless strong suggestion not to.
58 * e.g. auto=md
59 * 5/ Find out if array already exists
60 * 5a/ if it does not
61 * - choose a name, from mdadm.conf or 'name' field in array.
62 * - create the array
63 * - add the device
64 * 5b/ if it does
65 * - check one drive in array to make sure metadata is a reasonably
66 * close match. Reject if not (e.g. different type)
67 * - add the device
68 * 6/ Make sure /var/run/mdadm.map contains this array.
69 * 7/ Is there enough devices to possibly start the array?
70 * 7a/ if not, finish with success.
71 * 7b/ if yes,
72 * - read all metadata and arrange devices like -A does
73 * - if number of OK devices match expected, or -R and there are enough,
74 * start the array (auto-readonly).
75 */
76 struct stat stb;
8382f19b
NB
77 struct mdinfo info, info2;
78 struct mddev_ident_s *array_list, *match;
79 char chosen_name[1024];
80 int rv;
81 int devnum;
82 struct map_ent *mp, *map = NULL;
83 int dfd, mdfd;
84 char *avail;
85 int active_disks;
86
87
88 struct createinfo *ci = conf_get_create_info();
89
90 if (autof == 0)
91 autof = ci->autof;
92
93 /* 1/ Check if devices is permitted by mdadm.conf */
94
95 if (!conf_test_dev(devname)) {
96 if (verbose >= 0)
97 fprintf(stderr, Name
98 ": %s not permitted by mdadm.conf.\n",
99 devname);
100 return 1;
101 }
102
103 /* 2/ Find metadata, reject if none appropriate (check
104 * version/name from args) */
105
106 dfd = dev_open(devname, O_RDONLY|O_EXCL);
107 if (dfd < 0) {
108 if (verbose >= 0)
109 fprintf(stderr, Name ": cannot open %s: %s.\n",
110 devname, strerror(errno));
111 return 1;
112 }
113 if (fstat(dfd, &stb) < 0) {
114 if (verbose >= 0)
115 fprintf(stderr, Name ": fstat failed for %s: %s.\n",
116 devname, strerror(errno));
117 close(dfd);
118 return 1;
119 }
120 if ((stb.st_mode & S_IFMT) != S_IFBLK) {
121 if (verbose >= 0)
122 fprintf(stderr, Name ": %s is not a block device.\n",
123 devname);
124 close(dfd);
125 return 1;
126 }
127
128 if (st == NULL && (st = guess_super(dfd)) == NULL) {
129 if (verbose >= 0)
130 fprintf(stderr, Name
131 ": no recognisable superblock on %s.\n",
132 devname);
133 close(dfd);
134 return 1;
135 }
3da92f27 136 if (st->ss->load_super(st, dfd, NULL)) {
8382f19b
NB
137 if (verbose >= 0)
138 fprintf(stderr, Name ": no RAID superblock on %s.\n",
139 devname);
140 close(dfd);
141 return 1;
142 }
3da92f27 143 st->ss->getinfo_super(st, &info);
8382f19b
NB
144 close (dfd);
145
146 /* 3/ Check if there is a match in mdadm.conf */
147
148 array_list = conf_get_ident(NULL);
149 match = NULL;
150 for (; array_list; array_list = array_list->next) {
151 if (array_list->uuid_set &&
152 same_uuid(array_list->uuid, info.uuid, st->ss->swapuuid)
153 == 0) {
154 if (verbose >= 2)
155 fprintf(stderr, Name
156 ": UUID differs from %s.\n",
157 array_list->devname);
158 continue;
159 }
160 if (array_list->name[0] &&
161 strcasecmp(array_list->name, info.name) != 0) {
162 if (verbose >= 2)
163 fprintf(stderr, Name
164 ": Name differs from %s.\n",
165 array_list->devname);
166 continue;
167 }
168 if (array_list->devices &&
169 !match_oneof(array_list->devices, devname)) {
170 if (verbose >= 2)
171 fprintf(stderr, Name
172 ": Not a listed device for %s.\n",
173 array_list->devname);
174 continue;
175 }
176 if (array_list->super_minor != UnSet &&
177 array_list->super_minor != info.array.md_minor) {
178 if (verbose >= 2)
179 fprintf(stderr, Name
180 ": Different super-minor to %s.\n",
181 array_list->devname);
182 continue;
183 }
184 if (!array_list->uuid_set &&
185 !array_list->name[0] &&
186 !array_list->devices &&
187 array_list->super_minor == UnSet) {
188 if (verbose >= 2)
189 fprintf(stderr, Name
190 ": %s doesn't have any identifying information.\n",
191 array_list->devname);
192 continue;
193 }
194 /* FIXME, should I check raid_disks and level too?? */
195
196 if (match) {
197 if (verbose >= 0)
198 fprintf(stderr, Name
199 ": we match both %s and %s - cannot decide which to use.\n",
200 match->devname, array_list->devname);
201 return 2;
202 }
203 match = array_list;
204 }
205
206 /* 3a/ if not, check for homehost match. If no match, reject. */
207 if (!match) {
208 if (homehost == NULL ||
3da92f27 209 st->ss->match_home(st, homehost) == 0) {
8382f19b
NB
210 if (verbose >= 0)
211 fprintf(stderr, Name
212 ": not found in mdadm.conf and not identified by homehost.\n");
213 return 2;
214 }
215 }
216 /* 4/ Determine device number. */
217 /* - If in mdadm.conf with std name, use that */
218 /* - UUID in /var/run/mdadm.map use that */
219 /* - If name is suggestive, use that. unless in use with */
220 /* different uuid. */
221 /* - Choose a free, high number. */
222 /* - Use a partitioned device unless strong suggestion not to. */
223 /* e.g. auto=md */
224 if (match && is_standard(match->devname, &devnum))
225 /* We have devnum now */;
226 else if ((mp = map_by_uuid(&map, info.uuid)) != NULL)
227 devnum = mp->devnum;
228 else {
229 /* Have to guess a bit. */
230 int use_partitions = 1;
231 char *np, *ep;
232 if ((autof&7) == 3 || (autof&7) == 5)
233 use_partitions = 0;
234 np = strchr(info.name, ':');
235 if (np)
236 np++;
237 else
238 np = info.name;
239 devnum = strtoul(np, &ep, 10);
240 if (ep > np && *ep == 0) {
241 /* This is a number. Let check that it is unused. */
242 if (mddev_busy(use_partitions ? (-1-devnum) : devnum))
243 devnum = -1;
244 } else
245 devnum = -1;
246
247 if (devnum < 0) {
248 /* Haven't found anything yet, choose something free */
249 /* There is similar code in mdopen.c - should unify */
250 for (devnum = 127 ; devnum != 128 ;
251 devnum = devnum ? devnum-1 : (1<<22)-1) {
252 if (mddev_busy(use_partitions ?
253 (-1-devnum) : devnum))
254 break;
255 }
256 if (devnum == 128) {
257 fprintf(stderr, Name
258 ": No spare md devices!!\n");
259 return 2;
260 }
261 }
262 devnum = use_partitions ? (-1-devnum) : devnum;
263 }
264 mdfd = open_mddev_devnum(match ? match->devname : NULL,
265 devnum,
266 info.name,
267 chosen_name);
268 if (mdfd < 0) {
269 fprintf(stderr, Name ": failed to open %s: %s.\n",
270 chosen_name, strerror(errno));
271 return 2;
272 }
273 /* 5/ Find out if array already exists */
274 if (! mddev_busy(devnum)) {
275 /* 5a/ if it does not */
276 /* - choose a name, from mdadm.conf or 'name' field in array. */
277 /* - create the array */
278 /* - add the device */
279 mdu_array_info_t ainf;
280 mdu_disk_info_t disk;
281 char md[20];
282 struct sysarray *sra;
283
284 memset(&ainf, 0, sizeof(ainf));
285 ainf.major_version = st->ss->major;
286 ainf.minor_version = st->minor_version;
287 if (ioctl(mdfd, SET_ARRAY_INFO, &ainf) != 0) {
288 fprintf(stderr, Name
289 ": SET_ARRAY_INFO failed for %s: %s\b",
290 chosen_name, strerror(errno));
291 close(mdfd);
292 return 2;
293 }
294 sprintf(md, "%d.%d\n", st->ss->major, st->minor_version);
295 sra = sysfs_read(mdfd, devnum, GET_VERSION);
296 sysfs_set_str(sra, NULL, "metadata_version", md);
297 memset(&disk, 0, sizeof(disk));
298 disk.major = major(stb.st_rdev);
299 disk.minor = minor(stb.st_rdev);
300 sysfs_free(sra);
301 if (ioctl(mdfd, ADD_NEW_DISK, &disk) != 0) {
302 fprintf(stderr, Name ": failed to add %s to %s: %s.\n",
303 devname, chosen_name, strerror(errno));
304 ioctl(mdfd, STOP_ARRAY, 0);
305 close(mdfd);
306 return 2;
307 }
308 sra = sysfs_read(mdfd, devnum, GET_DEVS);
309 if (!sra || !sra->devs || sra->devs->role >= 0) {
310 /* It really should be 'none' - must be old buggy
311 * kernel, and mdadm -I may not be able to complete.
312 * So reject it.
313 */
314 ioctl(mdfd, STOP_ARRAY, NULL);
315 fprintf(stderr, Name
316 ": You have an old buggy kernel which cannot support\n"
317 " --incremental reliably. Aborting.\n");
318 close(mdfd);
319 sysfs_free(sra);
320 return 2;
321 }
322 } else {
323 /* 5b/ if it does */
324 /* - check one drive in array to make sure metadata is a reasonably */
325 /* close match. Reject if not (e.g. different type) */
326 /* - add the device */
327 char dn[20];
328 int dfd2;
329 mdu_disk_info_t disk;
330 int err;
331 struct sysarray *sra;
3da92f27 332 struct supertype *st2;
8382f19b
NB
333 sra = sysfs_read(mdfd, devnum, (GET_VERSION | GET_DEVS |
334 GET_STATE));
335 if (sra->major_version != st->ss->major ||
336 sra->minor_version != st->minor_version) {
337 if (verbose >= 0)
338 fprintf(stderr, Name
339 ": %s has different metadata to chosen array %s %d.%d %d.%d.\n",
340 devname, chosen_name,
341 sra->major_version, sra->minor_version,
342 st->ss->major, st->minor_version);
343 close(mdfd);
344 return 1;
345 }
346 sprintf(dn, "%d:%d", sra->devs->major, sra->devs->minor);
347 dfd2 = dev_open(dn, O_RDONLY);
3da92f27
NB
348 st2 = dup_super(st);
349 if (st2->ss->load_super(st2, dfd2, NULL)) {
8382f19b
NB
350 fprintf(stderr, Name
351 ": Strange error loading metadata for %s.\n",
352 chosen_name);
353 close(mdfd);
354 close(dfd2);
355 return 2;
356 }
357 close(dfd2);
3da92f27
NB
358 st2->ss->getinfo_super(st2, &info2);
359 st2->ss->free_super(st2);
8382f19b
NB
360 if (info.array.level != info2.array.level ||
361 memcmp(info.uuid, info2.uuid, 16) != 0 ||
362 info.array.raid_disks != info2.array.raid_disks) {
363 fprintf(stderr, Name
364 ": unexpected difference between %s and %s.\n",
365 chosen_name, devname);
366 close(mdfd);
367 return 2;
368 }
369 memset(&disk, 0, sizeof(disk));
370 disk.major = major(stb.st_rdev);
371 disk.minor = minor(stb.st_rdev);
372 err = ioctl(mdfd, ADD_NEW_DISK, &disk);
373 if (err < 0 && errno == EBUSY) {
374 /* could be another device present with the same
375 * disk.number. Find and reject any such
376 */
377 find_reject(mdfd, st, sra, info.disk.number,
378 info.events, verbose, chosen_name);
379 err = ioctl(mdfd, ADD_NEW_DISK, &disk);
380 }
381 if (err < 0) {
382 fprintf(stderr, Name ": failed to add %s to %s: %s.\n",
383 devname, chosen_name, strerror(errno));
384 close(mdfd);
385 return 2;
386 }
387 }
388 /* 6/ Make sure /var/run/mdadm.map contains this array. */
389 map_update(&map, devnum,
390 info.array.major_version,
391 info.array.minor_version,
392 info.uuid, chosen_name);
393
394 /* 7/ Is there enough devices to possibly start the array? */
395 /* 7a/ if not, finish with success. */
f8409e54 396 avail = NULL;
8382f19b
NB
397 active_disks = count_active(st, mdfd, &avail, &info);
398 if (enough(info.array.level, info.array.raid_disks,
399 info.array.layout, info.array.state & 1,
400 avail, active_disks) == 0) {
401 free(avail);
402 if (verbose >= 0)
403 fprintf(stderr, Name
404 ": %s attached to %s, not enough to start (%d).\n",
405 devname, chosen_name, active_disks);
406 close(mdfd);
407 return 0;
408 }
409 free(avail);
410
411 /* 7b/ if yes, */
412 /* - if number of OK devices match expected, or -R and there */
413 /* are enough, */
414 /* + add any bitmap file */
415 /* + start the array (auto-readonly). */
416{
417 mdu_array_info_t ainf;
418
419 if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
420 if (verbose >= 0)
421 fprintf(stderr, Name
422 ": %s attached to %s which is already active.\n",
423 devname, chosen_name);
424 close (mdfd);
425 return 0;
426 }
427}
428 if (runstop > 0 || active_disks >= info.array.working_disks) {
429 struct sysarray *sra;
430 /* Let's try to start it */
431 if (match && match->bitmap_file) {
432 int bmfd = open(match->bitmap_file, O_RDWR);
433 if (bmfd < 0) {
434 fprintf(stderr, Name
435 ": Could not open bitmap file %s.\n",
436 match->bitmap_file);
437 close(mdfd);
438 return 1;
439 }
440 if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
441 close(bmfd);
442 fprintf(stderr, Name
443 ": Failed to set bitmapfile for %s.\n",
444 chosen_name);
445 close(mdfd);
446 return 1;
447 }
448 close(bmfd);
449 }
450 sra = sysfs_read(mdfd, devnum, 0);
451 if (sra == NULL || active_disks >= info.array.working_disks)
452 rv = ioctl(mdfd, RUN_ARRAY, NULL);
453 else
454 rv = sysfs_set_str(sra, NULL,
455 "array_state", "read-auto");
456 if (rv == 0) {
457 if (verbose >= 0)
458 fprintf(stderr, Name
459 ": %s attached to %s, which has been started.\n",
460 devname, chosen_name);
461 rv = 0;
462 } else {
463 fprintf(stderr, Name
464 ": %s attached to %s, but failed to start: %s.\n",
465 devname, chosen_name, strerror(errno));
466 rv = 1;
467 }
468 } else {
469 if (verbose >= 0)
470 fprintf(stderr, Name
471 ": %s attached to %s, not enough to start safely.\n",
472 devname, chosen_name);
473 rv = 0;
474 }
475 close(mdfd);
476 return rv;
477}
478
479static void find_reject(int mdfd, struct supertype *st, struct sysarray *sra,
480 int number, __u64 events, int verbose,
481 char *array_name)
482{
3da92f27 483 /* Find a device attached to this array with a disk.number of number
8382f19b
NB
484 * and events less than the passed events, and remove the device.
485 */
486 struct sysdev *d;
487 mdu_array_info_t ra;
488
489 if (ioctl(mdfd, GET_ARRAY_INFO, &ra) == 0)
490 return; /* not safe to remove from active arrays
491 * without thinking more */
492
493 for (d = sra->devs; d ; d = d->next) {
494 char dn[10];
495 int dfd;
8382f19b
NB
496 struct mdinfo info;
497 sprintf(dn, "%d:%d", d->major, d->minor);
498 dfd = dev_open(dn, O_RDONLY);
499 if (dfd < 0)
500 continue;
3da92f27 501 if (st->ss->load_super(st, dfd, NULL)) {
8382f19b
NB
502 close(dfd);
503 continue;
504 }
3da92f27
NB
505 st->ss->getinfo_super(st, &info);
506 st->ss->free_super(st);
8382f19b
NB
507 close(dfd);
508
509 if (info.disk.number != number ||
510 info.events >= events)
511 continue;
512
513 if (d->role > -1)
514 sysfs_set_str(sra, d, "slot", "none");
515 if (sysfs_set_str(sra, d, "state", "remove") == 0)
516 if (verbose >= 0)
517 fprintf(stderr, Name
518 ": removing old device %s from %s\n",
519 d->name+4, array_name);
520 }
521}
522
523static int count_active(struct supertype *st, int mdfd, char **availp,
524 struct mdinfo *bestinfo)
525{
526 /* count how many devices in sra think they are active */
527 struct sysdev *d;
528 int cnt = 0, cnt1 = 0;
529 __u64 max_events = 0;
8382f19b
NB
530 struct sysarray *sra = sysfs_read(mdfd, -1, GET_DEVS | GET_STATE);
531 char *avail = NULL;
532
533 for (d = sra->devs ; d ; d = d->next) {
534 char dn[30];
535 int dfd;
8382f19b
NB
536 int ok;
537 struct mdinfo info;
538
539 sprintf(dn, "%d:%d", d->major, d->minor);
540 dfd = dev_open(dn, O_RDONLY);
541 if (dfd < 0)
542 continue;
3da92f27 543 ok = st->ss->load_super(st, dfd, NULL);
8382f19b
NB
544 close(dfd);
545 if (ok != 0)
546 continue;
3da92f27 547 st->ss->getinfo_super(st, &info);
8382f19b
NB
548 if (info.disk.state & (1<<MD_DISK_SYNC))
549 {
550 if (avail == NULL) {
551 avail = malloc(info.array.raid_disks);
552 memset(avail, 0, info.array.raid_disks);
553 }
554 if (cnt == 0) {
555 cnt++;
556 max_events = info.events;
557 avail[info.disk.raid_disk] = 2;
3da92f27 558 st->ss->getinfo_super(st, bestinfo);
8382f19b
NB
559 } else if (info.events == max_events) {
560 cnt++;
561 avail[info.disk.raid_disk] = 2;
562 } else if (info.events == max_events-1) {
563 cnt1++;
564 avail[info.disk.raid_disk] = 1;
565 } else if (info.events < max_events - 1)
566 ;
567 else if (info.events == max_events+1) {
568 int i;
569 cnt1 = cnt;
570 cnt = 1;
571 max_events = info.events;
572 for (i=0; i<info.array.raid_disks; i++)
573 if (avail[i])
574 avail[i]--;
575 avail[info.disk.raid_disk] = 2;
3da92f27 576 st->ss->getinfo_super(st, bestinfo);
8382f19b
NB
577 } else { /* info.events much bigger */
578 cnt = 1; cnt1 = 0;
579 memset(avail, 0, info.disk.raid_disk);
580 max_events = info.events;
3da92f27 581 st->ss->getinfo_super(st, bestinfo);
8382f19b
NB
582 }
583 }
3da92f27 584 st->ss->free_super(st);
8382f19b
NB
585 }
586 return cnt + cnt1;
587}
588
589void RebuildMap(void)
590{
591 struct mdstat_ent *mdstat = mdstat_read(0, 0);
592 struct mdstat_ent *md;
593 struct map_ent *map = NULL;
594 int mdp = get_mdp_major();
595
596 for (md = mdstat ; md ; md = md->next) {
597 struct sysarray *sra = sysfs_read(-1, md->devnum, GET_DEVS);
598 struct sysdev *sd;
599
600 for (sd = sra->devs ; sd ; sd = sd->next) {
601 char dn[30];
602 int dfd;
603 int ok;
604 struct supertype *st;
605 char *path;
8382f19b
NB
606 struct mdinfo info;
607
608 sprintf(dn, "%d:%d", sd->major, sd->minor);
609 dfd = dev_open(dn, O_RDONLY);
610 if (dfd < 0)
611 continue;
612 st = guess_super(dfd);
613 if ( st == NULL)
614 ok = -1;
615 else
3da92f27 616 ok = st->ss->load_super(st, dfd, NULL);
8382f19b
NB
617 close(dfd);
618 if (ok != 0)
619 continue;
3da92f27 620 st->ss->getinfo_super(st, &info);
8382f19b
NB
621 if (md->devnum > 0)
622 path = map_dev(MD_MAJOR, md->devnum, 0);
623 else
624 path = map_dev(mdp, (-1-md->devnum)<< 6, 0);
625 map_add(&map, md->devnum, st->ss->major,
626 st->minor_version,
627 info.uuid, path ? : "/unknown");
3da92f27 628 st->ss->free_super(st);
8382f19b
NB
629 break;
630 }
631 }
632 map_write(map);
633 map_free(map);
634}
635
636int IncrementalScan(int verbose)
637{
638 /* look at every device listed in the 'map' file.
639 * If one is found that is not running then:
640 * look in mdadm.conf for bitmap file.
641 * if one exists, but array has none, add it.
642 * try to start array in auto-readonly mode
643 */
644 struct map_ent *mapl = NULL;
645 struct map_ent *me;
646 mddev_ident_t devs, mddev;
647 int rv = 0;
648
649 map_read(&mapl);
650 devs = conf_get_ident(NULL);
651
652 for (me = mapl ; me ; me = me->next) {
653 char path[1024];
654 mdu_array_info_t array;
655 mdu_bitmap_file_t bmf;
656 struct sysarray *sra;
657 int mdfd = open_mddev_devnum(me->path, me->devnum, NULL, path);
658 if (mdfd < 0)
659 continue;
660 if (ioctl(mdfd, GET_ARRAY_INFO, &array) == 0 ||
661 errno != ENODEV) {
662 close(mdfd);
663 continue;
664 }
665 /* Ok, we can try this one. Maybe it needs a bitmap */
666 for (mddev = devs ; mddev ; mddev = mddev->next)
667 if (strcmp(mddev->devname, me->path) == 0)
668 break;
669 if (mddev && mddev->bitmap_file) {
670 /*
671 * Note: early kernels will wrongly fail this, so it
672 * is a hint only
673 */
674 int added = -1;
675 if (ioctl(mdfd, GET_ARRAY_INFO, &bmf) < 0) {
676 int bmfd = open(mddev->bitmap_file, O_RDWR);
677 if (bmfd >= 0) {
678 added = ioctl(mdfd, SET_BITMAP_FILE,
679 bmfd);
680 close(bmfd);
681 }
682 }
683 if (verbose >= 0) {
684 if (added == 0)
685 fprintf(stderr, Name
686 ": Added bitmap %s to %s\n",
687 mddev->bitmap_file, me->path);
688 else if (errno != EEXIST)
689 fprintf(stderr, Name
690 ": Failed to add bitmap to %s: %s\n",
691 me->path, strerror(errno));
692 }
693 }
694 sra = sysfs_read(mdfd, 0, 0);
695 if (sra) {
696 if (sysfs_set_str(sra, NULL,
697 "array_state", "read-auto") == 0) {
698 if (verbose >= 0)
699 fprintf(stderr, Name
700 ": started array %s\n",
701 me->path);
702 } else {
703 fprintf(stderr, Name
704 ": failed to start array %s: %s\n",
705 me->path, strerror(errno));
706 rv = 1;
707 }
708 }
709 }
710 return rv;
711}