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
95 #define MULTIPLE_PPL_AREA_SIZE_IMSM (1024 * 1024) /* Size of the whole
99 /* Disk configuration info. */
100 #define IMSM_MAX_DEVICES 255
102 __u8 serial
[MAX_RAID_SERIAL_LEN
];/* 0xD8 - 0xE7 ascii serial number */
103 __u32 total_blocks_lo
; /* 0xE8 - 0xEB total blocks lo */
104 __u32 scsi_id
; /* 0xEC - 0xEF scsi ID */
105 #define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
106 #define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
107 #define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
108 #define JOURNAL_DISK __cpu_to_le32(0x2000000) /* Device marked as Journaling Drive */
109 __u32 status
; /* 0xF0 - 0xF3 */
110 __u32 owner_cfg_num
; /* which config 0,1,2... owns this disk */
111 __u32 total_blocks_hi
; /* 0xF4 - 0xF5 total blocks hi */
112 #define IMSM_DISK_FILLERS 3
113 __u32 filler
[IMSM_DISK_FILLERS
]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
116 /* map selector for map managment
122 /* RAID map configuration infos. */
124 __u32 pba_of_lba0_lo
; /* start address of partition */
125 __u32 blocks_per_member_lo
;/* blocks per member */
126 __u32 num_data_stripes_lo
; /* number of data stripes */
127 __u16 blocks_per_strip
;
128 __u8 map_state
; /* Normal, Uninitialized, Degraded, Failed */
129 #define IMSM_T_STATE_NORMAL 0
130 #define IMSM_T_STATE_UNINITIALIZED 1
131 #define IMSM_T_STATE_DEGRADED 2
132 #define IMSM_T_STATE_FAILED 3
134 #define IMSM_T_RAID0 0
135 #define IMSM_T_RAID1 1
136 #define IMSM_T_RAID5 5 /* since metadata version 1.2.02 ? */
137 __u8 num_members
; /* number of member disks */
138 __u8 num_domains
; /* number of parity domains */
139 __u8 failed_disk_num
; /* valid only when state is degraded */
141 __u32 pba_of_lba0_hi
;
142 __u32 blocks_per_member_hi
;
143 __u32 num_data_stripes_hi
;
144 __u32 filler
[4]; /* expansion area */
145 #define IMSM_ORD_REBUILD (1 << 24)
146 __u32 disk_ord_tbl
[1]; /* disk_ord_tbl[num_members],
147 * top byte contains some flags
149 } __attribute__ ((packed
));
152 __u32 curr_migr_unit
;
153 __u32 checkpoint_id
; /* id to access curr_migr_unit */
154 __u8 migr_state
; /* Normal or Migrating */
156 #define MIGR_REBUILD 1
157 #define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
158 #define MIGR_GEN_MIGR 3
159 #define MIGR_STATE_CHANGE 4
160 #define MIGR_REPAIR 5
161 __u8 migr_type
; /* Initializing, Rebuilding, ... */
162 #define RAIDVOL_CLEAN 0
163 #define RAIDVOL_DIRTY 1
164 #define RAIDVOL_DSRECORD_VALID 2
166 __u8 fs_state
; /* fast-sync state for CnG (0xff == disabled) */
167 __u16 verify_errors
; /* number of mismatches */
168 __u16 bad_blocks
; /* number of bad blocks during verify */
170 struct imsm_map map
[1];
171 /* here comes another one if migr_state */
172 } __attribute__ ((packed
));
175 __u8 volume
[MAX_RAID_SERIAL_LEN
];
178 #define DEV_BOOTABLE __cpu_to_le32(0x01)
179 #define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
180 #define DEV_READ_COALESCING __cpu_to_le32(0x04)
181 #define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
182 #define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
183 #define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
184 #define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
185 #define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
186 #define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
187 #define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
188 #define DEV_CLONE_N_GO __cpu_to_le32(0x400)
189 #define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
190 #define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
191 __u32 status
; /* Persistent RaidDev status */
192 __u32 reserved_blocks
; /* Reserved blocks at beginning of volume */
196 __u8 cng_master_disk
;
200 __u16 my_vol_raid_dev_num
; /* Used in Unique volume Id for this RaidDev */
206 /* Unique Volume Id of the NvCache Volume associated with this volume */
207 __u32 nvc_vol_orig_family_num
;
208 __u16 nvc_vol_raid_dev_num
;
211 #define RWH_DISTRIBUTED 1
212 #define RWH_JOURNALING_DRIVE 2
213 #define RWH_MULTIPLE_DISTRIBUTED 3
214 #define RWH_MULTIPLE_PPLS_JOURNALING_DRIVE 4
215 #define RWH_MULTIPLE_OFF 5
216 __u8 rwh_policy
; /* Raid Write Hole Policy */
217 __u8 jd_serial
[MAX_RAID_SERIAL_LEN
]; /* Journal Drive serial number */
220 #define IMSM_DEV_FILLERS 3
221 __u32 filler
[IMSM_DEV_FILLERS
];
223 } __attribute__ ((packed
));
226 __u8 sig
[MAX_SIGNATURE_LENGTH
]; /* 0x00 - 0x1F */
227 __u32 check_sum
; /* 0x20 - 0x23 MPB Checksum */
228 __u32 mpb_size
; /* 0x24 - 0x27 Size of MPB */
229 __u32 family_num
; /* 0x28 - 0x2B Checksum from first time this config was written */
230 __u32 generation_num
; /* 0x2C - 0x2F Incremented each time this array's MPB is written */
231 __u32 error_log_size
; /* 0x30 - 0x33 in bytes */
232 __u32 attributes
; /* 0x34 - 0x37 */
233 __u8 num_disks
; /* 0x38 Number of configured disks */
234 __u8 num_raid_devs
; /* 0x39 Number of configured volumes */
235 __u8 error_log_pos
; /* 0x3A */
236 __u8 fill
[1]; /* 0x3B */
237 __u32 cache_size
; /* 0x3c - 0x40 in mb */
238 __u32 orig_family_num
; /* 0x40 - 0x43 original family num */
239 __u32 pwr_cycle_count
; /* 0x44 - 0x47 simulated power cycle count for array */
240 __u32 bbm_log_size
; /* 0x48 - 0x4B - size of bad Block Mgmt Log in bytes */
241 __u16 num_raid_devs_created
; /* 0x4C - 0x4D Used for generating unique
242 * volume IDs for raid_dev created in this array
245 __u16 filler1
; /* 0x4E - 0x4F */
246 #define IMSM_FILLERS 34
247 __u32 filler
[IMSM_FILLERS
]; /* 0x50 - 0xD7 RAID_MPB_FILLERS */
248 struct imsm_disk disk
[1]; /* 0xD8 diskTbl[numDisks] */
249 /* here comes imsm_dev[num_raid_devs] */
250 /* here comes BBM logs */
251 } __attribute__ ((packed
));
253 #define BBM_LOG_MAX_ENTRIES 254
254 #define BBM_LOG_MAX_LBA_ENTRY_VAL 256 /* Represents 256 LBAs */
255 #define BBM_LOG_SIGNATURE 0xabadb10c
257 struct bbm_log_block_addr
{
260 } __attribute__ ((__packed__
));
262 struct bbm_log_entry
{
263 __u8 marked_count
; /* Number of blocks marked - 1 */
264 __u8 disk_ordinal
; /* Disk entry within the imsm_super */
265 struct bbm_log_block_addr defective_block_start
;
266 } __attribute__ ((__packed__
));
269 __u32 signature
; /* 0xABADB10C */
271 struct bbm_log_entry marked_block_entries
[BBM_LOG_MAX_ENTRIES
];
272 } __attribute__ ((__packed__
));
274 static char *map_state_str
[] = { "normal", "uninitialized", "degraded", "failed" };
276 #define BLOCKS_PER_KB (1024/512)
278 #define RAID_DISK_RESERVED_BLOCKS_IMSM_HI 2209
280 #define GEN_MIGR_AREA_SIZE 2048 /* General Migration Copy Area size in blocks */
282 #define MIGR_REC_BUF_SECTORS 1 /* size of migr_record i/o buffer in sectors */
283 #define MIGR_REC_SECTOR_POSITION 1 /* migr_record position offset on disk,
284 * MIGR_REC_BUF_SECTORS <= MIGR_REC_SECTOR_POS
287 #define UNIT_SRC_NORMAL 0 /* Source data for curr_migr_unit must
288 * be recovered using srcMap */
289 #define UNIT_SRC_IN_CP_AREA 1 /* Source data for curr_migr_unit has
290 * already been migrated and must
291 * be recovered from checkpoint area */
293 #define PPL_ENTRY_SPACE (128 * 1024) /* Size of single PPL, without the header */
296 __u32 rec_status
; /* Status used to determine how to restart
297 * migration in case it aborts
299 __u32 curr_migr_unit
; /* 0..numMigrUnits-1 */
300 __u32 family_num
; /* Family number of MPB
301 * containing the RaidDev
302 * that is migrating */
303 __u32 ascending_migr
; /* True if migrating in increasing
305 __u32 blocks_per_unit
; /* Num disk blocks per unit of operation */
306 __u32 dest_depth_per_unit
; /* Num member blocks each destMap
308 * advances per unit-of-operation */
309 __u32 ckpt_area_pba
; /* Pba of first block of ckpt copy area */
310 __u32 dest_1st_member_lba
; /* First member lba on first
311 * stripe of destination */
312 __u32 num_migr_units
; /* Total num migration units-of-op */
313 __u32 post_migr_vol_cap
; /* Size of volume after
314 * migration completes */
315 __u32 post_migr_vol_cap_hi
; /* Expansion space for LBA64 */
316 __u32 ckpt_read_disk_num
; /* Which member disk in destSubMap[0] the
317 * migration ckpt record was read from
318 * (for recovered migrations) */
319 } __attribute__ ((__packed__
));
324 * 2: metadata does not match
332 struct md_list
*next
;
335 #define pr_vrb(fmt, arg...) (void) (verbose && pr_err(fmt, ##arg))
337 static __u8
migr_type(struct imsm_dev
*dev
)
339 if (dev
->vol
.migr_type
== MIGR_VERIFY
&&
340 dev
->status
& DEV_VERIFY_AND_FIX
)
343 return dev
->vol
.migr_type
;
346 static void set_migr_type(struct imsm_dev
*dev
, __u8 migr_type
)
348 /* for compatibility with older oroms convert MIGR_REPAIR, into
349 * MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status
351 if (migr_type
== MIGR_REPAIR
) {
352 dev
->vol
.migr_type
= MIGR_VERIFY
;
353 dev
->status
|= DEV_VERIFY_AND_FIX
;
355 dev
->vol
.migr_type
= migr_type
;
356 dev
->status
&= ~DEV_VERIFY_AND_FIX
;
360 static unsigned int sector_count(__u32 bytes
, unsigned int sector_size
)
362 return ROUND_UP(bytes
, sector_size
) / sector_size
;
365 static unsigned int mpb_sectors(struct imsm_super
*mpb
,
366 unsigned int sector_size
)
368 return sector_count(__le32_to_cpu(mpb
->mpb_size
), sector_size
);
372 struct imsm_dev
*dev
;
373 struct intel_dev
*next
;
378 enum sys_dev_type type
;
381 struct intel_hba
*next
;
388 /* internal representation of IMSM metadata */
391 void *buf
; /* O_DIRECT buffer for reading/writing metadata */
392 struct imsm_super
*anchor
; /* immovable parameters */
395 void *migr_rec_buf
; /* buffer for I/O operations */
396 struct migr_record
*migr_rec
; /* migration record */
398 int clean_migration_record_by_mdmon
; /* when reshape is switched to next
399 array, it indicates that mdmon is allowed to clean migration
401 size_t len
; /* size of the 'buf' allocation */
402 size_t extra_space
; /* extra space in 'buf' that is not used yet */
403 void *next_buf
; /* for realloc'ing buf from the manager */
405 int updates_pending
; /* count of pending updates for mdmon */
406 int current_vol
; /* index of raid device undergoing creation */
407 unsigned long long create_offset
; /* common start for 'current_vol' */
408 __u32 random
; /* random data for seeding new family numbers */
409 struct intel_dev
*devlist
;
410 unsigned int sector_size
; /* sector size of used member drives */
414 __u8 serial
[MAX_RAID_SERIAL_LEN
];
417 struct imsm_disk disk
;
420 struct extent
*e
; /* for determining freespace @ create */
421 int raiddisk
; /* slot to fill in autolayout */
423 } *disks
, *current_disk
;
424 struct dl
*disk_mgmt_list
; /* list of disks to add/remove while mdmon
426 struct dl
*missing
; /* disks removed while we weren't looking */
427 struct bbm_log
*bbm_log
;
428 struct intel_hba
*hba
; /* device path of the raid controller for this metadata */
429 const struct imsm_orom
*orom
; /* platform firmware support */
430 struct intel_super
*next
; /* (temp) list for disambiguating family_num */
431 struct md_bb bb
; /* memory for get_bad_blocks call */
435 struct imsm_disk disk
;
436 #define IMSM_UNKNOWN_OWNER (-1)
438 struct intel_disk
*next
;
442 unsigned long long start
, size
;
445 /* definitions of reshape process types */
446 enum imsm_reshape_type
{
452 /* definition of messages passed to imsm_process_update */
453 enum imsm_update_type
{
454 update_activate_spare
,
458 update_add_remove_disk
,
459 update_reshape_container_disks
,
460 update_reshape_migration
,
462 update_general_migration_checkpoint
,
464 update_prealloc_badblocks_mem
,
468 struct imsm_update_activate_spare
{
469 enum imsm_update_type type
;
473 struct imsm_update_activate_spare
*next
;
479 unsigned long long size
;
486 enum takeover_direction
{
490 struct imsm_update_takeover
{
491 enum imsm_update_type type
;
493 enum takeover_direction direction
;
496 struct imsm_update_reshape
{
497 enum imsm_update_type type
;
501 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
504 struct imsm_update_reshape_migration
{
505 enum imsm_update_type type
;
508 /* fields for array migration changes
515 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
518 struct imsm_update_size_change
{
519 enum imsm_update_type type
;
524 struct imsm_update_general_migration_checkpoint
{
525 enum imsm_update_type type
;
526 __u32 curr_migr_unit
;
530 __u8 serial
[MAX_RAID_SERIAL_LEN
];
533 struct imsm_update_create_array
{
534 enum imsm_update_type type
;
539 struct imsm_update_kill_array
{
540 enum imsm_update_type type
;
544 struct imsm_update_rename_array
{
545 enum imsm_update_type type
;
546 __u8 name
[MAX_RAID_SERIAL_LEN
];
550 struct imsm_update_add_remove_disk
{
551 enum imsm_update_type type
;
554 struct imsm_update_prealloc_bb_mem
{
555 enum imsm_update_type type
;
558 struct imsm_update_rwh_policy
{
559 enum imsm_update_type type
;
564 static const char *_sys_dev_type
[] = {
565 [SYS_DEV_UNKNOWN
] = "Unknown",
566 [SYS_DEV_SAS
] = "SAS",
567 [SYS_DEV_SATA
] = "SATA",
568 [SYS_DEV_NVME
] = "NVMe",
569 [SYS_DEV_VMD
] = "VMD"
572 const char *get_sys_dev_type(enum sys_dev_type type
)
574 if (type
>= SYS_DEV_MAX
)
575 type
= SYS_DEV_UNKNOWN
;
577 return _sys_dev_type
[type
];
580 static struct intel_hba
* alloc_intel_hba(struct sys_dev
*device
)
582 struct intel_hba
*result
= xmalloc(sizeof(*result
));
584 result
->type
= device
->type
;
585 result
->path
= xstrdup(device
->path
);
587 if (result
->path
&& (result
->pci_id
= strrchr(result
->path
, '/')) != NULL
)
593 static struct intel_hba
* find_intel_hba(struct intel_hba
*hba
, struct sys_dev
*device
)
595 struct intel_hba
*result
;
597 for (result
= hba
; result
; result
= result
->next
) {
598 if (result
->type
== device
->type
&& strcmp(result
->path
, device
->path
) == 0)
604 static int attach_hba_to_super(struct intel_super
*super
, struct sys_dev
*device
)
606 struct intel_hba
*hba
;
608 /* check if disk attached to Intel HBA */
609 hba
= find_intel_hba(super
->hba
, device
);
612 /* Check if HBA is already attached to super */
613 if (super
->hba
== NULL
) {
614 super
->hba
= alloc_intel_hba(device
);
619 /* Intel metadata allows for all disks attached to the same type HBA.
620 * Do not support HBA types mixing
622 if (device
->type
!= hba
->type
)
625 /* Multiple same type HBAs can be used if they share the same OROM */
626 const struct imsm_orom
*device_orom
= get_orom_by_device_id(device
->dev_id
);
628 if (device_orom
!= super
->orom
)
634 hba
->next
= alloc_intel_hba(device
);
638 static struct sys_dev
* find_disk_attached_hba(int fd
, const char *devname
)
640 struct sys_dev
*list
, *elem
;
643 if ((list
= find_intel_devices()) == NULL
)
647 disk_path
= (char *) devname
;
649 disk_path
= diskfd_to_devpath(fd
);
654 for (elem
= list
; elem
; elem
= elem
->next
)
655 if (path_attached_to_hba(disk_path
, elem
->path
))
658 if (disk_path
!= devname
)
664 static int find_intel_hba_capability(int fd
, struct intel_super
*super
,
667 static struct supertype
*match_metadata_desc_imsm(char *arg
)
669 struct supertype
*st
;
671 if (strcmp(arg
, "imsm") != 0 &&
672 strcmp(arg
, "default") != 0
676 st
= xcalloc(1, sizeof(*st
));
677 st
->ss
= &super_imsm
;
678 st
->max_devs
= IMSM_MAX_DEVICES
;
679 st
->minor_version
= 0;
684 static __u8
*get_imsm_version(struct imsm_super
*mpb
)
686 return &mpb
->sig
[MPB_SIG_LEN
];
689 /* retrieve a disk directly from the anchor when the anchor is known to be
690 * up-to-date, currently only at load time
692 static struct imsm_disk
*__get_imsm_disk(struct imsm_super
*mpb
, __u8 index
)
694 if (index
>= mpb
->num_disks
)
696 return &mpb
->disk
[index
];
699 /* retrieve the disk description based on a index of the disk
702 static struct dl
*get_imsm_dl_disk(struct intel_super
*super
, __u8 index
)
706 for (d
= super
->disks
; d
; d
= d
->next
)
707 if (d
->index
== index
)
712 /* retrieve a disk from the parsed metadata */
713 static struct imsm_disk
*get_imsm_disk(struct intel_super
*super
, __u8 index
)
717 dl
= get_imsm_dl_disk(super
, index
);
724 /* generate a checksum directly from the anchor when the anchor is known to be
725 * up-to-date, currently only at load or write_super after coalescing
727 static __u32
__gen_imsm_checksum(struct imsm_super
*mpb
)
729 __u32 end
= mpb
->mpb_size
/ sizeof(end
);
730 __u32
*p
= (__u32
*) mpb
;
734 sum
+= __le32_to_cpu(*p
);
738 return sum
- __le32_to_cpu(mpb
->check_sum
);
741 static size_t sizeof_imsm_map(struct imsm_map
*map
)
743 return sizeof(struct imsm_map
) + sizeof(__u32
) * (map
->num_members
- 1);
746 struct imsm_map
*get_imsm_map(struct imsm_dev
*dev
, int second_map
)
748 /* A device can have 2 maps if it is in the middle of a migration.
750 * MAP_0 - we return the first map
751 * MAP_1 - we return the second map if it exists, else NULL
752 * MAP_X - we return the second map if it exists, else the first
754 struct imsm_map
*map
= &dev
->vol
.map
[0];
755 struct imsm_map
*map2
= NULL
;
757 if (dev
->vol
.migr_state
)
758 map2
= (void *)map
+ sizeof_imsm_map(map
);
760 switch (second_map
) {
777 /* return the size of the device.
778 * migr_state increases the returned size if map[0] were to be duplicated
780 static size_t sizeof_imsm_dev(struct imsm_dev
*dev
, int migr_state
)
782 size_t size
= sizeof(*dev
) - sizeof(struct imsm_map
) +
783 sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
785 /* migrating means an additional map */
786 if (dev
->vol
.migr_state
)
787 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_1
));
789 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
794 /* retrieve disk serial number list from a metadata update */
795 static struct disk_info
*get_disk_info(struct imsm_update_create_array
*update
)
798 struct disk_info
*inf
;
800 inf
= u
+ sizeof(*update
) - sizeof(struct imsm_dev
) +
801 sizeof_imsm_dev(&update
->dev
, 0);
806 static struct imsm_dev
*__get_imsm_dev(struct imsm_super
*mpb
, __u8 index
)
812 if (index
>= mpb
->num_raid_devs
)
815 /* devices start after all disks */
816 offset
= ((void *) &mpb
->disk
[mpb
->num_disks
]) - _mpb
;
818 for (i
= 0; i
<= index
; i
++)
820 return _mpb
+ offset
;
822 offset
+= sizeof_imsm_dev(_mpb
+ offset
, 0);
827 static struct imsm_dev
*get_imsm_dev(struct intel_super
*super
, __u8 index
)
829 struct intel_dev
*dv
;
831 if (index
>= super
->anchor
->num_raid_devs
)
833 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
834 if (dv
->index
== index
)
839 static inline unsigned long long __le48_to_cpu(const struct bbm_log_block_addr
842 return ((((__u64
)__le32_to_cpu(addr
->dw1
)) << 16) |
843 __le16_to_cpu(addr
->w1
));
846 static inline struct bbm_log_block_addr
__cpu_to_le48(unsigned long long sec
)
848 struct bbm_log_block_addr addr
;
850 addr
.w1
= __cpu_to_le16((__u16
)(sec
& 0xffff));
851 addr
.dw1
= __cpu_to_le32((__u32
)(sec
>> 16) & 0xffffffff);
855 /* get size of the bbm log */
856 static __u32
get_imsm_bbm_log_size(struct bbm_log
*log
)
858 if (!log
|| log
->entry_count
== 0)
861 return sizeof(log
->signature
) +
862 sizeof(log
->entry_count
) +
863 log
->entry_count
* sizeof(struct bbm_log_entry
);
866 /* check if bad block is not partially stored in bbm log */
867 static int is_stored_in_bbm(struct bbm_log
*log
, const __u8 idx
, const unsigned
868 long long sector
, const int length
, __u32
*pos
)
872 for (i
= *pos
; i
< log
->entry_count
; i
++) {
873 struct bbm_log_entry
*entry
= &log
->marked_block_entries
[i
];
874 unsigned long long bb_start
;
875 unsigned long long bb_end
;
877 bb_start
= __le48_to_cpu(&entry
->defective_block_start
);
878 bb_end
= bb_start
+ (entry
->marked_count
+ 1);
880 if ((entry
->disk_ordinal
== idx
) && (bb_start
>= sector
) &&
881 (bb_end
<= sector
+ length
)) {
889 /* record new bad block in bbm log */
890 static int record_new_badblock(struct bbm_log
*log
, const __u8 idx
, unsigned
891 long long sector
, int length
)
895 struct bbm_log_entry
*entry
= NULL
;
897 while (is_stored_in_bbm(log
, idx
, sector
, length
, &pos
)) {
898 struct bbm_log_entry
*e
= &log
->marked_block_entries
[pos
];
900 if ((e
->marked_count
+ 1 == BBM_LOG_MAX_LBA_ENTRY_VAL
) &&
901 (__le48_to_cpu(&e
->defective_block_start
) == sector
)) {
902 sector
+= BBM_LOG_MAX_LBA_ENTRY_VAL
;
903 length
-= BBM_LOG_MAX_LBA_ENTRY_VAL
;
912 int cnt
= (length
<= BBM_LOG_MAX_LBA_ENTRY_VAL
) ? length
:
913 BBM_LOG_MAX_LBA_ENTRY_VAL
;
914 entry
->defective_block_start
= __cpu_to_le48(sector
);
915 entry
->marked_count
= cnt
- 1;
922 new_bb
= ROUND_UP(length
, BBM_LOG_MAX_LBA_ENTRY_VAL
) /
923 BBM_LOG_MAX_LBA_ENTRY_VAL
;
924 if (log
->entry_count
+ new_bb
> BBM_LOG_MAX_ENTRIES
)
928 int cnt
= (length
<= BBM_LOG_MAX_LBA_ENTRY_VAL
) ? length
:
929 BBM_LOG_MAX_LBA_ENTRY_VAL
;
930 struct bbm_log_entry
*entry
=
931 &log
->marked_block_entries
[log
->entry_count
];
933 entry
->defective_block_start
= __cpu_to_le48(sector
);
934 entry
->marked_count
= cnt
- 1;
935 entry
->disk_ordinal
= idx
;
946 /* clear all bad blocks for given disk */
947 static void clear_disk_badblocks(struct bbm_log
*log
, const __u8 idx
)
951 while (i
< log
->entry_count
) {
952 struct bbm_log_entry
*entries
= log
->marked_block_entries
;
954 if (entries
[i
].disk_ordinal
== idx
) {
955 if (i
< log
->entry_count
- 1)
956 entries
[i
] = entries
[log
->entry_count
- 1];
964 /* clear given bad block */
965 static int clear_badblock(struct bbm_log
*log
, const __u8 idx
, const unsigned
966 long long sector
, const int length
) {
969 while (i
< log
->entry_count
) {
970 struct bbm_log_entry
*entries
= log
->marked_block_entries
;
972 if ((entries
[i
].disk_ordinal
== idx
) &&
973 (__le48_to_cpu(&entries
[i
].defective_block_start
) ==
974 sector
) && (entries
[i
].marked_count
+ 1 == length
)) {
975 if (i
< log
->entry_count
- 1)
976 entries
[i
] = entries
[log
->entry_count
- 1];
986 /* allocate and load BBM log from metadata */
987 static int load_bbm_log(struct intel_super
*super
)
989 struct imsm_super
*mpb
= super
->anchor
;
990 __u32 bbm_log_size
= __le32_to_cpu(mpb
->bbm_log_size
);
992 super
->bbm_log
= xcalloc(1, sizeof(struct bbm_log
));
997 struct bbm_log
*log
= (void *)mpb
+
998 __le32_to_cpu(mpb
->mpb_size
) - bbm_log_size
;
1002 if (bbm_log_size
< sizeof(log
->signature
) +
1003 sizeof(log
->entry_count
))
1006 entry_count
= __le32_to_cpu(log
->entry_count
);
1007 if ((__le32_to_cpu(log
->signature
) != BBM_LOG_SIGNATURE
) ||
1008 (entry_count
> BBM_LOG_MAX_ENTRIES
))
1012 sizeof(log
->signature
) + sizeof(log
->entry_count
) +
1013 entry_count
* sizeof(struct bbm_log_entry
))
1016 memcpy(super
->bbm_log
, log
, bbm_log_size
);
1018 super
->bbm_log
->signature
= __cpu_to_le32(BBM_LOG_SIGNATURE
);
1019 super
->bbm_log
->entry_count
= 0;
1025 /* checks if bad block is within volume boundaries */
1026 static int is_bad_block_in_volume(const struct bbm_log_entry
*entry
,
1027 const unsigned long long start_sector
,
1028 const unsigned long long size
)
1030 unsigned long long bb_start
;
1031 unsigned long long bb_end
;
1033 bb_start
= __le48_to_cpu(&entry
->defective_block_start
);
1034 bb_end
= bb_start
+ (entry
->marked_count
+ 1);
1036 if (((bb_start
>= start_sector
) && (bb_start
< start_sector
+ size
)) ||
1037 ((bb_end
>= start_sector
) && (bb_end
<= start_sector
+ size
)))
1043 /* get list of bad blocks on a drive for a volume */
1044 static void get_volume_badblocks(const struct bbm_log
*log
, const __u8 idx
,
1045 const unsigned long long start_sector
,
1046 const unsigned long long size
,
1052 for (i
= 0; i
< log
->entry_count
; i
++) {
1053 const struct bbm_log_entry
*ent
=
1054 &log
->marked_block_entries
[i
];
1055 struct md_bb_entry
*bb
;
1057 if ((ent
->disk_ordinal
== idx
) &&
1058 is_bad_block_in_volume(ent
, start_sector
, size
)) {
1060 if (!bbs
->entries
) {
1061 bbs
->entries
= xmalloc(BBM_LOG_MAX_ENTRIES
*
1067 bb
= &bbs
->entries
[count
++];
1068 bb
->sector
= __le48_to_cpu(&ent
->defective_block_start
);
1069 bb
->length
= ent
->marked_count
+ 1;
1077 * == MAP_0 get first map
1078 * == MAP_1 get second map
1079 * == MAP_X than get map according to the current migr_state
1081 static __u32
get_imsm_ord_tbl_ent(struct imsm_dev
*dev
,
1085 struct imsm_map
*map
;
1087 map
= get_imsm_map(dev
, second_map
);
1089 /* top byte identifies disk under rebuild */
1090 return __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
1093 #define ord_to_idx(ord) (((ord) << 8) >> 8)
1094 static __u32
get_imsm_disk_idx(struct imsm_dev
*dev
, int slot
, int second_map
)
1096 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, second_map
);
1098 return ord_to_idx(ord
);
1101 static void set_imsm_ord_tbl_ent(struct imsm_map
*map
, int slot
, __u32 ord
)
1103 map
->disk_ord_tbl
[slot
] = __cpu_to_le32(ord
);
1106 static int get_imsm_disk_slot(struct imsm_map
*map
, unsigned idx
)
1111 for (slot
= 0; slot
< map
->num_members
; slot
++) {
1112 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
1113 if (ord_to_idx(ord
) == idx
)
1120 static int get_imsm_raid_level(struct imsm_map
*map
)
1122 if (map
->raid_level
== 1) {
1123 if (map
->num_members
== 2)
1129 return map
->raid_level
;
1132 static int cmp_extent(const void *av
, const void *bv
)
1134 const struct extent
*a
= av
;
1135 const struct extent
*b
= bv
;
1136 if (a
->start
< b
->start
)
1138 if (a
->start
> b
->start
)
1143 static int count_memberships(struct dl
*dl
, struct intel_super
*super
)
1145 int memberships
= 0;
1148 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1149 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1150 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1152 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
1159 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
);
1161 static int split_ull(unsigned long long n
, __u32
*lo
, __u32
*hi
)
1163 if (lo
== 0 || hi
== 0)
1165 *lo
= __le32_to_cpu((unsigned)n
);
1166 *hi
= __le32_to_cpu((unsigned)(n
>> 32));
1170 static unsigned long long join_u32(__u32 lo
, __u32 hi
)
1172 return (unsigned long long)__le32_to_cpu(lo
) |
1173 (((unsigned long long)__le32_to_cpu(hi
)) << 32);
1176 static unsigned long long total_blocks(struct imsm_disk
*disk
)
1180 return join_u32(disk
->total_blocks_lo
, disk
->total_blocks_hi
);
1183 static unsigned long long pba_of_lba0(struct imsm_map
*map
)
1187 return join_u32(map
->pba_of_lba0_lo
, map
->pba_of_lba0_hi
);
1190 static unsigned long long blocks_per_member(struct imsm_map
*map
)
1194 return join_u32(map
->blocks_per_member_lo
, map
->blocks_per_member_hi
);
1197 static unsigned long long num_data_stripes(struct imsm_map
*map
)
1201 return join_u32(map
->num_data_stripes_lo
, map
->num_data_stripes_hi
);
1204 static void set_total_blocks(struct imsm_disk
*disk
, unsigned long long n
)
1206 split_ull(n
, &disk
->total_blocks_lo
, &disk
->total_blocks_hi
);
1209 static void set_pba_of_lba0(struct imsm_map
*map
, unsigned long long n
)
1211 split_ull(n
, &map
->pba_of_lba0_lo
, &map
->pba_of_lba0_hi
);
1214 static void set_blocks_per_member(struct imsm_map
*map
, unsigned long long n
)
1216 split_ull(n
, &map
->blocks_per_member_lo
, &map
->blocks_per_member_hi
);
1219 static void set_num_data_stripes(struct imsm_map
*map
, unsigned long long n
)
1221 split_ull(n
, &map
->num_data_stripes_lo
, &map
->num_data_stripes_hi
);
1224 static struct extent
*get_extents(struct intel_super
*super
, struct dl
*dl
)
1226 /* find a list of used extents on the given physical device */
1227 struct extent
*rv
, *e
;
1229 int memberships
= count_memberships(dl
, super
);
1232 /* trim the reserved area for spares, so they can join any array
1233 * regardless of whether the OROM has assigned sectors from the
1234 * IMSM_RESERVED_SECTORS region
1236 if (dl
->index
== -1)
1237 reservation
= imsm_min_reserved_sectors(super
);
1239 reservation
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1241 rv
= xcalloc(sizeof(struct extent
), (memberships
+ 1));
1244 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1245 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1246 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1248 if (get_imsm_disk_slot(map
, dl
->index
) >= 0) {
1249 e
->start
= pba_of_lba0(map
);
1250 e
->size
= blocks_per_member(map
);
1254 qsort(rv
, memberships
, sizeof(*rv
), cmp_extent
);
1256 /* determine the start of the metadata
1257 * when no raid devices are defined use the default
1258 * ...otherwise allow the metadata to truncate the value
1259 * as is the case with older versions of imsm
1262 struct extent
*last
= &rv
[memberships
- 1];
1263 unsigned long long remainder
;
1265 remainder
= total_blocks(&dl
->disk
) - (last
->start
+ last
->size
);
1266 /* round down to 1k block to satisfy precision of the kernel
1270 /* make sure remainder is still sane */
1271 if (remainder
< (unsigned)ROUND_UP(super
->len
, 512) >> 9)
1272 remainder
= ROUND_UP(super
->len
, 512) >> 9;
1273 if (reservation
> remainder
)
1274 reservation
= remainder
;
1276 e
->start
= total_blocks(&dl
->disk
) - reservation
;
1281 /* try to determine how much space is reserved for metadata from
1282 * the last get_extents() entry, otherwise fallback to the
1285 static __u32
imsm_reserved_sectors(struct intel_super
*super
, struct dl
*dl
)
1291 /* for spares just return a minimal reservation which will grow
1292 * once the spare is picked up by an array
1294 if (dl
->index
== -1)
1295 return MPB_SECTOR_CNT
;
1297 e
= get_extents(super
, dl
);
1299 return MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1301 /* scroll to last entry */
1302 for (i
= 0; e
[i
].size
; i
++)
1305 rv
= total_blocks(&dl
->disk
) - e
[i
].start
;
1312 static int is_spare(struct imsm_disk
*disk
)
1314 return (disk
->status
& SPARE_DISK
) == SPARE_DISK
;
1317 static int is_configured(struct imsm_disk
*disk
)
1319 return (disk
->status
& CONFIGURED_DISK
) == CONFIGURED_DISK
;
1322 static int is_failed(struct imsm_disk
*disk
)
1324 return (disk
->status
& FAILED_DISK
) == FAILED_DISK
;
1327 static int is_journal(struct imsm_disk
*disk
)
1329 return (disk
->status
& JOURNAL_DISK
) == JOURNAL_DISK
;
1332 /* round array size down to closest MB and ensure it splits evenly
1335 static unsigned long long round_size_to_mb(unsigned long long size
, unsigned int
1339 size
= (size
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
1345 /* try to determine how much space is reserved for metadata from
1346 * the last get_extents() entry on the smallest active disk,
1347 * otherwise fallback to the default
1349 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
)
1353 unsigned long long min_active
;
1355 __u32 rv
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1356 struct dl
*dl
, *dl_min
= NULL
;
1362 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
1365 unsigned long long blocks
= total_blocks(&dl
->disk
);
1366 if (blocks
< min_active
|| min_active
== 0) {
1368 min_active
= blocks
;
1374 /* find last lba used by subarrays on the smallest active disk */
1375 e
= get_extents(super
, dl_min
);
1378 for (i
= 0; e
[i
].size
; i
++)
1381 remainder
= min_active
- e
[i
].start
;
1384 /* to give priority to recovery we should not require full
1385 IMSM_RESERVED_SECTORS from the spare */
1386 rv
= MPB_SECTOR_CNT
+ NUM_BLOCKS_DIRTY_STRIPE_REGION
;
1388 /* if real reservation is smaller use that value */
1389 return (remainder
< rv
) ? remainder
: rv
;
1393 * Return minimum size of a spare and sector size
1394 * that can be used in this array
1396 int get_spare_criteria_imsm(struct supertype
*st
, struct spare_criteria
*c
)
1398 struct intel_super
*super
= st
->sb
;
1402 unsigned long long size
= 0;
1409 /* find first active disk in array */
1411 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
1415 /* find last lba used by subarrays */
1416 e
= get_extents(super
, dl
);
1419 for (i
= 0; e
[i
].size
; i
++)
1422 size
= e
[i
-1].start
+ e
[i
-1].size
;
1425 /* add the amount of space needed for metadata */
1426 size
+= imsm_min_reserved_sectors(super
);
1428 c
->min_size
= size
* 512;
1429 c
->sector_size
= super
->sector_size
;
1434 static int is_gen_migration(struct imsm_dev
*dev
);
1436 #define IMSM_4K_DIV 8
1438 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
1439 struct imsm_dev
*dev
);
1441 static void print_imsm_dev(struct intel_super
*super
,
1442 struct imsm_dev
*dev
,
1448 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1449 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
1453 printf("[%.16s]:\n", dev
->volume
);
1454 printf(" UUID : %s\n", uuid
);
1455 printf(" RAID Level : %d", get_imsm_raid_level(map
));
1457 printf(" <-- %d", get_imsm_raid_level(map2
));
1459 printf(" Members : %d", map
->num_members
);
1461 printf(" <-- %d", map2
->num_members
);
1463 printf(" Slots : [");
1464 for (i
= 0; i
< map
->num_members
; i
++) {
1465 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
1466 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1471 for (i
= 0; i
< map2
->num_members
; i
++) {
1472 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_1
);
1473 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1478 printf(" Failed disk : ");
1479 if (map
->failed_disk_num
== 0xff)
1482 printf("%i", map
->failed_disk_num
);
1484 slot
= get_imsm_disk_slot(map
, disk_idx
);
1486 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
1487 printf(" This Slot : %d%s\n", slot
,
1488 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
1490 printf(" This Slot : ?\n");
1491 printf(" Sector Size : %u\n", super
->sector_size
);
1492 sz
= __le32_to_cpu(dev
->size_high
);
1494 sz
+= __le32_to_cpu(dev
->size_low
);
1495 printf(" Array Size : %llu%s\n",
1496 (unsigned long long)sz
* 512 / super
->sector_size
,
1497 human_size(sz
* 512));
1498 sz
= blocks_per_member(map
);
1499 printf(" Per Dev Size : %llu%s\n",
1500 (unsigned long long)sz
* 512 / super
->sector_size
,
1501 human_size(sz
* 512));
1502 printf(" Sector Offset : %llu\n",
1504 printf(" Num Stripes : %llu\n",
1505 num_data_stripes(map
));
1506 printf(" Chunk Size : %u KiB",
1507 __le16_to_cpu(map
->blocks_per_strip
) / 2);
1509 printf(" <-- %u KiB",
1510 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
1512 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
1513 printf(" Migrate State : ");
1514 if (dev
->vol
.migr_state
) {
1515 if (migr_type(dev
) == MIGR_INIT
)
1516 printf("initialize\n");
1517 else if (migr_type(dev
) == MIGR_REBUILD
)
1518 printf("rebuild\n");
1519 else if (migr_type(dev
) == MIGR_VERIFY
)
1521 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
1522 printf("general migration\n");
1523 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
1524 printf("state change\n");
1525 else if (migr_type(dev
) == MIGR_REPAIR
)
1528 printf("<unknown:%d>\n", migr_type(dev
));
1531 printf(" Map State : %s", map_state_str
[map
->map_state
]);
1532 if (dev
->vol
.migr_state
) {
1533 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
1535 printf(" <-- %s", map_state_str
[map
->map_state
]);
1536 printf("\n Checkpoint : %u ",
1537 __le32_to_cpu(dev
->vol
.curr_migr_unit
));
1538 if (is_gen_migration(dev
) && (slot
> 1 || slot
< 0))
1541 printf("(%llu)", (unsigned long long)
1542 blocks_per_migr_unit(super
, dev
));
1545 printf(" Dirty State : %s\n", (dev
->vol
.dirty
& RAIDVOL_DIRTY
) ?
1547 printf(" RWH Policy : ");
1548 if (dev
->rwh_policy
== RWH_OFF
|| dev
->rwh_policy
== RWH_MULTIPLE_OFF
)
1550 else if (dev
->rwh_policy
== RWH_DISTRIBUTED
)
1551 printf("PPL distributed\n");
1552 else if (dev
->rwh_policy
== RWH_JOURNALING_DRIVE
)
1553 printf("PPL journaling drive\n");
1554 else if (dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)
1555 printf("Multiple distributed PPLs\n");
1556 else if (dev
->rwh_policy
== RWH_MULTIPLE_PPLS_JOURNALING_DRIVE
)
1557 printf("Multiple PPLs on journaling drive\n");
1559 printf("<unknown:%d>\n", dev
->rwh_policy
);
1562 static void print_imsm_disk(struct imsm_disk
*disk
,
1565 unsigned int sector_size
) {
1566 char str
[MAX_RAID_SERIAL_LEN
+ 1];
1569 if (index
< -1 || !disk
)
1573 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
1575 printf(" Disk%02d Serial : %s\n", index
, str
);
1577 printf(" Disk Serial : %s\n", str
);
1578 printf(" State :%s%s%s%s\n", is_spare(disk
) ? " spare" : "",
1579 is_configured(disk
) ? " active" : "",
1580 is_failed(disk
) ? " failed" : "",
1581 is_journal(disk
) ? " journal" : "");
1582 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
1583 sz
= total_blocks(disk
) - reserved
;
1584 printf(" Usable Size : %llu%s\n",
1585 (unsigned long long)sz
* 512 / sector_size
,
1586 human_size(sz
* 512));
1589 void convert_to_4k_imsm_migr_rec(struct intel_super
*super
)
1591 struct migr_record
*migr_rec
= super
->migr_rec
;
1593 migr_rec
->blocks_per_unit
/= IMSM_4K_DIV
;
1594 migr_rec
->ckpt_area_pba
/= IMSM_4K_DIV
;
1595 migr_rec
->dest_1st_member_lba
/= IMSM_4K_DIV
;
1596 migr_rec
->dest_depth_per_unit
/= IMSM_4K_DIV
;
1597 split_ull((join_u32(migr_rec
->post_migr_vol_cap
,
1598 migr_rec
->post_migr_vol_cap_hi
) / IMSM_4K_DIV
),
1599 &migr_rec
->post_migr_vol_cap
, &migr_rec
->post_migr_vol_cap_hi
);
1602 void convert_to_4k_imsm_disk(struct imsm_disk
*disk
)
1604 set_total_blocks(disk
, (total_blocks(disk
)/IMSM_4K_DIV
));
1607 void convert_to_4k(struct intel_super
*super
)
1609 struct imsm_super
*mpb
= super
->anchor
;
1610 struct imsm_disk
*disk
;
1612 __u32 bbm_log_size
= __le32_to_cpu(mpb
->bbm_log_size
);
1614 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1615 disk
= __get_imsm_disk(mpb
, i
);
1617 convert_to_4k_imsm_disk(disk
);
1619 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1620 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1621 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1623 split_ull((join_u32(dev
->size_low
, dev
->size_high
)/IMSM_4K_DIV
),
1624 &dev
->size_low
, &dev
->size_high
);
1625 dev
->vol
.curr_migr_unit
/= IMSM_4K_DIV
;
1628 set_blocks_per_member(map
, blocks_per_member(map
)/IMSM_4K_DIV
);
1629 map
->blocks_per_strip
/= IMSM_4K_DIV
;
1630 set_pba_of_lba0(map
, pba_of_lba0(map
)/IMSM_4K_DIV
);
1632 if (dev
->vol
.migr_state
) {
1634 map
= get_imsm_map(dev
, MAP_1
);
1635 set_blocks_per_member(map
,
1636 blocks_per_member(map
)/IMSM_4K_DIV
);
1637 map
->blocks_per_strip
/= IMSM_4K_DIV
;
1638 set_pba_of_lba0(map
, pba_of_lba0(map
)/IMSM_4K_DIV
);
1642 struct bbm_log
*log
= (void *)mpb
+
1643 __le32_to_cpu(mpb
->mpb_size
) - bbm_log_size
;
1646 for (i
= 0; i
< log
->entry_count
; i
++) {
1647 struct bbm_log_entry
*entry
=
1648 &log
->marked_block_entries
[i
];
1650 __u8 count
= entry
->marked_count
+ 1;
1651 unsigned long long sector
=
1652 __le48_to_cpu(&entry
->defective_block_start
);
1654 entry
->defective_block_start
=
1655 __cpu_to_le48(sector
/IMSM_4K_DIV
);
1656 entry
->marked_count
= max(count
/IMSM_4K_DIV
, 1) - 1;
1660 mpb
->check_sum
= __gen_imsm_checksum(mpb
);
1663 void examine_migr_rec_imsm(struct intel_super
*super
)
1665 struct migr_record
*migr_rec
= super
->migr_rec
;
1666 struct imsm_super
*mpb
= super
->anchor
;
1669 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1670 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1671 struct imsm_map
*map
;
1674 if (is_gen_migration(dev
) == 0)
1677 printf("\nMigration Record Information:");
1679 /* first map under migration */
1680 map
= get_imsm_map(dev
, MAP_0
);
1682 slot
= get_imsm_disk_slot(map
, super
->disks
->index
);
1683 if (map
== NULL
|| slot
> 1 || slot
< 0) {
1684 printf(" Empty\n ");
1685 printf("Examine one of first two disks in array\n");
1688 printf("\n Status : ");
1689 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
1692 printf("Contains Data\n");
1693 printf(" Current Unit : %u\n",
1694 __le32_to_cpu(migr_rec
->curr_migr_unit
));
1695 printf(" Family : %u\n",
1696 __le32_to_cpu(migr_rec
->family_num
));
1697 printf(" Ascending : %u\n",
1698 __le32_to_cpu(migr_rec
->ascending_migr
));
1699 printf(" Blocks Per Unit : %u\n",
1700 __le32_to_cpu(migr_rec
->blocks_per_unit
));
1701 printf(" Dest. Depth Per Unit : %u\n",
1702 __le32_to_cpu(migr_rec
->dest_depth_per_unit
));
1703 printf(" Checkpoint Area pba : %u\n",
1704 __le32_to_cpu(migr_rec
->ckpt_area_pba
));
1705 printf(" First member lba : %u\n",
1706 __le32_to_cpu(migr_rec
->dest_1st_member_lba
));
1707 printf(" Total Number of Units : %u\n",
1708 __le32_to_cpu(migr_rec
->num_migr_units
));
1709 printf(" Size of volume : %u\n",
1710 __le32_to_cpu(migr_rec
->post_migr_vol_cap
));
1711 printf(" Expansion space for LBA64 : %u\n",
1712 __le32_to_cpu(migr_rec
->post_migr_vol_cap_hi
));
1713 printf(" Record was read from : %u\n",
1714 __le32_to_cpu(migr_rec
->ckpt_read_disk_num
));
1720 void convert_from_4k_imsm_migr_rec(struct intel_super
*super
)
1722 struct migr_record
*migr_rec
= super
->migr_rec
;
1724 migr_rec
->blocks_per_unit
*= IMSM_4K_DIV
;
1725 migr_rec
->ckpt_area_pba
*= IMSM_4K_DIV
;
1726 migr_rec
->dest_1st_member_lba
*= IMSM_4K_DIV
;
1727 migr_rec
->dest_depth_per_unit
*= IMSM_4K_DIV
;
1728 split_ull((join_u32(migr_rec
->post_migr_vol_cap
,
1729 migr_rec
->post_migr_vol_cap_hi
) * IMSM_4K_DIV
),
1730 &migr_rec
->post_migr_vol_cap
,
1731 &migr_rec
->post_migr_vol_cap_hi
);
1734 void convert_from_4k(struct intel_super
*super
)
1736 struct imsm_super
*mpb
= super
->anchor
;
1737 struct imsm_disk
*disk
;
1739 __u32 bbm_log_size
= __le32_to_cpu(mpb
->bbm_log_size
);
1741 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1742 disk
= __get_imsm_disk(mpb
, i
);
1744 set_total_blocks(disk
, (total_blocks(disk
)*IMSM_4K_DIV
));
1747 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1748 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1749 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1751 split_ull((join_u32(dev
->size_low
, dev
->size_high
)*IMSM_4K_DIV
),
1752 &dev
->size_low
, &dev
->size_high
);
1753 dev
->vol
.curr_migr_unit
*= IMSM_4K_DIV
;
1756 set_blocks_per_member(map
, blocks_per_member(map
)*IMSM_4K_DIV
);
1757 map
->blocks_per_strip
*= IMSM_4K_DIV
;
1758 set_pba_of_lba0(map
, pba_of_lba0(map
)*IMSM_4K_DIV
);
1760 if (dev
->vol
.migr_state
) {
1762 map
= get_imsm_map(dev
, MAP_1
);
1763 set_blocks_per_member(map
,
1764 blocks_per_member(map
)*IMSM_4K_DIV
);
1765 map
->blocks_per_strip
*= IMSM_4K_DIV
;
1766 set_pba_of_lba0(map
, pba_of_lba0(map
)*IMSM_4K_DIV
);
1770 struct bbm_log
*log
= (void *)mpb
+
1771 __le32_to_cpu(mpb
->mpb_size
) - bbm_log_size
;
1774 for (i
= 0; i
< log
->entry_count
; i
++) {
1775 struct bbm_log_entry
*entry
=
1776 &log
->marked_block_entries
[i
];
1778 __u8 count
= entry
->marked_count
+ 1;
1779 unsigned long long sector
=
1780 __le48_to_cpu(&entry
->defective_block_start
);
1782 entry
->defective_block_start
=
1783 __cpu_to_le48(sector
*IMSM_4K_DIV
);
1784 entry
->marked_count
= count
*IMSM_4K_DIV
- 1;
1788 mpb
->check_sum
= __gen_imsm_checksum(mpb
);
1791 /*******************************************************************************
1792 * function: imsm_check_attributes
1793 * Description: Function checks if features represented by attributes flags
1794 * are supported by mdadm.
1796 * attributes - Attributes read from metadata
1798 * 0 - passed attributes contains unsupported features flags
1799 * 1 - all features are supported
1800 ******************************************************************************/
1801 static int imsm_check_attributes(__u32 attributes
)
1804 __u32 not_supported
= MPB_ATTRIB_SUPPORTED
^0xffffffff;
1806 not_supported
&= ~MPB_ATTRIB_IGNORED
;
1808 not_supported
&= attributes
;
1809 if (not_supported
) {
1810 pr_err("(IMSM): Unsupported attributes : %x\n",
1811 (unsigned)__le32_to_cpu(not_supported
));
1812 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1813 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY \n");
1814 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1816 if (not_supported
& MPB_ATTRIB_2TB
) {
1817 dprintf("\t\tMPB_ATTRIB_2TB\n");
1818 not_supported
^= MPB_ATTRIB_2TB
;
1820 if (not_supported
& MPB_ATTRIB_RAID0
) {
1821 dprintf("\t\tMPB_ATTRIB_RAID0\n");
1822 not_supported
^= MPB_ATTRIB_RAID0
;
1824 if (not_supported
& MPB_ATTRIB_RAID1
) {
1825 dprintf("\t\tMPB_ATTRIB_RAID1\n");
1826 not_supported
^= MPB_ATTRIB_RAID1
;
1828 if (not_supported
& MPB_ATTRIB_RAID10
) {
1829 dprintf("\t\tMPB_ATTRIB_RAID10\n");
1830 not_supported
^= MPB_ATTRIB_RAID10
;
1832 if (not_supported
& MPB_ATTRIB_RAID1E
) {
1833 dprintf("\t\tMPB_ATTRIB_RAID1E\n");
1834 not_supported
^= MPB_ATTRIB_RAID1E
;
1836 if (not_supported
& MPB_ATTRIB_RAID5
) {
1837 dprintf("\t\tMPB_ATTRIB_RAID5\n");
1838 not_supported
^= MPB_ATTRIB_RAID5
;
1840 if (not_supported
& MPB_ATTRIB_RAIDCNG
) {
1841 dprintf("\t\tMPB_ATTRIB_RAIDCNG\n");
1842 not_supported
^= MPB_ATTRIB_RAIDCNG
;
1844 if (not_supported
& MPB_ATTRIB_BBM
) {
1845 dprintf("\t\tMPB_ATTRIB_BBM\n");
1846 not_supported
^= MPB_ATTRIB_BBM
;
1848 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1849 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY (== MPB_ATTRIB_LEGACY)\n");
1850 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1852 if (not_supported
& MPB_ATTRIB_EXP_STRIPE_SIZE
) {
1853 dprintf("\t\tMPB_ATTRIB_EXP_STRIP_SIZE\n");
1854 not_supported
^= MPB_ATTRIB_EXP_STRIPE_SIZE
;
1856 if (not_supported
& MPB_ATTRIB_2TB_DISK
) {
1857 dprintf("\t\tMPB_ATTRIB_2TB_DISK\n");
1858 not_supported
^= MPB_ATTRIB_2TB_DISK
;
1860 if (not_supported
& MPB_ATTRIB_NEVER_USE2
) {
1861 dprintf("\t\tMPB_ATTRIB_NEVER_USE2\n");
1862 not_supported
^= MPB_ATTRIB_NEVER_USE2
;
1864 if (not_supported
& MPB_ATTRIB_NEVER_USE
) {
1865 dprintf("\t\tMPB_ATTRIB_NEVER_USE\n");
1866 not_supported
^= MPB_ATTRIB_NEVER_USE
;
1870 dprintf("(IMSM): Unknown attributes : %x\n", not_supported
);
1878 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
1880 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
1882 struct intel_super
*super
= st
->sb
;
1883 struct imsm_super
*mpb
= super
->anchor
;
1884 char str
[MAX_SIGNATURE_LENGTH
];
1889 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
1892 strncpy(str
, (char *)mpb
->sig
, MPB_SIG_LEN
);
1893 str
[MPB_SIG_LEN
-1] = '\0';
1894 printf(" Magic : %s\n", str
);
1895 snprintf(str
, strlen(MPB_VERSION_RAID0
), "%s", get_imsm_version(mpb
));
1896 printf(" Version : %s\n", get_imsm_version(mpb
));
1897 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
1898 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
1899 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
1900 printf(" Attributes : ");
1901 if (imsm_check_attributes(mpb
->attributes
))
1902 printf("All supported\n");
1904 printf("not supported\n");
1905 getinfo_super_imsm(st
, &info
, NULL
);
1906 fname_from_uuid(st
, &info
, nbuf
, ':');
1907 printf(" UUID : %s\n", nbuf
+ 5);
1908 sum
= __le32_to_cpu(mpb
->check_sum
);
1909 printf(" Checksum : %08x %s\n", sum
,
1910 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
1911 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
, super
->sector_size
));
1912 printf(" Disks : %d\n", mpb
->num_disks
);
1913 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
1914 print_imsm_disk(__get_imsm_disk(mpb
, super
->disks
->index
),
1915 super
->disks
->index
, reserved
, super
->sector_size
);
1916 if (get_imsm_bbm_log_size(super
->bbm_log
)) {
1917 struct bbm_log
*log
= super
->bbm_log
;
1920 printf("Bad Block Management Log:\n");
1921 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
1922 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
1923 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
1925 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1927 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1929 super
->current_vol
= i
;
1930 getinfo_super_imsm(st
, &info
, NULL
);
1931 fname_from_uuid(st
, &info
, nbuf
, ':');
1932 print_imsm_dev(super
, dev
, nbuf
+ 5, super
->disks
->index
);
1934 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1935 if (i
== super
->disks
->index
)
1937 print_imsm_disk(__get_imsm_disk(mpb
, i
), i
, reserved
,
1938 super
->sector_size
);
1941 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
1942 if (dl
->index
== -1)
1943 print_imsm_disk(&dl
->disk
, -1, reserved
,
1944 super
->sector_size
);
1946 examine_migr_rec_imsm(super
);
1949 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
1951 /* We just write a generic IMSM ARRAY entry */
1954 struct intel_super
*super
= st
->sb
;
1956 if (!super
->anchor
->num_raid_devs
) {
1957 printf("ARRAY metadata=imsm\n");
1961 getinfo_super_imsm(st
, &info
, NULL
);
1962 fname_from_uuid(st
, &info
, nbuf
, ':');
1963 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
1966 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
1968 /* We just write a generic IMSM ARRAY entry */
1972 struct intel_super
*super
= st
->sb
;
1975 if (!super
->anchor
->num_raid_devs
)
1978 getinfo_super_imsm(st
, &info
, NULL
);
1979 fname_from_uuid(st
, &info
, nbuf
, ':');
1980 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1981 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1983 super
->current_vol
= i
;
1984 getinfo_super_imsm(st
, &info
, NULL
);
1985 fname_from_uuid(st
, &info
, nbuf1
, ':');
1986 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
1987 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
1991 static void export_examine_super_imsm(struct supertype
*st
)
1993 struct intel_super
*super
= st
->sb
;
1994 struct imsm_super
*mpb
= super
->anchor
;
1998 getinfo_super_imsm(st
, &info
, NULL
);
1999 fname_from_uuid(st
, &info
, nbuf
, ':');
2000 printf("MD_METADATA=imsm\n");
2001 printf("MD_LEVEL=container\n");
2002 printf("MD_UUID=%s\n", nbuf
+5);
2003 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
2006 static int copy_metadata_imsm(struct supertype
*st
, int from
, int to
)
2008 /* The second last sector of the device contains
2009 * the "struct imsm_super" metadata.
2010 * This contains mpb_size which is the size in bytes of the
2011 * extended metadata. This is located immediately before
2013 * We want to read all that, plus the last sector which
2014 * may contain a migration record, and write it all
2018 unsigned long long dsize
, offset
;
2020 struct imsm_super
*sb
;
2021 struct intel_super
*super
= st
->sb
;
2022 unsigned int sector_size
= super
->sector_size
;
2023 unsigned int written
= 0;
2025 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, MAX_SECTOR_SIZE
) != 0)
2028 if (!get_dev_size(from
, NULL
, &dsize
))
2031 if (lseek64(from
, dsize
-(2*sector_size
), 0) < 0)
2033 if ((unsigned int)read(from
, buf
, sector_size
) != sector_size
)
2036 if (strncmp((char*)sb
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0)
2039 sectors
= mpb_sectors(sb
, sector_size
) + 2;
2040 offset
= dsize
- sectors
* sector_size
;
2041 if (lseek64(from
, offset
, 0) < 0 ||
2042 lseek64(to
, offset
, 0) < 0)
2044 while (written
< sectors
* sector_size
) {
2045 int n
= sectors
*sector_size
- written
;
2048 if (read(from
, buf
, n
) != n
)
2050 if (write(to
, buf
, n
) != n
)
2061 static void detail_super_imsm(struct supertype
*st
, char *homehost
)
2066 getinfo_super_imsm(st
, &info
, NULL
);
2067 fname_from_uuid(st
, &info
, nbuf
, ':');
2068 printf("\n UUID : %s\n", nbuf
+ 5);
2071 static void brief_detail_super_imsm(struct supertype
*st
)
2075 getinfo_super_imsm(st
, &info
, NULL
);
2076 fname_from_uuid(st
, &info
, nbuf
, ':');
2077 printf(" UUID=%s", nbuf
+ 5);
2080 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
);
2081 static void fd2devname(int fd
, char *name
);
2083 static int ahci_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
2085 /* dump an unsorted list of devices attached to AHCI Intel storage
2086 * controller, as well as non-connected ports
2088 int hba_len
= strlen(hba_path
) + 1;
2093 unsigned long port_mask
= (1 << port_count
) - 1;
2095 if (port_count
> (int)sizeof(port_mask
) * 8) {
2097 pr_err("port_count %d out of range\n", port_count
);
2101 /* scroll through /sys/dev/block looking for devices attached to
2104 dir
= opendir("/sys/dev/block");
2108 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2119 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
2121 path
= devt_to_devpath(makedev(major
, minor
));
2124 if (!path_attached_to_hba(path
, hba_path
)) {
2130 /* retrieve the scsi device type */
2131 if (asprintf(&device
, "/sys/dev/block/%d:%d/device/xxxxxxx", major
, minor
) < 0) {
2133 pr_err("failed to allocate 'device'\n");
2137 sprintf(device
, "/sys/dev/block/%d:%d/device/type", major
, minor
);
2138 if (load_sys(device
, buf
, sizeof(buf
)) != 0) {
2140 pr_err("failed to read device type for %s\n",
2146 type
= strtoul(buf
, NULL
, 10);
2148 /* if it's not a disk print the vendor and model */
2149 if (!(type
== 0 || type
== 7 || type
== 14)) {
2152 sprintf(device
, "/sys/dev/block/%d:%d/device/vendor", major
, minor
);
2153 if (load_sys(device
, buf
, sizeof(buf
)) == 0) {
2154 strncpy(vendor
, buf
, sizeof(vendor
));
2155 vendor
[sizeof(vendor
) - 1] = '\0';
2156 c
= (char *) &vendor
[sizeof(vendor
) - 1];
2157 while (isspace(*c
) || *c
== '\0')
2161 sprintf(device
, "/sys/dev/block/%d:%d/device/model", major
, minor
);
2162 if (load_sys(device
, buf
, sizeof(buf
)) == 0) {
2163 strncpy(model
, buf
, sizeof(model
));
2164 model
[sizeof(model
) - 1] = '\0';
2165 c
= (char *) &model
[sizeof(model
) - 1];
2166 while (isspace(*c
) || *c
== '\0')
2170 if (vendor
[0] && model
[0])
2171 sprintf(buf
, "%.64s %.64s", vendor
, model
);
2173 switch (type
) { /* numbers from hald/linux/device.c */
2174 case 1: sprintf(buf
, "tape"); break;
2175 case 2: sprintf(buf
, "printer"); break;
2176 case 3: sprintf(buf
, "processor"); break;
2178 case 5: sprintf(buf
, "cdrom"); break;
2179 case 6: sprintf(buf
, "scanner"); break;
2180 case 8: sprintf(buf
, "media_changer"); break;
2181 case 9: sprintf(buf
, "comm"); break;
2182 case 12: sprintf(buf
, "raid"); break;
2183 default: sprintf(buf
, "unknown");
2189 /* chop device path to 'host%d' and calculate the port number */
2190 c
= strchr(&path
[hba_len
], '/');
2193 pr_err("%s - invalid path name\n", path
+ hba_len
);
2198 if ((sscanf(&path
[hba_len
], "ata%d", &port
) == 1) ||
2199 ((sscanf(&path
[hba_len
], "host%d", &port
) == 1)))
2203 *c
= '/'; /* repair the full string */
2204 pr_err("failed to determine port number for %s\n",
2211 /* mark this port as used */
2212 port_mask
&= ~(1 << port
);
2214 /* print out the device information */
2216 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
2220 fd
= dev_open(ent
->d_name
, O_RDONLY
);
2222 printf(" Port%d : - disk info unavailable -\n", port
);
2224 fd2devname(fd
, buf
);
2225 printf(" Port%d : %s", port
, buf
);
2226 if (imsm_read_serial(fd
, NULL
, (__u8
*) buf
) == 0)
2227 printf(" (%.*s)\n", MAX_RAID_SERIAL_LEN
, buf
);
2242 for (i
= 0; i
< port_count
; i
++)
2243 if (port_mask
& (1 << i
))
2244 printf(" Port%d : - no device attached -\n", i
);
2250 static int print_vmd_attached_devs(struct sys_dev
*hba
)
2258 if (hba
->type
!= SYS_DEV_VMD
)
2261 /* scroll through /sys/dev/block looking for devices attached to
2264 dir
= opendir("/sys/bus/pci/drivers/nvme");
2268 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2271 /* is 'ent' a device? check that the 'subsystem' link exists and
2272 * that its target matches 'bus'
2274 sprintf(path
, "/sys/bus/pci/drivers/nvme/%s/subsystem",
2276 n
= readlink(path
, link
, sizeof(link
));
2277 if (n
< 0 || n
>= (int)sizeof(link
))
2280 c
= strrchr(link
, '/');
2283 if (strncmp("pci", c
+1, strlen("pci")) != 0)
2286 sprintf(path
, "/sys/bus/pci/drivers/nvme/%s", ent
->d_name
);
2288 rp
= realpath(path
, NULL
);
2292 if (path_attached_to_hba(rp
, hba
->path
)) {
2293 printf(" NVMe under VMD : %s\n", rp
);
2302 static void print_found_intel_controllers(struct sys_dev
*elem
)
2304 for (; elem
; elem
= elem
->next
) {
2305 pr_err("found Intel(R) ");
2306 if (elem
->type
== SYS_DEV_SATA
)
2307 fprintf(stderr
, "SATA ");
2308 else if (elem
->type
== SYS_DEV_SAS
)
2309 fprintf(stderr
, "SAS ");
2310 else if (elem
->type
== SYS_DEV_NVME
)
2311 fprintf(stderr
, "NVMe ");
2313 if (elem
->type
== SYS_DEV_VMD
)
2314 fprintf(stderr
, "VMD domain");
2316 fprintf(stderr
, "RAID controller");
2319 fprintf(stderr
, " at %s", elem
->pci_id
);
2320 fprintf(stderr
, ".\n");
2325 static int ahci_get_port_count(const char *hba_path
, int *port_count
)
2332 if ((dir
= opendir(hba_path
)) == NULL
)
2335 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2338 if ((sscanf(ent
->d_name
, "ata%d", &host
) != 1) &&
2339 ((sscanf(ent
->d_name
, "host%d", &host
) != 1)))
2341 if (*port_count
== 0)
2343 else if (host
< host_base
)
2346 if (host
+ 1 > *port_count
+ host_base
)
2347 *port_count
= host
+ 1 - host_base
;
2353 static void print_imsm_capability(const struct imsm_orom
*orom
)
2355 printf(" Platform : Intel(R) ");
2356 if (orom
->capabilities
== 0 && orom
->driver_features
== 0)
2357 printf("Matrix Storage Manager\n");
2359 printf("Rapid Storage Technology%s\n",
2360 imsm_orom_is_enterprise(orom
) ? " enterprise" : "");
2361 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
2362 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
,
2363 orom
->minor_ver
, orom
->hotfix_ver
, orom
->build
);
2364 printf(" RAID Levels :%s%s%s%s%s\n",
2365 imsm_orom_has_raid0(orom
) ? " raid0" : "",
2366 imsm_orom_has_raid1(orom
) ? " raid1" : "",
2367 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
2368 imsm_orom_has_raid10(orom
) ? " raid10" : "",
2369 imsm_orom_has_raid5(orom
) ? " raid5" : "");
2370 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2371 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
2372 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
2373 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
2374 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
2375 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
2376 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
2377 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
2378 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
2379 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
2380 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
2381 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
2382 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
2383 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
2384 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
2385 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
2386 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
2387 printf(" 2TB volumes :%s supported\n",
2388 (orom
->attr
& IMSM_OROM_ATTR_2TB
)?"":" not");
2389 printf(" 2TB disks :%s supported\n",
2390 (orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
)?"":" not");
2391 printf(" Max Disks : %d\n", orom
->tds
);
2392 printf(" Max Volumes : %d per array, %d per %s\n",
2393 orom
->vpa
, orom
->vphba
,
2394 imsm_orom_is_nvme(orom
) ? "platform" : "controller");
2398 static void print_imsm_capability_export(const struct imsm_orom
*orom
)
2400 printf("MD_FIRMWARE_TYPE=imsm\n");
2401 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
2402 printf("IMSM_VERSION=%d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
2403 orom
->hotfix_ver
, orom
->build
);
2404 printf("IMSM_SUPPORTED_RAID_LEVELS=%s%s%s%s%s\n",
2405 imsm_orom_has_raid0(orom
) ? "raid0 " : "",
2406 imsm_orom_has_raid1(orom
) ? "raid1 " : "",
2407 imsm_orom_has_raid1e(orom
) ? "raid1e " : "",
2408 imsm_orom_has_raid5(orom
) ? "raid10 " : "",
2409 imsm_orom_has_raid10(orom
) ? "raid5 " : "");
2410 printf("IMSM_SUPPORTED_CHUNK_SIZES=%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2411 imsm_orom_has_chunk(orom
, 2) ? "2k " : "",
2412 imsm_orom_has_chunk(orom
, 4) ? "4k " : "",
2413 imsm_orom_has_chunk(orom
, 8) ? "8k " : "",
2414 imsm_orom_has_chunk(orom
, 16) ? "16k " : "",
2415 imsm_orom_has_chunk(orom
, 32) ? "32k " : "",
2416 imsm_orom_has_chunk(orom
, 64) ? "64k " : "",
2417 imsm_orom_has_chunk(orom
, 128) ? "128k " : "",
2418 imsm_orom_has_chunk(orom
, 256) ? "256k " : "",
2419 imsm_orom_has_chunk(orom
, 512) ? "512k " : "",
2420 imsm_orom_has_chunk(orom
, 1024*1) ? "1M " : "",
2421 imsm_orom_has_chunk(orom
, 1024*2) ? "2M " : "",
2422 imsm_orom_has_chunk(orom
, 1024*4) ? "4M " : "",
2423 imsm_orom_has_chunk(orom
, 1024*8) ? "8M " : "",
2424 imsm_orom_has_chunk(orom
, 1024*16) ? "16M " : "",
2425 imsm_orom_has_chunk(orom
, 1024*32) ? "32M " : "",
2426 imsm_orom_has_chunk(orom
, 1024*64) ? "64M " : "");
2427 printf("IMSM_2TB_VOLUMES=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB
) ? "yes" : "no");
2428 printf("IMSM_2TB_DISKS=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) ? "yes" : "no");
2429 printf("IMSM_MAX_DISKS=%d\n",orom
->tds
);
2430 printf("IMSM_MAX_VOLUMES_PER_ARRAY=%d\n",orom
->vpa
);
2431 printf("IMSM_MAX_VOLUMES_PER_CONTROLLER=%d\n",orom
->vphba
);
2434 static int detail_platform_imsm(int verbose
, int enumerate_only
, char *controller_path
)
2436 /* There are two components to imsm platform support, the ahci SATA
2437 * controller and the option-rom. To find the SATA controller we
2438 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
2439 * controller with the Intel vendor id is present. This approach
2440 * allows mdadm to leverage the kernel's ahci detection logic, with the
2441 * caveat that if ahci.ko is not loaded mdadm will not be able to
2442 * detect platform raid capabilities. The option-rom resides in a
2443 * platform "Adapter ROM". We scan for its signature to retrieve the
2444 * platform capabilities. If raid support is disabled in the BIOS the
2445 * option-rom capability structure will not be available.
2447 struct sys_dev
*list
, *hba
;
2452 if (enumerate_only
) {
2453 if (check_env("IMSM_NO_PLATFORM"))
2455 list
= find_intel_devices();
2458 for (hba
= list
; hba
; hba
= hba
->next
) {
2459 if (find_imsm_capability(hba
)) {
2469 list
= find_intel_devices();
2472 pr_err("no active Intel(R) RAID controller found.\n");
2474 } else if (verbose
> 0)
2475 print_found_intel_controllers(list
);
2477 for (hba
= list
; hba
; hba
= hba
->next
) {
2478 if (controller_path
&& (compare_paths(hba
->path
, controller_path
) != 0))
2480 if (!find_imsm_capability(hba
)) {
2482 pr_err("imsm capabilities not found for controller: %s (type %s)\n",
2483 hba
->type
== SYS_DEV_VMD
? vmd_domain_to_controller(hba
, buf
) : hba
->path
,
2484 get_sys_dev_type(hba
->type
));
2490 if (controller_path
&& result
== 1) {
2491 pr_err("no active Intel(R) RAID controller found under %s\n",
2496 const struct orom_entry
*entry
;
2498 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
2499 if (entry
->type
== SYS_DEV_VMD
) {
2500 print_imsm_capability(&entry
->orom
);
2501 printf(" 3rd party NVMe :%s supported\n",
2502 imsm_orom_has_tpv_support(&entry
->orom
)?"":" not");
2503 for (hba
= list
; hba
; hba
= hba
->next
) {
2504 if (hba
->type
== SYS_DEV_VMD
) {
2506 printf(" I/O Controller : %s (%s)\n",
2507 vmd_domain_to_controller(hba
, buf
), get_sys_dev_type(hba
->type
));
2508 if (print_vmd_attached_devs(hba
)) {
2510 pr_err("failed to get devices attached to VMD domain.\n");
2519 print_imsm_capability(&entry
->orom
);
2520 if (entry
->type
== SYS_DEV_NVME
) {
2521 for (hba
= list
; hba
; hba
= hba
->next
) {
2522 if (hba
->type
== SYS_DEV_NVME
)
2523 printf(" NVMe Device : %s\n", hba
->path
);
2529 struct devid_list
*devid
;
2530 for (devid
= entry
->devid_list
; devid
; devid
= devid
->next
) {
2531 hba
= device_by_id(devid
->devid
);
2535 printf(" I/O Controller : %s (%s)\n",
2536 hba
->path
, get_sys_dev_type(hba
->type
));
2537 if (hba
->type
== SYS_DEV_SATA
) {
2538 host_base
= ahci_get_port_count(hba
->path
, &port_count
);
2539 if (ahci_enumerate_ports(hba
->path
, port_count
, host_base
, verbose
)) {
2541 pr_err("failed to enumerate ports on SATA controller at %s.\n", hba
->pci_id
);
2552 static int export_detail_platform_imsm(int verbose
, char *controller_path
)
2554 struct sys_dev
*list
, *hba
;
2557 list
= find_intel_devices();
2560 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_INTEL_DEVICES\n");
2565 for (hba
= list
; hba
; hba
= hba
->next
) {
2566 if (controller_path
&& (compare_paths(hba
->path
,controller_path
) != 0))
2568 if (!find_imsm_capability(hba
) && verbose
> 0) {
2570 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_IMSM_CAPABLE_DEVICE_UNDER_%s\n",
2571 hba
->type
== SYS_DEV_VMD
? vmd_domain_to_controller(hba
, buf
) : hba
->path
);
2577 const struct orom_entry
*entry
;
2579 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
2580 if (entry
->type
== SYS_DEV_VMD
) {
2581 for (hba
= list
; hba
; hba
= hba
->next
)
2582 print_imsm_capability_export(&entry
->orom
);
2585 print_imsm_capability_export(&entry
->orom
);
2591 static int match_home_imsm(struct supertype
*st
, char *homehost
)
2593 /* the imsm metadata format does not specify any host
2594 * identification information. We return -1 since we can never
2595 * confirm nor deny whether a given array is "meant" for this
2596 * host. We rely on compare_super and the 'family_num' fields to
2597 * exclude member disks that do not belong, and we rely on
2598 * mdadm.conf to specify the arrays that should be assembled.
2599 * Auto-assembly may still pick up "foreign" arrays.
2605 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
2607 /* The uuid returned here is used for:
2608 * uuid to put into bitmap file (Create, Grow)
2609 * uuid for backup header when saving critical section (Grow)
2610 * comparing uuids when re-adding a device into an array
2611 * In these cases the uuid required is that of the data-array,
2612 * not the device-set.
2613 * uuid to recognise same set when adding a missing device back
2614 * to an array. This is a uuid for the device-set.
2616 * For each of these we can make do with a truncated
2617 * or hashed uuid rather than the original, as long as
2619 * In each case the uuid required is that of the data-array,
2620 * not the device-set.
2622 /* imsm does not track uuid's so we synthesis one using sha1 on
2623 * - The signature (Which is constant for all imsm array, but no matter)
2624 * - the orig_family_num of the container
2625 * - the index number of the volume
2626 * - the 'serial' number of the volume.
2627 * Hopefully these are all constant.
2629 struct intel_super
*super
= st
->sb
;
2632 struct sha1_ctx ctx
;
2633 struct imsm_dev
*dev
= NULL
;
2636 /* some mdadm versions failed to set ->orig_family_num, in which
2637 * case fall back to ->family_num. orig_family_num will be
2638 * fixed up with the first metadata update.
2640 family_num
= super
->anchor
->orig_family_num
;
2641 if (family_num
== 0)
2642 family_num
= super
->anchor
->family_num
;
2643 sha1_init_ctx(&ctx
);
2644 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
2645 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
2646 if (super
->current_vol
>= 0)
2647 dev
= get_imsm_dev(super
, super
->current_vol
);
2649 __u32 vol
= super
->current_vol
;
2650 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
2651 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
2653 sha1_finish_ctx(&ctx
, buf
);
2654 memcpy(uuid
, buf
, 4*4);
2659 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
2661 __u8
*v
= get_imsm_version(mpb
);
2662 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
2663 char major
[] = { 0, 0, 0 };
2664 char minor
[] = { 0 ,0, 0 };
2665 char patch
[] = { 0, 0, 0 };
2666 char *ver_parse
[] = { major
, minor
, patch
};
2670 while (*v
!= '\0' && v
< end
) {
2671 if (*v
!= '.' && j
< 2)
2672 ver_parse
[i
][j
++] = *v
;
2680 *m
= strtol(minor
, NULL
, 0);
2681 *p
= strtol(patch
, NULL
, 0);
2685 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
2687 /* migr_strip_size when repairing or initializing parity */
2688 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2689 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2691 switch (get_imsm_raid_level(map
)) {
2696 return 128*1024 >> 9;
2700 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
2702 /* migr_strip_size when rebuilding a degraded disk, no idea why
2703 * this is different than migr_strip_size_resync(), but it's good
2706 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2707 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2709 switch (get_imsm_raid_level(map
)) {
2712 if (map
->num_members
% map
->num_domains
== 0)
2713 return 128*1024 >> 9;
2717 return max((__u32
) 64*1024 >> 9, chunk
);
2719 return 128*1024 >> 9;
2723 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
2725 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2726 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2727 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
2728 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
2730 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
2733 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
2735 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2736 int level
= get_imsm_raid_level(lo
);
2738 if (level
== 1 || level
== 10) {
2739 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2741 return hi
->num_domains
;
2743 return num_stripes_per_unit_resync(dev
);
2746 static __u8
imsm_num_data_members(struct imsm_dev
*dev
, int second_map
)
2748 /* named 'imsm_' because raid0, raid1 and raid10
2749 * counter-intuitively have the same number of data disks
2751 struct imsm_map
*map
= get_imsm_map(dev
, second_map
);
2753 switch (get_imsm_raid_level(map
)) {
2755 return map
->num_members
;
2759 return map
->num_members
/2;
2761 return map
->num_members
- 1;
2763 dprintf("unsupported raid level\n");
2768 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
2770 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2771 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2773 switch(get_imsm_raid_level(map
)) {
2776 return chunk
* map
->num_domains
;
2778 return chunk
* map
->num_members
;
2784 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
2786 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2787 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2788 __u32 strip
= block
/ chunk
;
2790 switch (get_imsm_raid_level(map
)) {
2793 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
2794 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
2796 return vol_stripe
* chunk
+ block
% chunk
;
2798 __u32 stripe
= strip
/ (map
->num_members
- 1);
2800 return stripe
* chunk
+ block
% chunk
;
2807 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
2808 struct imsm_dev
*dev
)
2810 /* calculate the conversion factor between per member 'blocks'
2811 * (md/{resync,rebuild}_start) and imsm migration units, return
2812 * 0 for the 'not migrating' and 'unsupported migration' cases
2814 if (!dev
->vol
.migr_state
)
2817 switch (migr_type(dev
)) {
2818 case MIGR_GEN_MIGR
: {
2819 struct migr_record
*migr_rec
= super
->migr_rec
;
2820 return __le32_to_cpu(migr_rec
->blocks_per_unit
);
2825 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2826 __u32 stripes_per_unit
;
2827 __u32 blocks_per_unit
;
2836 /* yes, this is really the translation of migr_units to
2837 * per-member blocks in the 'resync' case
2839 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
2840 migr_chunk
= migr_strip_blocks_resync(dev
);
2841 disks
= imsm_num_data_members(dev
, MAP_0
);
2842 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
2843 stripe
= __le16_to_cpu(map
->blocks_per_strip
) * disks
;
2844 segment
= blocks_per_unit
/ stripe
;
2845 block_rel
= blocks_per_unit
- segment
* stripe
;
2846 parity_depth
= parity_segment_depth(dev
);
2847 block_map
= map_migr_block(dev
, block_rel
);
2848 return block_map
+ parity_depth
* segment
;
2850 case MIGR_REBUILD
: {
2851 __u32 stripes_per_unit
;
2854 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
2855 migr_chunk
= migr_strip_blocks_rebuild(dev
);
2856 return migr_chunk
* stripes_per_unit
;
2858 case MIGR_STATE_CHANGE
:
2864 static int imsm_level_to_layout(int level
)
2872 return ALGORITHM_LEFT_ASYMMETRIC
;
2879 /*******************************************************************************
2880 * Function: read_imsm_migr_rec
2881 * Description: Function reads imsm migration record from last sector of disk
2883 * fd : disk descriptor
2884 * super : metadata info
2888 ******************************************************************************/
2889 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
)
2892 unsigned int sector_size
= super
->sector_size
;
2893 unsigned long long dsize
;
2895 get_dev_size(fd
, NULL
, &dsize
);
2896 if (lseek64(fd
, dsize
- (sector_size
*MIGR_REC_SECTOR_POSITION
),
2898 pr_err("Cannot seek to anchor block: %s\n",
2902 if ((unsigned int)read(fd
, super
->migr_rec_buf
,
2903 MIGR_REC_BUF_SECTORS
*sector_size
) !=
2904 MIGR_REC_BUF_SECTORS
*sector_size
) {
2905 pr_err("Cannot read migr record block: %s\n",
2910 if (sector_size
== 4096)
2911 convert_from_4k_imsm_migr_rec(super
);
2917 static struct imsm_dev
*imsm_get_device_during_migration(
2918 struct intel_super
*super
)
2921 struct intel_dev
*dv
;
2923 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
2924 if (is_gen_migration(dv
->dev
))
2930 /*******************************************************************************
2931 * Function: load_imsm_migr_rec
2932 * Description: Function reads imsm migration record (it is stored at the last
2935 * super : imsm internal array info
2936 * info : general array info
2940 * -2 : no migration in progress
2941 ******************************************************************************/
2942 static int load_imsm_migr_rec(struct intel_super
*super
, struct mdinfo
*info
)
2949 struct imsm_dev
*dev
;
2950 struct imsm_map
*map
;
2953 /* find map under migration */
2954 dev
= imsm_get_device_during_migration(super
);
2955 /* nothing to load,no migration in progress?
2961 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
2962 /* read only from one of the first two slots */
2963 if ((sd
->disk
.raid_disk
< 0) ||
2964 (sd
->disk
.raid_disk
> 1))
2967 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
2968 fd
= dev_open(nm
, O_RDONLY
);
2974 map
= get_imsm_map(dev
, MAP_0
);
2975 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
2976 /* skip spare and failed disks
2980 /* read only from one of the first two slots */
2982 slot
= get_imsm_disk_slot(map
, dl
->index
);
2983 if (map
== NULL
|| slot
> 1 || slot
< 0)
2985 sprintf(nm
, "%d:%d", dl
->major
, dl
->minor
);
2986 fd
= dev_open(nm
, O_RDONLY
);
2993 retval
= read_imsm_migr_rec(fd
, super
);
3001 /*******************************************************************************
3002 * function: imsm_create_metadata_checkpoint_update
3003 * Description: It creates update for checkpoint change.
3005 * super : imsm internal array info
3006 * u : pointer to prepared update
3009 * If length is equal to 0, input pointer u contains no update
3010 ******************************************************************************/
3011 static int imsm_create_metadata_checkpoint_update(
3012 struct intel_super
*super
,
3013 struct imsm_update_general_migration_checkpoint
**u
)
3016 int update_memory_size
= 0;
3018 dprintf("(enter)\n");
3024 /* size of all update data without anchor */
3025 update_memory_size
=
3026 sizeof(struct imsm_update_general_migration_checkpoint
);
3028 *u
= xcalloc(1, update_memory_size
);
3030 dprintf("error: cannot get memory\n");
3033 (*u
)->type
= update_general_migration_checkpoint
;
3034 (*u
)->curr_migr_unit
= __le32_to_cpu(super
->migr_rec
->curr_migr_unit
);
3035 dprintf("prepared for %u\n", (*u
)->curr_migr_unit
);
3037 return update_memory_size
;
3040 static void imsm_update_metadata_locally(struct supertype
*st
,
3041 void *buf
, int len
);
3043 /*******************************************************************************
3044 * Function: write_imsm_migr_rec
3045 * Description: Function writes imsm migration record
3046 * (at the last sector of disk)
3048 * super : imsm internal array info
3052 ******************************************************************************/
3053 static int write_imsm_migr_rec(struct supertype
*st
)
3055 struct intel_super
*super
= st
->sb
;
3056 unsigned int sector_size
= super
->sector_size
;
3057 unsigned long long dsize
;
3063 struct imsm_update_general_migration_checkpoint
*u
;
3064 struct imsm_dev
*dev
;
3065 struct imsm_map
*map
;
3067 /* find map under migration */
3068 dev
= imsm_get_device_during_migration(super
);
3069 /* if no migration, write buffer anyway to clear migr_record
3070 * on disk based on first available device
3073 dev
= get_imsm_dev(super
, super
->current_vol
< 0 ? 0 :
3074 super
->current_vol
);
3076 map
= get_imsm_map(dev
, MAP_0
);
3078 if (sector_size
== 4096)
3079 convert_to_4k_imsm_migr_rec(super
);
3080 for (sd
= super
->disks
; sd
; sd
= sd
->next
) {
3083 /* skip failed and spare devices */
3086 /* write to 2 first slots only */
3088 slot
= get_imsm_disk_slot(map
, sd
->index
);
3089 if (map
== NULL
|| slot
> 1 || slot
< 0)
3092 sprintf(nm
, "%d:%d", sd
->major
, sd
->minor
);
3093 fd
= dev_open(nm
, O_RDWR
);
3096 get_dev_size(fd
, NULL
, &dsize
);
3097 if (lseek64(fd
, dsize
- (MIGR_REC_SECTOR_POSITION
*sector_size
),
3099 pr_err("Cannot seek to anchor block: %s\n",
3103 if ((unsigned int)write(fd
, super
->migr_rec_buf
,
3104 MIGR_REC_BUF_SECTORS
*sector_size
) !=
3105 MIGR_REC_BUF_SECTORS
*sector_size
) {
3106 pr_err("Cannot write migr record block: %s\n",
3113 if (sector_size
== 4096)
3114 convert_from_4k_imsm_migr_rec(super
);
3115 /* update checkpoint information in metadata */
3116 len
= imsm_create_metadata_checkpoint_update(super
, &u
);
3118 dprintf("imsm: Cannot prepare update\n");
3121 /* update metadata locally */
3122 imsm_update_metadata_locally(st
, u
, len
);
3123 /* and possibly remotely */
3124 if (st
->update_tail
) {
3125 append_metadata_update(st
, u
, len
);
3126 /* during reshape we do all work inside metadata handler
3127 * manage_reshape(), so metadata update has to be triggered
3130 flush_metadata_updates(st
);
3131 st
->update_tail
= &st
->updates
;
3142 /* spare/missing disks activations are not allowe when
3143 * array/container performs reshape operation, because
3144 * all arrays in container works on the same disks set
3146 int imsm_reshape_blocks_arrays_changes(struct intel_super
*super
)
3149 struct intel_dev
*i_dev
;
3150 struct imsm_dev
*dev
;
3152 /* check whole container
3154 for (i_dev
= super
->devlist
; i_dev
; i_dev
= i_dev
->next
) {
3156 if (is_gen_migration(dev
)) {
3157 /* No repair during any migration in container
3165 static unsigned long long imsm_component_size_aligment_check(int level
,
3167 unsigned int sector_size
,
3168 unsigned long long component_size
)
3170 unsigned int component_size_alligment
;
3172 /* check component size aligment
3174 component_size_alligment
= component_size
% (chunk_size
/sector_size
);
3176 dprintf("(Level: %i, chunk_size = %i, component_size = %llu), component_size_alligment = %u\n",
3177 level
, chunk_size
, component_size
,
3178 component_size_alligment
);
3180 if (component_size_alligment
&& (level
!= 1) && (level
!= UnSet
)) {
3181 dprintf("imsm: reported component size alligned from %llu ",
3183 component_size
-= component_size_alligment
;
3184 dprintf_cont("to %llu (%i).\n",
3185 component_size
, component_size_alligment
);
3188 return component_size
;
3191 static unsigned long long get_ppl_sector(struct intel_super
*super
, int dev_idx
)
3193 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
3194 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3196 return pba_of_lba0(map
) +
3197 (num_data_stripes(map
) * map
->blocks_per_strip
);
3200 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
3202 struct intel_super
*super
= st
->sb
;
3203 struct migr_record
*migr_rec
= super
->migr_rec
;
3204 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
3205 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3206 struct imsm_map
*prev_map
= get_imsm_map(dev
, MAP_1
);
3207 struct imsm_map
*map_to_analyse
= map
;
3209 int map_disks
= info
->array
.raid_disks
;
3211 memset(info
, 0, sizeof(*info
));
3213 map_to_analyse
= prev_map
;
3215 dl
= super
->current_disk
;
3217 info
->container_member
= super
->current_vol
;
3218 info
->array
.raid_disks
= map
->num_members
;
3219 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
3220 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
3221 info
->array
.md_minor
= -1;
3222 info
->array
.ctime
= 0;
3223 info
->array
.utime
= 0;
3224 info
->array
.chunk_size
=
3225 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
3226 info
->array
.state
= !(dev
->vol
.dirty
& RAIDVOL_DIRTY
);
3227 info
->custom_array_size
= __le32_to_cpu(dev
->size_high
);
3228 info
->custom_array_size
<<= 32;
3229 info
->custom_array_size
|= __le32_to_cpu(dev
->size_low
);
3230 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
3232 if (is_gen_migration(dev
)) {
3233 info
->reshape_active
= 1;
3234 info
->new_level
= get_imsm_raid_level(map
);
3235 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
3236 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
3237 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
3238 if (info
->delta_disks
) {
3239 /* this needs to be applied to every array
3242 info
->reshape_active
= CONTAINER_RESHAPE
;
3244 /* We shape information that we give to md might have to be
3245 * modify to cope with md's requirement for reshaping arrays.
3246 * For example, when reshaping a RAID0, md requires it to be
3247 * presented as a degraded RAID4.
3248 * Also if a RAID0 is migrating to a RAID5 we need to specify
3249 * the array as already being RAID5, but the 'before' layout
3250 * is a RAID4-like layout.
3252 switch (info
->array
.level
) {
3254 switch(info
->new_level
) {
3256 /* conversion is happening as RAID4 */
3257 info
->array
.level
= 4;
3258 info
->array
.raid_disks
+= 1;
3261 /* conversion is happening as RAID5 */
3262 info
->array
.level
= 5;
3263 info
->array
.layout
= ALGORITHM_PARITY_N
;
3264 info
->delta_disks
-= 1;
3267 /* FIXME error message */
3268 info
->array
.level
= UnSet
;
3274 info
->new_level
= UnSet
;
3275 info
->new_layout
= UnSet
;
3276 info
->new_chunk
= info
->array
.chunk_size
;
3277 info
->delta_disks
= 0;
3281 info
->disk
.major
= dl
->major
;
3282 info
->disk
.minor
= dl
->minor
;
3283 info
->disk
.number
= dl
->index
;
3284 info
->disk
.raid_disk
= get_imsm_disk_slot(map_to_analyse
,
3288 info
->data_offset
= pba_of_lba0(map_to_analyse
);
3290 if (info
->array
.level
== 5) {
3291 info
->component_size
= num_data_stripes(map_to_analyse
) *
3292 map_to_analyse
->blocks_per_strip
;
3294 info
->component_size
= blocks_per_member(map_to_analyse
);
3297 info
->component_size
= imsm_component_size_aligment_check(
3299 info
->array
.chunk_size
,
3301 info
->component_size
);
3302 info
->bb
.supported
= 1;
3304 memset(info
->uuid
, 0, sizeof(info
->uuid
));
3305 info
->recovery_start
= MaxSector
;
3307 if (info
->array
.level
== 5 &&
3308 (dev
->rwh_policy
== RWH_DISTRIBUTED
||
3309 dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)) {
3310 info
->consistency_policy
= CONSISTENCY_POLICY_PPL
;
3311 info
->ppl_sector
= get_ppl_sector(super
, super
->current_vol
);
3312 if (dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)
3313 info
->ppl_size
= MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9;
3315 info
->ppl_size
= (PPL_HEADER_SIZE
+ PPL_ENTRY_SPACE
)
3317 } else if (info
->array
.level
<= 0) {
3318 info
->consistency_policy
= CONSISTENCY_POLICY_NONE
;
3320 info
->consistency_policy
= CONSISTENCY_POLICY_RESYNC
;
3323 info
->reshape_progress
= 0;
3324 info
->resync_start
= MaxSector
;
3325 if ((map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
3326 !(info
->array
.state
& 1)) &&
3327 imsm_reshape_blocks_arrays_changes(super
) == 0) {
3328 info
->resync_start
= 0;
3330 if (dev
->vol
.migr_state
) {
3331 switch (migr_type(dev
)) {
3334 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
3336 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
3338 info
->resync_start
= blocks_per_unit
* units
;
3341 case MIGR_GEN_MIGR
: {
3342 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
3344 __u64 units
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
3345 unsigned long long array_blocks
;
3348 if (__le32_to_cpu(migr_rec
->ascending_migr
) &&
3350 (__le32_to_cpu(migr_rec
->num_migr_units
)-1)) &&
3351 (super
->migr_rec
->rec_status
==
3352 __cpu_to_le32(UNIT_SRC_IN_CP_AREA
)))
3355 info
->reshape_progress
= blocks_per_unit
* units
;
3357 dprintf("IMSM: General Migration checkpoint : %llu (%llu) -> read reshape progress : %llu\n",
3358 (unsigned long long)units
,
3359 (unsigned long long)blocks_per_unit
,
3360 info
->reshape_progress
);
3362 used_disks
= imsm_num_data_members(dev
, MAP_1
);
3363 if (used_disks
> 0) {
3364 array_blocks
= blocks_per_member(map
) *
3366 info
->custom_array_size
=
3367 round_size_to_mb(array_blocks
,
3373 /* we could emulate the checkpointing of
3374 * 'sync_action=check' migrations, but for now
3375 * we just immediately complete them
3378 /* this is handled by container_content_imsm() */
3379 case MIGR_STATE_CHANGE
:
3380 /* FIXME handle other migrations */
3382 /* we are not dirty, so... */
3383 info
->resync_start
= MaxSector
;
3387 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
3388 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
3390 info
->array
.major_version
= -1;
3391 info
->array
.minor_version
= -2;
3392 sprintf(info
->text_version
, "/%s/%d", st
->container_devnm
, info
->container_member
);
3393 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
3394 uuid_from_super_imsm(st
, info
->uuid
);
3398 for (i
=0; i
<map_disks
; i
++) {
3400 if (i
< info
->array
.raid_disks
) {
3401 struct imsm_disk
*dsk
;
3402 j
= get_imsm_disk_idx(dev
, i
, MAP_X
);
3403 dsk
= get_imsm_disk(super
, j
);
3404 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
3411 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
3412 int failed
, int look_in_map
);
3414 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
3417 static void manage_second_map(struct intel_super
*super
, struct imsm_dev
*dev
)
3419 if (is_gen_migration(dev
)) {
3422 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
3424 failed
= imsm_count_failed(super
, dev
, MAP_1
);
3425 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_1
);
3426 if (map2
->map_state
!= map_state
) {
3427 map2
->map_state
= map_state
;
3428 super
->updates_pending
++;
3433 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
3437 for (d
= super
->missing
; d
; d
= d
->next
)
3438 if (d
->index
== index
)
3443 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
3445 struct intel_super
*super
= st
->sb
;
3446 struct imsm_disk
*disk
;
3447 int map_disks
= info
->array
.raid_disks
;
3448 int max_enough
= -1;
3450 struct imsm_super
*mpb
;
3452 if (super
->current_vol
>= 0) {
3453 getinfo_super_imsm_volume(st
, info
, map
);
3456 memset(info
, 0, sizeof(*info
));
3458 /* Set raid_disks to zero so that Assemble will always pull in valid
3461 info
->array
.raid_disks
= 0;
3462 info
->array
.level
= LEVEL_CONTAINER
;
3463 info
->array
.layout
= 0;
3464 info
->array
.md_minor
= -1;
3465 info
->array
.ctime
= 0; /* N/A for imsm */
3466 info
->array
.utime
= 0;
3467 info
->array
.chunk_size
= 0;
3469 info
->disk
.major
= 0;
3470 info
->disk
.minor
= 0;
3471 info
->disk
.raid_disk
= -1;
3472 info
->reshape_active
= 0;
3473 info
->array
.major_version
= -1;
3474 info
->array
.minor_version
= -2;
3475 strcpy(info
->text_version
, "imsm");
3476 info
->safe_mode_delay
= 0;
3477 info
->disk
.number
= -1;
3478 info
->disk
.state
= 0;
3480 info
->recovery_start
= MaxSector
;
3481 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
3482 info
->bb
.supported
= 1;
3484 /* do we have the all the insync disks that we expect? */
3485 mpb
= super
->anchor
;
3486 info
->events
= __le32_to_cpu(mpb
->generation_num
);
3488 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
3489 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
3490 int failed
, enough
, j
, missing
= 0;
3491 struct imsm_map
*map
;
3494 failed
= imsm_count_failed(super
, dev
, MAP_0
);
3495 state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
3496 map
= get_imsm_map(dev
, MAP_0
);
3498 /* any newly missing disks?
3499 * (catches single-degraded vs double-degraded)
3501 for (j
= 0; j
< map
->num_members
; j
++) {
3502 __u32 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
3503 __u32 idx
= ord_to_idx(ord
);
3505 if (super
->disks
&& super
->disks
->index
== (int)idx
)
3506 info
->disk
.raid_disk
= j
;
3508 if (!(ord
& IMSM_ORD_REBUILD
) &&
3509 get_imsm_missing(super
, idx
)) {
3515 if (state
== IMSM_T_STATE_FAILED
)
3517 else if (state
== IMSM_T_STATE_DEGRADED
&&
3518 (state
!= map
->map_state
|| missing
))
3520 else /* we're normal, or already degraded */
3522 if (is_gen_migration(dev
) && missing
) {
3523 /* during general migration we need all disks
3524 * that process is running on.
3525 * No new missing disk is allowed.
3529 /* no more checks necessary
3533 /* in the missing/failed disk case check to see
3534 * if at least one array is runnable
3536 max_enough
= max(max_enough
, enough
);
3538 dprintf("enough: %d\n", max_enough
);
3539 info
->container_enough
= max_enough
;
3542 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
3544 disk
= &super
->disks
->disk
;
3545 info
->data_offset
= total_blocks(&super
->disks
->disk
) - reserved
;
3546 info
->component_size
= reserved
;
3547 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
3548 /* we don't change info->disk.raid_disk here because
3549 * this state will be finalized in mdmon after we have
3550 * found the 'most fresh' version of the metadata
3552 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
3553 info
->disk
.state
|= (is_spare(disk
) || is_journal(disk
)) ?
3554 0 : (1 << MD_DISK_SYNC
);
3557 /* only call uuid_from_super_imsm when this disk is part of a populated container,
3558 * ->compare_super may have updated the 'num_raid_devs' field for spares
3560 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
3561 uuid_from_super_imsm(st
, info
->uuid
);
3563 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
3565 /* I don't know how to compute 'map' on imsm, so use safe default */
3568 for (i
= 0; i
< map_disks
; i
++)
3574 /* allocates memory and fills disk in mdinfo structure
3575 * for each disk in array */
3576 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
3578 struct mdinfo
*mddev
;
3579 struct intel_super
*super
= st
->sb
;
3580 struct imsm_disk
*disk
;
3583 if (!super
|| !super
->disks
)
3586 mddev
= xcalloc(1, sizeof(*mddev
));
3590 tmp
= xcalloc(1, sizeof(*tmp
));
3592 tmp
->next
= mddev
->devs
;
3594 tmp
->disk
.number
= count
++;
3595 tmp
->disk
.major
= dl
->major
;
3596 tmp
->disk
.minor
= dl
->minor
;
3597 tmp
->disk
.state
= is_configured(disk
) ?
3598 (1 << MD_DISK_ACTIVE
) : 0;
3599 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
3600 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
3601 tmp
->disk
.raid_disk
= -1;
3607 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
3608 char *update
, char *devname
, int verbose
,
3609 int uuid_set
, char *homehost
)
3611 /* For 'assemble' and 'force' we need to return non-zero if any
3612 * change was made. For others, the return value is ignored.
3613 * Update options are:
3614 * force-one : This device looks a bit old but needs to be included,
3615 * update age info appropriately.
3616 * assemble: clear any 'faulty' flag to allow this device to
3618 * force-array: Array is degraded but being forced, mark it clean
3619 * if that will be needed to assemble it.
3621 * newdev: not used ????
3622 * grow: Array has gained a new device - this is currently for
3624 * resync: mark as dirty so a resync will happen.
3625 * name: update the name - preserving the homehost
3626 * uuid: Change the uuid of the array to match watch is given
3628 * Following are not relevant for this imsm:
3629 * sparc2.2 : update from old dodgey metadata
3630 * super-minor: change the preferred_minor number
3631 * summaries: update redundant counters.
3632 * homehost: update the recorded homehost
3633 * _reshape_progress: record new reshape_progress position.
3636 struct intel_super
*super
= st
->sb
;
3637 struct imsm_super
*mpb
;
3639 /* we can only update container info */
3640 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
3643 mpb
= super
->anchor
;
3645 if (strcmp(update
, "uuid") == 0) {
3646 /* We take this to mean that the family_num should be updated.
3647 * However that is much smaller than the uuid so we cannot really
3648 * allow an explicit uuid to be given. And it is hard to reliably
3650 * So if !uuid_set we know the current uuid is random and just used
3651 * the first 'int' and copy it to the other 3 positions.
3652 * Otherwise we require the 4 'int's to be the same as would be the
3653 * case if we are using a random uuid. So an explicit uuid will be
3654 * accepted as long as all for ints are the same... which shouldn't hurt
3657 info
->uuid
[1] = info
->uuid
[2] = info
->uuid
[3] = info
->uuid
[0];
3660 if (info
->uuid
[0] != info
->uuid
[1] ||
3661 info
->uuid
[1] != info
->uuid
[2] ||
3662 info
->uuid
[2] != info
->uuid
[3])
3668 mpb
->orig_family_num
= info
->uuid
[0];
3669 } else if (strcmp(update
, "assemble") == 0)
3674 /* successful update? recompute checksum */
3676 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
3681 static size_t disks_to_mpb_size(int disks
)
3685 size
= sizeof(struct imsm_super
);
3686 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
3687 size
+= 2 * sizeof(struct imsm_dev
);
3688 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
3689 size
+= (4 - 2) * sizeof(struct imsm_map
);
3690 /* 4 possible disk_ord_tbl's */
3691 size
+= 4 * (disks
- 1) * sizeof(__u32
);
3692 /* maximum bbm log */
3693 size
+= sizeof(struct bbm_log
);
3698 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
,
3699 unsigned long long data_offset
)
3701 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
3704 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
3707 static void free_devlist(struct intel_super
*super
)
3709 struct intel_dev
*dv
;
3711 while (super
->devlist
) {
3712 dv
= super
->devlist
->next
;
3713 free(super
->devlist
->dev
);
3714 free(super
->devlist
);
3715 super
->devlist
= dv
;
3719 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
3721 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
3724 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
)
3728 * 0 same, or first was empty, and second was copied
3729 * 1 second had wrong number
3731 * 3 wrong other info
3733 struct intel_super
*first
= st
->sb
;
3734 struct intel_super
*sec
= tst
->sb
;
3741 /* in platform dependent environment test if the disks
3742 * use the same Intel hba
3743 * If not on Intel hba at all, allow anything.
3745 if (!check_env("IMSM_NO_PLATFORM") && first
->hba
&& sec
->hba
) {
3746 if (first
->hba
->type
!= sec
->hba
->type
) {
3748 "HBAs of devices do not match %s != %s\n",
3749 get_sys_dev_type(first
->hba
->type
),
3750 get_sys_dev_type(sec
->hba
->type
));
3753 if (first
->orom
!= sec
->orom
) {
3755 "HBAs of devices do not match %s != %s\n",
3756 first
->hba
->pci_id
, sec
->hba
->pci_id
);
3761 /* if an anchor does not have num_raid_devs set then it is a free
3764 if (first
->anchor
->num_raid_devs
> 0 &&
3765 sec
->anchor
->num_raid_devs
> 0) {
3766 /* Determine if these disks might ever have been
3767 * related. Further disambiguation can only take place
3768 * in load_super_imsm_all
3770 __u32 first_family
= first
->anchor
->orig_family_num
;
3771 __u32 sec_family
= sec
->anchor
->orig_family_num
;
3773 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
3774 MAX_SIGNATURE_LENGTH
) != 0)
3777 if (first_family
== 0)
3778 first_family
= first
->anchor
->family_num
;
3779 if (sec_family
== 0)
3780 sec_family
= sec
->anchor
->family_num
;
3782 if (first_family
!= sec_family
)
3787 /* if 'first' is a spare promote it to a populated mpb with sec's
3790 if (first
->anchor
->num_raid_devs
== 0 &&
3791 sec
->anchor
->num_raid_devs
> 0) {
3793 struct intel_dev
*dv
;
3794 struct imsm_dev
*dev
;
3796 /* we need to copy raid device info from sec if an allocation
3797 * fails here we don't associate the spare
3799 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++) {
3800 dv
= xmalloc(sizeof(*dv
));
3801 dev
= xmalloc(sizeof_imsm_dev(get_imsm_dev(sec
, i
), 1));
3804 dv
->next
= first
->devlist
;
3805 first
->devlist
= dv
;
3807 if (i
< sec
->anchor
->num_raid_devs
) {
3808 /* allocation failure */
3809 free_devlist(first
);
3810 pr_err("imsm: failed to associate spare\n");
3813 first
->anchor
->num_raid_devs
= sec
->anchor
->num_raid_devs
;
3814 first
->anchor
->orig_family_num
= sec
->anchor
->orig_family_num
;
3815 first
->anchor
->family_num
= sec
->anchor
->family_num
;
3816 memcpy(first
->anchor
->sig
, sec
->anchor
->sig
, MAX_SIGNATURE_LENGTH
);
3817 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++)
3818 imsm_copy_dev(get_imsm_dev(first
, i
), get_imsm_dev(sec
, i
));
3824 static void fd2devname(int fd
, char *name
)
3828 char dname
[PATH_MAX
];
3833 if (fstat(fd
, &st
) != 0)
3835 sprintf(path
, "/sys/dev/block/%d:%d",
3836 major(st
.st_rdev
), minor(st
.st_rdev
));
3838 rv
= readlink(path
, dname
, sizeof(dname
)-1);
3843 nm
= strrchr(dname
, '/');
3846 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
3850 static int nvme_get_serial(int fd
, void *buf
, size_t buf_len
)
3853 char *name
= fd2kname(fd
);
3858 if (strncmp(name
, "nvme", 4) != 0)
3861 snprintf(path
, sizeof(path
) - 1, "/sys/block/%s/device/serial", name
);
3863 return load_sys(path
, buf
, buf_len
);
3866 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
3868 static int imsm_read_serial(int fd
, char *devname
,
3869 __u8 serial
[MAX_RAID_SERIAL_LEN
])
3878 memset(buf
, 0, sizeof(buf
));
3880 rv
= nvme_get_serial(fd
, buf
, sizeof(buf
));
3883 rv
= scsi_get_serial(fd
, buf
, sizeof(buf
));
3885 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
3886 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3887 fd2devname(fd
, (char *) serial
);
3893 pr_err("Failed to retrieve serial for %s\n",
3898 /* trim all whitespace and non-printable characters and convert
3901 for (i
= 0, dest
= buf
; i
< sizeof(buf
) && buf
[i
]; i
++) {
3904 /* ':' is reserved for use in placeholder serial
3905 * numbers for missing disks
3916 /* truncate leading characters */
3917 if (len
> MAX_RAID_SERIAL_LEN
) {
3918 dest
+= len
- MAX_RAID_SERIAL_LEN
;
3919 len
= MAX_RAID_SERIAL_LEN
;
3922 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3923 memcpy(serial
, dest
, len
);
3928 static int serialcmp(__u8
*s1
, __u8
*s2
)
3930 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
3933 static void serialcpy(__u8
*dest
, __u8
*src
)
3935 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
3938 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
3942 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3943 if (serialcmp(dl
->serial
, serial
) == 0)
3949 static struct imsm_disk
*
3950 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
3954 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3955 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
3957 if (serialcmp(disk
->serial
, serial
) == 0) {
3968 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3970 struct imsm_disk
*disk
;
3975 __u8 serial
[MAX_RAID_SERIAL_LEN
];
3977 rv
= imsm_read_serial(fd
, devname
, serial
);
3982 dl
= xcalloc(1, sizeof(*dl
));
3985 dl
->major
= major(stb
.st_rdev
);
3986 dl
->minor
= minor(stb
.st_rdev
);
3987 dl
->next
= super
->disks
;
3988 dl
->fd
= keep_fd
? fd
: -1;
3989 assert(super
->disks
== NULL
);
3991 serialcpy(dl
->serial
, serial
);
3994 fd2devname(fd
, name
);
3996 dl
->devname
= xstrdup(devname
);
3998 dl
->devname
= xstrdup(name
);
4000 /* look up this disk's index in the current anchor */
4001 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
4004 /* only set index on disks that are a member of a
4005 * populated contianer, i.e. one with raid_devs
4007 if (is_failed(&dl
->disk
))
4009 else if (is_spare(&dl
->disk
) || is_journal(&dl
->disk
))
4016 /* When migrating map0 contains the 'destination' state while map1
4017 * contains the current state. When not migrating map0 contains the
4018 * current state. This routine assumes that map[0].map_state is set to
4019 * the current array state before being called.
4021 * Migration is indicated by one of the following states
4022 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
4023 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
4024 * map1state=unitialized)
4025 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
4027 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
4028 * map1state=degraded)
4029 * 5/ Migration (mig_state=1 migr_type=MIGR_GEN_MIGR map0state=normal
4032 static void migrate(struct imsm_dev
*dev
, struct intel_super
*super
,
4033 __u8 to_state
, int migr_type
)
4035 struct imsm_map
*dest
;
4036 struct imsm_map
*src
= get_imsm_map(dev
, MAP_0
);
4038 dev
->vol
.migr_state
= 1;
4039 set_migr_type(dev
, migr_type
);
4040 dev
->vol
.curr_migr_unit
= 0;
4041 dest
= get_imsm_map(dev
, MAP_1
);
4043 /* duplicate and then set the target end state in map[0] */
4044 memcpy(dest
, src
, sizeof_imsm_map(src
));
4045 if (migr_type
== MIGR_GEN_MIGR
) {
4049 for (i
= 0; i
< src
->num_members
; i
++) {
4050 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
4051 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
4055 if (migr_type
== MIGR_GEN_MIGR
)
4056 /* Clear migration record */
4057 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
4059 src
->map_state
= to_state
;
4062 static void end_migration(struct imsm_dev
*dev
, struct intel_super
*super
,
4065 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
4066 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
== 0 ?
4070 /* merge any IMSM_ORD_REBUILD bits that were not successfully
4071 * completed in the last migration.
4073 * FIXME add support for raid-level-migration
4075 if (map_state
!= map
->map_state
&& (is_gen_migration(dev
) == 0) &&
4076 prev
->map_state
!= IMSM_T_STATE_UNINITIALIZED
) {
4077 /* when final map state is other than expected
4078 * merge maps (not for migration)
4082 for (i
= 0; i
< prev
->num_members
; i
++)
4083 for (j
= 0; j
< map
->num_members
; j
++)
4084 /* during online capacity expansion
4085 * disks position can be changed
4086 * if takeover is used
4088 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
4089 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
4090 map
->disk_ord_tbl
[j
] |=
4091 prev
->disk_ord_tbl
[i
];
4094 failed
= imsm_count_failed(super
, dev
, MAP_0
);
4095 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
4098 dev
->vol
.migr_state
= 0;
4099 set_migr_type(dev
, 0);
4100 dev
->vol
.curr_migr_unit
= 0;
4101 map
->map_state
= map_state
;
4104 static int parse_raid_devices(struct intel_super
*super
)
4107 struct imsm_dev
*dev_new
;
4108 size_t len
, len_migr
;
4110 size_t space_needed
= 0;
4111 struct imsm_super
*mpb
= super
->anchor
;
4113 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
4114 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
4115 struct intel_dev
*dv
;
4117 len
= sizeof_imsm_dev(dev_iter
, 0);
4118 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
4120 space_needed
+= len_migr
- len
;
4122 dv
= xmalloc(sizeof(*dv
));
4123 if (max_len
< len_migr
)
4125 if (max_len
> len_migr
)
4126 space_needed
+= max_len
- len_migr
;
4127 dev_new
= xmalloc(max_len
);
4128 imsm_copy_dev(dev_new
, dev_iter
);
4131 dv
->next
= super
->devlist
;
4132 super
->devlist
= dv
;
4135 /* ensure that super->buf is large enough when all raid devices
4138 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
4141 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
,
4142 super
->sector_size
);
4143 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, len
) != 0)
4146 memcpy(buf
, super
->buf
, super
->len
);
4147 memset(buf
+ super
->len
, 0, len
- super
->len
);
4153 super
->extra_space
+= space_needed
;
4158 /*******************************************************************************
4159 * Function: check_mpb_migr_compatibility
4160 * Description: Function checks for unsupported migration features:
4161 * - migration optimization area (pba_of_lba0)
4162 * - descending reshape (ascending_migr)
4164 * super : imsm metadata information
4166 * 0 : migration is compatible
4167 * -1 : migration is not compatible
4168 ******************************************************************************/
4169 int check_mpb_migr_compatibility(struct intel_super
*super
)
4171 struct imsm_map
*map0
, *map1
;
4172 struct migr_record
*migr_rec
= super
->migr_rec
;
4175 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
4176 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
4179 dev_iter
->vol
.migr_state
== 1 &&
4180 dev_iter
->vol
.migr_type
== MIGR_GEN_MIGR
) {
4181 /* This device is migrating */
4182 map0
= get_imsm_map(dev_iter
, MAP_0
);
4183 map1
= get_imsm_map(dev_iter
, MAP_1
);
4184 if (pba_of_lba0(map0
) != pba_of_lba0(map1
))
4185 /* migration optimization area was used */
4187 if (migr_rec
->ascending_migr
== 0 &&
4188 migr_rec
->dest_depth_per_unit
> 0)
4189 /* descending reshape not supported yet */
4196 static void __free_imsm(struct intel_super
*super
, int free_disks
);
4198 /* load_imsm_mpb - read matrix metadata
4199 * allocates super->mpb to be freed by free_imsm
4201 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
4203 unsigned long long dsize
;
4204 unsigned long long sectors
;
4205 unsigned int sector_size
= super
->sector_size
;
4207 struct imsm_super
*anchor
;
4210 get_dev_size(fd
, NULL
, &dsize
);
4211 if (dsize
< 2*sector_size
) {
4213 pr_err("%s: device to small for imsm\n",
4218 if (lseek64(fd
, dsize
- (sector_size
* 2), SEEK_SET
) < 0) {
4220 pr_err("Cannot seek to anchor block on %s: %s\n",
4221 devname
, strerror(errno
));
4225 if (posix_memalign((void **)&anchor
, sector_size
, sector_size
) != 0) {
4227 pr_err("Failed to allocate imsm anchor buffer on %s\n", devname
);
4230 if ((unsigned int)read(fd
, anchor
, sector_size
) != sector_size
) {
4232 pr_err("Cannot read anchor block on %s: %s\n",
4233 devname
, strerror(errno
));
4238 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
4240 pr_err("no IMSM anchor on %s\n", devname
);
4245 __free_imsm(super
, 0);
4246 /* reload capability and hba */
4248 /* capability and hba must be updated with new super allocation */
4249 find_intel_hba_capability(fd
, super
, devname
);
4250 super
->len
= ROUND_UP(anchor
->mpb_size
, sector_size
);
4251 if (posix_memalign(&super
->buf
, MAX_SECTOR_SIZE
, super
->len
) != 0) {
4253 pr_err("unable to allocate %zu byte mpb buffer\n",
4258 memcpy(super
->buf
, anchor
, sector_size
);
4260 sectors
= mpb_sectors(anchor
, sector_size
) - 1;
4263 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
4264 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
) != 0) {
4265 pr_err("could not allocate migr_rec buffer\n");
4269 super
->clean_migration_record_by_mdmon
= 0;
4272 check_sum
= __gen_imsm_checksum(super
->anchor
);
4273 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
4275 pr_err("IMSM checksum %x != %x on %s\n",
4277 __le32_to_cpu(super
->anchor
->check_sum
),
4285 /* read the extended mpb */
4286 if (lseek64(fd
, dsize
- (sector_size
* (2 + sectors
)), SEEK_SET
) < 0) {
4288 pr_err("Cannot seek to extended mpb on %s: %s\n",
4289 devname
, strerror(errno
));
4293 if ((unsigned int)read(fd
, super
->buf
+ sector_size
,
4294 super
->len
- sector_size
) != super
->len
- sector_size
) {
4296 pr_err("Cannot read extended mpb on %s: %s\n",
4297 devname
, strerror(errno
));
4301 check_sum
= __gen_imsm_checksum(super
->anchor
);
4302 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
4304 pr_err("IMSM checksum %x != %x on %s\n",
4305 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
4313 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
);
4315 /* clears hi bits in metadata if MPB_ATTRIB_2TB_DISK not set */
4316 static void clear_hi(struct intel_super
*super
)
4318 struct imsm_super
*mpb
= super
->anchor
;
4320 if (mpb
->attributes
& MPB_ATTRIB_2TB_DISK
)
4322 for (i
= 0; i
< mpb
->num_disks
; ++i
) {
4323 struct imsm_disk
*disk
= &mpb
->disk
[i
];
4324 disk
->total_blocks_hi
= 0;
4326 for (i
= 0; i
< mpb
->num_raid_devs
; ++i
) {
4327 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
4330 for (n
= 0; n
< 2; ++n
) {
4331 struct imsm_map
*map
= get_imsm_map(dev
, n
);
4334 map
->pba_of_lba0_hi
= 0;
4335 map
->blocks_per_member_hi
= 0;
4336 map
->num_data_stripes_hi
= 0;
4342 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
4346 err
= load_imsm_mpb(fd
, super
, devname
);
4349 if (super
->sector_size
== 4096)
4350 convert_from_4k(super
);
4351 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
4354 err
= parse_raid_devices(super
);
4357 err
= load_bbm_log(super
);
4362 static void __free_imsm_disk(struct dl
*d
)
4374 static void free_imsm_disks(struct intel_super
*super
)
4378 while (super
->disks
) {
4380 super
->disks
= d
->next
;
4381 __free_imsm_disk(d
);
4383 while (super
->disk_mgmt_list
) {
4384 d
= super
->disk_mgmt_list
;
4385 super
->disk_mgmt_list
= d
->next
;
4386 __free_imsm_disk(d
);
4388 while (super
->missing
) {
4390 super
->missing
= d
->next
;
4391 __free_imsm_disk(d
);
4396 /* free all the pieces hanging off of a super pointer */
4397 static void __free_imsm(struct intel_super
*super
, int free_disks
)
4399 struct intel_hba
*elem
, *next
;
4405 /* unlink capability description */
4407 if (super
->migr_rec_buf
) {
4408 free(super
->migr_rec_buf
);
4409 super
->migr_rec_buf
= NULL
;
4412 free_imsm_disks(super
);
4413 free_devlist(super
);
4417 free((void *)elem
->path
);
4423 free(super
->bbm_log
);
4427 static void free_imsm(struct intel_super
*super
)
4429 __free_imsm(super
, 1);
4430 free(super
->bb
.entries
);
4434 static void free_super_imsm(struct supertype
*st
)
4436 struct intel_super
*super
= st
->sb
;
4445 static struct intel_super
*alloc_super(void)
4447 struct intel_super
*super
= xcalloc(1, sizeof(*super
));
4449 super
->current_vol
= -1;
4450 super
->create_offset
= ~((unsigned long long) 0);
4452 super
->bb
.entries
= xmalloc(BBM_LOG_MAX_ENTRIES
*
4453 sizeof(struct md_bb_entry
));
4454 if (!super
->bb
.entries
) {
4463 * find and allocate hba and OROM/EFI based on valid fd of RAID component device
4465 static int find_intel_hba_capability(int fd
, struct intel_super
*super
, char *devname
)
4467 struct sys_dev
*hba_name
;
4470 if (fd
< 0 || check_env("IMSM_NO_PLATFORM")) {
4475 hba_name
= find_disk_attached_hba(fd
, NULL
);
4478 pr_err("%s is not attached to Intel(R) RAID controller.\n",
4482 rv
= attach_hba_to_super(super
, hba_name
);
4485 struct intel_hba
*hba
= super
->hba
;
4487 pr_err("%s is attached to Intel(R) %s %s (%s),\n"
4488 " but the container is assigned to Intel(R) %s %s (",
4490 get_sys_dev_type(hba_name
->type
),
4491 hba_name
->type
== SYS_DEV_VMD
? "domain" : "RAID controller",
4492 hba_name
->pci_id
? : "Err!",
4493 get_sys_dev_type(super
->hba
->type
),
4494 hba
->type
== SYS_DEV_VMD
? "domain" : "RAID controller");
4497 fprintf(stderr
, "%s", hba
->pci_id
? : "Err!");
4499 fprintf(stderr
, ", ");
4502 fprintf(stderr
, ").\n"
4503 " Mixing devices attached to different %s is not allowed.\n",
4504 hba_name
->type
== SYS_DEV_VMD
? "VMD domains" : "controllers");
4508 super
->orom
= find_imsm_capability(hba_name
);
4515 /* find_missing - helper routine for load_super_imsm_all that identifies
4516 * disks that have disappeared from the system. This routine relies on
4517 * the mpb being uptodate, which it is at load time.
4519 static int find_missing(struct intel_super
*super
)
4522 struct imsm_super
*mpb
= super
->anchor
;
4524 struct imsm_disk
*disk
;
4526 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4527 disk
= __get_imsm_disk(mpb
, i
);
4528 dl
= serial_to_dl(disk
->serial
, super
);
4532 dl
= xmalloc(sizeof(*dl
));
4536 dl
->devname
= xstrdup("missing");
4538 serialcpy(dl
->serial
, disk
->serial
);
4541 dl
->next
= super
->missing
;
4542 super
->missing
= dl
;
4548 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
4550 struct intel_disk
*idisk
= disk_list
;
4553 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
4555 idisk
= idisk
->next
;
4561 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
4562 struct intel_super
*super
,
4563 struct intel_disk
**disk_list
)
4565 struct imsm_disk
*d
= &super
->disks
->disk
;
4566 struct imsm_super
*mpb
= super
->anchor
;
4569 for (i
= 0; i
< tbl_size
; i
++) {
4570 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
4571 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
4573 if (tbl_mpb
->family_num
== mpb
->family_num
) {
4574 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
4575 dprintf("mpb from %d:%d matches %d:%d\n",
4576 super
->disks
->major
,
4577 super
->disks
->minor
,
4578 table
[i
]->disks
->major
,
4579 table
[i
]->disks
->minor
);
4583 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
4584 is_configured(d
) == is_configured(tbl_d
)) &&
4585 tbl_mpb
->generation_num
< mpb
->generation_num
) {
4586 /* current version of the mpb is a
4587 * better candidate than the one in
4588 * super_table, but copy over "cross
4589 * generational" status
4591 struct intel_disk
*idisk
;
4593 dprintf("mpb from %d:%d replaces %d:%d\n",
4594 super
->disks
->major
,
4595 super
->disks
->minor
,
4596 table
[i
]->disks
->major
,
4597 table
[i
]->disks
->minor
);
4599 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
4600 if (idisk
&& is_failed(&idisk
->disk
))
4601 tbl_d
->status
|= FAILED_DISK
;
4604 struct intel_disk
*idisk
;
4605 struct imsm_disk
*disk
;
4607 /* tbl_mpb is more up to date, but copy
4608 * over cross generational status before
4611 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
4612 if (disk
&& is_failed(disk
))
4613 d
->status
|= FAILED_DISK
;
4615 idisk
= disk_list_get(d
->serial
, *disk_list
);
4618 if (disk
&& is_configured(disk
))
4619 idisk
->disk
.status
|= CONFIGURED_DISK
;
4622 dprintf("mpb from %d:%d prefer %d:%d\n",
4623 super
->disks
->major
,
4624 super
->disks
->minor
,
4625 table
[i
]->disks
->major
,
4626 table
[i
]->disks
->minor
);
4634 table
[tbl_size
++] = super
;
4638 /* update/extend the merged list of imsm_disk records */
4639 for (j
= 0; j
< mpb
->num_disks
; j
++) {
4640 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
4641 struct intel_disk
*idisk
;
4643 idisk
= disk_list_get(disk
->serial
, *disk_list
);
4645 idisk
->disk
.status
|= disk
->status
;
4646 if (is_configured(&idisk
->disk
) ||
4647 is_failed(&idisk
->disk
))
4648 idisk
->disk
.status
&= ~(SPARE_DISK
);
4650 idisk
= xcalloc(1, sizeof(*idisk
));
4651 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
4652 idisk
->disk
= *disk
;
4653 idisk
->next
= *disk_list
;
4657 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
4664 static struct intel_super
*
4665 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
4668 struct imsm_super
*mpb
= super
->anchor
;
4672 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4673 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
4674 struct intel_disk
*idisk
;
4676 idisk
= disk_list_get(disk
->serial
, disk_list
);
4678 if (idisk
->owner
== owner
||
4679 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
4682 dprintf("'%.16s' owner %d != %d\n",
4683 disk
->serial
, idisk
->owner
,
4686 dprintf("unknown disk %x [%d]: %.16s\n",
4687 __le32_to_cpu(mpb
->family_num
), i
,
4693 if (ok_count
== mpb
->num_disks
)
4698 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
4700 struct intel_super
*s
;
4702 for (s
= super_list
; s
; s
= s
->next
) {
4703 if (family_num
!= s
->anchor
->family_num
)
4705 pr_err("Conflict, offlining family %#x on '%s'\n",
4706 __le32_to_cpu(family_num
), s
->disks
->devname
);
4710 static struct intel_super
*
4711 imsm_thunderdome(struct intel_super
**super_list
, int len
)
4713 struct intel_super
*super_table
[len
];
4714 struct intel_disk
*disk_list
= NULL
;
4715 struct intel_super
*champion
, *spare
;
4716 struct intel_super
*s
, **del
;
4721 memset(super_table
, 0, sizeof(super_table
));
4722 for (s
= *super_list
; s
; s
= s
->next
)
4723 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
4725 for (i
= 0; i
< tbl_size
; i
++) {
4726 struct imsm_disk
*d
;
4727 struct intel_disk
*idisk
;
4728 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
4731 d
= &s
->disks
->disk
;
4733 /* 'd' must appear in merged disk list for its
4734 * configuration to be valid
4736 idisk
= disk_list_get(d
->serial
, disk_list
);
4737 if (idisk
&& idisk
->owner
== i
)
4738 s
= validate_members(s
, disk_list
, i
);
4743 dprintf("marking family: %#x from %d:%d offline\n",
4745 super_table
[i
]->disks
->major
,
4746 super_table
[i
]->disks
->minor
);
4750 /* This is where the mdadm implementation differs from the Windows
4751 * driver which has no strict concept of a container. We can only
4752 * assemble one family from a container, so when returning a prodigal
4753 * array member to this system the code will not be able to disambiguate
4754 * the container contents that should be assembled ("foreign" versus
4755 * "local"). It requires user intervention to set the orig_family_num
4756 * to a new value to establish a new container. The Windows driver in
4757 * this situation fixes up the volume name in place and manages the
4758 * foreign array as an independent entity.
4763 for (i
= 0; i
< tbl_size
; i
++) {
4764 struct intel_super
*tbl_ent
= super_table
[i
];
4770 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
4775 if (s
&& !is_spare
) {
4776 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
4778 } else if (!s
&& !is_spare
)
4791 pr_err("Chose family %#x on '%s', assemble conflicts to new container with '--update=uuid'\n",
4792 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
4794 /* collect all dl's onto 'champion', and update them to
4795 * champion's version of the status
4797 for (s
= *super_list
; s
; s
= s
->next
) {
4798 struct imsm_super
*mpb
= champion
->anchor
;
4799 struct dl
*dl
= s
->disks
;
4804 mpb
->attributes
|= s
->anchor
->attributes
& MPB_ATTRIB_2TB_DISK
;
4806 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4807 struct imsm_disk
*disk
;
4809 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
4812 /* only set index on disks that are a member of
4813 * a populated contianer, i.e. one with
4816 if (is_failed(&dl
->disk
))
4818 else if (is_spare(&dl
->disk
))
4824 if (i
>= mpb
->num_disks
) {
4825 struct intel_disk
*idisk
;
4827 idisk
= disk_list_get(dl
->serial
, disk_list
);
4828 if (idisk
&& is_spare(&idisk
->disk
) &&
4829 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
4837 dl
->next
= champion
->disks
;
4838 champion
->disks
= dl
;
4842 /* delete 'champion' from super_list */
4843 for (del
= super_list
; *del
; ) {
4844 if (*del
== champion
) {
4845 *del
= (*del
)->next
;
4848 del
= &(*del
)->next
;
4850 champion
->next
= NULL
;
4854 struct intel_disk
*idisk
= disk_list
;
4856 disk_list
= disk_list
->next
;
4864 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
);
4865 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4866 int major
, int minor
, int keep_fd
);
4868 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4869 int *max
, int keep_fd
);
4871 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
4872 char *devname
, struct md_list
*devlist
,
4875 struct intel_super
*super_list
= NULL
;
4876 struct intel_super
*super
= NULL
;
4881 /* 'fd' is an opened container */
4882 err
= get_sra_super_block(fd
, &super_list
, devname
, &i
, keep_fd
);
4884 /* get super block from devlist devices */
4885 err
= get_devlist_super_block(devlist
, &super_list
, &i
, keep_fd
);
4888 /* all mpbs enter, maybe one leaves */
4889 super
= imsm_thunderdome(&super_list
, i
);
4895 if (find_missing(super
) != 0) {
4901 /* load migration record */
4902 err
= load_imsm_migr_rec(super
, NULL
);
4904 /* migration is in progress,
4905 * but migr_rec cannot be loaded,
4911 /* Check migration compatibility */
4912 if (err
== 0 && check_mpb_migr_compatibility(super
) != 0) {
4913 pr_err("Unsupported migration detected");
4915 fprintf(stderr
, " on %s\n", devname
);
4917 fprintf(stderr
, " (IMSM).\n");
4926 while (super_list
) {
4927 struct intel_super
*s
= super_list
;
4929 super_list
= super_list
->next
;
4938 strcpy(st
->container_devnm
, fd2devnm(fd
));
4940 st
->container_devnm
[0] = 0;
4941 if (err
== 0 && st
->ss
== NULL
) {
4942 st
->ss
= &super_imsm
;
4943 st
->minor_version
= 0;
4944 st
->max_devs
= IMSM_MAX_DEVICES
;
4950 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4951 int *max
, int keep_fd
)
4953 struct md_list
*tmpdev
;
4957 for (i
= 0, tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
4958 if (tmpdev
->used
!= 1)
4960 if (tmpdev
->container
== 1) {
4962 int fd
= dev_open(tmpdev
->devname
, O_RDONLY
|O_EXCL
);
4964 pr_err("cannot open device %s: %s\n",
4965 tmpdev
->devname
, strerror(errno
));
4969 err
= get_sra_super_block(fd
, super_list
,
4970 tmpdev
->devname
, &lmax
,
4979 int major
= major(tmpdev
->st_rdev
);
4980 int minor
= minor(tmpdev
->st_rdev
);
4981 err
= get_super_block(super_list
,
4998 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4999 int major
, int minor
, int keep_fd
)
5001 struct intel_super
*s
;
5013 sprintf(nm
, "%d:%d", major
, minor
);
5014 dfd
= dev_open(nm
, O_RDWR
);
5020 get_dev_sector_size(dfd
, NULL
, &s
->sector_size
);
5021 find_intel_hba_capability(dfd
, s
, devname
);
5022 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
5024 /* retry the load if we might have raced against mdmon */
5025 if (err
== 3 && devnm
&& mdmon_running(devnm
))
5026 for (retry
= 0; retry
< 3; retry
++) {
5028 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
5034 s
->next
= *super_list
;
5042 if (dfd
>= 0 && !keep_fd
)
5049 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
)
5056 sra
= sysfs_read(fd
, NULL
, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
5060 if (sra
->array
.major_version
!= -1 ||
5061 sra
->array
.minor_version
!= -2 ||
5062 strcmp(sra
->text_version
, "imsm") != 0) {
5067 devnm
= fd2devnm(fd
);
5068 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
5069 if (get_super_block(super_list
, devnm
, devname
,
5070 sd
->disk
.major
, sd
->disk
.minor
, keep_fd
) != 0) {
5081 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
5083 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
, NULL
, 1);
5086 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
5088 struct intel_super
*super
;
5092 if (test_partition(fd
))
5093 /* IMSM not allowed on partitions */
5096 free_super_imsm(st
);
5098 super
= alloc_super();
5099 get_dev_sector_size(fd
, NULL
, &super
->sector_size
);
5102 /* Load hba and capabilities if they exist.
5103 * But do not preclude loading metadata in case capabilities or hba are
5104 * non-compliant and ignore_hw_compat is set.
5106 rv
= find_intel_hba_capability(fd
, super
, devname
);
5107 /* no orom/efi or non-intel hba of the disk */
5108 if (rv
!= 0 && st
->ignore_hw_compat
== 0) {
5110 pr_err("No OROM/EFI properties for %s\n", devname
);
5114 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
5116 /* retry the load if we might have raced against mdmon */
5118 struct mdstat_ent
*mdstat
= NULL
;
5119 char *name
= fd2kname(fd
);
5122 mdstat
= mdstat_by_component(name
);
5124 if (mdstat
&& mdmon_running(mdstat
->devnm
) && getpid() != mdmon_pid(mdstat
->devnm
)) {
5125 for (retry
= 0; retry
< 3; retry
++) {
5127 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
5133 free_mdstat(mdstat
);
5138 pr_err("Failed to load all information sections on %s\n", devname
);
5144 if (st
->ss
== NULL
) {
5145 st
->ss
= &super_imsm
;
5146 st
->minor_version
= 0;
5147 st
->max_devs
= IMSM_MAX_DEVICES
;
5150 /* load migration record */
5151 if (load_imsm_migr_rec(super
, NULL
) == 0) {
5152 /* Check for unsupported migration features */
5153 if (check_mpb_migr_compatibility(super
) != 0) {
5154 pr_err("Unsupported migration detected");
5156 fprintf(stderr
, " on %s\n", devname
);
5158 fprintf(stderr
, " (IMSM).\n");
5166 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
5168 if (info
->level
== 1)
5170 return info
->chunk_size
>> 9;
5173 static unsigned long long info_to_blocks_per_member(mdu_array_info_t
*info
,
5174 unsigned long long size
)
5176 if (info
->level
== 1)
5179 return (size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
5182 static void imsm_update_version_info(struct intel_super
*super
)
5184 /* update the version and attributes */
5185 struct imsm_super
*mpb
= super
->anchor
;
5187 struct imsm_dev
*dev
;
5188 struct imsm_map
*map
;
5191 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5192 dev
= get_imsm_dev(super
, i
);
5193 map
= get_imsm_map(dev
, MAP_0
);
5194 if (__le32_to_cpu(dev
->size_high
) > 0)
5195 mpb
->attributes
|= MPB_ATTRIB_2TB
;
5197 /* FIXME detect when an array spans a port multiplier */
5199 mpb
->attributes
|= MPB_ATTRIB_PM
;
5202 if (mpb
->num_raid_devs
> 1 ||
5203 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
5204 version
= MPB_VERSION_ATTRIBS
;
5205 switch (get_imsm_raid_level(map
)) {
5206 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
5207 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
5208 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
5209 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
5212 if (map
->num_members
>= 5)
5213 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
5214 else if (dev
->status
== DEV_CLONE_N_GO
)
5215 version
= MPB_VERSION_CNG
;
5216 else if (get_imsm_raid_level(map
) == 5)
5217 version
= MPB_VERSION_RAID5
;
5218 else if (map
->num_members
>= 3)
5219 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
5220 else if (get_imsm_raid_level(map
) == 1)
5221 version
= MPB_VERSION_RAID1
;
5223 version
= MPB_VERSION_RAID0
;
5225 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
5229 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
5231 struct imsm_super
*mpb
= super
->anchor
;
5232 char *reason
= NULL
;
5235 if (strlen(name
) > MAX_RAID_SERIAL_LEN
)
5236 reason
= "must be 16 characters or less";
5238 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5239 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
5241 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
5242 reason
= "already exists";
5247 if (reason
&& !quiet
)
5248 pr_err("imsm volume name %s\n", reason
);
5253 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
5254 struct shape
*s
, char *name
,
5255 char *homehost
, int *uuid
,
5256 long long data_offset
)
5258 /* We are creating a volume inside a pre-existing container.
5259 * so st->sb is already set.
5261 struct intel_super
*super
= st
->sb
;
5262 unsigned int sector_size
= super
->sector_size
;
5263 struct imsm_super
*mpb
= super
->anchor
;
5264 struct intel_dev
*dv
;
5265 struct imsm_dev
*dev
;
5266 struct imsm_vol
*vol
;
5267 struct imsm_map
*map
;
5268 int idx
= mpb
->num_raid_devs
;
5270 unsigned long long array_blocks
;
5271 size_t size_old
, size_new
;
5272 unsigned long long num_data_stripes
;
5273 unsigned int data_disks
;
5274 unsigned long long size_per_member
;
5276 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
5277 pr_err("This imsm-container already has the maximum of %d volumes\n", super
->orom
->vpa
);
5281 /* ensure the mpb is large enough for the new data */
5282 size_old
= __le32_to_cpu(mpb
->mpb_size
);
5283 size_new
= disks_to_mpb_size(info
->nr_disks
);
5284 if (size_new
> size_old
) {
5286 size_t size_round
= ROUND_UP(size_new
, sector_size
);
5288 if (posix_memalign(&mpb_new
, sector_size
, size_round
) != 0) {
5289 pr_err("could not allocate new mpb\n");
5292 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
5293 MIGR_REC_BUF_SECTORS
*
5294 MAX_SECTOR_SIZE
) != 0) {
5295 pr_err("could not allocate migr_rec buffer\n");
5301 memcpy(mpb_new
, mpb
, size_old
);
5304 super
->anchor
= mpb_new
;
5305 mpb
->mpb_size
= __cpu_to_le32(size_new
);
5306 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
5307 super
->len
= size_round
;
5309 super
->current_vol
= idx
;
5311 /* handle 'failed_disks' by either:
5312 * a) create dummy disk entries in the table if this the first
5313 * volume in the array. We add them here as this is the only
5314 * opportunity to add them. add_to_super_imsm_volume()
5315 * handles the non-failed disks and continues incrementing
5317 * b) validate that 'failed_disks' matches the current number
5318 * of missing disks if the container is populated
5320 if (super
->current_vol
== 0) {
5322 for (i
= 0; i
< info
->failed_disks
; i
++) {
5323 struct imsm_disk
*disk
;
5326 disk
= __get_imsm_disk(mpb
, i
);
5327 disk
->status
= CONFIGURED_DISK
| FAILED_DISK
;
5328 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
5329 snprintf((char *) disk
->serial
, MAX_RAID_SERIAL_LEN
,
5330 "missing:%d", (__u8
)i
);
5332 find_missing(super
);
5337 for (d
= super
->missing
; d
; d
= d
->next
)
5339 if (info
->failed_disks
> missing
) {
5340 pr_err("unable to add 'missing' disk to container\n");
5345 if (!check_name(super
, name
, 0))
5347 dv
= xmalloc(sizeof(*dv
));
5348 dev
= xcalloc(1, sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
5349 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
5350 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
5351 info
->layout
, info
->chunk_size
,
5352 s
->size
* BLOCKS_PER_KB
);
5353 data_disks
= get_data_disks(info
->level
, info
->layout
,
5355 array_blocks
= round_size_to_mb(array_blocks
, data_disks
);
5356 size_per_member
= array_blocks
/ data_disks
;
5358 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
5359 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
5360 dev
->status
= (DEV_READ_COALESCING
| DEV_WRITE_COALESCING
);
5362 vol
->migr_state
= 0;
5363 set_migr_type(dev
, MIGR_INIT
);
5364 vol
->dirty
= !info
->state
;
5365 vol
->curr_migr_unit
= 0;
5366 map
= get_imsm_map(dev
, MAP_0
);
5367 set_pba_of_lba0(map
, super
->create_offset
);
5368 set_blocks_per_member(map
, info_to_blocks_per_member(info
,
5371 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
5372 map
->failed_disk_num
= ~0;
5373 if (info
->level
> 0)
5374 map
->map_state
= (info
->state
? IMSM_T_STATE_NORMAL
5375 : IMSM_T_STATE_UNINITIALIZED
);
5377 map
->map_state
= info
->failed_disks
? IMSM_T_STATE_FAILED
:
5378 IMSM_T_STATE_NORMAL
;
5381 if (info
->level
== 1 && info
->raid_disks
> 2) {
5384 pr_err("imsm does not support more than 2 disksin a raid1 volume\n");
5388 map
->raid_level
= info
->level
;
5389 if (info
->level
== 10) {
5390 map
->raid_level
= 1;
5391 map
->num_domains
= info
->raid_disks
/ 2;
5392 } else if (info
->level
== 1)
5393 map
->num_domains
= info
->raid_disks
;
5395 map
->num_domains
= 1;
5397 /* info->size is only int so use the 'size' parameter instead */
5398 num_data_stripes
= size_per_member
/ info_to_blocks_per_strip(info
);
5399 num_data_stripes
/= map
->num_domains
;
5400 set_num_data_stripes(map
, num_data_stripes
);
5402 map
->num_members
= info
->raid_disks
;
5403 for (i
= 0; i
< map
->num_members
; i
++) {
5404 /* initialized in add_to_super */
5405 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
5407 mpb
->num_raid_devs
++;
5408 mpb
->num_raid_devs_created
++;
5409 dev
->my_vol_raid_dev_num
= mpb
->num_raid_devs_created
;
5411 if (s
->consistency_policy
<= CONSISTENCY_POLICY_RESYNC
) {
5412 dev
->rwh_policy
= RWH_MULTIPLE_OFF
;
5413 } else if (s
->consistency_policy
== CONSISTENCY_POLICY_PPL
) {
5414 dev
->rwh_policy
= RWH_MULTIPLE_DISTRIBUTED
;
5418 pr_err("imsm does not support consistency policy %s\n",
5419 map_num(consistency_policies
, s
->consistency_policy
));
5424 dv
->index
= super
->current_vol
;
5425 dv
->next
= super
->devlist
;
5426 super
->devlist
= dv
;
5428 imsm_update_version_info(super
);
5433 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
5434 struct shape
*s
, char *name
,
5435 char *homehost
, int *uuid
,
5436 unsigned long long data_offset
)
5438 /* This is primarily called by Create when creating a new array.
5439 * We will then get add_to_super called for each component, and then
5440 * write_init_super called to write it out to each device.
5441 * For IMSM, Create can create on fresh devices or on a pre-existing
5443 * To create on a pre-existing array a different method will be called.
5444 * This one is just for fresh drives.
5446 struct intel_super
*super
;
5447 struct imsm_super
*mpb
;
5451 if (data_offset
!= INVALID_SECTORS
) {
5452 pr_err("data-offset not supported by imsm\n");
5457 return init_super_imsm_volume(st
, info
, s
, name
, homehost
, uuid
,
5461 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
5463 mpb_size
= MAX_SECTOR_SIZE
;
5465 super
= alloc_super();
5467 posix_memalign(&super
->buf
, MAX_SECTOR_SIZE
, mpb_size
) != 0) {
5472 pr_err("could not allocate superblock\n");
5475 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
5476 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
) != 0) {
5477 pr_err("could not allocate migr_rec buffer\n");
5482 memset(super
->buf
, 0, mpb_size
);
5484 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5488 /* zeroing superblock */
5492 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5494 version
= (char *) mpb
->sig
;
5495 strcpy(version
, MPB_SIGNATURE
);
5496 version
+= strlen(MPB_SIGNATURE
);
5497 strcpy(version
, MPB_VERSION_RAID0
);
5502 static int drive_validate_sector_size(struct intel_super
*super
, struct dl
*dl
)
5504 unsigned int member_sector_size
;
5507 pr_err("Invalid file descriptor for %s\n", dl
->devname
);
5511 if (!get_dev_sector_size(dl
->fd
, dl
->devname
, &member_sector_size
))
5513 if (member_sector_size
!= super
->sector_size
)
5518 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
5519 int fd
, char *devname
)
5521 struct intel_super
*super
= st
->sb
;
5522 struct imsm_super
*mpb
= super
->anchor
;
5523 struct imsm_disk
*_disk
;
5524 struct imsm_dev
*dev
;
5525 struct imsm_map
*map
;
5529 dev
= get_imsm_dev(super
, super
->current_vol
);
5530 map
= get_imsm_map(dev
, MAP_0
);
5532 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
5533 pr_err("%s: Cannot add spare devices to IMSM volume\n",
5539 /* we're doing autolayout so grab the pre-marked (in
5540 * validate_geometry) raid_disk
5542 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5543 if (dl
->raiddisk
== dk
->raid_disk
)
5546 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5547 if (dl
->major
== dk
->major
&&
5548 dl
->minor
== dk
->minor
)
5553 pr_err("%s is not a member of the same container\n", devname
);
5557 if (!drive_validate_sector_size(super
, dl
)) {
5558 pr_err("Combining drives of different sector size in one volume is not allowed\n");
5562 /* add a pristine spare to the metadata */
5563 if (dl
->index
< 0) {
5564 dl
->index
= super
->anchor
->num_disks
;
5565 super
->anchor
->num_disks
++;
5567 /* Check the device has not already been added */
5568 slot
= get_imsm_disk_slot(map
, dl
->index
);
5570 (get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
) & IMSM_ORD_REBUILD
) == 0) {
5571 pr_err("%s has been included in this array twice\n",
5575 set_imsm_ord_tbl_ent(map
, dk
->raid_disk
, dl
->index
);
5576 dl
->disk
.status
= CONFIGURED_DISK
;
5578 /* update size of 'missing' disks to be at least as large as the
5579 * largest acitve member (we only have dummy missing disks when
5580 * creating the first volume)
5582 if (super
->current_vol
== 0) {
5583 for (df
= super
->missing
; df
; df
= df
->next
) {
5584 if (total_blocks(&dl
->disk
) > total_blocks(&df
->disk
))
5585 set_total_blocks(&df
->disk
, total_blocks(&dl
->disk
));
5586 _disk
= __get_imsm_disk(mpb
, df
->index
);
5591 /* refresh unset/failed slots to point to valid 'missing' entries */
5592 for (df
= super
->missing
; df
; df
= df
->next
)
5593 for (slot
= 0; slot
< mpb
->num_disks
; slot
++) {
5594 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
5596 if ((ord
& IMSM_ORD_REBUILD
) == 0)
5598 set_imsm_ord_tbl_ent(map
, slot
, df
->index
| IMSM_ORD_REBUILD
);
5599 if (is_gen_migration(dev
)) {
5600 struct imsm_map
*map2
= get_imsm_map(dev
,
5602 int slot2
= get_imsm_disk_slot(map2
, df
->index
);
5603 if (slot2
< map2
->num_members
&& slot2
>= 0) {
5604 __u32 ord2
= get_imsm_ord_tbl_ent(dev
,
5607 if ((unsigned)df
->index
==
5609 set_imsm_ord_tbl_ent(map2
,
5615 dprintf("set slot:%d to missing disk:%d\n", slot
, df
->index
);
5619 /* if we are creating the first raid device update the family number */
5620 if (super
->current_vol
== 0) {
5622 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
5624 _disk
= __get_imsm_disk(mpb
, dl
->index
);
5625 if (!_dev
|| !_disk
) {
5626 pr_err("BUG mpb setup error\n");
5632 sum
+= __gen_imsm_checksum(mpb
);
5633 mpb
->family_num
= __cpu_to_le32(sum
);
5634 mpb
->orig_family_num
= mpb
->family_num
;
5636 super
->current_disk
= dl
;
5641 * Function marks disk as spare and restores disk serial
5642 * in case it was previously marked as failed by takeover operation
5644 * -1 : critical error
5645 * 0 : disk is marked as spare but serial is not set
5648 int mark_spare(struct dl
*disk
)
5650 __u8 serial
[MAX_RAID_SERIAL_LEN
];
5657 if (!imsm_read_serial(disk
->fd
, NULL
, serial
)) {
5658 /* Restore disk serial number, because takeover marks disk
5659 * as failed and adds to serial ':0' before it becomes
5662 serialcpy(disk
->serial
, serial
);
5663 serialcpy(disk
->disk
.serial
, serial
);
5666 disk
->disk
.status
= SPARE_DISK
;
5672 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
5673 int fd
, char *devname
,
5674 unsigned long long data_offset
)
5676 struct intel_super
*super
= st
->sb
;
5678 unsigned long long size
;
5679 unsigned int member_sector_size
;
5684 /* If we are on an RAID enabled platform check that the disk is
5685 * attached to the raid controller.
5686 * We do not need to test disks attachment for container based additions,
5687 * they shall be already tested when container was created/assembled.
5689 rv
= find_intel_hba_capability(fd
, super
, devname
);
5690 /* no orom/efi or non-intel hba of the disk */
5692 dprintf("capability: %p fd: %d ret: %d\n",
5693 super
->orom
, fd
, rv
);
5697 if (super
->current_vol
>= 0)
5698 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
5701 dd
= xcalloc(sizeof(*dd
), 1);
5702 dd
->major
= major(stb
.st_rdev
);
5703 dd
->minor
= minor(stb
.st_rdev
);
5704 dd
->devname
= devname
? xstrdup(devname
) : NULL
;
5707 dd
->action
= DISK_ADD
;
5708 rv
= imsm_read_serial(fd
, devname
, dd
->serial
);
5710 pr_err("failed to retrieve scsi serial, aborting\n");
5716 if (super
->hba
&& ((super
->hba
->type
== SYS_DEV_NVME
) ||
5717 (super
->hba
->type
== SYS_DEV_VMD
))) {
5719 char *devpath
= diskfd_to_devpath(fd
);
5720 char controller_path
[PATH_MAX
];
5723 pr_err("failed to get devpath, aborting\n");
5730 snprintf(controller_path
, PATH_MAX
-1, "%s/device", devpath
);
5733 if (devpath_to_vendor(controller_path
) == 0x8086) {
5735 * If Intel's NVMe drive has serial ended with
5736 * "-A","-B","-1" or "-2" it means that this is "x8"
5737 * device (double drive on single PCIe card).
5738 * User should be warned about potential data loss.
5740 for (i
= MAX_RAID_SERIAL_LEN
-1; i
> 0; i
--) {
5741 /* Skip empty character at the end */
5742 if (dd
->serial
[i
] == 0)
5745 if (((dd
->serial
[i
] == 'A') ||
5746 (dd
->serial
[i
] == 'B') ||
5747 (dd
->serial
[i
] == '1') ||
5748 (dd
->serial
[i
] == '2')) &&
5749 (dd
->serial
[i
-1] == '-'))
5750 pr_err("\tThe action you are about to take may put your data at risk.\n"
5751 "\tPlease note that x8 devices may consist of two separate x4 devices "
5752 "located on a single PCIe port.\n"
5753 "\tRAID 0 is the only supported configuration for this type of x8 device.\n");
5756 } else if (super
->hba
->type
== SYS_DEV_VMD
&& super
->orom
&&
5757 !imsm_orom_has_tpv_support(super
->orom
)) {
5758 pr_err("\tPlatform configuration does not support non-Intel NVMe drives.\n"
5759 "\tPlease refer to Intel(R) RSTe user guide.\n");
5766 get_dev_size(fd
, NULL
, &size
);
5767 get_dev_sector_size(fd
, NULL
, &member_sector_size
);
5769 if (super
->sector_size
== 0) {
5770 /* this a first device, so sector_size is not set yet */
5771 super
->sector_size
= member_sector_size
;
5774 /* clear migr_rec when adding disk to container */
5775 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
);
5776 if (lseek64(fd
, size
- MIGR_REC_SECTOR_POSITION
*member_sector_size
,
5778 if ((unsigned int)write(fd
, super
->migr_rec_buf
,
5779 MIGR_REC_BUF_SECTORS
*member_sector_size
) !=
5780 MIGR_REC_BUF_SECTORS
*member_sector_size
)
5781 perror("Write migr_rec failed");
5785 serialcpy(dd
->disk
.serial
, dd
->serial
);
5786 set_total_blocks(&dd
->disk
, size
);
5787 if (__le32_to_cpu(dd
->disk
.total_blocks_hi
) > 0) {
5788 struct imsm_super
*mpb
= super
->anchor
;
5789 mpb
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5792 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
5793 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
5795 dd
->disk
.scsi_id
= __cpu_to_le32(0);
5797 if (st
->update_tail
) {
5798 dd
->next
= super
->disk_mgmt_list
;
5799 super
->disk_mgmt_list
= dd
;
5801 dd
->next
= super
->disks
;
5803 super
->updates_pending
++;
5809 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
5811 struct intel_super
*super
= st
->sb
;
5814 /* remove from super works only in mdmon - for communication
5815 * manager - monitor. Check if communication memory buffer
5818 if (!st
->update_tail
) {
5819 pr_err("shall be used in mdmon context only\n");
5822 dd
= xcalloc(1, sizeof(*dd
));
5823 dd
->major
= dk
->major
;
5824 dd
->minor
= dk
->minor
;
5827 dd
->action
= DISK_REMOVE
;
5829 dd
->next
= super
->disk_mgmt_list
;
5830 super
->disk_mgmt_list
= dd
;
5835 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
5838 char buf
[MAX_SECTOR_SIZE
];
5839 struct imsm_super anchor
;
5840 } spare_record
__attribute__ ((aligned(MAX_SECTOR_SIZE
)));
5842 /* spare records have their own family number and do not have any defined raid
5845 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
5847 struct imsm_super
*mpb
= super
->anchor
;
5848 struct imsm_super
*spare
= &spare_record
.anchor
;
5852 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
));
5853 spare
->generation_num
= __cpu_to_le32(1UL);
5854 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5855 spare
->num_disks
= 1;
5856 spare
->num_raid_devs
= 0;
5857 spare
->cache_size
= mpb
->cache_size
;
5858 spare
->pwr_cycle_count
= __cpu_to_le32(1);
5860 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
5861 MPB_SIGNATURE MPB_VERSION_RAID0
);
5863 for (d
= super
->disks
; d
; d
= d
->next
) {
5867 spare
->disk
[0] = d
->disk
;
5868 if (__le32_to_cpu(d
->disk
.total_blocks_hi
) > 0)
5869 spare
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5871 if (super
->sector_size
== 4096)
5872 convert_to_4k_imsm_disk(&spare
->disk
[0]);
5874 sum
= __gen_imsm_checksum(spare
);
5875 spare
->family_num
= __cpu_to_le32(sum
);
5876 spare
->orig_family_num
= 0;
5877 sum
= __gen_imsm_checksum(spare
);
5878 spare
->check_sum
= __cpu_to_le32(sum
);
5880 if (store_imsm_mpb(d
->fd
, spare
)) {
5881 pr_err("failed for device %d:%d %s\n",
5882 d
->major
, d
->minor
, strerror(errno
));
5894 static int write_super_imsm(struct supertype
*st
, int doclose
)
5896 struct intel_super
*super
= st
->sb
;
5897 unsigned int sector_size
= super
->sector_size
;
5898 struct imsm_super
*mpb
= super
->anchor
;
5904 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
5906 int clear_migration_record
= 1;
5909 /* 'generation' is incremented everytime the metadata is written */
5910 generation
= __le32_to_cpu(mpb
->generation_num
);
5912 mpb
->generation_num
= __cpu_to_le32(generation
);
5914 /* fix up cases where previous mdadm releases failed to set
5917 if (mpb
->orig_family_num
== 0)
5918 mpb
->orig_family_num
= mpb
->family_num
;
5920 for (d
= super
->disks
; d
; d
= d
->next
) {
5924 mpb
->disk
[d
->index
] = d
->disk
;
5928 for (d
= super
->missing
; d
; d
= d
->next
) {
5929 mpb
->disk
[d
->index
] = d
->disk
;
5932 mpb
->num_disks
= num_disks
;
5933 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
5935 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5936 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
5937 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
5939 imsm_copy_dev(dev
, dev2
);
5940 mpb_size
+= sizeof_imsm_dev(dev
, 0);
5942 if (is_gen_migration(dev2
))
5943 clear_migration_record
= 0;
5946 bbm_log_size
= get_imsm_bbm_log_size(super
->bbm_log
);
5949 memcpy((void *)mpb
+ mpb_size
, super
->bbm_log
, bbm_log_size
);
5950 mpb
->attributes
|= MPB_ATTRIB_BBM
;
5952 mpb
->attributes
&= ~MPB_ATTRIB_BBM
;
5954 super
->anchor
->bbm_log_size
= __cpu_to_le32(bbm_log_size
);
5955 mpb_size
+= bbm_log_size
;
5956 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5959 assert(super
->len
== 0 || mpb_size
<= super
->len
);
5962 /* recalculate checksum */
5963 sum
= __gen_imsm_checksum(mpb
);
5964 mpb
->check_sum
= __cpu_to_le32(sum
);
5966 if (super
->clean_migration_record_by_mdmon
) {
5967 clear_migration_record
= 1;
5968 super
->clean_migration_record_by_mdmon
= 0;
5970 if (clear_migration_record
)
5971 memset(super
->migr_rec_buf
, 0,
5972 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
);
5974 if (sector_size
== 4096)
5975 convert_to_4k(super
);
5977 /* write the mpb for disks that compose raid devices */
5978 for (d
= super
->disks
; d
; d
= d
->next
) {
5979 if (d
->index
< 0 || is_failed(&d
->disk
))
5982 if (clear_migration_record
) {
5983 unsigned long long dsize
;
5985 get_dev_size(d
->fd
, NULL
, &dsize
);
5986 if (lseek64(d
->fd
, dsize
- sector_size
,
5988 if ((unsigned int)write(d
->fd
,
5989 super
->migr_rec_buf
,
5990 MIGR_REC_BUF_SECTORS
*sector_size
) !=
5991 MIGR_REC_BUF_SECTORS
*sector_size
)
5992 perror("Write migr_rec failed");
5996 if (store_imsm_mpb(d
->fd
, mpb
))
5998 "failed for device %d:%d (fd: %d)%s\n",
6000 d
->fd
, strerror(errno
));
6009 return write_super_imsm_spares(super
, doclose
);
6014 static int create_array(struct supertype
*st
, int dev_idx
)
6017 struct imsm_update_create_array
*u
;
6018 struct intel_super
*super
= st
->sb
;
6019 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
6020 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
6021 struct disk_info
*inf
;
6022 struct imsm_disk
*disk
;
6025 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
6026 sizeof(*inf
) * map
->num_members
;
6028 u
->type
= update_create_array
;
6029 u
->dev_idx
= dev_idx
;
6030 imsm_copy_dev(&u
->dev
, dev
);
6031 inf
= get_disk_info(u
);
6032 for (i
= 0; i
< map
->num_members
; i
++) {
6033 int idx
= get_imsm_disk_idx(dev
, i
, MAP_X
);
6035 disk
= get_imsm_disk(super
, idx
);
6037 disk
= get_imsm_missing(super
, idx
);
6038 serialcpy(inf
[i
].serial
, disk
->serial
);
6040 append_metadata_update(st
, u
, len
);
6045 static int mgmt_disk(struct supertype
*st
)
6047 struct intel_super
*super
= st
->sb
;
6049 struct imsm_update_add_remove_disk
*u
;
6051 if (!super
->disk_mgmt_list
)
6056 u
->type
= update_add_remove_disk
;
6057 append_metadata_update(st
, u
, len
);
6062 __u32
crc32c_le(__u32 crc
, unsigned char const *p
, size_t len
);
6064 static int write_init_ppl_imsm(struct supertype
*st
, struct mdinfo
*info
, int fd
)
6066 struct intel_super
*super
= st
->sb
;
6068 struct ppl_header
*ppl_hdr
;
6071 /* first clear entire ppl space */
6072 ret
= zero_disk_range(fd
, info
->ppl_sector
, info
->ppl_size
);
6076 ret
= posix_memalign(&buf
, MAX_SECTOR_SIZE
, PPL_HEADER_SIZE
);
6078 pr_err("Failed to allocate PPL header buffer\n");
6082 memset(buf
, 0, PPL_HEADER_SIZE
);
6084 memset(ppl_hdr
->reserved
, 0xff, PPL_HDR_RESERVED
);
6085 ppl_hdr
->signature
= __cpu_to_le32(super
->anchor
->orig_family_num
);
6087 if (info
->mismatch_cnt
) {
6089 * We are overwriting an invalid ppl. Make one entry with wrong
6090 * checksum to prevent the kernel from skipping resync.
6092 ppl_hdr
->entries_count
= __cpu_to_le32(1);
6093 ppl_hdr
->entries
[0].checksum
= ~0;
6096 ppl_hdr
->checksum
= __cpu_to_le32(~crc32c_le(~0, buf
, PPL_HEADER_SIZE
));
6098 if (lseek64(fd
, info
->ppl_sector
* 512, SEEK_SET
) < 0) {
6100 perror("Failed to seek to PPL header location");
6103 if (!ret
&& write(fd
, buf
, PPL_HEADER_SIZE
) != PPL_HEADER_SIZE
) {
6105 perror("Write PPL header failed");
6115 static int validate_ppl_imsm(struct supertype
*st
, struct mdinfo
*info
,
6116 struct mdinfo
*disk
)
6118 struct intel_super
*super
= st
->sb
;
6122 struct ppl_header
*ppl_hdr
;
6124 struct imsm_dev
*dev
;
6127 unsigned long long ppl_offset
= 0;
6128 unsigned long long prev_gen_num
= 0;
6130 if (disk
->disk
.raid_disk
< 0)
6133 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, PPL_HEADER_SIZE
)) {
6134 pr_err("Failed to allocate PPL header buffer\n");
6138 dev
= get_imsm_dev(super
, info
->container_member
);
6139 idx
= get_imsm_disk_idx(dev
, disk
->disk
.raid_disk
, MAP_0
);
6140 d
= get_imsm_dl_disk(super
, idx
);
6142 if (!d
|| d
->index
< 0 || is_failed(&d
->disk
))
6146 while (ppl_offset
< MULTIPLE_PPL_AREA_SIZE_IMSM
) {
6147 dprintf("Checking potential PPL at offset: %llu\n", ppl_offset
);
6149 if (lseek64(d
->fd
, info
->ppl_sector
* 512 + ppl_offset
,
6151 perror("Failed to seek to PPL header location");
6156 if (read(d
->fd
, buf
, PPL_HEADER_SIZE
) != PPL_HEADER_SIZE
) {
6157 perror("Read PPL header failed");
6164 crc
= __le32_to_cpu(ppl_hdr
->checksum
);
6165 ppl_hdr
->checksum
= 0;
6167 if (crc
!= ~crc32c_le(~0, buf
, PPL_HEADER_SIZE
)) {
6168 dprintf("Wrong PPL header checksum on %s\n",
6173 if (prev_gen_num
> __le64_to_cpu(ppl_hdr
->generation
)) {
6174 /* previous was newest, it was already checked */
6178 if ((__le32_to_cpu(ppl_hdr
->signature
) !=
6179 super
->anchor
->orig_family_num
)) {
6180 dprintf("Wrong PPL header signature on %s\n",
6187 prev_gen_num
= __le64_to_cpu(ppl_hdr
->generation
);
6189 ppl_offset
+= PPL_HEADER_SIZE
;
6190 for (i
= 0; i
< __le32_to_cpu(ppl_hdr
->entries_count
); i
++)
6192 __le32_to_cpu(ppl_hdr
->entries
[i
].pp_size
);
6199 * Update metadata to use mutliple PPLs area (1MB).
6200 * This is done once for all RAID members
6202 if (info
->consistency_policy
== CONSISTENCY_POLICY_PPL
&&
6203 info
->ppl_size
!= (MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9)) {
6205 struct mdinfo
*member_dev
;
6207 sprintf(subarray
, "%d", info
->container_member
);
6209 if (mdmon_running(st
->container_devnm
))
6210 st
->update_tail
= &st
->updates
;
6212 if (st
->ss
->update_subarray(st
, subarray
, "ppl", NULL
)) {
6213 pr_err("Failed to update subarray %s\n",
6216 if (st
->update_tail
)
6217 flush_metadata_updates(st
);
6219 st
->ss
->sync_metadata(st
);
6220 info
->ppl_size
= (MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9);
6221 for (member_dev
= info
->devs
; member_dev
;
6222 member_dev
= member_dev
->next
)
6223 member_dev
->ppl_size
=
6224 (MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9);
6229 struct imsm_map
*map
= get_imsm_map(dev
, MAP_X
);
6231 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
6232 (map
->map_state
== IMSM_T_STATE_NORMAL
&&
6233 !(dev
->vol
.dirty
& RAIDVOL_DIRTY
)) ||
6234 (dev
->vol
.migr_state
== MIGR_REBUILD
&&
6235 dev
->vol
.curr_migr_unit
== 0 &&
6236 get_imsm_disk_idx(dev
, disk
->disk
.raid_disk
, MAP_1
) != idx
))
6237 ret
= st
->ss
->write_init_ppl(st
, info
, d
->fd
);
6239 info
->mismatch_cnt
++;
6245 static int write_init_ppl_imsm_all(struct supertype
*st
, struct mdinfo
*info
)
6247 struct intel_super
*super
= st
->sb
;
6251 if (info
->consistency_policy
!= CONSISTENCY_POLICY_PPL
||
6252 info
->array
.level
!= 5)
6255 for (d
= super
->disks
; d
; d
= d
->next
) {
6256 if (d
->index
< 0 || is_failed(&d
->disk
))
6259 ret
= st
->ss
->write_init_ppl(st
, info
, d
->fd
);
6267 static int write_init_super_imsm(struct supertype
*st
)
6269 struct intel_super
*super
= st
->sb
;
6270 int current_vol
= super
->current_vol
;
6274 getinfo_super_imsm(st
, &info
, NULL
);
6276 /* we are done with current_vol reset it to point st at the container */
6277 super
->current_vol
= -1;
6279 if (st
->update_tail
) {
6280 /* queue the recently created array / added disk
6281 * as a metadata update */
6283 /* determine if we are creating a volume or adding a disk */
6284 if (current_vol
< 0) {
6285 /* in the mgmt (add/remove) disk case we are running
6286 * in mdmon context, so don't close fd's
6290 rv
= write_init_ppl_imsm_all(st
, &info
);
6292 rv
= create_array(st
, current_vol
);
6296 for (d
= super
->disks
; d
; d
= d
->next
)
6297 Kill(d
->devname
, NULL
, 0, -1, 1);
6298 if (current_vol
>= 0)
6299 rv
= write_init_ppl_imsm_all(st
, &info
);
6301 rv
= write_super_imsm(st
, 1);
6307 static int store_super_imsm(struct supertype
*st
, int fd
)
6309 struct intel_super
*super
= st
->sb
;
6310 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
6315 if (super
->sector_size
== 4096)
6316 convert_to_4k(super
);
6317 return store_imsm_mpb(fd
, mpb
);
6320 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
6321 int layout
, int raiddisks
, int chunk
,
6322 unsigned long long size
,
6323 unsigned long long data_offset
,
6325 unsigned long long *freesize
,
6329 unsigned long long ldsize
;
6330 struct intel_super
*super
;
6333 if (level
!= LEVEL_CONTAINER
)
6338 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
6341 pr_err("imsm: Cannot open %s: %s\n",
6342 dev
, strerror(errno
));
6345 if (!get_dev_size(fd
, dev
, &ldsize
)) {
6350 /* capabilities retrieve could be possible
6351 * note that there is no fd for the disks in array.
6353 super
= alloc_super();
6358 if (!get_dev_sector_size(fd
, NULL
, &super
->sector_size
)) {
6364 rv
= find_intel_hba_capability(fd
, super
, verbose
> 0 ? dev
: NULL
);
6368 fd2devname(fd
, str
);
6369 dprintf("fd: %d %s orom: %p rv: %d raiddisk: %d\n",
6370 fd
, str
, super
->orom
, rv
, raiddisks
);
6372 /* no orom/efi or non-intel hba of the disk */
6379 if (raiddisks
> super
->orom
->tds
) {
6381 pr_err("%d exceeds maximum number of platform supported disks: %d\n",
6382 raiddisks
, super
->orom
->tds
);
6386 if ((super
->orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) == 0 &&
6387 (ldsize
>> 9) >> 32 > 0) {
6389 pr_err("%s exceeds maximum platform supported size\n", dev
);
6395 *freesize
= avail_size_imsm(st
, ldsize
>> 9, data_offset
);
6401 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
6403 const unsigned long long base_start
= e
[*idx
].start
;
6404 unsigned long long end
= base_start
+ e
[*idx
].size
;
6407 if (base_start
== end
)
6411 for (i
= *idx
; i
< num_extents
; i
++) {
6412 /* extend overlapping extents */
6413 if (e
[i
].start
>= base_start
&&
6414 e
[i
].start
<= end
) {
6417 if (e
[i
].start
+ e
[i
].size
> end
)
6418 end
= e
[i
].start
+ e
[i
].size
;
6419 } else if (e
[i
].start
> end
) {
6425 return end
- base_start
;
6428 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
6430 /* build a composite disk with all known extents and generate a new
6431 * 'maxsize' given the "all disks in an array must share a common start
6432 * offset" constraint
6434 struct extent
*e
= xcalloc(sum_extents
, sizeof(*e
));
6438 unsigned long long pos
;
6439 unsigned long long start
= 0;
6440 unsigned long long maxsize
;
6441 unsigned long reserve
;
6443 /* coalesce and sort all extents. also, check to see if we need to
6444 * reserve space between member arrays
6447 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6450 for (i
= 0; i
< dl
->extent_cnt
; i
++)
6453 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
6458 while (i
< sum_extents
) {
6459 e
[j
].start
= e
[i
].start
;
6460 e
[j
].size
= find_size(e
, &i
, sum_extents
);
6462 if (e
[j
-1].size
== 0)
6471 unsigned long long esize
;
6473 esize
= e
[i
].start
- pos
;
6474 if (esize
>= maxsize
) {
6479 pos
= e
[i
].start
+ e
[i
].size
;
6481 } while (e
[i
-1].size
);
6487 /* FIXME assumes volume at offset 0 is the first volume in a
6490 if (start_extent
> 0)
6491 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
6495 if (maxsize
< reserve
)
6498 super
->create_offset
= ~((unsigned long long) 0);
6499 if (start
+ reserve
> super
->create_offset
)
6500 return 0; /* start overflows create_offset */
6501 super
->create_offset
= start
+ reserve
;
6503 return maxsize
- reserve
;
6506 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
6508 if (level
< 0 || level
== 6 || level
== 4)
6511 /* if we have an orom prevent invalid raid levels */
6514 case 0: return imsm_orom_has_raid0(orom
);
6517 return imsm_orom_has_raid1e(orom
);
6518 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
6519 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
6520 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
6523 return 1; /* not on an Intel RAID platform so anything goes */
6529 active_arrays_by_format(char *name
, char* hba
, struct md_list
**devlist
,
6530 int dpa
, int verbose
)
6532 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
6533 struct mdstat_ent
*memb
;
6539 for (memb
= mdstat
; memb
; memb
= memb
->next
) {
6540 if (memb
->metadata_version
&&
6541 (strncmp(memb
->metadata_version
, "external:", 9) == 0) &&
6542 (strcmp(&memb
->metadata_version
[9], name
) == 0) &&
6543 !is_subarray(memb
->metadata_version
+9) &&
6545 struct dev_member
*dev
= memb
->members
;
6547 while(dev
&& (fd
< 0)) {
6548 char *path
= xmalloc(strlen(dev
->name
) + strlen("/dev/") + 1);
6549 num
= sprintf(path
, "%s%s", "/dev/", dev
->name
);
6551 fd
= open(path
, O_RDONLY
, 0);
6552 if (num
<= 0 || fd
< 0) {
6553 pr_vrb("Cannot open %s: %s\n",
6554 dev
->name
, strerror(errno
));
6560 if (fd
>= 0 && disk_attached_to_hba(fd
, hba
)) {
6561 struct mdstat_ent
*vol
;
6562 for (vol
= mdstat
; vol
; vol
= vol
->next
) {
6563 if (vol
->active
> 0 &&
6564 vol
->metadata_version
&&
6565 is_container_member(vol
, memb
->devnm
)) {
6570 if (*devlist
&& (found
< dpa
)) {
6571 dv
= xcalloc(1, sizeof(*dv
));
6572 dv
->devname
= xmalloc(strlen(memb
->devnm
) + strlen("/dev/") + 1);
6573 sprintf(dv
->devname
, "%s%s", "/dev/", memb
->devnm
);
6576 dv
->next
= *devlist
;
6584 free_mdstat(mdstat
);
6589 static struct md_list
*
6590 get_loop_devices(void)
6593 struct md_list
*devlist
= NULL
;
6596 for(i
= 0; i
< 12; i
++) {
6597 dv
= xcalloc(1, sizeof(*dv
));
6598 dv
->devname
= xmalloc(40);
6599 sprintf(dv
->devname
, "/dev/loop%d", i
);
6607 static struct md_list
*
6608 get_devices(const char *hba_path
)
6610 struct md_list
*devlist
= NULL
;
6617 devlist
= get_loop_devices();
6620 /* scroll through /sys/dev/block looking for devices attached to
6623 dir
= opendir("/sys/dev/block");
6624 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
6629 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
6631 path
= devt_to_devpath(makedev(major
, minor
));
6634 if (!path_attached_to_hba(path
, hba_path
)) {
6641 fd
= dev_open(ent
->d_name
, O_RDONLY
);
6643 fd2devname(fd
, buf
);
6646 pr_err("cannot open device: %s\n",
6651 dv
= xcalloc(1, sizeof(*dv
));
6652 dv
->devname
= xstrdup(buf
);
6659 devlist
= devlist
->next
;
6669 count_volumes_list(struct md_list
*devlist
, char *homehost
,
6670 int verbose
, int *found
)
6672 struct md_list
*tmpdev
;
6674 struct supertype
*st
;
6676 /* first walk the list of devices to find a consistent set
6677 * that match the criterea, if that is possible.
6678 * We flag the ones we like with 'used'.
6681 st
= match_metadata_desc_imsm("imsm");
6683 pr_vrb("cannot allocate memory for imsm supertype\n");
6687 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
6688 char *devname
= tmpdev
->devname
;
6690 struct supertype
*tst
;
6692 if (tmpdev
->used
> 1)
6694 tst
= dup_super(st
);
6696 pr_vrb("cannot allocate memory for imsm supertype\n");
6699 tmpdev
->container
= 0;
6700 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
6702 dprintf("cannot open device %s: %s\n",
6703 devname
, strerror(errno
));
6705 } else if (!fstat_is_blkdev(dfd
, devname
, &rdev
)) {
6707 } else if (must_be_container(dfd
)) {
6708 struct supertype
*cst
;
6709 cst
= super_by_fd(dfd
, NULL
);
6711 dprintf("cannot recognize container type %s\n",
6714 } else if (tst
->ss
!= st
->ss
) {
6715 dprintf("non-imsm container - ignore it: %s\n",
6718 } else if (!tst
->ss
->load_container
||
6719 tst
->ss
->load_container(tst
, dfd
, NULL
))
6722 tmpdev
->container
= 1;
6725 cst
->ss
->free_super(cst
);
6727 tmpdev
->st_rdev
= rdev
;
6728 if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
6729 dprintf("no RAID superblock on %s\n",
6732 } else if (tst
->ss
->compare_super
== NULL
) {
6733 dprintf("Cannot assemble %s metadata on %s\n",
6734 tst
->ss
->name
, devname
);
6740 if (tmpdev
->used
== 2 || tmpdev
->used
== 4) {
6741 /* Ignore unrecognised devices during auto-assembly */
6746 tst
->ss
->getinfo_super(tst
, &info
, NULL
);
6748 if (st
->minor_version
== -1)
6749 st
->minor_version
= tst
->minor_version
;
6751 if (memcmp(info
.uuid
, uuid_zero
,
6752 sizeof(int[4])) == 0) {
6753 /* this is a floating spare. It cannot define
6754 * an array unless there are no more arrays of
6755 * this type to be found. It can be included
6756 * in an array of this type though.
6762 if (st
->ss
!= tst
->ss
||
6763 st
->minor_version
!= tst
->minor_version
||
6764 st
->ss
->compare_super(st
, tst
) != 0) {
6765 /* Some mismatch. If exactly one array matches this host,
6766 * we can resolve on that one.
6767 * Or, if we are auto assembling, we just ignore the second
6770 dprintf("superblock on %s doesn't match others - assembly aborted\n",
6776 dprintf("found: devname: %s\n", devname
);
6780 tst
->ss
->free_super(tst
);
6784 if ((err
= load_super_imsm_all(st
, -1, &st
->sb
, NULL
, devlist
, 0)) == 0) {
6785 struct mdinfo
*iter
, *head
= st
->ss
->container_content(st
, NULL
);
6786 for (iter
= head
; iter
; iter
= iter
->next
) {
6787 dprintf("content->text_version: %s vol\n",
6788 iter
->text_version
);
6789 if (iter
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
)) {
6790 /* do not assemble arrays with unsupported
6792 dprintf("Cannot activate member %s.\n",
6793 iter
->text_version
);
6800 dprintf("No valid super block on device list: err: %d %p\n",
6804 dprintf("no more devices to examine\n");
6807 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
6808 if (tmpdev
->used
== 1 && tmpdev
->found
) {
6810 if (count
< tmpdev
->found
)
6813 count
-= tmpdev
->found
;
6816 if (tmpdev
->used
== 1)
6821 st
->ss
->free_super(st
);
6825 static int __count_volumes(char *hba_path
, int dpa
, int verbose
,
6828 struct sys_dev
*idev
, *intel_devices
= find_intel_devices();
6830 const struct orom_entry
*entry
;
6831 struct devid_list
*dv
, *devid_list
;
6836 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
6837 if (strstr(idev
->path
, hba_path
))
6841 if (!idev
|| !idev
->dev_id
)
6844 entry
= get_orom_entry_by_device_id(idev
->dev_id
);
6846 if (!entry
|| !entry
->devid_list
)
6849 devid_list
= entry
->devid_list
;
6850 for (dv
= devid_list
; dv
; dv
= dv
->next
) {
6851 struct md_list
*devlist
;
6852 struct sys_dev
*device
= NULL
;
6857 device
= device_by_id_and_path(dv
->devid
, hba_path
);
6859 device
= device_by_id(dv
->devid
);
6862 hpath
= device
->path
;
6866 devlist
= get_devices(hpath
);
6867 /* if no intel devices return zero volumes */
6868 if (devlist
== NULL
)
6871 count
+= active_arrays_by_format("imsm", hpath
, &devlist
, dpa
,
6873 dprintf("path: %s active arrays: %d\n", hpath
, count
);
6874 if (devlist
== NULL
)
6878 count
+= count_volumes_list(devlist
,
6882 dprintf("found %d count: %d\n", found
, count
);
6885 dprintf("path: %s total number of volumes: %d\n", hpath
, count
);
6888 struct md_list
*dv
= devlist
;
6889 devlist
= devlist
->next
;
6897 static int count_volumes(struct intel_hba
*hba
, int dpa
, int verbose
)
6901 if (hba
->type
== SYS_DEV_VMD
) {
6902 struct sys_dev
*dev
;
6905 for (dev
= find_intel_devices(); dev
; dev
= dev
->next
) {
6906 if (dev
->type
== SYS_DEV_VMD
)
6907 count
+= __count_volumes(dev
->path
, dpa
,
6912 return __count_volumes(hba
->path
, dpa
, verbose
, 0);
6915 static int imsm_default_chunk(const struct imsm_orom
*orom
)
6917 /* up to 512 if the plaform supports it, otherwise the platform max.
6918 * 128 if no platform detected
6920 int fs
= max(7, orom
? fls(orom
->sss
) : 0);
6922 return min(512, (1 << fs
));
6926 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
6927 int raiddisks
, int *chunk
, unsigned long long size
, int verbose
)
6929 /* check/set platform and metadata limits/defaults */
6930 if (super
->orom
&& raiddisks
> super
->orom
->dpa
) {
6931 pr_vrb("platform supports a maximum of %d disks per array\n",
6936 /* capabilities of OROM tested - copied from validate_geometry_imsm_volume */
6937 if (!is_raid_level_supported(super
->orom
, level
, raiddisks
)) {
6938 pr_vrb("platform does not support raid%d with %d disk%s\n",
6939 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
6943 if (*chunk
== 0 || *chunk
== UnSet
)
6944 *chunk
= imsm_default_chunk(super
->orom
);
6946 if (super
->orom
&& !imsm_orom_has_chunk(super
->orom
, *chunk
)) {
6947 pr_vrb("platform does not support a chunk size of: %d\n", *chunk
);
6951 if (layout
!= imsm_level_to_layout(level
)) {
6953 pr_vrb("imsm raid 5 only supports the left-asymmetric layout\n");
6954 else if (level
== 10)
6955 pr_vrb("imsm raid 10 only supports the n2 layout\n");
6957 pr_vrb("imsm unknown layout %#x for this raid level %d\n",
6962 if (super
->orom
&& (super
->orom
->attr
& IMSM_OROM_ATTR_2TB
) == 0 &&
6963 (calc_array_size(level
, raiddisks
, layout
, *chunk
, size
) >> 32) > 0) {
6964 pr_vrb("platform does not support a volume size over 2TB\n");
6971 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
6972 * FIX ME add ahci details
6974 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
6975 int layout
, int raiddisks
, int *chunk
,
6976 unsigned long long size
,
6977 unsigned long long data_offset
,
6979 unsigned long long *freesize
,
6983 struct intel_super
*super
= st
->sb
;
6984 struct imsm_super
*mpb
;
6986 unsigned long long pos
= 0;
6987 unsigned long long maxsize
;
6991 /* We must have the container info already read in. */
6995 mpb
= super
->anchor
;
6997 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, size
, verbose
)) {
6998 pr_err("RAID gemetry validation failed. Cannot proceed with the action(s).\n");
7002 /* General test: make sure there is space for
7003 * 'raiddisks' device extents of size 'size' at a given
7006 unsigned long long minsize
= size
;
7007 unsigned long long start_offset
= MaxSector
;
7010 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
7011 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7016 e
= get_extents(super
, dl
);
7019 unsigned long long esize
;
7020 esize
= e
[i
].start
- pos
;
7021 if (esize
>= minsize
)
7023 if (found
&& start_offset
== MaxSector
) {
7026 } else if (found
&& pos
!= start_offset
) {
7030 pos
= e
[i
].start
+ e
[i
].size
;
7032 } while (e
[i
-1].size
);
7037 if (dcnt
< raiddisks
) {
7039 pr_err("imsm: Not enough devices with space for this array (%d < %d)\n",
7046 /* This device must be a member of the set */
7047 if (!stat_is_blkdev(dev
, &rdev
))
7049 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7050 if (dl
->major
== (int)major(rdev
) &&
7051 dl
->minor
== (int)minor(rdev
))
7056 pr_err("%s is not in the same imsm set\n", dev
);
7058 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
7059 /* If a volume is present then the current creation attempt
7060 * cannot incorporate new spares because the orom may not
7061 * understand this configuration (all member disks must be
7062 * members of each array in the container).
7064 pr_err("%s is a spare and a volume is already defined for this container\n", dev
);
7065 pr_err("The option-rom requires all member disks to be a member of all volumes\n");
7067 } else if (super
->orom
&& mpb
->num_raid_devs
> 0 &&
7068 mpb
->num_disks
!= raiddisks
) {
7069 pr_err("The option-rom requires all member disks to be a member of all volumes\n");
7073 /* retrieve the largest free space block */
7074 e
= get_extents(super
, dl
);
7079 unsigned long long esize
;
7081 esize
= e
[i
].start
- pos
;
7082 if (esize
>= maxsize
)
7084 pos
= e
[i
].start
+ e
[i
].size
;
7086 } while (e
[i
-1].size
);
7091 pr_err("unable to determine free space for: %s\n",
7095 if (maxsize
< size
) {
7097 pr_err("%s not enough space (%llu < %llu)\n",
7098 dev
, maxsize
, size
);
7102 /* count total number of extents for merge */
7104 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7106 i
+= dl
->extent_cnt
;
7108 maxsize
= merge_extents(super
, i
);
7110 if (!check_env("IMSM_NO_PLATFORM") &&
7111 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
7112 pr_err("attempting to create a second volume with size less then remaining space. Aborting...\n");
7116 if (maxsize
< size
|| maxsize
== 0) {
7119 pr_err("no free space left on device. Aborting...\n");
7121 pr_err("not enough space to create volume of given size (%llu < %llu). Aborting...\n",
7127 *freesize
= maxsize
;
7130 int count
= count_volumes(super
->hba
,
7131 super
->orom
->dpa
, verbose
);
7132 if (super
->orom
->vphba
<= count
) {
7133 pr_vrb("platform does not support more than %d raid volumes.\n",
7134 super
->orom
->vphba
);
7141 static int imsm_get_free_size(struct supertype
*st
, int raiddisks
,
7142 unsigned long long size
, int chunk
,
7143 unsigned long long *freesize
)
7145 struct intel_super
*super
= st
->sb
;
7146 struct imsm_super
*mpb
= super
->anchor
;
7151 unsigned long long maxsize
;
7152 unsigned long long minsize
;
7156 /* find the largest common start free region of the possible disks */
7160 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7166 /* don't activate new spares if we are orom constrained
7167 * and there is already a volume active in the container
7169 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
7172 e
= get_extents(super
, dl
);
7175 for (i
= 1; e
[i
-1].size
; i
++)
7183 maxsize
= merge_extents(super
, extent_cnt
);
7187 minsize
= chunk
* 2;
7189 if (cnt
< raiddisks
||
7190 (super
->orom
&& used
&& used
!= raiddisks
) ||
7191 maxsize
< minsize
||
7193 pr_err("not enough devices with space to create array.\n");
7194 return 0; /* No enough free spaces large enough */
7205 if (!check_env("IMSM_NO_PLATFORM") &&
7206 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
7207 pr_err("attempting to create a second volume with size less then remaining space. Aborting...\n");
7211 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7213 dl
->raiddisk
= cnt
++;
7217 dprintf("imsm: imsm_get_free_size() returns : %llu\n", size
);
7222 static int reserve_space(struct supertype
*st
, int raiddisks
,
7223 unsigned long long size
, int chunk
,
7224 unsigned long long *freesize
)
7226 struct intel_super
*super
= st
->sb
;
7231 rv
= imsm_get_free_size(st
, raiddisks
, size
, chunk
, freesize
);
7234 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7236 dl
->raiddisk
= cnt
++;
7243 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
7244 int raiddisks
, int *chunk
, unsigned long long size
,
7245 unsigned long long data_offset
,
7246 char *dev
, unsigned long long *freesize
,
7247 int consistency_policy
, int verbose
)
7254 * if given unused devices create a container
7255 * if given given devices in a container create a member volume
7257 if (level
== LEVEL_CONTAINER
) {
7258 /* Must be a fresh device to add to a container */
7259 return validate_geometry_imsm_container(st
, level
, layout
,
7269 struct intel_super
*super
= st
->sb
;
7270 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
7271 raiddisks
, chunk
, size
,
7274 /* we are being asked to automatically layout a
7275 * new volume based on the current contents of
7276 * the container. If the the parameters can be
7277 * satisfied reserve_space will record the disks,
7278 * start offset, and size of the volume to be
7279 * created. add_to_super and getinfo_super
7280 * detect when autolayout is in progress.
7282 /* assuming that freesize is always given when array is
7284 if (super
->orom
&& freesize
) {
7286 count
= count_volumes(super
->hba
,
7287 super
->orom
->dpa
, verbose
);
7288 if (super
->orom
->vphba
<= count
) {
7289 pr_vrb("platform does not support more than %d raid volumes.\n",
7290 super
->orom
->vphba
);
7295 return reserve_space(st
, raiddisks
, size
,
7301 /* creating in a given container */
7302 return validate_geometry_imsm_volume(st
, level
, layout
,
7303 raiddisks
, chunk
, size
,
7305 dev
, freesize
, verbose
);
7308 /* This device needs to be a device in an 'imsm' container */
7309 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
7312 pr_err("Cannot create this array on device %s\n",
7317 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
7319 pr_err("Cannot open %s: %s\n",
7320 dev
, strerror(errno
));
7323 /* Well, it is in use by someone, maybe an 'imsm' container. */
7324 cfd
= open_container(fd
);
7328 pr_err("Cannot use %s: It is busy\n",
7332 sra
= sysfs_read(cfd
, NULL
, GET_VERSION
);
7333 if (sra
&& sra
->array
.major_version
== -1 &&
7334 strcmp(sra
->text_version
, "imsm") == 0)
7338 /* This is a member of a imsm container. Load the container
7339 * and try to create a volume
7341 struct intel_super
*super
;
7343 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
, NULL
, 1) == 0) {
7345 strcpy(st
->container_devnm
, fd2devnm(cfd
));
7347 return validate_geometry_imsm_volume(st
, level
, layout
,
7349 size
, data_offset
, dev
,
7356 pr_err("failed container membership check\n");
7362 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
7364 struct intel_super
*super
= st
->sb
;
7366 if (level
&& *level
== UnSet
)
7367 *level
= LEVEL_CONTAINER
;
7369 if (level
&& layout
&& *layout
== UnSet
)
7370 *layout
= imsm_level_to_layout(*level
);
7372 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0))
7373 *chunk
= imsm_default_chunk(super
->orom
);
7376 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
7378 static int kill_subarray_imsm(struct supertype
*st
)
7380 /* remove the subarray currently referenced by ->current_vol */
7382 struct intel_dev
**dp
;
7383 struct intel_super
*super
= st
->sb
;
7384 __u8 current_vol
= super
->current_vol
;
7385 struct imsm_super
*mpb
= super
->anchor
;
7387 if (super
->current_vol
< 0)
7389 super
->current_vol
= -1; /* invalidate subarray cursor */
7391 /* block deletions that would change the uuid of active subarrays
7393 * FIXME when immutable ids are available, but note that we'll
7394 * also need to fixup the invalidated/active subarray indexes in
7397 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7400 if (i
< current_vol
)
7402 sprintf(subarray
, "%u", i
);
7403 if (is_subarray_active(subarray
, st
->devnm
)) {
7404 pr_err("deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
7411 if (st
->update_tail
) {
7412 struct imsm_update_kill_array
*u
= xmalloc(sizeof(*u
));
7414 u
->type
= update_kill_array
;
7415 u
->dev_idx
= current_vol
;
7416 append_metadata_update(st
, u
, sizeof(*u
));
7421 for (dp
= &super
->devlist
; *dp
;)
7422 if ((*dp
)->index
== current_vol
) {
7425 handle_missing(super
, (*dp
)->dev
);
7426 if ((*dp
)->index
> current_vol
)
7431 /* no more raid devices, all active components are now spares,
7432 * but of course failed are still failed
7434 if (--mpb
->num_raid_devs
== 0) {
7437 for (d
= super
->disks
; d
; d
= d
->next
)
7442 super
->updates_pending
++;
7447 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
7448 char *update
, struct mddev_ident
*ident
)
7450 /* update the subarray currently referenced by ->current_vol */
7451 struct intel_super
*super
= st
->sb
;
7452 struct imsm_super
*mpb
= super
->anchor
;
7454 if (strcmp(update
, "name") == 0) {
7455 char *name
= ident
->name
;
7459 if (is_subarray_active(subarray
, st
->devnm
)) {
7460 pr_err("Unable to update name of active subarray\n");
7464 if (!check_name(super
, name
, 0))
7467 vol
= strtoul(subarray
, &ep
, 10);
7468 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
7471 if (st
->update_tail
) {
7472 struct imsm_update_rename_array
*u
= xmalloc(sizeof(*u
));
7474 u
->type
= update_rename_array
;
7476 strncpy((char *) u
->name
, name
, MAX_RAID_SERIAL_LEN
);
7477 u
->name
[MAX_RAID_SERIAL_LEN
-1] = '\0';
7478 append_metadata_update(st
, u
, sizeof(*u
));
7480 struct imsm_dev
*dev
;
7483 dev
= get_imsm_dev(super
, vol
);
7484 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
7485 dev
->volume
[MAX_RAID_SERIAL_LEN
-1] = '\0';
7486 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7487 dev
= get_imsm_dev(super
, i
);
7488 handle_missing(super
, dev
);
7490 super
->updates_pending
++;
7492 } else if (strcmp(update
, "ppl") == 0 ||
7493 strcmp(update
, "no-ppl") == 0) {
7496 int vol
= strtoul(subarray
, &ep
, 10);
7498 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
7501 if (strcmp(update
, "ppl") == 0)
7502 new_policy
= RWH_MULTIPLE_DISTRIBUTED
;
7504 new_policy
= RWH_MULTIPLE_OFF
;
7506 if (st
->update_tail
) {
7507 struct imsm_update_rwh_policy
*u
= xmalloc(sizeof(*u
));
7509 u
->type
= update_rwh_policy
;
7511 u
->new_policy
= new_policy
;
7512 append_metadata_update(st
, u
, sizeof(*u
));
7514 struct imsm_dev
*dev
;
7516 dev
= get_imsm_dev(super
, vol
);
7517 dev
->rwh_policy
= new_policy
;
7518 super
->updates_pending
++;
7526 static int is_gen_migration(struct imsm_dev
*dev
)
7531 if (!dev
->vol
.migr_state
)
7534 if (migr_type(dev
) == MIGR_GEN_MIGR
)
7540 static int is_rebuilding(struct imsm_dev
*dev
)
7542 struct imsm_map
*migr_map
;
7544 if (!dev
->vol
.migr_state
)
7547 if (migr_type(dev
) != MIGR_REBUILD
)
7550 migr_map
= get_imsm_map(dev
, MAP_1
);
7552 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
7558 static int is_initializing(struct imsm_dev
*dev
)
7560 struct imsm_map
*migr_map
;
7562 if (!dev
->vol
.migr_state
)
7565 if (migr_type(dev
) != MIGR_INIT
)
7568 migr_map
= get_imsm_map(dev
, MAP_1
);
7570 if (migr_map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
7576 static void update_recovery_start(struct intel_super
*super
,
7577 struct imsm_dev
*dev
,
7578 struct mdinfo
*array
)
7580 struct mdinfo
*rebuild
= NULL
;
7584 if (!is_rebuilding(dev
))
7587 /* Find the rebuild target, but punt on the dual rebuild case */
7588 for (d
= array
->devs
; d
; d
= d
->next
)
7589 if (d
->recovery_start
== 0) {
7596 /* (?) none of the disks are marked with
7597 * IMSM_ORD_REBUILD, so assume they are missing and the
7598 * disk_ord_tbl was not correctly updated
7600 dprintf("failed to locate out-of-sync disk\n");
7604 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
7605 rebuild
->recovery_start
= units
* blocks_per_migr_unit(super
, dev
);
7608 static int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
);
7610 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
7612 /* Given a container loaded by load_super_imsm_all,
7613 * extract information about all the arrays into
7615 * If 'subarray' is given, just extract info about that array.
7617 * For each imsm_dev create an mdinfo, fill it in,
7618 * then look for matching devices in super->disks
7619 * and create appropriate device mdinfo.
7621 struct intel_super
*super
= st
->sb
;
7622 struct imsm_super
*mpb
= super
->anchor
;
7623 struct mdinfo
*rest
= NULL
;
7627 int spare_disks
= 0;
7629 /* do not assemble arrays when not all attributes are supported */
7630 if (imsm_check_attributes(mpb
->attributes
) == 0) {
7632 pr_err("Unsupported attributes in IMSM metadata.Arrays activation is blocked.\n");
7635 /* count spare devices, not used in maps
7637 for (d
= super
->disks
; d
; d
= d
->next
)
7641 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7642 struct imsm_dev
*dev
;
7643 struct imsm_map
*map
;
7644 struct imsm_map
*map2
;
7645 struct mdinfo
*this;
7651 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
7654 dev
= get_imsm_dev(super
, i
);
7655 map
= get_imsm_map(dev
, MAP_0
);
7656 map2
= get_imsm_map(dev
, MAP_1
);
7658 /* do not publish arrays that are in the middle of an
7659 * unsupported migration
7661 if (dev
->vol
.migr_state
&&
7662 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
7663 pr_err("cannot assemble volume '%.16s': unsupported migration in progress\n",
7667 /* do not publish arrays that are not support by controller's
7671 this = xmalloc(sizeof(*this));
7673 super
->current_vol
= i
;
7674 getinfo_super_imsm_volume(st
, this, NULL
);
7676 chunk
= __le16_to_cpu(map
->blocks_per_strip
) >> 1;
7677 /* mdadm does not support all metadata features- set the bit in all arrays state */
7678 if (!validate_geometry_imsm_orom(super
,
7679 get_imsm_raid_level(map
), /* RAID level */
7680 imsm_level_to_layout(get_imsm_raid_level(map
)),
7681 map
->num_members
, /* raid disks */
7682 &chunk
, join_u32(dev
->size_low
, dev
->size_high
),
7684 pr_err("IMSM RAID geometry validation failed. Array %s activation is blocked.\n",
7686 this->array
.state
|=
7687 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
7688 (1<<MD_SB_BLOCK_VOLUME
);
7691 /* if array has bad blocks, set suitable bit in all arrays state */
7693 this->array
.state
|=
7694 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
7695 (1<<MD_SB_BLOCK_VOLUME
);
7697 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
7698 unsigned long long recovery_start
;
7699 struct mdinfo
*info_d
;
7706 idx
= get_imsm_disk_idx(dev
, slot
, MAP_0
);
7707 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
7708 for (d
= super
->disks
; d
; d
= d
->next
)
7709 if (d
->index
== idx
)
7712 recovery_start
= MaxSector
;
7715 if (d
&& is_failed(&d
->disk
))
7717 if (ord
& IMSM_ORD_REBUILD
)
7721 * if we skip some disks the array will be assmebled degraded;
7722 * reset resync start to avoid a dirty-degraded
7723 * situation when performing the intial sync
7725 * FIXME handle dirty degraded
7727 if ((skip
|| recovery_start
== 0) &&
7728 !(dev
->vol
.dirty
& RAIDVOL_DIRTY
))
7729 this->resync_start
= MaxSector
;
7733 info_d
= xcalloc(1, sizeof(*info_d
));
7734 info_d
->next
= this->devs
;
7735 this->devs
= info_d
;
7737 info_d
->disk
.number
= d
->index
;
7738 info_d
->disk
.major
= d
->major
;
7739 info_d
->disk
.minor
= d
->minor
;
7740 info_d
->disk
.raid_disk
= slot
;
7741 info_d
->recovery_start
= recovery_start
;
7743 if (slot
< map2
->num_members
)
7744 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
7746 this->array
.spare_disks
++;
7748 if (slot
< map
->num_members
)
7749 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
7751 this->array
.spare_disks
++;
7753 if (info_d
->recovery_start
== MaxSector
)
7754 this->array
.working_disks
++;
7756 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
7757 info_d
->data_offset
= pba_of_lba0(map
);
7759 if (map
->raid_level
== 5) {
7760 info_d
->component_size
=
7761 num_data_stripes(map
) *
7762 map
->blocks_per_strip
;
7763 info_d
->ppl_sector
= this->ppl_sector
;
7764 info_d
->ppl_size
= this->ppl_size
;
7765 if (this->consistency_policy
== CONSISTENCY_POLICY_PPL
&&
7766 recovery_start
== 0)
7767 this->resync_start
= 0;
7769 info_d
->component_size
= blocks_per_member(map
);
7772 info_d
->bb
.supported
= 1;
7773 get_volume_badblocks(super
->bbm_log
, ord_to_idx(ord
),
7774 info_d
->data_offset
,
7775 info_d
->component_size
,
7778 /* now that the disk list is up-to-date fixup recovery_start */
7779 update_recovery_start(super
, dev
, this);
7780 this->array
.spare_disks
+= spare_disks
;
7782 /* check for reshape */
7783 if (this->reshape_active
== 1)
7784 recover_backup_imsm(st
, this);
7791 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
7792 int failed
, int look_in_map
)
7794 struct imsm_map
*map
;
7796 map
= get_imsm_map(dev
, look_in_map
);
7799 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
7800 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
7802 switch (get_imsm_raid_level(map
)) {
7804 return IMSM_T_STATE_FAILED
;
7807 if (failed
< map
->num_members
)
7808 return IMSM_T_STATE_DEGRADED
;
7810 return IMSM_T_STATE_FAILED
;
7815 * check to see if any mirrors have failed, otherwise we
7816 * are degraded. Even numbered slots are mirrored on
7820 /* gcc -Os complains that this is unused */
7821 int insync
= insync
;
7823 for (i
= 0; i
< map
->num_members
; i
++) {
7824 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_X
);
7825 int idx
= ord_to_idx(ord
);
7826 struct imsm_disk
*disk
;
7828 /* reset the potential in-sync count on even-numbered
7829 * slots. num_copies is always 2 for imsm raid10
7834 disk
= get_imsm_disk(super
, idx
);
7835 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
7838 /* no in-sync disks left in this mirror the
7842 return IMSM_T_STATE_FAILED
;
7845 return IMSM_T_STATE_DEGRADED
;
7849 return IMSM_T_STATE_DEGRADED
;
7851 return IMSM_T_STATE_FAILED
;
7857 return map
->map_state
;
7860 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
7865 struct imsm_disk
*disk
;
7866 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7867 struct imsm_map
*prev
= get_imsm_map(dev
, MAP_1
);
7868 struct imsm_map
*map_for_loop
;
7873 /* at the beginning of migration we set IMSM_ORD_REBUILD on
7874 * disks that are being rebuilt. New failures are recorded to
7875 * map[0]. So we look through all the disks we started with and
7876 * see if any failures are still present, or if any new ones
7880 if (prev
&& (map
->num_members
< prev
->num_members
))
7881 map_for_loop
= prev
;
7883 for (i
= 0; i
< map_for_loop
->num_members
; i
++) {
7885 /* when MAP_X is passed both maps failures are counted
7888 (look_in_map
== MAP_1
|| look_in_map
== MAP_X
) &&
7889 i
< prev
->num_members
) {
7890 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
7891 idx_1
= ord_to_idx(ord
);
7893 disk
= get_imsm_disk(super
, idx_1
);
7894 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
7897 if ((look_in_map
== MAP_0
|| look_in_map
== MAP_X
) &&
7898 i
< map
->num_members
) {
7899 ord
= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
7900 idx
= ord_to_idx(ord
);
7903 disk
= get_imsm_disk(super
, idx
);
7904 if (!disk
|| is_failed(disk
) ||
7905 ord
& IMSM_ORD_REBUILD
)
7914 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
7917 struct intel_super
*super
= c
->sb
;
7918 struct imsm_super
*mpb
= super
->anchor
;
7919 struct imsm_update_prealloc_bb_mem u
;
7921 if (atoi(inst
) >= mpb
->num_raid_devs
) {
7922 pr_err("subarry index %d, out of range\n", atoi(inst
));
7926 dprintf("imsm: open_new %s\n", inst
);
7927 a
->info
.container_member
= atoi(inst
);
7929 u
.type
= update_prealloc_badblocks_mem
;
7930 imsm_update_metadata_locally(c
, &u
, sizeof(u
));
7935 static int is_resyncing(struct imsm_dev
*dev
)
7937 struct imsm_map
*migr_map
;
7939 if (!dev
->vol
.migr_state
)
7942 if (migr_type(dev
) == MIGR_INIT
||
7943 migr_type(dev
) == MIGR_REPAIR
)
7946 if (migr_type(dev
) == MIGR_GEN_MIGR
)
7949 migr_map
= get_imsm_map(dev
, MAP_1
);
7951 if (migr_map
->map_state
== IMSM_T_STATE_NORMAL
&&
7952 dev
->vol
.migr_type
!= MIGR_GEN_MIGR
)
7958 /* return true if we recorded new information */
7959 static int mark_failure(struct intel_super
*super
,
7960 struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
7964 struct imsm_map
*map
;
7965 char buf
[MAX_RAID_SERIAL_LEN
+3];
7966 unsigned int len
, shift
= 0;
7968 /* new failures are always set in map[0] */
7969 map
= get_imsm_map(dev
, MAP_0
);
7971 slot
= get_imsm_disk_slot(map
, idx
);
7975 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
7976 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
7979 memcpy(buf
, disk
->serial
, MAX_RAID_SERIAL_LEN
);
7980 buf
[MAX_RAID_SERIAL_LEN
] = '\000';
7982 if ((len
= strlen(buf
)) >= MAX_RAID_SERIAL_LEN
)
7983 shift
= len
- MAX_RAID_SERIAL_LEN
+ 1;
7984 strncpy((char *)disk
->serial
, &buf
[shift
], MAX_RAID_SERIAL_LEN
);
7986 disk
->status
|= FAILED_DISK
;
7987 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
7988 /* mark failures in second map if second map exists and this disk
7990 * This is valid for migration, initialization and rebuild
7992 if (dev
->vol
.migr_state
) {
7993 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
7994 int slot2
= get_imsm_disk_slot(map2
, idx
);
7996 if (slot2
< map2
->num_members
&& slot2
>= 0)
7997 set_imsm_ord_tbl_ent(map2
, slot2
,
7998 idx
| IMSM_ORD_REBUILD
);
8000 if (map
->failed_disk_num
== 0xff)
8001 map
->failed_disk_num
= slot
;
8003 clear_disk_badblocks(super
->bbm_log
, ord_to_idx(ord
));
8008 static void mark_missing(struct intel_super
*super
,
8009 struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
8011 mark_failure(super
, dev
, disk
, idx
);
8013 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
8016 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
8017 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
8020 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
8024 if (!super
->missing
)
8027 /* When orom adds replacement for missing disk it does
8028 * not remove entry of missing disk, but just updates map with
8029 * new added disk. So it is not enough just to test if there is
8030 * any missing disk, we have to look if there are any failed disks
8031 * in map to stop migration */
8033 dprintf("imsm: mark missing\n");
8034 /* end process for initialization and rebuild only
8036 if (is_gen_migration(dev
) == 0) {
8037 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
8041 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8042 struct imsm_map
*map1
;
8043 int i
, ord
, ord_map1
;
8046 for (i
= 0; i
< map
->num_members
; i
++) {
8047 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
8048 if (!(ord
& IMSM_ORD_REBUILD
))
8051 map1
= get_imsm_map(dev
, MAP_1
);
8055 ord_map1
= __le32_to_cpu(map1
->disk_ord_tbl
[i
]);
8056 if (ord_map1
& IMSM_ORD_REBUILD
)
8061 map_state
= imsm_check_degraded(super
, dev
,
8063 end_migration(dev
, super
, map_state
);
8067 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
8068 mark_missing(super
, dev
, &dl
->disk
, dl
->index
);
8069 super
->updates_pending
++;
8072 static unsigned long long imsm_set_array_size(struct imsm_dev
*dev
,
8075 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
8076 unsigned long long array_blocks
;
8077 struct imsm_map
*map
;
8079 if (used_disks
== 0) {
8080 /* when problems occures
8081 * return current array_blocks value
8083 array_blocks
= __le32_to_cpu(dev
->size_high
);
8084 array_blocks
= array_blocks
<< 32;
8085 array_blocks
+= __le32_to_cpu(dev
->size_low
);
8087 return array_blocks
;
8090 /* set array size in metadata
8092 if (new_size
<= 0) {
8093 /* OLCE size change is caused by added disks
8095 map
= get_imsm_map(dev
, MAP_0
);
8096 array_blocks
= blocks_per_member(map
) * used_disks
;
8098 /* Online Volume Size Change
8099 * Using available free space
8101 array_blocks
= new_size
;
8104 array_blocks
= round_size_to_mb(array_blocks
, used_disks
);
8105 dev
->size_low
= __cpu_to_le32((__u32
)array_blocks
);
8106 dev
->size_high
= __cpu_to_le32((__u32
)(array_blocks
>> 32));
8108 return array_blocks
;
8111 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
8113 static void imsm_progress_container_reshape(struct intel_super
*super
)
8115 /* if no device has a migr_state, but some device has a
8116 * different number of members than the previous device, start
8117 * changing the number of devices in this device to match
8120 struct imsm_super
*mpb
= super
->anchor
;
8121 int prev_disks
= -1;
8125 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8126 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
8127 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8128 struct imsm_map
*map2
;
8129 int prev_num_members
;
8131 if (dev
->vol
.migr_state
)
8134 if (prev_disks
== -1)
8135 prev_disks
= map
->num_members
;
8136 if (prev_disks
== map
->num_members
)
8139 /* OK, this array needs to enter reshape mode.
8140 * i.e it needs a migr_state
8143 copy_map_size
= sizeof_imsm_map(map
);
8144 prev_num_members
= map
->num_members
;
8145 map
->num_members
= prev_disks
;
8146 dev
->vol
.migr_state
= 1;
8147 dev
->vol
.curr_migr_unit
= 0;
8148 set_migr_type(dev
, MIGR_GEN_MIGR
);
8149 for (i
= prev_num_members
;
8150 i
< map
->num_members
; i
++)
8151 set_imsm_ord_tbl_ent(map
, i
, i
);
8152 map2
= get_imsm_map(dev
, MAP_1
);
8153 /* Copy the current map */
8154 memcpy(map2
, map
, copy_map_size
);
8155 map2
->num_members
= prev_num_members
;
8157 imsm_set_array_size(dev
, -1);
8158 super
->clean_migration_record_by_mdmon
= 1;
8159 super
->updates_pending
++;
8163 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
8164 * states are handled in imsm_set_disk() with one exception, when a
8165 * resync is stopped due to a new failure this routine will set the
8166 * 'degraded' state for the array.
8168 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
8170 int inst
= a
->info
.container_member
;
8171 struct intel_super
*super
= a
->container
->sb
;
8172 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8173 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8174 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
8175 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8176 __u32 blocks_per_unit
;
8178 if (dev
->vol
.migr_state
&&
8179 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
8180 /* array state change is blocked due to reshape action
8182 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
8183 * - finish the reshape (if last_checkpoint is big and action != reshape)
8184 * - update curr_migr_unit
8186 if (a
->curr_action
== reshape
) {
8187 /* still reshaping, maybe update curr_migr_unit */
8188 goto mark_checkpoint
;
8190 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
8191 /* for some reason we aborted the reshape.
8193 * disable automatic metadata rollback
8194 * user action is required to recover process
8197 struct imsm_map
*map2
=
8198 get_imsm_map(dev
, MAP_1
);
8199 dev
->vol
.migr_state
= 0;
8200 set_migr_type(dev
, 0);
8201 dev
->vol
.curr_migr_unit
= 0;
8203 sizeof_imsm_map(map2
));
8204 super
->updates_pending
++;
8207 if (a
->last_checkpoint
>= a
->info
.component_size
) {
8208 unsigned long long array_blocks
;
8212 used_disks
= imsm_num_data_members(dev
, MAP_0
);
8213 if (used_disks
> 0) {
8215 blocks_per_member(map
) *
8218 round_size_to_mb(array_blocks
,
8220 a
->info
.custom_array_size
= array_blocks
;
8221 /* encourage manager to update array
8225 a
->check_reshape
= 1;
8227 /* finalize online capacity expansion/reshape */
8228 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
8230 mdi
->disk
.raid_disk
,
8233 imsm_progress_container_reshape(super
);
8238 /* before we activate this array handle any missing disks */
8239 if (consistent
== 2)
8240 handle_missing(super
, dev
);
8242 if (consistent
== 2 &&
8243 (!is_resync_complete(&a
->info
) ||
8244 map_state
!= IMSM_T_STATE_NORMAL
||
8245 dev
->vol
.migr_state
))
8248 if (is_resync_complete(&a
->info
)) {
8249 /* complete intialization / resync,
8250 * recovery and interrupted recovery is completed in
8253 if (is_resyncing(dev
)) {
8254 dprintf("imsm: mark resync done\n");
8255 end_migration(dev
, super
, map_state
);
8256 super
->updates_pending
++;
8257 a
->last_checkpoint
= 0;
8259 } else if ((!is_resyncing(dev
) && !failed
) &&
8260 (imsm_reshape_blocks_arrays_changes(super
) == 0)) {
8261 /* mark the start of the init process if nothing is failed */
8262 dprintf("imsm: mark resync start\n");
8263 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
8264 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
8266 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
8267 super
->updates_pending
++;
8271 /* skip checkpointing for general migration,
8272 * it is controlled in mdadm
8274 if (is_gen_migration(dev
))
8275 goto skip_mark_checkpoint
;
8277 /* check if we can update curr_migr_unit from resync_start, recovery_start */
8278 blocks_per_unit
= blocks_per_migr_unit(super
, dev
);
8279 if (blocks_per_unit
) {
8283 units
= a
->last_checkpoint
/ blocks_per_unit
;
8286 /* check that we did not overflow 32-bits, and that
8287 * curr_migr_unit needs updating
8289 if (units32
== units
&&
8291 __le32_to_cpu(dev
->vol
.curr_migr_unit
) != units32
) {
8292 dprintf("imsm: mark checkpoint (%u)\n", units32
);
8293 dev
->vol
.curr_migr_unit
= __cpu_to_le32(units32
);
8294 super
->updates_pending
++;
8298 skip_mark_checkpoint
:
8299 /* mark dirty / clean */
8300 if (((dev
->vol
.dirty
& RAIDVOL_DIRTY
) && consistent
) ||
8301 (!(dev
->vol
.dirty
& RAIDVOL_DIRTY
) && !consistent
)) {
8302 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
8304 dev
->vol
.dirty
= RAIDVOL_CLEAN
;
8306 dev
->vol
.dirty
= RAIDVOL_DIRTY
;
8307 if (dev
->rwh_policy
== RWH_DISTRIBUTED
||
8308 dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)
8309 dev
->vol
.dirty
|= RAIDVOL_DSRECORD_VALID
;
8311 super
->updates_pending
++;
8317 static int imsm_disk_slot_to_ord(struct active_array
*a
, int slot
)
8319 int inst
= a
->info
.container_member
;
8320 struct intel_super
*super
= a
->container
->sb
;
8321 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8322 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8324 if (slot
> map
->num_members
) {
8325 pr_err("imsm: imsm_disk_slot_to_ord %d out of range 0..%d\n",
8326 slot
, map
->num_members
- 1);
8333 return get_imsm_ord_tbl_ent(dev
, slot
, MAP_0
);
8336 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
8338 int inst
= a
->info
.container_member
;
8339 struct intel_super
*super
= a
->container
->sb
;
8340 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8341 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8342 struct imsm_disk
*disk
;
8344 int recovery_not_finished
= 0;
8348 int rebuild_done
= 0;
8351 ord
= get_imsm_ord_tbl_ent(dev
, n
, MAP_X
);
8355 dprintf("imsm: set_disk %d:%x\n", n
, state
);
8356 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
8358 /* check for new failures */
8359 if (state
& DS_FAULTY
) {
8360 if (mark_failure(super
, dev
, disk
, ord_to_idx(ord
)))
8361 super
->updates_pending
++;
8364 /* check if in_sync */
8365 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
8366 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
8368 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
8370 super
->updates_pending
++;
8373 failed
= imsm_count_failed(super
, dev
, MAP_0
);
8374 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8376 /* check if recovery complete, newly degraded, or failed */
8377 dprintf("imsm: Detected transition to state ");
8378 switch (map_state
) {
8379 case IMSM_T_STATE_NORMAL
: /* transition to normal state */
8380 dprintf("normal: ");
8381 if (is_rebuilding(dev
)) {
8382 dprintf_cont("while rebuilding");
8383 /* check if recovery is really finished */
8384 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
8385 if (mdi
->recovery_start
!= MaxSector
) {
8386 recovery_not_finished
= 1;
8389 if (recovery_not_finished
) {
8391 dprintf("Rebuild has not finished yet, state not changed");
8392 if (a
->last_checkpoint
< mdi
->recovery_start
) {
8393 a
->last_checkpoint
= mdi
->recovery_start
;
8394 super
->updates_pending
++;
8398 end_migration(dev
, super
, map_state
);
8399 map
= get_imsm_map(dev
, MAP_0
);
8400 map
->failed_disk_num
= ~0;
8401 super
->updates_pending
++;
8402 a
->last_checkpoint
= 0;
8405 if (is_gen_migration(dev
)) {
8406 dprintf_cont("while general migration");
8407 if (a
->last_checkpoint
>= a
->info
.component_size
)
8408 end_migration(dev
, super
, map_state
);
8410 map
->map_state
= map_state
;
8411 map
= get_imsm_map(dev
, MAP_0
);
8412 map
->failed_disk_num
= ~0;
8413 super
->updates_pending
++;
8417 case IMSM_T_STATE_DEGRADED
: /* transition to degraded state */
8418 dprintf_cont("degraded: ");
8419 if (map
->map_state
!= map_state
&& !dev
->vol
.migr_state
) {
8420 dprintf_cont("mark degraded");
8421 map
->map_state
= map_state
;
8422 super
->updates_pending
++;
8423 a
->last_checkpoint
= 0;
8426 if (is_rebuilding(dev
)) {
8427 dprintf_cont("while rebuilding.");
8428 if (map
->map_state
!= map_state
) {
8429 dprintf_cont(" Map state change");
8430 end_migration(dev
, super
, map_state
);
8431 super
->updates_pending
++;
8432 } else if (!rebuild_done
) {
8436 /* check if recovery is really finished */
8437 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
8438 if (mdi
->recovery_start
!= MaxSector
) {
8439 recovery_not_finished
= 1;
8442 if (recovery_not_finished
) {
8444 dprintf("Rebuild has not finished yet, state not changed");
8445 if (a
->last_checkpoint
< mdi
->recovery_start
) {
8446 a
->last_checkpoint
=
8447 mdi
->recovery_start
;
8448 super
->updates_pending
++;
8453 dprintf_cont(" Rebuild done, still degraded");
8454 dev
->vol
.migr_state
= 0;
8455 set_migr_type(dev
, 0);
8456 dev
->vol
.curr_migr_unit
= 0;
8458 for (i
= 0; i
< map
->num_members
; i
++) {
8459 int idx
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
8461 if (idx
& IMSM_ORD_REBUILD
)
8462 map
->failed_disk_num
= i
;
8464 super
->updates_pending
++;
8467 if (is_gen_migration(dev
)) {
8468 dprintf_cont("while general migration");
8469 if (a
->last_checkpoint
>= a
->info
.component_size
)
8470 end_migration(dev
, super
, map_state
);
8472 map
->map_state
= map_state
;
8473 manage_second_map(super
, dev
);
8475 super
->updates_pending
++;
8478 if (is_initializing(dev
)) {
8479 dprintf_cont("while initialization.");
8480 map
->map_state
= map_state
;
8481 super
->updates_pending
++;
8485 case IMSM_T_STATE_FAILED
: /* transition to failed state */
8486 dprintf_cont("failed: ");
8487 if (is_gen_migration(dev
)) {
8488 dprintf_cont("while general migration");
8489 map
->map_state
= map_state
;
8490 super
->updates_pending
++;
8493 if (map
->map_state
!= map_state
) {
8494 dprintf_cont("mark failed");
8495 end_migration(dev
, super
, map_state
);
8496 super
->updates_pending
++;
8497 a
->last_checkpoint
= 0;
8502 dprintf_cont("state %i\n", map_state
);
8507 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
8510 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
8511 unsigned long long dsize
;
8512 unsigned long long sectors
;
8513 unsigned int sector_size
;
8515 get_dev_sector_size(fd
, NULL
, §or_size
);
8516 get_dev_size(fd
, NULL
, &dsize
);
8518 if (mpb_size
> sector_size
) {
8519 /* -1 to account for anchor */
8520 sectors
= mpb_sectors(mpb
, sector_size
) - 1;
8522 /* write the extended mpb to the sectors preceeding the anchor */
8523 if (lseek64(fd
, dsize
- (sector_size
* (2 + sectors
)),
8527 if ((unsigned long long)write(fd
, buf
+ sector_size
,
8528 sector_size
* sectors
) != sector_size
* sectors
)
8532 /* first block is stored on second to last sector of the disk */
8533 if (lseek64(fd
, dsize
- (sector_size
* 2), SEEK_SET
) < 0)
8536 if ((unsigned int)write(fd
, buf
, sector_size
) != sector_size
)
8542 static void imsm_sync_metadata(struct supertype
*container
)
8544 struct intel_super
*super
= container
->sb
;
8546 dprintf("sync metadata: %d\n", super
->updates_pending
);
8547 if (!super
->updates_pending
)
8550 write_super_imsm(container
, 0);
8552 super
->updates_pending
= 0;
8555 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
8557 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
8558 int i
= get_imsm_disk_idx(dev
, idx
, MAP_X
);
8561 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8565 if (dl
&& is_failed(&dl
->disk
))
8569 dprintf("found %x:%x\n", dl
->major
, dl
->minor
);
8574 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
8575 struct active_array
*a
, int activate_new
,
8576 struct mdinfo
*additional_test_list
)
8578 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
8579 int idx
= get_imsm_disk_idx(dev
, slot
, MAP_X
);
8580 struct imsm_super
*mpb
= super
->anchor
;
8581 struct imsm_map
*map
;
8582 unsigned long long pos
;
8587 __u32 array_start
= 0;
8588 __u32 array_end
= 0;
8590 struct mdinfo
*test_list
;
8592 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
8593 /* If in this array, skip */
8594 for (d
= a
->info
.devs
; d
; d
= d
->next
)
8595 if (d
->state_fd
>= 0 &&
8596 d
->disk
.major
== dl
->major
&&
8597 d
->disk
.minor
== dl
->minor
) {
8598 dprintf("%x:%x already in array\n",
8599 dl
->major
, dl
->minor
);
8604 test_list
= additional_test_list
;
8606 if (test_list
->disk
.major
== dl
->major
&&
8607 test_list
->disk
.minor
== dl
->minor
) {
8608 dprintf("%x:%x already in additional test list\n",
8609 dl
->major
, dl
->minor
);
8612 test_list
= test_list
->next
;
8617 /* skip in use or failed drives */
8618 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
8620 dprintf("%x:%x status (failed: %d index: %d)\n",
8621 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
8625 /* skip pure spares when we are looking for partially
8626 * assimilated drives
8628 if (dl
->index
== -1 && !activate_new
)
8631 if (!drive_validate_sector_size(super
, dl
))
8634 /* Does this unused device have the requisite free space?
8635 * It needs to be able to cover all member volumes
8637 ex
= get_extents(super
, dl
);
8639 dprintf("cannot get extents\n");
8642 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8643 dev
= get_imsm_dev(super
, i
);
8644 map
= get_imsm_map(dev
, MAP_0
);
8646 /* check if this disk is already a member of
8649 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
8655 array_start
= pba_of_lba0(map
);
8656 array_end
= array_start
+
8657 blocks_per_member(map
) - 1;
8660 /* check that we can start at pba_of_lba0 with
8661 * blocks_per_member of space
8663 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
8667 pos
= ex
[j
].start
+ ex
[j
].size
;
8669 } while (ex
[j
-1].size
);
8676 if (i
< mpb
->num_raid_devs
) {
8677 dprintf("%x:%x does not have %u to %u available\n",
8678 dl
->major
, dl
->minor
, array_start
, array_end
);
8688 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
8690 struct imsm_dev
*dev2
;
8691 struct imsm_map
*map
;
8697 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
8699 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
, MAP_0
);
8700 if (state
== IMSM_T_STATE_FAILED
) {
8701 map
= get_imsm_map(dev2
, MAP_0
);
8704 for (slot
= 0; slot
< map
->num_members
; slot
++) {
8706 * Check if failed disks are deleted from intel
8707 * disk list or are marked to be deleted
8709 idx
= get_imsm_disk_idx(dev2
, slot
, MAP_X
);
8710 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
8712 * Do not rebuild the array if failed disks
8713 * from failed sub-array are not removed from
8717 is_failed(&idisk
->disk
) &&
8718 (idisk
->action
!= DISK_REMOVE
))
8726 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
8727 struct metadata_update
**updates
)
8730 * Find a device with unused free space and use it to replace a
8731 * failed/vacant region in an array. We replace failed regions one a
8732 * array at a time. The result is that a new spare disk will be added
8733 * to the first failed array and after the monitor has finished
8734 * propagating failures the remainder will be consumed.
8736 * FIXME add a capability for mdmon to request spares from another
8740 struct intel_super
*super
= a
->container
->sb
;
8741 int inst
= a
->info
.container_member
;
8742 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8743 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8744 int failed
= a
->info
.array
.raid_disks
;
8745 struct mdinfo
*rv
= NULL
;
8748 struct metadata_update
*mu
;
8750 struct imsm_update_activate_spare
*u
;
8755 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
8756 if ((d
->curr_state
& DS_FAULTY
) &&
8758 /* wait for Removal to happen */
8760 if (d
->state_fd
>= 0)
8764 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
8765 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
8767 if (imsm_reshape_blocks_arrays_changes(super
))
8770 /* Cannot activate another spare if rebuild is in progress already
8772 if (is_rebuilding(dev
)) {
8773 dprintf("imsm: No spare activation allowed. Rebuild in progress already.\n");
8777 if (a
->info
.array
.level
== 4)
8778 /* No repair for takeovered array
8779 * imsm doesn't support raid4
8783 if (imsm_check_degraded(super
, dev
, failed
, MAP_0
) !=
8784 IMSM_T_STATE_DEGRADED
)
8787 if (get_imsm_map(dev
, MAP_0
)->map_state
== IMSM_T_STATE_UNINITIALIZED
) {
8788 dprintf("imsm: No spare activation allowed. Volume is not initialized.\n");
8793 * If there are any failed disks check state of the other volume.
8794 * Block rebuild if the another one is failed until failed disks
8795 * are removed from container.
8798 dprintf("found failed disks in %.*s, check if there anotherfailed sub-array.\n",
8799 MAX_RAID_SERIAL_LEN
, dev
->volume
);
8800 /* check if states of the other volumes allow for rebuild */
8801 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
8803 allowed
= imsm_rebuild_allowed(a
->container
,
8811 /* For each slot, if it is not working, find a spare */
8812 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
8813 for (d
= a
->info
.devs
; d
; d
= d
->next
)
8814 if (d
->disk
.raid_disk
== i
)
8816 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
8817 if (d
&& (d
->state_fd
>= 0))
8821 * OK, this device needs recovery. Try to re-add the
8822 * previous occupant of this slot, if this fails see if
8823 * we can continue the assimilation of a spare that was
8824 * partially assimilated, finally try to activate a new
8827 dl
= imsm_readd(super
, i
, a
);
8829 dl
= imsm_add_spare(super
, i
, a
, 0, rv
);
8831 dl
= imsm_add_spare(super
, i
, a
, 1, rv
);
8835 /* found a usable disk with enough space */
8836 di
= xcalloc(1, sizeof(*di
));
8838 /* dl->index will be -1 in the case we are activating a
8839 * pristine spare. imsm_process_update() will create a
8840 * new index in this case. Once a disk is found to be
8841 * failed in all member arrays it is kicked from the
8844 di
->disk
.number
= dl
->index
;
8846 /* (ab)use di->devs to store a pointer to the device
8849 di
->devs
= (struct mdinfo
*) dl
;
8851 di
->disk
.raid_disk
= i
;
8852 di
->disk
.major
= dl
->major
;
8853 di
->disk
.minor
= dl
->minor
;
8855 di
->recovery_start
= 0;
8856 di
->data_offset
= pba_of_lba0(map
);
8857 di
->component_size
= a
->info
.component_size
;
8858 di
->container_member
= inst
;
8859 di
->bb
.supported
= 1;
8860 if (a
->info
.consistency_policy
== CONSISTENCY_POLICY_PPL
) {
8861 di
->ppl_sector
= get_ppl_sector(super
, inst
);
8862 di
->ppl_size
= MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9;
8864 super
->random
= random32();
8868 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
8869 i
, di
->data_offset
);
8873 /* No spares found */
8875 /* Now 'rv' has a list of devices to return.
8876 * Create a metadata_update record to update the
8877 * disk_ord_tbl for the array
8879 mu
= xmalloc(sizeof(*mu
));
8880 mu
->buf
= xcalloc(num_spares
,
8881 sizeof(struct imsm_update_activate_spare
));
8883 mu
->space_list
= NULL
;
8884 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
8885 mu
->next
= *updates
;
8886 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
8888 for (di
= rv
; di
; di
= di
->next
) {
8889 u
->type
= update_activate_spare
;
8890 u
->dl
= (struct dl
*) di
->devs
;
8892 u
->slot
= di
->disk
.raid_disk
;
8903 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
8905 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
8906 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8907 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, MAP_0
);
8908 struct disk_info
*inf
= get_disk_info(u
);
8909 struct imsm_disk
*disk
;
8913 for (i
= 0; i
< map
->num_members
; i
++) {
8914 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, MAP_X
));
8915 for (j
= 0; j
< new_map
->num_members
; j
++)
8916 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
8923 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
8927 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8928 if (dl
->major
== major
&& dl
->minor
== minor
)
8933 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
8939 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
8940 if (dl
->major
== major
&& dl
->minor
== minor
) {
8943 prev
->next
= dl
->next
;
8945 super
->disks
= dl
->next
;
8947 __free_imsm_disk(dl
);
8948 dprintf("removed %x:%x\n", major
, minor
);
8956 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
8958 static int add_remove_disk_update(struct intel_super
*super
)
8960 int check_degraded
= 0;
8963 /* add/remove some spares to/from the metadata/contrainer */
8964 while (super
->disk_mgmt_list
) {
8965 struct dl
*disk_cfg
;
8967 disk_cfg
= super
->disk_mgmt_list
;
8968 super
->disk_mgmt_list
= disk_cfg
->next
;
8969 disk_cfg
->next
= NULL
;
8971 if (disk_cfg
->action
== DISK_ADD
) {
8972 disk_cfg
->next
= super
->disks
;
8973 super
->disks
= disk_cfg
;
8975 dprintf("added %x:%x\n",
8976 disk_cfg
->major
, disk_cfg
->minor
);
8977 } else if (disk_cfg
->action
== DISK_REMOVE
) {
8978 dprintf("Disk remove action processed: %x.%x\n",
8979 disk_cfg
->major
, disk_cfg
->minor
);
8980 disk
= get_disk_super(super
,
8984 /* store action status */
8985 disk
->action
= DISK_REMOVE
;
8986 /* remove spare disks only */
8987 if (disk
->index
== -1) {
8988 remove_disk_super(super
,
8993 /* release allocate disk structure */
8994 __free_imsm_disk(disk_cfg
);
8997 return check_degraded
;
9000 static int apply_reshape_migration_update(struct imsm_update_reshape_migration
*u
,
9001 struct intel_super
*super
,
9004 struct intel_dev
*id
;
9005 void **tofree
= NULL
;
9008 dprintf("(enter)\n");
9009 if (u
->subdev
< 0 || u
->subdev
> 1) {
9010 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
9013 if (space_list
== NULL
|| *space_list
== NULL
) {
9014 dprintf("imsm: Error: Memory is not allocated\n");
9018 for (id
= super
->devlist
; id
; id
= id
->next
) {
9019 if (id
->index
== (unsigned)u
->subdev
) {
9020 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
9021 struct imsm_map
*map
;
9022 struct imsm_dev
*new_dev
=
9023 (struct imsm_dev
*)*space_list
;
9024 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
9026 struct dl
*new_disk
;
9028 if (new_dev
== NULL
)
9030 *space_list
= **space_list
;
9031 memcpy(new_dev
, dev
, sizeof_imsm_dev(dev
, 0));
9032 map
= get_imsm_map(new_dev
, MAP_0
);
9034 dprintf("imsm: Error: migration in progress");
9038 to_state
= map
->map_state
;
9039 if ((u
->new_level
== 5) && (map
->raid_level
== 0)) {
9041 /* this should not happen */
9042 if (u
->new_disks
[0] < 0) {
9043 map
->failed_disk_num
=
9044 map
->num_members
- 1;
9045 to_state
= IMSM_T_STATE_DEGRADED
;
9047 to_state
= IMSM_T_STATE_NORMAL
;
9049 migrate(new_dev
, super
, to_state
, MIGR_GEN_MIGR
);
9050 if (u
->new_level
> -1)
9051 map
->raid_level
= u
->new_level
;
9052 migr_map
= get_imsm_map(new_dev
, MAP_1
);
9053 if ((u
->new_level
== 5) &&
9054 (migr_map
->raid_level
== 0)) {
9055 int ord
= map
->num_members
- 1;
9056 migr_map
->num_members
--;
9057 if (u
->new_disks
[0] < 0)
9058 ord
|= IMSM_ORD_REBUILD
;
9059 set_imsm_ord_tbl_ent(map
,
9060 map
->num_members
- 1,
9064 tofree
= (void **)dev
;
9066 /* update chunk size
9068 if (u
->new_chunksize
> 0) {
9069 unsigned long long num_data_stripes
;
9071 imsm_num_data_members(dev
, MAP_0
);
9073 if (used_disks
== 0)
9076 map
->blocks_per_strip
=
9077 __cpu_to_le16(u
->new_chunksize
* 2);
9079 (join_u32(dev
->size_low
, dev
->size_high
)
9081 num_data_stripes
/= map
->blocks_per_strip
;
9082 num_data_stripes
/= map
->num_domains
;
9083 set_num_data_stripes(map
, num_data_stripes
);
9088 if (u
->new_level
!= 5 || migr_map
->raid_level
!= 0 ||
9089 migr_map
->raid_level
== map
->raid_level
)
9092 if (u
->new_disks
[0] >= 0) {
9095 new_disk
= get_disk_super(super
,
9096 major(u
->new_disks
[0]),
9097 minor(u
->new_disks
[0]));
9098 dprintf("imsm: new disk for reshape is: %i:%i (%p, index = %i)\n",
9099 major(u
->new_disks
[0]),
9100 minor(u
->new_disks
[0]),
9101 new_disk
, new_disk
->index
);
9102 if (new_disk
== NULL
)
9103 goto error_disk_add
;
9105 new_disk
->index
= map
->num_members
- 1;
9106 /* slot to fill in autolayout
9108 new_disk
->raiddisk
= new_disk
->index
;
9109 new_disk
->disk
.status
|= CONFIGURED_DISK
;
9110 new_disk
->disk
.status
&= ~SPARE_DISK
;
9112 goto error_disk_add
;
9115 *tofree
= *space_list
;
9116 /* calculate new size
9118 imsm_set_array_size(new_dev
, -1);
9125 *space_list
= tofree
;
9129 dprintf("Error: imsm: Cannot find disk.\n");
9133 static int apply_size_change_update(struct imsm_update_size_change
*u
,
9134 struct intel_super
*super
)
9136 struct intel_dev
*id
;
9139 dprintf("(enter)\n");
9140 if (u
->subdev
< 0 || u
->subdev
> 1) {
9141 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
9145 for (id
= super
->devlist
; id
; id
= id
->next
) {
9146 if (id
->index
== (unsigned)u
->subdev
) {
9147 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
9148 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9149 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
9150 unsigned long long blocks_per_member
;
9151 unsigned long long num_data_stripes
;
9153 /* calculate new size
9155 blocks_per_member
= u
->new_size
/ used_disks
;
9156 num_data_stripes
= blocks_per_member
/
9157 map
->blocks_per_strip
;
9158 num_data_stripes
/= map
->num_domains
;
9159 dprintf("(size: %llu, blocks per member: %llu, num_data_stipes: %llu)\n",
9160 u
->new_size
, blocks_per_member
,
9162 set_blocks_per_member(map
, blocks_per_member
);
9163 set_num_data_stripes(map
, num_data_stripes
);
9164 imsm_set_array_size(dev
, u
->new_size
);
9174 static int apply_update_activate_spare(struct imsm_update_activate_spare
*u
,
9175 struct intel_super
*super
,
9176 struct active_array
*active_array
)
9178 struct imsm_super
*mpb
= super
->anchor
;
9179 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
9180 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9181 struct imsm_map
*migr_map
;
9182 struct active_array
*a
;
9183 struct imsm_disk
*disk
;
9190 int second_map_created
= 0;
9192 for (; u
; u
= u
->next
) {
9193 victim
= get_imsm_disk_idx(dev
, u
->slot
, MAP_X
);
9198 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
9203 pr_err("error: imsm_activate_spare passed an unknown disk (index: %d)\n",
9208 /* count failures (excluding rebuilds and the victim)
9209 * to determine map[0] state
9212 for (i
= 0; i
< map
->num_members
; i
++) {
9215 disk
= get_imsm_disk(super
,
9216 get_imsm_disk_idx(dev
, i
, MAP_X
));
9217 if (!disk
|| is_failed(disk
))
9221 /* adding a pristine spare, assign a new index */
9222 if (dl
->index
< 0) {
9223 dl
->index
= super
->anchor
->num_disks
;
9224 super
->anchor
->num_disks
++;
9227 disk
->status
|= CONFIGURED_DISK
;
9228 disk
->status
&= ~SPARE_DISK
;
9231 to_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
9232 if (!second_map_created
) {
9233 second_map_created
= 1;
9234 map
->map_state
= IMSM_T_STATE_DEGRADED
;
9235 migrate(dev
, super
, to_state
, MIGR_REBUILD
);
9237 map
->map_state
= to_state
;
9238 migr_map
= get_imsm_map(dev
, MAP_1
);
9239 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
9240 set_imsm_ord_tbl_ent(migr_map
, u
->slot
,
9241 dl
->index
| IMSM_ORD_REBUILD
);
9243 /* update the family_num to mark a new container
9244 * generation, being careful to record the existing
9245 * family_num in orig_family_num to clean up after
9246 * earlier mdadm versions that neglected to set it.
9248 if (mpb
->orig_family_num
== 0)
9249 mpb
->orig_family_num
= mpb
->family_num
;
9250 mpb
->family_num
+= super
->random
;
9252 /* count arrays using the victim in the metadata */
9254 for (a
= active_array
; a
; a
= a
->next
) {
9255 dev
= get_imsm_dev(super
, a
->info
.container_member
);
9256 map
= get_imsm_map(dev
, MAP_0
);
9258 if (get_imsm_disk_slot(map
, victim
) >= 0)
9262 /* delete the victim if it is no longer being
9268 /* We know that 'manager' isn't touching anything,
9269 * so it is safe to delete
9271 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
9272 if ((*dlp
)->index
== victim
)
9275 /* victim may be on the missing list */
9277 for (dlp
= &super
->missing
; *dlp
;
9278 dlp
= &(*dlp
)->next
)
9279 if ((*dlp
)->index
== victim
)
9281 imsm_delete(super
, dlp
, victim
);
9288 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
9289 struct intel_super
*super
,
9292 struct dl
*new_disk
;
9293 struct intel_dev
*id
;
9295 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
9296 int disk_count
= u
->old_raid_disks
;
9297 void **tofree
= NULL
;
9298 int devices_to_reshape
= 1;
9299 struct imsm_super
*mpb
= super
->anchor
;
9301 unsigned int dev_id
;
9303 dprintf("(enter)\n");
9305 /* enable spares to use in array */
9306 for (i
= 0; i
< delta_disks
; i
++) {
9307 new_disk
= get_disk_super(super
,
9308 major(u
->new_disks
[i
]),
9309 minor(u
->new_disks
[i
]));
9310 dprintf("imsm: new disk for reshape is: %i:%i (%p, index = %i)\n",
9311 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
9312 new_disk
, new_disk
->index
);
9313 if (new_disk
== NULL
||
9314 (new_disk
->index
>= 0 &&
9315 new_disk
->index
< u
->old_raid_disks
))
9316 goto update_reshape_exit
;
9317 new_disk
->index
= disk_count
++;
9318 /* slot to fill in autolayout
9320 new_disk
->raiddisk
= new_disk
->index
;
9321 new_disk
->disk
.status
|=
9323 new_disk
->disk
.status
&= ~SPARE_DISK
;
9326 dprintf("imsm: volume set mpb->num_raid_devs = %i\n",
9327 mpb
->num_raid_devs
);
9328 /* manage changes in volume
9330 for (dev_id
= 0; dev_id
< mpb
->num_raid_devs
; dev_id
++) {
9331 void **sp
= *space_list
;
9332 struct imsm_dev
*newdev
;
9333 struct imsm_map
*newmap
, *oldmap
;
9335 for (id
= super
->devlist
; id
; id
= id
->next
) {
9336 if (id
->index
== dev_id
)
9345 /* Copy the dev, but not (all of) the map */
9346 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
9347 oldmap
= get_imsm_map(id
->dev
, MAP_0
);
9348 newmap
= get_imsm_map(newdev
, MAP_0
);
9349 /* Copy the current map */
9350 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
9351 /* update one device only
9353 if (devices_to_reshape
) {
9354 dprintf("imsm: modifying subdev: %i\n",
9356 devices_to_reshape
--;
9357 newdev
->vol
.migr_state
= 1;
9358 newdev
->vol
.curr_migr_unit
= 0;
9359 set_migr_type(newdev
, MIGR_GEN_MIGR
);
9360 newmap
->num_members
= u
->new_raid_disks
;
9361 for (i
= 0; i
< delta_disks
; i
++) {
9362 set_imsm_ord_tbl_ent(newmap
,
9363 u
->old_raid_disks
+ i
,
9364 u
->old_raid_disks
+ i
);
9366 /* New map is correct, now need to save old map
9368 newmap
= get_imsm_map(newdev
, MAP_1
);
9369 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
9371 imsm_set_array_size(newdev
, -1);
9374 sp
= (void **)id
->dev
;
9379 /* Clear migration record */
9380 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
9383 *space_list
= tofree
;
9386 update_reshape_exit
:
9391 static int apply_takeover_update(struct imsm_update_takeover
*u
,
9392 struct intel_super
*super
,
9395 struct imsm_dev
*dev
= NULL
;
9396 struct intel_dev
*dv
;
9397 struct imsm_dev
*dev_new
;
9398 struct imsm_map
*map
;
9402 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
9403 if (dv
->index
== (unsigned int)u
->subarray
) {
9411 map
= get_imsm_map(dev
, MAP_0
);
9413 if (u
->direction
== R10_TO_R0
) {
9414 unsigned long long num_data_stripes
;
9416 map
->num_domains
= 1;
9417 num_data_stripes
= blocks_per_member(map
);
9418 num_data_stripes
/= map
->blocks_per_strip
;
9419 num_data_stripes
/= map
->num_domains
;
9420 set_num_data_stripes(map
, num_data_stripes
);
9422 /* Number of failed disks must be half of initial disk number */
9423 if (imsm_count_failed(super
, dev
, MAP_0
) !=
9424 (map
->num_members
/ 2))
9427 /* iterate through devices to mark removed disks as spare */
9428 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
9429 if (dm
->disk
.status
& FAILED_DISK
) {
9430 int idx
= dm
->index
;
9431 /* update indexes on the disk list */
9432 /* FIXME this loop-with-the-loop looks wrong, I'm not convinced
9433 the index values will end up being correct.... NB */
9434 for (du
= super
->disks
; du
; du
= du
->next
)
9435 if (du
->index
> idx
)
9437 /* mark as spare disk */
9442 map
->num_members
= map
->num_members
/ 2;
9443 map
->map_state
= IMSM_T_STATE_NORMAL
;
9444 map
->num_domains
= 1;
9445 map
->raid_level
= 0;
9446 map
->failed_disk_num
= -1;
9449 if (u
->direction
== R0_TO_R10
) {
9451 /* update slots in current disk list */
9452 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
9456 /* create new *missing* disks */
9457 for (i
= 0; i
< map
->num_members
; i
++) {
9458 space
= *space_list
;
9461 *space_list
= *space
;
9463 memcpy(du
, super
->disks
, sizeof(*du
));
9467 du
->index
= (i
* 2) + 1;
9468 sprintf((char *)du
->disk
.serial
,
9469 " MISSING_%d", du
->index
);
9470 sprintf((char *)du
->serial
,
9471 "MISSING_%d", du
->index
);
9472 du
->next
= super
->missing
;
9473 super
->missing
= du
;
9475 /* create new dev and map */
9476 space
= *space_list
;
9479 *space_list
= *space
;
9480 dev_new
= (void *)space
;
9481 memcpy(dev_new
, dev
, sizeof(*dev
));
9482 /* update new map */
9483 map
= get_imsm_map(dev_new
, MAP_0
);
9484 map
->num_members
= map
->num_members
* 2;
9485 map
->map_state
= IMSM_T_STATE_DEGRADED
;
9486 map
->num_domains
= 2;
9487 map
->raid_level
= 1;
9488 /* replace dev<->dev_new */
9491 /* update disk order table */
9492 for (du
= super
->disks
; du
; du
= du
->next
)
9494 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
9495 for (du
= super
->missing
; du
; du
= du
->next
)
9496 if (du
->index
>= 0) {
9497 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
9498 mark_missing(super
, dv
->dev
, &du
->disk
, du
->index
);
9504 static void imsm_process_update(struct supertype
*st
,
9505 struct metadata_update
*update
)
9508 * crack open the metadata_update envelope to find the update record
9509 * update can be one of:
9510 * update_reshape_container_disks - all the arrays in the container
9511 * are being reshaped to have more devices. We need to mark
9512 * the arrays for general migration and convert selected spares
9513 * into active devices.
9514 * update_activate_spare - a spare device has replaced a failed
9515 * device in an array, update the disk_ord_tbl. If this disk is
9516 * present in all member arrays then also clear the SPARE_DISK
9518 * update_create_array
9520 * update_rename_array
9521 * update_add_remove_disk
9523 struct intel_super
*super
= st
->sb
;
9524 struct imsm_super
*mpb
;
9525 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
9527 /* update requires a larger buf but the allocation failed */
9528 if (super
->next_len
&& !super
->next_buf
) {
9529 super
->next_len
= 0;
9533 if (super
->next_buf
) {
9534 memcpy(super
->next_buf
, super
->buf
, super
->len
);
9536 super
->len
= super
->next_len
;
9537 super
->buf
= super
->next_buf
;
9539 super
->next_len
= 0;
9540 super
->next_buf
= NULL
;
9543 mpb
= super
->anchor
;
9546 case update_general_migration_checkpoint
: {
9547 struct intel_dev
*id
;
9548 struct imsm_update_general_migration_checkpoint
*u
=
9549 (void *)update
->buf
;
9551 dprintf("called for update_general_migration_checkpoint\n");
9553 /* find device under general migration */
9554 for (id
= super
->devlist
; id
; id
= id
->next
) {
9555 if (is_gen_migration(id
->dev
)) {
9556 id
->dev
->vol
.curr_migr_unit
=
9557 __cpu_to_le32(u
->curr_migr_unit
);
9558 super
->updates_pending
++;
9563 case update_takeover
: {
9564 struct imsm_update_takeover
*u
= (void *)update
->buf
;
9565 if (apply_takeover_update(u
, super
, &update
->space_list
)) {
9566 imsm_update_version_info(super
);
9567 super
->updates_pending
++;
9572 case update_reshape_container_disks
: {
9573 struct imsm_update_reshape
*u
= (void *)update
->buf
;
9574 if (apply_reshape_container_disks_update(
9575 u
, super
, &update
->space_list
))
9576 super
->updates_pending
++;
9579 case update_reshape_migration
: {
9580 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
9581 if (apply_reshape_migration_update(
9582 u
, super
, &update
->space_list
))
9583 super
->updates_pending
++;
9586 case update_size_change
: {
9587 struct imsm_update_size_change
*u
= (void *)update
->buf
;
9588 if (apply_size_change_update(u
, super
))
9589 super
->updates_pending
++;
9592 case update_activate_spare
: {
9593 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
9594 if (apply_update_activate_spare(u
, super
, st
->arrays
))
9595 super
->updates_pending
++;
9598 case update_create_array
: {
9599 /* someone wants to create a new array, we need to be aware of
9600 * a few races/collisions:
9601 * 1/ 'Create' called by two separate instances of mdadm
9602 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
9603 * devices that have since been assimilated via
9605 * In the event this update can not be carried out mdadm will
9606 * (FIX ME) notice that its update did not take hold.
9608 struct imsm_update_create_array
*u
= (void *) update
->buf
;
9609 struct intel_dev
*dv
;
9610 struct imsm_dev
*dev
;
9611 struct imsm_map
*map
, *new_map
;
9612 unsigned long long start
, end
;
9613 unsigned long long new_start
, new_end
;
9615 struct disk_info
*inf
;
9618 /* handle racing creates: first come first serve */
9619 if (u
->dev_idx
< mpb
->num_raid_devs
) {
9620 dprintf("subarray %d already defined\n", u
->dev_idx
);
9624 /* check update is next in sequence */
9625 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
9626 dprintf("can not create array %d expected index %d\n",
9627 u
->dev_idx
, mpb
->num_raid_devs
);
9631 new_map
= get_imsm_map(&u
->dev
, MAP_0
);
9632 new_start
= pba_of_lba0(new_map
);
9633 new_end
= new_start
+ blocks_per_member(new_map
);
9634 inf
= get_disk_info(u
);
9636 /* handle activate_spare versus create race:
9637 * check to make sure that overlapping arrays do not include
9640 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
9641 dev
= get_imsm_dev(super
, i
);
9642 map
= get_imsm_map(dev
, MAP_0
);
9643 start
= pba_of_lba0(map
);
9644 end
= start
+ blocks_per_member(map
);
9645 if ((new_start
>= start
&& new_start
<= end
) ||
9646 (start
>= new_start
&& start
<= new_end
))
9651 if (disks_overlap(super
, i
, u
)) {
9652 dprintf("arrays overlap\n");
9657 /* check that prepare update was successful */
9658 if (!update
->space
) {
9659 dprintf("prepare update failed\n");
9663 /* check that all disks are still active before committing
9664 * changes. FIXME: could we instead handle this by creating a
9665 * degraded array? That's probably not what the user expects,
9666 * so better to drop this update on the floor.
9668 for (i
= 0; i
< new_map
->num_members
; i
++) {
9669 dl
= serial_to_dl(inf
[i
].serial
, super
);
9671 dprintf("disk disappeared\n");
9676 super
->updates_pending
++;
9678 /* convert spares to members and fixup ord_tbl */
9679 for (i
= 0; i
< new_map
->num_members
; i
++) {
9680 dl
= serial_to_dl(inf
[i
].serial
, super
);
9681 if (dl
->index
== -1) {
9682 dl
->index
= mpb
->num_disks
;
9684 dl
->disk
.status
|= CONFIGURED_DISK
;
9685 dl
->disk
.status
&= ~SPARE_DISK
;
9687 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
9692 update
->space
= NULL
;
9693 imsm_copy_dev(dev
, &u
->dev
);
9694 dv
->index
= u
->dev_idx
;
9695 dv
->next
= super
->devlist
;
9696 super
->devlist
= dv
;
9697 mpb
->num_raid_devs
++;
9699 imsm_update_version_info(super
);
9702 /* mdmon knows how to release update->space, but not
9703 * ((struct intel_dev *) update->space)->dev
9705 if (update
->space
) {
9711 case update_kill_array
: {
9712 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
9713 int victim
= u
->dev_idx
;
9714 struct active_array
*a
;
9715 struct intel_dev
**dp
;
9716 struct imsm_dev
*dev
;
9718 /* sanity check that we are not affecting the uuid of
9719 * active arrays, or deleting an active array
9721 * FIXME when immutable ids are available, but note that
9722 * we'll also need to fixup the invalidated/active
9723 * subarray indexes in mdstat
9725 for (a
= st
->arrays
; a
; a
= a
->next
)
9726 if (a
->info
.container_member
>= victim
)
9728 /* by definition if mdmon is running at least one array
9729 * is active in the container, so checking
9730 * mpb->num_raid_devs is just extra paranoia
9732 dev
= get_imsm_dev(super
, victim
);
9733 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
9734 dprintf("failed to delete subarray-%d\n", victim
);
9738 for (dp
= &super
->devlist
; *dp
;)
9739 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
9742 if ((*dp
)->index
> (unsigned)victim
)
9746 mpb
->num_raid_devs
--;
9747 super
->updates_pending
++;
9750 case update_rename_array
: {
9751 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
9752 char name
[MAX_RAID_SERIAL_LEN
+1];
9753 int target
= u
->dev_idx
;
9754 struct active_array
*a
;
9755 struct imsm_dev
*dev
;
9757 /* sanity check that we are not affecting the uuid of
9760 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
9761 name
[MAX_RAID_SERIAL_LEN
] = '\0';
9762 for (a
= st
->arrays
; a
; a
= a
->next
)
9763 if (a
->info
.container_member
== target
)
9765 dev
= get_imsm_dev(super
, u
->dev_idx
);
9766 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
9767 dprintf("failed to rename subarray-%d\n", target
);
9771 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
9772 super
->updates_pending
++;
9775 case update_add_remove_disk
: {
9776 /* we may be able to repair some arrays if disks are
9777 * being added, check the status of add_remove_disk
9778 * if discs has been added.
9780 if (add_remove_disk_update(super
)) {
9781 struct active_array
*a
;
9783 super
->updates_pending
++;
9784 for (a
= st
->arrays
; a
; a
= a
->next
)
9785 a
->check_degraded
= 1;
9789 case update_prealloc_badblocks_mem
:
9791 case update_rwh_policy
: {
9792 struct imsm_update_rwh_policy
*u
= (void *)update
->buf
;
9793 int target
= u
->dev_idx
;
9794 struct imsm_dev
*dev
= get_imsm_dev(super
, target
);
9796 dprintf("could not find subarray-%d\n", target
);
9800 if (dev
->rwh_policy
!= u
->new_policy
) {
9801 dev
->rwh_policy
= u
->new_policy
;
9802 super
->updates_pending
++;
9807 pr_err("error: unsuported process update type:(type: %d)\n", type
);
9811 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
);
9813 static int imsm_prepare_update(struct supertype
*st
,
9814 struct metadata_update
*update
)
9817 * Allocate space to hold new disk entries, raid-device entries or a new
9818 * mpb if necessary. The manager synchronously waits for updates to
9819 * complete in the monitor, so new mpb buffers allocated here can be
9820 * integrated by the monitor thread without worrying about live pointers
9821 * in the manager thread.
9823 enum imsm_update_type type
;
9824 struct intel_super
*super
= st
->sb
;
9825 unsigned int sector_size
= super
->sector_size
;
9826 struct imsm_super
*mpb
= super
->anchor
;
9830 if (update
->len
< (int)sizeof(type
))
9833 type
= *(enum imsm_update_type
*) update
->buf
;
9836 case update_general_migration_checkpoint
:
9837 if (update
->len
< (int)sizeof(struct imsm_update_general_migration_checkpoint
))
9839 dprintf("called for update_general_migration_checkpoint\n");
9841 case update_takeover
: {
9842 struct imsm_update_takeover
*u
= (void *)update
->buf
;
9843 if (update
->len
< (int)sizeof(*u
))
9845 if (u
->direction
== R0_TO_R10
) {
9846 void **tail
= (void **)&update
->space_list
;
9847 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subarray
);
9848 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9849 int num_members
= map
->num_members
;
9852 /* allocate memory for added disks */
9853 for (i
= 0; i
< num_members
; i
++) {
9854 size
= sizeof(struct dl
);
9855 space
= xmalloc(size
);
9860 /* allocate memory for new device */
9861 size
= sizeof_imsm_dev(super
->devlist
->dev
, 0) +
9862 (num_members
* sizeof(__u32
));
9863 space
= xmalloc(size
);
9867 len
= disks_to_mpb_size(num_members
* 2);
9872 case update_reshape_container_disks
: {
9873 /* Every raid device in the container is about to
9874 * gain some more devices, and we will enter a
9876 * So each 'imsm_map' will be bigger, and the imsm_vol
9877 * will now hold 2 of them.
9878 * Thus we need new 'struct imsm_dev' allocations sized
9879 * as sizeof_imsm_dev but with more devices in both maps.
9881 struct imsm_update_reshape
*u
= (void *)update
->buf
;
9882 struct intel_dev
*dl
;
9883 void **space_tail
= (void**)&update
->space_list
;
9885 if (update
->len
< (int)sizeof(*u
))
9888 dprintf("for update_reshape\n");
9890 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
9891 int size
= sizeof_imsm_dev(dl
->dev
, 1);
9893 if (u
->new_raid_disks
> u
->old_raid_disks
)
9894 size
+= sizeof(__u32
)*2*
9895 (u
->new_raid_disks
- u
->old_raid_disks
);
9902 len
= disks_to_mpb_size(u
->new_raid_disks
);
9903 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
9906 case update_reshape_migration
: {
9907 /* for migration level 0->5 we need to add disks
9908 * so the same as for container operation we will copy
9909 * device to the bigger location.
9910 * in memory prepared device and new disk area are prepared
9911 * for usage in process update
9913 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
9914 struct intel_dev
*id
;
9915 void **space_tail
= (void **)&update
->space_list
;
9918 int current_level
= -1;
9920 if (update
->len
< (int)sizeof(*u
))
9923 dprintf("for update_reshape\n");
9925 /* add space for bigger array in update
9927 for (id
= super
->devlist
; id
; id
= id
->next
) {
9928 if (id
->index
== (unsigned)u
->subdev
) {
9929 size
= sizeof_imsm_dev(id
->dev
, 1);
9930 if (u
->new_raid_disks
> u
->old_raid_disks
)
9931 size
+= sizeof(__u32
)*2*
9932 (u
->new_raid_disks
- u
->old_raid_disks
);
9940 if (update
->space_list
== NULL
)
9943 /* add space for disk in update
9945 size
= sizeof(struct dl
);
9951 /* add spare device to update
9953 for (id
= super
->devlist
; id
; id
= id
->next
)
9954 if (id
->index
== (unsigned)u
->subdev
) {
9955 struct imsm_dev
*dev
;
9956 struct imsm_map
*map
;
9958 dev
= get_imsm_dev(super
, u
->subdev
);
9959 map
= get_imsm_map(dev
, MAP_0
);
9960 current_level
= map
->raid_level
;
9963 if (u
->new_level
== 5 && u
->new_level
!= current_level
) {
9964 struct mdinfo
*spares
;
9966 spares
= get_spares_for_grow(st
);
9974 makedev(dev
->disk
.major
,
9976 dl
= get_disk_super(super
,
9979 dl
->index
= u
->old_raid_disks
;
9985 len
= disks_to_mpb_size(u
->new_raid_disks
);
9986 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
9989 case update_size_change
: {
9990 if (update
->len
< (int)sizeof(struct imsm_update_size_change
))
9994 case update_activate_spare
: {
9995 if (update
->len
< (int)sizeof(struct imsm_update_activate_spare
))
9999 case update_create_array
: {
10000 struct imsm_update_create_array
*u
= (void *) update
->buf
;
10001 struct intel_dev
*dv
;
10002 struct imsm_dev
*dev
= &u
->dev
;
10003 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
10005 struct disk_info
*inf
;
10009 if (update
->len
< (int)sizeof(*u
))
10012 inf
= get_disk_info(u
);
10013 len
= sizeof_imsm_dev(dev
, 1);
10014 /* allocate a new super->devlist entry */
10015 dv
= xmalloc(sizeof(*dv
));
10016 dv
->dev
= xmalloc(len
);
10017 update
->space
= dv
;
10019 /* count how many spares will be converted to members */
10020 for (i
= 0; i
< map
->num_members
; i
++) {
10021 dl
= serial_to_dl(inf
[i
].serial
, super
);
10023 /* hmm maybe it failed?, nothing we can do about
10028 if (count_memberships(dl
, super
) == 0)
10031 len
+= activate
* sizeof(struct imsm_disk
);
10034 case update_kill_array
: {
10035 if (update
->len
< (int)sizeof(struct imsm_update_kill_array
))
10039 case update_rename_array
: {
10040 if (update
->len
< (int)sizeof(struct imsm_update_rename_array
))
10044 case update_add_remove_disk
:
10045 /* no update->len needed */
10047 case update_prealloc_badblocks_mem
:
10048 super
->extra_space
+= sizeof(struct bbm_log
) -
10049 get_imsm_bbm_log_size(super
->bbm_log
);
10051 case update_rwh_policy
: {
10052 if (update
->len
< (int)sizeof(struct imsm_update_rwh_policy
))
10060 /* check if we need a larger metadata buffer */
10061 if (super
->next_buf
)
10062 buf_len
= super
->next_len
;
10064 buf_len
= super
->len
;
10066 if (__le32_to_cpu(mpb
->mpb_size
) + super
->extra_space
+ len
> buf_len
) {
10067 /* ok we need a larger buf than what is currently allocated
10068 * if this allocation fails process_update will notice that
10069 * ->next_len is set and ->next_buf is NULL
10071 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) +
10072 super
->extra_space
+ len
, sector_size
);
10073 if (super
->next_buf
)
10074 free(super
->next_buf
);
10076 super
->next_len
= buf_len
;
10077 if (posix_memalign(&super
->next_buf
, sector_size
, buf_len
) == 0)
10078 memset(super
->next_buf
, 0, buf_len
);
10080 super
->next_buf
= NULL
;
10085 /* must be called while manager is quiesced */
10086 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
10088 struct imsm_super
*mpb
= super
->anchor
;
10090 struct imsm_dev
*dev
;
10091 struct imsm_map
*map
;
10092 unsigned int i
, j
, num_members
;
10093 __u32 ord
, ord_map0
;
10094 struct bbm_log
*log
= super
->bbm_log
;
10096 dprintf("deleting device[%d] from imsm_super\n", index
);
10098 /* shift all indexes down one */
10099 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
10100 if (iter
->index
> (int)index
)
10102 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
10103 if (iter
->index
> (int)index
)
10106 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
10107 dev
= get_imsm_dev(super
, i
);
10108 map
= get_imsm_map(dev
, MAP_0
);
10109 num_members
= map
->num_members
;
10110 for (j
= 0; j
< num_members
; j
++) {
10111 /* update ord entries being careful not to propagate
10112 * ord-flags to the first map
10114 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_X
);
10115 ord_map0
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
10117 if (ord_to_idx(ord
) <= index
)
10120 map
= get_imsm_map(dev
, MAP_0
);
10121 set_imsm_ord_tbl_ent(map
, j
, ord_map0
- 1);
10122 map
= get_imsm_map(dev
, MAP_1
);
10124 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
10128 for (i
= 0; i
< log
->entry_count
; i
++) {
10129 struct bbm_log_entry
*entry
= &log
->marked_block_entries
[i
];
10131 if (entry
->disk_ordinal
<= index
)
10133 entry
->disk_ordinal
--;
10137 super
->updates_pending
++;
10139 struct dl
*dl
= *dlp
;
10141 *dlp
= (*dlp
)->next
;
10142 __free_imsm_disk(dl
);
10146 static void close_targets(int *targets
, int new_disks
)
10153 for (i
= 0; i
< new_disks
; i
++) {
10154 if (targets
[i
] >= 0) {
10161 static int imsm_get_allowed_degradation(int level
, int raid_disks
,
10162 struct intel_super
*super
,
10163 struct imsm_dev
*dev
)
10169 struct imsm_map
*map
;
10172 ret_val
= raid_disks
/2;
10173 /* check map if all disks pairs not failed
10176 map
= get_imsm_map(dev
, MAP_0
);
10177 for (i
= 0; i
< ret_val
; i
++) {
10178 int degradation
= 0;
10179 if (get_imsm_disk(super
, i
) == NULL
)
10181 if (get_imsm_disk(super
, i
+ 1) == NULL
)
10183 if (degradation
== 2)
10186 map
= get_imsm_map(dev
, MAP_1
);
10187 /* if there is no second map
10188 * result can be returned
10192 /* check degradation in second map
10194 for (i
= 0; i
< ret_val
; i
++) {
10195 int degradation
= 0;
10196 if (get_imsm_disk(super
, i
) == NULL
)
10198 if (get_imsm_disk(super
, i
+ 1) == NULL
)
10200 if (degradation
== 2)
10214 /*******************************************************************************
10215 * Function: open_backup_targets
10216 * Description: Function opens file descriptors for all devices given in
10219 * info : general array info
10220 * raid_disks : number of disks
10221 * raid_fds : table of device's file descriptors
10222 * super : intel super for raid10 degradation check
10223 * dev : intel device for raid10 degradation check
10227 ******************************************************************************/
10228 int open_backup_targets(struct mdinfo
*info
, int raid_disks
, int *raid_fds
,
10229 struct intel_super
*super
, struct imsm_dev
*dev
)
10235 for (i
= 0; i
< raid_disks
; i
++)
10238 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
10241 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
)) {
10242 dprintf("disk is faulty!!\n");
10246 if (sd
->disk
.raid_disk
>= raid_disks
|| sd
->disk
.raid_disk
< 0)
10249 dn
= map_dev(sd
->disk
.major
,
10250 sd
->disk
.minor
, 1);
10251 raid_fds
[sd
->disk
.raid_disk
] = dev_open(dn
, O_RDWR
);
10252 if (raid_fds
[sd
->disk
.raid_disk
] < 0) {
10253 pr_err("cannot open component\n");
10258 /* check if maximum array degradation level is not exceeded
10260 if ((raid_disks
- opened
) >
10261 imsm_get_allowed_degradation(info
->new_level
, raid_disks
,
10263 pr_err("Not enough disks can be opened.\n");
10264 close_targets(raid_fds
, raid_disks
);
10270 /*******************************************************************************
10271 * Function: validate_container_imsm
10272 * Description: This routine validates container after assemble,
10273 * eg. if devices in container are under the same controller.
10276 * info : linked list with info about devices used in array
10280 ******************************************************************************/
10281 int validate_container_imsm(struct mdinfo
*info
)
10283 if (check_env("IMSM_NO_PLATFORM"))
10286 struct sys_dev
*idev
;
10287 struct sys_dev
*hba
= NULL
;
10288 struct sys_dev
*intel_devices
= find_intel_devices();
10289 char *dev_path
= devt_to_devpath(makedev(info
->disk
.major
,
10290 info
->disk
.minor
));
10292 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
10293 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
10302 pr_err("WARNING - Cannot detect HBA for device %s!\n",
10303 devid2kname(makedev(info
->disk
.major
, info
->disk
.minor
)));
10307 const struct imsm_orom
*orom
= get_orom_by_device_id(hba
->dev_id
);
10308 struct mdinfo
*dev
;
10310 for (dev
= info
->next
; dev
; dev
= dev
->next
) {
10311 dev_path
= devt_to_devpath(makedev(dev
->disk
.major
, dev
->disk
.minor
));
10313 struct sys_dev
*hba2
= NULL
;
10314 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
10315 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
10323 const struct imsm_orom
*orom2
= hba2
== NULL
? NULL
:
10324 get_orom_by_device_id(hba2
->dev_id
);
10326 if (hba2
&& hba
->type
!= hba2
->type
) {
10327 pr_err("WARNING - HBAs of devices do not match %s != %s\n",
10328 get_sys_dev_type(hba
->type
), get_sys_dev_type(hba2
->type
));
10332 if (orom
!= orom2
) {
10333 pr_err("WARNING - IMSM container assembled with disks under different HBAs!\n"
10334 " This operation is not supported and can lead to data loss.\n");
10339 pr_err("WARNING - IMSM container assembled with disks under HBAs without IMSM platform support!\n"
10340 " This operation is not supported and can lead to data loss.\n");
10348 /*******************************************************************************
10349 * Function: imsm_record_badblock
10350 * Description: This routine stores new bad block record in BBM log
10353 * a : array containing a bad block
10354 * slot : disk number containing a bad block
10355 * sector : bad block sector
10356 * length : bad block sectors range
10360 ******************************************************************************/
10361 static int imsm_record_badblock(struct active_array
*a
, int slot
,
10362 unsigned long long sector
, int length
)
10364 struct intel_super
*super
= a
->container
->sb
;
10368 ord
= imsm_disk_slot_to_ord(a
, slot
);
10372 ret
= record_new_badblock(super
->bbm_log
, ord_to_idx(ord
), sector
,
10375 super
->updates_pending
++;
10379 /*******************************************************************************
10380 * Function: imsm_clear_badblock
10381 * Description: This routine clears bad block record from BBM log
10384 * a : array containing a bad block
10385 * slot : disk number containing a bad block
10386 * sector : bad block sector
10387 * length : bad block sectors range
10391 ******************************************************************************/
10392 static int imsm_clear_badblock(struct active_array
*a
, int slot
,
10393 unsigned long long sector
, int length
)
10395 struct intel_super
*super
= a
->container
->sb
;
10399 ord
= imsm_disk_slot_to_ord(a
, slot
);
10403 ret
= clear_badblock(super
->bbm_log
, ord_to_idx(ord
), sector
, length
);
10405 super
->updates_pending
++;
10409 /*******************************************************************************
10410 * Function: imsm_get_badblocks
10411 * Description: This routine get list of bad blocks for an array
10415 * slot : disk number
10417 * bb : structure containing bad blocks
10419 ******************************************************************************/
10420 static struct md_bb
*imsm_get_badblocks(struct active_array
*a
, int slot
)
10422 int inst
= a
->info
.container_member
;
10423 struct intel_super
*super
= a
->container
->sb
;
10424 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
10425 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
10428 ord
= imsm_disk_slot_to_ord(a
, slot
);
10432 get_volume_badblocks(super
->bbm_log
, ord_to_idx(ord
), pba_of_lba0(map
),
10433 blocks_per_member(map
), &super
->bb
);
10437 /*******************************************************************************
10438 * Function: examine_badblocks_imsm
10439 * Description: Prints list of bad blocks on a disk to the standard output
10442 * st : metadata handler
10443 * fd : open file descriptor for device
10444 * devname : device name
10448 ******************************************************************************/
10449 static int examine_badblocks_imsm(struct supertype
*st
, int fd
, char *devname
)
10451 struct intel_super
*super
= st
->sb
;
10452 struct bbm_log
*log
= super
->bbm_log
;
10453 struct dl
*d
= NULL
;
10456 for (d
= super
->disks
; d
; d
= d
->next
) {
10457 if (strcmp(d
->devname
, devname
) == 0)
10461 if ((d
== NULL
) || (d
->index
< 0)) { /* serial mismatch probably */
10462 pr_err("%s doesn't appear to be part of a raid array\n",
10469 struct bbm_log_entry
*entry
= &log
->marked_block_entries
[0];
10471 for (i
= 0; i
< log
->entry_count
; i
++) {
10472 if (entry
[i
].disk_ordinal
== d
->index
) {
10473 unsigned long long sector
= __le48_to_cpu(
10474 &entry
[i
].defective_block_start
);
10475 int cnt
= entry
[i
].marked_count
+ 1;
10478 printf("Bad-blocks on %s:\n", devname
);
10482 printf("%20llu for %d sectors\n", sector
, cnt
);
10488 printf("No bad-blocks list configured on %s\n", devname
);
10492 /*******************************************************************************
10493 * Function: init_migr_record_imsm
10494 * Description: Function inits imsm migration record
10496 * super : imsm internal array info
10497 * dev : device under migration
10498 * info : general array info to find the smallest device
10501 ******************************************************************************/
10502 void init_migr_record_imsm(struct supertype
*st
, struct imsm_dev
*dev
,
10503 struct mdinfo
*info
)
10505 struct intel_super
*super
= st
->sb
;
10506 struct migr_record
*migr_rec
= super
->migr_rec
;
10507 int new_data_disks
;
10508 unsigned long long dsize
, dev_sectors
;
10509 long long unsigned min_dev_sectors
= -1LLU;
10513 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
10514 struct imsm_map
*map_src
= get_imsm_map(dev
, MAP_1
);
10515 unsigned long long num_migr_units
;
10516 unsigned long long array_blocks
;
10518 memset(migr_rec
, 0, sizeof(struct migr_record
));
10519 migr_rec
->family_num
= __cpu_to_le32(super
->anchor
->family_num
);
10521 /* only ascending reshape supported now */
10522 migr_rec
->ascending_migr
= __cpu_to_le32(1);
10524 migr_rec
->dest_depth_per_unit
= GEN_MIGR_AREA_SIZE
/
10525 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
10526 migr_rec
->dest_depth_per_unit
*=
10527 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
10528 new_data_disks
= imsm_num_data_members(dev
, MAP_0
);
10529 migr_rec
->blocks_per_unit
=
10530 __cpu_to_le32(migr_rec
->dest_depth_per_unit
* new_data_disks
);
10531 migr_rec
->dest_depth_per_unit
=
10532 __cpu_to_le32(migr_rec
->dest_depth_per_unit
);
10533 array_blocks
= info
->component_size
* new_data_disks
;
10535 array_blocks
/ __le32_to_cpu(migr_rec
->blocks_per_unit
);
10537 if (array_blocks
% __le32_to_cpu(migr_rec
->blocks_per_unit
))
10539 migr_rec
->num_migr_units
= __cpu_to_le32(num_migr_units
);
10541 migr_rec
->post_migr_vol_cap
= dev
->size_low
;
10542 migr_rec
->post_migr_vol_cap_hi
= dev
->size_high
;
10544 /* Find the smallest dev */
10545 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
10546 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
10547 fd
= dev_open(nm
, O_RDONLY
);
10550 get_dev_size(fd
, NULL
, &dsize
);
10551 dev_sectors
= dsize
/ 512;
10552 if (dev_sectors
< min_dev_sectors
)
10553 min_dev_sectors
= dev_sectors
;
10556 migr_rec
->ckpt_area_pba
= __cpu_to_le32(min_dev_sectors
-
10557 RAID_DISK_RESERVED_BLOCKS_IMSM_HI
);
10559 write_imsm_migr_rec(st
);
10564 /*******************************************************************************
10565 * Function: save_backup_imsm
10566 * Description: Function saves critical data stripes to Migration Copy Area
10567 * and updates the current migration unit status.
10568 * Use restore_stripes() to form a destination stripe,
10569 * and to write it to the Copy Area.
10571 * st : supertype information
10572 * dev : imsm device that backup is saved for
10573 * info : general array info
10574 * buf : input buffer
10575 * length : length of data to backup (blocks_per_unit)
10579 ******************************************************************************/
10580 int save_backup_imsm(struct supertype
*st
,
10581 struct imsm_dev
*dev
,
10582 struct mdinfo
*info
,
10587 struct intel_super
*super
= st
->sb
;
10588 unsigned long long *target_offsets
;
10591 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
10592 int new_disks
= map_dest
->num_members
;
10593 int dest_layout
= 0;
10595 unsigned long long start
;
10596 int data_disks
= imsm_num_data_members(dev
, MAP_0
);
10598 targets
= xmalloc(new_disks
* sizeof(int));
10600 for (i
= 0; i
< new_disks
; i
++)
10603 target_offsets
= xcalloc(new_disks
, sizeof(unsigned long long));
10605 start
= info
->reshape_progress
* 512;
10606 for (i
= 0; i
< new_disks
; i
++) {
10607 target_offsets
[i
] = (unsigned long long)
10608 __le32_to_cpu(super
->migr_rec
->ckpt_area_pba
) * 512;
10609 /* move back copy area adderss, it will be moved forward
10610 * in restore_stripes() using start input variable
10612 target_offsets
[i
] -= start
/data_disks
;
10615 if (open_backup_targets(info
, new_disks
, targets
,
10619 dest_layout
= imsm_level_to_layout(map_dest
->raid_level
);
10620 dest_chunk
= __le16_to_cpu(map_dest
->blocks_per_strip
) * 512;
10622 if (restore_stripes(targets
, /* list of dest devices */
10623 target_offsets
, /* migration record offsets */
10626 map_dest
->raid_level
,
10628 -1, /* source backup file descriptor */
10629 0, /* input buf offset
10630 * always 0 buf is already offseted */
10634 pr_err("Error restoring stripes\n");
10642 close_targets(targets
, new_disks
);
10645 free(target_offsets
);
10650 /*******************************************************************************
10651 * Function: save_checkpoint_imsm
10652 * Description: Function called for current unit status update
10653 * in the migration record. It writes it to disk.
10655 * super : imsm internal array info
10656 * info : general array info
10660 * 2: failure, means no valid migration record
10661 * / no general migration in progress /
10662 ******************************************************************************/
10663 int save_checkpoint_imsm(struct supertype
*st
, struct mdinfo
*info
, int state
)
10665 struct intel_super
*super
= st
->sb
;
10666 unsigned long long blocks_per_unit
;
10667 unsigned long long curr_migr_unit
;
10669 if (load_imsm_migr_rec(super
, info
) != 0) {
10670 dprintf("imsm: ERROR: Cannot read migration record for checkpoint save.\n");
10674 blocks_per_unit
= __le32_to_cpu(super
->migr_rec
->blocks_per_unit
);
10675 if (blocks_per_unit
== 0) {
10676 dprintf("imsm: no migration in progress.\n");
10679 curr_migr_unit
= info
->reshape_progress
/ blocks_per_unit
;
10680 /* check if array is alligned to copy area
10681 * if it is not alligned, add one to current migration unit value
10682 * this can happend on array reshape finish only
10684 if (info
->reshape_progress
% blocks_per_unit
)
10687 super
->migr_rec
->curr_migr_unit
=
10688 __cpu_to_le32(curr_migr_unit
);
10689 super
->migr_rec
->rec_status
= __cpu_to_le32(state
);
10690 super
->migr_rec
->dest_1st_member_lba
=
10691 __cpu_to_le32(curr_migr_unit
*
10692 __le32_to_cpu(super
->migr_rec
->dest_depth_per_unit
));
10693 if (write_imsm_migr_rec(st
) < 0) {
10694 dprintf("imsm: Cannot write migration record outside backup area\n");
10701 /*******************************************************************************
10702 * Function: recover_backup_imsm
10703 * Description: Function recovers critical data from the Migration Copy Area
10704 * while assembling an array.
10706 * super : imsm internal array info
10707 * info : general array info
10709 * 0 : success (or there is no data to recover)
10711 ******************************************************************************/
10712 int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
)
10714 struct intel_super
*super
= st
->sb
;
10715 struct migr_record
*migr_rec
= super
->migr_rec
;
10716 struct imsm_map
*map_dest
;
10717 struct intel_dev
*id
= NULL
;
10718 unsigned long long read_offset
;
10719 unsigned long long write_offset
;
10721 int *targets
= NULL
;
10722 int new_disks
, i
, err
;
10725 unsigned int sector_size
= super
->sector_size
;
10726 unsigned long curr_migr_unit
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
10727 unsigned long num_migr_units
= __le32_to_cpu(migr_rec
->num_migr_units
);
10729 int skipped_disks
= 0;
10731 err
= sysfs_get_str(info
, NULL
, "array_state", (char *)buffer
, 20);
10735 /* recover data only during assemblation */
10736 if (strncmp(buffer
, "inactive", 8) != 0)
10738 /* no data to recover */
10739 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
10741 if (curr_migr_unit
>= num_migr_units
)
10744 /* find device during reshape */
10745 for (id
= super
->devlist
; id
; id
= id
->next
)
10746 if (is_gen_migration(id
->dev
))
10751 map_dest
= get_imsm_map(id
->dev
, MAP_0
);
10752 new_disks
= map_dest
->num_members
;
10754 read_offset
= (unsigned long long)
10755 __le32_to_cpu(migr_rec
->ckpt_area_pba
) * 512;
10757 write_offset
= ((unsigned long long)
10758 __le32_to_cpu(migr_rec
->dest_1st_member_lba
) +
10759 pba_of_lba0(map_dest
)) * 512;
10761 unit_len
= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
10762 if (posix_memalign((void **)&buf
, sector_size
, unit_len
) != 0)
10764 targets
= xcalloc(new_disks
, sizeof(int));
10766 if (open_backup_targets(info
, new_disks
, targets
, super
, id
->dev
)) {
10767 pr_err("Cannot open some devices belonging to array.\n");
10771 for (i
= 0; i
< new_disks
; i
++) {
10772 if (targets
[i
] < 0) {
10776 if (lseek64(targets
[i
], read_offset
, SEEK_SET
) < 0) {
10777 pr_err("Cannot seek to block: %s\n",
10782 if ((unsigned)read(targets
[i
], buf
, unit_len
) != unit_len
) {
10783 pr_err("Cannot read copy area block: %s\n",
10788 if (lseek64(targets
[i
], write_offset
, SEEK_SET
) < 0) {
10789 pr_err("Cannot seek to block: %s\n",
10794 if ((unsigned)write(targets
[i
], buf
, unit_len
) != unit_len
) {
10795 pr_err("Cannot restore block: %s\n",
10802 if (skipped_disks
> imsm_get_allowed_degradation(info
->new_level
,
10806 pr_err("Cannot restore data from backup. Too many failed disks\n");
10810 if (save_checkpoint_imsm(st
, info
, UNIT_SRC_NORMAL
)) {
10811 /* ignore error == 2, this can mean end of reshape here
10813 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL) during restart\n");
10819 for (i
= 0; i
< new_disks
; i
++)
10828 static char disk_by_path
[] = "/dev/disk/by-path/";
10830 static const char *imsm_get_disk_controller_domain(const char *path
)
10832 char disk_path
[PATH_MAX
];
10836 strcpy(disk_path
, disk_by_path
);
10837 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
10838 if (stat(disk_path
, &st
) == 0) {
10839 struct sys_dev
* hba
;
10842 path
= devt_to_devpath(st
.st_rdev
);
10845 hba
= find_disk_attached_hba(-1, path
);
10846 if (hba
&& hba
->type
== SYS_DEV_SAS
)
10848 else if (hba
&& hba
->type
== SYS_DEV_SATA
)
10850 else if (hba
&& hba
->type
== SYS_DEV_VMD
)
10852 else if (hba
&& hba
->type
== SYS_DEV_NVME
)
10856 dprintf("path: %s hba: %s attached: %s\n",
10857 path
, (hba
) ? hba
->path
: "NULL", drv
);
10863 static char *imsm_find_array_devnm_by_subdev(int subdev
, char *container
)
10865 static char devnm
[32];
10866 char subdev_name
[20];
10867 struct mdstat_ent
*mdstat
;
10869 sprintf(subdev_name
, "%d", subdev
);
10870 mdstat
= mdstat_by_subdev(subdev_name
, container
);
10874 strcpy(devnm
, mdstat
->devnm
);
10875 free_mdstat(mdstat
);
10879 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
10880 struct geo_params
*geo
,
10881 int *old_raid_disks
,
10884 /* currently we only support increasing the number of devices
10885 * for a container. This increases the number of device for each
10886 * member array. They must all be RAID0 or RAID5.
10889 struct mdinfo
*info
, *member
;
10890 int devices_that_can_grow
= 0;
10892 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): st->devnm = (%s)\n", st
->devnm
);
10894 if (geo
->size
> 0 ||
10895 geo
->level
!= UnSet
||
10896 geo
->layout
!= UnSet
||
10897 geo
->chunksize
!= 0 ||
10898 geo
->raid_disks
== UnSet
) {
10899 dprintf("imsm: Container operation is allowed for raid disks number change only.\n");
10903 if (direction
== ROLLBACK_METADATA_CHANGES
) {
10904 dprintf("imsm: Metadata changes rollback is not supported for container operation.\n");
10908 info
= container_content_imsm(st
, NULL
);
10909 for (member
= info
; member
; member
= member
->next
) {
10912 dprintf("imsm: checking device_num: %i\n",
10913 member
->container_member
);
10915 if (geo
->raid_disks
<= member
->array
.raid_disks
) {
10916 /* we work on container for Online Capacity Expansion
10917 * only so raid_disks has to grow
10919 dprintf("imsm: for container operation raid disks increase is required\n");
10923 if (info
->array
.level
!= 0 && info
->array
.level
!= 5) {
10924 /* we cannot use this container with other raid level
10926 dprintf("imsm: for container operation wrong raid level (%i) detected\n",
10927 info
->array
.level
);
10930 /* check for platform support
10931 * for this raid level configuration
10933 struct intel_super
*super
= st
->sb
;
10934 if (!is_raid_level_supported(super
->orom
,
10935 member
->array
.level
,
10936 geo
->raid_disks
)) {
10937 dprintf("platform does not support raid%d with %d disk%s\n",
10940 geo
->raid_disks
> 1 ? "s" : "");
10943 /* check if component size is aligned to chunk size
10945 if (info
->component_size
%
10946 (info
->array
.chunk_size
/512)) {
10947 dprintf("Component size is not aligned to chunk size\n");
10952 if (*old_raid_disks
&&
10953 info
->array
.raid_disks
!= *old_raid_disks
)
10955 *old_raid_disks
= info
->array
.raid_disks
;
10957 /* All raid5 and raid0 volumes in container
10958 * have to be ready for Online Capacity Expansion
10959 * so they need to be assembled. We have already
10960 * checked that no recovery etc is happening.
10962 result
= imsm_find_array_devnm_by_subdev(member
->container_member
,
10963 st
->container_devnm
);
10964 if (result
== NULL
) {
10965 dprintf("imsm: cannot find array\n");
10968 devices_that_can_grow
++;
10971 if (!member
&& devices_that_can_grow
)
10975 dprintf("Container operation allowed\n");
10977 dprintf("Error: %i\n", ret_val
);
10982 /* Function: get_spares_for_grow
10983 * Description: Allocates memory and creates list of spare devices
10984 * avaliable in container. Checks if spare drive size is acceptable.
10985 * Parameters: Pointer to the supertype structure
10986 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
10989 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
10991 struct spare_criteria sc
;
10993 get_spare_criteria_imsm(st
, &sc
);
10994 return container_choose_spares(st
, &sc
, NULL
, NULL
, NULL
, 0);
10997 /******************************************************************************
10998 * function: imsm_create_metadata_update_for_reshape
10999 * Function creates update for whole IMSM container.
11001 ******************************************************************************/
11002 static int imsm_create_metadata_update_for_reshape(
11003 struct supertype
*st
,
11004 struct geo_params
*geo
,
11005 int old_raid_disks
,
11006 struct imsm_update_reshape
**updatep
)
11008 struct intel_super
*super
= st
->sb
;
11009 struct imsm_super
*mpb
= super
->anchor
;
11010 int update_memory_size
;
11011 struct imsm_update_reshape
*u
;
11012 struct mdinfo
*spares
;
11015 struct mdinfo
*dev
;
11017 dprintf("(enter) raid_disks = %i\n", geo
->raid_disks
);
11019 delta_disks
= geo
->raid_disks
- old_raid_disks
;
11021 /* size of all update data without anchor */
11022 update_memory_size
= sizeof(struct imsm_update_reshape
);
11024 /* now add space for spare disks that we need to add. */
11025 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
11027 u
= xcalloc(1, update_memory_size
);
11028 u
->type
= update_reshape_container_disks
;
11029 u
->old_raid_disks
= old_raid_disks
;
11030 u
->new_raid_disks
= geo
->raid_disks
;
11032 /* now get spare disks list
11034 spares
= get_spares_for_grow(st
);
11036 if (spares
== NULL
|| delta_disks
> spares
->array
.spare_disks
) {
11037 pr_err("imsm: ERROR: Cannot get spare devices for %s.\n", geo
->dev_name
);
11042 /* we have got spares
11043 * update disk list in imsm_disk list table in anchor
11045 dprintf("imsm: %i spares are available.\n\n",
11046 spares
->array
.spare_disks
);
11048 dev
= spares
->devs
;
11049 for (i
= 0; i
< delta_disks
; i
++) {
11054 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
11056 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
11057 dl
->index
= mpb
->num_disks
;
11065 sysfs_free(spares
);
11067 dprintf("imsm: reshape update preparation :");
11068 if (i
== delta_disks
) {
11069 dprintf_cont(" OK\n");
11071 return update_memory_size
;
11074 dprintf_cont(" Error\n");
11079 /******************************************************************************
11080 * function: imsm_create_metadata_update_for_size_change()
11081 * Creates update for IMSM array for array size change.
11083 ******************************************************************************/
11084 static int imsm_create_metadata_update_for_size_change(
11085 struct supertype
*st
,
11086 struct geo_params
*geo
,
11087 struct imsm_update_size_change
**updatep
)
11089 struct intel_super
*super
= st
->sb
;
11090 int update_memory_size
;
11091 struct imsm_update_size_change
*u
;
11093 dprintf("(enter) New size = %llu\n", geo
->size
);
11095 /* size of all update data without anchor */
11096 update_memory_size
= sizeof(struct imsm_update_size_change
);
11098 u
= xcalloc(1, update_memory_size
);
11099 u
->type
= update_size_change
;
11100 u
->subdev
= super
->current_vol
;
11101 u
->new_size
= geo
->size
;
11103 dprintf("imsm: reshape update preparation : OK\n");
11106 return update_memory_size
;
11109 /******************************************************************************
11110 * function: imsm_create_metadata_update_for_migration()
11111 * Creates update for IMSM array.
11113 ******************************************************************************/
11114 static int imsm_create_metadata_update_for_migration(
11115 struct supertype
*st
,
11116 struct geo_params
*geo
,
11117 struct imsm_update_reshape_migration
**updatep
)
11119 struct intel_super
*super
= st
->sb
;
11120 int update_memory_size
;
11121 struct imsm_update_reshape_migration
*u
;
11122 struct imsm_dev
*dev
;
11123 int previous_level
= -1;
11125 dprintf("(enter) New Level = %i\n", geo
->level
);
11127 /* size of all update data without anchor */
11128 update_memory_size
= sizeof(struct imsm_update_reshape_migration
);
11130 u
= xcalloc(1, update_memory_size
);
11131 u
->type
= update_reshape_migration
;
11132 u
->subdev
= super
->current_vol
;
11133 u
->new_level
= geo
->level
;
11134 u
->new_layout
= geo
->layout
;
11135 u
->new_raid_disks
= u
->old_raid_disks
= geo
->raid_disks
;
11136 u
->new_disks
[0] = -1;
11137 u
->new_chunksize
= -1;
11139 dev
= get_imsm_dev(super
, u
->subdev
);
11141 struct imsm_map
*map
;
11143 map
= get_imsm_map(dev
, MAP_0
);
11145 int current_chunk_size
=
11146 __le16_to_cpu(map
->blocks_per_strip
) / 2;
11148 if (geo
->chunksize
!= current_chunk_size
) {
11149 u
->new_chunksize
= geo
->chunksize
/ 1024;
11150 dprintf("imsm: chunk size change from %i to %i\n",
11151 current_chunk_size
, u
->new_chunksize
);
11153 previous_level
= map
->raid_level
;
11156 if (geo
->level
== 5 && previous_level
== 0) {
11157 struct mdinfo
*spares
= NULL
;
11159 u
->new_raid_disks
++;
11160 spares
= get_spares_for_grow(st
);
11161 if (spares
== NULL
|| spares
->array
.spare_disks
< 1) {
11163 sysfs_free(spares
);
11164 update_memory_size
= 0;
11165 pr_err("cannot get spare device for requested migration\n");
11168 sysfs_free(spares
);
11170 dprintf("imsm: reshape update preparation : OK\n");
11173 return update_memory_size
;
11176 static void imsm_update_metadata_locally(struct supertype
*st
,
11177 void *buf
, int len
)
11179 struct metadata_update mu
;
11184 mu
.space_list
= NULL
;
11186 if (imsm_prepare_update(st
, &mu
))
11187 imsm_process_update(st
, &mu
);
11189 while (mu
.space_list
) {
11190 void **space
= mu
.space_list
;
11191 mu
.space_list
= *space
;
11196 /***************************************************************************
11197 * Function: imsm_analyze_change
11198 * Description: Function analyze change for single volume
11199 * and validate if transition is supported
11200 * Parameters: Geometry parameters, supertype structure,
11201 * metadata change direction (apply/rollback)
11202 * Returns: Operation type code on success, -1 if fail
11203 ****************************************************************************/
11204 enum imsm_reshape_type
imsm_analyze_change(struct supertype
*st
,
11205 struct geo_params
*geo
,
11208 struct mdinfo info
;
11210 int check_devs
= 0;
11212 /* number of added/removed disks in operation result */
11213 int devNumChange
= 0;
11214 /* imsm compatible layout value for array geometry verification */
11215 int imsm_layout
= -1;
11217 struct imsm_dev
*dev
;
11218 struct intel_super
*super
;
11219 unsigned long long current_size
;
11220 unsigned long long free_size
;
11221 unsigned long long max_size
;
11224 getinfo_super_imsm_volume(st
, &info
, NULL
);
11225 if (geo
->level
!= info
.array
.level
&& geo
->level
>= 0 &&
11226 geo
->level
!= UnSet
) {
11227 switch (info
.array
.level
) {
11229 if (geo
->level
== 5) {
11230 change
= CH_MIGRATION
;
11231 if (geo
->layout
!= ALGORITHM_LEFT_ASYMMETRIC
) {
11232 pr_err("Error. Requested Layout not supported (left-asymmetric layout is supported only)!\n");
11234 goto analyse_change_exit
;
11236 imsm_layout
= geo
->layout
;
11238 devNumChange
= 1; /* parity disk added */
11239 } else if (geo
->level
== 10) {
11240 change
= CH_TAKEOVER
;
11242 devNumChange
= 2; /* two mirrors added */
11243 imsm_layout
= 0x102; /* imsm supported layout */
11248 if (geo
->level
== 0) {
11249 change
= CH_TAKEOVER
;
11251 devNumChange
= -(geo
->raid_disks
/2);
11252 imsm_layout
= 0; /* imsm raid0 layout */
11256 if (change
== -1) {
11257 pr_err("Error. Level Migration from %d to %d not supported!\n",
11258 info
.array
.level
, geo
->level
);
11259 goto analyse_change_exit
;
11262 geo
->level
= info
.array
.level
;
11264 if (geo
->layout
!= info
.array
.layout
&&
11265 (geo
->layout
!= UnSet
&& geo
->layout
!= -1)) {
11266 change
= CH_MIGRATION
;
11267 if (info
.array
.layout
== 0 && info
.array
.level
== 5 &&
11268 geo
->layout
== 5) {
11269 /* reshape 5 -> 4 */
11270 } else if (info
.array
.layout
== 5 && info
.array
.level
== 5 &&
11271 geo
->layout
== 0) {
11272 /* reshape 4 -> 5 */
11276 pr_err("Error. Layout Migration from %d to %d not supported!\n",
11277 info
.array
.layout
, geo
->layout
);
11279 goto analyse_change_exit
;
11282 geo
->layout
= info
.array
.layout
;
11283 if (imsm_layout
== -1)
11284 imsm_layout
= info
.array
.layout
;
11287 if (geo
->chunksize
> 0 && geo
->chunksize
!= UnSet
&&
11288 geo
->chunksize
!= info
.array
.chunk_size
) {
11289 if (info
.array
.level
== 10) {
11290 pr_err("Error. Chunk size change for RAID 10 is not supported.\n");
11292 goto analyse_change_exit
;
11293 } else if (info
.component_size
% (geo
->chunksize
/512)) {
11294 pr_err("New chunk size (%dK) does not evenly divide device size (%lluk). Aborting...\n",
11295 geo
->chunksize
/1024, info
.component_size
/2);
11297 goto analyse_change_exit
;
11299 change
= CH_MIGRATION
;
11301 geo
->chunksize
= info
.array
.chunk_size
;
11304 chunk
= geo
->chunksize
/ 1024;
11307 dev
= get_imsm_dev(super
, super
->current_vol
);
11308 data_disks
= imsm_num_data_members(dev
, MAP_0
);
11309 /* compute current size per disk member
11311 current_size
= info
.custom_array_size
/ data_disks
;
11313 if (geo
->size
> 0 && geo
->size
!= MAX_SIZE
) {
11314 /* align component size
11316 geo
->size
= imsm_component_size_aligment_check(
11317 get_imsm_raid_level(dev
->vol
.map
),
11318 chunk
* 1024, super
->sector_size
,
11320 if (geo
->size
== 0) {
11321 pr_err("Error. Size expansion is supported only (current size is %llu, requested size /rounded/ is 0).\n",
11323 goto analyse_change_exit
;
11327 if (current_size
!= geo
->size
&& geo
->size
> 0) {
11328 if (change
!= -1) {
11329 pr_err("Error. Size change should be the only one at a time.\n");
11331 goto analyse_change_exit
;
11333 if ((super
->current_vol
+ 1) != super
->anchor
->num_raid_devs
) {
11334 pr_err("Error. The last volume in container can be expanded only (%i/%s).\n",
11335 super
->current_vol
, st
->devnm
);
11336 goto analyse_change_exit
;
11338 /* check the maximum available size
11340 rv
= imsm_get_free_size(st
, dev
->vol
.map
->num_members
,
11341 0, chunk
, &free_size
);
11343 /* Cannot find maximum available space
11347 max_size
= free_size
+ current_size
;
11348 /* align component size
11350 max_size
= imsm_component_size_aligment_check(
11351 get_imsm_raid_level(dev
->vol
.map
),
11352 chunk
* 1024, super
->sector_size
,
11355 if (geo
->size
== MAX_SIZE
) {
11356 /* requested size change to the maximum available size
11358 if (max_size
== 0) {
11359 pr_err("Error. Cannot find maximum available space.\n");
11361 goto analyse_change_exit
;
11363 geo
->size
= max_size
;
11366 if (direction
== ROLLBACK_METADATA_CHANGES
) {
11367 /* accept size for rollback only
11370 /* round size due to metadata compatibility
11372 geo
->size
= (geo
->size
>> SECT_PER_MB_SHIFT
)
11373 << SECT_PER_MB_SHIFT
;
11374 dprintf("Prepare update for size change to %llu\n",
11376 if (current_size
>= geo
->size
) {
11377 pr_err("Error. Size expansion is supported only (current size is %llu, requested size /rounded/ is %llu).\n",
11378 current_size
, geo
->size
);
11379 goto analyse_change_exit
;
11381 if (max_size
&& geo
->size
> max_size
) {
11382 pr_err("Error. Requested size is larger than maximum available size (maximum available size is %llu, requested size /rounded/ is %llu).\n",
11383 max_size
, geo
->size
);
11384 goto analyse_change_exit
;
11387 geo
->size
*= data_disks
;
11388 geo
->raid_disks
= dev
->vol
.map
->num_members
;
11389 change
= CH_ARRAY_SIZE
;
11391 if (!validate_geometry_imsm(st
,
11394 geo
->raid_disks
+ devNumChange
,
11396 geo
->size
, INVALID_SECTORS
,
11397 0, 0, info
.consistency_policy
, 1))
11401 struct intel_super
*super
= st
->sb
;
11402 struct imsm_super
*mpb
= super
->anchor
;
11404 if (mpb
->num_raid_devs
> 1) {
11405 pr_err("Error. Cannot perform operation on %s- for this operation it MUST be single array in container\n",
11411 analyse_change_exit
:
11412 if (direction
== ROLLBACK_METADATA_CHANGES
&&
11413 (change
== CH_MIGRATION
|| change
== CH_TAKEOVER
)) {
11414 dprintf("imsm: Metadata changes rollback is not supported for migration and takeover operations.\n");
11420 int imsm_takeover(struct supertype
*st
, struct geo_params
*geo
)
11422 struct intel_super
*super
= st
->sb
;
11423 struct imsm_update_takeover
*u
;
11425 u
= xmalloc(sizeof(struct imsm_update_takeover
));
11427 u
->type
= update_takeover
;
11428 u
->subarray
= super
->current_vol
;
11430 /* 10->0 transition */
11431 if (geo
->level
== 0)
11432 u
->direction
= R10_TO_R0
;
11434 /* 0->10 transition */
11435 if (geo
->level
== 10)
11436 u
->direction
= R0_TO_R10
;
11438 /* update metadata locally */
11439 imsm_update_metadata_locally(st
, u
,
11440 sizeof(struct imsm_update_takeover
));
11441 /* and possibly remotely */
11442 if (st
->update_tail
)
11443 append_metadata_update(st
, u
,
11444 sizeof(struct imsm_update_takeover
));
11451 static int imsm_reshape_super(struct supertype
*st
, unsigned long long size
,
11453 int layout
, int chunksize
, int raid_disks
,
11454 int delta_disks
, char *backup
, char *dev
,
11455 int direction
, int verbose
)
11458 struct geo_params geo
;
11460 dprintf("(enter)\n");
11462 memset(&geo
, 0, sizeof(struct geo_params
));
11464 geo
.dev_name
= dev
;
11465 strcpy(geo
.devnm
, st
->devnm
);
11468 geo
.layout
= layout
;
11469 geo
.chunksize
= chunksize
;
11470 geo
.raid_disks
= raid_disks
;
11471 if (delta_disks
!= UnSet
)
11472 geo
.raid_disks
+= delta_disks
;
11474 dprintf("for level : %i\n", geo
.level
);
11475 dprintf("for raid_disks : %i\n", geo
.raid_disks
);
11477 if (experimental() == 0)
11480 if (strcmp(st
->container_devnm
, st
->devnm
) == 0) {
11481 /* On container level we can only increase number of devices. */
11482 dprintf("imsm: info: Container operation\n");
11483 int old_raid_disks
= 0;
11485 if (imsm_reshape_is_allowed_on_container(
11486 st
, &geo
, &old_raid_disks
, direction
)) {
11487 struct imsm_update_reshape
*u
= NULL
;
11490 len
= imsm_create_metadata_update_for_reshape(
11491 st
, &geo
, old_raid_disks
, &u
);
11494 dprintf("imsm: Cannot prepare update\n");
11495 goto exit_imsm_reshape_super
;
11499 /* update metadata locally */
11500 imsm_update_metadata_locally(st
, u
, len
);
11501 /* and possibly remotely */
11502 if (st
->update_tail
)
11503 append_metadata_update(st
, u
, len
);
11508 pr_err("(imsm) Operation is not allowed on this container\n");
11511 /* On volume level we support following operations
11512 * - takeover: raid10 -> raid0; raid0 -> raid10
11513 * - chunk size migration
11514 * - migration: raid5 -> raid0; raid0 -> raid5
11516 struct intel_super
*super
= st
->sb
;
11517 struct intel_dev
*dev
= super
->devlist
;
11519 dprintf("imsm: info: Volume operation\n");
11520 /* find requested device */
11523 imsm_find_array_devnm_by_subdev(
11524 dev
->index
, st
->container_devnm
);
11525 if (devnm
&& strcmp(devnm
, geo
.devnm
) == 0)
11530 pr_err("Cannot find %s (%s) subarray\n",
11531 geo
.dev_name
, geo
.devnm
);
11532 goto exit_imsm_reshape_super
;
11534 super
->current_vol
= dev
->index
;
11535 change
= imsm_analyze_change(st
, &geo
, direction
);
11538 ret_val
= imsm_takeover(st
, &geo
);
11540 case CH_MIGRATION
: {
11541 struct imsm_update_reshape_migration
*u
= NULL
;
11543 imsm_create_metadata_update_for_migration(
11546 dprintf("imsm: Cannot prepare update\n");
11550 /* update metadata locally */
11551 imsm_update_metadata_locally(st
, u
, len
);
11552 /* and possibly remotely */
11553 if (st
->update_tail
)
11554 append_metadata_update(st
, u
, len
);
11559 case CH_ARRAY_SIZE
: {
11560 struct imsm_update_size_change
*u
= NULL
;
11562 imsm_create_metadata_update_for_size_change(
11565 dprintf("imsm: Cannot prepare update\n");
11569 /* update metadata locally */
11570 imsm_update_metadata_locally(st
, u
, len
);
11571 /* and possibly remotely */
11572 if (st
->update_tail
)
11573 append_metadata_update(st
, u
, len
);
11583 exit_imsm_reshape_super
:
11584 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
11588 #define COMPLETED_OK 0
11589 #define COMPLETED_NONE 1
11590 #define COMPLETED_DELAYED 2
11592 static int read_completed(int fd
, unsigned long long *val
)
11597 ret
= sysfs_fd_get_str(fd
, buf
, 50);
11601 ret
= COMPLETED_OK
;
11602 if (strncmp(buf
, "none", 4) == 0) {
11603 ret
= COMPLETED_NONE
;
11604 } else if (strncmp(buf
, "delayed", 7) == 0) {
11605 ret
= COMPLETED_DELAYED
;
11608 *val
= strtoull(buf
, &ep
, 0);
11609 if (ep
== buf
|| (*ep
!= 0 && *ep
!= '\n' && *ep
!= ' '))
11615 /*******************************************************************************
11616 * Function: wait_for_reshape_imsm
11617 * Description: Function writes new sync_max value and waits until
11618 * reshape process reach new position
11620 * sra : general array info
11621 * ndata : number of disks in new array's layout
11624 * 1 : there is no reshape in progress,
11626 ******************************************************************************/
11627 int wait_for_reshape_imsm(struct mdinfo
*sra
, int ndata
)
11629 int fd
= sysfs_get_fd(sra
, NULL
, "sync_completed");
11631 unsigned long long completed
;
11632 /* to_complete : new sync_max position */
11633 unsigned long long to_complete
= sra
->reshape_progress
;
11634 unsigned long long position_to_set
= to_complete
/ ndata
;
11637 dprintf("cannot open reshape_position\n");
11642 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
11644 dprintf("cannot read reshape_position (no reshape in progres)\n");
11653 if (completed
> position_to_set
) {
11654 dprintf("wrong next position to set %llu (%llu)\n",
11655 to_complete
, position_to_set
);
11659 dprintf("Position set: %llu\n", position_to_set
);
11660 if (sysfs_set_num(sra
, NULL
, "sync_max",
11661 position_to_set
) != 0) {
11662 dprintf("cannot set reshape position to %llu\n",
11671 int timeout
= 3000;
11673 sysfs_wait(fd
, &timeout
);
11674 if (sysfs_get_str(sra
, NULL
, "sync_action",
11676 strncmp(action
, "reshape", 7) != 0) {
11677 if (strncmp(action
, "idle", 4) == 0)
11683 rc
= read_completed(fd
, &completed
);
11685 dprintf("cannot read reshape_position (in loop)\n");
11688 } else if (rc
== COMPLETED_NONE
)
11690 } while (completed
< position_to_set
);
11696 /*******************************************************************************
11697 * Function: check_degradation_change
11698 * Description: Check that array hasn't become failed.
11700 * info : for sysfs access
11701 * sources : source disks descriptors
11702 * degraded: previous degradation level
11704 * degradation level
11705 ******************************************************************************/
11706 int check_degradation_change(struct mdinfo
*info
,
11710 unsigned long long new_degraded
;
11713 rv
= sysfs_get_ll(info
, NULL
, "degraded", &new_degraded
);
11714 if (rv
== -1 || (new_degraded
!= (unsigned long long)degraded
)) {
11715 /* check each device to ensure it is still working */
11718 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
11719 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
11721 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
11724 if (sysfs_get_str(info
,
11725 sd
, "state", sbuf
, sizeof(sbuf
)) < 0 ||
11726 strstr(sbuf
, "faulty") ||
11727 strstr(sbuf
, "in_sync") == NULL
) {
11728 /* this device is dead */
11729 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
11730 if (sd
->disk
.raid_disk
>= 0 &&
11731 sources
[sd
->disk
.raid_disk
] >= 0) {
11733 sd
->disk
.raid_disk
]);
11734 sources
[sd
->disk
.raid_disk
] =
11743 return new_degraded
;
11746 /*******************************************************************************
11747 * Function: imsm_manage_reshape
11748 * Description: Function finds array under reshape and it manages reshape
11749 * process. It creates stripes backups (if required) and sets
11752 * afd : Backup handle (nattive) - not used
11753 * sra : general array info
11754 * reshape : reshape parameters - not used
11755 * st : supertype structure
11756 * blocks : size of critical section [blocks]
11757 * fds : table of source device descriptor
11758 * offsets : start of array (offest per devices)
11760 * destfd : table of destination device descriptor
11761 * destoffsets : table of destination offsets (per device)
11763 * 1 : success, reshape is done
11765 ******************************************************************************/
11766 static int imsm_manage_reshape(
11767 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
11768 struct supertype
*st
, unsigned long backup_blocks
,
11769 int *fds
, unsigned long long *offsets
,
11770 int dests
, int *destfd
, unsigned long long *destoffsets
)
11773 struct intel_super
*super
= st
->sb
;
11774 struct intel_dev
*dv
;
11775 unsigned int sector_size
= super
->sector_size
;
11776 struct imsm_dev
*dev
= NULL
;
11777 struct imsm_map
*map_src
;
11778 int migr_vol_qan
= 0;
11779 int ndata
, odata
; /* [bytes] */
11780 int chunk
; /* [bytes] */
11781 struct migr_record
*migr_rec
;
11783 unsigned int buf_size
; /* [bytes] */
11784 unsigned long long max_position
; /* array size [bytes] */
11785 unsigned long long next_step
; /* [blocks]/[bytes] */
11786 unsigned long long old_data_stripe_length
;
11787 unsigned long long start_src
; /* [bytes] */
11788 unsigned long long start
; /* [bytes] */
11789 unsigned long long start_buf_shift
; /* [bytes] */
11791 int source_layout
= 0;
11796 if (!fds
|| !offsets
)
11799 /* Find volume during the reshape */
11800 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
11801 if (dv
->dev
->vol
.migr_type
== MIGR_GEN_MIGR
&&
11802 dv
->dev
->vol
.migr_state
== 1) {
11807 /* Only one volume can migrate at the same time */
11808 if (migr_vol_qan
!= 1) {
11809 pr_err("%s", migr_vol_qan
?
11810 "Number of migrating volumes greater than 1\n" :
11811 "There is no volume during migrationg\n");
11815 map_src
= get_imsm_map(dev
, MAP_1
);
11816 if (map_src
== NULL
)
11819 ndata
= imsm_num_data_members(dev
, MAP_0
);
11820 odata
= imsm_num_data_members(dev
, MAP_1
);
11822 chunk
= __le16_to_cpu(map_src
->blocks_per_strip
) * 512;
11823 old_data_stripe_length
= odata
* chunk
;
11825 migr_rec
= super
->migr_rec
;
11827 /* initialize migration record for start condition */
11828 if (sra
->reshape_progress
== 0)
11829 init_migr_record_imsm(st
, dev
, sra
);
11831 if (__le32_to_cpu(migr_rec
->rec_status
) != UNIT_SRC_NORMAL
) {
11832 dprintf("imsm: cannot restart migration when data are present in copy area.\n");
11835 /* Save checkpoint to update migration record for current
11836 * reshape position (in md). It can be farther than current
11837 * reshape position in metadata.
11839 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
11840 /* ignore error == 2, this can mean end of reshape here
11842 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL, initial save)\n");
11847 /* size for data */
11848 buf_size
= __le32_to_cpu(migr_rec
->blocks_per_unit
) * 512;
11849 /* extend buffer size for parity disk */
11850 buf_size
+= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
11851 /* add space for stripe aligment */
11852 buf_size
+= old_data_stripe_length
;
11853 if (posix_memalign((void **)&buf
, MAX_SECTOR_SIZE
, buf_size
)) {
11854 dprintf("imsm: Cannot allocate checkpoint buffer\n");
11858 max_position
= sra
->component_size
* ndata
;
11859 source_layout
= imsm_level_to_layout(map_src
->raid_level
);
11861 while (__le32_to_cpu(migr_rec
->curr_migr_unit
) <
11862 __le32_to_cpu(migr_rec
->num_migr_units
)) {
11863 /* current reshape position [blocks] */
11864 unsigned long long current_position
=
11865 __le32_to_cpu(migr_rec
->blocks_per_unit
)
11866 * __le32_to_cpu(migr_rec
->curr_migr_unit
);
11867 unsigned long long border
;
11869 /* Check that array hasn't become failed.
11871 degraded
= check_degradation_change(sra
, fds
, degraded
);
11872 if (degraded
> 1) {
11873 dprintf("imsm: Abort reshape due to degradation level (%i)\n", degraded
);
11877 next_step
= __le32_to_cpu(migr_rec
->blocks_per_unit
);
11879 if ((current_position
+ next_step
) > max_position
)
11880 next_step
= max_position
- current_position
;
11882 start
= current_position
* 512;
11884 /* align reading start to old geometry */
11885 start_buf_shift
= start
% old_data_stripe_length
;
11886 start_src
= start
- start_buf_shift
;
11888 border
= (start_src
/ odata
) - (start
/ ndata
);
11890 if (border
<= __le32_to_cpu(migr_rec
->dest_depth_per_unit
)) {
11891 /* save critical stripes to buf
11892 * start - start address of current unit
11893 * to backup [bytes]
11894 * start_src - start address of current unit
11895 * to backup alligned to source array
11898 unsigned long long next_step_filler
;
11899 unsigned long long copy_length
= next_step
* 512;
11901 /* allign copy area length to stripe in old geometry */
11902 next_step_filler
= ((copy_length
+ start_buf_shift
)
11903 % old_data_stripe_length
);
11904 if (next_step_filler
)
11905 next_step_filler
= (old_data_stripe_length
11906 - next_step_filler
);
11907 dprintf("save_stripes() parameters: start = %llu,\tstart_src = %llu,\tnext_step*512 = %llu,\tstart_in_buf_shift = %llu,\tnext_step_filler = %llu\n",
11908 start
, start_src
, copy_length
,
11909 start_buf_shift
, next_step_filler
);
11911 if (save_stripes(fds
, offsets
, map_src
->num_members
,
11912 chunk
, map_src
->raid_level
,
11913 source_layout
, 0, NULL
, start_src
,
11915 next_step_filler
+ start_buf_shift
,
11917 dprintf("imsm: Cannot save stripes to buffer\n");
11920 /* Convert data to destination format and store it
11921 * in backup general migration area
11923 if (save_backup_imsm(st
, dev
, sra
,
11924 buf
+ start_buf_shift
, copy_length
)) {
11925 dprintf("imsm: Cannot save stripes to target devices\n");
11928 if (save_checkpoint_imsm(st
, sra
,
11929 UNIT_SRC_IN_CP_AREA
)) {
11930 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_IN_CP_AREA)\n");
11934 /* set next step to use whole border area */
11935 border
/= next_step
;
11937 next_step
*= border
;
11939 /* When data backed up, checkpoint stored,
11940 * kick the kernel to reshape unit of data
11942 next_step
= next_step
+ sra
->reshape_progress
;
11943 /* limit next step to array max position */
11944 if (next_step
> max_position
)
11945 next_step
= max_position
;
11946 sysfs_set_num(sra
, NULL
, "suspend_lo", sra
->reshape_progress
);
11947 sysfs_set_num(sra
, NULL
, "suspend_hi", next_step
);
11948 sra
->reshape_progress
= next_step
;
11950 /* wait until reshape finish */
11951 if (wait_for_reshape_imsm(sra
, ndata
)) {
11952 dprintf("wait_for_reshape_imsm returned error!\n");
11958 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
11959 /* ignore error == 2, this can mean end of reshape here
11961 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL)\n");
11967 /* clear migr_rec on disks after successful migration */
11970 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
);
11971 for (d
= super
->disks
; d
; d
= d
->next
) {
11972 if (d
->index
< 0 || is_failed(&d
->disk
))
11974 unsigned long long dsize
;
11976 get_dev_size(d
->fd
, NULL
, &dsize
);
11977 if (lseek64(d
->fd
, dsize
- MIGR_REC_SECTOR_POSITION
*sector_size
,
11979 if ((unsigned int)write(d
->fd
, super
->migr_rec_buf
,
11980 MIGR_REC_BUF_SECTORS
*sector_size
) !=
11981 MIGR_REC_BUF_SECTORS
*sector_size
)
11982 perror("Write migr_rec failed");
11986 /* return '1' if done */
11990 /* See Grow.c: abort_reshape() for further explanation */
11991 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
11992 sysfs_set_num(sra
, NULL
, "suspend_hi", 0);
11993 sysfs_set_num(sra
, NULL
, "suspend_lo", 0);
11998 struct superswitch super_imsm
= {
11999 .examine_super
= examine_super_imsm
,
12000 .brief_examine_super
= brief_examine_super_imsm
,
12001 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
12002 .export_examine_super
= export_examine_super_imsm
,
12003 .detail_super
= detail_super_imsm
,
12004 .brief_detail_super
= brief_detail_super_imsm
,
12005 .write_init_super
= write_init_super_imsm
,
12006 .validate_geometry
= validate_geometry_imsm
,
12007 .add_to_super
= add_to_super_imsm
,
12008 .remove_from_super
= remove_from_super_imsm
,
12009 .detail_platform
= detail_platform_imsm
,
12010 .export_detail_platform
= export_detail_platform_imsm
,
12011 .kill_subarray
= kill_subarray_imsm
,
12012 .update_subarray
= update_subarray_imsm
,
12013 .load_container
= load_container_imsm
,
12014 .default_geometry
= default_geometry_imsm
,
12015 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
12016 .reshape_super
= imsm_reshape_super
,
12017 .manage_reshape
= imsm_manage_reshape
,
12018 .recover_backup
= recover_backup_imsm
,
12019 .copy_metadata
= copy_metadata_imsm
,
12020 .examine_badblocks
= examine_badblocks_imsm
,
12021 .match_home
= match_home_imsm
,
12022 .uuid_from_super
= uuid_from_super_imsm
,
12023 .getinfo_super
= getinfo_super_imsm
,
12024 .getinfo_super_disks
= getinfo_super_disks_imsm
,
12025 .update_super
= update_super_imsm
,
12027 .avail_size
= avail_size_imsm
,
12028 .get_spare_criteria
= get_spare_criteria_imsm
,
12030 .compare_super
= compare_super_imsm
,
12032 .load_super
= load_super_imsm
,
12033 .init_super
= init_super_imsm
,
12034 .store_super
= store_super_imsm
,
12035 .free_super
= free_super_imsm
,
12036 .match_metadata_desc
= match_metadata_desc_imsm
,
12037 .container_content
= container_content_imsm
,
12038 .validate_container
= validate_container_imsm
,
12040 .write_init_ppl
= write_init_ppl_imsm
,
12041 .validate_ppl
= validate_ppl_imsm
,
12047 .open_new
= imsm_open_new
,
12048 .set_array_state
= imsm_set_array_state
,
12049 .set_disk
= imsm_set_disk
,
12050 .sync_metadata
= imsm_sync_metadata
,
12051 .activate_spare
= imsm_activate_spare
,
12052 .process_update
= imsm_process_update
,
12053 .prepare_update
= imsm_prepare_update
,
12054 .record_bad_block
= imsm_record_badblock
,
12055 .clear_bad_block
= imsm_clear_badblock
,
12056 .get_bad_blocks
= imsm_get_badblocks
,