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"
515 const char *get_sys_dev_type(enum sys_dev_type type
)
517 if (type
>= SYS_DEV_MAX
)
518 type
= SYS_DEV_UNKNOWN
;
520 return _sys_dev_type
[type
];
523 static struct intel_hba
* alloc_intel_hba(struct sys_dev
*device
)
525 struct intel_hba
*result
= xmalloc(sizeof(*result
));
527 result
->type
= device
->type
;
528 result
->path
= xstrdup(device
->path
);
530 if (result
->path
&& (result
->pci_id
= strrchr(result
->path
, '/')) != NULL
)
536 static struct intel_hba
* find_intel_hba(struct intel_hba
*hba
, struct sys_dev
*device
)
538 struct intel_hba
*result
=NULL
;
539 for (result
= hba
; result
; result
= result
->next
) {
540 if (result
->type
== device
->type
&& strcmp(result
->path
, device
->path
) == 0)
546 static int attach_hba_to_super(struct intel_super
*super
, struct sys_dev
*device
)
548 struct intel_hba
*hba
;
550 /* check if disk attached to Intel HBA */
551 hba
= find_intel_hba(super
->hba
, device
);
554 /* Check if HBA is already attached to super */
555 if (super
->hba
== NULL
) {
556 super
->hba
= alloc_intel_hba(device
);
561 /* Intel metadata allows for all disks attached to the same type HBA.
562 * Do not sypport odf HBA types mixing
564 if (device
->type
!= hba
->type
)
567 /* Multiple same type HBAs can be used if they share the same OROM */
568 const struct imsm_orom
*device_orom
= get_orom_by_device_id(device
->dev_id
);
570 if (device_orom
!= super
->orom
)
576 hba
->next
= alloc_intel_hba(device
);
580 static struct sys_dev
* find_disk_attached_hba(int fd
, const char *devname
)
582 struct sys_dev
*list
, *elem
;
585 if ((list
= find_intel_devices()) == NULL
)
589 disk_path
= (char *) devname
;
591 disk_path
= diskfd_to_devpath(fd
);
596 for (elem
= list
; elem
; elem
= elem
->next
)
597 if (path_attached_to_hba(disk_path
, elem
->path
))
600 if (disk_path
!= devname
)
606 static int find_intel_hba_capability(int fd
, struct intel_super
*super
,
609 static struct supertype
*match_metadata_desc_imsm(char *arg
)
611 struct supertype
*st
;
613 if (strcmp(arg
, "imsm") != 0 &&
614 strcmp(arg
, "default") != 0
618 st
= xcalloc(1, sizeof(*st
));
619 st
->ss
= &super_imsm
;
620 st
->max_devs
= IMSM_MAX_DEVICES
;
621 st
->minor_version
= 0;
627 static __u8
*get_imsm_version(struct imsm_super
*mpb
)
629 return &mpb
->sig
[MPB_SIG_LEN
];
633 /* retrieve a disk directly from the anchor when the anchor is known to be
634 * up-to-date, currently only at load time
636 static struct imsm_disk
*__get_imsm_disk(struct imsm_super
*mpb
, __u8 index
)
638 if (index
>= mpb
->num_disks
)
640 return &mpb
->disk
[index
];
643 /* retrieve the disk description based on a index of the disk
646 static struct dl
*get_imsm_dl_disk(struct intel_super
*super
, __u8 index
)
650 for (d
= super
->disks
; d
; d
= d
->next
)
651 if (d
->index
== index
)
656 /* retrieve a disk from the parsed metadata */
657 static struct imsm_disk
*get_imsm_disk(struct intel_super
*super
, __u8 index
)
661 dl
= get_imsm_dl_disk(super
, index
);
668 /* generate a checksum directly from the anchor when the anchor is known to be
669 * up-to-date, currently only at load or write_super after coalescing
671 static __u32
__gen_imsm_checksum(struct imsm_super
*mpb
)
673 __u32 end
= mpb
->mpb_size
/ sizeof(end
);
674 __u32
*p
= (__u32
*) mpb
;
678 sum
+= __le32_to_cpu(*p
);
682 return sum
- __le32_to_cpu(mpb
->check_sum
);
685 static size_t sizeof_imsm_map(struct imsm_map
*map
)
687 return sizeof(struct imsm_map
) + sizeof(__u32
) * (map
->num_members
- 1);
690 struct imsm_map
*get_imsm_map(struct imsm_dev
*dev
, int second_map
)
692 /* A device can have 2 maps if it is in the middle of a migration.
694 * MAP_0 - we return the first map
695 * MAP_1 - we return the second map if it exists, else NULL
696 * MAP_X - we return the second map if it exists, else the first
698 struct imsm_map
*map
= &dev
->vol
.map
[0];
699 struct imsm_map
*map2
= NULL
;
701 if (dev
->vol
.migr_state
)
702 map2
= (void *)map
+ sizeof_imsm_map(map
);
704 switch (second_map
) {
721 /* return the size of the device.
722 * migr_state increases the returned size if map[0] were to be duplicated
724 static size_t sizeof_imsm_dev(struct imsm_dev
*dev
, int migr_state
)
726 size_t size
= sizeof(*dev
) - sizeof(struct imsm_map
) +
727 sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
729 /* migrating means an additional map */
730 if (dev
->vol
.migr_state
)
731 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_1
));
733 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
739 /* retrieve disk serial number list from a metadata update */
740 static struct disk_info
*get_disk_info(struct imsm_update_create_array
*update
)
743 struct disk_info
*inf
;
745 inf
= u
+ sizeof(*update
) - sizeof(struct imsm_dev
) +
746 sizeof_imsm_dev(&update
->dev
, 0);
752 static struct imsm_dev
*__get_imsm_dev(struct imsm_super
*mpb
, __u8 index
)
758 if (index
>= mpb
->num_raid_devs
)
761 /* devices start after all disks */
762 offset
= ((void *) &mpb
->disk
[mpb
->num_disks
]) - _mpb
;
764 for (i
= 0; i
<= index
; i
++)
766 return _mpb
+ offset
;
768 offset
+= sizeof_imsm_dev(_mpb
+ offset
, 0);
773 static struct imsm_dev
*get_imsm_dev(struct intel_super
*super
, __u8 index
)
775 struct intel_dev
*dv
;
777 if (index
>= super
->anchor
->num_raid_devs
)
779 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
780 if (dv
->index
== index
)
787 * == MAP_0 get first map
788 * == MAP_1 get second map
789 * == MAP_X than get map according to the current migr_state
791 static __u32
get_imsm_ord_tbl_ent(struct imsm_dev
*dev
,
795 struct imsm_map
*map
;
797 map
= get_imsm_map(dev
, second_map
);
799 /* top byte identifies disk under rebuild */
800 return __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
803 #define ord_to_idx(ord) (((ord) << 8) >> 8)
804 static __u32
get_imsm_disk_idx(struct imsm_dev
*dev
, int slot
, int second_map
)
806 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, second_map
);
808 return ord_to_idx(ord
);
811 static void set_imsm_ord_tbl_ent(struct imsm_map
*map
, int slot
, __u32 ord
)
813 map
->disk_ord_tbl
[slot
] = __cpu_to_le32(ord
);
816 static int get_imsm_disk_slot(struct imsm_map
*map
, unsigned idx
)
821 for (slot
= 0; slot
< map
->num_members
; slot
++) {
822 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
823 if (ord_to_idx(ord
) == idx
)
830 static int get_imsm_raid_level(struct imsm_map
*map
)
832 if (map
->raid_level
== 1) {
833 if (map
->num_members
== 2)
839 return map
->raid_level
;
842 static int cmp_extent(const void *av
, const void *bv
)
844 const struct extent
*a
= av
;
845 const struct extent
*b
= bv
;
846 if (a
->start
< b
->start
)
848 if (a
->start
> b
->start
)
853 static int count_memberships(struct dl
*dl
, struct intel_super
*super
)
858 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
859 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
860 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
862 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
869 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
);
871 static int split_ull(unsigned long long n
, __u32
*lo
, __u32
*hi
)
873 if (lo
== 0 || hi
== 0)
875 *lo
= __le32_to_cpu((unsigned)n
);
876 *hi
= __le32_to_cpu((unsigned)(n
>> 32));
880 static unsigned long long join_u32(__u32 lo
, __u32 hi
)
882 return (unsigned long long)__le32_to_cpu(lo
) |
883 (((unsigned long long)__le32_to_cpu(hi
)) << 32);
886 static unsigned long long total_blocks(struct imsm_disk
*disk
)
890 return join_u32(disk
->total_blocks_lo
, disk
->total_blocks_hi
);
893 static unsigned long long pba_of_lba0(struct imsm_map
*map
)
897 return join_u32(map
->pba_of_lba0_lo
, map
->pba_of_lba0_hi
);
900 static unsigned long long blocks_per_member(struct imsm_map
*map
)
904 return join_u32(map
->blocks_per_member_lo
, map
->blocks_per_member_hi
);
908 static unsigned long long num_data_stripes(struct imsm_map
*map
)
912 return join_u32(map
->num_data_stripes_lo
, map
->num_data_stripes_hi
);
915 static void set_total_blocks(struct imsm_disk
*disk
, unsigned long long n
)
917 split_ull(n
, &disk
->total_blocks_lo
, &disk
->total_blocks_hi
);
921 static void set_pba_of_lba0(struct imsm_map
*map
, unsigned long long n
)
923 split_ull(n
, &map
->pba_of_lba0_lo
, &map
->pba_of_lba0_hi
);
926 static void set_blocks_per_member(struct imsm_map
*map
, unsigned long long n
)
928 split_ull(n
, &map
->blocks_per_member_lo
, &map
->blocks_per_member_hi
);
931 static void set_num_data_stripes(struct imsm_map
*map
, unsigned long long n
)
933 split_ull(n
, &map
->num_data_stripes_lo
, &map
->num_data_stripes_hi
);
936 static struct extent
*get_extents(struct intel_super
*super
, struct dl
*dl
)
938 /* find a list of used extents on the given physical device */
939 struct extent
*rv
, *e
;
941 int memberships
= count_memberships(dl
, super
);
944 /* trim the reserved area for spares, so they can join any array
945 * regardless of whether the OROM has assigned sectors from the
946 * IMSM_RESERVED_SECTORS region
949 reservation
= imsm_min_reserved_sectors(super
);
951 reservation
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
953 rv
= xcalloc(sizeof(struct extent
), (memberships
+ 1));
956 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
957 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
958 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
960 if (get_imsm_disk_slot(map
, dl
->index
) >= 0) {
961 e
->start
= pba_of_lba0(map
);
962 e
->size
= blocks_per_member(map
);
966 qsort(rv
, memberships
, sizeof(*rv
), cmp_extent
);
968 /* determine the start of the metadata
969 * when no raid devices are defined use the default
970 * ...otherwise allow the metadata to truncate the value
971 * as is the case with older versions of imsm
974 struct extent
*last
= &rv
[memberships
- 1];
975 unsigned long long remainder
;
977 remainder
= total_blocks(&dl
->disk
) - (last
->start
+ last
->size
);
978 /* round down to 1k block to satisfy precision of the kernel
982 /* make sure remainder is still sane */
983 if (remainder
< (unsigned)ROUND_UP(super
->len
, 512) >> 9)
984 remainder
= ROUND_UP(super
->len
, 512) >> 9;
985 if (reservation
> remainder
)
986 reservation
= remainder
;
988 e
->start
= total_blocks(&dl
->disk
) - reservation
;
993 /* try to determine how much space is reserved for metadata from
994 * the last get_extents() entry, otherwise fallback to the
997 static __u32
imsm_reserved_sectors(struct intel_super
*super
, struct dl
*dl
)
1003 /* for spares just return a minimal reservation which will grow
1004 * once the spare is picked up by an array
1006 if (dl
->index
== -1)
1007 return MPB_SECTOR_CNT
;
1009 e
= get_extents(super
, dl
);
1011 return MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1013 /* scroll to last entry */
1014 for (i
= 0; e
[i
].size
; i
++)
1017 rv
= total_blocks(&dl
->disk
) - e
[i
].start
;
1024 static int is_spare(struct imsm_disk
*disk
)
1026 return (disk
->status
& SPARE_DISK
) == SPARE_DISK
;
1029 static int is_configured(struct imsm_disk
*disk
)
1031 return (disk
->status
& CONFIGURED_DISK
) == CONFIGURED_DISK
;
1034 static int is_failed(struct imsm_disk
*disk
)
1036 return (disk
->status
& FAILED_DISK
) == FAILED_DISK
;
1039 /* try to determine how much space is reserved for metadata from
1040 * the last get_extents() entry on the smallest active disk,
1041 * otherwise fallback to the default
1043 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
)
1047 unsigned long long min_active
;
1049 __u32 rv
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1050 struct dl
*dl
, *dl_min
= NULL
;
1056 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
1059 unsigned long long blocks
= total_blocks(&dl
->disk
);
1060 if (blocks
< min_active
|| min_active
== 0) {
1062 min_active
= blocks
;
1068 /* find last lba used by subarrays on the smallest active disk */
1069 e
= get_extents(super
, dl_min
);
1072 for (i
= 0; e
[i
].size
; i
++)
1075 remainder
= min_active
- e
[i
].start
;
1078 /* to give priority to recovery we should not require full
1079 IMSM_RESERVED_SECTORS from the spare */
1080 rv
= MPB_SECTOR_CNT
+ NUM_BLOCKS_DIRTY_STRIPE_REGION
;
1082 /* if real reservation is smaller use that value */
1083 return (remainder
< rv
) ? remainder
: rv
;
1086 /* Return minimum size of a spare that can be used in this array*/
1087 static unsigned long long min_acceptable_spare_size_imsm(struct supertype
*st
)
1089 struct intel_super
*super
= st
->sb
;
1093 unsigned long long rv
= 0;
1097 /* find first active disk in array */
1099 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
1103 /* find last lba used by subarrays */
1104 e
= get_extents(super
, dl
);
1107 for (i
= 0; e
[i
].size
; i
++)
1110 rv
= e
[i
-1].start
+ e
[i
-1].size
;
1113 /* add the amount of space needed for metadata */
1114 rv
= rv
+ imsm_min_reserved_sectors(super
);
1119 static int is_gen_migration(struct imsm_dev
*dev
);
1122 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
1123 struct imsm_dev
*dev
);
1125 static void print_imsm_dev(struct intel_super
*super
,
1126 struct imsm_dev
*dev
,
1132 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1133 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
1137 printf("[%.16s]:\n", dev
->volume
);
1138 printf(" UUID : %s\n", uuid
);
1139 printf(" RAID Level : %d", get_imsm_raid_level(map
));
1141 printf(" <-- %d", get_imsm_raid_level(map2
));
1143 printf(" Members : %d", map
->num_members
);
1145 printf(" <-- %d", map2
->num_members
);
1147 printf(" Slots : [");
1148 for (i
= 0; i
< map
->num_members
; i
++) {
1149 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
1150 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1155 for (i
= 0; i
< map2
->num_members
; i
++) {
1156 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_1
);
1157 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1162 printf(" Failed disk : ");
1163 if (map
->failed_disk_num
== 0xff)
1166 printf("%i", map
->failed_disk_num
);
1168 slot
= get_imsm_disk_slot(map
, disk_idx
);
1170 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
1171 printf(" This Slot : %d%s\n", slot
,
1172 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
1174 printf(" This Slot : ?\n");
1175 sz
= __le32_to_cpu(dev
->size_high
);
1177 sz
+= __le32_to_cpu(dev
->size_low
);
1178 printf(" Array Size : %llu%s\n", (unsigned long long)sz
,
1179 human_size(sz
* 512));
1180 sz
= blocks_per_member(map
);
1181 printf(" Per Dev Size : %llu%s\n", (unsigned long long)sz
,
1182 human_size(sz
* 512));
1183 printf(" Sector Offset : %llu\n",
1185 printf(" Num Stripes : %llu\n",
1186 num_data_stripes(map
));
1187 printf(" Chunk Size : %u KiB",
1188 __le16_to_cpu(map
->blocks_per_strip
) / 2);
1190 printf(" <-- %u KiB",
1191 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
1193 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
1194 printf(" Migrate State : ");
1195 if (dev
->vol
.migr_state
) {
1196 if (migr_type(dev
) == MIGR_INIT
)
1197 printf("initialize\n");
1198 else if (migr_type(dev
) == MIGR_REBUILD
)
1199 printf("rebuild\n");
1200 else if (migr_type(dev
) == MIGR_VERIFY
)
1202 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
1203 printf("general migration\n");
1204 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
1205 printf("state change\n");
1206 else if (migr_type(dev
) == MIGR_REPAIR
)
1209 printf("<unknown:%d>\n", migr_type(dev
));
1212 printf(" Map State : %s", map_state_str
[map
->map_state
]);
1213 if (dev
->vol
.migr_state
) {
1214 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
1216 printf(" <-- %s", map_state_str
[map
->map_state
]);
1217 printf("\n Checkpoint : %u ",
1218 __le32_to_cpu(dev
->vol
.curr_migr_unit
));
1219 if ((is_gen_migration(dev
)) && ((slot
> 1) || (slot
< 0)))
1222 printf("(%llu)", (unsigned long long)
1223 blocks_per_migr_unit(super
, dev
));
1226 printf(" Dirty State : %s\n", dev
->vol
.dirty
? "dirty" : "clean");
1229 static void print_imsm_disk(struct imsm_disk
*disk
, int index
, __u32 reserved
)
1231 char str
[MAX_RAID_SERIAL_LEN
+ 1];
1234 if (index
< -1 || !disk
)
1238 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
1240 printf(" Disk%02d Serial : %s\n", index
, str
);
1242 printf(" Disk Serial : %s\n", str
);
1243 printf(" State :%s%s%s\n", is_spare(disk
) ? " spare" : "",
1244 is_configured(disk
) ? " active" : "",
1245 is_failed(disk
) ? " failed" : "");
1246 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
1247 sz
= total_blocks(disk
) - reserved
;
1248 printf(" Usable Size : %llu%s\n", (unsigned long long)sz
,
1249 human_size(sz
* 512));
1252 void examine_migr_rec_imsm(struct intel_super
*super
)
1254 struct migr_record
*migr_rec
= super
->migr_rec
;
1255 struct imsm_super
*mpb
= super
->anchor
;
1258 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1259 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1260 struct imsm_map
*map
;
1263 if (is_gen_migration(dev
) == 0)
1266 printf("\nMigration Record Information:");
1268 /* first map under migration */
1269 map
= get_imsm_map(dev
, MAP_0
);
1271 slot
= get_imsm_disk_slot(map
, super
->disks
->index
);
1272 if ((map
== NULL
) || (slot
> 1) || (slot
< 0)) {
1273 printf(" Empty\n ");
1274 printf("Examine one of first two disks in array\n");
1277 printf("\n Status : ");
1278 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
1281 printf("Contains Data\n");
1282 printf(" Current Unit : %u\n",
1283 __le32_to_cpu(migr_rec
->curr_migr_unit
));
1284 printf(" Family : %u\n",
1285 __le32_to_cpu(migr_rec
->family_num
));
1286 printf(" Ascending : %u\n",
1287 __le32_to_cpu(migr_rec
->ascending_migr
));
1288 printf(" Blocks Per Unit : %u\n",
1289 __le32_to_cpu(migr_rec
->blocks_per_unit
));
1290 printf(" Dest. Depth Per Unit : %u\n",
1291 __le32_to_cpu(migr_rec
->dest_depth_per_unit
));
1292 printf(" Checkpoint Area pba : %u\n",
1293 __le32_to_cpu(migr_rec
->ckpt_area_pba
));
1294 printf(" First member lba : %u\n",
1295 __le32_to_cpu(migr_rec
->dest_1st_member_lba
));
1296 printf(" Total Number of Units : %u\n",
1297 __le32_to_cpu(migr_rec
->num_migr_units
));
1298 printf(" Size of volume : %u\n",
1299 __le32_to_cpu(migr_rec
->post_migr_vol_cap
));
1300 printf(" Expansion space for LBA64 : %u\n",
1301 __le32_to_cpu(migr_rec
->post_migr_vol_cap_hi
));
1302 printf(" Record was read from : %u\n",
1303 __le32_to_cpu(migr_rec
->ckpt_read_disk_num
));
1308 #endif /* MDASSEMBLE */
1309 /*******************************************************************************
1310 * function: imsm_check_attributes
1311 * Description: Function checks if features represented by attributes flags
1312 * are supported by mdadm.
1314 * attributes - Attributes read from metadata
1316 * 0 - passed attributes contains unsupported features flags
1317 * 1 - all features are supported
1318 ******************************************************************************/
1319 static int imsm_check_attributes(__u32 attributes
)
1322 __u32 not_supported
= MPB_ATTRIB_SUPPORTED
^0xffffffff;
1324 not_supported
&= ~MPB_ATTRIB_IGNORED
;
1326 not_supported
&= attributes
;
1327 if (not_supported
) {
1328 pr_err("(IMSM): Unsupported attributes : %x\n",
1329 (unsigned)__le32_to_cpu(not_supported
));
1330 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1331 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY \n");
1332 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1334 if (not_supported
& MPB_ATTRIB_2TB
) {
1335 dprintf("\t\tMPB_ATTRIB_2TB\n");
1336 not_supported
^= MPB_ATTRIB_2TB
;
1338 if (not_supported
& MPB_ATTRIB_RAID0
) {
1339 dprintf("\t\tMPB_ATTRIB_RAID0\n");
1340 not_supported
^= MPB_ATTRIB_RAID0
;
1342 if (not_supported
& MPB_ATTRIB_RAID1
) {
1343 dprintf("\t\tMPB_ATTRIB_RAID1\n");
1344 not_supported
^= MPB_ATTRIB_RAID1
;
1346 if (not_supported
& MPB_ATTRIB_RAID10
) {
1347 dprintf("\t\tMPB_ATTRIB_RAID10\n");
1348 not_supported
^= MPB_ATTRIB_RAID10
;
1350 if (not_supported
& MPB_ATTRIB_RAID1E
) {
1351 dprintf("\t\tMPB_ATTRIB_RAID1E\n");
1352 not_supported
^= MPB_ATTRIB_RAID1E
;
1354 if (not_supported
& MPB_ATTRIB_RAID5
) {
1355 dprintf("\t\tMPB_ATTRIB_RAID5\n");
1356 not_supported
^= MPB_ATTRIB_RAID5
;
1358 if (not_supported
& MPB_ATTRIB_RAIDCNG
) {
1359 dprintf("\t\tMPB_ATTRIB_RAIDCNG\n");
1360 not_supported
^= MPB_ATTRIB_RAIDCNG
;
1362 if (not_supported
& MPB_ATTRIB_BBM
) {
1363 dprintf("\t\tMPB_ATTRIB_BBM\n");
1364 not_supported
^= MPB_ATTRIB_BBM
;
1366 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1367 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY (== MPB_ATTRIB_LEGACY)\n");
1368 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1370 if (not_supported
& MPB_ATTRIB_EXP_STRIPE_SIZE
) {
1371 dprintf("\t\tMPB_ATTRIB_EXP_STRIP_SIZE\n");
1372 not_supported
^= MPB_ATTRIB_EXP_STRIPE_SIZE
;
1374 if (not_supported
& MPB_ATTRIB_2TB_DISK
) {
1375 dprintf("\t\tMPB_ATTRIB_2TB_DISK\n");
1376 not_supported
^= MPB_ATTRIB_2TB_DISK
;
1378 if (not_supported
& MPB_ATTRIB_NEVER_USE2
) {
1379 dprintf("\t\tMPB_ATTRIB_NEVER_USE2\n");
1380 not_supported
^= MPB_ATTRIB_NEVER_USE2
;
1382 if (not_supported
& MPB_ATTRIB_NEVER_USE
) {
1383 dprintf("\t\tMPB_ATTRIB_NEVER_USE\n");
1384 not_supported
^= MPB_ATTRIB_NEVER_USE
;
1388 dprintf(Name
"(IMSM): Unknown attributes : %x\n", not_supported
);
1397 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
1399 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
1401 struct intel_super
*super
= st
->sb
;
1402 struct imsm_super
*mpb
= super
->anchor
;
1403 char str
[MAX_SIGNATURE_LENGTH
];
1408 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
1411 snprintf(str
, MPB_SIG_LEN
, "%s", mpb
->sig
);
1412 printf(" Magic : %s\n", str
);
1413 snprintf(str
, strlen(MPB_VERSION_RAID0
), "%s", get_imsm_version(mpb
));
1414 printf(" Version : %s\n", get_imsm_version(mpb
));
1415 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
1416 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
1417 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
1418 printf(" Attributes : ");
1419 if (imsm_check_attributes(mpb
->attributes
))
1420 printf("All supported\n");
1422 printf("not supported\n");
1423 getinfo_super_imsm(st
, &info
, NULL
);
1424 fname_from_uuid(st
, &info
, nbuf
, ':');
1425 printf(" UUID : %s\n", nbuf
+ 5);
1426 sum
= __le32_to_cpu(mpb
->check_sum
);
1427 printf(" Checksum : %08x %s\n", sum
,
1428 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
1429 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
));
1430 printf(" Disks : %d\n", mpb
->num_disks
);
1431 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
1432 print_imsm_disk(__get_imsm_disk(mpb
, super
->disks
->index
), super
->disks
->index
, reserved
);
1433 if (super
->bbm_log
) {
1434 struct bbm_log
*log
= super
->bbm_log
;
1437 printf("Bad Block Management Log:\n");
1438 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
1439 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
1440 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
1441 printf(" Spare Blocks : %d\n", __le32_to_cpu(log
->reserved_spare_block_count
));
1442 printf(" First Spare : %llx\n",
1443 (unsigned long long) __le64_to_cpu(log
->first_spare_lba
));
1445 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1447 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1449 super
->current_vol
= i
;
1450 getinfo_super_imsm(st
, &info
, NULL
);
1451 fname_from_uuid(st
, &info
, nbuf
, ':');
1452 print_imsm_dev(super
, dev
, nbuf
+ 5, super
->disks
->index
);
1454 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1455 if (i
== super
->disks
->index
)
1457 print_imsm_disk(__get_imsm_disk(mpb
, i
), i
, reserved
);
1460 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
1461 if (dl
->index
== -1)
1462 print_imsm_disk(&dl
->disk
, -1, reserved
);
1464 examine_migr_rec_imsm(super
);
1467 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
1469 /* We just write a generic IMSM ARRAY entry */
1472 struct intel_super
*super
= st
->sb
;
1474 if (!super
->anchor
->num_raid_devs
) {
1475 printf("ARRAY metadata=imsm\n");
1479 getinfo_super_imsm(st
, &info
, NULL
);
1480 fname_from_uuid(st
, &info
, nbuf
, ':');
1481 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
1484 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
1486 /* We just write a generic IMSM ARRAY entry */
1490 struct intel_super
*super
= st
->sb
;
1493 if (!super
->anchor
->num_raid_devs
)
1496 getinfo_super_imsm(st
, &info
, NULL
);
1497 fname_from_uuid(st
, &info
, nbuf
, ':');
1498 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1499 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1501 super
->current_vol
= i
;
1502 getinfo_super_imsm(st
, &info
, NULL
);
1503 fname_from_uuid(st
, &info
, nbuf1
, ':');
1504 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
1505 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
1509 static void export_examine_super_imsm(struct supertype
*st
)
1511 struct intel_super
*super
= st
->sb
;
1512 struct imsm_super
*mpb
= super
->anchor
;
1516 getinfo_super_imsm(st
, &info
, NULL
);
1517 fname_from_uuid(st
, &info
, nbuf
, ':');
1518 printf("MD_METADATA=imsm\n");
1519 printf("MD_LEVEL=container\n");
1520 printf("MD_UUID=%s\n", nbuf
+5);
1521 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
1524 static int copy_metadata_imsm(struct supertype
*st
, int from
, int to
)
1526 /* The second last 512byte sector of the device contains
1527 * the "struct imsm_super" metadata.
1528 * This contains mpb_size which is the size in bytes of the
1529 * extended metadata. This is located immediately before
1531 * We want to read all that, plus the last sector which
1532 * may contain a migration record, and write it all
1536 unsigned long long dsize
, offset
;
1538 struct imsm_super
*sb
;
1541 if (posix_memalign(&buf
, 4096, 4096) != 0)
1544 if (!get_dev_size(from
, NULL
, &dsize
))
1547 if (lseek64(from
, dsize
-1024, 0) < 0)
1549 if (read(from
, buf
, 512) != 512)
1552 if (strncmp((char*)sb
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0)
1555 sectors
= mpb_sectors(sb
) + 2;
1556 offset
= dsize
- sectors
* 512;
1557 if (lseek64(from
, offset
, 0) < 0 ||
1558 lseek64(to
, offset
, 0) < 0)
1560 while (written
< sectors
* 512) {
1561 int n
= sectors
*512 - written
;
1564 if (read(from
, buf
, n
) != n
)
1566 if (write(to
, buf
, n
) != n
)
1577 static void detail_super_imsm(struct supertype
*st
, char *homehost
)
1582 getinfo_super_imsm(st
, &info
, NULL
);
1583 fname_from_uuid(st
, &info
, nbuf
, ':');
1584 printf("\n UUID : %s\n", nbuf
+ 5);
1587 static void brief_detail_super_imsm(struct supertype
*st
)
1591 getinfo_super_imsm(st
, &info
, NULL
);
1592 fname_from_uuid(st
, &info
, nbuf
, ':');
1593 printf(" UUID=%s", nbuf
+ 5);
1596 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
);
1597 static void fd2devname(int fd
, char *name
);
1599 static int ahci_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
1601 /* dump an unsorted list of devices attached to AHCI Intel storage
1602 * controller, as well as non-connected ports
1604 int hba_len
= strlen(hba_path
) + 1;
1609 unsigned long port_mask
= (1 << port_count
) - 1;
1611 if (port_count
> (int)sizeof(port_mask
) * 8) {
1613 pr_err("port_count %d out of range\n", port_count
);
1617 /* scroll through /sys/dev/block looking for devices attached to
1620 dir
= opendir("/sys/dev/block");
1621 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
1632 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
1634 path
= devt_to_devpath(makedev(major
, minor
));
1637 if (!path_attached_to_hba(path
, hba_path
)) {
1643 /* retrieve the scsi device type */
1644 if (asprintf(&device
, "/sys/dev/block/%d:%d/device/xxxxxxx", major
, minor
) < 0) {
1646 pr_err("failed to allocate 'device'\n");
1650 sprintf(device
, "/sys/dev/block/%d:%d/device/type", major
, minor
);
1651 if (load_sys(device
, buf
) != 0) {
1653 pr_err("failed to read device type for %s\n",
1659 type
= strtoul(buf
, NULL
, 10);
1661 /* if it's not a disk print the vendor and model */
1662 if (!(type
== 0 || type
== 7 || type
== 14)) {
1665 sprintf(device
, "/sys/dev/block/%d:%d/device/vendor", major
, minor
);
1666 if (load_sys(device
, buf
) == 0) {
1667 strncpy(vendor
, buf
, sizeof(vendor
));
1668 vendor
[sizeof(vendor
) - 1] = '\0';
1669 c
= (char *) &vendor
[sizeof(vendor
) - 1];
1670 while (isspace(*c
) || *c
== '\0')
1674 sprintf(device
, "/sys/dev/block/%d:%d/device/model", major
, minor
);
1675 if (load_sys(device
, buf
) == 0) {
1676 strncpy(model
, buf
, sizeof(model
));
1677 model
[sizeof(model
) - 1] = '\0';
1678 c
= (char *) &model
[sizeof(model
) - 1];
1679 while (isspace(*c
) || *c
== '\0')
1683 if (vendor
[0] && model
[0])
1684 sprintf(buf
, "%.64s %.64s", vendor
, model
);
1686 switch (type
) { /* numbers from hald/linux/device.c */
1687 case 1: sprintf(buf
, "tape"); break;
1688 case 2: sprintf(buf
, "printer"); break;
1689 case 3: sprintf(buf
, "processor"); break;
1691 case 5: sprintf(buf
, "cdrom"); break;
1692 case 6: sprintf(buf
, "scanner"); break;
1693 case 8: sprintf(buf
, "media_changer"); break;
1694 case 9: sprintf(buf
, "comm"); break;
1695 case 12: sprintf(buf
, "raid"); break;
1696 default: sprintf(buf
, "unknown");
1702 /* chop device path to 'host%d' and calculate the port number */
1703 c
= strchr(&path
[hba_len
], '/');
1706 pr_err("%s - invalid path name\n", path
+ hba_len
);
1711 if (sscanf(&path
[hba_len
], "host%d", &port
) == 1)
1715 *c
= '/'; /* repair the full string */
1716 pr_err("failed to determine port number for %s\n",
1723 /* mark this port as used */
1724 port_mask
&= ~(1 << port
);
1726 /* print out the device information */
1728 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
1732 fd
= dev_open(ent
->d_name
, O_RDONLY
);
1734 printf(" Port%d : - disk info unavailable -\n", port
);
1736 fd2devname(fd
, buf
);
1737 printf(" Port%d : %s", port
, buf
);
1738 if (imsm_read_serial(fd
, NULL
, (__u8
*) buf
) == 0)
1739 printf(" (%.*s)\n", MAX_RAID_SERIAL_LEN
, buf
);
1754 for (i
= 0; i
< port_count
; i
++)
1755 if (port_mask
& (1 << i
))
1756 printf(" Port%d : - no device attached -\n", i
);
1762 static void print_found_intel_controllers(struct sys_dev
*elem
)
1764 for (; elem
; elem
= elem
->next
) {
1765 pr_err("found Intel(R) ");
1766 if (elem
->type
== SYS_DEV_SATA
)
1767 fprintf(stderr
, "SATA ");
1768 else if (elem
->type
== SYS_DEV_SAS
)
1769 fprintf(stderr
, "SAS ");
1770 fprintf(stderr
, "RAID controller");
1772 fprintf(stderr
, " at %s", elem
->pci_id
);
1773 fprintf(stderr
, ".\n");
1778 static int ahci_get_port_count(const char *hba_path
, int *port_count
)
1785 if ((dir
= opendir(hba_path
)) == NULL
)
1788 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
1791 if (sscanf(ent
->d_name
, "host%d", &host
) != 1)
1793 if (*port_count
== 0)
1795 else if (host
< host_base
)
1798 if (host
+ 1 > *port_count
+ host_base
)
1799 *port_count
= host
+ 1 - host_base
;
1805 static void print_imsm_capability(const struct imsm_orom
*orom
)
1807 printf(" Platform : Intel(R) Matrix Storage Manager\n");
1808 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
1809 orom
->hotfix_ver
, orom
->build
);
1810 printf(" RAID Levels :%s%s%s%s%s\n",
1811 imsm_orom_has_raid0(orom
) ? " raid0" : "",
1812 imsm_orom_has_raid1(orom
) ? " raid1" : "",
1813 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
1814 imsm_orom_has_raid10(orom
) ? " raid10" : "",
1815 imsm_orom_has_raid5(orom
) ? " raid5" : "");
1816 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1817 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
1818 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
1819 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
1820 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
1821 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
1822 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
1823 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
1824 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
1825 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
1826 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
1827 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
1828 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
1829 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
1830 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
1831 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
1832 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
1833 printf(" 2TB volumes :%s supported\n",
1834 (orom
->attr
& IMSM_OROM_ATTR_2TB
)?"":" not");
1835 printf(" 2TB disks :%s supported\n",
1836 (orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
)?"":" not");
1837 printf(" Max Disks : %d\n", orom
->tds
);
1838 printf(" Max Volumes : %d per array, %d per controller\n",
1839 orom
->vpa
, orom
->vphba
);
1843 static void print_imsm_capability_export(const struct imsm_orom
*orom
)
1845 printf("MD_FIRMWARE_TYPE=imsm\n");
1846 printf("IMSM_VERSION=%d.%d.%d.%d\n",orom
->major_ver
, orom
->minor_ver
,
1847 orom
->hotfix_ver
, orom
->build
);
1848 printf("IMSM_SUPPORTED_RAID_LEVELS=%s%s%s%s%s\n",
1849 imsm_orom_has_raid0(orom
) ? "raid0 " : "",
1850 imsm_orom_has_raid1(orom
) ? "raid1 " : "",
1851 imsm_orom_has_raid1e(orom
) ? "raid1e " : "",
1852 imsm_orom_has_raid5(orom
) ? "raid10 " : "",
1853 imsm_orom_has_raid10(orom
) ? "raid5 " : "");
1854 printf("IMSM_SUPPORTED_CHUNK_SIZES=%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1855 imsm_orom_has_chunk(orom
, 2) ? "2k " : "",
1856 imsm_orom_has_chunk(orom
, 4) ? "4k " : "",
1857 imsm_orom_has_chunk(orom
, 8) ? "8k " : "",
1858 imsm_orom_has_chunk(orom
, 16) ? "16k " : "",
1859 imsm_orom_has_chunk(orom
, 32) ? "32k " : "",
1860 imsm_orom_has_chunk(orom
, 64) ? "64k " : "",
1861 imsm_orom_has_chunk(orom
, 128) ? "128k " : "",
1862 imsm_orom_has_chunk(orom
, 256) ? "256k " : "",
1863 imsm_orom_has_chunk(orom
, 512) ? "512k " : "",
1864 imsm_orom_has_chunk(orom
, 1024*1) ? "1M " : "",
1865 imsm_orom_has_chunk(orom
, 1024*2) ? "2M " : "",
1866 imsm_orom_has_chunk(orom
, 1024*4) ? "4M " : "",
1867 imsm_orom_has_chunk(orom
, 1024*8) ? "8M " : "",
1868 imsm_orom_has_chunk(orom
, 1024*16) ? "16M " : "",
1869 imsm_orom_has_chunk(orom
, 1024*32) ? "32M " : "",
1870 imsm_orom_has_chunk(orom
, 1024*64) ? "64M " : "");
1871 printf("IMSM_2TB_VOLUMES=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB
) ? "yes" : "no");
1872 printf("IMSM_2TB_DISKS=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) ? "yes" : "no");
1873 printf("IMSM_MAX_DISKS=%d\n",orom
->tds
);
1874 printf("IMSM_MAX_VOLUMES_PER_ARRAY=%d\n",orom
->vpa
);
1875 printf("IMSM_MAX_VOLUMES_PER_CONTROLLER=%d\n",orom
->vphba
);
1878 static int detail_platform_imsm(int verbose
, int enumerate_only
, char *controller_path
)
1880 /* There are two components to imsm platform support, the ahci SATA
1881 * controller and the option-rom. To find the SATA controller we
1882 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
1883 * controller with the Intel vendor id is present. This approach
1884 * allows mdadm to leverage the kernel's ahci detection logic, with the
1885 * caveat that if ahci.ko is not loaded mdadm will not be able to
1886 * detect platform raid capabilities. The option-rom resides in a
1887 * platform "Adapter ROM". We scan for its signature to retrieve the
1888 * platform capabilities. If raid support is disabled in the BIOS the
1889 * option-rom capability structure will not be available.
1891 const struct imsm_orom
*orom
;
1892 struct sys_dev
*list
, *hba
;
1897 if (enumerate_only
) {
1898 if (check_env("IMSM_NO_PLATFORM"))
1900 list
= find_intel_devices();
1903 for (hba
= list
; hba
; hba
= hba
->next
) {
1904 if (find_imsm_capability(hba
)) {
1914 list
= find_intel_devices();
1917 pr_err("no active Intel(R) RAID "
1918 "controller found.\n");
1920 } else if (verbose
> 0)
1921 print_found_intel_controllers(list
);
1923 for (hba
= list
; hba
; hba
= hba
->next
) {
1924 if (controller_path
&& (compare_paths(hba
->path
,controller_path
) != 0))
1926 orom
= find_imsm_capability(hba
);
1928 pr_err("imsm capabilities not found for controller: %s (type %s)\n",
1929 hba
->path
, get_sys_dev_type(hba
->type
));
1932 print_imsm_capability(orom
);
1933 printf(" I/O Controller : %s (%s)\n",
1934 hba
->path
, get_sys_dev_type(hba
->type
));
1935 if (hba
->type
== SYS_DEV_SATA
) {
1936 host_base
= ahci_get_port_count(hba
->path
, &port_count
);
1937 if (ahci_enumerate_ports(hba
->path
, port_count
, host_base
, verbose
)) {
1939 pr_err("failed to enumerate "
1940 "ports on SATA controller at %s.\n", hba
->pci_id
);
1947 if (controller_path
&& result
== 1)
1948 pr_err("no active Intel(R) RAID "
1949 "controller found under %s\n",controller_path
);
1954 static int export_detail_platform_imsm(int verbose
, char *controller_path
)
1956 const struct imsm_orom
*orom
;
1957 struct sys_dev
*list
, *hba
;
1960 list
= find_intel_devices();
1963 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_INTEL_DEVICES\n");
1968 for (hba
= list
; hba
; hba
= hba
->next
) {
1969 if (controller_path
&& (compare_paths(hba
->path
,controller_path
) != 0))
1971 orom
= find_imsm_capability(hba
);
1974 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_IMSM_CAPABLE_DEVICE_UNDER_%s\n",hba
->path
);
1977 print_imsm_capability_export(orom
);
1987 static int match_home_imsm(struct supertype
*st
, char *homehost
)
1989 /* the imsm metadata format does not specify any host
1990 * identification information. We return -1 since we can never
1991 * confirm nor deny whether a given array is "meant" for this
1992 * host. We rely on compare_super and the 'family_num' fields to
1993 * exclude member disks that do not belong, and we rely on
1994 * mdadm.conf to specify the arrays that should be assembled.
1995 * Auto-assembly may still pick up "foreign" arrays.
2001 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
2003 /* The uuid returned here is used for:
2004 * uuid to put into bitmap file (Create, Grow)
2005 * uuid for backup header when saving critical section (Grow)
2006 * comparing uuids when re-adding a device into an array
2007 * In these cases the uuid required is that of the data-array,
2008 * not the device-set.
2009 * uuid to recognise same set when adding a missing device back
2010 * to an array. This is a uuid for the device-set.
2012 * For each of these we can make do with a truncated
2013 * or hashed uuid rather than the original, as long as
2015 * In each case the uuid required is that of the data-array,
2016 * not the device-set.
2018 /* imsm does not track uuid's so we synthesis one using sha1 on
2019 * - The signature (Which is constant for all imsm array, but no matter)
2020 * - the orig_family_num of the container
2021 * - the index number of the volume
2022 * - the 'serial' number of the volume.
2023 * Hopefully these are all constant.
2025 struct intel_super
*super
= st
->sb
;
2028 struct sha1_ctx ctx
;
2029 struct imsm_dev
*dev
= NULL
;
2032 /* some mdadm versions failed to set ->orig_family_num, in which
2033 * case fall back to ->family_num. orig_family_num will be
2034 * fixed up with the first metadata update.
2036 family_num
= super
->anchor
->orig_family_num
;
2037 if (family_num
== 0)
2038 family_num
= super
->anchor
->family_num
;
2039 sha1_init_ctx(&ctx
);
2040 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
2041 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
2042 if (super
->current_vol
>= 0)
2043 dev
= get_imsm_dev(super
, super
->current_vol
);
2045 __u32 vol
= super
->current_vol
;
2046 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
2047 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
2049 sha1_finish_ctx(&ctx
, buf
);
2050 memcpy(uuid
, buf
, 4*4);
2055 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
2057 __u8
*v
= get_imsm_version(mpb
);
2058 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
2059 char major
[] = { 0, 0, 0 };
2060 char minor
[] = { 0 ,0, 0 };
2061 char patch
[] = { 0, 0, 0 };
2062 char *ver_parse
[] = { major
, minor
, patch
};
2066 while (*v
!= '\0' && v
< end
) {
2067 if (*v
!= '.' && j
< 2)
2068 ver_parse
[i
][j
++] = *v
;
2076 *m
= strtol(minor
, NULL
, 0);
2077 *p
= strtol(patch
, NULL
, 0);
2081 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
2083 /* migr_strip_size when repairing or initializing parity */
2084 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2085 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2087 switch (get_imsm_raid_level(map
)) {
2092 return 128*1024 >> 9;
2096 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
2098 /* migr_strip_size when rebuilding a degraded disk, no idea why
2099 * this is different than migr_strip_size_resync(), but it's good
2102 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2103 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2105 switch (get_imsm_raid_level(map
)) {
2108 if (map
->num_members
% map
->num_domains
== 0)
2109 return 128*1024 >> 9;
2113 return max((__u32
) 64*1024 >> 9, chunk
);
2115 return 128*1024 >> 9;
2119 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
2121 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2122 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2123 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
2124 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
2126 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
2129 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
2131 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2132 int level
= get_imsm_raid_level(lo
);
2134 if (level
== 1 || level
== 10) {
2135 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2137 return hi
->num_domains
;
2139 return num_stripes_per_unit_resync(dev
);
2142 static __u8
imsm_num_data_members(struct imsm_dev
*dev
, int second_map
)
2144 /* named 'imsm_' because raid0, raid1 and raid10
2145 * counter-intuitively have the same number of data disks
2147 struct imsm_map
*map
= get_imsm_map(dev
, second_map
);
2149 switch (get_imsm_raid_level(map
)) {
2151 return map
->num_members
;
2155 return map
->num_members
/2;
2157 return map
->num_members
- 1;
2159 dprintf("%s: unsupported raid level\n", __func__
);
2164 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
2166 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2167 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2169 switch(get_imsm_raid_level(map
)) {
2172 return chunk
* map
->num_domains
;
2174 return chunk
* map
->num_members
;
2180 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
2182 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2183 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2184 __u32 strip
= block
/ chunk
;
2186 switch (get_imsm_raid_level(map
)) {
2189 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
2190 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
2192 return vol_stripe
* chunk
+ block
% chunk
;
2194 __u32 stripe
= strip
/ (map
->num_members
- 1);
2196 return stripe
* chunk
+ block
% chunk
;
2203 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
2204 struct imsm_dev
*dev
)
2206 /* calculate the conversion factor between per member 'blocks'
2207 * (md/{resync,rebuild}_start) and imsm migration units, return
2208 * 0 for the 'not migrating' and 'unsupported migration' cases
2210 if (!dev
->vol
.migr_state
)
2213 switch (migr_type(dev
)) {
2214 case MIGR_GEN_MIGR
: {
2215 struct migr_record
*migr_rec
= super
->migr_rec
;
2216 return __le32_to_cpu(migr_rec
->blocks_per_unit
);
2221 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2222 __u32 stripes_per_unit
;
2223 __u32 blocks_per_unit
;
2232 /* yes, this is really the translation of migr_units to
2233 * per-member blocks in the 'resync' case
2235 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
2236 migr_chunk
= migr_strip_blocks_resync(dev
);
2237 disks
= imsm_num_data_members(dev
, MAP_0
);
2238 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
2239 stripe
= __le16_to_cpu(map
->blocks_per_strip
) * disks
;
2240 segment
= blocks_per_unit
/ stripe
;
2241 block_rel
= blocks_per_unit
- segment
* stripe
;
2242 parity_depth
= parity_segment_depth(dev
);
2243 block_map
= map_migr_block(dev
, block_rel
);
2244 return block_map
+ parity_depth
* segment
;
2246 case MIGR_REBUILD
: {
2247 __u32 stripes_per_unit
;
2250 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
2251 migr_chunk
= migr_strip_blocks_rebuild(dev
);
2252 return migr_chunk
* stripes_per_unit
;
2254 case MIGR_STATE_CHANGE
:
2260 static int imsm_level_to_layout(int level
)
2268 return ALGORITHM_LEFT_ASYMMETRIC
;
2275 /*******************************************************************************
2276 * Function: read_imsm_migr_rec
2277 * Description: Function reads imsm migration record from last sector of disk
2279 * fd : disk descriptor
2280 * super : metadata info
2284 ******************************************************************************/
2285 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
)
2288 unsigned long long dsize
;
2290 get_dev_size(fd
, NULL
, &dsize
);
2291 if (lseek64(fd
, dsize
- MIGR_REC_POSITION
, SEEK_SET
) < 0) {
2292 pr_err("Cannot seek to anchor block: %s\n",
2296 if (read(fd
, super
->migr_rec_buf
, MIGR_REC_BUF_SIZE
) !=
2297 MIGR_REC_BUF_SIZE
) {
2298 pr_err("Cannot read migr record block: %s\n",
2308 static struct imsm_dev
*imsm_get_device_during_migration(
2309 struct intel_super
*super
)
2312 struct intel_dev
*dv
;
2314 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
2315 if (is_gen_migration(dv
->dev
))
2321 /*******************************************************************************
2322 * Function: load_imsm_migr_rec
2323 * Description: Function reads imsm migration record (it is stored at the last
2326 * super : imsm internal array info
2327 * info : general array info
2331 * -2 : no migration in progress
2332 ******************************************************************************/
2333 static int load_imsm_migr_rec(struct intel_super
*super
, struct mdinfo
*info
)
2336 struct dl
*dl
= NULL
;
2340 struct imsm_dev
*dev
;
2341 struct imsm_map
*map
= NULL
;
2344 /* find map under migration */
2345 dev
= imsm_get_device_during_migration(super
);
2346 /* nothing to load,no migration in progress?
2350 map
= get_imsm_map(dev
, MAP_0
);
2353 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
2354 /* skip spare and failed disks
2356 if (sd
->disk
.raid_disk
< 0)
2358 /* read only from one of the first two slots */
2360 slot
= get_imsm_disk_slot(map
,
2361 sd
->disk
.raid_disk
);
2362 if ((map
== NULL
) || (slot
> 1) || (slot
< 0))
2365 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
2366 fd
= dev_open(nm
, O_RDONLY
);
2372 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
2373 /* skip spare and failed disks
2377 /* read only from one of the first two slots */
2379 slot
= get_imsm_disk_slot(map
, dl
->index
);
2380 if ((map
== NULL
) || (slot
> 1) || (slot
< 0))
2382 sprintf(nm
, "%d:%d", dl
->major
, dl
->minor
);
2383 fd
= dev_open(nm
, O_RDONLY
);
2390 retval
= read_imsm_migr_rec(fd
, super
);
2399 /*******************************************************************************
2400 * function: imsm_create_metadata_checkpoint_update
2401 * Description: It creates update for checkpoint change.
2403 * super : imsm internal array info
2404 * u : pointer to prepared update
2407 * If length is equal to 0, input pointer u contains no update
2408 ******************************************************************************/
2409 static int imsm_create_metadata_checkpoint_update(
2410 struct intel_super
*super
,
2411 struct imsm_update_general_migration_checkpoint
**u
)
2414 int update_memory_size
= 0;
2416 dprintf("imsm_create_metadata_checkpoint_update(enter)\n");
2422 /* size of all update data without anchor */
2423 update_memory_size
=
2424 sizeof(struct imsm_update_general_migration_checkpoint
);
2426 *u
= xcalloc(1, update_memory_size
);
2428 dprintf("error: cannot get memory for "
2429 "imsm_create_metadata_checkpoint_update update\n");
2432 (*u
)->type
= update_general_migration_checkpoint
;
2433 (*u
)->curr_migr_unit
= __le32_to_cpu(super
->migr_rec
->curr_migr_unit
);
2434 dprintf("imsm_create_metadata_checkpoint_update: prepared for %u\n",
2435 (*u
)->curr_migr_unit
);
2437 return update_memory_size
;
2440 static void imsm_update_metadata_locally(struct supertype
*st
,
2441 void *buf
, int len
);
2443 /*******************************************************************************
2444 * Function: write_imsm_migr_rec
2445 * Description: Function writes imsm migration record
2446 * (at the last sector of disk)
2448 * super : imsm internal array info
2452 ******************************************************************************/
2453 static int write_imsm_migr_rec(struct supertype
*st
)
2455 struct intel_super
*super
= st
->sb
;
2456 unsigned long long dsize
;
2462 struct imsm_update_general_migration_checkpoint
*u
;
2463 struct imsm_dev
*dev
;
2464 struct imsm_map
*map
= NULL
;
2466 /* find map under migration */
2467 dev
= imsm_get_device_during_migration(super
);
2468 /* if no migration, write buffer anyway to clear migr_record
2469 * on disk based on first available device
2472 dev
= get_imsm_dev(super
, super
->current_vol
< 0 ? 0 :
2473 super
->current_vol
);
2475 map
= get_imsm_map(dev
, MAP_0
);
2477 for (sd
= super
->disks
; sd
; sd
= sd
->next
) {
2480 /* skip failed and spare devices */
2483 /* write to 2 first slots only */
2485 slot
= get_imsm_disk_slot(map
, sd
->index
);
2486 if ((map
== NULL
) || (slot
> 1) || (slot
< 0))
2489 sprintf(nm
, "%d:%d", sd
->major
, sd
->minor
);
2490 fd
= dev_open(nm
, O_RDWR
);
2493 get_dev_size(fd
, NULL
, &dsize
);
2494 if (lseek64(fd
, dsize
- MIGR_REC_POSITION
, SEEK_SET
) < 0) {
2495 pr_err("Cannot seek to anchor block: %s\n",
2499 if (write(fd
, super
->migr_rec_buf
, MIGR_REC_BUF_SIZE
) !=
2500 MIGR_REC_BUF_SIZE
) {
2501 pr_err("Cannot write migr record block: %s\n",
2508 /* update checkpoint information in metadata */
2509 len
= imsm_create_metadata_checkpoint_update(super
, &u
);
2512 dprintf("imsm: Cannot prepare update\n");
2515 /* update metadata locally */
2516 imsm_update_metadata_locally(st
, u
, len
);
2517 /* and possibly remotely */
2518 if (st
->update_tail
) {
2519 append_metadata_update(st
, u
, len
);
2520 /* during reshape we do all work inside metadata handler
2521 * manage_reshape(), so metadata update has to be triggered
2524 flush_metadata_updates(st
);
2525 st
->update_tail
= &st
->updates
;
2535 #endif /* MDASSEMBLE */
2537 /* spare/missing disks activations are not allowe when
2538 * array/container performs reshape operation, because
2539 * all arrays in container works on the same disks set
2541 int imsm_reshape_blocks_arrays_changes(struct intel_super
*super
)
2544 struct intel_dev
*i_dev
;
2545 struct imsm_dev
*dev
;
2547 /* check whole container
2549 for (i_dev
= super
->devlist
; i_dev
; i_dev
= i_dev
->next
) {
2551 if (is_gen_migration(dev
)) {
2552 /* No repair during any migration in container
2560 static unsigned long long imsm_component_size_aligment_check(int level
,
2562 unsigned long long component_size
)
2564 unsigned int component_size_alligment
;
2566 /* check component size aligment
2568 component_size_alligment
= component_size
% (chunk_size
/512);
2570 dprintf("imsm_component_size_aligment_check(Level: %i, "
2571 "chunk_size = %i, component_size = %llu), "
2572 "component_size_alligment = %u\n",
2573 level
, chunk_size
, component_size
,
2574 component_size_alligment
);
2576 if (component_size_alligment
&& (level
!= 1) && (level
!= UnSet
)) {
2577 dprintf("imsm: reported component size alligned from %llu ",
2579 component_size
-= component_size_alligment
;
2580 dprintf("to %llu (%i).\n",
2581 component_size
, component_size_alligment
);
2584 return component_size
;
2587 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
2589 struct intel_super
*super
= st
->sb
;
2590 struct migr_record
*migr_rec
= super
->migr_rec
;
2591 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
2592 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2593 struct imsm_map
*prev_map
= get_imsm_map(dev
, MAP_1
);
2594 struct imsm_map
*map_to_analyse
= map
;
2596 int map_disks
= info
->array
.raid_disks
;
2598 memset(info
, 0, sizeof(*info
));
2600 map_to_analyse
= prev_map
;
2602 dl
= super
->current_disk
;
2604 info
->container_member
= super
->current_vol
;
2605 info
->array
.raid_disks
= map
->num_members
;
2606 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
2607 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
2608 info
->array
.md_minor
= -1;
2609 info
->array
.ctime
= 0;
2610 info
->array
.utime
= 0;
2611 info
->array
.chunk_size
=
2612 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
2613 info
->array
.state
= !dev
->vol
.dirty
;
2614 info
->custom_array_size
= __le32_to_cpu(dev
->size_high
);
2615 info
->custom_array_size
<<= 32;
2616 info
->custom_array_size
|= __le32_to_cpu(dev
->size_low
);
2617 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
2619 if (is_gen_migration(dev
)) {
2620 info
->reshape_active
= 1;
2621 info
->new_level
= get_imsm_raid_level(map
);
2622 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
2623 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
2624 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
2625 if (info
->delta_disks
) {
2626 /* this needs to be applied to every array
2629 info
->reshape_active
= CONTAINER_RESHAPE
;
2631 /* We shape information that we give to md might have to be
2632 * modify to cope with md's requirement for reshaping arrays.
2633 * For example, when reshaping a RAID0, md requires it to be
2634 * presented as a degraded RAID4.
2635 * Also if a RAID0 is migrating to a RAID5 we need to specify
2636 * the array as already being RAID5, but the 'before' layout
2637 * is a RAID4-like layout.
2639 switch (info
->array
.level
) {
2641 switch(info
->new_level
) {
2643 /* conversion is happening as RAID4 */
2644 info
->array
.level
= 4;
2645 info
->array
.raid_disks
+= 1;
2648 /* conversion is happening as RAID5 */
2649 info
->array
.level
= 5;
2650 info
->array
.layout
= ALGORITHM_PARITY_N
;
2651 info
->delta_disks
-= 1;
2654 /* FIXME error message */
2655 info
->array
.level
= UnSet
;
2661 info
->new_level
= UnSet
;
2662 info
->new_layout
= UnSet
;
2663 info
->new_chunk
= info
->array
.chunk_size
;
2664 info
->delta_disks
= 0;
2668 info
->disk
.major
= dl
->major
;
2669 info
->disk
.minor
= dl
->minor
;
2670 info
->disk
.number
= dl
->index
;
2671 info
->disk
.raid_disk
= get_imsm_disk_slot(map_to_analyse
,
2675 info
->data_offset
= pba_of_lba0(map_to_analyse
);
2676 info
->component_size
= blocks_per_member(map_to_analyse
);
2678 info
->component_size
= imsm_component_size_aligment_check(
2680 info
->array
.chunk_size
,
2681 info
->component_size
);
2683 memset(info
->uuid
, 0, sizeof(info
->uuid
));
2684 info
->recovery_start
= MaxSector
;
2686 info
->reshape_progress
= 0;
2687 info
->resync_start
= MaxSector
;
2688 if ((map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
2690 imsm_reshape_blocks_arrays_changes(super
) == 0) {
2691 info
->resync_start
= 0;
2693 if (dev
->vol
.migr_state
) {
2694 switch (migr_type(dev
)) {
2697 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
2699 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
2701 info
->resync_start
= blocks_per_unit
* units
;
2704 case MIGR_GEN_MIGR
: {
2705 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
2707 __u64 units
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
2708 unsigned long long array_blocks
;
2711 if (__le32_to_cpu(migr_rec
->ascending_migr
) &&
2713 (__le32_to_cpu(migr_rec
->num_migr_units
)-1)) &&
2714 (super
->migr_rec
->rec_status
==
2715 __cpu_to_le32(UNIT_SRC_IN_CP_AREA
)))
2718 info
->reshape_progress
= blocks_per_unit
* units
;
2720 dprintf("IMSM: General Migration checkpoint : %llu "
2721 "(%llu) -> read reshape progress : %llu\n",
2722 (unsigned long long)units
,
2723 (unsigned long long)blocks_per_unit
,
2724 info
->reshape_progress
);
2726 used_disks
= imsm_num_data_members(dev
, MAP_1
);
2727 if (used_disks
> 0) {
2728 array_blocks
= blocks_per_member(map
) *
2730 /* round array size down to closest MB
2732 info
->custom_array_size
= (array_blocks
2733 >> SECT_PER_MB_SHIFT
)
2734 << SECT_PER_MB_SHIFT
;
2738 /* we could emulate the checkpointing of
2739 * 'sync_action=check' migrations, but for now
2740 * we just immediately complete them
2743 /* this is handled by container_content_imsm() */
2744 case MIGR_STATE_CHANGE
:
2745 /* FIXME handle other migrations */
2747 /* we are not dirty, so... */
2748 info
->resync_start
= MaxSector
;
2752 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
2753 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
2755 info
->array
.major_version
= -1;
2756 info
->array
.minor_version
= -2;
2757 sprintf(info
->text_version
, "/%s/%d", st
->container_devnm
, info
->container_member
);
2758 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
2759 uuid_from_super_imsm(st
, info
->uuid
);
2763 for (i
=0; i
<map_disks
; i
++) {
2765 if (i
< info
->array
.raid_disks
) {
2766 struct imsm_disk
*dsk
;
2767 j
= get_imsm_disk_idx(dev
, i
, MAP_X
);
2768 dsk
= get_imsm_disk(super
, j
);
2769 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
2776 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
2777 int failed
, int look_in_map
);
2779 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
2783 static void manage_second_map(struct intel_super
*super
, struct imsm_dev
*dev
)
2785 if (is_gen_migration(dev
)) {
2788 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
2790 failed
= imsm_count_failed(super
, dev
, MAP_1
);
2791 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_1
);
2792 if (map2
->map_state
!= map_state
) {
2793 map2
->map_state
= map_state
;
2794 super
->updates_pending
++;
2800 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
2804 for (d
= super
->missing
; d
; d
= d
->next
)
2805 if (d
->index
== index
)
2810 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
2812 struct intel_super
*super
= st
->sb
;
2813 struct imsm_disk
*disk
;
2814 int map_disks
= info
->array
.raid_disks
;
2815 int max_enough
= -1;
2817 struct imsm_super
*mpb
;
2819 if (super
->current_vol
>= 0) {
2820 getinfo_super_imsm_volume(st
, info
, map
);
2823 memset(info
, 0, sizeof(*info
));
2825 /* Set raid_disks to zero so that Assemble will always pull in valid
2828 info
->array
.raid_disks
= 0;
2829 info
->array
.level
= LEVEL_CONTAINER
;
2830 info
->array
.layout
= 0;
2831 info
->array
.md_minor
= -1;
2832 info
->array
.ctime
= 0; /* N/A for imsm */
2833 info
->array
.utime
= 0;
2834 info
->array
.chunk_size
= 0;
2836 info
->disk
.major
= 0;
2837 info
->disk
.minor
= 0;
2838 info
->disk
.raid_disk
= -1;
2839 info
->reshape_active
= 0;
2840 info
->array
.major_version
= -1;
2841 info
->array
.minor_version
= -2;
2842 strcpy(info
->text_version
, "imsm");
2843 info
->safe_mode_delay
= 0;
2844 info
->disk
.number
= -1;
2845 info
->disk
.state
= 0;
2847 info
->recovery_start
= MaxSector
;
2848 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
2850 /* do we have the all the insync disks that we expect? */
2851 mpb
= super
->anchor
;
2853 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
2854 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
2855 int failed
, enough
, j
, missing
= 0;
2856 struct imsm_map
*map
;
2859 failed
= imsm_count_failed(super
, dev
, MAP_0
);
2860 state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
2861 map
= get_imsm_map(dev
, MAP_0
);
2863 /* any newly missing disks?
2864 * (catches single-degraded vs double-degraded)
2866 for (j
= 0; j
< map
->num_members
; j
++) {
2867 __u32 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
2868 __u32 idx
= ord_to_idx(ord
);
2870 if (!(ord
& IMSM_ORD_REBUILD
) &&
2871 get_imsm_missing(super
, idx
)) {
2877 if (state
== IMSM_T_STATE_FAILED
)
2879 else if (state
== IMSM_T_STATE_DEGRADED
&&
2880 (state
!= map
->map_state
|| missing
))
2882 else /* we're normal, or already degraded */
2884 if (is_gen_migration(dev
) && missing
) {
2885 /* during general migration we need all disks
2886 * that process is running on.
2887 * No new missing disk is allowed.
2891 /* no more checks necessary
2895 /* in the missing/failed disk case check to see
2896 * if at least one array is runnable
2898 max_enough
= max(max_enough
, enough
);
2900 dprintf("%s: enough: %d\n", __func__
, max_enough
);
2901 info
->container_enough
= max_enough
;
2904 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
2906 disk
= &super
->disks
->disk
;
2907 info
->data_offset
= total_blocks(&super
->disks
->disk
) - reserved
;
2908 info
->component_size
= reserved
;
2909 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
2910 /* we don't change info->disk.raid_disk here because
2911 * this state will be finalized in mdmon after we have
2912 * found the 'most fresh' version of the metadata
2914 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
2915 info
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
2918 /* only call uuid_from_super_imsm when this disk is part of a populated container,
2919 * ->compare_super may have updated the 'num_raid_devs' field for spares
2921 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
2922 uuid_from_super_imsm(st
, info
->uuid
);
2924 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
2926 /* I don't know how to compute 'map' on imsm, so use safe default */
2929 for (i
= 0; i
< map_disks
; i
++)
2935 /* allocates memory and fills disk in mdinfo structure
2936 * for each disk in array */
2937 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
2939 struct mdinfo
*mddev
= NULL
;
2940 struct intel_super
*super
= st
->sb
;
2941 struct imsm_disk
*disk
;
2944 if (!super
|| !super
->disks
)
2947 mddev
= xcalloc(1, sizeof(*mddev
));
2951 tmp
= xcalloc(1, sizeof(*tmp
));
2953 tmp
->next
= mddev
->devs
;
2955 tmp
->disk
.number
= count
++;
2956 tmp
->disk
.major
= dl
->major
;
2957 tmp
->disk
.minor
= dl
->minor
;
2958 tmp
->disk
.state
= is_configured(disk
) ?
2959 (1 << MD_DISK_ACTIVE
) : 0;
2960 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
2961 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
2962 tmp
->disk
.raid_disk
= -1;
2968 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
2969 char *update
, char *devname
, int verbose
,
2970 int uuid_set
, char *homehost
)
2972 /* For 'assemble' and 'force' we need to return non-zero if any
2973 * change was made. For others, the return value is ignored.
2974 * Update options are:
2975 * force-one : This device looks a bit old but needs to be included,
2976 * update age info appropriately.
2977 * assemble: clear any 'faulty' flag to allow this device to
2979 * force-array: Array is degraded but being forced, mark it clean
2980 * if that will be needed to assemble it.
2982 * newdev: not used ????
2983 * grow: Array has gained a new device - this is currently for
2985 * resync: mark as dirty so a resync will happen.
2986 * name: update the name - preserving the homehost
2987 * uuid: Change the uuid of the array to match watch is given
2989 * Following are not relevant for this imsm:
2990 * sparc2.2 : update from old dodgey metadata
2991 * super-minor: change the preferred_minor number
2992 * summaries: update redundant counters.
2993 * homehost: update the recorded homehost
2994 * _reshape_progress: record new reshape_progress position.
2997 struct intel_super
*super
= st
->sb
;
2998 struct imsm_super
*mpb
;
3000 /* we can only update container info */
3001 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
3004 mpb
= super
->anchor
;
3006 if (strcmp(update
, "uuid") == 0) {
3007 /* We take this to mean that the family_num should be updated.
3008 * However that is much smaller than the uuid so we cannot really
3009 * allow an explicit uuid to be given. And it is hard to reliably
3011 * So if !uuid_set we know the current uuid is random and just used
3012 * the first 'int' and copy it to the other 3 positions.
3013 * Otherwise we require the 4 'int's to be the same as would be the
3014 * case if we are using a random uuid. So an explicit uuid will be
3015 * accepted as long as all for ints are the same... which shouldn't hurt
3018 info
->uuid
[1] = info
->uuid
[2] = info
->uuid
[3] = info
->uuid
[0];
3021 if (info
->uuid
[0] != info
->uuid
[1] ||
3022 info
->uuid
[1] != info
->uuid
[2] ||
3023 info
->uuid
[2] != info
->uuid
[3])
3029 mpb
->orig_family_num
= info
->uuid
[0];
3030 } else if (strcmp(update
, "assemble") == 0)
3035 /* successful update? recompute checksum */
3037 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
3042 static size_t disks_to_mpb_size(int disks
)
3046 size
= sizeof(struct imsm_super
);
3047 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
3048 size
+= 2 * sizeof(struct imsm_dev
);
3049 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
3050 size
+= (4 - 2) * sizeof(struct imsm_map
);
3051 /* 4 possible disk_ord_tbl's */
3052 size
+= 4 * (disks
- 1) * sizeof(__u32
);
3057 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
,
3058 unsigned long long data_offset
)
3060 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
3063 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
3066 static void free_devlist(struct intel_super
*super
)
3068 struct intel_dev
*dv
;
3070 while (super
->devlist
) {
3071 dv
= super
->devlist
->next
;
3072 free(super
->devlist
->dev
);
3073 free(super
->devlist
);
3074 super
->devlist
= dv
;
3078 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
3080 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
3083 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
)
3087 * 0 same, or first was empty, and second was copied
3088 * 1 second had wrong number
3090 * 3 wrong other info
3092 struct intel_super
*first
= st
->sb
;
3093 struct intel_super
*sec
= tst
->sb
;
3100 /* in platform dependent environment test if the disks
3101 * use the same Intel hba
3102 * If not on Intel hba at all, allow anything.
3104 if (!check_env("IMSM_NO_PLATFORM") && first
->hba
&& sec
->hba
) {
3105 if (first
->hba
->type
!= sec
->hba
->type
) {
3107 "HBAs of devices do not match %s != %s\n",
3108 get_sys_dev_type(first
->hba
->type
),
3109 get_sys_dev_type(sec
->hba
->type
));
3112 if (first
->orom
!= sec
->orom
) {
3114 "HBAs of devices do not match %s != %s\n",
3115 first
->hba
->pci_id
, sec
->hba
->pci_id
);
3120 /* if an anchor does not have num_raid_devs set then it is a free
3123 if (first
->anchor
->num_raid_devs
> 0 &&
3124 sec
->anchor
->num_raid_devs
> 0) {
3125 /* Determine if these disks might ever have been
3126 * related. Further disambiguation can only take place
3127 * in load_super_imsm_all
3129 __u32 first_family
= first
->anchor
->orig_family_num
;
3130 __u32 sec_family
= sec
->anchor
->orig_family_num
;
3132 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
3133 MAX_SIGNATURE_LENGTH
) != 0)
3136 if (first_family
== 0)
3137 first_family
= first
->anchor
->family_num
;
3138 if (sec_family
== 0)
3139 sec_family
= sec
->anchor
->family_num
;
3141 if (first_family
!= sec_family
)
3146 /* if 'first' is a spare promote it to a populated mpb with sec's
3149 if (first
->anchor
->num_raid_devs
== 0 &&
3150 sec
->anchor
->num_raid_devs
> 0) {
3152 struct intel_dev
*dv
;
3153 struct imsm_dev
*dev
;
3155 /* we need to copy raid device info from sec if an allocation
3156 * fails here we don't associate the spare
3158 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++) {
3159 dv
= xmalloc(sizeof(*dv
));
3160 dev
= xmalloc(sizeof_imsm_dev(get_imsm_dev(sec
, i
), 1));
3163 dv
->next
= first
->devlist
;
3164 first
->devlist
= dv
;
3166 if (i
< sec
->anchor
->num_raid_devs
) {
3167 /* allocation failure */
3168 free_devlist(first
);
3169 pr_err("imsm: failed to associate spare\n");
3172 first
->anchor
->num_raid_devs
= sec
->anchor
->num_raid_devs
;
3173 first
->anchor
->orig_family_num
= sec
->anchor
->orig_family_num
;
3174 first
->anchor
->family_num
= sec
->anchor
->family_num
;
3175 memcpy(first
->anchor
->sig
, sec
->anchor
->sig
, MAX_SIGNATURE_LENGTH
);
3176 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++)
3177 imsm_copy_dev(get_imsm_dev(first
, i
), get_imsm_dev(sec
, i
));
3183 static void fd2devname(int fd
, char *name
)
3187 char dname
[PATH_MAX
];
3192 if (fstat(fd
, &st
) != 0)
3194 sprintf(path
, "/sys/dev/block/%d:%d",
3195 major(st
.st_rdev
), minor(st
.st_rdev
));
3197 rv
= readlink(path
, dname
, sizeof(dname
)-1);
3202 nm
= strrchr(dname
, '/');
3205 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
3209 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
3211 static int imsm_read_serial(int fd
, char *devname
,
3212 __u8 serial
[MAX_RAID_SERIAL_LEN
])
3214 unsigned char scsi_serial
[255];
3223 memset(scsi_serial
, 0, sizeof(scsi_serial
));
3225 rv
= scsi_get_serial(fd
, scsi_serial
, sizeof(scsi_serial
));
3227 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
3228 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3229 fd2devname(fd
, (char *) serial
);
3235 pr_err("Failed to retrieve serial for %s\n",
3240 rsp_len
= scsi_serial
[3];
3243 pr_err("Failed to retrieve serial for %s\n",
3247 rsp_buf
= (char *) &scsi_serial
[4];
3249 /* trim all whitespace and non-printable characters and convert
3252 for (i
= 0, dest
= rsp_buf
; i
< rsp_len
; i
++) {
3255 /* ':' is reserved for use in placeholder serial
3256 * numbers for missing disks
3264 len
= dest
- rsp_buf
;
3267 /* truncate leading characters */
3268 if (len
> MAX_RAID_SERIAL_LEN
) {
3269 dest
+= len
- MAX_RAID_SERIAL_LEN
;
3270 len
= MAX_RAID_SERIAL_LEN
;
3273 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3274 memcpy(serial
, dest
, len
);
3279 static int serialcmp(__u8
*s1
, __u8
*s2
)
3281 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
3284 static void serialcpy(__u8
*dest
, __u8
*src
)
3286 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
3289 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
3293 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3294 if (serialcmp(dl
->serial
, serial
) == 0)
3300 static struct imsm_disk
*
3301 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
3305 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3306 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
3308 if (serialcmp(disk
->serial
, serial
) == 0) {
3319 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3321 struct imsm_disk
*disk
;
3326 __u8 serial
[MAX_RAID_SERIAL_LEN
];
3328 rv
= imsm_read_serial(fd
, devname
, serial
);
3333 dl
= xcalloc(1, sizeof(*dl
));
3336 dl
->major
= major(stb
.st_rdev
);
3337 dl
->minor
= minor(stb
.st_rdev
);
3338 dl
->next
= super
->disks
;
3339 dl
->fd
= keep_fd
? fd
: -1;
3340 assert(super
->disks
== NULL
);
3342 serialcpy(dl
->serial
, serial
);
3345 fd2devname(fd
, name
);
3347 dl
->devname
= xstrdup(devname
);
3349 dl
->devname
= xstrdup(name
);
3351 /* look up this disk's index in the current anchor */
3352 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
3355 /* only set index on disks that are a member of a
3356 * populated contianer, i.e. one with raid_devs
3358 if (is_failed(&dl
->disk
))
3360 else if (is_spare(&dl
->disk
))
3368 /* When migrating map0 contains the 'destination' state while map1
3369 * contains the current state. When not migrating map0 contains the
3370 * current state. This routine assumes that map[0].map_state is set to
3371 * the current array state before being called.
3373 * Migration is indicated by one of the following states
3374 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
3375 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
3376 * map1state=unitialized)
3377 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
3379 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
3380 * map1state=degraded)
3381 * 5/ Migration (mig_state=1 migr_type=MIGR_GEN_MIGR map0state=normal
3384 static void migrate(struct imsm_dev
*dev
, struct intel_super
*super
,
3385 __u8 to_state
, int migr_type
)
3387 struct imsm_map
*dest
;
3388 struct imsm_map
*src
= get_imsm_map(dev
, MAP_0
);
3390 dev
->vol
.migr_state
= 1;
3391 set_migr_type(dev
, migr_type
);
3392 dev
->vol
.curr_migr_unit
= 0;
3393 dest
= get_imsm_map(dev
, MAP_1
);
3395 /* duplicate and then set the target end state in map[0] */
3396 memcpy(dest
, src
, sizeof_imsm_map(src
));
3397 if ((migr_type
== MIGR_REBUILD
) ||
3398 (migr_type
== MIGR_GEN_MIGR
)) {
3402 for (i
= 0; i
< src
->num_members
; i
++) {
3403 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
3404 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
3408 if (migr_type
== MIGR_GEN_MIGR
)
3409 /* Clear migration record */
3410 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
3412 src
->map_state
= to_state
;
3415 static void end_migration(struct imsm_dev
*dev
, struct intel_super
*super
,
3418 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3419 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
== 0 ?
3423 /* merge any IMSM_ORD_REBUILD bits that were not successfully
3424 * completed in the last migration.
3426 * FIXME add support for raid-level-migration
3428 if ((map_state
!= map
->map_state
) && (is_gen_migration(dev
) == 0) &&
3429 (prev
->map_state
!= IMSM_T_STATE_UNINITIALIZED
)) {
3430 /* when final map state is other than expected
3431 * merge maps (not for migration)
3435 for (i
= 0; i
< prev
->num_members
; i
++)
3436 for (j
= 0; j
< map
->num_members
; j
++)
3437 /* during online capacity expansion
3438 * disks position can be changed
3439 * if takeover is used
3441 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
3442 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
3443 map
->disk_ord_tbl
[j
] |=
3444 prev
->disk_ord_tbl
[i
];
3447 failed
= imsm_count_failed(super
, dev
, MAP_0
);
3448 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
3451 dev
->vol
.migr_state
= 0;
3452 set_migr_type(dev
, 0);
3453 dev
->vol
.curr_migr_unit
= 0;
3454 map
->map_state
= map_state
;
3458 static int parse_raid_devices(struct intel_super
*super
)
3461 struct imsm_dev
*dev_new
;
3462 size_t len
, len_migr
;
3464 size_t space_needed
= 0;
3465 struct imsm_super
*mpb
= super
->anchor
;
3467 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3468 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3469 struct intel_dev
*dv
;
3471 len
= sizeof_imsm_dev(dev_iter
, 0);
3472 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
3474 space_needed
+= len_migr
- len
;
3476 dv
= xmalloc(sizeof(*dv
));
3477 if (max_len
< len_migr
)
3479 if (max_len
> len_migr
)
3480 space_needed
+= max_len
- len_migr
;
3481 dev_new
= xmalloc(max_len
);
3482 imsm_copy_dev(dev_new
, dev_iter
);
3485 dv
->next
= super
->devlist
;
3486 super
->devlist
= dv
;
3489 /* ensure that super->buf is large enough when all raid devices
3492 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
3495 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
, 512);
3496 if (posix_memalign(&buf
, 512, len
) != 0)
3499 memcpy(buf
, super
->buf
, super
->len
);
3500 memset(buf
+ super
->len
, 0, len
- super
->len
);
3509 /* retrieve a pointer to the bbm log which starts after all raid devices */
3510 struct bbm_log
*__get_imsm_bbm_log(struct imsm_super
*mpb
)
3514 if (__le32_to_cpu(mpb
->bbm_log_size
)) {
3516 ptr
+= mpb
->mpb_size
- __le32_to_cpu(mpb
->bbm_log_size
);
3522 /*******************************************************************************
3523 * Function: check_mpb_migr_compatibility
3524 * Description: Function checks for unsupported migration features:
3525 * - migration optimization area (pba_of_lba0)
3526 * - descending reshape (ascending_migr)
3528 * super : imsm metadata information
3530 * 0 : migration is compatible
3531 * -1 : migration is not compatible
3532 ******************************************************************************/
3533 int check_mpb_migr_compatibility(struct intel_super
*super
)
3535 struct imsm_map
*map0
, *map1
;
3536 struct migr_record
*migr_rec
= super
->migr_rec
;
3539 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3540 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3543 dev_iter
->vol
.migr_state
== 1 &&
3544 dev_iter
->vol
.migr_type
== MIGR_GEN_MIGR
) {
3545 /* This device is migrating */
3546 map0
= get_imsm_map(dev_iter
, MAP_0
);
3547 map1
= get_imsm_map(dev_iter
, MAP_1
);
3548 if (pba_of_lba0(map0
) != pba_of_lba0(map1
))
3549 /* migration optimization area was used */
3551 if (migr_rec
->ascending_migr
== 0
3552 && migr_rec
->dest_depth_per_unit
> 0)
3553 /* descending reshape not supported yet */
3560 static void __free_imsm(struct intel_super
*super
, int free_disks
);
3562 /* load_imsm_mpb - read matrix metadata
3563 * allocates super->mpb to be freed by free_imsm
3565 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
3567 unsigned long long dsize
;
3568 unsigned long long sectors
;
3570 struct imsm_super
*anchor
;
3573 get_dev_size(fd
, NULL
, &dsize
);
3576 pr_err("%s: device to small for imsm\n",
3581 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0) {
3583 pr_err("Cannot seek to anchor block on %s: %s\n",
3584 devname
, strerror(errno
));
3588 if (posix_memalign((void**)&anchor
, 512, 512) != 0) {
3590 pr_err("Failed to allocate imsm anchor buffer"
3591 " on %s\n", devname
);
3594 if (read(fd
, anchor
, 512) != 512) {
3596 pr_err("Cannot read anchor block on %s: %s\n",
3597 devname
, strerror(errno
));
3602 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
3604 pr_err("no IMSM anchor on %s\n", devname
);
3609 __free_imsm(super
, 0);
3610 /* reload capability and hba */
3612 /* capability and hba must be updated with new super allocation */
3613 find_intel_hba_capability(fd
, super
, devname
);
3614 super
->len
= ROUND_UP(anchor
->mpb_size
, 512);
3615 if (posix_memalign(&super
->buf
, 512, super
->len
) != 0) {
3617 pr_err("unable to allocate %zu byte mpb buffer\n",
3622 memcpy(super
->buf
, anchor
, 512);
3624 sectors
= mpb_sectors(anchor
) - 1;
3627 if (posix_memalign(&super
->migr_rec_buf
, 512, MIGR_REC_BUF_SIZE
) != 0) {
3628 pr_err("%s could not allocate migr_rec buffer\n", __func__
);
3632 super
->clean_migration_record_by_mdmon
= 0;
3635 check_sum
= __gen_imsm_checksum(super
->anchor
);
3636 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
3638 pr_err("IMSM checksum %x != %x on %s\n",
3640 __le32_to_cpu(super
->anchor
->check_sum
),
3648 /* read the extended mpb */
3649 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0) {
3651 pr_err("Cannot seek to extended mpb on %s: %s\n",
3652 devname
, strerror(errno
));
3656 if ((unsigned)read(fd
, super
->buf
+ 512, super
->len
- 512) != super
->len
- 512) {
3658 pr_err("Cannot read extended mpb on %s: %s\n",
3659 devname
, strerror(errno
));
3663 check_sum
= __gen_imsm_checksum(super
->anchor
);
3664 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
3666 pr_err("IMSM checksum %x != %x on %s\n",
3667 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
3672 /* FIXME the BBM log is disk specific so we cannot use this global
3673 * buffer for all disks. Ok for now since we only look at the global
3674 * bbm_log_size parameter to gate assembly
3676 super
->bbm_log
= __get_imsm_bbm_log(super
->anchor
);
3681 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
);
3683 /* clears hi bits in metadata if MPB_ATTRIB_2TB_DISK not set */
3684 static void clear_hi(struct intel_super
*super
)
3686 struct imsm_super
*mpb
= super
->anchor
;
3688 if (mpb
->attributes
& MPB_ATTRIB_2TB_DISK
)
3690 for (i
= 0; i
< mpb
->num_disks
; ++i
) {
3691 struct imsm_disk
*disk
= &mpb
->disk
[i
];
3692 disk
->total_blocks_hi
= 0;
3694 for (i
= 0; i
< mpb
->num_raid_devs
; ++i
) {
3695 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
3698 for (n
= 0; n
< 2; ++n
) {
3699 struct imsm_map
*map
= get_imsm_map(dev
, n
);
3702 map
->pba_of_lba0_hi
= 0;
3703 map
->blocks_per_member_hi
= 0;
3704 map
->num_data_stripes_hi
= 0;
3710 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3714 err
= load_imsm_mpb(fd
, super
, devname
);
3717 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
3720 err
= parse_raid_devices(super
);
3725 static void __free_imsm_disk(struct dl
*d
)
3737 static void free_imsm_disks(struct intel_super
*super
)
3741 while (super
->disks
) {
3743 super
->disks
= d
->next
;
3744 __free_imsm_disk(d
);
3746 while (super
->disk_mgmt_list
) {
3747 d
= super
->disk_mgmt_list
;
3748 super
->disk_mgmt_list
= d
->next
;
3749 __free_imsm_disk(d
);
3751 while (super
->missing
) {
3753 super
->missing
= d
->next
;
3754 __free_imsm_disk(d
);
3759 /* free all the pieces hanging off of a super pointer */
3760 static void __free_imsm(struct intel_super
*super
, int free_disks
)
3762 struct intel_hba
*elem
, *next
;
3768 /* unlink capability description */
3770 if (super
->migr_rec_buf
) {
3771 free(super
->migr_rec_buf
);
3772 super
->migr_rec_buf
= NULL
;
3775 free_imsm_disks(super
);
3776 free_devlist(super
);
3780 free((void *)elem
->path
);
3788 static void free_imsm(struct intel_super
*super
)
3790 __free_imsm(super
, 1);
3794 static void free_super_imsm(struct supertype
*st
)
3796 struct intel_super
*super
= st
->sb
;
3805 static struct intel_super
*alloc_super(void)
3807 struct intel_super
*super
= xcalloc(1, sizeof(*super
));
3809 super
->current_vol
= -1;
3810 super
->create_offset
= ~((unsigned long long) 0);
3815 * find and allocate hba and OROM/EFI based on valid fd of RAID component device
3817 static int find_intel_hba_capability(int fd
, struct intel_super
*super
, char *devname
)
3819 struct sys_dev
*hba_name
;
3822 if ((fd
< 0) || check_env("IMSM_NO_PLATFORM")) {
3827 hba_name
= find_disk_attached_hba(fd
, NULL
);
3830 pr_err("%s is not attached to Intel(R) RAID controller.\n",
3834 rv
= attach_hba_to_super(super
, hba_name
);
3837 struct intel_hba
*hba
= super
->hba
;
3839 pr_err("%s is attached to Intel(R) %s RAID "
3840 "controller (%s),\n"
3841 " but the container is assigned to Intel(R) "
3842 "%s RAID controller (",
3845 hba_name
->pci_id
? : "Err!",
3846 get_sys_dev_type(hba_name
->type
));
3849 fprintf(stderr
, "%s", hba
->pci_id
? : "Err!");
3851 fprintf(stderr
, ", ");
3854 fprintf(stderr
, ").\n"
3855 " Mixing devices attached to different controllers "
3856 "is not allowed.\n");
3860 super
->orom
= find_imsm_capability(hba_name
);
3866 /* find_missing - helper routine for load_super_imsm_all that identifies
3867 * disks that have disappeared from the system. This routine relies on
3868 * the mpb being uptodate, which it is at load time.
3870 static int find_missing(struct intel_super
*super
)
3873 struct imsm_super
*mpb
= super
->anchor
;
3875 struct imsm_disk
*disk
;
3877 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3878 disk
= __get_imsm_disk(mpb
, i
);
3879 dl
= serial_to_dl(disk
->serial
, super
);
3883 dl
= xmalloc(sizeof(*dl
));
3887 dl
->devname
= xstrdup("missing");
3889 serialcpy(dl
->serial
, disk
->serial
);
3892 dl
->next
= super
->missing
;
3893 super
->missing
= dl
;
3900 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
3902 struct intel_disk
*idisk
= disk_list
;
3905 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
3907 idisk
= idisk
->next
;
3913 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
3914 struct intel_super
*super
,
3915 struct intel_disk
**disk_list
)
3917 struct imsm_disk
*d
= &super
->disks
->disk
;
3918 struct imsm_super
*mpb
= super
->anchor
;
3921 for (i
= 0; i
< tbl_size
; i
++) {
3922 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
3923 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
3925 if (tbl_mpb
->family_num
== mpb
->family_num
) {
3926 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
3927 dprintf("%s: mpb from %d:%d matches %d:%d\n",
3928 __func__
, super
->disks
->major
,
3929 super
->disks
->minor
,
3930 table
[i
]->disks
->major
,
3931 table
[i
]->disks
->minor
);
3935 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
3936 is_configured(d
) == is_configured(tbl_d
)) &&
3937 tbl_mpb
->generation_num
< mpb
->generation_num
) {
3938 /* current version of the mpb is a
3939 * better candidate than the one in
3940 * super_table, but copy over "cross
3941 * generational" status
3943 struct intel_disk
*idisk
;
3945 dprintf("%s: mpb from %d:%d replaces %d:%d\n",
3946 __func__
, super
->disks
->major
,
3947 super
->disks
->minor
,
3948 table
[i
]->disks
->major
,
3949 table
[i
]->disks
->minor
);
3951 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
3952 if (idisk
&& is_failed(&idisk
->disk
))
3953 tbl_d
->status
|= FAILED_DISK
;
3956 struct intel_disk
*idisk
;
3957 struct imsm_disk
*disk
;
3959 /* tbl_mpb is more up to date, but copy
3960 * over cross generational status before
3963 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
3964 if (disk
&& is_failed(disk
))
3965 d
->status
|= FAILED_DISK
;
3967 idisk
= disk_list_get(d
->serial
, *disk_list
);
3970 if (disk
&& is_configured(disk
))
3971 idisk
->disk
.status
|= CONFIGURED_DISK
;
3974 dprintf("%s: mpb from %d:%d prefer %d:%d\n",
3975 __func__
, super
->disks
->major
,
3976 super
->disks
->minor
,
3977 table
[i
]->disks
->major
,
3978 table
[i
]->disks
->minor
);
3986 table
[tbl_size
++] = super
;
3990 /* update/extend the merged list of imsm_disk records */
3991 for (j
= 0; j
< mpb
->num_disks
; j
++) {
3992 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
3993 struct intel_disk
*idisk
;
3995 idisk
= disk_list_get(disk
->serial
, *disk_list
);
3997 idisk
->disk
.status
|= disk
->status
;
3998 if (is_configured(&idisk
->disk
) ||
3999 is_failed(&idisk
->disk
))
4000 idisk
->disk
.status
&= ~(SPARE_DISK
);
4002 idisk
= xcalloc(1, sizeof(*idisk
));
4003 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
4004 idisk
->disk
= *disk
;
4005 idisk
->next
= *disk_list
;
4009 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
4016 static struct intel_super
*
4017 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
4020 struct imsm_super
*mpb
= super
->anchor
;
4024 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4025 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
4026 struct intel_disk
*idisk
;
4028 idisk
= disk_list_get(disk
->serial
, disk_list
);
4030 if (idisk
->owner
== owner
||
4031 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
4034 dprintf("%s: '%.16s' owner %d != %d\n",
4035 __func__
, disk
->serial
, idisk
->owner
,
4038 dprintf("%s: unknown disk %x [%d]: %.16s\n",
4039 __func__
, __le32_to_cpu(mpb
->family_num
), i
,
4045 if (ok_count
== mpb
->num_disks
)
4050 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
4052 struct intel_super
*s
;
4054 for (s
= super_list
; s
; s
= s
->next
) {
4055 if (family_num
!= s
->anchor
->family_num
)
4057 pr_err("Conflict, offlining family %#x on '%s'\n",
4058 __le32_to_cpu(family_num
), s
->disks
->devname
);
4062 static struct intel_super
*
4063 imsm_thunderdome(struct intel_super
**super_list
, int len
)
4065 struct intel_super
*super_table
[len
];
4066 struct intel_disk
*disk_list
= NULL
;
4067 struct intel_super
*champion
, *spare
;
4068 struct intel_super
*s
, **del
;
4073 memset(super_table
, 0, sizeof(super_table
));
4074 for (s
= *super_list
; s
; s
= s
->next
)
4075 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
4077 for (i
= 0; i
< tbl_size
; i
++) {
4078 struct imsm_disk
*d
;
4079 struct intel_disk
*idisk
;
4080 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
4083 d
= &s
->disks
->disk
;
4085 /* 'd' must appear in merged disk list for its
4086 * configuration to be valid
4088 idisk
= disk_list_get(d
->serial
, disk_list
);
4089 if (idisk
&& idisk
->owner
== i
)
4090 s
= validate_members(s
, disk_list
, i
);
4095 dprintf("%s: marking family: %#x from %d:%d offline\n",
4096 __func__
, mpb
->family_num
,
4097 super_table
[i
]->disks
->major
,
4098 super_table
[i
]->disks
->minor
);
4102 /* This is where the mdadm implementation differs from the Windows
4103 * driver which has no strict concept of a container. We can only
4104 * assemble one family from a container, so when returning a prodigal
4105 * array member to this system the code will not be able to disambiguate
4106 * the container contents that should be assembled ("foreign" versus
4107 * "local"). It requires user intervention to set the orig_family_num
4108 * to a new value to establish a new container. The Windows driver in
4109 * this situation fixes up the volume name in place and manages the
4110 * foreign array as an independent entity.
4115 for (i
= 0; i
< tbl_size
; i
++) {
4116 struct intel_super
*tbl_ent
= super_table
[i
];
4122 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
4127 if (s
&& !is_spare
) {
4128 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
4130 } else if (!s
&& !is_spare
)
4143 pr_err("Chose family %#x on '%s', "
4144 "assemble conflicts to new container with '--update=uuid'\n",
4145 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
4147 /* collect all dl's onto 'champion', and update them to
4148 * champion's version of the status
4150 for (s
= *super_list
; s
; s
= s
->next
) {
4151 struct imsm_super
*mpb
= champion
->anchor
;
4152 struct dl
*dl
= s
->disks
;
4157 mpb
->attributes
|= s
->anchor
->attributes
& MPB_ATTRIB_2TB_DISK
;
4159 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4160 struct imsm_disk
*disk
;
4162 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
4165 /* only set index on disks that are a member of
4166 * a populated contianer, i.e. one with
4169 if (is_failed(&dl
->disk
))
4171 else if (is_spare(&dl
->disk
))
4177 if (i
>= mpb
->num_disks
) {
4178 struct intel_disk
*idisk
;
4180 idisk
= disk_list_get(dl
->serial
, disk_list
);
4181 if (idisk
&& is_spare(&idisk
->disk
) &&
4182 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
4190 dl
->next
= champion
->disks
;
4191 champion
->disks
= dl
;
4195 /* delete 'champion' from super_list */
4196 for (del
= super_list
; *del
; ) {
4197 if (*del
== champion
) {
4198 *del
= (*del
)->next
;
4201 del
= &(*del
)->next
;
4203 champion
->next
= NULL
;
4207 struct intel_disk
*idisk
= disk_list
;
4209 disk_list
= disk_list
->next
;
4217 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
);
4218 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4219 int major
, int minor
, int keep_fd
);
4221 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4222 int *max
, int keep_fd
);
4224 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
4225 char *devname
, struct md_list
*devlist
,
4228 struct intel_super
*super_list
= NULL
;
4229 struct intel_super
*super
= NULL
;
4234 /* 'fd' is an opened container */
4235 err
= get_sra_super_block(fd
, &super_list
, devname
, &i
, keep_fd
);
4237 /* get super block from devlist devices */
4238 err
= get_devlist_super_block(devlist
, &super_list
, &i
, keep_fd
);
4241 /* all mpbs enter, maybe one leaves */
4242 super
= imsm_thunderdome(&super_list
, i
);
4248 if (find_missing(super
) != 0) {
4254 /* load migration record */
4255 err
= load_imsm_migr_rec(super
, NULL
);
4257 /* migration is in progress,
4258 * but migr_rec cannot be loaded,
4264 /* Check migration compatibility */
4265 if ((err
== 0) && (check_mpb_migr_compatibility(super
) != 0)) {
4266 pr_err("Unsupported migration detected");
4268 fprintf(stderr
, " on %s\n", devname
);
4270 fprintf(stderr
, " (IMSM).\n");
4279 while (super_list
) {
4280 struct intel_super
*s
= super_list
;
4282 super_list
= super_list
->next
;
4291 strcpy(st
->container_devnm
, fd2devnm(fd
));
4293 st
->container_devnm
[0] = 0;
4294 if (err
== 0 && st
->ss
== NULL
) {
4295 st
->ss
= &super_imsm
;
4296 st
->minor_version
= 0;
4297 st
->max_devs
= IMSM_MAX_DEVICES
;
4303 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4304 int *max
, int keep_fd
)
4306 struct md_list
*tmpdev
;
4310 for (i
= 0, tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
4311 if (tmpdev
->used
!= 1)
4313 if (tmpdev
->container
== 1) {
4315 int fd
= dev_open(tmpdev
->devname
, O_RDONLY
|O_EXCL
);
4317 pr_err("cannot open device %s: %s\n",
4318 tmpdev
->devname
, strerror(errno
));
4322 err
= get_sra_super_block(fd
, super_list
,
4323 tmpdev
->devname
, &lmax
,
4332 int major
= major(tmpdev
->st_rdev
);
4333 int minor
= minor(tmpdev
->st_rdev
);
4334 err
= get_super_block(super_list
,
4351 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4352 int major
, int minor
, int keep_fd
)
4354 struct intel_super
*s
= NULL
;
4366 sprintf(nm
, "%d:%d", major
, minor
);
4367 dfd
= dev_open(nm
, O_RDWR
);
4373 find_intel_hba_capability(dfd
, s
, devname
);
4374 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
4376 /* retry the load if we might have raced against mdmon */
4377 if (err
== 3 && devnm
&& mdmon_running(devnm
))
4378 for (retry
= 0; retry
< 3; retry
++) {
4380 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
4386 s
->next
= *super_list
;
4394 if ((dfd
>= 0) && (!keep_fd
))
4401 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
)
4408 sra
= sysfs_read(fd
, NULL
, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
4412 if (sra
->array
.major_version
!= -1 ||
4413 sra
->array
.minor_version
!= -2 ||
4414 strcmp(sra
->text_version
, "imsm") != 0) {
4419 devnm
= fd2devnm(fd
);
4420 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
4421 if (get_super_block(super_list
, devnm
, devname
,
4422 sd
->disk
.major
, sd
->disk
.minor
, keep_fd
) != 0) {
4433 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
4435 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
, NULL
, 1);
4439 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
4441 struct intel_super
*super
;
4445 if (test_partition(fd
))
4446 /* IMSM not allowed on partitions */
4449 free_super_imsm(st
);
4451 super
= alloc_super();
4452 /* Load hba and capabilities if they exist.
4453 * But do not preclude loading metadata in case capabilities or hba are
4454 * non-compliant and ignore_hw_compat is set.
4456 rv
= find_intel_hba_capability(fd
, super
, devname
);
4457 /* no orom/efi or non-intel hba of the disk */
4458 if ((rv
!= 0) && (st
->ignore_hw_compat
== 0)) {
4460 pr_err("No OROM/EFI properties for %s\n", devname
);
4464 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
4466 /* retry the load if we might have raced against mdmon */
4468 struct mdstat_ent
*mdstat
= mdstat_by_component(fd2devnm(fd
));
4470 if (mdstat
&& mdmon_running(mdstat
->devnm
) && getpid() != mdmon_pid(mdstat
->devnm
)) {
4471 for (retry
= 0; retry
< 3; retry
++) {
4473 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
4479 free_mdstat(mdstat
);
4484 pr_err("Failed to load all information "
4485 "sections on %s\n", devname
);
4491 if (st
->ss
== NULL
) {
4492 st
->ss
= &super_imsm
;
4493 st
->minor_version
= 0;
4494 st
->max_devs
= IMSM_MAX_DEVICES
;
4497 /* load migration record */
4498 if (load_imsm_migr_rec(super
, NULL
) == 0) {
4499 /* Check for unsupported migration features */
4500 if (check_mpb_migr_compatibility(super
) != 0) {
4501 pr_err("Unsupported migration detected");
4503 fprintf(stderr
, " on %s\n", devname
);
4505 fprintf(stderr
, " (IMSM).\n");
4513 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
4515 if (info
->level
== 1)
4517 return info
->chunk_size
>> 9;
4520 static unsigned long long info_to_blocks_per_member(mdu_array_info_t
*info
,
4521 unsigned long long size
)
4523 if (info
->level
== 1)
4526 return (size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
4529 static void imsm_update_version_info(struct intel_super
*super
)
4531 /* update the version and attributes */
4532 struct imsm_super
*mpb
= super
->anchor
;
4534 struct imsm_dev
*dev
;
4535 struct imsm_map
*map
;
4538 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4539 dev
= get_imsm_dev(super
, i
);
4540 map
= get_imsm_map(dev
, MAP_0
);
4541 if (__le32_to_cpu(dev
->size_high
) > 0)
4542 mpb
->attributes
|= MPB_ATTRIB_2TB
;
4544 /* FIXME detect when an array spans a port multiplier */
4546 mpb
->attributes
|= MPB_ATTRIB_PM
;
4549 if (mpb
->num_raid_devs
> 1 ||
4550 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
4551 version
= MPB_VERSION_ATTRIBS
;
4552 switch (get_imsm_raid_level(map
)) {
4553 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
4554 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
4555 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
4556 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
4559 if (map
->num_members
>= 5)
4560 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
4561 else if (dev
->status
== DEV_CLONE_N_GO
)
4562 version
= MPB_VERSION_CNG
;
4563 else if (get_imsm_raid_level(map
) == 5)
4564 version
= MPB_VERSION_RAID5
;
4565 else if (map
->num_members
>= 3)
4566 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
4567 else if (get_imsm_raid_level(map
) == 1)
4568 version
= MPB_VERSION_RAID1
;
4570 version
= MPB_VERSION_RAID0
;
4572 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
4576 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
4578 struct imsm_super
*mpb
= super
->anchor
;
4579 char *reason
= NULL
;
4582 if (strlen(name
) > MAX_RAID_SERIAL_LEN
)
4583 reason
= "must be 16 characters or less";
4585 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4586 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
4588 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
4589 reason
= "already exists";
4594 if (reason
&& !quiet
)
4595 pr_err("imsm volume name %s\n", reason
);
4600 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
4601 unsigned long long size
, char *name
,
4602 char *homehost
, int *uuid
,
4603 long long data_offset
)
4605 /* We are creating a volume inside a pre-existing container.
4606 * so st->sb is already set.
4608 struct intel_super
*super
= st
->sb
;
4609 struct imsm_super
*mpb
= super
->anchor
;
4610 struct intel_dev
*dv
;
4611 struct imsm_dev
*dev
;
4612 struct imsm_vol
*vol
;
4613 struct imsm_map
*map
;
4614 int idx
= mpb
->num_raid_devs
;
4616 unsigned long long array_blocks
;
4617 size_t size_old
, size_new
;
4618 unsigned long long num_data_stripes
;
4620 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
4621 pr_err("This imsm-container already has the "
4622 "maximum of %d volumes\n", super
->orom
->vpa
);
4626 /* ensure the mpb is large enough for the new data */
4627 size_old
= __le32_to_cpu(mpb
->mpb_size
);
4628 size_new
= disks_to_mpb_size(info
->nr_disks
);
4629 if (size_new
> size_old
) {
4631 size_t size_round
= ROUND_UP(size_new
, 512);
4633 if (posix_memalign(&mpb_new
, 512, size_round
) != 0) {
4634 pr_err("could not allocate new mpb\n");
4637 if (posix_memalign(&super
->migr_rec_buf
, 512,
4638 MIGR_REC_BUF_SIZE
) != 0) {
4639 pr_err("%s could not allocate migr_rec buffer\n",
4646 memcpy(mpb_new
, mpb
, size_old
);
4649 super
->anchor
= mpb_new
;
4650 mpb
->mpb_size
= __cpu_to_le32(size_new
);
4651 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
4653 super
->current_vol
= idx
;
4655 /* handle 'failed_disks' by either:
4656 * a) create dummy disk entries in the table if this the first
4657 * volume in the array. We add them here as this is the only
4658 * opportunity to add them. add_to_super_imsm_volume()
4659 * handles the non-failed disks and continues incrementing
4661 * b) validate that 'failed_disks' matches the current number
4662 * of missing disks if the container is populated
4664 if (super
->current_vol
== 0) {
4666 for (i
= 0; i
< info
->failed_disks
; i
++) {
4667 struct imsm_disk
*disk
;
4670 disk
= __get_imsm_disk(mpb
, i
);
4671 disk
->status
= CONFIGURED_DISK
| FAILED_DISK
;
4672 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
4673 snprintf((char *) disk
->serial
, MAX_RAID_SERIAL_LEN
,
4676 find_missing(super
);
4681 for (d
= super
->missing
; d
; d
= d
->next
)
4683 if (info
->failed_disks
> missing
) {
4684 pr_err("unable to add 'missing' disk to container\n");
4689 if (!check_name(super
, name
, 0))
4691 dv
= xmalloc(sizeof(*dv
));
4692 dev
= xcalloc(1, sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
4693 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
4694 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
4695 info
->layout
, info
->chunk_size
,
4697 /* round array size down to closest MB */
4698 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
4700 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
4701 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
4702 dev
->status
= (DEV_READ_COALESCING
| DEV_WRITE_COALESCING
);
4704 vol
->migr_state
= 0;
4705 set_migr_type(dev
, MIGR_INIT
);
4706 vol
->dirty
= !info
->state
;
4707 vol
->curr_migr_unit
= 0;
4708 map
= get_imsm_map(dev
, MAP_0
);
4709 set_pba_of_lba0(map
, super
->create_offset
);
4710 set_blocks_per_member(map
, info_to_blocks_per_member(info
, size
));
4711 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
4712 map
->failed_disk_num
= ~0;
4713 if (info
->level
> 0)
4714 map
->map_state
= (info
->state
? IMSM_T_STATE_NORMAL
4715 : IMSM_T_STATE_UNINITIALIZED
);
4717 map
->map_state
= info
->failed_disks
? IMSM_T_STATE_FAILED
:
4718 IMSM_T_STATE_NORMAL
;
4721 if (info
->level
== 1 && info
->raid_disks
> 2) {
4724 pr_err("imsm does not support more than 2 disks"
4725 "in a raid1 volume\n");
4729 map
->raid_level
= info
->level
;
4730 if (info
->level
== 10) {
4731 map
->raid_level
= 1;
4732 map
->num_domains
= info
->raid_disks
/ 2;
4733 } else if (info
->level
== 1)
4734 map
->num_domains
= info
->raid_disks
;
4736 map
->num_domains
= 1;
4738 /* info->size is only int so use the 'size' parameter instead */
4739 num_data_stripes
= (size
* 2) / info_to_blocks_per_strip(info
);
4740 num_data_stripes
/= map
->num_domains
;
4741 set_num_data_stripes(map
, num_data_stripes
);
4743 map
->num_members
= info
->raid_disks
;
4744 for (i
= 0; i
< map
->num_members
; i
++) {
4745 /* initialized in add_to_super */
4746 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
4748 mpb
->num_raid_devs
++;
4751 dv
->index
= super
->current_vol
;
4752 dv
->next
= super
->devlist
;
4753 super
->devlist
= dv
;
4755 imsm_update_version_info(super
);
4760 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
4761 unsigned long long size
, char *name
,
4762 char *homehost
, int *uuid
,
4763 unsigned long long data_offset
)
4765 /* This is primarily called by Create when creating a new array.
4766 * We will then get add_to_super called for each component, and then
4767 * write_init_super called to write it out to each device.
4768 * For IMSM, Create can create on fresh devices or on a pre-existing
4770 * To create on a pre-existing array a different method will be called.
4771 * This one is just for fresh drives.
4773 struct intel_super
*super
;
4774 struct imsm_super
*mpb
;
4778 if (data_offset
!= INVALID_SECTORS
) {
4779 pr_err("data-offset not supported by imsm\n");
4784 return init_super_imsm_volume(st
, info
, size
, name
, homehost
, uuid
,
4788 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
4792 super
= alloc_super();
4793 if (super
&& posix_memalign(&super
->buf
, 512, mpb_size
) != 0) {
4798 pr_err("%s could not allocate superblock\n", __func__
);
4801 if (posix_memalign(&super
->migr_rec_buf
, 512, MIGR_REC_BUF_SIZE
) != 0) {
4802 pr_err("%s could not allocate migr_rec buffer\n", __func__
);
4807 memset(super
->buf
, 0, mpb_size
);
4809 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
4813 /* zeroing superblock */
4817 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
4819 version
= (char *) mpb
->sig
;
4820 strcpy(version
, MPB_SIGNATURE
);
4821 version
+= strlen(MPB_SIGNATURE
);
4822 strcpy(version
, MPB_VERSION_RAID0
);
4828 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
4829 int fd
, char *devname
)
4831 struct intel_super
*super
= st
->sb
;
4832 struct imsm_super
*mpb
= super
->anchor
;
4833 struct imsm_disk
*_disk
;
4834 struct imsm_dev
*dev
;
4835 struct imsm_map
*map
;
4839 dev
= get_imsm_dev(super
, super
->current_vol
);
4840 map
= get_imsm_map(dev
, MAP_0
);
4842 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
4843 pr_err("%s: Cannot add spare devices to IMSM volume\n",
4849 /* we're doing autolayout so grab the pre-marked (in
4850 * validate_geometry) raid_disk
4852 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4853 if (dl
->raiddisk
== dk
->raid_disk
)
4856 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4857 if (dl
->major
== dk
->major
&&
4858 dl
->minor
== dk
->minor
)
4863 pr_err("%s is not a member of the same container\n", devname
);
4867 /* add a pristine spare to the metadata */
4868 if (dl
->index
< 0) {
4869 dl
->index
= super
->anchor
->num_disks
;
4870 super
->anchor
->num_disks
++;
4872 /* Check the device has not already been added */
4873 slot
= get_imsm_disk_slot(map
, dl
->index
);
4875 (get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
) & IMSM_ORD_REBUILD
) == 0) {
4876 pr_err("%s has been included in this array twice\n",
4880 set_imsm_ord_tbl_ent(map
, dk
->raid_disk
, dl
->index
);
4881 dl
->disk
.status
= CONFIGURED_DISK
;
4883 /* update size of 'missing' disks to be at least as large as the
4884 * largest acitve member (we only have dummy missing disks when
4885 * creating the first volume)
4887 if (super
->current_vol
== 0) {
4888 for (df
= super
->missing
; df
; df
= df
->next
) {
4889 if (total_blocks(&dl
->disk
) > total_blocks(&df
->disk
))
4890 set_total_blocks(&df
->disk
, total_blocks(&dl
->disk
));
4891 _disk
= __get_imsm_disk(mpb
, df
->index
);
4896 /* refresh unset/failed slots to point to valid 'missing' entries */
4897 for (df
= super
->missing
; df
; df
= df
->next
)
4898 for (slot
= 0; slot
< mpb
->num_disks
; slot
++) {
4899 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
4901 if ((ord
& IMSM_ORD_REBUILD
) == 0)
4903 set_imsm_ord_tbl_ent(map
, slot
, df
->index
| IMSM_ORD_REBUILD
);
4904 if (is_gen_migration(dev
)) {
4905 struct imsm_map
*map2
= get_imsm_map(dev
,
4907 int slot2
= get_imsm_disk_slot(map2
, df
->index
);
4908 if ((slot2
< map2
->num_members
) &&
4910 __u32 ord2
= get_imsm_ord_tbl_ent(dev
,
4913 if ((unsigned)df
->index
==
4915 set_imsm_ord_tbl_ent(map2
,
4921 dprintf("set slot:%d to missing disk:%d\n", slot
, df
->index
);
4925 /* if we are creating the first raid device update the family number */
4926 if (super
->current_vol
== 0) {
4928 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
4930 _disk
= __get_imsm_disk(mpb
, dl
->index
);
4931 if (!_dev
|| !_disk
) {
4932 pr_err("BUG mpb setup error\n");
4938 sum
+= __gen_imsm_checksum(mpb
);
4939 mpb
->family_num
= __cpu_to_le32(sum
);
4940 mpb
->orig_family_num
= mpb
->family_num
;
4942 super
->current_disk
= dl
;
4947 * Function marks disk as spare and restores disk serial
4948 * in case it was previously marked as failed by takeover operation
4950 * -1 : critical error
4951 * 0 : disk is marked as spare but serial is not set
4954 int mark_spare(struct dl
*disk
)
4956 __u8 serial
[MAX_RAID_SERIAL_LEN
];
4963 if (!imsm_read_serial(disk
->fd
, NULL
, serial
)) {
4964 /* Restore disk serial number, because takeover marks disk
4965 * as failed and adds to serial ':0' before it becomes
4968 serialcpy(disk
->serial
, serial
);
4969 serialcpy(disk
->disk
.serial
, serial
);
4972 disk
->disk
.status
= SPARE_DISK
;
4978 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
4979 int fd
, char *devname
,
4980 unsigned long long data_offset
)
4982 struct intel_super
*super
= st
->sb
;
4984 unsigned long long size
;
4989 /* If we are on an RAID enabled platform check that the disk is
4990 * attached to the raid controller.
4991 * We do not need to test disks attachment for container based additions,
4992 * they shall be already tested when container was created/assembled.
4994 rv
= find_intel_hba_capability(fd
, super
, devname
);
4995 /* no orom/efi or non-intel hba of the disk */
4997 dprintf("capability: %p fd: %d ret: %d\n",
4998 super
->orom
, fd
, rv
);
5002 if (super
->current_vol
>= 0)
5003 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
5006 dd
= xcalloc(sizeof(*dd
), 1);
5007 dd
->major
= major(stb
.st_rdev
);
5008 dd
->minor
= minor(stb
.st_rdev
);
5009 dd
->devname
= devname
? xstrdup(devname
) : NULL
;
5012 dd
->action
= DISK_ADD
;
5013 rv
= imsm_read_serial(fd
, devname
, dd
->serial
);
5015 pr_err("failed to retrieve scsi serial, aborting\n");
5020 get_dev_size(fd
, NULL
, &size
);
5022 serialcpy(dd
->disk
.serial
, dd
->serial
);
5023 set_total_blocks(&dd
->disk
, size
);
5024 if (__le32_to_cpu(dd
->disk
.total_blocks_hi
) > 0) {
5025 struct imsm_super
*mpb
= super
->anchor
;
5026 mpb
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5029 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
5030 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
5032 dd
->disk
.scsi_id
= __cpu_to_le32(0);
5034 if (st
->update_tail
) {
5035 dd
->next
= super
->disk_mgmt_list
;
5036 super
->disk_mgmt_list
= dd
;
5038 dd
->next
= super
->disks
;
5040 super
->updates_pending
++;
5046 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
5048 struct intel_super
*super
= st
->sb
;
5051 /* remove from super works only in mdmon - for communication
5052 * manager - monitor. Check if communication memory buffer
5055 if (!st
->update_tail
) {
5056 pr_err("%s shall be used in mdmon context only"
5057 "(line %d).\n", __func__
, __LINE__
);
5060 dd
= xcalloc(1, sizeof(*dd
));
5061 dd
->major
= dk
->major
;
5062 dd
->minor
= dk
->minor
;
5065 dd
->action
= DISK_REMOVE
;
5067 dd
->next
= super
->disk_mgmt_list
;
5068 super
->disk_mgmt_list
= dd
;
5073 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
5077 struct imsm_super anchor
;
5078 } spare_record
__attribute__ ((aligned(512)));
5080 /* spare records have their own family number and do not have any defined raid
5083 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
5085 struct imsm_super
*mpb
= super
->anchor
;
5086 struct imsm_super
*spare
= &spare_record
.anchor
;
5090 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
)),
5091 spare
->generation_num
= __cpu_to_le32(1UL),
5092 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5093 spare
->num_disks
= 1,
5094 spare
->num_raid_devs
= 0,
5095 spare
->cache_size
= mpb
->cache_size
,
5096 spare
->pwr_cycle_count
= __cpu_to_le32(1),
5098 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
5099 MPB_SIGNATURE MPB_VERSION_RAID0
);
5101 for (d
= super
->disks
; d
; d
= d
->next
) {
5105 spare
->disk
[0] = d
->disk
;
5106 if (__le32_to_cpu(d
->disk
.total_blocks_hi
) > 0)
5107 spare
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5109 sum
= __gen_imsm_checksum(spare
);
5110 spare
->family_num
= __cpu_to_le32(sum
);
5111 spare
->orig_family_num
= 0;
5112 sum
= __gen_imsm_checksum(spare
);
5113 spare
->check_sum
= __cpu_to_le32(sum
);
5115 if (store_imsm_mpb(d
->fd
, spare
)) {
5116 pr_err("%s: failed for device %d:%d %s\n",
5117 __func__
, d
->major
, d
->minor
, strerror(errno
));
5129 static int write_super_imsm(struct supertype
*st
, int doclose
)
5131 struct intel_super
*super
= st
->sb
;
5132 struct imsm_super
*mpb
= super
->anchor
;
5138 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
5140 int clear_migration_record
= 1;
5142 /* 'generation' is incremented everytime the metadata is written */
5143 generation
= __le32_to_cpu(mpb
->generation_num
);
5145 mpb
->generation_num
= __cpu_to_le32(generation
);
5147 /* fix up cases where previous mdadm releases failed to set
5150 if (mpb
->orig_family_num
== 0)
5151 mpb
->orig_family_num
= mpb
->family_num
;
5153 for (d
= super
->disks
; d
; d
= d
->next
) {
5157 mpb
->disk
[d
->index
] = d
->disk
;
5161 for (d
= super
->missing
; d
; d
= d
->next
) {
5162 mpb
->disk
[d
->index
] = d
->disk
;
5165 mpb
->num_disks
= num_disks
;
5166 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
5168 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5169 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
5170 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
5172 imsm_copy_dev(dev
, dev2
);
5173 mpb_size
+= sizeof_imsm_dev(dev
, 0);
5175 if (is_gen_migration(dev2
))
5176 clear_migration_record
= 0;
5178 mpb_size
+= __le32_to_cpu(mpb
->bbm_log_size
);
5179 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5181 /* recalculate checksum */
5182 sum
= __gen_imsm_checksum(mpb
);
5183 mpb
->check_sum
= __cpu_to_le32(sum
);
5185 if (super
->clean_migration_record_by_mdmon
) {
5186 clear_migration_record
= 1;
5187 super
->clean_migration_record_by_mdmon
= 0;
5189 if (clear_migration_record
)
5190 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SIZE
);
5192 /* write the mpb for disks that compose raid devices */
5193 for (d
= super
->disks
; d
; d
= d
->next
) {
5194 if (d
->index
< 0 || is_failed(&d
->disk
))
5197 if (clear_migration_record
) {
5198 unsigned long long dsize
;
5200 get_dev_size(d
->fd
, NULL
, &dsize
);
5201 if (lseek64(d
->fd
, dsize
- 512, SEEK_SET
) >= 0) {
5202 if (write(d
->fd
, super
->migr_rec_buf
,
5203 MIGR_REC_BUF_SIZE
) != MIGR_REC_BUF_SIZE
)
5204 perror("Write migr_rec failed");
5208 if (store_imsm_mpb(d
->fd
, mpb
))
5210 "%s: failed for device %d:%d (fd: %d)%s\n",
5211 __func__
, d
->major
, d
->minor
,
5212 d
->fd
, strerror(errno
));
5221 return write_super_imsm_spares(super
, doclose
);
5226 static int create_array(struct supertype
*st
, int dev_idx
)
5229 struct imsm_update_create_array
*u
;
5230 struct intel_super
*super
= st
->sb
;
5231 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
5232 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
5233 struct disk_info
*inf
;
5234 struct imsm_disk
*disk
;
5237 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
5238 sizeof(*inf
) * map
->num_members
;
5240 u
->type
= update_create_array
;
5241 u
->dev_idx
= dev_idx
;
5242 imsm_copy_dev(&u
->dev
, dev
);
5243 inf
= get_disk_info(u
);
5244 for (i
= 0; i
< map
->num_members
; i
++) {
5245 int idx
= get_imsm_disk_idx(dev
, i
, MAP_X
);
5247 disk
= get_imsm_disk(super
, idx
);
5249 disk
= get_imsm_missing(super
, idx
);
5250 serialcpy(inf
[i
].serial
, disk
->serial
);
5252 append_metadata_update(st
, u
, len
);
5257 static int mgmt_disk(struct supertype
*st
)
5259 struct intel_super
*super
= st
->sb
;
5261 struct imsm_update_add_remove_disk
*u
;
5263 if (!super
->disk_mgmt_list
)
5268 u
->type
= update_add_remove_disk
;
5269 append_metadata_update(st
, u
, len
);
5274 static int write_init_super_imsm(struct supertype
*st
)
5276 struct intel_super
*super
= st
->sb
;
5277 int current_vol
= super
->current_vol
;
5279 /* we are done with current_vol reset it to point st at the container */
5280 super
->current_vol
= -1;
5282 if (st
->update_tail
) {
5283 /* queue the recently created array / added disk
5284 * as a metadata update */
5287 /* determine if we are creating a volume or adding a disk */
5288 if (current_vol
< 0) {
5289 /* in the mgmt (add/remove) disk case we are running
5290 * in mdmon context, so don't close fd's
5292 return mgmt_disk(st
);
5294 rv
= create_array(st
, current_vol
);
5299 for (d
= super
->disks
; d
; d
= d
->next
)
5300 Kill(d
->devname
, NULL
, 0, -1, 1);
5301 return write_super_imsm(st
, 1);
5306 static int store_super_imsm(struct supertype
*st
, int fd
)
5308 struct intel_super
*super
= st
->sb
;
5309 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
5315 return store_imsm_mpb(fd
, mpb
);
5321 static int imsm_bbm_log_size(struct imsm_super
*mpb
)
5323 return __le32_to_cpu(mpb
->bbm_log_size
);
5327 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
5328 int layout
, int raiddisks
, int chunk
,
5329 unsigned long long size
,
5330 unsigned long long data_offset
,
5332 unsigned long long *freesize
,
5336 unsigned long long ldsize
;
5337 struct intel_super
*super
=NULL
;
5340 if (level
!= LEVEL_CONTAINER
)
5345 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
5348 pr_err("imsm: Cannot open %s: %s\n",
5349 dev
, strerror(errno
));
5352 if (!get_dev_size(fd
, dev
, &ldsize
)) {
5357 /* capabilities retrieve could be possible
5358 * note that there is no fd for the disks in array.
5360 super
= alloc_super();
5361 rv
= find_intel_hba_capability(fd
, super
, verbose
> 0 ? dev
: NULL
);
5365 fd2devname(fd
, str
);
5366 dprintf("validate_geometry_imsm_container: fd: %d %s orom: %p rv: %d raiddisk: %d\n",
5367 fd
, str
, super
->orom
, rv
, raiddisks
);
5369 /* no orom/efi or non-intel hba of the disk */
5376 if (raiddisks
> super
->orom
->tds
) {
5378 pr_err("%d exceeds maximum number of"
5379 " platform supported disks: %d\n",
5380 raiddisks
, super
->orom
->tds
);
5384 if ((super
->orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) == 0 &&
5385 (ldsize
>> 9) >> 32 > 0) {
5387 pr_err("%s exceeds maximum platform supported size\n", dev
);
5393 *freesize
= avail_size_imsm(st
, ldsize
>> 9, data_offset
);
5399 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
5401 const unsigned long long base_start
= e
[*idx
].start
;
5402 unsigned long long end
= base_start
+ e
[*idx
].size
;
5405 if (base_start
== end
)
5409 for (i
= *idx
; i
< num_extents
; i
++) {
5410 /* extend overlapping extents */
5411 if (e
[i
].start
>= base_start
&&
5412 e
[i
].start
<= end
) {
5415 if (e
[i
].start
+ e
[i
].size
> end
)
5416 end
= e
[i
].start
+ e
[i
].size
;
5417 } else if (e
[i
].start
> end
) {
5423 return end
- base_start
;
5426 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
5428 /* build a composite disk with all known extents and generate a new
5429 * 'maxsize' given the "all disks in an array must share a common start
5430 * offset" constraint
5432 struct extent
*e
= xcalloc(sum_extents
, sizeof(*e
));
5436 unsigned long long pos
;
5437 unsigned long long start
= 0;
5438 unsigned long long maxsize
;
5439 unsigned long reserve
;
5441 /* coalesce and sort all extents. also, check to see if we need to
5442 * reserve space between member arrays
5445 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5448 for (i
= 0; i
< dl
->extent_cnt
; i
++)
5451 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
5456 while (i
< sum_extents
) {
5457 e
[j
].start
= e
[i
].start
;
5458 e
[j
].size
= find_size(e
, &i
, sum_extents
);
5460 if (e
[j
-1].size
== 0)
5469 unsigned long long esize
;
5471 esize
= e
[i
].start
- pos
;
5472 if (esize
>= maxsize
) {
5477 pos
= e
[i
].start
+ e
[i
].size
;
5479 } while (e
[i
-1].size
);
5485 /* FIXME assumes volume at offset 0 is the first volume in a
5488 if (start_extent
> 0)
5489 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
5493 if (maxsize
< reserve
)
5496 super
->create_offset
= ~((unsigned long long) 0);
5497 if (start
+ reserve
> super
->create_offset
)
5498 return 0; /* start overflows create_offset */
5499 super
->create_offset
= start
+ reserve
;
5501 return maxsize
- reserve
;
5504 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
5506 if (level
< 0 || level
== 6 || level
== 4)
5509 /* if we have an orom prevent invalid raid levels */
5512 case 0: return imsm_orom_has_raid0(orom
);
5515 return imsm_orom_has_raid1e(orom
);
5516 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
5517 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
5518 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
5521 return 1; /* not on an Intel RAID platform so anything goes */
5527 active_arrays_by_format(char *name
, char* hba
, struct md_list
**devlist
,
5528 int dpa
, int verbose
)
5530 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
5531 struct mdstat_ent
*memb
= NULL
;
5534 struct md_list
*dv
= NULL
;
5537 for (memb
= mdstat
; memb
; memb
= memb
->next
) {
5538 if (memb
->metadata_version
&&
5539 (strncmp(memb
->metadata_version
, "external:", 9) == 0) &&
5540 (strcmp(&memb
->metadata_version
[9], name
) == 0) &&
5541 !is_subarray(memb
->metadata_version
+9) &&
5543 struct dev_member
*dev
= memb
->members
;
5545 while(dev
&& (fd
< 0)) {
5546 char *path
= xmalloc(strlen(dev
->name
) + strlen("/dev/") + 1);
5547 num
= sprintf(path
, "%s%s", "/dev/", dev
->name
);
5549 fd
= open(path
, O_RDONLY
, 0);
5550 if ((num
<= 0) || (fd
< 0)) {
5551 pr_vrb(": Cannot open %s: %s\n",
5552 dev
->name
, strerror(errno
));
5558 if ((fd
>= 0) && disk_attached_to_hba(fd
, hba
)) {
5559 struct mdstat_ent
*vol
;
5560 for (vol
= mdstat
; vol
; vol
= vol
->next
) {
5561 if ((vol
->active
> 0) &&
5562 vol
->metadata_version
&&
5563 is_container_member(vol
, memb
->dev
)) {
5568 if (*devlist
&& (found
< dpa
)) {
5569 dv
= xcalloc(1, sizeof(*dv
));
5570 dv
->devname
= xmalloc(strlen(memb
->dev
) + strlen("/dev/") + 1);
5571 sprintf(dv
->devname
, "%s%s", "/dev/", memb
->dev
);
5574 dv
->next
= *devlist
;
5582 free_mdstat(mdstat
);
5587 static struct md_list
*
5588 get_loop_devices(void)
5591 struct md_list
*devlist
= NULL
;
5592 struct md_list
*dv
= NULL
;
5594 for(i
= 0; i
< 12; i
++) {
5595 dv
= xcalloc(1, sizeof(*dv
));
5596 dv
->devname
= xmalloc(40);
5597 sprintf(dv
->devname
, "/dev/loop%d", i
);
5605 static struct md_list
*
5606 get_devices(const char *hba_path
)
5608 struct md_list
*devlist
= NULL
;
5609 struct md_list
*dv
= NULL
;
5615 devlist
= get_loop_devices();
5618 /* scroll through /sys/dev/block looking for devices attached to
5621 dir
= opendir("/sys/dev/block");
5622 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
5627 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
5629 path
= devt_to_devpath(makedev(major
, minor
));
5632 if (!path_attached_to_hba(path
, hba_path
)) {
5639 fd
= dev_open(ent
->d_name
, O_RDONLY
);
5641 fd2devname(fd
, buf
);
5644 pr_err("cannot open device: %s\n",
5649 dv
= xcalloc(1, sizeof(*dv
));
5650 dv
->devname
= xstrdup(buf
);
5657 devlist
= devlist
->next
;
5667 count_volumes_list(struct md_list
*devlist
, char *homehost
,
5668 int verbose
, int *found
)
5670 struct md_list
*tmpdev
;
5672 struct supertype
*st
= NULL
;
5674 /* first walk the list of devices to find a consistent set
5675 * that match the criterea, if that is possible.
5676 * We flag the ones we like with 'used'.
5679 st
= match_metadata_desc_imsm("imsm");
5681 pr_vrb(": cannot allocate memory for imsm supertype\n");
5685 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
5686 char *devname
= tmpdev
->devname
;
5688 struct supertype
*tst
;
5690 if (tmpdev
->used
> 1)
5692 tst
= dup_super(st
);
5694 pr_vrb(": cannot allocate memory for imsm supertype\n");
5697 tmpdev
->container
= 0;
5698 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
5700 dprintf(": cannot open device %s: %s\n",
5701 devname
, strerror(errno
));
5703 } else if (fstat(dfd
, &stb
)< 0) {
5705 dprintf(": fstat failed for %s: %s\n",
5706 devname
, strerror(errno
));
5708 } else if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
5709 dprintf(": %s is not a block device.\n",
5712 } else if (must_be_container(dfd
)) {
5713 struct supertype
*cst
;
5714 cst
= super_by_fd(dfd
, NULL
);
5716 dprintf(": cannot recognize container type %s\n",
5719 } else if (tst
->ss
!= st
->ss
) {
5720 dprintf(": non-imsm container - ignore it: %s\n",
5723 } else if (!tst
->ss
->load_container
||
5724 tst
->ss
->load_container(tst
, dfd
, NULL
))
5727 tmpdev
->container
= 1;
5730 cst
->ss
->free_super(cst
);
5732 tmpdev
->st_rdev
= stb
.st_rdev
;
5733 if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
5734 dprintf(": no RAID superblock on %s\n",
5737 } else if (tst
->ss
->compare_super
== NULL
) {
5738 dprintf(": Cannot assemble %s metadata on %s\n",
5739 tst
->ss
->name
, devname
);
5745 if (tmpdev
->used
== 2 || tmpdev
->used
== 4) {
5746 /* Ignore unrecognised devices during auto-assembly */
5751 tst
->ss
->getinfo_super(tst
, &info
, NULL
);
5753 if (st
->minor_version
== -1)
5754 st
->minor_version
= tst
->minor_version
;
5756 if (memcmp(info
.uuid
, uuid_zero
,
5757 sizeof(int[4])) == 0) {
5758 /* this is a floating spare. It cannot define
5759 * an array unless there are no more arrays of
5760 * this type to be found. It can be included
5761 * in an array of this type though.
5767 if (st
->ss
!= tst
->ss
||
5768 st
->minor_version
!= tst
->minor_version
||
5769 st
->ss
->compare_super(st
, tst
) != 0) {
5770 /* Some mismatch. If exactly one array matches this host,
5771 * we can resolve on that one.
5772 * Or, if we are auto assembling, we just ignore the second
5775 dprintf(": superblock on %s doesn't match others - assembly aborted\n",
5781 dprintf("found: devname: %s\n", devname
);
5785 tst
->ss
->free_super(tst
);
5789 if ((err
= load_super_imsm_all(st
, -1, &st
->sb
, NULL
, devlist
, 0)) == 0) {
5790 struct mdinfo
*iter
, *head
= st
->ss
->container_content(st
, NULL
);
5791 for (iter
= head
; iter
; iter
= iter
->next
) {
5792 dprintf("content->text_version: %s vol\n",
5793 iter
->text_version
);
5794 if (iter
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
)) {
5795 /* do not assemble arrays with unsupported
5797 dprintf(": Cannot activate member %s.\n",
5798 iter
->text_version
);
5805 dprintf(" no valid super block on device list: err: %d %p\n",
5809 dprintf(" no more devices to examin\n");
5812 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
5813 if ((tmpdev
->used
== 1) && (tmpdev
->found
)) {
5815 if (count
< tmpdev
->found
)
5818 count
-= tmpdev
->found
;
5821 if (tmpdev
->used
== 1)
5826 st
->ss
->free_super(st
);
5831 count_volumes(char *hba
, int dpa
, int verbose
)
5833 struct md_list
*devlist
= NULL
;
5837 devlist
= get_devices(hba
);
5838 /* if no intel devices return zero volumes */
5839 if (devlist
== NULL
)
5842 count
= active_arrays_by_format("imsm", hba
, &devlist
, dpa
, verbose
);
5843 dprintf(" path: %s active arrays: %d\n", hba
, count
);
5844 if (devlist
== NULL
)
5848 count
+= count_volumes_list(devlist
,
5852 dprintf("found %d count: %d\n", found
, count
);
5855 dprintf("path: %s total number of volumes: %d\n", hba
, count
);
5858 struct md_list
*dv
= devlist
;
5859 devlist
= devlist
->next
;
5866 static int imsm_default_chunk(const struct imsm_orom
*orom
)
5868 /* up to 512 if the plaform supports it, otherwise the platform max.
5869 * 128 if no platform detected
5871 int fs
= max(7, orom
? fls(orom
->sss
) : 0);
5873 return min(512, (1 << fs
));
5877 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
5878 int raiddisks
, int *chunk
, unsigned long long size
, int verbose
)
5880 /* check/set platform and metadata limits/defaults */
5881 if (super
->orom
&& raiddisks
> super
->orom
->dpa
) {
5882 pr_vrb(": platform supports a maximum of %d disks per array\n",
5887 /* capabilities of OROM tested - copied from validate_geometry_imsm_volume */
5888 if (!is_raid_level_supported(super
->orom
, level
, raiddisks
)) {
5889 pr_vrb(": platform does not support raid%d with %d disk%s\n",
5890 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
5894 if (*chunk
== 0 || *chunk
== UnSet
)
5895 *chunk
= imsm_default_chunk(super
->orom
);
5897 if (super
->orom
&& !imsm_orom_has_chunk(super
->orom
, *chunk
)) {
5898 pr_vrb(": platform does not support a chunk size of: "
5903 if (layout
!= imsm_level_to_layout(level
)) {
5905 pr_vrb(": imsm raid 5 only supports the left-asymmetric layout\n");
5906 else if (level
== 10)
5907 pr_vrb(": imsm raid 10 only supports the n2 layout\n");
5909 pr_vrb(": imsm unknown layout %#x for this raid level %d\n",
5914 if (super
->orom
&& (super
->orom
->attr
& IMSM_OROM_ATTR_2TB
) == 0 &&
5915 (calc_array_size(level
, raiddisks
, layout
, *chunk
, size
) >> 32) > 0) {
5916 pr_vrb(": platform does not support a volume size over 2TB\n");
5922 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
5923 * FIX ME add ahci details
5925 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
5926 int layout
, int raiddisks
, int *chunk
,
5927 unsigned long long size
,
5928 unsigned long long data_offset
,
5930 unsigned long long *freesize
,
5934 struct intel_super
*super
= st
->sb
;
5935 struct imsm_super
*mpb
;
5937 unsigned long long pos
= 0;
5938 unsigned long long maxsize
;
5942 /* We must have the container info already read in. */
5946 mpb
= super
->anchor
;
5948 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, size
, verbose
)) {
5949 pr_err("RAID gemetry validation failed. "
5950 "Cannot proceed with the action(s).\n");
5954 /* General test: make sure there is space for
5955 * 'raiddisks' device extents of size 'size' at a given
5958 unsigned long long minsize
= size
;
5959 unsigned long long start_offset
= MaxSector
;
5962 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
5963 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5968 e
= get_extents(super
, dl
);
5971 unsigned long long esize
;
5972 esize
= e
[i
].start
- pos
;
5973 if (esize
>= minsize
)
5975 if (found
&& start_offset
== MaxSector
) {
5978 } else if (found
&& pos
!= start_offset
) {
5982 pos
= e
[i
].start
+ e
[i
].size
;
5984 } while (e
[i
-1].size
);
5989 if (dcnt
< raiddisks
) {
5991 pr_err("imsm: Not enough "
5992 "devices with space for this array "
6000 /* This device must be a member of the set */
6001 if (stat(dev
, &stb
) < 0)
6003 if ((S_IFMT
& stb
.st_mode
) != S_IFBLK
)
6005 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6006 if (dl
->major
== (int)major(stb
.st_rdev
) &&
6007 dl
->minor
== (int)minor(stb
.st_rdev
))
6012 pr_err("%s is not in the "
6013 "same imsm set\n", dev
);
6015 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
6016 /* If a volume is present then the current creation attempt
6017 * cannot incorporate new spares because the orom may not
6018 * understand this configuration (all member disks must be
6019 * members of each array in the container).
6021 pr_err("%s is a spare and a volume"
6022 " is already defined for this container\n", dev
);
6023 pr_err("The option-rom requires all member"
6024 " disks to be a member of all volumes\n");
6026 } else if (super
->orom
&& mpb
->num_raid_devs
> 0 &&
6027 mpb
->num_disks
!= raiddisks
) {
6028 pr_err("The option-rom requires all member"
6029 " disks to be a member of all volumes\n");
6033 /* retrieve the largest free space block */
6034 e
= get_extents(super
, dl
);
6039 unsigned long long esize
;
6041 esize
= e
[i
].start
- pos
;
6042 if (esize
>= maxsize
)
6044 pos
= e
[i
].start
+ e
[i
].size
;
6046 } while (e
[i
-1].size
);
6051 pr_err("unable to determine free space for: %s\n",
6055 if (maxsize
< size
) {
6057 pr_err("%s not enough space (%llu < %llu)\n",
6058 dev
, maxsize
, size
);
6062 /* count total number of extents for merge */
6064 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6066 i
+= dl
->extent_cnt
;
6068 maxsize
= merge_extents(super
, i
);
6070 if (!check_env("IMSM_NO_PLATFORM") &&
6071 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
6072 pr_err("attempting to create a second "
6073 "volume with size less then remaining space. "
6078 if (maxsize
< size
|| maxsize
== 0) {
6081 pr_err("no free space"
6082 " left on device. Aborting...\n");
6084 pr_err("not enough space"
6085 " to create volume of given size"
6086 " (%llu < %llu). Aborting...\n",
6092 *freesize
= maxsize
;
6095 int count
= count_volumes(super
->hba
->path
,
6096 super
->orom
->dpa
, verbose
);
6097 if (super
->orom
->vphba
<= count
) {
6098 pr_vrb(": platform does not support more than %d raid volumes.\n",
6099 super
->orom
->vphba
);
6106 static int imsm_get_free_size(struct supertype
*st
, int raiddisks
,
6107 unsigned long long size
, int chunk
,
6108 unsigned long long *freesize
)
6110 struct intel_super
*super
= st
->sb
;
6111 struct imsm_super
*mpb
= super
->anchor
;
6116 unsigned long long maxsize
;
6117 unsigned long long minsize
;
6121 /* find the largest common start free region of the possible disks */
6125 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6131 /* don't activate new spares if we are orom constrained
6132 * and there is already a volume active in the container
6134 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
6137 e
= get_extents(super
, dl
);
6140 for (i
= 1; e
[i
-1].size
; i
++)
6148 maxsize
= merge_extents(super
, extent_cnt
);
6152 minsize
= chunk
* 2;
6154 if (cnt
< raiddisks
||
6155 (super
->orom
&& used
&& used
!= raiddisks
) ||
6156 maxsize
< minsize
||
6158 pr_err("not enough devices with space to create array.\n");
6159 return 0; /* No enough free spaces large enough */
6170 if (!check_env("IMSM_NO_PLATFORM") &&
6171 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
6172 pr_err("attempting to create a second "
6173 "volume with size less then remaining space. "
6178 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6180 dl
->raiddisk
= cnt
++;
6184 dprintf("imsm: imsm_get_free_size() returns : %llu\n", size
);
6189 static int reserve_space(struct supertype
*st
, int raiddisks
,
6190 unsigned long long size
, int chunk
,
6191 unsigned long long *freesize
)
6193 struct intel_super
*super
= st
->sb
;
6198 rv
= imsm_get_free_size(st
, raiddisks
, size
, chunk
, freesize
);
6201 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6203 dl
->raiddisk
= cnt
++;
6210 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
6211 int raiddisks
, int *chunk
, unsigned long long size
,
6212 unsigned long long data_offset
,
6213 char *dev
, unsigned long long *freesize
,
6221 * if given unused devices create a container
6222 * if given given devices in a container create a member volume
6224 if (level
== LEVEL_CONTAINER
) {
6225 /* Must be a fresh device to add to a container */
6226 return validate_geometry_imsm_container(st
, level
, layout
,
6236 struct intel_super
*super
= st
->sb
;
6237 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
6238 raiddisks
, chunk
, size
,
6241 /* we are being asked to automatically layout a
6242 * new volume based on the current contents of
6243 * the container. If the the parameters can be
6244 * satisfied reserve_space will record the disks,
6245 * start offset, and size of the volume to be
6246 * created. add_to_super and getinfo_super
6247 * detect when autolayout is in progress.
6249 /* assuming that freesize is always given when array is
6251 if (super
->orom
&& freesize
) {
6253 count
= count_volumes(super
->hba
->path
,
6254 super
->orom
->dpa
, verbose
);
6255 if (super
->orom
->vphba
<= count
) {
6256 pr_vrb(": platform does not support more"
6257 " than %d raid volumes.\n",
6258 super
->orom
->vphba
);
6263 return reserve_space(st
, raiddisks
, size
,
6269 /* creating in a given container */
6270 return validate_geometry_imsm_volume(st
, level
, layout
,
6271 raiddisks
, chunk
, size
,
6273 dev
, freesize
, verbose
);
6276 /* This device needs to be a device in an 'imsm' container */
6277 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
6280 pr_err("Cannot create this array on device %s\n",
6285 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
6287 pr_err("Cannot open %s: %s\n",
6288 dev
, strerror(errno
));
6291 /* Well, it is in use by someone, maybe an 'imsm' container. */
6292 cfd
= open_container(fd
);
6296 pr_err("Cannot use %s: It is busy\n",
6300 sra
= sysfs_read(cfd
, NULL
, GET_VERSION
);
6301 if (sra
&& sra
->array
.major_version
== -1 &&
6302 strcmp(sra
->text_version
, "imsm") == 0)
6306 /* This is a member of a imsm container. Load the container
6307 * and try to create a volume
6309 struct intel_super
*super
;
6311 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
, NULL
, 1) == 0) {
6313 strcpy(st
->container_devnm
, fd2devnm(cfd
));
6315 return validate_geometry_imsm_volume(st
, level
, layout
,
6317 size
, data_offset
, dev
,
6324 pr_err("failed container membership check\n");
6330 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
6332 struct intel_super
*super
= st
->sb
;
6334 if (level
&& *level
== UnSet
)
6335 *level
= LEVEL_CONTAINER
;
6337 if (level
&& layout
&& *layout
== UnSet
)
6338 *layout
= imsm_level_to_layout(*level
);
6340 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0))
6341 *chunk
= imsm_default_chunk(super
->orom
);
6344 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
6346 static int kill_subarray_imsm(struct supertype
*st
)
6348 /* remove the subarray currently referenced by ->current_vol */
6350 struct intel_dev
**dp
;
6351 struct intel_super
*super
= st
->sb
;
6352 __u8 current_vol
= super
->current_vol
;
6353 struct imsm_super
*mpb
= super
->anchor
;
6355 if (super
->current_vol
< 0)
6357 super
->current_vol
= -1; /* invalidate subarray cursor */
6359 /* block deletions that would change the uuid of active subarrays
6361 * FIXME when immutable ids are available, but note that we'll
6362 * also need to fixup the invalidated/active subarray indexes in
6365 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6368 if (i
< current_vol
)
6370 sprintf(subarray
, "%u", i
);
6371 if (is_subarray_active(subarray
, st
->devnm
)) {
6372 pr_err("deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
6379 if (st
->update_tail
) {
6380 struct imsm_update_kill_array
*u
= xmalloc(sizeof(*u
));
6382 u
->type
= update_kill_array
;
6383 u
->dev_idx
= current_vol
;
6384 append_metadata_update(st
, u
, sizeof(*u
));
6389 for (dp
= &super
->devlist
; *dp
;)
6390 if ((*dp
)->index
== current_vol
) {
6393 handle_missing(super
, (*dp
)->dev
);
6394 if ((*dp
)->index
> current_vol
)
6399 /* no more raid devices, all active components are now spares,
6400 * but of course failed are still failed
6402 if (--mpb
->num_raid_devs
== 0) {
6405 for (d
= super
->disks
; d
; d
= d
->next
)
6410 super
->updates_pending
++;
6415 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
6416 char *update
, struct mddev_ident
*ident
)
6418 /* update the subarray currently referenced by ->current_vol */
6419 struct intel_super
*super
= st
->sb
;
6420 struct imsm_super
*mpb
= super
->anchor
;
6422 if (strcmp(update
, "name") == 0) {
6423 char *name
= ident
->name
;
6427 if (is_subarray_active(subarray
, st
->devnm
)) {
6428 pr_err("Unable to update name of active subarray\n");
6432 if (!check_name(super
, name
, 0))
6435 vol
= strtoul(subarray
, &ep
, 10);
6436 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
6439 if (st
->update_tail
) {
6440 struct imsm_update_rename_array
*u
= xmalloc(sizeof(*u
));
6442 u
->type
= update_rename_array
;
6444 snprintf((char *) u
->name
, MAX_RAID_SERIAL_LEN
, "%s", name
);
6445 append_metadata_update(st
, u
, sizeof(*u
));
6447 struct imsm_dev
*dev
;
6450 dev
= get_imsm_dev(super
, vol
);
6451 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
6452 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6453 dev
= get_imsm_dev(super
, i
);
6454 handle_missing(super
, dev
);
6456 super
->updates_pending
++;
6463 #endif /* MDASSEMBLE */
6465 static int is_gen_migration(struct imsm_dev
*dev
)
6470 if (!dev
->vol
.migr_state
)
6473 if (migr_type(dev
) == MIGR_GEN_MIGR
)
6479 static int is_rebuilding(struct imsm_dev
*dev
)
6481 struct imsm_map
*migr_map
;
6483 if (!dev
->vol
.migr_state
)
6486 if (migr_type(dev
) != MIGR_REBUILD
)
6489 migr_map
= get_imsm_map(dev
, MAP_1
);
6491 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
6498 static int is_initializing(struct imsm_dev
*dev
)
6500 struct imsm_map
*migr_map
;
6502 if (!dev
->vol
.migr_state
)
6505 if (migr_type(dev
) != MIGR_INIT
)
6508 migr_map
= get_imsm_map(dev
, MAP_1
);
6510 if (migr_map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
6517 static void update_recovery_start(struct intel_super
*super
,
6518 struct imsm_dev
*dev
,
6519 struct mdinfo
*array
)
6521 struct mdinfo
*rebuild
= NULL
;
6525 if (!is_rebuilding(dev
))
6528 /* Find the rebuild target, but punt on the dual rebuild case */
6529 for (d
= array
->devs
; d
; d
= d
->next
)
6530 if (d
->recovery_start
== 0) {
6537 /* (?) none of the disks are marked with
6538 * IMSM_ORD_REBUILD, so assume they are missing and the
6539 * disk_ord_tbl was not correctly updated
6541 dprintf("%s: failed to locate out-of-sync disk\n", __func__
);
6545 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
6546 rebuild
->recovery_start
= units
* blocks_per_migr_unit(super
, dev
);
6550 static int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
);
6553 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
6555 /* Given a container loaded by load_super_imsm_all,
6556 * extract information about all the arrays into
6558 * If 'subarray' is given, just extract info about that array.
6560 * For each imsm_dev create an mdinfo, fill it in,
6561 * then look for matching devices in super->disks
6562 * and create appropriate device mdinfo.
6564 struct intel_super
*super
= st
->sb
;
6565 struct imsm_super
*mpb
= super
->anchor
;
6566 struct mdinfo
*rest
= NULL
;
6570 int spare_disks
= 0;
6572 /* do not assemble arrays when not all attributes are supported */
6573 if (imsm_check_attributes(mpb
->attributes
) == 0) {
6575 pr_err("Unsupported attributes in IMSM metadata."
6576 "Arrays activation is blocked.\n");
6579 /* check for bad blocks */
6580 if (imsm_bbm_log_size(super
->anchor
)) {
6581 pr_err("BBM log found in IMSM metadata."
6582 "Arrays activation is blocked.\n");
6586 /* count spare devices, not used in maps
6588 for (d
= super
->disks
; d
; d
= d
->next
)
6592 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6593 struct imsm_dev
*dev
;
6594 struct imsm_map
*map
;
6595 struct imsm_map
*map2
;
6596 struct mdinfo
*this;
6604 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
6607 dev
= get_imsm_dev(super
, i
);
6608 map
= get_imsm_map(dev
, MAP_0
);
6609 map2
= get_imsm_map(dev
, MAP_1
);
6611 /* do not publish arrays that are in the middle of an
6612 * unsupported migration
6614 if (dev
->vol
.migr_state
&&
6615 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
6616 pr_err("cannot assemble volume '%.16s':"
6617 " unsupported migration in progress\n",
6621 /* do not publish arrays that are not support by controller's
6625 this = xmalloc(sizeof(*this));
6627 super
->current_vol
= i
;
6628 getinfo_super_imsm_volume(st
, this, NULL
);
6631 chunk
= __le16_to_cpu(map
->blocks_per_strip
) >> 1;
6632 /* mdadm does not support all metadata features- set the bit in all arrays state */
6633 if (!validate_geometry_imsm_orom(super
,
6634 get_imsm_raid_level(map
), /* RAID level */
6635 imsm_level_to_layout(get_imsm_raid_level(map
)),
6636 map
->num_members
, /* raid disks */
6637 &chunk
, join_u32(dev
->size_low
, dev
->size_high
),
6639 pr_err("IMSM RAID geometry validation"
6640 " failed. Array %s activation is blocked.\n",
6642 this->array
.state
|=
6643 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
6644 (1<<MD_SB_BLOCK_VOLUME
);
6648 /* if array has bad blocks, set suitable bit in all arrays state */
6650 this->array
.state
|=
6651 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
6652 (1<<MD_SB_BLOCK_VOLUME
);
6654 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
6655 unsigned long long recovery_start
;
6656 struct mdinfo
*info_d
;
6663 idx
= get_imsm_disk_idx(dev
, slot
, MAP_0
);
6664 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
6665 for (d
= super
->disks
; d
; d
= d
->next
)
6666 if (d
->index
== idx
)
6669 recovery_start
= MaxSector
;
6672 if (d
&& is_failed(&d
->disk
))
6674 if (ord
& IMSM_ORD_REBUILD
)
6678 * if we skip some disks the array will be assmebled degraded;
6679 * reset resync start to avoid a dirty-degraded
6680 * situation when performing the intial sync
6682 * FIXME handle dirty degraded
6684 if ((skip
|| recovery_start
== 0) && !dev
->vol
.dirty
)
6685 this->resync_start
= MaxSector
;
6689 info_d
= xcalloc(1, sizeof(*info_d
));
6690 info_d
->next
= this->devs
;
6691 this->devs
= info_d
;
6693 info_d
->disk
.number
= d
->index
;
6694 info_d
->disk
.major
= d
->major
;
6695 info_d
->disk
.minor
= d
->minor
;
6696 info_d
->disk
.raid_disk
= slot
;
6697 info_d
->recovery_start
= recovery_start
;
6699 if (slot
< map2
->num_members
)
6700 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
6702 this->array
.spare_disks
++;
6704 if (slot
< map
->num_members
)
6705 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
6707 this->array
.spare_disks
++;
6709 if (info_d
->recovery_start
== MaxSector
)
6710 this->array
.working_disks
++;
6712 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
6713 info_d
->data_offset
= pba_of_lba0(map
);
6714 info_d
->component_size
= blocks_per_member(map
);
6716 /* now that the disk list is up-to-date fixup recovery_start */
6717 update_recovery_start(super
, dev
, this);
6718 this->array
.spare_disks
+= spare_disks
;
6721 /* check for reshape */
6722 if (this->reshape_active
== 1)
6723 recover_backup_imsm(st
, this);
6731 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
6732 int failed
, int look_in_map
)
6734 struct imsm_map
*map
;
6736 map
= get_imsm_map(dev
, look_in_map
);
6739 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
6740 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
6742 switch (get_imsm_raid_level(map
)) {
6744 return IMSM_T_STATE_FAILED
;
6747 if (failed
< map
->num_members
)
6748 return IMSM_T_STATE_DEGRADED
;
6750 return IMSM_T_STATE_FAILED
;
6755 * check to see if any mirrors have failed, otherwise we
6756 * are degraded. Even numbered slots are mirrored on
6760 /* gcc -Os complains that this is unused */
6761 int insync
= insync
;
6763 for (i
= 0; i
< map
->num_members
; i
++) {
6764 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_X
);
6765 int idx
= ord_to_idx(ord
);
6766 struct imsm_disk
*disk
;
6768 /* reset the potential in-sync count on even-numbered
6769 * slots. num_copies is always 2 for imsm raid10
6774 disk
= get_imsm_disk(super
, idx
);
6775 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
6778 /* no in-sync disks left in this mirror the
6782 return IMSM_T_STATE_FAILED
;
6785 return IMSM_T_STATE_DEGRADED
;
6789 return IMSM_T_STATE_DEGRADED
;
6791 return IMSM_T_STATE_FAILED
;
6797 return map
->map_state
;
6800 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
6805 struct imsm_disk
*disk
;
6806 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
6807 struct imsm_map
*prev
= get_imsm_map(dev
, MAP_1
);
6808 struct imsm_map
*map_for_loop
;
6813 /* at the beginning of migration we set IMSM_ORD_REBUILD on
6814 * disks that are being rebuilt. New failures are recorded to
6815 * map[0]. So we look through all the disks we started with and
6816 * see if any failures are still present, or if any new ones
6820 if (prev
&& (map
->num_members
< prev
->num_members
))
6821 map_for_loop
= prev
;
6823 for (i
= 0; i
< map_for_loop
->num_members
; i
++) {
6825 /* when MAP_X is passed both maps failures are counted
6828 ((look_in_map
== MAP_1
) || (look_in_map
== MAP_X
)) &&
6829 (i
< prev
->num_members
)) {
6830 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
6831 idx_1
= ord_to_idx(ord
);
6833 disk
= get_imsm_disk(super
, idx_1
);
6834 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
6837 if (((look_in_map
== MAP_0
) || (look_in_map
== MAP_X
)) &&
6838 (i
< map
->num_members
)) {
6839 ord
= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
6840 idx
= ord_to_idx(ord
);
6843 disk
= get_imsm_disk(super
, idx
);
6844 if (!disk
|| is_failed(disk
) ||
6845 ord
& IMSM_ORD_REBUILD
)
6855 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
6858 struct intel_super
*super
= c
->sb
;
6859 struct imsm_super
*mpb
= super
->anchor
;
6861 if (atoi(inst
) >= mpb
->num_raid_devs
) {
6862 pr_err("%s: subarry index %d, out of range\n",
6863 __func__
, atoi(inst
));
6867 dprintf("imsm: open_new %s\n", inst
);
6868 a
->info
.container_member
= atoi(inst
);
6872 static int is_resyncing(struct imsm_dev
*dev
)
6874 struct imsm_map
*migr_map
;
6876 if (!dev
->vol
.migr_state
)
6879 if (migr_type(dev
) == MIGR_INIT
||
6880 migr_type(dev
) == MIGR_REPAIR
)
6883 if (migr_type(dev
) == MIGR_GEN_MIGR
)
6886 migr_map
= get_imsm_map(dev
, MAP_1
);
6888 if ((migr_map
->map_state
== IMSM_T_STATE_NORMAL
) &&
6889 (dev
->vol
.migr_type
!= MIGR_GEN_MIGR
))
6895 /* return true if we recorded new information */
6896 static int mark_failure(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
6900 struct imsm_map
*map
;
6901 char buf
[MAX_RAID_SERIAL_LEN
+3];
6902 unsigned int len
, shift
= 0;
6904 /* new failures are always set in map[0] */
6905 map
= get_imsm_map(dev
, MAP_0
);
6907 slot
= get_imsm_disk_slot(map
, idx
);
6911 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
6912 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
6915 memcpy(buf
, disk
->serial
, MAX_RAID_SERIAL_LEN
);
6916 buf
[MAX_RAID_SERIAL_LEN
] = '\000';
6918 if ((len
= strlen(buf
)) >= MAX_RAID_SERIAL_LEN
)
6919 shift
= len
- MAX_RAID_SERIAL_LEN
+ 1;
6920 strncpy((char *)disk
->serial
, &buf
[shift
], MAX_RAID_SERIAL_LEN
);
6922 disk
->status
|= FAILED_DISK
;
6923 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
6924 /* mark failures in second map if second map exists and this disk
6926 * This is valid for migration, initialization and rebuild
6928 if (dev
->vol
.migr_state
) {
6929 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
6930 int slot2
= get_imsm_disk_slot(map2
, idx
);
6932 if ((slot2
< map2
->num_members
) &&
6934 set_imsm_ord_tbl_ent(map2
, slot2
,
6935 idx
| IMSM_ORD_REBUILD
);
6937 if (map
->failed_disk_num
== 0xff)
6938 map
->failed_disk_num
= slot
;
6942 static void mark_missing(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
6944 mark_failure(dev
, disk
, idx
);
6946 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
6949 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
6950 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
6953 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
6957 if (!super
->missing
)
6960 /* When orom adds replacement for missing disk it does
6961 * not remove entry of missing disk, but just updates map with
6962 * new added disk. So it is not enough just to test if there is
6963 * any missing disk, we have to look if there are any failed disks
6964 * in map to stop migration */
6966 dprintf("imsm: mark missing\n");
6967 /* end process for initialization and rebuild only
6969 if (is_gen_migration(dev
) == 0) {
6973 failed
= imsm_count_failed(super
, dev
, MAP_0
);
6974 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
6977 end_migration(dev
, super
, map_state
);
6979 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
6980 mark_missing(dev
, &dl
->disk
, dl
->index
);
6981 super
->updates_pending
++;
6984 static unsigned long long imsm_set_array_size(struct imsm_dev
*dev
,
6987 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
6988 unsigned long long array_blocks
;
6989 struct imsm_map
*map
;
6991 if (used_disks
== 0) {
6992 /* when problems occures
6993 * return current array_blocks value
6995 array_blocks
= __le32_to_cpu(dev
->size_high
);
6996 array_blocks
= array_blocks
<< 32;
6997 array_blocks
+= __le32_to_cpu(dev
->size_low
);
6999 return array_blocks
;
7002 /* set array size in metadata
7004 if (new_size
<= 0) {
7005 /* OLCE size change is caused by added disks
7007 map
= get_imsm_map(dev
, MAP_0
);
7008 array_blocks
= blocks_per_member(map
) * used_disks
;
7010 /* Online Volume Size Change
7011 * Using available free space
7013 array_blocks
= new_size
;
7016 /* round array size down to closest MB
7018 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
7019 dev
->size_low
= __cpu_to_le32((__u32
)array_blocks
);
7020 dev
->size_high
= __cpu_to_le32((__u32
)(array_blocks
>> 32));
7022 return array_blocks
;
7025 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
7027 static void imsm_progress_container_reshape(struct intel_super
*super
)
7029 /* if no device has a migr_state, but some device has a
7030 * different number of members than the previous device, start
7031 * changing the number of devices in this device to match
7034 struct imsm_super
*mpb
= super
->anchor
;
7035 int prev_disks
= -1;
7039 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7040 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
7041 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7042 struct imsm_map
*map2
;
7043 int prev_num_members
;
7045 if (dev
->vol
.migr_state
)
7048 if (prev_disks
== -1)
7049 prev_disks
= map
->num_members
;
7050 if (prev_disks
== map
->num_members
)
7053 /* OK, this array needs to enter reshape mode.
7054 * i.e it needs a migr_state
7057 copy_map_size
= sizeof_imsm_map(map
);
7058 prev_num_members
= map
->num_members
;
7059 map
->num_members
= prev_disks
;
7060 dev
->vol
.migr_state
= 1;
7061 dev
->vol
.curr_migr_unit
= 0;
7062 set_migr_type(dev
, MIGR_GEN_MIGR
);
7063 for (i
= prev_num_members
;
7064 i
< map
->num_members
; i
++)
7065 set_imsm_ord_tbl_ent(map
, i
, i
);
7066 map2
= get_imsm_map(dev
, MAP_1
);
7067 /* Copy the current map */
7068 memcpy(map2
, map
, copy_map_size
);
7069 map2
->num_members
= prev_num_members
;
7071 imsm_set_array_size(dev
, -1);
7072 super
->clean_migration_record_by_mdmon
= 1;
7073 super
->updates_pending
++;
7077 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
7078 * states are handled in imsm_set_disk() with one exception, when a
7079 * resync is stopped due to a new failure this routine will set the
7080 * 'degraded' state for the array.
7082 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
7084 int inst
= a
->info
.container_member
;
7085 struct intel_super
*super
= a
->container
->sb
;
7086 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7087 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7088 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
7089 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7090 __u32 blocks_per_unit
;
7092 if (dev
->vol
.migr_state
&&
7093 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
7094 /* array state change is blocked due to reshape action
7096 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
7097 * - finish the reshape (if last_checkpoint is big and action != reshape)
7098 * - update curr_migr_unit
7100 if (a
->curr_action
== reshape
) {
7101 /* still reshaping, maybe update curr_migr_unit */
7102 goto mark_checkpoint
;
7104 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
7105 /* for some reason we aborted the reshape.
7107 * disable automatic metadata rollback
7108 * user action is required to recover process
7111 struct imsm_map
*map2
=
7112 get_imsm_map(dev
, MAP_1
);
7113 dev
->vol
.migr_state
= 0;
7114 set_migr_type(dev
, 0);
7115 dev
->vol
.curr_migr_unit
= 0;
7117 sizeof_imsm_map(map2
));
7118 super
->updates_pending
++;
7121 if (a
->last_checkpoint
>= a
->info
.component_size
) {
7122 unsigned long long array_blocks
;
7126 used_disks
= imsm_num_data_members(dev
, MAP_0
);
7127 if (used_disks
> 0) {
7129 blocks_per_member(map
) *
7131 /* round array size down to closest MB
7133 array_blocks
= (array_blocks
7134 >> SECT_PER_MB_SHIFT
)
7135 << SECT_PER_MB_SHIFT
;
7136 a
->info
.custom_array_size
= array_blocks
;
7137 /* encourage manager to update array
7141 a
->check_reshape
= 1;
7143 /* finalize online capacity expansion/reshape */
7144 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
7146 mdi
->disk
.raid_disk
,
7149 imsm_progress_container_reshape(super
);
7154 /* before we activate this array handle any missing disks */
7155 if (consistent
== 2)
7156 handle_missing(super
, dev
);
7158 if (consistent
== 2 &&
7159 (!is_resync_complete(&a
->info
) ||
7160 map_state
!= IMSM_T_STATE_NORMAL
||
7161 dev
->vol
.migr_state
))
7164 if (is_resync_complete(&a
->info
)) {
7165 /* complete intialization / resync,
7166 * recovery and interrupted recovery is completed in
7169 if (is_resyncing(dev
)) {
7170 dprintf("imsm: mark resync done\n");
7171 end_migration(dev
, super
, map_state
);
7172 super
->updates_pending
++;
7173 a
->last_checkpoint
= 0;
7175 } else if ((!is_resyncing(dev
) && !failed
) &&
7176 (imsm_reshape_blocks_arrays_changes(super
) == 0)) {
7177 /* mark the start of the init process if nothing is failed */
7178 dprintf("imsm: mark resync start\n");
7179 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
7180 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
7182 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
7183 super
->updates_pending
++;
7187 /* skip checkpointing for general migration,
7188 * it is controlled in mdadm
7190 if (is_gen_migration(dev
))
7191 goto skip_mark_checkpoint
;
7193 /* check if we can update curr_migr_unit from resync_start, recovery_start */
7194 blocks_per_unit
= blocks_per_migr_unit(super
, dev
);
7195 if (blocks_per_unit
) {
7199 units
= a
->last_checkpoint
/ blocks_per_unit
;
7202 /* check that we did not overflow 32-bits, and that
7203 * curr_migr_unit needs updating
7205 if (units32
== units
&&
7207 __le32_to_cpu(dev
->vol
.curr_migr_unit
) != units32
) {
7208 dprintf("imsm: mark checkpoint (%u)\n", units32
);
7209 dev
->vol
.curr_migr_unit
= __cpu_to_le32(units32
);
7210 super
->updates_pending
++;
7214 skip_mark_checkpoint
:
7215 /* mark dirty / clean */
7216 if (dev
->vol
.dirty
!= !consistent
) {
7217 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
7222 super
->updates_pending
++;
7228 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
7230 int inst
= a
->info
.container_member
;
7231 struct intel_super
*super
= a
->container
->sb
;
7232 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7233 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7234 struct imsm_disk
*disk
;
7236 int recovery_not_finished
= 0;
7241 if (n
> map
->num_members
)
7242 pr_err("imsm: set_disk %d out of range 0..%d\n",
7243 n
, map
->num_members
- 1);
7248 dprintf("imsm: set_disk %d:%x\n", n
, state
);
7250 ord
= get_imsm_ord_tbl_ent(dev
, n
, MAP_0
);
7251 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
7253 /* check for new failures */
7254 if (state
& DS_FAULTY
) {
7255 if (mark_failure(dev
, disk
, ord_to_idx(ord
)))
7256 super
->updates_pending
++;
7259 /* check if in_sync */
7260 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
7261 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
7263 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
7264 super
->updates_pending
++;
7267 failed
= imsm_count_failed(super
, dev
, MAP_0
);
7268 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7270 /* check if recovery complete, newly degraded, or failed */
7271 dprintf("imsm: Detected transition to state ");
7272 switch (map_state
) {
7273 case IMSM_T_STATE_NORMAL
: /* transition to normal state */
7274 dprintf("normal: ");
7275 if (is_rebuilding(dev
)) {
7276 dprintf("while rebuilding");
7277 /* check if recovery is really finished */
7278 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
7279 if (mdi
->recovery_start
!= MaxSector
) {
7280 recovery_not_finished
= 1;
7283 if (recovery_not_finished
) {
7284 dprintf("\nimsm: Rebuild has not finished yet, "
7285 "state not changed");
7286 if (a
->last_checkpoint
< mdi
->recovery_start
) {
7287 a
->last_checkpoint
= mdi
->recovery_start
;
7288 super
->updates_pending
++;
7292 end_migration(dev
, super
, map_state
);
7293 map
= get_imsm_map(dev
, MAP_0
);
7294 map
->failed_disk_num
= ~0;
7295 super
->updates_pending
++;
7296 a
->last_checkpoint
= 0;
7299 if (is_gen_migration(dev
)) {
7300 dprintf("while general migration");
7301 if (a
->last_checkpoint
>= a
->info
.component_size
)
7302 end_migration(dev
, super
, map_state
);
7304 map
->map_state
= map_state
;
7305 map
= get_imsm_map(dev
, MAP_0
);
7306 map
->failed_disk_num
= ~0;
7307 super
->updates_pending
++;
7311 case IMSM_T_STATE_DEGRADED
: /* transition to degraded state */
7312 dprintf("degraded: ");
7313 if ((map
->map_state
!= map_state
) &&
7314 !dev
->vol
.migr_state
) {
7315 dprintf("mark degraded");
7316 map
->map_state
= map_state
;
7317 super
->updates_pending
++;
7318 a
->last_checkpoint
= 0;
7321 if (is_rebuilding(dev
)) {
7322 dprintf("while rebuilding.");
7323 if (map
->map_state
!= map_state
) {
7324 dprintf(" Map state change");
7325 end_migration(dev
, super
, map_state
);
7326 super
->updates_pending
++;
7330 if (is_gen_migration(dev
)) {
7331 dprintf("while general migration");
7332 if (a
->last_checkpoint
>= a
->info
.component_size
)
7333 end_migration(dev
, super
, map_state
);
7335 map
->map_state
= map_state
;
7336 manage_second_map(super
, dev
);
7338 super
->updates_pending
++;
7341 if (is_initializing(dev
)) {
7342 dprintf("while initialization.");
7343 map
->map_state
= map_state
;
7344 super
->updates_pending
++;
7348 case IMSM_T_STATE_FAILED
: /* transition to failed state */
7349 dprintf("failed: ");
7350 if (is_gen_migration(dev
)) {
7351 dprintf("while general migration");
7352 map
->map_state
= map_state
;
7353 super
->updates_pending
++;
7356 if (map
->map_state
!= map_state
) {
7357 dprintf("mark failed");
7358 end_migration(dev
, super
, map_state
);
7359 super
->updates_pending
++;
7360 a
->last_checkpoint
= 0;
7365 dprintf("state %i\n", map_state
);
7371 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
7374 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
7375 unsigned long long dsize
;
7376 unsigned long long sectors
;
7378 get_dev_size(fd
, NULL
, &dsize
);
7380 if (mpb_size
> 512) {
7381 /* -1 to account for anchor */
7382 sectors
= mpb_sectors(mpb
) - 1;
7384 /* write the extended mpb to the sectors preceeding the anchor */
7385 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0)
7388 if ((unsigned long long)write(fd
, buf
+ 512, 512 * sectors
)
7393 /* first block is stored on second to last sector of the disk */
7394 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0)
7397 if (write(fd
, buf
, 512) != 512)
7403 static void imsm_sync_metadata(struct supertype
*container
)
7405 struct intel_super
*super
= container
->sb
;
7407 dprintf("sync metadata: %d\n", super
->updates_pending
);
7408 if (!super
->updates_pending
)
7411 write_super_imsm(container
, 0);
7413 super
->updates_pending
= 0;
7416 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
7418 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
7419 int i
= get_imsm_disk_idx(dev
, idx
, MAP_X
);
7422 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7426 if (dl
&& is_failed(&dl
->disk
))
7430 dprintf("%s: found %x:%x\n", __func__
, dl
->major
, dl
->minor
);
7435 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
7436 struct active_array
*a
, int activate_new
,
7437 struct mdinfo
*additional_test_list
)
7439 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
7440 int idx
= get_imsm_disk_idx(dev
, slot
, MAP_X
);
7441 struct imsm_super
*mpb
= super
->anchor
;
7442 struct imsm_map
*map
;
7443 unsigned long long pos
;
7448 __u32 array_start
= 0;
7449 __u32 array_end
= 0;
7451 struct mdinfo
*test_list
;
7453 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7454 /* If in this array, skip */
7455 for (d
= a
->info
.devs
; d
; d
= d
->next
)
7456 if (d
->state_fd
>= 0 &&
7457 d
->disk
.major
== dl
->major
&&
7458 d
->disk
.minor
== dl
->minor
) {
7459 dprintf("%x:%x already in array\n",
7460 dl
->major
, dl
->minor
);
7465 test_list
= additional_test_list
;
7467 if (test_list
->disk
.major
== dl
->major
&&
7468 test_list
->disk
.minor
== dl
->minor
) {
7469 dprintf("%x:%x already in additional test list\n",
7470 dl
->major
, dl
->minor
);
7473 test_list
= test_list
->next
;
7478 /* skip in use or failed drives */
7479 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
7481 dprintf("%x:%x status (failed: %d index: %d)\n",
7482 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
7486 /* skip pure spares when we are looking for partially
7487 * assimilated drives
7489 if (dl
->index
== -1 && !activate_new
)
7492 /* Does this unused device have the requisite free space?
7493 * It needs to be able to cover all member volumes
7495 ex
= get_extents(super
, dl
);
7497 dprintf("cannot get extents\n");
7500 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7501 dev
= get_imsm_dev(super
, i
);
7502 map
= get_imsm_map(dev
, MAP_0
);
7504 /* check if this disk is already a member of
7507 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
7513 array_start
= pba_of_lba0(map
);
7514 array_end
= array_start
+
7515 blocks_per_member(map
) - 1;
7518 /* check that we can start at pba_of_lba0 with
7519 * blocks_per_member of space
7521 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
7525 pos
= ex
[j
].start
+ ex
[j
].size
;
7527 } while (ex
[j
-1].size
);
7534 if (i
< mpb
->num_raid_devs
) {
7535 dprintf("%x:%x does not have %u to %u available\n",
7536 dl
->major
, dl
->minor
, array_start
, array_end
);
7546 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
7548 struct imsm_dev
*dev2
;
7549 struct imsm_map
*map
;
7555 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
7557 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
, MAP_0
);
7558 if (state
== IMSM_T_STATE_FAILED
) {
7559 map
= get_imsm_map(dev2
, MAP_0
);
7562 for (slot
= 0; slot
< map
->num_members
; slot
++) {
7564 * Check if failed disks are deleted from intel
7565 * disk list or are marked to be deleted
7567 idx
= get_imsm_disk_idx(dev2
, slot
, MAP_X
);
7568 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
7570 * Do not rebuild the array if failed disks
7571 * from failed sub-array are not removed from
7575 is_failed(&idisk
->disk
) &&
7576 (idisk
->action
!= DISK_REMOVE
))
7584 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
7585 struct metadata_update
**updates
)
7588 * Find a device with unused free space and use it to replace a
7589 * failed/vacant region in an array. We replace failed regions one a
7590 * array at a time. The result is that a new spare disk will be added
7591 * to the first failed array and after the monitor has finished
7592 * propagating failures the remainder will be consumed.
7594 * FIXME add a capability for mdmon to request spares from another
7598 struct intel_super
*super
= a
->container
->sb
;
7599 int inst
= a
->info
.container_member
;
7600 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7601 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7602 int failed
= a
->info
.array
.raid_disks
;
7603 struct mdinfo
*rv
= NULL
;
7606 struct metadata_update
*mu
;
7608 struct imsm_update_activate_spare
*u
;
7613 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
7614 if ((d
->curr_state
& DS_FAULTY
) &&
7616 /* wait for Removal to happen */
7618 if (d
->state_fd
>= 0)
7622 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
7623 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
7625 if (imsm_reshape_blocks_arrays_changes(super
))
7628 /* Cannot activate another spare if rebuild is in progress already
7630 if (is_rebuilding(dev
)) {
7631 dprintf("imsm: No spare activation allowed. "
7632 "Rebuild in progress already.\n");
7636 if (a
->info
.array
.level
== 4)
7637 /* No repair for takeovered array
7638 * imsm doesn't support raid4
7642 if (imsm_check_degraded(super
, dev
, failed
, MAP_0
) !=
7643 IMSM_T_STATE_DEGRADED
)
7647 * If there are any failed disks check state of the other volume.
7648 * Block rebuild if the another one is failed until failed disks
7649 * are removed from container.
7652 dprintf("found failed disks in %.*s, check if there another"
7653 "failed sub-array.\n",
7654 MAX_RAID_SERIAL_LEN
, dev
->volume
);
7655 /* check if states of the other volumes allow for rebuild */
7656 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
7658 allowed
= imsm_rebuild_allowed(a
->container
,
7666 /* For each slot, if it is not working, find a spare */
7667 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
7668 for (d
= a
->info
.devs
; d
; d
= d
->next
)
7669 if (d
->disk
.raid_disk
== i
)
7671 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
7672 if (d
&& (d
->state_fd
>= 0))
7676 * OK, this device needs recovery. Try to re-add the
7677 * previous occupant of this slot, if this fails see if
7678 * we can continue the assimilation of a spare that was
7679 * partially assimilated, finally try to activate a new
7682 dl
= imsm_readd(super
, i
, a
);
7684 dl
= imsm_add_spare(super
, i
, a
, 0, rv
);
7686 dl
= imsm_add_spare(super
, i
, a
, 1, rv
);
7690 /* found a usable disk with enough space */
7691 di
= xcalloc(1, sizeof(*di
));
7693 /* dl->index will be -1 in the case we are activating a
7694 * pristine spare. imsm_process_update() will create a
7695 * new index in this case. Once a disk is found to be
7696 * failed in all member arrays it is kicked from the
7699 di
->disk
.number
= dl
->index
;
7701 /* (ab)use di->devs to store a pointer to the device
7704 di
->devs
= (struct mdinfo
*) dl
;
7706 di
->disk
.raid_disk
= i
;
7707 di
->disk
.major
= dl
->major
;
7708 di
->disk
.minor
= dl
->minor
;
7710 di
->recovery_start
= 0;
7711 di
->data_offset
= pba_of_lba0(map
);
7712 di
->component_size
= a
->info
.component_size
;
7713 di
->container_member
= inst
;
7714 super
->random
= random32();
7718 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
7719 i
, di
->data_offset
);
7723 /* No spares found */
7725 /* Now 'rv' has a list of devices to return.
7726 * Create a metadata_update record to update the
7727 * disk_ord_tbl for the array
7729 mu
= xmalloc(sizeof(*mu
));
7730 mu
->buf
= xcalloc(num_spares
,
7731 sizeof(struct imsm_update_activate_spare
));
7733 mu
->space_list
= NULL
;
7734 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
7735 mu
->next
= *updates
;
7736 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
7738 for (di
= rv
; di
; di
= di
->next
) {
7739 u
->type
= update_activate_spare
;
7740 u
->dl
= (struct dl
*) di
->devs
;
7742 u
->slot
= di
->disk
.raid_disk
;
7753 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
7755 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
7756 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7757 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, MAP_0
);
7758 struct disk_info
*inf
= get_disk_info(u
);
7759 struct imsm_disk
*disk
;
7763 for (i
= 0; i
< map
->num_members
; i
++) {
7764 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, MAP_X
));
7765 for (j
= 0; j
< new_map
->num_members
; j
++)
7766 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
7773 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
7775 struct dl
*dl
= NULL
;
7776 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7777 if ((dl
->major
== major
) && (dl
->minor
== minor
))
7782 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
7784 struct dl
*prev
= NULL
;
7788 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7789 if ((dl
->major
== major
) && (dl
->minor
== minor
)) {
7792 prev
->next
= dl
->next
;
7794 super
->disks
= dl
->next
;
7796 __free_imsm_disk(dl
);
7797 dprintf("%s: removed %x:%x\n",
7798 __func__
, major
, minor
);
7806 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
7808 static int add_remove_disk_update(struct intel_super
*super
)
7810 int check_degraded
= 0;
7811 struct dl
*disk
= NULL
;
7812 /* add/remove some spares to/from the metadata/contrainer */
7813 while (super
->disk_mgmt_list
) {
7814 struct dl
*disk_cfg
;
7816 disk_cfg
= super
->disk_mgmt_list
;
7817 super
->disk_mgmt_list
= disk_cfg
->next
;
7818 disk_cfg
->next
= NULL
;
7820 if (disk_cfg
->action
== DISK_ADD
) {
7821 disk_cfg
->next
= super
->disks
;
7822 super
->disks
= disk_cfg
;
7824 dprintf("%s: added %x:%x\n",
7825 __func__
, disk_cfg
->major
,
7827 } else if (disk_cfg
->action
== DISK_REMOVE
) {
7828 dprintf("Disk remove action processed: %x.%x\n",
7829 disk_cfg
->major
, disk_cfg
->minor
);
7830 disk
= get_disk_super(super
,
7834 /* store action status */
7835 disk
->action
= DISK_REMOVE
;
7836 /* remove spare disks only */
7837 if (disk
->index
== -1) {
7838 remove_disk_super(super
,
7843 /* release allocate disk structure */
7844 __free_imsm_disk(disk_cfg
);
7847 return check_degraded
;
7850 static int apply_reshape_migration_update(struct imsm_update_reshape_migration
*u
,
7851 struct intel_super
*super
,
7854 struct intel_dev
*id
;
7855 void **tofree
= NULL
;
7858 dprintf("apply_reshape_migration_update()\n");
7859 if ((u
->subdev
< 0) ||
7861 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
7864 if ((space_list
== NULL
) || (*space_list
== NULL
)) {
7865 dprintf("imsm: Error: Memory is not allocated\n");
7869 for (id
= super
->devlist
; id
; id
= id
->next
) {
7870 if (id
->index
== (unsigned)u
->subdev
) {
7871 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
7872 struct imsm_map
*map
;
7873 struct imsm_dev
*new_dev
=
7874 (struct imsm_dev
*)*space_list
;
7875 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
7877 struct dl
*new_disk
;
7879 if (new_dev
== NULL
)
7881 *space_list
= **space_list
;
7882 memcpy(new_dev
, dev
, sizeof_imsm_dev(dev
, 0));
7883 map
= get_imsm_map(new_dev
, MAP_0
);
7885 dprintf("imsm: Error: migration in progress");
7889 to_state
= map
->map_state
;
7890 if ((u
->new_level
== 5) && (map
->raid_level
== 0)) {
7892 /* this should not happen */
7893 if (u
->new_disks
[0] < 0) {
7894 map
->failed_disk_num
=
7895 map
->num_members
- 1;
7896 to_state
= IMSM_T_STATE_DEGRADED
;
7898 to_state
= IMSM_T_STATE_NORMAL
;
7900 migrate(new_dev
, super
, to_state
, MIGR_GEN_MIGR
);
7901 if (u
->new_level
> -1)
7902 map
->raid_level
= u
->new_level
;
7903 migr_map
= get_imsm_map(new_dev
, MAP_1
);
7904 if ((u
->new_level
== 5) &&
7905 (migr_map
->raid_level
== 0)) {
7906 int ord
= map
->num_members
- 1;
7907 migr_map
->num_members
--;
7908 if (u
->new_disks
[0] < 0)
7909 ord
|= IMSM_ORD_REBUILD
;
7910 set_imsm_ord_tbl_ent(map
,
7911 map
->num_members
- 1,
7915 tofree
= (void **)dev
;
7917 /* update chunk size
7919 if (u
->new_chunksize
> 0)
7920 map
->blocks_per_strip
=
7921 __cpu_to_le16(u
->new_chunksize
* 2);
7925 if ((u
->new_level
!= 5) ||
7926 (migr_map
->raid_level
!= 0) ||
7927 (migr_map
->raid_level
== map
->raid_level
))
7930 if (u
->new_disks
[0] >= 0) {
7933 new_disk
= get_disk_super(super
,
7934 major(u
->new_disks
[0]),
7935 minor(u
->new_disks
[0]));
7936 dprintf("imsm: new disk for reshape is: %i:%i "
7937 "(%p, index = %i)\n",
7938 major(u
->new_disks
[0]),
7939 minor(u
->new_disks
[0]),
7940 new_disk
, new_disk
->index
);
7941 if (new_disk
== NULL
)
7942 goto error_disk_add
;
7944 new_disk
->index
= map
->num_members
- 1;
7945 /* slot to fill in autolayout
7947 new_disk
->raiddisk
= new_disk
->index
;
7948 new_disk
->disk
.status
|= CONFIGURED_DISK
;
7949 new_disk
->disk
.status
&= ~SPARE_DISK
;
7951 goto error_disk_add
;
7954 *tofree
= *space_list
;
7955 /* calculate new size
7957 imsm_set_array_size(new_dev
, -1);
7964 *space_list
= tofree
;
7968 dprintf("Error: imsm: Cannot find disk.\n");
7972 static int apply_size_change_update(struct imsm_update_size_change
*u
,
7973 struct intel_super
*super
)
7975 struct intel_dev
*id
;
7978 dprintf("apply_size_change_update()\n");
7979 if ((u
->subdev
< 0) ||
7981 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
7985 for (id
= super
->devlist
; id
; id
= id
->next
) {
7986 if (id
->index
== (unsigned)u
->subdev
) {
7987 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
7988 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7989 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
7990 unsigned long long blocks_per_member
;
7992 /* calculate new size
7994 blocks_per_member
= u
->new_size
/ used_disks
;
7995 dprintf("imsm: apply_size_change_update(size: %llu, "
7996 "blocks per member: %llu)\n",
7997 u
->new_size
, blocks_per_member
);
7998 set_blocks_per_member(map
, blocks_per_member
);
7999 imsm_set_array_size(dev
, u
->new_size
);
8009 static int apply_update_activate_spare(struct imsm_update_activate_spare
*u
,
8010 struct intel_super
*super
,
8011 struct active_array
*active_array
)
8013 struct imsm_super
*mpb
= super
->anchor
;
8014 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
8015 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8016 struct imsm_map
*migr_map
;
8017 struct active_array
*a
;
8018 struct imsm_disk
*disk
;
8025 int second_map_created
= 0;
8027 for (; u
; u
= u
->next
) {
8028 victim
= get_imsm_disk_idx(dev
, u
->slot
, MAP_X
);
8033 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8038 pr_err("error: imsm_activate_spare passed "
8039 "an unknown disk (index: %d)\n",
8044 /* count failures (excluding rebuilds and the victim)
8045 * to determine map[0] state
8048 for (i
= 0; i
< map
->num_members
; i
++) {
8051 disk
= get_imsm_disk(super
,
8052 get_imsm_disk_idx(dev
, i
, MAP_X
));
8053 if (!disk
|| is_failed(disk
))
8057 /* adding a pristine spare, assign a new index */
8058 if (dl
->index
< 0) {
8059 dl
->index
= super
->anchor
->num_disks
;
8060 super
->anchor
->num_disks
++;
8063 disk
->status
|= CONFIGURED_DISK
;
8064 disk
->status
&= ~SPARE_DISK
;
8067 to_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8068 if (!second_map_created
) {
8069 second_map_created
= 1;
8070 map
->map_state
= IMSM_T_STATE_DEGRADED
;
8071 migrate(dev
, super
, to_state
, MIGR_REBUILD
);
8073 map
->map_state
= to_state
;
8074 migr_map
= get_imsm_map(dev
, MAP_1
);
8075 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
8076 set_imsm_ord_tbl_ent(migr_map
, u
->slot
,
8077 dl
->index
| IMSM_ORD_REBUILD
);
8079 /* update the family_num to mark a new container
8080 * generation, being careful to record the existing
8081 * family_num in orig_family_num to clean up after
8082 * earlier mdadm versions that neglected to set it.
8084 if (mpb
->orig_family_num
== 0)
8085 mpb
->orig_family_num
= mpb
->family_num
;
8086 mpb
->family_num
+= super
->random
;
8088 /* count arrays using the victim in the metadata */
8090 for (a
= active_array
; a
; a
= a
->next
) {
8091 dev
= get_imsm_dev(super
, a
->info
.container_member
);
8092 map
= get_imsm_map(dev
, MAP_0
);
8094 if (get_imsm_disk_slot(map
, victim
) >= 0)
8098 /* delete the victim if it is no longer being
8104 /* We know that 'manager' isn't touching anything,
8105 * so it is safe to delete
8107 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
8108 if ((*dlp
)->index
== victim
)
8111 /* victim may be on the missing list */
8113 for (dlp
= &super
->missing
; *dlp
;
8114 dlp
= &(*dlp
)->next
)
8115 if ((*dlp
)->index
== victim
)
8117 imsm_delete(super
, dlp
, victim
);
8124 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
8125 struct intel_super
*super
,
8128 struct dl
*new_disk
;
8129 struct intel_dev
*id
;
8131 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
8132 int disk_count
= u
->old_raid_disks
;
8133 void **tofree
= NULL
;
8134 int devices_to_reshape
= 1;
8135 struct imsm_super
*mpb
= super
->anchor
;
8137 unsigned int dev_id
;
8139 dprintf("imsm: apply_reshape_container_disks_update()\n");
8141 /* enable spares to use in array */
8142 for (i
= 0; i
< delta_disks
; i
++) {
8143 new_disk
= get_disk_super(super
,
8144 major(u
->new_disks
[i
]),
8145 minor(u
->new_disks
[i
]));
8146 dprintf("imsm: new disk for reshape is: %i:%i "
8147 "(%p, index = %i)\n",
8148 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
8149 new_disk
, new_disk
->index
);
8150 if ((new_disk
== NULL
) ||
8151 ((new_disk
->index
>= 0) &&
8152 (new_disk
->index
< u
->old_raid_disks
)))
8153 goto update_reshape_exit
;
8154 new_disk
->index
= disk_count
++;
8155 /* slot to fill in autolayout
8157 new_disk
->raiddisk
= new_disk
->index
;
8158 new_disk
->disk
.status
|=
8160 new_disk
->disk
.status
&= ~SPARE_DISK
;
8163 dprintf("imsm: volume set mpb->num_raid_devs = %i\n",
8164 mpb
->num_raid_devs
);
8165 /* manage changes in volume
8167 for (dev_id
= 0; dev_id
< mpb
->num_raid_devs
; dev_id
++) {
8168 void **sp
= *space_list
;
8169 struct imsm_dev
*newdev
;
8170 struct imsm_map
*newmap
, *oldmap
;
8172 for (id
= super
->devlist
; id
; id
= id
->next
) {
8173 if (id
->index
== dev_id
)
8182 /* Copy the dev, but not (all of) the map */
8183 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
8184 oldmap
= get_imsm_map(id
->dev
, MAP_0
);
8185 newmap
= get_imsm_map(newdev
, MAP_0
);
8186 /* Copy the current map */
8187 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
8188 /* update one device only
8190 if (devices_to_reshape
) {
8191 dprintf("imsm: modifying subdev: %i\n",
8193 devices_to_reshape
--;
8194 newdev
->vol
.migr_state
= 1;
8195 newdev
->vol
.curr_migr_unit
= 0;
8196 set_migr_type(newdev
, MIGR_GEN_MIGR
);
8197 newmap
->num_members
= u
->new_raid_disks
;
8198 for (i
= 0; i
< delta_disks
; i
++) {
8199 set_imsm_ord_tbl_ent(newmap
,
8200 u
->old_raid_disks
+ i
,
8201 u
->old_raid_disks
+ i
);
8203 /* New map is correct, now need to save old map
8205 newmap
= get_imsm_map(newdev
, MAP_1
);
8206 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
8208 imsm_set_array_size(newdev
, -1);
8211 sp
= (void **)id
->dev
;
8216 /* Clear migration record */
8217 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
8220 *space_list
= tofree
;
8223 update_reshape_exit
:
8228 static int apply_takeover_update(struct imsm_update_takeover
*u
,
8229 struct intel_super
*super
,
8232 struct imsm_dev
*dev
= NULL
;
8233 struct intel_dev
*dv
;
8234 struct imsm_dev
*dev_new
;
8235 struct imsm_map
*map
;
8239 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
8240 if (dv
->index
== (unsigned int)u
->subarray
) {
8248 map
= get_imsm_map(dev
, MAP_0
);
8250 if (u
->direction
== R10_TO_R0
) {
8251 /* Number of failed disks must be half of initial disk number */
8252 if (imsm_count_failed(super
, dev
, MAP_0
) !=
8253 (map
->num_members
/ 2))
8256 /* iterate through devices to mark removed disks as spare */
8257 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
8258 if (dm
->disk
.status
& FAILED_DISK
) {
8259 int idx
= dm
->index
;
8260 /* update indexes on the disk list */
8261 /* FIXME this loop-with-the-loop looks wrong, I'm not convinced
8262 the index values will end up being correct.... NB */
8263 for (du
= super
->disks
; du
; du
= du
->next
)
8264 if (du
->index
> idx
)
8266 /* mark as spare disk */
8271 map
->num_members
= map
->num_members
/ 2;
8272 map
->map_state
= IMSM_T_STATE_NORMAL
;
8273 map
->num_domains
= 1;
8274 map
->raid_level
= 0;
8275 map
->failed_disk_num
= -1;
8278 if (u
->direction
== R0_TO_R10
) {
8280 /* update slots in current disk list */
8281 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
8285 /* create new *missing* disks */
8286 for (i
= 0; i
< map
->num_members
; i
++) {
8287 space
= *space_list
;
8290 *space_list
= *space
;
8292 memcpy(du
, super
->disks
, sizeof(*du
));
8296 du
->index
= (i
* 2) + 1;
8297 sprintf((char *)du
->disk
.serial
,
8298 " MISSING_%d", du
->index
);
8299 sprintf((char *)du
->serial
,
8300 "MISSING_%d", du
->index
);
8301 du
->next
= super
->missing
;
8302 super
->missing
= du
;
8304 /* create new dev and map */
8305 space
= *space_list
;
8308 *space_list
= *space
;
8309 dev_new
= (void *)space
;
8310 memcpy(dev_new
, dev
, sizeof(*dev
));
8311 /* update new map */
8312 map
= get_imsm_map(dev_new
, MAP_0
);
8313 map
->num_members
= map
->num_members
* 2;
8314 map
->map_state
= IMSM_T_STATE_DEGRADED
;
8315 map
->num_domains
= 2;
8316 map
->raid_level
= 1;
8317 /* replace dev<->dev_new */
8320 /* update disk order table */
8321 for (du
= super
->disks
; du
; du
= du
->next
)
8323 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
8324 for (du
= super
->missing
; du
; du
= du
->next
)
8325 if (du
->index
>= 0) {
8326 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
8327 mark_missing(dv
->dev
, &du
->disk
, du
->index
);
8333 static void imsm_process_update(struct supertype
*st
,
8334 struct metadata_update
*update
)
8337 * crack open the metadata_update envelope to find the update record
8338 * update can be one of:
8339 * update_reshape_container_disks - all the arrays in the container
8340 * are being reshaped to have more devices. We need to mark
8341 * the arrays for general migration and convert selected spares
8342 * into active devices.
8343 * update_activate_spare - a spare device has replaced a failed
8344 * device in an array, update the disk_ord_tbl. If this disk is
8345 * present in all member arrays then also clear the SPARE_DISK
8347 * update_create_array
8349 * update_rename_array
8350 * update_add_remove_disk
8352 struct intel_super
*super
= st
->sb
;
8353 struct imsm_super
*mpb
;
8354 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
8356 /* update requires a larger buf but the allocation failed */
8357 if (super
->next_len
&& !super
->next_buf
) {
8358 super
->next_len
= 0;
8362 if (super
->next_buf
) {
8363 memcpy(super
->next_buf
, super
->buf
, super
->len
);
8365 super
->len
= super
->next_len
;
8366 super
->buf
= super
->next_buf
;
8368 super
->next_len
= 0;
8369 super
->next_buf
= NULL
;
8372 mpb
= super
->anchor
;
8375 case update_general_migration_checkpoint
: {
8376 struct intel_dev
*id
;
8377 struct imsm_update_general_migration_checkpoint
*u
=
8378 (void *)update
->buf
;
8380 dprintf("imsm: process_update() "
8381 "for update_general_migration_checkpoint called\n");
8383 /* find device under general migration */
8384 for (id
= super
->devlist
; id
; id
= id
->next
) {
8385 if (is_gen_migration(id
->dev
)) {
8386 id
->dev
->vol
.curr_migr_unit
=
8387 __cpu_to_le32(u
->curr_migr_unit
);
8388 super
->updates_pending
++;
8393 case update_takeover
: {
8394 struct imsm_update_takeover
*u
= (void *)update
->buf
;
8395 if (apply_takeover_update(u
, super
, &update
->space_list
)) {
8396 imsm_update_version_info(super
);
8397 super
->updates_pending
++;
8402 case update_reshape_container_disks
: {
8403 struct imsm_update_reshape
*u
= (void *)update
->buf
;
8404 if (apply_reshape_container_disks_update(
8405 u
, super
, &update
->space_list
))
8406 super
->updates_pending
++;
8409 case update_reshape_migration
: {
8410 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
8411 if (apply_reshape_migration_update(
8412 u
, super
, &update
->space_list
))
8413 super
->updates_pending
++;
8416 case update_size_change
: {
8417 struct imsm_update_size_change
*u
= (void *)update
->buf
;
8418 if (apply_size_change_update(u
, super
))
8419 super
->updates_pending
++;
8422 case update_activate_spare
: {
8423 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
8424 if (apply_update_activate_spare(u
, super
, st
->arrays
))
8425 super
->updates_pending
++;
8428 case update_create_array
: {
8429 /* someone wants to create a new array, we need to be aware of
8430 * a few races/collisions:
8431 * 1/ 'Create' called by two separate instances of mdadm
8432 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
8433 * devices that have since been assimilated via
8435 * In the event this update can not be carried out mdadm will
8436 * (FIX ME) notice that its update did not take hold.
8438 struct imsm_update_create_array
*u
= (void *) update
->buf
;
8439 struct intel_dev
*dv
;
8440 struct imsm_dev
*dev
;
8441 struct imsm_map
*map
, *new_map
;
8442 unsigned long long start
, end
;
8443 unsigned long long new_start
, new_end
;
8445 struct disk_info
*inf
;
8448 /* handle racing creates: first come first serve */
8449 if (u
->dev_idx
< mpb
->num_raid_devs
) {
8450 dprintf("%s: subarray %d already defined\n",
8451 __func__
, u
->dev_idx
);
8455 /* check update is next in sequence */
8456 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
8457 dprintf("%s: can not create array %d expected index %d\n",
8458 __func__
, u
->dev_idx
, mpb
->num_raid_devs
);
8462 new_map
= get_imsm_map(&u
->dev
, MAP_0
);
8463 new_start
= pba_of_lba0(new_map
);
8464 new_end
= new_start
+ blocks_per_member(new_map
);
8465 inf
= get_disk_info(u
);
8467 /* handle activate_spare versus create race:
8468 * check to make sure that overlapping arrays do not include
8471 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8472 dev
= get_imsm_dev(super
, i
);
8473 map
= get_imsm_map(dev
, MAP_0
);
8474 start
= pba_of_lba0(map
);
8475 end
= start
+ blocks_per_member(map
);
8476 if ((new_start
>= start
&& new_start
<= end
) ||
8477 (start
>= new_start
&& start
<= new_end
))
8482 if (disks_overlap(super
, i
, u
)) {
8483 dprintf("%s: arrays overlap\n", __func__
);
8488 /* check that prepare update was successful */
8489 if (!update
->space
) {
8490 dprintf("%s: prepare update failed\n", __func__
);
8494 /* check that all disks are still active before committing
8495 * changes. FIXME: could we instead handle this by creating a
8496 * degraded array? That's probably not what the user expects,
8497 * so better to drop this update on the floor.
8499 for (i
= 0; i
< new_map
->num_members
; i
++) {
8500 dl
= serial_to_dl(inf
[i
].serial
, super
);
8502 dprintf("%s: disk disappeared\n", __func__
);
8507 super
->updates_pending
++;
8509 /* convert spares to members and fixup ord_tbl */
8510 for (i
= 0; i
< new_map
->num_members
; i
++) {
8511 dl
= serial_to_dl(inf
[i
].serial
, super
);
8512 if (dl
->index
== -1) {
8513 dl
->index
= mpb
->num_disks
;
8515 dl
->disk
.status
|= CONFIGURED_DISK
;
8516 dl
->disk
.status
&= ~SPARE_DISK
;
8518 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
8523 update
->space
= NULL
;
8524 imsm_copy_dev(dev
, &u
->dev
);
8525 dv
->index
= u
->dev_idx
;
8526 dv
->next
= super
->devlist
;
8527 super
->devlist
= dv
;
8528 mpb
->num_raid_devs
++;
8530 imsm_update_version_info(super
);
8533 /* mdmon knows how to release update->space, but not
8534 * ((struct intel_dev *) update->space)->dev
8536 if (update
->space
) {
8542 case update_kill_array
: {
8543 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
8544 int victim
= u
->dev_idx
;
8545 struct active_array
*a
;
8546 struct intel_dev
**dp
;
8547 struct imsm_dev
*dev
;
8549 /* sanity check that we are not affecting the uuid of
8550 * active arrays, or deleting an active array
8552 * FIXME when immutable ids are available, but note that
8553 * we'll also need to fixup the invalidated/active
8554 * subarray indexes in mdstat
8556 for (a
= st
->arrays
; a
; a
= a
->next
)
8557 if (a
->info
.container_member
>= victim
)
8559 /* by definition if mdmon is running at least one array
8560 * is active in the container, so checking
8561 * mpb->num_raid_devs is just extra paranoia
8563 dev
= get_imsm_dev(super
, victim
);
8564 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
8565 dprintf("failed to delete subarray-%d\n", victim
);
8569 for (dp
= &super
->devlist
; *dp
;)
8570 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
8573 if ((*dp
)->index
> (unsigned)victim
)
8577 mpb
->num_raid_devs
--;
8578 super
->updates_pending
++;
8581 case update_rename_array
: {
8582 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
8583 char name
[MAX_RAID_SERIAL_LEN
+1];
8584 int target
= u
->dev_idx
;
8585 struct active_array
*a
;
8586 struct imsm_dev
*dev
;
8588 /* sanity check that we are not affecting the uuid of
8591 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
8592 name
[MAX_RAID_SERIAL_LEN
] = '\0';
8593 for (a
= st
->arrays
; a
; a
= a
->next
)
8594 if (a
->info
.container_member
== target
)
8596 dev
= get_imsm_dev(super
, u
->dev_idx
);
8597 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
8598 dprintf("failed to rename subarray-%d\n", target
);
8602 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
8603 super
->updates_pending
++;
8606 case update_add_remove_disk
: {
8607 /* we may be able to repair some arrays if disks are
8608 * being added, check the status of add_remove_disk
8609 * if discs has been added.
8611 if (add_remove_disk_update(super
)) {
8612 struct active_array
*a
;
8614 super
->updates_pending
++;
8615 for (a
= st
->arrays
; a
; a
= a
->next
)
8616 a
->check_degraded
= 1;
8621 pr_err("error: unsuported process update type:"
8622 "(type: %d)\n", type
);
8626 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
);
8628 static int imsm_prepare_update(struct supertype
*st
,
8629 struct metadata_update
*update
)
8632 * Allocate space to hold new disk entries, raid-device entries or a new
8633 * mpb if necessary. The manager synchronously waits for updates to
8634 * complete in the monitor, so new mpb buffers allocated here can be
8635 * integrated by the monitor thread without worrying about live pointers
8636 * in the manager thread.
8638 enum imsm_update_type type
;
8639 struct intel_super
*super
= st
->sb
;
8640 struct imsm_super
*mpb
= super
->anchor
;
8644 if (update
->len
< (int)sizeof(type
))
8647 type
= *(enum imsm_update_type
*) update
->buf
;
8650 case update_general_migration_checkpoint
:
8651 if (update
->len
< (int)sizeof(struct imsm_update_general_migration_checkpoint
))
8653 dprintf("imsm: prepare_update() "
8654 "for update_general_migration_checkpoint called\n");
8656 case update_takeover
: {
8657 struct imsm_update_takeover
*u
= (void *)update
->buf
;
8658 if (update
->len
< (int)sizeof(*u
))
8660 if (u
->direction
== R0_TO_R10
) {
8661 void **tail
= (void **)&update
->space_list
;
8662 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subarray
);
8663 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8664 int num_members
= map
->num_members
;
8667 /* allocate memory for added disks */
8668 for (i
= 0; i
< num_members
; i
++) {
8669 size
= sizeof(struct dl
);
8670 space
= xmalloc(size
);
8675 /* allocate memory for new device */
8676 size
= sizeof_imsm_dev(super
->devlist
->dev
, 0) +
8677 (num_members
* sizeof(__u32
));
8678 space
= xmalloc(size
);
8682 len
= disks_to_mpb_size(num_members
* 2);
8687 case update_reshape_container_disks
: {
8688 /* Every raid device in the container is about to
8689 * gain some more devices, and we will enter a
8691 * So each 'imsm_map' will be bigger, and the imsm_vol
8692 * will now hold 2 of them.
8693 * Thus we need new 'struct imsm_dev' allocations sized
8694 * as sizeof_imsm_dev but with more devices in both maps.
8696 struct imsm_update_reshape
*u
= (void *)update
->buf
;
8697 struct intel_dev
*dl
;
8698 void **space_tail
= (void**)&update
->space_list
;
8700 if (update
->len
< (int)sizeof(*u
))
8703 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
8705 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
8706 int size
= sizeof_imsm_dev(dl
->dev
, 1);
8708 if (u
->new_raid_disks
> u
->old_raid_disks
)
8709 size
+= sizeof(__u32
)*2*
8710 (u
->new_raid_disks
- u
->old_raid_disks
);
8717 len
= disks_to_mpb_size(u
->new_raid_disks
);
8718 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
8721 case update_reshape_migration
: {
8722 /* for migration level 0->5 we need to add disks
8723 * so the same as for container operation we will copy
8724 * device to the bigger location.
8725 * in memory prepared device and new disk area are prepared
8726 * for usage in process update
8728 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
8729 struct intel_dev
*id
;
8730 void **space_tail
= (void **)&update
->space_list
;
8733 int current_level
= -1;
8735 if (update
->len
< (int)sizeof(*u
))
8738 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
8740 /* add space for bigger array in update
8742 for (id
= super
->devlist
; id
; id
= id
->next
) {
8743 if (id
->index
== (unsigned)u
->subdev
) {
8744 size
= sizeof_imsm_dev(id
->dev
, 1);
8745 if (u
->new_raid_disks
> u
->old_raid_disks
)
8746 size
+= sizeof(__u32
)*2*
8747 (u
->new_raid_disks
- u
->old_raid_disks
);
8755 if (update
->space_list
== NULL
)
8758 /* add space for disk in update
8760 size
= sizeof(struct dl
);
8766 /* add spare device to update
8768 for (id
= super
->devlist
; id
; id
= id
->next
)
8769 if (id
->index
== (unsigned)u
->subdev
) {
8770 struct imsm_dev
*dev
;
8771 struct imsm_map
*map
;
8773 dev
= get_imsm_dev(super
, u
->subdev
);
8774 map
= get_imsm_map(dev
, MAP_0
);
8775 current_level
= map
->raid_level
;
8778 if ((u
->new_level
== 5) && (u
->new_level
!= current_level
)) {
8779 struct mdinfo
*spares
;
8781 spares
= get_spares_for_grow(st
);
8789 makedev(dev
->disk
.major
,
8791 dl
= get_disk_super(super
,
8794 dl
->index
= u
->old_raid_disks
;
8800 len
= disks_to_mpb_size(u
->new_raid_disks
);
8801 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
8804 case update_size_change
: {
8805 if (update
->len
< (int)sizeof(struct imsm_update_size_change
))
8809 case update_activate_spare
: {
8810 if (update
->len
< (int)sizeof(struct imsm_update_activate_spare
))
8814 case update_create_array
: {
8815 struct imsm_update_create_array
*u
= (void *) update
->buf
;
8816 struct intel_dev
*dv
;
8817 struct imsm_dev
*dev
= &u
->dev
;
8818 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8820 struct disk_info
*inf
;
8824 if (update
->len
< (int)sizeof(*u
))
8827 inf
= get_disk_info(u
);
8828 len
= sizeof_imsm_dev(dev
, 1);
8829 /* allocate a new super->devlist entry */
8830 dv
= xmalloc(sizeof(*dv
));
8831 dv
->dev
= xmalloc(len
);
8834 /* count how many spares will be converted to members */
8835 for (i
= 0; i
< map
->num_members
; i
++) {
8836 dl
= serial_to_dl(inf
[i
].serial
, super
);
8838 /* hmm maybe it failed?, nothing we can do about
8843 if (count_memberships(dl
, super
) == 0)
8846 len
+= activate
* sizeof(struct imsm_disk
);
8849 case update_kill_array
: {
8850 if (update
->len
< (int)sizeof(struct imsm_update_kill_array
))
8854 case update_rename_array
: {
8855 if (update
->len
< (int)sizeof(struct imsm_update_rename_array
))
8859 case update_add_remove_disk
:
8860 /* no update->len needed */
8866 /* check if we need a larger metadata buffer */
8867 if (super
->next_buf
)
8868 buf_len
= super
->next_len
;
8870 buf_len
= super
->len
;
8872 if (__le32_to_cpu(mpb
->mpb_size
) + len
> buf_len
) {
8873 /* ok we need a larger buf than what is currently allocated
8874 * if this allocation fails process_update will notice that
8875 * ->next_len is set and ->next_buf is NULL
8877 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + len
, 512);
8878 if (super
->next_buf
)
8879 free(super
->next_buf
);
8881 super
->next_len
= buf_len
;
8882 if (posix_memalign(&super
->next_buf
, 512, buf_len
) == 0)
8883 memset(super
->next_buf
, 0, buf_len
);
8885 super
->next_buf
= NULL
;
8890 /* must be called while manager is quiesced */
8891 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
8893 struct imsm_super
*mpb
= super
->anchor
;
8895 struct imsm_dev
*dev
;
8896 struct imsm_map
*map
;
8897 int i
, j
, num_members
;
8900 dprintf("%s: deleting device[%d] from imsm_super\n",
8903 /* shift all indexes down one */
8904 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
8905 if (iter
->index
> (int)index
)
8907 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
8908 if (iter
->index
> (int)index
)
8911 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8912 dev
= get_imsm_dev(super
, i
);
8913 map
= get_imsm_map(dev
, MAP_0
);
8914 num_members
= map
->num_members
;
8915 for (j
= 0; j
< num_members
; j
++) {
8916 /* update ord entries being careful not to propagate
8917 * ord-flags to the first map
8919 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_X
);
8921 if (ord_to_idx(ord
) <= index
)
8924 map
= get_imsm_map(dev
, MAP_0
);
8925 set_imsm_ord_tbl_ent(map
, j
, ord_to_idx(ord
- 1));
8926 map
= get_imsm_map(dev
, MAP_1
);
8928 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
8933 super
->updates_pending
++;
8935 struct dl
*dl
= *dlp
;
8937 *dlp
= (*dlp
)->next
;
8938 __free_imsm_disk(dl
);
8941 #endif /* MDASSEMBLE */
8943 static void close_targets(int *targets
, int new_disks
)
8950 for (i
= 0; i
< new_disks
; i
++) {
8951 if (targets
[i
] >= 0) {
8958 static int imsm_get_allowed_degradation(int level
, int raid_disks
,
8959 struct intel_super
*super
,
8960 struct imsm_dev
*dev
)
8966 struct imsm_map
*map
;
8969 ret_val
= raid_disks
/2;
8970 /* check map if all disks pairs not failed
8973 map
= get_imsm_map(dev
, MAP_0
);
8974 for (i
= 0; i
< ret_val
; i
++) {
8975 int degradation
= 0;
8976 if (get_imsm_disk(super
, i
) == NULL
)
8978 if (get_imsm_disk(super
, i
+ 1) == NULL
)
8980 if (degradation
== 2)
8983 map
= get_imsm_map(dev
, MAP_1
);
8984 /* if there is no second map
8985 * result can be returned
8989 /* check degradation in second map
8991 for (i
= 0; i
< ret_val
; i
++) {
8992 int degradation
= 0;
8993 if (get_imsm_disk(super
, i
) == NULL
)
8995 if (get_imsm_disk(super
, i
+ 1) == NULL
)
8997 if (degradation
== 2)
9011 /*******************************************************************************
9012 * Function: open_backup_targets
9013 * Description: Function opens file descriptors for all devices given in
9016 * info : general array info
9017 * raid_disks : number of disks
9018 * raid_fds : table of device's file descriptors
9019 * super : intel super for raid10 degradation check
9020 * dev : intel device for raid10 degradation check
9024 ******************************************************************************/
9025 int open_backup_targets(struct mdinfo
*info
, int raid_disks
, int *raid_fds
,
9026 struct intel_super
*super
, struct imsm_dev
*dev
)
9032 for (i
= 0; i
< raid_disks
; i
++)
9035 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
9038 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
)) {
9039 dprintf("disk is faulty!!\n");
9043 if ((sd
->disk
.raid_disk
>= raid_disks
) ||
9044 (sd
->disk
.raid_disk
< 0))
9047 dn
= map_dev(sd
->disk
.major
,
9049 raid_fds
[sd
->disk
.raid_disk
] = dev_open(dn
, O_RDWR
);
9050 if (raid_fds
[sd
->disk
.raid_disk
] < 0) {
9051 pr_err("cannot open component\n");
9056 /* check if maximum array degradation level is not exceeded
9058 if ((raid_disks
- opened
) >
9059 imsm_get_allowed_degradation(info
->new_level
,
9062 pr_err("Not enough disks can be opened.\n");
9063 close_targets(raid_fds
, raid_disks
);
9069 /*******************************************************************************
9070 * Function: validate_container_imsm
9071 * Description: This routine validates container after assemble,
9072 * eg. if devices in container are under the same controller.
9075 * info : linked list with info about devices used in array
9079 ******************************************************************************/
9080 int validate_container_imsm(struct mdinfo
*info
)
9082 if (check_env("IMSM_NO_PLATFORM"))
9085 struct sys_dev
*idev
;
9086 struct sys_dev
*hba
= NULL
;
9087 struct sys_dev
*intel_devices
= find_intel_devices();
9088 char *dev_path
= devt_to_devpath(makedev(info
->disk
.major
,
9091 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
9092 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
9101 pr_err("WARNING - Cannot detect HBA for device %s!\n",
9102 devid2kname(makedev(info
->disk
.major
, info
->disk
.minor
)));
9106 const struct imsm_orom
*orom
= get_orom_by_device_id(hba
->dev_id
);
9109 for (dev
= info
->next
; dev
; dev
= dev
->next
) {
9110 dev_path
= devt_to_devpath(makedev(dev
->disk
.major
, dev
->disk
.minor
));
9112 struct sys_dev
*hba2
= NULL
;
9113 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
9114 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
9122 const struct imsm_orom
*orom2
= hba2
== NULL
? NULL
:
9123 get_orom_by_device_id(hba2
->dev_id
);
9125 if (hba2
&& hba
->type
!= hba2
->type
) {
9126 pr_err("WARNING - HBAs of devices do not match %s != %s\n",
9127 get_sys_dev_type(hba
->type
), get_sys_dev_type(hba2
->type
));
9131 if (orom
!= orom2
) {
9132 pr_err("WARNING - IMSM container assembled with disks under different HBAs!\n"
9133 " This operation is not supported and can lead to data loss.\n");
9138 pr_err("WARNING - IMSM container assembled with disks under HBAs without IMSM platform support!\n"
9139 " This operation is not supported and can lead to data loss.\n");
9147 /*******************************************************************************
9148 * Function: init_migr_record_imsm
9149 * Description: Function inits imsm migration record
9151 * super : imsm internal array info
9152 * dev : device under migration
9153 * info : general array info to find the smallest device
9156 ******************************************************************************/
9157 void init_migr_record_imsm(struct supertype
*st
, struct imsm_dev
*dev
,
9158 struct mdinfo
*info
)
9160 struct intel_super
*super
= st
->sb
;
9161 struct migr_record
*migr_rec
= super
->migr_rec
;
9163 unsigned long long dsize
, dev_sectors
;
9164 long long unsigned min_dev_sectors
= -1LLU;
9168 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
9169 struct imsm_map
*map_src
= get_imsm_map(dev
, MAP_1
);
9170 unsigned long long num_migr_units
;
9171 unsigned long long array_blocks
;
9173 memset(migr_rec
, 0, sizeof(struct migr_record
));
9174 migr_rec
->family_num
= __cpu_to_le32(super
->anchor
->family_num
);
9176 /* only ascending reshape supported now */
9177 migr_rec
->ascending_migr
= __cpu_to_le32(1);
9179 migr_rec
->dest_depth_per_unit
= GEN_MIGR_AREA_SIZE
/
9180 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
9181 migr_rec
->dest_depth_per_unit
*=
9182 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
9183 new_data_disks
= imsm_num_data_members(dev
, MAP_0
);
9184 migr_rec
->blocks_per_unit
=
9185 __cpu_to_le32(migr_rec
->dest_depth_per_unit
* new_data_disks
);
9186 migr_rec
->dest_depth_per_unit
=
9187 __cpu_to_le32(migr_rec
->dest_depth_per_unit
);
9188 array_blocks
= info
->component_size
* new_data_disks
;
9190 array_blocks
/ __le32_to_cpu(migr_rec
->blocks_per_unit
);
9192 if (array_blocks
% __le32_to_cpu(migr_rec
->blocks_per_unit
))
9194 migr_rec
->num_migr_units
= __cpu_to_le32(num_migr_units
);
9196 migr_rec
->post_migr_vol_cap
= dev
->size_low
;
9197 migr_rec
->post_migr_vol_cap_hi
= dev
->size_high
;
9199 /* Find the smallest dev */
9200 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
9201 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
9202 fd
= dev_open(nm
, O_RDONLY
);
9205 get_dev_size(fd
, NULL
, &dsize
);
9206 dev_sectors
= dsize
/ 512;
9207 if (dev_sectors
< min_dev_sectors
)
9208 min_dev_sectors
= dev_sectors
;
9211 migr_rec
->ckpt_area_pba
= __cpu_to_le32(min_dev_sectors
-
9212 RAID_DISK_RESERVED_BLOCKS_IMSM_HI
);
9214 write_imsm_migr_rec(st
);
9219 /*******************************************************************************
9220 * Function: save_backup_imsm
9221 * Description: Function saves critical data stripes to Migration Copy Area
9222 * and updates the current migration unit status.
9223 * Use restore_stripes() to form a destination stripe,
9224 * and to write it to the Copy Area.
9226 * st : supertype information
9227 * dev : imsm device that backup is saved for
9228 * info : general array info
9229 * buf : input buffer
9230 * length : length of data to backup (blocks_per_unit)
9234 ******************************************************************************/
9235 int save_backup_imsm(struct supertype
*st
,
9236 struct imsm_dev
*dev
,
9237 struct mdinfo
*info
,
9242 struct intel_super
*super
= st
->sb
;
9243 unsigned long long *target_offsets
= NULL
;
9244 int *targets
= NULL
;
9246 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
9247 int new_disks
= map_dest
->num_members
;
9248 int dest_layout
= 0;
9250 unsigned long long start
;
9251 int data_disks
= imsm_num_data_members(dev
, MAP_0
);
9253 targets
= xmalloc(new_disks
* sizeof(int));
9255 for (i
= 0; i
< new_disks
; i
++)
9258 target_offsets
= xcalloc(new_disks
, sizeof(unsigned long long));
9260 start
= info
->reshape_progress
* 512;
9261 for (i
= 0; i
< new_disks
; i
++) {
9262 target_offsets
[i
] = (unsigned long long)
9263 __le32_to_cpu(super
->migr_rec
->ckpt_area_pba
) * 512;
9264 /* move back copy area adderss, it will be moved forward
9265 * in restore_stripes() using start input variable
9267 target_offsets
[i
] -= start
/data_disks
;
9270 if (open_backup_targets(info
, new_disks
, targets
,
9274 dest_layout
= imsm_level_to_layout(map_dest
->raid_level
);
9275 dest_chunk
= __le16_to_cpu(map_dest
->blocks_per_strip
) * 512;
9277 if (restore_stripes(targets
, /* list of dest devices */
9278 target_offsets
, /* migration record offsets */
9281 map_dest
->raid_level
,
9283 -1, /* source backup file descriptor */
9284 0, /* input buf offset
9285 * always 0 buf is already offseted */
9289 pr_err("Error restoring stripes\n");
9297 close_targets(targets
, new_disks
);
9300 free(target_offsets
);
9305 /*******************************************************************************
9306 * Function: save_checkpoint_imsm
9307 * Description: Function called for current unit status update
9308 * in the migration record. It writes it to disk.
9310 * super : imsm internal array info
9311 * info : general array info
9315 * 2: failure, means no valid migration record
9316 * / no general migration in progress /
9317 ******************************************************************************/
9318 int save_checkpoint_imsm(struct supertype
*st
, struct mdinfo
*info
, int state
)
9320 struct intel_super
*super
= st
->sb
;
9321 unsigned long long blocks_per_unit
;
9322 unsigned long long curr_migr_unit
;
9324 if (load_imsm_migr_rec(super
, info
) != 0) {
9325 dprintf("imsm: ERROR: Cannot read migration record "
9326 "for checkpoint save.\n");
9330 blocks_per_unit
= __le32_to_cpu(super
->migr_rec
->blocks_per_unit
);
9331 if (blocks_per_unit
== 0) {
9332 dprintf("imsm: no migration in progress.\n");
9335 curr_migr_unit
= info
->reshape_progress
/ blocks_per_unit
;
9336 /* check if array is alligned to copy area
9337 * if it is not alligned, add one to current migration unit value
9338 * this can happend on array reshape finish only
9340 if (info
->reshape_progress
% blocks_per_unit
)
9343 super
->migr_rec
->curr_migr_unit
=
9344 __cpu_to_le32(curr_migr_unit
);
9345 super
->migr_rec
->rec_status
= __cpu_to_le32(state
);
9346 super
->migr_rec
->dest_1st_member_lba
=
9347 __cpu_to_le32(curr_migr_unit
*
9348 __le32_to_cpu(super
->migr_rec
->dest_depth_per_unit
));
9349 if (write_imsm_migr_rec(st
) < 0) {
9350 dprintf("imsm: Cannot write migration record "
9351 "outside backup area\n");
9358 /*******************************************************************************
9359 * Function: recover_backup_imsm
9360 * Description: Function recovers critical data from the Migration Copy Area
9361 * while assembling an array.
9363 * super : imsm internal array info
9364 * info : general array info
9366 * 0 : success (or there is no data to recover)
9368 ******************************************************************************/
9369 int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
)
9371 struct intel_super
*super
= st
->sb
;
9372 struct migr_record
*migr_rec
= super
->migr_rec
;
9373 struct imsm_map
*map_dest
= NULL
;
9374 struct intel_dev
*id
= NULL
;
9375 unsigned long long read_offset
;
9376 unsigned long long write_offset
;
9378 int *targets
= NULL
;
9379 int new_disks
, i
, err
;
9382 unsigned long curr_migr_unit
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
9383 unsigned long num_migr_units
= __le32_to_cpu(migr_rec
->num_migr_units
);
9385 int skipped_disks
= 0;
9387 err
= sysfs_get_str(info
, NULL
, "array_state", (char *)buffer
, 20);
9391 /* recover data only during assemblation */
9392 if (strncmp(buffer
, "inactive", 8) != 0)
9394 /* no data to recover */
9395 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
9397 if (curr_migr_unit
>= num_migr_units
)
9400 /* find device during reshape */
9401 for (id
= super
->devlist
; id
; id
= id
->next
)
9402 if (is_gen_migration(id
->dev
))
9407 map_dest
= get_imsm_map(id
->dev
, MAP_0
);
9408 new_disks
= map_dest
->num_members
;
9410 read_offset
= (unsigned long long)
9411 __le32_to_cpu(migr_rec
->ckpt_area_pba
) * 512;
9413 write_offset
= ((unsigned long long)
9414 __le32_to_cpu(migr_rec
->dest_1st_member_lba
) +
9415 pba_of_lba0(map_dest
)) * 512;
9417 unit_len
= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
9418 if (posix_memalign((void **)&buf
, 512, unit_len
) != 0)
9420 targets
= xcalloc(new_disks
, sizeof(int));
9422 if (open_backup_targets(info
, new_disks
, targets
, super
, id
->dev
)) {
9423 pr_err("Cannot open some devices belonging to array.\n");
9427 for (i
= 0; i
< new_disks
; i
++) {
9428 if (targets
[i
] < 0) {
9432 if (lseek64(targets
[i
], read_offset
, SEEK_SET
) < 0) {
9433 pr_err("Cannot seek to block: %s\n",
9438 if ((unsigned)read(targets
[i
], buf
, unit_len
) != unit_len
) {
9439 pr_err("Cannot read copy area block: %s\n",
9444 if (lseek64(targets
[i
], write_offset
, SEEK_SET
) < 0) {
9445 pr_err("Cannot seek to block: %s\n",
9450 if ((unsigned)write(targets
[i
], buf
, unit_len
) != unit_len
) {
9451 pr_err("Cannot restore block: %s\n",
9458 if (skipped_disks
> imsm_get_allowed_degradation(info
->new_level
,
9462 pr_err("Cannot restore data from backup."
9463 " Too many failed disks\n");
9467 if (save_checkpoint_imsm(st
, info
, UNIT_SRC_NORMAL
)) {
9468 /* ignore error == 2, this can mean end of reshape here
9470 dprintf("imsm: Cannot write checkpoint to "
9471 "migration record (UNIT_SRC_NORMAL) during restart\n");
9477 for (i
= 0; i
< new_disks
; i
++)
9486 static char disk_by_path
[] = "/dev/disk/by-path/";
9488 static const char *imsm_get_disk_controller_domain(const char *path
)
9490 char disk_path
[PATH_MAX
];
9494 strcpy(disk_path
, disk_by_path
);
9495 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
9496 if (stat(disk_path
, &st
) == 0) {
9497 struct sys_dev
* hba
;
9500 path
= devt_to_devpath(st
.st_rdev
);
9503 hba
= find_disk_attached_hba(-1, path
);
9504 if (hba
&& hba
->type
== SYS_DEV_SAS
)
9506 else if (hba
&& hba
->type
== SYS_DEV_SATA
)
9510 dprintf("path: %s hba: %s attached: %s\n",
9511 path
, (hba
) ? hba
->path
: "NULL", drv
);
9517 static char *imsm_find_array_devnm_by_subdev(int subdev
, char *container
)
9519 static char devnm
[32];
9520 char subdev_name
[20];
9521 struct mdstat_ent
*mdstat
;
9523 sprintf(subdev_name
, "%d", subdev
);
9524 mdstat
= mdstat_by_subdev(subdev_name
, container
);
9528 strcpy(devnm
, mdstat
->devnm
);
9529 free_mdstat(mdstat
);
9533 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
9534 struct geo_params
*geo
,
9535 int *old_raid_disks
,
9538 /* currently we only support increasing the number of devices
9539 * for a container. This increases the number of device for each
9540 * member array. They must all be RAID0 or RAID5.
9543 struct mdinfo
*info
, *member
;
9544 int devices_that_can_grow
= 0;
9546 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): "
9547 "st->devnm = (%s)\n", st
->devnm
);
9549 if (geo
->size
> 0 ||
9550 geo
->level
!= UnSet
||
9551 geo
->layout
!= UnSet
||
9552 geo
->chunksize
!= 0 ||
9553 geo
->raid_disks
== UnSet
) {
9554 dprintf("imsm: Container operation is allowed for "
9555 "raid disks number change only.\n");
9559 if (direction
== ROLLBACK_METADATA_CHANGES
) {
9560 dprintf("imsm: Metadata changes rollback is not supported for "
9561 "container operation.\n");
9565 info
= container_content_imsm(st
, NULL
);
9566 for (member
= info
; member
; member
= member
->next
) {
9569 dprintf("imsm: checking device_num: %i\n",
9570 member
->container_member
);
9572 if (geo
->raid_disks
<= member
->array
.raid_disks
) {
9573 /* we work on container for Online Capacity Expansion
9574 * only so raid_disks has to grow
9576 dprintf("imsm: for container operation raid disks "
9577 "increase is required\n");
9581 if ((info
->array
.level
!= 0) &&
9582 (info
->array
.level
!= 5)) {
9583 /* we cannot use this container with other raid level
9585 dprintf("imsm: for container operation wrong"
9586 " raid level (%i) detected\n",
9590 /* check for platform support
9591 * for this raid level configuration
9593 struct intel_super
*super
= st
->sb
;
9594 if (!is_raid_level_supported(super
->orom
,
9595 member
->array
.level
,
9597 dprintf("platform does not support raid%d with"
9601 geo
->raid_disks
> 1 ? "s" : "");
9604 /* check if component size is aligned to chunk size
9606 if (info
->component_size
%
9607 (info
->array
.chunk_size
/512)) {
9608 dprintf("Component size is not aligned to "
9614 if (*old_raid_disks
&&
9615 info
->array
.raid_disks
!= *old_raid_disks
)
9617 *old_raid_disks
= info
->array
.raid_disks
;
9619 /* All raid5 and raid0 volumes in container
9620 * have to be ready for Online Capacity Expansion
9621 * so they need to be assembled. We have already
9622 * checked that no recovery etc is happening.
9624 result
= imsm_find_array_devnm_by_subdev(member
->container_member
,
9625 st
->container_devnm
);
9626 if (result
== NULL
) {
9627 dprintf("imsm: cannot find array\n");
9630 devices_that_can_grow
++;
9633 if (!member
&& devices_that_can_grow
)
9637 dprintf("\tContainer operation allowed\n");
9639 dprintf("\tError: %i\n", ret_val
);
9644 /* Function: get_spares_for_grow
9645 * Description: Allocates memory and creates list of spare devices
9646 * avaliable in container. Checks if spare drive size is acceptable.
9647 * Parameters: Pointer to the supertype structure
9648 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
9651 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
9653 unsigned long long min_size
= min_acceptable_spare_size_imsm(st
);
9654 return container_choose_spares(st
, min_size
, NULL
, NULL
, NULL
, 0);
9657 /******************************************************************************
9658 * function: imsm_create_metadata_update_for_reshape
9659 * Function creates update for whole IMSM container.
9661 ******************************************************************************/
9662 static int imsm_create_metadata_update_for_reshape(
9663 struct supertype
*st
,
9664 struct geo_params
*geo
,
9666 struct imsm_update_reshape
**updatep
)
9668 struct intel_super
*super
= st
->sb
;
9669 struct imsm_super
*mpb
= super
->anchor
;
9670 int update_memory_size
= 0;
9671 struct imsm_update_reshape
*u
= NULL
;
9672 struct mdinfo
*spares
= NULL
;
9674 int delta_disks
= 0;
9677 dprintf("imsm_update_metadata_for_reshape(enter) raid_disks = %i\n",
9680 delta_disks
= geo
->raid_disks
- old_raid_disks
;
9682 /* size of all update data without anchor */
9683 update_memory_size
= sizeof(struct imsm_update_reshape
);
9685 /* now add space for spare disks that we need to add. */
9686 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
9688 u
= xcalloc(1, update_memory_size
);
9689 u
->type
= update_reshape_container_disks
;
9690 u
->old_raid_disks
= old_raid_disks
;
9691 u
->new_raid_disks
= geo
->raid_disks
;
9693 /* now get spare disks list
9695 spares
= get_spares_for_grow(st
);
9698 || delta_disks
> spares
->array
.spare_disks
) {
9699 pr_err("imsm: ERROR: Cannot get spare devices "
9700 "for %s.\n", geo
->dev_name
);
9705 /* we have got spares
9706 * update disk list in imsm_disk list table in anchor
9708 dprintf("imsm: %i spares are available.\n\n",
9709 spares
->array
.spare_disks
);
9712 for (i
= 0; i
< delta_disks
; i
++) {
9717 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
9719 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
9720 dl
->index
= mpb
->num_disks
;
9730 dprintf("imsm: reshape update preparation :");
9731 if (i
== delta_disks
) {
9734 return update_memory_size
;
9737 dprintf(" Error\n");
9742 /******************************************************************************
9743 * function: imsm_create_metadata_update_for_size_change()
9744 * Creates update for IMSM array for array size change.
9746 ******************************************************************************/
9747 static int imsm_create_metadata_update_for_size_change(
9748 struct supertype
*st
,
9749 struct geo_params
*geo
,
9750 struct imsm_update_size_change
**updatep
)
9752 struct intel_super
*super
= st
->sb
;
9753 int update_memory_size
= 0;
9754 struct imsm_update_size_change
*u
= NULL
;
9756 dprintf("imsm_create_metadata_update_for_size_change(enter)"
9757 " New size = %llu\n", geo
->size
);
9759 /* size of all update data without anchor */
9760 update_memory_size
= sizeof(struct imsm_update_size_change
);
9762 u
= xcalloc(1, update_memory_size
);
9763 u
->type
= update_size_change
;
9764 u
->subdev
= super
->current_vol
;
9765 u
->new_size
= geo
->size
;
9767 dprintf("imsm: reshape update preparation : OK\n");
9770 return update_memory_size
;
9773 /******************************************************************************
9774 * function: imsm_create_metadata_update_for_migration()
9775 * Creates update for IMSM array.
9777 ******************************************************************************/
9778 static int imsm_create_metadata_update_for_migration(
9779 struct supertype
*st
,
9780 struct geo_params
*geo
,
9781 struct imsm_update_reshape_migration
**updatep
)
9783 struct intel_super
*super
= st
->sb
;
9784 int update_memory_size
= 0;
9785 struct imsm_update_reshape_migration
*u
= NULL
;
9786 struct imsm_dev
*dev
;
9787 int previous_level
= -1;
9789 dprintf("imsm_create_metadata_update_for_migration(enter)"
9790 " New Level = %i\n", geo
->level
);
9792 /* size of all update data without anchor */
9793 update_memory_size
= sizeof(struct imsm_update_reshape_migration
);
9795 u
= xcalloc(1, update_memory_size
);
9796 u
->type
= update_reshape_migration
;
9797 u
->subdev
= super
->current_vol
;
9798 u
->new_level
= geo
->level
;
9799 u
->new_layout
= geo
->layout
;
9800 u
->new_raid_disks
= u
->old_raid_disks
= geo
->raid_disks
;
9801 u
->new_disks
[0] = -1;
9802 u
->new_chunksize
= -1;
9804 dev
= get_imsm_dev(super
, u
->subdev
);
9806 struct imsm_map
*map
;
9808 map
= get_imsm_map(dev
, MAP_0
);
9810 int current_chunk_size
=
9811 __le16_to_cpu(map
->blocks_per_strip
) / 2;
9813 if (geo
->chunksize
!= current_chunk_size
) {
9814 u
->new_chunksize
= geo
->chunksize
/ 1024;
9816 "chunk size change from %i to %i\n",
9817 current_chunk_size
, u
->new_chunksize
);
9819 previous_level
= map
->raid_level
;
9822 if ((geo
->level
== 5) && (previous_level
== 0)) {
9823 struct mdinfo
*spares
= NULL
;
9825 u
->new_raid_disks
++;
9826 spares
= get_spares_for_grow(st
);
9827 if ((spares
== NULL
) || (spares
->array
.spare_disks
< 1)) {
9830 update_memory_size
= 0;
9831 dprintf("error: cannot get spare device "
9832 "for requested migration");
9837 dprintf("imsm: reshape update preparation : OK\n");
9840 return update_memory_size
;
9843 static void imsm_update_metadata_locally(struct supertype
*st
,
9846 struct metadata_update mu
;
9851 mu
.space_list
= NULL
;
9853 if (imsm_prepare_update(st
, &mu
))
9854 imsm_process_update(st
, &mu
);
9856 while (mu
.space_list
) {
9857 void **space
= mu
.space_list
;
9858 mu
.space_list
= *space
;
9863 /***************************************************************************
9864 * Function: imsm_analyze_change
9865 * Description: Function analyze change for single volume
9866 * and validate if transition is supported
9867 * Parameters: Geometry parameters, supertype structure,
9868 * metadata change direction (apply/rollback)
9869 * Returns: Operation type code on success, -1 if fail
9870 ****************************************************************************/
9871 enum imsm_reshape_type
imsm_analyze_change(struct supertype
*st
,
9872 struct geo_params
*geo
,
9879 /* number of added/removed disks in operation result */
9880 int devNumChange
= 0;
9881 /* imsm compatible layout value for array geometry verification */
9882 int imsm_layout
= -1;
9884 struct imsm_dev
*dev
;
9885 struct intel_super
*super
;
9886 unsigned long long current_size
;
9887 unsigned long long free_size
;
9888 unsigned long long max_size
;
9891 getinfo_super_imsm_volume(st
, &info
, NULL
);
9892 if ((geo
->level
!= info
.array
.level
) &&
9893 (geo
->level
>= 0) &&
9894 (geo
->level
!= UnSet
)) {
9895 switch (info
.array
.level
) {
9897 if (geo
->level
== 5) {
9898 change
= CH_MIGRATION
;
9899 if (geo
->layout
!= ALGORITHM_LEFT_ASYMMETRIC
) {
9900 pr_err("Error. Requested Layout "
9901 "not supported (left-asymmetric layout "
9902 "is supported only)!\n");
9904 goto analyse_change_exit
;
9906 imsm_layout
= geo
->layout
;
9908 devNumChange
= 1; /* parity disk added */
9909 } else if (geo
->level
== 10) {
9910 change
= CH_TAKEOVER
;
9912 devNumChange
= 2; /* two mirrors added */
9913 imsm_layout
= 0x102; /* imsm supported layout */
9918 if (geo
->level
== 0) {
9919 change
= CH_TAKEOVER
;
9921 devNumChange
= -(geo
->raid_disks
/2);
9922 imsm_layout
= 0; /* imsm raid0 layout */
9927 pr_err("Error. Level Migration from %d to %d "
9929 info
.array
.level
, geo
->level
);
9930 goto analyse_change_exit
;
9933 geo
->level
= info
.array
.level
;
9935 if ((geo
->layout
!= info
.array
.layout
)
9936 && ((geo
->layout
!= UnSet
) && (geo
->layout
!= -1))) {
9937 change
= CH_MIGRATION
;
9938 if ((info
.array
.layout
== 0)
9939 && (info
.array
.level
== 5)
9940 && (geo
->layout
== 5)) {
9941 /* reshape 5 -> 4 */
9942 } else if ((info
.array
.layout
== 5)
9943 && (info
.array
.level
== 5)
9944 && (geo
->layout
== 0)) {
9945 /* reshape 4 -> 5 */
9949 pr_err("Error. Layout Migration from %d to %d "
9951 info
.array
.layout
, geo
->layout
);
9953 goto analyse_change_exit
;
9956 geo
->layout
= info
.array
.layout
;
9957 if (imsm_layout
== -1)
9958 imsm_layout
= info
.array
.layout
;
9961 if ((geo
->chunksize
> 0) && (geo
->chunksize
!= UnSet
)
9962 && (geo
->chunksize
!= info
.array
.chunk_size
))
9963 change
= CH_MIGRATION
;
9965 geo
->chunksize
= info
.array
.chunk_size
;
9967 chunk
= geo
->chunksize
/ 1024;
9970 dev
= get_imsm_dev(super
, super
->current_vol
);
9971 data_disks
= imsm_num_data_members(dev
, MAP_0
);
9972 /* compute current size per disk member
9974 current_size
= info
.custom_array_size
/ data_disks
;
9976 if ((geo
->size
> 0) && (geo
->size
!= MAX_SIZE
)) {
9977 /* align component size
9979 geo
->size
= imsm_component_size_aligment_check(
9980 get_imsm_raid_level(dev
->vol
.map
),
9983 if (geo
->size
== 0) {
9984 pr_err("Error. Size expansion is " \
9985 "supported only (current size is %llu, " \
9986 "requested size /rounded/ is 0).\n",
9988 goto analyse_change_exit
;
9992 if ((current_size
!= geo
->size
) && (geo
->size
> 0)) {
9994 pr_err("Error. Size change should be the only "
9995 "one at a time.\n");
9997 goto analyse_change_exit
;
9999 if ((super
->current_vol
+ 1) != super
->anchor
->num_raid_devs
) {
10000 pr_err("Error. The last volume in container "
10001 "can be expanded only (%i/%s).\n",
10002 super
->current_vol
, st
->devnm
);
10003 goto analyse_change_exit
;
10005 /* check the maximum available size
10007 rv
= imsm_get_free_size(st
, dev
->vol
.map
->num_members
,
10008 0, chunk
, &free_size
);
10010 /* Cannot find maximum available space
10014 max_size
= free_size
+ current_size
;
10015 /* align component size
10017 max_size
= imsm_component_size_aligment_check(
10018 get_imsm_raid_level(dev
->vol
.map
),
10022 if (geo
->size
== MAX_SIZE
) {
10023 /* requested size change to the maximum available size
10025 if (max_size
== 0) {
10026 pr_err("Error. Cannot find "
10027 "maximum available space.\n");
10029 goto analyse_change_exit
;
10031 geo
->size
= max_size
;
10034 if ((direction
== ROLLBACK_METADATA_CHANGES
)) {
10035 /* accept size for rollback only
10038 /* round size due to metadata compatibility
10040 geo
->size
= (geo
->size
>> SECT_PER_MB_SHIFT
)
10041 << SECT_PER_MB_SHIFT
;
10042 dprintf("Prepare update for size change to %llu\n",
10044 if (current_size
>= geo
->size
) {
10045 pr_err("Error. Size expansion is "
10046 "supported only (current size is %llu, "
10047 "requested size /rounded/ is %llu).\n",
10048 current_size
, geo
->size
);
10049 goto analyse_change_exit
;
10051 if (max_size
&& geo
->size
> max_size
) {
10052 pr_err("Error. Requested size is larger "
10053 "than maximum available size (maximum "
10054 "available size is %llu, "
10055 "requested size /rounded/ is %llu).\n",
10056 max_size
, geo
->size
);
10057 goto analyse_change_exit
;
10060 geo
->size
*= data_disks
;
10061 geo
->raid_disks
= dev
->vol
.map
->num_members
;
10062 change
= CH_ARRAY_SIZE
;
10064 if (!validate_geometry_imsm(st
,
10067 geo
->raid_disks
+ devNumChange
,
10069 geo
->size
, INVALID_SECTORS
,
10074 struct intel_super
*super
= st
->sb
;
10075 struct imsm_super
*mpb
= super
->anchor
;
10077 if (mpb
->num_raid_devs
> 1) {
10078 pr_err("Error. Cannot perform operation on %s"
10079 "- for this operation it MUST be single "
10080 "array in container\n",
10086 analyse_change_exit
:
10087 if ((direction
== ROLLBACK_METADATA_CHANGES
) &&
10088 ((change
== CH_MIGRATION
) || (change
== CH_TAKEOVER
))) {
10089 dprintf("imsm: Metadata changes rollback is not supported for "
10090 "migration and takeover operations.\n");
10096 int imsm_takeover(struct supertype
*st
, struct geo_params
*geo
)
10098 struct intel_super
*super
= st
->sb
;
10099 struct imsm_update_takeover
*u
;
10101 u
= xmalloc(sizeof(struct imsm_update_takeover
));
10103 u
->type
= update_takeover
;
10104 u
->subarray
= super
->current_vol
;
10106 /* 10->0 transition */
10107 if (geo
->level
== 0)
10108 u
->direction
= R10_TO_R0
;
10110 /* 0->10 transition */
10111 if (geo
->level
== 10)
10112 u
->direction
= R0_TO_R10
;
10114 /* update metadata locally */
10115 imsm_update_metadata_locally(st
, u
,
10116 sizeof(struct imsm_update_takeover
));
10117 /* and possibly remotely */
10118 if (st
->update_tail
)
10119 append_metadata_update(st
, u
,
10120 sizeof(struct imsm_update_takeover
));
10127 static int imsm_reshape_super(struct supertype
*st
, unsigned long long size
,
10129 int layout
, int chunksize
, int raid_disks
,
10130 int delta_disks
, char *backup
, char *dev
,
10131 int direction
, int verbose
)
10134 struct geo_params geo
;
10136 dprintf("imsm: reshape_super called.\n");
10138 memset(&geo
, 0, sizeof(struct geo_params
));
10140 geo
.dev_name
= dev
;
10141 strcpy(geo
.devnm
, st
->devnm
);
10144 geo
.layout
= layout
;
10145 geo
.chunksize
= chunksize
;
10146 geo
.raid_disks
= raid_disks
;
10147 if (delta_disks
!= UnSet
)
10148 geo
.raid_disks
+= delta_disks
;
10150 dprintf("\tfor level : %i\n", geo
.level
);
10151 dprintf("\tfor raid_disks : %i\n", geo
.raid_disks
);
10153 if (experimental() == 0)
10156 if (strcmp(st
->container_devnm
, st
->devnm
) == 0) {
10157 /* On container level we can only increase number of devices. */
10158 dprintf("imsm: info: Container operation\n");
10159 int old_raid_disks
= 0;
10161 if (imsm_reshape_is_allowed_on_container(
10162 st
, &geo
, &old_raid_disks
, direction
)) {
10163 struct imsm_update_reshape
*u
= NULL
;
10166 len
= imsm_create_metadata_update_for_reshape(
10167 st
, &geo
, old_raid_disks
, &u
);
10170 dprintf("imsm: Cannot prepare update\n");
10171 goto exit_imsm_reshape_super
;
10175 /* update metadata locally */
10176 imsm_update_metadata_locally(st
, u
, len
);
10177 /* and possibly remotely */
10178 if (st
->update_tail
)
10179 append_metadata_update(st
, u
, len
);
10184 pr_err("(imsm) Operation "
10185 "is not allowed on this container\n");
10188 /* On volume level we support following operations
10189 * - takeover: raid10 -> raid0; raid0 -> raid10
10190 * - chunk size migration
10191 * - migration: raid5 -> raid0; raid0 -> raid5
10193 struct intel_super
*super
= st
->sb
;
10194 struct intel_dev
*dev
= super
->devlist
;
10196 dprintf("imsm: info: Volume operation\n");
10197 /* find requested device */
10200 imsm_find_array_devnm_by_subdev(
10201 dev
->index
, st
->container_devnm
);
10202 if (devnm
&& strcmp(devnm
, geo
.devnm
) == 0)
10207 pr_err("Cannot find %s (%s) subarray\n",
10208 geo
.dev_name
, geo
.devnm
);
10209 goto exit_imsm_reshape_super
;
10211 super
->current_vol
= dev
->index
;
10212 change
= imsm_analyze_change(st
, &geo
, direction
);
10215 ret_val
= imsm_takeover(st
, &geo
);
10217 case CH_MIGRATION
: {
10218 struct imsm_update_reshape_migration
*u
= NULL
;
10220 imsm_create_metadata_update_for_migration(
10224 "Cannot prepare update\n");
10228 /* update metadata locally */
10229 imsm_update_metadata_locally(st
, u
, len
);
10230 /* and possibly remotely */
10231 if (st
->update_tail
)
10232 append_metadata_update(st
, u
, len
);
10237 case CH_ARRAY_SIZE
: {
10238 struct imsm_update_size_change
*u
= NULL
;
10240 imsm_create_metadata_update_for_size_change(
10244 "Cannot prepare update\n");
10248 /* update metadata locally */
10249 imsm_update_metadata_locally(st
, u
, len
);
10250 /* and possibly remotely */
10251 if (st
->update_tail
)
10252 append_metadata_update(st
, u
, len
);
10262 exit_imsm_reshape_super
:
10263 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
10267 /*******************************************************************************
10268 * Function: wait_for_reshape_imsm
10269 * Description: Function writes new sync_max value and waits until
10270 * reshape process reach new position
10272 * sra : general array info
10273 * ndata : number of disks in new array's layout
10276 * 1 : there is no reshape in progress,
10278 ******************************************************************************/
10279 int wait_for_reshape_imsm(struct mdinfo
*sra
, int ndata
)
10281 int fd
= sysfs_get_fd(sra
, NULL
, "sync_completed");
10282 unsigned long long completed
;
10283 /* to_complete : new sync_max position */
10284 unsigned long long to_complete
= sra
->reshape_progress
;
10285 unsigned long long position_to_set
= to_complete
/ ndata
;
10288 dprintf("imsm: wait_for_reshape_imsm() "
10289 "cannot open reshape_position\n");
10293 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
10294 dprintf("imsm: wait_for_reshape_imsm() "
10295 "cannot read reshape_position (no reshape in progres)\n");
10300 if (completed
> position_to_set
) {
10301 dprintf("imsm: wait_for_reshape_imsm() "
10302 "wrong next position to set %llu (%llu)\n",
10303 to_complete
, position_to_set
);
10307 dprintf("Position set: %llu\n", position_to_set
);
10308 if (sysfs_set_num(sra
, NULL
, "sync_max",
10309 position_to_set
) != 0) {
10310 dprintf("imsm: wait_for_reshape_imsm() "
10311 "cannot set reshape position to %llu\n",
10319 sysfs_wait(fd
, NULL
);
10320 if (sysfs_get_str(sra
, NULL
, "sync_action",
10322 strncmp(action
, "reshape", 7) != 0)
10324 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
10325 dprintf("imsm: wait_for_reshape_imsm() "
10326 "cannot read reshape_position (in loop)\n");
10330 } while (completed
< position_to_set
);
10336 /*******************************************************************************
10337 * Function: check_degradation_change
10338 * Description: Check that array hasn't become failed.
10340 * info : for sysfs access
10341 * sources : source disks descriptors
10342 * degraded: previous degradation level
10344 * degradation level
10345 ******************************************************************************/
10346 int check_degradation_change(struct mdinfo
*info
,
10350 unsigned long long new_degraded
;
10353 rv
= sysfs_get_ll(info
, NULL
, "degraded", &new_degraded
);
10354 if ((rv
== -1) || (new_degraded
!= (unsigned long long)degraded
)) {
10355 /* check each device to ensure it is still working */
10358 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
10359 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
10361 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
10363 if (sysfs_get_str(info
,
10364 sd
, "state", sbuf
, 20) < 0 ||
10365 strstr(sbuf
, "faulty") ||
10366 strstr(sbuf
, "in_sync") == NULL
) {
10367 /* this device is dead */
10368 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
10369 if (sd
->disk
.raid_disk
>= 0 &&
10370 sources
[sd
->disk
.raid_disk
] >= 0) {
10372 sd
->disk
.raid_disk
]);
10373 sources
[sd
->disk
.raid_disk
] =
10382 return new_degraded
;
10385 /*******************************************************************************
10386 * Function: imsm_manage_reshape
10387 * Description: Function finds array under reshape and it manages reshape
10388 * process. It creates stripes backups (if required) and sets
10391 * afd : Backup handle (nattive) - not used
10392 * sra : general array info
10393 * reshape : reshape parameters - not used
10394 * st : supertype structure
10395 * blocks : size of critical section [blocks]
10396 * fds : table of source device descriptor
10397 * offsets : start of array (offest per devices)
10399 * destfd : table of destination device descriptor
10400 * destoffsets : table of destination offsets (per device)
10402 * 1 : success, reshape is done
10404 ******************************************************************************/
10405 static int imsm_manage_reshape(
10406 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
10407 struct supertype
*st
, unsigned long backup_blocks
,
10408 int *fds
, unsigned long long *offsets
,
10409 int dests
, int *destfd
, unsigned long long *destoffsets
)
10412 struct intel_super
*super
= st
->sb
;
10413 struct intel_dev
*dv
= NULL
;
10414 struct imsm_dev
*dev
= NULL
;
10415 struct imsm_map
*map_src
;
10416 int migr_vol_qan
= 0;
10417 int ndata
, odata
; /* [bytes] */
10418 int chunk
; /* [bytes] */
10419 struct migr_record
*migr_rec
;
10421 unsigned int buf_size
; /* [bytes] */
10422 unsigned long long max_position
; /* array size [bytes] */
10423 unsigned long long next_step
; /* [blocks]/[bytes] */
10424 unsigned long long old_data_stripe_length
;
10425 unsigned long long start_src
; /* [bytes] */
10426 unsigned long long start
; /* [bytes] */
10427 unsigned long long start_buf_shift
; /* [bytes] */
10429 int source_layout
= 0;
10431 if (!fds
|| !offsets
|| !sra
)
10434 /* Find volume during the reshape */
10435 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
10436 if (dv
->dev
->vol
.migr_type
== MIGR_GEN_MIGR
10437 && dv
->dev
->vol
.migr_state
== 1) {
10442 /* Only one volume can migrate at the same time */
10443 if (migr_vol_qan
!= 1) {
10444 pr_err(": %s", migr_vol_qan
?
10445 "Number of migrating volumes greater than 1\n" :
10446 "There is no volume during migrationg\n");
10450 map_src
= get_imsm_map(dev
, MAP_1
);
10451 if (map_src
== NULL
)
10454 ndata
= imsm_num_data_members(dev
, MAP_0
);
10455 odata
= imsm_num_data_members(dev
, MAP_1
);
10457 chunk
= __le16_to_cpu(map_src
->blocks_per_strip
) * 512;
10458 old_data_stripe_length
= odata
* chunk
;
10460 migr_rec
= super
->migr_rec
;
10462 /* initialize migration record for start condition */
10463 if (sra
->reshape_progress
== 0)
10464 init_migr_record_imsm(st
, dev
, sra
);
10466 if (__le32_to_cpu(migr_rec
->rec_status
) != UNIT_SRC_NORMAL
) {
10467 dprintf("imsm: cannot restart migration when data "
10468 "are present in copy area.\n");
10471 /* Save checkpoint to update migration record for current
10472 * reshape position (in md). It can be farther than current
10473 * reshape position in metadata.
10475 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
10476 /* ignore error == 2, this can mean end of reshape here
10478 dprintf("imsm: Cannot write checkpoint to "
10479 "migration record (UNIT_SRC_NORMAL, "
10480 "initial save)\n");
10485 /* size for data */
10486 buf_size
= __le32_to_cpu(migr_rec
->blocks_per_unit
) * 512;
10487 /* extend buffer size for parity disk */
10488 buf_size
+= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
10489 /* add space for stripe aligment */
10490 buf_size
+= old_data_stripe_length
;
10491 if (posix_memalign((void **)&buf
, 4096, buf_size
)) {
10492 dprintf("imsm: Cannot allocate checpoint buffer\n");
10496 max_position
= sra
->component_size
* ndata
;
10497 source_layout
= imsm_level_to_layout(map_src
->raid_level
);
10499 while (__le32_to_cpu(migr_rec
->curr_migr_unit
) <
10500 __le32_to_cpu(migr_rec
->num_migr_units
)) {
10501 /* current reshape position [blocks] */
10502 unsigned long long current_position
=
10503 __le32_to_cpu(migr_rec
->blocks_per_unit
)
10504 * __le32_to_cpu(migr_rec
->curr_migr_unit
);
10505 unsigned long long border
;
10507 /* Check that array hasn't become failed.
10509 degraded
= check_degradation_change(sra
, fds
, degraded
);
10510 if (degraded
> 1) {
10511 dprintf("imsm: Abort reshape due to degradation"
10512 " level (%i)\n", degraded
);
10516 next_step
= __le32_to_cpu(migr_rec
->blocks_per_unit
);
10518 if ((current_position
+ next_step
) > max_position
)
10519 next_step
= max_position
- current_position
;
10521 start
= current_position
* 512;
10523 /* allign reading start to old geometry */
10524 start_buf_shift
= start
% old_data_stripe_length
;
10525 start_src
= start
- start_buf_shift
;
10527 border
= (start_src
/ odata
) - (start
/ ndata
);
10529 if (border
<= __le32_to_cpu(migr_rec
->dest_depth_per_unit
)) {
10530 /* save critical stripes to buf
10531 * start - start address of current unit
10532 * to backup [bytes]
10533 * start_src - start address of current unit
10534 * to backup alligned to source array
10537 unsigned long long next_step_filler
= 0;
10538 unsigned long long copy_length
= next_step
* 512;
10540 /* allign copy area length to stripe in old geometry */
10541 next_step_filler
= ((copy_length
+ start_buf_shift
)
10542 % old_data_stripe_length
);
10543 if (next_step_filler
)
10544 next_step_filler
= (old_data_stripe_length
10545 - next_step_filler
);
10546 dprintf("save_stripes() parameters: start = %llu,"
10547 "\tstart_src = %llu,\tnext_step*512 = %llu,"
10548 "\tstart_in_buf_shift = %llu,"
10549 "\tnext_step_filler = %llu\n",
10550 start
, start_src
, copy_length
,
10551 start_buf_shift
, next_step_filler
);
10553 if (save_stripes(fds
, offsets
, map_src
->num_members
,
10554 chunk
, map_src
->raid_level
,
10555 source_layout
, 0, NULL
, start_src
,
10557 next_step_filler
+ start_buf_shift
,
10559 dprintf("imsm: Cannot save stripes"
10563 /* Convert data to destination format and store it
10564 * in backup general migration area
10566 if (save_backup_imsm(st
, dev
, sra
,
10567 buf
+ start_buf_shift
, copy_length
)) {
10568 dprintf("imsm: Cannot save stripes to "
10569 "target devices\n");
10572 if (save_checkpoint_imsm(st
, sra
,
10573 UNIT_SRC_IN_CP_AREA
)) {
10574 dprintf("imsm: Cannot write checkpoint to "
10575 "migration record (UNIT_SRC_IN_CP_AREA)\n");
10579 /* set next step to use whole border area */
10580 border
/= next_step
;
10582 next_step
*= border
;
10584 /* When data backed up, checkpoint stored,
10585 * kick the kernel to reshape unit of data
10587 next_step
= next_step
+ sra
->reshape_progress
;
10588 /* limit next step to array max position */
10589 if (next_step
> max_position
)
10590 next_step
= max_position
;
10591 sysfs_set_num(sra
, NULL
, "suspend_lo", sra
->reshape_progress
);
10592 sysfs_set_num(sra
, NULL
, "suspend_hi", next_step
);
10593 sra
->reshape_progress
= next_step
;
10595 /* wait until reshape finish */
10596 if (wait_for_reshape_imsm(sra
, ndata
) < 0) {
10597 dprintf("wait_for_reshape_imsm returned error!\n");
10603 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
10604 /* ignore error == 2, this can mean end of reshape here
10606 dprintf("imsm: Cannot write checkpoint to "
10607 "migration record (UNIT_SRC_NORMAL)\n");
10613 /* return '1' if done */
10617 abort_reshape(sra
);
10622 #endif /* MDASSEMBLE */
10624 struct superswitch super_imsm
= {
10626 .examine_super
= examine_super_imsm
,
10627 .brief_examine_super
= brief_examine_super_imsm
,
10628 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
10629 .export_examine_super
= export_examine_super_imsm
,
10630 .detail_super
= detail_super_imsm
,
10631 .brief_detail_super
= brief_detail_super_imsm
,
10632 .write_init_super
= write_init_super_imsm
,
10633 .validate_geometry
= validate_geometry_imsm
,
10634 .add_to_super
= add_to_super_imsm
,
10635 .remove_from_super
= remove_from_super_imsm
,
10636 .detail_platform
= detail_platform_imsm
,
10637 .export_detail_platform
= export_detail_platform_imsm
,
10638 .kill_subarray
= kill_subarray_imsm
,
10639 .update_subarray
= update_subarray_imsm
,
10640 .load_container
= load_container_imsm
,
10641 .default_geometry
= default_geometry_imsm
,
10642 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
10643 .reshape_super
= imsm_reshape_super
,
10644 .manage_reshape
= imsm_manage_reshape
,
10645 .recover_backup
= recover_backup_imsm
,
10646 .copy_metadata
= copy_metadata_imsm
,
10648 .match_home
= match_home_imsm
,
10649 .uuid_from_super
= uuid_from_super_imsm
,
10650 .getinfo_super
= getinfo_super_imsm
,
10651 .getinfo_super_disks
= getinfo_super_disks_imsm
,
10652 .update_super
= update_super_imsm
,
10654 .avail_size
= avail_size_imsm
,
10655 .min_acceptable_spare_size
= min_acceptable_spare_size_imsm
,
10657 .compare_super
= compare_super_imsm
,
10659 .load_super
= load_super_imsm
,
10660 .init_super
= init_super_imsm
,
10661 .store_super
= store_super_imsm
,
10662 .free_super
= free_super_imsm
,
10663 .match_metadata_desc
= match_metadata_desc_imsm
,
10664 .container_content
= container_content_imsm
,
10665 .validate_container
= validate_container_imsm
,
10672 .open_new
= imsm_open_new
,
10673 .set_array_state
= imsm_set_array_state
,
10674 .set_disk
= imsm_set_disk
,
10675 .sync_metadata
= imsm_sync_metadata
,
10676 .activate_spare
= imsm_activate_spare
,
10677 .process_update
= imsm_process_update
,
10678 .prepare_update
= imsm_prepare_update
,
10679 #endif /* MDASSEMBLE */