]> git.ipfire.org Git - thirdparty/mdadm.git/blob - super1.c
Add data_offset arg to ->validate_geometry.
[thirdparty/mdadm.git] / super1.c
1 /*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
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@suse.de>
23 */
24
25 #include "mdadm.h"
26 /*
27 * The version-1 superblock :
28 * All numeric fields are little-endian.
29 *
30 * total size: 256 bytes plus 2 per device.
31 * 1K allows 384 devices.
32 */
33 struct mdp_superblock_1 {
34 /* constant array information - 128 bytes */
35 __u32 magic; /* MD_SB_MAGIC: 0xa92b4efc - little endian */
36 __u32 major_version; /* 1 */
37 __u32 feature_map; /* 0 for now */
38 __u32 pad0; /* always set to 0 when writing */
39
40 __u8 set_uuid[16]; /* user-space generated. */
41 char set_name[32]; /* set and interpreted by user-space */
42
43 __u64 ctime; /* lo 40 bits are seconds, top 24 are microseconds or 0*/
44 __u32 level; /* -4 (multipath), -1 (linear), 0,1,4,5 */
45 __u32 layout; /* only for raid5 currently */
46 __u64 size; /* used size of component devices, in 512byte sectors */
47
48 __u32 chunksize; /* in 512byte sectors */
49 __u32 raid_disks;
50 __u32 bitmap_offset; /* sectors after start of superblock that bitmap starts
51 * NOTE: signed, so bitmap can be before superblock
52 * only meaningful of feature_map[0] is set.
53 */
54
55 /* These are only valid with feature bit '4' */
56 __u32 new_level; /* new level we are reshaping to */
57 __u64 reshape_position; /* next address in array-space for reshape */
58 __u32 delta_disks; /* change in number of raid_disks */
59 __u32 new_layout; /* new layout */
60 __u32 new_chunk; /* new chunk size (bytes) */
61 __u8 pad1[128-124]; /* set to 0 when written */
62
63 /* constant this-device information - 64 bytes */
64 __u64 data_offset; /* sector start of data, often 0 */
65 __u64 data_size; /* sectors in this device that can be used for data */
66 __u64 super_offset; /* sector start of this superblock */
67 __u64 recovery_offset;/* sectors before this offset (from data_offset) have been recovered */
68 __u32 dev_number; /* permanent identifier of this device - not role in raid */
69 __u32 cnt_corrected_read; /* number of read errors that were corrected by re-writing */
70 __u8 device_uuid[16]; /* user-space setable, ignored by kernel */
71 __u8 devflags; /* per-device flags. Only one defined...*/
72 #define WriteMostly1 1 /* mask for writemostly flag in above */
73 /* bad block log. If there are any bad blocks the feature flag is set.
74 * if offset and size are non-zero, that space is reserved and available.
75 */
76 __u8 bblog_shift; /* shift from sectors to block size for badblocklist */
77 __u16 bblog_size; /* number of sectors reserved for badblocklist */
78 __u32 bblog_offset; /* sector offset from superblock to bblog, signed */
79
80 /* array state information - 64 bytes */
81 __u64 utime; /* 40 bits second, 24 btes microseconds */
82 __u64 events; /* incremented when superblock updated */
83 __u64 resync_offset; /* data before this offset (from data_offset) known to be in sync */
84 __u32 sb_csum; /* checksum upto dev_roles[max_dev] */
85 __u32 max_dev; /* size of dev_roles[] array to consider */
86 __u8 pad3[64-32]; /* set to 0 when writing */
87
88 /* device state information. Indexed by dev_number.
89 * 2 bytes per device
90 * Note there are no per-device state flags. State information is rolled
91 * into the 'roles' value. If a device is spare or faulty, then it doesn't
92 * have a meaningful role.
93 */
94 __u16 dev_roles[0]; /* role in array, or 0xffff for a spare, or 0xfffe for faulty */
95 };
96
97 #define MAX_SB_SIZE 4096
98 /* bitmap super size is 256, but we round up to a sector for alignment */
99 #define BM_SUPER_SIZE 512
100 #define MAX_DEVS ((int)(MAX_SB_SIZE - sizeof(struct mdp_superblock_1)) / 2)
101 #define SUPER1_SIZE (MAX_SB_SIZE + BM_SUPER_SIZE \
102 + sizeof(struct misc_dev_info))
103
104 struct misc_dev_info {
105 __u64 device_size;
106 };
107
108 /* feature_map bits */
109 #define MD_FEATURE_BITMAP_OFFSET 1
110 #define MD_FEATURE_RECOVERY_OFFSET 2 /* recovery_offset is present and
111 * must be honoured
112 */
113 #define MD_FEATURE_RESHAPE_ACTIVE 4
114 #define MD_FEATURE_BAD_BLOCKS 8 /* badblock list is not empty */
115
116 #define MD_FEATURE_ALL (1|2|4|8)
117
118 #ifndef offsetof
119 #define offsetof(t,f) ((size_t)&(((t*)0)->f))
120 #endif
121 static unsigned int calc_sb_1_csum(struct mdp_superblock_1 * sb)
122 {
123 unsigned int disk_csum, csum;
124 unsigned long long newcsum;
125 int size = sizeof(*sb) + __le32_to_cpu(sb->max_dev)*2;
126 unsigned int *isuper = (unsigned int*)sb;
127
128 /* make sure I can count... */
129 if (offsetof(struct mdp_superblock_1,data_offset) != 128 ||
130 offsetof(struct mdp_superblock_1, utime) != 192 ||
131 sizeof(struct mdp_superblock_1) != 256) {
132 fprintf(stderr, "WARNING - superblock isn't sized correctly\n");
133 }
134
135 disk_csum = sb->sb_csum;
136 sb->sb_csum = 0;
137 newcsum = 0;
138 for (; size>=4; size -= 4 ) {
139 newcsum += __le32_to_cpu(*isuper);
140 isuper++;
141 }
142
143 if (size == 2)
144 newcsum += __le16_to_cpu(*(unsigned short*) isuper);
145
146 csum = (newcsum & 0xffffffff) + (newcsum >> 32);
147 sb->sb_csum = disk_csum;
148 return __cpu_to_le32(csum);
149 }
150
151 /*
152 * Information related to file descriptor used for aligned reads/writes.
153 * Cache the block size.
154 */
155 struct align_fd {
156 int fd;
157 int blk_sz;
158 };
159
160 static void init_afd(struct align_fd *afd, int fd)
161 {
162 afd->fd = fd;
163
164 if (ioctl(afd->fd, BLKSSZGET, &afd->blk_sz) != 0)
165 afd->blk_sz = 512;
166 }
167
168 static char abuf[4096+4096];
169 static int aread(struct align_fd *afd, void *buf, int len)
170 {
171 /* aligned read.
172 * On devices with a 4K sector size, we need to read
173 * the full sector and copy relevant bits into
174 * the buffer
175 */
176 int bsize, iosize;
177 char *b;
178 int n;
179
180 bsize = afd->blk_sz;
181
182 if (!bsize || bsize > 4096 || len > 4096) {
183 if (!bsize)
184 fprintf(stderr, "WARNING - aread() called with "
185 "invalid block size\n");
186 return -1;
187 }
188 b = ROUND_UP_PTR((char *)abuf, 4096);
189
190 for (iosize = 0; iosize < len; iosize += bsize)
191 ;
192 n = read(afd->fd, b, iosize);
193 if (n <= 0)
194 return n;
195 lseek(afd->fd, len - n, 1);
196 if (n > len)
197 n = len;
198 memcpy(buf, b, n);
199 return n;
200 }
201
202 static int awrite(struct align_fd *afd, void *buf, int len)
203 {
204 /* aligned write.
205 * On devices with a 4K sector size, we need to write
206 * the full sector. We pre-read if the sector is larger
207 * than the write.
208 * The address must be sector-aligned.
209 */
210 int bsize, iosize;
211 char *b;
212 int n;
213
214 bsize = afd->blk_sz;
215 if (!bsize || bsize > 4096 || len > 4096) {
216 if (!bsize)
217 fprintf(stderr, "WARNING - awrite() called with "
218 "invalid block size\n");
219 return -1;
220 }
221 b = ROUND_UP_PTR((char *)abuf, 4096);
222
223 for (iosize = 0; iosize < len ; iosize += bsize)
224 ;
225
226 if (len != iosize) {
227 n = read(afd->fd, b, iosize);
228 if (n <= 0)
229 return n;
230 lseek(afd->fd, -n, 1);
231 }
232
233 memcpy(b, buf, len);
234 n = write(afd->fd, b, iosize);
235 if (n <= 0)
236 return n;
237 lseek(afd->fd, len - n, 1);
238 return len;
239 }
240
241 #ifndef MDASSEMBLE
242 static void examine_super1(struct supertype *st, char *homehost)
243 {
244 struct mdp_superblock_1 *sb = st->sb;
245 time_t atime;
246 unsigned int d;
247 int role;
248 int delta_extra = 0;
249 int i;
250 char *c;
251 int l = homehost ? strlen(homehost) : 0;
252 int layout;
253 unsigned long long sb_offset;
254
255 printf(" Magic : %08x\n", __le32_to_cpu(sb->magic));
256 printf(" Version : 1");
257 sb_offset = __le64_to_cpu(sb->super_offset);
258 if (sb_offset <= 4)
259 printf(".1\n");
260 else if (sb_offset <= 8)
261 printf(".2\n");
262 else
263 printf(".0\n");
264 printf(" Feature Map : 0x%x\n", __le32_to_cpu(sb->feature_map));
265 printf(" Array UUID : ");
266 for (i=0; i<16; i++) {
267 if ((i&3)==0 && i != 0) printf(":");
268 printf("%02x", sb->set_uuid[i]);
269 }
270 printf("\n");
271 printf(" Name : %.32s", sb->set_name);
272 if (l > 0 && l < 32 &&
273 sb->set_name[l] == ':' &&
274 strncmp(sb->set_name, homehost, l) == 0)
275 printf(" (local to host %s)", homehost);
276 printf("\n");
277 atime = __le64_to_cpu(sb->ctime) & 0xFFFFFFFFFFULL;
278 printf(" Creation Time : %.24s\n", ctime(&atime));
279 c=map_num(pers, __le32_to_cpu(sb->level));
280 printf(" Raid Level : %s\n", c?c:"-unknown-");
281 printf(" Raid Devices : %d\n", __le32_to_cpu(sb->raid_disks));
282 printf("\n");
283 printf(" Avail Dev Size : %llu%s\n",
284 (unsigned long long)__le64_to_cpu(sb->data_size),
285 human_size(__le64_to_cpu(sb->data_size)<<9));
286 if (__le32_to_cpu(sb->level) > 0) {
287 int ddsks = 0, ddsks_denom = 1;
288 switch(__le32_to_cpu(sb->level)) {
289 case 1: ddsks=1;break;
290 case 4:
291 case 5: ddsks = __le32_to_cpu(sb->raid_disks)-1; break;
292 case 6: ddsks = __le32_to_cpu(sb->raid_disks)-2; break;
293 case 10:
294 layout = __le32_to_cpu(sb->layout);
295 ddsks = __le32_to_cpu(sb->raid_disks);
296 ddsks_denom = (layout&255) * ((layout>>8)&255);
297 }
298 if (ddsks) {
299 long long asize = __le64_to_cpu(sb->size);
300 asize = (asize << 9) * ddsks / ddsks_denom;
301 printf(" Array Size : %llu%s\n",
302 asize >> 10, human_size(asize));
303 }
304 if (sb->size != sb->data_size)
305 printf(" Used Dev Size : %llu%s\n",
306 (unsigned long long)__le64_to_cpu(sb->size),
307 human_size(__le64_to_cpu(sb->size)<<9));
308 }
309 if (sb->data_offset)
310 printf(" Data Offset : %llu sectors\n",
311 (unsigned long long)__le64_to_cpu(sb->data_offset));
312 printf(" Super Offset : %llu sectors\n",
313 (unsigned long long)__le64_to_cpu(sb->super_offset));
314 if (__le32_to_cpu(sb->feature_map) & MD_FEATURE_RECOVERY_OFFSET)
315 printf("Recovery Offset : %llu sectors\n", (unsigned long long)__le64_to_cpu(sb->recovery_offset));
316 printf(" State : %s\n", (__le64_to_cpu(sb->resync_offset)+1)? "active":"clean");
317 printf(" Device UUID : ");
318 for (i=0; i<16; i++) {
319 if ((i&3)==0 && i != 0) printf(":");
320 printf("%02x", sb->device_uuid[i]);
321 }
322 printf("\n");
323 printf("\n");
324 if (sb->feature_map & __cpu_to_le32(MD_FEATURE_BITMAP_OFFSET)) {
325 printf("Internal Bitmap : %ld sectors from superblock\n",
326 (long)(int32_t)__le32_to_cpu(sb->bitmap_offset));
327 }
328 if (sb->feature_map & __cpu_to_le32(MD_FEATURE_RESHAPE_ACTIVE)) {
329 printf(" Reshape pos'n : %llu%s\n", (unsigned long long)__le64_to_cpu(sb->reshape_position)/2,
330 human_size(__le64_to_cpu(sb->reshape_position)<<9));
331 if (__le32_to_cpu(sb->delta_disks)) {
332 printf(" Delta Devices : %d", __le32_to_cpu(sb->delta_disks));
333 printf(" (%d->%d)\n",
334 __le32_to_cpu(sb->raid_disks)-__le32_to_cpu(sb->delta_disks),
335 __le32_to_cpu(sb->raid_disks));
336 if ((int)__le32_to_cpu(sb->delta_disks) < 0)
337 delta_extra = -__le32_to_cpu(sb->delta_disks);
338 }
339 if (__le32_to_cpu(sb->new_level) != __le32_to_cpu(sb->level)) {
340 c = map_num(pers, __le32_to_cpu(sb->new_level));
341 printf(" New Level : %s\n", c?c:"-unknown-");
342 }
343 if (__le32_to_cpu(sb->new_layout) != __le32_to_cpu(sb->layout)) {
344 if (__le32_to_cpu(sb->level) == 5) {
345 c = map_num(r5layout, __le32_to_cpu(sb->new_layout));
346 printf(" New Layout : %s\n", c?c:"-unknown-");
347 }
348 if (__le32_to_cpu(sb->level) == 6) {
349 c = map_num(r6layout, __le32_to_cpu(sb->new_layout));
350 printf(" New Layout : %s\n", c?c:"-unknown-");
351 }
352 if (__le32_to_cpu(sb->level) == 10) {
353 printf(" New Layout :");
354 print_r10_layout(__le32_to_cpu(sb->new_layout));
355 printf("\n");
356 }
357 }
358 if (__le32_to_cpu(sb->new_chunk) != __le32_to_cpu(sb->chunksize))
359 printf(" New Chunksize : %dK\n", __le32_to_cpu(sb->new_chunk)/2);
360 printf("\n");
361 }
362 if (sb->devflags) {
363 printf(" Flags :");
364 if (sb->devflags & WriteMostly1)
365 printf(" write-mostly");
366 printf("\n");
367 }
368
369 atime = __le64_to_cpu(sb->utime) & 0xFFFFFFFFFFULL;
370 printf(" Update Time : %.24s\n", ctime(&atime));
371
372 if (sb->bblog_size && sb->bblog_offset) {
373 printf(" Bad Block Log : %d entries available at offset %ld sectors",
374 __le16_to_cpu(sb->bblog_size)*512/8,
375 (long)__le32_to_cpu(sb->bblog_offset));
376 if (sb->feature_map &
377 __cpu_to_le32(MD_FEATURE_BAD_BLOCKS))
378 printf(" - bad blocks present.");
379 printf("\n");
380 }
381
382
383 if (calc_sb_1_csum(sb) == sb->sb_csum)
384 printf(" Checksum : %x - correct\n", __le32_to_cpu(sb->sb_csum));
385 else
386 printf(" Checksum : %x - expected %x\n", __le32_to_cpu(sb->sb_csum),
387 __le32_to_cpu(calc_sb_1_csum(sb)));
388 printf(" Events : %llu\n", (unsigned long long)__le64_to_cpu(sb->events));
389 printf("\n");
390 if (__le32_to_cpu(sb->level) == 5) {
391 c = map_num(r5layout, __le32_to_cpu(sb->layout));
392 printf(" Layout : %s\n", c?c:"-unknown-");
393 }
394 if (__le32_to_cpu(sb->level) == 6) {
395 c = map_num(r6layout, __le32_to_cpu(sb->layout));
396 printf(" Layout : %s\n", c?c:"-unknown-");
397 }
398 if (__le32_to_cpu(sb->level) == 10) {
399 int lo = __le32_to_cpu(sb->layout);
400 printf(" Layout :");
401 print_r10_layout(lo);
402 printf("\n");
403 }
404 switch(__le32_to_cpu(sb->level)) {
405 case 0:
406 case 4:
407 case 5:
408 case 6:
409 case 10:
410 printf(" Chunk Size : %dK\n", __le32_to_cpu(sb->chunksize)/2);
411 break;
412 case -1:
413 printf(" Rounding : %dK\n", __le32_to_cpu(sb->chunksize)/2);
414 break;
415 default: break;
416 }
417 printf("\n");
418 #if 0
419 /* This turns out to just be confusing */
420 printf(" Array Slot : %d (", __le32_to_cpu(sb->dev_number));
421 for (i= __le32_to_cpu(sb->max_dev); i> 0 ; i--)
422 if (__le16_to_cpu(sb->dev_roles[i-1]) != 0xffff)
423 break;
424 for (d=0; d < i; d++) {
425 int role = __le16_to_cpu(sb->dev_roles[d]);
426 if (d) printf(", ");
427 if (role == 0xffff) printf("empty");
428 else if(role == 0xfffe) printf("failed");
429 else printf("%d", role);
430 }
431 printf(")\n");
432 #endif
433 printf(" Device Role : ");
434 d = __le32_to_cpu(sb->dev_number);
435 if (d < __le32_to_cpu(sb->max_dev))
436 role = __le16_to_cpu(sb->dev_roles[d]);
437 else
438 role = 0xFFFF;
439 if (role >= 0xFFFE)
440 printf("spare\n");
441 else
442 printf("Active device %d\n", role);
443
444 printf(" Array State : ");
445 for (d=0; d<__le32_to_cpu(sb->raid_disks) + delta_extra; d++) {
446 int cnt = 0;
447 unsigned int i;
448 for (i=0; i< __le32_to_cpu(sb->max_dev); i++) {
449 unsigned int role = __le16_to_cpu(sb->dev_roles[i]);
450 if (role == d)
451 cnt++;
452 }
453 if (cnt > 1) printf("?");
454 else if (cnt == 1) printf("A");
455 else printf (".");
456 }
457 #if 0
458 /* This is confusing too */
459 faulty = 0;
460 for (i=0; i< __le32_to_cpu(sb->max_dev); i++) {
461 int role = __le16_to_cpu(sb->dev_roles[i]);
462 if (role == 0xFFFE)
463 faulty++;
464 }
465 if (faulty) printf(" %d failed", faulty);
466 #endif
467 printf(" ('A' == active, '.' == missing)");
468 printf("\n");
469 }
470
471
472 static void brief_examine_super1(struct supertype *st, int verbose)
473 {
474 struct mdp_superblock_1 *sb = st->sb;
475 int i;
476 unsigned long long sb_offset;
477 char *nm;
478 char *c=map_num(pers, __le32_to_cpu(sb->level));
479
480 nm = strchr(sb->set_name, ':');
481 if (nm)
482 nm++;
483 else if (sb->set_name[0])
484 nm = sb->set_name;
485 else
486 nm = NULL;
487
488 printf("ARRAY ");
489 if (nm) {
490 printf("/dev/md/");
491 print_escape(nm);
492 putchar(' ');
493 }
494 if (verbose && c)
495 printf(" level=%s", c);
496 sb_offset = __le64_to_cpu(sb->super_offset);
497 if (sb_offset <= 4)
498 printf(" metadata=1.1 ");
499 else if (sb_offset <= 8)
500 printf(" metadata=1.2 ");
501 else
502 printf(" metadata=1.0 ");
503 if (verbose)
504 printf("num-devices=%d ", __le32_to_cpu(sb->raid_disks));
505 printf("UUID=");
506 for (i=0; i<16; i++) {
507 if ((i&3)==0 && i != 0) printf(":");
508 printf("%02x", sb->set_uuid[i]);
509 }
510 if (sb->set_name[0]) {
511 printf(" name=");
512 print_quoted(sb->set_name);
513 }
514 printf("\n");
515 }
516
517 static void export_examine_super1(struct supertype *st)
518 {
519 struct mdp_superblock_1 *sb = st->sb;
520 int i;
521 int len = 32;
522 int layout;
523
524 printf("MD_LEVEL=%s\n", map_num(pers, __le32_to_cpu(sb->level)));
525 printf("MD_DEVICES=%d\n", __le32_to_cpu(sb->raid_disks));
526 for (i=0; i<32; i++)
527 if (sb->set_name[i] == '\n' ||
528 sb->set_name[i] == '\0') {
529 len = i;
530 break;
531 }
532 if (len)
533 printf("MD_NAME=%.*s\n", len, sb->set_name);
534 if (__le32_to_cpu(sb->level) > 0) {
535 int ddsks = 0, ddsks_denom = 1;
536 switch(__le32_to_cpu(sb->level)) {
537 case 1: ddsks=1;break;
538 case 4:
539 case 5: ddsks = __le32_to_cpu(sb->raid_disks)-1; break;
540 case 6: ddsks = __le32_to_cpu(sb->raid_disks)-2; break;
541 case 10:
542 layout = __le32_to_cpu(sb->layout);
543 ddsks = __le32_to_cpu(sb->raid_disks);
544 ddsks_denom = (layout&255) * ((layout>>8)&255);
545 }
546 if (ddsks) {
547 long long asize = __le64_to_cpu(sb->size);
548 asize = (asize << 9) * ddsks / ddsks_denom;
549 printf("MD_ARRAY_SIZE=%s\n",human_size_brief(asize,JEDEC));
550 }
551 }
552 printf("MD_UUID=");
553 for (i=0; i<16; i++) {
554 if ((i&3)==0 && i != 0) printf(":");
555 printf("%02x", sb->set_uuid[i]);
556 }
557 printf("\n");
558 printf("MD_UPDATE_TIME=%llu\n",
559 __le64_to_cpu(sb->utime) & 0xFFFFFFFFFFULL);
560 printf("MD_DEV_UUID=");
561 for (i=0; i<16; i++) {
562 if ((i&3)==0 && i != 0) printf(":");
563 printf("%02x", sb->device_uuid[i]);
564 }
565 printf("\n");
566 printf("MD_EVENTS=%llu\n",
567 (unsigned long long)__le64_to_cpu(sb->events));
568 }
569
570 static void detail_super1(struct supertype *st, char *homehost)
571 {
572 struct mdp_superblock_1 *sb = st->sb;
573 int i;
574 int l = homehost ? strlen(homehost) : 0;
575
576 printf(" Name : %.32s", sb->set_name);
577 if (l > 0 && l < 32 &&
578 sb->set_name[l] == ':' &&
579 strncmp(sb->set_name, homehost, l) == 0)
580 printf(" (local to host %s)", homehost);
581 printf("\n UUID : ");
582 for (i=0; i<16; i++) {
583 if ((i&3)==0 && i != 0) printf(":");
584 printf("%02x", sb->set_uuid[i]);
585 }
586 printf("\n Events : %llu\n\n", (unsigned long long)__le64_to_cpu(sb->events));
587 }
588
589 static void brief_detail_super1(struct supertype *st)
590 {
591 struct mdp_superblock_1 *sb = st->sb;
592 int i;
593
594 if (sb->set_name[0]) {
595 printf(" name=");
596 print_quoted(sb->set_name);
597 }
598 printf(" UUID=");
599 for (i=0; i<16; i++) {
600 if ((i&3)==0 && i != 0) printf(":");
601 printf("%02x", sb->set_uuid[i]);
602 }
603 }
604
605 static void export_detail_super1(struct supertype *st)
606 {
607 struct mdp_superblock_1 *sb = st->sb;
608 int i;
609 int len = 32;
610
611 for (i=0; i<32; i++)
612 if (sb->set_name[i] == '\n' ||
613 sb->set_name[i] == '\0') {
614 len = i;
615 break;
616 }
617 if (len)
618 printf("MD_NAME=%.*s\n", len, sb->set_name);
619 }
620
621 #endif
622
623 static int match_home1(struct supertype *st, char *homehost)
624 {
625 struct mdp_superblock_1 *sb = st->sb;
626 int l = homehost ? strlen(homehost) : 0;
627
628 return (l > 0 && l < 32 &&
629 sb->set_name[l] == ':' &&
630 strncmp(sb->set_name, homehost, l) == 0);
631 }
632
633 static void uuid_from_super1(struct supertype *st, int uuid[4])
634 {
635 struct mdp_superblock_1 *super = st->sb;
636 char *cuuid = (char*)uuid;
637 int i;
638 for (i=0; i<16; i++)
639 cuuid[i] = super->set_uuid[i];
640 }
641
642 static void getinfo_super1(struct supertype *st, struct mdinfo *info, char *map)
643 {
644 struct mdp_superblock_1 *sb = st->sb;
645 int working = 0;
646 unsigned int i;
647 unsigned int role;
648 unsigned int map_disks = info->array.raid_disks;
649
650 memset(info, 0, sizeof(*info));
651 info->array.major_version = 1;
652 info->array.minor_version = st->minor_version;
653 info->array.patch_version = 0;
654 info->array.raid_disks = __le32_to_cpu(sb->raid_disks);
655 info->array.level = __le32_to_cpu(sb->level);
656 info->array.layout = __le32_to_cpu(sb->layout);
657 info->array.md_minor = -1;
658 info->array.ctime = __le64_to_cpu(sb->ctime);
659 info->array.utime = __le64_to_cpu(sb->utime);
660 info->array.chunk_size = __le32_to_cpu(sb->chunksize)*512;
661 info->array.state =
662 (__le64_to_cpu(sb->resync_offset) == MaxSector)
663 ? 1 : 0;
664
665 info->data_offset = __le64_to_cpu(sb->data_offset);
666 info->component_size = __le64_to_cpu(sb->size);
667 if (sb->feature_map & __le32_to_cpu(MD_FEATURE_BITMAP_OFFSET))
668 info->bitmap_offset = (int32_t)__le32_to_cpu(sb->bitmap_offset);
669
670 info->disk.major = 0;
671 info->disk.minor = 0;
672 info->disk.number = __le32_to_cpu(sb->dev_number);
673 if (__le32_to_cpu(sb->dev_number) >= __le32_to_cpu(sb->max_dev) ||
674 __le32_to_cpu(sb->dev_number) >= MAX_DEVS)
675 role = 0xfffe;
676 else
677 role = __le16_to_cpu(sb->dev_roles[__le32_to_cpu(sb->dev_number)]);
678
679 info->disk.raid_disk = -1;
680 switch(role) {
681 case 0xFFFF:
682 info->disk.state = 0; /* spare: not active, not sync, not faulty */
683 break;
684 case 0xFFFE:
685 info->disk.state = 1; /* faulty */
686 break;
687 default:
688 info->disk.state = 6; /* active and in sync */
689 info->disk.raid_disk = role;
690 }
691 if (sb->devflags & WriteMostly1)
692 info->disk.state |= (1 << MD_DISK_WRITEMOSTLY);
693 info->events = __le64_to_cpu(sb->events);
694 sprintf(info->text_version, "1.%d", st->minor_version);
695 info->safe_mode_delay = 200;
696
697 memcpy(info->uuid, sb->set_uuid, 16);
698
699 strncpy(info->name, sb->set_name, 32);
700 info->name[32] = 0;
701
702 if (sb->feature_map & __le32_to_cpu(MD_FEATURE_RECOVERY_OFFSET))
703 info->recovery_start = __le32_to_cpu(sb->recovery_offset);
704 else
705 info->recovery_start = MaxSector;
706
707 if (sb->feature_map & __le32_to_cpu(MD_FEATURE_RESHAPE_ACTIVE)) {
708 info->reshape_active = 1;
709 info->reshape_progress = __le64_to_cpu(sb->reshape_position);
710 info->new_level = __le32_to_cpu(sb->new_level);
711 info->delta_disks = __le32_to_cpu(sb->delta_disks);
712 info->new_layout = __le32_to_cpu(sb->new_layout);
713 info->new_chunk = __le32_to_cpu(sb->new_chunk)<<9;
714 if (info->delta_disks < 0)
715 info->array.raid_disks -= info->delta_disks;
716 } else
717 info->reshape_active = 0;
718
719 info->recovery_blocked = info->reshape_active;
720
721 if (map)
722 for (i=0; i<map_disks; i++)
723 map[i] = 0;
724 for (i = 0; i < __le32_to_cpu(sb->max_dev); i++) {
725 role = __le16_to_cpu(sb->dev_roles[i]);
726 if (/*role == 0xFFFF || */role < (unsigned) info->array.raid_disks) {
727 working++;
728 if (map && role < map_disks)
729 map[role] = 1;
730 }
731 }
732
733 info->array.working_disks = working;
734 }
735
736 static struct mdinfo *container_content1(struct supertype *st, char *subarray)
737 {
738 struct mdinfo *info;
739
740 if (subarray)
741 return NULL;
742
743 info = xmalloc(sizeof(*info));
744 getinfo_super1(st, info, NULL);
745 return info;
746 }
747
748 static int update_super1(struct supertype *st, struct mdinfo *info,
749 char *update,
750 char *devname, int verbose,
751 int uuid_set, char *homehost)
752 {
753 /* NOTE: for 'assemble' and 'force' we need to return non-zero
754 * if any change was made. For others, the return value is
755 * ignored.
756 */
757 int rv = 0;
758 struct mdp_superblock_1 *sb = st->sb;
759
760 if (strcmp(update, "force-one")==0) {
761 /* Not enough devices for a working array,
762 * so bring this one up-to-date
763 */
764 if (sb->events != __cpu_to_le64(info->events))
765 rv = 1;
766 sb->events = __cpu_to_le64(info->events);
767 } else if (strcmp(update, "force-array")==0) {
768 /* Degraded array and 'force' requests to
769 * maybe need to mark it 'clean'.
770 */
771 switch(__le32_to_cpu(sb->level)) {
772 case 5: case 4: case 6:
773 /* need to force clean */
774 if (sb->resync_offset != MaxSector)
775 rv = 1;
776 sb->resync_offset = MaxSector;
777 }
778 } else if (strcmp(update, "assemble")==0) {
779 int d = info->disk.number;
780 int want;
781 if (info->disk.state == 6)
782 want = info->disk.raid_disk;
783 else
784 want = 0xFFFF;
785 if (sb->dev_roles[d] != __cpu_to_le16(want)) {
786 sb->dev_roles[d] = __cpu_to_le16(want);
787 rv = 1;
788 }
789 if (info->reshape_active &&
790 sb->feature_map & __le32_to_cpu(MD_FEATURE_RESHAPE_ACTIVE) &&
791 info->delta_disks >= 0 &&
792 info->reshape_progress < __le64_to_cpu(sb->reshape_position)) {
793 sb->reshape_position = __cpu_to_le64(info->reshape_progress);
794 rv = 1;
795 }
796 if (info->reshape_active &&
797 sb->feature_map & __le32_to_cpu(MD_FEATURE_RESHAPE_ACTIVE) &&
798 info->delta_disks < 0 &&
799 info->reshape_progress > __le64_to_cpu(sb->reshape_position)) {
800 sb->reshape_position = __cpu_to_le64(info->reshape_progress);
801 rv = 1;
802 }
803 } else if (strcmp(update, "linear-grow-new") == 0) {
804 unsigned int i;
805 int rfd, fd;
806 unsigned int max = __le32_to_cpu(sb->max_dev);
807
808 for (i=0 ; i < max ; i++)
809 if (__le16_to_cpu(sb->dev_roles[i]) >= 0xfffe)
810 break;
811 sb->dev_number = __cpu_to_le32(i);
812 info->disk.number = i;
813 if (max >= __le32_to_cpu(sb->max_dev))
814 sb->max_dev = __cpu_to_le32(max+1);
815
816 if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
817 read(rfd, sb->device_uuid, 16) != 16) {
818 __u32 r[4] = {random(), random(), random(), random()};
819 memcpy(sb->device_uuid, r, 16);
820 }
821 if (rfd >= 0)
822 close(rfd);
823
824 sb->dev_roles[i] =
825 __cpu_to_le16(info->disk.raid_disk);
826
827 fd = open(devname, O_RDONLY);
828 if (fd >= 0) {
829 unsigned long long ds;
830 get_dev_size(fd, devname, &ds);
831 close(fd);
832 ds >>= 9;
833 if (__le64_to_cpu(sb->super_offset) <
834 __le64_to_cpu(sb->data_offset)) {
835 sb->data_size = __cpu_to_le64(
836 ds - __le64_to_cpu(sb->data_offset));
837 } else {
838 ds -= 8*2;
839 ds &= ~(unsigned long long)(4*2-1);
840 sb->super_offset = __cpu_to_le64(ds);
841 sb->data_size = __cpu_to_le64(
842 ds - __le64_to_cpu(sb->data_offset));
843 }
844 }
845 } else if (strcmp(update, "linear-grow-update") == 0) {
846 sb->raid_disks = __cpu_to_le32(info->array.raid_disks);
847 sb->dev_roles[info->disk.number] =
848 __cpu_to_le16(info->disk.raid_disk);
849 } else if (strcmp(update, "resync") == 0) {
850 /* make sure resync happens */
851 sb->resync_offset = 0ULL;
852 } else if (strcmp(update, "uuid") == 0) {
853 copy_uuid(sb->set_uuid, info->uuid, super1.swapuuid);
854
855 if (__le32_to_cpu(sb->feature_map)&MD_FEATURE_BITMAP_OFFSET) {
856 struct bitmap_super_s *bm;
857 bm = (struct bitmap_super_s*)(st->sb+MAX_SB_SIZE);
858 memcpy(bm->uuid, sb->set_uuid, 16);
859 }
860 } else if (strcmp(update, "no-bitmap") == 0) {
861 sb->feature_map &= ~__cpu_to_le32(MD_FEATURE_BITMAP_OFFSET);
862 } else if (strcmp(update, "bbl") == 0) {
863 /* only possible if there is room after the bitmap, or if
864 * there is no bitmap
865 */
866 unsigned long long sb_offset = __le64_to_cpu(sb->super_offset);
867 unsigned long long data_offset = __le64_to_cpu(sb->data_offset);
868 long bitmap_offset = (long)__le64_to_cpu(sb->bitmap_offset);
869 long bm_sectors = 0;
870 long space;
871
872 if (sb->feature_map & __cpu_to_le32(MD_FEATURE_BITMAP_OFFSET)) {
873 struct bitmap_super_s *bsb;
874 bsb = (struct bitmap_super_s *)(((char*)sb)+MAX_SB_SIZE);
875 bm_sectors = bitmap_sectors(bsb);
876 }
877
878 if (sb_offset < data_offset) {
879 /* 1.1 or 1.2. Put bbl just before data
880 */
881 long bb_offset;
882 space = data_offset - sb_offset;
883 bb_offset = space - 8;
884 if (bm_sectors && bitmap_offset > 0)
885 space -= (bitmap_offset + bm_sectors);
886 else
887 space -= 8; /* The superblock */
888 if (space >= 8) {
889 sb->bblog_size = __cpu_to_le16(8);
890 sb->bblog_offset = __cpu_to_le32(bb_offset);
891 }
892 } else {
893 /* 1.0 - Put bbl just before super block */
894 if (bm_sectors && bitmap_offset < 0)
895 space = -bitmap_offset - bm_sectors;
896 else
897 space = sb_offset - data_offset -
898 __le64_to_cpu(sb->data_size);
899 if (space >= 8) {
900 sb->bblog_size = __cpu_to_le16(8);
901 sb->bblog_offset = __cpu_to_le32((unsigned)-8);
902 }
903 }
904 } else if (strcmp(update, "no-bbl") == 0) {
905 if (sb->feature_map & __cpu_to_le32(MD_FEATURE_BAD_BLOCKS))
906 pr_err("Cannot remove active bbl from %s\n",devname);
907 else {
908 sb->bblog_size = 0;
909 sb->bblog_shift = 0;
910 sb->bblog_offset = 0;
911 }
912 } else if (strcmp(update, "homehost") == 0 &&
913 homehost) {
914 char *c;
915 update = "name";
916 c = strchr(sb->set_name, ':');
917 if (c)
918 strncpy(info->name, c+1, 31 - (c-sb->set_name));
919 else
920 strncpy(info->name, sb->set_name, 32);
921 info->name[32] = 0;
922 } else if (strcmp(update, "name") == 0) {
923 if (info->name[0] == 0)
924 sprintf(info->name, "%d", info->array.md_minor);
925 memset(sb->set_name, 0, sizeof(sb->set_name));
926 if (homehost &&
927 strchr(info->name, ':') == NULL &&
928 strlen(homehost)+1+strlen(info->name) < 32) {
929 strcpy(sb->set_name, homehost);
930 strcat(sb->set_name, ":");
931 strcat(sb->set_name, info->name);
932 } else
933 strcpy(sb->set_name, info->name);
934 } else if (strcmp(update, "devicesize") == 0 &&
935 __le64_to_cpu(sb->super_offset) <
936 __le64_to_cpu(sb->data_offset)) {
937 /* set data_size to device size less data_offset */
938 struct misc_dev_info *misc = (struct misc_dev_info*)
939 (st->sb + MAX_SB_SIZE + BM_SUPER_SIZE);
940 printf("Size was %llu\n", (unsigned long long)
941 __le64_to_cpu(sb->data_size));
942 sb->data_size = __cpu_to_le64(
943 misc->device_size - __le64_to_cpu(sb->data_offset));
944 printf("Size is %llu\n", (unsigned long long)
945 __le64_to_cpu(sb->data_size));
946 } else if (strcmp(update, "_reshape_progress")==0)
947 sb->reshape_position = __cpu_to_le64(info->reshape_progress);
948 else if (strcmp(update, "writemostly")==0)
949 sb->devflags |= WriteMostly1;
950 else if (strcmp(update, "readwrite")==0)
951 sb->devflags &= ~WriteMostly1;
952 else
953 rv = -1;
954
955 sb->sb_csum = calc_sb_1_csum(sb);
956 return rv;
957 }
958
959 static int init_super1(struct supertype *st, mdu_array_info_t *info,
960 unsigned long long size, char *name, char *homehost, int *uuid)
961 {
962 struct mdp_superblock_1 *sb;
963 int spares;
964 int rfd;
965 char defname[10];
966 int sbsize;
967
968 if (posix_memalign((void**)&sb, 4096, SUPER1_SIZE) != 0) {
969 pr_err("%s could not allocate superblock\n", __func__);
970 return 0;
971 }
972 memset(sb, 0, SUPER1_SIZE);
973
974 st->sb = sb;
975 if (info == NULL) {
976 /* zeroing superblock */
977 return 0;
978 }
979
980 spares = info->working_disks - info->active_disks;
981 if (info->raid_disks + spares > MAX_DEVS) {
982 pr_err("too many devices requested: %d+%d > %d\n",
983 info->raid_disks , spares, MAX_DEVS);
984 return 0;
985 }
986
987 sb->magic = __cpu_to_le32(MD_SB_MAGIC);
988 sb->major_version = __cpu_to_le32(1);
989 sb->feature_map = 0;
990 sb->pad0 = 0;
991
992 if (uuid)
993 copy_uuid(sb->set_uuid, uuid, super1.swapuuid);
994 else {
995 if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
996 read(rfd, sb->set_uuid, 16) != 16) {
997 __u32 r[4] = {random(), random(), random(), random()};
998 memcpy(sb->set_uuid, r, 16);
999 }
1000 if (rfd >= 0) close(rfd);
1001 }
1002
1003 if (name == NULL || *name == 0) {
1004 sprintf(defname, "%d", info->md_minor);
1005 name = defname;
1006 }
1007 if (homehost &&
1008 strchr(name, ':')== NULL &&
1009 strlen(homehost)+1+strlen(name) < 32) {
1010 strcpy(sb->set_name, homehost);
1011 strcat(sb->set_name, ":");
1012 strcat(sb->set_name, name);
1013 } else
1014 strcpy(sb->set_name, name);
1015
1016 sb->ctime = __cpu_to_le64((unsigned long long)time(0));
1017 sb->level = __cpu_to_le32(info->level);
1018 sb->layout = __cpu_to_le32(info->layout);
1019 sb->size = __cpu_to_le64(size*2ULL);
1020 sb->chunksize = __cpu_to_le32(info->chunk_size>>9);
1021 sb->raid_disks = __cpu_to_le32(info->raid_disks);
1022
1023 sb->data_offset = __cpu_to_le64(0);
1024 sb->data_size = __cpu_to_le64(0);
1025 sb->super_offset = __cpu_to_le64(0);
1026 sb->recovery_offset = __cpu_to_le64(0);
1027
1028 sb->utime = sb->ctime;
1029 sb->events = __cpu_to_le64(1);
1030 if (info->state & (1<<MD_SB_CLEAN))
1031 sb->resync_offset = MaxSector;
1032 else
1033 sb->resync_offset = 0;
1034 sbsize = sizeof(struct mdp_superblock_1) + 2 * (info->raid_disks + spares);
1035 sbsize = ROUND_UP(sbsize, 512);
1036 sb->max_dev = __cpu_to_le32((sbsize - sizeof(struct mdp_superblock_1)) / 2);
1037
1038 memset(sb->dev_roles, 0xff, MAX_SB_SIZE - sizeof(struct mdp_superblock_1));
1039
1040 return 1;
1041 }
1042
1043 struct devinfo {
1044 int fd;
1045 char *devname;
1046 mdu_disk_info_t disk;
1047 struct devinfo *next;
1048 };
1049 #ifndef MDASSEMBLE
1050 /* Add a device to the superblock being created */
1051 static int add_to_super1(struct supertype *st, mdu_disk_info_t *dk,
1052 int fd, char *devname)
1053 {
1054 struct mdp_superblock_1 *sb = st->sb;
1055 __u16 *rp = sb->dev_roles + dk->number;
1056 struct devinfo *di, **dip;
1057
1058 if ((dk->state & 6) == 6) /* active, sync */
1059 *rp = __cpu_to_le16(dk->raid_disk);
1060 else if ((dk->state & ~2) == 0) /* active or idle -> spare */
1061 *rp = 0xffff;
1062 else
1063 *rp = 0xfffe;
1064
1065 if (dk->number >= (int)__le32_to_cpu(sb->max_dev) &&
1066 __le32_to_cpu(sb->max_dev) < MAX_DEVS)
1067 sb->max_dev = __cpu_to_le32(dk->number+1);
1068
1069 sb->dev_number = __cpu_to_le32(dk->number);
1070 sb->devflags = 0; /* don't copy another disks flags */
1071 sb->sb_csum = calc_sb_1_csum(sb);
1072
1073 dip = (struct devinfo **)&st->info;
1074 while (*dip)
1075 dip = &(*dip)->next;
1076 di = xmalloc(sizeof(struct devinfo));
1077 di->fd = fd;
1078 di->devname = devname;
1079 di->disk = *dk;
1080 di->next = NULL;
1081 *dip = di;
1082
1083 return 0;
1084 }
1085 #endif
1086
1087 static void locate_bitmap1(struct supertype *st, int fd);
1088
1089 static int store_super1(struct supertype *st, int fd)
1090 {
1091 struct mdp_superblock_1 *sb = st->sb;
1092 unsigned long long sb_offset;
1093 struct align_fd afd;
1094 int sbsize;
1095 unsigned long long dsize;
1096
1097 if (!get_dev_size(fd, NULL, &dsize))
1098 return 1;
1099
1100 dsize >>= 9;
1101
1102 if (dsize < 24)
1103 return 2;
1104
1105 init_afd(&afd, fd);
1106
1107 /*
1108 * Calculate the position of the superblock.
1109 * It is always aligned to a 4K boundary and
1110 * depending on minor_version, it can be:
1111 * 0: At least 8K, but less than 12K, from end of device
1112 * 1: At start of device
1113 * 2: 4K from start of device.
1114 */
1115 switch(st->minor_version) {
1116 case 0:
1117 sb_offset = dsize;
1118 sb_offset -= 8*2;
1119 sb_offset &= ~(4*2-1);
1120 break;
1121 case 1:
1122 sb_offset = 0;
1123 break;
1124 case 2:
1125 sb_offset = 4*2;
1126 break;
1127 default:
1128 return -EINVAL;
1129 }
1130
1131
1132
1133 if (sb_offset != __le64_to_cpu(sb->super_offset) &&
1134 0 != __le64_to_cpu(sb->super_offset)
1135 ) {
1136 pr_err("internal error - sb_offset is wrong\n");
1137 abort();
1138 }
1139
1140 if (lseek64(fd, sb_offset << 9, 0)< 0LL)
1141 return 3;
1142
1143 sbsize = ROUND_UP(sizeof(*sb) + 2 * __le32_to_cpu(sb->max_dev), 512);
1144
1145 if (awrite(&afd, sb, sbsize) != sbsize)
1146 return 4;
1147
1148 if (sb->feature_map & __cpu_to_le32(MD_FEATURE_BITMAP_OFFSET)) {
1149 struct bitmap_super_s *bm = (struct bitmap_super_s*)
1150 (((char*)sb)+MAX_SB_SIZE);
1151 if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC) {
1152 locate_bitmap1(st, fd);
1153 if (awrite(&afd, bm, sizeof(*bm)) != sizeof(*bm))
1154 return 5;
1155 }
1156 }
1157 fsync(fd);
1158 return 0;
1159 }
1160
1161 static int load_super1(struct supertype *st, int fd, char *devname);
1162
1163 static unsigned long choose_bm_space(unsigned long devsize)
1164 {
1165 /* if the device is bigger than 8Gig, save 64k for bitmap usage,
1166 * if bigger than 200Gig, save 128k
1167 * NOTE: result must be multiple of 4K else bad things happen
1168 * on 4K-sector devices.
1169 */
1170 if (devsize < 64*2) return 0;
1171 if (devsize - 64*2 >= 200*1024*1024*2)
1172 return 128*2;
1173 if (devsize - 4*2 > 8*1024*1024*2)
1174 return 64*2;
1175 return 4*2;
1176 }
1177
1178 static void free_super1(struct supertype *st);
1179
1180 #ifndef MDASSEMBLE
1181 static int write_init_super1(struct supertype *st)
1182 {
1183 struct mdp_superblock_1 *sb = st->sb;
1184 struct supertype *refst;
1185 int rfd;
1186 int rv = 0;
1187 unsigned long long bm_space;
1188 unsigned long long reserved;
1189 struct devinfo *di;
1190 unsigned long long dsize, array_size;
1191 unsigned long long sb_offset, headroom;
1192
1193 for (di = st->info; di; di = di->next) {
1194 if (di->disk.state == 1)
1195 continue;
1196 if (di->fd < 0)
1197 continue;
1198
1199 while (Kill(di->devname, NULL, 0, -1, 1) == 0)
1200 ;
1201
1202 sb->dev_number = __cpu_to_le32(di->disk.number);
1203 if (di->disk.state & (1<<MD_DISK_WRITEMOSTLY))
1204 sb->devflags |= WriteMostly1;
1205 else
1206 sb->devflags &= ~WriteMostly1;
1207
1208 if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
1209 read(rfd, sb->device_uuid, 16) != 16) {
1210 __u32 r[4] = {random(), random(), random(), random()};
1211 memcpy(sb->device_uuid, r, 16);
1212 }
1213 if (rfd >= 0)
1214 close(rfd);
1215
1216 sb->events = 0;
1217
1218 refst = dup_super(st);
1219 if (load_super1(refst, di->fd, NULL)==0) {
1220 struct mdp_superblock_1 *refsb = refst->sb;
1221
1222 memcpy(sb->device_uuid, refsb->device_uuid, 16);
1223 if (memcmp(sb->set_uuid, refsb->set_uuid, 16)==0) {
1224 /* same array, so preserve events and
1225 * dev_number */
1226 sb->events = refsb->events;
1227 /* bugs in 2.6.17 and earlier mean the
1228 * dev_number chosen in Manage must be preserved
1229 */
1230 if (get_linux_version() >= 2006018)
1231 sb->dev_number = refsb->dev_number;
1232 }
1233 free_super1(refst);
1234 }
1235 free(refst);
1236
1237 if (!get_dev_size(di->fd, NULL, &dsize)) {
1238 rv = 1;
1239 goto error_out;
1240 }
1241 dsize >>= 9;
1242
1243 if (dsize < 24) {
1244 close(di->fd);
1245 rv = 2;
1246 goto error_out;
1247 }
1248
1249
1250 /*
1251 * Calculate the position of the superblock.
1252 * It is always aligned to a 4K boundary and
1253 * depending on minor_version, it can be:
1254 * 0: At least 8K, but less than 12K, from end of device
1255 * 1: At start of device
1256 * 2: 4K from start of device.
1257 * Depending on the array size, we might leave extra space
1258 * for a bitmap.
1259 * Also leave 4K for bad-block log.
1260 */
1261 array_size = __le64_to_cpu(sb->size);
1262 /* work out how much space we left for a bitmap,
1263 * Add 8 sectors for bad block log */
1264 bm_space = choose_bm_space(array_size) + 8;
1265
1266 /* We try to leave 0.1% at the start for reshape
1267 * operations, but limit this to 128Meg (0.1% of 10Gig)
1268 * which is plenty for efficient reshapes
1269 */
1270 headroom = 128 * 1024 * 2;
1271 while (headroom << 10 > array_size)
1272 headroom >>= 1;
1273
1274 switch(st->minor_version) {
1275 case 0:
1276 sb_offset = dsize;
1277 sb_offset -= 8*2;
1278 sb_offset &= ~(4*2-1);
1279 sb->super_offset = __cpu_to_le64(sb_offset);
1280 sb->data_offset = __cpu_to_le64(0);
1281 if (sb_offset < array_size + bm_space)
1282 bm_space = sb_offset - array_size;
1283 sb->data_size = __cpu_to_le64(sb_offset - bm_space);
1284 if (bm_space >= 8) {
1285 sb->bblog_size = __cpu_to_le16(8);
1286 sb->bblog_offset = __cpu_to_le32((unsigned)-8);
1287 }
1288 break;
1289 case 1:
1290 sb->super_offset = __cpu_to_le64(0);
1291 reserved = bm_space + 4*2;
1292 if (reserved < headroom)
1293 reserved = headroom;
1294 if (reserved + array_size > dsize)
1295 reserved = dsize - array_size;
1296 /* Try for multiple of 1Meg so it is nicely aligned */
1297 #define ONE_MEG (2*1024)
1298 if (reserved > ONE_MEG)
1299 reserved = (reserved/ONE_MEG) * ONE_MEG;
1300
1301 /* force 4K alignment */
1302 reserved &= ~7ULL;
1303
1304 sb->data_offset = __cpu_to_le64(reserved);
1305 sb->data_size = __cpu_to_le64(dsize - reserved);
1306 if (reserved >= 16) {
1307 sb->bblog_size = __cpu_to_le16(8);
1308 sb->bblog_offset = __cpu_to_le32(reserved-8);
1309 }
1310 break;
1311 case 2:
1312 sb_offset = 4*2;
1313 sb->super_offset = __cpu_to_le64(4*2);
1314 if (4*2 + 4*2 + bm_space + array_size
1315 > dsize)
1316 bm_space = dsize - array_size
1317 - 4*2 - 4*2;
1318
1319 reserved = bm_space + 4*2 + 4*2;
1320 if (reserved < headroom)
1321 reserved = headroom;
1322 if (reserved + array_size > dsize)
1323 reserved = dsize - array_size;
1324 /* Try for multiple of 1Meg so it is nicely aligned */
1325 #define ONE_MEG (2*1024)
1326 if (reserved > ONE_MEG)
1327 reserved = (reserved/ONE_MEG) * ONE_MEG;
1328
1329 /* force 4K alignment */
1330 reserved &= ~7ULL;
1331
1332 sb->data_offset = __cpu_to_le64(reserved);
1333 sb->data_size = __cpu_to_le64(dsize - reserved);
1334 if (reserved >= 16+16) {
1335 sb->bblog_size = __cpu_to_le16(8);
1336 /* '8' sectors for the bblog, and another '8'
1337 * because we want offset from superblock, not
1338 * start of device.
1339 */
1340 sb->bblog_offset = __cpu_to_le32(reserved-8-8);
1341 }
1342 break;
1343 default:
1344 pr_err("Failed to write invalid "
1345 "metadata format 1.%i to %s\n",
1346 st->minor_version, di->devname);
1347 rv = -EINVAL;
1348 goto out;
1349 }
1350
1351 sb->sb_csum = calc_sb_1_csum(sb);
1352 rv = store_super1(st, di->fd);
1353 if (rv == 0 && (__le32_to_cpu(sb->feature_map) & 1))
1354 rv = st->ss->write_bitmap(st, di->fd);
1355 close(di->fd);
1356 di->fd = -1;
1357 if (rv)
1358 goto error_out;
1359 }
1360 error_out:
1361 if (rv)
1362 pr_err("Failed to write metadata to %s\n",
1363 di->devname);
1364 out:
1365 return rv;
1366 }
1367 #endif
1368
1369 static int compare_super1(struct supertype *st, struct supertype *tst)
1370 {
1371 /*
1372 * return:
1373 * 0 same, or first was empty, and second was copied
1374 * 1 second had wrong number
1375 * 2 wrong uuid
1376 * 3 wrong other info
1377 */
1378 struct mdp_superblock_1 *first = st->sb;
1379 struct mdp_superblock_1 *second = tst->sb;
1380
1381 if (second->magic != __cpu_to_le32(MD_SB_MAGIC))
1382 return 1;
1383 if (second->major_version != __cpu_to_le32(1))
1384 return 1;
1385
1386 if (!first) {
1387 if (posix_memalign((void**)&first, 4096, SUPER1_SIZE) != 0) {
1388 pr_err("%s could not allocate superblock\n", __func__);
1389 return 1;
1390 }
1391 memcpy(first, second, SUPER1_SIZE);
1392 st->sb = first;
1393 return 0;
1394 }
1395 if (memcmp(first->set_uuid, second->set_uuid, 16)!= 0)
1396 return 2;
1397
1398 if (first->ctime != second->ctime ||
1399 first->level != second->level ||
1400 first->layout != second->layout ||
1401 first->size != second->size ||
1402 first->chunksize != second->chunksize ||
1403 first->raid_disks != second->raid_disks)
1404 return 3;
1405 return 0;
1406 }
1407
1408 static int load_super1(struct supertype *st, int fd, char *devname)
1409 {
1410 unsigned long long dsize;
1411 unsigned long long sb_offset;
1412 struct mdp_superblock_1 *super;
1413 int uuid[4];
1414 struct bitmap_super_s *bsb;
1415 struct misc_dev_info *misc;
1416 struct align_fd afd;
1417
1418 free_super1(st);
1419
1420 init_afd(&afd, fd);
1421
1422 if (st->ss == NULL || st->minor_version == -1) {
1423 int bestvers = -1;
1424 struct supertype tst;
1425 __u64 bestctime = 0;
1426 /* guess... choose latest ctime */
1427 memset(&tst, 0, sizeof(tst));
1428 tst.ss = &super1;
1429 for (tst.minor_version = 0; tst.minor_version <= 2 ; tst.minor_version++) {
1430 switch(load_super1(&tst, fd, devname)) {
1431 case 0: super = tst.sb;
1432 if (bestvers == -1 ||
1433 bestctime < __le64_to_cpu(super->ctime)) {
1434 bestvers = tst.minor_version;
1435 bestctime = __le64_to_cpu(super->ctime);
1436 }
1437 free(super);
1438 tst.sb = NULL;
1439 break;
1440 case 1: return 1; /*bad device */
1441 case 2: break; /* bad, try next */
1442 }
1443 }
1444 if (bestvers != -1) {
1445 int rv;
1446 tst.minor_version = bestvers;
1447 tst.ss = &super1;
1448 tst.max_devs = MAX_DEVS;
1449 rv = load_super1(&tst, fd, devname);
1450 if (rv == 0)
1451 *st = tst;
1452 return rv;
1453 }
1454 return 2;
1455 }
1456 if (!get_dev_size(fd, devname, &dsize))
1457 return 1;
1458 dsize >>= 9;
1459
1460 if (dsize < 24) {
1461 if (devname)
1462 pr_err("%s is too small for md: size is %llu sectors.\n",
1463 devname, dsize);
1464 return 1;
1465 }
1466
1467 /*
1468 * Calculate the position of the superblock.
1469 * It is always aligned to a 4K boundary and
1470 * depending on minor_version, it can be:
1471 * 0: At least 8K, but less than 12K, from end of device
1472 * 1: At start of device
1473 * 2: 4K from start of device.
1474 */
1475 switch(st->minor_version) {
1476 case 0:
1477 sb_offset = dsize;
1478 sb_offset -= 8*2;
1479 sb_offset &= ~(4*2-1);
1480 break;
1481 case 1:
1482 sb_offset = 0;
1483 break;
1484 case 2:
1485 sb_offset = 4*2;
1486 break;
1487 default:
1488 return -EINVAL;
1489 }
1490
1491 ioctl(fd, BLKFLSBUF, 0); /* make sure we read current data */
1492
1493
1494 if (lseek64(fd, sb_offset << 9, 0)< 0LL) {
1495 if (devname)
1496 pr_err("Cannot seek to superblock on %s: %s\n",
1497 devname, strerror(errno));
1498 return 1;
1499 }
1500
1501 if (posix_memalign((void**)&super, 4096, SUPER1_SIZE) != 0) {
1502 pr_err("%s could not allocate superblock\n",
1503 __func__);
1504 return 1;
1505 }
1506
1507 if (aread(&afd, super, MAX_SB_SIZE) != MAX_SB_SIZE) {
1508 if (devname)
1509 pr_err("Cannot read superblock on %s\n",
1510 devname);
1511 free(super);
1512 return 1;
1513 }
1514
1515 if (__le32_to_cpu(super->magic) != MD_SB_MAGIC) {
1516 if (devname)
1517 pr_err("No super block found on %s (Expected magic %08x, got %08x)\n",
1518 devname, MD_SB_MAGIC, __le32_to_cpu(super->magic));
1519 free(super);
1520 return 2;
1521 }
1522
1523 if (__le32_to_cpu(super->major_version) != 1) {
1524 if (devname)
1525 pr_err("Cannot interpret superblock on %s - version is %d\n",
1526 devname, __le32_to_cpu(super->major_version));
1527 free(super);
1528 return 2;
1529 }
1530 if (__le64_to_cpu(super->super_offset) != sb_offset) {
1531 if (devname)
1532 pr_err("No superblock found on %s (super_offset is wrong)\n",
1533 devname);
1534 free(super);
1535 return 2;
1536 }
1537 st->sb = super;
1538
1539 bsb = (struct bitmap_super_s *)(((char*)super)+MAX_SB_SIZE);
1540
1541 misc = (struct misc_dev_info*) (((char*)super)+MAX_SB_SIZE+BM_SUPER_SIZE);
1542 misc->device_size = dsize;
1543
1544 /* Now check on the bitmap superblock */
1545 if ((__le32_to_cpu(super->feature_map)&MD_FEATURE_BITMAP_OFFSET) == 0)
1546 return 0;
1547 /* Read the bitmap superblock and make sure it looks
1548 * valid. If it doesn't clear the bit. An --assemble --force
1549 * should get that written out.
1550 */
1551 locate_bitmap1(st, fd);
1552 if (aread(&afd, bsb, 512) != 512)
1553 goto no_bitmap;
1554
1555 uuid_from_super1(st, uuid);
1556 if (__le32_to_cpu(bsb->magic) != BITMAP_MAGIC ||
1557 memcmp(bsb->uuid, uuid, 16) != 0)
1558 goto no_bitmap;
1559 return 0;
1560
1561 no_bitmap:
1562 super->feature_map = __cpu_to_le32(__le32_to_cpu(super->feature_map)
1563 & ~MD_FEATURE_BITMAP_OFFSET);
1564 return 0;
1565 }
1566
1567
1568 static struct supertype *match_metadata_desc1(char *arg)
1569 {
1570 struct supertype *st = xcalloc(1, sizeof(*st));
1571
1572 st->container_dev = NoMdDev;
1573 st->ss = &super1;
1574 st->max_devs = MAX_DEVS;
1575 st->sb = NULL;
1576 /* leading zeros can be safely ignored. --detail generates them. */
1577 while (*arg == '0')
1578 arg++;
1579 if (strcmp(arg, "1.0") == 0 ||
1580 strcmp(arg, "1.00") == 0) {
1581 st->minor_version = 0;
1582 return st;
1583 }
1584 if (strcmp(arg, "1.1") == 0 ||
1585 strcmp(arg, "1.01") == 0
1586 ) {
1587 st->minor_version = 1;
1588 return st;
1589 }
1590 if (strcmp(arg, "1.2") == 0 ||
1591 #ifndef DEFAULT_OLD_METADATA /* ifdef in super0.c */
1592 strcmp(arg, "default") == 0 ||
1593 #endif /* DEFAULT_OLD_METADATA */
1594 strcmp(arg, "1.02") == 0) {
1595 st->minor_version = 2;
1596 return st;
1597 }
1598 if (strcmp(arg, "1") == 0 ||
1599 strcmp(arg, "default") == 0) {
1600 st->minor_version = -1;
1601 return st;
1602 }
1603
1604 free(st);
1605 return NULL;
1606 }
1607
1608 /* find available size on device with this devsize, using
1609 * superblock type st, and reserving 'reserve' sectors for
1610 * a possible bitmap
1611 */
1612 static __u64 avail_size1(struct supertype *st, __u64 devsize,
1613 unsigned long long data_offset)
1614 {
1615 struct mdp_superblock_1 *super = st->sb;
1616 int bmspace = 0;
1617 if (devsize < 24)
1618 return 0;
1619
1620 if (super == NULL)
1621 /* creating: allow suitable space for bitmap */
1622 bmspace = choose_bm_space(devsize);
1623 #ifndef MDASSEMBLE
1624 else if (__le32_to_cpu(super->feature_map)&MD_FEATURE_BITMAP_OFFSET) {
1625 /* hot-add. allow for actual size of bitmap */
1626 struct bitmap_super_s *bsb;
1627 bsb = (struct bitmap_super_s *)(((char*)super)+MAX_SB_SIZE);
1628 bmspace = bitmap_sectors(bsb);
1629 }
1630 #endif
1631 /* Allow space for bad block log */
1632 if (super && super->bblog_size)
1633 devsize -= __le16_to_cpu(super->bblog_size);
1634 else
1635 devsize -= 8;
1636
1637
1638 if (st->minor_version < 0)
1639 /* not specified, so time to set default */
1640 st->minor_version = 2;
1641
1642 if (data_offset != INVALID_SECTORS)
1643 switch(st->minor_version) {
1644 case 0:
1645 return devsize - data_offset - 8*2;
1646 case 1:
1647 case 2:
1648 return devsize - data_offset;
1649 default:
1650 return 0;
1651 }
1652
1653 devsize -= bmspace;
1654
1655 if (super == NULL && st->minor_version > 0) {
1656 /* haven't committed to a size yet, so allow some
1657 * slack for space for reshape.
1658 * Limit slack to 128M, but aim for about 0.1%
1659 */
1660 unsigned long long headroom = 128*1024*2;
1661 while ((headroom << 10) > devsize)
1662 headroom >>= 1;
1663 devsize -= headroom;
1664 }
1665 switch(st->minor_version) {
1666 case 0:
1667 /* at end */
1668 return ((devsize - 8*2 ) & ~(4*2-1));
1669 case 1:
1670 /* at start, 4K for superblock and possible bitmap */
1671 return devsize - 4*2;
1672 case 2:
1673 /* 4k from start, 4K for superblock and possible bitmap */
1674 return devsize - (4+4)*2;
1675 }
1676 return 0;
1677 }
1678
1679 static int
1680 add_internal_bitmap1(struct supertype *st,
1681 int *chunkp, int delay, int write_behind,
1682 unsigned long long size,
1683 int may_change, int major)
1684 {
1685 /*
1686 * If not may_change, then this is a 'Grow' without sysfs support for
1687 * bitmaps, and the bitmap must fit after the superblock at 1K offset.
1688 * If may_change, then this is create or a Grow with sysfs syupport,
1689 * and we can put the bitmap wherever we like.
1690 *
1691 * size is in sectors, chunk is in bytes !!!
1692 */
1693
1694 unsigned long long bits;
1695 unsigned long long max_bits;
1696 unsigned long long min_chunk;
1697 long offset;
1698 long bbl_offset, bbl_size;
1699 unsigned long long chunk = *chunkp;
1700 int room = 0;
1701 int creating = 0;
1702 struct mdp_superblock_1 *sb = st->sb;
1703 bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MAX_SB_SIZE);
1704 int uuid[4];
1705
1706
1707 if (__le64_to_cpu(sb->data_size) == 0)
1708 /* Must be creating the array, else data_size would be non-zero */
1709 creating = 1;
1710 switch(st->minor_version) {
1711 case 0:
1712 /* either 3K after the superblock (when hot-add),
1713 * or some amount of space before.
1714 */
1715 if (creating) {
1716 /* We are creating array, so we *know* how much room has
1717 * been left.
1718 */
1719 offset = 0;
1720 room = choose_bm_space(__le64_to_cpu(sb->size));
1721 bbl_size = 8;
1722 } else {
1723 room = __le64_to_cpu(sb->super_offset)
1724 - __le64_to_cpu(sb->data_offset)
1725 - __le64_to_cpu(sb->data_size);
1726 bbl_size = __le16_to_cpu(sb->bblog_size);
1727 if (bbl_size < 8)
1728 bbl_size = 8;
1729 bbl_offset = (__s32)__le32_to_cpu(sb->bblog_offset);
1730 if (bbl_size < -bbl_offset)
1731 bbl_size = -bbl_offset;
1732
1733 if (!may_change || (room < 3*2 &&
1734 __le32_to_cpu(sb->max_dev) <= 384)) {
1735 room = 3*2;
1736 offset = 1*2;
1737 bbl_size = 0;
1738 } else {
1739 offset = 0; /* means movable offset */
1740 }
1741 }
1742 break;
1743 case 1:
1744 case 2: /* between superblock and data */
1745 if (creating) {
1746 offset = 4*2;
1747 room = choose_bm_space(__le64_to_cpu(sb->size));
1748 bbl_size = 8;
1749 } else {
1750 room = __le64_to_cpu(sb->data_offset)
1751 - __le64_to_cpu(sb->super_offset);
1752 bbl_size = __le16_to_cpu(sb->bblog_size);
1753 if (bbl_size)
1754 room = __le32_to_cpu(sb->bblog_offset) + bbl_size;
1755 else
1756 bbl_size = 8;
1757
1758 if (!may_change) {
1759 room -= 2; /* Leave 1K for superblock */
1760 offset = 2;
1761 bbl_size = 0;
1762 } else {
1763 room -= 4*2; /* leave 4K for superblock */
1764 offset = 4*2;
1765 }
1766 }
1767 break;
1768 default:
1769 return 0;
1770 }
1771
1772 room -= bbl_size;
1773 if (chunk == UnSet && room > 128*2)
1774 /* Limit to 128K of bitmap when chunk size not requested */
1775 room = 128*2;
1776
1777 max_bits = (room * 512 - sizeof(bitmap_super_t)) * 8;
1778
1779 min_chunk = 4096; /* sub-page chunks don't work yet.. */
1780 bits = (size*512)/min_chunk +1;
1781 while (bits > max_bits) {
1782 min_chunk *= 2;
1783 bits = (bits+1)/2;
1784 }
1785 if (chunk == UnSet) {
1786 /* For practical purpose, 64Meg is a good
1787 * default chunk size for internal bitmaps.
1788 */
1789 chunk = min_chunk;
1790 if (chunk < 64*1024*1024)
1791 chunk = 64*1024*1024;
1792 } else if (chunk < min_chunk)
1793 return 0; /* chunk size too small */
1794 if (chunk == 0) /* rounding problem */
1795 return 0;
1796
1797 if (offset == 0) {
1798 /* start bitmap on a 4K boundary with enough space for
1799 * the bitmap
1800 */
1801 bits = (size*512) / chunk + 1;
1802 room = ((bits+7)/8 + sizeof(bitmap_super_t) +4095)/4096;
1803 room *= 8; /* convert 4K blocks to sectors */
1804 offset = -room - bbl_size;
1805 }
1806
1807 sb->bitmap_offset = (int32_t)__cpu_to_le32(offset);
1808
1809 sb->feature_map = __cpu_to_le32(__le32_to_cpu(sb->feature_map)
1810 | MD_FEATURE_BITMAP_OFFSET);
1811 memset(bms, 0, sizeof(*bms));
1812 bms->magic = __cpu_to_le32(BITMAP_MAGIC);
1813 bms->version = __cpu_to_le32(major);
1814 uuid_from_super1(st, uuid);
1815 memcpy(bms->uuid, uuid, 16);
1816 bms->chunksize = __cpu_to_le32(chunk);
1817 bms->daemon_sleep = __cpu_to_le32(delay);
1818 bms->sync_size = __cpu_to_le64(size);
1819 bms->write_behind = __cpu_to_le32(write_behind);
1820
1821 *chunkp = chunk;
1822 return 1;
1823 }
1824
1825 static void locate_bitmap1(struct supertype *st, int fd)
1826 {
1827 unsigned long long offset;
1828 struct mdp_superblock_1 *sb;
1829 int mustfree = 0;
1830
1831 if (!st->sb) {
1832 if (st->ss->load_super(st, fd, NULL))
1833 return; /* no error I hope... */
1834 mustfree = 1;
1835 }
1836 sb = st->sb;
1837
1838 offset = __le64_to_cpu(sb->super_offset);
1839 offset += (int32_t) __le32_to_cpu(sb->bitmap_offset);
1840 if (mustfree)
1841 free(sb);
1842 lseek64(fd, offset<<9, 0);
1843 }
1844
1845 static int write_bitmap1(struct supertype *st, int fd)
1846 {
1847 struct mdp_superblock_1 *sb = st->sb;
1848 bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb)+MAX_SB_SIZE);
1849 int rv = 0;
1850 void *buf;
1851 int towrite, n;
1852 struct align_fd afd;
1853
1854 init_afd(&afd, fd);
1855
1856 locate_bitmap1(st, fd);
1857
1858 if (posix_memalign(&buf, 4096, 4096))
1859 return -ENOMEM;
1860
1861 memset(buf, 0xff, 4096);
1862 memcpy(buf, (char *)bms, sizeof(bitmap_super_t));
1863
1864 towrite = __le64_to_cpu(bms->sync_size) / (__le32_to_cpu(bms->chunksize)>>9);
1865 towrite = (towrite+7) >> 3; /* bits to bytes */
1866 towrite += sizeof(bitmap_super_t);
1867 towrite = ROUND_UP(towrite, 512);
1868 while (towrite > 0) {
1869 n = towrite;
1870 if (n > 4096)
1871 n = 4096;
1872 n = awrite(&afd, buf, n);
1873 if (n > 0)
1874 towrite -= n;
1875 else
1876 break;
1877 memset(buf, 0xff, 4096);
1878 }
1879 fsync(fd);
1880 if (towrite)
1881 rv = -2;
1882
1883 free(buf);
1884 return rv;
1885 }
1886
1887 static void free_super1(struct supertype *st)
1888 {
1889 if (st->sb)
1890 free(st->sb);
1891 while (st->info) {
1892 struct devinfo *di = st->info;
1893 st->info = di->next;
1894 if (di->fd >= 0)
1895 close(di->fd);
1896 free(di);
1897 }
1898 st->sb = NULL;
1899 }
1900
1901 #ifndef MDASSEMBLE
1902 static int validate_geometry1(struct supertype *st, int level,
1903 int layout, int raiddisks,
1904 int *chunk, unsigned long long size,
1905 unsigned long long data_offset,
1906 char *subdev, unsigned long long *freesize,
1907 int verbose)
1908 {
1909 unsigned long long ldsize;
1910 int fd;
1911
1912 if (level == LEVEL_CONTAINER) {
1913 if (verbose)
1914 pr_err("1.x metadata does not support containers\n");
1915 return 0;
1916 }
1917 if (chunk && *chunk == UnSet)
1918 *chunk = DEFAULT_CHUNK;
1919
1920 if (!subdev)
1921 return 1;
1922
1923 fd = open(subdev, O_RDONLY|O_EXCL, 0);
1924 if (fd < 0) {
1925 if (verbose)
1926 pr_err("super1.x cannot open %s: %s\n",
1927 subdev, strerror(errno));
1928 return 0;
1929 }
1930
1931 if (!get_dev_size(fd, subdev, &ldsize)) {
1932 close(fd);
1933 return 0;
1934 }
1935 close(fd);
1936
1937 *freesize = avail_size1(st, ldsize >> 9, data_offset);
1938 return 1;
1939 }
1940 #endif /* MDASSEMBLE */
1941
1942 struct superswitch super1 = {
1943 #ifndef MDASSEMBLE
1944 .examine_super = examine_super1,
1945 .brief_examine_super = brief_examine_super1,
1946 .export_examine_super = export_examine_super1,
1947 .detail_super = detail_super1,
1948 .brief_detail_super = brief_detail_super1,
1949 .export_detail_super = export_detail_super1,
1950 .write_init_super = write_init_super1,
1951 .validate_geometry = validate_geometry1,
1952 .add_to_super = add_to_super1,
1953 #endif
1954 .match_home = match_home1,
1955 .uuid_from_super = uuid_from_super1,
1956 .getinfo_super = getinfo_super1,
1957 .container_content = container_content1,
1958 .update_super = update_super1,
1959 .init_super = init_super1,
1960 .store_super = store_super1,
1961 .compare_super = compare_super1,
1962 .load_super = load_super1,
1963 .match_metadata_desc = match_metadata_desc1,
1964 .avail_size = avail_size1,
1965 .add_internal_bitmap = add_internal_bitmap1,
1966 .locate_bitmap = locate_bitmap1,
1967 .write_bitmap = write_bitmap1,
1968 .free_super = free_super1,
1969 #if __BYTE_ORDER == BIG_ENDIAN
1970 .swapuuid = 0,
1971 #else
1972 .swapuuid = 1,
1973 #endif
1974 .name = "1.x",
1975 };