]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Grow.c
Grow: goto release rather than just return
[thirdparty/mdadm.git] / Grow.c
1 /*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001-2009 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 #include "mdadm.h"
25 #include "dlink.h"
26 #include <sys/mman.h>
27
28 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
29 #error no endian defined
30 #endif
31 #include "md_u.h"
32 #include "md_p.h"
33
34 #ifndef offsetof
35 #define offsetof(t,f) ((size_t)&(((t*)0)->f))
36 #endif
37
38 int Grow_Add_device(char *devname, int fd, char *newdev)
39 {
40 /* Add a device to an active array.
41 * Currently, just extend a linear array.
42 * This requires writing a new superblock on the
43 * new device, calling the kernel to add the device,
44 * and if that succeeds, update the superblock on
45 * all other devices.
46 * This means that we need to *find* all other devices.
47 */
48 struct mdinfo info;
49
50 struct stat stb;
51 int nfd, fd2;
52 int d, nd;
53 struct supertype *st = NULL;
54
55
56 if (ioctl(fd, GET_ARRAY_INFO, &info.array) < 0) {
57 fprintf(stderr, Name ": cannot get array info for %s\n", devname);
58 return 1;
59 }
60
61 st = super_by_fd(fd);
62 if (!st) {
63 fprintf(stderr, Name ": cannot handle arrays with superblock version %d\n", info.array.major_version);
64 return 1;
65 }
66
67 if (info.array.level != -1) {
68 fprintf(stderr, Name ": can only add devices to linear arrays\n");
69 return 1;
70 }
71
72 nfd = open(newdev, O_RDWR|O_EXCL|O_DIRECT);
73 if (nfd < 0) {
74 fprintf(stderr, Name ": cannot open %s\n", newdev);
75 return 1;
76 }
77 fstat(nfd, &stb);
78 if ((stb.st_mode & S_IFMT) != S_IFBLK) {
79 fprintf(stderr, Name ": %s is not a block device!\n", newdev);
80 close(nfd);
81 return 1;
82 }
83 /* now check out all the devices and make sure we can read the superblock */
84 for (d=0 ; d < info.array.raid_disks ; d++) {
85 mdu_disk_info_t disk;
86 char *dv;
87
88 disk.number = d;
89 if (ioctl(fd, GET_DISK_INFO, &disk) < 0) {
90 fprintf(stderr, Name ": cannot get device detail for device %d\n",
91 d);
92 return 1;
93 }
94 dv = map_dev(disk.major, disk.minor, 1);
95 if (!dv) {
96 fprintf(stderr, Name ": cannot find device file for device %d\n",
97 d);
98 return 1;
99 }
100 fd2 = dev_open(dv, O_RDWR);
101 if (!fd2) {
102 fprintf(stderr, Name ": cannot open device file %s\n", dv);
103 return 1;
104 }
105 st->ss->free_super(st);
106
107 if (st->ss->load_super(st, fd2, NULL)) {
108 fprintf(stderr, Name ": cannot find super block on %s\n", dv);
109 close(fd2);
110 return 1;
111 }
112 close(fd2);
113 }
114 /* Ok, looks good. Lets update the superblock and write it out to
115 * newdev.
116 */
117
118 info.disk.number = d;
119 info.disk.major = major(stb.st_rdev);
120 info.disk.minor = minor(stb.st_rdev);
121 info.disk.raid_disk = d;
122 info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
123 st->ss->update_super(st, &info, "linear-grow-new", newdev,
124 0, 0, NULL);
125
126 if (st->ss->store_super(st, nfd)) {
127 fprintf(stderr, Name ": Cannot store new superblock on %s\n",
128 newdev);
129 close(nfd);
130 return 1;
131 }
132 close(nfd);
133
134 if (ioctl(fd, ADD_NEW_DISK, &info.disk) != 0) {
135 fprintf(stderr, Name ": Cannot add new disk to this array\n");
136 return 1;
137 }
138 /* Well, that seems to have worked.
139 * Now go through and update all superblocks
140 */
141
142 if (ioctl(fd, GET_ARRAY_INFO, &info.array) < 0) {
143 fprintf(stderr, Name ": cannot get array info for %s\n", devname);
144 return 1;
145 }
146
147 nd = d;
148 for (d=0 ; d < info.array.raid_disks ; d++) {
149 mdu_disk_info_t disk;
150 char *dv;
151
152 disk.number = d;
153 if (ioctl(fd, GET_DISK_INFO, &disk) < 0) {
154 fprintf(stderr, Name ": cannot get device detail for device %d\n",
155 d);
156 return 1;
157 }
158 dv = map_dev(disk.major, disk.minor, 1);
159 if (!dv) {
160 fprintf(stderr, Name ": cannot find device file for device %d\n",
161 d);
162 return 1;
163 }
164 fd2 = dev_open(dv, O_RDWR);
165 if (fd2 < 0) {
166 fprintf(stderr, Name ": cannot open device file %s\n", dv);
167 return 1;
168 }
169 if (st->ss->load_super(st, fd2, NULL)) {
170 fprintf(stderr, Name ": cannot find super block on %s\n", dv);
171 close(fd);
172 return 1;
173 }
174 info.array.raid_disks = nd+1;
175 info.array.nr_disks = nd+1;
176 info.array.active_disks = nd+1;
177 info.array.working_disks = nd+1;
178
179 st->ss->update_super(st, &info, "linear-grow-update", dv,
180 0, 0, NULL);
181
182 if (st->ss->store_super(st, fd2)) {
183 fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv);
184 close(fd2);
185 return 1;
186 }
187 close(fd2);
188 }
189
190 return 0;
191 }
192
193 int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int write_behind, int force)
194 {
195 /*
196 * First check that array doesn't have a bitmap
197 * Then create the bitmap
198 * Then add it
199 *
200 * For internal bitmaps, we need to check the version,
201 * find all the active devices, and write the bitmap block
202 * to all devices
203 */
204 mdu_bitmap_file_t bmf;
205 mdu_array_info_t array;
206 struct supertype *st;
207 int major = BITMAP_MAJOR_HI;
208 int vers = md_get_version(fd);
209 unsigned long long bitmapsize, array_size;
210
211 if (vers < 9003) {
212 major = BITMAP_MAJOR_HOSTENDIAN;
213 #ifdef __BIG_ENDIAN
214 fprintf(stderr, Name ": Warning - bitmaps created on this kernel are not portable\n"
215 " between different architectured. Consider upgrading the Linux kernel.\n");
216 #endif
217 }
218
219 if (ioctl(fd, GET_BITMAP_FILE, &bmf) != 0) {
220 if (errno == ENOMEM)
221 fprintf(stderr, Name ": Memory allocation failure.\n");
222 else
223 fprintf(stderr, Name ": bitmaps not supported by this kernel.\n");
224 return 1;
225 }
226 if (bmf.pathname[0]) {
227 if (strcmp(file,"none")==0) {
228 if (ioctl(fd, SET_BITMAP_FILE, -1)!= 0) {
229 fprintf(stderr, Name ": failed to remove bitmap %s\n",
230 bmf.pathname);
231 return 1;
232 }
233 return 0;
234 }
235 fprintf(stderr, Name ": %s already has a bitmap (%s)\n",
236 devname, bmf.pathname);
237 return 1;
238 }
239 if (ioctl(fd, GET_ARRAY_INFO, &array) != 0) {
240 fprintf(stderr, Name ": cannot get array status for %s\n", devname);
241 return 1;
242 }
243 if (array.state & (1<<MD_SB_BITMAP_PRESENT)) {
244 if (strcmp(file, "none")==0) {
245 array.state &= ~(1<<MD_SB_BITMAP_PRESENT);
246 if (ioctl(fd, SET_ARRAY_INFO, &array)!= 0) {
247 fprintf(stderr, Name ": failed to remove internal bitmap.\n");
248 return 1;
249 }
250 return 0;
251 }
252 fprintf(stderr, Name ": Internal bitmap already present on %s\n",
253 devname);
254 return 1;
255 }
256 if (array.level <= 0) {
257 fprintf(stderr, Name ": Bitmaps not meaningful with level %s\n",
258 map_num(pers, array.level)?:"of this array");
259 return 1;
260 }
261 bitmapsize = array.size;
262 bitmapsize <<= 1;
263 if (get_dev_size(fd, NULL, &array_size) &&
264 array_size > (0x7fffffffULL<<9)) {
265 /* Array is big enough that we cannot trust array.size
266 * try other approaches
267 */
268 bitmapsize = get_component_size(fd);
269 }
270 if (bitmapsize == 0) {
271 fprintf(stderr, Name ": Cannot reliably determine size of array to create bitmap - sorry.\n");
272 return 1;
273 }
274
275 if (array.level == 10) {
276 int ncopies = (array.layout&255)*((array.layout>>8)&255);
277 bitmapsize = bitmapsize * array.raid_disks / ncopies;
278 }
279
280 st = super_by_fd(fd);
281 if (!st) {
282 fprintf(stderr, Name ": Cannot understand version %d.%d\n",
283 array.major_version, array.minor_version);
284 return 1;
285 }
286 if (strcmp(file, "none") == 0) {
287 fprintf(stderr, Name ": no bitmap found on %s\n", devname);
288 return 1;
289 } else if (strcmp(file, "internal") == 0) {
290 int d;
291 for (d=0; d< st->max_devs; d++) {
292 mdu_disk_info_t disk;
293 char *dv;
294 disk.number = d;
295 if (ioctl(fd, GET_DISK_INFO, &disk) < 0)
296 continue;
297 if (disk.major == 0 &&
298 disk.minor == 0)
299 continue;
300 if ((disk.state & (1<<MD_DISK_SYNC))==0)
301 continue;
302 dv = map_dev(disk.major, disk.minor, 1);
303 if (dv) {
304 int fd2 = dev_open(dv, O_RDWR);
305 if (fd2 < 0)
306 continue;
307 if (st->ss->load_super(st, fd2, NULL)==0) {
308 if (st->ss->add_internal_bitmap(
309 st,
310 &chunk, delay, write_behind,
311 bitmapsize, 0, major)
312 )
313 st->ss->write_bitmap(st, fd2);
314 else {
315 fprintf(stderr, Name ": failed to create internal bitmap - chunksize problem.\n");
316 close(fd2);
317 return 1;
318 }
319 }
320 close(fd2);
321 }
322 }
323 array.state |= (1<<MD_SB_BITMAP_PRESENT);
324 if (ioctl(fd, SET_ARRAY_INFO, &array)!= 0) {
325 fprintf(stderr, Name ": failed to set internal bitmap.\n");
326 return 1;
327 }
328 } else {
329 int uuid[4];
330 int bitmap_fd;
331 int d;
332 int max_devs = st->max_devs;
333
334 /* try to load a superblock */
335 for (d=0; d<max_devs; d++) {
336 mdu_disk_info_t disk;
337 char *dv;
338 int fd2;
339 disk.number = d;
340 if (ioctl(fd, GET_DISK_INFO, &disk) < 0)
341 continue;
342 if ((disk.major==0 && disk.minor==0) ||
343 (disk.state & (1<<MD_DISK_REMOVED)))
344 continue;
345 dv = map_dev(disk.major, disk.minor, 1);
346 if (!dv) continue;
347 fd2 = dev_open(dv, O_RDONLY);
348 if (fd2 >= 0 &&
349 st->ss->load_super(st, fd2, NULL) == 0) {
350 close(fd2);
351 st->ss->uuid_from_super(st, uuid);
352 break;
353 }
354 close(fd2);
355 }
356 if (d == max_devs) {
357 fprintf(stderr, Name ": cannot find UUID for array!\n");
358 return 1;
359 }
360 if (CreateBitmap(file, force, (char*)uuid, chunk,
361 delay, write_behind, bitmapsize, major)) {
362 return 1;
363 }
364 bitmap_fd = open(file, O_RDWR);
365 if (bitmap_fd < 0) {
366 fprintf(stderr, Name ": weird: %s cannot be opened\n",
367 file);
368 return 1;
369 }
370 if (ioctl(fd, SET_BITMAP_FILE, bitmap_fd) < 0) {
371 fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n",
372 devname, strerror(errno));
373 return 1;
374 }
375 }
376
377 return 0;
378 }
379
380
381 /*
382 * When reshaping an array we might need to backup some data.
383 * This is written to all spares with a 'super_block' describing it.
384 * The superblock goes 1K form the end of the used space on the
385 * device.
386 * It if written after the backup is complete.
387 * It has the following structure.
388 */
389
390 static struct mdp_backup_super {
391 char magic[16]; /* md_backup_data-1 or -2 */
392 __u8 set_uuid[16];
393 __u64 mtime;
394 /* start/sizes in 512byte sectors */
395 __u64 devstart; /* address on backup device/file of data */
396 __u64 arraystart;
397 __u64 length;
398 __u32 sb_csum; /* csum of preceeding bytes. */
399 __u32 pad1;
400 __u64 devstart2; /* offset in to data of second section */
401 __u64 arraystart2;
402 __u64 length2;
403 __u32 sb_csum2; /* csum of preceeding bytes. */
404 __u8 pad[512-68-32];
405 } __attribute__((aligned(512))) bsb, bsb2;
406
407 int bsb_csum(char *buf, int len)
408 {
409 int i;
410 int csum = 0;
411 for (i=0; i<len; i++)
412 csum = (csum<<3) + buf[0];
413 return __cpu_to_le32(csum);
414 }
415
416 static int child_grow(int afd, struct mdinfo *sra, unsigned long blocks,
417 int *fds, unsigned long long *offsets,
418 int disks, int chunk, int level, int layout, int data,
419 int dests, int *destfd, unsigned long long *destoffsets);
420 static int child_shrink(int afd, struct mdinfo *sra, unsigned long blocks,
421 int *fds, unsigned long long *offsets,
422 int disks, int chunk, int level, int layout, int data,
423 int dests, int *destfd, unsigned long long *destoffsets);
424 static int child_same_size(int afd, struct mdinfo *sra, unsigned long blocks,
425 int *fds, unsigned long long *offsets,
426 unsigned long long start,
427 int disks, int chunk, int level, int layout, int data,
428 int dests, int *destfd, unsigned long long *destoffsets);
429
430 int freeze_array(struct mdinfo *sra)
431 {
432 /* Try to freeze resync on this array.
433 * Return -1 if the array is busy,
434 * return 0 if this kernel doesn't support 'frozen'
435 * return 1 if it worked.
436 */
437 char buf[20];
438 if (sysfs_get_str(sra, NULL, "sync_action", buf, 20) <= 0)
439 return 0;
440 if (strcmp(buf, "idle\n") != 0 &&
441 strcmp(buf, "frozen\n") != 0)
442 return -1;
443 if (sysfs_set_str(sra, NULL, "sync_action", "frozen") < 0)
444 return 0;
445 return 1;
446 }
447
448 void unfreeze_array(struct mdinfo *sra, int frozen)
449 {
450 /* If 'frozen' is 1, unfreeze the array */
451 if (frozen > 0)
452 sysfs_set_str(sra, NULL, "sync_action", "idle");
453 }
454
455 void wait_reshape(struct mdinfo *sra)
456 {
457 int fd = sysfs_get_fd(sra, NULL, "sync_action");
458 char action[20];
459
460 do {
461 fd_set rfds;
462 FD_ZERO(&rfds);
463 FD_SET(fd, &rfds);
464 select(fd+1, NULL, NULL, &rfds, NULL);
465
466 if (sysfs_fd_get_str(fd, action, 20) < 0) {
467 close(fd);
468 return;
469 }
470 } while (strncmp(action, "reshape", 7) == 0);
471 }
472
473
474 int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
475 long long size,
476 int level, char *layout_str, int chunksize, int raid_disks)
477 {
478 /* Make some changes in the shape of an array.
479 * The kernel must support the change.
480 *
481 * There are three different changes. Each can trigger
482 * a resync or recovery so we freeze that until we have
483 * requested everything (if kernel supports freezing - 2.6.30).
484 * The steps are:
485 * - change size (i.e. component_size)
486 * - change level
487 * - change layout/chunksize/ndisks
488 *
489 * The last can require a reshape. It is different on different
490 * levels so we need to check the level before actioning it.
491 * Some times the level change needs to be requested after the
492 * reshape (e.g. raid6->raid5, raid5->raid0)
493 *
494 */
495 struct mdu_array_info_s array, orig;
496 char *c;
497 int rv = 0;
498 struct supertype *st;
499
500 int nchunk, ochunk;
501 int nlayout, olayout;
502 int ndisks, odisks;
503 int ndata, odata;
504 int orig_level = UnSet;
505 char alt_layout[40];
506 int *fdlist;
507 unsigned long long *offsets;
508 int d, i;
509 int nrdisks;
510 int err;
511 int frozen;
512 unsigned long a,b, blocks, stripes;
513 int cache;
514 unsigned long long array_size;
515 int changed = 0;
516 int done;
517
518 struct mdinfo *sra;
519 struct mdinfo *sd;
520
521 if (ioctl(fd, GET_ARRAY_INFO, &array) < 0) {
522 fprintf(stderr, Name ": %s is not an active md array - aborting\n",
523 devname);
524 return 1;
525 }
526
527 if (raid_disks && raid_disks < array.raid_disks && array.level > 1 &&
528 get_linux_version() < 2006032 &&
529 !check_env("MDADM_FORCE_FEWER")) {
530 fprintf(stderr, Name ": reducing the number of devices is not safe before Linux 2.6.32\n"
531 " Please use a newer kernel\n");
532 return 1;
533 }
534 sra = sysfs_read(fd, 0, GET_LEVEL);
535 frozen = freeze_array(sra);
536 if (frozen < 0) {
537 fprintf(stderr, Name ": %s is performing resync/recovery and cannot"
538 " be reshaped\n", devname);
539 return 1;
540 }
541
542 /* ========= set size =============== */
543 if (size >= 0 && (size == 0 || size != array.size)) {
544 array.size = size;
545 if (array.size != size) {
546 /* got truncated to 32bit, write to
547 * component_size instead
548 */
549 if (sra)
550 rv = sysfs_set_num(sra, NULL,
551 "component_size", size);
552 else
553 rv = -1;
554 } else
555 rv = ioctl(fd, SET_ARRAY_INFO, &array);
556 if (rv != 0) {
557 fprintf(stderr, Name ": Cannot set device size for %s: %s\n",
558 devname, strerror(errno));
559 rv = 1;
560 goto release;
561 }
562 ioctl(fd, GET_ARRAY_INFO, &array);
563 if (!quiet)
564 fprintf(stderr, Name ": component size of %s has been set to %dK\n",
565 devname, array.size);
566 changed = 1;
567 }
568
569 /* ======= set level =========== */
570 if (level != UnSet && level != array.level) {
571 /* Trying to change the level.
572 * We might need to change layout first and schedule a
573 * level change for later.
574 * Level changes that can happen immediately are:
575 * 0->4,5,6 1->5 4->5,6 5->1,6
576 * Level changes that need a layout change first are:
577 * 6->5,4,0 : need a -6 layout, or parity-last
578 * 5->4,0 : need parity-last
579 */
580 if ((array.level == 6 || array.level == 5) &&
581 (level == 5 || level == 4 || level == 0)) {
582 /* Don't change level yet, but choose intermediate
583 * layout
584 */
585 if (level == 5) {
586 if (layout_str == NULL)
587 switch (array.layout) {
588 case ALGORITHM_LEFT_ASYMMETRIC:
589 case ALGORITHM_LEFT_ASYMMETRIC_6:
590 case ALGORITHM_ROTATING_N_RESTART:
591 layout_str = "left-asymmetric-6";
592 break;
593 case ALGORITHM_LEFT_SYMMETRIC:
594 case ALGORITHM_LEFT_SYMMETRIC_6:
595 case ALGORITHM_ROTATING_N_CONTINUE:
596 layout_str = "left-symmetric-6";
597 break;
598 case ALGORITHM_RIGHT_ASYMMETRIC:
599 case ALGORITHM_RIGHT_ASYMMETRIC_6:
600 case ALGORITHM_ROTATING_ZERO_RESTART:
601 layout_str = "right-asymmetric-6";
602 break;
603 case ALGORITHM_RIGHT_SYMMETRIC:
604 case ALGORITHM_RIGHT_SYMMETRIC_6:
605 layout_str = "right-symmetric-6";
606 break;
607 case ALGORITHM_PARITY_0:
608 case ALGORITHM_PARITY_0_6:
609 layout_str = "parity-first-6";
610 break;
611 case ALGORITHM_PARITY_N:
612 layout_str = "parity-last";
613 break;
614 default:
615 fprintf(stderr, Name ": %s: cannot"
616 "convert layout to RAID5 equivalent\n",
617 devname);
618 rv = 1;
619 goto release;
620 }
621 else {
622 int l = map_name(r5layout, layout_str);
623 if (l == UnSet) {
624 fprintf(stderr, Name ": %s: layout '%s' not recognised\n",
625 devname, layout_str);
626 rv = 1;
627 goto release;
628 }
629 if (l != ALGORITHM_PARITY_N) {
630 /* need the -6 version */
631 char *ls = map_num(r5layout, l);
632 strcat(strcpy(alt_layout, ls),
633 "-6");
634 layout_str = alt_layout;
635 }
636 }
637 if (raid_disks)
638 /* The final raid6->raid5 conversion
639 * will reduce the number of disks,
640 * so now we need to aim higher
641 */
642 raid_disks++;
643 } else
644 layout_str = "parity-last";
645 } else {
646 c = map_num(pers, level);
647 if (c == NULL) {
648 rv = 1;/* not possible */
649 goto release;
650 }
651 err = sysfs_set_str(sra, NULL, "level", c);
652 if (err) {
653 fprintf(stderr, Name ": %s: could not set level to %s\n",
654 devname, c);
655 rv = 1;
656 goto release;
657 }
658 orig = array;
659 orig_level = orig.level;
660 ioctl(fd, GET_ARRAY_INFO, &array);
661 if (layout_str == NULL &&
662 orig.level == 5 && level == 6 &&
663 array.layout != orig.layout)
664 layout_str = map_num(r5layout, orig.layout);
665 if (!quiet)
666 fprintf(stderr, Name " level of %s changed to %s\n",
667 devname, c);
668 changed = 1;
669 }
670 }
671
672 /* ========= set shape (chunk_size / layout / ndisks) ============== */
673 /* Check if layout change is a no-op */
674 if (layout_str) switch(array.level) {
675 case 5:
676 if (array.layout == map_name(r5layout, layout_str))
677 layout_str = NULL;
678 break;
679 case 6:
680 if (layout_str == NULL &&
681 ((chunksize && chunksize * 1024 != array.chunk_size) ||
682 (raid_disks && raid_disks != array.raid_disks)) &&
683 array.layout >= 16) {
684 fprintf(stderr, Name
685 ": %s has a non-standard layout. If you wish to preserve this\n"
686 " during the reshape, please specify --layout=preserve\n"
687 " If you want to change it, specify a layout or use --layout=normalise\n",
688 devname);
689 rv = 1;
690 goto release;
691 }
692 if (strcmp(layout_str, "normalise") == 0 ||
693 strcmp(layout_str, "normalize") == 0) {
694 char *hyphen;
695 strcpy(alt_layout, map_num(r6layout, array.layout));
696 hyphen = strrchr(alt_layout, '-');
697 if (hyphen && strcmp(hyphen, "-6") == 0) {
698 *hyphen = 0;
699 layout_str = alt_layout;
700 }
701 }
702
703 if (array.layout == map_name(r6layout, layout_str))
704 layout_str = NULL;
705 if (layout_str && strcmp(layout_str, "preserve") == 0)
706 layout_str = NULL;
707 break;
708 }
709 if (layout_str == NULL
710 && (chunksize == 0 || chunksize*1024 == array.chunk_size)
711 && (raid_disks == 0 || raid_disks == array.raid_disks)) {
712 rv = 0;
713 if (level != UnSet && level != array.level) {
714 /* Looks like this level change doesn't need
715 * a reshape after all.
716 */
717 c = map_num(pers, level);
718 if (c) {
719 rv = sysfs_set_str(sra, NULL, "level", c);
720 if (rv)
721 fprintf(stderr, Name ": %s: could not set level to %s\n",
722 devname, c);
723 }
724 } else if (!changed && !quiet)
725 fprintf(stderr, Name ": %s: no change requested\n",
726 devname);
727 goto release;
728 }
729
730 c = map_num(pers, array.level);
731 if (c == NULL) c = "-unknown-";
732 switch(array.level) {
733 default: /* raid0, linear, multipath cannot be reconfigured */
734 fprintf(stderr, Name ": %s array %s cannot be reshaped.\n",
735 c, devname);
736 rv = 1;
737 break;
738
739 case LEVEL_FAULTY: /* only 'layout' change is permitted */
740
741 if (chunksize || raid_disks) {
742 fprintf(stderr, Name ": %s: Cannot change chunksize or disks of a 'faulty' array\n",
743 devname);
744 rv = 1;
745 break;
746 }
747 if (layout_str == NULL)
748 break; /* nothing to do.... */
749
750 array.layout = parse_layout_faulty(layout_str);
751 if (array.layout < 0) {
752 int rv;
753 fprintf(stderr, Name ": %s: layout %s not understood for 'faulty' array\n",
754 devname, layout_str);
755 rv = 1;
756 break;
757 }
758 if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) {
759 fprintf(stderr, Name ": Cannot set layout for %s: %s\n",
760 devname, strerror(errno));
761 rv = 1;
762 } else if (!quiet)
763 printf("layout for %s set to %d\n", devname, array.layout);
764 break;
765
766 case 1: /* only raid_disks can each be changed. */
767
768 if (chunksize || layout_str != NULL) {
769 fprintf(stderr, Name ": %s: Cannot change chunk size or layout for a RAID1 array.\n",
770 devname);
771 rv = 1;
772 break;
773 }
774 if (raid_disks > 0) {
775 array.raid_disks = raid_disks;
776 if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) {
777 fprintf(stderr, Name ": Cannot set raid-devices for %s: %s\n",
778 devname, strerror(errno));
779 rv = 1;
780 }
781 }
782 break;
783
784 case 4:
785 case 5:
786 case 6:
787
788 /*
789 * layout/chunksize/raid_disks can be changed
790 * though the kernel may not support it all.
791 */
792 st = super_by_fd(fd);
793
794 /*
795 * There are three possibilities.
796 * 1/ The array will shrink.
797 * We need to ensure the reshape will pause before reaching
798 * the 'critical section'. We also need to fork and wait for
799 * that to happen. When it does we
800 * suspend/backup/complete/unfreeze
801 *
802 * 2/ The array will not change size.
803 * This requires that we keep a backup of a sliding window
804 * so that we can restore data after a crash. So we need
805 * to fork and monitor progress.
806 *
807 * 3/ The array will grow. This is relatively easy.
808 * However the kernel's restripe routines will cheerfully
809 * overwrite some early data before it is safe. So we
810 * need to make a backup of the early parts of the array
811 * and be ready to restore it if rebuild aborts very early.
812 *
813 * We backup data by writing it to one spare, or to a
814 * file which was given on command line.
815 *
816 * [FOLLOWING IS OLD AND PARTLY WRONG]
817 * So: we enumerate the devices in the array and
818 * make sure we can open all of them.
819 * Then we freeze the early part of the array and
820 * backup to the various spares.
821 * Then we request changes and start the reshape.
822 * Monitor progress until it has passed the danger zone.
823 * and finally invalidate the copied data and unfreeze the
824 * start of the array.
825 *
826 * In each case, we first make sure that storage is available
827 * for the required backup.
828 * Then we:
829 * - request the shape change.
830 * - for to handle backup etc.
831 */
832 nchunk = ochunk = array.chunk_size;
833 nlayout = olayout = array.layout;
834 ndisks = odisks = array.raid_disks;
835
836 if (chunksize) {
837 nchunk = chunksize * 1024;
838 if (array.size % chunksize) {
839 fprintf(stderr, Name ": component size %dK is not"
840 " a multiple of chunksize %dK\n",
841 array.size, chunksize);
842 break;
843 }
844 }
845 if (layout_str != NULL)
846 switch(array.level) {
847 case 4: /* ignore layout */
848 break;
849 case 5:
850 nlayout = map_name(r5layout, layout_str);
851 if (nlayout == UnSet) {
852 fprintf(stderr, Name ": layout %s not understood for raid5.\n",
853 layout_str);
854 rv = 1;
855 goto release;
856 }
857 break;
858
859 case 6:
860 nlayout = map_name(r6layout, layout_str);
861 if (nlayout == UnSet) {
862 fprintf(stderr, Name ": layout %s not understood for raid6.\n",
863 layout_str);
864 rv = 1;
865 goto release;
866 }
867 break;
868 }
869 if (raid_disks) ndisks = raid_disks;
870
871 odata = odisks-1;
872 ndata = ndisks-1;
873 if (array.level == 6) {
874 odata--; /* number of data disks */
875 ndata--;
876 }
877
878 if (odata == ndata &&
879 get_linux_version() < 2006032) {
880 fprintf(stderr, Name ": in-place reshape is not safe before 2.6.32, sorry.\n");
881 break;
882 }
883
884 /* Check that we can hold all the data */
885 size = ndata * array.size;
886 get_dev_size(fd, NULL, &array_size);
887 if (size < (array_size/1024)) {
888 fprintf(stderr, Name ": this change will reduce the size of the array.\n"
889 " use --grow --array-size first to truncate array.\n"
890 " e.g. mdadm --grow %s --array-size %llu\n",
891 devname, size);
892 rv = 1;
893 break;
894 }
895
896 /* So how much do we need to backup.
897 * We need an amount of data which is both a whole number of
898 * old stripes and a whole number of new stripes.
899 * So LCM for (chunksize*datadisks).
900 */
901 a = ochunk/512 * odata;
902 b = nchunk/512 * ndata;
903 /* Find GCD */
904 while (a != b) {
905 if (a < b)
906 b -= a;
907 if (b < a)
908 a -= b;
909 }
910 /* LCM == product / GCD */
911 blocks = ochunk/512 * nchunk/512 * odata * ndata / a;
912
913 sysfs_free(sra);
914 sra = sysfs_read(fd, 0,
915 GET_COMPONENT|GET_DEVS|GET_OFFSET|GET_STATE|
916 GET_CACHE);
917
918 if (ndata == odata) {
919 /* Make 'blocks' bigger for better throughput, but
920 * not so big that we reject it below.
921 * Try for 16 megabytes
922 */
923 while (blocks * 32 < sra->component_size &&
924 blocks < 16*1024*2)
925 blocks *= 2;
926 } else
927 fprintf(stderr, Name ": Need to backup %luK of critical "
928 "section..\n", blocks/2);
929
930 if (!sra) {
931 fprintf(stderr, Name ": %s: Cannot get array details from sysfs\n",
932 devname);
933 rv = 1;
934 break;
935 }
936
937 if (blocks >= sra->component_size/2) {
938 fprintf(stderr, Name ": %s: Something wrong - reshape aborted\n",
939 devname);
940 rv = 1;
941 break;
942 }
943 nrdisks = array.nr_disks + sra->array.spare_disks;
944 /* Now we need to open all these devices so we can read/write.
945 */
946 fdlist = malloc((1+nrdisks) * sizeof(int));
947 offsets = malloc((1+nrdisks) * sizeof(offsets[0]));
948 if (!fdlist || !offsets) {
949 fprintf(stderr, Name ": malloc failed: grow aborted\n");
950 rv = 1;
951 break;
952 }
953 for (d=0; d <= nrdisks; d++)
954 fdlist[d] = -1;
955 d = array.raid_disks;
956 for (sd = sra->devs; sd; sd=sd->next) {
957 if (sd->disk.state & (1<<MD_DISK_FAULTY))
958 continue;
959 if (sd->disk.state & (1<<MD_DISK_SYNC)) {
960 char *dn = map_dev(sd->disk.major,
961 sd->disk.minor, 1);
962 fdlist[sd->disk.raid_disk]
963 = dev_open(dn, O_RDONLY);
964 offsets[sd->disk.raid_disk] = sd->data_offset*512;
965 if (fdlist[sd->disk.raid_disk] < 0) {
966 fprintf(stderr, Name ": %s: cannot open component %s\n",
967 devname, dn?dn:"-unknown-");
968 rv = 1;
969 goto release;
970 }
971 } else if (backup_file == NULL) {
972 /* spare */
973 char *dn = map_dev(sd->disk.major,
974 sd->disk.minor, 1);
975 fdlist[d] = dev_open(dn, O_RDWR);
976 offsets[d] = (sra->component_size - blocks - 8)*512;
977 if (fdlist[d]<0) {
978 fprintf(stderr, Name ": %s: cannot open component %s\n",
979 devname, dn?dn:"-unknown");
980 rv = 1;
981 goto release;
982 }
983 d++;
984 }
985 }
986 if (backup_file == NULL) {
987 if (ndata <= odata) {
988 fprintf(stderr, Name ": %s: Cannot grow - need backup-file\n",
989 devname);
990 rv = 1;
991 break;
992 } else if (sra->array.spare_disks == 0) {
993 fprintf(stderr, Name ": %s: Cannot grow - need a spare or "
994 "backup-file to backup critical section\n",
995 devname);
996 rv = 1;
997 break;
998 }
999 if (d == array.raid_disks) {
1000 fprintf(stderr, Name ": %s: No spare device for backup\n",
1001 devname);
1002 rv = 1;
1003 break;
1004 }
1005 } else {
1006 /* need to check backup file is large enough */
1007 char buf[512];
1008 fdlist[d] = open(backup_file, O_RDWR|O_CREAT|O_EXCL,
1009 S_IRUSR | S_IWUSR);
1010 offsets[d] = 8 * 512;
1011 if (fdlist[d] < 0) {
1012 fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n",
1013 devname, backup_file, strerror(errno));
1014 rv = 1;
1015 break;
1016 }
1017 memset(buf, 0, 512);
1018 for (i=0; i < blocks + 1 ; i++) {
1019 if (write(fdlist[d], buf, 512) != 512) {
1020 fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n",
1021 devname, backup_file, strerror(errno));
1022 rv = 1;
1023 break;
1024 }
1025 }
1026 if (fsync(fdlist[d]) != 0) {
1027 fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n",
1028 devname, backup_file, strerror(errno));
1029 rv = 1;
1030 break;
1031 }
1032 d++;
1033 }
1034
1035 /* lastly, check that the internal stripe cache is
1036 * large enough, or it won't work.
1037 */
1038
1039 cache = (nchunk < ochunk) ? ochunk : nchunk;
1040 cache = cache * 4 / 4096;
1041 if (cache < blocks / 8 / odisks + 16)
1042 /* Make it big enough to hold 'blocks' */
1043 cache = blocks / 8 / odisks + 16;
1044 if (sra->cache_size < cache)
1045 sysfs_set_num(sra, NULL, "stripe_cache_size",
1046 cache+1);
1047 /* Right, everything seems fine. Let's kick things off.
1048 * If only changing raid_disks, use ioctl, else use
1049 * sysfs.
1050 */
1051 if (ochunk == nchunk && olayout == nlayout) {
1052 array.raid_disks = ndisks;
1053 if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) {
1054 rv = 1;
1055 fprintf(stderr, Name ": Cannot set device shape for %s: %s\n",
1056 devname, strerror(errno));
1057 if (ndisks < odisks &&
1058 get_linux_version() < 2006030)
1059 fprintf(stderr, Name ": linux 2.6.30 or later required\n");
1060
1061 break;
1062 }
1063 } else {
1064 /* set them all just in case some old 'new_*' value
1065 * persists from some earlier problem
1066 */
1067 if (sysfs_set_num(sra, NULL, "chunk_size", nchunk) < 0)
1068 rv = 1;
1069 if (sysfs_set_num(sra, NULL, "layout", nlayout) < 0)
1070 rv = 1;
1071 if (sysfs_set_num(sra, NULL, "raid_disks", ndisks) < 0)
1072 rv = 1;
1073 if (rv) {
1074 fprintf(stderr, Name ": Cannot set device shape for %s\n",
1075 devname);
1076 if (get_linux_version() < 2006030)
1077 fprintf(stderr, Name ": linux 2.6.30 or later required\n");
1078 break;
1079 }
1080 }
1081
1082 if (ndisks == 2 && odisks == 2) {
1083 /* No reshape is needed in this trivial case */
1084 rv = 0;
1085 break;
1086 }
1087
1088 /* set up the backup-super-block. This requires the
1089 * uuid from the array.
1090 */
1091 /* Find a superblock */
1092 for (sd = sra->devs; sd; sd = sd->next) {
1093 char *dn;
1094 int devfd;
1095 int ok;
1096 if (sd->disk.state & (1<<MD_DISK_FAULTY))
1097 continue;
1098 dn = map_dev(sd->disk.major, sd->disk.minor, 1);
1099 devfd = dev_open(dn, O_RDONLY);
1100 if (devfd < 0)
1101 continue;
1102 ok = st->ss->load_super(st, devfd, NULL);
1103 close(devfd);
1104 if (ok >= 0)
1105 break;
1106 }
1107 if (!sd) {
1108 fprintf(stderr, Name ": %s: Cannot find a superblock\n",
1109 devname);
1110 rv = 1;
1111 break;
1112 }
1113
1114 memset(&bsb, 0, 512);
1115 memcpy(bsb.magic, "md_backup_data-1", 16);
1116 st->ss->uuid_from_super(st, (int*)&bsb.set_uuid);
1117 bsb.mtime = __cpu_to_le64(time(0));
1118 bsb.devstart2 = blocks;
1119 stripes = blocks / (ochunk/512) / odata;
1120 /* Now we just need to kick off the reshape and watch, while
1121 * handling backups of the data...
1122 * This is all done by a forked background process.
1123 */
1124 switch(fork()) {
1125 case 0:
1126 close(fd);
1127 if (check_env("MDADM_GROW_VERIFY"))
1128 fd = open(devname, O_RDONLY | O_DIRECT);
1129 else
1130 fd = -1;
1131 mlockall(MCL_FUTURE);
1132
1133 if (odata < ndata)
1134 done = child_grow(fd, sra, stripes,
1135 fdlist, offsets,
1136 odisks, ochunk, array.level, olayout, odata,
1137 d - odisks, fdlist+odisks, offsets+odisks);
1138 else if (odata > ndata)
1139 done = child_shrink(fd, sra, stripes,
1140 fdlist, offsets,
1141 odisks, ochunk, array.level, olayout, odata,
1142 d - odisks, fdlist+odisks, offsets+odisks);
1143 else
1144 done = child_same_size(fd, sra, stripes,
1145 fdlist, offsets,
1146 0,
1147 odisks, ochunk, array.level, olayout, odata,
1148 d - odisks, fdlist+odisks, offsets+odisks);
1149 if (backup_file && done)
1150 unlink(backup_file);
1151 if (level != UnSet && level != array.level) {
1152 /* We need to wait for the reshape to finish
1153 * (which will have happened unless odata < ndata)
1154 * and then set the level
1155 */
1156
1157 c = map_num(pers, level);
1158 if (c == NULL)
1159 exit(0);/* not possible */
1160
1161 if (odata < ndata)
1162 wait_reshape(sra);
1163 err = sysfs_set_str(sra, NULL, "level", c);
1164 if (err)
1165 fprintf(stderr, Name ": %s: could not set level to %s\n",
1166 devname, c);
1167 }
1168 exit(0);
1169 case -1:
1170 fprintf(stderr, Name ": Cannot run child to monitor reshape: %s\n",
1171 strerror(errno));
1172 rv = 1;
1173 break;
1174 default:
1175 /* The child will take care of unfreezing the array */
1176 frozen = 0;
1177 break;
1178 }
1179 break;
1180
1181 }
1182
1183 release:
1184 if (rv && orig_level != UnSet && sra) {
1185 c = map_num(pers, orig_level);
1186 if (c && sysfs_set_str(sra, NULL, "level", c) == 0)
1187 fprintf(stderr, Name ": aborting level change\n");
1188 }
1189 if (sra)
1190 unfreeze_array(sra, frozen);
1191 return rv;
1192 }
1193
1194 /*
1195 * We run a child process in the background which performs the following
1196 * steps:
1197 * - wait for resync to reach a certain point
1198 * - suspend io to the following section
1199 * - backup that section
1200 * - allow resync to proceed further
1201 * - resume io
1202 * - discard the backup.
1203 *
1204 * When are combined in slightly different ways in the three cases.
1205 * Grow:
1206 * - suspend/backup/allow/wait/resume/discard
1207 * Shrink:
1208 * - allow/wait/suspend/backup/allow/wait/resume/discard
1209 * same-size:
1210 * - wait/resume/discard/suspend/backup/allow
1211 *
1212 * suspend/backup/allow always come together
1213 * wait/resume/discard do too.
1214 * For the same-size case we have two backups to improve flow.
1215 *
1216 */
1217
1218 int grow_backup(struct mdinfo *sra,
1219 unsigned long long offset, /* per device */
1220 unsigned long stripes, /* per device */
1221 int *sources, unsigned long long *offsets,
1222 int disks, int chunk, int level, int layout,
1223 int dests, int *destfd, unsigned long long *destoffsets,
1224 int part, int *degraded,
1225 char *buf)
1226 {
1227 /* Backup 'blocks' sectors at 'offset' on each device of the array,
1228 * to storage 'destfd' (offset 'destoffsets'), after first
1229 * suspending IO. Then allow resync to continue
1230 * over the suspended section.
1231 * Use part 'part' of the backup-super-block.
1232 */
1233 int odata = disks;
1234 int rv = 0;
1235 int i;
1236 unsigned long long new_degraded;
1237 //printf("offset %llu\n", offset);
1238 if (level >= 4)
1239 odata--;
1240 if (level == 6)
1241 odata--;
1242 sysfs_set_num(sra, NULL, "suspend_hi", (offset + stripes * chunk/512) * odata);
1243 /* Check that array hasn't become degraded, else we might backup the wrong data */
1244 sysfs_get_ll(sra, NULL, "degraded", &new_degraded);
1245 if (new_degraded != *degraded) {
1246 /* check each device to ensure it is still working */
1247 struct mdinfo *sd;
1248 for (sd = sra->devs ; sd ; sd = sd->next) {
1249 if (sd->disk.state & (1<<MD_DISK_FAULTY))
1250 continue;
1251 if (sd->disk.state & (1<<MD_DISK_SYNC)) {
1252 char sbuf[20];
1253 if (sysfs_get_str(sra, sd, "state", sbuf, 20) < 0 ||
1254 strstr(sbuf, "faulty") ||
1255 strstr(sbuf, "in_sync") == NULL) {
1256 /* this device is dead */
1257 sd->disk.state = (1<<MD_DISK_FAULTY);
1258 if (sd->disk.raid_disk >= 0 &&
1259 sources[sd->disk.raid_disk] >= 0) {
1260 close(sources[sd->disk.raid_disk]);
1261 sources[sd->disk.raid_disk] = -1;
1262 }
1263 }
1264 }
1265 }
1266 *degraded = new_degraded;
1267 }
1268 if (part) {
1269 bsb.arraystart2 = __cpu_to_le64(offset * odata);
1270 bsb.length2 = __cpu_to_le64(stripes * chunk/512 * odata);
1271 } else {
1272 bsb.arraystart = __cpu_to_le64(offset * odata);
1273 bsb.length = __cpu_to_le64(stripes * chunk/512 * odata);
1274 }
1275 if (part)
1276 bsb.magic[15] = '2';
1277 for (i = 0; i < dests; i++)
1278 if (part)
1279 lseek64(destfd[i], destoffsets[i] + __le64_to_cpu(bsb.devstart2)*512, 0);
1280 else
1281 lseek64(destfd[i], destoffsets[i], 0);
1282
1283 rv = save_stripes(sources, offsets,
1284 disks, chunk, level, layout,
1285 dests, destfd,
1286 offset*512*odata, stripes * chunk * odata,
1287 buf);
1288
1289 if (rv)
1290 return rv;
1291 bsb.mtime = __cpu_to_le64(time(0));
1292 for (i = 0; i < dests; i++) {
1293 bsb.devstart = __cpu_to_le64(destoffsets[i]/512);
1294
1295 bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb));
1296 if (memcmp(bsb.magic, "md_backup_data-2", 16) == 0)
1297 bsb.sb_csum2 = bsb_csum((char*)&bsb,
1298 ((char*)&bsb.sb_csum2)-((char*)&bsb));
1299
1300 lseek64(destfd[i], destoffsets[i] - 4096, 0);
1301 write(destfd[i], &bsb, 512);
1302 fsync(destfd[i]);
1303 }
1304
1305 return 0;
1306 }
1307
1308 /* in 2.6.30, the value reported by sync_completed can be
1309 * less that it should be by one stripe.
1310 * This only happens when reshape hits sync_max and pauses.
1311 * So allow wait_backup to either extent sync_max further
1312 * than strictly necessary, or return before the
1313 * sync has got quite as far as we would really like.
1314 * This is what 'blocks2' is for.
1315 * The various caller give appropriate values so that
1316 * every works.
1317 */
1318 int wait_backup(struct mdinfo *sra,
1319 unsigned long long offset, /* per device */
1320 unsigned long long blocks, /* per device */
1321 unsigned long long blocks2, /* per device - hack */
1322 int dests, int *destfd, unsigned long long *destoffsets,
1323 int part)
1324 {
1325 /* Wait for resync to pass the section that was backed up
1326 * then erase the backup and allow IO
1327 */
1328 int fd = sysfs_get_fd(sra, NULL, "sync_completed");
1329 unsigned long long completed;
1330 int i;
1331
1332 if (fd < 0)
1333 return -1;
1334 sysfs_set_num(sra, NULL, "sync_max", offset + blocks + blocks2);
1335 if (offset == 0)
1336 sysfs_set_str(sra, NULL, "sync_action", "reshape");
1337 do {
1338 char action[20];
1339 fd_set rfds;
1340 FD_ZERO(&rfds);
1341 FD_SET(fd, &rfds);
1342 select(fd+1, NULL, NULL, &rfds, NULL);
1343 if (sysfs_fd_get_ll(fd, &completed) < 0) {
1344 close(fd);
1345 return -1;
1346 }
1347 if (sysfs_get_str(sra, NULL, "sync_action",
1348 action, 20) > 0 &&
1349 strncmp(action, "reshape", 7) != 0)
1350 break;
1351 } while (completed < offset + blocks);
1352 close(fd);
1353
1354 if (part) {
1355 bsb.arraystart2 = __cpu_to_le64(0);
1356 bsb.length2 = __cpu_to_le64(0);
1357 } else {
1358 bsb.arraystart = __cpu_to_le64(0);
1359 bsb.length = __cpu_to_le64(0);
1360 }
1361 bsb.mtime = __cpu_to_le64(time(0));
1362 for (i = 0; i < dests; i++) {
1363 bsb.devstart = __cpu_to_le64(destoffsets[i]/512);
1364 bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb));
1365 if (memcmp(bsb.magic, "md_backup_data-2", 16) == 0)
1366 bsb.sb_csum2 = bsb_csum((char*)&bsb,
1367 ((char*)&bsb.sb_csum2)-((char*)&bsb));
1368 lseek64(destfd[i], destoffsets[i]-4096, 0);
1369 write(destfd[i], &bsb, 512);
1370 fsync(destfd[i]);
1371 }
1372 return 0;
1373 }
1374
1375 static void fail(char *msg)
1376 {
1377 write(2, msg, strlen(msg));
1378 write(2, "\n", 1);
1379 exit(1);
1380 }
1381
1382 static char *abuf, *bbuf;
1383 static int abuflen;
1384 static void validate(int afd, int bfd, unsigned long long offset)
1385 {
1386 /* check that the data in the backup against the array.
1387 * This is only used for regression testing and should not
1388 * be used while the array is active
1389 */
1390 if (afd < 0)
1391 return;
1392 lseek64(bfd, offset - 4096, 0);
1393 if (read(bfd, &bsb2, 512) != 512)
1394 fail("cannot read bsb");
1395 if (bsb2.sb_csum != bsb_csum((char*)&bsb2,
1396 ((char*)&bsb2.sb_csum)-((char*)&bsb2)))
1397 fail("first csum bad");
1398 if (memcmp(bsb2.magic, "md_backup_data", 14) != 0)
1399 fail("magic is bad");
1400 if (memcmp(bsb2.magic, "md_backup_data-2", 16) == 0 &&
1401 bsb2.sb_csum2 != bsb_csum((char*)&bsb2,
1402 ((char*)&bsb2.sb_csum2)-((char*)&bsb2)))
1403 fail("second csum bad");
1404
1405 if (__le64_to_cpu(bsb2.devstart)*512 != offset)
1406 fail("devstart is wrong");
1407
1408 if (bsb2.length) {
1409 unsigned long long len = __le64_to_cpu(bsb2.length)*512;
1410
1411 if (abuflen < len) {
1412 free(abuf);
1413 free(bbuf);
1414 abuflen = len;
1415 posix_memalign((void**)&abuf, 4096, abuflen);
1416 posix_memalign((void**)&bbuf, 4096, abuflen);
1417 }
1418
1419 lseek64(bfd, offset, 0);
1420 if (read(bfd, bbuf, len) != len) {
1421 printf("len %llu\n", len);
1422 fail("read first backup failed");
1423 }
1424 lseek64(afd, __le64_to_cpu(bsb2.arraystart)*512, 0);
1425 if (read(afd, abuf, len) != len)
1426 fail("read first from array failed");
1427 if (memcmp(bbuf, abuf, len) != 0) {
1428 int i;
1429 printf("offset=%llu len=%llu\n",
1430 __le64_to_cpu(bsb2.arraystart)*512, len);
1431 for (i=0; i<len; i++)
1432 if (bbuf[i] != abuf[i]) {
1433 printf("first diff byte %d\n", i);
1434 break;
1435 }
1436 fail("data1 compare failed");
1437 }
1438 }
1439 if (bsb2.length2) {
1440 unsigned long long len = __le64_to_cpu(bsb2.length2)*512;
1441
1442 if (abuflen < len) {
1443 free(abuf);
1444 free(bbuf);
1445 abuflen = len;
1446 abuf = malloc(abuflen);
1447 bbuf = malloc(abuflen);
1448 }
1449
1450 lseek64(bfd, offset+__le64_to_cpu(bsb2.devstart2)*512, 0);
1451 if (read(bfd, bbuf, len) != len)
1452 fail("read second backup failed");
1453 lseek64(afd, __le64_to_cpu(bsb2.arraystart2)*512, 0);
1454 if (read(afd, abuf, len) != len)
1455 fail("read second from array failed");
1456 if (memcmp(bbuf, abuf, len) != 0)
1457 fail("data2 compare failed");
1458 }
1459 }
1460
1461 static int child_grow(int afd, struct mdinfo *sra, unsigned long stripes,
1462 int *fds, unsigned long long *offsets,
1463 int disks, int chunk, int level, int layout, int data,
1464 int dests, int *destfd, unsigned long long *destoffsets)
1465 {
1466 char *buf;
1467 int degraded = 0;
1468
1469 posix_memalign((void**)&buf, 4096, disks * chunk);
1470 sysfs_set_num(sra, NULL, "suspend_hi", 0);
1471 sysfs_set_num(sra, NULL, "suspend_lo", 0);
1472 grow_backup(sra, 0, stripes,
1473 fds, offsets, disks, chunk, level, layout,
1474 dests, destfd, destoffsets,
1475 0, &degraded, buf);
1476 validate(afd, destfd[0], destoffsets[0]);
1477 wait_backup(sra, 0, stripes * chunk / 512, stripes * chunk / 512,
1478 dests, destfd, destoffsets,
1479 0);
1480 sysfs_set_num(sra, NULL, "suspend_lo", (stripes * chunk/512) * data);
1481 free(buf);
1482 /* FIXME this should probably be numeric */
1483 sysfs_set_str(sra, NULL, "sync_max", "max");
1484 return 1;
1485 }
1486
1487 static int child_shrink(int afd, struct mdinfo *sra, unsigned long stripes,
1488 int *fds, unsigned long long *offsets,
1489 int disks, int chunk, int level, int layout, int data,
1490 int dests, int *destfd, unsigned long long *destoffsets)
1491 {
1492 char *buf;
1493 unsigned long long start;
1494 int rv;
1495 int degraded = 0;
1496
1497 posix_memalign((void**)&buf, 4096, disks * chunk);
1498 start = sra->component_size - stripes * chunk/512;
1499 sysfs_set_num(sra, NULL, "sync_max", start);
1500 sysfs_set_str(sra, NULL, "sync_action", "reshape");
1501 sysfs_set_num(sra, NULL, "suspend_lo", 0);
1502 sysfs_set_num(sra, NULL, "suspend_hi", 0);
1503 rv = wait_backup(sra, 0, start - stripes * chunk/512, stripes * chunk/512,
1504 dests, destfd, destoffsets, 0);
1505 if (rv < 0)
1506 return 0;
1507 grow_backup(sra, 0, stripes,
1508 fds, offsets,
1509 disks, chunk, level, layout,
1510 dests, destfd, destoffsets,
1511 0, &degraded, buf);
1512 validate(afd, destfd[0], destoffsets[0]);
1513 wait_backup(sra, start, stripes*chunk/512, 0,
1514 dests, destfd, destoffsets, 0);
1515 sysfs_set_num(sra, NULL, "suspend_lo", (stripes * chunk/512) * data);
1516 free(buf);
1517 /* FIXME this should probably be numeric */
1518 sysfs_set_str(sra, NULL, "sync_max", "max");
1519 return 1;
1520 }
1521
1522 static int child_same_size(int afd, struct mdinfo *sra, unsigned long stripes,
1523 int *fds, unsigned long long *offsets,
1524 unsigned long long start,
1525 int disks, int chunk, int level, int layout, int data,
1526 int dests, int *destfd, unsigned long long *destoffsets)
1527 {
1528 unsigned long long size;
1529 unsigned long tailstripes = stripes;
1530 int part;
1531 char *buf;
1532 unsigned long long speed;
1533 int degraded = 0;
1534
1535
1536 posix_memalign((void**)&buf, 4096, disks * chunk);
1537
1538 sysfs_set_num(sra, NULL, "suspend_lo", 0);
1539 sysfs_set_num(sra, NULL, "suspend_hi", 0);
1540
1541 sysfs_get_ll(sra, NULL, "sync_speed_min", &speed);
1542 sysfs_set_num(sra, NULL, "sync_speed_min", 200000);
1543
1544 grow_backup(sra, start, stripes,
1545 fds, offsets,
1546 disks, chunk, level, layout,
1547 dests, destfd, destoffsets,
1548 0, &degraded, buf);
1549 grow_backup(sra, (start + stripes) * chunk/512, stripes,
1550 fds, offsets,
1551 disks, chunk, level, layout,
1552 dests, destfd, destoffsets,
1553 1, &degraded, buf);
1554 validate(afd, destfd[0], destoffsets[0]);
1555 part = 0;
1556 start += stripes * 2; /* where to read next */
1557 size = sra->component_size / (chunk/512);
1558 while (start < size) {
1559 if (wait_backup(sra, (start-stripes*2)*chunk/512,
1560 stripes*chunk/512, 0,
1561 dests, destfd, destoffsets,
1562 part) < 0)
1563 return 0;
1564 sysfs_set_num(sra, NULL, "suspend_lo", start*chunk/512 * data);
1565 if (start + stripes > size)
1566 tailstripes = (size - start);
1567
1568 grow_backup(sra, start*chunk/512, tailstripes,
1569 fds, offsets,
1570 disks, chunk, level, layout,
1571 dests, destfd, destoffsets,
1572 part, &degraded, buf);
1573 start += stripes;
1574 part = 1 - part;
1575 validate(afd, destfd[0], destoffsets[0]);
1576 }
1577 if (wait_backup(sra, (start-stripes*2) * chunk/512, stripes * chunk/512, 0,
1578 dests, destfd, destoffsets,
1579 part) < 0)
1580 return 0;
1581 sysfs_set_num(sra, NULL, "suspend_lo", ((start-stripes)*chunk/512) * data);
1582 wait_backup(sra, (start-stripes) * chunk/512, tailstripes * chunk/512, 0,
1583 dests, destfd, destoffsets,
1584 1-part);
1585 sysfs_set_num(sra, NULL, "suspend_lo", (size*chunk/512) * data);
1586 sysfs_set_num(sra, NULL, "sync_speed_min", speed);
1587 free(buf);
1588 return 1;
1589 }
1590
1591 /*
1592 * If any spare contains md_back_data-1 which is recent wrt mtime,
1593 * write that data into the array and update the super blocks with
1594 * the new reshape_progress
1595 */
1596 int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt,
1597 char *backup_file, int verbose)
1598 {
1599 int i, j;
1600 int old_disks;
1601 unsigned long long *offsets;
1602 unsigned long long nstripe, ostripe;
1603 int ndata, odata;
1604
1605 if (info->new_level != info->array.level)
1606 return 1; /* Cannot handle level changes (they are instantaneous) */
1607
1608 odata = info->array.raid_disks - info->delta_disks - 1;
1609 if (info->array.level == 6) odata--; /* number of data disks */
1610 ndata = info->array.raid_disks - 1;
1611 if (info->new_level == 6) ndata--;
1612
1613 old_disks = info->array.raid_disks - info->delta_disks;
1614
1615 if (info->delta_disks <= 0)
1616 /* Didn't grow, so the backup file must have
1617 * been used
1618 */
1619 old_disks = cnt;
1620 for (i=old_disks-(backup_file?1:0); i<cnt; i++) {
1621 struct mdinfo dinfo;
1622 char buf[4096];
1623 int fd;
1624 int bsbsize;
1625 char *devname, namebuf[20];
1626
1627 /* This was a spare and may have some saved data on it.
1628 * Load the superblock, find and load the
1629 * backup_super_block.
1630 * If either fail, go on to next device.
1631 * If the backup contains no new info, just return
1632 * else restore data and update all superblocks
1633 */
1634 if (i == old_disks-1) {
1635 fd = open(backup_file, O_RDONLY);
1636 if (fd<0) {
1637 fprintf(stderr, Name ": backup file %s inaccessible: %s\n",
1638 backup_file, strerror(errno));
1639 continue;
1640 }
1641 devname = backup_file;
1642 } else {
1643 fd = fdlist[i];
1644 if (fd < 0)
1645 continue;
1646 if (st->ss->load_super(st, fd, NULL))
1647 continue;
1648
1649 st->ss->getinfo_super(st, &dinfo);
1650 st->ss->free_super(st);
1651
1652 if (lseek64(fd,
1653 (dinfo.data_offset + dinfo.component_size - 8) <<9,
1654 0) < 0) {
1655 fprintf(stderr, Name ": Cannot seek on device %d\n", i);
1656 continue; /* Cannot seek */
1657 }
1658 sprintf(namebuf, "device-%d", i);
1659 devname = namebuf;
1660 }
1661 if (read(fd, &bsb, sizeof(bsb)) != sizeof(bsb)) {
1662 if (verbose)
1663 fprintf(stderr, Name ": Cannot read from %s\n", devname);
1664 continue; /* Cannot read */
1665 }
1666 if (memcmp(bsb.magic, "md_backup_data-1", 16) != 0 &&
1667 memcmp(bsb.magic, "md_backup_data-2", 16) != 0) {
1668 if (verbose)
1669 fprintf(stderr, Name ": No backup metadata on %s\n", devname);
1670 continue;
1671 }
1672 if (bsb.sb_csum != bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb))) {
1673 if (verbose)
1674 fprintf(stderr, Name ": Bad backup-metadata checksum on %s\n", devname);
1675 continue; /* bad checksum */
1676 }
1677 if (memcmp(bsb.magic, "md_backup_data-2", 16) == 0 &&
1678 bsb.sb_csum2 != bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum2)-((char*)&bsb))) {
1679 if (verbose)
1680 fprintf(stderr, Name ": Bad backup-metadata checksum2 on %s\n", devname);
1681 continue; /* Bad second checksum */
1682 }
1683 if (memcmp(bsb.set_uuid,info->uuid, 16) != 0) {
1684 if (verbose)
1685 fprintf(stderr, Name ": Wrong uuid on backup-metadata on %s\n", devname);
1686 continue; /* Wrong uuid */
1687 }
1688
1689 if (info->array.utime > __le64_to_cpu(bsb.mtime) + 10*60 ||
1690 info->array.utime < __le64_to_cpu(bsb.mtime) - 10*60) {
1691 if (verbose)
1692 fprintf(stderr, Name ": too-old timestamp on backup-metadata on %s\n", devname);
1693 continue; /* time stamp is too bad */
1694 }
1695
1696 if (bsb.magic[15] == '1') {
1697 if (info->delta_disks >= 0) {
1698 /* reshape_progress is increasing */
1699 if (__le64_to_cpu(bsb.arraystart) + __le64_to_cpu(bsb.length) <
1700 info->reshape_progress) {
1701 nonew:
1702 if (verbose)
1703 fprintf(stderr, Name ": backup-metadata found on %s but is not needed\n", devname);
1704 continue; /* No new data here */
1705 }
1706 } else {
1707 /* reshape_progress is decreasing */
1708 if (__le64_to_cpu(bsb.arraystart) >=
1709 info->reshape_progress)
1710 goto nonew; /* No new data here */
1711 }
1712 } else {
1713 if (info->delta_disks >= 0) {
1714 /* reshape_progress is increasing */
1715 if (__le64_to_cpu(bsb.arraystart) + __le64_to_cpu(bsb.length) <
1716 info->reshape_progress &&
1717 __le64_to_cpu(bsb.arraystart2) + __le64_to_cpu(bsb.length2) <
1718 info->reshape_progress)
1719 goto nonew; /* No new data here */
1720 } else {
1721 /* reshape_progress is decreasing */
1722 if (__le64_to_cpu(bsb.arraystart) >=
1723 info->reshape_progress &&
1724 __le64_to_cpu(bsb.arraystart2) >=
1725 info->reshape_progress)
1726 goto nonew; /* No new data here */
1727 }
1728 }
1729 if (lseek64(fd, __le64_to_cpu(bsb.devstart)*512, 0)< 0) {
1730 second_fail:
1731 if (verbose)
1732 fprintf(stderr, Name ": Failed to verify secondary backup-metadata block on %s\n",
1733 devname);
1734 continue; /* Cannot seek */
1735 }
1736 /* There should be a duplicate backup superblock 4k before here */
1737 if (lseek64(fd, -4096, 1) < 0 ||
1738 read(fd, buf, 4096) != 4096)
1739 goto second_fail; /* Cannot find leading superblock */
1740 if (bsb.magic[15] == '1')
1741 bsbsize = offsetof(struct mdp_backup_super, pad1);
1742 else
1743 bsbsize = offsetof(struct mdp_backup_super, pad);
1744 if (memcmp(buf, &bsb, bsbsize) != 0)
1745 goto second_fail; /* Cannot find leading superblock */
1746
1747 /* Now need the data offsets for all devices. */
1748 offsets = malloc(sizeof(*offsets)*info->array.raid_disks);
1749 for(j=0; j<info->array.raid_disks; j++) {
1750 if (fdlist[j] < 0)
1751 continue;
1752 if (st->ss->load_super(st, fdlist[j], NULL))
1753 /* FIXME should be this be an error */
1754 continue;
1755 st->ss->getinfo_super(st, &dinfo);
1756 st->ss->free_super(st);
1757 offsets[j] = dinfo.data_offset;
1758 }
1759 printf(Name ": restoring critical section\n");
1760
1761 if (restore_stripes(fdlist, offsets,
1762 info->array.raid_disks,
1763 info->new_chunk,
1764 info->new_level,
1765 info->new_layout,
1766 fd, __le64_to_cpu(bsb.devstart)*512,
1767 __le64_to_cpu(bsb.arraystart)*512,
1768 __le64_to_cpu(bsb.length)*512)) {
1769 /* didn't succeed, so giveup */
1770 if (verbose)
1771 fprintf(stderr, Name ": Error restoring backup from %s\n",
1772 devname);
1773 return 1;
1774 }
1775
1776 if (bsb.magic[15] == '2' &&
1777 restore_stripes(fdlist, offsets,
1778 info->array.raid_disks,
1779 info->new_chunk,
1780 info->new_level,
1781 info->new_layout,
1782 fd, __le64_to_cpu(bsb.devstart)*512 +
1783 __le64_to_cpu(bsb.devstart2)*512,
1784 __le64_to_cpu(bsb.arraystart2)*512,
1785 __le64_to_cpu(bsb.length2)*512)) {
1786 /* didn't succeed, so giveup */
1787 if (verbose)
1788 fprintf(stderr, Name ": Error restoring second backup from %s\n",
1789 devname);
1790 return 1;
1791 }
1792
1793
1794 /* Ok, so the data is restored. Let's update those superblocks. */
1795
1796 if (info->delta_disks >= 0) {
1797 info->reshape_progress = __le64_to_cpu(bsb.arraystart) +
1798 __le64_to_cpu(bsb.length);
1799 if (bsb.magic[15] == '2') {
1800 unsigned long long p2 = __le64_to_cpu(bsb.arraystart2) +
1801 __le64_to_cpu(bsb.length2);
1802 if (p2 > info->reshape_progress)
1803 info->reshape_progress = p2;
1804 }
1805 } else {
1806 info->reshape_progress = __le64_to_cpu(bsb.arraystart);
1807 if (bsb.magic[15] == '2') {
1808 unsigned long long p2 = __le64_to_cpu(bsb.arraystart2);
1809 if (p2 < info->reshape_progress)
1810 info->reshape_progress = p2;
1811 }
1812 }
1813 for (j=0; j<info->array.raid_disks; j++) {
1814 if (fdlist[j] < 0) continue;
1815 if (st->ss->load_super(st, fdlist[j], NULL))
1816 continue;
1817 st->ss->getinfo_super(st, &dinfo);
1818 dinfo.reshape_progress = info->reshape_progress;
1819 st->ss->update_super(st, &dinfo,
1820 "_reshape_progress",
1821 NULL,0, 0, NULL);
1822 st->ss->store_super(st, fdlist[j]);
1823 st->ss->free_super(st);
1824 }
1825 return 0;
1826 }
1827 /* Didn't find any backup data, try to see if any
1828 * was needed.
1829 */
1830 if (info->delta_disks < 0) {
1831 /* When shrinking, the critical section is at the end.
1832 * So see if we are before the critical section.
1833 */
1834 unsigned long long first_block;
1835 nstripe = ostripe = 0;
1836 first_block = 0;
1837 while (ostripe >= nstripe) {
1838 ostripe += info->array.chunk_size / 512;
1839 first_block = ostripe * odata;
1840 nstripe = first_block / ndata / (info->new_chunk/512) *
1841 (info->new_chunk/512);
1842 }
1843
1844 if (info->reshape_progress >= first_block)
1845 return 0;
1846 }
1847 if (info->delta_disks > 0) {
1848 /* See if we are beyond the critical section. */
1849 unsigned long long last_block;
1850 nstripe = ostripe = 0;
1851 last_block = 0;
1852 while (nstripe >= ostripe) {
1853 nstripe += info->new_chunk / 512;
1854 last_block = nstripe * ndata;
1855 ostripe = last_block / odata / (info->array.chunk_size/512) *
1856 (info->array.chunk_size/512);
1857 }
1858
1859 if (info->reshape_progress >= last_block)
1860 return 0;
1861 }
1862 /* needed to recover critical section! */
1863 if (verbose)
1864 fprintf(stderr, Name ": Failed to find backup of critical section\n");
1865 return 1;
1866 }
1867
1868 int Grow_continue(int mdfd, struct supertype *st, struct mdinfo *info,
1869 char *backup_file)
1870 {
1871 /* Array is assembled and ready to be started, but
1872 * monitoring is probably required.
1873 * So:
1874 * - start read-only
1875 * - set upper bound for resync
1876 * - initialise the 'suspend' boundaries
1877 * - switch to read-write
1878 * - fork and continue monitoring
1879 */
1880 int err;
1881 int backup_list[1];
1882 unsigned long long backup_offsets[1];
1883 int odisks, ndisks, ochunk, nchunk,odata,ndata;
1884 unsigned long a,b,blocks,stripes;
1885 int backup_fd;
1886 int *fds;
1887 unsigned long long *offsets;
1888 int d;
1889 struct mdinfo *sra, *sd;
1890 int rv;
1891 int cache;
1892 int done = 0;
1893
1894 err = sysfs_set_str(info, NULL, "array_state", "readonly");
1895 if (err)
1896 return err;
1897
1898 /* make sure reshape doesn't progress until we are ready */
1899 sysfs_set_str(info, NULL, "sync_max", "0");
1900 sysfs_set_str(info, NULL, "array_state", "active"); /* FIXME or clean */
1901
1902 /* ndisks is not growing, so raid_disks is old and +delta is new */
1903 odisks = info->array.raid_disks;
1904 ndisks = odisks + info->delta_disks;
1905 odata = odisks - 1;
1906 ndata = ndisks - 1;
1907 if (info->array.level == 6) {
1908 odata--;
1909 ndata--;
1910 }
1911 ochunk = info->array.chunk_size;
1912 nchunk = info->new_chunk;
1913
1914
1915 a = ochunk/512 * odata;
1916 b = nchunk/512 * ndata;
1917 /* Find GCD */
1918 while (a != b) {
1919 if (a < b)
1920 b -= a;
1921 if (b < a)
1922 a -= b;
1923 }
1924 /* LCM == product / GCD */
1925 blocks = ochunk/512 * nchunk/512 * odata * ndata / a;
1926
1927 sra = sysfs_read(-1, devname2devnum(info->sys_name),
1928 GET_COMPONENT|GET_DEVS|GET_OFFSET|GET_STATE|
1929 GET_CACHE);
1930
1931
1932 if (ndata == odata)
1933 while (blocks * 32 < sra->component_size &&
1934 blocks < 16*1024*2)
1935 blocks *= 2;
1936 stripes = blocks / (info->array.chunk_size/512) / odata;
1937
1938 /* check that the internal stripe cache is
1939 * large enough, or it won't work.
1940 */
1941 cache = (nchunk < ochunk) ? ochunk : nchunk;
1942 cache = cache * 4 / 4096;
1943 if (cache < blocks / 8 / odisks + 16)
1944 /* Make it big enough to hold 'blocks' */
1945 cache = blocks / 8 / odisks + 16;
1946 if (sra->cache_size < cache)
1947 sysfs_set_num(sra, NULL, "stripe_cache_size",
1948 cache+1);
1949
1950 memset(&bsb, 0, 512);
1951 memcpy(bsb.magic, "md_backup_data-1", 16);
1952 memcpy(&bsb.set_uuid, info->uuid, 16);
1953 bsb.mtime = __cpu_to_le64(time(0));
1954 bsb.devstart2 = blocks;
1955
1956 backup_fd = open(backup_file, O_RDWR|O_CREAT, S_IRUSR | S_IWUSR);
1957 backup_list[0] = backup_fd;
1958 backup_offsets[0] = 8 * 512;
1959 fds = malloc(odisks * sizeof(fds[0]));
1960 offsets = malloc(odisks * sizeof(offsets[0]));
1961 for (d=0; d<odisks; d++)
1962 fds[d] = -1;
1963
1964 for (sd = sra->devs; sd; sd = sd->next) {
1965 if (sd->disk.state & (1<<MD_DISK_FAULTY))
1966 continue;
1967 if (sd->disk.state & (1<<MD_DISK_SYNC)) {
1968 char *dn = map_dev(sd->disk.major,
1969 sd->disk.minor, 1);
1970 fds[sd->disk.raid_disk]
1971 = dev_open(dn, O_RDONLY);
1972 offsets[sd->disk.raid_disk] = sd->data_offset*512;
1973 if (fds[sd->disk.raid_disk] < 0) {
1974 fprintf(stderr, Name ": %s: cannot open component %s\n",
1975 info->sys_name, dn?dn:"-unknown-");
1976 rv = 1;
1977 goto release;
1978 }
1979 free(dn);
1980 }
1981 }
1982
1983 switch(fork()) {
1984 case 0:
1985 close(mdfd);
1986 mlockall(MCL_FUTURE);
1987 if (info->delta_disks < 0)
1988 done = child_shrink(-1, info, stripes,
1989 fds, offsets,
1990 info->array.raid_disks,
1991 info->array.chunk_size,
1992 info->array.level, info->array.layout,
1993 odata,
1994 1, backup_list, backup_offsets);
1995 else if (info->delta_disks == 0) {
1996 /* The 'start' is a per-device stripe number.
1997 * reshape_progress is a per-array sector number.
1998 * So divide by ndata * chunk_size
1999 */
2000 unsigned long long start = info->reshape_progress / ndata;
2001 start /= (info->array.chunk_size/512);
2002 done = child_same_size(-1, info, stripes,
2003 fds, offsets,
2004 start,
2005 info->array.raid_disks,
2006 info->array.chunk_size,
2007 info->array.level, info->array.layout,
2008 odata,
2009 1, backup_list, backup_offsets);
2010 }
2011 if (backup_file && done)
2012 unlink(backup_file);
2013 /* FIXME should I intuit a level change */
2014 exit(0);
2015 case -1:
2016 fprintf(stderr, Name ": Cannot run child to continue monitoring reshape: %s\n",
2017 strerror(errno));
2018 return 1;
2019 default:
2020 break;
2021 }
2022 release:
2023 return 0;
2024 }
2025
2026