2 * mdadm - Intel(R) Matrix Storage Manager Support
4 * Copyright (C) 2002-2008 Intel Corporation
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20 #define HAVE_STDINT_H 1
24 #include "platform-intel.h"
30 /* MPB == Metadata Parameter Block */
31 #define MPB_SIGNATURE "Intel Raid ISM Cfg Sig. "
32 #define MPB_SIG_LEN (strlen(MPB_SIGNATURE))
33 #define MPB_VERSION_RAID0 "1.0.00"
34 #define MPB_VERSION_RAID1 "1.1.00"
35 #define MPB_VERSION_MANY_VOLUMES_PER_ARRAY "1.2.00"
36 #define MPB_VERSION_3OR4_DISK_ARRAY "1.2.01"
37 #define MPB_VERSION_RAID5 "1.2.02"
38 #define MPB_VERSION_5OR6_DISK_ARRAY "1.2.04"
39 #define MPB_VERSION_CNG "1.2.06"
40 #define MPB_VERSION_ATTRIBS "1.3.00"
41 #define MAX_SIGNATURE_LENGTH 32
42 #define MAX_RAID_SERIAL_LEN 16
45 #define MPB_ATTRIB_RAID0 __cpu_to_le32(0x00000001)
47 #define MPB_ATTRIB_RAID1 __cpu_to_le32(0x00000002)
49 #define MPB_ATTRIB_RAID10 __cpu_to_le32(0x00000004)
51 #define MPB_ATTRIB_RAID1E __cpu_to_le32(0x00000008)
53 #define MPB_ATTRIB_RAID5 __cpu_to_le32(0x00000010)
54 /* supports RAID CNG */
55 #define MPB_ATTRIB_RAIDCNG __cpu_to_le32(0x00000020)
56 /* supports expanded stripe sizes of 256K, 512K and 1MB */
57 #define MPB_ATTRIB_EXP_STRIPE_SIZE __cpu_to_le32(0x00000040)
59 /* The OROM Support RST Caching of Volumes */
60 #define MPB_ATTRIB_NVM __cpu_to_le32(0x02000000)
61 /* The OROM supports creating disks greater than 2TB */
62 #define MPB_ATTRIB_2TB_DISK __cpu_to_le32(0x04000000)
63 /* The OROM supports Bad Block Management */
64 #define MPB_ATTRIB_BBM __cpu_to_le32(0x08000000)
66 /* THe OROM Supports NVM Caching of Volumes */
67 #define MPB_ATTRIB_NEVER_USE2 __cpu_to_le32(0x10000000)
68 /* The OROM supports creating volumes greater than 2TB */
69 #define MPB_ATTRIB_2TB __cpu_to_le32(0x20000000)
70 /* originally for PMP, now it's wasted b/c. Never use this bit! */
71 #define MPB_ATTRIB_NEVER_USE __cpu_to_le32(0x40000000)
72 /* Verify MPB contents against checksum after reading MPB */
73 #define MPB_ATTRIB_CHECKSUM_VERIFY __cpu_to_le32(0x80000000)
75 /* Define all supported attributes that have to be accepted by mdadm
77 #define MPB_ATTRIB_SUPPORTED (MPB_ATTRIB_CHECKSUM_VERIFY | \
79 MPB_ATTRIB_2TB_DISK | \
84 MPB_ATTRIB_EXP_STRIPE_SIZE | \
87 /* Define attributes that are unused but not harmful */
88 #define MPB_ATTRIB_IGNORED (MPB_ATTRIB_NEVER_USE)
90 #define MPB_SECTOR_CNT 2210
91 #define IMSM_RESERVED_SECTORS 4096
92 #define NUM_BLOCKS_DIRTY_STRIPE_REGION 2056
93 #define SECT_PER_MB_SHIFT 11
94 #define MAX_SECTOR_SIZE 4096
96 /* Disk configuration info. */
97 #define IMSM_MAX_DEVICES 255
99 __u8 serial
[MAX_RAID_SERIAL_LEN
];/* 0xD8 - 0xE7 ascii serial number */
100 __u32 total_blocks_lo
; /* 0xE8 - 0xEB total blocks lo */
101 __u32 scsi_id
; /* 0xEC - 0xEF scsi ID */
102 #define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
103 #define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
104 #define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
105 __u32 status
; /* 0xF0 - 0xF3 */
106 __u32 owner_cfg_num
; /* which config 0,1,2... owns this disk */
107 __u32 total_blocks_hi
; /* 0xF4 - 0xF5 total blocks hi */
108 #define IMSM_DISK_FILLERS 3
109 __u32 filler
[IMSM_DISK_FILLERS
]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
112 /* map selector for map managment
118 /* RAID map configuration infos. */
120 __u32 pba_of_lba0_lo
; /* start address of partition */
121 __u32 blocks_per_member_lo
;/* blocks per member */
122 __u32 num_data_stripes_lo
; /* number of data stripes */
123 __u16 blocks_per_strip
;
124 __u8 map_state
; /* Normal, Uninitialized, Degraded, Failed */
125 #define IMSM_T_STATE_NORMAL 0
126 #define IMSM_T_STATE_UNINITIALIZED 1
127 #define IMSM_T_STATE_DEGRADED 2
128 #define IMSM_T_STATE_FAILED 3
130 #define IMSM_T_RAID0 0
131 #define IMSM_T_RAID1 1
132 #define IMSM_T_RAID5 5 /* since metadata version 1.2.02 ? */
133 __u8 num_members
; /* number of member disks */
134 __u8 num_domains
; /* number of parity domains */
135 __u8 failed_disk_num
; /* valid only when state is degraded */
137 __u32 pba_of_lba0_hi
;
138 __u32 blocks_per_member_hi
;
139 __u32 num_data_stripes_hi
;
140 __u32 filler
[4]; /* expansion area */
141 #define IMSM_ORD_REBUILD (1 << 24)
142 __u32 disk_ord_tbl
[1]; /* disk_ord_tbl[num_members],
143 * top byte contains some flags
145 } __attribute__ ((packed
));
148 __u32 curr_migr_unit
;
149 __u32 checkpoint_id
; /* id to access curr_migr_unit */
150 __u8 migr_state
; /* Normal or Migrating */
152 #define MIGR_REBUILD 1
153 #define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
154 #define MIGR_GEN_MIGR 3
155 #define MIGR_STATE_CHANGE 4
156 #define MIGR_REPAIR 5
157 __u8 migr_type
; /* Initializing, Rebuilding, ... */
159 __u8 fs_state
; /* fast-sync state for CnG (0xff == disabled) */
160 __u16 verify_errors
; /* number of mismatches */
161 __u16 bad_blocks
; /* number of bad blocks during verify */
163 struct imsm_map map
[1];
164 /* here comes another one if migr_state */
165 } __attribute__ ((packed
));
168 __u8 volume
[MAX_RAID_SERIAL_LEN
];
171 #define DEV_BOOTABLE __cpu_to_le32(0x01)
172 #define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
173 #define DEV_READ_COALESCING __cpu_to_le32(0x04)
174 #define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
175 #define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
176 #define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
177 #define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
178 #define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
179 #define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
180 #define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
181 #define DEV_CLONE_N_GO __cpu_to_le32(0x400)
182 #define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
183 #define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
184 __u32 status
; /* Persistent RaidDev status */
185 __u32 reserved_blocks
; /* Reserved blocks at beginning of volume */
189 __u8 cng_master_disk
;
193 #define IMSM_DEV_FILLERS 10
194 __u32 filler
[IMSM_DEV_FILLERS
];
196 } __attribute__ ((packed
));
199 __u8 sig
[MAX_SIGNATURE_LENGTH
]; /* 0x00 - 0x1F */
200 __u32 check_sum
; /* 0x20 - 0x23 MPB Checksum */
201 __u32 mpb_size
; /* 0x24 - 0x27 Size of MPB */
202 __u32 family_num
; /* 0x28 - 0x2B Checksum from first time this config was written */
203 __u32 generation_num
; /* 0x2C - 0x2F Incremented each time this array's MPB is written */
204 __u32 error_log_size
; /* 0x30 - 0x33 in bytes */
205 __u32 attributes
; /* 0x34 - 0x37 */
206 __u8 num_disks
; /* 0x38 Number of configured disks */
207 __u8 num_raid_devs
; /* 0x39 Number of configured volumes */
208 __u8 error_log_pos
; /* 0x3A */
209 __u8 fill
[1]; /* 0x3B */
210 __u32 cache_size
; /* 0x3c - 0x40 in mb */
211 __u32 orig_family_num
; /* 0x40 - 0x43 original family num */
212 __u32 pwr_cycle_count
; /* 0x44 - 0x47 simulated power cycle count for array */
213 __u32 bbm_log_size
; /* 0x48 - 0x4B - size of bad Block Mgmt Log in bytes */
214 #define IMSM_FILLERS 35
215 __u32 filler
[IMSM_FILLERS
]; /* 0x4C - 0xD7 RAID_MPB_FILLERS */
216 struct imsm_disk disk
[1]; /* 0xD8 diskTbl[numDisks] */
217 /* here comes imsm_dev[num_raid_devs] */
218 /* here comes BBM logs */
219 } __attribute__ ((packed
));
221 #define BBM_LOG_MAX_ENTRIES 254
222 #define BBM_LOG_MAX_LBA_ENTRY_VAL 256 /* Represents 256 LBAs */
223 #define BBM_LOG_SIGNATURE 0xabadb10c
225 struct bbm_log_block_addr
{
228 } __attribute__ ((__packed__
));
230 struct bbm_log_entry
{
231 __u8 marked_count
; /* Number of blocks marked - 1 */
232 __u8 disk_ordinal
; /* Disk entry within the imsm_super */
233 struct bbm_log_block_addr defective_block_start
;
234 } __attribute__ ((__packed__
));
237 __u32 signature
; /* 0xABADB10C */
239 struct bbm_log_entry marked_block_entries
[BBM_LOG_MAX_ENTRIES
];
240 } __attribute__ ((__packed__
));
243 static char *map_state_str
[] = { "normal", "uninitialized", "degraded", "failed" };
246 #define RAID_DISK_RESERVED_BLOCKS_IMSM_HI 2209
248 #define GEN_MIGR_AREA_SIZE 2048 /* General Migration Copy Area size in blocks */
250 #define MIGR_REC_BUF_SECTORS 1 /* size of migr_record i/o buffer in sectors */
251 #define MIGR_REC_SECTOR_POSITION 1 /* migr_record position offset on disk,
252 * MIGR_REC_BUF_SECTORS <= MIGR_REC_SECTOR_POS
255 #define UNIT_SRC_NORMAL 0 /* Source data for curr_migr_unit must
256 * be recovered using srcMap */
257 #define UNIT_SRC_IN_CP_AREA 1 /* Source data for curr_migr_unit has
258 * already been migrated and must
259 * be recovered from checkpoint area */
261 __u32 rec_status
; /* Status used to determine how to restart
262 * migration in case it aborts
264 __u32 curr_migr_unit
; /* 0..numMigrUnits-1 */
265 __u32 family_num
; /* Family number of MPB
266 * containing the RaidDev
267 * that is migrating */
268 __u32 ascending_migr
; /* True if migrating in increasing
270 __u32 blocks_per_unit
; /* Num disk blocks per unit of operation */
271 __u32 dest_depth_per_unit
; /* Num member blocks each destMap
273 * advances per unit-of-operation */
274 __u32 ckpt_area_pba
; /* Pba of first block of ckpt copy area */
275 __u32 dest_1st_member_lba
; /* First member lba on first
276 * stripe of destination */
277 __u32 num_migr_units
; /* Total num migration units-of-op */
278 __u32 post_migr_vol_cap
; /* Size of volume after
279 * migration completes */
280 __u32 post_migr_vol_cap_hi
; /* Expansion space for LBA64 */
281 __u32 ckpt_read_disk_num
; /* Which member disk in destSubMap[0] the
282 * migration ckpt record was read from
283 * (for recovered migrations) */
284 } __attribute__ ((__packed__
));
289 * 2: metadata does not match
297 struct md_list
*next
;
300 #define pr_vrb(fmt, arg...) (void) (verbose && pr_err(fmt, ##arg))
302 static __u8
migr_type(struct imsm_dev
*dev
)
304 if (dev
->vol
.migr_type
== MIGR_VERIFY
&&
305 dev
->status
& DEV_VERIFY_AND_FIX
)
308 return dev
->vol
.migr_type
;
311 static void set_migr_type(struct imsm_dev
*dev
, __u8 migr_type
)
313 /* for compatibility with older oroms convert MIGR_REPAIR, into
314 * MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status
316 if (migr_type
== MIGR_REPAIR
) {
317 dev
->vol
.migr_type
= MIGR_VERIFY
;
318 dev
->status
|= DEV_VERIFY_AND_FIX
;
320 dev
->vol
.migr_type
= migr_type
;
321 dev
->status
&= ~DEV_VERIFY_AND_FIX
;
325 static unsigned int sector_count(__u32 bytes
, unsigned int sector_size
)
327 return ROUND_UP(bytes
, sector_size
) / sector_size
;
330 static unsigned int mpb_sectors(struct imsm_super
*mpb
,
331 unsigned int sector_size
)
333 return sector_count(__le32_to_cpu(mpb
->mpb_size
), sector_size
);
337 struct imsm_dev
*dev
;
338 struct intel_dev
*next
;
343 enum sys_dev_type type
;
346 struct intel_hba
*next
;
353 /* internal representation of IMSM metadata */
356 void *buf
; /* O_DIRECT buffer for reading/writing metadata */
357 struct imsm_super
*anchor
; /* immovable parameters */
360 void *migr_rec_buf
; /* buffer for I/O operations */
361 struct migr_record
*migr_rec
; /* migration record */
363 int clean_migration_record_by_mdmon
; /* when reshape is switched to next
364 array, it indicates that mdmon is allowed to clean migration
366 size_t len
; /* size of the 'buf' allocation */
367 size_t extra_space
; /* extra space in 'buf' that is not used yet */
368 void *next_buf
; /* for realloc'ing buf from the manager */
370 int updates_pending
; /* count of pending updates for mdmon */
371 int current_vol
; /* index of raid device undergoing creation */
372 unsigned long long create_offset
; /* common start for 'current_vol' */
373 __u32 random
; /* random data for seeding new family numbers */
374 struct intel_dev
*devlist
;
375 unsigned int sector_size
; /* sector size of used member drives */
379 __u8 serial
[MAX_RAID_SERIAL_LEN
];
382 struct imsm_disk disk
;
385 struct extent
*e
; /* for determining freespace @ create */
386 int raiddisk
; /* slot to fill in autolayout */
388 } *disks
, *current_disk
;
389 struct dl
*disk_mgmt_list
; /* list of disks to add/remove while mdmon
391 struct dl
*missing
; /* disks removed while we weren't looking */
392 struct bbm_log
*bbm_log
;
393 struct intel_hba
*hba
; /* device path of the raid controller for this metadata */
394 const struct imsm_orom
*orom
; /* platform firmware support */
395 struct intel_super
*next
; /* (temp) list for disambiguating family_num */
399 struct imsm_disk disk
;
400 #define IMSM_UNKNOWN_OWNER (-1)
402 struct intel_disk
*next
;
406 unsigned long long start
, size
;
409 /* definitions of reshape process types */
410 enum imsm_reshape_type
{
416 /* definition of messages passed to imsm_process_update */
417 enum imsm_update_type
{
418 update_activate_spare
,
422 update_add_remove_disk
,
423 update_reshape_container_disks
,
424 update_reshape_migration
,
426 update_general_migration_checkpoint
,
428 update_prealloc_badblocks_mem
,
431 struct imsm_update_activate_spare
{
432 enum imsm_update_type type
;
436 struct imsm_update_activate_spare
*next
;
442 unsigned long long size
;
449 enum takeover_direction
{
453 struct imsm_update_takeover
{
454 enum imsm_update_type type
;
456 enum takeover_direction direction
;
459 struct imsm_update_reshape
{
460 enum imsm_update_type type
;
464 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
467 struct imsm_update_reshape_migration
{
468 enum imsm_update_type type
;
471 /* fields for array migration changes
478 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
481 struct imsm_update_size_change
{
482 enum imsm_update_type type
;
487 struct imsm_update_general_migration_checkpoint
{
488 enum imsm_update_type type
;
489 __u32 curr_migr_unit
;
493 __u8 serial
[MAX_RAID_SERIAL_LEN
];
496 struct imsm_update_create_array
{
497 enum imsm_update_type type
;
502 struct imsm_update_kill_array
{
503 enum imsm_update_type type
;
507 struct imsm_update_rename_array
{
508 enum imsm_update_type type
;
509 __u8 name
[MAX_RAID_SERIAL_LEN
];
513 struct imsm_update_add_remove_disk
{
514 enum imsm_update_type type
;
517 struct imsm_update_prealloc_bb_mem
{
518 enum imsm_update_type type
;
521 static const char *_sys_dev_type
[] = {
522 [SYS_DEV_UNKNOWN
] = "Unknown",
523 [SYS_DEV_SAS
] = "SAS",
524 [SYS_DEV_SATA
] = "SATA",
525 [SYS_DEV_NVME
] = "NVMe",
526 [SYS_DEV_VMD
] = "VMD"
529 const char *get_sys_dev_type(enum sys_dev_type type
)
531 if (type
>= SYS_DEV_MAX
)
532 type
= SYS_DEV_UNKNOWN
;
534 return _sys_dev_type
[type
];
537 static struct intel_hba
* alloc_intel_hba(struct sys_dev
*device
)
539 struct intel_hba
*result
= xmalloc(sizeof(*result
));
541 result
->type
= device
->type
;
542 result
->path
= xstrdup(device
->path
);
544 if (result
->path
&& (result
->pci_id
= strrchr(result
->path
, '/')) != NULL
)
550 static struct intel_hba
* find_intel_hba(struct intel_hba
*hba
, struct sys_dev
*device
)
552 struct intel_hba
*result
;
554 for (result
= hba
; result
; result
= result
->next
) {
555 if (result
->type
== device
->type
&& strcmp(result
->path
, device
->path
) == 0)
561 static int attach_hba_to_super(struct intel_super
*super
, struct sys_dev
*device
)
563 struct intel_hba
*hba
;
565 /* check if disk attached to Intel HBA */
566 hba
= find_intel_hba(super
->hba
, device
);
569 /* Check if HBA is already attached to super */
570 if (super
->hba
== NULL
) {
571 super
->hba
= alloc_intel_hba(device
);
576 /* Intel metadata allows for all disks attached to the same type HBA.
577 * Do not support HBA types mixing
579 if (device
->type
!= hba
->type
)
582 /* Multiple same type HBAs can be used if they share the same OROM */
583 const struct imsm_orom
*device_orom
= get_orom_by_device_id(device
->dev_id
);
585 if (device_orom
!= super
->orom
)
591 hba
->next
= alloc_intel_hba(device
);
595 static struct sys_dev
* find_disk_attached_hba(int fd
, const char *devname
)
597 struct sys_dev
*list
, *elem
;
600 if ((list
= find_intel_devices()) == NULL
)
604 disk_path
= (char *) devname
;
606 disk_path
= diskfd_to_devpath(fd
);
611 for (elem
= list
; elem
; elem
= elem
->next
)
612 if (path_attached_to_hba(disk_path
, elem
->path
))
615 if (disk_path
!= devname
)
621 static int find_intel_hba_capability(int fd
, struct intel_super
*super
,
624 static struct supertype
*match_metadata_desc_imsm(char *arg
)
626 struct supertype
*st
;
628 if (strcmp(arg
, "imsm") != 0 &&
629 strcmp(arg
, "default") != 0
633 st
= xcalloc(1, sizeof(*st
));
634 st
->ss
= &super_imsm
;
635 st
->max_devs
= IMSM_MAX_DEVICES
;
636 st
->minor_version
= 0;
642 static __u8
*get_imsm_version(struct imsm_super
*mpb
)
644 return &mpb
->sig
[MPB_SIG_LEN
];
648 /* retrieve a disk directly from the anchor when the anchor is known to be
649 * up-to-date, currently only at load time
651 static struct imsm_disk
*__get_imsm_disk(struct imsm_super
*mpb
, __u8 index
)
653 if (index
>= mpb
->num_disks
)
655 return &mpb
->disk
[index
];
658 /* retrieve the disk description based on a index of the disk
661 static struct dl
*get_imsm_dl_disk(struct intel_super
*super
, __u8 index
)
665 for (d
= super
->disks
; d
; d
= d
->next
)
666 if (d
->index
== index
)
671 /* retrieve a disk from the parsed metadata */
672 static struct imsm_disk
*get_imsm_disk(struct intel_super
*super
, __u8 index
)
676 dl
= get_imsm_dl_disk(super
, index
);
683 /* generate a checksum directly from the anchor when the anchor is known to be
684 * up-to-date, currently only at load or write_super after coalescing
686 static __u32
__gen_imsm_checksum(struct imsm_super
*mpb
)
688 __u32 end
= mpb
->mpb_size
/ sizeof(end
);
689 __u32
*p
= (__u32
*) mpb
;
693 sum
+= __le32_to_cpu(*p
);
697 return sum
- __le32_to_cpu(mpb
->check_sum
);
700 static size_t sizeof_imsm_map(struct imsm_map
*map
)
702 return sizeof(struct imsm_map
) + sizeof(__u32
) * (map
->num_members
- 1);
705 struct imsm_map
*get_imsm_map(struct imsm_dev
*dev
, int second_map
)
707 /* A device can have 2 maps if it is in the middle of a migration.
709 * MAP_0 - we return the first map
710 * MAP_1 - we return the second map if it exists, else NULL
711 * MAP_X - we return the second map if it exists, else the first
713 struct imsm_map
*map
= &dev
->vol
.map
[0];
714 struct imsm_map
*map2
= NULL
;
716 if (dev
->vol
.migr_state
)
717 map2
= (void *)map
+ sizeof_imsm_map(map
);
719 switch (second_map
) {
736 /* return the size of the device.
737 * migr_state increases the returned size if map[0] were to be duplicated
739 static size_t sizeof_imsm_dev(struct imsm_dev
*dev
, int migr_state
)
741 size_t size
= sizeof(*dev
) - sizeof(struct imsm_map
) +
742 sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
744 /* migrating means an additional map */
745 if (dev
->vol
.migr_state
)
746 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_1
));
748 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
754 /* retrieve disk serial number list from a metadata update */
755 static struct disk_info
*get_disk_info(struct imsm_update_create_array
*update
)
758 struct disk_info
*inf
;
760 inf
= u
+ sizeof(*update
) - sizeof(struct imsm_dev
) +
761 sizeof_imsm_dev(&update
->dev
, 0);
767 static struct imsm_dev
*__get_imsm_dev(struct imsm_super
*mpb
, __u8 index
)
773 if (index
>= mpb
->num_raid_devs
)
776 /* devices start after all disks */
777 offset
= ((void *) &mpb
->disk
[mpb
->num_disks
]) - _mpb
;
779 for (i
= 0; i
<= index
; i
++)
781 return _mpb
+ offset
;
783 offset
+= sizeof_imsm_dev(_mpb
+ offset
, 0);
788 static struct imsm_dev
*get_imsm_dev(struct intel_super
*super
, __u8 index
)
790 struct intel_dev
*dv
;
792 if (index
>= super
->anchor
->num_raid_devs
)
794 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
795 if (dv
->index
== index
)
800 static inline unsigned long long __le48_to_cpu(const struct bbm_log_block_addr
803 return ((((__u64
)__le32_to_cpu(addr
->dw1
)) << 16) |
804 __le16_to_cpu(addr
->w1
));
807 static inline struct bbm_log_block_addr
__cpu_to_le48(unsigned long long sec
)
809 struct bbm_log_block_addr addr
;
811 addr
.w1
= __cpu_to_le16((__u16
)(sec
& 0xffff));
812 addr
.dw1
= __cpu_to_le32((__u32
)(sec
>> 16) & 0xffffffff);
817 /* get size of the bbm log */
818 static __u32
get_imsm_bbm_log_size(struct bbm_log
*log
)
820 if (!log
|| log
->entry_count
== 0)
823 return sizeof(log
->signature
) +
824 sizeof(log
->entry_count
) +
825 log
->entry_count
* sizeof(struct bbm_log_entry
);
828 /* check if bad block is not partially stored in bbm log */
829 static int is_stored_in_bbm(struct bbm_log
*log
, const __u8 idx
, const unsigned
830 long long sector
, const int length
, __u32
*pos
)
834 for (i
= *pos
; i
< log
->entry_count
; i
++) {
835 struct bbm_log_entry
*entry
= &log
->marked_block_entries
[i
];
836 unsigned long long bb_start
;
837 unsigned long long bb_end
;
839 bb_start
= __le48_to_cpu(&entry
->defective_block_start
);
840 bb_end
= bb_start
+ (entry
->marked_count
+ 1);
842 if ((entry
->disk_ordinal
== idx
) && (bb_start
>= sector
) &&
843 (bb_end
<= sector
+ length
)) {
851 /* record new bad block in bbm log */
852 static int record_new_badblock(struct bbm_log
*log
, const __u8 idx
, unsigned
853 long long sector
, int length
)
857 struct bbm_log_entry
*entry
= NULL
;
859 while (is_stored_in_bbm(log
, idx
, sector
, length
, &pos
)) {
860 struct bbm_log_entry
*e
= &log
->marked_block_entries
[pos
];
862 if ((e
->marked_count
+ 1 == BBM_LOG_MAX_LBA_ENTRY_VAL
) &&
863 (__le48_to_cpu(&e
->defective_block_start
) == sector
)) {
864 sector
+= BBM_LOG_MAX_LBA_ENTRY_VAL
;
865 length
-= BBM_LOG_MAX_LBA_ENTRY_VAL
;
874 int cnt
= (length
<= BBM_LOG_MAX_LBA_ENTRY_VAL
) ? length
:
875 BBM_LOG_MAX_LBA_ENTRY_VAL
;
876 entry
->defective_block_start
= __cpu_to_le48(sector
);
877 entry
->marked_count
= cnt
- 1;
884 new_bb
= ROUND_UP(length
, BBM_LOG_MAX_LBA_ENTRY_VAL
) /
885 BBM_LOG_MAX_LBA_ENTRY_VAL
;
886 if (log
->entry_count
+ new_bb
> BBM_LOG_MAX_ENTRIES
)
890 int cnt
= (length
<= BBM_LOG_MAX_LBA_ENTRY_VAL
) ? length
:
891 BBM_LOG_MAX_LBA_ENTRY_VAL
;
892 struct bbm_log_entry
*entry
=
893 &log
->marked_block_entries
[log
->entry_count
];
895 entry
->defective_block_start
= __cpu_to_le48(sector
);
896 entry
->marked_count
= cnt
- 1;
897 entry
->disk_ordinal
= idx
;
908 /* clear given bad block */
909 static int clear_badblock(struct bbm_log
*log
, const __u8 idx
, const unsigned
910 long long sector
, const int length
) {
913 while (i
< log
->entry_count
) {
914 struct bbm_log_entry
*entries
= log
->marked_block_entries
;
916 if ((entries
[i
].disk_ordinal
== idx
) &&
917 (__le48_to_cpu(&entries
[i
].defective_block_start
) ==
918 sector
) && (entries
[i
].marked_count
+ 1 == length
)) {
919 if (i
< log
->entry_count
- 1)
920 entries
[i
] = entries
[log
->entry_count
- 1];
929 #endif /* MDASSEMBLE */
931 /* allocate and load BBM log from metadata */
932 static int load_bbm_log(struct intel_super
*super
)
934 struct imsm_super
*mpb
= super
->anchor
;
935 __u32 bbm_log_size
= __le32_to_cpu(mpb
->bbm_log_size
);
937 super
->bbm_log
= xcalloc(1, sizeof(struct bbm_log
));
942 struct bbm_log
*log
= (void *)mpb
+
943 __le32_to_cpu(mpb
->mpb_size
) - bbm_log_size
;
947 if (bbm_log_size
< sizeof(log
->signature
) +
948 sizeof(log
->entry_count
))
951 entry_count
= __le32_to_cpu(log
->entry_count
);
952 if ((__le32_to_cpu(log
->signature
) != BBM_LOG_SIGNATURE
) ||
953 (entry_count
> BBM_LOG_MAX_ENTRIES
))
957 sizeof(log
->signature
) + sizeof(log
->entry_count
) +
958 entry_count
* sizeof(struct bbm_log_entry
))
961 memcpy(super
->bbm_log
, log
, bbm_log_size
);
963 super
->bbm_log
->signature
= __cpu_to_le32(BBM_LOG_SIGNATURE
);
964 super
->bbm_log
->entry_count
= 0;
970 /* checks if bad block is within volume boundaries */
971 static int is_bad_block_in_volume(const struct bbm_log_entry
*entry
,
972 const unsigned long long start_sector
,
973 const unsigned long long size
)
975 unsigned long long bb_start
;
976 unsigned long long bb_end
;
978 bb_start
= __le48_to_cpu(&entry
->defective_block_start
);
979 bb_end
= bb_start
+ (entry
->marked_count
+ 1);
981 if (((bb_start
>= start_sector
) && (bb_start
< start_sector
+ size
)) ||
982 ((bb_end
>= start_sector
) && (bb_end
<= start_sector
+ size
)))
988 /* get list of bad blocks on a drive for a volume */
989 static void get_volume_badblocks(const struct bbm_log
*log
, const __u8 idx
,
990 const unsigned long long start_sector
,
991 const unsigned long long size
,
997 for (i
= 0; i
< log
->entry_count
; i
++) {
998 const struct bbm_log_entry
*ent
=
999 &log
->marked_block_entries
[i
];
1000 struct md_bb_entry
*bb
;
1002 if ((ent
->disk_ordinal
== idx
) &&
1003 is_bad_block_in_volume(ent
, start_sector
, size
)) {
1005 if (!bbs
->entries
) {
1006 bbs
->entries
= xmalloc(BBM_LOG_MAX_ENTRIES
*
1012 bb
= &bbs
->entries
[count
++];
1013 bb
->sector
= __le48_to_cpu(&ent
->defective_block_start
);
1014 bb
->length
= ent
->marked_count
+ 1;
1022 * == MAP_0 get first map
1023 * == MAP_1 get second map
1024 * == MAP_X than get map according to the current migr_state
1026 static __u32
get_imsm_ord_tbl_ent(struct imsm_dev
*dev
,
1030 struct imsm_map
*map
;
1032 map
= get_imsm_map(dev
, second_map
);
1034 /* top byte identifies disk under rebuild */
1035 return __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
1038 #define ord_to_idx(ord) (((ord) << 8) >> 8)
1039 static __u32
get_imsm_disk_idx(struct imsm_dev
*dev
, int slot
, int second_map
)
1041 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, second_map
);
1043 return ord_to_idx(ord
);
1046 static void set_imsm_ord_tbl_ent(struct imsm_map
*map
, int slot
, __u32 ord
)
1048 map
->disk_ord_tbl
[slot
] = __cpu_to_le32(ord
);
1051 static int get_imsm_disk_slot(struct imsm_map
*map
, unsigned idx
)
1056 for (slot
= 0; slot
< map
->num_members
; slot
++) {
1057 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
1058 if (ord_to_idx(ord
) == idx
)
1065 static int get_imsm_raid_level(struct imsm_map
*map
)
1067 if (map
->raid_level
== 1) {
1068 if (map
->num_members
== 2)
1074 return map
->raid_level
;
1077 static int cmp_extent(const void *av
, const void *bv
)
1079 const struct extent
*a
= av
;
1080 const struct extent
*b
= bv
;
1081 if (a
->start
< b
->start
)
1083 if (a
->start
> b
->start
)
1088 static int count_memberships(struct dl
*dl
, struct intel_super
*super
)
1090 int memberships
= 0;
1093 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1094 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1095 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1097 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
1104 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
);
1106 static int split_ull(unsigned long long n
, __u32
*lo
, __u32
*hi
)
1108 if (lo
== 0 || hi
== 0)
1110 *lo
= __le32_to_cpu((unsigned)n
);
1111 *hi
= __le32_to_cpu((unsigned)(n
>> 32));
1115 static unsigned long long join_u32(__u32 lo
, __u32 hi
)
1117 return (unsigned long long)__le32_to_cpu(lo
) |
1118 (((unsigned long long)__le32_to_cpu(hi
)) << 32);
1121 static unsigned long long total_blocks(struct imsm_disk
*disk
)
1125 return join_u32(disk
->total_blocks_lo
, disk
->total_blocks_hi
);
1128 static unsigned long long pba_of_lba0(struct imsm_map
*map
)
1132 return join_u32(map
->pba_of_lba0_lo
, map
->pba_of_lba0_hi
);
1135 static unsigned long long blocks_per_member(struct imsm_map
*map
)
1139 return join_u32(map
->blocks_per_member_lo
, map
->blocks_per_member_hi
);
1142 static unsigned long long num_data_stripes(struct imsm_map
*map
)
1146 return join_u32(map
->num_data_stripes_lo
, map
->num_data_stripes_hi
);
1149 static void set_total_blocks(struct imsm_disk
*disk
, unsigned long long n
)
1151 split_ull(n
, &disk
->total_blocks_lo
, &disk
->total_blocks_hi
);
1154 static void set_pba_of_lba0(struct imsm_map
*map
, unsigned long long n
)
1156 split_ull(n
, &map
->pba_of_lba0_lo
, &map
->pba_of_lba0_hi
);
1159 static void set_blocks_per_member(struct imsm_map
*map
, unsigned long long n
)
1161 split_ull(n
, &map
->blocks_per_member_lo
, &map
->blocks_per_member_hi
);
1164 static void set_num_data_stripes(struct imsm_map
*map
, unsigned long long n
)
1166 split_ull(n
, &map
->num_data_stripes_lo
, &map
->num_data_stripes_hi
);
1169 static struct extent
*get_extents(struct intel_super
*super
, struct dl
*dl
)
1171 /* find a list of used extents on the given physical device */
1172 struct extent
*rv
, *e
;
1174 int memberships
= count_memberships(dl
, super
);
1177 /* trim the reserved area for spares, so they can join any array
1178 * regardless of whether the OROM has assigned sectors from the
1179 * IMSM_RESERVED_SECTORS region
1181 if (dl
->index
== -1)
1182 reservation
= imsm_min_reserved_sectors(super
);
1184 reservation
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1186 rv
= xcalloc(sizeof(struct extent
), (memberships
+ 1));
1189 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1190 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1191 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1193 if (get_imsm_disk_slot(map
, dl
->index
) >= 0) {
1194 e
->start
= pba_of_lba0(map
);
1195 e
->size
= blocks_per_member(map
);
1199 qsort(rv
, memberships
, sizeof(*rv
), cmp_extent
);
1201 /* determine the start of the metadata
1202 * when no raid devices are defined use the default
1203 * ...otherwise allow the metadata to truncate the value
1204 * as is the case with older versions of imsm
1207 struct extent
*last
= &rv
[memberships
- 1];
1208 unsigned long long remainder
;
1210 remainder
= total_blocks(&dl
->disk
) - (last
->start
+ last
->size
);
1211 /* round down to 1k block to satisfy precision of the kernel
1215 /* make sure remainder is still sane */
1216 if (remainder
< (unsigned)ROUND_UP(super
->len
, 512) >> 9)
1217 remainder
= ROUND_UP(super
->len
, 512) >> 9;
1218 if (reservation
> remainder
)
1219 reservation
= remainder
;
1221 e
->start
= total_blocks(&dl
->disk
) - reservation
;
1226 /* try to determine how much space is reserved for metadata from
1227 * the last get_extents() entry, otherwise fallback to the
1230 static __u32
imsm_reserved_sectors(struct intel_super
*super
, struct dl
*dl
)
1236 /* for spares just return a minimal reservation which will grow
1237 * once the spare is picked up by an array
1239 if (dl
->index
== -1)
1240 return MPB_SECTOR_CNT
;
1242 e
= get_extents(super
, dl
);
1244 return MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1246 /* scroll to last entry */
1247 for (i
= 0; e
[i
].size
; i
++)
1250 rv
= total_blocks(&dl
->disk
) - e
[i
].start
;
1257 static int is_spare(struct imsm_disk
*disk
)
1259 return (disk
->status
& SPARE_DISK
) == SPARE_DISK
;
1262 static int is_configured(struct imsm_disk
*disk
)
1264 return (disk
->status
& CONFIGURED_DISK
) == CONFIGURED_DISK
;
1267 static int is_failed(struct imsm_disk
*disk
)
1269 return (disk
->status
& FAILED_DISK
) == FAILED_DISK
;
1272 /* try to determine how much space is reserved for metadata from
1273 * the last get_extents() entry on the smallest active disk,
1274 * otherwise fallback to the default
1276 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
)
1280 unsigned long long min_active
;
1282 __u32 rv
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1283 struct dl
*dl
, *dl_min
= NULL
;
1289 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
1292 unsigned long long blocks
= total_blocks(&dl
->disk
);
1293 if (blocks
< min_active
|| min_active
== 0) {
1295 min_active
= blocks
;
1301 /* find last lba used by subarrays on the smallest active disk */
1302 e
= get_extents(super
, dl_min
);
1305 for (i
= 0; e
[i
].size
; i
++)
1308 remainder
= min_active
- e
[i
].start
;
1311 /* to give priority to recovery we should not require full
1312 IMSM_RESERVED_SECTORS from the spare */
1313 rv
= MPB_SECTOR_CNT
+ NUM_BLOCKS_DIRTY_STRIPE_REGION
;
1315 /* if real reservation is smaller use that value */
1316 return (remainder
< rv
) ? remainder
: rv
;
1319 /* Return minimum size of a spare that can be used in this array*/
1320 static unsigned long long min_acceptable_spare_size_imsm(struct supertype
*st
)
1322 struct intel_super
*super
= st
->sb
;
1326 unsigned long long rv
= 0;
1330 /* find first active disk in array */
1332 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
1336 /* find last lba used by subarrays */
1337 e
= get_extents(super
, dl
);
1340 for (i
= 0; e
[i
].size
; i
++)
1343 rv
= e
[i
-1].start
+ e
[i
-1].size
;
1346 /* add the amount of space needed for metadata */
1347 rv
= rv
+ imsm_min_reserved_sectors(super
);
1352 static int is_gen_migration(struct imsm_dev
*dev
);
1354 #define IMSM_4K_DIV 8
1357 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
1358 struct imsm_dev
*dev
);
1360 static void print_imsm_dev(struct intel_super
*super
,
1361 struct imsm_dev
*dev
,
1367 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1368 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
1372 printf("[%.16s]:\n", dev
->volume
);
1373 printf(" UUID : %s\n", uuid
);
1374 printf(" RAID Level : %d", get_imsm_raid_level(map
));
1376 printf(" <-- %d", get_imsm_raid_level(map2
));
1378 printf(" Members : %d", map
->num_members
);
1380 printf(" <-- %d", map2
->num_members
);
1382 printf(" Slots : [");
1383 for (i
= 0; i
< map
->num_members
; i
++) {
1384 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
1385 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1390 for (i
= 0; i
< map2
->num_members
; i
++) {
1391 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_1
);
1392 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1397 printf(" Failed disk : ");
1398 if (map
->failed_disk_num
== 0xff)
1401 printf("%i", map
->failed_disk_num
);
1403 slot
= get_imsm_disk_slot(map
, disk_idx
);
1405 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
1406 printf(" This Slot : %d%s\n", slot
,
1407 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
1409 printf(" This Slot : ?\n");
1410 sz
= __le32_to_cpu(dev
->size_high
);
1412 sz
+= __le32_to_cpu(dev
->size_low
);
1413 printf(" Array Size : %llu%s\n", (unsigned long long)sz
,
1414 human_size(sz
* 512));
1415 sz
= blocks_per_member(map
);
1416 printf(" Per Dev Size : %llu%s\n", (unsigned long long)sz
,
1417 human_size(sz
* 512));
1418 printf(" Sector Offset : %llu\n",
1420 printf(" Num Stripes : %llu\n",
1421 num_data_stripes(map
));
1422 printf(" Chunk Size : %u KiB",
1423 __le16_to_cpu(map
->blocks_per_strip
) / 2);
1425 printf(" <-- %u KiB",
1426 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
1428 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
1429 printf(" Migrate State : ");
1430 if (dev
->vol
.migr_state
) {
1431 if (migr_type(dev
) == MIGR_INIT
)
1432 printf("initialize\n");
1433 else if (migr_type(dev
) == MIGR_REBUILD
)
1434 printf("rebuild\n");
1435 else if (migr_type(dev
) == MIGR_VERIFY
)
1437 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
1438 printf("general migration\n");
1439 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
1440 printf("state change\n");
1441 else if (migr_type(dev
) == MIGR_REPAIR
)
1444 printf("<unknown:%d>\n", migr_type(dev
));
1447 printf(" Map State : %s", map_state_str
[map
->map_state
]);
1448 if (dev
->vol
.migr_state
) {
1449 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
1451 printf(" <-- %s", map_state_str
[map
->map_state
]);
1452 printf("\n Checkpoint : %u ",
1453 __le32_to_cpu(dev
->vol
.curr_migr_unit
));
1454 if (is_gen_migration(dev
) && (slot
> 1 || slot
< 0))
1457 printf("(%llu)", (unsigned long long)
1458 blocks_per_migr_unit(super
, dev
));
1461 printf(" Dirty State : %s\n", dev
->vol
.dirty
? "dirty" : "clean");
1464 static void print_imsm_disk(struct imsm_disk
*disk
, int index
, __u32 reserved
)
1466 char str
[MAX_RAID_SERIAL_LEN
+ 1];
1469 if (index
< -1 || !disk
)
1473 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
1475 printf(" Disk%02d Serial : %s\n", index
, str
);
1477 printf(" Disk Serial : %s\n", str
);
1478 printf(" State :%s%s%s\n", is_spare(disk
) ? " spare" : "",
1479 is_configured(disk
) ? " active" : "",
1480 is_failed(disk
) ? " failed" : "");
1481 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
1482 sz
= total_blocks(disk
) - reserved
;
1483 printf(" Usable Size : %llu%s\n", (unsigned long long)sz
,
1484 human_size(sz
* 512));
1487 void convert_to_4k_imsm_migr_rec(struct intel_super
*super
)
1489 struct migr_record
*migr_rec
= super
->migr_rec
;
1491 migr_rec
->blocks_per_unit
/= IMSM_4K_DIV
;
1492 migr_rec
->ckpt_area_pba
/= IMSM_4K_DIV
;
1493 migr_rec
->dest_1st_member_lba
/= IMSM_4K_DIV
;
1494 migr_rec
->dest_depth_per_unit
/= IMSM_4K_DIV
;
1495 split_ull((join_u32(migr_rec
->post_migr_vol_cap
,
1496 migr_rec
->post_migr_vol_cap_hi
) / IMSM_4K_DIV
),
1497 &migr_rec
->post_migr_vol_cap
, &migr_rec
->post_migr_vol_cap_hi
);
1500 void convert_to_4k_imsm_disk(struct imsm_disk
*disk
)
1502 set_total_blocks(disk
, (total_blocks(disk
)/IMSM_4K_DIV
));
1505 void convert_to_4k(struct intel_super
*super
)
1507 struct imsm_super
*mpb
= super
->anchor
;
1508 struct imsm_disk
*disk
;
1511 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1512 disk
= __get_imsm_disk(mpb
, i
);
1514 convert_to_4k_imsm_disk(disk
);
1516 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1517 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1518 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1520 split_ull((join_u32(dev
->size_low
, dev
->size_high
)/IMSM_4K_DIV
),
1521 &dev
->size_low
, &dev
->size_high
);
1522 dev
->vol
.curr_migr_unit
/= IMSM_4K_DIV
;
1525 set_blocks_per_member(map
, blocks_per_member(map
)/IMSM_4K_DIV
);
1526 map
->blocks_per_strip
/= IMSM_4K_DIV
;
1527 set_pba_of_lba0(map
, pba_of_lba0(map
)/IMSM_4K_DIV
);
1529 if (dev
->vol
.migr_state
) {
1531 map
= get_imsm_map(dev
, MAP_1
);
1532 set_blocks_per_member(map
,
1533 blocks_per_member(map
)/IMSM_4K_DIV
);
1534 map
->blocks_per_strip
/= IMSM_4K_DIV
;
1535 set_pba_of_lba0(map
, pba_of_lba0(map
)/IMSM_4K_DIV
);
1539 mpb
->check_sum
= __gen_imsm_checksum(mpb
);
1542 void examine_migr_rec_imsm(struct intel_super
*super
)
1544 struct migr_record
*migr_rec
= super
->migr_rec
;
1545 struct imsm_super
*mpb
= super
->anchor
;
1548 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1549 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1550 struct imsm_map
*map
;
1553 if (is_gen_migration(dev
) == 0)
1556 printf("\nMigration Record Information:");
1558 /* first map under migration */
1559 map
= get_imsm_map(dev
, MAP_0
);
1561 slot
= get_imsm_disk_slot(map
, super
->disks
->index
);
1562 if (map
== NULL
|| slot
> 1 || slot
< 0) {
1563 printf(" Empty\n ");
1564 printf("Examine one of first two disks in array\n");
1567 printf("\n Status : ");
1568 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
1571 printf("Contains Data\n");
1572 printf(" Current Unit : %u\n",
1573 __le32_to_cpu(migr_rec
->curr_migr_unit
));
1574 printf(" Family : %u\n",
1575 __le32_to_cpu(migr_rec
->family_num
));
1576 printf(" Ascending : %u\n",
1577 __le32_to_cpu(migr_rec
->ascending_migr
));
1578 printf(" Blocks Per Unit : %u\n",
1579 __le32_to_cpu(migr_rec
->blocks_per_unit
));
1580 printf(" Dest. Depth Per Unit : %u\n",
1581 __le32_to_cpu(migr_rec
->dest_depth_per_unit
));
1582 printf(" Checkpoint Area pba : %u\n",
1583 __le32_to_cpu(migr_rec
->ckpt_area_pba
));
1584 printf(" First member lba : %u\n",
1585 __le32_to_cpu(migr_rec
->dest_1st_member_lba
));
1586 printf(" Total Number of Units : %u\n",
1587 __le32_to_cpu(migr_rec
->num_migr_units
));
1588 printf(" Size of volume : %u\n",
1589 __le32_to_cpu(migr_rec
->post_migr_vol_cap
));
1590 printf(" Expansion space for LBA64 : %u\n",
1591 __le32_to_cpu(migr_rec
->post_migr_vol_cap_hi
));
1592 printf(" Record was read from : %u\n",
1593 __le32_to_cpu(migr_rec
->ckpt_read_disk_num
));
1598 #endif /* MDASSEMBLE */
1600 void convert_from_4k_imsm_migr_rec(struct intel_super
*super
)
1602 struct migr_record
*migr_rec
= super
->migr_rec
;
1604 migr_rec
->blocks_per_unit
*= IMSM_4K_DIV
;
1605 migr_rec
->ckpt_area_pba
*= IMSM_4K_DIV
;
1606 migr_rec
->dest_1st_member_lba
*= IMSM_4K_DIV
;
1607 migr_rec
->dest_depth_per_unit
*= IMSM_4K_DIV
;
1608 split_ull((join_u32(migr_rec
->post_migr_vol_cap
,
1609 migr_rec
->post_migr_vol_cap_hi
) * IMSM_4K_DIV
),
1610 &migr_rec
->post_migr_vol_cap
,
1611 &migr_rec
->post_migr_vol_cap_hi
);
1614 void convert_from_4k(struct intel_super
*super
)
1616 struct imsm_super
*mpb
= super
->anchor
;
1617 struct imsm_disk
*disk
;
1620 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1621 disk
= __get_imsm_disk(mpb
, i
);
1623 set_total_blocks(disk
, (total_blocks(disk
)*IMSM_4K_DIV
));
1626 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1627 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1628 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1630 split_ull((join_u32(dev
->size_low
, dev
->size_high
)*IMSM_4K_DIV
),
1631 &dev
->size_low
, &dev
->size_high
);
1632 dev
->vol
.curr_migr_unit
*= IMSM_4K_DIV
;
1635 set_blocks_per_member(map
, blocks_per_member(map
)*IMSM_4K_DIV
);
1636 map
->blocks_per_strip
*= IMSM_4K_DIV
;
1637 set_pba_of_lba0(map
, pba_of_lba0(map
)*IMSM_4K_DIV
);
1639 if (dev
->vol
.migr_state
) {
1641 map
= get_imsm_map(dev
, MAP_1
);
1642 set_blocks_per_member(map
,
1643 blocks_per_member(map
)*IMSM_4K_DIV
);
1644 map
->blocks_per_strip
*= IMSM_4K_DIV
;
1645 set_pba_of_lba0(map
, pba_of_lba0(map
)*IMSM_4K_DIV
);
1649 mpb
->check_sum
= __gen_imsm_checksum(mpb
);
1652 /*******************************************************************************
1653 * function: imsm_check_attributes
1654 * Description: Function checks if features represented by attributes flags
1655 * are supported by mdadm.
1657 * attributes - Attributes read from metadata
1659 * 0 - passed attributes contains unsupported features flags
1660 * 1 - all features are supported
1661 ******************************************************************************/
1662 static int imsm_check_attributes(__u32 attributes
)
1665 __u32 not_supported
= MPB_ATTRIB_SUPPORTED
^0xffffffff;
1667 not_supported
&= ~MPB_ATTRIB_IGNORED
;
1669 not_supported
&= attributes
;
1670 if (not_supported
) {
1671 pr_err("(IMSM): Unsupported attributes : %x\n",
1672 (unsigned)__le32_to_cpu(not_supported
));
1673 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1674 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY \n");
1675 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1677 if (not_supported
& MPB_ATTRIB_2TB
) {
1678 dprintf("\t\tMPB_ATTRIB_2TB\n");
1679 not_supported
^= MPB_ATTRIB_2TB
;
1681 if (not_supported
& MPB_ATTRIB_RAID0
) {
1682 dprintf("\t\tMPB_ATTRIB_RAID0\n");
1683 not_supported
^= MPB_ATTRIB_RAID0
;
1685 if (not_supported
& MPB_ATTRIB_RAID1
) {
1686 dprintf("\t\tMPB_ATTRIB_RAID1\n");
1687 not_supported
^= MPB_ATTRIB_RAID1
;
1689 if (not_supported
& MPB_ATTRIB_RAID10
) {
1690 dprintf("\t\tMPB_ATTRIB_RAID10\n");
1691 not_supported
^= MPB_ATTRIB_RAID10
;
1693 if (not_supported
& MPB_ATTRIB_RAID1E
) {
1694 dprintf("\t\tMPB_ATTRIB_RAID1E\n");
1695 not_supported
^= MPB_ATTRIB_RAID1E
;
1697 if (not_supported
& MPB_ATTRIB_RAID5
) {
1698 dprintf("\t\tMPB_ATTRIB_RAID5\n");
1699 not_supported
^= MPB_ATTRIB_RAID5
;
1701 if (not_supported
& MPB_ATTRIB_RAIDCNG
) {
1702 dprintf("\t\tMPB_ATTRIB_RAIDCNG\n");
1703 not_supported
^= MPB_ATTRIB_RAIDCNG
;
1705 if (not_supported
& MPB_ATTRIB_BBM
) {
1706 dprintf("\t\tMPB_ATTRIB_BBM\n");
1707 not_supported
^= MPB_ATTRIB_BBM
;
1709 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1710 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY (== MPB_ATTRIB_LEGACY)\n");
1711 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1713 if (not_supported
& MPB_ATTRIB_EXP_STRIPE_SIZE
) {
1714 dprintf("\t\tMPB_ATTRIB_EXP_STRIP_SIZE\n");
1715 not_supported
^= MPB_ATTRIB_EXP_STRIPE_SIZE
;
1717 if (not_supported
& MPB_ATTRIB_2TB_DISK
) {
1718 dprintf("\t\tMPB_ATTRIB_2TB_DISK\n");
1719 not_supported
^= MPB_ATTRIB_2TB_DISK
;
1721 if (not_supported
& MPB_ATTRIB_NEVER_USE2
) {
1722 dprintf("\t\tMPB_ATTRIB_NEVER_USE2\n");
1723 not_supported
^= MPB_ATTRIB_NEVER_USE2
;
1725 if (not_supported
& MPB_ATTRIB_NEVER_USE
) {
1726 dprintf("\t\tMPB_ATTRIB_NEVER_USE\n");
1727 not_supported
^= MPB_ATTRIB_NEVER_USE
;
1731 dprintf("(IMSM): Unknown attributes : %x\n", not_supported
);
1740 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
1742 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
1744 struct intel_super
*super
= st
->sb
;
1745 struct imsm_super
*mpb
= super
->anchor
;
1746 char str
[MAX_SIGNATURE_LENGTH
];
1751 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
1754 snprintf(str
, MPB_SIG_LEN
, "%s", mpb
->sig
);
1755 printf(" Magic : %s\n", str
);
1756 snprintf(str
, strlen(MPB_VERSION_RAID0
), "%s", get_imsm_version(mpb
));
1757 printf(" Version : %s\n", get_imsm_version(mpb
));
1758 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
1759 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
1760 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
1761 printf(" Attributes : ");
1762 if (imsm_check_attributes(mpb
->attributes
))
1763 printf("All supported\n");
1765 printf("not supported\n");
1766 getinfo_super_imsm(st
, &info
, NULL
);
1767 fname_from_uuid(st
, &info
, nbuf
, ':');
1768 printf(" UUID : %s\n", nbuf
+ 5);
1769 sum
= __le32_to_cpu(mpb
->check_sum
);
1770 printf(" Checksum : %08x %s\n", sum
,
1771 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
1772 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
, super
->sector_size
));
1773 printf(" Disks : %d\n", mpb
->num_disks
);
1774 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
1775 print_imsm_disk(__get_imsm_disk(mpb
, super
->disks
->index
), super
->disks
->index
, reserved
);
1776 if (get_imsm_bbm_log_size(super
->bbm_log
)) {
1777 struct bbm_log
*log
= super
->bbm_log
;
1780 printf("Bad Block Management Log:\n");
1781 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
1782 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
1783 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
1785 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1787 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1789 super
->current_vol
= i
;
1790 getinfo_super_imsm(st
, &info
, NULL
);
1791 fname_from_uuid(st
, &info
, nbuf
, ':');
1792 print_imsm_dev(super
, dev
, nbuf
+ 5, super
->disks
->index
);
1794 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1795 if (i
== super
->disks
->index
)
1797 print_imsm_disk(__get_imsm_disk(mpb
, i
), i
, reserved
);
1800 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
1801 if (dl
->index
== -1)
1802 print_imsm_disk(&dl
->disk
, -1, reserved
);
1804 examine_migr_rec_imsm(super
);
1807 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
1809 /* We just write a generic IMSM ARRAY entry */
1812 struct intel_super
*super
= st
->sb
;
1814 if (!super
->anchor
->num_raid_devs
) {
1815 printf("ARRAY metadata=imsm\n");
1819 getinfo_super_imsm(st
, &info
, NULL
);
1820 fname_from_uuid(st
, &info
, nbuf
, ':');
1821 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
1824 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
1826 /* We just write a generic IMSM ARRAY entry */
1830 struct intel_super
*super
= st
->sb
;
1833 if (!super
->anchor
->num_raid_devs
)
1836 getinfo_super_imsm(st
, &info
, NULL
);
1837 fname_from_uuid(st
, &info
, nbuf
, ':');
1838 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1839 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1841 super
->current_vol
= i
;
1842 getinfo_super_imsm(st
, &info
, NULL
);
1843 fname_from_uuid(st
, &info
, nbuf1
, ':');
1844 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
1845 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
1849 static void export_examine_super_imsm(struct supertype
*st
)
1851 struct intel_super
*super
= st
->sb
;
1852 struct imsm_super
*mpb
= super
->anchor
;
1856 getinfo_super_imsm(st
, &info
, NULL
);
1857 fname_from_uuid(st
, &info
, nbuf
, ':');
1858 printf("MD_METADATA=imsm\n");
1859 printf("MD_LEVEL=container\n");
1860 printf("MD_UUID=%s\n", nbuf
+5);
1861 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
1864 static int copy_metadata_imsm(struct supertype
*st
, int from
, int to
)
1866 /* The second last sector of the device contains
1867 * the "struct imsm_super" metadata.
1868 * This contains mpb_size which is the size in bytes of the
1869 * extended metadata. This is located immediately before
1871 * We want to read all that, plus the last sector which
1872 * may contain a migration record, and write it all
1876 unsigned long long dsize
, offset
;
1878 struct imsm_super
*sb
;
1879 struct intel_super
*super
= st
->sb
;
1880 unsigned int sector_size
= super
->sector_size
;
1881 unsigned int written
= 0;
1883 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, MAX_SECTOR_SIZE
) != 0)
1886 if (!get_dev_size(from
, NULL
, &dsize
))
1889 if (lseek64(from
, dsize
-(2*sector_size
), 0) < 0)
1891 if (read(from
, buf
, sector_size
) != sector_size
)
1894 if (strncmp((char*)sb
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0)
1897 sectors
= mpb_sectors(sb
, sector_size
) + 2;
1898 offset
= dsize
- sectors
* sector_size
;
1899 if (lseek64(from
, offset
, 0) < 0 ||
1900 lseek64(to
, offset
, 0) < 0)
1902 while (written
< sectors
* sector_size
) {
1903 int n
= sectors
*sector_size
- written
;
1906 if (read(from
, buf
, n
) != n
)
1908 if (write(to
, buf
, n
) != n
)
1919 static void detail_super_imsm(struct supertype
*st
, char *homehost
)
1924 getinfo_super_imsm(st
, &info
, NULL
);
1925 fname_from_uuid(st
, &info
, nbuf
, ':');
1926 printf("\n UUID : %s\n", nbuf
+ 5);
1929 static void brief_detail_super_imsm(struct supertype
*st
)
1933 getinfo_super_imsm(st
, &info
, NULL
);
1934 fname_from_uuid(st
, &info
, nbuf
, ':');
1935 printf(" UUID=%s", nbuf
+ 5);
1938 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
);
1939 static void fd2devname(int fd
, char *name
);
1941 static int ahci_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
1943 /* dump an unsorted list of devices attached to AHCI Intel storage
1944 * controller, as well as non-connected ports
1946 int hba_len
= strlen(hba_path
) + 1;
1951 unsigned long port_mask
= (1 << port_count
) - 1;
1953 if (port_count
> (int)sizeof(port_mask
) * 8) {
1955 pr_err("port_count %d out of range\n", port_count
);
1959 /* scroll through /sys/dev/block looking for devices attached to
1962 dir
= opendir("/sys/dev/block");
1966 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
1977 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
1979 path
= devt_to_devpath(makedev(major
, minor
));
1982 if (!path_attached_to_hba(path
, hba_path
)) {
1988 /* retrieve the scsi device type */
1989 if (asprintf(&device
, "/sys/dev/block/%d:%d/device/xxxxxxx", major
, minor
) < 0) {
1991 pr_err("failed to allocate 'device'\n");
1995 sprintf(device
, "/sys/dev/block/%d:%d/device/type", major
, minor
);
1996 if (load_sys(device
, buf
, sizeof(buf
)) != 0) {
1998 pr_err("failed to read device type for %s\n",
2004 type
= strtoul(buf
, NULL
, 10);
2006 /* if it's not a disk print the vendor and model */
2007 if (!(type
== 0 || type
== 7 || type
== 14)) {
2010 sprintf(device
, "/sys/dev/block/%d:%d/device/vendor", major
, minor
);
2011 if (load_sys(device
, buf
, sizeof(buf
)) == 0) {
2012 strncpy(vendor
, buf
, sizeof(vendor
));
2013 vendor
[sizeof(vendor
) - 1] = '\0';
2014 c
= (char *) &vendor
[sizeof(vendor
) - 1];
2015 while (isspace(*c
) || *c
== '\0')
2019 sprintf(device
, "/sys/dev/block/%d:%d/device/model", major
, minor
);
2020 if (load_sys(device
, buf
, sizeof(buf
)) == 0) {
2021 strncpy(model
, buf
, sizeof(model
));
2022 model
[sizeof(model
) - 1] = '\0';
2023 c
= (char *) &model
[sizeof(model
) - 1];
2024 while (isspace(*c
) || *c
== '\0')
2028 if (vendor
[0] && model
[0])
2029 sprintf(buf
, "%.64s %.64s", vendor
, model
);
2031 switch (type
) { /* numbers from hald/linux/device.c */
2032 case 1: sprintf(buf
, "tape"); break;
2033 case 2: sprintf(buf
, "printer"); break;
2034 case 3: sprintf(buf
, "processor"); break;
2036 case 5: sprintf(buf
, "cdrom"); break;
2037 case 6: sprintf(buf
, "scanner"); break;
2038 case 8: sprintf(buf
, "media_changer"); break;
2039 case 9: sprintf(buf
, "comm"); break;
2040 case 12: sprintf(buf
, "raid"); break;
2041 default: sprintf(buf
, "unknown");
2047 /* chop device path to 'host%d' and calculate the port number */
2048 c
= strchr(&path
[hba_len
], '/');
2051 pr_err("%s - invalid path name\n", path
+ hba_len
);
2056 if ((sscanf(&path
[hba_len
], "ata%d", &port
) == 1) ||
2057 ((sscanf(&path
[hba_len
], "host%d", &port
) == 1)))
2061 *c
= '/'; /* repair the full string */
2062 pr_err("failed to determine port number for %s\n",
2069 /* mark this port as used */
2070 port_mask
&= ~(1 << port
);
2072 /* print out the device information */
2074 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
2078 fd
= dev_open(ent
->d_name
, O_RDONLY
);
2080 printf(" Port%d : - disk info unavailable -\n", port
);
2082 fd2devname(fd
, buf
);
2083 printf(" Port%d : %s", port
, buf
);
2084 if (imsm_read_serial(fd
, NULL
, (__u8
*) buf
) == 0)
2085 printf(" (%.*s)\n", MAX_RAID_SERIAL_LEN
, buf
);
2100 for (i
= 0; i
< port_count
; i
++)
2101 if (port_mask
& (1 << i
))
2102 printf(" Port%d : - no device attached -\n", i
);
2108 static int print_vmd_attached_devs(struct sys_dev
*hba
)
2116 if (hba
->type
!= SYS_DEV_VMD
)
2119 /* scroll through /sys/dev/block looking for devices attached to
2122 dir
= opendir("/sys/bus/pci/drivers/nvme");
2126 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2129 /* is 'ent' a device? check that the 'subsystem' link exists and
2130 * that its target matches 'bus'
2132 sprintf(path
, "/sys/bus/pci/drivers/nvme/%s/subsystem",
2134 n
= readlink(path
, link
, sizeof(link
));
2135 if (n
< 0 || n
>= (int)sizeof(link
))
2138 c
= strrchr(link
, '/');
2141 if (strncmp("pci", c
+1, strlen("pci")) != 0)
2144 sprintf(path
, "/sys/bus/pci/drivers/nvme/%s", ent
->d_name
);
2145 /* if not a intel NVMe - skip it*/
2146 if (devpath_to_vendor(path
) != 0x8086)
2149 rp
= realpath(path
, NULL
);
2153 if (path_attached_to_hba(rp
, hba
->path
)) {
2154 printf(" NVMe under VMD : %s\n", rp
);
2163 static void print_found_intel_controllers(struct sys_dev
*elem
)
2165 for (; elem
; elem
= elem
->next
) {
2166 pr_err("found Intel(R) ");
2167 if (elem
->type
== SYS_DEV_SATA
)
2168 fprintf(stderr
, "SATA ");
2169 else if (elem
->type
== SYS_DEV_SAS
)
2170 fprintf(stderr
, "SAS ");
2171 else if (elem
->type
== SYS_DEV_NVME
)
2172 fprintf(stderr
, "NVMe ");
2174 if (elem
->type
== SYS_DEV_VMD
)
2175 fprintf(stderr
, "VMD domain");
2177 fprintf(stderr
, "RAID controller");
2180 fprintf(stderr
, " at %s", elem
->pci_id
);
2181 fprintf(stderr
, ".\n");
2186 static int ahci_get_port_count(const char *hba_path
, int *port_count
)
2193 if ((dir
= opendir(hba_path
)) == NULL
)
2196 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
2199 if ((sscanf(ent
->d_name
, "ata%d", &host
) != 1) &&
2200 ((sscanf(ent
->d_name
, "host%d", &host
) != 1)))
2202 if (*port_count
== 0)
2204 else if (host
< host_base
)
2207 if (host
+ 1 > *port_count
+ host_base
)
2208 *port_count
= host
+ 1 - host_base
;
2214 static void print_imsm_capability(const struct imsm_orom
*orom
)
2216 printf(" Platform : Intel(R) ");
2217 if (orom
->capabilities
== 0 && orom
->driver_features
== 0)
2218 printf("Matrix Storage Manager\n");
2220 printf("Rapid Storage Technology%s\n",
2221 imsm_orom_is_enterprise(orom
) ? " enterprise" : "");
2222 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
2223 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
,
2224 orom
->minor_ver
, orom
->hotfix_ver
, orom
->build
);
2225 printf(" RAID Levels :%s%s%s%s%s\n",
2226 imsm_orom_has_raid0(orom
) ? " raid0" : "",
2227 imsm_orom_has_raid1(orom
) ? " raid1" : "",
2228 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
2229 imsm_orom_has_raid10(orom
) ? " raid10" : "",
2230 imsm_orom_has_raid5(orom
) ? " raid5" : "");
2231 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2232 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
2233 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
2234 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
2235 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
2236 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
2237 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
2238 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
2239 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
2240 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
2241 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
2242 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
2243 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
2244 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
2245 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
2246 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
2247 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
2248 printf(" 2TB volumes :%s supported\n",
2249 (orom
->attr
& IMSM_OROM_ATTR_2TB
)?"":" not");
2250 printf(" 2TB disks :%s supported\n",
2251 (orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
)?"":" not");
2252 printf(" Max Disks : %d\n", orom
->tds
);
2253 printf(" Max Volumes : %d per array, %d per %s\n",
2254 orom
->vpa
, orom
->vphba
,
2255 imsm_orom_is_nvme(orom
) ? "platform" : "controller");
2259 static void print_imsm_capability_export(const struct imsm_orom
*orom
)
2261 printf("MD_FIRMWARE_TYPE=imsm\n");
2262 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
2263 printf("IMSM_VERSION=%d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
2264 orom
->hotfix_ver
, orom
->build
);
2265 printf("IMSM_SUPPORTED_RAID_LEVELS=%s%s%s%s%s\n",
2266 imsm_orom_has_raid0(orom
) ? "raid0 " : "",
2267 imsm_orom_has_raid1(orom
) ? "raid1 " : "",
2268 imsm_orom_has_raid1e(orom
) ? "raid1e " : "",
2269 imsm_orom_has_raid5(orom
) ? "raid10 " : "",
2270 imsm_orom_has_raid10(orom
) ? "raid5 " : "");
2271 printf("IMSM_SUPPORTED_CHUNK_SIZES=%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
2272 imsm_orom_has_chunk(orom
, 2) ? "2k " : "",
2273 imsm_orom_has_chunk(orom
, 4) ? "4k " : "",
2274 imsm_orom_has_chunk(orom
, 8) ? "8k " : "",
2275 imsm_orom_has_chunk(orom
, 16) ? "16k " : "",
2276 imsm_orom_has_chunk(orom
, 32) ? "32k " : "",
2277 imsm_orom_has_chunk(orom
, 64) ? "64k " : "",
2278 imsm_orom_has_chunk(orom
, 128) ? "128k " : "",
2279 imsm_orom_has_chunk(orom
, 256) ? "256k " : "",
2280 imsm_orom_has_chunk(orom
, 512) ? "512k " : "",
2281 imsm_orom_has_chunk(orom
, 1024*1) ? "1M " : "",
2282 imsm_orom_has_chunk(orom
, 1024*2) ? "2M " : "",
2283 imsm_orom_has_chunk(orom
, 1024*4) ? "4M " : "",
2284 imsm_orom_has_chunk(orom
, 1024*8) ? "8M " : "",
2285 imsm_orom_has_chunk(orom
, 1024*16) ? "16M " : "",
2286 imsm_orom_has_chunk(orom
, 1024*32) ? "32M " : "",
2287 imsm_orom_has_chunk(orom
, 1024*64) ? "64M " : "");
2288 printf("IMSM_2TB_VOLUMES=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB
) ? "yes" : "no");
2289 printf("IMSM_2TB_DISKS=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) ? "yes" : "no");
2290 printf("IMSM_MAX_DISKS=%d\n",orom
->tds
);
2291 printf("IMSM_MAX_VOLUMES_PER_ARRAY=%d\n",orom
->vpa
);
2292 printf("IMSM_MAX_VOLUMES_PER_CONTROLLER=%d\n",orom
->vphba
);
2295 static int detail_platform_imsm(int verbose
, int enumerate_only
, char *controller_path
)
2297 /* There are two components to imsm platform support, the ahci SATA
2298 * controller and the option-rom. To find the SATA controller we
2299 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
2300 * controller with the Intel vendor id is present. This approach
2301 * allows mdadm to leverage the kernel's ahci detection logic, with the
2302 * caveat that if ahci.ko is not loaded mdadm will not be able to
2303 * detect platform raid capabilities. The option-rom resides in a
2304 * platform "Adapter ROM". We scan for its signature to retrieve the
2305 * platform capabilities. If raid support is disabled in the BIOS the
2306 * option-rom capability structure will not be available.
2308 struct sys_dev
*list
, *hba
;
2313 if (enumerate_only
) {
2314 if (check_env("IMSM_NO_PLATFORM"))
2316 list
= find_intel_devices();
2319 for (hba
= list
; hba
; hba
= hba
->next
) {
2320 if (find_imsm_capability(hba
)) {
2330 list
= find_intel_devices();
2333 pr_err("no active Intel(R) RAID controller found.\n");
2335 } else if (verbose
> 0)
2336 print_found_intel_controllers(list
);
2338 for (hba
= list
; hba
; hba
= hba
->next
) {
2339 if (controller_path
&& (compare_paths(hba
->path
, controller_path
) != 0))
2341 if (!find_imsm_capability(hba
)) {
2343 pr_err("imsm capabilities not found for controller: %s (type %s)\n",
2344 hba
->type
== SYS_DEV_VMD
? vmd_domain_to_controller(hba
, buf
) : hba
->path
,
2345 get_sys_dev_type(hba
->type
));
2351 if (controller_path
&& result
== 1) {
2352 pr_err("no active Intel(R) RAID controller found under %s\n",
2357 const struct orom_entry
*entry
;
2359 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
2360 if (entry
->type
== SYS_DEV_VMD
) {
2361 print_imsm_capability(&entry
->orom
);
2362 for (hba
= list
; hba
; hba
= hba
->next
) {
2363 if (hba
->type
== SYS_DEV_VMD
) {
2365 printf(" I/O Controller : %s (%s)\n",
2366 vmd_domain_to_controller(hba
, buf
), get_sys_dev_type(hba
->type
));
2367 if (print_vmd_attached_devs(hba
)) {
2369 pr_err("failed to get devices attached to VMD domain.\n");
2378 print_imsm_capability(&entry
->orom
);
2379 if (entry
->type
== SYS_DEV_NVME
) {
2380 for (hba
= list
; hba
; hba
= hba
->next
) {
2381 if (hba
->type
== SYS_DEV_NVME
)
2382 printf(" NVMe Device : %s\n", hba
->path
);
2388 struct devid_list
*devid
;
2389 for (devid
= entry
->devid_list
; devid
; devid
= devid
->next
) {
2390 hba
= device_by_id(devid
->devid
);
2394 printf(" I/O Controller : %s (%s)\n",
2395 hba
->path
, get_sys_dev_type(hba
->type
));
2396 if (hba
->type
== SYS_DEV_SATA
) {
2397 host_base
= ahci_get_port_count(hba
->path
, &port_count
);
2398 if (ahci_enumerate_ports(hba
->path
, port_count
, host_base
, verbose
)) {
2400 pr_err("failed to enumerate ports on SATA controller at %s.\n", hba
->pci_id
);
2411 static int export_detail_platform_imsm(int verbose
, char *controller_path
)
2413 struct sys_dev
*list
, *hba
;
2416 list
= find_intel_devices();
2419 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_INTEL_DEVICES\n");
2424 for (hba
= list
; hba
; hba
= hba
->next
) {
2425 if (controller_path
&& (compare_paths(hba
->path
,controller_path
) != 0))
2427 if (!find_imsm_capability(hba
) && verbose
> 0) {
2429 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_IMSM_CAPABLE_DEVICE_UNDER_%s\n",
2430 hba
->type
== SYS_DEV_VMD
? vmd_domain_to_controller(hba
, buf
) : hba
->path
);
2436 const struct orom_entry
*entry
;
2438 for (entry
= orom_entries
; entry
; entry
= entry
->next
) {
2439 if (entry
->type
== SYS_DEV_VMD
) {
2440 for (hba
= list
; hba
; hba
= hba
->next
)
2441 print_imsm_capability_export(&entry
->orom
);
2444 print_imsm_capability_export(&entry
->orom
);
2452 static int match_home_imsm(struct supertype
*st
, char *homehost
)
2454 /* the imsm metadata format does not specify any host
2455 * identification information. We return -1 since we can never
2456 * confirm nor deny whether a given array is "meant" for this
2457 * host. We rely on compare_super and the 'family_num' fields to
2458 * exclude member disks that do not belong, and we rely on
2459 * mdadm.conf to specify the arrays that should be assembled.
2460 * Auto-assembly may still pick up "foreign" arrays.
2466 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
2468 /* The uuid returned here is used for:
2469 * uuid to put into bitmap file (Create, Grow)
2470 * uuid for backup header when saving critical section (Grow)
2471 * comparing uuids when re-adding a device into an array
2472 * In these cases the uuid required is that of the data-array,
2473 * not the device-set.
2474 * uuid to recognise same set when adding a missing device back
2475 * to an array. This is a uuid for the device-set.
2477 * For each of these we can make do with a truncated
2478 * or hashed uuid rather than the original, as long as
2480 * In each case the uuid required is that of the data-array,
2481 * not the device-set.
2483 /* imsm does not track uuid's so we synthesis one using sha1 on
2484 * - The signature (Which is constant for all imsm array, but no matter)
2485 * - the orig_family_num of the container
2486 * - the index number of the volume
2487 * - the 'serial' number of the volume.
2488 * Hopefully these are all constant.
2490 struct intel_super
*super
= st
->sb
;
2493 struct sha1_ctx ctx
;
2494 struct imsm_dev
*dev
= NULL
;
2497 /* some mdadm versions failed to set ->orig_family_num, in which
2498 * case fall back to ->family_num. orig_family_num will be
2499 * fixed up with the first metadata update.
2501 family_num
= super
->anchor
->orig_family_num
;
2502 if (family_num
== 0)
2503 family_num
= super
->anchor
->family_num
;
2504 sha1_init_ctx(&ctx
);
2505 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
2506 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
2507 if (super
->current_vol
>= 0)
2508 dev
= get_imsm_dev(super
, super
->current_vol
);
2510 __u32 vol
= super
->current_vol
;
2511 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
2512 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
2514 sha1_finish_ctx(&ctx
, buf
);
2515 memcpy(uuid
, buf
, 4*4);
2520 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
2522 __u8
*v
= get_imsm_version(mpb
);
2523 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
2524 char major
[] = { 0, 0, 0 };
2525 char minor
[] = { 0 ,0, 0 };
2526 char patch
[] = { 0, 0, 0 };
2527 char *ver_parse
[] = { major
, minor
, patch
};
2531 while (*v
!= '\0' && v
< end
) {
2532 if (*v
!= '.' && j
< 2)
2533 ver_parse
[i
][j
++] = *v
;
2541 *m
= strtol(minor
, NULL
, 0);
2542 *p
= strtol(patch
, NULL
, 0);
2546 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
2548 /* migr_strip_size when repairing or initializing parity */
2549 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2550 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2552 switch (get_imsm_raid_level(map
)) {
2557 return 128*1024 >> 9;
2561 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
2563 /* migr_strip_size when rebuilding a degraded disk, no idea why
2564 * this is different than migr_strip_size_resync(), but it's good
2567 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2568 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2570 switch (get_imsm_raid_level(map
)) {
2573 if (map
->num_members
% map
->num_domains
== 0)
2574 return 128*1024 >> 9;
2578 return max((__u32
) 64*1024 >> 9, chunk
);
2580 return 128*1024 >> 9;
2584 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
2586 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2587 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2588 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
2589 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
2591 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
2594 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
2596 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2597 int level
= get_imsm_raid_level(lo
);
2599 if (level
== 1 || level
== 10) {
2600 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2602 return hi
->num_domains
;
2604 return num_stripes_per_unit_resync(dev
);
2607 static __u8
imsm_num_data_members(struct imsm_dev
*dev
, int second_map
)
2609 /* named 'imsm_' because raid0, raid1 and raid10
2610 * counter-intuitively have the same number of data disks
2612 struct imsm_map
*map
= get_imsm_map(dev
, second_map
);
2614 switch (get_imsm_raid_level(map
)) {
2616 return map
->num_members
;
2620 return map
->num_members
/2;
2622 return map
->num_members
- 1;
2624 dprintf("unsupported raid level\n");
2629 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
2631 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2632 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2634 switch(get_imsm_raid_level(map
)) {
2637 return chunk
* map
->num_domains
;
2639 return chunk
* map
->num_members
;
2645 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
2647 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2648 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2649 __u32 strip
= block
/ chunk
;
2651 switch (get_imsm_raid_level(map
)) {
2654 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
2655 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
2657 return vol_stripe
* chunk
+ block
% chunk
;
2659 __u32 stripe
= strip
/ (map
->num_members
- 1);
2661 return stripe
* chunk
+ block
% chunk
;
2668 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
2669 struct imsm_dev
*dev
)
2671 /* calculate the conversion factor between per member 'blocks'
2672 * (md/{resync,rebuild}_start) and imsm migration units, return
2673 * 0 for the 'not migrating' and 'unsupported migration' cases
2675 if (!dev
->vol
.migr_state
)
2678 switch (migr_type(dev
)) {
2679 case MIGR_GEN_MIGR
: {
2680 struct migr_record
*migr_rec
= super
->migr_rec
;
2681 return __le32_to_cpu(migr_rec
->blocks_per_unit
);
2686 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2687 __u32 stripes_per_unit
;
2688 __u32 blocks_per_unit
;
2697 /* yes, this is really the translation of migr_units to
2698 * per-member blocks in the 'resync' case
2700 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
2701 migr_chunk
= migr_strip_blocks_resync(dev
);
2702 disks
= imsm_num_data_members(dev
, MAP_0
);
2703 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
2704 stripe
= __le16_to_cpu(map
->blocks_per_strip
) * disks
;
2705 segment
= blocks_per_unit
/ stripe
;
2706 block_rel
= blocks_per_unit
- segment
* stripe
;
2707 parity_depth
= parity_segment_depth(dev
);
2708 block_map
= map_migr_block(dev
, block_rel
);
2709 return block_map
+ parity_depth
* segment
;
2711 case MIGR_REBUILD
: {
2712 __u32 stripes_per_unit
;
2715 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
2716 migr_chunk
= migr_strip_blocks_rebuild(dev
);
2717 return migr_chunk
* stripes_per_unit
;
2719 case MIGR_STATE_CHANGE
:
2725 static int imsm_level_to_layout(int level
)
2733 return ALGORITHM_LEFT_ASYMMETRIC
;
2740 /*******************************************************************************
2741 * Function: read_imsm_migr_rec
2742 * Description: Function reads imsm migration record from last sector of disk
2744 * fd : disk descriptor
2745 * super : metadata info
2749 ******************************************************************************/
2750 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
)
2753 unsigned int sector_size
= super
->sector_size
;
2754 unsigned long long dsize
;
2756 get_dev_size(fd
, NULL
, &dsize
);
2757 if (lseek64(fd
, dsize
- (sector_size
*MIGR_REC_SECTOR_POSITION
),
2759 pr_err("Cannot seek to anchor block: %s\n",
2763 if (read(fd
, super
->migr_rec_buf
,
2764 MIGR_REC_BUF_SECTORS
*sector_size
) !=
2765 MIGR_REC_BUF_SECTORS
*sector_size
) {
2766 pr_err("Cannot read migr record block: %s\n",
2771 if (sector_size
== 4096)
2772 convert_from_4k_imsm_migr_rec(super
);
2778 static struct imsm_dev
*imsm_get_device_during_migration(
2779 struct intel_super
*super
)
2782 struct intel_dev
*dv
;
2784 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
2785 if (is_gen_migration(dv
->dev
))
2791 /*******************************************************************************
2792 * Function: load_imsm_migr_rec
2793 * Description: Function reads imsm migration record (it is stored at the last
2796 * super : imsm internal array info
2797 * info : general array info
2801 * -2 : no migration in progress
2802 ******************************************************************************/
2803 static int load_imsm_migr_rec(struct intel_super
*super
, struct mdinfo
*info
)
2810 struct imsm_dev
*dev
;
2811 struct imsm_map
*map
;
2814 /* find map under migration */
2815 dev
= imsm_get_device_during_migration(super
);
2816 /* nothing to load,no migration in progress?
2822 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
2823 /* read only from one of the first two slots */
2824 if ((sd
->disk
.raid_disk
< 0) ||
2825 (sd
->disk
.raid_disk
> 1))
2828 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
2829 fd
= dev_open(nm
, O_RDONLY
);
2835 map
= get_imsm_map(dev
, MAP_0
);
2836 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
2837 /* skip spare and failed disks
2841 /* read only from one of the first two slots */
2843 slot
= get_imsm_disk_slot(map
, dl
->index
);
2844 if (map
== NULL
|| slot
> 1 || slot
< 0)
2846 sprintf(nm
, "%d:%d", dl
->major
, dl
->minor
);
2847 fd
= dev_open(nm
, O_RDONLY
);
2854 retval
= read_imsm_migr_rec(fd
, super
);
2863 /*******************************************************************************
2864 * function: imsm_create_metadata_checkpoint_update
2865 * Description: It creates update for checkpoint change.
2867 * super : imsm internal array info
2868 * u : pointer to prepared update
2871 * If length is equal to 0, input pointer u contains no update
2872 ******************************************************************************/
2873 static int imsm_create_metadata_checkpoint_update(
2874 struct intel_super
*super
,
2875 struct imsm_update_general_migration_checkpoint
**u
)
2878 int update_memory_size
= 0;
2880 dprintf("(enter)\n");
2886 /* size of all update data without anchor */
2887 update_memory_size
=
2888 sizeof(struct imsm_update_general_migration_checkpoint
);
2890 *u
= xcalloc(1, update_memory_size
);
2892 dprintf("error: cannot get memory\n");
2895 (*u
)->type
= update_general_migration_checkpoint
;
2896 (*u
)->curr_migr_unit
= __le32_to_cpu(super
->migr_rec
->curr_migr_unit
);
2897 dprintf("prepared for %u\n", (*u
)->curr_migr_unit
);
2899 return update_memory_size
;
2902 static void imsm_update_metadata_locally(struct supertype
*st
,
2903 void *buf
, int len
);
2905 /*******************************************************************************
2906 * Function: write_imsm_migr_rec
2907 * Description: Function writes imsm migration record
2908 * (at the last sector of disk)
2910 * super : imsm internal array info
2914 ******************************************************************************/
2915 static int write_imsm_migr_rec(struct supertype
*st
)
2917 struct intel_super
*super
= st
->sb
;
2918 unsigned int sector_size
= super
->sector_size
;
2919 unsigned long long dsize
;
2925 struct imsm_update_general_migration_checkpoint
*u
;
2926 struct imsm_dev
*dev
;
2927 struct imsm_map
*map
;
2929 /* find map under migration */
2930 dev
= imsm_get_device_during_migration(super
);
2931 /* if no migration, write buffer anyway to clear migr_record
2932 * on disk based on first available device
2935 dev
= get_imsm_dev(super
, super
->current_vol
< 0 ? 0 :
2936 super
->current_vol
);
2938 map
= get_imsm_map(dev
, MAP_0
);
2940 if (sector_size
== 4096)
2941 convert_to_4k_imsm_migr_rec(super
);
2942 for (sd
= super
->disks
; sd
; sd
= sd
->next
) {
2945 /* skip failed and spare devices */
2948 /* write to 2 first slots only */
2950 slot
= get_imsm_disk_slot(map
, sd
->index
);
2951 if (map
== NULL
|| slot
> 1 || slot
< 0)
2954 sprintf(nm
, "%d:%d", sd
->major
, sd
->minor
);
2955 fd
= dev_open(nm
, O_RDWR
);
2958 get_dev_size(fd
, NULL
, &dsize
);
2959 if (lseek64(fd
, dsize
- (MIGR_REC_SECTOR_POSITION
*sector_size
),
2961 pr_err("Cannot seek to anchor block: %s\n",
2965 if (write(fd
, super
->migr_rec_buf
,
2966 MIGR_REC_BUF_SECTORS
*sector_size
) !=
2967 MIGR_REC_BUF_SECTORS
*sector_size
) {
2968 pr_err("Cannot write migr record block: %s\n",
2975 if (sector_size
== 4096)
2976 convert_from_4k_imsm_migr_rec(super
);
2977 /* update checkpoint information in metadata */
2978 len
= imsm_create_metadata_checkpoint_update(super
, &u
);
2980 dprintf("imsm: Cannot prepare update\n");
2983 /* update metadata locally */
2984 imsm_update_metadata_locally(st
, u
, len
);
2985 /* and possibly remotely */
2986 if (st
->update_tail
) {
2987 append_metadata_update(st
, u
, len
);
2988 /* during reshape we do all work inside metadata handler
2989 * manage_reshape(), so metadata update has to be triggered
2992 flush_metadata_updates(st
);
2993 st
->update_tail
= &st
->updates
;
3003 #endif /* MDASSEMBLE */
3005 /* spare/missing disks activations are not allowe when
3006 * array/container performs reshape operation, because
3007 * all arrays in container works on the same disks set
3009 int imsm_reshape_blocks_arrays_changes(struct intel_super
*super
)
3012 struct intel_dev
*i_dev
;
3013 struct imsm_dev
*dev
;
3015 /* check whole container
3017 for (i_dev
= super
->devlist
; i_dev
; i_dev
= i_dev
->next
) {
3019 if (is_gen_migration(dev
)) {
3020 /* No repair during any migration in container
3028 static unsigned long long imsm_component_size_aligment_check(int level
,
3030 unsigned int sector_size
,
3031 unsigned long long component_size
)
3033 unsigned int component_size_alligment
;
3035 /* check component size aligment
3037 component_size_alligment
= component_size
% (chunk_size
/sector_size
);
3039 dprintf("(Level: %i, chunk_size = %i, component_size = %llu), component_size_alligment = %u\n",
3040 level
, chunk_size
, component_size
,
3041 component_size_alligment
);
3043 if (component_size_alligment
&& (level
!= 1) && (level
!= UnSet
)) {
3044 dprintf("imsm: reported component size alligned from %llu ",
3046 component_size
-= component_size_alligment
;
3047 dprintf_cont("to %llu (%i).\n",
3048 component_size
, component_size_alligment
);
3051 return component_size
;
3054 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
3056 struct intel_super
*super
= st
->sb
;
3057 struct migr_record
*migr_rec
= super
->migr_rec
;
3058 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
3059 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3060 struct imsm_map
*prev_map
= get_imsm_map(dev
, MAP_1
);
3061 struct imsm_map
*map_to_analyse
= map
;
3063 int map_disks
= info
->array
.raid_disks
;
3065 memset(info
, 0, sizeof(*info
));
3067 map_to_analyse
= prev_map
;
3069 dl
= super
->current_disk
;
3071 info
->container_member
= super
->current_vol
;
3072 info
->array
.raid_disks
= map
->num_members
;
3073 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
3074 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
3075 info
->array
.md_minor
= -1;
3076 info
->array
.ctime
= 0;
3077 info
->array
.utime
= 0;
3078 info
->array
.chunk_size
=
3079 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
3080 info
->array
.state
= !dev
->vol
.dirty
;
3081 info
->custom_array_size
= __le32_to_cpu(dev
->size_high
);
3082 info
->custom_array_size
<<= 32;
3083 info
->custom_array_size
|= __le32_to_cpu(dev
->size_low
);
3084 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
3086 if (is_gen_migration(dev
)) {
3087 info
->reshape_active
= 1;
3088 info
->new_level
= get_imsm_raid_level(map
);
3089 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
3090 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
3091 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
3092 if (info
->delta_disks
) {
3093 /* this needs to be applied to every array
3096 info
->reshape_active
= CONTAINER_RESHAPE
;
3098 /* We shape information that we give to md might have to be
3099 * modify to cope with md's requirement for reshaping arrays.
3100 * For example, when reshaping a RAID0, md requires it to be
3101 * presented as a degraded RAID4.
3102 * Also if a RAID0 is migrating to a RAID5 we need to specify
3103 * the array as already being RAID5, but the 'before' layout
3104 * is a RAID4-like layout.
3106 switch (info
->array
.level
) {
3108 switch(info
->new_level
) {
3110 /* conversion is happening as RAID4 */
3111 info
->array
.level
= 4;
3112 info
->array
.raid_disks
+= 1;
3115 /* conversion is happening as RAID5 */
3116 info
->array
.level
= 5;
3117 info
->array
.layout
= ALGORITHM_PARITY_N
;
3118 info
->delta_disks
-= 1;
3121 /* FIXME error message */
3122 info
->array
.level
= UnSet
;
3128 info
->new_level
= UnSet
;
3129 info
->new_layout
= UnSet
;
3130 info
->new_chunk
= info
->array
.chunk_size
;
3131 info
->delta_disks
= 0;
3135 info
->disk
.major
= dl
->major
;
3136 info
->disk
.minor
= dl
->minor
;
3137 info
->disk
.number
= dl
->index
;
3138 info
->disk
.raid_disk
= get_imsm_disk_slot(map_to_analyse
,
3142 info
->data_offset
= pba_of_lba0(map_to_analyse
);
3144 if (info
->array
.level
== 5) {
3145 info
->component_size
= num_data_stripes(map_to_analyse
) *
3146 map_to_analyse
->blocks_per_strip
;
3148 info
->component_size
= blocks_per_member(map_to_analyse
);
3151 info
->component_size
= imsm_component_size_aligment_check(
3153 info
->array
.chunk_size
,
3155 info
->component_size
);
3156 info
->bb
.supported
= 0;
3158 memset(info
->uuid
, 0, sizeof(info
->uuid
));
3159 info
->recovery_start
= MaxSector
;
3161 info
->reshape_progress
= 0;
3162 info
->resync_start
= MaxSector
;
3163 if ((map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
3165 imsm_reshape_blocks_arrays_changes(super
) == 0) {
3166 info
->resync_start
= 0;
3168 if (dev
->vol
.migr_state
) {
3169 switch (migr_type(dev
)) {
3172 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
3174 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
3176 info
->resync_start
= blocks_per_unit
* units
;
3179 case MIGR_GEN_MIGR
: {
3180 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
3182 __u64 units
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
3183 unsigned long long array_blocks
;
3186 if (__le32_to_cpu(migr_rec
->ascending_migr
) &&
3188 (__le32_to_cpu(migr_rec
->num_migr_units
)-1)) &&
3189 (super
->migr_rec
->rec_status
==
3190 __cpu_to_le32(UNIT_SRC_IN_CP_AREA
)))
3193 info
->reshape_progress
= blocks_per_unit
* units
;
3195 dprintf("IMSM: General Migration checkpoint : %llu (%llu) -> read reshape progress : %llu\n",
3196 (unsigned long long)units
,
3197 (unsigned long long)blocks_per_unit
,
3198 info
->reshape_progress
);
3200 used_disks
= imsm_num_data_members(dev
, MAP_1
);
3201 if (used_disks
> 0) {
3202 array_blocks
= blocks_per_member(map
) *
3204 /* round array size down to closest MB
3206 info
->custom_array_size
= (array_blocks
3207 >> SECT_PER_MB_SHIFT
)
3208 << SECT_PER_MB_SHIFT
;
3212 /* we could emulate the checkpointing of
3213 * 'sync_action=check' migrations, but for now
3214 * we just immediately complete them
3217 /* this is handled by container_content_imsm() */
3218 case MIGR_STATE_CHANGE
:
3219 /* FIXME handle other migrations */
3221 /* we are not dirty, so... */
3222 info
->resync_start
= MaxSector
;
3226 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
3227 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
3229 info
->array
.major_version
= -1;
3230 info
->array
.minor_version
= -2;
3231 sprintf(info
->text_version
, "/%s/%d", st
->container_devnm
, info
->container_member
);
3232 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
3233 uuid_from_super_imsm(st
, info
->uuid
);
3237 for (i
=0; i
<map_disks
; i
++) {
3239 if (i
< info
->array
.raid_disks
) {
3240 struct imsm_disk
*dsk
;
3241 j
= get_imsm_disk_idx(dev
, i
, MAP_X
);
3242 dsk
= get_imsm_disk(super
, j
);
3243 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
3250 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
3251 int failed
, int look_in_map
);
3253 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
3257 static void manage_second_map(struct intel_super
*super
, struct imsm_dev
*dev
)
3259 if (is_gen_migration(dev
)) {
3262 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
3264 failed
= imsm_count_failed(super
, dev
, MAP_1
);
3265 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_1
);
3266 if (map2
->map_state
!= map_state
) {
3267 map2
->map_state
= map_state
;
3268 super
->updates_pending
++;
3274 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
3278 for (d
= super
->missing
; d
; d
= d
->next
)
3279 if (d
->index
== index
)
3284 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
3286 struct intel_super
*super
= st
->sb
;
3287 struct imsm_disk
*disk
;
3288 int map_disks
= info
->array
.raid_disks
;
3289 int max_enough
= -1;
3291 struct imsm_super
*mpb
;
3293 if (super
->current_vol
>= 0) {
3294 getinfo_super_imsm_volume(st
, info
, map
);
3297 memset(info
, 0, sizeof(*info
));
3299 /* Set raid_disks to zero so that Assemble will always pull in valid
3302 info
->array
.raid_disks
= 0;
3303 info
->array
.level
= LEVEL_CONTAINER
;
3304 info
->array
.layout
= 0;
3305 info
->array
.md_minor
= -1;
3306 info
->array
.ctime
= 0; /* N/A for imsm */
3307 info
->array
.utime
= 0;
3308 info
->array
.chunk_size
= 0;
3310 info
->disk
.major
= 0;
3311 info
->disk
.minor
= 0;
3312 info
->disk
.raid_disk
= -1;
3313 info
->reshape_active
= 0;
3314 info
->array
.major_version
= -1;
3315 info
->array
.minor_version
= -2;
3316 strcpy(info
->text_version
, "imsm");
3317 info
->safe_mode_delay
= 0;
3318 info
->disk
.number
= -1;
3319 info
->disk
.state
= 0;
3321 info
->recovery_start
= MaxSector
;
3322 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
3323 info
->bb
.supported
= 0;
3325 /* do we have the all the insync disks that we expect? */
3326 mpb
= super
->anchor
;
3328 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
3329 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
3330 int failed
, enough
, j
, missing
= 0;
3331 struct imsm_map
*map
;
3334 failed
= imsm_count_failed(super
, dev
, MAP_0
);
3335 state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
3336 map
= get_imsm_map(dev
, MAP_0
);
3338 /* any newly missing disks?
3339 * (catches single-degraded vs double-degraded)
3341 for (j
= 0; j
< map
->num_members
; j
++) {
3342 __u32 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
3343 __u32 idx
= ord_to_idx(ord
);
3345 if (!(ord
& IMSM_ORD_REBUILD
) &&
3346 get_imsm_missing(super
, idx
)) {
3352 if (state
== IMSM_T_STATE_FAILED
)
3354 else if (state
== IMSM_T_STATE_DEGRADED
&&
3355 (state
!= map
->map_state
|| missing
))
3357 else /* we're normal, or already degraded */
3359 if (is_gen_migration(dev
) && missing
) {
3360 /* during general migration we need all disks
3361 * that process is running on.
3362 * No new missing disk is allowed.
3366 /* no more checks necessary
3370 /* in the missing/failed disk case check to see
3371 * if at least one array is runnable
3373 max_enough
= max(max_enough
, enough
);
3375 dprintf("enough: %d\n", max_enough
);
3376 info
->container_enough
= max_enough
;
3379 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
3381 disk
= &super
->disks
->disk
;
3382 info
->data_offset
= total_blocks(&super
->disks
->disk
) - reserved
;
3383 info
->component_size
= reserved
;
3384 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
3385 /* we don't change info->disk.raid_disk here because
3386 * this state will be finalized in mdmon after we have
3387 * found the 'most fresh' version of the metadata
3389 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
3390 info
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
3393 /* only call uuid_from_super_imsm when this disk is part of a populated container,
3394 * ->compare_super may have updated the 'num_raid_devs' field for spares
3396 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
3397 uuid_from_super_imsm(st
, info
->uuid
);
3399 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
3401 /* I don't know how to compute 'map' on imsm, so use safe default */
3404 for (i
= 0; i
< map_disks
; i
++)
3410 /* allocates memory and fills disk in mdinfo structure
3411 * for each disk in array */
3412 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
3414 struct mdinfo
*mddev
;
3415 struct intel_super
*super
= st
->sb
;
3416 struct imsm_disk
*disk
;
3419 if (!super
|| !super
->disks
)
3422 mddev
= xcalloc(1, sizeof(*mddev
));
3426 tmp
= xcalloc(1, sizeof(*tmp
));
3428 tmp
->next
= mddev
->devs
;
3430 tmp
->disk
.number
= count
++;
3431 tmp
->disk
.major
= dl
->major
;
3432 tmp
->disk
.minor
= dl
->minor
;
3433 tmp
->disk
.state
= is_configured(disk
) ?
3434 (1 << MD_DISK_ACTIVE
) : 0;
3435 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
3436 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
3437 tmp
->disk
.raid_disk
= -1;
3443 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
3444 char *update
, char *devname
, int verbose
,
3445 int uuid_set
, char *homehost
)
3447 /* For 'assemble' and 'force' we need to return non-zero if any
3448 * change was made. For others, the return value is ignored.
3449 * Update options are:
3450 * force-one : This device looks a bit old but needs to be included,
3451 * update age info appropriately.
3452 * assemble: clear any 'faulty' flag to allow this device to
3454 * force-array: Array is degraded but being forced, mark it clean
3455 * if that will be needed to assemble it.
3457 * newdev: not used ????
3458 * grow: Array has gained a new device - this is currently for
3460 * resync: mark as dirty so a resync will happen.
3461 * name: update the name - preserving the homehost
3462 * uuid: Change the uuid of the array to match watch is given
3464 * Following are not relevant for this imsm:
3465 * sparc2.2 : update from old dodgey metadata
3466 * super-minor: change the preferred_minor number
3467 * summaries: update redundant counters.
3468 * homehost: update the recorded homehost
3469 * _reshape_progress: record new reshape_progress position.
3472 struct intel_super
*super
= st
->sb
;
3473 struct imsm_super
*mpb
;
3475 /* we can only update container info */
3476 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
3479 mpb
= super
->anchor
;
3481 if (strcmp(update
, "uuid") == 0) {
3482 /* We take this to mean that the family_num should be updated.
3483 * However that is much smaller than the uuid so we cannot really
3484 * allow an explicit uuid to be given. And it is hard to reliably
3486 * So if !uuid_set we know the current uuid is random and just used
3487 * the first 'int' and copy it to the other 3 positions.
3488 * Otherwise we require the 4 'int's to be the same as would be the
3489 * case if we are using a random uuid. So an explicit uuid will be
3490 * accepted as long as all for ints are the same... which shouldn't hurt
3493 info
->uuid
[1] = info
->uuid
[2] = info
->uuid
[3] = info
->uuid
[0];
3496 if (info
->uuid
[0] != info
->uuid
[1] ||
3497 info
->uuid
[1] != info
->uuid
[2] ||
3498 info
->uuid
[2] != info
->uuid
[3])
3504 mpb
->orig_family_num
= info
->uuid
[0];
3505 } else if (strcmp(update
, "assemble") == 0)
3510 /* successful update? recompute checksum */
3512 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
3517 static size_t disks_to_mpb_size(int disks
)
3521 size
= sizeof(struct imsm_super
);
3522 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
3523 size
+= 2 * sizeof(struct imsm_dev
);
3524 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
3525 size
+= (4 - 2) * sizeof(struct imsm_map
);
3526 /* 4 possible disk_ord_tbl's */
3527 size
+= 4 * (disks
- 1) * sizeof(__u32
);
3528 /* maximum bbm log */
3529 size
+= sizeof(struct bbm_log
);
3534 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
,
3535 unsigned long long data_offset
)
3537 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
3540 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
3543 static void free_devlist(struct intel_super
*super
)
3545 struct intel_dev
*dv
;
3547 while (super
->devlist
) {
3548 dv
= super
->devlist
->next
;
3549 free(super
->devlist
->dev
);
3550 free(super
->devlist
);
3551 super
->devlist
= dv
;
3555 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
3557 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
3560 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
)
3564 * 0 same, or first was empty, and second was copied
3565 * 1 second had wrong number
3567 * 3 wrong other info
3569 struct intel_super
*first
= st
->sb
;
3570 struct intel_super
*sec
= tst
->sb
;
3577 /* in platform dependent environment test if the disks
3578 * use the same Intel hba
3579 * If not on Intel hba at all, allow anything.
3581 if (!check_env("IMSM_NO_PLATFORM") && first
->hba
&& sec
->hba
) {
3582 if (first
->hba
->type
!= sec
->hba
->type
) {
3584 "HBAs of devices do not match %s != %s\n",
3585 get_sys_dev_type(first
->hba
->type
),
3586 get_sys_dev_type(sec
->hba
->type
));
3589 if (first
->orom
!= sec
->orom
) {
3591 "HBAs of devices do not match %s != %s\n",
3592 first
->hba
->pci_id
, sec
->hba
->pci_id
);
3597 /* if an anchor does not have num_raid_devs set then it is a free
3600 if (first
->anchor
->num_raid_devs
> 0 &&
3601 sec
->anchor
->num_raid_devs
> 0) {
3602 /* Determine if these disks might ever have been
3603 * related. Further disambiguation can only take place
3604 * in load_super_imsm_all
3606 __u32 first_family
= first
->anchor
->orig_family_num
;
3607 __u32 sec_family
= sec
->anchor
->orig_family_num
;
3609 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
3610 MAX_SIGNATURE_LENGTH
) != 0)
3613 if (first_family
== 0)
3614 first_family
= first
->anchor
->family_num
;
3615 if (sec_family
== 0)
3616 sec_family
= sec
->anchor
->family_num
;
3618 if (first_family
!= sec_family
)
3623 /* if 'first' is a spare promote it to a populated mpb with sec's
3626 if (first
->anchor
->num_raid_devs
== 0 &&
3627 sec
->anchor
->num_raid_devs
> 0) {
3629 struct intel_dev
*dv
;
3630 struct imsm_dev
*dev
;
3632 /* we need to copy raid device info from sec if an allocation
3633 * fails here we don't associate the spare
3635 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++) {
3636 dv
= xmalloc(sizeof(*dv
));
3637 dev
= xmalloc(sizeof_imsm_dev(get_imsm_dev(sec
, i
), 1));
3640 dv
->next
= first
->devlist
;
3641 first
->devlist
= dv
;
3643 if (i
< sec
->anchor
->num_raid_devs
) {
3644 /* allocation failure */
3645 free_devlist(first
);
3646 pr_err("imsm: failed to associate spare\n");
3649 first
->anchor
->num_raid_devs
= sec
->anchor
->num_raid_devs
;
3650 first
->anchor
->orig_family_num
= sec
->anchor
->orig_family_num
;
3651 first
->anchor
->family_num
= sec
->anchor
->family_num
;
3652 memcpy(first
->anchor
->sig
, sec
->anchor
->sig
, MAX_SIGNATURE_LENGTH
);
3653 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++)
3654 imsm_copy_dev(get_imsm_dev(first
, i
), get_imsm_dev(sec
, i
));
3660 static void fd2devname(int fd
, char *name
)
3664 char dname
[PATH_MAX
];
3669 if (fstat(fd
, &st
) != 0)
3671 sprintf(path
, "/sys/dev/block/%d:%d",
3672 major(st
.st_rdev
), minor(st
.st_rdev
));
3674 rv
= readlink(path
, dname
, sizeof(dname
)-1);
3679 nm
= strrchr(dname
, '/');
3682 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
3686 static int nvme_get_serial(int fd
, void *buf
, size_t buf_len
)
3689 char *name
= fd2kname(fd
);
3694 if (strncmp(name
, "nvme", 4) != 0)
3697 snprintf(path
, sizeof(path
) - 1, "/sys/block/%s/device/serial", name
);
3699 return load_sys(path
, buf
, buf_len
);
3702 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
3704 static int imsm_read_serial(int fd
, char *devname
,
3705 __u8 serial
[MAX_RAID_SERIAL_LEN
])
3714 memset(buf
, 0, sizeof(buf
));
3716 rv
= nvme_get_serial(fd
, buf
, sizeof(buf
));
3719 rv
= scsi_get_serial(fd
, buf
, sizeof(buf
));
3721 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
3722 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3723 fd2devname(fd
, (char *) serial
);
3729 pr_err("Failed to retrieve serial for %s\n",
3734 /* trim all whitespace and non-printable characters and convert
3737 for (i
= 0, dest
= buf
; i
< sizeof(buf
) && buf
[i
]; i
++) {
3740 /* ':' is reserved for use in placeholder serial
3741 * numbers for missing disks
3752 /* truncate leading characters */
3753 if (len
> MAX_RAID_SERIAL_LEN
) {
3754 dest
+= len
- MAX_RAID_SERIAL_LEN
;
3755 len
= MAX_RAID_SERIAL_LEN
;
3758 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3759 memcpy(serial
, dest
, len
);
3764 static int serialcmp(__u8
*s1
, __u8
*s2
)
3766 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
3769 static void serialcpy(__u8
*dest
, __u8
*src
)
3771 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
3774 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
3778 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3779 if (serialcmp(dl
->serial
, serial
) == 0)
3785 static struct imsm_disk
*
3786 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
3790 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3791 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
3793 if (serialcmp(disk
->serial
, serial
) == 0) {
3804 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3806 struct imsm_disk
*disk
;
3811 __u8 serial
[MAX_RAID_SERIAL_LEN
];
3813 rv
= imsm_read_serial(fd
, devname
, serial
);
3818 dl
= xcalloc(1, sizeof(*dl
));
3821 dl
->major
= major(stb
.st_rdev
);
3822 dl
->minor
= minor(stb
.st_rdev
);
3823 dl
->next
= super
->disks
;
3824 dl
->fd
= keep_fd
? fd
: -1;
3825 assert(super
->disks
== NULL
);
3827 serialcpy(dl
->serial
, serial
);
3830 fd2devname(fd
, name
);
3832 dl
->devname
= xstrdup(devname
);
3834 dl
->devname
= xstrdup(name
);
3836 /* look up this disk's index in the current anchor */
3837 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
3840 /* only set index on disks that are a member of a
3841 * populated contianer, i.e. one with raid_devs
3843 if (is_failed(&dl
->disk
))
3845 else if (is_spare(&dl
->disk
))
3853 /* When migrating map0 contains the 'destination' state while map1
3854 * contains the current state. When not migrating map0 contains the
3855 * current state. This routine assumes that map[0].map_state is set to
3856 * the current array state before being called.
3858 * Migration is indicated by one of the following states
3859 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
3860 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
3861 * map1state=unitialized)
3862 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
3864 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
3865 * map1state=degraded)
3866 * 5/ Migration (mig_state=1 migr_type=MIGR_GEN_MIGR map0state=normal
3869 static void migrate(struct imsm_dev
*dev
, struct intel_super
*super
,
3870 __u8 to_state
, int migr_type
)
3872 struct imsm_map
*dest
;
3873 struct imsm_map
*src
= get_imsm_map(dev
, MAP_0
);
3875 dev
->vol
.migr_state
= 1;
3876 set_migr_type(dev
, migr_type
);
3877 dev
->vol
.curr_migr_unit
= 0;
3878 dest
= get_imsm_map(dev
, MAP_1
);
3880 /* duplicate and then set the target end state in map[0] */
3881 memcpy(dest
, src
, sizeof_imsm_map(src
));
3882 if (migr_type
== MIGR_REBUILD
|| migr_type
== MIGR_GEN_MIGR
) {
3886 for (i
= 0; i
< src
->num_members
; i
++) {
3887 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
3888 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
3892 if (migr_type
== MIGR_GEN_MIGR
)
3893 /* Clear migration record */
3894 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
3896 src
->map_state
= to_state
;
3899 static void end_migration(struct imsm_dev
*dev
, struct intel_super
*super
,
3902 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3903 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
== 0 ?
3907 /* merge any IMSM_ORD_REBUILD bits that were not successfully
3908 * completed in the last migration.
3910 * FIXME add support for raid-level-migration
3912 if (map_state
!= map
->map_state
&& (is_gen_migration(dev
) == 0) &&
3913 prev
->map_state
!= IMSM_T_STATE_UNINITIALIZED
) {
3914 /* when final map state is other than expected
3915 * merge maps (not for migration)
3919 for (i
= 0; i
< prev
->num_members
; i
++)
3920 for (j
= 0; j
< map
->num_members
; j
++)
3921 /* during online capacity expansion
3922 * disks position can be changed
3923 * if takeover is used
3925 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
3926 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
3927 map
->disk_ord_tbl
[j
] |=
3928 prev
->disk_ord_tbl
[i
];
3931 failed
= imsm_count_failed(super
, dev
, MAP_0
);
3932 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
3935 dev
->vol
.migr_state
= 0;
3936 set_migr_type(dev
, 0);
3937 dev
->vol
.curr_migr_unit
= 0;
3938 map
->map_state
= map_state
;
3942 static int parse_raid_devices(struct intel_super
*super
)
3945 struct imsm_dev
*dev_new
;
3946 size_t len
, len_migr
;
3948 size_t space_needed
= 0;
3949 struct imsm_super
*mpb
= super
->anchor
;
3951 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3952 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3953 struct intel_dev
*dv
;
3955 len
= sizeof_imsm_dev(dev_iter
, 0);
3956 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
3958 space_needed
+= len_migr
- len
;
3960 dv
= xmalloc(sizeof(*dv
));
3961 if (max_len
< len_migr
)
3963 if (max_len
> len_migr
)
3964 space_needed
+= max_len
- len_migr
;
3965 dev_new
= xmalloc(max_len
);
3966 imsm_copy_dev(dev_new
, dev_iter
);
3969 dv
->next
= super
->devlist
;
3970 super
->devlist
= dv
;
3973 /* ensure that super->buf is large enough when all raid devices
3976 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
3979 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
,
3980 super
->sector_size
);
3981 if (posix_memalign(&buf
, MAX_SECTOR_SIZE
, len
) != 0)
3984 memcpy(buf
, super
->buf
, super
->len
);
3985 memset(buf
+ super
->len
, 0, len
- super
->len
);
3991 super
->extra_space
+= space_needed
;
3996 /*******************************************************************************
3997 * Function: check_mpb_migr_compatibility
3998 * Description: Function checks for unsupported migration features:
3999 * - migration optimization area (pba_of_lba0)
4000 * - descending reshape (ascending_migr)
4002 * super : imsm metadata information
4004 * 0 : migration is compatible
4005 * -1 : migration is not compatible
4006 ******************************************************************************/
4007 int check_mpb_migr_compatibility(struct intel_super
*super
)
4009 struct imsm_map
*map0
, *map1
;
4010 struct migr_record
*migr_rec
= super
->migr_rec
;
4013 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
4014 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
4017 dev_iter
->vol
.migr_state
== 1 &&
4018 dev_iter
->vol
.migr_type
== MIGR_GEN_MIGR
) {
4019 /* This device is migrating */
4020 map0
= get_imsm_map(dev_iter
, MAP_0
);
4021 map1
= get_imsm_map(dev_iter
, MAP_1
);
4022 if (pba_of_lba0(map0
) != pba_of_lba0(map1
))
4023 /* migration optimization area was used */
4025 if (migr_rec
->ascending_migr
== 0
4026 && migr_rec
->dest_depth_per_unit
> 0)
4027 /* descending reshape not supported yet */
4034 static void __free_imsm(struct intel_super
*super
, int free_disks
);
4036 /* load_imsm_mpb - read matrix metadata
4037 * allocates super->mpb to be freed by free_imsm
4039 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
4041 unsigned long long dsize
;
4042 unsigned long long sectors
;
4043 unsigned int sector_size
= super
->sector_size
;
4045 struct imsm_super
*anchor
;
4048 get_dev_size(fd
, NULL
, &dsize
);
4049 if (dsize
< 2*sector_size
) {
4051 pr_err("%s: device to small for imsm\n",
4056 if (lseek64(fd
, dsize
- (sector_size
* 2), SEEK_SET
) < 0) {
4058 pr_err("Cannot seek to anchor block on %s: %s\n",
4059 devname
, strerror(errno
));
4063 if (posix_memalign((void **)&anchor
, sector_size
, sector_size
) != 0) {
4065 pr_err("Failed to allocate imsm anchor buffer on %s\n", devname
);
4068 if (read(fd
, anchor
, sector_size
) != sector_size
) {
4070 pr_err("Cannot read anchor block on %s: %s\n",
4071 devname
, strerror(errno
));
4076 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
4078 pr_err("no IMSM anchor on %s\n", devname
);
4083 __free_imsm(super
, 0);
4084 /* reload capability and hba */
4086 /* capability and hba must be updated with new super allocation */
4087 find_intel_hba_capability(fd
, super
, devname
);
4088 super
->len
= ROUND_UP(anchor
->mpb_size
, sector_size
);
4089 if (posix_memalign(&super
->buf
, MAX_SECTOR_SIZE
, super
->len
) != 0) {
4091 pr_err("unable to allocate %zu byte mpb buffer\n",
4096 memcpy(super
->buf
, anchor
, sector_size
);
4098 sectors
= mpb_sectors(anchor
, sector_size
) - 1;
4101 if (posix_memalign(&super
->migr_rec_buf
, sector_size
,
4102 MIGR_REC_BUF_SECTORS
*sector_size
) != 0) {
4103 pr_err("could not allocate migr_rec buffer\n");
4107 super
->clean_migration_record_by_mdmon
= 0;
4110 check_sum
= __gen_imsm_checksum(super
->anchor
);
4111 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
4113 pr_err("IMSM checksum %x != %x on %s\n",
4115 __le32_to_cpu(super
->anchor
->check_sum
),
4123 /* read the extended mpb */
4124 if (lseek64(fd
, dsize
- (sector_size
* (2 + sectors
)), SEEK_SET
) < 0) {
4126 pr_err("Cannot seek to extended mpb on %s: %s\n",
4127 devname
, strerror(errno
));
4131 if ((unsigned int)read(fd
, super
->buf
+ sector_size
,
4132 super
->len
- sector_size
) != super
->len
- sector_size
) {
4134 pr_err("Cannot read extended mpb on %s: %s\n",
4135 devname
, strerror(errno
));
4139 check_sum
= __gen_imsm_checksum(super
->anchor
);
4140 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
4142 pr_err("IMSM checksum %x != %x on %s\n",
4143 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
4151 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
);
4153 /* clears hi bits in metadata if MPB_ATTRIB_2TB_DISK not set */
4154 static void clear_hi(struct intel_super
*super
)
4156 struct imsm_super
*mpb
= super
->anchor
;
4158 if (mpb
->attributes
& MPB_ATTRIB_2TB_DISK
)
4160 for (i
= 0; i
< mpb
->num_disks
; ++i
) {
4161 struct imsm_disk
*disk
= &mpb
->disk
[i
];
4162 disk
->total_blocks_hi
= 0;
4164 for (i
= 0; i
< mpb
->num_raid_devs
; ++i
) {
4165 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
4168 for (n
= 0; n
< 2; ++n
) {
4169 struct imsm_map
*map
= get_imsm_map(dev
, n
);
4172 map
->pba_of_lba0_hi
= 0;
4173 map
->blocks_per_member_hi
= 0;
4174 map
->num_data_stripes_hi
= 0;
4180 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
4184 err
= load_imsm_mpb(fd
, super
, devname
);
4187 if (super
->sector_size
== 4096)
4188 convert_from_4k(super
);
4189 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
4192 err
= parse_raid_devices(super
);
4195 err
= load_bbm_log(super
);
4200 static void __free_imsm_disk(struct dl
*d
)
4212 static void free_imsm_disks(struct intel_super
*super
)
4216 while (super
->disks
) {
4218 super
->disks
= d
->next
;
4219 __free_imsm_disk(d
);
4221 while (super
->disk_mgmt_list
) {
4222 d
= super
->disk_mgmt_list
;
4223 super
->disk_mgmt_list
= d
->next
;
4224 __free_imsm_disk(d
);
4226 while (super
->missing
) {
4228 super
->missing
= d
->next
;
4229 __free_imsm_disk(d
);
4234 /* free all the pieces hanging off of a super pointer */
4235 static void __free_imsm(struct intel_super
*super
, int free_disks
)
4237 struct intel_hba
*elem
, *next
;
4243 /* unlink capability description */
4245 if (super
->migr_rec_buf
) {
4246 free(super
->migr_rec_buf
);
4247 super
->migr_rec_buf
= NULL
;
4250 free_imsm_disks(super
);
4251 free_devlist(super
);
4255 free((void *)elem
->path
);
4261 free(super
->bbm_log
);
4265 static void free_imsm(struct intel_super
*super
)
4267 __free_imsm(super
, 1);
4271 static void free_super_imsm(struct supertype
*st
)
4273 struct intel_super
*super
= st
->sb
;
4282 static struct intel_super
*alloc_super(void)
4284 struct intel_super
*super
= xcalloc(1, sizeof(*super
));
4286 super
->current_vol
= -1;
4287 super
->create_offset
= ~((unsigned long long) 0);
4292 * find and allocate hba and OROM/EFI based on valid fd of RAID component device
4294 static int find_intel_hba_capability(int fd
, struct intel_super
*super
, char *devname
)
4296 struct sys_dev
*hba_name
;
4299 if (fd
< 0 || check_env("IMSM_NO_PLATFORM")) {
4304 hba_name
= find_disk_attached_hba(fd
, NULL
);
4307 pr_err("%s is not attached to Intel(R) RAID controller.\n",
4311 rv
= attach_hba_to_super(super
, hba_name
);
4314 struct intel_hba
*hba
= super
->hba
;
4316 pr_err("%s is attached to Intel(R) %s %s (%s),\n"
4317 " but the container is assigned to Intel(R) %s %s (",
4319 get_sys_dev_type(hba_name
->type
),
4320 hba_name
->type
== SYS_DEV_VMD
? "domain" : "RAID controller",
4321 hba_name
->pci_id
? : "Err!",
4322 get_sys_dev_type(super
->hba
->type
),
4323 hba
->type
== SYS_DEV_VMD
? "domain" : "RAID controller");
4326 fprintf(stderr
, "%s", hba
->pci_id
? : "Err!");
4328 fprintf(stderr
, ", ");
4331 fprintf(stderr
, ").\n"
4332 " Mixing devices attached to different %s is not allowed.\n",
4333 hba_name
->type
== SYS_DEV_VMD
? "VMD domains" : "controllers");
4337 super
->orom
= find_imsm_capability(hba_name
);
4344 /* find_missing - helper routine for load_super_imsm_all that identifies
4345 * disks that have disappeared from the system. This routine relies on
4346 * the mpb being uptodate, which it is at load time.
4348 static int find_missing(struct intel_super
*super
)
4351 struct imsm_super
*mpb
= super
->anchor
;
4353 struct imsm_disk
*disk
;
4355 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4356 disk
= __get_imsm_disk(mpb
, i
);
4357 dl
= serial_to_dl(disk
->serial
, super
);
4361 dl
= xmalloc(sizeof(*dl
));
4365 dl
->devname
= xstrdup("missing");
4367 serialcpy(dl
->serial
, disk
->serial
);
4370 dl
->next
= super
->missing
;
4371 super
->missing
= dl
;
4378 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
4380 struct intel_disk
*idisk
= disk_list
;
4383 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
4385 idisk
= idisk
->next
;
4391 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
4392 struct intel_super
*super
,
4393 struct intel_disk
**disk_list
)
4395 struct imsm_disk
*d
= &super
->disks
->disk
;
4396 struct imsm_super
*mpb
= super
->anchor
;
4399 for (i
= 0; i
< tbl_size
; i
++) {
4400 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
4401 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
4403 if (tbl_mpb
->family_num
== mpb
->family_num
) {
4404 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
4405 dprintf("mpb from %d:%d matches %d:%d\n",
4406 super
->disks
->major
,
4407 super
->disks
->minor
,
4408 table
[i
]->disks
->major
,
4409 table
[i
]->disks
->minor
);
4413 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
4414 is_configured(d
) == is_configured(tbl_d
)) &&
4415 tbl_mpb
->generation_num
< mpb
->generation_num
) {
4416 /* current version of the mpb is a
4417 * better candidate than the one in
4418 * super_table, but copy over "cross
4419 * generational" status
4421 struct intel_disk
*idisk
;
4423 dprintf("mpb from %d:%d replaces %d:%d\n",
4424 super
->disks
->major
,
4425 super
->disks
->minor
,
4426 table
[i
]->disks
->major
,
4427 table
[i
]->disks
->minor
);
4429 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
4430 if (idisk
&& is_failed(&idisk
->disk
))
4431 tbl_d
->status
|= FAILED_DISK
;
4434 struct intel_disk
*idisk
;
4435 struct imsm_disk
*disk
;
4437 /* tbl_mpb is more up to date, but copy
4438 * over cross generational status before
4441 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
4442 if (disk
&& is_failed(disk
))
4443 d
->status
|= FAILED_DISK
;
4445 idisk
= disk_list_get(d
->serial
, *disk_list
);
4448 if (disk
&& is_configured(disk
))
4449 idisk
->disk
.status
|= CONFIGURED_DISK
;
4452 dprintf("mpb from %d:%d prefer %d:%d\n",
4453 super
->disks
->major
,
4454 super
->disks
->minor
,
4455 table
[i
]->disks
->major
,
4456 table
[i
]->disks
->minor
);
4464 table
[tbl_size
++] = super
;
4468 /* update/extend the merged list of imsm_disk records */
4469 for (j
= 0; j
< mpb
->num_disks
; j
++) {
4470 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
4471 struct intel_disk
*idisk
;
4473 idisk
= disk_list_get(disk
->serial
, *disk_list
);
4475 idisk
->disk
.status
|= disk
->status
;
4476 if (is_configured(&idisk
->disk
) ||
4477 is_failed(&idisk
->disk
))
4478 idisk
->disk
.status
&= ~(SPARE_DISK
);
4480 idisk
= xcalloc(1, sizeof(*idisk
));
4481 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
4482 idisk
->disk
= *disk
;
4483 idisk
->next
= *disk_list
;
4487 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
4494 static struct intel_super
*
4495 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
4498 struct imsm_super
*mpb
= super
->anchor
;
4502 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4503 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
4504 struct intel_disk
*idisk
;
4506 idisk
= disk_list_get(disk
->serial
, disk_list
);
4508 if (idisk
->owner
== owner
||
4509 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
4512 dprintf("'%.16s' owner %d != %d\n",
4513 disk
->serial
, idisk
->owner
,
4516 dprintf("unknown disk %x [%d]: %.16s\n",
4517 __le32_to_cpu(mpb
->family_num
), i
,
4523 if (ok_count
== mpb
->num_disks
)
4528 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
4530 struct intel_super
*s
;
4532 for (s
= super_list
; s
; s
= s
->next
) {
4533 if (family_num
!= s
->anchor
->family_num
)
4535 pr_err("Conflict, offlining family %#x on '%s'\n",
4536 __le32_to_cpu(family_num
), s
->disks
->devname
);
4540 static struct intel_super
*
4541 imsm_thunderdome(struct intel_super
**super_list
, int len
)
4543 struct intel_super
*super_table
[len
];
4544 struct intel_disk
*disk_list
= NULL
;
4545 struct intel_super
*champion
, *spare
;
4546 struct intel_super
*s
, **del
;
4551 memset(super_table
, 0, sizeof(super_table
));
4552 for (s
= *super_list
; s
; s
= s
->next
)
4553 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
4555 for (i
= 0; i
< tbl_size
; i
++) {
4556 struct imsm_disk
*d
;
4557 struct intel_disk
*idisk
;
4558 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
4561 d
= &s
->disks
->disk
;
4563 /* 'd' must appear in merged disk list for its
4564 * configuration to be valid
4566 idisk
= disk_list_get(d
->serial
, disk_list
);
4567 if (idisk
&& idisk
->owner
== i
)
4568 s
= validate_members(s
, disk_list
, i
);
4573 dprintf("marking family: %#x from %d:%d offline\n",
4575 super_table
[i
]->disks
->major
,
4576 super_table
[i
]->disks
->minor
);
4580 /* This is where the mdadm implementation differs from the Windows
4581 * driver which has no strict concept of a container. We can only
4582 * assemble one family from a container, so when returning a prodigal
4583 * array member to this system the code will not be able to disambiguate
4584 * the container contents that should be assembled ("foreign" versus
4585 * "local"). It requires user intervention to set the orig_family_num
4586 * to a new value to establish a new container. The Windows driver in
4587 * this situation fixes up the volume name in place and manages the
4588 * foreign array as an independent entity.
4593 for (i
= 0; i
< tbl_size
; i
++) {
4594 struct intel_super
*tbl_ent
= super_table
[i
];
4600 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
4605 if (s
&& !is_spare
) {
4606 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
4608 } else if (!s
&& !is_spare
)
4621 pr_err("Chose family %#x on '%s', assemble conflicts to new container with '--update=uuid'\n",
4622 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
4624 /* collect all dl's onto 'champion', and update them to
4625 * champion's version of the status
4627 for (s
= *super_list
; s
; s
= s
->next
) {
4628 struct imsm_super
*mpb
= champion
->anchor
;
4629 struct dl
*dl
= s
->disks
;
4634 mpb
->attributes
|= s
->anchor
->attributes
& MPB_ATTRIB_2TB_DISK
;
4636 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4637 struct imsm_disk
*disk
;
4639 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
4642 /* only set index on disks that are a member of
4643 * a populated contianer, i.e. one with
4646 if (is_failed(&dl
->disk
))
4648 else if (is_spare(&dl
->disk
))
4654 if (i
>= mpb
->num_disks
) {
4655 struct intel_disk
*idisk
;
4657 idisk
= disk_list_get(dl
->serial
, disk_list
);
4658 if (idisk
&& is_spare(&idisk
->disk
) &&
4659 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
4667 dl
->next
= champion
->disks
;
4668 champion
->disks
= dl
;
4672 /* delete 'champion' from super_list */
4673 for (del
= super_list
; *del
; ) {
4674 if (*del
== champion
) {
4675 *del
= (*del
)->next
;
4678 del
= &(*del
)->next
;
4680 champion
->next
= NULL
;
4684 struct intel_disk
*idisk
= disk_list
;
4686 disk_list
= disk_list
->next
;
4694 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
);
4695 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4696 int major
, int minor
, int keep_fd
);
4698 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4699 int *max
, int keep_fd
);
4701 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
4702 char *devname
, struct md_list
*devlist
,
4705 struct intel_super
*super_list
= NULL
;
4706 struct intel_super
*super
= NULL
;
4711 /* 'fd' is an opened container */
4712 err
= get_sra_super_block(fd
, &super_list
, devname
, &i
, keep_fd
);
4714 /* get super block from devlist devices */
4715 err
= get_devlist_super_block(devlist
, &super_list
, &i
, keep_fd
);
4718 /* all mpbs enter, maybe one leaves */
4719 super
= imsm_thunderdome(&super_list
, i
);
4725 if (find_missing(super
) != 0) {
4731 /* load migration record */
4732 err
= load_imsm_migr_rec(super
, NULL
);
4734 /* migration is in progress,
4735 * but migr_rec cannot be loaded,
4741 /* Check migration compatibility */
4742 if (err
== 0 && check_mpb_migr_compatibility(super
) != 0) {
4743 pr_err("Unsupported migration detected");
4745 fprintf(stderr
, " on %s\n", devname
);
4747 fprintf(stderr
, " (IMSM).\n");
4756 while (super_list
) {
4757 struct intel_super
*s
= super_list
;
4759 super_list
= super_list
->next
;
4768 strcpy(st
->container_devnm
, fd2devnm(fd
));
4770 st
->container_devnm
[0] = 0;
4771 if (err
== 0 && st
->ss
== NULL
) {
4772 st
->ss
= &super_imsm
;
4773 st
->minor_version
= 0;
4774 st
->max_devs
= IMSM_MAX_DEVICES
;
4780 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4781 int *max
, int keep_fd
)
4783 struct md_list
*tmpdev
;
4787 for (i
= 0, tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
4788 if (tmpdev
->used
!= 1)
4790 if (tmpdev
->container
== 1) {
4792 int fd
= dev_open(tmpdev
->devname
, O_RDONLY
|O_EXCL
);
4794 pr_err("cannot open device %s: %s\n",
4795 tmpdev
->devname
, strerror(errno
));
4799 err
= get_sra_super_block(fd
, super_list
,
4800 tmpdev
->devname
, &lmax
,
4809 int major
= major(tmpdev
->st_rdev
);
4810 int minor
= minor(tmpdev
->st_rdev
);
4811 err
= get_super_block(super_list
,
4828 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4829 int major
, int minor
, int keep_fd
)
4831 struct intel_super
*s
;
4843 sprintf(nm
, "%d:%d", major
, minor
);
4844 dfd
= dev_open(nm
, O_RDWR
);
4850 get_dev_sector_size(dfd
, NULL
, &s
->sector_size
);
4851 find_intel_hba_capability(dfd
, s
, devname
);
4852 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
4854 /* retry the load if we might have raced against mdmon */
4855 if (err
== 3 && devnm
&& mdmon_running(devnm
))
4856 for (retry
= 0; retry
< 3; retry
++) {
4858 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
4864 s
->next
= *super_list
;
4872 if (dfd
>= 0 && !keep_fd
)
4879 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
)
4886 sra
= sysfs_read(fd
, NULL
, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
4890 if (sra
->array
.major_version
!= -1 ||
4891 sra
->array
.minor_version
!= -2 ||
4892 strcmp(sra
->text_version
, "imsm") != 0) {
4897 devnm
= fd2devnm(fd
);
4898 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
4899 if (get_super_block(super_list
, devnm
, devname
,
4900 sd
->disk
.major
, sd
->disk
.minor
, keep_fd
) != 0) {
4911 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
4913 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
, NULL
, 1);
4917 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
4919 struct intel_super
*super
;
4923 if (test_partition(fd
))
4924 /* IMSM not allowed on partitions */
4927 free_super_imsm(st
);
4929 super
= alloc_super();
4930 get_dev_sector_size(fd
, NULL
, &super
->sector_size
);
4933 /* Load hba and capabilities if they exist.
4934 * But do not preclude loading metadata in case capabilities or hba are
4935 * non-compliant and ignore_hw_compat is set.
4937 rv
= find_intel_hba_capability(fd
, super
, devname
);
4938 /* no orom/efi or non-intel hba of the disk */
4939 if (rv
!= 0 && st
->ignore_hw_compat
== 0) {
4941 pr_err("No OROM/EFI properties for %s\n", devname
);
4945 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
4947 /* retry the load if we might have raced against mdmon */
4949 struct mdstat_ent
*mdstat
= NULL
;
4950 char *name
= fd2kname(fd
);
4953 mdstat
= mdstat_by_component(name
);
4955 if (mdstat
&& mdmon_running(mdstat
->devnm
) && getpid() != mdmon_pid(mdstat
->devnm
)) {
4956 for (retry
= 0; retry
< 3; retry
++) {
4958 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
4964 free_mdstat(mdstat
);
4969 pr_err("Failed to load all information sections on %s\n", devname
);
4975 if (st
->ss
== NULL
) {
4976 st
->ss
= &super_imsm
;
4977 st
->minor_version
= 0;
4978 st
->max_devs
= IMSM_MAX_DEVICES
;
4981 /* load migration record */
4982 if (load_imsm_migr_rec(super
, NULL
) == 0) {
4983 /* Check for unsupported migration features */
4984 if (check_mpb_migr_compatibility(super
) != 0) {
4985 pr_err("Unsupported migration detected");
4987 fprintf(stderr
, " on %s\n", devname
);
4989 fprintf(stderr
, " (IMSM).\n");
4997 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
4999 if (info
->level
== 1)
5001 return info
->chunk_size
>> 9;
5004 static unsigned long long info_to_blocks_per_member(mdu_array_info_t
*info
,
5005 unsigned long long size
)
5007 if (info
->level
== 1)
5010 return (size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
5013 static void imsm_update_version_info(struct intel_super
*super
)
5015 /* update the version and attributes */
5016 struct imsm_super
*mpb
= super
->anchor
;
5018 struct imsm_dev
*dev
;
5019 struct imsm_map
*map
;
5022 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5023 dev
= get_imsm_dev(super
, i
);
5024 map
= get_imsm_map(dev
, MAP_0
);
5025 if (__le32_to_cpu(dev
->size_high
) > 0)
5026 mpb
->attributes
|= MPB_ATTRIB_2TB
;
5028 /* FIXME detect when an array spans a port multiplier */
5030 mpb
->attributes
|= MPB_ATTRIB_PM
;
5033 if (mpb
->num_raid_devs
> 1 ||
5034 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
5035 version
= MPB_VERSION_ATTRIBS
;
5036 switch (get_imsm_raid_level(map
)) {
5037 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
5038 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
5039 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
5040 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
5043 if (map
->num_members
>= 5)
5044 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
5045 else if (dev
->status
== DEV_CLONE_N_GO
)
5046 version
= MPB_VERSION_CNG
;
5047 else if (get_imsm_raid_level(map
) == 5)
5048 version
= MPB_VERSION_RAID5
;
5049 else if (map
->num_members
>= 3)
5050 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
5051 else if (get_imsm_raid_level(map
) == 1)
5052 version
= MPB_VERSION_RAID1
;
5054 version
= MPB_VERSION_RAID0
;
5056 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
5060 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
5062 struct imsm_super
*mpb
= super
->anchor
;
5063 char *reason
= NULL
;
5066 if (strlen(name
) > MAX_RAID_SERIAL_LEN
)
5067 reason
= "must be 16 characters or less";
5069 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5070 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
5072 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
5073 reason
= "already exists";
5078 if (reason
&& !quiet
)
5079 pr_err("imsm volume name %s\n", reason
);
5084 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
5085 unsigned long long size
, char *name
,
5086 char *homehost
, int *uuid
,
5087 long long data_offset
)
5089 /* We are creating a volume inside a pre-existing container.
5090 * so st->sb is already set.
5092 struct intel_super
*super
= st
->sb
;
5093 unsigned int sector_size
= super
->sector_size
;
5094 struct imsm_super
*mpb
= super
->anchor
;
5095 struct intel_dev
*dv
;
5096 struct imsm_dev
*dev
;
5097 struct imsm_vol
*vol
;
5098 struct imsm_map
*map
;
5099 int idx
= mpb
->num_raid_devs
;
5101 unsigned long long array_blocks
;
5102 size_t size_old
, size_new
;
5103 unsigned long long num_data_stripes
;
5105 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
5106 pr_err("This imsm-container already has the maximum of %d volumes\n", super
->orom
->vpa
);
5110 /* ensure the mpb is large enough for the new data */
5111 size_old
= __le32_to_cpu(mpb
->mpb_size
);
5112 size_new
= disks_to_mpb_size(info
->nr_disks
);
5113 if (size_new
> size_old
) {
5115 size_t size_round
= ROUND_UP(size_new
, sector_size
);
5117 if (posix_memalign(&mpb_new
, sector_size
, size_round
) != 0) {
5118 pr_err("could not allocate new mpb\n");
5121 if (posix_memalign(&super
->migr_rec_buf
, sector_size
,
5122 MIGR_REC_BUF_SECTORS
*sector_size
) != 0) {
5123 pr_err("could not allocate migr_rec buffer\n");
5129 memcpy(mpb_new
, mpb
, size_old
);
5132 super
->anchor
= mpb_new
;
5133 mpb
->mpb_size
= __cpu_to_le32(size_new
);
5134 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
5135 super
->len
= size_round
;
5137 super
->current_vol
= idx
;
5139 /* handle 'failed_disks' by either:
5140 * a) create dummy disk entries in the table if this the first
5141 * volume in the array. We add them here as this is the only
5142 * opportunity to add them. add_to_super_imsm_volume()
5143 * handles the non-failed disks and continues incrementing
5145 * b) validate that 'failed_disks' matches the current number
5146 * of missing disks if the container is populated
5148 if (super
->current_vol
== 0) {
5150 for (i
= 0; i
< info
->failed_disks
; i
++) {
5151 struct imsm_disk
*disk
;
5154 disk
= __get_imsm_disk(mpb
, i
);
5155 disk
->status
= CONFIGURED_DISK
| FAILED_DISK
;
5156 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
5157 snprintf((char *) disk
->serial
, MAX_RAID_SERIAL_LEN
,
5160 find_missing(super
);
5165 for (d
= super
->missing
; d
; d
= d
->next
)
5167 if (info
->failed_disks
> missing
) {
5168 pr_err("unable to add 'missing' disk to container\n");
5173 if (!check_name(super
, name
, 0))
5175 dv
= xmalloc(sizeof(*dv
));
5176 dev
= xcalloc(1, sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
5177 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
5178 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
5179 info
->layout
, info
->chunk_size
,
5181 /* round array size down to closest MB */
5182 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
5184 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
5185 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
5186 dev
->status
= (DEV_READ_COALESCING
| DEV_WRITE_COALESCING
);
5188 vol
->migr_state
= 0;
5189 set_migr_type(dev
, MIGR_INIT
);
5190 vol
->dirty
= !info
->state
;
5191 vol
->curr_migr_unit
= 0;
5192 map
= get_imsm_map(dev
, MAP_0
);
5193 set_pba_of_lba0(map
, super
->create_offset
);
5194 set_blocks_per_member(map
, info_to_blocks_per_member(info
, size
));
5195 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
5196 map
->failed_disk_num
= ~0;
5197 if (info
->level
> 0)
5198 map
->map_state
= (info
->state
? IMSM_T_STATE_NORMAL
5199 : IMSM_T_STATE_UNINITIALIZED
);
5201 map
->map_state
= info
->failed_disks
? IMSM_T_STATE_FAILED
:
5202 IMSM_T_STATE_NORMAL
;
5205 if (info
->level
== 1 && info
->raid_disks
> 2) {
5208 pr_err("imsm does not support more than 2 disksin a raid1 volume\n");
5212 map
->raid_level
= info
->level
;
5213 if (info
->level
== 10) {
5214 map
->raid_level
= 1;
5215 map
->num_domains
= info
->raid_disks
/ 2;
5216 } else if (info
->level
== 1)
5217 map
->num_domains
= info
->raid_disks
;
5219 map
->num_domains
= 1;
5221 /* info->size is only int so use the 'size' parameter instead */
5222 num_data_stripes
= (size
* 2) / info_to_blocks_per_strip(info
);
5223 num_data_stripes
/= map
->num_domains
;
5224 set_num_data_stripes(map
, num_data_stripes
);
5226 map
->num_members
= info
->raid_disks
;
5227 for (i
= 0; i
< map
->num_members
; i
++) {
5228 /* initialized in add_to_super */
5229 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
5231 mpb
->num_raid_devs
++;
5234 dv
->index
= super
->current_vol
;
5235 dv
->next
= super
->devlist
;
5236 super
->devlist
= dv
;
5238 imsm_update_version_info(super
);
5243 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
5244 unsigned long long size
, char *name
,
5245 char *homehost
, int *uuid
,
5246 unsigned long long data_offset
)
5248 /* This is primarily called by Create when creating a new array.
5249 * We will then get add_to_super called for each component, and then
5250 * write_init_super called to write it out to each device.
5251 * For IMSM, Create can create on fresh devices or on a pre-existing
5253 * To create on a pre-existing array a different method will be called.
5254 * This one is just for fresh drives.
5256 struct intel_super
*super
;
5257 struct imsm_super
*mpb
;
5261 if (data_offset
!= INVALID_SECTORS
) {
5262 pr_err("data-offset not supported by imsm\n");
5267 return init_super_imsm_volume(st
, info
, size
, name
, homehost
, uuid
,
5271 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
5273 mpb_size
= MAX_SECTOR_SIZE
;
5275 super
= alloc_super();
5277 posix_memalign(&super
->buf
, MAX_SECTOR_SIZE
, mpb_size
) != 0) {
5282 pr_err("could not allocate superblock\n");
5285 if (posix_memalign(&super
->migr_rec_buf
, MAX_SECTOR_SIZE
,
5286 MIGR_REC_BUF_SECTORS
*MAX_SECTOR_SIZE
) != 0) {
5287 pr_err("could not allocate migr_rec buffer\n");
5292 memset(super
->buf
, 0, mpb_size
);
5294 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5298 /* zeroing superblock */
5302 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5304 version
= (char *) mpb
->sig
;
5305 strcpy(version
, MPB_SIGNATURE
);
5306 version
+= strlen(MPB_SIGNATURE
);
5307 strcpy(version
, MPB_VERSION_RAID0
);
5313 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
5314 int fd
, char *devname
)
5316 struct intel_super
*super
= st
->sb
;
5317 struct imsm_super
*mpb
= super
->anchor
;
5318 struct imsm_disk
*_disk
;
5319 struct imsm_dev
*dev
;
5320 struct imsm_map
*map
;
5324 dev
= get_imsm_dev(super
, super
->current_vol
);
5325 map
= get_imsm_map(dev
, MAP_0
);
5327 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
5328 pr_err("%s: Cannot add spare devices to IMSM volume\n",
5334 /* we're doing autolayout so grab the pre-marked (in
5335 * validate_geometry) raid_disk
5337 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5338 if (dl
->raiddisk
== dk
->raid_disk
)
5341 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5342 if (dl
->major
== dk
->major
&&
5343 dl
->minor
== dk
->minor
)
5348 pr_err("%s is not a member of the same container\n", devname
);
5352 /* add a pristine spare to the metadata */
5353 if (dl
->index
< 0) {
5354 dl
->index
= super
->anchor
->num_disks
;
5355 super
->anchor
->num_disks
++;
5357 /* Check the device has not already been added */
5358 slot
= get_imsm_disk_slot(map
, dl
->index
);
5360 (get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
) & IMSM_ORD_REBUILD
) == 0) {
5361 pr_err("%s has been included in this array twice\n",
5365 set_imsm_ord_tbl_ent(map
, dk
->raid_disk
, dl
->index
);
5366 dl
->disk
.status
= CONFIGURED_DISK
;
5368 /* update size of 'missing' disks to be at least as large as the
5369 * largest acitve member (we only have dummy missing disks when
5370 * creating the first volume)
5372 if (super
->current_vol
== 0) {
5373 for (df
= super
->missing
; df
; df
= df
->next
) {
5374 if (total_blocks(&dl
->disk
) > total_blocks(&df
->disk
))
5375 set_total_blocks(&df
->disk
, total_blocks(&dl
->disk
));
5376 _disk
= __get_imsm_disk(mpb
, df
->index
);
5381 /* refresh unset/failed slots to point to valid 'missing' entries */
5382 for (df
= super
->missing
; df
; df
= df
->next
)
5383 for (slot
= 0; slot
< mpb
->num_disks
; slot
++) {
5384 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
5386 if ((ord
& IMSM_ORD_REBUILD
) == 0)
5388 set_imsm_ord_tbl_ent(map
, slot
, df
->index
| IMSM_ORD_REBUILD
);
5389 if (is_gen_migration(dev
)) {
5390 struct imsm_map
*map2
= get_imsm_map(dev
,
5392 int slot2
= get_imsm_disk_slot(map2
, df
->index
);
5393 if (slot2
< map2
->num_members
&& slot2
>= 0) {
5394 __u32 ord2
= get_imsm_ord_tbl_ent(dev
,
5397 if ((unsigned)df
->index
==
5399 set_imsm_ord_tbl_ent(map2
,
5405 dprintf("set slot:%d to missing disk:%d\n", slot
, df
->index
);
5409 /* if we are creating the first raid device update the family number */
5410 if (super
->current_vol
== 0) {
5412 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
5414 _disk
= __get_imsm_disk(mpb
, dl
->index
);
5415 if (!_dev
|| !_disk
) {
5416 pr_err("BUG mpb setup error\n");
5422 sum
+= __gen_imsm_checksum(mpb
);
5423 mpb
->family_num
= __cpu_to_le32(sum
);
5424 mpb
->orig_family_num
= mpb
->family_num
;
5426 super
->current_disk
= dl
;
5431 * Function marks disk as spare and restores disk serial
5432 * in case it was previously marked as failed by takeover operation
5434 * -1 : critical error
5435 * 0 : disk is marked as spare but serial is not set
5438 int mark_spare(struct dl
*disk
)
5440 __u8 serial
[MAX_RAID_SERIAL_LEN
];
5447 if (!imsm_read_serial(disk
->fd
, NULL
, serial
)) {
5448 /* Restore disk serial number, because takeover marks disk
5449 * as failed and adds to serial ':0' before it becomes
5452 serialcpy(disk
->serial
, serial
);
5453 serialcpy(disk
->disk
.serial
, serial
);
5456 disk
->disk
.status
= SPARE_DISK
;
5462 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
5463 int fd
, char *devname
,
5464 unsigned long long data_offset
)
5466 struct intel_super
*super
= st
->sb
;
5468 unsigned long long size
;
5469 unsigned int member_sector_size
;
5474 /* If we are on an RAID enabled platform check that the disk is
5475 * attached to the raid controller.
5476 * We do not need to test disks attachment for container based additions,
5477 * they shall be already tested when container was created/assembled.
5479 rv
= find_intel_hba_capability(fd
, super
, devname
);
5480 /* no orom/efi or non-intel hba of the disk */
5482 dprintf("capability: %p fd: %d ret: %d\n",
5483 super
->orom
, fd
, rv
);
5487 if (super
->current_vol
>= 0)
5488 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
5491 dd
= xcalloc(sizeof(*dd
), 1);
5492 dd
->major
= major(stb
.st_rdev
);
5493 dd
->minor
= minor(stb
.st_rdev
);
5494 dd
->devname
= devname
? xstrdup(devname
) : NULL
;
5497 dd
->action
= DISK_ADD
;
5498 rv
= imsm_read_serial(fd
, devname
, dd
->serial
);
5500 pr_err("failed to retrieve scsi serial, aborting\n");
5506 if (super
->hba
&& ((super
->hba
->type
== SYS_DEV_NVME
) ||
5507 (super
->hba
->type
== SYS_DEV_VMD
))) {
5509 char *devpath
= diskfd_to_devpath(fd
);
5510 char controller_path
[PATH_MAX
];
5513 pr_err("failed to get devpath, aborting\n");
5520 snprintf(controller_path
, PATH_MAX
-1, "%s/device", devpath
);
5523 if (devpath_to_vendor(controller_path
) == 0x8086) {
5525 * If Intel's NVMe drive has serial ended with
5526 * "-A","-B","-1" or "-2" it means that this is "x8"
5527 * device (double drive on single PCIe card).
5528 * User should be warned about potential data loss.
5530 for (i
= MAX_RAID_SERIAL_LEN
-1; i
> 0; i
--) {
5531 /* Skip empty character at the end */
5532 if (dd
->serial
[i
] == 0)
5535 if (((dd
->serial
[i
] == 'A') ||
5536 (dd
->serial
[i
] == 'B') ||
5537 (dd
->serial
[i
] == '1') ||
5538 (dd
->serial
[i
] == '2')) &&
5539 (dd
->serial
[i
-1] == '-'))
5540 pr_err("\tThe action you are about to take may put your data at risk.\n"
5541 "\tPlease note that x8 devices may consist of two separate x4 devices "
5542 "located on a single PCIe port.\n"
5543 "\tRAID 0 is the only supported configuration for this type of x8 device.\n");
5549 get_dev_size(fd
, NULL
, &size
);
5550 get_dev_sector_size(fd
, NULL
, &member_sector_size
);
5552 if (super
->sector_size
== 0) {
5553 /* this a first device, so sector_size is not set yet */
5554 super
->sector_size
= member_sector_size
;
5555 } else if (member_sector_size
!= super
->sector_size
) {
5556 pr_err("Mixing between different sector size is forbidden, aborting...\n");
5563 /* clear migr_rec when adding disk to container */
5564 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SECTORS
*super
->sector_size
);
5565 if (lseek64(fd
, size
- MIGR_REC_SECTOR_POSITION
*super
->sector_size
,
5567 if (write(fd
, super
->migr_rec_buf
,
5568 MIGR_REC_BUF_SECTORS
*super
->sector_size
) !=
5569 MIGR_REC_BUF_SECTORS
*super
->sector_size
)
5570 perror("Write migr_rec failed");
5574 serialcpy(dd
->disk
.serial
, dd
->serial
);
5575 set_total_blocks(&dd
->disk
, size
);
5576 if (__le32_to_cpu(dd
->disk
.total_blocks_hi
) > 0) {
5577 struct imsm_super
*mpb
= super
->anchor
;
5578 mpb
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5581 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
5582 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
5584 dd
->disk
.scsi_id
= __cpu_to_le32(0);
5586 if (st
->update_tail
) {
5587 dd
->next
= super
->disk_mgmt_list
;
5588 super
->disk_mgmt_list
= dd
;
5590 dd
->next
= super
->disks
;
5592 super
->updates_pending
++;
5598 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
5600 struct intel_super
*super
= st
->sb
;
5603 /* remove from super works only in mdmon - for communication
5604 * manager - monitor. Check if communication memory buffer
5607 if (!st
->update_tail
) {
5608 pr_err("shall be used in mdmon context only\n");
5611 dd
= xcalloc(1, sizeof(*dd
));
5612 dd
->major
= dk
->major
;
5613 dd
->minor
= dk
->minor
;
5616 dd
->action
= DISK_REMOVE
;
5618 dd
->next
= super
->disk_mgmt_list
;
5619 super
->disk_mgmt_list
= dd
;
5624 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
5627 char buf
[MAX_SECTOR_SIZE
];
5628 struct imsm_super anchor
;
5629 } spare_record
__attribute__ ((aligned(MAX_SECTOR_SIZE
)));
5631 /* spare records have their own family number and do not have any defined raid
5634 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
5636 struct imsm_super
*mpb
= super
->anchor
;
5637 struct imsm_super
*spare
= &spare_record
.anchor
;
5641 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
));
5642 spare
->generation_num
= __cpu_to_le32(1UL);
5643 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5644 spare
->num_disks
= 1;
5645 spare
->num_raid_devs
= 0;
5646 spare
->cache_size
= mpb
->cache_size
;
5647 spare
->pwr_cycle_count
= __cpu_to_le32(1);
5649 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
5650 MPB_SIGNATURE MPB_VERSION_RAID0
);
5652 for (d
= super
->disks
; d
; d
= d
->next
) {
5656 spare
->disk
[0] = d
->disk
;
5657 if (__le32_to_cpu(d
->disk
.total_blocks_hi
) > 0)
5658 spare
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5660 if (super
->sector_size
== 4096)
5661 convert_to_4k_imsm_disk(&spare
->disk
[0]);
5663 sum
= __gen_imsm_checksum(spare
);
5664 spare
->family_num
= __cpu_to_le32(sum
);
5665 spare
->orig_family_num
= 0;
5666 sum
= __gen_imsm_checksum(spare
);
5667 spare
->check_sum
= __cpu_to_le32(sum
);
5669 if (store_imsm_mpb(d
->fd
, spare
)) {
5670 pr_err("failed for device %d:%d %s\n",
5671 d
->major
, d
->minor
, strerror(errno
));
5683 static int write_super_imsm(struct supertype
*st
, int doclose
)
5685 struct intel_super
*super
= st
->sb
;
5686 unsigned int sector_size
= super
->sector_size
;
5687 struct imsm_super
*mpb
= super
->anchor
;
5693 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
5695 int clear_migration_record
= 1;
5698 /* 'generation' is incremented everytime the metadata is written */
5699 generation
= __le32_to_cpu(mpb
->generation_num
);
5701 mpb
->generation_num
= __cpu_to_le32(generation
);
5703 /* fix up cases where previous mdadm releases failed to set
5706 if (mpb
->orig_family_num
== 0)
5707 mpb
->orig_family_num
= mpb
->family_num
;
5709 for (d
= super
->disks
; d
; d
= d
->next
) {
5713 mpb
->disk
[d
->index
] = d
->disk
;
5717 for (d
= super
->missing
; d
; d
= d
->next
) {
5718 mpb
->disk
[d
->index
] = d
->disk
;
5721 mpb
->num_disks
= num_disks
;
5722 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
5724 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5725 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
5726 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
5728 imsm_copy_dev(dev
, dev2
);
5729 mpb_size
+= sizeof_imsm_dev(dev
, 0);
5731 if (is_gen_migration(dev2
))
5732 clear_migration_record
= 0;
5735 bbm_log_size
= get_imsm_bbm_log_size(super
->bbm_log
);
5738 memcpy((void *)mpb
+ mpb_size
, super
->bbm_log
, bbm_log_size
);
5739 mpb
->attributes
|= MPB_ATTRIB_BBM
;
5741 mpb
->attributes
&= ~MPB_ATTRIB_BBM
;
5743 super
->anchor
->bbm_log_size
= __cpu_to_le32(bbm_log_size
);
5744 mpb_size
+= bbm_log_size
;
5745 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5748 assert(super
->len
== 0 || mpb_size
<= super
->len
);
5751 /* recalculate checksum */
5752 sum
= __gen_imsm_checksum(mpb
);
5753 mpb
->check_sum
= __cpu_to_le32(sum
);
5755 if (super
->clean_migration_record_by_mdmon
) {
5756 clear_migration_record
= 1;
5757 super
->clean_migration_record_by_mdmon
= 0;
5759 if (clear_migration_record
)
5760 memset(super
->migr_rec_buf
, 0,
5761 MIGR_REC_BUF_SECTORS
*sector_size
);
5763 if (sector_size
== 4096)
5764 convert_to_4k(super
);
5766 /* write the mpb for disks that compose raid devices */
5767 for (d
= super
->disks
; d
; d
= d
->next
) {
5768 if (d
->index
< 0 || is_failed(&d
->disk
))
5771 if (clear_migration_record
) {
5772 unsigned long long dsize
;
5774 get_dev_size(d
->fd
, NULL
, &dsize
);
5775 if (lseek64(d
->fd
, dsize
- sector_size
,
5777 if (write(d
->fd
, super
->migr_rec_buf
,
5778 MIGR_REC_BUF_SECTORS
*sector_size
) !=
5779 MIGR_REC_BUF_SECTORS
*sector_size
)
5780 perror("Write migr_rec failed");
5784 if (store_imsm_mpb(d
->fd
, mpb
))
5786 "failed for device %d:%d (fd: %d)%s\n",
5788 d
->fd
, strerror(errno
));
5797 return write_super_imsm_spares(super
, doclose
);
5802 static int create_array(struct supertype
*st
, int dev_idx
)
5805 struct imsm_update_create_array
*u
;
5806 struct intel_super
*super
= st
->sb
;
5807 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
5808 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
5809 struct disk_info
*inf
;
5810 struct imsm_disk
*disk
;
5813 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
5814 sizeof(*inf
) * map
->num_members
;
5816 u
->type
= update_create_array
;
5817 u
->dev_idx
= dev_idx
;
5818 imsm_copy_dev(&u
->dev
, dev
);
5819 inf
= get_disk_info(u
);
5820 for (i
= 0; i
< map
->num_members
; i
++) {
5821 int idx
= get_imsm_disk_idx(dev
, i
, MAP_X
);
5823 disk
= get_imsm_disk(super
, idx
);
5825 disk
= get_imsm_missing(super
, idx
);
5826 serialcpy(inf
[i
].serial
, disk
->serial
);
5828 append_metadata_update(st
, u
, len
);
5833 static int mgmt_disk(struct supertype
*st
)
5835 struct intel_super
*super
= st
->sb
;
5837 struct imsm_update_add_remove_disk
*u
;
5839 if (!super
->disk_mgmt_list
)
5844 u
->type
= update_add_remove_disk
;
5845 append_metadata_update(st
, u
, len
);
5850 static int write_init_super_imsm(struct supertype
*st
)
5852 struct intel_super
*super
= st
->sb
;
5853 int current_vol
= super
->current_vol
;
5855 /* we are done with current_vol reset it to point st at the container */
5856 super
->current_vol
= -1;
5858 if (st
->update_tail
) {
5859 /* queue the recently created array / added disk
5860 * as a metadata update */
5863 /* determine if we are creating a volume or adding a disk */
5864 if (current_vol
< 0) {
5865 /* in the mgmt (add/remove) disk case we are running
5866 * in mdmon context, so don't close fd's
5868 return mgmt_disk(st
);
5870 rv
= create_array(st
, current_vol
);
5875 for (d
= super
->disks
; d
; d
= d
->next
)
5876 Kill(d
->devname
, NULL
, 0, -1, 1);
5877 return write_super_imsm(st
, 1);
5882 static int store_super_imsm(struct supertype
*st
, int fd
)
5884 struct intel_super
*super
= st
->sb
;
5885 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
5891 if (super
->sector_size
== 4096)
5892 convert_to_4k(super
);
5893 return store_imsm_mpb(fd
, mpb
);
5900 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
5901 int layout
, int raiddisks
, int chunk
,
5902 unsigned long long size
,
5903 unsigned long long data_offset
,
5905 unsigned long long *freesize
,
5909 unsigned long long ldsize
;
5910 struct intel_super
*super
;
5913 if (level
!= LEVEL_CONTAINER
)
5918 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
5921 pr_err("imsm: Cannot open %s: %s\n",
5922 dev
, strerror(errno
));
5925 if (!get_dev_size(fd
, dev
, &ldsize
)) {
5930 /* capabilities retrieve could be possible
5931 * note that there is no fd for the disks in array.
5933 super
= alloc_super();
5938 if (!get_dev_sector_size(fd
, NULL
, &super
->sector_size
)) {
5944 rv
= find_intel_hba_capability(fd
, super
, verbose
> 0 ? dev
: NULL
);
5948 fd2devname(fd
, str
);
5949 dprintf("fd: %d %s orom: %p rv: %d raiddisk: %d\n",
5950 fd
, str
, super
->orom
, rv
, raiddisks
);
5952 /* no orom/efi or non-intel hba of the disk */
5959 if (raiddisks
> super
->orom
->tds
) {
5961 pr_err("%d exceeds maximum number of platform supported disks: %d\n",
5962 raiddisks
, super
->orom
->tds
);
5966 if ((super
->orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) == 0 &&
5967 (ldsize
>> 9) >> 32 > 0) {
5969 pr_err("%s exceeds maximum platform supported size\n", dev
);
5975 *freesize
= avail_size_imsm(st
, ldsize
>> 9, data_offset
);
5981 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
5983 const unsigned long long base_start
= e
[*idx
].start
;
5984 unsigned long long end
= base_start
+ e
[*idx
].size
;
5987 if (base_start
== end
)
5991 for (i
= *idx
; i
< num_extents
; i
++) {
5992 /* extend overlapping extents */
5993 if (e
[i
].start
>= base_start
&&
5994 e
[i
].start
<= end
) {
5997 if (e
[i
].start
+ e
[i
].size
> end
)
5998 end
= e
[i
].start
+ e
[i
].size
;
5999 } else if (e
[i
].start
> end
) {
6005 return end
- base_start
;
6008 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
6010 /* build a composite disk with all known extents and generate a new
6011 * 'maxsize' given the "all disks in an array must share a common start
6012 * offset" constraint
6014 struct extent
*e
= xcalloc(sum_extents
, sizeof(*e
));
6018 unsigned long long pos
;
6019 unsigned long long start
= 0;
6020 unsigned long long maxsize
;
6021 unsigned long reserve
;
6023 /* coalesce and sort all extents. also, check to see if we need to
6024 * reserve space between member arrays
6027 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6030 for (i
= 0; i
< dl
->extent_cnt
; i
++)
6033 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
6038 while (i
< sum_extents
) {
6039 e
[j
].start
= e
[i
].start
;
6040 e
[j
].size
= find_size(e
, &i
, sum_extents
);
6042 if (e
[j
-1].size
== 0)
6051 unsigned long long esize
;
6053 esize
= e
[i
].start
- pos
;
6054 if (esize
>= maxsize
) {
6059 pos
= e
[i
].start
+ e
[i
].size
;
6061 } while (e
[i
-1].size
);
6067 /* FIXME assumes volume at offset 0 is the first volume in a
6070 if (start_extent
> 0)
6071 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
6075 if (maxsize
< reserve
)
6078 super
->create_offset
= ~((unsigned long long) 0);
6079 if (start
+ reserve
> super
->create_offset
)
6080 return 0; /* start overflows create_offset */
6081 super
->create_offset
= start
+ reserve
;
6083 return maxsize
- reserve
;
6086 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
6088 if (level
< 0 || level
== 6 || level
== 4)
6091 /* if we have an orom prevent invalid raid levels */
6094 case 0: return imsm_orom_has_raid0(orom
);
6097 return imsm_orom_has_raid1e(orom
);
6098 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
6099 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
6100 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
6103 return 1; /* not on an Intel RAID platform so anything goes */
6109 active_arrays_by_format(char *name
, char* hba
, struct md_list
**devlist
,
6110 int dpa
, int verbose
)
6112 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
6113 struct mdstat_ent
*memb
;
6119 for (memb
= mdstat
; memb
; memb
= memb
->next
) {
6120 if (memb
->metadata_version
&&
6121 (strncmp(memb
->metadata_version
, "external:", 9) == 0) &&
6122 (strcmp(&memb
->metadata_version
[9], name
) == 0) &&
6123 !is_subarray(memb
->metadata_version
+9) &&
6125 struct dev_member
*dev
= memb
->members
;
6127 while(dev
&& (fd
< 0)) {
6128 char *path
= xmalloc(strlen(dev
->name
) + strlen("/dev/") + 1);
6129 num
= sprintf(path
, "%s%s", "/dev/", dev
->name
);
6131 fd
= open(path
, O_RDONLY
, 0);
6132 if (num
<= 0 || fd
< 0) {
6133 pr_vrb("Cannot open %s: %s\n",
6134 dev
->name
, strerror(errno
));
6140 if (fd
>= 0 && disk_attached_to_hba(fd
, hba
)) {
6141 struct mdstat_ent
*vol
;
6142 for (vol
= mdstat
; vol
; vol
= vol
->next
) {
6143 if (vol
->active
> 0 &&
6144 vol
->metadata_version
&&
6145 is_container_member(vol
, memb
->devnm
)) {
6150 if (*devlist
&& (found
< dpa
)) {
6151 dv
= xcalloc(1, sizeof(*dv
));
6152 dv
->devname
= xmalloc(strlen(memb
->devnm
) + strlen("/dev/") + 1);
6153 sprintf(dv
->devname
, "%s%s", "/dev/", memb
->devnm
);
6156 dv
->next
= *devlist
;
6164 free_mdstat(mdstat
);
6169 static struct md_list
*
6170 get_loop_devices(void)
6173 struct md_list
*devlist
= NULL
;
6176 for(i
= 0; i
< 12; i
++) {
6177 dv
= xcalloc(1, sizeof(*dv
));
6178 dv
->devname
= xmalloc(40);
6179 sprintf(dv
->devname
, "/dev/loop%d", i
);
6187 static struct md_list
*
6188 get_devices(const char *hba_path
)
6190 struct md_list
*devlist
= NULL
;
6197 devlist
= get_loop_devices();
6200 /* scroll through /sys/dev/block looking for devices attached to
6203 dir
= opendir("/sys/dev/block");
6204 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
6209 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
6211 path
= devt_to_devpath(makedev(major
, minor
));
6214 if (!path_attached_to_hba(path
, hba_path
)) {
6221 fd
= dev_open(ent
->d_name
, O_RDONLY
);
6223 fd2devname(fd
, buf
);
6226 pr_err("cannot open device: %s\n",
6231 dv
= xcalloc(1, sizeof(*dv
));
6232 dv
->devname
= xstrdup(buf
);
6239 devlist
= devlist
->next
;
6249 count_volumes_list(struct md_list
*devlist
, char *homehost
,
6250 int verbose
, int *found
)
6252 struct md_list
*tmpdev
;
6254 struct supertype
*st
;
6256 /* first walk the list of devices to find a consistent set
6257 * that match the criterea, if that is possible.
6258 * We flag the ones we like with 'used'.
6261 st
= match_metadata_desc_imsm("imsm");
6263 pr_vrb("cannot allocate memory for imsm supertype\n");
6267 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
6268 char *devname
= tmpdev
->devname
;
6270 struct supertype
*tst
;
6272 if (tmpdev
->used
> 1)
6274 tst
= dup_super(st
);
6276 pr_vrb("cannot allocate memory for imsm supertype\n");
6279 tmpdev
->container
= 0;
6280 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
6282 dprintf("cannot open device %s: %s\n",
6283 devname
, strerror(errno
));
6285 } else if (fstat(dfd
, &stb
)< 0) {
6287 dprintf("fstat failed for %s: %s\n",
6288 devname
, strerror(errno
));
6290 } else if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
6291 dprintf("%s is not a block device.\n",
6294 } else if (must_be_container(dfd
)) {
6295 struct supertype
*cst
;
6296 cst
= super_by_fd(dfd
, NULL
);
6298 dprintf("cannot recognize container type %s\n",
6301 } else if (tst
->ss
!= st
->ss
) {
6302 dprintf("non-imsm container - ignore it: %s\n",
6305 } else if (!tst
->ss
->load_container
||
6306 tst
->ss
->load_container(tst
, dfd
, NULL
))
6309 tmpdev
->container
= 1;
6312 cst
->ss
->free_super(cst
);
6314 tmpdev
->st_rdev
= stb
.st_rdev
;
6315 if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
6316 dprintf("no RAID superblock on %s\n",
6319 } else if (tst
->ss
->compare_super
== NULL
) {
6320 dprintf("Cannot assemble %s metadata on %s\n",
6321 tst
->ss
->name
, devname
);
6327 if (tmpdev
->used
== 2 || tmpdev
->used
== 4) {
6328 /* Ignore unrecognised devices during auto-assembly */
6333 tst
->ss
->getinfo_super(tst
, &info
, NULL
);
6335 if (st
->minor_version
== -1)
6336 st
->minor_version
= tst
->minor_version
;
6338 if (memcmp(info
.uuid
, uuid_zero
,
6339 sizeof(int[4])) == 0) {
6340 /* this is a floating spare. It cannot define
6341 * an array unless there are no more arrays of
6342 * this type to be found. It can be included
6343 * in an array of this type though.
6349 if (st
->ss
!= tst
->ss
||
6350 st
->minor_version
!= tst
->minor_version
||
6351 st
->ss
->compare_super(st
, tst
) != 0) {
6352 /* Some mismatch. If exactly one array matches this host,
6353 * we can resolve on that one.
6354 * Or, if we are auto assembling, we just ignore the second
6357 dprintf("superblock on %s doesn't match others - assembly aborted\n",
6363 dprintf("found: devname: %s\n", devname
);
6367 tst
->ss
->free_super(tst
);
6371 if ((err
= load_super_imsm_all(st
, -1, &st
->sb
, NULL
, devlist
, 0)) == 0) {
6372 struct mdinfo
*iter
, *head
= st
->ss
->container_content(st
, NULL
);
6373 for (iter
= head
; iter
; iter
= iter
->next
) {
6374 dprintf("content->text_version: %s vol\n",
6375 iter
->text_version
);
6376 if (iter
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
)) {
6377 /* do not assemble arrays with unsupported
6379 dprintf("Cannot activate member %s.\n",
6380 iter
->text_version
);
6387 dprintf("No valid super block on device list: err: %d %p\n",
6391 dprintf("no more devices to examine\n");
6394 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
6395 if (tmpdev
->used
== 1 && tmpdev
->found
) {
6397 if (count
< tmpdev
->found
)
6400 count
-= tmpdev
->found
;
6403 if (tmpdev
->used
== 1)
6408 st
->ss
->free_super(st
);
6413 count_volumes(struct intel_hba
*hba
, int dpa
, int verbose
)
6415 struct sys_dev
*idev
, *intel_devices
= find_intel_devices();
6417 const struct orom_entry
*entry
;
6418 struct devid_list
*dv
, *devid_list
;
6420 if (!hba
|| !hba
->path
)
6423 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
6424 if (strstr(idev
->path
, hba
->path
))
6428 if (!idev
|| !idev
->dev_id
)
6431 entry
= get_orom_entry_by_device_id(idev
->dev_id
);
6433 if (!entry
|| !entry
->devid_list
)
6436 devid_list
= entry
->devid_list
;
6437 for (dv
= devid_list
; dv
; dv
= dv
->next
) {
6438 struct md_list
*devlist
;
6439 struct sys_dev
*device
= device_by_id(dv
->devid
);
6444 hba_path
= device
->path
;
6448 devlist
= get_devices(hba_path
);
6449 /* if no intel devices return zero volumes */
6450 if (devlist
== NULL
)
6453 count
+= active_arrays_by_format("imsm", hba_path
, &devlist
, dpa
, verbose
);
6454 dprintf("path: %s active arrays: %d\n", hba_path
, count
);
6455 if (devlist
== NULL
)
6459 count
+= count_volumes_list(devlist
,
6463 dprintf("found %d count: %d\n", found
, count
);
6466 dprintf("path: %s total number of volumes: %d\n", hba_path
, count
);
6469 struct md_list
*dv
= devlist
;
6470 devlist
= devlist
->next
;
6478 static int imsm_default_chunk(const struct imsm_orom
*orom
)
6480 /* up to 512 if the plaform supports it, otherwise the platform max.
6481 * 128 if no platform detected
6483 int fs
= max(7, orom
? fls(orom
->sss
) : 0);
6485 return min(512, (1 << fs
));
6489 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
6490 int raiddisks
, int *chunk
, unsigned long long size
, int verbose
)
6492 /* check/set platform and metadata limits/defaults */
6493 if (super
->orom
&& raiddisks
> super
->orom
->dpa
) {
6494 pr_vrb("platform supports a maximum of %d disks per array\n",
6499 /* capabilities of OROM tested - copied from validate_geometry_imsm_volume */
6500 if (!is_raid_level_supported(super
->orom
, level
, raiddisks
)) {
6501 pr_vrb("platform does not support raid%d with %d disk%s\n",
6502 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
6506 if (*chunk
== 0 || *chunk
== UnSet
)
6507 *chunk
= imsm_default_chunk(super
->orom
);
6509 if (super
->orom
&& !imsm_orom_has_chunk(super
->orom
, *chunk
)) {
6510 pr_vrb("platform does not support a chunk size of: %d\n", *chunk
);
6514 if (layout
!= imsm_level_to_layout(level
)) {
6516 pr_vrb("imsm raid 5 only supports the left-asymmetric layout\n");
6517 else if (level
== 10)
6518 pr_vrb("imsm raid 10 only supports the n2 layout\n");
6520 pr_vrb("imsm unknown layout %#x for this raid level %d\n",
6525 if (super
->orom
&& (super
->orom
->attr
& IMSM_OROM_ATTR_2TB
) == 0 &&
6526 (calc_array_size(level
, raiddisks
, layout
, *chunk
, size
) >> 32) > 0) {
6527 pr_vrb("platform does not support a volume size over 2TB\n");
6534 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
6535 * FIX ME add ahci details
6537 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
6538 int layout
, int raiddisks
, int *chunk
,
6539 unsigned long long size
,
6540 unsigned long long data_offset
,
6542 unsigned long long *freesize
,
6546 struct intel_super
*super
= st
->sb
;
6547 struct imsm_super
*mpb
;
6549 unsigned long long pos
= 0;
6550 unsigned long long maxsize
;
6554 /* We must have the container info already read in. */
6558 mpb
= super
->anchor
;
6560 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, size
, verbose
)) {
6561 pr_err("RAID gemetry validation failed. Cannot proceed with the action(s).\n");
6565 /* General test: make sure there is space for
6566 * 'raiddisks' device extents of size 'size' at a given
6569 unsigned long long minsize
= size
;
6570 unsigned long long start_offset
= MaxSector
;
6573 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
6574 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6579 e
= get_extents(super
, dl
);
6582 unsigned long long esize
;
6583 esize
= e
[i
].start
- pos
;
6584 if (esize
>= minsize
)
6586 if (found
&& start_offset
== MaxSector
) {
6589 } else if (found
&& pos
!= start_offset
) {
6593 pos
= e
[i
].start
+ e
[i
].size
;
6595 } while (e
[i
-1].size
);
6600 if (dcnt
< raiddisks
) {
6602 pr_err("imsm: Not enough devices with space for this array (%d < %d)\n",
6609 /* This device must be a member of the set */
6610 if (stat(dev
, &stb
) < 0)
6612 if ((S_IFMT
& stb
.st_mode
) != S_IFBLK
)
6614 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6615 if (dl
->major
== (int)major(stb
.st_rdev
) &&
6616 dl
->minor
== (int)minor(stb
.st_rdev
))
6621 pr_err("%s is not in the same imsm set\n", dev
);
6623 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
6624 /* If a volume is present then the current creation attempt
6625 * cannot incorporate new spares because the orom may not
6626 * understand this configuration (all member disks must be
6627 * members of each array in the container).
6629 pr_err("%s is a spare and a volume is already defined for this container\n", dev
);
6630 pr_err("The option-rom requires all member disks to be a member of all volumes\n");
6632 } else if (super
->orom
&& mpb
->num_raid_devs
> 0 &&
6633 mpb
->num_disks
!= raiddisks
) {
6634 pr_err("The option-rom requires all member disks to be a member of all volumes\n");
6638 /* retrieve the largest free space block */
6639 e
= get_extents(super
, dl
);
6644 unsigned long long esize
;
6646 esize
= e
[i
].start
- pos
;
6647 if (esize
>= maxsize
)
6649 pos
= e
[i
].start
+ e
[i
].size
;
6651 } while (e
[i
-1].size
);
6656 pr_err("unable to determine free space for: %s\n",
6660 if (maxsize
< size
) {
6662 pr_err("%s not enough space (%llu < %llu)\n",
6663 dev
, maxsize
, size
);
6667 /* count total number of extents for merge */
6669 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6671 i
+= dl
->extent_cnt
;
6673 maxsize
= merge_extents(super
, i
);
6675 if (!check_env("IMSM_NO_PLATFORM") &&
6676 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
6677 pr_err("attempting to create a second volume with size less then remaining space. Aborting...\n");
6681 if (maxsize
< size
|| maxsize
== 0) {
6684 pr_err("no free space left on device. Aborting...\n");
6686 pr_err("not enough space to create volume of given size (%llu < %llu). Aborting...\n",
6692 *freesize
= maxsize
;
6695 int count
= count_volumes(super
->hba
,
6696 super
->orom
->dpa
, verbose
);
6697 if (super
->orom
->vphba
<= count
) {
6698 pr_vrb("platform does not support more than %d raid volumes.\n",
6699 super
->orom
->vphba
);
6706 static int imsm_get_free_size(struct supertype
*st
, int raiddisks
,
6707 unsigned long long size
, int chunk
,
6708 unsigned long long *freesize
)
6710 struct intel_super
*super
= st
->sb
;
6711 struct imsm_super
*mpb
= super
->anchor
;
6716 unsigned long long maxsize
;
6717 unsigned long long minsize
;
6721 /* find the largest common start free region of the possible disks */
6725 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6731 /* don't activate new spares if we are orom constrained
6732 * and there is already a volume active in the container
6734 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
6737 e
= get_extents(super
, dl
);
6740 for (i
= 1; e
[i
-1].size
; i
++)
6748 maxsize
= merge_extents(super
, extent_cnt
);
6752 minsize
= chunk
* 2;
6754 if (cnt
< raiddisks
||
6755 (super
->orom
&& used
&& used
!= raiddisks
) ||
6756 maxsize
< minsize
||
6758 pr_err("not enough devices with space to create array.\n");
6759 return 0; /* No enough free spaces large enough */
6770 if (!check_env("IMSM_NO_PLATFORM") &&
6771 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
6772 pr_err("attempting to create a second volume with size less then remaining space. Aborting...\n");
6776 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6778 dl
->raiddisk
= cnt
++;
6782 dprintf("imsm: imsm_get_free_size() returns : %llu\n", size
);
6787 static int reserve_space(struct supertype
*st
, int raiddisks
,
6788 unsigned long long size
, int chunk
,
6789 unsigned long long *freesize
)
6791 struct intel_super
*super
= st
->sb
;
6796 rv
= imsm_get_free_size(st
, raiddisks
, size
, chunk
, freesize
);
6799 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6801 dl
->raiddisk
= cnt
++;
6808 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
6809 int raiddisks
, int *chunk
, unsigned long long size
,
6810 unsigned long long data_offset
,
6811 char *dev
, unsigned long long *freesize
,
6819 * if given unused devices create a container
6820 * if given given devices in a container create a member volume
6822 if (level
== LEVEL_CONTAINER
) {
6823 /* Must be a fresh device to add to a container */
6824 return validate_geometry_imsm_container(st
, level
, layout
,
6834 struct intel_super
*super
= st
->sb
;
6835 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
6836 raiddisks
, chunk
, size
,
6839 /* we are being asked to automatically layout a
6840 * new volume based on the current contents of
6841 * the container. If the the parameters can be
6842 * satisfied reserve_space will record the disks,
6843 * start offset, and size of the volume to be
6844 * created. add_to_super and getinfo_super
6845 * detect when autolayout is in progress.
6847 /* assuming that freesize is always given when array is
6849 if (super
->orom
&& freesize
) {
6851 count
= count_volumes(super
->hba
,
6852 super
->orom
->dpa
, verbose
);
6853 if (super
->orom
->vphba
<= count
) {
6854 pr_vrb("platform does not support more than %d raid volumes.\n",
6855 super
->orom
->vphba
);
6860 return reserve_space(st
, raiddisks
, size
,
6866 /* creating in a given container */
6867 return validate_geometry_imsm_volume(st
, level
, layout
,
6868 raiddisks
, chunk
, size
,
6870 dev
, freesize
, verbose
);
6873 /* This device needs to be a device in an 'imsm' container */
6874 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
6877 pr_err("Cannot create this array on device %s\n",
6882 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
6884 pr_err("Cannot open %s: %s\n",
6885 dev
, strerror(errno
));
6888 /* Well, it is in use by someone, maybe an 'imsm' container. */
6889 cfd
= open_container(fd
);
6893 pr_err("Cannot use %s: It is busy\n",
6897 sra
= sysfs_read(cfd
, NULL
, GET_VERSION
);
6898 if (sra
&& sra
->array
.major_version
== -1 &&
6899 strcmp(sra
->text_version
, "imsm") == 0)
6903 /* This is a member of a imsm container. Load the container
6904 * and try to create a volume
6906 struct intel_super
*super
;
6908 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
, NULL
, 1) == 0) {
6910 strcpy(st
->container_devnm
, fd2devnm(cfd
));
6912 return validate_geometry_imsm_volume(st
, level
, layout
,
6914 size
, data_offset
, dev
,
6921 pr_err("failed container membership check\n");
6927 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
6929 struct intel_super
*super
= st
->sb
;
6931 if (level
&& *level
== UnSet
)
6932 *level
= LEVEL_CONTAINER
;
6934 if (level
&& layout
&& *layout
== UnSet
)
6935 *layout
= imsm_level_to_layout(*level
);
6937 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0))
6938 *chunk
= imsm_default_chunk(super
->orom
);
6941 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
6943 static int kill_subarray_imsm(struct supertype
*st
)
6945 /* remove the subarray currently referenced by ->current_vol */
6947 struct intel_dev
**dp
;
6948 struct intel_super
*super
= st
->sb
;
6949 __u8 current_vol
= super
->current_vol
;
6950 struct imsm_super
*mpb
= super
->anchor
;
6952 if (super
->current_vol
< 0)
6954 super
->current_vol
= -1; /* invalidate subarray cursor */
6956 /* block deletions that would change the uuid of active subarrays
6958 * FIXME when immutable ids are available, but note that we'll
6959 * also need to fixup the invalidated/active subarray indexes in
6962 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6965 if (i
< current_vol
)
6967 sprintf(subarray
, "%u", i
);
6968 if (is_subarray_active(subarray
, st
->devnm
)) {
6969 pr_err("deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
6976 if (st
->update_tail
) {
6977 struct imsm_update_kill_array
*u
= xmalloc(sizeof(*u
));
6979 u
->type
= update_kill_array
;
6980 u
->dev_idx
= current_vol
;
6981 append_metadata_update(st
, u
, sizeof(*u
));
6986 for (dp
= &super
->devlist
; *dp
;)
6987 if ((*dp
)->index
== current_vol
) {
6990 handle_missing(super
, (*dp
)->dev
);
6991 if ((*dp
)->index
> current_vol
)
6996 /* no more raid devices, all active components are now spares,
6997 * but of course failed are still failed
6999 if (--mpb
->num_raid_devs
== 0) {
7002 for (d
= super
->disks
; d
; d
= d
->next
)
7007 super
->updates_pending
++;
7012 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
7013 char *update
, struct mddev_ident
*ident
)
7015 /* update the subarray currently referenced by ->current_vol */
7016 struct intel_super
*super
= st
->sb
;
7017 struct imsm_super
*mpb
= super
->anchor
;
7019 if (strcmp(update
, "name") == 0) {
7020 char *name
= ident
->name
;
7024 if (is_subarray_active(subarray
, st
->devnm
)) {
7025 pr_err("Unable to update name of active subarray\n");
7029 if (!check_name(super
, name
, 0))
7032 vol
= strtoul(subarray
, &ep
, 10);
7033 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
7036 if (st
->update_tail
) {
7037 struct imsm_update_rename_array
*u
= xmalloc(sizeof(*u
));
7039 u
->type
= update_rename_array
;
7041 snprintf((char *) u
->name
, MAX_RAID_SERIAL_LEN
, "%s", name
);
7042 append_metadata_update(st
, u
, sizeof(*u
));
7044 struct imsm_dev
*dev
;
7047 dev
= get_imsm_dev(super
, vol
);
7048 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
7049 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7050 dev
= get_imsm_dev(super
, i
);
7051 handle_missing(super
, dev
);
7053 super
->updates_pending
++;
7060 #endif /* MDASSEMBLE */
7062 static int is_gen_migration(struct imsm_dev
*dev
)
7067 if (!dev
->vol
.migr_state
)
7070 if (migr_type(dev
) == MIGR_GEN_MIGR
)
7076 static int is_rebuilding(struct imsm_dev
*dev
)
7078 struct imsm_map
*migr_map
;
7080 if (!dev
->vol
.migr_state
)
7083 if (migr_type(dev
) != MIGR_REBUILD
)
7086 migr_map
= get_imsm_map(dev
, MAP_1
);
7088 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
7095 static int is_initializing(struct imsm_dev
*dev
)
7097 struct imsm_map
*migr_map
;
7099 if (!dev
->vol
.migr_state
)
7102 if (migr_type(dev
) != MIGR_INIT
)
7105 migr_map
= get_imsm_map(dev
, MAP_1
);
7107 if (migr_map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
7114 static void update_recovery_start(struct intel_super
*super
,
7115 struct imsm_dev
*dev
,
7116 struct mdinfo
*array
)
7118 struct mdinfo
*rebuild
= NULL
;
7122 if (!is_rebuilding(dev
))
7125 /* Find the rebuild target, but punt on the dual rebuild case */
7126 for (d
= array
->devs
; d
; d
= d
->next
)
7127 if (d
->recovery_start
== 0) {
7134 /* (?) none of the disks are marked with
7135 * IMSM_ORD_REBUILD, so assume they are missing and the
7136 * disk_ord_tbl was not correctly updated
7138 dprintf("failed to locate out-of-sync disk\n");
7142 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
7143 rebuild
->recovery_start
= units
* blocks_per_migr_unit(super
, dev
);
7147 static int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
);
7150 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
7152 /* Given a container loaded by load_super_imsm_all,
7153 * extract information about all the arrays into
7155 * If 'subarray' is given, just extract info about that array.
7157 * For each imsm_dev create an mdinfo, fill it in,
7158 * then look for matching devices in super->disks
7159 * and create appropriate device mdinfo.
7161 struct intel_super
*super
= st
->sb
;
7162 struct imsm_super
*mpb
= super
->anchor
;
7163 struct mdinfo
*rest
= NULL
;
7167 int spare_disks
= 0;
7169 /* do not assemble arrays when not all attributes are supported */
7170 if (imsm_check_attributes(mpb
->attributes
) == 0) {
7172 pr_err("Unsupported attributes in IMSM metadata.Arrays activation is blocked.\n");
7175 /* count spare devices, not used in maps
7177 for (d
= super
->disks
; d
; d
= d
->next
)
7181 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7182 struct imsm_dev
*dev
;
7183 struct imsm_map
*map
;
7184 struct imsm_map
*map2
;
7185 struct mdinfo
*this;
7193 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
7196 dev
= get_imsm_dev(super
, i
);
7197 map
= get_imsm_map(dev
, MAP_0
);
7198 map2
= get_imsm_map(dev
, MAP_1
);
7200 /* do not publish arrays that are in the middle of an
7201 * unsupported migration
7203 if (dev
->vol
.migr_state
&&
7204 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
7205 pr_err("cannot assemble volume '%.16s': unsupported migration in progress\n",
7209 /* do not publish arrays that are not support by controller's
7213 this = xmalloc(sizeof(*this));
7215 super
->current_vol
= i
;
7216 getinfo_super_imsm_volume(st
, this, NULL
);
7219 chunk
= __le16_to_cpu(map
->blocks_per_strip
) >> 1;
7220 /* mdadm does not support all metadata features- set the bit in all arrays state */
7221 if (!validate_geometry_imsm_orom(super
,
7222 get_imsm_raid_level(map
), /* RAID level */
7223 imsm_level_to_layout(get_imsm_raid_level(map
)),
7224 map
->num_members
, /* raid disks */
7225 &chunk
, join_u32(dev
->size_low
, dev
->size_high
),
7227 pr_err("IMSM RAID geometry validation failed. Array %s activation is blocked.\n",
7229 this->array
.state
|=
7230 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
7231 (1<<MD_SB_BLOCK_VOLUME
);
7235 /* if array has bad blocks, set suitable bit in all arrays state */
7237 this->array
.state
|=
7238 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
7239 (1<<MD_SB_BLOCK_VOLUME
);
7241 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
7242 unsigned long long recovery_start
;
7243 struct mdinfo
*info_d
;
7250 idx
= get_imsm_disk_idx(dev
, slot
, MAP_0
);
7251 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
7252 for (d
= super
->disks
; d
; d
= d
->next
)
7253 if (d
->index
== idx
)
7256 recovery_start
= MaxSector
;
7259 if (d
&& is_failed(&d
->disk
))
7261 if (ord
& IMSM_ORD_REBUILD
)
7265 * if we skip some disks the array will be assmebled degraded;
7266 * reset resync start to avoid a dirty-degraded
7267 * situation when performing the intial sync
7269 * FIXME handle dirty degraded
7271 if ((skip
|| recovery_start
== 0) && !dev
->vol
.dirty
)
7272 this->resync_start
= MaxSector
;
7276 info_d
= xcalloc(1, sizeof(*info_d
));
7277 info_d
->next
= this->devs
;
7278 this->devs
= info_d
;
7280 info_d
->disk
.number
= d
->index
;
7281 info_d
->disk
.major
= d
->major
;
7282 info_d
->disk
.minor
= d
->minor
;
7283 info_d
->disk
.raid_disk
= slot
;
7284 info_d
->recovery_start
= recovery_start
;
7286 if (slot
< map2
->num_members
)
7287 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
7289 this->array
.spare_disks
++;
7291 if (slot
< map
->num_members
)
7292 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
7294 this->array
.spare_disks
++;
7296 if (info_d
->recovery_start
== MaxSector
)
7297 this->array
.working_disks
++;
7299 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
7300 info_d
->data_offset
= pba_of_lba0(map
);
7302 if (map
->raid_level
== 5) {
7303 info_d
->component_size
=
7304 num_data_stripes(map
) *
7305 map
->blocks_per_strip
;
7307 info_d
->component_size
= blocks_per_member(map
);
7310 info_d
->bb
.supported
= 0;
7311 get_volume_badblocks(super
->bbm_log
, ord_to_idx(ord
),
7312 info_d
->data_offset
,
7313 info_d
->component_size
,
7316 /* now that the disk list is up-to-date fixup recovery_start */
7317 update_recovery_start(super
, dev
, this);
7318 this->array
.spare_disks
+= spare_disks
;
7321 /* check for reshape */
7322 if (this->reshape_active
== 1)
7323 recover_backup_imsm(st
, this);
7331 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
7332 int failed
, int look_in_map
)
7334 struct imsm_map
*map
;
7336 map
= get_imsm_map(dev
, look_in_map
);
7339 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
7340 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
7342 switch (get_imsm_raid_level(map
)) {
7344 return IMSM_T_STATE_FAILED
;
7347 if (failed
< map
->num_members
)
7348 return IMSM_T_STATE_DEGRADED
;
7350 return IMSM_T_STATE_FAILED
;
7355 * check to see if any mirrors have failed, otherwise we
7356 * are degraded. Even numbered slots are mirrored on
7360 /* gcc -Os complains that this is unused */
7361 int insync
= insync
;
7363 for (i
= 0; i
< map
->num_members
; i
++) {
7364 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_X
);
7365 int idx
= ord_to_idx(ord
);
7366 struct imsm_disk
*disk
;
7368 /* reset the potential in-sync count on even-numbered
7369 * slots. num_copies is always 2 for imsm raid10
7374 disk
= get_imsm_disk(super
, idx
);
7375 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
7378 /* no in-sync disks left in this mirror the
7382 return IMSM_T_STATE_FAILED
;
7385 return IMSM_T_STATE_DEGRADED
;
7389 return IMSM_T_STATE_DEGRADED
;
7391 return IMSM_T_STATE_FAILED
;
7397 return map
->map_state
;
7400 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
7405 struct imsm_disk
*disk
;
7406 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7407 struct imsm_map
*prev
= get_imsm_map(dev
, MAP_1
);
7408 struct imsm_map
*map_for_loop
;
7413 /* at the beginning of migration we set IMSM_ORD_REBUILD on
7414 * disks that are being rebuilt. New failures are recorded to
7415 * map[0]. So we look through all the disks we started with and
7416 * see if any failures are still present, or if any new ones
7420 if (prev
&& (map
->num_members
< prev
->num_members
))
7421 map_for_loop
= prev
;
7423 for (i
= 0; i
< map_for_loop
->num_members
; i
++) {
7425 /* when MAP_X is passed both maps failures are counted
7428 (look_in_map
== MAP_1
|| look_in_map
== MAP_X
) &&
7429 i
< prev
->num_members
) {
7430 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
7431 idx_1
= ord_to_idx(ord
);
7433 disk
= get_imsm_disk(super
, idx_1
);
7434 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
7437 if ((look_in_map
== MAP_0
|| look_in_map
== MAP_X
) &&
7438 i
< map
->num_members
) {
7439 ord
= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
7440 idx
= ord_to_idx(ord
);
7443 disk
= get_imsm_disk(super
, idx
);
7444 if (!disk
|| is_failed(disk
) ||
7445 ord
& IMSM_ORD_REBUILD
)
7455 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
7458 struct intel_super
*super
= c
->sb
;
7459 struct imsm_super
*mpb
= super
->anchor
;
7460 struct imsm_update_prealloc_bb_mem u
;
7462 if (atoi(inst
) >= mpb
->num_raid_devs
) {
7463 pr_err("subarry index %d, out of range\n", atoi(inst
));
7467 dprintf("imsm: open_new %s\n", inst
);
7468 a
->info
.container_member
= atoi(inst
);
7470 u
.type
= update_prealloc_badblocks_mem
;
7471 imsm_update_metadata_locally(c
, &u
, sizeof(u
));
7476 static int is_resyncing(struct imsm_dev
*dev
)
7478 struct imsm_map
*migr_map
;
7480 if (!dev
->vol
.migr_state
)
7483 if (migr_type(dev
) == MIGR_INIT
||
7484 migr_type(dev
) == MIGR_REPAIR
)
7487 if (migr_type(dev
) == MIGR_GEN_MIGR
)
7490 migr_map
= get_imsm_map(dev
, MAP_1
);
7492 if (migr_map
->map_state
== IMSM_T_STATE_NORMAL
&&
7493 dev
->vol
.migr_type
!= MIGR_GEN_MIGR
)
7499 /* return true if we recorded new information */
7500 static int mark_failure(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
7504 struct imsm_map
*map
;
7505 char buf
[MAX_RAID_SERIAL_LEN
+3];
7506 unsigned int len
, shift
= 0;
7508 /* new failures are always set in map[0] */
7509 map
= get_imsm_map(dev
, MAP_0
);
7511 slot
= get_imsm_disk_slot(map
, idx
);
7515 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
7516 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
7519 memcpy(buf
, disk
->serial
, MAX_RAID_SERIAL_LEN
);
7520 buf
[MAX_RAID_SERIAL_LEN
] = '\000';
7522 if ((len
= strlen(buf
)) >= MAX_RAID_SERIAL_LEN
)
7523 shift
= len
- MAX_RAID_SERIAL_LEN
+ 1;
7524 strncpy((char *)disk
->serial
, &buf
[shift
], MAX_RAID_SERIAL_LEN
);
7526 disk
->status
|= FAILED_DISK
;
7527 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
7528 /* mark failures in second map if second map exists and this disk
7530 * This is valid for migration, initialization and rebuild
7532 if (dev
->vol
.migr_state
) {
7533 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
7534 int slot2
= get_imsm_disk_slot(map2
, idx
);
7536 if (slot2
< map2
->num_members
&& slot2
>= 0)
7537 set_imsm_ord_tbl_ent(map2
, slot2
,
7538 idx
| IMSM_ORD_REBUILD
);
7540 if (map
->failed_disk_num
== 0xff)
7541 map
->failed_disk_num
= slot
;
7545 static void mark_missing(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
7547 mark_failure(dev
, disk
, idx
);
7549 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
7552 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
7553 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
7556 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
7560 if (!super
->missing
)
7563 /* When orom adds replacement for missing disk it does
7564 * not remove entry of missing disk, but just updates map with
7565 * new added disk. So it is not enough just to test if there is
7566 * any missing disk, we have to look if there are any failed disks
7567 * in map to stop migration */
7569 dprintf("imsm: mark missing\n");
7570 /* end process for initialization and rebuild only
7572 if (is_gen_migration(dev
) == 0) {
7576 failed
= imsm_count_failed(super
, dev
, MAP_0
);
7577 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7580 end_migration(dev
, super
, map_state
);
7582 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
7583 mark_missing(dev
, &dl
->disk
, dl
->index
);
7584 super
->updates_pending
++;
7587 static unsigned long long imsm_set_array_size(struct imsm_dev
*dev
,
7590 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
7591 unsigned long long array_blocks
;
7592 struct imsm_map
*map
;
7594 if (used_disks
== 0) {
7595 /* when problems occures
7596 * return current array_blocks value
7598 array_blocks
= __le32_to_cpu(dev
->size_high
);
7599 array_blocks
= array_blocks
<< 32;
7600 array_blocks
+= __le32_to_cpu(dev
->size_low
);
7602 return array_blocks
;
7605 /* set array size in metadata
7607 if (new_size
<= 0) {
7608 /* OLCE size change is caused by added disks
7610 map
= get_imsm_map(dev
, MAP_0
);
7611 array_blocks
= blocks_per_member(map
) * used_disks
;
7613 /* Online Volume Size Change
7614 * Using available free space
7616 array_blocks
= new_size
;
7619 /* round array size down to closest MB
7621 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
7622 dev
->size_low
= __cpu_to_le32((__u32
)array_blocks
);
7623 dev
->size_high
= __cpu_to_le32((__u32
)(array_blocks
>> 32));
7625 return array_blocks
;
7628 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
7630 static void imsm_progress_container_reshape(struct intel_super
*super
)
7632 /* if no device has a migr_state, but some device has a
7633 * different number of members than the previous device, start
7634 * changing the number of devices in this device to match
7637 struct imsm_super
*mpb
= super
->anchor
;
7638 int prev_disks
= -1;
7642 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7643 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
7644 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7645 struct imsm_map
*map2
;
7646 int prev_num_members
;
7648 if (dev
->vol
.migr_state
)
7651 if (prev_disks
== -1)
7652 prev_disks
= map
->num_members
;
7653 if (prev_disks
== map
->num_members
)
7656 /* OK, this array needs to enter reshape mode.
7657 * i.e it needs a migr_state
7660 copy_map_size
= sizeof_imsm_map(map
);
7661 prev_num_members
= map
->num_members
;
7662 map
->num_members
= prev_disks
;
7663 dev
->vol
.migr_state
= 1;
7664 dev
->vol
.curr_migr_unit
= 0;
7665 set_migr_type(dev
, MIGR_GEN_MIGR
);
7666 for (i
= prev_num_members
;
7667 i
< map
->num_members
; i
++)
7668 set_imsm_ord_tbl_ent(map
, i
, i
);
7669 map2
= get_imsm_map(dev
, MAP_1
);
7670 /* Copy the current map */
7671 memcpy(map2
, map
, copy_map_size
);
7672 map2
->num_members
= prev_num_members
;
7674 imsm_set_array_size(dev
, -1);
7675 super
->clean_migration_record_by_mdmon
= 1;
7676 super
->updates_pending
++;
7680 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
7681 * states are handled in imsm_set_disk() with one exception, when a
7682 * resync is stopped due to a new failure this routine will set the
7683 * 'degraded' state for the array.
7685 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
7687 int inst
= a
->info
.container_member
;
7688 struct intel_super
*super
= a
->container
->sb
;
7689 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7690 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7691 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
7692 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7693 __u32 blocks_per_unit
;
7695 if (dev
->vol
.migr_state
&&
7696 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
7697 /* array state change is blocked due to reshape action
7699 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
7700 * - finish the reshape (if last_checkpoint is big and action != reshape)
7701 * - update curr_migr_unit
7703 if (a
->curr_action
== reshape
) {
7704 /* still reshaping, maybe update curr_migr_unit */
7705 goto mark_checkpoint
;
7707 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
7708 /* for some reason we aborted the reshape.
7710 * disable automatic metadata rollback
7711 * user action is required to recover process
7714 struct imsm_map
*map2
=
7715 get_imsm_map(dev
, MAP_1
);
7716 dev
->vol
.migr_state
= 0;
7717 set_migr_type(dev
, 0);
7718 dev
->vol
.curr_migr_unit
= 0;
7720 sizeof_imsm_map(map2
));
7721 super
->updates_pending
++;
7724 if (a
->last_checkpoint
>= a
->info
.component_size
) {
7725 unsigned long long array_blocks
;
7729 used_disks
= imsm_num_data_members(dev
, MAP_0
);
7730 if (used_disks
> 0) {
7732 blocks_per_member(map
) *
7734 /* round array size down to closest MB
7736 array_blocks
= (array_blocks
7737 >> SECT_PER_MB_SHIFT
)
7738 << SECT_PER_MB_SHIFT
;
7739 a
->info
.custom_array_size
= array_blocks
;
7740 /* encourage manager to update array
7744 a
->check_reshape
= 1;
7746 /* finalize online capacity expansion/reshape */
7747 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
7749 mdi
->disk
.raid_disk
,
7752 imsm_progress_container_reshape(super
);
7757 /* before we activate this array handle any missing disks */
7758 if (consistent
== 2)
7759 handle_missing(super
, dev
);
7761 if (consistent
== 2 &&
7762 (!is_resync_complete(&a
->info
) ||
7763 map_state
!= IMSM_T_STATE_NORMAL
||
7764 dev
->vol
.migr_state
))
7767 if (is_resync_complete(&a
->info
)) {
7768 /* complete intialization / resync,
7769 * recovery and interrupted recovery is completed in
7772 if (is_resyncing(dev
)) {
7773 dprintf("imsm: mark resync done\n");
7774 end_migration(dev
, super
, map_state
);
7775 super
->updates_pending
++;
7776 a
->last_checkpoint
= 0;
7778 } else if ((!is_resyncing(dev
) && !failed
) &&
7779 (imsm_reshape_blocks_arrays_changes(super
) == 0)) {
7780 /* mark the start of the init process if nothing is failed */
7781 dprintf("imsm: mark resync start\n");
7782 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
7783 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
7785 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
7786 super
->updates_pending
++;
7790 /* skip checkpointing for general migration,
7791 * it is controlled in mdadm
7793 if (is_gen_migration(dev
))
7794 goto skip_mark_checkpoint
;
7796 /* check if we can update curr_migr_unit from resync_start, recovery_start */
7797 blocks_per_unit
= blocks_per_migr_unit(super
, dev
);
7798 if (blocks_per_unit
) {
7802 units
= a
->last_checkpoint
/ blocks_per_unit
;
7805 /* check that we did not overflow 32-bits, and that
7806 * curr_migr_unit needs updating
7808 if (units32
== units
&&
7810 __le32_to_cpu(dev
->vol
.curr_migr_unit
) != units32
) {
7811 dprintf("imsm: mark checkpoint (%u)\n", units32
);
7812 dev
->vol
.curr_migr_unit
= __cpu_to_le32(units32
);
7813 super
->updates_pending
++;
7817 skip_mark_checkpoint
:
7818 /* mark dirty / clean */
7819 if (dev
->vol
.dirty
!= !consistent
) {
7820 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
7825 super
->updates_pending
++;
7831 static int imsm_disk_slot_to_ord(struct active_array
*a
, int slot
)
7833 int inst
= a
->info
.container_member
;
7834 struct intel_super
*super
= a
->container
->sb
;
7835 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7836 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7838 if (slot
> map
->num_members
) {
7839 pr_err("imsm: imsm_disk_slot_to_ord %d out of range 0..%d\n",
7840 slot
, map
->num_members
- 1);
7847 return get_imsm_ord_tbl_ent(dev
, slot
, MAP_0
);
7850 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
7852 int inst
= a
->info
.container_member
;
7853 struct intel_super
*super
= a
->container
->sb
;
7854 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7855 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7856 struct imsm_disk
*disk
;
7858 int recovery_not_finished
= 0;
7863 ord
= imsm_disk_slot_to_ord(a
, n
);
7867 dprintf("imsm: set_disk %d:%x\n", n
, state
);
7868 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
7870 /* check for new failures */
7871 if (state
& DS_FAULTY
) {
7872 if (mark_failure(dev
, disk
, ord_to_idx(ord
)))
7873 super
->updates_pending
++;
7876 /* check if in_sync */
7877 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
7878 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
7880 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
7881 super
->updates_pending
++;
7884 failed
= imsm_count_failed(super
, dev
, MAP_0
);
7885 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7887 /* check if recovery complete, newly degraded, or failed */
7888 dprintf("imsm: Detected transition to state ");
7889 switch (map_state
) {
7890 case IMSM_T_STATE_NORMAL
: /* transition to normal state */
7891 dprintf("normal: ");
7892 if (is_rebuilding(dev
)) {
7893 dprintf_cont("while rebuilding");
7894 /* check if recovery is really finished */
7895 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
7896 if (mdi
->recovery_start
!= MaxSector
) {
7897 recovery_not_finished
= 1;
7900 if (recovery_not_finished
) {
7902 dprintf("Rebuild has not finished yet, state not changed");
7903 if (a
->last_checkpoint
< mdi
->recovery_start
) {
7904 a
->last_checkpoint
= mdi
->recovery_start
;
7905 super
->updates_pending
++;
7909 end_migration(dev
, super
, map_state
);
7910 map
= get_imsm_map(dev
, MAP_0
);
7911 map
->failed_disk_num
= ~0;
7912 super
->updates_pending
++;
7913 a
->last_checkpoint
= 0;
7916 if (is_gen_migration(dev
)) {
7917 dprintf_cont("while general migration");
7918 if (a
->last_checkpoint
>= a
->info
.component_size
)
7919 end_migration(dev
, super
, map_state
);
7921 map
->map_state
= map_state
;
7922 map
= get_imsm_map(dev
, MAP_0
);
7923 map
->failed_disk_num
= ~0;
7924 super
->updates_pending
++;
7928 case IMSM_T_STATE_DEGRADED
: /* transition to degraded state */
7929 dprintf_cont("degraded: ");
7930 if (map
->map_state
!= map_state
&& !dev
->vol
.migr_state
) {
7931 dprintf_cont("mark degraded");
7932 map
->map_state
= map_state
;
7933 super
->updates_pending
++;
7934 a
->last_checkpoint
= 0;
7937 if (is_rebuilding(dev
)) {
7938 dprintf_cont("while rebuilding.");
7939 if (map
->map_state
!= map_state
) {
7940 dprintf_cont(" Map state change");
7941 end_migration(dev
, super
, map_state
);
7942 super
->updates_pending
++;
7946 if (is_gen_migration(dev
)) {
7947 dprintf_cont("while general migration");
7948 if (a
->last_checkpoint
>= a
->info
.component_size
)
7949 end_migration(dev
, super
, map_state
);
7951 map
->map_state
= map_state
;
7952 manage_second_map(super
, dev
);
7954 super
->updates_pending
++;
7957 if (is_initializing(dev
)) {
7958 dprintf_cont("while initialization.");
7959 map
->map_state
= map_state
;
7960 super
->updates_pending
++;
7964 case IMSM_T_STATE_FAILED
: /* transition to failed state */
7965 dprintf_cont("failed: ");
7966 if (is_gen_migration(dev
)) {
7967 dprintf_cont("while general migration");
7968 map
->map_state
= map_state
;
7969 super
->updates_pending
++;
7972 if (map
->map_state
!= map_state
) {
7973 dprintf_cont("mark failed");
7974 end_migration(dev
, super
, map_state
);
7975 super
->updates_pending
++;
7976 a
->last_checkpoint
= 0;
7981 dprintf_cont("state %i\n", map_state
);
7986 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
7989 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
7990 unsigned long long dsize
;
7991 unsigned long long sectors
;
7992 unsigned int sector_size
;
7994 get_dev_sector_size(fd
, NULL
, §or_size
);
7995 get_dev_size(fd
, NULL
, &dsize
);
7997 if (mpb_size
> sector_size
) {
7998 /* -1 to account for anchor */
7999 sectors
= mpb_sectors(mpb
, sector_size
) - 1;
8001 /* write the extended mpb to the sectors preceeding the anchor */
8002 if (lseek64(fd
, dsize
- (sector_size
* (2 + sectors
)),
8006 if ((unsigned long long)write(fd
, buf
+ sector_size
,
8007 sector_size
* sectors
) != sector_size
* sectors
)
8011 /* first block is stored on second to last sector of the disk */
8012 if (lseek64(fd
, dsize
- (sector_size
* 2), SEEK_SET
) < 0)
8015 if (write(fd
, buf
, sector_size
) != sector_size
)
8021 static void imsm_sync_metadata(struct supertype
*container
)
8023 struct intel_super
*super
= container
->sb
;
8025 dprintf("sync metadata: %d\n", super
->updates_pending
);
8026 if (!super
->updates_pending
)
8029 write_super_imsm(container
, 0);
8031 super
->updates_pending
= 0;
8034 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
8036 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
8037 int i
= get_imsm_disk_idx(dev
, idx
, MAP_X
);
8040 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8044 if (dl
&& is_failed(&dl
->disk
))
8048 dprintf("found %x:%x\n", dl
->major
, dl
->minor
);
8053 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
8054 struct active_array
*a
, int activate_new
,
8055 struct mdinfo
*additional_test_list
)
8057 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
8058 int idx
= get_imsm_disk_idx(dev
, slot
, MAP_X
);
8059 struct imsm_super
*mpb
= super
->anchor
;
8060 struct imsm_map
*map
;
8061 unsigned long long pos
;
8066 __u32 array_start
= 0;
8067 __u32 array_end
= 0;
8069 struct mdinfo
*test_list
;
8071 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
8072 /* If in this array, skip */
8073 for (d
= a
->info
.devs
; d
; d
= d
->next
)
8074 if (d
->state_fd
>= 0 &&
8075 d
->disk
.major
== dl
->major
&&
8076 d
->disk
.minor
== dl
->minor
) {
8077 dprintf("%x:%x already in array\n",
8078 dl
->major
, dl
->minor
);
8083 test_list
= additional_test_list
;
8085 if (test_list
->disk
.major
== dl
->major
&&
8086 test_list
->disk
.minor
== dl
->minor
) {
8087 dprintf("%x:%x already in additional test list\n",
8088 dl
->major
, dl
->minor
);
8091 test_list
= test_list
->next
;
8096 /* skip in use or failed drives */
8097 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
8099 dprintf("%x:%x status (failed: %d index: %d)\n",
8100 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
8104 /* skip pure spares when we are looking for partially
8105 * assimilated drives
8107 if (dl
->index
== -1 && !activate_new
)
8110 /* Does this unused device have the requisite free space?
8111 * It needs to be able to cover all member volumes
8113 ex
= get_extents(super
, dl
);
8115 dprintf("cannot get extents\n");
8118 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8119 dev
= get_imsm_dev(super
, i
);
8120 map
= get_imsm_map(dev
, MAP_0
);
8122 /* check if this disk is already a member of
8125 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
8131 array_start
= pba_of_lba0(map
);
8132 array_end
= array_start
+
8133 blocks_per_member(map
) - 1;
8136 /* check that we can start at pba_of_lba0 with
8137 * blocks_per_member of space
8139 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
8143 pos
= ex
[j
].start
+ ex
[j
].size
;
8145 } while (ex
[j
-1].size
);
8152 if (i
< mpb
->num_raid_devs
) {
8153 dprintf("%x:%x does not have %u to %u available\n",
8154 dl
->major
, dl
->minor
, array_start
, array_end
);
8164 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
8166 struct imsm_dev
*dev2
;
8167 struct imsm_map
*map
;
8173 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
8175 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
, MAP_0
);
8176 if (state
== IMSM_T_STATE_FAILED
) {
8177 map
= get_imsm_map(dev2
, MAP_0
);
8180 for (slot
= 0; slot
< map
->num_members
; slot
++) {
8182 * Check if failed disks are deleted from intel
8183 * disk list or are marked to be deleted
8185 idx
= get_imsm_disk_idx(dev2
, slot
, MAP_X
);
8186 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
8188 * Do not rebuild the array if failed disks
8189 * from failed sub-array are not removed from
8193 is_failed(&idisk
->disk
) &&
8194 (idisk
->action
!= DISK_REMOVE
))
8202 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
8203 struct metadata_update
**updates
)
8206 * Find a device with unused free space and use it to replace a
8207 * failed/vacant region in an array. We replace failed regions one a
8208 * array at a time. The result is that a new spare disk will be added
8209 * to the first failed array and after the monitor has finished
8210 * propagating failures the remainder will be consumed.
8212 * FIXME add a capability for mdmon to request spares from another
8216 struct intel_super
*super
= a
->container
->sb
;
8217 int inst
= a
->info
.container_member
;
8218 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
8219 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8220 int failed
= a
->info
.array
.raid_disks
;
8221 struct mdinfo
*rv
= NULL
;
8224 struct metadata_update
*mu
;
8226 struct imsm_update_activate_spare
*u
;
8231 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
8232 if ((d
->curr_state
& DS_FAULTY
) &&
8234 /* wait for Removal to happen */
8236 if (d
->state_fd
>= 0)
8240 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
8241 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
8243 if (imsm_reshape_blocks_arrays_changes(super
))
8246 /* Cannot activate another spare if rebuild is in progress already
8248 if (is_rebuilding(dev
)) {
8249 dprintf("imsm: No spare activation allowed. Rebuild in progress already.\n");
8253 if (a
->info
.array
.level
== 4)
8254 /* No repair for takeovered array
8255 * imsm doesn't support raid4
8259 if (imsm_check_degraded(super
, dev
, failed
, MAP_0
) !=
8260 IMSM_T_STATE_DEGRADED
)
8263 if (get_imsm_map(dev
, MAP_0
)->map_state
== IMSM_T_STATE_UNINITIALIZED
) {
8264 dprintf("imsm: No spare activation allowed. Volume is not initialized.\n");
8269 * If there are any failed disks check state of the other volume.
8270 * Block rebuild if the another one is failed until failed disks
8271 * are removed from container.
8274 dprintf("found failed disks in %.*s, check if there anotherfailed sub-array.\n",
8275 MAX_RAID_SERIAL_LEN
, dev
->volume
);
8276 /* check if states of the other volumes allow for rebuild */
8277 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
8279 allowed
= imsm_rebuild_allowed(a
->container
,
8287 /* For each slot, if it is not working, find a spare */
8288 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
8289 for (d
= a
->info
.devs
; d
; d
= d
->next
)
8290 if (d
->disk
.raid_disk
== i
)
8292 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
8293 if (d
&& (d
->state_fd
>= 0))
8297 * OK, this device needs recovery. Try to re-add the
8298 * previous occupant of this slot, if this fails see if
8299 * we can continue the assimilation of a spare that was
8300 * partially assimilated, finally try to activate a new
8303 dl
= imsm_readd(super
, i
, a
);
8305 dl
= imsm_add_spare(super
, i
, a
, 0, rv
);
8307 dl
= imsm_add_spare(super
, i
, a
, 1, rv
);
8311 /* found a usable disk with enough space */
8312 di
= xcalloc(1, sizeof(*di
));
8314 /* dl->index will be -1 in the case we are activating a
8315 * pristine spare. imsm_process_update() will create a
8316 * new index in this case. Once a disk is found to be
8317 * failed in all member arrays it is kicked from the
8320 di
->disk
.number
= dl
->index
;
8322 /* (ab)use di->devs to store a pointer to the device
8325 di
->devs
= (struct mdinfo
*) dl
;
8327 di
->disk
.raid_disk
= i
;
8328 di
->disk
.major
= dl
->major
;
8329 di
->disk
.minor
= dl
->minor
;
8331 di
->recovery_start
= 0;
8332 di
->data_offset
= pba_of_lba0(map
);
8333 di
->component_size
= a
->info
.component_size
;
8334 di
->container_member
= inst
;
8335 di
->bb
.supported
= 0;
8336 super
->random
= random32();
8340 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
8341 i
, di
->data_offset
);
8345 /* No spares found */
8347 /* Now 'rv' has a list of devices to return.
8348 * Create a metadata_update record to update the
8349 * disk_ord_tbl for the array
8351 mu
= xmalloc(sizeof(*mu
));
8352 mu
->buf
= xcalloc(num_spares
,
8353 sizeof(struct imsm_update_activate_spare
));
8355 mu
->space_list
= NULL
;
8356 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
8357 mu
->next
= *updates
;
8358 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
8360 for (di
= rv
; di
; di
= di
->next
) {
8361 u
->type
= update_activate_spare
;
8362 u
->dl
= (struct dl
*) di
->devs
;
8364 u
->slot
= di
->disk
.raid_disk
;
8375 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
8377 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
8378 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8379 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, MAP_0
);
8380 struct disk_info
*inf
= get_disk_info(u
);
8381 struct imsm_disk
*disk
;
8385 for (i
= 0; i
< map
->num_members
; i
++) {
8386 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, MAP_X
));
8387 for (j
= 0; j
< new_map
->num_members
; j
++)
8388 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
8395 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
8399 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8400 if (dl
->major
== major
&& dl
->minor
== minor
)
8405 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
8411 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
8412 if (dl
->major
== major
&& dl
->minor
== minor
) {
8415 prev
->next
= dl
->next
;
8417 super
->disks
= dl
->next
;
8419 __free_imsm_disk(dl
);
8420 dprintf("removed %x:%x\n", major
, minor
);
8428 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
8430 static int add_remove_disk_update(struct intel_super
*super
)
8432 int check_degraded
= 0;
8435 /* add/remove some spares to/from the metadata/contrainer */
8436 while (super
->disk_mgmt_list
) {
8437 struct dl
*disk_cfg
;
8439 disk_cfg
= super
->disk_mgmt_list
;
8440 super
->disk_mgmt_list
= disk_cfg
->next
;
8441 disk_cfg
->next
= NULL
;
8443 if (disk_cfg
->action
== DISK_ADD
) {
8444 disk_cfg
->next
= super
->disks
;
8445 super
->disks
= disk_cfg
;
8447 dprintf("added %x:%x\n",
8448 disk_cfg
->major
, disk_cfg
->minor
);
8449 } else if (disk_cfg
->action
== DISK_REMOVE
) {
8450 dprintf("Disk remove action processed: %x.%x\n",
8451 disk_cfg
->major
, disk_cfg
->minor
);
8452 disk
= get_disk_super(super
,
8456 /* store action status */
8457 disk
->action
= DISK_REMOVE
;
8458 /* remove spare disks only */
8459 if (disk
->index
== -1) {
8460 remove_disk_super(super
,
8465 /* release allocate disk structure */
8466 __free_imsm_disk(disk_cfg
);
8469 return check_degraded
;
8472 static int apply_reshape_migration_update(struct imsm_update_reshape_migration
*u
,
8473 struct intel_super
*super
,
8476 struct intel_dev
*id
;
8477 void **tofree
= NULL
;
8480 dprintf("(enter)\n");
8481 if (u
->subdev
< 0 || u
->subdev
> 1) {
8482 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
8485 if (space_list
== NULL
|| *space_list
== NULL
) {
8486 dprintf("imsm: Error: Memory is not allocated\n");
8490 for (id
= super
->devlist
; id
; id
= id
->next
) {
8491 if (id
->index
== (unsigned)u
->subdev
) {
8492 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
8493 struct imsm_map
*map
;
8494 struct imsm_dev
*new_dev
=
8495 (struct imsm_dev
*)*space_list
;
8496 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
8498 struct dl
*new_disk
;
8500 if (new_dev
== NULL
)
8502 *space_list
= **space_list
;
8503 memcpy(new_dev
, dev
, sizeof_imsm_dev(dev
, 0));
8504 map
= get_imsm_map(new_dev
, MAP_0
);
8506 dprintf("imsm: Error: migration in progress");
8510 to_state
= map
->map_state
;
8511 if ((u
->new_level
== 5) && (map
->raid_level
== 0)) {
8513 /* this should not happen */
8514 if (u
->new_disks
[0] < 0) {
8515 map
->failed_disk_num
=
8516 map
->num_members
- 1;
8517 to_state
= IMSM_T_STATE_DEGRADED
;
8519 to_state
= IMSM_T_STATE_NORMAL
;
8521 migrate(new_dev
, super
, to_state
, MIGR_GEN_MIGR
);
8522 if (u
->new_level
> -1)
8523 map
->raid_level
= u
->new_level
;
8524 migr_map
= get_imsm_map(new_dev
, MAP_1
);
8525 if ((u
->new_level
== 5) &&
8526 (migr_map
->raid_level
== 0)) {
8527 int ord
= map
->num_members
- 1;
8528 migr_map
->num_members
--;
8529 if (u
->new_disks
[0] < 0)
8530 ord
|= IMSM_ORD_REBUILD
;
8531 set_imsm_ord_tbl_ent(map
,
8532 map
->num_members
- 1,
8536 tofree
= (void **)dev
;
8538 /* update chunk size
8540 if (u
->new_chunksize
> 0) {
8541 unsigned long long num_data_stripes
;
8543 imsm_num_data_members(dev
, MAP_0
);
8545 if (used_disks
== 0)
8548 map
->blocks_per_strip
=
8549 __cpu_to_le16(u
->new_chunksize
* 2);
8551 (join_u32(dev
->size_low
, dev
->size_high
)
8553 num_data_stripes
/= map
->blocks_per_strip
;
8554 num_data_stripes
/= map
->num_domains
;
8555 set_num_data_stripes(map
, num_data_stripes
);
8560 if (u
->new_level
!= 5 || migr_map
->raid_level
!= 0 ||
8561 migr_map
->raid_level
== map
->raid_level
)
8564 if (u
->new_disks
[0] >= 0) {
8567 new_disk
= get_disk_super(super
,
8568 major(u
->new_disks
[0]),
8569 minor(u
->new_disks
[0]));
8570 dprintf("imsm: new disk for reshape is: %i:%i (%p, index = %i)\n",
8571 major(u
->new_disks
[0]),
8572 minor(u
->new_disks
[0]),
8573 new_disk
, new_disk
->index
);
8574 if (new_disk
== NULL
)
8575 goto error_disk_add
;
8577 new_disk
->index
= map
->num_members
- 1;
8578 /* slot to fill in autolayout
8580 new_disk
->raiddisk
= new_disk
->index
;
8581 new_disk
->disk
.status
|= CONFIGURED_DISK
;
8582 new_disk
->disk
.status
&= ~SPARE_DISK
;
8584 goto error_disk_add
;
8587 *tofree
= *space_list
;
8588 /* calculate new size
8590 imsm_set_array_size(new_dev
, -1);
8597 *space_list
= tofree
;
8601 dprintf("Error: imsm: Cannot find disk.\n");
8605 static int apply_size_change_update(struct imsm_update_size_change
*u
,
8606 struct intel_super
*super
)
8608 struct intel_dev
*id
;
8611 dprintf("(enter)\n");
8612 if (u
->subdev
< 0 || u
->subdev
> 1) {
8613 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
8617 for (id
= super
->devlist
; id
; id
= id
->next
) {
8618 if (id
->index
== (unsigned)u
->subdev
) {
8619 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
8620 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8621 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
8622 unsigned long long blocks_per_member
;
8623 unsigned long long num_data_stripes
;
8625 /* calculate new size
8627 blocks_per_member
= u
->new_size
/ used_disks
;
8628 num_data_stripes
= blocks_per_member
/
8629 map
->blocks_per_strip
;
8630 num_data_stripes
/= map
->num_domains
;
8631 dprintf("(size: %llu, blocks per member: %llu, num_data_stipes: %llu)\n",
8632 u
->new_size
, blocks_per_member
,
8634 set_blocks_per_member(map
, blocks_per_member
);
8635 set_num_data_stripes(map
, num_data_stripes
);
8636 imsm_set_array_size(dev
, u
->new_size
);
8646 static int apply_update_activate_spare(struct imsm_update_activate_spare
*u
,
8647 struct intel_super
*super
,
8648 struct active_array
*active_array
)
8650 struct imsm_super
*mpb
= super
->anchor
;
8651 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
8652 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8653 struct imsm_map
*migr_map
;
8654 struct active_array
*a
;
8655 struct imsm_disk
*disk
;
8662 int second_map_created
= 0;
8664 for (; u
; u
= u
->next
) {
8665 victim
= get_imsm_disk_idx(dev
, u
->slot
, MAP_X
);
8670 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8675 pr_err("error: imsm_activate_spare passed an unknown disk (index: %d)\n",
8680 /* count failures (excluding rebuilds and the victim)
8681 * to determine map[0] state
8684 for (i
= 0; i
< map
->num_members
; i
++) {
8687 disk
= get_imsm_disk(super
,
8688 get_imsm_disk_idx(dev
, i
, MAP_X
));
8689 if (!disk
|| is_failed(disk
))
8693 /* adding a pristine spare, assign a new index */
8694 if (dl
->index
< 0) {
8695 dl
->index
= super
->anchor
->num_disks
;
8696 super
->anchor
->num_disks
++;
8699 disk
->status
|= CONFIGURED_DISK
;
8700 disk
->status
&= ~SPARE_DISK
;
8703 to_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8704 if (!second_map_created
) {
8705 second_map_created
= 1;
8706 map
->map_state
= IMSM_T_STATE_DEGRADED
;
8707 migrate(dev
, super
, to_state
, MIGR_REBUILD
);
8709 map
->map_state
= to_state
;
8710 migr_map
= get_imsm_map(dev
, MAP_1
);
8711 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
8712 set_imsm_ord_tbl_ent(migr_map
, u
->slot
,
8713 dl
->index
| IMSM_ORD_REBUILD
);
8715 /* update the family_num to mark a new container
8716 * generation, being careful to record the existing
8717 * family_num in orig_family_num to clean up after
8718 * earlier mdadm versions that neglected to set it.
8720 if (mpb
->orig_family_num
== 0)
8721 mpb
->orig_family_num
= mpb
->family_num
;
8722 mpb
->family_num
+= super
->random
;
8724 /* count arrays using the victim in the metadata */
8726 for (a
= active_array
; a
; a
= a
->next
) {
8727 dev
= get_imsm_dev(super
, a
->info
.container_member
);
8728 map
= get_imsm_map(dev
, MAP_0
);
8730 if (get_imsm_disk_slot(map
, victim
) >= 0)
8734 /* delete the victim if it is no longer being
8740 /* We know that 'manager' isn't touching anything,
8741 * so it is safe to delete
8743 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
8744 if ((*dlp
)->index
== victim
)
8747 /* victim may be on the missing list */
8749 for (dlp
= &super
->missing
; *dlp
;
8750 dlp
= &(*dlp
)->next
)
8751 if ((*dlp
)->index
== victim
)
8753 imsm_delete(super
, dlp
, victim
);
8760 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
8761 struct intel_super
*super
,
8764 struct dl
*new_disk
;
8765 struct intel_dev
*id
;
8767 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
8768 int disk_count
= u
->old_raid_disks
;
8769 void **tofree
= NULL
;
8770 int devices_to_reshape
= 1;
8771 struct imsm_super
*mpb
= super
->anchor
;
8773 unsigned int dev_id
;
8775 dprintf("(enter)\n");
8777 /* enable spares to use in array */
8778 for (i
= 0; i
< delta_disks
; i
++) {
8779 new_disk
= get_disk_super(super
,
8780 major(u
->new_disks
[i
]),
8781 minor(u
->new_disks
[i
]));
8782 dprintf("imsm: new disk for reshape is: %i:%i (%p, index = %i)\n",
8783 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
8784 new_disk
, new_disk
->index
);
8785 if (new_disk
== NULL
||
8786 (new_disk
->index
>= 0 &&
8787 new_disk
->index
< u
->old_raid_disks
))
8788 goto update_reshape_exit
;
8789 new_disk
->index
= disk_count
++;
8790 /* slot to fill in autolayout
8792 new_disk
->raiddisk
= new_disk
->index
;
8793 new_disk
->disk
.status
|=
8795 new_disk
->disk
.status
&= ~SPARE_DISK
;
8798 dprintf("imsm: volume set mpb->num_raid_devs = %i\n",
8799 mpb
->num_raid_devs
);
8800 /* manage changes in volume
8802 for (dev_id
= 0; dev_id
< mpb
->num_raid_devs
; dev_id
++) {
8803 void **sp
= *space_list
;
8804 struct imsm_dev
*newdev
;
8805 struct imsm_map
*newmap
, *oldmap
;
8807 for (id
= super
->devlist
; id
; id
= id
->next
) {
8808 if (id
->index
== dev_id
)
8817 /* Copy the dev, but not (all of) the map */
8818 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
8819 oldmap
= get_imsm_map(id
->dev
, MAP_0
);
8820 newmap
= get_imsm_map(newdev
, MAP_0
);
8821 /* Copy the current map */
8822 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
8823 /* update one device only
8825 if (devices_to_reshape
) {
8826 dprintf("imsm: modifying subdev: %i\n",
8828 devices_to_reshape
--;
8829 newdev
->vol
.migr_state
= 1;
8830 newdev
->vol
.curr_migr_unit
= 0;
8831 set_migr_type(newdev
, MIGR_GEN_MIGR
);
8832 newmap
->num_members
= u
->new_raid_disks
;
8833 for (i
= 0; i
< delta_disks
; i
++) {
8834 set_imsm_ord_tbl_ent(newmap
,
8835 u
->old_raid_disks
+ i
,
8836 u
->old_raid_disks
+ i
);
8838 /* New map is correct, now need to save old map
8840 newmap
= get_imsm_map(newdev
, MAP_1
);
8841 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
8843 imsm_set_array_size(newdev
, -1);
8846 sp
= (void **)id
->dev
;
8851 /* Clear migration record */
8852 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
8855 *space_list
= tofree
;
8858 update_reshape_exit
:
8863 static int apply_takeover_update(struct imsm_update_takeover
*u
,
8864 struct intel_super
*super
,
8867 struct imsm_dev
*dev
= NULL
;
8868 struct intel_dev
*dv
;
8869 struct imsm_dev
*dev_new
;
8870 struct imsm_map
*map
;
8874 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
8875 if (dv
->index
== (unsigned int)u
->subarray
) {
8883 map
= get_imsm_map(dev
, MAP_0
);
8885 if (u
->direction
== R10_TO_R0
) {
8886 unsigned long long num_data_stripes
;
8888 map
->num_domains
= 1;
8889 num_data_stripes
= blocks_per_member(map
);
8890 num_data_stripes
/= map
->blocks_per_strip
;
8891 num_data_stripes
/= map
->num_domains
;
8892 set_num_data_stripes(map
, num_data_stripes
);
8894 /* Number of failed disks must be half of initial disk number */
8895 if (imsm_count_failed(super
, dev
, MAP_0
) !=
8896 (map
->num_members
/ 2))
8899 /* iterate through devices to mark removed disks as spare */
8900 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
8901 if (dm
->disk
.status
& FAILED_DISK
) {
8902 int idx
= dm
->index
;
8903 /* update indexes on the disk list */
8904 /* FIXME this loop-with-the-loop looks wrong, I'm not convinced
8905 the index values will end up being correct.... NB */
8906 for (du
= super
->disks
; du
; du
= du
->next
)
8907 if (du
->index
> idx
)
8909 /* mark as spare disk */
8914 map
->num_members
= map
->num_members
/ 2;
8915 map
->map_state
= IMSM_T_STATE_NORMAL
;
8916 map
->num_domains
= 1;
8917 map
->raid_level
= 0;
8918 map
->failed_disk_num
= -1;
8921 if (u
->direction
== R0_TO_R10
) {
8923 /* update slots in current disk list */
8924 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
8928 /* create new *missing* disks */
8929 for (i
= 0; i
< map
->num_members
; i
++) {
8930 space
= *space_list
;
8933 *space_list
= *space
;
8935 memcpy(du
, super
->disks
, sizeof(*du
));
8939 du
->index
= (i
* 2) + 1;
8940 sprintf((char *)du
->disk
.serial
,
8941 " MISSING_%d", du
->index
);
8942 sprintf((char *)du
->serial
,
8943 "MISSING_%d", du
->index
);
8944 du
->next
= super
->missing
;
8945 super
->missing
= du
;
8947 /* create new dev and map */
8948 space
= *space_list
;
8951 *space_list
= *space
;
8952 dev_new
= (void *)space
;
8953 memcpy(dev_new
, dev
, sizeof(*dev
));
8954 /* update new map */
8955 map
= get_imsm_map(dev_new
, MAP_0
);
8956 map
->num_members
= map
->num_members
* 2;
8957 map
->map_state
= IMSM_T_STATE_DEGRADED
;
8958 map
->num_domains
= 2;
8959 map
->raid_level
= 1;
8960 /* replace dev<->dev_new */
8963 /* update disk order table */
8964 for (du
= super
->disks
; du
; du
= du
->next
)
8966 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
8967 for (du
= super
->missing
; du
; du
= du
->next
)
8968 if (du
->index
>= 0) {
8969 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
8970 mark_missing(dv
->dev
, &du
->disk
, du
->index
);
8976 static void imsm_process_update(struct supertype
*st
,
8977 struct metadata_update
*update
)
8980 * crack open the metadata_update envelope to find the update record
8981 * update can be one of:
8982 * update_reshape_container_disks - all the arrays in the container
8983 * are being reshaped to have more devices. We need to mark
8984 * the arrays for general migration and convert selected spares
8985 * into active devices.
8986 * update_activate_spare - a spare device has replaced a failed
8987 * device in an array, update the disk_ord_tbl. If this disk is
8988 * present in all member arrays then also clear the SPARE_DISK
8990 * update_create_array
8992 * update_rename_array
8993 * update_add_remove_disk
8995 struct intel_super
*super
= st
->sb
;
8996 struct imsm_super
*mpb
;
8997 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
8999 /* update requires a larger buf but the allocation failed */
9000 if (super
->next_len
&& !super
->next_buf
) {
9001 super
->next_len
= 0;
9005 if (super
->next_buf
) {
9006 memcpy(super
->next_buf
, super
->buf
, super
->len
);
9008 super
->len
= super
->next_len
;
9009 super
->buf
= super
->next_buf
;
9011 super
->next_len
= 0;
9012 super
->next_buf
= NULL
;
9015 mpb
= super
->anchor
;
9018 case update_general_migration_checkpoint
: {
9019 struct intel_dev
*id
;
9020 struct imsm_update_general_migration_checkpoint
*u
=
9021 (void *)update
->buf
;
9023 dprintf("called for update_general_migration_checkpoint\n");
9025 /* find device under general migration */
9026 for (id
= super
->devlist
; id
; id
= id
->next
) {
9027 if (is_gen_migration(id
->dev
)) {
9028 id
->dev
->vol
.curr_migr_unit
=
9029 __cpu_to_le32(u
->curr_migr_unit
);
9030 super
->updates_pending
++;
9035 case update_takeover
: {
9036 struct imsm_update_takeover
*u
= (void *)update
->buf
;
9037 if (apply_takeover_update(u
, super
, &update
->space_list
)) {
9038 imsm_update_version_info(super
);
9039 super
->updates_pending
++;
9044 case update_reshape_container_disks
: {
9045 struct imsm_update_reshape
*u
= (void *)update
->buf
;
9046 if (apply_reshape_container_disks_update(
9047 u
, super
, &update
->space_list
))
9048 super
->updates_pending
++;
9051 case update_reshape_migration
: {
9052 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
9053 if (apply_reshape_migration_update(
9054 u
, super
, &update
->space_list
))
9055 super
->updates_pending
++;
9058 case update_size_change
: {
9059 struct imsm_update_size_change
*u
= (void *)update
->buf
;
9060 if (apply_size_change_update(u
, super
))
9061 super
->updates_pending
++;
9064 case update_activate_spare
: {
9065 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
9066 if (apply_update_activate_spare(u
, super
, st
->arrays
))
9067 super
->updates_pending
++;
9070 case update_create_array
: {
9071 /* someone wants to create a new array, we need to be aware of
9072 * a few races/collisions:
9073 * 1/ 'Create' called by two separate instances of mdadm
9074 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
9075 * devices that have since been assimilated via
9077 * In the event this update can not be carried out mdadm will
9078 * (FIX ME) notice that its update did not take hold.
9080 struct imsm_update_create_array
*u
= (void *) update
->buf
;
9081 struct intel_dev
*dv
;
9082 struct imsm_dev
*dev
;
9083 struct imsm_map
*map
, *new_map
;
9084 unsigned long long start
, end
;
9085 unsigned long long new_start
, new_end
;
9087 struct disk_info
*inf
;
9090 /* handle racing creates: first come first serve */
9091 if (u
->dev_idx
< mpb
->num_raid_devs
) {
9092 dprintf("subarray %d already defined\n", u
->dev_idx
);
9096 /* check update is next in sequence */
9097 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
9098 dprintf("can not create array %d expected index %d\n",
9099 u
->dev_idx
, mpb
->num_raid_devs
);
9103 new_map
= get_imsm_map(&u
->dev
, MAP_0
);
9104 new_start
= pba_of_lba0(new_map
);
9105 new_end
= new_start
+ blocks_per_member(new_map
);
9106 inf
= get_disk_info(u
);
9108 /* handle activate_spare versus create race:
9109 * check to make sure that overlapping arrays do not include
9112 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
9113 dev
= get_imsm_dev(super
, i
);
9114 map
= get_imsm_map(dev
, MAP_0
);
9115 start
= pba_of_lba0(map
);
9116 end
= start
+ blocks_per_member(map
);
9117 if ((new_start
>= start
&& new_start
<= end
) ||
9118 (start
>= new_start
&& start
<= new_end
))
9123 if (disks_overlap(super
, i
, u
)) {
9124 dprintf("arrays overlap\n");
9129 /* check that prepare update was successful */
9130 if (!update
->space
) {
9131 dprintf("prepare update failed\n");
9135 /* check that all disks are still active before committing
9136 * changes. FIXME: could we instead handle this by creating a
9137 * degraded array? That's probably not what the user expects,
9138 * so better to drop this update on the floor.
9140 for (i
= 0; i
< new_map
->num_members
; i
++) {
9141 dl
= serial_to_dl(inf
[i
].serial
, super
);
9143 dprintf("disk disappeared\n");
9148 super
->updates_pending
++;
9150 /* convert spares to members and fixup ord_tbl */
9151 for (i
= 0; i
< new_map
->num_members
; i
++) {
9152 dl
= serial_to_dl(inf
[i
].serial
, super
);
9153 if (dl
->index
== -1) {
9154 dl
->index
= mpb
->num_disks
;
9156 dl
->disk
.status
|= CONFIGURED_DISK
;
9157 dl
->disk
.status
&= ~SPARE_DISK
;
9159 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
9164 update
->space
= NULL
;
9165 imsm_copy_dev(dev
, &u
->dev
);
9166 dv
->index
= u
->dev_idx
;
9167 dv
->next
= super
->devlist
;
9168 super
->devlist
= dv
;
9169 mpb
->num_raid_devs
++;
9171 imsm_update_version_info(super
);
9174 /* mdmon knows how to release update->space, but not
9175 * ((struct intel_dev *) update->space)->dev
9177 if (update
->space
) {
9183 case update_kill_array
: {
9184 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
9185 int victim
= u
->dev_idx
;
9186 struct active_array
*a
;
9187 struct intel_dev
**dp
;
9188 struct imsm_dev
*dev
;
9190 /* sanity check that we are not affecting the uuid of
9191 * active arrays, or deleting an active array
9193 * FIXME when immutable ids are available, but note that
9194 * we'll also need to fixup the invalidated/active
9195 * subarray indexes in mdstat
9197 for (a
= st
->arrays
; a
; a
= a
->next
)
9198 if (a
->info
.container_member
>= victim
)
9200 /* by definition if mdmon is running at least one array
9201 * is active in the container, so checking
9202 * mpb->num_raid_devs is just extra paranoia
9204 dev
= get_imsm_dev(super
, victim
);
9205 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
9206 dprintf("failed to delete subarray-%d\n", victim
);
9210 for (dp
= &super
->devlist
; *dp
;)
9211 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
9214 if ((*dp
)->index
> (unsigned)victim
)
9218 mpb
->num_raid_devs
--;
9219 super
->updates_pending
++;
9222 case update_rename_array
: {
9223 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
9224 char name
[MAX_RAID_SERIAL_LEN
+1];
9225 int target
= u
->dev_idx
;
9226 struct active_array
*a
;
9227 struct imsm_dev
*dev
;
9229 /* sanity check that we are not affecting the uuid of
9232 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
9233 name
[MAX_RAID_SERIAL_LEN
] = '\0';
9234 for (a
= st
->arrays
; a
; a
= a
->next
)
9235 if (a
->info
.container_member
== target
)
9237 dev
= get_imsm_dev(super
, u
->dev_idx
);
9238 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
9239 dprintf("failed to rename subarray-%d\n", target
);
9243 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
9244 super
->updates_pending
++;
9247 case update_add_remove_disk
: {
9248 /* we may be able to repair some arrays if disks are
9249 * being added, check the status of add_remove_disk
9250 * if discs has been added.
9252 if (add_remove_disk_update(super
)) {
9253 struct active_array
*a
;
9255 super
->updates_pending
++;
9256 for (a
= st
->arrays
; a
; a
= a
->next
)
9257 a
->check_degraded
= 1;
9261 case update_prealloc_badblocks_mem
:
9264 pr_err("error: unsuported process update type:(type: %d)\n", type
);
9268 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
);
9270 static int imsm_prepare_update(struct supertype
*st
,
9271 struct metadata_update
*update
)
9274 * Allocate space to hold new disk entries, raid-device entries or a new
9275 * mpb if necessary. The manager synchronously waits for updates to
9276 * complete in the monitor, so new mpb buffers allocated here can be
9277 * integrated by the monitor thread without worrying about live pointers
9278 * in the manager thread.
9280 enum imsm_update_type type
;
9281 struct intel_super
*super
= st
->sb
;
9282 unsigned int sector_size
= super
->sector_size
;
9283 struct imsm_super
*mpb
= super
->anchor
;
9287 if (update
->len
< (int)sizeof(type
))
9290 type
= *(enum imsm_update_type
*) update
->buf
;
9293 case update_general_migration_checkpoint
:
9294 if (update
->len
< (int)sizeof(struct imsm_update_general_migration_checkpoint
))
9296 dprintf("called for update_general_migration_checkpoint\n");
9298 case update_takeover
: {
9299 struct imsm_update_takeover
*u
= (void *)update
->buf
;
9300 if (update
->len
< (int)sizeof(*u
))
9302 if (u
->direction
== R0_TO_R10
) {
9303 void **tail
= (void **)&update
->space_list
;
9304 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subarray
);
9305 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9306 int num_members
= map
->num_members
;
9309 /* allocate memory for added disks */
9310 for (i
= 0; i
< num_members
; i
++) {
9311 size
= sizeof(struct dl
);
9312 space
= xmalloc(size
);
9317 /* allocate memory for new device */
9318 size
= sizeof_imsm_dev(super
->devlist
->dev
, 0) +
9319 (num_members
* sizeof(__u32
));
9320 space
= xmalloc(size
);
9324 len
= disks_to_mpb_size(num_members
* 2);
9329 case update_reshape_container_disks
: {
9330 /* Every raid device in the container is about to
9331 * gain some more devices, and we will enter a
9333 * So each 'imsm_map' will be bigger, and the imsm_vol
9334 * will now hold 2 of them.
9335 * Thus we need new 'struct imsm_dev' allocations sized
9336 * as sizeof_imsm_dev but with more devices in both maps.
9338 struct imsm_update_reshape
*u
= (void *)update
->buf
;
9339 struct intel_dev
*dl
;
9340 void **space_tail
= (void**)&update
->space_list
;
9342 if (update
->len
< (int)sizeof(*u
))
9345 dprintf("for update_reshape\n");
9347 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
9348 int size
= sizeof_imsm_dev(dl
->dev
, 1);
9350 if (u
->new_raid_disks
> u
->old_raid_disks
)
9351 size
+= sizeof(__u32
)*2*
9352 (u
->new_raid_disks
- u
->old_raid_disks
);
9359 len
= disks_to_mpb_size(u
->new_raid_disks
);
9360 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
9363 case update_reshape_migration
: {
9364 /* for migration level 0->5 we need to add disks
9365 * so the same as for container operation we will copy
9366 * device to the bigger location.
9367 * in memory prepared device and new disk area are prepared
9368 * for usage in process update
9370 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
9371 struct intel_dev
*id
;
9372 void **space_tail
= (void **)&update
->space_list
;
9375 int current_level
= -1;
9377 if (update
->len
< (int)sizeof(*u
))
9380 dprintf("for update_reshape\n");
9382 /* add space for bigger array in update
9384 for (id
= super
->devlist
; id
; id
= id
->next
) {
9385 if (id
->index
== (unsigned)u
->subdev
) {
9386 size
= sizeof_imsm_dev(id
->dev
, 1);
9387 if (u
->new_raid_disks
> u
->old_raid_disks
)
9388 size
+= sizeof(__u32
)*2*
9389 (u
->new_raid_disks
- u
->old_raid_disks
);
9397 if (update
->space_list
== NULL
)
9400 /* add space for disk in update
9402 size
= sizeof(struct dl
);
9408 /* add spare device to update
9410 for (id
= super
->devlist
; id
; id
= id
->next
)
9411 if (id
->index
== (unsigned)u
->subdev
) {
9412 struct imsm_dev
*dev
;
9413 struct imsm_map
*map
;
9415 dev
= get_imsm_dev(super
, u
->subdev
);
9416 map
= get_imsm_map(dev
, MAP_0
);
9417 current_level
= map
->raid_level
;
9420 if (u
->new_level
== 5 && u
->new_level
!= current_level
) {
9421 struct mdinfo
*spares
;
9423 spares
= get_spares_for_grow(st
);
9431 makedev(dev
->disk
.major
,
9433 dl
= get_disk_super(super
,
9436 dl
->index
= u
->old_raid_disks
;
9442 len
= disks_to_mpb_size(u
->new_raid_disks
);
9443 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
9446 case update_size_change
: {
9447 if (update
->len
< (int)sizeof(struct imsm_update_size_change
))
9451 case update_activate_spare
: {
9452 if (update
->len
< (int)sizeof(struct imsm_update_activate_spare
))
9456 case update_create_array
: {
9457 struct imsm_update_create_array
*u
= (void *) update
->buf
;
9458 struct intel_dev
*dv
;
9459 struct imsm_dev
*dev
= &u
->dev
;
9460 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
9462 struct disk_info
*inf
;
9466 if (update
->len
< (int)sizeof(*u
))
9469 inf
= get_disk_info(u
);
9470 len
= sizeof_imsm_dev(dev
, 1);
9471 /* allocate a new super->devlist entry */
9472 dv
= xmalloc(sizeof(*dv
));
9473 dv
->dev
= xmalloc(len
);
9476 /* count how many spares will be converted to members */
9477 for (i
= 0; i
< map
->num_members
; i
++) {
9478 dl
= serial_to_dl(inf
[i
].serial
, super
);
9480 /* hmm maybe it failed?, nothing we can do about
9485 if (count_memberships(dl
, super
) == 0)
9488 len
+= activate
* sizeof(struct imsm_disk
);
9491 case update_kill_array
: {
9492 if (update
->len
< (int)sizeof(struct imsm_update_kill_array
))
9496 case update_rename_array
: {
9497 if (update
->len
< (int)sizeof(struct imsm_update_rename_array
))
9501 case update_add_remove_disk
:
9502 /* no update->len needed */
9504 case update_prealloc_badblocks_mem
:
9505 super
->extra_space
+= sizeof(struct bbm_log
) -
9506 get_imsm_bbm_log_size(super
->bbm_log
);
9512 /* check if we need a larger metadata buffer */
9513 if (super
->next_buf
)
9514 buf_len
= super
->next_len
;
9516 buf_len
= super
->len
;
9518 if (__le32_to_cpu(mpb
->mpb_size
) + super
->extra_space
+ len
> buf_len
) {
9519 /* ok we need a larger buf than what is currently allocated
9520 * if this allocation fails process_update will notice that
9521 * ->next_len is set and ->next_buf is NULL
9523 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) +
9524 super
->extra_space
+ len
, sector_size
);
9525 if (super
->next_buf
)
9526 free(super
->next_buf
);
9528 super
->next_len
= buf_len
;
9529 if (posix_memalign(&super
->next_buf
, sector_size
, buf_len
) == 0)
9530 memset(super
->next_buf
, 0, buf_len
);
9532 super
->next_buf
= NULL
;
9537 /* must be called while manager is quiesced */
9538 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
9540 struct imsm_super
*mpb
= super
->anchor
;
9542 struct imsm_dev
*dev
;
9543 struct imsm_map
*map
;
9544 int i
, j
, num_members
;
9547 dprintf("deleting device[%d] from imsm_super\n", index
);
9549 /* shift all indexes down one */
9550 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
9551 if (iter
->index
> (int)index
)
9553 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
9554 if (iter
->index
> (int)index
)
9557 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
9558 dev
= get_imsm_dev(super
, i
);
9559 map
= get_imsm_map(dev
, MAP_0
);
9560 num_members
= map
->num_members
;
9561 for (j
= 0; j
< num_members
; j
++) {
9562 /* update ord entries being careful not to propagate
9563 * ord-flags to the first map
9565 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_X
);
9567 if (ord_to_idx(ord
) <= index
)
9570 map
= get_imsm_map(dev
, MAP_0
);
9571 set_imsm_ord_tbl_ent(map
, j
, ord_to_idx(ord
- 1));
9572 map
= get_imsm_map(dev
, MAP_1
);
9574 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
9579 super
->updates_pending
++;
9581 struct dl
*dl
= *dlp
;
9583 *dlp
= (*dlp
)->next
;
9584 __free_imsm_disk(dl
);
9587 #endif /* MDASSEMBLE */
9589 static void close_targets(int *targets
, int new_disks
)
9596 for (i
= 0; i
< new_disks
; i
++) {
9597 if (targets
[i
] >= 0) {
9604 static int imsm_get_allowed_degradation(int level
, int raid_disks
,
9605 struct intel_super
*super
,
9606 struct imsm_dev
*dev
)
9612 struct imsm_map
*map
;
9615 ret_val
= raid_disks
/2;
9616 /* check map if all disks pairs not failed
9619 map
= get_imsm_map(dev
, MAP_0
);
9620 for (i
= 0; i
< ret_val
; i
++) {
9621 int degradation
= 0;
9622 if (get_imsm_disk(super
, i
) == NULL
)
9624 if (get_imsm_disk(super
, i
+ 1) == NULL
)
9626 if (degradation
== 2)
9629 map
= get_imsm_map(dev
, MAP_1
);
9630 /* if there is no second map
9631 * result can be returned
9635 /* check degradation in second map
9637 for (i
= 0; i
< ret_val
; i
++) {
9638 int degradation
= 0;
9639 if (get_imsm_disk(super
, i
) == NULL
)
9641 if (get_imsm_disk(super
, i
+ 1) == NULL
)
9643 if (degradation
== 2)
9657 /*******************************************************************************
9658 * Function: open_backup_targets
9659 * Description: Function opens file descriptors for all devices given in
9662 * info : general array info
9663 * raid_disks : number of disks
9664 * raid_fds : table of device's file descriptors
9665 * super : intel super for raid10 degradation check
9666 * dev : intel device for raid10 degradation check
9670 ******************************************************************************/
9671 int open_backup_targets(struct mdinfo
*info
, int raid_disks
, int *raid_fds
,
9672 struct intel_super
*super
, struct imsm_dev
*dev
)
9678 for (i
= 0; i
< raid_disks
; i
++)
9681 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
9684 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
)) {
9685 dprintf("disk is faulty!!\n");
9689 if (sd
->disk
.raid_disk
>= raid_disks
|| sd
->disk
.raid_disk
< 0)
9692 dn
= map_dev(sd
->disk
.major
,
9694 raid_fds
[sd
->disk
.raid_disk
] = dev_open(dn
, O_RDWR
);
9695 if (raid_fds
[sd
->disk
.raid_disk
] < 0) {
9696 pr_err("cannot open component\n");
9701 /* check if maximum array degradation level is not exceeded
9703 if ((raid_disks
- opened
) >
9704 imsm_get_allowed_degradation(info
->new_level
, raid_disks
,
9706 pr_err("Not enough disks can be opened.\n");
9707 close_targets(raid_fds
, raid_disks
);
9713 /*******************************************************************************
9714 * Function: validate_container_imsm
9715 * Description: This routine validates container after assemble,
9716 * eg. if devices in container are under the same controller.
9719 * info : linked list with info about devices used in array
9723 ******************************************************************************/
9724 int validate_container_imsm(struct mdinfo
*info
)
9726 if (check_env("IMSM_NO_PLATFORM"))
9729 struct sys_dev
*idev
;
9730 struct sys_dev
*hba
= NULL
;
9731 struct sys_dev
*intel_devices
= find_intel_devices();
9732 char *dev_path
= devt_to_devpath(makedev(info
->disk
.major
,
9735 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
9736 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
9745 pr_err("WARNING - Cannot detect HBA for device %s!\n",
9746 devid2kname(makedev(info
->disk
.major
, info
->disk
.minor
)));
9750 const struct imsm_orom
*orom
= get_orom_by_device_id(hba
->dev_id
);
9753 for (dev
= info
->next
; dev
; dev
= dev
->next
) {
9754 dev_path
= devt_to_devpath(makedev(dev
->disk
.major
, dev
->disk
.minor
));
9756 struct sys_dev
*hba2
= NULL
;
9757 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
9758 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
9766 const struct imsm_orom
*orom2
= hba2
== NULL
? NULL
:
9767 get_orom_by_device_id(hba2
->dev_id
);
9769 if (hba2
&& hba
->type
!= hba2
->type
) {
9770 pr_err("WARNING - HBAs of devices do not match %s != %s\n",
9771 get_sys_dev_type(hba
->type
), get_sys_dev_type(hba2
->type
));
9775 if (orom
!= orom2
) {
9776 pr_err("WARNING - IMSM container assembled with disks under different HBAs!\n"
9777 " This operation is not supported and can lead to data loss.\n");
9782 pr_err("WARNING - IMSM container assembled with disks under HBAs without IMSM platform support!\n"
9783 " This operation is not supported and can lead to data loss.\n");
9791 /*******************************************************************************
9792 * Function: imsm_record_badblock
9793 * Description: This routine stores new bad block record in BBM log
9796 * a : array containing a bad block
9797 * slot : disk number containing a bad block
9798 * sector : bad block sector
9799 * length : bad block sectors range
9803 ******************************************************************************/
9804 static int imsm_record_badblock(struct active_array
*a
, int slot
,
9805 unsigned long long sector
, int length
)
9807 struct intel_super
*super
= a
->container
->sb
;
9811 ord
= imsm_disk_slot_to_ord(a
, slot
);
9815 ret
= record_new_badblock(super
->bbm_log
, ord_to_idx(ord
), sector
,
9818 super
->updates_pending
++;
9822 /*******************************************************************************
9823 * Function: imsm_clear_badblock
9824 * Description: This routine clears bad block record from BBM log
9827 * a : array containing a bad block
9828 * slot : disk number containing a bad block
9829 * sector : bad block sector
9830 * length : bad block sectors range
9834 ******************************************************************************/
9835 static int imsm_clear_badblock(struct active_array
*a
, int slot
,
9836 unsigned long long sector
, int length
)
9838 struct intel_super
*super
= a
->container
->sb
;
9842 ord
= imsm_disk_slot_to_ord(a
, slot
);
9846 ret
= clear_badblock(super
->bbm_log
, ord_to_idx(ord
), sector
, length
);
9848 super
->updates_pending
++;
9852 /*******************************************************************************
9853 * Function: init_migr_record_imsm
9854 * Description: Function inits imsm migration record
9856 * super : imsm internal array info
9857 * dev : device under migration
9858 * info : general array info to find the smallest device
9861 ******************************************************************************/
9862 void init_migr_record_imsm(struct supertype
*st
, struct imsm_dev
*dev
,
9863 struct mdinfo
*info
)
9865 struct intel_super
*super
= st
->sb
;
9866 struct migr_record
*migr_rec
= super
->migr_rec
;
9868 unsigned long long dsize
, dev_sectors
;
9869 long long unsigned min_dev_sectors
= -1LLU;
9873 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
9874 struct imsm_map
*map_src
= get_imsm_map(dev
, MAP_1
);
9875 unsigned long long num_migr_units
;
9876 unsigned long long array_blocks
;
9878 memset(migr_rec
, 0, sizeof(struct migr_record
));
9879 migr_rec
->family_num
= __cpu_to_le32(super
->anchor
->family_num
);
9881 /* only ascending reshape supported now */
9882 migr_rec
->ascending_migr
= __cpu_to_le32(1);
9884 migr_rec
->dest_depth_per_unit
= GEN_MIGR_AREA_SIZE
/
9885 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
9886 migr_rec
->dest_depth_per_unit
*=
9887 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
9888 new_data_disks
= imsm_num_data_members(dev
, MAP_0
);
9889 migr_rec
->blocks_per_unit
=
9890 __cpu_to_le32(migr_rec
->dest_depth_per_unit
* new_data_disks
);
9891 migr_rec
->dest_depth_per_unit
=
9892 __cpu_to_le32(migr_rec
->dest_depth_per_unit
);
9893 array_blocks
= info
->component_size
* new_data_disks
;
9895 array_blocks
/ __le32_to_cpu(migr_rec
->blocks_per_unit
);
9897 if (array_blocks
% __le32_to_cpu(migr_rec
->blocks_per_unit
))
9899 migr_rec
->num_migr_units
= __cpu_to_le32(num_migr_units
);
9901 migr_rec
->post_migr_vol_cap
= dev
->size_low
;
9902 migr_rec
->post_migr_vol_cap_hi
= dev
->size_high
;
9904 /* Find the smallest dev */
9905 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
9906 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
9907 fd
= dev_open(nm
, O_RDONLY
);
9910 get_dev_size(fd
, NULL
, &dsize
);
9911 dev_sectors
= dsize
/ 512;
9912 if (dev_sectors
< min_dev_sectors
)
9913 min_dev_sectors
= dev_sectors
;
9916 migr_rec
->ckpt_area_pba
= __cpu_to_le32(min_dev_sectors
-
9917 RAID_DISK_RESERVED_BLOCKS_IMSM_HI
);
9919 write_imsm_migr_rec(st
);
9924 /*******************************************************************************
9925 * Function: save_backup_imsm
9926 * Description: Function saves critical data stripes to Migration Copy Area
9927 * and updates the current migration unit status.
9928 * Use restore_stripes() to form a destination stripe,
9929 * and to write it to the Copy Area.
9931 * st : supertype information
9932 * dev : imsm device that backup is saved for
9933 * info : general array info
9934 * buf : input buffer
9935 * length : length of data to backup (blocks_per_unit)
9939 ******************************************************************************/
9940 int save_backup_imsm(struct supertype
*st
,
9941 struct imsm_dev
*dev
,
9942 struct mdinfo
*info
,
9947 struct intel_super
*super
= st
->sb
;
9948 unsigned long long *target_offsets
;
9951 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
9952 int new_disks
= map_dest
->num_members
;
9953 int dest_layout
= 0;
9955 unsigned long long start
;
9956 int data_disks
= imsm_num_data_members(dev
, MAP_0
);
9958 targets
= xmalloc(new_disks
* sizeof(int));
9960 for (i
= 0; i
< new_disks
; i
++)
9963 target_offsets
= xcalloc(new_disks
, sizeof(unsigned long long));
9965 start
= info
->reshape_progress
* 512;
9966 for (i
= 0; i
< new_disks
; i
++) {
9967 target_offsets
[i
] = (unsigned long long)
9968 __le32_to_cpu(super
->migr_rec
->ckpt_area_pba
) * 512;
9969 /* move back copy area adderss, it will be moved forward
9970 * in restore_stripes() using start input variable
9972 target_offsets
[i
] -= start
/data_disks
;
9975 if (open_backup_targets(info
, new_disks
, targets
,
9979 dest_layout
= imsm_level_to_layout(map_dest
->raid_level
);
9980 dest_chunk
= __le16_to_cpu(map_dest
->blocks_per_strip
) * 512;
9982 if (restore_stripes(targets
, /* list of dest devices */
9983 target_offsets
, /* migration record offsets */
9986 map_dest
->raid_level
,
9988 -1, /* source backup file descriptor */
9989 0, /* input buf offset
9990 * always 0 buf is already offseted */
9994 pr_err("Error restoring stripes\n");
10002 close_targets(targets
, new_disks
);
10005 free(target_offsets
);
10010 /*******************************************************************************
10011 * Function: save_checkpoint_imsm
10012 * Description: Function called for current unit status update
10013 * in the migration record. It writes it to disk.
10015 * super : imsm internal array info
10016 * info : general array info
10020 * 2: failure, means no valid migration record
10021 * / no general migration in progress /
10022 ******************************************************************************/
10023 int save_checkpoint_imsm(struct supertype
*st
, struct mdinfo
*info
, int state
)
10025 struct intel_super
*super
= st
->sb
;
10026 unsigned long long blocks_per_unit
;
10027 unsigned long long curr_migr_unit
;
10029 if (load_imsm_migr_rec(super
, info
) != 0) {
10030 dprintf("imsm: ERROR: Cannot read migration record for checkpoint save.\n");
10034 blocks_per_unit
= __le32_to_cpu(super
->migr_rec
->blocks_per_unit
);
10035 if (blocks_per_unit
== 0) {
10036 dprintf("imsm: no migration in progress.\n");
10039 curr_migr_unit
= info
->reshape_progress
/ blocks_per_unit
;
10040 /* check if array is alligned to copy area
10041 * if it is not alligned, add one to current migration unit value
10042 * this can happend on array reshape finish only
10044 if (info
->reshape_progress
% blocks_per_unit
)
10047 super
->migr_rec
->curr_migr_unit
=
10048 __cpu_to_le32(curr_migr_unit
);
10049 super
->migr_rec
->rec_status
= __cpu_to_le32(state
);
10050 super
->migr_rec
->dest_1st_member_lba
=
10051 __cpu_to_le32(curr_migr_unit
*
10052 __le32_to_cpu(super
->migr_rec
->dest_depth_per_unit
));
10053 if (write_imsm_migr_rec(st
) < 0) {
10054 dprintf("imsm: Cannot write migration record outside backup area\n");
10061 /*******************************************************************************
10062 * Function: recover_backup_imsm
10063 * Description: Function recovers critical data from the Migration Copy Area
10064 * while assembling an array.
10066 * super : imsm internal array info
10067 * info : general array info
10069 * 0 : success (or there is no data to recover)
10071 ******************************************************************************/
10072 int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
)
10074 struct intel_super
*super
= st
->sb
;
10075 struct migr_record
*migr_rec
= super
->migr_rec
;
10076 struct imsm_map
*map_dest
;
10077 struct intel_dev
*id
= NULL
;
10078 unsigned long long read_offset
;
10079 unsigned long long write_offset
;
10081 int *targets
= NULL
;
10082 int new_disks
, i
, err
;
10085 unsigned int sector_size
= super
->sector_size
;
10086 unsigned long curr_migr_unit
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
10087 unsigned long num_migr_units
= __le32_to_cpu(migr_rec
->num_migr_units
);
10089 int skipped_disks
= 0;
10091 err
= sysfs_get_str(info
, NULL
, "array_state", (char *)buffer
, 20);
10095 /* recover data only during assemblation */
10096 if (strncmp(buffer
, "inactive", 8) != 0)
10098 /* no data to recover */
10099 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
10101 if (curr_migr_unit
>= num_migr_units
)
10104 /* find device during reshape */
10105 for (id
= super
->devlist
; id
; id
= id
->next
)
10106 if (is_gen_migration(id
->dev
))
10111 map_dest
= get_imsm_map(id
->dev
, MAP_0
);
10112 new_disks
= map_dest
->num_members
;
10114 read_offset
= (unsigned long long)
10115 __le32_to_cpu(migr_rec
->ckpt_area_pba
) * 512;
10117 write_offset
= ((unsigned long long)
10118 __le32_to_cpu(migr_rec
->dest_1st_member_lba
) +
10119 pba_of_lba0(map_dest
)) * 512;
10121 unit_len
= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
10122 if (posix_memalign((void **)&buf
, sector_size
, unit_len
) != 0)
10124 targets
= xcalloc(new_disks
, sizeof(int));
10126 if (open_backup_targets(info
, new_disks
, targets
, super
, id
->dev
)) {
10127 pr_err("Cannot open some devices belonging to array.\n");
10131 for (i
= 0; i
< new_disks
; i
++) {
10132 if (targets
[i
] < 0) {
10136 if (lseek64(targets
[i
], read_offset
, SEEK_SET
) < 0) {
10137 pr_err("Cannot seek to block: %s\n",
10142 if ((unsigned)read(targets
[i
], buf
, unit_len
) != unit_len
) {
10143 pr_err("Cannot read copy area block: %s\n",
10148 if (lseek64(targets
[i
], write_offset
, SEEK_SET
) < 0) {
10149 pr_err("Cannot seek to block: %s\n",
10154 if ((unsigned)write(targets
[i
], buf
, unit_len
) != unit_len
) {
10155 pr_err("Cannot restore block: %s\n",
10162 if (skipped_disks
> imsm_get_allowed_degradation(info
->new_level
,
10166 pr_err("Cannot restore data from backup. Too many failed disks\n");
10170 if (save_checkpoint_imsm(st
, info
, UNIT_SRC_NORMAL
)) {
10171 /* ignore error == 2, this can mean end of reshape here
10173 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL) during restart\n");
10179 for (i
= 0; i
< new_disks
; i
++)
10188 static char disk_by_path
[] = "/dev/disk/by-path/";
10190 static const char *imsm_get_disk_controller_domain(const char *path
)
10192 char disk_path
[PATH_MAX
];
10196 strcpy(disk_path
, disk_by_path
);
10197 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
10198 if (stat(disk_path
, &st
) == 0) {
10199 struct sys_dev
* hba
;
10202 path
= devt_to_devpath(st
.st_rdev
);
10205 hba
= find_disk_attached_hba(-1, path
);
10206 if (hba
&& hba
->type
== SYS_DEV_SAS
)
10208 else if (hba
&& hba
->type
== SYS_DEV_SATA
)
10212 dprintf("path: %s hba: %s attached: %s\n",
10213 path
, (hba
) ? hba
->path
: "NULL", drv
);
10219 static char *imsm_find_array_devnm_by_subdev(int subdev
, char *container
)
10221 static char devnm
[32];
10222 char subdev_name
[20];
10223 struct mdstat_ent
*mdstat
;
10225 sprintf(subdev_name
, "%d", subdev
);
10226 mdstat
= mdstat_by_subdev(subdev_name
, container
);
10230 strcpy(devnm
, mdstat
->devnm
);
10231 free_mdstat(mdstat
);
10235 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
10236 struct geo_params
*geo
,
10237 int *old_raid_disks
,
10240 /* currently we only support increasing the number of devices
10241 * for a container. This increases the number of device for each
10242 * member array. They must all be RAID0 or RAID5.
10245 struct mdinfo
*info
, *member
;
10246 int devices_that_can_grow
= 0;
10248 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): st->devnm = (%s)\n", st
->devnm
);
10250 if (geo
->size
> 0 ||
10251 geo
->level
!= UnSet
||
10252 geo
->layout
!= UnSet
||
10253 geo
->chunksize
!= 0 ||
10254 geo
->raid_disks
== UnSet
) {
10255 dprintf("imsm: Container operation is allowed for raid disks number change only.\n");
10259 if (direction
== ROLLBACK_METADATA_CHANGES
) {
10260 dprintf("imsm: Metadata changes rollback is not supported for container operation.\n");
10264 info
= container_content_imsm(st
, NULL
);
10265 for (member
= info
; member
; member
= member
->next
) {
10268 dprintf("imsm: checking device_num: %i\n",
10269 member
->container_member
);
10271 if (geo
->raid_disks
<= member
->array
.raid_disks
) {
10272 /* we work on container for Online Capacity Expansion
10273 * only so raid_disks has to grow
10275 dprintf("imsm: for container operation raid disks increase is required\n");
10279 if (info
->array
.level
!= 0 && info
->array
.level
!= 5) {
10280 /* we cannot use this container with other raid level
10282 dprintf("imsm: for container operation wrong raid level (%i) detected\n",
10283 info
->array
.level
);
10286 /* check for platform support
10287 * for this raid level configuration
10289 struct intel_super
*super
= st
->sb
;
10290 if (!is_raid_level_supported(super
->orom
,
10291 member
->array
.level
,
10292 geo
->raid_disks
)) {
10293 dprintf("platform does not support raid%d with %d disk%s\n",
10296 geo
->raid_disks
> 1 ? "s" : "");
10299 /* check if component size is aligned to chunk size
10301 if (info
->component_size
%
10302 (info
->array
.chunk_size
/512)) {
10303 dprintf("Component size is not aligned to chunk size\n");
10308 if (*old_raid_disks
&&
10309 info
->array
.raid_disks
!= *old_raid_disks
)
10311 *old_raid_disks
= info
->array
.raid_disks
;
10313 /* All raid5 and raid0 volumes in container
10314 * have to be ready for Online Capacity Expansion
10315 * so they need to be assembled. We have already
10316 * checked that no recovery etc is happening.
10318 result
= imsm_find_array_devnm_by_subdev(member
->container_member
,
10319 st
->container_devnm
);
10320 if (result
== NULL
) {
10321 dprintf("imsm: cannot find array\n");
10324 devices_that_can_grow
++;
10327 if (!member
&& devices_that_can_grow
)
10331 dprintf("Container operation allowed\n");
10333 dprintf("Error: %i\n", ret_val
);
10338 /* Function: get_spares_for_grow
10339 * Description: Allocates memory and creates list of spare devices
10340 * avaliable in container. Checks if spare drive size is acceptable.
10341 * Parameters: Pointer to the supertype structure
10342 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
10345 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
10347 unsigned long long min_size
= min_acceptable_spare_size_imsm(st
);
10348 return container_choose_spares(st
, min_size
, NULL
, NULL
, NULL
, 0);
10351 /******************************************************************************
10352 * function: imsm_create_metadata_update_for_reshape
10353 * Function creates update for whole IMSM container.
10355 ******************************************************************************/
10356 static int imsm_create_metadata_update_for_reshape(
10357 struct supertype
*st
,
10358 struct geo_params
*geo
,
10359 int old_raid_disks
,
10360 struct imsm_update_reshape
**updatep
)
10362 struct intel_super
*super
= st
->sb
;
10363 struct imsm_super
*mpb
= super
->anchor
;
10364 int update_memory_size
;
10365 struct imsm_update_reshape
*u
;
10366 struct mdinfo
*spares
;
10369 struct mdinfo
*dev
;
10371 dprintf("(enter) raid_disks = %i\n", geo
->raid_disks
);
10373 delta_disks
= geo
->raid_disks
- old_raid_disks
;
10375 /* size of all update data without anchor */
10376 update_memory_size
= sizeof(struct imsm_update_reshape
);
10378 /* now add space for spare disks that we need to add. */
10379 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
10381 u
= xcalloc(1, update_memory_size
);
10382 u
->type
= update_reshape_container_disks
;
10383 u
->old_raid_disks
= old_raid_disks
;
10384 u
->new_raid_disks
= geo
->raid_disks
;
10386 /* now get spare disks list
10388 spares
= get_spares_for_grow(st
);
10391 || delta_disks
> spares
->array
.spare_disks
) {
10392 pr_err("imsm: ERROR: Cannot get spare devices for %s.\n", geo
->dev_name
);
10397 /* we have got spares
10398 * update disk list in imsm_disk list table in anchor
10400 dprintf("imsm: %i spares are available.\n\n",
10401 spares
->array
.spare_disks
);
10403 dev
= spares
->devs
;
10404 for (i
= 0; i
< delta_disks
; i
++) {
10409 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
10411 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
10412 dl
->index
= mpb
->num_disks
;
10420 sysfs_free(spares
);
10422 dprintf("imsm: reshape update preparation :");
10423 if (i
== delta_disks
) {
10424 dprintf_cont(" OK\n");
10426 return update_memory_size
;
10429 dprintf_cont(" Error\n");
10434 /******************************************************************************
10435 * function: imsm_create_metadata_update_for_size_change()
10436 * Creates update for IMSM array for array size change.
10438 ******************************************************************************/
10439 static int imsm_create_metadata_update_for_size_change(
10440 struct supertype
*st
,
10441 struct geo_params
*geo
,
10442 struct imsm_update_size_change
**updatep
)
10444 struct intel_super
*super
= st
->sb
;
10445 int update_memory_size
;
10446 struct imsm_update_size_change
*u
;
10448 dprintf("(enter) New size = %llu\n", geo
->size
);
10450 /* size of all update data without anchor */
10451 update_memory_size
= sizeof(struct imsm_update_size_change
);
10453 u
= xcalloc(1, update_memory_size
);
10454 u
->type
= update_size_change
;
10455 u
->subdev
= super
->current_vol
;
10456 u
->new_size
= geo
->size
;
10458 dprintf("imsm: reshape update preparation : OK\n");
10461 return update_memory_size
;
10464 /******************************************************************************
10465 * function: imsm_create_metadata_update_for_migration()
10466 * Creates update for IMSM array.
10468 ******************************************************************************/
10469 static int imsm_create_metadata_update_for_migration(
10470 struct supertype
*st
,
10471 struct geo_params
*geo
,
10472 struct imsm_update_reshape_migration
**updatep
)
10474 struct intel_super
*super
= st
->sb
;
10475 int update_memory_size
;
10476 struct imsm_update_reshape_migration
*u
;
10477 struct imsm_dev
*dev
;
10478 int previous_level
= -1;
10480 dprintf("(enter) New Level = %i\n", geo
->level
);
10482 /* size of all update data without anchor */
10483 update_memory_size
= sizeof(struct imsm_update_reshape_migration
);
10485 u
= xcalloc(1, update_memory_size
);
10486 u
->type
= update_reshape_migration
;
10487 u
->subdev
= super
->current_vol
;
10488 u
->new_level
= geo
->level
;
10489 u
->new_layout
= geo
->layout
;
10490 u
->new_raid_disks
= u
->old_raid_disks
= geo
->raid_disks
;
10491 u
->new_disks
[0] = -1;
10492 u
->new_chunksize
= -1;
10494 dev
= get_imsm_dev(super
, u
->subdev
);
10496 struct imsm_map
*map
;
10498 map
= get_imsm_map(dev
, MAP_0
);
10500 int current_chunk_size
=
10501 __le16_to_cpu(map
->blocks_per_strip
) / 2;
10503 if (geo
->chunksize
!= current_chunk_size
) {
10504 u
->new_chunksize
= geo
->chunksize
/ 1024;
10505 dprintf("imsm: chunk size change from %i to %i\n",
10506 current_chunk_size
, u
->new_chunksize
);
10508 previous_level
= map
->raid_level
;
10511 if (geo
->level
== 5 && previous_level
== 0) {
10512 struct mdinfo
*spares
= NULL
;
10514 u
->new_raid_disks
++;
10515 spares
= get_spares_for_grow(st
);
10516 if (spares
== NULL
|| spares
->array
.spare_disks
< 1) {
10518 sysfs_free(spares
);
10519 update_memory_size
= 0;
10520 dprintf("error: cannot get spare device for requested migration");
10523 sysfs_free(spares
);
10525 dprintf("imsm: reshape update preparation : OK\n");
10528 return update_memory_size
;
10531 static void imsm_update_metadata_locally(struct supertype
*st
,
10532 void *buf
, int len
)
10534 struct metadata_update mu
;
10539 mu
.space_list
= NULL
;
10541 if (imsm_prepare_update(st
, &mu
))
10542 imsm_process_update(st
, &mu
);
10544 while (mu
.space_list
) {
10545 void **space
= mu
.space_list
;
10546 mu
.space_list
= *space
;
10551 /***************************************************************************
10552 * Function: imsm_analyze_change
10553 * Description: Function analyze change for single volume
10554 * and validate if transition is supported
10555 * Parameters: Geometry parameters, supertype structure,
10556 * metadata change direction (apply/rollback)
10557 * Returns: Operation type code on success, -1 if fail
10558 ****************************************************************************/
10559 enum imsm_reshape_type
imsm_analyze_change(struct supertype
*st
,
10560 struct geo_params
*geo
,
10563 struct mdinfo info
;
10565 int check_devs
= 0;
10567 /* number of added/removed disks in operation result */
10568 int devNumChange
= 0;
10569 /* imsm compatible layout value for array geometry verification */
10570 int imsm_layout
= -1;
10572 struct imsm_dev
*dev
;
10573 struct intel_super
*super
;
10574 unsigned long long current_size
;
10575 unsigned long long free_size
;
10576 unsigned long long max_size
;
10579 getinfo_super_imsm_volume(st
, &info
, NULL
);
10580 if (geo
->level
!= info
.array
.level
&& geo
->level
>= 0 &&
10581 geo
->level
!= UnSet
) {
10582 switch (info
.array
.level
) {
10584 if (geo
->level
== 5) {
10585 change
= CH_MIGRATION
;
10586 if (geo
->layout
!= ALGORITHM_LEFT_ASYMMETRIC
) {
10587 pr_err("Error. Requested Layout not supported (left-asymmetric layout is supported only)!\n");
10589 goto analyse_change_exit
;
10591 imsm_layout
= geo
->layout
;
10593 devNumChange
= 1; /* parity disk added */
10594 } else if (geo
->level
== 10) {
10595 change
= CH_TAKEOVER
;
10597 devNumChange
= 2; /* two mirrors added */
10598 imsm_layout
= 0x102; /* imsm supported layout */
10603 if (geo
->level
== 0) {
10604 change
= CH_TAKEOVER
;
10606 devNumChange
= -(geo
->raid_disks
/2);
10607 imsm_layout
= 0; /* imsm raid0 layout */
10611 if (change
== -1) {
10612 pr_err("Error. Level Migration from %d to %d not supported!\n",
10613 info
.array
.level
, geo
->level
);
10614 goto analyse_change_exit
;
10617 geo
->level
= info
.array
.level
;
10619 if (geo
->layout
!= info
.array
.layout
&&
10620 (geo
->layout
!= UnSet
&& geo
->layout
!= -1)) {
10621 change
= CH_MIGRATION
;
10622 if (info
.array
.layout
== 0 && info
.array
.level
== 5 &&
10623 geo
->layout
== 5) {
10624 /* reshape 5 -> 4 */
10625 } else if (info
.array
.layout
== 5 && info
.array
.level
== 5 &&
10626 geo
->layout
== 0) {
10627 /* reshape 4 -> 5 */
10631 pr_err("Error. Layout Migration from %d to %d not supported!\n",
10632 info
.array
.layout
, geo
->layout
);
10634 goto analyse_change_exit
;
10637 geo
->layout
= info
.array
.layout
;
10638 if (imsm_layout
== -1)
10639 imsm_layout
= info
.array
.layout
;
10642 if (geo
->chunksize
> 0 && geo
->chunksize
!= UnSet
&&
10643 geo
->chunksize
!= info
.array
.chunk_size
) {
10644 if (info
.array
.level
== 10) {
10645 pr_err("Error. Chunk size change for RAID 10 is not supported.\n");
10647 goto analyse_change_exit
;
10649 change
= CH_MIGRATION
;
10651 geo
->chunksize
= info
.array
.chunk_size
;
10654 chunk
= geo
->chunksize
/ 1024;
10657 dev
= get_imsm_dev(super
, super
->current_vol
);
10658 data_disks
= imsm_num_data_members(dev
, MAP_0
);
10659 /* compute current size per disk member
10661 current_size
= info
.custom_array_size
/ data_disks
;
10663 if (geo
->size
> 0 && geo
->size
!= MAX_SIZE
) {
10664 /* align component size
10666 geo
->size
= imsm_component_size_aligment_check(
10667 get_imsm_raid_level(dev
->vol
.map
),
10668 chunk
* 1024, super
->sector_size
,
10670 if (geo
->size
== 0) {
10671 pr_err("Error. Size expansion is supported only (current size is %llu, requested size /rounded/ is 0).\n",
10673 goto analyse_change_exit
;
10677 if (current_size
!= geo
->size
&& geo
->size
> 0) {
10678 if (change
!= -1) {
10679 pr_err("Error. Size change should be the only one at a time.\n");
10681 goto analyse_change_exit
;
10683 if ((super
->current_vol
+ 1) != super
->anchor
->num_raid_devs
) {
10684 pr_err("Error. The last volume in container can be expanded only (%i/%s).\n",
10685 super
->current_vol
, st
->devnm
);
10686 goto analyse_change_exit
;
10688 /* check the maximum available size
10690 rv
= imsm_get_free_size(st
, dev
->vol
.map
->num_members
,
10691 0, chunk
, &free_size
);
10693 /* Cannot find maximum available space
10697 max_size
= free_size
+ current_size
;
10698 /* align component size
10700 max_size
= imsm_component_size_aligment_check(
10701 get_imsm_raid_level(dev
->vol
.map
),
10702 chunk
* 1024, super
->sector_size
,
10705 if (geo
->size
== MAX_SIZE
) {
10706 /* requested size change to the maximum available size
10708 if (max_size
== 0) {
10709 pr_err("Error. Cannot find maximum available space.\n");
10711 goto analyse_change_exit
;
10713 geo
->size
= max_size
;
10716 if (direction
== ROLLBACK_METADATA_CHANGES
) {
10717 /* accept size for rollback only
10720 /* round size due to metadata compatibility
10722 geo
->size
= (geo
->size
>> SECT_PER_MB_SHIFT
)
10723 << SECT_PER_MB_SHIFT
;
10724 dprintf("Prepare update for size change to %llu\n",
10726 if (current_size
>= geo
->size
) {
10727 pr_err("Error. Size expansion is supported only (current size is %llu, requested size /rounded/ is %llu).\n",
10728 current_size
, geo
->size
);
10729 goto analyse_change_exit
;
10731 if (max_size
&& geo
->size
> max_size
) {
10732 pr_err("Error. Requested size is larger than maximum available size (maximum available size is %llu, requested size /rounded/ is %llu).\n",
10733 max_size
, geo
->size
);
10734 goto analyse_change_exit
;
10737 geo
->size
*= data_disks
;
10738 geo
->raid_disks
= dev
->vol
.map
->num_members
;
10739 change
= CH_ARRAY_SIZE
;
10741 if (!validate_geometry_imsm(st
,
10744 geo
->raid_disks
+ devNumChange
,
10746 geo
->size
, INVALID_SECTORS
,
10751 struct intel_super
*super
= st
->sb
;
10752 struct imsm_super
*mpb
= super
->anchor
;
10754 if (mpb
->num_raid_devs
> 1) {
10755 pr_err("Error. Cannot perform operation on %s- for this operation it MUST be single array in container\n",
10761 analyse_change_exit
:
10762 if (direction
== ROLLBACK_METADATA_CHANGES
&&
10763 (change
== CH_MIGRATION
|| change
== CH_TAKEOVER
)) {
10764 dprintf("imsm: Metadata changes rollback is not supported for migration and takeover operations.\n");
10770 int imsm_takeover(struct supertype
*st
, struct geo_params
*geo
)
10772 struct intel_super
*super
= st
->sb
;
10773 struct imsm_update_takeover
*u
;
10775 u
= xmalloc(sizeof(struct imsm_update_takeover
));
10777 u
->type
= update_takeover
;
10778 u
->subarray
= super
->current_vol
;
10780 /* 10->0 transition */
10781 if (geo
->level
== 0)
10782 u
->direction
= R10_TO_R0
;
10784 /* 0->10 transition */
10785 if (geo
->level
== 10)
10786 u
->direction
= R0_TO_R10
;
10788 /* update metadata locally */
10789 imsm_update_metadata_locally(st
, u
,
10790 sizeof(struct imsm_update_takeover
));
10791 /* and possibly remotely */
10792 if (st
->update_tail
)
10793 append_metadata_update(st
, u
,
10794 sizeof(struct imsm_update_takeover
));
10801 static int imsm_reshape_super(struct supertype
*st
, unsigned long long size
,
10803 int layout
, int chunksize
, int raid_disks
,
10804 int delta_disks
, char *backup
, char *dev
,
10805 int direction
, int verbose
)
10808 struct geo_params geo
;
10810 dprintf("(enter)\n");
10812 memset(&geo
, 0, sizeof(struct geo_params
));
10814 geo
.dev_name
= dev
;
10815 strcpy(geo
.devnm
, st
->devnm
);
10818 geo
.layout
= layout
;
10819 geo
.chunksize
= chunksize
;
10820 geo
.raid_disks
= raid_disks
;
10821 if (delta_disks
!= UnSet
)
10822 geo
.raid_disks
+= delta_disks
;
10824 dprintf("for level : %i\n", geo
.level
);
10825 dprintf("for raid_disks : %i\n", geo
.raid_disks
);
10827 if (experimental() == 0)
10830 if (strcmp(st
->container_devnm
, st
->devnm
) == 0) {
10831 /* On container level we can only increase number of devices. */
10832 dprintf("imsm: info: Container operation\n");
10833 int old_raid_disks
= 0;
10835 if (imsm_reshape_is_allowed_on_container(
10836 st
, &geo
, &old_raid_disks
, direction
)) {
10837 struct imsm_update_reshape
*u
= NULL
;
10840 len
= imsm_create_metadata_update_for_reshape(
10841 st
, &geo
, old_raid_disks
, &u
);
10844 dprintf("imsm: Cannot prepare update\n");
10845 goto exit_imsm_reshape_super
;
10849 /* update metadata locally */
10850 imsm_update_metadata_locally(st
, u
, len
);
10851 /* and possibly remotely */
10852 if (st
->update_tail
)
10853 append_metadata_update(st
, u
, len
);
10858 pr_err("(imsm) Operation is not allowed on this container\n");
10861 /* On volume level we support following operations
10862 * - takeover: raid10 -> raid0; raid0 -> raid10
10863 * - chunk size migration
10864 * - migration: raid5 -> raid0; raid0 -> raid5
10866 struct intel_super
*super
= st
->sb
;
10867 struct intel_dev
*dev
= super
->devlist
;
10869 dprintf("imsm: info: Volume operation\n");
10870 /* find requested device */
10873 imsm_find_array_devnm_by_subdev(
10874 dev
->index
, st
->container_devnm
);
10875 if (devnm
&& strcmp(devnm
, geo
.devnm
) == 0)
10880 pr_err("Cannot find %s (%s) subarray\n",
10881 geo
.dev_name
, geo
.devnm
);
10882 goto exit_imsm_reshape_super
;
10884 super
->current_vol
= dev
->index
;
10885 change
= imsm_analyze_change(st
, &geo
, direction
);
10888 ret_val
= imsm_takeover(st
, &geo
);
10890 case CH_MIGRATION
: {
10891 struct imsm_update_reshape_migration
*u
= NULL
;
10893 imsm_create_metadata_update_for_migration(
10896 dprintf("imsm: Cannot prepare update\n");
10900 /* update metadata locally */
10901 imsm_update_metadata_locally(st
, u
, len
);
10902 /* and possibly remotely */
10903 if (st
->update_tail
)
10904 append_metadata_update(st
, u
, len
);
10909 case CH_ARRAY_SIZE
: {
10910 struct imsm_update_size_change
*u
= NULL
;
10912 imsm_create_metadata_update_for_size_change(
10915 dprintf("imsm: Cannot prepare update\n");
10919 /* update metadata locally */
10920 imsm_update_metadata_locally(st
, u
, len
);
10921 /* and possibly remotely */
10922 if (st
->update_tail
)
10923 append_metadata_update(st
, u
, len
);
10933 exit_imsm_reshape_super
:
10934 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
10938 #define COMPLETED_OK 0
10939 #define COMPLETED_NONE 1
10940 #define COMPLETED_DELAYED 2
10942 static int read_completed(int fd
, unsigned long long *val
)
10947 ret
= sysfs_fd_get_str(fd
, buf
, 50);
10951 ret
= COMPLETED_OK
;
10952 if (strncmp(buf
, "none", 4) == 0) {
10953 ret
= COMPLETED_NONE
;
10954 } else if (strncmp(buf
, "delayed", 7) == 0) {
10955 ret
= COMPLETED_DELAYED
;
10958 *val
= strtoull(buf
, &ep
, 0);
10959 if (ep
== buf
|| (*ep
!= 0 && *ep
!= '\n' && *ep
!= ' '))
10965 /*******************************************************************************
10966 * Function: wait_for_reshape_imsm
10967 * Description: Function writes new sync_max value and waits until
10968 * reshape process reach new position
10970 * sra : general array info
10971 * ndata : number of disks in new array's layout
10974 * 1 : there is no reshape in progress,
10976 ******************************************************************************/
10977 int wait_for_reshape_imsm(struct mdinfo
*sra
, int ndata
)
10979 int fd
= sysfs_get_fd(sra
, NULL
, "sync_completed");
10981 unsigned long long completed
;
10982 /* to_complete : new sync_max position */
10983 unsigned long long to_complete
= sra
->reshape_progress
;
10984 unsigned long long position_to_set
= to_complete
/ ndata
;
10987 dprintf("cannot open reshape_position\n");
10992 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
10994 dprintf("cannot read reshape_position (no reshape in progres)\n");
11003 if (completed
> position_to_set
) {
11004 dprintf("wrong next position to set %llu (%llu)\n",
11005 to_complete
, position_to_set
);
11009 dprintf("Position set: %llu\n", position_to_set
);
11010 if (sysfs_set_num(sra
, NULL
, "sync_max",
11011 position_to_set
) != 0) {
11012 dprintf("cannot set reshape position to %llu\n",
11021 int timeout
= 3000;
11023 sysfs_wait(fd
, &timeout
);
11024 if (sysfs_get_str(sra
, NULL
, "sync_action",
11026 strncmp(action
, "reshape", 7) != 0) {
11027 if (strncmp(action
, "idle", 4) == 0)
11033 rc
= read_completed(fd
, &completed
);
11035 dprintf("cannot read reshape_position (in loop)\n");
11038 } else if (rc
== COMPLETED_NONE
)
11040 } while (completed
< position_to_set
);
11046 /*******************************************************************************
11047 * Function: check_degradation_change
11048 * Description: Check that array hasn't become failed.
11050 * info : for sysfs access
11051 * sources : source disks descriptors
11052 * degraded: previous degradation level
11054 * degradation level
11055 ******************************************************************************/
11056 int check_degradation_change(struct mdinfo
*info
,
11060 unsigned long long new_degraded
;
11063 rv
= sysfs_get_ll(info
, NULL
, "degraded", &new_degraded
);
11064 if (rv
== -1 || (new_degraded
!= (unsigned long long)degraded
)) {
11065 /* check each device to ensure it is still working */
11068 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
11069 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
11071 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
11074 if (sysfs_get_str(info
,
11075 sd
, "state", sbuf
, sizeof(sbuf
)) < 0 ||
11076 strstr(sbuf
, "faulty") ||
11077 strstr(sbuf
, "in_sync") == NULL
) {
11078 /* this device is dead */
11079 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
11080 if (sd
->disk
.raid_disk
>= 0 &&
11081 sources
[sd
->disk
.raid_disk
] >= 0) {
11083 sd
->disk
.raid_disk
]);
11084 sources
[sd
->disk
.raid_disk
] =
11093 return new_degraded
;
11096 /*******************************************************************************
11097 * Function: imsm_manage_reshape
11098 * Description: Function finds array under reshape and it manages reshape
11099 * process. It creates stripes backups (if required) and sets
11102 * afd : Backup handle (nattive) - not used
11103 * sra : general array info
11104 * reshape : reshape parameters - not used
11105 * st : supertype structure
11106 * blocks : size of critical section [blocks]
11107 * fds : table of source device descriptor
11108 * offsets : start of array (offest per devices)
11110 * destfd : table of destination device descriptor
11111 * destoffsets : table of destination offsets (per device)
11113 * 1 : success, reshape is done
11115 ******************************************************************************/
11116 static int imsm_manage_reshape(
11117 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
11118 struct supertype
*st
, unsigned long backup_blocks
,
11119 int *fds
, unsigned long long *offsets
,
11120 int dests
, int *destfd
, unsigned long long *destoffsets
)
11123 struct intel_super
*super
= st
->sb
;
11124 struct intel_dev
*dv
;
11125 unsigned int sector_size
= super
->sector_size
;
11126 struct imsm_dev
*dev
= NULL
;
11127 struct imsm_map
*map_src
;
11128 int migr_vol_qan
= 0;
11129 int ndata
, odata
; /* [bytes] */
11130 int chunk
; /* [bytes] */
11131 struct migr_record
*migr_rec
;
11133 unsigned int buf_size
; /* [bytes] */
11134 unsigned long long max_position
; /* array size [bytes] */
11135 unsigned long long next_step
; /* [blocks]/[bytes] */
11136 unsigned long long old_data_stripe_length
;
11137 unsigned long long start_src
; /* [bytes] */
11138 unsigned long long start
; /* [bytes] */
11139 unsigned long long start_buf_shift
; /* [bytes] */
11141 int source_layout
= 0;
11146 if (!fds
|| !offsets
)
11149 /* Find volume during the reshape */
11150 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
11151 if (dv
->dev
->vol
.migr_type
== MIGR_GEN_MIGR
11152 && dv
->dev
->vol
.migr_state
== 1) {
11157 /* Only one volume can migrate at the same time */
11158 if (migr_vol_qan
!= 1) {
11159 pr_err("%s", migr_vol_qan
?
11160 "Number of migrating volumes greater than 1\n" :
11161 "There is no volume during migrationg\n");
11165 map_src
= get_imsm_map(dev
, MAP_1
);
11166 if (map_src
== NULL
)
11169 ndata
= imsm_num_data_members(dev
, MAP_0
);
11170 odata
= imsm_num_data_members(dev
, MAP_1
);
11172 chunk
= __le16_to_cpu(map_src
->blocks_per_strip
) * 512;
11173 old_data_stripe_length
= odata
* chunk
;
11175 migr_rec
= super
->migr_rec
;
11177 /* initialize migration record for start condition */
11178 if (sra
->reshape_progress
== 0)
11179 init_migr_record_imsm(st
, dev
, sra
);
11181 if (__le32_to_cpu(migr_rec
->rec_status
) != UNIT_SRC_NORMAL
) {
11182 dprintf("imsm: cannot restart migration when data are present in copy area.\n");
11185 /* Save checkpoint to update migration record for current
11186 * reshape position (in md). It can be farther than current
11187 * reshape position in metadata.
11189 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
11190 /* ignore error == 2, this can mean end of reshape here
11192 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL, initial save)\n");
11197 /* size for data */
11198 buf_size
= __le32_to_cpu(migr_rec
->blocks_per_unit
) * 512;
11199 /* extend buffer size for parity disk */
11200 buf_size
+= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
11201 /* add space for stripe aligment */
11202 buf_size
+= old_data_stripe_length
;
11203 if (posix_memalign((void **)&buf
, MAX_SECTOR_SIZE
, buf_size
)) {
11204 dprintf("imsm: Cannot allocate checkpoint buffer\n");
11208 max_position
= sra
->component_size
* ndata
;
11209 source_layout
= imsm_level_to_layout(map_src
->raid_level
);
11211 while (__le32_to_cpu(migr_rec
->curr_migr_unit
) <
11212 __le32_to_cpu(migr_rec
->num_migr_units
)) {
11213 /* current reshape position [blocks] */
11214 unsigned long long current_position
=
11215 __le32_to_cpu(migr_rec
->blocks_per_unit
)
11216 * __le32_to_cpu(migr_rec
->curr_migr_unit
);
11217 unsigned long long border
;
11219 /* Check that array hasn't become failed.
11221 degraded
= check_degradation_change(sra
, fds
, degraded
);
11222 if (degraded
> 1) {
11223 dprintf("imsm: Abort reshape due to degradation level (%i)\n", degraded
);
11227 next_step
= __le32_to_cpu(migr_rec
->blocks_per_unit
);
11229 if ((current_position
+ next_step
) > max_position
)
11230 next_step
= max_position
- current_position
;
11232 start
= current_position
* 512;
11234 /* align reading start to old geometry */
11235 start_buf_shift
= start
% old_data_stripe_length
;
11236 start_src
= start
- start_buf_shift
;
11238 border
= (start_src
/ odata
) - (start
/ ndata
);
11240 if (border
<= __le32_to_cpu(migr_rec
->dest_depth_per_unit
)) {
11241 /* save critical stripes to buf
11242 * start - start address of current unit
11243 * to backup [bytes]
11244 * start_src - start address of current unit
11245 * to backup alligned to source array
11248 unsigned long long next_step_filler
;
11249 unsigned long long copy_length
= next_step
* 512;
11251 /* allign copy area length to stripe in old geometry */
11252 next_step_filler
= ((copy_length
+ start_buf_shift
)
11253 % old_data_stripe_length
);
11254 if (next_step_filler
)
11255 next_step_filler
= (old_data_stripe_length
11256 - next_step_filler
);
11257 dprintf("save_stripes() parameters: start = %llu,\tstart_src = %llu,\tnext_step*512 = %llu,\tstart_in_buf_shift = %llu,\tnext_step_filler = %llu\n",
11258 start
, start_src
, copy_length
,
11259 start_buf_shift
, next_step_filler
);
11261 if (save_stripes(fds
, offsets
, map_src
->num_members
,
11262 chunk
, map_src
->raid_level
,
11263 source_layout
, 0, NULL
, start_src
,
11265 next_step_filler
+ start_buf_shift
,
11267 dprintf("imsm: Cannot save stripes to buffer\n");
11270 /* Convert data to destination format and store it
11271 * in backup general migration area
11273 if (save_backup_imsm(st
, dev
, sra
,
11274 buf
+ start_buf_shift
, copy_length
)) {
11275 dprintf("imsm: Cannot save stripes to target devices\n");
11278 if (save_checkpoint_imsm(st
, sra
,
11279 UNIT_SRC_IN_CP_AREA
)) {
11280 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_IN_CP_AREA)\n");
11284 /* set next step to use whole border area */
11285 border
/= next_step
;
11287 next_step
*= border
;
11289 /* When data backed up, checkpoint stored,
11290 * kick the kernel to reshape unit of data
11292 next_step
= next_step
+ sra
->reshape_progress
;
11293 /* limit next step to array max position */
11294 if (next_step
> max_position
)
11295 next_step
= max_position
;
11296 sysfs_set_num(sra
, NULL
, "suspend_lo", sra
->reshape_progress
);
11297 sysfs_set_num(sra
, NULL
, "suspend_hi", next_step
);
11298 sra
->reshape_progress
= next_step
;
11300 /* wait until reshape finish */
11301 if (wait_for_reshape_imsm(sra
, ndata
)) {
11302 dprintf("wait_for_reshape_imsm returned error!\n");
11308 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
11309 /* ignore error == 2, this can mean end of reshape here
11311 dprintf("imsm: Cannot write checkpoint to migration record (UNIT_SRC_NORMAL)\n");
11317 /* clear migr_rec on disks after successful migration */
11320 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SECTORS
*sector_size
);
11321 for (d
= super
->disks
; d
; d
= d
->next
) {
11322 if (d
->index
< 0 || is_failed(&d
->disk
))
11324 unsigned long long dsize
;
11326 get_dev_size(d
->fd
, NULL
, &dsize
);
11327 if (lseek64(d
->fd
, dsize
- MIGR_REC_SECTOR_POSITION
*sector_size
,
11329 if (write(d
->fd
, super
->migr_rec_buf
,
11330 MIGR_REC_BUF_SECTORS
*sector_size
) !=
11331 MIGR_REC_BUF_SECTORS
*sector_size
)
11332 perror("Write migr_rec failed");
11336 /* return '1' if done */
11340 /* See Grow.c: abort_reshape() for further explanation */
11341 sysfs_set_num(sra
, NULL
, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL
);
11342 sysfs_set_num(sra
, NULL
, "suspend_hi", 0);
11343 sysfs_set_num(sra
, NULL
, "suspend_lo", 0);
11348 #endif /* MDASSEMBLE */
11350 struct superswitch super_imsm
= {
11352 .examine_super
= examine_super_imsm
,
11353 .brief_examine_super
= brief_examine_super_imsm
,
11354 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
11355 .export_examine_super
= export_examine_super_imsm
,
11356 .detail_super
= detail_super_imsm
,
11357 .brief_detail_super
= brief_detail_super_imsm
,
11358 .write_init_super
= write_init_super_imsm
,
11359 .validate_geometry
= validate_geometry_imsm
,
11360 .add_to_super
= add_to_super_imsm
,
11361 .remove_from_super
= remove_from_super_imsm
,
11362 .detail_platform
= detail_platform_imsm
,
11363 .export_detail_platform
= export_detail_platform_imsm
,
11364 .kill_subarray
= kill_subarray_imsm
,
11365 .update_subarray
= update_subarray_imsm
,
11366 .load_container
= load_container_imsm
,
11367 .default_geometry
= default_geometry_imsm
,
11368 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
11369 .reshape_super
= imsm_reshape_super
,
11370 .manage_reshape
= imsm_manage_reshape
,
11371 .recover_backup
= recover_backup_imsm
,
11372 .copy_metadata
= copy_metadata_imsm
,
11374 .match_home
= match_home_imsm
,
11375 .uuid_from_super
= uuid_from_super_imsm
,
11376 .getinfo_super
= getinfo_super_imsm
,
11377 .getinfo_super_disks
= getinfo_super_disks_imsm
,
11378 .update_super
= update_super_imsm
,
11380 .avail_size
= avail_size_imsm
,
11381 .min_acceptable_spare_size
= min_acceptable_spare_size_imsm
,
11383 .compare_super
= compare_super_imsm
,
11385 .load_super
= load_super_imsm
,
11386 .init_super
= init_super_imsm
,
11387 .store_super
= store_super_imsm
,
11388 .free_super
= free_super_imsm
,
11389 .match_metadata_desc
= match_metadata_desc_imsm
,
11390 .container_content
= container_content_imsm
,
11391 .validate_container
= validate_container_imsm
,
11398 .open_new
= imsm_open_new
,
11399 .set_array_state
= imsm_set_array_state
,
11400 .set_disk
= imsm_set_disk
,
11401 .sync_metadata
= imsm_sync_metadata
,
11402 .activate_spare
= imsm_activate_spare
,
11403 .process_update
= imsm_process_update
,
11404 .prepare_update
= imsm_prepare_update
,
11405 .record_bad_block
= imsm_record_badblock
,
11406 .clear_bad_block
= imsm_clear_badblock
,
11407 #endif /* MDASSEMBLE */