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)
86 /* Define attributes that are unused but not harmful */
87 #define MPB_ATTRIB_IGNORED (MPB_ATTRIB_NEVER_USE)
89 #define MPB_SECTOR_CNT 2210
90 #define IMSM_RESERVED_SECTORS 4096
91 #define NUM_BLOCKS_DIRTY_STRIPE_REGION 2056
92 #define SECT_PER_MB_SHIFT 11
94 /* Disk configuration info. */
95 #define IMSM_MAX_DEVICES 255
97 __u8 serial
[MAX_RAID_SERIAL_LEN
];/* 0xD8 - 0xE7 ascii serial number */
98 __u32 total_blocks_lo
; /* 0xE8 - 0xEB total blocks lo */
99 __u32 scsi_id
; /* 0xEC - 0xEF scsi ID */
100 #define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
101 #define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
102 #define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
103 __u32 status
; /* 0xF0 - 0xF3 */
104 __u32 owner_cfg_num
; /* which config 0,1,2... owns this disk */
105 __u32 total_blocks_hi
; /* 0xF4 - 0xF5 total blocks hi */
106 #define IMSM_DISK_FILLERS 3
107 __u32 filler
[IMSM_DISK_FILLERS
]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
110 /* map selector for map managment
116 /* RAID map configuration infos. */
118 __u32 pba_of_lba0_lo
; /* start address of partition */
119 __u32 blocks_per_member_lo
;/* blocks per member */
120 __u32 num_data_stripes_lo
; /* number of data stripes */
121 __u16 blocks_per_strip
;
122 __u8 map_state
; /* Normal, Uninitialized, Degraded, Failed */
123 #define IMSM_T_STATE_NORMAL 0
124 #define IMSM_T_STATE_UNINITIALIZED 1
125 #define IMSM_T_STATE_DEGRADED 2
126 #define IMSM_T_STATE_FAILED 3
128 #define IMSM_T_RAID0 0
129 #define IMSM_T_RAID1 1
130 #define IMSM_T_RAID5 5 /* since metadata version 1.2.02 ? */
131 __u8 num_members
; /* number of member disks */
132 __u8 num_domains
; /* number of parity domains */
133 __u8 failed_disk_num
; /* valid only when state is degraded */
135 __u32 pba_of_lba0_hi
;
136 __u32 blocks_per_member_hi
;
137 __u32 num_data_stripes_hi
;
138 __u32 filler
[4]; /* expansion area */
139 #define IMSM_ORD_REBUILD (1 << 24)
140 __u32 disk_ord_tbl
[1]; /* disk_ord_tbl[num_members],
141 * top byte contains some flags
143 } __attribute__ ((packed
));
146 __u32 curr_migr_unit
;
147 __u32 checkpoint_id
; /* id to access curr_migr_unit */
148 __u8 migr_state
; /* Normal or Migrating */
150 #define MIGR_REBUILD 1
151 #define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
152 #define MIGR_GEN_MIGR 3
153 #define MIGR_STATE_CHANGE 4
154 #define MIGR_REPAIR 5
155 __u8 migr_type
; /* Initializing, Rebuilding, ... */
157 __u8 fs_state
; /* fast-sync state for CnG (0xff == disabled) */
158 __u16 verify_errors
; /* number of mismatches */
159 __u16 bad_blocks
; /* number of bad blocks during verify */
161 struct imsm_map map
[1];
162 /* here comes another one if migr_state */
163 } __attribute__ ((packed
));
166 __u8 volume
[MAX_RAID_SERIAL_LEN
];
169 #define DEV_BOOTABLE __cpu_to_le32(0x01)
170 #define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
171 #define DEV_READ_COALESCING __cpu_to_le32(0x04)
172 #define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
173 #define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
174 #define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
175 #define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
176 #define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
177 #define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
178 #define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
179 #define DEV_CLONE_N_GO __cpu_to_le32(0x400)
180 #define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
181 #define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
182 __u32 status
; /* Persistent RaidDev status */
183 __u32 reserved_blocks
; /* Reserved blocks at beginning of volume */
187 __u8 cng_master_disk
;
191 #define IMSM_DEV_FILLERS 10
192 __u32 filler
[IMSM_DEV_FILLERS
];
194 } __attribute__ ((packed
));
197 __u8 sig
[MAX_SIGNATURE_LENGTH
]; /* 0x00 - 0x1F */
198 __u32 check_sum
; /* 0x20 - 0x23 MPB Checksum */
199 __u32 mpb_size
; /* 0x24 - 0x27 Size of MPB */
200 __u32 family_num
; /* 0x28 - 0x2B Checksum from first time this config was written */
201 __u32 generation_num
; /* 0x2C - 0x2F Incremented each time this array's MPB is written */
202 __u32 error_log_size
; /* 0x30 - 0x33 in bytes */
203 __u32 attributes
; /* 0x34 - 0x37 */
204 __u8 num_disks
; /* 0x38 Number of configured disks */
205 __u8 num_raid_devs
; /* 0x39 Number of configured volumes */
206 __u8 error_log_pos
; /* 0x3A */
207 __u8 fill
[1]; /* 0x3B */
208 __u32 cache_size
; /* 0x3c - 0x40 in mb */
209 __u32 orig_family_num
; /* 0x40 - 0x43 original family num */
210 __u32 pwr_cycle_count
; /* 0x44 - 0x47 simulated power cycle count for array */
211 __u32 bbm_log_size
; /* 0x48 - 0x4B - size of bad Block Mgmt Log in bytes */
212 #define IMSM_FILLERS 35
213 __u32 filler
[IMSM_FILLERS
]; /* 0x4C - 0xD7 RAID_MPB_FILLERS */
214 struct imsm_disk disk
[1]; /* 0xD8 diskTbl[numDisks] */
215 /* here comes imsm_dev[num_raid_devs] */
216 /* here comes BBM logs */
217 } __attribute__ ((packed
));
219 #define BBM_LOG_MAX_ENTRIES 254
221 struct bbm_log_entry
{
222 __u64 defective_block_start
;
223 #define UNREADABLE 0xFFFFFFFF
224 __u32 spare_block_offset
;
225 __u16 remapped_marked_count
;
227 } __attribute__ ((__packed__
));
230 __u32 signature
; /* 0xABADB10C */
232 __u32 reserved_spare_block_count
; /* 0 */
233 __u32 reserved
; /* 0xFFFF */
234 __u64 first_spare_lba
;
235 struct bbm_log_entry mapped_block_entries
[BBM_LOG_MAX_ENTRIES
];
236 } __attribute__ ((__packed__
));
239 static char *map_state_str
[] = { "normal", "uninitialized", "degraded", "failed" };
242 #define RAID_DISK_RESERVED_BLOCKS_IMSM_HI 2209
244 #define GEN_MIGR_AREA_SIZE 2048 /* General Migration Copy Area size in blocks */
246 #define MIGR_REC_BUF_SIZE 512 /* size of migr_record i/o buffer */
247 #define MIGR_REC_POSITION 512 /* migr_record position offset on disk,
248 * MIGR_REC_BUF_SIZE <= MIGR_REC_POSITION
251 #define UNIT_SRC_NORMAL 0 /* Source data for curr_migr_unit must
252 * be recovered using srcMap */
253 #define UNIT_SRC_IN_CP_AREA 1 /* Source data for curr_migr_unit has
254 * already been migrated and must
255 * be recovered from checkpoint area */
257 __u32 rec_status
; /* Status used to determine how to restart
258 * migration in case it aborts
260 __u32 curr_migr_unit
; /* 0..numMigrUnits-1 */
261 __u32 family_num
; /* Family number of MPB
262 * containing the RaidDev
263 * that is migrating */
264 __u32 ascending_migr
; /* True if migrating in increasing
266 __u32 blocks_per_unit
; /* Num disk blocks per unit of operation */
267 __u32 dest_depth_per_unit
; /* Num member blocks each destMap
269 * advances per unit-of-operation */
270 __u32 ckpt_area_pba
; /* Pba of first block of ckpt copy area */
271 __u32 dest_1st_member_lba
; /* First member lba on first
272 * stripe of destination */
273 __u32 num_migr_units
; /* Total num migration units-of-op */
274 __u32 post_migr_vol_cap
; /* Size of volume after
275 * migration completes */
276 __u32 post_migr_vol_cap_hi
; /* Expansion space for LBA64 */
277 __u32 ckpt_read_disk_num
; /* Which member disk in destSubMap[0] the
278 * migration ckpt record was read from
279 * (for recovered migrations) */
280 } __attribute__ ((__packed__
));
285 * 2: metadata does not match
293 struct md_list
*next
;
296 #define pr_vrb(fmt, arg...) (void) (verbose && pr_err(fmt, ##arg))
298 static __u8
migr_type(struct imsm_dev
*dev
)
300 if (dev
->vol
.migr_type
== MIGR_VERIFY
&&
301 dev
->status
& DEV_VERIFY_AND_FIX
)
304 return dev
->vol
.migr_type
;
307 static void set_migr_type(struct imsm_dev
*dev
, __u8 migr_type
)
309 /* for compatibility with older oroms convert MIGR_REPAIR, into
310 * MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status
312 if (migr_type
== MIGR_REPAIR
) {
313 dev
->vol
.migr_type
= MIGR_VERIFY
;
314 dev
->status
|= DEV_VERIFY_AND_FIX
;
316 dev
->vol
.migr_type
= migr_type
;
317 dev
->status
&= ~DEV_VERIFY_AND_FIX
;
321 static unsigned int sector_count(__u32 bytes
)
323 return ROUND_UP(bytes
, 512) / 512;
326 static unsigned int mpb_sectors(struct imsm_super
*mpb
)
328 return sector_count(__le32_to_cpu(mpb
->mpb_size
));
332 struct imsm_dev
*dev
;
333 struct intel_dev
*next
;
338 enum sys_dev_type type
;
341 struct intel_hba
*next
;
348 /* internal representation of IMSM metadata */
351 void *buf
; /* O_DIRECT buffer for reading/writing metadata */
352 struct imsm_super
*anchor
; /* immovable parameters */
355 void *migr_rec_buf
; /* buffer for I/O operations */
356 struct migr_record
*migr_rec
; /* migration record */
358 int clean_migration_record_by_mdmon
; /* when reshape is switched to next
359 array, it indicates that mdmon is allowed to clean migration
361 size_t len
; /* size of the 'buf' allocation */
362 void *next_buf
; /* for realloc'ing buf from the manager */
364 int updates_pending
; /* count of pending updates for mdmon */
365 int current_vol
; /* index of raid device undergoing creation */
366 unsigned long long create_offset
; /* common start for 'current_vol' */
367 __u32 random
; /* random data for seeding new family numbers */
368 struct intel_dev
*devlist
;
372 __u8 serial
[MAX_RAID_SERIAL_LEN
];
375 struct imsm_disk disk
;
378 struct extent
*e
; /* for determining freespace @ create */
379 int raiddisk
; /* slot to fill in autolayout */
381 } *disks
, *current_disk
;
382 struct dl
*disk_mgmt_list
; /* list of disks to add/remove while mdmon
384 struct dl
*missing
; /* disks removed while we weren't looking */
385 struct bbm_log
*bbm_log
;
386 struct intel_hba
*hba
; /* device path of the raid controller for this metadata */
387 const struct imsm_orom
*orom
; /* platform firmware support */
388 struct intel_super
*next
; /* (temp) list for disambiguating family_num */
392 struct imsm_disk disk
;
393 #define IMSM_UNKNOWN_OWNER (-1)
395 struct intel_disk
*next
;
399 unsigned long long start
, size
;
402 /* definitions of reshape process types */
403 enum imsm_reshape_type
{
409 /* definition of messages passed to imsm_process_update */
410 enum imsm_update_type
{
411 update_activate_spare
,
415 update_add_remove_disk
,
416 update_reshape_container_disks
,
417 update_reshape_migration
,
419 update_general_migration_checkpoint
,
423 struct imsm_update_activate_spare
{
424 enum imsm_update_type type
;
428 struct imsm_update_activate_spare
*next
;
434 unsigned long long size
;
441 enum takeover_direction
{
445 struct imsm_update_takeover
{
446 enum imsm_update_type type
;
448 enum takeover_direction direction
;
451 struct imsm_update_reshape
{
452 enum imsm_update_type type
;
456 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
459 struct imsm_update_reshape_migration
{
460 enum imsm_update_type type
;
463 /* fields for array migration changes
470 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
473 struct imsm_update_size_change
{
474 enum imsm_update_type type
;
479 struct imsm_update_general_migration_checkpoint
{
480 enum imsm_update_type type
;
481 __u32 curr_migr_unit
;
485 __u8 serial
[MAX_RAID_SERIAL_LEN
];
488 struct imsm_update_create_array
{
489 enum imsm_update_type type
;
494 struct imsm_update_kill_array
{
495 enum imsm_update_type type
;
499 struct imsm_update_rename_array
{
500 enum imsm_update_type type
;
501 __u8 name
[MAX_RAID_SERIAL_LEN
];
505 struct imsm_update_add_remove_disk
{
506 enum imsm_update_type type
;
509 static const char *_sys_dev_type
[] = {
510 [SYS_DEV_UNKNOWN
] = "Unknown",
511 [SYS_DEV_SAS
] = "SAS",
512 [SYS_DEV_SATA
] = "SATA",
513 [SYS_DEV_NVME
] = "NVMe"
516 const char *get_sys_dev_type(enum sys_dev_type type
)
518 if (type
>= SYS_DEV_MAX
)
519 type
= SYS_DEV_UNKNOWN
;
521 return _sys_dev_type
[type
];
524 static struct intel_hba
* alloc_intel_hba(struct sys_dev
*device
)
526 struct intel_hba
*result
= xmalloc(sizeof(*result
));
528 result
->type
= device
->type
;
529 result
->path
= xstrdup(device
->path
);
531 if (result
->path
&& (result
->pci_id
= strrchr(result
->path
, '/')) != NULL
)
537 static struct intel_hba
* find_intel_hba(struct intel_hba
*hba
, struct sys_dev
*device
)
539 struct intel_hba
*result
=NULL
;
540 for (result
= hba
; result
; result
= result
->next
) {
541 if (result
->type
== device
->type
&& strcmp(result
->path
, device
->path
) == 0)
547 static int attach_hba_to_super(struct intel_super
*super
, struct sys_dev
*device
)
549 struct intel_hba
*hba
;
551 /* check if disk attached to Intel HBA */
552 hba
= find_intel_hba(super
->hba
, device
);
555 /* Check if HBA is already attached to super */
556 if (super
->hba
== NULL
) {
557 super
->hba
= alloc_intel_hba(device
);
562 /* Intel metadata allows for all disks attached to the same type HBA.
563 * Do not support HBA types mixing
565 if (device
->type
!= hba
->type
)
568 /* Multiple same type HBAs can be used if they share the same OROM */
569 const struct imsm_orom
*device_orom
= get_orom_by_device_id(device
->dev_id
);
571 if (device_orom
!= super
->orom
)
577 hba
->next
= alloc_intel_hba(device
);
581 static struct sys_dev
* find_disk_attached_hba(int fd
, const char *devname
)
583 struct sys_dev
*list
, *elem
;
586 if ((list
= find_intel_devices()) == NULL
)
590 disk_path
= (char *) devname
;
592 disk_path
= diskfd_to_devpath(fd
);
597 for (elem
= list
; elem
; elem
= elem
->next
)
598 if (path_attached_to_hba(disk_path
, elem
->path
))
601 if (disk_path
!= devname
)
607 static int find_intel_hba_capability(int fd
, struct intel_super
*super
,
610 static struct supertype
*match_metadata_desc_imsm(char *arg
)
612 struct supertype
*st
;
614 if (strcmp(arg
, "imsm") != 0 &&
615 strcmp(arg
, "default") != 0
619 st
= xcalloc(1, sizeof(*st
));
620 st
->ss
= &super_imsm
;
621 st
->max_devs
= IMSM_MAX_DEVICES
;
622 st
->minor_version
= 0;
628 static __u8
*get_imsm_version(struct imsm_super
*mpb
)
630 return &mpb
->sig
[MPB_SIG_LEN
];
634 /* retrieve a disk directly from the anchor when the anchor is known to be
635 * up-to-date, currently only at load time
637 static struct imsm_disk
*__get_imsm_disk(struct imsm_super
*mpb
, __u8 index
)
639 if (index
>= mpb
->num_disks
)
641 return &mpb
->disk
[index
];
644 /* retrieve the disk description based on a index of the disk
647 static struct dl
*get_imsm_dl_disk(struct intel_super
*super
, __u8 index
)
651 for (d
= super
->disks
; d
; d
= d
->next
)
652 if (d
->index
== index
)
657 /* retrieve a disk from the parsed metadata */
658 static struct imsm_disk
*get_imsm_disk(struct intel_super
*super
, __u8 index
)
662 dl
= get_imsm_dl_disk(super
, index
);
669 /* generate a checksum directly from the anchor when the anchor is known to be
670 * up-to-date, currently only at load or write_super after coalescing
672 static __u32
__gen_imsm_checksum(struct imsm_super
*mpb
)
674 __u32 end
= mpb
->mpb_size
/ sizeof(end
);
675 __u32
*p
= (__u32
*) mpb
;
679 sum
+= __le32_to_cpu(*p
);
683 return sum
- __le32_to_cpu(mpb
->check_sum
);
686 static size_t sizeof_imsm_map(struct imsm_map
*map
)
688 return sizeof(struct imsm_map
) + sizeof(__u32
) * (map
->num_members
- 1);
691 struct imsm_map
*get_imsm_map(struct imsm_dev
*dev
, int second_map
)
693 /* A device can have 2 maps if it is in the middle of a migration.
695 * MAP_0 - we return the first map
696 * MAP_1 - we return the second map if it exists, else NULL
697 * MAP_X - we return the second map if it exists, else the first
699 struct imsm_map
*map
= &dev
->vol
.map
[0];
700 struct imsm_map
*map2
= NULL
;
702 if (dev
->vol
.migr_state
)
703 map2
= (void *)map
+ sizeof_imsm_map(map
);
705 switch (second_map
) {
722 /* return the size of the device.
723 * migr_state increases the returned size if map[0] were to be duplicated
725 static size_t sizeof_imsm_dev(struct imsm_dev
*dev
, int migr_state
)
727 size_t size
= sizeof(*dev
) - sizeof(struct imsm_map
) +
728 sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
730 /* migrating means an additional map */
731 if (dev
->vol
.migr_state
)
732 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_1
));
734 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
740 /* retrieve disk serial number list from a metadata update */
741 static struct disk_info
*get_disk_info(struct imsm_update_create_array
*update
)
744 struct disk_info
*inf
;
746 inf
= u
+ sizeof(*update
) - sizeof(struct imsm_dev
) +
747 sizeof_imsm_dev(&update
->dev
, 0);
753 static struct imsm_dev
*__get_imsm_dev(struct imsm_super
*mpb
, __u8 index
)
759 if (index
>= mpb
->num_raid_devs
)
762 /* devices start after all disks */
763 offset
= ((void *) &mpb
->disk
[mpb
->num_disks
]) - _mpb
;
765 for (i
= 0; i
<= index
; i
++)
767 return _mpb
+ offset
;
769 offset
+= sizeof_imsm_dev(_mpb
+ offset
, 0);
774 static struct imsm_dev
*get_imsm_dev(struct intel_super
*super
, __u8 index
)
776 struct intel_dev
*dv
;
778 if (index
>= super
->anchor
->num_raid_devs
)
780 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
781 if (dv
->index
== index
)
788 * == MAP_0 get first map
789 * == MAP_1 get second map
790 * == MAP_X than get map according to the current migr_state
792 static __u32
get_imsm_ord_tbl_ent(struct imsm_dev
*dev
,
796 struct imsm_map
*map
;
798 map
= get_imsm_map(dev
, second_map
);
800 /* top byte identifies disk under rebuild */
801 return __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
804 #define ord_to_idx(ord) (((ord) << 8) >> 8)
805 static __u32
get_imsm_disk_idx(struct imsm_dev
*dev
, int slot
, int second_map
)
807 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, second_map
);
809 return ord_to_idx(ord
);
812 static void set_imsm_ord_tbl_ent(struct imsm_map
*map
, int slot
, __u32 ord
)
814 map
->disk_ord_tbl
[slot
] = __cpu_to_le32(ord
);
817 static int get_imsm_disk_slot(struct imsm_map
*map
, unsigned idx
)
822 for (slot
= 0; slot
< map
->num_members
; slot
++) {
823 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
824 if (ord_to_idx(ord
) == idx
)
831 static int get_imsm_raid_level(struct imsm_map
*map
)
833 if (map
->raid_level
== 1) {
834 if (map
->num_members
== 2)
840 return map
->raid_level
;
843 static int cmp_extent(const void *av
, const void *bv
)
845 const struct extent
*a
= av
;
846 const struct extent
*b
= bv
;
847 if (a
->start
< b
->start
)
849 if (a
->start
> b
->start
)
854 static int count_memberships(struct dl
*dl
, struct intel_super
*super
)
859 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
860 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
861 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
863 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
870 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
);
872 static int split_ull(unsigned long long n
, __u32
*lo
, __u32
*hi
)
874 if (lo
== 0 || hi
== 0)
876 *lo
= __le32_to_cpu((unsigned)n
);
877 *hi
= __le32_to_cpu((unsigned)(n
>> 32));
881 static unsigned long long join_u32(__u32 lo
, __u32 hi
)
883 return (unsigned long long)__le32_to_cpu(lo
) |
884 (((unsigned long long)__le32_to_cpu(hi
)) << 32);
887 static unsigned long long total_blocks(struct imsm_disk
*disk
)
891 return join_u32(disk
->total_blocks_lo
, disk
->total_blocks_hi
);
894 static unsigned long long pba_of_lba0(struct imsm_map
*map
)
898 return join_u32(map
->pba_of_lba0_lo
, map
->pba_of_lba0_hi
);
901 static unsigned long long blocks_per_member(struct imsm_map
*map
)
905 return join_u32(map
->blocks_per_member_lo
, map
->blocks_per_member_hi
);
909 static unsigned long long num_data_stripes(struct imsm_map
*map
)
913 return join_u32(map
->num_data_stripes_lo
, map
->num_data_stripes_hi
);
916 static void set_total_blocks(struct imsm_disk
*disk
, unsigned long long n
)
918 split_ull(n
, &disk
->total_blocks_lo
, &disk
->total_blocks_hi
);
922 static void set_pba_of_lba0(struct imsm_map
*map
, unsigned long long n
)
924 split_ull(n
, &map
->pba_of_lba0_lo
, &map
->pba_of_lba0_hi
);
927 static void set_blocks_per_member(struct imsm_map
*map
, unsigned long long n
)
929 split_ull(n
, &map
->blocks_per_member_lo
, &map
->blocks_per_member_hi
);
932 static void set_num_data_stripes(struct imsm_map
*map
, unsigned long long n
)
934 split_ull(n
, &map
->num_data_stripes_lo
, &map
->num_data_stripes_hi
);
937 static struct extent
*get_extents(struct intel_super
*super
, struct dl
*dl
)
939 /* find a list of used extents on the given physical device */
940 struct extent
*rv
, *e
;
942 int memberships
= count_memberships(dl
, super
);
945 /* trim the reserved area for spares, so they can join any array
946 * regardless of whether the OROM has assigned sectors from the
947 * IMSM_RESERVED_SECTORS region
950 reservation
= imsm_min_reserved_sectors(super
);
952 reservation
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
954 rv
= xcalloc(sizeof(struct extent
), (memberships
+ 1));
957 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
958 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
959 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
961 if (get_imsm_disk_slot(map
, dl
->index
) >= 0) {
962 e
->start
= pba_of_lba0(map
);
963 e
->size
= blocks_per_member(map
);
967 qsort(rv
, memberships
, sizeof(*rv
), cmp_extent
);
969 /* determine the start of the metadata
970 * when no raid devices are defined use the default
971 * ...otherwise allow the metadata to truncate the value
972 * as is the case with older versions of imsm
975 struct extent
*last
= &rv
[memberships
- 1];
976 unsigned long long remainder
;
978 remainder
= total_blocks(&dl
->disk
) - (last
->start
+ last
->size
);
979 /* round down to 1k block to satisfy precision of the kernel
983 /* make sure remainder is still sane */
984 if (remainder
< (unsigned)ROUND_UP(super
->len
, 512) >> 9)
985 remainder
= ROUND_UP(super
->len
, 512) >> 9;
986 if (reservation
> remainder
)
987 reservation
= remainder
;
989 e
->start
= total_blocks(&dl
->disk
) - reservation
;
994 /* try to determine how much space is reserved for metadata from
995 * the last get_extents() entry, otherwise fallback to the
998 static __u32
imsm_reserved_sectors(struct intel_super
*super
, struct dl
*dl
)
1004 /* for spares just return a minimal reservation which will grow
1005 * once the spare is picked up by an array
1007 if (dl
->index
== -1)
1008 return MPB_SECTOR_CNT
;
1010 e
= get_extents(super
, dl
);
1012 return MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1014 /* scroll to last entry */
1015 for (i
= 0; e
[i
].size
; i
++)
1018 rv
= total_blocks(&dl
->disk
) - e
[i
].start
;
1025 static int is_spare(struct imsm_disk
*disk
)
1027 return (disk
->status
& SPARE_DISK
) == SPARE_DISK
;
1030 static int is_configured(struct imsm_disk
*disk
)
1032 return (disk
->status
& CONFIGURED_DISK
) == CONFIGURED_DISK
;
1035 static int is_failed(struct imsm_disk
*disk
)
1037 return (disk
->status
& FAILED_DISK
) == FAILED_DISK
;
1040 /* try to determine how much space is reserved for metadata from
1041 * the last get_extents() entry on the smallest active disk,
1042 * otherwise fallback to the default
1044 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
)
1048 unsigned long long min_active
;
1050 __u32 rv
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1051 struct dl
*dl
, *dl_min
= NULL
;
1057 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
1060 unsigned long long blocks
= total_blocks(&dl
->disk
);
1061 if (blocks
< min_active
|| min_active
== 0) {
1063 min_active
= blocks
;
1069 /* find last lba used by subarrays on the smallest active disk */
1070 e
= get_extents(super
, dl_min
);
1073 for (i
= 0; e
[i
].size
; i
++)
1076 remainder
= min_active
- e
[i
].start
;
1079 /* to give priority to recovery we should not require full
1080 IMSM_RESERVED_SECTORS from the spare */
1081 rv
= MPB_SECTOR_CNT
+ NUM_BLOCKS_DIRTY_STRIPE_REGION
;
1083 /* if real reservation is smaller use that value */
1084 return (remainder
< rv
) ? remainder
: rv
;
1087 /* Return minimum size of a spare that can be used in this array*/
1088 static unsigned long long min_acceptable_spare_size_imsm(struct supertype
*st
)
1090 struct intel_super
*super
= st
->sb
;
1094 unsigned long long rv
= 0;
1098 /* find first active disk in array */
1100 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
1104 /* find last lba used by subarrays */
1105 e
= get_extents(super
, dl
);
1108 for (i
= 0; e
[i
].size
; i
++)
1111 rv
= e
[i
-1].start
+ e
[i
-1].size
;
1114 /* add the amount of space needed for metadata */
1115 rv
= rv
+ imsm_min_reserved_sectors(super
);
1120 static int is_gen_migration(struct imsm_dev
*dev
);
1123 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
1124 struct imsm_dev
*dev
);
1126 static void print_imsm_dev(struct intel_super
*super
,
1127 struct imsm_dev
*dev
,
1133 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1134 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
1138 printf("[%.16s]:\n", dev
->volume
);
1139 printf(" UUID : %s\n", uuid
);
1140 printf(" RAID Level : %d", get_imsm_raid_level(map
));
1142 printf(" <-- %d", get_imsm_raid_level(map2
));
1144 printf(" Members : %d", map
->num_members
);
1146 printf(" <-- %d", map2
->num_members
);
1148 printf(" Slots : [");
1149 for (i
= 0; i
< map
->num_members
; i
++) {
1150 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
1151 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1156 for (i
= 0; i
< map2
->num_members
; i
++) {
1157 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_1
);
1158 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1163 printf(" Failed disk : ");
1164 if (map
->failed_disk_num
== 0xff)
1167 printf("%i", map
->failed_disk_num
);
1169 slot
= get_imsm_disk_slot(map
, disk_idx
);
1171 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
1172 printf(" This Slot : %d%s\n", slot
,
1173 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
1175 printf(" This Slot : ?\n");
1176 sz
= __le32_to_cpu(dev
->size_high
);
1178 sz
+= __le32_to_cpu(dev
->size_low
);
1179 printf(" Array Size : %llu%s\n", (unsigned long long)sz
,
1180 human_size(sz
* 512));
1181 sz
= blocks_per_member(map
);
1182 printf(" Per Dev Size : %llu%s\n", (unsigned long long)sz
,
1183 human_size(sz
* 512));
1184 printf(" Sector Offset : %llu\n",
1186 printf(" Num Stripes : %llu\n",
1187 num_data_stripes(map
));
1188 printf(" Chunk Size : %u KiB",
1189 __le16_to_cpu(map
->blocks_per_strip
) / 2);
1191 printf(" <-- %u KiB",
1192 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
1194 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
1195 printf(" Migrate State : ");
1196 if (dev
->vol
.migr_state
) {
1197 if (migr_type(dev
) == MIGR_INIT
)
1198 printf("initialize\n");
1199 else if (migr_type(dev
) == MIGR_REBUILD
)
1200 printf("rebuild\n");
1201 else if (migr_type(dev
) == MIGR_VERIFY
)
1203 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
1204 printf("general migration\n");
1205 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
1206 printf("state change\n");
1207 else if (migr_type(dev
) == MIGR_REPAIR
)
1210 printf("<unknown:%d>\n", migr_type(dev
));
1213 printf(" Map State : %s", map_state_str
[map
->map_state
]);
1214 if (dev
->vol
.migr_state
) {
1215 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
1217 printf(" <-- %s", map_state_str
[map
->map_state
]);
1218 printf("\n Checkpoint : %u ",
1219 __le32_to_cpu(dev
->vol
.curr_migr_unit
));
1220 if ((is_gen_migration(dev
)) && ((slot
> 1) || (slot
< 0)))
1223 printf("(%llu)", (unsigned long long)
1224 blocks_per_migr_unit(super
, dev
));
1227 printf(" Dirty State : %s\n", dev
->vol
.dirty
? "dirty" : "clean");
1230 static void print_imsm_disk(struct imsm_disk
*disk
, int index
, __u32 reserved
)
1232 char str
[MAX_RAID_SERIAL_LEN
+ 1];
1235 if (index
< -1 || !disk
)
1239 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
1241 printf(" Disk%02d Serial : %s\n", index
, str
);
1243 printf(" Disk Serial : %s\n", str
);
1244 printf(" State :%s%s%s\n", is_spare(disk
) ? " spare" : "",
1245 is_configured(disk
) ? " active" : "",
1246 is_failed(disk
) ? " failed" : "");
1247 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
1248 sz
= total_blocks(disk
) - reserved
;
1249 printf(" Usable Size : %llu%s\n", (unsigned long long)sz
,
1250 human_size(sz
* 512));
1253 void examine_migr_rec_imsm(struct intel_super
*super
)
1255 struct migr_record
*migr_rec
= super
->migr_rec
;
1256 struct imsm_super
*mpb
= super
->anchor
;
1259 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1260 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1261 struct imsm_map
*map
;
1264 if (is_gen_migration(dev
) == 0)
1267 printf("\nMigration Record Information:");
1269 /* first map under migration */
1270 map
= get_imsm_map(dev
, MAP_0
);
1272 slot
= get_imsm_disk_slot(map
, super
->disks
->index
);
1273 if ((map
== NULL
) || (slot
> 1) || (slot
< 0)) {
1274 printf(" Empty\n ");
1275 printf("Examine one of first two disks in array\n");
1278 printf("\n Status : ");
1279 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
1282 printf("Contains Data\n");
1283 printf(" Current Unit : %u\n",
1284 __le32_to_cpu(migr_rec
->curr_migr_unit
));
1285 printf(" Family : %u\n",
1286 __le32_to_cpu(migr_rec
->family_num
));
1287 printf(" Ascending : %u\n",
1288 __le32_to_cpu(migr_rec
->ascending_migr
));
1289 printf(" Blocks Per Unit : %u\n",
1290 __le32_to_cpu(migr_rec
->blocks_per_unit
));
1291 printf(" Dest. Depth Per Unit : %u\n",
1292 __le32_to_cpu(migr_rec
->dest_depth_per_unit
));
1293 printf(" Checkpoint Area pba : %u\n",
1294 __le32_to_cpu(migr_rec
->ckpt_area_pba
));
1295 printf(" First member lba : %u\n",
1296 __le32_to_cpu(migr_rec
->dest_1st_member_lba
));
1297 printf(" Total Number of Units : %u\n",
1298 __le32_to_cpu(migr_rec
->num_migr_units
));
1299 printf(" Size of volume : %u\n",
1300 __le32_to_cpu(migr_rec
->post_migr_vol_cap
));
1301 printf(" Expansion space for LBA64 : %u\n",
1302 __le32_to_cpu(migr_rec
->post_migr_vol_cap_hi
));
1303 printf(" Record was read from : %u\n",
1304 __le32_to_cpu(migr_rec
->ckpt_read_disk_num
));
1309 #endif /* MDASSEMBLE */
1310 /*******************************************************************************
1311 * function: imsm_check_attributes
1312 * Description: Function checks if features represented by attributes flags
1313 * are supported by mdadm.
1315 * attributes - Attributes read from metadata
1317 * 0 - passed attributes contains unsupported features flags
1318 * 1 - all features are supported
1319 ******************************************************************************/
1320 static int imsm_check_attributes(__u32 attributes
)
1323 __u32 not_supported
= MPB_ATTRIB_SUPPORTED
^0xffffffff;
1325 not_supported
&= ~MPB_ATTRIB_IGNORED
;
1327 not_supported
&= attributes
;
1328 if (not_supported
) {
1329 pr_err("(IMSM): Unsupported attributes : %x\n",
1330 (unsigned)__le32_to_cpu(not_supported
));
1331 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1332 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY \n");
1333 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1335 if (not_supported
& MPB_ATTRIB_2TB
) {
1336 dprintf("\t\tMPB_ATTRIB_2TB\n");
1337 not_supported
^= MPB_ATTRIB_2TB
;
1339 if (not_supported
& MPB_ATTRIB_RAID0
) {
1340 dprintf("\t\tMPB_ATTRIB_RAID0\n");
1341 not_supported
^= MPB_ATTRIB_RAID0
;
1343 if (not_supported
& MPB_ATTRIB_RAID1
) {
1344 dprintf("\t\tMPB_ATTRIB_RAID1\n");
1345 not_supported
^= MPB_ATTRIB_RAID1
;
1347 if (not_supported
& MPB_ATTRIB_RAID10
) {
1348 dprintf("\t\tMPB_ATTRIB_RAID10\n");
1349 not_supported
^= MPB_ATTRIB_RAID10
;
1351 if (not_supported
& MPB_ATTRIB_RAID1E
) {
1352 dprintf("\t\tMPB_ATTRIB_RAID1E\n");
1353 not_supported
^= MPB_ATTRIB_RAID1E
;
1355 if (not_supported
& MPB_ATTRIB_RAID5
) {
1356 dprintf("\t\tMPB_ATTRIB_RAID5\n");
1357 not_supported
^= MPB_ATTRIB_RAID5
;
1359 if (not_supported
& MPB_ATTRIB_RAIDCNG
) {
1360 dprintf("\t\tMPB_ATTRIB_RAIDCNG\n");
1361 not_supported
^= MPB_ATTRIB_RAIDCNG
;
1363 if (not_supported
& MPB_ATTRIB_BBM
) {
1364 dprintf("\t\tMPB_ATTRIB_BBM\n");
1365 not_supported
^= MPB_ATTRIB_BBM
;
1367 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1368 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY (== MPB_ATTRIB_LEGACY)\n");
1369 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1371 if (not_supported
& MPB_ATTRIB_EXP_STRIPE_SIZE
) {
1372 dprintf("\t\tMPB_ATTRIB_EXP_STRIP_SIZE\n");
1373 not_supported
^= MPB_ATTRIB_EXP_STRIPE_SIZE
;
1375 if (not_supported
& MPB_ATTRIB_2TB_DISK
) {
1376 dprintf("\t\tMPB_ATTRIB_2TB_DISK\n");
1377 not_supported
^= MPB_ATTRIB_2TB_DISK
;
1379 if (not_supported
& MPB_ATTRIB_NEVER_USE2
) {
1380 dprintf("\t\tMPB_ATTRIB_NEVER_USE2\n");
1381 not_supported
^= MPB_ATTRIB_NEVER_USE2
;
1383 if (not_supported
& MPB_ATTRIB_NEVER_USE
) {
1384 dprintf("\t\tMPB_ATTRIB_NEVER_USE\n");
1385 not_supported
^= MPB_ATTRIB_NEVER_USE
;
1389 dprintf(Name
"(IMSM): Unknown attributes : %x\n", not_supported
);
1398 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
1400 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
1402 struct intel_super
*super
= st
->sb
;
1403 struct imsm_super
*mpb
= super
->anchor
;
1404 char str
[MAX_SIGNATURE_LENGTH
];
1409 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
1412 snprintf(str
, MPB_SIG_LEN
, "%s", mpb
->sig
);
1413 printf(" Magic : %s\n", str
);
1414 snprintf(str
, strlen(MPB_VERSION_RAID0
), "%s", get_imsm_version(mpb
));
1415 printf(" Version : %s\n", get_imsm_version(mpb
));
1416 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
1417 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
1418 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
1419 printf(" Attributes : ");
1420 if (imsm_check_attributes(mpb
->attributes
))
1421 printf("All supported\n");
1423 printf("not supported\n");
1424 getinfo_super_imsm(st
, &info
, NULL
);
1425 fname_from_uuid(st
, &info
, nbuf
, ':');
1426 printf(" UUID : %s\n", nbuf
+ 5);
1427 sum
= __le32_to_cpu(mpb
->check_sum
);
1428 printf(" Checksum : %08x %s\n", sum
,
1429 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
1430 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
));
1431 printf(" Disks : %d\n", mpb
->num_disks
);
1432 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
1433 print_imsm_disk(__get_imsm_disk(mpb
, super
->disks
->index
), super
->disks
->index
, reserved
);
1434 if (super
->bbm_log
) {
1435 struct bbm_log
*log
= super
->bbm_log
;
1438 printf("Bad Block Management Log:\n");
1439 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
1440 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
1441 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
1442 printf(" Spare Blocks : %d\n", __le32_to_cpu(log
->reserved_spare_block_count
));
1443 printf(" First Spare : %llx\n",
1444 (unsigned long long) __le64_to_cpu(log
->first_spare_lba
));
1446 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1448 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1450 super
->current_vol
= i
;
1451 getinfo_super_imsm(st
, &info
, NULL
);
1452 fname_from_uuid(st
, &info
, nbuf
, ':');
1453 print_imsm_dev(super
, dev
, nbuf
+ 5, super
->disks
->index
);
1455 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1456 if (i
== super
->disks
->index
)
1458 print_imsm_disk(__get_imsm_disk(mpb
, i
), i
, reserved
);
1461 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
1462 if (dl
->index
== -1)
1463 print_imsm_disk(&dl
->disk
, -1, reserved
);
1465 examine_migr_rec_imsm(super
);
1468 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
1470 /* We just write a generic IMSM ARRAY entry */
1473 struct intel_super
*super
= st
->sb
;
1475 if (!super
->anchor
->num_raid_devs
) {
1476 printf("ARRAY metadata=imsm\n");
1480 getinfo_super_imsm(st
, &info
, NULL
);
1481 fname_from_uuid(st
, &info
, nbuf
, ':');
1482 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
1485 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
1487 /* We just write a generic IMSM ARRAY entry */
1491 struct intel_super
*super
= st
->sb
;
1494 if (!super
->anchor
->num_raid_devs
)
1497 getinfo_super_imsm(st
, &info
, NULL
);
1498 fname_from_uuid(st
, &info
, nbuf
, ':');
1499 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1500 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1502 super
->current_vol
= i
;
1503 getinfo_super_imsm(st
, &info
, NULL
);
1504 fname_from_uuid(st
, &info
, nbuf1
, ':');
1505 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
1506 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
1510 static void export_examine_super_imsm(struct supertype
*st
)
1512 struct intel_super
*super
= st
->sb
;
1513 struct imsm_super
*mpb
= super
->anchor
;
1517 getinfo_super_imsm(st
, &info
, NULL
);
1518 fname_from_uuid(st
, &info
, nbuf
, ':');
1519 printf("MD_METADATA=imsm\n");
1520 printf("MD_LEVEL=container\n");
1521 printf("MD_UUID=%s\n", nbuf
+5);
1522 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
1525 static int copy_metadata_imsm(struct supertype
*st
, int from
, int to
)
1527 /* The second last 512byte sector of the device contains
1528 * the "struct imsm_super" metadata.
1529 * This contains mpb_size which is the size in bytes of the
1530 * extended metadata. This is located immediately before
1532 * We want to read all that, plus the last sector which
1533 * may contain a migration record, and write it all
1537 unsigned long long dsize
, offset
;
1539 struct imsm_super
*sb
;
1542 if (posix_memalign(&buf
, 4096, 4096) != 0)
1545 if (!get_dev_size(from
, NULL
, &dsize
))
1548 if (lseek64(from
, dsize
-1024, 0) < 0)
1550 if (read(from
, buf
, 512) != 512)
1553 if (strncmp((char*)sb
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0)
1556 sectors
= mpb_sectors(sb
) + 2;
1557 offset
= dsize
- sectors
* 512;
1558 if (lseek64(from
, offset
, 0) < 0 ||
1559 lseek64(to
, offset
, 0) < 0)
1561 while (written
< sectors
* 512) {
1562 int n
= sectors
*512 - written
;
1565 if (read(from
, buf
, n
) != n
)
1567 if (write(to
, buf
, n
) != n
)
1578 static void detail_super_imsm(struct supertype
*st
, char *homehost
)
1583 getinfo_super_imsm(st
, &info
, NULL
);
1584 fname_from_uuid(st
, &info
, nbuf
, ':');
1585 printf("\n UUID : %s\n", nbuf
+ 5);
1588 static void brief_detail_super_imsm(struct supertype
*st
)
1592 getinfo_super_imsm(st
, &info
, NULL
);
1593 fname_from_uuid(st
, &info
, nbuf
, ':');
1594 printf(" UUID=%s", nbuf
+ 5);
1597 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
);
1598 static void fd2devname(int fd
, char *name
);
1600 static int ahci_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
1602 /* dump an unsorted list of devices attached to AHCI Intel storage
1603 * controller, as well as non-connected ports
1605 int hba_len
= strlen(hba_path
) + 1;
1610 unsigned long port_mask
= (1 << port_count
) - 1;
1612 if (port_count
> (int)sizeof(port_mask
) * 8) {
1614 pr_err("port_count %d out of range\n", port_count
);
1618 /* scroll through /sys/dev/block looking for devices attached to
1621 dir
= opendir("/sys/dev/block");
1622 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
1633 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
1635 path
= devt_to_devpath(makedev(major
, minor
));
1638 if (!path_attached_to_hba(path
, hba_path
)) {
1644 /* retrieve the scsi device type */
1645 if (asprintf(&device
, "/sys/dev/block/%d:%d/device/xxxxxxx", major
, minor
) < 0) {
1647 pr_err("failed to allocate 'device'\n");
1651 sprintf(device
, "/sys/dev/block/%d:%d/device/type", major
, minor
);
1652 if (load_sys(device
, buf
) != 0) {
1654 pr_err("failed to read device type for %s\n",
1660 type
= strtoul(buf
, NULL
, 10);
1662 /* if it's not a disk print the vendor and model */
1663 if (!(type
== 0 || type
== 7 || type
== 14)) {
1666 sprintf(device
, "/sys/dev/block/%d:%d/device/vendor", major
, minor
);
1667 if (load_sys(device
, buf
) == 0) {
1668 strncpy(vendor
, buf
, sizeof(vendor
));
1669 vendor
[sizeof(vendor
) - 1] = '\0';
1670 c
= (char *) &vendor
[sizeof(vendor
) - 1];
1671 while (isspace(*c
) || *c
== '\0')
1675 sprintf(device
, "/sys/dev/block/%d:%d/device/model", major
, minor
);
1676 if (load_sys(device
, buf
) == 0) {
1677 strncpy(model
, buf
, sizeof(model
));
1678 model
[sizeof(model
) - 1] = '\0';
1679 c
= (char *) &model
[sizeof(model
) - 1];
1680 while (isspace(*c
) || *c
== '\0')
1684 if (vendor
[0] && model
[0])
1685 sprintf(buf
, "%.64s %.64s", vendor
, model
);
1687 switch (type
) { /* numbers from hald/linux/device.c */
1688 case 1: sprintf(buf
, "tape"); break;
1689 case 2: sprintf(buf
, "printer"); break;
1690 case 3: sprintf(buf
, "processor"); break;
1692 case 5: sprintf(buf
, "cdrom"); break;
1693 case 6: sprintf(buf
, "scanner"); break;
1694 case 8: sprintf(buf
, "media_changer"); break;
1695 case 9: sprintf(buf
, "comm"); break;
1696 case 12: sprintf(buf
, "raid"); break;
1697 default: sprintf(buf
, "unknown");
1703 /* chop device path to 'host%d' and calculate the port number */
1704 c
= strchr(&path
[hba_len
], '/');
1707 pr_err("%s - invalid path name\n", path
+ hba_len
);
1712 if (sscanf(&path
[hba_len
], "host%d", &port
) == 1)
1716 *c
= '/'; /* repair the full string */
1717 pr_err("failed to determine port number for %s\n",
1724 /* mark this port as used */
1725 port_mask
&= ~(1 << port
);
1727 /* print out the device information */
1729 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
1733 fd
= dev_open(ent
->d_name
, O_RDONLY
);
1735 printf(" Port%d : - disk info unavailable -\n", port
);
1737 fd2devname(fd
, buf
);
1738 printf(" Port%d : %s", port
, buf
);
1739 if (imsm_read_serial(fd
, NULL
, (__u8
*) buf
) == 0)
1740 printf(" (%.*s)\n", MAX_RAID_SERIAL_LEN
, buf
);
1755 for (i
= 0; i
< port_count
; i
++)
1756 if (port_mask
& (1 << i
))
1757 printf(" Port%d : - no device attached -\n", i
);
1763 static void print_found_intel_controllers(struct sys_dev
*elem
)
1765 for (; elem
; elem
= elem
->next
) {
1766 pr_err("found Intel(R) ");
1767 if (elem
->type
== SYS_DEV_SATA
)
1768 fprintf(stderr
, "SATA ");
1769 else if (elem
->type
== SYS_DEV_SAS
)
1770 fprintf(stderr
, "SAS ");
1771 fprintf(stderr
, "RAID controller");
1773 fprintf(stderr
, " at %s", elem
->pci_id
);
1774 fprintf(stderr
, ".\n");
1779 static int ahci_get_port_count(const char *hba_path
, int *port_count
)
1786 if ((dir
= opendir(hba_path
)) == NULL
)
1789 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
1792 if (sscanf(ent
->d_name
, "host%d", &host
) != 1)
1794 if (*port_count
== 0)
1796 else if (host
< host_base
)
1799 if (host
+ 1 > *port_count
+ host_base
)
1800 *port_count
= host
+ 1 - host_base
;
1806 static void print_imsm_capability(const struct imsm_orom
*orom
)
1808 printf(" Platform : Intel(R) Matrix Storage Manager\n");
1809 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
1810 orom
->hotfix_ver
, orom
->build
);
1811 printf(" RAID Levels :%s%s%s%s%s\n",
1812 imsm_orom_has_raid0(orom
) ? " raid0" : "",
1813 imsm_orom_has_raid1(orom
) ? " raid1" : "",
1814 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
1815 imsm_orom_has_raid10(orom
) ? " raid10" : "",
1816 imsm_orom_has_raid5(orom
) ? " raid5" : "");
1817 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1818 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
1819 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
1820 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
1821 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
1822 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
1823 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
1824 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
1825 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
1826 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
1827 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
1828 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
1829 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
1830 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
1831 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
1832 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
1833 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
1834 printf(" 2TB volumes :%s supported\n",
1835 (orom
->attr
& IMSM_OROM_ATTR_2TB
)?"":" not");
1836 printf(" 2TB disks :%s supported\n",
1837 (orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
)?"":" not");
1838 printf(" Max Disks : %d\n", orom
->tds
);
1839 printf(" Max Volumes : %d per array, %d per controller\n",
1840 orom
->vpa
, orom
->vphba
);
1844 static void print_imsm_capability_export(const struct imsm_orom
*orom
)
1846 printf("MD_FIRMWARE_TYPE=imsm\n");
1847 printf("IMSM_VERSION=%d.%d.%d.%d\n",orom
->major_ver
, orom
->minor_ver
,
1848 orom
->hotfix_ver
, orom
->build
);
1849 printf("IMSM_SUPPORTED_RAID_LEVELS=%s%s%s%s%s\n",
1850 imsm_orom_has_raid0(orom
) ? "raid0 " : "",
1851 imsm_orom_has_raid1(orom
) ? "raid1 " : "",
1852 imsm_orom_has_raid1e(orom
) ? "raid1e " : "",
1853 imsm_orom_has_raid5(orom
) ? "raid10 " : "",
1854 imsm_orom_has_raid10(orom
) ? "raid5 " : "");
1855 printf("IMSM_SUPPORTED_CHUNK_SIZES=%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1856 imsm_orom_has_chunk(orom
, 2) ? "2k " : "",
1857 imsm_orom_has_chunk(orom
, 4) ? "4k " : "",
1858 imsm_orom_has_chunk(orom
, 8) ? "8k " : "",
1859 imsm_orom_has_chunk(orom
, 16) ? "16k " : "",
1860 imsm_orom_has_chunk(orom
, 32) ? "32k " : "",
1861 imsm_orom_has_chunk(orom
, 64) ? "64k " : "",
1862 imsm_orom_has_chunk(orom
, 128) ? "128k " : "",
1863 imsm_orom_has_chunk(orom
, 256) ? "256k " : "",
1864 imsm_orom_has_chunk(orom
, 512) ? "512k " : "",
1865 imsm_orom_has_chunk(orom
, 1024*1) ? "1M " : "",
1866 imsm_orom_has_chunk(orom
, 1024*2) ? "2M " : "",
1867 imsm_orom_has_chunk(orom
, 1024*4) ? "4M " : "",
1868 imsm_orom_has_chunk(orom
, 1024*8) ? "8M " : "",
1869 imsm_orom_has_chunk(orom
, 1024*16) ? "16M " : "",
1870 imsm_orom_has_chunk(orom
, 1024*32) ? "32M " : "",
1871 imsm_orom_has_chunk(orom
, 1024*64) ? "64M " : "");
1872 printf("IMSM_2TB_VOLUMES=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB
) ? "yes" : "no");
1873 printf("IMSM_2TB_DISKS=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) ? "yes" : "no");
1874 printf("IMSM_MAX_DISKS=%d\n",orom
->tds
);
1875 printf("IMSM_MAX_VOLUMES_PER_ARRAY=%d\n",orom
->vpa
);
1876 printf("IMSM_MAX_VOLUMES_PER_CONTROLLER=%d\n",orom
->vphba
);
1879 static int detail_platform_imsm(int verbose
, int enumerate_only
, char *controller_path
)
1881 /* There are two components to imsm platform support, the ahci SATA
1882 * controller and the option-rom. To find the SATA controller we
1883 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
1884 * controller with the Intel vendor id is present. This approach
1885 * allows mdadm to leverage the kernel's ahci detection logic, with the
1886 * caveat that if ahci.ko is not loaded mdadm will not be able to
1887 * detect platform raid capabilities. The option-rom resides in a
1888 * platform "Adapter ROM". We scan for its signature to retrieve the
1889 * platform capabilities. If raid support is disabled in the BIOS the
1890 * option-rom capability structure will not be available.
1892 const struct imsm_orom
*orom
;
1893 struct sys_dev
*list
, *hba
;
1898 if (enumerate_only
) {
1899 if (check_env("IMSM_NO_PLATFORM"))
1901 list
= find_intel_devices();
1904 for (hba
= list
; hba
; hba
= hba
->next
) {
1905 if (find_imsm_capability(hba
)) {
1915 list
= find_intel_devices();
1918 pr_err("no active Intel(R) RAID "
1919 "controller found.\n");
1921 } else if (verbose
> 0)
1922 print_found_intel_controllers(list
);
1924 for (hba
= list
; hba
; hba
= hba
->next
) {
1925 if (controller_path
&& (compare_paths(hba
->path
,controller_path
) != 0))
1927 orom
= find_imsm_capability(hba
);
1929 pr_err("imsm capabilities not found for controller: %s (type %s)\n",
1930 hba
->path
, get_sys_dev_type(hba
->type
));
1933 print_imsm_capability(orom
);
1934 printf(" I/O Controller : %s (%s)\n",
1935 hba
->path
, get_sys_dev_type(hba
->type
));
1936 if (hba
->type
== SYS_DEV_SATA
) {
1937 host_base
= ahci_get_port_count(hba
->path
, &port_count
);
1938 if (ahci_enumerate_ports(hba
->path
, port_count
, host_base
, verbose
)) {
1940 pr_err("failed to enumerate "
1941 "ports on SATA controller at %s.\n", hba
->pci_id
);
1948 if (controller_path
&& result
== 1)
1949 pr_err("no active Intel(R) RAID "
1950 "controller found under %s\n",controller_path
);
1955 static int export_detail_platform_imsm(int verbose
, char *controller_path
)
1957 const struct imsm_orom
*orom
;
1958 struct sys_dev
*list
, *hba
;
1961 list
= find_intel_devices();
1964 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_INTEL_DEVICES\n");
1969 for (hba
= list
; hba
; hba
= hba
->next
) {
1970 if (controller_path
&& (compare_paths(hba
->path
,controller_path
) != 0))
1972 orom
= find_imsm_capability(hba
);
1975 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_IMSM_CAPABLE_DEVICE_UNDER_%s\n",hba
->path
);
1978 print_imsm_capability_export(orom
);
1988 static int match_home_imsm(struct supertype
*st
, char *homehost
)
1990 /* the imsm metadata format does not specify any host
1991 * identification information. We return -1 since we can never
1992 * confirm nor deny whether a given array is "meant" for this
1993 * host. We rely on compare_super and the 'family_num' fields to
1994 * exclude member disks that do not belong, and we rely on
1995 * mdadm.conf to specify the arrays that should be assembled.
1996 * Auto-assembly may still pick up "foreign" arrays.
2002 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
2004 /* The uuid returned here is used for:
2005 * uuid to put into bitmap file (Create, Grow)
2006 * uuid for backup header when saving critical section (Grow)
2007 * comparing uuids when re-adding a device into an array
2008 * In these cases the uuid required is that of the data-array,
2009 * not the device-set.
2010 * uuid to recognise same set when adding a missing device back
2011 * to an array. This is a uuid for the device-set.
2013 * For each of these we can make do with a truncated
2014 * or hashed uuid rather than the original, as long as
2016 * In each case the uuid required is that of the data-array,
2017 * not the device-set.
2019 /* imsm does not track uuid's so we synthesis one using sha1 on
2020 * - The signature (Which is constant for all imsm array, but no matter)
2021 * - the orig_family_num of the container
2022 * - the index number of the volume
2023 * - the 'serial' number of the volume.
2024 * Hopefully these are all constant.
2026 struct intel_super
*super
= st
->sb
;
2029 struct sha1_ctx ctx
;
2030 struct imsm_dev
*dev
= NULL
;
2033 /* some mdadm versions failed to set ->orig_family_num, in which
2034 * case fall back to ->family_num. orig_family_num will be
2035 * fixed up with the first metadata update.
2037 family_num
= super
->anchor
->orig_family_num
;
2038 if (family_num
== 0)
2039 family_num
= super
->anchor
->family_num
;
2040 sha1_init_ctx(&ctx
);
2041 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
2042 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
2043 if (super
->current_vol
>= 0)
2044 dev
= get_imsm_dev(super
, super
->current_vol
);
2046 __u32 vol
= super
->current_vol
;
2047 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
2048 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
2050 sha1_finish_ctx(&ctx
, buf
);
2051 memcpy(uuid
, buf
, 4*4);
2056 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
2058 __u8
*v
= get_imsm_version(mpb
);
2059 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
2060 char major
[] = { 0, 0, 0 };
2061 char minor
[] = { 0 ,0, 0 };
2062 char patch
[] = { 0, 0, 0 };
2063 char *ver_parse
[] = { major
, minor
, patch
};
2067 while (*v
!= '\0' && v
< end
) {
2068 if (*v
!= '.' && j
< 2)
2069 ver_parse
[i
][j
++] = *v
;
2077 *m
= strtol(minor
, NULL
, 0);
2078 *p
= strtol(patch
, NULL
, 0);
2082 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
2084 /* migr_strip_size when repairing or initializing parity */
2085 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2086 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2088 switch (get_imsm_raid_level(map
)) {
2093 return 128*1024 >> 9;
2097 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
2099 /* migr_strip_size when rebuilding a degraded disk, no idea why
2100 * this is different than migr_strip_size_resync(), but it's good
2103 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2104 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2106 switch (get_imsm_raid_level(map
)) {
2109 if (map
->num_members
% map
->num_domains
== 0)
2110 return 128*1024 >> 9;
2114 return max((__u32
) 64*1024 >> 9, chunk
);
2116 return 128*1024 >> 9;
2120 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
2122 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2123 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2124 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
2125 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
2127 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
2130 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
2132 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2133 int level
= get_imsm_raid_level(lo
);
2135 if (level
== 1 || level
== 10) {
2136 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2138 return hi
->num_domains
;
2140 return num_stripes_per_unit_resync(dev
);
2143 static __u8
imsm_num_data_members(struct imsm_dev
*dev
, int second_map
)
2145 /* named 'imsm_' because raid0, raid1 and raid10
2146 * counter-intuitively have the same number of data disks
2148 struct imsm_map
*map
= get_imsm_map(dev
, second_map
);
2150 switch (get_imsm_raid_level(map
)) {
2152 return map
->num_members
;
2156 return map
->num_members
/2;
2158 return map
->num_members
- 1;
2160 dprintf("%s: unsupported raid level\n", __func__
);
2165 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
2167 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2168 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2170 switch(get_imsm_raid_level(map
)) {
2173 return chunk
* map
->num_domains
;
2175 return chunk
* map
->num_members
;
2181 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
2183 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2184 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2185 __u32 strip
= block
/ chunk
;
2187 switch (get_imsm_raid_level(map
)) {
2190 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
2191 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
2193 return vol_stripe
* chunk
+ block
% chunk
;
2195 __u32 stripe
= strip
/ (map
->num_members
- 1);
2197 return stripe
* chunk
+ block
% chunk
;
2204 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
2205 struct imsm_dev
*dev
)
2207 /* calculate the conversion factor between per member 'blocks'
2208 * (md/{resync,rebuild}_start) and imsm migration units, return
2209 * 0 for the 'not migrating' and 'unsupported migration' cases
2211 if (!dev
->vol
.migr_state
)
2214 switch (migr_type(dev
)) {
2215 case MIGR_GEN_MIGR
: {
2216 struct migr_record
*migr_rec
= super
->migr_rec
;
2217 return __le32_to_cpu(migr_rec
->blocks_per_unit
);
2222 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2223 __u32 stripes_per_unit
;
2224 __u32 blocks_per_unit
;
2233 /* yes, this is really the translation of migr_units to
2234 * per-member blocks in the 'resync' case
2236 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
2237 migr_chunk
= migr_strip_blocks_resync(dev
);
2238 disks
= imsm_num_data_members(dev
, MAP_0
);
2239 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
2240 stripe
= __le16_to_cpu(map
->blocks_per_strip
) * disks
;
2241 segment
= blocks_per_unit
/ stripe
;
2242 block_rel
= blocks_per_unit
- segment
* stripe
;
2243 parity_depth
= parity_segment_depth(dev
);
2244 block_map
= map_migr_block(dev
, block_rel
);
2245 return block_map
+ parity_depth
* segment
;
2247 case MIGR_REBUILD
: {
2248 __u32 stripes_per_unit
;
2251 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
2252 migr_chunk
= migr_strip_blocks_rebuild(dev
);
2253 return migr_chunk
* stripes_per_unit
;
2255 case MIGR_STATE_CHANGE
:
2261 static int imsm_level_to_layout(int level
)
2269 return ALGORITHM_LEFT_ASYMMETRIC
;
2276 /*******************************************************************************
2277 * Function: read_imsm_migr_rec
2278 * Description: Function reads imsm migration record from last sector of disk
2280 * fd : disk descriptor
2281 * super : metadata info
2285 ******************************************************************************/
2286 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
)
2289 unsigned long long dsize
;
2291 get_dev_size(fd
, NULL
, &dsize
);
2292 if (lseek64(fd
, dsize
- MIGR_REC_POSITION
, SEEK_SET
) < 0) {
2293 pr_err("Cannot seek to anchor block: %s\n",
2297 if (read(fd
, super
->migr_rec_buf
, MIGR_REC_BUF_SIZE
) !=
2298 MIGR_REC_BUF_SIZE
) {
2299 pr_err("Cannot read migr record block: %s\n",
2309 static struct imsm_dev
*imsm_get_device_during_migration(
2310 struct intel_super
*super
)
2313 struct intel_dev
*dv
;
2315 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
2316 if (is_gen_migration(dv
->dev
))
2322 /*******************************************************************************
2323 * Function: load_imsm_migr_rec
2324 * Description: Function reads imsm migration record (it is stored at the last
2327 * super : imsm internal array info
2328 * info : general array info
2332 * -2 : no migration in progress
2333 ******************************************************************************/
2334 static int load_imsm_migr_rec(struct intel_super
*super
, struct mdinfo
*info
)
2337 struct dl
*dl
= NULL
;
2341 struct imsm_dev
*dev
;
2342 struct imsm_map
*map
= NULL
;
2345 /* find map under migration */
2346 dev
= imsm_get_device_during_migration(super
);
2347 /* nothing to load,no migration in progress?
2351 map
= get_imsm_map(dev
, MAP_0
);
2354 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
2355 /* skip spare and failed disks
2357 if (sd
->disk
.raid_disk
< 0)
2359 /* read only from one of the first two slots */
2361 slot
= get_imsm_disk_slot(map
,
2362 sd
->disk
.raid_disk
);
2363 if ((map
== NULL
) || (slot
> 1) || (slot
< 0))
2366 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
2367 fd
= dev_open(nm
, O_RDONLY
);
2373 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
2374 /* skip spare and failed disks
2378 /* read only from one of the first two slots */
2380 slot
= get_imsm_disk_slot(map
, dl
->index
);
2381 if ((map
== NULL
) || (slot
> 1) || (slot
< 0))
2383 sprintf(nm
, "%d:%d", dl
->major
, dl
->minor
);
2384 fd
= dev_open(nm
, O_RDONLY
);
2391 retval
= read_imsm_migr_rec(fd
, super
);
2400 /*******************************************************************************
2401 * function: imsm_create_metadata_checkpoint_update
2402 * Description: It creates update for checkpoint change.
2404 * super : imsm internal array info
2405 * u : pointer to prepared update
2408 * If length is equal to 0, input pointer u contains no update
2409 ******************************************************************************/
2410 static int imsm_create_metadata_checkpoint_update(
2411 struct intel_super
*super
,
2412 struct imsm_update_general_migration_checkpoint
**u
)
2415 int update_memory_size
= 0;
2417 dprintf("imsm_create_metadata_checkpoint_update(enter)\n");
2423 /* size of all update data without anchor */
2424 update_memory_size
=
2425 sizeof(struct imsm_update_general_migration_checkpoint
);
2427 *u
= xcalloc(1, update_memory_size
);
2429 dprintf("error: cannot get memory for "
2430 "imsm_create_metadata_checkpoint_update update\n");
2433 (*u
)->type
= update_general_migration_checkpoint
;
2434 (*u
)->curr_migr_unit
= __le32_to_cpu(super
->migr_rec
->curr_migr_unit
);
2435 dprintf("imsm_create_metadata_checkpoint_update: prepared for %u\n",
2436 (*u
)->curr_migr_unit
);
2438 return update_memory_size
;
2441 static void imsm_update_metadata_locally(struct supertype
*st
,
2442 void *buf
, int len
);
2444 /*******************************************************************************
2445 * Function: write_imsm_migr_rec
2446 * Description: Function writes imsm migration record
2447 * (at the last sector of disk)
2449 * super : imsm internal array info
2453 ******************************************************************************/
2454 static int write_imsm_migr_rec(struct supertype
*st
)
2456 struct intel_super
*super
= st
->sb
;
2457 unsigned long long dsize
;
2463 struct imsm_update_general_migration_checkpoint
*u
;
2464 struct imsm_dev
*dev
;
2465 struct imsm_map
*map
= NULL
;
2467 /* find map under migration */
2468 dev
= imsm_get_device_during_migration(super
);
2469 /* if no migration, write buffer anyway to clear migr_record
2470 * on disk based on first available device
2473 dev
= get_imsm_dev(super
, super
->current_vol
< 0 ? 0 :
2474 super
->current_vol
);
2476 map
= get_imsm_map(dev
, MAP_0
);
2478 for (sd
= super
->disks
; sd
; sd
= sd
->next
) {
2481 /* skip failed and spare devices */
2484 /* write to 2 first slots only */
2486 slot
= get_imsm_disk_slot(map
, sd
->index
);
2487 if ((map
== NULL
) || (slot
> 1) || (slot
< 0))
2490 sprintf(nm
, "%d:%d", sd
->major
, sd
->minor
);
2491 fd
= dev_open(nm
, O_RDWR
);
2494 get_dev_size(fd
, NULL
, &dsize
);
2495 if (lseek64(fd
, dsize
- MIGR_REC_POSITION
, SEEK_SET
) < 0) {
2496 pr_err("Cannot seek to anchor block: %s\n",
2500 if (write(fd
, super
->migr_rec_buf
, MIGR_REC_BUF_SIZE
) !=
2501 MIGR_REC_BUF_SIZE
) {
2502 pr_err("Cannot write migr record block: %s\n",
2509 /* update checkpoint information in metadata */
2510 len
= imsm_create_metadata_checkpoint_update(super
, &u
);
2513 dprintf("imsm: Cannot prepare update\n");
2516 /* update metadata locally */
2517 imsm_update_metadata_locally(st
, u
, len
);
2518 /* and possibly remotely */
2519 if (st
->update_tail
) {
2520 append_metadata_update(st
, u
, len
);
2521 /* during reshape we do all work inside metadata handler
2522 * manage_reshape(), so metadata update has to be triggered
2525 flush_metadata_updates(st
);
2526 st
->update_tail
= &st
->updates
;
2536 #endif /* MDASSEMBLE */
2538 /* spare/missing disks activations are not allowe when
2539 * array/container performs reshape operation, because
2540 * all arrays in container works on the same disks set
2542 int imsm_reshape_blocks_arrays_changes(struct intel_super
*super
)
2545 struct intel_dev
*i_dev
;
2546 struct imsm_dev
*dev
;
2548 /* check whole container
2550 for (i_dev
= super
->devlist
; i_dev
; i_dev
= i_dev
->next
) {
2552 if (is_gen_migration(dev
)) {
2553 /* No repair during any migration in container
2561 static unsigned long long imsm_component_size_aligment_check(int level
,
2563 unsigned long long component_size
)
2565 unsigned int component_size_alligment
;
2567 /* check component size aligment
2569 component_size_alligment
= component_size
% (chunk_size
/512);
2571 dprintf("imsm_component_size_aligment_check(Level: %i, "
2572 "chunk_size = %i, component_size = %llu), "
2573 "component_size_alligment = %u\n",
2574 level
, chunk_size
, component_size
,
2575 component_size_alligment
);
2577 if (component_size_alligment
&& (level
!= 1) && (level
!= UnSet
)) {
2578 dprintf("imsm: reported component size alligned from %llu ",
2580 component_size
-= component_size_alligment
;
2581 dprintf("to %llu (%i).\n",
2582 component_size
, component_size_alligment
);
2585 return component_size
;
2588 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
2590 struct intel_super
*super
= st
->sb
;
2591 struct migr_record
*migr_rec
= super
->migr_rec
;
2592 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
2593 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2594 struct imsm_map
*prev_map
= get_imsm_map(dev
, MAP_1
);
2595 struct imsm_map
*map_to_analyse
= map
;
2597 int map_disks
= info
->array
.raid_disks
;
2599 memset(info
, 0, sizeof(*info
));
2601 map_to_analyse
= prev_map
;
2603 dl
= super
->current_disk
;
2605 info
->container_member
= super
->current_vol
;
2606 info
->array
.raid_disks
= map
->num_members
;
2607 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
2608 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
2609 info
->array
.md_minor
= -1;
2610 info
->array
.ctime
= 0;
2611 info
->array
.utime
= 0;
2612 info
->array
.chunk_size
=
2613 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
2614 info
->array
.state
= !dev
->vol
.dirty
;
2615 info
->custom_array_size
= __le32_to_cpu(dev
->size_high
);
2616 info
->custom_array_size
<<= 32;
2617 info
->custom_array_size
|= __le32_to_cpu(dev
->size_low
);
2618 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
2620 if (is_gen_migration(dev
)) {
2621 info
->reshape_active
= 1;
2622 info
->new_level
= get_imsm_raid_level(map
);
2623 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
2624 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
2625 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
2626 if (info
->delta_disks
) {
2627 /* this needs to be applied to every array
2630 info
->reshape_active
= CONTAINER_RESHAPE
;
2632 /* We shape information that we give to md might have to be
2633 * modify to cope with md's requirement for reshaping arrays.
2634 * For example, when reshaping a RAID0, md requires it to be
2635 * presented as a degraded RAID4.
2636 * Also if a RAID0 is migrating to a RAID5 we need to specify
2637 * the array as already being RAID5, but the 'before' layout
2638 * is a RAID4-like layout.
2640 switch (info
->array
.level
) {
2642 switch(info
->new_level
) {
2644 /* conversion is happening as RAID4 */
2645 info
->array
.level
= 4;
2646 info
->array
.raid_disks
+= 1;
2649 /* conversion is happening as RAID5 */
2650 info
->array
.level
= 5;
2651 info
->array
.layout
= ALGORITHM_PARITY_N
;
2652 info
->delta_disks
-= 1;
2655 /* FIXME error message */
2656 info
->array
.level
= UnSet
;
2662 info
->new_level
= UnSet
;
2663 info
->new_layout
= UnSet
;
2664 info
->new_chunk
= info
->array
.chunk_size
;
2665 info
->delta_disks
= 0;
2669 info
->disk
.major
= dl
->major
;
2670 info
->disk
.minor
= dl
->minor
;
2671 info
->disk
.number
= dl
->index
;
2672 info
->disk
.raid_disk
= get_imsm_disk_slot(map_to_analyse
,
2676 info
->data_offset
= pba_of_lba0(map_to_analyse
);
2677 info
->component_size
= blocks_per_member(map_to_analyse
);
2679 info
->component_size
= imsm_component_size_aligment_check(
2681 info
->array
.chunk_size
,
2682 info
->component_size
);
2684 memset(info
->uuid
, 0, sizeof(info
->uuid
));
2685 info
->recovery_start
= MaxSector
;
2687 info
->reshape_progress
= 0;
2688 info
->resync_start
= MaxSector
;
2689 if ((map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
2691 imsm_reshape_blocks_arrays_changes(super
) == 0) {
2692 info
->resync_start
= 0;
2694 if (dev
->vol
.migr_state
) {
2695 switch (migr_type(dev
)) {
2698 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
2700 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
2702 info
->resync_start
= blocks_per_unit
* units
;
2705 case MIGR_GEN_MIGR
: {
2706 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
2708 __u64 units
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
2709 unsigned long long array_blocks
;
2712 if (__le32_to_cpu(migr_rec
->ascending_migr
) &&
2714 (__le32_to_cpu(migr_rec
->num_migr_units
)-1)) &&
2715 (super
->migr_rec
->rec_status
==
2716 __cpu_to_le32(UNIT_SRC_IN_CP_AREA
)))
2719 info
->reshape_progress
= blocks_per_unit
* units
;
2721 dprintf("IMSM: General Migration checkpoint : %llu "
2722 "(%llu) -> read reshape progress : %llu\n",
2723 (unsigned long long)units
,
2724 (unsigned long long)blocks_per_unit
,
2725 info
->reshape_progress
);
2727 used_disks
= imsm_num_data_members(dev
, MAP_1
);
2728 if (used_disks
> 0) {
2729 array_blocks
= blocks_per_member(map
) *
2731 /* round array size down to closest MB
2733 info
->custom_array_size
= (array_blocks
2734 >> SECT_PER_MB_SHIFT
)
2735 << SECT_PER_MB_SHIFT
;
2739 /* we could emulate the checkpointing of
2740 * 'sync_action=check' migrations, but for now
2741 * we just immediately complete them
2744 /* this is handled by container_content_imsm() */
2745 case MIGR_STATE_CHANGE
:
2746 /* FIXME handle other migrations */
2748 /* we are not dirty, so... */
2749 info
->resync_start
= MaxSector
;
2753 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
2754 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
2756 info
->array
.major_version
= -1;
2757 info
->array
.minor_version
= -2;
2758 sprintf(info
->text_version
, "/%s/%d", st
->container_devnm
, info
->container_member
);
2759 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
2760 uuid_from_super_imsm(st
, info
->uuid
);
2764 for (i
=0; i
<map_disks
; i
++) {
2766 if (i
< info
->array
.raid_disks
) {
2767 struct imsm_disk
*dsk
;
2768 j
= get_imsm_disk_idx(dev
, i
, MAP_X
);
2769 dsk
= get_imsm_disk(super
, j
);
2770 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
2777 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
2778 int failed
, int look_in_map
);
2780 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
2784 static void manage_second_map(struct intel_super
*super
, struct imsm_dev
*dev
)
2786 if (is_gen_migration(dev
)) {
2789 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
2791 failed
= imsm_count_failed(super
, dev
, MAP_1
);
2792 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_1
);
2793 if (map2
->map_state
!= map_state
) {
2794 map2
->map_state
= map_state
;
2795 super
->updates_pending
++;
2801 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
2805 for (d
= super
->missing
; d
; d
= d
->next
)
2806 if (d
->index
== index
)
2811 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
2813 struct intel_super
*super
= st
->sb
;
2814 struct imsm_disk
*disk
;
2815 int map_disks
= info
->array
.raid_disks
;
2816 int max_enough
= -1;
2818 struct imsm_super
*mpb
;
2820 if (super
->current_vol
>= 0) {
2821 getinfo_super_imsm_volume(st
, info
, map
);
2824 memset(info
, 0, sizeof(*info
));
2826 /* Set raid_disks to zero so that Assemble will always pull in valid
2829 info
->array
.raid_disks
= 0;
2830 info
->array
.level
= LEVEL_CONTAINER
;
2831 info
->array
.layout
= 0;
2832 info
->array
.md_minor
= -1;
2833 info
->array
.ctime
= 0; /* N/A for imsm */
2834 info
->array
.utime
= 0;
2835 info
->array
.chunk_size
= 0;
2837 info
->disk
.major
= 0;
2838 info
->disk
.minor
= 0;
2839 info
->disk
.raid_disk
= -1;
2840 info
->reshape_active
= 0;
2841 info
->array
.major_version
= -1;
2842 info
->array
.minor_version
= -2;
2843 strcpy(info
->text_version
, "imsm");
2844 info
->safe_mode_delay
= 0;
2845 info
->disk
.number
= -1;
2846 info
->disk
.state
= 0;
2848 info
->recovery_start
= MaxSector
;
2849 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
2851 /* do we have the all the insync disks that we expect? */
2852 mpb
= super
->anchor
;
2854 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
2855 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
2856 int failed
, enough
, j
, missing
= 0;
2857 struct imsm_map
*map
;
2860 failed
= imsm_count_failed(super
, dev
, MAP_0
);
2861 state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
2862 map
= get_imsm_map(dev
, MAP_0
);
2864 /* any newly missing disks?
2865 * (catches single-degraded vs double-degraded)
2867 for (j
= 0; j
< map
->num_members
; j
++) {
2868 __u32 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
2869 __u32 idx
= ord_to_idx(ord
);
2871 if (!(ord
& IMSM_ORD_REBUILD
) &&
2872 get_imsm_missing(super
, idx
)) {
2878 if (state
== IMSM_T_STATE_FAILED
)
2880 else if (state
== IMSM_T_STATE_DEGRADED
&&
2881 (state
!= map
->map_state
|| missing
))
2883 else /* we're normal, or already degraded */
2885 if (is_gen_migration(dev
) && missing
) {
2886 /* during general migration we need all disks
2887 * that process is running on.
2888 * No new missing disk is allowed.
2892 /* no more checks necessary
2896 /* in the missing/failed disk case check to see
2897 * if at least one array is runnable
2899 max_enough
= max(max_enough
, enough
);
2901 dprintf("%s: enough: %d\n", __func__
, max_enough
);
2902 info
->container_enough
= max_enough
;
2905 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
2907 disk
= &super
->disks
->disk
;
2908 info
->data_offset
= total_blocks(&super
->disks
->disk
) - reserved
;
2909 info
->component_size
= reserved
;
2910 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
2911 /* we don't change info->disk.raid_disk here because
2912 * this state will be finalized in mdmon after we have
2913 * found the 'most fresh' version of the metadata
2915 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
2916 info
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
2919 /* only call uuid_from_super_imsm when this disk is part of a populated container,
2920 * ->compare_super may have updated the 'num_raid_devs' field for spares
2922 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
2923 uuid_from_super_imsm(st
, info
->uuid
);
2925 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
2927 /* I don't know how to compute 'map' on imsm, so use safe default */
2930 for (i
= 0; i
< map_disks
; i
++)
2936 /* allocates memory and fills disk in mdinfo structure
2937 * for each disk in array */
2938 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
2940 struct mdinfo
*mddev
= NULL
;
2941 struct intel_super
*super
= st
->sb
;
2942 struct imsm_disk
*disk
;
2945 if (!super
|| !super
->disks
)
2948 mddev
= xcalloc(1, sizeof(*mddev
));
2952 tmp
= xcalloc(1, sizeof(*tmp
));
2954 tmp
->next
= mddev
->devs
;
2956 tmp
->disk
.number
= count
++;
2957 tmp
->disk
.major
= dl
->major
;
2958 tmp
->disk
.minor
= dl
->minor
;
2959 tmp
->disk
.state
= is_configured(disk
) ?
2960 (1 << MD_DISK_ACTIVE
) : 0;
2961 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
2962 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
2963 tmp
->disk
.raid_disk
= -1;
2969 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
2970 char *update
, char *devname
, int verbose
,
2971 int uuid_set
, char *homehost
)
2973 /* For 'assemble' and 'force' we need to return non-zero if any
2974 * change was made. For others, the return value is ignored.
2975 * Update options are:
2976 * force-one : This device looks a bit old but needs to be included,
2977 * update age info appropriately.
2978 * assemble: clear any 'faulty' flag to allow this device to
2980 * force-array: Array is degraded but being forced, mark it clean
2981 * if that will be needed to assemble it.
2983 * newdev: not used ????
2984 * grow: Array has gained a new device - this is currently for
2986 * resync: mark as dirty so a resync will happen.
2987 * name: update the name - preserving the homehost
2988 * uuid: Change the uuid of the array to match watch is given
2990 * Following are not relevant for this imsm:
2991 * sparc2.2 : update from old dodgey metadata
2992 * super-minor: change the preferred_minor number
2993 * summaries: update redundant counters.
2994 * homehost: update the recorded homehost
2995 * _reshape_progress: record new reshape_progress position.
2998 struct intel_super
*super
= st
->sb
;
2999 struct imsm_super
*mpb
;
3001 /* we can only update container info */
3002 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
3005 mpb
= super
->anchor
;
3007 if (strcmp(update
, "uuid") == 0) {
3008 /* We take this to mean that the family_num should be updated.
3009 * However that is much smaller than the uuid so we cannot really
3010 * allow an explicit uuid to be given. And it is hard to reliably
3012 * So if !uuid_set we know the current uuid is random and just used
3013 * the first 'int' and copy it to the other 3 positions.
3014 * Otherwise we require the 4 'int's to be the same as would be the
3015 * case if we are using a random uuid. So an explicit uuid will be
3016 * accepted as long as all for ints are the same... which shouldn't hurt
3019 info
->uuid
[1] = info
->uuid
[2] = info
->uuid
[3] = info
->uuid
[0];
3022 if (info
->uuid
[0] != info
->uuid
[1] ||
3023 info
->uuid
[1] != info
->uuid
[2] ||
3024 info
->uuid
[2] != info
->uuid
[3])
3030 mpb
->orig_family_num
= info
->uuid
[0];
3031 } else if (strcmp(update
, "assemble") == 0)
3036 /* successful update? recompute checksum */
3038 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
3043 static size_t disks_to_mpb_size(int disks
)
3047 size
= sizeof(struct imsm_super
);
3048 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
3049 size
+= 2 * sizeof(struct imsm_dev
);
3050 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
3051 size
+= (4 - 2) * sizeof(struct imsm_map
);
3052 /* 4 possible disk_ord_tbl's */
3053 size
+= 4 * (disks
- 1) * sizeof(__u32
);
3058 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
,
3059 unsigned long long data_offset
)
3061 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
3064 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
3067 static void free_devlist(struct intel_super
*super
)
3069 struct intel_dev
*dv
;
3071 while (super
->devlist
) {
3072 dv
= super
->devlist
->next
;
3073 free(super
->devlist
->dev
);
3074 free(super
->devlist
);
3075 super
->devlist
= dv
;
3079 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
3081 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
3084 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
)
3088 * 0 same, or first was empty, and second was copied
3089 * 1 second had wrong number
3091 * 3 wrong other info
3093 struct intel_super
*first
= st
->sb
;
3094 struct intel_super
*sec
= tst
->sb
;
3101 /* in platform dependent environment test if the disks
3102 * use the same Intel hba
3103 * If not on Intel hba at all, allow anything.
3105 if (!check_env("IMSM_NO_PLATFORM") && first
->hba
&& sec
->hba
) {
3106 if (first
->hba
->type
!= sec
->hba
->type
) {
3108 "HBAs of devices do not match %s != %s\n",
3109 get_sys_dev_type(first
->hba
->type
),
3110 get_sys_dev_type(sec
->hba
->type
));
3113 if (first
->orom
!= sec
->orom
) {
3115 "HBAs of devices do not match %s != %s\n",
3116 first
->hba
->pci_id
, sec
->hba
->pci_id
);
3121 /* if an anchor does not have num_raid_devs set then it is a free
3124 if (first
->anchor
->num_raid_devs
> 0 &&
3125 sec
->anchor
->num_raid_devs
> 0) {
3126 /* Determine if these disks might ever have been
3127 * related. Further disambiguation can only take place
3128 * in load_super_imsm_all
3130 __u32 first_family
= first
->anchor
->orig_family_num
;
3131 __u32 sec_family
= sec
->anchor
->orig_family_num
;
3133 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
3134 MAX_SIGNATURE_LENGTH
) != 0)
3137 if (first_family
== 0)
3138 first_family
= first
->anchor
->family_num
;
3139 if (sec_family
== 0)
3140 sec_family
= sec
->anchor
->family_num
;
3142 if (first_family
!= sec_family
)
3147 /* if 'first' is a spare promote it to a populated mpb with sec's
3150 if (first
->anchor
->num_raid_devs
== 0 &&
3151 sec
->anchor
->num_raid_devs
> 0) {
3153 struct intel_dev
*dv
;
3154 struct imsm_dev
*dev
;
3156 /* we need to copy raid device info from sec if an allocation
3157 * fails here we don't associate the spare
3159 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++) {
3160 dv
= xmalloc(sizeof(*dv
));
3161 dev
= xmalloc(sizeof_imsm_dev(get_imsm_dev(sec
, i
), 1));
3164 dv
->next
= first
->devlist
;
3165 first
->devlist
= dv
;
3167 if (i
< sec
->anchor
->num_raid_devs
) {
3168 /* allocation failure */
3169 free_devlist(first
);
3170 pr_err("imsm: failed to associate spare\n");
3173 first
->anchor
->num_raid_devs
= sec
->anchor
->num_raid_devs
;
3174 first
->anchor
->orig_family_num
= sec
->anchor
->orig_family_num
;
3175 first
->anchor
->family_num
= sec
->anchor
->family_num
;
3176 memcpy(first
->anchor
->sig
, sec
->anchor
->sig
, MAX_SIGNATURE_LENGTH
);
3177 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++)
3178 imsm_copy_dev(get_imsm_dev(first
, i
), get_imsm_dev(sec
, i
));
3184 static void fd2devname(int fd
, char *name
)
3188 char dname
[PATH_MAX
];
3193 if (fstat(fd
, &st
) != 0)
3195 sprintf(path
, "/sys/dev/block/%d:%d",
3196 major(st
.st_rdev
), minor(st
.st_rdev
));
3198 rv
= readlink(path
, dname
, sizeof(dname
)-1);
3203 nm
= strrchr(dname
, '/');
3206 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
3210 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
3212 static int imsm_read_serial(int fd
, char *devname
,
3213 __u8 serial
[MAX_RAID_SERIAL_LEN
])
3215 unsigned char scsi_serial
[255];
3224 memset(scsi_serial
, 0, sizeof(scsi_serial
));
3226 rv
= scsi_get_serial(fd
, scsi_serial
, sizeof(scsi_serial
));
3228 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
3229 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3230 fd2devname(fd
, (char *) serial
);
3236 pr_err("Failed to retrieve serial for %s\n",
3241 rsp_len
= scsi_serial
[3];
3244 pr_err("Failed to retrieve serial for %s\n",
3248 rsp_buf
= (char *) &scsi_serial
[4];
3250 /* trim all whitespace and non-printable characters and convert
3253 for (i
= 0, dest
= rsp_buf
; i
< rsp_len
; i
++) {
3256 /* ':' is reserved for use in placeholder serial
3257 * numbers for missing disks
3265 len
= dest
- rsp_buf
;
3268 /* truncate leading characters */
3269 if (len
> MAX_RAID_SERIAL_LEN
) {
3270 dest
+= len
- MAX_RAID_SERIAL_LEN
;
3271 len
= MAX_RAID_SERIAL_LEN
;
3274 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3275 memcpy(serial
, dest
, len
);
3280 static int serialcmp(__u8
*s1
, __u8
*s2
)
3282 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
3285 static void serialcpy(__u8
*dest
, __u8
*src
)
3287 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
3290 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
3294 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3295 if (serialcmp(dl
->serial
, serial
) == 0)
3301 static struct imsm_disk
*
3302 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
3306 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3307 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
3309 if (serialcmp(disk
->serial
, serial
) == 0) {
3320 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3322 struct imsm_disk
*disk
;
3327 __u8 serial
[MAX_RAID_SERIAL_LEN
];
3329 rv
= imsm_read_serial(fd
, devname
, serial
);
3334 dl
= xcalloc(1, sizeof(*dl
));
3337 dl
->major
= major(stb
.st_rdev
);
3338 dl
->minor
= minor(stb
.st_rdev
);
3339 dl
->next
= super
->disks
;
3340 dl
->fd
= keep_fd
? fd
: -1;
3341 assert(super
->disks
== NULL
);
3343 serialcpy(dl
->serial
, serial
);
3346 fd2devname(fd
, name
);
3348 dl
->devname
= xstrdup(devname
);
3350 dl
->devname
= xstrdup(name
);
3352 /* look up this disk's index in the current anchor */
3353 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
3356 /* only set index on disks that are a member of a
3357 * populated contianer, i.e. one with raid_devs
3359 if (is_failed(&dl
->disk
))
3361 else if (is_spare(&dl
->disk
))
3369 /* When migrating map0 contains the 'destination' state while map1
3370 * contains the current state. When not migrating map0 contains the
3371 * current state. This routine assumes that map[0].map_state is set to
3372 * the current array state before being called.
3374 * Migration is indicated by one of the following states
3375 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
3376 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
3377 * map1state=unitialized)
3378 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
3380 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
3381 * map1state=degraded)
3382 * 5/ Migration (mig_state=1 migr_type=MIGR_GEN_MIGR map0state=normal
3385 static void migrate(struct imsm_dev
*dev
, struct intel_super
*super
,
3386 __u8 to_state
, int migr_type
)
3388 struct imsm_map
*dest
;
3389 struct imsm_map
*src
= get_imsm_map(dev
, MAP_0
);
3391 dev
->vol
.migr_state
= 1;
3392 set_migr_type(dev
, migr_type
);
3393 dev
->vol
.curr_migr_unit
= 0;
3394 dest
= get_imsm_map(dev
, MAP_1
);
3396 /* duplicate and then set the target end state in map[0] */
3397 memcpy(dest
, src
, sizeof_imsm_map(src
));
3398 if ((migr_type
== MIGR_REBUILD
) ||
3399 (migr_type
== MIGR_GEN_MIGR
)) {
3403 for (i
= 0; i
< src
->num_members
; i
++) {
3404 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
3405 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
3409 if (migr_type
== MIGR_GEN_MIGR
)
3410 /* Clear migration record */
3411 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
3413 src
->map_state
= to_state
;
3416 static void end_migration(struct imsm_dev
*dev
, struct intel_super
*super
,
3419 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3420 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
== 0 ?
3424 /* merge any IMSM_ORD_REBUILD bits that were not successfully
3425 * completed in the last migration.
3427 * FIXME add support for raid-level-migration
3429 if ((map_state
!= map
->map_state
) && (is_gen_migration(dev
) == 0) &&
3430 (prev
->map_state
!= IMSM_T_STATE_UNINITIALIZED
)) {
3431 /* when final map state is other than expected
3432 * merge maps (not for migration)
3436 for (i
= 0; i
< prev
->num_members
; i
++)
3437 for (j
= 0; j
< map
->num_members
; j
++)
3438 /* during online capacity expansion
3439 * disks position can be changed
3440 * if takeover is used
3442 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
3443 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
3444 map
->disk_ord_tbl
[j
] |=
3445 prev
->disk_ord_tbl
[i
];
3448 failed
= imsm_count_failed(super
, dev
, MAP_0
);
3449 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
3452 dev
->vol
.migr_state
= 0;
3453 set_migr_type(dev
, 0);
3454 dev
->vol
.curr_migr_unit
= 0;
3455 map
->map_state
= map_state
;
3459 static int parse_raid_devices(struct intel_super
*super
)
3462 struct imsm_dev
*dev_new
;
3463 size_t len
, len_migr
;
3465 size_t space_needed
= 0;
3466 struct imsm_super
*mpb
= super
->anchor
;
3468 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3469 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3470 struct intel_dev
*dv
;
3472 len
= sizeof_imsm_dev(dev_iter
, 0);
3473 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
3475 space_needed
+= len_migr
- len
;
3477 dv
= xmalloc(sizeof(*dv
));
3478 if (max_len
< len_migr
)
3480 if (max_len
> len_migr
)
3481 space_needed
+= max_len
- len_migr
;
3482 dev_new
= xmalloc(max_len
);
3483 imsm_copy_dev(dev_new
, dev_iter
);
3486 dv
->next
= super
->devlist
;
3487 super
->devlist
= dv
;
3490 /* ensure that super->buf is large enough when all raid devices
3493 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
3496 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
, 512);
3497 if (posix_memalign(&buf
, 512, len
) != 0)
3500 memcpy(buf
, super
->buf
, super
->len
);
3501 memset(buf
+ super
->len
, 0, len
- super
->len
);
3510 /* retrieve a pointer to the bbm log which starts after all raid devices */
3511 struct bbm_log
*__get_imsm_bbm_log(struct imsm_super
*mpb
)
3515 if (__le32_to_cpu(mpb
->bbm_log_size
)) {
3517 ptr
+= mpb
->mpb_size
- __le32_to_cpu(mpb
->bbm_log_size
);
3523 /*******************************************************************************
3524 * Function: check_mpb_migr_compatibility
3525 * Description: Function checks for unsupported migration features:
3526 * - migration optimization area (pba_of_lba0)
3527 * - descending reshape (ascending_migr)
3529 * super : imsm metadata information
3531 * 0 : migration is compatible
3532 * -1 : migration is not compatible
3533 ******************************************************************************/
3534 int check_mpb_migr_compatibility(struct intel_super
*super
)
3536 struct imsm_map
*map0
, *map1
;
3537 struct migr_record
*migr_rec
= super
->migr_rec
;
3540 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3541 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3544 dev_iter
->vol
.migr_state
== 1 &&
3545 dev_iter
->vol
.migr_type
== MIGR_GEN_MIGR
) {
3546 /* This device is migrating */
3547 map0
= get_imsm_map(dev_iter
, MAP_0
);
3548 map1
= get_imsm_map(dev_iter
, MAP_1
);
3549 if (pba_of_lba0(map0
) != pba_of_lba0(map1
))
3550 /* migration optimization area was used */
3552 if (migr_rec
->ascending_migr
== 0
3553 && migr_rec
->dest_depth_per_unit
> 0)
3554 /* descending reshape not supported yet */
3561 static void __free_imsm(struct intel_super
*super
, int free_disks
);
3563 /* load_imsm_mpb - read matrix metadata
3564 * allocates super->mpb to be freed by free_imsm
3566 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
3568 unsigned long long dsize
;
3569 unsigned long long sectors
;
3571 struct imsm_super
*anchor
;
3574 get_dev_size(fd
, NULL
, &dsize
);
3577 pr_err("%s: device to small for imsm\n",
3582 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0) {
3584 pr_err("Cannot seek to anchor block on %s: %s\n",
3585 devname
, strerror(errno
));
3589 if (posix_memalign((void**)&anchor
, 512, 512) != 0) {
3591 pr_err("Failed to allocate imsm anchor buffer"
3592 " on %s\n", devname
);
3595 if (read(fd
, anchor
, 512) != 512) {
3597 pr_err("Cannot read anchor block on %s: %s\n",
3598 devname
, strerror(errno
));
3603 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
3605 pr_err("no IMSM anchor on %s\n", devname
);
3610 __free_imsm(super
, 0);
3611 /* reload capability and hba */
3613 /* capability and hba must be updated with new super allocation */
3614 find_intel_hba_capability(fd
, super
, devname
);
3615 super
->len
= ROUND_UP(anchor
->mpb_size
, 512);
3616 if (posix_memalign(&super
->buf
, 512, super
->len
) != 0) {
3618 pr_err("unable to allocate %zu byte mpb buffer\n",
3623 memcpy(super
->buf
, anchor
, 512);
3625 sectors
= mpb_sectors(anchor
) - 1;
3628 if (posix_memalign(&super
->migr_rec_buf
, 512, MIGR_REC_BUF_SIZE
) != 0) {
3629 pr_err("%s could not allocate migr_rec buffer\n", __func__
);
3633 super
->clean_migration_record_by_mdmon
= 0;
3636 check_sum
= __gen_imsm_checksum(super
->anchor
);
3637 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
3639 pr_err("IMSM checksum %x != %x on %s\n",
3641 __le32_to_cpu(super
->anchor
->check_sum
),
3649 /* read the extended mpb */
3650 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0) {
3652 pr_err("Cannot seek to extended mpb on %s: %s\n",
3653 devname
, strerror(errno
));
3657 if ((unsigned)read(fd
, super
->buf
+ 512, super
->len
- 512) != super
->len
- 512) {
3659 pr_err("Cannot read extended mpb on %s: %s\n",
3660 devname
, strerror(errno
));
3664 check_sum
= __gen_imsm_checksum(super
->anchor
);
3665 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
3667 pr_err("IMSM checksum %x != %x on %s\n",
3668 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
3673 /* FIXME the BBM log is disk specific so we cannot use this global
3674 * buffer for all disks. Ok for now since we only look at the global
3675 * bbm_log_size parameter to gate assembly
3677 super
->bbm_log
= __get_imsm_bbm_log(super
->anchor
);
3682 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
);
3684 /* clears hi bits in metadata if MPB_ATTRIB_2TB_DISK not set */
3685 static void clear_hi(struct intel_super
*super
)
3687 struct imsm_super
*mpb
= super
->anchor
;
3689 if (mpb
->attributes
& MPB_ATTRIB_2TB_DISK
)
3691 for (i
= 0; i
< mpb
->num_disks
; ++i
) {
3692 struct imsm_disk
*disk
= &mpb
->disk
[i
];
3693 disk
->total_blocks_hi
= 0;
3695 for (i
= 0; i
< mpb
->num_raid_devs
; ++i
) {
3696 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
3699 for (n
= 0; n
< 2; ++n
) {
3700 struct imsm_map
*map
= get_imsm_map(dev
, n
);
3703 map
->pba_of_lba0_hi
= 0;
3704 map
->blocks_per_member_hi
= 0;
3705 map
->num_data_stripes_hi
= 0;
3711 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3715 err
= load_imsm_mpb(fd
, super
, devname
);
3718 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
3721 err
= parse_raid_devices(super
);
3726 static void __free_imsm_disk(struct dl
*d
)
3738 static void free_imsm_disks(struct intel_super
*super
)
3742 while (super
->disks
) {
3744 super
->disks
= d
->next
;
3745 __free_imsm_disk(d
);
3747 while (super
->disk_mgmt_list
) {
3748 d
= super
->disk_mgmt_list
;
3749 super
->disk_mgmt_list
= d
->next
;
3750 __free_imsm_disk(d
);
3752 while (super
->missing
) {
3754 super
->missing
= d
->next
;
3755 __free_imsm_disk(d
);
3760 /* free all the pieces hanging off of a super pointer */
3761 static void __free_imsm(struct intel_super
*super
, int free_disks
)
3763 struct intel_hba
*elem
, *next
;
3769 /* unlink capability description */
3771 if (super
->migr_rec_buf
) {
3772 free(super
->migr_rec_buf
);
3773 super
->migr_rec_buf
= NULL
;
3776 free_imsm_disks(super
);
3777 free_devlist(super
);
3781 free((void *)elem
->path
);
3789 static void free_imsm(struct intel_super
*super
)
3791 __free_imsm(super
, 1);
3795 static void free_super_imsm(struct supertype
*st
)
3797 struct intel_super
*super
= st
->sb
;
3806 static struct intel_super
*alloc_super(void)
3808 struct intel_super
*super
= xcalloc(1, sizeof(*super
));
3810 super
->current_vol
= -1;
3811 super
->create_offset
= ~((unsigned long long) 0);
3816 * find and allocate hba and OROM/EFI based on valid fd of RAID component device
3818 static int find_intel_hba_capability(int fd
, struct intel_super
*super
, char *devname
)
3820 struct sys_dev
*hba_name
;
3823 if ((fd
< 0) || check_env("IMSM_NO_PLATFORM")) {
3828 hba_name
= find_disk_attached_hba(fd
, NULL
);
3831 pr_err("%s is not attached to Intel(R) RAID controller.\n",
3835 rv
= attach_hba_to_super(super
, hba_name
);
3838 struct intel_hba
*hba
= super
->hba
;
3840 pr_err("%s is attached to Intel(R) %s RAID "
3841 "controller (%s),\n"
3842 " but the container is assigned to Intel(R) "
3843 "%s RAID controller (",
3845 get_sys_dev_type(hba_name
->type
),
3846 hba_name
->pci_id
? : "Err!",
3847 get_sys_dev_type(super
->hba
->type
));
3850 fprintf(stderr
, "%s", hba
->pci_id
? : "Err!");
3852 fprintf(stderr
, ", ");
3855 fprintf(stderr
, ").\n"
3856 " Mixing devices attached to different controllers "
3857 "is not allowed.\n");
3861 super
->orom
= find_imsm_capability(hba_name
);
3868 /* find_missing - helper routine for load_super_imsm_all that identifies
3869 * disks that have disappeared from the system. This routine relies on
3870 * the mpb being uptodate, which it is at load time.
3872 static int find_missing(struct intel_super
*super
)
3875 struct imsm_super
*mpb
= super
->anchor
;
3877 struct imsm_disk
*disk
;
3879 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3880 disk
= __get_imsm_disk(mpb
, i
);
3881 dl
= serial_to_dl(disk
->serial
, super
);
3885 dl
= xmalloc(sizeof(*dl
));
3889 dl
->devname
= xstrdup("missing");
3891 serialcpy(dl
->serial
, disk
->serial
);
3894 dl
->next
= super
->missing
;
3895 super
->missing
= dl
;
3902 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
3904 struct intel_disk
*idisk
= disk_list
;
3907 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
3909 idisk
= idisk
->next
;
3915 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
3916 struct intel_super
*super
,
3917 struct intel_disk
**disk_list
)
3919 struct imsm_disk
*d
= &super
->disks
->disk
;
3920 struct imsm_super
*mpb
= super
->anchor
;
3923 for (i
= 0; i
< tbl_size
; i
++) {
3924 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
3925 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
3927 if (tbl_mpb
->family_num
== mpb
->family_num
) {
3928 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
3929 dprintf("%s: mpb from %d:%d matches %d:%d\n",
3930 __func__
, super
->disks
->major
,
3931 super
->disks
->minor
,
3932 table
[i
]->disks
->major
,
3933 table
[i
]->disks
->minor
);
3937 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
3938 is_configured(d
) == is_configured(tbl_d
)) &&
3939 tbl_mpb
->generation_num
< mpb
->generation_num
) {
3940 /* current version of the mpb is a
3941 * better candidate than the one in
3942 * super_table, but copy over "cross
3943 * generational" status
3945 struct intel_disk
*idisk
;
3947 dprintf("%s: mpb from %d:%d replaces %d:%d\n",
3948 __func__
, super
->disks
->major
,
3949 super
->disks
->minor
,
3950 table
[i
]->disks
->major
,
3951 table
[i
]->disks
->minor
);
3953 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
3954 if (idisk
&& is_failed(&idisk
->disk
))
3955 tbl_d
->status
|= FAILED_DISK
;
3958 struct intel_disk
*idisk
;
3959 struct imsm_disk
*disk
;
3961 /* tbl_mpb is more up to date, but copy
3962 * over cross generational status before
3965 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
3966 if (disk
&& is_failed(disk
))
3967 d
->status
|= FAILED_DISK
;
3969 idisk
= disk_list_get(d
->serial
, *disk_list
);
3972 if (disk
&& is_configured(disk
))
3973 idisk
->disk
.status
|= CONFIGURED_DISK
;
3976 dprintf("%s: mpb from %d:%d prefer %d:%d\n",
3977 __func__
, super
->disks
->major
,
3978 super
->disks
->minor
,
3979 table
[i
]->disks
->major
,
3980 table
[i
]->disks
->minor
);
3988 table
[tbl_size
++] = super
;
3992 /* update/extend the merged list of imsm_disk records */
3993 for (j
= 0; j
< mpb
->num_disks
; j
++) {
3994 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
3995 struct intel_disk
*idisk
;
3997 idisk
= disk_list_get(disk
->serial
, *disk_list
);
3999 idisk
->disk
.status
|= disk
->status
;
4000 if (is_configured(&idisk
->disk
) ||
4001 is_failed(&idisk
->disk
))
4002 idisk
->disk
.status
&= ~(SPARE_DISK
);
4004 idisk
= xcalloc(1, sizeof(*idisk
));
4005 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
4006 idisk
->disk
= *disk
;
4007 idisk
->next
= *disk_list
;
4011 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
4018 static struct intel_super
*
4019 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
4022 struct imsm_super
*mpb
= super
->anchor
;
4026 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4027 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
4028 struct intel_disk
*idisk
;
4030 idisk
= disk_list_get(disk
->serial
, disk_list
);
4032 if (idisk
->owner
== owner
||
4033 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
4036 dprintf("%s: '%.16s' owner %d != %d\n",
4037 __func__
, disk
->serial
, idisk
->owner
,
4040 dprintf("%s: unknown disk %x [%d]: %.16s\n",
4041 __func__
, __le32_to_cpu(mpb
->family_num
), i
,
4047 if (ok_count
== mpb
->num_disks
)
4052 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
4054 struct intel_super
*s
;
4056 for (s
= super_list
; s
; s
= s
->next
) {
4057 if (family_num
!= s
->anchor
->family_num
)
4059 pr_err("Conflict, offlining family %#x on '%s'\n",
4060 __le32_to_cpu(family_num
), s
->disks
->devname
);
4064 static struct intel_super
*
4065 imsm_thunderdome(struct intel_super
**super_list
, int len
)
4067 struct intel_super
*super_table
[len
];
4068 struct intel_disk
*disk_list
= NULL
;
4069 struct intel_super
*champion
, *spare
;
4070 struct intel_super
*s
, **del
;
4075 memset(super_table
, 0, sizeof(super_table
));
4076 for (s
= *super_list
; s
; s
= s
->next
)
4077 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
4079 for (i
= 0; i
< tbl_size
; i
++) {
4080 struct imsm_disk
*d
;
4081 struct intel_disk
*idisk
;
4082 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
4085 d
= &s
->disks
->disk
;
4087 /* 'd' must appear in merged disk list for its
4088 * configuration to be valid
4090 idisk
= disk_list_get(d
->serial
, disk_list
);
4091 if (idisk
&& idisk
->owner
== i
)
4092 s
= validate_members(s
, disk_list
, i
);
4097 dprintf("%s: marking family: %#x from %d:%d offline\n",
4098 __func__
, mpb
->family_num
,
4099 super_table
[i
]->disks
->major
,
4100 super_table
[i
]->disks
->minor
);
4104 /* This is where the mdadm implementation differs from the Windows
4105 * driver which has no strict concept of a container. We can only
4106 * assemble one family from a container, so when returning a prodigal
4107 * array member to this system the code will not be able to disambiguate
4108 * the container contents that should be assembled ("foreign" versus
4109 * "local"). It requires user intervention to set the orig_family_num
4110 * to a new value to establish a new container. The Windows driver in
4111 * this situation fixes up the volume name in place and manages the
4112 * foreign array as an independent entity.
4117 for (i
= 0; i
< tbl_size
; i
++) {
4118 struct intel_super
*tbl_ent
= super_table
[i
];
4124 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
4129 if (s
&& !is_spare
) {
4130 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
4132 } else if (!s
&& !is_spare
)
4145 pr_err("Chose family %#x on '%s', "
4146 "assemble conflicts to new container with '--update=uuid'\n",
4147 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
4149 /* collect all dl's onto 'champion', and update them to
4150 * champion's version of the status
4152 for (s
= *super_list
; s
; s
= s
->next
) {
4153 struct imsm_super
*mpb
= champion
->anchor
;
4154 struct dl
*dl
= s
->disks
;
4159 mpb
->attributes
|= s
->anchor
->attributes
& MPB_ATTRIB_2TB_DISK
;
4161 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4162 struct imsm_disk
*disk
;
4164 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
4167 /* only set index on disks that are a member of
4168 * a populated contianer, i.e. one with
4171 if (is_failed(&dl
->disk
))
4173 else if (is_spare(&dl
->disk
))
4179 if (i
>= mpb
->num_disks
) {
4180 struct intel_disk
*idisk
;
4182 idisk
= disk_list_get(dl
->serial
, disk_list
);
4183 if (idisk
&& is_spare(&idisk
->disk
) &&
4184 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
4192 dl
->next
= champion
->disks
;
4193 champion
->disks
= dl
;
4197 /* delete 'champion' from super_list */
4198 for (del
= super_list
; *del
; ) {
4199 if (*del
== champion
) {
4200 *del
= (*del
)->next
;
4203 del
= &(*del
)->next
;
4205 champion
->next
= NULL
;
4209 struct intel_disk
*idisk
= disk_list
;
4211 disk_list
= disk_list
->next
;
4219 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
);
4220 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4221 int major
, int minor
, int keep_fd
);
4223 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4224 int *max
, int keep_fd
);
4226 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
4227 char *devname
, struct md_list
*devlist
,
4230 struct intel_super
*super_list
= NULL
;
4231 struct intel_super
*super
= NULL
;
4236 /* 'fd' is an opened container */
4237 err
= get_sra_super_block(fd
, &super_list
, devname
, &i
, keep_fd
);
4239 /* get super block from devlist devices */
4240 err
= get_devlist_super_block(devlist
, &super_list
, &i
, keep_fd
);
4243 /* all mpbs enter, maybe one leaves */
4244 super
= imsm_thunderdome(&super_list
, i
);
4250 if (find_missing(super
) != 0) {
4256 /* load migration record */
4257 err
= load_imsm_migr_rec(super
, NULL
);
4259 /* migration is in progress,
4260 * but migr_rec cannot be loaded,
4266 /* Check migration compatibility */
4267 if ((err
== 0) && (check_mpb_migr_compatibility(super
) != 0)) {
4268 pr_err("Unsupported migration detected");
4270 fprintf(stderr
, " on %s\n", devname
);
4272 fprintf(stderr
, " (IMSM).\n");
4281 while (super_list
) {
4282 struct intel_super
*s
= super_list
;
4284 super_list
= super_list
->next
;
4293 strcpy(st
->container_devnm
, fd2devnm(fd
));
4295 st
->container_devnm
[0] = 0;
4296 if (err
== 0 && st
->ss
== NULL
) {
4297 st
->ss
= &super_imsm
;
4298 st
->minor_version
= 0;
4299 st
->max_devs
= IMSM_MAX_DEVICES
;
4305 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4306 int *max
, int keep_fd
)
4308 struct md_list
*tmpdev
;
4312 for (i
= 0, tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
4313 if (tmpdev
->used
!= 1)
4315 if (tmpdev
->container
== 1) {
4317 int fd
= dev_open(tmpdev
->devname
, O_RDONLY
|O_EXCL
);
4319 pr_err("cannot open device %s: %s\n",
4320 tmpdev
->devname
, strerror(errno
));
4324 err
= get_sra_super_block(fd
, super_list
,
4325 tmpdev
->devname
, &lmax
,
4334 int major
= major(tmpdev
->st_rdev
);
4335 int minor
= minor(tmpdev
->st_rdev
);
4336 err
= get_super_block(super_list
,
4353 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4354 int major
, int minor
, int keep_fd
)
4356 struct intel_super
*s
= NULL
;
4368 sprintf(nm
, "%d:%d", major
, minor
);
4369 dfd
= dev_open(nm
, O_RDWR
);
4375 find_intel_hba_capability(dfd
, s
, devname
);
4376 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
4378 /* retry the load if we might have raced against mdmon */
4379 if (err
== 3 && devnm
&& mdmon_running(devnm
))
4380 for (retry
= 0; retry
< 3; retry
++) {
4382 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
4388 s
->next
= *super_list
;
4396 if ((dfd
>= 0) && (!keep_fd
))
4403 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
)
4410 sra
= sysfs_read(fd
, NULL
, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
4414 if (sra
->array
.major_version
!= -1 ||
4415 sra
->array
.minor_version
!= -2 ||
4416 strcmp(sra
->text_version
, "imsm") != 0) {
4421 devnm
= fd2devnm(fd
);
4422 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
4423 if (get_super_block(super_list
, devnm
, devname
,
4424 sd
->disk
.major
, sd
->disk
.minor
, keep_fd
) != 0) {
4435 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
4437 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
, NULL
, 1);
4441 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
4443 struct intel_super
*super
;
4447 if (test_partition(fd
))
4448 /* IMSM not allowed on partitions */
4451 free_super_imsm(st
);
4453 super
= alloc_super();
4454 /* Load hba and capabilities if they exist.
4455 * But do not preclude loading metadata in case capabilities or hba are
4456 * non-compliant and ignore_hw_compat is set.
4458 rv
= find_intel_hba_capability(fd
, super
, devname
);
4459 /* no orom/efi or non-intel hba of the disk */
4460 if ((rv
!= 0) && (st
->ignore_hw_compat
== 0)) {
4462 pr_err("No OROM/EFI properties for %s\n", devname
);
4466 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
4468 /* retry the load if we might have raced against mdmon */
4470 struct mdstat_ent
*mdstat
= mdstat_by_component(fd2devnm(fd
));
4472 if (mdstat
&& mdmon_running(mdstat
->devnm
) && getpid() != mdmon_pid(mdstat
->devnm
)) {
4473 for (retry
= 0; retry
< 3; retry
++) {
4475 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
4481 free_mdstat(mdstat
);
4486 pr_err("Failed to load all information "
4487 "sections on %s\n", devname
);
4493 if (st
->ss
== NULL
) {
4494 st
->ss
= &super_imsm
;
4495 st
->minor_version
= 0;
4496 st
->max_devs
= IMSM_MAX_DEVICES
;
4499 /* load migration record */
4500 if (load_imsm_migr_rec(super
, NULL
) == 0) {
4501 /* Check for unsupported migration features */
4502 if (check_mpb_migr_compatibility(super
) != 0) {
4503 pr_err("Unsupported migration detected");
4505 fprintf(stderr
, " on %s\n", devname
);
4507 fprintf(stderr
, " (IMSM).\n");
4515 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
4517 if (info
->level
== 1)
4519 return info
->chunk_size
>> 9;
4522 static unsigned long long info_to_blocks_per_member(mdu_array_info_t
*info
,
4523 unsigned long long size
)
4525 if (info
->level
== 1)
4528 return (size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
4531 static void imsm_update_version_info(struct intel_super
*super
)
4533 /* update the version and attributes */
4534 struct imsm_super
*mpb
= super
->anchor
;
4536 struct imsm_dev
*dev
;
4537 struct imsm_map
*map
;
4540 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4541 dev
= get_imsm_dev(super
, i
);
4542 map
= get_imsm_map(dev
, MAP_0
);
4543 if (__le32_to_cpu(dev
->size_high
) > 0)
4544 mpb
->attributes
|= MPB_ATTRIB_2TB
;
4546 /* FIXME detect when an array spans a port multiplier */
4548 mpb
->attributes
|= MPB_ATTRIB_PM
;
4551 if (mpb
->num_raid_devs
> 1 ||
4552 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
4553 version
= MPB_VERSION_ATTRIBS
;
4554 switch (get_imsm_raid_level(map
)) {
4555 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
4556 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
4557 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
4558 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
4561 if (map
->num_members
>= 5)
4562 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
4563 else if (dev
->status
== DEV_CLONE_N_GO
)
4564 version
= MPB_VERSION_CNG
;
4565 else if (get_imsm_raid_level(map
) == 5)
4566 version
= MPB_VERSION_RAID5
;
4567 else if (map
->num_members
>= 3)
4568 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
4569 else if (get_imsm_raid_level(map
) == 1)
4570 version
= MPB_VERSION_RAID1
;
4572 version
= MPB_VERSION_RAID0
;
4574 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
4578 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
4580 struct imsm_super
*mpb
= super
->anchor
;
4581 char *reason
= NULL
;
4584 if (strlen(name
) > MAX_RAID_SERIAL_LEN
)
4585 reason
= "must be 16 characters or less";
4587 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4588 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
4590 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
4591 reason
= "already exists";
4596 if (reason
&& !quiet
)
4597 pr_err("imsm volume name %s\n", reason
);
4602 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
4603 unsigned long long size
, char *name
,
4604 char *homehost
, int *uuid
,
4605 long long data_offset
)
4607 /* We are creating a volume inside a pre-existing container.
4608 * so st->sb is already set.
4610 struct intel_super
*super
= st
->sb
;
4611 struct imsm_super
*mpb
= super
->anchor
;
4612 struct intel_dev
*dv
;
4613 struct imsm_dev
*dev
;
4614 struct imsm_vol
*vol
;
4615 struct imsm_map
*map
;
4616 int idx
= mpb
->num_raid_devs
;
4618 unsigned long long array_blocks
;
4619 size_t size_old
, size_new
;
4620 unsigned long long num_data_stripes
;
4622 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
4623 pr_err("This imsm-container already has the "
4624 "maximum of %d volumes\n", super
->orom
->vpa
);
4628 /* ensure the mpb is large enough for the new data */
4629 size_old
= __le32_to_cpu(mpb
->mpb_size
);
4630 size_new
= disks_to_mpb_size(info
->nr_disks
);
4631 if (size_new
> size_old
) {
4633 size_t size_round
= ROUND_UP(size_new
, 512);
4635 if (posix_memalign(&mpb_new
, 512, size_round
) != 0) {
4636 pr_err("could not allocate new mpb\n");
4639 if (posix_memalign(&super
->migr_rec_buf
, 512,
4640 MIGR_REC_BUF_SIZE
) != 0) {
4641 pr_err("%s could not allocate migr_rec buffer\n",
4648 memcpy(mpb_new
, mpb
, size_old
);
4651 super
->anchor
= mpb_new
;
4652 mpb
->mpb_size
= __cpu_to_le32(size_new
);
4653 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
4655 super
->current_vol
= idx
;
4657 /* handle 'failed_disks' by either:
4658 * a) create dummy disk entries in the table if this the first
4659 * volume in the array. We add them here as this is the only
4660 * opportunity to add them. add_to_super_imsm_volume()
4661 * handles the non-failed disks and continues incrementing
4663 * b) validate that 'failed_disks' matches the current number
4664 * of missing disks if the container is populated
4666 if (super
->current_vol
== 0) {
4668 for (i
= 0; i
< info
->failed_disks
; i
++) {
4669 struct imsm_disk
*disk
;
4672 disk
= __get_imsm_disk(mpb
, i
);
4673 disk
->status
= CONFIGURED_DISK
| FAILED_DISK
;
4674 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
4675 snprintf((char *) disk
->serial
, MAX_RAID_SERIAL_LEN
,
4678 find_missing(super
);
4683 for (d
= super
->missing
; d
; d
= d
->next
)
4685 if (info
->failed_disks
> missing
) {
4686 pr_err("unable to add 'missing' disk to container\n");
4691 if (!check_name(super
, name
, 0))
4693 dv
= xmalloc(sizeof(*dv
));
4694 dev
= xcalloc(1, sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
4695 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
4696 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
4697 info
->layout
, info
->chunk_size
,
4699 /* round array size down to closest MB */
4700 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
4702 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
4703 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
4704 dev
->status
= (DEV_READ_COALESCING
| DEV_WRITE_COALESCING
);
4706 vol
->migr_state
= 0;
4707 set_migr_type(dev
, MIGR_INIT
);
4708 vol
->dirty
= !info
->state
;
4709 vol
->curr_migr_unit
= 0;
4710 map
= get_imsm_map(dev
, MAP_0
);
4711 set_pba_of_lba0(map
, super
->create_offset
);
4712 set_blocks_per_member(map
, info_to_blocks_per_member(info
, size
));
4713 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
4714 map
->failed_disk_num
= ~0;
4715 if (info
->level
> 0)
4716 map
->map_state
= (info
->state
? IMSM_T_STATE_NORMAL
4717 : IMSM_T_STATE_UNINITIALIZED
);
4719 map
->map_state
= info
->failed_disks
? IMSM_T_STATE_FAILED
:
4720 IMSM_T_STATE_NORMAL
;
4723 if (info
->level
== 1 && info
->raid_disks
> 2) {
4726 pr_err("imsm does not support more than 2 disks"
4727 "in a raid1 volume\n");
4731 map
->raid_level
= info
->level
;
4732 if (info
->level
== 10) {
4733 map
->raid_level
= 1;
4734 map
->num_domains
= info
->raid_disks
/ 2;
4735 } else if (info
->level
== 1)
4736 map
->num_domains
= info
->raid_disks
;
4738 map
->num_domains
= 1;
4740 /* info->size is only int so use the 'size' parameter instead */
4741 num_data_stripes
= (size
* 2) / info_to_blocks_per_strip(info
);
4742 num_data_stripes
/= map
->num_domains
;
4743 set_num_data_stripes(map
, num_data_stripes
);
4745 map
->num_members
= info
->raid_disks
;
4746 for (i
= 0; i
< map
->num_members
; i
++) {
4747 /* initialized in add_to_super */
4748 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
4750 mpb
->num_raid_devs
++;
4753 dv
->index
= super
->current_vol
;
4754 dv
->next
= super
->devlist
;
4755 super
->devlist
= dv
;
4757 imsm_update_version_info(super
);
4762 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
4763 unsigned long long size
, char *name
,
4764 char *homehost
, int *uuid
,
4765 unsigned long long data_offset
)
4767 /* This is primarily called by Create when creating a new array.
4768 * We will then get add_to_super called for each component, and then
4769 * write_init_super called to write it out to each device.
4770 * For IMSM, Create can create on fresh devices or on a pre-existing
4772 * To create on a pre-existing array a different method will be called.
4773 * This one is just for fresh drives.
4775 struct intel_super
*super
;
4776 struct imsm_super
*mpb
;
4780 if (data_offset
!= INVALID_SECTORS
) {
4781 pr_err("data-offset not supported by imsm\n");
4786 return init_super_imsm_volume(st
, info
, size
, name
, homehost
, uuid
,
4790 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
4794 super
= alloc_super();
4795 if (super
&& posix_memalign(&super
->buf
, 512, mpb_size
) != 0) {
4800 pr_err("%s could not allocate superblock\n", __func__
);
4803 if (posix_memalign(&super
->migr_rec_buf
, 512, MIGR_REC_BUF_SIZE
) != 0) {
4804 pr_err("%s could not allocate migr_rec buffer\n", __func__
);
4809 memset(super
->buf
, 0, mpb_size
);
4811 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
4815 /* zeroing superblock */
4819 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
4821 version
= (char *) mpb
->sig
;
4822 strcpy(version
, MPB_SIGNATURE
);
4823 version
+= strlen(MPB_SIGNATURE
);
4824 strcpy(version
, MPB_VERSION_RAID0
);
4830 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
4831 int fd
, char *devname
)
4833 struct intel_super
*super
= st
->sb
;
4834 struct imsm_super
*mpb
= super
->anchor
;
4835 struct imsm_disk
*_disk
;
4836 struct imsm_dev
*dev
;
4837 struct imsm_map
*map
;
4841 dev
= get_imsm_dev(super
, super
->current_vol
);
4842 map
= get_imsm_map(dev
, MAP_0
);
4844 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
4845 pr_err("%s: Cannot add spare devices to IMSM volume\n",
4851 /* we're doing autolayout so grab the pre-marked (in
4852 * validate_geometry) raid_disk
4854 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4855 if (dl
->raiddisk
== dk
->raid_disk
)
4858 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4859 if (dl
->major
== dk
->major
&&
4860 dl
->minor
== dk
->minor
)
4865 pr_err("%s is not a member of the same container\n", devname
);
4869 /* add a pristine spare to the metadata */
4870 if (dl
->index
< 0) {
4871 dl
->index
= super
->anchor
->num_disks
;
4872 super
->anchor
->num_disks
++;
4874 /* Check the device has not already been added */
4875 slot
= get_imsm_disk_slot(map
, dl
->index
);
4877 (get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
) & IMSM_ORD_REBUILD
) == 0) {
4878 pr_err("%s has been included in this array twice\n",
4882 set_imsm_ord_tbl_ent(map
, dk
->raid_disk
, dl
->index
);
4883 dl
->disk
.status
= CONFIGURED_DISK
;
4885 /* update size of 'missing' disks to be at least as large as the
4886 * largest acitve member (we only have dummy missing disks when
4887 * creating the first volume)
4889 if (super
->current_vol
== 0) {
4890 for (df
= super
->missing
; df
; df
= df
->next
) {
4891 if (total_blocks(&dl
->disk
) > total_blocks(&df
->disk
))
4892 set_total_blocks(&df
->disk
, total_blocks(&dl
->disk
));
4893 _disk
= __get_imsm_disk(mpb
, df
->index
);
4898 /* refresh unset/failed slots to point to valid 'missing' entries */
4899 for (df
= super
->missing
; df
; df
= df
->next
)
4900 for (slot
= 0; slot
< mpb
->num_disks
; slot
++) {
4901 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
4903 if ((ord
& IMSM_ORD_REBUILD
) == 0)
4905 set_imsm_ord_tbl_ent(map
, slot
, df
->index
| IMSM_ORD_REBUILD
);
4906 if (is_gen_migration(dev
)) {
4907 struct imsm_map
*map2
= get_imsm_map(dev
,
4909 int slot2
= get_imsm_disk_slot(map2
, df
->index
);
4910 if ((slot2
< map2
->num_members
) &&
4912 __u32 ord2
= get_imsm_ord_tbl_ent(dev
,
4915 if ((unsigned)df
->index
==
4917 set_imsm_ord_tbl_ent(map2
,
4923 dprintf("set slot:%d to missing disk:%d\n", slot
, df
->index
);
4927 /* if we are creating the first raid device update the family number */
4928 if (super
->current_vol
== 0) {
4930 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
4932 _disk
= __get_imsm_disk(mpb
, dl
->index
);
4933 if (!_dev
|| !_disk
) {
4934 pr_err("BUG mpb setup error\n");
4940 sum
+= __gen_imsm_checksum(mpb
);
4941 mpb
->family_num
= __cpu_to_le32(sum
);
4942 mpb
->orig_family_num
= mpb
->family_num
;
4944 super
->current_disk
= dl
;
4949 * Function marks disk as spare and restores disk serial
4950 * in case it was previously marked as failed by takeover operation
4952 * -1 : critical error
4953 * 0 : disk is marked as spare but serial is not set
4956 int mark_spare(struct dl
*disk
)
4958 __u8 serial
[MAX_RAID_SERIAL_LEN
];
4965 if (!imsm_read_serial(disk
->fd
, NULL
, serial
)) {
4966 /* Restore disk serial number, because takeover marks disk
4967 * as failed and adds to serial ':0' before it becomes
4970 serialcpy(disk
->serial
, serial
);
4971 serialcpy(disk
->disk
.serial
, serial
);
4974 disk
->disk
.status
= SPARE_DISK
;
4980 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
4981 int fd
, char *devname
,
4982 unsigned long long data_offset
)
4984 struct intel_super
*super
= st
->sb
;
4986 unsigned long long size
;
4991 /* If we are on an RAID enabled platform check that the disk is
4992 * attached to the raid controller.
4993 * We do not need to test disks attachment for container based additions,
4994 * they shall be already tested when container was created/assembled.
4996 rv
= find_intel_hba_capability(fd
, super
, devname
);
4997 /* no orom/efi or non-intel hba of the disk */
4999 dprintf("capability: %p fd: %d ret: %d\n",
5000 super
->orom
, fd
, rv
);
5004 if (super
->current_vol
>= 0)
5005 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
5008 dd
= xcalloc(sizeof(*dd
), 1);
5009 dd
->major
= major(stb
.st_rdev
);
5010 dd
->minor
= minor(stb
.st_rdev
);
5011 dd
->devname
= devname
? xstrdup(devname
) : NULL
;
5014 dd
->action
= DISK_ADD
;
5015 rv
= imsm_read_serial(fd
, devname
, dd
->serial
);
5017 pr_err("failed to retrieve scsi serial, aborting\n");
5022 get_dev_size(fd
, NULL
, &size
);
5024 serialcpy(dd
->disk
.serial
, dd
->serial
);
5025 set_total_blocks(&dd
->disk
, size
);
5026 if (__le32_to_cpu(dd
->disk
.total_blocks_hi
) > 0) {
5027 struct imsm_super
*mpb
= super
->anchor
;
5028 mpb
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5031 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
5032 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
5034 dd
->disk
.scsi_id
= __cpu_to_le32(0);
5036 if (st
->update_tail
) {
5037 dd
->next
= super
->disk_mgmt_list
;
5038 super
->disk_mgmt_list
= dd
;
5040 dd
->next
= super
->disks
;
5042 super
->updates_pending
++;
5048 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
5050 struct intel_super
*super
= st
->sb
;
5053 /* remove from super works only in mdmon - for communication
5054 * manager - monitor. Check if communication memory buffer
5057 if (!st
->update_tail
) {
5058 pr_err("%s shall be used in mdmon context only"
5059 "(line %d).\n", __func__
, __LINE__
);
5062 dd
= xcalloc(1, sizeof(*dd
));
5063 dd
->major
= dk
->major
;
5064 dd
->minor
= dk
->minor
;
5067 dd
->action
= DISK_REMOVE
;
5069 dd
->next
= super
->disk_mgmt_list
;
5070 super
->disk_mgmt_list
= dd
;
5075 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
5079 struct imsm_super anchor
;
5080 } spare_record
__attribute__ ((aligned(512)));
5082 /* spare records have their own family number and do not have any defined raid
5085 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
5087 struct imsm_super
*mpb
= super
->anchor
;
5088 struct imsm_super
*spare
= &spare_record
.anchor
;
5092 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
)),
5093 spare
->generation_num
= __cpu_to_le32(1UL),
5094 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5095 spare
->num_disks
= 1,
5096 spare
->num_raid_devs
= 0,
5097 spare
->cache_size
= mpb
->cache_size
,
5098 spare
->pwr_cycle_count
= __cpu_to_le32(1),
5100 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
5101 MPB_SIGNATURE MPB_VERSION_RAID0
);
5103 for (d
= super
->disks
; d
; d
= d
->next
) {
5107 spare
->disk
[0] = d
->disk
;
5108 if (__le32_to_cpu(d
->disk
.total_blocks_hi
) > 0)
5109 spare
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5111 sum
= __gen_imsm_checksum(spare
);
5112 spare
->family_num
= __cpu_to_le32(sum
);
5113 spare
->orig_family_num
= 0;
5114 sum
= __gen_imsm_checksum(spare
);
5115 spare
->check_sum
= __cpu_to_le32(sum
);
5117 if (store_imsm_mpb(d
->fd
, spare
)) {
5118 pr_err("%s: failed for device %d:%d %s\n",
5119 __func__
, d
->major
, d
->minor
, strerror(errno
));
5131 static int write_super_imsm(struct supertype
*st
, int doclose
)
5133 struct intel_super
*super
= st
->sb
;
5134 struct imsm_super
*mpb
= super
->anchor
;
5140 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
5142 int clear_migration_record
= 1;
5144 /* 'generation' is incremented everytime the metadata is written */
5145 generation
= __le32_to_cpu(mpb
->generation_num
);
5147 mpb
->generation_num
= __cpu_to_le32(generation
);
5149 /* fix up cases where previous mdadm releases failed to set
5152 if (mpb
->orig_family_num
== 0)
5153 mpb
->orig_family_num
= mpb
->family_num
;
5155 for (d
= super
->disks
; d
; d
= d
->next
) {
5159 mpb
->disk
[d
->index
] = d
->disk
;
5163 for (d
= super
->missing
; d
; d
= d
->next
) {
5164 mpb
->disk
[d
->index
] = d
->disk
;
5167 mpb
->num_disks
= num_disks
;
5168 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
5170 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5171 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
5172 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
5174 imsm_copy_dev(dev
, dev2
);
5175 mpb_size
+= sizeof_imsm_dev(dev
, 0);
5177 if (is_gen_migration(dev2
))
5178 clear_migration_record
= 0;
5180 mpb_size
+= __le32_to_cpu(mpb
->bbm_log_size
);
5181 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5183 /* recalculate checksum */
5184 sum
= __gen_imsm_checksum(mpb
);
5185 mpb
->check_sum
= __cpu_to_le32(sum
);
5187 if (super
->clean_migration_record_by_mdmon
) {
5188 clear_migration_record
= 1;
5189 super
->clean_migration_record_by_mdmon
= 0;
5191 if (clear_migration_record
)
5192 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SIZE
);
5194 /* write the mpb for disks that compose raid devices */
5195 for (d
= super
->disks
; d
; d
= d
->next
) {
5196 if (d
->index
< 0 || is_failed(&d
->disk
))
5199 if (clear_migration_record
) {
5200 unsigned long long dsize
;
5202 get_dev_size(d
->fd
, NULL
, &dsize
);
5203 if (lseek64(d
->fd
, dsize
- 512, SEEK_SET
) >= 0) {
5204 if (write(d
->fd
, super
->migr_rec_buf
,
5205 MIGR_REC_BUF_SIZE
) != MIGR_REC_BUF_SIZE
)
5206 perror("Write migr_rec failed");
5210 if (store_imsm_mpb(d
->fd
, mpb
))
5212 "%s: failed for device %d:%d (fd: %d)%s\n",
5213 __func__
, d
->major
, d
->minor
,
5214 d
->fd
, strerror(errno
));
5223 return write_super_imsm_spares(super
, doclose
);
5228 static int create_array(struct supertype
*st
, int dev_idx
)
5231 struct imsm_update_create_array
*u
;
5232 struct intel_super
*super
= st
->sb
;
5233 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
5234 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
5235 struct disk_info
*inf
;
5236 struct imsm_disk
*disk
;
5239 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
5240 sizeof(*inf
) * map
->num_members
;
5242 u
->type
= update_create_array
;
5243 u
->dev_idx
= dev_idx
;
5244 imsm_copy_dev(&u
->dev
, dev
);
5245 inf
= get_disk_info(u
);
5246 for (i
= 0; i
< map
->num_members
; i
++) {
5247 int idx
= get_imsm_disk_idx(dev
, i
, MAP_X
);
5249 disk
= get_imsm_disk(super
, idx
);
5251 disk
= get_imsm_missing(super
, idx
);
5252 serialcpy(inf
[i
].serial
, disk
->serial
);
5254 append_metadata_update(st
, u
, len
);
5259 static int mgmt_disk(struct supertype
*st
)
5261 struct intel_super
*super
= st
->sb
;
5263 struct imsm_update_add_remove_disk
*u
;
5265 if (!super
->disk_mgmt_list
)
5270 u
->type
= update_add_remove_disk
;
5271 append_metadata_update(st
, u
, len
);
5276 static int write_init_super_imsm(struct supertype
*st
)
5278 struct intel_super
*super
= st
->sb
;
5279 int current_vol
= super
->current_vol
;
5281 /* we are done with current_vol reset it to point st at the container */
5282 super
->current_vol
= -1;
5284 if (st
->update_tail
) {
5285 /* queue the recently created array / added disk
5286 * as a metadata update */
5289 /* determine if we are creating a volume or adding a disk */
5290 if (current_vol
< 0) {
5291 /* in the mgmt (add/remove) disk case we are running
5292 * in mdmon context, so don't close fd's
5294 return mgmt_disk(st
);
5296 rv
= create_array(st
, current_vol
);
5301 for (d
= super
->disks
; d
; d
= d
->next
)
5302 Kill(d
->devname
, NULL
, 0, -1, 1);
5303 return write_super_imsm(st
, 1);
5308 static int store_super_imsm(struct supertype
*st
, int fd
)
5310 struct intel_super
*super
= st
->sb
;
5311 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
5317 return store_imsm_mpb(fd
, mpb
);
5323 static int imsm_bbm_log_size(struct imsm_super
*mpb
)
5325 return __le32_to_cpu(mpb
->bbm_log_size
);
5329 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
5330 int layout
, int raiddisks
, int chunk
,
5331 unsigned long long size
,
5332 unsigned long long data_offset
,
5334 unsigned long long *freesize
,
5338 unsigned long long ldsize
;
5339 struct intel_super
*super
=NULL
;
5342 if (level
!= LEVEL_CONTAINER
)
5347 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
5350 pr_err("imsm: Cannot open %s: %s\n",
5351 dev
, strerror(errno
));
5354 if (!get_dev_size(fd
, dev
, &ldsize
)) {
5359 /* capabilities retrieve could be possible
5360 * note that there is no fd for the disks in array.
5362 super
= alloc_super();
5363 rv
= find_intel_hba_capability(fd
, super
, verbose
> 0 ? dev
: NULL
);
5367 fd2devname(fd
, str
);
5368 dprintf("validate_geometry_imsm_container: fd: %d %s orom: %p rv: %d raiddisk: %d\n",
5369 fd
, str
, super
->orom
, rv
, raiddisks
);
5371 /* no orom/efi or non-intel hba of the disk */
5378 if (raiddisks
> super
->orom
->tds
) {
5380 pr_err("%d exceeds maximum number of"
5381 " platform supported disks: %d\n",
5382 raiddisks
, super
->orom
->tds
);
5386 if ((super
->orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) == 0 &&
5387 (ldsize
>> 9) >> 32 > 0) {
5389 pr_err("%s exceeds maximum platform supported size\n", dev
);
5395 *freesize
= avail_size_imsm(st
, ldsize
>> 9, data_offset
);
5401 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
5403 const unsigned long long base_start
= e
[*idx
].start
;
5404 unsigned long long end
= base_start
+ e
[*idx
].size
;
5407 if (base_start
== end
)
5411 for (i
= *idx
; i
< num_extents
; i
++) {
5412 /* extend overlapping extents */
5413 if (e
[i
].start
>= base_start
&&
5414 e
[i
].start
<= end
) {
5417 if (e
[i
].start
+ e
[i
].size
> end
)
5418 end
= e
[i
].start
+ e
[i
].size
;
5419 } else if (e
[i
].start
> end
) {
5425 return end
- base_start
;
5428 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
5430 /* build a composite disk with all known extents and generate a new
5431 * 'maxsize' given the "all disks in an array must share a common start
5432 * offset" constraint
5434 struct extent
*e
= xcalloc(sum_extents
, sizeof(*e
));
5438 unsigned long long pos
;
5439 unsigned long long start
= 0;
5440 unsigned long long maxsize
;
5441 unsigned long reserve
;
5443 /* coalesce and sort all extents. also, check to see if we need to
5444 * reserve space between member arrays
5447 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5450 for (i
= 0; i
< dl
->extent_cnt
; i
++)
5453 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
5458 while (i
< sum_extents
) {
5459 e
[j
].start
= e
[i
].start
;
5460 e
[j
].size
= find_size(e
, &i
, sum_extents
);
5462 if (e
[j
-1].size
== 0)
5471 unsigned long long esize
;
5473 esize
= e
[i
].start
- pos
;
5474 if (esize
>= maxsize
) {
5479 pos
= e
[i
].start
+ e
[i
].size
;
5481 } while (e
[i
-1].size
);
5487 /* FIXME assumes volume at offset 0 is the first volume in a
5490 if (start_extent
> 0)
5491 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
5495 if (maxsize
< reserve
)
5498 super
->create_offset
= ~((unsigned long long) 0);
5499 if (start
+ reserve
> super
->create_offset
)
5500 return 0; /* start overflows create_offset */
5501 super
->create_offset
= start
+ reserve
;
5503 return maxsize
- reserve
;
5506 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
5508 if (level
< 0 || level
== 6 || level
== 4)
5511 /* if we have an orom prevent invalid raid levels */
5514 case 0: return imsm_orom_has_raid0(orom
);
5517 return imsm_orom_has_raid1e(orom
);
5518 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
5519 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
5520 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
5523 return 1; /* not on an Intel RAID platform so anything goes */
5529 active_arrays_by_format(char *name
, char* hba
, struct md_list
**devlist
,
5530 int dpa
, int verbose
)
5532 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
5533 struct mdstat_ent
*memb
= NULL
;
5536 struct md_list
*dv
= NULL
;
5539 for (memb
= mdstat
; memb
; memb
= memb
->next
) {
5540 if (memb
->metadata_version
&&
5541 (strncmp(memb
->metadata_version
, "external:", 9) == 0) &&
5542 (strcmp(&memb
->metadata_version
[9], name
) == 0) &&
5543 !is_subarray(memb
->metadata_version
+9) &&
5545 struct dev_member
*dev
= memb
->members
;
5547 while(dev
&& (fd
< 0)) {
5548 char *path
= xmalloc(strlen(dev
->name
) + strlen("/dev/") + 1);
5549 num
= sprintf(path
, "%s%s", "/dev/", dev
->name
);
5551 fd
= open(path
, O_RDONLY
, 0);
5552 if ((num
<= 0) || (fd
< 0)) {
5553 pr_vrb(": Cannot open %s: %s\n",
5554 dev
->name
, strerror(errno
));
5560 if ((fd
>= 0) && disk_attached_to_hba(fd
, hba
)) {
5561 struct mdstat_ent
*vol
;
5562 for (vol
= mdstat
; vol
; vol
= vol
->next
) {
5563 if ((vol
->active
> 0) &&
5564 vol
->metadata_version
&&
5565 is_container_member(vol
, memb
->dev
)) {
5570 if (*devlist
&& (found
< dpa
)) {
5571 dv
= xcalloc(1, sizeof(*dv
));
5572 dv
->devname
= xmalloc(strlen(memb
->dev
) + strlen("/dev/") + 1);
5573 sprintf(dv
->devname
, "%s%s", "/dev/", memb
->dev
);
5576 dv
->next
= *devlist
;
5584 free_mdstat(mdstat
);
5589 static struct md_list
*
5590 get_loop_devices(void)
5593 struct md_list
*devlist
= NULL
;
5594 struct md_list
*dv
= NULL
;
5596 for(i
= 0; i
< 12; i
++) {
5597 dv
= xcalloc(1, sizeof(*dv
));
5598 dv
->devname
= xmalloc(40);
5599 sprintf(dv
->devname
, "/dev/loop%d", i
);
5607 static struct md_list
*
5608 get_devices(const char *hba_path
)
5610 struct md_list
*devlist
= NULL
;
5611 struct md_list
*dv
= NULL
;
5617 devlist
= get_loop_devices();
5620 /* scroll through /sys/dev/block looking for devices attached to
5623 dir
= opendir("/sys/dev/block");
5624 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
5629 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
5631 path
= devt_to_devpath(makedev(major
, minor
));
5634 if (!path_attached_to_hba(path
, hba_path
)) {
5641 fd
= dev_open(ent
->d_name
, O_RDONLY
);
5643 fd2devname(fd
, buf
);
5646 pr_err("cannot open device: %s\n",
5651 dv
= xcalloc(1, sizeof(*dv
));
5652 dv
->devname
= xstrdup(buf
);
5659 devlist
= devlist
->next
;
5669 count_volumes_list(struct md_list
*devlist
, char *homehost
,
5670 int verbose
, int *found
)
5672 struct md_list
*tmpdev
;
5674 struct supertype
*st
= NULL
;
5676 /* first walk the list of devices to find a consistent set
5677 * that match the criterea, if that is possible.
5678 * We flag the ones we like with 'used'.
5681 st
= match_metadata_desc_imsm("imsm");
5683 pr_vrb(": cannot allocate memory for imsm supertype\n");
5687 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
5688 char *devname
= tmpdev
->devname
;
5690 struct supertype
*tst
;
5692 if (tmpdev
->used
> 1)
5694 tst
= dup_super(st
);
5696 pr_vrb(": cannot allocate memory for imsm supertype\n");
5699 tmpdev
->container
= 0;
5700 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
5702 dprintf(": cannot open device %s: %s\n",
5703 devname
, strerror(errno
));
5705 } else if (fstat(dfd
, &stb
)< 0) {
5707 dprintf(": fstat failed for %s: %s\n",
5708 devname
, strerror(errno
));
5710 } else if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
5711 dprintf(": %s is not a block device.\n",
5714 } else if (must_be_container(dfd
)) {
5715 struct supertype
*cst
;
5716 cst
= super_by_fd(dfd
, NULL
);
5718 dprintf(": cannot recognize container type %s\n",
5721 } else if (tst
->ss
!= st
->ss
) {
5722 dprintf(": non-imsm container - ignore it: %s\n",
5725 } else if (!tst
->ss
->load_container
||
5726 tst
->ss
->load_container(tst
, dfd
, NULL
))
5729 tmpdev
->container
= 1;
5732 cst
->ss
->free_super(cst
);
5734 tmpdev
->st_rdev
= stb
.st_rdev
;
5735 if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
5736 dprintf(": no RAID superblock on %s\n",
5739 } else if (tst
->ss
->compare_super
== NULL
) {
5740 dprintf(": Cannot assemble %s metadata on %s\n",
5741 tst
->ss
->name
, devname
);
5747 if (tmpdev
->used
== 2 || tmpdev
->used
== 4) {
5748 /* Ignore unrecognised devices during auto-assembly */
5753 tst
->ss
->getinfo_super(tst
, &info
, NULL
);
5755 if (st
->minor_version
== -1)
5756 st
->minor_version
= tst
->minor_version
;
5758 if (memcmp(info
.uuid
, uuid_zero
,
5759 sizeof(int[4])) == 0) {
5760 /* this is a floating spare. It cannot define
5761 * an array unless there are no more arrays of
5762 * this type to be found. It can be included
5763 * in an array of this type though.
5769 if (st
->ss
!= tst
->ss
||
5770 st
->minor_version
!= tst
->minor_version
||
5771 st
->ss
->compare_super(st
, tst
) != 0) {
5772 /* Some mismatch. If exactly one array matches this host,
5773 * we can resolve on that one.
5774 * Or, if we are auto assembling, we just ignore the second
5777 dprintf(": superblock on %s doesn't match others - assembly aborted\n",
5783 dprintf("found: devname: %s\n", devname
);
5787 tst
->ss
->free_super(tst
);
5791 if ((err
= load_super_imsm_all(st
, -1, &st
->sb
, NULL
, devlist
, 0)) == 0) {
5792 struct mdinfo
*iter
, *head
= st
->ss
->container_content(st
, NULL
);
5793 for (iter
= head
; iter
; iter
= iter
->next
) {
5794 dprintf("content->text_version: %s vol\n",
5795 iter
->text_version
);
5796 if (iter
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
)) {
5797 /* do not assemble arrays with unsupported
5799 dprintf(": Cannot activate member %s.\n",
5800 iter
->text_version
);
5807 dprintf(" no valid super block on device list: err: %d %p\n",
5811 dprintf(" no more devices to examin\n");
5814 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
5815 if ((tmpdev
->used
== 1) && (tmpdev
->found
)) {
5817 if (count
< tmpdev
->found
)
5820 count
-= tmpdev
->found
;
5823 if (tmpdev
->used
== 1)
5828 st
->ss
->free_super(st
);
5833 count_volumes(char *hba
, int dpa
, int verbose
)
5835 struct md_list
*devlist
= NULL
;
5839 devlist
= get_devices(hba
);
5840 /* if no intel devices return zero volumes */
5841 if (devlist
== NULL
)
5844 count
= active_arrays_by_format("imsm", hba
, &devlist
, dpa
, verbose
);
5845 dprintf(" path: %s active arrays: %d\n", hba
, count
);
5846 if (devlist
== NULL
)
5850 count
+= count_volumes_list(devlist
,
5854 dprintf("found %d count: %d\n", found
, count
);
5857 dprintf("path: %s total number of volumes: %d\n", hba
, count
);
5860 struct md_list
*dv
= devlist
;
5861 devlist
= devlist
->next
;
5868 static int imsm_default_chunk(const struct imsm_orom
*orom
)
5870 /* up to 512 if the plaform supports it, otherwise the platform max.
5871 * 128 if no platform detected
5873 int fs
= max(7, orom
? fls(orom
->sss
) : 0);
5875 return min(512, (1 << fs
));
5879 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
5880 int raiddisks
, int *chunk
, unsigned long long size
, int verbose
)
5882 /* check/set platform and metadata limits/defaults */
5883 if (super
->orom
&& raiddisks
> super
->orom
->dpa
) {
5884 pr_vrb(": platform supports a maximum of %d disks per array\n",
5889 /* capabilities of OROM tested - copied from validate_geometry_imsm_volume */
5890 if (!is_raid_level_supported(super
->orom
, level
, raiddisks
)) {
5891 pr_vrb(": platform does not support raid%d with %d disk%s\n",
5892 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
5896 if (*chunk
== 0 || *chunk
== UnSet
)
5897 *chunk
= imsm_default_chunk(super
->orom
);
5899 if (super
->orom
&& !imsm_orom_has_chunk(super
->orom
, *chunk
)) {
5900 pr_vrb(": platform does not support a chunk size of: "
5905 if (layout
!= imsm_level_to_layout(level
)) {
5907 pr_vrb(": imsm raid 5 only supports the left-asymmetric layout\n");
5908 else if (level
== 10)
5909 pr_vrb(": imsm raid 10 only supports the n2 layout\n");
5911 pr_vrb(": imsm unknown layout %#x for this raid level %d\n",
5916 if (super
->orom
&& (super
->orom
->attr
& IMSM_OROM_ATTR_2TB
) == 0 &&
5917 (calc_array_size(level
, raiddisks
, layout
, *chunk
, size
) >> 32) > 0) {
5918 pr_vrb(": platform does not support a volume size over 2TB\n");
5925 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
5926 * FIX ME add ahci details
5928 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
5929 int layout
, int raiddisks
, int *chunk
,
5930 unsigned long long size
,
5931 unsigned long long data_offset
,
5933 unsigned long long *freesize
,
5937 struct intel_super
*super
= st
->sb
;
5938 struct imsm_super
*mpb
;
5940 unsigned long long pos
= 0;
5941 unsigned long long maxsize
;
5945 /* We must have the container info already read in. */
5949 mpb
= super
->anchor
;
5951 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, size
, verbose
)) {
5952 pr_err("RAID gemetry validation failed. "
5953 "Cannot proceed with the action(s).\n");
5957 /* General test: make sure there is space for
5958 * 'raiddisks' device extents of size 'size' at a given
5961 unsigned long long minsize
= size
;
5962 unsigned long long start_offset
= MaxSector
;
5965 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
5966 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5971 e
= get_extents(super
, dl
);
5974 unsigned long long esize
;
5975 esize
= e
[i
].start
- pos
;
5976 if (esize
>= minsize
)
5978 if (found
&& start_offset
== MaxSector
) {
5981 } else if (found
&& pos
!= start_offset
) {
5985 pos
= e
[i
].start
+ e
[i
].size
;
5987 } while (e
[i
-1].size
);
5992 if (dcnt
< raiddisks
) {
5994 pr_err("imsm: Not enough "
5995 "devices with space for this array "
6003 /* This device must be a member of the set */
6004 if (stat(dev
, &stb
) < 0)
6006 if ((S_IFMT
& stb
.st_mode
) != S_IFBLK
)
6008 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6009 if (dl
->major
== (int)major(stb
.st_rdev
) &&
6010 dl
->minor
== (int)minor(stb
.st_rdev
))
6015 pr_err("%s is not in the "
6016 "same imsm set\n", dev
);
6018 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
6019 /* If a volume is present then the current creation attempt
6020 * cannot incorporate new spares because the orom may not
6021 * understand this configuration (all member disks must be
6022 * members of each array in the container).
6024 pr_err("%s is a spare and a volume"
6025 " is already defined for this container\n", dev
);
6026 pr_err("The option-rom requires all member"
6027 " disks to be a member of all volumes\n");
6029 } else if (super
->orom
&& mpb
->num_raid_devs
> 0 &&
6030 mpb
->num_disks
!= raiddisks
) {
6031 pr_err("The option-rom requires all member"
6032 " disks to be a member of all volumes\n");
6036 /* retrieve the largest free space block */
6037 e
= get_extents(super
, dl
);
6042 unsigned long long esize
;
6044 esize
= e
[i
].start
- pos
;
6045 if (esize
>= maxsize
)
6047 pos
= e
[i
].start
+ e
[i
].size
;
6049 } while (e
[i
-1].size
);
6054 pr_err("unable to determine free space for: %s\n",
6058 if (maxsize
< size
) {
6060 pr_err("%s not enough space (%llu < %llu)\n",
6061 dev
, maxsize
, size
);
6065 /* count total number of extents for merge */
6067 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6069 i
+= dl
->extent_cnt
;
6071 maxsize
= merge_extents(super
, i
);
6073 if (!check_env("IMSM_NO_PLATFORM") &&
6074 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
6075 pr_err("attempting to create a second "
6076 "volume with size less then remaining space. "
6081 if (maxsize
< size
|| maxsize
== 0) {
6084 pr_err("no free space"
6085 " left on device. Aborting...\n");
6087 pr_err("not enough space"
6088 " to create volume of given size"
6089 " (%llu < %llu). Aborting...\n",
6095 *freesize
= maxsize
;
6098 int count
= count_volumes(super
->hba
->path
,
6099 super
->orom
->dpa
, verbose
);
6100 if (super
->orom
->vphba
<= count
) {
6101 pr_vrb(": platform does not support more than %d raid volumes.\n",
6102 super
->orom
->vphba
);
6109 static int imsm_get_free_size(struct supertype
*st
, int raiddisks
,
6110 unsigned long long size
, int chunk
,
6111 unsigned long long *freesize
)
6113 struct intel_super
*super
= st
->sb
;
6114 struct imsm_super
*mpb
= super
->anchor
;
6119 unsigned long long maxsize
;
6120 unsigned long long minsize
;
6124 /* find the largest common start free region of the possible disks */
6128 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6134 /* don't activate new spares if we are orom constrained
6135 * and there is already a volume active in the container
6137 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
6140 e
= get_extents(super
, dl
);
6143 for (i
= 1; e
[i
-1].size
; i
++)
6151 maxsize
= merge_extents(super
, extent_cnt
);
6155 minsize
= chunk
* 2;
6157 if (cnt
< raiddisks
||
6158 (super
->orom
&& used
&& used
!= raiddisks
) ||
6159 maxsize
< minsize
||
6161 pr_err("not enough devices with space to create array.\n");
6162 return 0; /* No enough free spaces large enough */
6173 if (!check_env("IMSM_NO_PLATFORM") &&
6174 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
6175 pr_err("attempting to create a second "
6176 "volume with size less then remaining space. "
6181 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6183 dl
->raiddisk
= cnt
++;
6187 dprintf("imsm: imsm_get_free_size() returns : %llu\n", size
);
6192 static int reserve_space(struct supertype
*st
, int raiddisks
,
6193 unsigned long long size
, int chunk
,
6194 unsigned long long *freesize
)
6196 struct intel_super
*super
= st
->sb
;
6201 rv
= imsm_get_free_size(st
, raiddisks
, size
, chunk
, freesize
);
6204 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6206 dl
->raiddisk
= cnt
++;
6213 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
6214 int raiddisks
, int *chunk
, unsigned long long size
,
6215 unsigned long long data_offset
,
6216 char *dev
, unsigned long long *freesize
,
6224 * if given unused devices create a container
6225 * if given given devices in a container create a member volume
6227 if (level
== LEVEL_CONTAINER
) {
6228 /* Must be a fresh device to add to a container */
6229 return validate_geometry_imsm_container(st
, level
, layout
,
6239 struct intel_super
*super
= st
->sb
;
6240 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
6241 raiddisks
, chunk
, size
,
6244 /* we are being asked to automatically layout a
6245 * new volume based on the current contents of
6246 * the container. If the the parameters can be
6247 * satisfied reserve_space will record the disks,
6248 * start offset, and size of the volume to be
6249 * created. add_to_super and getinfo_super
6250 * detect when autolayout is in progress.
6252 /* assuming that freesize is always given when array is
6254 if (super
->orom
&& freesize
) {
6256 count
= count_volumes(super
->hba
->path
,
6257 super
->orom
->dpa
, verbose
);
6258 if (super
->orom
->vphba
<= count
) {
6259 pr_vrb(": platform does not support more"
6260 " than %d raid volumes.\n",
6261 super
->orom
->vphba
);
6266 return reserve_space(st
, raiddisks
, size
,
6272 /* creating in a given container */
6273 return validate_geometry_imsm_volume(st
, level
, layout
,
6274 raiddisks
, chunk
, size
,
6276 dev
, freesize
, verbose
);
6279 /* This device needs to be a device in an 'imsm' container */
6280 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
6283 pr_err("Cannot create this array on device %s\n",
6288 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
6290 pr_err("Cannot open %s: %s\n",
6291 dev
, strerror(errno
));
6294 /* Well, it is in use by someone, maybe an 'imsm' container. */
6295 cfd
= open_container(fd
);
6299 pr_err("Cannot use %s: It is busy\n",
6303 sra
= sysfs_read(cfd
, NULL
, GET_VERSION
);
6304 if (sra
&& sra
->array
.major_version
== -1 &&
6305 strcmp(sra
->text_version
, "imsm") == 0)
6309 /* This is a member of a imsm container. Load the container
6310 * and try to create a volume
6312 struct intel_super
*super
;
6314 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
, NULL
, 1) == 0) {
6316 strcpy(st
->container_devnm
, fd2devnm(cfd
));
6318 return validate_geometry_imsm_volume(st
, level
, layout
,
6320 size
, data_offset
, dev
,
6327 pr_err("failed container membership check\n");
6333 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
6335 struct intel_super
*super
= st
->sb
;
6337 if (level
&& *level
== UnSet
)
6338 *level
= LEVEL_CONTAINER
;
6340 if (level
&& layout
&& *layout
== UnSet
)
6341 *layout
= imsm_level_to_layout(*level
);
6343 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0))
6344 *chunk
= imsm_default_chunk(super
->orom
);
6347 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
6349 static int kill_subarray_imsm(struct supertype
*st
)
6351 /* remove the subarray currently referenced by ->current_vol */
6353 struct intel_dev
**dp
;
6354 struct intel_super
*super
= st
->sb
;
6355 __u8 current_vol
= super
->current_vol
;
6356 struct imsm_super
*mpb
= super
->anchor
;
6358 if (super
->current_vol
< 0)
6360 super
->current_vol
= -1; /* invalidate subarray cursor */
6362 /* block deletions that would change the uuid of active subarrays
6364 * FIXME when immutable ids are available, but note that we'll
6365 * also need to fixup the invalidated/active subarray indexes in
6368 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6371 if (i
< current_vol
)
6373 sprintf(subarray
, "%u", i
);
6374 if (is_subarray_active(subarray
, st
->devnm
)) {
6375 pr_err("deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
6382 if (st
->update_tail
) {
6383 struct imsm_update_kill_array
*u
= xmalloc(sizeof(*u
));
6385 u
->type
= update_kill_array
;
6386 u
->dev_idx
= current_vol
;
6387 append_metadata_update(st
, u
, sizeof(*u
));
6392 for (dp
= &super
->devlist
; *dp
;)
6393 if ((*dp
)->index
== current_vol
) {
6396 handle_missing(super
, (*dp
)->dev
);
6397 if ((*dp
)->index
> current_vol
)
6402 /* no more raid devices, all active components are now spares,
6403 * but of course failed are still failed
6405 if (--mpb
->num_raid_devs
== 0) {
6408 for (d
= super
->disks
; d
; d
= d
->next
)
6413 super
->updates_pending
++;
6418 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
6419 char *update
, struct mddev_ident
*ident
)
6421 /* update the subarray currently referenced by ->current_vol */
6422 struct intel_super
*super
= st
->sb
;
6423 struct imsm_super
*mpb
= super
->anchor
;
6425 if (strcmp(update
, "name") == 0) {
6426 char *name
= ident
->name
;
6430 if (is_subarray_active(subarray
, st
->devnm
)) {
6431 pr_err("Unable to update name of active subarray\n");
6435 if (!check_name(super
, name
, 0))
6438 vol
= strtoul(subarray
, &ep
, 10);
6439 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
6442 if (st
->update_tail
) {
6443 struct imsm_update_rename_array
*u
= xmalloc(sizeof(*u
));
6445 u
->type
= update_rename_array
;
6447 snprintf((char *) u
->name
, MAX_RAID_SERIAL_LEN
, "%s", name
);
6448 append_metadata_update(st
, u
, sizeof(*u
));
6450 struct imsm_dev
*dev
;
6453 dev
= get_imsm_dev(super
, vol
);
6454 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
6455 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6456 dev
= get_imsm_dev(super
, i
);
6457 handle_missing(super
, dev
);
6459 super
->updates_pending
++;
6466 #endif /* MDASSEMBLE */
6468 static int is_gen_migration(struct imsm_dev
*dev
)
6473 if (!dev
->vol
.migr_state
)
6476 if (migr_type(dev
) == MIGR_GEN_MIGR
)
6482 static int is_rebuilding(struct imsm_dev
*dev
)
6484 struct imsm_map
*migr_map
;
6486 if (!dev
->vol
.migr_state
)
6489 if (migr_type(dev
) != MIGR_REBUILD
)
6492 migr_map
= get_imsm_map(dev
, MAP_1
);
6494 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
6501 static int is_initializing(struct imsm_dev
*dev
)
6503 struct imsm_map
*migr_map
;
6505 if (!dev
->vol
.migr_state
)
6508 if (migr_type(dev
) != MIGR_INIT
)
6511 migr_map
= get_imsm_map(dev
, MAP_1
);
6513 if (migr_map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
6520 static void update_recovery_start(struct intel_super
*super
,
6521 struct imsm_dev
*dev
,
6522 struct mdinfo
*array
)
6524 struct mdinfo
*rebuild
= NULL
;
6528 if (!is_rebuilding(dev
))
6531 /* Find the rebuild target, but punt on the dual rebuild case */
6532 for (d
= array
->devs
; d
; d
= d
->next
)
6533 if (d
->recovery_start
== 0) {
6540 /* (?) none of the disks are marked with
6541 * IMSM_ORD_REBUILD, so assume they are missing and the
6542 * disk_ord_tbl was not correctly updated
6544 dprintf("%s: failed to locate out-of-sync disk\n", __func__
);
6548 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
6549 rebuild
->recovery_start
= units
* blocks_per_migr_unit(super
, dev
);
6553 static int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
);
6556 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
6558 /* Given a container loaded by load_super_imsm_all,
6559 * extract information about all the arrays into
6561 * If 'subarray' is given, just extract info about that array.
6563 * For each imsm_dev create an mdinfo, fill it in,
6564 * then look for matching devices in super->disks
6565 * and create appropriate device mdinfo.
6567 struct intel_super
*super
= st
->sb
;
6568 struct imsm_super
*mpb
= super
->anchor
;
6569 struct mdinfo
*rest
= NULL
;
6573 int spare_disks
= 0;
6575 /* do not assemble arrays when not all attributes are supported */
6576 if (imsm_check_attributes(mpb
->attributes
) == 0) {
6578 pr_err("Unsupported attributes in IMSM metadata."
6579 "Arrays activation is blocked.\n");
6582 /* check for bad blocks */
6583 if (imsm_bbm_log_size(super
->anchor
)) {
6584 pr_err("BBM log found in IMSM metadata."
6585 "Arrays activation is blocked.\n");
6589 /* count spare devices, not used in maps
6591 for (d
= super
->disks
; d
; d
= d
->next
)
6595 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6596 struct imsm_dev
*dev
;
6597 struct imsm_map
*map
;
6598 struct imsm_map
*map2
;
6599 struct mdinfo
*this;
6607 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
6610 dev
= get_imsm_dev(super
, i
);
6611 map
= get_imsm_map(dev
, MAP_0
);
6612 map2
= get_imsm_map(dev
, MAP_1
);
6614 /* do not publish arrays that are in the middle of an
6615 * unsupported migration
6617 if (dev
->vol
.migr_state
&&
6618 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
6619 pr_err("cannot assemble volume '%.16s':"
6620 " unsupported migration in progress\n",
6624 /* do not publish arrays that are not support by controller's
6628 this = xmalloc(sizeof(*this));
6630 super
->current_vol
= i
;
6631 getinfo_super_imsm_volume(st
, this, NULL
);
6634 chunk
= __le16_to_cpu(map
->blocks_per_strip
) >> 1;
6635 /* mdadm does not support all metadata features- set the bit in all arrays state */
6636 if (!validate_geometry_imsm_orom(super
,
6637 get_imsm_raid_level(map
), /* RAID level */
6638 imsm_level_to_layout(get_imsm_raid_level(map
)),
6639 map
->num_members
, /* raid disks */
6640 &chunk
, join_u32(dev
->size_low
, dev
->size_high
),
6642 pr_err("IMSM RAID geometry validation"
6643 " failed. Array %s activation is blocked.\n",
6645 this->array
.state
|=
6646 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
6647 (1<<MD_SB_BLOCK_VOLUME
);
6651 /* if array has bad blocks, set suitable bit in all arrays state */
6653 this->array
.state
|=
6654 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
6655 (1<<MD_SB_BLOCK_VOLUME
);
6657 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
6658 unsigned long long recovery_start
;
6659 struct mdinfo
*info_d
;
6666 idx
= get_imsm_disk_idx(dev
, slot
, MAP_0
);
6667 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
6668 for (d
= super
->disks
; d
; d
= d
->next
)
6669 if (d
->index
== idx
)
6672 recovery_start
= MaxSector
;
6675 if (d
&& is_failed(&d
->disk
))
6677 if (ord
& IMSM_ORD_REBUILD
)
6681 * if we skip some disks the array will be assmebled degraded;
6682 * reset resync start to avoid a dirty-degraded
6683 * situation when performing the intial sync
6685 * FIXME handle dirty degraded
6687 if ((skip
|| recovery_start
== 0) && !dev
->vol
.dirty
)
6688 this->resync_start
= MaxSector
;
6692 info_d
= xcalloc(1, sizeof(*info_d
));
6693 info_d
->next
= this->devs
;
6694 this->devs
= info_d
;
6696 info_d
->disk
.number
= d
->index
;
6697 info_d
->disk
.major
= d
->major
;
6698 info_d
->disk
.minor
= d
->minor
;
6699 info_d
->disk
.raid_disk
= slot
;
6700 info_d
->recovery_start
= recovery_start
;
6702 if (slot
< map2
->num_members
)
6703 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
6705 this->array
.spare_disks
++;
6707 if (slot
< map
->num_members
)
6708 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
6710 this->array
.spare_disks
++;
6712 if (info_d
->recovery_start
== MaxSector
)
6713 this->array
.working_disks
++;
6715 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
6716 info_d
->data_offset
= pba_of_lba0(map
);
6717 info_d
->component_size
= blocks_per_member(map
);
6719 /* now that the disk list is up-to-date fixup recovery_start */
6720 update_recovery_start(super
, dev
, this);
6721 this->array
.spare_disks
+= spare_disks
;
6724 /* check for reshape */
6725 if (this->reshape_active
== 1)
6726 recover_backup_imsm(st
, this);
6734 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
6735 int failed
, int look_in_map
)
6737 struct imsm_map
*map
;
6739 map
= get_imsm_map(dev
, look_in_map
);
6742 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
6743 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
6745 switch (get_imsm_raid_level(map
)) {
6747 return IMSM_T_STATE_FAILED
;
6750 if (failed
< map
->num_members
)
6751 return IMSM_T_STATE_DEGRADED
;
6753 return IMSM_T_STATE_FAILED
;
6758 * check to see if any mirrors have failed, otherwise we
6759 * are degraded. Even numbered slots are mirrored on
6763 /* gcc -Os complains that this is unused */
6764 int insync
= insync
;
6766 for (i
= 0; i
< map
->num_members
; i
++) {
6767 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_X
);
6768 int idx
= ord_to_idx(ord
);
6769 struct imsm_disk
*disk
;
6771 /* reset the potential in-sync count on even-numbered
6772 * slots. num_copies is always 2 for imsm raid10
6777 disk
= get_imsm_disk(super
, idx
);
6778 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
6781 /* no in-sync disks left in this mirror the
6785 return IMSM_T_STATE_FAILED
;
6788 return IMSM_T_STATE_DEGRADED
;
6792 return IMSM_T_STATE_DEGRADED
;
6794 return IMSM_T_STATE_FAILED
;
6800 return map
->map_state
;
6803 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
6808 struct imsm_disk
*disk
;
6809 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
6810 struct imsm_map
*prev
= get_imsm_map(dev
, MAP_1
);
6811 struct imsm_map
*map_for_loop
;
6816 /* at the beginning of migration we set IMSM_ORD_REBUILD on
6817 * disks that are being rebuilt. New failures are recorded to
6818 * map[0]. So we look through all the disks we started with and
6819 * see if any failures are still present, or if any new ones
6823 if (prev
&& (map
->num_members
< prev
->num_members
))
6824 map_for_loop
= prev
;
6826 for (i
= 0; i
< map_for_loop
->num_members
; i
++) {
6828 /* when MAP_X is passed both maps failures are counted
6831 ((look_in_map
== MAP_1
) || (look_in_map
== MAP_X
)) &&
6832 (i
< prev
->num_members
)) {
6833 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
6834 idx_1
= ord_to_idx(ord
);
6836 disk
= get_imsm_disk(super
, idx_1
);
6837 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
6840 if (((look_in_map
== MAP_0
) || (look_in_map
== MAP_X
)) &&
6841 (i
< map
->num_members
)) {
6842 ord
= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
6843 idx
= ord_to_idx(ord
);
6846 disk
= get_imsm_disk(super
, idx
);
6847 if (!disk
|| is_failed(disk
) ||
6848 ord
& IMSM_ORD_REBUILD
)
6858 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
6861 struct intel_super
*super
= c
->sb
;
6862 struct imsm_super
*mpb
= super
->anchor
;
6864 if (atoi(inst
) >= mpb
->num_raid_devs
) {
6865 pr_err("%s: subarry index %d, out of range\n",
6866 __func__
, atoi(inst
));
6870 dprintf("imsm: open_new %s\n", inst
);
6871 a
->info
.container_member
= atoi(inst
);
6875 static int is_resyncing(struct imsm_dev
*dev
)
6877 struct imsm_map
*migr_map
;
6879 if (!dev
->vol
.migr_state
)
6882 if (migr_type(dev
) == MIGR_INIT
||
6883 migr_type(dev
) == MIGR_REPAIR
)
6886 if (migr_type(dev
) == MIGR_GEN_MIGR
)
6889 migr_map
= get_imsm_map(dev
, MAP_1
);
6891 if ((migr_map
->map_state
== IMSM_T_STATE_NORMAL
) &&
6892 (dev
->vol
.migr_type
!= MIGR_GEN_MIGR
))
6898 /* return true if we recorded new information */
6899 static int mark_failure(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
6903 struct imsm_map
*map
;
6904 char buf
[MAX_RAID_SERIAL_LEN
+3];
6905 unsigned int len
, shift
= 0;
6907 /* new failures are always set in map[0] */
6908 map
= get_imsm_map(dev
, MAP_0
);
6910 slot
= get_imsm_disk_slot(map
, idx
);
6914 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
6915 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
6918 memcpy(buf
, disk
->serial
, MAX_RAID_SERIAL_LEN
);
6919 buf
[MAX_RAID_SERIAL_LEN
] = '\000';
6921 if ((len
= strlen(buf
)) >= MAX_RAID_SERIAL_LEN
)
6922 shift
= len
- MAX_RAID_SERIAL_LEN
+ 1;
6923 strncpy((char *)disk
->serial
, &buf
[shift
], MAX_RAID_SERIAL_LEN
);
6925 disk
->status
|= FAILED_DISK
;
6926 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
6927 /* mark failures in second map if second map exists and this disk
6929 * This is valid for migration, initialization and rebuild
6931 if (dev
->vol
.migr_state
) {
6932 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
6933 int slot2
= get_imsm_disk_slot(map2
, idx
);
6935 if ((slot2
< map2
->num_members
) &&
6937 set_imsm_ord_tbl_ent(map2
, slot2
,
6938 idx
| IMSM_ORD_REBUILD
);
6940 if (map
->failed_disk_num
== 0xff)
6941 map
->failed_disk_num
= slot
;
6945 static void mark_missing(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
6947 mark_failure(dev
, disk
, idx
);
6949 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
6952 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
6953 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
6956 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
6960 if (!super
->missing
)
6963 /* When orom adds replacement for missing disk it does
6964 * not remove entry of missing disk, but just updates map with
6965 * new added disk. So it is not enough just to test if there is
6966 * any missing disk, we have to look if there are any failed disks
6967 * in map to stop migration */
6969 dprintf("imsm: mark missing\n");
6970 /* end process for initialization and rebuild only
6972 if (is_gen_migration(dev
) == 0) {
6976 failed
= imsm_count_failed(super
, dev
, MAP_0
);
6977 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
6980 end_migration(dev
, super
, map_state
);
6982 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
6983 mark_missing(dev
, &dl
->disk
, dl
->index
);
6984 super
->updates_pending
++;
6987 static unsigned long long imsm_set_array_size(struct imsm_dev
*dev
,
6990 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
6991 unsigned long long array_blocks
;
6992 struct imsm_map
*map
;
6994 if (used_disks
== 0) {
6995 /* when problems occures
6996 * return current array_blocks value
6998 array_blocks
= __le32_to_cpu(dev
->size_high
);
6999 array_blocks
= array_blocks
<< 32;
7000 array_blocks
+= __le32_to_cpu(dev
->size_low
);
7002 return array_blocks
;
7005 /* set array size in metadata
7007 if (new_size
<= 0) {
7008 /* OLCE size change is caused by added disks
7010 map
= get_imsm_map(dev
, MAP_0
);
7011 array_blocks
= blocks_per_member(map
) * used_disks
;
7013 /* Online Volume Size Change
7014 * Using available free space
7016 array_blocks
= new_size
;
7019 /* round array size down to closest MB
7021 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
7022 dev
->size_low
= __cpu_to_le32((__u32
)array_blocks
);
7023 dev
->size_high
= __cpu_to_le32((__u32
)(array_blocks
>> 32));
7025 return array_blocks
;
7028 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
7030 static void imsm_progress_container_reshape(struct intel_super
*super
)
7032 /* if no device has a migr_state, but some device has a
7033 * different number of members than the previous device, start
7034 * changing the number of devices in this device to match
7037 struct imsm_super
*mpb
= super
->anchor
;
7038 int prev_disks
= -1;
7042 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7043 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
7044 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7045 struct imsm_map
*map2
;
7046 int prev_num_members
;
7048 if (dev
->vol
.migr_state
)
7051 if (prev_disks
== -1)
7052 prev_disks
= map
->num_members
;
7053 if (prev_disks
== map
->num_members
)
7056 /* OK, this array needs to enter reshape mode.
7057 * i.e it needs a migr_state
7060 copy_map_size
= sizeof_imsm_map(map
);
7061 prev_num_members
= map
->num_members
;
7062 map
->num_members
= prev_disks
;
7063 dev
->vol
.migr_state
= 1;
7064 dev
->vol
.curr_migr_unit
= 0;
7065 set_migr_type(dev
, MIGR_GEN_MIGR
);
7066 for (i
= prev_num_members
;
7067 i
< map
->num_members
; i
++)
7068 set_imsm_ord_tbl_ent(map
, i
, i
);
7069 map2
= get_imsm_map(dev
, MAP_1
);
7070 /* Copy the current map */
7071 memcpy(map2
, map
, copy_map_size
);
7072 map2
->num_members
= prev_num_members
;
7074 imsm_set_array_size(dev
, -1);
7075 super
->clean_migration_record_by_mdmon
= 1;
7076 super
->updates_pending
++;
7080 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
7081 * states are handled in imsm_set_disk() with one exception, when a
7082 * resync is stopped due to a new failure this routine will set the
7083 * 'degraded' state for the array.
7085 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
7087 int inst
= a
->info
.container_member
;
7088 struct intel_super
*super
= a
->container
->sb
;
7089 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7090 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7091 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
7092 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7093 __u32 blocks_per_unit
;
7095 if (dev
->vol
.migr_state
&&
7096 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
7097 /* array state change is blocked due to reshape action
7099 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
7100 * - finish the reshape (if last_checkpoint is big and action != reshape)
7101 * - update curr_migr_unit
7103 if (a
->curr_action
== reshape
) {
7104 /* still reshaping, maybe update curr_migr_unit */
7105 goto mark_checkpoint
;
7107 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
7108 /* for some reason we aborted the reshape.
7110 * disable automatic metadata rollback
7111 * user action is required to recover process
7114 struct imsm_map
*map2
=
7115 get_imsm_map(dev
, MAP_1
);
7116 dev
->vol
.migr_state
= 0;
7117 set_migr_type(dev
, 0);
7118 dev
->vol
.curr_migr_unit
= 0;
7120 sizeof_imsm_map(map2
));
7121 super
->updates_pending
++;
7124 if (a
->last_checkpoint
>= a
->info
.component_size
) {
7125 unsigned long long array_blocks
;
7129 used_disks
= imsm_num_data_members(dev
, MAP_0
);
7130 if (used_disks
> 0) {
7132 blocks_per_member(map
) *
7134 /* round array size down to closest MB
7136 array_blocks
= (array_blocks
7137 >> SECT_PER_MB_SHIFT
)
7138 << SECT_PER_MB_SHIFT
;
7139 a
->info
.custom_array_size
= array_blocks
;
7140 /* encourage manager to update array
7144 a
->check_reshape
= 1;
7146 /* finalize online capacity expansion/reshape */
7147 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
7149 mdi
->disk
.raid_disk
,
7152 imsm_progress_container_reshape(super
);
7157 /* before we activate this array handle any missing disks */
7158 if (consistent
== 2)
7159 handle_missing(super
, dev
);
7161 if (consistent
== 2 &&
7162 (!is_resync_complete(&a
->info
) ||
7163 map_state
!= IMSM_T_STATE_NORMAL
||
7164 dev
->vol
.migr_state
))
7167 if (is_resync_complete(&a
->info
)) {
7168 /* complete intialization / resync,
7169 * recovery and interrupted recovery is completed in
7172 if (is_resyncing(dev
)) {
7173 dprintf("imsm: mark resync done\n");
7174 end_migration(dev
, super
, map_state
);
7175 super
->updates_pending
++;
7176 a
->last_checkpoint
= 0;
7178 } else if ((!is_resyncing(dev
) && !failed
) &&
7179 (imsm_reshape_blocks_arrays_changes(super
) == 0)) {
7180 /* mark the start of the init process if nothing is failed */
7181 dprintf("imsm: mark resync start\n");
7182 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
7183 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
7185 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
7186 super
->updates_pending
++;
7190 /* skip checkpointing for general migration,
7191 * it is controlled in mdadm
7193 if (is_gen_migration(dev
))
7194 goto skip_mark_checkpoint
;
7196 /* check if we can update curr_migr_unit from resync_start, recovery_start */
7197 blocks_per_unit
= blocks_per_migr_unit(super
, dev
);
7198 if (blocks_per_unit
) {
7202 units
= a
->last_checkpoint
/ blocks_per_unit
;
7205 /* check that we did not overflow 32-bits, and that
7206 * curr_migr_unit needs updating
7208 if (units32
== units
&&
7210 __le32_to_cpu(dev
->vol
.curr_migr_unit
) != units32
) {
7211 dprintf("imsm: mark checkpoint (%u)\n", units32
);
7212 dev
->vol
.curr_migr_unit
= __cpu_to_le32(units32
);
7213 super
->updates_pending
++;
7217 skip_mark_checkpoint
:
7218 /* mark dirty / clean */
7219 if (dev
->vol
.dirty
!= !consistent
) {
7220 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
7225 super
->updates_pending
++;
7231 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
7233 int inst
= a
->info
.container_member
;
7234 struct intel_super
*super
= a
->container
->sb
;
7235 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7236 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7237 struct imsm_disk
*disk
;
7239 int recovery_not_finished
= 0;
7244 if (n
> map
->num_members
)
7245 pr_err("imsm: set_disk %d out of range 0..%d\n",
7246 n
, map
->num_members
- 1);
7251 dprintf("imsm: set_disk %d:%x\n", n
, state
);
7253 ord
= get_imsm_ord_tbl_ent(dev
, n
, MAP_0
);
7254 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
7256 /* check for new failures */
7257 if (state
& DS_FAULTY
) {
7258 if (mark_failure(dev
, disk
, ord_to_idx(ord
)))
7259 super
->updates_pending
++;
7262 /* check if in_sync */
7263 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
7264 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
7266 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
7267 super
->updates_pending
++;
7270 failed
= imsm_count_failed(super
, dev
, MAP_0
);
7271 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7273 /* check if recovery complete, newly degraded, or failed */
7274 dprintf("imsm: Detected transition to state ");
7275 switch (map_state
) {
7276 case IMSM_T_STATE_NORMAL
: /* transition to normal state */
7277 dprintf("normal: ");
7278 if (is_rebuilding(dev
)) {
7279 dprintf("while rebuilding");
7280 /* check if recovery is really finished */
7281 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
7282 if (mdi
->recovery_start
!= MaxSector
) {
7283 recovery_not_finished
= 1;
7286 if (recovery_not_finished
) {
7287 dprintf("\nimsm: Rebuild has not finished yet, "
7288 "state not changed");
7289 if (a
->last_checkpoint
< mdi
->recovery_start
) {
7290 a
->last_checkpoint
= mdi
->recovery_start
;
7291 super
->updates_pending
++;
7295 end_migration(dev
, super
, map_state
);
7296 map
= get_imsm_map(dev
, MAP_0
);
7297 map
->failed_disk_num
= ~0;
7298 super
->updates_pending
++;
7299 a
->last_checkpoint
= 0;
7302 if (is_gen_migration(dev
)) {
7303 dprintf("while general migration");
7304 if (a
->last_checkpoint
>= a
->info
.component_size
)
7305 end_migration(dev
, super
, map_state
);
7307 map
->map_state
= map_state
;
7308 map
= get_imsm_map(dev
, MAP_0
);
7309 map
->failed_disk_num
= ~0;
7310 super
->updates_pending
++;
7314 case IMSM_T_STATE_DEGRADED
: /* transition to degraded state */
7315 dprintf("degraded: ");
7316 if ((map
->map_state
!= map_state
) &&
7317 !dev
->vol
.migr_state
) {
7318 dprintf("mark degraded");
7319 map
->map_state
= map_state
;
7320 super
->updates_pending
++;
7321 a
->last_checkpoint
= 0;
7324 if (is_rebuilding(dev
)) {
7325 dprintf("while rebuilding.");
7326 if (map
->map_state
!= map_state
) {
7327 dprintf(" Map state change");
7328 end_migration(dev
, super
, map_state
);
7329 super
->updates_pending
++;
7333 if (is_gen_migration(dev
)) {
7334 dprintf("while general migration");
7335 if (a
->last_checkpoint
>= a
->info
.component_size
)
7336 end_migration(dev
, super
, map_state
);
7338 map
->map_state
= map_state
;
7339 manage_second_map(super
, dev
);
7341 super
->updates_pending
++;
7344 if (is_initializing(dev
)) {
7345 dprintf("while initialization.");
7346 map
->map_state
= map_state
;
7347 super
->updates_pending
++;
7351 case IMSM_T_STATE_FAILED
: /* transition to failed state */
7352 dprintf("failed: ");
7353 if (is_gen_migration(dev
)) {
7354 dprintf("while general migration");
7355 map
->map_state
= map_state
;
7356 super
->updates_pending
++;
7359 if (map
->map_state
!= map_state
) {
7360 dprintf("mark failed");
7361 end_migration(dev
, super
, map_state
);
7362 super
->updates_pending
++;
7363 a
->last_checkpoint
= 0;
7368 dprintf("state %i\n", map_state
);
7374 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
7377 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
7378 unsigned long long dsize
;
7379 unsigned long long sectors
;
7381 get_dev_size(fd
, NULL
, &dsize
);
7383 if (mpb_size
> 512) {
7384 /* -1 to account for anchor */
7385 sectors
= mpb_sectors(mpb
) - 1;
7387 /* write the extended mpb to the sectors preceeding the anchor */
7388 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0)
7391 if ((unsigned long long)write(fd
, buf
+ 512, 512 * sectors
)
7396 /* first block is stored on second to last sector of the disk */
7397 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0)
7400 if (write(fd
, buf
, 512) != 512)
7406 static void imsm_sync_metadata(struct supertype
*container
)
7408 struct intel_super
*super
= container
->sb
;
7410 dprintf("sync metadata: %d\n", super
->updates_pending
);
7411 if (!super
->updates_pending
)
7414 write_super_imsm(container
, 0);
7416 super
->updates_pending
= 0;
7419 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
7421 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
7422 int i
= get_imsm_disk_idx(dev
, idx
, MAP_X
);
7425 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7429 if (dl
&& is_failed(&dl
->disk
))
7433 dprintf("%s: found %x:%x\n", __func__
, dl
->major
, dl
->minor
);
7438 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
7439 struct active_array
*a
, int activate_new
,
7440 struct mdinfo
*additional_test_list
)
7442 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
7443 int idx
= get_imsm_disk_idx(dev
, slot
, MAP_X
);
7444 struct imsm_super
*mpb
= super
->anchor
;
7445 struct imsm_map
*map
;
7446 unsigned long long pos
;
7451 __u32 array_start
= 0;
7452 __u32 array_end
= 0;
7454 struct mdinfo
*test_list
;
7456 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7457 /* If in this array, skip */
7458 for (d
= a
->info
.devs
; d
; d
= d
->next
)
7459 if (d
->state_fd
>= 0 &&
7460 d
->disk
.major
== dl
->major
&&
7461 d
->disk
.minor
== dl
->minor
) {
7462 dprintf("%x:%x already in array\n",
7463 dl
->major
, dl
->minor
);
7468 test_list
= additional_test_list
;
7470 if (test_list
->disk
.major
== dl
->major
&&
7471 test_list
->disk
.minor
== dl
->minor
) {
7472 dprintf("%x:%x already in additional test list\n",
7473 dl
->major
, dl
->minor
);
7476 test_list
= test_list
->next
;
7481 /* skip in use or failed drives */
7482 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
7484 dprintf("%x:%x status (failed: %d index: %d)\n",
7485 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
7489 /* skip pure spares when we are looking for partially
7490 * assimilated drives
7492 if (dl
->index
== -1 && !activate_new
)
7495 /* Does this unused device have the requisite free space?
7496 * It needs to be able to cover all member volumes
7498 ex
= get_extents(super
, dl
);
7500 dprintf("cannot get extents\n");
7503 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7504 dev
= get_imsm_dev(super
, i
);
7505 map
= get_imsm_map(dev
, MAP_0
);
7507 /* check if this disk is already a member of
7510 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
7516 array_start
= pba_of_lba0(map
);
7517 array_end
= array_start
+
7518 blocks_per_member(map
) - 1;
7521 /* check that we can start at pba_of_lba0 with
7522 * blocks_per_member of space
7524 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
7528 pos
= ex
[j
].start
+ ex
[j
].size
;
7530 } while (ex
[j
-1].size
);
7537 if (i
< mpb
->num_raid_devs
) {
7538 dprintf("%x:%x does not have %u to %u available\n",
7539 dl
->major
, dl
->minor
, array_start
, array_end
);
7549 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
7551 struct imsm_dev
*dev2
;
7552 struct imsm_map
*map
;
7558 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
7560 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
, MAP_0
);
7561 if (state
== IMSM_T_STATE_FAILED
) {
7562 map
= get_imsm_map(dev2
, MAP_0
);
7565 for (slot
= 0; slot
< map
->num_members
; slot
++) {
7567 * Check if failed disks are deleted from intel
7568 * disk list or are marked to be deleted
7570 idx
= get_imsm_disk_idx(dev2
, slot
, MAP_X
);
7571 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
7573 * Do not rebuild the array if failed disks
7574 * from failed sub-array are not removed from
7578 is_failed(&idisk
->disk
) &&
7579 (idisk
->action
!= DISK_REMOVE
))
7587 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
7588 struct metadata_update
**updates
)
7591 * Find a device with unused free space and use it to replace a
7592 * failed/vacant region in an array. We replace failed regions one a
7593 * array at a time. The result is that a new spare disk will be added
7594 * to the first failed array and after the monitor has finished
7595 * propagating failures the remainder will be consumed.
7597 * FIXME add a capability for mdmon to request spares from another
7601 struct intel_super
*super
= a
->container
->sb
;
7602 int inst
= a
->info
.container_member
;
7603 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7604 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7605 int failed
= a
->info
.array
.raid_disks
;
7606 struct mdinfo
*rv
= NULL
;
7609 struct metadata_update
*mu
;
7611 struct imsm_update_activate_spare
*u
;
7616 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
7617 if ((d
->curr_state
& DS_FAULTY
) &&
7619 /* wait for Removal to happen */
7621 if (d
->state_fd
>= 0)
7625 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
7626 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
7628 if (imsm_reshape_blocks_arrays_changes(super
))
7631 /* Cannot activate another spare if rebuild is in progress already
7633 if (is_rebuilding(dev
)) {
7634 dprintf("imsm: No spare activation allowed. "
7635 "Rebuild in progress already.\n");
7639 if (a
->info
.array
.level
== 4)
7640 /* No repair for takeovered array
7641 * imsm doesn't support raid4
7645 if (imsm_check_degraded(super
, dev
, failed
, MAP_0
) !=
7646 IMSM_T_STATE_DEGRADED
)
7650 * If there are any failed disks check state of the other volume.
7651 * Block rebuild if the another one is failed until failed disks
7652 * are removed from container.
7655 dprintf("found failed disks in %.*s, check if there another"
7656 "failed sub-array.\n",
7657 MAX_RAID_SERIAL_LEN
, dev
->volume
);
7658 /* check if states of the other volumes allow for rebuild */
7659 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
7661 allowed
= imsm_rebuild_allowed(a
->container
,
7669 /* For each slot, if it is not working, find a spare */
7670 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
7671 for (d
= a
->info
.devs
; d
; d
= d
->next
)
7672 if (d
->disk
.raid_disk
== i
)
7674 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
7675 if (d
&& (d
->state_fd
>= 0))
7679 * OK, this device needs recovery. Try to re-add the
7680 * previous occupant of this slot, if this fails see if
7681 * we can continue the assimilation of a spare that was
7682 * partially assimilated, finally try to activate a new
7685 dl
= imsm_readd(super
, i
, a
);
7687 dl
= imsm_add_spare(super
, i
, a
, 0, rv
);
7689 dl
= imsm_add_spare(super
, i
, a
, 1, rv
);
7693 /* found a usable disk with enough space */
7694 di
= xcalloc(1, sizeof(*di
));
7696 /* dl->index will be -1 in the case we are activating a
7697 * pristine spare. imsm_process_update() will create a
7698 * new index in this case. Once a disk is found to be
7699 * failed in all member arrays it is kicked from the
7702 di
->disk
.number
= dl
->index
;
7704 /* (ab)use di->devs to store a pointer to the device
7707 di
->devs
= (struct mdinfo
*) dl
;
7709 di
->disk
.raid_disk
= i
;
7710 di
->disk
.major
= dl
->major
;
7711 di
->disk
.minor
= dl
->minor
;
7713 di
->recovery_start
= 0;
7714 di
->data_offset
= pba_of_lba0(map
);
7715 di
->component_size
= a
->info
.component_size
;
7716 di
->container_member
= inst
;
7717 super
->random
= random32();
7721 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
7722 i
, di
->data_offset
);
7726 /* No spares found */
7728 /* Now 'rv' has a list of devices to return.
7729 * Create a metadata_update record to update the
7730 * disk_ord_tbl for the array
7732 mu
= xmalloc(sizeof(*mu
));
7733 mu
->buf
= xcalloc(num_spares
,
7734 sizeof(struct imsm_update_activate_spare
));
7736 mu
->space_list
= NULL
;
7737 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
7738 mu
->next
= *updates
;
7739 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
7741 for (di
= rv
; di
; di
= di
->next
) {
7742 u
->type
= update_activate_spare
;
7743 u
->dl
= (struct dl
*) di
->devs
;
7745 u
->slot
= di
->disk
.raid_disk
;
7756 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
7758 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
7759 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7760 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, MAP_0
);
7761 struct disk_info
*inf
= get_disk_info(u
);
7762 struct imsm_disk
*disk
;
7766 for (i
= 0; i
< map
->num_members
; i
++) {
7767 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, MAP_X
));
7768 for (j
= 0; j
< new_map
->num_members
; j
++)
7769 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
7776 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
7778 struct dl
*dl
= NULL
;
7779 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7780 if ((dl
->major
== major
) && (dl
->minor
== minor
))
7785 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
7787 struct dl
*prev
= NULL
;
7791 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7792 if ((dl
->major
== major
) && (dl
->minor
== minor
)) {
7795 prev
->next
= dl
->next
;
7797 super
->disks
= dl
->next
;
7799 __free_imsm_disk(dl
);
7800 dprintf("%s: removed %x:%x\n",
7801 __func__
, major
, minor
);
7809 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
7811 static int add_remove_disk_update(struct intel_super
*super
)
7813 int check_degraded
= 0;
7814 struct dl
*disk
= NULL
;
7815 /* add/remove some spares to/from the metadata/contrainer */
7816 while (super
->disk_mgmt_list
) {
7817 struct dl
*disk_cfg
;
7819 disk_cfg
= super
->disk_mgmt_list
;
7820 super
->disk_mgmt_list
= disk_cfg
->next
;
7821 disk_cfg
->next
= NULL
;
7823 if (disk_cfg
->action
== DISK_ADD
) {
7824 disk_cfg
->next
= super
->disks
;
7825 super
->disks
= disk_cfg
;
7827 dprintf("%s: added %x:%x\n",
7828 __func__
, disk_cfg
->major
,
7830 } else if (disk_cfg
->action
== DISK_REMOVE
) {
7831 dprintf("Disk remove action processed: %x.%x\n",
7832 disk_cfg
->major
, disk_cfg
->minor
);
7833 disk
= get_disk_super(super
,
7837 /* store action status */
7838 disk
->action
= DISK_REMOVE
;
7839 /* remove spare disks only */
7840 if (disk
->index
== -1) {
7841 remove_disk_super(super
,
7846 /* release allocate disk structure */
7847 __free_imsm_disk(disk_cfg
);
7850 return check_degraded
;
7853 static int apply_reshape_migration_update(struct imsm_update_reshape_migration
*u
,
7854 struct intel_super
*super
,
7857 struct intel_dev
*id
;
7858 void **tofree
= NULL
;
7861 dprintf("apply_reshape_migration_update()\n");
7862 if ((u
->subdev
< 0) ||
7864 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
7867 if ((space_list
== NULL
) || (*space_list
== NULL
)) {
7868 dprintf("imsm: Error: Memory is not allocated\n");
7872 for (id
= super
->devlist
; id
; id
= id
->next
) {
7873 if (id
->index
== (unsigned)u
->subdev
) {
7874 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
7875 struct imsm_map
*map
;
7876 struct imsm_dev
*new_dev
=
7877 (struct imsm_dev
*)*space_list
;
7878 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
7880 struct dl
*new_disk
;
7882 if (new_dev
== NULL
)
7884 *space_list
= **space_list
;
7885 memcpy(new_dev
, dev
, sizeof_imsm_dev(dev
, 0));
7886 map
= get_imsm_map(new_dev
, MAP_0
);
7888 dprintf("imsm: Error: migration in progress");
7892 to_state
= map
->map_state
;
7893 if ((u
->new_level
== 5) && (map
->raid_level
== 0)) {
7895 /* this should not happen */
7896 if (u
->new_disks
[0] < 0) {
7897 map
->failed_disk_num
=
7898 map
->num_members
- 1;
7899 to_state
= IMSM_T_STATE_DEGRADED
;
7901 to_state
= IMSM_T_STATE_NORMAL
;
7903 migrate(new_dev
, super
, to_state
, MIGR_GEN_MIGR
);
7904 if (u
->new_level
> -1)
7905 map
->raid_level
= u
->new_level
;
7906 migr_map
= get_imsm_map(new_dev
, MAP_1
);
7907 if ((u
->new_level
== 5) &&
7908 (migr_map
->raid_level
== 0)) {
7909 int ord
= map
->num_members
- 1;
7910 migr_map
->num_members
--;
7911 if (u
->new_disks
[0] < 0)
7912 ord
|= IMSM_ORD_REBUILD
;
7913 set_imsm_ord_tbl_ent(map
,
7914 map
->num_members
- 1,
7918 tofree
= (void **)dev
;
7920 /* update chunk size
7922 if (u
->new_chunksize
> 0)
7923 map
->blocks_per_strip
=
7924 __cpu_to_le16(u
->new_chunksize
* 2);
7928 if ((u
->new_level
!= 5) ||
7929 (migr_map
->raid_level
!= 0) ||
7930 (migr_map
->raid_level
== map
->raid_level
))
7933 if (u
->new_disks
[0] >= 0) {
7936 new_disk
= get_disk_super(super
,
7937 major(u
->new_disks
[0]),
7938 minor(u
->new_disks
[0]));
7939 dprintf("imsm: new disk for reshape is: %i:%i "
7940 "(%p, index = %i)\n",
7941 major(u
->new_disks
[0]),
7942 minor(u
->new_disks
[0]),
7943 new_disk
, new_disk
->index
);
7944 if (new_disk
== NULL
)
7945 goto error_disk_add
;
7947 new_disk
->index
= map
->num_members
- 1;
7948 /* slot to fill in autolayout
7950 new_disk
->raiddisk
= new_disk
->index
;
7951 new_disk
->disk
.status
|= CONFIGURED_DISK
;
7952 new_disk
->disk
.status
&= ~SPARE_DISK
;
7954 goto error_disk_add
;
7957 *tofree
= *space_list
;
7958 /* calculate new size
7960 imsm_set_array_size(new_dev
, -1);
7967 *space_list
= tofree
;
7971 dprintf("Error: imsm: Cannot find disk.\n");
7975 static int apply_size_change_update(struct imsm_update_size_change
*u
,
7976 struct intel_super
*super
)
7978 struct intel_dev
*id
;
7981 dprintf("apply_size_change_update()\n");
7982 if ((u
->subdev
< 0) ||
7984 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
7988 for (id
= super
->devlist
; id
; id
= id
->next
) {
7989 if (id
->index
== (unsigned)u
->subdev
) {
7990 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
7991 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7992 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
7993 unsigned long long blocks_per_member
;
7995 /* calculate new size
7997 blocks_per_member
= u
->new_size
/ used_disks
;
7998 dprintf("imsm: apply_size_change_update(size: %llu, "
7999 "blocks per member: %llu)\n",
8000 u
->new_size
, blocks_per_member
);
8001 set_blocks_per_member(map
, blocks_per_member
);
8002 imsm_set_array_size(dev
, u
->new_size
);
8012 static int apply_update_activate_spare(struct imsm_update_activate_spare
*u
,
8013 struct intel_super
*super
,
8014 struct active_array
*active_array
)
8016 struct imsm_super
*mpb
= super
->anchor
;
8017 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
8018 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8019 struct imsm_map
*migr_map
;
8020 struct active_array
*a
;
8021 struct imsm_disk
*disk
;
8028 int second_map_created
= 0;
8030 for (; u
; u
= u
->next
) {
8031 victim
= get_imsm_disk_idx(dev
, u
->slot
, MAP_X
);
8036 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8041 pr_err("error: imsm_activate_spare passed "
8042 "an unknown disk (index: %d)\n",
8047 /* count failures (excluding rebuilds and the victim)
8048 * to determine map[0] state
8051 for (i
= 0; i
< map
->num_members
; i
++) {
8054 disk
= get_imsm_disk(super
,
8055 get_imsm_disk_idx(dev
, i
, MAP_X
));
8056 if (!disk
|| is_failed(disk
))
8060 /* adding a pristine spare, assign a new index */
8061 if (dl
->index
< 0) {
8062 dl
->index
= super
->anchor
->num_disks
;
8063 super
->anchor
->num_disks
++;
8066 disk
->status
|= CONFIGURED_DISK
;
8067 disk
->status
&= ~SPARE_DISK
;
8070 to_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8071 if (!second_map_created
) {
8072 second_map_created
= 1;
8073 map
->map_state
= IMSM_T_STATE_DEGRADED
;
8074 migrate(dev
, super
, to_state
, MIGR_REBUILD
);
8076 map
->map_state
= to_state
;
8077 migr_map
= get_imsm_map(dev
, MAP_1
);
8078 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
8079 set_imsm_ord_tbl_ent(migr_map
, u
->slot
,
8080 dl
->index
| IMSM_ORD_REBUILD
);
8082 /* update the family_num to mark a new container
8083 * generation, being careful to record the existing
8084 * family_num in orig_family_num to clean up after
8085 * earlier mdadm versions that neglected to set it.
8087 if (mpb
->orig_family_num
== 0)
8088 mpb
->orig_family_num
= mpb
->family_num
;
8089 mpb
->family_num
+= super
->random
;
8091 /* count arrays using the victim in the metadata */
8093 for (a
= active_array
; a
; a
= a
->next
) {
8094 dev
= get_imsm_dev(super
, a
->info
.container_member
);
8095 map
= get_imsm_map(dev
, MAP_0
);
8097 if (get_imsm_disk_slot(map
, victim
) >= 0)
8101 /* delete the victim if it is no longer being
8107 /* We know that 'manager' isn't touching anything,
8108 * so it is safe to delete
8110 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
8111 if ((*dlp
)->index
== victim
)
8114 /* victim may be on the missing list */
8116 for (dlp
= &super
->missing
; *dlp
;
8117 dlp
= &(*dlp
)->next
)
8118 if ((*dlp
)->index
== victim
)
8120 imsm_delete(super
, dlp
, victim
);
8127 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
8128 struct intel_super
*super
,
8131 struct dl
*new_disk
;
8132 struct intel_dev
*id
;
8134 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
8135 int disk_count
= u
->old_raid_disks
;
8136 void **tofree
= NULL
;
8137 int devices_to_reshape
= 1;
8138 struct imsm_super
*mpb
= super
->anchor
;
8140 unsigned int dev_id
;
8142 dprintf("imsm: apply_reshape_container_disks_update()\n");
8144 /* enable spares to use in array */
8145 for (i
= 0; i
< delta_disks
; i
++) {
8146 new_disk
= get_disk_super(super
,
8147 major(u
->new_disks
[i
]),
8148 minor(u
->new_disks
[i
]));
8149 dprintf("imsm: new disk for reshape is: %i:%i "
8150 "(%p, index = %i)\n",
8151 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
8152 new_disk
, new_disk
->index
);
8153 if ((new_disk
== NULL
) ||
8154 ((new_disk
->index
>= 0) &&
8155 (new_disk
->index
< u
->old_raid_disks
)))
8156 goto update_reshape_exit
;
8157 new_disk
->index
= disk_count
++;
8158 /* slot to fill in autolayout
8160 new_disk
->raiddisk
= new_disk
->index
;
8161 new_disk
->disk
.status
|=
8163 new_disk
->disk
.status
&= ~SPARE_DISK
;
8166 dprintf("imsm: volume set mpb->num_raid_devs = %i\n",
8167 mpb
->num_raid_devs
);
8168 /* manage changes in volume
8170 for (dev_id
= 0; dev_id
< mpb
->num_raid_devs
; dev_id
++) {
8171 void **sp
= *space_list
;
8172 struct imsm_dev
*newdev
;
8173 struct imsm_map
*newmap
, *oldmap
;
8175 for (id
= super
->devlist
; id
; id
= id
->next
) {
8176 if (id
->index
== dev_id
)
8185 /* Copy the dev, but not (all of) the map */
8186 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
8187 oldmap
= get_imsm_map(id
->dev
, MAP_0
);
8188 newmap
= get_imsm_map(newdev
, MAP_0
);
8189 /* Copy the current map */
8190 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
8191 /* update one device only
8193 if (devices_to_reshape
) {
8194 dprintf("imsm: modifying subdev: %i\n",
8196 devices_to_reshape
--;
8197 newdev
->vol
.migr_state
= 1;
8198 newdev
->vol
.curr_migr_unit
= 0;
8199 set_migr_type(newdev
, MIGR_GEN_MIGR
);
8200 newmap
->num_members
= u
->new_raid_disks
;
8201 for (i
= 0; i
< delta_disks
; i
++) {
8202 set_imsm_ord_tbl_ent(newmap
,
8203 u
->old_raid_disks
+ i
,
8204 u
->old_raid_disks
+ i
);
8206 /* New map is correct, now need to save old map
8208 newmap
= get_imsm_map(newdev
, MAP_1
);
8209 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
8211 imsm_set_array_size(newdev
, -1);
8214 sp
= (void **)id
->dev
;
8219 /* Clear migration record */
8220 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
8223 *space_list
= tofree
;
8226 update_reshape_exit
:
8231 static int apply_takeover_update(struct imsm_update_takeover
*u
,
8232 struct intel_super
*super
,
8235 struct imsm_dev
*dev
= NULL
;
8236 struct intel_dev
*dv
;
8237 struct imsm_dev
*dev_new
;
8238 struct imsm_map
*map
;
8242 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
8243 if (dv
->index
== (unsigned int)u
->subarray
) {
8251 map
= get_imsm_map(dev
, MAP_0
);
8253 if (u
->direction
== R10_TO_R0
) {
8254 /* Number of failed disks must be half of initial disk number */
8255 if (imsm_count_failed(super
, dev
, MAP_0
) !=
8256 (map
->num_members
/ 2))
8259 /* iterate through devices to mark removed disks as spare */
8260 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
8261 if (dm
->disk
.status
& FAILED_DISK
) {
8262 int idx
= dm
->index
;
8263 /* update indexes on the disk list */
8264 /* FIXME this loop-with-the-loop looks wrong, I'm not convinced
8265 the index values will end up being correct.... NB */
8266 for (du
= super
->disks
; du
; du
= du
->next
)
8267 if (du
->index
> idx
)
8269 /* mark as spare disk */
8274 map
->num_members
= map
->num_members
/ 2;
8275 map
->map_state
= IMSM_T_STATE_NORMAL
;
8276 map
->num_domains
= 1;
8277 map
->raid_level
= 0;
8278 map
->failed_disk_num
= -1;
8281 if (u
->direction
== R0_TO_R10
) {
8283 /* update slots in current disk list */
8284 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
8288 /* create new *missing* disks */
8289 for (i
= 0; i
< map
->num_members
; i
++) {
8290 space
= *space_list
;
8293 *space_list
= *space
;
8295 memcpy(du
, super
->disks
, sizeof(*du
));
8299 du
->index
= (i
* 2) + 1;
8300 sprintf((char *)du
->disk
.serial
,
8301 " MISSING_%d", du
->index
);
8302 sprintf((char *)du
->serial
,
8303 "MISSING_%d", du
->index
);
8304 du
->next
= super
->missing
;
8305 super
->missing
= du
;
8307 /* create new dev and map */
8308 space
= *space_list
;
8311 *space_list
= *space
;
8312 dev_new
= (void *)space
;
8313 memcpy(dev_new
, dev
, sizeof(*dev
));
8314 /* update new map */
8315 map
= get_imsm_map(dev_new
, MAP_0
);
8316 map
->num_members
= map
->num_members
* 2;
8317 map
->map_state
= IMSM_T_STATE_DEGRADED
;
8318 map
->num_domains
= 2;
8319 map
->raid_level
= 1;
8320 /* replace dev<->dev_new */
8323 /* update disk order table */
8324 for (du
= super
->disks
; du
; du
= du
->next
)
8326 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
8327 for (du
= super
->missing
; du
; du
= du
->next
)
8328 if (du
->index
>= 0) {
8329 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
8330 mark_missing(dv
->dev
, &du
->disk
, du
->index
);
8336 static void imsm_process_update(struct supertype
*st
,
8337 struct metadata_update
*update
)
8340 * crack open the metadata_update envelope to find the update record
8341 * update can be one of:
8342 * update_reshape_container_disks - all the arrays in the container
8343 * are being reshaped to have more devices. We need to mark
8344 * the arrays for general migration and convert selected spares
8345 * into active devices.
8346 * update_activate_spare - a spare device has replaced a failed
8347 * device in an array, update the disk_ord_tbl. If this disk is
8348 * present in all member arrays then also clear the SPARE_DISK
8350 * update_create_array
8352 * update_rename_array
8353 * update_add_remove_disk
8355 struct intel_super
*super
= st
->sb
;
8356 struct imsm_super
*mpb
;
8357 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
8359 /* update requires a larger buf but the allocation failed */
8360 if (super
->next_len
&& !super
->next_buf
) {
8361 super
->next_len
= 0;
8365 if (super
->next_buf
) {
8366 memcpy(super
->next_buf
, super
->buf
, super
->len
);
8368 super
->len
= super
->next_len
;
8369 super
->buf
= super
->next_buf
;
8371 super
->next_len
= 0;
8372 super
->next_buf
= NULL
;
8375 mpb
= super
->anchor
;
8378 case update_general_migration_checkpoint
: {
8379 struct intel_dev
*id
;
8380 struct imsm_update_general_migration_checkpoint
*u
=
8381 (void *)update
->buf
;
8383 dprintf("imsm: process_update() "
8384 "for update_general_migration_checkpoint called\n");
8386 /* find device under general migration */
8387 for (id
= super
->devlist
; id
; id
= id
->next
) {
8388 if (is_gen_migration(id
->dev
)) {
8389 id
->dev
->vol
.curr_migr_unit
=
8390 __cpu_to_le32(u
->curr_migr_unit
);
8391 super
->updates_pending
++;
8396 case update_takeover
: {
8397 struct imsm_update_takeover
*u
= (void *)update
->buf
;
8398 if (apply_takeover_update(u
, super
, &update
->space_list
)) {
8399 imsm_update_version_info(super
);
8400 super
->updates_pending
++;
8405 case update_reshape_container_disks
: {
8406 struct imsm_update_reshape
*u
= (void *)update
->buf
;
8407 if (apply_reshape_container_disks_update(
8408 u
, super
, &update
->space_list
))
8409 super
->updates_pending
++;
8412 case update_reshape_migration
: {
8413 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
8414 if (apply_reshape_migration_update(
8415 u
, super
, &update
->space_list
))
8416 super
->updates_pending
++;
8419 case update_size_change
: {
8420 struct imsm_update_size_change
*u
= (void *)update
->buf
;
8421 if (apply_size_change_update(u
, super
))
8422 super
->updates_pending
++;
8425 case update_activate_spare
: {
8426 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
8427 if (apply_update_activate_spare(u
, super
, st
->arrays
))
8428 super
->updates_pending
++;
8431 case update_create_array
: {
8432 /* someone wants to create a new array, we need to be aware of
8433 * a few races/collisions:
8434 * 1/ 'Create' called by two separate instances of mdadm
8435 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
8436 * devices that have since been assimilated via
8438 * In the event this update can not be carried out mdadm will
8439 * (FIX ME) notice that its update did not take hold.
8441 struct imsm_update_create_array
*u
= (void *) update
->buf
;
8442 struct intel_dev
*dv
;
8443 struct imsm_dev
*dev
;
8444 struct imsm_map
*map
, *new_map
;
8445 unsigned long long start
, end
;
8446 unsigned long long new_start
, new_end
;
8448 struct disk_info
*inf
;
8451 /* handle racing creates: first come first serve */
8452 if (u
->dev_idx
< mpb
->num_raid_devs
) {
8453 dprintf("%s: subarray %d already defined\n",
8454 __func__
, u
->dev_idx
);
8458 /* check update is next in sequence */
8459 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
8460 dprintf("%s: can not create array %d expected index %d\n",
8461 __func__
, u
->dev_idx
, mpb
->num_raid_devs
);
8465 new_map
= get_imsm_map(&u
->dev
, MAP_0
);
8466 new_start
= pba_of_lba0(new_map
);
8467 new_end
= new_start
+ blocks_per_member(new_map
);
8468 inf
= get_disk_info(u
);
8470 /* handle activate_spare versus create race:
8471 * check to make sure that overlapping arrays do not include
8474 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8475 dev
= get_imsm_dev(super
, i
);
8476 map
= get_imsm_map(dev
, MAP_0
);
8477 start
= pba_of_lba0(map
);
8478 end
= start
+ blocks_per_member(map
);
8479 if ((new_start
>= start
&& new_start
<= end
) ||
8480 (start
>= new_start
&& start
<= new_end
))
8485 if (disks_overlap(super
, i
, u
)) {
8486 dprintf("%s: arrays overlap\n", __func__
);
8491 /* check that prepare update was successful */
8492 if (!update
->space
) {
8493 dprintf("%s: prepare update failed\n", __func__
);
8497 /* check that all disks are still active before committing
8498 * changes. FIXME: could we instead handle this by creating a
8499 * degraded array? That's probably not what the user expects,
8500 * so better to drop this update on the floor.
8502 for (i
= 0; i
< new_map
->num_members
; i
++) {
8503 dl
= serial_to_dl(inf
[i
].serial
, super
);
8505 dprintf("%s: disk disappeared\n", __func__
);
8510 super
->updates_pending
++;
8512 /* convert spares to members and fixup ord_tbl */
8513 for (i
= 0; i
< new_map
->num_members
; i
++) {
8514 dl
= serial_to_dl(inf
[i
].serial
, super
);
8515 if (dl
->index
== -1) {
8516 dl
->index
= mpb
->num_disks
;
8518 dl
->disk
.status
|= CONFIGURED_DISK
;
8519 dl
->disk
.status
&= ~SPARE_DISK
;
8521 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
8526 update
->space
= NULL
;
8527 imsm_copy_dev(dev
, &u
->dev
);
8528 dv
->index
= u
->dev_idx
;
8529 dv
->next
= super
->devlist
;
8530 super
->devlist
= dv
;
8531 mpb
->num_raid_devs
++;
8533 imsm_update_version_info(super
);
8536 /* mdmon knows how to release update->space, but not
8537 * ((struct intel_dev *) update->space)->dev
8539 if (update
->space
) {
8545 case update_kill_array
: {
8546 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
8547 int victim
= u
->dev_idx
;
8548 struct active_array
*a
;
8549 struct intel_dev
**dp
;
8550 struct imsm_dev
*dev
;
8552 /* sanity check that we are not affecting the uuid of
8553 * active arrays, or deleting an active array
8555 * FIXME when immutable ids are available, but note that
8556 * we'll also need to fixup the invalidated/active
8557 * subarray indexes in mdstat
8559 for (a
= st
->arrays
; a
; a
= a
->next
)
8560 if (a
->info
.container_member
>= victim
)
8562 /* by definition if mdmon is running at least one array
8563 * is active in the container, so checking
8564 * mpb->num_raid_devs is just extra paranoia
8566 dev
= get_imsm_dev(super
, victim
);
8567 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
8568 dprintf("failed to delete subarray-%d\n", victim
);
8572 for (dp
= &super
->devlist
; *dp
;)
8573 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
8576 if ((*dp
)->index
> (unsigned)victim
)
8580 mpb
->num_raid_devs
--;
8581 super
->updates_pending
++;
8584 case update_rename_array
: {
8585 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
8586 char name
[MAX_RAID_SERIAL_LEN
+1];
8587 int target
= u
->dev_idx
;
8588 struct active_array
*a
;
8589 struct imsm_dev
*dev
;
8591 /* sanity check that we are not affecting the uuid of
8594 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
8595 name
[MAX_RAID_SERIAL_LEN
] = '\0';
8596 for (a
= st
->arrays
; a
; a
= a
->next
)
8597 if (a
->info
.container_member
== target
)
8599 dev
= get_imsm_dev(super
, u
->dev_idx
);
8600 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
8601 dprintf("failed to rename subarray-%d\n", target
);
8605 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
8606 super
->updates_pending
++;
8609 case update_add_remove_disk
: {
8610 /* we may be able to repair some arrays if disks are
8611 * being added, check the status of add_remove_disk
8612 * if discs has been added.
8614 if (add_remove_disk_update(super
)) {
8615 struct active_array
*a
;
8617 super
->updates_pending
++;
8618 for (a
= st
->arrays
; a
; a
= a
->next
)
8619 a
->check_degraded
= 1;
8624 pr_err("error: unsuported process update type:"
8625 "(type: %d)\n", type
);
8629 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
);
8631 static int imsm_prepare_update(struct supertype
*st
,
8632 struct metadata_update
*update
)
8635 * Allocate space to hold new disk entries, raid-device entries or a new
8636 * mpb if necessary. The manager synchronously waits for updates to
8637 * complete in the monitor, so new mpb buffers allocated here can be
8638 * integrated by the monitor thread without worrying about live pointers
8639 * in the manager thread.
8641 enum imsm_update_type type
;
8642 struct intel_super
*super
= st
->sb
;
8643 struct imsm_super
*mpb
= super
->anchor
;
8647 if (update
->len
< (int)sizeof(type
))
8650 type
= *(enum imsm_update_type
*) update
->buf
;
8653 case update_general_migration_checkpoint
:
8654 if (update
->len
< (int)sizeof(struct imsm_update_general_migration_checkpoint
))
8656 dprintf("imsm: prepare_update() "
8657 "for update_general_migration_checkpoint called\n");
8659 case update_takeover
: {
8660 struct imsm_update_takeover
*u
= (void *)update
->buf
;
8661 if (update
->len
< (int)sizeof(*u
))
8663 if (u
->direction
== R0_TO_R10
) {
8664 void **tail
= (void **)&update
->space_list
;
8665 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subarray
);
8666 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8667 int num_members
= map
->num_members
;
8670 /* allocate memory for added disks */
8671 for (i
= 0; i
< num_members
; i
++) {
8672 size
= sizeof(struct dl
);
8673 space
= xmalloc(size
);
8678 /* allocate memory for new device */
8679 size
= sizeof_imsm_dev(super
->devlist
->dev
, 0) +
8680 (num_members
* sizeof(__u32
));
8681 space
= xmalloc(size
);
8685 len
= disks_to_mpb_size(num_members
* 2);
8690 case update_reshape_container_disks
: {
8691 /* Every raid device in the container is about to
8692 * gain some more devices, and we will enter a
8694 * So each 'imsm_map' will be bigger, and the imsm_vol
8695 * will now hold 2 of them.
8696 * Thus we need new 'struct imsm_dev' allocations sized
8697 * as sizeof_imsm_dev but with more devices in both maps.
8699 struct imsm_update_reshape
*u
= (void *)update
->buf
;
8700 struct intel_dev
*dl
;
8701 void **space_tail
= (void**)&update
->space_list
;
8703 if (update
->len
< (int)sizeof(*u
))
8706 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
8708 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
8709 int size
= sizeof_imsm_dev(dl
->dev
, 1);
8711 if (u
->new_raid_disks
> u
->old_raid_disks
)
8712 size
+= sizeof(__u32
)*2*
8713 (u
->new_raid_disks
- u
->old_raid_disks
);
8720 len
= disks_to_mpb_size(u
->new_raid_disks
);
8721 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
8724 case update_reshape_migration
: {
8725 /* for migration level 0->5 we need to add disks
8726 * so the same as for container operation we will copy
8727 * device to the bigger location.
8728 * in memory prepared device and new disk area are prepared
8729 * for usage in process update
8731 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
8732 struct intel_dev
*id
;
8733 void **space_tail
= (void **)&update
->space_list
;
8736 int current_level
= -1;
8738 if (update
->len
< (int)sizeof(*u
))
8741 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
8743 /* add space for bigger array in update
8745 for (id
= super
->devlist
; id
; id
= id
->next
) {
8746 if (id
->index
== (unsigned)u
->subdev
) {
8747 size
= sizeof_imsm_dev(id
->dev
, 1);
8748 if (u
->new_raid_disks
> u
->old_raid_disks
)
8749 size
+= sizeof(__u32
)*2*
8750 (u
->new_raid_disks
- u
->old_raid_disks
);
8758 if (update
->space_list
== NULL
)
8761 /* add space for disk in update
8763 size
= sizeof(struct dl
);
8769 /* add spare device to update
8771 for (id
= super
->devlist
; id
; id
= id
->next
)
8772 if (id
->index
== (unsigned)u
->subdev
) {
8773 struct imsm_dev
*dev
;
8774 struct imsm_map
*map
;
8776 dev
= get_imsm_dev(super
, u
->subdev
);
8777 map
= get_imsm_map(dev
, MAP_0
);
8778 current_level
= map
->raid_level
;
8781 if ((u
->new_level
== 5) && (u
->new_level
!= current_level
)) {
8782 struct mdinfo
*spares
;
8784 spares
= get_spares_for_grow(st
);
8792 makedev(dev
->disk
.major
,
8794 dl
= get_disk_super(super
,
8797 dl
->index
= u
->old_raid_disks
;
8803 len
= disks_to_mpb_size(u
->new_raid_disks
);
8804 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
8807 case update_size_change
: {
8808 if (update
->len
< (int)sizeof(struct imsm_update_size_change
))
8812 case update_activate_spare
: {
8813 if (update
->len
< (int)sizeof(struct imsm_update_activate_spare
))
8817 case update_create_array
: {
8818 struct imsm_update_create_array
*u
= (void *) update
->buf
;
8819 struct intel_dev
*dv
;
8820 struct imsm_dev
*dev
= &u
->dev
;
8821 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8823 struct disk_info
*inf
;
8827 if (update
->len
< (int)sizeof(*u
))
8830 inf
= get_disk_info(u
);
8831 len
= sizeof_imsm_dev(dev
, 1);
8832 /* allocate a new super->devlist entry */
8833 dv
= xmalloc(sizeof(*dv
));
8834 dv
->dev
= xmalloc(len
);
8837 /* count how many spares will be converted to members */
8838 for (i
= 0; i
< map
->num_members
; i
++) {
8839 dl
= serial_to_dl(inf
[i
].serial
, super
);
8841 /* hmm maybe it failed?, nothing we can do about
8846 if (count_memberships(dl
, super
) == 0)
8849 len
+= activate
* sizeof(struct imsm_disk
);
8852 case update_kill_array
: {
8853 if (update
->len
< (int)sizeof(struct imsm_update_kill_array
))
8857 case update_rename_array
: {
8858 if (update
->len
< (int)sizeof(struct imsm_update_rename_array
))
8862 case update_add_remove_disk
:
8863 /* no update->len needed */
8869 /* check if we need a larger metadata buffer */
8870 if (super
->next_buf
)
8871 buf_len
= super
->next_len
;
8873 buf_len
= super
->len
;
8875 if (__le32_to_cpu(mpb
->mpb_size
) + len
> buf_len
) {
8876 /* ok we need a larger buf than what is currently allocated
8877 * if this allocation fails process_update will notice that
8878 * ->next_len is set and ->next_buf is NULL
8880 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + len
, 512);
8881 if (super
->next_buf
)
8882 free(super
->next_buf
);
8884 super
->next_len
= buf_len
;
8885 if (posix_memalign(&super
->next_buf
, 512, buf_len
) == 0)
8886 memset(super
->next_buf
, 0, buf_len
);
8888 super
->next_buf
= NULL
;
8893 /* must be called while manager is quiesced */
8894 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
8896 struct imsm_super
*mpb
= super
->anchor
;
8898 struct imsm_dev
*dev
;
8899 struct imsm_map
*map
;
8900 int i
, j
, num_members
;
8903 dprintf("%s: deleting device[%d] from imsm_super\n",
8906 /* shift all indexes down one */
8907 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
8908 if (iter
->index
> (int)index
)
8910 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
8911 if (iter
->index
> (int)index
)
8914 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8915 dev
= get_imsm_dev(super
, i
);
8916 map
= get_imsm_map(dev
, MAP_0
);
8917 num_members
= map
->num_members
;
8918 for (j
= 0; j
< num_members
; j
++) {
8919 /* update ord entries being careful not to propagate
8920 * ord-flags to the first map
8922 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_X
);
8924 if (ord_to_idx(ord
) <= index
)
8927 map
= get_imsm_map(dev
, MAP_0
);
8928 set_imsm_ord_tbl_ent(map
, j
, ord_to_idx(ord
- 1));
8929 map
= get_imsm_map(dev
, MAP_1
);
8931 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
8936 super
->updates_pending
++;
8938 struct dl
*dl
= *dlp
;
8940 *dlp
= (*dlp
)->next
;
8941 __free_imsm_disk(dl
);
8944 #endif /* MDASSEMBLE */
8946 static void close_targets(int *targets
, int new_disks
)
8953 for (i
= 0; i
< new_disks
; i
++) {
8954 if (targets
[i
] >= 0) {
8961 static int imsm_get_allowed_degradation(int level
, int raid_disks
,
8962 struct intel_super
*super
,
8963 struct imsm_dev
*dev
)
8969 struct imsm_map
*map
;
8972 ret_val
= raid_disks
/2;
8973 /* check map if all disks pairs not failed
8976 map
= get_imsm_map(dev
, MAP_0
);
8977 for (i
= 0; i
< ret_val
; i
++) {
8978 int degradation
= 0;
8979 if (get_imsm_disk(super
, i
) == NULL
)
8981 if (get_imsm_disk(super
, i
+ 1) == NULL
)
8983 if (degradation
== 2)
8986 map
= get_imsm_map(dev
, MAP_1
);
8987 /* if there is no second map
8988 * result can be returned
8992 /* check degradation in second map
8994 for (i
= 0; i
< ret_val
; i
++) {
8995 int degradation
= 0;
8996 if (get_imsm_disk(super
, i
) == NULL
)
8998 if (get_imsm_disk(super
, i
+ 1) == NULL
)
9000 if (degradation
== 2)
9014 /*******************************************************************************
9015 * Function: open_backup_targets
9016 * Description: Function opens file descriptors for all devices given in
9019 * info : general array info
9020 * raid_disks : number of disks
9021 * raid_fds : table of device's file descriptors
9022 * super : intel super for raid10 degradation check
9023 * dev : intel device for raid10 degradation check
9027 ******************************************************************************/
9028 int open_backup_targets(struct mdinfo
*info
, int raid_disks
, int *raid_fds
,
9029 struct intel_super
*super
, struct imsm_dev
*dev
)
9035 for (i
= 0; i
< raid_disks
; i
++)
9038 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
9041 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
)) {
9042 dprintf("disk is faulty!!\n");
9046 if ((sd
->disk
.raid_disk
>= raid_disks
) ||
9047 (sd
->disk
.raid_disk
< 0))
9050 dn
= map_dev(sd
->disk
.major
,
9052 raid_fds
[sd
->disk
.raid_disk
] = dev_open(dn
, O_RDWR
);
9053 if (raid_fds
[sd
->disk
.raid_disk
] < 0) {
9054 pr_err("cannot open component\n");
9059 /* check if maximum array degradation level is not exceeded
9061 if ((raid_disks
- opened
) >
9062 imsm_get_allowed_degradation(info
->new_level
,
9065 pr_err("Not enough disks can be opened.\n");
9066 close_targets(raid_fds
, raid_disks
);
9072 /*******************************************************************************
9073 * Function: validate_container_imsm
9074 * Description: This routine validates container after assemble,
9075 * eg. if devices in container are under the same controller.
9078 * info : linked list with info about devices used in array
9082 ******************************************************************************/
9083 int validate_container_imsm(struct mdinfo
*info
)
9085 if (check_env("IMSM_NO_PLATFORM"))
9088 struct sys_dev
*idev
;
9089 struct sys_dev
*hba
= NULL
;
9090 struct sys_dev
*intel_devices
= find_intel_devices();
9091 char *dev_path
= devt_to_devpath(makedev(info
->disk
.major
,
9094 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
9095 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
9104 pr_err("WARNING - Cannot detect HBA for device %s!\n",
9105 devid2kname(makedev(info
->disk
.major
, info
->disk
.minor
)));
9109 const struct imsm_orom
*orom
= get_orom_by_device_id(hba
->dev_id
);
9112 for (dev
= info
->next
; dev
; dev
= dev
->next
) {
9113 dev_path
= devt_to_devpath(makedev(dev
->disk
.major
, dev
->disk
.minor
));
9115 struct sys_dev
*hba2
= NULL
;
9116 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
9117 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
9125 const struct imsm_orom
*orom2
= hba2
== NULL
? NULL
:
9126 get_orom_by_device_id(hba2
->dev_id
);
9128 if (hba2
&& hba
->type
!= hba2
->type
) {
9129 pr_err("WARNING - HBAs of devices do not match %s != %s\n",
9130 get_sys_dev_type(hba
->type
), get_sys_dev_type(hba2
->type
));
9134 if (orom
!= orom2
) {
9135 pr_err("WARNING - IMSM container assembled with disks under different HBAs!\n"
9136 " This operation is not supported and can lead to data loss.\n");
9141 pr_err("WARNING - IMSM container assembled with disks under HBAs without IMSM platform support!\n"
9142 " This operation is not supported and can lead to data loss.\n");
9150 /*******************************************************************************
9151 * Function: init_migr_record_imsm
9152 * Description: Function inits imsm migration record
9154 * super : imsm internal array info
9155 * dev : device under migration
9156 * info : general array info to find the smallest device
9159 ******************************************************************************/
9160 void init_migr_record_imsm(struct supertype
*st
, struct imsm_dev
*dev
,
9161 struct mdinfo
*info
)
9163 struct intel_super
*super
= st
->sb
;
9164 struct migr_record
*migr_rec
= super
->migr_rec
;
9166 unsigned long long dsize
, dev_sectors
;
9167 long long unsigned min_dev_sectors
= -1LLU;
9171 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
9172 struct imsm_map
*map_src
= get_imsm_map(dev
, MAP_1
);
9173 unsigned long long num_migr_units
;
9174 unsigned long long array_blocks
;
9176 memset(migr_rec
, 0, sizeof(struct migr_record
));
9177 migr_rec
->family_num
= __cpu_to_le32(super
->anchor
->family_num
);
9179 /* only ascending reshape supported now */
9180 migr_rec
->ascending_migr
= __cpu_to_le32(1);
9182 migr_rec
->dest_depth_per_unit
= GEN_MIGR_AREA_SIZE
/
9183 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
9184 migr_rec
->dest_depth_per_unit
*=
9185 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
9186 new_data_disks
= imsm_num_data_members(dev
, MAP_0
);
9187 migr_rec
->blocks_per_unit
=
9188 __cpu_to_le32(migr_rec
->dest_depth_per_unit
* new_data_disks
);
9189 migr_rec
->dest_depth_per_unit
=
9190 __cpu_to_le32(migr_rec
->dest_depth_per_unit
);
9191 array_blocks
= info
->component_size
* new_data_disks
;
9193 array_blocks
/ __le32_to_cpu(migr_rec
->blocks_per_unit
);
9195 if (array_blocks
% __le32_to_cpu(migr_rec
->blocks_per_unit
))
9197 migr_rec
->num_migr_units
= __cpu_to_le32(num_migr_units
);
9199 migr_rec
->post_migr_vol_cap
= dev
->size_low
;
9200 migr_rec
->post_migr_vol_cap_hi
= dev
->size_high
;
9202 /* Find the smallest dev */
9203 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
9204 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
9205 fd
= dev_open(nm
, O_RDONLY
);
9208 get_dev_size(fd
, NULL
, &dsize
);
9209 dev_sectors
= dsize
/ 512;
9210 if (dev_sectors
< min_dev_sectors
)
9211 min_dev_sectors
= dev_sectors
;
9214 migr_rec
->ckpt_area_pba
= __cpu_to_le32(min_dev_sectors
-
9215 RAID_DISK_RESERVED_BLOCKS_IMSM_HI
);
9217 write_imsm_migr_rec(st
);
9222 /*******************************************************************************
9223 * Function: save_backup_imsm
9224 * Description: Function saves critical data stripes to Migration Copy Area
9225 * and updates the current migration unit status.
9226 * Use restore_stripes() to form a destination stripe,
9227 * and to write it to the Copy Area.
9229 * st : supertype information
9230 * dev : imsm device that backup is saved for
9231 * info : general array info
9232 * buf : input buffer
9233 * length : length of data to backup (blocks_per_unit)
9237 ******************************************************************************/
9238 int save_backup_imsm(struct supertype
*st
,
9239 struct imsm_dev
*dev
,
9240 struct mdinfo
*info
,
9245 struct intel_super
*super
= st
->sb
;
9246 unsigned long long *target_offsets
= NULL
;
9247 int *targets
= NULL
;
9249 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
9250 int new_disks
= map_dest
->num_members
;
9251 int dest_layout
= 0;
9253 unsigned long long start
;
9254 int data_disks
= imsm_num_data_members(dev
, MAP_0
);
9256 targets
= xmalloc(new_disks
* sizeof(int));
9258 for (i
= 0; i
< new_disks
; i
++)
9261 target_offsets
= xcalloc(new_disks
, sizeof(unsigned long long));
9263 start
= info
->reshape_progress
* 512;
9264 for (i
= 0; i
< new_disks
; i
++) {
9265 target_offsets
[i
] = (unsigned long long)
9266 __le32_to_cpu(super
->migr_rec
->ckpt_area_pba
) * 512;
9267 /* move back copy area adderss, it will be moved forward
9268 * in restore_stripes() using start input variable
9270 target_offsets
[i
] -= start
/data_disks
;
9273 if (open_backup_targets(info
, new_disks
, targets
,
9277 dest_layout
= imsm_level_to_layout(map_dest
->raid_level
);
9278 dest_chunk
= __le16_to_cpu(map_dest
->blocks_per_strip
) * 512;
9280 if (restore_stripes(targets
, /* list of dest devices */
9281 target_offsets
, /* migration record offsets */
9284 map_dest
->raid_level
,
9286 -1, /* source backup file descriptor */
9287 0, /* input buf offset
9288 * always 0 buf is already offseted */
9292 pr_err("Error restoring stripes\n");
9300 close_targets(targets
, new_disks
);
9303 free(target_offsets
);
9308 /*******************************************************************************
9309 * Function: save_checkpoint_imsm
9310 * Description: Function called for current unit status update
9311 * in the migration record. It writes it to disk.
9313 * super : imsm internal array info
9314 * info : general array info
9318 * 2: failure, means no valid migration record
9319 * / no general migration in progress /
9320 ******************************************************************************/
9321 int save_checkpoint_imsm(struct supertype
*st
, struct mdinfo
*info
, int state
)
9323 struct intel_super
*super
= st
->sb
;
9324 unsigned long long blocks_per_unit
;
9325 unsigned long long curr_migr_unit
;
9327 if (load_imsm_migr_rec(super
, info
) != 0) {
9328 dprintf("imsm: ERROR: Cannot read migration record "
9329 "for checkpoint save.\n");
9333 blocks_per_unit
= __le32_to_cpu(super
->migr_rec
->blocks_per_unit
);
9334 if (blocks_per_unit
== 0) {
9335 dprintf("imsm: no migration in progress.\n");
9338 curr_migr_unit
= info
->reshape_progress
/ blocks_per_unit
;
9339 /* check if array is alligned to copy area
9340 * if it is not alligned, add one to current migration unit value
9341 * this can happend on array reshape finish only
9343 if (info
->reshape_progress
% blocks_per_unit
)
9346 super
->migr_rec
->curr_migr_unit
=
9347 __cpu_to_le32(curr_migr_unit
);
9348 super
->migr_rec
->rec_status
= __cpu_to_le32(state
);
9349 super
->migr_rec
->dest_1st_member_lba
=
9350 __cpu_to_le32(curr_migr_unit
*
9351 __le32_to_cpu(super
->migr_rec
->dest_depth_per_unit
));
9352 if (write_imsm_migr_rec(st
) < 0) {
9353 dprintf("imsm: Cannot write migration record "
9354 "outside backup area\n");
9361 /*******************************************************************************
9362 * Function: recover_backup_imsm
9363 * Description: Function recovers critical data from the Migration Copy Area
9364 * while assembling an array.
9366 * super : imsm internal array info
9367 * info : general array info
9369 * 0 : success (or there is no data to recover)
9371 ******************************************************************************/
9372 int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
)
9374 struct intel_super
*super
= st
->sb
;
9375 struct migr_record
*migr_rec
= super
->migr_rec
;
9376 struct imsm_map
*map_dest
= NULL
;
9377 struct intel_dev
*id
= NULL
;
9378 unsigned long long read_offset
;
9379 unsigned long long write_offset
;
9381 int *targets
= NULL
;
9382 int new_disks
, i
, err
;
9385 unsigned long curr_migr_unit
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
9386 unsigned long num_migr_units
= __le32_to_cpu(migr_rec
->num_migr_units
);
9388 int skipped_disks
= 0;
9390 err
= sysfs_get_str(info
, NULL
, "array_state", (char *)buffer
, 20);
9394 /* recover data only during assemblation */
9395 if (strncmp(buffer
, "inactive", 8) != 0)
9397 /* no data to recover */
9398 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
9400 if (curr_migr_unit
>= num_migr_units
)
9403 /* find device during reshape */
9404 for (id
= super
->devlist
; id
; id
= id
->next
)
9405 if (is_gen_migration(id
->dev
))
9410 map_dest
= get_imsm_map(id
->dev
, MAP_0
);
9411 new_disks
= map_dest
->num_members
;
9413 read_offset
= (unsigned long long)
9414 __le32_to_cpu(migr_rec
->ckpt_area_pba
) * 512;
9416 write_offset
= ((unsigned long long)
9417 __le32_to_cpu(migr_rec
->dest_1st_member_lba
) +
9418 pba_of_lba0(map_dest
)) * 512;
9420 unit_len
= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
9421 if (posix_memalign((void **)&buf
, 512, unit_len
) != 0)
9423 targets
= xcalloc(new_disks
, sizeof(int));
9425 if (open_backup_targets(info
, new_disks
, targets
, super
, id
->dev
)) {
9426 pr_err("Cannot open some devices belonging to array.\n");
9430 for (i
= 0; i
< new_disks
; i
++) {
9431 if (targets
[i
] < 0) {
9435 if (lseek64(targets
[i
], read_offset
, SEEK_SET
) < 0) {
9436 pr_err("Cannot seek to block: %s\n",
9441 if ((unsigned)read(targets
[i
], buf
, unit_len
) != unit_len
) {
9442 pr_err("Cannot read copy area block: %s\n",
9447 if (lseek64(targets
[i
], write_offset
, SEEK_SET
) < 0) {
9448 pr_err("Cannot seek to block: %s\n",
9453 if ((unsigned)write(targets
[i
], buf
, unit_len
) != unit_len
) {
9454 pr_err("Cannot restore block: %s\n",
9461 if (skipped_disks
> imsm_get_allowed_degradation(info
->new_level
,
9465 pr_err("Cannot restore data from backup."
9466 " Too many failed disks\n");
9470 if (save_checkpoint_imsm(st
, info
, UNIT_SRC_NORMAL
)) {
9471 /* ignore error == 2, this can mean end of reshape here
9473 dprintf("imsm: Cannot write checkpoint to "
9474 "migration record (UNIT_SRC_NORMAL) during restart\n");
9480 for (i
= 0; i
< new_disks
; i
++)
9489 static char disk_by_path
[] = "/dev/disk/by-path/";
9491 static const char *imsm_get_disk_controller_domain(const char *path
)
9493 char disk_path
[PATH_MAX
];
9497 strcpy(disk_path
, disk_by_path
);
9498 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
9499 if (stat(disk_path
, &st
) == 0) {
9500 struct sys_dev
* hba
;
9503 path
= devt_to_devpath(st
.st_rdev
);
9506 hba
= find_disk_attached_hba(-1, path
);
9507 if (hba
&& hba
->type
== SYS_DEV_SAS
)
9509 else if (hba
&& hba
->type
== SYS_DEV_SATA
)
9513 dprintf("path: %s hba: %s attached: %s\n",
9514 path
, (hba
) ? hba
->path
: "NULL", drv
);
9520 static char *imsm_find_array_devnm_by_subdev(int subdev
, char *container
)
9522 static char devnm
[32];
9523 char subdev_name
[20];
9524 struct mdstat_ent
*mdstat
;
9526 sprintf(subdev_name
, "%d", subdev
);
9527 mdstat
= mdstat_by_subdev(subdev_name
, container
);
9531 strcpy(devnm
, mdstat
->devnm
);
9532 free_mdstat(mdstat
);
9536 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
9537 struct geo_params
*geo
,
9538 int *old_raid_disks
,
9541 /* currently we only support increasing the number of devices
9542 * for a container. This increases the number of device for each
9543 * member array. They must all be RAID0 or RAID5.
9546 struct mdinfo
*info
, *member
;
9547 int devices_that_can_grow
= 0;
9549 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): "
9550 "st->devnm = (%s)\n", st
->devnm
);
9552 if (geo
->size
> 0 ||
9553 geo
->level
!= UnSet
||
9554 geo
->layout
!= UnSet
||
9555 geo
->chunksize
!= 0 ||
9556 geo
->raid_disks
== UnSet
) {
9557 dprintf("imsm: Container operation is allowed for "
9558 "raid disks number change only.\n");
9562 if (direction
== ROLLBACK_METADATA_CHANGES
) {
9563 dprintf("imsm: Metadata changes rollback is not supported for "
9564 "container operation.\n");
9568 info
= container_content_imsm(st
, NULL
);
9569 for (member
= info
; member
; member
= member
->next
) {
9572 dprintf("imsm: checking device_num: %i\n",
9573 member
->container_member
);
9575 if (geo
->raid_disks
<= member
->array
.raid_disks
) {
9576 /* we work on container for Online Capacity Expansion
9577 * only so raid_disks has to grow
9579 dprintf("imsm: for container operation raid disks "
9580 "increase is required\n");
9584 if ((info
->array
.level
!= 0) &&
9585 (info
->array
.level
!= 5)) {
9586 /* we cannot use this container with other raid level
9588 dprintf("imsm: for container operation wrong"
9589 " raid level (%i) detected\n",
9593 /* check for platform support
9594 * for this raid level configuration
9596 struct intel_super
*super
= st
->sb
;
9597 if (!is_raid_level_supported(super
->orom
,
9598 member
->array
.level
,
9600 dprintf("platform does not support raid%d with"
9604 geo
->raid_disks
> 1 ? "s" : "");
9607 /* check if component size is aligned to chunk size
9609 if (info
->component_size
%
9610 (info
->array
.chunk_size
/512)) {
9611 dprintf("Component size is not aligned to "
9617 if (*old_raid_disks
&&
9618 info
->array
.raid_disks
!= *old_raid_disks
)
9620 *old_raid_disks
= info
->array
.raid_disks
;
9622 /* All raid5 and raid0 volumes in container
9623 * have to be ready for Online Capacity Expansion
9624 * so they need to be assembled. We have already
9625 * checked that no recovery etc is happening.
9627 result
= imsm_find_array_devnm_by_subdev(member
->container_member
,
9628 st
->container_devnm
);
9629 if (result
== NULL
) {
9630 dprintf("imsm: cannot find array\n");
9633 devices_that_can_grow
++;
9636 if (!member
&& devices_that_can_grow
)
9640 dprintf("\tContainer operation allowed\n");
9642 dprintf("\tError: %i\n", ret_val
);
9647 /* Function: get_spares_for_grow
9648 * Description: Allocates memory and creates list of spare devices
9649 * avaliable in container. Checks if spare drive size is acceptable.
9650 * Parameters: Pointer to the supertype structure
9651 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
9654 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
9656 unsigned long long min_size
= min_acceptable_spare_size_imsm(st
);
9657 return container_choose_spares(st
, min_size
, NULL
, NULL
, NULL
, 0);
9660 /******************************************************************************
9661 * function: imsm_create_metadata_update_for_reshape
9662 * Function creates update for whole IMSM container.
9664 ******************************************************************************/
9665 static int imsm_create_metadata_update_for_reshape(
9666 struct supertype
*st
,
9667 struct geo_params
*geo
,
9669 struct imsm_update_reshape
**updatep
)
9671 struct intel_super
*super
= st
->sb
;
9672 struct imsm_super
*mpb
= super
->anchor
;
9673 int update_memory_size
= 0;
9674 struct imsm_update_reshape
*u
= NULL
;
9675 struct mdinfo
*spares
= NULL
;
9677 int delta_disks
= 0;
9680 dprintf("imsm_update_metadata_for_reshape(enter) raid_disks = %i\n",
9683 delta_disks
= geo
->raid_disks
- old_raid_disks
;
9685 /* size of all update data without anchor */
9686 update_memory_size
= sizeof(struct imsm_update_reshape
);
9688 /* now add space for spare disks that we need to add. */
9689 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
9691 u
= xcalloc(1, update_memory_size
);
9692 u
->type
= update_reshape_container_disks
;
9693 u
->old_raid_disks
= old_raid_disks
;
9694 u
->new_raid_disks
= geo
->raid_disks
;
9696 /* now get spare disks list
9698 spares
= get_spares_for_grow(st
);
9701 || delta_disks
> spares
->array
.spare_disks
) {
9702 pr_err("imsm: ERROR: Cannot get spare devices "
9703 "for %s.\n", geo
->dev_name
);
9708 /* we have got spares
9709 * update disk list in imsm_disk list table in anchor
9711 dprintf("imsm: %i spares are available.\n\n",
9712 spares
->array
.spare_disks
);
9715 for (i
= 0; i
< delta_disks
; i
++) {
9720 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
9722 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
9723 dl
->index
= mpb
->num_disks
;
9733 dprintf("imsm: reshape update preparation :");
9734 if (i
== delta_disks
) {
9737 return update_memory_size
;
9740 dprintf(" Error\n");
9745 /******************************************************************************
9746 * function: imsm_create_metadata_update_for_size_change()
9747 * Creates update for IMSM array for array size change.
9749 ******************************************************************************/
9750 static int imsm_create_metadata_update_for_size_change(
9751 struct supertype
*st
,
9752 struct geo_params
*geo
,
9753 struct imsm_update_size_change
**updatep
)
9755 struct intel_super
*super
= st
->sb
;
9756 int update_memory_size
= 0;
9757 struct imsm_update_size_change
*u
= NULL
;
9759 dprintf("imsm_create_metadata_update_for_size_change(enter)"
9760 " New size = %llu\n", geo
->size
);
9762 /* size of all update data without anchor */
9763 update_memory_size
= sizeof(struct imsm_update_size_change
);
9765 u
= xcalloc(1, update_memory_size
);
9766 u
->type
= update_size_change
;
9767 u
->subdev
= super
->current_vol
;
9768 u
->new_size
= geo
->size
;
9770 dprintf("imsm: reshape update preparation : OK\n");
9773 return update_memory_size
;
9776 /******************************************************************************
9777 * function: imsm_create_metadata_update_for_migration()
9778 * Creates update for IMSM array.
9780 ******************************************************************************/
9781 static int imsm_create_metadata_update_for_migration(
9782 struct supertype
*st
,
9783 struct geo_params
*geo
,
9784 struct imsm_update_reshape_migration
**updatep
)
9786 struct intel_super
*super
= st
->sb
;
9787 int update_memory_size
= 0;
9788 struct imsm_update_reshape_migration
*u
= NULL
;
9789 struct imsm_dev
*dev
;
9790 int previous_level
= -1;
9792 dprintf("imsm_create_metadata_update_for_migration(enter)"
9793 " New Level = %i\n", geo
->level
);
9795 /* size of all update data without anchor */
9796 update_memory_size
= sizeof(struct imsm_update_reshape_migration
);
9798 u
= xcalloc(1, update_memory_size
);
9799 u
->type
= update_reshape_migration
;
9800 u
->subdev
= super
->current_vol
;
9801 u
->new_level
= geo
->level
;
9802 u
->new_layout
= geo
->layout
;
9803 u
->new_raid_disks
= u
->old_raid_disks
= geo
->raid_disks
;
9804 u
->new_disks
[0] = -1;
9805 u
->new_chunksize
= -1;
9807 dev
= get_imsm_dev(super
, u
->subdev
);
9809 struct imsm_map
*map
;
9811 map
= get_imsm_map(dev
, MAP_0
);
9813 int current_chunk_size
=
9814 __le16_to_cpu(map
->blocks_per_strip
) / 2;
9816 if (geo
->chunksize
!= current_chunk_size
) {
9817 u
->new_chunksize
= geo
->chunksize
/ 1024;
9819 "chunk size change from %i to %i\n",
9820 current_chunk_size
, u
->new_chunksize
);
9822 previous_level
= map
->raid_level
;
9825 if ((geo
->level
== 5) && (previous_level
== 0)) {
9826 struct mdinfo
*spares
= NULL
;
9828 u
->new_raid_disks
++;
9829 spares
= get_spares_for_grow(st
);
9830 if ((spares
== NULL
) || (spares
->array
.spare_disks
< 1)) {
9833 update_memory_size
= 0;
9834 dprintf("error: cannot get spare device "
9835 "for requested migration");
9840 dprintf("imsm: reshape update preparation : OK\n");
9843 return update_memory_size
;
9846 static void imsm_update_metadata_locally(struct supertype
*st
,
9849 struct metadata_update mu
;
9854 mu
.space_list
= NULL
;
9856 if (imsm_prepare_update(st
, &mu
))
9857 imsm_process_update(st
, &mu
);
9859 while (mu
.space_list
) {
9860 void **space
= mu
.space_list
;
9861 mu
.space_list
= *space
;
9866 /***************************************************************************
9867 * Function: imsm_analyze_change
9868 * Description: Function analyze change for single volume
9869 * and validate if transition is supported
9870 * Parameters: Geometry parameters, supertype structure,
9871 * metadata change direction (apply/rollback)
9872 * Returns: Operation type code on success, -1 if fail
9873 ****************************************************************************/
9874 enum imsm_reshape_type
imsm_analyze_change(struct supertype
*st
,
9875 struct geo_params
*geo
,
9882 /* number of added/removed disks in operation result */
9883 int devNumChange
= 0;
9884 /* imsm compatible layout value for array geometry verification */
9885 int imsm_layout
= -1;
9887 struct imsm_dev
*dev
;
9888 struct intel_super
*super
;
9889 unsigned long long current_size
;
9890 unsigned long long free_size
;
9891 unsigned long long max_size
;
9894 getinfo_super_imsm_volume(st
, &info
, NULL
);
9895 if ((geo
->level
!= info
.array
.level
) &&
9896 (geo
->level
>= 0) &&
9897 (geo
->level
!= UnSet
)) {
9898 switch (info
.array
.level
) {
9900 if (geo
->level
== 5) {
9901 change
= CH_MIGRATION
;
9902 if (geo
->layout
!= ALGORITHM_LEFT_ASYMMETRIC
) {
9903 pr_err("Error. Requested Layout "
9904 "not supported (left-asymmetric layout "
9905 "is supported only)!\n");
9907 goto analyse_change_exit
;
9909 imsm_layout
= geo
->layout
;
9911 devNumChange
= 1; /* parity disk added */
9912 } else if (geo
->level
== 10) {
9913 change
= CH_TAKEOVER
;
9915 devNumChange
= 2; /* two mirrors added */
9916 imsm_layout
= 0x102; /* imsm supported layout */
9921 if (geo
->level
== 0) {
9922 change
= CH_TAKEOVER
;
9924 devNumChange
= -(geo
->raid_disks
/2);
9925 imsm_layout
= 0; /* imsm raid0 layout */
9930 pr_err("Error. Level Migration from %d to %d "
9932 info
.array
.level
, geo
->level
);
9933 goto analyse_change_exit
;
9936 geo
->level
= info
.array
.level
;
9938 if ((geo
->layout
!= info
.array
.layout
)
9939 && ((geo
->layout
!= UnSet
) && (geo
->layout
!= -1))) {
9940 change
= CH_MIGRATION
;
9941 if ((info
.array
.layout
== 0)
9942 && (info
.array
.level
== 5)
9943 && (geo
->layout
== 5)) {
9944 /* reshape 5 -> 4 */
9945 } else if ((info
.array
.layout
== 5)
9946 && (info
.array
.level
== 5)
9947 && (geo
->layout
== 0)) {
9948 /* reshape 4 -> 5 */
9952 pr_err("Error. Layout Migration from %d to %d "
9954 info
.array
.layout
, geo
->layout
);
9956 goto analyse_change_exit
;
9959 geo
->layout
= info
.array
.layout
;
9960 if (imsm_layout
== -1)
9961 imsm_layout
= info
.array
.layout
;
9964 if ((geo
->chunksize
> 0) && (geo
->chunksize
!= UnSet
)
9965 && (geo
->chunksize
!= info
.array
.chunk_size
))
9966 change
= CH_MIGRATION
;
9968 geo
->chunksize
= info
.array
.chunk_size
;
9970 chunk
= geo
->chunksize
/ 1024;
9973 dev
= get_imsm_dev(super
, super
->current_vol
);
9974 data_disks
= imsm_num_data_members(dev
, MAP_0
);
9975 /* compute current size per disk member
9977 current_size
= info
.custom_array_size
/ data_disks
;
9979 if ((geo
->size
> 0) && (geo
->size
!= MAX_SIZE
)) {
9980 /* align component size
9982 geo
->size
= imsm_component_size_aligment_check(
9983 get_imsm_raid_level(dev
->vol
.map
),
9986 if (geo
->size
== 0) {
9987 pr_err("Error. Size expansion is " \
9988 "supported only (current size is %llu, " \
9989 "requested size /rounded/ is 0).\n",
9991 goto analyse_change_exit
;
9995 if ((current_size
!= geo
->size
) && (geo
->size
> 0)) {
9997 pr_err("Error. Size change should be the only "
9998 "one at a time.\n");
10000 goto analyse_change_exit
;
10002 if ((super
->current_vol
+ 1) != super
->anchor
->num_raid_devs
) {
10003 pr_err("Error. The last volume in container "
10004 "can be expanded only (%i/%s).\n",
10005 super
->current_vol
, st
->devnm
);
10006 goto analyse_change_exit
;
10008 /* check the maximum available size
10010 rv
= imsm_get_free_size(st
, dev
->vol
.map
->num_members
,
10011 0, chunk
, &free_size
);
10013 /* Cannot find maximum available space
10017 max_size
= free_size
+ current_size
;
10018 /* align component size
10020 max_size
= imsm_component_size_aligment_check(
10021 get_imsm_raid_level(dev
->vol
.map
),
10025 if (geo
->size
== MAX_SIZE
) {
10026 /* requested size change to the maximum available size
10028 if (max_size
== 0) {
10029 pr_err("Error. Cannot find "
10030 "maximum available space.\n");
10032 goto analyse_change_exit
;
10034 geo
->size
= max_size
;
10037 if ((direction
== ROLLBACK_METADATA_CHANGES
)) {
10038 /* accept size for rollback only
10041 /* round size due to metadata compatibility
10043 geo
->size
= (geo
->size
>> SECT_PER_MB_SHIFT
)
10044 << SECT_PER_MB_SHIFT
;
10045 dprintf("Prepare update for size change to %llu\n",
10047 if (current_size
>= geo
->size
) {
10048 pr_err("Error. Size expansion is "
10049 "supported only (current size is %llu, "
10050 "requested size /rounded/ is %llu).\n",
10051 current_size
, geo
->size
);
10052 goto analyse_change_exit
;
10054 if (max_size
&& geo
->size
> max_size
) {
10055 pr_err("Error. Requested size is larger "
10056 "than maximum available size (maximum "
10057 "available size is %llu, "
10058 "requested size /rounded/ is %llu).\n",
10059 max_size
, geo
->size
);
10060 goto analyse_change_exit
;
10063 geo
->size
*= data_disks
;
10064 geo
->raid_disks
= dev
->vol
.map
->num_members
;
10065 change
= CH_ARRAY_SIZE
;
10067 if (!validate_geometry_imsm(st
,
10070 geo
->raid_disks
+ devNumChange
,
10072 geo
->size
, INVALID_SECTORS
,
10077 struct intel_super
*super
= st
->sb
;
10078 struct imsm_super
*mpb
= super
->anchor
;
10080 if (mpb
->num_raid_devs
> 1) {
10081 pr_err("Error. Cannot perform operation on %s"
10082 "- for this operation it MUST be single "
10083 "array in container\n",
10089 analyse_change_exit
:
10090 if ((direction
== ROLLBACK_METADATA_CHANGES
) &&
10091 ((change
== CH_MIGRATION
) || (change
== CH_TAKEOVER
))) {
10092 dprintf("imsm: Metadata changes rollback is not supported for "
10093 "migration and takeover operations.\n");
10099 int imsm_takeover(struct supertype
*st
, struct geo_params
*geo
)
10101 struct intel_super
*super
= st
->sb
;
10102 struct imsm_update_takeover
*u
;
10104 u
= xmalloc(sizeof(struct imsm_update_takeover
));
10106 u
->type
= update_takeover
;
10107 u
->subarray
= super
->current_vol
;
10109 /* 10->0 transition */
10110 if (geo
->level
== 0)
10111 u
->direction
= R10_TO_R0
;
10113 /* 0->10 transition */
10114 if (geo
->level
== 10)
10115 u
->direction
= R0_TO_R10
;
10117 /* update metadata locally */
10118 imsm_update_metadata_locally(st
, u
,
10119 sizeof(struct imsm_update_takeover
));
10120 /* and possibly remotely */
10121 if (st
->update_tail
)
10122 append_metadata_update(st
, u
,
10123 sizeof(struct imsm_update_takeover
));
10130 static int imsm_reshape_super(struct supertype
*st
, unsigned long long size
,
10132 int layout
, int chunksize
, int raid_disks
,
10133 int delta_disks
, char *backup
, char *dev
,
10134 int direction
, int verbose
)
10137 struct geo_params geo
;
10139 dprintf("imsm: reshape_super called.\n");
10141 memset(&geo
, 0, sizeof(struct geo_params
));
10143 geo
.dev_name
= dev
;
10144 strcpy(geo
.devnm
, st
->devnm
);
10147 geo
.layout
= layout
;
10148 geo
.chunksize
= chunksize
;
10149 geo
.raid_disks
= raid_disks
;
10150 if (delta_disks
!= UnSet
)
10151 geo
.raid_disks
+= delta_disks
;
10153 dprintf("\tfor level : %i\n", geo
.level
);
10154 dprintf("\tfor raid_disks : %i\n", geo
.raid_disks
);
10156 if (experimental() == 0)
10159 if (strcmp(st
->container_devnm
, st
->devnm
) == 0) {
10160 /* On container level we can only increase number of devices. */
10161 dprintf("imsm: info: Container operation\n");
10162 int old_raid_disks
= 0;
10164 if (imsm_reshape_is_allowed_on_container(
10165 st
, &geo
, &old_raid_disks
, direction
)) {
10166 struct imsm_update_reshape
*u
= NULL
;
10169 len
= imsm_create_metadata_update_for_reshape(
10170 st
, &geo
, old_raid_disks
, &u
);
10173 dprintf("imsm: Cannot prepare update\n");
10174 goto exit_imsm_reshape_super
;
10178 /* update metadata locally */
10179 imsm_update_metadata_locally(st
, u
, len
);
10180 /* and possibly remotely */
10181 if (st
->update_tail
)
10182 append_metadata_update(st
, u
, len
);
10187 pr_err("(imsm) Operation "
10188 "is not allowed on this container\n");
10191 /* On volume level we support following operations
10192 * - takeover: raid10 -> raid0; raid0 -> raid10
10193 * - chunk size migration
10194 * - migration: raid5 -> raid0; raid0 -> raid5
10196 struct intel_super
*super
= st
->sb
;
10197 struct intel_dev
*dev
= super
->devlist
;
10199 dprintf("imsm: info: Volume operation\n");
10200 /* find requested device */
10203 imsm_find_array_devnm_by_subdev(
10204 dev
->index
, st
->container_devnm
);
10205 if (devnm
&& strcmp(devnm
, geo
.devnm
) == 0)
10210 pr_err("Cannot find %s (%s) subarray\n",
10211 geo
.dev_name
, geo
.devnm
);
10212 goto exit_imsm_reshape_super
;
10214 super
->current_vol
= dev
->index
;
10215 change
= imsm_analyze_change(st
, &geo
, direction
);
10218 ret_val
= imsm_takeover(st
, &geo
);
10220 case CH_MIGRATION
: {
10221 struct imsm_update_reshape_migration
*u
= NULL
;
10223 imsm_create_metadata_update_for_migration(
10227 "Cannot prepare update\n");
10231 /* update metadata locally */
10232 imsm_update_metadata_locally(st
, u
, len
);
10233 /* and possibly remotely */
10234 if (st
->update_tail
)
10235 append_metadata_update(st
, u
, len
);
10240 case CH_ARRAY_SIZE
: {
10241 struct imsm_update_size_change
*u
= NULL
;
10243 imsm_create_metadata_update_for_size_change(
10247 "Cannot prepare update\n");
10251 /* update metadata locally */
10252 imsm_update_metadata_locally(st
, u
, len
);
10253 /* and possibly remotely */
10254 if (st
->update_tail
)
10255 append_metadata_update(st
, u
, len
);
10265 exit_imsm_reshape_super
:
10266 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
10270 /*******************************************************************************
10271 * Function: wait_for_reshape_imsm
10272 * Description: Function writes new sync_max value and waits until
10273 * reshape process reach new position
10275 * sra : general array info
10276 * ndata : number of disks in new array's layout
10279 * 1 : there is no reshape in progress,
10281 ******************************************************************************/
10282 int wait_for_reshape_imsm(struct mdinfo
*sra
, int ndata
)
10284 int fd
= sysfs_get_fd(sra
, NULL
, "sync_completed");
10285 unsigned long long completed
;
10286 /* to_complete : new sync_max position */
10287 unsigned long long to_complete
= sra
->reshape_progress
;
10288 unsigned long long position_to_set
= to_complete
/ ndata
;
10291 dprintf("imsm: wait_for_reshape_imsm() "
10292 "cannot open reshape_position\n");
10296 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
10297 dprintf("imsm: wait_for_reshape_imsm() "
10298 "cannot read reshape_position (no reshape in progres)\n");
10303 if (completed
> position_to_set
) {
10304 dprintf("imsm: wait_for_reshape_imsm() "
10305 "wrong next position to set %llu (%llu)\n",
10306 to_complete
, position_to_set
);
10310 dprintf("Position set: %llu\n", position_to_set
);
10311 if (sysfs_set_num(sra
, NULL
, "sync_max",
10312 position_to_set
) != 0) {
10313 dprintf("imsm: wait_for_reshape_imsm() "
10314 "cannot set reshape position to %llu\n",
10322 sysfs_wait(fd
, NULL
);
10323 if (sysfs_get_str(sra
, NULL
, "sync_action",
10325 strncmp(action
, "reshape", 7) != 0)
10327 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
10328 dprintf("imsm: wait_for_reshape_imsm() "
10329 "cannot read reshape_position (in loop)\n");
10333 } while (completed
< position_to_set
);
10339 /*******************************************************************************
10340 * Function: check_degradation_change
10341 * Description: Check that array hasn't become failed.
10343 * info : for sysfs access
10344 * sources : source disks descriptors
10345 * degraded: previous degradation level
10347 * degradation level
10348 ******************************************************************************/
10349 int check_degradation_change(struct mdinfo
*info
,
10353 unsigned long long new_degraded
;
10356 rv
= sysfs_get_ll(info
, NULL
, "degraded", &new_degraded
);
10357 if ((rv
== -1) || (new_degraded
!= (unsigned long long)degraded
)) {
10358 /* check each device to ensure it is still working */
10361 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
10362 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
10364 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
10366 if (sysfs_get_str(info
,
10367 sd
, "state", sbuf
, 20) < 0 ||
10368 strstr(sbuf
, "faulty") ||
10369 strstr(sbuf
, "in_sync") == NULL
) {
10370 /* this device is dead */
10371 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
10372 if (sd
->disk
.raid_disk
>= 0 &&
10373 sources
[sd
->disk
.raid_disk
] >= 0) {
10375 sd
->disk
.raid_disk
]);
10376 sources
[sd
->disk
.raid_disk
] =
10385 return new_degraded
;
10388 /*******************************************************************************
10389 * Function: imsm_manage_reshape
10390 * Description: Function finds array under reshape and it manages reshape
10391 * process. It creates stripes backups (if required) and sets
10394 * afd : Backup handle (nattive) - not used
10395 * sra : general array info
10396 * reshape : reshape parameters - not used
10397 * st : supertype structure
10398 * blocks : size of critical section [blocks]
10399 * fds : table of source device descriptor
10400 * offsets : start of array (offest per devices)
10402 * destfd : table of destination device descriptor
10403 * destoffsets : table of destination offsets (per device)
10405 * 1 : success, reshape is done
10407 ******************************************************************************/
10408 static int imsm_manage_reshape(
10409 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
10410 struct supertype
*st
, unsigned long backup_blocks
,
10411 int *fds
, unsigned long long *offsets
,
10412 int dests
, int *destfd
, unsigned long long *destoffsets
)
10415 struct intel_super
*super
= st
->sb
;
10416 struct intel_dev
*dv
= NULL
;
10417 struct imsm_dev
*dev
= NULL
;
10418 struct imsm_map
*map_src
;
10419 int migr_vol_qan
= 0;
10420 int ndata
, odata
; /* [bytes] */
10421 int chunk
; /* [bytes] */
10422 struct migr_record
*migr_rec
;
10424 unsigned int buf_size
; /* [bytes] */
10425 unsigned long long max_position
; /* array size [bytes] */
10426 unsigned long long next_step
; /* [blocks]/[bytes] */
10427 unsigned long long old_data_stripe_length
;
10428 unsigned long long start_src
; /* [bytes] */
10429 unsigned long long start
; /* [bytes] */
10430 unsigned long long start_buf_shift
; /* [bytes] */
10432 int source_layout
= 0;
10434 if (!fds
|| !offsets
|| !sra
)
10437 /* Find volume during the reshape */
10438 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
10439 if (dv
->dev
->vol
.migr_type
== MIGR_GEN_MIGR
10440 && dv
->dev
->vol
.migr_state
== 1) {
10445 /* Only one volume can migrate at the same time */
10446 if (migr_vol_qan
!= 1) {
10447 pr_err(": %s", migr_vol_qan
?
10448 "Number of migrating volumes greater than 1\n" :
10449 "There is no volume during migrationg\n");
10453 map_src
= get_imsm_map(dev
, MAP_1
);
10454 if (map_src
== NULL
)
10457 ndata
= imsm_num_data_members(dev
, MAP_0
);
10458 odata
= imsm_num_data_members(dev
, MAP_1
);
10460 chunk
= __le16_to_cpu(map_src
->blocks_per_strip
) * 512;
10461 old_data_stripe_length
= odata
* chunk
;
10463 migr_rec
= super
->migr_rec
;
10465 /* initialize migration record for start condition */
10466 if (sra
->reshape_progress
== 0)
10467 init_migr_record_imsm(st
, dev
, sra
);
10469 if (__le32_to_cpu(migr_rec
->rec_status
) != UNIT_SRC_NORMAL
) {
10470 dprintf("imsm: cannot restart migration when data "
10471 "are present in copy area.\n");
10474 /* Save checkpoint to update migration record for current
10475 * reshape position (in md). It can be farther than current
10476 * reshape position in metadata.
10478 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
10479 /* ignore error == 2, this can mean end of reshape here
10481 dprintf("imsm: Cannot write checkpoint to "
10482 "migration record (UNIT_SRC_NORMAL, "
10483 "initial save)\n");
10488 /* size for data */
10489 buf_size
= __le32_to_cpu(migr_rec
->blocks_per_unit
) * 512;
10490 /* extend buffer size for parity disk */
10491 buf_size
+= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
10492 /* add space for stripe aligment */
10493 buf_size
+= old_data_stripe_length
;
10494 if (posix_memalign((void **)&buf
, 4096, buf_size
)) {
10495 dprintf("imsm: Cannot allocate checpoint buffer\n");
10499 max_position
= sra
->component_size
* ndata
;
10500 source_layout
= imsm_level_to_layout(map_src
->raid_level
);
10502 while (__le32_to_cpu(migr_rec
->curr_migr_unit
) <
10503 __le32_to_cpu(migr_rec
->num_migr_units
)) {
10504 /* current reshape position [blocks] */
10505 unsigned long long current_position
=
10506 __le32_to_cpu(migr_rec
->blocks_per_unit
)
10507 * __le32_to_cpu(migr_rec
->curr_migr_unit
);
10508 unsigned long long border
;
10510 /* Check that array hasn't become failed.
10512 degraded
= check_degradation_change(sra
, fds
, degraded
);
10513 if (degraded
> 1) {
10514 dprintf("imsm: Abort reshape due to degradation"
10515 " level (%i)\n", degraded
);
10519 next_step
= __le32_to_cpu(migr_rec
->blocks_per_unit
);
10521 if ((current_position
+ next_step
) > max_position
)
10522 next_step
= max_position
- current_position
;
10524 start
= current_position
* 512;
10526 /* allign reading start to old geometry */
10527 start_buf_shift
= start
% old_data_stripe_length
;
10528 start_src
= start
- start_buf_shift
;
10530 border
= (start_src
/ odata
) - (start
/ ndata
);
10532 if (border
<= __le32_to_cpu(migr_rec
->dest_depth_per_unit
)) {
10533 /* save critical stripes to buf
10534 * start - start address of current unit
10535 * to backup [bytes]
10536 * start_src - start address of current unit
10537 * to backup alligned to source array
10540 unsigned long long next_step_filler
= 0;
10541 unsigned long long copy_length
= next_step
* 512;
10543 /* allign copy area length to stripe in old geometry */
10544 next_step_filler
= ((copy_length
+ start_buf_shift
)
10545 % old_data_stripe_length
);
10546 if (next_step_filler
)
10547 next_step_filler
= (old_data_stripe_length
10548 - next_step_filler
);
10549 dprintf("save_stripes() parameters: start = %llu,"
10550 "\tstart_src = %llu,\tnext_step*512 = %llu,"
10551 "\tstart_in_buf_shift = %llu,"
10552 "\tnext_step_filler = %llu\n",
10553 start
, start_src
, copy_length
,
10554 start_buf_shift
, next_step_filler
);
10556 if (save_stripes(fds
, offsets
, map_src
->num_members
,
10557 chunk
, map_src
->raid_level
,
10558 source_layout
, 0, NULL
, start_src
,
10560 next_step_filler
+ start_buf_shift
,
10562 dprintf("imsm: Cannot save stripes"
10566 /* Convert data to destination format and store it
10567 * in backup general migration area
10569 if (save_backup_imsm(st
, dev
, sra
,
10570 buf
+ start_buf_shift
, copy_length
)) {
10571 dprintf("imsm: Cannot save stripes to "
10572 "target devices\n");
10575 if (save_checkpoint_imsm(st
, sra
,
10576 UNIT_SRC_IN_CP_AREA
)) {
10577 dprintf("imsm: Cannot write checkpoint to "
10578 "migration record (UNIT_SRC_IN_CP_AREA)\n");
10582 /* set next step to use whole border area */
10583 border
/= next_step
;
10585 next_step
*= border
;
10587 /* When data backed up, checkpoint stored,
10588 * kick the kernel to reshape unit of data
10590 next_step
= next_step
+ sra
->reshape_progress
;
10591 /* limit next step to array max position */
10592 if (next_step
> max_position
)
10593 next_step
= max_position
;
10594 sysfs_set_num(sra
, NULL
, "suspend_lo", sra
->reshape_progress
);
10595 sysfs_set_num(sra
, NULL
, "suspend_hi", next_step
);
10596 sra
->reshape_progress
= next_step
;
10598 /* wait until reshape finish */
10599 if (wait_for_reshape_imsm(sra
, ndata
) < 0) {
10600 dprintf("wait_for_reshape_imsm returned error!\n");
10606 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
10607 /* ignore error == 2, this can mean end of reshape here
10609 dprintf("imsm: Cannot write checkpoint to "
10610 "migration record (UNIT_SRC_NORMAL)\n");
10616 /* return '1' if done */
10620 abort_reshape(sra
);
10625 #endif /* MDASSEMBLE */
10627 struct superswitch super_imsm
= {
10629 .examine_super
= examine_super_imsm
,
10630 .brief_examine_super
= brief_examine_super_imsm
,
10631 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
10632 .export_examine_super
= export_examine_super_imsm
,
10633 .detail_super
= detail_super_imsm
,
10634 .brief_detail_super
= brief_detail_super_imsm
,
10635 .write_init_super
= write_init_super_imsm
,
10636 .validate_geometry
= validate_geometry_imsm
,
10637 .add_to_super
= add_to_super_imsm
,
10638 .remove_from_super
= remove_from_super_imsm
,
10639 .detail_platform
= detail_platform_imsm
,
10640 .export_detail_platform
= export_detail_platform_imsm
,
10641 .kill_subarray
= kill_subarray_imsm
,
10642 .update_subarray
= update_subarray_imsm
,
10643 .load_container
= load_container_imsm
,
10644 .default_geometry
= default_geometry_imsm
,
10645 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
10646 .reshape_super
= imsm_reshape_super
,
10647 .manage_reshape
= imsm_manage_reshape
,
10648 .recover_backup
= recover_backup_imsm
,
10649 .copy_metadata
= copy_metadata_imsm
,
10651 .match_home
= match_home_imsm
,
10652 .uuid_from_super
= uuid_from_super_imsm
,
10653 .getinfo_super
= getinfo_super_imsm
,
10654 .getinfo_super_disks
= getinfo_super_disks_imsm
,
10655 .update_super
= update_super_imsm
,
10657 .avail_size
= avail_size_imsm
,
10658 .min_acceptable_spare_size
= min_acceptable_spare_size_imsm
,
10660 .compare_super
= compare_super_imsm
,
10662 .load_super
= load_super_imsm
,
10663 .init_super
= init_super_imsm
,
10664 .store_super
= store_super_imsm
,
10665 .free_super
= free_super_imsm
,
10666 .match_metadata_desc
= match_metadata_desc_imsm
,
10667 .container_content
= container_content_imsm
,
10668 .validate_container
= validate_container_imsm
,
10675 .open_new
= imsm_open_new
,
10676 .set_array_state
= imsm_set_array_state
,
10677 .set_disk
= imsm_set_disk
,
10678 .sync_metadata
= imsm_sync_metadata
,
10679 .activate_spare
= imsm_activate_spare
,
10680 .process_update
= imsm_process_update
,
10681 .prepare_update
= imsm_prepare_update
,
10682 #endif /* MDASSEMBLE */