2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
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.
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.
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
22 * Email: <neilb@suse.de>
28 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
29 #error no endian defined
35 #define offsetof(t,f) ((size_t)&(((t*)0)->f))
38 int restore_backup(struct supertype
*st
,
39 struct mdinfo
*content
,
49 int disk_count
= next_spare
+ working_disks
;
51 dprintf("Called restore_backup()\n");
52 fdlist
= malloc(sizeof(int) * disk_count
);
55 Name
": cannot allocate memory for disk list\n");
58 for (i
= 0; i
< next_spare
; i
++)
60 for (dev
= content
->devs
; dev
; dev
= dev
->next
) {
66 fd
= dev_open(buf
, O_RDWR
);
68 if (dev
->disk
.raid_disk
>= 0)
69 fdlist
[dev
->disk
.raid_disk
] = fd
;
71 fdlist
[next_spare
++] = fd
;
74 if (st
->ss
->external
&& st
->ss
->recover_backup
)
75 err
= st
->ss
->recover_backup(st
, content
);
77 err
= Grow_restart(st
, content
, fdlist
, next_spare
,
78 backup_file
, verbose
> 0);
80 while (next_spare
> 0) {
82 if (fdlist
[next_spare
] >= 0)
83 close(fdlist
[next_spare
]);
87 fprintf(stderr
, Name
": Failed to restore critical"
88 " section for reshape - sorry.\n");
90 fprintf(stderr
, Name
": Possibly you need"
91 " to specify a --backup-file\n");
95 dprintf("restore_backup() returns status OK.\n");
99 int Grow_Add_device(char *devname
, int fd
, char *newdev
)
101 /* Add a device to an active array.
102 * Currently, just extend a linear array.
103 * This requires writing a new superblock on the
104 * new device, calling the kernel to add the device,
105 * and if that succeeds, update the superblock on
107 * This means that we need to *find* all other devices.
114 struct supertype
*st
= NULL
;
115 char *subarray
= NULL
;
117 if (ioctl(fd
, GET_ARRAY_INFO
, &info
.array
) < 0) {
118 fprintf(stderr
, Name
": cannot get array info for %s\n", devname
);
122 if (info
.array
.level
!= -1) {
123 fprintf(stderr
, Name
": can only add devices to linear arrays\n");
127 st
= super_by_fd(fd
, &subarray
);
129 fprintf(stderr
, Name
": cannot handle arrays with superblock version %d\n", info
.array
.major_version
);
134 fprintf(stderr
, Name
": Cannot grow linear sub-arrays yet\n");
140 nfd
= open(newdev
, O_RDWR
|O_EXCL
|O_DIRECT
);
142 fprintf(stderr
, Name
": cannot open %s\n", newdev
);
147 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
148 fprintf(stderr
, Name
": %s is not a block device!\n", newdev
);
153 /* now check out all the devices and make sure we can read the superblock */
154 for (d
=0 ; d
< info
.array
.raid_disks
; d
++) {
155 mdu_disk_info_t disk
;
158 st
->ss
->free_super(st
);
161 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
162 fprintf(stderr
, Name
": cannot get device detail for device %d\n",
168 dv
= map_dev(disk
.major
, disk
.minor
, 1);
170 fprintf(stderr
, Name
": cannot find device file for device %d\n",
176 fd2
= dev_open(dv
, O_RDWR
);
178 fprintf(stderr
, Name
": cannot open device file %s\n", dv
);
184 if (st
->ss
->load_super(st
, fd2
, NULL
)) {
185 fprintf(stderr
, Name
": cannot find super block on %s\n", dv
);
193 /* Ok, looks good. Lets update the superblock and write it out to
197 info
.disk
.number
= d
;
198 info
.disk
.major
= major(stb
.st_rdev
);
199 info
.disk
.minor
= minor(stb
.st_rdev
);
200 info
.disk
.raid_disk
= d
;
201 info
.disk
.state
= (1 << MD_DISK_SYNC
) | (1 << MD_DISK_ACTIVE
);
202 st
->ss
->update_super(st
, &info
, "linear-grow-new", newdev
,
205 if (st
->ss
->store_super(st
, nfd
)) {
206 fprintf(stderr
, Name
": Cannot store new superblock on %s\n",
213 if (ioctl(fd
, ADD_NEW_DISK
, &info
.disk
) != 0) {
214 fprintf(stderr
, Name
": Cannot add new disk to this array\n");
217 /* Well, that seems to have worked.
218 * Now go through and update all superblocks
221 if (ioctl(fd
, GET_ARRAY_INFO
, &info
.array
) < 0) {
222 fprintf(stderr
, Name
": cannot get array info for %s\n", devname
);
227 for (d
=0 ; d
< info
.array
.raid_disks
; d
++) {
228 mdu_disk_info_t disk
;
232 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
233 fprintf(stderr
, Name
": cannot get device detail for device %d\n",
237 dv
= map_dev(disk
.major
, disk
.minor
, 1);
239 fprintf(stderr
, Name
": cannot find device file for device %d\n",
243 fd2
= dev_open(dv
, O_RDWR
);
245 fprintf(stderr
, Name
": cannot open device file %s\n", dv
);
248 if (st
->ss
->load_super(st
, fd2
, NULL
)) {
249 fprintf(stderr
, Name
": cannot find super block on %s\n", dv
);
253 info
.array
.raid_disks
= nd
+1;
254 info
.array
.nr_disks
= nd
+1;
255 info
.array
.active_disks
= nd
+1;
256 info
.array
.working_disks
= nd
+1;
258 st
->ss
->update_super(st
, &info
, "linear-grow-update", dv
,
261 if (st
->ss
->store_super(st
, fd2
)) {
262 fprintf(stderr
, Name
": Cannot store new superblock on %s\n", dv
);
272 int Grow_addbitmap(char *devname
, int fd
, char *file
, int chunk
, int delay
, int write_behind
, int force
)
275 * First check that array doesn't have a bitmap
276 * Then create the bitmap
279 * For internal bitmaps, we need to check the version,
280 * find all the active devices, and write the bitmap block
283 mdu_bitmap_file_t bmf
;
284 mdu_array_info_t array
;
285 struct supertype
*st
;
286 char *subarray
= NULL
;
287 int major
= BITMAP_MAJOR_HI
;
288 int vers
= md_get_version(fd
);
289 unsigned long long bitmapsize
, array_size
;
292 major
= BITMAP_MAJOR_HOSTENDIAN
;
293 fprintf(stderr
, Name
": Warning - bitmaps created on this kernel"
294 " are not portable\n"
295 " between different architectures. Consider upgrading"
296 " the Linux kernel.\n");
299 if (ioctl(fd
, GET_BITMAP_FILE
, &bmf
) != 0) {
301 fprintf(stderr
, Name
": Memory allocation failure.\n");
303 fprintf(stderr
, Name
": bitmaps not supported by this kernel.\n");
306 if (bmf
.pathname
[0]) {
307 if (strcmp(file
,"none")==0) {
308 if (ioctl(fd
, SET_BITMAP_FILE
, -1)!= 0) {
309 fprintf(stderr
, Name
": failed to remove bitmap %s\n",
315 fprintf(stderr
, Name
": %s already has a bitmap (%s)\n",
316 devname
, bmf
.pathname
);
319 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
320 fprintf(stderr
, Name
": cannot get array status for %s\n", devname
);
323 if (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)) {
324 if (strcmp(file
, "none")==0) {
325 array
.state
&= ~(1<<MD_SB_BITMAP_PRESENT
);
326 if (ioctl(fd
, SET_ARRAY_INFO
, &array
)!= 0) {
327 fprintf(stderr
, Name
": failed to remove internal bitmap.\n");
332 fprintf(stderr
, Name
": Internal bitmap already present on %s\n",
337 if (strcmp(file
, "none") == 0) {
338 fprintf(stderr
, Name
": no bitmap found on %s\n", devname
);
341 if (array
.level
<= 0) {
342 fprintf(stderr
, Name
": Bitmaps not meaningful with level %s\n",
343 map_num(pers
, array
.level
)?:"of this array");
346 bitmapsize
= array
.size
;
348 if (get_dev_size(fd
, NULL
, &array_size
) &&
349 array_size
> (0x7fffffffULL
<<9)) {
350 /* Array is big enough that we cannot trust array.size
351 * try other approaches
353 bitmapsize
= get_component_size(fd
);
355 if (bitmapsize
== 0) {
356 fprintf(stderr
, Name
": Cannot reliably determine size of array to create bitmap - sorry.\n");
360 if (array
.level
== 10) {
361 int ncopies
= (array
.layout
&255)*((array
.layout
>>8)&255);
362 bitmapsize
= bitmapsize
* array
.raid_disks
/ ncopies
;
365 st
= super_by_fd(fd
, &subarray
);
367 fprintf(stderr
, Name
": Cannot understand version %d.%d\n",
368 array
.major_version
, array
.minor_version
);
372 fprintf(stderr
, Name
": Cannot add bitmaps to sub-arrays yet\n");
377 if (strcmp(file
, "internal") == 0) {
380 int offset_setable
= 0;
382 if (st
->ss
->add_internal_bitmap
== NULL
) {
383 fprintf(stderr
, Name
": Internal bitmaps not supported "
384 "with %s metadata\n", st
->ss
->name
);
387 mdi
= sysfs_read(fd
, -1, GET_BITMAP_LOCATION
);
390 for (d
=0; d
< st
->max_devs
; d
++) {
391 mdu_disk_info_t disk
;
394 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
396 if (disk
.major
== 0 &&
399 if ((disk
.state
& (1<<MD_DISK_SYNC
))==0)
401 dv
= map_dev(disk
.major
, disk
.minor
, 1);
403 int fd2
= dev_open(dv
, O_RDWR
);
406 if (st
->ss
->load_super(st
, fd2
, NULL
)==0) {
407 if (st
->ss
->add_internal_bitmap(
409 &chunk
, delay
, write_behind
,
410 bitmapsize
, offset_setable
,
413 st
->ss
->write_bitmap(st
, fd2
);
415 fprintf(stderr
, Name
": failed "
416 "to create internal bitmap - chunksize problem.\n");
424 if (offset_setable
) {
425 st
->ss
->getinfo_super(st
, mdi
, NULL
);
426 sysfs_init(mdi
, fd
, -1);
427 rv
= sysfs_set_num_signed(mdi
, NULL
, "bitmap/location",
430 array
.state
|= (1<<MD_SB_BITMAP_PRESENT
);
431 rv
= ioctl(fd
, SET_ARRAY_INFO
, &array
);
436 ": Cannot add bitmap while array is"
437 " resyncing or reshaping etc.\n");
438 fprintf(stderr
, Name
": failed to set internal bitmap.\n");
445 int max_devs
= st
->max_devs
;
447 /* try to load a superblock */
448 for (d
=0; d
<max_devs
; d
++) {
449 mdu_disk_info_t disk
;
453 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
455 if ((disk
.major
==0 && disk
.minor
==0) ||
456 (disk
.state
& (1<<MD_DISK_REMOVED
)))
458 dv
= map_dev(disk
.major
, disk
.minor
, 1);
460 fd2
= dev_open(dv
, O_RDONLY
);
462 if (st
->ss
->load_super(st
, fd2
, NULL
) == 0) {
464 st
->ss
->uuid_from_super(st
, uuid
);
471 fprintf(stderr
, Name
": cannot find UUID for array!\n");
474 if (CreateBitmap(file
, force
, (char*)uuid
, chunk
,
475 delay
, write_behind
, bitmapsize
, major
)) {
478 bitmap_fd
= open(file
, O_RDWR
);
480 fprintf(stderr
, Name
": weird: %s cannot be opened\n",
484 if (ioctl(fd
, SET_BITMAP_FILE
, bitmap_fd
) < 0) {
488 ": Cannot add bitmap while array is"
489 " resyncing or reshaping etc.\n");
490 fprintf(stderr
, Name
": Cannot set bitmap file for %s: %s\n",
491 devname
, strerror(err
));
500 * When reshaping an array we might need to backup some data.
501 * This is written to all spares with a 'super_block' describing it.
502 * The superblock goes 4K from the end of the used space on the
504 * It if written after the backup is complete.
505 * It has the following structure.
508 static struct mdp_backup_super
{
509 char magic
[16]; /* md_backup_data-1 or -2 */
512 /* start/sizes in 512byte sectors */
513 __u64 devstart
; /* address on backup device/file of data */
516 __u32 sb_csum
; /* csum of preceeding bytes. */
518 __u64 devstart2
; /* offset in to data of second section */
521 __u32 sb_csum2
; /* csum of preceeding bytes. */
523 } __attribute__((aligned(512))) bsb
, bsb2
;
525 static __u32
bsb_csum(char *buf
, int len
)
529 for (i
=0; i
<len
; i
++)
530 csum
= (csum
<<3) + buf
[0];
531 return __cpu_to_le32(csum
);
534 static int check_idle(struct supertype
*st
)
536 /* Check that all member arrays for this container, or the
537 * container of this array, are idle
539 int container_dev
= (st
->container_dev
!= NoMdDev
540 ? st
->container_dev
: st
->devnum
);
542 struct mdstat_ent
*ent
, *e
;
545 fmt_devname(container
, container_dev
);
546 ent
= mdstat_read(0, 0);
547 for (e
= ent
; e
; e
= e
->next
) {
548 if (!is_container_member(e
, container
))
550 if (e
->percent
>= 0) {
559 static int freeze_container(struct supertype
*st
)
561 int container_dev
= (st
->container_dev
!= NoMdDev
562 ? st
->container_dev
: st
->devnum
);
568 fmt_devname(container
, container_dev
);
570 if (block_monitor(container
, 1)) {
571 fprintf(stderr
, Name
": failed to freeze container\n");
578 static void unfreeze_container(struct supertype
*st
)
580 int container_dev
= (st
->container_dev
!= NoMdDev
581 ? st
->container_dev
: st
->devnum
);
584 fmt_devname(container
, container_dev
);
586 unblock_monitor(container
, 1);
589 static int freeze(struct supertype
*st
)
591 /* Try to freeze resync/rebuild on this array/container.
592 * Return -1 if the array is busy,
593 * return -2 container cannot be frozen,
594 * return 0 if this kernel doesn't support 'frozen'
595 * return 1 if it worked.
597 if (st
->ss
->external
)
598 return freeze_container(st
);
600 struct mdinfo
*sra
= sysfs_read(-1, st
->devnum
, GET_VERSION
);
606 /* Need to clear any 'read-auto' status */
607 if (sysfs_get_str(sra
, NULL
, "array_state", buf
, 20) > 0 &&
608 strncmp(buf
, "read-auto", 9) == 0)
609 sysfs_set_str(sra
, NULL
, "array_state", "clean");
611 err
= sysfs_freeze_array(sra
);
617 static void unfreeze(struct supertype
*st
)
619 if (st
->ss
->external
)
620 return unfreeze_container(st
);
622 struct mdinfo
*sra
= sysfs_read(-1, st
->devnum
, GET_VERSION
);
625 sysfs_set_str(sra
, NULL
, "sync_action", "idle");
627 fprintf(stderr
, Name
": failed to unfreeze array\n");
632 static void wait_reshape(struct mdinfo
*sra
)
634 int fd
= sysfs_get_fd(sra
, NULL
, "sync_action");
640 while (sysfs_fd_get_str(fd
, action
, 20) > 0 &&
641 strncmp(action
, "reshape", 7) == 0) {
645 select(fd
+1, NULL
, NULL
, &rfds
, NULL
);
650 static int reshape_super(struct supertype
*st
, long long size
, int level
,
651 int layout
, int chunksize
, int raid_disks
,
652 int delta_disks
, char *backup_file
, char *dev
,
653 int direction
, int verbose
)
655 /* nothing extra to check in the native case */
656 if (!st
->ss
->external
)
658 if (!st
->ss
->reshape_super
||
659 !st
->ss
->manage_reshape
) {
660 fprintf(stderr
, Name
": %s metadata does not support reshape\n",
665 return st
->ss
->reshape_super(st
, size
, level
, layout
, chunksize
,
666 raid_disks
, delta_disks
, backup_file
, dev
,
670 static void sync_metadata(struct supertype
*st
)
672 if (st
->ss
->external
) {
673 if (st
->update_tail
) {
674 flush_metadata_updates(st
);
675 st
->update_tail
= &st
->updates
;
677 st
->ss
->sync_metadata(st
);
681 static int subarray_set_num(char *container
, struct mdinfo
*sra
, char *name
, int n
)
683 /* when dealing with external metadata subarrays we need to be
684 * prepared to handle EAGAIN. The kernel may need to wait for
685 * mdmon to mark the array active so the kernel can handle
686 * allocations/writeback when preparing the reshape action
687 * (md_allow_write()). We temporarily disable safe_mode_delay
688 * to close a race with the array_state going clean before the
689 * next write to raid_disks / stripe_cache_size
694 /* only 'raid_disks' and 'stripe_cache_size' trigger md_allow_write */
696 (strcmp(name
, "raid_disks") != 0 &&
697 strcmp(name
, "stripe_cache_size") != 0))
698 return sysfs_set_num(sra
, NULL
, name
, n
);
700 rc
= sysfs_get_str(sra
, NULL
, "safe_mode_delay", safe
, sizeof(safe
));
703 sysfs_set_num(sra
, NULL
, "safe_mode_delay", 0);
704 rc
= sysfs_set_num(sra
, NULL
, name
, n
);
705 if (rc
< 0 && errno
== EAGAIN
) {
706 ping_monitor(container
);
707 /* if we get EAGAIN here then the monitor is not active
710 rc
= sysfs_set_num(sra
, NULL
, name
, n
);
712 sysfs_set_str(sra
, NULL
, "safe_mode_delay", safe
);
716 int start_reshape(struct mdinfo
*sra
, int already_running
,
717 int before_data_disks
, int data_disks
)
720 unsigned long long sync_max_to_set
;
722 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
723 err
= sysfs_set_num(sra
, NULL
, "suspend_hi", sra
->reshape_progress
);
724 err
= err
?: sysfs_set_num(sra
, NULL
, "suspend_lo",
725 sra
->reshape_progress
);
726 if (before_data_disks
<= data_disks
)
727 sync_max_to_set
= sra
->reshape_progress
/ data_disks
;
729 sync_max_to_set
= (sra
->component_size
* data_disks
730 - sra
->reshape_progress
) / data_disks
;
731 if (!already_running
)
732 sysfs_set_num(sra
, NULL
, "sync_min", sync_max_to_set
);
733 err
= err
?: sysfs_set_num(sra
, NULL
, "sync_max", sync_max_to_set
);
734 if (!already_running
)
735 err
= err
?: sysfs_set_str(sra
, NULL
, "sync_action", "reshape");
740 void abort_reshape(struct mdinfo
*sra
)
742 sysfs_set_str(sra
, NULL
, "sync_action", "idle");
743 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
744 sysfs_set_num(sra
, NULL
, "suspend_hi", 0);
745 sysfs_set_num(sra
, NULL
, "suspend_lo", 0);
746 sysfs_set_num(sra
, NULL
, "sync_min", 0);
747 sysfs_set_str(sra
, NULL
, "sync_max", "max");
750 int remove_disks_for_takeover(struct supertype
*st
,
755 struct mdinfo
*remaining
;
758 if (sra
->array
.level
== 10)
759 nr_of_copies
= layout
& 0xff;
760 else if (sra
->array
.level
== 1)
761 nr_of_copies
= sra
->array
.raid_disks
;
765 remaining
= sra
->devs
;
767 /* for each 'copy', select one device and remove from the list. */
768 for (slot
= 0; slot
< sra
->array
.raid_disks
; slot
+= nr_of_copies
) {
769 struct mdinfo
**diskp
;
772 /* Find a working device to keep */
773 for (diskp
= &remaining
; *diskp
; diskp
= &(*diskp
)->next
) {
774 struct mdinfo
*disk
= *diskp
;
776 if (disk
->disk
.raid_disk
< slot
)
778 if (disk
->disk
.raid_disk
>= slot
+ nr_of_copies
)
780 if (disk
->disk
.state
& (1<<MD_DISK_REMOVED
))
782 if (disk
->disk
.state
& (1<<MD_DISK_FAULTY
))
784 if (!(disk
->disk
.state
& (1<<MD_DISK_SYNC
)))
787 /* We have found a good disk to use! */
789 disk
->next
= sra
->devs
;
798 if (slot
< sra
->array
.raid_disks
) {
799 /* didn't find all slots */
805 sra
->devs
= remaining
;
809 /* Remove all 'remaining' devices from the array */
811 struct mdinfo
*sd
= remaining
;
812 remaining
= sd
->next
;
814 sysfs_set_str(sra
, sd
, "state", "faulty");
815 sysfs_set_str(sra
, sd
, "slot", "none");
816 /* for external metadata disks should be removed in mdmon */
817 if (!st
->ss
->external
)
818 sysfs_set_str(sra
, sd
, "state", "remove");
819 sd
->disk
.state
|= (1<<MD_DISK_REMOVED
);
820 sd
->disk
.state
&= ~(1<<MD_DISK_SYNC
);
821 sd
->next
= sra
->devs
;
827 void reshape_free_fdlist(int *fdlist
,
828 unsigned long long *offsets
,
833 for (i
= 0; i
< size
; i
++)
841 int reshape_prepare_fdlist(char *devname
,
845 unsigned long blocks
,
848 unsigned long long *offsets
)
853 for (d
= 0; d
<= nrdisks
; d
++)
856 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
857 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
859 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
860 char *dn
= map_dev(sd
->disk
.major
,
862 fdlist
[sd
->disk
.raid_disk
]
863 = dev_open(dn
, O_RDONLY
);
864 offsets
[sd
->disk
.raid_disk
] = sd
->data_offset
*512;
865 if (fdlist
[sd
->disk
.raid_disk
] < 0) {
867 Name
": %s: cannot open component %s\n",
868 devname
, dn
? dn
: "-unknown-");
872 } else if (backup_file
== NULL
) {
874 char *dn
= map_dev(sd
->disk
.major
,
876 fdlist
[d
] = dev_open(dn
, O_RDWR
);
877 offsets
[d
] = (sd
->data_offset
+ sra
->component_size
- blocks
- 8)*512;
879 fprintf(stderr
, Name
": %s: cannot open component %s\n",
880 devname
, dn
? dn
: "-unknown-");
891 int reshape_open_backup_file(char *backup_file
,
896 unsigned long long *offsets
,
899 /* Return 1 on success, 0 on any form of failure */
900 /* need to check backup file is large enough */
906 *fdlist
= open(backup_file
, O_RDWR
|O_CREAT
|(restart
? O_TRUNC
: O_EXCL
),
910 fprintf(stderr
, Name
": %s: cannot create backup file %s: %s\n",
911 devname
, backup_file
, strerror(errno
));
914 /* Guard against backup file being on array device.
915 * If array is partitioned or if LVM etc is in the
916 * way this will not notice, but it is better than
919 fstat(*fdlist
, &stb
);
922 if (stb
.st_rdev
== dev
) {
923 fprintf(stderr
, Name
": backup file must NOT be"
924 " on the array being reshaped.\n");
930 for (i
=0; i
< blocks
+ 8 ; i
++) {
931 if (write(*fdlist
, buf
, 512) != 512) {
932 fprintf(stderr
, Name
": %s: cannot create"
933 " backup file %s: %s\n",
934 devname
, backup_file
, strerror(errno
));
938 if (fsync(*fdlist
) != 0) {
939 fprintf(stderr
, Name
": %s: cannot create backup file %s: %s\n",
940 devname
, backup_file
, strerror(errno
));
947 unsigned long compute_backup_blocks(int nchunk
, int ochunk
,
948 unsigned int ndata
, unsigned int odata
)
950 unsigned long a
, b
, blocks
;
951 /* So how much do we need to backup.
952 * We need an amount of data which is both a whole number of
953 * old stripes and a whole number of new stripes.
954 * So LCM for (chunksize*datadisks).
956 a
= (ochunk
/512) * odata
;
957 b
= (nchunk
/512) * ndata
;
965 /* LCM == product / GCD */
966 blocks
= (ochunk
/512) * (nchunk
/512) * odata
* ndata
/ a
;
971 char *analyse_change(struct mdinfo
*info
, struct reshape
*re
)
973 /* Based on the current array state in info->array and
974 * the changes in info->new_* etc, determine:
975 * - whether the change is possible
976 * - Intermediate level/raid_disks/layout
977 * - whether a restriping reshape is needed
978 * - number of sectors in minimum change unit. This
979 * will cover a whole number of stripes in 'before' and
982 * Return message if the change should be rejected
983 * NULL if the change can be achieved
985 * This can be called as part of starting a reshape, or
986 * when assembling an array that is undergoing reshape.
989 /* delta_parity records change in number of devices
990 * caused by level change
992 int delta_parity
= 0;
994 /* If a new level not explicitly given, we assume no-change */
995 if (info
->new_level
== UnSet
)
996 info
->new_level
= info
->array
.level
;
999 switch (info
->new_level
) {
1005 /* chunk size is meaningful, must divide component_size
1008 if (info
->component_size
% (info
->new_chunk
/512))
1009 return "New chunk size does not"
1010 " divide component size";
1013 return "chunk size not meaningful for this level";
1016 info
->new_chunk
= info
->array
.chunk_size
;
1018 switch (info
->array
.level
) {
1020 return "Cannot understand this RAID level";
1022 /* RAID1 can convert to RAID1 with different disks, or
1023 * raid5 with 2 disks, or
1026 if (info
->new_level
> 1 &&
1027 (info
->component_size
& 7))
1028 return "Cannot convert RAID1 of this size - "
1029 "reduce size to multiple of 4K first.";
1030 if (info
->new_level
== 0) {
1031 if (info
->delta_disks
!= UnSet
&&
1032 info
->delta_disks
!= 0)
1033 return "Cannot change number of disks "
1034 "with RAID1->RAID0 conversion";
1036 re
->before
.data_disks
= 1;
1037 re
->after
.data_disks
= 1;
1038 re
->before
.layout
= 0;
1039 re
->backup_blocks
= 0;
1043 if (info
->new_level
== 1) {
1044 if (info
->delta_disks
== UnSet
)
1045 /* Don't know what to do */
1046 return "no change requested for Growing RAID1";
1048 re
->backup_blocks
= 0;
1052 if (info
->array
.raid_disks
== 2 &&
1053 info
->new_level
== 5) {
1056 re
->before
.data_disks
= 1;
1057 if (info
->delta_disks
!= UnSet
&&
1058 info
->delta_disks
!= 0)
1059 re
->after
.data_disks
= 1 + info
->delta_disks
;
1061 re
->after
.data_disks
= 1;
1062 if (re
->after
.data_disks
< 1)
1063 return "Number of disks too small for RAID5";
1065 re
->before
.layout
= ALGORITHM_LEFT_SYMMETRIC
;
1066 info
->array
.chunk_size
= 65536;
1069 /* Could do some multi-stage conversions, but leave that to
1072 return "Impossibly level change request for RAID1";
1075 /* RAID10 can only be converted from near mode to
1076 * RAID0 by removing some devices
1078 if ((info
->array
.layout
& ~0xff) != 0x100)
1079 return "Cannot Grow RAID10 with far/offset layout";
1080 /* number of devices must be multiple of number of copies */
1081 if (info
->array
.raid_disks
% (info
->array
.layout
& 0xff))
1082 return "RAID10 layout too complex for Grow operation";
1084 if (info
->new_level
!= 0)
1085 return "RAID10 can only be changed to RAID0";
1086 new_disks
= (info
->array
.raid_disks
1087 / (info
->array
.layout
& 0xff));
1088 if (info
->delta_disks
== UnSet
)
1089 info
->delta_disks
= (new_disks
1090 - info
->array
.raid_disks
);
1092 if (info
->delta_disks
!= new_disks
- info
->array
.raid_disks
)
1093 return "New number of raid-devices impossible for RAID10";
1094 if (info
->new_chunk
&&
1095 info
->new_chunk
!= info
->array
.chunk_size
)
1096 return "Cannot change chunk-size with RAID10 Grow";
1101 re
->before
.data_disks
= new_disks
;
1102 re
->after
.data_disks
= re
->before
.data_disks
;
1103 re
->before
.layout
= 0;
1104 re
->backup_blocks
= 0;
1108 /* RAID0 can be converted to RAID10, or to RAID456 */
1109 if (info
->new_level
== 10) {
1110 if (info
->new_layout
== UnSet
&& info
->delta_disks
== UnSet
) {
1111 /* Assume near=2 layout */
1112 info
->new_layout
= 0x102;
1113 info
->delta_disks
= info
->array
.raid_disks
;
1115 if (info
->new_layout
== UnSet
) {
1116 int copies
= 1 + (info
->delta_disks
1117 / info
->array
.raid_disks
);
1118 if (info
->array
.raid_disks
* (copies
-1)
1119 != info
->delta_disks
)
1120 return "Impossible number of devices"
1121 " for RAID0->RAID10";
1122 info
->new_layout
= 0x100 + copies
;
1124 if (info
->delta_disks
== UnSet
) {
1125 int copies
= info
->new_layout
& 0xff;
1126 if (info
->new_layout
!= 0x100 + copies
)
1127 return "New layout impossible"
1128 " for RAID0->RAID10";;
1129 info
->delta_disks
= (copies
- 1) *
1130 info
->array
.raid_disks
;
1132 if (info
->new_chunk
&&
1133 info
->new_chunk
!= info
->array
.chunk_size
)
1134 return "Cannot change chunk-size with RAID0->RAID10";
1138 re
->before
.data_disks
= (info
->array
.raid_disks
+
1140 re
->after
.data_disks
= re
->before
.data_disks
;
1141 re
->before
.layout
= info
->new_layout
;
1142 re
->backup_blocks
= 0;
1146 /* RAID0 can also covert to RAID0/4/5/6 by first converting to
1147 * a raid4 style layout of the final level.
1149 switch (info
->new_level
) {
1154 re
->before
.layout
= 0;
1159 re
->before
.layout
= ALGORITHM_PARITY_N
;
1164 re
->before
.layout
= ALGORITHM_PARITY_N
;
1167 return "Impossible level change requested";
1169 re
->before
.data_disks
= info
->array
.raid_disks
;
1170 /* determining 'after' layout happens outside this 'switch' */
1174 info
->array
.layout
= ALGORITHM_PARITY_N
;
1176 switch (info
->new_level
) {
1180 re
->level
= info
->array
.level
;
1181 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1182 re
->before
.layout
= info
->array
.layout
;
1186 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1187 re
->before
.layout
= info
->array
.layout
;
1192 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1193 switch (info
->array
.layout
) {
1194 case ALGORITHM_LEFT_ASYMMETRIC
:
1195 re
->before
.layout
= ALGORITHM_LEFT_ASYMMETRIC_6
;
1197 case ALGORITHM_RIGHT_ASYMMETRIC
:
1198 re
->before
.layout
= ALGORITHM_RIGHT_ASYMMETRIC_6
;
1200 case ALGORITHM_LEFT_SYMMETRIC
:
1201 re
->before
.layout
= ALGORITHM_LEFT_SYMMETRIC_6
;
1203 case ALGORITHM_RIGHT_SYMMETRIC
:
1204 re
->before
.layout
= ALGORITHM_RIGHT_SYMMETRIC_6
;
1206 case ALGORITHM_PARITY_0
:
1207 re
->before
.layout
= ALGORITHM_PARITY_0_6
;
1209 case ALGORITHM_PARITY_N
:
1210 re
->before
.layout
= ALGORITHM_PARITY_N_6
;
1213 return "Cannot convert an array with this layout";
1217 if (info
->array
.raid_disks
!= 2)
1218 return "Can only convert a 2-device array to RAID1";
1219 if (info
->delta_disks
!= UnSet
&&
1220 info
->delta_disks
!= 0)
1221 return "Cannot set raid_disk when "
1222 "converting RAID5->RAID1";
1226 return "Impossible level change requested";
1230 switch (info
->new_level
) {
1236 re
->before
.data_disks
= info
->array
.raid_disks
- 2;
1237 re
->before
.layout
= info
->array
.layout
;
1240 return "Impossible level change requested";
1245 /* If we reached here then it looks like a re-stripe is
1246 * happening. We have determined the intermediate level
1247 * and initial raid_disks/layout and stored these in 're'.
1249 * We need to deduce the final layout that can be atomically
1250 * converted to the end state.
1252 switch (info
->new_level
) {
1254 /* We can only get to RAID0 from RAID4 or RAID5
1255 * with appropriate layout and one extra device
1257 if (re
->level
!= 4 && re
->level
!= 5)
1258 return "Cannot covert to RAID0 from this level";
1260 switch (re
->level
) {
1262 re
->after
.layout
= 0 ; break;
1264 re
->after
.layout
= ALGORITHM_PARITY_N
; break;
1269 /* We can only get to RAID4 from RAID5 */
1270 if (re
->level
!= 4 && re
->level
!= 5)
1271 return "Cannot convert to RAID4 from this level";
1273 switch (re
->level
) {
1275 re
->after
.layout
= 0 ; break;
1277 re
->after
.layout
= ALGORITHM_PARITY_N
; break;
1282 /* We get to RAID5 from RAID5 or RAID6 */
1283 if (re
->level
!= 5 && re
->level
!= 6)
1284 return "Cannot convert to RAID5 from this level";
1286 switch (re
->level
) {
1288 if (info
->new_layout
== UnSet
)
1289 re
->after
.layout
= re
->before
.layout
;
1291 re
->after
.layout
= info
->new_layout
;
1294 if (info
->new_layout
== UnSet
)
1295 info
->new_layout
= re
->before
.layout
;
1297 /* after.layout needs to be raid6 version of new_layout */
1298 if (info
->new_layout
== ALGORITHM_PARITY_N
)
1299 re
->after
.layout
= ALGORITHM_PARITY_N
;
1302 char *ls
= map_num(r5layout
, info
->new_layout
);
1305 /* Current RAID6 layout has a RAID5
1308 strcat(strcpy(layout
, ls
), "-6");
1309 l
= map_name(r6layout
, layout
);
1311 return "Cannot find RAID6 layout"
1314 /* Current RAID6 has no equivalent.
1315 * If it is already a '-6' layout we
1316 * can leave it unchanged, else we must
1319 ls
= map_num(r6layout
, info
->new_layout
);
1321 strcmp(ls
+strlen(ls
)-2, "-6") != 0)
1322 return "Please specify new layout";
1323 l
= info
->new_layout
;
1325 re
->after
.layout
= l
;
1331 /* We must already be at level 6 */
1333 return "Impossible level change";
1334 if (info
->new_layout
== UnSet
)
1335 re
->after
.layout
= info
->array
.layout
;
1337 re
->after
.layout
= info
->new_layout
;
1340 return "Impossible level change requested";
1342 if (info
->delta_disks
== UnSet
)
1343 info
->delta_disks
= delta_parity
;
1345 re
->after
.data_disks
= (re
->before
.data_disks
1348 switch (re
->level
) {
1349 case 6: re
->parity
= 2; break;
1351 case 5: re
->parity
= 1; break;
1352 default: re
->parity
= 0; break;
1354 /* So we have a restripe operation, we need to calculate the number
1355 * of blocks per reshape operation.
1357 if (info
->new_chunk
== 0)
1358 info
->new_chunk
= info
->array
.chunk_size
;
1359 if (re
->after
.data_disks
== re
->before
.data_disks
&&
1360 re
->after
.layout
== re
->before
.layout
&&
1361 info
->new_chunk
== info
->array
.chunk_size
) {
1362 /* Nothing to change */
1363 re
->backup_blocks
= 0;
1366 if (re
->after
.data_disks
== 1 && re
->before
.data_disks
== 1) {
1367 /* chunk and layout changes make no difference */
1368 re
->backup_blocks
= 0;
1372 if (re
->after
.data_disks
== re
->before
.data_disks
&&
1373 get_linux_version() < 2006032)
1374 return "in-place reshape is not safe before 2.6.32 - sorry.";
1376 if (re
->after
.data_disks
< re
->before
.data_disks
&&
1377 get_linux_version() < 2006030)
1378 return "reshape to fewer devices is not supported before 2.6.30 - sorry.";
1380 re
->backup_blocks
= compute_backup_blocks(
1381 info
->new_chunk
, info
->array
.chunk_size
,
1382 re
->after
.data_disks
,
1383 re
->before
.data_disks
);
1385 re
->new_size
= info
->component_size
* re
->after
.data_disks
;
1389 static int set_array_size(struct supertype
*st
, struct mdinfo
*sra
,
1392 struct mdinfo
*info
;
1396 if ((st
== NULL
) || (sra
== NULL
))
1399 if (text_version
== NULL
)
1400 text_version
= sra
->text_version
;
1401 subarray
= strchr(text_version
+1, '/')+1;
1402 info
= st
->ss
->container_content(st
, subarray
);
1404 unsigned long long current_size
= 0;
1405 unsigned long long new_size
=
1406 info
->custom_array_size
/2;
1408 if (sysfs_get_ll(sra
, NULL
, "array_size", ¤t_size
) == 0 &&
1409 new_size
> current_size
) {
1410 if (sysfs_set_num(sra
, NULL
, "array_size", new_size
)
1412 dprintf("Error: Cannot set array size");
1415 dprintf("Array size changed");
1417 dprintf(" from %llu to %llu.\n",
1418 current_size
, new_size
);
1422 dprintf("Error: set_array_size(): info pointer in NULL\n");
1427 static int reshape_array(char *container
, int fd
, char *devname
,
1428 struct supertype
*st
, struct mdinfo
*info
,
1429 int force
, struct mddev_dev
*devlist
,
1430 char *backup_file
, int quiet
, int forked
,
1431 int restart
, int freeze_reshape
);
1432 static int reshape_container(char *container
, char *devname
,
1434 struct supertype
*st
,
1435 struct mdinfo
*info
,
1438 int quiet
, int restart
, int freeze_reshape
);
1440 int Grow_reshape(char *devname
, int fd
, int quiet
, char *backup_file
,
1442 int level
, char *layout_str
, int chunksize
, int raid_disks
,
1443 struct mddev_dev
*devlist
,
1444 int assume_clean
, int force
)
1446 /* Make some changes in the shape of an array.
1447 * The kernel must support the change.
1449 * There are three different changes. Each can trigger
1450 * a resync or recovery so we freeze that until we have
1451 * requested everything (if kernel supports freezing - 2.6.30).
1453 * - change size (i.e. component_size)
1455 * - change layout/chunksize/ndisks
1457 * The last can require a reshape. It is different on different
1458 * levels so we need to check the level before actioning it.
1459 * Some times the level change needs to be requested after the
1460 * reshape (e.g. raid6->raid5, raid5->raid0)
1463 struct mdu_array_info_s array
;
1465 struct supertype
*st
;
1466 char *subarray
= NULL
;
1470 char *container
= NULL
;
1471 char container_buf
[20];
1474 struct mddev_dev
*dv
;
1480 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) < 0) {
1481 fprintf(stderr
, Name
": %s is not an active md array - aborting\n",
1487 (chunksize
|| level
!= UnSet
|| layout_str
|| raid_disks
)) {
1488 fprintf(stderr
, Name
": cannot change component size at the same time "
1489 "as other changes.\n"
1490 " Change size first, then check data is intact before "
1491 "making other changes.\n");
1495 if (raid_disks
&& raid_disks
< array
.raid_disks
&& array
.level
> 1 &&
1496 get_linux_version() < 2006032 &&
1497 !check_env("MDADM_FORCE_FEWER")) {
1498 fprintf(stderr
, Name
": reducing the number of devices is not safe before Linux 2.6.32\n"
1499 " Please use a newer kernel\n");
1503 st
= super_by_fd(fd
, &subarray
);
1505 fprintf(stderr
, Name
": Unable to determine metadata format for %s\n", devname
);
1508 if (raid_disks
> st
->max_devs
) {
1509 fprintf(stderr
, Name
": Cannot increase raid-disks on this array"
1510 " beyond %d\n", st
->max_devs
);
1514 /* in the external case we need to check that the requested reshape is
1515 * supported, and perform an initial check that the container holds the
1516 * pre-requisite spare devices (mdmon owns final validation)
1518 if (st
->ss
->external
) {
1523 container_dev
= st
->container_dev
;
1524 cfd
= open_dev_excl(st
->container_dev
);
1526 container_dev
= st
->devnum
;
1528 cfd
= open_dev_excl(st
->devnum
);
1532 fprintf(stderr
, Name
": Unable to open container for %s\n",
1538 fmt_devname(container_buf
, container_dev
);
1539 container
= container_buf
;
1541 rv
= st
->ss
->load_container(st
, cfd
, NULL
);
1544 fprintf(stderr
, Name
": Cannot read superblock for %s\n",
1550 /* check if operation is supported for metadata handler */
1551 if (st
->ss
->container_content
) {
1552 struct mdinfo
*cc
= NULL
;
1553 struct mdinfo
*content
= NULL
;
1555 cc
= st
->ss
->container_content(st
, subarray
);
1556 for (content
= cc
; content
; content
= content
->next
) {
1557 int allow_reshape
= 1;
1559 /* check if reshape is allowed based on metadata
1560 * indications stored in content.array.status
1562 if (content
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
))
1564 if (content
->array
.state
1565 & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
))
1567 if (!allow_reshape
) {
1568 fprintf(stderr
, Name
1569 " cannot reshape arrays in"
1570 " container with unsupported"
1571 " metadata: %s(%s)\n",
1572 devname
, container_buf
);
1580 if (mdmon_running(container_dev
))
1581 st
->update_tail
= &st
->updates
;
1585 for (dv
= devlist
; dv
; dv
= dv
->next
)
1587 if (raid_disks
> array
.raid_disks
&&
1588 array
.spare_disks
+added_disks
< (raid_disks
- array
.raid_disks
) &&
1591 Name
": Need %d spare%s to avoid degraded array,"
1592 " and only have %d.\n"
1593 " Use --force to over-ride this check.\n",
1594 raid_disks
- array
.raid_disks
,
1595 raid_disks
- array
.raid_disks
== 1 ? "" : "s",
1596 array
.spare_disks
+ added_disks
);
1600 sra
= sysfs_read(fd
, 0, GET_LEVEL
| GET_DISKS
| GET_DEVS
1601 | GET_STATE
| GET_VERSION
);
1603 if (st
->ss
->external
&& subarray
== NULL
) {
1604 array
.level
= LEVEL_CONTAINER
;
1605 sra
->array
.level
= LEVEL_CONTAINER
;
1608 fprintf(stderr
, Name
": failed to read sysfs parameters for %s\n",
1612 frozen
= freeze(st
);
1614 /* freeze() already spewed the reason */
1617 } else if (frozen
< 0) {
1618 fprintf(stderr
, Name
": %s is performing resync/recovery and cannot"
1619 " be reshaped\n", devname
);
1624 /* ========= set size =============== */
1625 if (size
>= 0 && (size
== 0 || size
!= array
.size
)) {
1626 long long orig_size
= get_component_size(fd
)/2;
1627 long long min_csize
;
1629 int raid0_takeover
= 0;
1632 orig_size
= array
.size
;
1634 if (reshape_super(st
, size
, UnSet
, UnSet
, 0, 0, UnSet
, NULL
,
1635 devname
, APPLY_METADATA_CHANGES
, !quiet
)) {
1640 if (st
->ss
->external
) {
1641 /* metadata can have size limitation
1642 * update size value according to metadata information
1644 struct mdinfo
*sizeinfo
=
1645 st
->ss
->container_content(st
, subarray
);
1647 unsigned long long new_size
=
1648 sizeinfo
->custom_array_size
/2;
1649 int data_disks
= get_data_disks(
1650 sizeinfo
->array
.level
,
1651 sizeinfo
->array
.layout
,
1652 sizeinfo
->array
.raid_disks
);
1653 new_size
/= data_disks
;
1654 dprintf("Metadata size correction from %llu to "
1655 "%llu (%llu)\n", orig_size
, new_size
,
1656 new_size
* data_disks
);
1658 sysfs_free(sizeinfo
);
1662 /* Update the size of each member device in case
1663 * they have been resized. This will never reduce
1664 * below the current used-size. The "size" attribute
1665 * understands '0' to mean 'max'.
1669 for (mdi
= sra
->devs
; mdi
; mdi
= mdi
->next
) {
1670 if (sysfs_set_num(sra
, mdi
, "size", size
) < 0) {
1671 /* Probably kernel refusing to let us
1672 * reduce the size - not an error.
1676 if (array
.not_persistent
== 0 &&
1677 array
.major_version
== 0 &&
1678 get_linux_version() < 3001000) {
1679 /* Dangerous to allow size to exceed 2TB */
1680 unsigned long long csize
;
1681 if (sysfs_get_ll(sra
, mdi
, "size", &csize
) == 0) {
1682 if (csize
>= 2ULL*1024*1024*1024)
1683 csize
= 2ULL*1024*1024*1024;
1684 if ((min_csize
== 0 || (min_csize
1685 > (long long)csize
)))
1691 fprintf(stderr
, Name
": Cannot set size on "
1692 "array members.\n");
1693 goto size_change_error
;
1695 if (min_csize
&& size
> min_csize
) {
1696 fprintf(stderr
, Name
": Cannot safely make this array "
1697 "use more than 2TB per device on this kernel.\n");
1699 goto size_change_error
;
1701 if (min_csize
&& size
== 0) {
1702 /* Don't let the kernel choose a size - it will get
1705 fprintf(stderr
, Name
": Limited v0.90 array to "
1706 "2TB per device\n");
1709 if (st
->ss
->external
) {
1710 if (sra
->array
.level
== 0) {
1711 rv
= sysfs_set_str(sra
, NULL
, "level",
1715 /* get array parametes after takeover
1716 * to chane one parameter at time only
1718 rv
= ioctl(fd
, GET_ARRAY_INFO
, &array
);
1721 /* make sure mdmon is
1722 * aware of the new level */
1723 if (!mdmon_running(st
->container_dev
))
1724 start_mdmon(st
->container_dev
);
1725 ping_monitor(container
);
1726 if (mdmon_running(st
->container_dev
) &&
1727 st
->update_tail
== NULL
)
1728 st
->update_tail
= &st
->updates
;
1732 if (array
.size
!= size
) {
1733 /* got truncated to 32bit, write to
1734 * component_size instead
1737 rv
= sysfs_set_num(sra
, NULL
,
1738 "component_size", size
);
1742 rv
= ioctl(fd
, SET_ARRAY_INFO
, &array
);
1744 /* manage array size when it is managed externally
1746 if ((rv
== 0) && st
->ss
->external
)
1747 rv
= set_array_size(st
, sra
, sra
->text_version
);
1750 if (raid0_takeover
) {
1751 /* do not recync non-existing parity,
1752 * we will drop it anyway
1754 sysfs_set_str(sra
, NULL
, "sync_action", "frozen");
1755 /* go back to raid0, drop parity disk
1757 sysfs_set_str(sra
, NULL
, "level", "raid0");
1758 ioctl(fd
, GET_ARRAY_INFO
, &array
);
1765 /* restore metadata */
1766 if (reshape_super(st
, orig_size
, UnSet
, UnSet
, 0, 0,
1767 UnSet
, NULL
, devname
,
1768 ROLLBACK_METADATA_CHANGES
,
1771 fprintf(stderr
, Name
": Cannot set device size for %s: %s\n",
1772 devname
, strerror(err
));
1774 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
1775 fprintf(stderr
, " Bitmap must be removed before size can be changed\n");
1780 /* This will fail on kernels newer than 3.0 unless
1781 * a backport has been arranged.
1784 sysfs_set_str(sra
, NULL
, "resync_start", "none") < 0)
1785 fprintf(stderr
, Name
": --assume-clean not support with --grow on this kernel\n");
1787 ioctl(fd
, GET_ARRAY_INFO
, &array
);
1788 size
= get_component_size(fd
)/2;
1792 if (size
== orig_size
)
1793 fprintf(stderr
, Name
": component size of %s "
1794 "unchanged at %lluK\n",
1797 fprintf(stderr
, Name
": component size of %s "
1798 "has been set to %lluK\n",
1802 } else if (array
.level
!= LEVEL_CONTAINER
) {
1803 size
= get_component_size(fd
)/2;
1808 /* See if there is anything else to do */
1809 if ((level
== UnSet
|| level
== array
.level
) &&
1810 (layout_str
== NULL
) &&
1811 (chunksize
== 0 || chunksize
== array
.chunk_size
) &&
1812 (raid_disks
== 0 || raid_disks
== array
.raid_disks
)) {
1813 /* Nothing more to do */
1814 if (!changed
&& !quiet
)
1815 fprintf(stderr
, Name
": %s: no change requested\n",
1820 /* ========= check for Raid10/Raid1 -> Raid0 conversion ===============
1821 * current implementation assumes that following conditions must be met:
1824 * - near_copies == 2
1826 if ((level
== 0 && array
.level
== 10 && sra
&&
1827 array
.layout
== ((1 << 8) + 2) && !(array
.raid_disks
& 1)) ||
1828 (level
== 0 && array
.level
== 1 && sra
)) {
1830 err
= remove_disks_for_takeover(st
, sra
, array
.layout
);
1832 dprintf(Name
": Array cannot be reshaped\n");
1838 /* Make sure mdmon has seen the device removal
1839 * and updated metadata before we continue with
1843 ping_monitor(container
);
1846 memset(&info
, 0, sizeof(info
));
1848 sysfs_init(&info
, fd
, NoMdDev
);
1849 strcpy(info
.text_version
, sra
->text_version
);
1850 info
.component_size
= size
*2;
1851 info
.new_level
= level
;
1852 info
.new_chunk
= chunksize
* 1024;
1853 if (info
.array
.level
== LEVEL_CONTAINER
) {
1854 info
.delta_disks
= UnSet
;
1855 info
.array
.raid_disks
= raid_disks
;
1856 } else if (raid_disks
)
1857 info
.delta_disks
= raid_disks
- info
.array
.raid_disks
;
1859 info
.delta_disks
= UnSet
;
1860 if (layout_str
== NULL
) {
1861 info
.new_layout
= UnSet
;
1862 if (info
.array
.level
== 6 &&
1863 (info
.new_level
== 6 || info
.new_level
== UnSet
) &&
1864 info
.array
.layout
>= 16) {
1865 fprintf(stderr
, Name
1866 ": %s has a non-standard layout. If you"
1867 " wish to preserve this\n"
1868 " during the reshape, please specify"
1869 " --layout=preserve\n"
1870 " If you want to change it, specify a"
1871 " layout or use --layout=normalise\n",
1876 } else if (strcmp(layout_str
, "normalise") == 0 ||
1877 strcmp(layout_str
, "normalize") == 0) {
1878 /* If we have a -6 RAID6 layout, remove the '-6'. */
1879 info
.new_layout
= UnSet
;
1880 if (info
.array
.level
== 6 && info
.new_level
== UnSet
) {
1882 strcpy(l
, map_num(r6layout
, info
.array
.layout
));
1883 h
= strrchr(l
, '-');
1884 if (h
&& strcmp(h
, "-6") == 0) {
1886 info
.new_layout
= map_name(r6layout
, l
);
1889 } else if (strcmp(layout_str
, "preserve") == 0) {
1890 info
.new_layout
= UnSet
;
1892 int l
= info
.new_level
;
1894 l
= info
.array
.level
;
1897 info
.new_layout
= map_name(r5layout
, layout_str
);
1900 info
.new_layout
= map_name(r6layout
, layout_str
);
1903 info
.new_layout
= parse_layout_10(layout_str
);
1906 info
.new_layout
= parse_layout_faulty(layout_str
);
1909 fprintf(stderr
, Name
": layout not meaningful"
1910 " with this level\n");
1914 if (info
.new_layout
== UnSet
) {
1915 fprintf(stderr
, Name
": layout %s not understood"
1916 " for this level\n",
1923 if (array
.level
== LEVEL_FAULTY
) {
1924 if (level
!= UnSet
&& level
!= array
.level
) {
1925 fprintf(stderr
, Name
": cannot change level of Faulty device\n");
1929 fprintf(stderr
, Name
": cannot set chunksize of Faulty device\n");
1932 if (raid_disks
&& raid_disks
!= 1) {
1933 fprintf(stderr
, Name
": cannot set raid_disks of Faulty device\n");
1937 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
1938 dprintf("Cannot get array information.\n");
1941 array
.layout
= info
.new_layout
;
1942 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
1943 fprintf(stderr
, Name
": failed to set new layout\n");
1946 printf("layout for %s set to %d\n",
1947 devname
, array
.layout
);
1949 } else if (array
.level
== LEVEL_CONTAINER
) {
1950 /* This change is to be applied to every array in the
1951 * container. This is only needed when the metadata imposes
1952 * restraints of the various arrays in the container.
1953 * Currently we only know that IMSM requires all arrays
1954 * to have the same number of devices so changing the
1955 * number of devices (On-Line Capacity Expansion) must be
1956 * performed at the level of the container
1958 rv
= reshape_container(container
, devname
, -1, st
, &info
,
1959 force
, backup_file
, quiet
, 0, 0);
1962 /* get spare devices from external metadata
1964 if (st
->ss
->external
) {
1965 struct mdinfo
*info2
;
1967 info2
= st
->ss
->container_content(st
, subarray
);
1969 info
.array
.spare_disks
=
1970 info2
->array
.spare_disks
;
1975 /* Impose these changes on a single array. First
1976 * check that the metadata is OK with the change. */
1978 if (reshape_super(st
, -1, info
.new_level
,
1979 info
.new_layout
, info
.new_chunk
,
1980 info
.array
.raid_disks
, info
.delta_disks
,
1981 backup_file
, devname
, APPLY_METADATA_CHANGES
,
1987 rv
= reshape_array(container
, fd
, devname
, st
, &info
, force
,
1988 devlist
, backup_file
, quiet
, 0, 0, 0);
1998 /* verify_reshape_position()
1999 * Function checks if reshape position in metadata is not farther
2000 * than position in md.
2002 * 0 : not valid sysfs entry
2003 * it can be caused by not started reshape, it should be started
2004 * by reshape array or raid0 array is before takeover
2005 * -1 : error, reshape position is obviously wrong
2006 * 1 : success, reshape progress correct or updated
2008 static int verify_reshape_position(struct mdinfo
*info
, int level
)
2014 /* read sync_max, failure can mean raid0 array */
2015 rv
= sysfs_get_str(info
, NULL
, "sync_max", buf
, 40);
2019 unsigned long long position
= strtoull(buf
, &ep
, 0);
2021 dprintf(Name
": Read sync_max sysfs entry is: %s\n", buf
);
2022 if (!(ep
== buf
|| (*ep
!= 0 && *ep
!= '\n' && *ep
!= ' '))) {
2023 position
*= get_data_disks(level
,
2025 info
->array
.raid_disks
);
2026 if (info
->reshape_progress
< position
) {
2027 dprintf("Corrected reshape progress (%llu) to "
2028 "md position (%llu)\n",
2029 info
->reshape_progress
, position
);
2030 info
->reshape_progress
= position
;
2032 } else if (info
->reshape_progress
> position
) {
2033 fprintf(stderr
, Name
": Fatal error: array "
2034 "reshape was not properly frozen "
2035 "(expected reshape position is %llu, "
2036 "but reshape progress is %llu.\n",
2037 position
, info
->reshape_progress
);
2040 dprintf("Reshape position in md and metadata "
2045 } else if (rv
== 0) {
2046 /* for valid sysfs entry, 0-length content
2047 * should be indicated as error
2055 static int reshape_array(char *container
, int fd
, char *devname
,
2056 struct supertype
*st
, struct mdinfo
*info
,
2057 int force
, struct mddev_dev
*devlist
,
2058 char *backup_file
, int quiet
, int forked
,
2059 int restart
, int freeze_reshape
)
2061 struct reshape reshape
;
2064 int orig_level
= UnSet
;
2067 struct mdu_array_info_s array
;
2070 struct mddev_dev
*dv
;
2074 unsigned long long *offsets
= NULL
;
2078 unsigned long blocks
;
2079 unsigned long cache
;
2080 unsigned long long array_size
;
2082 struct mdinfo
*sra
= NULL
;
2084 /* when reshaping a RAID0, the component_size might be zero.
2085 * So try to fix that up.
2087 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
2088 dprintf("Cannot get array information.\n");
2091 if (array
.level
== 0 && info
->component_size
== 0) {
2092 get_dev_size(fd
, NULL
, &array_size
);
2093 info
->component_size
= array_size
/ array
.raid_disks
;
2096 if (info
->reshape_active
) {
2097 int new_level
= info
->new_level
;
2098 info
->new_level
= UnSet
;
2099 if (info
->delta_disks
> 0)
2100 info
->array
.raid_disks
-= info
->delta_disks
;
2101 msg
= analyse_change(info
, &reshape
);
2102 info
->new_level
= new_level
;
2103 if (info
->delta_disks
> 0)
2104 info
->array
.raid_disks
+= info
->delta_disks
;
2106 /* Make sure the array isn't read-only */
2107 ioctl(fd
, RESTART_ARRAY_RW
, 0);
2109 msg
= analyse_change(info
, &reshape
);
2111 fprintf(stderr
, Name
": %s\n", msg
);
2115 (reshape
.level
!= info
->array
.level
||
2116 reshape
.before
.layout
!= info
->array
.layout
||
2117 reshape
.before
.data_disks
+ reshape
.parity
2118 != info
->array
.raid_disks
- max(0, info
->delta_disks
))) {
2119 fprintf(stderr
, Name
": reshape info is not in native format -"
2120 " cannot continue.\n");
2124 if (st
->ss
->external
&& restart
&& (info
->reshape_progress
== 0)) {
2125 /* When reshape is restarted from '0', very begin of array
2126 * it is possible that for external metadata reshape and array
2127 * configuration doesn't happen.
2128 * Check if md has the same opinion, and reshape is restarted
2129 * from 0. If so, this is regular reshape start after reshape
2130 * switch in metadata to next array only.
2132 if ((verify_reshape_position(info
, reshape
.level
) >= 0) &&
2133 (info
->reshape_progress
== 0))
2137 /* reshape already started. just skip to monitoring the reshape */
2138 if (reshape
.backup_blocks
== 0)
2142 /* The container is frozen but the array may not be.
2143 * So freeze the array so spares don't get put to the wrong use
2144 * FIXME there should probably be a cleaner separation between
2145 * freeze_array and freeze_container.
2147 sysfs_freeze_array(info
);
2148 /* Check we have enough spares to not be degraded */
2150 for (dv
= devlist
; dv
; dv
=dv
->next
)
2152 spares_needed
= max(reshape
.before
.data_disks
,
2153 reshape
.after
.data_disks
)
2154 + reshape
.parity
- array
.raid_disks
;
2157 info
->new_level
> 1 && info
->array
.level
> 1 &&
2158 spares_needed
> info
->array
.spare_disks
+ added_disks
) {
2160 Name
": Need %d spare%s to avoid degraded array,"
2161 " and only have %d.\n"
2162 " Use --force to over-ride this check.\n",
2164 spares_needed
== 1 ? "" : "s",
2165 info
->array
.spare_disks
+ added_disks
);
2168 /* Check we have enough spares to not fail */
2169 spares_needed
= max(reshape
.before
.data_disks
,
2170 reshape
.after
.data_disks
)
2172 if ((info
->new_level
> 1 || info
->new_level
== 0) &&
2173 spares_needed
> info
->array
.spare_disks
+added_disks
) {
2175 Name
": Need %d spare%s to create working array,"
2176 " and only have %d.\n",
2178 spares_needed
== 1 ? "" : "s",
2179 info
->array
.spare_disks
+ added_disks
);
2183 if (reshape
.level
!= array
.level
) {
2184 char *c
= map_num(pers
, reshape
.level
);
2189 err
= sysfs_set_str(info
, NULL
, "level", c
);
2192 fprintf(stderr
, Name
": %s: could not set level to %s\n",
2195 (info
->array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2196 fprintf(stderr
, " Bitmap must be removed"
2197 " before level can be changed\n");
2201 fprintf(stderr
, Name
": level of %s changed to %s\n",
2203 orig_level
= array
.level
;
2204 sysfs_freeze_array(info
);
2206 if (reshape
.level
> 0 && st
->ss
->external
) {
2207 /* make sure mdmon is aware of the new level */
2208 if (mdmon_running(st
->container_dev
))
2209 flush_mdmon(container
);
2211 if (!mdmon_running(st
->container_dev
))
2212 start_mdmon(st
->container_dev
);
2213 ping_monitor(container
);
2214 if (mdmon_running(st
->container_dev
) &&
2215 st
->update_tail
== NULL
)
2216 st
->update_tail
= &st
->updates
;
2219 /* ->reshape_super might have chosen some spares from the
2220 * container that it wants to be part of the new array.
2221 * We can collect them with ->container_content and give
2222 * them to the kernel.
2224 if (st
->ss
->reshape_super
&& st
->ss
->container_content
) {
2225 char *subarray
= strchr(info
->text_version
+1, '/')+1;
2226 struct mdinfo
*info2
=
2227 st
->ss
->container_content(st
, subarray
);
2231 sysfs_init(info2
, fd
, st
->devnum
);
2232 /* When increasing number of devices, we need to set
2233 * new raid_disks before adding these, or they might
2236 if (reshape
.backup_blocks
&&
2237 reshape
.after
.data_disks
> reshape
.before
.data_disks
)
2238 subarray_set_num(container
, info2
, "raid_disks",
2239 reshape
.after
.data_disks
+
2241 for (d
= info2
->devs
; d
; d
= d
->next
) {
2242 if (d
->disk
.state
== 0 &&
2243 d
->disk
.raid_disk
>= 0) {
2244 /* This is a spare that wants to
2245 * be part of the array.
2247 add_disk(fd
, st
, info2
, d
);
2253 /* We might have been given some devices to add to the
2254 * array. Now that the array has been changed to the right
2255 * level and frozen, we can safely add them.
2258 Manage_subdevs(devname
, fd
, devlist
, !quiet
,
2261 if (reshape
.backup_blocks
== 0) {
2262 /* No restriping needed, but we might need to impose
2263 * some more changes: layout, raid_disks, chunk_size
2265 /* read current array info */
2266 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
2267 dprintf("Cannot get array information.\n");
2270 /* compare current array info with new values and if
2271 * it is different update them to new */
2272 if (info
->new_layout
!= UnSet
&&
2273 info
->new_layout
!= array
.layout
) {
2274 array
.layout
= info
->new_layout
;
2275 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2276 fprintf(stderr
, Name
": failed to set new layout\n");
2279 printf("layout for %s set to %d\n",
2280 devname
, array
.layout
);
2282 if (info
->delta_disks
!= UnSet
&&
2283 info
->delta_disks
!= 0 &&
2284 array
.raid_disks
!= (info
->array
.raid_disks
+ info
->delta_disks
)) {
2285 array
.raid_disks
+= info
->delta_disks
;
2286 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2287 fprintf(stderr
, Name
": failed to set raid disks\n");
2289 } else if (!quiet
) {
2290 printf("raid_disks for %s set to %d\n",
2291 devname
, array
.raid_disks
);
2294 if (info
->new_chunk
!= 0 &&
2295 info
->new_chunk
!= array
.chunk_size
) {
2296 if (sysfs_set_num(info
, NULL
,
2297 "chunk_size", info
->new_chunk
) != 0) {
2298 fprintf(stderr
, Name
": failed to set chunk size\n");
2301 printf("chunk size for %s set to %d\n",
2302 devname
, array
.chunk_size
);
2309 * There are three possibilities.
2310 * 1/ The array will shrink.
2311 * We need to ensure the reshape will pause before reaching
2312 * the 'critical section'. We also need to fork and wait for
2313 * that to happen. When it does we
2314 * suspend/backup/complete/unfreeze
2316 * 2/ The array will not change size.
2317 * This requires that we keep a backup of a sliding window
2318 * so that we can restore data after a crash. So we need
2319 * to fork and monitor progress.
2320 * In future we will allow the data_offset to change, so
2321 * a sliding backup becomes unnecessary.
2323 * 3/ The array will grow. This is relatively easy.
2324 * However the kernel's restripe routines will cheerfully
2325 * overwrite some early data before it is safe. So we
2326 * need to make a backup of the early parts of the array
2327 * and be ready to restore it if rebuild aborts very early.
2328 * For externally managed metadata, we still need a forked
2329 * child to monitor the reshape and suspend IO over the region
2330 * that is being reshaped.
2332 * We backup data by writing it to one spare, or to a
2333 * file which was given on command line.
2335 * In each case, we first make sure that storage is available
2336 * for the required backup.
2338 * - request the shape change.
2339 * - fork to handle backup etc.
2342 /* Check that we can hold all the data */
2343 get_dev_size(fd
, NULL
, &array_size
);
2344 if (reshape
.new_size
< (array_size
/512)) {
2346 Name
": this change will reduce the size of the array.\n"
2347 " use --grow --array-size first to truncate array.\n"
2348 " e.g. mdadm --grow %s --array-size %llu\n",
2349 devname
, reshape
.new_size
/2);
2353 sra
= sysfs_read(fd
, 0,
2354 GET_COMPONENT
|GET_DEVS
|GET_OFFSET
|GET_STATE
|GET_CHUNK
|
2357 fprintf(stderr
, Name
": %s: Cannot get array details from sysfs\n",
2362 /* Decide how many blocks (sectors) for a reshape
2363 * unit. The number we have so far is just a minimum
2365 blocks
= reshape
.backup_blocks
;
2366 if (reshape
.before
.data_disks
==
2367 reshape
.after
.data_disks
) {
2368 /* Make 'blocks' bigger for better throughput, but
2369 * not so big that we reject it below.
2370 * Try for 16 megabytes
2372 while (blocks
* 32 < sra
->component_size
&&
2376 fprintf(stderr
, Name
": Need to backup %luK of critical "
2377 "section..\n", blocks
/2);
2379 if (blocks
>= sra
->component_size
/2) {
2380 fprintf(stderr
, Name
": %s: Something wrong"
2381 " - reshape aborted\n",
2386 /* Now we need to open all these devices so we can read/write.
2388 nrdisks
= max(reshape
.before
.data_disks
,
2389 reshape
.after
.data_disks
) + reshape
.parity
2390 + sra
->array
.spare_disks
;
2391 fdlist
= malloc((1+nrdisks
) * sizeof(int));
2392 offsets
= malloc((1+nrdisks
) * sizeof(offsets
[0]));
2393 if (!fdlist
|| !offsets
) {
2394 fprintf(stderr
, Name
": malloc failed: grow aborted\n");
2398 odisks
= reshape
.before
.data_disks
+ reshape
.parity
;
2399 d
= reshape_prepare_fdlist(devname
, sra
, odisks
,
2400 nrdisks
, blocks
, backup_file
,
2405 if ((st
->ss
->manage_reshape
== NULL
) ||
2406 (st
->ss
->recover_backup
== NULL
)) {
2407 if (backup_file
== NULL
) {
2408 if (reshape
.after
.data_disks
<=
2409 reshape
.before
.data_disks
) {
2410 fprintf(stderr
, Name
": %s: Cannot grow - "
2411 "need backup-file\n", devname
);
2413 } else if (sra
->array
.spare_disks
== 0) {
2414 fprintf(stderr
, Name
": %s: Cannot grow - "
2415 "need a spare or backup-file to backup "
2416 "critical section\n", devname
);
2420 if (!reshape_open_backup_file(backup_file
, fd
, devname
,
2422 fdlist
+d
, offsets
+d
,
2430 /* lastly, check that the internal stripe cache is
2431 * large enough, or it won't work.
2432 * It must hold at least 4 stripes of the larger
2435 cache
= max(info
->array
.chunk_size
, info
->new_chunk
);
2436 cache
*= 4; /* 4 stripes minimum */
2437 cache
/= 512; /* convert to sectors */
2438 disks
= min(reshape
.before
.data_disks
, reshape
.after
.data_disks
);
2439 /* make sure there is room for 'blocks' with a bit to spare */
2440 if (cache
< 16 + blocks
/ disks
)
2441 cache
= 16 + blocks
/ disks
;
2442 cache
/= (4096/512); /* Covert from sectors to pages */
2444 if (sra
->cache_size
< cache
)
2445 subarray_set_num(container
, sra
, "stripe_cache_size",
2448 /* Right, everything seems fine. Let's kick things off.
2449 * If only changing raid_disks, use ioctl, else use
2454 sra
->new_chunk
= info
->new_chunk
;
2457 /* for external metadata checkpoint saved by mdmon can be lost
2458 * or missed /due to e.g. crash/. Check if md is not during
2459 * restart farther than metadata points to.
2460 * If so, this means metadata information is obsolete.
2462 if (st
->ss
->external
)
2463 verify_reshape_position(info
, reshape
.level
);
2464 sra
->reshape_progress
= info
->reshape_progress
;
2466 sra
->reshape_progress
= 0;
2467 if (reshape
.after
.data_disks
< reshape
.before
.data_disks
)
2468 /* start from the end of the new array */
2469 sra
->reshape_progress
= (sra
->component_size
2470 * reshape
.after
.data_disks
);
2473 if (info
->array
.chunk_size
== info
->new_chunk
&&
2474 reshape
.before
.layout
== reshape
.after
.layout
&&
2475 st
->ss
->external
== 0) {
2476 /* use SET_ARRAY_INFO but only if reshape hasn't started */
2477 ioctl(fd
, GET_ARRAY_INFO
, &array
);
2478 array
.raid_disks
= reshape
.after
.data_disks
+ reshape
.parity
;
2480 ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2484 Name
": Cannot set device shape for %s: %s\n",
2485 devname
, strerror(errno
));
2488 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2490 " Bitmap must be removed before"
2491 " shape can be changed\n");
2495 } else if (!restart
) {
2496 /* set them all just in case some old 'new_*' value
2497 * persists from some earlier problem.
2500 if (sysfs_set_num(sra
, NULL
, "chunk_size", info
->new_chunk
) < 0)
2502 if (!err
&& sysfs_set_num(sra
, NULL
, "layout",
2503 reshape
.after
.layout
) < 0)
2505 if (!err
&& subarray_set_num(container
, sra
, "raid_disks",
2506 reshape
.after
.data_disks
+
2507 reshape
.parity
) < 0)
2510 fprintf(stderr
, Name
": Cannot set device shape for %s\n",
2514 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2516 " Bitmap must be removed before"
2517 " shape can be changed\n");
2522 err
= start_reshape(sra
, restart
, reshape
.before
.data_disks
,
2523 reshape
.after
.data_disks
);
2526 Name
": Cannot %s reshape for %s\n",
2527 restart
? "continue" : "start",
2532 sysfs_set_str(sra
, NULL
, "array_state", "active");
2533 if (freeze_reshape
) {
2537 fprintf(stderr
, Name
": Reshape has to be continued from"
2538 " location %llu when root filesystem has been mounted.\n",
2539 sra
->reshape_progress
);
2543 /* Now we just need to kick off the reshape and watch, while
2544 * handling backups of the data...
2545 * This is all done by a forked background process.
2547 switch(forked
? 0 : fork()) {
2549 fprintf(stderr
, Name
": Cannot run child to monitor reshape: %s\n",
2564 if (check_env("MDADM_GROW_VERIFY"))
2565 fd
= open(devname
, O_RDONLY
| O_DIRECT
);
2568 mlockall(MCL_FUTURE
);
2570 if (st
->ss
->external
) {
2571 /* metadata handler takes it from here */
2572 done
= st
->ss
->manage_reshape(
2573 fd
, sra
, &reshape
, st
, blocks
,
2575 d
- odisks
, fdlist
+odisks
,
2578 done
= child_monitor(
2579 fd
, sra
, &reshape
, st
, blocks
,
2581 d
- odisks
, fdlist
+odisks
,
2587 if (backup_file
&& done
)
2588 unlink(backup_file
);
2594 if (!st
->ss
->external
&&
2595 !(reshape
.before
.data_disks
!= reshape
.after
.data_disks
2596 && info
->custom_array_size
) &&
2597 info
->new_level
== reshape
.level
&&
2599 /* no need to wait for the reshape to finish as
2600 * there is nothing more to do.
2607 if (st
->ss
->external
) {
2608 /* Re-load the metadata as much could have changed */
2609 int cfd
= open_dev(st
->container_dev
);
2611 flush_mdmon(container
);
2612 st
->ss
->free_super(st
);
2613 st
->ss
->load_container(st
, cfd
, container
);
2618 /* set new array size if required customer_array_size is used
2621 if (reshape
.before
.data_disks
!=
2622 reshape
.after
.data_disks
&&
2623 info
->custom_array_size
)
2624 set_array_size(st
, info
, info
->text_version
);
2626 if (info
->new_level
!= reshape
.level
) {
2628 c
= map_num(pers
, info
->new_level
);
2630 err
= sysfs_set_str(sra
, NULL
, "level", c
);
2632 fprintf(stderr
, Name\
2633 ": %s: could not set level "
2634 "to %s\n", devname
, c
);
2636 if (info
->new_level
== 0)
2637 st
->update_tail
= NULL
;
2649 if (orig_level
!= UnSet
&& sra
) {
2650 c
= map_num(pers
, orig_level
);
2651 if (c
&& sysfs_set_str(sra
, NULL
, "level", c
) == 0)
2652 fprintf(stderr
, Name
": aborting level change\n");
2660 /* mdfd handle is passed to be closed in child process (after fork).
2662 int reshape_container(char *container
, char *devname
,
2664 struct supertype
*st
,
2665 struct mdinfo
*info
,
2668 int quiet
, int restart
, int freeze_reshape
)
2670 struct mdinfo
*cc
= NULL
;
2672 int last_devnum
= -1;
2674 /* component_size is not meaningful for a container,
2675 * so pass '-1' meaning 'no change'
2678 reshape_super(st
, -1, info
->new_level
,
2679 info
->new_layout
, info
->new_chunk
,
2680 info
->array
.raid_disks
, info
->delta_disks
,
2681 backup_file
, devname
, APPLY_METADATA_CHANGES
,
2689 /* ping monitor to be sure that update is on disk
2691 ping_monitor(container
);
2694 case -1: /* error */
2695 perror("Cannot fork to complete reshape\n");
2698 default: /* parent */
2699 if (!freeze_reshape
)
2700 printf(Name
": multi-array reshape continues"
2701 " in background\n");
2708 /* close unused handle in child process
2714 /* For each member array with reshape_active,
2715 * we need to perform the reshape.
2716 * We pick the first array that needs reshaping and
2717 * reshape it. reshape_array() will re-read the metadata
2718 * so the next time through a different array should be
2719 * ready for reshape.
2720 * It is possible that the 'different' array will not
2721 * be assembled yet. In that case we simple exit.
2722 * When it is assembled, the mdadm which assembles it
2723 * will take over the reshape.
2725 struct mdinfo
*content
;
2727 struct mdstat_ent
*mdstat
;
2732 cc
= st
->ss
->container_content(st
, NULL
);
2734 for (content
= cc
; content
; content
= content
->next
) {
2736 if (!content
->reshape_active
)
2739 subarray
= strchr(content
->text_version
+1, '/')+1;
2740 mdstat
= mdstat_by_subdev(subarray
,
2741 devname2devnum(container
));
2744 if (mdstat
->active
== 0) {
2745 fprintf(stderr
, Name
": Skipping inactive "
2746 "array md%i.\n", mdstat
->devnum
);
2747 free_mdstat(mdstat
);
2756 adev
= map_dev(dev2major(mdstat
->devnum
),
2757 dev2minor(mdstat
->devnum
),
2760 adev
= content
->text_version
;
2762 fd
= open_dev(mdstat
->devnum
);
2764 printf(Name
": Device %s cannot be opened for reshape.",
2769 if (last_devnum
== mdstat
->devnum
) {
2770 /* Do not allow for multiple reshape_array() calls for
2772 * It can happen when reshape_array() returns without
2773 * error, when reshape is not finished (wrong reshape
2774 * starting/continuation conditions). Mdmon doesn't
2775 * switch to next array in container and reentry
2776 * conditions for the same array occur.
2777 * This is possibly interim until the behaviour of
2778 * reshape_array is resolved().
2780 printf(Name
": Multiple reshape execution detected for "
2781 "device %s.", adev
);
2785 last_devnum
= mdstat
->devnum
;
2787 sysfs_init(content
, fd
, mdstat
->devnum
);
2789 if (mdmon_running(devname2devnum(container
)))
2790 flush_mdmon(container
);
2792 rv
= reshape_array(container
, fd
, adev
, st
,
2793 content
, force
, NULL
,
2794 backup_file
, quiet
, 1, restart
,
2798 if (freeze_reshape
) {
2807 if (mdmon_running(devname2devnum(container
)))
2808 flush_mdmon(container
);
2817 * We run a child process in the background which performs the following
2819 * - wait for resync to reach a certain point
2820 * - suspend io to the following section
2821 * - backup that section
2822 * - allow resync to proceed further
2824 * - discard the backup.
2826 * When are combined in slightly different ways in the three cases.
2828 * - suspend/backup/allow/wait/resume/discard
2830 * - allow/wait/suspend/backup/allow/wait/resume/discard
2832 * - wait/resume/discard/suspend/backup/allow
2834 * suspend/backup/allow always come together
2835 * wait/resume/discard do too.
2836 * For the same-size case we have two backups to improve flow.
2840 int progress_reshape(struct mdinfo
*info
, struct reshape
*reshape
,
2841 unsigned long long backup_point
,
2842 unsigned long long wait_point
,
2843 unsigned long long *suspend_point
,
2844 unsigned long long *reshape_completed
)
2846 /* This function is called repeatedly by the reshape manager.
2847 * It determines how much progress can safely be made and allows
2849 * - 'info' identifies the array and particularly records in
2850 * ->reshape_progress the metadata's knowledge of progress
2851 * This is a sector offset from the start of the array
2852 * of the next array block to be relocated. This number
2853 * may increase from 0 or decrease from array_size, depending
2854 * on the type of reshape that is happening.
2855 * Note that in contrast, 'sync_completed' is a block count of the
2856 * reshape so far. It gives the distance between the start point
2857 * (head or tail of device) and the next place that data will be
2858 * written. It always increases.
2859 * - 'reshape' is the structure created by analyse_change
2860 * - 'backup_point' shows how much the metadata manager has backed-up
2861 * data. For reshapes with increasing progress, it is the next address
2862 * to be backed up, previous addresses have been backed-up. For
2863 * decreasing progress, it is the earliest address that has been
2864 * backed up - later address are also backed up.
2865 * So addresses between reshape_progress and backup_point are
2866 * backed up providing those are in the 'correct' order.
2867 * - 'wait_point' is an array address. When reshape_completed
2868 * passes this point, progress_reshape should return. It might
2869 * return earlier if it determines that ->reshape_progress needs
2870 * to be updated or further backup is needed.
2871 * - suspend_point is maintained by progress_reshape and the caller
2872 * should not touch it except to initialise to zero.
2873 * It is an array address and it only increases in 2.6.37 and earlier.
2874 * This makes it difficult to handle reducing reshapes with
2875 * external metadata.
2876 * However: it is similar to backup_point in that it records the
2877 * other end of a suspended region from reshape_progress.
2878 * it is moved to extend the region that is safe to backup and/or
2880 * - reshape_completed is read from sysfs and returned. The caller
2881 * should copy this into ->reshape_progress when it has reason to
2882 * believe that the metadata knows this, and any backup outside this
2886 * 1 if more data from backup_point - but only as far as suspend_point,
2887 * should be backed up
2888 * 0 if things are progressing smoothly
2889 * -1 if the reshape is finished because it is all done,
2890 * -2 if the reshape is finished due to an error.
2893 int advancing
= (reshape
->after
.data_disks
2894 >= reshape
->before
.data_disks
);
2895 unsigned long long need_backup
; /* All data between start of array and
2896 * here will at some point need to
2899 unsigned long long read_offset
, write_offset
;
2900 unsigned long long write_range
;
2901 unsigned long long max_progress
, target
, completed
;
2902 unsigned long long array_size
= (info
->component_size
2903 * reshape
->before
.data_disks
);
2907 /* First, we unsuspend any region that is now known to be safe.
2908 * If suspend_point is on the 'wrong' side of reshape_progress, then
2909 * we don't have or need suspension at the moment. This is true for
2910 * native metadata when we don't need to back-up.
2913 if (info
->reshape_progress
<= *suspend_point
)
2914 sysfs_set_num(info
, NULL
, "suspend_lo",
2915 info
->reshape_progress
);
2917 /* Note: this won't work in 2.6.37 and before.
2918 * Something somewhere should make sure we don't need it!
2920 if (info
->reshape_progress
>= *suspend_point
)
2921 sysfs_set_num(info
, NULL
, "suspend_hi",
2922 info
->reshape_progress
);
2925 /* Now work out how far it is safe to progress.
2926 * If the read_offset for ->reshape_progress is less than
2927 * 'blocks' beyond the write_offset, we can only progress as far
2929 * Otherwise we can progress until the write_offset for the new location
2930 * reaches (within 'blocks' of) the read_offset at the current location.
2931 * However that region must be suspended unless we are using native
2933 * If we need to suspend more, we limit it to 128M per device, which is
2934 * rather arbitrary and should be some time-based calculation.
2936 read_offset
= info
->reshape_progress
/ reshape
->before
.data_disks
;
2937 write_offset
= info
->reshape_progress
/ reshape
->after
.data_disks
;
2938 write_range
= info
->new_chunk
/512;
2939 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
)
2940 need_backup
= array_size
;
2942 need_backup
= reshape
->backup_blocks
;
2944 if (read_offset
< write_offset
+ write_range
)
2945 max_progress
= backup_point
;
2949 reshape
->after
.data_disks
;
2951 if (read_offset
> write_offset
- write_range
)
2952 /* Can only progress as far as has been backed up,
2953 * which must be suspended */
2954 max_progress
= backup_point
;
2955 else if (info
->reshape_progress
<= need_backup
)
2956 max_progress
= backup_point
;
2958 if (info
->array
.major_version
>= 0)
2959 /* Can progress until backup is needed */
2960 max_progress
= need_backup
;
2962 /* Can progress until metadata update is required */
2965 reshape
->after
.data_disks
;
2966 /* but data must be suspended */
2967 if (max_progress
< *suspend_point
)
2968 max_progress
= *suspend_point
;
2973 /* We know it is safe to progress to 'max_progress' providing
2974 * it is suspended or we are using native metadata.
2975 * Consider extending suspend_point 128M per device if it
2976 * is less than 64M per device beyond reshape_progress.
2977 * But always do a multiple of 'blocks'
2978 * FIXME this is too big - it takes to long to complete
2981 target
= 64*1024*2 * min(reshape
->before
.data_disks
,
2982 reshape
->after
.data_disks
);
2983 target
/= reshape
->backup_blocks
;
2986 target
*= reshape
->backup_blocks
;
2988 /* For externally managed metadata we always need to suspend IO to
2989 * the area being reshaped so we regularly push suspend_point forward.
2990 * For native metadata we only need the suspend if we are going to do
2994 if ((need_backup
> info
->reshape_progress
2995 || info
->array
.major_version
< 0) &&
2996 *suspend_point
< info
->reshape_progress
+ target
) {
2997 if (need_backup
< *suspend_point
+ 2 * target
)
2998 *suspend_point
= need_backup
;
2999 else if (*suspend_point
+ 2 * target
< array_size
)
3000 *suspend_point
+= 2 * target
;
3002 *suspend_point
= array_size
;
3003 sysfs_set_num(info
, NULL
, "suspend_hi", *suspend_point
);
3004 if (max_progress
> *suspend_point
)
3005 max_progress
= *suspend_point
;
3008 if (info
->array
.major_version
>= 0) {
3009 /* Only need to suspend when about to backup */
3010 if (info
->reshape_progress
< need_backup
* 2 &&
3011 *suspend_point
> 0) {
3013 sysfs_set_num(info
, NULL
, "suspend_lo", 0);
3014 sysfs_set_num(info
, NULL
, "suspend_hi", need_backup
);
3017 /* Need to suspend continually */
3018 if (info
->reshape_progress
< *suspend_point
)
3019 *suspend_point
= info
->reshape_progress
;
3020 if (*suspend_point
+ target
< info
->reshape_progress
)
3021 /* No need to move suspend region yet */;
3023 if (*suspend_point
>= 2 * target
)
3024 *suspend_point
-= 2 * target
;
3027 sysfs_set_num(info
, NULL
, "suspend_lo",
3030 if (max_progress
< *suspend_point
)
3031 max_progress
= *suspend_point
;
3035 /* now set sync_max to allow that progress. sync_max, like
3036 * sync_completed is a count of sectors written per device, so
3037 * we find the difference between max_progress and the start point,
3038 * and divide that by after.data_disks to get a sync_max
3040 * At the same time we convert wait_point to a similar number
3041 * for comparing against sync_completed.
3043 /* scale down max_progress to per_disk */
3044 max_progress
/= reshape
->after
.data_disks
;
3045 /* Round to chunk size as some kernels give an erroneously high number */
3046 max_progress
/= info
->new_chunk
/512;
3047 max_progress
*= info
->new_chunk
/512;
3048 /* And round to old chunk size as the kernel wants that */
3049 max_progress
/= info
->array
.chunk_size
/512;
3050 max_progress
*= info
->array
.chunk_size
/512;
3051 /* Limit progress to the whole device */
3052 if (max_progress
> info
->component_size
)
3053 max_progress
= info
->component_size
;
3054 wait_point
/= reshape
->after
.data_disks
;
3056 /* switch from 'device offset' to 'processed block count' */
3057 max_progress
= info
->component_size
- max_progress
;
3058 wait_point
= info
->component_size
- wait_point
;
3061 sysfs_set_num(info
, NULL
, "sync_max", max_progress
);
3063 /* Now wait. If we have already reached the point that we were
3064 * asked to wait to, don't wait at all, else wait for any change.
3065 * We need to select on 'sync_completed' as that is the place that
3066 * notifications happen, but we are really interested in
3067 * 'reshape_position'
3069 fd
= sysfs_get_fd(info
, NULL
, "sync_completed");
3071 goto check_progress
;
3073 if (sysfs_fd_get_ll(fd
, &completed
) < 0)
3074 goto check_progress
;
3076 while (completed
< max_progress
&& completed
< wait_point
) {
3077 /* Check that sync_action is still 'reshape' to avoid
3078 * waiting forever on a dead array
3082 if (sysfs_get_str(info
, NULL
, "sync_action",
3084 strncmp(action
, "reshape", 7) != 0)
3086 /* Some kernels reset 'sync_completed' to zero
3087 * before setting 'sync_action' to 'idle'.
3088 * So we need these extra tests.
3090 if (completed
== 0 && advancing
3091 && info
->reshape_progress
> 0)
3093 if (completed
== 0 && !advancing
3094 && info
->reshape_progress
< (info
->component_size
3095 * reshape
->after
.data_disks
))
3099 select(fd
+1, NULL
, NULL
, &rfds
, NULL
);
3100 if (sysfs_fd_get_ll(fd
, &completed
) < 0)
3101 goto check_progress
;
3103 /* Some kernels reset 'sync_completed' to zero,
3104 * we need to have real point we are in md
3107 completed
= max_progress
;
3109 /* some kernels can give an incorrectly high 'completed' number */
3110 completed
/= (info
->new_chunk
/512);
3111 completed
*= (info
->new_chunk
/512);
3112 /* Convert 'completed' back in to a 'progress' number */
3113 completed
*= reshape
->after
.data_disks
;
3115 completed
= info
->component_size
* reshape
->after
.data_disks
3118 *reshape_completed
= completed
;
3122 /* We return the need_backup flag. Caller will decide
3123 * how much - a multiple of ->backup_blocks up to *suspend_point
3126 return need_backup
> info
->reshape_progress
;
3128 return need_backup
>= info
->reshape_progress
;
3131 /* if we couldn't read a number from sync_completed, then
3132 * either the reshape did complete, or it aborted.
3133 * We can tell which by checking for 'none' in reshape_position.
3134 * If it did abort, then it might immediately restart if it
3135 * it was just a device failure that leaves us degraded but
3139 if (sysfs_get_str(info
, NULL
, "reshape_position", buf
, sizeof(buf
)) < 0
3140 || strncmp(buf
, "none", 4) != 0) {
3141 /* The abort might only be temporary. Wait up to 10
3142 * seconds for fd to contain a valid number again.
3148 while (fd
>= 0 && rv
< 0 && tv
.tv_sec
> 0) {
3152 if (select(fd
+1, NULL
, NULL
, &rfds
, &tv
) != 1)
3154 switch (sysfs_fd_get_ll(fd
, &completed
)) {
3156 /* all good again */
3159 case -2: /* read error - abort */
3166 return rv
; /* abort */
3168 /* Maybe racing with array shutdown - check state */
3171 if (sysfs_get_str(info
, NULL
, "array_state", buf
, sizeof(buf
)) < 0
3172 || strncmp(buf
, "inactive", 8) == 0
3173 || strncmp(buf
, "clear",5) == 0)
3174 return -2; /* abort */
3175 return -1; /* complete */
3179 /* FIXME return status is never checked */
3180 static int grow_backup(struct mdinfo
*sra
,
3181 unsigned long long offset
, /* per device */
3182 unsigned long stripes
, /* per device, in old chunks */
3183 int *sources
, unsigned long long *offsets
,
3184 int disks
, int chunk
, int level
, int layout
,
3185 int dests
, int *destfd
, unsigned long long *destoffsets
,
3186 int part
, int *degraded
,
3189 /* Backup 'blocks' sectors at 'offset' on each device of the array,
3190 * to storage 'destfd' (offset 'destoffsets'), after first
3191 * suspending IO. Then allow resync to continue
3192 * over the suspended section.
3193 * Use part 'part' of the backup-super-block.
3198 unsigned long long ll
;
3200 //printf("offset %llu\n", offset);
3206 /* Check that array hasn't become degraded, else we might backup the wrong data */
3207 if (sysfs_get_ll(sra
, NULL
, "degraded", &ll
) < 0)
3208 return -1; /* FIXME this error is ignored */
3209 new_degraded
= (int)ll
;
3210 if (new_degraded
!= *degraded
) {
3211 /* check each device to ensure it is still working */
3213 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
3214 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
3216 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
3218 if (sysfs_get_str(sra
, sd
, "state", sbuf
, 20) < 0 ||
3219 strstr(sbuf
, "faulty") ||
3220 strstr(sbuf
, "in_sync") == NULL
) {
3221 /* this device is dead */
3222 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
3223 if (sd
->disk
.raid_disk
>= 0 &&
3224 sources
[sd
->disk
.raid_disk
] >= 0) {
3225 close(sources
[sd
->disk
.raid_disk
]);
3226 sources
[sd
->disk
.raid_disk
] = -1;
3231 *degraded
= new_degraded
;
3234 bsb
.arraystart2
= __cpu_to_le64(offset
* odata
);
3235 bsb
.length2
= __cpu_to_le64(stripes
* (chunk
/512) * odata
);
3237 bsb
.arraystart
= __cpu_to_le64(offset
* odata
);
3238 bsb
.length
= __cpu_to_le64(stripes
* (chunk
/512) * odata
);
3241 bsb
.magic
[15] = '2';
3242 for (i
= 0; i
< dests
; i
++)
3244 lseek64(destfd
[i
], destoffsets
[i
] + __le64_to_cpu(bsb
.devstart2
)*512, 0);
3246 lseek64(destfd
[i
], destoffsets
[i
], 0);
3248 rv
= save_stripes(sources
, offsets
,
3249 disks
, chunk
, level
, layout
,
3251 offset
*512*odata
, stripes
* chunk
* odata
,
3256 bsb
.mtime
= __cpu_to_le64(time(0));
3257 for (i
= 0; i
< dests
; i
++) {
3258 bsb
.devstart
= __cpu_to_le64(destoffsets
[i
]/512);
3260 bsb
.sb_csum
= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
));
3261 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0)
3262 bsb
.sb_csum2
= bsb_csum((char*)&bsb
,
3263 ((char*)&bsb
.sb_csum2
)-((char*)&bsb
));
3266 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
] - 4096, 0)
3267 != destoffsets
[i
] - 4096)
3269 if (write(destfd
[i
], &bsb
, 512) != 512)
3271 if (destoffsets
[i
] > 4096) {
3272 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
]+stripes
*chunk
*odata
, 0) !=
3273 destoffsets
[i
]+stripes
*chunk
*odata
)
3275 if (write(destfd
[i
], &bsb
, 512) != 512)
3285 /* in 2.6.30, the value reported by sync_completed can be
3286 * less that it should be by one stripe.
3287 * This only happens when reshape hits sync_max and pauses.
3288 * So allow wait_backup to either extent sync_max further
3289 * than strictly necessary, or return before the
3290 * sync has got quite as far as we would really like.
3291 * This is what 'blocks2' is for.
3292 * The various caller give appropriate values so that
3295 /* FIXME return value is often ignored */
3296 static int forget_backup(int dests
, int *destfd
,
3297 unsigned long long *destoffsets
,
3301 * Erase backup 'part' (which is 0 or 1)
3307 bsb
.arraystart2
= __cpu_to_le64(0);
3308 bsb
.length2
= __cpu_to_le64(0);
3310 bsb
.arraystart
= __cpu_to_le64(0);
3311 bsb
.length
= __cpu_to_le64(0);
3313 bsb
.mtime
= __cpu_to_le64(time(0));
3315 for (i
= 0; i
< dests
; i
++) {
3316 bsb
.devstart
= __cpu_to_le64(destoffsets
[i
]/512);
3317 bsb
.sb_csum
= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
));
3318 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0)
3319 bsb
.sb_csum2
= bsb_csum((char*)&bsb
,
3320 ((char*)&bsb
.sb_csum2
)-((char*)&bsb
));
3321 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
]-4096, 0) !=
3322 destoffsets
[i
]-4096)
3325 write(destfd
[i
], &bsb
, 512) != 512)
3332 static void fail(char *msg
)
3335 rv
= (write(2, msg
, strlen(msg
)) != (int)strlen(msg
));
3336 rv
|= (write(2, "\n", 1) != 1);
3340 static char *abuf
, *bbuf
;
3341 static unsigned long long abuflen
;
3342 static void validate(int afd
, int bfd
, unsigned long long offset
)
3344 /* check that the data in the backup against the array.
3345 * This is only used for regression testing and should not
3346 * be used while the array is active
3350 lseek64(bfd
, offset
- 4096, 0);
3351 if (read(bfd
, &bsb2
, 512) != 512)
3352 fail("cannot read bsb");
3353 if (bsb2
.sb_csum
!= bsb_csum((char*)&bsb2
,
3354 ((char*)&bsb2
.sb_csum
)-((char*)&bsb2
)))
3355 fail("first csum bad");
3356 if (memcmp(bsb2
.magic
, "md_backup_data", 14) != 0)
3357 fail("magic is bad");
3358 if (memcmp(bsb2
.magic
, "md_backup_data-2", 16) == 0 &&
3359 bsb2
.sb_csum2
!= bsb_csum((char*)&bsb2
,
3360 ((char*)&bsb2
.sb_csum2
)-((char*)&bsb2
)))
3361 fail("second csum bad");
3363 if (__le64_to_cpu(bsb2
.devstart
)*512 != offset
)
3364 fail("devstart is wrong");
3367 unsigned long long len
= __le64_to_cpu(bsb2
.length
)*512;
3369 if (abuflen
< len
) {
3373 if (posix_memalign((void**)&abuf
, 4096, abuflen
) ||
3374 posix_memalign((void**)&bbuf
, 4096, abuflen
)) {
3376 /* just stop validating on mem-alloc failure */
3381 lseek64(bfd
, offset
, 0);
3382 if ((unsigned long long)read(bfd
, bbuf
, len
) != len
) {
3383 //printf("len %llu\n", len);
3384 fail("read first backup failed");
3386 lseek64(afd
, __le64_to_cpu(bsb2
.arraystart
)*512, 0);
3387 if ((unsigned long long)read(afd
, abuf
, len
) != len
)
3388 fail("read first from array failed");
3389 if (memcmp(bbuf
, abuf
, len
) != 0) {
3392 printf("offset=%llu len=%llu\n",
3393 (unsigned long long)__le64_to_cpu(bsb2
.arraystart
)*512, len
);
3394 for (i
=0; i
<len
; i
++)
3395 if (bbuf
[i
] != abuf
[i
]) {
3396 printf("first diff byte %d\n", i
);
3400 fail("data1 compare failed");
3404 unsigned long long len
= __le64_to_cpu(bsb2
.length2
)*512;
3406 if (abuflen
< len
) {
3410 abuf
= malloc(abuflen
);
3411 bbuf
= malloc(abuflen
);
3414 lseek64(bfd
, offset
+__le64_to_cpu(bsb2
.devstart2
)*512, 0);
3415 if ((unsigned long long)read(bfd
, bbuf
, len
) != len
)
3416 fail("read second backup failed");
3417 lseek64(afd
, __le64_to_cpu(bsb2
.arraystart2
)*512, 0);
3418 if ((unsigned long long)read(afd
, abuf
, len
) != len
)
3419 fail("read second from array failed");
3420 if (memcmp(bbuf
, abuf
, len
) != 0)
3421 fail("data2 compare failed");
3425 int child_monitor(int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
3426 struct supertype
*st
, unsigned long blocks
,
3427 int *fds
, unsigned long long *offsets
,
3428 int dests
, int *destfd
, unsigned long long *destoffsets
)
3430 /* Monitor a reshape where backup is being performed using
3431 * 'native' mechanism - either to a backup file, or
3432 * to some space in a spare.
3436 unsigned long long speed
;
3437 unsigned long long suspend_point
, array_size
;
3438 unsigned long long backup_point
, wait_point
;
3439 unsigned long long reshape_completed
;
3441 int increasing
= reshape
->after
.data_disks
>= reshape
->before
.data_disks
;
3442 int part
= 0; /* The next part of the backup area to fill. It may already
3443 * be full, so we need to check */
3444 int level
= reshape
->level
;
3445 int layout
= reshape
->before
.layout
;
3446 int data
= reshape
->before
.data_disks
;
3447 int disks
= reshape
->before
.data_disks
+ reshape
->parity
;
3448 int chunk
= sra
->array
.chunk_size
;
3450 unsigned long stripes
;
3453 /* set up the backup-super-block. This requires the
3454 * uuid from the array.
3456 /* Find a superblock */
3457 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
3461 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
3463 dn
= map_dev(sd
->disk
.major
, sd
->disk
.minor
, 1);
3464 devfd
= dev_open(dn
, O_RDONLY
);
3467 ok
= st
->ss
->load_super(st
, devfd
, NULL
);
3473 fprintf(stderr
, Name
": Cannot find a superblock\n");
3477 memset(&bsb
, 0, 512);
3478 memcpy(bsb
.magic
, "md_backup_data-1", 16);
3479 st
->ss
->uuid_from_super(st
, uuid
);
3480 memcpy(bsb
.set_uuid
, uuid
, 16);
3481 bsb
.mtime
= __cpu_to_le64(time(0));
3482 bsb
.devstart2
= blocks
;
3484 stripes
= blocks
/ (sra
->array
.chunk_size
/512) /
3485 reshape
->before
.data_disks
;
3487 if (posix_memalign((void**)&buf
, 4096, disks
* chunk
))
3488 /* Don't start the 'reshape' */
3490 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
) {
3491 sysfs_get_ll(sra
, NULL
, "sync_speed_min", &speed
);
3492 sysfs_set_num(sra
, NULL
, "sync_speed_min", 200000);
3496 array_size
= sra
->component_size
* reshape
->after
.data_disks
;
3497 backup_point
= sra
->reshape_progress
;
3500 array_size
= sra
->component_size
* reshape
->before
.data_disks
;
3501 backup_point
= reshape
->backup_blocks
;
3502 suspend_point
= array_size
;
3508 /* Want to return as soon the oldest backup slot can
3509 * be released as that allows us to start backing up
3510 * some more, providing suspend_point has been
3511 * advanced, which it should have.
3514 wait_point
= array_size
;
3515 if (part
== 0 && __le64_to_cpu(bsb
.length
) > 0)
3516 wait_point
= (__le64_to_cpu(bsb
.arraystart
) +
3517 __le64_to_cpu(bsb
.length
));
3518 if (part
== 1 && __le64_to_cpu(bsb
.length2
) > 0)
3519 wait_point
= (__le64_to_cpu(bsb
.arraystart2
) +
3520 __le64_to_cpu(bsb
.length2
));
3523 if (part
== 0 && __le64_to_cpu(bsb
.length
) > 0)
3524 wait_point
= __le64_to_cpu(bsb
.arraystart
);
3525 if (part
== 1 && __le64_to_cpu(bsb
.length2
) > 0)
3526 wait_point
= __le64_to_cpu(bsb
.arraystart2
);
3529 rv
= progress_reshape(sra
, reshape
,
3530 backup_point
, wait_point
,
3531 &suspend_point
, &reshape_completed
);
3532 /* external metadata would need to ping_monitor here */
3533 sra
->reshape_progress
= reshape_completed
;
3535 /* Clear any backup region that is before 'here' */
3537 if (__le64_to_cpu(bsb
.length
) > 0 &&
3538 reshape_completed
>= (__le64_to_cpu(bsb
.arraystart
) +
3539 __le64_to_cpu(bsb
.length
)))
3540 forget_backup(dests
, destfd
,
3542 if (__le64_to_cpu(bsb
.length2
) > 0 &&
3543 reshape_completed
>= (__le64_to_cpu(bsb
.arraystart2
) +
3544 __le64_to_cpu(bsb
.length2
)))
3545 forget_backup(dests
, destfd
,
3548 if (__le64_to_cpu(bsb
.length
) > 0 &&
3549 reshape_completed
<= (__le64_to_cpu(bsb
.arraystart
)))
3550 forget_backup(dests
, destfd
,
3552 if (__le64_to_cpu(bsb
.length2
) > 0 &&
3553 reshape_completed
<= (__le64_to_cpu(bsb
.arraystart2
)))
3554 forget_backup(dests
, destfd
,
3563 if (rv
== 0 && increasing
&& !st
->ss
->external
) {
3564 /* No longer need to monitor this reshape */
3570 unsigned long long offset
;
3571 unsigned long actual_stripes
;
3572 /* Need to backup some data.
3573 * If 'part' is not used and the desired
3574 * backup size is suspended, do a backup,
3575 * then consider the next part.
3577 /* Check that 'part' is unused */
3578 if (part
== 0 && __le64_to_cpu(bsb
.length
) != 0)
3580 if (part
== 1 && __le64_to_cpu(bsb
.length2
) != 0)
3583 offset
= backup_point
/ data
;
3584 actual_stripes
= stripes
;
3586 if (offset
+ actual_stripes
* (chunk
/512) >
3587 sra
->component_size
)
3588 actual_stripes
= ((sra
->component_size
- offset
)
3590 if (offset
+ actual_stripes
* (chunk
/512) >
3594 if (offset
< actual_stripes
* (chunk
/512))
3595 actual_stripes
= offset
/ (chunk
/512);
3596 offset
-= actual_stripes
* (chunk
/512);
3597 if (offset
< suspend_point
/data
)
3600 if (actual_stripes
== 0)
3602 grow_backup(sra
, offset
, actual_stripes
,
3604 disks
, chunk
, level
, layout
,
3605 dests
, destfd
, destoffsets
,
3606 part
, °raded
, buf
);
3607 validate(afd
, destfd
[0], destoffsets
[0]);
3608 /* record where 'part' is up to */
3611 backup_point
+= actual_stripes
* (chunk
/512) * data
;
3613 backup_point
-= actual_stripes
* (chunk
/512) * data
;
3617 /* FIXME maybe call progress_reshape one more time instead */
3618 abort_reshape(sra
); /* remove any remaining suspension */
3619 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
)
3620 sysfs_set_num(sra
, NULL
, "sync_speed_min", speed
);
3626 * If any spare contains md_back_data-1 which is recent wrt mtime,
3627 * write that data into the array and update the super blocks with
3628 * the new reshape_progress
3630 int Grow_restart(struct supertype
*st
, struct mdinfo
*info
, int *fdlist
, int cnt
,
3631 char *backup_file
, int verbose
)
3635 unsigned long long *offsets
;
3636 unsigned long long nstripe
, ostripe
;
3639 odata
= info
->array
.raid_disks
- info
->delta_disks
- 1;
3640 if (info
->array
.level
== 6) odata
--; /* number of data disks */
3641 ndata
= info
->array
.raid_disks
- 1;
3642 if (info
->new_level
== 6) ndata
--;
3644 old_disks
= info
->array
.raid_disks
- info
->delta_disks
;
3646 if (info
->delta_disks
<= 0)
3647 /* Didn't grow, so the backup file must have
3651 for (i
=old_disks
-(backup_file
?1:0); i
<cnt
; i
++) {
3652 struct mdinfo dinfo
;
3655 char *devname
, namebuf
[20];
3656 unsigned long long lo
, hi
;
3658 /* This was a spare and may have some saved data on it.
3659 * Load the superblock, find and load the
3660 * backup_super_block.
3661 * If either fail, go on to next device.
3662 * If the backup contains no new info, just return
3663 * else restore data and update all superblocks
3665 if (i
== old_disks
-1) {
3666 fd
= open(backup_file
, O_RDONLY
);
3668 fprintf(stderr
, Name
": backup file %s inaccessible: %s\n",
3669 backup_file
, strerror(errno
));
3672 devname
= backup_file
;
3677 if (st
->ss
->load_super(st
, fd
, NULL
))
3680 st
->ss
->getinfo_super(st
, &dinfo
, NULL
);
3681 st
->ss
->free_super(st
);
3684 (dinfo
.data_offset
+ dinfo
.component_size
- 8) <<9,
3686 fprintf(stderr
, Name
": Cannot seek on device %d\n", i
);
3687 continue; /* Cannot seek */
3689 sprintf(namebuf
, "device-%d", i
);
3692 if (read(fd
, &bsb
, sizeof(bsb
)) != sizeof(bsb
)) {
3694 fprintf(stderr
, Name
": Cannot read from %s\n", devname
);
3695 continue; /* Cannot read */
3697 if (memcmp(bsb
.magic
, "md_backup_data-1", 16) != 0 &&
3698 memcmp(bsb
.magic
, "md_backup_data-2", 16) != 0) {
3700 fprintf(stderr
, Name
": No backup metadata on %s\n", devname
);
3703 if (bsb
.sb_csum
!= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
))) {
3705 fprintf(stderr
, Name
": Bad backup-metadata checksum on %s\n", devname
);
3706 continue; /* bad checksum */
3708 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0 &&
3709 bsb
.sb_csum2
!= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum2
)-((char*)&bsb
))) {
3711 fprintf(stderr
, Name
": Bad backup-metadata checksum2 on %s\n", devname
);
3712 continue; /* Bad second checksum */
3714 if (memcmp(bsb
.set_uuid
,info
->uuid
, 16) != 0) {
3716 fprintf(stderr
, Name
": Wrong uuid on backup-metadata on %s\n", devname
);
3717 continue; /* Wrong uuid */
3720 /* array utime and backup-mtime should be updated at much the same time, but it seems that
3721 * sometimes they aren't... So allow considerable flexability in matching, and allow
3722 * this test to be overridden by an environment variable.
3724 if (info
->array
.utime
> (int)__le64_to_cpu(bsb
.mtime
) + 2*60*60 ||
3725 info
->array
.utime
< (int)__le64_to_cpu(bsb
.mtime
) - 10*60) {
3726 if (check_env("MDADM_GROW_ALLOW_OLD")) {
3727 fprintf(stderr
, Name
": accepting backup with timestamp %lu "
3728 "for array with timestamp %lu\n",
3729 (unsigned long)__le64_to_cpu(bsb
.mtime
),
3730 (unsigned long)info
->array
.utime
);
3733 fprintf(stderr
, Name
": too-old timestamp on "
3734 "backup-metadata on %s\n", devname
);
3735 continue; /* time stamp is too bad */
3739 if (bsb
.magic
[15] == '1') {
3740 if (bsb
.length
== 0)
3742 if (info
->delta_disks
>= 0) {
3743 /* reshape_progress is increasing */
3744 if (__le64_to_cpu(bsb
.arraystart
)
3745 + __le64_to_cpu(bsb
.length
)
3746 < info
->reshape_progress
) {
3749 fprintf(stderr
, Name
3750 ": backup-metadata found on %s but is not needed\n", devname
);
3751 continue; /* No new data here */
3754 /* reshape_progress is decreasing */
3755 if (__le64_to_cpu(bsb
.arraystart
) >=
3756 info
->reshape_progress
)
3757 goto nonew
; /* No new data here */
3760 if (bsb
.length
== 0 && bsb
.length2
== 0)
3762 if (info
->delta_disks
>= 0) {
3763 /* reshape_progress is increasing */
3764 if ((__le64_to_cpu(bsb
.arraystart
)
3765 + __le64_to_cpu(bsb
.length
)
3766 < info
->reshape_progress
)
3768 (__le64_to_cpu(bsb
.arraystart2
)
3769 + __le64_to_cpu(bsb
.length2
)
3770 < info
->reshape_progress
))
3771 goto nonew
; /* No new data here */
3773 /* reshape_progress is decreasing */
3774 if (__le64_to_cpu(bsb
.arraystart
) >=
3775 info
->reshape_progress
&&
3776 __le64_to_cpu(bsb
.arraystart2
) >=
3777 info
->reshape_progress
)
3778 goto nonew
; /* No new data here */
3781 if (lseek64(fd
, __le64_to_cpu(bsb
.devstart
)*512, 0)< 0) {
3784 fprintf(stderr
, Name
3785 ": Failed to verify secondary backup-metadata block on %s\n",
3787 continue; /* Cannot seek */
3789 /* There should be a duplicate backup superblock 4k before here */
3790 if (lseek64(fd
, -4096, 1) < 0 ||
3791 read(fd
, &bsb2
, sizeof(bsb2
)) != sizeof(bsb2
))
3792 goto second_fail
; /* Cannot find leading superblock */
3793 if (bsb
.magic
[15] == '1')
3794 bsbsize
= offsetof(struct mdp_backup_super
, pad1
);
3796 bsbsize
= offsetof(struct mdp_backup_super
, pad
);
3797 if (memcmp(&bsb2
, &bsb
, bsbsize
) != 0)
3798 goto second_fail
; /* Cannot find leading superblock */
3800 /* Now need the data offsets for all devices. */
3801 offsets
= malloc(sizeof(*offsets
)*info
->array
.raid_disks
);
3802 for(j
=0; j
<info
->array
.raid_disks
; j
++) {
3805 if (st
->ss
->load_super(st
, fdlist
[j
], NULL
))
3806 /* FIXME should be this be an error */
3808 st
->ss
->getinfo_super(st
, &dinfo
, NULL
);
3809 st
->ss
->free_super(st
);
3810 offsets
[j
] = dinfo
.data_offset
* 512;
3812 printf(Name
": restoring critical section\n");
3814 if (restore_stripes(fdlist
, offsets
,
3815 info
->array
.raid_disks
,
3819 fd
, __le64_to_cpu(bsb
.devstart
)*512,
3820 __le64_to_cpu(bsb
.arraystart
)*512,
3821 __le64_to_cpu(bsb
.length
)*512, NULL
)) {
3822 /* didn't succeed, so giveup */
3824 fprintf(stderr
, Name
": Error restoring backup from %s\n",
3830 if (bsb
.magic
[15] == '2' &&
3831 restore_stripes(fdlist
, offsets
,
3832 info
->array
.raid_disks
,
3836 fd
, __le64_to_cpu(bsb
.devstart
)*512 +
3837 __le64_to_cpu(bsb
.devstart2
)*512,
3838 __le64_to_cpu(bsb
.arraystart2
)*512,
3839 __le64_to_cpu(bsb
.length2
)*512, NULL
)) {
3840 /* didn't succeed, so giveup */
3842 fprintf(stderr
, Name
": Error restoring second backup from %s\n",
3850 /* Ok, so the data is restored. Let's update those superblocks. */
3854 lo
= __le64_to_cpu(bsb
.arraystart
);
3855 hi
= lo
+ __le64_to_cpu(bsb
.length
);
3857 if (bsb
.magic
[15] == '2' && bsb
.length2
) {
3858 unsigned long long lo1
, hi1
;
3859 lo1
= __le64_to_cpu(bsb
.arraystart2
);
3860 hi1
= lo1
+ __le64_to_cpu(bsb
.length2
);
3864 } else if (lo
< lo1
)
3870 (info
->reshape_progress
< lo
||
3871 info
->reshape_progress
> hi
))
3872 /* backup does not affect reshape_progress*/ ;
3873 else if (info
->delta_disks
>= 0) {
3874 info
->reshape_progress
= __le64_to_cpu(bsb
.arraystart
) +
3875 __le64_to_cpu(bsb
.length
);
3876 if (bsb
.magic
[15] == '2') {
3877 unsigned long long p2
= __le64_to_cpu(bsb
.arraystart2
) +
3878 __le64_to_cpu(bsb
.length2
);
3879 if (p2
> info
->reshape_progress
)
3880 info
->reshape_progress
= p2
;
3883 info
->reshape_progress
= __le64_to_cpu(bsb
.arraystart
);
3884 if (bsb
.magic
[15] == '2') {
3885 unsigned long long p2
= __le64_to_cpu(bsb
.arraystart2
);
3886 if (p2
< info
->reshape_progress
)
3887 info
->reshape_progress
= p2
;
3890 for (j
=0; j
<info
->array
.raid_disks
; j
++) {
3891 if (fdlist
[j
] < 0) continue;
3892 if (st
->ss
->load_super(st
, fdlist
[j
], NULL
))
3894 st
->ss
->getinfo_super(st
, &dinfo
, NULL
);
3895 dinfo
.reshape_progress
= info
->reshape_progress
;
3896 st
->ss
->update_super(st
, &dinfo
,
3897 "_reshape_progress",
3899 st
->ss
->store_super(st
, fdlist
[j
]);
3900 st
->ss
->free_super(st
);
3904 /* Didn't find any backup data, try to see if any
3907 if (info
->delta_disks
< 0) {
3908 /* When shrinking, the critical section is at the end.
3909 * So see if we are before the critical section.
3911 unsigned long long first_block
;
3912 nstripe
= ostripe
= 0;
3914 while (ostripe
>= nstripe
) {
3915 ostripe
+= info
->array
.chunk_size
/ 512;
3916 first_block
= ostripe
* odata
;
3917 nstripe
= first_block
/ ndata
/ (info
->new_chunk
/512) *
3918 (info
->new_chunk
/512);
3921 if (info
->reshape_progress
>= first_block
)
3924 if (info
->delta_disks
> 0) {
3925 /* See if we are beyond the critical section. */
3926 unsigned long long last_block
;
3927 nstripe
= ostripe
= 0;
3929 while (nstripe
>= ostripe
) {
3930 nstripe
+= info
->new_chunk
/ 512;
3931 last_block
= nstripe
* ndata
;
3932 ostripe
= last_block
/ odata
/ (info
->array
.chunk_size
/512) *
3933 (info
->array
.chunk_size
/512);
3936 if (info
->reshape_progress
>= last_block
)
3939 /* needed to recover critical section! */
3941 fprintf(stderr
, Name
": Failed to find backup of critical section\n");
3945 int Grow_continue_command(char *devname
, int fd
,
3946 char *backup_file
, int verbose
)
3949 struct supertype
*st
= NULL
;
3950 struct mdinfo
*content
= NULL
;
3951 struct mdinfo array
;
3952 char *subarray
= NULL
;
3953 struct mdinfo
*cc
= NULL
;
3954 struct mdstat_ent
*mdstat
= NULL
;
3959 dprintf("Grow continue from command line called for %s\n",
3962 st
= super_by_fd(fd
, &subarray
);
3963 if (!st
|| !st
->ss
) {
3965 Name
": Unable to determine metadata format for %s\n",
3969 dprintf("Grow continue is run for ");
3970 if (st
->ss
->external
== 0) {
3971 dprintf("native array (%s)\n", devname
);
3972 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) < 0) {
3973 fprintf(stderr
, Name
": %s is not an active md array -"
3974 " aborting\n", devname
);
3976 goto Grow_continue_command_exit
;
3979 sysfs_init(content
, fd
, st
->devnum
);
3984 dprintf("subarray (%s)\n", subarray
);
3985 container_dev
= st
->container_dev
;
3986 cfd
= open_dev_excl(st
->container_dev
);
3988 container_dev
= st
->devnum
;
3990 cfd
= open_dev_excl(st
->devnum
);
3991 dprintf("container (%i)\n", container_dev
);
3995 fprintf(stderr
, Name
": Unable to open container "
3996 "for %s\n", devname
);
3998 goto Grow_continue_command_exit
;
4000 fmt_devname(buf
, container_dev
);
4002 /* find in container array under reshape
4004 ret_val
= st
->ss
->load_container(st
, cfd
, NULL
);
4007 Name
": Cannot read superblock for %s\n",
4010 goto Grow_continue_command_exit
;
4013 cc
= st
->ss
->container_content(st
, subarray
);
4014 for (content
= cc
; content
; content
= content
->next
) {
4016 int allow_reshape
= 1;
4018 if (content
->reshape_active
== 0)
4020 /* The decision about array or container wide
4021 * reshape is taken in Grow_continue based
4022 * content->reshape_active state, therefore we
4023 * need to check_reshape based on
4024 * reshape_active and subarray name
4026 if (content
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
))
4028 if (content
->reshape_active
== CONTAINER_RESHAPE
&&
4029 (content
->array
.state
4030 & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
)))
4033 if (!allow_reshape
) {
4034 fprintf(stderr
, Name
4035 ": cannot continue reshape of an array"
4036 " in container with unsupported"
4037 " metadata: %s(%s)\n",
4040 goto Grow_continue_command_exit
;
4043 array
= strchr(content
->text_version
+1, '/')+1;
4044 mdstat
= mdstat_by_subdev(array
, container_dev
);
4047 if (mdstat
->active
== 0) {
4048 fprintf(stderr
, Name
": Skipping inactive "
4049 "array md%i.\n", mdstat
->devnum
);
4050 free_mdstat(mdstat
);
4058 Name
": Unable to determine reshaped "
4059 "array for %s\n", devname
);
4061 goto Grow_continue_command_exit
;
4063 fd2
= open_dev(mdstat
->devnum
);
4065 fprintf(stderr
, Name
": cannot open (md%i)\n",
4068 goto Grow_continue_command_exit
;
4071 sysfs_init(content
, fd2
, mdstat
->devnum
);
4073 /* start mdmon in case it is not running
4075 if (!mdmon_running(container_dev
))
4076 start_mdmon(container_dev
);
4079 if (mdmon_running(container_dev
))
4080 st
->update_tail
= &st
->updates
;
4082 fprintf(stderr
, Name
": No mdmon found. "
4083 "Grow cannot continue.\n");
4085 goto Grow_continue_command_exit
;
4089 /* verify that array under reshape is started from
4092 if (verify_reshape_position(content
,
4093 map_name(pers
, mdstat
->level
)) < 0) {
4095 goto Grow_continue_command_exit
;
4100 ret_val
= Grow_continue(fd
, st
, content
, backup_file
, 0);
4102 Grow_continue_command_exit
:
4107 st
->ss
->free_super(st
);
4108 free_mdstat(mdstat
);
4115 int Grow_continue(int mdfd
, struct supertype
*st
, struct mdinfo
*info
,
4116 char *backup_file
, int freeze_reshape
)
4120 if (!info
->reshape_active
)
4123 if (st
->ss
->external
) {
4125 int cfd
= open_dev(st
->container_dev
);
4130 fmt_devname(container
, st
->container_dev
);
4131 st
->ss
->load_container(st
, cfd
, container
);
4133 ret_val
= reshape_container(container
, NULL
, mdfd
,
4134 st
, info
, 0, backup_file
,
4135 0, 1, freeze_reshape
);
4137 ret_val
= reshape_array(NULL
, mdfd
, "array", st
, info
, 1,
4138 NULL
, backup_file
, 0, 0, 1,