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 8192
92 #define NUM_BLOCKS_DIRTY_STRIPE_REGION 2048
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
100 * Internal Write-intent bitmap is stored in the same area where PPL.
101 * Both features are mutually exclusive, so it is not an issue.
102 * The first 8KiB of the area are reserved and shall not be used.
104 #define IMSM_BITMAP_AREA_RESERVED_SIZE 8192
106 #define IMSM_BITMAP_HEADER_OFFSET (IMSM_BITMAP_AREA_RESERVED_SIZE)
107 #define IMSM_BITMAP_HEADER_SIZE MAX_SECTOR_SIZE
109 #define IMSM_BITMAP_START_OFFSET (IMSM_BITMAP_HEADER_OFFSET + IMSM_BITMAP_HEADER_SIZE)
110 #define IMSM_BITMAP_AREA_SIZE (MULTIPLE_PPL_AREA_SIZE_IMSM - IMSM_BITMAP_START_OFFSET)
111 #define IMSM_BITMAP_AND_HEADER_SIZE (IMSM_BITMAP_AREA_SIZE + IMSM_BITMAP_HEADER_SIZE)
113 #define IMSM_DEFAULT_BITMAP_CHUNKSIZE (64 * 1024 * 1024)
114 #define IMSM_DEFAULT_BITMAP_DAEMON_SLEEP 5
117 * This macro let's us ensure that no-one accidentally
118 * changes the size of a struct
120 #define ASSERT_SIZE(_struct, size) \
121 static inline void __assert_size_##_struct(void) \
125 case (sizeof(struct _struct) == size): break; \
129 /* Disk configuration info. */
130 #define IMSM_MAX_DEVICES 255
132 __u8 serial
[MAX_RAID_SERIAL_LEN
];/* 0xD8 - 0xE7 ascii serial number */
133 __u32 total_blocks_lo
; /* 0xE8 - 0xEB total blocks lo */
134 __u32 scsi_id
; /* 0xEC - 0xEF scsi ID */
135 #define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
136 #define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
137 #define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
138 #define JOURNAL_DISK __cpu_to_le32(0x2000000) /* Device marked as Journaling Drive */
139 __u32 status
; /* 0xF0 - 0xF3 */
140 __u32 owner_cfg_num
; /* which config 0,1,2... owns this disk */
141 __u32 total_blocks_hi
; /* 0xF4 - 0xF5 total blocks hi */
142 #define IMSM_DISK_FILLERS 3
143 __u32 filler
[IMSM_DISK_FILLERS
]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
145 ASSERT_SIZE(imsm_disk
, 48)
147 /* map selector for map managment
153 /* RAID map configuration infos. */
155 __u32 pba_of_lba0_lo
; /* start address of partition */
156 __u32 blocks_per_member_lo
;/* blocks per member */
157 __u32 num_data_stripes_lo
; /* number of data stripes */
158 __u16 blocks_per_strip
;
159 __u8 map_state
; /* Normal, Uninitialized, Degraded, Failed */
160 #define IMSM_T_STATE_NORMAL 0
161 #define IMSM_T_STATE_UNINITIALIZED 1
162 #define IMSM_T_STATE_DEGRADED 2
163 #define IMSM_T_STATE_FAILED 3
165 #define IMSM_T_RAID0 0
166 #define IMSM_T_RAID1 1
167 #define IMSM_T_RAID5 5 /* since metadata version 1.2.02 ? */
168 __u8 num_members
; /* number of member disks */
169 __u8 num_domains
; /* number of parity domains */
170 __u8 failed_disk_num
; /* valid only when state is degraded */
172 __u32 pba_of_lba0_hi
;
173 __u32 blocks_per_member_hi
;
174 __u32 num_data_stripes_hi
;
175 __u32 filler
[4]; /* expansion area */
176 #define IMSM_ORD_REBUILD (1 << 24)
177 __u32 disk_ord_tbl
[1]; /* disk_ord_tbl[num_members],
178 * top byte contains some flags
181 ASSERT_SIZE(imsm_map
, 52)
184 __u32 curr_migr_unit_lo
;
185 __u32 checkpoint_id
; /* id to access curr_migr_unit */
186 __u8 migr_state
; /* Normal or Migrating */
188 #define MIGR_REBUILD 1
189 #define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
190 #define MIGR_GEN_MIGR 3
191 #define MIGR_STATE_CHANGE 4
192 #define MIGR_REPAIR 5
193 __u8 migr_type
; /* Initializing, Rebuilding, ... */
194 #define RAIDVOL_CLEAN 0
195 #define RAIDVOL_DIRTY 1
196 #define RAIDVOL_DSRECORD_VALID 2
198 __u8 fs_state
; /* fast-sync state for CnG (0xff == disabled) */
199 __u16 verify_errors
; /* number of mismatches */
200 __u16 bad_blocks
; /* number of bad blocks during verify */
201 __u32 curr_migr_unit_hi
;
203 struct imsm_map map
[1];
204 /* here comes another one if migr_state */
206 ASSERT_SIZE(imsm_vol
, 84)
209 __u8 volume
[MAX_RAID_SERIAL_LEN
];
212 #define DEV_BOOTABLE __cpu_to_le32(0x01)
213 #define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
214 #define DEV_READ_COALESCING __cpu_to_le32(0x04)
215 #define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
216 #define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
217 #define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
218 #define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
219 #define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
220 #define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
221 #define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
222 #define DEV_CLONE_N_GO __cpu_to_le32(0x400)
223 #define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
224 #define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
225 __u32 status
; /* Persistent RaidDev status */
226 __u32 reserved_blocks
; /* Reserved blocks at beginning of volume */
230 __u8 cng_master_disk
;
234 __u16 my_vol_raid_dev_num
; /* Used in Unique volume Id for this RaidDev */
240 /* Unique Volume Id of the NvCache Volume associated with this volume */
241 __u32 nvc_vol_orig_family_num
;
242 __u16 nvc_vol_raid_dev_num
;
245 #define RWH_DISTRIBUTED 1
246 #define RWH_JOURNALING_DRIVE 2
247 #define RWH_MULTIPLE_DISTRIBUTED 3
248 #define RWH_MULTIPLE_PPLS_JOURNALING_DRIVE 4
249 #define RWH_MULTIPLE_OFF 5
251 __u8 rwh_policy
; /* Raid Write Hole Policy */
252 __u8 jd_serial
[MAX_RAID_SERIAL_LEN
]; /* Journal Drive serial number */
255 #define IMSM_DEV_FILLERS 3
256 __u32 filler
[IMSM_DEV_FILLERS
];
259 ASSERT_SIZE(imsm_dev
, 164)
262 __u8 sig
[MAX_SIGNATURE_LENGTH
]; /* 0x00 - 0x1F */
263 __u32 check_sum
; /* 0x20 - 0x23 MPB Checksum */
264 __u32 mpb_size
; /* 0x24 - 0x27 Size of MPB */
265 __u32 family_num
; /* 0x28 - 0x2B Checksum from first time this config was written */
266 __u32 generation_num
; /* 0x2C - 0x2F Incremented each time this array's MPB is written */
267 __u32 error_log_size
; /* 0x30 - 0x33 in bytes */
268 __u32 attributes
; /* 0x34 - 0x37 */
269 __u8 num_disks
; /* 0x38 Number of configured disks */
270 __u8 num_raid_devs
; /* 0x39 Number of configured volumes */
271 __u8 error_log_pos
; /* 0x3A */
272 __u8 fill
[1]; /* 0x3B */
273 __u32 cache_size
; /* 0x3c - 0x40 in mb */
274 __u32 orig_family_num
; /* 0x40 - 0x43 original family num */
275 __u32 pwr_cycle_count
; /* 0x44 - 0x47 simulated power cycle count for array */
276 __u32 bbm_log_size
; /* 0x48 - 0x4B - size of bad Block Mgmt Log in bytes */
277 __u16 num_raid_devs_created
; /* 0x4C - 0x4D Used for generating unique
278 * volume IDs for raid_dev created in this array
281 __u16 filler1
; /* 0x4E - 0x4F */
282 __u64 creation_time
; /* 0x50 - 0x57 Array creation time */
283 #define IMSM_FILLERS 32
284 __u32 filler
[IMSM_FILLERS
]; /* 0x58 - 0xD7 RAID_MPB_FILLERS */
285 struct imsm_disk disk
[1]; /* 0xD8 diskTbl[numDisks] */
286 /* here comes imsm_dev[num_raid_devs] */
287 /* here comes BBM logs */
289 ASSERT_SIZE(imsm_super
, 264)
291 #define BBM_LOG_MAX_ENTRIES 254
292 #define BBM_LOG_MAX_LBA_ENTRY_VAL 256 /* Represents 256 LBAs */
293 #define BBM_LOG_SIGNATURE 0xabadb10c
295 struct bbm_log_block_addr
{
298 } __attribute__ ((__packed__
));
300 struct bbm_log_entry
{
301 __u8 marked_count
; /* Number of blocks marked - 1 */
302 __u8 disk_ordinal
; /* Disk entry within the imsm_super */
303 struct bbm_log_block_addr defective_block_start
;
304 } __attribute__ ((__packed__
));
307 __u32 signature
; /* 0xABADB10C */
309 struct bbm_log_entry marked_block_entries
[BBM_LOG_MAX_ENTRIES
];
311 ASSERT_SIZE(bbm_log
, 2040)
313 static char *map_state_str
[] = { "normal", "uninitialized", "degraded", "failed" };
315 #define BLOCKS_PER_KB (1024/512)
317 #define RAID_DISK_RESERVED_BLOCKS_IMSM_HI 2209
319 #define GEN_MIGR_AREA_SIZE 2048 /* General Migration Copy Area size in blocks */
321 #define MIGR_REC_BUF_SECTORS 1 /* size of migr_record i/o buffer in sectors */
322 #define MIGR_REC_SECTOR_POSITION 1 /* migr_record position offset on disk,
323 * MIGR_REC_BUF_SECTORS <= MIGR_REC_SECTOR_POS
326 #define UNIT_SRC_NORMAL 0 /* Source data for curr_migr_unit must
327 * be recovered using srcMap */
328 #define UNIT_SRC_IN_CP_AREA 1 /* Source data for curr_migr_unit has
329 * already been migrated and must
330 * be recovered from checkpoint area */
332 #define PPL_ENTRY_SPACE (128 * 1024) /* Size of single PPL, without the header */
335 __u32 rec_status
; /* Status used to determine how to restart
336 * migration in case it aborts
338 __u32 curr_migr_unit_lo
; /* 0..numMigrUnits-1 */
339 __u32 family_num
; /* Family number of MPB
340 * containing the RaidDev
341 * that is migrating */
342 __u32 ascending_migr
; /* True if migrating in increasing
344 __u32 blocks_per_unit
; /* Num disk blocks per unit of operation */
345 __u32 dest_depth_per_unit
; /* Num member blocks each destMap
347 * advances per unit-of-operation */
348 __u32 ckpt_area_pba_lo
; /* Pba of first block of ckpt copy area */
349 __u32 dest_1st_member_lba_lo
; /* First member lba on first
350 * stripe of destination */
351 __u32 num_migr_units_lo
; /* Total num migration units-of-op */
352 __u32 post_migr_vol_cap
; /* Size of volume after
353 * migration completes */
354 __u32 post_migr_vol_cap_hi
; /* Expansion space for LBA64 */
355 __u32 ckpt_read_disk_num
; /* Which member disk in destSubMap[0] the
356 * migration ckpt record was read from
357 * (for recovered migrations) */
358 __u32 curr_migr_unit_hi
; /* 0..numMigrUnits-1 high order 32 bits */
359 __u32 ckpt_area_pba_hi
; /* Pba of first block of ckpt copy area
360 * high order 32 bits */
361 __u32 dest_1st_member_lba_hi
; /* First member lba on first stripe of
362 * destination - high order 32 bits */
363 __u32 num_migr_units_hi
; /* Total num migration units-of-op
364 * high order 32 bits */
367 ASSERT_SIZE(migr_record
, 128)
372 * 2: metadata does not match
380 struct md_list
*next
;
383 #define pr_vrb(fmt, arg...) (void) (verbose && pr_err(fmt, ##arg))
385 static __u8
migr_type(struct imsm_dev
*dev
)
387 if (dev
->vol
.migr_type
== MIGR_VERIFY
&&
388 dev
->status
& DEV_VERIFY_AND_FIX
)
391 return dev
->vol
.migr_type
;
394 static void set_migr_type(struct imsm_dev
*dev
, __u8 migr_type
)
396 /* for compatibility with older oroms convert MIGR_REPAIR, into
397 * MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status
399 if (migr_type
== MIGR_REPAIR
) {
400 dev
->vol
.migr_type
= MIGR_VERIFY
;
401 dev
->status
|= DEV_VERIFY_AND_FIX
;
403 dev
->vol
.migr_type
= migr_type
;
404 dev
->status
&= ~DEV_VERIFY_AND_FIX
;
408 static unsigned int sector_count(__u32 bytes
, unsigned int sector_size
)
410 return ROUND_UP(bytes
, sector_size
) / sector_size
;
413 static unsigned int mpb_sectors(struct imsm_super
*mpb
,
414 unsigned int sector_size
)
416 return sector_count(__le32_to_cpu(mpb
->mpb_size
), sector_size
);
420 struct imsm_dev
*dev
;
421 struct intel_dev
*next
;
426 enum sys_dev_type type
;
429 struct intel_hba
*next
;
436 /* internal representation of IMSM metadata */
439 void *buf
; /* O_DIRECT buffer for reading/writing metadata */
440 struct imsm_super
*anchor
; /* immovable parameters */
443 void *migr_rec_buf
; /* buffer for I/O operations */
444 struct migr_record
*migr_rec
; /* migration record */
446 int clean_migration_record_by_mdmon
; /* when reshape is switched to next
447 array, it indicates that mdmon is allowed to clean migration
449 size_t len
; /* size of the 'buf' allocation */
450 size_t extra_space
; /* extra space in 'buf' that is not used yet */
451 void *next_buf
; /* for realloc'ing buf from the manager */
453 int updates_pending
; /* count of pending updates for mdmon */
454 int current_vol
; /* index of raid device undergoing creation */
455 unsigned long long create_offset
; /* common start for 'current_vol' */
456 __u32 random
; /* random data for seeding new family numbers */
457 struct intel_dev
*devlist
;
458 unsigned int sector_size
; /* sector size of used member drives */
462 __u8 serial
[MAX_RAID_SERIAL_LEN
];
465 struct imsm_disk disk
;
468 struct extent
*e
; /* for determining freespace @ create */
469 int raiddisk
; /* slot to fill in autolayout */
471 } *disks
, *current_disk
;
472 struct dl
*disk_mgmt_list
; /* list of disks to add/remove while mdmon
474 struct dl
*missing
; /* disks removed while we weren't looking */
475 struct bbm_log
*bbm_log
;
476 struct intel_hba
*hba
; /* device path of the raid controller for this metadata */
477 const struct imsm_orom
*orom
; /* platform firmware support */
478 struct intel_super
*next
; /* (temp) list for disambiguating family_num */
479 struct md_bb bb
; /* memory for get_bad_blocks call */
483 struct imsm_disk disk
;
484 #define IMSM_UNKNOWN_OWNER (-1)
486 struct intel_disk
*next
;
490 unsigned long long start
, size
;
493 /* definitions of reshape process types */
494 enum imsm_reshape_type
{
500 /* definition of messages passed to imsm_process_update */
501 enum imsm_update_type
{
502 update_activate_spare
,
506 update_add_remove_disk
,
507 update_reshape_container_disks
,
508 update_reshape_migration
,
510 update_general_migration_checkpoint
,
512 update_prealloc_badblocks_mem
,
516 struct imsm_update_activate_spare
{
517 enum imsm_update_type type
;
521 struct imsm_update_activate_spare
*next
;
527 unsigned long long size
;
534 enum takeover_direction
{
538 struct imsm_update_takeover
{
539 enum imsm_update_type type
;
541 enum takeover_direction direction
;
544 struct imsm_update_reshape
{
545 enum imsm_update_type type
;
549 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
552 struct imsm_update_reshape_migration
{
553 enum imsm_update_type type
;
556 /* fields for array migration changes
563 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
566 struct imsm_update_size_change
{
567 enum imsm_update_type type
;
572 struct imsm_update_general_migration_checkpoint
{
573 enum imsm_update_type type
;
574 __u64 curr_migr_unit
;
578 __u8 serial
[MAX_RAID_SERIAL_LEN
];
581 struct imsm_update_create_array
{
582 enum imsm_update_type type
;
587 struct imsm_update_kill_array
{
588 enum imsm_update_type type
;
592 struct imsm_update_rename_array
{
593 enum imsm_update_type type
;
594 __u8 name
[MAX_RAID_SERIAL_LEN
];
598 struct imsm_update_add_remove_disk
{
599 enum imsm_update_type type
;
602 struct imsm_update_prealloc_bb_mem
{
603 enum imsm_update_type type
;
606 struct imsm_update_rwh_policy
{
607 enum imsm_update_type type
;
612 static const char *_sys_dev_type
[] = {
613 [SYS_DEV_UNKNOWN
] = "Unknown",
614 [SYS_DEV_SAS
] = "SAS",
615 [SYS_DEV_SATA
] = "SATA",
616 [SYS_DEV_NVME
] = "NVMe",
617 [SYS_DEV_VMD
] = "VMD"
620 const char *get_sys_dev_type(enum sys_dev_type type
)
622 if (type
>= SYS_DEV_MAX
)
623 type
= SYS_DEV_UNKNOWN
;
625 return _sys_dev_type
[type
];
628 static struct intel_hba
* alloc_intel_hba(struct sys_dev
*device
)
630 struct intel_hba
*result
= xmalloc(sizeof(*result
));
632 result
->type
= device
->type
;
633 result
->path
= xstrdup(device
->path
);
635 if (result
->path
&& (result
->pci_id
= strrchr(result
->path
, '/')) != NULL
)
641 static struct intel_hba
* find_intel_hba(struct intel_hba
*hba
, struct sys_dev
*device
)
643 struct intel_hba
*result
;
645 for (result
= hba
; result
; result
= result
->next
) {
646 if (result
->type
== device
->type
&& strcmp(result
->path
, device
->path
) == 0)
652 static int attach_hba_to_super(struct intel_super
*super
, struct sys_dev
*device
)
654 struct intel_hba
*hba
;
656 /* check if disk attached to Intel HBA */
657 hba
= find_intel_hba(super
->hba
, device
);
660 /* Check if HBA is already attached to super */
661 if (super
->hba
== NULL
) {
662 super
->hba
= alloc_intel_hba(device
);
667 /* Intel metadata allows for all disks attached to the same type HBA.
668 * Do not support HBA types mixing
670 if (device
->type
!= hba
->type
)
673 /* Multiple same type HBAs can be used if they share the same OROM */
674 const struct imsm_orom
*device_orom
= get_orom_by_device_id(device
->dev_id
);
676 if (device_orom
!= super
->orom
)
682 hba
->next
= alloc_intel_hba(device
);
686 static struct sys_dev
* find_disk_attached_hba(int fd
, const char *devname
)
688 struct sys_dev
*list
, *elem
;
691 if ((list
= find_intel_devices()) == NULL
)
695 disk_path
= (char *) devname
;
697 disk_path
= diskfd_to_devpath(fd
, 1, NULL
);
702 for (elem
= list
; elem
; elem
= elem
->next
)
703 if (path_attached_to_hba(disk_path
, elem
->path
))
706 if (disk_path
!= devname
)
712 static int find_intel_hba_capability(int fd
, struct intel_super
*super
,
715 static struct supertype
*match_metadata_desc_imsm(char *arg
)
717 struct supertype
*st
;
719 if (strcmp(arg
, "imsm") != 0 &&
720 strcmp(arg
, "default") != 0
724 st
= xcalloc(1, sizeof(*st
));
725 st
->ss
= &super_imsm
;
726 st
->max_devs
= IMSM_MAX_DEVICES
;
727 st
->minor_version
= 0;
732 static __u8
*get_imsm_version(struct imsm_super
*mpb
)
734 return &mpb
->sig
[MPB_SIG_LEN
];
737 /* retrieve a disk directly from the anchor when the anchor is known to be
738 * up-to-date, currently only at load time
740 static struct imsm_disk
*__get_imsm_disk(struct imsm_super
*mpb
, __u8 index
)
742 if (index
>= mpb
->num_disks
)
744 return &mpb
->disk
[index
];
747 /* retrieve the disk description based on a index of the disk
750 static struct dl
*get_imsm_dl_disk(struct intel_super
*super
, __u8 index
)
754 for (d
= super
->disks
; d
; d
= d
->next
)
755 if (d
->index
== index
)
760 /* retrieve a disk from the parsed metadata */
761 static struct imsm_disk
*get_imsm_disk(struct intel_super
*super
, __u8 index
)
765 dl
= get_imsm_dl_disk(super
, index
);
772 /* generate a checksum directly from the anchor when the anchor is known to be
773 * up-to-date, currently only at load or write_super after coalescing
775 static __u32
__gen_imsm_checksum(struct imsm_super
*mpb
)
777 __u32 end
= mpb
->mpb_size
/ sizeof(end
);
778 __u32
*p
= (__u32
*) mpb
;
782 sum
+= __le32_to_cpu(*p
);
786 return sum
- __le32_to_cpu(mpb
->check_sum
);
789 static size_t sizeof_imsm_map(struct imsm_map
*map
)
791 return sizeof(struct imsm_map
) + sizeof(__u32
) * (map
->num_members
- 1);
794 struct imsm_map
*get_imsm_map(struct imsm_dev
*dev
, int second_map
)
796 /* A device can have 2 maps if it is in the middle of a migration.
798 * MAP_0 - we return the first map
799 * MAP_1 - we return the second map if it exists, else NULL
800 * MAP_X - we return the second map if it exists, else the first
802 struct imsm_map
*map
= &dev
->vol
.map
[0];
803 struct imsm_map
*map2
= NULL
;
805 if (dev
->vol
.migr_state
)
806 map2
= (void *)map
+ sizeof_imsm_map(map
);
808 switch (second_map
) {
825 /* return the size of the device.
826 * migr_state increases the returned size if map[0] were to be duplicated
828 static size_t sizeof_imsm_dev(struct imsm_dev
*dev
, int migr_state
)
830 size_t size
= sizeof(*dev
) - sizeof(struct imsm_map
) +
831 sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
833 /* migrating means an additional map */
834 if (dev
->vol
.migr_state
)
835 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_1
));
837 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
842 /* retrieve disk serial number list from a metadata update */
843 static struct disk_info
*get_disk_info(struct imsm_update_create_array
*update
)
846 struct disk_info
*inf
;
848 inf
= u
+ sizeof(*update
) - sizeof(struct imsm_dev
) +
849 sizeof_imsm_dev(&update
->dev
, 0);
854 static struct imsm_dev
*__get_imsm_dev(struct imsm_super
*mpb
, __u8 index
)
860 if (index
>= mpb
->num_raid_devs
)
863 /* devices start after all disks */
864 offset
= ((void *) &mpb
->disk
[mpb
->num_disks
]) - _mpb
;
866 for (i
= 0; i
<= index
; i
++)
868 return _mpb
+ offset
;
870 offset
+= sizeof_imsm_dev(_mpb
+ offset
, 0);
875 static struct imsm_dev
*get_imsm_dev(struct intel_super
*super
, __u8 index
)
877 struct intel_dev
*dv
;
879 if (index
>= super
->anchor
->num_raid_devs
)
881 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
882 if (dv
->index
== index
)
887 static inline unsigned long long __le48_to_cpu(const struct bbm_log_block_addr
890 return ((((__u64
)__le32_to_cpu(addr
->dw1
)) << 16) |
891 __le16_to_cpu(addr
->w1
));
894 static inline struct bbm_log_block_addr
__cpu_to_le48(unsigned long long sec
)
896 struct bbm_log_block_addr addr
;
898 addr
.w1
= __cpu_to_le16((__u16
)(sec
& 0xffff));
899 addr
.dw1
= __cpu_to_le32((__u32
)(sec
>> 16) & 0xffffffff);
903 /* get size of the bbm log */
904 static __u32
get_imsm_bbm_log_size(struct bbm_log
*log
)
906 if (!log
|| log
->entry_count
== 0)
909 return sizeof(log
->signature
) +
910 sizeof(log
->entry_count
) +
911 log
->entry_count
* sizeof(struct bbm_log_entry
);
914 /* check if bad block is not partially stored in bbm log */
915 static int is_stored_in_bbm(struct bbm_log
*log
, const __u8 idx
, const unsigned
916 long long sector
, const int length
, __u32
*pos
)
920 for (i
= *pos
; i
< log
->entry_count
; i
++) {
921 struct bbm_log_entry
*entry
= &log
->marked_block_entries
[i
];
922 unsigned long long bb_start
;
923 unsigned long long bb_end
;
925 bb_start
= __le48_to_cpu(&entry
->defective_block_start
);
926 bb_end
= bb_start
+ (entry
->marked_count
+ 1);
928 if ((entry
->disk_ordinal
== idx
) && (bb_start
>= sector
) &&
929 (bb_end
<= sector
+ length
)) {
937 /* record new bad block in bbm log */
938 static int record_new_badblock(struct bbm_log
*log
, const __u8 idx
, unsigned
939 long long sector
, int length
)
943 struct bbm_log_entry
*entry
= NULL
;
945 while (is_stored_in_bbm(log
, idx
, sector
, length
, &pos
)) {
946 struct bbm_log_entry
*e
= &log
->marked_block_entries
[pos
];
948 if ((e
->marked_count
+ 1 == BBM_LOG_MAX_LBA_ENTRY_VAL
) &&
949 (__le48_to_cpu(&e
->defective_block_start
) == sector
)) {
950 sector
+= BBM_LOG_MAX_LBA_ENTRY_VAL
;
951 length
-= BBM_LOG_MAX_LBA_ENTRY_VAL
;
960 int cnt
= (length
<= BBM_LOG_MAX_LBA_ENTRY_VAL
) ? length
:
961 BBM_LOG_MAX_LBA_ENTRY_VAL
;
962 entry
->defective_block_start
= __cpu_to_le48(sector
);
963 entry
->marked_count
= cnt
- 1;
970 new_bb
= ROUND_UP(length
, BBM_LOG_MAX_LBA_ENTRY_VAL
) /
971 BBM_LOG_MAX_LBA_ENTRY_VAL
;
972 if (log
->entry_count
+ new_bb
> BBM_LOG_MAX_ENTRIES
)
976 int cnt
= (length
<= BBM_LOG_MAX_LBA_ENTRY_VAL
) ? length
:
977 BBM_LOG_MAX_LBA_ENTRY_VAL
;
978 struct bbm_log_entry
*entry
=
979 &log
->marked_block_entries
[log
->entry_count
];
981 entry
->defective_block_start
= __cpu_to_le48(sector
);
982 entry
->marked_count
= cnt
- 1;
983 entry
->disk_ordinal
= idx
;
994 /* clear all bad blocks for given disk */
995 static void clear_disk_badblocks(struct bbm_log
*log
, const __u8 idx
)
999 while (i
< log
->entry_count
) {
1000 struct bbm_log_entry
*entries
= log
->marked_block_entries
;
1002 if (entries
[i
].disk_ordinal
== idx
) {
1003 if (i
< log
->entry_count
- 1)
1004 entries
[i
] = entries
[log
->entry_count
- 1];
1012 /* clear given bad block */
1013 static int clear_badblock(struct bbm_log
*log
, const __u8 idx
, const unsigned
1014 long long sector
, const int length
) {
1017 while (i
< log
->entry_count
) {
1018 struct bbm_log_entry
*entries
= log
->marked_block_entries
;
1020 if ((entries
[i
].disk_ordinal
== idx
) &&
1021 (__le48_to_cpu(&entries
[i
].defective_block_start
) ==
1022 sector
) && (entries
[i
].marked_count
+ 1 == length
)) {
1023 if (i
< log
->entry_count
- 1)
1024 entries
[i
] = entries
[log
->entry_count
- 1];
1034 /* allocate and load BBM log from metadata */
1035 static int load_bbm_log(struct intel_super
*super
)
1037 struct imsm_super
*mpb
= super
->anchor
;
1038 __u32 bbm_log_size
= __le32_to_cpu(mpb
->bbm_log_size
);
1040 super
->bbm_log
= xcalloc(1, sizeof(struct bbm_log
));
1041 if (!super
->bbm_log
)
1045 struct bbm_log
*log
= (void *)mpb
+
1046 __le32_to_cpu(mpb
->mpb_size
) - bbm_log_size
;
1050 if (bbm_log_size
< sizeof(log
->signature
) +
1051 sizeof(log
->entry_count
))
1054 entry_count
= __le32_to_cpu(log
->entry_count
);
1055 if ((__le32_to_cpu(log
->signature
) != BBM_LOG_SIGNATURE
) ||
1056 (entry_count
> BBM_LOG_MAX_ENTRIES
))
1060 sizeof(log
->signature
) + sizeof(log
->entry_count
) +
1061 entry_count
* sizeof(struct bbm_log_entry
))
1064 memcpy(super
->bbm_log
, log
, bbm_log_size
);
1066 super
->bbm_log
->signature
= __cpu_to_le32(BBM_LOG_SIGNATURE
);
1067 super
->bbm_log
->entry_count
= 0;
1073 /* checks if bad block is within volume boundaries */
1074 static int is_bad_block_in_volume(const struct bbm_log_entry
*entry
,
1075 const unsigned long long start_sector
,
1076 const unsigned long long size
)
1078 unsigned long long bb_start
;
1079 unsigned long long bb_end
;
1081 bb_start
= __le48_to_cpu(&entry
->defective_block_start
);
1082 bb_end
= bb_start
+ (entry
->marked_count
+ 1);
1084 if (((bb_start
>= start_sector
) && (bb_start
< start_sector
+ size
)) ||
1085 ((bb_end
>= start_sector
) && (bb_end
<= start_sector
+ size
)))
1091 /* get list of bad blocks on a drive for a volume */
1092 static void get_volume_badblocks(const struct bbm_log
*log
, const __u8 idx
,
1093 const unsigned long long start_sector
,
1094 const unsigned long long size
,
1100 for (i
= 0; i
< log
->entry_count
; i
++) {
1101 const struct bbm_log_entry
*ent
=
1102 &log
->marked_block_entries
[i
];
1103 struct md_bb_entry
*bb
;
1105 if ((ent
->disk_ordinal
== idx
) &&
1106 is_bad_block_in_volume(ent
, start_sector
, size
)) {
1108 if (!bbs
->entries
) {
1109 bbs
->entries
= xmalloc(BBM_LOG_MAX_ENTRIES
*
1115 bb
= &bbs
->entries
[count
++];
1116 bb
->sector
= __le48_to_cpu(&ent
->defective_block_start
);
1117 bb
->length
= ent
->marked_count
+ 1;
1125 * == MAP_0 get first map
1126 * == MAP_1 get second map
1127 * == MAP_X than get map according to the current migr_state
1129 static __u32
get_imsm_ord_tbl_ent(struct imsm_dev
*dev
,
1133 struct imsm_map
*map
;
1135 map
= get_imsm_map(dev
, second_map
);
1137 /* top byte identifies disk under rebuild */
1138 return __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
1141 #define ord_to_idx(ord) (((ord) << 8) >> 8)
1142 static __u32
get_imsm_disk_idx(struct imsm_dev
*dev
, int slot
, int second_map
)
1144 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, second_map
);
1146 return ord_to_idx(ord
);
1149 static void set_imsm_ord_tbl_ent(struct imsm_map
*map
, int slot
, __u32 ord
)
1151 map
->disk_ord_tbl
[slot
] = __cpu_to_le32(ord
);
1154 static int get_imsm_disk_slot(struct imsm_map
*map
, unsigned idx
)
1159 for (slot
= 0; slot
< map
->num_members
; slot
++) {
1160 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
1161 if (ord_to_idx(ord
) == idx
)
1168 static int get_imsm_raid_level(struct imsm_map
*map
)
1170 if (map
->raid_level
== 1) {
1171 if (map
->num_members
== 2)
1177 return map
->raid_level
;
1180 static int cmp_extent(const void *av
, const void *bv
)
1182 const struct extent
*a
= av
;
1183 const struct extent
*b
= bv
;
1184 if (a
->start
< b
->start
)
1186 if (a
->start
> b
->start
)
1191 static int count_memberships(struct dl
*dl
, struct intel_super
*super
)
1193 int memberships
= 0;
1196 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1197 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1198 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1200 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
1207 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
);
1209 static int split_ull(unsigned long long n
, void *lo
, void *hi
)
1211 if (lo
== 0 || hi
== 0)
1213 __put_unaligned32(__cpu_to_le32((__u32
)n
), lo
);
1214 __put_unaligned32(__cpu_to_le32((n
>> 32)), hi
);
1218 static unsigned long long join_u32(__u32 lo
, __u32 hi
)
1220 return (unsigned long long)__le32_to_cpu(lo
) |
1221 (((unsigned long long)__le32_to_cpu(hi
)) << 32);
1224 static unsigned long long total_blocks(struct imsm_disk
*disk
)
1228 return join_u32(disk
->total_blocks_lo
, disk
->total_blocks_hi
);
1232 * imsm_num_data_members() - get data drives count for an array.
1233 * @map: Map to analyze.
1235 * num_data_members value represents minimal count of drives for level.
1236 * The name of the property could be misleading for RAID5 with asymmetric layout
1237 * because some data required to be calculated from parity.
1238 * The property is extracted from level and num_members value.
1240 * Return: num_data_members value on success, zero otherwise.
1242 static __u8
imsm_num_data_members(struct imsm_map
*map
)
1244 switch (get_imsm_raid_level(map
)) {
1246 return map
->num_members
;
1249 return map
->num_members
/ 2;
1251 return map
->num_members
- 1;
1253 dprintf("unsupported raid level\n");
1258 static unsigned long long pba_of_lba0(struct imsm_map
*map
)
1262 return join_u32(map
->pba_of_lba0_lo
, map
->pba_of_lba0_hi
);
1265 static unsigned long long blocks_per_member(struct imsm_map
*map
)
1269 return join_u32(map
->blocks_per_member_lo
, map
->blocks_per_member_hi
);
1272 static unsigned long long num_data_stripes(struct imsm_map
*map
)
1276 return join_u32(map
->num_data_stripes_lo
, map
->num_data_stripes_hi
);
1279 static unsigned long long vol_curr_migr_unit(struct imsm_dev
*dev
)
1284 return join_u32(dev
->vol
.curr_migr_unit_lo
, dev
->vol
.curr_migr_unit_hi
);
1287 static unsigned long long imsm_dev_size(struct imsm_dev
*dev
)
1291 return join_u32(dev
->size_low
, dev
->size_high
);
1294 static unsigned long long migr_chkp_area_pba(struct migr_record
*migr_rec
)
1296 if (migr_rec
== NULL
)
1298 return join_u32(migr_rec
->ckpt_area_pba_lo
,
1299 migr_rec
->ckpt_area_pba_hi
);
1302 static unsigned long long current_migr_unit(struct migr_record
*migr_rec
)
1304 if (migr_rec
== NULL
)
1306 return join_u32(migr_rec
->curr_migr_unit_lo
,
1307 migr_rec
->curr_migr_unit_hi
);
1310 static unsigned long long migr_dest_1st_member_lba(struct migr_record
*migr_rec
)
1312 if (migr_rec
== NULL
)
1314 return join_u32(migr_rec
->dest_1st_member_lba_lo
,
1315 migr_rec
->dest_1st_member_lba_hi
);
1318 static unsigned long long get_num_migr_units(struct migr_record
*migr_rec
)
1320 if (migr_rec
== NULL
)
1322 return join_u32(migr_rec
->num_migr_units_lo
,
1323 migr_rec
->num_migr_units_hi
);
1326 static void set_total_blocks(struct imsm_disk
*disk
, unsigned long long n
)
1328 split_ull(n
, &disk
->total_blocks_lo
, &disk
->total_blocks_hi
);
1332 * set_num_domains() - Set number of domains for an array.
1333 * @map: Map to be updated.
1335 * num_domains property represents copies count of each data drive, thus make
1336 * it meaningful only for RAID1 and RAID10. IMSM supports two domains for
1339 static void set_num_domains(struct imsm_map
*map
)
1341 int level
= get_imsm_raid_level(map
);
1343 if (level
== 1 || level
== 10)
1344 map
->num_domains
= 2;
1346 map
->num_domains
= 1;
1349 static void set_pba_of_lba0(struct imsm_map
*map
, unsigned long long n
)
1351 split_ull(n
, &map
->pba_of_lba0_lo
, &map
->pba_of_lba0_hi
);
1354 static void set_blocks_per_member(struct imsm_map
*map
, unsigned long long n
)
1356 split_ull(n
, &map
->blocks_per_member_lo
, &map
->blocks_per_member_hi
);
1359 static void set_num_data_stripes(struct imsm_map
*map
, unsigned long long n
)
1361 split_ull(n
, &map
->num_data_stripes_lo
, &map
->num_data_stripes_hi
);
1365 * update_num_data_stripes() - Calculate and update num_data_stripes value.
1366 * @map: map to be updated.
1367 * @dev_size: size of volume.
1369 * num_data_stripes value is addictionally divided by num_domains, therefore for
1370 * levels where num_domains is not 1, nds is a part of real value.
1372 static void update_num_data_stripes(struct imsm_map
*map
,
1373 unsigned long long dev_size
)
1375 unsigned long long nds
= dev_size
/ imsm_num_data_members(map
);
1377 nds
/= map
->num_domains
;
1378 nds
/= map
->blocks_per_strip
;
1379 set_num_data_stripes(map
, nds
);
1382 static void set_vol_curr_migr_unit(struct imsm_dev
*dev
, unsigned long long n
)
1387 split_ull(n
, &dev
->vol
.curr_migr_unit_lo
, &dev
->vol
.curr_migr_unit_hi
);
1390 static void set_imsm_dev_size(struct imsm_dev
*dev
, unsigned long long n
)
1392 split_ull(n
, &dev
->size_low
, &dev
->size_high
);
1395 static void set_migr_chkp_area_pba(struct migr_record
*migr_rec
,
1396 unsigned long long n
)
1398 split_ull(n
, &migr_rec
->ckpt_area_pba_lo
, &migr_rec
->ckpt_area_pba_hi
);
1401 static void set_current_migr_unit(struct migr_record
*migr_rec
,
1402 unsigned long long n
)
1404 split_ull(n
, &migr_rec
->curr_migr_unit_lo
,
1405 &migr_rec
->curr_migr_unit_hi
);
1408 static void set_migr_dest_1st_member_lba(struct migr_record
*migr_rec
,
1409 unsigned long long n
)
1411 split_ull(n
, &migr_rec
->dest_1st_member_lba_lo
,
1412 &migr_rec
->dest_1st_member_lba_hi
);
1415 static void set_num_migr_units(struct migr_record
*migr_rec
,
1416 unsigned long long n
)
1418 split_ull(n
, &migr_rec
->num_migr_units_lo
,
1419 &migr_rec
->num_migr_units_hi
);
1422 static unsigned long long per_dev_array_size(struct imsm_map
*map
)
1424 unsigned long long array_size
= 0;
1429 array_size
= num_data_stripes(map
) * map
->blocks_per_strip
;
1430 if (get_imsm_raid_level(map
) == 1 || get_imsm_raid_level(map
) == 10)
1436 static struct extent
*get_extents(struct intel_super
*super
, struct dl
*dl
,
1437 int get_minimal_reservation
)
1439 /* find a list of used extents on the given physical device */
1440 struct extent
*rv
, *e
;
1442 int memberships
= count_memberships(dl
, super
);
1445 /* trim the reserved area for spares, so they can join any array
1446 * regardless of whether the OROM has assigned sectors from the
1447 * IMSM_RESERVED_SECTORS region
1449 if (dl
->index
== -1 || get_minimal_reservation
)
1450 reservation
= imsm_min_reserved_sectors(super
);
1452 reservation
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1454 rv
= xcalloc(sizeof(struct extent
), (memberships
+ 1));
1457 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1458 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1459 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1461 if (get_imsm_disk_slot(map
, dl
->index
) >= 0) {
1462 e
->start
= pba_of_lba0(map
);
1463 e
->size
= per_dev_array_size(map
);
1467 qsort(rv
, memberships
, sizeof(*rv
), cmp_extent
);
1469 /* determine the start of the metadata
1470 * when no raid devices are defined use the default
1471 * ...otherwise allow the metadata to truncate the value
1472 * as is the case with older versions of imsm
1475 struct extent
*last
= &rv
[memberships
- 1];
1476 unsigned long long remainder
;
1478 remainder
= total_blocks(&dl
->disk
) - (last
->start
+ last
->size
);
1479 /* round down to 1k block to satisfy precision of the kernel
1483 /* make sure remainder is still sane */
1484 if (remainder
< (unsigned)ROUND_UP(super
->len
, 512) >> 9)
1485 remainder
= ROUND_UP(super
->len
, 512) >> 9;
1486 if (reservation
> remainder
)
1487 reservation
= remainder
;
1489 e
->start
= total_blocks(&dl
->disk
) - reservation
;
1494 /* try to determine how much space is reserved for metadata from
1495 * the last get_extents() entry, otherwise fallback to the
1498 static __u32
imsm_reserved_sectors(struct intel_super
*super
, struct dl
*dl
)
1504 /* for spares just return a minimal reservation which will grow
1505 * once the spare is picked up by an array
1507 if (dl
->index
== -1)
1508 return MPB_SECTOR_CNT
;
1510 e
= get_extents(super
, dl
, 0);
1512 return MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1514 /* scroll to last entry */
1515 for (i
= 0; e
[i
].size
; i
++)
1518 rv
= total_blocks(&dl
->disk
) - e
[i
].start
;
1525 static int is_spare(struct imsm_disk
*disk
)
1527 return (disk
->status
& SPARE_DISK
) == SPARE_DISK
;
1530 static int is_configured(struct imsm_disk
*disk
)
1532 return (disk
->status
& CONFIGURED_DISK
) == CONFIGURED_DISK
;
1535 static int is_failed(struct imsm_disk
*disk
)
1537 return (disk
->status
& FAILED_DISK
) == FAILED_DISK
;
1540 static int is_journal(struct imsm_disk
*disk
)
1542 return (disk
->status
& JOURNAL_DISK
) == JOURNAL_DISK
;
1545 /* round array size down to closest MB and ensure it splits evenly
1548 static unsigned long long round_size_to_mb(unsigned long long size
, unsigned int
1552 size
= (size
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
1558 static int able_to_resync(int raid_level
, int missing_disks
)
1560 int max_missing_disks
= 0;
1562 switch (raid_level
) {
1564 max_missing_disks
= 1;
1567 max_missing_disks
= 0;
1569 return missing_disks
<= max_missing_disks
;
1572 /* try to determine how much space is reserved for metadata from
1573 * the last get_extents() entry on the smallest active disk,
1574 * otherwise fallback to the default
1576 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
)
1580 unsigned long long min_active
;
1582 __u32 rv
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1583 struct dl
*dl
, *dl_min
= NULL
;
1589 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
1592 unsigned long long blocks
= total_blocks(&dl
->disk
);
1593 if (blocks
< min_active
|| min_active
== 0) {
1595 min_active
= blocks
;
1601 /* find last lba used by subarrays on the smallest active disk */
1602 e
= get_extents(super
, dl_min
, 0);
1605 for (i
= 0; e
[i
].size
; i
++)
1608 remainder
= min_active
- e
[i
].start
;
1611 /* to give priority to recovery we should not require full
1612 IMSM_RESERVED_SECTORS from the spare */
1613 rv
= MPB_SECTOR_CNT
+ NUM_BLOCKS_DIRTY_STRIPE_REGION
;
1615 /* if real reservation is smaller use that value */
1616 return (remainder
< rv
) ? remainder
: rv
;
1620 * Return minimum size of a spare and sector size
1621 * that can be used in this array
1623 int get_spare_criteria_imsm(struct supertype
*st
, struct spare_criteria
*c
)
1625 struct intel_super
*super
= st
->sb
;
1629 unsigned long long size
= 0;
1636 /* find first active disk in array */
1638 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
1642 /* find last lba used by subarrays */
1643 e
= get_extents(super
, dl
, 0);
1646 for (i
= 0; e
[i
].size
; i
++)
1649 size
= e
[i
-1].start
+ e
[i
-1].size
;
1652 /* add the amount of space needed for metadata */
1653 size
+= imsm_min_reserved_sectors(super
);
1655 c
->min_size
= size
* 512;
1656 c
->sector_size
= super
->sector_size
;
1661 static int is_gen_migration(struct imsm_dev
*dev
);
1663 #define IMSM_4K_DIV 8
1665 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
1666 struct imsm_dev
*dev
);
1668 static void print_imsm_dev(struct intel_super
*super
,
1669 struct imsm_dev
*dev
,
1675 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1676 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
1680 printf("[%.16s]:\n", dev
->volume
);
1681 printf(" Subarray : %d\n", super
->current_vol
);
1682 printf(" UUID : %s\n", uuid
);
1683 printf(" RAID Level : %d", get_imsm_raid_level(map
));
1685 printf(" <-- %d", get_imsm_raid_level(map2
));
1687 printf(" Members : %d", map
->num_members
);
1689 printf(" <-- %d", map2
->num_members
);
1691 printf(" Slots : [");
1692 for (i
= 0; i
< map
->num_members
; i
++) {
1693 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
1694 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1699 for (i
= 0; i
< map2
->num_members
; i
++) {
1700 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_1
);
1701 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1706 printf(" Failed disk : ");
1707 if (map
->failed_disk_num
== 0xff)
1710 printf("%i", map
->failed_disk_num
);
1712 slot
= get_imsm_disk_slot(map
, disk_idx
);
1714 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
1715 printf(" This Slot : %d%s\n", slot
,
1716 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
1718 printf(" This Slot : ?\n");
1719 printf(" Sector Size : %u\n", super
->sector_size
);
1720 sz
= imsm_dev_size(dev
);
1721 printf(" Array Size : %llu%s\n",
1722 (unsigned long long)sz
* 512 / super
->sector_size
,
1723 human_size(sz
* 512));
1724 sz
= blocks_per_member(map
);
1725 printf(" Per Dev Size : %llu%s\n",
1726 (unsigned long long)sz
* 512 / super
->sector_size
,
1727 human_size(sz
* 512));
1728 printf(" Sector Offset : %llu\n",
1729 pba_of_lba0(map
) * 512 / super
->sector_size
);
1730 printf(" Num Stripes : %llu\n",
1731 num_data_stripes(map
));
1732 printf(" Chunk Size : %u KiB",
1733 __le16_to_cpu(map
->blocks_per_strip
) / 2);
1735 printf(" <-- %u KiB",
1736 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
1738 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
1739 printf(" Migrate State : ");
1740 if (dev
->vol
.migr_state
) {
1741 if (migr_type(dev
) == MIGR_INIT
)
1742 printf("initialize\n");
1743 else if (migr_type(dev
) == MIGR_REBUILD
)
1744 printf("rebuild\n");
1745 else if (migr_type(dev
) == MIGR_VERIFY
)
1747 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
1748 printf("general migration\n");
1749 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
1750 printf("state change\n");
1751 else if (migr_type(dev
) == MIGR_REPAIR
)
1754 printf("<unknown:%d>\n", migr_type(dev
));
1757 printf(" Map State : %s", map_state_str
[map
->map_state
]);
1758 if (dev
->vol
.migr_state
) {
1759 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
1761 printf(" <-- %s", map_state_str
[map
->map_state
]);
1762 printf("\n Checkpoint : %llu ", vol_curr_migr_unit(dev
));
1763 if (is_gen_migration(dev
) && (slot
> 1 || slot
< 0))
1766 printf("(%llu)", (unsigned long long)
1767 blocks_per_migr_unit(super
, dev
));
1770 printf(" Dirty State : %s\n", (dev
->vol
.dirty
& RAIDVOL_DIRTY
) ?
1772 printf(" RWH Policy : ");
1773 if (dev
->rwh_policy
== RWH_OFF
|| dev
->rwh_policy
== RWH_MULTIPLE_OFF
)
1775 else if (dev
->rwh_policy
== RWH_DISTRIBUTED
)
1776 printf("PPL distributed\n");
1777 else if (dev
->rwh_policy
== RWH_JOURNALING_DRIVE
)
1778 printf("PPL journaling drive\n");
1779 else if (dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)
1780 printf("Multiple distributed PPLs\n");
1781 else if (dev
->rwh_policy
== RWH_MULTIPLE_PPLS_JOURNALING_DRIVE
)
1782 printf("Multiple PPLs on journaling drive\n");
1783 else if (dev
->rwh_policy
== RWH_BITMAP
)
1784 printf("Write-intent bitmap\n");
1786 printf("<unknown:%d>\n", dev
->rwh_policy
);
1788 printf(" Volume ID : %u\n", dev
->my_vol_raid_dev_num
);
1791 static void print_imsm_disk(struct imsm_disk
*disk
,
1794 unsigned int sector_size
) {
1795 char str
[MAX_RAID_SERIAL_LEN
+ 1];
1798 if (index
< -1 || !disk
)
1802 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
1804 printf(" Disk%02d Serial : %s\n", index
, str
);
1806 printf(" Disk Serial : %s\n", str
);
1807 printf(" State :%s%s%s%s\n", is_spare(disk
) ? " spare" : "",
1808 is_configured(disk
) ? " active" : "",
1809 is_failed(disk
) ? " failed" : "",
1810 is_journal(disk
) ? " journal" : "");
1811 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
1812 sz
= total_blocks(disk
) - reserved
;
1813 printf(" Usable Size : %llu%s\n",
1814 (unsigned long long)sz
* 512 / sector_size
,
1815 human_size(sz
* 512));
1818 void convert_to_4k_imsm_migr_rec(struct intel_super
*super
)
1820 struct migr_record
*migr_rec
= super
->migr_rec
;
1822 migr_rec
->blocks_per_unit
/= IMSM_4K_DIV
;
1823 migr_rec
->dest_depth_per_unit
/= IMSM_4K_DIV
;
1824 split_ull((join_u32(migr_rec
->post_migr_vol_cap
,
1825 migr_rec
->post_migr_vol_cap_hi
) / IMSM_4K_DIV
),
1826 &migr_rec
->post_migr_vol_cap
, &migr_rec
->post_migr_vol_cap_hi
);
1827 set_migr_chkp_area_pba(migr_rec
,
1828 migr_chkp_area_pba(migr_rec
) / IMSM_4K_DIV
);
1829 set_migr_dest_1st_member_lba(migr_rec
,
1830 migr_dest_1st_member_lba(migr_rec
) / IMSM_4K_DIV
);
1833 void convert_to_4k_imsm_disk(struct imsm_disk
*disk
)
1835 set_total_blocks(disk
, (total_blocks(disk
)/IMSM_4K_DIV
));
1838 void convert_to_4k(struct intel_super
*super
)
1840 struct imsm_super
*mpb
= super
->anchor
;
1841 struct imsm_disk
*disk
;
1843 __u32 bbm_log_size
= __le32_to_cpu(mpb
->bbm_log_size
);
1845 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1846 disk
= __get_imsm_disk(mpb
, i
);
1848 convert_to_4k_imsm_disk(disk
);
1850 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1851 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1852 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1854 set_imsm_dev_size(dev
, imsm_dev_size(dev
)/IMSM_4K_DIV
);
1855 set_vol_curr_migr_unit(dev
,
1856 vol_curr_migr_unit(dev
) / IMSM_4K_DIV
);
1859 set_blocks_per_member(map
, blocks_per_member(map
)/IMSM_4K_DIV
);
1860 map
->blocks_per_strip
/= IMSM_4K_DIV
;
1861 set_pba_of_lba0(map
, pba_of_lba0(map
)/IMSM_4K_DIV
);
1863 if (dev
->vol
.migr_state
) {
1865 map
= get_imsm_map(dev
, MAP_1
);
1866 set_blocks_per_member(map
,
1867 blocks_per_member(map
)/IMSM_4K_DIV
);
1868 map
->blocks_per_strip
/= IMSM_4K_DIV
;
1869 set_pba_of_lba0(map
, pba_of_lba0(map
)/IMSM_4K_DIV
);
1873 struct bbm_log
*log
= (void *)mpb
+
1874 __le32_to_cpu(mpb
->mpb_size
) - bbm_log_size
;
1877 for (i
= 0; i
< log
->entry_count
; i
++) {
1878 struct bbm_log_entry
*entry
=
1879 &log
->marked_block_entries
[i
];
1881 __u8 count
= entry
->marked_count
+ 1;
1882 unsigned long long sector
=
1883 __le48_to_cpu(&entry
->defective_block_start
);
1885 entry
->defective_block_start
=
1886 __cpu_to_le48(sector
/IMSM_4K_DIV
);
1887 entry
->marked_count
= max(count
/IMSM_4K_DIV
, 1) - 1;
1891 mpb
->check_sum
= __gen_imsm_checksum(mpb
);
1894 void examine_migr_rec_imsm(struct intel_super
*super
)
1896 struct migr_record
*migr_rec
= super
->migr_rec
;
1897 struct imsm_super
*mpb
= super
->anchor
;
1900 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1901 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1902 struct imsm_map
*map
;
1905 if (is_gen_migration(dev
) == 0)
1908 printf("\nMigration Record Information:");
1910 /* first map under migration */
1911 map
= get_imsm_map(dev
, MAP_0
);
1913 slot
= get_imsm_disk_slot(map
, super
->disks
->index
);
1914 if (map
== NULL
|| slot
> 1 || slot
< 0) {
1915 printf(" Empty\n ");
1916 printf("Examine one of first two disks in array\n");
1919 printf("\n Status : ");
1920 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
1923 printf("Contains Data\n");
1924 printf(" Current Unit : %llu\n",
1925 current_migr_unit(migr_rec
));
1926 printf(" Family : %u\n",
1927 __le32_to_cpu(migr_rec
->family_num
));
1928 printf(" Ascending : %u\n",
1929 __le32_to_cpu(migr_rec
->ascending_migr
));
1930 printf(" Blocks Per Unit : %u\n",
1931 __le32_to_cpu(migr_rec
->blocks_per_unit
));
1932 printf(" Dest. Depth Per Unit : %u\n",
1933 __le32_to_cpu(migr_rec
->dest_depth_per_unit
));
1934 printf(" Checkpoint Area pba : %llu\n",
1935 migr_chkp_area_pba(migr_rec
));
1936 printf(" First member lba : %llu\n",
1937 migr_dest_1st_member_lba(migr_rec
));
1938 printf(" Total Number of Units : %llu\n",
1939 get_num_migr_units(migr_rec
));
1940 printf(" Size of volume : %llu\n",
1941 join_u32(migr_rec
->post_migr_vol_cap
,
1942 migr_rec
->post_migr_vol_cap_hi
));
1943 printf(" Record was read from : %u\n",
1944 __le32_to_cpu(migr_rec
->ckpt_read_disk_num
));
1950 void convert_from_4k_imsm_migr_rec(struct intel_super
*super
)
1952 struct migr_record
*migr_rec
= super
->migr_rec
;
1954 migr_rec
->blocks_per_unit
*= IMSM_4K_DIV
;
1955 migr_rec
->dest_depth_per_unit
*= IMSM_4K_DIV
;
1956 split_ull((join_u32(migr_rec
->post_migr_vol_cap
,
1957 migr_rec
->post_migr_vol_cap_hi
) * IMSM_4K_DIV
),
1958 &migr_rec
->post_migr_vol_cap
,
1959 &migr_rec
->post_migr_vol_cap_hi
);
1960 set_migr_chkp_area_pba(migr_rec
,
1961 migr_chkp_area_pba(migr_rec
) * IMSM_4K_DIV
);
1962 set_migr_dest_1st_member_lba(migr_rec
,
1963 migr_dest_1st_member_lba(migr_rec
) * IMSM_4K_DIV
);
1966 void convert_from_4k(struct intel_super
*super
)
1968 struct imsm_super
*mpb
= super
->anchor
;
1969 struct imsm_disk
*disk
;
1971 __u32 bbm_log_size
= __le32_to_cpu(mpb
->bbm_log_size
);
1973 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1974 disk
= __get_imsm_disk(mpb
, i
);
1976 set_total_blocks(disk
, (total_blocks(disk
)*IMSM_4K_DIV
));
1979 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1980 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1981 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1983 set_imsm_dev_size(dev
, imsm_dev_size(dev
)*IMSM_4K_DIV
);
1984 set_vol_curr_migr_unit(dev
,
1985 vol_curr_migr_unit(dev
) * IMSM_4K_DIV
);
1988 set_blocks_per_member(map
, blocks_per_member(map
)*IMSM_4K_DIV
);
1989 map
->blocks_per_strip
*= IMSM_4K_DIV
;
1990 set_pba_of_lba0(map
, pba_of_lba0(map
)*IMSM_4K_DIV
);
1992 if (dev
->vol
.migr_state
) {
1994 map
= get_imsm_map(dev
, MAP_1
);
1995 set_blocks_per_member(map
,
1996 blocks_per_member(map
)*IMSM_4K_DIV
);
1997 map
->blocks_per_strip
*= IMSM_4K_DIV
;
1998 set_pba_of_lba0(map
, pba_of_lba0(map
)*IMSM_4K_DIV
);
2002 struct bbm_log
*log
= (void *)mpb
+
2003 __le32_to_cpu(mpb
->mpb_size
) - bbm_log_size
;
2006 for (i
= 0; i
< log
->entry_count
; i
++) {
2007 struct bbm_log_entry
*entry
=
2008 &log
->marked_block_entries
[i
];
2010 __u8 count
= entry
->marked_count
+ 1;
2011 unsigned long long sector
=
2012 __le48_to_cpu(&entry
->defective_block_start
);
2014 entry
->defective_block_start
=
2015 __cpu_to_le48(sector
*IMSM_4K_DIV
);
2016 entry
->marked_count
= count
*IMSM_4K_DIV
- 1;
2020 mpb
->check_sum
= __gen_imsm_checksum(mpb
);
2023 /*******************************************************************************
2024 * function: imsm_check_attributes
2025 * Description: Function checks if features represented by attributes flags
2026 * are supported by mdadm.
2028 * attributes - Attributes read from metadata
2030 * 0 - passed attributes contains unsupported features flags
2031 * 1 - all features are supported
2032 ******************************************************************************/
2033 static int imsm_check_attributes(__u32 attributes
)
2036 __u32 not_supported
= MPB_ATTRIB_SUPPORTED
^0xffffffff;
2038 not_supported
&= ~MPB_ATTRIB_IGNORED
;
2040 not_supported
&= attributes
;
2041 if (not_supported
) {
2042 pr_err("(IMSM): Unsupported attributes : %x\n",
2043 (unsigned)__le32_to_cpu(not_supported
));
2044 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
2045 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY \n");
2046 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
2048 if (not_supported
& MPB_ATTRIB_2TB
) {
2049 dprintf("\t\tMPB_ATTRIB_2TB\n");
2050 not_supported
^= MPB_ATTRIB_2TB
;
2052 if (not_supported
& MPB_ATTRIB_RAID0
) {
2053 dprintf("\t\tMPB_ATTRIB_RAID0\n");
2054 not_supported
^= MPB_ATTRIB_RAID0
;
2056 if (not_supported
& MPB_ATTRIB_RAID1
) {
2057 dprintf("\t\tMPB_ATTRIB_RAID1\n");
2058 not_supported
^= MPB_ATTRIB_RAID1
;
2060 if (not_supported
& MPB_ATTRIB_RAID10
) {
2061 dprintf("\t\tMPB_ATTRIB_RAID10\n");
2062 not_supported
^= MPB_ATTRIB_RAID10
;
2064 if (not_supported
& MPB_ATTRIB_RAID1E
) {
2065 dprintf("\t\tMPB_ATTRIB_RAID1E\n");
2066 not_supported
^= MPB_ATTRIB_RAID1E
;
2068 if (not_supported
& MPB_ATTRIB_RAID5
) {
2069 dprintf("\t\tMPB_ATTRIB_RAID5\n");
2070 not_supported
^= MPB_ATTRIB_RAID5
;
2072 if (not_supported
& MPB_ATTRIB_RAIDCNG
) {
2073 dprintf("\t\tMPB_ATTRIB_RAIDCNG\n");
2074 not_supported
^= MPB_ATTRIB_RAIDCNG
;
2076 if (not_supported
& MPB_ATTRIB_BBM
) {
2077 dprintf("\t\tMPB_ATTRIB_BBM\n");
2078 not_supported
^= MPB_ATTRIB_BBM
;
2080 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
2081 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY (== MPB_ATTRIB_LEGACY)\n");
2082 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
2084 if (not_supported
& MPB_ATTRIB_EXP_STRIPE_SIZE
) {
2085 dprintf("\t\tMPB_ATTRIB_EXP_STRIP_SIZE\n");
2086 not_supported
^= MPB_ATTRIB_EXP_STRIPE_SIZE
;
2088 if (not_supported
& MPB_ATTRIB_2TB_DISK
) {
2089 dprintf("\t\tMPB_ATTRIB_2TB_DISK\n");
2090 not_supported
^= MPB_ATTRIB_2TB_DISK
;
2092 if (not_supported
& MPB_ATTRIB_NEVER_USE2
) {
2093 dprintf("\t\tMPB_ATTRIB_NEVER_USE2\n");
2094 not_supported
^= MPB_ATTRIB_NEVER_USE2
;
2096 if (not_supported
& MPB_ATTRIB_NEVER_USE
) {
2097 dprintf("\t\tMPB_ATTRIB_NEVER_USE\n");
2098 not_supported
^= MPB_ATTRIB_NEVER_USE
;
2102 dprintf("(IMSM): Unknown attributes : %x\n", not_supported
);
2110 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
2112 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
2114 struct intel_super
*super
= st
->sb
;
2115 struct imsm_super
*mpb
= super
->anchor
;
2116 char str
[MAX_SIGNATURE_LENGTH
];
2121 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
2123 time_t creation_time
;
2125 strncpy(str
, (char *)mpb
->sig
, MPB_SIG_LEN
);
2126 str
[MPB_SIG_LEN
-1] = '\0';
2127 printf(" Magic : %s\n", str
);
2128 printf(" Version : %s\n", get_imsm_version(mpb
));
2129 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
2130 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
2131 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
2132 creation_time
= __le64_to_cpu(mpb
->creation_time
);
2133 printf(" Creation Time : %.24s\n",
2134 creation_time
? ctime(&creation_time
) : "Unknown");
2135 printf(" Attributes : ");
2136 if (imsm_check_attributes(mpb
->attributes
))
2137 printf("All supported\n");
2139 printf("not supported\n");
2140 getinfo_super_imsm(st
, &info
, NULL
);
2141 fname_from_uuid(st
, &info
, nbuf
, ':');
2142 printf(" UUID : %s\n", nbuf
+ 5);
2143 sum
= __le32_to_cpu(mpb
->check_sum
);
2144 printf(" Checksum : %08x %s\n", sum
,
2145 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
2146 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
, super
->sector_size
));
2147 printf(" Disks : %d\n", mpb
->num_disks
);
2148 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
2149 print_imsm_disk(__get_imsm_disk(mpb
, super
->disks
->index
),
2150 super
->disks
->index
, reserved
, super
->sector_size
);
2151 if (get_imsm_bbm_log_size(super
->bbm_log
)) {
2152 struct bbm_log
*log
= super
->bbm_log
;
2155 printf("Bad Block Management Log:\n");
2156 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
2157 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
2158 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
2160 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
2162 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
2164 super
->current_vol
= i
;
2165 getinfo_super_imsm(st
, &info
, NULL
);
2166 fname_from_uuid(st
, &info
, nbuf
, ':');
2167 print_imsm_dev(super
, dev
, nbuf
+ 5, super
->disks
->index
);
2169 for (i
= 0; i
< mpb
->num_disks
; i
++) {
2170 if (i
== super
->disks
->index
)
2172 print_imsm_disk(__get_imsm_disk(mpb
, i
), i
, reserved
,
2173 super
->sector_size
);
2176 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
2177 if (dl
->index
== -1)
2178 print_imsm_disk(&dl
->disk
, -1, reserved
,
2179 super
->sector_size
);
2181 examine_migr_rec_imsm(super
);
2184 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
2186 /* We just write a generic IMSM ARRAY entry */
2190 getinfo_super_imsm(st
, &info
, NULL
);
2191 fname_from_uuid(st
, &info
, nbuf
, ':');
2192 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
2195 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
2197 /* We just write a generic IMSM ARRAY entry */
2201 struct intel_super
*super
= st
->sb
;
2204 if (!super
->anchor
->num_raid_devs
)
2207 getinfo_super_imsm(st
, &info
, NULL
);
2208 fname_from_uuid(st
, &info
, nbuf
, ':');
2209 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
2210 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
2212 super
->current_vol
= i
;
2213 getinfo_super_imsm(st
, &info
, NULL
);
2214 fname_from_uuid(st
, &info
, nbuf1
, ':');
2215 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
2216 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
2220 static void export_examine_super_imsm(struct supertype
*st
)
2222 struct intel_super
*super
= st
->sb
;
2223 struct imsm_super
*mpb
= super
->anchor
;
2227 getinfo_super_imsm(st
, &info
, NULL
);
2228 fname_from_uuid(st
, &info
, nbuf
, ':');
2229 printf("MD_METADATA=imsm\n");
2230 printf("MD_LEVEL=container\n");
2231 printf("MD_UUID=%s\n", nbuf
+5);
2232 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
2233 printf("MD_CREATION_TIME=%llu\n", __le64_to_cpu(mpb
->creation_time
));
2236 static void detail_super_imsm(struct supertype
*st
, char *homehost
,
2241 struct intel_super
*super
= st
->sb
;
2242 int temp_vol
= super
->current_vol
;
2245 super
->current_vol
= strtoul(subarray
, NULL
, 10);
2247 getinfo_super_imsm(st
, &info
, NULL
);
2248 fname_from_uuid(st
, &info
, nbuf
, ':');
2249 printf("\n UUID : %s\n", nbuf
+ 5);
2251 super
->current_vol
= temp_vol
;
2254 static void brief_detail_super_imsm(struct supertype
*st
, char *subarray
)
2258 struct intel_super
*super
= st
->sb
;
2259 int temp_vol
= super
->current_vol
;
2262 super
->current_vol
= strtoul(subarray
, NULL
, 10);
2264 getinfo_super_imsm(st
, &info
, NULL
);
2265 fname_from_uuid(st
, &info
, nbuf
, ':');
2266 printf(" UUID=%s", nbuf
+ 5);
2268 super
->current_vol
= temp_vol
;
2271 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
,
2272 size_t serial_buf_len
);
2273 static void fd2devname(int fd
, char *name
);
2275 static int ahci_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
2277 /* dump an unsorted list of devices attached to AHCI Intel storage
2278 * controller, as well as non-connected ports
2280 int hba_len
= strlen(hba_path
) + 1;
2285 unsigned long port_mask
= (1 << port_count
) - 1;
2287 if (port_count
> (int)sizeof(port_mask
) * 8) {
2289 pr_err("port_count %d out of range\n", port_count
);
2293 /* scroll through /sys/dev/block looking for devices attached to
2296 dir
= opendir("/sys/dev/block");
2300 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2306 char device
[PATH_MAX
];
2311 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
2313 path
= devt_to_devpath(makedev(major
, minor
), 1, NULL
);
2316 if (!path_attached_to_hba(path
, hba_path
)) {
2322 /* retrieve the scsi device */
2323 if (!devt_to_devpath(makedev(major
, minor
), 1, device
)) {
2325 pr_err("failed to get device\n");
2329 if (devpath_to_char(device
, "type", buf
, sizeof(buf
), 0)) {
2333 type
= strtoul(buf
, NULL
, 10);
2335 /* if it's not a disk print the vendor and model */
2336 if (!(type
== 0 || type
== 7 || type
== 14)) {
2340 if (devpath_to_char(device
, "vendor", buf
,
2341 sizeof(buf
), 0) == 0) {
2342 strncpy(vendor
, buf
, sizeof(vendor
));
2343 vendor
[sizeof(vendor
) - 1] = '\0';
2344 c
= (char *) &vendor
[sizeof(vendor
) - 1];
2345 while (isspace(*c
) || *c
== '\0')
2350 if (devpath_to_char(device
, "model", buf
,
2351 sizeof(buf
), 0) == 0) {
2352 strncpy(model
, buf
, sizeof(model
));
2353 model
[sizeof(model
) - 1] = '\0';
2354 c
= (char *) &model
[sizeof(model
) - 1];
2355 while (isspace(*c
) || *c
== '\0')
2359 if (vendor
[0] && model
[0])
2360 sprintf(buf
, "%.64s %.64s", vendor
, model
);
2362 switch (type
) { /* numbers from hald/linux/device.c */
2363 case 1: sprintf(buf
, "tape"); break;
2364 case 2: sprintf(buf
, "printer"); break;
2365 case 3: sprintf(buf
, "processor"); break;
2367 case 5: sprintf(buf
, "cdrom"); break;
2368 case 6: sprintf(buf
, "scanner"); break;
2369 case 8: sprintf(buf
, "media_changer"); break;
2370 case 9: sprintf(buf
, "comm"); break;
2371 case 12: sprintf(buf
, "raid"); break;
2372 default: sprintf(buf
, "unknown");
2377 /* chop device path to 'host%d' and calculate the port number */
2378 c
= strchr(&path
[hba_len
], '/');
2381 pr_err("%s - invalid path name\n", path
+ hba_len
);
2386 if ((sscanf(&path
[hba_len
], "ata%d", &port
) == 1) ||
2387 ((sscanf(&path
[hba_len
], "host%d", &port
) == 1)))
2391 *c
= '/'; /* repair the full string */
2392 pr_err("failed to determine port number for %s\n",
2399 /* mark this port as used */
2400 port_mask
&= ~(1 << port
);
2402 /* print out the device information */
2404 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
2408 fd
= dev_open(ent
->d_name
, O_RDONLY
);
2410 printf(" Port%d : - disk info unavailable -\n", port
);
2412 fd2devname(fd
, buf
);
2413 printf(" Port%d : %s", port
, buf
);
2414 if (imsm_read_serial(fd
, NULL
, (__u8
*)buf
,
2416 printf(" (%s)\n", buf
);
2431 for (i
= 0; i
< port_count
; i
++)
2432 if (port_mask
& (1 << i
))
2433 printf(" Port%d : - no device attached -\n", i
);
2439 static int print_nvme_info(struct sys_dev
*hba
)
2444 dir
= opendir("/sys/block/");
2448 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2449 char ns_path
[PATH_MAX
];
2450 char cntrl_path
[PATH_MAX
];
2454 if (!strstr(ent
->d_name
, "nvme"))
2457 fd
= open_dev(ent
->d_name
);
2461 if (!diskfd_to_devpath(fd
, 0, ns_path
) ||
2462 !diskfd_to_devpath(fd
, 1, cntrl_path
))
2465 if (!path_attached_to_hba(cntrl_path
, hba
->path
))
2468 if (!imsm_is_nvme_namespace_supported(fd
, 0))
2471 fd2devname(fd
, buf
);
2472 if (hba
->type
== SYS_DEV_VMD
)
2473 printf(" NVMe under VMD : %s", buf
);
2474 else if (hba
->type
== SYS_DEV_NVME
)
2475 printf(" NVMe Device : %s", buf
);
2477 if (!imsm_read_serial(fd
, NULL
, (__u8
*)buf
,
2479 printf(" (%s)\n", buf
);
2492 static void print_found_intel_controllers(struct sys_dev
*elem
)
2494 for (; elem
; elem
= elem
->next
) {
2495 pr_err("found Intel(R) ");
2496 if (elem
->type
== SYS_DEV_SATA
)
2497 fprintf(stderr
, "SATA ");
2498 else if (elem
->type
== SYS_DEV_SAS
)
2499 fprintf(stderr
, "SAS ");
2500 else if (elem
->type
== SYS_DEV_NVME
)
2501 fprintf(stderr
, "NVMe ");
2503 if (elem
->type
== SYS_DEV_VMD
)
2504 fprintf(stderr
, "VMD domain");
2506 fprintf(stderr
, "RAID controller");
2509 fprintf(stderr
, " at %s", elem
->pci_id
);
2510 fprintf(stderr
, ".\n");
2515 static int ahci_get_port_count(const char *hba_path
, int *port_count
)
2522 if ((dir
= opendir(hba_path
)) == NULL
)
2525 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2528 if ((sscanf(ent
->d_name
, "ata%d", &host
) != 1) &&
2529 ((sscanf(ent
->d_name
, "host%d", &host
) != 1)))
2531 if (*port_count
== 0)
2533 else if (host
< host_base
)
2536 if (host
+ 1 > *port_count
+ host_base
)
2537 *port_count
= host
+ 1 - host_base
;
2543 static void print_imsm_capability(const struct imsm_orom
*orom
)
2545 printf(" Platform : Intel(R) ");
2546 if (orom
->capabilities
== 0 && orom
->driver_features
== 0)
2547 printf("Matrix Storage Manager\n");
2548 else if (imsm_orom_is_enterprise(orom
) && orom
->major_ver
>= 6)
2549 printf("Virtual RAID on CPU\n");
2551 printf("Rapid Storage Technology%s\n",
2552 imsm_orom_is_enterprise(orom
) ? " enterprise" : "");
2553 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
2554 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
,
2555 orom
->minor_ver
, orom
->hotfix_ver
, orom
->build
);
2556 printf(" RAID Levels :%s%s%s%s%s\n",
2557 imsm_orom_has_raid0(orom
) ? " raid0" : "",
2558 imsm_orom_has_raid1(orom
) ? " raid1" : "",
2559 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
2560 imsm_orom_has_raid10(orom
) ? " raid10" : "",
2561 imsm_orom_has_raid5(orom
) ? " raid5" : "");
2562 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2563 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
2564 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
2565 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
2566 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
2567 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
2568 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
2569 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
2570 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
2571 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
2572 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
2573 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
2574 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
2575 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
2576 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
2577 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
2578 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
2579 printf(" 2TB volumes :%s supported\n",
2580 (orom
->attr
& IMSM_OROM_ATTR_2TB
)?"":" not");
2581 printf(" 2TB disks :%s supported\n",
2582 (orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
)?"":" not");
2583 printf(" Max Disks : %d\n", orom
->tds
);
2584 printf(" Max Volumes : %d per array, %d per %s\n",
2585 orom
->vpa
, orom
->vphba
,
2586 imsm_orom_is_nvme(orom
) ? "platform" : "controller");
2590 static void print_imsm_capability_export(const struct imsm_orom
*orom
)
2592 printf("MD_FIRMWARE_TYPE=imsm\n");
2593 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
2594 printf("IMSM_VERSION=%d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
2595 orom
->hotfix_ver
, orom
->build
);
2596 printf("IMSM_SUPPORTED_RAID_LEVELS=%s%s%s%s%s\n",
2597 imsm_orom_has_raid0(orom
) ? "raid0 " : "",
2598 imsm_orom_has_raid1(orom
) ? "raid1 " : "",
2599 imsm_orom_has_raid1e(orom
) ? "raid1e " : "",
2600 imsm_orom_has_raid5(orom
) ? "raid10 " : "",
2601 imsm_orom_has_raid10(orom
) ? "raid5 " : "");
2602 printf("IMSM_SUPPORTED_CHUNK_SIZES=%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2603 imsm_orom_has_chunk(orom
, 2) ? "2k " : "",
2604 imsm_orom_has_chunk(orom
, 4) ? "4k " : "",
2605 imsm_orom_has_chunk(orom
, 8) ? "8k " : "",
2606 imsm_orom_has_chunk(orom
, 16) ? "16k " : "",
2607 imsm_orom_has_chunk(orom
, 32) ? "32k " : "",
2608 imsm_orom_has_chunk(orom
, 64) ? "64k " : "",
2609 imsm_orom_has_chunk(orom
, 128) ? "128k " : "",
2610 imsm_orom_has_chunk(orom
, 256) ? "256k " : "",
2611 imsm_orom_has_chunk(orom
, 512) ? "512k " : "",
2612 imsm_orom_has_chunk(orom
, 1024*1) ? "1M " : "",
2613 imsm_orom_has_chunk(orom
, 1024*2) ? "2M " : "",
2614 imsm_orom_has_chunk(orom
, 1024*4) ? "4M " : "",
2615 imsm_orom_has_chunk(orom
, 1024*8) ? "8M " : "",
2616 imsm_orom_has_chunk(orom
, 1024*16) ? "16M " : "",
2617 imsm_orom_has_chunk(orom
, 1024*32) ? "32M " : "",
2618 imsm_orom_has_chunk(orom
, 1024*64) ? "64M " : "");
2619 printf("IMSM_2TB_VOLUMES=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB
) ? "yes" : "no");
2620 printf("IMSM_2TB_DISKS=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) ? "yes" : "no");
2621 printf("IMSM_MAX_DISKS=%d\n",orom
->tds
);
2622 printf("IMSM_MAX_VOLUMES_PER_ARRAY=%d\n",orom
->vpa
);
2623 printf("IMSM_MAX_VOLUMES_PER_CONTROLLER=%d\n",orom
->vphba
);
2626 static int detail_platform_imsm(int verbose
, int enumerate_only
, char *controller_path
)
2628 /* There are two components to imsm platform support, the ahci SATA
2629 * controller and the option-rom. To find the SATA controller we
2630 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
2631 * controller with the Intel vendor id is present. This approach
2632 * allows mdadm to leverage the kernel's ahci detection logic, with the
2633 * caveat that if ahci.ko is not loaded mdadm will not be able to
2634 * detect platform raid capabilities. The option-rom resides in a
2635 * platform "Adapter ROM". We scan for its signature to retrieve the
2636 * platform capabilities. If raid support is disabled in the BIOS the
2637 * option-rom capability structure will not be available.
2639 struct sys_dev
*list
, *hba
;
2644 if (enumerate_only
) {
2645 if (check_env("IMSM_NO_PLATFORM"))
2647 list
= find_intel_devices();
2650 for (hba
= list
; hba
; hba
= hba
->next
) {
2651 if (find_imsm_capability(hba
)) {
2661 list
= find_intel_devices();
2664 pr_err("no active Intel(R) RAID controller found.\n");
2666 } else if (verbose
> 0)
2667 print_found_intel_controllers(list
);
2669 for (hba
= list
; hba
; hba
= hba
->next
) {
2670 if (controller_path
&& (compare_paths(hba
->path
, controller_path
) != 0))
2672 if (!find_imsm_capability(hba
)) {
2674 pr_err("imsm capabilities not found for controller: %s (type %s)\n",
2675 hba
->type
== SYS_DEV_VMD
? vmd_domain_to_controller(hba
, buf
) : hba
->path
,
2676 get_sys_dev_type(hba
->type
));
2682 if (controller_path
&& result
== 1) {
2683 pr_err("no active Intel(R) RAID controller found under %s\n",
2688 const struct orom_entry
*entry
;
2690 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
2691 if (entry
->type
== SYS_DEV_VMD
) {
2692 print_imsm_capability(&entry
->orom
);
2693 printf(" 3rd party NVMe :%s supported\n",
2694 imsm_orom_has_tpv_support(&entry
->orom
)?"":" not");
2695 for (hba
= list
; hba
; hba
= hba
->next
) {
2696 if (hba
->type
== SYS_DEV_VMD
) {
2698 printf(" I/O Controller : %s (%s)\n",
2699 vmd_domain_to_controller(hba
, buf
), get_sys_dev_type(hba
->type
));
2700 if (print_nvme_info(hba
)) {
2702 pr_err("failed to get devices attached to VMD domain.\n");
2711 print_imsm_capability(&entry
->orom
);
2712 if (entry
->type
== SYS_DEV_NVME
) {
2713 for (hba
= list
; hba
; hba
= hba
->next
) {
2714 if (hba
->type
== SYS_DEV_NVME
)
2715 print_nvme_info(hba
);
2721 struct devid_list
*devid
;
2722 for (devid
= entry
->devid_list
; devid
; devid
= devid
->next
) {
2723 hba
= device_by_id(devid
->devid
);
2727 printf(" I/O Controller : %s (%s)\n",
2728 hba
->path
, get_sys_dev_type(hba
->type
));
2729 if (hba
->type
== SYS_DEV_SATA
) {
2730 host_base
= ahci_get_port_count(hba
->path
, &port_count
);
2731 if (ahci_enumerate_ports(hba
->path
, port_count
, host_base
, verbose
)) {
2733 pr_err("failed to enumerate ports on SATA controller at %s.\n", hba
->pci_id
);
2744 static int export_detail_platform_imsm(int verbose
, char *controller_path
)
2746 struct sys_dev
*list
, *hba
;
2749 list
= find_intel_devices();
2752 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_INTEL_DEVICES\n");
2757 for (hba
= list
; hba
; hba
= hba
->next
) {
2758 if (controller_path
&& (compare_paths(hba
->path
,controller_path
) != 0))
2760 if (!find_imsm_capability(hba
) && verbose
> 0) {
2762 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_IMSM_CAPABLE_DEVICE_UNDER_%s\n",
2763 hba
->type
== SYS_DEV_VMD
? vmd_domain_to_controller(hba
, buf
) : hba
->path
);
2769 const struct orom_entry
*entry
;
2771 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
2772 if (entry
->type
== SYS_DEV_VMD
) {
2773 for (hba
= list
; hba
; hba
= hba
->next
)
2774 print_imsm_capability_export(&entry
->orom
);
2777 print_imsm_capability_export(&entry
->orom
);
2783 static int match_home_imsm(struct supertype
*st
, char *homehost
)
2785 /* the imsm metadata format does not specify any host
2786 * identification information. We return -1 since we can never
2787 * confirm nor deny whether a given array is "meant" for this
2788 * host. We rely on compare_super and the 'family_num' fields to
2789 * exclude member disks that do not belong, and we rely on
2790 * mdadm.conf to specify the arrays that should be assembled.
2791 * Auto-assembly may still pick up "foreign" arrays.
2797 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
2799 /* The uuid returned here is used for:
2800 * uuid to put into bitmap file (Create, Grow)
2801 * uuid for backup header when saving critical section (Grow)
2802 * comparing uuids when re-adding a device into an array
2803 * In these cases the uuid required is that of the data-array,
2804 * not the device-set.
2805 * uuid to recognise same set when adding a missing device back
2806 * to an array. This is a uuid for the device-set.
2808 * For each of these we can make do with a truncated
2809 * or hashed uuid rather than the original, as long as
2811 * In each case the uuid required is that of the data-array,
2812 * not the device-set.
2814 /* imsm does not track uuid's so we synthesis one using sha1 on
2815 * - The signature (Which is constant for all imsm array, but no matter)
2816 * - the orig_family_num of the container
2817 * - the index number of the volume
2818 * - the 'serial' number of the volume.
2819 * Hopefully these are all constant.
2821 struct intel_super
*super
= st
->sb
;
2824 struct sha1_ctx ctx
;
2825 struct imsm_dev
*dev
= NULL
;
2828 /* some mdadm versions failed to set ->orig_family_num, in which
2829 * case fall back to ->family_num. orig_family_num will be
2830 * fixed up with the first metadata update.
2832 family_num
= super
->anchor
->orig_family_num
;
2833 if (family_num
== 0)
2834 family_num
= super
->anchor
->family_num
;
2835 sha1_init_ctx(&ctx
);
2836 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
2837 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
2838 if (super
->current_vol
>= 0)
2839 dev
= get_imsm_dev(super
, super
->current_vol
);
2841 __u32 vol
= super
->current_vol
;
2842 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
2843 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
2845 sha1_finish_ctx(&ctx
, buf
);
2846 memcpy(uuid
, buf
, 4*4);
2851 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
2853 __u8
*v
= get_imsm_version(mpb
);
2854 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
2855 char major
[] = { 0, 0, 0 };
2856 char minor
[] = { 0 ,0, 0 };
2857 char patch
[] = { 0, 0, 0 };
2858 char *ver_parse
[] = { major
, minor
, patch
};
2862 while (*v
!= '\0' && v
< end
) {
2863 if (*v
!= '.' && j
< 2)
2864 ver_parse
[i
][j
++] = *v
;
2872 *m
= strtol(minor
, NULL
, 0);
2873 *p
= strtol(patch
, NULL
, 0);
2877 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
2879 /* migr_strip_size when repairing or initializing parity */
2880 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2881 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2883 switch (get_imsm_raid_level(map
)) {
2888 return 128*1024 >> 9;
2892 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
2894 /* migr_strip_size when rebuilding a degraded disk, no idea why
2895 * this is different than migr_strip_size_resync(), but it's good
2898 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2899 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2901 switch (get_imsm_raid_level(map
)) {
2904 if (map
->num_members
% map
->num_domains
== 0)
2905 return 128*1024 >> 9;
2909 return max((__u32
) 64*1024 >> 9, chunk
);
2911 return 128*1024 >> 9;
2915 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
2917 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2918 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2919 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
2920 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
2922 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
2925 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
2927 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2928 int level
= get_imsm_raid_level(lo
);
2930 if (level
== 1 || level
== 10) {
2931 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2933 return hi
->num_domains
;
2935 return num_stripes_per_unit_resync(dev
);
2938 static unsigned long long calc_component_size(struct imsm_map
*map
,
2939 struct imsm_dev
*dev
)
2941 unsigned long long component_size
;
2942 unsigned long long dev_size
= imsm_dev_size(dev
);
2943 long long calc_dev_size
= 0;
2944 unsigned int member_disks
= imsm_num_data_members(map
);
2946 if (member_disks
== 0)
2949 component_size
= per_dev_array_size(map
);
2950 calc_dev_size
= component_size
* member_disks
;
2952 /* Component size is rounded to 1MB so difference between size from
2953 * metadata and size calculated from num_data_stripes equals up to
2954 * 2048 blocks per each device. If the difference is higher it means
2955 * that array size was expanded and num_data_stripes was not updated.
2957 if (llabs(calc_dev_size
- (long long)dev_size
) >
2958 (1 << SECT_PER_MB_SHIFT
) * member_disks
) {
2959 component_size
= dev_size
/ member_disks
;
2960 dprintf("Invalid num_data_stripes in metadata; expected=%llu, found=%llu\n",
2961 component_size
/ map
->blocks_per_strip
,
2962 num_data_stripes(map
));
2965 return component_size
;
2968 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
2970 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2971 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2973 switch(get_imsm_raid_level(map
)) {
2976 return chunk
* map
->num_domains
;
2978 return chunk
* map
->num_members
;
2984 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
2986 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2987 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2988 __u32 strip
= block
/ chunk
;
2990 switch (get_imsm_raid_level(map
)) {
2993 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
2994 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
2996 return vol_stripe
* chunk
+ block
% chunk
;
2998 __u32 stripe
= strip
/ (map
->num_members
- 1);
3000 return stripe
* chunk
+ block
% chunk
;
3007 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
3008 struct imsm_dev
*dev
)
3010 /* calculate the conversion factor between per member 'blocks'
3011 * (md/{resync,rebuild}_start) and imsm migration units, return
3012 * 0 for the 'not migrating' and 'unsupported migration' cases
3014 if (!dev
->vol
.migr_state
)
3017 switch (migr_type(dev
)) {
3018 case MIGR_GEN_MIGR
: {
3019 struct migr_record
*migr_rec
= super
->migr_rec
;
3020 return __le32_to_cpu(migr_rec
->blocks_per_unit
);
3025 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3026 __u32 stripes_per_unit
;
3027 __u32 blocks_per_unit
;
3036 /* yes, this is really the translation of migr_units to
3037 * per-member blocks in the 'resync' case
3039 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
3040 migr_chunk
= migr_strip_blocks_resync(dev
);
3041 disks
= imsm_num_data_members(map
);
3042 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
3043 stripe
= __le16_to_cpu(map
->blocks_per_strip
) * disks
;
3044 segment
= blocks_per_unit
/ stripe
;
3045 block_rel
= blocks_per_unit
- segment
* stripe
;
3046 parity_depth
= parity_segment_depth(dev
);
3047 block_map
= map_migr_block(dev
, block_rel
);
3048 return block_map
+ parity_depth
* segment
;
3050 case MIGR_REBUILD
: {
3051 __u32 stripes_per_unit
;
3054 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
3055 migr_chunk
= migr_strip_blocks_rebuild(dev
);
3056 return migr_chunk
* stripes_per_unit
;
3058 case MIGR_STATE_CHANGE
:
3064 static int imsm_level_to_layout(int level
)
3072 return ALGORITHM_LEFT_ASYMMETRIC
;
3079 /*******************************************************************************
3080 * Function: read_imsm_migr_rec
3081 * Description: Function reads imsm migration record from last sector of disk
3083 * fd : disk descriptor
3084 * super : metadata info
3088 ******************************************************************************/
3089 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
)
3092 unsigned int sector_size
= super
->sector_size
;
3093 unsigned long long dsize
;
3095 get_dev_size(fd
, NULL
, &dsize
);
3096 if (lseek64(fd
, dsize
- (sector_size
*MIGR_REC_SECTOR_POSITION
),
3098 pr_err("Cannot seek to anchor block: %s\n",
3102 if ((unsigned int)read(fd
, super
->migr_rec_buf
,
3103 MIGR_REC_BUF_SECTORS
*sector_size
) !=
3104 MIGR_REC_BUF_SECTORS
*sector_size
) {
3105 pr_err("Cannot read migr record block: %s\n",
3110 if (sector_size
== 4096)
3111 convert_from_4k_imsm_migr_rec(super
);
3117 static struct imsm_dev
*imsm_get_device_during_migration(
3118 struct intel_super
*super
)
3121 struct intel_dev
*dv
;
3123 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
3124 if (is_gen_migration(dv
->dev
))
3130 /*******************************************************************************
3131 * Function: load_imsm_migr_rec
3132 * Description: Function reads imsm migration record (it is stored at the last
3135 * super : imsm internal array info
3139 * -2 : no migration in progress
3140 ******************************************************************************/
3141 static int load_imsm_migr_rec(struct intel_super
*super
)
3147 struct imsm_dev
*dev
;
3148 struct imsm_map
*map
;
3152 /* find map under migration */
3153 dev
= imsm_get_device_during_migration(super
);
3154 /* nothing to load,no migration in progress?
3159 map
= get_imsm_map(dev
, MAP_0
);
3163 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
3164 /* skip spare and failed disks
3168 /* read only from one of the first two slots
3170 slot
= get_imsm_disk_slot(map
, dl
->index
);
3171 if (slot
> 1 || slot
< 0)
3175 sprintf(nm
, "%d:%d", dl
->major
, dl
->minor
);
3176 fd
= dev_open(nm
, O_RDONLY
);
3189 retval
= read_imsm_migr_rec(fd
, super
);
3196 /*******************************************************************************
3197 * function: imsm_create_metadata_checkpoint_update
3198 * Description: It creates update for checkpoint change.
3200 * super : imsm internal array info
3201 * u : pointer to prepared update
3204 * If length is equal to 0, input pointer u contains no update
3205 ******************************************************************************/
3206 static int imsm_create_metadata_checkpoint_update(
3207 struct intel_super
*super
,
3208 struct imsm_update_general_migration_checkpoint
**u
)
3211 int update_memory_size
= 0;
3213 dprintf("(enter)\n");
3219 /* size of all update data without anchor */
3220 update_memory_size
=
3221 sizeof(struct imsm_update_general_migration_checkpoint
);
3223 *u
= xcalloc(1, update_memory_size
);
3225 dprintf("error: cannot get memory\n");
3228 (*u
)->type
= update_general_migration_checkpoint
;
3229 (*u
)->curr_migr_unit
= current_migr_unit(super
->migr_rec
);
3230 dprintf("prepared for %llu\n", (unsigned long long)(*u
)->curr_migr_unit
);
3232 return update_memory_size
;
3235 static void imsm_update_metadata_locally(struct supertype
*st
,
3236 void *buf
, int len
);
3238 /*******************************************************************************
3239 * Function: write_imsm_migr_rec
3240 * Description: Function writes imsm migration record
3241 * (at the last sector of disk)
3243 * super : imsm internal array info
3247 ******************************************************************************/
3248 static int write_imsm_migr_rec(struct supertype
*st
)
3250 struct intel_super
*super
= st
->sb
;
3251 unsigned int sector_size
= super
->sector_size
;
3252 unsigned long long dsize
;
3256 struct imsm_update_general_migration_checkpoint
*u
;
3257 struct imsm_dev
*dev
;
3258 struct imsm_map
*map
;
3260 /* find map under migration */
3261 dev
= imsm_get_device_during_migration(super
);
3262 /* if no migration, write buffer anyway to clear migr_record
3263 * on disk based on first available device
3266 dev
= get_imsm_dev(super
, super
->current_vol
< 0 ? 0 :
3267 super
->current_vol
);
3269 map
= get_imsm_map(dev
, MAP_0
);
3271 if (sector_size
== 4096)
3272 convert_to_4k_imsm_migr_rec(super
);
3273 for (sd
= super
->disks
; sd
; sd
= sd
->next
) {
3276 /* skip failed and spare devices */
3279 /* write to 2 first slots only */
3281 slot
= get_imsm_disk_slot(map
, sd
->index
);
3282 if (map
== NULL
|| slot
> 1 || slot
< 0)
3285 get_dev_size(sd
->fd
, NULL
, &dsize
);
3286 if (lseek64(sd
->fd
, dsize
- (MIGR_REC_SECTOR_POSITION
*
3289 pr_err("Cannot seek to anchor block: %s\n",
3293 if ((unsigned int)write(sd
->fd
, super
->migr_rec_buf
,
3294 MIGR_REC_BUF_SECTORS
*sector_size
) !=
3295 MIGR_REC_BUF_SECTORS
*sector_size
) {
3296 pr_err("Cannot write migr record block: %s\n",
3301 if (sector_size
== 4096)
3302 convert_from_4k_imsm_migr_rec(super
);
3303 /* update checkpoint information in metadata */
3304 len
= imsm_create_metadata_checkpoint_update(super
, &u
);
3306 dprintf("imsm: Cannot prepare update\n");
3309 /* update metadata locally */
3310 imsm_update_metadata_locally(st
, u
, len
);
3311 /* and possibly remotely */
3312 if (st
->update_tail
) {
3313 append_metadata_update(st
, u
, len
);
3314 /* during reshape we do all work inside metadata handler
3315 * manage_reshape(), so metadata update has to be triggered
3318 flush_metadata_updates(st
);
3319 st
->update_tail
= &st
->updates
;
3328 /* spare/missing disks activations are not allowe when
3329 * array/container performs reshape operation, because
3330 * all arrays in container works on the same disks set
3332 int imsm_reshape_blocks_arrays_changes(struct intel_super
*super
)
3335 struct intel_dev
*i_dev
;
3336 struct imsm_dev
*dev
;
3338 /* check whole container
3340 for (i_dev
= super
->devlist
; i_dev
; i_dev
= i_dev
->next
) {
3342 if (is_gen_migration(dev
)) {
3343 /* No repair during any migration in container
3351 static unsigned long long imsm_component_size_alignment_check(int level
,
3353 unsigned int sector_size
,
3354 unsigned long long component_size
)
3356 unsigned int component_size_alignment
;
3358 /* check component size alignment
3360 component_size_alignment
= component_size
% (chunk_size
/sector_size
);
3362 dprintf("(Level: %i, chunk_size = %i, component_size = %llu), component_size_alignment = %u\n",
3363 level
, chunk_size
, component_size
,
3364 component_size_alignment
);
3366 if (component_size_alignment
&& (level
!= 1) && (level
!= UnSet
)) {
3367 dprintf("imsm: reported component size aligned from %llu ",
3369 component_size
-= component_size_alignment
;
3370 dprintf_cont("to %llu (%i).\n",
3371 component_size
, component_size_alignment
);
3374 return component_size
;
3377 /*******************************************************************************
3378 * Function: get_bitmap_header_sector
3379 * Description: Returns the sector where the bitmap header is placed.
3381 * st : supertype information
3382 * dev_idx : index of the device with bitmap
3385 * The sector where the bitmap header is placed
3386 ******************************************************************************/
3387 static unsigned long long get_bitmap_header_sector(struct intel_super
*super
,
3390 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
3391 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3393 if (!super
->sector_size
) {
3394 dprintf("sector size is not set\n");
3398 return pba_of_lba0(map
) + calc_component_size(map
, dev
) +
3399 (IMSM_BITMAP_HEADER_OFFSET
/ super
->sector_size
);
3402 /*******************************************************************************
3403 * Function: get_bitmap_sector
3404 * Description: Returns the sector where the bitmap is placed.
3406 * st : supertype information
3407 * dev_idx : index of the device with bitmap
3410 * The sector where the bitmap is placed
3411 ******************************************************************************/
3412 static unsigned long long get_bitmap_sector(struct intel_super
*super
,
3415 if (!super
->sector_size
) {
3416 dprintf("sector size is not set\n");
3420 return get_bitmap_header_sector(super
, dev_idx
) +
3421 (IMSM_BITMAP_HEADER_SIZE
/ super
->sector_size
);
3424 static unsigned long long get_ppl_sector(struct intel_super
*super
, int dev_idx
)
3426 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
3427 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3429 return pba_of_lba0(map
) +
3430 (num_data_stripes(map
) * map
->blocks_per_strip
);
3433 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
3435 struct intel_super
*super
= st
->sb
;
3436 struct migr_record
*migr_rec
= super
->migr_rec
;
3437 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
3438 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3439 struct imsm_map
*prev_map
= get_imsm_map(dev
, MAP_1
);
3440 struct imsm_map
*map_to_analyse
= map
;
3442 int map_disks
= info
->array
.raid_disks
;
3444 memset(info
, 0, sizeof(*info
));
3446 map_to_analyse
= prev_map
;
3448 dl
= super
->current_disk
;
3450 info
->container_member
= super
->current_vol
;
3451 info
->array
.raid_disks
= map
->num_members
;
3452 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
3453 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
3454 info
->array
.md_minor
= -1;
3455 info
->array
.ctime
= 0;
3456 info
->array
.utime
= 0;
3457 info
->array
.chunk_size
=
3458 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
3459 info
->array
.state
= !(dev
->vol
.dirty
& RAIDVOL_DIRTY
);
3460 info
->custom_array_size
= imsm_dev_size(dev
);
3461 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
3463 if (is_gen_migration(dev
)) {
3464 info
->reshape_active
= 1;
3465 info
->new_level
= get_imsm_raid_level(map
);
3466 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
3467 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
3468 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
3469 if (info
->delta_disks
) {
3470 /* this needs to be applied to every array
3473 info
->reshape_active
= CONTAINER_RESHAPE
;
3475 /* We shape information that we give to md might have to be
3476 * modify to cope with md's requirement for reshaping arrays.
3477 * For example, when reshaping a RAID0, md requires it to be
3478 * presented as a degraded RAID4.
3479 * Also if a RAID0 is migrating to a RAID5 we need to specify
3480 * the array as already being RAID5, but the 'before' layout
3481 * is a RAID4-like layout.
3483 switch (info
->array
.level
) {
3485 switch(info
->new_level
) {
3487 /* conversion is happening as RAID4 */
3488 info
->array
.level
= 4;
3489 info
->array
.raid_disks
+= 1;
3492 /* conversion is happening as RAID5 */
3493 info
->array
.level
= 5;
3494 info
->array
.layout
= ALGORITHM_PARITY_N
;
3495 info
->delta_disks
-= 1;
3498 /* FIXME error message */
3499 info
->array
.level
= UnSet
;
3505 info
->new_level
= UnSet
;
3506 info
->new_layout
= UnSet
;
3507 info
->new_chunk
= info
->array
.chunk_size
;
3508 info
->delta_disks
= 0;
3512 info
->disk
.major
= dl
->major
;
3513 info
->disk
.minor
= dl
->minor
;
3514 info
->disk
.number
= dl
->index
;
3515 info
->disk
.raid_disk
= get_imsm_disk_slot(map_to_analyse
,
3519 info
->data_offset
= pba_of_lba0(map_to_analyse
);
3520 info
->component_size
= calc_component_size(map
, dev
);
3521 info
->component_size
= imsm_component_size_alignment_check(
3523 info
->array
.chunk_size
,
3525 info
->component_size
);
3526 info
->bb
.supported
= 1;
3528 memset(info
->uuid
, 0, sizeof(info
->uuid
));
3529 info
->recovery_start
= MaxSector
;
3531 if (info
->array
.level
== 5 &&
3532 (dev
->rwh_policy
== RWH_DISTRIBUTED
||
3533 dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)) {
3534 info
->consistency_policy
= CONSISTENCY_POLICY_PPL
;
3535 info
->ppl_sector
= get_ppl_sector(super
, super
->current_vol
);
3536 if (dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)
3537 info
->ppl_size
= MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9;
3539 info
->ppl_size
= (PPL_HEADER_SIZE
+ PPL_ENTRY_SPACE
)
3541 } else if (info
->array
.level
<= 0) {
3542 info
->consistency_policy
= CONSISTENCY_POLICY_NONE
;
3544 if (dev
->rwh_policy
== RWH_BITMAP
) {
3545 info
->bitmap_offset
= get_bitmap_sector(super
, super
->current_vol
);
3546 info
->consistency_policy
= CONSISTENCY_POLICY_BITMAP
;
3548 info
->consistency_policy
= CONSISTENCY_POLICY_RESYNC
;
3552 info
->reshape_progress
= 0;
3553 info
->resync_start
= MaxSector
;
3554 if ((map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
3555 !(info
->array
.state
& 1)) &&
3556 imsm_reshape_blocks_arrays_changes(super
) == 0) {
3557 info
->resync_start
= 0;
3559 if (dev
->vol
.migr_state
) {
3560 switch (migr_type(dev
)) {
3563 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
3565 __u64 units
= vol_curr_migr_unit(dev
);
3567 info
->resync_start
= blocks_per_unit
* units
;
3570 case MIGR_GEN_MIGR
: {
3571 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
3573 __u64 units
= current_migr_unit(migr_rec
);
3576 if (__le32_to_cpu(migr_rec
->ascending_migr
) &&
3578 (get_num_migr_units(migr_rec
)-1)) &&
3579 (super
->migr_rec
->rec_status
==
3580 __cpu_to_le32(UNIT_SRC_IN_CP_AREA
)))
3583 info
->reshape_progress
= blocks_per_unit
* units
;
3585 dprintf("IMSM: General Migration checkpoint : %llu (%llu) -> read reshape progress : %llu\n",
3586 (unsigned long long)units
,
3587 (unsigned long long)blocks_per_unit
,
3588 info
->reshape_progress
);
3590 used_disks
= imsm_num_data_members(prev_map
);
3591 if (used_disks
> 0) {
3592 info
->custom_array_size
= per_dev_array_size(map
) *
3597 /* we could emulate the checkpointing of
3598 * 'sync_action=check' migrations, but for now
3599 * we just immediately complete them
3602 /* this is handled by container_content_imsm() */
3603 case MIGR_STATE_CHANGE
:
3604 /* FIXME handle other migrations */
3606 /* we are not dirty, so... */
3607 info
->resync_start
= MaxSector
;
3611 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
3612 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
3614 info
->array
.major_version
= -1;
3615 info
->array
.minor_version
= -2;
3616 sprintf(info
->text_version
, "/%s/%d", st
->container_devnm
, info
->container_member
);
3617 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
3618 uuid_from_super_imsm(st
, info
->uuid
);
3622 for (i
=0; i
<map_disks
; i
++) {
3624 if (i
< info
->array
.raid_disks
) {
3625 struct imsm_disk
*dsk
;
3626 j
= get_imsm_disk_idx(dev
, i
, MAP_X
);
3627 dsk
= get_imsm_disk(super
, j
);
3628 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
3635 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
3636 int failed
, int look_in_map
);
3638 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
3641 static void manage_second_map(struct intel_super
*super
, struct imsm_dev
*dev
)
3643 if (is_gen_migration(dev
)) {
3646 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
3648 failed
= imsm_count_failed(super
, dev
, MAP_1
);
3649 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_1
);
3650 if (map2
->map_state
!= map_state
) {
3651 map2
->map_state
= map_state
;
3652 super
->updates_pending
++;
3657 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
3661 for (d
= super
->missing
; d
; d
= d
->next
)
3662 if (d
->index
== index
)
3667 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
3669 struct intel_super
*super
= st
->sb
;
3670 struct imsm_disk
*disk
;
3671 int map_disks
= info
->array
.raid_disks
;
3672 int max_enough
= -1;
3674 struct imsm_super
*mpb
;
3676 if (super
->current_vol
>= 0) {
3677 getinfo_super_imsm_volume(st
, info
, map
);
3680 memset(info
, 0, sizeof(*info
));
3682 /* Set raid_disks to zero so that Assemble will always pull in valid
3685 info
->array
.raid_disks
= 0;
3686 info
->array
.level
= LEVEL_CONTAINER
;
3687 info
->array
.layout
= 0;
3688 info
->array
.md_minor
= -1;
3689 info
->array
.ctime
= 0; /* N/A for imsm */
3690 info
->array
.utime
= 0;
3691 info
->array
.chunk_size
= 0;
3693 info
->disk
.major
= 0;
3694 info
->disk
.minor
= 0;
3695 info
->disk
.raid_disk
= -1;
3696 info
->reshape_active
= 0;
3697 info
->array
.major_version
= -1;
3698 info
->array
.minor_version
= -2;
3699 strcpy(info
->text_version
, "imsm");
3700 info
->safe_mode_delay
= 0;
3701 info
->disk
.number
= -1;
3702 info
->disk
.state
= 0;
3704 info
->recovery_start
= MaxSector
;
3705 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
3706 info
->bb
.supported
= 1;
3708 /* do we have the all the insync disks that we expect? */
3709 mpb
= super
->anchor
;
3710 info
->events
= __le32_to_cpu(mpb
->generation_num
);
3712 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
3713 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
3714 int failed
, enough
, j
, missing
= 0;
3715 struct imsm_map
*map
;
3718 failed
= imsm_count_failed(super
, dev
, MAP_0
);
3719 state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
3720 map
= get_imsm_map(dev
, MAP_0
);
3722 /* any newly missing disks?
3723 * (catches single-degraded vs double-degraded)
3725 for (j
= 0; j
< map
->num_members
; j
++) {
3726 __u32 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
3727 __u32 idx
= ord_to_idx(ord
);
3729 if (super
->disks
&& super
->disks
->index
== (int)idx
)
3730 info
->disk
.raid_disk
= j
;
3732 if (!(ord
& IMSM_ORD_REBUILD
) &&
3733 get_imsm_missing(super
, idx
)) {
3739 if (state
== IMSM_T_STATE_FAILED
)
3741 else if (state
== IMSM_T_STATE_DEGRADED
&&
3742 (state
!= map
->map_state
|| missing
))
3744 else /* we're normal, or already degraded */
3746 if (is_gen_migration(dev
) && missing
) {
3747 /* during general migration we need all disks
3748 * that process is running on.
3749 * No new missing disk is allowed.
3753 /* no more checks necessary
3757 /* in the missing/failed disk case check to see
3758 * if at least one array is runnable
3760 max_enough
= max(max_enough
, enough
);
3762 dprintf("enough: %d\n", max_enough
);
3763 info
->container_enough
= max_enough
;
3766 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
3768 disk
= &super
->disks
->disk
;
3769 info
->data_offset
= total_blocks(&super
->disks
->disk
) - reserved
;
3770 info
->component_size
= reserved
;
3771 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
3772 /* we don't change info->disk.raid_disk here because
3773 * this state will be finalized in mdmon after we have
3774 * found the 'most fresh' version of the metadata
3776 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
3777 info
->disk
.state
|= (is_spare(disk
) || is_journal(disk
)) ?
3778 0 : (1 << MD_DISK_SYNC
);
3781 /* only call uuid_from_super_imsm when this disk is part of a populated container,
3782 * ->compare_super may have updated the 'num_raid_devs' field for spares
3784 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
3785 uuid_from_super_imsm(st
, info
->uuid
);
3787 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
3789 /* I don't know how to compute 'map' on imsm, so use safe default */
3792 for (i
= 0; i
< map_disks
; i
++)
3798 /* allocates memory and fills disk in mdinfo structure
3799 * for each disk in array */
3800 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
3802 struct mdinfo
*mddev
;
3803 struct intel_super
*super
= st
->sb
;
3804 struct imsm_disk
*disk
;
3807 if (!super
|| !super
->disks
)
3810 mddev
= xcalloc(1, sizeof(*mddev
));
3814 tmp
= xcalloc(1, sizeof(*tmp
));
3816 tmp
->next
= mddev
->devs
;
3818 tmp
->disk
.number
= count
++;
3819 tmp
->disk
.major
= dl
->major
;
3820 tmp
->disk
.minor
= dl
->minor
;
3821 tmp
->disk
.state
= is_configured(disk
) ?
3822 (1 << MD_DISK_ACTIVE
) : 0;
3823 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
3824 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
3825 tmp
->disk
.raid_disk
= -1;
3831 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
3832 char *update
, char *devname
, int verbose
,
3833 int uuid_set
, char *homehost
)
3835 /* For 'assemble' and 'force' we need to return non-zero if any
3836 * change was made. For others, the return value is ignored.
3837 * Update options are:
3838 * force-one : This device looks a bit old but needs to be included,
3839 * update age info appropriately.
3840 * assemble: clear any 'faulty' flag to allow this device to
3842 * force-array: Array is degraded but being forced, mark it clean
3843 * if that will be needed to assemble it.
3845 * newdev: not used ????
3846 * grow: Array has gained a new device - this is currently for
3848 * resync: mark as dirty so a resync will happen.
3849 * name: update the name - preserving the homehost
3850 * uuid: Change the uuid of the array to match watch is given
3852 * Following are not relevant for this imsm:
3853 * sparc2.2 : update from old dodgey metadata
3854 * super-minor: change the preferred_minor number
3855 * summaries: update redundant counters.
3856 * homehost: update the recorded homehost
3857 * _reshape_progress: record new reshape_progress position.
3860 struct intel_super
*super
= st
->sb
;
3861 struct imsm_super
*mpb
;
3863 /* we can only update container info */
3864 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
3867 mpb
= super
->anchor
;
3869 if (strcmp(update
, "uuid") == 0) {
3870 /* We take this to mean that the family_num should be updated.
3871 * However that is much smaller than the uuid so we cannot really
3872 * allow an explicit uuid to be given. And it is hard to reliably
3874 * So if !uuid_set we know the current uuid is random and just used
3875 * the first 'int' and copy it to the other 3 positions.
3876 * Otherwise we require the 4 'int's to be the same as would be the
3877 * case if we are using a random uuid. So an explicit uuid will be
3878 * accepted as long as all for ints are the same... which shouldn't hurt
3881 info
->uuid
[1] = info
->uuid
[2] = info
->uuid
[3] = info
->uuid
[0];
3884 if (info
->uuid
[0] != info
->uuid
[1] ||
3885 info
->uuid
[1] != info
->uuid
[2] ||
3886 info
->uuid
[2] != info
->uuid
[3])
3892 mpb
->orig_family_num
= info
->uuid
[0];
3893 } else if (strcmp(update
, "assemble") == 0)
3898 /* successful update? recompute checksum */
3900 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
3905 static size_t disks_to_mpb_size(int disks
)
3909 size
= sizeof(struct imsm_super
);
3910 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
3911 size
+= 2 * sizeof(struct imsm_dev
);
3912 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
3913 size
+= (4 - 2) * sizeof(struct imsm_map
);
3914 /* 4 possible disk_ord_tbl's */
3915 size
+= 4 * (disks
- 1) * sizeof(__u32
);
3916 /* maximum bbm log */
3917 size
+= sizeof(struct bbm_log
);
3922 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
,
3923 unsigned long long data_offset
)
3925 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
3928 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
3931 static void free_devlist(struct intel_super
*super
)
3933 struct intel_dev
*dv
;
3935 while (super
->devlist
) {
3936 dv
= super
->devlist
->next
;
3937 free(super
->devlist
->dev
);
3938 free(super
->devlist
);
3939 super
->devlist
= dv
;
3943 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
3945 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
3948 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
,
3952 * 0 same, or first was empty, and second was copied
3953 * 1 sb are different
3955 struct intel_super
*first
= st
->sb
;
3956 struct intel_super
*sec
= tst
->sb
;
3964 /* in platform dependent environment test if the disks
3965 * use the same Intel hba
3966 * if not on Intel hba at all, allow anything.
3967 * doesn't check HBAs if num_raid_devs is not set, as it means
3968 * it is a free floating spare, and all spares regardless of HBA type
3969 * will fall into separate container during the assembly
3971 if (first
->hba
&& sec
->hba
&& first
->anchor
->num_raid_devs
!= 0) {
3972 if (first
->hba
->type
!= sec
->hba
->type
) {
3974 pr_err("HBAs of devices do not match %s != %s\n",
3975 get_sys_dev_type(first
->hba
->type
),
3976 get_sys_dev_type(sec
->hba
->type
));
3979 if (first
->orom
!= sec
->orom
) {
3981 pr_err("HBAs of devices do not match %s != %s\n",
3982 first
->hba
->pci_id
, sec
->hba
->pci_id
);
3987 if (first
->anchor
->num_raid_devs
> 0 &&
3988 sec
->anchor
->num_raid_devs
> 0) {
3989 /* Determine if these disks might ever have been
3990 * related. Further disambiguation can only take place
3991 * in load_super_imsm_all
3993 __u32 first_family
= first
->anchor
->orig_family_num
;
3994 __u32 sec_family
= sec
->anchor
->orig_family_num
;
3996 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
3997 MAX_SIGNATURE_LENGTH
) != 0)
4000 if (first_family
== 0)
4001 first_family
= first
->anchor
->family_num
;
4002 if (sec_family
== 0)
4003 sec_family
= sec
->anchor
->family_num
;
4005 if (first_family
!= sec_family
)
4010 /* if an anchor does not have num_raid_devs set then it is a free
4011 * floating spare. don't assosiate spare with any array, as during assembly
4012 * spares shall fall into separate container, from which they can be moved
4015 if (first
->anchor
->num_raid_devs
^ sec
->anchor
->num_raid_devs
)
4021 static void fd2devname(int fd
, char *name
)
4029 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
4032 static int nvme_get_serial(int fd
, void *buf
, size_t buf_len
)
4034 char path
[PATH_MAX
];
4035 char *name
= fd2kname(fd
);
4040 if (strncmp(name
, "nvme", 4) != 0)
4043 if (!diskfd_to_devpath(fd
, 1, path
))
4046 return devpath_to_char(path
, "serial", buf
, buf_len
, 0);
4049 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
4051 static int imsm_read_serial(int fd
, char *devname
,
4052 __u8
*serial
, size_t serial_buf_len
)
4061 memset(buf
, 0, sizeof(buf
));
4063 rv
= nvme_get_serial(fd
, buf
, sizeof(buf
));
4066 rv
= scsi_get_serial(fd
, buf
, sizeof(buf
));
4068 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
4069 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
4070 fd2devname(fd
, (char *) serial
);
4076 pr_err("Failed to retrieve serial for %s\n",
4081 /* trim all whitespace and non-printable characters and convert
4084 for (i
= 0, dest
= buf
; i
< sizeof(buf
) && buf
[i
]; i
++) {
4087 /* ':' is reserved for use in placeholder serial
4088 * numbers for missing disks
4099 if (len
> serial_buf_len
) {
4100 /* truncate leading characters */
4101 dest
+= len
- serial_buf_len
;
4102 len
= serial_buf_len
;
4105 memset(serial
, 0, serial_buf_len
);
4106 memcpy(serial
, dest
, len
);
4111 static int serialcmp(__u8
*s1
, __u8
*s2
)
4113 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
4116 static void serialcpy(__u8
*dest
, __u8
*src
)
4118 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
4121 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
4125 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4126 if (serialcmp(dl
->serial
, serial
) == 0)
4132 static struct imsm_disk
*
4133 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
4137 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4138 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
4140 if (serialcmp(disk
->serial
, serial
) == 0) {
4151 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
4153 struct imsm_disk
*disk
;
4158 __u8 serial
[MAX_RAID_SERIAL_LEN
];
4160 rv
= imsm_read_serial(fd
, devname
, serial
, MAX_RAID_SERIAL_LEN
);
4165 dl
= xcalloc(1, sizeof(*dl
));
4168 dl
->major
= major(stb
.st_rdev
);
4169 dl
->minor
= minor(stb
.st_rdev
);
4170 dl
->next
= super
->disks
;
4171 dl
->fd
= keep_fd
? fd
: -1;
4172 assert(super
->disks
== NULL
);
4174 serialcpy(dl
->serial
, serial
);
4177 fd2devname(fd
, name
);
4179 dl
->devname
= xstrdup(devname
);
4181 dl
->devname
= xstrdup(name
);
4183 /* look up this disk's index in the current anchor */
4184 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
4187 /* only set index on disks that are a member of a
4188 * populated contianer, i.e. one with raid_devs
4190 if (is_failed(&dl
->disk
))
4192 else if (is_spare(&dl
->disk
) || is_journal(&dl
->disk
))
4199 /* When migrating map0 contains the 'destination' state while map1
4200 * contains the current state. When not migrating map0 contains the
4201 * current state. This routine assumes that map[0].map_state is set to
4202 * the current array state before being called.
4204 * Migration is indicated by one of the following states
4205 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
4206 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
4207 * map1state=unitialized)
4208 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
4210 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
4211 * map1state=degraded)
4212 * 5/ Migration (mig_state=1 migr_type=MIGR_GEN_MIGR map0state=normal
4215 static void migrate(struct imsm_dev
*dev
, struct intel_super
*super
,
4216 __u8 to_state
, int migr_type
)
4218 struct imsm_map
*dest
;
4219 struct imsm_map
*src
= get_imsm_map(dev
, MAP_0
);
4221 dev
->vol
.migr_state
= 1;
4222 set_migr_type(dev
, migr_type
);
4223 set_vol_curr_migr_unit(dev
, 0);
4224 dest
= get_imsm_map(dev
, MAP_1
);
4226 /* duplicate and then set the target end state in map[0] */
4227 memcpy(dest
, src
, sizeof_imsm_map(src
));
4228 if (migr_type
== MIGR_GEN_MIGR
) {
4232 for (i
= 0; i
< src
->num_members
; i
++) {
4233 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
4234 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
4238 if (migr_type
== MIGR_GEN_MIGR
)
4239 /* Clear migration record */
4240 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
4242 src
->map_state
= to_state
;
4245 static void end_migration(struct imsm_dev
*dev
, struct intel_super
*super
,
4248 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
4249 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
== 0 ?
4253 /* merge any IMSM_ORD_REBUILD bits that were not successfully
4254 * completed in the last migration.
4256 * FIXME add support for raid-level-migration
4258 if (map_state
!= map
->map_state
&& (is_gen_migration(dev
) == 0) &&
4259 prev
->map_state
!= IMSM_T_STATE_UNINITIALIZED
) {
4260 /* when final map state is other than expected
4261 * merge maps (not for migration)
4265 for (i
= 0; i
< prev
->num_members
; i
++)
4266 for (j
= 0; j
< map
->num_members
; j
++)
4267 /* during online capacity expansion
4268 * disks position can be changed
4269 * if takeover is used
4271 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
4272 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
4273 map
->disk_ord_tbl
[j
] |=
4274 prev
->disk_ord_tbl
[i
];
4277 failed
= imsm_count_failed(super
, dev
, MAP_0
);
4278 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
4281 dev
->vol
.migr_state
= 0;
4282 set_migr_type(dev
, 0);
4283 set_vol_curr_migr_unit(dev
, 0);
4284 map
->map_state
= map_state
;
4287 static int parse_raid_devices(struct intel_super
*super
)
4290 struct imsm_dev
*dev_new
;
4291 size_t len
, len_migr
;
4293 size_t space_needed
= 0;
4294 struct imsm_super
*mpb
= super
->anchor
;
4296 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
4297 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
4298 struct intel_dev
*dv
;
4300 len
= sizeof_imsm_dev(dev_iter
, 0);
4301 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
4303 space_needed
+= len_migr
- len
;
4305 dv
= xmalloc(sizeof(*dv
));
4306 if (max_len
< len_migr
)
4308 if (max_len
> len_migr
)
4309 space_needed
+= max_len
- len_migr
;
4310 dev_new
= xmalloc(max_len
);
4311 imsm_copy_dev(dev_new
, dev_iter
);
4314 dv
->next
= super
->devlist
;
4315 super
->devlist
= dv
;
4318 /* ensure that super->buf is large enough when all raid devices
4321 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
4324 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
,
4325 super
->sector_size
);
4326 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, len
) != 0)
4329 memcpy(buf
, super
->buf
, super
->len
);
4330 memset(buf
+ super
->len
, 0, len
- super
->len
);
4336 super
->extra_space
+= space_needed
;
4341 /*******************************************************************************
4342 * Function: check_mpb_migr_compatibility
4343 * Description: Function checks for unsupported migration features:
4344 * - migration optimization area (pba_of_lba0)
4345 * - descending reshape (ascending_migr)
4347 * super : imsm metadata information
4349 * 0 : migration is compatible
4350 * -1 : migration is not compatible
4351 ******************************************************************************/
4352 int check_mpb_migr_compatibility(struct intel_super
*super
)
4354 struct imsm_map
*map0
, *map1
;
4355 struct migr_record
*migr_rec
= super
->migr_rec
;
4358 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
4359 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
4362 dev_iter
->vol
.migr_state
== 1 &&
4363 dev_iter
->vol
.migr_type
== MIGR_GEN_MIGR
) {
4364 /* This device is migrating */
4365 map0
= get_imsm_map(dev_iter
, MAP_0
);
4366 map1
= get_imsm_map(dev_iter
, MAP_1
);
4367 if (pba_of_lba0(map0
) != pba_of_lba0(map1
))
4368 /* migration optimization area was used */
4370 if (migr_rec
->ascending_migr
== 0 &&
4371 migr_rec
->dest_depth_per_unit
> 0)
4372 /* descending reshape not supported yet */
4379 static void __free_imsm(struct intel_super
*super
, int free_disks
);
4381 /* load_imsm_mpb - read matrix metadata
4382 * allocates super->mpb to be freed by free_imsm
4384 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
4386 unsigned long long dsize
;
4387 unsigned long long sectors
;
4388 unsigned int sector_size
= super
->sector_size
;
4390 struct imsm_super
*anchor
;
4393 get_dev_size(fd
, NULL
, &dsize
);
4394 if (dsize
< 2*sector_size
) {
4396 pr_err("%s: device to small for imsm\n",
4401 if (lseek64(fd
, dsize
- (sector_size
* 2), SEEK_SET
) < 0) {
4403 pr_err("Cannot seek to anchor block on %s: %s\n",
4404 devname
, strerror(errno
));
4408 if (posix_memalign((void **)&anchor
, sector_size
, sector_size
) != 0) {
4410 pr_err("Failed to allocate imsm anchor buffer on %s\n", devname
);
4413 if ((unsigned int)read(fd
, anchor
, sector_size
) != sector_size
) {
4415 pr_err("Cannot read anchor block on %s: %s\n",
4416 devname
, strerror(errno
));
4421 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
4423 pr_err("no IMSM anchor on %s\n", devname
);
4428 __free_imsm(super
, 0);
4429 /* reload capability and hba */
4431 /* capability and hba must be updated with new super allocation */
4432 find_intel_hba_capability(fd
, super
, devname
);
4433 super
->len
= ROUND_UP(anchor
->mpb_size
, sector_size
);
4434 if (posix_memalign(&super
->buf
, MAX_SECTOR_SIZE
, super
->len
) != 0) {
4436 pr_err("unable to allocate %zu byte mpb buffer\n",
4441 memcpy(super
->buf
, anchor
, sector_size
);
4443 sectors
= mpb_sectors(anchor
, sector_size
) - 1;
4446 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
4447 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
) != 0) {
4448 pr_err("could not allocate migr_rec buffer\n");
4452 super
->clean_migration_record_by_mdmon
= 0;
4455 check_sum
= __gen_imsm_checksum(super
->anchor
);
4456 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
4458 pr_err("IMSM checksum %x != %x on %s\n",
4460 __le32_to_cpu(super
->anchor
->check_sum
),
4468 /* read the extended mpb */
4469 if (lseek64(fd
, dsize
- (sector_size
* (2 + sectors
)), SEEK_SET
) < 0) {
4471 pr_err("Cannot seek to extended mpb on %s: %s\n",
4472 devname
, strerror(errno
));
4476 if ((unsigned int)read(fd
, super
->buf
+ sector_size
,
4477 super
->len
- sector_size
) != super
->len
- sector_size
) {
4479 pr_err("Cannot read extended mpb on %s: %s\n",
4480 devname
, strerror(errno
));
4484 check_sum
= __gen_imsm_checksum(super
->anchor
);
4485 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
4487 pr_err("IMSM checksum %x != %x on %s\n",
4488 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
4496 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
);
4498 /* clears hi bits in metadata if MPB_ATTRIB_2TB_DISK not set */
4499 static void clear_hi(struct intel_super
*super
)
4501 struct imsm_super
*mpb
= super
->anchor
;
4503 if (mpb
->attributes
& MPB_ATTRIB_2TB_DISK
)
4505 for (i
= 0; i
< mpb
->num_disks
; ++i
) {
4506 struct imsm_disk
*disk
= &mpb
->disk
[i
];
4507 disk
->total_blocks_hi
= 0;
4509 for (i
= 0; i
< mpb
->num_raid_devs
; ++i
) {
4510 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
4513 for (n
= 0; n
< 2; ++n
) {
4514 struct imsm_map
*map
= get_imsm_map(dev
, n
);
4517 map
->pba_of_lba0_hi
= 0;
4518 map
->blocks_per_member_hi
= 0;
4519 map
->num_data_stripes_hi
= 0;
4525 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
4529 err
= load_imsm_mpb(fd
, super
, devname
);
4532 if (super
->sector_size
== 4096)
4533 convert_from_4k(super
);
4534 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
4537 err
= parse_raid_devices(super
);
4540 err
= load_bbm_log(super
);
4545 static void __free_imsm_disk(struct dl
*d
, int close_fd
)
4547 if (close_fd
&& d
->fd
> -1)
4557 static void free_imsm_disks(struct intel_super
*super
)
4561 while (super
->disks
) {
4563 super
->disks
= d
->next
;
4564 __free_imsm_disk(d
, 1);
4566 while (super
->disk_mgmt_list
) {
4567 d
= super
->disk_mgmt_list
;
4568 super
->disk_mgmt_list
= d
->next
;
4569 __free_imsm_disk(d
, 1);
4571 while (super
->missing
) {
4573 super
->missing
= d
->next
;
4574 __free_imsm_disk(d
, 1);
4579 /* free all the pieces hanging off of a super pointer */
4580 static void __free_imsm(struct intel_super
*super
, int free_disks
)
4582 struct intel_hba
*elem
, *next
;
4588 /* unlink capability description */
4590 if (super
->migr_rec_buf
) {
4591 free(super
->migr_rec_buf
);
4592 super
->migr_rec_buf
= NULL
;
4595 free_imsm_disks(super
);
4596 free_devlist(super
);
4600 free((void *)elem
->path
);
4606 free(super
->bbm_log
);
4610 static void free_imsm(struct intel_super
*super
)
4612 __free_imsm(super
, 1);
4613 free(super
->bb
.entries
);
4617 static void free_super_imsm(struct supertype
*st
)
4619 struct intel_super
*super
= st
->sb
;
4628 static struct intel_super
*alloc_super(void)
4630 struct intel_super
*super
= xcalloc(1, sizeof(*super
));
4632 super
->current_vol
= -1;
4633 super
->create_offset
= ~((unsigned long long) 0);
4635 super
->bb
.entries
= xmalloc(BBM_LOG_MAX_ENTRIES
*
4636 sizeof(struct md_bb_entry
));
4637 if (!super
->bb
.entries
) {
4646 * find and allocate hba and OROM/EFI based on valid fd of RAID component device
4648 static int find_intel_hba_capability(int fd
, struct intel_super
*super
, char *devname
)
4650 struct sys_dev
*hba_name
;
4653 if (fd
>= 0 && test_partition(fd
)) {
4654 pr_err("imsm: %s is a partition, cannot be used in IMSM\n",
4658 if (fd
< 0 || check_env("IMSM_NO_PLATFORM")) {
4663 hba_name
= find_disk_attached_hba(fd
, NULL
);
4666 pr_err("%s is not attached to Intel(R) RAID controller.\n",
4670 rv
= attach_hba_to_super(super
, hba_name
);
4673 struct intel_hba
*hba
= super
->hba
;
4675 pr_err("%s is attached to Intel(R) %s %s (%s),\n"
4676 " but the container is assigned to Intel(R) %s %s (",
4678 get_sys_dev_type(hba_name
->type
),
4679 hba_name
->type
== SYS_DEV_VMD
? "domain" : "RAID controller",
4680 hba_name
->pci_id
? : "Err!",
4681 get_sys_dev_type(super
->hba
->type
),
4682 hba
->type
== SYS_DEV_VMD
? "domain" : "RAID controller");
4685 fprintf(stderr
, "%s", hba
->pci_id
? : "Err!");
4687 fprintf(stderr
, ", ");
4690 fprintf(stderr
, ").\n"
4691 " Mixing devices attached to different controllers is not allowed.\n");
4695 super
->orom
= find_imsm_capability(hba_name
);
4702 /* find_missing - helper routine for load_super_imsm_all that identifies
4703 * disks that have disappeared from the system. This routine relies on
4704 * the mpb being uptodate, which it is at load time.
4706 static int find_missing(struct intel_super
*super
)
4709 struct imsm_super
*mpb
= super
->anchor
;
4711 struct imsm_disk
*disk
;
4713 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4714 disk
= __get_imsm_disk(mpb
, i
);
4715 dl
= serial_to_dl(disk
->serial
, super
);
4719 dl
= xmalloc(sizeof(*dl
));
4723 dl
->devname
= xstrdup("missing");
4725 serialcpy(dl
->serial
, disk
->serial
);
4728 dl
->next
= super
->missing
;
4729 super
->missing
= dl
;
4735 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
4737 struct intel_disk
*idisk
= disk_list
;
4740 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
4742 idisk
= idisk
->next
;
4748 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
4749 struct intel_super
*super
,
4750 struct intel_disk
**disk_list
)
4752 struct imsm_disk
*d
= &super
->disks
->disk
;
4753 struct imsm_super
*mpb
= super
->anchor
;
4756 for (i
= 0; i
< tbl_size
; i
++) {
4757 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
4758 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
4760 if (tbl_mpb
->family_num
== mpb
->family_num
) {
4761 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
4762 dprintf("mpb from %d:%d matches %d:%d\n",
4763 super
->disks
->major
,
4764 super
->disks
->minor
,
4765 table
[i
]->disks
->major
,
4766 table
[i
]->disks
->minor
);
4770 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
4771 is_configured(d
) == is_configured(tbl_d
)) &&
4772 tbl_mpb
->generation_num
< mpb
->generation_num
) {
4773 /* current version of the mpb is a
4774 * better candidate than the one in
4775 * super_table, but copy over "cross
4776 * generational" status
4778 struct intel_disk
*idisk
;
4780 dprintf("mpb from %d:%d replaces %d:%d\n",
4781 super
->disks
->major
,
4782 super
->disks
->minor
,
4783 table
[i
]->disks
->major
,
4784 table
[i
]->disks
->minor
);
4786 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
4787 if (idisk
&& is_failed(&idisk
->disk
))
4788 tbl_d
->status
|= FAILED_DISK
;
4791 struct intel_disk
*idisk
;
4792 struct imsm_disk
*disk
;
4794 /* tbl_mpb is more up to date, but copy
4795 * over cross generational status before
4798 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
4799 if (disk
&& is_failed(disk
))
4800 d
->status
|= FAILED_DISK
;
4802 idisk
= disk_list_get(d
->serial
, *disk_list
);
4805 if (disk
&& is_configured(disk
))
4806 idisk
->disk
.status
|= CONFIGURED_DISK
;
4809 dprintf("mpb from %d:%d prefer %d:%d\n",
4810 super
->disks
->major
,
4811 super
->disks
->minor
,
4812 table
[i
]->disks
->major
,
4813 table
[i
]->disks
->minor
);
4821 table
[tbl_size
++] = super
;
4825 /* update/extend the merged list of imsm_disk records */
4826 for (j
= 0; j
< mpb
->num_disks
; j
++) {
4827 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
4828 struct intel_disk
*idisk
;
4830 idisk
= disk_list_get(disk
->serial
, *disk_list
);
4832 idisk
->disk
.status
|= disk
->status
;
4833 if (is_configured(&idisk
->disk
) ||
4834 is_failed(&idisk
->disk
))
4835 idisk
->disk
.status
&= ~(SPARE_DISK
);
4837 idisk
= xcalloc(1, sizeof(*idisk
));
4838 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
4839 idisk
->disk
= *disk
;
4840 idisk
->next
= *disk_list
;
4844 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
4851 static struct intel_super
*
4852 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
4855 struct imsm_super
*mpb
= super
->anchor
;
4859 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4860 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
4861 struct intel_disk
*idisk
;
4863 idisk
= disk_list_get(disk
->serial
, disk_list
);
4865 if (idisk
->owner
== owner
||
4866 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
4869 dprintf("'%.16s' owner %d != %d\n",
4870 disk
->serial
, idisk
->owner
,
4873 dprintf("unknown disk %x [%d]: %.16s\n",
4874 __le32_to_cpu(mpb
->family_num
), i
,
4880 if (ok_count
== mpb
->num_disks
)
4885 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
4887 struct intel_super
*s
;
4889 for (s
= super_list
; s
; s
= s
->next
) {
4890 if (family_num
!= s
->anchor
->family_num
)
4892 pr_err("Conflict, offlining family %#x on '%s'\n",
4893 __le32_to_cpu(family_num
), s
->disks
->devname
);
4897 static struct intel_super
*
4898 imsm_thunderdome(struct intel_super
**super_list
, int len
)
4900 struct intel_super
*super_table
[len
];
4901 struct intel_disk
*disk_list
= NULL
;
4902 struct intel_super
*champion
, *spare
;
4903 struct intel_super
*s
, **del
;
4908 memset(super_table
, 0, sizeof(super_table
));
4909 for (s
= *super_list
; s
; s
= s
->next
)
4910 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
4912 for (i
= 0; i
< tbl_size
; i
++) {
4913 struct imsm_disk
*d
;
4914 struct intel_disk
*idisk
;
4915 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
4918 d
= &s
->disks
->disk
;
4920 /* 'd' must appear in merged disk list for its
4921 * configuration to be valid
4923 idisk
= disk_list_get(d
->serial
, disk_list
);
4924 if (idisk
&& idisk
->owner
== i
)
4925 s
= validate_members(s
, disk_list
, i
);
4930 dprintf("marking family: %#x from %d:%d offline\n",
4932 super_table
[i
]->disks
->major
,
4933 super_table
[i
]->disks
->minor
);
4937 /* This is where the mdadm implementation differs from the Windows
4938 * driver which has no strict concept of a container. We can only
4939 * assemble one family from a container, so when returning a prodigal
4940 * array member to this system the code will not be able to disambiguate
4941 * the container contents that should be assembled ("foreign" versus
4942 * "local"). It requires user intervention to set the orig_family_num
4943 * to a new value to establish a new container. The Windows driver in
4944 * this situation fixes up the volume name in place and manages the
4945 * foreign array as an independent entity.
4950 for (i
= 0; i
< tbl_size
; i
++) {
4951 struct intel_super
*tbl_ent
= super_table
[i
];
4957 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
4962 if (s
&& !is_spare
) {
4963 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
4965 } else if (!s
&& !is_spare
)
4978 pr_err("Chose family %#x on '%s', assemble conflicts to new container with '--update=uuid'\n",
4979 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
4981 /* collect all dl's onto 'champion', and update them to
4982 * champion's version of the status
4984 for (s
= *super_list
; s
; s
= s
->next
) {
4985 struct imsm_super
*mpb
= champion
->anchor
;
4986 struct dl
*dl
= s
->disks
;
4991 mpb
->attributes
|= s
->anchor
->attributes
& MPB_ATTRIB_2TB_DISK
;
4993 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4994 struct imsm_disk
*disk
;
4996 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
4999 /* only set index on disks that are a member of
5000 * a populated contianer, i.e. one with
5003 if (is_failed(&dl
->disk
))
5005 else if (is_spare(&dl
->disk
))
5011 if (i
>= mpb
->num_disks
) {
5012 struct intel_disk
*idisk
;
5014 idisk
= disk_list_get(dl
->serial
, disk_list
);
5015 if (idisk
&& is_spare(&idisk
->disk
) &&
5016 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
5024 dl
->next
= champion
->disks
;
5025 champion
->disks
= dl
;
5029 /* delete 'champion' from super_list */
5030 for (del
= super_list
; *del
; ) {
5031 if (*del
== champion
) {
5032 *del
= (*del
)->next
;
5035 del
= &(*del
)->next
;
5037 champion
->next
= NULL
;
5041 struct intel_disk
*idisk
= disk_list
;
5043 disk_list
= disk_list
->next
;
5051 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
);
5052 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
5053 int major
, int minor
, int keep_fd
);
5055 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
5056 int *max
, int keep_fd
);
5058 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
5059 char *devname
, struct md_list
*devlist
,
5062 struct intel_super
*super_list
= NULL
;
5063 struct intel_super
*super
= NULL
;
5068 /* 'fd' is an opened container */
5069 err
= get_sra_super_block(fd
, &super_list
, devname
, &i
, keep_fd
);
5071 /* get super block from devlist devices */
5072 err
= get_devlist_super_block(devlist
, &super_list
, &i
, keep_fd
);
5075 /* all mpbs enter, maybe one leaves */
5076 super
= imsm_thunderdome(&super_list
, i
);
5082 if (find_missing(super
) != 0) {
5088 /* load migration record */
5089 err
= load_imsm_migr_rec(super
);
5091 /* migration is in progress,
5092 * but migr_rec cannot be loaded,
5098 /* Check migration compatibility */
5099 if (err
== 0 && check_mpb_migr_compatibility(super
) != 0) {
5100 pr_err("Unsupported migration detected");
5102 fprintf(stderr
, " on %s\n", devname
);
5104 fprintf(stderr
, " (IMSM).\n");
5113 while (super_list
) {
5114 struct intel_super
*s
= super_list
;
5116 super_list
= super_list
->next
;
5125 strcpy(st
->container_devnm
, fd2devnm(fd
));
5127 st
->container_devnm
[0] = 0;
5128 if (err
== 0 && st
->ss
== NULL
) {
5129 st
->ss
= &super_imsm
;
5130 st
->minor_version
= 0;
5131 st
->max_devs
= IMSM_MAX_DEVICES
;
5137 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
5138 int *max
, int keep_fd
)
5140 struct md_list
*tmpdev
;
5144 for (i
= 0, tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
5145 if (tmpdev
->used
!= 1)
5147 if (tmpdev
->container
== 1) {
5149 int fd
= dev_open(tmpdev
->devname
, O_RDONLY
|O_EXCL
);
5151 pr_err("cannot open device %s: %s\n",
5152 tmpdev
->devname
, strerror(errno
));
5156 err
= get_sra_super_block(fd
, super_list
,
5157 tmpdev
->devname
, &lmax
,
5166 int major
= major(tmpdev
->st_rdev
);
5167 int minor
= minor(tmpdev
->st_rdev
);
5168 err
= get_super_block(super_list
,
5185 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
5186 int major
, int minor
, int keep_fd
)
5188 struct intel_super
*s
;
5200 sprintf(nm
, "%d:%d", major
, minor
);
5201 dfd
= dev_open(nm
, O_RDWR
);
5207 if (!get_dev_sector_size(dfd
, NULL
, &s
->sector_size
)) {
5211 find_intel_hba_capability(dfd
, s
, devname
);
5212 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
5214 /* retry the load if we might have raced against mdmon */
5215 if (err
== 3 && devnm
&& mdmon_running(devnm
))
5216 for (retry
= 0; retry
< 3; retry
++) {
5218 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
5224 s
->next
= *super_list
;
5232 if (dfd
>= 0 && !keep_fd
)
5239 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
)
5246 sra
= sysfs_read(fd
, NULL
, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
5250 if (sra
->array
.major_version
!= -1 ||
5251 sra
->array
.minor_version
!= -2 ||
5252 strcmp(sra
->text_version
, "imsm") != 0) {
5257 devnm
= fd2devnm(fd
);
5258 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
5259 if (get_super_block(super_list
, devnm
, devname
,
5260 sd
->disk
.major
, sd
->disk
.minor
, keep_fd
) != 0) {
5271 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
5273 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
, NULL
, 1);
5276 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
5278 struct intel_super
*super
;
5282 if (test_partition(fd
))
5283 /* IMSM not allowed on partitions */
5286 free_super_imsm(st
);
5288 super
= alloc_super();
5292 if (!get_dev_sector_size(fd
, NULL
, &super
->sector_size
)) {
5296 /* Load hba and capabilities if they exist.
5297 * But do not preclude loading metadata in case capabilities or hba are
5298 * non-compliant and ignore_hw_compat is set.
5300 rv
= find_intel_hba_capability(fd
, super
, devname
);
5301 /* no orom/efi or non-intel hba of the disk */
5302 if (rv
!= 0 && st
->ignore_hw_compat
== 0) {
5304 pr_err("No OROM/EFI properties for %s\n", devname
);
5308 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
5310 /* retry the load if we might have raced against mdmon */
5312 struct mdstat_ent
*mdstat
= NULL
;
5313 char *name
= fd2kname(fd
);
5316 mdstat
= mdstat_by_component(name
);
5318 if (mdstat
&& mdmon_running(mdstat
->devnm
) && getpid() != mdmon_pid(mdstat
->devnm
)) {
5319 for (retry
= 0; retry
< 3; retry
++) {
5321 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
5327 free_mdstat(mdstat
);
5332 pr_err("Failed to load all information sections on %s\n", devname
);
5338 if (st
->ss
== NULL
) {
5339 st
->ss
= &super_imsm
;
5340 st
->minor_version
= 0;
5341 st
->max_devs
= IMSM_MAX_DEVICES
;
5344 /* load migration record */
5345 if (load_imsm_migr_rec(super
) == 0) {
5346 /* Check for unsupported migration features */
5347 if (check_mpb_migr_compatibility(super
) != 0) {
5348 pr_err("Unsupported migration detected");
5350 fprintf(stderr
, " on %s\n", devname
);
5352 fprintf(stderr
, " (IMSM).\n");
5360 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
5362 if (info
->level
== 1)
5364 return info
->chunk_size
>> 9;
5367 static unsigned long long info_to_blocks_per_member(mdu_array_info_t
*info
,
5368 unsigned long long size
)
5370 if (info
->level
== 1)
5373 return (size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
5376 static void imsm_update_version_info(struct intel_super
*super
)
5378 /* update the version and attributes */
5379 struct imsm_super
*mpb
= super
->anchor
;
5381 struct imsm_dev
*dev
;
5382 struct imsm_map
*map
;
5385 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5386 dev
= get_imsm_dev(super
, i
);
5387 map
= get_imsm_map(dev
, MAP_0
);
5388 if (__le32_to_cpu(dev
->size_high
) > 0)
5389 mpb
->attributes
|= MPB_ATTRIB_2TB
;
5391 /* FIXME detect when an array spans a port multiplier */
5393 mpb
->attributes
|= MPB_ATTRIB_PM
;
5396 if (mpb
->num_raid_devs
> 1 ||
5397 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
5398 version
= MPB_VERSION_ATTRIBS
;
5399 switch (get_imsm_raid_level(map
)) {
5400 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
5401 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
5402 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
5403 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
5406 if (map
->num_members
>= 5)
5407 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
5408 else if (dev
->status
== DEV_CLONE_N_GO
)
5409 version
= MPB_VERSION_CNG
;
5410 else if (get_imsm_raid_level(map
) == 5)
5411 version
= MPB_VERSION_RAID5
;
5412 else if (map
->num_members
>= 3)
5413 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
5414 else if (get_imsm_raid_level(map
) == 1)
5415 version
= MPB_VERSION_RAID1
;
5417 version
= MPB_VERSION_RAID0
;
5419 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
5423 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
5425 struct imsm_super
*mpb
= super
->anchor
;
5426 char *reason
= NULL
;
5428 size_t len
= strlen(name
);
5432 while (isspace(start
[len
- 1]))
5434 while (*start
&& isspace(*start
))
5436 memmove(name
, start
, len
+ 1);
5439 if (len
> MAX_RAID_SERIAL_LEN
)
5440 reason
= "must be 16 characters or less";
5442 reason
= "must be a non-empty string";
5444 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5445 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
5447 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
5448 reason
= "already exists";
5453 if (reason
&& !quiet
)
5454 pr_err("imsm volume name %s\n", reason
);
5459 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
5460 struct shape
*s
, char *name
,
5461 char *homehost
, int *uuid
,
5462 long long data_offset
)
5464 /* We are creating a volume inside a pre-existing container.
5465 * so st->sb is already set.
5467 struct intel_super
*super
= st
->sb
;
5468 unsigned int sector_size
= super
->sector_size
;
5469 struct imsm_super
*mpb
= super
->anchor
;
5470 struct intel_dev
*dv
;
5471 struct imsm_dev
*dev
;
5472 struct imsm_vol
*vol
;
5473 struct imsm_map
*map
;
5474 int idx
= mpb
->num_raid_devs
;
5477 unsigned long long array_blocks
;
5478 size_t size_old
, size_new
;
5479 unsigned int data_disks
;
5480 unsigned long long size_per_member
;
5482 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
5483 pr_err("This imsm-container already has the maximum of %d volumes\n", super
->orom
->vpa
);
5487 /* ensure the mpb is large enough for the new data */
5488 size_old
= __le32_to_cpu(mpb
->mpb_size
);
5489 size_new
= disks_to_mpb_size(info
->nr_disks
);
5490 if (size_new
> size_old
) {
5492 size_t size_round
= ROUND_UP(size_new
, sector_size
);
5494 if (posix_memalign(&mpb_new
, sector_size
, size_round
) != 0) {
5495 pr_err("could not allocate new mpb\n");
5498 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
5499 MIGR_REC_BUF_SECTORS
*
5500 MAX_SECTOR_SIZE
) != 0) {
5501 pr_err("could not allocate migr_rec buffer\n");
5507 memcpy(mpb_new
, mpb
, size_old
);
5510 super
->anchor
= mpb_new
;
5511 mpb
->mpb_size
= __cpu_to_le32(size_new
);
5512 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
5513 super
->len
= size_round
;
5515 super
->current_vol
= idx
;
5517 /* handle 'failed_disks' by either:
5518 * a) create dummy disk entries in the table if this the first
5519 * volume in the array. We add them here as this is the only
5520 * opportunity to add them. add_to_super_imsm_volume()
5521 * handles the non-failed disks and continues incrementing
5523 * b) validate that 'failed_disks' matches the current number
5524 * of missing disks if the container is populated
5526 if (super
->current_vol
== 0) {
5528 for (i
= 0; i
< info
->failed_disks
; i
++) {
5529 struct imsm_disk
*disk
;
5532 disk
= __get_imsm_disk(mpb
, i
);
5533 disk
->status
= CONFIGURED_DISK
| FAILED_DISK
;
5534 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
5535 snprintf((char *) disk
->serial
, MAX_RAID_SERIAL_LEN
,
5536 "missing:%d", (__u8
)i
);
5538 find_missing(super
);
5543 for (d
= super
->missing
; d
; d
= d
->next
)
5545 if (info
->failed_disks
> missing
) {
5546 pr_err("unable to add 'missing' disk to container\n");
5551 if (!check_name(super
, name
, 0))
5553 dv
= xmalloc(sizeof(*dv
));
5554 dev
= xcalloc(1, sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
5556 * Explicitly allow truncating to not confuse gcc's
5557 * -Werror=stringop-truncation
5559 namelen
= min((int) strlen(name
), MAX_RAID_SERIAL_LEN
);
5560 memcpy(dev
->volume
, name
, namelen
);
5561 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
5562 info
->layout
, info
->chunk_size
,
5563 s
->size
* BLOCKS_PER_KB
);
5564 data_disks
= get_data_disks(info
->level
, info
->layout
,
5566 array_blocks
= round_size_to_mb(array_blocks
, data_disks
);
5567 size_per_member
= array_blocks
/ data_disks
;
5569 set_imsm_dev_size(dev
, array_blocks
);
5570 dev
->status
= (DEV_READ_COALESCING
| DEV_WRITE_COALESCING
);
5572 vol
->migr_state
= 0;
5573 set_migr_type(dev
, MIGR_INIT
);
5574 vol
->dirty
= !info
->state
;
5575 set_vol_curr_migr_unit(dev
, 0);
5576 map
= get_imsm_map(dev
, MAP_0
);
5577 set_pba_of_lba0(map
, super
->create_offset
);
5578 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
5579 map
->failed_disk_num
= ~0;
5580 if (info
->level
> 0)
5581 map
->map_state
= (info
->state
? IMSM_T_STATE_NORMAL
5582 : IMSM_T_STATE_UNINITIALIZED
);
5584 map
->map_state
= info
->failed_disks
? IMSM_T_STATE_FAILED
:
5585 IMSM_T_STATE_NORMAL
;
5588 if (info
->level
== 1 && info
->raid_disks
> 2) {
5591 pr_err("imsm does not support more than 2 disksin a raid1 volume\n");
5595 map
->raid_level
= info
->level
;
5596 if (info
->level
== 10)
5597 map
->raid_level
= 1;
5598 set_num_domains(map
);
5600 size_per_member
+= NUM_BLOCKS_DIRTY_STRIPE_REGION
;
5601 set_blocks_per_member(map
, info_to_blocks_per_member(info
,
5605 map
->num_members
= info
->raid_disks
;
5606 update_num_data_stripes(map
, array_blocks
);
5607 for (i
= 0; i
< map
->num_members
; i
++) {
5608 /* initialized in add_to_super */
5609 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
5611 mpb
->num_raid_devs
++;
5612 mpb
->num_raid_devs_created
++;
5613 dev
->my_vol_raid_dev_num
= mpb
->num_raid_devs_created
;
5615 if (s
->consistency_policy
<= CONSISTENCY_POLICY_RESYNC
) {
5616 dev
->rwh_policy
= RWH_MULTIPLE_OFF
;
5617 } else if (s
->consistency_policy
== CONSISTENCY_POLICY_PPL
) {
5618 dev
->rwh_policy
= RWH_MULTIPLE_DISTRIBUTED
;
5622 pr_err("imsm does not support consistency policy %s\n",
5623 map_num(consistency_policies
, s
->consistency_policy
));
5628 dv
->index
= super
->current_vol
;
5629 dv
->next
= super
->devlist
;
5630 super
->devlist
= dv
;
5632 imsm_update_version_info(super
);
5637 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
5638 struct shape
*s
, char *name
,
5639 char *homehost
, int *uuid
,
5640 unsigned long long data_offset
)
5642 /* This is primarily called by Create when creating a new array.
5643 * We will then get add_to_super called for each component, and then
5644 * write_init_super called to write it out to each device.
5645 * For IMSM, Create can create on fresh devices or on a pre-existing
5647 * To create on a pre-existing array a different method will be called.
5648 * This one is just for fresh drives.
5650 struct intel_super
*super
;
5651 struct imsm_super
*mpb
;
5655 if (data_offset
!= INVALID_SECTORS
) {
5656 pr_err("data-offset not supported by imsm\n");
5661 return init_super_imsm_volume(st
, info
, s
, name
, homehost
, uuid
,
5665 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
5667 mpb_size
= MAX_SECTOR_SIZE
;
5669 super
= alloc_super();
5671 posix_memalign(&super
->buf
, MAX_SECTOR_SIZE
, mpb_size
) != 0) {
5676 pr_err("could not allocate superblock\n");
5679 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
5680 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
) != 0) {
5681 pr_err("could not allocate migr_rec buffer\n");
5686 memset(super
->buf
, 0, mpb_size
);
5688 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5692 /* zeroing superblock */
5696 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5698 version
= (char *) mpb
->sig
;
5699 strcpy(version
, MPB_SIGNATURE
);
5700 version
+= strlen(MPB_SIGNATURE
);
5701 strcpy(version
, MPB_VERSION_RAID0
);
5706 static int drive_validate_sector_size(struct intel_super
*super
, struct dl
*dl
)
5708 unsigned int member_sector_size
;
5711 pr_err("Invalid file descriptor for %s\n", dl
->devname
);
5715 if (!get_dev_sector_size(dl
->fd
, dl
->devname
, &member_sector_size
))
5717 if (member_sector_size
!= super
->sector_size
)
5722 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
5723 int fd
, char *devname
)
5725 struct intel_super
*super
= st
->sb
;
5726 struct imsm_super
*mpb
= super
->anchor
;
5727 struct imsm_disk
*_disk
;
5728 struct imsm_dev
*dev
;
5729 struct imsm_map
*map
;
5733 dev
= get_imsm_dev(super
, super
->current_vol
);
5734 map
= get_imsm_map(dev
, MAP_0
);
5736 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
5737 pr_err("%s: Cannot add spare devices to IMSM volume\n",
5743 /* we're doing autolayout so grab the pre-marked (in
5744 * validate_geometry) raid_disk
5746 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5747 if (dl
->raiddisk
== dk
->raid_disk
)
5750 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5751 if (dl
->major
== dk
->major
&&
5752 dl
->minor
== dk
->minor
)
5757 pr_err("%s is not a member of the same container\n", devname
);
5761 if (mpb
->num_disks
== 0)
5762 if (!get_dev_sector_size(dl
->fd
, dl
->devname
,
5763 &super
->sector_size
))
5766 if (!drive_validate_sector_size(super
, dl
)) {
5767 pr_err("Combining drives of different sector size in one volume is not allowed\n");
5771 /* add a pristine spare to the metadata */
5772 if (dl
->index
< 0) {
5773 dl
->index
= super
->anchor
->num_disks
;
5774 super
->anchor
->num_disks
++;
5776 /* Check the device has not already been added */
5777 slot
= get_imsm_disk_slot(map
, dl
->index
);
5779 (get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
) & IMSM_ORD_REBUILD
) == 0) {
5780 pr_err("%s has been included in this array twice\n",
5784 set_imsm_ord_tbl_ent(map
, dk
->raid_disk
, dl
->index
);
5785 dl
->disk
.status
= CONFIGURED_DISK
;
5787 /* update size of 'missing' disks to be at least as large as the
5788 * largest acitve member (we only have dummy missing disks when
5789 * creating the first volume)
5791 if (super
->current_vol
== 0) {
5792 for (df
= super
->missing
; df
; df
= df
->next
) {
5793 if (total_blocks(&dl
->disk
) > total_blocks(&df
->disk
))
5794 set_total_blocks(&df
->disk
, total_blocks(&dl
->disk
));
5795 _disk
= __get_imsm_disk(mpb
, df
->index
);
5800 /* refresh unset/failed slots to point to valid 'missing' entries */
5801 for (df
= super
->missing
; df
; df
= df
->next
)
5802 for (slot
= 0; slot
< mpb
->num_disks
; slot
++) {
5803 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
5805 if ((ord
& IMSM_ORD_REBUILD
) == 0)
5807 set_imsm_ord_tbl_ent(map
, slot
, df
->index
| IMSM_ORD_REBUILD
);
5808 if (is_gen_migration(dev
)) {
5809 struct imsm_map
*map2
= get_imsm_map(dev
,
5811 int slot2
= get_imsm_disk_slot(map2
, df
->index
);
5812 if (slot2
< map2
->num_members
&& slot2
>= 0) {
5813 __u32 ord2
= get_imsm_ord_tbl_ent(dev
,
5816 if ((unsigned)df
->index
==
5818 set_imsm_ord_tbl_ent(map2
,
5824 dprintf("set slot:%d to missing disk:%d\n", slot
, df
->index
);
5828 /* if we are creating the first raid device update the family number */
5829 if (super
->current_vol
== 0) {
5831 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
5833 _disk
= __get_imsm_disk(mpb
, dl
->index
);
5834 if (!_dev
|| !_disk
) {
5835 pr_err("BUG mpb setup error\n");
5841 sum
+= __gen_imsm_checksum(mpb
);
5842 mpb
->family_num
= __cpu_to_le32(sum
);
5843 mpb
->orig_family_num
= mpb
->family_num
;
5844 mpb
->creation_time
= __cpu_to_le64((__u64
)time(NULL
));
5846 super
->current_disk
= dl
;
5851 * Function marks disk as spare and restores disk serial
5852 * in case it was previously marked as failed by takeover operation
5854 * -1 : critical error
5855 * 0 : disk is marked as spare but serial is not set
5858 int mark_spare(struct dl
*disk
)
5860 __u8 serial
[MAX_RAID_SERIAL_LEN
];
5867 if (!imsm_read_serial(disk
->fd
, NULL
, serial
, MAX_RAID_SERIAL_LEN
)) {
5868 /* Restore disk serial number, because takeover marks disk
5869 * as failed and adds to serial ':0' before it becomes
5872 serialcpy(disk
->serial
, serial
);
5873 serialcpy(disk
->disk
.serial
, serial
);
5876 disk
->disk
.status
= SPARE_DISK
;
5883 static int write_super_imsm_spare(struct intel_super
*super
, struct dl
*d
);
5885 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
5886 int fd
, char *devname
,
5887 unsigned long long data_offset
)
5889 struct intel_super
*super
= st
->sb
;
5891 unsigned long long size
;
5892 unsigned int member_sector_size
;
5897 /* If we are on an RAID enabled platform check that the disk is
5898 * attached to the raid controller.
5899 * We do not need to test disks attachment for container based additions,
5900 * they shall be already tested when container was created/assembled.
5902 rv
= find_intel_hba_capability(fd
, super
, devname
);
5903 /* no orom/efi or non-intel hba of the disk */
5905 dprintf("capability: %p fd: %d ret: %d\n",
5906 super
->orom
, fd
, rv
);
5910 if (super
->current_vol
>= 0)
5911 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
5914 dd
= xcalloc(sizeof(*dd
), 1);
5915 dd
->major
= major(stb
.st_rdev
);
5916 dd
->minor
= minor(stb
.st_rdev
);
5917 dd
->devname
= devname
? xstrdup(devname
) : NULL
;
5920 dd
->action
= DISK_ADD
;
5921 rv
= imsm_read_serial(fd
, devname
, dd
->serial
, MAX_RAID_SERIAL_LEN
);
5923 pr_err("failed to retrieve scsi serial, aborting\n");
5924 __free_imsm_disk(dd
, 0);
5928 if (super
->hba
&& ((super
->hba
->type
== SYS_DEV_NVME
) ||
5929 (super
->hba
->type
== SYS_DEV_VMD
))) {
5931 char cntrl_path
[PATH_MAX
];
5933 char pci_dev_path
[PATH_MAX
];
5935 if (!diskfd_to_devpath(fd
, 2, pci_dev_path
) ||
5936 !diskfd_to_devpath(fd
, 1, cntrl_path
)) {
5937 pr_err("failed to get dev paths, aborting\n");
5938 __free_imsm_disk(dd
, 0);
5942 cntrl_name
= basename(cntrl_path
);
5943 if (is_multipath_nvme(fd
))
5944 pr_err("%s controller supports Multi-Path I/O, Intel (R) VROC does not support multipathing\n",
5947 if (devpath_to_vendor(pci_dev_path
) == 0x8086) {
5949 * If Intel's NVMe drive has serial ended with
5950 * "-A","-B","-1" or "-2" it means that this is "x8"
5951 * device (double drive on single PCIe card).
5952 * User should be warned about potential data loss.
5954 for (i
= MAX_RAID_SERIAL_LEN
-1; i
> 0; i
--) {
5955 /* Skip empty character at the end */
5956 if (dd
->serial
[i
] == 0)
5959 if (((dd
->serial
[i
] == 'A') ||
5960 (dd
->serial
[i
] == 'B') ||
5961 (dd
->serial
[i
] == '1') ||
5962 (dd
->serial
[i
] == '2')) &&
5963 (dd
->serial
[i
-1] == '-'))
5964 pr_err("\tThe action you are about to take may put your data at risk.\n"
5965 "\tPlease note that x8 devices may consist of two separate x4 devices "
5966 "located on a single PCIe port.\n"
5967 "\tRAID 0 is the only supported configuration for this type of x8 device.\n");
5970 } else if (super
->hba
->type
== SYS_DEV_VMD
&& super
->orom
&&
5971 !imsm_orom_has_tpv_support(super
->orom
)) {
5972 pr_err("\tPlatform configuration does not support non-Intel NVMe drives.\n"
5973 "\tPlease refer to Intel(R) RSTe/VROC user guide.\n");
5974 __free_imsm_disk(dd
, 0);
5979 get_dev_size(fd
, NULL
, &size
);
5980 if (!get_dev_sector_size(fd
, NULL
, &member_sector_size
)) {
5981 __free_imsm_disk(dd
, 0);
5985 if (super
->sector_size
== 0) {
5986 /* this a first device, so sector_size is not set yet */
5987 super
->sector_size
= member_sector_size
;
5990 /* clear migr_rec when adding disk to container */
5991 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
);
5992 if (lseek64(fd
, size
- MIGR_REC_SECTOR_POSITION
*member_sector_size
,
5994 if ((unsigned int)write(fd
, super
->migr_rec_buf
,
5995 MIGR_REC_BUF_SECTORS
*member_sector_size
) !=
5996 MIGR_REC_BUF_SECTORS
*member_sector_size
)
5997 perror("Write migr_rec failed");
6001 serialcpy(dd
->disk
.serial
, dd
->serial
);
6002 set_total_blocks(&dd
->disk
, size
);
6003 if (__le32_to_cpu(dd
->disk
.total_blocks_hi
) > 0) {
6004 struct imsm_super
*mpb
= super
->anchor
;
6005 mpb
->attributes
|= MPB_ATTRIB_2TB_DISK
;
6008 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
6009 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
6011 dd
->disk
.scsi_id
= __cpu_to_le32(0);
6013 if (st
->update_tail
) {
6014 dd
->next
= super
->disk_mgmt_list
;
6015 super
->disk_mgmt_list
= dd
;
6017 /* this is called outside of mdmon
6018 * write initial spare metadata
6019 * mdmon will overwrite it.
6021 dd
->next
= super
->disks
;
6023 write_super_imsm_spare(super
, dd
);
6029 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
6031 struct intel_super
*super
= st
->sb
;
6034 /* remove from super works only in mdmon - for communication
6035 * manager - monitor. Check if communication memory buffer
6038 if (!st
->update_tail
) {
6039 pr_err("shall be used in mdmon context only\n");
6042 dd
= xcalloc(1, sizeof(*dd
));
6043 dd
->major
= dk
->major
;
6044 dd
->minor
= dk
->minor
;
6047 dd
->action
= DISK_REMOVE
;
6049 dd
->next
= super
->disk_mgmt_list
;
6050 super
->disk_mgmt_list
= dd
;
6055 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
6058 char buf
[MAX_SECTOR_SIZE
];
6059 struct imsm_super anchor
;
6060 } spare_record
__attribute__ ((aligned(MAX_SECTOR_SIZE
)));
6063 static int write_super_imsm_spare(struct intel_super
*super
, struct dl
*d
)
6065 struct imsm_super
*mpb
= super
->anchor
;
6066 struct imsm_super
*spare
= &spare_record
.anchor
;
6072 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
));
6073 spare
->generation_num
= __cpu_to_le32(1UL);
6074 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
6075 spare
->num_disks
= 1;
6076 spare
->num_raid_devs
= 0;
6077 spare
->cache_size
= mpb
->cache_size
;
6078 spare
->pwr_cycle_count
= __cpu_to_le32(1);
6080 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
6081 MPB_SIGNATURE MPB_VERSION_RAID0
);
6083 spare
->disk
[0] = d
->disk
;
6084 if (__le32_to_cpu(d
->disk
.total_blocks_hi
) > 0)
6085 spare
->attributes
|= MPB_ATTRIB_2TB_DISK
;
6087 if (super
->sector_size
== 4096)
6088 convert_to_4k_imsm_disk(&spare
->disk
[0]);
6090 sum
= __gen_imsm_checksum(spare
);
6091 spare
->family_num
= __cpu_to_le32(sum
);
6092 spare
->orig_family_num
= 0;
6093 sum
= __gen_imsm_checksum(spare
);
6094 spare
->check_sum
= __cpu_to_le32(sum
);
6096 if (store_imsm_mpb(d
->fd
, spare
)) {
6097 pr_err("failed for device %d:%d %s\n",
6098 d
->major
, d
->minor
, strerror(errno
));
6104 /* spare records have their own family number and do not have any defined raid
6107 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
6111 for (d
= super
->disks
; d
; d
= d
->next
) {
6115 if (write_super_imsm_spare(super
, d
))
6127 static int write_super_imsm(struct supertype
*st
, int doclose
)
6129 struct intel_super
*super
= st
->sb
;
6130 unsigned int sector_size
= super
->sector_size
;
6131 struct imsm_super
*mpb
= super
->anchor
;
6137 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
6139 int clear_migration_record
= 1;
6142 /* 'generation' is incremented everytime the metadata is written */
6143 generation
= __le32_to_cpu(mpb
->generation_num
);
6145 mpb
->generation_num
= __cpu_to_le32(generation
);
6147 /* fix up cases where previous mdadm releases failed to set
6150 if (mpb
->orig_family_num
== 0)
6151 mpb
->orig_family_num
= mpb
->family_num
;
6153 for (d
= super
->disks
; d
; d
= d
->next
) {
6157 mpb
->disk
[d
->index
] = d
->disk
;
6161 for (d
= super
->missing
; d
; d
= d
->next
) {
6162 mpb
->disk
[d
->index
] = d
->disk
;
6165 mpb
->num_disks
= num_disks
;
6166 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
6168 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6169 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
6170 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
6172 imsm_copy_dev(dev
, dev2
);
6173 mpb_size
+= sizeof_imsm_dev(dev
, 0);
6175 if (is_gen_migration(dev2
))
6176 clear_migration_record
= 0;
6179 bbm_log_size
= get_imsm_bbm_log_size(super
->bbm_log
);
6182 memcpy((void *)mpb
+ mpb_size
, super
->bbm_log
, bbm_log_size
);
6183 mpb
->attributes
|= MPB_ATTRIB_BBM
;
6185 mpb
->attributes
&= ~MPB_ATTRIB_BBM
;
6187 super
->anchor
->bbm_log_size
= __cpu_to_le32(bbm_log_size
);
6188 mpb_size
+= bbm_log_size
;
6189 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
6192 assert(super
->len
== 0 || mpb_size
<= super
->len
);
6195 /* recalculate checksum */
6196 sum
= __gen_imsm_checksum(mpb
);
6197 mpb
->check_sum
= __cpu_to_le32(sum
);
6199 if (super
->clean_migration_record_by_mdmon
) {
6200 clear_migration_record
= 1;
6201 super
->clean_migration_record_by_mdmon
= 0;
6203 if (clear_migration_record
)
6204 memset(super
->migr_rec_buf
, 0,
6205 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
);
6207 if (sector_size
== 4096)
6208 convert_to_4k(super
);
6210 /* write the mpb for disks that compose raid devices */
6211 for (d
= super
->disks
; d
; d
= d
->next
) {
6212 if (d
->index
< 0 || is_failed(&d
->disk
))
6215 if (clear_migration_record
) {
6216 unsigned long long dsize
;
6218 get_dev_size(d
->fd
, NULL
, &dsize
);
6219 if (lseek64(d
->fd
, dsize
- sector_size
,
6221 if ((unsigned int)write(d
->fd
,
6222 super
->migr_rec_buf
,
6223 MIGR_REC_BUF_SECTORS
*sector_size
) !=
6224 MIGR_REC_BUF_SECTORS
*sector_size
)
6225 perror("Write migr_rec failed");
6229 if (store_imsm_mpb(d
->fd
, mpb
))
6231 "failed for device %d:%d (fd: %d)%s\n",
6233 d
->fd
, strerror(errno
));
6242 return write_super_imsm_spares(super
, doclose
);
6247 static int create_array(struct supertype
*st
, int dev_idx
)
6250 struct imsm_update_create_array
*u
;
6251 struct intel_super
*super
= st
->sb
;
6252 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
6253 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
6254 struct disk_info
*inf
;
6255 struct imsm_disk
*disk
;
6258 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
6259 sizeof(*inf
) * map
->num_members
;
6261 u
->type
= update_create_array
;
6262 u
->dev_idx
= dev_idx
;
6263 imsm_copy_dev(&u
->dev
, dev
);
6264 inf
= get_disk_info(u
);
6265 for (i
= 0; i
< map
->num_members
; i
++) {
6266 int idx
= get_imsm_disk_idx(dev
, i
, MAP_X
);
6268 disk
= get_imsm_disk(super
, idx
);
6270 disk
= get_imsm_missing(super
, idx
);
6271 serialcpy(inf
[i
].serial
, disk
->serial
);
6273 append_metadata_update(st
, u
, len
);
6278 static int mgmt_disk(struct supertype
*st
)
6280 struct intel_super
*super
= st
->sb
;
6282 struct imsm_update_add_remove_disk
*u
;
6284 if (!super
->disk_mgmt_list
)
6289 u
->type
= update_add_remove_disk
;
6290 append_metadata_update(st
, u
, len
);
6295 __u32
crc32c_le(__u32 crc
, unsigned char const *p
, size_t len
);
6297 static int write_ppl_header(unsigned long long ppl_sector
, int fd
, void *buf
)
6299 struct ppl_header
*ppl_hdr
= buf
;
6302 ppl_hdr
->checksum
= __cpu_to_le32(~crc32c_le(~0, buf
, PPL_HEADER_SIZE
));
6304 if (lseek64(fd
, ppl_sector
* 512, SEEK_SET
) < 0) {
6306 perror("Failed to seek to PPL header location");
6310 if (write(fd
, buf
, PPL_HEADER_SIZE
) != PPL_HEADER_SIZE
) {
6312 perror("Write PPL header failed");
6321 static int write_init_ppl_imsm(struct supertype
*st
, struct mdinfo
*info
, int fd
)
6323 struct intel_super
*super
= st
->sb
;
6325 struct ppl_header
*ppl_hdr
;
6328 /* first clear entire ppl space */
6329 ret
= zero_disk_range(fd
, info
->ppl_sector
, info
->ppl_size
);
6333 ret
= posix_memalign(&buf
, MAX_SECTOR_SIZE
, PPL_HEADER_SIZE
);
6335 pr_err("Failed to allocate PPL header buffer\n");
6339 memset(buf
, 0, PPL_HEADER_SIZE
);
6341 memset(ppl_hdr
->reserved
, 0xff, PPL_HDR_RESERVED
);
6342 ppl_hdr
->signature
= __cpu_to_le32(super
->anchor
->orig_family_num
);
6344 if (info
->mismatch_cnt
) {
6346 * We are overwriting an invalid ppl. Make one entry with wrong
6347 * checksum to prevent the kernel from skipping resync.
6349 ppl_hdr
->entries_count
= __cpu_to_le32(1);
6350 ppl_hdr
->entries
[0].checksum
= ~0;
6353 ret
= write_ppl_header(info
->ppl_sector
, fd
, buf
);
6359 static int is_rebuilding(struct imsm_dev
*dev
);
6361 static int validate_ppl_imsm(struct supertype
*st
, struct mdinfo
*info
,
6362 struct mdinfo
*disk
)
6364 struct intel_super
*super
= st
->sb
;
6366 void *buf_orig
, *buf
, *buf_prev
= NULL
;
6368 struct ppl_header
*ppl_hdr
= NULL
;
6370 struct imsm_dev
*dev
;
6373 unsigned long long ppl_offset
= 0;
6374 unsigned long long prev_gen_num
= 0;
6376 if (disk
->disk
.raid_disk
< 0)
6379 dev
= get_imsm_dev(super
, info
->container_member
);
6380 idx
= get_imsm_disk_idx(dev
, disk
->disk
.raid_disk
, MAP_0
);
6381 d
= get_imsm_dl_disk(super
, idx
);
6383 if (!d
|| d
->index
< 0 || is_failed(&d
->disk
))
6386 if (posix_memalign(&buf_orig
, MAX_SECTOR_SIZE
, PPL_HEADER_SIZE
* 2)) {
6387 pr_err("Failed to allocate PPL header buffer\n");
6393 while (ppl_offset
< MULTIPLE_PPL_AREA_SIZE_IMSM
) {
6396 dprintf("Checking potential PPL at offset: %llu\n", ppl_offset
);
6398 if (lseek64(d
->fd
, info
->ppl_sector
* 512 + ppl_offset
,
6400 perror("Failed to seek to PPL header location");
6405 if (read(d
->fd
, buf
, PPL_HEADER_SIZE
) != PPL_HEADER_SIZE
) {
6406 perror("Read PPL header failed");
6413 crc
= __le32_to_cpu(ppl_hdr
->checksum
);
6414 ppl_hdr
->checksum
= 0;
6416 if (crc
!= ~crc32c_le(~0, buf
, PPL_HEADER_SIZE
)) {
6417 dprintf("Wrong PPL header checksum on %s\n",
6422 if (prev_gen_num
> __le64_to_cpu(ppl_hdr
->generation
)) {
6423 /* previous was newest, it was already checked */
6427 if ((__le32_to_cpu(ppl_hdr
->signature
) !=
6428 super
->anchor
->orig_family_num
)) {
6429 dprintf("Wrong PPL header signature on %s\n",
6436 prev_gen_num
= __le64_to_cpu(ppl_hdr
->generation
);
6438 ppl_offset
+= PPL_HEADER_SIZE
;
6439 for (i
= 0; i
< __le32_to_cpu(ppl_hdr
->entries_count
); i
++)
6441 __le32_to_cpu(ppl_hdr
->entries
[i
].pp_size
);
6444 buf_prev
= buf
+ PPL_HEADER_SIZE
;
6456 * Update metadata to use mutliple PPLs area (1MB).
6457 * This is done once for all RAID members
6459 if (info
->consistency_policy
== CONSISTENCY_POLICY_PPL
&&
6460 info
->ppl_size
!= (MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9)) {
6462 struct mdinfo
*member_dev
;
6464 sprintf(subarray
, "%d", info
->container_member
);
6466 if (mdmon_running(st
->container_devnm
))
6467 st
->update_tail
= &st
->updates
;
6469 if (st
->ss
->update_subarray(st
, subarray
, "ppl", NULL
)) {
6470 pr_err("Failed to update subarray %s\n",
6473 if (st
->update_tail
)
6474 flush_metadata_updates(st
);
6476 st
->ss
->sync_metadata(st
);
6477 info
->ppl_size
= (MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9);
6478 for (member_dev
= info
->devs
; member_dev
;
6479 member_dev
= member_dev
->next
)
6480 member_dev
->ppl_size
=
6481 (MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9);
6486 struct imsm_map
*map
= get_imsm_map(dev
, MAP_X
);
6488 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
6489 (map
->map_state
== IMSM_T_STATE_NORMAL
&&
6490 !(dev
->vol
.dirty
& RAIDVOL_DIRTY
)) ||
6491 (is_rebuilding(dev
) &&
6492 vol_curr_migr_unit(dev
) == 0 &&
6493 get_imsm_disk_idx(dev
, disk
->disk
.raid_disk
, MAP_1
) != idx
))
6494 ret
= st
->ss
->write_init_ppl(st
, info
, d
->fd
);
6496 info
->mismatch_cnt
++;
6497 } else if (ret
== 0 &&
6498 ppl_hdr
->entries_count
== 0 &&
6499 is_rebuilding(dev
) &&
6500 info
->resync_start
== 0) {
6502 * The header has no entries - add a single empty entry and
6503 * rewrite the header to prevent the kernel from going into
6504 * resync after an interrupted rebuild.
6506 ppl_hdr
->entries_count
= __cpu_to_le32(1);
6507 ret
= write_ppl_header(info
->ppl_sector
, d
->fd
, buf
);
6515 static int write_init_ppl_imsm_all(struct supertype
*st
, struct mdinfo
*info
)
6517 struct intel_super
*super
= st
->sb
;
6521 if (info
->consistency_policy
!= CONSISTENCY_POLICY_PPL
||
6522 info
->array
.level
!= 5)
6525 for (d
= super
->disks
; d
; d
= d
->next
) {
6526 if (d
->index
< 0 || is_failed(&d
->disk
))
6529 ret
= st
->ss
->write_init_ppl(st
, info
, d
->fd
);
6537 /*******************************************************************************
6538 * Function: write_init_bitmap_imsm_vol
6539 * Description: Write a bitmap header and prepares the area for the bitmap.
6541 * st : supertype information
6542 * vol_idx : the volume index to use
6547 ******************************************************************************/
6548 static int write_init_bitmap_imsm_vol(struct supertype
*st
, int vol_idx
)
6550 struct intel_super
*super
= st
->sb
;
6551 int prev_current_vol
= super
->current_vol
;
6555 super
->current_vol
= vol_idx
;
6556 for (d
= super
->disks
; d
; d
= d
->next
) {
6557 if (d
->index
< 0 || is_failed(&d
->disk
))
6559 ret
= st
->ss
->write_bitmap(st
, d
->fd
, NoUpdate
);
6563 super
->current_vol
= prev_current_vol
;
6567 /*******************************************************************************
6568 * Function: write_init_bitmap_imsm_all
6569 * Description: Write a bitmap header and prepares the area for the bitmap.
6570 * Operation is executed for volumes with CONSISTENCY_POLICY_BITMAP.
6572 * st : supertype information
6573 * info : info about the volume where the bitmap should be written
6574 * vol_idx : the volume index to use
6579 ******************************************************************************/
6580 static int write_init_bitmap_imsm_all(struct supertype
*st
, struct mdinfo
*info
,
6585 if (info
&& (info
->consistency_policy
== CONSISTENCY_POLICY_BITMAP
))
6586 ret
= write_init_bitmap_imsm_vol(st
, vol_idx
);
6591 static int write_init_super_imsm(struct supertype
*st
)
6593 struct intel_super
*super
= st
->sb
;
6594 int current_vol
= super
->current_vol
;
6598 getinfo_super_imsm(st
, &info
, NULL
);
6600 /* we are done with current_vol reset it to point st at the container */
6601 super
->current_vol
= -1;
6603 if (st
->update_tail
) {
6604 /* queue the recently created array / added disk
6605 * as a metadata update */
6607 /* determine if we are creating a volume or adding a disk */
6608 if (current_vol
< 0) {
6609 /* in the mgmt (add/remove) disk case we are running
6610 * in mdmon context, so don't close fd's
6614 /* adding the second volume to the array */
6615 rv
= write_init_ppl_imsm_all(st
, &info
);
6617 rv
= write_init_bitmap_imsm_all(st
, &info
, current_vol
);
6619 rv
= create_array(st
, current_vol
);
6623 for (d
= super
->disks
; d
; d
= d
->next
)
6624 Kill(d
->devname
, NULL
, 0, -1, 1);
6625 if (current_vol
>= 0) {
6626 rv
= write_init_ppl_imsm_all(st
, &info
);
6628 rv
= write_init_bitmap_imsm_all(st
, &info
, current_vol
);
6632 rv
= write_super_imsm(st
, 1);
6638 static int store_super_imsm(struct supertype
*st
, int fd
)
6640 struct intel_super
*super
= st
->sb
;
6641 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
6646 if (super
->sector_size
== 4096)
6647 convert_to_4k(super
);
6648 return store_imsm_mpb(fd
, mpb
);
6651 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
6653 unsigned long long data_offset
,
6655 unsigned long long *freesize
,
6659 unsigned long long ldsize
;
6660 struct intel_super
*super
= NULL
;
6663 if (level
!= LEVEL_CONTAINER
)
6668 fd
= dev_open(dev
, O_RDONLY
|O_EXCL
);
6671 pr_err("imsm: Cannot open %s: %s\n",
6672 dev
, strerror(errno
));
6675 if (!get_dev_size(fd
, dev
, &ldsize
))
6678 /* capabilities retrieve could be possible
6679 * note that there is no fd for the disks in array.
6681 super
= alloc_super();
6685 if (!get_dev_sector_size(fd
, NULL
, &super
->sector_size
))
6688 rv
= find_intel_hba_capability(fd
, super
, verbose
> 0 ? dev
: NULL
);
6692 fd2devname(fd
, str
);
6693 dprintf("fd: %d %s orom: %p rv: %d raiddisk: %d\n",
6694 fd
, str
, super
->orom
, rv
, raiddisks
);
6696 /* no orom/efi or non-intel hba of the disk */
6701 if (raiddisks
> super
->orom
->tds
) {
6703 pr_err("%d exceeds maximum number of platform supported disks: %d\n",
6704 raiddisks
, super
->orom
->tds
);
6707 if ((super
->orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) == 0 &&
6708 (ldsize
>> 9) >> 32 > 0) {
6710 pr_err("%s exceeds maximum platform supported size\n", dev
);
6714 if (super
->hba
->type
== SYS_DEV_VMD
||
6715 super
->hba
->type
== SYS_DEV_NVME
) {
6716 if (!imsm_is_nvme_namespace_supported(fd
, 1)) {
6718 pr_err("NVMe namespace %s is not supported by IMSM\n",
6725 *freesize
= avail_size_imsm(st
, ldsize
>> 9, data_offset
);
6735 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
6737 const unsigned long long base_start
= e
[*idx
].start
;
6738 unsigned long long end
= base_start
+ e
[*idx
].size
;
6741 if (base_start
== end
)
6745 for (i
= *idx
; i
< num_extents
; i
++) {
6746 /* extend overlapping extents */
6747 if (e
[i
].start
>= base_start
&&
6748 e
[i
].start
<= end
) {
6751 if (e
[i
].start
+ e
[i
].size
> end
)
6752 end
= e
[i
].start
+ e
[i
].size
;
6753 } else if (e
[i
].start
> end
) {
6759 return end
- base_start
;
6762 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
6764 /* build a composite disk with all known extents and generate a new
6765 * 'maxsize' given the "all disks in an array must share a common start
6766 * offset" constraint
6768 struct extent
*e
= xcalloc(sum_extents
, sizeof(*e
));
6772 unsigned long long pos
;
6773 unsigned long long start
= 0;
6774 unsigned long long maxsize
;
6775 unsigned long reserve
;
6777 /* coalesce and sort all extents. also, check to see if we need to
6778 * reserve space between member arrays
6781 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6784 for (i
= 0; i
< dl
->extent_cnt
; i
++)
6787 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
6792 while (i
< sum_extents
) {
6793 e
[j
].start
= e
[i
].start
;
6794 e
[j
].size
= find_size(e
, &i
, sum_extents
);
6796 if (e
[j
-1].size
== 0)
6805 unsigned long long esize
;
6807 esize
= e
[i
].start
- pos
;
6808 if (esize
>= maxsize
) {
6813 pos
= e
[i
].start
+ e
[i
].size
;
6815 } while (e
[i
-1].size
);
6821 /* FIXME assumes volume at offset 0 is the first volume in a
6824 if (start_extent
> 0)
6825 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
6829 if (maxsize
< reserve
)
6832 super
->create_offset
= ~((unsigned long long) 0);
6833 if (start
+ reserve
> super
->create_offset
)
6834 return 0; /* start overflows create_offset */
6835 super
->create_offset
= start
+ reserve
;
6837 return maxsize
- reserve
;
6840 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
6842 if (level
< 0 || level
== 6 || level
== 4)
6845 /* if we have an orom prevent invalid raid levels */
6848 case 0: return imsm_orom_has_raid0(orom
);
6851 return imsm_orom_has_raid1e(orom
);
6852 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
6853 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
6854 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
6857 return 1; /* not on an Intel RAID platform so anything goes */
6863 active_arrays_by_format(char *name
, char* hba
, struct md_list
**devlist
,
6864 int dpa
, int verbose
)
6866 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
6867 struct mdstat_ent
*memb
;
6873 for (memb
= mdstat
; memb
; memb
= memb
->next
) {
6874 if (memb
->metadata_version
&&
6875 (strncmp(memb
->metadata_version
, "external:", 9) == 0) &&
6876 (strcmp(&memb
->metadata_version
[9], name
) == 0) &&
6877 !is_subarray(memb
->metadata_version
+9) &&
6879 struct dev_member
*dev
= memb
->members
;
6881 while(dev
&& (fd
< 0)) {
6882 char *path
= xmalloc(strlen(dev
->name
) + strlen("/dev/") + 1);
6883 num
= sprintf(path
, "%s%s", "/dev/", dev
->name
);
6885 fd
= open(path
, O_RDONLY
, 0);
6886 if (num
<= 0 || fd
< 0) {
6887 pr_vrb("Cannot open %s: %s\n",
6888 dev
->name
, strerror(errno
));
6894 if (fd
>= 0 && disk_attached_to_hba(fd
, hba
)) {
6895 struct mdstat_ent
*vol
;
6896 for (vol
= mdstat
; vol
; vol
= vol
->next
) {
6897 if (vol
->active
> 0 &&
6898 vol
->metadata_version
&&
6899 is_container_member(vol
, memb
->devnm
)) {
6904 if (*devlist
&& (found
< dpa
)) {
6905 dv
= xcalloc(1, sizeof(*dv
));
6906 dv
->devname
= xmalloc(strlen(memb
->devnm
) + strlen("/dev/") + 1);
6907 sprintf(dv
->devname
, "%s%s", "/dev/", memb
->devnm
);
6910 dv
->next
= *devlist
;
6918 free_mdstat(mdstat
);
6923 static struct md_list
*
6924 get_loop_devices(void)
6927 struct md_list
*devlist
= NULL
;
6930 for(i
= 0; i
< 12; i
++) {
6931 dv
= xcalloc(1, sizeof(*dv
));
6932 dv
->devname
= xmalloc(40);
6933 sprintf(dv
->devname
, "/dev/loop%d", i
);
6941 static struct md_list
*
6942 get_devices(const char *hba_path
)
6944 struct md_list
*devlist
= NULL
;
6951 devlist
= get_loop_devices();
6954 /* scroll through /sys/dev/block looking for devices attached to
6957 dir
= opendir("/sys/dev/block");
6958 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
6963 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
6965 path
= devt_to_devpath(makedev(major
, minor
), 1, NULL
);
6968 if (!path_attached_to_hba(path
, hba_path
)) {
6975 fd
= dev_open(ent
->d_name
, O_RDONLY
);
6977 fd2devname(fd
, buf
);
6980 pr_err("cannot open device: %s\n",
6985 dv
= xcalloc(1, sizeof(*dv
));
6986 dv
->devname
= xstrdup(buf
);
6993 devlist
= devlist
->next
;
7003 count_volumes_list(struct md_list
*devlist
, char *homehost
,
7004 int verbose
, int *found
)
7006 struct md_list
*tmpdev
;
7008 struct supertype
*st
;
7010 /* first walk the list of devices to find a consistent set
7011 * that match the criterea, if that is possible.
7012 * We flag the ones we like with 'used'.
7015 st
= match_metadata_desc_imsm("imsm");
7017 pr_vrb("cannot allocate memory for imsm supertype\n");
7021 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
7022 char *devname
= tmpdev
->devname
;
7024 struct supertype
*tst
;
7026 if (tmpdev
->used
> 1)
7028 tst
= dup_super(st
);
7030 pr_vrb("cannot allocate memory for imsm supertype\n");
7033 tmpdev
->container
= 0;
7034 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
7036 dprintf("cannot open device %s: %s\n",
7037 devname
, strerror(errno
));
7039 } else if (!fstat_is_blkdev(dfd
, devname
, &rdev
)) {
7041 } else if (must_be_container(dfd
)) {
7042 struct supertype
*cst
;
7043 cst
= super_by_fd(dfd
, NULL
);
7045 dprintf("cannot recognize container type %s\n",
7048 } else if (tst
->ss
!= st
->ss
) {
7049 dprintf("non-imsm container - ignore it: %s\n",
7052 } else if (!tst
->ss
->load_container
||
7053 tst
->ss
->load_container(tst
, dfd
, NULL
))
7056 tmpdev
->container
= 1;
7059 cst
->ss
->free_super(cst
);
7061 tmpdev
->st_rdev
= rdev
;
7062 if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
7063 dprintf("no RAID superblock on %s\n",
7066 } else if (tst
->ss
->compare_super
== NULL
) {
7067 dprintf("Cannot assemble %s metadata on %s\n",
7068 tst
->ss
->name
, devname
);
7074 if (tmpdev
->used
== 2 || tmpdev
->used
== 4) {
7075 /* Ignore unrecognised devices during auto-assembly */
7080 tst
->ss
->getinfo_super(tst
, &info
, NULL
);
7082 if (st
->minor_version
== -1)
7083 st
->minor_version
= tst
->minor_version
;
7085 if (memcmp(info
.uuid
, uuid_zero
,
7086 sizeof(int[4])) == 0) {
7087 /* this is a floating spare. It cannot define
7088 * an array unless there are no more arrays of
7089 * this type to be found. It can be included
7090 * in an array of this type though.
7096 if (st
->ss
!= tst
->ss
||
7097 st
->minor_version
!= tst
->minor_version
||
7098 st
->ss
->compare_super(st
, tst
, 1) != 0) {
7099 /* Some mismatch. If exactly one array matches this host,
7100 * we can resolve on that one.
7101 * Or, if we are auto assembling, we just ignore the second
7104 dprintf("superblock on %s doesn't match others - assembly aborted\n",
7110 dprintf("found: devname: %s\n", devname
);
7114 tst
->ss
->free_super(tst
);
7118 if ((err
= load_super_imsm_all(st
, -1, &st
->sb
, NULL
, devlist
, 0)) == 0) {
7119 struct mdinfo
*iter
, *head
= st
->ss
->container_content(st
, NULL
);
7120 for (iter
= head
; iter
; iter
= iter
->next
) {
7121 dprintf("content->text_version: %s vol\n",
7122 iter
->text_version
);
7123 if (iter
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
)) {
7124 /* do not assemble arrays with unsupported
7126 dprintf("Cannot activate member %s.\n",
7127 iter
->text_version
);
7134 dprintf("No valid super block on device list: err: %d %p\n",
7138 dprintf("no more devices to examine\n");
7141 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
7142 if (tmpdev
->used
== 1 && tmpdev
->found
) {
7144 if (count
< tmpdev
->found
)
7147 count
-= tmpdev
->found
;
7150 if (tmpdev
->used
== 1)
7155 st
->ss
->free_super(st
);
7159 static int __count_volumes(char *hba_path
, int dpa
, int verbose
,
7162 struct sys_dev
*idev
, *intel_devices
= find_intel_devices();
7164 const struct orom_entry
*entry
;
7165 struct devid_list
*dv
, *devid_list
;
7170 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
7171 if (strstr(idev
->path
, hba_path
))
7175 if (!idev
|| !idev
->dev_id
)
7178 entry
= get_orom_entry_by_device_id(idev
->dev_id
);
7180 if (!entry
|| !entry
->devid_list
)
7183 devid_list
= entry
->devid_list
;
7184 for (dv
= devid_list
; dv
; dv
= dv
->next
) {
7185 struct md_list
*devlist
;
7186 struct sys_dev
*device
= NULL
;
7191 device
= device_by_id_and_path(dv
->devid
, hba_path
);
7193 device
= device_by_id(dv
->devid
);
7196 hpath
= device
->path
;
7200 devlist
= get_devices(hpath
);
7201 /* if no intel devices return zero volumes */
7202 if (devlist
== NULL
)
7205 count
+= active_arrays_by_format("imsm", hpath
, &devlist
, dpa
,
7207 dprintf("path: %s active arrays: %d\n", hpath
, count
);
7208 if (devlist
== NULL
)
7212 count
+= count_volumes_list(devlist
,
7216 dprintf("found %d count: %d\n", found
, count
);
7219 dprintf("path: %s total number of volumes: %d\n", hpath
, count
);
7222 struct md_list
*dv
= devlist
;
7223 devlist
= devlist
->next
;
7231 static int count_volumes(struct intel_hba
*hba
, int dpa
, int verbose
)
7235 if (hba
->type
== SYS_DEV_VMD
) {
7236 struct sys_dev
*dev
;
7239 for (dev
= find_intel_devices(); dev
; dev
= dev
->next
) {
7240 if (dev
->type
== SYS_DEV_VMD
)
7241 count
+= __count_volumes(dev
->path
, dpa
,
7246 return __count_volumes(hba
->path
, dpa
, verbose
, 0);
7249 static int imsm_default_chunk(const struct imsm_orom
*orom
)
7251 /* up to 512 if the plaform supports it, otherwise the platform max.
7252 * 128 if no platform detected
7254 int fs
= max(7, orom
? fls(orom
->sss
) : 0);
7256 return min(512, (1 << fs
));
7260 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
7261 int raiddisks
, int *chunk
, unsigned long long size
, int verbose
)
7263 /* check/set platform and metadata limits/defaults */
7264 if (super
->orom
&& raiddisks
> super
->orom
->dpa
) {
7265 pr_vrb("platform supports a maximum of %d disks per array\n",
7270 /* capabilities of OROM tested - copied from validate_geometry_imsm_volume */
7271 if (!is_raid_level_supported(super
->orom
, level
, raiddisks
)) {
7272 pr_vrb("platform does not support raid%d with %d disk%s\n",
7273 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
7277 if (*chunk
== 0 || *chunk
== UnSet
)
7278 *chunk
= imsm_default_chunk(super
->orom
);
7280 if (super
->orom
&& !imsm_orom_has_chunk(super
->orom
, *chunk
)) {
7281 pr_vrb("platform does not support a chunk size of: %d\n", *chunk
);
7285 if (layout
!= imsm_level_to_layout(level
)) {
7287 pr_vrb("imsm raid 5 only supports the left-asymmetric layout\n");
7288 else if (level
== 10)
7289 pr_vrb("imsm raid 10 only supports the n2 layout\n");
7291 pr_vrb("imsm unknown layout %#x for this raid level %d\n",
7296 if (super
->orom
&& (super
->orom
->attr
& IMSM_OROM_ATTR_2TB
) == 0 &&
7297 (calc_array_size(level
, raiddisks
, layout
, *chunk
, size
) >> 32) > 0) {
7298 pr_vrb("platform does not support a volume size over 2TB\n");
7305 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
7306 * FIX ME add ahci details
7308 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
7309 int layout
, int raiddisks
, int *chunk
,
7310 unsigned long long size
,
7311 unsigned long long data_offset
,
7313 unsigned long long *freesize
,
7317 struct intel_super
*super
= st
->sb
;
7318 struct imsm_super
*mpb
;
7320 unsigned long long pos
= 0;
7321 unsigned long long maxsize
;
7325 /* We must have the container info already read in. */
7329 mpb
= super
->anchor
;
7331 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, size
, verbose
)) {
7332 pr_err("RAID geometry validation failed. Cannot proceed with the action(s).\n");
7336 /* General test: make sure there is space for
7337 * 'raiddisks' device extents of size 'size' at a given
7340 unsigned long long minsize
= size
;
7341 unsigned long long start_offset
= MaxSector
;
7344 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
7345 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7350 e
= get_extents(super
, dl
, 0);
7353 unsigned long long esize
;
7354 esize
= e
[i
].start
- pos
;
7355 if (esize
>= minsize
)
7357 if (found
&& start_offset
== MaxSector
) {
7360 } else if (found
&& pos
!= start_offset
) {
7364 pos
= e
[i
].start
+ e
[i
].size
;
7366 } while (e
[i
-1].size
);
7371 if (dcnt
< raiddisks
) {
7373 pr_err("imsm: Not enough devices with space for this array (%d < %d)\n",
7380 /* This device must be a member of the set */
7381 if (!stat_is_blkdev(dev
, &rdev
))
7383 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7384 if (dl
->major
== (int)major(rdev
) &&
7385 dl
->minor
== (int)minor(rdev
))
7390 pr_err("%s is not in the same imsm set\n", dev
);
7392 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
7393 /* If a volume is present then the current creation attempt
7394 * cannot incorporate new spares because the orom may not
7395 * understand this configuration (all member disks must be
7396 * members of each array in the container).
7398 pr_err("%s is a spare and a volume is already defined for this container\n", dev
);
7399 pr_err("The option-rom requires all member disks to be a member of all volumes\n");
7401 } else if (super
->orom
&& mpb
->num_raid_devs
> 0 &&
7402 mpb
->num_disks
!= raiddisks
) {
7403 pr_err("The option-rom requires all member disks to be a member of all volumes\n");
7407 /* retrieve the largest free space block */
7408 e
= get_extents(super
, dl
, 0);
7413 unsigned long long esize
;
7415 esize
= e
[i
].start
- pos
;
7416 if (esize
>= maxsize
)
7418 pos
= e
[i
].start
+ e
[i
].size
;
7420 } while (e
[i
-1].size
);
7425 pr_err("unable to determine free space for: %s\n",
7429 if (maxsize
< size
) {
7431 pr_err("%s not enough space (%llu < %llu)\n",
7432 dev
, maxsize
, size
);
7436 /* count total number of extents for merge */
7438 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7440 i
+= dl
->extent_cnt
;
7442 maxsize
= merge_extents(super
, i
);
7444 if (mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
)
7445 pr_err("attempting to create a second volume with size less then remaining space.\n");
7447 if (maxsize
< size
|| maxsize
== 0) {
7450 pr_err("no free space left on device. Aborting...\n");
7452 pr_err("not enough space to create volume of given size (%llu < %llu). Aborting...\n",
7458 *freesize
= maxsize
;
7461 int count
= count_volumes(super
->hba
,
7462 super
->orom
->dpa
, verbose
);
7463 if (super
->orom
->vphba
<= count
) {
7464 pr_vrb("platform does not support more than %d raid volumes.\n",
7465 super
->orom
->vphba
);
7472 static int imsm_get_free_size(struct supertype
*st
, int raiddisks
,
7473 unsigned long long size
, int chunk
,
7474 unsigned long long *freesize
)
7476 struct intel_super
*super
= st
->sb
;
7477 struct imsm_super
*mpb
= super
->anchor
;
7482 unsigned long long maxsize
;
7483 unsigned long long minsize
;
7487 /* find the largest common start free region of the possible disks */
7491 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7497 /* don't activate new spares if we are orom constrained
7498 * and there is already a volume active in the container
7500 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
7503 e
= get_extents(super
, dl
, 0);
7506 for (i
= 1; e
[i
-1].size
; i
++)
7514 maxsize
= merge_extents(super
, extent_cnt
);
7518 minsize
= chunk
* 2;
7520 if (cnt
< raiddisks
||
7521 (super
->orom
&& used
&& used
!= raiddisks
) ||
7522 maxsize
< minsize
||
7524 pr_err("not enough devices with space to create array.\n");
7525 return 0; /* No enough free spaces large enough */
7536 if (mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
)
7537 pr_err("attempting to create a second volume with size less then remaining space.\n");
7539 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7541 dl
->raiddisk
= cnt
++;
7545 dprintf("imsm: imsm_get_free_size() returns : %llu\n", size
);
7550 static int reserve_space(struct supertype
*st
, int raiddisks
,
7551 unsigned long long size
, int chunk
,
7552 unsigned long long *freesize
)
7554 struct intel_super
*super
= st
->sb
;
7559 rv
= imsm_get_free_size(st
, raiddisks
, size
, chunk
, freesize
);
7562 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7564 dl
->raiddisk
= cnt
++;
7571 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
7572 int raiddisks
, int *chunk
, unsigned long long size
,
7573 unsigned long long data_offset
,
7574 char *dev
, unsigned long long *freesize
,
7575 int consistency_policy
, int verbose
)
7582 * if given unused devices create a container
7583 * if given given devices in a container create a member volume
7585 if (level
== LEVEL_CONTAINER
)
7586 /* Must be a fresh device to add to a container */
7587 return validate_geometry_imsm_container(st
, level
, raiddisks
,
7592 * Size is given in sectors.
7594 if (size
&& (size
< 2048)) {
7595 pr_err("Given size must be greater than 1M.\n");
7596 /* Depends on algorithm in Create.c :
7597 * if container was given (dev == NULL) return -1,
7598 * if block device was given ( dev != NULL) return 0.
7600 return dev
? -1 : 0;
7605 struct intel_super
*super
= st
->sb
;
7606 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
7607 raiddisks
, chunk
, size
,
7610 /* we are being asked to automatically layout a
7611 * new volume based on the current contents of
7612 * the container. If the the parameters can be
7613 * satisfied reserve_space will record the disks,
7614 * start offset, and size of the volume to be
7615 * created. add_to_super and getinfo_super
7616 * detect when autolayout is in progress.
7618 /* assuming that freesize is always given when array is
7620 if (super
->orom
&& freesize
) {
7622 count
= count_volumes(super
->hba
,
7623 super
->orom
->dpa
, verbose
);
7624 if (super
->orom
->vphba
<= count
) {
7625 pr_vrb("platform does not support more than %d raid volumes.\n",
7626 super
->orom
->vphba
);
7631 return reserve_space(st
, raiddisks
, size
,
7637 /* creating in a given container */
7638 return validate_geometry_imsm_volume(st
, level
, layout
,
7639 raiddisks
, chunk
, size
,
7641 dev
, freesize
, verbose
);
7644 /* This device needs to be a device in an 'imsm' container */
7645 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
7648 pr_err("Cannot create this array on device %s\n",
7653 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
7655 pr_err("Cannot open %s: %s\n",
7656 dev
, strerror(errno
));
7659 /* Well, it is in use by someone, maybe an 'imsm' container. */
7660 cfd
= open_container(fd
);
7664 pr_err("Cannot use %s: It is busy\n",
7668 sra
= sysfs_read(cfd
, NULL
, GET_VERSION
);
7669 if (sra
&& sra
->array
.major_version
== -1 &&
7670 strcmp(sra
->text_version
, "imsm") == 0)
7674 /* This is a member of a imsm container. Load the container
7675 * and try to create a volume
7677 struct intel_super
*super
;
7679 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
, NULL
, 1) == 0) {
7681 strcpy(st
->container_devnm
, fd2devnm(cfd
));
7683 return validate_geometry_imsm_volume(st
, level
, layout
,
7685 size
, data_offset
, dev
,
7692 pr_err("failed container membership check\n");
7698 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
7700 struct intel_super
*super
= st
->sb
;
7702 if (level
&& *level
== UnSet
)
7703 *level
= LEVEL_CONTAINER
;
7705 if (level
&& layout
&& *layout
== UnSet
)
7706 *layout
= imsm_level_to_layout(*level
);
7708 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0))
7709 *chunk
= imsm_default_chunk(super
->orom
);
7712 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
7714 static int kill_subarray_imsm(struct supertype
*st
, char *subarray_id
)
7716 /* remove the subarray currently referenced by subarray_id */
7718 struct intel_dev
**dp
;
7719 struct intel_super
*super
= st
->sb
;
7720 __u8 current_vol
= strtoul(subarray_id
, NULL
, 10);
7721 struct imsm_super
*mpb
= super
->anchor
;
7723 if (mpb
->num_raid_devs
== 0)
7726 /* block deletions that would change the uuid of active subarrays
7728 * FIXME when immutable ids are available, but note that we'll
7729 * also need to fixup the invalidated/active subarray indexes in
7732 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7735 if (i
< current_vol
)
7737 sprintf(subarray
, "%u", i
);
7738 if (is_subarray_active(subarray
, st
->devnm
)) {
7739 pr_err("deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
7746 if (st
->update_tail
) {
7747 struct imsm_update_kill_array
*u
= xmalloc(sizeof(*u
));
7749 u
->type
= update_kill_array
;
7750 u
->dev_idx
= current_vol
;
7751 append_metadata_update(st
, u
, sizeof(*u
));
7756 for (dp
= &super
->devlist
; *dp
;)
7757 if ((*dp
)->index
== current_vol
) {
7760 handle_missing(super
, (*dp
)->dev
);
7761 if ((*dp
)->index
> current_vol
)
7766 /* no more raid devices, all active components are now spares,
7767 * but of course failed are still failed
7769 if (--mpb
->num_raid_devs
== 0) {
7772 for (d
= super
->disks
; d
; d
= d
->next
)
7777 super
->updates_pending
++;
7782 static int get_rwh_policy_from_update(char *update
)
7784 if (strcmp(update
, "ppl") == 0)
7785 return RWH_MULTIPLE_DISTRIBUTED
;
7786 else if (strcmp(update
, "no-ppl") == 0)
7787 return RWH_MULTIPLE_OFF
;
7788 else if (strcmp(update
, "bitmap") == 0)
7790 else if (strcmp(update
, "no-bitmap") == 0)
7795 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
7796 char *update
, struct mddev_ident
*ident
)
7798 /* update the subarray currently referenced by ->current_vol */
7799 struct intel_super
*super
= st
->sb
;
7800 struct imsm_super
*mpb
= super
->anchor
;
7802 if (strcmp(update
, "name") == 0) {
7803 char *name
= ident
->name
;
7807 if (is_subarray_active(subarray
, st
->devnm
)) {
7808 pr_err("Unable to update name of active subarray\n");
7812 if (!check_name(super
, name
, 0))
7815 vol
= strtoul(subarray
, &ep
, 10);
7816 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
7819 if (st
->update_tail
) {
7820 struct imsm_update_rename_array
*u
= xmalloc(sizeof(*u
));
7822 u
->type
= update_rename_array
;
7824 strncpy((char *) u
->name
, name
, MAX_RAID_SERIAL_LEN
);
7825 u
->name
[MAX_RAID_SERIAL_LEN
-1] = '\0';
7826 append_metadata_update(st
, u
, sizeof(*u
));
7828 struct imsm_dev
*dev
;
7831 dev
= get_imsm_dev(super
, vol
);
7832 memset(dev
->volume
, '\0', MAX_RAID_SERIAL_LEN
);
7833 namelen
= min((int)strlen(name
), MAX_RAID_SERIAL_LEN
);
7834 memcpy(dev
->volume
, name
, namelen
);
7835 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7836 dev
= get_imsm_dev(super
, i
);
7837 handle_missing(super
, dev
);
7839 super
->updates_pending
++;
7841 } else if (get_rwh_policy_from_update(update
) != -1) {
7844 int vol
= strtoul(subarray
, &ep
, 10);
7846 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
7849 new_policy
= get_rwh_policy_from_update(update
);
7851 if (st
->update_tail
) {
7852 struct imsm_update_rwh_policy
*u
= xmalloc(sizeof(*u
));
7854 u
->type
= update_rwh_policy
;
7856 u
->new_policy
= new_policy
;
7857 append_metadata_update(st
, u
, sizeof(*u
));
7859 struct imsm_dev
*dev
;
7861 dev
= get_imsm_dev(super
, vol
);
7862 dev
->rwh_policy
= new_policy
;
7863 super
->updates_pending
++;
7865 if (new_policy
== RWH_BITMAP
)
7866 return write_init_bitmap_imsm_vol(st
, vol
);
7873 static int is_gen_migration(struct imsm_dev
*dev
)
7878 if (!dev
->vol
.migr_state
)
7881 if (migr_type(dev
) == MIGR_GEN_MIGR
)
7887 static int is_rebuilding(struct imsm_dev
*dev
)
7889 struct imsm_map
*migr_map
;
7891 if (!dev
->vol
.migr_state
)
7894 if (migr_type(dev
) != MIGR_REBUILD
)
7897 migr_map
= get_imsm_map(dev
, MAP_1
);
7899 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
7905 static int is_initializing(struct imsm_dev
*dev
)
7907 struct imsm_map
*migr_map
;
7909 if (!dev
->vol
.migr_state
)
7912 if (migr_type(dev
) != MIGR_INIT
)
7915 migr_map
= get_imsm_map(dev
, MAP_1
);
7917 if (migr_map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
7923 static void update_recovery_start(struct intel_super
*super
,
7924 struct imsm_dev
*dev
,
7925 struct mdinfo
*array
)
7927 struct mdinfo
*rebuild
= NULL
;
7931 if (!is_rebuilding(dev
))
7934 /* Find the rebuild target, but punt on the dual rebuild case */
7935 for (d
= array
->devs
; d
; d
= d
->next
)
7936 if (d
->recovery_start
== 0) {
7943 /* (?) none of the disks are marked with
7944 * IMSM_ORD_REBUILD, so assume they are missing and the
7945 * disk_ord_tbl was not correctly updated
7947 dprintf("failed to locate out-of-sync disk\n");
7951 units
= vol_curr_migr_unit(dev
);
7952 rebuild
->recovery_start
= units
* blocks_per_migr_unit(super
, dev
);
7955 static int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
);
7957 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
7959 /* Given a container loaded by load_super_imsm_all,
7960 * extract information about all the arrays into
7962 * If 'subarray' is given, just extract info about that array.
7964 * For each imsm_dev create an mdinfo, fill it in,
7965 * then look for matching devices in super->disks
7966 * and create appropriate device mdinfo.
7968 struct intel_super
*super
= st
->sb
;
7969 struct imsm_super
*mpb
= super
->anchor
;
7970 struct mdinfo
*rest
= NULL
;
7974 int spare_disks
= 0;
7975 int current_vol
= super
->current_vol
;
7977 /* do not assemble arrays when not all attributes are supported */
7978 if (imsm_check_attributes(mpb
->attributes
) == 0) {
7980 pr_err("Unsupported attributes in IMSM metadata.Arrays activation is blocked.\n");
7983 /* count spare devices, not used in maps
7985 for (d
= super
->disks
; d
; d
= d
->next
)
7989 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7990 struct imsm_dev
*dev
;
7991 struct imsm_map
*map
;
7992 struct imsm_map
*map2
;
7993 struct mdinfo
*this;
8000 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
8003 dev
= get_imsm_dev(super
, i
);
8004 map
= get_imsm_map(dev
, MAP_0
);
8005 map2
= get_imsm_map(dev
, MAP_1
);
8006 level
= get_imsm_raid_level(map
);
8008 /* do not publish arrays that are in the middle of an
8009 * unsupported migration
8011 if (dev
->vol
.migr_state
&&
8012 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
8013 pr_err("cannot assemble volume '%.16s': unsupported migration in progress\n",
8017 /* do not publish arrays that are not support by controller's
8021 this = xmalloc(sizeof(*this));
8023 super
->current_vol
= i
;
8024 getinfo_super_imsm_volume(st
, this, NULL
);
8026 chunk
= __le16_to_cpu(map
->blocks_per_strip
) >> 1;
8027 /* mdadm does not support all metadata features- set the bit in all arrays state */
8028 if (!validate_geometry_imsm_orom(super
,
8029 level
, /* RAID level */
8030 imsm_level_to_layout(level
),
8031 map
->num_members
, /* raid disks */
8032 &chunk
, imsm_dev_size(dev
),
8034 pr_err("IMSM RAID geometry validation failed. Array %s activation is blocked.\n",
8036 this->array
.state
|=
8037 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
8038 (1<<MD_SB_BLOCK_VOLUME
);
8041 /* if array has bad blocks, set suitable bit in all arrays state */
8043 this->array
.state
|=
8044 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
8045 (1<<MD_SB_BLOCK_VOLUME
);
8047 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
8048 unsigned long long recovery_start
;
8049 struct mdinfo
*info_d
;
8057 idx
= get_imsm_disk_idx(dev
, slot
, MAP_0
);
8058 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
8059 for (d
= super
->disks
; d
; d
= d
->next
)
8060 if (d
->index
== idx
)
8063 recovery_start
= MaxSector
;
8066 if (d
&& is_failed(&d
->disk
))
8068 if (!skip
&& (ord
& IMSM_ORD_REBUILD
))
8070 if (!(ord
& IMSM_ORD_REBUILD
))
8071 this->array
.working_disks
++;
8073 * if we skip some disks the array will be assmebled degraded;
8074 * reset resync start to avoid a dirty-degraded
8075 * situation when performing the intial sync
8080 if (!(dev
->vol
.dirty
& RAIDVOL_DIRTY
)) {
8081 if ((!able_to_resync(level
, missing
) ||
8082 recovery_start
== 0))
8083 this->resync_start
= MaxSector
;
8086 * FIXME handle dirty degraded
8093 info_d
= xcalloc(1, sizeof(*info_d
));
8094 info_d
->next
= this->devs
;
8095 this->devs
= info_d
;
8097 info_d
->disk
.number
= d
->index
;
8098 info_d
->disk
.major
= d
->major
;
8099 info_d
->disk
.minor
= d
->minor
;
8100 info_d
->disk
.raid_disk
= slot
;
8101 info_d
->recovery_start
= recovery_start
;
8103 if (slot
< map2
->num_members
)
8104 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
8106 this->array
.spare_disks
++;
8108 if (slot
< map
->num_members
)
8109 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
8111 this->array
.spare_disks
++;
8114 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
8115 info_d
->data_offset
= pba_of_lba0(map
);
8116 info_d
->component_size
= calc_component_size(map
, dev
);
8118 if (map
->raid_level
== 5) {
8119 info_d
->ppl_sector
= this->ppl_sector
;
8120 info_d
->ppl_size
= this->ppl_size
;
8121 if (this->consistency_policy
== CONSISTENCY_POLICY_PPL
&&
8122 recovery_start
== 0)
8123 this->resync_start
= 0;
8126 info_d
->bb
.supported
= 1;
8127 get_volume_badblocks(super
->bbm_log
, ord_to_idx(ord
),
8128 info_d
->data_offset
,
8129 info_d
->component_size
,
8132 /* now that the disk list is up-to-date fixup recovery_start */
8133 update_recovery_start(super
, dev
, this);
8134 this->array
.spare_disks
+= spare_disks
;
8136 /* check for reshape */
8137 if (this->reshape_active
== 1)
8138 recover_backup_imsm(st
, this);
8142 super
->current_vol
= current_vol
;
8146 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
8147 int failed
, int look_in_map
)
8149 struct imsm_map
*map
;
8151 map
= get_imsm_map(dev
, look_in_map
);
8154 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
8155 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
8157 switch (get_imsm_raid_level(map
)) {
8159 return IMSM_T_STATE_FAILED
;
8162 if (failed
< map
->num_members
)
8163 return IMSM_T_STATE_DEGRADED
;
8165 return IMSM_T_STATE_FAILED
;
8170 * check to see if any mirrors have failed, otherwise we
8171 * are degraded. Even numbered slots are mirrored on
8175 /* gcc -Os complains that this is unused */
8176 int insync
= insync
;
8178 for (i
= 0; i
< map
->num_members
; i
++) {
8179 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_X
);
8180 int idx
= ord_to_idx(ord
);
8181 struct imsm_disk
*disk
;
8183 /* reset the potential in-sync count on even-numbered
8184 * slots. num_copies is always 2 for imsm raid10
8189 disk
= get_imsm_disk(super
, idx
);
8190 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
8193 /* no in-sync disks left in this mirror the
8197 return IMSM_T_STATE_FAILED
;
8200 return IMSM_T_STATE_DEGRADED
;
8204 return IMSM_T_STATE_DEGRADED
;
8206 return IMSM_T_STATE_FAILED
;
8212 return map
->map_state
;
8215 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
8220 struct imsm_disk
*disk
;
8221 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8222 struct imsm_map
*prev
= get_imsm_map(dev
, MAP_1
);
8223 struct imsm_map
*map_for_loop
;
8228 /* at the beginning of migration we set IMSM_ORD_REBUILD on
8229 * disks that are being rebuilt. New failures are recorded to
8230 * map[0]. So we look through all the disks we started with and
8231 * see if any failures are still present, or if any new ones
8235 if (prev
&& (map
->num_members
< prev
->num_members
))
8236 map_for_loop
= prev
;
8238 for (i
= 0; i
< map_for_loop
->num_members
; i
++) {
8240 /* when MAP_X is passed both maps failures are counted
8243 (look_in_map
== MAP_1
|| look_in_map
== MAP_X
) &&
8244 i
< prev
->num_members
) {
8245 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
8246 idx_1
= ord_to_idx(ord
);
8248 disk
= get_imsm_disk(super
, idx_1
);
8249 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
8252 if ((look_in_map
== MAP_0
|| look_in_map
== MAP_X
) &&
8253 i
< map
->num_members
) {
8254 ord
= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
8255 idx
= ord_to_idx(ord
);
8258 disk
= get_imsm_disk(super
, idx
);
8259 if (!disk
|| is_failed(disk
) ||
8260 ord
& IMSM_ORD_REBUILD
)
8269 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
8272 struct intel_super
*super
= c
->sb
;
8273 struct imsm_super
*mpb
= super
->anchor
;
8274 struct imsm_update_prealloc_bb_mem u
;
8276 if (atoi(inst
) >= mpb
->num_raid_devs
) {
8277 pr_err("subarry index %d, out of range\n", atoi(inst
));
8281 dprintf("imsm: open_new %s\n", inst
);
8282 a
->info
.container_member
= atoi(inst
);
8284 u
.type
= update_prealloc_badblocks_mem
;
8285 imsm_update_metadata_locally(c
, &u
, sizeof(u
));
8290 static int is_resyncing(struct imsm_dev
*dev
)
8292 struct imsm_map
*migr_map
;
8294 if (!dev
->vol
.migr_state
)
8297 if (migr_type(dev
) == MIGR_INIT
||
8298 migr_type(dev
) == MIGR_REPAIR
)
8301 if (migr_type(dev
) == MIGR_GEN_MIGR
)
8304 migr_map
= get_imsm_map(dev
, MAP_1
);
8306 if (migr_map
->map_state
== IMSM_T_STATE_NORMAL
&&
8307 dev
->vol
.migr_type
!= MIGR_GEN_MIGR
)
8313 /* return true if we recorded new information */
8314 static int mark_failure(struct intel_super
*super
,
8315 struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
8319 struct imsm_map
*map
;
8320 char buf
[MAX_RAID_SERIAL_LEN
+3];
8321 unsigned int len
, shift
= 0;
8323 /* new failures are always set in map[0] */
8324 map
= get_imsm_map(dev
, MAP_0
);
8326 slot
= get_imsm_disk_slot(map
, idx
);
8330 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
8331 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
8334 memcpy(buf
, disk
->serial
, MAX_RAID_SERIAL_LEN
);
8335 buf
[MAX_RAID_SERIAL_LEN
] = '\000';
8337 if ((len
= strlen(buf
)) >= MAX_RAID_SERIAL_LEN
)
8338 shift
= len
- MAX_RAID_SERIAL_LEN
+ 1;
8339 memcpy(disk
->serial
, &buf
[shift
], len
+ 1 - shift
);
8341 disk
->status
|= FAILED_DISK
;
8342 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
8343 /* mark failures in second map if second map exists and this disk
8345 * This is valid for migration, initialization and rebuild
8347 if (dev
->vol
.migr_state
) {
8348 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
8349 int slot2
= get_imsm_disk_slot(map2
, idx
);
8351 if (slot2
< map2
->num_members
&& slot2
>= 0)
8352 set_imsm_ord_tbl_ent(map2
, slot2
,
8353 idx
| IMSM_ORD_REBUILD
);
8355 if (map
->failed_disk_num
== 0xff ||
8356 (!is_rebuilding(dev
) && map
->failed_disk_num
> slot
))
8357 map
->failed_disk_num
= slot
;
8359 clear_disk_badblocks(super
->bbm_log
, ord_to_idx(ord
));
8364 static void mark_missing(struct intel_super
*super
,
8365 struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
8367 mark_failure(super
, dev
, disk
, idx
);
8369 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
8372 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
8373 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
8376 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
8380 if (!super
->missing
)
8383 /* When orom adds replacement for missing disk it does
8384 * not remove entry of missing disk, but just updates map with
8385 * new added disk. So it is not enough just to test if there is
8386 * any missing disk, we have to look if there are any failed disks
8387 * in map to stop migration */
8389 dprintf("imsm: mark missing\n");
8390 /* end process for initialization and rebuild only
8392 if (is_gen_migration(dev
) == 0) {
8393 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
8397 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8398 struct imsm_map
*map1
;
8399 int i
, ord
, ord_map1
;
8402 for (i
= 0; i
< map
->num_members
; i
++) {
8403 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
8404 if (!(ord
& IMSM_ORD_REBUILD
))
8407 map1
= get_imsm_map(dev
, MAP_1
);
8411 ord_map1
= __le32_to_cpu(map1
->disk_ord_tbl
[i
]);
8412 if (ord_map1
& IMSM_ORD_REBUILD
)
8417 map_state
= imsm_check_degraded(super
, dev
,
8419 end_migration(dev
, super
, map_state
);
8423 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
8424 mark_missing(super
, dev
, &dl
->disk
, dl
->index
);
8425 super
->updates_pending
++;
8428 static unsigned long long imsm_set_array_size(struct imsm_dev
*dev
,
8431 unsigned long long array_blocks
;
8432 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8433 int used_disks
= imsm_num_data_members(map
);
8435 if (used_disks
== 0) {
8436 /* when problems occures
8437 * return current array_blocks value
8439 array_blocks
= imsm_dev_size(dev
);
8441 return array_blocks
;
8444 /* set array size in metadata
8447 /* OLCE size change is caused by added disks
8449 array_blocks
= per_dev_array_size(map
) * used_disks
;
8451 /* Online Volume Size Change
8452 * Using available free space
8454 array_blocks
= new_size
;
8456 array_blocks
= round_size_to_mb(array_blocks
, used_disks
);
8457 set_imsm_dev_size(dev
, array_blocks
);
8459 return array_blocks
;
8462 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
8464 static void imsm_progress_container_reshape(struct intel_super
*super
)
8466 /* if no device has a migr_state, but some device has a
8467 * different number of members than the previous device, start
8468 * changing the number of devices in this device to match
8471 struct imsm_super
*mpb
= super
->anchor
;
8472 int prev_disks
= -1;
8476 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8477 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
8478 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8479 struct imsm_map
*map2
;
8480 int prev_num_members
;
8482 if (dev
->vol
.migr_state
)
8485 if (prev_disks
== -1)
8486 prev_disks
= map
->num_members
;
8487 if (prev_disks
== map
->num_members
)
8490 /* OK, this array needs to enter reshape mode.
8491 * i.e it needs a migr_state
8494 copy_map_size
= sizeof_imsm_map(map
);
8495 prev_num_members
= map
->num_members
;
8496 map
->num_members
= prev_disks
;
8497 dev
->vol
.migr_state
= 1;
8498 set_vol_curr_migr_unit(dev
, 0);
8499 set_migr_type(dev
, MIGR_GEN_MIGR
);
8500 for (i
= prev_num_members
;
8501 i
< map
->num_members
; i
++)
8502 set_imsm_ord_tbl_ent(map
, i
, i
);
8503 map2
= get_imsm_map(dev
, MAP_1
);
8504 /* Copy the current map */
8505 memcpy(map2
, map
, copy_map_size
);
8506 map2
->num_members
= prev_num_members
;
8508 imsm_set_array_size(dev
, -1);
8509 super
->clean_migration_record_by_mdmon
= 1;
8510 super
->updates_pending
++;
8514 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
8515 * states are handled in imsm_set_disk() with one exception, when a
8516 * resync is stopped due to a new failure this routine will set the
8517 * 'degraded' state for the array.
8519 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
8521 int inst
= a
->info
.container_member
;
8522 struct intel_super
*super
= a
->container
->sb
;
8523 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8524 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8525 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
8526 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8527 __u32 blocks_per_unit
;
8529 if (dev
->vol
.migr_state
&&
8530 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
8531 /* array state change is blocked due to reshape action
8533 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
8534 * - finish the reshape (if last_checkpoint is big and action != reshape)
8535 * - update vol_curr_migr_unit
8537 if (a
->curr_action
== reshape
) {
8538 /* still reshaping, maybe update vol_curr_migr_unit */
8539 goto mark_checkpoint
;
8541 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
8542 /* for some reason we aborted the reshape.
8544 * disable automatic metadata rollback
8545 * user action is required to recover process
8548 struct imsm_map
*map2
=
8549 get_imsm_map(dev
, MAP_1
);
8550 dev
->vol
.migr_state
= 0;
8551 set_migr_type(dev
, 0);
8552 set_vol_curr_migr_unit(dev
, 0);
8554 sizeof_imsm_map(map2
));
8555 super
->updates_pending
++;
8558 if (a
->last_checkpoint
>= a
->info
.component_size
) {
8559 unsigned long long array_blocks
;
8563 used_disks
= imsm_num_data_members(map
);
8564 if (used_disks
> 0) {
8566 per_dev_array_size(map
) *
8569 round_size_to_mb(array_blocks
,
8571 a
->info
.custom_array_size
= array_blocks
;
8572 /* encourage manager to update array
8576 a
->check_reshape
= 1;
8578 /* finalize online capacity expansion/reshape */
8579 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
8581 mdi
->disk
.raid_disk
,
8584 imsm_progress_container_reshape(super
);
8589 /* before we activate this array handle any missing disks */
8590 if (consistent
== 2)
8591 handle_missing(super
, dev
);
8593 if (consistent
== 2 &&
8594 (!is_resync_complete(&a
->info
) ||
8595 map_state
!= IMSM_T_STATE_NORMAL
||
8596 dev
->vol
.migr_state
))
8599 if (is_resync_complete(&a
->info
)) {
8600 /* complete intialization / resync,
8601 * recovery and interrupted recovery is completed in
8604 if (is_resyncing(dev
)) {
8605 dprintf("imsm: mark resync done\n");
8606 end_migration(dev
, super
, map_state
);
8607 super
->updates_pending
++;
8608 a
->last_checkpoint
= 0;
8610 } else if ((!is_resyncing(dev
) && !failed
) &&
8611 (imsm_reshape_blocks_arrays_changes(super
) == 0)) {
8612 /* mark the start of the init process if nothing is failed */
8613 dprintf("imsm: mark resync start\n");
8614 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
8615 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
8617 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
8618 super
->updates_pending
++;
8622 /* skip checkpointing for general migration,
8623 * it is controlled in mdadm
8625 if (is_gen_migration(dev
))
8626 goto skip_mark_checkpoint
;
8628 /* check if we can update vol_curr_migr_unit from resync_start,
8631 blocks_per_unit
= blocks_per_migr_unit(super
, dev
);
8632 if (blocks_per_unit
) {
8633 set_vol_curr_migr_unit(dev
,
8634 a
->last_checkpoint
/ blocks_per_unit
);
8635 dprintf("imsm: mark checkpoint (%llu)\n",
8636 vol_curr_migr_unit(dev
));
8637 super
->updates_pending
++;
8640 skip_mark_checkpoint
:
8641 /* mark dirty / clean */
8642 if (((dev
->vol
.dirty
& RAIDVOL_DIRTY
) && consistent
) ||
8643 (!(dev
->vol
.dirty
& RAIDVOL_DIRTY
) && !consistent
)) {
8644 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
8646 dev
->vol
.dirty
= RAIDVOL_CLEAN
;
8648 dev
->vol
.dirty
= RAIDVOL_DIRTY
;
8649 if (dev
->rwh_policy
== RWH_DISTRIBUTED
||
8650 dev
->rwh_policy
== RWH_MULTIPLE_DISTRIBUTED
)
8651 dev
->vol
.dirty
|= RAIDVOL_DSRECORD_VALID
;
8653 super
->updates_pending
++;
8659 static int imsm_disk_slot_to_ord(struct active_array
*a
, int slot
)
8661 int inst
= a
->info
.container_member
;
8662 struct intel_super
*super
= a
->container
->sb
;
8663 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8664 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8666 if (slot
> map
->num_members
) {
8667 pr_err("imsm: imsm_disk_slot_to_ord %d out of range 0..%d\n",
8668 slot
, map
->num_members
- 1);
8675 return get_imsm_ord_tbl_ent(dev
, slot
, MAP_0
);
8678 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
8680 int inst
= a
->info
.container_member
;
8681 struct intel_super
*super
= a
->container
->sb
;
8682 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8683 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8684 struct imsm_disk
*disk
;
8686 int recovery_not_finished
= 0;
8690 int rebuild_done
= 0;
8693 ord
= get_imsm_ord_tbl_ent(dev
, n
, MAP_X
);
8697 dprintf("imsm: set_disk %d:%x\n", n
, state
);
8698 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
8700 /* check for new failures */
8701 if (disk
&& (state
& DS_FAULTY
)) {
8702 if (mark_failure(super
, dev
, disk
, ord_to_idx(ord
)))
8703 super
->updates_pending
++;
8706 /* check if in_sync */
8707 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
8708 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
8710 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
8712 super
->updates_pending
++;
8715 failed
= imsm_count_failed(super
, dev
, MAP_0
);
8716 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8718 /* check if recovery complete, newly degraded, or failed */
8719 dprintf("imsm: Detected transition to state ");
8720 switch (map_state
) {
8721 case IMSM_T_STATE_NORMAL
: /* transition to normal state */
8722 dprintf("normal: ");
8723 if (is_rebuilding(dev
)) {
8724 dprintf_cont("while rebuilding");
8725 /* check if recovery is really finished */
8726 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
8727 if (mdi
->recovery_start
!= MaxSector
) {
8728 recovery_not_finished
= 1;
8731 if (recovery_not_finished
) {
8733 dprintf("Rebuild has not finished yet, state not changed");
8734 if (a
->last_checkpoint
< mdi
->recovery_start
) {
8735 a
->last_checkpoint
= mdi
->recovery_start
;
8736 super
->updates_pending
++;
8740 end_migration(dev
, super
, map_state
);
8741 map
->failed_disk_num
= ~0;
8742 super
->updates_pending
++;
8743 a
->last_checkpoint
= 0;
8746 if (is_gen_migration(dev
)) {
8747 dprintf_cont("while general migration");
8748 if (a
->last_checkpoint
>= a
->info
.component_size
)
8749 end_migration(dev
, super
, map_state
);
8751 map
->map_state
= map_state
;
8752 map
->failed_disk_num
= ~0;
8753 super
->updates_pending
++;
8757 case IMSM_T_STATE_DEGRADED
: /* transition to degraded state */
8758 dprintf_cont("degraded: ");
8759 if (map
->map_state
!= map_state
&& !dev
->vol
.migr_state
) {
8760 dprintf_cont("mark degraded");
8761 map
->map_state
= map_state
;
8762 super
->updates_pending
++;
8763 a
->last_checkpoint
= 0;
8766 if (is_rebuilding(dev
)) {
8767 dprintf_cont("while rebuilding ");
8768 if (state
& DS_FAULTY
) {
8769 dprintf_cont("removing failed drive ");
8770 if (n
== map
->failed_disk_num
) {
8771 dprintf_cont("end migration");
8772 end_migration(dev
, super
, map_state
);
8773 a
->last_checkpoint
= 0;
8775 dprintf_cont("fail detected during rebuild, changing map state");
8776 map
->map_state
= map_state
;
8778 super
->updates_pending
++;
8784 /* check if recovery is really finished */
8785 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
8786 if (mdi
->recovery_start
!= MaxSector
) {
8787 recovery_not_finished
= 1;
8790 if (recovery_not_finished
) {
8792 dprintf_cont("Rebuild has not finished yet");
8793 if (a
->last_checkpoint
< mdi
->recovery_start
) {
8794 a
->last_checkpoint
=
8795 mdi
->recovery_start
;
8796 super
->updates_pending
++;
8801 dprintf_cont(" Rebuild done, still degraded");
8802 end_migration(dev
, super
, map_state
);
8803 a
->last_checkpoint
= 0;
8804 super
->updates_pending
++;
8806 for (i
= 0; i
< map
->num_members
; i
++) {
8807 int idx
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
8809 if (idx
& IMSM_ORD_REBUILD
)
8810 map
->failed_disk_num
= i
;
8812 super
->updates_pending
++;
8815 if (is_gen_migration(dev
)) {
8816 dprintf_cont("while general migration");
8817 if (a
->last_checkpoint
>= a
->info
.component_size
)
8818 end_migration(dev
, super
, map_state
);
8820 map
->map_state
= map_state
;
8821 manage_second_map(super
, dev
);
8823 super
->updates_pending
++;
8826 if (is_initializing(dev
)) {
8827 dprintf_cont("while initialization.");
8828 map
->map_state
= map_state
;
8829 super
->updates_pending
++;
8833 case IMSM_T_STATE_FAILED
: /* transition to failed state */
8834 dprintf_cont("failed: ");
8835 if (is_gen_migration(dev
)) {
8836 dprintf_cont("while general migration");
8837 map
->map_state
= map_state
;
8838 super
->updates_pending
++;
8841 if (map
->map_state
!= map_state
) {
8842 dprintf_cont("mark failed");
8843 end_migration(dev
, super
, map_state
);
8844 super
->updates_pending
++;
8845 a
->last_checkpoint
= 0;
8850 dprintf_cont("state %i\n", map_state
);
8855 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
8858 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
8859 unsigned long long dsize
;
8860 unsigned long long sectors
;
8861 unsigned int sector_size
;
8863 if (!get_dev_sector_size(fd
, NULL
, §or_size
))
8865 get_dev_size(fd
, NULL
, &dsize
);
8867 if (mpb_size
> sector_size
) {
8868 /* -1 to account for anchor */
8869 sectors
= mpb_sectors(mpb
, sector_size
) - 1;
8871 /* write the extended mpb to the sectors preceeding the anchor */
8872 if (lseek64(fd
, dsize
- (sector_size
* (2 + sectors
)),
8876 if ((unsigned long long)write(fd
, buf
+ sector_size
,
8877 sector_size
* sectors
) != sector_size
* sectors
)
8881 /* first block is stored on second to last sector of the disk */
8882 if (lseek64(fd
, dsize
- (sector_size
* 2), SEEK_SET
) < 0)
8885 if ((unsigned int)write(fd
, buf
, sector_size
) != sector_size
)
8891 static void imsm_sync_metadata(struct supertype
*container
)
8893 struct intel_super
*super
= container
->sb
;
8895 dprintf("sync metadata: %d\n", super
->updates_pending
);
8896 if (!super
->updates_pending
)
8899 write_super_imsm(container
, 0);
8901 super
->updates_pending
= 0;
8904 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
8906 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
8907 int i
= get_imsm_disk_idx(dev
, idx
, MAP_X
);
8910 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8914 if (dl
&& is_failed(&dl
->disk
))
8918 dprintf("found %x:%x\n", dl
->major
, dl
->minor
);
8923 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
8924 struct active_array
*a
, int activate_new
,
8925 struct mdinfo
*additional_test_list
)
8927 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
8928 int idx
= get_imsm_disk_idx(dev
, slot
, MAP_X
);
8929 struct imsm_super
*mpb
= super
->anchor
;
8930 struct imsm_map
*map
;
8931 unsigned long long pos
;
8936 __u32 array_start
= 0;
8937 __u32 array_end
= 0;
8939 struct mdinfo
*test_list
;
8941 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
8942 /* If in this array, skip */
8943 for (d
= a
->info
.devs
; d
; d
= d
->next
)
8944 if (d
->state_fd
>= 0 &&
8945 d
->disk
.major
== dl
->major
&&
8946 d
->disk
.minor
== dl
->minor
) {
8947 dprintf("%x:%x already in array\n",
8948 dl
->major
, dl
->minor
);
8953 test_list
= additional_test_list
;
8955 if (test_list
->disk
.major
== dl
->major
&&
8956 test_list
->disk
.minor
== dl
->minor
) {
8957 dprintf("%x:%x already in additional test list\n",
8958 dl
->major
, dl
->minor
);
8961 test_list
= test_list
->next
;
8966 /* skip in use or failed drives */
8967 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
8969 dprintf("%x:%x status (failed: %d index: %d)\n",
8970 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
8974 /* skip pure spares when we are looking for partially
8975 * assimilated drives
8977 if (dl
->index
== -1 && !activate_new
)
8980 if (!drive_validate_sector_size(super
, dl
))
8983 /* Does this unused device have the requisite free space?
8984 * It needs to be able to cover all member volumes
8986 ex
= get_extents(super
, dl
, 1);
8988 dprintf("cannot get extents\n");
8991 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8992 dev
= get_imsm_dev(super
, i
);
8993 map
= get_imsm_map(dev
, MAP_0
);
8995 /* check if this disk is already a member of
8998 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
9004 array_start
= pba_of_lba0(map
);
9005 array_end
= array_start
+
9006 per_dev_array_size(map
) - 1;
9009 /* check that we can start at pba_of_lba0 with
9010 * num_data_stripes*blocks_per_stripe of space
9012 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
9016 pos
= ex
[j
].start
+ ex
[j
].size
;
9018 } while (ex
[j
-1].size
);
9025 if (i
< mpb
->num_raid_devs
) {
9026 dprintf("%x:%x does not have %u to %u available\n",
9027 dl
->major
, dl
->minor
, array_start
, array_end
);
9037 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
9039 struct imsm_dev
*dev2
;
9040 struct imsm_map
*map
;
9046 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
9048 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
, MAP_0
);
9049 if (state
== IMSM_T_STATE_FAILED
) {
9050 map
= get_imsm_map(dev2
, MAP_0
);
9053 for (slot
= 0; slot
< map
->num_members
; slot
++) {
9055 * Check if failed disks are deleted from intel
9056 * disk list or are marked to be deleted
9058 idx
= get_imsm_disk_idx(dev2
, slot
, MAP_X
);
9059 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
9061 * Do not rebuild the array if failed disks
9062 * from failed sub-array are not removed from
9066 is_failed(&idisk
->disk
) &&
9067 (idisk
->action
!= DISK_REMOVE
))
9075 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
9076 struct metadata_update
**updates
)
9079 * Find a device with unused free space and use it to replace a
9080 * failed/vacant region in an array. We replace failed regions one a
9081 * array at a time. The result is that a new spare disk will be added
9082 * to the first failed array and after the monitor has finished
9083 * propagating failures the remainder will be consumed.
9085 * FIXME add a capability for mdmon to request spares from another
9089 struct intel_super
*super
= a
->container
->sb
;
9090 int inst
= a
->info
.container_member
;
9091 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
9092 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9093 int failed
= a
->info
.array
.raid_disks
;
9094 struct mdinfo
*rv
= NULL
;
9097 struct metadata_update
*mu
;
9099 struct imsm_update_activate_spare
*u
;
9104 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
9105 if ((d
->curr_state
& DS_FAULTY
) &&
9107 /* wait for Removal to happen */
9109 if (d
->state_fd
>= 0)
9113 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
9114 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
9116 if (imsm_reshape_blocks_arrays_changes(super
))
9119 /* Cannot activate another spare if rebuild is in progress already
9121 if (is_rebuilding(dev
)) {
9122 dprintf("imsm: No spare activation allowed. Rebuild in progress already.\n");
9126 if (a
->info
.array
.level
== 4)
9127 /* No repair for takeovered array
9128 * imsm doesn't support raid4
9132 if (imsm_check_degraded(super
, dev
, failed
, MAP_0
) !=
9133 IMSM_T_STATE_DEGRADED
)
9136 if (get_imsm_map(dev
, MAP_0
)->map_state
== IMSM_T_STATE_UNINITIALIZED
) {
9137 dprintf("imsm: No spare activation allowed. Volume is not initialized.\n");
9142 * If there are any failed disks check state of the other volume.
9143 * Block rebuild if the another one is failed until failed disks
9144 * are removed from container.
9147 dprintf("found failed disks in %.*s, check if there anotherfailed sub-array.\n",
9148 MAX_RAID_SERIAL_LEN
, dev
->volume
);
9149 /* check if states of the other volumes allow for rebuild */
9150 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
9152 allowed
= imsm_rebuild_allowed(a
->container
,
9160 /* For each slot, if it is not working, find a spare */
9161 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
9162 for (d
= a
->info
.devs
; d
; d
= d
->next
)
9163 if (d
->disk
.raid_disk
== i
)
9165 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
9166 if (d
&& (d
->state_fd
>= 0))
9170 * OK, this device needs recovery. Try to re-add the
9171 * previous occupant of this slot, if this fails see if
9172 * we can continue the assimilation of a spare that was
9173 * partially assimilated, finally try to activate a new
9176 dl
= imsm_readd(super
, i
, a
);
9178 dl
= imsm_add_spare(super
, i
, a
, 0, rv
);
9180 dl
= imsm_add_spare(super
, i
, a
, 1, rv
);
9184 /* found a usable disk with enough space */
9185 di
= xcalloc(1, sizeof(*di
));
9187 /* dl->index will be -1 in the case we are activating a
9188 * pristine spare. imsm_process_update() will create a
9189 * new index in this case. Once a disk is found to be
9190 * failed in all member arrays it is kicked from the
9193 di
->disk
.number
= dl
->index
;
9195 /* (ab)use di->devs to store a pointer to the device
9198 di
->devs
= (struct mdinfo
*) dl
;
9200 di
->disk
.raid_disk
= i
;
9201 di
->disk
.major
= dl
->major
;
9202 di
->disk
.minor
= dl
->minor
;
9204 di
->recovery_start
= 0;
9205 di
->data_offset
= pba_of_lba0(map
);
9206 di
->component_size
= a
->info
.component_size
;
9207 di
->container_member
= inst
;
9208 di
->bb
.supported
= 1;
9209 if (a
->info
.consistency_policy
== CONSISTENCY_POLICY_PPL
) {
9210 di
->ppl_sector
= get_ppl_sector(super
, inst
);
9211 di
->ppl_size
= MULTIPLE_PPL_AREA_SIZE_IMSM
>> 9;
9213 super
->random
= random32();
9217 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
9218 i
, di
->data_offset
);
9222 /* No spares found */
9224 /* Now 'rv' has a list of devices to return.
9225 * Create a metadata_update record to update the
9226 * disk_ord_tbl for the array
9228 mu
= xmalloc(sizeof(*mu
));
9229 mu
->buf
= xcalloc(num_spares
,
9230 sizeof(struct imsm_update_activate_spare
));
9232 mu
->space_list
= NULL
;
9233 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
9234 mu
->next
= *updates
;
9235 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
9237 for (di
= rv
; di
; di
= di
->next
) {
9238 u
->type
= update_activate_spare
;
9239 u
->dl
= (struct dl
*) di
->devs
;
9241 u
->slot
= di
->disk
.raid_disk
;
9252 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
9254 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
9255 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9256 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, MAP_0
);
9257 struct disk_info
*inf
= get_disk_info(u
);
9258 struct imsm_disk
*disk
;
9262 for (i
= 0; i
< map
->num_members
; i
++) {
9263 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, MAP_X
));
9264 for (j
= 0; j
< new_map
->num_members
; j
++)
9265 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
9272 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
9276 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
9277 if (dl
->major
== major
&& dl
->minor
== minor
)
9282 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
9288 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
9289 if (dl
->major
== major
&& dl
->minor
== minor
) {
9292 prev
->next
= dl
->next
;
9294 super
->disks
= dl
->next
;
9296 __free_imsm_disk(dl
, 1);
9297 dprintf("removed %x:%x\n", major
, minor
);
9305 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
9307 static int add_remove_disk_update(struct intel_super
*super
)
9309 int check_degraded
= 0;
9312 /* add/remove some spares to/from the metadata/contrainer */
9313 while (super
->disk_mgmt_list
) {
9314 struct dl
*disk_cfg
;
9316 disk_cfg
= super
->disk_mgmt_list
;
9317 super
->disk_mgmt_list
= disk_cfg
->next
;
9318 disk_cfg
->next
= NULL
;
9320 if (disk_cfg
->action
== DISK_ADD
) {
9321 disk_cfg
->next
= super
->disks
;
9322 super
->disks
= disk_cfg
;
9324 dprintf("added %x:%x\n",
9325 disk_cfg
->major
, disk_cfg
->minor
);
9326 } else if (disk_cfg
->action
== DISK_REMOVE
) {
9327 dprintf("Disk remove action processed: %x.%x\n",
9328 disk_cfg
->major
, disk_cfg
->minor
);
9329 disk
= get_disk_super(super
,
9333 /* store action status */
9334 disk
->action
= DISK_REMOVE
;
9335 /* remove spare disks only */
9336 if (disk
->index
== -1) {
9337 remove_disk_super(super
,
9341 disk_cfg
->fd
= disk
->fd
;
9345 /* release allocate disk structure */
9346 __free_imsm_disk(disk_cfg
, 1);
9349 return check_degraded
;
9352 static int apply_reshape_migration_update(struct imsm_update_reshape_migration
*u
,
9353 struct intel_super
*super
,
9356 struct intel_dev
*id
;
9357 void **tofree
= NULL
;
9360 dprintf("(enter)\n");
9361 if (u
->subdev
< 0 || u
->subdev
> 1) {
9362 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
9365 if (space_list
== NULL
|| *space_list
== NULL
) {
9366 dprintf("imsm: Error: Memory is not allocated\n");
9370 for (id
= super
->devlist
; id
; id
= id
->next
) {
9371 if (id
->index
== (unsigned)u
->subdev
) {
9372 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
9373 struct imsm_map
*map
;
9374 struct imsm_dev
*new_dev
=
9375 (struct imsm_dev
*)*space_list
;
9376 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
9378 struct dl
*new_disk
;
9380 if (new_dev
== NULL
)
9382 *space_list
= **space_list
;
9383 memcpy(new_dev
, dev
, sizeof_imsm_dev(dev
, 0));
9384 map
= get_imsm_map(new_dev
, MAP_0
);
9386 dprintf("imsm: Error: migration in progress");
9390 to_state
= map
->map_state
;
9391 if ((u
->new_level
== 5) && (map
->raid_level
== 0)) {
9393 /* this should not happen */
9394 if (u
->new_disks
[0] < 0) {
9395 map
->failed_disk_num
=
9396 map
->num_members
- 1;
9397 to_state
= IMSM_T_STATE_DEGRADED
;
9399 to_state
= IMSM_T_STATE_NORMAL
;
9401 migrate(new_dev
, super
, to_state
, MIGR_GEN_MIGR
);
9402 if (u
->new_level
> -1)
9403 map
->raid_level
= u
->new_level
;
9404 migr_map
= get_imsm_map(new_dev
, MAP_1
);
9405 if ((u
->new_level
== 5) &&
9406 (migr_map
->raid_level
== 0)) {
9407 int ord
= map
->num_members
- 1;
9408 migr_map
->num_members
--;
9409 if (u
->new_disks
[0] < 0)
9410 ord
|= IMSM_ORD_REBUILD
;
9411 set_imsm_ord_tbl_ent(map
,
9412 map
->num_members
- 1,
9416 tofree
= (void **)dev
;
9418 /* update chunk size
9420 if (u
->new_chunksize
> 0) {
9421 struct imsm_map
*dest_map
=
9422 get_imsm_map(dev
, MAP_0
);
9424 imsm_num_data_members(dest_map
);
9426 if (used_disks
== 0)
9429 map
->blocks_per_strip
=
9430 __cpu_to_le16(u
->new_chunksize
* 2);
9431 update_num_data_stripes(map
, imsm_dev_size(dev
));
9434 /* ensure blocks_per_member has valid value
9436 set_blocks_per_member(map
,
9437 per_dev_array_size(map
) +
9438 NUM_BLOCKS_DIRTY_STRIPE_REGION
);
9442 if (u
->new_level
!= 5 || migr_map
->raid_level
!= 0 ||
9443 migr_map
->raid_level
== map
->raid_level
)
9446 if (u
->new_disks
[0] >= 0) {
9449 new_disk
= get_disk_super(super
,
9450 major(u
->new_disks
[0]),
9451 minor(u
->new_disks
[0]));
9452 dprintf("imsm: new disk for reshape is: %i:%i (%p, index = %i)\n",
9453 major(u
->new_disks
[0]),
9454 minor(u
->new_disks
[0]),
9455 new_disk
, new_disk
->index
);
9456 if (new_disk
== NULL
)
9457 goto error_disk_add
;
9459 new_disk
->index
= map
->num_members
- 1;
9460 /* slot to fill in autolayout
9462 new_disk
->raiddisk
= new_disk
->index
;
9463 new_disk
->disk
.status
|= CONFIGURED_DISK
;
9464 new_disk
->disk
.status
&= ~SPARE_DISK
;
9466 goto error_disk_add
;
9469 *tofree
= *space_list
;
9470 /* calculate new size
9472 imsm_set_array_size(new_dev
, -1);
9479 *space_list
= tofree
;
9483 dprintf("Error: imsm: Cannot find disk.\n");
9487 static int apply_size_change_update(struct imsm_update_size_change
*u
,
9488 struct intel_super
*super
)
9490 struct intel_dev
*id
;
9493 dprintf("(enter)\n");
9494 if (u
->subdev
< 0 || u
->subdev
> 1) {
9495 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
9499 for (id
= super
->devlist
; id
; id
= id
->next
) {
9500 if (id
->index
== (unsigned)u
->subdev
) {
9501 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
9502 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9503 int used_disks
= imsm_num_data_members(map
);
9504 unsigned long long blocks_per_member
;
9505 unsigned long long new_size_per_disk
;
9507 if (used_disks
== 0)
9510 /* calculate new size
9512 new_size_per_disk
= u
->new_size
/ used_disks
;
9513 blocks_per_member
= new_size_per_disk
+
9514 NUM_BLOCKS_DIRTY_STRIPE_REGION
;
9516 imsm_set_array_size(dev
, u
->new_size
);
9517 set_blocks_per_member(map
, blocks_per_member
);
9518 update_num_data_stripes(map
, u
->new_size
);
9527 static int prepare_spare_to_activate(struct supertype
*st
,
9528 struct imsm_update_activate_spare
*u
)
9530 struct intel_super
*super
= st
->sb
;
9531 int prev_current_vol
= super
->current_vol
;
9532 struct active_array
*a
;
9535 for (a
= st
->arrays
; a
; a
= a
->next
)
9537 * Additional initialization (adding bitmap header, filling
9538 * the bitmap area with '1's to force initial rebuild for a whole
9539 * data-area) is required when adding the spare to the volume
9540 * with write-intent bitmap.
9542 if (a
->info
.container_member
== u
->array
&&
9543 a
->info
.consistency_policy
== CONSISTENCY_POLICY_BITMAP
) {
9546 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
9552 super
->current_vol
= u
->array
;
9553 if (st
->ss
->write_bitmap(st
, dl
->fd
, NoUpdate
))
9555 super
->current_vol
= prev_current_vol
;
9560 static int apply_update_activate_spare(struct imsm_update_activate_spare
*u
,
9561 struct intel_super
*super
,
9562 struct active_array
*active_array
)
9564 struct imsm_super
*mpb
= super
->anchor
;
9565 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
9566 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9567 struct imsm_map
*migr_map
;
9568 struct active_array
*a
;
9569 struct imsm_disk
*disk
;
9576 int second_map_created
= 0;
9578 for (; u
; u
= u
->next
) {
9579 victim
= get_imsm_disk_idx(dev
, u
->slot
, MAP_X
);
9584 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
9589 pr_err("error: imsm_activate_spare passed an unknown disk (index: %d)\n",
9594 /* count failures (excluding rebuilds and the victim)
9595 * to determine map[0] state
9598 for (i
= 0; i
< map
->num_members
; i
++) {
9601 disk
= get_imsm_disk(super
,
9602 get_imsm_disk_idx(dev
, i
, MAP_X
));
9603 if (!disk
|| is_failed(disk
))
9607 /* adding a pristine spare, assign a new index */
9608 if (dl
->index
< 0) {
9609 dl
->index
= super
->anchor
->num_disks
;
9610 super
->anchor
->num_disks
++;
9613 disk
->status
|= CONFIGURED_DISK
;
9614 disk
->status
&= ~SPARE_DISK
;
9617 to_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
9618 if (!second_map_created
) {
9619 second_map_created
= 1;
9620 map
->map_state
= IMSM_T_STATE_DEGRADED
;
9621 migrate(dev
, super
, to_state
, MIGR_REBUILD
);
9623 map
->map_state
= to_state
;
9624 migr_map
= get_imsm_map(dev
, MAP_1
);
9625 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
9626 set_imsm_ord_tbl_ent(migr_map
, u
->slot
,
9627 dl
->index
| IMSM_ORD_REBUILD
);
9629 /* update the family_num to mark a new container
9630 * generation, being careful to record the existing
9631 * family_num in orig_family_num to clean up after
9632 * earlier mdadm versions that neglected to set it.
9634 if (mpb
->orig_family_num
== 0)
9635 mpb
->orig_family_num
= mpb
->family_num
;
9636 mpb
->family_num
+= super
->random
;
9638 /* count arrays using the victim in the metadata */
9640 for (a
= active_array
; a
; a
= a
->next
) {
9641 dev
= get_imsm_dev(super
, a
->info
.container_member
);
9642 map
= get_imsm_map(dev
, MAP_0
);
9644 if (get_imsm_disk_slot(map
, victim
) >= 0)
9648 /* delete the victim if it is no longer being
9654 /* We know that 'manager' isn't touching anything,
9655 * so it is safe to delete
9657 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
9658 if ((*dlp
)->index
== victim
)
9661 /* victim may be on the missing list */
9663 for (dlp
= &super
->missing
; *dlp
;
9664 dlp
= &(*dlp
)->next
)
9665 if ((*dlp
)->index
== victim
)
9667 imsm_delete(super
, dlp
, victim
);
9674 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
9675 struct intel_super
*super
,
9678 struct dl
*new_disk
;
9679 struct intel_dev
*id
;
9681 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
9682 int disk_count
= u
->old_raid_disks
;
9683 void **tofree
= NULL
;
9684 int devices_to_reshape
= 1;
9685 struct imsm_super
*mpb
= super
->anchor
;
9687 unsigned int dev_id
;
9689 dprintf("(enter)\n");
9691 /* enable spares to use in array */
9692 for (i
= 0; i
< delta_disks
; i
++) {
9693 new_disk
= get_disk_super(super
,
9694 major(u
->new_disks
[i
]),
9695 minor(u
->new_disks
[i
]));
9696 dprintf("imsm: new disk for reshape is: %i:%i (%p, index = %i)\n",
9697 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
9698 new_disk
, new_disk
->index
);
9699 if (new_disk
== NULL
||
9700 (new_disk
->index
>= 0 &&
9701 new_disk
->index
< u
->old_raid_disks
))
9702 goto update_reshape_exit
;
9703 new_disk
->index
= disk_count
++;
9704 /* slot to fill in autolayout
9706 new_disk
->raiddisk
= new_disk
->index
;
9707 new_disk
->disk
.status
|=
9709 new_disk
->disk
.status
&= ~SPARE_DISK
;
9712 dprintf("imsm: volume set mpb->num_raid_devs = %i\n",
9713 mpb
->num_raid_devs
);
9714 /* manage changes in volume
9716 for (dev_id
= 0; dev_id
< mpb
->num_raid_devs
; dev_id
++) {
9717 void **sp
= *space_list
;
9718 struct imsm_dev
*newdev
;
9719 struct imsm_map
*newmap
, *oldmap
;
9721 for (id
= super
->devlist
; id
; id
= id
->next
) {
9722 if (id
->index
== dev_id
)
9731 /* Copy the dev, but not (all of) the map */
9732 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
9733 oldmap
= get_imsm_map(id
->dev
, MAP_0
);
9734 newmap
= get_imsm_map(newdev
, MAP_0
);
9735 /* Copy the current map */
9736 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
9737 /* update one device only
9739 if (devices_to_reshape
) {
9740 dprintf("imsm: modifying subdev: %i\n",
9742 devices_to_reshape
--;
9743 newdev
->vol
.migr_state
= 1;
9744 set_vol_curr_migr_unit(newdev
, 0);
9745 set_migr_type(newdev
, MIGR_GEN_MIGR
);
9746 newmap
->num_members
= u
->new_raid_disks
;
9747 for (i
= 0; i
< delta_disks
; i
++) {
9748 set_imsm_ord_tbl_ent(newmap
,
9749 u
->old_raid_disks
+ i
,
9750 u
->old_raid_disks
+ i
);
9752 /* New map is correct, now need to save old map
9754 newmap
= get_imsm_map(newdev
, MAP_1
);
9755 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
9757 imsm_set_array_size(newdev
, -1);
9760 sp
= (void **)id
->dev
;
9765 /* Clear migration record */
9766 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
9769 *space_list
= tofree
;
9772 update_reshape_exit
:
9777 static int apply_takeover_update(struct imsm_update_takeover
*u
,
9778 struct intel_super
*super
,
9781 struct imsm_dev
*dev
= NULL
;
9782 struct intel_dev
*dv
;
9783 struct imsm_dev
*dev_new
;
9784 struct imsm_map
*map
;
9788 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
9789 if (dv
->index
== (unsigned int)u
->subarray
) {
9797 map
= get_imsm_map(dev
, MAP_0
);
9799 if (u
->direction
== R10_TO_R0
) {
9800 /* Number of failed disks must be half of initial disk number */
9801 if (imsm_count_failed(super
, dev
, MAP_0
) !=
9802 (map
->num_members
/ 2))
9805 /* iterate through devices to mark removed disks as spare */
9806 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
9807 if (dm
->disk
.status
& FAILED_DISK
) {
9808 int idx
= dm
->index
;
9809 /* update indexes on the disk list */
9810 /* FIXME this loop-with-the-loop looks wrong, I'm not convinced
9811 the index values will end up being correct.... NB */
9812 for (du
= super
->disks
; du
; du
= du
->next
)
9813 if (du
->index
> idx
)
9815 /* mark as spare disk */
9820 map
->num_members
/= map
->num_domains
;
9821 map
->map_state
= IMSM_T_STATE_NORMAL
;
9822 map
->raid_level
= 0;
9823 set_num_domains(map
);
9824 update_num_data_stripes(map
, imsm_dev_size(dev
));
9825 map
->failed_disk_num
= -1;
9828 if (u
->direction
== R0_TO_R10
) {
9831 /* update slots in current disk list */
9832 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
9836 /* create new *missing* disks */
9837 for (i
= 0; i
< map
->num_members
; i
++) {
9838 space
= *space_list
;
9841 *space_list
= *space
;
9843 memcpy(du
, super
->disks
, sizeof(*du
));
9847 du
->index
= (i
* 2) + 1;
9848 sprintf((char *)du
->disk
.serial
,
9849 " MISSING_%d", du
->index
);
9850 sprintf((char *)du
->serial
,
9851 "MISSING_%d", du
->index
);
9852 du
->next
= super
->missing
;
9853 super
->missing
= du
;
9855 /* create new dev and map */
9856 space
= *space_list
;
9859 *space_list
= *space
;
9860 dev_new
= (void *)space
;
9861 memcpy(dev_new
, dev
, sizeof(*dev
));
9862 /* update new map */
9863 map
= get_imsm_map(dev_new
, MAP_0
);
9865 map
->map_state
= IMSM_T_STATE_DEGRADED
;
9866 map
->raid_level
= 1;
9867 set_num_domains(map
);
9868 map
->num_members
= map
->num_members
* map
->num_domains
;
9869 update_num_data_stripes(map
, imsm_dev_size(dev
));
9871 /* replace dev<->dev_new */
9874 /* update disk order table */
9875 for (du
= super
->disks
; du
; du
= du
->next
)
9877 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
9878 for (du
= super
->missing
; du
; du
= du
->next
)
9879 if (du
->index
>= 0) {
9880 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
9881 mark_missing(super
, dv
->dev
, &du
->disk
, du
->index
);
9887 static void imsm_process_update(struct supertype
*st
,
9888 struct metadata_update
*update
)
9891 * crack open the metadata_update envelope to find the update record
9892 * update can be one of:
9893 * update_reshape_container_disks - all the arrays in the container
9894 * are being reshaped to have more devices. We need to mark
9895 * the arrays for general migration and convert selected spares
9896 * into active devices.
9897 * update_activate_spare - a spare device has replaced a failed
9898 * device in an array, update the disk_ord_tbl. If this disk is
9899 * present in all member arrays then also clear the SPARE_DISK
9901 * update_create_array
9903 * update_rename_array
9904 * update_add_remove_disk
9906 struct intel_super
*super
= st
->sb
;
9907 struct imsm_super
*mpb
;
9908 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
9910 /* update requires a larger buf but the allocation failed */
9911 if (super
->next_len
&& !super
->next_buf
) {
9912 super
->next_len
= 0;
9916 if (super
->next_buf
) {
9917 memcpy(super
->next_buf
, super
->buf
, super
->len
);
9919 super
->len
= super
->next_len
;
9920 super
->buf
= super
->next_buf
;
9922 super
->next_len
= 0;
9923 super
->next_buf
= NULL
;
9926 mpb
= super
->anchor
;
9929 case update_general_migration_checkpoint
: {
9930 struct intel_dev
*id
;
9931 struct imsm_update_general_migration_checkpoint
*u
=
9932 (void *)update
->buf
;
9934 dprintf("called for update_general_migration_checkpoint\n");
9936 /* find device under general migration */
9937 for (id
= super
->devlist
; id
; id
= id
->next
) {
9938 if (is_gen_migration(id
->dev
)) {
9939 set_vol_curr_migr_unit(id
->dev
,
9941 super
->updates_pending
++;
9946 case update_takeover
: {
9947 struct imsm_update_takeover
*u
= (void *)update
->buf
;
9948 if (apply_takeover_update(u
, super
, &update
->space_list
)) {
9949 imsm_update_version_info(super
);
9950 super
->updates_pending
++;
9955 case update_reshape_container_disks
: {
9956 struct imsm_update_reshape
*u
= (void *)update
->buf
;
9957 if (apply_reshape_container_disks_update(
9958 u
, super
, &update
->space_list
))
9959 super
->updates_pending
++;
9962 case update_reshape_migration
: {
9963 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
9964 if (apply_reshape_migration_update(
9965 u
, super
, &update
->space_list
))
9966 super
->updates_pending
++;
9969 case update_size_change
: {
9970 struct imsm_update_size_change
*u
= (void *)update
->buf
;
9971 if (apply_size_change_update(u
, super
))
9972 super
->updates_pending
++;
9975 case update_activate_spare
: {
9976 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
9978 if (prepare_spare_to_activate(st
, u
) &&
9979 apply_update_activate_spare(u
, super
, st
->arrays
))
9980 super
->updates_pending
++;
9983 case update_create_array
: {
9984 /* someone wants to create a new array, we need to be aware of
9985 * a few races/collisions:
9986 * 1/ 'Create' called by two separate instances of mdadm
9987 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
9988 * devices that have since been assimilated via
9990 * In the event this update can not be carried out mdadm will
9991 * (FIX ME) notice that its update did not take hold.
9993 struct imsm_update_create_array
*u
= (void *) update
->buf
;
9994 struct intel_dev
*dv
;
9995 struct imsm_dev
*dev
;
9996 struct imsm_map
*map
, *new_map
;
9997 unsigned long long start
, end
;
9998 unsigned long long new_start
, new_end
;
10000 struct disk_info
*inf
;
10003 /* handle racing creates: first come first serve */
10004 if (u
->dev_idx
< mpb
->num_raid_devs
) {
10005 dprintf("subarray %d already defined\n", u
->dev_idx
);
10009 /* check update is next in sequence */
10010 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
10011 dprintf("can not create array %d expected index %d\n",
10012 u
->dev_idx
, mpb
->num_raid_devs
);
10016 new_map
= get_imsm_map(&u
->dev
, MAP_0
);
10017 new_start
= pba_of_lba0(new_map
);
10018 new_end
= new_start
+ per_dev_array_size(new_map
);
10019 inf
= get_disk_info(u
);
10021 /* handle activate_spare versus create race:
10022 * check to make sure that overlapping arrays do not include
10023 * overalpping disks
10025 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
10026 dev
= get_imsm_dev(super
, i
);
10027 map
= get_imsm_map(dev
, MAP_0
);
10028 start
= pba_of_lba0(map
);
10029 end
= start
+ per_dev_array_size(map
);
10030 if ((new_start
>= start
&& new_start
<= end
) ||
10031 (start
>= new_start
&& start
<= new_end
))
10036 if (disks_overlap(super
, i
, u
)) {
10037 dprintf("arrays overlap\n");
10042 /* check that prepare update was successful */
10043 if (!update
->space
) {
10044 dprintf("prepare update failed\n");
10048 /* check that all disks are still active before committing
10049 * changes. FIXME: could we instead handle this by creating a
10050 * degraded array? That's probably not what the user expects,
10051 * so better to drop this update on the floor.
10053 for (i
= 0; i
< new_map
->num_members
; i
++) {
10054 dl
= serial_to_dl(inf
[i
].serial
, super
);
10056 dprintf("disk disappeared\n");
10061 super
->updates_pending
++;
10063 /* convert spares to members and fixup ord_tbl */
10064 for (i
= 0; i
< new_map
->num_members
; i
++) {
10065 dl
= serial_to_dl(inf
[i
].serial
, super
);
10066 if (dl
->index
== -1) {
10067 dl
->index
= mpb
->num_disks
;
10069 dl
->disk
.status
|= CONFIGURED_DISK
;
10070 dl
->disk
.status
&= ~SPARE_DISK
;
10072 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
10075 dv
= update
->space
;
10077 update
->space
= NULL
;
10078 imsm_copy_dev(dev
, &u
->dev
);
10079 dv
->index
= u
->dev_idx
;
10080 dv
->next
= super
->devlist
;
10081 super
->devlist
= dv
;
10082 mpb
->num_raid_devs
++;
10084 imsm_update_version_info(super
);
10087 /* mdmon knows how to release update->space, but not
10088 * ((struct intel_dev *) update->space)->dev
10090 if (update
->space
) {
10091 dv
= update
->space
;
10096 case update_kill_array
: {
10097 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
10098 int victim
= u
->dev_idx
;
10099 struct active_array
*a
;
10100 struct intel_dev
**dp
;
10101 struct imsm_dev
*dev
;
10103 /* sanity check that we are not affecting the uuid of
10104 * active arrays, or deleting an active array
10106 * FIXME when immutable ids are available, but note that
10107 * we'll also need to fixup the invalidated/active
10108 * subarray indexes in mdstat
10110 for (a
= st
->arrays
; a
; a
= a
->next
)
10111 if (a
->info
.container_member
>= victim
)
10113 /* by definition if mdmon is running at least one array
10114 * is active in the container, so checking
10115 * mpb->num_raid_devs is just extra paranoia
10117 dev
= get_imsm_dev(super
, victim
);
10118 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
10119 dprintf("failed to delete subarray-%d\n", victim
);
10123 for (dp
= &super
->devlist
; *dp
;)
10124 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
10127 if ((*dp
)->index
> (unsigned)victim
)
10131 mpb
->num_raid_devs
--;
10132 super
->updates_pending
++;
10135 case update_rename_array
: {
10136 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
10137 char name
[MAX_RAID_SERIAL_LEN
+1];
10138 int target
= u
->dev_idx
;
10139 struct active_array
*a
;
10140 struct imsm_dev
*dev
;
10142 /* sanity check that we are not affecting the uuid of
10145 memset(name
, 0, sizeof(name
));
10146 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
10147 name
[MAX_RAID_SERIAL_LEN
] = '\0';
10148 for (a
= st
->arrays
; a
; a
= a
->next
)
10149 if (a
->info
.container_member
== target
)
10151 dev
= get_imsm_dev(super
, u
->dev_idx
);
10152 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
10153 dprintf("failed to rename subarray-%d\n", target
);
10157 memcpy(dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
10158 super
->updates_pending
++;
10161 case update_add_remove_disk
: {
10162 /* we may be able to repair some arrays if disks are
10163 * being added, check the status of add_remove_disk
10164 * if discs has been added.
10166 if (add_remove_disk_update(super
)) {
10167 struct active_array
*a
;
10169 super
->updates_pending
++;
10170 for (a
= st
->arrays
; a
; a
= a
->next
)
10171 a
->check_degraded
= 1;
10175 case update_prealloc_badblocks_mem
:
10177 case update_rwh_policy
: {
10178 struct imsm_update_rwh_policy
*u
= (void *)update
->buf
;
10179 int target
= u
->dev_idx
;
10180 struct imsm_dev
*dev
= get_imsm_dev(super
, target
);
10182 dprintf("could not find subarray-%d\n", target
);
10186 if (dev
->rwh_policy
!= u
->new_policy
) {
10187 dev
->rwh_policy
= u
->new_policy
;
10188 super
->updates_pending
++;
10193 pr_err("error: unsupported process update type:(type: %d)\n", type
);
10197 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
);
10199 static int imsm_prepare_update(struct supertype
*st
,
10200 struct metadata_update
*update
)
10203 * Allocate space to hold new disk entries, raid-device entries or a new
10204 * mpb if necessary. The manager synchronously waits for updates to
10205 * complete in the monitor, so new mpb buffers allocated here can be
10206 * integrated by the monitor thread without worrying about live pointers
10207 * in the manager thread.
10209 enum imsm_update_type type
;
10210 struct intel_super
*super
= st
->sb
;
10211 unsigned int sector_size
= super
->sector_size
;
10212 struct imsm_super
*mpb
= super
->anchor
;
10216 if (update
->len
< (int)sizeof(type
))
10219 type
= *(enum imsm_update_type
*) update
->buf
;
10222 case update_general_migration_checkpoint
:
10223 if (update
->len
< (int)sizeof(struct imsm_update_general_migration_checkpoint
))
10225 dprintf("called for update_general_migration_checkpoint\n");
10227 case update_takeover
: {
10228 struct imsm_update_takeover
*u
= (void *)update
->buf
;
10229 if (update
->len
< (int)sizeof(*u
))
10231 if (u
->direction
== R0_TO_R10
) {
10232 void **tail
= (void **)&update
->space_list
;
10233 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subarray
);
10234 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
10235 int num_members
= map
->num_members
;
10238 /* allocate memory for added disks */
10239 for (i
= 0; i
< num_members
; i
++) {
10240 size
= sizeof(struct dl
);
10241 space
= xmalloc(size
);
10246 /* allocate memory for new device */
10247 size
= sizeof_imsm_dev(super
->devlist
->dev
, 0) +
10248 (num_members
* sizeof(__u32
));
10249 space
= xmalloc(size
);
10253 len
= disks_to_mpb_size(num_members
* 2);
10258 case update_reshape_container_disks
: {
10259 /* Every raid device in the container is about to
10260 * gain some more devices, and we will enter a
10262 * So each 'imsm_map' will be bigger, and the imsm_vol
10263 * will now hold 2 of them.
10264 * Thus we need new 'struct imsm_dev' allocations sized
10265 * as sizeof_imsm_dev but with more devices in both maps.
10267 struct imsm_update_reshape
*u
= (void *)update
->buf
;
10268 struct intel_dev
*dl
;
10269 void **space_tail
= (void**)&update
->space_list
;
10271 if (update
->len
< (int)sizeof(*u
))
10274 dprintf("for update_reshape\n");
10276 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
10277 int size
= sizeof_imsm_dev(dl
->dev
, 1);
10279 if (u
->new_raid_disks
> u
->old_raid_disks
)
10280 size
+= sizeof(__u32
)*2*
10281 (u
->new_raid_disks
- u
->old_raid_disks
);
10285 *space_tail
= NULL
;
10288 len
= disks_to_mpb_size(u
->new_raid_disks
);
10289 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
10292 case update_reshape_migration
: {
10293 /* for migration level 0->5 we need to add disks
10294 * so the same as for container operation we will copy
10295 * device to the bigger location.
10296 * in memory prepared device and new disk area are prepared
10297 * for usage in process update
10299 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
10300 struct intel_dev
*id
;
10301 void **space_tail
= (void **)&update
->space_list
;
10304 int current_level
= -1;
10306 if (update
->len
< (int)sizeof(*u
))
10309 dprintf("for update_reshape\n");
10311 /* add space for bigger array in update
10313 for (id
= super
->devlist
; id
; id
= id
->next
) {
10314 if (id
->index
== (unsigned)u
->subdev
) {
10315 size
= sizeof_imsm_dev(id
->dev
, 1);
10316 if (u
->new_raid_disks
> u
->old_raid_disks
)
10317 size
+= sizeof(__u32
)*2*
10318 (u
->new_raid_disks
- u
->old_raid_disks
);
10322 *space_tail
= NULL
;
10326 if (update
->space_list
== NULL
)
10329 /* add space for disk in update
10331 size
= sizeof(struct dl
);
10335 *space_tail
= NULL
;
10337 /* add spare device to update
10339 for (id
= super
->devlist
; id
; id
= id
->next
)
10340 if (id
->index
== (unsigned)u
->subdev
) {
10341 struct imsm_dev
*dev
;
10342 struct imsm_map
*map
;
10344 dev
= get_imsm_dev(super
, u
->subdev
);
10345 map
= get_imsm_map(dev
, MAP_0
);
10346 current_level
= map
->raid_level
;
10349 if (u
->new_level
== 5 && u
->new_level
!= current_level
) {
10350 struct mdinfo
*spares
;
10352 spares
= get_spares_for_grow(st
);
10355 struct mdinfo
*dev
;
10357 dev
= spares
->devs
;
10360 makedev(dev
->disk
.major
,
10362 dl
= get_disk_super(super
,
10365 dl
->index
= u
->old_raid_disks
;
10368 sysfs_free(spares
);
10371 len
= disks_to_mpb_size(u
->new_raid_disks
);
10372 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
10375 case update_size_change
: {
10376 if (update
->len
< (int)sizeof(struct imsm_update_size_change
))
10380 case update_activate_spare
: {
10381 if (update
->len
< (int)sizeof(struct imsm_update_activate_spare
))
10385 case update_create_array
: {
10386 struct imsm_update_create_array
*u
= (void *) update
->buf
;
10387 struct intel_dev
*dv
;
10388 struct imsm_dev
*dev
= &u
->dev
;
10389 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
10391 struct disk_info
*inf
;
10395 if (update
->len
< (int)sizeof(*u
))
10398 inf
= get_disk_info(u
);
10399 len
= sizeof_imsm_dev(dev
, 1);
10400 /* allocate a new super->devlist entry */
10401 dv
= xmalloc(sizeof(*dv
));
10402 dv
->dev
= xmalloc(len
);
10403 update
->space
= dv
;
10405 /* count how many spares will be converted to members */
10406 for (i
= 0; i
< map
->num_members
; i
++) {
10407 dl
= serial_to_dl(inf
[i
].serial
, super
);
10409 /* hmm maybe it failed?, nothing we can do about
10414 if (count_memberships(dl
, super
) == 0)
10417 len
+= activate
* sizeof(struct imsm_disk
);
10420 case update_kill_array
: {
10421 if (update
->len
< (int)sizeof(struct imsm_update_kill_array
))
10425 case update_rename_array
: {
10426 if (update
->len
< (int)sizeof(struct imsm_update_rename_array
))
10430 case update_add_remove_disk
:
10431 /* no update->len needed */
10433 case update_prealloc_badblocks_mem
:
10434 super
->extra_space
+= sizeof(struct bbm_log
) -
10435 get_imsm_bbm_log_size(super
->bbm_log
);
10437 case update_rwh_policy
: {
10438 if (update
->len
< (int)sizeof(struct imsm_update_rwh_policy
))
10446 /* check if we need a larger metadata buffer */
10447 if (super
->next_buf
)
10448 buf_len
= super
->next_len
;
10450 buf_len
= super
->len
;
10452 if (__le32_to_cpu(mpb
->mpb_size
) + super
->extra_space
+ len
> buf_len
) {
10453 /* ok we need a larger buf than what is currently allocated
10454 * if this allocation fails process_update will notice that
10455 * ->next_len is set and ->next_buf is NULL
10457 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) +
10458 super
->extra_space
+ len
, sector_size
);
10459 if (super
->next_buf
)
10460 free(super
->next_buf
);
10462 super
->next_len
= buf_len
;
10463 if (posix_memalign(&super
->next_buf
, sector_size
, buf_len
) == 0)
10464 memset(super
->next_buf
, 0, buf_len
);
10466 super
->next_buf
= NULL
;
10471 /* must be called while manager is quiesced */
10472 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
10474 struct imsm_super
*mpb
= super
->anchor
;
10476 struct imsm_dev
*dev
;
10477 struct imsm_map
*map
;
10478 unsigned int i
, j
, num_members
;
10479 __u32 ord
, ord_map0
;
10480 struct bbm_log
*log
= super
->bbm_log
;
10482 dprintf("deleting device[%d] from imsm_super\n", index
);
10484 /* shift all indexes down one */
10485 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
10486 if (iter
->index
> (int)index
)
10488 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
10489 if (iter
->index
> (int)index
)
10492 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
10493 dev
= get_imsm_dev(super
, i
);
10494 map
= get_imsm_map(dev
, MAP_0
);
10495 num_members
= map
->num_members
;
10496 for (j
= 0; j
< num_members
; j
++) {
10497 /* update ord entries being careful not to propagate
10498 * ord-flags to the first map
10500 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_X
);
10501 ord_map0
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
10503 if (ord_to_idx(ord
) <= index
)
10506 map
= get_imsm_map(dev
, MAP_0
);
10507 set_imsm_ord_tbl_ent(map
, j
, ord_map0
- 1);
10508 map
= get_imsm_map(dev
, MAP_1
);
10510 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
10514 for (i
= 0; i
< log
->entry_count
; i
++) {
10515 struct bbm_log_entry
*entry
= &log
->marked_block_entries
[i
];
10517 if (entry
->disk_ordinal
<= index
)
10519 entry
->disk_ordinal
--;
10523 super
->updates_pending
++;
10525 struct dl
*dl
= *dlp
;
10527 *dlp
= (*dlp
)->next
;
10528 __free_imsm_disk(dl
, 1);
10532 static int imsm_get_allowed_degradation(int level
, int raid_disks
,
10533 struct intel_super
*super
,
10534 struct imsm_dev
*dev
)
10540 struct imsm_map
*map
;
10543 ret_val
= raid_disks
/2;
10544 /* check map if all disks pairs not failed
10547 map
= get_imsm_map(dev
, MAP_0
);
10548 for (i
= 0; i
< ret_val
; i
++) {
10549 int degradation
= 0;
10550 if (get_imsm_disk(super
, i
) == NULL
)
10552 if (get_imsm_disk(super
, i
+ 1) == NULL
)
10554 if (degradation
== 2)
10557 map
= get_imsm_map(dev
, MAP_1
);
10558 /* if there is no second map
10559 * result can be returned
10563 /* check degradation in second map
10565 for (i
= 0; i
< ret_val
; i
++) {
10566 int degradation
= 0;
10567 if (get_imsm_disk(super
, i
) == NULL
)
10569 if (get_imsm_disk(super
, i
+ 1) == NULL
)
10571 if (degradation
== 2)
10585 /*******************************************************************************
10586 * Function: validate_container_imsm
10587 * Description: This routine validates container after assemble,
10588 * eg. if devices in container are under the same controller.
10591 * info : linked list with info about devices used in array
10595 ******************************************************************************/
10596 int validate_container_imsm(struct mdinfo
*info
)
10598 if (check_env("IMSM_NO_PLATFORM"))
10601 struct sys_dev
*idev
;
10602 struct sys_dev
*hba
= NULL
;
10603 struct sys_dev
*intel_devices
= find_intel_devices();
10604 char *dev_path
= devt_to_devpath(makedev(info
->disk
.major
,
10605 info
->disk
.minor
), 1, NULL
);
10607 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
10608 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
10617 pr_err("WARNING - Cannot detect HBA for device %s!\n",
10618 devid2kname(makedev(info
->disk
.major
, info
->disk
.minor
)));
10622 const struct imsm_orom
*orom
= get_orom_by_device_id(hba
->dev_id
);
10623 struct mdinfo
*dev
;
10625 for (dev
= info
->next
; dev
; dev
= dev
->next
) {
10626 dev_path
= devt_to_devpath(makedev(dev
->disk
.major
,
10627 dev
->disk
.minor
), 1, NULL
);
10629 struct sys_dev
*hba2
= NULL
;
10630 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
10631 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
10639 const struct imsm_orom
*orom2
= hba2
== NULL
? NULL
:
10640 get_orom_by_device_id(hba2
->dev_id
);
10642 if (hba2
&& hba
->type
!= hba2
->type
) {
10643 pr_err("WARNING - HBAs of devices do not match %s != %s\n",
10644 get_sys_dev_type(hba
->type
), get_sys_dev_type(hba2
->type
));
10648 if (orom
!= orom2
) {
10649 pr_err("WARNING - IMSM container assembled with disks under different HBAs!\n"
10650 " This operation is not supported and can lead to data loss.\n");
10655 pr_err("WARNING - IMSM container assembled with disks under HBAs without IMSM platform support!\n"
10656 " This operation is not supported and can lead to data loss.\n");
10664 /*******************************************************************************
10665 * Function: imsm_record_badblock
10666 * Description: This routine stores new bad block record in BBM log
10669 * a : array containing a bad block
10670 * slot : disk number containing a bad block
10671 * sector : bad block sector
10672 * length : bad block sectors range
10676 ******************************************************************************/
10677 static int imsm_record_badblock(struct active_array
*a
, int slot
,
10678 unsigned long long sector
, int length
)
10680 struct intel_super
*super
= a
->container
->sb
;
10684 ord
= imsm_disk_slot_to_ord(a
, slot
);
10688 ret
= record_new_badblock(super
->bbm_log
, ord_to_idx(ord
), sector
,
10691 super
->updates_pending
++;
10695 /*******************************************************************************
10696 * Function: imsm_clear_badblock
10697 * Description: This routine clears bad block record from BBM log
10700 * a : array containing a bad block
10701 * slot : disk number containing a bad block
10702 * sector : bad block sector
10703 * length : bad block sectors range
10707 ******************************************************************************/
10708 static int imsm_clear_badblock(struct active_array
*a
, int slot
,
10709 unsigned long long sector
, int length
)
10711 struct intel_super
*super
= a
->container
->sb
;
10715 ord
= imsm_disk_slot_to_ord(a
, slot
);
10719 ret
= clear_badblock(super
->bbm_log
, ord_to_idx(ord
), sector
, length
);
10721 super
->updates_pending
++;
10725 /*******************************************************************************
10726 * Function: imsm_get_badblocks
10727 * Description: This routine get list of bad blocks for an array
10731 * slot : disk number
10733 * bb : structure containing bad blocks
10735 ******************************************************************************/
10736 static struct md_bb
*imsm_get_badblocks(struct active_array
*a
, int slot
)
10738 int inst
= a
->info
.container_member
;
10739 struct intel_super
*super
= a
->container
->sb
;
10740 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
10741 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
10744 ord
= imsm_disk_slot_to_ord(a
, slot
);
10748 get_volume_badblocks(super
->bbm_log
, ord_to_idx(ord
), pba_of_lba0(map
),
10749 per_dev_array_size(map
), &super
->bb
);
10753 /*******************************************************************************
10754 * Function: examine_badblocks_imsm
10755 * Description: Prints list of bad blocks on a disk to the standard output
10758 * st : metadata handler
10759 * fd : open file descriptor for device
10760 * devname : device name
10764 ******************************************************************************/
10765 static int examine_badblocks_imsm(struct supertype
*st
, int fd
, char *devname
)
10767 struct intel_super
*super
= st
->sb
;
10768 struct bbm_log
*log
= super
->bbm_log
;
10769 struct dl
*d
= NULL
;
10772 for (d
= super
->disks
; d
; d
= d
->next
) {
10773 if (strcmp(d
->devname
, devname
) == 0)
10777 if ((d
== NULL
) || (d
->index
< 0)) { /* serial mismatch probably */
10778 pr_err("%s doesn't appear to be part of a raid array\n",
10785 struct bbm_log_entry
*entry
= &log
->marked_block_entries
[0];
10787 for (i
= 0; i
< log
->entry_count
; i
++) {
10788 if (entry
[i
].disk_ordinal
== d
->index
) {
10789 unsigned long long sector
= __le48_to_cpu(
10790 &entry
[i
].defective_block_start
);
10791 int cnt
= entry
[i
].marked_count
+ 1;
10794 printf("Bad-blocks on %s:\n", devname
);
10798 printf("%20llu for %d sectors\n", sector
, cnt
);
10804 printf("No bad-blocks list configured on %s\n", devname
);
10808 /*******************************************************************************
10809 * Function: init_migr_record_imsm
10810 * Description: Function inits imsm migration record
10812 * super : imsm internal array info
10813 * dev : device under migration
10814 * info : general array info to find the smallest device
10817 ******************************************************************************/
10818 void init_migr_record_imsm(struct supertype
*st
, struct imsm_dev
*dev
,
10819 struct mdinfo
*info
)
10821 struct intel_super
*super
= st
->sb
;
10822 struct migr_record
*migr_rec
= super
->migr_rec
;
10823 int new_data_disks
;
10824 unsigned long long dsize
, dev_sectors
;
10825 long long unsigned min_dev_sectors
= -1LLU;
10826 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
10827 struct imsm_map
*map_src
= get_imsm_map(dev
, MAP_1
);
10828 unsigned long long num_migr_units
;
10829 unsigned long long array_blocks
;
10830 struct dl
*dl_disk
= NULL
;
10832 memset(migr_rec
, 0, sizeof(struct migr_record
));
10833 migr_rec
->family_num
= __cpu_to_le32(super
->anchor
->family_num
);
10835 /* only ascending reshape supported now */
10836 migr_rec
->ascending_migr
= __cpu_to_le32(1);
10838 migr_rec
->dest_depth_per_unit
= GEN_MIGR_AREA_SIZE
/
10839 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
10840 migr_rec
->dest_depth_per_unit
*=
10841 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
10842 new_data_disks
= imsm_num_data_members(map_dest
);
10843 migr_rec
->blocks_per_unit
=
10844 __cpu_to_le32(migr_rec
->dest_depth_per_unit
* new_data_disks
);
10845 migr_rec
->dest_depth_per_unit
=
10846 __cpu_to_le32(migr_rec
->dest_depth_per_unit
);
10847 array_blocks
= info
->component_size
* new_data_disks
;
10849 array_blocks
/ __le32_to_cpu(migr_rec
->blocks_per_unit
);
10851 if (array_blocks
% __le32_to_cpu(migr_rec
->blocks_per_unit
))
10853 set_num_migr_units(migr_rec
, num_migr_units
);
10855 migr_rec
->post_migr_vol_cap
= dev
->size_low
;
10856 migr_rec
->post_migr_vol_cap_hi
= dev
->size_high
;
10858 /* Find the smallest dev */
10859 for (dl_disk
= super
->disks
; dl_disk
; dl_disk
= dl_disk
->next
) {
10860 /* ignore spares in container */
10861 if (dl_disk
->index
< 0)
10863 get_dev_size(dl_disk
->fd
, NULL
, &dsize
);
10864 dev_sectors
= dsize
/ 512;
10865 if (dev_sectors
< min_dev_sectors
)
10866 min_dev_sectors
= dev_sectors
;
10868 set_migr_chkp_area_pba(migr_rec
, min_dev_sectors
-
10869 RAID_DISK_RESERVED_BLOCKS_IMSM_HI
);
10871 write_imsm_migr_rec(st
);
10876 /*******************************************************************************
10877 * Function: save_backup_imsm
10878 * Description: Function saves critical data stripes to Migration Copy Area
10879 * and updates the current migration unit status.
10880 * Use restore_stripes() to form a destination stripe,
10881 * and to write it to the Copy Area.
10883 * st : supertype information
10884 * dev : imsm device that backup is saved for
10885 * info : general array info
10886 * buf : input buffer
10887 * length : length of data to backup (blocks_per_unit)
10891 ******************************************************************************/
10892 int save_backup_imsm(struct supertype
*st
,
10893 struct imsm_dev
*dev
,
10894 struct mdinfo
*info
,
10899 struct intel_super
*super
= st
->sb
;
10900 unsigned long long *target_offsets
;
10903 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
10904 int new_disks
= map_dest
->num_members
;
10905 int dest_layout
= 0;
10907 unsigned long long start
;
10908 int data_disks
= imsm_num_data_members(map_dest
);
10910 targets
= xmalloc(new_disks
* sizeof(int));
10912 for (i
= 0; i
< new_disks
; i
++) {
10913 struct dl
*dl_disk
= get_imsm_dl_disk(super
, i
);
10915 targets
[i
] = dl_disk
->fd
;
10918 target_offsets
= xcalloc(new_disks
, sizeof(unsigned long long));
10920 start
= info
->reshape_progress
* 512;
10921 for (i
= 0; i
< new_disks
; i
++) {
10922 target_offsets
[i
] = migr_chkp_area_pba(super
->migr_rec
) * 512;
10923 /* move back copy area adderss, it will be moved forward
10924 * in restore_stripes() using start input variable
10926 target_offsets
[i
] -= start
/data_disks
;
10929 dest_layout
= imsm_level_to_layout(map_dest
->raid_level
);
10930 dest_chunk
= __le16_to_cpu(map_dest
->blocks_per_strip
) * 512;
10932 if (restore_stripes(targets
, /* list of dest devices */
10933 target_offsets
, /* migration record offsets */
10936 map_dest
->raid_level
,
10938 -1, /* source backup file descriptor */
10939 0, /* input buf offset
10940 * always 0 buf is already offseted */
10944 pr_err("Error restoring stripes\n");
10954 free(target_offsets
);
10959 /*******************************************************************************
10960 * Function: save_checkpoint_imsm
10961 * Description: Function called for current unit status update
10962 * in the migration record. It writes it to disk.
10964 * super : imsm internal array info
10965 * info : general array info
10969 * 2: failure, means no valid migration record
10970 * / no general migration in progress /
10971 ******************************************************************************/
10972 int save_checkpoint_imsm(struct supertype
*st
, struct mdinfo
*info
, int state
)
10974 struct intel_super
*super
= st
->sb
;
10975 unsigned long long blocks_per_unit
;
10976 unsigned long long curr_migr_unit
;
10978 if (load_imsm_migr_rec(super
) != 0) {
10979 dprintf("imsm: ERROR: Cannot read migration record for checkpoint save.\n");
10983 blocks_per_unit
= __le32_to_cpu(super
->migr_rec
->blocks_per_unit
);
10984 if (blocks_per_unit
== 0) {
10985 dprintf("imsm: no migration in progress.\n");
10988 curr_migr_unit
= info
->reshape_progress
/ blocks_per_unit
;
10989 /* check if array is alligned to copy area
10990 * if it is not alligned, add one to current migration unit value
10991 * this can happend on array reshape finish only
10993 if (info
->reshape_progress
% blocks_per_unit
)
10996 set_current_migr_unit(super
->migr_rec
, curr_migr_unit
);
10997 super
->migr_rec
->rec_status
= __cpu_to_le32(state
);
10998 set_migr_dest_1st_member_lba(super
->migr_rec
,
10999 super
->migr_rec
->dest_depth_per_unit
* curr_migr_unit
);
11001 if (write_imsm_migr_rec(st
) < 0) {
11002 dprintf("imsm: Cannot write migration record outside backup area\n");
11009 /*******************************************************************************
11010 * Function: recover_backup_imsm
11011 * Description: Function recovers critical data from the Migration Copy Area
11012 * while assembling an array.
11014 * super : imsm internal array info
11015 * info : general array info
11017 * 0 : success (or there is no data to recover)
11019 ******************************************************************************/
11020 int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
)
11022 struct intel_super
*super
= st
->sb
;
11023 struct migr_record
*migr_rec
= super
->migr_rec
;
11024 struct imsm_map
*map_dest
;
11025 struct intel_dev
*id
= NULL
;
11026 unsigned long long read_offset
;
11027 unsigned long long write_offset
;
11029 int new_disks
, err
;
11032 unsigned int sector_size
= super
->sector_size
;
11033 unsigned long long curr_migr_unit
= current_migr_unit(migr_rec
);
11034 unsigned long long num_migr_units
= get_num_migr_units(migr_rec
);
11036 int skipped_disks
= 0;
11037 struct dl
*dl_disk
;
11039 err
= sysfs_get_str(info
, NULL
, "array_state", (char *)buffer
, 20);
11043 /* recover data only during assemblation */
11044 if (strncmp(buffer
, "inactive", 8) != 0)
11046 /* no data to recover */
11047 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
11049 if (curr_migr_unit
>= num_migr_units
)
11052 /* find device during reshape */
11053 for (id
= super
->devlist
; id
; id
= id
->next
)
11054 if (is_gen_migration(id
->dev
))
11059 map_dest
= get_imsm_map(id
->dev
, MAP_0
);
11060 new_disks
= map_dest
->num_members
;
11062 read_offset
= migr_chkp_area_pba(migr_rec
) * 512;
11064 write_offset
= (migr_dest_1st_member_lba(migr_rec
) +
11065 pba_of_lba0(map_dest
)) * 512;
11067 unit_len
= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
11068 if (posix_memalign((void **)&buf
, sector_size
, unit_len
) != 0)
11071 for (dl_disk
= super
->disks
; dl_disk
; dl_disk
= dl_disk
->next
) {
11072 if (dl_disk
->index
< 0)
11075 if (dl_disk
->fd
< 0) {
11079 if (lseek64(dl_disk
->fd
, read_offset
, SEEK_SET
) < 0) {
11080 pr_err("Cannot seek to block: %s\n",
11085 if (read(dl_disk
->fd
, buf
, unit_len
) != (ssize_t
)unit_len
) {
11086 pr_err("Cannot read copy area block: %s\n",
11091 if (lseek64(dl_disk
->fd
, write_offset
, SEEK_SET
) < 0) {
11092 pr_err("Cannot seek to block: %s\n",
11097 if (write(dl_disk
->fd
, buf
, unit_len
) != (ssize_t
)unit_len
) {
11098 pr_err("Cannot restore block: %s\n",
11105 if (skipped_disks
> imsm_get_allowed_degradation(info
->new_level
,
11109 pr_err("Cannot restore data from backup. Too many failed disks\n");
11113 if (save_checkpoint_imsm(st
, info
, UNIT_SRC_NORMAL
)) {
11114 /* ignore error == 2, this can mean end of reshape here
11116 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL) during restart\n");
11125 static char disk_by_path
[] = "/dev/disk/by-path/";
11127 static const char *imsm_get_disk_controller_domain(const char *path
)
11129 char disk_path
[PATH_MAX
];
11133 strcpy(disk_path
, disk_by_path
);
11134 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
11135 if (stat(disk_path
, &st
) == 0) {
11136 struct sys_dev
* hba
;
11139 path
= devt_to_devpath(st
.st_rdev
, 1, NULL
);
11142 hba
= find_disk_attached_hba(-1, path
);
11143 if (hba
&& hba
->type
== SYS_DEV_SAS
)
11145 else if (hba
&& hba
->type
== SYS_DEV_SATA
)
11147 else if (hba
&& hba
->type
== SYS_DEV_VMD
)
11149 else if (hba
&& hba
->type
== SYS_DEV_NVME
)
11153 dprintf("path: %s hba: %s attached: %s\n",
11154 path
, (hba
) ? hba
->path
: "NULL", drv
);
11160 static char *imsm_find_array_devnm_by_subdev(int subdev
, char *container
)
11162 static char devnm
[32];
11163 char subdev_name
[20];
11164 struct mdstat_ent
*mdstat
;
11166 sprintf(subdev_name
, "%d", subdev
);
11167 mdstat
= mdstat_by_subdev(subdev_name
, container
);
11171 strcpy(devnm
, mdstat
->devnm
);
11172 free_mdstat(mdstat
);
11176 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
11177 struct geo_params
*geo
,
11178 int *old_raid_disks
,
11181 /* currently we only support increasing the number of devices
11182 * for a container. This increases the number of device for each
11183 * member array. They must all be RAID0 or RAID5.
11186 struct mdinfo
*info
, *member
;
11187 int devices_that_can_grow
= 0;
11189 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): st->devnm = (%s)\n", st
->devnm
);
11191 if (geo
->size
> 0 ||
11192 geo
->level
!= UnSet
||
11193 geo
->layout
!= UnSet
||
11194 geo
->chunksize
!= 0 ||
11195 geo
->raid_disks
== UnSet
) {
11196 dprintf("imsm: Container operation is allowed for raid disks number change only.\n");
11200 if (direction
== ROLLBACK_METADATA_CHANGES
) {
11201 dprintf("imsm: Metadata changes rollback is not supported for container operation.\n");
11205 info
= container_content_imsm(st
, NULL
);
11206 for (member
= info
; member
; member
= member
->next
) {
11209 dprintf("imsm: checking device_num: %i\n",
11210 member
->container_member
);
11212 if (geo
->raid_disks
<= member
->array
.raid_disks
) {
11213 /* we work on container for Online Capacity Expansion
11214 * only so raid_disks has to grow
11216 dprintf("imsm: for container operation raid disks increase is required\n");
11220 if (info
->array
.level
!= 0 && info
->array
.level
!= 5) {
11221 /* we cannot use this container with other raid level
11223 dprintf("imsm: for container operation wrong raid level (%i) detected\n",
11224 info
->array
.level
);
11227 /* check for platform support
11228 * for this raid level configuration
11230 struct intel_super
*super
= st
->sb
;
11231 if (!is_raid_level_supported(super
->orom
,
11232 member
->array
.level
,
11233 geo
->raid_disks
)) {
11234 dprintf("platform does not support raid%d with %d disk%s\n",
11237 geo
->raid_disks
> 1 ? "s" : "");
11240 /* check if component size is aligned to chunk size
11242 if (info
->component_size
%
11243 (info
->array
.chunk_size
/512)) {
11244 dprintf("Component size is not aligned to chunk size\n");
11249 if (*old_raid_disks
&&
11250 info
->array
.raid_disks
!= *old_raid_disks
)
11252 *old_raid_disks
= info
->array
.raid_disks
;
11254 /* All raid5 and raid0 volumes in container
11255 * have to be ready for Online Capacity Expansion
11256 * so they need to be assembled. We have already
11257 * checked that no recovery etc is happening.
11259 result
= imsm_find_array_devnm_by_subdev(member
->container_member
,
11260 st
->container_devnm
);
11261 if (result
== NULL
) {
11262 dprintf("imsm: cannot find array\n");
11265 devices_that_can_grow
++;
11268 if (!member
&& devices_that_can_grow
)
11272 dprintf("Container operation allowed\n");
11274 dprintf("Error: %i\n", ret_val
);
11279 /* Function: get_spares_for_grow
11280 * Description: Allocates memory and creates list of spare devices
11281 * avaliable in container. Checks if spare drive size is acceptable.
11282 * Parameters: Pointer to the supertype structure
11283 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
11286 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
11288 struct spare_criteria sc
;
11290 get_spare_criteria_imsm(st
, &sc
);
11291 return container_choose_spares(st
, &sc
, NULL
, NULL
, NULL
, 0);
11294 /******************************************************************************
11295 * function: imsm_create_metadata_update_for_reshape
11296 * Function creates update for whole IMSM container.
11298 ******************************************************************************/
11299 static int imsm_create_metadata_update_for_reshape(
11300 struct supertype
*st
,
11301 struct geo_params
*geo
,
11302 int old_raid_disks
,
11303 struct imsm_update_reshape
**updatep
)
11305 struct intel_super
*super
= st
->sb
;
11306 struct imsm_super
*mpb
= super
->anchor
;
11307 int update_memory_size
;
11308 struct imsm_update_reshape
*u
;
11309 struct mdinfo
*spares
;
11312 struct mdinfo
*dev
;
11314 dprintf("(enter) raid_disks = %i\n", geo
->raid_disks
);
11316 delta_disks
= geo
->raid_disks
- old_raid_disks
;
11318 /* size of all update data without anchor */
11319 update_memory_size
= sizeof(struct imsm_update_reshape
);
11321 /* now add space for spare disks that we need to add. */
11322 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
11324 u
= xcalloc(1, update_memory_size
);
11325 u
->type
= update_reshape_container_disks
;
11326 u
->old_raid_disks
= old_raid_disks
;
11327 u
->new_raid_disks
= geo
->raid_disks
;
11329 /* now get spare disks list
11331 spares
= get_spares_for_grow(st
);
11333 if (spares
== NULL
|| delta_disks
> spares
->array
.spare_disks
) {
11334 pr_err("imsm: ERROR: Cannot get spare devices for %s.\n", geo
->dev_name
);
11339 /* we have got spares
11340 * update disk list in imsm_disk list table in anchor
11342 dprintf("imsm: %i spares are available.\n\n",
11343 spares
->array
.spare_disks
);
11345 dev
= spares
->devs
;
11346 for (i
= 0; i
< delta_disks
; i
++) {
11351 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
11353 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
11354 dl
->index
= mpb
->num_disks
;
11362 sysfs_free(spares
);
11364 dprintf("imsm: reshape update preparation :");
11365 if (i
== delta_disks
) {
11366 dprintf_cont(" OK\n");
11368 return update_memory_size
;
11371 dprintf_cont(" Error\n");
11376 /******************************************************************************
11377 * function: imsm_create_metadata_update_for_size_change()
11378 * Creates update for IMSM array for array size change.
11380 ******************************************************************************/
11381 static int imsm_create_metadata_update_for_size_change(
11382 struct supertype
*st
,
11383 struct geo_params
*geo
,
11384 struct imsm_update_size_change
**updatep
)
11386 struct intel_super
*super
= st
->sb
;
11387 int update_memory_size
;
11388 struct imsm_update_size_change
*u
;
11390 dprintf("(enter) New size = %llu\n", geo
->size
);
11392 /* size of all update data without anchor */
11393 update_memory_size
= sizeof(struct imsm_update_size_change
);
11395 u
= xcalloc(1, update_memory_size
);
11396 u
->type
= update_size_change
;
11397 u
->subdev
= super
->current_vol
;
11398 u
->new_size
= geo
->size
;
11400 dprintf("imsm: reshape update preparation : OK\n");
11403 return update_memory_size
;
11406 /******************************************************************************
11407 * function: imsm_create_metadata_update_for_migration()
11408 * Creates update for IMSM array.
11410 ******************************************************************************/
11411 static int imsm_create_metadata_update_for_migration(
11412 struct supertype
*st
,
11413 struct geo_params
*geo
,
11414 struct imsm_update_reshape_migration
**updatep
)
11416 struct intel_super
*super
= st
->sb
;
11417 int update_memory_size
;
11418 struct imsm_update_reshape_migration
*u
;
11419 struct imsm_dev
*dev
;
11420 int previous_level
= -1;
11422 dprintf("(enter) New Level = %i\n", geo
->level
);
11424 /* size of all update data without anchor */
11425 update_memory_size
= sizeof(struct imsm_update_reshape_migration
);
11427 u
= xcalloc(1, update_memory_size
);
11428 u
->type
= update_reshape_migration
;
11429 u
->subdev
= super
->current_vol
;
11430 u
->new_level
= geo
->level
;
11431 u
->new_layout
= geo
->layout
;
11432 u
->new_raid_disks
= u
->old_raid_disks
= geo
->raid_disks
;
11433 u
->new_disks
[0] = -1;
11434 u
->new_chunksize
= -1;
11436 dev
= get_imsm_dev(super
, u
->subdev
);
11438 struct imsm_map
*map
;
11440 map
= get_imsm_map(dev
, MAP_0
);
11442 int current_chunk_size
=
11443 __le16_to_cpu(map
->blocks_per_strip
) / 2;
11445 if (geo
->chunksize
!= current_chunk_size
) {
11446 u
->new_chunksize
= geo
->chunksize
/ 1024;
11447 dprintf("imsm: chunk size change from %i to %i\n",
11448 current_chunk_size
, u
->new_chunksize
);
11450 previous_level
= map
->raid_level
;
11453 if (geo
->level
== 5 && previous_level
== 0) {
11454 struct mdinfo
*spares
= NULL
;
11456 u
->new_raid_disks
++;
11457 spares
= get_spares_for_grow(st
);
11458 if (spares
== NULL
|| spares
->array
.spare_disks
< 1) {
11460 sysfs_free(spares
);
11461 update_memory_size
= 0;
11462 pr_err("cannot get spare device for requested migration\n");
11465 sysfs_free(spares
);
11467 dprintf("imsm: reshape update preparation : OK\n");
11470 return update_memory_size
;
11473 static void imsm_update_metadata_locally(struct supertype
*st
,
11474 void *buf
, int len
)
11476 struct metadata_update mu
;
11481 mu
.space_list
= NULL
;
11483 if (imsm_prepare_update(st
, &mu
))
11484 imsm_process_update(st
, &mu
);
11486 while (mu
.space_list
) {
11487 void **space
= mu
.space_list
;
11488 mu
.space_list
= *space
;
11493 /***************************************************************************
11494 * Function: imsm_analyze_change
11495 * Description: Function analyze change for single volume
11496 * and validate if transition is supported
11497 * Parameters: Geometry parameters, supertype structure,
11498 * metadata change direction (apply/rollback)
11499 * Returns: Operation type code on success, -1 if fail
11500 ****************************************************************************/
11501 enum imsm_reshape_type
imsm_analyze_change(struct supertype
*st
,
11502 struct geo_params
*geo
,
11505 struct mdinfo info
;
11507 int check_devs
= 0;
11509 /* number of added/removed disks in operation result */
11510 int devNumChange
= 0;
11511 /* imsm compatible layout value for array geometry verification */
11512 int imsm_layout
= -1;
11514 struct imsm_dev
*dev
;
11515 struct imsm_map
*map
;
11516 struct intel_super
*super
;
11517 unsigned long long current_size
;
11518 unsigned long long free_size
;
11519 unsigned long long max_size
;
11522 getinfo_super_imsm_volume(st
, &info
, NULL
);
11523 if (geo
->level
!= info
.array
.level
&& geo
->level
>= 0 &&
11524 geo
->level
!= UnSet
) {
11525 switch (info
.array
.level
) {
11527 if (geo
->level
== 5) {
11528 change
= CH_MIGRATION
;
11529 if (geo
->layout
!= ALGORITHM_LEFT_ASYMMETRIC
) {
11530 pr_err("Error. Requested Layout not supported (left-asymmetric layout is supported only)!\n");
11532 goto analyse_change_exit
;
11534 imsm_layout
= geo
->layout
;
11536 devNumChange
= 1; /* parity disk added */
11537 } else if (geo
->level
== 10) {
11538 change
= CH_TAKEOVER
;
11540 devNumChange
= 2; /* two mirrors added */
11541 imsm_layout
= 0x102; /* imsm supported layout */
11546 if (geo
->level
== 0) {
11547 change
= CH_TAKEOVER
;
11549 devNumChange
= -(geo
->raid_disks
/2);
11550 imsm_layout
= 0; /* imsm raid0 layout */
11554 if (change
== -1) {
11555 pr_err("Error. Level Migration from %d to %d not supported!\n",
11556 info
.array
.level
, geo
->level
);
11557 goto analyse_change_exit
;
11560 geo
->level
= info
.array
.level
;
11562 if (geo
->layout
!= info
.array
.layout
&&
11563 (geo
->layout
!= UnSet
&& geo
->layout
!= -1)) {
11564 change
= CH_MIGRATION
;
11565 if (info
.array
.layout
== 0 && info
.array
.level
== 5 &&
11566 geo
->layout
== 5) {
11567 /* reshape 5 -> 4 */
11568 } else if (info
.array
.layout
== 5 && info
.array
.level
== 5 &&
11569 geo
->layout
== 0) {
11570 /* reshape 4 -> 5 */
11574 pr_err("Error. Layout Migration from %d to %d not supported!\n",
11575 info
.array
.layout
, geo
->layout
);
11577 goto analyse_change_exit
;
11580 geo
->layout
= info
.array
.layout
;
11581 if (imsm_layout
== -1)
11582 imsm_layout
= info
.array
.layout
;
11585 if (geo
->chunksize
> 0 && geo
->chunksize
!= UnSet
&&
11586 geo
->chunksize
!= info
.array
.chunk_size
) {
11587 if (info
.array
.level
== 10) {
11588 pr_err("Error. Chunk size change for RAID 10 is not supported.\n");
11590 goto analyse_change_exit
;
11591 } else if (info
.component_size
% (geo
->chunksize
/512)) {
11592 pr_err("New chunk size (%dK) does not evenly divide device size (%lluk). Aborting...\n",
11593 geo
->chunksize
/1024, info
.component_size
/2);
11595 goto analyse_change_exit
;
11597 change
= CH_MIGRATION
;
11599 geo
->chunksize
= info
.array
.chunk_size
;
11602 chunk
= geo
->chunksize
/ 1024;
11605 dev
= get_imsm_dev(super
, super
->current_vol
);
11606 map
= get_imsm_map(dev
, MAP_0
);
11607 data_disks
= imsm_num_data_members(map
);
11608 /* compute current size per disk member
11610 current_size
= info
.custom_array_size
/ data_disks
;
11612 if (geo
->size
> 0 && geo
->size
!= MAX_SIZE
) {
11613 /* align component size
11615 geo
->size
= imsm_component_size_alignment_check(
11616 get_imsm_raid_level(dev
->vol
.map
),
11617 chunk
* 1024, super
->sector_size
,
11619 if (geo
->size
== 0) {
11620 pr_err("Error. Size expansion is supported only (current size is %llu, requested size /rounded/ is 0).\n",
11622 goto analyse_change_exit
;
11626 if (current_size
!= geo
->size
&& geo
->size
> 0) {
11627 if (change
!= -1) {
11628 pr_err("Error. Size change should be the only one at a time.\n");
11630 goto analyse_change_exit
;
11632 if ((super
->current_vol
+ 1) != super
->anchor
->num_raid_devs
) {
11633 pr_err("Error. The last volume in container can be expanded only (%i/%s).\n",
11634 super
->current_vol
, st
->devnm
);
11635 goto analyse_change_exit
;
11637 /* check the maximum available size
11639 rv
= imsm_get_free_size(st
, dev
->vol
.map
->num_members
,
11640 0, chunk
, &free_size
);
11642 /* Cannot find maximum available space
11646 max_size
= free_size
+ current_size
;
11647 /* align component size
11649 max_size
= imsm_component_size_alignment_check(
11650 get_imsm_raid_level(dev
->vol
.map
),
11651 chunk
* 1024, super
->sector_size
,
11654 if (geo
->size
== MAX_SIZE
) {
11655 /* requested size change to the maximum available size
11657 if (max_size
== 0) {
11658 pr_err("Error. Cannot find maximum available space.\n");
11660 goto analyse_change_exit
;
11662 geo
->size
= max_size
;
11665 if (direction
== ROLLBACK_METADATA_CHANGES
) {
11666 /* accept size for rollback only
11669 /* round size due to metadata compatibility
11671 geo
->size
= (geo
->size
>> SECT_PER_MB_SHIFT
)
11672 << SECT_PER_MB_SHIFT
;
11673 dprintf("Prepare update for size change to %llu\n",
11675 if (current_size
>= geo
->size
) {
11676 pr_err("Error. Size expansion is supported only (current size is %llu, requested size /rounded/ is %llu).\n",
11677 current_size
, geo
->size
);
11678 goto analyse_change_exit
;
11680 if (max_size
&& geo
->size
> max_size
) {
11681 pr_err("Error. Requested size is larger than maximum available size (maximum available size is %llu, requested size /rounded/ is %llu).\n",
11682 max_size
, geo
->size
);
11683 goto analyse_change_exit
;
11686 geo
->size
*= data_disks
;
11687 geo
->raid_disks
= dev
->vol
.map
->num_members
;
11688 change
= CH_ARRAY_SIZE
;
11690 if (!validate_geometry_imsm(st
,
11693 geo
->raid_disks
+ devNumChange
,
11695 geo
->size
, INVALID_SECTORS
,
11696 0, 0, info
.consistency_policy
, 1))
11700 struct intel_super
*super
= st
->sb
;
11701 struct imsm_super
*mpb
= super
->anchor
;
11703 if (mpb
->num_raid_devs
> 1) {
11704 pr_err("Error. Cannot perform operation on %s- for this operation it MUST be single array in container\n",
11710 analyse_change_exit
:
11711 if (direction
== ROLLBACK_METADATA_CHANGES
&&
11712 (change
== CH_MIGRATION
|| change
== CH_TAKEOVER
)) {
11713 dprintf("imsm: Metadata changes rollback is not supported for migration and takeover operations.\n");
11719 int imsm_takeover(struct supertype
*st
, struct geo_params
*geo
)
11721 struct intel_super
*super
= st
->sb
;
11722 struct imsm_update_takeover
*u
;
11724 u
= xmalloc(sizeof(struct imsm_update_takeover
));
11726 u
->type
= update_takeover
;
11727 u
->subarray
= super
->current_vol
;
11729 /* 10->0 transition */
11730 if (geo
->level
== 0)
11731 u
->direction
= R10_TO_R0
;
11733 /* 0->10 transition */
11734 if (geo
->level
== 10)
11735 u
->direction
= R0_TO_R10
;
11737 /* update metadata locally */
11738 imsm_update_metadata_locally(st
, u
,
11739 sizeof(struct imsm_update_takeover
));
11740 /* and possibly remotely */
11741 if (st
->update_tail
)
11742 append_metadata_update(st
, u
,
11743 sizeof(struct imsm_update_takeover
));
11750 /* Flush size update if size calculated by num_data_stripes is higher than
11751 * imsm_dev_size to eliminate differences during reshape.
11752 * Mdmon will recalculate them correctly.
11753 * If subarray index is not set then check whole container.
11755 * 0 - no error occurred
11756 * 1 - error detected
11758 static int imsm_fix_size_mismatch(struct supertype
*st
, int subarray_index
)
11760 struct intel_super
*super
= st
->sb
;
11761 int tmp
= super
->current_vol
;
11765 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
11766 if (subarray_index
>= 0 && i
!= subarray_index
)
11768 super
->current_vol
= i
;
11769 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
11770 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
11771 unsigned int disc_count
= imsm_num_data_members(map
);
11772 struct geo_params geo
;
11773 struct imsm_update_size_change
*update
;
11774 unsigned long long calc_size
= per_dev_array_size(map
) * disc_count
;
11775 unsigned long long d_size
= imsm_dev_size(dev
);
11778 if (calc_size
== d_size
|| dev
->vol
.migr_type
== MIGR_GEN_MIGR
)
11781 /* There is a difference, confirm that imsm_dev_size is
11782 * smaller and push update.
11784 if (d_size
> calc_size
) {
11785 pr_err("imsm: dev size of subarray %d is incorrect\n",
11789 memset(&geo
, 0, sizeof(struct geo_params
));
11791 u_size
= imsm_create_metadata_update_for_size_change(st
, &geo
,
11794 dprintf("imsm: Cannot prepare size change update\n");
11797 imsm_update_metadata_locally(st
, update
, u_size
);
11798 if (st
->update_tail
) {
11799 append_metadata_update(st
, update
, u_size
);
11800 flush_metadata_updates(st
);
11801 st
->update_tail
= &st
->updates
;
11803 imsm_sync_metadata(st
);
11808 super
->current_vol
= tmp
;
11812 static int imsm_reshape_super(struct supertype
*st
, unsigned long long size
,
11814 int layout
, int chunksize
, int raid_disks
,
11815 int delta_disks
, char *backup
, char *dev
,
11816 int direction
, int verbose
)
11819 struct geo_params geo
;
11821 dprintf("(enter)\n");
11823 memset(&geo
, 0, sizeof(struct geo_params
));
11825 geo
.dev_name
= dev
;
11826 strcpy(geo
.devnm
, st
->devnm
);
11829 geo
.layout
= layout
;
11830 geo
.chunksize
= chunksize
;
11831 geo
.raid_disks
= raid_disks
;
11832 if (delta_disks
!= UnSet
)
11833 geo
.raid_disks
+= delta_disks
;
11835 dprintf("for level : %i\n", geo
.level
);
11836 dprintf("for raid_disks : %i\n", geo
.raid_disks
);
11838 if (strcmp(st
->container_devnm
, st
->devnm
) == 0) {
11839 /* On container level we can only increase number of devices. */
11840 dprintf("imsm: info: Container operation\n");
11841 int old_raid_disks
= 0;
11843 if (imsm_reshape_is_allowed_on_container(
11844 st
, &geo
, &old_raid_disks
, direction
)) {
11845 struct imsm_update_reshape
*u
= NULL
;
11848 if (imsm_fix_size_mismatch(st
, -1)) {
11849 dprintf("imsm: Cannot fix size mismatch\n");
11850 goto exit_imsm_reshape_super
;
11853 len
= imsm_create_metadata_update_for_reshape(
11854 st
, &geo
, old_raid_disks
, &u
);
11857 dprintf("imsm: Cannot prepare update\n");
11858 goto exit_imsm_reshape_super
;
11862 /* update metadata locally */
11863 imsm_update_metadata_locally(st
, u
, len
);
11864 /* and possibly remotely */
11865 if (st
->update_tail
)
11866 append_metadata_update(st
, u
, len
);
11871 pr_err("(imsm) Operation is not allowed on this container\n");
11874 /* On volume level we support following operations
11875 * - takeover: raid10 -> raid0; raid0 -> raid10
11876 * - chunk size migration
11877 * - migration: raid5 -> raid0; raid0 -> raid5
11879 struct intel_super
*super
= st
->sb
;
11880 struct intel_dev
*dev
= super
->devlist
;
11882 dprintf("imsm: info: Volume operation\n");
11883 /* find requested device */
11886 imsm_find_array_devnm_by_subdev(
11887 dev
->index
, st
->container_devnm
);
11888 if (devnm
&& strcmp(devnm
, geo
.devnm
) == 0)
11893 pr_err("Cannot find %s (%s) subarray\n",
11894 geo
.dev_name
, geo
.devnm
);
11895 goto exit_imsm_reshape_super
;
11897 super
->current_vol
= dev
->index
;
11898 change
= imsm_analyze_change(st
, &geo
, direction
);
11901 ret_val
= imsm_takeover(st
, &geo
);
11903 case CH_MIGRATION
: {
11904 struct imsm_update_reshape_migration
*u
= NULL
;
11906 imsm_create_metadata_update_for_migration(
11909 dprintf("imsm: Cannot prepare update\n");
11913 /* update metadata locally */
11914 imsm_update_metadata_locally(st
, u
, len
);
11915 /* and possibly remotely */
11916 if (st
->update_tail
)
11917 append_metadata_update(st
, u
, len
);
11922 case CH_ARRAY_SIZE
: {
11923 struct imsm_update_size_change
*u
= NULL
;
11925 imsm_create_metadata_update_for_size_change(
11928 dprintf("imsm: Cannot prepare update\n");
11932 /* update metadata locally */
11933 imsm_update_metadata_locally(st
, u
, len
);
11934 /* and possibly remotely */
11935 if (st
->update_tail
)
11936 append_metadata_update(st
, u
, len
);
11946 exit_imsm_reshape_super
:
11947 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
11951 #define COMPLETED_OK 0
11952 #define COMPLETED_NONE 1
11953 #define COMPLETED_DELAYED 2
11955 static int read_completed(int fd
, unsigned long long *val
)
11960 ret
= sysfs_fd_get_str(fd
, buf
, 50);
11964 ret
= COMPLETED_OK
;
11965 if (strncmp(buf
, "none", 4) == 0) {
11966 ret
= COMPLETED_NONE
;
11967 } else if (strncmp(buf
, "delayed", 7) == 0) {
11968 ret
= COMPLETED_DELAYED
;
11971 *val
= strtoull(buf
, &ep
, 0);
11972 if (ep
== buf
|| (*ep
!= 0 && *ep
!= '\n' && *ep
!= ' '))
11978 /*******************************************************************************
11979 * Function: wait_for_reshape_imsm
11980 * Description: Function writes new sync_max value and waits until
11981 * reshape process reach new position
11983 * sra : general array info
11984 * ndata : number of disks in new array's layout
11987 * 1 : there is no reshape in progress,
11989 ******************************************************************************/
11990 int wait_for_reshape_imsm(struct mdinfo
*sra
, int ndata
)
11992 int fd
= sysfs_get_fd(sra
, NULL
, "sync_completed");
11994 unsigned long long completed
;
11995 /* to_complete : new sync_max position */
11996 unsigned long long to_complete
= sra
->reshape_progress
;
11997 unsigned long long position_to_set
= to_complete
/ ndata
;
12000 dprintf("cannot open reshape_position\n");
12005 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
12007 dprintf("cannot read reshape_position (no reshape in progres)\n");
12016 if (completed
> position_to_set
) {
12017 dprintf("wrong next position to set %llu (%llu)\n",
12018 to_complete
, position_to_set
);
12022 dprintf("Position set: %llu\n", position_to_set
);
12023 if (sysfs_set_num(sra
, NULL
, "sync_max",
12024 position_to_set
) != 0) {
12025 dprintf("cannot set reshape position to %llu\n",
12034 int timeout
= 3000;
12036 sysfs_wait(fd
, &timeout
);
12037 if (sysfs_get_str(sra
, NULL
, "sync_action",
12039 strncmp(action
, "reshape", 7) != 0) {
12040 if (strncmp(action
, "idle", 4) == 0)
12046 rc
= read_completed(fd
, &completed
);
12048 dprintf("cannot read reshape_position (in loop)\n");
12051 } else if (rc
== COMPLETED_NONE
)
12053 } while (completed
< position_to_set
);
12059 /*******************************************************************************
12060 * Function: check_degradation_change
12061 * Description: Check that array hasn't become failed.
12063 * info : for sysfs access
12064 * sources : source disks descriptors
12065 * degraded: previous degradation level
12067 * degradation level
12068 ******************************************************************************/
12069 int check_degradation_change(struct mdinfo
*info
,
12073 unsigned long long new_degraded
;
12076 rv
= sysfs_get_ll(info
, NULL
, "degraded", &new_degraded
);
12077 if (rv
== -1 || (new_degraded
!= (unsigned long long)degraded
)) {
12078 /* check each device to ensure it is still working */
12081 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
12082 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
12084 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
12087 if (sysfs_get_str(info
,
12088 sd
, "state", sbuf
, sizeof(sbuf
)) < 0 ||
12089 strstr(sbuf
, "faulty") ||
12090 strstr(sbuf
, "in_sync") == NULL
) {
12091 /* this device is dead */
12092 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
12093 if (sd
->disk
.raid_disk
>= 0 &&
12094 sources
[sd
->disk
.raid_disk
] >= 0) {
12096 sd
->disk
.raid_disk
]);
12097 sources
[sd
->disk
.raid_disk
] =
12106 return new_degraded
;
12109 /*******************************************************************************
12110 * Function: imsm_manage_reshape
12111 * Description: Function finds array under reshape and it manages reshape
12112 * process. It creates stripes backups (if required) and sets
12115 * afd : Backup handle (nattive) - not used
12116 * sra : general array info
12117 * reshape : reshape parameters - not used
12118 * st : supertype structure
12119 * blocks : size of critical section [blocks]
12120 * fds : table of source device descriptor
12121 * offsets : start of array (offest per devices)
12123 * destfd : table of destination device descriptor
12124 * destoffsets : table of destination offsets (per device)
12126 * 1 : success, reshape is done
12128 ******************************************************************************/
12129 static int imsm_manage_reshape(
12130 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
12131 struct supertype
*st
, unsigned long backup_blocks
,
12132 int *fds
, unsigned long long *offsets
,
12133 int dests
, int *destfd
, unsigned long long *destoffsets
)
12136 struct intel_super
*super
= st
->sb
;
12137 struct intel_dev
*dv
;
12138 unsigned int sector_size
= super
->sector_size
;
12139 struct imsm_dev
*dev
= NULL
;
12140 struct imsm_map
*map_src
, *map_dest
;
12141 int migr_vol_qan
= 0;
12142 int ndata
, odata
; /* [bytes] */
12143 int chunk
; /* [bytes] */
12144 struct migr_record
*migr_rec
;
12146 unsigned int buf_size
; /* [bytes] */
12147 unsigned long long max_position
; /* array size [bytes] */
12148 unsigned long long next_step
; /* [blocks]/[bytes] */
12149 unsigned long long old_data_stripe_length
;
12150 unsigned long long start_src
; /* [bytes] */
12151 unsigned long long start
; /* [bytes] */
12152 unsigned long long start_buf_shift
; /* [bytes] */
12154 int source_layout
= 0;
12155 int subarray_index
= -1;
12160 if (!fds
|| !offsets
)
12163 /* Find volume during the reshape */
12164 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
12165 if (dv
->dev
->vol
.migr_type
== MIGR_GEN_MIGR
&&
12166 dv
->dev
->vol
.migr_state
== 1) {
12169 subarray_index
= dv
->index
;
12172 /* Only one volume can migrate at the same time */
12173 if (migr_vol_qan
!= 1) {
12174 pr_err("%s", migr_vol_qan
?
12175 "Number of migrating volumes greater than 1\n" :
12176 "There is no volume during migrationg\n");
12180 map_dest
= get_imsm_map(dev
, MAP_0
);
12181 map_src
= get_imsm_map(dev
, MAP_1
);
12182 if (map_src
== NULL
)
12185 ndata
= imsm_num_data_members(map_dest
);
12186 odata
= imsm_num_data_members(map_src
);
12188 chunk
= __le16_to_cpu(map_src
->blocks_per_strip
) * 512;
12189 old_data_stripe_length
= odata
* chunk
;
12191 migr_rec
= super
->migr_rec
;
12193 /* initialize migration record for start condition */
12194 if (sra
->reshape_progress
== 0)
12195 init_migr_record_imsm(st
, dev
, sra
);
12197 if (__le32_to_cpu(migr_rec
->rec_status
) != UNIT_SRC_NORMAL
) {
12198 dprintf("imsm: cannot restart migration when data are present in copy area.\n");
12201 /* Save checkpoint to update migration record for current
12202 * reshape position (in md). It can be farther than current
12203 * reshape position in metadata.
12205 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
12206 /* ignore error == 2, this can mean end of reshape here
12208 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL, initial save)\n");
12213 /* size for data */
12214 buf_size
= __le32_to_cpu(migr_rec
->blocks_per_unit
) * 512;
12215 /* extend buffer size for parity disk */
12216 buf_size
+= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
12217 /* add space for stripe alignment */
12218 buf_size
+= old_data_stripe_length
;
12219 if (posix_memalign((void **)&buf
, MAX_SECTOR_SIZE
, buf_size
)) {
12220 dprintf("imsm: Cannot allocate checkpoint buffer\n");
12224 max_position
= sra
->component_size
* ndata
;
12225 source_layout
= imsm_level_to_layout(map_src
->raid_level
);
12227 while (current_migr_unit(migr_rec
) <
12228 get_num_migr_units(migr_rec
)) {
12229 /* current reshape position [blocks] */
12230 unsigned long long current_position
=
12231 __le32_to_cpu(migr_rec
->blocks_per_unit
)
12232 * current_migr_unit(migr_rec
);
12233 unsigned long long border
;
12235 /* Check that array hasn't become failed.
12237 degraded
= check_degradation_change(sra
, fds
, degraded
);
12238 if (degraded
> 1) {
12239 dprintf("imsm: Abort reshape due to degradation level (%i)\n", degraded
);
12243 next_step
= __le32_to_cpu(migr_rec
->blocks_per_unit
);
12245 if ((current_position
+ next_step
) > max_position
)
12246 next_step
= max_position
- current_position
;
12248 start
= current_position
* 512;
12250 /* align reading start to old geometry */
12251 start_buf_shift
= start
% old_data_stripe_length
;
12252 start_src
= start
- start_buf_shift
;
12254 border
= (start_src
/ odata
) - (start
/ ndata
);
12256 if (border
<= __le32_to_cpu(migr_rec
->dest_depth_per_unit
)) {
12257 /* save critical stripes to buf
12258 * start - start address of current unit
12259 * to backup [bytes]
12260 * start_src - start address of current unit
12261 * to backup alligned to source array
12264 unsigned long long next_step_filler
;
12265 unsigned long long copy_length
= next_step
* 512;
12267 /* allign copy area length to stripe in old geometry */
12268 next_step_filler
= ((copy_length
+ start_buf_shift
)
12269 % old_data_stripe_length
);
12270 if (next_step_filler
)
12271 next_step_filler
= (old_data_stripe_length
12272 - next_step_filler
);
12273 dprintf("save_stripes() parameters: start = %llu,\tstart_src = %llu,\tnext_step*512 = %llu,\tstart_in_buf_shift = %llu,\tnext_step_filler = %llu\n",
12274 start
, start_src
, copy_length
,
12275 start_buf_shift
, next_step_filler
);
12277 if (save_stripes(fds
, offsets
, map_src
->num_members
,
12278 chunk
, map_src
->raid_level
,
12279 source_layout
, 0, NULL
, start_src
,
12281 next_step_filler
+ start_buf_shift
,
12283 dprintf("imsm: Cannot save stripes to buffer\n");
12286 /* Convert data to destination format and store it
12287 * in backup general migration area
12289 if (save_backup_imsm(st
, dev
, sra
,
12290 buf
+ start_buf_shift
, copy_length
)) {
12291 dprintf("imsm: Cannot save stripes to target devices\n");
12294 if (save_checkpoint_imsm(st
, sra
,
12295 UNIT_SRC_IN_CP_AREA
)) {
12296 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_IN_CP_AREA)\n");
12300 /* set next step to use whole border area */
12301 border
/= next_step
;
12303 next_step
*= border
;
12305 /* When data backed up, checkpoint stored,
12306 * kick the kernel to reshape unit of data
12308 next_step
= next_step
+ sra
->reshape_progress
;
12309 /* limit next step to array max position */
12310 if (next_step
> max_position
)
12311 next_step
= max_position
;
12312 sysfs_set_num(sra
, NULL
, "suspend_lo", sra
->reshape_progress
);
12313 sysfs_set_num(sra
, NULL
, "suspend_hi", next_step
);
12314 sra
->reshape_progress
= next_step
;
12316 /* wait until reshape finish */
12317 if (wait_for_reshape_imsm(sra
, ndata
)) {
12318 dprintf("wait_for_reshape_imsm returned error!\n");
12324 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
12325 /* ignore error == 2, this can mean end of reshape here
12327 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL)\n");
12333 /* clear migr_rec on disks after successful migration */
12336 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
);
12337 for (d
= super
->disks
; d
; d
= d
->next
) {
12338 if (d
->index
< 0 || is_failed(&d
->disk
))
12340 unsigned long long dsize
;
12342 get_dev_size(d
->fd
, NULL
, &dsize
);
12343 if (lseek64(d
->fd
, dsize
- MIGR_REC_SECTOR_POSITION
*sector_size
,
12345 if ((unsigned int)write(d
->fd
, super
->migr_rec_buf
,
12346 MIGR_REC_BUF_SECTORS
*sector_size
) !=
12347 MIGR_REC_BUF_SECTORS
*sector_size
)
12348 perror("Write migr_rec failed");
12352 /* return '1' if done */
12355 /* After the reshape eliminate size mismatch in metadata.
12356 * Don't update md/component_size here, volume hasn't
12357 * to take whole space. It is allowed by kernel.
12358 * md/component_size will be set propoperly after next assembly.
12360 imsm_fix_size_mismatch(st
, subarray_index
);
12364 /* See Grow.c: abort_reshape() for further explanation */
12365 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
12366 sysfs_set_num(sra
, NULL
, "suspend_hi", 0);
12367 sysfs_set_num(sra
, NULL
, "suspend_lo", 0);
12372 /*******************************************************************************
12373 * Function: calculate_bitmap_min_chunksize
12374 * Description: Calculates the minimal valid bitmap chunk size
12376 * max_bits : indicate how many bits can be used for the bitmap
12377 * data_area_size : the size of the data area covered by the bitmap
12380 * The bitmap chunk size
12381 ******************************************************************************/
12382 static unsigned long long
12383 calculate_bitmap_min_chunksize(unsigned long long max_bits
,
12384 unsigned long long data_area_size
)
12386 unsigned long long min_chunk
=
12387 4096; /* sub-page chunks don't work yet.. */
12388 unsigned long long bits
= data_area_size
/ min_chunk
+ 1;
12390 while (bits
> max_bits
) {
12392 bits
= (bits
+ 1) / 2;
12397 /*******************************************************************************
12398 * Function: calculate_bitmap_chunksize
12399 * Description: Calculates the bitmap chunk size for the given device
12401 * st : supertype information
12402 * dev : device for the bitmap
12405 * The bitmap chunk size
12406 ******************************************************************************/
12407 static unsigned long long calculate_bitmap_chunksize(struct supertype
*st
,
12408 struct imsm_dev
*dev
)
12410 struct intel_super
*super
= st
->sb
;
12411 unsigned long long min_chunksize
;
12412 unsigned long long result
= IMSM_DEFAULT_BITMAP_CHUNKSIZE
;
12413 size_t dev_size
= imsm_dev_size(dev
);
12415 min_chunksize
= calculate_bitmap_min_chunksize(
12416 IMSM_BITMAP_AREA_SIZE
* super
->sector_size
, dev_size
);
12418 if (result
< min_chunksize
)
12419 result
= min_chunksize
;
12424 /*******************************************************************************
12425 * Function: init_bitmap_header
12426 * Description: Initialize the bitmap header structure
12428 * st : supertype information
12429 * bms : bitmap header struct to initialize
12430 * dev : device for the bitmap
12435 ******************************************************************************/
12436 static int init_bitmap_header(struct supertype
*st
, struct bitmap_super_s
*bms
,
12437 struct imsm_dev
*dev
)
12444 bms
->magic
= __cpu_to_le32(BITMAP_MAGIC
);
12445 bms
->version
= __cpu_to_le32(BITMAP_MAJOR_HI
);
12446 bms
->daemon_sleep
= __cpu_to_le32(IMSM_DEFAULT_BITMAP_DAEMON_SLEEP
);
12447 bms
->sync_size
= __cpu_to_le64(IMSM_BITMAP_AREA_SIZE
);
12448 bms
->write_behind
= __cpu_to_le32(0);
12450 uuid_from_super_imsm(st
, vol_uuid
);
12451 memcpy(bms
->uuid
, vol_uuid
, 16);
12453 bms
->chunksize
= calculate_bitmap_chunksize(st
, dev
);
12458 /*******************************************************************************
12459 * Function: validate_internal_bitmap_for_drive
12460 * Description: Verify if the bitmap header for a given drive.
12462 * st : supertype information
12463 * offset : The offset from the beginning of the drive where to look for
12464 * the bitmap header.
12465 * d : the drive info
12470 ******************************************************************************/
12471 static int validate_internal_bitmap_for_drive(struct supertype
*st
,
12472 unsigned long long offset
,
12475 struct intel_super
*super
= st
->sb
;
12478 bitmap_super_t
*bms
;
12486 if (posix_memalign(&read_buf
, MAX_SECTOR_SIZE
, IMSM_BITMAP_HEADER_SIZE
))
12491 fd
= open(d
->devname
, O_RDONLY
, 0);
12493 dprintf("cannot open the device %s\n", d
->devname
);
12498 if (lseek64(fd
, offset
* super
->sector_size
, SEEK_SET
) < 0)
12500 if (read(fd
, read_buf
, IMSM_BITMAP_HEADER_SIZE
) !=
12501 IMSM_BITMAP_HEADER_SIZE
)
12504 uuid_from_super_imsm(st
, vol_uuid
);
12507 if ((bms
->magic
!= __cpu_to_le32(BITMAP_MAGIC
)) ||
12508 (bms
->version
!= __cpu_to_le32(BITMAP_MAJOR_HI
)) ||
12509 (!same_uuid((int *)bms
->uuid
, vol_uuid
, st
->ss
->swapuuid
))) {
12510 dprintf("wrong bitmap header detected\n");
12516 if ((d
->fd
< 0) && (fd
>= 0))
12524 /*******************************************************************************
12525 * Function: validate_internal_bitmap_imsm
12526 * Description: Verify if the bitmap header is in place and with proper data.
12528 * st : supertype information
12531 * 0 : success or device w/o RWH_BITMAP
12533 ******************************************************************************/
12534 static int validate_internal_bitmap_imsm(struct supertype
*st
)
12536 struct intel_super
*super
= st
->sb
;
12537 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
12538 unsigned long long offset
;
12544 if (dev
->rwh_policy
!= RWH_BITMAP
)
12547 offset
= get_bitmap_header_sector(super
, super
->current_vol
);
12548 for (d
= super
->disks
; d
; d
= d
->next
) {
12549 if (d
->index
< 0 || is_failed(&d
->disk
))
12552 if (validate_internal_bitmap_for_drive(st
, offset
, d
)) {
12553 pr_err("imsm: bitmap validation failed\n");
12560 /*******************************************************************************
12561 * Function: add_internal_bitmap_imsm
12562 * Description: Mark the volume to use the bitmap and updates the chunk size value.
12564 * st : supertype information
12565 * chunkp : bitmap chunk size
12566 * delay : not used for imsm
12567 * write_behind : not used for imsm
12568 * size : not used for imsm
12569 * may_change : not used for imsm
12570 * amajor : not used for imsm
12575 ******************************************************************************/
12576 static int add_internal_bitmap_imsm(struct supertype
*st
, int *chunkp
,
12577 int delay
, int write_behind
,
12578 unsigned long long size
, int may_change
,
12581 struct intel_super
*super
= st
->sb
;
12582 int vol_idx
= super
->current_vol
;
12583 struct imsm_dev
*dev
;
12585 if (!super
->devlist
|| vol_idx
== -1 || !chunkp
)
12588 dev
= get_imsm_dev(super
, vol_idx
);
12591 dprintf("cannot find the device for volume index %d\n",
12595 dev
->rwh_policy
= RWH_BITMAP
;
12597 *chunkp
= calculate_bitmap_chunksize(st
, dev
);
12602 /*******************************************************************************
12603 * Function: locate_bitmap_imsm
12604 * Description: Seek 'fd' to start of write-intent-bitmap.
12606 * st : supertype information
12607 * fd : file descriptor for the device
12608 * node_num : not used for imsm
12613 ******************************************************************************/
12614 static int locate_bitmap_imsm(struct supertype
*st
, int fd
, int node_num
)
12616 struct intel_super
*super
= st
->sb
;
12617 unsigned long long offset
;
12618 int vol_idx
= super
->current_vol
;
12620 if (!super
->devlist
|| vol_idx
== -1)
12623 offset
= get_bitmap_header_sector(super
, super
->current_vol
);
12624 dprintf("bitmap header offset is %llu\n", offset
);
12626 lseek64(fd
, offset
<< 9, 0);
12631 /*******************************************************************************
12632 * Function: write_init_bitmap_imsm
12633 * Description: Write a bitmap header and prepares the area for the bitmap.
12635 * st : supertype information
12636 * fd : file descriptor for the device
12637 * update : not used for imsm
12642 ******************************************************************************/
12643 static int write_init_bitmap_imsm(struct supertype
*st
, int fd
,
12644 enum bitmap_update update
)
12646 struct intel_super
*super
= st
->sb
;
12647 int vol_idx
= super
->current_vol
;
12649 unsigned long long offset
;
12650 bitmap_super_t bms
= { 0 };
12651 size_t written
= 0;
12656 if (!super
->devlist
|| !super
->sector_size
|| vol_idx
== -1)
12659 struct imsm_dev
*dev
= get_imsm_dev(super
, vol_idx
);
12661 /* first clear the space for bitmap header */
12662 unsigned long long bitmap_area_start
=
12663 get_bitmap_header_sector(super
, vol_idx
);
12665 dprintf("zeroing area start (%llu) and size (%u)\n", bitmap_area_start
,
12666 IMSM_BITMAP_AND_HEADER_SIZE
/ super
->sector_size
);
12667 if (zero_disk_range(fd
, bitmap_area_start
,
12668 IMSM_BITMAP_HEADER_SIZE
/ super
->sector_size
)) {
12669 pr_err("imsm: cannot zeroing the space for the bitmap\n");
12673 /* The bitmap area should be filled with "1"s to perform initial
12676 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, MAX_SECTOR_SIZE
))
12678 memset(buf
, 0xFF, MAX_SECTOR_SIZE
);
12679 offset
= get_bitmap_sector(super
, vol_idx
);
12680 lseek64(fd
, offset
<< 9, 0);
12681 while (written
< IMSM_BITMAP_AREA_SIZE
) {
12682 to_write
= IMSM_BITMAP_AREA_SIZE
- written
;
12683 if (to_write
> MAX_SECTOR_SIZE
)
12684 to_write
= MAX_SECTOR_SIZE
;
12685 rv_num
= write(fd
, buf
, MAX_SECTOR_SIZE
);
12686 if (rv_num
!= MAX_SECTOR_SIZE
) {
12688 dprintf("cannot initialize bitmap area\n");
12694 /* write a bitmap header */
12695 init_bitmap_header(st
, &bms
, dev
);
12696 memset(buf
, 0, MAX_SECTOR_SIZE
);
12697 memcpy(buf
, &bms
, sizeof(bitmap_super_t
));
12698 if (locate_bitmap_imsm(st
, fd
, 0)) {
12700 dprintf("cannot locate the bitmap\n");
12703 if (write(fd
, buf
, MAX_SECTOR_SIZE
) != MAX_SECTOR_SIZE
) {
12705 dprintf("cannot write the bitmap header\n");
12716 /*******************************************************************************
12717 * Function: is_vol_to_setup_bitmap
12718 * Description: Checks if a bitmap should be activated on the dev.
12720 * info : info about the volume to setup the bitmap
12721 * dev : the device to check against bitmap creation
12724 * 0 : bitmap should be set up on the device
12726 ******************************************************************************/
12727 static int is_vol_to_setup_bitmap(struct mdinfo
*info
, struct imsm_dev
*dev
)
12732 if ((strcmp((char *)dev
->volume
, info
->name
) == 0) &&
12733 (dev
->rwh_policy
== RWH_BITMAP
))
12739 /*******************************************************************************
12740 * Function: set_bitmap_sysfs
12741 * Description: Set the sysfs atributes of a given volume to activate the bitmap.
12743 * info : info about the volume where the bitmap should be setup
12744 * chunksize : bitmap chunk size
12745 * location : location of the bitmap
12750 ******************************************************************************/
12751 static int set_bitmap_sysfs(struct mdinfo
*info
, unsigned long long chunksize
,
12754 /* The bitmap/metadata is set to external to allow changing of value for
12755 * bitmap/location. When external is used, the kernel will treat an offset
12756 * related to the device's first lba (in opposition to the "internal" case
12757 * when this value is related to the beginning of the superblock).
12759 if (sysfs_set_str(info
, NULL
, "bitmap/metadata", "external")) {
12760 dprintf("failed to set bitmap/metadata\n");
12764 /* It can only be changed when no bitmap is active.
12765 * Should be bigger than 512 and must be power of 2.
12766 * It is expecting the value in bytes.
12768 if (sysfs_set_num(info
, NULL
, "bitmap/chunksize",
12769 __cpu_to_le32(chunksize
))) {
12770 dprintf("failed to set bitmap/chunksize\n");
12774 /* It is expecting the value in sectors. */
12775 if (sysfs_set_num(info
, NULL
, "bitmap/space",
12776 __cpu_to_le64(IMSM_BITMAP_AREA_SIZE
))) {
12777 dprintf("failed to set bitmap/space\n");
12781 /* Determines the delay between the bitmap updates.
12782 * It is expecting the value in seconds.
12784 if (sysfs_set_num(info
, NULL
, "bitmap/time_base",
12785 __cpu_to_le64(IMSM_DEFAULT_BITMAP_DAEMON_SLEEP
))) {
12786 dprintf("failed to set bitmap/time_base\n");
12790 /* It is expecting the value in sectors with a sign at the beginning. */
12791 if (sysfs_set_str(info
, NULL
, "bitmap/location", location
)) {
12792 dprintf("failed to set bitmap/location\n");
12799 /*******************************************************************************
12800 * Function: set_bitmap_imsm
12801 * Description: Setup the bitmap for the given volume
12803 * st : supertype information
12804 * info : info about the volume where the bitmap should be setup
12809 ******************************************************************************/
12810 static int set_bitmap_imsm(struct supertype
*st
, struct mdinfo
*info
)
12812 struct intel_super
*super
= st
->sb
;
12813 int prev_current_vol
= super
->current_vol
;
12814 struct imsm_dev
*dev
;
12816 char location
[16] = "";
12817 unsigned long long chunksize
;
12818 struct intel_dev
*dev_it
;
12820 for (dev_it
= super
->devlist
; dev_it
; dev_it
= dev_it
->next
) {
12821 super
->current_vol
= dev_it
->index
;
12822 dev
= get_imsm_dev(super
, super
->current_vol
);
12824 if (is_vol_to_setup_bitmap(info
, dev
)) {
12825 if (validate_internal_bitmap_imsm(st
)) {
12826 dprintf("bitmap header validation failed\n");
12830 chunksize
= calculate_bitmap_chunksize(st
, dev
);
12831 dprintf("chunk size is %llu\n", chunksize
);
12833 snprintf(location
, sizeof(location
), "+%llu",
12834 get_bitmap_sector(super
, super
->current_vol
));
12835 dprintf("bitmap offset is %s\n", location
);
12837 if (set_bitmap_sysfs(info
, chunksize
, location
)) {
12838 dprintf("cannot setup the bitmap\n");
12845 super
->current_vol
= prev_current_vol
;
12849 struct superswitch super_imsm
= {
12850 .examine_super
= examine_super_imsm
,
12851 .brief_examine_super
= brief_examine_super_imsm
,
12852 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
12853 .export_examine_super
= export_examine_super_imsm
,
12854 .detail_super
= detail_super_imsm
,
12855 .brief_detail_super
= brief_detail_super_imsm
,
12856 .write_init_super
= write_init_super_imsm
,
12857 .validate_geometry
= validate_geometry_imsm
,
12858 .add_to_super
= add_to_super_imsm
,
12859 .remove_from_super
= remove_from_super_imsm
,
12860 .detail_platform
= detail_platform_imsm
,
12861 .export_detail_platform
= export_detail_platform_imsm
,
12862 .kill_subarray
= kill_subarray_imsm
,
12863 .update_subarray
= update_subarray_imsm
,
12864 .load_container
= load_container_imsm
,
12865 .default_geometry
= default_geometry_imsm
,
12866 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
12867 .reshape_super
= imsm_reshape_super
,
12868 .manage_reshape
= imsm_manage_reshape
,
12869 .recover_backup
= recover_backup_imsm
,
12870 .examine_badblocks
= examine_badblocks_imsm
,
12871 .match_home
= match_home_imsm
,
12872 .uuid_from_super
= uuid_from_super_imsm
,
12873 .getinfo_super
= getinfo_super_imsm
,
12874 .getinfo_super_disks
= getinfo_super_disks_imsm
,
12875 .update_super
= update_super_imsm
,
12877 .avail_size
= avail_size_imsm
,
12878 .get_spare_criteria
= get_spare_criteria_imsm
,
12880 .compare_super
= compare_super_imsm
,
12882 .load_super
= load_super_imsm
,
12883 .init_super
= init_super_imsm
,
12884 .store_super
= store_super_imsm
,
12885 .free_super
= free_super_imsm
,
12886 .match_metadata_desc
= match_metadata_desc_imsm
,
12887 .container_content
= container_content_imsm
,
12888 .validate_container
= validate_container_imsm
,
12890 .add_internal_bitmap
= add_internal_bitmap_imsm
,
12891 .locate_bitmap
= locate_bitmap_imsm
,
12892 .write_bitmap
= write_init_bitmap_imsm
,
12893 .set_bitmap
= set_bitmap_imsm
,
12895 .write_init_ppl
= write_init_ppl_imsm
,
12896 .validate_ppl
= validate_ppl_imsm
,
12902 .open_new
= imsm_open_new
,
12903 .set_array_state
= imsm_set_array_state
,
12904 .set_disk
= imsm_set_disk
,
12905 .sync_metadata
= imsm_sync_metadata
,
12906 .activate_spare
= imsm_activate_spare
,
12907 .process_update
= imsm_process_update
,
12908 .prepare_update
= imsm_prepare_update
,
12909 .record_bad_block
= imsm_record_badblock
,
12910 .clear_bad_block
= imsm_clear_badblock
,
12911 .get_bad_blocks
= imsm_get_badblocks
,