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
= xmalloc(sizeof(int) * disk_count
);
54 for (i
= 0; i
< next_spare
; i
++)
56 for (dev
= content
->devs
; dev
; dev
= dev
->next
) {
62 fd
= dev_open(buf
, O_RDWR
);
64 if (dev
->disk
.raid_disk
>= 0)
65 fdlist
[dev
->disk
.raid_disk
] = fd
;
67 fdlist
[next_spare
++] = fd
;
70 if (st
->ss
->external
&& st
->ss
->recover_backup
)
71 err
= st
->ss
->recover_backup(st
, content
);
73 err
= Grow_restart(st
, content
, fdlist
, next_spare
,
74 backup_file
, verbose
> 0);
76 while (next_spare
> 0) {
78 if (fdlist
[next_spare
] >= 0)
79 close(fdlist
[next_spare
]);
83 pr_err("Failed to restore critical"
84 " section for reshape - sorry.\n");
86 pr_err("Possibly you need"
87 " to specify a --backup-file\n");
91 dprintf("restore_backup() returns status OK.\n");
95 int Grow_Add_device(char *devname
, int fd
, char *newdev
)
97 /* Add a device to an active array.
98 * Currently, just extend a linear array.
99 * This requires writing a new superblock on the
100 * new device, calling the kernel to add the device,
101 * and if that succeeds, update the superblock on
103 * This means that we need to *find* all other devices.
110 struct supertype
*st
= NULL
;
111 char *subarray
= NULL
;
113 if (ioctl(fd
, GET_ARRAY_INFO
, &info
.array
) < 0) {
114 pr_err("cannot get array info for %s\n", devname
);
118 if (info
.array
.level
!= -1) {
119 pr_err("can only add devices to linear arrays\n");
123 st
= super_by_fd(fd
, &subarray
);
125 pr_err("cannot handle arrays with superblock version %d\n", info
.array
.major_version
);
130 pr_err("Cannot grow linear sub-arrays yet\n");
136 nfd
= open(newdev
, O_RDWR
|O_EXCL
|O_DIRECT
);
138 pr_err("cannot open %s\n", newdev
);
143 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
144 pr_err("%s is not a block device!\n", newdev
);
149 /* now check out all the devices and make sure we can read the superblock */
150 for (d
=0 ; d
< info
.array
.raid_disks
; d
++) {
151 mdu_disk_info_t disk
;
154 st
->ss
->free_super(st
);
157 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
158 pr_err("cannot get device detail for device %d\n",
164 dv
= map_dev(disk
.major
, disk
.minor
, 1);
166 pr_err("cannot find device file for device %d\n",
172 fd2
= dev_open(dv
, O_RDWR
);
174 pr_err("cannot open device file %s\n", dv
);
180 if (st
->ss
->load_super(st
, fd2
, NULL
)) {
181 pr_err("cannot find super block on %s\n", dv
);
189 /* Ok, looks good. Lets update the superblock and write it out to
193 info
.disk
.number
= d
;
194 info
.disk
.major
= major(stb
.st_rdev
);
195 info
.disk
.minor
= minor(stb
.st_rdev
);
196 info
.disk
.raid_disk
= d
;
197 info
.disk
.state
= (1 << MD_DISK_SYNC
) | (1 << MD_DISK_ACTIVE
);
198 st
->ss
->update_super(st
, &info
, "linear-grow-new", newdev
,
201 if (st
->ss
->store_super(st
, nfd
)) {
202 pr_err("Cannot store new superblock on %s\n",
209 if (ioctl(fd
, ADD_NEW_DISK
, &info
.disk
) != 0) {
210 pr_err("Cannot add new disk to this array\n");
213 /* Well, that seems to have worked.
214 * Now go through and update all superblocks
217 if (ioctl(fd
, GET_ARRAY_INFO
, &info
.array
) < 0) {
218 pr_err("cannot get array info for %s\n", devname
);
223 for (d
=0 ; d
< info
.array
.raid_disks
; d
++) {
224 mdu_disk_info_t disk
;
228 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
229 pr_err("cannot get device detail for device %d\n",
233 dv
= map_dev(disk
.major
, disk
.minor
, 1);
235 pr_err("cannot find device file for device %d\n",
239 fd2
= dev_open(dv
, O_RDWR
);
241 pr_err("cannot open device file %s\n", dv
);
244 if (st
->ss
->load_super(st
, fd2
, NULL
)) {
245 pr_err("cannot find super block on %s\n", dv
);
249 info
.array
.raid_disks
= nd
+1;
250 info
.array
.nr_disks
= nd
+1;
251 info
.array
.active_disks
= nd
+1;
252 info
.array
.working_disks
= nd
+1;
254 st
->ss
->update_super(st
, &info
, "linear-grow-update", dv
,
257 if (st
->ss
->store_super(st
, fd2
)) {
258 pr_err("Cannot store new superblock on %s\n", dv
);
268 int Grow_addbitmap(char *devname
, int fd
, struct context
*c
, struct shape
*s
)
271 * First check that array doesn't have a bitmap
272 * Then create the bitmap
275 * For internal bitmaps, we need to check the version,
276 * find all the active devices, and write the bitmap block
279 mdu_bitmap_file_t bmf
;
280 mdu_array_info_t array
;
281 struct supertype
*st
;
282 char *subarray
= NULL
;
283 int major
= BITMAP_MAJOR_HI
;
284 int vers
= md_get_version(fd
);
285 unsigned long long bitmapsize
, array_size
;
288 major
= BITMAP_MAJOR_HOSTENDIAN
;
289 pr_err("Warning - bitmaps created on this kernel"
290 " are not portable\n"
291 " between different architectures. Consider upgrading"
292 " the Linux kernel.\n");
295 if (ioctl(fd
, GET_BITMAP_FILE
, &bmf
) != 0) {
297 pr_err("Memory allocation failure.\n");
299 pr_err("bitmaps not supported by this kernel.\n");
302 if (bmf
.pathname
[0]) {
303 if (strcmp(s
->bitmap_file
,"none")==0) {
304 if (ioctl(fd
, SET_BITMAP_FILE
, -1)!= 0) {
305 pr_err("failed to remove bitmap %s\n",
311 pr_err("%s already has a bitmap (%s)\n",
312 devname
, bmf
.pathname
);
315 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
316 pr_err("cannot get array status for %s\n", devname
);
319 if (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)) {
320 if (strcmp(s
->bitmap_file
, "none")==0) {
321 array
.state
&= ~(1<<MD_SB_BITMAP_PRESENT
);
322 if (ioctl(fd
, SET_ARRAY_INFO
, &array
)!= 0) {
323 pr_err("failed to remove internal bitmap.\n");
328 pr_err("Internal bitmap already present on %s\n",
333 if (strcmp(s
->bitmap_file
, "none") == 0) {
334 pr_err("no bitmap found on %s\n", devname
);
337 if (array
.level
<= 0) {
338 pr_err("Bitmaps not meaningful with level %s\n",
339 map_num(pers
, array
.level
)?:"of this array");
342 bitmapsize
= array
.size
;
344 if (get_dev_size(fd
, NULL
, &array_size
) &&
345 array_size
> (0x7fffffffULL
<<9)) {
346 /* Array is big enough that we cannot trust array.size
347 * try other approaches
349 bitmapsize
= get_component_size(fd
);
351 if (bitmapsize
== 0) {
352 pr_err("Cannot reliably determine size of array to create bitmap - sorry.\n");
356 if (array
.level
== 10) {
357 int ncopies
= (array
.layout
&255)*((array
.layout
>>8)&255);
358 bitmapsize
= bitmapsize
* array
.raid_disks
/ ncopies
;
361 st
= super_by_fd(fd
, &subarray
);
363 pr_err("Cannot understand version %d.%d\n",
364 array
.major_version
, array
.minor_version
);
368 pr_err("Cannot add bitmaps to sub-arrays yet\n");
373 if (strcmp(s
->bitmap_file
, "internal") == 0) {
376 int offset_setable
= 0;
378 if (st
->ss
->add_internal_bitmap
== NULL
) {
379 pr_err("Internal bitmaps not supported "
380 "with %s metadata\n", st
->ss
->name
);
383 mdi
= sysfs_read(fd
, -1, GET_BITMAP_LOCATION
);
386 for (d
=0; d
< st
->max_devs
; d
++) {
387 mdu_disk_info_t disk
;
390 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
392 if (disk
.major
== 0 &&
395 if ((disk
.state
& (1<<MD_DISK_SYNC
))==0)
397 dv
= map_dev(disk
.major
, disk
.minor
, 1);
399 int fd2
= dev_open(dv
, O_RDWR
);
402 if (st
->ss
->load_super(st
, fd2
, NULL
)==0) {
403 if (st
->ss
->add_internal_bitmap(
405 &s
->bitmap_chunk
, c
->delay
, s
->write_behind
,
406 bitmapsize
, offset_setable
,
409 st
->ss
->write_bitmap(st
, fd2
);
412 "to create internal bitmap - chunksize problem.\n");
420 if (offset_setable
) {
421 st
->ss
->getinfo_super(st
, mdi
, NULL
);
422 sysfs_init(mdi
, fd
, -1);
423 rv
= sysfs_set_num_signed(mdi
, NULL
, "bitmap/location",
426 array
.state
|= (1<<MD_SB_BITMAP_PRESENT
);
427 rv
= ioctl(fd
, SET_ARRAY_INFO
, &array
);
431 pr_err("Cannot add bitmap while array is"
432 " resyncing or reshaping etc.\n");
433 pr_err("failed to set internal bitmap.\n");
440 int max_devs
= st
->max_devs
;
442 /* try to load a superblock */
443 for (d
=0; d
<max_devs
; d
++) {
444 mdu_disk_info_t disk
;
448 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
450 if ((disk
.major
==0 && disk
.minor
==0) ||
451 (disk
.state
& (1<<MD_DISK_REMOVED
)))
453 dv
= map_dev(disk
.major
, disk
.minor
, 1);
455 fd2
= dev_open(dv
, O_RDONLY
);
457 if (st
->ss
->load_super(st
, fd2
, NULL
) == 0) {
459 st
->ss
->uuid_from_super(st
, uuid
);
466 pr_err("cannot find UUID for array!\n");
469 if (CreateBitmap(s
->bitmap_file
, c
->force
, (char*)uuid
, s
->bitmap_chunk
,
470 c
->delay
, s
->write_behind
, bitmapsize
, major
)) {
473 bitmap_fd
= open(s
->bitmap_file
, O_RDWR
);
475 pr_err("weird: %s cannot be opened\n",
479 if (ioctl(fd
, SET_BITMAP_FILE
, bitmap_fd
) < 0) {
482 pr_err("Cannot add bitmap while array is"
483 " resyncing or reshaping etc.\n");
484 pr_err("Cannot set bitmap file for %s: %s\n",
485 devname
, strerror(err
));
494 * When reshaping an array we might need to backup some data.
495 * This is written to all spares with a 'super_block' describing it.
496 * The superblock goes 4K from the end of the used space on the
498 * It if written after the backup is complete.
499 * It has the following structure.
502 static struct mdp_backup_super
{
503 char magic
[16]; /* md_backup_data-1 or -2 */
506 /* start/sizes in 512byte sectors */
507 __u64 devstart
; /* address on backup device/file of data */
510 __u32 sb_csum
; /* csum of preceeding bytes. */
512 __u64 devstart2
; /* offset in to data of second section */
515 __u32 sb_csum2
; /* csum of preceeding bytes. */
517 } __attribute__((aligned(512))) bsb
, bsb2
;
519 static __u32
bsb_csum(char *buf
, int len
)
523 for (i
=0; i
<len
; i
++)
524 csum
= (csum
<<3) + buf
[0];
525 return __cpu_to_le32(csum
);
528 static int check_idle(struct supertype
*st
)
530 /* Check that all member arrays for this container, or the
531 * container of this array, are idle
533 int container_dev
= (st
->container_dev
!= NoMdDev
534 ? st
->container_dev
: st
->devnum
);
536 struct mdstat_ent
*ent
, *e
;
539 fmt_devname(container
, container_dev
);
540 ent
= mdstat_read(0, 0);
541 for (e
= ent
; e
; e
= e
->next
) {
542 if (!is_container_member(e
, container
))
544 if (e
->percent
>= 0) {
553 static int freeze_container(struct supertype
*st
)
555 int container_dev
= (st
->container_dev
!= NoMdDev
556 ? st
->container_dev
: st
->devnum
);
562 fmt_devname(container
, container_dev
);
564 if (block_monitor(container
, 1)) {
565 pr_err("failed to freeze container\n");
572 static void unfreeze_container(struct supertype
*st
)
574 int container_dev
= (st
->container_dev
!= NoMdDev
575 ? st
->container_dev
: st
->devnum
);
578 fmt_devname(container
, container_dev
);
580 unblock_monitor(container
, 1);
583 static int freeze(struct supertype
*st
)
585 /* Try to freeze resync/rebuild on this array/container.
586 * Return -1 if the array is busy,
587 * return -2 container cannot be frozen,
588 * return 0 if this kernel doesn't support 'frozen'
589 * return 1 if it worked.
591 if (st
->ss
->external
)
592 return freeze_container(st
);
594 struct mdinfo
*sra
= sysfs_read(-1, st
->devnum
, GET_VERSION
);
600 /* Need to clear any 'read-auto' status */
601 if (sysfs_get_str(sra
, NULL
, "array_state", buf
, 20) > 0 &&
602 strncmp(buf
, "read-auto", 9) == 0)
603 sysfs_set_str(sra
, NULL
, "array_state", "clean");
605 err
= sysfs_freeze_array(sra
);
611 static void unfreeze(struct supertype
*st
)
613 if (st
->ss
->external
)
614 return unfreeze_container(st
);
616 struct mdinfo
*sra
= sysfs_read(-1, st
->devnum
, GET_VERSION
);
619 sysfs_set_str(sra
, NULL
, "sync_action", "idle");
624 static void wait_reshape(struct mdinfo
*sra
)
626 int fd
= sysfs_get_fd(sra
, NULL
, "sync_action");
632 while (sysfs_fd_get_str(fd
, action
, 20) > 0 &&
633 strncmp(action
, "reshape", 7) == 0) {
637 select(fd
+1, NULL
, NULL
, &rfds
, NULL
);
642 static int reshape_super(struct supertype
*st
, long long size
, int level
,
643 int layout
, int chunksize
, int raid_disks
,
644 int delta_disks
, char *backup_file
, char *dev
,
645 int direction
, int verbose
)
647 /* nothing extra to check in the native case */
648 if (!st
->ss
->external
)
650 if (!st
->ss
->reshape_super
||
651 !st
->ss
->manage_reshape
) {
652 pr_err("%s metadata does not support reshape\n",
657 return st
->ss
->reshape_super(st
, size
, level
, layout
, chunksize
,
658 raid_disks
, delta_disks
, backup_file
, dev
,
662 static void sync_metadata(struct supertype
*st
)
664 if (st
->ss
->external
) {
665 if (st
->update_tail
) {
666 flush_metadata_updates(st
);
667 st
->update_tail
= &st
->updates
;
669 st
->ss
->sync_metadata(st
);
673 static int subarray_set_num(char *container
, struct mdinfo
*sra
, char *name
, int n
)
675 /* when dealing with external metadata subarrays we need to be
676 * prepared to handle EAGAIN. The kernel may need to wait for
677 * mdmon to mark the array active so the kernel can handle
678 * allocations/writeback when preparing the reshape action
679 * (md_allow_write()). We temporarily disable safe_mode_delay
680 * to close a race with the array_state going clean before the
681 * next write to raid_disks / stripe_cache_size
686 /* only 'raid_disks' and 'stripe_cache_size' trigger md_allow_write */
688 (strcmp(name
, "raid_disks") != 0 &&
689 strcmp(name
, "stripe_cache_size") != 0))
690 return sysfs_set_num(sra
, NULL
, name
, n
);
692 rc
= sysfs_get_str(sra
, NULL
, "safe_mode_delay", safe
, sizeof(safe
));
695 sysfs_set_num(sra
, NULL
, "safe_mode_delay", 0);
696 rc
= sysfs_set_num(sra
, NULL
, name
, n
);
697 if (rc
< 0 && errno
== EAGAIN
) {
698 ping_monitor(container
);
699 /* if we get EAGAIN here then the monitor is not active
702 rc
= sysfs_set_num(sra
, NULL
, name
, n
);
704 sysfs_set_str(sra
, NULL
, "safe_mode_delay", safe
);
708 int start_reshape(struct mdinfo
*sra
, int already_running
,
709 int before_data_disks
, int data_disks
)
712 unsigned long long sync_max_to_set
;
714 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
715 err
= sysfs_set_num(sra
, NULL
, "suspend_hi", sra
->reshape_progress
);
716 err
= err
?: sysfs_set_num(sra
, NULL
, "suspend_lo",
717 sra
->reshape_progress
);
718 if (before_data_disks
<= data_disks
)
719 sync_max_to_set
= sra
->reshape_progress
/ data_disks
;
721 sync_max_to_set
= (sra
->component_size
* data_disks
722 - sra
->reshape_progress
) / data_disks
;
723 if (!already_running
)
724 sysfs_set_num(sra
, NULL
, "sync_min", sync_max_to_set
);
725 err
= err
?: sysfs_set_num(sra
, NULL
, "sync_max", sync_max_to_set
);
726 if (!already_running
)
727 err
= err
?: sysfs_set_str(sra
, NULL
, "sync_action", "reshape");
732 void abort_reshape(struct mdinfo
*sra
)
734 sysfs_set_str(sra
, NULL
, "sync_action", "idle");
735 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
736 sysfs_set_num(sra
, NULL
, "suspend_hi", 0);
737 sysfs_set_num(sra
, NULL
, "suspend_lo", 0);
738 sysfs_set_num(sra
, NULL
, "sync_min", 0);
739 sysfs_set_str(sra
, NULL
, "sync_max", "max");
742 int remove_disks_for_takeover(struct supertype
*st
,
747 struct mdinfo
*remaining
;
750 if (sra
->array
.level
== 10)
751 nr_of_copies
= layout
& 0xff;
752 else if (sra
->array
.level
== 1)
753 nr_of_copies
= sra
->array
.raid_disks
;
757 remaining
= sra
->devs
;
759 /* for each 'copy', select one device and remove from the list. */
760 for (slot
= 0; slot
< sra
->array
.raid_disks
; slot
+= nr_of_copies
) {
761 struct mdinfo
**diskp
;
764 /* Find a working device to keep */
765 for (diskp
= &remaining
; *diskp
; diskp
= &(*diskp
)->next
) {
766 struct mdinfo
*disk
= *diskp
;
768 if (disk
->disk
.raid_disk
< slot
)
770 if (disk
->disk
.raid_disk
>= slot
+ nr_of_copies
)
772 if (disk
->disk
.state
& (1<<MD_DISK_REMOVED
))
774 if (disk
->disk
.state
& (1<<MD_DISK_FAULTY
))
776 if (!(disk
->disk
.state
& (1<<MD_DISK_SYNC
)))
779 /* We have found a good disk to use! */
781 disk
->next
= sra
->devs
;
790 if (slot
< sra
->array
.raid_disks
) {
791 /* didn't find all slots */
797 sra
->devs
= remaining
;
801 /* Remove all 'remaining' devices from the array */
803 struct mdinfo
*sd
= remaining
;
804 remaining
= sd
->next
;
806 sysfs_set_str(sra
, sd
, "state", "faulty");
807 sysfs_set_str(sra
, sd
, "slot", "none");
808 /* for external metadata disks should be removed in mdmon */
809 if (!st
->ss
->external
)
810 sysfs_set_str(sra
, sd
, "state", "remove");
811 sd
->disk
.state
|= (1<<MD_DISK_REMOVED
);
812 sd
->disk
.state
&= ~(1<<MD_DISK_SYNC
);
813 sd
->next
= sra
->devs
;
819 void reshape_free_fdlist(int *fdlist
,
820 unsigned long long *offsets
,
825 for (i
= 0; i
< size
; i
++)
833 int reshape_prepare_fdlist(char *devname
,
837 unsigned long blocks
,
840 unsigned long long *offsets
)
845 for (d
= 0; d
<= nrdisks
; d
++)
848 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
849 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
851 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
852 char *dn
= map_dev(sd
->disk
.major
,
854 fdlist
[sd
->disk
.raid_disk
]
855 = dev_open(dn
, O_RDONLY
);
856 offsets
[sd
->disk
.raid_disk
] = sd
->data_offset
*512;
857 if (fdlist
[sd
->disk
.raid_disk
] < 0) {
858 pr_err("%s: cannot open component %s\n",
859 devname
, dn
? dn
: "-unknown-");
863 } else if (backup_file
== NULL
) {
865 char *dn
= map_dev(sd
->disk
.major
,
867 fdlist
[d
] = dev_open(dn
, O_RDWR
);
868 offsets
[d
] = (sd
->data_offset
+ sra
->component_size
- blocks
- 8)*512;
870 pr_err("%s: cannot open component %s\n",
871 devname
, dn
? dn
: "-unknown-");
882 int reshape_open_backup_file(char *backup_file
,
887 unsigned long long *offsets
,
890 /* Return 1 on success, 0 on any form of failure */
891 /* need to check backup file is large enough */
897 *fdlist
= open(backup_file
, O_RDWR
|O_CREAT
|(restart
? O_TRUNC
: O_EXCL
),
901 pr_err("%s: cannot create backup file %s: %s\n",
902 devname
, backup_file
, strerror(errno
));
905 /* Guard against backup file being on array device.
906 * If array is partitioned or if LVM etc is in the
907 * way this will not notice, but it is better than
910 fstat(*fdlist
, &stb
);
913 if (stb
.st_rdev
== dev
) {
914 pr_err("backup file must NOT be"
915 " on the array being reshaped.\n");
921 for (i
=0; i
< blocks
+ 8 ; i
++) {
922 if (write(*fdlist
, buf
, 512) != 512) {
923 pr_err("%s: cannot create"
924 " backup file %s: %s\n",
925 devname
, backup_file
, strerror(errno
));
929 if (fsync(*fdlist
) != 0) {
930 pr_err("%s: cannot create backup file %s: %s\n",
931 devname
, backup_file
, strerror(errno
));
938 unsigned long compute_backup_blocks(int nchunk
, int ochunk
,
939 unsigned int ndata
, unsigned int odata
)
941 unsigned long a
, b
, blocks
;
942 /* So how much do we need to backup.
943 * We need an amount of data which is both a whole number of
944 * old stripes and a whole number of new stripes.
945 * So LCM for (chunksize*datadisks).
947 a
= (ochunk
/512) * odata
;
948 b
= (nchunk
/512) * ndata
;
956 /* LCM == product / GCD */
957 blocks
= (ochunk
/512) * (nchunk
/512) * odata
* ndata
/ a
;
962 char *analyse_change(struct mdinfo
*info
, struct reshape
*re
)
964 /* Based on the current array state in info->array and
965 * the changes in info->new_* etc, determine:
966 * - whether the change is possible
967 * - Intermediate level/raid_disks/layout
968 * - whether a restriping reshape is needed
969 * - number of sectors in minimum change unit. This
970 * will cover a whole number of stripes in 'before' and
973 * Return message if the change should be rejected
974 * NULL if the change can be achieved
976 * This can be called as part of starting a reshape, or
977 * when assembling an array that is undergoing reshape.
980 /* delta_parity records change in number of devices
981 * caused by level change
983 int delta_parity
= 0;
985 /* If a new level not explicitly given, we assume no-change */
986 if (info
->new_level
== UnSet
)
987 info
->new_level
= info
->array
.level
;
990 switch (info
->new_level
) {
996 /* chunk size is meaningful, must divide component_size
999 if (info
->component_size
% (info
->new_chunk
/512))
1000 return "New chunk size does not"
1001 " divide component size";
1004 return "chunk size not meaningful for this level";
1007 info
->new_chunk
= info
->array
.chunk_size
;
1009 switch (info
->array
.level
) {
1011 return "Cannot understand this RAID level";
1013 /* RAID1 can convert to RAID1 with different disks, or
1014 * raid5 with 2 disks, or
1017 if (info
->new_level
> 1 &&
1018 (info
->component_size
& 7))
1019 return "Cannot convert RAID1 of this size - "
1020 "reduce size to multiple of 4K first.";
1021 if (info
->new_level
== 0) {
1022 if (info
->delta_disks
!= UnSet
&&
1023 info
->delta_disks
!= 0)
1024 return "Cannot change number of disks "
1025 "with RAID1->RAID0 conversion";
1027 re
->before
.data_disks
= 1;
1028 re
->after
.data_disks
= 1;
1029 re
->before
.layout
= 0;
1030 re
->backup_blocks
= 0;
1034 if (info
->new_level
== 1) {
1035 if (info
->delta_disks
== UnSet
)
1036 /* Don't know what to do */
1037 return "no change requested for Growing RAID1";
1039 re
->backup_blocks
= 0;
1043 if (info
->array
.raid_disks
== 2 &&
1044 info
->new_level
== 5) {
1047 re
->before
.data_disks
= 1;
1048 if (info
->delta_disks
!= UnSet
&&
1049 info
->delta_disks
!= 0)
1050 re
->after
.data_disks
= 1 + info
->delta_disks
;
1052 re
->after
.data_disks
= 1;
1053 if (re
->after
.data_disks
< 1)
1054 return "Number of disks too small for RAID5";
1056 re
->before
.layout
= ALGORITHM_LEFT_SYMMETRIC
;
1057 info
->array
.chunk_size
= 65536;
1060 /* Could do some multi-stage conversions, but leave that to
1063 return "Impossibly level change request for RAID1";
1066 /* RAID10 can only be converted from near mode to
1067 * RAID0 by removing some devices
1069 if ((info
->array
.layout
& ~0xff) != 0x100)
1070 return "Cannot Grow RAID10 with far/offset layout";
1071 /* number of devices must be multiple of number of copies */
1072 if (info
->array
.raid_disks
% (info
->array
.layout
& 0xff))
1073 return "RAID10 layout too complex for Grow operation";
1075 if (info
->new_level
!= 0)
1076 return "RAID10 can only be changed to RAID0";
1077 new_disks
= (info
->array
.raid_disks
1078 / (info
->array
.layout
& 0xff));
1079 if (info
->delta_disks
== UnSet
)
1080 info
->delta_disks
= (new_disks
1081 - info
->array
.raid_disks
);
1083 if (info
->delta_disks
!= new_disks
- info
->array
.raid_disks
)
1084 return "New number of raid-devices impossible for RAID10";
1085 if (info
->new_chunk
&&
1086 info
->new_chunk
!= info
->array
.chunk_size
)
1087 return "Cannot change chunk-size with RAID10 Grow";
1092 re
->before
.data_disks
= new_disks
;
1093 re
->after
.data_disks
= re
->before
.data_disks
;
1094 re
->before
.layout
= 0;
1095 re
->backup_blocks
= 0;
1099 /* RAID0 can be converted to RAID10, or to RAID456 */
1100 if (info
->new_level
== 10) {
1101 if (info
->new_layout
== UnSet
&& info
->delta_disks
== UnSet
) {
1102 /* Assume near=2 layout */
1103 info
->new_layout
= 0x102;
1104 info
->delta_disks
= info
->array
.raid_disks
;
1106 if (info
->new_layout
== UnSet
) {
1107 int copies
= 1 + (info
->delta_disks
1108 / info
->array
.raid_disks
);
1109 if (info
->array
.raid_disks
* (copies
-1)
1110 != info
->delta_disks
)
1111 return "Impossible number of devices"
1112 " for RAID0->RAID10";
1113 info
->new_layout
= 0x100 + copies
;
1115 if (info
->delta_disks
== UnSet
) {
1116 int copies
= info
->new_layout
& 0xff;
1117 if (info
->new_layout
!= 0x100 + copies
)
1118 return "New layout impossible"
1119 " for RAID0->RAID10";;
1120 info
->delta_disks
= (copies
- 1) *
1121 info
->array
.raid_disks
;
1123 if (info
->new_chunk
&&
1124 info
->new_chunk
!= info
->array
.chunk_size
)
1125 return "Cannot change chunk-size with RAID0->RAID10";
1129 re
->before
.data_disks
= (info
->array
.raid_disks
+
1131 re
->after
.data_disks
= re
->before
.data_disks
;
1132 re
->before
.layout
= info
->new_layout
;
1133 re
->backup_blocks
= 0;
1137 /* RAID0 can also covert to RAID0/4/5/6 by first converting to
1138 * a raid4 style layout of the final level.
1140 switch (info
->new_level
) {
1145 re
->before
.layout
= 0;
1150 re
->before
.layout
= ALGORITHM_PARITY_N
;
1155 re
->before
.layout
= ALGORITHM_PARITY_N
;
1158 return "Impossible level change requested";
1160 re
->before
.data_disks
= info
->array
.raid_disks
;
1161 /* determining 'after' layout happens outside this 'switch' */
1165 info
->array
.layout
= ALGORITHM_PARITY_N
;
1167 switch (info
->new_level
) {
1171 re
->level
= info
->array
.level
;
1172 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1173 re
->before
.layout
= info
->array
.layout
;
1177 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1178 re
->before
.layout
= info
->array
.layout
;
1183 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1184 switch (info
->array
.layout
) {
1185 case ALGORITHM_LEFT_ASYMMETRIC
:
1186 re
->before
.layout
= ALGORITHM_LEFT_ASYMMETRIC_6
;
1188 case ALGORITHM_RIGHT_ASYMMETRIC
:
1189 re
->before
.layout
= ALGORITHM_RIGHT_ASYMMETRIC_6
;
1191 case ALGORITHM_LEFT_SYMMETRIC
:
1192 re
->before
.layout
= ALGORITHM_LEFT_SYMMETRIC_6
;
1194 case ALGORITHM_RIGHT_SYMMETRIC
:
1195 re
->before
.layout
= ALGORITHM_RIGHT_SYMMETRIC_6
;
1197 case ALGORITHM_PARITY_0
:
1198 re
->before
.layout
= ALGORITHM_PARITY_0_6
;
1200 case ALGORITHM_PARITY_N
:
1201 re
->before
.layout
= ALGORITHM_PARITY_N_6
;
1204 return "Cannot convert an array with this layout";
1208 if (info
->array
.raid_disks
!= 2)
1209 return "Can only convert a 2-device array to RAID1";
1210 if (info
->delta_disks
!= UnSet
&&
1211 info
->delta_disks
!= 0)
1212 return "Cannot set raid_disk when "
1213 "converting RAID5->RAID1";
1217 return "Impossible level change requested";
1221 switch (info
->new_level
) {
1227 re
->before
.data_disks
= info
->array
.raid_disks
- 2;
1228 re
->before
.layout
= info
->array
.layout
;
1231 return "Impossible level change requested";
1236 /* If we reached here then it looks like a re-stripe is
1237 * happening. We have determined the intermediate level
1238 * and initial raid_disks/layout and stored these in 're'.
1240 * We need to deduce the final layout that can be atomically
1241 * converted to the end state.
1243 switch (info
->new_level
) {
1245 /* We can only get to RAID0 from RAID4 or RAID5
1246 * with appropriate layout and one extra device
1248 if (re
->level
!= 4 && re
->level
!= 5)
1249 return "Cannot covert to RAID0 from this level";
1251 switch (re
->level
) {
1253 re
->after
.layout
= 0 ; break;
1255 re
->after
.layout
= ALGORITHM_PARITY_N
; break;
1260 /* We can only get to RAID4 from RAID5 */
1261 if (re
->level
!= 4 && re
->level
!= 5)
1262 return "Cannot convert to RAID4 from this level";
1264 switch (re
->level
) {
1266 re
->after
.layout
= 0 ; break;
1268 re
->after
.layout
= ALGORITHM_PARITY_N
; break;
1273 /* We get to RAID5 from RAID5 or RAID6 */
1274 if (re
->level
!= 5 && re
->level
!= 6)
1275 return "Cannot convert to RAID5 from this level";
1277 switch (re
->level
) {
1279 if (info
->new_layout
== UnSet
)
1280 re
->after
.layout
= re
->before
.layout
;
1282 re
->after
.layout
= info
->new_layout
;
1285 if (info
->new_layout
== UnSet
)
1286 info
->new_layout
= re
->before
.layout
;
1288 /* after.layout needs to be raid6 version of new_layout */
1289 if (info
->new_layout
== ALGORITHM_PARITY_N
)
1290 re
->after
.layout
= ALGORITHM_PARITY_N
;
1293 char *ls
= map_num(r5layout
, info
->new_layout
);
1296 /* Current RAID6 layout has a RAID5
1299 strcat(strcpy(layout
, ls
), "-6");
1300 l
= map_name(r6layout
, layout
);
1302 return "Cannot find RAID6 layout"
1305 /* Current RAID6 has no equivalent.
1306 * If it is already a '-6' layout we
1307 * can leave it unchanged, else we must
1310 ls
= map_num(r6layout
, info
->new_layout
);
1312 strcmp(ls
+strlen(ls
)-2, "-6") != 0)
1313 return "Please specify new layout";
1314 l
= info
->new_layout
;
1316 re
->after
.layout
= l
;
1322 /* We must already be at level 6 */
1324 return "Impossible level change";
1325 if (info
->new_layout
== UnSet
)
1326 re
->after
.layout
= info
->array
.layout
;
1328 re
->after
.layout
= info
->new_layout
;
1331 return "Impossible level change requested";
1333 if (info
->delta_disks
== UnSet
)
1334 info
->delta_disks
= delta_parity
;
1336 re
->after
.data_disks
= (re
->before
.data_disks
1339 switch (re
->level
) {
1340 case 6: re
->parity
= 2; break;
1342 case 5: re
->parity
= 1; break;
1343 default: re
->parity
= 0; break;
1345 /* So we have a restripe operation, we need to calculate the number
1346 * of blocks per reshape operation.
1348 if (info
->new_chunk
== 0)
1349 info
->new_chunk
= info
->array
.chunk_size
;
1350 if (re
->after
.data_disks
== re
->before
.data_disks
&&
1351 re
->after
.layout
== re
->before
.layout
&&
1352 info
->new_chunk
== info
->array
.chunk_size
) {
1353 /* Nothing to change */
1354 re
->backup_blocks
= 0;
1357 if (re
->after
.data_disks
== 1 && re
->before
.data_disks
== 1) {
1358 /* chunk and layout changes make no difference */
1359 re
->backup_blocks
= 0;
1363 if (re
->after
.data_disks
== re
->before
.data_disks
&&
1364 get_linux_version() < 2006032)
1365 return "in-place reshape is not safe before 2.6.32 - sorry.";
1367 if (re
->after
.data_disks
< re
->before
.data_disks
&&
1368 get_linux_version() < 2006030)
1369 return "reshape to fewer devices is not supported before 2.6.30 - sorry.";
1371 re
->backup_blocks
= compute_backup_blocks(
1372 info
->new_chunk
, info
->array
.chunk_size
,
1373 re
->after
.data_disks
,
1374 re
->before
.data_disks
);
1376 re
->new_size
= info
->component_size
* re
->after
.data_disks
;
1380 static int set_array_size(struct supertype
*st
, struct mdinfo
*sra
,
1383 struct mdinfo
*info
;
1387 if ((st
== NULL
) || (sra
== NULL
))
1390 if (text_version
== NULL
)
1391 text_version
= sra
->text_version
;
1392 subarray
= strchr(text_version
+1, '/')+1;
1393 info
= st
->ss
->container_content(st
, subarray
);
1395 unsigned long long current_size
= 0;
1396 unsigned long long new_size
=
1397 info
->custom_array_size
/2;
1399 if (sysfs_get_ll(sra
, NULL
, "array_size", ¤t_size
) == 0 &&
1400 new_size
> current_size
) {
1401 if (sysfs_set_num(sra
, NULL
, "array_size", new_size
)
1403 dprintf("Error: Cannot set array size");
1406 dprintf("Array size changed");
1408 dprintf(" from %llu to %llu.\n",
1409 current_size
, new_size
);
1413 dprintf("Error: set_array_size(): info pointer in NULL\n");
1418 static int reshape_array(char *container
, int fd
, char *devname
,
1419 struct supertype
*st
, struct mdinfo
*info
,
1420 int force
, struct mddev_dev
*devlist
,
1421 char *backup_file
, int verbose
, int forked
,
1422 int restart
, int freeze_reshape
);
1423 static int reshape_container(char *container
, char *devname
,
1425 struct supertype
*st
,
1426 struct mdinfo
*info
,
1429 int verbose
, int restart
, int freeze_reshape
);
1431 int Grow_reshape(char *devname
, int fd
,
1432 struct mddev_dev
*devlist
,
1433 struct context
*c
, struct shape
*s
)
1435 /* Make some changes in the shape of an array.
1436 * The kernel must support the change.
1438 * There are three different changes. Each can trigger
1439 * a resync or recovery so we freeze that until we have
1440 * requested everything (if kernel supports freezing - 2.6.30).
1442 * - change size (i.e. component_size)
1444 * - change layout/chunksize/ndisks
1446 * The last can require a reshape. It is different on different
1447 * levels so we need to check the level before actioning it.
1448 * Some times the level change needs to be requested after the
1449 * reshape (e.g. raid6->raid5, raid5->raid0)
1452 struct mdu_array_info_s array
;
1454 struct supertype
*st
;
1455 char *subarray
= NULL
;
1459 char *container
= NULL
;
1460 char container_buf
[20];
1463 struct mddev_dev
*dv
;
1469 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) < 0) {
1470 pr_err("%s is not an active md array - aborting\n",
1476 (s
->chunk
|| s
->level
!= UnSet
|| s
->layout_str
|| s
->raiddisks
)) {
1477 pr_err("cannot change component size at the same time "
1478 "as other changes.\n"
1479 " Change size first, then check data is intact before "
1480 "making other changes.\n");
1484 if (s
->raiddisks
&& s
->raiddisks
< array
.raid_disks
&& array
.level
> 1 &&
1485 get_linux_version() < 2006032 &&
1486 !check_env("MDADM_FORCE_FEWER")) {
1487 pr_err("reducing the number of devices is not safe before Linux 2.6.32\n"
1488 " Please use a newer kernel\n");
1492 st
= super_by_fd(fd
, &subarray
);
1494 pr_err("Unable to determine metadata format for %s\n", devname
);
1497 if (s
->raiddisks
> st
->max_devs
) {
1498 pr_err("Cannot increase raid-disks on this array"
1499 " beyond %d\n", st
->max_devs
);
1503 /* in the external case we need to check that the requested reshape is
1504 * supported, and perform an initial check that the container holds the
1505 * pre-requisite spare devices (mdmon owns final validation)
1507 if (st
->ss
->external
) {
1512 container_dev
= st
->container_dev
;
1513 cfd
= open_dev_excl(st
->container_dev
);
1515 container_dev
= st
->devnum
;
1517 cfd
= open_dev_excl(st
->devnum
);
1521 pr_err("Unable to open container for %s\n",
1527 fmt_devname(container_buf
, container_dev
);
1528 container
= container_buf
;
1530 rv
= st
->ss
->load_container(st
, cfd
, NULL
);
1533 pr_err("Cannot read superblock for %s\n",
1539 /* check if operation is supported for metadata handler */
1540 if (st
->ss
->container_content
) {
1541 struct mdinfo
*cc
= NULL
;
1542 struct mdinfo
*content
= NULL
;
1544 cc
= st
->ss
->container_content(st
, subarray
);
1545 for (content
= cc
; content
; content
= content
->next
) {
1546 int allow_reshape
= 1;
1548 /* check if reshape is allowed based on metadata
1549 * indications stored in content.array.status
1551 if (content
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
))
1553 if (content
->array
.state
1554 & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
))
1556 if (!allow_reshape
) {
1557 pr_err("cannot reshape arrays in"
1558 " container with unsupported"
1559 " metadata: %s(%s)\n",
1560 devname
, container_buf
);
1568 if (mdmon_running(container_dev
))
1569 st
->update_tail
= &st
->updates
;
1573 for (dv
= devlist
; dv
; dv
= dv
->next
)
1575 if (s
->raiddisks
> array
.raid_disks
&&
1576 array
.spare_disks
+added_disks
< (s
->raiddisks
- array
.raid_disks
) &&
1578 pr_err("Need %d spare%s to avoid degraded array,"
1579 " and only have %d.\n"
1580 " Use --force to over-ride this check.\n",
1581 s
->raiddisks
- array
.raid_disks
,
1582 s
->raiddisks
- array
.raid_disks
== 1 ? "" : "s",
1583 array
.spare_disks
+ added_disks
);
1587 sra
= sysfs_read(fd
, 0, GET_LEVEL
| GET_DISKS
| GET_DEVS
1588 | GET_STATE
| GET_VERSION
);
1590 if (st
->ss
->external
&& subarray
== NULL
) {
1591 array
.level
= LEVEL_CONTAINER
;
1592 sra
->array
.level
= LEVEL_CONTAINER
;
1595 pr_err("failed to read sysfs parameters for %s\n",
1599 frozen
= freeze(st
);
1601 /* freeze() already spewed the reason */
1604 } else if (frozen
< 0) {
1605 pr_err("%s is performing resync/recovery and cannot"
1606 " be reshaped\n", devname
);
1611 /* ========= set size =============== */
1612 if (s
->size
> 0 && (s
->size
== MAX_DISKS
|| s
->size
!= (unsigned)array
.size
)) {
1613 unsigned long long orig_size
= get_component_size(fd
)/2;
1614 unsigned long long min_csize
;
1616 int raid0_takeover
= 0;
1619 orig_size
= (unsigned) array
.size
;
1621 if (reshape_super(st
, s
->size
, UnSet
, UnSet
, 0, 0, UnSet
, NULL
,
1622 devname
, APPLY_METADATA_CHANGES
, c
->verbose
> 0)) {
1627 if (st
->ss
->external
) {
1628 /* metadata can have size limitation
1629 * update size value according to metadata information
1631 struct mdinfo
*sizeinfo
=
1632 st
->ss
->container_content(st
, subarray
);
1634 unsigned long long new_size
=
1635 sizeinfo
->custom_array_size
/2;
1636 int data_disks
= get_data_disks(
1637 sizeinfo
->array
.level
,
1638 sizeinfo
->array
.layout
,
1639 sizeinfo
->array
.raid_disks
);
1640 new_size
/= data_disks
;
1641 dprintf("Metadata size correction from %llu to "
1642 "%llu (%llu)\n", orig_size
, new_size
,
1643 new_size
* data_disks
);
1645 sysfs_free(sizeinfo
);
1649 /* Update the size of each member device in case
1650 * they have been resized. This will never reduce
1651 * below the current used-size. The "size" attribute
1652 * understands '0' to mean 'max'.
1656 for (mdi
= sra
->devs
; mdi
; mdi
= mdi
->next
) {
1657 if (sysfs_set_num(sra
, mdi
, "size",
1658 s
->size
== MAX_SIZE
? 0 : s
->size
) < 0) {
1659 /* Probably kernel refusing to let us
1660 * reduce the size - not an error.
1664 if (array
.not_persistent
== 0 &&
1665 array
.major_version
== 0 &&
1666 get_linux_version() < 3001000) {
1667 /* Dangerous to allow size to exceed 2TB */
1668 unsigned long long csize
;
1669 if (sysfs_get_ll(sra
, mdi
, "size", &csize
) == 0) {
1670 if (csize
>= 2ULL*1024*1024*1024)
1671 csize
= 2ULL*1024*1024*1024;
1672 if ((min_csize
== 0 || (min_csize
1679 pr_err("Cannot set size on "
1680 "array members.\n");
1681 goto size_change_error
;
1683 if (min_csize
&& s
->size
> min_csize
) {
1684 pr_err("Cannot safely make this array "
1685 "use more than 2TB per device on this kernel.\n");
1687 goto size_change_error
;
1689 if (min_csize
&& s
->size
== MAX_SIZE
) {
1690 /* Don't let the kernel choose a size - it will get
1693 pr_err("Limited v0.90 array to "
1694 "2TB per device\n");
1695 s
->size
= min_csize
;
1697 if (st
->ss
->external
) {
1698 if (sra
->array
.level
== 0) {
1699 rv
= sysfs_set_str(sra
, NULL
, "level",
1703 /* get array parametes after takeover
1704 * to chane one parameter at time only
1706 rv
= ioctl(fd
, GET_ARRAY_INFO
, &array
);
1709 /* make sure mdmon is
1710 * aware of the new level */
1711 if (!mdmon_running(st
->container_dev
))
1712 start_mdmon(st
->container_dev
);
1713 ping_monitor(container
);
1714 if (mdmon_running(st
->container_dev
) &&
1715 st
->update_tail
== NULL
)
1716 st
->update_tail
= &st
->updates
;
1719 if (s
->size
== MAX_SIZE
)
1721 array
.size
= s
->size
;
1722 if ((unsigned)array
.size
!= s
->size
) {
1723 /* got truncated to 32bit, write to
1724 * component_size instead
1727 rv
= sysfs_set_num(sra
, NULL
,
1728 "component_size", s
->size
);
1732 rv
= ioctl(fd
, SET_ARRAY_INFO
, &array
);
1734 /* manage array size when it is managed externally
1736 if ((rv
== 0) && st
->ss
->external
)
1737 rv
= set_array_size(st
, sra
, sra
->text_version
);
1740 if (raid0_takeover
) {
1741 /* do not recync non-existing parity,
1742 * we will drop it anyway
1744 sysfs_set_str(sra
, NULL
, "sync_action", "frozen");
1745 /* go back to raid0, drop parity disk
1747 sysfs_set_str(sra
, NULL
, "level", "raid0");
1748 ioctl(fd
, GET_ARRAY_INFO
, &array
);
1755 /* restore metadata */
1756 if (reshape_super(st
, orig_size
, UnSet
, UnSet
, 0, 0,
1757 UnSet
, NULL
, devname
,
1758 ROLLBACK_METADATA_CHANGES
,
1761 pr_err("Cannot set device size for %s: %s\n",
1762 devname
, strerror(err
));
1764 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
1765 cont_err("Bitmap must be removed before size can be changed\n");
1769 if (s
->assume_clean
) {
1770 /* This will fail on kernels newer than 3.0 unless
1771 * a backport has been arranged.
1774 sysfs_set_str(sra
, NULL
, "resync_start", "none") < 0)
1775 pr_err("--assume-clean not support with --grow on this kernel\n");
1777 ioctl(fd
, GET_ARRAY_INFO
, &array
);
1778 s
->size
= get_component_size(fd
)/2;
1780 s
->size
= array
.size
;
1781 if (c
->verbose
>= 0) {
1782 if (s
->size
== orig_size
)
1783 pr_err("component size of %s "
1784 "unchanged at %lluK\n",
1787 pr_err("component size of %s "
1788 "has been set to %lluK\n",
1792 } else if (array
.level
!= LEVEL_CONTAINER
) {
1793 s
->size
= get_component_size(fd
)/2;
1795 s
->size
= array
.size
;
1798 /* See if there is anything else to do */
1799 if ((s
->level
== UnSet
|| s
->level
== array
.level
) &&
1800 (s
->layout_str
== NULL
) &&
1801 (s
->chunk
== 0 || s
->chunk
== array
.chunk_size
) &&
1802 (s
->raiddisks
== 0 || s
->raiddisks
== array
.raid_disks
)) {
1803 /* Nothing more to do */
1804 if (!changed
&& c
->verbose
>= 0)
1805 pr_err("%s: no change requested\n",
1810 /* ========= check for Raid10/Raid1 -> Raid0 conversion ===============
1811 * current implementation assumes that following conditions must be met:
1814 * - near_copies == 2
1816 if ((s
->level
== 0 && array
.level
== 10 && sra
&&
1817 array
.layout
== ((1 << 8) + 2) && !(array
.raid_disks
& 1)) ||
1818 (s
->level
== 0 && array
.level
== 1 && sra
)) {
1820 err
= remove_disks_for_takeover(st
, sra
, array
.layout
);
1822 dprintf(Name
": Array cannot be reshaped\n");
1828 /* Make sure mdmon has seen the device removal
1829 * and updated metadata before we continue with
1833 ping_monitor(container
);
1836 memset(&info
, 0, sizeof(info
));
1838 sysfs_init(&info
, fd
, NoMdDev
);
1839 strcpy(info
.text_version
, sra
->text_version
);
1840 info
.component_size
= s
->size
*2;
1841 info
.new_level
= s
->level
;
1842 info
.new_chunk
= s
->chunk
* 1024;
1843 if (info
.array
.level
== LEVEL_CONTAINER
) {
1844 info
.delta_disks
= UnSet
;
1845 info
.array
.raid_disks
= s
->raiddisks
;
1846 } else if (s
->raiddisks
)
1847 info
.delta_disks
= s
->raiddisks
- info
.array
.raid_disks
;
1849 info
.delta_disks
= UnSet
;
1850 if (s
->layout_str
== NULL
) {
1851 info
.new_layout
= UnSet
;
1852 if (info
.array
.level
== 6 &&
1853 (info
.new_level
== 6 || info
.new_level
== UnSet
) &&
1854 info
.array
.layout
>= 16) {
1855 pr_err("%s has a non-standard layout. If you"
1856 " wish to preserve this\n", devname
);
1857 cont_err("during the reshape, please specify"
1858 " --layout=preserve\n");
1859 cont_err("If you want to change it, specify a"
1860 " layout or use --layout=normalise\n");
1864 } else if (strcmp(s
->layout_str
, "normalise") == 0 ||
1865 strcmp(s
->layout_str
, "normalize") == 0) {
1866 /* If we have a -6 RAID6 layout, remove the '-6'. */
1867 info
.new_layout
= UnSet
;
1868 if (info
.array
.level
== 6 && info
.new_level
== UnSet
) {
1870 strcpy(l
, map_num(r6layout
, info
.array
.layout
));
1871 h
= strrchr(l
, '-');
1872 if (h
&& strcmp(h
, "-6") == 0) {
1874 info
.new_layout
= map_name(r6layout
, l
);
1877 pr_err("%s is only meaningful when reshaping"
1878 " a RAID6 array.\n", s
->layout_str
);
1882 } else if (strcmp(s
->layout_str
, "preserve") == 0) {
1883 /* This means that a non-standard RAID6 layout
1886 * - When reshape a RAID6 (e.g. adding a device)
1887 * which is in a non-standard layout, it is OK
1888 * to preserve that layout.
1889 * - When converting a RAID5 to RAID6, leave it in
1890 * the XXX-6 layout, don't re-layout.
1892 if (info
.array
.level
== 6 && info
.new_level
== UnSet
)
1893 info
.new_layout
= info
.array
.layout
;
1894 else if (info
.array
.level
== 5 && info
.new_level
== 6) {
1896 strcpy(l
, map_num(r5layout
, info
.array
.layout
));
1898 info
.new_layout
= map_name(r6layout
, l
);
1900 pr_err("%s in only meaningful when reshaping"
1901 " to RAID6\n", s
->layout_str
);
1906 int l
= info
.new_level
;
1908 l
= info
.array
.level
;
1911 info
.new_layout
= map_name(r5layout
, s
->layout_str
);
1914 info
.new_layout
= map_name(r6layout
, s
->layout_str
);
1917 info
.new_layout
= parse_layout_10(s
->layout_str
);
1920 info
.new_layout
= parse_layout_faulty(s
->layout_str
);
1923 pr_err("layout not meaningful"
1924 " with this level\n");
1928 if (info
.new_layout
== UnSet
) {
1929 pr_err("layout %s not understood"
1930 " for this level\n",
1937 if (array
.level
== LEVEL_FAULTY
) {
1938 if (s
->level
!= UnSet
&& s
->level
!= array
.level
) {
1939 pr_err("cannot change level of Faulty device\n");
1943 pr_err("cannot set chunksize of Faulty device\n");
1946 if (s
->raiddisks
&& s
->raiddisks
!= 1) {
1947 pr_err("cannot set raid_disks of Faulty device\n");
1950 if (s
->layout_str
) {
1951 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
1952 dprintf("Cannot get array information.\n");
1955 array
.layout
= info
.new_layout
;
1956 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
1957 pr_err("failed to set new layout\n");
1959 } else if (c
->verbose
>= 0)
1960 printf("layout for %s set to %d\n",
1961 devname
, array
.layout
);
1963 } else if (array
.level
== LEVEL_CONTAINER
) {
1964 /* This change is to be applied to every array in the
1965 * container. This is only needed when the metadata imposes
1966 * restraints of the various arrays in the container.
1967 * Currently we only know that IMSM requires all arrays
1968 * to have the same number of devices so changing the
1969 * number of devices (On-Line Capacity Expansion) must be
1970 * performed at the level of the container
1972 rv
= reshape_container(container
, devname
, -1, st
, &info
,
1973 c
->force
, c
->backup_file
, c
->verbose
, 0, 0);
1976 /* get spare devices from external metadata
1978 if (st
->ss
->external
) {
1979 struct mdinfo
*info2
;
1981 info2
= st
->ss
->container_content(st
, subarray
);
1983 info
.array
.spare_disks
=
1984 info2
->array
.spare_disks
;
1989 /* Impose these changes on a single array. First
1990 * check that the metadata is OK with the change. */
1992 if (reshape_super(st
, -1, info
.new_level
,
1993 info
.new_layout
, info
.new_chunk
,
1994 info
.array
.raid_disks
, info
.delta_disks
,
1995 c
->backup_file
, devname
, APPLY_METADATA_CHANGES
,
2001 rv
= reshape_array(container
, fd
, devname
, st
, &info
, c
->force
,
2002 devlist
, c
->backup_file
, c
->verbose
, 0, 0, 0);
2012 /* verify_reshape_position()
2013 * Function checks if reshape position in metadata is not farther
2014 * than position in md.
2016 * 0 : not valid sysfs entry
2017 * it can be caused by not started reshape, it should be started
2018 * by reshape array or raid0 array is before takeover
2019 * -1 : error, reshape position is obviously wrong
2020 * 1 : success, reshape progress correct or updated
2022 static int verify_reshape_position(struct mdinfo
*info
, int level
)
2028 /* read sync_max, failure can mean raid0 array */
2029 rv
= sysfs_get_str(info
, NULL
, "sync_max", buf
, 40);
2033 unsigned long long position
= strtoull(buf
, &ep
, 0);
2035 dprintf(Name
": Read sync_max sysfs entry is: %s\n", buf
);
2036 if (!(ep
== buf
|| (*ep
!= 0 && *ep
!= '\n' && *ep
!= ' '))) {
2037 position
*= get_data_disks(level
,
2039 info
->array
.raid_disks
);
2040 if (info
->reshape_progress
< position
) {
2041 dprintf("Corrected reshape progress (%llu) to "
2042 "md position (%llu)\n",
2043 info
->reshape_progress
, position
);
2044 info
->reshape_progress
= position
;
2046 } else if (info
->reshape_progress
> position
) {
2047 pr_err("Fatal error: array "
2048 "reshape was not properly frozen "
2049 "(expected reshape position is %llu, "
2050 "but reshape progress is %llu.\n",
2051 position
, info
->reshape_progress
);
2054 dprintf("Reshape position in md and metadata "
2059 } else if (rv
== 0) {
2060 /* for valid sysfs entry, 0-length content
2061 * should be indicated as error
2069 static int reshape_array(char *container
, int fd
, char *devname
,
2070 struct supertype
*st
, struct mdinfo
*info
,
2071 int force
, struct mddev_dev
*devlist
,
2072 char *backup_file
, int verbose
, int forked
,
2073 int restart
, int freeze_reshape
)
2075 struct reshape reshape
;
2078 int orig_level
= UnSet
;
2081 struct mdu_array_info_s array
;
2084 struct mddev_dev
*dv
;
2088 unsigned long long *offsets
= NULL
;
2092 unsigned long blocks
;
2093 unsigned long cache
;
2094 unsigned long long array_size
;
2096 struct mdinfo
*sra
= NULL
;
2098 /* when reshaping a RAID0, the component_size might be zero.
2099 * So try to fix that up.
2101 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
2102 dprintf("Cannot get array information.\n");
2105 if (array
.level
== 0 && info
->component_size
== 0) {
2106 get_dev_size(fd
, NULL
, &array_size
);
2107 info
->component_size
= array_size
/ array
.raid_disks
;
2110 if (info
->reshape_active
) {
2111 int new_level
= info
->new_level
;
2112 info
->new_level
= UnSet
;
2113 if (info
->delta_disks
> 0)
2114 info
->array
.raid_disks
-= info
->delta_disks
;
2115 msg
= analyse_change(info
, &reshape
);
2116 info
->new_level
= new_level
;
2117 if (info
->delta_disks
> 0)
2118 info
->array
.raid_disks
+= info
->delta_disks
;
2120 /* Make sure the array isn't read-only */
2121 ioctl(fd
, RESTART_ARRAY_RW
, 0);
2123 msg
= analyse_change(info
, &reshape
);
2125 pr_err("%s\n", msg
);
2129 (reshape
.level
!= info
->array
.level
||
2130 reshape
.before
.layout
!= info
->array
.layout
||
2131 reshape
.before
.data_disks
+ reshape
.parity
2132 != info
->array
.raid_disks
- max(0, info
->delta_disks
))) {
2133 pr_err("reshape info is not in native format -"
2134 " cannot continue.\n");
2138 if (st
->ss
->external
&& restart
&& (info
->reshape_progress
== 0)) {
2139 /* When reshape is restarted from '0', very begin of array
2140 * it is possible that for external metadata reshape and array
2141 * configuration doesn't happen.
2142 * Check if md has the same opinion, and reshape is restarted
2143 * from 0. If so, this is regular reshape start after reshape
2144 * switch in metadata to next array only.
2146 if ((verify_reshape_position(info
, reshape
.level
) >= 0) &&
2147 (info
->reshape_progress
== 0))
2151 /* reshape already started. just skip to monitoring the reshape */
2152 if (reshape
.backup_blocks
== 0)
2156 /* The container is frozen but the array may not be.
2157 * So freeze the array so spares don't get put to the wrong use
2158 * FIXME there should probably be a cleaner separation between
2159 * freeze_array and freeze_container.
2161 sysfs_freeze_array(info
);
2162 /* Check we have enough spares to not be degraded */
2164 for (dv
= devlist
; dv
; dv
=dv
->next
)
2166 spares_needed
= max(reshape
.before
.data_disks
,
2167 reshape
.after
.data_disks
)
2168 + reshape
.parity
- array
.raid_disks
;
2171 info
->new_level
> 1 && info
->array
.level
> 1 &&
2172 spares_needed
> info
->array
.spare_disks
+ added_disks
) {
2173 pr_err("Need %d spare%s to avoid degraded array,"
2174 " and only have %d.\n"
2175 " Use --force to over-ride this check.\n",
2177 spares_needed
== 1 ? "" : "s",
2178 info
->array
.spare_disks
+ added_disks
);
2181 /* Check we have enough spares to not fail */
2182 spares_needed
= max(reshape
.before
.data_disks
,
2183 reshape
.after
.data_disks
)
2185 if ((info
->new_level
> 1 || info
->new_level
== 0) &&
2186 spares_needed
> info
->array
.spare_disks
+added_disks
) {
2187 pr_err("Need %d spare%s to create working array,"
2188 " and only have %d.\n",
2190 spares_needed
== 1 ? "" : "s",
2191 info
->array
.spare_disks
+ added_disks
);
2195 if (reshape
.level
!= array
.level
) {
2196 char *c
= map_num(pers
, reshape
.level
);
2201 err
= sysfs_set_str(info
, NULL
, "level", c
);
2204 pr_err("%s: could not set level to %s\n",
2207 (info
->array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2208 cont_err("Bitmap must be removed"
2209 " before level can be changed\n");
2213 pr_err("level of %s changed to %s\n",
2215 orig_level
= array
.level
;
2216 sysfs_freeze_array(info
);
2218 if (reshape
.level
> 0 && st
->ss
->external
) {
2219 /* make sure mdmon is aware of the new level */
2220 if (mdmon_running(st
->container_dev
))
2221 flush_mdmon(container
);
2223 if (!mdmon_running(st
->container_dev
))
2224 start_mdmon(st
->container_dev
);
2225 ping_monitor(container
);
2226 if (mdmon_running(st
->container_dev
) &&
2227 st
->update_tail
== NULL
)
2228 st
->update_tail
= &st
->updates
;
2231 /* ->reshape_super might have chosen some spares from the
2232 * container that it wants to be part of the new array.
2233 * We can collect them with ->container_content and give
2234 * them to the kernel.
2236 if (st
->ss
->reshape_super
&& st
->ss
->container_content
) {
2237 char *subarray
= strchr(info
->text_version
+1, '/')+1;
2238 struct mdinfo
*info2
=
2239 st
->ss
->container_content(st
, subarray
);
2243 sysfs_init(info2
, fd
, st
->devnum
);
2244 /* When increasing number of devices, we need to set
2245 * new raid_disks before adding these, or they might
2248 if (reshape
.backup_blocks
&&
2249 reshape
.after
.data_disks
> reshape
.before
.data_disks
)
2250 subarray_set_num(container
, info2
, "raid_disks",
2251 reshape
.after
.data_disks
+
2253 for (d
= info2
->devs
; d
; d
= d
->next
) {
2254 if (d
->disk
.state
== 0 &&
2255 d
->disk
.raid_disk
>= 0) {
2256 /* This is a spare that wants to
2257 * be part of the array.
2259 add_disk(fd
, st
, info2
, d
);
2265 /* We might have been given some devices to add to the
2266 * array. Now that the array has been changed to the right
2267 * level and frozen, we can safely add them.
2270 Manage_subdevs(devname
, fd
, devlist
, verbose
,
2273 if (reshape
.backup_blocks
== 0) {
2274 /* No restriping needed, but we might need to impose
2275 * some more changes: layout, raid_disks, chunk_size
2277 /* read current array info */
2278 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
2279 dprintf("Cannot get array information.\n");
2282 /* compare current array info with new values and if
2283 * it is different update them to new */
2284 if (info
->new_layout
!= UnSet
&&
2285 info
->new_layout
!= array
.layout
) {
2286 array
.layout
= info
->new_layout
;
2287 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2288 pr_err("failed to set new layout\n");
2290 } else if (verbose
>= 0)
2291 printf("layout for %s set to %d\n",
2292 devname
, array
.layout
);
2294 if (info
->delta_disks
!= UnSet
&&
2295 info
->delta_disks
!= 0 &&
2296 array
.raid_disks
!= (info
->array
.raid_disks
+ info
->delta_disks
)) {
2297 array
.raid_disks
+= info
->delta_disks
;
2298 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2299 pr_err("failed to set raid disks\n");
2301 } else if (verbose
>= 0) {
2302 printf("raid_disks for %s set to %d\n",
2303 devname
, array
.raid_disks
);
2306 if (info
->new_chunk
!= 0 &&
2307 info
->new_chunk
!= array
.chunk_size
) {
2308 if (sysfs_set_num(info
, NULL
,
2309 "chunk_size", info
->new_chunk
) != 0) {
2310 pr_err("failed to set chunk size\n");
2312 } else if (verbose
>= 0)
2313 printf("chunk size for %s set to %d\n",
2314 devname
, array
.chunk_size
);
2321 * There are three possibilities.
2322 * 1/ The array will shrink.
2323 * We need to ensure the reshape will pause before reaching
2324 * the 'critical section'. We also need to fork and wait for
2325 * that to happen. When it does we
2326 * suspend/backup/complete/unfreeze
2328 * 2/ The array will not change size.
2329 * This requires that we keep a backup of a sliding window
2330 * so that we can restore data after a crash. So we need
2331 * to fork and monitor progress.
2332 * In future we will allow the data_offset to change, so
2333 * a sliding backup becomes unnecessary.
2335 * 3/ The array will grow. This is relatively easy.
2336 * However the kernel's restripe routines will cheerfully
2337 * overwrite some early data before it is safe. So we
2338 * need to make a backup of the early parts of the array
2339 * and be ready to restore it if rebuild aborts very early.
2340 * For externally managed metadata, we still need a forked
2341 * child to monitor the reshape and suspend IO over the region
2342 * that is being reshaped.
2344 * We backup data by writing it to one spare, or to a
2345 * file which was given on command line.
2347 * In each case, we first make sure that storage is available
2348 * for the required backup.
2350 * - request the shape change.
2351 * - fork to handle backup etc.
2354 /* Check that we can hold all the data */
2355 get_dev_size(fd
, NULL
, &array_size
);
2356 if (reshape
.new_size
< (array_size
/512)) {
2357 pr_err("this change will reduce the size of the array.\n"
2358 " use --grow --array-size first to truncate array.\n"
2359 " e.g. mdadm --grow %s --array-size %llu\n",
2360 devname
, reshape
.new_size
/2);
2364 sra
= sysfs_read(fd
, 0,
2365 GET_COMPONENT
|GET_DEVS
|GET_OFFSET
|GET_STATE
|GET_CHUNK
|
2368 pr_err("%s: Cannot get array details from sysfs\n",
2373 /* Decide how many blocks (sectors) for a reshape
2374 * unit. The number we have so far is just a minimum
2376 blocks
= reshape
.backup_blocks
;
2377 if (reshape
.before
.data_disks
==
2378 reshape
.after
.data_disks
) {
2379 /* Make 'blocks' bigger for better throughput, but
2380 * not so big that we reject it below.
2381 * Try for 16 megabytes
2383 while (blocks
* 32 < sra
->component_size
&&
2387 pr_err("Need to backup %luK of critical "
2388 "section..\n", blocks
/2);
2390 if (blocks
>= sra
->component_size
/2) {
2391 pr_err("%s: Something wrong"
2392 " - reshape aborted\n",
2397 /* Now we need to open all these devices so we can read/write.
2399 nrdisks
= max(reshape
.before
.data_disks
,
2400 reshape
.after
.data_disks
) + reshape
.parity
2401 + sra
->array
.spare_disks
;
2402 fdlist
= xcalloc((1+nrdisks
), sizeof(int));
2403 offsets
= xcalloc((1+nrdisks
), sizeof(offsets
[0]));
2405 odisks
= reshape
.before
.data_disks
+ reshape
.parity
;
2406 d
= reshape_prepare_fdlist(devname
, sra
, odisks
,
2407 nrdisks
, blocks
, backup_file
,
2412 if ((st
->ss
->manage_reshape
== NULL
) ||
2413 (st
->ss
->recover_backup
== NULL
)) {
2414 if (backup_file
== NULL
) {
2415 if (reshape
.after
.data_disks
<=
2416 reshape
.before
.data_disks
) {
2417 pr_err("%s: Cannot grow - "
2418 "need backup-file\n", devname
);
2420 } else if (sra
->array
.spare_disks
== 0) {
2421 pr_err("%s: Cannot grow - "
2422 "need a spare or backup-file to backup "
2423 "critical section\n", devname
);
2427 if (!reshape_open_backup_file(backup_file
, fd
, devname
,
2429 fdlist
+d
, offsets
+d
,
2437 /* lastly, check that the internal stripe cache is
2438 * large enough, or it won't work.
2439 * It must hold at least 4 stripes of the larger
2442 cache
= max(info
->array
.chunk_size
, info
->new_chunk
);
2443 cache
*= 4; /* 4 stripes minimum */
2444 cache
/= 512; /* convert to sectors */
2445 disks
= min(reshape
.before
.data_disks
, reshape
.after
.data_disks
);
2446 /* make sure there is room for 'blocks' with a bit to spare */
2447 if (cache
< 16 + blocks
/ disks
)
2448 cache
= 16 + blocks
/ disks
;
2449 cache
/= (4096/512); /* Covert from sectors to pages */
2451 if (sra
->cache_size
< cache
)
2452 subarray_set_num(container
, sra
, "stripe_cache_size",
2455 /* Right, everything seems fine. Let's kick things off.
2456 * If only changing raid_disks, use ioctl, else use
2461 sra
->new_chunk
= info
->new_chunk
;
2464 /* for external metadata checkpoint saved by mdmon can be lost
2465 * or missed /due to e.g. crash/. Check if md is not during
2466 * restart farther than metadata points to.
2467 * If so, this means metadata information is obsolete.
2469 if (st
->ss
->external
)
2470 verify_reshape_position(info
, reshape
.level
);
2471 sra
->reshape_progress
= info
->reshape_progress
;
2473 sra
->reshape_progress
= 0;
2474 if (reshape
.after
.data_disks
< reshape
.before
.data_disks
)
2475 /* start from the end of the new array */
2476 sra
->reshape_progress
= (sra
->component_size
2477 * reshape
.after
.data_disks
);
2480 if (info
->array
.chunk_size
== info
->new_chunk
&&
2481 reshape
.before
.layout
== reshape
.after
.layout
&&
2482 st
->ss
->external
== 0) {
2483 /* use SET_ARRAY_INFO but only if reshape hasn't started */
2484 ioctl(fd
, GET_ARRAY_INFO
, &array
);
2485 array
.raid_disks
= reshape
.after
.data_disks
+ reshape
.parity
;
2487 ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2490 pr_err("Cannot set device shape for %s: %s\n",
2491 devname
, strerror(errno
));
2494 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2495 cont_err("Bitmap must be removed before"
2496 " shape can be changed\n");
2500 } else if (!restart
) {
2501 /* set them all just in case some old 'new_*' value
2502 * persists from some earlier problem.
2505 if (sysfs_set_num(sra
, NULL
, "chunk_size", info
->new_chunk
) < 0)
2507 if (!err
&& sysfs_set_num(sra
, NULL
, "layout",
2508 reshape
.after
.layout
) < 0)
2510 if (!err
&& subarray_set_num(container
, sra
, "raid_disks",
2511 reshape
.after
.data_disks
+
2512 reshape
.parity
) < 0)
2515 pr_err("Cannot set device shape for %s\n",
2519 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2520 cont_err("Bitmap must be removed before"
2521 " shape can be changed\n");
2526 err
= start_reshape(sra
, restart
, reshape
.before
.data_disks
,
2527 reshape
.after
.data_disks
);
2529 pr_err("Cannot %s reshape for %s\n",
2530 restart
? "continue" : "start",
2535 sysfs_set_str(sra
, NULL
, "array_state", "active");
2536 if (freeze_reshape
) {
2540 pr_err("Reshape has to be continued from"
2541 " location %llu when root filesystem has been mounted.\n",
2542 sra
->reshape_progress
);
2546 /* Now we just need to kick off the reshape and watch, while
2547 * handling backups of the data...
2548 * This is all done by a forked background process.
2550 switch(forked
? 0 : fork()) {
2552 pr_err("Cannot run child to monitor reshape: %s\n",
2567 if (check_env("MDADM_GROW_VERIFY"))
2568 fd
= open(devname
, O_RDONLY
| O_DIRECT
);
2571 mlockall(MCL_FUTURE
);
2573 if (st
->ss
->external
) {
2574 /* metadata handler takes it from here */
2575 done
= st
->ss
->manage_reshape(
2576 fd
, sra
, &reshape
, st
, blocks
,
2578 d
- odisks
, fdlist
+odisks
,
2581 done
= child_monitor(
2582 fd
, sra
, &reshape
, st
, blocks
,
2584 d
- odisks
, fdlist
+odisks
,
2590 if (backup_file
&& done
)
2591 unlink(backup_file
);
2597 if (!st
->ss
->external
&&
2598 !(reshape
.before
.data_disks
!= reshape
.after
.data_disks
2599 && info
->custom_array_size
) &&
2600 info
->new_level
== reshape
.level
&&
2602 /* no need to wait for the reshape to finish as
2603 * there is nothing more to do.
2610 if (st
->ss
->external
) {
2611 /* Re-load the metadata as much could have changed */
2612 int cfd
= open_dev(st
->container_dev
);
2614 flush_mdmon(container
);
2615 st
->ss
->free_super(st
);
2616 st
->ss
->load_container(st
, cfd
, container
);
2621 /* set new array size if required customer_array_size is used
2624 if (reshape
.before
.data_disks
!=
2625 reshape
.after
.data_disks
&&
2626 info
->custom_array_size
)
2627 set_array_size(st
, info
, info
->text_version
);
2629 if (info
->new_level
!= reshape
.level
) {
2631 c
= map_num(pers
, info
->new_level
);
2633 err
= sysfs_set_str(sra
, NULL
, "level", c
);
2635 pr_err("%s: could not set level "
2636 "to %s\n", devname
, c
);
2638 if (info
->new_level
== 0)
2639 st
->update_tail
= NULL
;
2651 if (orig_level
!= UnSet
&& sra
) {
2652 c
= map_num(pers
, orig_level
);
2653 if (c
&& sysfs_set_str(sra
, NULL
, "level", c
) == 0)
2654 pr_err("aborting level change\n");
2662 /* mdfd handle is passed to be closed in child process (after fork).
2664 int reshape_container(char *container
, char *devname
,
2666 struct supertype
*st
,
2667 struct mdinfo
*info
,
2670 int verbose
, int restart
, int freeze_reshape
)
2672 struct mdinfo
*cc
= NULL
;
2674 int last_devnum
= -1;
2676 /* component_size is not meaningful for a container,
2677 * so pass '-1' meaning 'no change'
2680 reshape_super(st
, -1, info
->new_level
,
2681 info
->new_layout
, info
->new_chunk
,
2682 info
->array
.raid_disks
, info
->delta_disks
,
2683 backup_file
, devname
, APPLY_METADATA_CHANGES
,
2691 /* ping monitor to be sure that update is on disk
2693 ping_monitor(container
);
2696 case -1: /* error */
2697 perror("Cannot fork to complete reshape\n");
2700 default: /* parent */
2701 if (!freeze_reshape
)
2702 printf(Name
": multi-array reshape continues"
2703 " in background\n");
2710 /* close unused handle in child process
2716 /* For each member array with reshape_active,
2717 * we need to perform the reshape.
2718 * We pick the first array that needs reshaping and
2719 * reshape it. reshape_array() will re-read the metadata
2720 * so the next time through a different array should be
2721 * ready for reshape.
2722 * It is possible that the 'different' array will not
2723 * be assembled yet. In that case we simple exit.
2724 * When it is assembled, the mdadm which assembles it
2725 * will take over the reshape.
2727 struct mdinfo
*content
;
2729 struct mdstat_ent
*mdstat
;
2734 cc
= st
->ss
->container_content(st
, NULL
);
2736 for (content
= cc
; content
; content
= content
->next
) {
2738 if (!content
->reshape_active
)
2741 subarray
= strchr(content
->text_version
+1, '/')+1;
2742 mdstat
= mdstat_by_subdev(subarray
,
2743 devname2devnum(container
));
2746 if (mdstat
->active
== 0) {
2747 pr_err("Skipping inactive "
2748 "array md%i.\n", mdstat
->devnum
);
2749 free_mdstat(mdstat
);
2758 adev
= map_dev(dev2major(mdstat
->devnum
),
2759 dev2minor(mdstat
->devnum
),
2762 adev
= content
->text_version
;
2764 fd
= open_dev(mdstat
->devnum
);
2766 printf(Name
": Device %s cannot be opened for reshape.",
2771 if (last_devnum
== mdstat
->devnum
) {
2772 /* Do not allow for multiple reshape_array() calls for
2774 * It can happen when reshape_array() returns without
2775 * error, when reshape is not finished (wrong reshape
2776 * starting/continuation conditions). Mdmon doesn't
2777 * switch to next array in container and reentry
2778 * conditions for the same array occur.
2779 * This is possibly interim until the behaviour of
2780 * reshape_array is resolved().
2782 printf(Name
": Multiple reshape execution detected for "
2783 "device %s.", adev
);
2787 last_devnum
= mdstat
->devnum
;
2789 sysfs_init(content
, fd
, mdstat
->devnum
);
2791 if (mdmon_running(devname2devnum(container
)))
2792 flush_mdmon(container
);
2794 rv
= reshape_array(container
, fd
, adev
, st
,
2795 content
, force
, NULL
,
2796 backup_file
, verbose
, 1, restart
,
2800 if (freeze_reshape
) {
2809 if (mdmon_running(devname2devnum(container
)))
2810 flush_mdmon(container
);
2819 * We run a child process in the background which performs the following
2821 * - wait for resync to reach a certain point
2822 * - suspend io to the following section
2823 * - backup that section
2824 * - allow resync to proceed further
2826 * - discard the backup.
2828 * When are combined in slightly different ways in the three cases.
2830 * - suspend/backup/allow/wait/resume/discard
2832 * - allow/wait/suspend/backup/allow/wait/resume/discard
2834 * - wait/resume/discard/suspend/backup/allow
2836 * suspend/backup/allow always come together
2837 * wait/resume/discard do too.
2838 * For the same-size case we have two backups to improve flow.
2842 int progress_reshape(struct mdinfo
*info
, struct reshape
*reshape
,
2843 unsigned long long backup_point
,
2844 unsigned long long wait_point
,
2845 unsigned long long *suspend_point
,
2846 unsigned long long *reshape_completed
)
2848 /* This function is called repeatedly by the reshape manager.
2849 * It determines how much progress can safely be made and allows
2851 * - 'info' identifies the array and particularly records in
2852 * ->reshape_progress the metadata's knowledge of progress
2853 * This is a sector offset from the start of the array
2854 * of the next array block to be relocated. This number
2855 * may increase from 0 or decrease from array_size, depending
2856 * on the type of reshape that is happening.
2857 * Note that in contrast, 'sync_completed' is a block count of the
2858 * reshape so far. It gives the distance between the start point
2859 * (head or tail of device) and the next place that data will be
2860 * written. It always increases.
2861 * - 'reshape' is the structure created by analyse_change
2862 * - 'backup_point' shows how much the metadata manager has backed-up
2863 * data. For reshapes with increasing progress, it is the next address
2864 * to be backed up, previous addresses have been backed-up. For
2865 * decreasing progress, it is the earliest address that has been
2866 * backed up - later address are also backed up.
2867 * So addresses between reshape_progress and backup_point are
2868 * backed up providing those are in the 'correct' order.
2869 * - 'wait_point' is an array address. When reshape_completed
2870 * passes this point, progress_reshape should return. It might
2871 * return earlier if it determines that ->reshape_progress needs
2872 * to be updated or further backup is needed.
2873 * - suspend_point is maintained by progress_reshape and the caller
2874 * should not touch it except to initialise to zero.
2875 * It is an array address and it only increases in 2.6.37 and earlier.
2876 * This makes it difficult to handle reducing reshapes with
2877 * external metadata.
2878 * However: it is similar to backup_point in that it records the
2879 * other end of a suspended region from reshape_progress.
2880 * it is moved to extend the region that is safe to backup and/or
2882 * - reshape_completed is read from sysfs and returned. The caller
2883 * should copy this into ->reshape_progress when it has reason to
2884 * believe that the metadata knows this, and any backup outside this
2888 * 1 if more data from backup_point - but only as far as suspend_point,
2889 * should be backed up
2890 * 0 if things are progressing smoothly
2891 * -1 if the reshape is finished because it is all done,
2892 * -2 if the reshape is finished due to an error.
2895 int advancing
= (reshape
->after
.data_disks
2896 >= reshape
->before
.data_disks
);
2897 unsigned long long need_backup
; /* All data between start of array and
2898 * here will at some point need to
2901 unsigned long long read_offset
, write_offset
;
2902 unsigned long long write_range
;
2903 unsigned long long max_progress
, target
, completed
;
2904 unsigned long long array_size
= (info
->component_size
2905 * reshape
->before
.data_disks
);
2909 /* First, we unsuspend any region that is now known to be safe.
2910 * If suspend_point is on the 'wrong' side of reshape_progress, then
2911 * we don't have or need suspension at the moment. This is true for
2912 * native metadata when we don't need to back-up.
2915 if (info
->reshape_progress
<= *suspend_point
)
2916 sysfs_set_num(info
, NULL
, "suspend_lo",
2917 info
->reshape_progress
);
2919 /* Note: this won't work in 2.6.37 and before.
2920 * Something somewhere should make sure we don't need it!
2922 if (info
->reshape_progress
>= *suspend_point
)
2923 sysfs_set_num(info
, NULL
, "suspend_hi",
2924 info
->reshape_progress
);
2927 /* Now work out how far it is safe to progress.
2928 * If the read_offset for ->reshape_progress is less than
2929 * 'blocks' beyond the write_offset, we can only progress as far
2931 * Otherwise we can progress until the write_offset for the new location
2932 * reaches (within 'blocks' of) the read_offset at the current location.
2933 * However that region must be suspended unless we are using native
2935 * If we need to suspend more, we limit it to 128M per device, which is
2936 * rather arbitrary and should be some time-based calculation.
2938 read_offset
= info
->reshape_progress
/ reshape
->before
.data_disks
;
2939 write_offset
= info
->reshape_progress
/ reshape
->after
.data_disks
;
2940 write_range
= info
->new_chunk
/512;
2941 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
)
2942 need_backup
= array_size
;
2944 need_backup
= reshape
->backup_blocks
;
2946 if (read_offset
< write_offset
+ write_range
)
2947 max_progress
= backup_point
;
2951 reshape
->after
.data_disks
;
2953 if (read_offset
> write_offset
- write_range
)
2954 /* Can only progress as far as has been backed up,
2955 * which must be suspended */
2956 max_progress
= backup_point
;
2957 else if (info
->reshape_progress
<= need_backup
)
2958 max_progress
= backup_point
;
2960 if (info
->array
.major_version
>= 0)
2961 /* Can progress until backup is needed */
2962 max_progress
= need_backup
;
2964 /* Can progress until metadata update is required */
2967 reshape
->after
.data_disks
;
2968 /* but data must be suspended */
2969 if (max_progress
< *suspend_point
)
2970 max_progress
= *suspend_point
;
2975 /* We know it is safe to progress to 'max_progress' providing
2976 * it is suspended or we are using native metadata.
2977 * Consider extending suspend_point 128M per device if it
2978 * is less than 64M per device beyond reshape_progress.
2979 * But always do a multiple of 'blocks'
2980 * FIXME this is too big - it takes to long to complete
2983 target
= 64*1024*2 * min(reshape
->before
.data_disks
,
2984 reshape
->after
.data_disks
);
2985 target
/= reshape
->backup_blocks
;
2988 target
*= reshape
->backup_blocks
;
2990 /* For externally managed metadata we always need to suspend IO to
2991 * the area being reshaped so we regularly push suspend_point forward.
2992 * For native metadata we only need the suspend if we are going to do
2996 if ((need_backup
> info
->reshape_progress
2997 || info
->array
.major_version
< 0) &&
2998 *suspend_point
< info
->reshape_progress
+ target
) {
2999 if (need_backup
< *suspend_point
+ 2 * target
)
3000 *suspend_point
= need_backup
;
3001 else if (*suspend_point
+ 2 * target
< array_size
)
3002 *suspend_point
+= 2 * target
;
3004 *suspend_point
= array_size
;
3005 sysfs_set_num(info
, NULL
, "suspend_hi", *suspend_point
);
3006 if (max_progress
> *suspend_point
)
3007 max_progress
= *suspend_point
;
3010 if (info
->array
.major_version
>= 0) {
3011 /* Only need to suspend when about to backup */
3012 if (info
->reshape_progress
< need_backup
* 2 &&
3013 *suspend_point
> 0) {
3015 sysfs_set_num(info
, NULL
, "suspend_lo", 0);
3016 sysfs_set_num(info
, NULL
, "suspend_hi", need_backup
);
3019 /* Need to suspend continually */
3020 if (info
->reshape_progress
< *suspend_point
)
3021 *suspend_point
= info
->reshape_progress
;
3022 if (*suspend_point
+ target
< info
->reshape_progress
)
3023 /* No need to move suspend region yet */;
3025 if (*suspend_point
>= 2 * target
)
3026 *suspend_point
-= 2 * target
;
3029 sysfs_set_num(info
, NULL
, "suspend_lo",
3032 if (max_progress
< *suspend_point
)
3033 max_progress
= *suspend_point
;
3037 /* now set sync_max to allow that progress. sync_max, like
3038 * sync_completed is a count of sectors written per device, so
3039 * we find the difference between max_progress and the start point,
3040 * and divide that by after.data_disks to get a sync_max
3042 * At the same time we convert wait_point to a similar number
3043 * for comparing against sync_completed.
3045 /* scale down max_progress to per_disk */
3046 max_progress
/= reshape
->after
.data_disks
;
3047 /* Round to chunk size as some kernels give an erroneously high number */
3048 max_progress
/= info
->new_chunk
/512;
3049 max_progress
*= info
->new_chunk
/512;
3050 /* And round to old chunk size as the kernel wants that */
3051 max_progress
/= info
->array
.chunk_size
/512;
3052 max_progress
*= info
->array
.chunk_size
/512;
3053 /* Limit progress to the whole device */
3054 if (max_progress
> info
->component_size
)
3055 max_progress
= info
->component_size
;
3056 wait_point
/= reshape
->after
.data_disks
;
3058 /* switch from 'device offset' to 'processed block count' */
3059 max_progress
= info
->component_size
- max_progress
;
3060 wait_point
= info
->component_size
- wait_point
;
3063 sysfs_set_num(info
, NULL
, "sync_max", max_progress
);
3065 /* Now wait. If we have already reached the point that we were
3066 * asked to wait to, don't wait at all, else wait for any change.
3067 * We need to select on 'sync_completed' as that is the place that
3068 * notifications happen, but we are really interested in
3069 * 'reshape_position'
3071 fd
= sysfs_get_fd(info
, NULL
, "sync_completed");
3073 goto check_progress
;
3075 if (sysfs_fd_get_ll(fd
, &completed
) < 0)
3076 goto check_progress
;
3078 while (completed
< max_progress
&& completed
< wait_point
) {
3079 /* Check that sync_action is still 'reshape' to avoid
3080 * waiting forever on a dead array
3084 if (sysfs_get_str(info
, NULL
, "sync_action",
3086 strncmp(action
, "reshape", 7) != 0)
3088 /* Some kernels reset 'sync_completed' to zero
3089 * before setting 'sync_action' to 'idle'.
3090 * So we need these extra tests.
3092 if (completed
== 0 && advancing
3093 && info
->reshape_progress
> 0)
3095 if (completed
== 0 && !advancing
3096 && info
->reshape_progress
< (info
->component_size
3097 * reshape
->after
.data_disks
))
3101 select(fd
+1, NULL
, NULL
, &rfds
, NULL
);
3102 if (sysfs_fd_get_ll(fd
, &completed
) < 0)
3103 goto check_progress
;
3105 /* Some kernels reset 'sync_completed' to zero,
3106 * we need to have real point we are in md
3109 completed
= max_progress
;
3111 /* some kernels can give an incorrectly high 'completed' number */
3112 completed
/= (info
->new_chunk
/512);
3113 completed
*= (info
->new_chunk
/512);
3114 /* Convert 'completed' back in to a 'progress' number */
3115 completed
*= reshape
->after
.data_disks
;
3117 completed
= info
->component_size
* reshape
->after
.data_disks
3120 *reshape_completed
= completed
;
3124 /* We return the need_backup flag. Caller will decide
3125 * how much - a multiple of ->backup_blocks up to *suspend_point
3128 return need_backup
> info
->reshape_progress
;
3130 return need_backup
>= info
->reshape_progress
;
3133 /* if we couldn't read a number from sync_completed, then
3134 * either the reshape did complete, or it aborted.
3135 * We can tell which by checking for 'none' in reshape_position.
3136 * If it did abort, then it might immediately restart if it
3137 * it was just a device failure that leaves us degraded but
3141 if (sysfs_get_str(info
, NULL
, "reshape_position", buf
, sizeof(buf
)) < 0
3142 || strncmp(buf
, "none", 4) != 0) {
3143 /* The abort might only be temporary. Wait up to 10
3144 * seconds for fd to contain a valid number again.
3150 while (fd
>= 0 && rv
< 0 && tv
.tv_sec
> 0) {
3154 if (select(fd
+1, NULL
, NULL
, &rfds
, &tv
) != 1)
3156 switch (sysfs_fd_get_ll(fd
, &completed
)) {
3158 /* all good again */
3161 case -2: /* read error - abort */
3168 return rv
; /* abort */
3170 /* Maybe racing with array shutdown - check state */
3173 if (sysfs_get_str(info
, NULL
, "array_state", buf
, sizeof(buf
)) < 0
3174 || strncmp(buf
, "inactive", 8) == 0
3175 || strncmp(buf
, "clear",5) == 0)
3176 return -2; /* abort */
3177 return -1; /* complete */
3181 /* FIXME return status is never checked */
3182 static int grow_backup(struct mdinfo
*sra
,
3183 unsigned long long offset
, /* per device */
3184 unsigned long stripes
, /* per device, in old chunks */
3185 int *sources
, unsigned long long *offsets
,
3186 int disks
, int chunk
, int level
, int layout
,
3187 int dests
, int *destfd
, unsigned long long *destoffsets
,
3188 int part
, int *degraded
,
3191 /* Backup 'blocks' sectors at 'offset' on each device of the array,
3192 * to storage 'destfd' (offset 'destoffsets'), after first
3193 * suspending IO. Then allow resync to continue
3194 * over the suspended section.
3195 * Use part 'part' of the backup-super-block.
3200 unsigned long long ll
;
3202 //printf("offset %llu\n", offset);
3208 /* Check that array hasn't become degraded, else we might backup the wrong data */
3209 if (sysfs_get_ll(sra
, NULL
, "degraded", &ll
) < 0)
3210 return -1; /* FIXME this error is ignored */
3211 new_degraded
= (int)ll
;
3212 if (new_degraded
!= *degraded
) {
3213 /* check each device to ensure it is still working */
3215 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
3216 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
3218 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
3220 if (sysfs_get_str(sra
, sd
, "state", sbuf
, 20) < 0 ||
3221 strstr(sbuf
, "faulty") ||
3222 strstr(sbuf
, "in_sync") == NULL
) {
3223 /* this device is dead */
3224 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
3225 if (sd
->disk
.raid_disk
>= 0 &&
3226 sources
[sd
->disk
.raid_disk
] >= 0) {
3227 close(sources
[sd
->disk
.raid_disk
]);
3228 sources
[sd
->disk
.raid_disk
] = -1;
3233 *degraded
= new_degraded
;
3236 bsb
.arraystart2
= __cpu_to_le64(offset
* odata
);
3237 bsb
.length2
= __cpu_to_le64(stripes
* (chunk
/512) * odata
);
3239 bsb
.arraystart
= __cpu_to_le64(offset
* odata
);
3240 bsb
.length
= __cpu_to_le64(stripes
* (chunk
/512) * odata
);
3243 bsb
.magic
[15] = '2';
3244 for (i
= 0; i
< dests
; i
++)
3246 lseek64(destfd
[i
], destoffsets
[i
] + __le64_to_cpu(bsb
.devstart2
)*512, 0);
3248 lseek64(destfd
[i
], destoffsets
[i
], 0);
3250 rv
= save_stripes(sources
, offsets
,
3251 disks
, chunk
, level
, layout
,
3253 offset
*512*odata
, stripes
* chunk
* odata
,
3258 bsb
.mtime
= __cpu_to_le64(time(0));
3259 for (i
= 0; i
< dests
; i
++) {
3260 bsb
.devstart
= __cpu_to_le64(destoffsets
[i
]/512);
3262 bsb
.sb_csum
= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
));
3263 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0)
3264 bsb
.sb_csum2
= bsb_csum((char*)&bsb
,
3265 ((char*)&bsb
.sb_csum2
)-((char*)&bsb
));
3268 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
] - 4096, 0)
3269 != destoffsets
[i
] - 4096)
3271 if (write(destfd
[i
], &bsb
, 512) != 512)
3273 if (destoffsets
[i
] > 4096) {
3274 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
]+stripes
*chunk
*odata
, 0) !=
3275 destoffsets
[i
]+stripes
*chunk
*odata
)
3277 if (write(destfd
[i
], &bsb
, 512) != 512)
3287 /* in 2.6.30, the value reported by sync_completed can be
3288 * less that it should be by one stripe.
3289 * This only happens when reshape hits sync_max and pauses.
3290 * So allow wait_backup to either extent sync_max further
3291 * than strictly necessary, or return before the
3292 * sync has got quite as far as we would really like.
3293 * This is what 'blocks2' is for.
3294 * The various caller give appropriate values so that
3297 /* FIXME return value is often ignored */
3298 static int forget_backup(int dests
, int *destfd
,
3299 unsigned long long *destoffsets
,
3303 * Erase backup 'part' (which is 0 or 1)
3309 bsb
.arraystart2
= __cpu_to_le64(0);
3310 bsb
.length2
= __cpu_to_le64(0);
3312 bsb
.arraystart
= __cpu_to_le64(0);
3313 bsb
.length
= __cpu_to_le64(0);
3315 bsb
.mtime
= __cpu_to_le64(time(0));
3317 for (i
= 0; i
< dests
; i
++) {
3318 bsb
.devstart
= __cpu_to_le64(destoffsets
[i
]/512);
3319 bsb
.sb_csum
= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
));
3320 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0)
3321 bsb
.sb_csum2
= bsb_csum((char*)&bsb
,
3322 ((char*)&bsb
.sb_csum2
)-((char*)&bsb
));
3323 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
]-4096, 0) !=
3324 destoffsets
[i
]-4096)
3327 write(destfd
[i
], &bsb
, 512) != 512)
3334 static void fail(char *msg
)
3337 rv
= (write(2, msg
, strlen(msg
)) != (int)strlen(msg
));
3338 rv
|= (write(2, "\n", 1) != 1);
3342 static char *abuf
, *bbuf
;
3343 static unsigned long long abuflen
;
3344 static void validate(int afd
, int bfd
, unsigned long long offset
)
3346 /* check that the data in the backup against the array.
3347 * This is only used for regression testing and should not
3348 * be used while the array is active
3352 lseek64(bfd
, offset
- 4096, 0);
3353 if (read(bfd
, &bsb2
, 512) != 512)
3354 fail("cannot read bsb");
3355 if (bsb2
.sb_csum
!= bsb_csum((char*)&bsb2
,
3356 ((char*)&bsb2
.sb_csum
)-((char*)&bsb2
)))
3357 fail("first csum bad");
3358 if (memcmp(bsb2
.magic
, "md_backup_data", 14) != 0)
3359 fail("magic is bad");
3360 if (memcmp(bsb2
.magic
, "md_backup_data-2", 16) == 0 &&
3361 bsb2
.sb_csum2
!= bsb_csum((char*)&bsb2
,
3362 ((char*)&bsb2
.sb_csum2
)-((char*)&bsb2
)))
3363 fail("second csum bad");
3365 if (__le64_to_cpu(bsb2
.devstart
)*512 != offset
)
3366 fail("devstart is wrong");
3369 unsigned long long len
= __le64_to_cpu(bsb2
.length
)*512;
3371 if (abuflen
< len
) {
3375 if (posix_memalign((void**)&abuf
, 4096, abuflen
) ||
3376 posix_memalign((void**)&bbuf
, 4096, abuflen
)) {
3378 /* just stop validating on mem-alloc failure */
3383 lseek64(bfd
, offset
, 0);
3384 if ((unsigned long long)read(bfd
, bbuf
, len
) != len
) {
3385 //printf("len %llu\n", len);
3386 fail("read first backup failed");
3388 lseek64(afd
, __le64_to_cpu(bsb2
.arraystart
)*512, 0);
3389 if ((unsigned long long)read(afd
, abuf
, len
) != len
)
3390 fail("read first from array failed");
3391 if (memcmp(bbuf
, abuf
, len
) != 0) {
3394 printf("offset=%llu len=%llu\n",
3395 (unsigned long long)__le64_to_cpu(bsb2
.arraystart
)*512, len
);
3396 for (i
=0; i
<len
; i
++)
3397 if (bbuf
[i
] != abuf
[i
]) {
3398 printf("first diff byte %d\n", i
);
3402 fail("data1 compare failed");
3406 unsigned long long len
= __le64_to_cpu(bsb2
.length2
)*512;
3408 if (abuflen
< len
) {
3412 abuf
= xmalloc(abuflen
);
3413 bbuf
= xmalloc(abuflen
);
3416 lseek64(bfd
, offset
+__le64_to_cpu(bsb2
.devstart2
)*512, 0);
3417 if ((unsigned long long)read(bfd
, bbuf
, len
) != len
)
3418 fail("read second backup failed");
3419 lseek64(afd
, __le64_to_cpu(bsb2
.arraystart2
)*512, 0);
3420 if ((unsigned long long)read(afd
, abuf
, len
) != len
)
3421 fail("read second from array failed");
3422 if (memcmp(bbuf
, abuf
, len
) != 0)
3423 fail("data2 compare failed");
3427 int child_monitor(int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
3428 struct supertype
*st
, unsigned long blocks
,
3429 int *fds
, unsigned long long *offsets
,
3430 int dests
, int *destfd
, unsigned long long *destoffsets
)
3432 /* Monitor a reshape where backup is being performed using
3433 * 'native' mechanism - either to a backup file, or
3434 * to some space in a spare.
3438 unsigned long long speed
;
3439 unsigned long long suspend_point
, array_size
;
3440 unsigned long long backup_point
, wait_point
;
3441 unsigned long long reshape_completed
;
3443 int increasing
= reshape
->after
.data_disks
>= reshape
->before
.data_disks
;
3444 int part
= 0; /* The next part of the backup area to fill. It may already
3445 * be full, so we need to check */
3446 int level
= reshape
->level
;
3447 int layout
= reshape
->before
.layout
;
3448 int data
= reshape
->before
.data_disks
;
3449 int disks
= reshape
->before
.data_disks
+ reshape
->parity
;
3450 int chunk
= sra
->array
.chunk_size
;
3452 unsigned long stripes
;
3455 /* set up the backup-super-block. This requires the
3456 * uuid from the array.
3458 /* Find a superblock */
3459 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
3463 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
3465 dn
= map_dev(sd
->disk
.major
, sd
->disk
.minor
, 1);
3466 devfd
= dev_open(dn
, O_RDONLY
);
3469 ok
= st
->ss
->load_super(st
, devfd
, NULL
);
3475 pr_err("Cannot find a superblock\n");
3479 memset(&bsb
, 0, 512);
3480 memcpy(bsb
.magic
, "md_backup_data-1", 16);
3481 st
->ss
->uuid_from_super(st
, uuid
);
3482 memcpy(bsb
.set_uuid
, uuid
, 16);
3483 bsb
.mtime
= __cpu_to_le64(time(0));
3484 bsb
.devstart2
= blocks
;
3486 stripes
= blocks
/ (sra
->array
.chunk_size
/512) /
3487 reshape
->before
.data_disks
;
3489 if (posix_memalign((void**)&buf
, 4096, disks
* chunk
))
3490 /* Don't start the 'reshape' */
3492 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
) {
3493 sysfs_get_ll(sra
, NULL
, "sync_speed_min", &speed
);
3494 sysfs_set_num(sra
, NULL
, "sync_speed_min", 200000);
3498 array_size
= sra
->component_size
* reshape
->after
.data_disks
;
3499 backup_point
= sra
->reshape_progress
;
3502 array_size
= sra
->component_size
* reshape
->before
.data_disks
;
3503 backup_point
= reshape
->backup_blocks
;
3504 suspend_point
= array_size
;
3510 /* Want to return as soon the oldest backup slot can
3511 * be released as that allows us to start backing up
3512 * some more, providing suspend_point has been
3513 * advanced, which it should have.
3516 wait_point
= array_size
;
3517 if (part
== 0 && __le64_to_cpu(bsb
.length
) > 0)
3518 wait_point
= (__le64_to_cpu(bsb
.arraystart
) +
3519 __le64_to_cpu(bsb
.length
));
3520 if (part
== 1 && __le64_to_cpu(bsb
.length2
) > 0)
3521 wait_point
= (__le64_to_cpu(bsb
.arraystart2
) +
3522 __le64_to_cpu(bsb
.length2
));
3525 if (part
== 0 && __le64_to_cpu(bsb
.length
) > 0)
3526 wait_point
= __le64_to_cpu(bsb
.arraystart
);
3527 if (part
== 1 && __le64_to_cpu(bsb
.length2
) > 0)
3528 wait_point
= __le64_to_cpu(bsb
.arraystart2
);
3531 rv
= progress_reshape(sra
, reshape
,
3532 backup_point
, wait_point
,
3533 &suspend_point
, &reshape_completed
);
3534 /* external metadata would need to ping_monitor here */
3535 sra
->reshape_progress
= reshape_completed
;
3537 /* Clear any backup region that is before 'here' */
3539 if (__le64_to_cpu(bsb
.length
) > 0 &&
3540 reshape_completed
>= (__le64_to_cpu(bsb
.arraystart
) +
3541 __le64_to_cpu(bsb
.length
)))
3542 forget_backup(dests
, destfd
,
3544 if (__le64_to_cpu(bsb
.length2
) > 0 &&
3545 reshape_completed
>= (__le64_to_cpu(bsb
.arraystart2
) +
3546 __le64_to_cpu(bsb
.length2
)))
3547 forget_backup(dests
, destfd
,
3550 if (__le64_to_cpu(bsb
.length
) > 0 &&
3551 reshape_completed
<= (__le64_to_cpu(bsb
.arraystart
)))
3552 forget_backup(dests
, destfd
,
3554 if (__le64_to_cpu(bsb
.length2
) > 0 &&
3555 reshape_completed
<= (__le64_to_cpu(bsb
.arraystart2
)))
3556 forget_backup(dests
, destfd
,
3565 if (rv
== 0 && increasing
&& !st
->ss
->external
) {
3566 /* No longer need to monitor this reshape */
3572 unsigned long long offset
;
3573 unsigned long actual_stripes
;
3574 /* Need to backup some data.
3575 * If 'part' is not used and the desired
3576 * backup size is suspended, do a backup,
3577 * then consider the next part.
3579 /* Check that 'part' is unused */
3580 if (part
== 0 && __le64_to_cpu(bsb
.length
) != 0)
3582 if (part
== 1 && __le64_to_cpu(bsb
.length2
) != 0)
3585 offset
= backup_point
/ data
;
3586 actual_stripes
= stripes
;
3588 if (offset
+ actual_stripes
* (chunk
/512) >
3589 sra
->component_size
)
3590 actual_stripes
= ((sra
->component_size
- offset
)
3592 if (offset
+ actual_stripes
* (chunk
/512) >
3596 if (offset
< actual_stripes
* (chunk
/512))
3597 actual_stripes
= offset
/ (chunk
/512);
3598 offset
-= actual_stripes
* (chunk
/512);
3599 if (offset
< suspend_point
/data
)
3602 if (actual_stripes
== 0)
3604 grow_backup(sra
, offset
, actual_stripes
,
3606 disks
, chunk
, level
, layout
,
3607 dests
, destfd
, destoffsets
,
3608 part
, °raded
, buf
);
3609 validate(afd
, destfd
[0], destoffsets
[0]);
3610 /* record where 'part' is up to */
3613 backup_point
+= actual_stripes
* (chunk
/512) * data
;
3615 backup_point
-= actual_stripes
* (chunk
/512) * data
;
3619 /* FIXME maybe call progress_reshape one more time instead */
3620 abort_reshape(sra
); /* remove any remaining suspension */
3621 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
)
3622 sysfs_set_num(sra
, NULL
, "sync_speed_min", speed
);
3628 * If any spare contains md_back_data-1 which is recent wrt mtime,
3629 * write that data into the array and update the super blocks with
3630 * the new reshape_progress
3632 int Grow_restart(struct supertype
*st
, struct mdinfo
*info
, int *fdlist
, int cnt
,
3633 char *backup_file
, int verbose
)
3637 unsigned long long *offsets
;
3638 unsigned long long nstripe
, ostripe
;
3641 odata
= info
->array
.raid_disks
- info
->delta_disks
- 1;
3642 if (info
->array
.level
== 6) odata
--; /* number of data disks */
3643 ndata
= info
->array
.raid_disks
- 1;
3644 if (info
->new_level
== 6) ndata
--;
3646 old_disks
= info
->array
.raid_disks
- info
->delta_disks
;
3648 if (info
->delta_disks
<= 0)
3649 /* Didn't grow, so the backup file must have
3653 for (i
=old_disks
-(backup_file
?1:0); i
<cnt
; i
++) {
3654 struct mdinfo dinfo
;
3657 char *devname
, namebuf
[20];
3658 unsigned long long lo
, hi
;
3660 /* This was a spare and may have some saved data on it.
3661 * Load the superblock, find and load the
3662 * backup_super_block.
3663 * If either fail, go on to next device.
3664 * If the backup contains no new info, just return
3665 * else restore data and update all superblocks
3667 if (i
== old_disks
-1) {
3668 fd
= open(backup_file
, O_RDONLY
);
3670 pr_err("backup file %s inaccessible: %s\n",
3671 backup_file
, strerror(errno
));
3674 devname
= backup_file
;
3679 if (st
->ss
->load_super(st
, fd
, NULL
))
3682 st
->ss
->getinfo_super(st
, &dinfo
, NULL
);
3683 st
->ss
->free_super(st
);
3686 (dinfo
.data_offset
+ dinfo
.component_size
- 8) <<9,
3688 pr_err("Cannot seek on device %d\n", i
);
3689 continue; /* Cannot seek */
3691 sprintf(namebuf
, "device-%d", i
);
3694 if (read(fd
, &bsb
, sizeof(bsb
)) != sizeof(bsb
)) {
3696 pr_err("Cannot read from %s\n", devname
);
3697 continue; /* Cannot read */
3699 if (memcmp(bsb
.magic
, "md_backup_data-1", 16) != 0 &&
3700 memcmp(bsb
.magic
, "md_backup_data-2", 16) != 0) {
3702 pr_err("No backup metadata on %s\n", devname
);
3705 if (bsb
.sb_csum
!= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
))) {
3707 pr_err("Bad backup-metadata checksum on %s\n", devname
);
3708 continue; /* bad checksum */
3710 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0 &&
3711 bsb
.sb_csum2
!= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum2
)-((char*)&bsb
))) {
3713 pr_err("Bad backup-metadata checksum2 on %s\n", devname
);
3714 continue; /* Bad second checksum */
3716 if (memcmp(bsb
.set_uuid
,info
->uuid
, 16) != 0) {
3718 pr_err("Wrong uuid on backup-metadata on %s\n", devname
);
3719 continue; /* Wrong uuid */
3722 /* array utime and backup-mtime should be updated at much the same time, but it seems that
3723 * sometimes they aren't... So allow considerable flexability in matching, and allow
3724 * this test to be overridden by an environment variable.
3726 if (info
->array
.utime
> (int)__le64_to_cpu(bsb
.mtime
) + 2*60*60 ||
3727 info
->array
.utime
< (int)__le64_to_cpu(bsb
.mtime
) - 10*60) {
3728 if (check_env("MDADM_GROW_ALLOW_OLD")) {
3729 pr_err("accepting backup with timestamp %lu "
3730 "for array with timestamp %lu\n",
3731 (unsigned long)__le64_to_cpu(bsb
.mtime
),
3732 (unsigned long)info
->array
.utime
);
3735 pr_err("too-old timestamp on "
3736 "backup-metadata on %s\n", devname
);
3737 continue; /* time stamp is too bad */
3741 if (bsb
.magic
[15] == '1') {
3742 if (bsb
.length
== 0)
3744 if (info
->delta_disks
>= 0) {
3745 /* reshape_progress is increasing */
3746 if (__le64_to_cpu(bsb
.arraystart
)
3747 + __le64_to_cpu(bsb
.length
)
3748 < info
->reshape_progress
) {
3751 pr_err("backup-metadata found on %s but is not needed\n", devname
);
3752 continue; /* No new data here */
3755 /* reshape_progress is decreasing */
3756 if (__le64_to_cpu(bsb
.arraystart
) >=
3757 info
->reshape_progress
)
3758 goto nonew
; /* No new data here */
3761 if (bsb
.length
== 0 && bsb
.length2
== 0)
3763 if (info
->delta_disks
>= 0) {
3764 /* reshape_progress is increasing */
3765 if ((__le64_to_cpu(bsb
.arraystart
)
3766 + __le64_to_cpu(bsb
.length
)
3767 < info
->reshape_progress
)
3769 (__le64_to_cpu(bsb
.arraystart2
)
3770 + __le64_to_cpu(bsb
.length2
)
3771 < info
->reshape_progress
))
3772 goto nonew
; /* No new data here */
3774 /* reshape_progress is decreasing */
3775 if (__le64_to_cpu(bsb
.arraystart
) >=
3776 info
->reshape_progress
&&
3777 __le64_to_cpu(bsb
.arraystart2
) >=
3778 info
->reshape_progress
)
3779 goto nonew
; /* No new data here */
3782 if (lseek64(fd
, __le64_to_cpu(bsb
.devstart
)*512, 0)< 0) {
3785 pr_err("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
= xmalloc(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 pr_err("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 pr_err("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 pr_err("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
) {
3964 pr_err("Unable to determine metadata format for %s\n",
3968 dprintf("Grow continue is run for ");
3969 if (st
->ss
->external
== 0) {
3970 dprintf("native array (%s)\n", devname
);
3971 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) < 0) {
3972 pr_err("%s is not an active md array -"
3973 " aborting\n", devname
);
3975 goto Grow_continue_command_exit
;
3978 sysfs_init(content
, fd
, st
->devnum
);
3983 dprintf("subarray (%s)\n", subarray
);
3984 container_dev
= st
->container_dev
;
3985 cfd
= open_dev_excl(st
->container_dev
);
3987 container_dev
= st
->devnum
;
3989 cfd
= open_dev_excl(st
->devnum
);
3990 dprintf("container (%i)\n", container_dev
);
3994 pr_err("Unable to open container "
3995 "for %s\n", devname
);
3997 goto Grow_continue_command_exit
;
3999 fmt_devname(buf
, container_dev
);
4001 /* find in container array under reshape
4003 ret_val
= st
->ss
->load_container(st
, cfd
, NULL
);
4005 pr_err("Cannot read superblock for %s\n",
4008 goto Grow_continue_command_exit
;
4011 cc
= st
->ss
->container_content(st
, subarray
);
4012 for (content
= cc
; content
; content
= content
->next
) {
4014 int allow_reshape
= 1;
4016 if (content
->reshape_active
== 0)
4018 /* The decision about array or container wide
4019 * reshape is taken in Grow_continue based
4020 * content->reshape_active state, therefore we
4021 * need to check_reshape based on
4022 * reshape_active and subarray name
4024 if (content
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
))
4026 if (content
->reshape_active
== CONTAINER_RESHAPE
&&
4027 (content
->array
.state
4028 & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
)))
4031 if (!allow_reshape
) {
4032 pr_err("cannot continue reshape of an array"
4033 " in container with unsupported"
4034 " metadata: %s(%s)\n",
4037 goto Grow_continue_command_exit
;
4040 array
= strchr(content
->text_version
+1, '/')+1;
4041 mdstat
= mdstat_by_subdev(array
, container_dev
);
4044 if (mdstat
->active
== 0) {
4045 pr_err("Skipping inactive "
4046 "array md%i.\n", mdstat
->devnum
);
4047 free_mdstat(mdstat
);
4054 pr_err("Unable to determine reshaped "
4055 "array for %s\n", devname
);
4057 goto Grow_continue_command_exit
;
4059 fd2
= open_dev(mdstat
->devnum
);
4061 pr_err("cannot open (md%i)\n",
4064 goto Grow_continue_command_exit
;
4067 sysfs_init(content
, fd2
, mdstat
->devnum
);
4069 /* start mdmon in case it is not running
4071 if (!mdmon_running(container_dev
))
4072 start_mdmon(container_dev
);
4075 if (mdmon_running(container_dev
))
4076 st
->update_tail
= &st
->updates
;
4078 pr_err("No mdmon found. "
4079 "Grow cannot continue.\n");
4081 goto Grow_continue_command_exit
;
4085 /* verify that array under reshape is started from
4088 if (verify_reshape_position(content
,
4089 map_name(pers
, mdstat
->level
)) < 0) {
4091 goto Grow_continue_command_exit
;
4096 ret_val
= Grow_continue(fd
, st
, content
, backup_file
, 0);
4098 Grow_continue_command_exit
:
4103 st
->ss
->free_super(st
);
4104 free_mdstat(mdstat
);
4111 int Grow_continue(int mdfd
, struct supertype
*st
, struct mdinfo
*info
,
4112 char *backup_file
, int freeze_reshape
)
4116 if (!info
->reshape_active
)
4119 if (st
->ss
->external
) {
4121 int cfd
= open_dev(st
->container_dev
);
4126 fmt_devname(container
, st
->container_dev
);
4127 st
->ss
->load_container(st
, cfd
, container
);
4129 ret_val
= reshape_container(container
, NULL
, mdfd
,
4130 st
, info
, 0, backup_file
,
4131 0, 1, freeze_reshape
);
4133 ret_val
= reshape_array(NULL
, mdfd
, "array", st
, info
, 1,
4134 NULL
, backup_file
, 0, 0, 1,