2 * mdadm - Intel(R) Matrix Storage Manager Support
4 * Copyright (C) 2002-2008 Intel Corporation
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20 #define HAVE_STDINT_H 1
24 #include "platform-intel.h"
30 /* MPB == Metadata Parameter Block */
31 #define MPB_SIGNATURE "Intel Raid ISM Cfg Sig. "
32 #define MPB_SIG_LEN (strlen(MPB_SIGNATURE))
33 #define MPB_VERSION_RAID0 "1.0.00"
34 #define MPB_VERSION_RAID1 "1.1.00"
35 #define MPB_VERSION_MANY_VOLUMES_PER_ARRAY "1.2.00"
36 #define MPB_VERSION_3OR4_DISK_ARRAY "1.2.01"
37 #define MPB_VERSION_RAID5 "1.2.02"
38 #define MPB_VERSION_5OR6_DISK_ARRAY "1.2.04"
39 #define MPB_VERSION_CNG "1.2.06"
40 #define MPB_VERSION_ATTRIBS "1.3.00"
41 #define MAX_SIGNATURE_LENGTH 32
42 #define MAX_RAID_SERIAL_LEN 16
44 #define MPB_ATTRIB_CHECKSUM_VERIFY __cpu_to_le32(0x80000000)
45 #define MPB_ATTRIB_PM __cpu_to_le32(0x40000000)
46 #define MPB_ATTRIB_2TB __cpu_to_le32(0x20000000)
47 #define MPB_ATTRIB_RAID0 __cpu_to_le32(0x00000001)
48 #define MPB_ATTRIB_RAID1 __cpu_to_le32(0x00000002)
49 #define MPB_ATTRIB_RAID10 __cpu_to_le32(0x00000004)
50 #define MPB_ATTRIB_RAID1E __cpu_to_le32(0x00000008)
51 #define MPB_ATTRIB_RAID5 __cpu_to_le32(0x00000010)
52 #define MPB_ATTRIB_RAIDCNG __cpu_to_le32(0x00000020)
54 #define MPB_SECTOR_CNT 418
55 #define IMSM_RESERVED_SECTORS 4096
56 #define SECT_PER_MB_SHIFT 11
58 /* Disk configuration info. */
59 #define IMSM_MAX_DEVICES 255
61 __u8 serial
[MAX_RAID_SERIAL_LEN
];/* 0xD8 - 0xE7 ascii serial number */
62 __u32 total_blocks
; /* 0xE8 - 0xEB total blocks */
63 __u32 scsi_id
; /* 0xEC - 0xEF scsi ID */
64 #define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
65 #define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
66 #define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
67 __u32 status
; /* 0xF0 - 0xF3 */
68 __u32 owner_cfg_num
; /* which config 0,1,2... owns this disk */
69 #define IMSM_DISK_FILLERS 4
70 __u32 filler
[IMSM_DISK_FILLERS
]; /* 0xF4 - 0x107 MPB_DISK_FILLERS for future expansion */
73 /* RAID map configuration infos. */
75 __u32 pba_of_lba0
; /* start address of partition */
76 __u32 blocks_per_member
;/* blocks per member */
77 __u32 num_data_stripes
; /* number of data stripes */
78 __u16 blocks_per_strip
;
79 __u8 map_state
; /* Normal, Uninitialized, Degraded, Failed */
80 #define IMSM_T_STATE_NORMAL 0
81 #define IMSM_T_STATE_UNINITIALIZED 1
82 #define IMSM_T_STATE_DEGRADED 2
83 #define IMSM_T_STATE_FAILED 3
85 #define IMSM_T_RAID0 0
86 #define IMSM_T_RAID1 1
87 #define IMSM_T_RAID5 5 /* since metadata version 1.2.02 ? */
88 __u8 num_members
; /* number of member disks */
89 __u8 num_domains
; /* number of parity domains */
90 __u8 failed_disk_num
; /* valid only when state is degraded */
92 __u32 filler
[7]; /* expansion area */
93 #define IMSM_ORD_REBUILD (1 << 24)
94 __u32 disk_ord_tbl
[1]; /* disk_ord_tbl[num_members],
95 * top byte contains some flags
97 } __attribute__ ((packed
));
100 __u32 curr_migr_unit
;
101 __u32 checkpoint_id
; /* id to access curr_migr_unit */
102 __u8 migr_state
; /* Normal or Migrating */
104 #define MIGR_REBUILD 1
105 #define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
106 #define MIGR_GEN_MIGR 3
107 #define MIGR_STATE_CHANGE 4
108 #define MIGR_REPAIR 5
109 __u8 migr_type
; /* Initializing, Rebuilding, ... */
111 __u8 fs_state
; /* fast-sync state for CnG (0xff == disabled) */
112 __u16 verify_errors
; /* number of mismatches */
113 __u16 bad_blocks
; /* number of bad blocks during verify */
115 struct imsm_map map
[1];
116 /* here comes another one if migr_state */
117 } __attribute__ ((packed
));
120 __u8 volume
[MAX_RAID_SERIAL_LEN
];
123 #define DEV_BOOTABLE __cpu_to_le32(0x01)
124 #define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
125 #define DEV_READ_COALESCING __cpu_to_le32(0x04)
126 #define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
127 #define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
128 #define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
129 #define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
130 #define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
131 #define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
132 #define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
133 #define DEV_CLONE_N_GO __cpu_to_le32(0x400)
134 #define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
135 #define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
136 __u32 status
; /* Persistent RaidDev status */
137 __u32 reserved_blocks
; /* Reserved blocks at beginning of volume */
141 __u8 cng_master_disk
;
145 #define IMSM_DEV_FILLERS 10
146 __u32 filler
[IMSM_DEV_FILLERS
];
148 } __attribute__ ((packed
));
151 __u8 sig
[MAX_SIGNATURE_LENGTH
]; /* 0x00 - 0x1F */
152 __u32 check_sum
; /* 0x20 - 0x23 MPB Checksum */
153 __u32 mpb_size
; /* 0x24 - 0x27 Size of MPB */
154 __u32 family_num
; /* 0x28 - 0x2B Checksum from first time this config was written */
155 __u32 generation_num
; /* 0x2C - 0x2F Incremented each time this array's MPB is written */
156 __u32 error_log_size
; /* 0x30 - 0x33 in bytes */
157 __u32 attributes
; /* 0x34 - 0x37 */
158 __u8 num_disks
; /* 0x38 Number of configured disks */
159 __u8 num_raid_devs
; /* 0x39 Number of configured volumes */
160 __u8 error_log_pos
; /* 0x3A */
161 __u8 fill
[1]; /* 0x3B */
162 __u32 cache_size
; /* 0x3c - 0x40 in mb */
163 __u32 orig_family_num
; /* 0x40 - 0x43 original family num */
164 __u32 pwr_cycle_count
; /* 0x44 - 0x47 simulated power cycle count for array */
165 __u32 bbm_log_size
; /* 0x48 - 0x4B - size of bad Block Mgmt Log in bytes */
166 #define IMSM_FILLERS 35
167 __u32 filler
[IMSM_FILLERS
]; /* 0x4C - 0xD7 RAID_MPB_FILLERS */
168 struct imsm_disk disk
[1]; /* 0xD8 diskTbl[numDisks] */
169 /* here comes imsm_dev[num_raid_devs] */
170 /* here comes BBM logs */
171 } __attribute__ ((packed
));
173 #define BBM_LOG_MAX_ENTRIES 254
175 struct bbm_log_entry
{
176 __u64 defective_block_start
;
177 #define UNREADABLE 0xFFFFFFFF
178 __u32 spare_block_offset
;
179 __u16 remapped_marked_count
;
181 } __attribute__ ((__packed__
));
184 __u32 signature
; /* 0xABADB10C */
186 __u32 reserved_spare_block_count
; /* 0 */
187 __u32 reserved
; /* 0xFFFF */
188 __u64 first_spare_lba
;
189 struct bbm_log_entry mapped_block_entries
[BBM_LOG_MAX_ENTRIES
];
190 } __attribute__ ((__packed__
));
194 static char *map_state_str
[] = { "normal", "uninitialized", "degraded", "failed" };
197 static __u8
migr_type(struct imsm_dev
*dev
)
199 if (dev
->vol
.migr_type
== MIGR_VERIFY
&&
200 dev
->status
& DEV_VERIFY_AND_FIX
)
203 return dev
->vol
.migr_type
;
206 static void set_migr_type(struct imsm_dev
*dev
, __u8 migr_type
)
208 /* for compatibility with older oroms convert MIGR_REPAIR, into
209 * MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status
211 if (migr_type
== MIGR_REPAIR
) {
212 dev
->vol
.migr_type
= MIGR_VERIFY
;
213 dev
->status
|= DEV_VERIFY_AND_FIX
;
215 dev
->vol
.migr_type
= migr_type
;
216 dev
->status
&= ~DEV_VERIFY_AND_FIX
;
220 static unsigned int sector_count(__u32 bytes
)
222 return ((bytes
+ (512-1)) & (~(512-1))) / 512;
225 static unsigned int mpb_sectors(struct imsm_super
*mpb
)
227 return sector_count(__le32_to_cpu(mpb
->mpb_size
));
231 struct imsm_dev
*dev
;
232 struct intel_dev
*next
;
240 /* internal representation of IMSM metadata */
243 void *buf
; /* O_DIRECT buffer for reading/writing metadata */
244 struct imsm_super
*anchor
; /* immovable parameters */
246 size_t len
; /* size of the 'buf' allocation */
247 void *next_buf
; /* for realloc'ing buf from the manager */
249 int updates_pending
; /* count of pending updates for mdmon */
250 int current_vol
; /* index of raid device undergoing creation */
251 __u32 create_offset
; /* common start for 'current_vol' */
252 __u32 random
; /* random data for seeding new family numbers */
253 struct intel_dev
*devlist
;
257 __u8 serial
[MAX_RAID_SERIAL_LEN
];
260 struct imsm_disk disk
;
263 struct extent
*e
; /* for determining freespace @ create */
264 int raiddisk
; /* slot to fill in autolayout */
267 struct dl
*disk_mgmt_list
; /* list of disks to add/remove while mdmon
269 struct dl
*missing
; /* disks removed while we weren't looking */
270 struct bbm_log
*bbm_log
;
271 const char *hba
; /* device path of the raid controller for this metadata */
272 const struct imsm_orom
*orom
; /* platform firmware support */
273 struct intel_super
*next
; /* (temp) list for disambiguating family_num */
277 struct imsm_disk disk
;
278 #define IMSM_UNKNOWN_OWNER (-1)
280 struct intel_disk
*next
;
284 unsigned long long start
, size
;
287 /* definition of messages passed to imsm_process_update */
288 enum imsm_update_type
{
289 update_activate_spare
,
293 update_add_remove_disk
,
294 update_reshape_container_disks
,
297 struct imsm_update_activate_spare
{
298 enum imsm_update_type type
;
302 struct imsm_update_activate_spare
*next
;
316 struct imsm_update_reshape
{
317 enum imsm_update_type type
;
320 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
324 __u8 serial
[MAX_RAID_SERIAL_LEN
];
327 struct imsm_update_create_array
{
328 enum imsm_update_type type
;
333 struct imsm_update_kill_array
{
334 enum imsm_update_type type
;
338 struct imsm_update_rename_array
{
339 enum imsm_update_type type
;
340 __u8 name
[MAX_RAID_SERIAL_LEN
];
344 struct imsm_update_add_remove_disk
{
345 enum imsm_update_type type
;
348 static struct supertype
*match_metadata_desc_imsm(char *arg
)
350 struct supertype
*st
;
352 if (strcmp(arg
, "imsm") != 0 &&
353 strcmp(arg
, "default") != 0
357 st
= malloc(sizeof(*st
));
360 memset(st
, 0, sizeof(*st
));
361 st
->container_dev
= NoMdDev
;
362 st
->ss
= &super_imsm
;
363 st
->max_devs
= IMSM_MAX_DEVICES
;
364 st
->minor_version
= 0;
370 static __u8
*get_imsm_version(struct imsm_super
*mpb
)
372 return &mpb
->sig
[MPB_SIG_LEN
];
376 /* retrieve a disk directly from the anchor when the anchor is known to be
377 * up-to-date, currently only at load time
379 static struct imsm_disk
*__get_imsm_disk(struct imsm_super
*mpb
, __u8 index
)
381 if (index
>= mpb
->num_disks
)
383 return &mpb
->disk
[index
];
386 /* retrieve the disk description based on a index of the disk
389 static struct dl
*get_imsm_dl_disk(struct intel_super
*super
, __u8 index
)
393 for (d
= super
->disks
; d
; d
= d
->next
)
394 if (d
->index
== index
)
399 /* retrieve a disk from the parsed metadata */
400 static struct imsm_disk
*get_imsm_disk(struct intel_super
*super
, __u8 index
)
404 dl
= get_imsm_dl_disk(super
, index
);
411 /* generate a checksum directly from the anchor when the anchor is known to be
412 * up-to-date, currently only at load or write_super after coalescing
414 static __u32
__gen_imsm_checksum(struct imsm_super
*mpb
)
416 __u32 end
= mpb
->mpb_size
/ sizeof(end
);
417 __u32
*p
= (__u32
*) mpb
;
421 sum
+= __le32_to_cpu(*p
);
425 return sum
- __le32_to_cpu(mpb
->check_sum
);
428 static size_t sizeof_imsm_map(struct imsm_map
*map
)
430 return sizeof(struct imsm_map
) + sizeof(__u32
) * (map
->num_members
- 1);
433 struct imsm_map
*get_imsm_map(struct imsm_dev
*dev
, int second_map
)
435 struct imsm_map
*map
= &dev
->vol
.map
[0];
437 if (second_map
&& !dev
->vol
.migr_state
)
439 else if (second_map
) {
442 return ptr
+ sizeof_imsm_map(map
);
448 /* return the size of the device.
449 * migr_state increases the returned size if map[0] were to be duplicated
451 static size_t sizeof_imsm_dev(struct imsm_dev
*dev
, int migr_state
)
453 size_t size
= sizeof(*dev
) - sizeof(struct imsm_map
) +
454 sizeof_imsm_map(get_imsm_map(dev
, 0));
456 /* migrating means an additional map */
457 if (dev
->vol
.migr_state
)
458 size
+= sizeof_imsm_map(get_imsm_map(dev
, 1));
460 size
+= sizeof_imsm_map(get_imsm_map(dev
, 0));
466 /* retrieve disk serial number list from a metadata update */
467 static struct disk_info
*get_disk_info(struct imsm_update_create_array
*update
)
470 struct disk_info
*inf
;
472 inf
= u
+ sizeof(*update
) - sizeof(struct imsm_dev
) +
473 sizeof_imsm_dev(&update
->dev
, 0);
479 static struct imsm_dev
*__get_imsm_dev(struct imsm_super
*mpb
, __u8 index
)
485 if (index
>= mpb
->num_raid_devs
)
488 /* devices start after all disks */
489 offset
= ((void *) &mpb
->disk
[mpb
->num_disks
]) - _mpb
;
491 for (i
= 0; i
<= index
; i
++)
493 return _mpb
+ offset
;
495 offset
+= sizeof_imsm_dev(_mpb
+ offset
, 0);
500 static struct imsm_dev
*get_imsm_dev(struct intel_super
*super
, __u8 index
)
502 struct intel_dev
*dv
;
504 if (index
>= super
->anchor
->num_raid_devs
)
506 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
507 if (dv
->index
== index
)
515 * == 1 get second map
516 * == -1 than get map according to the current migr_state
518 static __u32
get_imsm_ord_tbl_ent(struct imsm_dev
*dev
,
522 struct imsm_map
*map
;
524 if (second_map
== -1) {
525 if (dev
->vol
.migr_state
)
526 map
= get_imsm_map(dev
, 1);
528 map
= get_imsm_map(dev
, 0);
530 map
= get_imsm_map(dev
, second_map
);
533 /* top byte identifies disk under rebuild */
534 return __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
537 #define ord_to_idx(ord) (((ord) << 8) >> 8)
538 static __u32
get_imsm_disk_idx(struct imsm_dev
*dev
, int slot
, int second_map
)
540 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, second_map
);
542 return ord_to_idx(ord
);
545 static void set_imsm_ord_tbl_ent(struct imsm_map
*map
, int slot
, __u32 ord
)
547 map
->disk_ord_tbl
[slot
] = __cpu_to_le32(ord
);
550 static int get_imsm_disk_slot(struct imsm_map
*map
, unsigned idx
)
555 for (slot
= 0; slot
< map
->num_members
; slot
++) {
556 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
557 if (ord_to_idx(ord
) == idx
)
564 static int get_imsm_raid_level(struct imsm_map
*map
)
566 if (map
->raid_level
== 1) {
567 if (map
->num_members
== 2)
573 return map
->raid_level
;
576 static int cmp_extent(const void *av
, const void *bv
)
578 const struct extent
*a
= av
;
579 const struct extent
*b
= bv
;
580 if (a
->start
< b
->start
)
582 if (a
->start
> b
->start
)
587 static int count_memberships(struct dl
*dl
, struct intel_super
*super
)
592 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
593 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
594 struct imsm_map
*map
= get_imsm_map(dev
, 0);
596 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
603 static struct extent
*get_extents(struct intel_super
*super
, struct dl
*dl
)
605 /* find a list of used extents on the given physical device */
606 struct extent
*rv
, *e
;
608 int memberships
= count_memberships(dl
, super
);
609 __u32 reservation
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
611 rv
= malloc(sizeof(struct extent
) * (memberships
+ 1));
616 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
617 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
618 struct imsm_map
*map
= get_imsm_map(dev
, 0);
620 if (get_imsm_disk_slot(map
, dl
->index
) >= 0) {
621 e
->start
= __le32_to_cpu(map
->pba_of_lba0
);
622 e
->size
= __le32_to_cpu(map
->blocks_per_member
);
626 qsort(rv
, memberships
, sizeof(*rv
), cmp_extent
);
628 /* determine the start of the metadata
629 * when no raid devices are defined use the default
630 * ...otherwise allow the metadata to truncate the value
631 * as is the case with older versions of imsm
634 struct extent
*last
= &rv
[memberships
- 1];
637 remainder
= __le32_to_cpu(dl
->disk
.total_blocks
) -
638 (last
->start
+ last
->size
);
639 /* round down to 1k block to satisfy precision of the kernel
643 /* make sure remainder is still sane */
644 if (remainder
< (unsigned)ROUND_UP(super
->len
, 512) >> 9)
645 remainder
= ROUND_UP(super
->len
, 512) >> 9;
646 if (reservation
> remainder
)
647 reservation
= remainder
;
649 e
->start
= __le32_to_cpu(dl
->disk
.total_blocks
) - reservation
;
654 /* try to determine how much space is reserved for metadata from
655 * the last get_extents() entry, otherwise fallback to the
658 static __u32
imsm_reserved_sectors(struct intel_super
*super
, struct dl
*dl
)
664 /* for spares just return a minimal reservation which will grow
665 * once the spare is picked up by an array
668 return MPB_SECTOR_CNT
;
670 e
= get_extents(super
, dl
);
672 return MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
674 /* scroll to last entry */
675 for (i
= 0; e
[i
].size
; i
++)
678 rv
= __le32_to_cpu(dl
->disk
.total_blocks
) - e
[i
].start
;
685 static int is_spare(struct imsm_disk
*disk
)
687 return (disk
->status
& SPARE_DISK
) == SPARE_DISK
;
690 static int is_configured(struct imsm_disk
*disk
)
692 return (disk
->status
& CONFIGURED_DISK
) == CONFIGURED_DISK
;
695 static int is_failed(struct imsm_disk
*disk
)
697 return (disk
->status
& FAILED_DISK
) == FAILED_DISK
;
700 /* Return minimum size of a spare that can be used in this array*/
701 static unsigned long long min_acceptable_spare_size_imsm(struct supertype
*st
)
703 struct intel_super
*super
= st
->sb
;
707 unsigned long long rv
= 0;
711 /* find first active disk in array */
713 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
717 /* find last lba used by subarrays */
718 e
= get_extents(super
, dl
);
721 for (i
= 0; e
[i
].size
; i
++)
724 rv
= e
[i
-1].start
+ e
[i
-1].size
;
726 /* add the amount of space needed for metadata */
727 rv
= rv
+ MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
732 static __u64
blocks_per_migr_unit(struct imsm_dev
*dev
);
734 static void print_imsm_dev(struct imsm_dev
*dev
, char *uuid
, int disk_idx
)
738 struct imsm_map
*map
= get_imsm_map(dev
, 0);
739 struct imsm_map
*map2
= get_imsm_map(dev
, 1);
743 printf("[%.16s]:\n", dev
->volume
);
744 printf(" UUID : %s\n", uuid
);
745 printf(" RAID Level : %d", get_imsm_raid_level(map
));
747 printf(" <-- %d", get_imsm_raid_level(map2
));
749 printf(" Members : %d", map
->num_members
);
751 printf(" <-- %d", map2
->num_members
);
753 printf(" Slots : [");
754 for (i
= 0; i
< map
->num_members
; i
++) {
755 ord
= get_imsm_ord_tbl_ent(dev
, i
, 0);
756 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
761 for (i
= 0; i
< map2
->num_members
; i
++) {
762 ord
= get_imsm_ord_tbl_ent(dev
, i
, 1);
763 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
768 slot
= get_imsm_disk_slot(map
, disk_idx
);
770 ord
= get_imsm_ord_tbl_ent(dev
, slot
, -1);
771 printf(" This Slot : %d%s\n", slot
,
772 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
774 printf(" This Slot : ?\n");
775 sz
= __le32_to_cpu(dev
->size_high
);
777 sz
+= __le32_to_cpu(dev
->size_low
);
778 printf(" Array Size : %llu%s\n", (unsigned long long)sz
,
779 human_size(sz
* 512));
780 sz
= __le32_to_cpu(map
->blocks_per_member
);
781 printf(" Per Dev Size : %llu%s\n", (unsigned long long)sz
,
782 human_size(sz
* 512));
783 printf(" Sector Offset : %u\n",
784 __le32_to_cpu(map
->pba_of_lba0
));
785 printf(" Num Stripes : %u\n",
786 __le32_to_cpu(map
->num_data_stripes
));
787 printf(" Chunk Size : %u KiB",
788 __le16_to_cpu(map
->blocks_per_strip
) / 2);
790 printf(" <-- %u KiB",
791 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
793 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
794 printf(" Migrate State : ");
795 if (dev
->vol
.migr_state
) {
796 if (migr_type(dev
) == MIGR_INIT
)
797 printf("initialize\n");
798 else if (migr_type(dev
) == MIGR_REBUILD
)
800 else if (migr_type(dev
) == MIGR_VERIFY
)
802 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
803 printf("general migration\n");
804 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
805 printf("state change\n");
806 else if (migr_type(dev
) == MIGR_REPAIR
)
809 printf("<unknown:%d>\n", migr_type(dev
));
812 printf(" Map State : %s", map_state_str
[map
->map_state
]);
813 if (dev
->vol
.migr_state
) {
814 struct imsm_map
*map
= get_imsm_map(dev
, 1);
816 printf(" <-- %s", map_state_str
[map
->map_state
]);
817 printf("\n Checkpoint : %u (%llu)",
818 __le32_to_cpu(dev
->vol
.curr_migr_unit
),
819 (unsigned long long)blocks_per_migr_unit(dev
));
822 printf(" Dirty State : %s\n", dev
->vol
.dirty
? "dirty" : "clean");
825 static void print_imsm_disk(struct imsm_super
*mpb
, int index
, __u32 reserved
)
827 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, index
);
828 char str
[MAX_RAID_SERIAL_LEN
+ 1];
831 if (index
< 0 || !disk
)
835 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
836 printf(" Disk%02d Serial : %s\n", index
, str
);
837 printf(" State :%s%s%s\n", is_spare(disk
) ? " spare" : "",
838 is_configured(disk
) ? " active" : "",
839 is_failed(disk
) ? " failed" : "");
840 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
841 sz
= __le32_to_cpu(disk
->total_blocks
) - reserved
;
842 printf(" Usable Size : %llu%s\n", (unsigned long long)sz
,
843 human_size(sz
* 512));
846 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
848 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
850 struct intel_super
*super
= st
->sb
;
851 struct imsm_super
*mpb
= super
->anchor
;
852 char str
[MAX_SIGNATURE_LENGTH
];
857 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
860 snprintf(str
, MPB_SIG_LEN
, "%s", mpb
->sig
);
861 printf(" Magic : %s\n", str
);
862 snprintf(str
, strlen(MPB_VERSION_RAID0
), "%s", get_imsm_version(mpb
));
863 printf(" Version : %s\n", get_imsm_version(mpb
));
864 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
865 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
866 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
867 getinfo_super_imsm(st
, &info
, NULL
);
868 fname_from_uuid(st
, &info
, nbuf
, ':');
869 printf(" UUID : %s\n", nbuf
+ 5);
870 sum
= __le32_to_cpu(mpb
->check_sum
);
871 printf(" Checksum : %08x %s\n", sum
,
872 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
873 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
));
874 printf(" Disks : %d\n", mpb
->num_disks
);
875 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
876 print_imsm_disk(mpb
, super
->disks
->index
, reserved
);
877 if (super
->bbm_log
) {
878 struct bbm_log
*log
= super
->bbm_log
;
881 printf("Bad Block Management Log:\n");
882 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
883 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
884 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
885 printf(" Spare Blocks : %d\n", __le32_to_cpu(log
->reserved_spare_block_count
));
886 printf(" First Spare : %llx\n",
887 (unsigned long long) __le64_to_cpu(log
->first_spare_lba
));
889 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
891 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
893 super
->current_vol
= i
;
894 getinfo_super_imsm(st
, &info
, NULL
);
895 fname_from_uuid(st
, &info
, nbuf
, ':');
896 print_imsm_dev(dev
, nbuf
+ 5, super
->disks
->index
);
898 for (i
= 0; i
< mpb
->num_disks
; i
++) {
899 if (i
== super
->disks
->index
)
901 print_imsm_disk(mpb
, i
, reserved
);
903 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
904 struct imsm_disk
*disk
;
905 char str
[MAX_RAID_SERIAL_LEN
+ 1];
913 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
914 printf(" Disk Serial : %s\n", str
);
915 printf(" State :%s%s%s\n", is_spare(disk
) ? " spare" : "",
916 is_configured(disk
) ? " active" : "",
917 is_failed(disk
) ? " failed" : "");
918 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
919 sz
= __le32_to_cpu(disk
->total_blocks
) - reserved
;
920 printf(" Usable Size : %llu%s\n", (unsigned long long)sz
,
921 human_size(sz
* 512));
925 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
927 /* We just write a generic IMSM ARRAY entry */
930 struct intel_super
*super
= st
->sb
;
932 if (!super
->anchor
->num_raid_devs
) {
933 printf("ARRAY metadata=imsm\n");
937 getinfo_super_imsm(st
, &info
, NULL
);
938 fname_from_uuid(st
, &info
, nbuf
, ':');
939 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
942 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
944 /* We just write a generic IMSM ARRAY entry */
948 struct intel_super
*super
= st
->sb
;
951 if (!super
->anchor
->num_raid_devs
)
954 getinfo_super_imsm(st
, &info
, NULL
);
955 fname_from_uuid(st
, &info
, nbuf
, ':');
956 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
957 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
959 super
->current_vol
= i
;
960 getinfo_super_imsm(st
, &info
, NULL
);
961 fname_from_uuid(st
, &info
, nbuf1
, ':');
962 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
963 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
967 static void export_examine_super_imsm(struct supertype
*st
)
969 struct intel_super
*super
= st
->sb
;
970 struct imsm_super
*mpb
= super
->anchor
;
974 getinfo_super_imsm(st
, &info
, NULL
);
975 fname_from_uuid(st
, &info
, nbuf
, ':');
976 printf("MD_METADATA=imsm\n");
977 printf("MD_LEVEL=container\n");
978 printf("MD_UUID=%s\n", nbuf
+5);
979 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
982 static void detail_super_imsm(struct supertype
*st
, char *homehost
)
987 getinfo_super_imsm(st
, &info
, NULL
);
988 fname_from_uuid(st
, &info
, nbuf
, ':');
989 printf("\n UUID : %s\n", nbuf
+ 5);
992 static void brief_detail_super_imsm(struct supertype
*st
)
996 getinfo_super_imsm(st
, &info
, NULL
);
997 fname_from_uuid(st
, &info
, nbuf
, ':');
998 printf(" UUID=%s", nbuf
+ 5);
1001 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
);
1002 static void fd2devname(int fd
, char *name
);
1004 static int imsm_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
1006 /* dump an unsorted list of devices attached to ahci, as well as
1007 * non-connected ports
1009 int hba_len
= strlen(hba_path
) + 1;
1014 unsigned long port_mask
= (1 << port_count
) - 1;
1016 if (port_count
> (int)sizeof(port_mask
) * 8) {
1018 fprintf(stderr
, Name
": port_count %d out of range\n", port_count
);
1022 /* scroll through /sys/dev/block looking for devices attached to
1025 dir
= opendir("/sys/dev/block");
1026 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
1037 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
1039 path
= devt_to_devpath(makedev(major
, minor
));
1042 if (!path_attached_to_hba(path
, hba_path
)) {
1048 /* retrieve the scsi device type */
1049 if (asprintf(&device
, "/sys/dev/block/%d:%d/device/xxxxxxx", major
, minor
) < 0) {
1051 fprintf(stderr
, Name
": failed to allocate 'device'\n");
1055 sprintf(device
, "/sys/dev/block/%d:%d/device/type", major
, minor
);
1056 if (load_sys(device
, buf
) != 0) {
1058 fprintf(stderr
, Name
": failed to read device type for %s\n",
1064 type
= strtoul(buf
, NULL
, 10);
1066 /* if it's not a disk print the vendor and model */
1067 if (!(type
== 0 || type
== 7 || type
== 14)) {
1070 sprintf(device
, "/sys/dev/block/%d:%d/device/vendor", major
, minor
);
1071 if (load_sys(device
, buf
) == 0) {
1072 strncpy(vendor
, buf
, sizeof(vendor
));
1073 vendor
[sizeof(vendor
) - 1] = '\0';
1074 c
= (char *) &vendor
[sizeof(vendor
) - 1];
1075 while (isspace(*c
) || *c
== '\0')
1079 sprintf(device
, "/sys/dev/block/%d:%d/device/model", major
, minor
);
1080 if (load_sys(device
, buf
) == 0) {
1081 strncpy(model
, buf
, sizeof(model
));
1082 model
[sizeof(model
) - 1] = '\0';
1083 c
= (char *) &model
[sizeof(model
) - 1];
1084 while (isspace(*c
) || *c
== '\0')
1088 if (vendor
[0] && model
[0])
1089 sprintf(buf
, "%.64s %.64s", vendor
, model
);
1091 switch (type
) { /* numbers from hald/linux/device.c */
1092 case 1: sprintf(buf
, "tape"); break;
1093 case 2: sprintf(buf
, "printer"); break;
1094 case 3: sprintf(buf
, "processor"); break;
1096 case 5: sprintf(buf
, "cdrom"); break;
1097 case 6: sprintf(buf
, "scanner"); break;
1098 case 8: sprintf(buf
, "media_changer"); break;
1099 case 9: sprintf(buf
, "comm"); break;
1100 case 12: sprintf(buf
, "raid"); break;
1101 default: sprintf(buf
, "unknown");
1107 /* chop device path to 'host%d' and calculate the port number */
1108 c
= strchr(&path
[hba_len
], '/');
1111 fprintf(stderr
, Name
": %s - invalid path name\n", path
+ hba_len
);
1116 if (sscanf(&path
[hba_len
], "host%d", &port
) == 1)
1120 *c
= '/'; /* repair the full string */
1121 fprintf(stderr
, Name
": failed to determine port number for %s\n",
1128 /* mark this port as used */
1129 port_mask
&= ~(1 << port
);
1131 /* print out the device information */
1133 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
1137 fd
= dev_open(ent
->d_name
, O_RDONLY
);
1139 printf(" Port%d : - disk info unavailable -\n", port
);
1141 fd2devname(fd
, buf
);
1142 printf(" Port%d : %s", port
, buf
);
1143 if (imsm_read_serial(fd
, NULL
, (__u8
*) buf
) == 0)
1144 printf(" (%s)\n", buf
);
1159 for (i
= 0; i
< port_count
; i
++)
1160 if (port_mask
& (1 << i
))
1161 printf(" Port%d : - no device attached -\n", i
);
1167 static int detail_platform_imsm(int verbose
, int enumerate_only
)
1169 /* There are two components to imsm platform support, the ahci SATA
1170 * controller and the option-rom. To find the SATA controller we
1171 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
1172 * controller with the Intel vendor id is present. This approach
1173 * allows mdadm to leverage the kernel's ahci detection logic, with the
1174 * caveat that if ahci.ko is not loaded mdadm will not be able to
1175 * detect platform raid capabilities. The option-rom resides in a
1176 * platform "Adapter ROM". We scan for its signature to retrieve the
1177 * platform capabilities. If raid support is disabled in the BIOS the
1178 * option-rom capability structure will not be available.
1180 const struct imsm_orom
*orom
;
1181 struct sys_dev
*list
, *hba
;
1184 const char *hba_path
;
1188 if (enumerate_only
) {
1189 if (check_env("IMSM_NO_PLATFORM") || find_imsm_orom())
1194 list
= find_driver_devices("pci", "ahci");
1195 for (hba
= list
; hba
; hba
= hba
->next
)
1196 if (devpath_to_vendor(hba
->path
) == 0x8086)
1201 fprintf(stderr
, Name
": unable to find active ahci controller\n");
1202 free_sys_dev(&list
);
1205 fprintf(stderr
, Name
": found Intel SATA AHCI Controller\n");
1206 hba_path
= hba
->path
;
1208 free_sys_dev(&list
);
1210 orom
= find_imsm_orom();
1213 fprintf(stderr
, Name
": imsm option-rom not found\n");
1217 printf(" Platform : Intel(R) Matrix Storage Manager\n");
1218 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
1219 orom
->hotfix_ver
, orom
->build
);
1220 printf(" RAID Levels :%s%s%s%s%s\n",
1221 imsm_orom_has_raid0(orom
) ? " raid0" : "",
1222 imsm_orom_has_raid1(orom
) ? " raid1" : "",
1223 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
1224 imsm_orom_has_raid10(orom
) ? " raid10" : "",
1225 imsm_orom_has_raid5(orom
) ? " raid5" : "");
1226 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1227 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
1228 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
1229 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
1230 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
1231 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
1232 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
1233 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
1234 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
1235 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
1236 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
1237 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
1238 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
1239 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
1240 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
1241 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
1242 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
1243 printf(" Max Disks : %d\n", orom
->tds
);
1244 printf(" Max Volumes : %d\n", orom
->vpa
);
1245 printf(" I/O Controller : %s\n", hba_path
);
1247 /* find the smallest scsi host number to determine a port number base */
1248 dir
= opendir(hba_path
);
1249 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
1252 if (sscanf(ent
->d_name
, "host%d", &host
) != 1)
1254 if (port_count
== 0)
1256 else if (host
< host_base
)
1259 if (host
+ 1 > port_count
+ host_base
)
1260 port_count
= host
+ 1 - host_base
;
1266 if (!port_count
|| imsm_enumerate_ports(hba_path
, port_count
,
1267 host_base
, verbose
) != 0) {
1269 fprintf(stderr
, Name
": failed to enumerate ports\n");
1277 static int match_home_imsm(struct supertype
*st
, char *homehost
)
1279 /* the imsm metadata format does not specify any host
1280 * identification information. We return -1 since we can never
1281 * confirm nor deny whether a given array is "meant" for this
1282 * host. We rely on compare_super and the 'family_num' fields to
1283 * exclude member disks that do not belong, and we rely on
1284 * mdadm.conf to specify the arrays that should be assembled.
1285 * Auto-assembly may still pick up "foreign" arrays.
1291 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
1293 /* The uuid returned here is used for:
1294 * uuid to put into bitmap file (Create, Grow)
1295 * uuid for backup header when saving critical section (Grow)
1296 * comparing uuids when re-adding a device into an array
1297 * In these cases the uuid required is that of the data-array,
1298 * not the device-set.
1299 * uuid to recognise same set when adding a missing device back
1300 * to an array. This is a uuid for the device-set.
1302 * For each of these we can make do with a truncated
1303 * or hashed uuid rather than the original, as long as
1305 * In each case the uuid required is that of the data-array,
1306 * not the device-set.
1308 /* imsm does not track uuid's so we synthesis one using sha1 on
1309 * - The signature (Which is constant for all imsm array, but no matter)
1310 * - the orig_family_num of the container
1311 * - the index number of the volume
1312 * - the 'serial' number of the volume.
1313 * Hopefully these are all constant.
1315 struct intel_super
*super
= st
->sb
;
1318 struct sha1_ctx ctx
;
1319 struct imsm_dev
*dev
= NULL
;
1322 /* some mdadm versions failed to set ->orig_family_num, in which
1323 * case fall back to ->family_num. orig_family_num will be
1324 * fixed up with the first metadata update.
1326 family_num
= super
->anchor
->orig_family_num
;
1327 if (family_num
== 0)
1328 family_num
= super
->anchor
->family_num
;
1329 sha1_init_ctx(&ctx
);
1330 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
1331 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
1332 if (super
->current_vol
>= 0)
1333 dev
= get_imsm_dev(super
, super
->current_vol
);
1335 __u32 vol
= super
->current_vol
;
1336 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
1337 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
1339 sha1_finish_ctx(&ctx
, buf
);
1340 memcpy(uuid
, buf
, 4*4);
1345 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
1347 __u8
*v
= get_imsm_version(mpb
);
1348 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
1349 char major
[] = { 0, 0, 0 };
1350 char minor
[] = { 0 ,0, 0 };
1351 char patch
[] = { 0, 0, 0 };
1352 char *ver_parse
[] = { major
, minor
, patch
};
1356 while (*v
!= '\0' && v
< end
) {
1357 if (*v
!= '.' && j
< 2)
1358 ver_parse
[i
][j
++] = *v
;
1366 *m
= strtol(minor
, NULL
, 0);
1367 *p
= strtol(patch
, NULL
, 0);
1371 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
1373 /* migr_strip_size when repairing or initializing parity */
1374 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1375 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1377 switch (get_imsm_raid_level(map
)) {
1382 return 128*1024 >> 9;
1386 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
1388 /* migr_strip_size when rebuilding a degraded disk, no idea why
1389 * this is different than migr_strip_size_resync(), but it's good
1392 struct imsm_map
*map
= get_imsm_map(dev
, 1);
1393 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1395 switch (get_imsm_raid_level(map
)) {
1398 if (map
->num_members
% map
->num_domains
== 0)
1399 return 128*1024 >> 9;
1403 return max((__u32
) 64*1024 >> 9, chunk
);
1405 return 128*1024 >> 9;
1409 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
1411 struct imsm_map
*lo
= get_imsm_map(dev
, 0);
1412 struct imsm_map
*hi
= get_imsm_map(dev
, 1);
1413 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
1414 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
1416 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
1419 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
1421 struct imsm_map
*lo
= get_imsm_map(dev
, 0);
1422 int level
= get_imsm_raid_level(lo
);
1424 if (level
== 1 || level
== 10) {
1425 struct imsm_map
*hi
= get_imsm_map(dev
, 1);
1427 return hi
->num_domains
;
1429 return num_stripes_per_unit_resync(dev
);
1432 static __u8
imsm_num_data_members(struct imsm_dev
*dev
, int second_map
)
1434 /* named 'imsm_' because raid0, raid1 and raid10
1435 * counter-intuitively have the same number of data disks
1437 struct imsm_map
*map
= get_imsm_map(dev
, second_map
);
1439 switch (get_imsm_raid_level(map
)) {
1443 return map
->num_members
;
1445 return map
->num_members
- 1;
1447 dprintf("%s: unsupported raid level\n", __func__
);
1452 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
1454 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1455 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1457 switch(get_imsm_raid_level(map
)) {
1460 return chunk
* map
->num_domains
;
1462 return chunk
* map
->num_members
;
1468 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
1470 struct imsm_map
*map
= get_imsm_map(dev
, 1);
1471 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1472 __u32 strip
= block
/ chunk
;
1474 switch (get_imsm_raid_level(map
)) {
1477 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
1478 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
1480 return vol_stripe
* chunk
+ block
% chunk
;
1482 __u32 stripe
= strip
/ (map
->num_members
- 1);
1484 return stripe
* chunk
+ block
% chunk
;
1491 static __u64
blocks_per_migr_unit(struct imsm_dev
*dev
)
1493 /* calculate the conversion factor between per member 'blocks'
1494 * (md/{resync,rebuild}_start) and imsm migration units, return
1495 * 0 for the 'not migrating' and 'unsupported migration' cases
1497 if (!dev
->vol
.migr_state
)
1500 switch (migr_type(dev
)) {
1505 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1506 __u32 stripes_per_unit
;
1507 __u32 blocks_per_unit
;
1516 /* yes, this is really the translation of migr_units to
1517 * per-member blocks in the 'resync' case
1519 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
1520 migr_chunk
= migr_strip_blocks_resync(dev
);
1521 disks
= imsm_num_data_members(dev
, 0);
1522 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
1523 stripe
= __le32_to_cpu(map
->blocks_per_strip
) * disks
;
1524 segment
= blocks_per_unit
/ stripe
;
1525 block_rel
= blocks_per_unit
- segment
* stripe
;
1526 parity_depth
= parity_segment_depth(dev
);
1527 block_map
= map_migr_block(dev
, block_rel
);
1528 return block_map
+ parity_depth
* segment
;
1530 case MIGR_REBUILD
: {
1531 __u32 stripes_per_unit
;
1534 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
1535 migr_chunk
= migr_strip_blocks_rebuild(dev
);
1536 return migr_chunk
* stripes_per_unit
;
1538 case MIGR_STATE_CHANGE
:
1544 static int imsm_level_to_layout(int level
)
1552 return ALGORITHM_LEFT_ASYMMETRIC
;
1559 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
1561 struct intel_super
*super
= st
->sb
;
1562 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
1563 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1564 struct imsm_map
*prev_map
= get_imsm_map(dev
, 1);
1565 struct imsm_map
*map_to_analyse
= map
;
1568 int map_disks
= info
->array
.raid_disks
;
1571 map_to_analyse
= prev_map
;
1573 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
1574 if (dl
->raiddisk
== info
->disk
.raid_disk
)
1576 info
->container_member
= super
->current_vol
;
1577 info
->array
.raid_disks
= map_to_analyse
->num_members
;
1578 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
1579 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
1580 info
->array
.md_minor
= -1;
1581 info
->array
.ctime
= 0;
1582 info
->array
.utime
= 0;
1583 info
->array
.chunk_size
=
1584 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
1585 info
->array
.state
= !dev
->vol
.dirty
;
1586 info
->custom_array_size
= __le32_to_cpu(dev
->size_high
);
1587 info
->custom_array_size
<<= 32;
1588 info
->custom_array_size
|= __le32_to_cpu(dev
->size_low
);
1590 info
->new_level
= get_imsm_raid_level(map
);
1591 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
1592 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
1594 info
->new_level
= UnSet
;
1595 info
->new_layout
= UnSet
;
1596 info
->new_chunk
= info
->array
.chunk_size
;
1598 info
->disk
.major
= 0;
1599 info
->disk
.minor
= 0;
1601 info
->disk
.major
= dl
->major
;
1602 info
->disk
.minor
= dl
->minor
;
1605 info
->data_offset
= __le32_to_cpu(map_to_analyse
->pba_of_lba0
);
1606 info
->component_size
=
1607 __le32_to_cpu(map_to_analyse
->blocks_per_member
);
1608 memset(info
->uuid
, 0, sizeof(info
->uuid
));
1609 info
->recovery_start
= MaxSector
;
1610 info
->reshape_active
= (prev_map
!= NULL
);
1611 if (info
->reshape_active
)
1612 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
1614 info
->delta_disks
= 0;
1616 if (map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
1618 info
->resync_start
= 0;
1619 } else if (dev
->vol
.migr_state
) {
1620 switch (migr_type(dev
)) {
1623 __u64 blocks_per_unit
= blocks_per_migr_unit(dev
);
1624 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
1626 info
->resync_start
= blocks_per_unit
* units
;
1630 /* we could emulate the checkpointing of
1631 * 'sync_action=check' migrations, but for now
1632 * we just immediately complete them
1635 /* this is handled by container_content_imsm() */
1637 case MIGR_STATE_CHANGE
:
1638 /* FIXME handle other migrations */
1640 /* we are not dirty, so... */
1641 info
->resync_start
= MaxSector
;
1644 info
->resync_start
= MaxSector
;
1646 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
1647 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
1649 info
->array
.major_version
= -1;
1650 info
->array
.minor_version
= -2;
1651 devname
= devnum2devname(st
->container_dev
);
1652 *info
->text_version
= '\0';
1654 sprintf(info
->text_version
, "/%s/%d", devname
, info
->container_member
);
1656 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
1657 uuid_from_super_imsm(st
, info
->uuid
);
1661 for (i
=0; i
<map_disks
; i
++) {
1663 if (i
< info
->array
.raid_disks
) {
1664 struct imsm_disk
*dsk
;
1665 j
= get_imsm_disk_idx(dev
, i
, -1);
1666 dsk
= get_imsm_disk(super
, j
);
1667 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
1674 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
, int failed
);
1675 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
);
1677 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
1681 for (d
= super
->missing
; d
; d
= d
->next
)
1682 if (d
->index
== index
)
1687 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
1689 struct intel_super
*super
= st
->sb
;
1690 struct imsm_disk
*disk
;
1691 int map_disks
= info
->array
.raid_disks
;
1692 int max_enough
= -1;
1694 struct imsm_super
*mpb
;
1696 if (super
->current_vol
>= 0) {
1697 getinfo_super_imsm_volume(st
, info
, map
);
1701 /* Set raid_disks to zero so that Assemble will always pull in valid
1704 info
->array
.raid_disks
= 0;
1705 info
->array
.level
= LEVEL_CONTAINER
;
1706 info
->array
.layout
= 0;
1707 info
->array
.md_minor
= -1;
1708 info
->array
.ctime
= 0; /* N/A for imsm */
1709 info
->array
.utime
= 0;
1710 info
->array
.chunk_size
= 0;
1712 info
->disk
.major
= 0;
1713 info
->disk
.minor
= 0;
1714 info
->disk
.raid_disk
= -1;
1715 info
->reshape_active
= 0;
1716 info
->array
.major_version
= -1;
1717 info
->array
.minor_version
= -2;
1718 strcpy(info
->text_version
, "imsm");
1719 info
->safe_mode_delay
= 0;
1720 info
->disk
.number
= -1;
1721 info
->disk
.state
= 0;
1723 info
->recovery_start
= MaxSector
;
1725 /* do we have the all the insync disks that we expect? */
1726 mpb
= super
->anchor
;
1728 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1729 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1730 int failed
, enough
, j
, missing
= 0;
1731 struct imsm_map
*map
;
1734 failed
= imsm_count_failed(super
, dev
);
1735 state
= imsm_check_degraded(super
, dev
, failed
);
1736 map
= get_imsm_map(dev
, dev
->vol
.migr_state
);
1738 /* any newly missing disks?
1739 * (catches single-degraded vs double-degraded)
1741 for (j
= 0; j
< map
->num_members
; j
++) {
1742 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, -1);
1743 __u32 idx
= ord_to_idx(ord
);
1745 if (!(ord
& IMSM_ORD_REBUILD
) &&
1746 get_imsm_missing(super
, idx
)) {
1752 if (state
== IMSM_T_STATE_FAILED
)
1754 else if (state
== IMSM_T_STATE_DEGRADED
&&
1755 (state
!= map
->map_state
|| missing
))
1757 else /* we're normal, or already degraded */
1760 /* in the missing/failed disk case check to see
1761 * if at least one array is runnable
1763 max_enough
= max(max_enough
, enough
);
1765 dprintf("%s: enough: %d\n", __func__
, max_enough
);
1766 info
->container_enough
= max_enough
;
1769 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
1771 disk
= &super
->disks
->disk
;
1772 info
->data_offset
= __le32_to_cpu(disk
->total_blocks
) - reserved
;
1773 info
->component_size
= reserved
;
1774 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
1775 /* we don't change info->disk.raid_disk here because
1776 * this state will be finalized in mdmon after we have
1777 * found the 'most fresh' version of the metadata
1779 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
1780 info
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
1783 /* only call uuid_from_super_imsm when this disk is part of a populated container,
1784 * ->compare_super may have updated the 'num_raid_devs' field for spares
1786 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
1787 uuid_from_super_imsm(st
, info
->uuid
);
1789 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
1791 /* I don't know how to compute 'map' on imsm, so use safe default */
1794 for (i
= 0; i
< map_disks
; i
++)
1800 /* allocates memory and fills disk in mdinfo structure
1801 * for each disk in array */
1802 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
1804 struct mdinfo
*mddev
= NULL
;
1805 struct intel_super
*super
= st
->sb
;
1806 struct imsm_disk
*disk
;
1809 if (!super
|| !super
->disks
)
1812 mddev
= malloc(sizeof(*mddev
));
1814 fprintf(stderr
, Name
": Failed to allocate memory.\n");
1817 memset(mddev
, 0, sizeof(*mddev
));
1821 tmp
= malloc(sizeof(*tmp
));
1823 fprintf(stderr
, Name
": Failed to allocate memory.\n");
1828 memset(tmp
, 0, sizeof(*tmp
));
1830 tmp
->next
= mddev
->devs
;
1832 tmp
->disk
.number
= count
++;
1833 tmp
->disk
.major
= dl
->major
;
1834 tmp
->disk
.minor
= dl
->minor
;
1835 tmp
->disk
.state
= is_configured(disk
) ?
1836 (1 << MD_DISK_ACTIVE
) : 0;
1837 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
1838 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
1839 tmp
->disk
.raid_disk
= -1;
1845 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
1846 char *update
, char *devname
, int verbose
,
1847 int uuid_set
, char *homehost
)
1849 /* For 'assemble' and 'force' we need to return non-zero if any
1850 * change was made. For others, the return value is ignored.
1851 * Update options are:
1852 * force-one : This device looks a bit old but needs to be included,
1853 * update age info appropriately.
1854 * assemble: clear any 'faulty' flag to allow this device to
1856 * force-array: Array is degraded but being forced, mark it clean
1857 * if that will be needed to assemble it.
1859 * newdev: not used ????
1860 * grow: Array has gained a new device - this is currently for
1862 * resync: mark as dirty so a resync will happen.
1863 * name: update the name - preserving the homehost
1864 * uuid: Change the uuid of the array to match watch is given
1866 * Following are not relevant for this imsm:
1867 * sparc2.2 : update from old dodgey metadata
1868 * super-minor: change the preferred_minor number
1869 * summaries: update redundant counters.
1870 * homehost: update the recorded homehost
1871 * _reshape_progress: record new reshape_progress position.
1874 struct intel_super
*super
= st
->sb
;
1875 struct imsm_super
*mpb
;
1877 /* we can only update container info */
1878 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
1881 mpb
= super
->anchor
;
1883 if (strcmp(update
, "uuid") == 0 && uuid_set
&& !info
->update_private
)
1885 else if (strcmp(update
, "uuid") == 0 && uuid_set
&& info
->update_private
) {
1886 mpb
->orig_family_num
= *((__u32
*) info
->update_private
);
1888 } else if (strcmp(update
, "uuid") == 0) {
1889 __u32
*new_family
= malloc(sizeof(*new_family
));
1891 /* update orig_family_number with the incoming random
1892 * data, report the new effective uuid, and store the
1893 * new orig_family_num for future updates.
1896 memcpy(&mpb
->orig_family_num
, info
->uuid
, sizeof(__u32
));
1897 uuid_from_super_imsm(st
, info
->uuid
);
1898 *new_family
= mpb
->orig_family_num
;
1899 info
->update_private
= new_family
;
1902 } else if (strcmp(update
, "assemble") == 0)
1907 /* successful update? recompute checksum */
1909 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
1914 static size_t disks_to_mpb_size(int disks
)
1918 size
= sizeof(struct imsm_super
);
1919 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
1920 size
+= 2 * sizeof(struct imsm_dev
);
1921 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
1922 size
+= (4 - 2) * sizeof(struct imsm_map
);
1923 /* 4 possible disk_ord_tbl's */
1924 size
+= 4 * (disks
- 1) * sizeof(__u32
);
1929 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
)
1931 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
1934 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
1937 static void free_devlist(struct intel_super
*super
)
1939 struct intel_dev
*dv
;
1941 while (super
->devlist
) {
1942 dv
= super
->devlist
->next
;
1943 free(super
->devlist
->dev
);
1944 free(super
->devlist
);
1945 super
->devlist
= dv
;
1949 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
1951 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
1954 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
)
1958 * 0 same, or first was empty, and second was copied
1959 * 1 second had wrong number
1961 * 3 wrong other info
1963 struct intel_super
*first
= st
->sb
;
1964 struct intel_super
*sec
= tst
->sb
;
1972 /* if an anchor does not have num_raid_devs set then it is a free
1975 if (first
->anchor
->num_raid_devs
> 0 &&
1976 sec
->anchor
->num_raid_devs
> 0) {
1977 /* Determine if these disks might ever have been
1978 * related. Further disambiguation can only take place
1979 * in load_super_imsm_all
1981 __u32 first_family
= first
->anchor
->orig_family_num
;
1982 __u32 sec_family
= sec
->anchor
->orig_family_num
;
1984 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
1985 MAX_SIGNATURE_LENGTH
) != 0)
1988 if (first_family
== 0)
1989 first_family
= first
->anchor
->family_num
;
1990 if (sec_family
== 0)
1991 sec_family
= sec
->anchor
->family_num
;
1993 if (first_family
!= sec_family
)
1999 /* if 'first' is a spare promote it to a populated mpb with sec's
2002 if (first
->anchor
->num_raid_devs
== 0 &&
2003 sec
->anchor
->num_raid_devs
> 0) {
2005 struct intel_dev
*dv
;
2006 struct imsm_dev
*dev
;
2008 /* we need to copy raid device info from sec if an allocation
2009 * fails here we don't associate the spare
2011 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++) {
2012 dv
= malloc(sizeof(*dv
));
2015 dev
= malloc(sizeof_imsm_dev(get_imsm_dev(sec
, i
), 1));
2022 dv
->next
= first
->devlist
;
2023 first
->devlist
= dv
;
2025 if (i
< sec
->anchor
->num_raid_devs
) {
2026 /* allocation failure */
2027 free_devlist(first
);
2028 fprintf(stderr
, "imsm: failed to associate spare\n");
2031 first
->anchor
->num_raid_devs
= sec
->anchor
->num_raid_devs
;
2032 first
->anchor
->orig_family_num
= sec
->anchor
->orig_family_num
;
2033 first
->anchor
->family_num
= sec
->anchor
->family_num
;
2034 memcpy(first
->anchor
->sig
, sec
->anchor
->sig
, MAX_SIGNATURE_LENGTH
);
2035 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++)
2036 imsm_copy_dev(get_imsm_dev(first
, i
), get_imsm_dev(sec
, i
));
2042 static void fd2devname(int fd
, char *name
)
2046 char dname
[PATH_MAX
];
2051 if (fstat(fd
, &st
) != 0)
2053 sprintf(path
, "/sys/dev/block/%d:%d",
2054 major(st
.st_rdev
), minor(st
.st_rdev
));
2056 rv
= readlink(path
, dname
, sizeof(dname
));
2061 nm
= strrchr(dname
, '/');
2063 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
2066 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
2068 static int imsm_read_serial(int fd
, char *devname
,
2069 __u8 serial
[MAX_RAID_SERIAL_LEN
])
2071 unsigned char scsi_serial
[255];
2080 memset(scsi_serial
, 0, sizeof(scsi_serial
));
2082 rv
= scsi_get_serial(fd
, scsi_serial
, sizeof(scsi_serial
));
2084 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
2085 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
2086 fd2devname(fd
, (char *) serial
);
2093 Name
": Failed to retrieve serial for %s\n",
2098 rsp_len
= scsi_serial
[3];
2102 Name
": Failed to retrieve serial for %s\n",
2106 rsp_buf
= (char *) &scsi_serial
[4];
2108 /* trim all whitespace and non-printable characters and convert
2111 for (i
= 0, dest
= rsp_buf
; i
< rsp_len
; i
++) {
2114 /* ':' is reserved for use in placeholder serial
2115 * numbers for missing disks
2123 len
= dest
- rsp_buf
;
2126 /* truncate leading characters */
2127 if (len
> MAX_RAID_SERIAL_LEN
) {
2128 dest
+= len
- MAX_RAID_SERIAL_LEN
;
2129 len
= MAX_RAID_SERIAL_LEN
;
2132 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
2133 memcpy(serial
, dest
, len
);
2138 static int serialcmp(__u8
*s1
, __u8
*s2
)
2140 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
2143 static void serialcpy(__u8
*dest
, __u8
*src
)
2145 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
2149 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
2153 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
2154 if (serialcmp(dl
->serial
, serial
) == 0)
2161 static struct imsm_disk
*
2162 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
2166 for (i
= 0; i
< mpb
->num_disks
; i
++) {
2167 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
2169 if (serialcmp(disk
->serial
, serial
) == 0) {
2180 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
2182 struct imsm_disk
*disk
;
2187 __u8 serial
[MAX_RAID_SERIAL_LEN
];
2189 rv
= imsm_read_serial(fd
, devname
, serial
);
2194 dl
= calloc(1, sizeof(*dl
));
2198 Name
": failed to allocate disk buffer for %s\n",
2204 dl
->major
= major(stb
.st_rdev
);
2205 dl
->minor
= minor(stb
.st_rdev
);
2206 dl
->next
= super
->disks
;
2207 dl
->fd
= keep_fd
? fd
: -1;
2208 assert(super
->disks
== NULL
);
2210 serialcpy(dl
->serial
, serial
);
2213 fd2devname(fd
, name
);
2215 dl
->devname
= strdup(devname
);
2217 dl
->devname
= strdup(name
);
2219 /* look up this disk's index in the current anchor */
2220 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
2223 /* only set index on disks that are a member of a
2224 * populated contianer, i.e. one with raid_devs
2226 if (is_failed(&dl
->disk
))
2228 else if (is_spare(&dl
->disk
))
2236 /* When migrating map0 contains the 'destination' state while map1
2237 * contains the current state. When not migrating map0 contains the
2238 * current state. This routine assumes that map[0].map_state is set to
2239 * the current array state before being called.
2241 * Migration is indicated by one of the following states
2242 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
2243 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
2244 * map1state=unitialized)
2245 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
2247 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
2248 * map1state=degraded)
2250 static void migrate(struct imsm_dev
*dev
, __u8 to_state
, int migr_type
)
2252 struct imsm_map
*dest
;
2253 struct imsm_map
*src
= get_imsm_map(dev
, 0);
2255 dev
->vol
.migr_state
= 1;
2256 set_migr_type(dev
, migr_type
);
2257 dev
->vol
.curr_migr_unit
= 0;
2258 dest
= get_imsm_map(dev
, 1);
2260 /* duplicate and then set the target end state in map[0] */
2261 memcpy(dest
, src
, sizeof_imsm_map(src
));
2262 if ((migr_type
== MIGR_REBUILD
) ||
2263 (migr_type
== MIGR_GEN_MIGR
)) {
2267 for (i
= 0; i
< src
->num_members
; i
++) {
2268 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
2269 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
2273 src
->map_state
= to_state
;
2276 static void end_migration(struct imsm_dev
*dev
, __u8 map_state
)
2278 struct imsm_map
*map
= get_imsm_map(dev
, 0);
2279 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
);
2282 /* merge any IMSM_ORD_REBUILD bits that were not successfully
2283 * completed in the last migration.
2285 * FIXME add support for raid-level-migration
2287 for (i
= 0; i
< prev
->num_members
; i
++)
2288 for (j
= 0; j
< map
->num_members
; j
++)
2289 /* during online capacity expansion
2290 * disks position can be changed if takeover is used
2292 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
2293 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
2294 map
->disk_ord_tbl
[j
] |= prev
->disk_ord_tbl
[i
];
2298 dev
->vol
.migr_state
= 0;
2299 dev
->vol
.migr_type
= 0;
2300 dev
->vol
.curr_migr_unit
= 0;
2301 map
->map_state
= map_state
;
2305 static int parse_raid_devices(struct intel_super
*super
)
2308 struct imsm_dev
*dev_new
;
2309 size_t len
, len_migr
;
2310 size_t space_needed
= 0;
2311 struct imsm_super
*mpb
= super
->anchor
;
2313 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
2314 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
2315 struct intel_dev
*dv
;
2317 len
= sizeof_imsm_dev(dev_iter
, 0);
2318 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
2320 space_needed
+= len_migr
- len
;
2322 dv
= malloc(sizeof(*dv
));
2325 dev_new
= malloc(len_migr
);
2330 imsm_copy_dev(dev_new
, dev_iter
);
2333 dv
->next
= super
->devlist
;
2334 super
->devlist
= dv
;
2337 /* ensure that super->buf is large enough when all raid devices
2340 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
2343 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
, 512);
2344 if (posix_memalign(&buf
, 512, len
) != 0)
2347 memcpy(buf
, super
->buf
, super
->len
);
2348 memset(buf
+ super
->len
, 0, len
- super
->len
);
2357 /* retrieve a pointer to the bbm log which starts after all raid devices */
2358 struct bbm_log
*__get_imsm_bbm_log(struct imsm_super
*mpb
)
2362 if (__le32_to_cpu(mpb
->bbm_log_size
)) {
2364 ptr
+= mpb
->mpb_size
- __le32_to_cpu(mpb
->bbm_log_size
);
2370 static void __free_imsm(struct intel_super
*super
, int free_disks
);
2372 /* load_imsm_mpb - read matrix metadata
2373 * allocates super->mpb to be freed by free_super
2375 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
2377 unsigned long long dsize
;
2378 unsigned long long sectors
;
2380 struct imsm_super
*anchor
;
2383 get_dev_size(fd
, NULL
, &dsize
);
2387 Name
": %s: device to small for imsm\n",
2392 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0) {
2395 Name
": Cannot seek to anchor block on %s: %s\n",
2396 devname
, strerror(errno
));
2400 if (posix_memalign((void**)&anchor
, 512, 512) != 0) {
2403 Name
": Failed to allocate imsm anchor buffer"
2404 " on %s\n", devname
);
2407 if (read(fd
, anchor
, 512) != 512) {
2410 Name
": Cannot read anchor block on %s: %s\n",
2411 devname
, strerror(errno
));
2416 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
2419 Name
": no IMSM anchor on %s\n", devname
);
2424 __free_imsm(super
, 0);
2425 super
->len
= ROUND_UP(anchor
->mpb_size
, 512);
2426 if (posix_memalign(&super
->buf
, 512, super
->len
) != 0) {
2429 Name
": unable to allocate %zu byte mpb buffer\n",
2434 memcpy(super
->buf
, anchor
, 512);
2436 sectors
= mpb_sectors(anchor
) - 1;
2439 check_sum
= __gen_imsm_checksum(super
->anchor
);
2440 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
2443 Name
": IMSM checksum %x != %x on %s\n",
2445 __le32_to_cpu(super
->anchor
->check_sum
),
2453 /* read the extended mpb */
2454 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0) {
2457 Name
": Cannot seek to extended mpb on %s: %s\n",
2458 devname
, strerror(errno
));
2462 if ((unsigned)read(fd
, super
->buf
+ 512, super
->len
- 512) != super
->len
- 512) {
2465 Name
": Cannot read extended mpb on %s: %s\n",
2466 devname
, strerror(errno
));
2470 check_sum
= __gen_imsm_checksum(super
->anchor
);
2471 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
2474 Name
": IMSM checksum %x != %x on %s\n",
2475 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
2480 /* FIXME the BBM log is disk specific so we cannot use this global
2481 * buffer for all disks. Ok for now since we only look at the global
2482 * bbm_log_size parameter to gate assembly
2484 super
->bbm_log
= __get_imsm_bbm_log(super
->anchor
);
2490 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
2494 err
= load_imsm_mpb(fd
, super
, devname
);
2497 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
2500 err
= parse_raid_devices(super
);
2505 static void __free_imsm_disk(struct dl
*d
)
2517 static void free_imsm_disks(struct intel_super
*super
)
2521 while (super
->disks
) {
2523 super
->disks
= d
->next
;
2524 __free_imsm_disk(d
);
2526 while (super
->missing
) {
2528 super
->missing
= d
->next
;
2529 __free_imsm_disk(d
);
2534 /* free all the pieces hanging off of a super pointer */
2535 static void __free_imsm(struct intel_super
*super
, int free_disks
)
2542 free_imsm_disks(super
);
2543 free_devlist(super
);
2545 free((void *) super
->hba
);
2550 static void free_imsm(struct intel_super
*super
)
2552 __free_imsm(super
, 1);
2556 static void free_super_imsm(struct supertype
*st
)
2558 struct intel_super
*super
= st
->sb
;
2567 static struct intel_super
*alloc_super(void)
2569 struct intel_super
*super
= malloc(sizeof(*super
));
2572 memset(super
, 0, sizeof(*super
));
2573 super
->current_vol
= -1;
2574 super
->create_offset
= ~((__u32
) 0);
2575 if (!check_env("IMSM_NO_PLATFORM"))
2576 super
->orom
= find_imsm_orom();
2577 if (super
->orom
&& !check_env("IMSM_TEST_OROM")) {
2578 struct sys_dev
*list
, *ent
;
2580 /* find the first intel ahci controller */
2581 list
= find_driver_devices("pci", "ahci");
2582 for (ent
= list
; ent
; ent
= ent
->next
)
2583 if (devpath_to_vendor(ent
->path
) == 0x8086)
2586 super
->hba
= ent
->path
;
2589 free_sys_dev(&list
);
2597 /* find_missing - helper routine for load_super_imsm_all that identifies
2598 * disks that have disappeared from the system. This routine relies on
2599 * the mpb being uptodate, which it is at load time.
2601 static int find_missing(struct intel_super
*super
)
2604 struct imsm_super
*mpb
= super
->anchor
;
2606 struct imsm_disk
*disk
;
2608 for (i
= 0; i
< mpb
->num_disks
; i
++) {
2609 disk
= __get_imsm_disk(mpb
, i
);
2610 dl
= serial_to_dl(disk
->serial
, super
);
2614 dl
= malloc(sizeof(*dl
));
2620 dl
->devname
= strdup("missing");
2622 serialcpy(dl
->serial
, disk
->serial
);
2625 dl
->next
= super
->missing
;
2626 super
->missing
= dl
;
2632 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
2634 struct intel_disk
*idisk
= disk_list
;
2637 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
2639 idisk
= idisk
->next
;
2645 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
2646 struct intel_super
*super
,
2647 struct intel_disk
**disk_list
)
2649 struct imsm_disk
*d
= &super
->disks
->disk
;
2650 struct imsm_super
*mpb
= super
->anchor
;
2653 for (i
= 0; i
< tbl_size
; i
++) {
2654 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
2655 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
2657 if (tbl_mpb
->family_num
== mpb
->family_num
) {
2658 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
2659 dprintf("%s: mpb from %d:%d matches %d:%d\n",
2660 __func__
, super
->disks
->major
,
2661 super
->disks
->minor
,
2662 table
[i
]->disks
->major
,
2663 table
[i
]->disks
->minor
);
2667 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
2668 is_configured(d
) == is_configured(tbl_d
)) &&
2669 tbl_mpb
->generation_num
< mpb
->generation_num
) {
2670 /* current version of the mpb is a
2671 * better candidate than the one in
2672 * super_table, but copy over "cross
2673 * generational" status
2675 struct intel_disk
*idisk
;
2677 dprintf("%s: mpb from %d:%d replaces %d:%d\n",
2678 __func__
, super
->disks
->major
,
2679 super
->disks
->minor
,
2680 table
[i
]->disks
->major
,
2681 table
[i
]->disks
->minor
);
2683 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
2684 if (idisk
&& is_failed(&idisk
->disk
))
2685 tbl_d
->status
|= FAILED_DISK
;
2688 struct intel_disk
*idisk
;
2689 struct imsm_disk
*disk
;
2691 /* tbl_mpb is more up to date, but copy
2692 * over cross generational status before
2695 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
2696 if (disk
&& is_failed(disk
))
2697 d
->status
|= FAILED_DISK
;
2699 idisk
= disk_list_get(d
->serial
, *disk_list
);
2702 if (disk
&& is_configured(disk
))
2703 idisk
->disk
.status
|= CONFIGURED_DISK
;
2706 dprintf("%s: mpb from %d:%d prefer %d:%d\n",
2707 __func__
, super
->disks
->major
,
2708 super
->disks
->minor
,
2709 table
[i
]->disks
->major
,
2710 table
[i
]->disks
->minor
);
2718 table
[tbl_size
++] = super
;
2722 /* update/extend the merged list of imsm_disk records */
2723 for (j
= 0; j
< mpb
->num_disks
; j
++) {
2724 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
2725 struct intel_disk
*idisk
;
2727 idisk
= disk_list_get(disk
->serial
, *disk_list
);
2729 idisk
->disk
.status
|= disk
->status
;
2730 if (is_configured(&idisk
->disk
) ||
2731 is_failed(&idisk
->disk
))
2732 idisk
->disk
.status
&= ~(SPARE_DISK
);
2734 idisk
= calloc(1, sizeof(*idisk
));
2737 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
2738 idisk
->disk
= *disk
;
2739 idisk
->next
= *disk_list
;
2743 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
2750 static struct intel_super
*
2751 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
2754 struct imsm_super
*mpb
= super
->anchor
;
2758 for (i
= 0; i
< mpb
->num_disks
; i
++) {
2759 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
2760 struct intel_disk
*idisk
;
2762 idisk
= disk_list_get(disk
->serial
, disk_list
);
2764 if (idisk
->owner
== owner
||
2765 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
2768 dprintf("%s: '%.16s' owner %d != %d\n",
2769 __func__
, disk
->serial
, idisk
->owner
,
2772 dprintf("%s: unknown disk %x [%d]: %.16s\n",
2773 __func__
, __le32_to_cpu(mpb
->family_num
), i
,
2779 if (ok_count
== mpb
->num_disks
)
2784 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
2786 struct intel_super
*s
;
2788 for (s
= super_list
; s
; s
= s
->next
) {
2789 if (family_num
!= s
->anchor
->family_num
)
2791 fprintf(stderr
, "Conflict, offlining family %#x on '%s'\n",
2792 __le32_to_cpu(family_num
), s
->disks
->devname
);
2796 static struct intel_super
*
2797 imsm_thunderdome(struct intel_super
**super_list
, int len
)
2799 struct intel_super
*super_table
[len
];
2800 struct intel_disk
*disk_list
= NULL
;
2801 struct intel_super
*champion
, *spare
;
2802 struct intel_super
*s
, **del
;
2807 memset(super_table
, 0, sizeof(super_table
));
2808 for (s
= *super_list
; s
; s
= s
->next
)
2809 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
2811 for (i
= 0; i
< tbl_size
; i
++) {
2812 struct imsm_disk
*d
;
2813 struct intel_disk
*idisk
;
2814 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
2817 d
= &s
->disks
->disk
;
2819 /* 'd' must appear in merged disk list for its
2820 * configuration to be valid
2822 idisk
= disk_list_get(d
->serial
, disk_list
);
2823 if (idisk
&& idisk
->owner
== i
)
2824 s
= validate_members(s
, disk_list
, i
);
2829 dprintf("%s: marking family: %#x from %d:%d offline\n",
2830 __func__
, mpb
->family_num
,
2831 super_table
[i
]->disks
->major
,
2832 super_table
[i
]->disks
->minor
);
2836 /* This is where the mdadm implementation differs from the Windows
2837 * driver which has no strict concept of a container. We can only
2838 * assemble one family from a container, so when returning a prodigal
2839 * array member to this system the code will not be able to disambiguate
2840 * the container contents that should be assembled ("foreign" versus
2841 * "local"). It requires user intervention to set the orig_family_num
2842 * to a new value to establish a new container. The Windows driver in
2843 * this situation fixes up the volume name in place and manages the
2844 * foreign array as an independent entity.
2849 for (i
= 0; i
< tbl_size
; i
++) {
2850 struct intel_super
*tbl_ent
= super_table
[i
];
2856 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
2861 if (s
&& !is_spare
) {
2862 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
2864 } else if (!s
&& !is_spare
)
2877 fprintf(stderr
, "Chose family %#x on '%s', "
2878 "assemble conflicts to new container with '--update=uuid'\n",
2879 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
2881 /* collect all dl's onto 'champion', and update them to
2882 * champion's version of the status
2884 for (s
= *super_list
; s
; s
= s
->next
) {
2885 struct imsm_super
*mpb
= champion
->anchor
;
2886 struct dl
*dl
= s
->disks
;
2891 for (i
= 0; i
< mpb
->num_disks
; i
++) {
2892 struct imsm_disk
*disk
;
2894 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
2897 /* only set index on disks that are a member of
2898 * a populated contianer, i.e. one with
2901 if (is_failed(&dl
->disk
))
2903 else if (is_spare(&dl
->disk
))
2909 if (i
>= mpb
->num_disks
) {
2910 struct intel_disk
*idisk
;
2912 idisk
= disk_list_get(dl
->serial
, disk_list
);
2913 if (idisk
&& is_spare(&idisk
->disk
) &&
2914 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
2922 dl
->next
= champion
->disks
;
2923 champion
->disks
= dl
;
2927 /* delete 'champion' from super_list */
2928 for (del
= super_list
; *del
; ) {
2929 if (*del
== champion
) {
2930 *del
= (*del
)->next
;
2933 del
= &(*del
)->next
;
2935 champion
->next
= NULL
;
2939 struct intel_disk
*idisk
= disk_list
;
2941 disk_list
= disk_list
->next
;
2948 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
2952 struct intel_super
*super_list
= NULL
;
2953 struct intel_super
*super
= NULL
;
2954 int devnum
= fd2devnum(fd
);
2960 /* check if 'fd' an opened container */
2961 sra
= sysfs_read(fd
, 0, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
2965 if (sra
->array
.major_version
!= -1 ||
2966 sra
->array
.minor_version
!= -2 ||
2967 strcmp(sra
->text_version
, "imsm") != 0) {
2972 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
2973 struct intel_super
*s
= alloc_super();
2980 s
->next
= super_list
;
2984 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
2985 dfd
= dev_open(nm
, O_RDWR
);
2989 err
= load_and_parse_mpb(dfd
, s
, NULL
, 1);
2991 /* retry the load if we might have raced against mdmon */
2992 if (err
== 3 && mdmon_running(devnum
))
2993 for (retry
= 0; retry
< 3; retry
++) {
2995 err
= load_and_parse_mpb(dfd
, s
, NULL
, 1);
3003 /* all mpbs enter, maybe one leaves */
3004 super
= imsm_thunderdome(&super_list
, i
);
3010 if (find_missing(super
) != 0) {
3018 while (super_list
) {
3019 struct intel_super
*s
= super_list
;
3021 super_list
= super_list
->next
;
3030 st
->container_dev
= devnum
;
3031 if (err
== 0 && st
->ss
== NULL
) {
3032 st
->ss
= &super_imsm
;
3033 st
->minor_version
= 0;
3034 st
->max_devs
= IMSM_MAX_DEVICES
;
3039 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
3041 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
);
3045 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
3047 struct intel_super
*super
;
3051 if (load_super_imsm_all(st
, fd
, &st
->sb
, devname
) == 0)
3055 if (test_partition(fd
))
3056 /* IMSM not allowed on partitions */
3059 free_super_imsm(st
);
3061 super
= alloc_super();
3064 Name
": malloc of %zu failed.\n",
3069 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
3074 Name
": Failed to load all information "
3075 "sections on %s\n", devname
);
3081 if (st
->ss
== NULL
) {
3082 st
->ss
= &super_imsm
;
3083 st
->minor_version
= 0;
3084 st
->max_devs
= IMSM_MAX_DEVICES
;
3089 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
3091 if (info
->level
== 1)
3093 return info
->chunk_size
>> 9;
3096 static __u32
info_to_num_data_stripes(mdu_array_info_t
*info
, int num_domains
)
3100 num_stripes
= (info
->size
* 2) / info_to_blocks_per_strip(info
);
3101 num_stripes
/= num_domains
;
3106 static __u32
info_to_blocks_per_member(mdu_array_info_t
*info
)
3108 if (info
->level
== 1)
3109 return info
->size
* 2;
3111 return (info
->size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
3114 static void imsm_update_version_info(struct intel_super
*super
)
3116 /* update the version and attributes */
3117 struct imsm_super
*mpb
= super
->anchor
;
3119 struct imsm_dev
*dev
;
3120 struct imsm_map
*map
;
3123 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
3124 dev
= get_imsm_dev(super
, i
);
3125 map
= get_imsm_map(dev
, 0);
3126 if (__le32_to_cpu(dev
->size_high
) > 0)
3127 mpb
->attributes
|= MPB_ATTRIB_2TB
;
3129 /* FIXME detect when an array spans a port multiplier */
3131 mpb
->attributes
|= MPB_ATTRIB_PM
;
3134 if (mpb
->num_raid_devs
> 1 ||
3135 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
3136 version
= MPB_VERSION_ATTRIBS
;
3137 switch (get_imsm_raid_level(map
)) {
3138 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
3139 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
3140 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
3141 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
3144 if (map
->num_members
>= 5)
3145 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
3146 else if (dev
->status
== DEV_CLONE_N_GO
)
3147 version
= MPB_VERSION_CNG
;
3148 else if (get_imsm_raid_level(map
) == 5)
3149 version
= MPB_VERSION_RAID5
;
3150 else if (map
->num_members
>= 3)
3151 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
3152 else if (get_imsm_raid_level(map
) == 1)
3153 version
= MPB_VERSION_RAID1
;
3155 version
= MPB_VERSION_RAID0
;
3157 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
3161 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
3163 struct imsm_super
*mpb
= super
->anchor
;
3164 char *reason
= NULL
;
3167 if (strlen(name
) > MAX_RAID_SERIAL_LEN
)
3168 reason
= "must be 16 characters or less";
3170 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
3171 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
3173 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
3174 reason
= "already exists";
3179 if (reason
&& !quiet
)
3180 fprintf(stderr
, Name
": imsm volume name %s\n", reason
);
3185 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
3186 unsigned long long size
, char *name
,
3187 char *homehost
, int *uuid
)
3189 /* We are creating a volume inside a pre-existing container.
3190 * so st->sb is already set.
3192 struct intel_super
*super
= st
->sb
;
3193 struct imsm_super
*mpb
= super
->anchor
;
3194 struct intel_dev
*dv
;
3195 struct imsm_dev
*dev
;
3196 struct imsm_vol
*vol
;
3197 struct imsm_map
*map
;
3198 int idx
= mpb
->num_raid_devs
;
3200 unsigned long long array_blocks
;
3201 size_t size_old
, size_new
;
3202 __u32 num_data_stripes
;
3204 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
3205 fprintf(stderr
, Name
": This imsm-container already has the "
3206 "maximum of %d volumes\n", super
->orom
->vpa
);
3210 /* ensure the mpb is large enough for the new data */
3211 size_old
= __le32_to_cpu(mpb
->mpb_size
);
3212 size_new
= disks_to_mpb_size(info
->nr_disks
);
3213 if (size_new
> size_old
) {
3215 size_t size_round
= ROUND_UP(size_new
, 512);
3217 if (posix_memalign(&mpb_new
, 512, size_round
) != 0) {
3218 fprintf(stderr
, Name
": could not allocate new mpb\n");
3221 memcpy(mpb_new
, mpb
, size_old
);
3224 super
->anchor
= mpb_new
;
3225 mpb
->mpb_size
= __cpu_to_le32(size_new
);
3226 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
3228 super
->current_vol
= idx
;
3229 /* when creating the first raid device in this container set num_disks
3230 * to zero, i.e. delete this spare and add raid member devices in
3231 * add_to_super_imsm_volume()
3233 if (super
->current_vol
== 0)
3236 if (!check_name(super
, name
, 0))
3238 dv
= malloc(sizeof(*dv
));
3240 fprintf(stderr
, Name
": failed to allocate device list entry\n");
3243 dev
= malloc(sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
3246 fprintf(stderr
, Name
": could not allocate raid device\n");
3249 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
3250 if (info
->level
== 1)
3251 array_blocks
= info_to_blocks_per_member(info
);
3253 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
3254 info
->layout
, info
->chunk_size
,
3256 /* round array size down to closest MB */
3257 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
3259 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
3260 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
3261 dev
->status
= __cpu_to_le32(0);
3262 dev
->reserved_blocks
= __cpu_to_le32(0);
3264 vol
->migr_state
= 0;
3265 set_migr_type(dev
, MIGR_INIT
);
3267 vol
->curr_migr_unit
= 0;
3268 map
= get_imsm_map(dev
, 0);
3269 map
->pba_of_lba0
= __cpu_to_le32(super
->create_offset
);
3270 map
->blocks_per_member
= __cpu_to_le32(info_to_blocks_per_member(info
));
3271 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
3272 map
->failed_disk_num
= ~0;
3273 map
->map_state
= info
->level
? IMSM_T_STATE_UNINITIALIZED
:
3274 IMSM_T_STATE_NORMAL
;
3277 if (info
->level
== 1 && info
->raid_disks
> 2) {
3280 fprintf(stderr
, Name
": imsm does not support more than 2 disks"
3281 "in a raid1 volume\n");
3285 map
->raid_level
= info
->level
;
3286 if (info
->level
== 10) {
3287 map
->raid_level
= 1;
3288 map
->num_domains
= info
->raid_disks
/ 2;
3289 } else if (info
->level
== 1)
3290 map
->num_domains
= info
->raid_disks
;
3292 map
->num_domains
= 1;
3294 num_data_stripes
= info_to_num_data_stripes(info
, map
->num_domains
);
3295 map
->num_data_stripes
= __cpu_to_le32(num_data_stripes
);
3297 map
->num_members
= info
->raid_disks
;
3298 for (i
= 0; i
< map
->num_members
; i
++) {
3299 /* initialized in add_to_super */
3300 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
3302 mpb
->num_raid_devs
++;
3305 dv
->index
= super
->current_vol
;
3306 dv
->next
= super
->devlist
;
3307 super
->devlist
= dv
;
3309 imsm_update_version_info(super
);
3314 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
3315 unsigned long long size
, char *name
,
3316 char *homehost
, int *uuid
)
3318 /* This is primarily called by Create when creating a new array.
3319 * We will then get add_to_super called for each component, and then
3320 * write_init_super called to write it out to each device.
3321 * For IMSM, Create can create on fresh devices or on a pre-existing
3323 * To create on a pre-existing array a different method will be called.
3324 * This one is just for fresh drives.
3326 struct intel_super
*super
;
3327 struct imsm_super
*mpb
;
3332 return init_super_imsm_volume(st
, info
, size
, name
, homehost
, uuid
);
3335 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
3339 super
= alloc_super();
3340 if (super
&& posix_memalign(&super
->buf
, 512, mpb_size
) != 0) {
3345 fprintf(stderr
, Name
3346 ": %s could not allocate superblock\n", __func__
);
3349 memset(super
->buf
, 0, mpb_size
);
3351 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
3355 /* zeroing superblock */
3359 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
3361 version
= (char *) mpb
->sig
;
3362 strcpy(version
, MPB_SIGNATURE
);
3363 version
+= strlen(MPB_SIGNATURE
);
3364 strcpy(version
, MPB_VERSION_RAID0
);
3370 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
3371 int fd
, char *devname
)
3373 struct intel_super
*super
= st
->sb
;
3374 struct imsm_super
*mpb
= super
->anchor
;
3376 struct imsm_dev
*dev
;
3377 struct imsm_map
*map
;
3380 dev
= get_imsm_dev(super
, super
->current_vol
);
3381 map
= get_imsm_map(dev
, 0);
3383 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
3384 fprintf(stderr
, Name
": %s: Cannot add spare devices to IMSM volume\n",
3390 /* we're doing autolayout so grab the pre-marked (in
3391 * validate_geometry) raid_disk
3393 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3394 if (dl
->raiddisk
== dk
->raid_disk
)
3397 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3398 if (dl
->major
== dk
->major
&&
3399 dl
->minor
== dk
->minor
)
3404 fprintf(stderr
, Name
": %s is not a member of the same container\n", devname
);
3408 /* add a pristine spare to the metadata */
3409 if (dl
->index
< 0) {
3410 dl
->index
= super
->anchor
->num_disks
;
3411 super
->anchor
->num_disks
++;
3413 /* Check the device has not already been added */
3414 slot
= get_imsm_disk_slot(map
, dl
->index
);
3416 (get_imsm_ord_tbl_ent(dev
, slot
, -1) & IMSM_ORD_REBUILD
) == 0) {
3417 fprintf(stderr
, Name
": %s has been included in this array twice\n",
3421 set_imsm_ord_tbl_ent(map
, dk
->number
, dl
->index
);
3422 dl
->disk
.status
= CONFIGURED_DISK
;
3424 /* if we are creating the first raid device update the family number */
3425 if (super
->current_vol
== 0) {
3427 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
3428 struct imsm_disk
*_disk
= __get_imsm_disk(mpb
, dl
->index
);
3430 if (!_dev
|| !_disk
) {
3431 fprintf(stderr
, Name
": BUG mpb setup error\n");
3437 sum
+= __gen_imsm_checksum(mpb
);
3438 mpb
->family_num
= __cpu_to_le32(sum
);
3439 mpb
->orig_family_num
= mpb
->family_num
;
3445 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
3446 int fd
, char *devname
)
3448 struct intel_super
*super
= st
->sb
;
3450 unsigned long long size
;
3455 /* if we are on an RAID enabled platform check that the disk is
3456 * attached to the raid controller
3458 if (super
->hba
&& !disk_attached_to_hba(fd
, super
->hba
)) {
3460 Name
": %s is not attached to the raid controller: %s\n",
3461 devname
? : "disk", super
->hba
);
3465 if (super
->current_vol
>= 0)
3466 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
3469 dd
= malloc(sizeof(*dd
));
3472 Name
": malloc failed %s:%d.\n", __func__
, __LINE__
);
3475 memset(dd
, 0, sizeof(*dd
));
3476 dd
->major
= major(stb
.st_rdev
);
3477 dd
->minor
= minor(stb
.st_rdev
);
3479 dd
->devname
= devname
? strdup(devname
) : NULL
;
3482 dd
->action
= DISK_ADD
;
3483 rv
= imsm_read_serial(fd
, devname
, dd
->serial
);
3486 Name
": failed to retrieve scsi serial, aborting\n");
3491 get_dev_size(fd
, NULL
, &size
);
3493 serialcpy(dd
->disk
.serial
, dd
->serial
);
3494 dd
->disk
.total_blocks
= __cpu_to_le32(size
);
3495 dd
->disk
.status
= SPARE_DISK
;
3496 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
3497 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
3499 dd
->disk
.scsi_id
= __cpu_to_le32(0);
3501 if (st
->update_tail
) {
3502 dd
->next
= super
->disk_mgmt_list
;
3503 super
->disk_mgmt_list
= dd
;
3505 dd
->next
= super
->disks
;
3513 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
3515 struct intel_super
*super
= st
->sb
;
3518 /* remove from super works only in mdmon - for communication
3519 * manager - monitor. Check if communication memory buffer
3522 if (!st
->update_tail
) {
3524 Name
": %s shall be used in mdmon context only"
3525 "(line %d).\n", __func__
, __LINE__
);
3528 dd
= malloc(sizeof(*dd
));
3531 Name
": malloc failed %s:%d.\n", __func__
, __LINE__
);
3534 memset(dd
, 0, sizeof(*dd
));
3535 dd
->major
= dk
->major
;
3536 dd
->minor
= dk
->minor
;
3539 dd
->disk
.status
= SPARE_DISK
;
3540 dd
->action
= DISK_REMOVE
;
3542 dd
->next
= super
->disk_mgmt_list
;
3543 super
->disk_mgmt_list
= dd
;
3549 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
3553 struct imsm_super anchor
;
3554 } spare_record
__attribute__ ((aligned(512)));
3556 /* spare records have their own family number and do not have any defined raid
3559 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
3561 struct imsm_super
*mpb
= super
->anchor
;
3562 struct imsm_super
*spare
= &spare_record
.anchor
;
3566 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
)),
3567 spare
->generation_num
= __cpu_to_le32(1UL),
3568 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
3569 spare
->num_disks
= 1,
3570 spare
->num_raid_devs
= 0,
3571 spare
->cache_size
= mpb
->cache_size
,
3572 spare
->pwr_cycle_count
= __cpu_to_le32(1),
3574 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
3575 MPB_SIGNATURE MPB_VERSION_RAID0
);
3577 for (d
= super
->disks
; d
; d
= d
->next
) {
3581 spare
->disk
[0] = d
->disk
;
3582 sum
= __gen_imsm_checksum(spare
);
3583 spare
->family_num
= __cpu_to_le32(sum
);
3584 spare
->orig_family_num
= 0;
3585 sum
= __gen_imsm_checksum(spare
);
3586 spare
->check_sum
= __cpu_to_le32(sum
);
3588 if (store_imsm_mpb(d
->fd
, spare
)) {
3589 fprintf(stderr
, "%s: failed for device %d:%d %s\n",
3590 __func__
, d
->major
, d
->minor
, strerror(errno
));
3602 static int write_super_imsm(struct supertype
*st
, int doclose
)
3604 struct intel_super
*super
= st
->sb
;
3605 struct imsm_super
*mpb
= super
->anchor
;
3611 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
3614 /* 'generation' is incremented everytime the metadata is written */
3615 generation
= __le32_to_cpu(mpb
->generation_num
);
3617 mpb
->generation_num
= __cpu_to_le32(generation
);
3619 /* fix up cases where previous mdadm releases failed to set
3622 if (mpb
->orig_family_num
== 0)
3623 mpb
->orig_family_num
= mpb
->family_num
;
3625 for (d
= super
->disks
; d
; d
= d
->next
) {
3629 mpb
->disk
[d
->index
] = d
->disk
;
3633 for (d
= super
->missing
; d
; d
= d
->next
) {
3634 mpb
->disk
[d
->index
] = d
->disk
;
3637 mpb
->num_disks
= num_disks
;
3638 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
3640 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
3641 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
3642 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
3644 imsm_copy_dev(dev
, dev2
);
3645 mpb_size
+= sizeof_imsm_dev(dev
, 0);
3648 mpb_size
+= __le32_to_cpu(mpb
->bbm_log_size
);
3649 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
3651 /* recalculate checksum */
3652 sum
= __gen_imsm_checksum(mpb
);
3653 mpb
->check_sum
= __cpu_to_le32(sum
);
3655 /* write the mpb for disks that compose raid devices */
3656 for (d
= super
->disks
; d
; d
= d
->next
) {
3659 if (store_imsm_mpb(d
->fd
, mpb
))
3660 fprintf(stderr
, "%s: failed for device %d:%d %s\n",
3661 __func__
, d
->major
, d
->minor
, strerror(errno
));
3669 return write_super_imsm_spares(super
, doclose
);
3675 static int create_array(struct supertype
*st
, int dev_idx
)
3678 struct imsm_update_create_array
*u
;
3679 struct intel_super
*super
= st
->sb
;
3680 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
3681 struct imsm_map
*map
= get_imsm_map(dev
, 0);
3682 struct disk_info
*inf
;
3683 struct imsm_disk
*disk
;
3686 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
3687 sizeof(*inf
) * map
->num_members
;
3690 fprintf(stderr
, "%s: failed to allocate update buffer\n",
3695 u
->type
= update_create_array
;
3696 u
->dev_idx
= dev_idx
;
3697 imsm_copy_dev(&u
->dev
, dev
);
3698 inf
= get_disk_info(u
);
3699 for (i
= 0; i
< map
->num_members
; i
++) {
3700 int idx
= get_imsm_disk_idx(dev
, i
, -1);
3702 disk
= get_imsm_disk(super
, idx
);
3703 serialcpy(inf
[i
].serial
, disk
->serial
);
3705 append_metadata_update(st
, u
, len
);
3710 static int mgmt_disk(struct supertype
*st
)
3712 struct intel_super
*super
= st
->sb
;
3714 struct imsm_update_add_remove_disk
*u
;
3716 if (!super
->disk_mgmt_list
)
3722 fprintf(stderr
, "%s: failed to allocate update buffer\n",
3727 u
->type
= update_add_remove_disk
;
3728 append_metadata_update(st
, u
, len
);
3733 static int write_init_super_imsm(struct supertype
*st
)
3735 struct intel_super
*super
= st
->sb
;
3736 int current_vol
= super
->current_vol
;
3738 /* we are done with current_vol reset it to point st at the container */
3739 super
->current_vol
= -1;
3741 if (st
->update_tail
) {
3742 /* queue the recently created array / added disk
3743 * as a metadata update */
3747 /* determine if we are creating a volume or adding a disk */
3748 if (current_vol
< 0) {
3749 /* in the mgmt (add/remove) disk case we are running
3750 * in mdmon context, so don't close fd's
3752 return mgmt_disk(st
);
3754 rv
= create_array(st
, current_vol
);
3756 for (d
= super
->disks
; d
; d
= d
->next
) {
3764 for (d
= super
->disks
; d
; d
= d
->next
)
3765 Kill(d
->devname
, NULL
, 0, 1, 1);
3766 return write_super_imsm(st
, 1);
3771 static int store_super_imsm(struct supertype
*st
, int fd
)
3773 struct intel_super
*super
= st
->sb
;
3774 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
3780 return store_imsm_mpb(fd
, mpb
);
3786 static int imsm_bbm_log_size(struct imsm_super
*mpb
)
3788 return __le32_to_cpu(mpb
->bbm_log_size
);
3792 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
3793 int layout
, int raiddisks
, int chunk
,
3794 unsigned long long size
, char *dev
,
3795 unsigned long long *freesize
,
3799 unsigned long long ldsize
;
3800 const struct imsm_orom
*orom
;
3802 if (level
!= LEVEL_CONTAINER
)
3807 if (check_env("IMSM_NO_PLATFORM"))
3810 orom
= find_imsm_orom();
3811 if (orom
&& raiddisks
> orom
->tds
) {
3813 fprintf(stderr
, Name
": %d exceeds maximum number of"
3814 " platform supported disks: %d\n",
3815 raiddisks
, orom
->tds
);
3819 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
3822 fprintf(stderr
, Name
": imsm: Cannot open %s: %s\n",
3823 dev
, strerror(errno
));
3826 if (!get_dev_size(fd
, dev
, &ldsize
)) {
3832 *freesize
= avail_size_imsm(st
, ldsize
>> 9);
3837 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
3839 const unsigned long long base_start
= e
[*idx
].start
;
3840 unsigned long long end
= base_start
+ e
[*idx
].size
;
3843 if (base_start
== end
)
3847 for (i
= *idx
; i
< num_extents
; i
++) {
3848 /* extend overlapping extents */
3849 if (e
[i
].start
>= base_start
&&
3850 e
[i
].start
<= end
) {
3853 if (e
[i
].start
+ e
[i
].size
> end
)
3854 end
= e
[i
].start
+ e
[i
].size
;
3855 } else if (e
[i
].start
> end
) {
3861 return end
- base_start
;
3864 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
3866 /* build a composite disk with all known extents and generate a new
3867 * 'maxsize' given the "all disks in an array must share a common start
3868 * offset" constraint
3870 struct extent
*e
= calloc(sum_extents
, sizeof(*e
));
3874 unsigned long long pos
;
3875 unsigned long long start
= 0;
3876 unsigned long long maxsize
;
3877 unsigned long reserve
;
3882 /* coalesce and sort all extents. also, check to see if we need to
3883 * reserve space between member arrays
3886 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
3889 for (i
= 0; i
< dl
->extent_cnt
; i
++)
3892 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
3897 while (i
< sum_extents
) {
3898 e
[j
].start
= e
[i
].start
;
3899 e
[j
].size
= find_size(e
, &i
, sum_extents
);
3901 if (e
[j
-1].size
== 0)
3910 unsigned long long esize
;
3912 esize
= e
[i
].start
- pos
;
3913 if (esize
>= maxsize
) {
3918 pos
= e
[i
].start
+ e
[i
].size
;
3920 } while (e
[i
-1].size
);
3926 /* FIXME assumes volume at offset 0 is the first volume in a
3929 if (start_extent
> 0)
3930 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
3934 if (maxsize
< reserve
)
3937 super
->create_offset
= ~((__u32
) 0);
3938 if (start
+ reserve
> super
->create_offset
)
3939 return 0; /* start overflows create_offset */
3940 super
->create_offset
= start
+ reserve
;
3942 return maxsize
- reserve
;
3945 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
3947 if (level
< 0 || level
== 6 || level
== 4)
3950 /* if we have an orom prevent invalid raid levels */
3953 case 0: return imsm_orom_has_raid0(orom
);
3956 return imsm_orom_has_raid1e(orom
);
3957 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
3958 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
3959 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
3962 return 1; /* not on an Intel RAID platform so anything goes */
3967 #define pr_vrb(fmt, arg...) (void) (verbose && fprintf(stderr, Name fmt, ##arg))
3969 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
3970 int raiddisks
, int chunk
, int verbose
)
3972 if (!is_raid_level_supported(super
->orom
, level
, raiddisks
)) {
3973 pr_vrb(": platform does not support raid%d with %d disk%s\n",
3974 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
3977 if (super
->orom
&& level
!= 1 &&
3978 !imsm_orom_has_chunk(super
->orom
, chunk
)) {
3979 pr_vrb(": platform does not support a chunk size of: %d\n", chunk
);
3982 if (layout
!= imsm_level_to_layout(level
)) {
3984 pr_vrb(": imsm raid 5 only supports the left-asymmetric layout\n");
3985 else if (level
== 10)
3986 pr_vrb(": imsm raid 10 only supports the n2 layout\n");
3988 pr_vrb(": imsm unknown layout %#x for this raid level %d\n",
3996 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
3997 * FIX ME add ahci details
3999 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
4000 int layout
, int raiddisks
, int chunk
,
4001 unsigned long long size
, char *dev
,
4002 unsigned long long *freesize
,
4006 struct intel_super
*super
= st
->sb
;
4007 struct imsm_super
*mpb
= super
->anchor
;
4009 unsigned long long pos
= 0;
4010 unsigned long long maxsize
;
4014 /* We must have the container info already read in. */
4018 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, verbose
))
4022 /* General test: make sure there is space for
4023 * 'raiddisks' device extents of size 'size' at a given
4026 unsigned long long minsize
= size
;
4027 unsigned long long start_offset
= MaxSector
;
4030 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
4031 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
4036 e
= get_extents(super
, dl
);
4039 unsigned long long esize
;
4040 esize
= e
[i
].start
- pos
;
4041 if (esize
>= minsize
)
4043 if (found
&& start_offset
== MaxSector
) {
4046 } else if (found
&& pos
!= start_offset
) {
4050 pos
= e
[i
].start
+ e
[i
].size
;
4052 } while (e
[i
-1].size
);
4057 if (dcnt
< raiddisks
) {
4059 fprintf(stderr
, Name
": imsm: Not enough "
4060 "devices with space for this array "
4068 /* This device must be a member of the set */
4069 if (stat(dev
, &stb
) < 0)
4071 if ((S_IFMT
& stb
.st_mode
) != S_IFBLK
)
4073 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
4074 if (dl
->major
== (int)major(stb
.st_rdev
) &&
4075 dl
->minor
== (int)minor(stb
.st_rdev
))
4080 fprintf(stderr
, Name
": %s is not in the "
4081 "same imsm set\n", dev
);
4083 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
4084 /* If a volume is present then the current creation attempt
4085 * cannot incorporate new spares because the orom may not
4086 * understand this configuration (all member disks must be
4087 * members of each array in the container).
4089 fprintf(stderr
, Name
": %s is a spare and a volume"
4090 " is already defined for this container\n", dev
);
4091 fprintf(stderr
, Name
": The option-rom requires all member"
4092 " disks to be a member of all volumes\n");
4096 /* retrieve the largest free space block */
4097 e
= get_extents(super
, dl
);
4102 unsigned long long esize
;
4104 esize
= e
[i
].start
- pos
;
4105 if (esize
>= maxsize
)
4107 pos
= e
[i
].start
+ e
[i
].size
;
4109 } while (e
[i
-1].size
);
4114 fprintf(stderr
, Name
": unable to determine free space for: %s\n",
4118 if (maxsize
< size
) {
4120 fprintf(stderr
, Name
": %s not enough space (%llu < %llu)\n",
4121 dev
, maxsize
, size
);
4125 /* count total number of extents for merge */
4127 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4129 i
+= dl
->extent_cnt
;
4131 maxsize
= merge_extents(super
, i
);
4132 if (maxsize
< size
|| maxsize
== 0) {
4134 fprintf(stderr
, Name
": not enough space after merge (%llu < %llu)\n",
4139 *freesize
= maxsize
;
4144 static int reserve_space(struct supertype
*st
, int raiddisks
,
4145 unsigned long long size
, int chunk
,
4146 unsigned long long *freesize
)
4148 struct intel_super
*super
= st
->sb
;
4149 struct imsm_super
*mpb
= super
->anchor
;
4154 unsigned long long maxsize
;
4155 unsigned long long minsize
;
4159 /* find the largest common start free region of the possible disks */
4163 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
4169 /* don't activate new spares if we are orom constrained
4170 * and there is already a volume active in the container
4172 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
4175 e
= get_extents(super
, dl
);
4178 for (i
= 1; e
[i
-1].size
; i
++)
4186 maxsize
= merge_extents(super
, extent_cnt
);
4191 if (cnt
< raiddisks
||
4192 (super
->orom
&& used
&& used
!= raiddisks
) ||
4193 maxsize
< minsize
||
4195 fprintf(stderr
, Name
": not enough devices with space to create array.\n");
4196 return 0; /* No enough free spaces large enough */
4208 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4210 dl
->raiddisk
= cnt
++;
4217 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
4218 int raiddisks
, int chunk
, unsigned long long size
,
4219 char *dev
, unsigned long long *freesize
,
4226 /* if given unused devices create a container
4227 * if given given devices in a container create a member volume
4229 if (level
== LEVEL_CONTAINER
) {
4230 /* Must be a fresh device to add to a container */
4231 return validate_geometry_imsm_container(st
, level
, layout
,
4232 raiddisks
, chunk
, size
,
4238 if (st
->sb
&& freesize
) {
4239 /* we are being asked to automatically layout a
4240 * new volume based on the current contents of
4241 * the container. If the the parameters can be
4242 * satisfied reserve_space will record the disks,
4243 * start offset, and size of the volume to be
4244 * created. add_to_super and getinfo_super
4245 * detect when autolayout is in progress.
4247 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
4251 return reserve_space(st
, raiddisks
, size
, chunk
, freesize
);
4256 /* creating in a given container */
4257 return validate_geometry_imsm_volume(st
, level
, layout
,
4258 raiddisks
, chunk
, size
,
4259 dev
, freesize
, verbose
);
4262 /* This device needs to be a device in an 'imsm' container */
4263 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
4267 Name
": Cannot create this array on device %s\n",
4272 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
4274 fprintf(stderr
, Name
": Cannot open %s: %s\n",
4275 dev
, strerror(errno
));
4278 /* Well, it is in use by someone, maybe an 'imsm' container. */
4279 cfd
= open_container(fd
);
4283 fprintf(stderr
, Name
": Cannot use %s: It is busy\n",
4287 sra
= sysfs_read(cfd
, 0, GET_VERSION
);
4288 if (sra
&& sra
->array
.major_version
== -1 &&
4289 strcmp(sra
->text_version
, "imsm") == 0)
4293 /* This is a member of a imsm container. Load the container
4294 * and try to create a volume
4296 struct intel_super
*super
;
4298 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
) == 0) {
4300 st
->container_dev
= fd2devnum(cfd
);
4302 return validate_geometry_imsm_volume(st
, level
, layout
,
4310 fprintf(stderr
, Name
": failed container membership check\n");
4316 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
4318 struct intel_super
*super
= st
->sb
;
4320 if (level
&& *level
== UnSet
)
4321 *level
= LEVEL_CONTAINER
;
4323 if (level
&& layout
&& *layout
== UnSet
)
4324 *layout
= imsm_level_to_layout(*level
);
4326 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0) &&
4327 super
&& super
->orom
)
4328 *chunk
= imsm_orom_default_chunk(super
->orom
);
4331 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
4333 static int kill_subarray_imsm(struct supertype
*st
)
4335 /* remove the subarray currently referenced by ->current_vol */
4337 struct intel_dev
**dp
;
4338 struct intel_super
*super
= st
->sb
;
4339 __u8 current_vol
= super
->current_vol
;
4340 struct imsm_super
*mpb
= super
->anchor
;
4342 if (super
->current_vol
< 0)
4344 super
->current_vol
= -1; /* invalidate subarray cursor */
4346 /* block deletions that would change the uuid of active subarrays
4348 * FIXME when immutable ids are available, but note that we'll
4349 * also need to fixup the invalidated/active subarray indexes in
4352 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4355 if (i
< current_vol
)
4357 sprintf(subarray
, "%u", i
);
4358 if (is_subarray_active(subarray
, st
->devname
)) {
4360 Name
": deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
4367 if (st
->update_tail
) {
4368 struct imsm_update_kill_array
*u
= malloc(sizeof(*u
));
4372 u
->type
= update_kill_array
;
4373 u
->dev_idx
= current_vol
;
4374 append_metadata_update(st
, u
, sizeof(*u
));
4379 for (dp
= &super
->devlist
; *dp
;)
4380 if ((*dp
)->index
== current_vol
) {
4383 handle_missing(super
, (*dp
)->dev
);
4384 if ((*dp
)->index
> current_vol
)
4389 /* no more raid devices, all active components are now spares,
4390 * but of course failed are still failed
4392 if (--mpb
->num_raid_devs
== 0) {
4395 for (d
= super
->disks
; d
; d
= d
->next
)
4396 if (d
->index
> -2) {
4398 d
->disk
.status
= SPARE_DISK
;
4402 super
->updates_pending
++;
4407 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
4408 char *update
, struct mddev_ident
*ident
)
4410 /* update the subarray currently referenced by ->current_vol */
4411 struct intel_super
*super
= st
->sb
;
4412 struct imsm_super
*mpb
= super
->anchor
;
4414 if (strcmp(update
, "name") == 0) {
4415 char *name
= ident
->name
;
4419 if (is_subarray_active(subarray
, st
->devname
)) {
4421 Name
": Unable to update name of active subarray\n");
4425 if (!check_name(super
, name
, 0))
4428 vol
= strtoul(subarray
, &ep
, 10);
4429 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
4432 if (st
->update_tail
) {
4433 struct imsm_update_rename_array
*u
= malloc(sizeof(*u
));
4437 u
->type
= update_rename_array
;
4439 snprintf((char *) u
->name
, MAX_RAID_SERIAL_LEN
, "%s", name
);
4440 append_metadata_update(st
, u
, sizeof(*u
));
4442 struct imsm_dev
*dev
;
4445 dev
= get_imsm_dev(super
, vol
);
4446 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
4447 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4448 dev
= get_imsm_dev(super
, i
);
4449 handle_missing(super
, dev
);
4451 super
->updates_pending
++;
4458 #endif /* MDASSEMBLE */
4460 static int is_gen_migration(struct imsm_dev
*dev
)
4462 if (!dev
->vol
.migr_state
)
4465 if (migr_type(dev
) == MIGR_GEN_MIGR
)
4471 static int is_rebuilding(struct imsm_dev
*dev
)
4473 struct imsm_map
*migr_map
;
4475 if (!dev
->vol
.migr_state
)
4478 if (migr_type(dev
) != MIGR_REBUILD
)
4481 migr_map
= get_imsm_map(dev
, 1);
4483 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
4489 static void update_recovery_start(struct imsm_dev
*dev
, struct mdinfo
*array
)
4491 struct mdinfo
*rebuild
= NULL
;
4495 if (!is_rebuilding(dev
))
4498 /* Find the rebuild target, but punt on the dual rebuild case */
4499 for (d
= array
->devs
; d
; d
= d
->next
)
4500 if (d
->recovery_start
== 0) {
4507 /* (?) none of the disks are marked with
4508 * IMSM_ORD_REBUILD, so assume they are missing and the
4509 * disk_ord_tbl was not correctly updated
4511 dprintf("%s: failed to locate out-of-sync disk\n", __func__
);
4515 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
4516 rebuild
->recovery_start
= units
* blocks_per_migr_unit(dev
);
4520 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
4522 /* Given a container loaded by load_super_imsm_all,
4523 * extract information about all the arrays into
4525 * If 'subarray' is given, just extract info about that array.
4527 * For each imsm_dev create an mdinfo, fill it in,
4528 * then look for matching devices in super->disks
4529 * and create appropriate device mdinfo.
4531 struct intel_super
*super
= st
->sb
;
4532 struct imsm_super
*mpb
= super
->anchor
;
4533 struct mdinfo
*rest
= NULL
;
4537 /* check for bad blocks */
4538 if (imsm_bbm_log_size(super
->anchor
))
4541 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4542 struct imsm_dev
*dev
;
4543 struct imsm_map
*map
;
4544 struct imsm_map
*map2
;
4545 struct mdinfo
*this;
4550 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
4553 dev
= get_imsm_dev(super
, i
);
4554 map
= get_imsm_map(dev
, 0);
4555 map2
= get_imsm_map(dev
, 1);
4557 /* do not publish arrays that are in the middle of an
4558 * unsupported migration
4560 if (dev
->vol
.migr_state
&&
4561 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
4562 fprintf(stderr
, Name
": cannot assemble volume '%.16s':"
4563 " unsupported migration in progress\n",
4568 this = malloc(sizeof(*this));
4570 fprintf(stderr
, Name
": failed to allocate %zu bytes\n",
4574 memset(this, 0, sizeof(*this));
4577 super
->current_vol
= i
;
4578 getinfo_super_imsm_volume(st
, this, NULL
);
4579 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
4580 unsigned long long recovery_start
;
4581 struct mdinfo
*info_d
;
4588 idx
= get_imsm_disk_idx(dev
, slot
, 0);
4589 ord
= get_imsm_ord_tbl_ent(dev
, slot
, 0);
4590 for (d
= super
->disks
; d
; d
= d
->next
)
4591 if (d
->index
== idx
)
4594 recovery_start
= MaxSector
;
4597 if (d
&& is_failed(&d
->disk
))
4599 if (ord
& IMSM_ORD_REBUILD
)
4603 * if we skip some disks the array will be assmebled degraded;
4604 * reset resync start to avoid a dirty-degraded
4605 * situation when performing the intial sync
4607 * FIXME handle dirty degraded
4609 if ((skip
|| recovery_start
== 0) && !dev
->vol
.dirty
)
4610 this->resync_start
= MaxSector
;
4614 info_d
= calloc(1, sizeof(*info_d
));
4616 fprintf(stderr
, Name
": failed to allocate disk"
4617 " for volume %.16s\n", dev
->volume
);
4618 info_d
= this->devs
;
4620 struct mdinfo
*d
= info_d
->next
;
4629 info_d
->next
= this->devs
;
4630 this->devs
= info_d
;
4632 info_d
->disk
.number
= d
->index
;
4633 info_d
->disk
.major
= d
->major
;
4634 info_d
->disk
.minor
= d
->minor
;
4635 info_d
->disk
.raid_disk
= slot
;
4636 info_d
->recovery_start
= recovery_start
;
4638 if (slot
< map2
->num_members
)
4639 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
4641 if (slot
< map
->num_members
)
4642 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
4644 if (info_d
->recovery_start
== MaxSector
)
4645 this->array
.working_disks
++;
4647 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
4648 info_d
->data_offset
= __le32_to_cpu(map
->pba_of_lba0
);
4649 info_d
->component_size
= __le32_to_cpu(map
->blocks_per_member
);
4651 /* now that the disk list is up-to-date fixup recovery_start */
4652 update_recovery_start(dev
, this);
4656 /* if array has bad blocks, set suitable bit in array status */
4658 rest
->array
.state
|= (1<<MD_SB_BBM_ERRORS
);
4664 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
, int failed
)
4666 struct imsm_map
*map
= get_imsm_map(dev
, 0);
4669 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
4670 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
4672 switch (get_imsm_raid_level(map
)) {
4674 return IMSM_T_STATE_FAILED
;
4677 if (failed
< map
->num_members
)
4678 return IMSM_T_STATE_DEGRADED
;
4680 return IMSM_T_STATE_FAILED
;
4685 * check to see if any mirrors have failed, otherwise we
4686 * are degraded. Even numbered slots are mirrored on
4690 /* gcc -Os complains that this is unused */
4691 int insync
= insync
;
4693 for (i
= 0; i
< map
->num_members
; i
++) {
4694 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, -1);
4695 int idx
= ord_to_idx(ord
);
4696 struct imsm_disk
*disk
;
4698 /* reset the potential in-sync count on even-numbered
4699 * slots. num_copies is always 2 for imsm raid10
4704 disk
= get_imsm_disk(super
, idx
);
4705 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
4708 /* no in-sync disks left in this mirror the
4712 return IMSM_T_STATE_FAILED
;
4715 return IMSM_T_STATE_DEGRADED
;
4719 return IMSM_T_STATE_DEGRADED
;
4721 return IMSM_T_STATE_FAILED
;
4727 return map
->map_state
;
4730 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
)
4734 struct imsm_disk
*disk
;
4735 struct imsm_map
*map
= get_imsm_map(dev
, 0);
4736 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
);
4740 /* at the beginning of migration we set IMSM_ORD_REBUILD on
4741 * disks that are being rebuilt. New failures are recorded to
4742 * map[0]. So we look through all the disks we started with and
4743 * see if any failures are still present, or if any new ones
4746 * FIXME add support for online capacity expansion and
4747 * raid-level-migration
4749 for (i
= 0; i
< prev
->num_members
; i
++) {
4750 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
4751 ord
|= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
4752 idx
= ord_to_idx(ord
);
4754 disk
= get_imsm_disk(super
, idx
);
4755 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
4763 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
4766 struct intel_super
*super
= c
->sb
;
4767 struct imsm_super
*mpb
= super
->anchor
;
4769 if (atoi(inst
) >= mpb
->num_raid_devs
) {
4770 fprintf(stderr
, "%s: subarry index %d, out of range\n",
4771 __func__
, atoi(inst
));
4775 dprintf("imsm: open_new %s\n", inst
);
4776 a
->info
.container_member
= atoi(inst
);
4780 static int is_resyncing(struct imsm_dev
*dev
)
4782 struct imsm_map
*migr_map
;
4784 if (!dev
->vol
.migr_state
)
4787 if (migr_type(dev
) == MIGR_INIT
||
4788 migr_type(dev
) == MIGR_REPAIR
)
4791 if (migr_type(dev
) == MIGR_GEN_MIGR
)
4794 migr_map
= get_imsm_map(dev
, 1);
4796 if ((migr_map
->map_state
== IMSM_T_STATE_NORMAL
) &&
4797 (dev
->vol
.migr_type
!= MIGR_GEN_MIGR
))
4803 /* return true if we recorded new information */
4804 static int mark_failure(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
4808 struct imsm_map
*map
;
4810 /* new failures are always set in map[0] */
4811 map
= get_imsm_map(dev
, 0);
4813 slot
= get_imsm_disk_slot(map
, idx
);
4817 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
4818 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
4821 disk
->status
|= FAILED_DISK
;
4822 disk
->status
&= ~CONFIGURED_DISK
;
4823 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
4824 if (map
->failed_disk_num
== 0xff)
4825 map
->failed_disk_num
= slot
;
4829 static void mark_missing(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
4831 mark_failure(dev
, disk
, idx
);
4833 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
4836 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
4837 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
4840 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
4846 if (!super
->missing
)
4848 failed
= imsm_count_failed(super
, dev
);
4849 map_state
= imsm_check_degraded(super
, dev
, failed
);
4851 dprintf("imsm: mark missing\n");
4852 end_migration(dev
, map_state
);
4853 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
4854 mark_missing(dev
, &dl
->disk
, dl
->index
);
4855 super
->updates_pending
++;
4858 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
4860 static void imsm_progress_container_reshape(struct intel_super
*super
)
4862 /* if no device has a migr_state, but some device has a
4863 * different number of members than the previous device, start
4864 * changing the number of devices in this device to match
4867 struct imsm_super
*mpb
= super
->anchor
;
4868 int prev_disks
= -1;
4871 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4872 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
4873 struct imsm_map
*map
= get_imsm_map(dev
, 0);
4874 struct imsm_map
*map2
;
4875 int prev_num_members
;
4878 if (dev
->vol
.migr_state
)
4881 if (prev_disks
== -1)
4882 prev_disks
= map
->num_members
;
4883 if (prev_disks
== map
->num_members
)
4886 /* OK, this array needs to enter reshape mode.
4887 * i.e it needs a migr_state
4890 prev_num_members
= map
->num_members
;
4891 map
->num_members
= prev_disks
;
4892 dev
->vol
.migr_state
= 1;
4893 dev
->vol
.curr_migr_unit
= 0;
4894 dev
->vol
.migr_type
= MIGR_GEN_MIGR
;
4895 for (i
= prev_num_members
;
4896 i
< map
->num_members
; i
++)
4897 set_imsm_ord_tbl_ent(map
, i
, i
);
4898 map2
= get_imsm_map(dev
, 1);
4899 /* Copy the current map */
4900 memcpy(map2
, map
, sizeof_imsm_map(map
));
4901 map2
->num_members
= prev_num_members
;
4903 /* calculate new size
4905 used_disks
= imsm_num_data_members(dev
, 0);
4907 unsigned long long array_blocks
;
4910 map
->blocks_per_member
4912 /* round array size down to closest MB
4914 array_blocks
= (array_blocks
4915 >> SECT_PER_MB_SHIFT
)
4916 << SECT_PER_MB_SHIFT
;
4918 __cpu_to_le32((__u32
)array_blocks
);
4921 (__u32
)(array_blocks
>> 32));
4923 super
->updates_pending
++;
4927 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
4928 * states are handled in imsm_set_disk() with one exception, when a
4929 * resync is stopped due to a new failure this routine will set the
4930 * 'degraded' state for the array.
4932 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
4934 int inst
= a
->info
.container_member
;
4935 struct intel_super
*super
= a
->container
->sb
;
4936 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
4937 struct imsm_map
*map
= get_imsm_map(dev
, 0);
4938 int failed
= imsm_count_failed(super
, dev
);
4939 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
);
4940 __u32 blocks_per_unit
;
4942 if (dev
->vol
.migr_state
&&
4943 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
4944 /* array state change is blocked due to reshape action
4946 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
4947 * - finish the reshape (if last_checkpoint is big and action != reshape)
4948 * - update curr_migr_unit
4950 if (a
->curr_action
== reshape
) {
4951 /* still reshaping, maybe update curr_migr_unit */
4952 long long blocks_per_unit
= blocks_per_migr_unit(dev
);
4953 long long unit
= a
->last_checkpoint
;
4954 if (blocks_per_unit
) {
4955 unit
/= blocks_per_unit
;
4957 __le32_to_cpu(dev
->vol
.curr_migr_unit
)) {
4958 dev
->vol
.curr_migr_unit
=
4959 __cpu_to_le32(unit
);
4960 super
->updates_pending
++;
4965 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
4966 /* for some reason we aborted the reshape.
4969 struct imsm_map
*map2
= get_imsm_map(dev
, 1);
4970 dev
->vol
.migr_state
= 0;
4971 dev
->vol
.migr_type
= 0;
4972 dev
->vol
.curr_migr_unit
= 0;
4973 memcpy(map
, map2
, sizeof_imsm_map(map2
));
4974 super
->updates_pending
++;
4976 if (a
->last_checkpoint
>= a
->info
.component_size
) {
4977 unsigned long long array_blocks
;
4979 /* it seems the reshape is all done */
4980 dev
->vol
.migr_state
= 0;
4981 dev
->vol
.migr_type
= 0;
4982 dev
->vol
.curr_migr_unit
= 0;
4984 used_disks
= imsm_num_data_members(dev
, -1);
4985 array_blocks
= map
->blocks_per_member
* used_disks
;
4986 /* round array size down to closest MB */
4987 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
)
4988 << SECT_PER_MB_SHIFT
;
4989 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
4990 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
4991 a
->info
.custom_array_size
= array_blocks
;
4992 a
->check_reshape
= 1; /* encourage manager to update
4995 super
->updates_pending
++;
4996 imsm_progress_container_reshape(super
);
5001 /* before we activate this array handle any missing disks */
5002 if (consistent
== 2)
5003 handle_missing(super
, dev
);
5005 if (consistent
== 2 &&
5006 (!is_resync_complete(&a
->info
) ||
5007 map_state
!= IMSM_T_STATE_NORMAL
||
5008 dev
->vol
.migr_state
))
5011 if (is_resync_complete(&a
->info
)) {
5012 /* complete intialization / resync,
5013 * recovery and interrupted recovery is completed in
5016 if (is_resyncing(dev
)) {
5017 dprintf("imsm: mark resync done\n");
5018 end_migration(dev
, map_state
);
5019 super
->updates_pending
++;
5020 a
->last_checkpoint
= 0;
5022 } else if (!is_resyncing(dev
) && !failed
) {
5023 /* mark the start of the init process if nothing is failed */
5024 dprintf("imsm: mark resync start\n");
5025 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
5026 migrate(dev
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
5028 migrate(dev
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
5029 super
->updates_pending
++;
5032 /* check if we can update curr_migr_unit from resync_start, recovery_start */
5033 blocks_per_unit
= blocks_per_migr_unit(dev
);
5034 if (blocks_per_unit
) {
5038 units
= a
->last_checkpoint
/ blocks_per_unit
;
5041 /* check that we did not overflow 32-bits, and that
5042 * curr_migr_unit needs updating
5044 if (units32
== units
&&
5045 __le32_to_cpu(dev
->vol
.curr_migr_unit
) != units32
) {
5046 dprintf("imsm: mark checkpoint (%u)\n", units32
);
5047 dev
->vol
.curr_migr_unit
= __cpu_to_le32(units32
);
5048 super
->updates_pending
++;
5052 /* mark dirty / clean */
5053 if (dev
->vol
.dirty
!= !consistent
) {
5054 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
5059 super
->updates_pending
++;
5062 /* finalize online capacity expansion/reshape */
5063 if ((a
->curr_action
!= reshape
) &&
5064 (a
->prev_action
== reshape
)) {
5067 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
5068 imsm_set_disk(a
, mdi
->disk
.raid_disk
, mdi
->curr_state
);
5074 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
5076 int inst
= a
->info
.container_member
;
5077 struct intel_super
*super
= a
->container
->sb
;
5078 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
5079 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5080 struct imsm_disk
*disk
;
5085 if (n
> map
->num_members
)
5086 fprintf(stderr
, "imsm: set_disk %d out of range 0..%d\n",
5087 n
, map
->num_members
- 1);
5092 dprintf("imsm: set_disk %d:%x\n", n
, state
);
5094 ord
= get_imsm_ord_tbl_ent(dev
, n
, -1);
5095 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
5097 /* check for new failures */
5098 if (state
& DS_FAULTY
) {
5099 if (mark_failure(dev
, disk
, ord_to_idx(ord
)))
5100 super
->updates_pending
++;
5103 /* check if in_sync */
5104 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
5105 struct imsm_map
*migr_map
= get_imsm_map(dev
, 1);
5107 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
5108 super
->updates_pending
++;
5111 failed
= imsm_count_failed(super
, dev
);
5112 map_state
= imsm_check_degraded(super
, dev
, failed
);
5114 /* check if recovery complete, newly degraded, or failed */
5115 if (map_state
== IMSM_T_STATE_NORMAL
&& is_rebuilding(dev
)) {
5116 end_migration(dev
, map_state
);
5117 map
= get_imsm_map(dev
, 0);
5118 map
->failed_disk_num
= ~0;
5119 super
->updates_pending
++;
5120 a
->last_checkpoint
= 0;
5121 } else if (map_state
== IMSM_T_STATE_DEGRADED
&&
5122 map
->map_state
!= map_state
&&
5123 !dev
->vol
.migr_state
) {
5124 dprintf("imsm: mark degraded\n");
5125 map
->map_state
= map_state
;
5126 super
->updates_pending
++;
5127 a
->last_checkpoint
= 0;
5128 } else if (map_state
== IMSM_T_STATE_FAILED
&&
5129 map
->map_state
!= map_state
) {
5130 dprintf("imsm: mark failed\n");
5131 end_migration(dev
, map_state
);
5132 super
->updates_pending
++;
5133 a
->last_checkpoint
= 0;
5134 } else if (is_gen_migration(dev
)) {
5135 dprintf("imsm: Detected General Migration in state: ");
5136 if (map_state
== IMSM_T_STATE_NORMAL
) {
5137 end_migration(dev
, map_state
);
5138 map
= get_imsm_map(dev
, 0);
5139 map
->failed_disk_num
= ~0;
5140 dprintf("normal\n");
5142 if (map_state
== IMSM_T_STATE_DEGRADED
) {
5143 printf("degraded\n");
5144 end_migration(dev
, map_state
);
5146 dprintf("failed\n");
5148 map
->map_state
= map_state
;
5150 super
->updates_pending
++;
5154 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
5157 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
5158 unsigned long long dsize
;
5159 unsigned long long sectors
;
5161 get_dev_size(fd
, NULL
, &dsize
);
5163 if (mpb_size
> 512) {
5164 /* -1 to account for anchor */
5165 sectors
= mpb_sectors(mpb
) - 1;
5167 /* write the extended mpb to the sectors preceeding the anchor */
5168 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0)
5171 if ((unsigned long long)write(fd
, buf
+ 512, 512 * sectors
)
5176 /* first block is stored on second to last sector of the disk */
5177 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0)
5180 if (write(fd
, buf
, 512) != 512)
5186 static void imsm_sync_metadata(struct supertype
*container
)
5188 struct intel_super
*super
= container
->sb
;
5190 dprintf("sync metadata: %d\n", super
->updates_pending
);
5191 if (!super
->updates_pending
)
5194 write_super_imsm(container
, 0);
5196 super
->updates_pending
= 0;
5199 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
5201 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
5202 int i
= get_imsm_disk_idx(dev
, idx
, -1);
5205 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5209 if (dl
&& is_failed(&dl
->disk
))
5213 dprintf("%s: found %x:%x\n", __func__
, dl
->major
, dl
->minor
);
5218 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
5219 struct active_array
*a
, int activate_new
,
5220 struct mdinfo
*additional_test_list
)
5222 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
5223 int idx
= get_imsm_disk_idx(dev
, slot
, -1);
5224 struct imsm_super
*mpb
= super
->anchor
;
5225 struct imsm_map
*map
;
5226 unsigned long long pos
;
5231 __u32 array_start
= 0;
5232 __u32 array_end
= 0;
5234 struct mdinfo
*test_list
;
5236 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5237 /* If in this array, skip */
5238 for (d
= a
->info
.devs
; d
; d
= d
->next
)
5239 if (d
->state_fd
>= 0 &&
5240 d
->disk
.major
== dl
->major
&&
5241 d
->disk
.minor
== dl
->minor
) {
5242 dprintf("%x:%x already in array\n",
5243 dl
->major
, dl
->minor
);
5248 test_list
= additional_test_list
;
5250 if (test_list
->disk
.major
== dl
->major
&&
5251 test_list
->disk
.minor
== dl
->minor
) {
5252 dprintf("%x:%x already in additional test list\n",
5253 dl
->major
, dl
->minor
);
5256 test_list
= test_list
->next
;
5261 /* skip in use or failed drives */
5262 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
5264 dprintf("%x:%x status (failed: %d index: %d)\n",
5265 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
5269 /* skip pure spares when we are looking for partially
5270 * assimilated drives
5272 if (dl
->index
== -1 && !activate_new
)
5275 /* Does this unused device have the requisite free space?
5276 * It needs to be able to cover all member volumes
5278 ex
= get_extents(super
, dl
);
5280 dprintf("cannot get extents\n");
5283 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5284 dev
= get_imsm_dev(super
, i
);
5285 map
= get_imsm_map(dev
, 0);
5287 /* check if this disk is already a member of
5290 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
5296 array_start
= __le32_to_cpu(map
->pba_of_lba0
);
5297 array_end
= array_start
+
5298 __le32_to_cpu(map
->blocks_per_member
) - 1;
5301 /* check that we can start at pba_of_lba0 with
5302 * blocks_per_member of space
5304 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
5308 pos
= ex
[j
].start
+ ex
[j
].size
;
5310 } while (ex
[j
-1].size
);
5317 if (i
< mpb
->num_raid_devs
) {
5318 dprintf("%x:%x does not have %u to %u available\n",
5319 dl
->major
, dl
->minor
, array_start
, array_end
);
5330 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
5332 struct imsm_dev
*dev2
;
5333 struct imsm_map
*map
;
5339 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
5341 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
);
5342 if (state
== IMSM_T_STATE_FAILED
) {
5343 map
= get_imsm_map(dev2
, 0);
5346 for (slot
= 0; slot
< map
->num_members
; slot
++) {
5348 * Check if failed disks are deleted from intel
5349 * disk list or are marked to be deleted
5351 idx
= get_imsm_disk_idx(dev2
, slot
, -1);
5352 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
5354 * Do not rebuild the array if failed disks
5355 * from failed sub-array are not removed from
5359 is_failed(&idisk
->disk
) &&
5360 (idisk
->action
!= DISK_REMOVE
))
5368 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
5369 struct metadata_update
**updates
)
5372 * Find a device with unused free space and use it to replace a
5373 * failed/vacant region in an array. We replace failed regions one a
5374 * array at a time. The result is that a new spare disk will be added
5375 * to the first failed array and after the monitor has finished
5376 * propagating failures the remainder will be consumed.
5378 * FIXME add a capability for mdmon to request spares from another
5382 struct intel_super
*super
= a
->container
->sb
;
5383 int inst
= a
->info
.container_member
;
5384 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
5385 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5386 int failed
= a
->info
.array
.raid_disks
;
5387 struct mdinfo
*rv
= NULL
;
5390 struct metadata_update
*mu
;
5392 struct imsm_update_activate_spare
*u
;
5397 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
5398 if ((d
->curr_state
& DS_FAULTY
) &&
5400 /* wait for Removal to happen */
5402 if (d
->state_fd
>= 0)
5406 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
5407 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
5409 if (dev
->vol
.migr_state
&&
5410 dev
->vol
.migr_type
== MIGR_GEN_MIGR
)
5411 /* No repair during migration */
5414 if (a
->info
.array
.level
== 4)
5415 /* No repair for takeovered array
5416 * imsm doesn't support raid4
5420 if (imsm_check_degraded(super
, dev
, failed
) != IMSM_T_STATE_DEGRADED
)
5424 * If there are any failed disks check state of the other volume.
5425 * Block rebuild if the another one is failed until failed disks
5426 * are removed from container.
5429 dprintf("found failed disks in %s, check if there another"
5430 "failed sub-array.\n",
5432 /* check if states of the other volumes allow for rebuild */
5433 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
5435 allowed
= imsm_rebuild_allowed(a
->container
,
5443 /* For each slot, if it is not working, find a spare */
5444 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
5445 for (d
= a
->info
.devs
; d
; d
= d
->next
)
5446 if (d
->disk
.raid_disk
== i
)
5448 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
5449 if (d
&& (d
->state_fd
>= 0))
5453 * OK, this device needs recovery. Try to re-add the
5454 * previous occupant of this slot, if this fails see if
5455 * we can continue the assimilation of a spare that was
5456 * partially assimilated, finally try to activate a new
5459 dl
= imsm_readd(super
, i
, a
);
5461 dl
= imsm_add_spare(super
, i
, a
, 0, NULL
);
5463 dl
= imsm_add_spare(super
, i
, a
, 1, NULL
);
5467 /* found a usable disk with enough space */
5468 di
= malloc(sizeof(*di
));
5471 memset(di
, 0, sizeof(*di
));
5473 /* dl->index will be -1 in the case we are activating a
5474 * pristine spare. imsm_process_update() will create a
5475 * new index in this case. Once a disk is found to be
5476 * failed in all member arrays it is kicked from the
5479 di
->disk
.number
= dl
->index
;
5481 /* (ab)use di->devs to store a pointer to the device
5484 di
->devs
= (struct mdinfo
*) dl
;
5486 di
->disk
.raid_disk
= i
;
5487 di
->disk
.major
= dl
->major
;
5488 di
->disk
.minor
= dl
->minor
;
5490 di
->recovery_start
= 0;
5491 di
->data_offset
= __le32_to_cpu(map
->pba_of_lba0
);
5492 di
->component_size
= a
->info
.component_size
;
5493 di
->container_member
= inst
;
5494 super
->random
= random32();
5498 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
5499 i
, di
->data_offset
);
5505 /* No spares found */
5507 /* Now 'rv' has a list of devices to return.
5508 * Create a metadata_update record to update the
5509 * disk_ord_tbl for the array
5511 mu
= malloc(sizeof(*mu
));
5513 mu
->buf
= malloc(sizeof(struct imsm_update_activate_spare
) * num_spares
);
5514 if (mu
->buf
== NULL
) {
5521 struct mdinfo
*n
= rv
->next
;
5530 mu
->space_list
= NULL
;
5531 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
5532 mu
->next
= *updates
;
5533 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
5535 for (di
= rv
; di
; di
= di
->next
) {
5536 u
->type
= update_activate_spare
;
5537 u
->dl
= (struct dl
*) di
->devs
;
5539 u
->slot
= di
->disk
.raid_disk
;
5550 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
5552 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
5553 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5554 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, 0);
5555 struct disk_info
*inf
= get_disk_info(u
);
5556 struct imsm_disk
*disk
;
5560 for (i
= 0; i
< map
->num_members
; i
++) {
5561 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, -1));
5562 for (j
= 0; j
< new_map
->num_members
; j
++)
5563 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
5571 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
5573 struct dl
*dl
= NULL
;
5574 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5575 if ((dl
->major
== major
) && (dl
->minor
== minor
))
5580 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
5582 struct dl
*prev
= NULL
;
5586 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5587 if ((dl
->major
== major
) && (dl
->minor
== minor
)) {
5590 prev
->next
= dl
->next
;
5592 super
->disks
= dl
->next
;
5594 __free_imsm_disk(dl
);
5595 dprintf("%s: removed %x:%x\n",
5596 __func__
, major
, minor
);
5604 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
5606 static int add_remove_disk_update(struct intel_super
*super
)
5608 int check_degraded
= 0;
5609 struct dl
*disk
= NULL
;
5610 /* add/remove some spares to/from the metadata/contrainer */
5611 while (super
->disk_mgmt_list
) {
5612 struct dl
*disk_cfg
;
5614 disk_cfg
= super
->disk_mgmt_list
;
5615 super
->disk_mgmt_list
= disk_cfg
->next
;
5616 disk_cfg
->next
= NULL
;
5618 if (disk_cfg
->action
== DISK_ADD
) {
5619 disk_cfg
->next
= super
->disks
;
5620 super
->disks
= disk_cfg
;
5622 dprintf("%s: added %x:%x\n",
5623 __func__
, disk_cfg
->major
,
5625 } else if (disk_cfg
->action
== DISK_REMOVE
) {
5626 dprintf("Disk remove action processed: %x.%x\n",
5627 disk_cfg
->major
, disk_cfg
->minor
);
5628 disk
= get_disk_super(super
,
5632 /* store action status */
5633 disk
->action
= DISK_REMOVE
;
5634 /* remove spare disks only */
5635 if (disk
->index
== -1) {
5636 remove_disk_super(super
,
5641 /* release allocate disk structure */
5642 __free_imsm_disk(disk_cfg
);
5645 return check_degraded
;
5648 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
5649 struct intel_super
*super
,
5652 struct dl
*new_disk
;
5653 struct intel_dev
*id
;
5655 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
5656 void **tofree
= NULL
;
5657 int devices_to_reshape
= 1;
5658 struct imsm_super
*mpb
= super
->anchor
;
5661 dprintf("imsm: imsm_process_update() for update_reshape\n");
5663 /* enable spares to use in array */
5664 for (i
= 0; i
< delta_disks
; i
++) {
5665 new_disk
= get_disk_super(super
,
5666 major(u
->new_disks
[i
]),
5667 minor(u
->new_disks
[i
]));
5668 dprintf("imsm: imsm_process_update(): new disk "
5669 "for reshape is: %i:%i (%p, index = %i)\n",
5670 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
5671 new_disk
, new_disk
->index
);
5672 if ((new_disk
== NULL
) ||
5673 ((new_disk
->index
>= 0) &&
5674 (new_disk
->index
< u
->old_raid_disks
)))
5675 goto update_reshape_exit
;
5676 new_disk
->index
= mpb
->num_disks
++;
5677 /* slot to fill in autolayout
5679 new_disk
->raiddisk
= new_disk
->index
;
5680 new_disk
->disk
.status
|=
5682 new_disk
->disk
.status
&= ~SPARE_DISK
;
5685 dprintf("imsm: process_update(): update_reshape: volume set"
5686 " mpb->num_raid_devs = %i\n", mpb
->num_raid_devs
);
5687 /* manage changes in volume
5689 for (id
= super
->devlist
; id
; id
= id
->next
) {
5690 void **sp
= *space_list
;
5691 struct imsm_dev
*newdev
;
5692 struct imsm_map
*newmap
, *oldmap
;
5698 /* Copy the dev, but not (all of) the map */
5699 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
5700 oldmap
= get_imsm_map(id
->dev
, 0);
5701 newmap
= get_imsm_map(newdev
, 0);
5702 /* Copy the current map */
5703 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
5704 /* update one device only
5706 if (devices_to_reshape
) {
5709 dprintf("process_update(): modifying "
5710 "subdev: %i\n", id
->index
);
5711 devices_to_reshape
--;
5712 newdev
->vol
.migr_state
= 1;
5713 newdev
->vol
.curr_migr_unit
= 0;
5714 newdev
->vol
.migr_type
= MIGR_GEN_MIGR
;
5715 newmap
->num_members
= u
->new_raid_disks
;
5716 for (i
= 0; i
< delta_disks
; i
++) {
5717 set_imsm_ord_tbl_ent(newmap
,
5718 u
->old_raid_disks
+ i
,
5719 u
->old_raid_disks
+ i
);
5721 /* New map is correct, now need to save old map
5723 newmap
= get_imsm_map(newdev
, 1);
5724 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
5726 /* calculate new size
5728 used_disks
= imsm_num_data_members(newdev
, 0);
5730 unsigned long long array_blocks
;
5733 newmap
->blocks_per_member
* used_disks
;
5734 /* round array size down to closest MB
5736 array_blocks
= (array_blocks
5737 >> SECT_PER_MB_SHIFT
)
5738 << SECT_PER_MB_SHIFT
;
5740 __cpu_to_le32((__u32
)array_blocks
);
5742 __cpu_to_le32((__u32
)(array_blocks
>> 32));
5746 sp
= (void **)id
->dev
;
5753 update_reshape_exit
:
5758 static void imsm_process_update(struct supertype
*st
,
5759 struct metadata_update
*update
)
5762 * crack open the metadata_update envelope to find the update record
5763 * update can be one of:
5764 * update_reshape_container_disks - all the arrays in the container
5765 * are being reshaped to have more devices. We need to mark
5766 * the arrays for general migration and convert selected spares
5767 * into active devices.
5768 * update_activate_spare - a spare device has replaced a failed
5769 * device in an array, update the disk_ord_tbl. If this disk is
5770 * present in all member arrays then also clear the SPARE_DISK
5772 * update_create_array
5774 * update_rename_array
5775 * update_add_remove_disk
5777 struct intel_super
*super
= st
->sb
;
5778 struct imsm_super
*mpb
;
5779 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
5781 /* update requires a larger buf but the allocation failed */
5782 if (super
->next_len
&& !super
->next_buf
) {
5783 super
->next_len
= 0;
5787 if (super
->next_buf
) {
5788 memcpy(super
->next_buf
, super
->buf
, super
->len
);
5790 super
->len
= super
->next_len
;
5791 super
->buf
= super
->next_buf
;
5793 super
->next_len
= 0;
5794 super
->next_buf
= NULL
;
5797 mpb
= super
->anchor
;
5800 case update_reshape_container_disks
: {
5801 struct imsm_update_reshape
*u
= (void *)update
->buf
;
5802 if (apply_reshape_container_disks_update(
5803 u
, super
, &update
->space_list
))
5804 super
->updates_pending
++;
5807 case update_activate_spare
: {
5808 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
5809 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
5810 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5811 struct imsm_map
*migr_map
;
5812 struct active_array
*a
;
5813 struct imsm_disk
*disk
;
5818 int victim
= get_imsm_disk_idx(dev
, u
->slot
, -1);
5821 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5826 fprintf(stderr
, "error: imsm_activate_spare passed "
5827 "an unknown disk (index: %d)\n",
5832 super
->updates_pending
++;
5834 /* count failures (excluding rebuilds and the victim)
5835 * to determine map[0] state
5838 for (i
= 0; i
< map
->num_members
; i
++) {
5841 disk
= get_imsm_disk(super
,
5842 get_imsm_disk_idx(dev
, i
, -1));
5843 if (!disk
|| is_failed(disk
))
5847 /* adding a pristine spare, assign a new index */
5848 if (dl
->index
< 0) {
5849 dl
->index
= super
->anchor
->num_disks
;
5850 super
->anchor
->num_disks
++;
5853 disk
->status
|= CONFIGURED_DISK
;
5854 disk
->status
&= ~SPARE_DISK
;
5857 to_state
= imsm_check_degraded(super
, dev
, failed
);
5858 map
->map_state
= IMSM_T_STATE_DEGRADED
;
5859 migrate(dev
, to_state
, MIGR_REBUILD
);
5860 migr_map
= get_imsm_map(dev
, 1);
5861 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
5862 set_imsm_ord_tbl_ent(migr_map
, u
->slot
, dl
->index
| IMSM_ORD_REBUILD
);
5864 /* update the family_num to mark a new container
5865 * generation, being careful to record the existing
5866 * family_num in orig_family_num to clean up after
5867 * earlier mdadm versions that neglected to set it.
5869 if (mpb
->orig_family_num
== 0)
5870 mpb
->orig_family_num
= mpb
->family_num
;
5871 mpb
->family_num
+= super
->random
;
5873 /* count arrays using the victim in the metadata */
5875 for (a
= st
->arrays
; a
; a
= a
->next
) {
5876 dev
= get_imsm_dev(super
, a
->info
.container_member
);
5877 map
= get_imsm_map(dev
, 0);
5879 if (get_imsm_disk_slot(map
, victim
) >= 0)
5883 /* delete the victim if it is no longer being
5889 /* We know that 'manager' isn't touching anything,
5890 * so it is safe to delete
5892 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
5893 if ((*dlp
)->index
== victim
)
5896 /* victim may be on the missing list */
5898 for (dlp
= &super
->missing
; *dlp
; dlp
= &(*dlp
)->next
)
5899 if ((*dlp
)->index
== victim
)
5901 imsm_delete(super
, dlp
, victim
);
5905 case update_create_array
: {
5906 /* someone wants to create a new array, we need to be aware of
5907 * a few races/collisions:
5908 * 1/ 'Create' called by two separate instances of mdadm
5909 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
5910 * devices that have since been assimilated via
5912 * In the event this update can not be carried out mdadm will
5913 * (FIX ME) notice that its update did not take hold.
5915 struct imsm_update_create_array
*u
= (void *) update
->buf
;
5916 struct intel_dev
*dv
;
5917 struct imsm_dev
*dev
;
5918 struct imsm_map
*map
, *new_map
;
5919 unsigned long long start
, end
;
5920 unsigned long long new_start
, new_end
;
5922 struct disk_info
*inf
;
5925 /* handle racing creates: first come first serve */
5926 if (u
->dev_idx
< mpb
->num_raid_devs
) {
5927 dprintf("%s: subarray %d already defined\n",
5928 __func__
, u
->dev_idx
);
5932 /* check update is next in sequence */
5933 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
5934 dprintf("%s: can not create array %d expected index %d\n",
5935 __func__
, u
->dev_idx
, mpb
->num_raid_devs
);
5939 new_map
= get_imsm_map(&u
->dev
, 0);
5940 new_start
= __le32_to_cpu(new_map
->pba_of_lba0
);
5941 new_end
= new_start
+ __le32_to_cpu(new_map
->blocks_per_member
);
5942 inf
= get_disk_info(u
);
5944 /* handle activate_spare versus create race:
5945 * check to make sure that overlapping arrays do not include
5948 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5949 dev
= get_imsm_dev(super
, i
);
5950 map
= get_imsm_map(dev
, 0);
5951 start
= __le32_to_cpu(map
->pba_of_lba0
);
5952 end
= start
+ __le32_to_cpu(map
->blocks_per_member
);
5953 if ((new_start
>= start
&& new_start
<= end
) ||
5954 (start
>= new_start
&& start
<= new_end
))
5959 if (disks_overlap(super
, i
, u
)) {
5960 dprintf("%s: arrays overlap\n", __func__
);
5965 /* check that prepare update was successful */
5966 if (!update
->space
) {
5967 dprintf("%s: prepare update failed\n", __func__
);
5971 /* check that all disks are still active before committing
5972 * changes. FIXME: could we instead handle this by creating a
5973 * degraded array? That's probably not what the user expects,
5974 * so better to drop this update on the floor.
5976 for (i
= 0; i
< new_map
->num_members
; i
++) {
5977 dl
= serial_to_dl(inf
[i
].serial
, super
);
5979 dprintf("%s: disk disappeared\n", __func__
);
5984 super
->updates_pending
++;
5986 /* convert spares to members and fixup ord_tbl */
5987 for (i
= 0; i
< new_map
->num_members
; i
++) {
5988 dl
= serial_to_dl(inf
[i
].serial
, super
);
5989 if (dl
->index
== -1) {
5990 dl
->index
= mpb
->num_disks
;
5992 dl
->disk
.status
|= CONFIGURED_DISK
;
5993 dl
->disk
.status
&= ~SPARE_DISK
;
5995 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
6000 update
->space
= NULL
;
6001 imsm_copy_dev(dev
, &u
->dev
);
6002 dv
->index
= u
->dev_idx
;
6003 dv
->next
= super
->devlist
;
6004 super
->devlist
= dv
;
6005 mpb
->num_raid_devs
++;
6007 imsm_update_version_info(super
);
6010 /* mdmon knows how to release update->space, but not
6011 * ((struct intel_dev *) update->space)->dev
6013 if (update
->space
) {
6019 case update_kill_array
: {
6020 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
6021 int victim
= u
->dev_idx
;
6022 struct active_array
*a
;
6023 struct intel_dev
**dp
;
6024 struct imsm_dev
*dev
;
6026 /* sanity check that we are not affecting the uuid of
6027 * active arrays, or deleting an active array
6029 * FIXME when immutable ids are available, but note that
6030 * we'll also need to fixup the invalidated/active
6031 * subarray indexes in mdstat
6033 for (a
= st
->arrays
; a
; a
= a
->next
)
6034 if (a
->info
.container_member
>= victim
)
6036 /* by definition if mdmon is running at least one array
6037 * is active in the container, so checking
6038 * mpb->num_raid_devs is just extra paranoia
6040 dev
= get_imsm_dev(super
, victim
);
6041 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
6042 dprintf("failed to delete subarray-%d\n", victim
);
6046 for (dp
= &super
->devlist
; *dp
;)
6047 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
6050 if ((*dp
)->index
> (unsigned)victim
)
6054 mpb
->num_raid_devs
--;
6055 super
->updates_pending
++;
6058 case update_rename_array
: {
6059 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
6060 char name
[MAX_RAID_SERIAL_LEN
+1];
6061 int target
= u
->dev_idx
;
6062 struct active_array
*a
;
6063 struct imsm_dev
*dev
;
6065 /* sanity check that we are not affecting the uuid of
6068 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
6069 name
[MAX_RAID_SERIAL_LEN
] = '\0';
6070 for (a
= st
->arrays
; a
; a
= a
->next
)
6071 if (a
->info
.container_member
== target
)
6073 dev
= get_imsm_dev(super
, u
->dev_idx
);
6074 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
6075 dprintf("failed to rename subarray-%d\n", target
);
6079 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
6080 super
->updates_pending
++;
6083 case update_add_remove_disk
: {
6084 /* we may be able to repair some arrays if disks are
6085 * being added, check teh status of add_remove_disk
6086 * if discs has been added.
6088 if (add_remove_disk_update(super
)) {
6089 struct active_array
*a
;
6091 super
->updates_pending
++;
6092 for (a
= st
->arrays
; a
; a
= a
->next
)
6093 a
->check_degraded
= 1;
6098 fprintf(stderr
, "error: unsuported process update type:"
6099 "(type: %d)\n", type
);
6103 static void imsm_prepare_update(struct supertype
*st
,
6104 struct metadata_update
*update
)
6107 * Allocate space to hold new disk entries, raid-device entries or a new
6108 * mpb if necessary. The manager synchronously waits for updates to
6109 * complete in the monitor, so new mpb buffers allocated here can be
6110 * integrated by the monitor thread without worrying about live pointers
6111 * in the manager thread.
6113 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
6114 struct intel_super
*super
= st
->sb
;
6115 struct imsm_super
*mpb
= super
->anchor
;
6120 case update_reshape_container_disks
: {
6121 /* Every raid device in the container is about to
6122 * gain some more devices, and we will enter a
6124 * So each 'imsm_map' will be bigger, and the imsm_vol
6125 * will now hold 2 of them.
6126 * Thus we need new 'struct imsm_dev' allocations sized
6127 * as sizeof_imsm_dev but with more devices in both maps.
6129 struct imsm_update_reshape
*u
= (void *)update
->buf
;
6130 struct intel_dev
*dl
;
6131 void **space_tail
= (void**)&update
->space_list
;
6133 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
6135 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
6136 int size
= sizeof_imsm_dev(dl
->dev
, 1);
6138 if (u
->new_raid_disks
> u
->old_raid_disks
)
6139 size
+= sizeof(__u32
)*2*
6140 (u
->new_raid_disks
- u
->old_raid_disks
);
6149 len
= disks_to_mpb_size(u
->new_raid_disks
);
6150 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
6153 case update_create_array
: {
6154 struct imsm_update_create_array
*u
= (void *) update
->buf
;
6155 struct intel_dev
*dv
;
6156 struct imsm_dev
*dev
= &u
->dev
;
6157 struct imsm_map
*map
= get_imsm_map(dev
, 0);
6159 struct disk_info
*inf
;
6163 inf
= get_disk_info(u
);
6164 len
= sizeof_imsm_dev(dev
, 1);
6165 /* allocate a new super->devlist entry */
6166 dv
= malloc(sizeof(*dv
));
6168 dv
->dev
= malloc(len
);
6173 update
->space
= NULL
;
6177 /* count how many spares will be converted to members */
6178 for (i
= 0; i
< map
->num_members
; i
++) {
6179 dl
= serial_to_dl(inf
[i
].serial
, super
);
6181 /* hmm maybe it failed?, nothing we can do about
6186 if (count_memberships(dl
, super
) == 0)
6189 len
+= activate
* sizeof(struct imsm_disk
);
6196 /* check if we need a larger metadata buffer */
6197 if (super
->next_buf
)
6198 buf_len
= super
->next_len
;
6200 buf_len
= super
->len
;
6202 if (__le32_to_cpu(mpb
->mpb_size
) + len
> buf_len
) {
6203 /* ok we need a larger buf than what is currently allocated
6204 * if this allocation fails process_update will notice that
6205 * ->next_len is set and ->next_buf is NULL
6207 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + len
, 512);
6208 if (super
->next_buf
)
6209 free(super
->next_buf
);
6211 super
->next_len
= buf_len
;
6212 if (posix_memalign(&super
->next_buf
, 512, buf_len
) == 0)
6213 memset(super
->next_buf
, 0, buf_len
);
6215 super
->next_buf
= NULL
;
6219 /* must be called while manager is quiesced */
6220 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
6222 struct imsm_super
*mpb
= super
->anchor
;
6224 struct imsm_dev
*dev
;
6225 struct imsm_map
*map
;
6226 int i
, j
, num_members
;
6229 dprintf("%s: deleting device[%d] from imsm_super\n",
6232 /* shift all indexes down one */
6233 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
6234 if (iter
->index
> (int)index
)
6236 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
6237 if (iter
->index
> (int)index
)
6240 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6241 dev
= get_imsm_dev(super
, i
);
6242 map
= get_imsm_map(dev
, 0);
6243 num_members
= map
->num_members
;
6244 for (j
= 0; j
< num_members
; j
++) {
6245 /* update ord entries being careful not to propagate
6246 * ord-flags to the first map
6248 ord
= get_imsm_ord_tbl_ent(dev
, j
, -1);
6250 if (ord_to_idx(ord
) <= index
)
6253 map
= get_imsm_map(dev
, 0);
6254 set_imsm_ord_tbl_ent(map
, j
, ord_to_idx(ord
- 1));
6255 map
= get_imsm_map(dev
, 1);
6257 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
6262 super
->updates_pending
++;
6264 struct dl
*dl
= *dlp
;
6266 *dlp
= (*dlp
)->next
;
6267 __free_imsm_disk(dl
);
6270 #endif /* MDASSEMBLE */
6272 static char disk_by_path
[] = "/dev/disk/by-path/";
6274 static const char *imsm_get_disk_controller_domain(const char *path
)
6276 struct sys_dev
*list
, *hba
= NULL
;
6277 char disk_path
[PATH_MAX
];
6281 list
= find_driver_devices("pci", "ahci");
6282 for (hba
= list
; hba
; hba
= hba
->next
)
6283 if (devpath_to_vendor(hba
->path
) == 0x8086)
6289 strncpy(disk_path
, disk_by_path
, PATH_MAX
- 1);
6290 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
6291 if (stat(disk_path
, &st
) == 0) {
6292 dpath
= devt_to_devpath(st
.st_rdev
);
6294 ahci
= path_attached_to_hba(dpath
, hba
->path
);
6297 dprintf("path: %s(%s) hba: %s attached: %d\n",
6298 path
, dpath
, (hba
) ? hba
->path
: "NULL", ahci
);
6299 free_sys_dev(&list
);
6306 static int imsm_find_array_minor_by_subdev(int subdev
, int container
, int *minor
)
6308 char subdev_name
[20];
6309 struct mdstat_ent
*mdstat
;
6311 sprintf(subdev_name
, "%d", subdev
);
6312 mdstat
= mdstat_by_subdev(subdev_name
, container
);
6316 *minor
= mdstat
->devnum
;
6317 free_mdstat(mdstat
);
6321 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
6322 struct geo_params
*geo
,
6323 int *old_raid_disks
)
6326 struct mdinfo
*info
, *member
;
6327 int devices_that_can_grow
= 0;
6329 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): "
6330 "st->devnum = (%i)\n",
6333 if (geo
->size
!= -1 ||
6334 geo
->level
!= UnSet
||
6335 geo
->layout
!= UnSet
||
6336 geo
->chunksize
!= 0 ||
6337 geo
->raid_disks
== UnSet
) {
6338 dprintf("imsm: Container operation is allowed for "
6339 "raid disks number change only.\n");
6343 info
= container_content_imsm(st
, NULL
);
6344 for (member
= info
; member
; member
= member
->next
) {
6348 dprintf("imsm: checking device_num: %i\n",
6349 member
->container_member
);
6351 if (geo
->raid_disks
< member
->array
.raid_disks
) {
6352 /* we work on container for Online Capacity Expansion
6353 * only so raid_disks has to grow
6355 dprintf("imsm: for container operation raid disks "
6356 "increase is required\n");
6360 if ((info
->array
.level
!= 0) &&
6361 (info
->array
.level
!= 5)) {
6362 /* we cannot use this container with other raid level
6364 dprintf("imsm: for container operation wrong"
6365 " raid level (%i) detected\n",
6369 /* check for platform support
6370 * for this raid level configuration
6372 struct intel_super
*super
= st
->sb
;
6373 if (!is_raid_level_supported(super
->orom
,
6374 member
->array
.level
,
6376 dprintf("platform does not support raid%d with"
6380 geo
->raid_disks
> 1 ? "s" : "");
6385 if (*old_raid_disks
&&
6386 info
->array
.raid_disks
!= *old_raid_disks
)
6388 *old_raid_disks
= info
->array
.raid_disks
;
6390 /* All raid5 and raid0 volumes in container
6391 * have to be ready for Online Capacity Expansion
6392 * so they need to be assembled. We have already
6393 * checked that no recovery etc is happening.
6395 result
= imsm_find_array_minor_by_subdev(member
->container_member
,
6399 dprintf("imsm: cannot find array\n");
6402 devices_that_can_grow
++;
6405 if (!member
&& devices_that_can_grow
)
6409 dprintf("\tContainer operation allowed\n");
6411 dprintf("\tError: %i\n", ret_val
);
6416 /* Function: get_spares_for_grow
6417 * Description: Allocates memory and creates list of spare devices
6418 * avaliable in container. Checks if spare drive size is acceptable.
6419 * Parameters: Pointer to the supertype structure
6420 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
6423 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
6425 unsigned long long min_size
= min_acceptable_spare_size_imsm(st
);
6426 return container_choose_spares(st
, min_size
, NULL
, NULL
, NULL
, 0);
6429 /******************************************************************************
6430 * function: imsm_create_metadata_update_for_reshape
6431 * Function creates update for whole IMSM container.
6433 ******************************************************************************/
6434 static int imsm_create_metadata_update_for_reshape(
6435 struct supertype
*st
,
6436 struct geo_params
*geo
,
6438 struct imsm_update_reshape
**updatep
)
6440 struct intel_super
*super
= st
->sb
;
6441 struct imsm_super
*mpb
= super
->anchor
;
6442 int update_memory_size
= 0;
6443 struct imsm_update_reshape
*u
= NULL
;
6444 struct mdinfo
*spares
= NULL
;
6446 int delta_disks
= 0;
6448 dprintf("imsm_update_metadata_for_reshape(enter) raid_disks = %i\n",
6451 delta_disks
= geo
->raid_disks
- old_raid_disks
;
6453 /* size of all update data without anchor */
6454 update_memory_size
= sizeof(struct imsm_update_reshape
);
6456 /* now add space for spare disks that we need to add. */
6457 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
6459 u
= calloc(1, update_memory_size
);
6462 "cannot get memory for imsm_update_reshape update\n");
6465 u
->type
= update_reshape_container_disks
;
6466 u
->old_raid_disks
= old_raid_disks
;
6467 u
->new_raid_disks
= geo
->raid_disks
;
6469 /* now get spare disks list
6471 spares
= get_spares_for_grow(st
);
6474 || delta_disks
> spares
->array
.spare_disks
) {
6475 dprintf("imsm: ERROR: Cannot get spare devices.\n");
6479 /* we have got spares
6480 * update disk list in imsm_disk list table in anchor
6482 dprintf("imsm: %i spares are available.\n\n",
6483 spares
->array
.spare_disks
);
6485 for (i
= 0; i
< delta_disks
; i
++) {
6486 struct mdinfo
*dev
= spares
->devs
;
6489 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
6491 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
6492 dl
->index
= mpb
->num_disks
++;
6494 /* Now update the metadata so that container_content will find
6497 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6499 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
6500 struct imsm_map
*map
= get_imsm_map(dev
, 0);
6501 map
->num_members
= geo
->raid_disks
;
6502 for (d
= 0; d
< delta_disks
; d
++) {
6503 set_imsm_ord_tbl_ent(map
, old_raid_disks
+ d
,
6504 mpb
->num_disks
- delta_disks
+ d
);
6513 dprintf("imsm: reshape update preparation :");
6514 if (i
== delta_disks
) {
6517 return update_memory_size
;
6520 dprintf(" Error\n");
6526 static int imsm_reshape_super(struct supertype
*st
, long long size
, int level
,
6527 int layout
, int chunksize
, int raid_disks
,
6528 char *backup
, char *dev
, int verbose
)
6530 /* currently we only support increasing the number of devices
6531 * for a container. This increases the number of device for each
6532 * member array. They must all be RAID0 or RAID5.
6536 struct geo_params geo
;
6538 dprintf("imsm: reshape_super called.\n");
6540 memset(&geo
, sizeof(struct geo_params
), 0);
6545 geo
.layout
= layout
;
6546 geo
.chunksize
= chunksize
;
6547 geo
.raid_disks
= raid_disks
;
6549 dprintf("\tfor level : %i\n", geo
.level
);
6550 dprintf("\tfor raid_disks : %i\n", geo
.raid_disks
);
6552 if (experimental() == 0)
6555 /* verify reshape conditions
6556 * on container level we can only increase number of devices.
6558 if (st
->container_dev
== st
->devnum
) {
6559 /* check for delta_disks > 0
6560 * and supported raid levels 0 and 5 only in container
6562 int old_raid_disks
= 0;
6563 if (imsm_reshape_is_allowed_on_container(
6564 st
, &geo
, &old_raid_disks
)) {
6565 struct imsm_update_reshape
*u
= NULL
;
6567 struct intel_super
*super
= st
->sb
;
6569 struct intel_dev
*dl
;
6570 void **space_tail
= (void **)&space_list
;
6573 len
= imsm_create_metadata_update_for_reshape(
6574 st
, &geo
, old_raid_disks
, &u
);
6577 dprintf("imsm: Cannot prepare update\n");
6578 goto exit_imsm_reshape_super
;
6581 /* As well as creating update, we apply update.
6584 dprintf("imsm:prepare space list for update_reshape\n");
6585 for (dl
= super
->devlist
; dl
;
6587 int size
= sizeof_imsm_dev(dl
->dev
, 1);
6589 if (u
->new_raid_disks
> u
->old_raid_disks
)
6590 size
+= sizeof(__u32
)*2*
6591 (u
->new_raid_disks
- u
->old_raid_disks
);
6599 ret_val
= apply_reshape_container_disks_update(
6600 u
, super
, &space_list
);
6602 /* reallocate anchor
6604 size_t buf_len
= super
->len
;
6606 disks_to_mpb_size(u
->new_raid_disks
);
6607 struct imsm_super
*mpb
= super
->anchor
;
6610 if (__le32_to_cpu(mpb
->mpb_size
) + len
>
6612 buf_len
= ROUND_UP(__le32_to_cpu(
6613 mpb
->mpb_size
) + len
, 512);
6614 if (posix_memalign(&new_anchor
,
6615 512, buf_len
) == 0) {
6616 memcpy(new_anchor
, super
->buf
,
6619 super
->buf
= new_anchor
;
6620 super
->len
= buf_len
;
6622 super
->updates_pending
++;
6626 while (space_list
) {
6627 void *space
= space_list
;
6628 space_list
= *space_list
;
6634 fprintf(stderr
, Name
"imsm: Operation is not allowed "
6635 "on this container\n");
6637 fprintf(stderr
, Name
"imsm: not a container operation\n");
6639 exit_imsm_reshape_super
:
6640 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
6644 static int imsm_manage_reshape(
6645 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
6646 struct supertype
*st
, unsigned long stripes
,
6647 int *fds
, unsigned long long *offsets
,
6648 int dests
, int *destfd
, unsigned long long *destoffsets
)
6650 /* Just use child_monitor for now */
6651 return child_monitor(
6652 afd
, sra
, reshape
, st
, stripes
,
6653 fds
, offsets
, dests
, destfd
, destoffsets
);
6656 struct superswitch super_imsm
= {
6658 .examine_super
= examine_super_imsm
,
6659 .brief_examine_super
= brief_examine_super_imsm
,
6660 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
6661 .export_examine_super
= export_examine_super_imsm
,
6662 .detail_super
= detail_super_imsm
,
6663 .brief_detail_super
= brief_detail_super_imsm
,
6664 .write_init_super
= write_init_super_imsm
,
6665 .validate_geometry
= validate_geometry_imsm
,
6666 .add_to_super
= add_to_super_imsm
,
6667 .remove_from_super
= remove_from_super_imsm
,
6668 .detail_platform
= detail_platform_imsm
,
6669 .kill_subarray
= kill_subarray_imsm
,
6670 .update_subarray
= update_subarray_imsm
,
6671 .load_container
= load_container_imsm
,
6673 .match_home
= match_home_imsm
,
6674 .uuid_from_super
= uuid_from_super_imsm
,
6675 .getinfo_super
= getinfo_super_imsm
,
6676 .getinfo_super_disks
= getinfo_super_disks_imsm
,
6677 .update_super
= update_super_imsm
,
6679 .avail_size
= avail_size_imsm
,
6680 .min_acceptable_spare_size
= min_acceptable_spare_size_imsm
,
6682 .compare_super
= compare_super_imsm
,
6684 .load_super
= load_super_imsm
,
6685 .init_super
= init_super_imsm
,
6686 .store_super
= store_super_imsm
,
6687 .free_super
= free_super_imsm
,
6688 .match_metadata_desc
= match_metadata_desc_imsm
,
6689 .container_content
= container_content_imsm
,
6690 .default_geometry
= default_geometry_imsm
,
6691 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
6692 .reshape_super
= imsm_reshape_super
,
6693 .manage_reshape
= imsm_manage_reshape
,
6700 .open_new
= imsm_open_new
,
6701 .set_array_state
= imsm_set_array_state
,
6702 .set_disk
= imsm_set_disk
,
6703 .sync_metadata
= imsm_sync_metadata
,
6704 .activate_spare
= imsm_activate_spare
,
6705 .process_update
= imsm_process_update
,
6706 .prepare_update
= imsm_prepare_update
,
6707 #endif /* MDASSEMBLE */