]>
Commit | Line | Data |
---|---|---|
e5329c37 NB |
1 | /* |
2 | * mdadm - manage Linux "md" devices aka RAID arrays. | |
3 | * | |
4f589ad0 | 4 | * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de> |
e5329c37 NB |
5 | * |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | * | |
21 | * Author: Neil Brown | |
22 | * Email: <neilb@cse.unsw.edu.au> | |
23 | * Paper: Neil Brown | |
24 | * School of Computer Science and Engineering | |
25 | * The University of New South Wales | |
26 | * Sydney, 2052 | |
27 | * Australia | |
28 | */ | |
29 | #include "mdadm.h" | |
30 | #include "dlink.h" | |
31 | ||
32 | #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN) | |
33 | #error no endian defined | |
34 | #endif | |
35 | #include "md_u.h" | |
36 | #include "md_p.h" | |
37 | ||
38 | int Grow_Add_device(char *devname, int fd, char *newdev) | |
39 | { | |
40 | /* Add a device to an active array. | |
41 | * Currently, just extend a linear array. | |
42 | * This requires writing a new superblock on the | |
43 | * new device, calling the kernel to add the device, | |
44 | * and if that succeeds, update the superblock on | |
45 | * all other devices. | |
46 | * This means that we need to *find* all other devices. | |
47 | */ | |
4b1ac34b NB |
48 | struct mdinfo info; |
49 | ||
e5329c37 NB |
50 | struct stat stb; |
51 | int nfd, fd2; | |
52 | int d, nd; | |
82d9eba6 | 53 | struct supertype *st = NULL; |
aba69144 | 54 | |
e5329c37 | 55 | |
4b1ac34b | 56 | if (ioctl(fd, GET_ARRAY_INFO, &info.array) < 0) { |
e5329c37 NB |
57 | fprintf(stderr, Name ": cannot get array info for %s\n", devname); |
58 | return 1; | |
59 | } | |
60 | ||
1686dc25 | 61 | st = super_by_fd(fd); |
82d9eba6 | 62 | if (!st) { |
f9ce90ba NB |
63 | fprintf(stderr, Name ": cannot handle arrays with superblock version %d\n", info.array.major_version); |
64 | return 1; | |
65 | } | |
66 | ||
4b1ac34b | 67 | if (info.array.level != -1) { |
e5329c37 NB |
68 | fprintf(stderr, Name ": can only add devices to linear arrays\n"); |
69 | return 1; | |
70 | } | |
71 | ||
6416d527 | 72 | nfd = open(newdev, O_RDWR|O_EXCL|O_DIRECT); |
e5329c37 NB |
73 | if (nfd < 0) { |
74 | fprintf(stderr, Name ": cannot open %s\n", newdev); | |
75 | return 1; | |
76 | } | |
77 | fstat(nfd, &stb); | |
78 | if ((stb.st_mode & S_IFMT) != S_IFBLK) { | |
79 | fprintf(stderr, Name ": %s is not a block device!\n", newdev); | |
80 | close(nfd); | |
81 | return 1; | |
82 | } | |
83 | /* now check out all the devices and make sure we can read the superblock */ | |
4b1ac34b | 84 | for (d=0 ; d < info.array.raid_disks ; d++) { |
e5329c37 NB |
85 | mdu_disk_info_t disk; |
86 | char *dv; | |
87 | ||
88 | disk.number = d; | |
89 | if (ioctl(fd, GET_DISK_INFO, &disk) < 0) { | |
90 | fprintf(stderr, Name ": cannot get device detail for device %d\n", | |
91 | d); | |
92 | return 1; | |
93 | } | |
16c6fa80 | 94 | dv = map_dev(disk.major, disk.minor, 1); |
e5329c37 NB |
95 | if (!dv) { |
96 | fprintf(stderr, Name ": cannot find device file for device %d\n", | |
97 | d); | |
98 | return 1; | |
99 | } | |
16c6fa80 | 100 | fd2 = dev_open(dv, O_RDWR); |
e5329c37 NB |
101 | if (!fd2) { |
102 | fprintf(stderr, Name ": cannot open device file %s\n", dv); | |
103 | return 1; | |
104 | } | |
3da92f27 NB |
105 | st->ss->free_super(st); |
106 | ||
107 | if (st->ss->load_super(st, fd2, NULL)) { | |
e5329c37 NB |
108 | fprintf(stderr, Name ": cannot find super block on %s\n", dv); |
109 | close(fd2); | |
110 | return 1; | |
111 | } | |
112 | close(fd2); | |
113 | } | |
114 | /* Ok, looks good. Lets update the superblock and write it out to | |
115 | * newdev. | |
116 | */ | |
aba69144 | 117 | |
4b1ac34b NB |
118 | info.disk.number = d; |
119 | info.disk.major = major(stb.st_rdev); | |
120 | info.disk.minor = minor(stb.st_rdev); | |
121 | info.disk.raid_disk = d; | |
122 | info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE); | |
3da92f27 | 123 | st->ss->update_super(st, &info, "linear-grow-new", newdev, |
f752781f | 124 | 0, 0, NULL); |
e5329c37 | 125 | |
3da92f27 | 126 | if (st->ss->store_super(st, nfd)) { |
f752781f NB |
127 | fprintf(stderr, Name ": Cannot store new superblock on %s\n", |
128 | newdev); | |
e5329c37 NB |
129 | close(nfd); |
130 | return 1; | |
131 | } | |
e5329c37 | 132 | close(nfd); |
4b1ac34b NB |
133 | |
134 | if (ioctl(fd, ADD_NEW_DISK, &info.disk) != 0) { | |
e5329c37 NB |
135 | fprintf(stderr, Name ": Cannot add new disk to this array\n"); |
136 | return 1; | |
137 | } | |
138 | /* Well, that seems to have worked. | |
139 | * Now go through and update all superblocks | |
140 | */ | |
141 | ||
4b1ac34b | 142 | if (ioctl(fd, GET_ARRAY_INFO, &info.array) < 0) { |
e5329c37 NB |
143 | fprintf(stderr, Name ": cannot get array info for %s\n", devname); |
144 | return 1; | |
145 | } | |
146 | ||
147 | nd = d; | |
4b1ac34b | 148 | for (d=0 ; d < info.array.raid_disks ; d++) { |
e5329c37 NB |
149 | mdu_disk_info_t disk; |
150 | char *dv; | |
151 | ||
152 | disk.number = d; | |
153 | if (ioctl(fd, GET_DISK_INFO, &disk) < 0) { | |
154 | fprintf(stderr, Name ": cannot get device detail for device %d\n", | |
155 | d); | |
156 | return 1; | |
157 | } | |
16c6fa80 | 158 | dv = map_dev(disk.major, disk.minor, 1); |
e5329c37 NB |
159 | if (!dv) { |
160 | fprintf(stderr, Name ": cannot find device file for device %d\n", | |
161 | d); | |
162 | return 1; | |
163 | } | |
16c6fa80 | 164 | fd2 = dev_open(dv, O_RDWR); |
e5329c37 NB |
165 | if (fd2 < 0) { |
166 | fprintf(stderr, Name ": cannot open device file %s\n", dv); | |
167 | return 1; | |
168 | } | |
3da92f27 | 169 | if (st->ss->load_super(st, fd2, NULL)) { |
e5329c37 NB |
170 | fprintf(stderr, Name ": cannot find super block on %s\n", dv); |
171 | close(fd); | |
172 | return 1; | |
173 | } | |
4b1ac34b NB |
174 | info.array.raid_disks = nd+1; |
175 | info.array.nr_disks = nd+1; | |
176 | info.array.active_disks = nd+1; | |
177 | info.array.working_disks = nd+1; | |
f752781f | 178 | |
3da92f27 | 179 | st->ss->update_super(st, &info, "linear-grow-update", dv, |
f752781f | 180 | 0, 0, NULL); |
aba69144 | 181 | |
3da92f27 | 182 | if (st->ss->store_super(st, fd2)) { |
e5329c37 NB |
183 | fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv); |
184 | close(fd2); | |
185 | return 1; | |
186 | } | |
187 | close(fd2); | |
188 | } | |
189 | ||
190 | return 0; | |
191 | } | |
f5e166fe | 192 | |
8fac0577 | 193 | int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int write_behind, int force) |
f5e166fe NB |
194 | { |
195 | /* | |
196 | * First check that array doesn't have a bitmap | |
197 | * Then create the bitmap | |
198 | * Then add it | |
199 | * | |
200 | * For internal bitmaps, we need to check the version, | |
201 | * find all the active devices, and write the bitmap block | |
202 | * to all devices | |
203 | */ | |
204 | mdu_bitmap_file_t bmf; | |
205 | mdu_array_info_t array; | |
206 | struct supertype *st; | |
dcec9ee5 NB |
207 | int major = BITMAP_MAJOR_HI; |
208 | int vers = md_get_version(fd); | |
8fac0577 | 209 | unsigned long long bitmapsize, array_size; |
dcec9ee5 NB |
210 | |
211 | if (vers < 9003) { | |
212 | major = BITMAP_MAJOR_HOSTENDIAN; | |
213 | #ifdef __BIG_ENDIAN | |
214 | fprintf(stderr, Name ": Warning - bitmaps created on this kernel are not portable\n" | |
215 | " between different architectured. Consider upgrading the Linux kernel.\n"); | |
216 | #endif | |
217 | } | |
f5e166fe NB |
218 | |
219 | if (ioctl(fd, GET_BITMAP_FILE, &bmf) != 0) { | |
353632d9 | 220 | if (errno == ENOMEM) |
f5e166fe NB |
221 | fprintf(stderr, Name ": Memory allocation failure.\n"); |
222 | else | |
223 | fprintf(stderr, Name ": bitmaps not supported by this kernel.\n"); | |
224 | return 1; | |
225 | } | |
226 | if (bmf.pathname[0]) { | |
fe80f49b NB |
227 | if (strcmp(file,"none")==0) { |
228 | if (ioctl(fd, SET_BITMAP_FILE, -1)!= 0) { | |
229 | fprintf(stderr, Name ": failed to remove bitmap %s\n", | |
230 | bmf.pathname); | |
231 | return 1; | |
232 | } | |
233 | return 0; | |
234 | } | |
f5e166fe NB |
235 | fprintf(stderr, Name ": %s already has a bitmap (%s)\n", |
236 | devname, bmf.pathname); | |
237 | return 1; | |
238 | } | |
239 | if (ioctl(fd, GET_ARRAY_INFO, &array) != 0) { | |
240 | fprintf(stderr, Name ": cannot get array status for %s\n", devname); | |
241 | return 1; | |
242 | } | |
243 | if (array.state & (1<<MD_SB_BITMAP_PRESENT)) { | |
fe80f49b NB |
244 | if (strcmp(file, "none")==0) { |
245 | array.state &= ~(1<<MD_SB_BITMAP_PRESENT); | |
246 | if (ioctl(fd, SET_ARRAY_INFO, &array)!= 0) { | |
247 | fprintf(stderr, Name ": failed to remove internal bitmap.\n"); | |
248 | return 1; | |
249 | } | |
250 | return 0; | |
251 | } | |
f5e166fe NB |
252 | fprintf(stderr, Name ": Internal bitmap already present on %s\n", |
253 | devname); | |
254 | return 1; | |
255 | } | |
5b28bd56 NB |
256 | if (array.level <= 0) { |
257 | fprintf(stderr, Name ": Bitmaps not meaningful with level %s\n", | |
258 | map_num(pers, array.level)?:"of this array"); | |
259 | return 1; | |
260 | } | |
8fac0577 NB |
261 | bitmapsize = array.size; |
262 | bitmapsize <<= 1; | |
beae1dfe | 263 | if (get_dev_size(fd, NULL, &array_size) && |
8fac0577 NB |
264 | array_size > (0x7fffffffULL<<9)) { |
265 | /* Array is big enough that we cannot trust array.size | |
266 | * try other approaches | |
267 | */ | |
268 | bitmapsize = get_component_size(fd); | |
269 | } | |
8fac0577 NB |
270 | if (bitmapsize == 0) { |
271 | fprintf(stderr, Name ": Cannot reliably determine size of array to create bitmap - sorry.\n"); | |
272 | return 1; | |
273 | } | |
274 | ||
f9c25f1d | 275 | if (array.level == 10) { |
8686f3ed | 276 | int ncopies = (array.layout&255)*((array.layout>>8)&255); |
f9c25f1d NB |
277 | bitmapsize = bitmapsize * array.raid_disks / ncopies; |
278 | } | |
279 | ||
1686dc25 | 280 | st = super_by_fd(fd); |
f5e166fe NB |
281 | if (!st) { |
282 | fprintf(stderr, Name ": Cannot understand version %d.%d\n", | |
283 | array.major_version, array.minor_version); | |
284 | return 1; | |
285 | } | |
fe80f49b NB |
286 | if (strcmp(file, "none") == 0) { |
287 | fprintf(stderr, Name ": no bitmap found on %s\n", devname); | |
288 | return 1; | |
289 | } else if (strcmp(file, "internal") == 0) { | |
f5e166fe | 290 | int d; |
ea329559 | 291 | for (d=0; d< st->max_devs; d++) { |
f5e166fe NB |
292 | mdu_disk_info_t disk; |
293 | char *dv; | |
294 | disk.number = d; | |
295 | if (ioctl(fd, GET_DISK_INFO, &disk) < 0) | |
296 | continue; | |
297 | if (disk.major == 0 && | |
298 | disk.minor == 0) | |
299 | continue; | |
300 | if ((disk.state & (1<<MD_DISK_SYNC))==0) | |
301 | continue; | |
16c6fa80 | 302 | dv = map_dev(disk.major, disk.minor, 1); |
f5e166fe | 303 | if (dv) { |
16c6fa80 | 304 | int fd2 = dev_open(dv, O_RDWR); |
f5e166fe NB |
305 | if (fd2 < 0) |
306 | continue; | |
3da92f27 | 307 | if (st->ss->load_super(st, fd2, NULL)==0) { |
199171a2 | 308 | if (st->ss->add_internal_bitmap( |
3da92f27 | 309 | st, |
199171a2 NB |
310 | &chunk, delay, write_behind, |
311 | bitmapsize, 0, major) | |
312 | ) | |
3da92f27 | 313 | st->ss->write_bitmap(st, fd2); |
21e92547 NB |
314 | else { |
315 | fprintf(stderr, Name ": failed to create internal bitmap - chunksize problem.\n"); | |
316 | close(fd2); | |
317 | return 1; | |
318 | } | |
f5e166fe NB |
319 | } |
320 | close(fd2); | |
321 | } | |
322 | } | |
323 | array.state |= (1<<MD_SB_BITMAP_PRESENT); | |
324 | if (ioctl(fd, SET_ARRAY_INFO, &array)!= 0) { | |
325 | fprintf(stderr, Name ": failed to set internal bitmap.\n"); | |
326 | return 1; | |
327 | } | |
fe80f49b NB |
328 | } else { |
329 | int uuid[4]; | |
330 | int bitmap_fd; | |
331 | int d; | |
332 | int max_devs = st->max_devs; | |
fe80f49b NB |
333 | |
334 | /* try to load a superblock */ | |
335 | for (d=0; d<max_devs; d++) { | |
336 | mdu_disk_info_t disk; | |
337 | char *dv; | |
338 | int fd2; | |
339 | disk.number = d; | |
340 | if (ioctl(fd, GET_DISK_INFO, &disk) < 0) | |
341 | continue; | |
342 | if ((disk.major==0 && disk.minor==0) || | |
343 | (disk.state & (1<<MD_DISK_REMOVED))) | |
344 | continue; | |
16c6fa80 | 345 | dv = map_dev(disk.major, disk.minor, 1); |
fe80f49b | 346 | if (!dv) continue; |
16c6fa80 | 347 | fd2 = dev_open(dv, O_RDONLY); |
fe80f49b | 348 | if (fd2 >= 0 && |
3da92f27 | 349 | st->ss->load_super(st, fd2, NULL) == 0) { |
fe80f49b | 350 | close(fd2); |
3da92f27 | 351 | st->ss->uuid_from_super(st, uuid); |
fe80f49b NB |
352 | break; |
353 | } | |
354 | close(fd2); | |
355 | } | |
356 | if (d == max_devs) { | |
357 | fprintf(stderr, Name ": cannot find UUID for array!\n"); | |
358 | return 1; | |
359 | } | |
8fac0577 | 360 | if (CreateBitmap(file, force, (char*)uuid, chunk, |
f9c25f1d | 361 | delay, write_behind, bitmapsize, major)) { |
fe80f49b NB |
362 | return 1; |
363 | } | |
364 | bitmap_fd = open(file, O_RDWR); | |
365 | if (bitmap_fd < 0) { | |
8fac0577 | 366 | fprintf(stderr, Name ": weird: %s cannot be opened\n", |
fe80f49b NB |
367 | file); |
368 | return 1; | |
369 | } | |
370 | if (ioctl(fd, SET_BITMAP_FILE, bitmap_fd) < 0) { | |
371 | fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n", | |
372 | devname, strerror(errno)); | |
373 | return 1; | |
374 | } | |
375 | } | |
f5e166fe NB |
376 | |
377 | return 0; | |
378 | } | |
379 | ||
e86c9dd6 NB |
380 | |
381 | /* | |
382 | * When reshaping an array we might need to backup some data. | |
383 | * This is written to all spares with a 'super_block' describing it. | |
384 | * The superblock goes 1K form the end of the used space on the | |
385 | * device. | |
386 | * It if written after the backup is complete. | |
387 | * It has the following structure. | |
388 | */ | |
389 | ||
390 | struct mdp_backup_super { | |
391 | char magic[16]; /* md_backup_data-1 */ | |
392 | __u8 set_uuid[16]; | |
393 | __u64 mtime; | |
394 | /* start/sizes in 512byte sectors */ | |
395 | __u64 devstart; | |
396 | __u64 arraystart; | |
397 | __u64 length; | |
398 | __u32 sb_csum; /* csum of preceeding bytes. */ | |
94a20f0c N |
399 | __u8 pad[512-68]; |
400 | } __attribute__((aligned(512))) bsb; | |
e86c9dd6 NB |
401 | |
402 | int bsb_csum(char *buf, int len) | |
403 | { | |
404 | int i; | |
405 | int csum = 0; | |
406 | for (i=0; i<len; i++) | |
407 | csum = (csum<<3) + buf[0]; | |
408 | return __cpu_to_le32(csum); | |
409 | } | |
410 | ||
06b0d786 | 411 | int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, |
e86c9dd6 | 412 | long long size, |
19678e53 | 413 | int level, char *layout_str, int chunksize, int raid_disks) |
e86c9dd6 NB |
414 | { |
415 | /* Make some changes in the shape of an array. | |
416 | * The kernel must support the change. | |
417 | * Different reshapes have subtly different meaning for different | |
418 | * levels, so we need to check the current state of the array | |
419 | * and go from there. | |
420 | */ | |
421 | struct mdu_array_info_s array; | |
422 | char *c; | |
423 | ||
e86c9dd6 NB |
424 | struct supertype *st; |
425 | ||
426 | int nlevel, olevel; | |
427 | int nchunk, ochunk; | |
428 | int nlayout, olayout; | |
429 | int ndisks, odisks; | |
430 | int ndata, odata; | |
431 | unsigned long long nstripe, ostripe, last_block; | |
432 | int *fdlist; | |
433 | unsigned long long *offsets; | |
434 | int d, i, spares; | |
435 | int nrdisks; | |
436 | int err; | |
e86c9dd6 | 437 | |
7e0f6979 | 438 | struct mdinfo *sra; |
06c7f68e | 439 | struct mdinfo *sd; |
e86c9dd6 NB |
440 | |
441 | if (ioctl(fd, GET_ARRAY_INFO, &array) < 0) { | |
442 | fprintf(stderr, Name ": %s is not an active md array - aborting\n", | |
443 | devname); | |
444 | return 1; | |
445 | } | |
446 | c = map_num(pers, array.level); | |
447 | if (c == NULL) c = "-unknown-"; | |
448 | switch(array.level) { | |
449 | default: /* raid0, linear, multipath cannot be reconfigured */ | |
450 | fprintf(stderr, Name ": %s array %s cannot be reshaped.\n", | |
451 | c, devname); | |
452 | return 1; | |
453 | ||
454 | case LEVEL_FAULTY: /* only 'layout' change is permitted */ | |
455 | ||
456 | if (size >= 0) { | |
457 | fprintf(stderr, Name ": %s: Cannot change size of a 'faulty' array\n", | |
458 | devname); | |
459 | return 1; | |
460 | } | |
461 | if (level != UnSet && level != LEVEL_FAULTY) { | |
462 | fprintf(stderr, Name ": %s: Cannot change RAID level of a 'faulty' array\n", | |
463 | devname); | |
464 | return 1; | |
465 | } | |
466 | if (chunksize || raid_disks) { | |
467 | fprintf(stderr, Name ": %s: Cannot change chunksize or disks of a 'faulty' array\n", | |
468 | devname); | |
469 | return 1; | |
470 | } | |
19678e53 | 471 | if (layout_str == NULL) |
e86c9dd6 NB |
472 | return 0; /* nothing to do.... */ |
473 | ||
19678e53 N |
474 | array.layout = parse_layout_faulty(layout_str); |
475 | if (array.layout < 0) { | |
476 | fprintf(stderr, Name ": %s: layout %s not understood for 'faulty' array\n", | |
477 | devname, layout_str); | |
478 | return 1; | |
479 | } | |
e86c9dd6 NB |
480 | if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) { |
481 | fprintf(stderr, Name ": Cannot set layout for %s: %s\n", | |
482 | devname, strerror(errno)); | |
483 | return 1; | |
484 | } | |
485 | if (!quiet) | |
486 | printf("layout for %s set to %d\n", devname, array.layout); | |
487 | return 0; | |
488 | ||
489 | case 1: /* raid_disks and size can each be changed. They are independant */ | |
490 | ||
491 | if (level != UnSet && level != 1) { | |
492 | fprintf(stderr, Name ": %s: Cannot change RAID level of a RAID1 array.\n", | |
493 | devname); | |
494 | return 1; | |
495 | } | |
19678e53 | 496 | if (chunksize || layout_str != NULL) { |
e86c9dd6 NB |
497 | fprintf(stderr, Name ": %s: Cannot change chunk size of layout for a RAID1 array.\n", |
498 | devname); | |
499 | return 1; | |
500 | } | |
501 | ||
502 | /* Each can trigger a resync/recovery which will block the | |
503 | * other from happening. Later we could block | |
504 | * resync for the duration via 'sync_action'... | |
505 | */ | |
9860f271 | 506 | if (raid_disks > 0) { |
e86c9dd6 | 507 | array.raid_disks = raid_disks; |
9860f271 NB |
508 | if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) { |
509 | fprintf(stderr, Name ": Cannot set raid-devices for %s: %s\n", | |
510 | devname, strerror(errno)); | |
511 | return 1; | |
512 | } | |
513 | } | |
514 | if (size >= 0) { | |
5f4fc0e1 | 515 | int rv; |
e86c9dd6 | 516 | array.size = size; |
5f4fc0e1 N |
517 | if (array.size != size) { |
518 | /* got truncated to 32bit, write to | |
519 | * component_size instead | |
520 | */ | |
521 | sra = sysfs_read(fd, 0, 0); | |
522 | if (sra) | |
523 | rv = sysfs_set_num(sra, NULL, | |
524 | "component_size", size); | |
525 | else | |
526 | rv = -1; | |
527 | } else | |
528 | rv = ioctl(fd, SET_ARRAY_INFO, &array); | |
529 | if (rv != 0) { | |
9860f271 NB |
530 | fprintf(stderr, Name ": Cannot set device size for %s: %s\n", |
531 | devname, strerror(errno)); | |
532 | return 1; | |
533 | } | |
e86c9dd6 NB |
534 | } |
535 | return 0; | |
536 | ||
537 | case 4: | |
538 | case 5: | |
539 | case 6: | |
1686dc25 NB |
540 | st = super_by_fd(fd); |
541 | ||
758d3a8e | 542 | /* size can be changed independently. |
e86c9dd6 NB |
543 | * layout/chunksize/raid_disks/level can be changed |
544 | * though the kernel may not support it all. | |
545 | * If 'suspend_lo' is not present in devfs, then | |
546 | * these cannot be changed. | |
547 | */ | |
548 | if (size >= 0) { | |
549 | /* Cannot change other details as well.. */ | |
19678e53 | 550 | if (layout_str != NULL || |
e86c9dd6 NB |
551 | chunksize != 0 || |
552 | raid_disks != 0 || | |
553 | level != UnSet) { | |
554 | fprintf(stderr, Name ": %s: Cannot change shape as well as size of a %s array.\n", | |
555 | devname, c); | |
556 | return 1; | |
557 | } | |
558 | array.size = size; | |
559 | if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) { | |
560 | fprintf(stderr, Name ": Cannot set device size/shape for %s: %s\n", | |
561 | devname, strerror(errno)); | |
562 | return 1; | |
563 | } | |
564 | return 0; | |
565 | } | |
566 | /* Ok, just change the shape. This can be awkward. | |
567 | * There are three possibilities. | |
568 | * 1/ The array will shrink. We don't support this | |
569 | * possibility. Maybe one day... | |
570 | * 2/ The array will not change size. This is easy enough | |
571 | * to do, but not reliably. If the process is aborted | |
572 | * the array *will* be corrupted. So maybe we can allow | |
573 | * this but only if the user is really certain. e.g. | |
574 | * --really-risk-everything | |
575 | * 3/ The array will grow. This can be reliably achieved. | |
576 | * However the kernel's restripe routines will cheerfully | |
577 | * overwrite some early data before it is safe. So we | |
578 | * need to make a backup of the early parts of the array | |
579 | * and be ready to restore it if rebuild aborts very early. | |
580 | * | |
581 | * We backup data by writing it to all spares (there must be | |
582 | * at least 1, so even raid6->raid5 requires a spare to be | |
583 | * present). | |
584 | * | |
585 | * So: we enumerate the devices in the array and | |
586 | * make sure we can open all of them. | |
587 | * Then we freeze the early part of the array and | |
588 | * backup to the various spares. | |
589 | * Then we request changes and start the reshape. | |
590 | * Monitor progress until it has passed the danger zone. | |
591 | * and finally invalidate the copied data and unfreeze the | |
592 | * start of the array. | |
593 | * | |
594 | * Before we can do this we need to decide: | |
595 | * - will the array grow? Just calculate size | |
596 | * - how much needs to be saved: count stripes. | |
597 | * - where to save data... good question. | |
598 | * | |
599 | */ | |
600 | nlevel = olevel = array.level; | |
601 | nchunk = ochunk = array.chunk_size; | |
602 | nlayout = olayout = array.layout; | |
603 | ndisks = odisks = array.raid_disks; | |
604 | ||
605 | if (level != UnSet) nlevel = level; | |
606 | if (chunksize) nchunk = chunksize; | |
19678e53 N |
607 | if (layout_str != NULL) |
608 | switch(nlevel) { | |
609 | case 4: /* ignore layout */ | |
610 | break; | |
611 | case 5: | |
612 | nlayout = map_name(r5layout, layout_str); | |
613 | if (nlayout == UnSet) { | |
614 | fprintf(stderr, Name ": layout %s not understood for raid5.\n", | |
615 | layout_str); | |
616 | return 1; | |
617 | } | |
618 | break; | |
619 | ||
620 | case 6: | |
621 | nlayout = map_name(r6layout, layout_str); | |
622 | if (nlayout == UnSet) { | |
623 | fprintf(stderr, Name ": layout %s not understood for raid6.\n", | |
624 | layout_str); | |
625 | return 1; | |
626 | } | |
627 | break; | |
628 | } | |
e86c9dd6 NB |
629 | if (raid_disks) ndisks = raid_disks; |
630 | ||
631 | odata = odisks-1; | |
632 | if (olevel == 6) odata--; /* number of data disks */ | |
633 | ndata = ndisks-1; | |
634 | if (nlevel == 6) ndata--; | |
635 | ||
636 | if (ndata < odata) { | |
637 | fprintf(stderr, Name ": %s: Cannot reduce number of data disks (yet).\n", | |
638 | devname); | |
639 | return 1; | |
640 | } | |
641 | if (ndata == odata) { | |
642 | fprintf(stderr, Name ": %s: Cannot reshape array without increasing size (yet).\n", | |
643 | devname); | |
644 | return 1; | |
645 | } | |
646 | /* Well, it is growing... so how much do we need to backup. | |
647 | * Need to backup a full number of new-stripes, such that the | |
648 | * last one does not over-write any place that it would be read | |
649 | * from | |
650 | */ | |
651 | nstripe = ostripe = 0; | |
353632d9 | 652 | while (nstripe >= ostripe) { |
e86c9dd6 NB |
653 | nstripe += nchunk/512; |
654 | last_block = nstripe * ndata; | |
353632d9 | 655 | ostripe = last_block / odata / (ochunk/512) * (ochunk/512); |
e86c9dd6 | 656 | } |
0aa389dc NB |
657 | fprintf(stderr, Name ": Need to backup %lluK of critical " |
658 | "section..\n", last_block/2); | |
e86c9dd6 NB |
659 | |
660 | sra = sysfs_read(fd, 0, | |
758d3a8e NB |
661 | GET_COMPONENT|GET_DEVS|GET_OFFSET|GET_STATE| |
662 | GET_CACHE); | |
e86c9dd6 NB |
663 | if (!sra) { |
664 | fprintf(stderr, Name ": %s: Cannot get array details from sysfs\n", | |
665 | devname); | |
666 | return 1; | |
667 | } | |
668 | ||
669 | if (last_block >= sra->component_size/2) { | |
670 | fprintf(stderr, Name ": %s: Something wrong - reshape aborted\n", | |
671 | devname); | |
672 | return 1; | |
673 | } | |
7e0f6979 | 674 | if (sra->array.spare_disks == 0 && backup_file == NULL) { |
06b0d786 | 675 | fprintf(stderr, Name ": %s: Cannot grow - need a spare or backup-file to backup critical section\n", |
353632d9 NB |
676 | devname); |
677 | return 1; | |
678 | } | |
e86c9dd6 | 679 | |
7e0f6979 | 680 | nrdisks = array.nr_disks + sra->array.spare_disks; |
e86c9dd6 NB |
681 | /* Now we need to open all these devices so we can read/write. |
682 | */ | |
06b0d786 NB |
683 | fdlist = malloc((1+nrdisks) * sizeof(int)); |
684 | offsets = malloc((1+nrdisks) * sizeof(offsets[0])); | |
e86c9dd6 NB |
685 | if (!fdlist || !offsets) { |
686 | fprintf(stderr, Name ": malloc failed: grow aborted\n"); | |
687 | return 1; | |
688 | } | |
06b0d786 | 689 | for (d=0; d <= nrdisks; d++) |
e86c9dd6 NB |
690 | fdlist[d] = -1; |
691 | d = array.raid_disks; | |
692 | for (sd = sra->devs; sd; sd=sd->next) { | |
06c7f68e | 693 | if (sd->disk.state & (1<<MD_DISK_FAULTY)) |
e86c9dd6 | 694 | continue; |
06c7f68e NB |
695 | if (sd->disk.state & (1<<MD_DISK_SYNC)) { |
696 | char *dn = map_dev(sd->disk.major, | |
697 | sd->disk.minor, 1); | |
698 | fdlist[sd->disk.raid_disk] | |
699 | = dev_open(dn, O_RDONLY); | |
700 | offsets[sd->disk.raid_disk] = sd->data_offset; | |
701 | if (fdlist[sd->disk.raid_disk] < 0) { | |
e86c9dd6 | 702 | fprintf(stderr, Name ": %s: cannot open component %s\n", |
e81cdd9f | 703 | devname, dn?dn:"-unknown-"); |
e86c9dd6 NB |
704 | goto abort; |
705 | } | |
706 | } else { | |
707 | /* spare */ | |
06c7f68e NB |
708 | char *dn = map_dev(sd->disk.major, |
709 | sd->disk.minor, 1); | |
16c6fa80 | 710 | fdlist[d] = dev_open(dn, O_RDWR); |
06c7f68e | 711 | offsets[d] = sd->data_offset; |
e86c9dd6 NB |
712 | if (fdlist[d]<0) { |
713 | fprintf(stderr, Name ": %s: cannot open component %s\n", | |
e81cdd9f | 714 | devname, dn?dn:"-unknown"); |
e86c9dd6 NB |
715 | goto abort; |
716 | } | |
717 | d++; | |
718 | } | |
719 | } | |
720 | for (i=0 ; i<array.raid_disks; i++) | |
721 | if (fdlist[i] < 0) { | |
722 | fprintf(stderr, Name ": %s: failed to find device %d. Array might be degraded.\n" | |
723 | " --grow aborted\n", devname, i); | |
724 | goto abort; | |
725 | } | |
7e0f6979 | 726 | spares = sra->array.spare_disks; |
06b0d786 | 727 | if (backup_file) { |
fb97b4d6 | 728 | fdlist[d] = open(backup_file, O_RDWR|O_CREAT|O_EXCL, S_IRUSR | S_IWUSR); |
06b0d786 NB |
729 | if (fdlist[d] < 0) { |
730 | fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n", | |
731 | devname, backup_file, strerror(errno)); | |
732 | goto abort; | |
733 | } | |
734 | offsets[d] = 8; | |
735 | d++; | |
736 | spares++; | |
737 | } | |
e86c9dd6 | 738 | if (fdlist[array.raid_disks] < 0) { |
06b0d786 | 739 | fprintf(stderr, Name ": %s: failed to find a spare and no backup-file given - --grow aborted\n", |
e86c9dd6 NB |
740 | devname); |
741 | goto abort; | |
742 | } | |
743 | ||
744 | /* Find a superblock */ | |
3da92f27 | 745 | if (st->ss->load_super(st, fdlist[0], NULL)) { |
e86c9dd6 NB |
746 | fprintf(stderr, Name ": %s: Cannot find a superblock\n", |
747 | devname); | |
748 | goto abort; | |
749 | } | |
750 | ||
2efedc7b NB |
751 | |
752 | memcpy(bsb.magic, "md_backup_data-1", 16); | |
3da92f27 | 753 | st->ss->uuid_from_super(st, (int*)&bsb.set_uuid); |
2efedc7b NB |
754 | bsb.mtime = __cpu_to_le64(time(0)); |
755 | bsb.arraystart = 0; | |
756 | bsb.length = __cpu_to_le64(last_block); | |
757 | ||
758 | /* Decide offset for the backup, llseek the spares, and write | |
759 | * a leading superblock 4K earlier. | |
760 | */ | |
e86c9dd6 | 761 | for (i=array.raid_disks; i<d; i++) { |
94a20f0c N |
762 | char abuf[4096+512]; |
763 | char *buf = (char*)(((unsigned long)abuf+511)& ~511); | |
06b0d786 NB |
764 | if (i==d-1 && backup_file) { |
765 | /* This is the backup file */ | |
766 | offsets[i] = 8; | |
767 | } else | |
768 | offsets[i] += sra->component_size - last_block - 8; | |
2efedc7b NB |
769 | if (lseek64(fdlist[i], (offsets[i]<<9) - 4096, 0) |
770 | != (offsets[i]<<9) - 4096) { | |
e86c9dd6 NB |
771 | fprintf(stderr, Name ": could not seek...\n"); |
772 | goto abort; | |
773 | } | |
94a20f0c | 774 | memset(buf, 0, 4096); |
2efedc7b NB |
775 | bsb.devstart = __cpu_to_le64(offsets[i]); |
776 | bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb)); | |
777 | memcpy(buf, &bsb, sizeof(bsb)); | |
778 | if (write(fdlist[i], buf, 4096) != 4096) { | |
779 | fprintf(stderr, Name ": could not write leading superblock\n"); | |
780 | goto abort; | |
781 | } | |
e86c9dd6 NB |
782 | } |
783 | array.level = nlevel; | |
784 | array.raid_disks = ndisks; | |
785 | array.chunk_size = nchunk; | |
786 | array.layout = nlayout; | |
787 | if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) { | |
758d3a8e NB |
788 | if (errno == ENOSPC) { |
789 | /* stripe cache is not big enough. | |
790 | * It needs to be 4 times chunksize_size, | |
791 | * and we assume pagesize is 4K | |
792 | */ | |
793 | if (sra->cache_size < 4 * (nchunk/4096)) { | |
794 | sysfs_set_num(sra, NULL, | |
795 | "stripe_cache_size", | |
796 | 4 * (nchunk/4096) +1); | |
797 | if (ioctl(fd, SET_ARRAY_INFO, | |
798 | &array) == 0) | |
799 | goto ok; | |
800 | } | |
801 | } | |
e86c9dd6 NB |
802 | fprintf(stderr, Name ": Cannot set device size/shape for %s: %s\n", |
803 | devname, strerror(errno)); | |
804 | goto abort; | |
805 | } | |
758d3a8e | 806 | ok: ; |
e86c9dd6 NB |
807 | |
808 | /* suspend the relevant region */ | |
809 | sysfs_set_num(sra, NULL, "suspend_hi", 0); /* just in case */ | |
810 | if (sysfs_set_num(sra, NULL, "suspend_lo", 0) < 0 || | |
811 | sysfs_set_num(sra, NULL, "suspend_hi", last_block) < 0) { | |
812 | fprintf(stderr, Name ": %s: failed to suspend device.\n", | |
813 | devname); | |
814 | goto abort_resume; | |
815 | } | |
816 | ||
817 | ||
818 | err = save_stripes(fdlist, offsets, | |
819 | odisks, ochunk, olevel, olayout, | |
820 | spares, fdlist+odisks, | |
06b0d786 | 821 | 0ULL, last_block*512); |
e86c9dd6 NB |
822 | |
823 | /* abort if there was an error */ | |
824 | if (err < 0) { | |
825 | fprintf(stderr, Name ": %s: failed to save critical region\n", | |
826 | devname); | |
827 | goto abort_resume; | |
828 | } | |
2efedc7b | 829 | |
e86c9dd6 | 830 | for (i=odisks; i<d ; i++) { |
353632d9 | 831 | bsb.devstart = __cpu_to_le64(offsets[i]); |
e86c9dd6 | 832 | bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb)); |
206c5eae | 833 | if (lseek64(fdlist[i], (offsets[i]+last_block)<<9, 0) < 0 || |
06b0d786 NB |
834 | write(fdlist[i], &bsb, sizeof(bsb)) != sizeof(bsb) || |
835 | fsync(fdlist[i]) != 0) { | |
94a20f0c | 836 | fprintf(stderr, Name ": %s: failed to save metadata for critical region backups.\n", |
206c5eae NB |
837 | devname); |
838 | goto abort_resume; | |
839 | } | |
e86c9dd6 NB |
840 | } |
841 | ||
842 | /* start the reshape happening */ | |
843 | if (sysfs_set_str(sra, NULL, "sync_action", "reshape") < 0) { | |
844 | fprintf(stderr, Name ": %s: failed to initiate reshape\n", | |
845 | devname); | |
846 | goto abort_resume; | |
847 | } | |
848 | /* wait for reshape to pass the critical region */ | |
849 | while(1) { | |
850 | unsigned long long comp; | |
48924014 | 851 | |
206c5eae NB |
852 | if (sysfs_get_ll(sra, NULL, "sync_completed", &comp)<0) { |
853 | sleep(5); | |
e86c9dd6 | 854 | break; |
206c5eae | 855 | } |
e86c9dd6 NB |
856 | if (comp >= nstripe) |
857 | break; | |
93ecfa01 N |
858 | if (comp == 0) { |
859 | /* Maybe it finished already */ | |
860 | char action[20]; | |
861 | if (sysfs_get_str(sra, NULL, "sync_action", | |
862 | action, 20) > 0 && | |
863 | strncmp(action, "reshape", 7) != 0) | |
864 | break; | |
865 | } | |
e86c9dd6 NB |
866 | sleep(1); |
867 | } | |
aba69144 | 868 | |
e86c9dd6 NB |
869 | /* invalidate superblocks */ |
870 | memset(&bsb, 0, sizeof(bsb)); | |
871 | for (i=odisks; i<d ; i++) { | |
872 | lseek64(fdlist[i], (offsets[i]+last_block)<<9, 0); | |
9fca7d62 NB |
873 | if (write(fdlist[i], &bsb, sizeof(bsb)) < 0) { |
874 | fprintf(stderr, Name ": %s: failed to invalidate metadata for raid disk %d\n", | |
875 | devname, i); | |
876 | } | |
e86c9dd6 NB |
877 | } |
878 | ||
879 | /* unsuspend. */ | |
880 | sysfs_set_num(sra, NULL, "suspend_lo", last_block); | |
881 | ||
882 | for (i=0; i<d; i++) | |
883 | if (fdlist[i] >= 0) | |
884 | close(fdlist[i]); | |
885 | free(fdlist); | |
886 | free(offsets); | |
06b0d786 NB |
887 | if (backup_file) |
888 | unlink(backup_file); | |
e86c9dd6 | 889 | |
0aa389dc | 890 | fprintf(stderr, Name ": ... critical section passed.\n"); |
e86c9dd6 NB |
891 | break; |
892 | } | |
893 | return 0; | |
894 | ||
895 | ||
896 | abort_resume: | |
897 | sysfs_set_num(sra, NULL, "suspend_lo", last_block); | |
898 | abort: | |
899 | for (i=0; i<array.nr_disks; i++) | |
900 | if (fdlist[i] >= 0) | |
901 | close(fdlist[i]); | |
902 | free(fdlist); | |
903 | free(offsets); | |
06b0d786 NB |
904 | if (backup_file) |
905 | unlink(backup_file); | |
e86c9dd6 NB |
906 | return 1; |
907 | ||
908 | } | |
353632d9 NB |
909 | |
910 | /* | |
911 | * If any spare contains md_back_data-1 which is recent wrt mtime, | |
912 | * write that data into the array and update the super blocks with | |
913 | * the new reshape_progress | |
914 | */ | |
06b0d786 | 915 | int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt, char *backup_file) |
353632d9 NB |
916 | { |
917 | int i, j; | |
918 | int old_disks; | |
353632d9 | 919 | unsigned long long *offsets; |
6e9eac4f NB |
920 | unsigned long long nstripe, ostripe, last_block; |
921 | int ndata, odata; | |
353632d9 NB |
922 | |
923 | if (info->delta_disks < 0) | |
924 | return 1; /* cannot handle a shrink */ | |
925 | if (info->new_level != info->array.level || | |
926 | info->new_layout != info->array.layout || | |
927 | info->new_chunk != info->array.chunk_size) | |
928 | return 1; /* Can only handle change in disks */ | |
929 | ||
930 | old_disks = info->array.raid_disks - info->delta_disks; | |
931 | ||
06b0d786 | 932 | for (i=old_disks-(backup_file?1:0); i<cnt; i++) { |
353632d9 | 933 | struct mdinfo dinfo; |
2efedc7b | 934 | char buf[4096]; |
06b0d786 | 935 | int fd; |
353632d9 NB |
936 | |
937 | /* This was a spare and may have some saved data on it. | |
938 | * Load the superblock, find and load the | |
939 | * backup_super_block. | |
940 | * If either fail, go on to next device. | |
941 | * If the backup contains no new info, just return | |
206c5eae | 942 | * else restore data and update all superblocks |
353632d9 | 943 | */ |
06b0d786 NB |
944 | if (i == old_disks-1) { |
945 | fd = open(backup_file, O_RDONLY); | |
946 | if (fd<0) | |
947 | continue; | |
06b0d786 NB |
948 | } else { |
949 | fd = fdlist[i]; | |
950 | if (fd < 0) | |
951 | continue; | |
3da92f27 | 952 | if (st->ss->load_super(st, fd, NULL)) |
06b0d786 | 953 | continue; |
353632d9 | 954 | |
3da92f27 NB |
955 | st->ss->getinfo_super(st, &dinfo); |
956 | st->ss->free_super(st); | |
957 | ||
06b0d786 NB |
958 | if (lseek64(fd, |
959 | (dinfo.data_offset + dinfo.component_size - 8) <<9, | |
960 | 0) < 0) | |
961 | continue; /* Cannot seek */ | |
962 | } | |
963 | if (read(fd, &bsb, sizeof(bsb)) != sizeof(bsb)) | |
353632d9 NB |
964 | continue; /* Cannot read */ |
965 | if (memcmp(bsb.magic, "md_backup_data-1", 16) != 0) | |
966 | continue; | |
967 | if (bsb.sb_csum != bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb))) | |
968 | continue; /* bad checksum */ | |
969 | if (memcmp(bsb.set_uuid,info->uuid, 16) != 0) | |
970 | continue; /* Wrong uuid */ | |
971 | ||
972 | if (info->array.utime > __le64_to_cpu(bsb.mtime) + 3600 || | |
973 | info->array.utime < __le64_to_cpu(bsb.mtime)) | |
974 | continue; /* time stamp is too bad */ | |
975 | ||
976 | if (__le64_to_cpu(bsb.arraystart) != 0) | |
977 | continue; /* Can only handle backup from start of array */ | |
978 | if (__le64_to_cpu(bsb.length) < | |
979 | info->reshape_progress) | |
980 | continue; /* No new data here */ | |
981 | ||
06b0d786 | 982 | if (lseek64(fd, __le64_to_cpu(bsb.devstart)*512, 0)< 0) |
353632d9 | 983 | continue; /* Cannot seek */ |
2efedc7b | 984 | /* There should be a duplicate backup superblock 4k before here */ |
06b0d786 NB |
985 | if (lseek64(fd, -4096, 1) < 0 || |
986 | read(fd, buf, 4096) != 4096 || | |
9860f271 | 987 | memcmp(buf, &bsb, sizeof(bsb)) != 0) |
2efedc7b NB |
988 | continue; /* Cannot find leading superblock */ |
989 | ||
353632d9 NB |
990 | /* Now need the data offsets for all devices. */ |
991 | offsets = malloc(sizeof(*offsets)*info->array.raid_disks); | |
992 | for(j=0; j<info->array.raid_disks; j++) { | |
993 | if (fdlist[j] < 0) | |
994 | continue; | |
3da92f27 | 995 | if (st->ss->load_super(st, fdlist[j], NULL)) |
353632d9 NB |
996 | /* FIXME should be this be an error */ |
997 | continue; | |
3da92f27 NB |
998 | st->ss->getinfo_super(st, &dinfo); |
999 | st->ss->free_super(st); | |
353632d9 NB |
1000 | offsets[j] = dinfo.data_offset; |
1001 | } | |
1002 | printf(Name ": restoring critical section\n"); | |
1003 | ||
1004 | if (restore_stripes(fdlist, offsets, | |
1005 | info->array.raid_disks, | |
1006 | info->new_chunk, | |
1007 | info->new_level, | |
1008 | info->new_layout, | |
06b0d786 | 1009 | fd, __le64_to_cpu(bsb.devstart)*512, |
353632d9 NB |
1010 | 0, __le64_to_cpu(bsb.length)*512)) { |
1011 | /* didn't succeed, so giveup */ | |
2295250a | 1012 | return 1; |
353632d9 NB |
1013 | } |
1014 | ||
1015 | /* Ok, so the data is restored. Let's update those superblocks. */ | |
1016 | ||
1017 | for (j=0; j<info->array.raid_disks; j++) { | |
1018 | if (fdlist[j] < 0) continue; | |
3da92f27 | 1019 | if (st->ss->load_super(st, fdlist[j], NULL)) |
353632d9 | 1020 | continue; |
3da92f27 | 1021 | st->ss->getinfo_super(st, &dinfo); |
353632d9 | 1022 | dinfo.reshape_progress = __le64_to_cpu(bsb.length); |
3da92f27 | 1023 | st->ss->update_super(st, &dinfo, |
68c7d6d7 NB |
1024 | "_reshape_progress", |
1025 | NULL,0, 0, NULL); | |
3da92f27 NB |
1026 | st->ss->store_super(st, fdlist[j]); |
1027 | st->ss->free_super(st); | |
353632d9 NB |
1028 | } |
1029 | ||
1030 | /* And we are done! */ | |
1031 | return 0; | |
1032 | } | |
6e9eac4f NB |
1033 | /* Didn't find any backup data, try to see if any |
1034 | * was needed. | |
1035 | */ | |
1036 | nstripe = ostripe = 0; | |
1037 | odata = info->array.raid_disks - info->delta_disks - 1; | |
1038 | if (info->array.level == 6) odata--; /* number of data disks */ | |
1039 | ndata = info->array.raid_disks - 1; | |
1040 | if (info->new_level == 6) ndata--; | |
1041 | last_block = 0; | |
1042 | while (nstripe >= ostripe) { | |
1043 | nstripe += info->new_chunk / 512; | |
1044 | last_block = nstripe * ndata; | |
1045 | ostripe = last_block / odata / (info->array.chunk_size/512) * | |
1046 | (info->array.chunk_size/512); | |
1047 | } | |
1048 | ||
1049 | if (info->reshape_progress >= last_block) | |
1050 | return 0; | |
1051 | /* needed to recover critical section! */ | |
2295250a | 1052 | return 1; |
353632d9 | 1053 | } |