]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Manage.c
tests: zero devices before --adding them.
[thirdparty/mdadm.git] / Manage.c
1 /*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001-2012 Neil Brown <neilb@suse.de>
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Author: Neil Brown
22 * Email: <neilb@suse.de>
23 */
24
25 #include "mdadm.h"
26 #include "md_u.h"
27 #include "md_p.h"
28 #include <ctype.h>
29
30 #define REGISTER_DEV _IO (MD_MAJOR, 1)
31 #define START_MD _IO (MD_MAJOR, 2)
32 #define STOP_MD _IO (MD_MAJOR, 3)
33
34 int Manage_ro(char *devname, int fd, int readonly)
35 {
36 /* switch to readonly or rw
37 *
38 * requires >= 0.90.0
39 * first check that array is runing
40 * use RESTART_ARRAY_RW or STOP_ARRAY_RO
41 *
42 */
43 mdu_array_info_t array;
44 #ifndef MDASSEMBLE
45 struct mdinfo *mdi;
46 #endif
47 int rv = 0;
48
49 if (md_get_version(fd) < 9000) {
50 pr_err("need md driver version 0.90.0 or later\n");
51 return 1;
52 }
53 #ifndef MDASSEMBLE
54 /* If this is an externally-managed array, we need to modify the
55 * metadata_version so that mdmon doesn't undo our change.
56 */
57 mdi = sysfs_read(fd, NULL, GET_LEVEL|GET_VERSION);
58 if (mdi &&
59 mdi->array.major_version == -1 &&
60 is_subarray(mdi->text_version)) {
61 char vers[64];
62 strcpy(vers, "external:");
63 strcat(vers, mdi->text_version);
64 if (readonly > 0) {
65 int rv;
66 /* We set readonly ourselves. */
67 vers[9] = '-';
68 sysfs_set_str(mdi, NULL, "metadata_version", vers);
69
70 close(fd);
71 rv = sysfs_set_str(mdi, NULL, "array_state", "readonly");
72
73 if (rv < 0) {
74 pr_err("failed to set readonly for %s: %s\n",
75 devname, strerror(errno));
76
77 vers[9] = mdi->text_version[0];
78 sysfs_set_str(mdi, NULL, "metadata_version", vers);
79 rv = 1;
80 goto out;
81 }
82 } else {
83 char *cp;
84 /* We cannot set read/write - must signal mdmon */
85 vers[9] = '/';
86 sysfs_set_str(mdi, NULL, "metadata_version", vers);
87
88 cp = strchr(vers+10, '/');
89 if (cp)
90 *cp = 0;
91 ping_monitor(vers+10);
92 if (mdi->array.level <= 0)
93 sysfs_set_str(mdi, NULL, "array_state", "active");
94 }
95 goto out;
96 }
97 #endif
98 if (ioctl(fd, GET_ARRAY_INFO, &array)) {
99 pr_err("%s does not appear to be active.\n",
100 devname);
101 rv = 1;
102 goto out;
103 }
104
105 if (readonly > 0) {
106 if (ioctl(fd, STOP_ARRAY_RO, NULL)) {
107 pr_err("failed to set readonly for %s: %s\n",
108 devname, strerror(errno));
109 rv = 1;
110 goto out;
111 }
112 } else if (readonly < 0) {
113 if (ioctl(fd, RESTART_ARRAY_RW, NULL)) {
114 pr_err("failed to set writable for %s: %s\n",
115 devname, strerror(errno));
116 rv = 1;
117 goto out;
118 }
119 }
120 out:
121 #ifndef MDASSEMBLE
122 if (mdi)
123 sysfs_free(mdi);
124 #endif
125 return rv;
126 }
127
128 #ifndef MDASSEMBLE
129
130 static void remove_devices(char *devnm, char *path)
131 {
132 /*
133 * Remove names at 'path' - possibly with
134 * partition suffixes - which link to the 'standard'
135 * name for devnm. These were probably created
136 * by mdadm when the array was assembled.
137 */
138 char base[40];
139 char *path2;
140 char link[1024];
141 int n;
142 int part;
143 char *be;
144 char *pe;
145
146 if (!path)
147 return;
148
149 sprintf(base, "/dev/%s", devnm);
150 be = base + strlen(base);
151
152 path2 = xmalloc(strlen(path)+20);
153 strcpy(path2, path);
154 pe = path2 + strlen(path2);
155
156 for (part = 0; part < 16; part++) {
157 if (part) {
158 sprintf(be, "p%d", part);
159
160 if (isdigit(pe[-1]))
161 sprintf(pe, "p%d", part);
162 else
163 sprintf(pe, "%d", part);
164 }
165 n = readlink(path2, link, sizeof(link));
166 if (n > 0 && (int)strlen(base) == n &&
167 strncmp(link, base, n) == 0)
168 unlink(path2);
169 }
170 free(path2);
171 }
172
173 int Manage_runstop(char *devname, int fd, int runstop,
174 int verbose, int will_retry)
175 {
176 /* Run or stop the array. Array must already be configured
177 * 'Run' requires >= 0.90.0
178 * 'will_retry' is only relevant for 'stop', and means
179 * that error messages are not wanted.
180 */
181 mdu_param_t param; /* unused */
182 int rv = 0;
183
184 if (will_retry && verbose == 0)
185 verbose = -1;
186
187 if (runstop == -1 && md_get_version(fd) < 9000) {
188 if (ioctl(fd, STOP_MD, 0) == 0)
189 return 0;
190 pr_err("stopping device %s "
191 "failed: %s\n",
192 devname, strerror(errno));
193 return 1;
194 }
195
196 if (md_get_version(fd) < 9000) {
197 pr_err("need md driver version 0.90.0 or later\n");
198 return 1;
199 }
200
201 if (runstop > 0) {
202 if (ioctl(fd, RUN_ARRAY, &param)) {
203 if (verbose >= 0)
204 pr_err("failed to run array %s: %s\n",
205 devname, strerror(errno));
206 return 1;
207 }
208 if (verbose >= 0)
209 pr_err("started %s\n", devname);
210 } else if (runstop < 0){
211 struct map_ent *map = NULL;
212 struct stat stb;
213 struct mdinfo *mdi;
214 char devnm[32];
215 char container[32];
216 int err;
217 int count;
218 /* If this is an mdmon managed array, just write 'inactive'
219 * to the array state and let mdmon clear up.
220 */
221 strcpy(devnm, fd2devnm(fd));
222 /* Get EXCL access first. If this fails, then attempting
223 * to stop is probably a bad idea.
224 */
225 mdi = sysfs_read(fd, NULL, GET_LEVEL|GET_VERSION);
226 if (mdi && is_subarray(mdi->text_version)) {
227 char *sl;
228 strncpy(container, mdi->text_version+1, sizeof(container));
229 container[sizeof(container)-1] = 0;
230 sl = strchr(container, '/');
231 if (sl)
232 *sl = 0;
233 } else
234 container[0] = 0;
235 close(fd);
236 count = 5;
237 while (((fd = ((devnm[0] == '/')
238 ?open(devname, O_RDONLY|O_EXCL)
239 :open_dev_flags(devnm, O_RDONLY|O_EXCL))) < 0
240 || strcmp(fd2devnm(fd), devnm) != 0)
241 && container[0]
242 && mdmon_running(container)
243 && count) {
244 if (fd >= 0)
245 close(fd);
246 flush_mdmon(container);
247 count--;
248 }
249 if (fd < 0 || strcmp(fd2devnm(fd), devnm) != 0) {
250 if (fd >= 0)
251 close(fd);
252 if (verbose >= 0)
253 pr_err("Cannot get exclusive access to %s:"
254 "Perhaps a running "
255 "process, mounted filesystem "
256 "or active volume group?\n",
257 devname);
258 return 1;
259 }
260 if (mdi &&
261 mdi->array.level > 0 &&
262 is_subarray(mdi->text_version)) {
263 int err;
264 /* This is mdmon managed. */
265 close(fd);
266
267 /* As we have an O_EXCL open, any use of the device
268 * which blocks STOP_ARRAY is probably a transient use,
269 * so it is reasonable to retry for a while - 5 seconds.
270 */
271 count = 25;
272 while (count &&
273 (err = sysfs_set_str(mdi, NULL,
274 "array_state",
275 "inactive")) < 0
276 && errno == EBUSY) {
277 usleep(200000);
278 count--;
279 }
280 if (err) {
281 if (verbose >= 0)
282 pr_err("failed to stop array %s: %s\n",
283 devname, strerror(errno));
284 rv = 1;
285 goto out;
286 }
287
288 /* Give monitor a chance to act */
289 ping_monitor(mdi->text_version);
290
291 fd = open_dev_excl(devnm);
292 if (fd < 0) {
293 if (verbose >= 0)
294 pr_err("failed to completely stop %s"
295 ": Device is busy\n",
296 devname);
297 rv = 1;
298 goto out;
299 }
300 } else if (mdi &&
301 mdi->array.major_version == -1 &&
302 mdi->array.minor_version == -2 &&
303 !is_subarray(mdi->text_version)) {
304 struct mdstat_ent *mds, *m;
305 /* container, possibly mdmon-managed.
306 * Make sure mdmon isn't opening it, which
307 * would interfere with the 'stop'
308 */
309 ping_monitor(mdi->sys_name);
310
311 /* now check that there are no existing arrays
312 * which are members of this array
313 */
314 mds = mdstat_read(0, 0);
315 for (m = mds; m; m = m->next)
316 if (m->metadata_version &&
317 strncmp(m->metadata_version, "external:", 9)==0 &&
318 metadata_container_matches(m->metadata_version+9,
319 devnm)) {
320 if (verbose >= 0)
321 pr_err("Cannot stop container %s: "
322 "member %s still active\n",
323 devname, m->dev);
324 free_mdstat(mds);
325 rv = 1;
326 goto out;
327 }
328 }
329
330 /* As we have an O_EXCL open, any use of the device
331 * which blocks STOP_ARRAY is probably a transient use,
332 * so it is reasonable to retry for a while - 5 seconds.
333 */
334 count = 25; err = 0;
335 while (count && fd >= 0
336 && (err = ioctl(fd, STOP_ARRAY, NULL)) < 0
337 && errno == EBUSY) {
338 usleep(200000);
339 count --;
340 }
341 if (fd >= 0 && err) {
342 if (verbose >= 0) {
343 pr_err("failed to stop array %s: %s\n",
344 devname, strerror(errno));
345 if (errno == EBUSY)
346 fprintf(stderr, "Perhaps a running "
347 "process, mounted filesystem "
348 "or active volume group?\n");
349 }
350 rv = 1;
351 goto out;
352 }
353 /* prior to 2.6.28, KOBJ_CHANGE was not sent when an md array
354 * was stopped, so We'll do it here just to be sure. Drop any
355 * partitions as well...
356 */
357 if (fd >= 0)
358 ioctl(fd, BLKRRPART, 0);
359 if (mdi)
360 sysfs_uevent(mdi, "change");
361
362 if (devnm[0] &&
363 (stat("/dev/.udev", &stb) != 0 ||
364 check_env("MDADM_NO_UDEV"))) {
365 struct map_ent *mp = map_by_devnm(&map, devnm);
366 remove_devices(devnm, mp ? mp->path : NULL);
367 }
368
369 if (verbose >= 0)
370 pr_err("stopped %s\n", devname);
371 map_lock(&map);
372 map_remove(&map, devnm);
373 map_unlock(&map);
374 out:
375 if (mdi)
376 sysfs_free(mdi);
377 }
378 return rv;
379 }
380
381 static struct mddev_dev *add_one(struct mddev_dev *dv, char *name, char disp)
382 {
383 struct mddev_dev *new;
384 new = xmalloc(sizeof(*new));
385 memset(new, 0, sizeof(*new));
386 new->devname = xstrdup(name);
387 new->disposition = disp;
388 new->next = dv->next;
389 dv->next = new;
390 return new;
391 }
392
393 static void add_faulty(struct mddev_dev *dv, int fd, char disp)
394 {
395 mdu_array_info_t array;
396 mdu_disk_info_t disk;
397 int remaining_disks;
398 int i;
399
400 if (ioctl(fd, GET_ARRAY_INFO, &array) != 0)
401 return;
402
403 remaining_disks = array.nr_disks;
404 for (i = 0; i < MAX_DISKS && remaining_disks > 0; i++) {
405 char buf[40];
406 disk.number = i;
407 if (ioctl(fd, GET_DISK_INFO, &disk) != 0)
408 continue;
409 if (disk.major == 0 && disk.minor == 0)
410 continue;
411 remaining_disks--;
412 if ((disk.state & 1) == 0) /* not faulty */
413 continue;
414 sprintf(buf, "%d:%d", disk.major, disk.minor);
415 dv = add_one(dv, buf, disp);
416 }
417 }
418
419 static void add_detached(struct mddev_dev *dv, int fd, char disp)
420 {
421 mdu_array_info_t array;
422 mdu_disk_info_t disk;
423 int remaining_disks;
424 int i;
425
426 if (ioctl(fd, GET_ARRAY_INFO, &array) != 0)
427 return;
428
429 remaining_disks = array.nr_disks;
430 for (i = 0; i < MAX_DISKS && remaining_disks > 0; i++) {
431 char buf[40];
432 int sfd;
433 disk.number = i;
434 if (ioctl(fd, GET_DISK_INFO, &disk) != 0)
435 continue;
436 if (disk.major == 0 && disk.minor == 0)
437 continue;
438 remaining_disks--;
439 if (disp == 'f' && (disk.state & 1) != 0) /* already faulty */
440 continue;
441 sprintf(buf, "%d:%d", disk.major, disk.minor);
442 sfd = dev_open(buf, O_RDONLY);
443 if (sfd >= 0) {
444 /* Not detached */
445 close(sfd);
446 continue;
447 }
448 if (errno != ENXIO)
449 /* Probably not detached */
450 continue;
451 dv = add_one(dv, buf, disp);
452 }
453 }
454
455 int attempt_re_add(int fd, int tfd, struct mddev_dev *dv,
456 struct supertype *dev_st, struct supertype *tst,
457 unsigned long rdev,
458 char *update, char *devname, int verbose,
459 mdu_array_info_t *array)
460 {
461 struct mdinfo mdi;
462 int duuid[4];
463 int ouuid[4];
464
465 dev_st->ss->getinfo_super(dev_st, &mdi, NULL);
466 dev_st->ss->uuid_from_super(dev_st, ouuid);
467 if (tst->sb)
468 tst->ss->uuid_from_super(tst, duuid);
469 else
470 /* Assume uuid matches: kernel will check */
471 memcpy(duuid, ouuid, sizeof(ouuid));
472 if ((mdi.disk.state & (1<<MD_DISK_ACTIVE)) &&
473 !(mdi.disk.state & (1<<MD_DISK_FAULTY)) &&
474 memcmp(duuid, ouuid, sizeof(ouuid))==0) {
475 /* Looks like it is worth a
476 * try. Need to make sure
477 * kernel will accept it
478 * though.
479 */
480 mdu_disk_info_t disc;
481 /* re-add doesn't work for version-1 superblocks
482 * before 2.6.18 :-(
483 */
484 if (array->major_version == 1 &&
485 get_linux_version() <= 2006018)
486 goto skip_re_add;
487 disc.number = mdi.disk.number;
488 if (ioctl(fd, GET_DISK_INFO, &disc) != 0
489 || disc.major != 0 || disc.minor != 0
490 )
491 goto skip_re_add;
492 disc.major = major(rdev);
493 disc.minor = minor(rdev);
494 disc.number = mdi.disk.number;
495 disc.raid_disk = mdi.disk.raid_disk;
496 disc.state = mdi.disk.state;
497 if (dv->writemostly == 1)
498 disc.state |= 1 << MD_DISK_WRITEMOSTLY;
499 if (dv->writemostly == 2)
500 disc.state &= ~(1 << MD_DISK_WRITEMOSTLY);
501 remove_partitions(tfd);
502 if (update || dv->writemostly > 0) {
503 int rv = -1;
504 tfd = dev_open(dv->devname, O_RDWR);
505 if (tfd < 0) {
506 pr_err("failed to open %s for"
507 " superblock update during re-add\n", dv->devname);
508 return -1;
509 }
510
511 if (dv->writemostly == 1)
512 rv = dev_st->ss->update_super(
513 dev_st, NULL, "writemostly",
514 devname, verbose, 0, NULL);
515 if (dv->writemostly == 2)
516 rv = dev_st->ss->update_super(
517 dev_st, NULL, "readwrite",
518 devname, verbose, 0, NULL);
519 if (update)
520 rv = dev_st->ss->update_super(
521 dev_st, NULL, update,
522 devname, verbose, 0, NULL);
523 if (rv == 0)
524 rv = dev_st->ss->store_super(dev_st, tfd);
525 close(tfd);
526 if (rv != 0) {
527 pr_err("failed to update"
528 " superblock during re-add\n");
529 return -1;
530 }
531 }
532 /* don't even try if disk is marked as faulty */
533 errno = 0;
534 if (ioctl(fd, ADD_NEW_DISK, &disc) == 0) {
535 if (verbose >= 0)
536 pr_err("re-added %s\n", dv->devname);
537 return 1;
538 }
539 if (errno == ENOMEM || errno == EROFS) {
540 pr_err("add new device failed for %s: %s\n",
541 dv->devname, strerror(errno));
542 if (dv->disposition == 'M')
543 return 0;
544 return -1;
545 }
546 }
547 skip_re_add:
548 return 0;
549 }
550
551 int Manage_add(int fd, int tfd, struct mddev_dev *dv,
552 struct supertype *tst, mdu_array_info_t *array,
553 int force, int verbose, char *devname,
554 char *update, unsigned long rdev, unsigned long long array_size)
555 {
556 unsigned long long ldsize;
557 struct supertype *dev_st = NULL;
558 int j;
559 mdu_disk_info_t disc;
560
561 if (!get_dev_size(tfd, dv->devname, &ldsize)) {
562 if (dv->disposition == 'M')
563 return 0;
564 else
565 return -1;
566 }
567
568 if (tst->ss->validate_geometry(
569 tst, array->level, array->layout,
570 array->raid_disks, NULL,
571 ldsize >> 9, INVALID_SECTORS, NULL, NULL, 0) == 0) {
572 if (!force) {
573 pr_err("%s is larger than %s can "
574 "effectively use.\n"
575 " Add --force is you "
576 "really want to add this device.\n",
577 dv->devname, devname);
578 return -1;
579 }
580 pr_err("%s is larger than %s can "
581 "effectively use.\n"
582 " Adding anyway as --force "
583 "was given.\n",
584 dv->devname, devname);
585 }
586 if (!tst->ss->external &&
587 array->major_version == 0 &&
588 md_get_version(fd)%100 < 2) {
589 if (ioctl(fd, HOT_ADD_DISK, rdev)==0) {
590 if (verbose >= 0)
591 pr_err("hot added %s\n",
592 dv->devname);
593 return 1;
594 }
595
596 pr_err("hot add failed for %s: %s\n",
597 dv->devname, strerror(errno));
598 return -1;
599 }
600
601 if (array->not_persistent == 0 || tst->ss->external) {
602
603 /* need to find a sample superblock to copy, and
604 * a spare slot to use.
605 * For 'external' array (well, container based),
606 * We can just load the metadata for the array->
607 */
608 int array_failed;
609 if (tst->sb)
610 /* already loaded */;
611 else if (tst->ss->external) {
612 tst->ss->load_container(tst, fd, NULL);
613 } else for (j = 0; j < tst->max_devs; j++) {
614 char *dev;
615 int dfd;
616 disc.number = j;
617 if (ioctl(fd, GET_DISK_INFO, &disc))
618 continue;
619 if (disc.major==0 && disc.minor==0)
620 continue;
621 if ((disc.state & 4)==0) /* sync */
622 continue;
623 /* Looks like a good device to try */
624 dev = map_dev(disc.major, disc.minor, 1);
625 if (!dev)
626 continue;
627 dfd = dev_open(dev, O_RDONLY);
628 if (dfd < 0)
629 continue;
630 if (tst->ss->load_super(tst, dfd,
631 NULL)) {
632 close(dfd);
633 continue;
634 }
635 close(dfd);
636 break;
637 }
638 /* FIXME this is a bad test to be using */
639 if (!tst->sb && dv->disposition != 'a') {
640 /* we are re-adding a device to a
641 * completely dead array - have to depend
642 * on kernel to check
643 */
644 } else if (!tst->sb) {
645 pr_err("cannot load array metadata from %s\n", devname);
646 return -1;
647 }
648
649 /* Make sure device is large enough */
650 if (tst->ss->avail_size(tst, ldsize/512, INVALID_SECTORS) <
651 array_size) {
652 if (dv->disposition == 'M')
653 return 0;
654 pr_err("%s not large enough to join array\n",
655 dv->devname);
656 return -1;
657 }
658
659 /* Possibly this device was recently part of
660 * the array and was temporarily removed, and
661 * is now being re-added. If so, we can
662 * simply re-add it.
663 */
664
665 if (array->not_persistent==0) {
666 dev_st = dup_super(tst);
667 dev_st->ss->load_super(dev_st, tfd, NULL);
668 }
669 if (dev_st && dev_st->sb) {
670 int rv = attempt_re_add(fd, tfd, dv,
671 dev_st, tst,
672 rdev,
673 update, devname,
674 verbose,
675 array);
676 dev_st->ss->free_super(dev_st);
677 if (rv)
678 return rv;
679 }
680 if (dv->disposition == 'M') {
681 if (verbose > 0)
682 pr_err("--re-add for %s to %s is not possible\n",
683 dv->devname, devname);
684 return 0;
685 }
686 if (dv->disposition == 'A') {
687 pr_err("--re-add for %s to %s is not possible\n",
688 dv->devname, devname);
689 return -1;
690 }
691 if (array->active_disks < array->raid_disks) {
692 char *avail = xcalloc(array->raid_disks, 1);
693 int d;
694 int found = 0;
695
696 for (d = 0; d < MAX_DISKS && found < array->active_disks; d++) {
697 disc.number = d;
698 if (ioctl(fd, GET_DISK_INFO, &disc))
699 continue;
700 if (disc.major == 0 && disc.minor == 0)
701 continue;
702 if (!(disc.state & (1<<MD_DISK_SYNC)))
703 continue;
704 avail[disc.raid_disk] = 1;
705 found++;
706 }
707 array_failed = !enough(array->level, array->raid_disks,
708 array->layout, 1, avail);
709 } else
710 array_failed = 0;
711 if (array_failed) {
712 pr_err("%s has failed so using --add cannot work and might destroy\n",
713 devname);
714 pr_err("data on %s. You should stop the array and re-assemble it.\n",
715 dv->devname);
716 return -1;
717 }
718 } else {
719 /* non-persistent. Must ensure that new drive
720 * is at least array->size big.
721 */
722 if (ldsize/512 < array_size) {
723 pr_err("%s not large enough to join array\n",
724 dv->devname);
725 return -1;
726 }
727 }
728 /* committed to really trying this device now*/
729 remove_partitions(tfd);
730
731 /* in 2.6.17 and earlier, version-1 superblocks won't
732 * use the number we write, but will choose a free number.
733 * we must choose the same free number, which requires
734 * starting at 'raid_disks' and counting up
735 */
736 for (j = array->raid_disks; j < tst->max_devs; j++) {
737 disc.number = j;
738 if (ioctl(fd, GET_DISK_INFO, &disc))
739 break;
740 if (disc.major==0 && disc.minor==0)
741 break;
742 if (disc.state & 8) /* removed */
743 break;
744 }
745 disc.major = major(rdev);
746 disc.minor = minor(rdev);
747 disc.number =j;
748 disc.state = 0;
749 if (array->not_persistent==0) {
750 int dfd;
751 if (dv->writemostly == 1)
752 disc.state |= 1 << MD_DISK_WRITEMOSTLY;
753 dfd = dev_open(dv->devname, O_RDWR | O_EXCL|O_DIRECT);
754 if (tst->ss->add_to_super(tst, &disc, dfd,
755 dv->devname, INVALID_SECTORS))
756 return -1;
757 if (tst->ss->write_init_super(tst))
758 return -1;
759 } else if (dv->disposition == 'A') {
760 /* this had better be raid1.
761 * As we are "--re-add"ing we must find a spare slot
762 * to fill.
763 */
764 char *used = xcalloc(array->raid_disks, 1);
765 for (j = 0; j < tst->max_devs; j++) {
766 mdu_disk_info_t disc2;
767 disc2.number = j;
768 if (ioctl(fd, GET_DISK_INFO, &disc2))
769 continue;
770 if (disc2.major==0 && disc2.minor==0)
771 continue;
772 if (disc2.state & 8) /* removed */
773 continue;
774 if (disc2.raid_disk < 0)
775 continue;
776 if (disc2.raid_disk > array->raid_disks)
777 continue;
778 used[disc2.raid_disk] = 1;
779 }
780 for (j = 0 ; j < array->raid_disks; j++)
781 if (!used[j]) {
782 disc.raid_disk = j;
783 disc.state |= (1<<MD_DISK_SYNC);
784 break;
785 }
786 free(used);
787 }
788 if (dv->writemostly == 1)
789 disc.state |= (1 << MD_DISK_WRITEMOSTLY);
790 if (tst->ss->external) {
791 /* add a disk
792 * to an external metadata container */
793 struct mdinfo new_mdi;
794 struct mdinfo *sra;
795 int container_fd;
796 char devnm[32];
797 int dfd;
798
799 strcpy(devnm, fd2devnm(fd));
800
801 container_fd = open_dev_excl(devnm);
802 if (container_fd < 0) {
803 pr_err("add failed for %s:"
804 " could not get exclusive access to container\n",
805 dv->devname);
806 tst->ss->free_super(tst);
807 return -1;
808 }
809
810 Kill(dv->devname, NULL, 0, -1, 0);
811 dfd = dev_open(dv->devname, O_RDWR | O_EXCL|O_DIRECT);
812 if (mdmon_running(tst->container_devnm))
813 tst->update_tail = &tst->updates;
814 if (tst->ss->add_to_super(tst, &disc, dfd,
815 dv->devname, INVALID_SECTORS)) {
816 close(dfd);
817 close(container_fd);
818 return -1;
819 }
820 if (tst->update_tail)
821 flush_metadata_updates(tst);
822 else
823 tst->ss->sync_metadata(tst);
824
825 sra = sysfs_read(container_fd, NULL, 0);
826 if (!sra) {
827 pr_err("add failed for %s: sysfs_read failed\n",
828 dv->devname);
829 close(container_fd);
830 tst->ss->free_super(tst);
831 return -1;
832 }
833 sra->array.level = LEVEL_CONTAINER;
834 /* Need to set data_offset and component_size */
835 tst->ss->getinfo_super(tst, &new_mdi, NULL);
836 new_mdi.disk.major = disc.major;
837 new_mdi.disk.minor = disc.minor;
838 new_mdi.recovery_start = 0;
839 /* Make sure fds are closed as they are O_EXCL which
840 * would block add_disk */
841 tst->ss->free_super(tst);
842 if (sysfs_add_disk(sra, &new_mdi, 0) != 0) {
843 pr_err("add new device to external metadata"
844 " failed for %s\n", dv->devname);
845 close(container_fd);
846 sysfs_free(sra);
847 return -1;
848 }
849 ping_monitor(devnm);
850 sysfs_free(sra);
851 close(container_fd);
852 } else {
853 tst->ss->free_super(tst);
854 if (ioctl(fd, ADD_NEW_DISK, &disc)) {
855 pr_err("add new device failed for %s as %d: %s\n",
856 dv->devname, j, strerror(errno));
857 return -1;
858 }
859 }
860 if (verbose >= 0)
861 pr_err("added %s\n", dv->devname);
862 return 1;
863 }
864
865 int Manage_remove(struct supertype *tst, int fd, struct mddev_dev *dv,
866 int sysfd, unsigned long rdev, int verbose, char *devname)
867 {
868 int lfd = -1;
869 int err;
870
871 if (tst->ss->external) {
872 /* To remove a device from a container, we must
873 * check that it isn't in use in an array.
874 * This involves looking in the 'holders'
875 * directory - there must be just one entry,
876 * the container.
877 * To ensure that it doesn't get used as a
878 * hot spare while we are checking, we
879 * get an O_EXCL open on the container
880 */
881 int ret;
882 char devnm[32];
883 strcpy(devnm, fd2devnm(fd));
884 lfd = open_dev_excl(devnm);
885 if (lfd < 0) {
886 pr_err("Cannot get exclusive access "
887 " to container - odd\n");
888 return -1;
889 }
890 /* We may not be able to check on holders in
891 * sysfs, either because we don't have the dev num
892 * (rdev == 0) or because the device has been detached
893 * and the 'holders' directory no longer exists
894 * (ret == -1). In that case, assume it is OK to
895 * remove.
896 */
897 if (rdev == 0)
898 ret = -1;
899 else
900 ret = sysfs_unique_holder(devnm, rdev);
901 if (ret == 0) {
902 pr_err("%s is not a member, cannot remove.\n",
903 dv->devname);
904 close(lfd);
905 return -1;
906 }
907 if (ret >= 2) {
908 pr_err("%s is still in use, cannot remove.\n",
909 dv->devname);
910 close(lfd);
911 return -1;
912 }
913 }
914 /* FIXME check that it is a current member */
915 if (sysfd >= 0) {
916 /* device has been removed and we don't know
917 * the major:minor number
918 */
919 int n = write(sysfd, "remove", 6);
920 if (n != 6)
921 err = -1;
922 else
923 err = 0;
924 } else {
925 err = ioctl(fd, HOT_REMOVE_DISK, rdev);
926 if (err && errno == ENODEV) {
927 /* Old kernels rejected this if no personality
928 * is registered */
929 struct mdinfo *sra = sysfs_read(fd, NULL, GET_DEVS);
930 struct mdinfo *dv = NULL;
931 if (sra)
932 dv = sra->devs;
933 for ( ; dv ; dv=dv->next)
934 if (dv->disk.major == (int)major(rdev) &&
935 dv->disk.minor == (int)minor(rdev))
936 break;
937 if (dv)
938 err = sysfs_set_str(sra, dv,
939 "state", "remove");
940 else
941 err = -1;
942 if (sra)
943 sysfs_free(sra);
944 }
945 }
946 if (err) {
947 pr_err("hot remove failed "
948 "for %s: %s\n", dv->devname,
949 strerror(errno));
950 if (lfd >= 0)
951 close(lfd);
952 return -1;
953 }
954 if (tst->ss->external) {
955 /*
956 * Before dropping our exclusive open we make an
957 * attempt at preventing mdmon from seeing an
958 * 'add' event before reconciling this 'remove'
959 * event.
960 */
961 char *devnm = fd2devnm(fd);
962
963 if (!devnm) {
964 pr_err("unable to get container name\n");
965 return -1;
966 }
967
968 ping_manager(devnm);
969 }
970 if (lfd >= 0)
971 close(lfd);
972 if (verbose >= 0)
973 pr_err("hot removed %s from %s\n",
974 dv->devname, devname);
975 return 1;
976 }
977
978 int Manage_replace(struct supertype *tst, int fd, struct mddev_dev *dv,
979 unsigned long rdev, int verbose, char *devname)
980 {
981 struct mdinfo *mdi, *di;
982 if (tst->ss->external) {
983 pr_err("--replace only supported for native metadata (0.90 or 1.x)\n");
984 return -1;
985 }
986 /* Need to find the device in sysfs and add 'want_replacement' to the
987 * status.
988 */
989 mdi = sysfs_read(fd, NULL, GET_DEVS);
990 if (!mdi || !mdi->devs) {
991 pr_err("Cannot find status of %s to enable replacement - strange\n",
992 devname);
993 return -1;
994 }
995 for (di = mdi->devs; di; di = di->next)
996 if (di->disk.major == (int)major(rdev) &&
997 di->disk.minor == (int)minor(rdev))
998 break;
999 if (di) {
1000 int rv;
1001 if (di->disk.raid_disk < 0) {
1002 pr_err("%s is not active and so cannot be replaced.\n",
1003 dv->devname);
1004 sysfs_free(mdi);
1005 return -1;
1006 }
1007 rv = sysfs_set_str(mdi, di,
1008 "state", "want_replacement");
1009 if (rv) {
1010 sysfs_free(mdi);
1011 pr_err("Failed to request replacement for %s\n",
1012 dv->devname);
1013 return -1;
1014 }
1015 if (verbose >= 0)
1016 pr_err("Marked %s (device %d in %s) for replacement\n",
1017 dv->devname, di->disk.raid_disk, devname);
1018 /* If there is a matching 'with', we need to tell it which
1019 * raid disk
1020 */
1021 while (dv && dv->disposition != 'W')
1022 dv = dv->next;
1023 if (dv) {
1024 dv->disposition = 'w';
1025 dv->used = di->disk.raid_disk;
1026 }
1027 return 1;
1028 }
1029 sysfs_free(mdi);
1030 pr_err("%s not found in %s so cannot --replace it\n",
1031 dv->devname, devname);
1032 return -1;
1033 }
1034
1035 int Manage_with(struct supertype *tst, int fd, struct mddev_dev *dv,
1036 unsigned long rdev, int verbose, char *devname)
1037 {
1038 struct mdinfo *mdi, *di;
1039 /* try to set 'slot' for 'rdev' in 'fd' to 'dv->used' */
1040 mdi = sysfs_read(fd, NULL, GET_DEVS|GET_STATE);
1041 if (!mdi || !mdi->devs) {
1042 pr_err("Cannot find status of %s to enable replacement - strange\n",
1043 devname);
1044 return -1;
1045 }
1046 for (di = mdi->devs; di; di = di->next)
1047 if (di->disk.major == (int)major(rdev) &&
1048 di->disk.minor == (int)minor(rdev))
1049 break;
1050 if (di) {
1051 int rv;
1052 if (di->disk.state & (1<<MD_DISK_FAULTY)) {
1053 pr_err("%s is faulty and cannot be a replacement\n",
1054 dv->devname);
1055 sysfs_free(mdi);
1056 return -1;
1057 }
1058 if (di->disk.raid_disk >= 0) {
1059 pr_err("%s is active and cannot be a replacement\n",
1060 dv->devname);
1061 sysfs_free(mdi);
1062 return -1;
1063 }
1064 rv = sysfs_set_num(mdi, di,
1065 "slot", dv->used);
1066 if (rv) {
1067 sysfs_free(mdi);
1068 pr_err("Failed to %s as preferred replacement.\n",
1069 dv->devname);
1070 return -1;
1071 }
1072 if (verbose >= 0)
1073 pr_err("Marked %s in %s as replacement for device %d\n",
1074 dv->devname, devname, dv->used);
1075 return 1;
1076 }
1077 sysfs_free(mdi);
1078 pr_err("%s not found in %s so cannot make it preferred replacement\n",
1079 dv->devname, devname);
1080 return -1;
1081 }
1082
1083 int Manage_subdevs(char *devname, int fd,
1084 struct mddev_dev *devlist, int verbose, int test,
1085 char *update, int force)
1086 {
1087 /* Do something to each dev.
1088 * devmode can be
1089 * 'a' - add the device
1090 * try HOT_ADD_DISK
1091 * If that fails EINVAL, try ADD_NEW_DISK
1092 * 'A' - re-add the device
1093 * 'r' - remove the device: HOT_REMOVE_DISK
1094 * device can be 'faulty' or 'detached' in which case all
1095 * matching devices are removed.
1096 * 'f' - set the device faulty SET_DISK_FAULTY
1097 * device can be 'detached' in which case any device that
1098 * is inaccessible will be marked faulty.
1099 * 'R' - mark this device as wanting replacement.
1100 * 'W' - this device is added if necessary and activated as
1101 * a replacement for a previous 'R' device.
1102 * -----
1103 * 'w' - 'W' will be changed to 'w' when it is paired with
1104 * a 'R' device. If a 'W' is found while walking the list
1105 * it must be unpaired, and is an error.
1106 * 'M' - this is created by a 'missing' target. It is a slight
1107 * variant on 'A'
1108 * 'F' - Another variant of 'A', where the device was faulty
1109 * so must be removed from the array first.
1110 *
1111 * For 'f' and 'r', the device can also be a kernel-internal
1112 * name such as 'sdb'.
1113 */
1114 mdu_array_info_t array;
1115 unsigned long long array_size;
1116 struct mddev_dev *dv;
1117 struct stat stb;
1118 int tfd = -1;
1119 struct supertype *tst;
1120 char *subarray = NULL;
1121 int sysfd = -1;
1122 int count = 0; /* number of actions taken */
1123 struct mdinfo info;
1124 int frozen = 0;
1125 int busy = 0;
1126
1127 if (ioctl(fd, GET_ARRAY_INFO, &array)) {
1128 pr_err("Cannot get array info for %s\n",
1129 devname);
1130 goto abort;
1131 }
1132 sysfs_init(&info, fd, NULL);
1133
1134 /* array.size is only 32 bits and may be truncated.
1135 * So read from sysfs if possible, and record number of sectors
1136 */
1137
1138 array_size = get_component_size(fd);
1139 if (array_size <= 0)
1140 array_size = array.size * 2;
1141
1142 tst = super_by_fd(fd, &subarray);
1143 if (!tst) {
1144 pr_err("unsupport array - version %d.%d\n",
1145 array.major_version, array.minor_version);
1146 goto abort;
1147 }
1148
1149 stb.st_rdev = 0;
1150 for (dv = devlist; dv; dv = dv->next) {
1151 int rv;
1152
1153 if (strcmp(dv->devname, "failed") == 0 ||
1154 strcmp(dv->devname, "faulty") == 0) {
1155 if (dv->disposition != 'A'
1156 && dv->disposition != 'r') {
1157 pr_err("%s only meaningful "
1158 "with -r or --re-add, not -%c\n",
1159 dv->devname, dv->disposition);
1160 goto abort;
1161 }
1162 add_faulty(dv, fd, (dv->disposition == 'A'
1163 ? 'F' : 'r'));
1164 continue;
1165 }
1166 if (strcmp(dv->devname, "detached") == 0) {
1167 if (dv->disposition != 'r' && dv->disposition != 'f') {
1168 pr_err("%s only meaningful "
1169 "with -r of -f, not -%c\n",
1170 dv->devname, dv->disposition);
1171 goto abort;
1172 }
1173 add_detached(dv, fd, dv->disposition);
1174 continue;
1175 }
1176
1177 if (strcmp(dv->devname, "missing") == 0) {
1178 struct mddev_dev *add_devlist = NULL;
1179 struct mddev_dev **dp;
1180 if (dv->disposition != 'A') {
1181 pr_err("'missing' only meaningful "
1182 "with --re-add\n");
1183 goto abort;
1184 }
1185 add_devlist = conf_get_devs();
1186 if (add_devlist == NULL) {
1187 pr_err("no devices to scan for missing members.");
1188 continue;
1189 }
1190 for (dp = &add_devlist; *dp; dp = & (*dp)->next)
1191 /* 'M' (for 'missing') is like 'A' without errors */
1192 (*dp)->disposition = 'M';
1193 *dp = dv->next;
1194 dv->next = add_devlist;
1195 continue;
1196 }
1197
1198 if (strchr(dv->devname, '/') == NULL &&
1199 strchr(dv->devname, ':') == NULL &&
1200 strlen(dv->devname) < 50) {
1201 /* Assume this is a kernel-internal name like 'sda1' */
1202 int found = 0;
1203 char dname[55];
1204 if (dv->disposition != 'r' && dv->disposition != 'f') {
1205 pr_err("%s only meaningful "
1206 "with -r or -f, not -%c\n",
1207 dv->devname, dv->disposition);
1208 goto abort;
1209 }
1210
1211 sprintf(dname, "dev-%s", dv->devname);
1212 sysfd = sysfs_open(fd2devnm(fd), dname, "block/dev");
1213 if (sysfd >= 0) {
1214 char dn[20];
1215 int mj,mn;
1216 if (sysfs_fd_get_str(sysfd, dn, 20) > 0 &&
1217 sscanf(dn, "%d:%d", &mj,&mn) == 2) {
1218 stb.st_rdev = makedev(mj,mn);
1219 found = 1;
1220 }
1221 close(sysfd);
1222 sysfd = -1;
1223 }
1224 if (!found) {
1225 sysfd = sysfs_open(fd2devnm(fd), dname, "state");
1226 if (sysfd < 0) {
1227 pr_err("%s does not appear "
1228 "to be a component of %s\n",
1229 dv->devname, devname);
1230 goto abort;
1231 }
1232 }
1233 } else {
1234 tfd = dev_open(dv->devname, O_RDONLY);
1235 if (tfd >= 0)
1236 fstat(tfd, &stb);
1237 else {
1238 int open_err = errno;
1239 if (stat(dv->devname, &stb) != 0) {
1240 pr_err("Cannot find %s: %s\n",
1241 dv->devname, strerror(errno));
1242 goto abort;
1243 }
1244 if ((stb.st_mode & S_IFMT) != S_IFBLK) {
1245 if (dv->disposition == 'M')
1246 /* non-fatal. Also improbable */
1247 continue;
1248 pr_err("%s is not a block device.\n",
1249 dv->devname);
1250 goto abort;
1251 }
1252 if (dv->disposition == 'r')
1253 /* Be happy, the stat worked, that is
1254 * enough for --remove
1255 */
1256 ;
1257 else {
1258 if (dv->disposition == 'M')
1259 /* non-fatal */
1260 continue;
1261 pr_err("Cannot open %s: %s\n",
1262 dv->devname, strerror(open_err));
1263 goto abort;
1264 }
1265 }
1266 }
1267 switch(dv->disposition){
1268 default:
1269 pr_err("internal error - devmode[%s]=%d\n",
1270 dv->devname, dv->disposition);
1271 goto abort;
1272 case 'a':
1273 case 'A':
1274 case 'M': /* --re-add missing */
1275 case 'F': /* --re-add faulty */
1276 /* add the device */
1277 if (subarray) {
1278 pr_err("Cannot add disks to a"
1279 " \'member\' array, perform this"
1280 " operation on the parent container\n");
1281 goto abort;
1282 }
1283 if (dv->disposition == 'F')
1284 /* Need to remove first */
1285 ioctl(fd, HOT_REMOVE_DISK,
1286 (unsigned long)stb.st_rdev);
1287 /* Make sure it isn't in use (in 2.6 or later) */
1288 tfd = dev_open(dv->devname, O_RDONLY|O_EXCL);
1289 if (tfd >= 0) {
1290 /* We know no-one else is using it. We'll
1291 * need non-exclusive access to add it, so
1292 * do that now.
1293 */
1294 close(tfd);
1295 tfd = dev_open(dv->devname, O_RDONLY);
1296 }
1297 if (tfd < 0) {
1298 if (dv->disposition == 'M')
1299 continue;
1300 pr_err("Cannot open %s: %s\n",
1301 dv->devname, strerror(errno));
1302 goto abort;
1303 }
1304 if (!frozen) {
1305 if (sysfs_freeze_array(&info) == 1)
1306 frozen = 1;
1307 else
1308 frozen = -1;
1309 }
1310 rv = Manage_add(fd, tfd, dv, tst, &array,
1311 force, verbose, devname, update,
1312 stb.st_rdev, array_size);
1313 close(tfd);
1314 tfd = -1;
1315 if (rv < 0)
1316 goto abort;
1317 if (rv > 0)
1318 count++;
1319 break;
1320
1321 case 'r':
1322 /* hot remove */
1323 if (subarray) {
1324 pr_err("Cannot remove disks from a"
1325 " \'member\' array, perform this"
1326 " operation on the parent container\n");
1327 rv = -1;
1328 } else
1329 rv = Manage_remove(tst, fd, dv, sysfd,
1330 stb.st_rdev, verbose,
1331 devname);
1332 if (sysfd >= 0)
1333 close(sysfd);
1334 sysfd = -1;
1335 if (rv < 0)
1336 goto abort;
1337 if (rv > 0)
1338 count++;
1339 break;
1340
1341 case 'f': /* set faulty */
1342 /* FIXME check current member */
1343 if ((sysfd >= 0 && write(sysfd, "faulty", 6) != 6) ||
1344 (sysfd < 0 && ioctl(fd, SET_DISK_FAULTY,
1345 (unsigned long) stb.st_rdev))) {
1346 if (errno == EBUSY)
1347 busy = 1;
1348 pr_err("set device faulty failed for %s: %s\n",
1349 dv->devname, strerror(errno));
1350 if (sysfd >= 0)
1351 close(sysfd);
1352 goto abort;
1353 }
1354 if (sysfd >= 0)
1355 close(sysfd);
1356 sysfd = -1;
1357 count++;
1358 if (verbose >= 0)
1359 pr_err("set %s faulty in %s\n",
1360 dv->devname, devname);
1361 break;
1362 case 'R': /* Mark as replaceable */
1363 if (subarray) {
1364 pr_err("Cannot replace disks in a"
1365 " \'member\' array, perform this"
1366 " operation on the parent container\n");
1367 rv = -1;
1368 } else {
1369 if (!frozen) {
1370 if (sysfs_freeze_array(&info) == 1)
1371 frozen = 1;
1372 else
1373 frozen = -1;
1374 }
1375 rv = Manage_replace(tst, fd, dv,
1376 stb.st_rdev, verbose,
1377 devname);
1378 }
1379 if (rv < 0)
1380 goto abort;
1381 if (rv > 0)
1382 count++;
1383 break;
1384 case 'W': /* --with device that doesn't match */
1385 pr_err("No matching --replace device for --with %s\n",
1386 dv->devname);
1387 goto abort;
1388 case 'w': /* --with device which was matched */
1389 rv = Manage_with(tst, fd, dv,
1390 stb.st_rdev, verbose, devname);
1391 if (rv < 0)
1392 goto abort;
1393 break;
1394 }
1395 }
1396 if (frozen > 0)
1397 sysfs_set_str(&info, NULL, "sync_action","idle");
1398 if (test && count == 0)
1399 return 2;
1400 return 0;
1401
1402 abort:
1403 if (frozen > 0)
1404 sysfs_set_str(&info, NULL, "sync_action","idle");
1405 return !test && busy ? 2 : 1;
1406 }
1407
1408 int autodetect(void)
1409 {
1410 /* Open any md device, and issue the RAID_AUTORUN ioctl */
1411 int rv = 1;
1412 int fd = dev_open("9:0", O_RDONLY);
1413 if (fd >= 0) {
1414 if (ioctl(fd, RAID_AUTORUN, 0) == 0)
1415 rv = 0;
1416 close(fd);
1417 }
1418 return rv;
1419 }
1420
1421 int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident *ident, int verbose)
1422 {
1423 struct supertype supertype, *st = &supertype;
1424 int fd, rv = 2;
1425
1426 memset(st, 0, sizeof(*st));
1427
1428 fd = open_subarray(dev, subarray, st, verbose < 0);
1429 if (fd < 0)
1430 return 2;
1431
1432 if (!st->ss->update_subarray) {
1433 if (verbose >= 0)
1434 pr_err("Operation not supported for %s metadata\n",
1435 st->ss->name);
1436 goto free_super;
1437 }
1438
1439 if (mdmon_running(st->devnm))
1440 st->update_tail = &st->updates;
1441
1442 rv = st->ss->update_subarray(st, subarray, update, ident);
1443
1444 if (rv) {
1445 if (verbose >= 0)
1446 pr_err("Failed to update %s of subarray-%s in %s\n",
1447 update, subarray, dev);
1448 } else if (st->update_tail)
1449 flush_metadata_updates(st);
1450 else
1451 st->ss->sync_metadata(st);
1452
1453 if (rv == 0 && strcmp(update, "name") == 0 && verbose >= 0)
1454 pr_err("Updated subarray-%s name from %s, UUIDs may have changed\n",
1455 subarray, dev);
1456
1457 free_super:
1458 st->ss->free_super(st);
1459 close(fd);
1460
1461 return rv;
1462 }
1463
1464 /* Move spare from one array to another If adding to destination array fails
1465 * add back to original array.
1466 * Returns 1 on success, 0 on failure */
1467 int move_spare(char *from_devname, char *to_devname, dev_t devid)
1468 {
1469 struct mddev_dev devlist;
1470 char devname[20];
1471
1472 /* try to remove and add */
1473 int fd1 = open(to_devname, O_RDONLY);
1474 int fd2 = open(from_devname, O_RDONLY);
1475
1476 if (fd1 < 0 || fd2 < 0) {
1477 if (fd1>=0) close(fd1);
1478 if (fd2>=0) close(fd2);
1479 return 0;
1480 }
1481
1482 devlist.next = NULL;
1483 devlist.used = 0;
1484 devlist.writemostly = 0;
1485 devlist.devname = devname;
1486 sprintf(devname, "%d:%d", major(devid), minor(devid));
1487
1488 devlist.disposition = 'r';
1489 if (Manage_subdevs(from_devname, fd2, &devlist, -1, 0, NULL, 0) == 0) {
1490 devlist.disposition = 'a';
1491 if (Manage_subdevs(to_devname, fd1, &devlist, -1, 0, NULL, 0) == 0) {
1492 /* make sure manager is aware of changes */
1493 ping_manager(to_devname);
1494 ping_manager(from_devname);
1495 close(fd1);
1496 close(fd2);
1497 return 1;
1498 }
1499 else Manage_subdevs(from_devname, fd2, &devlist, -1, 0, NULL, 0);
1500 }
1501 close(fd1);
1502 close(fd2);
1503 return 0;
1504 }
1505 #endif