2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2012 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",
126 info
.array
.major_version
);
131 pr_err("Cannot grow linear sub-arrays yet\n");
137 nfd
= open(newdev
, O_RDWR
|O_EXCL
|O_DIRECT
);
139 pr_err("cannot open %s\n", newdev
);
144 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
145 pr_err("%s is not a block device!\n", newdev
);
150 /* now check out all the devices and make sure we can read the
152 for (d
=0 ; d
< info
.array
.raid_disks
; d
++) {
153 mdu_disk_info_t disk
;
156 st
->ss
->free_super(st
);
159 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
160 pr_err("cannot get device detail for device %d\n",
166 dv
= map_dev(disk
.major
, disk
.minor
, 1);
168 pr_err("cannot find device file for device %d\n",
174 fd2
= dev_open(dv
, O_RDWR
);
176 pr_err("cannot open device file %s\n", dv
);
182 if (st
->ss
->load_super(st
, fd2
, NULL
)) {
183 pr_err("cannot find super block on %s\n", dv
);
191 /* Ok, looks good. Lets update the superblock and write it out to
195 info
.disk
.number
= d
;
196 info
.disk
.major
= major(stb
.st_rdev
);
197 info
.disk
.minor
= minor(stb
.st_rdev
);
198 info
.disk
.raid_disk
= d
;
199 info
.disk
.state
= (1 << MD_DISK_SYNC
) | (1 << MD_DISK_ACTIVE
);
200 st
->ss
->update_super(st
, &info
, "linear-grow-new", newdev
,
203 if (st
->ss
->store_super(st
, nfd
)) {
204 pr_err("Cannot store new superblock on %s\n",
211 if (ioctl(fd
, ADD_NEW_DISK
, &info
.disk
) != 0) {
212 pr_err("Cannot add new disk to this array\n");
215 /* Well, that seems to have worked.
216 * Now go through and update all superblocks
219 if (ioctl(fd
, GET_ARRAY_INFO
, &info
.array
) < 0) {
220 pr_err("cannot get array info for %s\n", devname
);
225 for (d
=0 ; d
< info
.array
.raid_disks
; d
++) {
226 mdu_disk_info_t disk
;
230 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
231 pr_err("cannot get device detail for device %d\n",
235 dv
= map_dev(disk
.major
, disk
.minor
, 1);
237 pr_err("cannot find device file for device %d\n",
241 fd2
= dev_open(dv
, O_RDWR
);
243 pr_err("cannot open device file %s\n", dv
);
246 if (st
->ss
->load_super(st
, fd2
, NULL
)) {
247 pr_err("cannot find super block on %s\n", dv
);
251 info
.array
.raid_disks
= nd
+1;
252 info
.array
.nr_disks
= nd
+1;
253 info
.array
.active_disks
= nd
+1;
254 info
.array
.working_disks
= nd
+1;
256 st
->ss
->update_super(st
, &info
, "linear-grow-update", dv
,
259 if (st
->ss
->store_super(st
, fd2
)) {
260 pr_err("Cannot store new superblock on %s\n", dv
);
270 int Grow_addbitmap(char *devname
, int fd
, struct context
*c
, struct shape
*s
)
273 * First check that array doesn't have a bitmap
274 * Then create the bitmap
277 * For internal bitmaps, we need to check the version,
278 * find all the active devices, and write the bitmap block
281 mdu_bitmap_file_t bmf
;
282 mdu_array_info_t array
;
283 struct supertype
*st
;
284 char *subarray
= NULL
;
285 int major
= BITMAP_MAJOR_HI
;
286 int vers
= md_get_version(fd
);
287 unsigned long long bitmapsize
, array_size
;
290 major
= BITMAP_MAJOR_HOSTENDIAN
;
291 pr_err("Warning - bitmaps created on this kernel"
292 " are not portable\n"
293 " between different architectures. Consider upgrading"
294 " the Linux kernel.\n");
297 if (ioctl(fd
, GET_BITMAP_FILE
, &bmf
) != 0) {
299 pr_err("Memory allocation failure.\n");
301 pr_err("bitmaps not supported by this kernel.\n");
304 if (bmf
.pathname
[0]) {
305 if (strcmp(s
->bitmap_file
,"none")==0) {
306 if (ioctl(fd
, SET_BITMAP_FILE
, -1)!= 0) {
307 pr_err("failed to remove bitmap %s\n",
313 pr_err("%s already has a bitmap (%s)\n",
314 devname
, bmf
.pathname
);
317 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
318 pr_err("cannot get array status for %s\n", devname
);
321 if (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)) {
322 if (strcmp(s
->bitmap_file
, "none")==0) {
323 array
.state
&= ~(1<<MD_SB_BITMAP_PRESENT
);
324 if (ioctl(fd
, SET_ARRAY_INFO
, &array
)!= 0) {
325 pr_err("failed to remove internal bitmap.\n");
330 pr_err("Internal bitmap already present on %s\n",
335 if (strcmp(s
->bitmap_file
, "none") == 0) {
336 pr_err("no bitmap found on %s\n", devname
);
339 if (array
.level
<= 0) {
340 pr_err("Bitmaps not meaningful with level %s\n",
341 map_num(pers
, array
.level
)?:"of this array");
344 bitmapsize
= array
.size
;
346 if (get_dev_size(fd
, NULL
, &array_size
) &&
347 array_size
> (0x7fffffffULL
<<9)) {
348 /* Array is big enough that we cannot trust array.size
349 * try other approaches
351 bitmapsize
= get_component_size(fd
);
353 if (bitmapsize
== 0) {
354 pr_err("Cannot reliably determine size of array to create bitmap - sorry.\n");
358 if (array
.level
== 10) {
359 int ncopies
= (array
.layout
&255)*((array
.layout
>>8)&255);
360 bitmapsize
= bitmapsize
* array
.raid_disks
/ ncopies
;
363 st
= super_by_fd(fd
, &subarray
);
365 pr_err("Cannot understand version %d.%d\n",
366 array
.major_version
, array
.minor_version
);
370 pr_err("Cannot add bitmaps to sub-arrays yet\n");
375 if (strcmp(s
->bitmap_file
, "internal") == 0) {
378 int offset_setable
= 0;
380 if (st
->ss
->add_internal_bitmap
== NULL
) {
381 pr_err("Internal bitmaps not supported "
382 "with %s metadata\n", st
->ss
->name
);
385 mdi
= sysfs_read(fd
, -1, GET_BITMAP_LOCATION
);
388 for (d
=0; d
< st
->max_devs
; d
++) {
389 mdu_disk_info_t disk
;
392 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
394 if (disk
.major
== 0 &&
397 if ((disk
.state
& (1<<MD_DISK_SYNC
))==0)
399 dv
= map_dev(disk
.major
, disk
.minor
, 1);
401 int fd2
= dev_open(dv
, O_RDWR
);
404 if (st
->ss
->load_super(st
, fd2
, NULL
)==0) {
405 if (st
->ss
->add_internal_bitmap(
407 &s
->bitmap_chunk
, c
->delay
, s
->write_behind
,
408 bitmapsize
, offset_setable
,
411 st
->ss
->write_bitmap(st
, fd2
);
413 pr_err("failed to create internal bitmap"
414 " - chunksize problem.\n");
422 if (offset_setable
) {
423 st
->ss
->getinfo_super(st
, mdi
, NULL
);
424 sysfs_init(mdi
, fd
, -1);
425 rv
= sysfs_set_num_signed(mdi
, NULL
, "bitmap/location",
428 array
.state
|= (1<<MD_SB_BITMAP_PRESENT
);
429 rv
= ioctl(fd
, SET_ARRAY_INFO
, &array
);
433 pr_err("Cannot add bitmap while array is"
434 " resyncing or reshaping etc.\n");
435 pr_err("failed to set internal bitmap.\n");
442 int max_devs
= st
->max_devs
;
444 /* try to load a superblock */
445 for (d
= 0; d
< max_devs
; d
++) {
446 mdu_disk_info_t disk
;
450 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
452 if ((disk
.major
==0 && disk
.minor
==0) ||
453 (disk
.state
& (1<<MD_DISK_REMOVED
)))
455 dv
= map_dev(disk
.major
, disk
.minor
, 1);
458 fd2
= dev_open(dv
, O_RDONLY
);
460 if (st
->ss
->load_super(st
, fd2
, NULL
) == 0) {
462 st
->ss
->uuid_from_super(st
, uuid
);
469 pr_err("cannot find UUID for array!\n");
472 if (CreateBitmap(s
->bitmap_file
, c
->force
, (char*)uuid
, s
->bitmap_chunk
,
473 c
->delay
, s
->write_behind
, bitmapsize
, major
)) {
476 bitmap_fd
= open(s
->bitmap_file
, O_RDWR
);
478 pr_err("weird: %s cannot be opened\n",
482 if (ioctl(fd
, SET_BITMAP_FILE
, bitmap_fd
) < 0) {
485 pr_err("Cannot add bitmap while array is"
486 " resyncing or reshaping etc.\n");
487 pr_err("Cannot set bitmap file for %s: %s\n",
488 devname
, strerror(err
));
497 * When reshaping an array we might need to backup some data.
498 * This is written to all spares with a 'super_block' describing it.
499 * The superblock goes 4K from the end of the used space on the
501 * It if written after the backup is complete.
502 * It has the following structure.
505 static struct mdp_backup_super
{
506 char magic
[16]; /* md_backup_data-1 or -2 */
509 /* start/sizes in 512byte sectors */
510 __u64 devstart
; /* address on backup device/file of data */
513 __u32 sb_csum
; /* csum of preceeding bytes. */
515 __u64 devstart2
; /* offset in to data of second section */
518 __u32 sb_csum2
; /* csum of preceeding bytes. */
520 } __attribute__((aligned(512))) bsb
, bsb2
;
522 static __u32
bsb_csum(char *buf
, int len
)
526 for (i
= 0; i
< len
; i
++)
527 csum
= (csum
<<3) + buf
[0];
528 return __cpu_to_le32(csum
);
531 static int check_idle(struct supertype
*st
)
533 /* Check that all member arrays for this container, or the
534 * container of this array, are idle
536 int container_dev
= (st
->container_dev
!= NoMdDev
537 ? st
->container_dev
: st
->devnum
);
539 struct mdstat_ent
*ent
, *e
;
542 fmt_devname(container
, container_dev
);
543 ent
= mdstat_read(0, 0);
544 for (e
= ent
; e
; e
= e
->next
) {
545 if (!is_container_member(e
, container
))
547 if (e
->percent
>= 0) {
556 static int freeze_container(struct supertype
*st
)
558 int container_dev
= (st
->container_dev
!= NoMdDev
559 ? st
->container_dev
: st
->devnum
);
565 fmt_devname(container
, container_dev
);
567 if (block_monitor(container
, 1)) {
568 pr_err("failed to freeze container\n");
575 static void unfreeze_container(struct supertype
*st
)
577 int container_dev
= (st
->container_dev
!= NoMdDev
578 ? st
->container_dev
: st
->devnum
);
581 fmt_devname(container
, container_dev
);
583 unblock_monitor(container
, 1);
586 static int freeze(struct supertype
*st
)
588 /* Try to freeze resync/rebuild on this array/container.
589 * Return -1 if the array is busy,
590 * return -2 container cannot be frozen,
591 * return 0 if this kernel doesn't support 'frozen'
592 * return 1 if it worked.
594 if (st
->ss
->external
)
595 return freeze_container(st
);
597 struct mdinfo
*sra
= sysfs_read(-1, st
->devnum
, GET_VERSION
);
603 /* Need to clear any 'read-auto' status */
604 if (sysfs_get_str(sra
, NULL
, "array_state", buf
, 20) > 0 &&
605 strncmp(buf
, "read-auto", 9) == 0)
606 sysfs_set_str(sra
, NULL
, "array_state", "clean");
608 err
= sysfs_freeze_array(sra
);
614 static void unfreeze(struct supertype
*st
)
616 if (st
->ss
->external
)
617 return unfreeze_container(st
);
619 struct mdinfo
*sra
= sysfs_read(-1, st
->devnum
, GET_VERSION
);
622 sysfs_set_str(sra
, NULL
, "sync_action", "idle");
627 static void wait_reshape(struct mdinfo
*sra
)
629 int fd
= sysfs_get_fd(sra
, NULL
, "sync_action");
635 while (sysfs_fd_get_str(fd
, action
, 20) > 0 &&
636 strncmp(action
, "reshape", 7) == 0) {
640 select(fd
+1, NULL
, NULL
, &rfds
, NULL
);
645 static int reshape_super(struct supertype
*st
, long long size
, int level
,
646 int layout
, int chunksize
, int raid_disks
,
647 int delta_disks
, char *backup_file
, char *dev
,
648 int direction
, int verbose
)
650 /* nothing extra to check in the native case */
651 if (!st
->ss
->external
)
653 if (!st
->ss
->reshape_super
||
654 !st
->ss
->manage_reshape
) {
655 pr_err("%s metadata does not support reshape\n",
660 return st
->ss
->reshape_super(st
, size
, level
, layout
, chunksize
,
661 raid_disks
, delta_disks
, backup_file
, dev
,
665 static void sync_metadata(struct supertype
*st
)
667 if (st
->ss
->external
) {
668 if (st
->update_tail
) {
669 flush_metadata_updates(st
);
670 st
->update_tail
= &st
->updates
;
672 st
->ss
->sync_metadata(st
);
676 static int subarray_set_num(char *container
, struct mdinfo
*sra
, char *name
, int n
)
678 /* when dealing with external metadata subarrays we need to be
679 * prepared to handle EAGAIN. The kernel may need to wait for
680 * mdmon to mark the array active so the kernel can handle
681 * allocations/writeback when preparing the reshape action
682 * (md_allow_write()). We temporarily disable safe_mode_delay
683 * to close a race with the array_state going clean before the
684 * next write to raid_disks / stripe_cache_size
689 /* only 'raid_disks' and 'stripe_cache_size' trigger md_allow_write */
691 (strcmp(name
, "raid_disks") != 0 &&
692 strcmp(name
, "stripe_cache_size") != 0))
693 return sysfs_set_num(sra
, NULL
, name
, n
);
695 rc
= sysfs_get_str(sra
, NULL
, "safe_mode_delay", safe
, sizeof(safe
));
698 sysfs_set_num(sra
, NULL
, "safe_mode_delay", 0);
699 rc
= sysfs_set_num(sra
, NULL
, name
, n
);
700 if (rc
< 0 && errno
== EAGAIN
) {
701 ping_monitor(container
);
702 /* if we get EAGAIN here then the monitor is not active
705 rc
= sysfs_set_num(sra
, NULL
, name
, n
);
707 sysfs_set_str(sra
, NULL
, "safe_mode_delay", safe
);
711 int start_reshape(struct mdinfo
*sra
, int already_running
,
712 int before_data_disks
, int data_disks
)
715 unsigned long long sync_max_to_set
;
717 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
718 err
= sysfs_set_num(sra
, NULL
, "suspend_hi", sra
->reshape_progress
);
719 err
= err
?: sysfs_set_num(sra
, NULL
, "suspend_lo",
720 sra
->reshape_progress
);
721 if (before_data_disks
<= data_disks
)
722 sync_max_to_set
= sra
->reshape_progress
/ data_disks
;
724 sync_max_to_set
= (sra
->component_size
* data_disks
725 - sra
->reshape_progress
) / data_disks
;
726 if (!already_running
)
727 sysfs_set_num(sra
, NULL
, "sync_min", sync_max_to_set
);
728 err
= err
?: sysfs_set_num(sra
, NULL
, "sync_max", sync_max_to_set
);
729 if (!already_running
)
730 err
= err
?: sysfs_set_str(sra
, NULL
, "sync_action", "reshape");
735 void abort_reshape(struct mdinfo
*sra
)
737 sysfs_set_str(sra
, NULL
, "sync_action", "idle");
738 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
739 sysfs_set_num(sra
, NULL
, "suspend_hi", 0);
740 sysfs_set_num(sra
, NULL
, "suspend_lo", 0);
741 sysfs_set_num(sra
, NULL
, "sync_min", 0);
742 sysfs_set_str(sra
, NULL
, "sync_max", "max");
745 int remove_disks_for_takeover(struct supertype
*st
,
750 struct mdinfo
*remaining
;
753 if (sra
->array
.level
== 10)
754 nr_of_copies
= layout
& 0xff;
755 else if (sra
->array
.level
== 1)
756 nr_of_copies
= sra
->array
.raid_disks
;
760 remaining
= sra
->devs
;
762 /* for each 'copy', select one device and remove from the list. */
763 for (slot
= 0; slot
< sra
->array
.raid_disks
; slot
+= nr_of_copies
) {
764 struct mdinfo
**diskp
;
767 /* Find a working device to keep */
768 for (diskp
= &remaining
; *diskp
; diskp
= &(*diskp
)->next
) {
769 struct mdinfo
*disk
= *diskp
;
771 if (disk
->disk
.raid_disk
< slot
)
773 if (disk
->disk
.raid_disk
>= slot
+ nr_of_copies
)
775 if (disk
->disk
.state
& (1<<MD_DISK_REMOVED
))
777 if (disk
->disk
.state
& (1<<MD_DISK_FAULTY
))
779 if (!(disk
->disk
.state
& (1<<MD_DISK_SYNC
)))
782 /* We have found a good disk to use! */
784 disk
->next
= sra
->devs
;
793 if (slot
< sra
->array
.raid_disks
) {
794 /* didn't find all slots */
800 sra
->devs
= remaining
;
804 /* Remove all 'remaining' devices from the array */
806 struct mdinfo
*sd
= remaining
;
807 remaining
= sd
->next
;
809 sysfs_set_str(sra
, sd
, "state", "faulty");
810 sysfs_set_str(sra
, sd
, "slot", "none");
811 /* for external metadata disks should be removed in mdmon */
812 if (!st
->ss
->external
)
813 sysfs_set_str(sra
, sd
, "state", "remove");
814 sd
->disk
.state
|= (1<<MD_DISK_REMOVED
);
815 sd
->disk
.state
&= ~(1<<MD_DISK_SYNC
);
816 sd
->next
= sra
->devs
;
822 void reshape_free_fdlist(int *fdlist
,
823 unsigned long long *offsets
,
828 for (i
= 0; i
< size
; i
++)
836 int reshape_prepare_fdlist(char *devname
,
840 unsigned long blocks
,
843 unsigned long long *offsets
)
848 for (d
= 0; d
<= nrdisks
; d
++)
851 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
852 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
854 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
855 char *dn
= map_dev(sd
->disk
.major
,
857 fdlist
[sd
->disk
.raid_disk
]
858 = dev_open(dn
, O_RDONLY
);
859 offsets
[sd
->disk
.raid_disk
] = sd
->data_offset
*512;
860 if (fdlist
[sd
->disk
.raid_disk
] < 0) {
861 pr_err("%s: cannot open component %s\n",
862 devname
, dn
? dn
: "-unknown-");
866 } else if (backup_file
== NULL
) {
868 char *dn
= map_dev(sd
->disk
.major
,
870 fdlist
[d
] = dev_open(dn
, O_RDWR
);
871 offsets
[d
] = (sd
->data_offset
+ sra
->component_size
- blocks
- 8)*512;
873 pr_err("%s: cannot open component %s\n",
874 devname
, dn
? dn
: "-unknown-");
885 int reshape_open_backup_file(char *backup_file
,
890 unsigned long long *offsets
,
893 /* Return 1 on success, 0 on any form of failure */
894 /* need to check backup file is large enough */
900 *fdlist
= open(backup_file
, O_RDWR
|O_CREAT
|(restart
? O_TRUNC
: O_EXCL
),
904 pr_err("%s: cannot create backup file %s: %s\n",
905 devname
, backup_file
, strerror(errno
));
908 /* Guard against backup file being on array device.
909 * If array is partitioned or if LVM etc is in the
910 * way this will not notice, but it is better than
913 fstat(*fdlist
, &stb
);
916 if (stb
.st_rdev
== dev
) {
917 pr_err("backup file must NOT be"
918 " on the array being reshaped.\n");
924 for (i
=0; i
< blocks
+ 8 ; i
++) {
925 if (write(*fdlist
, buf
, 512) != 512) {
926 pr_err("%s: cannot create"
927 " backup file %s: %s\n",
928 devname
, backup_file
, strerror(errno
));
932 if (fsync(*fdlist
) != 0) {
933 pr_err("%s: cannot create backup file %s: %s\n",
934 devname
, backup_file
, strerror(errno
));
941 unsigned long compute_backup_blocks(int nchunk
, int ochunk
,
942 unsigned int ndata
, unsigned int odata
)
944 unsigned long a
, b
, blocks
;
945 /* So how much do we need to backup.
946 * We need an amount of data which is both a whole number of
947 * old stripes and a whole number of new stripes.
948 * So LCM for (chunksize*datadisks).
950 a
= (ochunk
/512) * odata
;
951 b
= (nchunk
/512) * ndata
;
959 /* LCM == product / GCD */
960 blocks
= (ochunk
/512) * (nchunk
/512) * odata
* ndata
/ a
;
965 char *analyse_change(struct mdinfo
*info
, struct reshape
*re
)
967 /* Based on the current array state in info->array and
968 * the changes in info->new_* etc, determine:
969 * - whether the change is possible
970 * - Intermediate level/raid_disks/layout
971 * - whether a restriping reshape is needed
972 * - number of sectors in minimum change unit. This
973 * will cover a whole number of stripes in 'before' and
976 * Return message if the change should be rejected
977 * NULL if the change can be achieved
979 * This can be called as part of starting a reshape, or
980 * when assembling an array that is undergoing reshape.
983 /* delta_parity records change in number of devices
984 * caused by level change
986 int delta_parity
= 0;
988 /* If a new level not explicitly given, we assume no-change */
989 if (info
->new_level
== UnSet
)
990 info
->new_level
= info
->array
.level
;
993 switch (info
->new_level
) {
999 /* chunk size is meaningful, must divide component_size
1002 if (info
->component_size
% (info
->new_chunk
/512))
1003 return "New chunk size does not"
1004 " divide component size";
1007 return "chunk size not meaningful for this level";
1010 info
->new_chunk
= info
->array
.chunk_size
;
1012 switch (info
->array
.level
) {
1014 return "Cannot understand this RAID level";
1016 /* RAID1 can convert to RAID1 with different disks, or
1017 * raid5 with 2 disks, or
1020 if (info
->new_level
> 1 &&
1021 (info
->component_size
& 7))
1022 return "Cannot convert RAID1 of this size - "
1023 "reduce size to multiple of 4K first.";
1024 if (info
->new_level
== 0) {
1025 if (info
->delta_disks
!= UnSet
&&
1026 info
->delta_disks
!= 0)
1027 return "Cannot change number of disks "
1028 "with RAID1->RAID0 conversion";
1030 re
->before
.data_disks
= 1;
1031 re
->after
.data_disks
= 1;
1032 re
->before
.layout
= 0;
1033 re
->backup_blocks
= 0;
1037 if (info
->new_level
== 1) {
1038 if (info
->delta_disks
== UnSet
)
1039 /* Don't know what to do */
1040 return "no change requested for Growing RAID1";
1042 re
->backup_blocks
= 0;
1046 if (info
->array
.raid_disks
== 2 &&
1047 info
->new_level
== 5) {
1050 re
->before
.data_disks
= 1;
1051 if (info
->delta_disks
!= UnSet
&&
1052 info
->delta_disks
!= 0)
1053 re
->after
.data_disks
= 1 + info
->delta_disks
;
1055 re
->after
.data_disks
= 1;
1056 if (re
->after
.data_disks
< 1)
1057 return "Number of disks too small for RAID5";
1059 re
->before
.layout
= ALGORITHM_LEFT_SYMMETRIC
;
1060 info
->array
.chunk_size
= 65536;
1063 /* Could do some multi-stage conversions, but leave that to
1066 return "Impossibly level change request for RAID1";
1069 /* RAID10 can only be converted from near mode to
1070 * RAID0 by removing some devices
1072 if ((info
->array
.layout
& ~0xff) != 0x100)
1073 return "Cannot Grow RAID10 with far/offset layout";
1074 /* number of devices must be multiple of number of copies */
1075 if (info
->array
.raid_disks
% (info
->array
.layout
& 0xff))
1076 return "RAID10 layout too complex for Grow operation";
1078 if (info
->new_level
!= 0)
1079 return "RAID10 can only be changed to RAID0";
1080 new_disks
= (info
->array
.raid_disks
1081 / (info
->array
.layout
& 0xff));
1082 if (info
->delta_disks
== UnSet
)
1083 info
->delta_disks
= (new_disks
1084 - info
->array
.raid_disks
);
1086 if (info
->delta_disks
!= new_disks
- info
->array
.raid_disks
)
1087 return "New number of raid-devices impossible for RAID10";
1088 if (info
->new_chunk
&&
1089 info
->new_chunk
!= info
->array
.chunk_size
)
1090 return "Cannot change chunk-size with RAID10 Grow";
1095 re
->before
.data_disks
= new_disks
;
1096 re
->after
.data_disks
= re
->before
.data_disks
;
1097 re
->before
.layout
= 0;
1098 re
->backup_blocks
= 0;
1102 /* RAID0 can be converted to RAID10, or to RAID456 */
1103 if (info
->new_level
== 10) {
1104 if (info
->new_layout
== UnSet
&& info
->delta_disks
== UnSet
) {
1105 /* Assume near=2 layout */
1106 info
->new_layout
= 0x102;
1107 info
->delta_disks
= info
->array
.raid_disks
;
1109 if (info
->new_layout
== UnSet
) {
1110 int copies
= 1 + (info
->delta_disks
1111 / info
->array
.raid_disks
);
1112 if (info
->array
.raid_disks
* (copies
-1)
1113 != info
->delta_disks
)
1114 return "Impossible number of devices"
1115 " for RAID0->RAID10";
1116 info
->new_layout
= 0x100 + copies
;
1118 if (info
->delta_disks
== UnSet
) {
1119 int copies
= info
->new_layout
& 0xff;
1120 if (info
->new_layout
!= 0x100 + copies
)
1121 return "New layout impossible"
1122 " for RAID0->RAID10";;
1123 info
->delta_disks
= (copies
- 1) *
1124 info
->array
.raid_disks
;
1126 if (info
->new_chunk
&&
1127 info
->new_chunk
!= info
->array
.chunk_size
)
1128 return "Cannot change chunk-size with RAID0->RAID10";
1132 re
->before
.data_disks
= (info
->array
.raid_disks
+
1134 re
->after
.data_disks
= re
->before
.data_disks
;
1135 re
->before
.layout
= info
->new_layout
;
1136 re
->backup_blocks
= 0;
1140 /* RAID0 can also covert to RAID0/4/5/6 by first converting to
1141 * a raid4 style layout of the final level.
1143 switch (info
->new_level
) {
1148 re
->before
.layout
= 0;
1153 re
->before
.layout
= ALGORITHM_PARITY_N
;
1158 re
->before
.layout
= ALGORITHM_PARITY_N
;
1161 return "Impossible level change requested";
1163 re
->before
.data_disks
= info
->array
.raid_disks
;
1164 /* determining 'after' layout happens outside this 'switch' */
1168 info
->array
.layout
= ALGORITHM_PARITY_N
;
1170 switch (info
->new_level
) {
1174 re
->level
= info
->array
.level
;
1175 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1176 re
->before
.layout
= info
->array
.layout
;
1180 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1181 re
->before
.layout
= info
->array
.layout
;
1186 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1187 switch (info
->array
.layout
) {
1188 case ALGORITHM_LEFT_ASYMMETRIC
:
1189 re
->before
.layout
= ALGORITHM_LEFT_ASYMMETRIC_6
;
1191 case ALGORITHM_RIGHT_ASYMMETRIC
:
1192 re
->before
.layout
= ALGORITHM_RIGHT_ASYMMETRIC_6
;
1194 case ALGORITHM_LEFT_SYMMETRIC
:
1195 re
->before
.layout
= ALGORITHM_LEFT_SYMMETRIC_6
;
1197 case ALGORITHM_RIGHT_SYMMETRIC
:
1198 re
->before
.layout
= ALGORITHM_RIGHT_SYMMETRIC_6
;
1200 case ALGORITHM_PARITY_0
:
1201 re
->before
.layout
= ALGORITHM_PARITY_0_6
;
1203 case ALGORITHM_PARITY_N
:
1204 re
->before
.layout
= ALGORITHM_PARITY_N_6
;
1207 return "Cannot convert an array with this layout";
1211 if (info
->array
.raid_disks
!= 2)
1212 return "Can only convert a 2-device array to RAID1";
1213 if (info
->delta_disks
!= UnSet
&&
1214 info
->delta_disks
!= 0)
1215 return "Cannot set raid_disk when "
1216 "converting RAID5->RAID1";
1220 return "Impossible level change requested";
1224 switch (info
->new_level
) {
1230 re
->before
.data_disks
= info
->array
.raid_disks
- 2;
1231 re
->before
.layout
= info
->array
.layout
;
1234 return "Impossible level change requested";
1239 /* If we reached here then it looks like a re-stripe is
1240 * happening. We have determined the intermediate level
1241 * and initial raid_disks/layout and stored these in 're'.
1243 * We need to deduce the final layout that can be atomically
1244 * converted to the end state.
1246 switch (info
->new_level
) {
1248 /* We can only get to RAID0 from RAID4 or RAID5
1249 * with appropriate layout and one extra device
1251 if (re
->level
!= 4 && re
->level
!= 5)
1252 return "Cannot covert to RAID0 from this level";
1254 switch (re
->level
) {
1256 re
->after
.layout
= 0;
1259 re
->after
.layout
= ALGORITHM_PARITY_N
;
1265 /* We can only get to RAID4 from RAID5 */
1266 if (re
->level
!= 4 && re
->level
!= 5)
1267 return "Cannot convert to RAID4 from this level";
1269 switch (re
->level
) {
1271 re
->after
.layout
= 0;
1274 re
->after
.layout
= ALGORITHM_PARITY_N
;
1280 /* We get to RAID5 from RAID5 or RAID6 */
1281 if (re
->level
!= 5 && re
->level
!= 6)
1282 return "Cannot convert to RAID5 from this level";
1284 switch (re
->level
) {
1286 if (info
->new_layout
== UnSet
)
1287 re
->after
.layout
= re
->before
.layout
;
1289 re
->after
.layout
= info
->new_layout
;
1292 if (info
->new_layout
== UnSet
)
1293 info
->new_layout
= re
->before
.layout
;
1295 /* after.layout needs to be raid6 version of new_layout */
1296 if (info
->new_layout
== ALGORITHM_PARITY_N
)
1297 re
->after
.layout
= ALGORITHM_PARITY_N
;
1300 char *ls
= map_num(r5layout
, info
->new_layout
);
1303 /* Current RAID6 layout has a RAID5
1306 strcat(strcpy(layout
, ls
), "-6");
1307 l
= map_name(r6layout
, layout
);
1309 return "Cannot find RAID6 layout"
1312 /* Current RAID6 has no equivalent.
1313 * If it is already a '-6' layout we
1314 * can leave it unchanged, else we must
1317 ls
= map_num(r6layout
, info
->new_layout
);
1319 strcmp(ls
+strlen(ls
)-2, "-6") != 0)
1320 return "Please specify new layout";
1321 l
= info
->new_layout
;
1323 re
->after
.layout
= l
;
1329 /* We must already be at level 6 */
1331 return "Impossible level change";
1332 if (info
->new_layout
== UnSet
)
1333 re
->after
.layout
= info
->array
.layout
;
1335 re
->after
.layout
= info
->new_layout
;
1338 return "Impossible level change requested";
1340 if (info
->delta_disks
== UnSet
)
1341 info
->delta_disks
= delta_parity
;
1343 re
->after
.data_disks
= (re
->before
.data_disks
1346 switch (re
->level
) {
1347 case 6: re
->parity
= 2;
1350 case 5: re
->parity
= 1;
1352 default: re
->parity
= 0;
1355 /* So we have a restripe operation, we need to calculate the number
1356 * of blocks per reshape operation.
1358 if (info
->new_chunk
== 0)
1359 info
->new_chunk
= info
->array
.chunk_size
;
1360 if (re
->after
.data_disks
== re
->before
.data_disks
&&
1361 re
->after
.layout
== re
->before
.layout
&&
1362 info
->new_chunk
== info
->array
.chunk_size
) {
1363 /* Nothing to change */
1364 re
->backup_blocks
= 0;
1367 if (re
->after
.data_disks
== 1 && re
->before
.data_disks
== 1) {
1368 /* chunk and layout changes make no difference */
1369 re
->backup_blocks
= 0;
1373 if (re
->after
.data_disks
== re
->before
.data_disks
&&
1374 get_linux_version() < 2006032)
1375 return "in-place reshape is not safe before 2.6.32 - sorry.";
1377 if (re
->after
.data_disks
< re
->before
.data_disks
&&
1378 get_linux_version() < 2006030)
1379 return "reshape to fewer devices is not supported before 2.6.30 - sorry.";
1381 re
->backup_blocks
= compute_backup_blocks(
1382 info
->new_chunk
, info
->array
.chunk_size
,
1383 re
->after
.data_disks
,
1384 re
->before
.data_disks
);
1386 re
->new_size
= info
->component_size
* re
->after
.data_disks
;
1390 static int set_array_size(struct supertype
*st
, struct mdinfo
*sra
,
1393 struct mdinfo
*info
;
1397 if ((st
== NULL
) || (sra
== NULL
))
1400 if (text_version
== NULL
)
1401 text_version
= sra
->text_version
;
1402 subarray
= strchr(text_version
+1, '/')+1;
1403 info
= st
->ss
->container_content(st
, subarray
);
1405 unsigned long long current_size
= 0;
1406 unsigned long long new_size
=
1407 info
->custom_array_size
/2;
1409 if (sysfs_get_ll(sra
, NULL
, "array_size", ¤t_size
) == 0 &&
1410 new_size
> current_size
) {
1411 if (sysfs_set_num(sra
, NULL
, "array_size", new_size
)
1413 dprintf("Error: Cannot set array size");
1416 dprintf("Array size changed");
1418 dprintf(" from %llu to %llu.\n",
1419 current_size
, new_size
);
1423 dprintf("Error: set_array_size(): info pointer in NULL\n");
1428 static int reshape_array(char *container
, int fd
, char *devname
,
1429 struct supertype
*st
, struct mdinfo
*info
,
1430 int force
, struct mddev_dev
*devlist
,
1431 char *backup_file
, int verbose
, int forked
,
1432 int restart
, int freeze_reshape
);
1433 static int reshape_container(char *container
, char *devname
,
1435 struct supertype
*st
,
1436 struct mdinfo
*info
,
1439 int verbose
, int restart
, int freeze_reshape
);
1441 int Grow_reshape(char *devname
, int fd
,
1442 struct mddev_dev
*devlist
,
1443 struct context
*c
, struct shape
*s
)
1445 /* Make some changes in the shape of an array.
1446 * The kernel must support the change.
1448 * There are three different changes. Each can trigger
1449 * a resync or recovery so we freeze that until we have
1450 * requested everything (if kernel supports freezing - 2.6.30).
1452 * - change size (i.e. component_size)
1454 * - change layout/chunksize/ndisks
1456 * The last can require a reshape. It is different on different
1457 * levels so we need to check the level before actioning it.
1458 * Some times the level change needs to be requested after the
1459 * reshape (e.g. raid6->raid5, raid5->raid0)
1462 struct mdu_array_info_s array
;
1464 struct supertype
*st
;
1465 char *subarray
= NULL
;
1469 char *container
= NULL
;
1470 char container_buf
[20];
1473 struct mddev_dev
*dv
;
1479 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) < 0) {
1480 pr_err("%s is not an active md array - aborting\n",
1486 (s
->chunk
|| s
->level
!= UnSet
|| s
->layout_str
|| s
->raiddisks
)) {
1487 pr_err("cannot change component size at the same time "
1488 "as other changes.\n"
1489 " Change size first, then check data is intact before "
1490 "making other changes.\n");
1494 if (s
->raiddisks
&& s
->raiddisks
< array
.raid_disks
&& array
.level
> 1 &&
1495 get_linux_version() < 2006032 &&
1496 !check_env("MDADM_FORCE_FEWER")) {
1497 pr_err("reducing the number of devices is not safe before Linux 2.6.32\n"
1498 " Please use a newer kernel\n");
1502 st
= super_by_fd(fd
, &subarray
);
1504 pr_err("Unable to determine metadata format for %s\n", devname
);
1507 if (s
->raiddisks
> st
->max_devs
) {
1508 pr_err("Cannot increase raid-disks on this array"
1509 " beyond %d\n", st
->max_devs
);
1513 /* in the external case we need to check that the requested reshape is
1514 * supported, and perform an initial check that the container holds the
1515 * pre-requisite spare devices (mdmon owns final validation)
1517 if (st
->ss
->external
) {
1522 container_dev
= st
->container_dev
;
1523 cfd
= open_dev_excl(st
->container_dev
);
1525 container_dev
= st
->devnum
;
1527 cfd
= open_dev_excl(st
->devnum
);
1531 pr_err("Unable to open container for %s\n",
1537 fmt_devname(container_buf
, container_dev
);
1538 container
= container_buf
;
1540 rv
= st
->ss
->load_container(st
, cfd
, NULL
);
1543 pr_err("Cannot read superblock for %s\n",
1549 /* check if operation is supported for metadata handler */
1550 if (st
->ss
->container_content
) {
1551 struct mdinfo
*cc
= NULL
;
1552 struct mdinfo
*content
= NULL
;
1554 cc
= st
->ss
->container_content(st
, subarray
);
1555 for (content
= cc
; content
; content
= content
->next
) {
1556 int allow_reshape
= 1;
1558 /* check if reshape is allowed based on metadata
1559 * indications stored in content.array.status
1561 if (content
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
))
1563 if (content
->array
.state
1564 & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
))
1566 if (!allow_reshape
) {
1567 pr_err("cannot reshape arrays in"
1568 " container with unsupported"
1569 " metadata: %s(%s)\n",
1570 devname
, container_buf
);
1578 if (mdmon_running(container_dev
))
1579 st
->update_tail
= &st
->updates
;
1583 for (dv
= devlist
; dv
; dv
= dv
->next
)
1585 if (s
->raiddisks
> array
.raid_disks
&&
1586 array
.spare_disks
+added_disks
< (s
->raiddisks
- array
.raid_disks
) &&
1588 pr_err("Need %d spare%s to avoid degraded array,"
1589 " and only have %d.\n"
1590 " Use --force to over-ride this check.\n",
1591 s
->raiddisks
- array
.raid_disks
,
1592 s
->raiddisks
- array
.raid_disks
== 1 ? "" : "s",
1593 array
.spare_disks
+ added_disks
);
1597 sra
= sysfs_read(fd
, 0, GET_LEVEL
| GET_DISKS
| GET_DEVS
1598 | GET_STATE
| GET_VERSION
);
1600 if (st
->ss
->external
&& subarray
== NULL
) {
1601 array
.level
= LEVEL_CONTAINER
;
1602 sra
->array
.level
= LEVEL_CONTAINER
;
1605 pr_err("failed to read sysfs parameters for %s\n",
1609 frozen
= freeze(st
);
1611 /* freeze() already spewed the reason */
1614 } else if (frozen
< 0) {
1615 pr_err("%s is performing resync/recovery and cannot"
1616 " be reshaped\n", devname
);
1621 /* ========= set size =============== */
1622 if (s
->size
> 0 && (s
->size
== MAX_DISKS
|| s
->size
!= (unsigned)array
.size
)) {
1623 unsigned long long orig_size
= get_component_size(fd
)/2;
1624 unsigned long long min_csize
;
1626 int raid0_takeover
= 0;
1629 orig_size
= (unsigned) array
.size
;
1631 if (reshape_super(st
, s
->size
, UnSet
, UnSet
, 0, 0, UnSet
, NULL
,
1632 devname
, APPLY_METADATA_CHANGES
, c
->verbose
> 0)) {
1637 if (st
->ss
->external
) {
1638 /* metadata can have size limitation
1639 * update size value according to metadata information
1641 struct mdinfo
*sizeinfo
=
1642 st
->ss
->container_content(st
, subarray
);
1644 unsigned long long new_size
=
1645 sizeinfo
->custom_array_size
/2;
1646 int data_disks
= get_data_disks(
1647 sizeinfo
->array
.level
,
1648 sizeinfo
->array
.layout
,
1649 sizeinfo
->array
.raid_disks
);
1650 new_size
/= data_disks
;
1651 dprintf("Metadata size correction from %llu to "
1652 "%llu (%llu)\n", orig_size
, new_size
,
1653 new_size
* data_disks
);
1655 sysfs_free(sizeinfo
);
1659 /* Update the size of each member device in case
1660 * they have been resized. This will never reduce
1661 * below the current used-size. The "size" attribute
1662 * understands '0' to mean 'max'.
1666 for (mdi
= sra
->devs
; mdi
; mdi
= mdi
->next
) {
1667 if (sysfs_set_num(sra
, mdi
, "size",
1668 s
->size
== MAX_SIZE
? 0 : s
->size
) < 0) {
1669 /* Probably kernel refusing to let us
1670 * reduce the size - not an error.
1674 if (array
.not_persistent
== 0 &&
1675 array
.major_version
== 0 &&
1676 get_linux_version() < 3001000) {
1677 /* Dangerous to allow size to exceed 2TB */
1678 unsigned long long csize
;
1679 if (sysfs_get_ll(sra
, mdi
, "size", &csize
) == 0) {
1680 if (csize
>= 2ULL*1024*1024*1024)
1681 csize
= 2ULL*1024*1024*1024;
1682 if ((min_csize
== 0 || (min_csize
1689 pr_err("Cannot set size on "
1690 "array members.\n");
1691 goto size_change_error
;
1693 if (min_csize
&& s
->size
> min_csize
) {
1694 pr_err("Cannot safely make this array "
1695 "use more than 2TB per device on this kernel.\n");
1697 goto size_change_error
;
1699 if (min_csize
&& s
->size
== MAX_SIZE
) {
1700 /* Don't let the kernel choose a size - it will get
1703 pr_err("Limited v0.90 array to "
1704 "2TB per device\n");
1705 s
->size
= min_csize
;
1707 if (st
->ss
->external
) {
1708 if (sra
->array
.level
== 0) {
1709 rv
= sysfs_set_str(sra
, NULL
, "level",
1713 /* get array parametes after takeover
1714 * to chane one parameter at time only
1716 rv
= ioctl(fd
, GET_ARRAY_INFO
, &array
);
1719 /* make sure mdmon is
1720 * aware of the new level */
1721 if (!mdmon_running(st
->container_dev
))
1722 start_mdmon(st
->container_dev
);
1723 ping_monitor(container
);
1724 if (mdmon_running(st
->container_dev
) &&
1725 st
->update_tail
== NULL
)
1726 st
->update_tail
= &st
->updates
;
1729 if (s
->size
== MAX_SIZE
)
1731 array
.size
= s
->size
;
1732 if ((unsigned)array
.size
!= s
->size
) {
1733 /* got truncated to 32bit, write to
1734 * component_size instead
1737 rv
= sysfs_set_num(sra
, NULL
,
1738 "component_size", s
->size
);
1742 rv
= ioctl(fd
, SET_ARRAY_INFO
, &array
);
1744 /* manage array size when it is managed externally
1746 if ((rv
== 0) && st
->ss
->external
)
1747 rv
= set_array_size(st
, sra
, sra
->text_version
);
1750 if (raid0_takeover
) {
1751 /* do not recync non-existing parity,
1752 * we will drop it anyway
1754 sysfs_set_str(sra
, NULL
, "sync_action", "frozen");
1755 /* go back to raid0, drop parity disk
1757 sysfs_set_str(sra
, NULL
, "level", "raid0");
1758 ioctl(fd
, GET_ARRAY_INFO
, &array
);
1765 /* restore metadata */
1766 if (reshape_super(st
, orig_size
, UnSet
, UnSet
, 0, 0,
1767 UnSet
, NULL
, devname
,
1768 ROLLBACK_METADATA_CHANGES
,
1771 pr_err("Cannot set device size for %s: %s\n",
1772 devname
, strerror(err
));
1774 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
1775 cont_err("Bitmap must be removed before size can be changed\n");
1779 if (s
->assume_clean
) {
1780 /* This will fail on kernels newer than 3.0 unless
1781 * a backport has been arranged.
1784 sysfs_set_str(sra
, NULL
, "resync_start", "none") < 0)
1785 pr_err("--assume-clean not support with --grow on this kernel\n");
1787 ioctl(fd
, GET_ARRAY_INFO
, &array
);
1788 s
->size
= get_component_size(fd
)/2;
1790 s
->size
= array
.size
;
1791 if (c
->verbose
>= 0) {
1792 if (s
->size
== orig_size
)
1793 pr_err("component size of %s "
1794 "unchanged at %lluK\n",
1797 pr_err("component size of %s "
1798 "has been set to %lluK\n",
1802 } else if (array
.level
!= LEVEL_CONTAINER
) {
1803 s
->size
= get_component_size(fd
)/2;
1805 s
->size
= array
.size
;
1808 /* See if there is anything else to do */
1809 if ((s
->level
== UnSet
|| s
->level
== array
.level
) &&
1810 (s
->layout_str
== NULL
) &&
1811 (s
->chunk
== 0 || s
->chunk
== array
.chunk_size
) &&
1812 (s
->raiddisks
== 0 || s
->raiddisks
== array
.raid_disks
)) {
1813 /* Nothing more to do */
1814 if (!changed
&& c
->verbose
>= 0)
1815 pr_err("%s: no change requested\n",
1820 /* ========= check for Raid10/Raid1 -> Raid0 conversion ===============
1821 * current implementation assumes that following conditions must be met:
1824 * - near_copies == 2
1826 if ((s
->level
== 0 && array
.level
== 10 && sra
&&
1827 array
.layout
== ((1 << 8) + 2) && !(array
.raid_disks
& 1)) ||
1828 (s
->level
== 0 && array
.level
== 1 && sra
)) {
1830 err
= remove_disks_for_takeover(st
, sra
, array
.layout
);
1832 dprintf(Name
": Array cannot be reshaped\n");
1838 /* Make sure mdmon has seen the device removal
1839 * and updated metadata before we continue with
1843 ping_monitor(container
);
1846 memset(&info
, 0, sizeof(info
));
1848 sysfs_init(&info
, fd
, NoMdDev
);
1849 strcpy(info
.text_version
, sra
->text_version
);
1850 info
.component_size
= s
->size
*2;
1851 info
.new_level
= s
->level
;
1852 info
.new_chunk
= s
->chunk
* 1024;
1853 if (info
.array
.level
== LEVEL_CONTAINER
) {
1854 info
.delta_disks
= UnSet
;
1855 info
.array
.raid_disks
= s
->raiddisks
;
1856 } else if (s
->raiddisks
)
1857 info
.delta_disks
= s
->raiddisks
- info
.array
.raid_disks
;
1859 info
.delta_disks
= UnSet
;
1860 if (s
->layout_str
== NULL
) {
1861 info
.new_layout
= UnSet
;
1862 if (info
.array
.level
== 6 &&
1863 (info
.new_level
== 6 || info
.new_level
== UnSet
) &&
1864 info
.array
.layout
>= 16) {
1865 pr_err("%s has a non-standard layout. If you"
1866 " wish to preserve this\n", devname
);
1867 cont_err("during the reshape, please specify"
1868 " --layout=preserve\n");
1869 cont_err("If you want to change it, specify a"
1870 " layout or use --layout=normalise\n");
1874 } else if (strcmp(s
->layout_str
, "normalise") == 0 ||
1875 strcmp(s
->layout_str
, "normalize") == 0) {
1876 /* If we have a -6 RAID6 layout, remove the '-6'. */
1877 info
.new_layout
= UnSet
;
1878 if (info
.array
.level
== 6 && info
.new_level
== UnSet
) {
1880 strcpy(l
, map_num(r6layout
, info
.array
.layout
));
1881 h
= strrchr(l
, '-');
1882 if (h
&& strcmp(h
, "-6") == 0) {
1884 info
.new_layout
= map_name(r6layout
, l
);
1887 pr_err("%s is only meaningful when reshaping"
1888 " a RAID6 array.\n", s
->layout_str
);
1892 } else if (strcmp(s
->layout_str
, "preserve") == 0) {
1893 /* This means that a non-standard RAID6 layout
1896 * - When reshape a RAID6 (e.g. adding a device)
1897 * which is in a non-standard layout, it is OK
1898 * to preserve that layout.
1899 * - When converting a RAID5 to RAID6, leave it in
1900 * the XXX-6 layout, don't re-layout.
1902 if (info
.array
.level
== 6 && info
.new_level
== UnSet
)
1903 info
.new_layout
= info
.array
.layout
;
1904 else if (info
.array
.level
== 5 && info
.new_level
== 6) {
1906 strcpy(l
, map_num(r5layout
, info
.array
.layout
));
1908 info
.new_layout
= map_name(r6layout
, l
);
1910 pr_err("%s in only meaningful when reshaping"
1911 " to RAID6\n", s
->layout_str
);
1916 int l
= info
.new_level
;
1918 l
= info
.array
.level
;
1921 info
.new_layout
= map_name(r5layout
, s
->layout_str
);
1924 info
.new_layout
= map_name(r6layout
, s
->layout_str
);
1927 info
.new_layout
= parse_layout_10(s
->layout_str
);
1930 info
.new_layout
= parse_layout_faulty(s
->layout_str
);
1933 pr_err("layout not meaningful"
1934 " with this level\n");
1938 if (info
.new_layout
== UnSet
) {
1939 pr_err("layout %s not understood"
1940 " for this level\n",
1947 if (array
.level
== LEVEL_FAULTY
) {
1948 if (s
->level
!= UnSet
&& s
->level
!= array
.level
) {
1949 pr_err("cannot change level of Faulty device\n");
1953 pr_err("cannot set chunksize of Faulty device\n");
1956 if (s
->raiddisks
&& s
->raiddisks
!= 1) {
1957 pr_err("cannot set raid_disks of Faulty device\n");
1960 if (s
->layout_str
) {
1961 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
1962 dprintf("Cannot get array information.\n");
1965 array
.layout
= info
.new_layout
;
1966 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
1967 pr_err("failed to set new layout\n");
1969 } else if (c
->verbose
>= 0)
1970 printf("layout for %s set to %d\n",
1971 devname
, array
.layout
);
1973 } else if (array
.level
== LEVEL_CONTAINER
) {
1974 /* This change is to be applied to every array in the
1975 * container. This is only needed when the metadata imposes
1976 * restraints of the various arrays in the container.
1977 * Currently we only know that IMSM requires all arrays
1978 * to have the same number of devices so changing the
1979 * number of devices (On-Line Capacity Expansion) must be
1980 * performed at the level of the container
1982 rv
= reshape_container(container
, devname
, -1, st
, &info
,
1983 c
->force
, c
->backup_file
, c
->verbose
, 0, 0);
1986 /* get spare devices from external metadata
1988 if (st
->ss
->external
) {
1989 struct mdinfo
*info2
;
1991 info2
= st
->ss
->container_content(st
, subarray
);
1993 info
.array
.spare_disks
=
1994 info2
->array
.spare_disks
;
1999 /* Impose these changes on a single array. First
2000 * check that the metadata is OK with the change. */
2002 if (reshape_super(st
, -1, info
.new_level
,
2003 info
.new_layout
, info
.new_chunk
,
2004 info
.array
.raid_disks
, info
.delta_disks
,
2005 c
->backup_file
, devname
, APPLY_METADATA_CHANGES
,
2011 rv
= reshape_array(container
, fd
, devname
, st
, &info
, c
->force
,
2012 devlist
, c
->backup_file
, c
->verbose
, 0, 0, 0);
2022 /* verify_reshape_position()
2023 * Function checks if reshape position in metadata is not farther
2024 * than position in md.
2026 * 0 : not valid sysfs entry
2027 * it can be caused by not started reshape, it should be started
2028 * by reshape array or raid0 array is before takeover
2029 * -1 : error, reshape position is obviously wrong
2030 * 1 : success, reshape progress correct or updated
2032 static int verify_reshape_position(struct mdinfo
*info
, int level
)
2038 /* read sync_max, failure can mean raid0 array */
2039 rv
= sysfs_get_str(info
, NULL
, "sync_max", buf
, 40);
2043 unsigned long long position
= strtoull(buf
, &ep
, 0);
2045 dprintf(Name
": Read sync_max sysfs entry is: %s\n", buf
);
2046 if (!(ep
== buf
|| (*ep
!= 0 && *ep
!= '\n' && *ep
!= ' '))) {
2047 position
*= get_data_disks(level
,
2049 info
->array
.raid_disks
);
2050 if (info
->reshape_progress
< position
) {
2051 dprintf("Corrected reshape progress (%llu) to "
2052 "md position (%llu)\n",
2053 info
->reshape_progress
, position
);
2054 info
->reshape_progress
= position
;
2056 } else if (info
->reshape_progress
> position
) {
2057 pr_err("Fatal error: array "
2058 "reshape was not properly frozen "
2059 "(expected reshape position is %llu, "
2060 "but reshape progress is %llu.\n",
2061 position
, info
->reshape_progress
);
2064 dprintf("Reshape position in md and metadata "
2069 } else if (rv
== 0) {
2070 /* for valid sysfs entry, 0-length content
2071 * should be indicated as error
2079 static int reshape_array(char *container
, int fd
, char *devname
,
2080 struct supertype
*st
, struct mdinfo
*info
,
2081 int force
, struct mddev_dev
*devlist
,
2082 char *backup_file
, int verbose
, int forked
,
2083 int restart
, int freeze_reshape
)
2085 struct reshape reshape
;
2088 int orig_level
= UnSet
;
2091 struct mdu_array_info_s array
;
2094 struct mddev_dev
*dv
;
2098 unsigned long long *offsets
= NULL
;
2102 unsigned long blocks
;
2103 unsigned long cache
;
2104 unsigned long long array_size
;
2106 struct mdinfo
*sra
= NULL
;
2108 /* when reshaping a RAID0, the component_size might be zero.
2109 * So try to fix that up.
2111 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
2112 dprintf("Cannot get array information.\n");
2115 if (array
.level
== 0 && info
->component_size
== 0) {
2116 get_dev_size(fd
, NULL
, &array_size
);
2117 info
->component_size
= array_size
/ array
.raid_disks
;
2120 if (info
->reshape_active
) {
2121 int new_level
= info
->new_level
;
2122 info
->new_level
= UnSet
;
2123 if (info
->delta_disks
> 0)
2124 info
->array
.raid_disks
-= info
->delta_disks
;
2125 msg
= analyse_change(info
, &reshape
);
2126 info
->new_level
= new_level
;
2127 if (info
->delta_disks
> 0)
2128 info
->array
.raid_disks
+= info
->delta_disks
;
2130 /* Make sure the array isn't read-only */
2131 ioctl(fd
, RESTART_ARRAY_RW
, 0);
2133 msg
= analyse_change(info
, &reshape
);
2135 pr_err("%s\n", msg
);
2139 (reshape
.level
!= info
->array
.level
||
2140 reshape
.before
.layout
!= info
->array
.layout
||
2141 reshape
.before
.data_disks
+ reshape
.parity
2142 != info
->array
.raid_disks
- max(0, info
->delta_disks
))) {
2143 pr_err("reshape info is not in native format -"
2144 " cannot continue.\n");
2148 if (st
->ss
->external
&& restart
&& (info
->reshape_progress
== 0)) {
2149 /* When reshape is restarted from '0', very begin of array
2150 * it is possible that for external metadata reshape and array
2151 * configuration doesn't happen.
2152 * Check if md has the same opinion, and reshape is restarted
2153 * from 0. If so, this is regular reshape start after reshape
2154 * switch in metadata to next array only.
2156 if ((verify_reshape_position(info
, reshape
.level
) >= 0) &&
2157 (info
->reshape_progress
== 0))
2161 /* reshape already started. just skip to monitoring the reshape */
2162 if (reshape
.backup_blocks
== 0)
2166 /* The container is frozen but the array may not be.
2167 * So freeze the array so spares don't get put to the wrong use
2168 * FIXME there should probably be a cleaner separation between
2169 * freeze_array and freeze_container.
2171 sysfs_freeze_array(info
);
2172 /* Check we have enough spares to not be degraded */
2174 for (dv
= devlist
; dv
; dv
=dv
->next
)
2176 spares_needed
= max(reshape
.before
.data_disks
,
2177 reshape
.after
.data_disks
)
2178 + reshape
.parity
- array
.raid_disks
;
2181 info
->new_level
> 1 && info
->array
.level
> 1 &&
2182 spares_needed
> info
->array
.spare_disks
+ added_disks
) {
2183 pr_err("Need %d spare%s to avoid degraded array,"
2184 " and only have %d.\n"
2185 " Use --force to over-ride this check.\n",
2187 spares_needed
== 1 ? "" : "s",
2188 info
->array
.spare_disks
+ added_disks
);
2191 /* Check we have enough spares to not fail */
2192 spares_needed
= max(reshape
.before
.data_disks
,
2193 reshape
.after
.data_disks
)
2195 if ((info
->new_level
> 1 || info
->new_level
== 0) &&
2196 spares_needed
> info
->array
.spare_disks
+added_disks
) {
2197 pr_err("Need %d spare%s to create working array,"
2198 " and only have %d.\n",
2200 spares_needed
== 1 ? "" : "s",
2201 info
->array
.spare_disks
+ added_disks
);
2205 if (reshape
.level
!= array
.level
) {
2206 char *c
= map_num(pers
, reshape
.level
);
2211 err
= sysfs_set_str(info
, NULL
, "level", c
);
2214 pr_err("%s: could not set level to %s\n",
2217 (info
->array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2218 cont_err("Bitmap must be removed"
2219 " before level can be changed\n");
2223 pr_err("level of %s changed to %s\n",
2225 orig_level
= array
.level
;
2226 sysfs_freeze_array(info
);
2228 if (reshape
.level
> 0 && st
->ss
->external
) {
2229 /* make sure mdmon is aware of the new level */
2230 if (mdmon_running(st
->container_dev
))
2231 flush_mdmon(container
);
2233 if (!mdmon_running(st
->container_dev
))
2234 start_mdmon(st
->container_dev
);
2235 ping_monitor(container
);
2236 if (mdmon_running(st
->container_dev
) &&
2237 st
->update_tail
== NULL
)
2238 st
->update_tail
= &st
->updates
;
2241 /* ->reshape_super might have chosen some spares from the
2242 * container that it wants to be part of the new array.
2243 * We can collect them with ->container_content and give
2244 * them to the kernel.
2246 if (st
->ss
->reshape_super
&& st
->ss
->container_content
) {
2247 char *subarray
= strchr(info
->text_version
+1, '/')+1;
2248 struct mdinfo
*info2
=
2249 st
->ss
->container_content(st
, subarray
);
2253 sysfs_init(info2
, fd
, st
->devnum
);
2254 /* When increasing number of devices, we need to set
2255 * new raid_disks before adding these, or they might
2258 if (reshape
.backup_blocks
&&
2259 reshape
.after
.data_disks
> reshape
.before
.data_disks
)
2260 subarray_set_num(container
, info2
, "raid_disks",
2261 reshape
.after
.data_disks
+
2263 for (d
= info2
->devs
; d
; d
= d
->next
) {
2264 if (d
->disk
.state
== 0 &&
2265 d
->disk
.raid_disk
>= 0) {
2266 /* This is a spare that wants to
2267 * be part of the array.
2269 add_disk(fd
, st
, info2
, d
);
2275 /* We might have been given some devices to add to the
2276 * array. Now that the array has been changed to the right
2277 * level and frozen, we can safely add them.
2280 Manage_subdevs(devname
, fd
, devlist
, verbose
,
2283 if (reshape
.backup_blocks
== 0) {
2284 /* No restriping needed, but we might need to impose
2285 * some more changes: layout, raid_disks, chunk_size
2287 /* read current array info */
2288 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
2289 dprintf("Cannot get array information.\n");
2292 /* compare current array info with new values and if
2293 * it is different update them to new */
2294 if (info
->new_layout
!= UnSet
&&
2295 info
->new_layout
!= array
.layout
) {
2296 array
.layout
= info
->new_layout
;
2297 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2298 pr_err("failed to set new layout\n");
2300 } else if (verbose
>= 0)
2301 printf("layout for %s set to %d\n",
2302 devname
, array
.layout
);
2304 if (info
->delta_disks
!= UnSet
&&
2305 info
->delta_disks
!= 0 &&
2306 array
.raid_disks
!= (info
->array
.raid_disks
+ info
->delta_disks
)) {
2307 array
.raid_disks
+= info
->delta_disks
;
2308 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2309 pr_err("failed to set raid disks\n");
2311 } else if (verbose
>= 0) {
2312 printf("raid_disks for %s set to %d\n",
2313 devname
, array
.raid_disks
);
2316 if (info
->new_chunk
!= 0 &&
2317 info
->new_chunk
!= array
.chunk_size
) {
2318 if (sysfs_set_num(info
, NULL
,
2319 "chunk_size", info
->new_chunk
) != 0) {
2320 pr_err("failed to set chunk size\n");
2322 } else if (verbose
>= 0)
2323 printf("chunk size for %s set to %d\n",
2324 devname
, array
.chunk_size
);
2331 * There are three possibilities.
2332 * 1/ The array will shrink.
2333 * We need to ensure the reshape will pause before reaching
2334 * the 'critical section'. We also need to fork and wait for
2335 * that to happen. When it does we
2336 * suspend/backup/complete/unfreeze
2338 * 2/ The array will not change size.
2339 * This requires that we keep a backup of a sliding window
2340 * so that we can restore data after a crash. So we need
2341 * to fork and monitor progress.
2342 * In future we will allow the data_offset to change, so
2343 * a sliding backup becomes unnecessary.
2345 * 3/ The array will grow. This is relatively easy.
2346 * However the kernel's restripe routines will cheerfully
2347 * overwrite some early data before it is safe. So we
2348 * need to make a backup of the early parts of the array
2349 * and be ready to restore it if rebuild aborts very early.
2350 * For externally managed metadata, we still need a forked
2351 * child to monitor the reshape and suspend IO over the region
2352 * that is being reshaped.
2354 * We backup data by writing it to one spare, or to a
2355 * file which was given on command line.
2357 * In each case, we first make sure that storage is available
2358 * for the required backup.
2360 * - request the shape change.
2361 * - fork to handle backup etc.
2364 /* Check that we can hold all the data */
2365 get_dev_size(fd
, NULL
, &array_size
);
2366 if (reshape
.new_size
< (array_size
/512)) {
2367 pr_err("this change will reduce the size of the array.\n"
2368 " use --grow --array-size first to truncate array.\n"
2369 " e.g. mdadm --grow %s --array-size %llu\n",
2370 devname
, reshape
.new_size
/2);
2374 sra
= sysfs_read(fd
, 0,
2375 GET_COMPONENT
|GET_DEVS
|GET_OFFSET
|GET_STATE
|GET_CHUNK
|
2378 pr_err("%s: Cannot get array details from sysfs\n",
2383 /* Decide how many blocks (sectors) for a reshape
2384 * unit. The number we have so far is just a minimum
2386 blocks
= reshape
.backup_blocks
;
2387 if (reshape
.before
.data_disks
==
2388 reshape
.after
.data_disks
) {
2389 /* Make 'blocks' bigger for better throughput, but
2390 * not so big that we reject it below.
2391 * Try for 16 megabytes
2393 while (blocks
* 32 < sra
->component_size
&&
2397 pr_err("Need to backup %luK of critical "
2398 "section..\n", blocks
/2);
2400 if (blocks
>= sra
->component_size
/2) {
2401 pr_err("%s: Something wrong"
2402 " - reshape aborted\n",
2407 /* Now we need to open all these devices so we can read/write.
2409 nrdisks
= max(reshape
.before
.data_disks
,
2410 reshape
.after
.data_disks
) + reshape
.parity
2411 + sra
->array
.spare_disks
;
2412 fdlist
= xcalloc((1+nrdisks
), sizeof(int));
2413 offsets
= xcalloc((1+nrdisks
), sizeof(offsets
[0]));
2415 odisks
= reshape
.before
.data_disks
+ reshape
.parity
;
2416 d
= reshape_prepare_fdlist(devname
, sra
, odisks
,
2417 nrdisks
, blocks
, backup_file
,
2422 if ((st
->ss
->manage_reshape
== NULL
) ||
2423 (st
->ss
->recover_backup
== NULL
)) {
2424 if (backup_file
== NULL
) {
2425 if (reshape
.after
.data_disks
<=
2426 reshape
.before
.data_disks
) {
2427 pr_err("%s: Cannot grow - "
2428 "need backup-file\n", devname
);
2430 } else if (sra
->array
.spare_disks
== 0) {
2431 pr_err("%s: Cannot grow - "
2432 "need a spare or backup-file to backup "
2433 "critical section\n", devname
);
2437 if (!reshape_open_backup_file(backup_file
, fd
, devname
,
2439 fdlist
+d
, offsets
+d
,
2447 /* lastly, check that the internal stripe cache is
2448 * large enough, or it won't work.
2449 * It must hold at least 4 stripes of the larger
2452 cache
= max(info
->array
.chunk_size
, info
->new_chunk
);
2453 cache
*= 4; /* 4 stripes minimum */
2454 cache
/= 512; /* convert to sectors */
2455 disks
= min(reshape
.before
.data_disks
, reshape
.after
.data_disks
);
2456 /* make sure there is room for 'blocks' with a bit to spare */
2457 if (cache
< 16 + blocks
/ disks
)
2458 cache
= 16 + blocks
/ disks
;
2459 cache
/= (4096/512); /* Covert from sectors to pages */
2461 if (sra
->cache_size
< cache
)
2462 subarray_set_num(container
, sra
, "stripe_cache_size",
2465 /* Right, everything seems fine. Let's kick things off.
2466 * If only changing raid_disks, use ioctl, else use
2471 sra
->new_chunk
= info
->new_chunk
;
2474 /* for external metadata checkpoint saved by mdmon can be lost
2475 * or missed /due to e.g. crash/. Check if md is not during
2476 * restart farther than metadata points to.
2477 * If so, this means metadata information is obsolete.
2479 if (st
->ss
->external
)
2480 verify_reshape_position(info
, reshape
.level
);
2481 sra
->reshape_progress
= info
->reshape_progress
;
2483 sra
->reshape_progress
= 0;
2484 if (reshape
.after
.data_disks
< reshape
.before
.data_disks
)
2485 /* start from the end of the new array */
2486 sra
->reshape_progress
= (sra
->component_size
2487 * reshape
.after
.data_disks
);
2490 if (info
->array
.chunk_size
== info
->new_chunk
&&
2491 reshape
.before
.layout
== reshape
.after
.layout
&&
2492 st
->ss
->external
== 0) {
2493 /* use SET_ARRAY_INFO but only if reshape hasn't started */
2494 ioctl(fd
, GET_ARRAY_INFO
, &array
);
2495 array
.raid_disks
= reshape
.after
.data_disks
+ reshape
.parity
;
2497 ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2500 pr_err("Cannot set device shape for %s: %s\n",
2501 devname
, strerror(errno
));
2504 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2505 cont_err("Bitmap must be removed before"
2506 " shape can be changed\n");
2510 } else if (!restart
) {
2511 /* set them all just in case some old 'new_*' value
2512 * persists from some earlier problem.
2515 if (sysfs_set_num(sra
, NULL
, "chunk_size", info
->new_chunk
) < 0)
2517 if (!err
&& sysfs_set_num(sra
, NULL
, "layout",
2518 reshape
.after
.layout
) < 0)
2520 if (!err
&& subarray_set_num(container
, sra
, "raid_disks",
2521 reshape
.after
.data_disks
+
2522 reshape
.parity
) < 0)
2525 pr_err("Cannot set device shape for %s\n",
2529 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2530 cont_err("Bitmap must be removed before"
2531 " shape can be changed\n");
2536 err
= start_reshape(sra
, restart
, reshape
.before
.data_disks
,
2537 reshape
.after
.data_disks
);
2539 pr_err("Cannot %s reshape for %s\n",
2540 restart
? "continue" : "start",
2545 sysfs_set_str(sra
, NULL
, "array_state", "active");
2546 if (freeze_reshape
) {
2550 pr_err("Reshape has to be continued from"
2551 " location %llu when root filesystem has been mounted.\n",
2552 sra
->reshape_progress
);
2556 /* Now we just need to kick off the reshape and watch, while
2557 * handling backups of the data...
2558 * This is all done by a forked background process.
2560 switch(forked
? 0 : fork()) {
2562 pr_err("Cannot run child to monitor reshape: %s\n",
2577 if (check_env("MDADM_GROW_VERIFY"))
2578 fd
= open(devname
, O_RDONLY
| O_DIRECT
);
2581 mlockall(MCL_FUTURE
);
2583 if (st
->ss
->external
) {
2584 /* metadata handler takes it from here */
2585 done
= st
->ss
->manage_reshape(
2586 fd
, sra
, &reshape
, st
, blocks
,
2588 d
- odisks
, fdlist
+odisks
,
2591 done
= child_monitor(
2592 fd
, sra
, &reshape
, st
, blocks
,
2594 d
- odisks
, fdlist
+odisks
,
2600 if (backup_file
&& done
)
2601 unlink(backup_file
);
2607 if (!st
->ss
->external
&&
2608 !(reshape
.before
.data_disks
!= reshape
.after
.data_disks
2609 && info
->custom_array_size
) &&
2610 info
->new_level
== reshape
.level
&&
2612 /* no need to wait for the reshape to finish as
2613 * there is nothing more to do.
2620 if (st
->ss
->external
) {
2621 /* Re-load the metadata as much could have changed */
2622 int cfd
= open_dev(st
->container_dev
);
2624 flush_mdmon(container
);
2625 st
->ss
->free_super(st
);
2626 st
->ss
->load_container(st
, cfd
, container
);
2631 /* set new array size if required customer_array_size is used
2634 if (reshape
.before
.data_disks
!=
2635 reshape
.after
.data_disks
&&
2636 info
->custom_array_size
)
2637 set_array_size(st
, info
, info
->text_version
);
2639 if (info
->new_level
!= reshape
.level
) {
2641 c
= map_num(pers
, info
->new_level
);
2643 err
= sysfs_set_str(sra
, NULL
, "level", c
);
2645 pr_err("%s: could not set level "
2646 "to %s\n", devname
, c
);
2648 if (info
->new_level
== 0)
2649 st
->update_tail
= NULL
;
2661 if (orig_level
!= UnSet
&& sra
) {
2662 c
= map_num(pers
, orig_level
);
2663 if (c
&& sysfs_set_str(sra
, NULL
, "level", c
) == 0)
2664 pr_err("aborting level change\n");
2672 /* mdfd handle is passed to be closed in child process (after fork).
2674 int reshape_container(char *container
, char *devname
,
2676 struct supertype
*st
,
2677 struct mdinfo
*info
,
2680 int verbose
, int restart
, int freeze_reshape
)
2682 struct mdinfo
*cc
= NULL
;
2684 int last_devnum
= -1;
2686 /* component_size is not meaningful for a container,
2687 * so pass '-1' meaning 'no change'
2690 reshape_super(st
, -1, info
->new_level
,
2691 info
->new_layout
, info
->new_chunk
,
2692 info
->array
.raid_disks
, info
->delta_disks
,
2693 backup_file
, devname
, APPLY_METADATA_CHANGES
,
2701 /* ping monitor to be sure that update is on disk
2703 ping_monitor(container
);
2706 case -1: /* error */
2707 perror("Cannot fork to complete reshape\n");
2710 default: /* parent */
2711 if (!freeze_reshape
)
2712 printf(Name
": multi-array reshape continues"
2713 " in background\n");
2720 /* close unused handle in child process
2726 /* For each member array with reshape_active,
2727 * we need to perform the reshape.
2728 * We pick the first array that needs reshaping and
2729 * reshape it. reshape_array() will re-read the metadata
2730 * so the next time through a different array should be
2731 * ready for reshape.
2732 * It is possible that the 'different' array will not
2733 * be assembled yet. In that case we simple exit.
2734 * When it is assembled, the mdadm which assembles it
2735 * will take over the reshape.
2737 struct mdinfo
*content
;
2739 struct mdstat_ent
*mdstat
;
2744 cc
= st
->ss
->container_content(st
, NULL
);
2746 for (content
= cc
; content
; content
= content
->next
) {
2748 if (!content
->reshape_active
)
2751 subarray
= strchr(content
->text_version
+1, '/')+1;
2752 mdstat
= mdstat_by_subdev(subarray
,
2753 devname2devnum(container
));
2756 if (mdstat
->active
== 0) {
2757 pr_err("Skipping inactive "
2758 "array md%i.\n", mdstat
->devnum
);
2759 free_mdstat(mdstat
);
2768 adev
= map_dev(dev2major(mdstat
->devnum
),
2769 dev2minor(mdstat
->devnum
),
2772 adev
= content
->text_version
;
2774 fd
= open_dev(mdstat
->devnum
);
2776 printf(Name
": Device %s cannot be opened for reshape.",
2781 if (last_devnum
== mdstat
->devnum
) {
2782 /* Do not allow for multiple reshape_array() calls for
2784 * It can happen when reshape_array() returns without
2785 * error, when reshape is not finished (wrong reshape
2786 * starting/continuation conditions). Mdmon doesn't
2787 * switch to next array in container and reentry
2788 * conditions for the same array occur.
2789 * This is possibly interim until the behaviour of
2790 * reshape_array is resolved().
2792 printf(Name
": Multiple reshape execution detected for "
2793 "device %s.", adev
);
2797 last_devnum
= mdstat
->devnum
;
2799 sysfs_init(content
, fd
, mdstat
->devnum
);
2801 if (mdmon_running(devname2devnum(container
)))
2802 flush_mdmon(container
);
2804 rv
= reshape_array(container
, fd
, adev
, st
,
2805 content
, force
, NULL
,
2806 backup_file
, verbose
, 1, restart
,
2810 if (freeze_reshape
) {
2819 if (mdmon_running(devname2devnum(container
)))
2820 flush_mdmon(container
);
2829 * We run a child process in the background which performs the following
2831 * - wait for resync to reach a certain point
2832 * - suspend io to the following section
2833 * - backup that section
2834 * - allow resync to proceed further
2836 * - discard the backup.
2838 * When are combined in slightly different ways in the three cases.
2840 * - suspend/backup/allow/wait/resume/discard
2842 * - allow/wait/suspend/backup/allow/wait/resume/discard
2844 * - wait/resume/discard/suspend/backup/allow
2846 * suspend/backup/allow always come together
2847 * wait/resume/discard do too.
2848 * For the same-size case we have two backups to improve flow.
2852 int progress_reshape(struct mdinfo
*info
, struct reshape
*reshape
,
2853 unsigned long long backup_point
,
2854 unsigned long long wait_point
,
2855 unsigned long long *suspend_point
,
2856 unsigned long long *reshape_completed
)
2858 /* This function is called repeatedly by the reshape manager.
2859 * It determines how much progress can safely be made and allows
2861 * - 'info' identifies the array and particularly records in
2862 * ->reshape_progress the metadata's knowledge of progress
2863 * This is a sector offset from the start of the array
2864 * of the next array block to be relocated. This number
2865 * may increase from 0 or decrease from array_size, depending
2866 * on the type of reshape that is happening.
2867 * Note that in contrast, 'sync_completed' is a block count of the
2868 * reshape so far. It gives the distance between the start point
2869 * (head or tail of device) and the next place that data will be
2870 * written. It always increases.
2871 * - 'reshape' is the structure created by analyse_change
2872 * - 'backup_point' shows how much the metadata manager has backed-up
2873 * data. For reshapes with increasing progress, it is the next address
2874 * to be backed up, previous addresses have been backed-up. For
2875 * decreasing progress, it is the earliest address that has been
2876 * backed up - later address are also backed up.
2877 * So addresses between reshape_progress and backup_point are
2878 * backed up providing those are in the 'correct' order.
2879 * - 'wait_point' is an array address. When reshape_completed
2880 * passes this point, progress_reshape should return. It might
2881 * return earlier if it determines that ->reshape_progress needs
2882 * to be updated or further backup is needed.
2883 * - suspend_point is maintained by progress_reshape and the caller
2884 * should not touch it except to initialise to zero.
2885 * It is an array address and it only increases in 2.6.37 and earlier.
2886 * This makes it difficult to handle reducing reshapes with
2887 * external metadata.
2888 * However: it is similar to backup_point in that it records the
2889 * other end of a suspended region from reshape_progress.
2890 * it is moved to extend the region that is safe to backup and/or
2892 * - reshape_completed is read from sysfs and returned. The caller
2893 * should copy this into ->reshape_progress when it has reason to
2894 * believe that the metadata knows this, and any backup outside this
2898 * 1 if more data from backup_point - but only as far as suspend_point,
2899 * should be backed up
2900 * 0 if things are progressing smoothly
2901 * -1 if the reshape is finished because it is all done,
2902 * -2 if the reshape is finished due to an error.
2905 int advancing
= (reshape
->after
.data_disks
2906 >= reshape
->before
.data_disks
);
2907 unsigned long long need_backup
; /* All data between start of array and
2908 * here will at some point need to
2911 unsigned long long read_offset
, write_offset
;
2912 unsigned long long write_range
;
2913 unsigned long long max_progress
, target
, completed
;
2914 unsigned long long array_size
= (info
->component_size
2915 * reshape
->before
.data_disks
);
2919 /* First, we unsuspend any region that is now known to be safe.
2920 * If suspend_point is on the 'wrong' side of reshape_progress, then
2921 * we don't have or need suspension at the moment. This is true for
2922 * native metadata when we don't need to back-up.
2925 if (info
->reshape_progress
<= *suspend_point
)
2926 sysfs_set_num(info
, NULL
, "suspend_lo",
2927 info
->reshape_progress
);
2929 /* Note: this won't work in 2.6.37 and before.
2930 * Something somewhere should make sure we don't need it!
2932 if (info
->reshape_progress
>= *suspend_point
)
2933 sysfs_set_num(info
, NULL
, "suspend_hi",
2934 info
->reshape_progress
);
2937 /* Now work out how far it is safe to progress.
2938 * If the read_offset for ->reshape_progress is less than
2939 * 'blocks' beyond the write_offset, we can only progress as far
2941 * Otherwise we can progress until the write_offset for the new location
2942 * reaches (within 'blocks' of) the read_offset at the current location.
2943 * However that region must be suspended unless we are using native
2945 * If we need to suspend more, we limit it to 128M per device, which is
2946 * rather arbitrary and should be some time-based calculation.
2948 read_offset
= info
->reshape_progress
/ reshape
->before
.data_disks
;
2949 write_offset
= info
->reshape_progress
/ reshape
->after
.data_disks
;
2950 write_range
= info
->new_chunk
/512;
2951 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
)
2952 need_backup
= array_size
;
2954 need_backup
= reshape
->backup_blocks
;
2956 if (read_offset
< write_offset
+ write_range
)
2957 max_progress
= backup_point
;
2961 reshape
->after
.data_disks
;
2963 if (read_offset
> write_offset
- write_range
)
2964 /* Can only progress as far as has been backed up,
2965 * which must be suspended */
2966 max_progress
= backup_point
;
2967 else if (info
->reshape_progress
<= need_backup
)
2968 max_progress
= backup_point
;
2970 if (info
->array
.major_version
>= 0)
2971 /* Can progress until backup is needed */
2972 max_progress
= need_backup
;
2974 /* Can progress until metadata update is required */
2977 reshape
->after
.data_disks
;
2978 /* but data must be suspended */
2979 if (max_progress
< *suspend_point
)
2980 max_progress
= *suspend_point
;
2985 /* We know it is safe to progress to 'max_progress' providing
2986 * it is suspended or we are using native metadata.
2987 * Consider extending suspend_point 128M per device if it
2988 * is less than 64M per device beyond reshape_progress.
2989 * But always do a multiple of 'blocks'
2990 * FIXME this is too big - it takes to long to complete
2993 target
= 64*1024*2 * min(reshape
->before
.data_disks
,
2994 reshape
->after
.data_disks
);
2995 target
/= reshape
->backup_blocks
;
2998 target
*= reshape
->backup_blocks
;
3000 /* For externally managed metadata we always need to suspend IO to
3001 * the area being reshaped so we regularly push suspend_point forward.
3002 * For native metadata we only need the suspend if we are going to do
3006 if ((need_backup
> info
->reshape_progress
3007 || info
->array
.major_version
< 0) &&
3008 *suspend_point
< info
->reshape_progress
+ target
) {
3009 if (need_backup
< *suspend_point
+ 2 * target
)
3010 *suspend_point
= need_backup
;
3011 else if (*suspend_point
+ 2 * target
< array_size
)
3012 *suspend_point
+= 2 * target
;
3014 *suspend_point
= array_size
;
3015 sysfs_set_num(info
, NULL
, "suspend_hi", *suspend_point
);
3016 if (max_progress
> *suspend_point
)
3017 max_progress
= *suspend_point
;
3020 if (info
->array
.major_version
>= 0) {
3021 /* Only need to suspend when about to backup */
3022 if (info
->reshape_progress
< need_backup
* 2 &&
3023 *suspend_point
> 0) {
3025 sysfs_set_num(info
, NULL
, "suspend_lo", 0);
3026 sysfs_set_num(info
, NULL
, "suspend_hi", need_backup
);
3029 /* Need to suspend continually */
3030 if (info
->reshape_progress
< *suspend_point
)
3031 *suspend_point
= info
->reshape_progress
;
3032 if (*suspend_point
+ target
< info
->reshape_progress
)
3033 /* No need to move suspend region yet */;
3035 if (*suspend_point
>= 2 * target
)
3036 *suspend_point
-= 2 * target
;
3039 sysfs_set_num(info
, NULL
, "suspend_lo",
3042 if (max_progress
< *suspend_point
)
3043 max_progress
= *suspend_point
;
3047 /* now set sync_max to allow that progress. sync_max, like
3048 * sync_completed is a count of sectors written per device, so
3049 * we find the difference between max_progress and the start point,
3050 * and divide that by after.data_disks to get a sync_max
3052 * At the same time we convert wait_point to a similar number
3053 * for comparing against sync_completed.
3055 /* scale down max_progress to per_disk */
3056 max_progress
/= reshape
->after
.data_disks
;
3057 /* Round to chunk size as some kernels give an erroneously high number */
3058 max_progress
/= info
->new_chunk
/512;
3059 max_progress
*= info
->new_chunk
/512;
3060 /* And round to old chunk size as the kernel wants that */
3061 max_progress
/= info
->array
.chunk_size
/512;
3062 max_progress
*= info
->array
.chunk_size
/512;
3063 /* Limit progress to the whole device */
3064 if (max_progress
> info
->component_size
)
3065 max_progress
= info
->component_size
;
3066 wait_point
/= reshape
->after
.data_disks
;
3068 /* switch from 'device offset' to 'processed block count' */
3069 max_progress
= info
->component_size
- max_progress
;
3070 wait_point
= info
->component_size
- wait_point
;
3073 sysfs_set_num(info
, NULL
, "sync_max", max_progress
);
3075 /* Now wait. If we have already reached the point that we were
3076 * asked to wait to, don't wait at all, else wait for any change.
3077 * We need to select on 'sync_completed' as that is the place that
3078 * notifications happen, but we are really interested in
3079 * 'reshape_position'
3081 fd
= sysfs_get_fd(info
, NULL
, "sync_completed");
3083 goto check_progress
;
3085 if (sysfs_fd_get_ll(fd
, &completed
) < 0)
3086 goto check_progress
;
3088 while (completed
< max_progress
&& completed
< wait_point
) {
3089 /* Check that sync_action is still 'reshape' to avoid
3090 * waiting forever on a dead array
3094 if (sysfs_get_str(info
, NULL
, "sync_action",
3096 strncmp(action
, "reshape", 7) != 0)
3098 /* Some kernels reset 'sync_completed' to zero
3099 * before setting 'sync_action' to 'idle'.
3100 * So we need these extra tests.
3102 if (completed
== 0 && advancing
3103 && info
->reshape_progress
> 0)
3105 if (completed
== 0 && !advancing
3106 && info
->reshape_progress
< (info
->component_size
3107 * reshape
->after
.data_disks
))
3111 select(fd
+1, NULL
, NULL
, &rfds
, NULL
);
3112 if (sysfs_fd_get_ll(fd
, &completed
) < 0)
3113 goto check_progress
;
3115 /* Some kernels reset 'sync_completed' to zero,
3116 * we need to have real point we are in md
3119 completed
= max_progress
;
3121 /* some kernels can give an incorrectly high 'completed' number */
3122 completed
/= (info
->new_chunk
/512);
3123 completed
*= (info
->new_chunk
/512);
3124 /* Convert 'completed' back in to a 'progress' number */
3125 completed
*= reshape
->after
.data_disks
;
3127 completed
= info
->component_size
* reshape
->after
.data_disks
3130 *reshape_completed
= completed
;
3134 /* We return the need_backup flag. Caller will decide
3135 * how much - a multiple of ->backup_blocks up to *suspend_point
3138 return need_backup
> info
->reshape_progress
;
3140 return need_backup
>= info
->reshape_progress
;
3143 /* if we couldn't read a number from sync_completed, then
3144 * either the reshape did complete, or it aborted.
3145 * We can tell which by checking for 'none' in reshape_position.
3146 * If it did abort, then it might immediately restart if it
3147 * it was just a device failure that leaves us degraded but
3151 if (sysfs_get_str(info
, NULL
, "reshape_position", buf
, sizeof(buf
)) < 0
3152 || strncmp(buf
, "none", 4) != 0) {
3153 /* The abort might only be temporary. Wait up to 10
3154 * seconds for fd to contain a valid number again.
3160 while (fd
>= 0 && rv
< 0 && tv
.tv_sec
> 0) {
3164 if (select(fd
+1, NULL
, NULL
, &rfds
, &tv
) != 1)
3166 switch (sysfs_fd_get_ll(fd
, &completed
)) {
3168 /* all good again */
3171 case -2: /* read error - abort */
3178 return rv
; /* abort */
3180 /* Maybe racing with array shutdown - check state */
3183 if (sysfs_get_str(info
, NULL
, "array_state", buf
, sizeof(buf
)) < 0
3184 || strncmp(buf
, "inactive", 8) == 0
3185 || strncmp(buf
, "clear",5) == 0)
3186 return -2; /* abort */
3187 return -1; /* complete */
3191 /* FIXME return status is never checked */
3192 static int grow_backup(struct mdinfo
*sra
,
3193 unsigned long long offset
, /* per device */
3194 unsigned long stripes
, /* per device, in old chunks */
3195 int *sources
, unsigned long long *offsets
,
3196 int disks
, int chunk
, int level
, int layout
,
3197 int dests
, int *destfd
, unsigned long long *destoffsets
,
3198 int part
, int *degraded
,
3201 /* Backup 'blocks' sectors at 'offset' on each device of the array,
3202 * to storage 'destfd' (offset 'destoffsets'), after first
3203 * suspending IO. Then allow resync to continue
3204 * over the suspended section.
3205 * Use part 'part' of the backup-super-block.
3210 unsigned long long ll
;
3212 //printf("offset %llu\n", offset);
3218 /* Check that array hasn't become degraded, else we might backup the wrong data */
3219 if (sysfs_get_ll(sra
, NULL
, "degraded", &ll
) < 0)
3220 return -1; /* FIXME this error is ignored */
3221 new_degraded
= (int)ll
;
3222 if (new_degraded
!= *degraded
) {
3223 /* check each device to ensure it is still working */
3225 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
3226 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
3228 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
3230 if (sysfs_get_str(sra
, sd
, "state", sbuf
, 20) < 0 ||
3231 strstr(sbuf
, "faulty") ||
3232 strstr(sbuf
, "in_sync") == NULL
) {
3233 /* this device is dead */
3234 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
3235 if (sd
->disk
.raid_disk
>= 0 &&
3236 sources
[sd
->disk
.raid_disk
] >= 0) {
3237 close(sources
[sd
->disk
.raid_disk
]);
3238 sources
[sd
->disk
.raid_disk
] = -1;
3243 *degraded
= new_degraded
;
3246 bsb
.arraystart2
= __cpu_to_le64(offset
* odata
);
3247 bsb
.length2
= __cpu_to_le64(stripes
* (chunk
/512) * odata
);
3249 bsb
.arraystart
= __cpu_to_le64(offset
* odata
);
3250 bsb
.length
= __cpu_to_le64(stripes
* (chunk
/512) * odata
);
3253 bsb
.magic
[15] = '2';
3254 for (i
= 0; i
< dests
; i
++)
3256 lseek64(destfd
[i
], destoffsets
[i
] + __le64_to_cpu(bsb
.devstart2
)*512, 0);
3258 lseek64(destfd
[i
], destoffsets
[i
], 0);
3260 rv
= save_stripes(sources
, offsets
,
3261 disks
, chunk
, level
, layout
,
3263 offset
*512*odata
, stripes
* chunk
* odata
,
3268 bsb
.mtime
= __cpu_to_le64(time(0));
3269 for (i
= 0; i
< dests
; i
++) {
3270 bsb
.devstart
= __cpu_to_le64(destoffsets
[i
]/512);
3272 bsb
.sb_csum
= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
));
3273 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0)
3274 bsb
.sb_csum2
= bsb_csum((char*)&bsb
,
3275 ((char*)&bsb
.sb_csum2
)-((char*)&bsb
));
3278 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
] - 4096, 0)
3279 != destoffsets
[i
] - 4096)
3281 if (write(destfd
[i
], &bsb
, 512) != 512)
3283 if (destoffsets
[i
] > 4096) {
3284 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
]+stripes
*chunk
*odata
, 0) !=
3285 destoffsets
[i
]+stripes
*chunk
*odata
)
3287 if (write(destfd
[i
], &bsb
, 512) != 512)
3297 /* in 2.6.30, the value reported by sync_completed can be
3298 * less that it should be by one stripe.
3299 * This only happens when reshape hits sync_max and pauses.
3300 * So allow wait_backup to either extent sync_max further
3301 * than strictly necessary, or return before the
3302 * sync has got quite as far as we would really like.
3303 * This is what 'blocks2' is for.
3304 * The various caller give appropriate values so that
3307 /* FIXME return value is often ignored */
3308 static int forget_backup(int dests
, int *destfd
,
3309 unsigned long long *destoffsets
,
3313 * Erase backup 'part' (which is 0 or 1)
3319 bsb
.arraystart2
= __cpu_to_le64(0);
3320 bsb
.length2
= __cpu_to_le64(0);
3322 bsb
.arraystart
= __cpu_to_le64(0);
3323 bsb
.length
= __cpu_to_le64(0);
3325 bsb
.mtime
= __cpu_to_le64(time(0));
3327 for (i
= 0; i
< dests
; i
++) {
3328 bsb
.devstart
= __cpu_to_le64(destoffsets
[i
]/512);
3329 bsb
.sb_csum
= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
));
3330 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0)
3331 bsb
.sb_csum2
= bsb_csum((char*)&bsb
,
3332 ((char*)&bsb
.sb_csum2
)-((char*)&bsb
));
3333 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
]-4096, 0) !=
3334 destoffsets
[i
]-4096)
3337 write(destfd
[i
], &bsb
, 512) != 512)
3344 static void fail(char *msg
)
3347 rv
= (write(2, msg
, strlen(msg
)) != (int)strlen(msg
));
3348 rv
|= (write(2, "\n", 1) != 1);
3352 static char *abuf
, *bbuf
;
3353 static unsigned long long abuflen
;
3354 static void validate(int afd
, int bfd
, unsigned long long offset
)
3356 /* check that the data in the backup against the array.
3357 * This is only used for regression testing and should not
3358 * be used while the array is active
3362 lseek64(bfd
, offset
- 4096, 0);
3363 if (read(bfd
, &bsb2
, 512) != 512)
3364 fail("cannot read bsb");
3365 if (bsb2
.sb_csum
!= bsb_csum((char*)&bsb2
,
3366 ((char*)&bsb2
.sb_csum
)-((char*)&bsb2
)))
3367 fail("first csum bad");
3368 if (memcmp(bsb2
.magic
, "md_backup_data", 14) != 0)
3369 fail("magic is bad");
3370 if (memcmp(bsb2
.magic
, "md_backup_data-2", 16) == 0 &&
3371 bsb2
.sb_csum2
!= bsb_csum((char*)&bsb2
,
3372 ((char*)&bsb2
.sb_csum2
)-((char*)&bsb2
)))
3373 fail("second csum bad");
3375 if (__le64_to_cpu(bsb2
.devstart
)*512 != offset
)
3376 fail("devstart is wrong");
3379 unsigned long long len
= __le64_to_cpu(bsb2
.length
)*512;
3381 if (abuflen
< len
) {
3385 if (posix_memalign((void**)&abuf
, 4096, abuflen
) ||
3386 posix_memalign((void**)&bbuf
, 4096, abuflen
)) {
3388 /* just stop validating on mem-alloc failure */
3393 lseek64(bfd
, offset
, 0);
3394 if ((unsigned long long)read(bfd
, bbuf
, len
) != len
) {
3395 //printf("len %llu\n", len);
3396 fail("read first backup failed");
3398 lseek64(afd
, __le64_to_cpu(bsb2
.arraystart
)*512, 0);
3399 if ((unsigned long long)read(afd
, abuf
, len
) != len
)
3400 fail("read first from array failed");
3401 if (memcmp(bbuf
, abuf
, len
) != 0) {
3404 printf("offset=%llu len=%llu\n",
3405 (unsigned long long)__le64_to_cpu(bsb2
.arraystart
)*512, len
);
3406 for (i
=0; i
<len
; i
++)
3407 if (bbuf
[i
] != abuf
[i
]) {
3408 printf("first diff byte %d\n", i
);
3412 fail("data1 compare failed");
3416 unsigned long long len
= __le64_to_cpu(bsb2
.length2
)*512;
3418 if (abuflen
< len
) {
3422 abuf
= xmalloc(abuflen
);
3423 bbuf
= xmalloc(abuflen
);
3426 lseek64(bfd
, offset
+__le64_to_cpu(bsb2
.devstart2
)*512, 0);
3427 if ((unsigned long long)read(bfd
, bbuf
, len
) != len
)
3428 fail("read second backup failed");
3429 lseek64(afd
, __le64_to_cpu(bsb2
.arraystart2
)*512, 0);
3430 if ((unsigned long long)read(afd
, abuf
, len
) != len
)
3431 fail("read second from array failed");
3432 if (memcmp(bbuf
, abuf
, len
) != 0)
3433 fail("data2 compare failed");
3437 int child_monitor(int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
3438 struct supertype
*st
, unsigned long blocks
,
3439 int *fds
, unsigned long long *offsets
,
3440 int dests
, int *destfd
, unsigned long long *destoffsets
)
3442 /* Monitor a reshape where backup is being performed using
3443 * 'native' mechanism - either to a backup file, or
3444 * to some space in a spare.
3448 unsigned long long speed
;
3449 unsigned long long suspend_point
, array_size
;
3450 unsigned long long backup_point
, wait_point
;
3451 unsigned long long reshape_completed
;
3453 int increasing
= reshape
->after
.data_disks
>= reshape
->before
.data_disks
;
3454 int part
= 0; /* The next part of the backup area to fill. It may already
3455 * be full, so we need to check */
3456 int level
= reshape
->level
;
3457 int layout
= reshape
->before
.layout
;
3458 int data
= reshape
->before
.data_disks
;
3459 int disks
= reshape
->before
.data_disks
+ reshape
->parity
;
3460 int chunk
= sra
->array
.chunk_size
;
3462 unsigned long stripes
;
3465 /* set up the backup-super-block. This requires the
3466 * uuid from the array.
3468 /* Find a superblock */
3469 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
3473 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
3475 dn
= map_dev(sd
->disk
.major
, sd
->disk
.minor
, 1);
3476 devfd
= dev_open(dn
, O_RDONLY
);
3479 ok
= st
->ss
->load_super(st
, devfd
, NULL
);
3485 pr_err("Cannot find a superblock\n");
3489 memset(&bsb
, 0, 512);
3490 memcpy(bsb
.magic
, "md_backup_data-1", 16);
3491 st
->ss
->uuid_from_super(st
, uuid
);
3492 memcpy(bsb
.set_uuid
, uuid
, 16);
3493 bsb
.mtime
= __cpu_to_le64(time(0));
3494 bsb
.devstart2
= blocks
;
3496 stripes
= blocks
/ (sra
->array
.chunk_size
/512) /
3497 reshape
->before
.data_disks
;
3499 if (posix_memalign((void**)&buf
, 4096, disks
* chunk
))
3500 /* Don't start the 'reshape' */
3502 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
) {
3503 sysfs_get_ll(sra
, NULL
, "sync_speed_min", &speed
);
3504 sysfs_set_num(sra
, NULL
, "sync_speed_min", 200000);
3508 array_size
= sra
->component_size
* reshape
->after
.data_disks
;
3509 backup_point
= sra
->reshape_progress
;
3512 array_size
= sra
->component_size
* reshape
->before
.data_disks
;
3513 backup_point
= reshape
->backup_blocks
;
3514 suspend_point
= array_size
;
3520 /* Want to return as soon the oldest backup slot can
3521 * be released as that allows us to start backing up
3522 * some more, providing suspend_point has been
3523 * advanced, which it should have.
3526 wait_point
= array_size
;
3527 if (part
== 0 && __le64_to_cpu(bsb
.length
) > 0)
3528 wait_point
= (__le64_to_cpu(bsb
.arraystart
) +
3529 __le64_to_cpu(bsb
.length
));
3530 if (part
== 1 && __le64_to_cpu(bsb
.length2
) > 0)
3531 wait_point
= (__le64_to_cpu(bsb
.arraystart2
) +
3532 __le64_to_cpu(bsb
.length2
));
3535 if (part
== 0 && __le64_to_cpu(bsb
.length
) > 0)
3536 wait_point
= __le64_to_cpu(bsb
.arraystart
);
3537 if (part
== 1 && __le64_to_cpu(bsb
.length2
) > 0)
3538 wait_point
= __le64_to_cpu(bsb
.arraystart2
);
3541 rv
= progress_reshape(sra
, reshape
,
3542 backup_point
, wait_point
,
3543 &suspend_point
, &reshape_completed
);
3544 /* external metadata would need to ping_monitor here */
3545 sra
->reshape_progress
= reshape_completed
;
3547 /* Clear any backup region that is before 'here' */
3549 if (__le64_to_cpu(bsb
.length
) > 0 &&
3550 reshape_completed
>= (__le64_to_cpu(bsb
.arraystart
) +
3551 __le64_to_cpu(bsb
.length
)))
3552 forget_backup(dests
, destfd
,
3554 if (__le64_to_cpu(bsb
.length2
) > 0 &&
3555 reshape_completed
>= (__le64_to_cpu(bsb
.arraystart2
) +
3556 __le64_to_cpu(bsb
.length2
)))
3557 forget_backup(dests
, destfd
,
3560 if (__le64_to_cpu(bsb
.length
) > 0 &&
3561 reshape_completed
<= (__le64_to_cpu(bsb
.arraystart
)))
3562 forget_backup(dests
, destfd
,
3564 if (__le64_to_cpu(bsb
.length2
) > 0 &&
3565 reshape_completed
<= (__le64_to_cpu(bsb
.arraystart2
)))
3566 forget_backup(dests
, destfd
,
3575 if (rv
== 0 && increasing
&& !st
->ss
->external
) {
3576 /* No longer need to monitor this reshape */
3582 unsigned long long offset
;
3583 unsigned long actual_stripes
;
3584 /* Need to backup some data.
3585 * If 'part' is not used and the desired
3586 * backup size is suspended, do a backup,
3587 * then consider the next part.
3589 /* Check that 'part' is unused */
3590 if (part
== 0 && __le64_to_cpu(bsb
.length
) != 0)
3592 if (part
== 1 && __le64_to_cpu(bsb
.length2
) != 0)
3595 offset
= backup_point
/ data
;
3596 actual_stripes
= stripes
;
3598 if (offset
+ actual_stripes
* (chunk
/512) >
3599 sra
->component_size
)
3600 actual_stripes
= ((sra
->component_size
- offset
)
3602 if (offset
+ actual_stripes
* (chunk
/512) >
3606 if (offset
< actual_stripes
* (chunk
/512))
3607 actual_stripes
= offset
/ (chunk
/512);
3608 offset
-= actual_stripes
* (chunk
/512);
3609 if (offset
< suspend_point
/data
)
3612 if (actual_stripes
== 0)
3614 grow_backup(sra
, offset
, actual_stripes
,
3616 disks
, chunk
, level
, layout
,
3617 dests
, destfd
, destoffsets
,
3618 part
, °raded
, buf
);
3619 validate(afd
, destfd
[0], destoffsets
[0]);
3620 /* record where 'part' is up to */
3623 backup_point
+= actual_stripes
* (chunk
/512) * data
;
3625 backup_point
-= actual_stripes
* (chunk
/512) * data
;
3629 /* FIXME maybe call progress_reshape one more time instead */
3630 abort_reshape(sra
); /* remove any remaining suspension */
3631 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
)
3632 sysfs_set_num(sra
, NULL
, "sync_speed_min", speed
);
3638 * If any spare contains md_back_data-1 which is recent wrt mtime,
3639 * write that data into the array and update the super blocks with
3640 * the new reshape_progress
3642 int Grow_restart(struct supertype
*st
, struct mdinfo
*info
, int *fdlist
, int cnt
,
3643 char *backup_file
, int verbose
)
3647 unsigned long long *offsets
;
3648 unsigned long long nstripe
, ostripe
;
3651 odata
= info
->array
.raid_disks
- info
->delta_disks
- 1;
3652 if (info
->array
.level
== 6) odata
--; /* number of data disks */
3653 ndata
= info
->array
.raid_disks
- 1;
3654 if (info
->new_level
== 6) ndata
--;
3656 old_disks
= info
->array
.raid_disks
- info
->delta_disks
;
3658 if (info
->delta_disks
<= 0)
3659 /* Didn't grow, so the backup file must have
3663 for (i
=old_disks
-(backup_file
?1:0); i
<cnt
; i
++) {
3664 struct mdinfo dinfo
;
3667 char *devname
, namebuf
[20];
3668 unsigned long long lo
, hi
;
3670 /* This was a spare and may have some saved data on it.
3671 * Load the superblock, find and load the
3672 * backup_super_block.
3673 * If either fail, go on to next device.
3674 * If the backup contains no new info, just return
3675 * else restore data and update all superblocks
3677 if (i
== old_disks
-1) {
3678 fd
= open(backup_file
, O_RDONLY
);
3680 pr_err("backup file %s inaccessible: %s\n",
3681 backup_file
, strerror(errno
));
3684 devname
= backup_file
;
3689 if (st
->ss
->load_super(st
, fd
, NULL
))
3692 st
->ss
->getinfo_super(st
, &dinfo
, NULL
);
3693 st
->ss
->free_super(st
);
3696 (dinfo
.data_offset
+ dinfo
.component_size
- 8) <<9,
3698 pr_err("Cannot seek on device %d\n", i
);
3699 continue; /* Cannot seek */
3701 sprintf(namebuf
, "device-%d", i
);
3704 if (read(fd
, &bsb
, sizeof(bsb
)) != sizeof(bsb
)) {
3706 pr_err("Cannot read from %s\n", devname
);
3707 continue; /* Cannot read */
3709 if (memcmp(bsb
.magic
, "md_backup_data-1", 16) != 0 &&
3710 memcmp(bsb
.magic
, "md_backup_data-2", 16) != 0) {
3712 pr_err("No backup metadata on %s\n", devname
);
3715 if (bsb
.sb_csum
!= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
))) {
3717 pr_err("Bad backup-metadata checksum on %s\n", devname
);
3718 continue; /* bad checksum */
3720 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0 &&
3721 bsb
.sb_csum2
!= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum2
)-((char*)&bsb
))) {
3723 pr_err("Bad backup-metadata checksum2 on %s\n", devname
);
3724 continue; /* Bad second checksum */
3726 if (memcmp(bsb
.set_uuid
,info
->uuid
, 16) != 0) {
3728 pr_err("Wrong uuid on backup-metadata on %s\n", devname
);
3729 continue; /* Wrong uuid */
3732 /* array utime and backup-mtime should be updated at much the same time, but it seems that
3733 * sometimes they aren't... So allow considerable flexability in matching, and allow
3734 * this test to be overridden by an environment variable.
3736 if (info
->array
.utime
> (int)__le64_to_cpu(bsb
.mtime
) + 2*60*60 ||
3737 info
->array
.utime
< (int)__le64_to_cpu(bsb
.mtime
) - 10*60) {
3738 if (check_env("MDADM_GROW_ALLOW_OLD")) {
3739 pr_err("accepting backup with timestamp %lu "
3740 "for array with timestamp %lu\n",
3741 (unsigned long)__le64_to_cpu(bsb
.mtime
),
3742 (unsigned long)info
->array
.utime
);
3745 pr_err("too-old timestamp on "
3746 "backup-metadata on %s\n", devname
);
3747 continue; /* time stamp is too bad */
3751 if (bsb
.magic
[15] == '1') {
3752 if (bsb
.length
== 0)
3754 if (info
->delta_disks
>= 0) {
3755 /* reshape_progress is increasing */
3756 if (__le64_to_cpu(bsb
.arraystart
)
3757 + __le64_to_cpu(bsb
.length
)
3758 < info
->reshape_progress
) {
3761 pr_err("backup-metadata found on %s but is not needed\n", devname
);
3762 continue; /* No new data here */
3765 /* reshape_progress is decreasing */
3766 if (__le64_to_cpu(bsb
.arraystart
) >=
3767 info
->reshape_progress
)
3768 goto nonew
; /* No new data here */
3771 if (bsb
.length
== 0 && bsb
.length2
== 0)
3773 if (info
->delta_disks
>= 0) {
3774 /* reshape_progress is increasing */
3775 if ((__le64_to_cpu(bsb
.arraystart
)
3776 + __le64_to_cpu(bsb
.length
)
3777 < info
->reshape_progress
)
3779 (__le64_to_cpu(bsb
.arraystart2
)
3780 + __le64_to_cpu(bsb
.length2
)
3781 < info
->reshape_progress
))
3782 goto nonew
; /* No new data here */
3784 /* reshape_progress is decreasing */
3785 if (__le64_to_cpu(bsb
.arraystart
) >=
3786 info
->reshape_progress
&&
3787 __le64_to_cpu(bsb
.arraystart2
) >=
3788 info
->reshape_progress
)
3789 goto nonew
; /* No new data here */
3792 if (lseek64(fd
, __le64_to_cpu(bsb
.devstart
)*512, 0)< 0) {
3795 pr_err("Failed to verify secondary backup-metadata block on %s\n",
3797 continue; /* Cannot seek */
3799 /* There should be a duplicate backup superblock 4k before here */
3800 if (lseek64(fd
, -4096, 1) < 0 ||
3801 read(fd
, &bsb2
, sizeof(bsb2
)) != sizeof(bsb2
))
3802 goto second_fail
; /* Cannot find leading superblock */
3803 if (bsb
.magic
[15] == '1')
3804 bsbsize
= offsetof(struct mdp_backup_super
, pad1
);
3806 bsbsize
= offsetof(struct mdp_backup_super
, pad
);
3807 if (memcmp(&bsb2
, &bsb
, bsbsize
) != 0)
3808 goto second_fail
; /* Cannot find leading superblock */
3810 /* Now need the data offsets for all devices. */
3811 offsets
= xmalloc(sizeof(*offsets
)*info
->array
.raid_disks
);
3812 for(j
=0; j
<info
->array
.raid_disks
; j
++) {
3815 if (st
->ss
->load_super(st
, fdlist
[j
], NULL
))
3816 /* FIXME should be this be an error */
3818 st
->ss
->getinfo_super(st
, &dinfo
, NULL
);
3819 st
->ss
->free_super(st
);
3820 offsets
[j
] = dinfo
.data_offset
* 512;
3822 printf(Name
": restoring critical section\n");
3824 if (restore_stripes(fdlist
, offsets
,
3825 info
->array
.raid_disks
,
3829 fd
, __le64_to_cpu(bsb
.devstart
)*512,
3830 __le64_to_cpu(bsb
.arraystart
)*512,
3831 __le64_to_cpu(bsb
.length
)*512, NULL
)) {
3832 /* didn't succeed, so giveup */
3834 pr_err("Error restoring backup from %s\n",
3840 if (bsb
.magic
[15] == '2' &&
3841 restore_stripes(fdlist
, offsets
,
3842 info
->array
.raid_disks
,
3846 fd
, __le64_to_cpu(bsb
.devstart
)*512 +
3847 __le64_to_cpu(bsb
.devstart2
)*512,
3848 __le64_to_cpu(bsb
.arraystart2
)*512,
3849 __le64_to_cpu(bsb
.length2
)*512, NULL
)) {
3850 /* didn't succeed, so giveup */
3852 pr_err("Error restoring second backup from %s\n",
3860 /* Ok, so the data is restored. Let's update those superblocks. */
3864 lo
= __le64_to_cpu(bsb
.arraystart
);
3865 hi
= lo
+ __le64_to_cpu(bsb
.length
);
3867 if (bsb
.magic
[15] == '2' && bsb
.length2
) {
3868 unsigned long long lo1
, hi1
;
3869 lo1
= __le64_to_cpu(bsb
.arraystart2
);
3870 hi1
= lo1
+ __le64_to_cpu(bsb
.length2
);
3874 } else if (lo
< lo1
)
3880 (info
->reshape_progress
< lo
||
3881 info
->reshape_progress
> hi
))
3882 /* backup does not affect reshape_progress*/ ;
3883 else if (info
->delta_disks
>= 0) {
3884 info
->reshape_progress
= __le64_to_cpu(bsb
.arraystart
) +
3885 __le64_to_cpu(bsb
.length
);
3886 if (bsb
.magic
[15] == '2') {
3887 unsigned long long p2
= __le64_to_cpu(bsb
.arraystart2
) +
3888 __le64_to_cpu(bsb
.length2
);
3889 if (p2
> info
->reshape_progress
)
3890 info
->reshape_progress
= p2
;
3893 info
->reshape_progress
= __le64_to_cpu(bsb
.arraystart
);
3894 if (bsb
.magic
[15] == '2') {
3895 unsigned long long p2
= __le64_to_cpu(bsb
.arraystart2
);
3896 if (p2
< info
->reshape_progress
)
3897 info
->reshape_progress
= p2
;
3900 for (j
=0; j
<info
->array
.raid_disks
; j
++) {
3903 if (st
->ss
->load_super(st
, fdlist
[j
], NULL
))
3905 st
->ss
->getinfo_super(st
, &dinfo
, NULL
);
3906 dinfo
.reshape_progress
= info
->reshape_progress
;
3907 st
->ss
->update_super(st
, &dinfo
,
3908 "_reshape_progress",
3910 st
->ss
->store_super(st
, fdlist
[j
]);
3911 st
->ss
->free_super(st
);
3915 /* Didn't find any backup data, try to see if any
3918 if (info
->delta_disks
< 0) {
3919 /* When shrinking, the critical section is at the end.
3920 * So see if we are before the critical section.
3922 unsigned long long first_block
;
3923 nstripe
= ostripe
= 0;
3925 while (ostripe
>= nstripe
) {
3926 ostripe
+= info
->array
.chunk_size
/ 512;
3927 first_block
= ostripe
* odata
;
3928 nstripe
= first_block
/ ndata
/ (info
->new_chunk
/512) *
3929 (info
->new_chunk
/512);
3932 if (info
->reshape_progress
>= first_block
)
3935 if (info
->delta_disks
> 0) {
3936 /* See if we are beyond the critical section. */
3937 unsigned long long last_block
;
3938 nstripe
= ostripe
= 0;
3940 while (nstripe
>= ostripe
) {
3941 nstripe
+= info
->new_chunk
/ 512;
3942 last_block
= nstripe
* ndata
;
3943 ostripe
= last_block
/ odata
/ (info
->array
.chunk_size
/512) *
3944 (info
->array
.chunk_size
/512);
3947 if (info
->reshape_progress
>= last_block
)
3950 /* needed to recover critical section! */
3952 pr_err("Failed to find backup of critical section\n");
3956 int Grow_continue_command(char *devname
, int fd
,
3957 char *backup_file
, int verbose
)
3960 struct supertype
*st
= NULL
;
3961 struct mdinfo
*content
= NULL
;
3962 struct mdinfo array
;
3963 char *subarray
= NULL
;
3964 struct mdinfo
*cc
= NULL
;
3965 struct mdstat_ent
*mdstat
= NULL
;
3970 dprintf("Grow continue from command line called for %s\n",
3973 st
= super_by_fd(fd
, &subarray
);
3974 if (!st
|| !st
->ss
) {
3975 pr_err("Unable to determine metadata format for %s\n",
3979 dprintf("Grow continue is run for ");
3980 if (st
->ss
->external
== 0) {
3981 dprintf("native array (%s)\n", devname
);
3982 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) < 0) {
3983 pr_err("%s is not an active md array -"
3984 " aborting\n", devname
);
3986 goto Grow_continue_command_exit
;
3989 sysfs_init(content
, fd
, st
->devnum
);
3994 dprintf("subarray (%s)\n", subarray
);
3995 container_dev
= st
->container_dev
;
3996 cfd
= open_dev_excl(st
->container_dev
);
3998 container_dev
= st
->devnum
;
4000 cfd
= open_dev_excl(st
->devnum
);
4001 dprintf("container (%i)\n", container_dev
);
4005 pr_err("Unable to open container "
4006 "for %s\n", devname
);
4008 goto Grow_continue_command_exit
;
4010 fmt_devname(buf
, container_dev
);
4012 /* find in container array under reshape
4014 ret_val
= st
->ss
->load_container(st
, cfd
, NULL
);
4016 pr_err("Cannot read superblock for %s\n",
4019 goto Grow_continue_command_exit
;
4022 cc
= st
->ss
->container_content(st
, subarray
);
4023 for (content
= cc
; content
; content
= content
->next
) {
4025 int allow_reshape
= 1;
4027 if (content
->reshape_active
== 0)
4029 /* The decision about array or container wide
4030 * reshape is taken in Grow_continue based
4031 * content->reshape_active state, therefore we
4032 * need to check_reshape based on
4033 * reshape_active and subarray name
4035 if (content
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
))
4037 if (content
->reshape_active
== CONTAINER_RESHAPE
&&
4038 (content
->array
.state
4039 & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
)))
4042 if (!allow_reshape
) {
4043 pr_err("cannot continue reshape of an array"
4044 " in container with unsupported"
4045 " metadata: %s(%s)\n",
4048 goto Grow_continue_command_exit
;
4051 array
= strchr(content
->text_version
+1, '/')+1;
4052 mdstat
= mdstat_by_subdev(array
, container_dev
);
4055 if (mdstat
->active
== 0) {
4056 pr_err("Skipping inactive "
4057 "array md%i.\n", mdstat
->devnum
);
4058 free_mdstat(mdstat
);
4065 pr_err("Unable to determine reshaped "
4066 "array for %s\n", devname
);
4068 goto Grow_continue_command_exit
;
4070 fd2
= open_dev(mdstat
->devnum
);
4072 pr_err("cannot open (md%i)\n",
4075 goto Grow_continue_command_exit
;
4078 sysfs_init(content
, fd2
, mdstat
->devnum
);
4080 /* start mdmon in case it is not running
4082 if (!mdmon_running(container_dev
))
4083 start_mdmon(container_dev
);
4086 if (mdmon_running(container_dev
))
4087 st
->update_tail
= &st
->updates
;
4089 pr_err("No mdmon found. "
4090 "Grow cannot continue.\n");
4092 goto Grow_continue_command_exit
;
4096 /* verify that array under reshape is started from
4099 if (verify_reshape_position(content
,
4100 map_name(pers
, mdstat
->level
)) < 0) {
4102 goto Grow_continue_command_exit
;
4107 ret_val
= Grow_continue(fd
, st
, content
, backup_file
, 0);
4109 Grow_continue_command_exit
:
4114 st
->ss
->free_super(st
);
4115 free_mdstat(mdstat
);
4122 int Grow_continue(int mdfd
, struct supertype
*st
, struct mdinfo
*info
,
4123 char *backup_file
, int freeze_reshape
)
4127 if (!info
->reshape_active
)
4130 if (st
->ss
->external
) {
4132 int cfd
= open_dev(st
->container_dev
);
4137 fmt_devname(container
, st
->container_dev
);
4138 st
->ss
->load_container(st
, cfd
, container
);
4140 ret_val
= reshape_container(container
, NULL
, mdfd
,
4141 st
, info
, 0, backup_file
,
4142 0, 1, freeze_reshape
);
4144 ret_val
= reshape_array(NULL
, mdfd
, "array", st
, info
, 1,
4145 NULL
, backup_file
, 0, 0, 1,