2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Email: <neilb@suse.de>
28 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
29 #error no endian defined
35 #define offsetof(t,f) ((size_t)&(((t*)0)->f))
38 int restore_backup(struct supertype
*st
,
39 struct mdinfo
*content
,
49 int disk_count
= next_spare
+ working_disks
;
51 dprintf("Called restore_backup()\n");
52 fdlist
= malloc(sizeof(int) * disk_count
);
55 Name
": cannot allocate memory for disk list\n");
58 for (i
= 0; i
< next_spare
; i
++)
60 for (dev
= content
->devs
; dev
; dev
= dev
->next
) {
66 fd
= dev_open(buf
, O_RDWR
);
68 if (dev
->disk
.raid_disk
>= 0)
69 fdlist
[dev
->disk
.raid_disk
] = fd
;
71 fdlist
[next_spare
++] = fd
;
74 if (st
->ss
->external
&& st
->ss
->recover_backup
)
75 err
= st
->ss
->recover_backup(st
, content
);
77 err
= Grow_restart(st
, content
, fdlist
, next_spare
,
78 backup_file
, verbose
> 0);
80 while (next_spare
> 0) {
82 if (fdlist
[next_spare
] >= 0)
83 close(fdlist
[next_spare
]);
87 fprintf(stderr
, Name
": Failed to restore critical"
88 " section for reshape - sorry.\n");
90 fprintf(stderr
, Name
": Possibly you need"
91 " to specify a --backup-file\n");
95 dprintf("restore_backup() returns status OK.\n");
99 int Grow_Add_device(char *devname
, int fd
, char *newdev
)
101 /* Add a device to an active array.
102 * Currently, just extend a linear array.
103 * This requires writing a new superblock on the
104 * new device, calling the kernel to add the device,
105 * and if that succeeds, update the superblock on
107 * This means that we need to *find* all other devices.
114 struct supertype
*st
= NULL
;
115 char *subarray
= NULL
;
117 if (ioctl(fd
, GET_ARRAY_INFO
, &info
.array
) < 0) {
118 fprintf(stderr
, Name
": cannot get array info for %s\n", devname
);
122 if (info
.array
.level
!= -1) {
123 fprintf(stderr
, Name
": can only add devices to linear arrays\n");
127 st
= super_by_fd(fd
, &subarray
);
129 fprintf(stderr
, Name
": cannot handle arrays with superblock version %d\n", info
.array
.major_version
);
134 fprintf(stderr
, Name
": Cannot grow linear sub-arrays yet\n");
140 nfd
= open(newdev
, O_RDWR
|O_EXCL
|O_DIRECT
);
142 fprintf(stderr
, Name
": cannot open %s\n", newdev
);
147 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
148 fprintf(stderr
, Name
": %s is not a block device!\n", newdev
);
153 /* now check out all the devices and make sure we can read the superblock */
154 for (d
=0 ; d
< info
.array
.raid_disks
; d
++) {
155 mdu_disk_info_t disk
;
158 st
->ss
->free_super(st
);
161 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
162 fprintf(stderr
, Name
": cannot get device detail for device %d\n",
168 dv
= map_dev(disk
.major
, disk
.minor
, 1);
170 fprintf(stderr
, Name
": cannot find device file for device %d\n",
176 fd2
= dev_open(dv
, O_RDWR
);
178 fprintf(stderr
, Name
": cannot open device file %s\n", dv
);
184 if (st
->ss
->load_super(st
, fd2
, NULL
)) {
185 fprintf(stderr
, Name
": cannot find super block on %s\n", dv
);
193 /* Ok, looks good. Lets update the superblock and write it out to
197 info
.disk
.number
= d
;
198 info
.disk
.major
= major(stb
.st_rdev
);
199 info
.disk
.minor
= minor(stb
.st_rdev
);
200 info
.disk
.raid_disk
= d
;
201 info
.disk
.state
= (1 << MD_DISK_SYNC
) | (1 << MD_DISK_ACTIVE
);
202 st
->ss
->update_super(st
, &info
, "linear-grow-new", newdev
,
205 if (st
->ss
->store_super(st
, nfd
)) {
206 fprintf(stderr
, Name
": Cannot store new superblock on %s\n",
213 if (ioctl(fd
, ADD_NEW_DISK
, &info
.disk
) != 0) {
214 fprintf(stderr
, Name
": Cannot add new disk to this array\n");
217 /* Well, that seems to have worked.
218 * Now go through and update all superblocks
221 if (ioctl(fd
, GET_ARRAY_INFO
, &info
.array
) < 0) {
222 fprintf(stderr
, Name
": cannot get array info for %s\n", devname
);
227 for (d
=0 ; d
< info
.array
.raid_disks
; d
++) {
228 mdu_disk_info_t disk
;
232 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0) {
233 fprintf(stderr
, Name
": cannot get device detail for device %d\n",
237 dv
= map_dev(disk
.major
, disk
.minor
, 1);
239 fprintf(stderr
, Name
": cannot find device file for device %d\n",
243 fd2
= dev_open(dv
, O_RDWR
);
245 fprintf(stderr
, Name
": cannot open device file %s\n", dv
);
248 if (st
->ss
->load_super(st
, fd2
, NULL
)) {
249 fprintf(stderr
, Name
": cannot find super block on %s\n", dv
);
253 info
.array
.raid_disks
= nd
+1;
254 info
.array
.nr_disks
= nd
+1;
255 info
.array
.active_disks
= nd
+1;
256 info
.array
.working_disks
= nd
+1;
258 st
->ss
->update_super(st
, &info
, "linear-grow-update", dv
,
261 if (st
->ss
->store_super(st
, fd2
)) {
262 fprintf(stderr
, Name
": Cannot store new superblock on %s\n", dv
);
272 int Grow_addbitmap(char *devname
, int fd
, char *file
, int chunk
, int delay
, int write_behind
, int force
)
275 * First check that array doesn't have a bitmap
276 * Then create the bitmap
279 * For internal bitmaps, we need to check the version,
280 * find all the active devices, and write the bitmap block
283 mdu_bitmap_file_t bmf
;
284 mdu_array_info_t array
;
285 struct supertype
*st
;
286 char *subarray
= NULL
;
287 int major
= BITMAP_MAJOR_HI
;
288 int vers
= md_get_version(fd
);
289 unsigned long long bitmapsize
, array_size
;
292 major
= BITMAP_MAJOR_HOSTENDIAN
;
293 fprintf(stderr
, Name
": Warning - bitmaps created on this kernel"
294 " are not portable\n"
295 " between different architectures. Consider upgrading"
296 " the Linux kernel.\n");
299 if (ioctl(fd
, GET_BITMAP_FILE
, &bmf
) != 0) {
301 fprintf(stderr
, Name
": Memory allocation failure.\n");
303 fprintf(stderr
, Name
": bitmaps not supported by this kernel.\n");
306 if (bmf
.pathname
[0]) {
307 if (strcmp(file
,"none")==0) {
308 if (ioctl(fd
, SET_BITMAP_FILE
, -1)!= 0) {
309 fprintf(stderr
, Name
": failed to remove bitmap %s\n",
315 fprintf(stderr
, Name
": %s already has a bitmap (%s)\n",
316 devname
, bmf
.pathname
);
319 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
320 fprintf(stderr
, Name
": cannot get array status for %s\n", devname
);
323 if (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)) {
324 if (strcmp(file
, "none")==0) {
325 array
.state
&= ~(1<<MD_SB_BITMAP_PRESENT
);
326 if (ioctl(fd
, SET_ARRAY_INFO
, &array
)!= 0) {
327 fprintf(stderr
, Name
": failed to remove internal bitmap.\n");
332 fprintf(stderr
, Name
": Internal bitmap already present on %s\n",
337 if (strcmp(file
, "none") == 0) {
338 fprintf(stderr
, Name
": no bitmap found on %s\n", devname
);
341 if (array
.level
<= 0) {
342 fprintf(stderr
, Name
": Bitmaps not meaningful with level %s\n",
343 map_num(pers
, array
.level
)?:"of this array");
346 bitmapsize
= array
.size
;
348 if (get_dev_size(fd
, NULL
, &array_size
) &&
349 array_size
> (0x7fffffffULL
<<9)) {
350 /* Array is big enough that we cannot trust array.size
351 * try other approaches
353 bitmapsize
= get_component_size(fd
);
355 if (bitmapsize
== 0) {
356 fprintf(stderr
, Name
": Cannot reliably determine size of array to create bitmap - sorry.\n");
360 if (array
.level
== 10) {
361 int ncopies
= (array
.layout
&255)*((array
.layout
>>8)&255);
362 bitmapsize
= bitmapsize
* array
.raid_disks
/ ncopies
;
365 st
= super_by_fd(fd
, &subarray
);
367 fprintf(stderr
, Name
": Cannot understand version %d.%d\n",
368 array
.major_version
, array
.minor_version
);
372 fprintf(stderr
, Name
": Cannot add bitmaps to sub-arrays yet\n");
377 if (strcmp(file
, "internal") == 0) {
380 int offset_setable
= 0;
382 if (st
->ss
->add_internal_bitmap
== NULL
) {
383 fprintf(stderr
, Name
": Internal bitmaps not supported "
384 "with %s metadata\n", st
->ss
->name
);
387 mdi
= sysfs_read(fd
, -1, GET_BITMAP_LOCATION
);
390 for (d
=0; d
< st
->max_devs
; d
++) {
391 mdu_disk_info_t disk
;
394 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
396 if (disk
.major
== 0 &&
399 if ((disk
.state
& (1<<MD_DISK_SYNC
))==0)
401 dv
= map_dev(disk
.major
, disk
.minor
, 1);
403 int fd2
= dev_open(dv
, O_RDWR
);
406 if (st
->ss
->load_super(st
, fd2
, NULL
)==0) {
407 if (st
->ss
->add_internal_bitmap(
409 &chunk
, delay
, write_behind
,
410 bitmapsize
, offset_setable
,
413 st
->ss
->write_bitmap(st
, fd2
);
415 fprintf(stderr
, Name
": failed "
416 "to create internal bitmap - chunksize problem.\n");
424 if (offset_setable
) {
425 st
->ss
->getinfo_super(st
, mdi
, NULL
);
426 sysfs_init(mdi
, fd
, -1);
427 rv
= sysfs_set_num_signed(mdi
, NULL
, "bitmap/location",
430 array
.state
|= (1<<MD_SB_BITMAP_PRESENT
);
431 rv
= ioctl(fd
, SET_ARRAY_INFO
, &array
);
436 ": Cannot add bitmap while array is"
437 " resyncing or reshaping etc.\n");
438 fprintf(stderr
, Name
": failed to set internal bitmap.\n");
445 int max_devs
= st
->max_devs
;
447 /* try to load a superblock */
448 for (d
=0; d
<max_devs
; d
++) {
449 mdu_disk_info_t disk
;
453 if (ioctl(fd
, GET_DISK_INFO
, &disk
) < 0)
455 if ((disk
.major
==0 && disk
.minor
==0) ||
456 (disk
.state
& (1<<MD_DISK_REMOVED
)))
458 dv
= map_dev(disk
.major
, disk
.minor
, 1);
460 fd2
= dev_open(dv
, O_RDONLY
);
462 if (st
->ss
->load_super(st
, fd2
, NULL
) == 0) {
464 st
->ss
->uuid_from_super(st
, uuid
);
471 fprintf(stderr
, Name
": cannot find UUID for array!\n");
474 if (CreateBitmap(file
, force
, (char*)uuid
, chunk
,
475 delay
, write_behind
, bitmapsize
, major
)) {
478 bitmap_fd
= open(file
, O_RDWR
);
480 fprintf(stderr
, Name
": weird: %s cannot be opened\n",
484 if (ioctl(fd
, SET_BITMAP_FILE
, bitmap_fd
) < 0) {
488 ": Cannot add bitmap while array is"
489 " resyncing or reshaping etc.\n");
490 fprintf(stderr
, Name
": Cannot set bitmap file for %s: %s\n",
491 devname
, strerror(err
));
500 * When reshaping an array we might need to backup some data.
501 * This is written to all spares with a 'super_block' describing it.
502 * The superblock goes 4K from the end of the used space on the
504 * It if written after the backup is complete.
505 * It has the following structure.
508 static struct mdp_backup_super
{
509 char magic
[16]; /* md_backup_data-1 or -2 */
512 /* start/sizes in 512byte sectors */
513 __u64 devstart
; /* address on backup device/file of data */
516 __u32 sb_csum
; /* csum of preceeding bytes. */
518 __u64 devstart2
; /* offset in to data of second section */
521 __u32 sb_csum2
; /* csum of preceeding bytes. */
523 } __attribute__((aligned(512))) bsb
, bsb2
;
525 static __u32
bsb_csum(char *buf
, int len
)
529 for (i
=0; i
<len
; i
++)
530 csum
= (csum
<<3) + buf
[0];
531 return __cpu_to_le32(csum
);
534 static int check_idle(struct supertype
*st
)
536 /* Check that all member arrays for this container, or the
537 * container of this array, are idle
539 int container_dev
= (st
->container_dev
!= NoMdDev
540 ? st
->container_dev
: st
->devnum
);
542 struct mdstat_ent
*ent
, *e
;
545 fmt_devname(container
, container_dev
);
546 ent
= mdstat_read(0, 0);
547 for (e
= ent
; e
; e
= e
->next
) {
548 if (!is_container_member(e
, container
))
550 if (e
->percent
>= 0) {
559 static int freeze_container(struct supertype
*st
)
561 int container_dev
= (st
->container_dev
!= NoMdDev
562 ? st
->container_dev
: st
->devnum
);
568 fmt_devname(container
, container_dev
);
570 if (block_monitor(container
, 1)) {
571 fprintf(stderr
, Name
": failed to freeze container\n");
578 static void unfreeze_container(struct supertype
*st
)
580 int container_dev
= (st
->container_dev
!= NoMdDev
581 ? st
->container_dev
: st
->devnum
);
584 fmt_devname(container
, container_dev
);
586 unblock_monitor(container
, 1);
589 static int freeze(struct supertype
*st
)
591 /* Try to freeze resync/rebuild on this array/container.
592 * Return -1 if the array is busy,
593 * return -2 container cannot be frozen,
594 * return 0 if this kernel doesn't support 'frozen'
595 * return 1 if it worked.
597 if (st
->ss
->external
)
598 return freeze_container(st
);
600 struct mdinfo
*sra
= sysfs_read(-1, st
->devnum
, GET_VERSION
);
606 /* Need to clear any 'read-auto' status */
607 if (sysfs_get_str(sra
, NULL
, "array_state", buf
, 20) > 0 &&
608 strncmp(buf
, "read-auto", 9) == 0)
609 sysfs_set_str(sra
, NULL
, "array_state", "clean");
611 err
= sysfs_freeze_array(sra
);
617 static void unfreeze(struct supertype
*st
)
619 if (st
->ss
->external
)
620 return unfreeze_container(st
);
622 struct mdinfo
*sra
= sysfs_read(-1, st
->devnum
, GET_VERSION
);
625 sysfs_set_str(sra
, NULL
, "sync_action", "idle");
630 static void wait_reshape(struct mdinfo
*sra
)
632 int fd
= sysfs_get_fd(sra
, NULL
, "sync_action");
638 while (sysfs_fd_get_str(fd
, action
, 20) > 0 &&
639 strncmp(action
, "reshape", 7) == 0) {
643 select(fd
+1, NULL
, NULL
, &rfds
, NULL
);
648 static int reshape_super(struct supertype
*st
, long long size
, int level
,
649 int layout
, int chunksize
, int raid_disks
,
650 int delta_disks
, char *backup_file
, char *dev
,
651 int direction
, int verbose
)
653 /* nothing extra to check in the native case */
654 if (!st
->ss
->external
)
656 if (!st
->ss
->reshape_super
||
657 !st
->ss
->manage_reshape
) {
658 fprintf(stderr
, Name
": %s metadata does not support reshape\n",
663 return st
->ss
->reshape_super(st
, size
, level
, layout
, chunksize
,
664 raid_disks
, delta_disks
, backup_file
, dev
,
668 static void sync_metadata(struct supertype
*st
)
670 if (st
->ss
->external
) {
671 if (st
->update_tail
) {
672 flush_metadata_updates(st
);
673 st
->update_tail
= &st
->updates
;
675 st
->ss
->sync_metadata(st
);
679 static int subarray_set_num(char *container
, struct mdinfo
*sra
, char *name
, int n
)
681 /* when dealing with external metadata subarrays we need to be
682 * prepared to handle EAGAIN. The kernel may need to wait for
683 * mdmon to mark the array active so the kernel can handle
684 * allocations/writeback when preparing the reshape action
685 * (md_allow_write()). We temporarily disable safe_mode_delay
686 * to close a race with the array_state going clean before the
687 * next write to raid_disks / stripe_cache_size
692 /* only 'raid_disks' and 'stripe_cache_size' trigger md_allow_write */
694 (strcmp(name
, "raid_disks") != 0 &&
695 strcmp(name
, "stripe_cache_size") != 0))
696 return sysfs_set_num(sra
, NULL
, name
, n
);
698 rc
= sysfs_get_str(sra
, NULL
, "safe_mode_delay", safe
, sizeof(safe
));
701 sysfs_set_num(sra
, NULL
, "safe_mode_delay", 0);
702 rc
= sysfs_set_num(sra
, NULL
, name
, n
);
703 if (rc
< 0 && errno
== EAGAIN
) {
704 ping_monitor(container
);
705 /* if we get EAGAIN here then the monitor is not active
708 rc
= sysfs_set_num(sra
, NULL
, name
, n
);
710 sysfs_set_str(sra
, NULL
, "safe_mode_delay", safe
);
714 int start_reshape(struct mdinfo
*sra
, int already_running
,
715 int before_data_disks
, int data_disks
)
718 unsigned long long sync_max_to_set
;
720 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
721 err
= sysfs_set_num(sra
, NULL
, "suspend_hi", sra
->reshape_progress
);
722 err
= err
?: sysfs_set_num(sra
, NULL
, "suspend_lo",
723 sra
->reshape_progress
);
724 if (before_data_disks
<= data_disks
)
725 sync_max_to_set
= sra
->reshape_progress
/ data_disks
;
727 sync_max_to_set
= (sra
->component_size
* data_disks
728 - sra
->reshape_progress
) / data_disks
;
729 if (!already_running
)
730 sysfs_set_num(sra
, NULL
, "sync_min", sync_max_to_set
);
731 err
= err
?: sysfs_set_num(sra
, NULL
, "sync_max", sync_max_to_set
);
732 if (!already_running
)
733 err
= err
?: sysfs_set_str(sra
, NULL
, "sync_action", "reshape");
738 void abort_reshape(struct mdinfo
*sra
)
740 sysfs_set_str(sra
, NULL
, "sync_action", "idle");
741 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
742 sysfs_set_num(sra
, NULL
, "suspend_hi", 0);
743 sysfs_set_num(sra
, NULL
, "suspend_lo", 0);
744 sysfs_set_num(sra
, NULL
, "sync_min", 0);
745 sysfs_set_str(sra
, NULL
, "sync_max", "max");
748 int remove_disks_for_takeover(struct supertype
*st
,
753 struct mdinfo
*remaining
;
756 if (sra
->array
.level
== 10)
757 nr_of_copies
= layout
& 0xff;
758 else if (sra
->array
.level
== 1)
759 nr_of_copies
= sra
->array
.raid_disks
;
763 remaining
= sra
->devs
;
765 /* for each 'copy', select one device and remove from the list. */
766 for (slot
= 0; slot
< sra
->array
.raid_disks
; slot
+= nr_of_copies
) {
767 struct mdinfo
**diskp
;
770 /* Find a working device to keep */
771 for (diskp
= &remaining
; *diskp
; diskp
= &(*diskp
)->next
) {
772 struct mdinfo
*disk
= *diskp
;
774 if (disk
->disk
.raid_disk
< slot
)
776 if (disk
->disk
.raid_disk
>= slot
+ nr_of_copies
)
778 if (disk
->disk
.state
& (1<<MD_DISK_REMOVED
))
780 if (disk
->disk
.state
& (1<<MD_DISK_FAULTY
))
782 if (!(disk
->disk
.state
& (1<<MD_DISK_SYNC
)))
785 /* We have found a good disk to use! */
787 disk
->next
= sra
->devs
;
796 if (slot
< sra
->array
.raid_disks
) {
797 /* didn't find all slots */
803 sra
->devs
= remaining
;
807 /* Remove all 'remaining' devices from the array */
809 struct mdinfo
*sd
= remaining
;
810 remaining
= sd
->next
;
812 sysfs_set_str(sra
, sd
, "state", "faulty");
813 sysfs_set_str(sra
, sd
, "slot", "none");
814 /* for external metadata disks should be removed in mdmon */
815 if (!st
->ss
->external
)
816 sysfs_set_str(sra
, sd
, "state", "remove");
817 sd
->disk
.state
|= (1<<MD_DISK_REMOVED
);
818 sd
->disk
.state
&= ~(1<<MD_DISK_SYNC
);
819 sd
->next
= sra
->devs
;
825 void reshape_free_fdlist(int *fdlist
,
826 unsigned long long *offsets
,
831 for (i
= 0; i
< size
; i
++)
839 int reshape_prepare_fdlist(char *devname
,
843 unsigned long blocks
,
846 unsigned long long *offsets
)
851 for (d
= 0; d
<= nrdisks
; d
++)
854 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
855 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
857 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
858 char *dn
= map_dev(sd
->disk
.major
,
860 fdlist
[sd
->disk
.raid_disk
]
861 = dev_open(dn
, O_RDONLY
);
862 offsets
[sd
->disk
.raid_disk
] = sd
->data_offset
*512;
863 if (fdlist
[sd
->disk
.raid_disk
] < 0) {
865 Name
": %s: cannot open component %s\n",
866 devname
, dn
? dn
: "-unknown-");
870 } else if (backup_file
== NULL
) {
872 char *dn
= map_dev(sd
->disk
.major
,
874 fdlist
[d
] = dev_open(dn
, O_RDWR
);
875 offsets
[d
] = (sd
->data_offset
+ sra
->component_size
- blocks
- 8)*512;
877 fprintf(stderr
, Name
": %s: cannot open component %s\n",
878 devname
, dn
? dn
: "-unknown-");
889 int reshape_open_backup_file(char *backup_file
,
894 unsigned long long *offsets
,
897 /* Return 1 on success, 0 on any form of failure */
898 /* need to check backup file is large enough */
904 *fdlist
= open(backup_file
, O_RDWR
|O_CREAT
|(restart
? O_TRUNC
: O_EXCL
),
908 fprintf(stderr
, Name
": %s: cannot create backup file %s: %s\n",
909 devname
, backup_file
, strerror(errno
));
912 /* Guard against backup file being on array device.
913 * If array is partitioned or if LVM etc is in the
914 * way this will not notice, but it is better than
917 fstat(*fdlist
, &stb
);
920 if (stb
.st_rdev
== dev
) {
921 fprintf(stderr
, Name
": backup file must NOT be"
922 " on the array being reshaped.\n");
928 for (i
=0; i
< blocks
+ 8 ; i
++) {
929 if (write(*fdlist
, buf
, 512) != 512) {
930 fprintf(stderr
, Name
": %s: cannot create"
931 " backup file %s: %s\n",
932 devname
, backup_file
, strerror(errno
));
936 if (fsync(*fdlist
) != 0) {
937 fprintf(stderr
, Name
": %s: cannot create backup file %s: %s\n",
938 devname
, backup_file
, strerror(errno
));
945 unsigned long compute_backup_blocks(int nchunk
, int ochunk
,
946 unsigned int ndata
, unsigned int odata
)
948 unsigned long a
, b
, blocks
;
949 /* So how much do we need to backup.
950 * We need an amount of data which is both a whole number of
951 * old stripes and a whole number of new stripes.
952 * So LCM for (chunksize*datadisks).
954 a
= (ochunk
/512) * odata
;
955 b
= (nchunk
/512) * ndata
;
963 /* LCM == product / GCD */
964 blocks
= (ochunk
/512) * (nchunk
/512) * odata
* ndata
/ a
;
969 char *analyse_change(struct mdinfo
*info
, struct reshape
*re
)
971 /* Based on the current array state in info->array and
972 * the changes in info->new_* etc, determine:
973 * - whether the change is possible
974 * - Intermediate level/raid_disks/layout
975 * - whether a restriping reshape is needed
976 * - number of sectors in minimum change unit. This
977 * will cover a whole number of stripes in 'before' and
980 * Return message if the change should be rejected
981 * NULL if the change can be achieved
983 * This can be called as part of starting a reshape, or
984 * when assembling an array that is undergoing reshape.
987 /* delta_parity records change in number of devices
988 * caused by level change
990 int delta_parity
= 0;
992 /* If a new level not explicitly given, we assume no-change */
993 if (info
->new_level
== UnSet
)
994 info
->new_level
= info
->array
.level
;
997 switch (info
->new_level
) {
1003 /* chunk size is meaningful, must divide component_size
1006 if (info
->component_size
% (info
->new_chunk
/512))
1007 return "New chunk size does not"
1008 " divide component size";
1011 return "chunk size not meaningful for this level";
1014 info
->new_chunk
= info
->array
.chunk_size
;
1016 switch (info
->array
.level
) {
1018 return "Cannot understand this RAID level";
1020 /* RAID1 can convert to RAID1 with different disks, or
1021 * raid5 with 2 disks, or
1024 if (info
->new_level
> 1 &&
1025 (info
->component_size
& 7))
1026 return "Cannot convert RAID1 of this size - "
1027 "reduce size to multiple of 4K first.";
1028 if (info
->new_level
== 0) {
1029 if (info
->delta_disks
!= UnSet
&&
1030 info
->delta_disks
!= 0)
1031 return "Cannot change number of disks "
1032 "with RAID1->RAID0 conversion";
1034 re
->before
.data_disks
= 1;
1035 re
->after
.data_disks
= 1;
1036 re
->before
.layout
= 0;
1037 re
->backup_blocks
= 0;
1041 if (info
->new_level
== 1) {
1042 if (info
->delta_disks
== UnSet
)
1043 /* Don't know what to do */
1044 return "no change requested for Growing RAID1";
1046 re
->backup_blocks
= 0;
1050 if (info
->array
.raid_disks
== 2 &&
1051 info
->new_level
== 5) {
1054 re
->before
.data_disks
= 1;
1055 if (info
->delta_disks
!= UnSet
&&
1056 info
->delta_disks
!= 0)
1057 re
->after
.data_disks
= 1 + info
->delta_disks
;
1059 re
->after
.data_disks
= 1;
1060 if (re
->after
.data_disks
< 1)
1061 return "Number of disks too small for RAID5";
1063 re
->before
.layout
= ALGORITHM_LEFT_SYMMETRIC
;
1064 info
->array
.chunk_size
= 65536;
1067 /* Could do some multi-stage conversions, but leave that to
1070 return "Impossibly level change request for RAID1";
1073 /* RAID10 can only be converted from near mode to
1074 * RAID0 by removing some devices
1076 if ((info
->array
.layout
& ~0xff) != 0x100)
1077 return "Cannot Grow RAID10 with far/offset layout";
1078 /* number of devices must be multiple of number of copies */
1079 if (info
->array
.raid_disks
% (info
->array
.layout
& 0xff))
1080 return "RAID10 layout too complex for Grow operation";
1082 if (info
->new_level
!= 0)
1083 return "RAID10 can only be changed to RAID0";
1084 new_disks
= (info
->array
.raid_disks
1085 / (info
->array
.layout
& 0xff));
1086 if (info
->delta_disks
== UnSet
)
1087 info
->delta_disks
= (new_disks
1088 - info
->array
.raid_disks
);
1090 if (info
->delta_disks
!= new_disks
- info
->array
.raid_disks
)
1091 return "New number of raid-devices impossible for RAID10";
1092 if (info
->new_chunk
&&
1093 info
->new_chunk
!= info
->array
.chunk_size
)
1094 return "Cannot change chunk-size with RAID10 Grow";
1099 re
->before
.data_disks
= new_disks
;
1100 re
->after
.data_disks
= re
->before
.data_disks
;
1101 re
->before
.layout
= 0;
1102 re
->backup_blocks
= 0;
1106 /* RAID0 can be converted to RAID10, or to RAID456 */
1107 if (info
->new_level
== 10) {
1108 if (info
->new_layout
== UnSet
&& info
->delta_disks
== UnSet
) {
1109 /* Assume near=2 layout */
1110 info
->new_layout
= 0x102;
1111 info
->delta_disks
= info
->array
.raid_disks
;
1113 if (info
->new_layout
== UnSet
) {
1114 int copies
= 1 + (info
->delta_disks
1115 / info
->array
.raid_disks
);
1116 if (info
->array
.raid_disks
* (copies
-1)
1117 != info
->delta_disks
)
1118 return "Impossible number of devices"
1119 " for RAID0->RAID10";
1120 info
->new_layout
= 0x100 + copies
;
1122 if (info
->delta_disks
== UnSet
) {
1123 int copies
= info
->new_layout
& 0xff;
1124 if (info
->new_layout
!= 0x100 + copies
)
1125 return "New layout impossible"
1126 " for RAID0->RAID10";;
1127 info
->delta_disks
= (copies
- 1) *
1128 info
->array
.raid_disks
;
1130 if (info
->new_chunk
&&
1131 info
->new_chunk
!= info
->array
.chunk_size
)
1132 return "Cannot change chunk-size with RAID0->RAID10";
1136 re
->before
.data_disks
= (info
->array
.raid_disks
+
1138 re
->after
.data_disks
= re
->before
.data_disks
;
1139 re
->before
.layout
= info
->new_layout
;
1140 re
->backup_blocks
= 0;
1144 /* RAID0 can also covert to RAID0/4/5/6 by first converting to
1145 * a raid4 style layout of the final level.
1147 switch (info
->new_level
) {
1152 re
->before
.layout
= 0;
1157 re
->before
.layout
= ALGORITHM_PARITY_N
;
1162 re
->before
.layout
= ALGORITHM_PARITY_N
;
1165 return "Impossible level change requested";
1167 re
->before
.data_disks
= info
->array
.raid_disks
;
1168 /* determining 'after' layout happens outside this 'switch' */
1172 info
->array
.layout
= ALGORITHM_PARITY_N
;
1174 switch (info
->new_level
) {
1178 re
->level
= info
->array
.level
;
1179 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1180 re
->before
.layout
= info
->array
.layout
;
1184 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1185 re
->before
.layout
= info
->array
.layout
;
1190 re
->before
.data_disks
= info
->array
.raid_disks
- 1;
1191 switch (info
->array
.layout
) {
1192 case ALGORITHM_LEFT_ASYMMETRIC
:
1193 re
->before
.layout
= ALGORITHM_LEFT_ASYMMETRIC_6
;
1195 case ALGORITHM_RIGHT_ASYMMETRIC
:
1196 re
->before
.layout
= ALGORITHM_RIGHT_ASYMMETRIC_6
;
1198 case ALGORITHM_LEFT_SYMMETRIC
:
1199 re
->before
.layout
= ALGORITHM_LEFT_SYMMETRIC_6
;
1201 case ALGORITHM_RIGHT_SYMMETRIC
:
1202 re
->before
.layout
= ALGORITHM_RIGHT_SYMMETRIC_6
;
1204 case ALGORITHM_PARITY_0
:
1205 re
->before
.layout
= ALGORITHM_PARITY_0_6
;
1207 case ALGORITHM_PARITY_N
:
1208 re
->before
.layout
= ALGORITHM_PARITY_N_6
;
1211 return "Cannot convert an array with this layout";
1215 if (info
->array
.raid_disks
!= 2)
1216 return "Can only convert a 2-device array to RAID1";
1217 if (info
->delta_disks
!= UnSet
&&
1218 info
->delta_disks
!= 0)
1219 return "Cannot set raid_disk when "
1220 "converting RAID5->RAID1";
1224 return "Impossible level change requested";
1228 switch (info
->new_level
) {
1234 re
->before
.data_disks
= info
->array
.raid_disks
- 2;
1235 re
->before
.layout
= info
->array
.layout
;
1238 return "Impossible level change requested";
1243 /* If we reached here then it looks like a re-stripe is
1244 * happening. We have determined the intermediate level
1245 * and initial raid_disks/layout and stored these in 're'.
1247 * We need to deduce the final layout that can be atomically
1248 * converted to the end state.
1250 switch (info
->new_level
) {
1252 /* We can only get to RAID0 from RAID4 or RAID5
1253 * with appropriate layout and one extra device
1255 if (re
->level
!= 4 && re
->level
!= 5)
1256 return "Cannot covert to RAID0 from this level";
1258 switch (re
->level
) {
1260 re
->after
.layout
= 0 ; break;
1262 re
->after
.layout
= ALGORITHM_PARITY_N
; break;
1267 /* We can only get to RAID4 from RAID5 */
1268 if (re
->level
!= 4 && re
->level
!= 5)
1269 return "Cannot convert to RAID4 from this level";
1271 switch (re
->level
) {
1273 re
->after
.layout
= 0 ; break;
1275 re
->after
.layout
= ALGORITHM_PARITY_N
; break;
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; break;
1349 case 5: re
->parity
= 1; break;
1350 default: re
->parity
= 0; break;
1352 /* So we have a restripe operation, we need to calculate the number
1353 * of blocks per reshape operation.
1355 if (info
->new_chunk
== 0)
1356 info
->new_chunk
= info
->array
.chunk_size
;
1357 if (re
->after
.data_disks
== re
->before
.data_disks
&&
1358 re
->after
.layout
== re
->before
.layout
&&
1359 info
->new_chunk
== info
->array
.chunk_size
) {
1360 /* Nothing to change */
1361 re
->backup_blocks
= 0;
1364 if (re
->after
.data_disks
== 1 && re
->before
.data_disks
== 1) {
1365 /* chunk and layout changes make no difference */
1366 re
->backup_blocks
= 0;
1370 if (re
->after
.data_disks
== re
->before
.data_disks
&&
1371 get_linux_version() < 2006032)
1372 return "in-place reshape is not safe before 2.6.32 - sorry.";
1374 if (re
->after
.data_disks
< re
->before
.data_disks
&&
1375 get_linux_version() < 2006030)
1376 return "reshape to fewer devices is not supported before 2.6.30 - sorry.";
1378 re
->backup_blocks
= compute_backup_blocks(
1379 info
->new_chunk
, info
->array
.chunk_size
,
1380 re
->after
.data_disks
,
1381 re
->before
.data_disks
);
1383 re
->new_size
= info
->component_size
* re
->after
.data_disks
;
1387 static int set_array_size(struct supertype
*st
, struct mdinfo
*sra
,
1390 struct mdinfo
*info
;
1394 if ((st
== NULL
) || (sra
== NULL
))
1397 if (text_version
== NULL
)
1398 text_version
= sra
->text_version
;
1399 subarray
= strchr(text_version
+1, '/')+1;
1400 info
= st
->ss
->container_content(st
, subarray
);
1402 unsigned long long current_size
= 0;
1403 unsigned long long new_size
=
1404 info
->custom_array_size
/2;
1406 if (sysfs_get_ll(sra
, NULL
, "array_size", ¤t_size
) == 0 &&
1407 new_size
> current_size
) {
1408 if (sysfs_set_num(sra
, NULL
, "array_size", new_size
)
1410 dprintf("Error: Cannot set array size");
1413 dprintf("Array size changed");
1415 dprintf(" from %llu to %llu.\n",
1416 current_size
, new_size
);
1420 dprintf("Error: set_array_size(): info pointer in NULL\n");
1425 static int reshape_array(char *container
, int fd
, char *devname
,
1426 struct supertype
*st
, struct mdinfo
*info
,
1427 int force
, struct mddev_dev
*devlist
,
1428 char *backup_file
, int quiet
, int forked
,
1429 int restart
, int freeze_reshape
);
1430 static int reshape_container(char *container
, char *devname
,
1432 struct supertype
*st
,
1433 struct mdinfo
*info
,
1436 int quiet
, int restart
, int freeze_reshape
);
1438 int Grow_reshape(char *devname
, int fd
, int quiet
, char *backup_file
,
1440 int level
, char *layout_str
, int chunksize
, int raid_disks
,
1441 struct mddev_dev
*devlist
,
1442 int assume_clean
, int force
)
1444 /* Make some changes in the shape of an array.
1445 * The kernel must support the change.
1447 * There are three different changes. Each can trigger
1448 * a resync or recovery so we freeze that until we have
1449 * requested everything (if kernel supports freezing - 2.6.30).
1451 * - change size (i.e. component_size)
1453 * - change layout/chunksize/ndisks
1455 * The last can require a reshape. It is different on different
1456 * levels so we need to check the level before actioning it.
1457 * Some times the level change needs to be requested after the
1458 * reshape (e.g. raid6->raid5, raid5->raid0)
1461 struct mdu_array_info_s array
;
1463 struct supertype
*st
;
1464 char *subarray
= NULL
;
1468 char *container
= NULL
;
1469 char container_buf
[20];
1472 struct mddev_dev
*dv
;
1478 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) < 0) {
1479 fprintf(stderr
, Name
": %s is not an active md array - aborting\n",
1485 (chunksize
|| level
!= UnSet
|| layout_str
|| raid_disks
)) {
1486 fprintf(stderr
, Name
": cannot change component size at the same time "
1487 "as other changes.\n"
1488 " Change size first, then check data is intact before "
1489 "making other changes.\n");
1493 if (raid_disks
&& raid_disks
< array
.raid_disks
&& array
.level
> 1 &&
1494 get_linux_version() < 2006032 &&
1495 !check_env("MDADM_FORCE_FEWER")) {
1496 fprintf(stderr
, Name
": reducing the number of devices is not safe before Linux 2.6.32\n"
1497 " Please use a newer kernel\n");
1501 st
= super_by_fd(fd
, &subarray
);
1503 fprintf(stderr
, Name
": Unable to determine metadata format for %s\n", devname
);
1506 if (raid_disks
> st
->max_devs
) {
1507 fprintf(stderr
, Name
": Cannot increase raid-disks on this array"
1508 " beyond %d\n", st
->max_devs
);
1512 /* in the external case we need to check that the requested reshape is
1513 * supported, and perform an initial check that the container holds the
1514 * pre-requisite spare devices (mdmon owns final validation)
1516 if (st
->ss
->external
) {
1521 container_dev
= st
->container_dev
;
1522 cfd
= open_dev_excl(st
->container_dev
);
1524 container_dev
= st
->devnum
;
1526 cfd
= open_dev_excl(st
->devnum
);
1530 fprintf(stderr
, Name
": Unable to open container for %s\n",
1536 fmt_devname(container_buf
, container_dev
);
1537 container
= container_buf
;
1539 rv
= st
->ss
->load_container(st
, cfd
, NULL
);
1542 fprintf(stderr
, Name
": Cannot read superblock for %s\n",
1548 /* check if operation is supported for metadata handler */
1549 if (st
->ss
->container_content
) {
1550 struct mdinfo
*cc
= NULL
;
1551 struct mdinfo
*content
= NULL
;
1553 cc
= st
->ss
->container_content(st
, subarray
);
1554 for (content
= cc
; content
; content
= content
->next
) {
1555 int allow_reshape
= 1;
1557 /* check if reshape is allowed based on metadata
1558 * indications stored in content.array.status
1560 if (content
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
))
1562 if (content
->array
.state
1563 & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
))
1565 if (!allow_reshape
) {
1566 fprintf(stderr
, Name
1567 " 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 (raid_disks
> array
.raid_disks
&&
1586 array
.spare_disks
+added_disks
< (raid_disks
- array
.raid_disks
) &&
1589 Name
": Need %d spare%s to avoid degraded array,"
1590 " and only have %d.\n"
1591 " Use --force to over-ride this check.\n",
1592 raid_disks
- array
.raid_disks
,
1593 raid_disks
- array
.raid_disks
== 1 ? "" : "s",
1594 array
.spare_disks
+ added_disks
);
1598 sra
= sysfs_read(fd
, 0, GET_LEVEL
| GET_DISKS
| GET_DEVS
1599 | GET_STATE
| GET_VERSION
);
1601 if (st
->ss
->external
&& subarray
== NULL
) {
1602 array
.level
= LEVEL_CONTAINER
;
1603 sra
->array
.level
= LEVEL_CONTAINER
;
1606 fprintf(stderr
, Name
": failed to read sysfs parameters for %s\n",
1610 frozen
= freeze(st
);
1612 /* freeze() already spewed the reason */
1615 } else if (frozen
< 0) {
1616 fprintf(stderr
, Name
": %s is performing resync/recovery and cannot"
1617 " be reshaped\n", devname
);
1622 /* ========= set size =============== */
1623 if (size
>= 0 && (size
== 0 || size
!= array
.size
)) {
1624 long long orig_size
= get_component_size(fd
)/2;
1625 long long min_csize
;
1627 int raid0_takeover
= 0;
1630 orig_size
= array
.size
;
1632 if (reshape_super(st
, size
, UnSet
, UnSet
, 0, 0, UnSet
, NULL
,
1633 devname
, APPLY_METADATA_CHANGES
, !quiet
)) {
1638 if (st
->ss
->external
) {
1639 /* metadata can have size limitation
1640 * update size value according to metadata information
1642 struct mdinfo
*sizeinfo
=
1643 st
->ss
->container_content(st
, subarray
);
1645 unsigned long long new_size
=
1646 sizeinfo
->custom_array_size
/2;
1647 int data_disks
= get_data_disks(
1648 sizeinfo
->array
.level
,
1649 sizeinfo
->array
.layout
,
1650 sizeinfo
->array
.raid_disks
);
1651 new_size
/= data_disks
;
1652 dprintf("Metadata size correction from %llu to "
1653 "%llu (%llu)\n", orig_size
, new_size
,
1654 new_size
* data_disks
);
1656 sysfs_free(sizeinfo
);
1660 /* Update the size of each member device in case
1661 * they have been resized. This will never reduce
1662 * below the current used-size. The "size" attribute
1663 * understands '0' to mean 'max'.
1667 for (mdi
= sra
->devs
; mdi
; mdi
= mdi
->next
) {
1668 if (sysfs_set_num(sra
, mdi
, "size", 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
1683 > (long long)csize
)))
1689 fprintf(stderr
, Name
": Cannot set size on "
1690 "array members.\n");
1691 goto size_change_error
;
1693 if (min_csize
&& size
> min_csize
) {
1694 fprintf(stderr
, Name
": 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
&& size
== 0) {
1700 /* Don't let the kernel choose a size - it will get
1703 fprintf(stderr
, Name
": Limited v0.90 array to "
1704 "2TB per device\n");
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
;
1730 if (array
.size
!= size
) {
1731 /* got truncated to 32bit, write to
1732 * component_size instead
1735 rv
= sysfs_set_num(sra
, NULL
,
1736 "component_size", size
);
1740 rv
= ioctl(fd
, SET_ARRAY_INFO
, &array
);
1742 /* manage array size when it is managed externally
1744 if ((rv
== 0) && st
->ss
->external
)
1745 rv
= set_array_size(st
, sra
, sra
->text_version
);
1748 if (raid0_takeover
) {
1749 /* do not recync non-existing parity,
1750 * we will drop it anyway
1752 sysfs_set_str(sra
, NULL
, "sync_action", "frozen");
1753 /* go back to raid0, drop parity disk
1755 sysfs_set_str(sra
, NULL
, "level", "raid0");
1756 ioctl(fd
, GET_ARRAY_INFO
, &array
);
1763 /* restore metadata */
1764 if (reshape_super(st
, orig_size
, UnSet
, UnSet
, 0, 0,
1765 UnSet
, NULL
, devname
,
1766 ROLLBACK_METADATA_CHANGES
,
1769 fprintf(stderr
, Name
": Cannot set device size for %s: %s\n",
1770 devname
, strerror(err
));
1772 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
1773 fprintf(stderr
, " Bitmap must be removed before size can be changed\n");
1778 /* This will fail on kernels newer than 3.0 unless
1779 * a backport has been arranged.
1782 sysfs_set_str(sra
, NULL
, "resync_start", "none") < 0)
1783 fprintf(stderr
, Name
": --assume-clean not support with --grow on this kernel\n");
1785 ioctl(fd
, GET_ARRAY_INFO
, &array
);
1786 size
= get_component_size(fd
)/2;
1790 if (size
== orig_size
)
1791 fprintf(stderr
, Name
": component size of %s "
1792 "unchanged at %lluK\n",
1795 fprintf(stderr
, Name
": component size of %s "
1796 "has been set to %lluK\n",
1800 } else if (array
.level
!= LEVEL_CONTAINER
) {
1801 size
= get_component_size(fd
)/2;
1806 /* See if there is anything else to do */
1807 if ((level
== UnSet
|| level
== array
.level
) &&
1808 (layout_str
== NULL
) &&
1809 (chunksize
== 0 || chunksize
== array
.chunk_size
) &&
1810 (raid_disks
== 0 || raid_disks
== array
.raid_disks
)) {
1811 /* Nothing more to do */
1812 if (!changed
&& !quiet
)
1813 fprintf(stderr
, Name
": %s: no change requested\n",
1818 /* ========= check for Raid10/Raid1 -> Raid0 conversion ===============
1819 * current implementation assumes that following conditions must be met:
1822 * - near_copies == 2
1824 if ((level
== 0 && array
.level
== 10 && sra
&&
1825 array
.layout
== ((1 << 8) + 2) && !(array
.raid_disks
& 1)) ||
1826 (level
== 0 && array
.level
== 1 && sra
)) {
1828 err
= remove_disks_for_takeover(st
, sra
, array
.layout
);
1830 dprintf(Name
": Array cannot be reshaped\n");
1836 /* Make sure mdmon has seen the device removal
1837 * and updated metadata before we continue with
1841 ping_monitor(container
);
1844 memset(&info
, 0, sizeof(info
));
1846 sysfs_init(&info
, fd
, NoMdDev
);
1847 strcpy(info
.text_version
, sra
->text_version
);
1848 info
.component_size
= size
*2;
1849 info
.new_level
= level
;
1850 info
.new_chunk
= chunksize
* 1024;
1851 if (info
.array
.level
== LEVEL_CONTAINER
) {
1852 info
.delta_disks
= UnSet
;
1853 info
.array
.raid_disks
= raid_disks
;
1854 } else if (raid_disks
)
1855 info
.delta_disks
= raid_disks
- info
.array
.raid_disks
;
1857 info
.delta_disks
= UnSet
;
1858 if (layout_str
== NULL
) {
1859 info
.new_layout
= UnSet
;
1860 if (info
.array
.level
== 6 &&
1861 (info
.new_level
== 6 || info
.new_level
== UnSet
) &&
1862 info
.array
.layout
>= 16) {
1863 fprintf(stderr
, Name
1864 ": %s has a non-standard layout. If you"
1865 " wish to preserve this\n"
1866 " during the reshape, please specify"
1867 " --layout=preserve\n"
1868 " If you want to change it, specify a"
1869 " layout or use --layout=normalise\n",
1874 } else if (strcmp(layout_str
, "normalise") == 0 ||
1875 strcmp(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 fprintf(stderr
, Name
1888 ": %s is only meaningful when reshaping"
1889 " a RAID6 array.\n", layout_str
);
1893 } else if (strcmp(layout_str
, "preserve") == 0) {
1894 /* This means that a non-standard RAID6 layout
1897 * - When reshape a RAID6 (e.g. adding a device)
1898 * which is in a non-standard layout, it is OK
1899 * to preserve that layout.
1900 * - When converting a RAID5 to RAID6, leave it in
1901 * the XXX-6 layout, don't re-layout.
1903 if (info
.array
.level
== 6 && info
.new_level
== UnSet
)
1904 info
.new_layout
= info
.array
.layout
;
1905 else if (info
.array
.level
== 5 && info
.new_level
== 6) {
1907 strcpy(l
, map_num(r5layout
, info
.array
.layout
));
1909 info
.new_layout
= map_name(r6layout
, l
);
1911 fprintf(stderr
, Name
1912 ": %s in only meaningful when reshaping"
1913 " to RAID6\n", layout_str
);
1918 int l
= info
.new_level
;
1920 l
= info
.array
.level
;
1923 info
.new_layout
= map_name(r5layout
, layout_str
);
1926 info
.new_layout
= map_name(r6layout
, layout_str
);
1929 info
.new_layout
= parse_layout_10(layout_str
);
1932 info
.new_layout
= parse_layout_faulty(layout_str
);
1935 fprintf(stderr
, Name
": layout not meaningful"
1936 " with this level\n");
1940 if (info
.new_layout
== UnSet
) {
1941 fprintf(stderr
, Name
": layout %s not understood"
1942 " for this level\n",
1949 if (array
.level
== LEVEL_FAULTY
) {
1950 if (level
!= UnSet
&& level
!= array
.level
) {
1951 fprintf(stderr
, Name
": cannot change level of Faulty device\n");
1955 fprintf(stderr
, Name
": cannot set chunksize of Faulty device\n");
1958 if (raid_disks
&& raid_disks
!= 1) {
1959 fprintf(stderr
, Name
": cannot set raid_disks of Faulty device\n");
1963 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
1964 dprintf("Cannot get array information.\n");
1967 array
.layout
= info
.new_layout
;
1968 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
1969 fprintf(stderr
, Name
": failed to set new layout\n");
1972 printf("layout for %s set to %d\n",
1973 devname
, array
.layout
);
1975 } else if (array
.level
== LEVEL_CONTAINER
) {
1976 /* This change is to be applied to every array in the
1977 * container. This is only needed when the metadata imposes
1978 * restraints of the various arrays in the container.
1979 * Currently we only know that IMSM requires all arrays
1980 * to have the same number of devices so changing the
1981 * number of devices (On-Line Capacity Expansion) must be
1982 * performed at the level of the container
1984 rv
= reshape_container(container
, devname
, -1, st
, &info
,
1985 force
, backup_file
, quiet
, 0, 0);
1988 /* get spare devices from external metadata
1990 if (st
->ss
->external
) {
1991 struct mdinfo
*info2
;
1993 info2
= st
->ss
->container_content(st
, subarray
);
1995 info
.array
.spare_disks
=
1996 info2
->array
.spare_disks
;
2001 /* Impose these changes on a single array. First
2002 * check that the metadata is OK with the change. */
2004 if (reshape_super(st
, -1, info
.new_level
,
2005 info
.new_layout
, info
.new_chunk
,
2006 info
.array
.raid_disks
, info
.delta_disks
,
2007 backup_file
, devname
, APPLY_METADATA_CHANGES
,
2013 rv
= reshape_array(container
, fd
, devname
, st
, &info
, force
,
2014 devlist
, backup_file
, quiet
, 0, 0, 0);
2024 /* verify_reshape_position()
2025 * Function checks if reshape position in metadata is not farther
2026 * than position in md.
2028 * 0 : not valid sysfs entry
2029 * it can be caused by not started reshape, it should be started
2030 * by reshape array or raid0 array is before takeover
2031 * -1 : error, reshape position is obviously wrong
2032 * 1 : success, reshape progress correct or updated
2034 static int verify_reshape_position(struct mdinfo
*info
, int level
)
2040 /* read sync_max, failure can mean raid0 array */
2041 rv
= sysfs_get_str(info
, NULL
, "sync_max", buf
, 40);
2045 unsigned long long position
= strtoull(buf
, &ep
, 0);
2047 dprintf(Name
": Read sync_max sysfs entry is: %s\n", buf
);
2048 if (!(ep
== buf
|| (*ep
!= 0 && *ep
!= '\n' && *ep
!= ' '))) {
2049 position
*= get_data_disks(level
,
2051 info
->array
.raid_disks
);
2052 if (info
->reshape_progress
< position
) {
2053 dprintf("Corrected reshape progress (%llu) to "
2054 "md position (%llu)\n",
2055 info
->reshape_progress
, position
);
2056 info
->reshape_progress
= position
;
2058 } else if (info
->reshape_progress
> position
) {
2059 fprintf(stderr
, Name
": Fatal error: array "
2060 "reshape was not properly frozen "
2061 "(expected reshape position is %llu, "
2062 "but reshape progress is %llu.\n",
2063 position
, info
->reshape_progress
);
2066 dprintf("Reshape position in md and metadata "
2071 } else if (rv
== 0) {
2072 /* for valid sysfs entry, 0-length content
2073 * should be indicated as error
2081 static int reshape_array(char *container
, int fd
, char *devname
,
2082 struct supertype
*st
, struct mdinfo
*info
,
2083 int force
, struct mddev_dev
*devlist
,
2084 char *backup_file
, int quiet
, int forked
,
2085 int restart
, int freeze_reshape
)
2087 struct reshape reshape
;
2090 int orig_level
= UnSet
;
2093 struct mdu_array_info_s array
;
2096 struct mddev_dev
*dv
;
2100 unsigned long long *offsets
= NULL
;
2104 unsigned long blocks
;
2105 unsigned long cache
;
2106 unsigned long long array_size
;
2108 struct mdinfo
*sra
= NULL
;
2110 /* when reshaping a RAID0, the component_size might be zero.
2111 * So try to fix that up.
2113 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
2114 dprintf("Cannot get array information.\n");
2117 if (array
.level
== 0 && info
->component_size
== 0) {
2118 get_dev_size(fd
, NULL
, &array_size
);
2119 info
->component_size
= array_size
/ array
.raid_disks
;
2122 if (info
->reshape_active
) {
2123 int new_level
= info
->new_level
;
2124 info
->new_level
= UnSet
;
2125 if (info
->delta_disks
> 0)
2126 info
->array
.raid_disks
-= info
->delta_disks
;
2127 msg
= analyse_change(info
, &reshape
);
2128 info
->new_level
= new_level
;
2129 if (info
->delta_disks
> 0)
2130 info
->array
.raid_disks
+= info
->delta_disks
;
2132 /* Make sure the array isn't read-only */
2133 ioctl(fd
, RESTART_ARRAY_RW
, 0);
2135 msg
= analyse_change(info
, &reshape
);
2137 fprintf(stderr
, Name
": %s\n", msg
);
2141 (reshape
.level
!= info
->array
.level
||
2142 reshape
.before
.layout
!= info
->array
.layout
||
2143 reshape
.before
.data_disks
+ reshape
.parity
2144 != info
->array
.raid_disks
- max(0, info
->delta_disks
))) {
2145 fprintf(stderr
, Name
": reshape info is not in native format -"
2146 " cannot continue.\n");
2150 if (st
->ss
->external
&& restart
&& (info
->reshape_progress
== 0)) {
2151 /* When reshape is restarted from '0', very begin of array
2152 * it is possible that for external metadata reshape and array
2153 * configuration doesn't happen.
2154 * Check if md has the same opinion, and reshape is restarted
2155 * from 0. If so, this is regular reshape start after reshape
2156 * switch in metadata to next array only.
2158 if ((verify_reshape_position(info
, reshape
.level
) >= 0) &&
2159 (info
->reshape_progress
== 0))
2163 /* reshape already started. just skip to monitoring the reshape */
2164 if (reshape
.backup_blocks
== 0)
2168 /* The container is frozen but the array may not be.
2169 * So freeze the array so spares don't get put to the wrong use
2170 * FIXME there should probably be a cleaner separation between
2171 * freeze_array and freeze_container.
2173 sysfs_freeze_array(info
);
2174 /* Check we have enough spares to not be degraded */
2176 for (dv
= devlist
; dv
; dv
=dv
->next
)
2178 spares_needed
= max(reshape
.before
.data_disks
,
2179 reshape
.after
.data_disks
)
2180 + reshape
.parity
- array
.raid_disks
;
2183 info
->new_level
> 1 && info
->array
.level
> 1 &&
2184 spares_needed
> info
->array
.spare_disks
+ added_disks
) {
2186 Name
": Need %d spare%s to avoid degraded array,"
2187 " and only have %d.\n"
2188 " Use --force to over-ride this check.\n",
2190 spares_needed
== 1 ? "" : "s",
2191 info
->array
.spare_disks
+ added_disks
);
2194 /* Check we have enough spares to not fail */
2195 spares_needed
= max(reshape
.before
.data_disks
,
2196 reshape
.after
.data_disks
)
2198 if ((info
->new_level
> 1 || info
->new_level
== 0) &&
2199 spares_needed
> info
->array
.spare_disks
+added_disks
) {
2201 Name
": Need %d spare%s to create working array,"
2202 " and only have %d.\n",
2204 spares_needed
== 1 ? "" : "s",
2205 info
->array
.spare_disks
+ added_disks
);
2209 if (reshape
.level
!= array
.level
) {
2210 char *c
= map_num(pers
, reshape
.level
);
2215 err
= sysfs_set_str(info
, NULL
, "level", c
);
2218 fprintf(stderr
, Name
": %s: could not set level to %s\n",
2221 (info
->array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2222 fprintf(stderr
, " Bitmap must be removed"
2223 " before level can be changed\n");
2227 fprintf(stderr
, Name
": level of %s changed to %s\n",
2229 orig_level
= array
.level
;
2230 sysfs_freeze_array(info
);
2232 if (reshape
.level
> 0 && st
->ss
->external
) {
2233 /* make sure mdmon is aware of the new level */
2234 if (mdmon_running(st
->container_dev
))
2235 flush_mdmon(container
);
2237 if (!mdmon_running(st
->container_dev
))
2238 start_mdmon(st
->container_dev
);
2239 ping_monitor(container
);
2240 if (mdmon_running(st
->container_dev
) &&
2241 st
->update_tail
== NULL
)
2242 st
->update_tail
= &st
->updates
;
2245 /* ->reshape_super might have chosen some spares from the
2246 * container that it wants to be part of the new array.
2247 * We can collect them with ->container_content and give
2248 * them to the kernel.
2250 if (st
->ss
->reshape_super
&& st
->ss
->container_content
) {
2251 char *subarray
= strchr(info
->text_version
+1, '/')+1;
2252 struct mdinfo
*info2
=
2253 st
->ss
->container_content(st
, subarray
);
2257 sysfs_init(info2
, fd
, st
->devnum
);
2258 /* When increasing number of devices, we need to set
2259 * new raid_disks before adding these, or they might
2262 if (reshape
.backup_blocks
&&
2263 reshape
.after
.data_disks
> reshape
.before
.data_disks
)
2264 subarray_set_num(container
, info2
, "raid_disks",
2265 reshape
.after
.data_disks
+
2267 for (d
= info2
->devs
; d
; d
= d
->next
) {
2268 if (d
->disk
.state
== 0 &&
2269 d
->disk
.raid_disk
>= 0) {
2270 /* This is a spare that wants to
2271 * be part of the array.
2273 add_disk(fd
, st
, info2
, d
);
2279 /* We might have been given some devices to add to the
2280 * array. Now that the array has been changed to the right
2281 * level and frozen, we can safely add them.
2284 Manage_subdevs(devname
, fd
, devlist
, !quiet
,
2287 if (reshape
.backup_blocks
== 0) {
2288 /* No restriping needed, but we might need to impose
2289 * some more changes: layout, raid_disks, chunk_size
2291 /* read current array info */
2292 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) != 0) {
2293 dprintf("Cannot get array information.\n");
2296 /* compare current array info with new values and if
2297 * it is different update them to new */
2298 if (info
->new_layout
!= UnSet
&&
2299 info
->new_layout
!= array
.layout
) {
2300 array
.layout
= info
->new_layout
;
2301 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2302 fprintf(stderr
, Name
": failed to set new layout\n");
2305 printf("layout for %s set to %d\n",
2306 devname
, array
.layout
);
2308 if (info
->delta_disks
!= UnSet
&&
2309 info
->delta_disks
!= 0 &&
2310 array
.raid_disks
!= (info
->array
.raid_disks
+ info
->delta_disks
)) {
2311 array
.raid_disks
+= info
->delta_disks
;
2312 if (ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2313 fprintf(stderr
, Name
": failed to set raid disks\n");
2315 } else if (!quiet
) {
2316 printf("raid_disks for %s set to %d\n",
2317 devname
, array
.raid_disks
);
2320 if (info
->new_chunk
!= 0 &&
2321 info
->new_chunk
!= array
.chunk_size
) {
2322 if (sysfs_set_num(info
, NULL
,
2323 "chunk_size", info
->new_chunk
) != 0) {
2324 fprintf(stderr
, Name
": failed to set chunk size\n");
2327 printf("chunk size for %s set to %d\n",
2328 devname
, array
.chunk_size
);
2335 * There are three possibilities.
2336 * 1/ The array will shrink.
2337 * We need to ensure the reshape will pause before reaching
2338 * the 'critical section'. We also need to fork and wait for
2339 * that to happen. When it does we
2340 * suspend/backup/complete/unfreeze
2342 * 2/ The array will not change size.
2343 * This requires that we keep a backup of a sliding window
2344 * so that we can restore data after a crash. So we need
2345 * to fork and monitor progress.
2346 * In future we will allow the data_offset to change, so
2347 * a sliding backup becomes unnecessary.
2349 * 3/ The array will grow. This is relatively easy.
2350 * However the kernel's restripe routines will cheerfully
2351 * overwrite some early data before it is safe. So we
2352 * need to make a backup of the early parts of the array
2353 * and be ready to restore it if rebuild aborts very early.
2354 * For externally managed metadata, we still need a forked
2355 * child to monitor the reshape and suspend IO over the region
2356 * that is being reshaped.
2358 * We backup data by writing it to one spare, or to a
2359 * file which was given on command line.
2361 * In each case, we first make sure that storage is available
2362 * for the required backup.
2364 * - request the shape change.
2365 * - fork to handle backup etc.
2368 /* Check that we can hold all the data */
2369 get_dev_size(fd
, NULL
, &array_size
);
2370 if (reshape
.new_size
< (array_size
/512)) {
2372 Name
": this change will reduce the size of the array.\n"
2373 " use --grow --array-size first to truncate array.\n"
2374 " e.g. mdadm --grow %s --array-size %llu\n",
2375 devname
, reshape
.new_size
/2);
2379 sra
= sysfs_read(fd
, 0,
2380 GET_COMPONENT
|GET_DEVS
|GET_OFFSET
|GET_STATE
|GET_CHUNK
|
2383 fprintf(stderr
, Name
": %s: Cannot get array details from sysfs\n",
2388 /* Decide how many blocks (sectors) for a reshape
2389 * unit. The number we have so far is just a minimum
2391 blocks
= reshape
.backup_blocks
;
2392 if (reshape
.before
.data_disks
==
2393 reshape
.after
.data_disks
) {
2394 /* Make 'blocks' bigger for better throughput, but
2395 * not so big that we reject it below.
2396 * Try for 16 megabytes
2398 while (blocks
* 32 < sra
->component_size
&&
2402 fprintf(stderr
, Name
": Need to backup %luK of critical "
2403 "section..\n", blocks
/2);
2405 if (blocks
>= sra
->component_size
/2) {
2406 fprintf(stderr
, Name
": %s: Something wrong"
2407 " - reshape aborted\n",
2412 /* Now we need to open all these devices so we can read/write.
2414 nrdisks
= max(reshape
.before
.data_disks
,
2415 reshape
.after
.data_disks
) + reshape
.parity
2416 + sra
->array
.spare_disks
;
2417 fdlist
= malloc((1+nrdisks
) * sizeof(int));
2418 offsets
= malloc((1+nrdisks
) * sizeof(offsets
[0]));
2419 if (!fdlist
|| !offsets
) {
2420 fprintf(stderr
, Name
": malloc failed: grow aborted\n");
2424 odisks
= reshape
.before
.data_disks
+ reshape
.parity
;
2425 d
= reshape_prepare_fdlist(devname
, sra
, odisks
,
2426 nrdisks
, blocks
, backup_file
,
2431 if ((st
->ss
->manage_reshape
== NULL
) ||
2432 (st
->ss
->recover_backup
== NULL
)) {
2433 if (backup_file
== NULL
) {
2434 if (reshape
.after
.data_disks
<=
2435 reshape
.before
.data_disks
) {
2436 fprintf(stderr
, Name
": %s: Cannot grow - "
2437 "need backup-file\n", devname
);
2439 } else if (sra
->array
.spare_disks
== 0) {
2440 fprintf(stderr
, Name
": %s: Cannot grow - "
2441 "need a spare or backup-file to backup "
2442 "critical section\n", devname
);
2446 if (!reshape_open_backup_file(backup_file
, fd
, devname
,
2448 fdlist
+d
, offsets
+d
,
2456 /* lastly, check that the internal stripe cache is
2457 * large enough, or it won't work.
2458 * It must hold at least 4 stripes of the larger
2461 cache
= max(info
->array
.chunk_size
, info
->new_chunk
);
2462 cache
*= 4; /* 4 stripes minimum */
2463 cache
/= 512; /* convert to sectors */
2464 disks
= min(reshape
.before
.data_disks
, reshape
.after
.data_disks
);
2465 /* make sure there is room for 'blocks' with a bit to spare */
2466 if (cache
< 16 + blocks
/ disks
)
2467 cache
= 16 + blocks
/ disks
;
2468 cache
/= (4096/512); /* Covert from sectors to pages */
2470 if (sra
->cache_size
< cache
)
2471 subarray_set_num(container
, sra
, "stripe_cache_size",
2474 /* Right, everything seems fine. Let's kick things off.
2475 * If only changing raid_disks, use ioctl, else use
2480 sra
->new_chunk
= info
->new_chunk
;
2483 /* for external metadata checkpoint saved by mdmon can be lost
2484 * or missed /due to e.g. crash/. Check if md is not during
2485 * restart farther than metadata points to.
2486 * If so, this means metadata information is obsolete.
2488 if (st
->ss
->external
)
2489 verify_reshape_position(info
, reshape
.level
);
2490 sra
->reshape_progress
= info
->reshape_progress
;
2492 sra
->reshape_progress
= 0;
2493 if (reshape
.after
.data_disks
< reshape
.before
.data_disks
)
2494 /* start from the end of the new array */
2495 sra
->reshape_progress
= (sra
->component_size
2496 * reshape
.after
.data_disks
);
2499 if (info
->array
.chunk_size
== info
->new_chunk
&&
2500 reshape
.before
.layout
== reshape
.after
.layout
&&
2501 st
->ss
->external
== 0) {
2502 /* use SET_ARRAY_INFO but only if reshape hasn't started */
2503 ioctl(fd
, GET_ARRAY_INFO
, &array
);
2504 array
.raid_disks
= reshape
.after
.data_disks
+ reshape
.parity
;
2506 ioctl(fd
, SET_ARRAY_INFO
, &array
) != 0) {
2510 Name
": Cannot set device shape for %s: %s\n",
2511 devname
, strerror(errno
));
2514 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2516 " Bitmap must be removed before"
2517 " shape can be changed\n");
2521 } else if (!restart
) {
2522 /* set them all just in case some old 'new_*' value
2523 * persists from some earlier problem.
2526 if (sysfs_set_num(sra
, NULL
, "chunk_size", info
->new_chunk
) < 0)
2528 if (!err
&& sysfs_set_num(sra
, NULL
, "layout",
2529 reshape
.after
.layout
) < 0)
2531 if (!err
&& subarray_set_num(container
, sra
, "raid_disks",
2532 reshape
.after
.data_disks
+
2533 reshape
.parity
) < 0)
2536 fprintf(stderr
, Name
": Cannot set device shape for %s\n",
2540 (array
.state
& (1<<MD_SB_BITMAP_PRESENT
)))
2542 " Bitmap must be removed before"
2543 " shape can be changed\n");
2548 err
= start_reshape(sra
, restart
, reshape
.before
.data_disks
,
2549 reshape
.after
.data_disks
);
2552 Name
": Cannot %s reshape for %s\n",
2553 restart
? "continue" : "start",
2558 sysfs_set_str(sra
, NULL
, "array_state", "active");
2559 if (freeze_reshape
) {
2563 fprintf(stderr
, Name
": Reshape has to be continued from"
2564 " location %llu when root filesystem has been mounted.\n",
2565 sra
->reshape_progress
);
2569 /* Now we just need to kick off the reshape and watch, while
2570 * handling backups of the data...
2571 * This is all done by a forked background process.
2573 switch(forked
? 0 : fork()) {
2575 fprintf(stderr
, Name
": Cannot run child to monitor reshape: %s\n",
2590 if (check_env("MDADM_GROW_VERIFY"))
2591 fd
= open(devname
, O_RDONLY
| O_DIRECT
);
2594 mlockall(MCL_FUTURE
);
2596 if (st
->ss
->external
) {
2597 /* metadata handler takes it from here */
2598 done
= st
->ss
->manage_reshape(
2599 fd
, sra
, &reshape
, st
, blocks
,
2601 d
- odisks
, fdlist
+odisks
,
2604 done
= child_monitor(
2605 fd
, sra
, &reshape
, st
, blocks
,
2607 d
- odisks
, fdlist
+odisks
,
2613 if (backup_file
&& done
)
2614 unlink(backup_file
);
2620 if (!st
->ss
->external
&&
2621 !(reshape
.before
.data_disks
!= reshape
.after
.data_disks
2622 && info
->custom_array_size
) &&
2623 info
->new_level
== reshape
.level
&&
2625 /* no need to wait for the reshape to finish as
2626 * there is nothing more to do.
2633 if (st
->ss
->external
) {
2634 /* Re-load the metadata as much could have changed */
2635 int cfd
= open_dev(st
->container_dev
);
2637 flush_mdmon(container
);
2638 st
->ss
->free_super(st
);
2639 st
->ss
->load_container(st
, cfd
, container
);
2644 /* set new array size if required customer_array_size is used
2647 if (reshape
.before
.data_disks
!=
2648 reshape
.after
.data_disks
&&
2649 info
->custom_array_size
)
2650 set_array_size(st
, info
, info
->text_version
);
2652 if (info
->new_level
!= reshape
.level
) {
2654 c
= map_num(pers
, info
->new_level
);
2656 err
= sysfs_set_str(sra
, NULL
, "level", c
);
2658 fprintf(stderr
, Name\
2659 ": %s: could not set level "
2660 "to %s\n", devname
, c
);
2662 if (info
->new_level
== 0)
2663 st
->update_tail
= NULL
;
2675 if (orig_level
!= UnSet
&& sra
) {
2676 c
= map_num(pers
, orig_level
);
2677 if (c
&& sysfs_set_str(sra
, NULL
, "level", c
) == 0)
2678 fprintf(stderr
, Name
": aborting level change\n");
2686 /* mdfd handle is passed to be closed in child process (after fork).
2688 int reshape_container(char *container
, char *devname
,
2690 struct supertype
*st
,
2691 struct mdinfo
*info
,
2694 int quiet
, int restart
, int freeze_reshape
)
2696 struct mdinfo
*cc
= NULL
;
2698 int last_devnum
= -1;
2700 /* component_size is not meaningful for a container,
2701 * so pass '-1' meaning 'no change'
2704 reshape_super(st
, -1, info
->new_level
,
2705 info
->new_layout
, info
->new_chunk
,
2706 info
->array
.raid_disks
, info
->delta_disks
,
2707 backup_file
, devname
, APPLY_METADATA_CHANGES
,
2715 /* ping monitor to be sure that update is on disk
2717 ping_monitor(container
);
2720 case -1: /* error */
2721 perror("Cannot fork to complete reshape\n");
2724 default: /* parent */
2725 if (!freeze_reshape
)
2726 printf(Name
": multi-array reshape continues"
2727 " in background\n");
2734 /* close unused handle in child process
2740 /* For each member array with reshape_active,
2741 * we need to perform the reshape.
2742 * We pick the first array that needs reshaping and
2743 * reshape it. reshape_array() will re-read the metadata
2744 * so the next time through a different array should be
2745 * ready for reshape.
2746 * It is possible that the 'different' array will not
2747 * be assembled yet. In that case we simple exit.
2748 * When it is assembled, the mdadm which assembles it
2749 * will take over the reshape.
2751 struct mdinfo
*content
;
2753 struct mdstat_ent
*mdstat
;
2758 cc
= st
->ss
->container_content(st
, NULL
);
2760 for (content
= cc
; content
; content
= content
->next
) {
2762 if (!content
->reshape_active
)
2765 subarray
= strchr(content
->text_version
+1, '/')+1;
2766 mdstat
= mdstat_by_subdev(subarray
,
2767 devname2devnum(container
));
2770 if (mdstat
->active
== 0) {
2771 fprintf(stderr
, Name
": Skipping inactive "
2772 "array md%i.\n", mdstat
->devnum
);
2773 free_mdstat(mdstat
);
2782 adev
= map_dev(dev2major(mdstat
->devnum
),
2783 dev2minor(mdstat
->devnum
),
2786 adev
= content
->text_version
;
2788 fd
= open_dev(mdstat
->devnum
);
2790 printf(Name
": Device %s cannot be opened for reshape.",
2795 if (last_devnum
== mdstat
->devnum
) {
2796 /* Do not allow for multiple reshape_array() calls for
2798 * It can happen when reshape_array() returns without
2799 * error, when reshape is not finished (wrong reshape
2800 * starting/continuation conditions). Mdmon doesn't
2801 * switch to next array in container and reentry
2802 * conditions for the same array occur.
2803 * This is possibly interim until the behaviour of
2804 * reshape_array is resolved().
2806 printf(Name
": Multiple reshape execution detected for "
2807 "device %s.", adev
);
2811 last_devnum
= mdstat
->devnum
;
2813 sysfs_init(content
, fd
, mdstat
->devnum
);
2815 if (mdmon_running(devname2devnum(container
)))
2816 flush_mdmon(container
);
2818 rv
= reshape_array(container
, fd
, adev
, st
,
2819 content
, force
, NULL
,
2820 backup_file
, quiet
, 1, restart
,
2824 if (freeze_reshape
) {
2833 if (mdmon_running(devname2devnum(container
)))
2834 flush_mdmon(container
);
2843 * We run a child process in the background which performs the following
2845 * - wait for resync to reach a certain point
2846 * - suspend io to the following section
2847 * - backup that section
2848 * - allow resync to proceed further
2850 * - discard the backup.
2852 * When are combined in slightly different ways in the three cases.
2854 * - suspend/backup/allow/wait/resume/discard
2856 * - allow/wait/suspend/backup/allow/wait/resume/discard
2858 * - wait/resume/discard/suspend/backup/allow
2860 * suspend/backup/allow always come together
2861 * wait/resume/discard do too.
2862 * For the same-size case we have two backups to improve flow.
2866 int progress_reshape(struct mdinfo
*info
, struct reshape
*reshape
,
2867 unsigned long long backup_point
,
2868 unsigned long long wait_point
,
2869 unsigned long long *suspend_point
,
2870 unsigned long long *reshape_completed
)
2872 /* This function is called repeatedly by the reshape manager.
2873 * It determines how much progress can safely be made and allows
2875 * - 'info' identifies the array and particularly records in
2876 * ->reshape_progress the metadata's knowledge of progress
2877 * This is a sector offset from the start of the array
2878 * of the next array block to be relocated. This number
2879 * may increase from 0 or decrease from array_size, depending
2880 * on the type of reshape that is happening.
2881 * Note that in contrast, 'sync_completed' is a block count of the
2882 * reshape so far. It gives the distance between the start point
2883 * (head or tail of device) and the next place that data will be
2884 * written. It always increases.
2885 * - 'reshape' is the structure created by analyse_change
2886 * - 'backup_point' shows how much the metadata manager has backed-up
2887 * data. For reshapes with increasing progress, it is the next address
2888 * to be backed up, previous addresses have been backed-up. For
2889 * decreasing progress, it is the earliest address that has been
2890 * backed up - later address are also backed up.
2891 * So addresses between reshape_progress and backup_point are
2892 * backed up providing those are in the 'correct' order.
2893 * - 'wait_point' is an array address. When reshape_completed
2894 * passes this point, progress_reshape should return. It might
2895 * return earlier if it determines that ->reshape_progress needs
2896 * to be updated or further backup is needed.
2897 * - suspend_point is maintained by progress_reshape and the caller
2898 * should not touch it except to initialise to zero.
2899 * It is an array address and it only increases in 2.6.37 and earlier.
2900 * This makes it difficult to handle reducing reshapes with
2901 * external metadata.
2902 * However: it is similar to backup_point in that it records the
2903 * other end of a suspended region from reshape_progress.
2904 * it is moved to extend the region that is safe to backup and/or
2906 * - reshape_completed is read from sysfs and returned. The caller
2907 * should copy this into ->reshape_progress when it has reason to
2908 * believe that the metadata knows this, and any backup outside this
2912 * 1 if more data from backup_point - but only as far as suspend_point,
2913 * should be backed up
2914 * 0 if things are progressing smoothly
2915 * -1 if the reshape is finished because it is all done,
2916 * -2 if the reshape is finished due to an error.
2919 int advancing
= (reshape
->after
.data_disks
2920 >= reshape
->before
.data_disks
);
2921 unsigned long long need_backup
; /* All data between start of array and
2922 * here will at some point need to
2925 unsigned long long read_offset
, write_offset
;
2926 unsigned long long write_range
;
2927 unsigned long long max_progress
, target
, completed
;
2928 unsigned long long array_size
= (info
->component_size
2929 * reshape
->before
.data_disks
);
2933 /* First, we unsuspend any region that is now known to be safe.
2934 * If suspend_point is on the 'wrong' side of reshape_progress, then
2935 * we don't have or need suspension at the moment. This is true for
2936 * native metadata when we don't need to back-up.
2939 if (info
->reshape_progress
<= *suspend_point
)
2940 sysfs_set_num(info
, NULL
, "suspend_lo",
2941 info
->reshape_progress
);
2943 /* Note: this won't work in 2.6.37 and before.
2944 * Something somewhere should make sure we don't need it!
2946 if (info
->reshape_progress
>= *suspend_point
)
2947 sysfs_set_num(info
, NULL
, "suspend_hi",
2948 info
->reshape_progress
);
2951 /* Now work out how far it is safe to progress.
2952 * If the read_offset for ->reshape_progress is less than
2953 * 'blocks' beyond the write_offset, we can only progress as far
2955 * Otherwise we can progress until the write_offset for the new location
2956 * reaches (within 'blocks' of) the read_offset at the current location.
2957 * However that region must be suspended unless we are using native
2959 * If we need to suspend more, we limit it to 128M per device, which is
2960 * rather arbitrary and should be some time-based calculation.
2962 read_offset
= info
->reshape_progress
/ reshape
->before
.data_disks
;
2963 write_offset
= info
->reshape_progress
/ reshape
->after
.data_disks
;
2964 write_range
= info
->new_chunk
/512;
2965 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
)
2966 need_backup
= array_size
;
2968 need_backup
= reshape
->backup_blocks
;
2970 if (read_offset
< write_offset
+ write_range
)
2971 max_progress
= backup_point
;
2975 reshape
->after
.data_disks
;
2977 if (read_offset
> write_offset
- write_range
)
2978 /* Can only progress as far as has been backed up,
2979 * which must be suspended */
2980 max_progress
= backup_point
;
2981 else if (info
->reshape_progress
<= need_backup
)
2982 max_progress
= backup_point
;
2984 if (info
->array
.major_version
>= 0)
2985 /* Can progress until backup is needed */
2986 max_progress
= need_backup
;
2988 /* Can progress until metadata update is required */
2991 reshape
->after
.data_disks
;
2992 /* but data must be suspended */
2993 if (max_progress
< *suspend_point
)
2994 max_progress
= *suspend_point
;
2999 /* We know it is safe to progress to 'max_progress' providing
3000 * it is suspended or we are using native metadata.
3001 * Consider extending suspend_point 128M per device if it
3002 * is less than 64M per device beyond reshape_progress.
3003 * But always do a multiple of 'blocks'
3004 * FIXME this is too big - it takes to long to complete
3007 target
= 64*1024*2 * min(reshape
->before
.data_disks
,
3008 reshape
->after
.data_disks
);
3009 target
/= reshape
->backup_blocks
;
3012 target
*= reshape
->backup_blocks
;
3014 /* For externally managed metadata we always need to suspend IO to
3015 * the area being reshaped so we regularly push suspend_point forward.
3016 * For native metadata we only need the suspend if we are going to do
3020 if ((need_backup
> info
->reshape_progress
3021 || info
->array
.major_version
< 0) &&
3022 *suspend_point
< info
->reshape_progress
+ target
) {
3023 if (need_backup
< *suspend_point
+ 2 * target
)
3024 *suspend_point
= need_backup
;
3025 else if (*suspend_point
+ 2 * target
< array_size
)
3026 *suspend_point
+= 2 * target
;
3028 *suspend_point
= array_size
;
3029 sysfs_set_num(info
, NULL
, "suspend_hi", *suspend_point
);
3030 if (max_progress
> *suspend_point
)
3031 max_progress
= *suspend_point
;
3034 if (info
->array
.major_version
>= 0) {
3035 /* Only need to suspend when about to backup */
3036 if (info
->reshape_progress
< need_backup
* 2 &&
3037 *suspend_point
> 0) {
3039 sysfs_set_num(info
, NULL
, "suspend_lo", 0);
3040 sysfs_set_num(info
, NULL
, "suspend_hi", need_backup
);
3043 /* Need to suspend continually */
3044 if (info
->reshape_progress
< *suspend_point
)
3045 *suspend_point
= info
->reshape_progress
;
3046 if (*suspend_point
+ target
< info
->reshape_progress
)
3047 /* No need to move suspend region yet */;
3049 if (*suspend_point
>= 2 * target
)
3050 *suspend_point
-= 2 * target
;
3053 sysfs_set_num(info
, NULL
, "suspend_lo",
3056 if (max_progress
< *suspend_point
)
3057 max_progress
= *suspend_point
;
3061 /* now set sync_max to allow that progress. sync_max, like
3062 * sync_completed is a count of sectors written per device, so
3063 * we find the difference between max_progress and the start point,
3064 * and divide that by after.data_disks to get a sync_max
3066 * At the same time we convert wait_point to a similar number
3067 * for comparing against sync_completed.
3069 /* scale down max_progress to per_disk */
3070 max_progress
/= reshape
->after
.data_disks
;
3071 /* Round to chunk size as some kernels give an erroneously high number */
3072 max_progress
/= info
->new_chunk
/512;
3073 max_progress
*= info
->new_chunk
/512;
3074 /* And round to old chunk size as the kernel wants that */
3075 max_progress
/= info
->array
.chunk_size
/512;
3076 max_progress
*= info
->array
.chunk_size
/512;
3077 /* Limit progress to the whole device */
3078 if (max_progress
> info
->component_size
)
3079 max_progress
= info
->component_size
;
3080 wait_point
/= reshape
->after
.data_disks
;
3082 /* switch from 'device offset' to 'processed block count' */
3083 max_progress
= info
->component_size
- max_progress
;
3084 wait_point
= info
->component_size
- wait_point
;
3087 sysfs_set_num(info
, NULL
, "sync_max", max_progress
);
3089 /* Now wait. If we have already reached the point that we were
3090 * asked to wait to, don't wait at all, else wait for any change.
3091 * We need to select on 'sync_completed' as that is the place that
3092 * notifications happen, but we are really interested in
3093 * 'reshape_position'
3095 fd
= sysfs_get_fd(info
, NULL
, "sync_completed");
3097 goto check_progress
;
3099 if (sysfs_fd_get_ll(fd
, &completed
) < 0)
3100 goto check_progress
;
3102 while (completed
< max_progress
&& completed
< wait_point
) {
3103 /* Check that sync_action is still 'reshape' to avoid
3104 * waiting forever on a dead array
3108 if (sysfs_get_str(info
, NULL
, "sync_action",
3110 strncmp(action
, "reshape", 7) != 0)
3112 /* Some kernels reset 'sync_completed' to zero
3113 * before setting 'sync_action' to 'idle'.
3114 * So we need these extra tests.
3116 if (completed
== 0 && advancing
3117 && info
->reshape_progress
> 0)
3119 if (completed
== 0 && !advancing
3120 && info
->reshape_progress
< (info
->component_size
3121 * reshape
->after
.data_disks
))
3125 select(fd
+1, NULL
, NULL
, &rfds
, NULL
);
3126 if (sysfs_fd_get_ll(fd
, &completed
) < 0)
3127 goto check_progress
;
3129 /* Some kernels reset 'sync_completed' to zero,
3130 * we need to have real point we are in md
3133 completed
= max_progress
;
3135 /* some kernels can give an incorrectly high 'completed' number */
3136 completed
/= (info
->new_chunk
/512);
3137 completed
*= (info
->new_chunk
/512);
3138 /* Convert 'completed' back in to a 'progress' number */
3139 completed
*= reshape
->after
.data_disks
;
3141 completed
= info
->component_size
* reshape
->after
.data_disks
3144 *reshape_completed
= completed
;
3148 /* We return the need_backup flag. Caller will decide
3149 * how much - a multiple of ->backup_blocks up to *suspend_point
3152 return need_backup
> info
->reshape_progress
;
3154 return need_backup
>= info
->reshape_progress
;
3157 /* if we couldn't read a number from sync_completed, then
3158 * either the reshape did complete, or it aborted.
3159 * We can tell which by checking for 'none' in reshape_position.
3160 * If it did abort, then it might immediately restart if it
3161 * it was just a device failure that leaves us degraded but
3165 if (sysfs_get_str(info
, NULL
, "reshape_position", buf
, sizeof(buf
)) < 0
3166 || strncmp(buf
, "none", 4) != 0) {
3167 /* The abort might only be temporary. Wait up to 10
3168 * seconds for fd to contain a valid number again.
3174 while (fd
>= 0 && rv
< 0 && tv
.tv_sec
> 0) {
3178 if (select(fd
+1, NULL
, NULL
, &rfds
, &tv
) != 1)
3180 switch (sysfs_fd_get_ll(fd
, &completed
)) {
3182 /* all good again */
3185 case -2: /* read error - abort */
3192 return rv
; /* abort */
3194 /* Maybe racing with array shutdown - check state */
3197 if (sysfs_get_str(info
, NULL
, "array_state", buf
, sizeof(buf
)) < 0
3198 || strncmp(buf
, "inactive", 8) == 0
3199 || strncmp(buf
, "clear",5) == 0)
3200 return -2; /* abort */
3201 return -1; /* complete */
3205 /* FIXME return status is never checked */
3206 static int grow_backup(struct mdinfo
*sra
,
3207 unsigned long long offset
, /* per device */
3208 unsigned long stripes
, /* per device, in old chunks */
3209 int *sources
, unsigned long long *offsets
,
3210 int disks
, int chunk
, int level
, int layout
,
3211 int dests
, int *destfd
, unsigned long long *destoffsets
,
3212 int part
, int *degraded
,
3215 /* Backup 'blocks' sectors at 'offset' on each device of the array,
3216 * to storage 'destfd' (offset 'destoffsets'), after first
3217 * suspending IO. Then allow resync to continue
3218 * over the suspended section.
3219 * Use part 'part' of the backup-super-block.
3224 unsigned long long ll
;
3226 //printf("offset %llu\n", offset);
3232 /* Check that array hasn't become degraded, else we might backup the wrong data */
3233 if (sysfs_get_ll(sra
, NULL
, "degraded", &ll
) < 0)
3234 return -1; /* FIXME this error is ignored */
3235 new_degraded
= (int)ll
;
3236 if (new_degraded
!= *degraded
) {
3237 /* check each device to ensure it is still working */
3239 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
3240 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
3242 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
3244 if (sysfs_get_str(sra
, sd
, "state", sbuf
, 20) < 0 ||
3245 strstr(sbuf
, "faulty") ||
3246 strstr(sbuf
, "in_sync") == NULL
) {
3247 /* this device is dead */
3248 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
3249 if (sd
->disk
.raid_disk
>= 0 &&
3250 sources
[sd
->disk
.raid_disk
] >= 0) {
3251 close(sources
[sd
->disk
.raid_disk
]);
3252 sources
[sd
->disk
.raid_disk
] = -1;
3257 *degraded
= new_degraded
;
3260 bsb
.arraystart2
= __cpu_to_le64(offset
* odata
);
3261 bsb
.length2
= __cpu_to_le64(stripes
* (chunk
/512) * odata
);
3263 bsb
.arraystart
= __cpu_to_le64(offset
* odata
);
3264 bsb
.length
= __cpu_to_le64(stripes
* (chunk
/512) * odata
);
3267 bsb
.magic
[15] = '2';
3268 for (i
= 0; i
< dests
; i
++)
3270 lseek64(destfd
[i
], destoffsets
[i
] + __le64_to_cpu(bsb
.devstart2
)*512, 0);
3272 lseek64(destfd
[i
], destoffsets
[i
], 0);
3274 rv
= save_stripes(sources
, offsets
,
3275 disks
, chunk
, level
, layout
,
3277 offset
*512*odata
, stripes
* chunk
* odata
,
3282 bsb
.mtime
= __cpu_to_le64(time(0));
3283 for (i
= 0; i
< dests
; i
++) {
3284 bsb
.devstart
= __cpu_to_le64(destoffsets
[i
]/512);
3286 bsb
.sb_csum
= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
));
3287 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0)
3288 bsb
.sb_csum2
= bsb_csum((char*)&bsb
,
3289 ((char*)&bsb
.sb_csum2
)-((char*)&bsb
));
3292 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
] - 4096, 0)
3293 != destoffsets
[i
] - 4096)
3295 if (write(destfd
[i
], &bsb
, 512) != 512)
3297 if (destoffsets
[i
] > 4096) {
3298 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
]+stripes
*chunk
*odata
, 0) !=
3299 destoffsets
[i
]+stripes
*chunk
*odata
)
3301 if (write(destfd
[i
], &bsb
, 512) != 512)
3311 /* in 2.6.30, the value reported by sync_completed can be
3312 * less that it should be by one stripe.
3313 * This only happens when reshape hits sync_max and pauses.
3314 * So allow wait_backup to either extent sync_max further
3315 * than strictly necessary, or return before the
3316 * sync has got quite as far as we would really like.
3317 * This is what 'blocks2' is for.
3318 * The various caller give appropriate values so that
3321 /* FIXME return value is often ignored */
3322 static int forget_backup(int dests
, int *destfd
,
3323 unsigned long long *destoffsets
,
3327 * Erase backup 'part' (which is 0 or 1)
3333 bsb
.arraystart2
= __cpu_to_le64(0);
3334 bsb
.length2
= __cpu_to_le64(0);
3336 bsb
.arraystart
= __cpu_to_le64(0);
3337 bsb
.length
= __cpu_to_le64(0);
3339 bsb
.mtime
= __cpu_to_le64(time(0));
3341 for (i
= 0; i
< dests
; i
++) {
3342 bsb
.devstart
= __cpu_to_le64(destoffsets
[i
]/512);
3343 bsb
.sb_csum
= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
));
3344 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0)
3345 bsb
.sb_csum2
= bsb_csum((char*)&bsb
,
3346 ((char*)&bsb
.sb_csum2
)-((char*)&bsb
));
3347 if ((unsigned long long)lseek64(destfd
[i
], destoffsets
[i
]-4096, 0) !=
3348 destoffsets
[i
]-4096)
3351 write(destfd
[i
], &bsb
, 512) != 512)
3358 static void fail(char *msg
)
3361 rv
= (write(2, msg
, strlen(msg
)) != (int)strlen(msg
));
3362 rv
|= (write(2, "\n", 1) != 1);
3366 static char *abuf
, *bbuf
;
3367 static unsigned long long abuflen
;
3368 static void validate(int afd
, int bfd
, unsigned long long offset
)
3370 /* check that the data in the backup against the array.
3371 * This is only used for regression testing and should not
3372 * be used while the array is active
3376 lseek64(bfd
, offset
- 4096, 0);
3377 if (read(bfd
, &bsb2
, 512) != 512)
3378 fail("cannot read bsb");
3379 if (bsb2
.sb_csum
!= bsb_csum((char*)&bsb2
,
3380 ((char*)&bsb2
.sb_csum
)-((char*)&bsb2
)))
3381 fail("first csum bad");
3382 if (memcmp(bsb2
.magic
, "md_backup_data", 14) != 0)
3383 fail("magic is bad");
3384 if (memcmp(bsb2
.magic
, "md_backup_data-2", 16) == 0 &&
3385 bsb2
.sb_csum2
!= bsb_csum((char*)&bsb2
,
3386 ((char*)&bsb2
.sb_csum2
)-((char*)&bsb2
)))
3387 fail("second csum bad");
3389 if (__le64_to_cpu(bsb2
.devstart
)*512 != offset
)
3390 fail("devstart is wrong");
3393 unsigned long long len
= __le64_to_cpu(bsb2
.length
)*512;
3395 if (abuflen
< len
) {
3399 if (posix_memalign((void**)&abuf
, 4096, abuflen
) ||
3400 posix_memalign((void**)&bbuf
, 4096, abuflen
)) {
3402 /* just stop validating on mem-alloc failure */
3407 lseek64(bfd
, offset
, 0);
3408 if ((unsigned long long)read(bfd
, bbuf
, len
) != len
) {
3409 //printf("len %llu\n", len);
3410 fail("read first backup failed");
3412 lseek64(afd
, __le64_to_cpu(bsb2
.arraystart
)*512, 0);
3413 if ((unsigned long long)read(afd
, abuf
, len
) != len
)
3414 fail("read first from array failed");
3415 if (memcmp(bbuf
, abuf
, len
) != 0) {
3418 printf("offset=%llu len=%llu\n",
3419 (unsigned long long)__le64_to_cpu(bsb2
.arraystart
)*512, len
);
3420 for (i
=0; i
<len
; i
++)
3421 if (bbuf
[i
] != abuf
[i
]) {
3422 printf("first diff byte %d\n", i
);
3426 fail("data1 compare failed");
3430 unsigned long long len
= __le64_to_cpu(bsb2
.length2
)*512;
3432 if (abuflen
< len
) {
3436 abuf
= malloc(abuflen
);
3437 bbuf
= malloc(abuflen
);
3440 lseek64(bfd
, offset
+__le64_to_cpu(bsb2
.devstart2
)*512, 0);
3441 if ((unsigned long long)read(bfd
, bbuf
, len
) != len
)
3442 fail("read second backup failed");
3443 lseek64(afd
, __le64_to_cpu(bsb2
.arraystart2
)*512, 0);
3444 if ((unsigned long long)read(afd
, abuf
, len
) != len
)
3445 fail("read second from array failed");
3446 if (memcmp(bbuf
, abuf
, len
) != 0)
3447 fail("data2 compare failed");
3451 int child_monitor(int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
3452 struct supertype
*st
, unsigned long blocks
,
3453 int *fds
, unsigned long long *offsets
,
3454 int dests
, int *destfd
, unsigned long long *destoffsets
)
3456 /* Monitor a reshape where backup is being performed using
3457 * 'native' mechanism - either to a backup file, or
3458 * to some space in a spare.
3462 unsigned long long speed
;
3463 unsigned long long suspend_point
, array_size
;
3464 unsigned long long backup_point
, wait_point
;
3465 unsigned long long reshape_completed
;
3467 int increasing
= reshape
->after
.data_disks
>= reshape
->before
.data_disks
;
3468 int part
= 0; /* The next part of the backup area to fill. It may already
3469 * be full, so we need to check */
3470 int level
= reshape
->level
;
3471 int layout
= reshape
->before
.layout
;
3472 int data
= reshape
->before
.data_disks
;
3473 int disks
= reshape
->before
.data_disks
+ reshape
->parity
;
3474 int chunk
= sra
->array
.chunk_size
;
3476 unsigned long stripes
;
3479 /* set up the backup-super-block. This requires the
3480 * uuid from the array.
3482 /* Find a superblock */
3483 for (sd
= sra
->devs
; sd
; sd
= sd
->next
) {
3487 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
3489 dn
= map_dev(sd
->disk
.major
, sd
->disk
.minor
, 1);
3490 devfd
= dev_open(dn
, O_RDONLY
);
3493 ok
= st
->ss
->load_super(st
, devfd
, NULL
);
3499 fprintf(stderr
, Name
": Cannot find a superblock\n");
3503 memset(&bsb
, 0, 512);
3504 memcpy(bsb
.magic
, "md_backup_data-1", 16);
3505 st
->ss
->uuid_from_super(st
, uuid
);
3506 memcpy(bsb
.set_uuid
, uuid
, 16);
3507 bsb
.mtime
= __cpu_to_le64(time(0));
3508 bsb
.devstart2
= blocks
;
3510 stripes
= blocks
/ (sra
->array
.chunk_size
/512) /
3511 reshape
->before
.data_disks
;
3513 if (posix_memalign((void**)&buf
, 4096, disks
* chunk
))
3514 /* Don't start the 'reshape' */
3516 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
) {
3517 sysfs_get_ll(sra
, NULL
, "sync_speed_min", &speed
);
3518 sysfs_set_num(sra
, NULL
, "sync_speed_min", 200000);
3522 array_size
= sra
->component_size
* reshape
->after
.data_disks
;
3523 backup_point
= sra
->reshape_progress
;
3526 array_size
= sra
->component_size
* reshape
->before
.data_disks
;
3527 backup_point
= reshape
->backup_blocks
;
3528 suspend_point
= array_size
;
3534 /* Want to return as soon the oldest backup slot can
3535 * be released as that allows us to start backing up
3536 * some more, providing suspend_point has been
3537 * advanced, which it should have.
3540 wait_point
= array_size
;
3541 if (part
== 0 && __le64_to_cpu(bsb
.length
) > 0)
3542 wait_point
= (__le64_to_cpu(bsb
.arraystart
) +
3543 __le64_to_cpu(bsb
.length
));
3544 if (part
== 1 && __le64_to_cpu(bsb
.length2
) > 0)
3545 wait_point
= (__le64_to_cpu(bsb
.arraystart2
) +
3546 __le64_to_cpu(bsb
.length2
));
3549 if (part
== 0 && __le64_to_cpu(bsb
.length
) > 0)
3550 wait_point
= __le64_to_cpu(bsb
.arraystart
);
3551 if (part
== 1 && __le64_to_cpu(bsb
.length2
) > 0)
3552 wait_point
= __le64_to_cpu(bsb
.arraystart2
);
3555 rv
= progress_reshape(sra
, reshape
,
3556 backup_point
, wait_point
,
3557 &suspend_point
, &reshape_completed
);
3558 /* external metadata would need to ping_monitor here */
3559 sra
->reshape_progress
= reshape_completed
;
3561 /* Clear any backup region that is before 'here' */
3563 if (__le64_to_cpu(bsb
.length
) > 0 &&
3564 reshape_completed
>= (__le64_to_cpu(bsb
.arraystart
) +
3565 __le64_to_cpu(bsb
.length
)))
3566 forget_backup(dests
, destfd
,
3568 if (__le64_to_cpu(bsb
.length2
) > 0 &&
3569 reshape_completed
>= (__le64_to_cpu(bsb
.arraystart2
) +
3570 __le64_to_cpu(bsb
.length2
)))
3571 forget_backup(dests
, destfd
,
3574 if (__le64_to_cpu(bsb
.length
) > 0 &&
3575 reshape_completed
<= (__le64_to_cpu(bsb
.arraystart
)))
3576 forget_backup(dests
, destfd
,
3578 if (__le64_to_cpu(bsb
.length2
) > 0 &&
3579 reshape_completed
<= (__le64_to_cpu(bsb
.arraystart2
)))
3580 forget_backup(dests
, destfd
,
3589 if (rv
== 0 && increasing
&& !st
->ss
->external
) {
3590 /* No longer need to monitor this reshape */
3596 unsigned long long offset
;
3597 unsigned long actual_stripes
;
3598 /* Need to backup some data.
3599 * If 'part' is not used and the desired
3600 * backup size is suspended, do a backup,
3601 * then consider the next part.
3603 /* Check that 'part' is unused */
3604 if (part
== 0 && __le64_to_cpu(bsb
.length
) != 0)
3606 if (part
== 1 && __le64_to_cpu(bsb
.length2
) != 0)
3609 offset
= backup_point
/ data
;
3610 actual_stripes
= stripes
;
3612 if (offset
+ actual_stripes
* (chunk
/512) >
3613 sra
->component_size
)
3614 actual_stripes
= ((sra
->component_size
- offset
)
3616 if (offset
+ actual_stripes
* (chunk
/512) >
3620 if (offset
< actual_stripes
* (chunk
/512))
3621 actual_stripes
= offset
/ (chunk
/512);
3622 offset
-= actual_stripes
* (chunk
/512);
3623 if (offset
< suspend_point
/data
)
3626 if (actual_stripes
== 0)
3628 grow_backup(sra
, offset
, actual_stripes
,
3630 disks
, chunk
, level
, layout
,
3631 dests
, destfd
, destoffsets
,
3632 part
, °raded
, buf
);
3633 validate(afd
, destfd
[0], destoffsets
[0]);
3634 /* record where 'part' is up to */
3637 backup_point
+= actual_stripes
* (chunk
/512) * data
;
3639 backup_point
-= actual_stripes
* (chunk
/512) * data
;
3643 /* FIXME maybe call progress_reshape one more time instead */
3644 abort_reshape(sra
); /* remove any remaining suspension */
3645 if (reshape
->before
.data_disks
== reshape
->after
.data_disks
)
3646 sysfs_set_num(sra
, NULL
, "sync_speed_min", speed
);
3652 * If any spare contains md_back_data-1 which is recent wrt mtime,
3653 * write that data into the array and update the super blocks with
3654 * the new reshape_progress
3656 int Grow_restart(struct supertype
*st
, struct mdinfo
*info
, int *fdlist
, int cnt
,
3657 char *backup_file
, int verbose
)
3661 unsigned long long *offsets
;
3662 unsigned long long nstripe
, ostripe
;
3665 odata
= info
->array
.raid_disks
- info
->delta_disks
- 1;
3666 if (info
->array
.level
== 6) odata
--; /* number of data disks */
3667 ndata
= info
->array
.raid_disks
- 1;
3668 if (info
->new_level
== 6) ndata
--;
3670 old_disks
= info
->array
.raid_disks
- info
->delta_disks
;
3672 if (info
->delta_disks
<= 0)
3673 /* Didn't grow, so the backup file must have
3677 for (i
=old_disks
-(backup_file
?1:0); i
<cnt
; i
++) {
3678 struct mdinfo dinfo
;
3681 char *devname
, namebuf
[20];
3682 unsigned long long lo
, hi
;
3684 /* This was a spare and may have some saved data on it.
3685 * Load the superblock, find and load the
3686 * backup_super_block.
3687 * If either fail, go on to next device.
3688 * If the backup contains no new info, just return
3689 * else restore data and update all superblocks
3691 if (i
== old_disks
-1) {
3692 fd
= open(backup_file
, O_RDONLY
);
3694 fprintf(stderr
, Name
": backup file %s inaccessible: %s\n",
3695 backup_file
, strerror(errno
));
3698 devname
= backup_file
;
3703 if (st
->ss
->load_super(st
, fd
, NULL
))
3706 st
->ss
->getinfo_super(st
, &dinfo
, NULL
);
3707 st
->ss
->free_super(st
);
3710 (dinfo
.data_offset
+ dinfo
.component_size
- 8) <<9,
3712 fprintf(stderr
, Name
": Cannot seek on device %d\n", i
);
3713 continue; /* Cannot seek */
3715 sprintf(namebuf
, "device-%d", i
);
3718 if (read(fd
, &bsb
, sizeof(bsb
)) != sizeof(bsb
)) {
3720 fprintf(stderr
, Name
": Cannot read from %s\n", devname
);
3721 continue; /* Cannot read */
3723 if (memcmp(bsb
.magic
, "md_backup_data-1", 16) != 0 &&
3724 memcmp(bsb
.magic
, "md_backup_data-2", 16) != 0) {
3726 fprintf(stderr
, Name
": No backup metadata on %s\n", devname
);
3729 if (bsb
.sb_csum
!= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum
)-((char*)&bsb
))) {
3731 fprintf(stderr
, Name
": Bad backup-metadata checksum on %s\n", devname
);
3732 continue; /* bad checksum */
3734 if (memcmp(bsb
.magic
, "md_backup_data-2", 16) == 0 &&
3735 bsb
.sb_csum2
!= bsb_csum((char*)&bsb
, ((char*)&bsb
.sb_csum2
)-((char*)&bsb
))) {
3737 fprintf(stderr
, Name
": Bad backup-metadata checksum2 on %s\n", devname
);
3738 continue; /* Bad second checksum */
3740 if (memcmp(bsb
.set_uuid
,info
->uuid
, 16) != 0) {
3742 fprintf(stderr
, Name
": Wrong uuid on backup-metadata on %s\n", devname
);
3743 continue; /* Wrong uuid */
3746 /* array utime and backup-mtime should be updated at much the same time, but it seems that
3747 * sometimes they aren't... So allow considerable flexability in matching, and allow
3748 * this test to be overridden by an environment variable.
3750 if (info
->array
.utime
> (int)__le64_to_cpu(bsb
.mtime
) + 2*60*60 ||
3751 info
->array
.utime
< (int)__le64_to_cpu(bsb
.mtime
) - 10*60) {
3752 if (check_env("MDADM_GROW_ALLOW_OLD")) {
3753 fprintf(stderr
, Name
": accepting backup with timestamp %lu "
3754 "for array with timestamp %lu\n",
3755 (unsigned long)__le64_to_cpu(bsb
.mtime
),
3756 (unsigned long)info
->array
.utime
);
3759 fprintf(stderr
, Name
": too-old timestamp on "
3760 "backup-metadata on %s\n", devname
);
3761 continue; /* time stamp is too bad */
3765 if (bsb
.magic
[15] == '1') {
3766 if (bsb
.length
== 0)
3768 if (info
->delta_disks
>= 0) {
3769 /* reshape_progress is increasing */
3770 if (__le64_to_cpu(bsb
.arraystart
)
3771 + __le64_to_cpu(bsb
.length
)
3772 < info
->reshape_progress
) {
3775 fprintf(stderr
, Name
3776 ": backup-metadata found on %s but is not needed\n", devname
);
3777 continue; /* No new data here */
3780 /* reshape_progress is decreasing */
3781 if (__le64_to_cpu(bsb
.arraystart
) >=
3782 info
->reshape_progress
)
3783 goto nonew
; /* No new data here */
3786 if (bsb
.length
== 0 && bsb
.length2
== 0)
3788 if (info
->delta_disks
>= 0) {
3789 /* reshape_progress is increasing */
3790 if ((__le64_to_cpu(bsb
.arraystart
)
3791 + __le64_to_cpu(bsb
.length
)
3792 < info
->reshape_progress
)
3794 (__le64_to_cpu(bsb
.arraystart2
)
3795 + __le64_to_cpu(bsb
.length2
)
3796 < info
->reshape_progress
))
3797 goto nonew
; /* No new data here */
3799 /* reshape_progress is decreasing */
3800 if (__le64_to_cpu(bsb
.arraystart
) >=
3801 info
->reshape_progress
&&
3802 __le64_to_cpu(bsb
.arraystart2
) >=
3803 info
->reshape_progress
)
3804 goto nonew
; /* No new data here */
3807 if (lseek64(fd
, __le64_to_cpu(bsb
.devstart
)*512, 0)< 0) {
3810 fprintf(stderr
, Name
3811 ": Failed to verify secondary backup-metadata block on %s\n",
3813 continue; /* Cannot seek */
3815 /* There should be a duplicate backup superblock 4k before here */
3816 if (lseek64(fd
, -4096, 1) < 0 ||
3817 read(fd
, &bsb2
, sizeof(bsb2
)) != sizeof(bsb2
))
3818 goto second_fail
; /* Cannot find leading superblock */
3819 if (bsb
.magic
[15] == '1')
3820 bsbsize
= offsetof(struct mdp_backup_super
, pad1
);
3822 bsbsize
= offsetof(struct mdp_backup_super
, pad
);
3823 if (memcmp(&bsb2
, &bsb
, bsbsize
) != 0)
3824 goto second_fail
; /* Cannot find leading superblock */
3826 /* Now need the data offsets for all devices. */
3827 offsets
= malloc(sizeof(*offsets
)*info
->array
.raid_disks
);
3828 for(j
=0; j
<info
->array
.raid_disks
; j
++) {
3831 if (st
->ss
->load_super(st
, fdlist
[j
], NULL
))
3832 /* FIXME should be this be an error */
3834 st
->ss
->getinfo_super(st
, &dinfo
, NULL
);
3835 st
->ss
->free_super(st
);
3836 offsets
[j
] = dinfo
.data_offset
* 512;
3838 printf(Name
": restoring critical section\n");
3840 if (restore_stripes(fdlist
, offsets
,
3841 info
->array
.raid_disks
,
3845 fd
, __le64_to_cpu(bsb
.devstart
)*512,
3846 __le64_to_cpu(bsb
.arraystart
)*512,
3847 __le64_to_cpu(bsb
.length
)*512, NULL
)) {
3848 /* didn't succeed, so giveup */
3850 fprintf(stderr
, Name
": Error restoring backup from %s\n",
3856 if (bsb
.magic
[15] == '2' &&
3857 restore_stripes(fdlist
, offsets
,
3858 info
->array
.raid_disks
,
3862 fd
, __le64_to_cpu(bsb
.devstart
)*512 +
3863 __le64_to_cpu(bsb
.devstart2
)*512,
3864 __le64_to_cpu(bsb
.arraystart2
)*512,
3865 __le64_to_cpu(bsb
.length2
)*512, NULL
)) {
3866 /* didn't succeed, so giveup */
3868 fprintf(stderr
, Name
": Error restoring second backup from %s\n",
3876 /* Ok, so the data is restored. Let's update those superblocks. */
3880 lo
= __le64_to_cpu(bsb
.arraystart
);
3881 hi
= lo
+ __le64_to_cpu(bsb
.length
);
3883 if (bsb
.magic
[15] == '2' && bsb
.length2
) {
3884 unsigned long long lo1
, hi1
;
3885 lo1
= __le64_to_cpu(bsb
.arraystart2
);
3886 hi1
= lo1
+ __le64_to_cpu(bsb
.length2
);
3890 } else if (lo
< lo1
)
3896 (info
->reshape_progress
< lo
||
3897 info
->reshape_progress
> hi
))
3898 /* backup does not affect reshape_progress*/ ;
3899 else if (info
->delta_disks
>= 0) {
3900 info
->reshape_progress
= __le64_to_cpu(bsb
.arraystart
) +
3901 __le64_to_cpu(bsb
.length
);
3902 if (bsb
.magic
[15] == '2') {
3903 unsigned long long p2
= __le64_to_cpu(bsb
.arraystart2
) +
3904 __le64_to_cpu(bsb
.length2
);
3905 if (p2
> info
->reshape_progress
)
3906 info
->reshape_progress
= p2
;
3909 info
->reshape_progress
= __le64_to_cpu(bsb
.arraystart
);
3910 if (bsb
.magic
[15] == '2') {
3911 unsigned long long p2
= __le64_to_cpu(bsb
.arraystart2
);
3912 if (p2
< info
->reshape_progress
)
3913 info
->reshape_progress
= p2
;
3916 for (j
=0; j
<info
->array
.raid_disks
; j
++) {
3917 if (fdlist
[j
] < 0) continue;
3918 if (st
->ss
->load_super(st
, fdlist
[j
], NULL
))
3920 st
->ss
->getinfo_super(st
, &dinfo
, NULL
);
3921 dinfo
.reshape_progress
= info
->reshape_progress
;
3922 st
->ss
->update_super(st
, &dinfo
,
3923 "_reshape_progress",
3925 st
->ss
->store_super(st
, fdlist
[j
]);
3926 st
->ss
->free_super(st
);
3930 /* Didn't find any backup data, try to see if any
3933 if (info
->delta_disks
< 0) {
3934 /* When shrinking, the critical section is at the end.
3935 * So see if we are before the critical section.
3937 unsigned long long first_block
;
3938 nstripe
= ostripe
= 0;
3940 while (ostripe
>= nstripe
) {
3941 ostripe
+= info
->array
.chunk_size
/ 512;
3942 first_block
= ostripe
* odata
;
3943 nstripe
= first_block
/ ndata
/ (info
->new_chunk
/512) *
3944 (info
->new_chunk
/512);
3947 if (info
->reshape_progress
>= first_block
)
3950 if (info
->delta_disks
> 0) {
3951 /* See if we are beyond the critical section. */
3952 unsigned long long last_block
;
3953 nstripe
= ostripe
= 0;
3955 while (nstripe
>= ostripe
) {
3956 nstripe
+= info
->new_chunk
/ 512;
3957 last_block
= nstripe
* ndata
;
3958 ostripe
= last_block
/ odata
/ (info
->array
.chunk_size
/512) *
3959 (info
->array
.chunk_size
/512);
3962 if (info
->reshape_progress
>= last_block
)
3965 /* needed to recover critical section! */
3967 fprintf(stderr
, Name
": Failed to find backup of critical section\n");
3971 int Grow_continue_command(char *devname
, int fd
,
3972 char *backup_file
, int verbose
)
3975 struct supertype
*st
= NULL
;
3976 struct mdinfo
*content
= NULL
;
3977 struct mdinfo array
;
3978 char *subarray
= NULL
;
3979 struct mdinfo
*cc
= NULL
;
3980 struct mdstat_ent
*mdstat
= NULL
;
3985 dprintf("Grow continue from command line called for %s\n",
3988 st
= super_by_fd(fd
, &subarray
);
3989 if (!st
|| !st
->ss
) {
3991 Name
": Unable to determine metadata format for %s\n",
3995 dprintf("Grow continue is run for ");
3996 if (st
->ss
->external
== 0) {
3997 dprintf("native array (%s)\n", devname
);
3998 if (ioctl(fd
, GET_ARRAY_INFO
, &array
) < 0) {
3999 fprintf(stderr
, Name
": %s is not an active md array -"
4000 " aborting\n", devname
);
4002 goto Grow_continue_command_exit
;
4005 sysfs_init(content
, fd
, st
->devnum
);
4010 dprintf("subarray (%s)\n", subarray
);
4011 container_dev
= st
->container_dev
;
4012 cfd
= open_dev_excl(st
->container_dev
);
4014 container_dev
= st
->devnum
;
4016 cfd
= open_dev_excl(st
->devnum
);
4017 dprintf("container (%i)\n", container_dev
);
4021 fprintf(stderr
, Name
": Unable to open container "
4022 "for %s\n", devname
);
4024 goto Grow_continue_command_exit
;
4026 fmt_devname(buf
, container_dev
);
4028 /* find in container array under reshape
4030 ret_val
= st
->ss
->load_container(st
, cfd
, NULL
);
4033 Name
": Cannot read superblock for %s\n",
4036 goto Grow_continue_command_exit
;
4039 cc
= st
->ss
->container_content(st
, subarray
);
4040 for (content
= cc
; content
; content
= content
->next
) {
4042 int allow_reshape
= 1;
4044 if (content
->reshape_active
== 0)
4046 /* The decision about array or container wide
4047 * reshape is taken in Grow_continue based
4048 * content->reshape_active state, therefore we
4049 * need to check_reshape based on
4050 * reshape_active and subarray name
4052 if (content
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
))
4054 if (content
->reshape_active
== CONTAINER_RESHAPE
&&
4055 (content
->array
.state
4056 & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
)))
4059 if (!allow_reshape
) {
4060 fprintf(stderr
, Name
4061 ": cannot continue reshape of an array"
4062 " in container with unsupported"
4063 " metadata: %s(%s)\n",
4066 goto Grow_continue_command_exit
;
4069 array
= strchr(content
->text_version
+1, '/')+1;
4070 mdstat
= mdstat_by_subdev(array
, container_dev
);
4073 if (mdstat
->active
== 0) {
4074 fprintf(stderr
, Name
": Skipping inactive "
4075 "array md%i.\n", mdstat
->devnum
);
4076 free_mdstat(mdstat
);
4084 Name
": Unable to determine reshaped "
4085 "array for %s\n", devname
);
4087 goto Grow_continue_command_exit
;
4089 fd2
= open_dev(mdstat
->devnum
);
4091 fprintf(stderr
, Name
": cannot open (md%i)\n",
4094 goto Grow_continue_command_exit
;
4097 sysfs_init(content
, fd2
, mdstat
->devnum
);
4099 /* start mdmon in case it is not running
4101 if (!mdmon_running(container_dev
))
4102 start_mdmon(container_dev
);
4105 if (mdmon_running(container_dev
))
4106 st
->update_tail
= &st
->updates
;
4108 fprintf(stderr
, Name
": No mdmon found. "
4109 "Grow cannot continue.\n");
4111 goto Grow_continue_command_exit
;
4115 /* verify that array under reshape is started from
4118 if (verify_reshape_position(content
,
4119 map_name(pers
, mdstat
->level
)) < 0) {
4121 goto Grow_continue_command_exit
;
4126 ret_val
= Grow_continue(fd
, st
, content
, backup_file
, 0);
4128 Grow_continue_command_exit
:
4133 st
->ss
->free_super(st
);
4134 free_mdstat(mdstat
);
4141 int Grow_continue(int mdfd
, struct supertype
*st
, struct mdinfo
*info
,
4142 char *backup_file
, int freeze_reshape
)
4146 if (!info
->reshape_active
)
4149 if (st
->ss
->external
) {
4151 int cfd
= open_dev(st
->container_dev
);
4156 fmt_devname(container
, st
->container_dev
);
4157 st
->ss
->load_container(st
, cfd
, container
);
4159 ret_val
= reshape_container(container
, NULL
, mdfd
,
4160 st
, info
, 0, backup_file
,
4161 0, 1, freeze_reshape
);
4163 ret_val
= reshape_array(NULL
, mdfd
, "array", st
, info
, 1,
4164 NULL
, backup_file
, 0, 0, 1,