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
45 #define MPB_ATTRIB_RAID0 __cpu_to_le32(0x00000001)
47 #define MPB_ATTRIB_RAID1 __cpu_to_le32(0x00000002)
49 #define MPB_ATTRIB_RAID10 __cpu_to_le32(0x00000004)
51 #define MPB_ATTRIB_RAID1E __cpu_to_le32(0x00000008)
53 #define MPB_ATTRIB_RAID5 __cpu_to_le32(0x00000010)
54 /* supports RAID CNG */
55 #define MPB_ATTRIB_RAIDCNG __cpu_to_le32(0x00000020)
56 /* supports expanded stripe sizes of 256K, 512K and 1MB */
57 #define MPB_ATTRIB_EXP_STRIPE_SIZE __cpu_to_le32(0x00000040)
59 /* The OROM Support RST Caching of Volumes */
60 #define MPB_ATTRIB_NVM __cpu_to_le32(0x02000000)
61 /* The OROM supports creating disks greater than 2TB */
62 #define MPB_ATTRIB_2TB_DISK __cpu_to_le32(0x04000000)
63 /* The OROM supports Bad Block Management */
64 #define MPB_ATTRIB_BBM __cpu_to_le32(0x08000000)
66 /* THe OROM Supports NVM Caching of Volumes */
67 #define MPB_ATTRIB_NEVER_USE2 __cpu_to_le32(0x10000000)
68 /* The OROM supports creating volumes greater than 2TB */
69 #define MPB_ATTRIB_2TB __cpu_to_le32(0x20000000)
70 /* originally for PMP, now it's wasted b/c. Never use this bit! */
71 #define MPB_ATTRIB_NEVER_USE __cpu_to_le32(0x40000000)
72 /* Verify MPB contents against checksum after reading MPB */
73 #define MPB_ATTRIB_CHECKSUM_VERIFY __cpu_to_le32(0x80000000)
75 /* Define all supported attributes that have to be accepted by mdadm
77 #define MPB_ATTRIB_SUPPORTED (MPB_ATTRIB_CHECKSUM_VERIFY | \
79 MPB_ATTRIB_2TB_DISK | \
84 MPB_ATTRIB_EXP_STRIPE_SIZE | \
87 /* Define attributes that are unused but not harmful */
88 #define MPB_ATTRIB_IGNORED (MPB_ATTRIB_NEVER_USE)
90 #define MPB_SECTOR_CNT 2210
91 #define IMSM_RESERVED_SECTORS 4096
92 #define NUM_BLOCKS_DIRTY_STRIPE_REGION 2056
93 #define SECT_PER_MB_SHIFT 11
94 #define MAX_SECTOR_SIZE 4096
96 /* Disk configuration info. */
97 #define IMSM_MAX_DEVICES 255
99 __u8 serial
[MAX_RAID_SERIAL_LEN
];/* 0xD8 - 0xE7 ascii serial number */
100 __u32 total_blocks_lo
; /* 0xE8 - 0xEB total blocks lo */
101 __u32 scsi_id
; /* 0xEC - 0xEF scsi ID */
102 #define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
103 #define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
104 #define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
105 __u32 status
; /* 0xF0 - 0xF3 */
106 __u32 owner_cfg_num
; /* which config 0,1,2... owns this disk */
107 __u32 total_blocks_hi
; /* 0xF4 - 0xF5 total blocks hi */
108 #define IMSM_DISK_FILLERS 3
109 __u32 filler
[IMSM_DISK_FILLERS
]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
112 /* map selector for map managment
118 /* RAID map configuration infos. */
120 __u32 pba_of_lba0_lo
; /* start address of partition */
121 __u32 blocks_per_member_lo
;/* blocks per member */
122 __u32 num_data_stripes_lo
; /* number of data stripes */
123 __u16 blocks_per_strip
;
124 __u8 map_state
; /* Normal, Uninitialized, Degraded, Failed */
125 #define IMSM_T_STATE_NORMAL 0
126 #define IMSM_T_STATE_UNINITIALIZED 1
127 #define IMSM_T_STATE_DEGRADED 2
128 #define IMSM_T_STATE_FAILED 3
130 #define IMSM_T_RAID0 0
131 #define IMSM_T_RAID1 1
132 #define IMSM_T_RAID5 5 /* since metadata version 1.2.02 ? */
133 __u8 num_members
; /* number of member disks */
134 __u8 num_domains
; /* number of parity domains */
135 __u8 failed_disk_num
; /* valid only when state is degraded */
137 __u32 pba_of_lba0_hi
;
138 __u32 blocks_per_member_hi
;
139 __u32 num_data_stripes_hi
;
140 __u32 filler
[4]; /* expansion area */
141 #define IMSM_ORD_REBUILD (1 << 24)
142 __u32 disk_ord_tbl
[1]; /* disk_ord_tbl[num_members],
143 * top byte contains some flags
145 } __attribute__ ((packed
));
148 __u32 curr_migr_unit
;
149 __u32 checkpoint_id
; /* id to access curr_migr_unit */
150 __u8 migr_state
; /* Normal or Migrating */
152 #define MIGR_REBUILD 1
153 #define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
154 #define MIGR_GEN_MIGR 3
155 #define MIGR_STATE_CHANGE 4
156 #define MIGR_REPAIR 5
157 __u8 migr_type
; /* Initializing, Rebuilding, ... */
159 __u8 fs_state
; /* fast-sync state for CnG (0xff == disabled) */
160 __u16 verify_errors
; /* number of mismatches */
161 __u16 bad_blocks
; /* number of bad blocks during verify */
163 struct imsm_map map
[1];
164 /* here comes another one if migr_state */
165 } __attribute__ ((packed
));
168 __u8 volume
[MAX_RAID_SERIAL_LEN
];
171 #define DEV_BOOTABLE __cpu_to_le32(0x01)
172 #define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
173 #define DEV_READ_COALESCING __cpu_to_le32(0x04)
174 #define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
175 #define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
176 #define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
177 #define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
178 #define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
179 #define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
180 #define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
181 #define DEV_CLONE_N_GO __cpu_to_le32(0x400)
182 #define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
183 #define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
184 __u32 status
; /* Persistent RaidDev status */
185 __u32 reserved_blocks
; /* Reserved blocks at beginning of volume */
189 __u8 cng_master_disk
;
193 #define IMSM_DEV_FILLERS 10
194 __u32 filler
[IMSM_DEV_FILLERS
];
196 } __attribute__ ((packed
));
199 __u8 sig
[MAX_SIGNATURE_LENGTH
]; /* 0x00 - 0x1F */
200 __u32 check_sum
; /* 0x20 - 0x23 MPB Checksum */
201 __u32 mpb_size
; /* 0x24 - 0x27 Size of MPB */
202 __u32 family_num
; /* 0x28 - 0x2B Checksum from first time this config was written */
203 __u32 generation_num
; /* 0x2C - 0x2F Incremented each time this array's MPB is written */
204 __u32 error_log_size
; /* 0x30 - 0x33 in bytes */
205 __u32 attributes
; /* 0x34 - 0x37 */
206 __u8 num_disks
; /* 0x38 Number of configured disks */
207 __u8 num_raid_devs
; /* 0x39 Number of configured volumes */
208 __u8 error_log_pos
; /* 0x3A */
209 __u8 fill
[1]; /* 0x3B */
210 __u32 cache_size
; /* 0x3c - 0x40 in mb */
211 __u32 orig_family_num
; /* 0x40 - 0x43 original family num */
212 __u32 pwr_cycle_count
; /* 0x44 - 0x47 simulated power cycle count for array */
213 __u32 bbm_log_size
; /* 0x48 - 0x4B - size of bad Block Mgmt Log in bytes */
214 #define IMSM_FILLERS 35
215 __u32 filler
[IMSM_FILLERS
]; /* 0x4C - 0xD7 RAID_MPB_FILLERS */
216 struct imsm_disk disk
[1]; /* 0xD8 diskTbl[numDisks] */
217 /* here comes imsm_dev[num_raid_devs] */
218 /* here comes BBM logs */
219 } __attribute__ ((packed
));
221 #define BBM_LOG_MAX_ENTRIES 254
222 #define BBM_LOG_MAX_LBA_ENTRY_VAL 256 /* Represents 256 LBAs */
223 #define BBM_LOG_SIGNATURE 0xabadb10c
225 struct bbm_log_block_addr
{
228 } __attribute__ ((__packed__
));
230 struct bbm_log_entry
{
231 __u8 marked_count
; /* Number of blocks marked - 1 */
232 __u8 disk_ordinal
; /* Disk entry within the imsm_super */
233 struct bbm_log_block_addr defective_block_start
;
234 } __attribute__ ((__packed__
));
237 __u32 signature
; /* 0xABADB10C */
239 struct bbm_log_entry marked_block_entries
[BBM_LOG_MAX_ENTRIES
];
240 } __attribute__ ((__packed__
));
243 static char *map_state_str
[] = { "normal", "uninitialized", "degraded", "failed" };
246 #define RAID_DISK_RESERVED_BLOCKS_IMSM_HI 2209
248 #define GEN_MIGR_AREA_SIZE 2048 /* General Migration Copy Area size in blocks */
250 #define MIGR_REC_BUF_SECTORS 1 /* size of migr_record i/o buffer in sectors */
251 #define MIGR_REC_SECTOR_POSITION 1 /* migr_record position offset on disk,
252 * MIGR_REC_BUF_SECTORS <= MIGR_REC_SECTOR_POS
255 #define UNIT_SRC_NORMAL 0 /* Source data for curr_migr_unit must
256 * be recovered using srcMap */
257 #define UNIT_SRC_IN_CP_AREA 1 /* Source data for curr_migr_unit has
258 * already been migrated and must
259 * be recovered from checkpoint area */
261 __u32 rec_status
; /* Status used to determine how to restart
262 * migration in case it aborts
264 __u32 curr_migr_unit
; /* 0..numMigrUnits-1 */
265 __u32 family_num
; /* Family number of MPB
266 * containing the RaidDev
267 * that is migrating */
268 __u32 ascending_migr
; /* True if migrating in increasing
270 __u32 blocks_per_unit
; /* Num disk blocks per unit of operation */
271 __u32 dest_depth_per_unit
; /* Num member blocks each destMap
273 * advances per unit-of-operation */
274 __u32 ckpt_area_pba
; /* Pba of first block of ckpt copy area */
275 __u32 dest_1st_member_lba
; /* First member lba on first
276 * stripe of destination */
277 __u32 num_migr_units
; /* Total num migration units-of-op */
278 __u32 post_migr_vol_cap
; /* Size of volume after
279 * migration completes */
280 __u32 post_migr_vol_cap_hi
; /* Expansion space for LBA64 */
281 __u32 ckpt_read_disk_num
; /* Which member disk in destSubMap[0] the
282 * migration ckpt record was read from
283 * (for recovered migrations) */
284 } __attribute__ ((__packed__
));
289 * 2: metadata does not match
297 struct md_list
*next
;
300 #define pr_vrb(fmt, arg...) (void) (verbose && pr_err(fmt, ##arg))
302 static __u8
migr_type(struct imsm_dev
*dev
)
304 if (dev
->vol
.migr_type
== MIGR_VERIFY
&&
305 dev
->status
& DEV_VERIFY_AND_FIX
)
308 return dev
->vol
.migr_type
;
311 static void set_migr_type(struct imsm_dev
*dev
, __u8 migr_type
)
313 /* for compatibility with older oroms convert MIGR_REPAIR, into
314 * MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status
316 if (migr_type
== MIGR_REPAIR
) {
317 dev
->vol
.migr_type
= MIGR_VERIFY
;
318 dev
->status
|= DEV_VERIFY_AND_FIX
;
320 dev
->vol
.migr_type
= migr_type
;
321 dev
->status
&= ~DEV_VERIFY_AND_FIX
;
325 static unsigned int sector_count(__u32 bytes
, unsigned int sector_size
)
327 return ROUND_UP(bytes
, sector_size
) / sector_size
;
330 static unsigned int mpb_sectors(struct imsm_super
*mpb
,
331 unsigned int sector_size
)
333 return sector_count(__le32_to_cpu(mpb
->mpb_size
), sector_size
);
337 struct imsm_dev
*dev
;
338 struct intel_dev
*next
;
343 enum sys_dev_type type
;
346 struct intel_hba
*next
;
353 /* internal representation of IMSM metadata */
356 void *buf
; /* O_DIRECT buffer for reading/writing metadata */
357 struct imsm_super
*anchor
; /* immovable parameters */
360 void *migr_rec_buf
; /* buffer for I/O operations */
361 struct migr_record
*migr_rec
; /* migration record */
363 int clean_migration_record_by_mdmon
; /* when reshape is switched to next
364 array, it indicates that mdmon is allowed to clean migration
366 size_t len
; /* size of the 'buf' allocation */
367 size_t extra_space
; /* extra space in 'buf' that is not used yet */
368 void *next_buf
; /* for realloc'ing buf from the manager */
370 int updates_pending
; /* count of pending updates for mdmon */
371 int current_vol
; /* index of raid device undergoing creation */
372 unsigned long long create_offset
; /* common start for 'current_vol' */
373 __u32 random
; /* random data for seeding new family numbers */
374 struct intel_dev
*devlist
;
375 unsigned int sector_size
; /* sector size of used member drives */
379 __u8 serial
[MAX_RAID_SERIAL_LEN
];
382 struct imsm_disk disk
;
385 struct extent
*e
; /* for determining freespace @ create */
386 int raiddisk
; /* slot to fill in autolayout */
388 } *disks
, *current_disk
;
389 struct dl
*disk_mgmt_list
; /* list of disks to add/remove while mdmon
391 struct dl
*missing
; /* disks removed while we weren't looking */
392 struct bbm_log
*bbm_log
;
393 struct intel_hba
*hba
; /* device path of the raid controller for this metadata */
394 const struct imsm_orom
*orom
; /* platform firmware support */
395 struct intel_super
*next
; /* (temp) list for disambiguating family_num */
399 struct imsm_disk disk
;
400 #define IMSM_UNKNOWN_OWNER (-1)
402 struct intel_disk
*next
;
406 unsigned long long start
, size
;
409 /* definitions of reshape process types */
410 enum imsm_reshape_type
{
416 /* definition of messages passed to imsm_process_update */
417 enum imsm_update_type
{
418 update_activate_spare
,
422 update_add_remove_disk
,
423 update_reshape_container_disks
,
424 update_reshape_migration
,
426 update_general_migration_checkpoint
,
428 update_prealloc_badblocks_mem
,
431 struct imsm_update_activate_spare
{
432 enum imsm_update_type type
;
436 struct imsm_update_activate_spare
*next
;
442 unsigned long long size
;
449 enum takeover_direction
{
453 struct imsm_update_takeover
{
454 enum imsm_update_type type
;
456 enum takeover_direction direction
;
459 struct imsm_update_reshape
{
460 enum imsm_update_type type
;
464 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
467 struct imsm_update_reshape_migration
{
468 enum imsm_update_type type
;
471 /* fields for array migration changes
478 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
481 struct imsm_update_size_change
{
482 enum imsm_update_type type
;
487 struct imsm_update_general_migration_checkpoint
{
488 enum imsm_update_type type
;
489 __u32 curr_migr_unit
;
493 __u8 serial
[MAX_RAID_SERIAL_LEN
];
496 struct imsm_update_create_array
{
497 enum imsm_update_type type
;
502 struct imsm_update_kill_array
{
503 enum imsm_update_type type
;
507 struct imsm_update_rename_array
{
508 enum imsm_update_type type
;
509 __u8 name
[MAX_RAID_SERIAL_LEN
];
513 struct imsm_update_add_remove_disk
{
514 enum imsm_update_type type
;
517 struct imsm_update_prealloc_bb_mem
{
518 enum imsm_update_type type
;
521 static const char *_sys_dev_type
[] = {
522 [SYS_DEV_UNKNOWN
] = "Unknown",
523 [SYS_DEV_SAS
] = "SAS",
524 [SYS_DEV_SATA
] = "SATA",
525 [SYS_DEV_NVME
] = "NVMe",
526 [SYS_DEV_VMD
] = "VMD"
529 const char *get_sys_dev_type(enum sys_dev_type type
)
531 if (type
>= SYS_DEV_MAX
)
532 type
= SYS_DEV_UNKNOWN
;
534 return _sys_dev_type
[type
];
537 static struct intel_hba
* alloc_intel_hba(struct sys_dev
*device
)
539 struct intel_hba
*result
= xmalloc(sizeof(*result
));
541 result
->type
= device
->type
;
542 result
->path
= xstrdup(device
->path
);
544 if (result
->path
&& (result
->pci_id
= strrchr(result
->path
, '/')) != NULL
)
550 static struct intel_hba
* find_intel_hba(struct intel_hba
*hba
, struct sys_dev
*device
)
552 struct intel_hba
*result
;
554 for (result
= hba
; result
; result
= result
->next
) {
555 if (result
->type
== device
->type
&& strcmp(result
->path
, device
->path
) == 0)
561 static int attach_hba_to_super(struct intel_super
*super
, struct sys_dev
*device
)
563 struct intel_hba
*hba
;
565 /* check if disk attached to Intel HBA */
566 hba
= find_intel_hba(super
->hba
, device
);
569 /* Check if HBA is already attached to super */
570 if (super
->hba
== NULL
) {
571 super
->hba
= alloc_intel_hba(device
);
576 /* Intel metadata allows for all disks attached to the same type HBA.
577 * Do not support HBA types mixing
579 if (device
->type
!= hba
->type
)
582 /* Multiple same type HBAs can be used if they share the same OROM */
583 const struct imsm_orom
*device_orom
= get_orom_by_device_id(device
->dev_id
);
585 if (device_orom
!= super
->orom
)
591 hba
->next
= alloc_intel_hba(device
);
595 static struct sys_dev
* find_disk_attached_hba(int fd
, const char *devname
)
597 struct sys_dev
*list
, *elem
;
600 if ((list
= find_intel_devices()) == NULL
)
604 disk_path
= (char *) devname
;
606 disk_path
= diskfd_to_devpath(fd
);
611 for (elem
= list
; elem
; elem
= elem
->next
)
612 if (path_attached_to_hba(disk_path
, elem
->path
))
615 if (disk_path
!= devname
)
621 static int find_intel_hba_capability(int fd
, struct intel_super
*super
,
624 static struct supertype
*match_metadata_desc_imsm(char *arg
)
626 struct supertype
*st
;
628 if (strcmp(arg
, "imsm") != 0 &&
629 strcmp(arg
, "default") != 0
633 st
= xcalloc(1, sizeof(*st
));
634 st
->ss
= &super_imsm
;
635 st
->max_devs
= IMSM_MAX_DEVICES
;
636 st
->minor_version
= 0;
642 static __u8
*get_imsm_version(struct imsm_super
*mpb
)
644 return &mpb
->sig
[MPB_SIG_LEN
];
648 /* retrieve a disk directly from the anchor when the anchor is known to be
649 * up-to-date, currently only at load time
651 static struct imsm_disk
*__get_imsm_disk(struct imsm_super
*mpb
, __u8 index
)
653 if (index
>= mpb
->num_disks
)
655 return &mpb
->disk
[index
];
658 /* retrieve the disk description based on a index of the disk
661 static struct dl
*get_imsm_dl_disk(struct intel_super
*super
, __u8 index
)
665 for (d
= super
->disks
; d
; d
= d
->next
)
666 if (d
->index
== index
)
671 /* retrieve a disk from the parsed metadata */
672 static struct imsm_disk
*get_imsm_disk(struct intel_super
*super
, __u8 index
)
676 dl
= get_imsm_dl_disk(super
, index
);
683 /* generate a checksum directly from the anchor when the anchor is known to be
684 * up-to-date, currently only at load or write_super after coalescing
686 static __u32
__gen_imsm_checksum(struct imsm_super
*mpb
)
688 __u32 end
= mpb
->mpb_size
/ sizeof(end
);
689 __u32
*p
= (__u32
*) mpb
;
693 sum
+= __le32_to_cpu(*p
);
697 return sum
- __le32_to_cpu(mpb
->check_sum
);
700 static size_t sizeof_imsm_map(struct imsm_map
*map
)
702 return sizeof(struct imsm_map
) + sizeof(__u32
) * (map
->num_members
- 1);
705 struct imsm_map
*get_imsm_map(struct imsm_dev
*dev
, int second_map
)
707 /* A device can have 2 maps if it is in the middle of a migration.
709 * MAP_0 - we return the first map
710 * MAP_1 - we return the second map if it exists, else NULL
711 * MAP_X - we return the second map if it exists, else the first
713 struct imsm_map
*map
= &dev
->vol
.map
[0];
714 struct imsm_map
*map2
= NULL
;
716 if (dev
->vol
.migr_state
)
717 map2
= (void *)map
+ sizeof_imsm_map(map
);
719 switch (second_map
) {
736 /* return the size of the device.
737 * migr_state increases the returned size if map[0] were to be duplicated
739 static size_t sizeof_imsm_dev(struct imsm_dev
*dev
, int migr_state
)
741 size_t size
= sizeof(*dev
) - sizeof(struct imsm_map
) +
742 sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
744 /* migrating means an additional map */
745 if (dev
->vol
.migr_state
)
746 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_1
));
748 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
754 /* retrieve disk serial number list from a metadata update */
755 static struct disk_info
*get_disk_info(struct imsm_update_create_array
*update
)
758 struct disk_info
*inf
;
760 inf
= u
+ sizeof(*update
) - sizeof(struct imsm_dev
) +
761 sizeof_imsm_dev(&update
->dev
, 0);
767 static struct imsm_dev
*__get_imsm_dev(struct imsm_super
*mpb
, __u8 index
)
773 if (index
>= mpb
->num_raid_devs
)
776 /* devices start after all disks */
777 offset
= ((void *) &mpb
->disk
[mpb
->num_disks
]) - _mpb
;
779 for (i
= 0; i
<= index
; i
++)
781 return _mpb
+ offset
;
783 offset
+= sizeof_imsm_dev(_mpb
+ offset
, 0);
788 static struct imsm_dev
*get_imsm_dev(struct intel_super
*super
, __u8 index
)
790 struct intel_dev
*dv
;
792 if (index
>= super
->anchor
->num_raid_devs
)
794 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
795 if (dv
->index
== index
)
800 static inline unsigned long long __le48_to_cpu(const struct bbm_log_block_addr
803 return ((((__u64
)__le32_to_cpu(addr
->dw1
)) << 16) |
804 __le16_to_cpu(addr
->w1
));
807 static inline struct bbm_log_block_addr
__cpu_to_le48(unsigned long long sec
)
809 struct bbm_log_block_addr addr
;
811 addr
.w1
= __cpu_to_le16((__u16
)(sec
& 0xffff));
812 addr
.dw1
= __cpu_to_le32((__u32
)(sec
>> 16) & 0xffffffff);
817 /* get size of the bbm log */
818 static __u32
get_imsm_bbm_log_size(struct bbm_log
*log
)
820 if (!log
|| log
->entry_count
== 0)
823 return sizeof(log
->signature
) +
824 sizeof(log
->entry_count
) +
825 log
->entry_count
* sizeof(struct bbm_log_entry
);
828 /* check if bad block is not partially stored in bbm log */
829 static int is_stored_in_bbm(struct bbm_log
*log
, const __u8 idx
, const unsigned
830 long long sector
, const int length
, __u32
*pos
)
834 for (i
= *pos
; i
< log
->entry_count
; i
++) {
835 struct bbm_log_entry
*entry
= &log
->marked_block_entries
[i
];
836 unsigned long long bb_start
;
837 unsigned long long bb_end
;
839 bb_start
= __le48_to_cpu(&entry
->defective_block_start
);
840 bb_end
= bb_start
+ (entry
->marked_count
+ 1);
842 if ((entry
->disk_ordinal
== idx
) && (bb_start
>= sector
) &&
843 (bb_end
<= sector
+ length
)) {
851 /* record new bad block in bbm log */
852 static int record_new_badblock(struct bbm_log
*log
, const __u8 idx
, unsigned
853 long long sector
, int length
)
857 struct bbm_log_entry
*entry
= NULL
;
859 while (is_stored_in_bbm(log
, idx
, sector
, length
, &pos
)) {
860 struct bbm_log_entry
*e
= &log
->marked_block_entries
[pos
];
862 if ((e
->marked_count
+ 1 == BBM_LOG_MAX_LBA_ENTRY_VAL
) &&
863 (__le48_to_cpu(&e
->defective_block_start
) == sector
)) {
864 sector
+= BBM_LOG_MAX_LBA_ENTRY_VAL
;
865 length
-= BBM_LOG_MAX_LBA_ENTRY_VAL
;
874 int cnt
= (length
<= BBM_LOG_MAX_LBA_ENTRY_VAL
) ? length
:
875 BBM_LOG_MAX_LBA_ENTRY_VAL
;
876 entry
->defective_block_start
= __cpu_to_le48(sector
);
877 entry
->marked_count
= cnt
- 1;
884 new_bb
= ROUND_UP(length
, BBM_LOG_MAX_LBA_ENTRY_VAL
) /
885 BBM_LOG_MAX_LBA_ENTRY_VAL
;
886 if (log
->entry_count
+ new_bb
> BBM_LOG_MAX_ENTRIES
)
890 int cnt
= (length
<= BBM_LOG_MAX_LBA_ENTRY_VAL
) ? length
:
891 BBM_LOG_MAX_LBA_ENTRY_VAL
;
892 struct bbm_log_entry
*entry
=
893 &log
->marked_block_entries
[log
->entry_count
];
895 entry
->defective_block_start
= __cpu_to_le48(sector
);
896 entry
->marked_count
= cnt
- 1;
897 entry
->disk_ordinal
= idx
;
907 #endif /* MDASSEMBLE */
909 /* allocate and load BBM log from metadata */
910 static int load_bbm_log(struct intel_super
*super
)
912 struct imsm_super
*mpb
= super
->anchor
;
913 __u32 bbm_log_size
= __le32_to_cpu(mpb
->bbm_log_size
);
915 super
->bbm_log
= xcalloc(1, sizeof(struct bbm_log
));
920 struct bbm_log
*log
= (void *)mpb
+
921 __le32_to_cpu(mpb
->mpb_size
) - bbm_log_size
;
925 if (bbm_log_size
< sizeof(log
->signature
) +
926 sizeof(log
->entry_count
))
929 entry_count
= __le32_to_cpu(log
->entry_count
);
930 if ((__le32_to_cpu(log
->signature
) != BBM_LOG_SIGNATURE
) ||
931 (entry_count
> BBM_LOG_MAX_ENTRIES
))
935 sizeof(log
->signature
) + sizeof(log
->entry_count
) +
936 entry_count
* sizeof(struct bbm_log_entry
))
939 memcpy(super
->bbm_log
, log
, bbm_log_size
);
941 super
->bbm_log
->signature
= __cpu_to_le32(BBM_LOG_SIGNATURE
);
942 super
->bbm_log
->entry_count
= 0;
948 /* checks if bad block is within volume boundaries */
949 static int is_bad_block_in_volume(const struct bbm_log_entry
*entry
,
950 const unsigned long long start_sector
,
951 const unsigned long long size
)
953 unsigned long long bb_start
;
954 unsigned long long bb_end
;
956 bb_start
= __le48_to_cpu(&entry
->defective_block_start
);
957 bb_end
= bb_start
+ (entry
->marked_count
+ 1);
959 if (((bb_start
>= start_sector
) && (bb_start
< start_sector
+ size
)) ||
960 ((bb_end
>= start_sector
) && (bb_end
<= start_sector
+ size
)))
966 /* get list of bad blocks on a drive for a volume */
967 static void get_volume_badblocks(const struct bbm_log
*log
, const __u8 idx
,
968 const unsigned long long start_sector
,
969 const unsigned long long size
,
975 for (i
= 0; i
< log
->entry_count
; i
++) {
976 const struct bbm_log_entry
*ent
=
977 &log
->marked_block_entries
[i
];
978 struct md_bb_entry
*bb
;
980 if ((ent
->disk_ordinal
== idx
) &&
981 is_bad_block_in_volume(ent
, start_sector
, size
)) {
984 bbs
->entries
= xmalloc(BBM_LOG_MAX_ENTRIES
*
990 bb
= &bbs
->entries
[count
++];
991 bb
->sector
= __le48_to_cpu(&ent
->defective_block_start
);
992 bb
->length
= ent
->marked_count
+ 1;
1000 * == MAP_0 get first map
1001 * == MAP_1 get second map
1002 * == MAP_X than get map according to the current migr_state
1004 static __u32
get_imsm_ord_tbl_ent(struct imsm_dev
*dev
,
1008 struct imsm_map
*map
;
1010 map
= get_imsm_map(dev
, second_map
);
1012 /* top byte identifies disk under rebuild */
1013 return __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
1016 #define ord_to_idx(ord) (((ord) << 8) >> 8)
1017 static __u32
get_imsm_disk_idx(struct imsm_dev
*dev
, int slot
, int second_map
)
1019 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, second_map
);
1021 return ord_to_idx(ord
);
1024 static void set_imsm_ord_tbl_ent(struct imsm_map
*map
, int slot
, __u32 ord
)
1026 map
->disk_ord_tbl
[slot
] = __cpu_to_le32(ord
);
1029 static int get_imsm_disk_slot(struct imsm_map
*map
, unsigned idx
)
1034 for (slot
= 0; slot
< map
->num_members
; slot
++) {
1035 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
1036 if (ord_to_idx(ord
) == idx
)
1043 static int get_imsm_raid_level(struct imsm_map
*map
)
1045 if (map
->raid_level
== 1) {
1046 if (map
->num_members
== 2)
1052 return map
->raid_level
;
1055 static int cmp_extent(const void *av
, const void *bv
)
1057 const struct extent
*a
= av
;
1058 const struct extent
*b
= bv
;
1059 if (a
->start
< b
->start
)
1061 if (a
->start
> b
->start
)
1066 static int count_memberships(struct dl
*dl
, struct intel_super
*super
)
1068 int memberships
= 0;
1071 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1072 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1073 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1075 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
1082 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
);
1084 static int split_ull(unsigned long long n
, __u32
*lo
, __u32
*hi
)
1086 if (lo
== 0 || hi
== 0)
1088 *lo
= __le32_to_cpu((unsigned)n
);
1089 *hi
= __le32_to_cpu((unsigned)(n
>> 32));
1093 static unsigned long long join_u32(__u32 lo
, __u32 hi
)
1095 return (unsigned long long)__le32_to_cpu(lo
) |
1096 (((unsigned long long)__le32_to_cpu(hi
)) << 32);
1099 static unsigned long long total_blocks(struct imsm_disk
*disk
)
1103 return join_u32(disk
->total_blocks_lo
, disk
->total_blocks_hi
);
1106 static unsigned long long pba_of_lba0(struct imsm_map
*map
)
1110 return join_u32(map
->pba_of_lba0_lo
, map
->pba_of_lba0_hi
);
1113 static unsigned long long blocks_per_member(struct imsm_map
*map
)
1117 return join_u32(map
->blocks_per_member_lo
, map
->blocks_per_member_hi
);
1120 static unsigned long long num_data_stripes(struct imsm_map
*map
)
1124 return join_u32(map
->num_data_stripes_lo
, map
->num_data_stripes_hi
);
1127 static void set_total_blocks(struct imsm_disk
*disk
, unsigned long long n
)
1129 split_ull(n
, &disk
->total_blocks_lo
, &disk
->total_blocks_hi
);
1132 static void set_pba_of_lba0(struct imsm_map
*map
, unsigned long long n
)
1134 split_ull(n
, &map
->pba_of_lba0_lo
, &map
->pba_of_lba0_hi
);
1137 static void set_blocks_per_member(struct imsm_map
*map
, unsigned long long n
)
1139 split_ull(n
, &map
->blocks_per_member_lo
, &map
->blocks_per_member_hi
);
1142 static void set_num_data_stripes(struct imsm_map
*map
, unsigned long long n
)
1144 split_ull(n
, &map
->num_data_stripes_lo
, &map
->num_data_stripes_hi
);
1147 static struct extent
*get_extents(struct intel_super
*super
, struct dl
*dl
)
1149 /* find a list of used extents on the given physical device */
1150 struct extent
*rv
, *e
;
1152 int memberships
= count_memberships(dl
, super
);
1155 /* trim the reserved area for spares, so they can join any array
1156 * regardless of whether the OROM has assigned sectors from the
1157 * IMSM_RESERVED_SECTORS region
1159 if (dl
->index
== -1)
1160 reservation
= imsm_min_reserved_sectors(super
);
1162 reservation
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1164 rv
= xcalloc(sizeof(struct extent
), (memberships
+ 1));
1167 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1168 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1169 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1171 if (get_imsm_disk_slot(map
, dl
->index
) >= 0) {
1172 e
->start
= pba_of_lba0(map
);
1173 e
->size
= blocks_per_member(map
);
1177 qsort(rv
, memberships
, sizeof(*rv
), cmp_extent
);
1179 /* determine the start of the metadata
1180 * when no raid devices are defined use the default
1181 * ...otherwise allow the metadata to truncate the value
1182 * as is the case with older versions of imsm
1185 struct extent
*last
= &rv
[memberships
- 1];
1186 unsigned long long remainder
;
1188 remainder
= total_blocks(&dl
->disk
) - (last
->start
+ last
->size
);
1189 /* round down to 1k block to satisfy precision of the kernel
1193 /* make sure remainder is still sane */
1194 if (remainder
< (unsigned)ROUND_UP(super
->len
, 512) >> 9)
1195 remainder
= ROUND_UP(super
->len
, 512) >> 9;
1196 if (reservation
> remainder
)
1197 reservation
= remainder
;
1199 e
->start
= total_blocks(&dl
->disk
) - reservation
;
1204 /* try to determine how much space is reserved for metadata from
1205 * the last get_extents() entry, otherwise fallback to the
1208 static __u32
imsm_reserved_sectors(struct intel_super
*super
, struct dl
*dl
)
1214 /* for spares just return a minimal reservation which will grow
1215 * once the spare is picked up by an array
1217 if (dl
->index
== -1)
1218 return MPB_SECTOR_CNT
;
1220 e
= get_extents(super
, dl
);
1222 return MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1224 /* scroll to last entry */
1225 for (i
= 0; e
[i
].size
; i
++)
1228 rv
= total_blocks(&dl
->disk
) - e
[i
].start
;
1235 static int is_spare(struct imsm_disk
*disk
)
1237 return (disk
->status
& SPARE_DISK
) == SPARE_DISK
;
1240 static int is_configured(struct imsm_disk
*disk
)
1242 return (disk
->status
& CONFIGURED_DISK
) == CONFIGURED_DISK
;
1245 static int is_failed(struct imsm_disk
*disk
)
1247 return (disk
->status
& FAILED_DISK
) == FAILED_DISK
;
1250 /* try to determine how much space is reserved for metadata from
1251 * the last get_extents() entry on the smallest active disk,
1252 * otherwise fallback to the default
1254 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
)
1258 unsigned long long min_active
;
1260 __u32 rv
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1261 struct dl
*dl
, *dl_min
= NULL
;
1267 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
1270 unsigned long long blocks
= total_blocks(&dl
->disk
);
1271 if (blocks
< min_active
|| min_active
== 0) {
1273 min_active
= blocks
;
1279 /* find last lba used by subarrays on the smallest active disk */
1280 e
= get_extents(super
, dl_min
);
1283 for (i
= 0; e
[i
].size
; i
++)
1286 remainder
= min_active
- e
[i
].start
;
1289 /* to give priority to recovery we should not require full
1290 IMSM_RESERVED_SECTORS from the spare */
1291 rv
= MPB_SECTOR_CNT
+ NUM_BLOCKS_DIRTY_STRIPE_REGION
;
1293 /* if real reservation is smaller use that value */
1294 return (remainder
< rv
) ? remainder
: rv
;
1297 /* Return minimum size of a spare that can be used in this array*/
1298 static unsigned long long min_acceptable_spare_size_imsm(struct supertype
*st
)
1300 struct intel_super
*super
= st
->sb
;
1304 unsigned long long rv
= 0;
1308 /* find first active disk in array */
1310 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
1314 /* find last lba used by subarrays */
1315 e
= get_extents(super
, dl
);
1318 for (i
= 0; e
[i
].size
; i
++)
1321 rv
= e
[i
-1].start
+ e
[i
-1].size
;
1324 /* add the amount of space needed for metadata */
1325 rv
= rv
+ imsm_min_reserved_sectors(super
);
1330 static int is_gen_migration(struct imsm_dev
*dev
);
1332 #define IMSM_4K_DIV 8
1335 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
1336 struct imsm_dev
*dev
);
1338 static void print_imsm_dev(struct intel_super
*super
,
1339 struct imsm_dev
*dev
,
1345 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1346 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
1350 printf("[%.16s]:\n", dev
->volume
);
1351 printf(" UUID : %s\n", uuid
);
1352 printf(" RAID Level : %d", get_imsm_raid_level(map
));
1354 printf(" <-- %d", get_imsm_raid_level(map2
));
1356 printf(" Members : %d", map
->num_members
);
1358 printf(" <-- %d", map2
->num_members
);
1360 printf(" Slots : [");
1361 for (i
= 0; i
< map
->num_members
; i
++) {
1362 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
1363 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1368 for (i
= 0; i
< map2
->num_members
; i
++) {
1369 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_1
);
1370 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1375 printf(" Failed disk : ");
1376 if (map
->failed_disk_num
== 0xff)
1379 printf("%i", map
->failed_disk_num
);
1381 slot
= get_imsm_disk_slot(map
, disk_idx
);
1383 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
1384 printf(" This Slot : %d%s\n", slot
,
1385 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
1387 printf(" This Slot : ?\n");
1388 sz
= __le32_to_cpu(dev
->size_high
);
1390 sz
+= __le32_to_cpu(dev
->size_low
);
1391 printf(" Array Size : %llu%s\n", (unsigned long long)sz
,
1392 human_size(sz
* 512));
1393 sz
= blocks_per_member(map
);
1394 printf(" Per Dev Size : %llu%s\n", (unsigned long long)sz
,
1395 human_size(sz
* 512));
1396 printf(" Sector Offset : %llu\n",
1398 printf(" Num Stripes : %llu\n",
1399 num_data_stripes(map
));
1400 printf(" Chunk Size : %u KiB",
1401 __le16_to_cpu(map
->blocks_per_strip
) / 2);
1403 printf(" <-- %u KiB",
1404 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
1406 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
1407 printf(" Migrate State : ");
1408 if (dev
->vol
.migr_state
) {
1409 if (migr_type(dev
) == MIGR_INIT
)
1410 printf("initialize\n");
1411 else if (migr_type(dev
) == MIGR_REBUILD
)
1412 printf("rebuild\n");
1413 else if (migr_type(dev
) == MIGR_VERIFY
)
1415 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
1416 printf("general migration\n");
1417 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
1418 printf("state change\n");
1419 else if (migr_type(dev
) == MIGR_REPAIR
)
1422 printf("<unknown:%d>\n", migr_type(dev
));
1425 printf(" Map State : %s", map_state_str
[map
->map_state
]);
1426 if (dev
->vol
.migr_state
) {
1427 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
1429 printf(" <-- %s", map_state_str
[map
->map_state
]);
1430 printf("\n Checkpoint : %u ",
1431 __le32_to_cpu(dev
->vol
.curr_migr_unit
));
1432 if (is_gen_migration(dev
) && (slot
> 1 || slot
< 0))
1435 printf("(%llu)", (unsigned long long)
1436 blocks_per_migr_unit(super
, dev
));
1439 printf(" Dirty State : %s\n", dev
->vol
.dirty
? "dirty" : "clean");
1442 static void print_imsm_disk(struct imsm_disk
*disk
, int index
, __u32 reserved
)
1444 char str
[MAX_RAID_SERIAL_LEN
+ 1];
1447 if (index
< -1 || !disk
)
1451 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
1453 printf(" Disk%02d Serial : %s\n", index
, str
);
1455 printf(" Disk Serial : %s\n", str
);
1456 printf(" State :%s%s%s\n", is_spare(disk
) ? " spare" : "",
1457 is_configured(disk
) ? " active" : "",
1458 is_failed(disk
) ? " failed" : "");
1459 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
1460 sz
= total_blocks(disk
) - reserved
;
1461 printf(" Usable Size : %llu%s\n", (unsigned long long)sz
,
1462 human_size(sz
* 512));
1465 void convert_to_4k_imsm_migr_rec(struct intel_super
*super
)
1467 struct migr_record
*migr_rec
= super
->migr_rec
;
1469 migr_rec
->blocks_per_unit
/= IMSM_4K_DIV
;
1470 migr_rec
->ckpt_area_pba
/= IMSM_4K_DIV
;
1471 migr_rec
->dest_1st_member_lba
/= IMSM_4K_DIV
;
1472 migr_rec
->dest_depth_per_unit
/= IMSM_4K_DIV
;
1473 split_ull((join_u32(migr_rec
->post_migr_vol_cap
,
1474 migr_rec
->post_migr_vol_cap_hi
) / IMSM_4K_DIV
),
1475 &migr_rec
->post_migr_vol_cap
, &migr_rec
->post_migr_vol_cap_hi
);
1478 void convert_to_4k_imsm_disk(struct imsm_disk
*disk
)
1480 set_total_blocks(disk
, (total_blocks(disk
)/IMSM_4K_DIV
));
1483 void convert_to_4k(struct intel_super
*super
)
1485 struct imsm_super
*mpb
= super
->anchor
;
1486 struct imsm_disk
*disk
;
1489 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1490 disk
= __get_imsm_disk(mpb
, i
);
1492 convert_to_4k_imsm_disk(disk
);
1494 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1495 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1496 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1498 split_ull((join_u32(dev
->size_low
, dev
->size_high
)/IMSM_4K_DIV
),
1499 &dev
->size_low
, &dev
->size_high
);
1500 dev
->vol
.curr_migr_unit
/= IMSM_4K_DIV
;
1503 set_blocks_per_member(map
, blocks_per_member(map
)/IMSM_4K_DIV
);
1504 map
->blocks_per_strip
/= IMSM_4K_DIV
;
1505 set_pba_of_lba0(map
, pba_of_lba0(map
)/IMSM_4K_DIV
);
1507 if (dev
->vol
.migr_state
) {
1509 map
= get_imsm_map(dev
, MAP_1
);
1510 set_blocks_per_member(map
,
1511 blocks_per_member(map
)/IMSM_4K_DIV
);
1512 map
->blocks_per_strip
/= IMSM_4K_DIV
;
1513 set_pba_of_lba0(map
, pba_of_lba0(map
)/IMSM_4K_DIV
);
1517 mpb
->check_sum
= __gen_imsm_checksum(mpb
);
1520 void examine_migr_rec_imsm(struct intel_super
*super
)
1522 struct migr_record
*migr_rec
= super
->migr_rec
;
1523 struct imsm_super
*mpb
= super
->anchor
;
1526 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1527 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1528 struct imsm_map
*map
;
1531 if (is_gen_migration(dev
) == 0)
1534 printf("\nMigration Record Information:");
1536 /* first map under migration */
1537 map
= get_imsm_map(dev
, MAP_0
);
1539 slot
= get_imsm_disk_slot(map
, super
->disks
->index
);
1540 if (map
== NULL
|| slot
> 1 || slot
< 0) {
1541 printf(" Empty\n ");
1542 printf("Examine one of first two disks in array\n");
1545 printf("\n Status : ");
1546 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
1549 printf("Contains Data\n");
1550 printf(" Current Unit : %u\n",
1551 __le32_to_cpu(migr_rec
->curr_migr_unit
));
1552 printf(" Family : %u\n",
1553 __le32_to_cpu(migr_rec
->family_num
));
1554 printf(" Ascending : %u\n",
1555 __le32_to_cpu(migr_rec
->ascending_migr
));
1556 printf(" Blocks Per Unit : %u\n",
1557 __le32_to_cpu(migr_rec
->blocks_per_unit
));
1558 printf(" Dest. Depth Per Unit : %u\n",
1559 __le32_to_cpu(migr_rec
->dest_depth_per_unit
));
1560 printf(" Checkpoint Area pba : %u\n",
1561 __le32_to_cpu(migr_rec
->ckpt_area_pba
));
1562 printf(" First member lba : %u\n",
1563 __le32_to_cpu(migr_rec
->dest_1st_member_lba
));
1564 printf(" Total Number of Units : %u\n",
1565 __le32_to_cpu(migr_rec
->num_migr_units
));
1566 printf(" Size of volume : %u\n",
1567 __le32_to_cpu(migr_rec
->post_migr_vol_cap
));
1568 printf(" Expansion space for LBA64 : %u\n",
1569 __le32_to_cpu(migr_rec
->post_migr_vol_cap_hi
));
1570 printf(" Record was read from : %u\n",
1571 __le32_to_cpu(migr_rec
->ckpt_read_disk_num
));
1576 #endif /* MDASSEMBLE */
1578 void convert_from_4k_imsm_migr_rec(struct intel_super
*super
)
1580 struct migr_record
*migr_rec
= super
->migr_rec
;
1582 migr_rec
->blocks_per_unit
*= IMSM_4K_DIV
;
1583 migr_rec
->ckpt_area_pba
*= IMSM_4K_DIV
;
1584 migr_rec
->dest_1st_member_lba
*= IMSM_4K_DIV
;
1585 migr_rec
->dest_depth_per_unit
*= IMSM_4K_DIV
;
1586 split_ull((join_u32(migr_rec
->post_migr_vol_cap
,
1587 migr_rec
->post_migr_vol_cap_hi
) * IMSM_4K_DIV
),
1588 &migr_rec
->post_migr_vol_cap
,
1589 &migr_rec
->post_migr_vol_cap_hi
);
1592 void convert_from_4k(struct intel_super
*super
)
1594 struct imsm_super
*mpb
= super
->anchor
;
1595 struct imsm_disk
*disk
;
1598 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1599 disk
= __get_imsm_disk(mpb
, i
);
1601 set_total_blocks(disk
, (total_blocks(disk
)*IMSM_4K_DIV
));
1604 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1605 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1606 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1608 split_ull((join_u32(dev
->size_low
, dev
->size_high
)*IMSM_4K_DIV
),
1609 &dev
->size_low
, &dev
->size_high
);
1610 dev
->vol
.curr_migr_unit
*= IMSM_4K_DIV
;
1613 set_blocks_per_member(map
, blocks_per_member(map
)*IMSM_4K_DIV
);
1614 map
->blocks_per_strip
*= IMSM_4K_DIV
;
1615 set_pba_of_lba0(map
, pba_of_lba0(map
)*IMSM_4K_DIV
);
1617 if (dev
->vol
.migr_state
) {
1619 map
= get_imsm_map(dev
, MAP_1
);
1620 set_blocks_per_member(map
,
1621 blocks_per_member(map
)*IMSM_4K_DIV
);
1622 map
->blocks_per_strip
*= IMSM_4K_DIV
;
1623 set_pba_of_lba0(map
, pba_of_lba0(map
)*IMSM_4K_DIV
);
1627 mpb
->check_sum
= __gen_imsm_checksum(mpb
);
1630 /*******************************************************************************
1631 * function: imsm_check_attributes
1632 * Description: Function checks if features represented by attributes flags
1633 * are supported by mdadm.
1635 * attributes - Attributes read from metadata
1637 * 0 - passed attributes contains unsupported features flags
1638 * 1 - all features are supported
1639 ******************************************************************************/
1640 static int imsm_check_attributes(__u32 attributes
)
1643 __u32 not_supported
= MPB_ATTRIB_SUPPORTED
^0xffffffff;
1645 not_supported
&= ~MPB_ATTRIB_IGNORED
;
1647 not_supported
&= attributes
;
1648 if (not_supported
) {
1649 pr_err("(IMSM): Unsupported attributes : %x\n",
1650 (unsigned)__le32_to_cpu(not_supported
));
1651 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1652 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY \n");
1653 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1655 if (not_supported
& MPB_ATTRIB_2TB
) {
1656 dprintf("\t\tMPB_ATTRIB_2TB\n");
1657 not_supported
^= MPB_ATTRIB_2TB
;
1659 if (not_supported
& MPB_ATTRIB_RAID0
) {
1660 dprintf("\t\tMPB_ATTRIB_RAID0\n");
1661 not_supported
^= MPB_ATTRIB_RAID0
;
1663 if (not_supported
& MPB_ATTRIB_RAID1
) {
1664 dprintf("\t\tMPB_ATTRIB_RAID1\n");
1665 not_supported
^= MPB_ATTRIB_RAID1
;
1667 if (not_supported
& MPB_ATTRIB_RAID10
) {
1668 dprintf("\t\tMPB_ATTRIB_RAID10\n");
1669 not_supported
^= MPB_ATTRIB_RAID10
;
1671 if (not_supported
& MPB_ATTRIB_RAID1E
) {
1672 dprintf("\t\tMPB_ATTRIB_RAID1E\n");
1673 not_supported
^= MPB_ATTRIB_RAID1E
;
1675 if (not_supported
& MPB_ATTRIB_RAID5
) {
1676 dprintf("\t\tMPB_ATTRIB_RAID5\n");
1677 not_supported
^= MPB_ATTRIB_RAID5
;
1679 if (not_supported
& MPB_ATTRIB_RAIDCNG
) {
1680 dprintf("\t\tMPB_ATTRIB_RAIDCNG\n");
1681 not_supported
^= MPB_ATTRIB_RAIDCNG
;
1683 if (not_supported
& MPB_ATTRIB_BBM
) {
1684 dprintf("\t\tMPB_ATTRIB_BBM\n");
1685 not_supported
^= MPB_ATTRIB_BBM
;
1687 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1688 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY (== MPB_ATTRIB_LEGACY)\n");
1689 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1691 if (not_supported
& MPB_ATTRIB_EXP_STRIPE_SIZE
) {
1692 dprintf("\t\tMPB_ATTRIB_EXP_STRIP_SIZE\n");
1693 not_supported
^= MPB_ATTRIB_EXP_STRIPE_SIZE
;
1695 if (not_supported
& MPB_ATTRIB_2TB_DISK
) {
1696 dprintf("\t\tMPB_ATTRIB_2TB_DISK\n");
1697 not_supported
^= MPB_ATTRIB_2TB_DISK
;
1699 if (not_supported
& MPB_ATTRIB_NEVER_USE2
) {
1700 dprintf("\t\tMPB_ATTRIB_NEVER_USE2\n");
1701 not_supported
^= MPB_ATTRIB_NEVER_USE2
;
1703 if (not_supported
& MPB_ATTRIB_NEVER_USE
) {
1704 dprintf("\t\tMPB_ATTRIB_NEVER_USE\n");
1705 not_supported
^= MPB_ATTRIB_NEVER_USE
;
1709 dprintf("(IMSM): Unknown attributes : %x\n", not_supported
);
1718 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
1720 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
1722 struct intel_super
*super
= st
->sb
;
1723 struct imsm_super
*mpb
= super
->anchor
;
1724 char str
[MAX_SIGNATURE_LENGTH
];
1729 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
1732 snprintf(str
, MPB_SIG_LEN
, "%s", mpb
->sig
);
1733 printf(" Magic : %s\n", str
);
1734 snprintf(str
, strlen(MPB_VERSION_RAID0
), "%s", get_imsm_version(mpb
));
1735 printf(" Version : %s\n", get_imsm_version(mpb
));
1736 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
1737 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
1738 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
1739 printf(" Attributes : ");
1740 if (imsm_check_attributes(mpb
->attributes
))
1741 printf("All supported\n");
1743 printf("not supported\n");
1744 getinfo_super_imsm(st
, &info
, NULL
);
1745 fname_from_uuid(st
, &info
, nbuf
, ':');
1746 printf(" UUID : %s\n", nbuf
+ 5);
1747 sum
= __le32_to_cpu(mpb
->check_sum
);
1748 printf(" Checksum : %08x %s\n", sum
,
1749 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
1750 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
, super
->sector_size
));
1751 printf(" Disks : %d\n", mpb
->num_disks
);
1752 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
1753 print_imsm_disk(__get_imsm_disk(mpb
, super
->disks
->index
), super
->disks
->index
, reserved
);
1754 if (get_imsm_bbm_log_size(super
->bbm_log
)) {
1755 struct bbm_log
*log
= super
->bbm_log
;
1758 printf("Bad Block Management Log:\n");
1759 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
1760 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
1761 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
1763 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1765 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1767 super
->current_vol
= i
;
1768 getinfo_super_imsm(st
, &info
, NULL
);
1769 fname_from_uuid(st
, &info
, nbuf
, ':');
1770 print_imsm_dev(super
, dev
, nbuf
+ 5, super
->disks
->index
);
1772 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1773 if (i
== super
->disks
->index
)
1775 print_imsm_disk(__get_imsm_disk(mpb
, i
), i
, reserved
);
1778 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
1779 if (dl
->index
== -1)
1780 print_imsm_disk(&dl
->disk
, -1, reserved
);
1782 examine_migr_rec_imsm(super
);
1785 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
1787 /* We just write a generic IMSM ARRAY entry */
1790 struct intel_super
*super
= st
->sb
;
1792 if (!super
->anchor
->num_raid_devs
) {
1793 printf("ARRAY metadata=imsm\n");
1797 getinfo_super_imsm(st
, &info
, NULL
);
1798 fname_from_uuid(st
, &info
, nbuf
, ':');
1799 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
1802 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
1804 /* We just write a generic IMSM ARRAY entry */
1808 struct intel_super
*super
= st
->sb
;
1811 if (!super
->anchor
->num_raid_devs
)
1814 getinfo_super_imsm(st
, &info
, NULL
);
1815 fname_from_uuid(st
, &info
, nbuf
, ':');
1816 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1817 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1819 super
->current_vol
= i
;
1820 getinfo_super_imsm(st
, &info
, NULL
);
1821 fname_from_uuid(st
, &info
, nbuf1
, ':');
1822 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
1823 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
1827 static void export_examine_super_imsm(struct supertype
*st
)
1829 struct intel_super
*super
= st
->sb
;
1830 struct imsm_super
*mpb
= super
->anchor
;
1834 getinfo_super_imsm(st
, &info
, NULL
);
1835 fname_from_uuid(st
, &info
, nbuf
, ':');
1836 printf("MD_METADATA=imsm\n");
1837 printf("MD_LEVEL=container\n");
1838 printf("MD_UUID=%s\n", nbuf
+5);
1839 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
1842 static int copy_metadata_imsm(struct supertype
*st
, int from
, int to
)
1844 /* The second last sector of the device contains
1845 * the "struct imsm_super" metadata.
1846 * This contains mpb_size which is the size in bytes of the
1847 * extended metadata. This is located immediately before
1849 * We want to read all that, plus the last sector which
1850 * may contain a migration record, and write it all
1854 unsigned long long dsize
, offset
;
1856 struct imsm_super
*sb
;
1857 struct intel_super
*super
= st
->sb
;
1858 unsigned int sector_size
= super
->sector_size
;
1859 unsigned int written
= 0;
1861 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, MAX_SECTOR_SIZE
) != 0)
1864 if (!get_dev_size(from
, NULL
, &dsize
))
1867 if (lseek64(from
, dsize
-(2*sector_size
), 0) < 0)
1869 if (read(from
, buf
, sector_size
) != sector_size
)
1872 if (strncmp((char*)sb
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0)
1875 sectors
= mpb_sectors(sb
, sector_size
) + 2;
1876 offset
= dsize
- sectors
* sector_size
;
1877 if (lseek64(from
, offset
, 0) < 0 ||
1878 lseek64(to
, offset
, 0) < 0)
1880 while (written
< sectors
* sector_size
) {
1881 int n
= sectors
*sector_size
- written
;
1884 if (read(from
, buf
, n
) != n
)
1886 if (write(to
, buf
, n
) != n
)
1897 static void detail_super_imsm(struct supertype
*st
, char *homehost
)
1902 getinfo_super_imsm(st
, &info
, NULL
);
1903 fname_from_uuid(st
, &info
, nbuf
, ':');
1904 printf("\n UUID : %s\n", nbuf
+ 5);
1907 static void brief_detail_super_imsm(struct supertype
*st
)
1911 getinfo_super_imsm(st
, &info
, NULL
);
1912 fname_from_uuid(st
, &info
, nbuf
, ':');
1913 printf(" UUID=%s", nbuf
+ 5);
1916 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
);
1917 static void fd2devname(int fd
, char *name
);
1919 static int ahci_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
1921 /* dump an unsorted list of devices attached to AHCI Intel storage
1922 * controller, as well as non-connected ports
1924 int hba_len
= strlen(hba_path
) + 1;
1929 unsigned long port_mask
= (1 << port_count
) - 1;
1931 if (port_count
> (int)sizeof(port_mask
) * 8) {
1933 pr_err("port_count %d out of range\n", port_count
);
1937 /* scroll through /sys/dev/block looking for devices attached to
1940 dir
= opendir("/sys/dev/block");
1944 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
1955 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
1957 path
= devt_to_devpath(makedev(major
, minor
));
1960 if (!path_attached_to_hba(path
, hba_path
)) {
1966 /* retrieve the scsi device type */
1967 if (asprintf(&device
, "/sys/dev/block/%d:%d/device/xxxxxxx", major
, minor
) < 0) {
1969 pr_err("failed to allocate 'device'\n");
1973 sprintf(device
, "/sys/dev/block/%d:%d/device/type", major
, minor
);
1974 if (load_sys(device
, buf
, sizeof(buf
)) != 0) {
1976 pr_err("failed to read device type for %s\n",
1982 type
= strtoul(buf
, NULL
, 10);
1984 /* if it's not a disk print the vendor and model */
1985 if (!(type
== 0 || type
== 7 || type
== 14)) {
1988 sprintf(device
, "/sys/dev/block/%d:%d/device/vendor", major
, minor
);
1989 if (load_sys(device
, buf
, sizeof(buf
)) == 0) {
1990 strncpy(vendor
, buf
, sizeof(vendor
));
1991 vendor
[sizeof(vendor
) - 1] = '\0';
1992 c
= (char *) &vendor
[sizeof(vendor
) - 1];
1993 while (isspace(*c
) || *c
== '\0')
1997 sprintf(device
, "/sys/dev/block/%d:%d/device/model", major
, minor
);
1998 if (load_sys(device
, buf
, sizeof(buf
)) == 0) {
1999 strncpy(model
, buf
, sizeof(model
));
2000 model
[sizeof(model
) - 1] = '\0';
2001 c
= (char *) &model
[sizeof(model
) - 1];
2002 while (isspace(*c
) || *c
== '\0')
2006 if (vendor
[0] && model
[0])
2007 sprintf(buf
, "%.64s %.64s", vendor
, model
);
2009 switch (type
) { /* numbers from hald/linux/device.c */
2010 case 1: sprintf(buf
, "tape"); break;
2011 case 2: sprintf(buf
, "printer"); break;
2012 case 3: sprintf(buf
, "processor"); break;
2014 case 5: sprintf(buf
, "cdrom"); break;
2015 case 6: sprintf(buf
, "scanner"); break;
2016 case 8: sprintf(buf
, "media_changer"); break;
2017 case 9: sprintf(buf
, "comm"); break;
2018 case 12: sprintf(buf
, "raid"); break;
2019 default: sprintf(buf
, "unknown");
2025 /* chop device path to 'host%d' and calculate the port number */
2026 c
= strchr(&path
[hba_len
], '/');
2029 pr_err("%s - invalid path name\n", path
+ hba_len
);
2034 if ((sscanf(&path
[hba_len
], "ata%d", &port
) == 1) ||
2035 ((sscanf(&path
[hba_len
], "host%d", &port
) == 1)))
2039 *c
= '/'; /* repair the full string */
2040 pr_err("failed to determine port number for %s\n",
2047 /* mark this port as used */
2048 port_mask
&= ~(1 << port
);
2050 /* print out the device information */
2052 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
2056 fd
= dev_open(ent
->d_name
, O_RDONLY
);
2058 printf(" Port%d : - disk info unavailable -\n", port
);
2060 fd2devname(fd
, buf
);
2061 printf(" Port%d : %s", port
, buf
);
2062 if (imsm_read_serial(fd
, NULL
, (__u8
*) buf
) == 0)
2063 printf(" (%.*s)\n", MAX_RAID_SERIAL_LEN
, buf
);
2078 for (i
= 0; i
< port_count
; i
++)
2079 if (port_mask
& (1 << i
))
2080 printf(" Port%d : - no device attached -\n", i
);
2086 static int print_vmd_attached_devs(struct sys_dev
*hba
)
2094 if (hba
->type
!= SYS_DEV_VMD
)
2097 /* scroll through /sys/dev/block looking for devices attached to
2100 dir
= opendir("/sys/bus/pci/drivers/nvme");
2104 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2107 /* is 'ent' a device? check that the 'subsystem' link exists and
2108 * that its target matches 'bus'
2110 sprintf(path
, "/sys/bus/pci/drivers/nvme/%s/subsystem",
2112 n
= readlink(path
, link
, sizeof(link
));
2113 if (n
< 0 || n
>= (int)sizeof(link
))
2116 c
= strrchr(link
, '/');
2119 if (strncmp("pci", c
+1, strlen("pci")) != 0)
2122 sprintf(path
, "/sys/bus/pci/drivers/nvme/%s", ent
->d_name
);
2123 /* if not a intel NVMe - skip it*/
2124 if (devpath_to_vendor(path
) != 0x8086)
2127 rp
= realpath(path
, NULL
);
2131 if (path_attached_to_hba(rp
, hba
->path
)) {
2132 printf(" NVMe under VMD : %s\n", rp
);
2141 static void print_found_intel_controllers(struct sys_dev
*elem
)
2143 for (; elem
; elem
= elem
->next
) {
2144 pr_err("found Intel(R) ");
2145 if (elem
->type
== SYS_DEV_SATA
)
2146 fprintf(stderr
, "SATA ");
2147 else if (elem
->type
== SYS_DEV_SAS
)
2148 fprintf(stderr
, "SAS ");
2149 else if (elem
->type
== SYS_DEV_NVME
)
2150 fprintf(stderr
, "NVMe ");
2152 if (elem
->type
== SYS_DEV_VMD
)
2153 fprintf(stderr
, "VMD domain");
2155 fprintf(stderr
, "RAID controller");
2158 fprintf(stderr
, " at %s", elem
->pci_id
);
2159 fprintf(stderr
, ".\n");
2164 static int ahci_get_port_count(const char *hba_path
, int *port_count
)
2171 if ((dir
= opendir(hba_path
)) == NULL
)
2174 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2177 if ((sscanf(ent
->d_name
, "ata%d", &host
) != 1) &&
2178 ((sscanf(ent
->d_name
, "host%d", &host
) != 1)))
2180 if (*port_count
== 0)
2182 else if (host
< host_base
)
2185 if (host
+ 1 > *port_count
+ host_base
)
2186 *port_count
= host
+ 1 - host_base
;
2192 static void print_imsm_capability(const struct imsm_orom
*orom
)
2194 printf(" Platform : Intel(R) ");
2195 if (orom
->capabilities
== 0 && orom
->driver_features
== 0)
2196 printf("Matrix Storage Manager\n");
2198 printf("Rapid Storage Technology%s\n",
2199 imsm_orom_is_enterprise(orom
) ? " enterprise" : "");
2200 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
2201 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
,
2202 orom
->minor_ver
, orom
->hotfix_ver
, orom
->build
);
2203 printf(" RAID Levels :%s%s%s%s%s\n",
2204 imsm_orom_has_raid0(orom
) ? " raid0" : "",
2205 imsm_orom_has_raid1(orom
) ? " raid1" : "",
2206 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
2207 imsm_orom_has_raid10(orom
) ? " raid10" : "",
2208 imsm_orom_has_raid5(orom
) ? " raid5" : "");
2209 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2210 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
2211 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
2212 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
2213 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
2214 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
2215 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
2216 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
2217 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
2218 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
2219 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
2220 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
2221 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
2222 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
2223 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
2224 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
2225 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
2226 printf(" 2TB volumes :%s supported\n",
2227 (orom
->attr
& IMSM_OROM_ATTR_2TB
)?"":" not");
2228 printf(" 2TB disks :%s supported\n",
2229 (orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
)?"":" not");
2230 printf(" Max Disks : %d\n", orom
->tds
);
2231 printf(" Max Volumes : %d per array, %d per %s\n",
2232 orom
->vpa
, orom
->vphba
,
2233 imsm_orom_is_nvme(orom
) ? "platform" : "controller");
2237 static void print_imsm_capability_export(const struct imsm_orom
*orom
)
2239 printf("MD_FIRMWARE_TYPE=imsm\n");
2240 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
2241 printf("IMSM_VERSION=%d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
2242 orom
->hotfix_ver
, orom
->build
);
2243 printf("IMSM_SUPPORTED_RAID_LEVELS=%s%s%s%s%s\n",
2244 imsm_orom_has_raid0(orom
) ? "raid0 " : "",
2245 imsm_orom_has_raid1(orom
) ? "raid1 " : "",
2246 imsm_orom_has_raid1e(orom
) ? "raid1e " : "",
2247 imsm_orom_has_raid5(orom
) ? "raid10 " : "",
2248 imsm_orom_has_raid10(orom
) ? "raid5 " : "");
2249 printf("IMSM_SUPPORTED_CHUNK_SIZES=%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2250 imsm_orom_has_chunk(orom
, 2) ? "2k " : "",
2251 imsm_orom_has_chunk(orom
, 4) ? "4k " : "",
2252 imsm_orom_has_chunk(orom
, 8) ? "8k " : "",
2253 imsm_orom_has_chunk(orom
, 16) ? "16k " : "",
2254 imsm_orom_has_chunk(orom
, 32) ? "32k " : "",
2255 imsm_orom_has_chunk(orom
, 64) ? "64k " : "",
2256 imsm_orom_has_chunk(orom
, 128) ? "128k " : "",
2257 imsm_orom_has_chunk(orom
, 256) ? "256k " : "",
2258 imsm_orom_has_chunk(orom
, 512) ? "512k " : "",
2259 imsm_orom_has_chunk(orom
, 1024*1) ? "1M " : "",
2260 imsm_orom_has_chunk(orom
, 1024*2) ? "2M " : "",
2261 imsm_orom_has_chunk(orom
, 1024*4) ? "4M " : "",
2262 imsm_orom_has_chunk(orom
, 1024*8) ? "8M " : "",
2263 imsm_orom_has_chunk(orom
, 1024*16) ? "16M " : "",
2264 imsm_orom_has_chunk(orom
, 1024*32) ? "32M " : "",
2265 imsm_orom_has_chunk(orom
, 1024*64) ? "64M " : "");
2266 printf("IMSM_2TB_VOLUMES=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB
) ? "yes" : "no");
2267 printf("IMSM_2TB_DISKS=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) ? "yes" : "no");
2268 printf("IMSM_MAX_DISKS=%d\n",orom
->tds
);
2269 printf("IMSM_MAX_VOLUMES_PER_ARRAY=%d\n",orom
->vpa
);
2270 printf("IMSM_MAX_VOLUMES_PER_CONTROLLER=%d\n",orom
->vphba
);
2273 static int detail_platform_imsm(int verbose
, int enumerate_only
, char *controller_path
)
2275 /* There are two components to imsm platform support, the ahci SATA
2276 * controller and the option-rom. To find the SATA controller we
2277 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
2278 * controller with the Intel vendor id is present. This approach
2279 * allows mdadm to leverage the kernel's ahci detection logic, with the
2280 * caveat that if ahci.ko is not loaded mdadm will not be able to
2281 * detect platform raid capabilities. The option-rom resides in a
2282 * platform "Adapter ROM". We scan for its signature to retrieve the
2283 * platform capabilities. If raid support is disabled in the BIOS the
2284 * option-rom capability structure will not be available.
2286 struct sys_dev
*list
, *hba
;
2291 if (enumerate_only
) {
2292 if (check_env("IMSM_NO_PLATFORM"))
2294 list
= find_intel_devices();
2297 for (hba
= list
; hba
; hba
= hba
->next
) {
2298 if (find_imsm_capability(hba
)) {
2308 list
= find_intel_devices();
2311 pr_err("no active Intel(R) RAID controller found.\n");
2313 } else if (verbose
> 0)
2314 print_found_intel_controllers(list
);
2316 for (hba
= list
; hba
; hba
= hba
->next
) {
2317 if (controller_path
&& (compare_paths(hba
->path
, controller_path
) != 0))
2319 if (!find_imsm_capability(hba
)) {
2321 pr_err("imsm capabilities not found for controller: %s (type %s)\n",
2322 hba
->type
== SYS_DEV_VMD
? vmd_domain_to_controller(hba
, buf
) : hba
->path
,
2323 get_sys_dev_type(hba
->type
));
2329 if (controller_path
&& result
== 1) {
2330 pr_err("no active Intel(R) RAID controller found under %s\n",
2335 const struct orom_entry
*entry
;
2337 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
2338 if (entry
->type
== SYS_DEV_VMD
) {
2339 print_imsm_capability(&entry
->orom
);
2340 for (hba
= list
; hba
; hba
= hba
->next
) {
2341 if (hba
->type
== SYS_DEV_VMD
) {
2343 printf(" I/O Controller : %s (%s)\n",
2344 vmd_domain_to_controller(hba
, buf
), get_sys_dev_type(hba
->type
));
2345 if (print_vmd_attached_devs(hba
)) {
2347 pr_err("failed to get devices attached to VMD domain.\n");
2356 print_imsm_capability(&entry
->orom
);
2357 if (entry
->type
== SYS_DEV_NVME
) {
2358 for (hba
= list
; hba
; hba
= hba
->next
) {
2359 if (hba
->type
== SYS_DEV_NVME
)
2360 printf(" NVMe Device : %s\n", hba
->path
);
2366 struct devid_list
*devid
;
2367 for (devid
= entry
->devid_list
; devid
; devid
= devid
->next
) {
2368 hba
= device_by_id(devid
->devid
);
2372 printf(" I/O Controller : %s (%s)\n",
2373 hba
->path
, get_sys_dev_type(hba
->type
));
2374 if (hba
->type
== SYS_DEV_SATA
) {
2375 host_base
= ahci_get_port_count(hba
->path
, &port_count
);
2376 if (ahci_enumerate_ports(hba
->path
, port_count
, host_base
, verbose
)) {
2378 pr_err("failed to enumerate ports on SATA controller at %s.\n", hba
->pci_id
);
2389 static int export_detail_platform_imsm(int verbose
, char *controller_path
)
2391 struct sys_dev
*list
, *hba
;
2394 list
= find_intel_devices();
2397 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_INTEL_DEVICES\n");
2402 for (hba
= list
; hba
; hba
= hba
->next
) {
2403 if (controller_path
&& (compare_paths(hba
->path
,controller_path
) != 0))
2405 if (!find_imsm_capability(hba
) && verbose
> 0) {
2407 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_IMSM_CAPABLE_DEVICE_UNDER_%s\n",
2408 hba
->type
== SYS_DEV_VMD
? vmd_domain_to_controller(hba
, buf
) : hba
->path
);
2414 const struct orom_entry
*entry
;
2416 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
2417 if (entry
->type
== SYS_DEV_VMD
) {
2418 for (hba
= list
; hba
; hba
= hba
->next
)
2419 print_imsm_capability_export(&entry
->orom
);
2422 print_imsm_capability_export(&entry
->orom
);
2430 static int match_home_imsm(struct supertype
*st
, char *homehost
)
2432 /* the imsm metadata format does not specify any host
2433 * identification information. We return -1 since we can never
2434 * confirm nor deny whether a given array is "meant" for this
2435 * host. We rely on compare_super and the 'family_num' fields to
2436 * exclude member disks that do not belong, and we rely on
2437 * mdadm.conf to specify the arrays that should be assembled.
2438 * Auto-assembly may still pick up "foreign" arrays.
2444 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
2446 /* The uuid returned here is used for:
2447 * uuid to put into bitmap file (Create, Grow)
2448 * uuid for backup header when saving critical section (Grow)
2449 * comparing uuids when re-adding a device into an array
2450 * In these cases the uuid required is that of the data-array,
2451 * not the device-set.
2452 * uuid to recognise same set when adding a missing device back
2453 * to an array. This is a uuid for the device-set.
2455 * For each of these we can make do with a truncated
2456 * or hashed uuid rather than the original, as long as
2458 * In each case the uuid required is that of the data-array,
2459 * not the device-set.
2461 /* imsm does not track uuid's so we synthesis one using sha1 on
2462 * - The signature (Which is constant for all imsm array, but no matter)
2463 * - the orig_family_num of the container
2464 * - the index number of the volume
2465 * - the 'serial' number of the volume.
2466 * Hopefully these are all constant.
2468 struct intel_super
*super
= st
->sb
;
2471 struct sha1_ctx ctx
;
2472 struct imsm_dev
*dev
= NULL
;
2475 /* some mdadm versions failed to set ->orig_family_num, in which
2476 * case fall back to ->family_num. orig_family_num will be
2477 * fixed up with the first metadata update.
2479 family_num
= super
->anchor
->orig_family_num
;
2480 if (family_num
== 0)
2481 family_num
= super
->anchor
->family_num
;
2482 sha1_init_ctx(&ctx
);
2483 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
2484 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
2485 if (super
->current_vol
>= 0)
2486 dev
= get_imsm_dev(super
, super
->current_vol
);
2488 __u32 vol
= super
->current_vol
;
2489 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
2490 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
2492 sha1_finish_ctx(&ctx
, buf
);
2493 memcpy(uuid
, buf
, 4*4);
2498 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
2500 __u8
*v
= get_imsm_version(mpb
);
2501 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
2502 char major
[] = { 0, 0, 0 };
2503 char minor
[] = { 0 ,0, 0 };
2504 char patch
[] = { 0, 0, 0 };
2505 char *ver_parse
[] = { major
, minor
, patch
};
2509 while (*v
!= '\0' && v
< end
) {
2510 if (*v
!= '.' && j
< 2)
2511 ver_parse
[i
][j
++] = *v
;
2519 *m
= strtol(minor
, NULL
, 0);
2520 *p
= strtol(patch
, NULL
, 0);
2524 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
2526 /* migr_strip_size when repairing or initializing parity */
2527 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2528 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2530 switch (get_imsm_raid_level(map
)) {
2535 return 128*1024 >> 9;
2539 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
2541 /* migr_strip_size when rebuilding a degraded disk, no idea why
2542 * this is different than migr_strip_size_resync(), but it's good
2545 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2546 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2548 switch (get_imsm_raid_level(map
)) {
2551 if (map
->num_members
% map
->num_domains
== 0)
2552 return 128*1024 >> 9;
2556 return max((__u32
) 64*1024 >> 9, chunk
);
2558 return 128*1024 >> 9;
2562 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
2564 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2565 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2566 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
2567 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
2569 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
2572 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
2574 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2575 int level
= get_imsm_raid_level(lo
);
2577 if (level
== 1 || level
== 10) {
2578 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2580 return hi
->num_domains
;
2582 return num_stripes_per_unit_resync(dev
);
2585 static __u8
imsm_num_data_members(struct imsm_dev
*dev
, int second_map
)
2587 /* named 'imsm_' because raid0, raid1 and raid10
2588 * counter-intuitively have the same number of data disks
2590 struct imsm_map
*map
= get_imsm_map(dev
, second_map
);
2592 switch (get_imsm_raid_level(map
)) {
2594 return map
->num_members
;
2598 return map
->num_members
/2;
2600 return map
->num_members
- 1;
2602 dprintf("unsupported raid level\n");
2607 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
2609 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2610 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2612 switch(get_imsm_raid_level(map
)) {
2615 return chunk
* map
->num_domains
;
2617 return chunk
* map
->num_members
;
2623 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
2625 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2626 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2627 __u32 strip
= block
/ chunk
;
2629 switch (get_imsm_raid_level(map
)) {
2632 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
2633 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
2635 return vol_stripe
* chunk
+ block
% chunk
;
2637 __u32 stripe
= strip
/ (map
->num_members
- 1);
2639 return stripe
* chunk
+ block
% chunk
;
2646 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
2647 struct imsm_dev
*dev
)
2649 /* calculate the conversion factor between per member 'blocks'
2650 * (md/{resync,rebuild}_start) and imsm migration units, return
2651 * 0 for the 'not migrating' and 'unsupported migration' cases
2653 if (!dev
->vol
.migr_state
)
2656 switch (migr_type(dev
)) {
2657 case MIGR_GEN_MIGR
: {
2658 struct migr_record
*migr_rec
= super
->migr_rec
;
2659 return __le32_to_cpu(migr_rec
->blocks_per_unit
);
2664 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2665 __u32 stripes_per_unit
;
2666 __u32 blocks_per_unit
;
2675 /* yes, this is really the translation of migr_units to
2676 * per-member blocks in the 'resync' case
2678 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
2679 migr_chunk
= migr_strip_blocks_resync(dev
);
2680 disks
= imsm_num_data_members(dev
, MAP_0
);
2681 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
2682 stripe
= __le16_to_cpu(map
->blocks_per_strip
) * disks
;
2683 segment
= blocks_per_unit
/ stripe
;
2684 block_rel
= blocks_per_unit
- segment
* stripe
;
2685 parity_depth
= parity_segment_depth(dev
);
2686 block_map
= map_migr_block(dev
, block_rel
);
2687 return block_map
+ parity_depth
* segment
;
2689 case MIGR_REBUILD
: {
2690 __u32 stripes_per_unit
;
2693 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
2694 migr_chunk
= migr_strip_blocks_rebuild(dev
);
2695 return migr_chunk
* stripes_per_unit
;
2697 case MIGR_STATE_CHANGE
:
2703 static int imsm_level_to_layout(int level
)
2711 return ALGORITHM_LEFT_ASYMMETRIC
;
2718 /*******************************************************************************
2719 * Function: read_imsm_migr_rec
2720 * Description: Function reads imsm migration record from last sector of disk
2722 * fd : disk descriptor
2723 * super : metadata info
2727 ******************************************************************************/
2728 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
)
2731 unsigned int sector_size
= super
->sector_size
;
2732 unsigned long long dsize
;
2734 get_dev_size(fd
, NULL
, &dsize
);
2735 if (lseek64(fd
, dsize
- (sector_size
*MIGR_REC_SECTOR_POSITION
),
2737 pr_err("Cannot seek to anchor block: %s\n",
2741 if (read(fd
, super
->migr_rec_buf
,
2742 MIGR_REC_BUF_SECTORS
*sector_size
) !=
2743 MIGR_REC_BUF_SECTORS
*sector_size
) {
2744 pr_err("Cannot read migr record block: %s\n",
2749 if (sector_size
== 4096)
2750 convert_from_4k_imsm_migr_rec(super
);
2756 static struct imsm_dev
*imsm_get_device_during_migration(
2757 struct intel_super
*super
)
2760 struct intel_dev
*dv
;
2762 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
2763 if (is_gen_migration(dv
->dev
))
2769 /*******************************************************************************
2770 * Function: load_imsm_migr_rec
2771 * Description: Function reads imsm migration record (it is stored at the last
2774 * super : imsm internal array info
2775 * info : general array info
2779 * -2 : no migration in progress
2780 ******************************************************************************/
2781 static int load_imsm_migr_rec(struct intel_super
*super
, struct mdinfo
*info
)
2788 struct imsm_dev
*dev
;
2789 struct imsm_map
*map
;
2792 /* find map under migration */
2793 dev
= imsm_get_device_during_migration(super
);
2794 /* nothing to load,no migration in progress?
2800 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
2801 /* read only from one of the first two slots */
2802 if ((sd
->disk
.raid_disk
< 0) ||
2803 (sd
->disk
.raid_disk
> 1))
2806 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
2807 fd
= dev_open(nm
, O_RDONLY
);
2813 map
= get_imsm_map(dev
, MAP_0
);
2814 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
2815 /* skip spare and failed disks
2819 /* read only from one of the first two slots */
2821 slot
= get_imsm_disk_slot(map
, dl
->index
);
2822 if (map
== NULL
|| slot
> 1 || slot
< 0)
2824 sprintf(nm
, "%d:%d", dl
->major
, dl
->minor
);
2825 fd
= dev_open(nm
, O_RDONLY
);
2832 retval
= read_imsm_migr_rec(fd
, super
);
2841 /*******************************************************************************
2842 * function: imsm_create_metadata_checkpoint_update
2843 * Description: It creates update for checkpoint change.
2845 * super : imsm internal array info
2846 * u : pointer to prepared update
2849 * If length is equal to 0, input pointer u contains no update
2850 ******************************************************************************/
2851 static int imsm_create_metadata_checkpoint_update(
2852 struct intel_super
*super
,
2853 struct imsm_update_general_migration_checkpoint
**u
)
2856 int update_memory_size
= 0;
2858 dprintf("(enter)\n");
2864 /* size of all update data without anchor */
2865 update_memory_size
=
2866 sizeof(struct imsm_update_general_migration_checkpoint
);
2868 *u
= xcalloc(1, update_memory_size
);
2870 dprintf("error: cannot get memory\n");
2873 (*u
)->type
= update_general_migration_checkpoint
;
2874 (*u
)->curr_migr_unit
= __le32_to_cpu(super
->migr_rec
->curr_migr_unit
);
2875 dprintf("prepared for %u\n", (*u
)->curr_migr_unit
);
2877 return update_memory_size
;
2880 static void imsm_update_metadata_locally(struct supertype
*st
,
2881 void *buf
, int len
);
2883 /*******************************************************************************
2884 * Function: write_imsm_migr_rec
2885 * Description: Function writes imsm migration record
2886 * (at the last sector of disk)
2888 * super : imsm internal array info
2892 ******************************************************************************/
2893 static int write_imsm_migr_rec(struct supertype
*st
)
2895 struct intel_super
*super
= st
->sb
;
2896 unsigned int sector_size
= super
->sector_size
;
2897 unsigned long long dsize
;
2903 struct imsm_update_general_migration_checkpoint
*u
;
2904 struct imsm_dev
*dev
;
2905 struct imsm_map
*map
;
2907 /* find map under migration */
2908 dev
= imsm_get_device_during_migration(super
);
2909 /* if no migration, write buffer anyway to clear migr_record
2910 * on disk based on first available device
2913 dev
= get_imsm_dev(super
, super
->current_vol
< 0 ? 0 :
2914 super
->current_vol
);
2916 map
= get_imsm_map(dev
, MAP_0
);
2918 if (sector_size
== 4096)
2919 convert_to_4k_imsm_migr_rec(super
);
2920 for (sd
= super
->disks
; sd
; sd
= sd
->next
) {
2923 /* skip failed and spare devices */
2926 /* write to 2 first slots only */
2928 slot
= get_imsm_disk_slot(map
, sd
->index
);
2929 if (map
== NULL
|| slot
> 1 || slot
< 0)
2932 sprintf(nm
, "%d:%d", sd
->major
, sd
->minor
);
2933 fd
= dev_open(nm
, O_RDWR
);
2936 get_dev_size(fd
, NULL
, &dsize
);
2937 if (lseek64(fd
, dsize
- (MIGR_REC_SECTOR_POSITION
*sector_size
),
2939 pr_err("Cannot seek to anchor block: %s\n",
2943 if (write(fd
, super
->migr_rec_buf
,
2944 MIGR_REC_BUF_SECTORS
*sector_size
) !=
2945 MIGR_REC_BUF_SECTORS
*sector_size
) {
2946 pr_err("Cannot write migr record block: %s\n",
2953 if (sector_size
== 4096)
2954 convert_from_4k_imsm_migr_rec(super
);
2955 /* update checkpoint information in metadata */
2956 len
= imsm_create_metadata_checkpoint_update(super
, &u
);
2958 dprintf("imsm: Cannot prepare update\n");
2961 /* update metadata locally */
2962 imsm_update_metadata_locally(st
, u
, len
);
2963 /* and possibly remotely */
2964 if (st
->update_tail
) {
2965 append_metadata_update(st
, u
, len
);
2966 /* during reshape we do all work inside metadata handler
2967 * manage_reshape(), so metadata update has to be triggered
2970 flush_metadata_updates(st
);
2971 st
->update_tail
= &st
->updates
;
2981 #endif /* MDASSEMBLE */
2983 /* spare/missing disks activations are not allowe when
2984 * array/container performs reshape operation, because
2985 * all arrays in container works on the same disks set
2987 int imsm_reshape_blocks_arrays_changes(struct intel_super
*super
)
2990 struct intel_dev
*i_dev
;
2991 struct imsm_dev
*dev
;
2993 /* check whole container
2995 for (i_dev
= super
->devlist
; i_dev
; i_dev
= i_dev
->next
) {
2997 if (is_gen_migration(dev
)) {
2998 /* No repair during any migration in container
3006 static unsigned long long imsm_component_size_aligment_check(int level
,
3008 unsigned int sector_size
,
3009 unsigned long long component_size
)
3011 unsigned int component_size_alligment
;
3013 /* check component size aligment
3015 component_size_alligment
= component_size
% (chunk_size
/sector_size
);
3017 dprintf("(Level: %i, chunk_size = %i, component_size = %llu), component_size_alligment = %u\n",
3018 level
, chunk_size
, component_size
,
3019 component_size_alligment
);
3021 if (component_size_alligment
&& (level
!= 1) && (level
!= UnSet
)) {
3022 dprintf("imsm: reported component size alligned from %llu ",
3024 component_size
-= component_size_alligment
;
3025 dprintf_cont("to %llu (%i).\n",
3026 component_size
, component_size_alligment
);
3029 return component_size
;
3032 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
3034 struct intel_super
*super
= st
->sb
;
3035 struct migr_record
*migr_rec
= super
->migr_rec
;
3036 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
3037 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3038 struct imsm_map
*prev_map
= get_imsm_map(dev
, MAP_1
);
3039 struct imsm_map
*map_to_analyse
= map
;
3041 int map_disks
= info
->array
.raid_disks
;
3043 memset(info
, 0, sizeof(*info
));
3045 map_to_analyse
= prev_map
;
3047 dl
= super
->current_disk
;
3049 info
->container_member
= super
->current_vol
;
3050 info
->array
.raid_disks
= map
->num_members
;
3051 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
3052 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
3053 info
->array
.md_minor
= -1;
3054 info
->array
.ctime
= 0;
3055 info
->array
.utime
= 0;
3056 info
->array
.chunk_size
=
3057 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
3058 info
->array
.state
= !dev
->vol
.dirty
;
3059 info
->custom_array_size
= __le32_to_cpu(dev
->size_high
);
3060 info
->custom_array_size
<<= 32;
3061 info
->custom_array_size
|= __le32_to_cpu(dev
->size_low
);
3062 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
3064 if (is_gen_migration(dev
)) {
3065 info
->reshape_active
= 1;
3066 info
->new_level
= get_imsm_raid_level(map
);
3067 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
3068 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
3069 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
3070 if (info
->delta_disks
) {
3071 /* this needs to be applied to every array
3074 info
->reshape_active
= CONTAINER_RESHAPE
;
3076 /* We shape information that we give to md might have to be
3077 * modify to cope with md's requirement for reshaping arrays.
3078 * For example, when reshaping a RAID0, md requires it to be
3079 * presented as a degraded RAID4.
3080 * Also if a RAID0 is migrating to a RAID5 we need to specify
3081 * the array as already being RAID5, but the 'before' layout
3082 * is a RAID4-like layout.
3084 switch (info
->array
.level
) {
3086 switch(info
->new_level
) {
3088 /* conversion is happening as RAID4 */
3089 info
->array
.level
= 4;
3090 info
->array
.raid_disks
+= 1;
3093 /* conversion is happening as RAID5 */
3094 info
->array
.level
= 5;
3095 info
->array
.layout
= ALGORITHM_PARITY_N
;
3096 info
->delta_disks
-= 1;
3099 /* FIXME error message */
3100 info
->array
.level
= UnSet
;
3106 info
->new_level
= UnSet
;
3107 info
->new_layout
= UnSet
;
3108 info
->new_chunk
= info
->array
.chunk_size
;
3109 info
->delta_disks
= 0;
3113 info
->disk
.major
= dl
->major
;
3114 info
->disk
.minor
= dl
->minor
;
3115 info
->disk
.number
= dl
->index
;
3116 info
->disk
.raid_disk
= get_imsm_disk_slot(map_to_analyse
,
3120 info
->data_offset
= pba_of_lba0(map_to_analyse
);
3122 if (info
->array
.level
== 5) {
3123 info
->component_size
= num_data_stripes(map_to_analyse
) *
3124 map_to_analyse
->blocks_per_strip
;
3126 info
->component_size
= blocks_per_member(map_to_analyse
);
3129 info
->component_size
= imsm_component_size_aligment_check(
3131 info
->array
.chunk_size
,
3133 info
->component_size
);
3134 info
->bb
.supported
= 0;
3136 memset(info
->uuid
, 0, sizeof(info
->uuid
));
3137 info
->recovery_start
= MaxSector
;
3139 info
->reshape_progress
= 0;
3140 info
->resync_start
= MaxSector
;
3141 if ((map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
3143 imsm_reshape_blocks_arrays_changes(super
) == 0) {
3144 info
->resync_start
= 0;
3146 if (dev
->vol
.migr_state
) {
3147 switch (migr_type(dev
)) {
3150 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
3152 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
3154 info
->resync_start
= blocks_per_unit
* units
;
3157 case MIGR_GEN_MIGR
: {
3158 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
3160 __u64 units
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
3161 unsigned long long array_blocks
;
3164 if (__le32_to_cpu(migr_rec
->ascending_migr
) &&
3166 (__le32_to_cpu(migr_rec
->num_migr_units
)-1)) &&
3167 (super
->migr_rec
->rec_status
==
3168 __cpu_to_le32(UNIT_SRC_IN_CP_AREA
)))
3171 info
->reshape_progress
= blocks_per_unit
* units
;
3173 dprintf("IMSM: General Migration checkpoint : %llu (%llu) -> read reshape progress : %llu\n",
3174 (unsigned long long)units
,
3175 (unsigned long long)blocks_per_unit
,
3176 info
->reshape_progress
);
3178 used_disks
= imsm_num_data_members(dev
, MAP_1
);
3179 if (used_disks
> 0) {
3180 array_blocks
= blocks_per_member(map
) *
3182 /* round array size down to closest MB
3184 info
->custom_array_size
= (array_blocks
3185 >> SECT_PER_MB_SHIFT
)
3186 << SECT_PER_MB_SHIFT
;
3190 /* we could emulate the checkpointing of
3191 * 'sync_action=check' migrations, but for now
3192 * we just immediately complete them
3195 /* this is handled by container_content_imsm() */
3196 case MIGR_STATE_CHANGE
:
3197 /* FIXME handle other migrations */
3199 /* we are not dirty, so... */
3200 info
->resync_start
= MaxSector
;
3204 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
3205 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
3207 info
->array
.major_version
= -1;
3208 info
->array
.minor_version
= -2;
3209 sprintf(info
->text_version
, "/%s/%d", st
->container_devnm
, info
->container_member
);
3210 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
3211 uuid_from_super_imsm(st
, info
->uuid
);
3215 for (i
=0; i
<map_disks
; i
++) {
3217 if (i
< info
->array
.raid_disks
) {
3218 struct imsm_disk
*dsk
;
3219 j
= get_imsm_disk_idx(dev
, i
, MAP_X
);
3220 dsk
= get_imsm_disk(super
, j
);
3221 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
3228 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
3229 int failed
, int look_in_map
);
3231 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
3235 static void manage_second_map(struct intel_super
*super
, struct imsm_dev
*dev
)
3237 if (is_gen_migration(dev
)) {
3240 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
3242 failed
= imsm_count_failed(super
, dev
, MAP_1
);
3243 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_1
);
3244 if (map2
->map_state
!= map_state
) {
3245 map2
->map_state
= map_state
;
3246 super
->updates_pending
++;
3252 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
3256 for (d
= super
->missing
; d
; d
= d
->next
)
3257 if (d
->index
== index
)
3262 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
3264 struct intel_super
*super
= st
->sb
;
3265 struct imsm_disk
*disk
;
3266 int map_disks
= info
->array
.raid_disks
;
3267 int max_enough
= -1;
3269 struct imsm_super
*mpb
;
3271 if (super
->current_vol
>= 0) {
3272 getinfo_super_imsm_volume(st
, info
, map
);
3275 memset(info
, 0, sizeof(*info
));
3277 /* Set raid_disks to zero so that Assemble will always pull in valid
3280 info
->array
.raid_disks
= 0;
3281 info
->array
.level
= LEVEL_CONTAINER
;
3282 info
->array
.layout
= 0;
3283 info
->array
.md_minor
= -1;
3284 info
->array
.ctime
= 0; /* N/A for imsm */
3285 info
->array
.utime
= 0;
3286 info
->array
.chunk_size
= 0;
3288 info
->disk
.major
= 0;
3289 info
->disk
.minor
= 0;
3290 info
->disk
.raid_disk
= -1;
3291 info
->reshape_active
= 0;
3292 info
->array
.major_version
= -1;
3293 info
->array
.minor_version
= -2;
3294 strcpy(info
->text_version
, "imsm");
3295 info
->safe_mode_delay
= 0;
3296 info
->disk
.number
= -1;
3297 info
->disk
.state
= 0;
3299 info
->recovery_start
= MaxSector
;
3300 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
3301 info
->bb
.supported
= 0;
3303 /* do we have the all the insync disks that we expect? */
3304 mpb
= super
->anchor
;
3306 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
3307 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
3308 int failed
, enough
, j
, missing
= 0;
3309 struct imsm_map
*map
;
3312 failed
= imsm_count_failed(super
, dev
, MAP_0
);
3313 state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
3314 map
= get_imsm_map(dev
, MAP_0
);
3316 /* any newly missing disks?
3317 * (catches single-degraded vs double-degraded)
3319 for (j
= 0; j
< map
->num_members
; j
++) {
3320 __u32 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
3321 __u32 idx
= ord_to_idx(ord
);
3323 if (!(ord
& IMSM_ORD_REBUILD
) &&
3324 get_imsm_missing(super
, idx
)) {
3330 if (state
== IMSM_T_STATE_FAILED
)
3332 else if (state
== IMSM_T_STATE_DEGRADED
&&
3333 (state
!= map
->map_state
|| missing
))
3335 else /* we're normal, or already degraded */
3337 if (is_gen_migration(dev
) && missing
) {
3338 /* during general migration we need all disks
3339 * that process is running on.
3340 * No new missing disk is allowed.
3344 /* no more checks necessary
3348 /* in the missing/failed disk case check to see
3349 * if at least one array is runnable
3351 max_enough
= max(max_enough
, enough
);
3353 dprintf("enough: %d\n", max_enough
);
3354 info
->container_enough
= max_enough
;
3357 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
3359 disk
= &super
->disks
->disk
;
3360 info
->data_offset
= total_blocks(&super
->disks
->disk
) - reserved
;
3361 info
->component_size
= reserved
;
3362 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
3363 /* we don't change info->disk.raid_disk here because
3364 * this state will be finalized in mdmon after we have
3365 * found the 'most fresh' version of the metadata
3367 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
3368 info
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
3371 /* only call uuid_from_super_imsm when this disk is part of a populated container,
3372 * ->compare_super may have updated the 'num_raid_devs' field for spares
3374 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
3375 uuid_from_super_imsm(st
, info
->uuid
);
3377 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
3379 /* I don't know how to compute 'map' on imsm, so use safe default */
3382 for (i
= 0; i
< map_disks
; i
++)
3388 /* allocates memory and fills disk in mdinfo structure
3389 * for each disk in array */
3390 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
3392 struct mdinfo
*mddev
;
3393 struct intel_super
*super
= st
->sb
;
3394 struct imsm_disk
*disk
;
3397 if (!super
|| !super
->disks
)
3400 mddev
= xcalloc(1, sizeof(*mddev
));
3404 tmp
= xcalloc(1, sizeof(*tmp
));
3406 tmp
->next
= mddev
->devs
;
3408 tmp
->disk
.number
= count
++;
3409 tmp
->disk
.major
= dl
->major
;
3410 tmp
->disk
.minor
= dl
->minor
;
3411 tmp
->disk
.state
= is_configured(disk
) ?
3412 (1 << MD_DISK_ACTIVE
) : 0;
3413 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
3414 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
3415 tmp
->disk
.raid_disk
= -1;
3421 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
3422 char *update
, char *devname
, int verbose
,
3423 int uuid_set
, char *homehost
)
3425 /* For 'assemble' and 'force' we need to return non-zero if any
3426 * change was made. For others, the return value is ignored.
3427 * Update options are:
3428 * force-one : This device looks a bit old but needs to be included,
3429 * update age info appropriately.
3430 * assemble: clear any 'faulty' flag to allow this device to
3432 * force-array: Array is degraded but being forced, mark it clean
3433 * if that will be needed to assemble it.
3435 * newdev: not used ????
3436 * grow: Array has gained a new device - this is currently for
3438 * resync: mark as dirty so a resync will happen.
3439 * name: update the name - preserving the homehost
3440 * uuid: Change the uuid of the array to match watch is given
3442 * Following are not relevant for this imsm:
3443 * sparc2.2 : update from old dodgey metadata
3444 * super-minor: change the preferred_minor number
3445 * summaries: update redundant counters.
3446 * homehost: update the recorded homehost
3447 * _reshape_progress: record new reshape_progress position.
3450 struct intel_super
*super
= st
->sb
;
3451 struct imsm_super
*mpb
;
3453 /* we can only update container info */
3454 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
3457 mpb
= super
->anchor
;
3459 if (strcmp(update
, "uuid") == 0) {
3460 /* We take this to mean that the family_num should be updated.
3461 * However that is much smaller than the uuid so we cannot really
3462 * allow an explicit uuid to be given. And it is hard to reliably
3464 * So if !uuid_set we know the current uuid is random and just used
3465 * the first 'int' and copy it to the other 3 positions.
3466 * Otherwise we require the 4 'int's to be the same as would be the
3467 * case if we are using a random uuid. So an explicit uuid will be
3468 * accepted as long as all for ints are the same... which shouldn't hurt
3471 info
->uuid
[1] = info
->uuid
[2] = info
->uuid
[3] = info
->uuid
[0];
3474 if (info
->uuid
[0] != info
->uuid
[1] ||
3475 info
->uuid
[1] != info
->uuid
[2] ||
3476 info
->uuid
[2] != info
->uuid
[3])
3482 mpb
->orig_family_num
= info
->uuid
[0];
3483 } else if (strcmp(update
, "assemble") == 0)
3488 /* successful update? recompute checksum */
3490 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
3495 static size_t disks_to_mpb_size(int disks
)
3499 size
= sizeof(struct imsm_super
);
3500 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
3501 size
+= 2 * sizeof(struct imsm_dev
);
3502 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
3503 size
+= (4 - 2) * sizeof(struct imsm_map
);
3504 /* 4 possible disk_ord_tbl's */
3505 size
+= 4 * (disks
- 1) * sizeof(__u32
);
3506 /* maximum bbm log */
3507 size
+= sizeof(struct bbm_log
);
3512 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
,
3513 unsigned long long data_offset
)
3515 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
3518 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
3521 static void free_devlist(struct intel_super
*super
)
3523 struct intel_dev
*dv
;
3525 while (super
->devlist
) {
3526 dv
= super
->devlist
->next
;
3527 free(super
->devlist
->dev
);
3528 free(super
->devlist
);
3529 super
->devlist
= dv
;
3533 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
3535 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
3538 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
)
3542 * 0 same, or first was empty, and second was copied
3543 * 1 second had wrong number
3545 * 3 wrong other info
3547 struct intel_super
*first
= st
->sb
;
3548 struct intel_super
*sec
= tst
->sb
;
3555 /* in platform dependent environment test if the disks
3556 * use the same Intel hba
3557 * If not on Intel hba at all, allow anything.
3559 if (!check_env("IMSM_NO_PLATFORM") && first
->hba
&& sec
->hba
) {
3560 if (first
->hba
->type
!= sec
->hba
->type
) {
3562 "HBAs of devices do not match %s != %s\n",
3563 get_sys_dev_type(first
->hba
->type
),
3564 get_sys_dev_type(sec
->hba
->type
));
3567 if (first
->orom
!= sec
->orom
) {
3569 "HBAs of devices do not match %s != %s\n",
3570 first
->hba
->pci_id
, sec
->hba
->pci_id
);
3575 /* if an anchor does not have num_raid_devs set then it is a free
3578 if (first
->anchor
->num_raid_devs
> 0 &&
3579 sec
->anchor
->num_raid_devs
> 0) {
3580 /* Determine if these disks might ever have been
3581 * related. Further disambiguation can only take place
3582 * in load_super_imsm_all
3584 __u32 first_family
= first
->anchor
->orig_family_num
;
3585 __u32 sec_family
= sec
->anchor
->orig_family_num
;
3587 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
3588 MAX_SIGNATURE_LENGTH
) != 0)
3591 if (first_family
== 0)
3592 first_family
= first
->anchor
->family_num
;
3593 if (sec_family
== 0)
3594 sec_family
= sec
->anchor
->family_num
;
3596 if (first_family
!= sec_family
)
3601 /* if 'first' is a spare promote it to a populated mpb with sec's
3604 if (first
->anchor
->num_raid_devs
== 0 &&
3605 sec
->anchor
->num_raid_devs
> 0) {
3607 struct intel_dev
*dv
;
3608 struct imsm_dev
*dev
;
3610 /* we need to copy raid device info from sec if an allocation
3611 * fails here we don't associate the spare
3613 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++) {
3614 dv
= xmalloc(sizeof(*dv
));
3615 dev
= xmalloc(sizeof_imsm_dev(get_imsm_dev(sec
, i
), 1));
3618 dv
->next
= first
->devlist
;
3619 first
->devlist
= dv
;
3621 if (i
< sec
->anchor
->num_raid_devs
) {
3622 /* allocation failure */
3623 free_devlist(first
);
3624 pr_err("imsm: failed to associate spare\n");
3627 first
->anchor
->num_raid_devs
= sec
->anchor
->num_raid_devs
;
3628 first
->anchor
->orig_family_num
= sec
->anchor
->orig_family_num
;
3629 first
->anchor
->family_num
= sec
->anchor
->family_num
;
3630 memcpy(first
->anchor
->sig
, sec
->anchor
->sig
, MAX_SIGNATURE_LENGTH
);
3631 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++)
3632 imsm_copy_dev(get_imsm_dev(first
, i
), get_imsm_dev(sec
, i
));
3638 static void fd2devname(int fd
, char *name
)
3642 char dname
[PATH_MAX
];
3647 if (fstat(fd
, &st
) != 0)
3649 sprintf(path
, "/sys/dev/block/%d:%d",
3650 major(st
.st_rdev
), minor(st
.st_rdev
));
3652 rv
= readlink(path
, dname
, sizeof(dname
)-1);
3657 nm
= strrchr(dname
, '/');
3660 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
3664 static int nvme_get_serial(int fd
, void *buf
, size_t buf_len
)
3667 char *name
= fd2kname(fd
);
3672 if (strncmp(name
, "nvme", 4) != 0)
3675 snprintf(path
, sizeof(path
) - 1, "/sys/block/%s/device/serial", name
);
3677 return load_sys(path
, buf
, buf_len
);
3680 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
3682 static int imsm_read_serial(int fd
, char *devname
,
3683 __u8 serial
[MAX_RAID_SERIAL_LEN
])
3692 memset(buf
, 0, sizeof(buf
));
3694 rv
= nvme_get_serial(fd
, buf
, sizeof(buf
));
3697 rv
= scsi_get_serial(fd
, buf
, sizeof(buf
));
3699 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
3700 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3701 fd2devname(fd
, (char *) serial
);
3707 pr_err("Failed to retrieve serial for %s\n",
3712 /* trim all whitespace and non-printable characters and convert
3715 for (i
= 0, dest
= buf
; i
< sizeof(buf
) && buf
[i
]; i
++) {
3718 /* ':' is reserved for use in placeholder serial
3719 * numbers for missing disks
3730 /* truncate leading characters */
3731 if (len
> MAX_RAID_SERIAL_LEN
) {
3732 dest
+= len
- MAX_RAID_SERIAL_LEN
;
3733 len
= MAX_RAID_SERIAL_LEN
;
3736 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3737 memcpy(serial
, dest
, len
);
3742 static int serialcmp(__u8
*s1
, __u8
*s2
)
3744 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
3747 static void serialcpy(__u8
*dest
, __u8
*src
)
3749 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
3752 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
3756 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3757 if (serialcmp(dl
->serial
, serial
) == 0)
3763 static struct imsm_disk
*
3764 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
3768 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3769 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
3771 if (serialcmp(disk
->serial
, serial
) == 0) {
3782 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3784 struct imsm_disk
*disk
;
3789 __u8 serial
[MAX_RAID_SERIAL_LEN
];
3791 rv
= imsm_read_serial(fd
, devname
, serial
);
3796 dl
= xcalloc(1, sizeof(*dl
));
3799 dl
->major
= major(stb
.st_rdev
);
3800 dl
->minor
= minor(stb
.st_rdev
);
3801 dl
->next
= super
->disks
;
3802 dl
->fd
= keep_fd
? fd
: -1;
3803 assert(super
->disks
== NULL
);
3805 serialcpy(dl
->serial
, serial
);
3808 fd2devname(fd
, name
);
3810 dl
->devname
= xstrdup(devname
);
3812 dl
->devname
= xstrdup(name
);
3814 /* look up this disk's index in the current anchor */
3815 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
3818 /* only set index on disks that are a member of a
3819 * populated contianer, i.e. one with raid_devs
3821 if (is_failed(&dl
->disk
))
3823 else if (is_spare(&dl
->disk
))
3831 /* When migrating map0 contains the 'destination' state while map1
3832 * contains the current state. When not migrating map0 contains the
3833 * current state. This routine assumes that map[0].map_state is set to
3834 * the current array state before being called.
3836 * Migration is indicated by one of the following states
3837 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
3838 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
3839 * map1state=unitialized)
3840 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
3842 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
3843 * map1state=degraded)
3844 * 5/ Migration (mig_state=1 migr_type=MIGR_GEN_MIGR map0state=normal
3847 static void migrate(struct imsm_dev
*dev
, struct intel_super
*super
,
3848 __u8 to_state
, int migr_type
)
3850 struct imsm_map
*dest
;
3851 struct imsm_map
*src
= get_imsm_map(dev
, MAP_0
);
3853 dev
->vol
.migr_state
= 1;
3854 set_migr_type(dev
, migr_type
);
3855 dev
->vol
.curr_migr_unit
= 0;
3856 dest
= get_imsm_map(dev
, MAP_1
);
3858 /* duplicate and then set the target end state in map[0] */
3859 memcpy(dest
, src
, sizeof_imsm_map(src
));
3860 if (migr_type
== MIGR_REBUILD
|| migr_type
== MIGR_GEN_MIGR
) {
3864 for (i
= 0; i
< src
->num_members
; i
++) {
3865 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
3866 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
3870 if (migr_type
== MIGR_GEN_MIGR
)
3871 /* Clear migration record */
3872 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
3874 src
->map_state
= to_state
;
3877 static void end_migration(struct imsm_dev
*dev
, struct intel_super
*super
,
3880 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3881 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
== 0 ?
3885 /* merge any IMSM_ORD_REBUILD bits that were not successfully
3886 * completed in the last migration.
3888 * FIXME add support for raid-level-migration
3890 if (map_state
!= map
->map_state
&& (is_gen_migration(dev
) == 0) &&
3891 prev
->map_state
!= IMSM_T_STATE_UNINITIALIZED
) {
3892 /* when final map state is other than expected
3893 * merge maps (not for migration)
3897 for (i
= 0; i
< prev
->num_members
; i
++)
3898 for (j
= 0; j
< map
->num_members
; j
++)
3899 /* during online capacity expansion
3900 * disks position can be changed
3901 * if takeover is used
3903 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
3904 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
3905 map
->disk_ord_tbl
[j
] |=
3906 prev
->disk_ord_tbl
[i
];
3909 failed
= imsm_count_failed(super
, dev
, MAP_0
);
3910 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
3913 dev
->vol
.migr_state
= 0;
3914 set_migr_type(dev
, 0);
3915 dev
->vol
.curr_migr_unit
= 0;
3916 map
->map_state
= map_state
;
3920 static int parse_raid_devices(struct intel_super
*super
)
3923 struct imsm_dev
*dev_new
;
3924 size_t len
, len_migr
;
3926 size_t space_needed
= 0;
3927 struct imsm_super
*mpb
= super
->anchor
;
3929 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3930 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3931 struct intel_dev
*dv
;
3933 len
= sizeof_imsm_dev(dev_iter
, 0);
3934 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
3936 space_needed
+= len_migr
- len
;
3938 dv
= xmalloc(sizeof(*dv
));
3939 if (max_len
< len_migr
)
3941 if (max_len
> len_migr
)
3942 space_needed
+= max_len
- len_migr
;
3943 dev_new
= xmalloc(max_len
);
3944 imsm_copy_dev(dev_new
, dev_iter
);
3947 dv
->next
= super
->devlist
;
3948 super
->devlist
= dv
;
3951 /* ensure that super->buf is large enough when all raid devices
3954 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
3957 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
,
3958 super
->sector_size
);
3959 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, len
) != 0)
3962 memcpy(buf
, super
->buf
, super
->len
);
3963 memset(buf
+ super
->len
, 0, len
- super
->len
);
3969 super
->extra_space
+= space_needed
;
3974 /*******************************************************************************
3975 * Function: check_mpb_migr_compatibility
3976 * Description: Function checks for unsupported migration features:
3977 * - migration optimization area (pba_of_lba0)
3978 * - descending reshape (ascending_migr)
3980 * super : imsm metadata information
3982 * 0 : migration is compatible
3983 * -1 : migration is not compatible
3984 ******************************************************************************/
3985 int check_mpb_migr_compatibility(struct intel_super
*super
)
3987 struct imsm_map
*map0
, *map1
;
3988 struct migr_record
*migr_rec
= super
->migr_rec
;
3991 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3992 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3995 dev_iter
->vol
.migr_state
== 1 &&
3996 dev_iter
->vol
.migr_type
== MIGR_GEN_MIGR
) {
3997 /* This device is migrating */
3998 map0
= get_imsm_map(dev_iter
, MAP_0
);
3999 map1
= get_imsm_map(dev_iter
, MAP_1
);
4000 if (pba_of_lba0(map0
) != pba_of_lba0(map1
))
4001 /* migration optimization area was used */
4003 if (migr_rec
->ascending_migr
== 0
4004 && migr_rec
->dest_depth_per_unit
> 0)
4005 /* descending reshape not supported yet */
4012 static void __free_imsm(struct intel_super
*super
, int free_disks
);
4014 /* load_imsm_mpb - read matrix metadata
4015 * allocates super->mpb to be freed by free_imsm
4017 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
4019 unsigned long long dsize
;
4020 unsigned long long sectors
;
4021 unsigned int sector_size
= super
->sector_size
;
4023 struct imsm_super
*anchor
;
4026 get_dev_size(fd
, NULL
, &dsize
);
4027 if (dsize
< 2*sector_size
) {
4029 pr_err("%s: device to small for imsm\n",
4034 if (lseek64(fd
, dsize
- (sector_size
* 2), SEEK_SET
) < 0) {
4036 pr_err("Cannot seek to anchor block on %s: %s\n",
4037 devname
, strerror(errno
));
4041 if (posix_memalign((void **)&anchor
, sector_size
, sector_size
) != 0) {
4043 pr_err("Failed to allocate imsm anchor buffer on %s\n", devname
);
4046 if (read(fd
, anchor
, sector_size
) != sector_size
) {
4048 pr_err("Cannot read anchor block on %s: %s\n",
4049 devname
, strerror(errno
));
4054 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
4056 pr_err("no IMSM anchor on %s\n", devname
);
4061 __free_imsm(super
, 0);
4062 /* reload capability and hba */
4064 /* capability and hba must be updated with new super allocation */
4065 find_intel_hba_capability(fd
, super
, devname
);
4066 super
->len
= ROUND_UP(anchor
->mpb_size
, sector_size
);
4067 if (posix_memalign(&super
->buf
, MAX_SECTOR_SIZE
, super
->len
) != 0) {
4069 pr_err("unable to allocate %zu byte mpb buffer\n",
4074 memcpy(super
->buf
, anchor
, sector_size
);
4076 sectors
= mpb_sectors(anchor
, sector_size
) - 1;
4079 if (posix_memalign(&super
->migr_rec_buf
, sector_size
,
4080 MIGR_REC_BUF_SECTORS
*sector_size
) != 0) {
4081 pr_err("could not allocate migr_rec buffer\n");
4085 super
->clean_migration_record_by_mdmon
= 0;
4088 check_sum
= __gen_imsm_checksum(super
->anchor
);
4089 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
4091 pr_err("IMSM checksum %x != %x on %s\n",
4093 __le32_to_cpu(super
->anchor
->check_sum
),
4101 /* read the extended mpb */
4102 if (lseek64(fd
, dsize
- (sector_size
* (2 + sectors
)), SEEK_SET
) < 0) {
4104 pr_err("Cannot seek to extended mpb on %s: %s\n",
4105 devname
, strerror(errno
));
4109 if ((unsigned int)read(fd
, super
->buf
+ sector_size
,
4110 super
->len
- sector_size
) != super
->len
- sector_size
) {
4112 pr_err("Cannot read extended mpb on %s: %s\n",
4113 devname
, strerror(errno
));
4117 check_sum
= __gen_imsm_checksum(super
->anchor
);
4118 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
4120 pr_err("IMSM checksum %x != %x on %s\n",
4121 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
4129 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
);
4131 /* clears hi bits in metadata if MPB_ATTRIB_2TB_DISK not set */
4132 static void clear_hi(struct intel_super
*super
)
4134 struct imsm_super
*mpb
= super
->anchor
;
4136 if (mpb
->attributes
& MPB_ATTRIB_2TB_DISK
)
4138 for (i
= 0; i
< mpb
->num_disks
; ++i
) {
4139 struct imsm_disk
*disk
= &mpb
->disk
[i
];
4140 disk
->total_blocks_hi
= 0;
4142 for (i
= 0; i
< mpb
->num_raid_devs
; ++i
) {
4143 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
4146 for (n
= 0; n
< 2; ++n
) {
4147 struct imsm_map
*map
= get_imsm_map(dev
, n
);
4150 map
->pba_of_lba0_hi
= 0;
4151 map
->blocks_per_member_hi
= 0;
4152 map
->num_data_stripes_hi
= 0;
4158 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
4162 err
= load_imsm_mpb(fd
, super
, devname
);
4165 if (super
->sector_size
== 4096)
4166 convert_from_4k(super
);
4167 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
4170 err
= parse_raid_devices(super
);
4173 err
= load_bbm_log(super
);
4178 static void __free_imsm_disk(struct dl
*d
)
4190 static void free_imsm_disks(struct intel_super
*super
)
4194 while (super
->disks
) {
4196 super
->disks
= d
->next
;
4197 __free_imsm_disk(d
);
4199 while (super
->disk_mgmt_list
) {
4200 d
= super
->disk_mgmt_list
;
4201 super
->disk_mgmt_list
= d
->next
;
4202 __free_imsm_disk(d
);
4204 while (super
->missing
) {
4206 super
->missing
= d
->next
;
4207 __free_imsm_disk(d
);
4212 /* free all the pieces hanging off of a super pointer */
4213 static void __free_imsm(struct intel_super
*super
, int free_disks
)
4215 struct intel_hba
*elem
, *next
;
4221 /* unlink capability description */
4223 if (super
->migr_rec_buf
) {
4224 free(super
->migr_rec_buf
);
4225 super
->migr_rec_buf
= NULL
;
4228 free_imsm_disks(super
);
4229 free_devlist(super
);
4233 free((void *)elem
->path
);
4239 free(super
->bbm_log
);
4243 static void free_imsm(struct intel_super
*super
)
4245 __free_imsm(super
, 1);
4249 static void free_super_imsm(struct supertype
*st
)
4251 struct intel_super
*super
= st
->sb
;
4260 static struct intel_super
*alloc_super(void)
4262 struct intel_super
*super
= xcalloc(1, sizeof(*super
));
4264 super
->current_vol
= -1;
4265 super
->create_offset
= ~((unsigned long long) 0);
4270 * find and allocate hba and OROM/EFI based on valid fd of RAID component device
4272 static int find_intel_hba_capability(int fd
, struct intel_super
*super
, char *devname
)
4274 struct sys_dev
*hba_name
;
4277 if (fd
< 0 || check_env("IMSM_NO_PLATFORM")) {
4282 hba_name
= find_disk_attached_hba(fd
, NULL
);
4285 pr_err("%s is not attached to Intel(R) RAID controller.\n",
4289 rv
= attach_hba_to_super(super
, hba_name
);
4292 struct intel_hba
*hba
= super
->hba
;
4294 pr_err("%s is attached to Intel(R) %s %s (%s),\n"
4295 " but the container is assigned to Intel(R) %s %s (",
4297 get_sys_dev_type(hba_name
->type
),
4298 hba_name
->type
== SYS_DEV_VMD
? "domain" : "RAID controller",
4299 hba_name
->pci_id
? : "Err!",
4300 get_sys_dev_type(super
->hba
->type
),
4301 hba
->type
== SYS_DEV_VMD
? "domain" : "RAID controller");
4304 fprintf(stderr
, "%s", hba
->pci_id
? : "Err!");
4306 fprintf(stderr
, ", ");
4309 fprintf(stderr
, ").\n"
4310 " Mixing devices attached to different %s is not allowed.\n",
4311 hba_name
->type
== SYS_DEV_VMD
? "VMD domains" : "controllers");
4315 super
->orom
= find_imsm_capability(hba_name
);
4322 /* find_missing - helper routine for load_super_imsm_all that identifies
4323 * disks that have disappeared from the system. This routine relies on
4324 * the mpb being uptodate, which it is at load time.
4326 static int find_missing(struct intel_super
*super
)
4329 struct imsm_super
*mpb
= super
->anchor
;
4331 struct imsm_disk
*disk
;
4333 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4334 disk
= __get_imsm_disk(mpb
, i
);
4335 dl
= serial_to_dl(disk
->serial
, super
);
4339 dl
= xmalloc(sizeof(*dl
));
4343 dl
->devname
= xstrdup("missing");
4345 serialcpy(dl
->serial
, disk
->serial
);
4348 dl
->next
= super
->missing
;
4349 super
->missing
= dl
;
4356 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
4358 struct intel_disk
*idisk
= disk_list
;
4361 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
4363 idisk
= idisk
->next
;
4369 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
4370 struct intel_super
*super
,
4371 struct intel_disk
**disk_list
)
4373 struct imsm_disk
*d
= &super
->disks
->disk
;
4374 struct imsm_super
*mpb
= super
->anchor
;
4377 for (i
= 0; i
< tbl_size
; i
++) {
4378 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
4379 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
4381 if (tbl_mpb
->family_num
== mpb
->family_num
) {
4382 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
4383 dprintf("mpb from %d:%d matches %d:%d\n",
4384 super
->disks
->major
,
4385 super
->disks
->minor
,
4386 table
[i
]->disks
->major
,
4387 table
[i
]->disks
->minor
);
4391 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
4392 is_configured(d
) == is_configured(tbl_d
)) &&
4393 tbl_mpb
->generation_num
< mpb
->generation_num
) {
4394 /* current version of the mpb is a
4395 * better candidate than the one in
4396 * super_table, but copy over "cross
4397 * generational" status
4399 struct intel_disk
*idisk
;
4401 dprintf("mpb from %d:%d replaces %d:%d\n",
4402 super
->disks
->major
,
4403 super
->disks
->minor
,
4404 table
[i
]->disks
->major
,
4405 table
[i
]->disks
->minor
);
4407 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
4408 if (idisk
&& is_failed(&idisk
->disk
))
4409 tbl_d
->status
|= FAILED_DISK
;
4412 struct intel_disk
*idisk
;
4413 struct imsm_disk
*disk
;
4415 /* tbl_mpb is more up to date, but copy
4416 * over cross generational status before
4419 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
4420 if (disk
&& is_failed(disk
))
4421 d
->status
|= FAILED_DISK
;
4423 idisk
= disk_list_get(d
->serial
, *disk_list
);
4426 if (disk
&& is_configured(disk
))
4427 idisk
->disk
.status
|= CONFIGURED_DISK
;
4430 dprintf("mpb from %d:%d prefer %d:%d\n",
4431 super
->disks
->major
,
4432 super
->disks
->minor
,
4433 table
[i
]->disks
->major
,
4434 table
[i
]->disks
->minor
);
4442 table
[tbl_size
++] = super
;
4446 /* update/extend the merged list of imsm_disk records */
4447 for (j
= 0; j
< mpb
->num_disks
; j
++) {
4448 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
4449 struct intel_disk
*idisk
;
4451 idisk
= disk_list_get(disk
->serial
, *disk_list
);
4453 idisk
->disk
.status
|= disk
->status
;
4454 if (is_configured(&idisk
->disk
) ||
4455 is_failed(&idisk
->disk
))
4456 idisk
->disk
.status
&= ~(SPARE_DISK
);
4458 idisk
= xcalloc(1, sizeof(*idisk
));
4459 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
4460 idisk
->disk
= *disk
;
4461 idisk
->next
= *disk_list
;
4465 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
4472 static struct intel_super
*
4473 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
4476 struct imsm_super
*mpb
= super
->anchor
;
4480 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4481 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
4482 struct intel_disk
*idisk
;
4484 idisk
= disk_list_get(disk
->serial
, disk_list
);
4486 if (idisk
->owner
== owner
||
4487 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
4490 dprintf("'%.16s' owner %d != %d\n",
4491 disk
->serial
, idisk
->owner
,
4494 dprintf("unknown disk %x [%d]: %.16s\n",
4495 __le32_to_cpu(mpb
->family_num
), i
,
4501 if (ok_count
== mpb
->num_disks
)
4506 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
4508 struct intel_super
*s
;
4510 for (s
= super_list
; s
; s
= s
->next
) {
4511 if (family_num
!= s
->anchor
->family_num
)
4513 pr_err("Conflict, offlining family %#x on '%s'\n",
4514 __le32_to_cpu(family_num
), s
->disks
->devname
);
4518 static struct intel_super
*
4519 imsm_thunderdome(struct intel_super
**super_list
, int len
)
4521 struct intel_super
*super_table
[len
];
4522 struct intel_disk
*disk_list
= NULL
;
4523 struct intel_super
*champion
, *spare
;
4524 struct intel_super
*s
, **del
;
4529 memset(super_table
, 0, sizeof(super_table
));
4530 for (s
= *super_list
; s
; s
= s
->next
)
4531 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
4533 for (i
= 0; i
< tbl_size
; i
++) {
4534 struct imsm_disk
*d
;
4535 struct intel_disk
*idisk
;
4536 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
4539 d
= &s
->disks
->disk
;
4541 /* 'd' must appear in merged disk list for its
4542 * configuration to be valid
4544 idisk
= disk_list_get(d
->serial
, disk_list
);
4545 if (idisk
&& idisk
->owner
== i
)
4546 s
= validate_members(s
, disk_list
, i
);
4551 dprintf("marking family: %#x from %d:%d offline\n",
4553 super_table
[i
]->disks
->major
,
4554 super_table
[i
]->disks
->minor
);
4558 /* This is where the mdadm implementation differs from the Windows
4559 * driver which has no strict concept of a container. We can only
4560 * assemble one family from a container, so when returning a prodigal
4561 * array member to this system the code will not be able to disambiguate
4562 * the container contents that should be assembled ("foreign" versus
4563 * "local"). It requires user intervention to set the orig_family_num
4564 * to a new value to establish a new container. The Windows driver in
4565 * this situation fixes up the volume name in place and manages the
4566 * foreign array as an independent entity.
4571 for (i
= 0; i
< tbl_size
; i
++) {
4572 struct intel_super
*tbl_ent
= super_table
[i
];
4578 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
4583 if (s
&& !is_spare
) {
4584 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
4586 } else if (!s
&& !is_spare
)
4599 pr_err("Chose family %#x on '%s', assemble conflicts to new container with '--update=uuid'\n",
4600 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
4602 /* collect all dl's onto 'champion', and update them to
4603 * champion's version of the status
4605 for (s
= *super_list
; s
; s
= s
->next
) {
4606 struct imsm_super
*mpb
= champion
->anchor
;
4607 struct dl
*dl
= s
->disks
;
4612 mpb
->attributes
|= s
->anchor
->attributes
& MPB_ATTRIB_2TB_DISK
;
4614 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4615 struct imsm_disk
*disk
;
4617 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
4620 /* only set index on disks that are a member of
4621 * a populated contianer, i.e. one with
4624 if (is_failed(&dl
->disk
))
4626 else if (is_spare(&dl
->disk
))
4632 if (i
>= mpb
->num_disks
) {
4633 struct intel_disk
*idisk
;
4635 idisk
= disk_list_get(dl
->serial
, disk_list
);
4636 if (idisk
&& is_spare(&idisk
->disk
) &&
4637 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
4645 dl
->next
= champion
->disks
;
4646 champion
->disks
= dl
;
4650 /* delete 'champion' from super_list */
4651 for (del
= super_list
; *del
; ) {
4652 if (*del
== champion
) {
4653 *del
= (*del
)->next
;
4656 del
= &(*del
)->next
;
4658 champion
->next
= NULL
;
4662 struct intel_disk
*idisk
= disk_list
;
4664 disk_list
= disk_list
->next
;
4672 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
);
4673 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4674 int major
, int minor
, int keep_fd
);
4676 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4677 int *max
, int keep_fd
);
4679 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
4680 char *devname
, struct md_list
*devlist
,
4683 struct intel_super
*super_list
= NULL
;
4684 struct intel_super
*super
= NULL
;
4689 /* 'fd' is an opened container */
4690 err
= get_sra_super_block(fd
, &super_list
, devname
, &i
, keep_fd
);
4692 /* get super block from devlist devices */
4693 err
= get_devlist_super_block(devlist
, &super_list
, &i
, keep_fd
);
4696 /* all mpbs enter, maybe one leaves */
4697 super
= imsm_thunderdome(&super_list
, i
);
4703 if (find_missing(super
) != 0) {
4709 /* load migration record */
4710 err
= load_imsm_migr_rec(super
, NULL
);
4712 /* migration is in progress,
4713 * but migr_rec cannot be loaded,
4719 /* Check migration compatibility */
4720 if (err
== 0 && check_mpb_migr_compatibility(super
) != 0) {
4721 pr_err("Unsupported migration detected");
4723 fprintf(stderr
, " on %s\n", devname
);
4725 fprintf(stderr
, " (IMSM).\n");
4734 while (super_list
) {
4735 struct intel_super
*s
= super_list
;
4737 super_list
= super_list
->next
;
4746 strcpy(st
->container_devnm
, fd2devnm(fd
));
4748 st
->container_devnm
[0] = 0;
4749 if (err
== 0 && st
->ss
== NULL
) {
4750 st
->ss
= &super_imsm
;
4751 st
->minor_version
= 0;
4752 st
->max_devs
= IMSM_MAX_DEVICES
;
4758 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4759 int *max
, int keep_fd
)
4761 struct md_list
*tmpdev
;
4765 for (i
= 0, tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
4766 if (tmpdev
->used
!= 1)
4768 if (tmpdev
->container
== 1) {
4770 int fd
= dev_open(tmpdev
->devname
, O_RDONLY
|O_EXCL
);
4772 pr_err("cannot open device %s: %s\n",
4773 tmpdev
->devname
, strerror(errno
));
4777 err
= get_sra_super_block(fd
, super_list
,
4778 tmpdev
->devname
, &lmax
,
4787 int major
= major(tmpdev
->st_rdev
);
4788 int minor
= minor(tmpdev
->st_rdev
);
4789 err
= get_super_block(super_list
,
4806 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4807 int major
, int minor
, int keep_fd
)
4809 struct intel_super
*s
;
4821 sprintf(nm
, "%d:%d", major
, minor
);
4822 dfd
= dev_open(nm
, O_RDWR
);
4828 get_dev_sector_size(dfd
, NULL
, &s
->sector_size
);
4829 find_intel_hba_capability(dfd
, s
, devname
);
4830 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
4832 /* retry the load if we might have raced against mdmon */
4833 if (err
== 3 && devnm
&& mdmon_running(devnm
))
4834 for (retry
= 0; retry
< 3; retry
++) {
4836 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
4842 s
->next
= *super_list
;
4850 if (dfd
>= 0 && !keep_fd
)
4857 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
)
4864 sra
= sysfs_read(fd
, NULL
, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
4868 if (sra
->array
.major_version
!= -1 ||
4869 sra
->array
.minor_version
!= -2 ||
4870 strcmp(sra
->text_version
, "imsm") != 0) {
4875 devnm
= fd2devnm(fd
);
4876 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
4877 if (get_super_block(super_list
, devnm
, devname
,
4878 sd
->disk
.major
, sd
->disk
.minor
, keep_fd
) != 0) {
4889 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
4891 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
, NULL
, 1);
4895 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
4897 struct intel_super
*super
;
4901 if (test_partition(fd
))
4902 /* IMSM not allowed on partitions */
4905 free_super_imsm(st
);
4907 super
= alloc_super();
4908 get_dev_sector_size(fd
, NULL
, &super
->sector_size
);
4911 /* Load hba and capabilities if they exist.
4912 * But do not preclude loading metadata in case capabilities or hba are
4913 * non-compliant and ignore_hw_compat is set.
4915 rv
= find_intel_hba_capability(fd
, super
, devname
);
4916 /* no orom/efi or non-intel hba of the disk */
4917 if (rv
!= 0 && st
->ignore_hw_compat
== 0) {
4919 pr_err("No OROM/EFI properties for %s\n", devname
);
4923 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
4925 /* retry the load if we might have raced against mdmon */
4927 struct mdstat_ent
*mdstat
= NULL
;
4928 char *name
= fd2kname(fd
);
4931 mdstat
= mdstat_by_component(name
);
4933 if (mdstat
&& mdmon_running(mdstat
->devnm
) && getpid() != mdmon_pid(mdstat
->devnm
)) {
4934 for (retry
= 0; retry
< 3; retry
++) {
4936 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
4942 free_mdstat(mdstat
);
4947 pr_err("Failed to load all information sections on %s\n", devname
);
4953 if (st
->ss
== NULL
) {
4954 st
->ss
= &super_imsm
;
4955 st
->minor_version
= 0;
4956 st
->max_devs
= IMSM_MAX_DEVICES
;
4959 /* load migration record */
4960 if (load_imsm_migr_rec(super
, NULL
) == 0) {
4961 /* Check for unsupported migration features */
4962 if (check_mpb_migr_compatibility(super
) != 0) {
4963 pr_err("Unsupported migration detected");
4965 fprintf(stderr
, " on %s\n", devname
);
4967 fprintf(stderr
, " (IMSM).\n");
4975 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
4977 if (info
->level
== 1)
4979 return info
->chunk_size
>> 9;
4982 static unsigned long long info_to_blocks_per_member(mdu_array_info_t
*info
,
4983 unsigned long long size
)
4985 if (info
->level
== 1)
4988 return (size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
4991 static void imsm_update_version_info(struct intel_super
*super
)
4993 /* update the version and attributes */
4994 struct imsm_super
*mpb
= super
->anchor
;
4996 struct imsm_dev
*dev
;
4997 struct imsm_map
*map
;
5000 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5001 dev
= get_imsm_dev(super
, i
);
5002 map
= get_imsm_map(dev
, MAP_0
);
5003 if (__le32_to_cpu(dev
->size_high
) > 0)
5004 mpb
->attributes
|= MPB_ATTRIB_2TB
;
5006 /* FIXME detect when an array spans a port multiplier */
5008 mpb
->attributes
|= MPB_ATTRIB_PM
;
5011 if (mpb
->num_raid_devs
> 1 ||
5012 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
5013 version
= MPB_VERSION_ATTRIBS
;
5014 switch (get_imsm_raid_level(map
)) {
5015 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
5016 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
5017 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
5018 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
5021 if (map
->num_members
>= 5)
5022 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
5023 else if (dev
->status
== DEV_CLONE_N_GO
)
5024 version
= MPB_VERSION_CNG
;
5025 else if (get_imsm_raid_level(map
) == 5)
5026 version
= MPB_VERSION_RAID5
;
5027 else if (map
->num_members
>= 3)
5028 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
5029 else if (get_imsm_raid_level(map
) == 1)
5030 version
= MPB_VERSION_RAID1
;
5032 version
= MPB_VERSION_RAID0
;
5034 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
5038 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
5040 struct imsm_super
*mpb
= super
->anchor
;
5041 char *reason
= NULL
;
5044 if (strlen(name
) > MAX_RAID_SERIAL_LEN
)
5045 reason
= "must be 16 characters or less";
5047 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5048 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
5050 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
5051 reason
= "already exists";
5056 if (reason
&& !quiet
)
5057 pr_err("imsm volume name %s\n", reason
);
5062 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
5063 unsigned long long size
, char *name
,
5064 char *homehost
, int *uuid
,
5065 long long data_offset
)
5067 /* We are creating a volume inside a pre-existing container.
5068 * so st->sb is already set.
5070 struct intel_super
*super
= st
->sb
;
5071 unsigned int sector_size
= super
->sector_size
;
5072 struct imsm_super
*mpb
= super
->anchor
;
5073 struct intel_dev
*dv
;
5074 struct imsm_dev
*dev
;
5075 struct imsm_vol
*vol
;
5076 struct imsm_map
*map
;
5077 int idx
= mpb
->num_raid_devs
;
5079 unsigned long long array_blocks
;
5080 size_t size_old
, size_new
;
5081 unsigned long long num_data_stripes
;
5083 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
5084 pr_err("This imsm-container already has the maximum of %d volumes\n", super
->orom
->vpa
);
5088 /* ensure the mpb is large enough for the new data */
5089 size_old
= __le32_to_cpu(mpb
->mpb_size
);
5090 size_new
= disks_to_mpb_size(info
->nr_disks
);
5091 if (size_new
> size_old
) {
5093 size_t size_round
= ROUND_UP(size_new
, sector_size
);
5095 if (posix_memalign(&mpb_new
, sector_size
, size_round
) != 0) {
5096 pr_err("could not allocate new mpb\n");
5099 if (posix_memalign(&super
->migr_rec_buf
, sector_size
,
5100 MIGR_REC_BUF_SECTORS
*sector_size
) != 0) {
5101 pr_err("could not allocate migr_rec buffer\n");
5107 memcpy(mpb_new
, mpb
, size_old
);
5110 super
->anchor
= mpb_new
;
5111 mpb
->mpb_size
= __cpu_to_le32(size_new
);
5112 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
5113 super
->len
= size_round
;
5115 super
->current_vol
= idx
;
5117 /* handle 'failed_disks' by either:
5118 * a) create dummy disk entries in the table if this the first
5119 * volume in the array. We add them here as this is the only
5120 * opportunity to add them. add_to_super_imsm_volume()
5121 * handles the non-failed disks and continues incrementing
5123 * b) validate that 'failed_disks' matches the current number
5124 * of missing disks if the container is populated
5126 if (super
->current_vol
== 0) {
5128 for (i
= 0; i
< info
->failed_disks
; i
++) {
5129 struct imsm_disk
*disk
;
5132 disk
= __get_imsm_disk(mpb
, i
);
5133 disk
->status
= CONFIGURED_DISK
| FAILED_DISK
;
5134 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
5135 snprintf((char *) disk
->serial
, MAX_RAID_SERIAL_LEN
,
5138 find_missing(super
);
5143 for (d
= super
->missing
; d
; d
= d
->next
)
5145 if (info
->failed_disks
> missing
) {
5146 pr_err("unable to add 'missing' disk to container\n");
5151 if (!check_name(super
, name
, 0))
5153 dv
= xmalloc(sizeof(*dv
));
5154 dev
= xcalloc(1, sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
5155 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
5156 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
5157 info
->layout
, info
->chunk_size
,
5159 /* round array size down to closest MB */
5160 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
5162 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
5163 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
5164 dev
->status
= (DEV_READ_COALESCING
| DEV_WRITE_COALESCING
);
5166 vol
->migr_state
= 0;
5167 set_migr_type(dev
, MIGR_INIT
);
5168 vol
->dirty
= !info
->state
;
5169 vol
->curr_migr_unit
= 0;
5170 map
= get_imsm_map(dev
, MAP_0
);
5171 set_pba_of_lba0(map
, super
->create_offset
);
5172 set_blocks_per_member(map
, info_to_blocks_per_member(info
, size
));
5173 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
5174 map
->failed_disk_num
= ~0;
5175 if (info
->level
> 0)
5176 map
->map_state
= (info
->state
? IMSM_T_STATE_NORMAL
5177 : IMSM_T_STATE_UNINITIALIZED
);
5179 map
->map_state
= info
->failed_disks
? IMSM_T_STATE_FAILED
:
5180 IMSM_T_STATE_NORMAL
;
5183 if (info
->level
== 1 && info
->raid_disks
> 2) {
5186 pr_err("imsm does not support more than 2 disksin a raid1 volume\n");
5190 map
->raid_level
= info
->level
;
5191 if (info
->level
== 10) {
5192 map
->raid_level
= 1;
5193 map
->num_domains
= info
->raid_disks
/ 2;
5194 } else if (info
->level
== 1)
5195 map
->num_domains
= info
->raid_disks
;
5197 map
->num_domains
= 1;
5199 /* info->size is only int so use the 'size' parameter instead */
5200 num_data_stripes
= (size
* 2) / info_to_blocks_per_strip(info
);
5201 num_data_stripes
/= map
->num_domains
;
5202 set_num_data_stripes(map
, num_data_stripes
);
5204 map
->num_members
= info
->raid_disks
;
5205 for (i
= 0; i
< map
->num_members
; i
++) {
5206 /* initialized in add_to_super */
5207 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
5209 mpb
->num_raid_devs
++;
5212 dv
->index
= super
->current_vol
;
5213 dv
->next
= super
->devlist
;
5214 super
->devlist
= dv
;
5216 imsm_update_version_info(super
);
5221 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
5222 unsigned long long size
, char *name
,
5223 char *homehost
, int *uuid
,
5224 unsigned long long data_offset
)
5226 /* This is primarily called by Create when creating a new array.
5227 * We will then get add_to_super called for each component, and then
5228 * write_init_super called to write it out to each device.
5229 * For IMSM, Create can create on fresh devices or on a pre-existing
5231 * To create on a pre-existing array a different method will be called.
5232 * This one is just for fresh drives.
5234 struct intel_super
*super
;
5235 struct imsm_super
*mpb
;
5239 if (data_offset
!= INVALID_SECTORS
) {
5240 pr_err("data-offset not supported by imsm\n");
5245 return init_super_imsm_volume(st
, info
, size
, name
, homehost
, uuid
,
5249 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
5251 mpb_size
= MAX_SECTOR_SIZE
;
5253 super
= alloc_super();
5255 posix_memalign(&super
->buf
, MAX_SECTOR_SIZE
, mpb_size
) != 0) {
5260 pr_err("could not allocate superblock\n");
5263 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
5264 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
) != 0) {
5265 pr_err("could not allocate migr_rec buffer\n");
5270 memset(super
->buf
, 0, mpb_size
);
5272 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5276 /* zeroing superblock */
5280 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5282 version
= (char *) mpb
->sig
;
5283 strcpy(version
, MPB_SIGNATURE
);
5284 version
+= strlen(MPB_SIGNATURE
);
5285 strcpy(version
, MPB_VERSION_RAID0
);
5291 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
5292 int fd
, char *devname
)
5294 struct intel_super
*super
= st
->sb
;
5295 struct imsm_super
*mpb
= super
->anchor
;
5296 struct imsm_disk
*_disk
;
5297 struct imsm_dev
*dev
;
5298 struct imsm_map
*map
;
5302 dev
= get_imsm_dev(super
, super
->current_vol
);
5303 map
= get_imsm_map(dev
, MAP_0
);
5305 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
5306 pr_err("%s: Cannot add spare devices to IMSM volume\n",
5312 /* we're doing autolayout so grab the pre-marked (in
5313 * validate_geometry) raid_disk
5315 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5316 if (dl
->raiddisk
== dk
->raid_disk
)
5319 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5320 if (dl
->major
== dk
->major
&&
5321 dl
->minor
== dk
->minor
)
5326 pr_err("%s is not a member of the same container\n", devname
);
5330 /* add a pristine spare to the metadata */
5331 if (dl
->index
< 0) {
5332 dl
->index
= super
->anchor
->num_disks
;
5333 super
->anchor
->num_disks
++;
5335 /* Check the device has not already been added */
5336 slot
= get_imsm_disk_slot(map
, dl
->index
);
5338 (get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
) & IMSM_ORD_REBUILD
) == 0) {
5339 pr_err("%s has been included in this array twice\n",
5343 set_imsm_ord_tbl_ent(map
, dk
->raid_disk
, dl
->index
);
5344 dl
->disk
.status
= CONFIGURED_DISK
;
5346 /* update size of 'missing' disks to be at least as large as the
5347 * largest acitve member (we only have dummy missing disks when
5348 * creating the first volume)
5350 if (super
->current_vol
== 0) {
5351 for (df
= super
->missing
; df
; df
= df
->next
) {
5352 if (total_blocks(&dl
->disk
) > total_blocks(&df
->disk
))
5353 set_total_blocks(&df
->disk
, total_blocks(&dl
->disk
));
5354 _disk
= __get_imsm_disk(mpb
, df
->index
);
5359 /* refresh unset/failed slots to point to valid 'missing' entries */
5360 for (df
= super
->missing
; df
; df
= df
->next
)
5361 for (slot
= 0; slot
< mpb
->num_disks
; slot
++) {
5362 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
5364 if ((ord
& IMSM_ORD_REBUILD
) == 0)
5366 set_imsm_ord_tbl_ent(map
, slot
, df
->index
| IMSM_ORD_REBUILD
);
5367 if (is_gen_migration(dev
)) {
5368 struct imsm_map
*map2
= get_imsm_map(dev
,
5370 int slot2
= get_imsm_disk_slot(map2
, df
->index
);
5371 if (slot2
< map2
->num_members
&& slot2
>= 0) {
5372 __u32 ord2
= get_imsm_ord_tbl_ent(dev
,
5375 if ((unsigned)df
->index
==
5377 set_imsm_ord_tbl_ent(map2
,
5383 dprintf("set slot:%d to missing disk:%d\n", slot
, df
->index
);
5387 /* if we are creating the first raid device update the family number */
5388 if (super
->current_vol
== 0) {
5390 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
5392 _disk
= __get_imsm_disk(mpb
, dl
->index
);
5393 if (!_dev
|| !_disk
) {
5394 pr_err("BUG mpb setup error\n");
5400 sum
+= __gen_imsm_checksum(mpb
);
5401 mpb
->family_num
= __cpu_to_le32(sum
);
5402 mpb
->orig_family_num
= mpb
->family_num
;
5404 super
->current_disk
= dl
;
5409 * Function marks disk as spare and restores disk serial
5410 * in case it was previously marked as failed by takeover operation
5412 * -1 : critical error
5413 * 0 : disk is marked as spare but serial is not set
5416 int mark_spare(struct dl
*disk
)
5418 __u8 serial
[MAX_RAID_SERIAL_LEN
];
5425 if (!imsm_read_serial(disk
->fd
, NULL
, serial
)) {
5426 /* Restore disk serial number, because takeover marks disk
5427 * as failed and adds to serial ':0' before it becomes
5430 serialcpy(disk
->serial
, serial
);
5431 serialcpy(disk
->disk
.serial
, serial
);
5434 disk
->disk
.status
= SPARE_DISK
;
5440 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
5441 int fd
, char *devname
,
5442 unsigned long long data_offset
)
5444 struct intel_super
*super
= st
->sb
;
5446 unsigned long long size
;
5447 unsigned int member_sector_size
;
5452 /* If we are on an RAID enabled platform check that the disk is
5453 * attached to the raid controller.
5454 * We do not need to test disks attachment for container based additions,
5455 * they shall be already tested when container was created/assembled.
5457 rv
= find_intel_hba_capability(fd
, super
, devname
);
5458 /* no orom/efi or non-intel hba of the disk */
5460 dprintf("capability: %p fd: %d ret: %d\n",
5461 super
->orom
, fd
, rv
);
5465 if (super
->current_vol
>= 0)
5466 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
5469 dd
= xcalloc(sizeof(*dd
), 1);
5470 dd
->major
= major(stb
.st_rdev
);
5471 dd
->minor
= minor(stb
.st_rdev
);
5472 dd
->devname
= devname
? xstrdup(devname
) : NULL
;
5475 dd
->action
= DISK_ADD
;
5476 rv
= imsm_read_serial(fd
, devname
, dd
->serial
);
5478 pr_err("failed to retrieve scsi serial, aborting\n");
5484 if (super
->hba
&& ((super
->hba
->type
== SYS_DEV_NVME
) ||
5485 (super
->hba
->type
== SYS_DEV_VMD
))) {
5487 char *devpath
= diskfd_to_devpath(fd
);
5488 char controller_path
[PATH_MAX
];
5491 pr_err("failed to get devpath, aborting\n");
5498 snprintf(controller_path
, PATH_MAX
-1, "%s/device", devpath
);
5501 if (devpath_to_vendor(controller_path
) == 0x8086) {
5503 * If Intel's NVMe drive has serial ended with
5504 * "-A","-B","-1" or "-2" it means that this is "x8"
5505 * device (double drive on single PCIe card).
5506 * User should be warned about potential data loss.
5508 for (i
= MAX_RAID_SERIAL_LEN
-1; i
> 0; i
--) {
5509 /* Skip empty character at the end */
5510 if (dd
->serial
[i
] == 0)
5513 if (((dd
->serial
[i
] == 'A') ||
5514 (dd
->serial
[i
] == 'B') ||
5515 (dd
->serial
[i
] == '1') ||
5516 (dd
->serial
[i
] == '2')) &&
5517 (dd
->serial
[i
-1] == '-'))
5518 pr_err("\tThe action you are about to take may put your data at risk.\n"
5519 "\tPlease note that x8 devices may consist of two separate x4 devices "
5520 "located on a single PCIe port.\n"
5521 "\tRAID 0 is the only supported configuration for this type of x8 device.\n");
5527 get_dev_size(fd
, NULL
, &size
);
5528 get_dev_sector_size(fd
, NULL
, &member_sector_size
);
5530 if (super
->sector_size
== 0) {
5531 /* this a first device, so sector_size is not set yet */
5532 super
->sector_size
= member_sector_size
;
5533 } else if (member_sector_size
!= super
->sector_size
) {
5534 pr_err("Mixing between different sector size is forbidden, aborting...\n");
5541 /* clear migr_rec when adding disk to container */
5542 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SECTORS
*super
->sector_size
);
5543 if (lseek64(fd
, size
- MIGR_REC_SECTOR_POSITION
*super
->sector_size
,
5545 if (write(fd
, super
->migr_rec_buf
,
5546 MIGR_REC_BUF_SECTORS
*super
->sector_size
) !=
5547 MIGR_REC_BUF_SECTORS
*super
->sector_size
)
5548 perror("Write migr_rec failed");
5552 serialcpy(dd
->disk
.serial
, dd
->serial
);
5553 set_total_blocks(&dd
->disk
, size
);
5554 if (__le32_to_cpu(dd
->disk
.total_blocks_hi
) > 0) {
5555 struct imsm_super
*mpb
= super
->anchor
;
5556 mpb
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5559 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
5560 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
5562 dd
->disk
.scsi_id
= __cpu_to_le32(0);
5564 if (st
->update_tail
) {
5565 dd
->next
= super
->disk_mgmt_list
;
5566 super
->disk_mgmt_list
= dd
;
5568 dd
->next
= super
->disks
;
5570 super
->updates_pending
++;
5576 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
5578 struct intel_super
*super
= st
->sb
;
5581 /* remove from super works only in mdmon - for communication
5582 * manager - monitor. Check if communication memory buffer
5585 if (!st
->update_tail
) {
5586 pr_err("shall be used in mdmon context only\n");
5589 dd
= xcalloc(1, sizeof(*dd
));
5590 dd
->major
= dk
->major
;
5591 dd
->minor
= dk
->minor
;
5594 dd
->action
= DISK_REMOVE
;
5596 dd
->next
= super
->disk_mgmt_list
;
5597 super
->disk_mgmt_list
= dd
;
5602 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
5605 char buf
[MAX_SECTOR_SIZE
];
5606 struct imsm_super anchor
;
5607 } spare_record
__attribute__ ((aligned(MAX_SECTOR_SIZE
)));
5609 /* spare records have their own family number and do not have any defined raid
5612 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
5614 struct imsm_super
*mpb
= super
->anchor
;
5615 struct imsm_super
*spare
= &spare_record
.anchor
;
5619 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
));
5620 spare
->generation_num
= __cpu_to_le32(1UL);
5621 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5622 spare
->num_disks
= 1;
5623 spare
->num_raid_devs
= 0;
5624 spare
->cache_size
= mpb
->cache_size
;
5625 spare
->pwr_cycle_count
= __cpu_to_le32(1);
5627 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
5628 MPB_SIGNATURE MPB_VERSION_RAID0
);
5630 for (d
= super
->disks
; d
; d
= d
->next
) {
5634 spare
->disk
[0] = d
->disk
;
5635 if (__le32_to_cpu(d
->disk
.total_blocks_hi
) > 0)
5636 spare
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5638 if (super
->sector_size
== 4096)
5639 convert_to_4k_imsm_disk(&spare
->disk
[0]);
5641 sum
= __gen_imsm_checksum(spare
);
5642 spare
->family_num
= __cpu_to_le32(sum
);
5643 spare
->orig_family_num
= 0;
5644 sum
= __gen_imsm_checksum(spare
);
5645 spare
->check_sum
= __cpu_to_le32(sum
);
5647 if (store_imsm_mpb(d
->fd
, spare
)) {
5648 pr_err("failed for device %d:%d %s\n",
5649 d
->major
, d
->minor
, strerror(errno
));
5661 static int write_super_imsm(struct supertype
*st
, int doclose
)
5663 struct intel_super
*super
= st
->sb
;
5664 unsigned int sector_size
= super
->sector_size
;
5665 struct imsm_super
*mpb
= super
->anchor
;
5671 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
5673 int clear_migration_record
= 1;
5676 /* 'generation' is incremented everytime the metadata is written */
5677 generation
= __le32_to_cpu(mpb
->generation_num
);
5679 mpb
->generation_num
= __cpu_to_le32(generation
);
5681 /* fix up cases where previous mdadm releases failed to set
5684 if (mpb
->orig_family_num
== 0)
5685 mpb
->orig_family_num
= mpb
->family_num
;
5687 for (d
= super
->disks
; d
; d
= d
->next
) {
5691 mpb
->disk
[d
->index
] = d
->disk
;
5695 for (d
= super
->missing
; d
; d
= d
->next
) {
5696 mpb
->disk
[d
->index
] = d
->disk
;
5699 mpb
->num_disks
= num_disks
;
5700 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
5702 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5703 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
5704 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
5706 imsm_copy_dev(dev
, dev2
);
5707 mpb_size
+= sizeof_imsm_dev(dev
, 0);
5709 if (is_gen_migration(dev2
))
5710 clear_migration_record
= 0;
5713 bbm_log_size
= get_imsm_bbm_log_size(super
->bbm_log
);
5716 memcpy((void *)mpb
+ mpb_size
, super
->bbm_log
, bbm_log_size
);
5717 mpb
->attributes
|= MPB_ATTRIB_BBM
;
5719 mpb
->attributes
&= ~MPB_ATTRIB_BBM
;
5721 super
->anchor
->bbm_log_size
= __cpu_to_le32(bbm_log_size
);
5722 mpb_size
+= bbm_log_size
;
5723 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5726 assert(super
->len
== 0 || mpb_size
<= super
->len
);
5729 /* recalculate checksum */
5730 sum
= __gen_imsm_checksum(mpb
);
5731 mpb
->check_sum
= __cpu_to_le32(sum
);
5733 if (super
->clean_migration_record_by_mdmon
) {
5734 clear_migration_record
= 1;
5735 super
->clean_migration_record_by_mdmon
= 0;
5737 if (clear_migration_record
)
5738 memset(super
->migr_rec_buf
, 0,
5739 MIGR_REC_BUF_SECTORS
*sector_size
);
5741 if (sector_size
== 4096)
5742 convert_to_4k(super
);
5744 /* write the mpb for disks that compose raid devices */
5745 for (d
= super
->disks
; d
; d
= d
->next
) {
5746 if (d
->index
< 0 || is_failed(&d
->disk
))
5749 if (clear_migration_record
) {
5750 unsigned long long dsize
;
5752 get_dev_size(d
->fd
, NULL
, &dsize
);
5753 if (lseek64(d
->fd
, dsize
- sector_size
,
5755 if (write(d
->fd
, super
->migr_rec_buf
,
5756 MIGR_REC_BUF_SECTORS
*sector_size
) !=
5757 MIGR_REC_BUF_SECTORS
*sector_size
)
5758 perror("Write migr_rec failed");
5762 if (store_imsm_mpb(d
->fd
, mpb
))
5764 "failed for device %d:%d (fd: %d)%s\n",
5766 d
->fd
, strerror(errno
));
5775 return write_super_imsm_spares(super
, doclose
);
5780 static int create_array(struct supertype
*st
, int dev_idx
)
5783 struct imsm_update_create_array
*u
;
5784 struct intel_super
*super
= st
->sb
;
5785 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
5786 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
5787 struct disk_info
*inf
;
5788 struct imsm_disk
*disk
;
5791 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
5792 sizeof(*inf
) * map
->num_members
;
5794 u
->type
= update_create_array
;
5795 u
->dev_idx
= dev_idx
;
5796 imsm_copy_dev(&u
->dev
, dev
);
5797 inf
= get_disk_info(u
);
5798 for (i
= 0; i
< map
->num_members
; i
++) {
5799 int idx
= get_imsm_disk_idx(dev
, i
, MAP_X
);
5801 disk
= get_imsm_disk(super
, idx
);
5803 disk
= get_imsm_missing(super
, idx
);
5804 serialcpy(inf
[i
].serial
, disk
->serial
);
5806 append_metadata_update(st
, u
, len
);
5811 static int mgmt_disk(struct supertype
*st
)
5813 struct intel_super
*super
= st
->sb
;
5815 struct imsm_update_add_remove_disk
*u
;
5817 if (!super
->disk_mgmt_list
)
5822 u
->type
= update_add_remove_disk
;
5823 append_metadata_update(st
, u
, len
);
5828 static int write_init_super_imsm(struct supertype
*st
)
5830 struct intel_super
*super
= st
->sb
;
5831 int current_vol
= super
->current_vol
;
5833 /* we are done with current_vol reset it to point st at the container */
5834 super
->current_vol
= -1;
5836 if (st
->update_tail
) {
5837 /* queue the recently created array / added disk
5838 * as a metadata update */
5841 /* determine if we are creating a volume or adding a disk */
5842 if (current_vol
< 0) {
5843 /* in the mgmt (add/remove) disk case we are running
5844 * in mdmon context, so don't close fd's
5846 return mgmt_disk(st
);
5848 rv
= create_array(st
, current_vol
);
5853 for (d
= super
->disks
; d
; d
= d
->next
)
5854 Kill(d
->devname
, NULL
, 0, -1, 1);
5855 return write_super_imsm(st
, 1);
5860 static int store_super_imsm(struct supertype
*st
, int fd
)
5862 struct intel_super
*super
= st
->sb
;
5863 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
5869 if (super
->sector_size
== 4096)
5870 convert_to_4k(super
);
5871 return store_imsm_mpb(fd
, mpb
);
5878 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
5879 int layout
, int raiddisks
, int chunk
,
5880 unsigned long long size
,
5881 unsigned long long data_offset
,
5883 unsigned long long *freesize
,
5887 unsigned long long ldsize
;
5888 struct intel_super
*super
;
5891 if (level
!= LEVEL_CONTAINER
)
5896 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
5899 pr_err("imsm: Cannot open %s: %s\n",
5900 dev
, strerror(errno
));
5903 if (!get_dev_size(fd
, dev
, &ldsize
)) {
5908 /* capabilities retrieve could be possible
5909 * note that there is no fd for the disks in array.
5911 super
= alloc_super();
5916 if (!get_dev_sector_size(fd
, NULL
, &super
->sector_size
)) {
5922 rv
= find_intel_hba_capability(fd
, super
, verbose
> 0 ? dev
: NULL
);
5926 fd2devname(fd
, str
);
5927 dprintf("fd: %d %s orom: %p rv: %d raiddisk: %d\n",
5928 fd
, str
, super
->orom
, rv
, raiddisks
);
5930 /* no orom/efi or non-intel hba of the disk */
5937 if (raiddisks
> super
->orom
->tds
) {
5939 pr_err("%d exceeds maximum number of platform supported disks: %d\n",
5940 raiddisks
, super
->orom
->tds
);
5944 if ((super
->orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) == 0 &&
5945 (ldsize
>> 9) >> 32 > 0) {
5947 pr_err("%s exceeds maximum platform supported size\n", dev
);
5953 *freesize
= avail_size_imsm(st
, ldsize
>> 9, data_offset
);
5959 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
5961 const unsigned long long base_start
= e
[*idx
].start
;
5962 unsigned long long end
= base_start
+ e
[*idx
].size
;
5965 if (base_start
== end
)
5969 for (i
= *idx
; i
< num_extents
; i
++) {
5970 /* extend overlapping extents */
5971 if (e
[i
].start
>= base_start
&&
5972 e
[i
].start
<= end
) {
5975 if (e
[i
].start
+ e
[i
].size
> end
)
5976 end
= e
[i
].start
+ e
[i
].size
;
5977 } else if (e
[i
].start
> end
) {
5983 return end
- base_start
;
5986 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
5988 /* build a composite disk with all known extents and generate a new
5989 * 'maxsize' given the "all disks in an array must share a common start
5990 * offset" constraint
5992 struct extent
*e
= xcalloc(sum_extents
, sizeof(*e
));
5996 unsigned long long pos
;
5997 unsigned long long start
= 0;
5998 unsigned long long maxsize
;
5999 unsigned long reserve
;
6001 /* coalesce and sort all extents. also, check to see if we need to
6002 * reserve space between member arrays
6005 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6008 for (i
= 0; i
< dl
->extent_cnt
; i
++)
6011 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
6016 while (i
< sum_extents
) {
6017 e
[j
].start
= e
[i
].start
;
6018 e
[j
].size
= find_size(e
, &i
, sum_extents
);
6020 if (e
[j
-1].size
== 0)
6029 unsigned long long esize
;
6031 esize
= e
[i
].start
- pos
;
6032 if (esize
>= maxsize
) {
6037 pos
= e
[i
].start
+ e
[i
].size
;
6039 } while (e
[i
-1].size
);
6045 /* FIXME assumes volume at offset 0 is the first volume in a
6048 if (start_extent
> 0)
6049 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
6053 if (maxsize
< reserve
)
6056 super
->create_offset
= ~((unsigned long long) 0);
6057 if (start
+ reserve
> super
->create_offset
)
6058 return 0; /* start overflows create_offset */
6059 super
->create_offset
= start
+ reserve
;
6061 return maxsize
- reserve
;
6064 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
6066 if (level
< 0 || level
== 6 || level
== 4)
6069 /* if we have an orom prevent invalid raid levels */
6072 case 0: return imsm_orom_has_raid0(orom
);
6075 return imsm_orom_has_raid1e(orom
);
6076 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
6077 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
6078 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
6081 return 1; /* not on an Intel RAID platform so anything goes */
6087 active_arrays_by_format(char *name
, char* hba
, struct md_list
**devlist
,
6088 int dpa
, int verbose
)
6090 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
6091 struct mdstat_ent
*memb
;
6097 for (memb
= mdstat
; memb
; memb
= memb
->next
) {
6098 if (memb
->metadata_version
&&
6099 (strncmp(memb
->metadata_version
, "external:", 9) == 0) &&
6100 (strcmp(&memb
->metadata_version
[9], name
) == 0) &&
6101 !is_subarray(memb
->metadata_version
+9) &&
6103 struct dev_member
*dev
= memb
->members
;
6105 while(dev
&& (fd
< 0)) {
6106 char *path
= xmalloc(strlen(dev
->name
) + strlen("/dev/") + 1);
6107 num
= sprintf(path
, "%s%s", "/dev/", dev
->name
);
6109 fd
= open(path
, O_RDONLY
, 0);
6110 if (num
<= 0 || fd
< 0) {
6111 pr_vrb("Cannot open %s: %s\n",
6112 dev
->name
, strerror(errno
));
6118 if (fd
>= 0 && disk_attached_to_hba(fd
, hba
)) {
6119 struct mdstat_ent
*vol
;
6120 for (vol
= mdstat
; vol
; vol
= vol
->next
) {
6121 if (vol
->active
> 0 &&
6122 vol
->metadata_version
&&
6123 is_container_member(vol
, memb
->devnm
)) {
6128 if (*devlist
&& (found
< dpa
)) {
6129 dv
= xcalloc(1, sizeof(*dv
));
6130 dv
->devname
= xmalloc(strlen(memb
->devnm
) + strlen("/dev/") + 1);
6131 sprintf(dv
->devname
, "%s%s", "/dev/", memb
->devnm
);
6134 dv
->next
= *devlist
;
6142 free_mdstat(mdstat
);
6147 static struct md_list
*
6148 get_loop_devices(void)
6151 struct md_list
*devlist
= NULL
;
6154 for(i
= 0; i
< 12; i
++) {
6155 dv
= xcalloc(1, sizeof(*dv
));
6156 dv
->devname
= xmalloc(40);
6157 sprintf(dv
->devname
, "/dev/loop%d", i
);
6165 static struct md_list
*
6166 get_devices(const char *hba_path
)
6168 struct md_list
*devlist
= NULL
;
6175 devlist
= get_loop_devices();
6178 /* scroll through /sys/dev/block looking for devices attached to
6181 dir
= opendir("/sys/dev/block");
6182 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
6187 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
6189 path
= devt_to_devpath(makedev(major
, minor
));
6192 if (!path_attached_to_hba(path
, hba_path
)) {
6199 fd
= dev_open(ent
->d_name
, O_RDONLY
);
6201 fd2devname(fd
, buf
);
6204 pr_err("cannot open device: %s\n",
6209 dv
= xcalloc(1, sizeof(*dv
));
6210 dv
->devname
= xstrdup(buf
);
6217 devlist
= devlist
->next
;
6227 count_volumes_list(struct md_list
*devlist
, char *homehost
,
6228 int verbose
, int *found
)
6230 struct md_list
*tmpdev
;
6232 struct supertype
*st
;
6234 /* first walk the list of devices to find a consistent set
6235 * that match the criterea, if that is possible.
6236 * We flag the ones we like with 'used'.
6239 st
= match_metadata_desc_imsm("imsm");
6241 pr_vrb("cannot allocate memory for imsm supertype\n");
6245 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
6246 char *devname
= tmpdev
->devname
;
6248 struct supertype
*tst
;
6250 if (tmpdev
->used
> 1)
6252 tst
= dup_super(st
);
6254 pr_vrb("cannot allocate memory for imsm supertype\n");
6257 tmpdev
->container
= 0;
6258 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
6260 dprintf("cannot open device %s: %s\n",
6261 devname
, strerror(errno
));
6263 } else if (fstat(dfd
, &stb
)< 0) {
6265 dprintf("fstat failed for %s: %s\n",
6266 devname
, strerror(errno
));
6268 } else if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
6269 dprintf("%s is not a block device.\n",
6272 } else if (must_be_container(dfd
)) {
6273 struct supertype
*cst
;
6274 cst
= super_by_fd(dfd
, NULL
);
6276 dprintf("cannot recognize container type %s\n",
6279 } else if (tst
->ss
!= st
->ss
) {
6280 dprintf("non-imsm container - ignore it: %s\n",
6283 } else if (!tst
->ss
->load_container
||
6284 tst
->ss
->load_container(tst
, dfd
, NULL
))
6287 tmpdev
->container
= 1;
6290 cst
->ss
->free_super(cst
);
6292 tmpdev
->st_rdev
= stb
.st_rdev
;
6293 if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
6294 dprintf("no RAID superblock on %s\n",
6297 } else if (tst
->ss
->compare_super
== NULL
) {
6298 dprintf("Cannot assemble %s metadata on %s\n",
6299 tst
->ss
->name
, devname
);
6305 if (tmpdev
->used
== 2 || tmpdev
->used
== 4) {
6306 /* Ignore unrecognised devices during auto-assembly */
6311 tst
->ss
->getinfo_super(tst
, &info
, NULL
);
6313 if (st
->minor_version
== -1)
6314 st
->minor_version
= tst
->minor_version
;
6316 if (memcmp(info
.uuid
, uuid_zero
,
6317 sizeof(int[4])) == 0) {
6318 /* this is a floating spare. It cannot define
6319 * an array unless there are no more arrays of
6320 * this type to be found. It can be included
6321 * in an array of this type though.
6327 if (st
->ss
!= tst
->ss
||
6328 st
->minor_version
!= tst
->minor_version
||
6329 st
->ss
->compare_super(st
, tst
) != 0) {
6330 /* Some mismatch. If exactly one array matches this host,
6331 * we can resolve on that one.
6332 * Or, if we are auto assembling, we just ignore the second
6335 dprintf("superblock on %s doesn't match others - assembly aborted\n",
6341 dprintf("found: devname: %s\n", devname
);
6345 tst
->ss
->free_super(tst
);
6349 if ((err
= load_super_imsm_all(st
, -1, &st
->sb
, NULL
, devlist
, 0)) == 0) {
6350 struct mdinfo
*iter
, *head
= st
->ss
->container_content(st
, NULL
);
6351 for (iter
= head
; iter
; iter
= iter
->next
) {
6352 dprintf("content->text_version: %s vol\n",
6353 iter
->text_version
);
6354 if (iter
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
)) {
6355 /* do not assemble arrays with unsupported
6357 dprintf("Cannot activate member %s.\n",
6358 iter
->text_version
);
6365 dprintf("No valid super block on device list: err: %d %p\n",
6369 dprintf("no more devices to examine\n");
6372 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
6373 if (tmpdev
->used
== 1 && tmpdev
->found
) {
6375 if (count
< tmpdev
->found
)
6378 count
-= tmpdev
->found
;
6381 if (tmpdev
->used
== 1)
6386 st
->ss
->free_super(st
);
6391 count_volumes(struct intel_hba
*hba
, int dpa
, int verbose
)
6393 struct sys_dev
*idev
, *intel_devices
= find_intel_devices();
6395 const struct orom_entry
*entry
;
6396 struct devid_list
*dv
, *devid_list
;
6398 if (!hba
|| !hba
->path
)
6401 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
6402 if (strstr(idev
->path
, hba
->path
))
6406 if (!idev
|| !idev
->dev_id
)
6409 entry
= get_orom_entry_by_device_id(idev
->dev_id
);
6411 if (!entry
|| !entry
->devid_list
)
6414 devid_list
= entry
->devid_list
;
6415 for (dv
= devid_list
; dv
; dv
= dv
->next
) {
6416 struct md_list
*devlist
;
6417 struct sys_dev
*device
= device_by_id(dv
->devid
);
6422 hba_path
= device
->path
;
6426 devlist
= get_devices(hba_path
);
6427 /* if no intel devices return zero volumes */
6428 if (devlist
== NULL
)
6431 count
+= active_arrays_by_format("imsm", hba_path
, &devlist
, dpa
, verbose
);
6432 dprintf("path: %s active arrays: %d\n", hba_path
, count
);
6433 if (devlist
== NULL
)
6437 count
+= count_volumes_list(devlist
,
6441 dprintf("found %d count: %d\n", found
, count
);
6444 dprintf("path: %s total number of volumes: %d\n", hba_path
, count
);
6447 struct md_list
*dv
= devlist
;
6448 devlist
= devlist
->next
;
6456 static int imsm_default_chunk(const struct imsm_orom
*orom
)
6458 /* up to 512 if the plaform supports it, otherwise the platform max.
6459 * 128 if no platform detected
6461 int fs
= max(7, orom
? fls(orom
->sss
) : 0);
6463 return min(512, (1 << fs
));
6467 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
6468 int raiddisks
, int *chunk
, unsigned long long size
, int verbose
)
6470 /* check/set platform and metadata limits/defaults */
6471 if (super
->orom
&& raiddisks
> super
->orom
->dpa
) {
6472 pr_vrb("platform supports a maximum of %d disks per array\n",
6477 /* capabilities of OROM tested - copied from validate_geometry_imsm_volume */
6478 if (!is_raid_level_supported(super
->orom
, level
, raiddisks
)) {
6479 pr_vrb("platform does not support raid%d with %d disk%s\n",
6480 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
6484 if (*chunk
== 0 || *chunk
== UnSet
)
6485 *chunk
= imsm_default_chunk(super
->orom
);
6487 if (super
->orom
&& !imsm_orom_has_chunk(super
->orom
, *chunk
)) {
6488 pr_vrb("platform does not support a chunk size of: %d\n", *chunk
);
6492 if (layout
!= imsm_level_to_layout(level
)) {
6494 pr_vrb("imsm raid 5 only supports the left-asymmetric layout\n");
6495 else if (level
== 10)
6496 pr_vrb("imsm raid 10 only supports the n2 layout\n");
6498 pr_vrb("imsm unknown layout %#x for this raid level %d\n",
6503 if (super
->orom
&& (super
->orom
->attr
& IMSM_OROM_ATTR_2TB
) == 0 &&
6504 (calc_array_size(level
, raiddisks
, layout
, *chunk
, size
) >> 32) > 0) {
6505 pr_vrb("platform does not support a volume size over 2TB\n");
6512 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
6513 * FIX ME add ahci details
6515 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
6516 int layout
, int raiddisks
, int *chunk
,
6517 unsigned long long size
,
6518 unsigned long long data_offset
,
6520 unsigned long long *freesize
,
6524 struct intel_super
*super
= st
->sb
;
6525 struct imsm_super
*mpb
;
6527 unsigned long long pos
= 0;
6528 unsigned long long maxsize
;
6532 /* We must have the container info already read in. */
6536 mpb
= super
->anchor
;
6538 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, size
, verbose
)) {
6539 pr_err("RAID gemetry validation failed. Cannot proceed with the action(s).\n");
6543 /* General test: make sure there is space for
6544 * 'raiddisks' device extents of size 'size' at a given
6547 unsigned long long minsize
= size
;
6548 unsigned long long start_offset
= MaxSector
;
6551 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
6552 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6557 e
= get_extents(super
, dl
);
6560 unsigned long long esize
;
6561 esize
= e
[i
].start
- pos
;
6562 if (esize
>= minsize
)
6564 if (found
&& start_offset
== MaxSector
) {
6567 } else if (found
&& pos
!= start_offset
) {
6571 pos
= e
[i
].start
+ e
[i
].size
;
6573 } while (e
[i
-1].size
);
6578 if (dcnt
< raiddisks
) {
6580 pr_err("imsm: Not enough devices with space for this array (%d < %d)\n",
6587 /* This device must be a member of the set */
6588 if (stat(dev
, &stb
) < 0)
6590 if ((S_IFMT
& stb
.st_mode
) != S_IFBLK
)
6592 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6593 if (dl
->major
== (int)major(stb
.st_rdev
) &&
6594 dl
->minor
== (int)minor(stb
.st_rdev
))
6599 pr_err("%s is not in the same imsm set\n", dev
);
6601 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
6602 /* If a volume is present then the current creation attempt
6603 * cannot incorporate new spares because the orom may not
6604 * understand this configuration (all member disks must be
6605 * members of each array in the container).
6607 pr_err("%s is a spare and a volume is already defined for this container\n", dev
);
6608 pr_err("The option-rom requires all member disks to be a member of all volumes\n");
6610 } else if (super
->orom
&& mpb
->num_raid_devs
> 0 &&
6611 mpb
->num_disks
!= raiddisks
) {
6612 pr_err("The option-rom requires all member disks to be a member of all volumes\n");
6616 /* retrieve the largest free space block */
6617 e
= get_extents(super
, dl
);
6622 unsigned long long esize
;
6624 esize
= e
[i
].start
- pos
;
6625 if (esize
>= maxsize
)
6627 pos
= e
[i
].start
+ e
[i
].size
;
6629 } while (e
[i
-1].size
);
6634 pr_err("unable to determine free space for: %s\n",
6638 if (maxsize
< size
) {
6640 pr_err("%s not enough space (%llu < %llu)\n",
6641 dev
, maxsize
, size
);
6645 /* count total number of extents for merge */
6647 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6649 i
+= dl
->extent_cnt
;
6651 maxsize
= merge_extents(super
, i
);
6653 if (!check_env("IMSM_NO_PLATFORM") &&
6654 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
6655 pr_err("attempting to create a second volume with size less then remaining space. Aborting...\n");
6659 if (maxsize
< size
|| maxsize
== 0) {
6662 pr_err("no free space left on device. Aborting...\n");
6664 pr_err("not enough space to create volume of given size (%llu < %llu). Aborting...\n",
6670 *freesize
= maxsize
;
6673 int count
= count_volumes(super
->hba
,
6674 super
->orom
->dpa
, verbose
);
6675 if (super
->orom
->vphba
<= count
) {
6676 pr_vrb("platform does not support more than %d raid volumes.\n",
6677 super
->orom
->vphba
);
6684 static int imsm_get_free_size(struct supertype
*st
, int raiddisks
,
6685 unsigned long long size
, int chunk
,
6686 unsigned long long *freesize
)
6688 struct intel_super
*super
= st
->sb
;
6689 struct imsm_super
*mpb
= super
->anchor
;
6694 unsigned long long maxsize
;
6695 unsigned long long minsize
;
6699 /* find the largest common start free region of the possible disks */
6703 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6709 /* don't activate new spares if we are orom constrained
6710 * and there is already a volume active in the container
6712 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
6715 e
= get_extents(super
, dl
);
6718 for (i
= 1; e
[i
-1].size
; i
++)
6726 maxsize
= merge_extents(super
, extent_cnt
);
6730 minsize
= chunk
* 2;
6732 if (cnt
< raiddisks
||
6733 (super
->orom
&& used
&& used
!= raiddisks
) ||
6734 maxsize
< minsize
||
6736 pr_err("not enough devices with space to create array.\n");
6737 return 0; /* No enough free spaces large enough */
6748 if (!check_env("IMSM_NO_PLATFORM") &&
6749 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
6750 pr_err("attempting to create a second volume with size less then remaining space. Aborting...\n");
6754 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6756 dl
->raiddisk
= cnt
++;
6760 dprintf("imsm: imsm_get_free_size() returns : %llu\n", size
);
6765 static int reserve_space(struct supertype
*st
, int raiddisks
,
6766 unsigned long long size
, int chunk
,
6767 unsigned long long *freesize
)
6769 struct intel_super
*super
= st
->sb
;
6774 rv
= imsm_get_free_size(st
, raiddisks
, size
, chunk
, freesize
);
6777 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6779 dl
->raiddisk
= cnt
++;
6786 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
6787 int raiddisks
, int *chunk
, unsigned long long size
,
6788 unsigned long long data_offset
,
6789 char *dev
, unsigned long long *freesize
,
6797 * if given unused devices create a container
6798 * if given given devices in a container create a member volume
6800 if (level
== LEVEL_CONTAINER
) {
6801 /* Must be a fresh device to add to a container */
6802 return validate_geometry_imsm_container(st
, level
, layout
,
6812 struct intel_super
*super
= st
->sb
;
6813 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
6814 raiddisks
, chunk
, size
,
6817 /* we are being asked to automatically layout a
6818 * new volume based on the current contents of
6819 * the container. If the the parameters can be
6820 * satisfied reserve_space will record the disks,
6821 * start offset, and size of the volume to be
6822 * created. add_to_super and getinfo_super
6823 * detect when autolayout is in progress.
6825 /* assuming that freesize is always given when array is
6827 if (super
->orom
&& freesize
) {
6829 count
= count_volumes(super
->hba
,
6830 super
->orom
->dpa
, verbose
);
6831 if (super
->orom
->vphba
<= count
) {
6832 pr_vrb("platform does not support more than %d raid volumes.\n",
6833 super
->orom
->vphba
);
6838 return reserve_space(st
, raiddisks
, size
,
6844 /* creating in a given container */
6845 return validate_geometry_imsm_volume(st
, level
, layout
,
6846 raiddisks
, chunk
, size
,
6848 dev
, freesize
, verbose
);
6851 /* This device needs to be a device in an 'imsm' container */
6852 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
6855 pr_err("Cannot create this array on device %s\n",
6860 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
6862 pr_err("Cannot open %s: %s\n",
6863 dev
, strerror(errno
));
6866 /* Well, it is in use by someone, maybe an 'imsm' container. */
6867 cfd
= open_container(fd
);
6871 pr_err("Cannot use %s: It is busy\n",
6875 sra
= sysfs_read(cfd
, NULL
, GET_VERSION
);
6876 if (sra
&& sra
->array
.major_version
== -1 &&
6877 strcmp(sra
->text_version
, "imsm") == 0)
6881 /* This is a member of a imsm container. Load the container
6882 * and try to create a volume
6884 struct intel_super
*super
;
6886 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
, NULL
, 1) == 0) {
6888 strcpy(st
->container_devnm
, fd2devnm(cfd
));
6890 return validate_geometry_imsm_volume(st
, level
, layout
,
6892 size
, data_offset
, dev
,
6899 pr_err("failed container membership check\n");
6905 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
6907 struct intel_super
*super
= st
->sb
;
6909 if (level
&& *level
== UnSet
)
6910 *level
= LEVEL_CONTAINER
;
6912 if (level
&& layout
&& *layout
== UnSet
)
6913 *layout
= imsm_level_to_layout(*level
);
6915 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0))
6916 *chunk
= imsm_default_chunk(super
->orom
);
6919 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
6921 static int kill_subarray_imsm(struct supertype
*st
)
6923 /* remove the subarray currently referenced by ->current_vol */
6925 struct intel_dev
**dp
;
6926 struct intel_super
*super
= st
->sb
;
6927 __u8 current_vol
= super
->current_vol
;
6928 struct imsm_super
*mpb
= super
->anchor
;
6930 if (super
->current_vol
< 0)
6932 super
->current_vol
= -1; /* invalidate subarray cursor */
6934 /* block deletions that would change the uuid of active subarrays
6936 * FIXME when immutable ids are available, but note that we'll
6937 * also need to fixup the invalidated/active subarray indexes in
6940 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6943 if (i
< current_vol
)
6945 sprintf(subarray
, "%u", i
);
6946 if (is_subarray_active(subarray
, st
->devnm
)) {
6947 pr_err("deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
6954 if (st
->update_tail
) {
6955 struct imsm_update_kill_array
*u
= xmalloc(sizeof(*u
));
6957 u
->type
= update_kill_array
;
6958 u
->dev_idx
= current_vol
;
6959 append_metadata_update(st
, u
, sizeof(*u
));
6964 for (dp
= &super
->devlist
; *dp
;)
6965 if ((*dp
)->index
== current_vol
) {
6968 handle_missing(super
, (*dp
)->dev
);
6969 if ((*dp
)->index
> current_vol
)
6974 /* no more raid devices, all active components are now spares,
6975 * but of course failed are still failed
6977 if (--mpb
->num_raid_devs
== 0) {
6980 for (d
= super
->disks
; d
; d
= d
->next
)
6985 super
->updates_pending
++;
6990 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
6991 char *update
, struct mddev_ident
*ident
)
6993 /* update the subarray currently referenced by ->current_vol */
6994 struct intel_super
*super
= st
->sb
;
6995 struct imsm_super
*mpb
= super
->anchor
;
6997 if (strcmp(update
, "name") == 0) {
6998 char *name
= ident
->name
;
7002 if (is_subarray_active(subarray
, st
->devnm
)) {
7003 pr_err("Unable to update name of active subarray\n");
7007 if (!check_name(super
, name
, 0))
7010 vol
= strtoul(subarray
, &ep
, 10);
7011 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
7014 if (st
->update_tail
) {
7015 struct imsm_update_rename_array
*u
= xmalloc(sizeof(*u
));
7017 u
->type
= update_rename_array
;
7019 snprintf((char *) u
->name
, MAX_RAID_SERIAL_LEN
, "%s", name
);
7020 append_metadata_update(st
, u
, sizeof(*u
));
7022 struct imsm_dev
*dev
;
7025 dev
= get_imsm_dev(super
, vol
);
7026 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
7027 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7028 dev
= get_imsm_dev(super
, i
);
7029 handle_missing(super
, dev
);
7031 super
->updates_pending
++;
7038 #endif /* MDASSEMBLE */
7040 static int is_gen_migration(struct imsm_dev
*dev
)
7045 if (!dev
->vol
.migr_state
)
7048 if (migr_type(dev
) == MIGR_GEN_MIGR
)
7054 static int is_rebuilding(struct imsm_dev
*dev
)
7056 struct imsm_map
*migr_map
;
7058 if (!dev
->vol
.migr_state
)
7061 if (migr_type(dev
) != MIGR_REBUILD
)
7064 migr_map
= get_imsm_map(dev
, MAP_1
);
7066 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
7073 static int is_initializing(struct imsm_dev
*dev
)
7075 struct imsm_map
*migr_map
;
7077 if (!dev
->vol
.migr_state
)
7080 if (migr_type(dev
) != MIGR_INIT
)
7083 migr_map
= get_imsm_map(dev
, MAP_1
);
7085 if (migr_map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
7092 static void update_recovery_start(struct intel_super
*super
,
7093 struct imsm_dev
*dev
,
7094 struct mdinfo
*array
)
7096 struct mdinfo
*rebuild
= NULL
;
7100 if (!is_rebuilding(dev
))
7103 /* Find the rebuild target, but punt on the dual rebuild case */
7104 for (d
= array
->devs
; d
; d
= d
->next
)
7105 if (d
->recovery_start
== 0) {
7112 /* (?) none of the disks are marked with
7113 * IMSM_ORD_REBUILD, so assume they are missing and the
7114 * disk_ord_tbl was not correctly updated
7116 dprintf("failed to locate out-of-sync disk\n");
7120 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
7121 rebuild
->recovery_start
= units
* blocks_per_migr_unit(super
, dev
);
7125 static int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
);
7128 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
7130 /* Given a container loaded by load_super_imsm_all,
7131 * extract information about all the arrays into
7133 * If 'subarray' is given, just extract info about that array.
7135 * For each imsm_dev create an mdinfo, fill it in,
7136 * then look for matching devices in super->disks
7137 * and create appropriate device mdinfo.
7139 struct intel_super
*super
= st
->sb
;
7140 struct imsm_super
*mpb
= super
->anchor
;
7141 struct mdinfo
*rest
= NULL
;
7145 int spare_disks
= 0;
7147 /* do not assemble arrays when not all attributes are supported */
7148 if (imsm_check_attributes(mpb
->attributes
) == 0) {
7150 pr_err("Unsupported attributes in IMSM metadata.Arrays activation is blocked.\n");
7153 /* count spare devices, not used in maps
7155 for (d
= super
->disks
; d
; d
= d
->next
)
7159 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7160 struct imsm_dev
*dev
;
7161 struct imsm_map
*map
;
7162 struct imsm_map
*map2
;
7163 struct mdinfo
*this;
7171 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
7174 dev
= get_imsm_dev(super
, i
);
7175 map
= get_imsm_map(dev
, MAP_0
);
7176 map2
= get_imsm_map(dev
, MAP_1
);
7178 /* do not publish arrays that are in the middle of an
7179 * unsupported migration
7181 if (dev
->vol
.migr_state
&&
7182 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
7183 pr_err("cannot assemble volume '%.16s': unsupported migration in progress\n",
7187 /* do not publish arrays that are not support by controller's
7191 this = xmalloc(sizeof(*this));
7193 super
->current_vol
= i
;
7194 getinfo_super_imsm_volume(st
, this, NULL
);
7197 chunk
= __le16_to_cpu(map
->blocks_per_strip
) >> 1;
7198 /* mdadm does not support all metadata features- set the bit in all arrays state */
7199 if (!validate_geometry_imsm_orom(super
,
7200 get_imsm_raid_level(map
), /* RAID level */
7201 imsm_level_to_layout(get_imsm_raid_level(map
)),
7202 map
->num_members
, /* raid disks */
7203 &chunk
, join_u32(dev
->size_low
, dev
->size_high
),
7205 pr_err("IMSM RAID geometry validation failed. Array %s activation is blocked.\n",
7207 this->array
.state
|=
7208 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
7209 (1<<MD_SB_BLOCK_VOLUME
);
7213 /* if array has bad blocks, set suitable bit in all arrays state */
7215 this->array
.state
|=
7216 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
7217 (1<<MD_SB_BLOCK_VOLUME
);
7219 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
7220 unsigned long long recovery_start
;
7221 struct mdinfo
*info_d
;
7228 idx
= get_imsm_disk_idx(dev
, slot
, MAP_0
);
7229 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
7230 for (d
= super
->disks
; d
; d
= d
->next
)
7231 if (d
->index
== idx
)
7234 recovery_start
= MaxSector
;
7237 if (d
&& is_failed(&d
->disk
))
7239 if (ord
& IMSM_ORD_REBUILD
)
7243 * if we skip some disks the array will be assmebled degraded;
7244 * reset resync start to avoid a dirty-degraded
7245 * situation when performing the intial sync
7247 * FIXME handle dirty degraded
7249 if ((skip
|| recovery_start
== 0) && !dev
->vol
.dirty
)
7250 this->resync_start
= MaxSector
;
7254 info_d
= xcalloc(1, sizeof(*info_d
));
7255 info_d
->next
= this->devs
;
7256 this->devs
= info_d
;
7258 info_d
->disk
.number
= d
->index
;
7259 info_d
->disk
.major
= d
->major
;
7260 info_d
->disk
.minor
= d
->minor
;
7261 info_d
->disk
.raid_disk
= slot
;
7262 info_d
->recovery_start
= recovery_start
;
7264 if (slot
< map2
->num_members
)
7265 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
7267 this->array
.spare_disks
++;
7269 if (slot
< map
->num_members
)
7270 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
7272 this->array
.spare_disks
++;
7274 if (info_d
->recovery_start
== MaxSector
)
7275 this->array
.working_disks
++;
7277 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
7278 info_d
->data_offset
= pba_of_lba0(map
);
7280 if (map
->raid_level
== 5) {
7281 info_d
->component_size
=
7282 num_data_stripes(map
) *
7283 map
->blocks_per_strip
;
7285 info_d
->component_size
= blocks_per_member(map
);
7288 info_d
->bb
.supported
= 0;
7289 get_volume_badblocks(super
->bbm_log
, ord_to_idx(ord
),
7290 info_d
->data_offset
,
7291 info_d
->component_size
,
7294 /* now that the disk list is up-to-date fixup recovery_start */
7295 update_recovery_start(super
, dev
, this);
7296 this->array
.spare_disks
+= spare_disks
;
7299 /* check for reshape */
7300 if (this->reshape_active
== 1)
7301 recover_backup_imsm(st
, this);
7309 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
7310 int failed
, int look_in_map
)
7312 struct imsm_map
*map
;
7314 map
= get_imsm_map(dev
, look_in_map
);
7317 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
7318 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
7320 switch (get_imsm_raid_level(map
)) {
7322 return IMSM_T_STATE_FAILED
;
7325 if (failed
< map
->num_members
)
7326 return IMSM_T_STATE_DEGRADED
;
7328 return IMSM_T_STATE_FAILED
;
7333 * check to see if any mirrors have failed, otherwise we
7334 * are degraded. Even numbered slots are mirrored on
7338 /* gcc -Os complains that this is unused */
7339 int insync
= insync
;
7341 for (i
= 0; i
< map
->num_members
; i
++) {
7342 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_X
);
7343 int idx
= ord_to_idx(ord
);
7344 struct imsm_disk
*disk
;
7346 /* reset the potential in-sync count on even-numbered
7347 * slots. num_copies is always 2 for imsm raid10
7352 disk
= get_imsm_disk(super
, idx
);
7353 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
7356 /* no in-sync disks left in this mirror the
7360 return IMSM_T_STATE_FAILED
;
7363 return IMSM_T_STATE_DEGRADED
;
7367 return IMSM_T_STATE_DEGRADED
;
7369 return IMSM_T_STATE_FAILED
;
7375 return map
->map_state
;
7378 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
7383 struct imsm_disk
*disk
;
7384 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7385 struct imsm_map
*prev
= get_imsm_map(dev
, MAP_1
);
7386 struct imsm_map
*map_for_loop
;
7391 /* at the beginning of migration we set IMSM_ORD_REBUILD on
7392 * disks that are being rebuilt. New failures are recorded to
7393 * map[0]. So we look through all the disks we started with and
7394 * see if any failures are still present, or if any new ones
7398 if (prev
&& (map
->num_members
< prev
->num_members
))
7399 map_for_loop
= prev
;
7401 for (i
= 0; i
< map_for_loop
->num_members
; i
++) {
7403 /* when MAP_X is passed both maps failures are counted
7406 (look_in_map
== MAP_1
|| look_in_map
== MAP_X
) &&
7407 i
< prev
->num_members
) {
7408 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
7409 idx_1
= ord_to_idx(ord
);
7411 disk
= get_imsm_disk(super
, idx_1
);
7412 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
7415 if ((look_in_map
== MAP_0
|| look_in_map
== MAP_X
) &&
7416 i
< map
->num_members
) {
7417 ord
= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
7418 idx
= ord_to_idx(ord
);
7421 disk
= get_imsm_disk(super
, idx
);
7422 if (!disk
|| is_failed(disk
) ||
7423 ord
& IMSM_ORD_REBUILD
)
7433 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
7436 struct intel_super
*super
= c
->sb
;
7437 struct imsm_super
*mpb
= super
->anchor
;
7438 struct imsm_update_prealloc_bb_mem u
;
7440 if (atoi(inst
) >= mpb
->num_raid_devs
) {
7441 pr_err("subarry index %d, out of range\n", atoi(inst
));
7445 dprintf("imsm: open_new %s\n", inst
);
7446 a
->info
.container_member
= atoi(inst
);
7448 u
.type
= update_prealloc_badblocks_mem
;
7449 imsm_update_metadata_locally(c
, &u
, sizeof(u
));
7454 static int is_resyncing(struct imsm_dev
*dev
)
7456 struct imsm_map
*migr_map
;
7458 if (!dev
->vol
.migr_state
)
7461 if (migr_type(dev
) == MIGR_INIT
||
7462 migr_type(dev
) == MIGR_REPAIR
)
7465 if (migr_type(dev
) == MIGR_GEN_MIGR
)
7468 migr_map
= get_imsm_map(dev
, MAP_1
);
7470 if (migr_map
->map_state
== IMSM_T_STATE_NORMAL
&&
7471 dev
->vol
.migr_type
!= MIGR_GEN_MIGR
)
7477 /* return true if we recorded new information */
7478 static int mark_failure(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
7482 struct imsm_map
*map
;
7483 char buf
[MAX_RAID_SERIAL_LEN
+3];
7484 unsigned int len
, shift
= 0;
7486 /* new failures are always set in map[0] */
7487 map
= get_imsm_map(dev
, MAP_0
);
7489 slot
= get_imsm_disk_slot(map
, idx
);
7493 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
7494 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
7497 memcpy(buf
, disk
->serial
, MAX_RAID_SERIAL_LEN
);
7498 buf
[MAX_RAID_SERIAL_LEN
] = '\000';
7500 if ((len
= strlen(buf
)) >= MAX_RAID_SERIAL_LEN
)
7501 shift
= len
- MAX_RAID_SERIAL_LEN
+ 1;
7502 strncpy((char *)disk
->serial
, &buf
[shift
], MAX_RAID_SERIAL_LEN
);
7504 disk
->status
|= FAILED_DISK
;
7505 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
7506 /* mark failures in second map if second map exists and this disk
7508 * This is valid for migration, initialization and rebuild
7510 if (dev
->vol
.migr_state
) {
7511 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
7512 int slot2
= get_imsm_disk_slot(map2
, idx
);
7514 if (slot2
< map2
->num_members
&& slot2
>= 0)
7515 set_imsm_ord_tbl_ent(map2
, slot2
,
7516 idx
| IMSM_ORD_REBUILD
);
7518 if (map
->failed_disk_num
== 0xff)
7519 map
->failed_disk_num
= slot
;
7523 static void mark_missing(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
7525 mark_failure(dev
, disk
, idx
);
7527 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
7530 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
7531 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
7534 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
7538 if (!super
->missing
)
7541 /* When orom adds replacement for missing disk it does
7542 * not remove entry of missing disk, but just updates map with
7543 * new added disk. So it is not enough just to test if there is
7544 * any missing disk, we have to look if there are any failed disks
7545 * in map to stop migration */
7547 dprintf("imsm: mark missing\n");
7548 /* end process for initialization and rebuild only
7550 if (is_gen_migration(dev
) == 0) {
7554 failed
= imsm_count_failed(super
, dev
, MAP_0
);
7555 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7558 end_migration(dev
, super
, map_state
);
7560 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
7561 mark_missing(dev
, &dl
->disk
, dl
->index
);
7562 super
->updates_pending
++;
7565 static unsigned long long imsm_set_array_size(struct imsm_dev
*dev
,
7568 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
7569 unsigned long long array_blocks
;
7570 struct imsm_map
*map
;
7572 if (used_disks
== 0) {
7573 /* when problems occures
7574 * return current array_blocks value
7576 array_blocks
= __le32_to_cpu(dev
->size_high
);
7577 array_blocks
= array_blocks
<< 32;
7578 array_blocks
+= __le32_to_cpu(dev
->size_low
);
7580 return array_blocks
;
7583 /* set array size in metadata
7585 if (new_size
<= 0) {
7586 /* OLCE size change is caused by added disks
7588 map
= get_imsm_map(dev
, MAP_0
);
7589 array_blocks
= blocks_per_member(map
) * used_disks
;
7591 /* Online Volume Size Change
7592 * Using available free space
7594 array_blocks
= new_size
;
7597 /* round array size down to closest MB
7599 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
7600 dev
->size_low
= __cpu_to_le32((__u32
)array_blocks
);
7601 dev
->size_high
= __cpu_to_le32((__u32
)(array_blocks
>> 32));
7603 return array_blocks
;
7606 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
7608 static void imsm_progress_container_reshape(struct intel_super
*super
)
7610 /* if no device has a migr_state, but some device has a
7611 * different number of members than the previous device, start
7612 * changing the number of devices in this device to match
7615 struct imsm_super
*mpb
= super
->anchor
;
7616 int prev_disks
= -1;
7620 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7621 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
7622 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7623 struct imsm_map
*map2
;
7624 int prev_num_members
;
7626 if (dev
->vol
.migr_state
)
7629 if (prev_disks
== -1)
7630 prev_disks
= map
->num_members
;
7631 if (prev_disks
== map
->num_members
)
7634 /* OK, this array needs to enter reshape mode.
7635 * i.e it needs a migr_state
7638 copy_map_size
= sizeof_imsm_map(map
);
7639 prev_num_members
= map
->num_members
;
7640 map
->num_members
= prev_disks
;
7641 dev
->vol
.migr_state
= 1;
7642 dev
->vol
.curr_migr_unit
= 0;
7643 set_migr_type(dev
, MIGR_GEN_MIGR
);
7644 for (i
= prev_num_members
;
7645 i
< map
->num_members
; i
++)
7646 set_imsm_ord_tbl_ent(map
, i
, i
);
7647 map2
= get_imsm_map(dev
, MAP_1
);
7648 /* Copy the current map */
7649 memcpy(map2
, map
, copy_map_size
);
7650 map2
->num_members
= prev_num_members
;
7652 imsm_set_array_size(dev
, -1);
7653 super
->clean_migration_record_by_mdmon
= 1;
7654 super
->updates_pending
++;
7658 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
7659 * states are handled in imsm_set_disk() with one exception, when a
7660 * resync is stopped due to a new failure this routine will set the
7661 * 'degraded' state for the array.
7663 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
7665 int inst
= a
->info
.container_member
;
7666 struct intel_super
*super
= a
->container
->sb
;
7667 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7668 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7669 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
7670 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7671 __u32 blocks_per_unit
;
7673 if (dev
->vol
.migr_state
&&
7674 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
7675 /* array state change is blocked due to reshape action
7677 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
7678 * - finish the reshape (if last_checkpoint is big and action != reshape)
7679 * - update curr_migr_unit
7681 if (a
->curr_action
== reshape
) {
7682 /* still reshaping, maybe update curr_migr_unit */
7683 goto mark_checkpoint
;
7685 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
7686 /* for some reason we aborted the reshape.
7688 * disable automatic metadata rollback
7689 * user action is required to recover process
7692 struct imsm_map
*map2
=
7693 get_imsm_map(dev
, MAP_1
);
7694 dev
->vol
.migr_state
= 0;
7695 set_migr_type(dev
, 0);
7696 dev
->vol
.curr_migr_unit
= 0;
7698 sizeof_imsm_map(map2
));
7699 super
->updates_pending
++;
7702 if (a
->last_checkpoint
>= a
->info
.component_size
) {
7703 unsigned long long array_blocks
;
7707 used_disks
= imsm_num_data_members(dev
, MAP_0
);
7708 if (used_disks
> 0) {
7710 blocks_per_member(map
) *
7712 /* round array size down to closest MB
7714 array_blocks
= (array_blocks
7715 >> SECT_PER_MB_SHIFT
)
7716 << SECT_PER_MB_SHIFT
;
7717 a
->info
.custom_array_size
= array_blocks
;
7718 /* encourage manager to update array
7722 a
->check_reshape
= 1;
7724 /* finalize online capacity expansion/reshape */
7725 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
7727 mdi
->disk
.raid_disk
,
7730 imsm_progress_container_reshape(super
);
7735 /* before we activate this array handle any missing disks */
7736 if (consistent
== 2)
7737 handle_missing(super
, dev
);
7739 if (consistent
== 2 &&
7740 (!is_resync_complete(&a
->info
) ||
7741 map_state
!= IMSM_T_STATE_NORMAL
||
7742 dev
->vol
.migr_state
))
7745 if (is_resync_complete(&a
->info
)) {
7746 /* complete intialization / resync,
7747 * recovery and interrupted recovery is completed in
7750 if (is_resyncing(dev
)) {
7751 dprintf("imsm: mark resync done\n");
7752 end_migration(dev
, super
, map_state
);
7753 super
->updates_pending
++;
7754 a
->last_checkpoint
= 0;
7756 } else if ((!is_resyncing(dev
) && !failed
) &&
7757 (imsm_reshape_blocks_arrays_changes(super
) == 0)) {
7758 /* mark the start of the init process if nothing is failed */
7759 dprintf("imsm: mark resync start\n");
7760 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
7761 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
7763 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
7764 super
->updates_pending
++;
7768 /* skip checkpointing for general migration,
7769 * it is controlled in mdadm
7771 if (is_gen_migration(dev
))
7772 goto skip_mark_checkpoint
;
7774 /* check if we can update curr_migr_unit from resync_start, recovery_start */
7775 blocks_per_unit
= blocks_per_migr_unit(super
, dev
);
7776 if (blocks_per_unit
) {
7780 units
= a
->last_checkpoint
/ blocks_per_unit
;
7783 /* check that we did not overflow 32-bits, and that
7784 * curr_migr_unit needs updating
7786 if (units32
== units
&&
7788 __le32_to_cpu(dev
->vol
.curr_migr_unit
) != units32
) {
7789 dprintf("imsm: mark checkpoint (%u)\n", units32
);
7790 dev
->vol
.curr_migr_unit
= __cpu_to_le32(units32
);
7791 super
->updates_pending
++;
7795 skip_mark_checkpoint
:
7796 /* mark dirty / clean */
7797 if (dev
->vol
.dirty
!= !consistent
) {
7798 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
7803 super
->updates_pending
++;
7809 static int imsm_disk_slot_to_ord(struct active_array
*a
, int slot
)
7811 int inst
= a
->info
.container_member
;
7812 struct intel_super
*super
= a
->container
->sb
;
7813 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7814 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7816 if (slot
> map
->num_members
) {
7817 pr_err("imsm: imsm_disk_slot_to_ord %d out of range 0..%d\n",
7818 slot
, map
->num_members
- 1);
7825 return get_imsm_ord_tbl_ent(dev
, slot
, MAP_0
);
7828 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
7830 int inst
= a
->info
.container_member
;
7831 struct intel_super
*super
= a
->container
->sb
;
7832 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7833 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7834 struct imsm_disk
*disk
;
7836 int recovery_not_finished
= 0;
7841 ord
= imsm_disk_slot_to_ord(a
, n
);
7845 dprintf("imsm: set_disk %d:%x\n", n
, state
);
7846 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
7848 /* check for new failures */
7849 if (state
& DS_FAULTY
) {
7850 if (mark_failure(dev
, disk
, ord_to_idx(ord
)))
7851 super
->updates_pending
++;
7854 /* check if in_sync */
7855 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
7856 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
7858 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
7859 super
->updates_pending
++;
7862 failed
= imsm_count_failed(super
, dev
, MAP_0
);
7863 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7865 /* check if recovery complete, newly degraded, or failed */
7866 dprintf("imsm: Detected transition to state ");
7867 switch (map_state
) {
7868 case IMSM_T_STATE_NORMAL
: /* transition to normal state */
7869 dprintf("normal: ");
7870 if (is_rebuilding(dev
)) {
7871 dprintf_cont("while rebuilding");
7872 /* check if recovery is really finished */
7873 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
7874 if (mdi
->recovery_start
!= MaxSector
) {
7875 recovery_not_finished
= 1;
7878 if (recovery_not_finished
) {
7880 dprintf("Rebuild has not finished yet, state not changed");
7881 if (a
->last_checkpoint
< mdi
->recovery_start
) {
7882 a
->last_checkpoint
= mdi
->recovery_start
;
7883 super
->updates_pending
++;
7887 end_migration(dev
, super
, map_state
);
7888 map
= get_imsm_map(dev
, MAP_0
);
7889 map
->failed_disk_num
= ~0;
7890 super
->updates_pending
++;
7891 a
->last_checkpoint
= 0;
7894 if (is_gen_migration(dev
)) {
7895 dprintf_cont("while general migration");
7896 if (a
->last_checkpoint
>= a
->info
.component_size
)
7897 end_migration(dev
, super
, map_state
);
7899 map
->map_state
= map_state
;
7900 map
= get_imsm_map(dev
, MAP_0
);
7901 map
->failed_disk_num
= ~0;
7902 super
->updates_pending
++;
7906 case IMSM_T_STATE_DEGRADED
: /* transition to degraded state */
7907 dprintf_cont("degraded: ");
7908 if (map
->map_state
!= map_state
&& !dev
->vol
.migr_state
) {
7909 dprintf_cont("mark degraded");
7910 map
->map_state
= map_state
;
7911 super
->updates_pending
++;
7912 a
->last_checkpoint
= 0;
7915 if (is_rebuilding(dev
)) {
7916 dprintf_cont("while rebuilding.");
7917 if (map
->map_state
!= map_state
) {
7918 dprintf_cont(" Map state change");
7919 end_migration(dev
, super
, map_state
);
7920 super
->updates_pending
++;
7924 if (is_gen_migration(dev
)) {
7925 dprintf_cont("while general migration");
7926 if (a
->last_checkpoint
>= a
->info
.component_size
)
7927 end_migration(dev
, super
, map_state
);
7929 map
->map_state
= map_state
;
7930 manage_second_map(super
, dev
);
7932 super
->updates_pending
++;
7935 if (is_initializing(dev
)) {
7936 dprintf_cont("while initialization.");
7937 map
->map_state
= map_state
;
7938 super
->updates_pending
++;
7942 case IMSM_T_STATE_FAILED
: /* transition to failed state */
7943 dprintf_cont("failed: ");
7944 if (is_gen_migration(dev
)) {
7945 dprintf_cont("while general migration");
7946 map
->map_state
= map_state
;
7947 super
->updates_pending
++;
7950 if (map
->map_state
!= map_state
) {
7951 dprintf_cont("mark failed");
7952 end_migration(dev
, super
, map_state
);
7953 super
->updates_pending
++;
7954 a
->last_checkpoint
= 0;
7959 dprintf_cont("state %i\n", map_state
);
7964 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
7967 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
7968 unsigned long long dsize
;
7969 unsigned long long sectors
;
7970 unsigned int sector_size
;
7972 get_dev_sector_size(fd
, NULL
, §or_size
);
7973 get_dev_size(fd
, NULL
, &dsize
);
7975 if (mpb_size
> sector_size
) {
7976 /* -1 to account for anchor */
7977 sectors
= mpb_sectors(mpb
, sector_size
) - 1;
7979 /* write the extended mpb to the sectors preceeding the anchor */
7980 if (lseek64(fd
, dsize
- (sector_size
* (2 + sectors
)),
7984 if ((unsigned long long)write(fd
, buf
+ sector_size
,
7985 sector_size
* sectors
) != sector_size
* sectors
)
7989 /* first block is stored on second to last sector of the disk */
7990 if (lseek64(fd
, dsize
- (sector_size
* 2), SEEK_SET
) < 0)
7993 if (write(fd
, buf
, sector_size
) != sector_size
)
7999 static void imsm_sync_metadata(struct supertype
*container
)
8001 struct intel_super
*super
= container
->sb
;
8003 dprintf("sync metadata: %d\n", super
->updates_pending
);
8004 if (!super
->updates_pending
)
8007 write_super_imsm(container
, 0);
8009 super
->updates_pending
= 0;
8012 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
8014 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
8015 int i
= get_imsm_disk_idx(dev
, idx
, MAP_X
);
8018 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8022 if (dl
&& is_failed(&dl
->disk
))
8026 dprintf("found %x:%x\n", dl
->major
, dl
->minor
);
8031 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
8032 struct active_array
*a
, int activate_new
,
8033 struct mdinfo
*additional_test_list
)
8035 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
8036 int idx
= get_imsm_disk_idx(dev
, slot
, MAP_X
);
8037 struct imsm_super
*mpb
= super
->anchor
;
8038 struct imsm_map
*map
;
8039 unsigned long long pos
;
8044 __u32 array_start
= 0;
8045 __u32 array_end
= 0;
8047 struct mdinfo
*test_list
;
8049 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
8050 /* If in this array, skip */
8051 for (d
= a
->info
.devs
; d
; d
= d
->next
)
8052 if (d
->state_fd
>= 0 &&
8053 d
->disk
.major
== dl
->major
&&
8054 d
->disk
.minor
== dl
->minor
) {
8055 dprintf("%x:%x already in array\n",
8056 dl
->major
, dl
->minor
);
8061 test_list
= additional_test_list
;
8063 if (test_list
->disk
.major
== dl
->major
&&
8064 test_list
->disk
.minor
== dl
->minor
) {
8065 dprintf("%x:%x already in additional test list\n",
8066 dl
->major
, dl
->minor
);
8069 test_list
= test_list
->next
;
8074 /* skip in use or failed drives */
8075 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
8077 dprintf("%x:%x status (failed: %d index: %d)\n",
8078 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
8082 /* skip pure spares when we are looking for partially
8083 * assimilated drives
8085 if (dl
->index
== -1 && !activate_new
)
8088 /* Does this unused device have the requisite free space?
8089 * It needs to be able to cover all member volumes
8091 ex
= get_extents(super
, dl
);
8093 dprintf("cannot get extents\n");
8096 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8097 dev
= get_imsm_dev(super
, i
);
8098 map
= get_imsm_map(dev
, MAP_0
);
8100 /* check if this disk is already a member of
8103 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
8109 array_start
= pba_of_lba0(map
);
8110 array_end
= array_start
+
8111 blocks_per_member(map
) - 1;
8114 /* check that we can start at pba_of_lba0 with
8115 * blocks_per_member of space
8117 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
8121 pos
= ex
[j
].start
+ ex
[j
].size
;
8123 } while (ex
[j
-1].size
);
8130 if (i
< mpb
->num_raid_devs
) {
8131 dprintf("%x:%x does not have %u to %u available\n",
8132 dl
->major
, dl
->minor
, array_start
, array_end
);
8142 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
8144 struct imsm_dev
*dev2
;
8145 struct imsm_map
*map
;
8151 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
8153 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
, MAP_0
);
8154 if (state
== IMSM_T_STATE_FAILED
) {
8155 map
= get_imsm_map(dev2
, MAP_0
);
8158 for (slot
= 0; slot
< map
->num_members
; slot
++) {
8160 * Check if failed disks are deleted from intel
8161 * disk list or are marked to be deleted
8163 idx
= get_imsm_disk_idx(dev2
, slot
, MAP_X
);
8164 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
8166 * Do not rebuild the array if failed disks
8167 * from failed sub-array are not removed from
8171 is_failed(&idisk
->disk
) &&
8172 (idisk
->action
!= DISK_REMOVE
))
8180 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
8181 struct metadata_update
**updates
)
8184 * Find a device with unused free space and use it to replace a
8185 * failed/vacant region in an array. We replace failed regions one a
8186 * array at a time. The result is that a new spare disk will be added
8187 * to the first failed array and after the monitor has finished
8188 * propagating failures the remainder will be consumed.
8190 * FIXME add a capability for mdmon to request spares from another
8194 struct intel_super
*super
= a
->container
->sb
;
8195 int inst
= a
->info
.container_member
;
8196 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8197 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8198 int failed
= a
->info
.array
.raid_disks
;
8199 struct mdinfo
*rv
= NULL
;
8202 struct metadata_update
*mu
;
8204 struct imsm_update_activate_spare
*u
;
8209 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
8210 if ((d
->curr_state
& DS_FAULTY
) &&
8212 /* wait for Removal to happen */
8214 if (d
->state_fd
>= 0)
8218 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
8219 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
8221 if (imsm_reshape_blocks_arrays_changes(super
))
8224 /* Cannot activate another spare if rebuild is in progress already
8226 if (is_rebuilding(dev
)) {
8227 dprintf("imsm: No spare activation allowed. Rebuild in progress already.\n");
8231 if (a
->info
.array
.level
== 4)
8232 /* No repair for takeovered array
8233 * imsm doesn't support raid4
8237 if (imsm_check_degraded(super
, dev
, failed
, MAP_0
) !=
8238 IMSM_T_STATE_DEGRADED
)
8241 if (get_imsm_map(dev
, MAP_0
)->map_state
== IMSM_T_STATE_UNINITIALIZED
) {
8242 dprintf("imsm: No spare activation allowed. Volume is not initialized.\n");
8247 * If there are any failed disks check state of the other volume.
8248 * Block rebuild if the another one is failed until failed disks
8249 * are removed from container.
8252 dprintf("found failed disks in %.*s, check if there anotherfailed sub-array.\n",
8253 MAX_RAID_SERIAL_LEN
, dev
->volume
);
8254 /* check if states of the other volumes allow for rebuild */
8255 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
8257 allowed
= imsm_rebuild_allowed(a
->container
,
8265 /* For each slot, if it is not working, find a spare */
8266 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
8267 for (d
= a
->info
.devs
; d
; d
= d
->next
)
8268 if (d
->disk
.raid_disk
== i
)
8270 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
8271 if (d
&& (d
->state_fd
>= 0))
8275 * OK, this device needs recovery. Try to re-add the
8276 * previous occupant of this slot, if this fails see if
8277 * we can continue the assimilation of a spare that was
8278 * partially assimilated, finally try to activate a new
8281 dl
= imsm_readd(super
, i
, a
);
8283 dl
= imsm_add_spare(super
, i
, a
, 0, rv
);
8285 dl
= imsm_add_spare(super
, i
, a
, 1, rv
);
8289 /* found a usable disk with enough space */
8290 di
= xcalloc(1, sizeof(*di
));
8292 /* dl->index will be -1 in the case we are activating a
8293 * pristine spare. imsm_process_update() will create a
8294 * new index in this case. Once a disk is found to be
8295 * failed in all member arrays it is kicked from the
8298 di
->disk
.number
= dl
->index
;
8300 /* (ab)use di->devs to store a pointer to the device
8303 di
->devs
= (struct mdinfo
*) dl
;
8305 di
->disk
.raid_disk
= i
;
8306 di
->disk
.major
= dl
->major
;
8307 di
->disk
.minor
= dl
->minor
;
8309 di
->recovery_start
= 0;
8310 di
->data_offset
= pba_of_lba0(map
);
8311 di
->component_size
= a
->info
.component_size
;
8312 di
->container_member
= inst
;
8313 di
->bb
.supported
= 0;
8314 super
->random
= random32();
8318 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
8319 i
, di
->data_offset
);
8323 /* No spares found */
8325 /* Now 'rv' has a list of devices to return.
8326 * Create a metadata_update record to update the
8327 * disk_ord_tbl for the array
8329 mu
= xmalloc(sizeof(*mu
));
8330 mu
->buf
= xcalloc(num_spares
,
8331 sizeof(struct imsm_update_activate_spare
));
8333 mu
->space_list
= NULL
;
8334 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
8335 mu
->next
= *updates
;
8336 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
8338 for (di
= rv
; di
; di
= di
->next
) {
8339 u
->type
= update_activate_spare
;
8340 u
->dl
= (struct dl
*) di
->devs
;
8342 u
->slot
= di
->disk
.raid_disk
;
8353 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
8355 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
8356 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8357 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, MAP_0
);
8358 struct disk_info
*inf
= get_disk_info(u
);
8359 struct imsm_disk
*disk
;
8363 for (i
= 0; i
< map
->num_members
; i
++) {
8364 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, MAP_X
));
8365 for (j
= 0; j
< new_map
->num_members
; j
++)
8366 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
8373 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
8377 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8378 if (dl
->major
== major
&& dl
->minor
== minor
)
8383 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
8389 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
8390 if (dl
->major
== major
&& dl
->minor
== minor
) {
8393 prev
->next
= dl
->next
;
8395 super
->disks
= dl
->next
;
8397 __free_imsm_disk(dl
);
8398 dprintf("removed %x:%x\n", major
, minor
);
8406 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
8408 static int add_remove_disk_update(struct intel_super
*super
)
8410 int check_degraded
= 0;
8413 /* add/remove some spares to/from the metadata/contrainer */
8414 while (super
->disk_mgmt_list
) {
8415 struct dl
*disk_cfg
;
8417 disk_cfg
= super
->disk_mgmt_list
;
8418 super
->disk_mgmt_list
= disk_cfg
->next
;
8419 disk_cfg
->next
= NULL
;
8421 if (disk_cfg
->action
== DISK_ADD
) {
8422 disk_cfg
->next
= super
->disks
;
8423 super
->disks
= disk_cfg
;
8425 dprintf("added %x:%x\n",
8426 disk_cfg
->major
, disk_cfg
->minor
);
8427 } else if (disk_cfg
->action
== DISK_REMOVE
) {
8428 dprintf("Disk remove action processed: %x.%x\n",
8429 disk_cfg
->major
, disk_cfg
->minor
);
8430 disk
= get_disk_super(super
,
8434 /* store action status */
8435 disk
->action
= DISK_REMOVE
;
8436 /* remove spare disks only */
8437 if (disk
->index
== -1) {
8438 remove_disk_super(super
,
8443 /* release allocate disk structure */
8444 __free_imsm_disk(disk_cfg
);
8447 return check_degraded
;
8450 static int apply_reshape_migration_update(struct imsm_update_reshape_migration
*u
,
8451 struct intel_super
*super
,
8454 struct intel_dev
*id
;
8455 void **tofree
= NULL
;
8458 dprintf("(enter)\n");
8459 if (u
->subdev
< 0 || u
->subdev
> 1) {
8460 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
8463 if (space_list
== NULL
|| *space_list
== NULL
) {
8464 dprintf("imsm: Error: Memory is not allocated\n");
8468 for (id
= super
->devlist
; id
; id
= id
->next
) {
8469 if (id
->index
== (unsigned)u
->subdev
) {
8470 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
8471 struct imsm_map
*map
;
8472 struct imsm_dev
*new_dev
=
8473 (struct imsm_dev
*)*space_list
;
8474 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
8476 struct dl
*new_disk
;
8478 if (new_dev
== NULL
)
8480 *space_list
= **space_list
;
8481 memcpy(new_dev
, dev
, sizeof_imsm_dev(dev
, 0));
8482 map
= get_imsm_map(new_dev
, MAP_0
);
8484 dprintf("imsm: Error: migration in progress");
8488 to_state
= map
->map_state
;
8489 if ((u
->new_level
== 5) && (map
->raid_level
== 0)) {
8491 /* this should not happen */
8492 if (u
->new_disks
[0] < 0) {
8493 map
->failed_disk_num
=
8494 map
->num_members
- 1;
8495 to_state
= IMSM_T_STATE_DEGRADED
;
8497 to_state
= IMSM_T_STATE_NORMAL
;
8499 migrate(new_dev
, super
, to_state
, MIGR_GEN_MIGR
);
8500 if (u
->new_level
> -1)
8501 map
->raid_level
= u
->new_level
;
8502 migr_map
= get_imsm_map(new_dev
, MAP_1
);
8503 if ((u
->new_level
== 5) &&
8504 (migr_map
->raid_level
== 0)) {
8505 int ord
= map
->num_members
- 1;
8506 migr_map
->num_members
--;
8507 if (u
->new_disks
[0] < 0)
8508 ord
|= IMSM_ORD_REBUILD
;
8509 set_imsm_ord_tbl_ent(map
,
8510 map
->num_members
- 1,
8514 tofree
= (void **)dev
;
8516 /* update chunk size
8518 if (u
->new_chunksize
> 0) {
8519 unsigned long long num_data_stripes
;
8521 imsm_num_data_members(dev
, MAP_0
);
8523 if (used_disks
== 0)
8526 map
->blocks_per_strip
=
8527 __cpu_to_le16(u
->new_chunksize
* 2);
8529 (join_u32(dev
->size_low
, dev
->size_high
)
8531 num_data_stripes
/= map
->blocks_per_strip
;
8532 num_data_stripes
/= map
->num_domains
;
8533 set_num_data_stripes(map
, num_data_stripes
);
8538 if (u
->new_level
!= 5 || migr_map
->raid_level
!= 0 ||
8539 migr_map
->raid_level
== map
->raid_level
)
8542 if (u
->new_disks
[0] >= 0) {
8545 new_disk
= get_disk_super(super
,
8546 major(u
->new_disks
[0]),
8547 minor(u
->new_disks
[0]));
8548 dprintf("imsm: new disk for reshape is: %i:%i (%p, index = %i)\n",
8549 major(u
->new_disks
[0]),
8550 minor(u
->new_disks
[0]),
8551 new_disk
, new_disk
->index
);
8552 if (new_disk
== NULL
)
8553 goto error_disk_add
;
8555 new_disk
->index
= map
->num_members
- 1;
8556 /* slot to fill in autolayout
8558 new_disk
->raiddisk
= new_disk
->index
;
8559 new_disk
->disk
.status
|= CONFIGURED_DISK
;
8560 new_disk
->disk
.status
&= ~SPARE_DISK
;
8562 goto error_disk_add
;
8565 *tofree
= *space_list
;
8566 /* calculate new size
8568 imsm_set_array_size(new_dev
, -1);
8575 *space_list
= tofree
;
8579 dprintf("Error: imsm: Cannot find disk.\n");
8583 static int apply_size_change_update(struct imsm_update_size_change
*u
,
8584 struct intel_super
*super
)
8586 struct intel_dev
*id
;
8589 dprintf("(enter)\n");
8590 if (u
->subdev
< 0 || u
->subdev
> 1) {
8591 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
8595 for (id
= super
->devlist
; id
; id
= id
->next
) {
8596 if (id
->index
== (unsigned)u
->subdev
) {
8597 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
8598 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8599 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
8600 unsigned long long blocks_per_member
;
8601 unsigned long long num_data_stripes
;
8603 /* calculate new size
8605 blocks_per_member
= u
->new_size
/ used_disks
;
8606 num_data_stripes
= blocks_per_member
/
8607 map
->blocks_per_strip
;
8608 num_data_stripes
/= map
->num_domains
;
8609 dprintf("(size: %llu, blocks per member: %llu, num_data_stipes: %llu)\n",
8610 u
->new_size
, blocks_per_member
,
8612 set_blocks_per_member(map
, blocks_per_member
);
8613 set_num_data_stripes(map
, num_data_stripes
);
8614 imsm_set_array_size(dev
, u
->new_size
);
8624 static int apply_update_activate_spare(struct imsm_update_activate_spare
*u
,
8625 struct intel_super
*super
,
8626 struct active_array
*active_array
)
8628 struct imsm_super
*mpb
= super
->anchor
;
8629 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
8630 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8631 struct imsm_map
*migr_map
;
8632 struct active_array
*a
;
8633 struct imsm_disk
*disk
;
8640 int second_map_created
= 0;
8642 for (; u
; u
= u
->next
) {
8643 victim
= get_imsm_disk_idx(dev
, u
->slot
, MAP_X
);
8648 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8653 pr_err("error: imsm_activate_spare passed an unknown disk (index: %d)\n",
8658 /* count failures (excluding rebuilds and the victim)
8659 * to determine map[0] state
8662 for (i
= 0; i
< map
->num_members
; i
++) {
8665 disk
= get_imsm_disk(super
,
8666 get_imsm_disk_idx(dev
, i
, MAP_X
));
8667 if (!disk
|| is_failed(disk
))
8671 /* adding a pristine spare, assign a new index */
8672 if (dl
->index
< 0) {
8673 dl
->index
= super
->anchor
->num_disks
;
8674 super
->anchor
->num_disks
++;
8677 disk
->status
|= CONFIGURED_DISK
;
8678 disk
->status
&= ~SPARE_DISK
;
8681 to_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8682 if (!second_map_created
) {
8683 second_map_created
= 1;
8684 map
->map_state
= IMSM_T_STATE_DEGRADED
;
8685 migrate(dev
, super
, to_state
, MIGR_REBUILD
);
8687 map
->map_state
= to_state
;
8688 migr_map
= get_imsm_map(dev
, MAP_1
);
8689 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
8690 set_imsm_ord_tbl_ent(migr_map
, u
->slot
,
8691 dl
->index
| IMSM_ORD_REBUILD
);
8693 /* update the family_num to mark a new container
8694 * generation, being careful to record the existing
8695 * family_num in orig_family_num to clean up after
8696 * earlier mdadm versions that neglected to set it.
8698 if (mpb
->orig_family_num
== 0)
8699 mpb
->orig_family_num
= mpb
->family_num
;
8700 mpb
->family_num
+= super
->random
;
8702 /* count arrays using the victim in the metadata */
8704 for (a
= active_array
; a
; a
= a
->next
) {
8705 dev
= get_imsm_dev(super
, a
->info
.container_member
);
8706 map
= get_imsm_map(dev
, MAP_0
);
8708 if (get_imsm_disk_slot(map
, victim
) >= 0)
8712 /* delete the victim if it is no longer being
8718 /* We know that 'manager' isn't touching anything,
8719 * so it is safe to delete
8721 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
8722 if ((*dlp
)->index
== victim
)
8725 /* victim may be on the missing list */
8727 for (dlp
= &super
->missing
; *dlp
;
8728 dlp
= &(*dlp
)->next
)
8729 if ((*dlp
)->index
== victim
)
8731 imsm_delete(super
, dlp
, victim
);
8738 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
8739 struct intel_super
*super
,
8742 struct dl
*new_disk
;
8743 struct intel_dev
*id
;
8745 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
8746 int disk_count
= u
->old_raid_disks
;
8747 void **tofree
= NULL
;
8748 int devices_to_reshape
= 1;
8749 struct imsm_super
*mpb
= super
->anchor
;
8751 unsigned int dev_id
;
8753 dprintf("(enter)\n");
8755 /* enable spares to use in array */
8756 for (i
= 0; i
< delta_disks
; i
++) {
8757 new_disk
= get_disk_super(super
,
8758 major(u
->new_disks
[i
]),
8759 minor(u
->new_disks
[i
]));
8760 dprintf("imsm: new disk for reshape is: %i:%i (%p, index = %i)\n",
8761 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
8762 new_disk
, new_disk
->index
);
8763 if (new_disk
== NULL
||
8764 (new_disk
->index
>= 0 &&
8765 new_disk
->index
< u
->old_raid_disks
))
8766 goto update_reshape_exit
;
8767 new_disk
->index
= disk_count
++;
8768 /* slot to fill in autolayout
8770 new_disk
->raiddisk
= new_disk
->index
;
8771 new_disk
->disk
.status
|=
8773 new_disk
->disk
.status
&= ~SPARE_DISK
;
8776 dprintf("imsm: volume set mpb->num_raid_devs = %i\n",
8777 mpb
->num_raid_devs
);
8778 /* manage changes in volume
8780 for (dev_id
= 0; dev_id
< mpb
->num_raid_devs
; dev_id
++) {
8781 void **sp
= *space_list
;
8782 struct imsm_dev
*newdev
;
8783 struct imsm_map
*newmap
, *oldmap
;
8785 for (id
= super
->devlist
; id
; id
= id
->next
) {
8786 if (id
->index
== dev_id
)
8795 /* Copy the dev, but not (all of) the map */
8796 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
8797 oldmap
= get_imsm_map(id
->dev
, MAP_0
);
8798 newmap
= get_imsm_map(newdev
, MAP_0
);
8799 /* Copy the current map */
8800 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
8801 /* update one device only
8803 if (devices_to_reshape
) {
8804 dprintf("imsm: modifying subdev: %i\n",
8806 devices_to_reshape
--;
8807 newdev
->vol
.migr_state
= 1;
8808 newdev
->vol
.curr_migr_unit
= 0;
8809 set_migr_type(newdev
, MIGR_GEN_MIGR
);
8810 newmap
->num_members
= u
->new_raid_disks
;
8811 for (i
= 0; i
< delta_disks
; i
++) {
8812 set_imsm_ord_tbl_ent(newmap
,
8813 u
->old_raid_disks
+ i
,
8814 u
->old_raid_disks
+ i
);
8816 /* New map is correct, now need to save old map
8818 newmap
= get_imsm_map(newdev
, MAP_1
);
8819 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
8821 imsm_set_array_size(newdev
, -1);
8824 sp
= (void **)id
->dev
;
8829 /* Clear migration record */
8830 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
8833 *space_list
= tofree
;
8836 update_reshape_exit
:
8841 static int apply_takeover_update(struct imsm_update_takeover
*u
,
8842 struct intel_super
*super
,
8845 struct imsm_dev
*dev
= NULL
;
8846 struct intel_dev
*dv
;
8847 struct imsm_dev
*dev_new
;
8848 struct imsm_map
*map
;
8852 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
8853 if (dv
->index
== (unsigned int)u
->subarray
) {
8861 map
= get_imsm_map(dev
, MAP_0
);
8863 if (u
->direction
== R10_TO_R0
) {
8864 unsigned long long num_data_stripes
;
8866 map
->num_domains
= 1;
8867 num_data_stripes
= blocks_per_member(map
);
8868 num_data_stripes
/= map
->blocks_per_strip
;
8869 num_data_stripes
/= map
->num_domains
;
8870 set_num_data_stripes(map
, num_data_stripes
);
8872 /* Number of failed disks must be half of initial disk number */
8873 if (imsm_count_failed(super
, dev
, MAP_0
) !=
8874 (map
->num_members
/ 2))
8877 /* iterate through devices to mark removed disks as spare */
8878 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
8879 if (dm
->disk
.status
& FAILED_DISK
) {
8880 int idx
= dm
->index
;
8881 /* update indexes on the disk list */
8882 /* FIXME this loop-with-the-loop looks wrong, I'm not convinced
8883 the index values will end up being correct.... NB */
8884 for (du
= super
->disks
; du
; du
= du
->next
)
8885 if (du
->index
> idx
)
8887 /* mark as spare disk */
8892 map
->num_members
= map
->num_members
/ 2;
8893 map
->map_state
= IMSM_T_STATE_NORMAL
;
8894 map
->num_domains
= 1;
8895 map
->raid_level
= 0;
8896 map
->failed_disk_num
= -1;
8899 if (u
->direction
== R0_TO_R10
) {
8901 /* update slots in current disk list */
8902 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
8906 /* create new *missing* disks */
8907 for (i
= 0; i
< map
->num_members
; i
++) {
8908 space
= *space_list
;
8911 *space_list
= *space
;
8913 memcpy(du
, super
->disks
, sizeof(*du
));
8917 du
->index
= (i
* 2) + 1;
8918 sprintf((char *)du
->disk
.serial
,
8919 " MISSING_%d", du
->index
);
8920 sprintf((char *)du
->serial
,
8921 "MISSING_%d", du
->index
);
8922 du
->next
= super
->missing
;
8923 super
->missing
= du
;
8925 /* create new dev and map */
8926 space
= *space_list
;
8929 *space_list
= *space
;
8930 dev_new
= (void *)space
;
8931 memcpy(dev_new
, dev
, sizeof(*dev
));
8932 /* update new map */
8933 map
= get_imsm_map(dev_new
, MAP_0
);
8934 map
->num_members
= map
->num_members
* 2;
8935 map
->map_state
= IMSM_T_STATE_DEGRADED
;
8936 map
->num_domains
= 2;
8937 map
->raid_level
= 1;
8938 /* replace dev<->dev_new */
8941 /* update disk order table */
8942 for (du
= super
->disks
; du
; du
= du
->next
)
8944 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
8945 for (du
= super
->missing
; du
; du
= du
->next
)
8946 if (du
->index
>= 0) {
8947 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
8948 mark_missing(dv
->dev
, &du
->disk
, du
->index
);
8954 static void imsm_process_update(struct supertype
*st
,
8955 struct metadata_update
*update
)
8958 * crack open the metadata_update envelope to find the update record
8959 * update can be one of:
8960 * update_reshape_container_disks - all the arrays in the container
8961 * are being reshaped to have more devices. We need to mark
8962 * the arrays for general migration and convert selected spares
8963 * into active devices.
8964 * update_activate_spare - a spare device has replaced a failed
8965 * device in an array, update the disk_ord_tbl. If this disk is
8966 * present in all member arrays then also clear the SPARE_DISK
8968 * update_create_array
8970 * update_rename_array
8971 * update_add_remove_disk
8973 struct intel_super
*super
= st
->sb
;
8974 struct imsm_super
*mpb
;
8975 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
8977 /* update requires a larger buf but the allocation failed */
8978 if (super
->next_len
&& !super
->next_buf
) {
8979 super
->next_len
= 0;
8983 if (super
->next_buf
) {
8984 memcpy(super
->next_buf
, super
->buf
, super
->len
);
8986 super
->len
= super
->next_len
;
8987 super
->buf
= super
->next_buf
;
8989 super
->next_len
= 0;
8990 super
->next_buf
= NULL
;
8993 mpb
= super
->anchor
;
8996 case update_general_migration_checkpoint
: {
8997 struct intel_dev
*id
;
8998 struct imsm_update_general_migration_checkpoint
*u
=
8999 (void *)update
->buf
;
9001 dprintf("called for update_general_migration_checkpoint\n");
9003 /* find device under general migration */
9004 for (id
= super
->devlist
; id
; id
= id
->next
) {
9005 if (is_gen_migration(id
->dev
)) {
9006 id
->dev
->vol
.curr_migr_unit
=
9007 __cpu_to_le32(u
->curr_migr_unit
);
9008 super
->updates_pending
++;
9013 case update_takeover
: {
9014 struct imsm_update_takeover
*u
= (void *)update
->buf
;
9015 if (apply_takeover_update(u
, super
, &update
->space_list
)) {
9016 imsm_update_version_info(super
);
9017 super
->updates_pending
++;
9022 case update_reshape_container_disks
: {
9023 struct imsm_update_reshape
*u
= (void *)update
->buf
;
9024 if (apply_reshape_container_disks_update(
9025 u
, super
, &update
->space_list
))
9026 super
->updates_pending
++;
9029 case update_reshape_migration
: {
9030 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
9031 if (apply_reshape_migration_update(
9032 u
, super
, &update
->space_list
))
9033 super
->updates_pending
++;
9036 case update_size_change
: {
9037 struct imsm_update_size_change
*u
= (void *)update
->buf
;
9038 if (apply_size_change_update(u
, super
))
9039 super
->updates_pending
++;
9042 case update_activate_spare
: {
9043 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
9044 if (apply_update_activate_spare(u
, super
, st
->arrays
))
9045 super
->updates_pending
++;
9048 case update_create_array
: {
9049 /* someone wants to create a new array, we need to be aware of
9050 * a few races/collisions:
9051 * 1/ 'Create' called by two separate instances of mdadm
9052 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
9053 * devices that have since been assimilated via
9055 * In the event this update can not be carried out mdadm will
9056 * (FIX ME) notice that its update did not take hold.
9058 struct imsm_update_create_array
*u
= (void *) update
->buf
;
9059 struct intel_dev
*dv
;
9060 struct imsm_dev
*dev
;
9061 struct imsm_map
*map
, *new_map
;
9062 unsigned long long start
, end
;
9063 unsigned long long new_start
, new_end
;
9065 struct disk_info
*inf
;
9068 /* handle racing creates: first come first serve */
9069 if (u
->dev_idx
< mpb
->num_raid_devs
) {
9070 dprintf("subarray %d already defined\n", u
->dev_idx
);
9074 /* check update is next in sequence */
9075 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
9076 dprintf("can not create array %d expected index %d\n",
9077 u
->dev_idx
, mpb
->num_raid_devs
);
9081 new_map
= get_imsm_map(&u
->dev
, MAP_0
);
9082 new_start
= pba_of_lba0(new_map
);
9083 new_end
= new_start
+ blocks_per_member(new_map
);
9084 inf
= get_disk_info(u
);
9086 /* handle activate_spare versus create race:
9087 * check to make sure that overlapping arrays do not include
9090 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
9091 dev
= get_imsm_dev(super
, i
);
9092 map
= get_imsm_map(dev
, MAP_0
);
9093 start
= pba_of_lba0(map
);
9094 end
= start
+ blocks_per_member(map
);
9095 if ((new_start
>= start
&& new_start
<= end
) ||
9096 (start
>= new_start
&& start
<= new_end
))
9101 if (disks_overlap(super
, i
, u
)) {
9102 dprintf("arrays overlap\n");
9107 /* check that prepare update was successful */
9108 if (!update
->space
) {
9109 dprintf("prepare update failed\n");
9113 /* check that all disks are still active before committing
9114 * changes. FIXME: could we instead handle this by creating a
9115 * degraded array? That's probably not what the user expects,
9116 * so better to drop this update on the floor.
9118 for (i
= 0; i
< new_map
->num_members
; i
++) {
9119 dl
= serial_to_dl(inf
[i
].serial
, super
);
9121 dprintf("disk disappeared\n");
9126 super
->updates_pending
++;
9128 /* convert spares to members and fixup ord_tbl */
9129 for (i
= 0; i
< new_map
->num_members
; i
++) {
9130 dl
= serial_to_dl(inf
[i
].serial
, super
);
9131 if (dl
->index
== -1) {
9132 dl
->index
= mpb
->num_disks
;
9134 dl
->disk
.status
|= CONFIGURED_DISK
;
9135 dl
->disk
.status
&= ~SPARE_DISK
;
9137 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
9142 update
->space
= NULL
;
9143 imsm_copy_dev(dev
, &u
->dev
);
9144 dv
->index
= u
->dev_idx
;
9145 dv
->next
= super
->devlist
;
9146 super
->devlist
= dv
;
9147 mpb
->num_raid_devs
++;
9149 imsm_update_version_info(super
);
9152 /* mdmon knows how to release update->space, but not
9153 * ((struct intel_dev *) update->space)->dev
9155 if (update
->space
) {
9161 case update_kill_array
: {
9162 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
9163 int victim
= u
->dev_idx
;
9164 struct active_array
*a
;
9165 struct intel_dev
**dp
;
9166 struct imsm_dev
*dev
;
9168 /* sanity check that we are not affecting the uuid of
9169 * active arrays, or deleting an active array
9171 * FIXME when immutable ids are available, but note that
9172 * we'll also need to fixup the invalidated/active
9173 * subarray indexes in mdstat
9175 for (a
= st
->arrays
; a
; a
= a
->next
)
9176 if (a
->info
.container_member
>= victim
)
9178 /* by definition if mdmon is running at least one array
9179 * is active in the container, so checking
9180 * mpb->num_raid_devs is just extra paranoia
9182 dev
= get_imsm_dev(super
, victim
);
9183 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
9184 dprintf("failed to delete subarray-%d\n", victim
);
9188 for (dp
= &super
->devlist
; *dp
;)
9189 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
9192 if ((*dp
)->index
> (unsigned)victim
)
9196 mpb
->num_raid_devs
--;
9197 super
->updates_pending
++;
9200 case update_rename_array
: {
9201 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
9202 char name
[MAX_RAID_SERIAL_LEN
+1];
9203 int target
= u
->dev_idx
;
9204 struct active_array
*a
;
9205 struct imsm_dev
*dev
;
9207 /* sanity check that we are not affecting the uuid of
9210 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
9211 name
[MAX_RAID_SERIAL_LEN
] = '\0';
9212 for (a
= st
->arrays
; a
; a
= a
->next
)
9213 if (a
->info
.container_member
== target
)
9215 dev
= get_imsm_dev(super
, u
->dev_idx
);
9216 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
9217 dprintf("failed to rename subarray-%d\n", target
);
9221 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
9222 super
->updates_pending
++;
9225 case update_add_remove_disk
: {
9226 /* we may be able to repair some arrays if disks are
9227 * being added, check the status of add_remove_disk
9228 * if discs has been added.
9230 if (add_remove_disk_update(super
)) {
9231 struct active_array
*a
;
9233 super
->updates_pending
++;
9234 for (a
= st
->arrays
; a
; a
= a
->next
)
9235 a
->check_degraded
= 1;
9239 case update_prealloc_badblocks_mem
:
9242 pr_err("error: unsuported process update type:(type: %d)\n", type
);
9246 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
);
9248 static int imsm_prepare_update(struct supertype
*st
,
9249 struct metadata_update
*update
)
9252 * Allocate space to hold new disk entries, raid-device entries or a new
9253 * mpb if necessary. The manager synchronously waits for updates to
9254 * complete in the monitor, so new mpb buffers allocated here can be
9255 * integrated by the monitor thread without worrying about live pointers
9256 * in the manager thread.
9258 enum imsm_update_type type
;
9259 struct intel_super
*super
= st
->sb
;
9260 unsigned int sector_size
= super
->sector_size
;
9261 struct imsm_super
*mpb
= super
->anchor
;
9265 if (update
->len
< (int)sizeof(type
))
9268 type
= *(enum imsm_update_type
*) update
->buf
;
9271 case update_general_migration_checkpoint
:
9272 if (update
->len
< (int)sizeof(struct imsm_update_general_migration_checkpoint
))
9274 dprintf("called for update_general_migration_checkpoint\n");
9276 case update_takeover
: {
9277 struct imsm_update_takeover
*u
= (void *)update
->buf
;
9278 if (update
->len
< (int)sizeof(*u
))
9280 if (u
->direction
== R0_TO_R10
) {
9281 void **tail
= (void **)&update
->space_list
;
9282 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subarray
);
9283 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9284 int num_members
= map
->num_members
;
9287 /* allocate memory for added disks */
9288 for (i
= 0; i
< num_members
; i
++) {
9289 size
= sizeof(struct dl
);
9290 space
= xmalloc(size
);
9295 /* allocate memory for new device */
9296 size
= sizeof_imsm_dev(super
->devlist
->dev
, 0) +
9297 (num_members
* sizeof(__u32
));
9298 space
= xmalloc(size
);
9302 len
= disks_to_mpb_size(num_members
* 2);
9307 case update_reshape_container_disks
: {
9308 /* Every raid device in the container is about to
9309 * gain some more devices, and we will enter a
9311 * So each 'imsm_map' will be bigger, and the imsm_vol
9312 * will now hold 2 of them.
9313 * Thus we need new 'struct imsm_dev' allocations sized
9314 * as sizeof_imsm_dev but with more devices in both maps.
9316 struct imsm_update_reshape
*u
= (void *)update
->buf
;
9317 struct intel_dev
*dl
;
9318 void **space_tail
= (void**)&update
->space_list
;
9320 if (update
->len
< (int)sizeof(*u
))
9323 dprintf("for update_reshape\n");
9325 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
9326 int size
= sizeof_imsm_dev(dl
->dev
, 1);
9328 if (u
->new_raid_disks
> u
->old_raid_disks
)
9329 size
+= sizeof(__u32
)*2*
9330 (u
->new_raid_disks
- u
->old_raid_disks
);
9337 len
= disks_to_mpb_size(u
->new_raid_disks
);
9338 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
9341 case update_reshape_migration
: {
9342 /* for migration level 0->5 we need to add disks
9343 * so the same as for container operation we will copy
9344 * device to the bigger location.
9345 * in memory prepared device and new disk area are prepared
9346 * for usage in process update
9348 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
9349 struct intel_dev
*id
;
9350 void **space_tail
= (void **)&update
->space_list
;
9353 int current_level
= -1;
9355 if (update
->len
< (int)sizeof(*u
))
9358 dprintf("for update_reshape\n");
9360 /* add space for bigger array in update
9362 for (id
= super
->devlist
; id
; id
= id
->next
) {
9363 if (id
->index
== (unsigned)u
->subdev
) {
9364 size
= sizeof_imsm_dev(id
->dev
, 1);
9365 if (u
->new_raid_disks
> u
->old_raid_disks
)
9366 size
+= sizeof(__u32
)*2*
9367 (u
->new_raid_disks
- u
->old_raid_disks
);
9375 if (update
->space_list
== NULL
)
9378 /* add space for disk in update
9380 size
= sizeof(struct dl
);
9386 /* add spare device to update
9388 for (id
= super
->devlist
; id
; id
= id
->next
)
9389 if (id
->index
== (unsigned)u
->subdev
) {
9390 struct imsm_dev
*dev
;
9391 struct imsm_map
*map
;
9393 dev
= get_imsm_dev(super
, u
->subdev
);
9394 map
= get_imsm_map(dev
, MAP_0
);
9395 current_level
= map
->raid_level
;
9398 if (u
->new_level
== 5 && u
->new_level
!= current_level
) {
9399 struct mdinfo
*spares
;
9401 spares
= get_spares_for_grow(st
);
9409 makedev(dev
->disk
.major
,
9411 dl
= get_disk_super(super
,
9414 dl
->index
= u
->old_raid_disks
;
9420 len
= disks_to_mpb_size(u
->new_raid_disks
);
9421 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
9424 case update_size_change
: {
9425 if (update
->len
< (int)sizeof(struct imsm_update_size_change
))
9429 case update_activate_spare
: {
9430 if (update
->len
< (int)sizeof(struct imsm_update_activate_spare
))
9434 case update_create_array
: {
9435 struct imsm_update_create_array
*u
= (void *) update
->buf
;
9436 struct intel_dev
*dv
;
9437 struct imsm_dev
*dev
= &u
->dev
;
9438 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9440 struct disk_info
*inf
;
9444 if (update
->len
< (int)sizeof(*u
))
9447 inf
= get_disk_info(u
);
9448 len
= sizeof_imsm_dev(dev
, 1);
9449 /* allocate a new super->devlist entry */
9450 dv
= xmalloc(sizeof(*dv
));
9451 dv
->dev
= xmalloc(len
);
9454 /* count how many spares will be converted to members */
9455 for (i
= 0; i
< map
->num_members
; i
++) {
9456 dl
= serial_to_dl(inf
[i
].serial
, super
);
9458 /* hmm maybe it failed?, nothing we can do about
9463 if (count_memberships(dl
, super
) == 0)
9466 len
+= activate
* sizeof(struct imsm_disk
);
9469 case update_kill_array
: {
9470 if (update
->len
< (int)sizeof(struct imsm_update_kill_array
))
9474 case update_rename_array
: {
9475 if (update
->len
< (int)sizeof(struct imsm_update_rename_array
))
9479 case update_add_remove_disk
:
9480 /* no update->len needed */
9482 case update_prealloc_badblocks_mem
:
9483 super
->extra_space
+= sizeof(struct bbm_log
) -
9484 get_imsm_bbm_log_size(super
->bbm_log
);
9490 /* check if we need a larger metadata buffer */
9491 if (super
->next_buf
)
9492 buf_len
= super
->next_len
;
9494 buf_len
= super
->len
;
9496 if (__le32_to_cpu(mpb
->mpb_size
) + super
->extra_space
+ len
> buf_len
) {
9497 /* ok we need a larger buf than what is currently allocated
9498 * if this allocation fails process_update will notice that
9499 * ->next_len is set and ->next_buf is NULL
9501 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) +
9502 super
->extra_space
+ len
, sector_size
);
9503 if (super
->next_buf
)
9504 free(super
->next_buf
);
9506 super
->next_len
= buf_len
;
9507 if (posix_memalign(&super
->next_buf
, sector_size
, buf_len
) == 0)
9508 memset(super
->next_buf
, 0, buf_len
);
9510 super
->next_buf
= NULL
;
9515 /* must be called while manager is quiesced */
9516 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
9518 struct imsm_super
*mpb
= super
->anchor
;
9520 struct imsm_dev
*dev
;
9521 struct imsm_map
*map
;
9522 int i
, j
, num_members
;
9525 dprintf("deleting device[%d] from imsm_super\n", index
);
9527 /* shift all indexes down one */
9528 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
9529 if (iter
->index
> (int)index
)
9531 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
9532 if (iter
->index
> (int)index
)
9535 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
9536 dev
= get_imsm_dev(super
, i
);
9537 map
= get_imsm_map(dev
, MAP_0
);
9538 num_members
= map
->num_members
;
9539 for (j
= 0; j
< num_members
; j
++) {
9540 /* update ord entries being careful not to propagate
9541 * ord-flags to the first map
9543 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_X
);
9545 if (ord_to_idx(ord
) <= index
)
9548 map
= get_imsm_map(dev
, MAP_0
);
9549 set_imsm_ord_tbl_ent(map
, j
, ord_to_idx(ord
- 1));
9550 map
= get_imsm_map(dev
, MAP_1
);
9552 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
9557 super
->updates_pending
++;
9559 struct dl
*dl
= *dlp
;
9561 *dlp
= (*dlp
)->next
;
9562 __free_imsm_disk(dl
);
9565 #endif /* MDASSEMBLE */
9567 static void close_targets(int *targets
, int new_disks
)
9574 for (i
= 0; i
< new_disks
; i
++) {
9575 if (targets
[i
] >= 0) {
9582 static int imsm_get_allowed_degradation(int level
, int raid_disks
,
9583 struct intel_super
*super
,
9584 struct imsm_dev
*dev
)
9590 struct imsm_map
*map
;
9593 ret_val
= raid_disks
/2;
9594 /* check map if all disks pairs not failed
9597 map
= get_imsm_map(dev
, MAP_0
);
9598 for (i
= 0; i
< ret_val
; i
++) {
9599 int degradation
= 0;
9600 if (get_imsm_disk(super
, i
) == NULL
)
9602 if (get_imsm_disk(super
, i
+ 1) == NULL
)
9604 if (degradation
== 2)
9607 map
= get_imsm_map(dev
, MAP_1
);
9608 /* if there is no second map
9609 * result can be returned
9613 /* check degradation in second map
9615 for (i
= 0; i
< ret_val
; i
++) {
9616 int degradation
= 0;
9617 if (get_imsm_disk(super
, i
) == NULL
)
9619 if (get_imsm_disk(super
, i
+ 1) == NULL
)
9621 if (degradation
== 2)
9635 /*******************************************************************************
9636 * Function: open_backup_targets
9637 * Description: Function opens file descriptors for all devices given in
9640 * info : general array info
9641 * raid_disks : number of disks
9642 * raid_fds : table of device's file descriptors
9643 * super : intel super for raid10 degradation check
9644 * dev : intel device for raid10 degradation check
9648 ******************************************************************************/
9649 int open_backup_targets(struct mdinfo
*info
, int raid_disks
, int *raid_fds
,
9650 struct intel_super
*super
, struct imsm_dev
*dev
)
9656 for (i
= 0; i
< raid_disks
; i
++)
9659 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
9662 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
)) {
9663 dprintf("disk is faulty!!\n");
9667 if (sd
->disk
.raid_disk
>= raid_disks
|| sd
->disk
.raid_disk
< 0)
9670 dn
= map_dev(sd
->disk
.major
,
9672 raid_fds
[sd
->disk
.raid_disk
] = dev_open(dn
, O_RDWR
);
9673 if (raid_fds
[sd
->disk
.raid_disk
] < 0) {
9674 pr_err("cannot open component\n");
9679 /* check if maximum array degradation level is not exceeded
9681 if ((raid_disks
- opened
) >
9682 imsm_get_allowed_degradation(info
->new_level
, raid_disks
,
9684 pr_err("Not enough disks can be opened.\n");
9685 close_targets(raid_fds
, raid_disks
);
9691 /*******************************************************************************
9692 * Function: validate_container_imsm
9693 * Description: This routine validates container after assemble,
9694 * eg. if devices in container are under the same controller.
9697 * info : linked list with info about devices used in array
9701 ******************************************************************************/
9702 int validate_container_imsm(struct mdinfo
*info
)
9704 if (check_env("IMSM_NO_PLATFORM"))
9707 struct sys_dev
*idev
;
9708 struct sys_dev
*hba
= NULL
;
9709 struct sys_dev
*intel_devices
= find_intel_devices();
9710 char *dev_path
= devt_to_devpath(makedev(info
->disk
.major
,
9713 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
9714 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
9723 pr_err("WARNING - Cannot detect HBA for device %s!\n",
9724 devid2kname(makedev(info
->disk
.major
, info
->disk
.minor
)));
9728 const struct imsm_orom
*orom
= get_orom_by_device_id(hba
->dev_id
);
9731 for (dev
= info
->next
; dev
; dev
= dev
->next
) {
9732 dev_path
= devt_to_devpath(makedev(dev
->disk
.major
, dev
->disk
.minor
));
9734 struct sys_dev
*hba2
= NULL
;
9735 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
9736 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
9744 const struct imsm_orom
*orom2
= hba2
== NULL
? NULL
:
9745 get_orom_by_device_id(hba2
->dev_id
);
9747 if (hba2
&& hba
->type
!= hba2
->type
) {
9748 pr_err("WARNING - HBAs of devices do not match %s != %s\n",
9749 get_sys_dev_type(hba
->type
), get_sys_dev_type(hba2
->type
));
9753 if (orom
!= orom2
) {
9754 pr_err("WARNING - IMSM container assembled with disks under different HBAs!\n"
9755 " This operation is not supported and can lead to data loss.\n");
9760 pr_err("WARNING - IMSM container assembled with disks under HBAs without IMSM platform support!\n"
9761 " This operation is not supported and can lead to data loss.\n");
9769 /*******************************************************************************
9770 * Function: imsm_record_badblock
9771 * Description: This routine stores new bad block record in BBM log
9774 * a : array containing a bad block
9775 * slot : disk number containing a bad block
9776 * sector : bad block sector
9777 * length : bad block sectors range
9781 ******************************************************************************/
9782 static int imsm_record_badblock(struct active_array
*a
, int slot
,
9783 unsigned long long sector
, int length
)
9785 struct intel_super
*super
= a
->container
->sb
;
9789 ord
= imsm_disk_slot_to_ord(a
, slot
);
9793 ret
= record_new_badblock(super
->bbm_log
, ord_to_idx(ord
), sector
,
9796 super
->updates_pending
++;
9800 /*******************************************************************************
9801 * Function: init_migr_record_imsm
9802 * Description: Function inits imsm migration record
9804 * super : imsm internal array info
9805 * dev : device under migration
9806 * info : general array info to find the smallest device
9809 ******************************************************************************/
9810 void init_migr_record_imsm(struct supertype
*st
, struct imsm_dev
*dev
,
9811 struct mdinfo
*info
)
9813 struct intel_super
*super
= st
->sb
;
9814 struct migr_record
*migr_rec
= super
->migr_rec
;
9816 unsigned long long dsize
, dev_sectors
;
9817 long long unsigned min_dev_sectors
= -1LLU;
9821 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
9822 struct imsm_map
*map_src
= get_imsm_map(dev
, MAP_1
);
9823 unsigned long long num_migr_units
;
9824 unsigned long long array_blocks
;
9826 memset(migr_rec
, 0, sizeof(struct migr_record
));
9827 migr_rec
->family_num
= __cpu_to_le32(super
->anchor
->family_num
);
9829 /* only ascending reshape supported now */
9830 migr_rec
->ascending_migr
= __cpu_to_le32(1);
9832 migr_rec
->dest_depth_per_unit
= GEN_MIGR_AREA_SIZE
/
9833 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
9834 migr_rec
->dest_depth_per_unit
*=
9835 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
9836 new_data_disks
= imsm_num_data_members(dev
, MAP_0
);
9837 migr_rec
->blocks_per_unit
=
9838 __cpu_to_le32(migr_rec
->dest_depth_per_unit
* new_data_disks
);
9839 migr_rec
->dest_depth_per_unit
=
9840 __cpu_to_le32(migr_rec
->dest_depth_per_unit
);
9841 array_blocks
= info
->component_size
* new_data_disks
;
9843 array_blocks
/ __le32_to_cpu(migr_rec
->blocks_per_unit
);
9845 if (array_blocks
% __le32_to_cpu(migr_rec
->blocks_per_unit
))
9847 migr_rec
->num_migr_units
= __cpu_to_le32(num_migr_units
);
9849 migr_rec
->post_migr_vol_cap
= dev
->size_low
;
9850 migr_rec
->post_migr_vol_cap_hi
= dev
->size_high
;
9852 /* Find the smallest dev */
9853 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
9854 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
9855 fd
= dev_open(nm
, O_RDONLY
);
9858 get_dev_size(fd
, NULL
, &dsize
);
9859 dev_sectors
= dsize
/ 512;
9860 if (dev_sectors
< min_dev_sectors
)
9861 min_dev_sectors
= dev_sectors
;
9864 migr_rec
->ckpt_area_pba
= __cpu_to_le32(min_dev_sectors
-
9865 RAID_DISK_RESERVED_BLOCKS_IMSM_HI
);
9867 write_imsm_migr_rec(st
);
9872 /*******************************************************************************
9873 * Function: save_backup_imsm
9874 * Description: Function saves critical data stripes to Migration Copy Area
9875 * and updates the current migration unit status.
9876 * Use restore_stripes() to form a destination stripe,
9877 * and to write it to the Copy Area.
9879 * st : supertype information
9880 * dev : imsm device that backup is saved for
9881 * info : general array info
9882 * buf : input buffer
9883 * length : length of data to backup (blocks_per_unit)
9887 ******************************************************************************/
9888 int save_backup_imsm(struct supertype
*st
,
9889 struct imsm_dev
*dev
,
9890 struct mdinfo
*info
,
9895 struct intel_super
*super
= st
->sb
;
9896 unsigned long long *target_offsets
;
9899 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
9900 int new_disks
= map_dest
->num_members
;
9901 int dest_layout
= 0;
9903 unsigned long long start
;
9904 int data_disks
= imsm_num_data_members(dev
, MAP_0
);
9906 targets
= xmalloc(new_disks
* sizeof(int));
9908 for (i
= 0; i
< new_disks
; i
++)
9911 target_offsets
= xcalloc(new_disks
, sizeof(unsigned long long));
9913 start
= info
->reshape_progress
* 512;
9914 for (i
= 0; i
< new_disks
; i
++) {
9915 target_offsets
[i
] = (unsigned long long)
9916 __le32_to_cpu(super
->migr_rec
->ckpt_area_pba
) * 512;
9917 /* move back copy area adderss, it will be moved forward
9918 * in restore_stripes() using start input variable
9920 target_offsets
[i
] -= start
/data_disks
;
9923 if (open_backup_targets(info
, new_disks
, targets
,
9927 dest_layout
= imsm_level_to_layout(map_dest
->raid_level
);
9928 dest_chunk
= __le16_to_cpu(map_dest
->blocks_per_strip
) * 512;
9930 if (restore_stripes(targets
, /* list of dest devices */
9931 target_offsets
, /* migration record offsets */
9934 map_dest
->raid_level
,
9936 -1, /* source backup file descriptor */
9937 0, /* input buf offset
9938 * always 0 buf is already offseted */
9942 pr_err("Error restoring stripes\n");
9950 close_targets(targets
, new_disks
);
9953 free(target_offsets
);
9958 /*******************************************************************************
9959 * Function: save_checkpoint_imsm
9960 * Description: Function called for current unit status update
9961 * in the migration record. It writes it to disk.
9963 * super : imsm internal array info
9964 * info : general array info
9968 * 2: failure, means no valid migration record
9969 * / no general migration in progress /
9970 ******************************************************************************/
9971 int save_checkpoint_imsm(struct supertype
*st
, struct mdinfo
*info
, int state
)
9973 struct intel_super
*super
= st
->sb
;
9974 unsigned long long blocks_per_unit
;
9975 unsigned long long curr_migr_unit
;
9977 if (load_imsm_migr_rec(super
, info
) != 0) {
9978 dprintf("imsm: ERROR: Cannot read migration record for checkpoint save.\n");
9982 blocks_per_unit
= __le32_to_cpu(super
->migr_rec
->blocks_per_unit
);
9983 if (blocks_per_unit
== 0) {
9984 dprintf("imsm: no migration in progress.\n");
9987 curr_migr_unit
= info
->reshape_progress
/ blocks_per_unit
;
9988 /* check if array is alligned to copy area
9989 * if it is not alligned, add one to current migration unit value
9990 * this can happend on array reshape finish only
9992 if (info
->reshape_progress
% blocks_per_unit
)
9995 super
->migr_rec
->curr_migr_unit
=
9996 __cpu_to_le32(curr_migr_unit
);
9997 super
->migr_rec
->rec_status
= __cpu_to_le32(state
);
9998 super
->migr_rec
->dest_1st_member_lba
=
9999 __cpu_to_le32(curr_migr_unit
*
10000 __le32_to_cpu(super
->migr_rec
->dest_depth_per_unit
));
10001 if (write_imsm_migr_rec(st
) < 0) {
10002 dprintf("imsm: Cannot write migration record outside backup area\n");
10009 /*******************************************************************************
10010 * Function: recover_backup_imsm
10011 * Description: Function recovers critical data from the Migration Copy Area
10012 * while assembling an array.
10014 * super : imsm internal array info
10015 * info : general array info
10017 * 0 : success (or there is no data to recover)
10019 ******************************************************************************/
10020 int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
)
10022 struct intel_super
*super
= st
->sb
;
10023 struct migr_record
*migr_rec
= super
->migr_rec
;
10024 struct imsm_map
*map_dest
;
10025 struct intel_dev
*id
= NULL
;
10026 unsigned long long read_offset
;
10027 unsigned long long write_offset
;
10029 int *targets
= NULL
;
10030 int new_disks
, i
, err
;
10033 unsigned int sector_size
= super
->sector_size
;
10034 unsigned long curr_migr_unit
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
10035 unsigned long num_migr_units
= __le32_to_cpu(migr_rec
->num_migr_units
);
10037 int skipped_disks
= 0;
10039 err
= sysfs_get_str(info
, NULL
, "array_state", (char *)buffer
, 20);
10043 /* recover data only during assemblation */
10044 if (strncmp(buffer
, "inactive", 8) != 0)
10046 /* no data to recover */
10047 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
10049 if (curr_migr_unit
>= num_migr_units
)
10052 /* find device during reshape */
10053 for (id
= super
->devlist
; id
; id
= id
->next
)
10054 if (is_gen_migration(id
->dev
))
10059 map_dest
= get_imsm_map(id
->dev
, MAP_0
);
10060 new_disks
= map_dest
->num_members
;
10062 read_offset
= (unsigned long long)
10063 __le32_to_cpu(migr_rec
->ckpt_area_pba
) * 512;
10065 write_offset
= ((unsigned long long)
10066 __le32_to_cpu(migr_rec
->dest_1st_member_lba
) +
10067 pba_of_lba0(map_dest
)) * 512;
10069 unit_len
= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
10070 if (posix_memalign((void **)&buf
, sector_size
, unit_len
) != 0)
10072 targets
= xcalloc(new_disks
, sizeof(int));
10074 if (open_backup_targets(info
, new_disks
, targets
, super
, id
->dev
)) {
10075 pr_err("Cannot open some devices belonging to array.\n");
10079 for (i
= 0; i
< new_disks
; i
++) {
10080 if (targets
[i
] < 0) {
10084 if (lseek64(targets
[i
], read_offset
, SEEK_SET
) < 0) {
10085 pr_err("Cannot seek to block: %s\n",
10090 if ((unsigned)read(targets
[i
], buf
, unit_len
) != unit_len
) {
10091 pr_err("Cannot read copy area block: %s\n",
10096 if (lseek64(targets
[i
], write_offset
, SEEK_SET
) < 0) {
10097 pr_err("Cannot seek to block: %s\n",
10102 if ((unsigned)write(targets
[i
], buf
, unit_len
) != unit_len
) {
10103 pr_err("Cannot restore block: %s\n",
10110 if (skipped_disks
> imsm_get_allowed_degradation(info
->new_level
,
10114 pr_err("Cannot restore data from backup. Too many failed disks\n");
10118 if (save_checkpoint_imsm(st
, info
, UNIT_SRC_NORMAL
)) {
10119 /* ignore error == 2, this can mean end of reshape here
10121 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL) during restart\n");
10127 for (i
= 0; i
< new_disks
; i
++)
10136 static char disk_by_path
[] = "/dev/disk/by-path/";
10138 static const char *imsm_get_disk_controller_domain(const char *path
)
10140 char disk_path
[PATH_MAX
];
10144 strcpy(disk_path
, disk_by_path
);
10145 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
10146 if (stat(disk_path
, &st
) == 0) {
10147 struct sys_dev
* hba
;
10150 path
= devt_to_devpath(st
.st_rdev
);
10153 hba
= find_disk_attached_hba(-1, path
);
10154 if (hba
&& hba
->type
== SYS_DEV_SAS
)
10156 else if (hba
&& hba
->type
== SYS_DEV_SATA
)
10160 dprintf("path: %s hba: %s attached: %s\n",
10161 path
, (hba
) ? hba
->path
: "NULL", drv
);
10167 static char *imsm_find_array_devnm_by_subdev(int subdev
, char *container
)
10169 static char devnm
[32];
10170 char subdev_name
[20];
10171 struct mdstat_ent
*mdstat
;
10173 sprintf(subdev_name
, "%d", subdev
);
10174 mdstat
= mdstat_by_subdev(subdev_name
, container
);
10178 strcpy(devnm
, mdstat
->devnm
);
10179 free_mdstat(mdstat
);
10183 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
10184 struct geo_params
*geo
,
10185 int *old_raid_disks
,
10188 /* currently we only support increasing the number of devices
10189 * for a container. This increases the number of device for each
10190 * member array. They must all be RAID0 or RAID5.
10193 struct mdinfo
*info
, *member
;
10194 int devices_that_can_grow
= 0;
10196 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): st->devnm = (%s)\n", st
->devnm
);
10198 if (geo
->size
> 0 ||
10199 geo
->level
!= UnSet
||
10200 geo
->layout
!= UnSet
||
10201 geo
->chunksize
!= 0 ||
10202 geo
->raid_disks
== UnSet
) {
10203 dprintf("imsm: Container operation is allowed for raid disks number change only.\n");
10207 if (direction
== ROLLBACK_METADATA_CHANGES
) {
10208 dprintf("imsm: Metadata changes rollback is not supported for container operation.\n");
10212 info
= container_content_imsm(st
, NULL
);
10213 for (member
= info
; member
; member
= member
->next
) {
10216 dprintf("imsm: checking device_num: %i\n",
10217 member
->container_member
);
10219 if (geo
->raid_disks
<= member
->array
.raid_disks
) {
10220 /* we work on container for Online Capacity Expansion
10221 * only so raid_disks has to grow
10223 dprintf("imsm: for container operation raid disks increase is required\n");
10227 if (info
->array
.level
!= 0 && info
->array
.level
!= 5) {
10228 /* we cannot use this container with other raid level
10230 dprintf("imsm: for container operation wrong raid level (%i) detected\n",
10231 info
->array
.level
);
10234 /* check for platform support
10235 * for this raid level configuration
10237 struct intel_super
*super
= st
->sb
;
10238 if (!is_raid_level_supported(super
->orom
,
10239 member
->array
.level
,
10240 geo
->raid_disks
)) {
10241 dprintf("platform does not support raid%d with %d disk%s\n",
10244 geo
->raid_disks
> 1 ? "s" : "");
10247 /* check if component size is aligned to chunk size
10249 if (info
->component_size
%
10250 (info
->array
.chunk_size
/512)) {
10251 dprintf("Component size is not aligned to chunk size\n");
10256 if (*old_raid_disks
&&
10257 info
->array
.raid_disks
!= *old_raid_disks
)
10259 *old_raid_disks
= info
->array
.raid_disks
;
10261 /* All raid5 and raid0 volumes in container
10262 * have to be ready for Online Capacity Expansion
10263 * so they need to be assembled. We have already
10264 * checked that no recovery etc is happening.
10266 result
= imsm_find_array_devnm_by_subdev(member
->container_member
,
10267 st
->container_devnm
);
10268 if (result
== NULL
) {
10269 dprintf("imsm: cannot find array\n");
10272 devices_that_can_grow
++;
10275 if (!member
&& devices_that_can_grow
)
10279 dprintf("Container operation allowed\n");
10281 dprintf("Error: %i\n", ret_val
);
10286 /* Function: get_spares_for_grow
10287 * Description: Allocates memory and creates list of spare devices
10288 * avaliable in container. Checks if spare drive size is acceptable.
10289 * Parameters: Pointer to the supertype structure
10290 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
10293 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
10295 unsigned long long min_size
= min_acceptable_spare_size_imsm(st
);
10296 return container_choose_spares(st
, min_size
, NULL
, NULL
, NULL
, 0);
10299 /******************************************************************************
10300 * function: imsm_create_metadata_update_for_reshape
10301 * Function creates update for whole IMSM container.
10303 ******************************************************************************/
10304 static int imsm_create_metadata_update_for_reshape(
10305 struct supertype
*st
,
10306 struct geo_params
*geo
,
10307 int old_raid_disks
,
10308 struct imsm_update_reshape
**updatep
)
10310 struct intel_super
*super
= st
->sb
;
10311 struct imsm_super
*mpb
= super
->anchor
;
10312 int update_memory_size
;
10313 struct imsm_update_reshape
*u
;
10314 struct mdinfo
*spares
;
10317 struct mdinfo
*dev
;
10319 dprintf("(enter) raid_disks = %i\n", geo
->raid_disks
);
10321 delta_disks
= geo
->raid_disks
- old_raid_disks
;
10323 /* size of all update data without anchor */
10324 update_memory_size
= sizeof(struct imsm_update_reshape
);
10326 /* now add space for spare disks that we need to add. */
10327 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
10329 u
= xcalloc(1, update_memory_size
);
10330 u
->type
= update_reshape_container_disks
;
10331 u
->old_raid_disks
= old_raid_disks
;
10332 u
->new_raid_disks
= geo
->raid_disks
;
10334 /* now get spare disks list
10336 spares
= get_spares_for_grow(st
);
10339 || delta_disks
> spares
->array
.spare_disks
) {
10340 pr_err("imsm: ERROR: Cannot get spare devices for %s.\n", geo
->dev_name
);
10345 /* we have got spares
10346 * update disk list in imsm_disk list table in anchor
10348 dprintf("imsm: %i spares are available.\n\n",
10349 spares
->array
.spare_disks
);
10351 dev
= spares
->devs
;
10352 for (i
= 0; i
< delta_disks
; i
++) {
10357 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
10359 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
10360 dl
->index
= mpb
->num_disks
;
10368 sysfs_free(spares
);
10370 dprintf("imsm: reshape update preparation :");
10371 if (i
== delta_disks
) {
10372 dprintf_cont(" OK\n");
10374 return update_memory_size
;
10377 dprintf_cont(" Error\n");
10382 /******************************************************************************
10383 * function: imsm_create_metadata_update_for_size_change()
10384 * Creates update for IMSM array for array size change.
10386 ******************************************************************************/
10387 static int imsm_create_metadata_update_for_size_change(
10388 struct supertype
*st
,
10389 struct geo_params
*geo
,
10390 struct imsm_update_size_change
**updatep
)
10392 struct intel_super
*super
= st
->sb
;
10393 int update_memory_size
;
10394 struct imsm_update_size_change
*u
;
10396 dprintf("(enter) New size = %llu\n", geo
->size
);
10398 /* size of all update data without anchor */
10399 update_memory_size
= sizeof(struct imsm_update_size_change
);
10401 u
= xcalloc(1, update_memory_size
);
10402 u
->type
= update_size_change
;
10403 u
->subdev
= super
->current_vol
;
10404 u
->new_size
= geo
->size
;
10406 dprintf("imsm: reshape update preparation : OK\n");
10409 return update_memory_size
;
10412 /******************************************************************************
10413 * function: imsm_create_metadata_update_for_migration()
10414 * Creates update for IMSM array.
10416 ******************************************************************************/
10417 static int imsm_create_metadata_update_for_migration(
10418 struct supertype
*st
,
10419 struct geo_params
*geo
,
10420 struct imsm_update_reshape_migration
**updatep
)
10422 struct intel_super
*super
= st
->sb
;
10423 int update_memory_size
;
10424 struct imsm_update_reshape_migration
*u
;
10425 struct imsm_dev
*dev
;
10426 int previous_level
= -1;
10428 dprintf("(enter) New Level = %i\n", geo
->level
);
10430 /* size of all update data without anchor */
10431 update_memory_size
= sizeof(struct imsm_update_reshape_migration
);
10433 u
= xcalloc(1, update_memory_size
);
10434 u
->type
= update_reshape_migration
;
10435 u
->subdev
= super
->current_vol
;
10436 u
->new_level
= geo
->level
;
10437 u
->new_layout
= geo
->layout
;
10438 u
->new_raid_disks
= u
->old_raid_disks
= geo
->raid_disks
;
10439 u
->new_disks
[0] = -1;
10440 u
->new_chunksize
= -1;
10442 dev
= get_imsm_dev(super
, u
->subdev
);
10444 struct imsm_map
*map
;
10446 map
= get_imsm_map(dev
, MAP_0
);
10448 int current_chunk_size
=
10449 __le16_to_cpu(map
->blocks_per_strip
) / 2;
10451 if (geo
->chunksize
!= current_chunk_size
) {
10452 u
->new_chunksize
= geo
->chunksize
/ 1024;
10453 dprintf("imsm: chunk size change from %i to %i\n",
10454 current_chunk_size
, u
->new_chunksize
);
10456 previous_level
= map
->raid_level
;
10459 if (geo
->level
== 5 && previous_level
== 0) {
10460 struct mdinfo
*spares
= NULL
;
10462 u
->new_raid_disks
++;
10463 spares
= get_spares_for_grow(st
);
10464 if (spares
== NULL
|| spares
->array
.spare_disks
< 1) {
10466 sysfs_free(spares
);
10467 update_memory_size
= 0;
10468 dprintf("error: cannot get spare device for requested migration");
10471 sysfs_free(spares
);
10473 dprintf("imsm: reshape update preparation : OK\n");
10476 return update_memory_size
;
10479 static void imsm_update_metadata_locally(struct supertype
*st
,
10480 void *buf
, int len
)
10482 struct metadata_update mu
;
10487 mu
.space_list
= NULL
;
10489 if (imsm_prepare_update(st
, &mu
))
10490 imsm_process_update(st
, &mu
);
10492 while (mu
.space_list
) {
10493 void **space
= mu
.space_list
;
10494 mu
.space_list
= *space
;
10499 /***************************************************************************
10500 * Function: imsm_analyze_change
10501 * Description: Function analyze change for single volume
10502 * and validate if transition is supported
10503 * Parameters: Geometry parameters, supertype structure,
10504 * metadata change direction (apply/rollback)
10505 * Returns: Operation type code on success, -1 if fail
10506 ****************************************************************************/
10507 enum imsm_reshape_type
imsm_analyze_change(struct supertype
*st
,
10508 struct geo_params
*geo
,
10511 struct mdinfo info
;
10513 int check_devs
= 0;
10515 /* number of added/removed disks in operation result */
10516 int devNumChange
= 0;
10517 /* imsm compatible layout value for array geometry verification */
10518 int imsm_layout
= -1;
10520 struct imsm_dev
*dev
;
10521 struct intel_super
*super
;
10522 unsigned long long current_size
;
10523 unsigned long long free_size
;
10524 unsigned long long max_size
;
10527 getinfo_super_imsm_volume(st
, &info
, NULL
);
10528 if (geo
->level
!= info
.array
.level
&& geo
->level
>= 0 &&
10529 geo
->level
!= UnSet
) {
10530 switch (info
.array
.level
) {
10532 if (geo
->level
== 5) {
10533 change
= CH_MIGRATION
;
10534 if (geo
->layout
!= ALGORITHM_LEFT_ASYMMETRIC
) {
10535 pr_err("Error. Requested Layout not supported (left-asymmetric layout is supported only)!\n");
10537 goto analyse_change_exit
;
10539 imsm_layout
= geo
->layout
;
10541 devNumChange
= 1; /* parity disk added */
10542 } else if (geo
->level
== 10) {
10543 change
= CH_TAKEOVER
;
10545 devNumChange
= 2; /* two mirrors added */
10546 imsm_layout
= 0x102; /* imsm supported layout */
10551 if (geo
->level
== 0) {
10552 change
= CH_TAKEOVER
;
10554 devNumChange
= -(geo
->raid_disks
/2);
10555 imsm_layout
= 0; /* imsm raid0 layout */
10559 if (change
== -1) {
10560 pr_err("Error. Level Migration from %d to %d not supported!\n",
10561 info
.array
.level
, geo
->level
);
10562 goto analyse_change_exit
;
10565 geo
->level
= info
.array
.level
;
10567 if (geo
->layout
!= info
.array
.layout
&&
10568 (geo
->layout
!= UnSet
&& geo
->layout
!= -1)) {
10569 change
= CH_MIGRATION
;
10570 if (info
.array
.layout
== 0 && info
.array
.level
== 5 &&
10571 geo
->layout
== 5) {
10572 /* reshape 5 -> 4 */
10573 } else if (info
.array
.layout
== 5 && info
.array
.level
== 5 &&
10574 geo
->layout
== 0) {
10575 /* reshape 4 -> 5 */
10579 pr_err("Error. Layout Migration from %d to %d not supported!\n",
10580 info
.array
.layout
, geo
->layout
);
10582 goto analyse_change_exit
;
10585 geo
->layout
= info
.array
.layout
;
10586 if (imsm_layout
== -1)
10587 imsm_layout
= info
.array
.layout
;
10590 if (geo
->chunksize
> 0 && geo
->chunksize
!= UnSet
&&
10591 geo
->chunksize
!= info
.array
.chunk_size
) {
10592 if (info
.array
.level
== 10) {
10593 pr_err("Error. Chunk size change for RAID 10 is not supported.\n");
10595 goto analyse_change_exit
;
10597 change
= CH_MIGRATION
;
10599 geo
->chunksize
= info
.array
.chunk_size
;
10602 chunk
= geo
->chunksize
/ 1024;
10605 dev
= get_imsm_dev(super
, super
->current_vol
);
10606 data_disks
= imsm_num_data_members(dev
, MAP_0
);
10607 /* compute current size per disk member
10609 current_size
= info
.custom_array_size
/ data_disks
;
10611 if (geo
->size
> 0 && geo
->size
!= MAX_SIZE
) {
10612 /* align component size
10614 geo
->size
= imsm_component_size_aligment_check(
10615 get_imsm_raid_level(dev
->vol
.map
),
10616 chunk
* 1024, super
->sector_size
,
10618 if (geo
->size
== 0) {
10619 pr_err("Error. Size expansion is supported only (current size is %llu, requested size /rounded/ is 0).\n",
10621 goto analyse_change_exit
;
10625 if (current_size
!= geo
->size
&& geo
->size
> 0) {
10626 if (change
!= -1) {
10627 pr_err("Error. Size change should be the only one at a time.\n");
10629 goto analyse_change_exit
;
10631 if ((super
->current_vol
+ 1) != super
->anchor
->num_raid_devs
) {
10632 pr_err("Error. The last volume in container can be expanded only (%i/%s).\n",
10633 super
->current_vol
, st
->devnm
);
10634 goto analyse_change_exit
;
10636 /* check the maximum available size
10638 rv
= imsm_get_free_size(st
, dev
->vol
.map
->num_members
,
10639 0, chunk
, &free_size
);
10641 /* Cannot find maximum available space
10645 max_size
= free_size
+ current_size
;
10646 /* align component size
10648 max_size
= imsm_component_size_aligment_check(
10649 get_imsm_raid_level(dev
->vol
.map
),
10650 chunk
* 1024, super
->sector_size
,
10653 if (geo
->size
== MAX_SIZE
) {
10654 /* requested size change to the maximum available size
10656 if (max_size
== 0) {
10657 pr_err("Error. Cannot find maximum available space.\n");
10659 goto analyse_change_exit
;
10661 geo
->size
= max_size
;
10664 if (direction
== ROLLBACK_METADATA_CHANGES
) {
10665 /* accept size for rollback only
10668 /* round size due to metadata compatibility
10670 geo
->size
= (geo
->size
>> SECT_PER_MB_SHIFT
)
10671 << SECT_PER_MB_SHIFT
;
10672 dprintf("Prepare update for size change to %llu\n",
10674 if (current_size
>= geo
->size
) {
10675 pr_err("Error. Size expansion is supported only (current size is %llu, requested size /rounded/ is %llu).\n",
10676 current_size
, geo
->size
);
10677 goto analyse_change_exit
;
10679 if (max_size
&& geo
->size
> max_size
) {
10680 pr_err("Error. Requested size is larger than maximum available size (maximum available size is %llu, requested size /rounded/ is %llu).\n",
10681 max_size
, geo
->size
);
10682 goto analyse_change_exit
;
10685 geo
->size
*= data_disks
;
10686 geo
->raid_disks
= dev
->vol
.map
->num_members
;
10687 change
= CH_ARRAY_SIZE
;
10689 if (!validate_geometry_imsm(st
,
10692 geo
->raid_disks
+ devNumChange
,
10694 geo
->size
, INVALID_SECTORS
,
10699 struct intel_super
*super
= st
->sb
;
10700 struct imsm_super
*mpb
= super
->anchor
;
10702 if (mpb
->num_raid_devs
> 1) {
10703 pr_err("Error. Cannot perform operation on %s- for this operation it MUST be single array in container\n",
10709 analyse_change_exit
:
10710 if (direction
== ROLLBACK_METADATA_CHANGES
&&
10711 (change
== CH_MIGRATION
|| change
== CH_TAKEOVER
)) {
10712 dprintf("imsm: Metadata changes rollback is not supported for migration and takeover operations.\n");
10718 int imsm_takeover(struct supertype
*st
, struct geo_params
*geo
)
10720 struct intel_super
*super
= st
->sb
;
10721 struct imsm_update_takeover
*u
;
10723 u
= xmalloc(sizeof(struct imsm_update_takeover
));
10725 u
->type
= update_takeover
;
10726 u
->subarray
= super
->current_vol
;
10728 /* 10->0 transition */
10729 if (geo
->level
== 0)
10730 u
->direction
= R10_TO_R0
;
10732 /* 0->10 transition */
10733 if (geo
->level
== 10)
10734 u
->direction
= R0_TO_R10
;
10736 /* update metadata locally */
10737 imsm_update_metadata_locally(st
, u
,
10738 sizeof(struct imsm_update_takeover
));
10739 /* and possibly remotely */
10740 if (st
->update_tail
)
10741 append_metadata_update(st
, u
,
10742 sizeof(struct imsm_update_takeover
));
10749 static int imsm_reshape_super(struct supertype
*st
, unsigned long long size
,
10751 int layout
, int chunksize
, int raid_disks
,
10752 int delta_disks
, char *backup
, char *dev
,
10753 int direction
, int verbose
)
10756 struct geo_params geo
;
10758 dprintf("(enter)\n");
10760 memset(&geo
, 0, sizeof(struct geo_params
));
10762 geo
.dev_name
= dev
;
10763 strcpy(geo
.devnm
, st
->devnm
);
10766 geo
.layout
= layout
;
10767 geo
.chunksize
= chunksize
;
10768 geo
.raid_disks
= raid_disks
;
10769 if (delta_disks
!= UnSet
)
10770 geo
.raid_disks
+= delta_disks
;
10772 dprintf("for level : %i\n", geo
.level
);
10773 dprintf("for raid_disks : %i\n", geo
.raid_disks
);
10775 if (experimental() == 0)
10778 if (strcmp(st
->container_devnm
, st
->devnm
) == 0) {
10779 /* On container level we can only increase number of devices. */
10780 dprintf("imsm: info: Container operation\n");
10781 int old_raid_disks
= 0;
10783 if (imsm_reshape_is_allowed_on_container(
10784 st
, &geo
, &old_raid_disks
, direction
)) {
10785 struct imsm_update_reshape
*u
= NULL
;
10788 len
= imsm_create_metadata_update_for_reshape(
10789 st
, &geo
, old_raid_disks
, &u
);
10792 dprintf("imsm: Cannot prepare update\n");
10793 goto exit_imsm_reshape_super
;
10797 /* update metadata locally */
10798 imsm_update_metadata_locally(st
, u
, len
);
10799 /* and possibly remotely */
10800 if (st
->update_tail
)
10801 append_metadata_update(st
, u
, len
);
10806 pr_err("(imsm) Operation is not allowed on this container\n");
10809 /* On volume level we support following operations
10810 * - takeover: raid10 -> raid0; raid0 -> raid10
10811 * - chunk size migration
10812 * - migration: raid5 -> raid0; raid0 -> raid5
10814 struct intel_super
*super
= st
->sb
;
10815 struct intel_dev
*dev
= super
->devlist
;
10817 dprintf("imsm: info: Volume operation\n");
10818 /* find requested device */
10821 imsm_find_array_devnm_by_subdev(
10822 dev
->index
, st
->container_devnm
);
10823 if (devnm
&& strcmp(devnm
, geo
.devnm
) == 0)
10828 pr_err("Cannot find %s (%s) subarray\n",
10829 geo
.dev_name
, geo
.devnm
);
10830 goto exit_imsm_reshape_super
;
10832 super
->current_vol
= dev
->index
;
10833 change
= imsm_analyze_change(st
, &geo
, direction
);
10836 ret_val
= imsm_takeover(st
, &geo
);
10838 case CH_MIGRATION
: {
10839 struct imsm_update_reshape_migration
*u
= NULL
;
10841 imsm_create_metadata_update_for_migration(
10844 dprintf("imsm: Cannot prepare update\n");
10848 /* update metadata locally */
10849 imsm_update_metadata_locally(st
, u
, len
);
10850 /* and possibly remotely */
10851 if (st
->update_tail
)
10852 append_metadata_update(st
, u
, len
);
10857 case CH_ARRAY_SIZE
: {
10858 struct imsm_update_size_change
*u
= NULL
;
10860 imsm_create_metadata_update_for_size_change(
10863 dprintf("imsm: Cannot prepare update\n");
10867 /* update metadata locally */
10868 imsm_update_metadata_locally(st
, u
, len
);
10869 /* and possibly remotely */
10870 if (st
->update_tail
)
10871 append_metadata_update(st
, u
, len
);
10881 exit_imsm_reshape_super
:
10882 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
10886 #define COMPLETED_OK 0
10887 #define COMPLETED_NONE 1
10888 #define COMPLETED_DELAYED 2
10890 static int read_completed(int fd
, unsigned long long *val
)
10895 ret
= sysfs_fd_get_str(fd
, buf
, 50);
10899 ret
= COMPLETED_OK
;
10900 if (strncmp(buf
, "none", 4) == 0) {
10901 ret
= COMPLETED_NONE
;
10902 } else if (strncmp(buf
, "delayed", 7) == 0) {
10903 ret
= COMPLETED_DELAYED
;
10906 *val
= strtoull(buf
, &ep
, 0);
10907 if (ep
== buf
|| (*ep
!= 0 && *ep
!= '\n' && *ep
!= ' '))
10913 /*******************************************************************************
10914 * Function: wait_for_reshape_imsm
10915 * Description: Function writes new sync_max value and waits until
10916 * reshape process reach new position
10918 * sra : general array info
10919 * ndata : number of disks in new array's layout
10922 * 1 : there is no reshape in progress,
10924 ******************************************************************************/
10925 int wait_for_reshape_imsm(struct mdinfo
*sra
, int ndata
)
10927 int fd
= sysfs_get_fd(sra
, NULL
, "sync_completed");
10929 unsigned long long completed
;
10930 /* to_complete : new sync_max position */
10931 unsigned long long to_complete
= sra
->reshape_progress
;
10932 unsigned long long position_to_set
= to_complete
/ ndata
;
10935 dprintf("cannot open reshape_position\n");
10940 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
10942 dprintf("cannot read reshape_position (no reshape in progres)\n");
10951 if (completed
> position_to_set
) {
10952 dprintf("wrong next position to set %llu (%llu)\n",
10953 to_complete
, position_to_set
);
10957 dprintf("Position set: %llu\n", position_to_set
);
10958 if (sysfs_set_num(sra
, NULL
, "sync_max",
10959 position_to_set
) != 0) {
10960 dprintf("cannot set reshape position to %llu\n",
10969 int timeout
= 3000;
10971 sysfs_wait(fd
, &timeout
);
10972 if (sysfs_get_str(sra
, NULL
, "sync_action",
10974 strncmp(action
, "reshape", 7) != 0) {
10975 if (strncmp(action
, "idle", 4) == 0)
10981 rc
= read_completed(fd
, &completed
);
10983 dprintf("cannot read reshape_position (in loop)\n");
10986 } else if (rc
== COMPLETED_NONE
)
10988 } while (completed
< position_to_set
);
10994 /*******************************************************************************
10995 * Function: check_degradation_change
10996 * Description: Check that array hasn't become failed.
10998 * info : for sysfs access
10999 * sources : source disks descriptors
11000 * degraded: previous degradation level
11002 * degradation level
11003 ******************************************************************************/
11004 int check_degradation_change(struct mdinfo
*info
,
11008 unsigned long long new_degraded
;
11011 rv
= sysfs_get_ll(info
, NULL
, "degraded", &new_degraded
);
11012 if (rv
== -1 || (new_degraded
!= (unsigned long long)degraded
)) {
11013 /* check each device to ensure it is still working */
11016 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
11017 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
11019 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
11022 if (sysfs_get_str(info
,
11023 sd
, "state", sbuf
, sizeof(sbuf
)) < 0 ||
11024 strstr(sbuf
, "faulty") ||
11025 strstr(sbuf
, "in_sync") == NULL
) {
11026 /* this device is dead */
11027 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
11028 if (sd
->disk
.raid_disk
>= 0 &&
11029 sources
[sd
->disk
.raid_disk
] >= 0) {
11031 sd
->disk
.raid_disk
]);
11032 sources
[sd
->disk
.raid_disk
] =
11041 return new_degraded
;
11044 /*******************************************************************************
11045 * Function: imsm_manage_reshape
11046 * Description: Function finds array under reshape and it manages reshape
11047 * process. It creates stripes backups (if required) and sets
11050 * afd : Backup handle (nattive) - not used
11051 * sra : general array info
11052 * reshape : reshape parameters - not used
11053 * st : supertype structure
11054 * blocks : size of critical section [blocks]
11055 * fds : table of source device descriptor
11056 * offsets : start of array (offest per devices)
11058 * destfd : table of destination device descriptor
11059 * destoffsets : table of destination offsets (per device)
11061 * 1 : success, reshape is done
11063 ******************************************************************************/
11064 static int imsm_manage_reshape(
11065 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
11066 struct supertype
*st
, unsigned long backup_blocks
,
11067 int *fds
, unsigned long long *offsets
,
11068 int dests
, int *destfd
, unsigned long long *destoffsets
)
11071 struct intel_super
*super
= st
->sb
;
11072 struct intel_dev
*dv
;
11073 unsigned int sector_size
= super
->sector_size
;
11074 struct imsm_dev
*dev
= NULL
;
11075 struct imsm_map
*map_src
;
11076 int migr_vol_qan
= 0;
11077 int ndata
, odata
; /* [bytes] */
11078 int chunk
; /* [bytes] */
11079 struct migr_record
*migr_rec
;
11081 unsigned int buf_size
; /* [bytes] */
11082 unsigned long long max_position
; /* array size [bytes] */
11083 unsigned long long next_step
; /* [blocks]/[bytes] */
11084 unsigned long long old_data_stripe_length
;
11085 unsigned long long start_src
; /* [bytes] */
11086 unsigned long long start
; /* [bytes] */
11087 unsigned long long start_buf_shift
; /* [bytes] */
11089 int source_layout
= 0;
11094 if (!fds
|| !offsets
)
11097 /* Find volume during the reshape */
11098 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
11099 if (dv
->dev
->vol
.migr_type
== MIGR_GEN_MIGR
11100 && dv
->dev
->vol
.migr_state
== 1) {
11105 /* Only one volume can migrate at the same time */
11106 if (migr_vol_qan
!= 1) {
11107 pr_err("%s", migr_vol_qan
?
11108 "Number of migrating volumes greater than 1\n" :
11109 "There is no volume during migrationg\n");
11113 map_src
= get_imsm_map(dev
, MAP_1
);
11114 if (map_src
== NULL
)
11117 ndata
= imsm_num_data_members(dev
, MAP_0
);
11118 odata
= imsm_num_data_members(dev
, MAP_1
);
11120 chunk
= __le16_to_cpu(map_src
->blocks_per_strip
) * 512;
11121 old_data_stripe_length
= odata
* chunk
;
11123 migr_rec
= super
->migr_rec
;
11125 /* initialize migration record for start condition */
11126 if (sra
->reshape_progress
== 0)
11127 init_migr_record_imsm(st
, dev
, sra
);
11129 if (__le32_to_cpu(migr_rec
->rec_status
) != UNIT_SRC_NORMAL
) {
11130 dprintf("imsm: cannot restart migration when data are present in copy area.\n");
11133 /* Save checkpoint to update migration record for current
11134 * reshape position (in md). It can be farther than current
11135 * reshape position in metadata.
11137 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
11138 /* ignore error == 2, this can mean end of reshape here
11140 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL, initial save)\n");
11145 /* size for data */
11146 buf_size
= __le32_to_cpu(migr_rec
->blocks_per_unit
) * 512;
11147 /* extend buffer size for parity disk */
11148 buf_size
+= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
11149 /* add space for stripe aligment */
11150 buf_size
+= old_data_stripe_length
;
11151 if (posix_memalign((void **)&buf
, MAX_SECTOR_SIZE
, buf_size
)) {
11152 dprintf("imsm: Cannot allocate checkpoint buffer\n");
11156 max_position
= sra
->component_size
* ndata
;
11157 source_layout
= imsm_level_to_layout(map_src
->raid_level
);
11159 while (__le32_to_cpu(migr_rec
->curr_migr_unit
) <
11160 __le32_to_cpu(migr_rec
->num_migr_units
)) {
11161 /* current reshape position [blocks] */
11162 unsigned long long current_position
=
11163 __le32_to_cpu(migr_rec
->blocks_per_unit
)
11164 * __le32_to_cpu(migr_rec
->curr_migr_unit
);
11165 unsigned long long border
;
11167 /* Check that array hasn't become failed.
11169 degraded
= check_degradation_change(sra
, fds
, degraded
);
11170 if (degraded
> 1) {
11171 dprintf("imsm: Abort reshape due to degradation level (%i)\n", degraded
);
11175 next_step
= __le32_to_cpu(migr_rec
->blocks_per_unit
);
11177 if ((current_position
+ next_step
) > max_position
)
11178 next_step
= max_position
- current_position
;
11180 start
= current_position
* 512;
11182 /* align reading start to old geometry */
11183 start_buf_shift
= start
% old_data_stripe_length
;
11184 start_src
= start
- start_buf_shift
;
11186 border
= (start_src
/ odata
) - (start
/ ndata
);
11188 if (border
<= __le32_to_cpu(migr_rec
->dest_depth_per_unit
)) {
11189 /* save critical stripes to buf
11190 * start - start address of current unit
11191 * to backup [bytes]
11192 * start_src - start address of current unit
11193 * to backup alligned to source array
11196 unsigned long long next_step_filler
;
11197 unsigned long long copy_length
= next_step
* 512;
11199 /* allign copy area length to stripe in old geometry */
11200 next_step_filler
= ((copy_length
+ start_buf_shift
)
11201 % old_data_stripe_length
);
11202 if (next_step_filler
)
11203 next_step_filler
= (old_data_stripe_length
11204 - next_step_filler
);
11205 dprintf("save_stripes() parameters: start = %llu,\tstart_src = %llu,\tnext_step*512 = %llu,\tstart_in_buf_shift = %llu,\tnext_step_filler = %llu\n",
11206 start
, start_src
, copy_length
,
11207 start_buf_shift
, next_step_filler
);
11209 if (save_stripes(fds
, offsets
, map_src
->num_members
,
11210 chunk
, map_src
->raid_level
,
11211 source_layout
, 0, NULL
, start_src
,
11213 next_step_filler
+ start_buf_shift
,
11215 dprintf("imsm: Cannot save stripes to buffer\n");
11218 /* Convert data to destination format and store it
11219 * in backup general migration area
11221 if (save_backup_imsm(st
, dev
, sra
,
11222 buf
+ start_buf_shift
, copy_length
)) {
11223 dprintf("imsm: Cannot save stripes to target devices\n");
11226 if (save_checkpoint_imsm(st
, sra
,
11227 UNIT_SRC_IN_CP_AREA
)) {
11228 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_IN_CP_AREA)\n");
11232 /* set next step to use whole border area */
11233 border
/= next_step
;
11235 next_step
*= border
;
11237 /* When data backed up, checkpoint stored,
11238 * kick the kernel to reshape unit of data
11240 next_step
= next_step
+ sra
->reshape_progress
;
11241 /* limit next step to array max position */
11242 if (next_step
> max_position
)
11243 next_step
= max_position
;
11244 sysfs_set_num(sra
, NULL
, "suspend_lo", sra
->reshape_progress
);
11245 sysfs_set_num(sra
, NULL
, "suspend_hi", next_step
);
11246 sra
->reshape_progress
= next_step
;
11248 /* wait until reshape finish */
11249 if (wait_for_reshape_imsm(sra
, ndata
)) {
11250 dprintf("wait_for_reshape_imsm returned error!\n");
11256 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
11257 /* ignore error == 2, this can mean end of reshape here
11259 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL)\n");
11265 /* clear migr_rec on disks after successful migration */
11268 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SECTORS
*sector_size
);
11269 for (d
= super
->disks
; d
; d
= d
->next
) {
11270 if (d
->index
< 0 || is_failed(&d
->disk
))
11272 unsigned long long dsize
;
11274 get_dev_size(d
->fd
, NULL
, &dsize
);
11275 if (lseek64(d
->fd
, dsize
- MIGR_REC_SECTOR_POSITION
*sector_size
,
11277 if (write(d
->fd
, super
->migr_rec_buf
,
11278 MIGR_REC_BUF_SECTORS
*sector_size
) !=
11279 MIGR_REC_BUF_SECTORS
*sector_size
)
11280 perror("Write migr_rec failed");
11284 /* return '1' if done */
11288 /* See Grow.c: abort_reshape() for further explanation */
11289 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
11290 sysfs_set_num(sra
, NULL
, "suspend_hi", 0);
11291 sysfs_set_num(sra
, NULL
, "suspend_lo", 0);
11296 #endif /* MDASSEMBLE */
11298 struct superswitch super_imsm
= {
11300 .examine_super
= examine_super_imsm
,
11301 .brief_examine_super
= brief_examine_super_imsm
,
11302 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
11303 .export_examine_super
= export_examine_super_imsm
,
11304 .detail_super
= detail_super_imsm
,
11305 .brief_detail_super
= brief_detail_super_imsm
,
11306 .write_init_super
= write_init_super_imsm
,
11307 .validate_geometry
= validate_geometry_imsm
,
11308 .add_to_super
= add_to_super_imsm
,
11309 .remove_from_super
= remove_from_super_imsm
,
11310 .detail_platform
= detail_platform_imsm
,
11311 .export_detail_platform
= export_detail_platform_imsm
,
11312 .kill_subarray
= kill_subarray_imsm
,
11313 .update_subarray
= update_subarray_imsm
,
11314 .load_container
= load_container_imsm
,
11315 .default_geometry
= default_geometry_imsm
,
11316 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
11317 .reshape_super
= imsm_reshape_super
,
11318 .manage_reshape
= imsm_manage_reshape
,
11319 .recover_backup
= recover_backup_imsm
,
11320 .copy_metadata
= copy_metadata_imsm
,
11322 .match_home
= match_home_imsm
,
11323 .uuid_from_super
= uuid_from_super_imsm
,
11324 .getinfo_super
= getinfo_super_imsm
,
11325 .getinfo_super_disks
= getinfo_super_disks_imsm
,
11326 .update_super
= update_super_imsm
,
11328 .avail_size
= avail_size_imsm
,
11329 .min_acceptable_spare_size
= min_acceptable_spare_size_imsm
,
11331 .compare_super
= compare_super_imsm
,
11333 .load_super
= load_super_imsm
,
11334 .init_super
= init_super_imsm
,
11335 .store_super
= store_super_imsm
,
11336 .free_super
= free_super_imsm
,
11337 .match_metadata_desc
= match_metadata_desc_imsm
,
11338 .container_content
= container_content_imsm
,
11339 .validate_container
= validate_container_imsm
,
11346 .open_new
= imsm_open_new
,
11347 .set_array_state
= imsm_set_array_state
,
11348 .set_disk
= imsm_set_disk
,
11349 .sync_metadata
= imsm_sync_metadata
,
11350 .activate_spare
= imsm_activate_spare
,
11351 .process_update
= imsm_process_update
,
11352 .prepare_update
= imsm_prepare_update
,
11353 .record_bad_block
= imsm_record_badblock
,
11354 #endif /* MDASSEMBLE */