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 static int able_to_resync(int raid_level
, int missing_disks
)
1347 int max_missing_disks
= 0;
1349 switch (raid_level
) {
1351 max_missing_disks
= 1;
1354 max_missing_disks
= 0;
1356 return missing_disks
<= max_missing_disks
;
1359 /* try to determine how much space is reserved for metadata from
1360 * the last get_extents() entry on the smallest active disk,
1361 * otherwise fallback to the default
1363 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
)
1367 unsigned long long min_active
;
1369 __u32 rv
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1370 struct dl
*dl
, *dl_min
= NULL
;
1376 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
1379 unsigned long long blocks
= total_blocks(&dl
->disk
);
1380 if (blocks
< min_active
|| min_active
== 0) {
1382 min_active
= blocks
;
1388 /* find last lba used by subarrays on the smallest active disk */
1389 e
= get_extents(super
, dl_min
);
1392 for (i
= 0; e
[i
].size
; i
++)
1395 remainder
= min_active
- e
[i
].start
;
1398 /* to give priority to recovery we should not require full
1399 IMSM_RESERVED_SECTORS from the spare */
1400 rv
= MPB_SECTOR_CNT
+ NUM_BLOCKS_DIRTY_STRIPE_REGION
;
1402 /* if real reservation is smaller use that value */
1403 return (remainder
< rv
) ? remainder
: rv
;
1407 * Return minimum size of a spare and sector size
1408 * that can be used in this array
1410 int get_spare_criteria_imsm(struct supertype
*st
, struct spare_criteria
*c
)
1412 struct intel_super
*super
= st
->sb
;
1416 unsigned long long size
= 0;
1423 /* find first active disk in array */
1425 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
1429 /* find last lba used by subarrays */
1430 e
= get_extents(super
, dl
);
1433 for (i
= 0; e
[i
].size
; i
++)
1436 size
= e
[i
-1].start
+ e
[i
-1].size
;
1439 /* add the amount of space needed for metadata */
1440 size
+= imsm_min_reserved_sectors(super
);
1442 c
->min_size
= size
* 512;
1443 c
->sector_size
= super
->sector_size
;
1448 static int is_gen_migration(struct imsm_dev
*dev
);
1450 #define IMSM_4K_DIV 8
1452 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
1453 struct imsm_dev
*dev
);
1455 static void print_imsm_dev(struct intel_super
*super
,
1456 struct imsm_dev
*dev
,
1462 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1463 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
1467 printf("[%.16s]:\n", dev
->volume
);
1468 printf(" UUID : %s\n", uuid
);
1469 printf(" RAID Level : %d", get_imsm_raid_level(map
));
1471 printf(" <-- %d", get_imsm_raid_level(map2
));
1473 printf(" Members : %d", map
->num_members
);
1475 printf(" <-- %d", map2
->num_members
);
1477 printf(" Slots : [");
1478 for (i
= 0; i
< map
->num_members
; i
++) {
1479 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
1480 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1485 for (i
= 0; i
< map2
->num_members
; i
++) {
1486 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_1
);
1487 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1492 printf(" Failed disk : ");
1493 if (map
->failed_disk_num
== 0xff)
1496 printf("%i", map
->failed_disk_num
);
1498 slot
= get_imsm_disk_slot(map
, disk_idx
);
1500 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
1501 printf(" This Slot : %d%s\n", slot
,
1502 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
1504 printf(" This Slot : ?\n");
1505 printf(" Sector Size : %u\n", super
->sector_size
);
1506 sz
= __le32_to_cpu(dev
->size_high
);
1508 sz
+= __le32_to_cpu(dev
->size_low
);
1509 printf(" Array Size : %llu%s\n",
1510 (unsigned long long)sz
* 512 / super
->sector_size
,
1511 human_size(sz
* 512));
1512 sz
= blocks_per_member(map
);
1513 printf(" Per Dev Size : %llu%s\n",
1514 (unsigned long long)sz
* 512 / super
->sector_size
,
1515 human_size(sz
* 512));
1516 printf(" Sector Offset : %llu\n",
1518 printf(" Num Stripes : %llu\n",
1519 num_data_stripes(map
));
1520 printf(" Chunk Size : %u KiB",
1521 __le16_to_cpu(map
->blocks_per_strip
) / 2);
1523 printf(" <-- %u KiB",
1524 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
1526 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
1527 printf(" Migrate State : ");
1528 if (dev
->vol
.migr_state
) {
1529 if (migr_type(dev
) == MIGR_INIT
)
1530 printf("initialize\n");
1531 else if (migr_type(dev
) == MIGR_REBUILD
)
1532 printf("rebuild\n");
1533 else if (migr_type(dev
) == MIGR_VERIFY
)
1535 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
1536 printf("general migration\n");
1537 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
1538 printf("state change\n");
1539 else if (migr_type(dev
) == MIGR_REPAIR
)
1542 printf("<unknown:%d>\n", migr_type(dev
));
1545 printf(" Map State : %s", map_state_str
[map
->map_state
]);
1546 if (dev
->vol
.migr_state
) {
1547 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
1549 printf(" <-- %s", map_state_str
[map
->map_state
]);
1550 printf("\n Checkpoint : %u ",
1551 __le32_to_cpu(dev
->vol
.curr_migr_unit
));
1552 if (is_gen_migration(dev
) && (slot
> 1 || slot
< 0))
1555 printf("(%llu)", (unsigned long long)
1556 blocks_per_migr_unit(super
, dev
));
1559 printf(" Dirty State : %s\n", (dev
->vol
.dirty
& RAIDVOL_DIRTY
) ?
1561 printf(" RWH Policy : ");
1562 if (dev
->rwh_policy
== RWH_OFF
|| dev
->rwh_policy
== RWH_MULTIPLE_OFF
)
1564 else if (dev
->rwh_policy
== RWH_DISTRIBUTED
)
1565 printf("PPL distributed\n");
1566 else if (dev
->rwh_policy
== RWH_JOURNALING_DRIVE
)
1567 printf("PPL journaling drive\n");
1568 else if (dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)
1569 printf("Multiple distributed PPLs\n");
1570 else if (dev
->rwh_policy
== RWH_MULTIPLE_PPLS_JOURNALING_DRIVE
)
1571 printf("Multiple PPLs on journaling drive\n");
1573 printf("<unknown:%d>\n", dev
->rwh_policy
);
1576 static void print_imsm_disk(struct imsm_disk
*disk
,
1579 unsigned int sector_size
) {
1580 char str
[MAX_RAID_SERIAL_LEN
+ 1];
1583 if (index
< -1 || !disk
)
1587 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
1589 printf(" Disk%02d Serial : %s\n", index
, str
);
1591 printf(" Disk Serial : %s\n", str
);
1592 printf(" State :%s%s%s%s\n", is_spare(disk
) ? " spare" : "",
1593 is_configured(disk
) ? " active" : "",
1594 is_failed(disk
) ? " failed" : "",
1595 is_journal(disk
) ? " journal" : "");
1596 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
1597 sz
= total_blocks(disk
) - reserved
;
1598 printf(" Usable Size : %llu%s\n",
1599 (unsigned long long)sz
* 512 / sector_size
,
1600 human_size(sz
* 512));
1603 void convert_to_4k_imsm_migr_rec(struct intel_super
*super
)
1605 struct migr_record
*migr_rec
= super
->migr_rec
;
1607 migr_rec
->blocks_per_unit
/= IMSM_4K_DIV
;
1608 migr_rec
->ckpt_area_pba
/= IMSM_4K_DIV
;
1609 migr_rec
->dest_1st_member_lba
/= IMSM_4K_DIV
;
1610 migr_rec
->dest_depth_per_unit
/= IMSM_4K_DIV
;
1611 split_ull((join_u32(migr_rec
->post_migr_vol_cap
,
1612 migr_rec
->post_migr_vol_cap_hi
) / IMSM_4K_DIV
),
1613 &migr_rec
->post_migr_vol_cap
, &migr_rec
->post_migr_vol_cap_hi
);
1616 void convert_to_4k_imsm_disk(struct imsm_disk
*disk
)
1618 set_total_blocks(disk
, (total_blocks(disk
)/IMSM_4K_DIV
));
1621 void convert_to_4k(struct intel_super
*super
)
1623 struct imsm_super
*mpb
= super
->anchor
;
1624 struct imsm_disk
*disk
;
1626 __u32 bbm_log_size
= __le32_to_cpu(mpb
->bbm_log_size
);
1628 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1629 disk
= __get_imsm_disk(mpb
, i
);
1631 convert_to_4k_imsm_disk(disk
);
1633 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1634 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1635 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1637 split_ull((join_u32(dev
->size_low
, dev
->size_high
)/IMSM_4K_DIV
),
1638 &dev
->size_low
, &dev
->size_high
);
1639 dev
->vol
.curr_migr_unit
/= IMSM_4K_DIV
;
1642 set_blocks_per_member(map
, blocks_per_member(map
)/IMSM_4K_DIV
);
1643 map
->blocks_per_strip
/= IMSM_4K_DIV
;
1644 set_pba_of_lba0(map
, pba_of_lba0(map
)/IMSM_4K_DIV
);
1646 if (dev
->vol
.migr_state
) {
1648 map
= get_imsm_map(dev
, MAP_1
);
1649 set_blocks_per_member(map
,
1650 blocks_per_member(map
)/IMSM_4K_DIV
);
1651 map
->blocks_per_strip
/= IMSM_4K_DIV
;
1652 set_pba_of_lba0(map
, pba_of_lba0(map
)/IMSM_4K_DIV
);
1656 struct bbm_log
*log
= (void *)mpb
+
1657 __le32_to_cpu(mpb
->mpb_size
) - bbm_log_size
;
1660 for (i
= 0; i
< log
->entry_count
; i
++) {
1661 struct bbm_log_entry
*entry
=
1662 &log
->marked_block_entries
[i
];
1664 __u8 count
= entry
->marked_count
+ 1;
1665 unsigned long long sector
=
1666 __le48_to_cpu(&entry
->defective_block_start
);
1668 entry
->defective_block_start
=
1669 __cpu_to_le48(sector
/IMSM_4K_DIV
);
1670 entry
->marked_count
= max(count
/IMSM_4K_DIV
, 1) - 1;
1674 mpb
->check_sum
= __gen_imsm_checksum(mpb
);
1677 void examine_migr_rec_imsm(struct intel_super
*super
)
1679 struct migr_record
*migr_rec
= super
->migr_rec
;
1680 struct imsm_super
*mpb
= super
->anchor
;
1683 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1684 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1685 struct imsm_map
*map
;
1688 if (is_gen_migration(dev
) == 0)
1691 printf("\nMigration Record Information:");
1693 /* first map under migration */
1694 map
= get_imsm_map(dev
, MAP_0
);
1696 slot
= get_imsm_disk_slot(map
, super
->disks
->index
);
1697 if (map
== NULL
|| slot
> 1 || slot
< 0) {
1698 printf(" Empty\n ");
1699 printf("Examine one of first two disks in array\n");
1702 printf("\n Status : ");
1703 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
1706 printf("Contains Data\n");
1707 printf(" Current Unit : %u\n",
1708 __le32_to_cpu(migr_rec
->curr_migr_unit
));
1709 printf(" Family : %u\n",
1710 __le32_to_cpu(migr_rec
->family_num
));
1711 printf(" Ascending : %u\n",
1712 __le32_to_cpu(migr_rec
->ascending_migr
));
1713 printf(" Blocks Per Unit : %u\n",
1714 __le32_to_cpu(migr_rec
->blocks_per_unit
));
1715 printf(" Dest. Depth Per Unit : %u\n",
1716 __le32_to_cpu(migr_rec
->dest_depth_per_unit
));
1717 printf(" Checkpoint Area pba : %u\n",
1718 __le32_to_cpu(migr_rec
->ckpt_area_pba
));
1719 printf(" First member lba : %u\n",
1720 __le32_to_cpu(migr_rec
->dest_1st_member_lba
));
1721 printf(" Total Number of Units : %u\n",
1722 __le32_to_cpu(migr_rec
->num_migr_units
));
1723 printf(" Size of volume : %u\n",
1724 __le32_to_cpu(migr_rec
->post_migr_vol_cap
));
1725 printf(" Expansion space for LBA64 : %u\n",
1726 __le32_to_cpu(migr_rec
->post_migr_vol_cap_hi
));
1727 printf(" Record was read from : %u\n",
1728 __le32_to_cpu(migr_rec
->ckpt_read_disk_num
));
1734 void convert_from_4k_imsm_migr_rec(struct intel_super
*super
)
1736 struct migr_record
*migr_rec
= super
->migr_rec
;
1738 migr_rec
->blocks_per_unit
*= IMSM_4K_DIV
;
1739 migr_rec
->ckpt_area_pba
*= IMSM_4K_DIV
;
1740 migr_rec
->dest_1st_member_lba
*= IMSM_4K_DIV
;
1741 migr_rec
->dest_depth_per_unit
*= IMSM_4K_DIV
;
1742 split_ull((join_u32(migr_rec
->post_migr_vol_cap
,
1743 migr_rec
->post_migr_vol_cap_hi
) * IMSM_4K_DIV
),
1744 &migr_rec
->post_migr_vol_cap
,
1745 &migr_rec
->post_migr_vol_cap_hi
);
1748 void convert_from_4k(struct intel_super
*super
)
1750 struct imsm_super
*mpb
= super
->anchor
;
1751 struct imsm_disk
*disk
;
1753 __u32 bbm_log_size
= __le32_to_cpu(mpb
->bbm_log_size
);
1755 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1756 disk
= __get_imsm_disk(mpb
, i
);
1758 set_total_blocks(disk
, (total_blocks(disk
)*IMSM_4K_DIV
));
1761 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1762 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1763 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1765 split_ull((join_u32(dev
->size_low
, dev
->size_high
)*IMSM_4K_DIV
),
1766 &dev
->size_low
, &dev
->size_high
);
1767 dev
->vol
.curr_migr_unit
*= IMSM_4K_DIV
;
1770 set_blocks_per_member(map
, blocks_per_member(map
)*IMSM_4K_DIV
);
1771 map
->blocks_per_strip
*= IMSM_4K_DIV
;
1772 set_pba_of_lba0(map
, pba_of_lba0(map
)*IMSM_4K_DIV
);
1774 if (dev
->vol
.migr_state
) {
1776 map
= get_imsm_map(dev
, MAP_1
);
1777 set_blocks_per_member(map
,
1778 blocks_per_member(map
)*IMSM_4K_DIV
);
1779 map
->blocks_per_strip
*= IMSM_4K_DIV
;
1780 set_pba_of_lba0(map
, pba_of_lba0(map
)*IMSM_4K_DIV
);
1784 struct bbm_log
*log
= (void *)mpb
+
1785 __le32_to_cpu(mpb
->mpb_size
) - bbm_log_size
;
1788 for (i
= 0; i
< log
->entry_count
; i
++) {
1789 struct bbm_log_entry
*entry
=
1790 &log
->marked_block_entries
[i
];
1792 __u8 count
= entry
->marked_count
+ 1;
1793 unsigned long long sector
=
1794 __le48_to_cpu(&entry
->defective_block_start
);
1796 entry
->defective_block_start
=
1797 __cpu_to_le48(sector
*IMSM_4K_DIV
);
1798 entry
->marked_count
= count
*IMSM_4K_DIV
- 1;
1802 mpb
->check_sum
= __gen_imsm_checksum(mpb
);
1805 /*******************************************************************************
1806 * function: imsm_check_attributes
1807 * Description: Function checks if features represented by attributes flags
1808 * are supported by mdadm.
1810 * attributes - Attributes read from metadata
1812 * 0 - passed attributes contains unsupported features flags
1813 * 1 - all features are supported
1814 ******************************************************************************/
1815 static int imsm_check_attributes(__u32 attributes
)
1818 __u32 not_supported
= MPB_ATTRIB_SUPPORTED
^0xffffffff;
1820 not_supported
&= ~MPB_ATTRIB_IGNORED
;
1822 not_supported
&= attributes
;
1823 if (not_supported
) {
1824 pr_err("(IMSM): Unsupported attributes : %x\n",
1825 (unsigned)__le32_to_cpu(not_supported
));
1826 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1827 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY \n");
1828 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1830 if (not_supported
& MPB_ATTRIB_2TB
) {
1831 dprintf("\t\tMPB_ATTRIB_2TB\n");
1832 not_supported
^= MPB_ATTRIB_2TB
;
1834 if (not_supported
& MPB_ATTRIB_RAID0
) {
1835 dprintf("\t\tMPB_ATTRIB_RAID0\n");
1836 not_supported
^= MPB_ATTRIB_RAID0
;
1838 if (not_supported
& MPB_ATTRIB_RAID1
) {
1839 dprintf("\t\tMPB_ATTRIB_RAID1\n");
1840 not_supported
^= MPB_ATTRIB_RAID1
;
1842 if (not_supported
& MPB_ATTRIB_RAID10
) {
1843 dprintf("\t\tMPB_ATTRIB_RAID10\n");
1844 not_supported
^= MPB_ATTRIB_RAID10
;
1846 if (not_supported
& MPB_ATTRIB_RAID1E
) {
1847 dprintf("\t\tMPB_ATTRIB_RAID1E\n");
1848 not_supported
^= MPB_ATTRIB_RAID1E
;
1850 if (not_supported
& MPB_ATTRIB_RAID5
) {
1851 dprintf("\t\tMPB_ATTRIB_RAID5\n");
1852 not_supported
^= MPB_ATTRIB_RAID5
;
1854 if (not_supported
& MPB_ATTRIB_RAIDCNG
) {
1855 dprintf("\t\tMPB_ATTRIB_RAIDCNG\n");
1856 not_supported
^= MPB_ATTRIB_RAIDCNG
;
1858 if (not_supported
& MPB_ATTRIB_BBM
) {
1859 dprintf("\t\tMPB_ATTRIB_BBM\n");
1860 not_supported
^= MPB_ATTRIB_BBM
;
1862 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1863 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY (== MPB_ATTRIB_LEGACY)\n");
1864 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1866 if (not_supported
& MPB_ATTRIB_EXP_STRIPE_SIZE
) {
1867 dprintf("\t\tMPB_ATTRIB_EXP_STRIP_SIZE\n");
1868 not_supported
^= MPB_ATTRIB_EXP_STRIPE_SIZE
;
1870 if (not_supported
& MPB_ATTRIB_2TB_DISK
) {
1871 dprintf("\t\tMPB_ATTRIB_2TB_DISK\n");
1872 not_supported
^= MPB_ATTRIB_2TB_DISK
;
1874 if (not_supported
& MPB_ATTRIB_NEVER_USE2
) {
1875 dprintf("\t\tMPB_ATTRIB_NEVER_USE2\n");
1876 not_supported
^= MPB_ATTRIB_NEVER_USE2
;
1878 if (not_supported
& MPB_ATTRIB_NEVER_USE
) {
1879 dprintf("\t\tMPB_ATTRIB_NEVER_USE\n");
1880 not_supported
^= MPB_ATTRIB_NEVER_USE
;
1884 dprintf("(IMSM): Unknown attributes : %x\n", not_supported
);
1892 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
1894 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
1896 struct intel_super
*super
= st
->sb
;
1897 struct imsm_super
*mpb
= super
->anchor
;
1898 char str
[MAX_SIGNATURE_LENGTH
];
1903 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
1906 strncpy(str
, (char *)mpb
->sig
, MPB_SIG_LEN
);
1907 str
[MPB_SIG_LEN
-1] = '\0';
1908 printf(" Magic : %s\n", str
);
1909 snprintf(str
, strlen(MPB_VERSION_RAID0
), "%s", get_imsm_version(mpb
));
1910 printf(" Version : %s\n", get_imsm_version(mpb
));
1911 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
1912 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
1913 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
1914 printf(" Attributes : ");
1915 if (imsm_check_attributes(mpb
->attributes
))
1916 printf("All supported\n");
1918 printf("not supported\n");
1919 getinfo_super_imsm(st
, &info
, NULL
);
1920 fname_from_uuid(st
, &info
, nbuf
, ':');
1921 printf(" UUID : %s\n", nbuf
+ 5);
1922 sum
= __le32_to_cpu(mpb
->check_sum
);
1923 printf(" Checksum : %08x %s\n", sum
,
1924 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
1925 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
, super
->sector_size
));
1926 printf(" Disks : %d\n", mpb
->num_disks
);
1927 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
1928 print_imsm_disk(__get_imsm_disk(mpb
, super
->disks
->index
),
1929 super
->disks
->index
, reserved
, super
->sector_size
);
1930 if (get_imsm_bbm_log_size(super
->bbm_log
)) {
1931 struct bbm_log
*log
= super
->bbm_log
;
1934 printf("Bad Block Management Log:\n");
1935 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
1936 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
1937 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
1939 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1941 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1943 super
->current_vol
= i
;
1944 getinfo_super_imsm(st
, &info
, NULL
);
1945 fname_from_uuid(st
, &info
, nbuf
, ':');
1946 print_imsm_dev(super
, dev
, nbuf
+ 5, super
->disks
->index
);
1948 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1949 if (i
== super
->disks
->index
)
1951 print_imsm_disk(__get_imsm_disk(mpb
, i
), i
, reserved
,
1952 super
->sector_size
);
1955 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
1956 if (dl
->index
== -1)
1957 print_imsm_disk(&dl
->disk
, -1, reserved
,
1958 super
->sector_size
);
1960 examine_migr_rec_imsm(super
);
1963 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
1965 /* We just write a generic IMSM ARRAY entry */
1968 struct intel_super
*super
= st
->sb
;
1970 if (!super
->anchor
->num_raid_devs
) {
1971 printf("ARRAY metadata=imsm\n");
1975 getinfo_super_imsm(st
, &info
, NULL
);
1976 fname_from_uuid(st
, &info
, nbuf
, ':');
1977 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
1980 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
1982 /* We just write a generic IMSM ARRAY entry */
1986 struct intel_super
*super
= st
->sb
;
1989 if (!super
->anchor
->num_raid_devs
)
1992 getinfo_super_imsm(st
, &info
, NULL
);
1993 fname_from_uuid(st
, &info
, nbuf
, ':');
1994 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1995 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1997 super
->current_vol
= i
;
1998 getinfo_super_imsm(st
, &info
, NULL
);
1999 fname_from_uuid(st
, &info
, nbuf1
, ':');
2000 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
2001 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
2005 static void export_examine_super_imsm(struct supertype
*st
)
2007 struct intel_super
*super
= st
->sb
;
2008 struct imsm_super
*mpb
= super
->anchor
;
2012 getinfo_super_imsm(st
, &info
, NULL
);
2013 fname_from_uuid(st
, &info
, nbuf
, ':');
2014 printf("MD_METADATA=imsm\n");
2015 printf("MD_LEVEL=container\n");
2016 printf("MD_UUID=%s\n", nbuf
+5);
2017 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
2020 static int copy_metadata_imsm(struct supertype
*st
, int from
, int to
)
2022 /* The second last sector of the device contains
2023 * the "struct imsm_super" metadata.
2024 * This contains mpb_size which is the size in bytes of the
2025 * extended metadata. This is located immediately before
2027 * We want to read all that, plus the last sector which
2028 * may contain a migration record, and write it all
2032 unsigned long long dsize
, offset
;
2034 struct imsm_super
*sb
;
2035 struct intel_super
*super
= st
->sb
;
2036 unsigned int sector_size
= super
->sector_size
;
2037 unsigned int written
= 0;
2039 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, MAX_SECTOR_SIZE
) != 0)
2042 if (!get_dev_size(from
, NULL
, &dsize
))
2045 if (lseek64(from
, dsize
-(2*sector_size
), 0) < 0)
2047 if ((unsigned int)read(from
, buf
, sector_size
) != sector_size
)
2050 if (strncmp((char*)sb
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0)
2053 sectors
= mpb_sectors(sb
, sector_size
) + 2;
2054 offset
= dsize
- sectors
* sector_size
;
2055 if (lseek64(from
, offset
, 0) < 0 ||
2056 lseek64(to
, offset
, 0) < 0)
2058 while (written
< sectors
* sector_size
) {
2059 int n
= sectors
*sector_size
- written
;
2062 if (read(from
, buf
, n
) != n
)
2064 if (write(to
, buf
, n
) != n
)
2075 static void detail_super_imsm(struct supertype
*st
, char *homehost
)
2080 getinfo_super_imsm(st
, &info
, NULL
);
2081 fname_from_uuid(st
, &info
, nbuf
, ':');
2082 printf("\n UUID : %s\n", nbuf
+ 5);
2085 static void brief_detail_super_imsm(struct supertype
*st
)
2089 getinfo_super_imsm(st
, &info
, NULL
);
2090 fname_from_uuid(st
, &info
, nbuf
, ':');
2091 printf(" UUID=%s", nbuf
+ 5);
2094 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
);
2095 static void fd2devname(int fd
, char *name
);
2097 static int ahci_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
2099 /* dump an unsorted list of devices attached to AHCI Intel storage
2100 * controller, as well as non-connected ports
2102 int hba_len
= strlen(hba_path
) + 1;
2107 unsigned long port_mask
= (1 << port_count
) - 1;
2109 if (port_count
> (int)sizeof(port_mask
) * 8) {
2111 pr_err("port_count %d out of range\n", port_count
);
2115 /* scroll through /sys/dev/block looking for devices attached to
2118 dir
= opendir("/sys/dev/block");
2122 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2133 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
2135 path
= devt_to_devpath(makedev(major
, minor
));
2138 if (!path_attached_to_hba(path
, hba_path
)) {
2144 /* retrieve the scsi device type */
2145 if (asprintf(&device
, "/sys/dev/block/%d:%d/device/xxxxxxx", major
, minor
) < 0) {
2147 pr_err("failed to allocate 'device'\n");
2151 sprintf(device
, "/sys/dev/block/%d:%d/device/type", major
, minor
);
2152 if (load_sys(device
, buf
, sizeof(buf
)) != 0) {
2154 pr_err("failed to read device type for %s\n",
2160 type
= strtoul(buf
, NULL
, 10);
2162 /* if it's not a disk print the vendor and model */
2163 if (!(type
== 0 || type
== 7 || type
== 14)) {
2166 sprintf(device
, "/sys/dev/block/%d:%d/device/vendor", major
, minor
);
2167 if (load_sys(device
, buf
, sizeof(buf
)) == 0) {
2168 strncpy(vendor
, buf
, sizeof(vendor
));
2169 vendor
[sizeof(vendor
) - 1] = '\0';
2170 c
= (char *) &vendor
[sizeof(vendor
) - 1];
2171 while (isspace(*c
) || *c
== '\0')
2175 sprintf(device
, "/sys/dev/block/%d:%d/device/model", major
, minor
);
2176 if (load_sys(device
, buf
, sizeof(buf
)) == 0) {
2177 strncpy(model
, buf
, sizeof(model
));
2178 model
[sizeof(model
) - 1] = '\0';
2179 c
= (char *) &model
[sizeof(model
) - 1];
2180 while (isspace(*c
) || *c
== '\0')
2184 if (vendor
[0] && model
[0])
2185 sprintf(buf
, "%.64s %.64s", vendor
, model
);
2187 switch (type
) { /* numbers from hald/linux/device.c */
2188 case 1: sprintf(buf
, "tape"); break;
2189 case 2: sprintf(buf
, "printer"); break;
2190 case 3: sprintf(buf
, "processor"); break;
2192 case 5: sprintf(buf
, "cdrom"); break;
2193 case 6: sprintf(buf
, "scanner"); break;
2194 case 8: sprintf(buf
, "media_changer"); break;
2195 case 9: sprintf(buf
, "comm"); break;
2196 case 12: sprintf(buf
, "raid"); break;
2197 default: sprintf(buf
, "unknown");
2203 /* chop device path to 'host%d' and calculate the port number */
2204 c
= strchr(&path
[hba_len
], '/');
2207 pr_err("%s - invalid path name\n", path
+ hba_len
);
2212 if ((sscanf(&path
[hba_len
], "ata%d", &port
) == 1) ||
2213 ((sscanf(&path
[hba_len
], "host%d", &port
) == 1)))
2217 *c
= '/'; /* repair the full string */
2218 pr_err("failed to determine port number for %s\n",
2225 /* mark this port as used */
2226 port_mask
&= ~(1 << port
);
2228 /* print out the device information */
2230 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
2234 fd
= dev_open(ent
->d_name
, O_RDONLY
);
2236 printf(" Port%d : - disk info unavailable -\n", port
);
2238 fd2devname(fd
, buf
);
2239 printf(" Port%d : %s", port
, buf
);
2240 if (imsm_read_serial(fd
, NULL
, (__u8
*) buf
) == 0)
2241 printf(" (%.*s)\n", MAX_RAID_SERIAL_LEN
, buf
);
2256 for (i
= 0; i
< port_count
; i
++)
2257 if (port_mask
& (1 << i
))
2258 printf(" Port%d : - no device attached -\n", i
);
2264 static int print_vmd_attached_devs(struct sys_dev
*hba
)
2272 if (hba
->type
!= SYS_DEV_VMD
)
2275 /* scroll through /sys/dev/block looking for devices attached to
2278 dir
= opendir("/sys/bus/pci/drivers/nvme");
2282 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2285 /* is 'ent' a device? check that the 'subsystem' link exists and
2286 * that its target matches 'bus'
2288 sprintf(path
, "/sys/bus/pci/drivers/nvme/%s/subsystem",
2290 n
= readlink(path
, link
, sizeof(link
));
2291 if (n
< 0 || n
>= (int)sizeof(link
))
2294 c
= strrchr(link
, '/');
2297 if (strncmp("pci", c
+1, strlen("pci")) != 0)
2300 sprintf(path
, "/sys/bus/pci/drivers/nvme/%s", ent
->d_name
);
2302 rp
= realpath(path
, NULL
);
2306 if (path_attached_to_hba(rp
, hba
->path
)) {
2307 printf(" NVMe under VMD : %s\n", rp
);
2316 static void print_found_intel_controllers(struct sys_dev
*elem
)
2318 for (; elem
; elem
= elem
->next
) {
2319 pr_err("found Intel(R) ");
2320 if (elem
->type
== SYS_DEV_SATA
)
2321 fprintf(stderr
, "SATA ");
2322 else if (elem
->type
== SYS_DEV_SAS
)
2323 fprintf(stderr
, "SAS ");
2324 else if (elem
->type
== SYS_DEV_NVME
)
2325 fprintf(stderr
, "NVMe ");
2327 if (elem
->type
== SYS_DEV_VMD
)
2328 fprintf(stderr
, "VMD domain");
2330 fprintf(stderr
, "RAID controller");
2333 fprintf(stderr
, " at %s", elem
->pci_id
);
2334 fprintf(stderr
, ".\n");
2339 static int ahci_get_port_count(const char *hba_path
, int *port_count
)
2346 if ((dir
= opendir(hba_path
)) == NULL
)
2349 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2352 if ((sscanf(ent
->d_name
, "ata%d", &host
) != 1) &&
2353 ((sscanf(ent
->d_name
, "host%d", &host
) != 1)))
2355 if (*port_count
== 0)
2357 else if (host
< host_base
)
2360 if (host
+ 1 > *port_count
+ host_base
)
2361 *port_count
= host
+ 1 - host_base
;
2367 static void print_imsm_capability(const struct imsm_orom
*orom
)
2369 printf(" Platform : Intel(R) ");
2370 if (orom
->capabilities
== 0 && orom
->driver_features
== 0)
2371 printf("Matrix Storage Manager\n");
2373 printf("Rapid Storage Technology%s\n",
2374 imsm_orom_is_enterprise(orom
) ? " enterprise" : "");
2375 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
2376 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
,
2377 orom
->minor_ver
, orom
->hotfix_ver
, orom
->build
);
2378 printf(" RAID Levels :%s%s%s%s%s\n",
2379 imsm_orom_has_raid0(orom
) ? " raid0" : "",
2380 imsm_orom_has_raid1(orom
) ? " raid1" : "",
2381 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
2382 imsm_orom_has_raid10(orom
) ? " raid10" : "",
2383 imsm_orom_has_raid5(orom
) ? " raid5" : "");
2384 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2385 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
2386 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
2387 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
2388 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
2389 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
2390 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
2391 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
2392 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
2393 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
2394 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
2395 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
2396 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
2397 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
2398 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
2399 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
2400 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
2401 printf(" 2TB volumes :%s supported\n",
2402 (orom
->attr
& IMSM_OROM_ATTR_2TB
)?"":" not");
2403 printf(" 2TB disks :%s supported\n",
2404 (orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
)?"":" not");
2405 printf(" Max Disks : %d\n", orom
->tds
);
2406 printf(" Max Volumes : %d per array, %d per %s\n",
2407 orom
->vpa
, orom
->vphba
,
2408 imsm_orom_is_nvme(orom
) ? "platform" : "controller");
2412 static void print_imsm_capability_export(const struct imsm_orom
*orom
)
2414 printf("MD_FIRMWARE_TYPE=imsm\n");
2415 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
2416 printf("IMSM_VERSION=%d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
2417 orom
->hotfix_ver
, orom
->build
);
2418 printf("IMSM_SUPPORTED_RAID_LEVELS=%s%s%s%s%s\n",
2419 imsm_orom_has_raid0(orom
) ? "raid0 " : "",
2420 imsm_orom_has_raid1(orom
) ? "raid1 " : "",
2421 imsm_orom_has_raid1e(orom
) ? "raid1e " : "",
2422 imsm_orom_has_raid5(orom
) ? "raid10 " : "",
2423 imsm_orom_has_raid10(orom
) ? "raid5 " : "");
2424 printf("IMSM_SUPPORTED_CHUNK_SIZES=%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2425 imsm_orom_has_chunk(orom
, 2) ? "2k " : "",
2426 imsm_orom_has_chunk(orom
, 4) ? "4k " : "",
2427 imsm_orom_has_chunk(orom
, 8) ? "8k " : "",
2428 imsm_orom_has_chunk(orom
, 16) ? "16k " : "",
2429 imsm_orom_has_chunk(orom
, 32) ? "32k " : "",
2430 imsm_orom_has_chunk(orom
, 64) ? "64k " : "",
2431 imsm_orom_has_chunk(orom
, 128) ? "128k " : "",
2432 imsm_orom_has_chunk(orom
, 256) ? "256k " : "",
2433 imsm_orom_has_chunk(orom
, 512) ? "512k " : "",
2434 imsm_orom_has_chunk(orom
, 1024*1) ? "1M " : "",
2435 imsm_orom_has_chunk(orom
, 1024*2) ? "2M " : "",
2436 imsm_orom_has_chunk(orom
, 1024*4) ? "4M " : "",
2437 imsm_orom_has_chunk(orom
, 1024*8) ? "8M " : "",
2438 imsm_orom_has_chunk(orom
, 1024*16) ? "16M " : "",
2439 imsm_orom_has_chunk(orom
, 1024*32) ? "32M " : "",
2440 imsm_orom_has_chunk(orom
, 1024*64) ? "64M " : "");
2441 printf("IMSM_2TB_VOLUMES=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB
) ? "yes" : "no");
2442 printf("IMSM_2TB_DISKS=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) ? "yes" : "no");
2443 printf("IMSM_MAX_DISKS=%d\n",orom
->tds
);
2444 printf("IMSM_MAX_VOLUMES_PER_ARRAY=%d\n",orom
->vpa
);
2445 printf("IMSM_MAX_VOLUMES_PER_CONTROLLER=%d\n",orom
->vphba
);
2448 static int detail_platform_imsm(int verbose
, int enumerate_only
, char *controller_path
)
2450 /* There are two components to imsm platform support, the ahci SATA
2451 * controller and the option-rom. To find the SATA controller we
2452 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
2453 * controller with the Intel vendor id is present. This approach
2454 * allows mdadm to leverage the kernel's ahci detection logic, with the
2455 * caveat that if ahci.ko is not loaded mdadm will not be able to
2456 * detect platform raid capabilities. The option-rom resides in a
2457 * platform "Adapter ROM". We scan for its signature to retrieve the
2458 * platform capabilities. If raid support is disabled in the BIOS the
2459 * option-rom capability structure will not be available.
2461 struct sys_dev
*list
, *hba
;
2466 if (enumerate_only
) {
2467 if (check_env("IMSM_NO_PLATFORM"))
2469 list
= find_intel_devices();
2472 for (hba
= list
; hba
; hba
= hba
->next
) {
2473 if (find_imsm_capability(hba
)) {
2483 list
= find_intel_devices();
2486 pr_err("no active Intel(R) RAID controller found.\n");
2488 } else if (verbose
> 0)
2489 print_found_intel_controllers(list
);
2491 for (hba
= list
; hba
; hba
= hba
->next
) {
2492 if (controller_path
&& (compare_paths(hba
->path
, controller_path
) != 0))
2494 if (!find_imsm_capability(hba
)) {
2496 pr_err("imsm capabilities not found for controller: %s (type %s)\n",
2497 hba
->type
== SYS_DEV_VMD
? vmd_domain_to_controller(hba
, buf
) : hba
->path
,
2498 get_sys_dev_type(hba
->type
));
2504 if (controller_path
&& result
== 1) {
2505 pr_err("no active Intel(R) RAID controller found under %s\n",
2510 const struct orom_entry
*entry
;
2512 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
2513 if (entry
->type
== SYS_DEV_VMD
) {
2514 print_imsm_capability(&entry
->orom
);
2515 printf(" 3rd party NVMe :%s supported\n",
2516 imsm_orom_has_tpv_support(&entry
->orom
)?"":" not");
2517 for (hba
= list
; hba
; hba
= hba
->next
) {
2518 if (hba
->type
== SYS_DEV_VMD
) {
2520 printf(" I/O Controller : %s (%s)\n",
2521 vmd_domain_to_controller(hba
, buf
), get_sys_dev_type(hba
->type
));
2522 if (print_vmd_attached_devs(hba
)) {
2524 pr_err("failed to get devices attached to VMD domain.\n");
2533 print_imsm_capability(&entry
->orom
);
2534 if (entry
->type
== SYS_DEV_NVME
) {
2535 for (hba
= list
; hba
; hba
= hba
->next
) {
2536 if (hba
->type
== SYS_DEV_NVME
)
2537 printf(" NVMe Device : %s\n", hba
->path
);
2543 struct devid_list
*devid
;
2544 for (devid
= entry
->devid_list
; devid
; devid
= devid
->next
) {
2545 hba
= device_by_id(devid
->devid
);
2549 printf(" I/O Controller : %s (%s)\n",
2550 hba
->path
, get_sys_dev_type(hba
->type
));
2551 if (hba
->type
== SYS_DEV_SATA
) {
2552 host_base
= ahci_get_port_count(hba
->path
, &port_count
);
2553 if (ahci_enumerate_ports(hba
->path
, port_count
, host_base
, verbose
)) {
2555 pr_err("failed to enumerate ports on SATA controller at %s.\n", hba
->pci_id
);
2566 static int export_detail_platform_imsm(int verbose
, char *controller_path
)
2568 struct sys_dev
*list
, *hba
;
2571 list
= find_intel_devices();
2574 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_INTEL_DEVICES\n");
2579 for (hba
= list
; hba
; hba
= hba
->next
) {
2580 if (controller_path
&& (compare_paths(hba
->path
,controller_path
) != 0))
2582 if (!find_imsm_capability(hba
) && verbose
> 0) {
2584 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_IMSM_CAPABLE_DEVICE_UNDER_%s\n",
2585 hba
->type
== SYS_DEV_VMD
? vmd_domain_to_controller(hba
, buf
) : hba
->path
);
2591 const struct orom_entry
*entry
;
2593 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
2594 if (entry
->type
== SYS_DEV_VMD
) {
2595 for (hba
= list
; hba
; hba
= hba
->next
)
2596 print_imsm_capability_export(&entry
->orom
);
2599 print_imsm_capability_export(&entry
->orom
);
2605 static int match_home_imsm(struct supertype
*st
, char *homehost
)
2607 /* the imsm metadata format does not specify any host
2608 * identification information. We return -1 since we can never
2609 * confirm nor deny whether a given array is "meant" for this
2610 * host. We rely on compare_super and the 'family_num' fields to
2611 * exclude member disks that do not belong, and we rely on
2612 * mdadm.conf to specify the arrays that should be assembled.
2613 * Auto-assembly may still pick up "foreign" arrays.
2619 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
2621 /* The uuid returned here is used for:
2622 * uuid to put into bitmap file (Create, Grow)
2623 * uuid for backup header when saving critical section (Grow)
2624 * comparing uuids when re-adding a device into an array
2625 * In these cases the uuid required is that of the data-array,
2626 * not the device-set.
2627 * uuid to recognise same set when adding a missing device back
2628 * to an array. This is a uuid for the device-set.
2630 * For each of these we can make do with a truncated
2631 * or hashed uuid rather than the original, as long as
2633 * In each case the uuid required is that of the data-array,
2634 * not the device-set.
2636 /* imsm does not track uuid's so we synthesis one using sha1 on
2637 * - The signature (Which is constant for all imsm array, but no matter)
2638 * - the orig_family_num of the container
2639 * - the index number of the volume
2640 * - the 'serial' number of the volume.
2641 * Hopefully these are all constant.
2643 struct intel_super
*super
= st
->sb
;
2646 struct sha1_ctx ctx
;
2647 struct imsm_dev
*dev
= NULL
;
2650 /* some mdadm versions failed to set ->orig_family_num, in which
2651 * case fall back to ->family_num. orig_family_num will be
2652 * fixed up with the first metadata update.
2654 family_num
= super
->anchor
->orig_family_num
;
2655 if (family_num
== 0)
2656 family_num
= super
->anchor
->family_num
;
2657 sha1_init_ctx(&ctx
);
2658 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
2659 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
2660 if (super
->current_vol
>= 0)
2661 dev
= get_imsm_dev(super
, super
->current_vol
);
2663 __u32 vol
= super
->current_vol
;
2664 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
2665 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
2667 sha1_finish_ctx(&ctx
, buf
);
2668 memcpy(uuid
, buf
, 4*4);
2673 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
2675 __u8
*v
= get_imsm_version(mpb
);
2676 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
2677 char major
[] = { 0, 0, 0 };
2678 char minor
[] = { 0 ,0, 0 };
2679 char patch
[] = { 0, 0, 0 };
2680 char *ver_parse
[] = { major
, minor
, patch
};
2684 while (*v
!= '\0' && v
< end
) {
2685 if (*v
!= '.' && j
< 2)
2686 ver_parse
[i
][j
++] = *v
;
2694 *m
= strtol(minor
, NULL
, 0);
2695 *p
= strtol(patch
, NULL
, 0);
2699 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
2701 /* migr_strip_size when repairing or initializing parity */
2702 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2703 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2705 switch (get_imsm_raid_level(map
)) {
2710 return 128*1024 >> 9;
2714 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
2716 /* migr_strip_size when rebuilding a degraded disk, no idea why
2717 * this is different than migr_strip_size_resync(), but it's good
2720 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2721 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2723 switch (get_imsm_raid_level(map
)) {
2726 if (map
->num_members
% map
->num_domains
== 0)
2727 return 128*1024 >> 9;
2731 return max((__u32
) 64*1024 >> 9, chunk
);
2733 return 128*1024 >> 9;
2737 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
2739 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2740 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2741 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
2742 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
2744 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
2747 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
2749 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2750 int level
= get_imsm_raid_level(lo
);
2752 if (level
== 1 || level
== 10) {
2753 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2755 return hi
->num_domains
;
2757 return num_stripes_per_unit_resync(dev
);
2760 static __u8
imsm_num_data_members(struct imsm_dev
*dev
, int second_map
)
2762 /* named 'imsm_' because raid0, raid1 and raid10
2763 * counter-intuitively have the same number of data disks
2765 struct imsm_map
*map
= get_imsm_map(dev
, second_map
);
2767 switch (get_imsm_raid_level(map
)) {
2769 return map
->num_members
;
2773 return map
->num_members
/2;
2775 return map
->num_members
- 1;
2777 dprintf("unsupported raid level\n");
2782 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
2784 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2785 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2787 switch(get_imsm_raid_level(map
)) {
2790 return chunk
* map
->num_domains
;
2792 return chunk
* map
->num_members
;
2798 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
2800 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2801 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2802 __u32 strip
= block
/ chunk
;
2804 switch (get_imsm_raid_level(map
)) {
2807 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
2808 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
2810 return vol_stripe
* chunk
+ block
% chunk
;
2812 __u32 stripe
= strip
/ (map
->num_members
- 1);
2814 return stripe
* chunk
+ block
% chunk
;
2821 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
2822 struct imsm_dev
*dev
)
2824 /* calculate the conversion factor between per member 'blocks'
2825 * (md/{resync,rebuild}_start) and imsm migration units, return
2826 * 0 for the 'not migrating' and 'unsupported migration' cases
2828 if (!dev
->vol
.migr_state
)
2831 switch (migr_type(dev
)) {
2832 case MIGR_GEN_MIGR
: {
2833 struct migr_record
*migr_rec
= super
->migr_rec
;
2834 return __le32_to_cpu(migr_rec
->blocks_per_unit
);
2839 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2840 __u32 stripes_per_unit
;
2841 __u32 blocks_per_unit
;
2850 /* yes, this is really the translation of migr_units to
2851 * per-member blocks in the 'resync' case
2853 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
2854 migr_chunk
= migr_strip_blocks_resync(dev
);
2855 disks
= imsm_num_data_members(dev
, MAP_0
);
2856 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
2857 stripe
= __le16_to_cpu(map
->blocks_per_strip
) * disks
;
2858 segment
= blocks_per_unit
/ stripe
;
2859 block_rel
= blocks_per_unit
- segment
* stripe
;
2860 parity_depth
= parity_segment_depth(dev
);
2861 block_map
= map_migr_block(dev
, block_rel
);
2862 return block_map
+ parity_depth
* segment
;
2864 case MIGR_REBUILD
: {
2865 __u32 stripes_per_unit
;
2868 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
2869 migr_chunk
= migr_strip_blocks_rebuild(dev
);
2870 return migr_chunk
* stripes_per_unit
;
2872 case MIGR_STATE_CHANGE
:
2878 static int imsm_level_to_layout(int level
)
2886 return ALGORITHM_LEFT_ASYMMETRIC
;
2893 /*******************************************************************************
2894 * Function: read_imsm_migr_rec
2895 * Description: Function reads imsm migration record from last sector of disk
2897 * fd : disk descriptor
2898 * super : metadata info
2902 ******************************************************************************/
2903 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
)
2906 unsigned int sector_size
= super
->sector_size
;
2907 unsigned long long dsize
;
2909 get_dev_size(fd
, NULL
, &dsize
);
2910 if (lseek64(fd
, dsize
- (sector_size
*MIGR_REC_SECTOR_POSITION
),
2912 pr_err("Cannot seek to anchor block: %s\n",
2916 if ((unsigned int)read(fd
, super
->migr_rec_buf
,
2917 MIGR_REC_BUF_SECTORS
*sector_size
) !=
2918 MIGR_REC_BUF_SECTORS
*sector_size
) {
2919 pr_err("Cannot read migr record block: %s\n",
2924 if (sector_size
== 4096)
2925 convert_from_4k_imsm_migr_rec(super
);
2931 static struct imsm_dev
*imsm_get_device_during_migration(
2932 struct intel_super
*super
)
2935 struct intel_dev
*dv
;
2937 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
2938 if (is_gen_migration(dv
->dev
))
2944 /*******************************************************************************
2945 * Function: load_imsm_migr_rec
2946 * Description: Function reads imsm migration record (it is stored at the last
2949 * super : imsm internal array info
2950 * info : general array info
2954 * -2 : no migration in progress
2955 ******************************************************************************/
2956 static int load_imsm_migr_rec(struct intel_super
*super
, struct mdinfo
*info
)
2963 struct imsm_dev
*dev
;
2964 struct imsm_map
*map
;
2967 /* find map under migration */
2968 dev
= imsm_get_device_during_migration(super
);
2969 /* nothing to load,no migration in progress?
2975 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
2976 /* read only from one of the first two slots */
2977 if ((sd
->disk
.raid_disk
< 0) ||
2978 (sd
->disk
.raid_disk
> 1))
2981 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
2982 fd
= dev_open(nm
, O_RDONLY
);
2988 map
= get_imsm_map(dev
, MAP_0
);
2989 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
2990 /* skip spare and failed disks
2994 /* read only from one of the first two slots */
2996 slot
= get_imsm_disk_slot(map
, dl
->index
);
2997 if (map
== NULL
|| slot
> 1 || slot
< 0)
2999 sprintf(nm
, "%d:%d", dl
->major
, dl
->minor
);
3000 fd
= dev_open(nm
, O_RDONLY
);
3007 retval
= read_imsm_migr_rec(fd
, super
);
3015 /*******************************************************************************
3016 * function: imsm_create_metadata_checkpoint_update
3017 * Description: It creates update for checkpoint change.
3019 * super : imsm internal array info
3020 * u : pointer to prepared update
3023 * If length is equal to 0, input pointer u contains no update
3024 ******************************************************************************/
3025 static int imsm_create_metadata_checkpoint_update(
3026 struct intel_super
*super
,
3027 struct imsm_update_general_migration_checkpoint
**u
)
3030 int update_memory_size
= 0;
3032 dprintf("(enter)\n");
3038 /* size of all update data without anchor */
3039 update_memory_size
=
3040 sizeof(struct imsm_update_general_migration_checkpoint
);
3042 *u
= xcalloc(1, update_memory_size
);
3044 dprintf("error: cannot get memory\n");
3047 (*u
)->type
= update_general_migration_checkpoint
;
3048 (*u
)->curr_migr_unit
= __le32_to_cpu(super
->migr_rec
->curr_migr_unit
);
3049 dprintf("prepared for %u\n", (*u
)->curr_migr_unit
);
3051 return update_memory_size
;
3054 static void imsm_update_metadata_locally(struct supertype
*st
,
3055 void *buf
, int len
);
3057 /*******************************************************************************
3058 * Function: write_imsm_migr_rec
3059 * Description: Function writes imsm migration record
3060 * (at the last sector of disk)
3062 * super : imsm internal array info
3066 ******************************************************************************/
3067 static int write_imsm_migr_rec(struct supertype
*st
)
3069 struct intel_super
*super
= st
->sb
;
3070 unsigned int sector_size
= super
->sector_size
;
3071 unsigned long long dsize
;
3077 struct imsm_update_general_migration_checkpoint
*u
;
3078 struct imsm_dev
*dev
;
3079 struct imsm_map
*map
;
3081 /* find map under migration */
3082 dev
= imsm_get_device_during_migration(super
);
3083 /* if no migration, write buffer anyway to clear migr_record
3084 * on disk based on first available device
3087 dev
= get_imsm_dev(super
, super
->current_vol
< 0 ? 0 :
3088 super
->current_vol
);
3090 map
= get_imsm_map(dev
, MAP_0
);
3092 if (sector_size
== 4096)
3093 convert_to_4k_imsm_migr_rec(super
);
3094 for (sd
= super
->disks
; sd
; sd
= sd
->next
) {
3097 /* skip failed and spare devices */
3100 /* write to 2 first slots only */
3102 slot
= get_imsm_disk_slot(map
, sd
->index
);
3103 if (map
== NULL
|| slot
> 1 || slot
< 0)
3106 sprintf(nm
, "%d:%d", sd
->major
, sd
->minor
);
3107 fd
= dev_open(nm
, O_RDWR
);
3110 get_dev_size(fd
, NULL
, &dsize
);
3111 if (lseek64(fd
, dsize
- (MIGR_REC_SECTOR_POSITION
*sector_size
),
3113 pr_err("Cannot seek to anchor block: %s\n",
3117 if ((unsigned int)write(fd
, super
->migr_rec_buf
,
3118 MIGR_REC_BUF_SECTORS
*sector_size
) !=
3119 MIGR_REC_BUF_SECTORS
*sector_size
) {
3120 pr_err("Cannot write migr record block: %s\n",
3127 if (sector_size
== 4096)
3128 convert_from_4k_imsm_migr_rec(super
);
3129 /* update checkpoint information in metadata */
3130 len
= imsm_create_metadata_checkpoint_update(super
, &u
);
3132 dprintf("imsm: Cannot prepare update\n");
3135 /* update metadata locally */
3136 imsm_update_metadata_locally(st
, u
, len
);
3137 /* and possibly remotely */
3138 if (st
->update_tail
) {
3139 append_metadata_update(st
, u
, len
);
3140 /* during reshape we do all work inside metadata handler
3141 * manage_reshape(), so metadata update has to be triggered
3144 flush_metadata_updates(st
);
3145 st
->update_tail
= &st
->updates
;
3156 /* spare/missing disks activations are not allowe when
3157 * array/container performs reshape operation, because
3158 * all arrays in container works on the same disks set
3160 int imsm_reshape_blocks_arrays_changes(struct intel_super
*super
)
3163 struct intel_dev
*i_dev
;
3164 struct imsm_dev
*dev
;
3166 /* check whole container
3168 for (i_dev
= super
->devlist
; i_dev
; i_dev
= i_dev
->next
) {
3170 if (is_gen_migration(dev
)) {
3171 /* No repair during any migration in container
3179 static unsigned long long imsm_component_size_aligment_check(int level
,
3181 unsigned int sector_size
,
3182 unsigned long long component_size
)
3184 unsigned int component_size_alligment
;
3186 /* check component size aligment
3188 component_size_alligment
= component_size
% (chunk_size
/sector_size
);
3190 dprintf("(Level: %i, chunk_size = %i, component_size = %llu), component_size_alligment = %u\n",
3191 level
, chunk_size
, component_size
,
3192 component_size_alligment
);
3194 if (component_size_alligment
&& (level
!= 1) && (level
!= UnSet
)) {
3195 dprintf("imsm: reported component size alligned from %llu ",
3197 component_size
-= component_size_alligment
;
3198 dprintf_cont("to %llu (%i).\n",
3199 component_size
, component_size_alligment
);
3202 return component_size
;
3205 static unsigned long long get_ppl_sector(struct intel_super
*super
, int dev_idx
)
3207 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
3208 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3210 return pba_of_lba0(map
) +
3211 (num_data_stripes(map
) * map
->blocks_per_strip
);
3214 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
3216 struct intel_super
*super
= st
->sb
;
3217 struct migr_record
*migr_rec
= super
->migr_rec
;
3218 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
3219 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3220 struct imsm_map
*prev_map
= get_imsm_map(dev
, MAP_1
);
3221 struct imsm_map
*map_to_analyse
= map
;
3223 int map_disks
= info
->array
.raid_disks
;
3225 memset(info
, 0, sizeof(*info
));
3227 map_to_analyse
= prev_map
;
3229 dl
= super
->current_disk
;
3231 info
->container_member
= super
->current_vol
;
3232 info
->array
.raid_disks
= map
->num_members
;
3233 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
3234 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
3235 info
->array
.md_minor
= -1;
3236 info
->array
.ctime
= 0;
3237 info
->array
.utime
= 0;
3238 info
->array
.chunk_size
=
3239 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
3240 info
->array
.state
= !(dev
->vol
.dirty
& RAIDVOL_DIRTY
);
3241 info
->custom_array_size
= __le32_to_cpu(dev
->size_high
);
3242 info
->custom_array_size
<<= 32;
3243 info
->custom_array_size
|= __le32_to_cpu(dev
->size_low
);
3244 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
3246 if (is_gen_migration(dev
)) {
3247 info
->reshape_active
= 1;
3248 info
->new_level
= get_imsm_raid_level(map
);
3249 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
3250 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
3251 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
3252 if (info
->delta_disks
) {
3253 /* this needs to be applied to every array
3256 info
->reshape_active
= CONTAINER_RESHAPE
;
3258 /* We shape information that we give to md might have to be
3259 * modify to cope with md's requirement for reshaping arrays.
3260 * For example, when reshaping a RAID0, md requires it to be
3261 * presented as a degraded RAID4.
3262 * Also if a RAID0 is migrating to a RAID5 we need to specify
3263 * the array as already being RAID5, but the 'before' layout
3264 * is a RAID4-like layout.
3266 switch (info
->array
.level
) {
3268 switch(info
->new_level
) {
3270 /* conversion is happening as RAID4 */
3271 info
->array
.level
= 4;
3272 info
->array
.raid_disks
+= 1;
3275 /* conversion is happening as RAID5 */
3276 info
->array
.level
= 5;
3277 info
->array
.layout
= ALGORITHM_PARITY_N
;
3278 info
->delta_disks
-= 1;
3281 /* FIXME error message */
3282 info
->array
.level
= UnSet
;
3288 info
->new_level
= UnSet
;
3289 info
->new_layout
= UnSet
;
3290 info
->new_chunk
= info
->array
.chunk_size
;
3291 info
->delta_disks
= 0;
3295 info
->disk
.major
= dl
->major
;
3296 info
->disk
.minor
= dl
->minor
;
3297 info
->disk
.number
= dl
->index
;
3298 info
->disk
.raid_disk
= get_imsm_disk_slot(map_to_analyse
,
3302 info
->data_offset
= pba_of_lba0(map_to_analyse
);
3304 if (info
->array
.level
== 5) {
3305 info
->component_size
= num_data_stripes(map_to_analyse
) *
3306 map_to_analyse
->blocks_per_strip
;
3308 info
->component_size
= blocks_per_member(map_to_analyse
);
3311 info
->component_size
= imsm_component_size_aligment_check(
3313 info
->array
.chunk_size
,
3315 info
->component_size
);
3316 info
->bb
.supported
= 1;
3318 memset(info
->uuid
, 0, sizeof(info
->uuid
));
3319 info
->recovery_start
= MaxSector
;
3321 if (info
->array
.level
== 5 &&
3322 (dev
->rwh_policy
== RWH_DISTRIBUTED
||
3323 dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)) {
3324 info
->consistency_policy
= CONSISTENCY_POLICY_PPL
;
3325 info
->ppl_sector
= get_ppl_sector(super
, super
->current_vol
);
3326 if (dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)
3327 info
->ppl_size
= MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9;
3329 info
->ppl_size
= (PPL_HEADER_SIZE
+ PPL_ENTRY_SPACE
)
3331 } else if (info
->array
.level
<= 0) {
3332 info
->consistency_policy
= CONSISTENCY_POLICY_NONE
;
3334 info
->consistency_policy
= CONSISTENCY_POLICY_RESYNC
;
3337 info
->reshape_progress
= 0;
3338 info
->resync_start
= MaxSector
;
3339 if ((map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
3340 !(info
->array
.state
& 1)) &&
3341 imsm_reshape_blocks_arrays_changes(super
) == 0) {
3342 info
->resync_start
= 0;
3344 if (dev
->vol
.migr_state
) {
3345 switch (migr_type(dev
)) {
3348 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
3350 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
3352 info
->resync_start
= blocks_per_unit
* units
;
3355 case MIGR_GEN_MIGR
: {
3356 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
3358 __u64 units
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
3359 unsigned long long array_blocks
;
3362 if (__le32_to_cpu(migr_rec
->ascending_migr
) &&
3364 (__le32_to_cpu(migr_rec
->num_migr_units
)-1)) &&
3365 (super
->migr_rec
->rec_status
==
3366 __cpu_to_le32(UNIT_SRC_IN_CP_AREA
)))
3369 info
->reshape_progress
= blocks_per_unit
* units
;
3371 dprintf("IMSM: General Migration checkpoint : %llu (%llu) -> read reshape progress : %llu\n",
3372 (unsigned long long)units
,
3373 (unsigned long long)blocks_per_unit
,
3374 info
->reshape_progress
);
3376 used_disks
= imsm_num_data_members(dev
, MAP_1
);
3377 if (used_disks
> 0) {
3378 array_blocks
= blocks_per_member(map
) *
3380 info
->custom_array_size
=
3381 round_size_to_mb(array_blocks
,
3387 /* we could emulate the checkpointing of
3388 * 'sync_action=check' migrations, but for now
3389 * we just immediately complete them
3392 /* this is handled by container_content_imsm() */
3393 case MIGR_STATE_CHANGE
:
3394 /* FIXME handle other migrations */
3396 /* we are not dirty, so... */
3397 info
->resync_start
= MaxSector
;
3401 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
3402 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
3404 info
->array
.major_version
= -1;
3405 info
->array
.minor_version
= -2;
3406 sprintf(info
->text_version
, "/%s/%d", st
->container_devnm
, info
->container_member
);
3407 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
3408 uuid_from_super_imsm(st
, info
->uuid
);
3412 for (i
=0; i
<map_disks
; i
++) {
3414 if (i
< info
->array
.raid_disks
) {
3415 struct imsm_disk
*dsk
;
3416 j
= get_imsm_disk_idx(dev
, i
, MAP_X
);
3417 dsk
= get_imsm_disk(super
, j
);
3418 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
3425 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
3426 int failed
, int look_in_map
);
3428 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
3431 static void manage_second_map(struct intel_super
*super
, struct imsm_dev
*dev
)
3433 if (is_gen_migration(dev
)) {
3436 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
3438 failed
= imsm_count_failed(super
, dev
, MAP_1
);
3439 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_1
);
3440 if (map2
->map_state
!= map_state
) {
3441 map2
->map_state
= map_state
;
3442 super
->updates_pending
++;
3447 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
3451 for (d
= super
->missing
; d
; d
= d
->next
)
3452 if (d
->index
== index
)
3457 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
3459 struct intel_super
*super
= st
->sb
;
3460 struct imsm_disk
*disk
;
3461 int map_disks
= info
->array
.raid_disks
;
3462 int max_enough
= -1;
3464 struct imsm_super
*mpb
;
3466 if (super
->current_vol
>= 0) {
3467 getinfo_super_imsm_volume(st
, info
, map
);
3470 memset(info
, 0, sizeof(*info
));
3472 /* Set raid_disks to zero so that Assemble will always pull in valid
3475 info
->array
.raid_disks
= 0;
3476 info
->array
.level
= LEVEL_CONTAINER
;
3477 info
->array
.layout
= 0;
3478 info
->array
.md_minor
= -1;
3479 info
->array
.ctime
= 0; /* N/A for imsm */
3480 info
->array
.utime
= 0;
3481 info
->array
.chunk_size
= 0;
3483 info
->disk
.major
= 0;
3484 info
->disk
.minor
= 0;
3485 info
->disk
.raid_disk
= -1;
3486 info
->reshape_active
= 0;
3487 info
->array
.major_version
= -1;
3488 info
->array
.minor_version
= -2;
3489 strcpy(info
->text_version
, "imsm");
3490 info
->safe_mode_delay
= 0;
3491 info
->disk
.number
= -1;
3492 info
->disk
.state
= 0;
3494 info
->recovery_start
= MaxSector
;
3495 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
3496 info
->bb
.supported
= 1;
3498 /* do we have the all the insync disks that we expect? */
3499 mpb
= super
->anchor
;
3500 info
->events
= __le32_to_cpu(mpb
->generation_num
);
3502 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
3503 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
3504 int failed
, enough
, j
, missing
= 0;
3505 struct imsm_map
*map
;
3508 failed
= imsm_count_failed(super
, dev
, MAP_0
);
3509 state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
3510 map
= get_imsm_map(dev
, MAP_0
);
3512 /* any newly missing disks?
3513 * (catches single-degraded vs double-degraded)
3515 for (j
= 0; j
< map
->num_members
; j
++) {
3516 __u32 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
3517 __u32 idx
= ord_to_idx(ord
);
3519 if (super
->disks
&& super
->disks
->index
== (int)idx
)
3520 info
->disk
.raid_disk
= j
;
3522 if (!(ord
& IMSM_ORD_REBUILD
) &&
3523 get_imsm_missing(super
, idx
)) {
3529 if (state
== IMSM_T_STATE_FAILED
)
3531 else if (state
== IMSM_T_STATE_DEGRADED
&&
3532 (state
!= map
->map_state
|| missing
))
3534 else /* we're normal, or already degraded */
3536 if (is_gen_migration(dev
) && missing
) {
3537 /* during general migration we need all disks
3538 * that process is running on.
3539 * No new missing disk is allowed.
3543 /* no more checks necessary
3547 /* in the missing/failed disk case check to see
3548 * if at least one array is runnable
3550 max_enough
= max(max_enough
, enough
);
3552 dprintf("enough: %d\n", max_enough
);
3553 info
->container_enough
= max_enough
;
3556 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
3558 disk
= &super
->disks
->disk
;
3559 info
->data_offset
= total_blocks(&super
->disks
->disk
) - reserved
;
3560 info
->component_size
= reserved
;
3561 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
3562 /* we don't change info->disk.raid_disk here because
3563 * this state will be finalized in mdmon after we have
3564 * found the 'most fresh' version of the metadata
3566 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
3567 info
->disk
.state
|= (is_spare(disk
) || is_journal(disk
)) ?
3568 0 : (1 << MD_DISK_SYNC
);
3571 /* only call uuid_from_super_imsm when this disk is part of a populated container,
3572 * ->compare_super may have updated the 'num_raid_devs' field for spares
3574 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
3575 uuid_from_super_imsm(st
, info
->uuid
);
3577 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
3579 /* I don't know how to compute 'map' on imsm, so use safe default */
3582 for (i
= 0; i
< map_disks
; i
++)
3588 /* allocates memory and fills disk in mdinfo structure
3589 * for each disk in array */
3590 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
3592 struct mdinfo
*mddev
;
3593 struct intel_super
*super
= st
->sb
;
3594 struct imsm_disk
*disk
;
3597 if (!super
|| !super
->disks
)
3600 mddev
= xcalloc(1, sizeof(*mddev
));
3604 tmp
= xcalloc(1, sizeof(*tmp
));
3606 tmp
->next
= mddev
->devs
;
3608 tmp
->disk
.number
= count
++;
3609 tmp
->disk
.major
= dl
->major
;
3610 tmp
->disk
.minor
= dl
->minor
;
3611 tmp
->disk
.state
= is_configured(disk
) ?
3612 (1 << MD_DISK_ACTIVE
) : 0;
3613 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
3614 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
3615 tmp
->disk
.raid_disk
= -1;
3621 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
3622 char *update
, char *devname
, int verbose
,
3623 int uuid_set
, char *homehost
)
3625 /* For 'assemble' and 'force' we need to return non-zero if any
3626 * change was made. For others, the return value is ignored.
3627 * Update options are:
3628 * force-one : This device looks a bit old but needs to be included,
3629 * update age info appropriately.
3630 * assemble: clear any 'faulty' flag to allow this device to
3632 * force-array: Array is degraded but being forced, mark it clean
3633 * if that will be needed to assemble it.
3635 * newdev: not used ????
3636 * grow: Array has gained a new device - this is currently for
3638 * resync: mark as dirty so a resync will happen.
3639 * name: update the name - preserving the homehost
3640 * uuid: Change the uuid of the array to match watch is given
3642 * Following are not relevant for this imsm:
3643 * sparc2.2 : update from old dodgey metadata
3644 * super-minor: change the preferred_minor number
3645 * summaries: update redundant counters.
3646 * homehost: update the recorded homehost
3647 * _reshape_progress: record new reshape_progress position.
3650 struct intel_super
*super
= st
->sb
;
3651 struct imsm_super
*mpb
;
3653 /* we can only update container info */
3654 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
3657 mpb
= super
->anchor
;
3659 if (strcmp(update
, "uuid") == 0) {
3660 /* We take this to mean that the family_num should be updated.
3661 * However that is much smaller than the uuid so we cannot really
3662 * allow an explicit uuid to be given. And it is hard to reliably
3664 * So if !uuid_set we know the current uuid is random and just used
3665 * the first 'int' and copy it to the other 3 positions.
3666 * Otherwise we require the 4 'int's to be the same as would be the
3667 * case if we are using a random uuid. So an explicit uuid will be
3668 * accepted as long as all for ints are the same... which shouldn't hurt
3671 info
->uuid
[1] = info
->uuid
[2] = info
->uuid
[3] = info
->uuid
[0];
3674 if (info
->uuid
[0] != info
->uuid
[1] ||
3675 info
->uuid
[1] != info
->uuid
[2] ||
3676 info
->uuid
[2] != info
->uuid
[3])
3682 mpb
->orig_family_num
= info
->uuid
[0];
3683 } else if (strcmp(update
, "assemble") == 0)
3688 /* successful update? recompute checksum */
3690 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
3695 static size_t disks_to_mpb_size(int disks
)
3699 size
= sizeof(struct imsm_super
);
3700 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
3701 size
+= 2 * sizeof(struct imsm_dev
);
3702 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
3703 size
+= (4 - 2) * sizeof(struct imsm_map
);
3704 /* 4 possible disk_ord_tbl's */
3705 size
+= 4 * (disks
- 1) * sizeof(__u32
);
3706 /* maximum bbm log */
3707 size
+= sizeof(struct bbm_log
);
3712 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
,
3713 unsigned long long data_offset
)
3715 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
3718 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
3721 static void free_devlist(struct intel_super
*super
)
3723 struct intel_dev
*dv
;
3725 while (super
->devlist
) {
3726 dv
= super
->devlist
->next
;
3727 free(super
->devlist
->dev
);
3728 free(super
->devlist
);
3729 super
->devlist
= dv
;
3733 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
3735 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
3738 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
)
3742 * 0 same, or first was empty, and second was copied
3743 * 1 second had wrong number
3745 * 3 wrong other info
3747 struct intel_super
*first
= st
->sb
;
3748 struct intel_super
*sec
= tst
->sb
;
3755 /* in platform dependent environment test if the disks
3756 * use the same Intel hba
3757 * If not on Intel hba at all, allow anything.
3759 if (!check_env("IMSM_NO_PLATFORM") && first
->hba
&& sec
->hba
) {
3760 if (first
->hba
->type
!= sec
->hba
->type
) {
3762 "HBAs of devices do not match %s != %s\n",
3763 get_sys_dev_type(first
->hba
->type
),
3764 get_sys_dev_type(sec
->hba
->type
));
3767 if (first
->orom
!= sec
->orom
) {
3769 "HBAs of devices do not match %s != %s\n",
3770 first
->hba
->pci_id
, sec
->hba
->pci_id
);
3775 /* if an anchor does not have num_raid_devs set then it is a free
3778 if (first
->anchor
->num_raid_devs
> 0 &&
3779 sec
->anchor
->num_raid_devs
> 0) {
3780 /* Determine if these disks might ever have been
3781 * related. Further disambiguation can only take place
3782 * in load_super_imsm_all
3784 __u32 first_family
= first
->anchor
->orig_family_num
;
3785 __u32 sec_family
= sec
->anchor
->orig_family_num
;
3787 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
3788 MAX_SIGNATURE_LENGTH
) != 0)
3791 if (first_family
== 0)
3792 first_family
= first
->anchor
->family_num
;
3793 if (sec_family
== 0)
3794 sec_family
= sec
->anchor
->family_num
;
3796 if (first_family
!= sec_family
)
3801 /* if 'first' is a spare promote it to a populated mpb with sec's
3804 if (first
->anchor
->num_raid_devs
== 0 &&
3805 sec
->anchor
->num_raid_devs
> 0) {
3807 struct intel_dev
*dv
;
3808 struct imsm_dev
*dev
;
3810 /* we need to copy raid device info from sec if an allocation
3811 * fails here we don't associate the spare
3813 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++) {
3814 dv
= xmalloc(sizeof(*dv
));
3815 dev
= xmalloc(sizeof_imsm_dev(get_imsm_dev(sec
, i
), 1));
3818 dv
->next
= first
->devlist
;
3819 first
->devlist
= dv
;
3821 if (i
< sec
->anchor
->num_raid_devs
) {
3822 /* allocation failure */
3823 free_devlist(first
);
3824 pr_err("imsm: failed to associate spare\n");
3827 first
->anchor
->num_raid_devs
= sec
->anchor
->num_raid_devs
;
3828 first
->anchor
->orig_family_num
= sec
->anchor
->orig_family_num
;
3829 first
->anchor
->family_num
= sec
->anchor
->family_num
;
3830 memcpy(first
->anchor
->sig
, sec
->anchor
->sig
, MAX_SIGNATURE_LENGTH
);
3831 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++)
3832 imsm_copy_dev(get_imsm_dev(first
, i
), get_imsm_dev(sec
, i
));
3838 static void fd2devname(int fd
, char *name
)
3842 char dname
[PATH_MAX
];
3847 if (fstat(fd
, &st
) != 0)
3849 sprintf(path
, "/sys/dev/block/%d:%d",
3850 major(st
.st_rdev
), minor(st
.st_rdev
));
3852 rv
= readlink(path
, dname
, sizeof(dname
)-1);
3857 nm
= strrchr(dname
, '/');
3860 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
3864 static int nvme_get_serial(int fd
, void *buf
, size_t buf_len
)
3867 char *name
= fd2kname(fd
);
3872 if (strncmp(name
, "nvme", 4) != 0)
3875 snprintf(path
, sizeof(path
) - 1, "/sys/block/%s/device/serial", name
);
3877 return load_sys(path
, buf
, buf_len
);
3880 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
3882 static int imsm_read_serial(int fd
, char *devname
,
3883 __u8 serial
[MAX_RAID_SERIAL_LEN
])
3892 memset(buf
, 0, sizeof(buf
));
3894 rv
= nvme_get_serial(fd
, buf
, sizeof(buf
));
3897 rv
= scsi_get_serial(fd
, buf
, sizeof(buf
));
3899 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
3900 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3901 fd2devname(fd
, (char *) serial
);
3907 pr_err("Failed to retrieve serial for %s\n",
3912 /* trim all whitespace and non-printable characters and convert
3915 for (i
= 0, dest
= buf
; i
< sizeof(buf
) && buf
[i
]; i
++) {
3918 /* ':' is reserved for use in placeholder serial
3919 * numbers for missing disks
3930 /* truncate leading characters */
3931 if (len
> MAX_RAID_SERIAL_LEN
) {
3932 dest
+= len
- MAX_RAID_SERIAL_LEN
;
3933 len
= MAX_RAID_SERIAL_LEN
;
3936 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3937 memcpy(serial
, dest
, len
);
3942 static int serialcmp(__u8
*s1
, __u8
*s2
)
3944 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
3947 static void serialcpy(__u8
*dest
, __u8
*src
)
3949 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
3952 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
3956 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3957 if (serialcmp(dl
->serial
, serial
) == 0)
3963 static struct imsm_disk
*
3964 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
3968 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3969 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
3971 if (serialcmp(disk
->serial
, serial
) == 0) {
3982 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3984 struct imsm_disk
*disk
;
3989 __u8 serial
[MAX_RAID_SERIAL_LEN
];
3991 rv
= imsm_read_serial(fd
, devname
, serial
);
3996 dl
= xcalloc(1, sizeof(*dl
));
3999 dl
->major
= major(stb
.st_rdev
);
4000 dl
->minor
= minor(stb
.st_rdev
);
4001 dl
->next
= super
->disks
;
4002 dl
->fd
= keep_fd
? fd
: -1;
4003 assert(super
->disks
== NULL
);
4005 serialcpy(dl
->serial
, serial
);
4008 fd2devname(fd
, name
);
4010 dl
->devname
= xstrdup(devname
);
4012 dl
->devname
= xstrdup(name
);
4014 /* look up this disk's index in the current anchor */
4015 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
4018 /* only set index on disks that are a member of a
4019 * populated contianer, i.e. one with raid_devs
4021 if (is_failed(&dl
->disk
))
4023 else if (is_spare(&dl
->disk
) || is_journal(&dl
->disk
))
4030 /* When migrating map0 contains the 'destination' state while map1
4031 * contains the current state. When not migrating map0 contains the
4032 * current state. This routine assumes that map[0].map_state is set to
4033 * the current array state before being called.
4035 * Migration is indicated by one of the following states
4036 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
4037 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
4038 * map1state=unitialized)
4039 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
4041 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
4042 * map1state=degraded)
4043 * 5/ Migration (mig_state=1 migr_type=MIGR_GEN_MIGR map0state=normal
4046 static void migrate(struct imsm_dev
*dev
, struct intel_super
*super
,
4047 __u8 to_state
, int migr_type
)
4049 struct imsm_map
*dest
;
4050 struct imsm_map
*src
= get_imsm_map(dev
, MAP_0
);
4052 dev
->vol
.migr_state
= 1;
4053 set_migr_type(dev
, migr_type
);
4054 dev
->vol
.curr_migr_unit
= 0;
4055 dest
= get_imsm_map(dev
, MAP_1
);
4057 /* duplicate and then set the target end state in map[0] */
4058 memcpy(dest
, src
, sizeof_imsm_map(src
));
4059 if (migr_type
== MIGR_GEN_MIGR
) {
4063 for (i
= 0; i
< src
->num_members
; i
++) {
4064 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
4065 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
4069 if (migr_type
== MIGR_GEN_MIGR
)
4070 /* Clear migration record */
4071 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
4073 src
->map_state
= to_state
;
4076 static void end_migration(struct imsm_dev
*dev
, struct intel_super
*super
,
4079 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
4080 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
== 0 ?
4084 /* merge any IMSM_ORD_REBUILD bits that were not successfully
4085 * completed in the last migration.
4087 * FIXME add support for raid-level-migration
4089 if (map_state
!= map
->map_state
&& (is_gen_migration(dev
) == 0) &&
4090 prev
->map_state
!= IMSM_T_STATE_UNINITIALIZED
) {
4091 /* when final map state is other than expected
4092 * merge maps (not for migration)
4096 for (i
= 0; i
< prev
->num_members
; i
++)
4097 for (j
= 0; j
< map
->num_members
; j
++)
4098 /* during online capacity expansion
4099 * disks position can be changed
4100 * if takeover is used
4102 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
4103 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
4104 map
->disk_ord_tbl
[j
] |=
4105 prev
->disk_ord_tbl
[i
];
4108 failed
= imsm_count_failed(super
, dev
, MAP_0
);
4109 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
4112 dev
->vol
.migr_state
= 0;
4113 set_migr_type(dev
, 0);
4114 dev
->vol
.curr_migr_unit
= 0;
4115 map
->map_state
= map_state
;
4118 static int parse_raid_devices(struct intel_super
*super
)
4121 struct imsm_dev
*dev_new
;
4122 size_t len
, len_migr
;
4124 size_t space_needed
= 0;
4125 struct imsm_super
*mpb
= super
->anchor
;
4127 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
4128 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
4129 struct intel_dev
*dv
;
4131 len
= sizeof_imsm_dev(dev_iter
, 0);
4132 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
4134 space_needed
+= len_migr
- len
;
4136 dv
= xmalloc(sizeof(*dv
));
4137 if (max_len
< len_migr
)
4139 if (max_len
> len_migr
)
4140 space_needed
+= max_len
- len_migr
;
4141 dev_new
= xmalloc(max_len
);
4142 imsm_copy_dev(dev_new
, dev_iter
);
4145 dv
->next
= super
->devlist
;
4146 super
->devlist
= dv
;
4149 /* ensure that super->buf is large enough when all raid devices
4152 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
4155 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
,
4156 super
->sector_size
);
4157 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, len
) != 0)
4160 memcpy(buf
, super
->buf
, super
->len
);
4161 memset(buf
+ super
->len
, 0, len
- super
->len
);
4167 super
->extra_space
+= space_needed
;
4172 /*******************************************************************************
4173 * Function: check_mpb_migr_compatibility
4174 * Description: Function checks for unsupported migration features:
4175 * - migration optimization area (pba_of_lba0)
4176 * - descending reshape (ascending_migr)
4178 * super : imsm metadata information
4180 * 0 : migration is compatible
4181 * -1 : migration is not compatible
4182 ******************************************************************************/
4183 int check_mpb_migr_compatibility(struct intel_super
*super
)
4185 struct imsm_map
*map0
, *map1
;
4186 struct migr_record
*migr_rec
= super
->migr_rec
;
4189 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
4190 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
4193 dev_iter
->vol
.migr_state
== 1 &&
4194 dev_iter
->vol
.migr_type
== MIGR_GEN_MIGR
) {
4195 /* This device is migrating */
4196 map0
= get_imsm_map(dev_iter
, MAP_0
);
4197 map1
= get_imsm_map(dev_iter
, MAP_1
);
4198 if (pba_of_lba0(map0
) != pba_of_lba0(map1
))
4199 /* migration optimization area was used */
4201 if (migr_rec
->ascending_migr
== 0 &&
4202 migr_rec
->dest_depth_per_unit
> 0)
4203 /* descending reshape not supported yet */
4210 static void __free_imsm(struct intel_super
*super
, int free_disks
);
4212 /* load_imsm_mpb - read matrix metadata
4213 * allocates super->mpb to be freed by free_imsm
4215 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
4217 unsigned long long dsize
;
4218 unsigned long long sectors
;
4219 unsigned int sector_size
= super
->sector_size
;
4221 struct imsm_super
*anchor
;
4224 get_dev_size(fd
, NULL
, &dsize
);
4225 if (dsize
< 2*sector_size
) {
4227 pr_err("%s: device to small for imsm\n",
4232 if (lseek64(fd
, dsize
- (sector_size
* 2), SEEK_SET
) < 0) {
4234 pr_err("Cannot seek to anchor block on %s: %s\n",
4235 devname
, strerror(errno
));
4239 if (posix_memalign((void **)&anchor
, sector_size
, sector_size
) != 0) {
4241 pr_err("Failed to allocate imsm anchor buffer on %s\n", devname
);
4244 if ((unsigned int)read(fd
, anchor
, sector_size
) != sector_size
) {
4246 pr_err("Cannot read anchor block on %s: %s\n",
4247 devname
, strerror(errno
));
4252 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
4254 pr_err("no IMSM anchor on %s\n", devname
);
4259 __free_imsm(super
, 0);
4260 /* reload capability and hba */
4262 /* capability and hba must be updated with new super allocation */
4263 find_intel_hba_capability(fd
, super
, devname
);
4264 super
->len
= ROUND_UP(anchor
->mpb_size
, sector_size
);
4265 if (posix_memalign(&super
->buf
, MAX_SECTOR_SIZE
, super
->len
) != 0) {
4267 pr_err("unable to allocate %zu byte mpb buffer\n",
4272 memcpy(super
->buf
, anchor
, sector_size
);
4274 sectors
= mpb_sectors(anchor
, sector_size
) - 1;
4277 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
4278 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
) != 0) {
4279 pr_err("could not allocate migr_rec buffer\n");
4283 super
->clean_migration_record_by_mdmon
= 0;
4286 check_sum
= __gen_imsm_checksum(super
->anchor
);
4287 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
4289 pr_err("IMSM checksum %x != %x on %s\n",
4291 __le32_to_cpu(super
->anchor
->check_sum
),
4299 /* read the extended mpb */
4300 if (lseek64(fd
, dsize
- (sector_size
* (2 + sectors
)), SEEK_SET
) < 0) {
4302 pr_err("Cannot seek to extended mpb on %s: %s\n",
4303 devname
, strerror(errno
));
4307 if ((unsigned int)read(fd
, super
->buf
+ sector_size
,
4308 super
->len
- sector_size
) != super
->len
- sector_size
) {
4310 pr_err("Cannot read extended mpb on %s: %s\n",
4311 devname
, strerror(errno
));
4315 check_sum
= __gen_imsm_checksum(super
->anchor
);
4316 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
4318 pr_err("IMSM checksum %x != %x on %s\n",
4319 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
4327 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
);
4329 /* clears hi bits in metadata if MPB_ATTRIB_2TB_DISK not set */
4330 static void clear_hi(struct intel_super
*super
)
4332 struct imsm_super
*mpb
= super
->anchor
;
4334 if (mpb
->attributes
& MPB_ATTRIB_2TB_DISK
)
4336 for (i
= 0; i
< mpb
->num_disks
; ++i
) {
4337 struct imsm_disk
*disk
= &mpb
->disk
[i
];
4338 disk
->total_blocks_hi
= 0;
4340 for (i
= 0; i
< mpb
->num_raid_devs
; ++i
) {
4341 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
4344 for (n
= 0; n
< 2; ++n
) {
4345 struct imsm_map
*map
= get_imsm_map(dev
, n
);
4348 map
->pba_of_lba0_hi
= 0;
4349 map
->blocks_per_member_hi
= 0;
4350 map
->num_data_stripes_hi
= 0;
4356 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
4360 err
= load_imsm_mpb(fd
, super
, devname
);
4363 if (super
->sector_size
== 4096)
4364 convert_from_4k(super
);
4365 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
4368 err
= parse_raid_devices(super
);
4371 err
= load_bbm_log(super
);
4376 static void __free_imsm_disk(struct dl
*d
)
4388 static void free_imsm_disks(struct intel_super
*super
)
4392 while (super
->disks
) {
4394 super
->disks
= d
->next
;
4395 __free_imsm_disk(d
);
4397 while (super
->disk_mgmt_list
) {
4398 d
= super
->disk_mgmt_list
;
4399 super
->disk_mgmt_list
= d
->next
;
4400 __free_imsm_disk(d
);
4402 while (super
->missing
) {
4404 super
->missing
= d
->next
;
4405 __free_imsm_disk(d
);
4410 /* free all the pieces hanging off of a super pointer */
4411 static void __free_imsm(struct intel_super
*super
, int free_disks
)
4413 struct intel_hba
*elem
, *next
;
4419 /* unlink capability description */
4421 if (super
->migr_rec_buf
) {
4422 free(super
->migr_rec_buf
);
4423 super
->migr_rec_buf
= NULL
;
4426 free_imsm_disks(super
);
4427 free_devlist(super
);
4431 free((void *)elem
->path
);
4437 free(super
->bbm_log
);
4441 static void free_imsm(struct intel_super
*super
)
4443 __free_imsm(super
, 1);
4444 free(super
->bb
.entries
);
4448 static void free_super_imsm(struct supertype
*st
)
4450 struct intel_super
*super
= st
->sb
;
4459 static struct intel_super
*alloc_super(void)
4461 struct intel_super
*super
= xcalloc(1, sizeof(*super
));
4463 super
->current_vol
= -1;
4464 super
->create_offset
= ~((unsigned long long) 0);
4466 super
->bb
.entries
= xmalloc(BBM_LOG_MAX_ENTRIES
*
4467 sizeof(struct md_bb_entry
));
4468 if (!super
->bb
.entries
) {
4477 * find and allocate hba and OROM/EFI based on valid fd of RAID component device
4479 static int find_intel_hba_capability(int fd
, struct intel_super
*super
, char *devname
)
4481 struct sys_dev
*hba_name
;
4484 if (fd
< 0 || check_env("IMSM_NO_PLATFORM")) {
4489 hba_name
= find_disk_attached_hba(fd
, NULL
);
4492 pr_err("%s is not attached to Intel(R) RAID controller.\n",
4496 rv
= attach_hba_to_super(super
, hba_name
);
4499 struct intel_hba
*hba
= super
->hba
;
4501 pr_err("%s is attached to Intel(R) %s %s (%s),\n"
4502 " but the container is assigned to Intel(R) %s %s (",
4504 get_sys_dev_type(hba_name
->type
),
4505 hba_name
->type
== SYS_DEV_VMD
? "domain" : "RAID controller",
4506 hba_name
->pci_id
? : "Err!",
4507 get_sys_dev_type(super
->hba
->type
),
4508 hba
->type
== SYS_DEV_VMD
? "domain" : "RAID controller");
4511 fprintf(stderr
, "%s", hba
->pci_id
? : "Err!");
4513 fprintf(stderr
, ", ");
4516 fprintf(stderr
, ").\n"
4517 " Mixing devices attached to different controllers is not allowed.\n");
4521 super
->orom
= find_imsm_capability(hba_name
);
4528 /* find_missing - helper routine for load_super_imsm_all that identifies
4529 * disks that have disappeared from the system. This routine relies on
4530 * the mpb being uptodate, which it is at load time.
4532 static int find_missing(struct intel_super
*super
)
4535 struct imsm_super
*mpb
= super
->anchor
;
4537 struct imsm_disk
*disk
;
4539 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4540 disk
= __get_imsm_disk(mpb
, i
);
4541 dl
= serial_to_dl(disk
->serial
, super
);
4545 dl
= xmalloc(sizeof(*dl
));
4549 dl
->devname
= xstrdup("missing");
4551 serialcpy(dl
->serial
, disk
->serial
);
4554 dl
->next
= super
->missing
;
4555 super
->missing
= dl
;
4561 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
4563 struct intel_disk
*idisk
= disk_list
;
4566 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
4568 idisk
= idisk
->next
;
4574 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
4575 struct intel_super
*super
,
4576 struct intel_disk
**disk_list
)
4578 struct imsm_disk
*d
= &super
->disks
->disk
;
4579 struct imsm_super
*mpb
= super
->anchor
;
4582 for (i
= 0; i
< tbl_size
; i
++) {
4583 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
4584 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
4586 if (tbl_mpb
->family_num
== mpb
->family_num
) {
4587 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
4588 dprintf("mpb from %d:%d matches %d:%d\n",
4589 super
->disks
->major
,
4590 super
->disks
->minor
,
4591 table
[i
]->disks
->major
,
4592 table
[i
]->disks
->minor
);
4596 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
4597 is_configured(d
) == is_configured(tbl_d
)) &&
4598 tbl_mpb
->generation_num
< mpb
->generation_num
) {
4599 /* current version of the mpb is a
4600 * better candidate than the one in
4601 * super_table, but copy over "cross
4602 * generational" status
4604 struct intel_disk
*idisk
;
4606 dprintf("mpb from %d:%d replaces %d:%d\n",
4607 super
->disks
->major
,
4608 super
->disks
->minor
,
4609 table
[i
]->disks
->major
,
4610 table
[i
]->disks
->minor
);
4612 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
4613 if (idisk
&& is_failed(&idisk
->disk
))
4614 tbl_d
->status
|= FAILED_DISK
;
4617 struct intel_disk
*idisk
;
4618 struct imsm_disk
*disk
;
4620 /* tbl_mpb is more up to date, but copy
4621 * over cross generational status before
4624 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
4625 if (disk
&& is_failed(disk
))
4626 d
->status
|= FAILED_DISK
;
4628 idisk
= disk_list_get(d
->serial
, *disk_list
);
4631 if (disk
&& is_configured(disk
))
4632 idisk
->disk
.status
|= CONFIGURED_DISK
;
4635 dprintf("mpb from %d:%d prefer %d:%d\n",
4636 super
->disks
->major
,
4637 super
->disks
->minor
,
4638 table
[i
]->disks
->major
,
4639 table
[i
]->disks
->minor
);
4647 table
[tbl_size
++] = super
;
4651 /* update/extend the merged list of imsm_disk records */
4652 for (j
= 0; j
< mpb
->num_disks
; j
++) {
4653 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
4654 struct intel_disk
*idisk
;
4656 idisk
= disk_list_get(disk
->serial
, *disk_list
);
4658 idisk
->disk
.status
|= disk
->status
;
4659 if (is_configured(&idisk
->disk
) ||
4660 is_failed(&idisk
->disk
))
4661 idisk
->disk
.status
&= ~(SPARE_DISK
);
4663 idisk
= xcalloc(1, sizeof(*idisk
));
4664 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
4665 idisk
->disk
= *disk
;
4666 idisk
->next
= *disk_list
;
4670 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
4677 static struct intel_super
*
4678 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
4681 struct imsm_super
*mpb
= super
->anchor
;
4685 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4686 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
4687 struct intel_disk
*idisk
;
4689 idisk
= disk_list_get(disk
->serial
, disk_list
);
4691 if (idisk
->owner
== owner
||
4692 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
4695 dprintf("'%.16s' owner %d != %d\n",
4696 disk
->serial
, idisk
->owner
,
4699 dprintf("unknown disk %x [%d]: %.16s\n",
4700 __le32_to_cpu(mpb
->family_num
), i
,
4706 if (ok_count
== mpb
->num_disks
)
4711 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
4713 struct intel_super
*s
;
4715 for (s
= super_list
; s
; s
= s
->next
) {
4716 if (family_num
!= s
->anchor
->family_num
)
4718 pr_err("Conflict, offlining family %#x on '%s'\n",
4719 __le32_to_cpu(family_num
), s
->disks
->devname
);
4723 static struct intel_super
*
4724 imsm_thunderdome(struct intel_super
**super_list
, int len
)
4726 struct intel_super
*super_table
[len
];
4727 struct intel_disk
*disk_list
= NULL
;
4728 struct intel_super
*champion
, *spare
;
4729 struct intel_super
*s
, **del
;
4734 memset(super_table
, 0, sizeof(super_table
));
4735 for (s
= *super_list
; s
; s
= s
->next
)
4736 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
4738 for (i
= 0; i
< tbl_size
; i
++) {
4739 struct imsm_disk
*d
;
4740 struct intel_disk
*idisk
;
4741 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
4744 d
= &s
->disks
->disk
;
4746 /* 'd' must appear in merged disk list for its
4747 * configuration to be valid
4749 idisk
= disk_list_get(d
->serial
, disk_list
);
4750 if (idisk
&& idisk
->owner
== i
)
4751 s
= validate_members(s
, disk_list
, i
);
4756 dprintf("marking family: %#x from %d:%d offline\n",
4758 super_table
[i
]->disks
->major
,
4759 super_table
[i
]->disks
->minor
);
4763 /* This is where the mdadm implementation differs from the Windows
4764 * driver which has no strict concept of a container. We can only
4765 * assemble one family from a container, so when returning a prodigal
4766 * array member to this system the code will not be able to disambiguate
4767 * the container contents that should be assembled ("foreign" versus
4768 * "local"). It requires user intervention to set the orig_family_num
4769 * to a new value to establish a new container. The Windows driver in
4770 * this situation fixes up the volume name in place and manages the
4771 * foreign array as an independent entity.
4776 for (i
= 0; i
< tbl_size
; i
++) {
4777 struct intel_super
*tbl_ent
= super_table
[i
];
4783 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
4788 if (s
&& !is_spare
) {
4789 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
4791 } else if (!s
&& !is_spare
)
4804 pr_err("Chose family %#x on '%s', assemble conflicts to new container with '--update=uuid'\n",
4805 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
4807 /* collect all dl's onto 'champion', and update them to
4808 * champion's version of the status
4810 for (s
= *super_list
; s
; s
= s
->next
) {
4811 struct imsm_super
*mpb
= champion
->anchor
;
4812 struct dl
*dl
= s
->disks
;
4817 mpb
->attributes
|= s
->anchor
->attributes
& MPB_ATTRIB_2TB_DISK
;
4819 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4820 struct imsm_disk
*disk
;
4822 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
4825 /* only set index on disks that are a member of
4826 * a populated contianer, i.e. one with
4829 if (is_failed(&dl
->disk
))
4831 else if (is_spare(&dl
->disk
))
4837 if (i
>= mpb
->num_disks
) {
4838 struct intel_disk
*idisk
;
4840 idisk
= disk_list_get(dl
->serial
, disk_list
);
4841 if (idisk
&& is_spare(&idisk
->disk
) &&
4842 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
4850 dl
->next
= champion
->disks
;
4851 champion
->disks
= dl
;
4855 /* delete 'champion' from super_list */
4856 for (del
= super_list
; *del
; ) {
4857 if (*del
== champion
) {
4858 *del
= (*del
)->next
;
4861 del
= &(*del
)->next
;
4863 champion
->next
= NULL
;
4867 struct intel_disk
*idisk
= disk_list
;
4869 disk_list
= disk_list
->next
;
4877 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
);
4878 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4879 int major
, int minor
, int keep_fd
);
4881 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4882 int *max
, int keep_fd
);
4884 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
4885 char *devname
, struct md_list
*devlist
,
4888 struct intel_super
*super_list
= NULL
;
4889 struct intel_super
*super
= NULL
;
4894 /* 'fd' is an opened container */
4895 err
= get_sra_super_block(fd
, &super_list
, devname
, &i
, keep_fd
);
4897 /* get super block from devlist devices */
4898 err
= get_devlist_super_block(devlist
, &super_list
, &i
, keep_fd
);
4901 /* all mpbs enter, maybe one leaves */
4902 super
= imsm_thunderdome(&super_list
, i
);
4908 if (find_missing(super
) != 0) {
4914 /* load migration record */
4915 err
= load_imsm_migr_rec(super
, NULL
);
4917 /* migration is in progress,
4918 * but migr_rec cannot be loaded,
4924 /* Check migration compatibility */
4925 if (err
== 0 && check_mpb_migr_compatibility(super
) != 0) {
4926 pr_err("Unsupported migration detected");
4928 fprintf(stderr
, " on %s\n", devname
);
4930 fprintf(stderr
, " (IMSM).\n");
4939 while (super_list
) {
4940 struct intel_super
*s
= super_list
;
4942 super_list
= super_list
->next
;
4951 strcpy(st
->container_devnm
, fd2devnm(fd
));
4953 st
->container_devnm
[0] = 0;
4954 if (err
== 0 && st
->ss
== NULL
) {
4955 st
->ss
= &super_imsm
;
4956 st
->minor_version
= 0;
4957 st
->max_devs
= IMSM_MAX_DEVICES
;
4963 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4964 int *max
, int keep_fd
)
4966 struct md_list
*tmpdev
;
4970 for (i
= 0, tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
4971 if (tmpdev
->used
!= 1)
4973 if (tmpdev
->container
== 1) {
4975 int fd
= dev_open(tmpdev
->devname
, O_RDONLY
|O_EXCL
);
4977 pr_err("cannot open device %s: %s\n",
4978 tmpdev
->devname
, strerror(errno
));
4982 err
= get_sra_super_block(fd
, super_list
,
4983 tmpdev
->devname
, &lmax
,
4992 int major
= major(tmpdev
->st_rdev
);
4993 int minor
= minor(tmpdev
->st_rdev
);
4994 err
= get_super_block(super_list
,
5011 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
5012 int major
, int minor
, int keep_fd
)
5014 struct intel_super
*s
;
5026 sprintf(nm
, "%d:%d", major
, minor
);
5027 dfd
= dev_open(nm
, O_RDWR
);
5033 get_dev_sector_size(dfd
, NULL
, &s
->sector_size
);
5034 find_intel_hba_capability(dfd
, s
, devname
);
5035 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
5037 /* retry the load if we might have raced against mdmon */
5038 if (err
== 3 && devnm
&& mdmon_running(devnm
))
5039 for (retry
= 0; retry
< 3; retry
++) {
5041 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
5047 s
->next
= *super_list
;
5055 if (dfd
>= 0 && !keep_fd
)
5062 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
)
5069 sra
= sysfs_read(fd
, NULL
, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
5073 if (sra
->array
.major_version
!= -1 ||
5074 sra
->array
.minor_version
!= -2 ||
5075 strcmp(sra
->text_version
, "imsm") != 0) {
5080 devnm
= fd2devnm(fd
);
5081 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
5082 if (get_super_block(super_list
, devnm
, devname
,
5083 sd
->disk
.major
, sd
->disk
.minor
, keep_fd
) != 0) {
5094 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
5096 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
, NULL
, 1);
5099 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
5101 struct intel_super
*super
;
5105 if (test_partition(fd
))
5106 /* IMSM not allowed on partitions */
5109 free_super_imsm(st
);
5111 super
= alloc_super();
5112 get_dev_sector_size(fd
, NULL
, &super
->sector_size
);
5115 /* Load hba and capabilities if they exist.
5116 * But do not preclude loading metadata in case capabilities or hba are
5117 * non-compliant and ignore_hw_compat is set.
5119 rv
= find_intel_hba_capability(fd
, super
, devname
);
5120 /* no orom/efi or non-intel hba of the disk */
5121 if (rv
!= 0 && st
->ignore_hw_compat
== 0) {
5123 pr_err("No OROM/EFI properties for %s\n", devname
);
5127 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
5129 /* retry the load if we might have raced against mdmon */
5131 struct mdstat_ent
*mdstat
= NULL
;
5132 char *name
= fd2kname(fd
);
5135 mdstat
= mdstat_by_component(name
);
5137 if (mdstat
&& mdmon_running(mdstat
->devnm
) && getpid() != mdmon_pid(mdstat
->devnm
)) {
5138 for (retry
= 0; retry
< 3; retry
++) {
5140 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
5146 free_mdstat(mdstat
);
5151 pr_err("Failed to load all information sections on %s\n", devname
);
5157 if (st
->ss
== NULL
) {
5158 st
->ss
= &super_imsm
;
5159 st
->minor_version
= 0;
5160 st
->max_devs
= IMSM_MAX_DEVICES
;
5163 /* load migration record */
5164 if (load_imsm_migr_rec(super
, NULL
) == 0) {
5165 /* Check for unsupported migration features */
5166 if (check_mpb_migr_compatibility(super
) != 0) {
5167 pr_err("Unsupported migration detected");
5169 fprintf(stderr
, " on %s\n", devname
);
5171 fprintf(stderr
, " (IMSM).\n");
5179 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
5181 if (info
->level
== 1)
5183 return info
->chunk_size
>> 9;
5186 static unsigned long long info_to_blocks_per_member(mdu_array_info_t
*info
,
5187 unsigned long long size
)
5189 if (info
->level
== 1)
5192 return (size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
5195 static void imsm_update_version_info(struct intel_super
*super
)
5197 /* update the version and attributes */
5198 struct imsm_super
*mpb
= super
->anchor
;
5200 struct imsm_dev
*dev
;
5201 struct imsm_map
*map
;
5204 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5205 dev
= get_imsm_dev(super
, i
);
5206 map
= get_imsm_map(dev
, MAP_0
);
5207 if (__le32_to_cpu(dev
->size_high
) > 0)
5208 mpb
->attributes
|= MPB_ATTRIB_2TB
;
5210 /* FIXME detect when an array spans a port multiplier */
5212 mpb
->attributes
|= MPB_ATTRIB_PM
;
5215 if (mpb
->num_raid_devs
> 1 ||
5216 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
5217 version
= MPB_VERSION_ATTRIBS
;
5218 switch (get_imsm_raid_level(map
)) {
5219 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
5220 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
5221 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
5222 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
5225 if (map
->num_members
>= 5)
5226 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
5227 else if (dev
->status
== DEV_CLONE_N_GO
)
5228 version
= MPB_VERSION_CNG
;
5229 else if (get_imsm_raid_level(map
) == 5)
5230 version
= MPB_VERSION_RAID5
;
5231 else if (map
->num_members
>= 3)
5232 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
5233 else if (get_imsm_raid_level(map
) == 1)
5234 version
= MPB_VERSION_RAID1
;
5236 version
= MPB_VERSION_RAID0
;
5238 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
5242 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
5244 struct imsm_super
*mpb
= super
->anchor
;
5245 char *reason
= NULL
;
5248 if (strlen(name
) > MAX_RAID_SERIAL_LEN
)
5249 reason
= "must be 16 characters or less";
5251 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5252 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
5254 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
5255 reason
= "already exists";
5260 if (reason
&& !quiet
)
5261 pr_err("imsm volume name %s\n", reason
);
5266 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
5267 struct shape
*s
, char *name
,
5268 char *homehost
, int *uuid
,
5269 long long data_offset
)
5271 /* We are creating a volume inside a pre-existing container.
5272 * so st->sb is already set.
5274 struct intel_super
*super
= st
->sb
;
5275 unsigned int sector_size
= super
->sector_size
;
5276 struct imsm_super
*mpb
= super
->anchor
;
5277 struct intel_dev
*dv
;
5278 struct imsm_dev
*dev
;
5279 struct imsm_vol
*vol
;
5280 struct imsm_map
*map
;
5281 int idx
= mpb
->num_raid_devs
;
5283 unsigned long long array_blocks
;
5284 size_t size_old
, size_new
;
5285 unsigned long long num_data_stripes
;
5286 unsigned int data_disks
;
5287 unsigned long long size_per_member
;
5289 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
5290 pr_err("This imsm-container already has the maximum of %d volumes\n", super
->orom
->vpa
);
5294 /* ensure the mpb is large enough for the new data */
5295 size_old
= __le32_to_cpu(mpb
->mpb_size
);
5296 size_new
= disks_to_mpb_size(info
->nr_disks
);
5297 if (size_new
> size_old
) {
5299 size_t size_round
= ROUND_UP(size_new
, sector_size
);
5301 if (posix_memalign(&mpb_new
, sector_size
, size_round
) != 0) {
5302 pr_err("could not allocate new mpb\n");
5305 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
5306 MIGR_REC_BUF_SECTORS
*
5307 MAX_SECTOR_SIZE
) != 0) {
5308 pr_err("could not allocate migr_rec buffer\n");
5314 memcpy(mpb_new
, mpb
, size_old
);
5317 super
->anchor
= mpb_new
;
5318 mpb
->mpb_size
= __cpu_to_le32(size_new
);
5319 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
5320 super
->len
= size_round
;
5322 super
->current_vol
= idx
;
5324 /* handle 'failed_disks' by either:
5325 * a) create dummy disk entries in the table if this the first
5326 * volume in the array. We add them here as this is the only
5327 * opportunity to add them. add_to_super_imsm_volume()
5328 * handles the non-failed disks and continues incrementing
5330 * b) validate that 'failed_disks' matches the current number
5331 * of missing disks if the container is populated
5333 if (super
->current_vol
== 0) {
5335 for (i
= 0; i
< info
->failed_disks
; i
++) {
5336 struct imsm_disk
*disk
;
5339 disk
= __get_imsm_disk(mpb
, i
);
5340 disk
->status
= CONFIGURED_DISK
| FAILED_DISK
;
5341 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
5342 snprintf((char *) disk
->serial
, MAX_RAID_SERIAL_LEN
,
5343 "missing:%d", (__u8
)i
);
5345 find_missing(super
);
5350 for (d
= super
->missing
; d
; d
= d
->next
)
5352 if (info
->failed_disks
> missing
) {
5353 pr_err("unable to add 'missing' disk to container\n");
5358 if (!check_name(super
, name
, 0))
5360 dv
= xmalloc(sizeof(*dv
));
5361 dev
= xcalloc(1, sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
5362 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
5363 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
5364 info
->layout
, info
->chunk_size
,
5365 s
->size
* BLOCKS_PER_KB
);
5366 data_disks
= get_data_disks(info
->level
, info
->layout
,
5368 array_blocks
= round_size_to_mb(array_blocks
, data_disks
);
5369 size_per_member
= array_blocks
/ data_disks
;
5371 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
5372 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
5373 dev
->status
= (DEV_READ_COALESCING
| DEV_WRITE_COALESCING
);
5375 vol
->migr_state
= 0;
5376 set_migr_type(dev
, MIGR_INIT
);
5377 vol
->dirty
= !info
->state
;
5378 vol
->curr_migr_unit
= 0;
5379 map
= get_imsm_map(dev
, MAP_0
);
5380 set_pba_of_lba0(map
, super
->create_offset
);
5381 set_blocks_per_member(map
, info_to_blocks_per_member(info
,
5384 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
5385 map
->failed_disk_num
= ~0;
5386 if (info
->level
> 0)
5387 map
->map_state
= (info
->state
? IMSM_T_STATE_NORMAL
5388 : IMSM_T_STATE_UNINITIALIZED
);
5390 map
->map_state
= info
->failed_disks
? IMSM_T_STATE_FAILED
:
5391 IMSM_T_STATE_NORMAL
;
5394 if (info
->level
== 1 && info
->raid_disks
> 2) {
5397 pr_err("imsm does not support more than 2 disksin a raid1 volume\n");
5401 map
->raid_level
= info
->level
;
5402 if (info
->level
== 10) {
5403 map
->raid_level
= 1;
5404 map
->num_domains
= info
->raid_disks
/ 2;
5405 } else if (info
->level
== 1)
5406 map
->num_domains
= info
->raid_disks
;
5408 map
->num_domains
= 1;
5410 /* info->size is only int so use the 'size' parameter instead */
5411 num_data_stripes
= size_per_member
/ info_to_blocks_per_strip(info
);
5412 num_data_stripes
/= map
->num_domains
;
5413 set_num_data_stripes(map
, num_data_stripes
);
5415 map
->num_members
= info
->raid_disks
;
5416 for (i
= 0; i
< map
->num_members
; i
++) {
5417 /* initialized in add_to_super */
5418 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
5420 mpb
->num_raid_devs
++;
5421 mpb
->num_raid_devs_created
++;
5422 dev
->my_vol_raid_dev_num
= mpb
->num_raid_devs_created
;
5424 if (s
->consistency_policy
<= CONSISTENCY_POLICY_RESYNC
) {
5425 dev
->rwh_policy
= RWH_MULTIPLE_OFF
;
5426 } else if (s
->consistency_policy
== CONSISTENCY_POLICY_PPL
) {
5427 dev
->rwh_policy
= RWH_MULTIPLE_DISTRIBUTED
;
5431 pr_err("imsm does not support consistency policy %s\n",
5432 map_num(consistency_policies
, s
->consistency_policy
));
5437 dv
->index
= super
->current_vol
;
5438 dv
->next
= super
->devlist
;
5439 super
->devlist
= dv
;
5441 imsm_update_version_info(super
);
5446 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
5447 struct shape
*s
, char *name
,
5448 char *homehost
, int *uuid
,
5449 unsigned long long data_offset
)
5451 /* This is primarily called by Create when creating a new array.
5452 * We will then get add_to_super called for each component, and then
5453 * write_init_super called to write it out to each device.
5454 * For IMSM, Create can create on fresh devices or on a pre-existing
5456 * To create on a pre-existing array a different method will be called.
5457 * This one is just for fresh drives.
5459 struct intel_super
*super
;
5460 struct imsm_super
*mpb
;
5464 if (data_offset
!= INVALID_SECTORS
) {
5465 pr_err("data-offset not supported by imsm\n");
5470 return init_super_imsm_volume(st
, info
, s
, name
, homehost
, uuid
,
5474 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
5476 mpb_size
= MAX_SECTOR_SIZE
;
5478 super
= alloc_super();
5480 posix_memalign(&super
->buf
, MAX_SECTOR_SIZE
, mpb_size
) != 0) {
5485 pr_err("could not allocate superblock\n");
5488 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
5489 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
) != 0) {
5490 pr_err("could not allocate migr_rec buffer\n");
5495 memset(super
->buf
, 0, mpb_size
);
5497 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5501 /* zeroing superblock */
5505 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5507 version
= (char *) mpb
->sig
;
5508 strcpy(version
, MPB_SIGNATURE
);
5509 version
+= strlen(MPB_SIGNATURE
);
5510 strcpy(version
, MPB_VERSION_RAID0
);
5515 static int drive_validate_sector_size(struct intel_super
*super
, struct dl
*dl
)
5517 unsigned int member_sector_size
;
5520 pr_err("Invalid file descriptor for %s\n", dl
->devname
);
5524 if (!get_dev_sector_size(dl
->fd
, dl
->devname
, &member_sector_size
))
5526 if (member_sector_size
!= super
->sector_size
)
5531 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
5532 int fd
, char *devname
)
5534 struct intel_super
*super
= st
->sb
;
5535 struct imsm_super
*mpb
= super
->anchor
;
5536 struct imsm_disk
*_disk
;
5537 struct imsm_dev
*dev
;
5538 struct imsm_map
*map
;
5542 dev
= get_imsm_dev(super
, super
->current_vol
);
5543 map
= get_imsm_map(dev
, MAP_0
);
5545 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
5546 pr_err("%s: Cannot add spare devices to IMSM volume\n",
5552 /* we're doing autolayout so grab the pre-marked (in
5553 * validate_geometry) raid_disk
5555 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5556 if (dl
->raiddisk
== dk
->raid_disk
)
5559 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5560 if (dl
->major
== dk
->major
&&
5561 dl
->minor
== dk
->minor
)
5566 pr_err("%s is not a member of the same container\n", devname
);
5570 if (!drive_validate_sector_size(super
, dl
)) {
5571 pr_err("Combining drives of different sector size in one volume is not allowed\n");
5575 /* add a pristine spare to the metadata */
5576 if (dl
->index
< 0) {
5577 dl
->index
= super
->anchor
->num_disks
;
5578 super
->anchor
->num_disks
++;
5580 /* Check the device has not already been added */
5581 slot
= get_imsm_disk_slot(map
, dl
->index
);
5583 (get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
) & IMSM_ORD_REBUILD
) == 0) {
5584 pr_err("%s has been included in this array twice\n",
5588 set_imsm_ord_tbl_ent(map
, dk
->raid_disk
, dl
->index
);
5589 dl
->disk
.status
= CONFIGURED_DISK
;
5591 /* update size of 'missing' disks to be at least as large as the
5592 * largest acitve member (we only have dummy missing disks when
5593 * creating the first volume)
5595 if (super
->current_vol
== 0) {
5596 for (df
= super
->missing
; df
; df
= df
->next
) {
5597 if (total_blocks(&dl
->disk
) > total_blocks(&df
->disk
))
5598 set_total_blocks(&df
->disk
, total_blocks(&dl
->disk
));
5599 _disk
= __get_imsm_disk(mpb
, df
->index
);
5604 /* refresh unset/failed slots to point to valid 'missing' entries */
5605 for (df
= super
->missing
; df
; df
= df
->next
)
5606 for (slot
= 0; slot
< mpb
->num_disks
; slot
++) {
5607 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
5609 if ((ord
& IMSM_ORD_REBUILD
) == 0)
5611 set_imsm_ord_tbl_ent(map
, slot
, df
->index
| IMSM_ORD_REBUILD
);
5612 if (is_gen_migration(dev
)) {
5613 struct imsm_map
*map2
= get_imsm_map(dev
,
5615 int slot2
= get_imsm_disk_slot(map2
, df
->index
);
5616 if (slot2
< map2
->num_members
&& slot2
>= 0) {
5617 __u32 ord2
= get_imsm_ord_tbl_ent(dev
,
5620 if ((unsigned)df
->index
==
5622 set_imsm_ord_tbl_ent(map2
,
5628 dprintf("set slot:%d to missing disk:%d\n", slot
, df
->index
);
5632 /* if we are creating the first raid device update the family number */
5633 if (super
->current_vol
== 0) {
5635 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
5637 _disk
= __get_imsm_disk(mpb
, dl
->index
);
5638 if (!_dev
|| !_disk
) {
5639 pr_err("BUG mpb setup error\n");
5645 sum
+= __gen_imsm_checksum(mpb
);
5646 mpb
->family_num
= __cpu_to_le32(sum
);
5647 mpb
->orig_family_num
= mpb
->family_num
;
5649 super
->current_disk
= dl
;
5654 * Function marks disk as spare and restores disk serial
5655 * in case it was previously marked as failed by takeover operation
5657 * -1 : critical error
5658 * 0 : disk is marked as spare but serial is not set
5661 int mark_spare(struct dl
*disk
)
5663 __u8 serial
[MAX_RAID_SERIAL_LEN
];
5670 if (!imsm_read_serial(disk
->fd
, NULL
, serial
)) {
5671 /* Restore disk serial number, because takeover marks disk
5672 * as failed and adds to serial ':0' before it becomes
5675 serialcpy(disk
->serial
, serial
);
5676 serialcpy(disk
->disk
.serial
, serial
);
5679 disk
->disk
.status
= SPARE_DISK
;
5685 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
5686 int fd
, char *devname
,
5687 unsigned long long data_offset
)
5689 struct intel_super
*super
= st
->sb
;
5691 unsigned long long size
;
5692 unsigned int member_sector_size
;
5697 /* If we are on an RAID enabled platform check that the disk is
5698 * attached to the raid controller.
5699 * We do not need to test disks attachment for container based additions,
5700 * they shall be already tested when container was created/assembled.
5702 rv
= find_intel_hba_capability(fd
, super
, devname
);
5703 /* no orom/efi or non-intel hba of the disk */
5705 dprintf("capability: %p fd: %d ret: %d\n",
5706 super
->orom
, fd
, rv
);
5710 if (super
->current_vol
>= 0)
5711 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
5714 dd
= xcalloc(sizeof(*dd
), 1);
5715 dd
->major
= major(stb
.st_rdev
);
5716 dd
->minor
= minor(stb
.st_rdev
);
5717 dd
->devname
= devname
? xstrdup(devname
) : NULL
;
5720 dd
->action
= DISK_ADD
;
5721 rv
= imsm_read_serial(fd
, devname
, dd
->serial
);
5723 pr_err("failed to retrieve scsi serial, aborting\n");
5729 if (super
->hba
&& ((super
->hba
->type
== SYS_DEV_NVME
) ||
5730 (super
->hba
->type
== SYS_DEV_VMD
))) {
5732 char *devpath
= diskfd_to_devpath(fd
);
5733 char controller_path
[PATH_MAX
];
5736 pr_err("failed to get devpath, aborting\n");
5743 snprintf(controller_path
, PATH_MAX
-1, "%s/device", devpath
);
5746 if (devpath_to_vendor(controller_path
) == 0x8086) {
5748 * If Intel's NVMe drive has serial ended with
5749 * "-A","-B","-1" or "-2" it means that this is "x8"
5750 * device (double drive on single PCIe card).
5751 * User should be warned about potential data loss.
5753 for (i
= MAX_RAID_SERIAL_LEN
-1; i
> 0; i
--) {
5754 /* Skip empty character at the end */
5755 if (dd
->serial
[i
] == 0)
5758 if (((dd
->serial
[i
] == 'A') ||
5759 (dd
->serial
[i
] == 'B') ||
5760 (dd
->serial
[i
] == '1') ||
5761 (dd
->serial
[i
] == '2')) &&
5762 (dd
->serial
[i
-1] == '-'))
5763 pr_err("\tThe action you are about to take may put your data at risk.\n"
5764 "\tPlease note that x8 devices may consist of two separate x4 devices "
5765 "located on a single PCIe port.\n"
5766 "\tRAID 0 is the only supported configuration for this type of x8 device.\n");
5769 } else if (super
->hba
->type
== SYS_DEV_VMD
&& super
->orom
&&
5770 !imsm_orom_has_tpv_support(super
->orom
)) {
5771 pr_err("\tPlatform configuration does not support non-Intel NVMe drives.\n"
5772 "\tPlease refer to Intel(R) RSTe user guide.\n");
5779 get_dev_size(fd
, NULL
, &size
);
5780 get_dev_sector_size(fd
, NULL
, &member_sector_size
);
5782 if (super
->sector_size
== 0) {
5783 /* this a first device, so sector_size is not set yet */
5784 super
->sector_size
= member_sector_size
;
5787 /* clear migr_rec when adding disk to container */
5788 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
);
5789 if (lseek64(fd
, size
- MIGR_REC_SECTOR_POSITION
*member_sector_size
,
5791 if ((unsigned int)write(fd
, super
->migr_rec_buf
,
5792 MIGR_REC_BUF_SECTORS
*member_sector_size
) !=
5793 MIGR_REC_BUF_SECTORS
*member_sector_size
)
5794 perror("Write migr_rec failed");
5798 serialcpy(dd
->disk
.serial
, dd
->serial
);
5799 set_total_blocks(&dd
->disk
, size
);
5800 if (__le32_to_cpu(dd
->disk
.total_blocks_hi
) > 0) {
5801 struct imsm_super
*mpb
= super
->anchor
;
5802 mpb
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5805 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
5806 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
5808 dd
->disk
.scsi_id
= __cpu_to_le32(0);
5810 if (st
->update_tail
) {
5811 dd
->next
= super
->disk_mgmt_list
;
5812 super
->disk_mgmt_list
= dd
;
5814 dd
->next
= super
->disks
;
5816 super
->updates_pending
++;
5822 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
5824 struct intel_super
*super
= st
->sb
;
5827 /* remove from super works only in mdmon - for communication
5828 * manager - monitor. Check if communication memory buffer
5831 if (!st
->update_tail
) {
5832 pr_err("shall be used in mdmon context only\n");
5835 dd
= xcalloc(1, sizeof(*dd
));
5836 dd
->major
= dk
->major
;
5837 dd
->minor
= dk
->minor
;
5840 dd
->action
= DISK_REMOVE
;
5842 dd
->next
= super
->disk_mgmt_list
;
5843 super
->disk_mgmt_list
= dd
;
5848 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
5851 char buf
[MAX_SECTOR_SIZE
];
5852 struct imsm_super anchor
;
5853 } spare_record
__attribute__ ((aligned(MAX_SECTOR_SIZE
)));
5855 /* spare records have their own family number and do not have any defined raid
5858 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
5860 struct imsm_super
*mpb
= super
->anchor
;
5861 struct imsm_super
*spare
= &spare_record
.anchor
;
5865 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
));
5866 spare
->generation_num
= __cpu_to_le32(1UL);
5867 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5868 spare
->num_disks
= 1;
5869 spare
->num_raid_devs
= 0;
5870 spare
->cache_size
= mpb
->cache_size
;
5871 spare
->pwr_cycle_count
= __cpu_to_le32(1);
5873 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
5874 MPB_SIGNATURE MPB_VERSION_RAID0
);
5876 for (d
= super
->disks
; d
; d
= d
->next
) {
5880 spare
->disk
[0] = d
->disk
;
5881 if (__le32_to_cpu(d
->disk
.total_blocks_hi
) > 0)
5882 spare
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5884 if (super
->sector_size
== 4096)
5885 convert_to_4k_imsm_disk(&spare
->disk
[0]);
5887 sum
= __gen_imsm_checksum(spare
);
5888 spare
->family_num
= __cpu_to_le32(sum
);
5889 spare
->orig_family_num
= 0;
5890 sum
= __gen_imsm_checksum(spare
);
5891 spare
->check_sum
= __cpu_to_le32(sum
);
5893 if (store_imsm_mpb(d
->fd
, spare
)) {
5894 pr_err("failed for device %d:%d %s\n",
5895 d
->major
, d
->minor
, strerror(errno
));
5907 static int write_super_imsm(struct supertype
*st
, int doclose
)
5909 struct intel_super
*super
= st
->sb
;
5910 unsigned int sector_size
= super
->sector_size
;
5911 struct imsm_super
*mpb
= super
->anchor
;
5917 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
5919 int clear_migration_record
= 1;
5922 /* 'generation' is incremented everytime the metadata is written */
5923 generation
= __le32_to_cpu(mpb
->generation_num
);
5925 mpb
->generation_num
= __cpu_to_le32(generation
);
5927 /* fix up cases where previous mdadm releases failed to set
5930 if (mpb
->orig_family_num
== 0)
5931 mpb
->orig_family_num
= mpb
->family_num
;
5933 for (d
= super
->disks
; d
; d
= d
->next
) {
5937 mpb
->disk
[d
->index
] = d
->disk
;
5941 for (d
= super
->missing
; d
; d
= d
->next
) {
5942 mpb
->disk
[d
->index
] = d
->disk
;
5945 mpb
->num_disks
= num_disks
;
5946 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
5948 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5949 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
5950 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
5952 imsm_copy_dev(dev
, dev2
);
5953 mpb_size
+= sizeof_imsm_dev(dev
, 0);
5955 if (is_gen_migration(dev2
))
5956 clear_migration_record
= 0;
5959 bbm_log_size
= get_imsm_bbm_log_size(super
->bbm_log
);
5962 memcpy((void *)mpb
+ mpb_size
, super
->bbm_log
, bbm_log_size
);
5963 mpb
->attributes
|= MPB_ATTRIB_BBM
;
5965 mpb
->attributes
&= ~MPB_ATTRIB_BBM
;
5967 super
->anchor
->bbm_log_size
= __cpu_to_le32(bbm_log_size
);
5968 mpb_size
+= bbm_log_size
;
5969 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5972 assert(super
->len
== 0 || mpb_size
<= super
->len
);
5975 /* recalculate checksum */
5976 sum
= __gen_imsm_checksum(mpb
);
5977 mpb
->check_sum
= __cpu_to_le32(sum
);
5979 if (super
->clean_migration_record_by_mdmon
) {
5980 clear_migration_record
= 1;
5981 super
->clean_migration_record_by_mdmon
= 0;
5983 if (clear_migration_record
)
5984 memset(super
->migr_rec_buf
, 0,
5985 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
);
5987 if (sector_size
== 4096)
5988 convert_to_4k(super
);
5990 /* write the mpb for disks that compose raid devices */
5991 for (d
= super
->disks
; d
; d
= d
->next
) {
5992 if (d
->index
< 0 || is_failed(&d
->disk
))
5995 if (clear_migration_record
) {
5996 unsigned long long dsize
;
5998 get_dev_size(d
->fd
, NULL
, &dsize
);
5999 if (lseek64(d
->fd
, dsize
- sector_size
,
6001 if ((unsigned int)write(d
->fd
,
6002 super
->migr_rec_buf
,
6003 MIGR_REC_BUF_SECTORS
*sector_size
) !=
6004 MIGR_REC_BUF_SECTORS
*sector_size
)
6005 perror("Write migr_rec failed");
6009 if (store_imsm_mpb(d
->fd
, mpb
))
6011 "failed for device %d:%d (fd: %d)%s\n",
6013 d
->fd
, strerror(errno
));
6022 return write_super_imsm_spares(super
, doclose
);
6027 static int create_array(struct supertype
*st
, int dev_idx
)
6030 struct imsm_update_create_array
*u
;
6031 struct intel_super
*super
= st
->sb
;
6032 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
6033 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
6034 struct disk_info
*inf
;
6035 struct imsm_disk
*disk
;
6038 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
6039 sizeof(*inf
) * map
->num_members
;
6041 u
->type
= update_create_array
;
6042 u
->dev_idx
= dev_idx
;
6043 imsm_copy_dev(&u
->dev
, dev
);
6044 inf
= get_disk_info(u
);
6045 for (i
= 0; i
< map
->num_members
; i
++) {
6046 int idx
= get_imsm_disk_idx(dev
, i
, MAP_X
);
6048 disk
= get_imsm_disk(super
, idx
);
6050 disk
= get_imsm_missing(super
, idx
);
6051 serialcpy(inf
[i
].serial
, disk
->serial
);
6053 append_metadata_update(st
, u
, len
);
6058 static int mgmt_disk(struct supertype
*st
)
6060 struct intel_super
*super
= st
->sb
;
6062 struct imsm_update_add_remove_disk
*u
;
6064 if (!super
->disk_mgmt_list
)
6069 u
->type
= update_add_remove_disk
;
6070 append_metadata_update(st
, u
, len
);
6075 __u32
crc32c_le(__u32 crc
, unsigned char const *p
, size_t len
);
6077 static int write_init_ppl_imsm(struct supertype
*st
, struct mdinfo
*info
, int fd
)
6079 struct intel_super
*super
= st
->sb
;
6081 struct ppl_header
*ppl_hdr
;
6084 /* first clear entire ppl space */
6085 ret
= zero_disk_range(fd
, info
->ppl_sector
, info
->ppl_size
);
6089 ret
= posix_memalign(&buf
, MAX_SECTOR_SIZE
, PPL_HEADER_SIZE
);
6091 pr_err("Failed to allocate PPL header buffer\n");
6095 memset(buf
, 0, PPL_HEADER_SIZE
);
6097 memset(ppl_hdr
->reserved
, 0xff, PPL_HDR_RESERVED
);
6098 ppl_hdr
->signature
= __cpu_to_le32(super
->anchor
->orig_family_num
);
6100 if (info
->mismatch_cnt
) {
6102 * We are overwriting an invalid ppl. Make one entry with wrong
6103 * checksum to prevent the kernel from skipping resync.
6105 ppl_hdr
->entries_count
= __cpu_to_le32(1);
6106 ppl_hdr
->entries
[0].checksum
= ~0;
6109 ppl_hdr
->checksum
= __cpu_to_le32(~crc32c_le(~0, buf
, PPL_HEADER_SIZE
));
6111 if (lseek64(fd
, info
->ppl_sector
* 512, SEEK_SET
) < 0) {
6113 perror("Failed to seek to PPL header location");
6116 if (!ret
&& write(fd
, buf
, PPL_HEADER_SIZE
) != PPL_HEADER_SIZE
) {
6118 perror("Write PPL header failed");
6128 static int validate_ppl_imsm(struct supertype
*st
, struct mdinfo
*info
,
6129 struct mdinfo
*disk
)
6131 struct intel_super
*super
= st
->sb
;
6135 struct ppl_header
*ppl_hdr
;
6137 struct imsm_dev
*dev
;
6140 unsigned long long ppl_offset
= 0;
6141 unsigned long long prev_gen_num
= 0;
6143 if (disk
->disk
.raid_disk
< 0)
6146 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, PPL_HEADER_SIZE
)) {
6147 pr_err("Failed to allocate PPL header buffer\n");
6151 dev
= get_imsm_dev(super
, info
->container_member
);
6152 idx
= get_imsm_disk_idx(dev
, disk
->disk
.raid_disk
, MAP_0
);
6153 d
= get_imsm_dl_disk(super
, idx
);
6155 if (!d
|| d
->index
< 0 || is_failed(&d
->disk
))
6159 while (ppl_offset
< MULTIPLE_PPL_AREA_SIZE_IMSM
) {
6160 dprintf("Checking potential PPL at offset: %llu\n", ppl_offset
);
6162 if (lseek64(d
->fd
, info
->ppl_sector
* 512 + ppl_offset
,
6164 perror("Failed to seek to PPL header location");
6169 if (read(d
->fd
, buf
, PPL_HEADER_SIZE
) != PPL_HEADER_SIZE
) {
6170 perror("Read PPL header failed");
6177 crc
= __le32_to_cpu(ppl_hdr
->checksum
);
6178 ppl_hdr
->checksum
= 0;
6180 if (crc
!= ~crc32c_le(~0, buf
, PPL_HEADER_SIZE
)) {
6181 dprintf("Wrong PPL header checksum on %s\n",
6186 if (prev_gen_num
> __le64_to_cpu(ppl_hdr
->generation
)) {
6187 /* previous was newest, it was already checked */
6191 if ((__le32_to_cpu(ppl_hdr
->signature
) !=
6192 super
->anchor
->orig_family_num
)) {
6193 dprintf("Wrong PPL header signature on %s\n",
6200 prev_gen_num
= __le64_to_cpu(ppl_hdr
->generation
);
6202 ppl_offset
+= PPL_HEADER_SIZE
;
6203 for (i
= 0; i
< __le32_to_cpu(ppl_hdr
->entries_count
); i
++)
6205 __le32_to_cpu(ppl_hdr
->entries
[i
].pp_size
);
6212 * Update metadata to use mutliple PPLs area (1MB).
6213 * This is done once for all RAID members
6215 if (info
->consistency_policy
== CONSISTENCY_POLICY_PPL
&&
6216 info
->ppl_size
!= (MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9)) {
6218 struct mdinfo
*member_dev
;
6220 sprintf(subarray
, "%d", info
->container_member
);
6222 if (mdmon_running(st
->container_devnm
))
6223 st
->update_tail
= &st
->updates
;
6225 if (st
->ss
->update_subarray(st
, subarray
, "ppl", NULL
)) {
6226 pr_err("Failed to update subarray %s\n",
6229 if (st
->update_tail
)
6230 flush_metadata_updates(st
);
6232 st
->ss
->sync_metadata(st
);
6233 info
->ppl_size
= (MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9);
6234 for (member_dev
= info
->devs
; member_dev
;
6235 member_dev
= member_dev
->next
)
6236 member_dev
->ppl_size
=
6237 (MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9);
6242 struct imsm_map
*map
= get_imsm_map(dev
, MAP_X
);
6244 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
6245 (map
->map_state
== IMSM_T_STATE_NORMAL
&&
6246 !(dev
->vol
.dirty
& RAIDVOL_DIRTY
)) ||
6247 (dev
->vol
.migr_state
== MIGR_REBUILD
&&
6248 dev
->vol
.curr_migr_unit
== 0 &&
6249 get_imsm_disk_idx(dev
, disk
->disk
.raid_disk
, MAP_1
) != idx
))
6250 ret
= st
->ss
->write_init_ppl(st
, info
, d
->fd
);
6252 info
->mismatch_cnt
++;
6258 static int write_init_ppl_imsm_all(struct supertype
*st
, struct mdinfo
*info
)
6260 struct intel_super
*super
= st
->sb
;
6264 if (info
->consistency_policy
!= CONSISTENCY_POLICY_PPL
||
6265 info
->array
.level
!= 5)
6268 for (d
= super
->disks
; d
; d
= d
->next
) {
6269 if (d
->index
< 0 || is_failed(&d
->disk
))
6272 ret
= st
->ss
->write_init_ppl(st
, info
, d
->fd
);
6280 static int write_init_super_imsm(struct supertype
*st
)
6282 struct intel_super
*super
= st
->sb
;
6283 int current_vol
= super
->current_vol
;
6287 getinfo_super_imsm(st
, &info
, NULL
);
6289 /* we are done with current_vol reset it to point st at the container */
6290 super
->current_vol
= -1;
6292 if (st
->update_tail
) {
6293 /* queue the recently created array / added disk
6294 * as a metadata update */
6296 /* determine if we are creating a volume or adding a disk */
6297 if (current_vol
< 0) {
6298 /* in the mgmt (add/remove) disk case we are running
6299 * in mdmon context, so don't close fd's
6303 rv
= write_init_ppl_imsm_all(st
, &info
);
6305 rv
= create_array(st
, current_vol
);
6309 for (d
= super
->disks
; d
; d
= d
->next
)
6310 Kill(d
->devname
, NULL
, 0, -1, 1);
6311 if (current_vol
>= 0)
6312 rv
= write_init_ppl_imsm_all(st
, &info
);
6314 rv
= write_super_imsm(st
, 1);
6320 static int store_super_imsm(struct supertype
*st
, int fd
)
6322 struct intel_super
*super
= st
->sb
;
6323 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
6328 if (super
->sector_size
== 4096)
6329 convert_to_4k(super
);
6330 return store_imsm_mpb(fd
, mpb
);
6333 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
6334 int layout
, int raiddisks
, int chunk
,
6335 unsigned long long size
,
6336 unsigned long long data_offset
,
6338 unsigned long long *freesize
,
6342 unsigned long long ldsize
;
6343 struct intel_super
*super
;
6346 if (level
!= LEVEL_CONTAINER
)
6351 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
6354 pr_err("imsm: Cannot open %s: %s\n",
6355 dev
, strerror(errno
));
6358 if (!get_dev_size(fd
, dev
, &ldsize
)) {
6363 /* capabilities retrieve could be possible
6364 * note that there is no fd for the disks in array.
6366 super
= alloc_super();
6371 if (!get_dev_sector_size(fd
, NULL
, &super
->sector_size
)) {
6377 rv
= find_intel_hba_capability(fd
, super
, verbose
> 0 ? dev
: NULL
);
6381 fd2devname(fd
, str
);
6382 dprintf("fd: %d %s orom: %p rv: %d raiddisk: %d\n",
6383 fd
, str
, super
->orom
, rv
, raiddisks
);
6385 /* no orom/efi or non-intel hba of the disk */
6392 if (raiddisks
> super
->orom
->tds
) {
6394 pr_err("%d exceeds maximum number of platform supported disks: %d\n",
6395 raiddisks
, super
->orom
->tds
);
6399 if ((super
->orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) == 0 &&
6400 (ldsize
>> 9) >> 32 > 0) {
6402 pr_err("%s exceeds maximum platform supported size\n", dev
);
6408 *freesize
= avail_size_imsm(st
, ldsize
>> 9, data_offset
);
6414 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
6416 const unsigned long long base_start
= e
[*idx
].start
;
6417 unsigned long long end
= base_start
+ e
[*idx
].size
;
6420 if (base_start
== end
)
6424 for (i
= *idx
; i
< num_extents
; i
++) {
6425 /* extend overlapping extents */
6426 if (e
[i
].start
>= base_start
&&
6427 e
[i
].start
<= end
) {
6430 if (e
[i
].start
+ e
[i
].size
> end
)
6431 end
= e
[i
].start
+ e
[i
].size
;
6432 } else if (e
[i
].start
> end
) {
6438 return end
- base_start
;
6441 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
6443 /* build a composite disk with all known extents and generate a new
6444 * 'maxsize' given the "all disks in an array must share a common start
6445 * offset" constraint
6447 struct extent
*e
= xcalloc(sum_extents
, sizeof(*e
));
6451 unsigned long long pos
;
6452 unsigned long long start
= 0;
6453 unsigned long long maxsize
;
6454 unsigned long reserve
;
6456 /* coalesce and sort all extents. also, check to see if we need to
6457 * reserve space between member arrays
6460 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6463 for (i
= 0; i
< dl
->extent_cnt
; i
++)
6466 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
6471 while (i
< sum_extents
) {
6472 e
[j
].start
= e
[i
].start
;
6473 e
[j
].size
= find_size(e
, &i
, sum_extents
);
6475 if (e
[j
-1].size
== 0)
6484 unsigned long long esize
;
6486 esize
= e
[i
].start
- pos
;
6487 if (esize
>= maxsize
) {
6492 pos
= e
[i
].start
+ e
[i
].size
;
6494 } while (e
[i
-1].size
);
6500 /* FIXME assumes volume at offset 0 is the first volume in a
6503 if (start_extent
> 0)
6504 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
6508 if (maxsize
< reserve
)
6511 super
->create_offset
= ~((unsigned long long) 0);
6512 if (start
+ reserve
> super
->create_offset
)
6513 return 0; /* start overflows create_offset */
6514 super
->create_offset
= start
+ reserve
;
6516 return maxsize
- reserve
;
6519 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
6521 if (level
< 0 || level
== 6 || level
== 4)
6524 /* if we have an orom prevent invalid raid levels */
6527 case 0: return imsm_orom_has_raid0(orom
);
6530 return imsm_orom_has_raid1e(orom
);
6531 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
6532 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
6533 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
6536 return 1; /* not on an Intel RAID platform so anything goes */
6542 active_arrays_by_format(char *name
, char* hba
, struct md_list
**devlist
,
6543 int dpa
, int verbose
)
6545 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
6546 struct mdstat_ent
*memb
;
6552 for (memb
= mdstat
; memb
; memb
= memb
->next
) {
6553 if (memb
->metadata_version
&&
6554 (strncmp(memb
->metadata_version
, "external:", 9) == 0) &&
6555 (strcmp(&memb
->metadata_version
[9], name
) == 0) &&
6556 !is_subarray(memb
->metadata_version
+9) &&
6558 struct dev_member
*dev
= memb
->members
;
6560 while(dev
&& (fd
< 0)) {
6561 char *path
= xmalloc(strlen(dev
->name
) + strlen("/dev/") + 1);
6562 num
= sprintf(path
, "%s%s", "/dev/", dev
->name
);
6564 fd
= open(path
, O_RDONLY
, 0);
6565 if (num
<= 0 || fd
< 0) {
6566 pr_vrb("Cannot open %s: %s\n",
6567 dev
->name
, strerror(errno
));
6573 if (fd
>= 0 && disk_attached_to_hba(fd
, hba
)) {
6574 struct mdstat_ent
*vol
;
6575 for (vol
= mdstat
; vol
; vol
= vol
->next
) {
6576 if (vol
->active
> 0 &&
6577 vol
->metadata_version
&&
6578 is_container_member(vol
, memb
->devnm
)) {
6583 if (*devlist
&& (found
< dpa
)) {
6584 dv
= xcalloc(1, sizeof(*dv
));
6585 dv
->devname
= xmalloc(strlen(memb
->devnm
) + strlen("/dev/") + 1);
6586 sprintf(dv
->devname
, "%s%s", "/dev/", memb
->devnm
);
6589 dv
->next
= *devlist
;
6597 free_mdstat(mdstat
);
6602 static struct md_list
*
6603 get_loop_devices(void)
6606 struct md_list
*devlist
= NULL
;
6609 for(i
= 0; i
< 12; i
++) {
6610 dv
= xcalloc(1, sizeof(*dv
));
6611 dv
->devname
= xmalloc(40);
6612 sprintf(dv
->devname
, "/dev/loop%d", i
);
6620 static struct md_list
*
6621 get_devices(const char *hba_path
)
6623 struct md_list
*devlist
= NULL
;
6630 devlist
= get_loop_devices();
6633 /* scroll through /sys/dev/block looking for devices attached to
6636 dir
= opendir("/sys/dev/block");
6637 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
6642 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
6644 path
= devt_to_devpath(makedev(major
, minor
));
6647 if (!path_attached_to_hba(path
, hba_path
)) {
6654 fd
= dev_open(ent
->d_name
, O_RDONLY
);
6656 fd2devname(fd
, buf
);
6659 pr_err("cannot open device: %s\n",
6664 dv
= xcalloc(1, sizeof(*dv
));
6665 dv
->devname
= xstrdup(buf
);
6672 devlist
= devlist
->next
;
6682 count_volumes_list(struct md_list
*devlist
, char *homehost
,
6683 int verbose
, int *found
)
6685 struct md_list
*tmpdev
;
6687 struct supertype
*st
;
6689 /* first walk the list of devices to find a consistent set
6690 * that match the criterea, if that is possible.
6691 * We flag the ones we like with 'used'.
6694 st
= match_metadata_desc_imsm("imsm");
6696 pr_vrb("cannot allocate memory for imsm supertype\n");
6700 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
6701 char *devname
= tmpdev
->devname
;
6703 struct supertype
*tst
;
6705 if (tmpdev
->used
> 1)
6707 tst
= dup_super(st
);
6709 pr_vrb("cannot allocate memory for imsm supertype\n");
6712 tmpdev
->container
= 0;
6713 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
6715 dprintf("cannot open device %s: %s\n",
6716 devname
, strerror(errno
));
6718 } else if (!fstat_is_blkdev(dfd
, devname
, &rdev
)) {
6720 } else if (must_be_container(dfd
)) {
6721 struct supertype
*cst
;
6722 cst
= super_by_fd(dfd
, NULL
);
6724 dprintf("cannot recognize container type %s\n",
6727 } else if (tst
->ss
!= st
->ss
) {
6728 dprintf("non-imsm container - ignore it: %s\n",
6731 } else if (!tst
->ss
->load_container
||
6732 tst
->ss
->load_container(tst
, dfd
, NULL
))
6735 tmpdev
->container
= 1;
6738 cst
->ss
->free_super(cst
);
6740 tmpdev
->st_rdev
= rdev
;
6741 if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
6742 dprintf("no RAID superblock on %s\n",
6745 } else if (tst
->ss
->compare_super
== NULL
) {
6746 dprintf("Cannot assemble %s metadata on %s\n",
6747 tst
->ss
->name
, devname
);
6753 if (tmpdev
->used
== 2 || tmpdev
->used
== 4) {
6754 /* Ignore unrecognised devices during auto-assembly */
6759 tst
->ss
->getinfo_super(tst
, &info
, NULL
);
6761 if (st
->minor_version
== -1)
6762 st
->minor_version
= tst
->minor_version
;
6764 if (memcmp(info
.uuid
, uuid_zero
,
6765 sizeof(int[4])) == 0) {
6766 /* this is a floating spare. It cannot define
6767 * an array unless there are no more arrays of
6768 * this type to be found. It can be included
6769 * in an array of this type though.
6775 if (st
->ss
!= tst
->ss
||
6776 st
->minor_version
!= tst
->minor_version
||
6777 st
->ss
->compare_super(st
, tst
) != 0) {
6778 /* Some mismatch. If exactly one array matches this host,
6779 * we can resolve on that one.
6780 * Or, if we are auto assembling, we just ignore the second
6783 dprintf("superblock on %s doesn't match others - assembly aborted\n",
6789 dprintf("found: devname: %s\n", devname
);
6793 tst
->ss
->free_super(tst
);
6797 if ((err
= load_super_imsm_all(st
, -1, &st
->sb
, NULL
, devlist
, 0)) == 0) {
6798 struct mdinfo
*iter
, *head
= st
->ss
->container_content(st
, NULL
);
6799 for (iter
= head
; iter
; iter
= iter
->next
) {
6800 dprintf("content->text_version: %s vol\n",
6801 iter
->text_version
);
6802 if (iter
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
)) {
6803 /* do not assemble arrays with unsupported
6805 dprintf("Cannot activate member %s.\n",
6806 iter
->text_version
);
6813 dprintf("No valid super block on device list: err: %d %p\n",
6817 dprintf("no more devices to examine\n");
6820 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
6821 if (tmpdev
->used
== 1 && tmpdev
->found
) {
6823 if (count
< tmpdev
->found
)
6826 count
-= tmpdev
->found
;
6829 if (tmpdev
->used
== 1)
6834 st
->ss
->free_super(st
);
6838 static int __count_volumes(char *hba_path
, int dpa
, int verbose
,
6841 struct sys_dev
*idev
, *intel_devices
= find_intel_devices();
6843 const struct orom_entry
*entry
;
6844 struct devid_list
*dv
, *devid_list
;
6849 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
6850 if (strstr(idev
->path
, hba_path
))
6854 if (!idev
|| !idev
->dev_id
)
6857 entry
= get_orom_entry_by_device_id(idev
->dev_id
);
6859 if (!entry
|| !entry
->devid_list
)
6862 devid_list
= entry
->devid_list
;
6863 for (dv
= devid_list
; dv
; dv
= dv
->next
) {
6864 struct md_list
*devlist
;
6865 struct sys_dev
*device
= NULL
;
6870 device
= device_by_id_and_path(dv
->devid
, hba_path
);
6872 device
= device_by_id(dv
->devid
);
6875 hpath
= device
->path
;
6879 devlist
= get_devices(hpath
);
6880 /* if no intel devices return zero volumes */
6881 if (devlist
== NULL
)
6884 count
+= active_arrays_by_format("imsm", hpath
, &devlist
, dpa
,
6886 dprintf("path: %s active arrays: %d\n", hpath
, count
);
6887 if (devlist
== NULL
)
6891 count
+= count_volumes_list(devlist
,
6895 dprintf("found %d count: %d\n", found
, count
);
6898 dprintf("path: %s total number of volumes: %d\n", hpath
, count
);
6901 struct md_list
*dv
= devlist
;
6902 devlist
= devlist
->next
;
6910 static int count_volumes(struct intel_hba
*hba
, int dpa
, int verbose
)
6914 if (hba
->type
== SYS_DEV_VMD
) {
6915 struct sys_dev
*dev
;
6918 for (dev
= find_intel_devices(); dev
; dev
= dev
->next
) {
6919 if (dev
->type
== SYS_DEV_VMD
)
6920 count
+= __count_volumes(dev
->path
, dpa
,
6925 return __count_volumes(hba
->path
, dpa
, verbose
, 0);
6928 static int imsm_default_chunk(const struct imsm_orom
*orom
)
6930 /* up to 512 if the plaform supports it, otherwise the platform max.
6931 * 128 if no platform detected
6933 int fs
= max(7, orom
? fls(orom
->sss
) : 0);
6935 return min(512, (1 << fs
));
6939 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
6940 int raiddisks
, int *chunk
, unsigned long long size
, int verbose
)
6942 /* check/set platform and metadata limits/defaults */
6943 if (super
->orom
&& raiddisks
> super
->orom
->dpa
) {
6944 pr_vrb("platform supports a maximum of %d disks per array\n",
6949 /* capabilities of OROM tested - copied from validate_geometry_imsm_volume */
6950 if (!is_raid_level_supported(super
->orom
, level
, raiddisks
)) {
6951 pr_vrb("platform does not support raid%d with %d disk%s\n",
6952 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
6956 if (*chunk
== 0 || *chunk
== UnSet
)
6957 *chunk
= imsm_default_chunk(super
->orom
);
6959 if (super
->orom
&& !imsm_orom_has_chunk(super
->orom
, *chunk
)) {
6960 pr_vrb("platform does not support a chunk size of: %d\n", *chunk
);
6964 if (layout
!= imsm_level_to_layout(level
)) {
6966 pr_vrb("imsm raid 5 only supports the left-asymmetric layout\n");
6967 else if (level
== 10)
6968 pr_vrb("imsm raid 10 only supports the n2 layout\n");
6970 pr_vrb("imsm unknown layout %#x for this raid level %d\n",
6975 if (super
->orom
&& (super
->orom
->attr
& IMSM_OROM_ATTR_2TB
) == 0 &&
6976 (calc_array_size(level
, raiddisks
, layout
, *chunk
, size
) >> 32) > 0) {
6977 pr_vrb("platform does not support a volume size over 2TB\n");
6984 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
6985 * FIX ME add ahci details
6987 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
6988 int layout
, int raiddisks
, int *chunk
,
6989 unsigned long long size
,
6990 unsigned long long data_offset
,
6992 unsigned long long *freesize
,
6996 struct intel_super
*super
= st
->sb
;
6997 struct imsm_super
*mpb
;
6999 unsigned long long pos
= 0;
7000 unsigned long long maxsize
;
7004 /* We must have the container info already read in. */
7008 mpb
= super
->anchor
;
7010 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, size
, verbose
)) {
7011 pr_err("RAID gemetry validation failed. Cannot proceed with the action(s).\n");
7015 /* General test: make sure there is space for
7016 * 'raiddisks' device extents of size 'size' at a given
7019 unsigned long long minsize
= size
;
7020 unsigned long long start_offset
= MaxSector
;
7023 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
7024 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7029 e
= get_extents(super
, dl
);
7032 unsigned long long esize
;
7033 esize
= e
[i
].start
- pos
;
7034 if (esize
>= minsize
)
7036 if (found
&& start_offset
== MaxSector
) {
7039 } else if (found
&& pos
!= start_offset
) {
7043 pos
= e
[i
].start
+ e
[i
].size
;
7045 } while (e
[i
-1].size
);
7050 if (dcnt
< raiddisks
) {
7052 pr_err("imsm: Not enough devices with space for this array (%d < %d)\n",
7059 /* This device must be a member of the set */
7060 if (!stat_is_blkdev(dev
, &rdev
))
7062 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7063 if (dl
->major
== (int)major(rdev
) &&
7064 dl
->minor
== (int)minor(rdev
))
7069 pr_err("%s is not in the same imsm set\n", dev
);
7071 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
7072 /* If a volume is present then the current creation attempt
7073 * cannot incorporate new spares because the orom may not
7074 * understand this configuration (all member disks must be
7075 * members of each array in the container).
7077 pr_err("%s is a spare and a volume is already defined for this container\n", dev
);
7078 pr_err("The option-rom requires all member disks to be a member of all volumes\n");
7080 } else if (super
->orom
&& mpb
->num_raid_devs
> 0 &&
7081 mpb
->num_disks
!= raiddisks
) {
7082 pr_err("The option-rom requires all member disks to be a member of all volumes\n");
7086 /* retrieve the largest free space block */
7087 e
= get_extents(super
, dl
);
7092 unsigned long long esize
;
7094 esize
= e
[i
].start
- pos
;
7095 if (esize
>= maxsize
)
7097 pos
= e
[i
].start
+ e
[i
].size
;
7099 } while (e
[i
-1].size
);
7104 pr_err("unable to determine free space for: %s\n",
7108 if (maxsize
< size
) {
7110 pr_err("%s not enough space (%llu < %llu)\n",
7111 dev
, maxsize
, size
);
7115 /* count total number of extents for merge */
7117 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7119 i
+= dl
->extent_cnt
;
7121 maxsize
= merge_extents(super
, i
);
7123 if (!check_env("IMSM_NO_PLATFORM") &&
7124 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
7125 pr_err("attempting to create a second volume with size less then remaining space. Aborting...\n");
7129 if (maxsize
< size
|| maxsize
== 0) {
7132 pr_err("no free space left on device. Aborting...\n");
7134 pr_err("not enough space to create volume of given size (%llu < %llu). Aborting...\n",
7140 *freesize
= maxsize
;
7143 int count
= count_volumes(super
->hba
,
7144 super
->orom
->dpa
, verbose
);
7145 if (super
->orom
->vphba
<= count
) {
7146 pr_vrb("platform does not support more than %d raid volumes.\n",
7147 super
->orom
->vphba
);
7154 static int imsm_get_free_size(struct supertype
*st
, int raiddisks
,
7155 unsigned long long size
, int chunk
,
7156 unsigned long long *freesize
)
7158 struct intel_super
*super
= st
->sb
;
7159 struct imsm_super
*mpb
= super
->anchor
;
7164 unsigned long long maxsize
;
7165 unsigned long long minsize
;
7169 /* find the largest common start free region of the possible disks */
7173 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7179 /* don't activate new spares if we are orom constrained
7180 * and there is already a volume active in the container
7182 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
7185 e
= get_extents(super
, dl
);
7188 for (i
= 1; e
[i
-1].size
; i
++)
7196 maxsize
= merge_extents(super
, extent_cnt
);
7200 minsize
= chunk
* 2;
7202 if (cnt
< raiddisks
||
7203 (super
->orom
&& used
&& used
!= raiddisks
) ||
7204 maxsize
< minsize
||
7206 pr_err("not enough devices with space to create array.\n");
7207 return 0; /* No enough free spaces large enough */
7218 if (!check_env("IMSM_NO_PLATFORM") &&
7219 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
7220 pr_err("attempting to create a second volume with size less then remaining space. Aborting...\n");
7224 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7226 dl
->raiddisk
= cnt
++;
7230 dprintf("imsm: imsm_get_free_size() returns : %llu\n", size
);
7235 static int reserve_space(struct supertype
*st
, int raiddisks
,
7236 unsigned long long size
, int chunk
,
7237 unsigned long long *freesize
)
7239 struct intel_super
*super
= st
->sb
;
7244 rv
= imsm_get_free_size(st
, raiddisks
, size
, chunk
, freesize
);
7247 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7249 dl
->raiddisk
= cnt
++;
7256 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
7257 int raiddisks
, int *chunk
, unsigned long long size
,
7258 unsigned long long data_offset
,
7259 char *dev
, unsigned long long *freesize
,
7260 int consistency_policy
, int verbose
)
7267 * if given unused devices create a container
7268 * if given given devices in a container create a member volume
7270 if (level
== LEVEL_CONTAINER
) {
7271 /* Must be a fresh device to add to a container */
7272 return validate_geometry_imsm_container(st
, level
, layout
,
7282 struct intel_super
*super
= st
->sb
;
7283 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
7284 raiddisks
, chunk
, size
,
7287 /* we are being asked to automatically layout a
7288 * new volume based on the current contents of
7289 * the container. If the the parameters can be
7290 * satisfied reserve_space will record the disks,
7291 * start offset, and size of the volume to be
7292 * created. add_to_super and getinfo_super
7293 * detect when autolayout is in progress.
7295 /* assuming that freesize is always given when array is
7297 if (super
->orom
&& freesize
) {
7299 count
= count_volumes(super
->hba
,
7300 super
->orom
->dpa
, verbose
);
7301 if (super
->orom
->vphba
<= count
) {
7302 pr_vrb("platform does not support more than %d raid volumes.\n",
7303 super
->orom
->vphba
);
7308 return reserve_space(st
, raiddisks
, size
,
7314 /* creating in a given container */
7315 return validate_geometry_imsm_volume(st
, level
, layout
,
7316 raiddisks
, chunk
, size
,
7318 dev
, freesize
, verbose
);
7321 /* This device needs to be a device in an 'imsm' container */
7322 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
7325 pr_err("Cannot create this array on device %s\n",
7330 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
7332 pr_err("Cannot open %s: %s\n",
7333 dev
, strerror(errno
));
7336 /* Well, it is in use by someone, maybe an 'imsm' container. */
7337 cfd
= open_container(fd
);
7341 pr_err("Cannot use %s: It is busy\n",
7345 sra
= sysfs_read(cfd
, NULL
, GET_VERSION
);
7346 if (sra
&& sra
->array
.major_version
== -1 &&
7347 strcmp(sra
->text_version
, "imsm") == 0)
7351 /* This is a member of a imsm container. Load the container
7352 * and try to create a volume
7354 struct intel_super
*super
;
7356 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
, NULL
, 1) == 0) {
7358 strcpy(st
->container_devnm
, fd2devnm(cfd
));
7360 return validate_geometry_imsm_volume(st
, level
, layout
,
7362 size
, data_offset
, dev
,
7369 pr_err("failed container membership check\n");
7375 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
7377 struct intel_super
*super
= st
->sb
;
7379 if (level
&& *level
== UnSet
)
7380 *level
= LEVEL_CONTAINER
;
7382 if (level
&& layout
&& *layout
== UnSet
)
7383 *layout
= imsm_level_to_layout(*level
);
7385 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0))
7386 *chunk
= imsm_default_chunk(super
->orom
);
7389 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
7391 static int kill_subarray_imsm(struct supertype
*st
)
7393 /* remove the subarray currently referenced by ->current_vol */
7395 struct intel_dev
**dp
;
7396 struct intel_super
*super
= st
->sb
;
7397 __u8 current_vol
= super
->current_vol
;
7398 struct imsm_super
*mpb
= super
->anchor
;
7400 if (super
->current_vol
< 0)
7402 super
->current_vol
= -1; /* invalidate subarray cursor */
7404 /* block deletions that would change the uuid of active subarrays
7406 * FIXME when immutable ids are available, but note that we'll
7407 * also need to fixup the invalidated/active subarray indexes in
7410 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7413 if (i
< current_vol
)
7415 sprintf(subarray
, "%u", i
);
7416 if (is_subarray_active(subarray
, st
->devnm
)) {
7417 pr_err("deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
7424 if (st
->update_tail
) {
7425 struct imsm_update_kill_array
*u
= xmalloc(sizeof(*u
));
7427 u
->type
= update_kill_array
;
7428 u
->dev_idx
= current_vol
;
7429 append_metadata_update(st
, u
, sizeof(*u
));
7434 for (dp
= &super
->devlist
; *dp
;)
7435 if ((*dp
)->index
== current_vol
) {
7438 handle_missing(super
, (*dp
)->dev
);
7439 if ((*dp
)->index
> current_vol
)
7444 /* no more raid devices, all active components are now spares,
7445 * but of course failed are still failed
7447 if (--mpb
->num_raid_devs
== 0) {
7450 for (d
= super
->disks
; d
; d
= d
->next
)
7455 super
->updates_pending
++;
7460 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
7461 char *update
, struct mddev_ident
*ident
)
7463 /* update the subarray currently referenced by ->current_vol */
7464 struct intel_super
*super
= st
->sb
;
7465 struct imsm_super
*mpb
= super
->anchor
;
7467 if (strcmp(update
, "name") == 0) {
7468 char *name
= ident
->name
;
7472 if (is_subarray_active(subarray
, st
->devnm
)) {
7473 pr_err("Unable to update name of active subarray\n");
7477 if (!check_name(super
, name
, 0))
7480 vol
= strtoul(subarray
, &ep
, 10);
7481 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
7484 if (st
->update_tail
) {
7485 struct imsm_update_rename_array
*u
= xmalloc(sizeof(*u
));
7487 u
->type
= update_rename_array
;
7489 strncpy((char *) u
->name
, name
, MAX_RAID_SERIAL_LEN
);
7490 u
->name
[MAX_RAID_SERIAL_LEN
-1] = '\0';
7491 append_metadata_update(st
, u
, sizeof(*u
));
7493 struct imsm_dev
*dev
;
7496 dev
= get_imsm_dev(super
, vol
);
7497 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
7498 dev
->volume
[MAX_RAID_SERIAL_LEN
-1] = '\0';
7499 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7500 dev
= get_imsm_dev(super
, i
);
7501 handle_missing(super
, dev
);
7503 super
->updates_pending
++;
7505 } else if (strcmp(update
, "ppl") == 0 ||
7506 strcmp(update
, "no-ppl") == 0) {
7509 int vol
= strtoul(subarray
, &ep
, 10);
7511 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
7514 if (strcmp(update
, "ppl") == 0)
7515 new_policy
= RWH_MULTIPLE_DISTRIBUTED
;
7517 new_policy
= RWH_MULTIPLE_OFF
;
7519 if (st
->update_tail
) {
7520 struct imsm_update_rwh_policy
*u
= xmalloc(sizeof(*u
));
7522 u
->type
= update_rwh_policy
;
7524 u
->new_policy
= new_policy
;
7525 append_metadata_update(st
, u
, sizeof(*u
));
7527 struct imsm_dev
*dev
;
7529 dev
= get_imsm_dev(super
, vol
);
7530 dev
->rwh_policy
= new_policy
;
7531 super
->updates_pending
++;
7539 static int is_gen_migration(struct imsm_dev
*dev
)
7544 if (!dev
->vol
.migr_state
)
7547 if (migr_type(dev
) == MIGR_GEN_MIGR
)
7553 static int is_rebuilding(struct imsm_dev
*dev
)
7555 struct imsm_map
*migr_map
;
7557 if (!dev
->vol
.migr_state
)
7560 if (migr_type(dev
) != MIGR_REBUILD
)
7563 migr_map
= get_imsm_map(dev
, MAP_1
);
7565 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
7571 static int is_initializing(struct imsm_dev
*dev
)
7573 struct imsm_map
*migr_map
;
7575 if (!dev
->vol
.migr_state
)
7578 if (migr_type(dev
) != MIGR_INIT
)
7581 migr_map
= get_imsm_map(dev
, MAP_1
);
7583 if (migr_map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
7589 static void update_recovery_start(struct intel_super
*super
,
7590 struct imsm_dev
*dev
,
7591 struct mdinfo
*array
)
7593 struct mdinfo
*rebuild
= NULL
;
7597 if (!is_rebuilding(dev
))
7600 /* Find the rebuild target, but punt on the dual rebuild case */
7601 for (d
= array
->devs
; d
; d
= d
->next
)
7602 if (d
->recovery_start
== 0) {
7609 /* (?) none of the disks are marked with
7610 * IMSM_ORD_REBUILD, so assume they are missing and the
7611 * disk_ord_tbl was not correctly updated
7613 dprintf("failed to locate out-of-sync disk\n");
7617 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
7618 rebuild
->recovery_start
= units
* blocks_per_migr_unit(super
, dev
);
7621 static int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
);
7623 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
7625 /* Given a container loaded by load_super_imsm_all,
7626 * extract information about all the arrays into
7628 * If 'subarray' is given, just extract info about that array.
7630 * For each imsm_dev create an mdinfo, fill it in,
7631 * then look for matching devices in super->disks
7632 * and create appropriate device mdinfo.
7634 struct intel_super
*super
= st
->sb
;
7635 struct imsm_super
*mpb
= super
->anchor
;
7636 struct mdinfo
*rest
= NULL
;
7640 int spare_disks
= 0;
7642 /* do not assemble arrays when not all attributes are supported */
7643 if (imsm_check_attributes(mpb
->attributes
) == 0) {
7645 pr_err("Unsupported attributes in IMSM metadata.Arrays activation is blocked.\n");
7648 /* count spare devices, not used in maps
7650 for (d
= super
->disks
; d
; d
= d
->next
)
7654 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7655 struct imsm_dev
*dev
;
7656 struct imsm_map
*map
;
7657 struct imsm_map
*map2
;
7658 struct mdinfo
*this;
7665 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
7668 dev
= get_imsm_dev(super
, i
);
7669 map
= get_imsm_map(dev
, MAP_0
);
7670 map2
= get_imsm_map(dev
, MAP_1
);
7671 level
= get_imsm_raid_level(map
);
7673 /* do not publish arrays that are in the middle of an
7674 * unsupported migration
7676 if (dev
->vol
.migr_state
&&
7677 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
7678 pr_err("cannot assemble volume '%.16s': unsupported migration in progress\n",
7682 /* do not publish arrays that are not support by controller's
7686 this = xmalloc(sizeof(*this));
7688 super
->current_vol
= i
;
7689 getinfo_super_imsm_volume(st
, this, NULL
);
7691 chunk
= __le16_to_cpu(map
->blocks_per_strip
) >> 1;
7692 /* mdadm does not support all metadata features- set the bit in all arrays state */
7693 if (!validate_geometry_imsm_orom(super
,
7694 level
, /* RAID level */
7695 imsm_level_to_layout(level
),
7696 map
->num_members
, /* raid disks */
7697 &chunk
, join_u32(dev
->size_low
, dev
->size_high
),
7699 pr_err("IMSM RAID geometry validation failed. Array %s activation is blocked.\n",
7701 this->array
.state
|=
7702 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
7703 (1<<MD_SB_BLOCK_VOLUME
);
7706 /* if array has bad blocks, set suitable bit in all arrays state */
7708 this->array
.state
|=
7709 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
7710 (1<<MD_SB_BLOCK_VOLUME
);
7712 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
7713 unsigned long long recovery_start
;
7714 struct mdinfo
*info_d
;
7722 idx
= get_imsm_disk_idx(dev
, slot
, MAP_0
);
7723 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
7724 for (d
= super
->disks
; d
; d
= d
->next
)
7725 if (d
->index
== idx
)
7728 recovery_start
= MaxSector
;
7731 if (d
&& is_failed(&d
->disk
))
7733 if (!skip
&& (ord
& IMSM_ORD_REBUILD
))
7737 * if we skip some disks the array will be assmebled degraded;
7738 * reset resync start to avoid a dirty-degraded
7739 * situation when performing the intial sync
7744 if (!(dev
->vol
.dirty
& RAIDVOL_DIRTY
)) {
7745 if ((!able_to_resync(level
, missing
) ||
7746 recovery_start
== 0))
7747 this->resync_start
= MaxSector
;
7750 * FIXME handle dirty degraded
7757 info_d
= xcalloc(1, sizeof(*info_d
));
7758 info_d
->next
= this->devs
;
7759 this->devs
= info_d
;
7761 info_d
->disk
.number
= d
->index
;
7762 info_d
->disk
.major
= d
->major
;
7763 info_d
->disk
.minor
= d
->minor
;
7764 info_d
->disk
.raid_disk
= slot
;
7765 info_d
->recovery_start
= recovery_start
;
7767 if (slot
< map2
->num_members
)
7768 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
7770 this->array
.spare_disks
++;
7772 if (slot
< map
->num_members
)
7773 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
7775 this->array
.spare_disks
++;
7777 if (info_d
->recovery_start
== MaxSector
)
7778 this->array
.working_disks
++;
7780 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
7781 info_d
->data_offset
= pba_of_lba0(map
);
7783 if (map
->raid_level
== 5) {
7784 info_d
->component_size
=
7785 num_data_stripes(map
) *
7786 map
->blocks_per_strip
;
7787 info_d
->ppl_sector
= this->ppl_sector
;
7788 info_d
->ppl_size
= this->ppl_size
;
7789 if (this->consistency_policy
== CONSISTENCY_POLICY_PPL
&&
7790 recovery_start
== 0)
7791 this->resync_start
= 0;
7793 info_d
->component_size
= blocks_per_member(map
);
7796 info_d
->bb
.supported
= 1;
7797 get_volume_badblocks(super
->bbm_log
, ord_to_idx(ord
),
7798 info_d
->data_offset
,
7799 info_d
->component_size
,
7802 /* now that the disk list is up-to-date fixup recovery_start */
7803 update_recovery_start(super
, dev
, this);
7804 this->array
.spare_disks
+= spare_disks
;
7806 /* check for reshape */
7807 if (this->reshape_active
== 1)
7808 recover_backup_imsm(st
, this);
7815 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
7816 int failed
, int look_in_map
)
7818 struct imsm_map
*map
;
7820 map
= get_imsm_map(dev
, look_in_map
);
7823 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
7824 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
7826 switch (get_imsm_raid_level(map
)) {
7828 return IMSM_T_STATE_FAILED
;
7831 if (failed
< map
->num_members
)
7832 return IMSM_T_STATE_DEGRADED
;
7834 return IMSM_T_STATE_FAILED
;
7839 * check to see if any mirrors have failed, otherwise we
7840 * are degraded. Even numbered slots are mirrored on
7844 /* gcc -Os complains that this is unused */
7845 int insync
= insync
;
7847 for (i
= 0; i
< map
->num_members
; i
++) {
7848 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_X
);
7849 int idx
= ord_to_idx(ord
);
7850 struct imsm_disk
*disk
;
7852 /* reset the potential in-sync count on even-numbered
7853 * slots. num_copies is always 2 for imsm raid10
7858 disk
= get_imsm_disk(super
, idx
);
7859 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
7862 /* no in-sync disks left in this mirror the
7866 return IMSM_T_STATE_FAILED
;
7869 return IMSM_T_STATE_DEGRADED
;
7873 return IMSM_T_STATE_DEGRADED
;
7875 return IMSM_T_STATE_FAILED
;
7881 return map
->map_state
;
7884 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
7889 struct imsm_disk
*disk
;
7890 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7891 struct imsm_map
*prev
= get_imsm_map(dev
, MAP_1
);
7892 struct imsm_map
*map_for_loop
;
7897 /* at the beginning of migration we set IMSM_ORD_REBUILD on
7898 * disks that are being rebuilt. New failures are recorded to
7899 * map[0]. So we look through all the disks we started with and
7900 * see if any failures are still present, or if any new ones
7904 if (prev
&& (map
->num_members
< prev
->num_members
))
7905 map_for_loop
= prev
;
7907 for (i
= 0; i
< map_for_loop
->num_members
; i
++) {
7909 /* when MAP_X is passed both maps failures are counted
7912 (look_in_map
== MAP_1
|| look_in_map
== MAP_X
) &&
7913 i
< prev
->num_members
) {
7914 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
7915 idx_1
= ord_to_idx(ord
);
7917 disk
= get_imsm_disk(super
, idx_1
);
7918 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
7921 if ((look_in_map
== MAP_0
|| look_in_map
== MAP_X
) &&
7922 i
< map
->num_members
) {
7923 ord
= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
7924 idx
= ord_to_idx(ord
);
7927 disk
= get_imsm_disk(super
, idx
);
7928 if (!disk
|| is_failed(disk
) ||
7929 ord
& IMSM_ORD_REBUILD
)
7938 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
7941 struct intel_super
*super
= c
->sb
;
7942 struct imsm_super
*mpb
= super
->anchor
;
7943 struct imsm_update_prealloc_bb_mem u
;
7945 if (atoi(inst
) >= mpb
->num_raid_devs
) {
7946 pr_err("subarry index %d, out of range\n", atoi(inst
));
7950 dprintf("imsm: open_new %s\n", inst
);
7951 a
->info
.container_member
= atoi(inst
);
7953 u
.type
= update_prealloc_badblocks_mem
;
7954 imsm_update_metadata_locally(c
, &u
, sizeof(u
));
7959 static int is_resyncing(struct imsm_dev
*dev
)
7961 struct imsm_map
*migr_map
;
7963 if (!dev
->vol
.migr_state
)
7966 if (migr_type(dev
) == MIGR_INIT
||
7967 migr_type(dev
) == MIGR_REPAIR
)
7970 if (migr_type(dev
) == MIGR_GEN_MIGR
)
7973 migr_map
= get_imsm_map(dev
, MAP_1
);
7975 if (migr_map
->map_state
== IMSM_T_STATE_NORMAL
&&
7976 dev
->vol
.migr_type
!= MIGR_GEN_MIGR
)
7982 /* return true if we recorded new information */
7983 static int mark_failure(struct intel_super
*super
,
7984 struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
7988 struct imsm_map
*map
;
7989 char buf
[MAX_RAID_SERIAL_LEN
+3];
7990 unsigned int len
, shift
= 0;
7992 /* new failures are always set in map[0] */
7993 map
= get_imsm_map(dev
, MAP_0
);
7995 slot
= get_imsm_disk_slot(map
, idx
);
7999 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
8000 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
8003 memcpy(buf
, disk
->serial
, MAX_RAID_SERIAL_LEN
);
8004 buf
[MAX_RAID_SERIAL_LEN
] = '\000';
8006 if ((len
= strlen(buf
)) >= MAX_RAID_SERIAL_LEN
)
8007 shift
= len
- MAX_RAID_SERIAL_LEN
+ 1;
8008 strncpy((char *)disk
->serial
, &buf
[shift
], MAX_RAID_SERIAL_LEN
);
8010 disk
->status
|= FAILED_DISK
;
8011 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
8012 /* mark failures in second map if second map exists and this disk
8014 * This is valid for migration, initialization and rebuild
8016 if (dev
->vol
.migr_state
) {
8017 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
8018 int slot2
= get_imsm_disk_slot(map2
, idx
);
8020 if (slot2
< map2
->num_members
&& slot2
>= 0)
8021 set_imsm_ord_tbl_ent(map2
, slot2
,
8022 idx
| IMSM_ORD_REBUILD
);
8024 if (map
->failed_disk_num
== 0xff)
8025 map
->failed_disk_num
= slot
;
8027 clear_disk_badblocks(super
->bbm_log
, ord_to_idx(ord
));
8032 static void mark_missing(struct intel_super
*super
,
8033 struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
8035 mark_failure(super
, dev
, disk
, idx
);
8037 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
8040 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
8041 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
8044 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
8048 if (!super
->missing
)
8051 /* When orom adds replacement for missing disk it does
8052 * not remove entry of missing disk, but just updates map with
8053 * new added disk. So it is not enough just to test if there is
8054 * any missing disk, we have to look if there are any failed disks
8055 * in map to stop migration */
8057 dprintf("imsm: mark missing\n");
8058 /* end process for initialization and rebuild only
8060 if (is_gen_migration(dev
) == 0) {
8061 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
8065 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8066 struct imsm_map
*map1
;
8067 int i
, ord
, ord_map1
;
8070 for (i
= 0; i
< map
->num_members
; i
++) {
8071 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
8072 if (!(ord
& IMSM_ORD_REBUILD
))
8075 map1
= get_imsm_map(dev
, MAP_1
);
8079 ord_map1
= __le32_to_cpu(map1
->disk_ord_tbl
[i
]);
8080 if (ord_map1
& IMSM_ORD_REBUILD
)
8085 map_state
= imsm_check_degraded(super
, dev
,
8087 end_migration(dev
, super
, map_state
);
8091 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
8092 mark_missing(super
, dev
, &dl
->disk
, dl
->index
);
8093 super
->updates_pending
++;
8096 static unsigned long long imsm_set_array_size(struct imsm_dev
*dev
,
8099 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
8100 unsigned long long array_blocks
;
8101 struct imsm_map
*map
;
8103 if (used_disks
== 0) {
8104 /* when problems occures
8105 * return current array_blocks value
8107 array_blocks
= __le32_to_cpu(dev
->size_high
);
8108 array_blocks
= array_blocks
<< 32;
8109 array_blocks
+= __le32_to_cpu(dev
->size_low
);
8111 return array_blocks
;
8114 /* set array size in metadata
8116 if (new_size
<= 0) {
8117 /* OLCE size change is caused by added disks
8119 map
= get_imsm_map(dev
, MAP_0
);
8120 array_blocks
= blocks_per_member(map
) * used_disks
;
8122 /* Online Volume Size Change
8123 * Using available free space
8125 array_blocks
= new_size
;
8128 array_blocks
= round_size_to_mb(array_blocks
, used_disks
);
8129 dev
->size_low
= __cpu_to_le32((__u32
)array_blocks
);
8130 dev
->size_high
= __cpu_to_le32((__u32
)(array_blocks
>> 32));
8132 return array_blocks
;
8135 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
8137 static void imsm_progress_container_reshape(struct intel_super
*super
)
8139 /* if no device has a migr_state, but some device has a
8140 * different number of members than the previous device, start
8141 * changing the number of devices in this device to match
8144 struct imsm_super
*mpb
= super
->anchor
;
8145 int prev_disks
= -1;
8149 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8150 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
8151 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8152 struct imsm_map
*map2
;
8153 int prev_num_members
;
8155 if (dev
->vol
.migr_state
)
8158 if (prev_disks
== -1)
8159 prev_disks
= map
->num_members
;
8160 if (prev_disks
== map
->num_members
)
8163 /* OK, this array needs to enter reshape mode.
8164 * i.e it needs a migr_state
8167 copy_map_size
= sizeof_imsm_map(map
);
8168 prev_num_members
= map
->num_members
;
8169 map
->num_members
= prev_disks
;
8170 dev
->vol
.migr_state
= 1;
8171 dev
->vol
.curr_migr_unit
= 0;
8172 set_migr_type(dev
, MIGR_GEN_MIGR
);
8173 for (i
= prev_num_members
;
8174 i
< map
->num_members
; i
++)
8175 set_imsm_ord_tbl_ent(map
, i
, i
);
8176 map2
= get_imsm_map(dev
, MAP_1
);
8177 /* Copy the current map */
8178 memcpy(map2
, map
, copy_map_size
);
8179 map2
->num_members
= prev_num_members
;
8181 imsm_set_array_size(dev
, -1);
8182 super
->clean_migration_record_by_mdmon
= 1;
8183 super
->updates_pending
++;
8187 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
8188 * states are handled in imsm_set_disk() with one exception, when a
8189 * resync is stopped due to a new failure this routine will set the
8190 * 'degraded' state for the array.
8192 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
8194 int inst
= a
->info
.container_member
;
8195 struct intel_super
*super
= a
->container
->sb
;
8196 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8197 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8198 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
8199 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8200 __u32 blocks_per_unit
;
8202 if (dev
->vol
.migr_state
&&
8203 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
8204 /* array state change is blocked due to reshape action
8206 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
8207 * - finish the reshape (if last_checkpoint is big and action != reshape)
8208 * - update curr_migr_unit
8210 if (a
->curr_action
== reshape
) {
8211 /* still reshaping, maybe update curr_migr_unit */
8212 goto mark_checkpoint
;
8214 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
8215 /* for some reason we aborted the reshape.
8217 * disable automatic metadata rollback
8218 * user action is required to recover process
8221 struct imsm_map
*map2
=
8222 get_imsm_map(dev
, MAP_1
);
8223 dev
->vol
.migr_state
= 0;
8224 set_migr_type(dev
, 0);
8225 dev
->vol
.curr_migr_unit
= 0;
8227 sizeof_imsm_map(map2
));
8228 super
->updates_pending
++;
8231 if (a
->last_checkpoint
>= a
->info
.component_size
) {
8232 unsigned long long array_blocks
;
8236 used_disks
= imsm_num_data_members(dev
, MAP_0
);
8237 if (used_disks
> 0) {
8239 blocks_per_member(map
) *
8242 round_size_to_mb(array_blocks
,
8244 a
->info
.custom_array_size
= array_blocks
;
8245 /* encourage manager to update array
8249 a
->check_reshape
= 1;
8251 /* finalize online capacity expansion/reshape */
8252 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
8254 mdi
->disk
.raid_disk
,
8257 imsm_progress_container_reshape(super
);
8262 /* before we activate this array handle any missing disks */
8263 if (consistent
== 2)
8264 handle_missing(super
, dev
);
8266 if (consistent
== 2 &&
8267 (!is_resync_complete(&a
->info
) ||
8268 map_state
!= IMSM_T_STATE_NORMAL
||
8269 dev
->vol
.migr_state
))
8272 if (is_resync_complete(&a
->info
)) {
8273 /* complete intialization / resync,
8274 * recovery and interrupted recovery is completed in
8277 if (is_resyncing(dev
)) {
8278 dprintf("imsm: mark resync done\n");
8279 end_migration(dev
, super
, map_state
);
8280 super
->updates_pending
++;
8281 a
->last_checkpoint
= 0;
8283 } else if ((!is_resyncing(dev
) && !failed
) &&
8284 (imsm_reshape_blocks_arrays_changes(super
) == 0)) {
8285 /* mark the start of the init process if nothing is failed */
8286 dprintf("imsm: mark resync start\n");
8287 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
8288 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
8290 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
8291 super
->updates_pending
++;
8295 /* skip checkpointing for general migration,
8296 * it is controlled in mdadm
8298 if (is_gen_migration(dev
))
8299 goto skip_mark_checkpoint
;
8301 /* check if we can update curr_migr_unit from resync_start, recovery_start */
8302 blocks_per_unit
= blocks_per_migr_unit(super
, dev
);
8303 if (blocks_per_unit
) {
8307 units
= a
->last_checkpoint
/ blocks_per_unit
;
8310 /* check that we did not overflow 32-bits, and that
8311 * curr_migr_unit needs updating
8313 if (units32
== units
&&
8315 __le32_to_cpu(dev
->vol
.curr_migr_unit
) != units32
) {
8316 dprintf("imsm: mark checkpoint (%u)\n", units32
);
8317 dev
->vol
.curr_migr_unit
= __cpu_to_le32(units32
);
8318 super
->updates_pending
++;
8322 skip_mark_checkpoint
:
8323 /* mark dirty / clean */
8324 if (((dev
->vol
.dirty
& RAIDVOL_DIRTY
) && consistent
) ||
8325 (!(dev
->vol
.dirty
& RAIDVOL_DIRTY
) && !consistent
)) {
8326 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
8328 dev
->vol
.dirty
= RAIDVOL_CLEAN
;
8330 dev
->vol
.dirty
= RAIDVOL_DIRTY
;
8331 if (dev
->rwh_policy
== RWH_DISTRIBUTED
||
8332 dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)
8333 dev
->vol
.dirty
|= RAIDVOL_DSRECORD_VALID
;
8335 super
->updates_pending
++;
8341 static int imsm_disk_slot_to_ord(struct active_array
*a
, int slot
)
8343 int inst
= a
->info
.container_member
;
8344 struct intel_super
*super
= a
->container
->sb
;
8345 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8346 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8348 if (slot
> map
->num_members
) {
8349 pr_err("imsm: imsm_disk_slot_to_ord %d out of range 0..%d\n",
8350 slot
, map
->num_members
- 1);
8357 return get_imsm_ord_tbl_ent(dev
, slot
, MAP_0
);
8360 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
8362 int inst
= a
->info
.container_member
;
8363 struct intel_super
*super
= a
->container
->sb
;
8364 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8365 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8366 struct imsm_disk
*disk
;
8368 int recovery_not_finished
= 0;
8372 int rebuild_done
= 0;
8375 ord
= get_imsm_ord_tbl_ent(dev
, n
, MAP_X
);
8379 dprintf("imsm: set_disk %d:%x\n", n
, state
);
8380 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
8382 /* check for new failures */
8383 if (state
& DS_FAULTY
) {
8384 if (mark_failure(super
, dev
, disk
, ord_to_idx(ord
)))
8385 super
->updates_pending
++;
8388 /* check if in_sync */
8389 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
8390 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
8392 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
8394 super
->updates_pending
++;
8397 failed
= imsm_count_failed(super
, dev
, MAP_0
);
8398 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8400 /* check if recovery complete, newly degraded, or failed */
8401 dprintf("imsm: Detected transition to state ");
8402 switch (map_state
) {
8403 case IMSM_T_STATE_NORMAL
: /* transition to normal state */
8404 dprintf("normal: ");
8405 if (is_rebuilding(dev
)) {
8406 dprintf_cont("while rebuilding");
8407 /* check if recovery is really finished */
8408 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
8409 if (mdi
->recovery_start
!= MaxSector
) {
8410 recovery_not_finished
= 1;
8413 if (recovery_not_finished
) {
8415 dprintf("Rebuild has not finished yet, state not changed");
8416 if (a
->last_checkpoint
< mdi
->recovery_start
) {
8417 a
->last_checkpoint
= mdi
->recovery_start
;
8418 super
->updates_pending
++;
8422 end_migration(dev
, super
, map_state
);
8423 map
= get_imsm_map(dev
, MAP_0
);
8424 map
->failed_disk_num
= ~0;
8425 super
->updates_pending
++;
8426 a
->last_checkpoint
= 0;
8429 if (is_gen_migration(dev
)) {
8430 dprintf_cont("while general migration");
8431 if (a
->last_checkpoint
>= a
->info
.component_size
)
8432 end_migration(dev
, super
, map_state
);
8434 map
->map_state
= map_state
;
8435 map
= get_imsm_map(dev
, MAP_0
);
8436 map
->failed_disk_num
= ~0;
8437 super
->updates_pending
++;
8441 case IMSM_T_STATE_DEGRADED
: /* transition to degraded state */
8442 dprintf_cont("degraded: ");
8443 if (map
->map_state
!= map_state
&& !dev
->vol
.migr_state
) {
8444 dprintf_cont("mark degraded");
8445 map
->map_state
= map_state
;
8446 super
->updates_pending
++;
8447 a
->last_checkpoint
= 0;
8450 if (is_rebuilding(dev
)) {
8451 dprintf_cont("while rebuilding.");
8452 if (map
->map_state
!= map_state
) {
8453 dprintf_cont(" Map state change");
8454 end_migration(dev
, super
, map_state
);
8455 super
->updates_pending
++;
8456 } else if (!rebuild_done
) {
8460 /* check if recovery is really finished */
8461 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
8462 if (mdi
->recovery_start
!= MaxSector
) {
8463 recovery_not_finished
= 1;
8466 if (recovery_not_finished
) {
8468 dprintf("Rebuild has not finished yet, state not changed");
8469 if (a
->last_checkpoint
< mdi
->recovery_start
) {
8470 a
->last_checkpoint
=
8471 mdi
->recovery_start
;
8472 super
->updates_pending
++;
8477 dprintf_cont(" Rebuild done, still degraded");
8478 dev
->vol
.migr_state
= 0;
8479 set_migr_type(dev
, 0);
8480 dev
->vol
.curr_migr_unit
= 0;
8482 for (i
= 0; i
< map
->num_members
; i
++) {
8483 int idx
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
8485 if (idx
& IMSM_ORD_REBUILD
)
8486 map
->failed_disk_num
= i
;
8488 super
->updates_pending
++;
8491 if (is_gen_migration(dev
)) {
8492 dprintf_cont("while general migration");
8493 if (a
->last_checkpoint
>= a
->info
.component_size
)
8494 end_migration(dev
, super
, map_state
);
8496 map
->map_state
= map_state
;
8497 manage_second_map(super
, dev
);
8499 super
->updates_pending
++;
8502 if (is_initializing(dev
)) {
8503 dprintf_cont("while initialization.");
8504 map
->map_state
= map_state
;
8505 super
->updates_pending
++;
8509 case IMSM_T_STATE_FAILED
: /* transition to failed state */
8510 dprintf_cont("failed: ");
8511 if (is_gen_migration(dev
)) {
8512 dprintf_cont("while general migration");
8513 map
->map_state
= map_state
;
8514 super
->updates_pending
++;
8517 if (map
->map_state
!= map_state
) {
8518 dprintf_cont("mark failed");
8519 end_migration(dev
, super
, map_state
);
8520 super
->updates_pending
++;
8521 a
->last_checkpoint
= 0;
8526 dprintf_cont("state %i\n", map_state
);
8531 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
8534 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
8535 unsigned long long dsize
;
8536 unsigned long long sectors
;
8537 unsigned int sector_size
;
8539 get_dev_sector_size(fd
, NULL
, §or_size
);
8540 get_dev_size(fd
, NULL
, &dsize
);
8542 if (mpb_size
> sector_size
) {
8543 /* -1 to account for anchor */
8544 sectors
= mpb_sectors(mpb
, sector_size
) - 1;
8546 /* write the extended mpb to the sectors preceeding the anchor */
8547 if (lseek64(fd
, dsize
- (sector_size
* (2 + sectors
)),
8551 if ((unsigned long long)write(fd
, buf
+ sector_size
,
8552 sector_size
* sectors
) != sector_size
* sectors
)
8556 /* first block is stored on second to last sector of the disk */
8557 if (lseek64(fd
, dsize
- (sector_size
* 2), SEEK_SET
) < 0)
8560 if ((unsigned int)write(fd
, buf
, sector_size
) != sector_size
)
8566 static void imsm_sync_metadata(struct supertype
*container
)
8568 struct intel_super
*super
= container
->sb
;
8570 dprintf("sync metadata: %d\n", super
->updates_pending
);
8571 if (!super
->updates_pending
)
8574 write_super_imsm(container
, 0);
8576 super
->updates_pending
= 0;
8579 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
8581 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
8582 int i
= get_imsm_disk_idx(dev
, idx
, MAP_X
);
8585 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8589 if (dl
&& is_failed(&dl
->disk
))
8593 dprintf("found %x:%x\n", dl
->major
, dl
->minor
);
8598 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
8599 struct active_array
*a
, int activate_new
,
8600 struct mdinfo
*additional_test_list
)
8602 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
8603 int idx
= get_imsm_disk_idx(dev
, slot
, MAP_X
);
8604 struct imsm_super
*mpb
= super
->anchor
;
8605 struct imsm_map
*map
;
8606 unsigned long long pos
;
8611 __u32 array_start
= 0;
8612 __u32 array_end
= 0;
8614 struct mdinfo
*test_list
;
8616 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
8617 /* If in this array, skip */
8618 for (d
= a
->info
.devs
; d
; d
= d
->next
)
8619 if (d
->state_fd
>= 0 &&
8620 d
->disk
.major
== dl
->major
&&
8621 d
->disk
.minor
== dl
->minor
) {
8622 dprintf("%x:%x already in array\n",
8623 dl
->major
, dl
->minor
);
8628 test_list
= additional_test_list
;
8630 if (test_list
->disk
.major
== dl
->major
&&
8631 test_list
->disk
.minor
== dl
->minor
) {
8632 dprintf("%x:%x already in additional test list\n",
8633 dl
->major
, dl
->minor
);
8636 test_list
= test_list
->next
;
8641 /* skip in use or failed drives */
8642 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
8644 dprintf("%x:%x status (failed: %d index: %d)\n",
8645 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
8649 /* skip pure spares when we are looking for partially
8650 * assimilated drives
8652 if (dl
->index
== -1 && !activate_new
)
8655 if (!drive_validate_sector_size(super
, dl
))
8658 /* Does this unused device have the requisite free space?
8659 * It needs to be able to cover all member volumes
8661 ex
= get_extents(super
, dl
);
8663 dprintf("cannot get extents\n");
8666 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8667 dev
= get_imsm_dev(super
, i
);
8668 map
= get_imsm_map(dev
, MAP_0
);
8670 /* check if this disk is already a member of
8673 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
8679 array_start
= pba_of_lba0(map
);
8680 array_end
= array_start
+
8681 blocks_per_member(map
) - 1;
8684 /* check that we can start at pba_of_lba0 with
8685 * blocks_per_member of space
8687 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
8691 pos
= ex
[j
].start
+ ex
[j
].size
;
8693 } while (ex
[j
-1].size
);
8700 if (i
< mpb
->num_raid_devs
) {
8701 dprintf("%x:%x does not have %u to %u available\n",
8702 dl
->major
, dl
->minor
, array_start
, array_end
);
8712 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
8714 struct imsm_dev
*dev2
;
8715 struct imsm_map
*map
;
8721 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
8723 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
, MAP_0
);
8724 if (state
== IMSM_T_STATE_FAILED
) {
8725 map
= get_imsm_map(dev2
, MAP_0
);
8728 for (slot
= 0; slot
< map
->num_members
; slot
++) {
8730 * Check if failed disks are deleted from intel
8731 * disk list or are marked to be deleted
8733 idx
= get_imsm_disk_idx(dev2
, slot
, MAP_X
);
8734 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
8736 * Do not rebuild the array if failed disks
8737 * from failed sub-array are not removed from
8741 is_failed(&idisk
->disk
) &&
8742 (idisk
->action
!= DISK_REMOVE
))
8750 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
8751 struct metadata_update
**updates
)
8754 * Find a device with unused free space and use it to replace a
8755 * failed/vacant region in an array. We replace failed regions one a
8756 * array at a time. The result is that a new spare disk will be added
8757 * to the first failed array and after the monitor has finished
8758 * propagating failures the remainder will be consumed.
8760 * FIXME add a capability for mdmon to request spares from another
8764 struct intel_super
*super
= a
->container
->sb
;
8765 int inst
= a
->info
.container_member
;
8766 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8767 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8768 int failed
= a
->info
.array
.raid_disks
;
8769 struct mdinfo
*rv
= NULL
;
8772 struct metadata_update
*mu
;
8774 struct imsm_update_activate_spare
*u
;
8779 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
8780 if ((d
->curr_state
& DS_FAULTY
) &&
8782 /* wait for Removal to happen */
8784 if (d
->state_fd
>= 0)
8788 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
8789 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
8791 if (imsm_reshape_blocks_arrays_changes(super
))
8794 /* Cannot activate another spare if rebuild is in progress already
8796 if (is_rebuilding(dev
)) {
8797 dprintf("imsm: No spare activation allowed. Rebuild in progress already.\n");
8801 if (a
->info
.array
.level
== 4)
8802 /* No repair for takeovered array
8803 * imsm doesn't support raid4
8807 if (imsm_check_degraded(super
, dev
, failed
, MAP_0
) !=
8808 IMSM_T_STATE_DEGRADED
)
8811 if (get_imsm_map(dev
, MAP_0
)->map_state
== IMSM_T_STATE_UNINITIALIZED
) {
8812 dprintf("imsm: No spare activation allowed. Volume is not initialized.\n");
8817 * If there are any failed disks check state of the other volume.
8818 * Block rebuild if the another one is failed until failed disks
8819 * are removed from container.
8822 dprintf("found failed disks in %.*s, check if there anotherfailed sub-array.\n",
8823 MAX_RAID_SERIAL_LEN
, dev
->volume
);
8824 /* check if states of the other volumes allow for rebuild */
8825 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
8827 allowed
= imsm_rebuild_allowed(a
->container
,
8835 /* For each slot, if it is not working, find a spare */
8836 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
8837 for (d
= a
->info
.devs
; d
; d
= d
->next
)
8838 if (d
->disk
.raid_disk
== i
)
8840 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
8841 if (d
&& (d
->state_fd
>= 0))
8845 * OK, this device needs recovery. Try to re-add the
8846 * previous occupant of this slot, if this fails see if
8847 * we can continue the assimilation of a spare that was
8848 * partially assimilated, finally try to activate a new
8851 dl
= imsm_readd(super
, i
, a
);
8853 dl
= imsm_add_spare(super
, i
, a
, 0, rv
);
8855 dl
= imsm_add_spare(super
, i
, a
, 1, rv
);
8859 /* found a usable disk with enough space */
8860 di
= xcalloc(1, sizeof(*di
));
8862 /* dl->index will be -1 in the case we are activating a
8863 * pristine spare. imsm_process_update() will create a
8864 * new index in this case. Once a disk is found to be
8865 * failed in all member arrays it is kicked from the
8868 di
->disk
.number
= dl
->index
;
8870 /* (ab)use di->devs to store a pointer to the device
8873 di
->devs
= (struct mdinfo
*) dl
;
8875 di
->disk
.raid_disk
= i
;
8876 di
->disk
.major
= dl
->major
;
8877 di
->disk
.minor
= dl
->minor
;
8879 di
->recovery_start
= 0;
8880 di
->data_offset
= pba_of_lba0(map
);
8881 di
->component_size
= a
->info
.component_size
;
8882 di
->container_member
= inst
;
8883 di
->bb
.supported
= 1;
8884 if (a
->info
.consistency_policy
== CONSISTENCY_POLICY_PPL
) {
8885 di
->ppl_sector
= get_ppl_sector(super
, inst
);
8886 di
->ppl_size
= MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9;
8888 super
->random
= random32();
8892 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
8893 i
, di
->data_offset
);
8897 /* No spares found */
8899 /* Now 'rv' has a list of devices to return.
8900 * Create a metadata_update record to update the
8901 * disk_ord_tbl for the array
8903 mu
= xmalloc(sizeof(*mu
));
8904 mu
->buf
= xcalloc(num_spares
,
8905 sizeof(struct imsm_update_activate_spare
));
8907 mu
->space_list
= NULL
;
8908 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
8909 mu
->next
= *updates
;
8910 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
8912 for (di
= rv
; di
; di
= di
->next
) {
8913 u
->type
= update_activate_spare
;
8914 u
->dl
= (struct dl
*) di
->devs
;
8916 u
->slot
= di
->disk
.raid_disk
;
8927 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
8929 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
8930 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8931 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, MAP_0
);
8932 struct disk_info
*inf
= get_disk_info(u
);
8933 struct imsm_disk
*disk
;
8937 for (i
= 0; i
< map
->num_members
; i
++) {
8938 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, MAP_X
));
8939 for (j
= 0; j
< new_map
->num_members
; j
++)
8940 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
8947 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
8951 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8952 if (dl
->major
== major
&& dl
->minor
== minor
)
8957 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
8963 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
8964 if (dl
->major
== major
&& dl
->minor
== minor
) {
8967 prev
->next
= dl
->next
;
8969 super
->disks
= dl
->next
;
8971 __free_imsm_disk(dl
);
8972 dprintf("removed %x:%x\n", major
, minor
);
8980 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
8982 static int add_remove_disk_update(struct intel_super
*super
)
8984 int check_degraded
= 0;
8987 /* add/remove some spares to/from the metadata/contrainer */
8988 while (super
->disk_mgmt_list
) {
8989 struct dl
*disk_cfg
;
8991 disk_cfg
= super
->disk_mgmt_list
;
8992 super
->disk_mgmt_list
= disk_cfg
->next
;
8993 disk_cfg
->next
= NULL
;
8995 if (disk_cfg
->action
== DISK_ADD
) {
8996 disk_cfg
->next
= super
->disks
;
8997 super
->disks
= disk_cfg
;
8999 dprintf("added %x:%x\n",
9000 disk_cfg
->major
, disk_cfg
->minor
);
9001 } else if (disk_cfg
->action
== DISK_REMOVE
) {
9002 dprintf("Disk remove action processed: %x.%x\n",
9003 disk_cfg
->major
, disk_cfg
->minor
);
9004 disk
= get_disk_super(super
,
9008 /* store action status */
9009 disk
->action
= DISK_REMOVE
;
9010 /* remove spare disks only */
9011 if (disk
->index
== -1) {
9012 remove_disk_super(super
,
9017 /* release allocate disk structure */
9018 __free_imsm_disk(disk_cfg
);
9021 return check_degraded
;
9024 static int apply_reshape_migration_update(struct imsm_update_reshape_migration
*u
,
9025 struct intel_super
*super
,
9028 struct intel_dev
*id
;
9029 void **tofree
= NULL
;
9032 dprintf("(enter)\n");
9033 if (u
->subdev
< 0 || u
->subdev
> 1) {
9034 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
9037 if (space_list
== NULL
|| *space_list
== NULL
) {
9038 dprintf("imsm: Error: Memory is not allocated\n");
9042 for (id
= super
->devlist
; id
; id
= id
->next
) {
9043 if (id
->index
== (unsigned)u
->subdev
) {
9044 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
9045 struct imsm_map
*map
;
9046 struct imsm_dev
*new_dev
=
9047 (struct imsm_dev
*)*space_list
;
9048 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
9050 struct dl
*new_disk
;
9052 if (new_dev
== NULL
)
9054 *space_list
= **space_list
;
9055 memcpy(new_dev
, dev
, sizeof_imsm_dev(dev
, 0));
9056 map
= get_imsm_map(new_dev
, MAP_0
);
9058 dprintf("imsm: Error: migration in progress");
9062 to_state
= map
->map_state
;
9063 if ((u
->new_level
== 5) && (map
->raid_level
== 0)) {
9065 /* this should not happen */
9066 if (u
->new_disks
[0] < 0) {
9067 map
->failed_disk_num
=
9068 map
->num_members
- 1;
9069 to_state
= IMSM_T_STATE_DEGRADED
;
9071 to_state
= IMSM_T_STATE_NORMAL
;
9073 migrate(new_dev
, super
, to_state
, MIGR_GEN_MIGR
);
9074 if (u
->new_level
> -1)
9075 map
->raid_level
= u
->new_level
;
9076 migr_map
= get_imsm_map(new_dev
, MAP_1
);
9077 if ((u
->new_level
== 5) &&
9078 (migr_map
->raid_level
== 0)) {
9079 int ord
= map
->num_members
- 1;
9080 migr_map
->num_members
--;
9081 if (u
->new_disks
[0] < 0)
9082 ord
|= IMSM_ORD_REBUILD
;
9083 set_imsm_ord_tbl_ent(map
,
9084 map
->num_members
- 1,
9088 tofree
= (void **)dev
;
9090 /* update chunk size
9092 if (u
->new_chunksize
> 0) {
9093 unsigned long long num_data_stripes
;
9095 imsm_num_data_members(dev
, MAP_0
);
9097 if (used_disks
== 0)
9100 map
->blocks_per_strip
=
9101 __cpu_to_le16(u
->new_chunksize
* 2);
9103 (join_u32(dev
->size_low
, dev
->size_high
)
9105 num_data_stripes
/= map
->blocks_per_strip
;
9106 num_data_stripes
/= map
->num_domains
;
9107 set_num_data_stripes(map
, num_data_stripes
);
9112 if (u
->new_level
!= 5 || migr_map
->raid_level
!= 0 ||
9113 migr_map
->raid_level
== map
->raid_level
)
9116 if (u
->new_disks
[0] >= 0) {
9119 new_disk
= get_disk_super(super
,
9120 major(u
->new_disks
[0]),
9121 minor(u
->new_disks
[0]));
9122 dprintf("imsm: new disk for reshape is: %i:%i (%p, index = %i)\n",
9123 major(u
->new_disks
[0]),
9124 minor(u
->new_disks
[0]),
9125 new_disk
, new_disk
->index
);
9126 if (new_disk
== NULL
)
9127 goto error_disk_add
;
9129 new_disk
->index
= map
->num_members
- 1;
9130 /* slot to fill in autolayout
9132 new_disk
->raiddisk
= new_disk
->index
;
9133 new_disk
->disk
.status
|= CONFIGURED_DISK
;
9134 new_disk
->disk
.status
&= ~SPARE_DISK
;
9136 goto error_disk_add
;
9139 *tofree
= *space_list
;
9140 /* calculate new size
9142 imsm_set_array_size(new_dev
, -1);
9149 *space_list
= tofree
;
9153 dprintf("Error: imsm: Cannot find disk.\n");
9157 static int apply_size_change_update(struct imsm_update_size_change
*u
,
9158 struct intel_super
*super
)
9160 struct intel_dev
*id
;
9163 dprintf("(enter)\n");
9164 if (u
->subdev
< 0 || u
->subdev
> 1) {
9165 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
9169 for (id
= super
->devlist
; id
; id
= id
->next
) {
9170 if (id
->index
== (unsigned)u
->subdev
) {
9171 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
9172 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9173 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
9174 unsigned long long blocks_per_member
;
9175 unsigned long long num_data_stripes
;
9177 /* calculate new size
9179 blocks_per_member
= u
->new_size
/ used_disks
;
9180 num_data_stripes
= blocks_per_member
/
9181 map
->blocks_per_strip
;
9182 num_data_stripes
/= map
->num_domains
;
9183 dprintf("(size: %llu, blocks per member: %llu, num_data_stipes: %llu)\n",
9184 u
->new_size
, blocks_per_member
,
9186 set_blocks_per_member(map
, blocks_per_member
);
9187 set_num_data_stripes(map
, num_data_stripes
);
9188 imsm_set_array_size(dev
, u
->new_size
);
9198 static int apply_update_activate_spare(struct imsm_update_activate_spare
*u
,
9199 struct intel_super
*super
,
9200 struct active_array
*active_array
)
9202 struct imsm_super
*mpb
= super
->anchor
;
9203 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
9204 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9205 struct imsm_map
*migr_map
;
9206 struct active_array
*a
;
9207 struct imsm_disk
*disk
;
9214 int second_map_created
= 0;
9216 for (; u
; u
= u
->next
) {
9217 victim
= get_imsm_disk_idx(dev
, u
->slot
, MAP_X
);
9222 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
9227 pr_err("error: imsm_activate_spare passed an unknown disk (index: %d)\n",
9232 /* count failures (excluding rebuilds and the victim)
9233 * to determine map[0] state
9236 for (i
= 0; i
< map
->num_members
; i
++) {
9239 disk
= get_imsm_disk(super
,
9240 get_imsm_disk_idx(dev
, i
, MAP_X
));
9241 if (!disk
|| is_failed(disk
))
9245 /* adding a pristine spare, assign a new index */
9246 if (dl
->index
< 0) {
9247 dl
->index
= super
->anchor
->num_disks
;
9248 super
->anchor
->num_disks
++;
9251 disk
->status
|= CONFIGURED_DISK
;
9252 disk
->status
&= ~SPARE_DISK
;
9255 to_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
9256 if (!second_map_created
) {
9257 second_map_created
= 1;
9258 map
->map_state
= IMSM_T_STATE_DEGRADED
;
9259 migrate(dev
, super
, to_state
, MIGR_REBUILD
);
9261 map
->map_state
= to_state
;
9262 migr_map
= get_imsm_map(dev
, MAP_1
);
9263 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
9264 set_imsm_ord_tbl_ent(migr_map
, u
->slot
,
9265 dl
->index
| IMSM_ORD_REBUILD
);
9267 /* update the family_num to mark a new container
9268 * generation, being careful to record the existing
9269 * family_num in orig_family_num to clean up after
9270 * earlier mdadm versions that neglected to set it.
9272 if (mpb
->orig_family_num
== 0)
9273 mpb
->orig_family_num
= mpb
->family_num
;
9274 mpb
->family_num
+= super
->random
;
9276 /* count arrays using the victim in the metadata */
9278 for (a
= active_array
; a
; a
= a
->next
) {
9279 dev
= get_imsm_dev(super
, a
->info
.container_member
);
9280 map
= get_imsm_map(dev
, MAP_0
);
9282 if (get_imsm_disk_slot(map
, victim
) >= 0)
9286 /* delete the victim if it is no longer being
9292 /* We know that 'manager' isn't touching anything,
9293 * so it is safe to delete
9295 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
9296 if ((*dlp
)->index
== victim
)
9299 /* victim may be on the missing list */
9301 for (dlp
= &super
->missing
; *dlp
;
9302 dlp
= &(*dlp
)->next
)
9303 if ((*dlp
)->index
== victim
)
9305 imsm_delete(super
, dlp
, victim
);
9312 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
9313 struct intel_super
*super
,
9316 struct dl
*new_disk
;
9317 struct intel_dev
*id
;
9319 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
9320 int disk_count
= u
->old_raid_disks
;
9321 void **tofree
= NULL
;
9322 int devices_to_reshape
= 1;
9323 struct imsm_super
*mpb
= super
->anchor
;
9325 unsigned int dev_id
;
9327 dprintf("(enter)\n");
9329 /* enable spares to use in array */
9330 for (i
= 0; i
< delta_disks
; i
++) {
9331 new_disk
= get_disk_super(super
,
9332 major(u
->new_disks
[i
]),
9333 minor(u
->new_disks
[i
]));
9334 dprintf("imsm: new disk for reshape is: %i:%i (%p, index = %i)\n",
9335 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
9336 new_disk
, new_disk
->index
);
9337 if (new_disk
== NULL
||
9338 (new_disk
->index
>= 0 &&
9339 new_disk
->index
< u
->old_raid_disks
))
9340 goto update_reshape_exit
;
9341 new_disk
->index
= disk_count
++;
9342 /* slot to fill in autolayout
9344 new_disk
->raiddisk
= new_disk
->index
;
9345 new_disk
->disk
.status
|=
9347 new_disk
->disk
.status
&= ~SPARE_DISK
;
9350 dprintf("imsm: volume set mpb->num_raid_devs = %i\n",
9351 mpb
->num_raid_devs
);
9352 /* manage changes in volume
9354 for (dev_id
= 0; dev_id
< mpb
->num_raid_devs
; dev_id
++) {
9355 void **sp
= *space_list
;
9356 struct imsm_dev
*newdev
;
9357 struct imsm_map
*newmap
, *oldmap
;
9359 for (id
= super
->devlist
; id
; id
= id
->next
) {
9360 if (id
->index
== dev_id
)
9369 /* Copy the dev, but not (all of) the map */
9370 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
9371 oldmap
= get_imsm_map(id
->dev
, MAP_0
);
9372 newmap
= get_imsm_map(newdev
, MAP_0
);
9373 /* Copy the current map */
9374 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
9375 /* update one device only
9377 if (devices_to_reshape
) {
9378 dprintf("imsm: modifying subdev: %i\n",
9380 devices_to_reshape
--;
9381 newdev
->vol
.migr_state
= 1;
9382 newdev
->vol
.curr_migr_unit
= 0;
9383 set_migr_type(newdev
, MIGR_GEN_MIGR
);
9384 newmap
->num_members
= u
->new_raid_disks
;
9385 for (i
= 0; i
< delta_disks
; i
++) {
9386 set_imsm_ord_tbl_ent(newmap
,
9387 u
->old_raid_disks
+ i
,
9388 u
->old_raid_disks
+ i
);
9390 /* New map is correct, now need to save old map
9392 newmap
= get_imsm_map(newdev
, MAP_1
);
9393 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
9395 imsm_set_array_size(newdev
, -1);
9398 sp
= (void **)id
->dev
;
9403 /* Clear migration record */
9404 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
9407 *space_list
= tofree
;
9410 update_reshape_exit
:
9415 static int apply_takeover_update(struct imsm_update_takeover
*u
,
9416 struct intel_super
*super
,
9419 struct imsm_dev
*dev
= NULL
;
9420 struct intel_dev
*dv
;
9421 struct imsm_dev
*dev_new
;
9422 struct imsm_map
*map
;
9426 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
9427 if (dv
->index
== (unsigned int)u
->subarray
) {
9435 map
= get_imsm_map(dev
, MAP_0
);
9437 if (u
->direction
== R10_TO_R0
) {
9438 unsigned long long num_data_stripes
;
9440 map
->num_domains
= 1;
9441 num_data_stripes
= blocks_per_member(map
);
9442 num_data_stripes
/= map
->blocks_per_strip
;
9443 num_data_stripes
/= map
->num_domains
;
9444 set_num_data_stripes(map
, num_data_stripes
);
9446 /* Number of failed disks must be half of initial disk number */
9447 if (imsm_count_failed(super
, dev
, MAP_0
) !=
9448 (map
->num_members
/ 2))
9451 /* iterate through devices to mark removed disks as spare */
9452 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
9453 if (dm
->disk
.status
& FAILED_DISK
) {
9454 int idx
= dm
->index
;
9455 /* update indexes on the disk list */
9456 /* FIXME this loop-with-the-loop looks wrong, I'm not convinced
9457 the index values will end up being correct.... NB */
9458 for (du
= super
->disks
; du
; du
= du
->next
)
9459 if (du
->index
> idx
)
9461 /* mark as spare disk */
9466 map
->num_members
= map
->num_members
/ 2;
9467 map
->map_state
= IMSM_T_STATE_NORMAL
;
9468 map
->num_domains
= 1;
9469 map
->raid_level
= 0;
9470 map
->failed_disk_num
= -1;
9473 if (u
->direction
== R0_TO_R10
) {
9475 /* update slots in current disk list */
9476 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
9480 /* create new *missing* disks */
9481 for (i
= 0; i
< map
->num_members
; i
++) {
9482 space
= *space_list
;
9485 *space_list
= *space
;
9487 memcpy(du
, super
->disks
, sizeof(*du
));
9491 du
->index
= (i
* 2) + 1;
9492 sprintf((char *)du
->disk
.serial
,
9493 " MISSING_%d", du
->index
);
9494 sprintf((char *)du
->serial
,
9495 "MISSING_%d", du
->index
);
9496 du
->next
= super
->missing
;
9497 super
->missing
= du
;
9499 /* create new dev and map */
9500 space
= *space_list
;
9503 *space_list
= *space
;
9504 dev_new
= (void *)space
;
9505 memcpy(dev_new
, dev
, sizeof(*dev
));
9506 /* update new map */
9507 map
= get_imsm_map(dev_new
, MAP_0
);
9508 map
->num_members
= map
->num_members
* 2;
9509 map
->map_state
= IMSM_T_STATE_DEGRADED
;
9510 map
->num_domains
= 2;
9511 map
->raid_level
= 1;
9512 /* replace dev<->dev_new */
9515 /* update disk order table */
9516 for (du
= super
->disks
; du
; du
= du
->next
)
9518 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
9519 for (du
= super
->missing
; du
; du
= du
->next
)
9520 if (du
->index
>= 0) {
9521 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
9522 mark_missing(super
, dv
->dev
, &du
->disk
, du
->index
);
9528 static void imsm_process_update(struct supertype
*st
,
9529 struct metadata_update
*update
)
9532 * crack open the metadata_update envelope to find the update record
9533 * update can be one of:
9534 * update_reshape_container_disks - all the arrays in the container
9535 * are being reshaped to have more devices. We need to mark
9536 * the arrays for general migration and convert selected spares
9537 * into active devices.
9538 * update_activate_spare - a spare device has replaced a failed
9539 * device in an array, update the disk_ord_tbl. If this disk is
9540 * present in all member arrays then also clear the SPARE_DISK
9542 * update_create_array
9544 * update_rename_array
9545 * update_add_remove_disk
9547 struct intel_super
*super
= st
->sb
;
9548 struct imsm_super
*mpb
;
9549 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
9551 /* update requires a larger buf but the allocation failed */
9552 if (super
->next_len
&& !super
->next_buf
) {
9553 super
->next_len
= 0;
9557 if (super
->next_buf
) {
9558 memcpy(super
->next_buf
, super
->buf
, super
->len
);
9560 super
->len
= super
->next_len
;
9561 super
->buf
= super
->next_buf
;
9563 super
->next_len
= 0;
9564 super
->next_buf
= NULL
;
9567 mpb
= super
->anchor
;
9570 case update_general_migration_checkpoint
: {
9571 struct intel_dev
*id
;
9572 struct imsm_update_general_migration_checkpoint
*u
=
9573 (void *)update
->buf
;
9575 dprintf("called for update_general_migration_checkpoint\n");
9577 /* find device under general migration */
9578 for (id
= super
->devlist
; id
; id
= id
->next
) {
9579 if (is_gen_migration(id
->dev
)) {
9580 id
->dev
->vol
.curr_migr_unit
=
9581 __cpu_to_le32(u
->curr_migr_unit
);
9582 super
->updates_pending
++;
9587 case update_takeover
: {
9588 struct imsm_update_takeover
*u
= (void *)update
->buf
;
9589 if (apply_takeover_update(u
, super
, &update
->space_list
)) {
9590 imsm_update_version_info(super
);
9591 super
->updates_pending
++;
9596 case update_reshape_container_disks
: {
9597 struct imsm_update_reshape
*u
= (void *)update
->buf
;
9598 if (apply_reshape_container_disks_update(
9599 u
, super
, &update
->space_list
))
9600 super
->updates_pending
++;
9603 case update_reshape_migration
: {
9604 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
9605 if (apply_reshape_migration_update(
9606 u
, super
, &update
->space_list
))
9607 super
->updates_pending
++;
9610 case update_size_change
: {
9611 struct imsm_update_size_change
*u
= (void *)update
->buf
;
9612 if (apply_size_change_update(u
, super
))
9613 super
->updates_pending
++;
9616 case update_activate_spare
: {
9617 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
9618 if (apply_update_activate_spare(u
, super
, st
->arrays
))
9619 super
->updates_pending
++;
9622 case update_create_array
: {
9623 /* someone wants to create a new array, we need to be aware of
9624 * a few races/collisions:
9625 * 1/ 'Create' called by two separate instances of mdadm
9626 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
9627 * devices that have since been assimilated via
9629 * In the event this update can not be carried out mdadm will
9630 * (FIX ME) notice that its update did not take hold.
9632 struct imsm_update_create_array
*u
= (void *) update
->buf
;
9633 struct intel_dev
*dv
;
9634 struct imsm_dev
*dev
;
9635 struct imsm_map
*map
, *new_map
;
9636 unsigned long long start
, end
;
9637 unsigned long long new_start
, new_end
;
9639 struct disk_info
*inf
;
9642 /* handle racing creates: first come first serve */
9643 if (u
->dev_idx
< mpb
->num_raid_devs
) {
9644 dprintf("subarray %d already defined\n", u
->dev_idx
);
9648 /* check update is next in sequence */
9649 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
9650 dprintf("can not create array %d expected index %d\n",
9651 u
->dev_idx
, mpb
->num_raid_devs
);
9655 new_map
= get_imsm_map(&u
->dev
, MAP_0
);
9656 new_start
= pba_of_lba0(new_map
);
9657 new_end
= new_start
+ blocks_per_member(new_map
);
9658 inf
= get_disk_info(u
);
9660 /* handle activate_spare versus create race:
9661 * check to make sure that overlapping arrays do not include
9664 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
9665 dev
= get_imsm_dev(super
, i
);
9666 map
= get_imsm_map(dev
, MAP_0
);
9667 start
= pba_of_lba0(map
);
9668 end
= start
+ blocks_per_member(map
);
9669 if ((new_start
>= start
&& new_start
<= end
) ||
9670 (start
>= new_start
&& start
<= new_end
))
9675 if (disks_overlap(super
, i
, u
)) {
9676 dprintf("arrays overlap\n");
9681 /* check that prepare update was successful */
9682 if (!update
->space
) {
9683 dprintf("prepare update failed\n");
9687 /* check that all disks are still active before committing
9688 * changes. FIXME: could we instead handle this by creating a
9689 * degraded array? That's probably not what the user expects,
9690 * so better to drop this update on the floor.
9692 for (i
= 0; i
< new_map
->num_members
; i
++) {
9693 dl
= serial_to_dl(inf
[i
].serial
, super
);
9695 dprintf("disk disappeared\n");
9700 super
->updates_pending
++;
9702 /* convert spares to members and fixup ord_tbl */
9703 for (i
= 0; i
< new_map
->num_members
; i
++) {
9704 dl
= serial_to_dl(inf
[i
].serial
, super
);
9705 if (dl
->index
== -1) {
9706 dl
->index
= mpb
->num_disks
;
9708 dl
->disk
.status
|= CONFIGURED_DISK
;
9709 dl
->disk
.status
&= ~SPARE_DISK
;
9711 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
9716 update
->space
= NULL
;
9717 imsm_copy_dev(dev
, &u
->dev
);
9718 dv
->index
= u
->dev_idx
;
9719 dv
->next
= super
->devlist
;
9720 super
->devlist
= dv
;
9721 mpb
->num_raid_devs
++;
9723 imsm_update_version_info(super
);
9726 /* mdmon knows how to release update->space, but not
9727 * ((struct intel_dev *) update->space)->dev
9729 if (update
->space
) {
9735 case update_kill_array
: {
9736 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
9737 int victim
= u
->dev_idx
;
9738 struct active_array
*a
;
9739 struct intel_dev
**dp
;
9740 struct imsm_dev
*dev
;
9742 /* sanity check that we are not affecting the uuid of
9743 * active arrays, or deleting an active array
9745 * FIXME when immutable ids are available, but note that
9746 * we'll also need to fixup the invalidated/active
9747 * subarray indexes in mdstat
9749 for (a
= st
->arrays
; a
; a
= a
->next
)
9750 if (a
->info
.container_member
>= victim
)
9752 /* by definition if mdmon is running at least one array
9753 * is active in the container, so checking
9754 * mpb->num_raid_devs is just extra paranoia
9756 dev
= get_imsm_dev(super
, victim
);
9757 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
9758 dprintf("failed to delete subarray-%d\n", victim
);
9762 for (dp
= &super
->devlist
; *dp
;)
9763 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
9766 if ((*dp
)->index
> (unsigned)victim
)
9770 mpb
->num_raid_devs
--;
9771 super
->updates_pending
++;
9774 case update_rename_array
: {
9775 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
9776 char name
[MAX_RAID_SERIAL_LEN
+1];
9777 int target
= u
->dev_idx
;
9778 struct active_array
*a
;
9779 struct imsm_dev
*dev
;
9781 /* sanity check that we are not affecting the uuid of
9784 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
9785 name
[MAX_RAID_SERIAL_LEN
] = '\0';
9786 for (a
= st
->arrays
; a
; a
= a
->next
)
9787 if (a
->info
.container_member
== target
)
9789 dev
= get_imsm_dev(super
, u
->dev_idx
);
9790 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
9791 dprintf("failed to rename subarray-%d\n", target
);
9795 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
9796 super
->updates_pending
++;
9799 case update_add_remove_disk
: {
9800 /* we may be able to repair some arrays if disks are
9801 * being added, check the status of add_remove_disk
9802 * if discs has been added.
9804 if (add_remove_disk_update(super
)) {
9805 struct active_array
*a
;
9807 super
->updates_pending
++;
9808 for (a
= st
->arrays
; a
; a
= a
->next
)
9809 a
->check_degraded
= 1;
9813 case update_prealloc_badblocks_mem
:
9815 case update_rwh_policy
: {
9816 struct imsm_update_rwh_policy
*u
= (void *)update
->buf
;
9817 int target
= u
->dev_idx
;
9818 struct imsm_dev
*dev
= get_imsm_dev(super
, target
);
9820 dprintf("could not find subarray-%d\n", target
);
9824 if (dev
->rwh_policy
!= u
->new_policy
) {
9825 dev
->rwh_policy
= u
->new_policy
;
9826 super
->updates_pending
++;
9831 pr_err("error: unsuported process update type:(type: %d)\n", type
);
9835 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
);
9837 static int imsm_prepare_update(struct supertype
*st
,
9838 struct metadata_update
*update
)
9841 * Allocate space to hold new disk entries, raid-device entries or a new
9842 * mpb if necessary. The manager synchronously waits for updates to
9843 * complete in the monitor, so new mpb buffers allocated here can be
9844 * integrated by the monitor thread without worrying about live pointers
9845 * in the manager thread.
9847 enum imsm_update_type type
;
9848 struct intel_super
*super
= st
->sb
;
9849 unsigned int sector_size
= super
->sector_size
;
9850 struct imsm_super
*mpb
= super
->anchor
;
9854 if (update
->len
< (int)sizeof(type
))
9857 type
= *(enum imsm_update_type
*) update
->buf
;
9860 case update_general_migration_checkpoint
:
9861 if (update
->len
< (int)sizeof(struct imsm_update_general_migration_checkpoint
))
9863 dprintf("called for update_general_migration_checkpoint\n");
9865 case update_takeover
: {
9866 struct imsm_update_takeover
*u
= (void *)update
->buf
;
9867 if (update
->len
< (int)sizeof(*u
))
9869 if (u
->direction
== R0_TO_R10
) {
9870 void **tail
= (void **)&update
->space_list
;
9871 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subarray
);
9872 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9873 int num_members
= map
->num_members
;
9876 /* allocate memory for added disks */
9877 for (i
= 0; i
< num_members
; i
++) {
9878 size
= sizeof(struct dl
);
9879 space
= xmalloc(size
);
9884 /* allocate memory for new device */
9885 size
= sizeof_imsm_dev(super
->devlist
->dev
, 0) +
9886 (num_members
* sizeof(__u32
));
9887 space
= xmalloc(size
);
9891 len
= disks_to_mpb_size(num_members
* 2);
9896 case update_reshape_container_disks
: {
9897 /* Every raid device in the container is about to
9898 * gain some more devices, and we will enter a
9900 * So each 'imsm_map' will be bigger, and the imsm_vol
9901 * will now hold 2 of them.
9902 * Thus we need new 'struct imsm_dev' allocations sized
9903 * as sizeof_imsm_dev but with more devices in both maps.
9905 struct imsm_update_reshape
*u
= (void *)update
->buf
;
9906 struct intel_dev
*dl
;
9907 void **space_tail
= (void**)&update
->space_list
;
9909 if (update
->len
< (int)sizeof(*u
))
9912 dprintf("for update_reshape\n");
9914 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
9915 int size
= sizeof_imsm_dev(dl
->dev
, 1);
9917 if (u
->new_raid_disks
> u
->old_raid_disks
)
9918 size
+= sizeof(__u32
)*2*
9919 (u
->new_raid_disks
- u
->old_raid_disks
);
9926 len
= disks_to_mpb_size(u
->new_raid_disks
);
9927 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
9930 case update_reshape_migration
: {
9931 /* for migration level 0->5 we need to add disks
9932 * so the same as for container operation we will copy
9933 * device to the bigger location.
9934 * in memory prepared device and new disk area are prepared
9935 * for usage in process update
9937 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
9938 struct intel_dev
*id
;
9939 void **space_tail
= (void **)&update
->space_list
;
9942 int current_level
= -1;
9944 if (update
->len
< (int)sizeof(*u
))
9947 dprintf("for update_reshape\n");
9949 /* add space for bigger array in update
9951 for (id
= super
->devlist
; id
; id
= id
->next
) {
9952 if (id
->index
== (unsigned)u
->subdev
) {
9953 size
= sizeof_imsm_dev(id
->dev
, 1);
9954 if (u
->new_raid_disks
> u
->old_raid_disks
)
9955 size
+= sizeof(__u32
)*2*
9956 (u
->new_raid_disks
- u
->old_raid_disks
);
9964 if (update
->space_list
== NULL
)
9967 /* add space for disk in update
9969 size
= sizeof(struct dl
);
9975 /* add spare device to update
9977 for (id
= super
->devlist
; id
; id
= id
->next
)
9978 if (id
->index
== (unsigned)u
->subdev
) {
9979 struct imsm_dev
*dev
;
9980 struct imsm_map
*map
;
9982 dev
= get_imsm_dev(super
, u
->subdev
);
9983 map
= get_imsm_map(dev
, MAP_0
);
9984 current_level
= map
->raid_level
;
9987 if (u
->new_level
== 5 && u
->new_level
!= current_level
) {
9988 struct mdinfo
*spares
;
9990 spares
= get_spares_for_grow(st
);
9998 makedev(dev
->disk
.major
,
10000 dl
= get_disk_super(super
,
10003 dl
->index
= u
->old_raid_disks
;
10006 sysfs_free(spares
);
10009 len
= disks_to_mpb_size(u
->new_raid_disks
);
10010 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
10013 case update_size_change
: {
10014 if (update
->len
< (int)sizeof(struct imsm_update_size_change
))
10018 case update_activate_spare
: {
10019 if (update
->len
< (int)sizeof(struct imsm_update_activate_spare
))
10023 case update_create_array
: {
10024 struct imsm_update_create_array
*u
= (void *) update
->buf
;
10025 struct intel_dev
*dv
;
10026 struct imsm_dev
*dev
= &u
->dev
;
10027 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
10029 struct disk_info
*inf
;
10033 if (update
->len
< (int)sizeof(*u
))
10036 inf
= get_disk_info(u
);
10037 len
= sizeof_imsm_dev(dev
, 1);
10038 /* allocate a new super->devlist entry */
10039 dv
= xmalloc(sizeof(*dv
));
10040 dv
->dev
= xmalloc(len
);
10041 update
->space
= dv
;
10043 /* count how many spares will be converted to members */
10044 for (i
= 0; i
< map
->num_members
; i
++) {
10045 dl
= serial_to_dl(inf
[i
].serial
, super
);
10047 /* hmm maybe it failed?, nothing we can do about
10052 if (count_memberships(dl
, super
) == 0)
10055 len
+= activate
* sizeof(struct imsm_disk
);
10058 case update_kill_array
: {
10059 if (update
->len
< (int)sizeof(struct imsm_update_kill_array
))
10063 case update_rename_array
: {
10064 if (update
->len
< (int)sizeof(struct imsm_update_rename_array
))
10068 case update_add_remove_disk
:
10069 /* no update->len needed */
10071 case update_prealloc_badblocks_mem
:
10072 super
->extra_space
+= sizeof(struct bbm_log
) -
10073 get_imsm_bbm_log_size(super
->bbm_log
);
10075 case update_rwh_policy
: {
10076 if (update
->len
< (int)sizeof(struct imsm_update_rwh_policy
))
10084 /* check if we need a larger metadata buffer */
10085 if (super
->next_buf
)
10086 buf_len
= super
->next_len
;
10088 buf_len
= super
->len
;
10090 if (__le32_to_cpu(mpb
->mpb_size
) + super
->extra_space
+ len
> buf_len
) {
10091 /* ok we need a larger buf than what is currently allocated
10092 * if this allocation fails process_update will notice that
10093 * ->next_len is set and ->next_buf is NULL
10095 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) +
10096 super
->extra_space
+ len
, sector_size
);
10097 if (super
->next_buf
)
10098 free(super
->next_buf
);
10100 super
->next_len
= buf_len
;
10101 if (posix_memalign(&super
->next_buf
, sector_size
, buf_len
) == 0)
10102 memset(super
->next_buf
, 0, buf_len
);
10104 super
->next_buf
= NULL
;
10109 /* must be called while manager is quiesced */
10110 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
10112 struct imsm_super
*mpb
= super
->anchor
;
10114 struct imsm_dev
*dev
;
10115 struct imsm_map
*map
;
10116 unsigned int i
, j
, num_members
;
10117 __u32 ord
, ord_map0
;
10118 struct bbm_log
*log
= super
->bbm_log
;
10120 dprintf("deleting device[%d] from imsm_super\n", index
);
10122 /* shift all indexes down one */
10123 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
10124 if (iter
->index
> (int)index
)
10126 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
10127 if (iter
->index
> (int)index
)
10130 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
10131 dev
= get_imsm_dev(super
, i
);
10132 map
= get_imsm_map(dev
, MAP_0
);
10133 num_members
= map
->num_members
;
10134 for (j
= 0; j
< num_members
; j
++) {
10135 /* update ord entries being careful not to propagate
10136 * ord-flags to the first map
10138 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_X
);
10139 ord_map0
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
10141 if (ord_to_idx(ord
) <= index
)
10144 map
= get_imsm_map(dev
, MAP_0
);
10145 set_imsm_ord_tbl_ent(map
, j
, ord_map0
- 1);
10146 map
= get_imsm_map(dev
, MAP_1
);
10148 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
10152 for (i
= 0; i
< log
->entry_count
; i
++) {
10153 struct bbm_log_entry
*entry
= &log
->marked_block_entries
[i
];
10155 if (entry
->disk_ordinal
<= index
)
10157 entry
->disk_ordinal
--;
10161 super
->updates_pending
++;
10163 struct dl
*dl
= *dlp
;
10165 *dlp
= (*dlp
)->next
;
10166 __free_imsm_disk(dl
);
10170 static void close_targets(int *targets
, int new_disks
)
10177 for (i
= 0; i
< new_disks
; i
++) {
10178 if (targets
[i
] >= 0) {
10185 static int imsm_get_allowed_degradation(int level
, int raid_disks
,
10186 struct intel_super
*super
,
10187 struct imsm_dev
*dev
)
10193 struct imsm_map
*map
;
10196 ret_val
= raid_disks
/2;
10197 /* check map if all disks pairs not failed
10200 map
= get_imsm_map(dev
, MAP_0
);
10201 for (i
= 0; i
< ret_val
; i
++) {
10202 int degradation
= 0;
10203 if (get_imsm_disk(super
, i
) == NULL
)
10205 if (get_imsm_disk(super
, i
+ 1) == NULL
)
10207 if (degradation
== 2)
10210 map
= get_imsm_map(dev
, MAP_1
);
10211 /* if there is no second map
10212 * result can be returned
10216 /* check degradation in second map
10218 for (i
= 0; i
< ret_val
; i
++) {
10219 int degradation
= 0;
10220 if (get_imsm_disk(super
, i
) == NULL
)
10222 if (get_imsm_disk(super
, i
+ 1) == NULL
)
10224 if (degradation
== 2)
10238 /*******************************************************************************
10239 * Function: open_backup_targets
10240 * Description: Function opens file descriptors for all devices given in
10243 * info : general array info
10244 * raid_disks : number of disks
10245 * raid_fds : table of device's file descriptors
10246 * super : intel super for raid10 degradation check
10247 * dev : intel device for raid10 degradation check
10251 ******************************************************************************/
10252 int open_backup_targets(struct mdinfo
*info
, int raid_disks
, int *raid_fds
,
10253 struct intel_super
*super
, struct imsm_dev
*dev
)
10259 for (i
= 0; i
< raid_disks
; i
++)
10262 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
10265 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
)) {
10266 dprintf("disk is faulty!!\n");
10270 if (sd
->disk
.raid_disk
>= raid_disks
|| sd
->disk
.raid_disk
< 0)
10273 dn
= map_dev(sd
->disk
.major
,
10274 sd
->disk
.minor
, 1);
10275 raid_fds
[sd
->disk
.raid_disk
] = dev_open(dn
, O_RDWR
);
10276 if (raid_fds
[sd
->disk
.raid_disk
] < 0) {
10277 pr_err("cannot open component\n");
10282 /* check if maximum array degradation level is not exceeded
10284 if ((raid_disks
- opened
) >
10285 imsm_get_allowed_degradation(info
->new_level
, raid_disks
,
10287 pr_err("Not enough disks can be opened.\n");
10288 close_targets(raid_fds
, raid_disks
);
10294 /*******************************************************************************
10295 * Function: validate_container_imsm
10296 * Description: This routine validates container after assemble,
10297 * eg. if devices in container are under the same controller.
10300 * info : linked list with info about devices used in array
10304 ******************************************************************************/
10305 int validate_container_imsm(struct mdinfo
*info
)
10307 if (check_env("IMSM_NO_PLATFORM"))
10310 struct sys_dev
*idev
;
10311 struct sys_dev
*hba
= NULL
;
10312 struct sys_dev
*intel_devices
= find_intel_devices();
10313 char *dev_path
= devt_to_devpath(makedev(info
->disk
.major
,
10314 info
->disk
.minor
));
10316 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
10317 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
10326 pr_err("WARNING - Cannot detect HBA for device %s!\n",
10327 devid2kname(makedev(info
->disk
.major
, info
->disk
.minor
)));
10331 const struct imsm_orom
*orom
= get_orom_by_device_id(hba
->dev_id
);
10332 struct mdinfo
*dev
;
10334 for (dev
= info
->next
; dev
; dev
= dev
->next
) {
10335 dev_path
= devt_to_devpath(makedev(dev
->disk
.major
, dev
->disk
.minor
));
10337 struct sys_dev
*hba2
= NULL
;
10338 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
10339 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
10347 const struct imsm_orom
*orom2
= hba2
== NULL
? NULL
:
10348 get_orom_by_device_id(hba2
->dev_id
);
10350 if (hba2
&& hba
->type
!= hba2
->type
) {
10351 pr_err("WARNING - HBAs of devices do not match %s != %s\n",
10352 get_sys_dev_type(hba
->type
), get_sys_dev_type(hba2
->type
));
10356 if (orom
!= orom2
) {
10357 pr_err("WARNING - IMSM container assembled with disks under different HBAs!\n"
10358 " This operation is not supported and can lead to data loss.\n");
10363 pr_err("WARNING - IMSM container assembled with disks under HBAs without IMSM platform support!\n"
10364 " This operation is not supported and can lead to data loss.\n");
10372 /*******************************************************************************
10373 * Function: imsm_record_badblock
10374 * Description: This routine stores new bad block record in BBM log
10377 * a : array containing a bad block
10378 * slot : disk number containing a bad block
10379 * sector : bad block sector
10380 * length : bad block sectors range
10384 ******************************************************************************/
10385 static int imsm_record_badblock(struct active_array
*a
, int slot
,
10386 unsigned long long sector
, int length
)
10388 struct intel_super
*super
= a
->container
->sb
;
10392 ord
= imsm_disk_slot_to_ord(a
, slot
);
10396 ret
= record_new_badblock(super
->bbm_log
, ord_to_idx(ord
), sector
,
10399 super
->updates_pending
++;
10403 /*******************************************************************************
10404 * Function: imsm_clear_badblock
10405 * Description: This routine clears bad block record from BBM log
10408 * a : array containing a bad block
10409 * slot : disk number containing a bad block
10410 * sector : bad block sector
10411 * length : bad block sectors range
10415 ******************************************************************************/
10416 static int imsm_clear_badblock(struct active_array
*a
, int slot
,
10417 unsigned long long sector
, int length
)
10419 struct intel_super
*super
= a
->container
->sb
;
10423 ord
= imsm_disk_slot_to_ord(a
, slot
);
10427 ret
= clear_badblock(super
->bbm_log
, ord_to_idx(ord
), sector
, length
);
10429 super
->updates_pending
++;
10433 /*******************************************************************************
10434 * Function: imsm_get_badblocks
10435 * Description: This routine get list of bad blocks for an array
10439 * slot : disk number
10441 * bb : structure containing bad blocks
10443 ******************************************************************************/
10444 static struct md_bb
*imsm_get_badblocks(struct active_array
*a
, int slot
)
10446 int inst
= a
->info
.container_member
;
10447 struct intel_super
*super
= a
->container
->sb
;
10448 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
10449 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
10452 ord
= imsm_disk_slot_to_ord(a
, slot
);
10456 get_volume_badblocks(super
->bbm_log
, ord_to_idx(ord
), pba_of_lba0(map
),
10457 blocks_per_member(map
), &super
->bb
);
10461 /*******************************************************************************
10462 * Function: examine_badblocks_imsm
10463 * Description: Prints list of bad blocks on a disk to the standard output
10466 * st : metadata handler
10467 * fd : open file descriptor for device
10468 * devname : device name
10472 ******************************************************************************/
10473 static int examine_badblocks_imsm(struct supertype
*st
, int fd
, char *devname
)
10475 struct intel_super
*super
= st
->sb
;
10476 struct bbm_log
*log
= super
->bbm_log
;
10477 struct dl
*d
= NULL
;
10480 for (d
= super
->disks
; d
; d
= d
->next
) {
10481 if (strcmp(d
->devname
, devname
) == 0)
10485 if ((d
== NULL
) || (d
->index
< 0)) { /* serial mismatch probably */
10486 pr_err("%s doesn't appear to be part of a raid array\n",
10493 struct bbm_log_entry
*entry
= &log
->marked_block_entries
[0];
10495 for (i
= 0; i
< log
->entry_count
; i
++) {
10496 if (entry
[i
].disk_ordinal
== d
->index
) {
10497 unsigned long long sector
= __le48_to_cpu(
10498 &entry
[i
].defective_block_start
);
10499 int cnt
= entry
[i
].marked_count
+ 1;
10502 printf("Bad-blocks on %s:\n", devname
);
10506 printf("%20llu for %d sectors\n", sector
, cnt
);
10512 printf("No bad-blocks list configured on %s\n", devname
);
10516 /*******************************************************************************
10517 * Function: init_migr_record_imsm
10518 * Description: Function inits imsm migration record
10520 * super : imsm internal array info
10521 * dev : device under migration
10522 * info : general array info to find the smallest device
10525 ******************************************************************************/
10526 void init_migr_record_imsm(struct supertype
*st
, struct imsm_dev
*dev
,
10527 struct mdinfo
*info
)
10529 struct intel_super
*super
= st
->sb
;
10530 struct migr_record
*migr_rec
= super
->migr_rec
;
10531 int new_data_disks
;
10532 unsigned long long dsize
, dev_sectors
;
10533 long long unsigned min_dev_sectors
= -1LLU;
10537 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
10538 struct imsm_map
*map_src
= get_imsm_map(dev
, MAP_1
);
10539 unsigned long long num_migr_units
;
10540 unsigned long long array_blocks
;
10542 memset(migr_rec
, 0, sizeof(struct migr_record
));
10543 migr_rec
->family_num
= __cpu_to_le32(super
->anchor
->family_num
);
10545 /* only ascending reshape supported now */
10546 migr_rec
->ascending_migr
= __cpu_to_le32(1);
10548 migr_rec
->dest_depth_per_unit
= GEN_MIGR_AREA_SIZE
/
10549 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
10550 migr_rec
->dest_depth_per_unit
*=
10551 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
10552 new_data_disks
= imsm_num_data_members(dev
, MAP_0
);
10553 migr_rec
->blocks_per_unit
=
10554 __cpu_to_le32(migr_rec
->dest_depth_per_unit
* new_data_disks
);
10555 migr_rec
->dest_depth_per_unit
=
10556 __cpu_to_le32(migr_rec
->dest_depth_per_unit
);
10557 array_blocks
= info
->component_size
* new_data_disks
;
10559 array_blocks
/ __le32_to_cpu(migr_rec
->blocks_per_unit
);
10561 if (array_blocks
% __le32_to_cpu(migr_rec
->blocks_per_unit
))
10563 migr_rec
->num_migr_units
= __cpu_to_le32(num_migr_units
);
10565 migr_rec
->post_migr_vol_cap
= dev
->size_low
;
10566 migr_rec
->post_migr_vol_cap_hi
= dev
->size_high
;
10568 /* Find the smallest dev */
10569 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
10570 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
10571 fd
= dev_open(nm
, O_RDONLY
);
10574 get_dev_size(fd
, NULL
, &dsize
);
10575 dev_sectors
= dsize
/ 512;
10576 if (dev_sectors
< min_dev_sectors
)
10577 min_dev_sectors
= dev_sectors
;
10580 migr_rec
->ckpt_area_pba
= __cpu_to_le32(min_dev_sectors
-
10581 RAID_DISK_RESERVED_BLOCKS_IMSM_HI
);
10583 write_imsm_migr_rec(st
);
10588 /*******************************************************************************
10589 * Function: save_backup_imsm
10590 * Description: Function saves critical data stripes to Migration Copy Area
10591 * and updates the current migration unit status.
10592 * Use restore_stripes() to form a destination stripe,
10593 * and to write it to the Copy Area.
10595 * st : supertype information
10596 * dev : imsm device that backup is saved for
10597 * info : general array info
10598 * buf : input buffer
10599 * length : length of data to backup (blocks_per_unit)
10603 ******************************************************************************/
10604 int save_backup_imsm(struct supertype
*st
,
10605 struct imsm_dev
*dev
,
10606 struct mdinfo
*info
,
10611 struct intel_super
*super
= st
->sb
;
10612 unsigned long long *target_offsets
;
10615 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
10616 int new_disks
= map_dest
->num_members
;
10617 int dest_layout
= 0;
10619 unsigned long long start
;
10620 int data_disks
= imsm_num_data_members(dev
, MAP_0
);
10622 targets
= xmalloc(new_disks
* sizeof(int));
10624 for (i
= 0; i
< new_disks
; i
++)
10627 target_offsets
= xcalloc(new_disks
, sizeof(unsigned long long));
10629 start
= info
->reshape_progress
* 512;
10630 for (i
= 0; i
< new_disks
; i
++) {
10631 target_offsets
[i
] = (unsigned long long)
10632 __le32_to_cpu(super
->migr_rec
->ckpt_area_pba
) * 512;
10633 /* move back copy area adderss, it will be moved forward
10634 * in restore_stripes() using start input variable
10636 target_offsets
[i
] -= start
/data_disks
;
10639 if (open_backup_targets(info
, new_disks
, targets
,
10643 dest_layout
= imsm_level_to_layout(map_dest
->raid_level
);
10644 dest_chunk
= __le16_to_cpu(map_dest
->blocks_per_strip
) * 512;
10646 if (restore_stripes(targets
, /* list of dest devices */
10647 target_offsets
, /* migration record offsets */
10650 map_dest
->raid_level
,
10652 -1, /* source backup file descriptor */
10653 0, /* input buf offset
10654 * always 0 buf is already offseted */
10658 pr_err("Error restoring stripes\n");
10666 close_targets(targets
, new_disks
);
10669 free(target_offsets
);
10674 /*******************************************************************************
10675 * Function: save_checkpoint_imsm
10676 * Description: Function called for current unit status update
10677 * in the migration record. It writes it to disk.
10679 * super : imsm internal array info
10680 * info : general array info
10684 * 2: failure, means no valid migration record
10685 * / no general migration in progress /
10686 ******************************************************************************/
10687 int save_checkpoint_imsm(struct supertype
*st
, struct mdinfo
*info
, int state
)
10689 struct intel_super
*super
= st
->sb
;
10690 unsigned long long blocks_per_unit
;
10691 unsigned long long curr_migr_unit
;
10693 if (load_imsm_migr_rec(super
, info
) != 0) {
10694 dprintf("imsm: ERROR: Cannot read migration record for checkpoint save.\n");
10698 blocks_per_unit
= __le32_to_cpu(super
->migr_rec
->blocks_per_unit
);
10699 if (blocks_per_unit
== 0) {
10700 dprintf("imsm: no migration in progress.\n");
10703 curr_migr_unit
= info
->reshape_progress
/ blocks_per_unit
;
10704 /* check if array is alligned to copy area
10705 * if it is not alligned, add one to current migration unit value
10706 * this can happend on array reshape finish only
10708 if (info
->reshape_progress
% blocks_per_unit
)
10711 super
->migr_rec
->curr_migr_unit
=
10712 __cpu_to_le32(curr_migr_unit
);
10713 super
->migr_rec
->rec_status
= __cpu_to_le32(state
);
10714 super
->migr_rec
->dest_1st_member_lba
=
10715 __cpu_to_le32(curr_migr_unit
*
10716 __le32_to_cpu(super
->migr_rec
->dest_depth_per_unit
));
10717 if (write_imsm_migr_rec(st
) < 0) {
10718 dprintf("imsm: Cannot write migration record outside backup area\n");
10725 /*******************************************************************************
10726 * Function: recover_backup_imsm
10727 * Description: Function recovers critical data from the Migration Copy Area
10728 * while assembling an array.
10730 * super : imsm internal array info
10731 * info : general array info
10733 * 0 : success (or there is no data to recover)
10735 ******************************************************************************/
10736 int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
)
10738 struct intel_super
*super
= st
->sb
;
10739 struct migr_record
*migr_rec
= super
->migr_rec
;
10740 struct imsm_map
*map_dest
;
10741 struct intel_dev
*id
= NULL
;
10742 unsigned long long read_offset
;
10743 unsigned long long write_offset
;
10745 int *targets
= NULL
;
10746 int new_disks
, i
, err
;
10749 unsigned int sector_size
= super
->sector_size
;
10750 unsigned long curr_migr_unit
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
10751 unsigned long num_migr_units
= __le32_to_cpu(migr_rec
->num_migr_units
);
10753 int skipped_disks
= 0;
10755 err
= sysfs_get_str(info
, NULL
, "array_state", (char *)buffer
, 20);
10759 /* recover data only during assemblation */
10760 if (strncmp(buffer
, "inactive", 8) != 0)
10762 /* no data to recover */
10763 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
10765 if (curr_migr_unit
>= num_migr_units
)
10768 /* find device during reshape */
10769 for (id
= super
->devlist
; id
; id
= id
->next
)
10770 if (is_gen_migration(id
->dev
))
10775 map_dest
= get_imsm_map(id
->dev
, MAP_0
);
10776 new_disks
= map_dest
->num_members
;
10778 read_offset
= (unsigned long long)
10779 __le32_to_cpu(migr_rec
->ckpt_area_pba
) * 512;
10781 write_offset
= ((unsigned long long)
10782 __le32_to_cpu(migr_rec
->dest_1st_member_lba
) +
10783 pba_of_lba0(map_dest
)) * 512;
10785 unit_len
= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
10786 if (posix_memalign((void **)&buf
, sector_size
, unit_len
) != 0)
10788 targets
= xcalloc(new_disks
, sizeof(int));
10790 if (open_backup_targets(info
, new_disks
, targets
, super
, id
->dev
)) {
10791 pr_err("Cannot open some devices belonging to array.\n");
10795 for (i
= 0; i
< new_disks
; i
++) {
10796 if (targets
[i
] < 0) {
10800 if (lseek64(targets
[i
], read_offset
, SEEK_SET
) < 0) {
10801 pr_err("Cannot seek to block: %s\n",
10806 if ((unsigned)read(targets
[i
], buf
, unit_len
) != unit_len
) {
10807 pr_err("Cannot read copy area block: %s\n",
10812 if (lseek64(targets
[i
], write_offset
, SEEK_SET
) < 0) {
10813 pr_err("Cannot seek to block: %s\n",
10818 if ((unsigned)write(targets
[i
], buf
, unit_len
) != unit_len
) {
10819 pr_err("Cannot restore block: %s\n",
10826 if (skipped_disks
> imsm_get_allowed_degradation(info
->new_level
,
10830 pr_err("Cannot restore data from backup. Too many failed disks\n");
10834 if (save_checkpoint_imsm(st
, info
, UNIT_SRC_NORMAL
)) {
10835 /* ignore error == 2, this can mean end of reshape here
10837 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL) during restart\n");
10843 for (i
= 0; i
< new_disks
; i
++)
10852 static char disk_by_path
[] = "/dev/disk/by-path/";
10854 static const char *imsm_get_disk_controller_domain(const char *path
)
10856 char disk_path
[PATH_MAX
];
10860 strcpy(disk_path
, disk_by_path
);
10861 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
10862 if (stat(disk_path
, &st
) == 0) {
10863 struct sys_dev
* hba
;
10866 path
= devt_to_devpath(st
.st_rdev
);
10869 hba
= find_disk_attached_hba(-1, path
);
10870 if (hba
&& hba
->type
== SYS_DEV_SAS
)
10872 else if (hba
&& hba
->type
== SYS_DEV_SATA
)
10874 else if (hba
&& hba
->type
== SYS_DEV_VMD
)
10876 else if (hba
&& hba
->type
== SYS_DEV_NVME
)
10880 dprintf("path: %s hba: %s attached: %s\n",
10881 path
, (hba
) ? hba
->path
: "NULL", drv
);
10887 static char *imsm_find_array_devnm_by_subdev(int subdev
, char *container
)
10889 static char devnm
[32];
10890 char subdev_name
[20];
10891 struct mdstat_ent
*mdstat
;
10893 sprintf(subdev_name
, "%d", subdev
);
10894 mdstat
= mdstat_by_subdev(subdev_name
, container
);
10898 strcpy(devnm
, mdstat
->devnm
);
10899 free_mdstat(mdstat
);
10903 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
10904 struct geo_params
*geo
,
10905 int *old_raid_disks
,
10908 /* currently we only support increasing the number of devices
10909 * for a container. This increases the number of device for each
10910 * member array. They must all be RAID0 or RAID5.
10913 struct mdinfo
*info
, *member
;
10914 int devices_that_can_grow
= 0;
10916 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): st->devnm = (%s)\n", st
->devnm
);
10918 if (geo
->size
> 0 ||
10919 geo
->level
!= UnSet
||
10920 geo
->layout
!= UnSet
||
10921 geo
->chunksize
!= 0 ||
10922 geo
->raid_disks
== UnSet
) {
10923 dprintf("imsm: Container operation is allowed for raid disks number change only.\n");
10927 if (direction
== ROLLBACK_METADATA_CHANGES
) {
10928 dprintf("imsm: Metadata changes rollback is not supported for container operation.\n");
10932 info
= container_content_imsm(st
, NULL
);
10933 for (member
= info
; member
; member
= member
->next
) {
10936 dprintf("imsm: checking device_num: %i\n",
10937 member
->container_member
);
10939 if (geo
->raid_disks
<= member
->array
.raid_disks
) {
10940 /* we work on container for Online Capacity Expansion
10941 * only so raid_disks has to grow
10943 dprintf("imsm: for container operation raid disks increase is required\n");
10947 if (info
->array
.level
!= 0 && info
->array
.level
!= 5) {
10948 /* we cannot use this container with other raid level
10950 dprintf("imsm: for container operation wrong raid level (%i) detected\n",
10951 info
->array
.level
);
10954 /* check for platform support
10955 * for this raid level configuration
10957 struct intel_super
*super
= st
->sb
;
10958 if (!is_raid_level_supported(super
->orom
,
10959 member
->array
.level
,
10960 geo
->raid_disks
)) {
10961 dprintf("platform does not support raid%d with %d disk%s\n",
10964 geo
->raid_disks
> 1 ? "s" : "");
10967 /* check if component size is aligned to chunk size
10969 if (info
->component_size
%
10970 (info
->array
.chunk_size
/512)) {
10971 dprintf("Component size is not aligned to chunk size\n");
10976 if (*old_raid_disks
&&
10977 info
->array
.raid_disks
!= *old_raid_disks
)
10979 *old_raid_disks
= info
->array
.raid_disks
;
10981 /* All raid5 and raid0 volumes in container
10982 * have to be ready for Online Capacity Expansion
10983 * so they need to be assembled. We have already
10984 * checked that no recovery etc is happening.
10986 result
= imsm_find_array_devnm_by_subdev(member
->container_member
,
10987 st
->container_devnm
);
10988 if (result
== NULL
) {
10989 dprintf("imsm: cannot find array\n");
10992 devices_that_can_grow
++;
10995 if (!member
&& devices_that_can_grow
)
10999 dprintf("Container operation allowed\n");
11001 dprintf("Error: %i\n", ret_val
);
11006 /* Function: get_spares_for_grow
11007 * Description: Allocates memory and creates list of spare devices
11008 * avaliable in container. Checks if spare drive size is acceptable.
11009 * Parameters: Pointer to the supertype structure
11010 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
11013 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
11015 struct spare_criteria sc
;
11017 get_spare_criteria_imsm(st
, &sc
);
11018 return container_choose_spares(st
, &sc
, NULL
, NULL
, NULL
, 0);
11021 /******************************************************************************
11022 * function: imsm_create_metadata_update_for_reshape
11023 * Function creates update for whole IMSM container.
11025 ******************************************************************************/
11026 static int imsm_create_metadata_update_for_reshape(
11027 struct supertype
*st
,
11028 struct geo_params
*geo
,
11029 int old_raid_disks
,
11030 struct imsm_update_reshape
**updatep
)
11032 struct intel_super
*super
= st
->sb
;
11033 struct imsm_super
*mpb
= super
->anchor
;
11034 int update_memory_size
;
11035 struct imsm_update_reshape
*u
;
11036 struct mdinfo
*spares
;
11039 struct mdinfo
*dev
;
11041 dprintf("(enter) raid_disks = %i\n", geo
->raid_disks
);
11043 delta_disks
= geo
->raid_disks
- old_raid_disks
;
11045 /* size of all update data without anchor */
11046 update_memory_size
= sizeof(struct imsm_update_reshape
);
11048 /* now add space for spare disks that we need to add. */
11049 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
11051 u
= xcalloc(1, update_memory_size
);
11052 u
->type
= update_reshape_container_disks
;
11053 u
->old_raid_disks
= old_raid_disks
;
11054 u
->new_raid_disks
= geo
->raid_disks
;
11056 /* now get spare disks list
11058 spares
= get_spares_for_grow(st
);
11060 if (spares
== NULL
|| delta_disks
> spares
->array
.spare_disks
) {
11061 pr_err("imsm: ERROR: Cannot get spare devices for %s.\n", geo
->dev_name
);
11066 /* we have got spares
11067 * update disk list in imsm_disk list table in anchor
11069 dprintf("imsm: %i spares are available.\n\n",
11070 spares
->array
.spare_disks
);
11072 dev
= spares
->devs
;
11073 for (i
= 0; i
< delta_disks
; i
++) {
11078 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
11080 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
11081 dl
->index
= mpb
->num_disks
;
11089 sysfs_free(spares
);
11091 dprintf("imsm: reshape update preparation :");
11092 if (i
== delta_disks
) {
11093 dprintf_cont(" OK\n");
11095 return update_memory_size
;
11098 dprintf_cont(" Error\n");
11103 /******************************************************************************
11104 * function: imsm_create_metadata_update_for_size_change()
11105 * Creates update for IMSM array for array size change.
11107 ******************************************************************************/
11108 static int imsm_create_metadata_update_for_size_change(
11109 struct supertype
*st
,
11110 struct geo_params
*geo
,
11111 struct imsm_update_size_change
**updatep
)
11113 struct intel_super
*super
= st
->sb
;
11114 int update_memory_size
;
11115 struct imsm_update_size_change
*u
;
11117 dprintf("(enter) New size = %llu\n", geo
->size
);
11119 /* size of all update data without anchor */
11120 update_memory_size
= sizeof(struct imsm_update_size_change
);
11122 u
= xcalloc(1, update_memory_size
);
11123 u
->type
= update_size_change
;
11124 u
->subdev
= super
->current_vol
;
11125 u
->new_size
= geo
->size
;
11127 dprintf("imsm: reshape update preparation : OK\n");
11130 return update_memory_size
;
11133 /******************************************************************************
11134 * function: imsm_create_metadata_update_for_migration()
11135 * Creates update for IMSM array.
11137 ******************************************************************************/
11138 static int imsm_create_metadata_update_for_migration(
11139 struct supertype
*st
,
11140 struct geo_params
*geo
,
11141 struct imsm_update_reshape_migration
**updatep
)
11143 struct intel_super
*super
= st
->sb
;
11144 int update_memory_size
;
11145 struct imsm_update_reshape_migration
*u
;
11146 struct imsm_dev
*dev
;
11147 int previous_level
= -1;
11149 dprintf("(enter) New Level = %i\n", geo
->level
);
11151 /* size of all update data without anchor */
11152 update_memory_size
= sizeof(struct imsm_update_reshape_migration
);
11154 u
= xcalloc(1, update_memory_size
);
11155 u
->type
= update_reshape_migration
;
11156 u
->subdev
= super
->current_vol
;
11157 u
->new_level
= geo
->level
;
11158 u
->new_layout
= geo
->layout
;
11159 u
->new_raid_disks
= u
->old_raid_disks
= geo
->raid_disks
;
11160 u
->new_disks
[0] = -1;
11161 u
->new_chunksize
= -1;
11163 dev
= get_imsm_dev(super
, u
->subdev
);
11165 struct imsm_map
*map
;
11167 map
= get_imsm_map(dev
, MAP_0
);
11169 int current_chunk_size
=
11170 __le16_to_cpu(map
->blocks_per_strip
) / 2;
11172 if (geo
->chunksize
!= current_chunk_size
) {
11173 u
->new_chunksize
= geo
->chunksize
/ 1024;
11174 dprintf("imsm: chunk size change from %i to %i\n",
11175 current_chunk_size
, u
->new_chunksize
);
11177 previous_level
= map
->raid_level
;
11180 if (geo
->level
== 5 && previous_level
== 0) {
11181 struct mdinfo
*spares
= NULL
;
11183 u
->new_raid_disks
++;
11184 spares
= get_spares_for_grow(st
);
11185 if (spares
== NULL
|| spares
->array
.spare_disks
< 1) {
11187 sysfs_free(spares
);
11188 update_memory_size
= 0;
11189 pr_err("cannot get spare device for requested migration\n");
11192 sysfs_free(spares
);
11194 dprintf("imsm: reshape update preparation : OK\n");
11197 return update_memory_size
;
11200 static void imsm_update_metadata_locally(struct supertype
*st
,
11201 void *buf
, int len
)
11203 struct metadata_update mu
;
11208 mu
.space_list
= NULL
;
11210 if (imsm_prepare_update(st
, &mu
))
11211 imsm_process_update(st
, &mu
);
11213 while (mu
.space_list
) {
11214 void **space
= mu
.space_list
;
11215 mu
.space_list
= *space
;
11220 /***************************************************************************
11221 * Function: imsm_analyze_change
11222 * Description: Function analyze change for single volume
11223 * and validate if transition is supported
11224 * Parameters: Geometry parameters, supertype structure,
11225 * metadata change direction (apply/rollback)
11226 * Returns: Operation type code on success, -1 if fail
11227 ****************************************************************************/
11228 enum imsm_reshape_type
imsm_analyze_change(struct supertype
*st
,
11229 struct geo_params
*geo
,
11232 struct mdinfo info
;
11234 int check_devs
= 0;
11236 /* number of added/removed disks in operation result */
11237 int devNumChange
= 0;
11238 /* imsm compatible layout value for array geometry verification */
11239 int imsm_layout
= -1;
11241 struct imsm_dev
*dev
;
11242 struct intel_super
*super
;
11243 unsigned long long current_size
;
11244 unsigned long long free_size
;
11245 unsigned long long max_size
;
11248 getinfo_super_imsm_volume(st
, &info
, NULL
);
11249 if (geo
->level
!= info
.array
.level
&& geo
->level
>= 0 &&
11250 geo
->level
!= UnSet
) {
11251 switch (info
.array
.level
) {
11253 if (geo
->level
== 5) {
11254 change
= CH_MIGRATION
;
11255 if (geo
->layout
!= ALGORITHM_LEFT_ASYMMETRIC
) {
11256 pr_err("Error. Requested Layout not supported (left-asymmetric layout is supported only)!\n");
11258 goto analyse_change_exit
;
11260 imsm_layout
= geo
->layout
;
11262 devNumChange
= 1; /* parity disk added */
11263 } else if (geo
->level
== 10) {
11264 change
= CH_TAKEOVER
;
11266 devNumChange
= 2; /* two mirrors added */
11267 imsm_layout
= 0x102; /* imsm supported layout */
11272 if (geo
->level
== 0) {
11273 change
= CH_TAKEOVER
;
11275 devNumChange
= -(geo
->raid_disks
/2);
11276 imsm_layout
= 0; /* imsm raid0 layout */
11280 if (change
== -1) {
11281 pr_err("Error. Level Migration from %d to %d not supported!\n",
11282 info
.array
.level
, geo
->level
);
11283 goto analyse_change_exit
;
11286 geo
->level
= info
.array
.level
;
11288 if (geo
->layout
!= info
.array
.layout
&&
11289 (geo
->layout
!= UnSet
&& geo
->layout
!= -1)) {
11290 change
= CH_MIGRATION
;
11291 if (info
.array
.layout
== 0 && info
.array
.level
== 5 &&
11292 geo
->layout
== 5) {
11293 /* reshape 5 -> 4 */
11294 } else if (info
.array
.layout
== 5 && info
.array
.level
== 5 &&
11295 geo
->layout
== 0) {
11296 /* reshape 4 -> 5 */
11300 pr_err("Error. Layout Migration from %d to %d not supported!\n",
11301 info
.array
.layout
, geo
->layout
);
11303 goto analyse_change_exit
;
11306 geo
->layout
= info
.array
.layout
;
11307 if (imsm_layout
== -1)
11308 imsm_layout
= info
.array
.layout
;
11311 if (geo
->chunksize
> 0 && geo
->chunksize
!= UnSet
&&
11312 geo
->chunksize
!= info
.array
.chunk_size
) {
11313 if (info
.array
.level
== 10) {
11314 pr_err("Error. Chunk size change for RAID 10 is not supported.\n");
11316 goto analyse_change_exit
;
11317 } else if (info
.component_size
% (geo
->chunksize
/512)) {
11318 pr_err("New chunk size (%dK) does not evenly divide device size (%lluk). Aborting...\n",
11319 geo
->chunksize
/1024, info
.component_size
/2);
11321 goto analyse_change_exit
;
11323 change
= CH_MIGRATION
;
11325 geo
->chunksize
= info
.array
.chunk_size
;
11328 chunk
= geo
->chunksize
/ 1024;
11331 dev
= get_imsm_dev(super
, super
->current_vol
);
11332 data_disks
= imsm_num_data_members(dev
, MAP_0
);
11333 /* compute current size per disk member
11335 current_size
= info
.custom_array_size
/ data_disks
;
11337 if (geo
->size
> 0 && geo
->size
!= MAX_SIZE
) {
11338 /* align component size
11340 geo
->size
= imsm_component_size_aligment_check(
11341 get_imsm_raid_level(dev
->vol
.map
),
11342 chunk
* 1024, super
->sector_size
,
11344 if (geo
->size
== 0) {
11345 pr_err("Error. Size expansion is supported only (current size is %llu, requested size /rounded/ is 0).\n",
11347 goto analyse_change_exit
;
11351 if (current_size
!= geo
->size
&& geo
->size
> 0) {
11352 if (change
!= -1) {
11353 pr_err("Error. Size change should be the only one at a time.\n");
11355 goto analyse_change_exit
;
11357 if ((super
->current_vol
+ 1) != super
->anchor
->num_raid_devs
) {
11358 pr_err("Error. The last volume in container can be expanded only (%i/%s).\n",
11359 super
->current_vol
, st
->devnm
);
11360 goto analyse_change_exit
;
11362 /* check the maximum available size
11364 rv
= imsm_get_free_size(st
, dev
->vol
.map
->num_members
,
11365 0, chunk
, &free_size
);
11367 /* Cannot find maximum available space
11371 max_size
= free_size
+ current_size
;
11372 /* align component size
11374 max_size
= imsm_component_size_aligment_check(
11375 get_imsm_raid_level(dev
->vol
.map
),
11376 chunk
* 1024, super
->sector_size
,
11379 if (geo
->size
== MAX_SIZE
) {
11380 /* requested size change to the maximum available size
11382 if (max_size
== 0) {
11383 pr_err("Error. Cannot find maximum available space.\n");
11385 goto analyse_change_exit
;
11387 geo
->size
= max_size
;
11390 if (direction
== ROLLBACK_METADATA_CHANGES
) {
11391 /* accept size for rollback only
11394 /* round size due to metadata compatibility
11396 geo
->size
= (geo
->size
>> SECT_PER_MB_SHIFT
)
11397 << SECT_PER_MB_SHIFT
;
11398 dprintf("Prepare update for size change to %llu\n",
11400 if (current_size
>= geo
->size
) {
11401 pr_err("Error. Size expansion is supported only (current size is %llu, requested size /rounded/ is %llu).\n",
11402 current_size
, geo
->size
);
11403 goto analyse_change_exit
;
11405 if (max_size
&& geo
->size
> max_size
) {
11406 pr_err("Error. Requested size is larger than maximum available size (maximum available size is %llu, requested size /rounded/ is %llu).\n",
11407 max_size
, geo
->size
);
11408 goto analyse_change_exit
;
11411 geo
->size
*= data_disks
;
11412 geo
->raid_disks
= dev
->vol
.map
->num_members
;
11413 change
= CH_ARRAY_SIZE
;
11415 if (!validate_geometry_imsm(st
,
11418 geo
->raid_disks
+ devNumChange
,
11420 geo
->size
, INVALID_SECTORS
,
11421 0, 0, info
.consistency_policy
, 1))
11425 struct intel_super
*super
= st
->sb
;
11426 struct imsm_super
*mpb
= super
->anchor
;
11428 if (mpb
->num_raid_devs
> 1) {
11429 pr_err("Error. Cannot perform operation on %s- for this operation it MUST be single array in container\n",
11435 analyse_change_exit
:
11436 if (direction
== ROLLBACK_METADATA_CHANGES
&&
11437 (change
== CH_MIGRATION
|| change
== CH_TAKEOVER
)) {
11438 dprintf("imsm: Metadata changes rollback is not supported for migration and takeover operations.\n");
11444 int imsm_takeover(struct supertype
*st
, struct geo_params
*geo
)
11446 struct intel_super
*super
= st
->sb
;
11447 struct imsm_update_takeover
*u
;
11449 u
= xmalloc(sizeof(struct imsm_update_takeover
));
11451 u
->type
= update_takeover
;
11452 u
->subarray
= super
->current_vol
;
11454 /* 10->0 transition */
11455 if (geo
->level
== 0)
11456 u
->direction
= R10_TO_R0
;
11458 /* 0->10 transition */
11459 if (geo
->level
== 10)
11460 u
->direction
= R0_TO_R10
;
11462 /* update metadata locally */
11463 imsm_update_metadata_locally(st
, u
,
11464 sizeof(struct imsm_update_takeover
));
11465 /* and possibly remotely */
11466 if (st
->update_tail
)
11467 append_metadata_update(st
, u
,
11468 sizeof(struct imsm_update_takeover
));
11475 static int imsm_reshape_super(struct supertype
*st
, unsigned long long size
,
11477 int layout
, int chunksize
, int raid_disks
,
11478 int delta_disks
, char *backup
, char *dev
,
11479 int direction
, int verbose
)
11482 struct geo_params geo
;
11484 dprintf("(enter)\n");
11486 memset(&geo
, 0, sizeof(struct geo_params
));
11488 geo
.dev_name
= dev
;
11489 strcpy(geo
.devnm
, st
->devnm
);
11492 geo
.layout
= layout
;
11493 geo
.chunksize
= chunksize
;
11494 geo
.raid_disks
= raid_disks
;
11495 if (delta_disks
!= UnSet
)
11496 geo
.raid_disks
+= delta_disks
;
11498 dprintf("for level : %i\n", geo
.level
);
11499 dprintf("for raid_disks : %i\n", geo
.raid_disks
);
11501 if (experimental() == 0)
11504 if (strcmp(st
->container_devnm
, st
->devnm
) == 0) {
11505 /* On container level we can only increase number of devices. */
11506 dprintf("imsm: info: Container operation\n");
11507 int old_raid_disks
= 0;
11509 if (imsm_reshape_is_allowed_on_container(
11510 st
, &geo
, &old_raid_disks
, direction
)) {
11511 struct imsm_update_reshape
*u
= NULL
;
11514 len
= imsm_create_metadata_update_for_reshape(
11515 st
, &geo
, old_raid_disks
, &u
);
11518 dprintf("imsm: Cannot prepare update\n");
11519 goto exit_imsm_reshape_super
;
11523 /* update metadata locally */
11524 imsm_update_metadata_locally(st
, u
, len
);
11525 /* and possibly remotely */
11526 if (st
->update_tail
)
11527 append_metadata_update(st
, u
, len
);
11532 pr_err("(imsm) Operation is not allowed on this container\n");
11535 /* On volume level we support following operations
11536 * - takeover: raid10 -> raid0; raid0 -> raid10
11537 * - chunk size migration
11538 * - migration: raid5 -> raid0; raid0 -> raid5
11540 struct intel_super
*super
= st
->sb
;
11541 struct intel_dev
*dev
= super
->devlist
;
11543 dprintf("imsm: info: Volume operation\n");
11544 /* find requested device */
11547 imsm_find_array_devnm_by_subdev(
11548 dev
->index
, st
->container_devnm
);
11549 if (devnm
&& strcmp(devnm
, geo
.devnm
) == 0)
11554 pr_err("Cannot find %s (%s) subarray\n",
11555 geo
.dev_name
, geo
.devnm
);
11556 goto exit_imsm_reshape_super
;
11558 super
->current_vol
= dev
->index
;
11559 change
= imsm_analyze_change(st
, &geo
, direction
);
11562 ret_val
= imsm_takeover(st
, &geo
);
11564 case CH_MIGRATION
: {
11565 struct imsm_update_reshape_migration
*u
= NULL
;
11567 imsm_create_metadata_update_for_migration(
11570 dprintf("imsm: Cannot prepare update\n");
11574 /* update metadata locally */
11575 imsm_update_metadata_locally(st
, u
, len
);
11576 /* and possibly remotely */
11577 if (st
->update_tail
)
11578 append_metadata_update(st
, u
, len
);
11583 case CH_ARRAY_SIZE
: {
11584 struct imsm_update_size_change
*u
= NULL
;
11586 imsm_create_metadata_update_for_size_change(
11589 dprintf("imsm: Cannot prepare update\n");
11593 /* update metadata locally */
11594 imsm_update_metadata_locally(st
, u
, len
);
11595 /* and possibly remotely */
11596 if (st
->update_tail
)
11597 append_metadata_update(st
, u
, len
);
11607 exit_imsm_reshape_super
:
11608 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
11612 #define COMPLETED_OK 0
11613 #define COMPLETED_NONE 1
11614 #define COMPLETED_DELAYED 2
11616 static int read_completed(int fd
, unsigned long long *val
)
11621 ret
= sysfs_fd_get_str(fd
, buf
, 50);
11625 ret
= COMPLETED_OK
;
11626 if (strncmp(buf
, "none", 4) == 0) {
11627 ret
= COMPLETED_NONE
;
11628 } else if (strncmp(buf
, "delayed", 7) == 0) {
11629 ret
= COMPLETED_DELAYED
;
11632 *val
= strtoull(buf
, &ep
, 0);
11633 if (ep
== buf
|| (*ep
!= 0 && *ep
!= '\n' && *ep
!= ' '))
11639 /*******************************************************************************
11640 * Function: wait_for_reshape_imsm
11641 * Description: Function writes new sync_max value and waits until
11642 * reshape process reach new position
11644 * sra : general array info
11645 * ndata : number of disks in new array's layout
11648 * 1 : there is no reshape in progress,
11650 ******************************************************************************/
11651 int wait_for_reshape_imsm(struct mdinfo
*sra
, int ndata
)
11653 int fd
= sysfs_get_fd(sra
, NULL
, "sync_completed");
11655 unsigned long long completed
;
11656 /* to_complete : new sync_max position */
11657 unsigned long long to_complete
= sra
->reshape_progress
;
11658 unsigned long long position_to_set
= to_complete
/ ndata
;
11661 dprintf("cannot open reshape_position\n");
11666 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
11668 dprintf("cannot read reshape_position (no reshape in progres)\n");
11677 if (completed
> position_to_set
) {
11678 dprintf("wrong next position to set %llu (%llu)\n",
11679 to_complete
, position_to_set
);
11683 dprintf("Position set: %llu\n", position_to_set
);
11684 if (sysfs_set_num(sra
, NULL
, "sync_max",
11685 position_to_set
) != 0) {
11686 dprintf("cannot set reshape position to %llu\n",
11695 int timeout
= 3000;
11697 sysfs_wait(fd
, &timeout
);
11698 if (sysfs_get_str(sra
, NULL
, "sync_action",
11700 strncmp(action
, "reshape", 7) != 0) {
11701 if (strncmp(action
, "idle", 4) == 0)
11707 rc
= read_completed(fd
, &completed
);
11709 dprintf("cannot read reshape_position (in loop)\n");
11712 } else if (rc
== COMPLETED_NONE
)
11714 } while (completed
< position_to_set
);
11720 /*******************************************************************************
11721 * Function: check_degradation_change
11722 * Description: Check that array hasn't become failed.
11724 * info : for sysfs access
11725 * sources : source disks descriptors
11726 * degraded: previous degradation level
11728 * degradation level
11729 ******************************************************************************/
11730 int check_degradation_change(struct mdinfo
*info
,
11734 unsigned long long new_degraded
;
11737 rv
= sysfs_get_ll(info
, NULL
, "degraded", &new_degraded
);
11738 if (rv
== -1 || (new_degraded
!= (unsigned long long)degraded
)) {
11739 /* check each device to ensure it is still working */
11742 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
11743 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
11745 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
11748 if (sysfs_get_str(info
,
11749 sd
, "state", sbuf
, sizeof(sbuf
)) < 0 ||
11750 strstr(sbuf
, "faulty") ||
11751 strstr(sbuf
, "in_sync") == NULL
) {
11752 /* this device is dead */
11753 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
11754 if (sd
->disk
.raid_disk
>= 0 &&
11755 sources
[sd
->disk
.raid_disk
] >= 0) {
11757 sd
->disk
.raid_disk
]);
11758 sources
[sd
->disk
.raid_disk
] =
11767 return new_degraded
;
11770 /*******************************************************************************
11771 * Function: imsm_manage_reshape
11772 * Description: Function finds array under reshape and it manages reshape
11773 * process. It creates stripes backups (if required) and sets
11776 * afd : Backup handle (nattive) - not used
11777 * sra : general array info
11778 * reshape : reshape parameters - not used
11779 * st : supertype structure
11780 * blocks : size of critical section [blocks]
11781 * fds : table of source device descriptor
11782 * offsets : start of array (offest per devices)
11784 * destfd : table of destination device descriptor
11785 * destoffsets : table of destination offsets (per device)
11787 * 1 : success, reshape is done
11789 ******************************************************************************/
11790 static int imsm_manage_reshape(
11791 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
11792 struct supertype
*st
, unsigned long backup_blocks
,
11793 int *fds
, unsigned long long *offsets
,
11794 int dests
, int *destfd
, unsigned long long *destoffsets
)
11797 struct intel_super
*super
= st
->sb
;
11798 struct intel_dev
*dv
;
11799 unsigned int sector_size
= super
->sector_size
;
11800 struct imsm_dev
*dev
= NULL
;
11801 struct imsm_map
*map_src
;
11802 int migr_vol_qan
= 0;
11803 int ndata
, odata
; /* [bytes] */
11804 int chunk
; /* [bytes] */
11805 struct migr_record
*migr_rec
;
11807 unsigned int buf_size
; /* [bytes] */
11808 unsigned long long max_position
; /* array size [bytes] */
11809 unsigned long long next_step
; /* [blocks]/[bytes] */
11810 unsigned long long old_data_stripe_length
;
11811 unsigned long long start_src
; /* [bytes] */
11812 unsigned long long start
; /* [bytes] */
11813 unsigned long long start_buf_shift
; /* [bytes] */
11815 int source_layout
= 0;
11820 if (!fds
|| !offsets
)
11823 /* Find volume during the reshape */
11824 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
11825 if (dv
->dev
->vol
.migr_type
== MIGR_GEN_MIGR
&&
11826 dv
->dev
->vol
.migr_state
== 1) {
11831 /* Only one volume can migrate at the same time */
11832 if (migr_vol_qan
!= 1) {
11833 pr_err("%s", migr_vol_qan
?
11834 "Number of migrating volumes greater than 1\n" :
11835 "There is no volume during migrationg\n");
11839 map_src
= get_imsm_map(dev
, MAP_1
);
11840 if (map_src
== NULL
)
11843 ndata
= imsm_num_data_members(dev
, MAP_0
);
11844 odata
= imsm_num_data_members(dev
, MAP_1
);
11846 chunk
= __le16_to_cpu(map_src
->blocks_per_strip
) * 512;
11847 old_data_stripe_length
= odata
* chunk
;
11849 migr_rec
= super
->migr_rec
;
11851 /* initialize migration record for start condition */
11852 if (sra
->reshape_progress
== 0)
11853 init_migr_record_imsm(st
, dev
, sra
);
11855 if (__le32_to_cpu(migr_rec
->rec_status
) != UNIT_SRC_NORMAL
) {
11856 dprintf("imsm: cannot restart migration when data are present in copy area.\n");
11859 /* Save checkpoint to update migration record for current
11860 * reshape position (in md). It can be farther than current
11861 * reshape position in metadata.
11863 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
11864 /* ignore error == 2, this can mean end of reshape here
11866 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL, initial save)\n");
11871 /* size for data */
11872 buf_size
= __le32_to_cpu(migr_rec
->blocks_per_unit
) * 512;
11873 /* extend buffer size for parity disk */
11874 buf_size
+= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
11875 /* add space for stripe aligment */
11876 buf_size
+= old_data_stripe_length
;
11877 if (posix_memalign((void **)&buf
, MAX_SECTOR_SIZE
, buf_size
)) {
11878 dprintf("imsm: Cannot allocate checkpoint buffer\n");
11882 max_position
= sra
->component_size
* ndata
;
11883 source_layout
= imsm_level_to_layout(map_src
->raid_level
);
11885 while (__le32_to_cpu(migr_rec
->curr_migr_unit
) <
11886 __le32_to_cpu(migr_rec
->num_migr_units
)) {
11887 /* current reshape position [blocks] */
11888 unsigned long long current_position
=
11889 __le32_to_cpu(migr_rec
->blocks_per_unit
)
11890 * __le32_to_cpu(migr_rec
->curr_migr_unit
);
11891 unsigned long long border
;
11893 /* Check that array hasn't become failed.
11895 degraded
= check_degradation_change(sra
, fds
, degraded
);
11896 if (degraded
> 1) {
11897 dprintf("imsm: Abort reshape due to degradation level (%i)\n", degraded
);
11901 next_step
= __le32_to_cpu(migr_rec
->blocks_per_unit
);
11903 if ((current_position
+ next_step
) > max_position
)
11904 next_step
= max_position
- current_position
;
11906 start
= current_position
* 512;
11908 /* align reading start to old geometry */
11909 start_buf_shift
= start
% old_data_stripe_length
;
11910 start_src
= start
- start_buf_shift
;
11912 border
= (start_src
/ odata
) - (start
/ ndata
);
11914 if (border
<= __le32_to_cpu(migr_rec
->dest_depth_per_unit
)) {
11915 /* save critical stripes to buf
11916 * start - start address of current unit
11917 * to backup [bytes]
11918 * start_src - start address of current unit
11919 * to backup alligned to source array
11922 unsigned long long next_step_filler
;
11923 unsigned long long copy_length
= next_step
* 512;
11925 /* allign copy area length to stripe in old geometry */
11926 next_step_filler
= ((copy_length
+ start_buf_shift
)
11927 % old_data_stripe_length
);
11928 if (next_step_filler
)
11929 next_step_filler
= (old_data_stripe_length
11930 - next_step_filler
);
11931 dprintf("save_stripes() parameters: start = %llu,\tstart_src = %llu,\tnext_step*512 = %llu,\tstart_in_buf_shift = %llu,\tnext_step_filler = %llu\n",
11932 start
, start_src
, copy_length
,
11933 start_buf_shift
, next_step_filler
);
11935 if (save_stripes(fds
, offsets
, map_src
->num_members
,
11936 chunk
, map_src
->raid_level
,
11937 source_layout
, 0, NULL
, start_src
,
11939 next_step_filler
+ start_buf_shift
,
11941 dprintf("imsm: Cannot save stripes to buffer\n");
11944 /* Convert data to destination format and store it
11945 * in backup general migration area
11947 if (save_backup_imsm(st
, dev
, sra
,
11948 buf
+ start_buf_shift
, copy_length
)) {
11949 dprintf("imsm: Cannot save stripes to target devices\n");
11952 if (save_checkpoint_imsm(st
, sra
,
11953 UNIT_SRC_IN_CP_AREA
)) {
11954 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_IN_CP_AREA)\n");
11958 /* set next step to use whole border area */
11959 border
/= next_step
;
11961 next_step
*= border
;
11963 /* When data backed up, checkpoint stored,
11964 * kick the kernel to reshape unit of data
11966 next_step
= next_step
+ sra
->reshape_progress
;
11967 /* limit next step to array max position */
11968 if (next_step
> max_position
)
11969 next_step
= max_position
;
11970 sysfs_set_num(sra
, NULL
, "suspend_lo", sra
->reshape_progress
);
11971 sysfs_set_num(sra
, NULL
, "suspend_hi", next_step
);
11972 sra
->reshape_progress
= next_step
;
11974 /* wait until reshape finish */
11975 if (wait_for_reshape_imsm(sra
, ndata
)) {
11976 dprintf("wait_for_reshape_imsm returned error!\n");
11982 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
11983 /* ignore error == 2, this can mean end of reshape here
11985 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL)\n");
11991 /* clear migr_rec on disks after successful migration */
11994 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
);
11995 for (d
= super
->disks
; d
; d
= d
->next
) {
11996 if (d
->index
< 0 || is_failed(&d
->disk
))
11998 unsigned long long dsize
;
12000 get_dev_size(d
->fd
, NULL
, &dsize
);
12001 if (lseek64(d
->fd
, dsize
- MIGR_REC_SECTOR_POSITION
*sector_size
,
12003 if ((unsigned int)write(d
->fd
, super
->migr_rec_buf
,
12004 MIGR_REC_BUF_SECTORS
*sector_size
) !=
12005 MIGR_REC_BUF_SECTORS
*sector_size
)
12006 perror("Write migr_rec failed");
12010 /* return '1' if done */
12014 /* See Grow.c: abort_reshape() for further explanation */
12015 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
12016 sysfs_set_num(sra
, NULL
, "suspend_hi", 0);
12017 sysfs_set_num(sra
, NULL
, "suspend_lo", 0);
12022 struct superswitch super_imsm
= {
12023 .examine_super
= examine_super_imsm
,
12024 .brief_examine_super
= brief_examine_super_imsm
,
12025 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
12026 .export_examine_super
= export_examine_super_imsm
,
12027 .detail_super
= detail_super_imsm
,
12028 .brief_detail_super
= brief_detail_super_imsm
,
12029 .write_init_super
= write_init_super_imsm
,
12030 .validate_geometry
= validate_geometry_imsm
,
12031 .add_to_super
= add_to_super_imsm
,
12032 .remove_from_super
= remove_from_super_imsm
,
12033 .detail_platform
= detail_platform_imsm
,
12034 .export_detail_platform
= export_detail_platform_imsm
,
12035 .kill_subarray
= kill_subarray_imsm
,
12036 .update_subarray
= update_subarray_imsm
,
12037 .load_container
= load_container_imsm
,
12038 .default_geometry
= default_geometry_imsm
,
12039 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
12040 .reshape_super
= imsm_reshape_super
,
12041 .manage_reshape
= imsm_manage_reshape
,
12042 .recover_backup
= recover_backup_imsm
,
12043 .copy_metadata
= copy_metadata_imsm
,
12044 .examine_badblocks
= examine_badblocks_imsm
,
12045 .match_home
= match_home_imsm
,
12046 .uuid_from_super
= uuid_from_super_imsm
,
12047 .getinfo_super
= getinfo_super_imsm
,
12048 .getinfo_super_disks
= getinfo_super_disks_imsm
,
12049 .update_super
= update_super_imsm
,
12051 .avail_size
= avail_size_imsm
,
12052 .get_spare_criteria
= get_spare_criteria_imsm
,
12054 .compare_super
= compare_super_imsm
,
12056 .load_super
= load_super_imsm
,
12057 .init_super
= init_super_imsm
,
12058 .store_super
= store_super_imsm
,
12059 .free_super
= free_super_imsm
,
12060 .match_metadata_desc
= match_metadata_desc_imsm
,
12061 .container_content
= container_content_imsm
,
12062 .validate_container
= validate_container_imsm
,
12064 .write_init_ppl
= write_init_ppl_imsm
,
12065 .validate_ppl
= validate_ppl_imsm
,
12071 .open_new
= imsm_open_new
,
12072 .set_array_state
= imsm_set_array_state
,
12073 .set_disk
= imsm_set_disk
,
12074 .sync_metadata
= imsm_sync_metadata
,
12075 .activate_spare
= imsm_activate_spare
,
12076 .process_update
= imsm_process_update
,
12077 .prepare_update
= imsm_prepare_update
,
12078 .record_bad_block
= imsm_record_badblock
,
12079 .clear_bad_block
= imsm_clear_badblock
,
12080 .get_bad_blocks
= imsm_get_badblocks
,