2 * mdadm - Intel(R) Matrix Storage Manager Support
4 * Copyright (C) 2002-2008 Intel Corporation
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20 #define HAVE_STDINT_H 1
24 #include "platform-intel.h"
30 /* MPB == Metadata Parameter Block */
31 #define MPB_SIGNATURE "Intel Raid ISM Cfg Sig. "
32 #define MPB_SIG_LEN (strlen(MPB_SIGNATURE))
33 #define MPB_VERSION_RAID0 "1.0.00"
34 #define MPB_VERSION_RAID1 "1.1.00"
35 #define MPB_VERSION_MANY_VOLUMES_PER_ARRAY "1.2.00"
36 #define MPB_VERSION_3OR4_DISK_ARRAY "1.2.01"
37 #define MPB_VERSION_RAID5 "1.2.02"
38 #define MPB_VERSION_5OR6_DISK_ARRAY "1.2.04"
39 #define MPB_VERSION_CNG "1.2.06"
40 #define MPB_VERSION_ATTRIBS "1.3.00"
41 #define MAX_SIGNATURE_LENGTH 32
42 #define MAX_RAID_SERIAL_LEN 16
45 #define MPB_ATTRIB_RAID0 __cpu_to_le32(0x00000001)
47 #define MPB_ATTRIB_RAID1 __cpu_to_le32(0x00000002)
49 #define MPB_ATTRIB_RAID10 __cpu_to_le32(0x00000004)
51 #define MPB_ATTRIB_RAID1E __cpu_to_le32(0x00000008)
53 #define MPB_ATTRIB_RAID5 __cpu_to_le32(0x00000010)
54 /* supports RAID CNG */
55 #define MPB_ATTRIB_RAIDCNG __cpu_to_le32(0x00000020)
56 /* supports expanded stripe sizes of 256K, 512K and 1MB */
57 #define MPB_ATTRIB_EXP_STRIPE_SIZE __cpu_to_le32(0x00000040)
59 /* The OROM Support RST Caching of Volumes */
60 #define MPB_ATTRIB_NVM __cpu_to_le32(0x02000000)
61 /* The OROM supports creating disks greater than 2TB */
62 #define MPB_ATTRIB_2TB_DISK __cpu_to_le32(0x04000000)
63 /* The OROM supports Bad Block Management */
64 #define MPB_ATTRIB_BBM __cpu_to_le32(0x08000000)
66 /* THe OROM Supports NVM Caching of Volumes */
67 #define MPB_ATTRIB_NEVER_USE2 __cpu_to_le32(0x10000000)
68 /* The OROM supports creating volumes greater than 2TB */
69 #define MPB_ATTRIB_2TB __cpu_to_le32(0x20000000)
70 /* originally for PMP, now it's wasted b/c. Never use this bit! */
71 #define MPB_ATTRIB_NEVER_USE __cpu_to_le32(0x40000000)
72 /* Verify MPB contents against checksum after reading MPB */
73 #define MPB_ATTRIB_CHECKSUM_VERIFY __cpu_to_le32(0x80000000)
75 /* Define all supported attributes that have to be accepted by mdadm
77 #define MPB_ATTRIB_SUPPORTED (MPB_ATTRIB_CHECKSUM_VERIFY | \
79 MPB_ATTRIB_2TB_DISK | \
84 MPB_ATTRIB_EXP_STRIPE_SIZE)
86 /* Define attributes that are unused but not harmful */
87 #define MPB_ATTRIB_IGNORED (MPB_ATTRIB_NEVER_USE)
89 #define MPB_SECTOR_CNT 2210
90 #define IMSM_RESERVED_SECTORS 4096
91 #define NUM_BLOCKS_DIRTY_STRIPE_REGION 2056
92 #define SECT_PER_MB_SHIFT 11
94 /* Disk configuration info. */
95 #define IMSM_MAX_DEVICES 255
97 __u8 serial
[MAX_RAID_SERIAL_LEN
];/* 0xD8 - 0xE7 ascii serial number */
98 __u32 total_blocks_lo
; /* 0xE8 - 0xEB total blocks lo */
99 __u32 scsi_id
; /* 0xEC - 0xEF scsi ID */
100 #define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
101 #define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
102 #define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
103 __u32 status
; /* 0xF0 - 0xF3 */
104 __u32 owner_cfg_num
; /* which config 0,1,2... owns this disk */
105 __u32 total_blocks_hi
; /* 0xF4 - 0xF5 total blocks hi */
106 #define IMSM_DISK_FILLERS 3
107 __u32 filler
[IMSM_DISK_FILLERS
]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
110 /* map selector for map managment
116 /* RAID map configuration infos. */
118 __u32 pba_of_lba0_lo
; /* start address of partition */
119 __u32 blocks_per_member_lo
;/* blocks per member */
120 __u32 num_data_stripes_lo
; /* number of data stripes */
121 __u16 blocks_per_strip
;
122 __u8 map_state
; /* Normal, Uninitialized, Degraded, Failed */
123 #define IMSM_T_STATE_NORMAL 0
124 #define IMSM_T_STATE_UNINITIALIZED 1
125 #define IMSM_T_STATE_DEGRADED 2
126 #define IMSM_T_STATE_FAILED 3
128 #define IMSM_T_RAID0 0
129 #define IMSM_T_RAID1 1
130 #define IMSM_T_RAID5 5 /* since metadata version 1.2.02 ? */
131 __u8 num_members
; /* number of member disks */
132 __u8 num_domains
; /* number of parity domains */
133 __u8 failed_disk_num
; /* valid only when state is degraded */
135 __u32 pba_of_lba0_hi
;
136 __u32 blocks_per_member_hi
;
137 __u32 num_data_stripes_hi
;
138 __u32 filler
[4]; /* expansion area */
139 #define IMSM_ORD_REBUILD (1 << 24)
140 __u32 disk_ord_tbl
[1]; /* disk_ord_tbl[num_members],
141 * top byte contains some flags
143 } __attribute__ ((packed
));
146 __u32 curr_migr_unit
;
147 __u32 checkpoint_id
; /* id to access curr_migr_unit */
148 __u8 migr_state
; /* Normal or Migrating */
150 #define MIGR_REBUILD 1
151 #define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
152 #define MIGR_GEN_MIGR 3
153 #define MIGR_STATE_CHANGE 4
154 #define MIGR_REPAIR 5
155 __u8 migr_type
; /* Initializing, Rebuilding, ... */
157 __u8 fs_state
; /* fast-sync state for CnG (0xff == disabled) */
158 __u16 verify_errors
; /* number of mismatches */
159 __u16 bad_blocks
; /* number of bad blocks during verify */
161 struct imsm_map map
[1];
162 /* here comes another one if migr_state */
163 } __attribute__ ((packed
));
166 __u8 volume
[MAX_RAID_SERIAL_LEN
];
169 #define DEV_BOOTABLE __cpu_to_le32(0x01)
170 #define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
171 #define DEV_READ_COALESCING __cpu_to_le32(0x04)
172 #define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
173 #define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
174 #define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
175 #define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
176 #define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
177 #define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
178 #define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
179 #define DEV_CLONE_N_GO __cpu_to_le32(0x400)
180 #define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
181 #define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
182 __u32 status
; /* Persistent RaidDev status */
183 __u32 reserved_blocks
; /* Reserved blocks at beginning of volume */
187 __u8 cng_master_disk
;
191 #define IMSM_DEV_FILLERS 10
192 __u32 filler
[IMSM_DEV_FILLERS
];
194 } __attribute__ ((packed
));
197 __u8 sig
[MAX_SIGNATURE_LENGTH
]; /* 0x00 - 0x1F */
198 __u32 check_sum
; /* 0x20 - 0x23 MPB Checksum */
199 __u32 mpb_size
; /* 0x24 - 0x27 Size of MPB */
200 __u32 family_num
; /* 0x28 - 0x2B Checksum from first time this config was written */
201 __u32 generation_num
; /* 0x2C - 0x2F Incremented each time this array's MPB is written */
202 __u32 error_log_size
; /* 0x30 - 0x33 in bytes */
203 __u32 attributes
; /* 0x34 - 0x37 */
204 __u8 num_disks
; /* 0x38 Number of configured disks */
205 __u8 num_raid_devs
; /* 0x39 Number of configured volumes */
206 __u8 error_log_pos
; /* 0x3A */
207 __u8 fill
[1]; /* 0x3B */
208 __u32 cache_size
; /* 0x3c - 0x40 in mb */
209 __u32 orig_family_num
; /* 0x40 - 0x43 original family num */
210 __u32 pwr_cycle_count
; /* 0x44 - 0x47 simulated power cycle count for array */
211 __u32 bbm_log_size
; /* 0x48 - 0x4B - size of bad Block Mgmt Log in bytes */
212 #define IMSM_FILLERS 35
213 __u32 filler
[IMSM_FILLERS
]; /* 0x4C - 0xD7 RAID_MPB_FILLERS */
214 struct imsm_disk disk
[1]; /* 0xD8 diskTbl[numDisks] */
215 /* here comes imsm_dev[num_raid_devs] */
216 /* here comes BBM logs */
217 } __attribute__ ((packed
));
219 #define BBM_LOG_MAX_ENTRIES 254
221 struct bbm_log_entry
{
222 __u64 defective_block_start
;
223 #define UNREADABLE 0xFFFFFFFF
224 __u32 spare_block_offset
;
225 __u16 remapped_marked_count
;
227 } __attribute__ ((__packed__
));
230 __u32 signature
; /* 0xABADB10C */
232 __u32 reserved_spare_block_count
; /* 0 */
233 __u32 reserved
; /* 0xFFFF */
234 __u64 first_spare_lba
;
235 struct bbm_log_entry mapped_block_entries
[BBM_LOG_MAX_ENTRIES
];
236 } __attribute__ ((__packed__
));
239 static char *map_state_str
[] = { "normal", "uninitialized", "degraded", "failed" };
242 #define RAID_DISK_RESERVED_BLOCKS_IMSM_HI 2209
244 #define GEN_MIGR_AREA_SIZE 2048 /* General Migration Copy Area size in blocks */
246 #define MIGR_REC_BUF_SIZE 512 /* size of migr_record i/o buffer */
247 #define MIGR_REC_POSITION 512 /* migr_record position offset on disk,
248 * MIGR_REC_BUF_SIZE <= MIGR_REC_POSITION
251 #define UNIT_SRC_NORMAL 0 /* Source data for curr_migr_unit must
252 * be recovered using srcMap */
253 #define UNIT_SRC_IN_CP_AREA 1 /* Source data for curr_migr_unit has
254 * already been migrated and must
255 * be recovered from checkpoint area */
257 __u32 rec_status
; /* Status used to determine how to restart
258 * migration in case it aborts
260 __u32 curr_migr_unit
; /* 0..numMigrUnits-1 */
261 __u32 family_num
; /* Family number of MPB
262 * containing the RaidDev
263 * that is migrating */
264 __u32 ascending_migr
; /* True if migrating in increasing
266 __u32 blocks_per_unit
; /* Num disk blocks per unit of operation */
267 __u32 dest_depth_per_unit
; /* Num member blocks each destMap
269 * advances per unit-of-operation */
270 __u32 ckpt_area_pba
; /* Pba of first block of ckpt copy area */
271 __u32 dest_1st_member_lba
; /* First member lba on first
272 * stripe of destination */
273 __u32 num_migr_units
; /* Total num migration units-of-op */
274 __u32 post_migr_vol_cap
; /* Size of volume after
275 * migration completes */
276 __u32 post_migr_vol_cap_hi
; /* Expansion space for LBA64 */
277 __u32 ckpt_read_disk_num
; /* Which member disk in destSubMap[0] the
278 * migration ckpt record was read from
279 * (for recovered migrations) */
280 } __attribute__ ((__packed__
));
285 * 2: metadata does not match
293 struct md_list
*next
;
296 #define pr_vrb(fmt, arg...) (void) (verbose && pr_err(fmt, ##arg))
298 static __u8
migr_type(struct imsm_dev
*dev
)
300 if (dev
->vol
.migr_type
== MIGR_VERIFY
&&
301 dev
->status
& DEV_VERIFY_AND_FIX
)
304 return dev
->vol
.migr_type
;
307 static void set_migr_type(struct imsm_dev
*dev
, __u8 migr_type
)
309 /* for compatibility with older oroms convert MIGR_REPAIR, into
310 * MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status
312 if (migr_type
== MIGR_REPAIR
) {
313 dev
->vol
.migr_type
= MIGR_VERIFY
;
314 dev
->status
|= DEV_VERIFY_AND_FIX
;
316 dev
->vol
.migr_type
= migr_type
;
317 dev
->status
&= ~DEV_VERIFY_AND_FIX
;
321 static unsigned int sector_count(__u32 bytes
)
323 return ROUND_UP(bytes
, 512) / 512;
326 static unsigned int mpb_sectors(struct imsm_super
*mpb
)
328 return sector_count(__le32_to_cpu(mpb
->mpb_size
));
332 struct imsm_dev
*dev
;
333 struct intel_dev
*next
;
338 enum sys_dev_type type
;
341 struct intel_hba
*next
;
348 /* internal representation of IMSM metadata */
351 void *buf
; /* O_DIRECT buffer for reading/writing metadata */
352 struct imsm_super
*anchor
; /* immovable parameters */
355 void *migr_rec_buf
; /* buffer for I/O operations */
356 struct migr_record
*migr_rec
; /* migration record */
358 int clean_migration_record_by_mdmon
; /* when reshape is switched to next
359 array, it indicates that mdmon is allowed to clean migration
361 size_t len
; /* size of the 'buf' allocation */
362 void *next_buf
; /* for realloc'ing buf from the manager */
364 int updates_pending
; /* count of pending updates for mdmon */
365 int current_vol
; /* index of raid device undergoing creation */
366 unsigned long long create_offset
; /* common start for 'current_vol' */
367 __u32 random
; /* random data for seeding new family numbers */
368 struct intel_dev
*devlist
;
372 __u8 serial
[MAX_RAID_SERIAL_LEN
];
375 struct imsm_disk disk
;
378 struct extent
*e
; /* for determining freespace @ create */
379 int raiddisk
; /* slot to fill in autolayout */
381 } *disks
, *current_disk
;
382 struct dl
*disk_mgmt_list
; /* list of disks to add/remove while mdmon
384 struct dl
*missing
; /* disks removed while we weren't looking */
385 struct bbm_log
*bbm_log
;
386 struct intel_hba
*hba
; /* device path of the raid controller for this metadata */
387 const struct imsm_orom
*orom
; /* platform firmware support */
388 struct intel_super
*next
; /* (temp) list for disambiguating family_num */
392 struct imsm_disk disk
;
393 #define IMSM_UNKNOWN_OWNER (-1)
395 struct intel_disk
*next
;
399 unsigned long long start
, size
;
402 /* definitions of reshape process types */
403 enum imsm_reshape_type
{
409 /* definition of messages passed to imsm_process_update */
410 enum imsm_update_type
{
411 update_activate_spare
,
415 update_add_remove_disk
,
416 update_reshape_container_disks
,
417 update_reshape_migration
,
419 update_general_migration_checkpoint
,
423 struct imsm_update_activate_spare
{
424 enum imsm_update_type type
;
428 struct imsm_update_activate_spare
*next
;
434 unsigned long long size
;
441 enum takeover_direction
{
445 struct imsm_update_takeover
{
446 enum imsm_update_type type
;
448 enum takeover_direction direction
;
451 struct imsm_update_reshape
{
452 enum imsm_update_type type
;
456 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
459 struct imsm_update_reshape_migration
{
460 enum imsm_update_type type
;
463 /* fields for array migration changes
470 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
473 struct imsm_update_size_change
{
474 enum imsm_update_type type
;
479 struct imsm_update_general_migration_checkpoint
{
480 enum imsm_update_type type
;
481 __u32 curr_migr_unit
;
485 __u8 serial
[MAX_RAID_SERIAL_LEN
];
488 struct imsm_update_create_array
{
489 enum imsm_update_type type
;
494 struct imsm_update_kill_array
{
495 enum imsm_update_type type
;
499 struct imsm_update_rename_array
{
500 enum imsm_update_type type
;
501 __u8 name
[MAX_RAID_SERIAL_LEN
];
505 struct imsm_update_add_remove_disk
{
506 enum imsm_update_type type
;
509 static const char *_sys_dev_type
[] = {
510 [SYS_DEV_UNKNOWN
] = "Unknown",
511 [SYS_DEV_SAS
] = "SAS",
512 [SYS_DEV_SATA
] = "SATA",
513 [SYS_DEV_NVME
] = "NVMe"
516 const char *get_sys_dev_type(enum sys_dev_type type
)
518 if (type
>= SYS_DEV_MAX
)
519 type
= SYS_DEV_UNKNOWN
;
521 return _sys_dev_type
[type
];
524 static struct intel_hba
* alloc_intel_hba(struct sys_dev
*device
)
526 struct intel_hba
*result
= xmalloc(sizeof(*result
));
528 result
->type
= device
->type
;
529 result
->path
= xstrdup(device
->path
);
531 if (result
->path
&& (result
->pci_id
= strrchr(result
->path
, '/')) != NULL
)
537 static struct intel_hba
* find_intel_hba(struct intel_hba
*hba
, struct sys_dev
*device
)
539 struct intel_hba
*result
=NULL
;
540 for (result
= hba
; result
; result
= result
->next
) {
541 if (result
->type
== device
->type
&& strcmp(result
->path
, device
->path
) == 0)
547 static int attach_hba_to_super(struct intel_super
*super
, struct sys_dev
*device
)
549 struct intel_hba
*hba
;
551 /* check if disk attached to Intel HBA */
552 hba
= find_intel_hba(super
->hba
, device
);
555 /* Check if HBA is already attached to super */
556 if (super
->hba
== NULL
) {
557 super
->hba
= alloc_intel_hba(device
);
562 /* Intel metadata allows for all disks attached to the same type HBA.
563 * Do not support HBA types mixing
565 if (device
->type
!= hba
->type
)
568 /* Multiple same type HBAs can be used if they share the same OROM */
569 const struct imsm_orom
*device_orom
= get_orom_by_device_id(device
->dev_id
);
571 if (device_orom
!= super
->orom
)
577 hba
->next
= alloc_intel_hba(device
);
581 static struct sys_dev
* find_disk_attached_hba(int fd
, const char *devname
)
583 struct sys_dev
*list
, *elem
;
586 if ((list
= find_intel_devices()) == NULL
)
590 disk_path
= (char *) devname
;
592 disk_path
= diskfd_to_devpath(fd
);
597 for (elem
= list
; elem
; elem
= elem
->next
)
598 if (path_attached_to_hba(disk_path
, elem
->path
))
601 if (disk_path
!= devname
)
607 static int find_intel_hba_capability(int fd
, struct intel_super
*super
,
610 static struct supertype
*match_metadata_desc_imsm(char *arg
)
612 struct supertype
*st
;
614 if (strcmp(arg
, "imsm") != 0 &&
615 strcmp(arg
, "default") != 0
619 st
= xcalloc(1, sizeof(*st
));
620 st
->ss
= &super_imsm
;
621 st
->max_devs
= IMSM_MAX_DEVICES
;
622 st
->minor_version
= 0;
628 static __u8
*get_imsm_version(struct imsm_super
*mpb
)
630 return &mpb
->sig
[MPB_SIG_LEN
];
634 /* retrieve a disk directly from the anchor when the anchor is known to be
635 * up-to-date, currently only at load time
637 static struct imsm_disk
*__get_imsm_disk(struct imsm_super
*mpb
, __u8 index
)
639 if (index
>= mpb
->num_disks
)
641 return &mpb
->disk
[index
];
644 /* retrieve the disk description based on a index of the disk
647 static struct dl
*get_imsm_dl_disk(struct intel_super
*super
, __u8 index
)
651 for (d
= super
->disks
; d
; d
= d
->next
)
652 if (d
->index
== index
)
657 /* retrieve a disk from the parsed metadata */
658 static struct imsm_disk
*get_imsm_disk(struct intel_super
*super
, __u8 index
)
662 dl
= get_imsm_dl_disk(super
, index
);
669 /* generate a checksum directly from the anchor when the anchor is known to be
670 * up-to-date, currently only at load or write_super after coalescing
672 static __u32
__gen_imsm_checksum(struct imsm_super
*mpb
)
674 __u32 end
= mpb
->mpb_size
/ sizeof(end
);
675 __u32
*p
= (__u32
*) mpb
;
679 sum
+= __le32_to_cpu(*p
);
683 return sum
- __le32_to_cpu(mpb
->check_sum
);
686 static size_t sizeof_imsm_map(struct imsm_map
*map
)
688 return sizeof(struct imsm_map
) + sizeof(__u32
) * (map
->num_members
- 1);
691 struct imsm_map
*get_imsm_map(struct imsm_dev
*dev
, int second_map
)
693 /* A device can have 2 maps if it is in the middle of a migration.
695 * MAP_0 - we return the first map
696 * MAP_1 - we return the second map if it exists, else NULL
697 * MAP_X - we return the second map if it exists, else the first
699 struct imsm_map
*map
= &dev
->vol
.map
[0];
700 struct imsm_map
*map2
= NULL
;
702 if (dev
->vol
.migr_state
)
703 map2
= (void *)map
+ sizeof_imsm_map(map
);
705 switch (second_map
) {
722 /* return the size of the device.
723 * migr_state increases the returned size if map[0] were to be duplicated
725 static size_t sizeof_imsm_dev(struct imsm_dev
*dev
, int migr_state
)
727 size_t size
= sizeof(*dev
) - sizeof(struct imsm_map
) +
728 sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
730 /* migrating means an additional map */
731 if (dev
->vol
.migr_state
)
732 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_1
));
734 size
+= sizeof_imsm_map(get_imsm_map(dev
, MAP_0
));
740 /* retrieve disk serial number list from a metadata update */
741 static struct disk_info
*get_disk_info(struct imsm_update_create_array
*update
)
744 struct disk_info
*inf
;
746 inf
= u
+ sizeof(*update
) - sizeof(struct imsm_dev
) +
747 sizeof_imsm_dev(&update
->dev
, 0);
753 static struct imsm_dev
*__get_imsm_dev(struct imsm_super
*mpb
, __u8 index
)
759 if (index
>= mpb
->num_raid_devs
)
762 /* devices start after all disks */
763 offset
= ((void *) &mpb
->disk
[mpb
->num_disks
]) - _mpb
;
765 for (i
= 0; i
<= index
; i
++)
767 return _mpb
+ offset
;
769 offset
+= sizeof_imsm_dev(_mpb
+ offset
, 0);
774 static struct imsm_dev
*get_imsm_dev(struct intel_super
*super
, __u8 index
)
776 struct intel_dev
*dv
;
778 if (index
>= super
->anchor
->num_raid_devs
)
780 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
781 if (dv
->index
== index
)
788 * == MAP_0 get first map
789 * == MAP_1 get second map
790 * == MAP_X than get map according to the current migr_state
792 static __u32
get_imsm_ord_tbl_ent(struct imsm_dev
*dev
,
796 struct imsm_map
*map
;
798 map
= get_imsm_map(dev
, second_map
);
800 /* top byte identifies disk under rebuild */
801 return __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
804 #define ord_to_idx(ord) (((ord) << 8) >> 8)
805 static __u32
get_imsm_disk_idx(struct imsm_dev
*dev
, int slot
, int second_map
)
807 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, second_map
);
809 return ord_to_idx(ord
);
812 static void set_imsm_ord_tbl_ent(struct imsm_map
*map
, int slot
, __u32 ord
)
814 map
->disk_ord_tbl
[slot
] = __cpu_to_le32(ord
);
817 static int get_imsm_disk_slot(struct imsm_map
*map
, unsigned idx
)
822 for (slot
= 0; slot
< map
->num_members
; slot
++) {
823 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
824 if (ord_to_idx(ord
) == idx
)
831 static int get_imsm_raid_level(struct imsm_map
*map
)
833 if (map
->raid_level
== 1) {
834 if (map
->num_members
== 2)
840 return map
->raid_level
;
843 static int cmp_extent(const void *av
, const void *bv
)
845 const struct extent
*a
= av
;
846 const struct extent
*b
= bv
;
847 if (a
->start
< b
->start
)
849 if (a
->start
> b
->start
)
854 static int count_memberships(struct dl
*dl
, struct intel_super
*super
)
859 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
860 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
861 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
863 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
870 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
);
872 static int split_ull(unsigned long long n
, __u32
*lo
, __u32
*hi
)
874 if (lo
== 0 || hi
== 0)
876 *lo
= __le32_to_cpu((unsigned)n
);
877 *hi
= __le32_to_cpu((unsigned)(n
>> 32));
881 static unsigned long long join_u32(__u32 lo
, __u32 hi
)
883 return (unsigned long long)__le32_to_cpu(lo
) |
884 (((unsigned long long)__le32_to_cpu(hi
)) << 32);
887 static unsigned long long total_blocks(struct imsm_disk
*disk
)
891 return join_u32(disk
->total_blocks_lo
, disk
->total_blocks_hi
);
894 static unsigned long long pba_of_lba0(struct imsm_map
*map
)
898 return join_u32(map
->pba_of_lba0_lo
, map
->pba_of_lba0_hi
);
901 static unsigned long long blocks_per_member(struct imsm_map
*map
)
905 return join_u32(map
->blocks_per_member_lo
, map
->blocks_per_member_hi
);
909 static unsigned long long num_data_stripes(struct imsm_map
*map
)
913 return join_u32(map
->num_data_stripes_lo
, map
->num_data_stripes_hi
);
916 static void set_total_blocks(struct imsm_disk
*disk
, unsigned long long n
)
918 split_ull(n
, &disk
->total_blocks_lo
, &disk
->total_blocks_hi
);
922 static void set_pba_of_lba0(struct imsm_map
*map
, unsigned long long n
)
924 split_ull(n
, &map
->pba_of_lba0_lo
, &map
->pba_of_lba0_hi
);
927 static void set_blocks_per_member(struct imsm_map
*map
, unsigned long long n
)
929 split_ull(n
, &map
->blocks_per_member_lo
, &map
->blocks_per_member_hi
);
932 static void set_num_data_stripes(struct imsm_map
*map
, unsigned long long n
)
934 split_ull(n
, &map
->num_data_stripes_lo
, &map
->num_data_stripes_hi
);
937 static struct extent
*get_extents(struct intel_super
*super
, struct dl
*dl
)
939 /* find a list of used extents on the given physical device */
940 struct extent
*rv
, *e
;
942 int memberships
= count_memberships(dl
, super
);
945 /* trim the reserved area for spares, so they can join any array
946 * regardless of whether the OROM has assigned sectors from the
947 * IMSM_RESERVED_SECTORS region
950 reservation
= imsm_min_reserved_sectors(super
);
952 reservation
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
954 rv
= xcalloc(sizeof(struct extent
), (memberships
+ 1));
957 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
958 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
959 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
961 if (get_imsm_disk_slot(map
, dl
->index
) >= 0) {
962 e
->start
= pba_of_lba0(map
);
963 e
->size
= blocks_per_member(map
);
967 qsort(rv
, memberships
, sizeof(*rv
), cmp_extent
);
969 /* determine the start of the metadata
970 * when no raid devices are defined use the default
971 * ...otherwise allow the metadata to truncate the value
972 * as is the case with older versions of imsm
975 struct extent
*last
= &rv
[memberships
- 1];
976 unsigned long long remainder
;
978 remainder
= total_blocks(&dl
->disk
) - (last
->start
+ last
->size
);
979 /* round down to 1k block to satisfy precision of the kernel
983 /* make sure remainder is still sane */
984 if (remainder
< (unsigned)ROUND_UP(super
->len
, 512) >> 9)
985 remainder
= ROUND_UP(super
->len
, 512) >> 9;
986 if (reservation
> remainder
)
987 reservation
= remainder
;
989 e
->start
= total_blocks(&dl
->disk
) - reservation
;
994 /* try to determine how much space is reserved for metadata from
995 * the last get_extents() entry, otherwise fallback to the
998 static __u32
imsm_reserved_sectors(struct intel_super
*super
, struct dl
*dl
)
1004 /* for spares just return a minimal reservation which will grow
1005 * once the spare is picked up by an array
1007 if (dl
->index
== -1)
1008 return MPB_SECTOR_CNT
;
1010 e
= get_extents(super
, dl
);
1012 return MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1014 /* scroll to last entry */
1015 for (i
= 0; e
[i
].size
; i
++)
1018 rv
= total_blocks(&dl
->disk
) - e
[i
].start
;
1025 static int is_spare(struct imsm_disk
*disk
)
1027 return (disk
->status
& SPARE_DISK
) == SPARE_DISK
;
1030 static int is_configured(struct imsm_disk
*disk
)
1032 return (disk
->status
& CONFIGURED_DISK
) == CONFIGURED_DISK
;
1035 static int is_failed(struct imsm_disk
*disk
)
1037 return (disk
->status
& FAILED_DISK
) == FAILED_DISK
;
1040 /* try to determine how much space is reserved for metadata from
1041 * the last get_extents() entry on the smallest active disk,
1042 * otherwise fallback to the default
1044 static __u32
imsm_min_reserved_sectors(struct intel_super
*super
)
1048 unsigned long long min_active
;
1050 __u32 rv
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
1051 struct dl
*dl
, *dl_min
= NULL
;
1057 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
1060 unsigned long long blocks
= total_blocks(&dl
->disk
);
1061 if (blocks
< min_active
|| min_active
== 0) {
1063 min_active
= blocks
;
1069 /* find last lba used by subarrays on the smallest active disk */
1070 e
= get_extents(super
, dl_min
);
1073 for (i
= 0; e
[i
].size
; i
++)
1076 remainder
= min_active
- e
[i
].start
;
1079 /* to give priority to recovery we should not require full
1080 IMSM_RESERVED_SECTORS from the spare */
1081 rv
= MPB_SECTOR_CNT
+ NUM_BLOCKS_DIRTY_STRIPE_REGION
;
1083 /* if real reservation is smaller use that value */
1084 return (remainder
< rv
) ? remainder
: rv
;
1087 /* Return minimum size of a spare that can be used in this array*/
1088 static unsigned long long min_acceptable_spare_size_imsm(struct supertype
*st
)
1090 struct intel_super
*super
= st
->sb
;
1094 unsigned long long rv
= 0;
1098 /* find first active disk in array */
1100 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
1104 /* find last lba used by subarrays */
1105 e
= get_extents(super
, dl
);
1108 for (i
= 0; e
[i
].size
; i
++)
1111 rv
= e
[i
-1].start
+ e
[i
-1].size
;
1114 /* add the amount of space needed for metadata */
1115 rv
= rv
+ imsm_min_reserved_sectors(super
);
1120 static int is_gen_migration(struct imsm_dev
*dev
);
1123 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
1124 struct imsm_dev
*dev
);
1126 static void print_imsm_dev(struct intel_super
*super
,
1127 struct imsm_dev
*dev
,
1133 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
1134 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
1138 printf("[%.16s]:\n", dev
->volume
);
1139 printf(" UUID : %s\n", uuid
);
1140 printf(" RAID Level : %d", get_imsm_raid_level(map
));
1142 printf(" <-- %d", get_imsm_raid_level(map2
));
1144 printf(" Members : %d", map
->num_members
);
1146 printf(" <-- %d", map2
->num_members
);
1148 printf(" Slots : [");
1149 for (i
= 0; i
< map
->num_members
; i
++) {
1150 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_0
);
1151 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1156 for (i
= 0; i
< map2
->num_members
; i
++) {
1157 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_1
);
1158 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1163 printf(" Failed disk : ");
1164 if (map
->failed_disk_num
== 0xff)
1167 printf("%i", map
->failed_disk_num
);
1169 slot
= get_imsm_disk_slot(map
, disk_idx
);
1171 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
1172 printf(" This Slot : %d%s\n", slot
,
1173 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
1175 printf(" This Slot : ?\n");
1176 sz
= __le32_to_cpu(dev
->size_high
);
1178 sz
+= __le32_to_cpu(dev
->size_low
);
1179 printf(" Array Size : %llu%s\n", (unsigned long long)sz
,
1180 human_size(sz
* 512));
1181 sz
= blocks_per_member(map
);
1182 printf(" Per Dev Size : %llu%s\n", (unsigned long long)sz
,
1183 human_size(sz
* 512));
1184 printf(" Sector Offset : %llu\n",
1186 printf(" Num Stripes : %llu\n",
1187 num_data_stripes(map
));
1188 printf(" Chunk Size : %u KiB",
1189 __le16_to_cpu(map
->blocks_per_strip
) / 2);
1191 printf(" <-- %u KiB",
1192 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
1194 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
1195 printf(" Migrate State : ");
1196 if (dev
->vol
.migr_state
) {
1197 if (migr_type(dev
) == MIGR_INIT
)
1198 printf("initialize\n");
1199 else if (migr_type(dev
) == MIGR_REBUILD
)
1200 printf("rebuild\n");
1201 else if (migr_type(dev
) == MIGR_VERIFY
)
1203 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
1204 printf("general migration\n");
1205 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
1206 printf("state change\n");
1207 else if (migr_type(dev
) == MIGR_REPAIR
)
1210 printf("<unknown:%d>\n", migr_type(dev
));
1213 printf(" Map State : %s", map_state_str
[map
->map_state
]);
1214 if (dev
->vol
.migr_state
) {
1215 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
1217 printf(" <-- %s", map_state_str
[map
->map_state
]);
1218 printf("\n Checkpoint : %u ",
1219 __le32_to_cpu(dev
->vol
.curr_migr_unit
));
1220 if ((is_gen_migration(dev
)) && ((slot
> 1) || (slot
< 0)))
1223 printf("(%llu)", (unsigned long long)
1224 blocks_per_migr_unit(super
, dev
));
1227 printf(" Dirty State : %s\n", dev
->vol
.dirty
? "dirty" : "clean");
1230 static void print_imsm_disk(struct imsm_disk
*disk
, int index
, __u32 reserved
)
1232 char str
[MAX_RAID_SERIAL_LEN
+ 1];
1235 if (index
< -1 || !disk
)
1239 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
1241 printf(" Disk%02d Serial : %s\n", index
, str
);
1243 printf(" Disk Serial : %s\n", str
);
1244 printf(" State :%s%s%s\n", is_spare(disk
) ? " spare" : "",
1245 is_configured(disk
) ? " active" : "",
1246 is_failed(disk
) ? " failed" : "");
1247 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
1248 sz
= total_blocks(disk
) - reserved
;
1249 printf(" Usable Size : %llu%s\n", (unsigned long long)sz
,
1250 human_size(sz
* 512));
1253 void examine_migr_rec_imsm(struct intel_super
*super
)
1255 struct migr_record
*migr_rec
= super
->migr_rec
;
1256 struct imsm_super
*mpb
= super
->anchor
;
1259 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1260 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1261 struct imsm_map
*map
;
1264 if (is_gen_migration(dev
) == 0)
1267 printf("\nMigration Record Information:");
1269 /* first map under migration */
1270 map
= get_imsm_map(dev
, MAP_0
);
1272 slot
= get_imsm_disk_slot(map
, super
->disks
->index
);
1273 if ((map
== NULL
) || (slot
> 1) || (slot
< 0)) {
1274 printf(" Empty\n ");
1275 printf("Examine one of first two disks in array\n");
1278 printf("\n Status : ");
1279 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
1282 printf("Contains Data\n");
1283 printf(" Current Unit : %u\n",
1284 __le32_to_cpu(migr_rec
->curr_migr_unit
));
1285 printf(" Family : %u\n",
1286 __le32_to_cpu(migr_rec
->family_num
));
1287 printf(" Ascending : %u\n",
1288 __le32_to_cpu(migr_rec
->ascending_migr
));
1289 printf(" Blocks Per Unit : %u\n",
1290 __le32_to_cpu(migr_rec
->blocks_per_unit
));
1291 printf(" Dest. Depth Per Unit : %u\n",
1292 __le32_to_cpu(migr_rec
->dest_depth_per_unit
));
1293 printf(" Checkpoint Area pba : %u\n",
1294 __le32_to_cpu(migr_rec
->ckpt_area_pba
));
1295 printf(" First member lba : %u\n",
1296 __le32_to_cpu(migr_rec
->dest_1st_member_lba
));
1297 printf(" Total Number of Units : %u\n",
1298 __le32_to_cpu(migr_rec
->num_migr_units
));
1299 printf(" Size of volume : %u\n",
1300 __le32_to_cpu(migr_rec
->post_migr_vol_cap
));
1301 printf(" Expansion space for LBA64 : %u\n",
1302 __le32_to_cpu(migr_rec
->post_migr_vol_cap_hi
));
1303 printf(" Record was read from : %u\n",
1304 __le32_to_cpu(migr_rec
->ckpt_read_disk_num
));
1309 #endif /* MDASSEMBLE */
1310 /*******************************************************************************
1311 * function: imsm_check_attributes
1312 * Description: Function checks if features represented by attributes flags
1313 * are supported by mdadm.
1315 * attributes - Attributes read from metadata
1317 * 0 - passed attributes contains unsupported features flags
1318 * 1 - all features are supported
1319 ******************************************************************************/
1320 static int imsm_check_attributes(__u32 attributes
)
1323 __u32 not_supported
= MPB_ATTRIB_SUPPORTED
^0xffffffff;
1325 not_supported
&= ~MPB_ATTRIB_IGNORED
;
1327 not_supported
&= attributes
;
1328 if (not_supported
) {
1329 pr_err("(IMSM): Unsupported attributes : %x\n",
1330 (unsigned)__le32_to_cpu(not_supported
));
1331 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1332 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY \n");
1333 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1335 if (not_supported
& MPB_ATTRIB_2TB
) {
1336 dprintf("\t\tMPB_ATTRIB_2TB\n");
1337 not_supported
^= MPB_ATTRIB_2TB
;
1339 if (not_supported
& MPB_ATTRIB_RAID0
) {
1340 dprintf("\t\tMPB_ATTRIB_RAID0\n");
1341 not_supported
^= MPB_ATTRIB_RAID0
;
1343 if (not_supported
& MPB_ATTRIB_RAID1
) {
1344 dprintf("\t\tMPB_ATTRIB_RAID1\n");
1345 not_supported
^= MPB_ATTRIB_RAID1
;
1347 if (not_supported
& MPB_ATTRIB_RAID10
) {
1348 dprintf("\t\tMPB_ATTRIB_RAID10\n");
1349 not_supported
^= MPB_ATTRIB_RAID10
;
1351 if (not_supported
& MPB_ATTRIB_RAID1E
) {
1352 dprintf("\t\tMPB_ATTRIB_RAID1E\n");
1353 not_supported
^= MPB_ATTRIB_RAID1E
;
1355 if (not_supported
& MPB_ATTRIB_RAID5
) {
1356 dprintf("\t\tMPB_ATTRIB_RAID5\n");
1357 not_supported
^= MPB_ATTRIB_RAID5
;
1359 if (not_supported
& MPB_ATTRIB_RAIDCNG
) {
1360 dprintf("\t\tMPB_ATTRIB_RAIDCNG\n");
1361 not_supported
^= MPB_ATTRIB_RAIDCNG
;
1363 if (not_supported
& MPB_ATTRIB_BBM
) {
1364 dprintf("\t\tMPB_ATTRIB_BBM\n");
1365 not_supported
^= MPB_ATTRIB_BBM
;
1367 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1368 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY (== MPB_ATTRIB_LEGACY)\n");
1369 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1371 if (not_supported
& MPB_ATTRIB_EXP_STRIPE_SIZE
) {
1372 dprintf("\t\tMPB_ATTRIB_EXP_STRIP_SIZE\n");
1373 not_supported
^= MPB_ATTRIB_EXP_STRIPE_SIZE
;
1375 if (not_supported
& MPB_ATTRIB_2TB_DISK
) {
1376 dprintf("\t\tMPB_ATTRIB_2TB_DISK\n");
1377 not_supported
^= MPB_ATTRIB_2TB_DISK
;
1379 if (not_supported
& MPB_ATTRIB_NEVER_USE2
) {
1380 dprintf("\t\tMPB_ATTRIB_NEVER_USE2\n");
1381 not_supported
^= MPB_ATTRIB_NEVER_USE2
;
1383 if (not_supported
& MPB_ATTRIB_NEVER_USE
) {
1384 dprintf("\t\tMPB_ATTRIB_NEVER_USE\n");
1385 not_supported
^= MPB_ATTRIB_NEVER_USE
;
1389 dprintf("%s (IMSM): Unknown attributes : %x\n", Name
, not_supported
);
1398 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
1400 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
1402 struct intel_super
*super
= st
->sb
;
1403 struct imsm_super
*mpb
= super
->anchor
;
1404 char str
[MAX_SIGNATURE_LENGTH
];
1409 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
1412 snprintf(str
, MPB_SIG_LEN
, "%s", mpb
->sig
);
1413 printf(" Magic : %s\n", str
);
1414 snprintf(str
, strlen(MPB_VERSION_RAID0
), "%s", get_imsm_version(mpb
));
1415 printf(" Version : %s\n", get_imsm_version(mpb
));
1416 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
1417 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
1418 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
1419 printf(" Attributes : ");
1420 if (imsm_check_attributes(mpb
->attributes
))
1421 printf("All supported\n");
1423 printf("not supported\n");
1424 getinfo_super_imsm(st
, &info
, NULL
);
1425 fname_from_uuid(st
, &info
, nbuf
, ':');
1426 printf(" UUID : %s\n", nbuf
+ 5);
1427 sum
= __le32_to_cpu(mpb
->check_sum
);
1428 printf(" Checksum : %08x %s\n", sum
,
1429 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
1430 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
));
1431 printf(" Disks : %d\n", mpb
->num_disks
);
1432 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
1433 print_imsm_disk(__get_imsm_disk(mpb
, super
->disks
->index
), super
->disks
->index
, reserved
);
1434 if (super
->bbm_log
) {
1435 struct bbm_log
*log
= super
->bbm_log
;
1438 printf("Bad Block Management Log:\n");
1439 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
1440 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
1441 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
1442 printf(" Spare Blocks : %d\n", __le32_to_cpu(log
->reserved_spare_block_count
));
1443 printf(" First Spare : %llx\n",
1444 (unsigned long long) __le64_to_cpu(log
->first_spare_lba
));
1446 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1448 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1450 super
->current_vol
= i
;
1451 getinfo_super_imsm(st
, &info
, NULL
);
1452 fname_from_uuid(st
, &info
, nbuf
, ':');
1453 print_imsm_dev(super
, dev
, nbuf
+ 5, super
->disks
->index
);
1455 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1456 if (i
== super
->disks
->index
)
1458 print_imsm_disk(__get_imsm_disk(mpb
, i
), i
, reserved
);
1461 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
1462 if (dl
->index
== -1)
1463 print_imsm_disk(&dl
->disk
, -1, reserved
);
1465 examine_migr_rec_imsm(super
);
1468 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
1470 /* We just write a generic IMSM ARRAY entry */
1473 struct intel_super
*super
= st
->sb
;
1475 if (!super
->anchor
->num_raid_devs
) {
1476 printf("ARRAY metadata=imsm\n");
1480 getinfo_super_imsm(st
, &info
, NULL
);
1481 fname_from_uuid(st
, &info
, nbuf
, ':');
1482 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
1485 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
1487 /* We just write a generic IMSM ARRAY entry */
1491 struct intel_super
*super
= st
->sb
;
1494 if (!super
->anchor
->num_raid_devs
)
1497 getinfo_super_imsm(st
, &info
, NULL
);
1498 fname_from_uuid(st
, &info
, nbuf
, ':');
1499 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1500 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1502 super
->current_vol
= i
;
1503 getinfo_super_imsm(st
, &info
, NULL
);
1504 fname_from_uuid(st
, &info
, nbuf1
, ':');
1505 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
1506 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
1510 static void export_examine_super_imsm(struct supertype
*st
)
1512 struct intel_super
*super
= st
->sb
;
1513 struct imsm_super
*mpb
= super
->anchor
;
1517 getinfo_super_imsm(st
, &info
, NULL
);
1518 fname_from_uuid(st
, &info
, nbuf
, ':');
1519 printf("MD_METADATA=imsm\n");
1520 printf("MD_LEVEL=container\n");
1521 printf("MD_UUID=%s\n", nbuf
+5);
1522 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
1525 static int copy_metadata_imsm(struct supertype
*st
, int from
, int to
)
1527 /* The second last 512byte sector of the device contains
1528 * the "struct imsm_super" metadata.
1529 * This contains mpb_size which is the size in bytes of the
1530 * extended metadata. This is located immediately before
1532 * We want to read all that, plus the last sector which
1533 * may contain a migration record, and write it all
1537 unsigned long long dsize
, offset
;
1539 struct imsm_super
*sb
;
1542 if (posix_memalign(&buf
, 4096, 4096) != 0)
1545 if (!get_dev_size(from
, NULL
, &dsize
))
1548 if (lseek64(from
, dsize
-1024, 0) < 0)
1550 if (read(from
, buf
, 512) != 512)
1553 if (strncmp((char*)sb
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0)
1556 sectors
= mpb_sectors(sb
) + 2;
1557 offset
= dsize
- sectors
* 512;
1558 if (lseek64(from
, offset
, 0) < 0 ||
1559 lseek64(to
, offset
, 0) < 0)
1561 while (written
< sectors
* 512) {
1562 int n
= sectors
*512 - written
;
1565 if (read(from
, buf
, n
) != n
)
1567 if (write(to
, buf
, n
) != n
)
1578 static void detail_super_imsm(struct supertype
*st
, char *homehost
)
1583 getinfo_super_imsm(st
, &info
, NULL
);
1584 fname_from_uuid(st
, &info
, nbuf
, ':');
1585 printf("\n UUID : %s\n", nbuf
+ 5);
1588 static void brief_detail_super_imsm(struct supertype
*st
)
1592 getinfo_super_imsm(st
, &info
, NULL
);
1593 fname_from_uuid(st
, &info
, nbuf
, ':');
1594 printf(" UUID=%s", nbuf
+ 5);
1597 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
);
1598 static void fd2devname(int fd
, char *name
);
1600 static int ahci_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
1602 /* dump an unsorted list of devices attached to AHCI Intel storage
1603 * controller, as well as non-connected ports
1605 int hba_len
= strlen(hba_path
) + 1;
1610 unsigned long port_mask
= (1 << port_count
) - 1;
1612 if (port_count
> (int)sizeof(port_mask
) * 8) {
1614 pr_err("port_count %d out of range\n", port_count
);
1618 /* scroll through /sys/dev/block looking for devices attached to
1621 dir
= opendir("/sys/dev/block");
1622 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
1633 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
1635 path
= devt_to_devpath(makedev(major
, minor
));
1638 if (!path_attached_to_hba(path
, hba_path
)) {
1644 /* retrieve the scsi device type */
1645 if (asprintf(&device
, "/sys/dev/block/%d:%d/device/xxxxxxx", major
, minor
) < 0) {
1647 pr_err("failed to allocate 'device'\n");
1651 sprintf(device
, "/sys/dev/block/%d:%d/device/type", major
, minor
);
1652 if (load_sys(device
, buf
) != 0) {
1654 pr_err("failed to read device type for %s\n",
1660 type
= strtoul(buf
, NULL
, 10);
1662 /* if it's not a disk print the vendor and model */
1663 if (!(type
== 0 || type
== 7 || type
== 14)) {
1666 sprintf(device
, "/sys/dev/block/%d:%d/device/vendor", major
, minor
);
1667 if (load_sys(device
, buf
) == 0) {
1668 strncpy(vendor
, buf
, sizeof(vendor
));
1669 vendor
[sizeof(vendor
) - 1] = '\0';
1670 c
= (char *) &vendor
[sizeof(vendor
) - 1];
1671 while (isspace(*c
) || *c
== '\0')
1675 sprintf(device
, "/sys/dev/block/%d:%d/device/model", major
, minor
);
1676 if (load_sys(device
, buf
) == 0) {
1677 strncpy(model
, buf
, sizeof(model
));
1678 model
[sizeof(model
) - 1] = '\0';
1679 c
= (char *) &model
[sizeof(model
) - 1];
1680 while (isspace(*c
) || *c
== '\0')
1684 if (vendor
[0] && model
[0])
1685 sprintf(buf
, "%.64s %.64s", vendor
, model
);
1687 switch (type
) { /* numbers from hald/linux/device.c */
1688 case 1: sprintf(buf
, "tape"); break;
1689 case 2: sprintf(buf
, "printer"); break;
1690 case 3: sprintf(buf
, "processor"); break;
1692 case 5: sprintf(buf
, "cdrom"); break;
1693 case 6: sprintf(buf
, "scanner"); break;
1694 case 8: sprintf(buf
, "media_changer"); break;
1695 case 9: sprintf(buf
, "comm"); break;
1696 case 12: sprintf(buf
, "raid"); break;
1697 default: sprintf(buf
, "unknown");
1703 /* chop device path to 'host%d' and calculate the port number */
1704 c
= strchr(&path
[hba_len
], '/');
1707 pr_err("%s - invalid path name\n", path
+ hba_len
);
1712 if ((sscanf(&path
[hba_len
], "ata%d", &port
) == 1) ||
1713 ((sscanf(&path
[hba_len
], "host%d", &port
) == 1)))
1717 *c
= '/'; /* repair the full string */
1718 pr_err("failed to determine port number for %s\n",
1725 /* mark this port as used */
1726 port_mask
&= ~(1 << port
);
1728 /* print out the device information */
1730 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
1734 fd
= dev_open(ent
->d_name
, O_RDONLY
);
1736 printf(" Port%d : - disk info unavailable -\n", port
);
1738 fd2devname(fd
, buf
);
1739 printf(" Port%d : %s", port
, buf
);
1740 if (imsm_read_serial(fd
, NULL
, (__u8
*) buf
) == 0)
1741 printf(" (%.*s)\n", MAX_RAID_SERIAL_LEN
, buf
);
1756 for (i
= 0; i
< port_count
; i
++)
1757 if (port_mask
& (1 << i
))
1758 printf(" Port%d : - no device attached -\n", i
);
1764 static void print_found_intel_controllers(struct sys_dev
*elem
)
1766 for (; elem
; elem
= elem
->next
) {
1767 pr_err("found Intel(R) ");
1768 if (elem
->type
== SYS_DEV_SATA
)
1769 fprintf(stderr
, "SATA ");
1770 else if (elem
->type
== SYS_DEV_SAS
)
1771 fprintf(stderr
, "SAS ");
1772 else if (elem
->type
== SYS_DEV_NVME
)
1773 fprintf(stderr
, "NVMe ");
1774 fprintf(stderr
, "RAID controller");
1776 fprintf(stderr
, " at %s", elem
->pci_id
);
1777 fprintf(stderr
, ".\n");
1782 static int ahci_get_port_count(const char *hba_path
, int *port_count
)
1789 if ((dir
= opendir(hba_path
)) == NULL
)
1792 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
1795 if ((sscanf(ent
->d_name
, "ata%d", &host
) != 1) &&
1796 ((sscanf(ent
->d_name
, "host%d", &host
) != 1)))
1798 if (*port_count
== 0)
1800 else if (host
< host_base
)
1803 if (host
+ 1 > *port_count
+ host_base
)
1804 *port_count
= host
+ 1 - host_base
;
1810 static void print_imsm_capability(const struct imsm_orom
*orom
)
1812 printf(" Platform : Intel(R) ");
1813 if (orom
->capabilities
== 0 && orom
->driver_features
== 0)
1814 printf("Matrix Storage Manager\n");
1816 printf("Rapid Storage Technology%s\n",
1817 imsm_orom_is_enterprise(orom
) ? " enterprise" : "");
1818 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
1819 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
,
1820 orom
->minor_ver
, orom
->hotfix_ver
, orom
->build
);
1821 printf(" RAID Levels :%s%s%s%s%s\n",
1822 imsm_orom_has_raid0(orom
) ? " raid0" : "",
1823 imsm_orom_has_raid1(orom
) ? " raid1" : "",
1824 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
1825 imsm_orom_has_raid10(orom
) ? " raid10" : "",
1826 imsm_orom_has_raid5(orom
) ? " raid5" : "");
1827 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1828 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
1829 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
1830 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
1831 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
1832 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
1833 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
1834 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
1835 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
1836 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
1837 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
1838 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
1839 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
1840 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
1841 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
1842 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
1843 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
1844 printf(" 2TB volumes :%s supported\n",
1845 (orom
->attr
& IMSM_OROM_ATTR_2TB
)?"":" not");
1846 printf(" 2TB disks :%s supported\n",
1847 (orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
)?"":" not");
1848 printf(" Max Disks : %d\n", orom
->tds
);
1849 printf(" Max Volumes : %d per array, %d per %s\n",
1850 orom
->vpa
, orom
->vphba
,
1851 imsm_orom_is_nvme(orom
) ? "platform" : "controller");
1855 static void print_imsm_capability_export(const struct imsm_orom
*orom
)
1857 printf("MD_FIRMWARE_TYPE=imsm\n");
1858 if (orom
->major_ver
|| orom
->minor_ver
|| orom
->hotfix_ver
|| orom
->build
)
1859 printf("IMSM_VERSION=%d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
1860 orom
->hotfix_ver
, orom
->build
);
1861 printf("IMSM_SUPPORTED_RAID_LEVELS=%s%s%s%s%s\n",
1862 imsm_orom_has_raid0(orom
) ? "raid0 " : "",
1863 imsm_orom_has_raid1(orom
) ? "raid1 " : "",
1864 imsm_orom_has_raid1e(orom
) ? "raid1e " : "",
1865 imsm_orom_has_raid5(orom
) ? "raid10 " : "",
1866 imsm_orom_has_raid10(orom
) ? "raid5 " : "");
1867 printf("IMSM_SUPPORTED_CHUNK_SIZES=%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1868 imsm_orom_has_chunk(orom
, 2) ? "2k " : "",
1869 imsm_orom_has_chunk(orom
, 4) ? "4k " : "",
1870 imsm_orom_has_chunk(orom
, 8) ? "8k " : "",
1871 imsm_orom_has_chunk(orom
, 16) ? "16k " : "",
1872 imsm_orom_has_chunk(orom
, 32) ? "32k " : "",
1873 imsm_orom_has_chunk(orom
, 64) ? "64k " : "",
1874 imsm_orom_has_chunk(orom
, 128) ? "128k " : "",
1875 imsm_orom_has_chunk(orom
, 256) ? "256k " : "",
1876 imsm_orom_has_chunk(orom
, 512) ? "512k " : "",
1877 imsm_orom_has_chunk(orom
, 1024*1) ? "1M " : "",
1878 imsm_orom_has_chunk(orom
, 1024*2) ? "2M " : "",
1879 imsm_orom_has_chunk(orom
, 1024*4) ? "4M " : "",
1880 imsm_orom_has_chunk(orom
, 1024*8) ? "8M " : "",
1881 imsm_orom_has_chunk(orom
, 1024*16) ? "16M " : "",
1882 imsm_orom_has_chunk(orom
, 1024*32) ? "32M " : "",
1883 imsm_orom_has_chunk(orom
, 1024*64) ? "64M " : "");
1884 printf("IMSM_2TB_VOLUMES=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB
) ? "yes" : "no");
1885 printf("IMSM_2TB_DISKS=%s\n",(orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) ? "yes" : "no");
1886 printf("IMSM_MAX_DISKS=%d\n",orom
->tds
);
1887 printf("IMSM_MAX_VOLUMES_PER_ARRAY=%d\n",orom
->vpa
);
1888 printf("IMSM_MAX_VOLUMES_PER_CONTROLLER=%d\n",orom
->vphba
);
1891 static int detail_platform_imsm(int verbose
, int enumerate_only
, char *controller_path
)
1893 /* There are two components to imsm platform support, the ahci SATA
1894 * controller and the option-rom. To find the SATA controller we
1895 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
1896 * controller with the Intel vendor id is present. This approach
1897 * allows mdadm to leverage the kernel's ahci detection logic, with the
1898 * caveat that if ahci.ko is not loaded mdadm will not be able to
1899 * detect platform raid capabilities. The option-rom resides in a
1900 * platform "Adapter ROM". We scan for its signature to retrieve the
1901 * platform capabilities. If raid support is disabled in the BIOS the
1902 * option-rom capability structure will not be available.
1904 struct sys_dev
*list
, *hba
;
1909 if (enumerate_only
) {
1910 if (check_env("IMSM_NO_PLATFORM"))
1912 list
= find_intel_devices();
1915 for (hba
= list
; hba
; hba
= hba
->next
) {
1916 if (find_imsm_capability(hba
)) {
1926 list
= find_intel_devices();
1929 pr_err("no active Intel(R) RAID "
1930 "controller found.\n");
1932 } else if (verbose
> 0)
1933 print_found_intel_controllers(list
);
1935 for (hba
= list
; hba
; hba
= hba
->next
) {
1936 if (controller_path
&& (compare_paths(hba
->path
, controller_path
) != 0))
1938 if (!find_imsm_capability(hba
)) {
1939 pr_err("imsm capabilities not found for controller: %s (type %s)\n",
1940 hba
->path
, get_sys_dev_type(hba
->type
));
1946 if (controller_path
&& result
== 1) {
1947 pr_err("no active Intel(R) RAID controller found under %s\n",
1952 const struct orom_entry
*oroms
= get_oroms();
1955 for (i
= 0; i
< SYS_DEV_MAX
&& oroms
[i
].devid_list
; i
++) {
1956 print_imsm_capability(&oroms
[i
].orom
);
1958 if (imsm_orom_is_nvme(&oroms
[i
].orom
)) {
1959 for (hba
= list
; hba
; hba
= hba
->next
) {
1960 if (hba
->type
== SYS_DEV_NVME
)
1961 printf(" NVMe Device : %s\n", hba
->path
);
1966 struct devid_list
*devid
;
1967 for (devid
= oroms
[i
].devid_list
; devid
; devid
= devid
->next
) {
1968 hba
= device_by_id(devid
->devid
);
1972 printf(" I/O Controller : %s (%s)\n",
1973 hba
->path
, get_sys_dev_type(hba
->type
));
1974 if (hba
->type
== SYS_DEV_SATA
) {
1975 host_base
= ahci_get_port_count(hba
->path
, &port_count
);
1976 if (ahci_enumerate_ports(hba
->path
, port_count
, host_base
, verbose
)) {
1978 pr_err("failed to enumerate "
1979 "ports on SATA controller at %s.\n", hba
->pci_id
);
1990 static int export_detail_platform_imsm(int verbose
, char *controller_path
)
1992 struct sys_dev
*list
, *hba
;
1995 list
= find_intel_devices();
1998 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_INTEL_DEVICES\n");
2003 for (hba
= list
; hba
; hba
= hba
->next
) {
2004 if (controller_path
&& (compare_paths(hba
->path
,controller_path
) != 0))
2006 if (!find_imsm_capability(hba
) && verbose
> 0)
2007 pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_IMSM_CAPABLE_DEVICE_UNDER_%s\n", hba
->path
);
2012 const struct orom_entry
*oroms
= get_oroms();
2015 for (i
= 0; i
< SYS_DEV_MAX
&& oroms
[i
].devid_list
; i
++)
2016 print_imsm_capability_export(&oroms
[i
].orom
);
2023 static int match_home_imsm(struct supertype
*st
, char *homehost
)
2025 /* the imsm metadata format does not specify any host
2026 * identification information. We return -1 since we can never
2027 * confirm nor deny whether a given array is "meant" for this
2028 * host. We rely on compare_super and the 'family_num' fields to
2029 * exclude member disks that do not belong, and we rely on
2030 * mdadm.conf to specify the arrays that should be assembled.
2031 * Auto-assembly may still pick up "foreign" arrays.
2037 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
2039 /* The uuid returned here is used for:
2040 * uuid to put into bitmap file (Create, Grow)
2041 * uuid for backup header when saving critical section (Grow)
2042 * comparing uuids when re-adding a device into an array
2043 * In these cases the uuid required is that of the data-array,
2044 * not the device-set.
2045 * uuid to recognise same set when adding a missing device back
2046 * to an array. This is a uuid for the device-set.
2048 * For each of these we can make do with a truncated
2049 * or hashed uuid rather than the original, as long as
2051 * In each case the uuid required is that of the data-array,
2052 * not the device-set.
2054 /* imsm does not track uuid's so we synthesis one using sha1 on
2055 * - The signature (Which is constant for all imsm array, but no matter)
2056 * - the orig_family_num of the container
2057 * - the index number of the volume
2058 * - the 'serial' number of the volume.
2059 * Hopefully these are all constant.
2061 struct intel_super
*super
= st
->sb
;
2064 struct sha1_ctx ctx
;
2065 struct imsm_dev
*dev
= NULL
;
2068 /* some mdadm versions failed to set ->orig_family_num, in which
2069 * case fall back to ->family_num. orig_family_num will be
2070 * fixed up with the first metadata update.
2072 family_num
= super
->anchor
->orig_family_num
;
2073 if (family_num
== 0)
2074 family_num
= super
->anchor
->family_num
;
2075 sha1_init_ctx(&ctx
);
2076 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
2077 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
2078 if (super
->current_vol
>= 0)
2079 dev
= get_imsm_dev(super
, super
->current_vol
);
2081 __u32 vol
= super
->current_vol
;
2082 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
2083 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
2085 sha1_finish_ctx(&ctx
, buf
);
2086 memcpy(uuid
, buf
, 4*4);
2091 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
2093 __u8
*v
= get_imsm_version(mpb
);
2094 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
2095 char major
[] = { 0, 0, 0 };
2096 char minor
[] = { 0 ,0, 0 };
2097 char patch
[] = { 0, 0, 0 };
2098 char *ver_parse
[] = { major
, minor
, patch
};
2102 while (*v
!= '\0' && v
< end
) {
2103 if (*v
!= '.' && j
< 2)
2104 ver_parse
[i
][j
++] = *v
;
2112 *m
= strtol(minor
, NULL
, 0);
2113 *p
= strtol(patch
, NULL
, 0);
2117 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
2119 /* migr_strip_size when repairing or initializing parity */
2120 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2121 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2123 switch (get_imsm_raid_level(map
)) {
2128 return 128*1024 >> 9;
2132 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
2134 /* migr_strip_size when rebuilding a degraded disk, no idea why
2135 * this is different than migr_strip_size_resync(), but it's good
2138 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2139 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2141 switch (get_imsm_raid_level(map
)) {
2144 if (map
->num_members
% map
->num_domains
== 0)
2145 return 128*1024 >> 9;
2149 return max((__u32
) 64*1024 >> 9, chunk
);
2151 return 128*1024 >> 9;
2155 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
2157 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2158 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2159 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
2160 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
2162 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
2165 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
2167 struct imsm_map
*lo
= get_imsm_map(dev
, MAP_0
);
2168 int level
= get_imsm_raid_level(lo
);
2170 if (level
== 1 || level
== 10) {
2171 struct imsm_map
*hi
= get_imsm_map(dev
, MAP_1
);
2173 return hi
->num_domains
;
2175 return num_stripes_per_unit_resync(dev
);
2178 static __u8
imsm_num_data_members(struct imsm_dev
*dev
, int second_map
)
2180 /* named 'imsm_' because raid0, raid1 and raid10
2181 * counter-intuitively have the same number of data disks
2183 struct imsm_map
*map
= get_imsm_map(dev
, second_map
);
2185 switch (get_imsm_raid_level(map
)) {
2187 return map
->num_members
;
2191 return map
->num_members
/2;
2193 return map
->num_members
- 1;
2195 dprintf("%s: unsupported raid level\n", __func__
);
2200 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
2202 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2203 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2205 switch(get_imsm_raid_level(map
)) {
2208 return chunk
* map
->num_domains
;
2210 return chunk
* map
->num_members
;
2216 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
2218 struct imsm_map
*map
= get_imsm_map(dev
, MAP_1
);
2219 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
2220 __u32 strip
= block
/ chunk
;
2222 switch (get_imsm_raid_level(map
)) {
2225 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
2226 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
2228 return vol_stripe
* chunk
+ block
% chunk
;
2230 __u32 stripe
= strip
/ (map
->num_members
- 1);
2232 return stripe
* chunk
+ block
% chunk
;
2239 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
2240 struct imsm_dev
*dev
)
2242 /* calculate the conversion factor between per member 'blocks'
2243 * (md/{resync,rebuild}_start) and imsm migration units, return
2244 * 0 for the 'not migrating' and 'unsupported migration' cases
2246 if (!dev
->vol
.migr_state
)
2249 switch (migr_type(dev
)) {
2250 case MIGR_GEN_MIGR
: {
2251 struct migr_record
*migr_rec
= super
->migr_rec
;
2252 return __le32_to_cpu(migr_rec
->blocks_per_unit
);
2257 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2258 __u32 stripes_per_unit
;
2259 __u32 blocks_per_unit
;
2268 /* yes, this is really the translation of migr_units to
2269 * per-member blocks in the 'resync' case
2271 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
2272 migr_chunk
= migr_strip_blocks_resync(dev
);
2273 disks
= imsm_num_data_members(dev
, MAP_0
);
2274 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
2275 stripe
= __le16_to_cpu(map
->blocks_per_strip
) * disks
;
2276 segment
= blocks_per_unit
/ stripe
;
2277 block_rel
= blocks_per_unit
- segment
* stripe
;
2278 parity_depth
= parity_segment_depth(dev
);
2279 block_map
= map_migr_block(dev
, block_rel
);
2280 return block_map
+ parity_depth
* segment
;
2282 case MIGR_REBUILD
: {
2283 __u32 stripes_per_unit
;
2286 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
2287 migr_chunk
= migr_strip_blocks_rebuild(dev
);
2288 return migr_chunk
* stripes_per_unit
;
2290 case MIGR_STATE_CHANGE
:
2296 static int imsm_level_to_layout(int level
)
2304 return ALGORITHM_LEFT_ASYMMETRIC
;
2311 /*******************************************************************************
2312 * Function: read_imsm_migr_rec
2313 * Description: Function reads imsm migration record from last sector of disk
2315 * fd : disk descriptor
2316 * super : metadata info
2320 ******************************************************************************/
2321 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
)
2324 unsigned long long dsize
;
2326 get_dev_size(fd
, NULL
, &dsize
);
2327 if (lseek64(fd
, dsize
- MIGR_REC_POSITION
, SEEK_SET
) < 0) {
2328 pr_err("Cannot seek to anchor block: %s\n",
2332 if (read(fd
, super
->migr_rec_buf
, MIGR_REC_BUF_SIZE
) !=
2333 MIGR_REC_BUF_SIZE
) {
2334 pr_err("Cannot read migr record block: %s\n",
2344 static struct imsm_dev
*imsm_get_device_during_migration(
2345 struct intel_super
*super
)
2348 struct intel_dev
*dv
;
2350 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
2351 if (is_gen_migration(dv
->dev
))
2357 /*******************************************************************************
2358 * Function: load_imsm_migr_rec
2359 * Description: Function reads imsm migration record (it is stored at the last
2362 * super : imsm internal array info
2363 * info : general array info
2367 * -2 : no migration in progress
2368 ******************************************************************************/
2369 static int load_imsm_migr_rec(struct intel_super
*super
, struct mdinfo
*info
)
2372 struct dl
*dl
= NULL
;
2376 struct imsm_dev
*dev
;
2377 struct imsm_map
*map
= NULL
;
2380 /* find map under migration */
2381 dev
= imsm_get_device_during_migration(super
);
2382 /* nothing to load,no migration in progress?
2386 map
= get_imsm_map(dev
, MAP_0
);
2389 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
2390 /* skip spare and failed disks
2392 if (sd
->disk
.raid_disk
< 0)
2394 /* read only from one of the first two slots */
2396 slot
= get_imsm_disk_slot(map
,
2397 sd
->disk
.raid_disk
);
2398 if ((map
== NULL
) || (slot
> 1) || (slot
< 0))
2401 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
2402 fd
= dev_open(nm
, O_RDONLY
);
2408 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
2409 /* skip spare and failed disks
2413 /* read only from one of the first two slots */
2415 slot
= get_imsm_disk_slot(map
, dl
->index
);
2416 if ((map
== NULL
) || (slot
> 1) || (slot
< 0))
2418 sprintf(nm
, "%d:%d", dl
->major
, dl
->minor
);
2419 fd
= dev_open(nm
, O_RDONLY
);
2426 retval
= read_imsm_migr_rec(fd
, super
);
2435 /*******************************************************************************
2436 * function: imsm_create_metadata_checkpoint_update
2437 * Description: It creates update for checkpoint change.
2439 * super : imsm internal array info
2440 * u : pointer to prepared update
2443 * If length is equal to 0, input pointer u contains no update
2444 ******************************************************************************/
2445 static int imsm_create_metadata_checkpoint_update(
2446 struct intel_super
*super
,
2447 struct imsm_update_general_migration_checkpoint
**u
)
2450 int update_memory_size
= 0;
2452 dprintf("imsm_create_metadata_checkpoint_update(enter)\n");
2458 /* size of all update data without anchor */
2459 update_memory_size
=
2460 sizeof(struct imsm_update_general_migration_checkpoint
);
2462 *u
= xcalloc(1, update_memory_size
);
2464 dprintf("error: cannot get memory for "
2465 "imsm_create_metadata_checkpoint_update update\n");
2468 (*u
)->type
= update_general_migration_checkpoint
;
2469 (*u
)->curr_migr_unit
= __le32_to_cpu(super
->migr_rec
->curr_migr_unit
);
2470 dprintf("imsm_create_metadata_checkpoint_update: prepared for %u\n",
2471 (*u
)->curr_migr_unit
);
2473 return update_memory_size
;
2476 static void imsm_update_metadata_locally(struct supertype
*st
,
2477 void *buf
, int len
);
2479 /*******************************************************************************
2480 * Function: write_imsm_migr_rec
2481 * Description: Function writes imsm migration record
2482 * (at the last sector of disk)
2484 * super : imsm internal array info
2488 ******************************************************************************/
2489 static int write_imsm_migr_rec(struct supertype
*st
)
2491 struct intel_super
*super
= st
->sb
;
2492 unsigned long long dsize
;
2498 struct imsm_update_general_migration_checkpoint
*u
;
2499 struct imsm_dev
*dev
;
2500 struct imsm_map
*map
= NULL
;
2502 /* find map under migration */
2503 dev
= imsm_get_device_during_migration(super
);
2504 /* if no migration, write buffer anyway to clear migr_record
2505 * on disk based on first available device
2508 dev
= get_imsm_dev(super
, super
->current_vol
< 0 ? 0 :
2509 super
->current_vol
);
2511 map
= get_imsm_map(dev
, MAP_0
);
2513 for (sd
= super
->disks
; sd
; sd
= sd
->next
) {
2516 /* skip failed and spare devices */
2519 /* write to 2 first slots only */
2521 slot
= get_imsm_disk_slot(map
, sd
->index
);
2522 if ((map
== NULL
) || (slot
> 1) || (slot
< 0))
2525 sprintf(nm
, "%d:%d", sd
->major
, sd
->minor
);
2526 fd
= dev_open(nm
, O_RDWR
);
2529 get_dev_size(fd
, NULL
, &dsize
);
2530 if (lseek64(fd
, dsize
- MIGR_REC_POSITION
, SEEK_SET
) < 0) {
2531 pr_err("Cannot seek to anchor block: %s\n",
2535 if (write(fd
, super
->migr_rec_buf
, MIGR_REC_BUF_SIZE
) !=
2536 MIGR_REC_BUF_SIZE
) {
2537 pr_err("Cannot write migr record block: %s\n",
2544 /* update checkpoint information in metadata */
2545 len
= imsm_create_metadata_checkpoint_update(super
, &u
);
2548 dprintf("imsm: Cannot prepare update\n");
2551 /* update metadata locally */
2552 imsm_update_metadata_locally(st
, u
, len
);
2553 /* and possibly remotely */
2554 if (st
->update_tail
) {
2555 append_metadata_update(st
, u
, len
);
2556 /* during reshape we do all work inside metadata handler
2557 * manage_reshape(), so metadata update has to be triggered
2560 flush_metadata_updates(st
);
2561 st
->update_tail
= &st
->updates
;
2571 #endif /* MDASSEMBLE */
2573 /* spare/missing disks activations are not allowe when
2574 * array/container performs reshape operation, because
2575 * all arrays in container works on the same disks set
2577 int imsm_reshape_blocks_arrays_changes(struct intel_super
*super
)
2580 struct intel_dev
*i_dev
;
2581 struct imsm_dev
*dev
;
2583 /* check whole container
2585 for (i_dev
= super
->devlist
; i_dev
; i_dev
= i_dev
->next
) {
2587 if (is_gen_migration(dev
)) {
2588 /* No repair during any migration in container
2596 static unsigned long long imsm_component_size_aligment_check(int level
,
2598 unsigned long long component_size
)
2600 unsigned int component_size_alligment
;
2602 /* check component size aligment
2604 component_size_alligment
= component_size
% (chunk_size
/512);
2606 dprintf("imsm_component_size_aligment_check(Level: %i, "
2607 "chunk_size = %i, component_size = %llu), "
2608 "component_size_alligment = %u\n",
2609 level
, chunk_size
, component_size
,
2610 component_size_alligment
);
2612 if (component_size_alligment
&& (level
!= 1) && (level
!= UnSet
)) {
2613 dprintf("imsm: reported component size alligned from %llu ",
2615 component_size
-= component_size_alligment
;
2616 dprintf("to %llu (%i).\n",
2617 component_size
, component_size_alligment
);
2620 return component_size
;
2623 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
2625 struct intel_super
*super
= st
->sb
;
2626 struct migr_record
*migr_rec
= super
->migr_rec
;
2627 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
2628 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
2629 struct imsm_map
*prev_map
= get_imsm_map(dev
, MAP_1
);
2630 struct imsm_map
*map_to_analyse
= map
;
2632 int map_disks
= info
->array
.raid_disks
;
2634 memset(info
, 0, sizeof(*info
));
2636 map_to_analyse
= prev_map
;
2638 dl
= super
->current_disk
;
2640 info
->container_member
= super
->current_vol
;
2641 info
->array
.raid_disks
= map
->num_members
;
2642 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
2643 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
2644 info
->array
.md_minor
= -1;
2645 info
->array
.ctime
= 0;
2646 info
->array
.utime
= 0;
2647 info
->array
.chunk_size
=
2648 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
2649 info
->array
.state
= !dev
->vol
.dirty
;
2650 info
->custom_array_size
= __le32_to_cpu(dev
->size_high
);
2651 info
->custom_array_size
<<= 32;
2652 info
->custom_array_size
|= __le32_to_cpu(dev
->size_low
);
2653 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
2655 if (is_gen_migration(dev
)) {
2656 info
->reshape_active
= 1;
2657 info
->new_level
= get_imsm_raid_level(map
);
2658 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
2659 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
2660 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
2661 if (info
->delta_disks
) {
2662 /* this needs to be applied to every array
2665 info
->reshape_active
= CONTAINER_RESHAPE
;
2667 /* We shape information that we give to md might have to be
2668 * modify to cope with md's requirement for reshaping arrays.
2669 * For example, when reshaping a RAID0, md requires it to be
2670 * presented as a degraded RAID4.
2671 * Also if a RAID0 is migrating to a RAID5 we need to specify
2672 * the array as already being RAID5, but the 'before' layout
2673 * is a RAID4-like layout.
2675 switch (info
->array
.level
) {
2677 switch(info
->new_level
) {
2679 /* conversion is happening as RAID4 */
2680 info
->array
.level
= 4;
2681 info
->array
.raid_disks
+= 1;
2684 /* conversion is happening as RAID5 */
2685 info
->array
.level
= 5;
2686 info
->array
.layout
= ALGORITHM_PARITY_N
;
2687 info
->delta_disks
-= 1;
2690 /* FIXME error message */
2691 info
->array
.level
= UnSet
;
2697 info
->new_level
= UnSet
;
2698 info
->new_layout
= UnSet
;
2699 info
->new_chunk
= info
->array
.chunk_size
;
2700 info
->delta_disks
= 0;
2704 info
->disk
.major
= dl
->major
;
2705 info
->disk
.minor
= dl
->minor
;
2706 info
->disk
.number
= dl
->index
;
2707 info
->disk
.raid_disk
= get_imsm_disk_slot(map_to_analyse
,
2711 info
->data_offset
= pba_of_lba0(map_to_analyse
);
2712 info
->component_size
= blocks_per_member(map_to_analyse
);
2714 info
->component_size
= imsm_component_size_aligment_check(
2716 info
->array
.chunk_size
,
2717 info
->component_size
);
2719 memset(info
->uuid
, 0, sizeof(info
->uuid
));
2720 info
->recovery_start
= MaxSector
;
2722 info
->reshape_progress
= 0;
2723 info
->resync_start
= MaxSector
;
2724 if ((map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
2726 imsm_reshape_blocks_arrays_changes(super
) == 0) {
2727 info
->resync_start
= 0;
2729 if (dev
->vol
.migr_state
) {
2730 switch (migr_type(dev
)) {
2733 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
2735 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
2737 info
->resync_start
= blocks_per_unit
* units
;
2740 case MIGR_GEN_MIGR
: {
2741 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
2743 __u64 units
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
2744 unsigned long long array_blocks
;
2747 if (__le32_to_cpu(migr_rec
->ascending_migr
) &&
2749 (__le32_to_cpu(migr_rec
->num_migr_units
)-1)) &&
2750 (super
->migr_rec
->rec_status
==
2751 __cpu_to_le32(UNIT_SRC_IN_CP_AREA
)))
2754 info
->reshape_progress
= blocks_per_unit
* units
;
2756 dprintf("IMSM: General Migration checkpoint : %llu "
2757 "(%llu) -> read reshape progress : %llu\n",
2758 (unsigned long long)units
,
2759 (unsigned long long)blocks_per_unit
,
2760 info
->reshape_progress
);
2762 used_disks
= imsm_num_data_members(dev
, MAP_1
);
2763 if (used_disks
> 0) {
2764 array_blocks
= blocks_per_member(map
) *
2766 /* round array size down to closest MB
2768 info
->custom_array_size
= (array_blocks
2769 >> SECT_PER_MB_SHIFT
)
2770 << SECT_PER_MB_SHIFT
;
2774 /* we could emulate the checkpointing of
2775 * 'sync_action=check' migrations, but for now
2776 * we just immediately complete them
2779 /* this is handled by container_content_imsm() */
2780 case MIGR_STATE_CHANGE
:
2781 /* FIXME handle other migrations */
2783 /* we are not dirty, so... */
2784 info
->resync_start
= MaxSector
;
2788 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
2789 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
2791 info
->array
.major_version
= -1;
2792 info
->array
.minor_version
= -2;
2793 sprintf(info
->text_version
, "/%s/%d", st
->container_devnm
, info
->container_member
);
2794 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
2795 uuid_from_super_imsm(st
, info
->uuid
);
2799 for (i
=0; i
<map_disks
; i
++) {
2801 if (i
< info
->array
.raid_disks
) {
2802 struct imsm_disk
*dsk
;
2803 j
= get_imsm_disk_idx(dev
, i
, MAP_X
);
2804 dsk
= get_imsm_disk(super
, j
);
2805 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
2812 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
2813 int failed
, int look_in_map
);
2815 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
2819 static void manage_second_map(struct intel_super
*super
, struct imsm_dev
*dev
)
2821 if (is_gen_migration(dev
)) {
2824 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
2826 failed
= imsm_count_failed(super
, dev
, MAP_1
);
2827 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_1
);
2828 if (map2
->map_state
!= map_state
) {
2829 map2
->map_state
= map_state
;
2830 super
->updates_pending
++;
2836 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
2840 for (d
= super
->missing
; d
; d
= d
->next
)
2841 if (d
->index
== index
)
2846 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
2848 struct intel_super
*super
= st
->sb
;
2849 struct imsm_disk
*disk
;
2850 int map_disks
= info
->array
.raid_disks
;
2851 int max_enough
= -1;
2853 struct imsm_super
*mpb
;
2855 if (super
->current_vol
>= 0) {
2856 getinfo_super_imsm_volume(st
, info
, map
);
2859 memset(info
, 0, sizeof(*info
));
2861 /* Set raid_disks to zero so that Assemble will always pull in valid
2864 info
->array
.raid_disks
= 0;
2865 info
->array
.level
= LEVEL_CONTAINER
;
2866 info
->array
.layout
= 0;
2867 info
->array
.md_minor
= -1;
2868 info
->array
.ctime
= 0; /* N/A for imsm */
2869 info
->array
.utime
= 0;
2870 info
->array
.chunk_size
= 0;
2872 info
->disk
.major
= 0;
2873 info
->disk
.minor
= 0;
2874 info
->disk
.raid_disk
= -1;
2875 info
->reshape_active
= 0;
2876 info
->array
.major_version
= -1;
2877 info
->array
.minor_version
= -2;
2878 strcpy(info
->text_version
, "imsm");
2879 info
->safe_mode_delay
= 0;
2880 info
->disk
.number
= -1;
2881 info
->disk
.state
= 0;
2883 info
->recovery_start
= MaxSector
;
2884 info
->recovery_blocked
= imsm_reshape_blocks_arrays_changes(st
->sb
);
2886 /* do we have the all the insync disks that we expect? */
2887 mpb
= super
->anchor
;
2889 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
2890 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
2891 int failed
, enough
, j
, missing
= 0;
2892 struct imsm_map
*map
;
2895 failed
= imsm_count_failed(super
, dev
, MAP_0
);
2896 state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
2897 map
= get_imsm_map(dev
, MAP_0
);
2899 /* any newly missing disks?
2900 * (catches single-degraded vs double-degraded)
2902 for (j
= 0; j
< map
->num_members
; j
++) {
2903 __u32 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_0
);
2904 __u32 idx
= ord_to_idx(ord
);
2906 if (!(ord
& IMSM_ORD_REBUILD
) &&
2907 get_imsm_missing(super
, idx
)) {
2913 if (state
== IMSM_T_STATE_FAILED
)
2915 else if (state
== IMSM_T_STATE_DEGRADED
&&
2916 (state
!= map
->map_state
|| missing
))
2918 else /* we're normal, or already degraded */
2920 if (is_gen_migration(dev
) && missing
) {
2921 /* during general migration we need all disks
2922 * that process is running on.
2923 * No new missing disk is allowed.
2927 /* no more checks necessary
2931 /* in the missing/failed disk case check to see
2932 * if at least one array is runnable
2934 max_enough
= max(max_enough
, enough
);
2936 dprintf("%s: enough: %d\n", __func__
, max_enough
);
2937 info
->container_enough
= max_enough
;
2940 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
2942 disk
= &super
->disks
->disk
;
2943 info
->data_offset
= total_blocks(&super
->disks
->disk
) - reserved
;
2944 info
->component_size
= reserved
;
2945 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
2946 /* we don't change info->disk.raid_disk here because
2947 * this state will be finalized in mdmon after we have
2948 * found the 'most fresh' version of the metadata
2950 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
2951 info
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
2954 /* only call uuid_from_super_imsm when this disk is part of a populated container,
2955 * ->compare_super may have updated the 'num_raid_devs' field for spares
2957 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
2958 uuid_from_super_imsm(st
, info
->uuid
);
2960 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
2962 /* I don't know how to compute 'map' on imsm, so use safe default */
2965 for (i
= 0; i
< map_disks
; i
++)
2971 /* allocates memory and fills disk in mdinfo structure
2972 * for each disk in array */
2973 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
2975 struct mdinfo
*mddev
= NULL
;
2976 struct intel_super
*super
= st
->sb
;
2977 struct imsm_disk
*disk
;
2980 if (!super
|| !super
->disks
)
2983 mddev
= xcalloc(1, sizeof(*mddev
));
2987 tmp
= xcalloc(1, sizeof(*tmp
));
2989 tmp
->next
= mddev
->devs
;
2991 tmp
->disk
.number
= count
++;
2992 tmp
->disk
.major
= dl
->major
;
2993 tmp
->disk
.minor
= dl
->minor
;
2994 tmp
->disk
.state
= is_configured(disk
) ?
2995 (1 << MD_DISK_ACTIVE
) : 0;
2996 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
2997 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
2998 tmp
->disk
.raid_disk
= -1;
3004 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
3005 char *update
, char *devname
, int verbose
,
3006 int uuid_set
, char *homehost
)
3008 /* For 'assemble' and 'force' we need to return non-zero if any
3009 * change was made. For others, the return value is ignored.
3010 * Update options are:
3011 * force-one : This device looks a bit old but needs to be included,
3012 * update age info appropriately.
3013 * assemble: clear any 'faulty' flag to allow this device to
3015 * force-array: Array is degraded but being forced, mark it clean
3016 * if that will be needed to assemble it.
3018 * newdev: not used ????
3019 * grow: Array has gained a new device - this is currently for
3021 * resync: mark as dirty so a resync will happen.
3022 * name: update the name - preserving the homehost
3023 * uuid: Change the uuid of the array to match watch is given
3025 * Following are not relevant for this imsm:
3026 * sparc2.2 : update from old dodgey metadata
3027 * super-minor: change the preferred_minor number
3028 * summaries: update redundant counters.
3029 * homehost: update the recorded homehost
3030 * _reshape_progress: record new reshape_progress position.
3033 struct intel_super
*super
= st
->sb
;
3034 struct imsm_super
*mpb
;
3036 /* we can only update container info */
3037 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
3040 mpb
= super
->anchor
;
3042 if (strcmp(update
, "uuid") == 0) {
3043 /* We take this to mean that the family_num should be updated.
3044 * However that is much smaller than the uuid so we cannot really
3045 * allow an explicit uuid to be given. And it is hard to reliably
3047 * So if !uuid_set we know the current uuid is random and just used
3048 * the first 'int' and copy it to the other 3 positions.
3049 * Otherwise we require the 4 'int's to be the same as would be the
3050 * case if we are using a random uuid. So an explicit uuid will be
3051 * accepted as long as all for ints are the same... which shouldn't hurt
3054 info
->uuid
[1] = info
->uuid
[2] = info
->uuid
[3] = info
->uuid
[0];
3057 if (info
->uuid
[0] != info
->uuid
[1] ||
3058 info
->uuid
[1] != info
->uuid
[2] ||
3059 info
->uuid
[2] != info
->uuid
[3])
3065 mpb
->orig_family_num
= info
->uuid
[0];
3066 } else if (strcmp(update
, "assemble") == 0)
3071 /* successful update? recompute checksum */
3073 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
3078 static size_t disks_to_mpb_size(int disks
)
3082 size
= sizeof(struct imsm_super
);
3083 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
3084 size
+= 2 * sizeof(struct imsm_dev
);
3085 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
3086 size
+= (4 - 2) * sizeof(struct imsm_map
);
3087 /* 4 possible disk_ord_tbl's */
3088 size
+= 4 * (disks
- 1) * sizeof(__u32
);
3093 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
,
3094 unsigned long long data_offset
)
3096 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
3099 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
3102 static void free_devlist(struct intel_super
*super
)
3104 struct intel_dev
*dv
;
3106 while (super
->devlist
) {
3107 dv
= super
->devlist
->next
;
3108 free(super
->devlist
->dev
);
3109 free(super
->devlist
);
3110 super
->devlist
= dv
;
3114 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
3116 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
3119 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
)
3123 * 0 same, or first was empty, and second was copied
3124 * 1 second had wrong number
3126 * 3 wrong other info
3128 struct intel_super
*first
= st
->sb
;
3129 struct intel_super
*sec
= tst
->sb
;
3136 /* in platform dependent environment test if the disks
3137 * use the same Intel hba
3138 * If not on Intel hba at all, allow anything.
3140 if (!check_env("IMSM_NO_PLATFORM") && first
->hba
&& sec
->hba
) {
3141 if (first
->hba
->type
!= sec
->hba
->type
) {
3143 "HBAs of devices do not match %s != %s\n",
3144 get_sys_dev_type(first
->hba
->type
),
3145 get_sys_dev_type(sec
->hba
->type
));
3148 if (first
->orom
!= sec
->orom
) {
3150 "HBAs of devices do not match %s != %s\n",
3151 first
->hba
->pci_id
, sec
->hba
->pci_id
);
3156 /* if an anchor does not have num_raid_devs set then it is a free
3159 if (first
->anchor
->num_raid_devs
> 0 &&
3160 sec
->anchor
->num_raid_devs
> 0) {
3161 /* Determine if these disks might ever have been
3162 * related. Further disambiguation can only take place
3163 * in load_super_imsm_all
3165 __u32 first_family
= first
->anchor
->orig_family_num
;
3166 __u32 sec_family
= sec
->anchor
->orig_family_num
;
3168 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
3169 MAX_SIGNATURE_LENGTH
) != 0)
3172 if (first_family
== 0)
3173 first_family
= first
->anchor
->family_num
;
3174 if (sec_family
== 0)
3175 sec_family
= sec
->anchor
->family_num
;
3177 if (first_family
!= sec_family
)
3182 /* if 'first' is a spare promote it to a populated mpb with sec's
3185 if (first
->anchor
->num_raid_devs
== 0 &&
3186 sec
->anchor
->num_raid_devs
> 0) {
3188 struct intel_dev
*dv
;
3189 struct imsm_dev
*dev
;
3191 /* we need to copy raid device info from sec if an allocation
3192 * fails here we don't associate the spare
3194 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++) {
3195 dv
= xmalloc(sizeof(*dv
));
3196 dev
= xmalloc(sizeof_imsm_dev(get_imsm_dev(sec
, i
), 1));
3199 dv
->next
= first
->devlist
;
3200 first
->devlist
= dv
;
3202 if (i
< sec
->anchor
->num_raid_devs
) {
3203 /* allocation failure */
3204 free_devlist(first
);
3205 pr_err("imsm: failed to associate spare\n");
3208 first
->anchor
->num_raid_devs
= sec
->anchor
->num_raid_devs
;
3209 first
->anchor
->orig_family_num
= sec
->anchor
->orig_family_num
;
3210 first
->anchor
->family_num
= sec
->anchor
->family_num
;
3211 memcpy(first
->anchor
->sig
, sec
->anchor
->sig
, MAX_SIGNATURE_LENGTH
);
3212 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++)
3213 imsm_copy_dev(get_imsm_dev(first
, i
), get_imsm_dev(sec
, i
));
3219 static void fd2devname(int fd
, char *name
)
3223 char dname
[PATH_MAX
];
3228 if (fstat(fd
, &st
) != 0)
3230 sprintf(path
, "/sys/dev/block/%d:%d",
3231 major(st
.st_rdev
), minor(st
.st_rdev
));
3233 rv
= readlink(path
, dname
, sizeof(dname
)-1);
3238 nm
= strrchr(dname
, '/');
3241 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
3245 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
3247 static int imsm_read_serial(int fd
, char *devname
,
3248 __u8 serial
[MAX_RAID_SERIAL_LEN
])
3250 unsigned char scsi_serial
[255];
3259 memset(scsi_serial
, 0, sizeof(scsi_serial
));
3261 rv
= scsi_get_serial(fd
, scsi_serial
, sizeof(scsi_serial
));
3263 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
3264 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3265 fd2devname(fd
, (char *) serial
);
3271 pr_err("Failed to retrieve serial for %s\n",
3276 rsp_len
= scsi_serial
[3];
3279 pr_err("Failed to retrieve serial for %s\n",
3283 rsp_buf
= (char *) &scsi_serial
[4];
3285 /* trim all whitespace and non-printable characters and convert
3288 for (i
= 0, dest
= rsp_buf
; i
< rsp_len
; i
++) {
3291 /* ':' is reserved for use in placeholder serial
3292 * numbers for missing disks
3300 len
= dest
- rsp_buf
;
3303 /* truncate leading characters */
3304 if (len
> MAX_RAID_SERIAL_LEN
) {
3305 dest
+= len
- MAX_RAID_SERIAL_LEN
;
3306 len
= MAX_RAID_SERIAL_LEN
;
3309 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
3310 memcpy(serial
, dest
, len
);
3315 static int serialcmp(__u8
*s1
, __u8
*s2
)
3317 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
3320 static void serialcpy(__u8
*dest
, __u8
*src
)
3322 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
3325 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
3329 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3330 if (serialcmp(dl
->serial
, serial
) == 0)
3336 static struct imsm_disk
*
3337 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
3341 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3342 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
3344 if (serialcmp(disk
->serial
, serial
) == 0) {
3355 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3357 struct imsm_disk
*disk
;
3362 __u8 serial
[MAX_RAID_SERIAL_LEN
];
3364 rv
= imsm_read_serial(fd
, devname
, serial
);
3369 dl
= xcalloc(1, sizeof(*dl
));
3372 dl
->major
= major(stb
.st_rdev
);
3373 dl
->minor
= minor(stb
.st_rdev
);
3374 dl
->next
= super
->disks
;
3375 dl
->fd
= keep_fd
? fd
: -1;
3376 assert(super
->disks
== NULL
);
3378 serialcpy(dl
->serial
, serial
);
3381 fd2devname(fd
, name
);
3383 dl
->devname
= xstrdup(devname
);
3385 dl
->devname
= xstrdup(name
);
3387 /* look up this disk's index in the current anchor */
3388 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
3391 /* only set index on disks that are a member of a
3392 * populated contianer, i.e. one with raid_devs
3394 if (is_failed(&dl
->disk
))
3396 else if (is_spare(&dl
->disk
))
3404 /* When migrating map0 contains the 'destination' state while map1
3405 * contains the current state. When not migrating map0 contains the
3406 * current state. This routine assumes that map[0].map_state is set to
3407 * the current array state before being called.
3409 * Migration is indicated by one of the following states
3410 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
3411 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
3412 * map1state=unitialized)
3413 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
3415 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
3416 * map1state=degraded)
3417 * 5/ Migration (mig_state=1 migr_type=MIGR_GEN_MIGR map0state=normal
3420 static void migrate(struct imsm_dev
*dev
, struct intel_super
*super
,
3421 __u8 to_state
, int migr_type
)
3423 struct imsm_map
*dest
;
3424 struct imsm_map
*src
= get_imsm_map(dev
, MAP_0
);
3426 dev
->vol
.migr_state
= 1;
3427 set_migr_type(dev
, migr_type
);
3428 dev
->vol
.curr_migr_unit
= 0;
3429 dest
= get_imsm_map(dev
, MAP_1
);
3431 /* duplicate and then set the target end state in map[0] */
3432 memcpy(dest
, src
, sizeof_imsm_map(src
));
3433 if ((migr_type
== MIGR_REBUILD
) ||
3434 (migr_type
== MIGR_GEN_MIGR
)) {
3438 for (i
= 0; i
< src
->num_members
; i
++) {
3439 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
3440 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
3444 if (migr_type
== MIGR_GEN_MIGR
)
3445 /* Clear migration record */
3446 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
3448 src
->map_state
= to_state
;
3451 static void end_migration(struct imsm_dev
*dev
, struct intel_super
*super
,
3454 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
3455 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
== 0 ?
3459 /* merge any IMSM_ORD_REBUILD bits that were not successfully
3460 * completed in the last migration.
3462 * FIXME add support for raid-level-migration
3464 if ((map_state
!= map
->map_state
) && (is_gen_migration(dev
) == 0) &&
3465 (prev
->map_state
!= IMSM_T_STATE_UNINITIALIZED
)) {
3466 /* when final map state is other than expected
3467 * merge maps (not for migration)
3471 for (i
= 0; i
< prev
->num_members
; i
++)
3472 for (j
= 0; j
< map
->num_members
; j
++)
3473 /* during online capacity expansion
3474 * disks position can be changed
3475 * if takeover is used
3477 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
3478 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
3479 map
->disk_ord_tbl
[j
] |=
3480 prev
->disk_ord_tbl
[i
];
3483 failed
= imsm_count_failed(super
, dev
, MAP_0
);
3484 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
3487 dev
->vol
.migr_state
= 0;
3488 set_migr_type(dev
, 0);
3489 dev
->vol
.curr_migr_unit
= 0;
3490 map
->map_state
= map_state
;
3494 static int parse_raid_devices(struct intel_super
*super
)
3497 struct imsm_dev
*dev_new
;
3498 size_t len
, len_migr
;
3500 size_t space_needed
= 0;
3501 struct imsm_super
*mpb
= super
->anchor
;
3503 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3504 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3505 struct intel_dev
*dv
;
3507 len
= sizeof_imsm_dev(dev_iter
, 0);
3508 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
3510 space_needed
+= len_migr
- len
;
3512 dv
= xmalloc(sizeof(*dv
));
3513 if (max_len
< len_migr
)
3515 if (max_len
> len_migr
)
3516 space_needed
+= max_len
- len_migr
;
3517 dev_new
= xmalloc(max_len
);
3518 imsm_copy_dev(dev_new
, dev_iter
);
3521 dv
->next
= super
->devlist
;
3522 super
->devlist
= dv
;
3525 /* ensure that super->buf is large enough when all raid devices
3528 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
3531 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
, 512);
3532 if (posix_memalign(&buf
, 512, len
) != 0)
3535 memcpy(buf
, super
->buf
, super
->len
);
3536 memset(buf
+ super
->len
, 0, len
- super
->len
);
3545 /* retrieve a pointer to the bbm log which starts after all raid devices */
3546 struct bbm_log
*__get_imsm_bbm_log(struct imsm_super
*mpb
)
3550 if (__le32_to_cpu(mpb
->bbm_log_size
)) {
3552 ptr
+= mpb
->mpb_size
- __le32_to_cpu(mpb
->bbm_log_size
);
3558 /*******************************************************************************
3559 * Function: check_mpb_migr_compatibility
3560 * Description: Function checks for unsupported migration features:
3561 * - migration optimization area (pba_of_lba0)
3562 * - descending reshape (ascending_migr)
3564 * super : imsm metadata information
3566 * 0 : migration is compatible
3567 * -1 : migration is not compatible
3568 ******************************************************************************/
3569 int check_mpb_migr_compatibility(struct intel_super
*super
)
3571 struct imsm_map
*map0
, *map1
;
3572 struct migr_record
*migr_rec
= super
->migr_rec
;
3575 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3576 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3579 dev_iter
->vol
.migr_state
== 1 &&
3580 dev_iter
->vol
.migr_type
== MIGR_GEN_MIGR
) {
3581 /* This device is migrating */
3582 map0
= get_imsm_map(dev_iter
, MAP_0
);
3583 map1
= get_imsm_map(dev_iter
, MAP_1
);
3584 if (pba_of_lba0(map0
) != pba_of_lba0(map1
))
3585 /* migration optimization area was used */
3587 if (migr_rec
->ascending_migr
== 0
3588 && migr_rec
->dest_depth_per_unit
> 0)
3589 /* descending reshape not supported yet */
3596 static void __free_imsm(struct intel_super
*super
, int free_disks
);
3598 /* load_imsm_mpb - read matrix metadata
3599 * allocates super->mpb to be freed by free_imsm
3601 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
3603 unsigned long long dsize
;
3604 unsigned long long sectors
;
3606 struct imsm_super
*anchor
;
3609 get_dev_size(fd
, NULL
, &dsize
);
3612 pr_err("%s: device to small for imsm\n",
3617 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0) {
3619 pr_err("Cannot seek to anchor block on %s: %s\n",
3620 devname
, strerror(errno
));
3624 if (posix_memalign((void**)&anchor
, 512, 512) != 0) {
3626 pr_err("Failed to allocate imsm anchor buffer"
3627 " on %s\n", devname
);
3630 if (read(fd
, anchor
, 512) != 512) {
3632 pr_err("Cannot read anchor block on %s: %s\n",
3633 devname
, strerror(errno
));
3638 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
3640 pr_err("no IMSM anchor on %s\n", devname
);
3645 __free_imsm(super
, 0);
3646 /* reload capability and hba */
3648 /* capability and hba must be updated with new super allocation */
3649 find_intel_hba_capability(fd
, super
, devname
);
3650 super
->len
= ROUND_UP(anchor
->mpb_size
, 512);
3651 if (posix_memalign(&super
->buf
, 512, super
->len
) != 0) {
3653 pr_err("unable to allocate %zu byte mpb buffer\n",
3658 memcpy(super
->buf
, anchor
, 512);
3660 sectors
= mpb_sectors(anchor
) - 1;
3663 if (posix_memalign(&super
->migr_rec_buf
, 512, MIGR_REC_BUF_SIZE
) != 0) {
3664 pr_err("%s could not allocate migr_rec buffer\n", __func__
);
3668 super
->clean_migration_record_by_mdmon
= 0;
3671 check_sum
= __gen_imsm_checksum(super
->anchor
);
3672 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
3674 pr_err("IMSM checksum %x != %x on %s\n",
3676 __le32_to_cpu(super
->anchor
->check_sum
),
3684 /* read the extended mpb */
3685 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0) {
3687 pr_err("Cannot seek to extended mpb on %s: %s\n",
3688 devname
, strerror(errno
));
3692 if ((unsigned)read(fd
, super
->buf
+ 512, super
->len
- 512) != super
->len
- 512) {
3694 pr_err("Cannot read extended mpb on %s: %s\n",
3695 devname
, strerror(errno
));
3699 check_sum
= __gen_imsm_checksum(super
->anchor
);
3700 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
3702 pr_err("IMSM checksum %x != %x on %s\n",
3703 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
3708 /* FIXME the BBM log is disk specific so we cannot use this global
3709 * buffer for all disks. Ok for now since we only look at the global
3710 * bbm_log_size parameter to gate assembly
3712 super
->bbm_log
= __get_imsm_bbm_log(super
->anchor
);
3717 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
);
3719 /* clears hi bits in metadata if MPB_ATTRIB_2TB_DISK not set */
3720 static void clear_hi(struct intel_super
*super
)
3722 struct imsm_super
*mpb
= super
->anchor
;
3724 if (mpb
->attributes
& MPB_ATTRIB_2TB_DISK
)
3726 for (i
= 0; i
< mpb
->num_disks
; ++i
) {
3727 struct imsm_disk
*disk
= &mpb
->disk
[i
];
3728 disk
->total_blocks_hi
= 0;
3730 for (i
= 0; i
< mpb
->num_raid_devs
; ++i
) {
3731 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
3734 for (n
= 0; n
< 2; ++n
) {
3735 struct imsm_map
*map
= get_imsm_map(dev
, n
);
3738 map
->pba_of_lba0_hi
= 0;
3739 map
->blocks_per_member_hi
= 0;
3740 map
->num_data_stripes_hi
= 0;
3746 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3750 err
= load_imsm_mpb(fd
, super
, devname
);
3753 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
3756 err
= parse_raid_devices(super
);
3761 static void __free_imsm_disk(struct dl
*d
)
3773 static void free_imsm_disks(struct intel_super
*super
)
3777 while (super
->disks
) {
3779 super
->disks
= d
->next
;
3780 __free_imsm_disk(d
);
3782 while (super
->disk_mgmt_list
) {
3783 d
= super
->disk_mgmt_list
;
3784 super
->disk_mgmt_list
= d
->next
;
3785 __free_imsm_disk(d
);
3787 while (super
->missing
) {
3789 super
->missing
= d
->next
;
3790 __free_imsm_disk(d
);
3795 /* free all the pieces hanging off of a super pointer */
3796 static void __free_imsm(struct intel_super
*super
, int free_disks
)
3798 struct intel_hba
*elem
, *next
;
3804 /* unlink capability description */
3806 if (super
->migr_rec_buf
) {
3807 free(super
->migr_rec_buf
);
3808 super
->migr_rec_buf
= NULL
;
3811 free_imsm_disks(super
);
3812 free_devlist(super
);
3816 free((void *)elem
->path
);
3824 static void free_imsm(struct intel_super
*super
)
3826 __free_imsm(super
, 1);
3830 static void free_super_imsm(struct supertype
*st
)
3832 struct intel_super
*super
= st
->sb
;
3841 static struct intel_super
*alloc_super(void)
3843 struct intel_super
*super
= xcalloc(1, sizeof(*super
));
3845 super
->current_vol
= -1;
3846 super
->create_offset
= ~((unsigned long long) 0);
3851 * find and allocate hba and OROM/EFI based on valid fd of RAID component device
3853 static int find_intel_hba_capability(int fd
, struct intel_super
*super
, char *devname
)
3855 struct sys_dev
*hba_name
;
3858 if ((fd
< 0) || check_env("IMSM_NO_PLATFORM")) {
3863 hba_name
= find_disk_attached_hba(fd
, NULL
);
3866 pr_err("%s is not attached to Intel(R) RAID controller.\n",
3870 rv
= attach_hba_to_super(super
, hba_name
);
3873 struct intel_hba
*hba
= super
->hba
;
3875 pr_err("%s is attached to Intel(R) %s RAID "
3876 "controller (%s),\n"
3877 " but the container is assigned to Intel(R) "
3878 "%s RAID controller (",
3880 get_sys_dev_type(hba_name
->type
),
3881 hba_name
->pci_id
? : "Err!",
3882 get_sys_dev_type(super
->hba
->type
));
3885 fprintf(stderr
, "%s", hba
->pci_id
? : "Err!");
3887 fprintf(stderr
, ", ");
3890 fprintf(stderr
, ").\n"
3891 " Mixing devices attached to different controllers "
3892 "is not allowed.\n");
3896 super
->orom
= find_imsm_capability(hba_name
);
3903 /* find_missing - helper routine for load_super_imsm_all that identifies
3904 * disks that have disappeared from the system. This routine relies on
3905 * the mpb being uptodate, which it is at load time.
3907 static int find_missing(struct intel_super
*super
)
3910 struct imsm_super
*mpb
= super
->anchor
;
3912 struct imsm_disk
*disk
;
3914 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3915 disk
= __get_imsm_disk(mpb
, i
);
3916 dl
= serial_to_dl(disk
->serial
, super
);
3920 dl
= xmalloc(sizeof(*dl
));
3924 dl
->devname
= xstrdup("missing");
3926 serialcpy(dl
->serial
, disk
->serial
);
3929 dl
->next
= super
->missing
;
3930 super
->missing
= dl
;
3937 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
3939 struct intel_disk
*idisk
= disk_list
;
3942 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
3944 idisk
= idisk
->next
;
3950 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
3951 struct intel_super
*super
,
3952 struct intel_disk
**disk_list
)
3954 struct imsm_disk
*d
= &super
->disks
->disk
;
3955 struct imsm_super
*mpb
= super
->anchor
;
3958 for (i
= 0; i
< tbl_size
; i
++) {
3959 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
3960 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
3962 if (tbl_mpb
->family_num
== mpb
->family_num
) {
3963 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
3964 dprintf("%s: mpb from %d:%d matches %d:%d\n",
3965 __func__
, super
->disks
->major
,
3966 super
->disks
->minor
,
3967 table
[i
]->disks
->major
,
3968 table
[i
]->disks
->minor
);
3972 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
3973 is_configured(d
) == is_configured(tbl_d
)) &&
3974 tbl_mpb
->generation_num
< mpb
->generation_num
) {
3975 /* current version of the mpb is a
3976 * better candidate than the one in
3977 * super_table, but copy over "cross
3978 * generational" status
3980 struct intel_disk
*idisk
;
3982 dprintf("%s: mpb from %d:%d replaces %d:%d\n",
3983 __func__
, super
->disks
->major
,
3984 super
->disks
->minor
,
3985 table
[i
]->disks
->major
,
3986 table
[i
]->disks
->minor
);
3988 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
3989 if (idisk
&& is_failed(&idisk
->disk
))
3990 tbl_d
->status
|= FAILED_DISK
;
3993 struct intel_disk
*idisk
;
3994 struct imsm_disk
*disk
;
3996 /* tbl_mpb is more up to date, but copy
3997 * over cross generational status before
4000 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
4001 if (disk
&& is_failed(disk
))
4002 d
->status
|= FAILED_DISK
;
4004 idisk
= disk_list_get(d
->serial
, *disk_list
);
4007 if (disk
&& is_configured(disk
))
4008 idisk
->disk
.status
|= CONFIGURED_DISK
;
4011 dprintf("%s: mpb from %d:%d prefer %d:%d\n",
4012 __func__
, super
->disks
->major
,
4013 super
->disks
->minor
,
4014 table
[i
]->disks
->major
,
4015 table
[i
]->disks
->minor
);
4023 table
[tbl_size
++] = super
;
4027 /* update/extend the merged list of imsm_disk records */
4028 for (j
= 0; j
< mpb
->num_disks
; j
++) {
4029 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
4030 struct intel_disk
*idisk
;
4032 idisk
= disk_list_get(disk
->serial
, *disk_list
);
4034 idisk
->disk
.status
|= disk
->status
;
4035 if (is_configured(&idisk
->disk
) ||
4036 is_failed(&idisk
->disk
))
4037 idisk
->disk
.status
&= ~(SPARE_DISK
);
4039 idisk
= xcalloc(1, sizeof(*idisk
));
4040 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
4041 idisk
->disk
= *disk
;
4042 idisk
->next
= *disk_list
;
4046 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
4053 static struct intel_super
*
4054 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
4057 struct imsm_super
*mpb
= super
->anchor
;
4061 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4062 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
4063 struct intel_disk
*idisk
;
4065 idisk
= disk_list_get(disk
->serial
, disk_list
);
4067 if (idisk
->owner
== owner
||
4068 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
4071 dprintf("%s: '%.16s' owner %d != %d\n",
4072 __func__
, disk
->serial
, idisk
->owner
,
4075 dprintf("%s: unknown disk %x [%d]: %.16s\n",
4076 __func__
, __le32_to_cpu(mpb
->family_num
), i
,
4082 if (ok_count
== mpb
->num_disks
)
4087 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
4089 struct intel_super
*s
;
4091 for (s
= super_list
; s
; s
= s
->next
) {
4092 if (family_num
!= s
->anchor
->family_num
)
4094 pr_err("Conflict, offlining family %#x on '%s'\n",
4095 __le32_to_cpu(family_num
), s
->disks
->devname
);
4099 static struct intel_super
*
4100 imsm_thunderdome(struct intel_super
**super_list
, int len
)
4102 struct intel_super
*super_table
[len
];
4103 struct intel_disk
*disk_list
= NULL
;
4104 struct intel_super
*champion
, *spare
;
4105 struct intel_super
*s
, **del
;
4110 memset(super_table
, 0, sizeof(super_table
));
4111 for (s
= *super_list
; s
; s
= s
->next
)
4112 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
4114 for (i
= 0; i
< tbl_size
; i
++) {
4115 struct imsm_disk
*d
;
4116 struct intel_disk
*idisk
;
4117 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
4120 d
= &s
->disks
->disk
;
4122 /* 'd' must appear in merged disk list for its
4123 * configuration to be valid
4125 idisk
= disk_list_get(d
->serial
, disk_list
);
4126 if (idisk
&& idisk
->owner
== i
)
4127 s
= validate_members(s
, disk_list
, i
);
4132 dprintf("%s: marking family: %#x from %d:%d offline\n",
4133 __func__
, mpb
->family_num
,
4134 super_table
[i
]->disks
->major
,
4135 super_table
[i
]->disks
->minor
);
4139 /* This is where the mdadm implementation differs from the Windows
4140 * driver which has no strict concept of a container. We can only
4141 * assemble one family from a container, so when returning a prodigal
4142 * array member to this system the code will not be able to disambiguate
4143 * the container contents that should be assembled ("foreign" versus
4144 * "local"). It requires user intervention to set the orig_family_num
4145 * to a new value to establish a new container. The Windows driver in
4146 * this situation fixes up the volume name in place and manages the
4147 * foreign array as an independent entity.
4152 for (i
= 0; i
< tbl_size
; i
++) {
4153 struct intel_super
*tbl_ent
= super_table
[i
];
4159 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
4164 if (s
&& !is_spare
) {
4165 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
4167 } else if (!s
&& !is_spare
)
4180 pr_err("Chose family %#x on '%s', "
4181 "assemble conflicts to new container with '--update=uuid'\n",
4182 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
4184 /* collect all dl's onto 'champion', and update them to
4185 * champion's version of the status
4187 for (s
= *super_list
; s
; s
= s
->next
) {
4188 struct imsm_super
*mpb
= champion
->anchor
;
4189 struct dl
*dl
= s
->disks
;
4194 mpb
->attributes
|= s
->anchor
->attributes
& MPB_ATTRIB_2TB_DISK
;
4196 for (i
= 0; i
< mpb
->num_disks
; i
++) {
4197 struct imsm_disk
*disk
;
4199 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
4202 /* only set index on disks that are a member of
4203 * a populated contianer, i.e. one with
4206 if (is_failed(&dl
->disk
))
4208 else if (is_spare(&dl
->disk
))
4214 if (i
>= mpb
->num_disks
) {
4215 struct intel_disk
*idisk
;
4217 idisk
= disk_list_get(dl
->serial
, disk_list
);
4218 if (idisk
&& is_spare(&idisk
->disk
) &&
4219 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
4227 dl
->next
= champion
->disks
;
4228 champion
->disks
= dl
;
4232 /* delete 'champion' from super_list */
4233 for (del
= super_list
; *del
; ) {
4234 if (*del
== champion
) {
4235 *del
= (*del
)->next
;
4238 del
= &(*del
)->next
;
4240 champion
->next
= NULL
;
4244 struct intel_disk
*idisk
= disk_list
;
4246 disk_list
= disk_list
->next
;
4254 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
);
4255 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4256 int major
, int minor
, int keep_fd
);
4258 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4259 int *max
, int keep_fd
);
4261 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
4262 char *devname
, struct md_list
*devlist
,
4265 struct intel_super
*super_list
= NULL
;
4266 struct intel_super
*super
= NULL
;
4271 /* 'fd' is an opened container */
4272 err
= get_sra_super_block(fd
, &super_list
, devname
, &i
, keep_fd
);
4274 /* get super block from devlist devices */
4275 err
= get_devlist_super_block(devlist
, &super_list
, &i
, keep_fd
);
4278 /* all mpbs enter, maybe one leaves */
4279 super
= imsm_thunderdome(&super_list
, i
);
4285 if (find_missing(super
) != 0) {
4291 /* load migration record */
4292 err
= load_imsm_migr_rec(super
, NULL
);
4294 /* migration is in progress,
4295 * but migr_rec cannot be loaded,
4301 /* Check migration compatibility */
4302 if ((err
== 0) && (check_mpb_migr_compatibility(super
) != 0)) {
4303 pr_err("Unsupported migration detected");
4305 fprintf(stderr
, " on %s\n", devname
);
4307 fprintf(stderr
, " (IMSM).\n");
4316 while (super_list
) {
4317 struct intel_super
*s
= super_list
;
4319 super_list
= super_list
->next
;
4328 strcpy(st
->container_devnm
, fd2devnm(fd
));
4330 st
->container_devnm
[0] = 0;
4331 if (err
== 0 && st
->ss
== NULL
) {
4332 st
->ss
= &super_imsm
;
4333 st
->minor_version
= 0;
4334 st
->max_devs
= IMSM_MAX_DEVICES
;
4340 get_devlist_super_block(struct md_list
*devlist
, struct intel_super
**super_list
,
4341 int *max
, int keep_fd
)
4343 struct md_list
*tmpdev
;
4347 for (i
= 0, tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
4348 if (tmpdev
->used
!= 1)
4350 if (tmpdev
->container
== 1) {
4352 int fd
= dev_open(tmpdev
->devname
, O_RDONLY
|O_EXCL
);
4354 pr_err("cannot open device %s: %s\n",
4355 tmpdev
->devname
, strerror(errno
));
4359 err
= get_sra_super_block(fd
, super_list
,
4360 tmpdev
->devname
, &lmax
,
4369 int major
= major(tmpdev
->st_rdev
);
4370 int minor
= minor(tmpdev
->st_rdev
);
4371 err
= get_super_block(super_list
,
4388 static int get_super_block(struct intel_super
**super_list
, char *devnm
, char *devname
,
4389 int major
, int minor
, int keep_fd
)
4391 struct intel_super
*s
= NULL
;
4403 sprintf(nm
, "%d:%d", major
, minor
);
4404 dfd
= dev_open(nm
, O_RDWR
);
4410 find_intel_hba_capability(dfd
, s
, devname
);
4411 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
4413 /* retry the load if we might have raced against mdmon */
4414 if (err
== 3 && devnm
&& mdmon_running(devnm
))
4415 for (retry
= 0; retry
< 3; retry
++) {
4417 err
= load_and_parse_mpb(dfd
, s
, NULL
, keep_fd
);
4423 s
->next
= *super_list
;
4431 if ((dfd
>= 0) && (!keep_fd
))
4438 get_sra_super_block(int fd
, struct intel_super
**super_list
, char *devname
, int *max
, int keep_fd
)
4445 sra
= sysfs_read(fd
, NULL
, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
4449 if (sra
->array
.major_version
!= -1 ||
4450 sra
->array
.minor_version
!= -2 ||
4451 strcmp(sra
->text_version
, "imsm") != 0) {
4456 devnm
= fd2devnm(fd
);
4457 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
4458 if (get_super_block(super_list
, devnm
, devname
,
4459 sd
->disk
.major
, sd
->disk
.minor
, keep_fd
) != 0) {
4470 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
4472 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
, NULL
, 1);
4476 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
4478 struct intel_super
*super
;
4482 if (test_partition(fd
))
4483 /* IMSM not allowed on partitions */
4486 free_super_imsm(st
);
4488 super
= alloc_super();
4489 /* Load hba and capabilities if they exist.
4490 * But do not preclude loading metadata in case capabilities or hba are
4491 * non-compliant and ignore_hw_compat is set.
4493 rv
= find_intel_hba_capability(fd
, super
, devname
);
4494 /* no orom/efi or non-intel hba of the disk */
4495 if ((rv
!= 0) && (st
->ignore_hw_compat
== 0)) {
4497 pr_err("No OROM/EFI properties for %s\n", devname
);
4501 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
4503 /* retry the load if we might have raced against mdmon */
4505 struct mdstat_ent
*mdstat
= mdstat_by_component(fd2devnm(fd
));
4507 if (mdstat
&& mdmon_running(mdstat
->devnm
) && getpid() != mdmon_pid(mdstat
->devnm
)) {
4508 for (retry
= 0; retry
< 3; retry
++) {
4510 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
4516 free_mdstat(mdstat
);
4521 pr_err("Failed to load all information "
4522 "sections on %s\n", devname
);
4528 if (st
->ss
== NULL
) {
4529 st
->ss
= &super_imsm
;
4530 st
->minor_version
= 0;
4531 st
->max_devs
= IMSM_MAX_DEVICES
;
4534 /* load migration record */
4535 if (load_imsm_migr_rec(super
, NULL
) == 0) {
4536 /* Check for unsupported migration features */
4537 if (check_mpb_migr_compatibility(super
) != 0) {
4538 pr_err("Unsupported migration detected");
4540 fprintf(stderr
, " on %s\n", devname
);
4542 fprintf(stderr
, " (IMSM).\n");
4550 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
4552 if (info
->level
== 1)
4554 return info
->chunk_size
>> 9;
4557 static unsigned long long info_to_blocks_per_member(mdu_array_info_t
*info
,
4558 unsigned long long size
)
4560 if (info
->level
== 1)
4563 return (size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
4566 static void imsm_update_version_info(struct intel_super
*super
)
4568 /* update the version and attributes */
4569 struct imsm_super
*mpb
= super
->anchor
;
4571 struct imsm_dev
*dev
;
4572 struct imsm_map
*map
;
4575 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4576 dev
= get_imsm_dev(super
, i
);
4577 map
= get_imsm_map(dev
, MAP_0
);
4578 if (__le32_to_cpu(dev
->size_high
) > 0)
4579 mpb
->attributes
|= MPB_ATTRIB_2TB
;
4581 /* FIXME detect when an array spans a port multiplier */
4583 mpb
->attributes
|= MPB_ATTRIB_PM
;
4586 if (mpb
->num_raid_devs
> 1 ||
4587 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
4588 version
= MPB_VERSION_ATTRIBS
;
4589 switch (get_imsm_raid_level(map
)) {
4590 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
4591 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
4592 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
4593 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
4596 if (map
->num_members
>= 5)
4597 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
4598 else if (dev
->status
== DEV_CLONE_N_GO
)
4599 version
= MPB_VERSION_CNG
;
4600 else if (get_imsm_raid_level(map
) == 5)
4601 version
= MPB_VERSION_RAID5
;
4602 else if (map
->num_members
>= 3)
4603 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
4604 else if (get_imsm_raid_level(map
) == 1)
4605 version
= MPB_VERSION_RAID1
;
4607 version
= MPB_VERSION_RAID0
;
4609 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
4613 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
4615 struct imsm_super
*mpb
= super
->anchor
;
4616 char *reason
= NULL
;
4619 if (strlen(name
) > MAX_RAID_SERIAL_LEN
)
4620 reason
= "must be 16 characters or less";
4622 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4623 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
4625 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
4626 reason
= "already exists";
4631 if (reason
&& !quiet
)
4632 pr_err("imsm volume name %s\n", reason
);
4637 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
4638 unsigned long long size
, char *name
,
4639 char *homehost
, int *uuid
,
4640 long long data_offset
)
4642 /* We are creating a volume inside a pre-existing container.
4643 * so st->sb is already set.
4645 struct intel_super
*super
= st
->sb
;
4646 struct imsm_super
*mpb
= super
->anchor
;
4647 struct intel_dev
*dv
;
4648 struct imsm_dev
*dev
;
4649 struct imsm_vol
*vol
;
4650 struct imsm_map
*map
;
4651 int idx
= mpb
->num_raid_devs
;
4653 unsigned long long array_blocks
;
4654 size_t size_old
, size_new
;
4655 unsigned long long num_data_stripes
;
4657 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
4658 pr_err("This imsm-container already has the "
4659 "maximum of %d volumes\n", super
->orom
->vpa
);
4663 /* ensure the mpb is large enough for the new data */
4664 size_old
= __le32_to_cpu(mpb
->mpb_size
);
4665 size_new
= disks_to_mpb_size(info
->nr_disks
);
4666 if (size_new
> size_old
) {
4668 size_t size_round
= ROUND_UP(size_new
, 512);
4670 if (posix_memalign(&mpb_new
, 512, size_round
) != 0) {
4671 pr_err("could not allocate new mpb\n");
4674 if (posix_memalign(&super
->migr_rec_buf
, 512,
4675 MIGR_REC_BUF_SIZE
) != 0) {
4676 pr_err("%s could not allocate migr_rec buffer\n",
4683 memcpy(mpb_new
, mpb
, size_old
);
4686 super
->anchor
= mpb_new
;
4687 mpb
->mpb_size
= __cpu_to_le32(size_new
);
4688 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
4690 super
->current_vol
= idx
;
4692 /* handle 'failed_disks' by either:
4693 * a) create dummy disk entries in the table if this the first
4694 * volume in the array. We add them here as this is the only
4695 * opportunity to add them. add_to_super_imsm_volume()
4696 * handles the non-failed disks and continues incrementing
4698 * b) validate that 'failed_disks' matches the current number
4699 * of missing disks if the container is populated
4701 if (super
->current_vol
== 0) {
4703 for (i
= 0; i
< info
->failed_disks
; i
++) {
4704 struct imsm_disk
*disk
;
4707 disk
= __get_imsm_disk(mpb
, i
);
4708 disk
->status
= CONFIGURED_DISK
| FAILED_DISK
;
4709 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
4710 snprintf((char *) disk
->serial
, MAX_RAID_SERIAL_LEN
,
4713 find_missing(super
);
4718 for (d
= super
->missing
; d
; d
= d
->next
)
4720 if (info
->failed_disks
> missing
) {
4721 pr_err("unable to add 'missing' disk to container\n");
4726 if (!check_name(super
, name
, 0))
4728 dv
= xmalloc(sizeof(*dv
));
4729 dev
= xcalloc(1, sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
4730 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
4731 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
4732 info
->layout
, info
->chunk_size
,
4734 /* round array size down to closest MB */
4735 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
4737 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
4738 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
4739 dev
->status
= (DEV_READ_COALESCING
| DEV_WRITE_COALESCING
);
4741 vol
->migr_state
= 0;
4742 set_migr_type(dev
, MIGR_INIT
);
4743 vol
->dirty
= !info
->state
;
4744 vol
->curr_migr_unit
= 0;
4745 map
= get_imsm_map(dev
, MAP_0
);
4746 set_pba_of_lba0(map
, super
->create_offset
);
4747 set_blocks_per_member(map
, info_to_blocks_per_member(info
, size
));
4748 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
4749 map
->failed_disk_num
= ~0;
4750 if (info
->level
> 0)
4751 map
->map_state
= (info
->state
? IMSM_T_STATE_NORMAL
4752 : IMSM_T_STATE_UNINITIALIZED
);
4754 map
->map_state
= info
->failed_disks
? IMSM_T_STATE_FAILED
:
4755 IMSM_T_STATE_NORMAL
;
4758 if (info
->level
== 1 && info
->raid_disks
> 2) {
4761 pr_err("imsm does not support more than 2 disks"
4762 "in a raid1 volume\n");
4766 map
->raid_level
= info
->level
;
4767 if (info
->level
== 10) {
4768 map
->raid_level
= 1;
4769 map
->num_domains
= info
->raid_disks
/ 2;
4770 } else if (info
->level
== 1)
4771 map
->num_domains
= info
->raid_disks
;
4773 map
->num_domains
= 1;
4775 /* info->size is only int so use the 'size' parameter instead */
4776 num_data_stripes
= (size
* 2) / info_to_blocks_per_strip(info
);
4777 num_data_stripes
/= map
->num_domains
;
4778 set_num_data_stripes(map
, num_data_stripes
);
4780 map
->num_members
= info
->raid_disks
;
4781 for (i
= 0; i
< map
->num_members
; i
++) {
4782 /* initialized in add_to_super */
4783 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
4785 mpb
->num_raid_devs
++;
4788 dv
->index
= super
->current_vol
;
4789 dv
->next
= super
->devlist
;
4790 super
->devlist
= dv
;
4792 imsm_update_version_info(super
);
4797 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
4798 unsigned long long size
, char *name
,
4799 char *homehost
, int *uuid
,
4800 unsigned long long data_offset
)
4802 /* This is primarily called by Create when creating a new array.
4803 * We will then get add_to_super called for each component, and then
4804 * write_init_super called to write it out to each device.
4805 * For IMSM, Create can create on fresh devices or on a pre-existing
4807 * To create on a pre-existing array a different method will be called.
4808 * This one is just for fresh drives.
4810 struct intel_super
*super
;
4811 struct imsm_super
*mpb
;
4815 if (data_offset
!= INVALID_SECTORS
) {
4816 pr_err("data-offset not supported by imsm\n");
4821 return init_super_imsm_volume(st
, info
, size
, name
, homehost
, uuid
,
4825 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
4829 super
= alloc_super();
4830 if (super
&& posix_memalign(&super
->buf
, 512, mpb_size
) != 0) {
4835 pr_err("%s could not allocate superblock\n", __func__
);
4838 if (posix_memalign(&super
->migr_rec_buf
, 512, MIGR_REC_BUF_SIZE
) != 0) {
4839 pr_err("%s could not allocate migr_rec buffer\n", __func__
);
4844 memset(super
->buf
, 0, mpb_size
);
4846 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
4850 /* zeroing superblock */
4854 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
4856 version
= (char *) mpb
->sig
;
4857 strcpy(version
, MPB_SIGNATURE
);
4858 version
+= strlen(MPB_SIGNATURE
);
4859 strcpy(version
, MPB_VERSION_RAID0
);
4865 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
4866 int fd
, char *devname
)
4868 struct intel_super
*super
= st
->sb
;
4869 struct imsm_super
*mpb
= super
->anchor
;
4870 struct imsm_disk
*_disk
;
4871 struct imsm_dev
*dev
;
4872 struct imsm_map
*map
;
4876 dev
= get_imsm_dev(super
, super
->current_vol
);
4877 map
= get_imsm_map(dev
, MAP_0
);
4879 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
4880 pr_err("%s: Cannot add spare devices to IMSM volume\n",
4886 /* we're doing autolayout so grab the pre-marked (in
4887 * validate_geometry) raid_disk
4889 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4890 if (dl
->raiddisk
== dk
->raid_disk
)
4893 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4894 if (dl
->major
== dk
->major
&&
4895 dl
->minor
== dk
->minor
)
4900 pr_err("%s is not a member of the same container\n", devname
);
4904 /* add a pristine spare to the metadata */
4905 if (dl
->index
< 0) {
4906 dl
->index
= super
->anchor
->num_disks
;
4907 super
->anchor
->num_disks
++;
4909 /* Check the device has not already been added */
4910 slot
= get_imsm_disk_slot(map
, dl
->index
);
4912 (get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
) & IMSM_ORD_REBUILD
) == 0) {
4913 pr_err("%s has been included in this array twice\n",
4917 set_imsm_ord_tbl_ent(map
, dk
->raid_disk
, dl
->index
);
4918 dl
->disk
.status
= CONFIGURED_DISK
;
4920 /* update size of 'missing' disks to be at least as large as the
4921 * largest acitve member (we only have dummy missing disks when
4922 * creating the first volume)
4924 if (super
->current_vol
== 0) {
4925 for (df
= super
->missing
; df
; df
= df
->next
) {
4926 if (total_blocks(&dl
->disk
) > total_blocks(&df
->disk
))
4927 set_total_blocks(&df
->disk
, total_blocks(&dl
->disk
));
4928 _disk
= __get_imsm_disk(mpb
, df
->index
);
4933 /* refresh unset/failed slots to point to valid 'missing' entries */
4934 for (df
= super
->missing
; df
; df
= df
->next
)
4935 for (slot
= 0; slot
< mpb
->num_disks
; slot
++) {
4936 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
4938 if ((ord
& IMSM_ORD_REBUILD
) == 0)
4940 set_imsm_ord_tbl_ent(map
, slot
, df
->index
| IMSM_ORD_REBUILD
);
4941 if (is_gen_migration(dev
)) {
4942 struct imsm_map
*map2
= get_imsm_map(dev
,
4944 int slot2
= get_imsm_disk_slot(map2
, df
->index
);
4945 if ((slot2
< map2
->num_members
) &&
4947 __u32 ord2
= get_imsm_ord_tbl_ent(dev
,
4950 if ((unsigned)df
->index
==
4952 set_imsm_ord_tbl_ent(map2
,
4958 dprintf("set slot:%d to missing disk:%d\n", slot
, df
->index
);
4962 /* if we are creating the first raid device update the family number */
4963 if (super
->current_vol
== 0) {
4965 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
4967 _disk
= __get_imsm_disk(mpb
, dl
->index
);
4968 if (!_dev
|| !_disk
) {
4969 pr_err("BUG mpb setup error\n");
4975 sum
+= __gen_imsm_checksum(mpb
);
4976 mpb
->family_num
= __cpu_to_le32(sum
);
4977 mpb
->orig_family_num
= mpb
->family_num
;
4979 super
->current_disk
= dl
;
4984 * Function marks disk as spare and restores disk serial
4985 * in case it was previously marked as failed by takeover operation
4987 * -1 : critical error
4988 * 0 : disk is marked as spare but serial is not set
4991 int mark_spare(struct dl
*disk
)
4993 __u8 serial
[MAX_RAID_SERIAL_LEN
];
5000 if (!imsm_read_serial(disk
->fd
, NULL
, serial
)) {
5001 /* Restore disk serial number, because takeover marks disk
5002 * as failed and adds to serial ':0' before it becomes
5005 serialcpy(disk
->serial
, serial
);
5006 serialcpy(disk
->disk
.serial
, serial
);
5009 disk
->disk
.status
= SPARE_DISK
;
5015 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
5016 int fd
, char *devname
,
5017 unsigned long long data_offset
)
5019 struct intel_super
*super
= st
->sb
;
5021 unsigned long long size
;
5026 /* If we are on an RAID enabled platform check that the disk is
5027 * attached to the raid controller.
5028 * We do not need to test disks attachment for container based additions,
5029 * they shall be already tested when container was created/assembled.
5031 rv
= find_intel_hba_capability(fd
, super
, devname
);
5032 /* no orom/efi or non-intel hba of the disk */
5034 dprintf("capability: %p fd: %d ret: %d\n",
5035 super
->orom
, fd
, rv
);
5039 if (super
->current_vol
>= 0)
5040 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
5043 dd
= xcalloc(sizeof(*dd
), 1);
5044 dd
->major
= major(stb
.st_rdev
);
5045 dd
->minor
= minor(stb
.st_rdev
);
5046 dd
->devname
= devname
? xstrdup(devname
) : NULL
;
5049 dd
->action
= DISK_ADD
;
5050 rv
= imsm_read_serial(fd
, devname
, dd
->serial
);
5052 pr_err("failed to retrieve scsi serial, aborting\n");
5057 get_dev_size(fd
, NULL
, &size
);
5058 /* clear migr_rec when adding disk to container */
5059 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SIZE
);
5060 if (lseek64(fd
, size
- MIGR_REC_POSITION
, SEEK_SET
) >= 0) {
5061 if (write(fd
, super
->migr_rec_buf
,
5062 MIGR_REC_BUF_SIZE
) != MIGR_REC_BUF_SIZE
)
5063 perror("Write migr_rec failed");
5067 serialcpy(dd
->disk
.serial
, dd
->serial
);
5068 set_total_blocks(&dd
->disk
, size
);
5069 if (__le32_to_cpu(dd
->disk
.total_blocks_hi
) > 0) {
5070 struct imsm_super
*mpb
= super
->anchor
;
5071 mpb
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5074 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
5075 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
5077 dd
->disk
.scsi_id
= __cpu_to_le32(0);
5079 if (st
->update_tail
) {
5080 dd
->next
= super
->disk_mgmt_list
;
5081 super
->disk_mgmt_list
= dd
;
5083 dd
->next
= super
->disks
;
5085 super
->updates_pending
++;
5091 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
5093 struct intel_super
*super
= st
->sb
;
5096 /* remove from super works only in mdmon - for communication
5097 * manager - monitor. Check if communication memory buffer
5100 if (!st
->update_tail
) {
5101 pr_err("%s shall be used in mdmon context only"
5102 "(line %d).\n", __func__
, __LINE__
);
5105 dd
= xcalloc(1, sizeof(*dd
));
5106 dd
->major
= dk
->major
;
5107 dd
->minor
= dk
->minor
;
5110 dd
->action
= DISK_REMOVE
;
5112 dd
->next
= super
->disk_mgmt_list
;
5113 super
->disk_mgmt_list
= dd
;
5118 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
5122 struct imsm_super anchor
;
5123 } spare_record
__attribute__ ((aligned(512)));
5125 /* spare records have their own family number and do not have any defined raid
5128 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
5130 struct imsm_super
*mpb
= super
->anchor
;
5131 struct imsm_super
*spare
= &spare_record
.anchor
;
5135 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
)),
5136 spare
->generation_num
= __cpu_to_le32(1UL),
5137 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
5138 spare
->num_disks
= 1,
5139 spare
->num_raid_devs
= 0,
5140 spare
->cache_size
= mpb
->cache_size
,
5141 spare
->pwr_cycle_count
= __cpu_to_le32(1),
5143 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
5144 MPB_SIGNATURE MPB_VERSION_RAID0
);
5146 for (d
= super
->disks
; d
; d
= d
->next
) {
5150 spare
->disk
[0] = d
->disk
;
5151 if (__le32_to_cpu(d
->disk
.total_blocks_hi
) > 0)
5152 spare
->attributes
|= MPB_ATTRIB_2TB_DISK
;
5154 sum
= __gen_imsm_checksum(spare
);
5155 spare
->family_num
= __cpu_to_le32(sum
);
5156 spare
->orig_family_num
= 0;
5157 sum
= __gen_imsm_checksum(spare
);
5158 spare
->check_sum
= __cpu_to_le32(sum
);
5160 if (store_imsm_mpb(d
->fd
, spare
)) {
5161 pr_err("%s: failed for device %d:%d %s\n",
5162 __func__
, d
->major
, d
->minor
, strerror(errno
));
5174 static int write_super_imsm(struct supertype
*st
, int doclose
)
5176 struct intel_super
*super
= st
->sb
;
5177 struct imsm_super
*mpb
= super
->anchor
;
5183 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
5185 int clear_migration_record
= 1;
5187 /* 'generation' is incremented everytime the metadata is written */
5188 generation
= __le32_to_cpu(mpb
->generation_num
);
5190 mpb
->generation_num
= __cpu_to_le32(generation
);
5192 /* fix up cases where previous mdadm releases failed to set
5195 if (mpb
->orig_family_num
== 0)
5196 mpb
->orig_family_num
= mpb
->family_num
;
5198 for (d
= super
->disks
; d
; d
= d
->next
) {
5202 mpb
->disk
[d
->index
] = d
->disk
;
5206 for (d
= super
->missing
; d
; d
= d
->next
) {
5207 mpb
->disk
[d
->index
] = d
->disk
;
5210 mpb
->num_disks
= num_disks
;
5211 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
5213 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5214 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
5215 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
5217 imsm_copy_dev(dev
, dev2
);
5218 mpb_size
+= sizeof_imsm_dev(dev
, 0);
5220 if (is_gen_migration(dev2
))
5221 clear_migration_record
= 0;
5223 mpb_size
+= __le32_to_cpu(mpb
->bbm_log_size
);
5224 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
5226 /* recalculate checksum */
5227 sum
= __gen_imsm_checksum(mpb
);
5228 mpb
->check_sum
= __cpu_to_le32(sum
);
5230 if (super
->clean_migration_record_by_mdmon
) {
5231 clear_migration_record
= 1;
5232 super
->clean_migration_record_by_mdmon
= 0;
5234 if (clear_migration_record
)
5235 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SIZE
);
5237 /* write the mpb for disks that compose raid devices */
5238 for (d
= super
->disks
; d
; d
= d
->next
) {
5239 if (d
->index
< 0 || is_failed(&d
->disk
))
5242 if (clear_migration_record
) {
5243 unsigned long long dsize
;
5245 get_dev_size(d
->fd
, NULL
, &dsize
);
5246 if (lseek64(d
->fd
, dsize
- 512, SEEK_SET
) >= 0) {
5247 if (write(d
->fd
, super
->migr_rec_buf
,
5248 MIGR_REC_BUF_SIZE
) != MIGR_REC_BUF_SIZE
)
5249 perror("Write migr_rec failed");
5253 if (store_imsm_mpb(d
->fd
, mpb
))
5255 "%s: failed for device %d:%d (fd: %d)%s\n",
5256 __func__
, d
->major
, d
->minor
,
5257 d
->fd
, strerror(errno
));
5266 return write_super_imsm_spares(super
, doclose
);
5271 static int create_array(struct supertype
*st
, int dev_idx
)
5274 struct imsm_update_create_array
*u
;
5275 struct intel_super
*super
= st
->sb
;
5276 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
5277 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
5278 struct disk_info
*inf
;
5279 struct imsm_disk
*disk
;
5282 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
5283 sizeof(*inf
) * map
->num_members
;
5285 u
->type
= update_create_array
;
5286 u
->dev_idx
= dev_idx
;
5287 imsm_copy_dev(&u
->dev
, dev
);
5288 inf
= get_disk_info(u
);
5289 for (i
= 0; i
< map
->num_members
; i
++) {
5290 int idx
= get_imsm_disk_idx(dev
, i
, MAP_X
);
5292 disk
= get_imsm_disk(super
, idx
);
5294 disk
= get_imsm_missing(super
, idx
);
5295 serialcpy(inf
[i
].serial
, disk
->serial
);
5297 append_metadata_update(st
, u
, len
);
5302 static int mgmt_disk(struct supertype
*st
)
5304 struct intel_super
*super
= st
->sb
;
5306 struct imsm_update_add_remove_disk
*u
;
5308 if (!super
->disk_mgmt_list
)
5313 u
->type
= update_add_remove_disk
;
5314 append_metadata_update(st
, u
, len
);
5319 static int write_init_super_imsm(struct supertype
*st
)
5321 struct intel_super
*super
= st
->sb
;
5322 int current_vol
= super
->current_vol
;
5324 /* we are done with current_vol reset it to point st at the container */
5325 super
->current_vol
= -1;
5327 if (st
->update_tail
) {
5328 /* queue the recently created array / added disk
5329 * as a metadata update */
5332 /* determine if we are creating a volume or adding a disk */
5333 if (current_vol
< 0) {
5334 /* in the mgmt (add/remove) disk case we are running
5335 * in mdmon context, so don't close fd's
5337 return mgmt_disk(st
);
5339 rv
= create_array(st
, current_vol
);
5344 for (d
= super
->disks
; d
; d
= d
->next
)
5345 Kill(d
->devname
, NULL
, 0, -1, 1);
5346 return write_super_imsm(st
, 1);
5351 static int store_super_imsm(struct supertype
*st
, int fd
)
5353 struct intel_super
*super
= st
->sb
;
5354 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
5360 return store_imsm_mpb(fd
, mpb
);
5366 static int imsm_bbm_log_size(struct imsm_super
*mpb
)
5368 return __le32_to_cpu(mpb
->bbm_log_size
);
5372 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
5373 int layout
, int raiddisks
, int chunk
,
5374 unsigned long long size
,
5375 unsigned long long data_offset
,
5377 unsigned long long *freesize
,
5381 unsigned long long ldsize
;
5382 struct intel_super
*super
=NULL
;
5385 if (level
!= LEVEL_CONTAINER
)
5390 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
5393 pr_err("imsm: Cannot open %s: %s\n",
5394 dev
, strerror(errno
));
5397 if (!get_dev_size(fd
, dev
, &ldsize
)) {
5402 /* capabilities retrieve could be possible
5403 * note that there is no fd for the disks in array.
5405 super
= alloc_super();
5406 rv
= find_intel_hba_capability(fd
, super
, verbose
> 0 ? dev
: NULL
);
5410 fd2devname(fd
, str
);
5411 dprintf("validate_geometry_imsm_container: fd: %d %s orom: %p rv: %d raiddisk: %d\n",
5412 fd
, str
, super
->orom
, rv
, raiddisks
);
5414 /* no orom/efi or non-intel hba of the disk */
5421 if (raiddisks
> super
->orom
->tds
) {
5423 pr_err("%d exceeds maximum number of"
5424 " platform supported disks: %d\n",
5425 raiddisks
, super
->orom
->tds
);
5429 if ((super
->orom
->attr
& IMSM_OROM_ATTR_2TB_DISK
) == 0 &&
5430 (ldsize
>> 9) >> 32 > 0) {
5432 pr_err("%s exceeds maximum platform supported size\n", dev
);
5438 *freesize
= avail_size_imsm(st
, ldsize
>> 9, data_offset
);
5444 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
5446 const unsigned long long base_start
= e
[*idx
].start
;
5447 unsigned long long end
= base_start
+ e
[*idx
].size
;
5450 if (base_start
== end
)
5454 for (i
= *idx
; i
< num_extents
; i
++) {
5455 /* extend overlapping extents */
5456 if (e
[i
].start
>= base_start
&&
5457 e
[i
].start
<= end
) {
5460 if (e
[i
].start
+ e
[i
].size
> end
)
5461 end
= e
[i
].start
+ e
[i
].size
;
5462 } else if (e
[i
].start
> end
) {
5468 return end
- base_start
;
5471 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
5473 /* build a composite disk with all known extents and generate a new
5474 * 'maxsize' given the "all disks in an array must share a common start
5475 * offset" constraint
5477 struct extent
*e
= xcalloc(sum_extents
, sizeof(*e
));
5481 unsigned long long pos
;
5482 unsigned long long start
= 0;
5483 unsigned long long maxsize
;
5484 unsigned long reserve
;
5486 /* coalesce and sort all extents. also, check to see if we need to
5487 * reserve space between member arrays
5490 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5493 for (i
= 0; i
< dl
->extent_cnt
; i
++)
5496 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
5501 while (i
< sum_extents
) {
5502 e
[j
].start
= e
[i
].start
;
5503 e
[j
].size
= find_size(e
, &i
, sum_extents
);
5505 if (e
[j
-1].size
== 0)
5514 unsigned long long esize
;
5516 esize
= e
[i
].start
- pos
;
5517 if (esize
>= maxsize
) {
5522 pos
= e
[i
].start
+ e
[i
].size
;
5524 } while (e
[i
-1].size
);
5530 /* FIXME assumes volume at offset 0 is the first volume in a
5533 if (start_extent
> 0)
5534 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
5538 if (maxsize
< reserve
)
5541 super
->create_offset
= ~((unsigned long long) 0);
5542 if (start
+ reserve
> super
->create_offset
)
5543 return 0; /* start overflows create_offset */
5544 super
->create_offset
= start
+ reserve
;
5546 return maxsize
- reserve
;
5549 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
5551 if (level
< 0 || level
== 6 || level
== 4)
5554 /* if we have an orom prevent invalid raid levels */
5557 case 0: return imsm_orom_has_raid0(orom
);
5560 return imsm_orom_has_raid1e(orom
);
5561 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
5562 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
5563 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
5566 return 1; /* not on an Intel RAID platform so anything goes */
5572 active_arrays_by_format(char *name
, char* hba
, struct md_list
**devlist
,
5573 int dpa
, int verbose
)
5575 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
5576 struct mdstat_ent
*memb
= NULL
;
5579 struct md_list
*dv
= NULL
;
5582 for (memb
= mdstat
; memb
; memb
= memb
->next
) {
5583 if (memb
->metadata_version
&&
5584 (strncmp(memb
->metadata_version
, "external:", 9) == 0) &&
5585 (strcmp(&memb
->metadata_version
[9], name
) == 0) &&
5586 !is_subarray(memb
->metadata_version
+9) &&
5588 struct dev_member
*dev
= memb
->members
;
5590 while(dev
&& (fd
< 0)) {
5591 char *path
= xmalloc(strlen(dev
->name
) + strlen("/dev/") + 1);
5592 num
= sprintf(path
, "%s%s", "/dev/", dev
->name
);
5594 fd
= open(path
, O_RDONLY
, 0);
5595 if ((num
<= 0) || (fd
< 0)) {
5596 pr_vrb(": Cannot open %s: %s\n",
5597 dev
->name
, strerror(errno
));
5603 if ((fd
>= 0) && disk_attached_to_hba(fd
, hba
)) {
5604 struct mdstat_ent
*vol
;
5605 for (vol
= mdstat
; vol
; vol
= vol
->next
) {
5606 if ((vol
->active
> 0) &&
5607 vol
->metadata_version
&&
5608 is_container_member(vol
, memb
->dev
)) {
5613 if (*devlist
&& (found
< dpa
)) {
5614 dv
= xcalloc(1, sizeof(*dv
));
5615 dv
->devname
= xmalloc(strlen(memb
->dev
) + strlen("/dev/") + 1);
5616 sprintf(dv
->devname
, "%s%s", "/dev/", memb
->dev
);
5619 dv
->next
= *devlist
;
5627 free_mdstat(mdstat
);
5632 static struct md_list
*
5633 get_loop_devices(void)
5636 struct md_list
*devlist
= NULL
;
5637 struct md_list
*dv
= NULL
;
5639 for(i
= 0; i
< 12; i
++) {
5640 dv
= xcalloc(1, sizeof(*dv
));
5641 dv
->devname
= xmalloc(40);
5642 sprintf(dv
->devname
, "/dev/loop%d", i
);
5650 static struct md_list
*
5651 get_devices(const char *hba_path
)
5653 struct md_list
*devlist
= NULL
;
5654 struct md_list
*dv
= NULL
;
5660 devlist
= get_loop_devices();
5663 /* scroll through /sys/dev/block looking for devices attached to
5666 dir
= opendir("/sys/dev/block");
5667 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
5672 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
5674 path
= devt_to_devpath(makedev(major
, minor
));
5677 if (!path_attached_to_hba(path
, hba_path
)) {
5684 fd
= dev_open(ent
->d_name
, O_RDONLY
);
5686 fd2devname(fd
, buf
);
5689 pr_err("cannot open device: %s\n",
5694 dv
= xcalloc(1, sizeof(*dv
));
5695 dv
->devname
= xstrdup(buf
);
5702 devlist
= devlist
->next
;
5712 count_volumes_list(struct md_list
*devlist
, char *homehost
,
5713 int verbose
, int *found
)
5715 struct md_list
*tmpdev
;
5717 struct supertype
*st
= NULL
;
5719 /* first walk the list of devices to find a consistent set
5720 * that match the criterea, if that is possible.
5721 * We flag the ones we like with 'used'.
5724 st
= match_metadata_desc_imsm("imsm");
5726 pr_vrb(": cannot allocate memory for imsm supertype\n");
5730 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
5731 char *devname
= tmpdev
->devname
;
5733 struct supertype
*tst
;
5735 if (tmpdev
->used
> 1)
5737 tst
= dup_super(st
);
5739 pr_vrb(": cannot allocate memory for imsm supertype\n");
5742 tmpdev
->container
= 0;
5743 dfd
= dev_open(devname
, O_RDONLY
|O_EXCL
);
5745 dprintf(": cannot open device %s: %s\n",
5746 devname
, strerror(errno
));
5748 } else if (fstat(dfd
, &stb
)< 0) {
5750 dprintf(": fstat failed for %s: %s\n",
5751 devname
, strerror(errno
));
5753 } else if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
5754 dprintf(": %s is not a block device.\n",
5757 } else if (must_be_container(dfd
)) {
5758 struct supertype
*cst
;
5759 cst
= super_by_fd(dfd
, NULL
);
5761 dprintf(": cannot recognize container type %s\n",
5764 } else if (tst
->ss
!= st
->ss
) {
5765 dprintf(": non-imsm container - ignore it: %s\n",
5768 } else if (!tst
->ss
->load_container
||
5769 tst
->ss
->load_container(tst
, dfd
, NULL
))
5772 tmpdev
->container
= 1;
5775 cst
->ss
->free_super(cst
);
5777 tmpdev
->st_rdev
= stb
.st_rdev
;
5778 if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
5779 dprintf(": no RAID superblock on %s\n",
5782 } else if (tst
->ss
->compare_super
== NULL
) {
5783 dprintf(": Cannot assemble %s metadata on %s\n",
5784 tst
->ss
->name
, devname
);
5790 if (tmpdev
->used
== 2 || tmpdev
->used
== 4) {
5791 /* Ignore unrecognised devices during auto-assembly */
5796 tst
->ss
->getinfo_super(tst
, &info
, NULL
);
5798 if (st
->minor_version
== -1)
5799 st
->minor_version
= tst
->minor_version
;
5801 if (memcmp(info
.uuid
, uuid_zero
,
5802 sizeof(int[4])) == 0) {
5803 /* this is a floating spare. It cannot define
5804 * an array unless there are no more arrays of
5805 * this type to be found. It can be included
5806 * in an array of this type though.
5812 if (st
->ss
!= tst
->ss
||
5813 st
->minor_version
!= tst
->minor_version
||
5814 st
->ss
->compare_super(st
, tst
) != 0) {
5815 /* Some mismatch. If exactly one array matches this host,
5816 * we can resolve on that one.
5817 * Or, if we are auto assembling, we just ignore the second
5820 dprintf(": superblock on %s doesn't match others - assembly aborted\n",
5826 dprintf("found: devname: %s\n", devname
);
5830 tst
->ss
->free_super(tst
);
5834 if ((err
= load_super_imsm_all(st
, -1, &st
->sb
, NULL
, devlist
, 0)) == 0) {
5835 struct mdinfo
*iter
, *head
= st
->ss
->container_content(st
, NULL
);
5836 for (iter
= head
; iter
; iter
= iter
->next
) {
5837 dprintf("content->text_version: %s vol\n",
5838 iter
->text_version
);
5839 if (iter
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
)) {
5840 /* do not assemble arrays with unsupported
5842 dprintf(": Cannot activate member %s.\n",
5843 iter
->text_version
);
5850 dprintf(" no valid super block on device list: err: %d %p\n",
5854 dprintf(" no more devices to examin\n");
5857 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
5858 if ((tmpdev
->used
== 1) && (tmpdev
->found
)) {
5860 if (count
< tmpdev
->found
)
5863 count
-= tmpdev
->found
;
5866 if (tmpdev
->used
== 1)
5871 st
->ss
->free_super(st
);
5876 count_volumes(char *hba
, int dpa
, int verbose
)
5878 struct md_list
*devlist
= NULL
;
5882 devlist
= get_devices(hba
);
5883 /* if no intel devices return zero volumes */
5884 if (devlist
== NULL
)
5887 count
= active_arrays_by_format("imsm", hba
, &devlist
, dpa
, verbose
);
5888 dprintf(" path: %s active arrays: %d\n", hba
, count
);
5889 if (devlist
== NULL
)
5893 count
+= count_volumes_list(devlist
,
5897 dprintf("found %d count: %d\n", found
, count
);
5900 dprintf("path: %s total number of volumes: %d\n", hba
, count
);
5903 struct md_list
*dv
= devlist
;
5904 devlist
= devlist
->next
;
5911 static int imsm_default_chunk(const struct imsm_orom
*orom
)
5913 /* up to 512 if the plaform supports it, otherwise the platform max.
5914 * 128 if no platform detected
5916 int fs
= max(7, orom
? fls(orom
->sss
) : 0);
5918 return min(512, (1 << fs
));
5922 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
5923 int raiddisks
, int *chunk
, unsigned long long size
, int verbose
)
5925 /* check/set platform and metadata limits/defaults */
5926 if (super
->orom
&& raiddisks
> super
->orom
->dpa
) {
5927 pr_vrb(": platform supports a maximum of %d disks per array\n",
5932 /* capabilities of OROM tested - copied from validate_geometry_imsm_volume */
5933 if (!is_raid_level_supported(super
->orom
, level
, raiddisks
)) {
5934 pr_vrb(": platform does not support raid%d with %d disk%s\n",
5935 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
5939 if (*chunk
== 0 || *chunk
== UnSet
)
5940 *chunk
= imsm_default_chunk(super
->orom
);
5942 if (super
->orom
&& !imsm_orom_has_chunk(super
->orom
, *chunk
)) {
5943 pr_vrb(": platform does not support a chunk size of: "
5948 if (layout
!= imsm_level_to_layout(level
)) {
5950 pr_vrb(": imsm raid 5 only supports the left-asymmetric layout\n");
5951 else if (level
== 10)
5952 pr_vrb(": imsm raid 10 only supports the n2 layout\n");
5954 pr_vrb(": imsm unknown layout %#x for this raid level %d\n",
5959 if (super
->orom
&& (super
->orom
->attr
& IMSM_OROM_ATTR_2TB
) == 0 &&
5960 (calc_array_size(level
, raiddisks
, layout
, *chunk
, size
) >> 32) > 0) {
5961 pr_vrb(": platform does not support a volume size over 2TB\n");
5968 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
5969 * FIX ME add ahci details
5971 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
5972 int layout
, int raiddisks
, int *chunk
,
5973 unsigned long long size
,
5974 unsigned long long data_offset
,
5976 unsigned long long *freesize
,
5980 struct intel_super
*super
= st
->sb
;
5981 struct imsm_super
*mpb
;
5983 unsigned long long pos
= 0;
5984 unsigned long long maxsize
;
5988 /* We must have the container info already read in. */
5992 mpb
= super
->anchor
;
5994 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, size
, verbose
)) {
5995 pr_err("RAID gemetry validation failed. "
5996 "Cannot proceed with the action(s).\n");
6000 /* General test: make sure there is space for
6001 * 'raiddisks' device extents of size 'size' at a given
6004 unsigned long long minsize
= size
;
6005 unsigned long long start_offset
= MaxSector
;
6008 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
6009 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6014 e
= get_extents(super
, dl
);
6017 unsigned long long esize
;
6018 esize
= e
[i
].start
- pos
;
6019 if (esize
>= minsize
)
6021 if (found
&& start_offset
== MaxSector
) {
6024 } else if (found
&& pos
!= start_offset
) {
6028 pos
= e
[i
].start
+ e
[i
].size
;
6030 } while (e
[i
-1].size
);
6035 if (dcnt
< raiddisks
) {
6037 pr_err("imsm: Not enough "
6038 "devices with space for this array "
6046 /* This device must be a member of the set */
6047 if (stat(dev
, &stb
) < 0)
6049 if ((S_IFMT
& stb
.st_mode
) != S_IFBLK
)
6051 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6052 if (dl
->major
== (int)major(stb
.st_rdev
) &&
6053 dl
->minor
== (int)minor(stb
.st_rdev
))
6058 pr_err("%s is not in the "
6059 "same imsm set\n", dev
);
6061 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
6062 /* If a volume is present then the current creation attempt
6063 * cannot incorporate new spares because the orom may not
6064 * understand this configuration (all member disks must be
6065 * members of each array in the container).
6067 pr_err("%s is a spare and a volume"
6068 " is already defined for this container\n", dev
);
6069 pr_err("The option-rom requires all member"
6070 " disks to be a member of all volumes\n");
6072 } else if (super
->orom
&& mpb
->num_raid_devs
> 0 &&
6073 mpb
->num_disks
!= raiddisks
) {
6074 pr_err("The option-rom requires all member"
6075 " disks to be a member of all volumes\n");
6079 /* retrieve the largest free space block */
6080 e
= get_extents(super
, dl
);
6085 unsigned long long esize
;
6087 esize
= e
[i
].start
- pos
;
6088 if (esize
>= maxsize
)
6090 pos
= e
[i
].start
+ e
[i
].size
;
6092 } while (e
[i
-1].size
);
6097 pr_err("unable to determine free space for: %s\n",
6101 if (maxsize
< size
) {
6103 pr_err("%s not enough space (%llu < %llu)\n",
6104 dev
, maxsize
, size
);
6108 /* count total number of extents for merge */
6110 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6112 i
+= dl
->extent_cnt
;
6114 maxsize
= merge_extents(super
, i
);
6116 if (!check_env("IMSM_NO_PLATFORM") &&
6117 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
6118 pr_err("attempting to create a second "
6119 "volume with size less then remaining space. "
6124 if (maxsize
< size
|| maxsize
== 0) {
6127 pr_err("no free space"
6128 " left on device. Aborting...\n");
6130 pr_err("not enough space"
6131 " to create volume of given size"
6132 " (%llu < %llu). Aborting...\n",
6138 *freesize
= maxsize
;
6141 int count
= count_volumes(super
->hba
->path
,
6142 super
->orom
->dpa
, verbose
);
6143 if (super
->orom
->vphba
<= count
) {
6144 pr_vrb(": platform does not support more than %d raid volumes.\n",
6145 super
->orom
->vphba
);
6152 static int imsm_get_free_size(struct supertype
*st
, int raiddisks
,
6153 unsigned long long size
, int chunk
,
6154 unsigned long long *freesize
)
6156 struct intel_super
*super
= st
->sb
;
6157 struct imsm_super
*mpb
= super
->anchor
;
6162 unsigned long long maxsize
;
6163 unsigned long long minsize
;
6167 /* find the largest common start free region of the possible disks */
6171 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6177 /* don't activate new spares if we are orom constrained
6178 * and there is already a volume active in the container
6180 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
6183 e
= get_extents(super
, dl
);
6186 for (i
= 1; e
[i
-1].size
; i
++)
6194 maxsize
= merge_extents(super
, extent_cnt
);
6198 minsize
= chunk
* 2;
6200 if (cnt
< raiddisks
||
6201 (super
->orom
&& used
&& used
!= raiddisks
) ||
6202 maxsize
< minsize
||
6204 pr_err("not enough devices with space to create array.\n");
6205 return 0; /* No enough free spaces large enough */
6216 if (!check_env("IMSM_NO_PLATFORM") &&
6217 mpb
->num_raid_devs
> 0 && size
&& size
!= maxsize
) {
6218 pr_err("attempting to create a second "
6219 "volume with size less then remaining space. "
6224 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6226 dl
->raiddisk
= cnt
++;
6230 dprintf("imsm: imsm_get_free_size() returns : %llu\n", size
);
6235 static int reserve_space(struct supertype
*st
, int raiddisks
,
6236 unsigned long long size
, int chunk
,
6237 unsigned long long *freesize
)
6239 struct intel_super
*super
= st
->sb
;
6244 rv
= imsm_get_free_size(st
, raiddisks
, size
, chunk
, freesize
);
6247 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6249 dl
->raiddisk
= cnt
++;
6256 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
6257 int raiddisks
, int *chunk
, unsigned long long size
,
6258 unsigned long long data_offset
,
6259 char *dev
, unsigned long long *freesize
,
6267 * if given unused devices create a container
6268 * if given given devices in a container create a member volume
6270 if (level
== LEVEL_CONTAINER
) {
6271 /* Must be a fresh device to add to a container */
6272 return validate_geometry_imsm_container(st
, level
, layout
,
6282 struct intel_super
*super
= st
->sb
;
6283 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
6284 raiddisks
, chunk
, size
,
6287 /* we are being asked to automatically layout a
6288 * new volume based on the current contents of
6289 * the container. If the the parameters can be
6290 * satisfied reserve_space will record the disks,
6291 * start offset, and size of the volume to be
6292 * created. add_to_super and getinfo_super
6293 * detect when autolayout is in progress.
6295 /* assuming that freesize is always given when array is
6297 if (super
->orom
&& freesize
) {
6299 count
= count_volumes(super
->hba
->path
,
6300 super
->orom
->dpa
, verbose
);
6301 if (super
->orom
->vphba
<= count
) {
6302 pr_vrb(": platform does not support more"
6303 " than %d raid volumes.\n",
6304 super
->orom
->vphba
);
6309 return reserve_space(st
, raiddisks
, size
,
6315 /* creating in a given container */
6316 return validate_geometry_imsm_volume(st
, level
, layout
,
6317 raiddisks
, chunk
, size
,
6319 dev
, freesize
, verbose
);
6322 /* This device needs to be a device in an 'imsm' container */
6323 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
6326 pr_err("Cannot create this array on device %s\n",
6331 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
6333 pr_err("Cannot open %s: %s\n",
6334 dev
, strerror(errno
));
6337 /* Well, it is in use by someone, maybe an 'imsm' container. */
6338 cfd
= open_container(fd
);
6342 pr_err("Cannot use %s: It is busy\n",
6346 sra
= sysfs_read(cfd
, NULL
, GET_VERSION
);
6347 if (sra
&& sra
->array
.major_version
== -1 &&
6348 strcmp(sra
->text_version
, "imsm") == 0)
6352 /* This is a member of a imsm container. Load the container
6353 * and try to create a volume
6355 struct intel_super
*super
;
6357 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
, NULL
, 1) == 0) {
6359 strcpy(st
->container_devnm
, fd2devnm(cfd
));
6361 return validate_geometry_imsm_volume(st
, level
, layout
,
6363 size
, data_offset
, dev
,
6370 pr_err("failed container membership check\n");
6376 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
6378 struct intel_super
*super
= st
->sb
;
6380 if (level
&& *level
== UnSet
)
6381 *level
= LEVEL_CONTAINER
;
6383 if (level
&& layout
&& *layout
== UnSet
)
6384 *layout
= imsm_level_to_layout(*level
);
6386 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0))
6387 *chunk
= imsm_default_chunk(super
->orom
);
6390 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
6392 static int kill_subarray_imsm(struct supertype
*st
)
6394 /* remove the subarray currently referenced by ->current_vol */
6396 struct intel_dev
**dp
;
6397 struct intel_super
*super
= st
->sb
;
6398 __u8 current_vol
= super
->current_vol
;
6399 struct imsm_super
*mpb
= super
->anchor
;
6401 if (super
->current_vol
< 0)
6403 super
->current_vol
= -1; /* invalidate subarray cursor */
6405 /* block deletions that would change the uuid of active subarrays
6407 * FIXME when immutable ids are available, but note that we'll
6408 * also need to fixup the invalidated/active subarray indexes in
6411 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6414 if (i
< current_vol
)
6416 sprintf(subarray
, "%u", i
);
6417 if (is_subarray_active(subarray
, st
->devnm
)) {
6418 pr_err("deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
6425 if (st
->update_tail
) {
6426 struct imsm_update_kill_array
*u
= xmalloc(sizeof(*u
));
6428 u
->type
= update_kill_array
;
6429 u
->dev_idx
= current_vol
;
6430 append_metadata_update(st
, u
, sizeof(*u
));
6435 for (dp
= &super
->devlist
; *dp
;)
6436 if ((*dp
)->index
== current_vol
) {
6439 handle_missing(super
, (*dp
)->dev
);
6440 if ((*dp
)->index
> current_vol
)
6445 /* no more raid devices, all active components are now spares,
6446 * but of course failed are still failed
6448 if (--mpb
->num_raid_devs
== 0) {
6451 for (d
= super
->disks
; d
; d
= d
->next
)
6456 super
->updates_pending
++;
6461 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
6462 char *update
, struct mddev_ident
*ident
)
6464 /* update the subarray currently referenced by ->current_vol */
6465 struct intel_super
*super
= st
->sb
;
6466 struct imsm_super
*mpb
= super
->anchor
;
6468 if (strcmp(update
, "name") == 0) {
6469 char *name
= ident
->name
;
6473 if (is_subarray_active(subarray
, st
->devnm
)) {
6474 pr_err("Unable to update name of active subarray\n");
6478 if (!check_name(super
, name
, 0))
6481 vol
= strtoul(subarray
, &ep
, 10);
6482 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
6485 if (st
->update_tail
) {
6486 struct imsm_update_rename_array
*u
= xmalloc(sizeof(*u
));
6488 u
->type
= update_rename_array
;
6490 snprintf((char *) u
->name
, MAX_RAID_SERIAL_LEN
, "%s", name
);
6491 append_metadata_update(st
, u
, sizeof(*u
));
6493 struct imsm_dev
*dev
;
6496 dev
= get_imsm_dev(super
, vol
);
6497 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
6498 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6499 dev
= get_imsm_dev(super
, i
);
6500 handle_missing(super
, dev
);
6502 super
->updates_pending
++;
6509 #endif /* MDASSEMBLE */
6511 static int is_gen_migration(struct imsm_dev
*dev
)
6516 if (!dev
->vol
.migr_state
)
6519 if (migr_type(dev
) == MIGR_GEN_MIGR
)
6525 static int is_rebuilding(struct imsm_dev
*dev
)
6527 struct imsm_map
*migr_map
;
6529 if (!dev
->vol
.migr_state
)
6532 if (migr_type(dev
) != MIGR_REBUILD
)
6535 migr_map
= get_imsm_map(dev
, MAP_1
);
6537 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
6544 static int is_initializing(struct imsm_dev
*dev
)
6546 struct imsm_map
*migr_map
;
6548 if (!dev
->vol
.migr_state
)
6551 if (migr_type(dev
) != MIGR_INIT
)
6554 migr_map
= get_imsm_map(dev
, MAP_1
);
6556 if (migr_map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
6563 static void update_recovery_start(struct intel_super
*super
,
6564 struct imsm_dev
*dev
,
6565 struct mdinfo
*array
)
6567 struct mdinfo
*rebuild
= NULL
;
6571 if (!is_rebuilding(dev
))
6574 /* Find the rebuild target, but punt on the dual rebuild case */
6575 for (d
= array
->devs
; d
; d
= d
->next
)
6576 if (d
->recovery_start
== 0) {
6583 /* (?) none of the disks are marked with
6584 * IMSM_ORD_REBUILD, so assume they are missing and the
6585 * disk_ord_tbl was not correctly updated
6587 dprintf("%s: failed to locate out-of-sync disk\n", __func__
);
6591 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
6592 rebuild
->recovery_start
= units
* blocks_per_migr_unit(super
, dev
);
6596 static int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
);
6599 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
6601 /* Given a container loaded by load_super_imsm_all,
6602 * extract information about all the arrays into
6604 * If 'subarray' is given, just extract info about that array.
6606 * For each imsm_dev create an mdinfo, fill it in,
6607 * then look for matching devices in super->disks
6608 * and create appropriate device mdinfo.
6610 struct intel_super
*super
= st
->sb
;
6611 struct imsm_super
*mpb
= super
->anchor
;
6612 struct mdinfo
*rest
= NULL
;
6616 int spare_disks
= 0;
6618 /* do not assemble arrays when not all attributes are supported */
6619 if (imsm_check_attributes(mpb
->attributes
) == 0) {
6621 pr_err("Unsupported attributes in IMSM metadata."
6622 "Arrays activation is blocked.\n");
6625 /* check for bad blocks */
6626 if (imsm_bbm_log_size(super
->anchor
)) {
6627 pr_err("BBM log found in IMSM metadata."
6628 "Arrays activation is blocked.\n");
6632 /* count spare devices, not used in maps
6634 for (d
= super
->disks
; d
; d
= d
->next
)
6638 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6639 struct imsm_dev
*dev
;
6640 struct imsm_map
*map
;
6641 struct imsm_map
*map2
;
6642 struct mdinfo
*this;
6650 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
6653 dev
= get_imsm_dev(super
, i
);
6654 map
= get_imsm_map(dev
, MAP_0
);
6655 map2
= get_imsm_map(dev
, MAP_1
);
6657 /* do not publish arrays that are in the middle of an
6658 * unsupported migration
6660 if (dev
->vol
.migr_state
&&
6661 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
6662 pr_err("cannot assemble volume '%.16s':"
6663 " unsupported migration in progress\n",
6667 /* do not publish arrays that are not support by controller's
6671 this = xmalloc(sizeof(*this));
6673 super
->current_vol
= i
;
6674 getinfo_super_imsm_volume(st
, this, NULL
);
6677 chunk
= __le16_to_cpu(map
->blocks_per_strip
) >> 1;
6678 /* mdadm does not support all metadata features- set the bit in all arrays state */
6679 if (!validate_geometry_imsm_orom(super
,
6680 get_imsm_raid_level(map
), /* RAID level */
6681 imsm_level_to_layout(get_imsm_raid_level(map
)),
6682 map
->num_members
, /* raid disks */
6683 &chunk
, join_u32(dev
->size_low
, dev
->size_high
),
6685 pr_err("IMSM RAID geometry validation"
6686 " failed. Array %s activation is blocked.\n",
6688 this->array
.state
|=
6689 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
6690 (1<<MD_SB_BLOCK_VOLUME
);
6694 /* if array has bad blocks, set suitable bit in all arrays state */
6696 this->array
.state
|=
6697 (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
) |
6698 (1<<MD_SB_BLOCK_VOLUME
);
6700 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
6701 unsigned long long recovery_start
;
6702 struct mdinfo
*info_d
;
6709 idx
= get_imsm_disk_idx(dev
, slot
, MAP_0
);
6710 ord
= get_imsm_ord_tbl_ent(dev
, slot
, MAP_X
);
6711 for (d
= super
->disks
; d
; d
= d
->next
)
6712 if (d
->index
== idx
)
6715 recovery_start
= MaxSector
;
6718 if (d
&& is_failed(&d
->disk
))
6720 if (ord
& IMSM_ORD_REBUILD
)
6724 * if we skip some disks the array will be assmebled degraded;
6725 * reset resync start to avoid a dirty-degraded
6726 * situation when performing the intial sync
6728 * FIXME handle dirty degraded
6730 if ((skip
|| recovery_start
== 0) && !dev
->vol
.dirty
)
6731 this->resync_start
= MaxSector
;
6735 info_d
= xcalloc(1, sizeof(*info_d
));
6736 info_d
->next
= this->devs
;
6737 this->devs
= info_d
;
6739 info_d
->disk
.number
= d
->index
;
6740 info_d
->disk
.major
= d
->major
;
6741 info_d
->disk
.minor
= d
->minor
;
6742 info_d
->disk
.raid_disk
= slot
;
6743 info_d
->recovery_start
= recovery_start
;
6745 if (slot
< map2
->num_members
)
6746 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
6748 this->array
.spare_disks
++;
6750 if (slot
< map
->num_members
)
6751 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
6753 this->array
.spare_disks
++;
6755 if (info_d
->recovery_start
== MaxSector
)
6756 this->array
.working_disks
++;
6758 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
6759 info_d
->data_offset
= pba_of_lba0(map
);
6760 info_d
->component_size
= blocks_per_member(map
);
6762 /* now that the disk list is up-to-date fixup recovery_start */
6763 update_recovery_start(super
, dev
, this);
6764 this->array
.spare_disks
+= spare_disks
;
6767 /* check for reshape */
6768 if (this->reshape_active
== 1)
6769 recover_backup_imsm(st
, this);
6777 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
,
6778 int failed
, int look_in_map
)
6780 struct imsm_map
*map
;
6782 map
= get_imsm_map(dev
, look_in_map
);
6785 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
6786 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
6788 switch (get_imsm_raid_level(map
)) {
6790 return IMSM_T_STATE_FAILED
;
6793 if (failed
< map
->num_members
)
6794 return IMSM_T_STATE_DEGRADED
;
6796 return IMSM_T_STATE_FAILED
;
6801 * check to see if any mirrors have failed, otherwise we
6802 * are degraded. Even numbered slots are mirrored on
6806 /* gcc -Os complains that this is unused */
6807 int insync
= insync
;
6809 for (i
= 0; i
< map
->num_members
; i
++) {
6810 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, MAP_X
);
6811 int idx
= ord_to_idx(ord
);
6812 struct imsm_disk
*disk
;
6814 /* reset the potential in-sync count on even-numbered
6815 * slots. num_copies is always 2 for imsm raid10
6820 disk
= get_imsm_disk(super
, idx
);
6821 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
6824 /* no in-sync disks left in this mirror the
6828 return IMSM_T_STATE_FAILED
;
6831 return IMSM_T_STATE_DEGRADED
;
6835 return IMSM_T_STATE_DEGRADED
;
6837 return IMSM_T_STATE_FAILED
;
6843 return map
->map_state
;
6846 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
,
6851 struct imsm_disk
*disk
;
6852 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
6853 struct imsm_map
*prev
= get_imsm_map(dev
, MAP_1
);
6854 struct imsm_map
*map_for_loop
;
6859 /* at the beginning of migration we set IMSM_ORD_REBUILD on
6860 * disks that are being rebuilt. New failures are recorded to
6861 * map[0]. So we look through all the disks we started with and
6862 * see if any failures are still present, or if any new ones
6866 if (prev
&& (map
->num_members
< prev
->num_members
))
6867 map_for_loop
= prev
;
6869 for (i
= 0; i
< map_for_loop
->num_members
; i
++) {
6871 /* when MAP_X is passed both maps failures are counted
6874 ((look_in_map
== MAP_1
) || (look_in_map
== MAP_X
)) &&
6875 (i
< prev
->num_members
)) {
6876 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
6877 idx_1
= ord_to_idx(ord
);
6879 disk
= get_imsm_disk(super
, idx_1
);
6880 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
6883 if (((look_in_map
== MAP_0
) || (look_in_map
== MAP_X
)) &&
6884 (i
< map
->num_members
)) {
6885 ord
= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
6886 idx
= ord_to_idx(ord
);
6889 disk
= get_imsm_disk(super
, idx
);
6890 if (!disk
|| is_failed(disk
) ||
6891 ord
& IMSM_ORD_REBUILD
)
6901 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
6904 struct intel_super
*super
= c
->sb
;
6905 struct imsm_super
*mpb
= super
->anchor
;
6907 if (atoi(inst
) >= mpb
->num_raid_devs
) {
6908 pr_err("%s: subarry index %d, out of range\n",
6909 __func__
, atoi(inst
));
6913 dprintf("imsm: open_new %s\n", inst
);
6914 a
->info
.container_member
= atoi(inst
);
6918 static int is_resyncing(struct imsm_dev
*dev
)
6920 struct imsm_map
*migr_map
;
6922 if (!dev
->vol
.migr_state
)
6925 if (migr_type(dev
) == MIGR_INIT
||
6926 migr_type(dev
) == MIGR_REPAIR
)
6929 if (migr_type(dev
) == MIGR_GEN_MIGR
)
6932 migr_map
= get_imsm_map(dev
, MAP_1
);
6934 if ((migr_map
->map_state
== IMSM_T_STATE_NORMAL
) &&
6935 (dev
->vol
.migr_type
!= MIGR_GEN_MIGR
))
6941 /* return true if we recorded new information */
6942 static int mark_failure(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
6946 struct imsm_map
*map
;
6947 char buf
[MAX_RAID_SERIAL_LEN
+3];
6948 unsigned int len
, shift
= 0;
6950 /* new failures are always set in map[0] */
6951 map
= get_imsm_map(dev
, MAP_0
);
6953 slot
= get_imsm_disk_slot(map
, idx
);
6957 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
6958 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
6961 memcpy(buf
, disk
->serial
, MAX_RAID_SERIAL_LEN
);
6962 buf
[MAX_RAID_SERIAL_LEN
] = '\000';
6964 if ((len
= strlen(buf
)) >= MAX_RAID_SERIAL_LEN
)
6965 shift
= len
- MAX_RAID_SERIAL_LEN
+ 1;
6966 strncpy((char *)disk
->serial
, &buf
[shift
], MAX_RAID_SERIAL_LEN
);
6968 disk
->status
|= FAILED_DISK
;
6969 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
6970 /* mark failures in second map if second map exists and this disk
6972 * This is valid for migration, initialization and rebuild
6974 if (dev
->vol
.migr_state
) {
6975 struct imsm_map
*map2
= get_imsm_map(dev
, MAP_1
);
6976 int slot2
= get_imsm_disk_slot(map2
, idx
);
6978 if ((slot2
< map2
->num_members
) &&
6980 set_imsm_ord_tbl_ent(map2
, slot2
,
6981 idx
| IMSM_ORD_REBUILD
);
6983 if (map
->failed_disk_num
== 0xff)
6984 map
->failed_disk_num
= slot
;
6988 static void mark_missing(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
6990 mark_failure(dev
, disk
, idx
);
6992 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
6995 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
6996 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
6999 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
7003 if (!super
->missing
)
7006 /* When orom adds replacement for missing disk it does
7007 * not remove entry of missing disk, but just updates map with
7008 * new added disk. So it is not enough just to test if there is
7009 * any missing disk, we have to look if there are any failed disks
7010 * in map to stop migration */
7012 dprintf("imsm: mark missing\n");
7013 /* end process for initialization and rebuild only
7015 if (is_gen_migration(dev
) == 0) {
7019 failed
= imsm_count_failed(super
, dev
, MAP_0
);
7020 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7023 end_migration(dev
, super
, map_state
);
7025 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
7026 mark_missing(dev
, &dl
->disk
, dl
->index
);
7027 super
->updates_pending
++;
7030 static unsigned long long imsm_set_array_size(struct imsm_dev
*dev
,
7033 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
7034 unsigned long long array_blocks
;
7035 struct imsm_map
*map
;
7037 if (used_disks
== 0) {
7038 /* when problems occures
7039 * return current array_blocks value
7041 array_blocks
= __le32_to_cpu(dev
->size_high
);
7042 array_blocks
= array_blocks
<< 32;
7043 array_blocks
+= __le32_to_cpu(dev
->size_low
);
7045 return array_blocks
;
7048 /* set array size in metadata
7050 if (new_size
<= 0) {
7051 /* OLCE size change is caused by added disks
7053 map
= get_imsm_map(dev
, MAP_0
);
7054 array_blocks
= blocks_per_member(map
) * used_disks
;
7056 /* Online Volume Size Change
7057 * Using available free space
7059 array_blocks
= new_size
;
7062 /* round array size down to closest MB
7064 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
7065 dev
->size_low
= __cpu_to_le32((__u32
)array_blocks
);
7066 dev
->size_high
= __cpu_to_le32((__u32
)(array_blocks
>> 32));
7068 return array_blocks
;
7071 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
7073 static void imsm_progress_container_reshape(struct intel_super
*super
)
7075 /* if no device has a migr_state, but some device has a
7076 * different number of members than the previous device, start
7077 * changing the number of devices in this device to match
7080 struct imsm_super
*mpb
= super
->anchor
;
7081 int prev_disks
= -1;
7085 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7086 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
7087 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7088 struct imsm_map
*map2
;
7089 int prev_num_members
;
7091 if (dev
->vol
.migr_state
)
7094 if (prev_disks
== -1)
7095 prev_disks
= map
->num_members
;
7096 if (prev_disks
== map
->num_members
)
7099 /* OK, this array needs to enter reshape mode.
7100 * i.e it needs a migr_state
7103 copy_map_size
= sizeof_imsm_map(map
);
7104 prev_num_members
= map
->num_members
;
7105 map
->num_members
= prev_disks
;
7106 dev
->vol
.migr_state
= 1;
7107 dev
->vol
.curr_migr_unit
= 0;
7108 set_migr_type(dev
, MIGR_GEN_MIGR
);
7109 for (i
= prev_num_members
;
7110 i
< map
->num_members
; i
++)
7111 set_imsm_ord_tbl_ent(map
, i
, i
);
7112 map2
= get_imsm_map(dev
, MAP_1
);
7113 /* Copy the current map */
7114 memcpy(map2
, map
, copy_map_size
);
7115 map2
->num_members
= prev_num_members
;
7117 imsm_set_array_size(dev
, -1);
7118 super
->clean_migration_record_by_mdmon
= 1;
7119 super
->updates_pending
++;
7123 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
7124 * states are handled in imsm_set_disk() with one exception, when a
7125 * resync is stopped due to a new failure this routine will set the
7126 * 'degraded' state for the array.
7128 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
7130 int inst
= a
->info
.container_member
;
7131 struct intel_super
*super
= a
->container
->sb
;
7132 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7133 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7134 int failed
= imsm_count_failed(super
, dev
, MAP_0
);
7135 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7136 __u32 blocks_per_unit
;
7138 if (dev
->vol
.migr_state
&&
7139 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
7140 /* array state change is blocked due to reshape action
7142 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
7143 * - finish the reshape (if last_checkpoint is big and action != reshape)
7144 * - update curr_migr_unit
7146 if (a
->curr_action
== reshape
) {
7147 /* still reshaping, maybe update curr_migr_unit */
7148 goto mark_checkpoint
;
7150 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
7151 /* for some reason we aborted the reshape.
7153 * disable automatic metadata rollback
7154 * user action is required to recover process
7157 struct imsm_map
*map2
=
7158 get_imsm_map(dev
, MAP_1
);
7159 dev
->vol
.migr_state
= 0;
7160 set_migr_type(dev
, 0);
7161 dev
->vol
.curr_migr_unit
= 0;
7163 sizeof_imsm_map(map2
));
7164 super
->updates_pending
++;
7167 if (a
->last_checkpoint
>= a
->info
.component_size
) {
7168 unsigned long long array_blocks
;
7172 used_disks
= imsm_num_data_members(dev
, MAP_0
);
7173 if (used_disks
> 0) {
7175 blocks_per_member(map
) *
7177 /* round array size down to closest MB
7179 array_blocks
= (array_blocks
7180 >> SECT_PER_MB_SHIFT
)
7181 << SECT_PER_MB_SHIFT
;
7182 a
->info
.custom_array_size
= array_blocks
;
7183 /* encourage manager to update array
7187 a
->check_reshape
= 1;
7189 /* finalize online capacity expansion/reshape */
7190 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
7192 mdi
->disk
.raid_disk
,
7195 imsm_progress_container_reshape(super
);
7200 /* before we activate this array handle any missing disks */
7201 if (consistent
== 2)
7202 handle_missing(super
, dev
);
7204 if (consistent
== 2 &&
7205 (!is_resync_complete(&a
->info
) ||
7206 map_state
!= IMSM_T_STATE_NORMAL
||
7207 dev
->vol
.migr_state
))
7210 if (is_resync_complete(&a
->info
)) {
7211 /* complete intialization / resync,
7212 * recovery and interrupted recovery is completed in
7215 if (is_resyncing(dev
)) {
7216 dprintf("imsm: mark resync done\n");
7217 end_migration(dev
, super
, map_state
);
7218 super
->updates_pending
++;
7219 a
->last_checkpoint
= 0;
7221 } else if ((!is_resyncing(dev
) && !failed
) &&
7222 (imsm_reshape_blocks_arrays_changes(super
) == 0)) {
7223 /* mark the start of the init process if nothing is failed */
7224 dprintf("imsm: mark resync start\n");
7225 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
7226 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
7228 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
7229 super
->updates_pending
++;
7233 /* skip checkpointing for general migration,
7234 * it is controlled in mdadm
7236 if (is_gen_migration(dev
))
7237 goto skip_mark_checkpoint
;
7239 /* check if we can update curr_migr_unit from resync_start, recovery_start */
7240 blocks_per_unit
= blocks_per_migr_unit(super
, dev
);
7241 if (blocks_per_unit
) {
7245 units
= a
->last_checkpoint
/ blocks_per_unit
;
7248 /* check that we did not overflow 32-bits, and that
7249 * curr_migr_unit needs updating
7251 if (units32
== units
&&
7253 __le32_to_cpu(dev
->vol
.curr_migr_unit
) != units32
) {
7254 dprintf("imsm: mark checkpoint (%u)\n", units32
);
7255 dev
->vol
.curr_migr_unit
= __cpu_to_le32(units32
);
7256 super
->updates_pending
++;
7260 skip_mark_checkpoint
:
7261 /* mark dirty / clean */
7262 if (dev
->vol
.dirty
!= !consistent
) {
7263 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
7268 super
->updates_pending
++;
7274 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
7276 int inst
= a
->info
.container_member
;
7277 struct intel_super
*super
= a
->container
->sb
;
7278 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7279 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7280 struct imsm_disk
*disk
;
7282 int recovery_not_finished
= 0;
7287 if (n
> map
->num_members
)
7288 pr_err("imsm: set_disk %d out of range 0..%d\n",
7289 n
, map
->num_members
- 1);
7294 dprintf("imsm: set_disk %d:%x\n", n
, state
);
7296 ord
= get_imsm_ord_tbl_ent(dev
, n
, MAP_0
);
7297 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
7299 /* check for new failures */
7300 if (state
& DS_FAULTY
) {
7301 if (mark_failure(dev
, disk
, ord_to_idx(ord
)))
7302 super
->updates_pending
++;
7305 /* check if in_sync */
7306 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
7307 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
7309 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
7310 super
->updates_pending
++;
7313 failed
= imsm_count_failed(super
, dev
, MAP_0
);
7314 map_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
7316 /* check if recovery complete, newly degraded, or failed */
7317 dprintf("imsm: Detected transition to state ");
7318 switch (map_state
) {
7319 case IMSM_T_STATE_NORMAL
: /* transition to normal state */
7320 dprintf("normal: ");
7321 if (is_rebuilding(dev
)) {
7322 dprintf("while rebuilding");
7323 /* check if recovery is really finished */
7324 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
7325 if (mdi
->recovery_start
!= MaxSector
) {
7326 recovery_not_finished
= 1;
7329 if (recovery_not_finished
) {
7330 dprintf("\nimsm: Rebuild has not finished yet, "
7331 "state not changed");
7332 if (a
->last_checkpoint
< mdi
->recovery_start
) {
7333 a
->last_checkpoint
= mdi
->recovery_start
;
7334 super
->updates_pending
++;
7338 end_migration(dev
, super
, map_state
);
7339 map
= get_imsm_map(dev
, MAP_0
);
7340 map
->failed_disk_num
= ~0;
7341 super
->updates_pending
++;
7342 a
->last_checkpoint
= 0;
7345 if (is_gen_migration(dev
)) {
7346 dprintf("while general migration");
7347 if (a
->last_checkpoint
>= a
->info
.component_size
)
7348 end_migration(dev
, super
, map_state
);
7350 map
->map_state
= map_state
;
7351 map
= get_imsm_map(dev
, MAP_0
);
7352 map
->failed_disk_num
= ~0;
7353 super
->updates_pending
++;
7357 case IMSM_T_STATE_DEGRADED
: /* transition to degraded state */
7358 dprintf("degraded: ");
7359 if ((map
->map_state
!= map_state
) &&
7360 !dev
->vol
.migr_state
) {
7361 dprintf("mark degraded");
7362 map
->map_state
= map_state
;
7363 super
->updates_pending
++;
7364 a
->last_checkpoint
= 0;
7367 if (is_rebuilding(dev
)) {
7368 dprintf("while rebuilding.");
7369 if (map
->map_state
!= map_state
) {
7370 dprintf(" Map state change");
7371 end_migration(dev
, super
, map_state
);
7372 super
->updates_pending
++;
7376 if (is_gen_migration(dev
)) {
7377 dprintf("while general migration");
7378 if (a
->last_checkpoint
>= a
->info
.component_size
)
7379 end_migration(dev
, super
, map_state
);
7381 map
->map_state
= map_state
;
7382 manage_second_map(super
, dev
);
7384 super
->updates_pending
++;
7387 if (is_initializing(dev
)) {
7388 dprintf("while initialization.");
7389 map
->map_state
= map_state
;
7390 super
->updates_pending
++;
7394 case IMSM_T_STATE_FAILED
: /* transition to failed state */
7395 dprintf("failed: ");
7396 if (is_gen_migration(dev
)) {
7397 dprintf("while general migration");
7398 map
->map_state
= map_state
;
7399 super
->updates_pending
++;
7402 if (map
->map_state
!= map_state
) {
7403 dprintf("mark failed");
7404 end_migration(dev
, super
, map_state
);
7405 super
->updates_pending
++;
7406 a
->last_checkpoint
= 0;
7411 dprintf("state %i\n", map_state
);
7417 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
7420 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
7421 unsigned long long dsize
;
7422 unsigned long long sectors
;
7424 get_dev_size(fd
, NULL
, &dsize
);
7426 if (mpb_size
> 512) {
7427 /* -1 to account for anchor */
7428 sectors
= mpb_sectors(mpb
) - 1;
7430 /* write the extended mpb to the sectors preceeding the anchor */
7431 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0)
7434 if ((unsigned long long)write(fd
, buf
+ 512, 512 * sectors
)
7439 /* first block is stored on second to last sector of the disk */
7440 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0)
7443 if (write(fd
, buf
, 512) != 512)
7449 static void imsm_sync_metadata(struct supertype
*container
)
7451 struct intel_super
*super
= container
->sb
;
7453 dprintf("sync metadata: %d\n", super
->updates_pending
);
7454 if (!super
->updates_pending
)
7457 write_super_imsm(container
, 0);
7459 super
->updates_pending
= 0;
7462 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
7464 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
7465 int i
= get_imsm_disk_idx(dev
, idx
, MAP_X
);
7468 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7472 if (dl
&& is_failed(&dl
->disk
))
7476 dprintf("%s: found %x:%x\n", __func__
, dl
->major
, dl
->minor
);
7481 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
7482 struct active_array
*a
, int activate_new
,
7483 struct mdinfo
*additional_test_list
)
7485 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
7486 int idx
= get_imsm_disk_idx(dev
, slot
, MAP_X
);
7487 struct imsm_super
*mpb
= super
->anchor
;
7488 struct imsm_map
*map
;
7489 unsigned long long pos
;
7494 __u32 array_start
= 0;
7495 __u32 array_end
= 0;
7497 struct mdinfo
*test_list
;
7499 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7500 /* If in this array, skip */
7501 for (d
= a
->info
.devs
; d
; d
= d
->next
)
7502 if (d
->state_fd
>= 0 &&
7503 d
->disk
.major
== dl
->major
&&
7504 d
->disk
.minor
== dl
->minor
) {
7505 dprintf("%x:%x already in array\n",
7506 dl
->major
, dl
->minor
);
7511 test_list
= additional_test_list
;
7513 if (test_list
->disk
.major
== dl
->major
&&
7514 test_list
->disk
.minor
== dl
->minor
) {
7515 dprintf("%x:%x already in additional test list\n",
7516 dl
->major
, dl
->minor
);
7519 test_list
= test_list
->next
;
7524 /* skip in use or failed drives */
7525 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
7527 dprintf("%x:%x status (failed: %d index: %d)\n",
7528 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
7532 /* skip pure spares when we are looking for partially
7533 * assimilated drives
7535 if (dl
->index
== -1 && !activate_new
)
7538 /* Does this unused device have the requisite free space?
7539 * It needs to be able to cover all member volumes
7541 ex
= get_extents(super
, dl
);
7543 dprintf("cannot get extents\n");
7546 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7547 dev
= get_imsm_dev(super
, i
);
7548 map
= get_imsm_map(dev
, MAP_0
);
7550 /* check if this disk is already a member of
7553 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
7559 array_start
= pba_of_lba0(map
);
7560 array_end
= array_start
+
7561 blocks_per_member(map
) - 1;
7564 /* check that we can start at pba_of_lba0 with
7565 * blocks_per_member of space
7567 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
7571 pos
= ex
[j
].start
+ ex
[j
].size
;
7573 } while (ex
[j
-1].size
);
7580 if (i
< mpb
->num_raid_devs
) {
7581 dprintf("%x:%x does not have %u to %u available\n",
7582 dl
->major
, dl
->minor
, array_start
, array_end
);
7592 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
7594 struct imsm_dev
*dev2
;
7595 struct imsm_map
*map
;
7601 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
7603 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
, MAP_0
);
7604 if (state
== IMSM_T_STATE_FAILED
) {
7605 map
= get_imsm_map(dev2
, MAP_0
);
7608 for (slot
= 0; slot
< map
->num_members
; slot
++) {
7610 * Check if failed disks are deleted from intel
7611 * disk list or are marked to be deleted
7613 idx
= get_imsm_disk_idx(dev2
, slot
, MAP_X
);
7614 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
7616 * Do not rebuild the array if failed disks
7617 * from failed sub-array are not removed from
7621 is_failed(&idisk
->disk
) &&
7622 (idisk
->action
!= DISK_REMOVE
))
7630 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
7631 struct metadata_update
**updates
)
7634 * Find a device with unused free space and use it to replace a
7635 * failed/vacant region in an array. We replace failed regions one a
7636 * array at a time. The result is that a new spare disk will be added
7637 * to the first failed array and after the monitor has finished
7638 * propagating failures the remainder will be consumed.
7640 * FIXME add a capability for mdmon to request spares from another
7644 struct intel_super
*super
= a
->container
->sb
;
7645 int inst
= a
->info
.container_member
;
7646 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
7647 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7648 int failed
= a
->info
.array
.raid_disks
;
7649 struct mdinfo
*rv
= NULL
;
7652 struct metadata_update
*mu
;
7654 struct imsm_update_activate_spare
*u
;
7659 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
7660 if ((d
->curr_state
& DS_FAULTY
) &&
7662 /* wait for Removal to happen */
7664 if (d
->state_fd
>= 0)
7668 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
7669 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
7671 if (imsm_reshape_blocks_arrays_changes(super
))
7674 /* Cannot activate another spare if rebuild is in progress already
7676 if (is_rebuilding(dev
)) {
7677 dprintf("imsm: No spare activation allowed. "
7678 "Rebuild in progress already.\n");
7682 if (a
->info
.array
.level
== 4)
7683 /* No repair for takeovered array
7684 * imsm doesn't support raid4
7688 if (imsm_check_degraded(super
, dev
, failed
, MAP_0
) !=
7689 IMSM_T_STATE_DEGRADED
)
7693 * If there are any failed disks check state of the other volume.
7694 * Block rebuild if the another one is failed until failed disks
7695 * are removed from container.
7698 dprintf("found failed disks in %.*s, check if there another"
7699 "failed sub-array.\n",
7700 MAX_RAID_SERIAL_LEN
, dev
->volume
);
7701 /* check if states of the other volumes allow for rebuild */
7702 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
7704 allowed
= imsm_rebuild_allowed(a
->container
,
7712 /* For each slot, if it is not working, find a spare */
7713 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
7714 for (d
= a
->info
.devs
; d
; d
= d
->next
)
7715 if (d
->disk
.raid_disk
== i
)
7717 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
7718 if (d
&& (d
->state_fd
>= 0))
7722 * OK, this device needs recovery. Try to re-add the
7723 * previous occupant of this slot, if this fails see if
7724 * we can continue the assimilation of a spare that was
7725 * partially assimilated, finally try to activate a new
7728 dl
= imsm_readd(super
, i
, a
);
7730 dl
= imsm_add_spare(super
, i
, a
, 0, rv
);
7732 dl
= imsm_add_spare(super
, i
, a
, 1, rv
);
7736 /* found a usable disk with enough space */
7737 di
= xcalloc(1, sizeof(*di
));
7739 /* dl->index will be -1 in the case we are activating a
7740 * pristine spare. imsm_process_update() will create a
7741 * new index in this case. Once a disk is found to be
7742 * failed in all member arrays it is kicked from the
7745 di
->disk
.number
= dl
->index
;
7747 /* (ab)use di->devs to store a pointer to the device
7750 di
->devs
= (struct mdinfo
*) dl
;
7752 di
->disk
.raid_disk
= i
;
7753 di
->disk
.major
= dl
->major
;
7754 di
->disk
.minor
= dl
->minor
;
7756 di
->recovery_start
= 0;
7757 di
->data_offset
= pba_of_lba0(map
);
7758 di
->component_size
= a
->info
.component_size
;
7759 di
->container_member
= inst
;
7760 super
->random
= random32();
7764 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
7765 i
, di
->data_offset
);
7769 /* No spares found */
7771 /* Now 'rv' has a list of devices to return.
7772 * Create a metadata_update record to update the
7773 * disk_ord_tbl for the array
7775 mu
= xmalloc(sizeof(*mu
));
7776 mu
->buf
= xcalloc(num_spares
,
7777 sizeof(struct imsm_update_activate_spare
));
7779 mu
->space_list
= NULL
;
7780 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
7781 mu
->next
= *updates
;
7782 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
7784 for (di
= rv
; di
; di
= di
->next
) {
7785 u
->type
= update_activate_spare
;
7786 u
->dl
= (struct dl
*) di
->devs
;
7788 u
->slot
= di
->disk
.raid_disk
;
7799 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
7801 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
7802 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
7803 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, MAP_0
);
7804 struct disk_info
*inf
= get_disk_info(u
);
7805 struct imsm_disk
*disk
;
7809 for (i
= 0; i
< map
->num_members
; i
++) {
7810 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, MAP_X
));
7811 for (j
= 0; j
< new_map
->num_members
; j
++)
7812 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
7819 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
7821 struct dl
*dl
= NULL
;
7822 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7823 if ((dl
->major
== major
) && (dl
->minor
== minor
))
7828 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
7830 struct dl
*prev
= NULL
;
7834 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
7835 if ((dl
->major
== major
) && (dl
->minor
== minor
)) {
7838 prev
->next
= dl
->next
;
7840 super
->disks
= dl
->next
;
7842 __free_imsm_disk(dl
);
7843 dprintf("%s: removed %x:%x\n",
7844 __func__
, major
, minor
);
7852 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
7854 static int add_remove_disk_update(struct intel_super
*super
)
7856 int check_degraded
= 0;
7857 struct dl
*disk
= NULL
;
7858 /* add/remove some spares to/from the metadata/contrainer */
7859 while (super
->disk_mgmt_list
) {
7860 struct dl
*disk_cfg
;
7862 disk_cfg
= super
->disk_mgmt_list
;
7863 super
->disk_mgmt_list
= disk_cfg
->next
;
7864 disk_cfg
->next
= NULL
;
7866 if (disk_cfg
->action
== DISK_ADD
) {
7867 disk_cfg
->next
= super
->disks
;
7868 super
->disks
= disk_cfg
;
7870 dprintf("%s: added %x:%x\n",
7871 __func__
, disk_cfg
->major
,
7873 } else if (disk_cfg
->action
== DISK_REMOVE
) {
7874 dprintf("Disk remove action processed: %x.%x\n",
7875 disk_cfg
->major
, disk_cfg
->minor
);
7876 disk
= get_disk_super(super
,
7880 /* store action status */
7881 disk
->action
= DISK_REMOVE
;
7882 /* remove spare disks only */
7883 if (disk
->index
== -1) {
7884 remove_disk_super(super
,
7889 /* release allocate disk structure */
7890 __free_imsm_disk(disk_cfg
);
7893 return check_degraded
;
7896 static int apply_reshape_migration_update(struct imsm_update_reshape_migration
*u
,
7897 struct intel_super
*super
,
7900 struct intel_dev
*id
;
7901 void **tofree
= NULL
;
7904 dprintf("apply_reshape_migration_update()\n");
7905 if ((u
->subdev
< 0) ||
7907 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
7910 if ((space_list
== NULL
) || (*space_list
== NULL
)) {
7911 dprintf("imsm: Error: Memory is not allocated\n");
7915 for (id
= super
->devlist
; id
; id
= id
->next
) {
7916 if (id
->index
== (unsigned)u
->subdev
) {
7917 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
7918 struct imsm_map
*map
;
7919 struct imsm_dev
*new_dev
=
7920 (struct imsm_dev
*)*space_list
;
7921 struct imsm_map
*migr_map
= get_imsm_map(dev
, MAP_1
);
7923 struct dl
*new_disk
;
7925 if (new_dev
== NULL
)
7927 *space_list
= **space_list
;
7928 memcpy(new_dev
, dev
, sizeof_imsm_dev(dev
, 0));
7929 map
= get_imsm_map(new_dev
, MAP_0
);
7931 dprintf("imsm: Error: migration in progress");
7935 to_state
= map
->map_state
;
7936 if ((u
->new_level
== 5) && (map
->raid_level
== 0)) {
7938 /* this should not happen */
7939 if (u
->new_disks
[0] < 0) {
7940 map
->failed_disk_num
=
7941 map
->num_members
- 1;
7942 to_state
= IMSM_T_STATE_DEGRADED
;
7944 to_state
= IMSM_T_STATE_NORMAL
;
7946 migrate(new_dev
, super
, to_state
, MIGR_GEN_MIGR
);
7947 if (u
->new_level
> -1)
7948 map
->raid_level
= u
->new_level
;
7949 migr_map
= get_imsm_map(new_dev
, MAP_1
);
7950 if ((u
->new_level
== 5) &&
7951 (migr_map
->raid_level
== 0)) {
7952 int ord
= map
->num_members
- 1;
7953 migr_map
->num_members
--;
7954 if (u
->new_disks
[0] < 0)
7955 ord
|= IMSM_ORD_REBUILD
;
7956 set_imsm_ord_tbl_ent(map
,
7957 map
->num_members
- 1,
7961 tofree
= (void **)dev
;
7963 /* update chunk size
7965 if (u
->new_chunksize
> 0)
7966 map
->blocks_per_strip
=
7967 __cpu_to_le16(u
->new_chunksize
* 2);
7971 if ((u
->new_level
!= 5) ||
7972 (migr_map
->raid_level
!= 0) ||
7973 (migr_map
->raid_level
== map
->raid_level
))
7976 if (u
->new_disks
[0] >= 0) {
7979 new_disk
= get_disk_super(super
,
7980 major(u
->new_disks
[0]),
7981 minor(u
->new_disks
[0]));
7982 dprintf("imsm: new disk for reshape is: %i:%i "
7983 "(%p, index = %i)\n",
7984 major(u
->new_disks
[0]),
7985 minor(u
->new_disks
[0]),
7986 new_disk
, new_disk
->index
);
7987 if (new_disk
== NULL
)
7988 goto error_disk_add
;
7990 new_disk
->index
= map
->num_members
- 1;
7991 /* slot to fill in autolayout
7993 new_disk
->raiddisk
= new_disk
->index
;
7994 new_disk
->disk
.status
|= CONFIGURED_DISK
;
7995 new_disk
->disk
.status
&= ~SPARE_DISK
;
7997 goto error_disk_add
;
8000 *tofree
= *space_list
;
8001 /* calculate new size
8003 imsm_set_array_size(new_dev
, -1);
8010 *space_list
= tofree
;
8014 dprintf("Error: imsm: Cannot find disk.\n");
8018 static int apply_size_change_update(struct imsm_update_size_change
*u
,
8019 struct intel_super
*super
)
8021 struct intel_dev
*id
;
8024 dprintf("apply_size_change_update()\n");
8025 if ((u
->subdev
< 0) ||
8027 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
8031 for (id
= super
->devlist
; id
; id
= id
->next
) {
8032 if (id
->index
== (unsigned)u
->subdev
) {
8033 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
8034 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8035 int used_disks
= imsm_num_data_members(dev
, MAP_0
);
8036 unsigned long long blocks_per_member
;
8038 /* calculate new size
8040 blocks_per_member
= u
->new_size
/ used_disks
;
8041 dprintf("imsm: apply_size_change_update(size: %llu, "
8042 "blocks per member: %llu)\n",
8043 u
->new_size
, blocks_per_member
);
8044 set_blocks_per_member(map
, blocks_per_member
);
8045 imsm_set_array_size(dev
, u
->new_size
);
8055 static int apply_update_activate_spare(struct imsm_update_activate_spare
*u
,
8056 struct intel_super
*super
,
8057 struct active_array
*active_array
)
8059 struct imsm_super
*mpb
= super
->anchor
;
8060 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
8061 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8062 struct imsm_map
*migr_map
;
8063 struct active_array
*a
;
8064 struct imsm_disk
*disk
;
8071 int second_map_created
= 0;
8073 for (; u
; u
= u
->next
) {
8074 victim
= get_imsm_disk_idx(dev
, u
->slot
, MAP_X
);
8079 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
8084 pr_err("error: imsm_activate_spare passed "
8085 "an unknown disk (index: %d)\n",
8090 /* count failures (excluding rebuilds and the victim)
8091 * to determine map[0] state
8094 for (i
= 0; i
< map
->num_members
; i
++) {
8097 disk
= get_imsm_disk(super
,
8098 get_imsm_disk_idx(dev
, i
, MAP_X
));
8099 if (!disk
|| is_failed(disk
))
8103 /* adding a pristine spare, assign a new index */
8104 if (dl
->index
< 0) {
8105 dl
->index
= super
->anchor
->num_disks
;
8106 super
->anchor
->num_disks
++;
8109 disk
->status
|= CONFIGURED_DISK
;
8110 disk
->status
&= ~SPARE_DISK
;
8113 to_state
= imsm_check_degraded(super
, dev
, failed
, MAP_0
);
8114 if (!second_map_created
) {
8115 second_map_created
= 1;
8116 map
->map_state
= IMSM_T_STATE_DEGRADED
;
8117 migrate(dev
, super
, to_state
, MIGR_REBUILD
);
8119 map
->map_state
= to_state
;
8120 migr_map
= get_imsm_map(dev
, MAP_1
);
8121 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
8122 set_imsm_ord_tbl_ent(migr_map
, u
->slot
,
8123 dl
->index
| IMSM_ORD_REBUILD
);
8125 /* update the family_num to mark a new container
8126 * generation, being careful to record the existing
8127 * family_num in orig_family_num to clean up after
8128 * earlier mdadm versions that neglected to set it.
8130 if (mpb
->orig_family_num
== 0)
8131 mpb
->orig_family_num
= mpb
->family_num
;
8132 mpb
->family_num
+= super
->random
;
8134 /* count arrays using the victim in the metadata */
8136 for (a
= active_array
; a
; a
= a
->next
) {
8137 dev
= get_imsm_dev(super
, a
->info
.container_member
);
8138 map
= get_imsm_map(dev
, MAP_0
);
8140 if (get_imsm_disk_slot(map
, victim
) >= 0)
8144 /* delete the victim if it is no longer being
8150 /* We know that 'manager' isn't touching anything,
8151 * so it is safe to delete
8153 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
8154 if ((*dlp
)->index
== victim
)
8157 /* victim may be on the missing list */
8159 for (dlp
= &super
->missing
; *dlp
;
8160 dlp
= &(*dlp
)->next
)
8161 if ((*dlp
)->index
== victim
)
8163 imsm_delete(super
, dlp
, victim
);
8170 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
8171 struct intel_super
*super
,
8174 struct dl
*new_disk
;
8175 struct intel_dev
*id
;
8177 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
8178 int disk_count
= u
->old_raid_disks
;
8179 void **tofree
= NULL
;
8180 int devices_to_reshape
= 1;
8181 struct imsm_super
*mpb
= super
->anchor
;
8183 unsigned int dev_id
;
8185 dprintf("imsm: apply_reshape_container_disks_update()\n");
8187 /* enable spares to use in array */
8188 for (i
= 0; i
< delta_disks
; i
++) {
8189 new_disk
= get_disk_super(super
,
8190 major(u
->new_disks
[i
]),
8191 minor(u
->new_disks
[i
]));
8192 dprintf("imsm: new disk for reshape is: %i:%i "
8193 "(%p, index = %i)\n",
8194 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
8195 new_disk
, new_disk
->index
);
8196 if ((new_disk
== NULL
) ||
8197 ((new_disk
->index
>= 0) &&
8198 (new_disk
->index
< u
->old_raid_disks
)))
8199 goto update_reshape_exit
;
8200 new_disk
->index
= disk_count
++;
8201 /* slot to fill in autolayout
8203 new_disk
->raiddisk
= new_disk
->index
;
8204 new_disk
->disk
.status
|=
8206 new_disk
->disk
.status
&= ~SPARE_DISK
;
8209 dprintf("imsm: volume set mpb->num_raid_devs = %i\n",
8210 mpb
->num_raid_devs
);
8211 /* manage changes in volume
8213 for (dev_id
= 0; dev_id
< mpb
->num_raid_devs
; dev_id
++) {
8214 void **sp
= *space_list
;
8215 struct imsm_dev
*newdev
;
8216 struct imsm_map
*newmap
, *oldmap
;
8218 for (id
= super
->devlist
; id
; id
= id
->next
) {
8219 if (id
->index
== dev_id
)
8228 /* Copy the dev, but not (all of) the map */
8229 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
8230 oldmap
= get_imsm_map(id
->dev
, MAP_0
);
8231 newmap
= get_imsm_map(newdev
, MAP_0
);
8232 /* Copy the current map */
8233 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
8234 /* update one device only
8236 if (devices_to_reshape
) {
8237 dprintf("imsm: modifying subdev: %i\n",
8239 devices_to_reshape
--;
8240 newdev
->vol
.migr_state
= 1;
8241 newdev
->vol
.curr_migr_unit
= 0;
8242 set_migr_type(newdev
, MIGR_GEN_MIGR
);
8243 newmap
->num_members
= u
->new_raid_disks
;
8244 for (i
= 0; i
< delta_disks
; i
++) {
8245 set_imsm_ord_tbl_ent(newmap
,
8246 u
->old_raid_disks
+ i
,
8247 u
->old_raid_disks
+ i
);
8249 /* New map is correct, now need to save old map
8251 newmap
= get_imsm_map(newdev
, MAP_1
);
8252 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
8254 imsm_set_array_size(newdev
, -1);
8257 sp
= (void **)id
->dev
;
8262 /* Clear migration record */
8263 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
8266 *space_list
= tofree
;
8269 update_reshape_exit
:
8274 static int apply_takeover_update(struct imsm_update_takeover
*u
,
8275 struct intel_super
*super
,
8278 struct imsm_dev
*dev
= NULL
;
8279 struct intel_dev
*dv
;
8280 struct imsm_dev
*dev_new
;
8281 struct imsm_map
*map
;
8285 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
8286 if (dv
->index
== (unsigned int)u
->subarray
) {
8294 map
= get_imsm_map(dev
, MAP_0
);
8296 if (u
->direction
== R10_TO_R0
) {
8297 /* Number of failed disks must be half of initial disk number */
8298 if (imsm_count_failed(super
, dev
, MAP_0
) !=
8299 (map
->num_members
/ 2))
8302 /* iterate through devices to mark removed disks as spare */
8303 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
8304 if (dm
->disk
.status
& FAILED_DISK
) {
8305 int idx
= dm
->index
;
8306 /* update indexes on the disk list */
8307 /* FIXME this loop-with-the-loop looks wrong, I'm not convinced
8308 the index values will end up being correct.... NB */
8309 for (du
= super
->disks
; du
; du
= du
->next
)
8310 if (du
->index
> idx
)
8312 /* mark as spare disk */
8317 map
->num_members
= map
->num_members
/ 2;
8318 map
->map_state
= IMSM_T_STATE_NORMAL
;
8319 map
->num_domains
= 1;
8320 map
->raid_level
= 0;
8321 map
->failed_disk_num
= -1;
8324 if (u
->direction
== R0_TO_R10
) {
8326 /* update slots in current disk list */
8327 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
8331 /* create new *missing* disks */
8332 for (i
= 0; i
< map
->num_members
; i
++) {
8333 space
= *space_list
;
8336 *space_list
= *space
;
8338 memcpy(du
, super
->disks
, sizeof(*du
));
8342 du
->index
= (i
* 2) + 1;
8343 sprintf((char *)du
->disk
.serial
,
8344 " MISSING_%d", du
->index
);
8345 sprintf((char *)du
->serial
,
8346 "MISSING_%d", du
->index
);
8347 du
->next
= super
->missing
;
8348 super
->missing
= du
;
8350 /* create new dev and map */
8351 space
= *space_list
;
8354 *space_list
= *space
;
8355 dev_new
= (void *)space
;
8356 memcpy(dev_new
, dev
, sizeof(*dev
));
8357 /* update new map */
8358 map
= get_imsm_map(dev_new
, MAP_0
);
8359 map
->num_members
= map
->num_members
* 2;
8360 map
->map_state
= IMSM_T_STATE_DEGRADED
;
8361 map
->num_domains
= 2;
8362 map
->raid_level
= 1;
8363 /* replace dev<->dev_new */
8366 /* update disk order table */
8367 for (du
= super
->disks
; du
; du
= du
->next
)
8369 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
8370 for (du
= super
->missing
; du
; du
= du
->next
)
8371 if (du
->index
>= 0) {
8372 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
8373 mark_missing(dv
->dev
, &du
->disk
, du
->index
);
8379 static void imsm_process_update(struct supertype
*st
,
8380 struct metadata_update
*update
)
8383 * crack open the metadata_update envelope to find the update record
8384 * update can be one of:
8385 * update_reshape_container_disks - all the arrays in the container
8386 * are being reshaped to have more devices. We need to mark
8387 * the arrays for general migration and convert selected spares
8388 * into active devices.
8389 * update_activate_spare - a spare device has replaced a failed
8390 * device in an array, update the disk_ord_tbl. If this disk is
8391 * present in all member arrays then also clear the SPARE_DISK
8393 * update_create_array
8395 * update_rename_array
8396 * update_add_remove_disk
8398 struct intel_super
*super
= st
->sb
;
8399 struct imsm_super
*mpb
;
8400 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
8402 /* update requires a larger buf but the allocation failed */
8403 if (super
->next_len
&& !super
->next_buf
) {
8404 super
->next_len
= 0;
8408 if (super
->next_buf
) {
8409 memcpy(super
->next_buf
, super
->buf
, super
->len
);
8411 super
->len
= super
->next_len
;
8412 super
->buf
= super
->next_buf
;
8414 super
->next_len
= 0;
8415 super
->next_buf
= NULL
;
8418 mpb
= super
->anchor
;
8421 case update_general_migration_checkpoint
: {
8422 struct intel_dev
*id
;
8423 struct imsm_update_general_migration_checkpoint
*u
=
8424 (void *)update
->buf
;
8426 dprintf("imsm: process_update() "
8427 "for update_general_migration_checkpoint called\n");
8429 /* find device under general migration */
8430 for (id
= super
->devlist
; id
; id
= id
->next
) {
8431 if (is_gen_migration(id
->dev
)) {
8432 id
->dev
->vol
.curr_migr_unit
=
8433 __cpu_to_le32(u
->curr_migr_unit
);
8434 super
->updates_pending
++;
8439 case update_takeover
: {
8440 struct imsm_update_takeover
*u
= (void *)update
->buf
;
8441 if (apply_takeover_update(u
, super
, &update
->space_list
)) {
8442 imsm_update_version_info(super
);
8443 super
->updates_pending
++;
8448 case update_reshape_container_disks
: {
8449 struct imsm_update_reshape
*u
= (void *)update
->buf
;
8450 if (apply_reshape_container_disks_update(
8451 u
, super
, &update
->space_list
))
8452 super
->updates_pending
++;
8455 case update_reshape_migration
: {
8456 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
8457 if (apply_reshape_migration_update(
8458 u
, super
, &update
->space_list
))
8459 super
->updates_pending
++;
8462 case update_size_change
: {
8463 struct imsm_update_size_change
*u
= (void *)update
->buf
;
8464 if (apply_size_change_update(u
, super
))
8465 super
->updates_pending
++;
8468 case update_activate_spare
: {
8469 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
8470 if (apply_update_activate_spare(u
, super
, st
->arrays
))
8471 super
->updates_pending
++;
8474 case update_create_array
: {
8475 /* someone wants to create a new array, we need to be aware of
8476 * a few races/collisions:
8477 * 1/ 'Create' called by two separate instances of mdadm
8478 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
8479 * devices that have since been assimilated via
8481 * In the event this update can not be carried out mdadm will
8482 * (FIX ME) notice that its update did not take hold.
8484 struct imsm_update_create_array
*u
= (void *) update
->buf
;
8485 struct intel_dev
*dv
;
8486 struct imsm_dev
*dev
;
8487 struct imsm_map
*map
, *new_map
;
8488 unsigned long long start
, end
;
8489 unsigned long long new_start
, new_end
;
8491 struct disk_info
*inf
;
8494 /* handle racing creates: first come first serve */
8495 if (u
->dev_idx
< mpb
->num_raid_devs
) {
8496 dprintf("%s: subarray %d already defined\n",
8497 __func__
, u
->dev_idx
);
8501 /* check update is next in sequence */
8502 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
8503 dprintf("%s: can not create array %d expected index %d\n",
8504 __func__
, u
->dev_idx
, mpb
->num_raid_devs
);
8508 new_map
= get_imsm_map(&u
->dev
, MAP_0
);
8509 new_start
= pba_of_lba0(new_map
);
8510 new_end
= new_start
+ blocks_per_member(new_map
);
8511 inf
= get_disk_info(u
);
8513 /* handle activate_spare versus create race:
8514 * check to make sure that overlapping arrays do not include
8517 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8518 dev
= get_imsm_dev(super
, i
);
8519 map
= get_imsm_map(dev
, MAP_0
);
8520 start
= pba_of_lba0(map
);
8521 end
= start
+ blocks_per_member(map
);
8522 if ((new_start
>= start
&& new_start
<= end
) ||
8523 (start
>= new_start
&& start
<= new_end
))
8528 if (disks_overlap(super
, i
, u
)) {
8529 dprintf("%s: arrays overlap\n", __func__
);
8534 /* check that prepare update was successful */
8535 if (!update
->space
) {
8536 dprintf("%s: prepare update failed\n", __func__
);
8540 /* check that all disks are still active before committing
8541 * changes. FIXME: could we instead handle this by creating a
8542 * degraded array? That's probably not what the user expects,
8543 * so better to drop this update on the floor.
8545 for (i
= 0; i
< new_map
->num_members
; i
++) {
8546 dl
= serial_to_dl(inf
[i
].serial
, super
);
8548 dprintf("%s: disk disappeared\n", __func__
);
8553 super
->updates_pending
++;
8555 /* convert spares to members and fixup ord_tbl */
8556 for (i
= 0; i
< new_map
->num_members
; i
++) {
8557 dl
= serial_to_dl(inf
[i
].serial
, super
);
8558 if (dl
->index
== -1) {
8559 dl
->index
= mpb
->num_disks
;
8561 dl
->disk
.status
|= CONFIGURED_DISK
;
8562 dl
->disk
.status
&= ~SPARE_DISK
;
8564 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
8569 update
->space
= NULL
;
8570 imsm_copy_dev(dev
, &u
->dev
);
8571 dv
->index
= u
->dev_idx
;
8572 dv
->next
= super
->devlist
;
8573 super
->devlist
= dv
;
8574 mpb
->num_raid_devs
++;
8576 imsm_update_version_info(super
);
8579 /* mdmon knows how to release update->space, but not
8580 * ((struct intel_dev *) update->space)->dev
8582 if (update
->space
) {
8588 case update_kill_array
: {
8589 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
8590 int victim
= u
->dev_idx
;
8591 struct active_array
*a
;
8592 struct intel_dev
**dp
;
8593 struct imsm_dev
*dev
;
8595 /* sanity check that we are not affecting the uuid of
8596 * active arrays, or deleting an active array
8598 * FIXME when immutable ids are available, but note that
8599 * we'll also need to fixup the invalidated/active
8600 * subarray indexes in mdstat
8602 for (a
= st
->arrays
; a
; a
= a
->next
)
8603 if (a
->info
.container_member
>= victim
)
8605 /* by definition if mdmon is running at least one array
8606 * is active in the container, so checking
8607 * mpb->num_raid_devs is just extra paranoia
8609 dev
= get_imsm_dev(super
, victim
);
8610 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
8611 dprintf("failed to delete subarray-%d\n", victim
);
8615 for (dp
= &super
->devlist
; *dp
;)
8616 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
8619 if ((*dp
)->index
> (unsigned)victim
)
8623 mpb
->num_raid_devs
--;
8624 super
->updates_pending
++;
8627 case update_rename_array
: {
8628 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
8629 char name
[MAX_RAID_SERIAL_LEN
+1];
8630 int target
= u
->dev_idx
;
8631 struct active_array
*a
;
8632 struct imsm_dev
*dev
;
8634 /* sanity check that we are not affecting the uuid of
8637 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
8638 name
[MAX_RAID_SERIAL_LEN
] = '\0';
8639 for (a
= st
->arrays
; a
; a
= a
->next
)
8640 if (a
->info
.container_member
== target
)
8642 dev
= get_imsm_dev(super
, u
->dev_idx
);
8643 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
8644 dprintf("failed to rename subarray-%d\n", target
);
8648 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
8649 super
->updates_pending
++;
8652 case update_add_remove_disk
: {
8653 /* we may be able to repair some arrays if disks are
8654 * being added, check the status of add_remove_disk
8655 * if discs has been added.
8657 if (add_remove_disk_update(super
)) {
8658 struct active_array
*a
;
8660 super
->updates_pending
++;
8661 for (a
= st
->arrays
; a
; a
= a
->next
)
8662 a
->check_degraded
= 1;
8667 pr_err("error: unsuported process update type:"
8668 "(type: %d)\n", type
);
8672 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
);
8674 static int imsm_prepare_update(struct supertype
*st
,
8675 struct metadata_update
*update
)
8678 * Allocate space to hold new disk entries, raid-device entries or a new
8679 * mpb if necessary. The manager synchronously waits for updates to
8680 * complete in the monitor, so new mpb buffers allocated here can be
8681 * integrated by the monitor thread without worrying about live pointers
8682 * in the manager thread.
8684 enum imsm_update_type type
;
8685 struct intel_super
*super
= st
->sb
;
8686 struct imsm_super
*mpb
= super
->anchor
;
8690 if (update
->len
< (int)sizeof(type
))
8693 type
= *(enum imsm_update_type
*) update
->buf
;
8696 case update_general_migration_checkpoint
:
8697 if (update
->len
< (int)sizeof(struct imsm_update_general_migration_checkpoint
))
8699 dprintf("imsm: prepare_update() "
8700 "for update_general_migration_checkpoint called\n");
8702 case update_takeover
: {
8703 struct imsm_update_takeover
*u
= (void *)update
->buf
;
8704 if (update
->len
< (int)sizeof(*u
))
8706 if (u
->direction
== R0_TO_R10
) {
8707 void **tail
= (void **)&update
->space_list
;
8708 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subarray
);
8709 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8710 int num_members
= map
->num_members
;
8713 /* allocate memory for added disks */
8714 for (i
= 0; i
< num_members
; i
++) {
8715 size
= sizeof(struct dl
);
8716 space
= xmalloc(size
);
8721 /* allocate memory for new device */
8722 size
= sizeof_imsm_dev(super
->devlist
->dev
, 0) +
8723 (num_members
* sizeof(__u32
));
8724 space
= xmalloc(size
);
8728 len
= disks_to_mpb_size(num_members
* 2);
8733 case update_reshape_container_disks
: {
8734 /* Every raid device in the container is about to
8735 * gain some more devices, and we will enter a
8737 * So each 'imsm_map' will be bigger, and the imsm_vol
8738 * will now hold 2 of them.
8739 * Thus we need new 'struct imsm_dev' allocations sized
8740 * as sizeof_imsm_dev but with more devices in both maps.
8742 struct imsm_update_reshape
*u
= (void *)update
->buf
;
8743 struct intel_dev
*dl
;
8744 void **space_tail
= (void**)&update
->space_list
;
8746 if (update
->len
< (int)sizeof(*u
))
8749 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
8751 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
8752 int size
= sizeof_imsm_dev(dl
->dev
, 1);
8754 if (u
->new_raid_disks
> u
->old_raid_disks
)
8755 size
+= sizeof(__u32
)*2*
8756 (u
->new_raid_disks
- u
->old_raid_disks
);
8763 len
= disks_to_mpb_size(u
->new_raid_disks
);
8764 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
8767 case update_reshape_migration
: {
8768 /* for migration level 0->5 we need to add disks
8769 * so the same as for container operation we will copy
8770 * device to the bigger location.
8771 * in memory prepared device and new disk area are prepared
8772 * for usage in process update
8774 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
8775 struct intel_dev
*id
;
8776 void **space_tail
= (void **)&update
->space_list
;
8779 int current_level
= -1;
8781 if (update
->len
< (int)sizeof(*u
))
8784 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
8786 /* add space for bigger array in update
8788 for (id
= super
->devlist
; id
; id
= id
->next
) {
8789 if (id
->index
== (unsigned)u
->subdev
) {
8790 size
= sizeof_imsm_dev(id
->dev
, 1);
8791 if (u
->new_raid_disks
> u
->old_raid_disks
)
8792 size
+= sizeof(__u32
)*2*
8793 (u
->new_raid_disks
- u
->old_raid_disks
);
8801 if (update
->space_list
== NULL
)
8804 /* add space for disk in update
8806 size
= sizeof(struct dl
);
8812 /* add spare device to update
8814 for (id
= super
->devlist
; id
; id
= id
->next
)
8815 if (id
->index
== (unsigned)u
->subdev
) {
8816 struct imsm_dev
*dev
;
8817 struct imsm_map
*map
;
8819 dev
= get_imsm_dev(super
, u
->subdev
);
8820 map
= get_imsm_map(dev
, MAP_0
);
8821 current_level
= map
->raid_level
;
8824 if ((u
->new_level
== 5) && (u
->new_level
!= current_level
)) {
8825 struct mdinfo
*spares
;
8827 spares
= get_spares_for_grow(st
);
8835 makedev(dev
->disk
.major
,
8837 dl
= get_disk_super(super
,
8840 dl
->index
= u
->old_raid_disks
;
8846 len
= disks_to_mpb_size(u
->new_raid_disks
);
8847 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
8850 case update_size_change
: {
8851 if (update
->len
< (int)sizeof(struct imsm_update_size_change
))
8855 case update_activate_spare
: {
8856 if (update
->len
< (int)sizeof(struct imsm_update_activate_spare
))
8860 case update_create_array
: {
8861 struct imsm_update_create_array
*u
= (void *) update
->buf
;
8862 struct intel_dev
*dv
;
8863 struct imsm_dev
*dev
= &u
->dev
;
8864 struct imsm_map
*map
= get_imsm_map(dev
, MAP_0
);
8866 struct disk_info
*inf
;
8870 if (update
->len
< (int)sizeof(*u
))
8873 inf
= get_disk_info(u
);
8874 len
= sizeof_imsm_dev(dev
, 1);
8875 /* allocate a new super->devlist entry */
8876 dv
= xmalloc(sizeof(*dv
));
8877 dv
->dev
= xmalloc(len
);
8880 /* count how many spares will be converted to members */
8881 for (i
= 0; i
< map
->num_members
; i
++) {
8882 dl
= serial_to_dl(inf
[i
].serial
, super
);
8884 /* hmm maybe it failed?, nothing we can do about
8889 if (count_memberships(dl
, super
) == 0)
8892 len
+= activate
* sizeof(struct imsm_disk
);
8895 case update_kill_array
: {
8896 if (update
->len
< (int)sizeof(struct imsm_update_kill_array
))
8900 case update_rename_array
: {
8901 if (update
->len
< (int)sizeof(struct imsm_update_rename_array
))
8905 case update_add_remove_disk
:
8906 /* no update->len needed */
8912 /* check if we need a larger metadata buffer */
8913 if (super
->next_buf
)
8914 buf_len
= super
->next_len
;
8916 buf_len
= super
->len
;
8918 if (__le32_to_cpu(mpb
->mpb_size
) + len
> buf_len
) {
8919 /* ok we need a larger buf than what is currently allocated
8920 * if this allocation fails process_update will notice that
8921 * ->next_len is set and ->next_buf is NULL
8923 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + len
, 512);
8924 if (super
->next_buf
)
8925 free(super
->next_buf
);
8927 super
->next_len
= buf_len
;
8928 if (posix_memalign(&super
->next_buf
, 512, buf_len
) == 0)
8929 memset(super
->next_buf
, 0, buf_len
);
8931 super
->next_buf
= NULL
;
8936 /* must be called while manager is quiesced */
8937 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
8939 struct imsm_super
*mpb
= super
->anchor
;
8941 struct imsm_dev
*dev
;
8942 struct imsm_map
*map
;
8943 int i
, j
, num_members
;
8946 dprintf("%s: deleting device[%d] from imsm_super\n",
8949 /* shift all indexes down one */
8950 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
8951 if (iter
->index
> (int)index
)
8953 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
8954 if (iter
->index
> (int)index
)
8957 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
8958 dev
= get_imsm_dev(super
, i
);
8959 map
= get_imsm_map(dev
, MAP_0
);
8960 num_members
= map
->num_members
;
8961 for (j
= 0; j
< num_members
; j
++) {
8962 /* update ord entries being careful not to propagate
8963 * ord-flags to the first map
8965 ord
= get_imsm_ord_tbl_ent(dev
, j
, MAP_X
);
8967 if (ord_to_idx(ord
) <= index
)
8970 map
= get_imsm_map(dev
, MAP_0
);
8971 set_imsm_ord_tbl_ent(map
, j
, ord_to_idx(ord
- 1));
8972 map
= get_imsm_map(dev
, MAP_1
);
8974 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
8979 super
->updates_pending
++;
8981 struct dl
*dl
= *dlp
;
8983 *dlp
= (*dlp
)->next
;
8984 __free_imsm_disk(dl
);
8987 #endif /* MDASSEMBLE */
8989 static void close_targets(int *targets
, int new_disks
)
8996 for (i
= 0; i
< new_disks
; i
++) {
8997 if (targets
[i
] >= 0) {
9004 static int imsm_get_allowed_degradation(int level
, int raid_disks
,
9005 struct intel_super
*super
,
9006 struct imsm_dev
*dev
)
9012 struct imsm_map
*map
;
9015 ret_val
= raid_disks
/2;
9016 /* check map if all disks pairs not failed
9019 map
= get_imsm_map(dev
, MAP_0
);
9020 for (i
= 0; i
< ret_val
; i
++) {
9021 int degradation
= 0;
9022 if (get_imsm_disk(super
, i
) == NULL
)
9024 if (get_imsm_disk(super
, i
+ 1) == NULL
)
9026 if (degradation
== 2)
9029 map
= get_imsm_map(dev
, MAP_1
);
9030 /* if there is no second map
9031 * result can be returned
9035 /* check degradation in second map
9037 for (i
= 0; i
< ret_val
; i
++) {
9038 int degradation
= 0;
9039 if (get_imsm_disk(super
, i
) == NULL
)
9041 if (get_imsm_disk(super
, i
+ 1) == NULL
)
9043 if (degradation
== 2)
9057 /*******************************************************************************
9058 * Function: open_backup_targets
9059 * Description: Function opens file descriptors for all devices given in
9062 * info : general array info
9063 * raid_disks : number of disks
9064 * raid_fds : table of device's file descriptors
9065 * super : intel super for raid10 degradation check
9066 * dev : intel device for raid10 degradation check
9070 ******************************************************************************/
9071 int open_backup_targets(struct mdinfo
*info
, int raid_disks
, int *raid_fds
,
9072 struct intel_super
*super
, struct imsm_dev
*dev
)
9078 for (i
= 0; i
< raid_disks
; i
++)
9081 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
9084 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
)) {
9085 dprintf("disk is faulty!!\n");
9089 if ((sd
->disk
.raid_disk
>= raid_disks
) ||
9090 (sd
->disk
.raid_disk
< 0))
9093 dn
= map_dev(sd
->disk
.major
,
9095 raid_fds
[sd
->disk
.raid_disk
] = dev_open(dn
, O_RDWR
);
9096 if (raid_fds
[sd
->disk
.raid_disk
] < 0) {
9097 pr_err("cannot open component\n");
9102 /* check if maximum array degradation level is not exceeded
9104 if ((raid_disks
- opened
) >
9105 imsm_get_allowed_degradation(info
->new_level
,
9108 pr_err("Not enough disks can be opened.\n");
9109 close_targets(raid_fds
, raid_disks
);
9115 /*******************************************************************************
9116 * Function: validate_container_imsm
9117 * Description: This routine validates container after assemble,
9118 * eg. if devices in container are under the same controller.
9121 * info : linked list with info about devices used in array
9125 ******************************************************************************/
9126 int validate_container_imsm(struct mdinfo
*info
)
9128 if (check_env("IMSM_NO_PLATFORM"))
9131 struct sys_dev
*idev
;
9132 struct sys_dev
*hba
= NULL
;
9133 struct sys_dev
*intel_devices
= find_intel_devices();
9134 char *dev_path
= devt_to_devpath(makedev(info
->disk
.major
,
9137 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
9138 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
9147 pr_err("WARNING - Cannot detect HBA for device %s!\n",
9148 devid2kname(makedev(info
->disk
.major
, info
->disk
.minor
)));
9152 const struct imsm_orom
*orom
= get_orom_by_device_id(hba
->dev_id
);
9155 for (dev
= info
->next
; dev
; dev
= dev
->next
) {
9156 dev_path
= devt_to_devpath(makedev(dev
->disk
.major
, dev
->disk
.minor
));
9158 struct sys_dev
*hba2
= NULL
;
9159 for (idev
= intel_devices
; idev
; idev
= idev
->next
) {
9160 if (dev_path
&& strstr(dev_path
, idev
->path
)) {
9168 const struct imsm_orom
*orom2
= hba2
== NULL
? NULL
:
9169 get_orom_by_device_id(hba2
->dev_id
);
9171 if (hba2
&& hba
->type
!= hba2
->type
) {
9172 pr_err("WARNING - HBAs of devices do not match %s != %s\n",
9173 get_sys_dev_type(hba
->type
), get_sys_dev_type(hba2
->type
));
9177 if (orom
!= orom2
) {
9178 pr_err("WARNING - IMSM container assembled with disks under different HBAs!\n"
9179 " This operation is not supported and can lead to data loss.\n");
9184 pr_err("WARNING - IMSM container assembled with disks under HBAs without IMSM platform support!\n"
9185 " This operation is not supported and can lead to data loss.\n");
9193 /*******************************************************************************
9194 * Function: init_migr_record_imsm
9195 * Description: Function inits imsm migration record
9197 * super : imsm internal array info
9198 * dev : device under migration
9199 * info : general array info to find the smallest device
9202 ******************************************************************************/
9203 void init_migr_record_imsm(struct supertype
*st
, struct imsm_dev
*dev
,
9204 struct mdinfo
*info
)
9206 struct intel_super
*super
= st
->sb
;
9207 struct migr_record
*migr_rec
= super
->migr_rec
;
9209 unsigned long long dsize
, dev_sectors
;
9210 long long unsigned min_dev_sectors
= -1LLU;
9214 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
9215 struct imsm_map
*map_src
= get_imsm_map(dev
, MAP_1
);
9216 unsigned long long num_migr_units
;
9217 unsigned long long array_blocks
;
9219 memset(migr_rec
, 0, sizeof(struct migr_record
));
9220 migr_rec
->family_num
= __cpu_to_le32(super
->anchor
->family_num
);
9222 /* only ascending reshape supported now */
9223 migr_rec
->ascending_migr
= __cpu_to_le32(1);
9225 migr_rec
->dest_depth_per_unit
= GEN_MIGR_AREA_SIZE
/
9226 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
9227 migr_rec
->dest_depth_per_unit
*=
9228 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
9229 new_data_disks
= imsm_num_data_members(dev
, MAP_0
);
9230 migr_rec
->blocks_per_unit
=
9231 __cpu_to_le32(migr_rec
->dest_depth_per_unit
* new_data_disks
);
9232 migr_rec
->dest_depth_per_unit
=
9233 __cpu_to_le32(migr_rec
->dest_depth_per_unit
);
9234 array_blocks
= info
->component_size
* new_data_disks
;
9236 array_blocks
/ __le32_to_cpu(migr_rec
->blocks_per_unit
);
9238 if (array_blocks
% __le32_to_cpu(migr_rec
->blocks_per_unit
))
9240 migr_rec
->num_migr_units
= __cpu_to_le32(num_migr_units
);
9242 migr_rec
->post_migr_vol_cap
= dev
->size_low
;
9243 migr_rec
->post_migr_vol_cap_hi
= dev
->size_high
;
9245 /* Find the smallest dev */
9246 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
9247 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
9248 fd
= dev_open(nm
, O_RDONLY
);
9251 get_dev_size(fd
, NULL
, &dsize
);
9252 dev_sectors
= dsize
/ 512;
9253 if (dev_sectors
< min_dev_sectors
)
9254 min_dev_sectors
= dev_sectors
;
9257 migr_rec
->ckpt_area_pba
= __cpu_to_le32(min_dev_sectors
-
9258 RAID_DISK_RESERVED_BLOCKS_IMSM_HI
);
9260 write_imsm_migr_rec(st
);
9265 /*******************************************************************************
9266 * Function: save_backup_imsm
9267 * Description: Function saves critical data stripes to Migration Copy Area
9268 * and updates the current migration unit status.
9269 * Use restore_stripes() to form a destination stripe,
9270 * and to write it to the Copy Area.
9272 * st : supertype information
9273 * dev : imsm device that backup is saved for
9274 * info : general array info
9275 * buf : input buffer
9276 * length : length of data to backup (blocks_per_unit)
9280 ******************************************************************************/
9281 int save_backup_imsm(struct supertype
*st
,
9282 struct imsm_dev
*dev
,
9283 struct mdinfo
*info
,
9288 struct intel_super
*super
= st
->sb
;
9289 unsigned long long *target_offsets
= NULL
;
9290 int *targets
= NULL
;
9292 struct imsm_map
*map_dest
= get_imsm_map(dev
, MAP_0
);
9293 int new_disks
= map_dest
->num_members
;
9294 int dest_layout
= 0;
9296 unsigned long long start
;
9297 int data_disks
= imsm_num_data_members(dev
, MAP_0
);
9299 targets
= xmalloc(new_disks
* sizeof(int));
9301 for (i
= 0; i
< new_disks
; i
++)
9304 target_offsets
= xcalloc(new_disks
, sizeof(unsigned long long));
9306 start
= info
->reshape_progress
* 512;
9307 for (i
= 0; i
< new_disks
; i
++) {
9308 target_offsets
[i
] = (unsigned long long)
9309 __le32_to_cpu(super
->migr_rec
->ckpt_area_pba
) * 512;
9310 /* move back copy area adderss, it will be moved forward
9311 * in restore_stripes() using start input variable
9313 target_offsets
[i
] -= start
/data_disks
;
9316 if (open_backup_targets(info
, new_disks
, targets
,
9320 dest_layout
= imsm_level_to_layout(map_dest
->raid_level
);
9321 dest_chunk
= __le16_to_cpu(map_dest
->blocks_per_strip
) * 512;
9323 if (restore_stripes(targets
, /* list of dest devices */
9324 target_offsets
, /* migration record offsets */
9327 map_dest
->raid_level
,
9329 -1, /* source backup file descriptor */
9330 0, /* input buf offset
9331 * always 0 buf is already offseted */
9335 pr_err("Error restoring stripes\n");
9343 close_targets(targets
, new_disks
);
9346 free(target_offsets
);
9351 /*******************************************************************************
9352 * Function: save_checkpoint_imsm
9353 * Description: Function called for current unit status update
9354 * in the migration record. It writes it to disk.
9356 * super : imsm internal array info
9357 * info : general array info
9361 * 2: failure, means no valid migration record
9362 * / no general migration in progress /
9363 ******************************************************************************/
9364 int save_checkpoint_imsm(struct supertype
*st
, struct mdinfo
*info
, int state
)
9366 struct intel_super
*super
= st
->sb
;
9367 unsigned long long blocks_per_unit
;
9368 unsigned long long curr_migr_unit
;
9370 if (load_imsm_migr_rec(super
, info
) != 0) {
9371 dprintf("imsm: ERROR: Cannot read migration record "
9372 "for checkpoint save.\n");
9376 blocks_per_unit
= __le32_to_cpu(super
->migr_rec
->blocks_per_unit
);
9377 if (blocks_per_unit
== 0) {
9378 dprintf("imsm: no migration in progress.\n");
9381 curr_migr_unit
= info
->reshape_progress
/ blocks_per_unit
;
9382 /* check if array is alligned to copy area
9383 * if it is not alligned, add one to current migration unit value
9384 * this can happend on array reshape finish only
9386 if (info
->reshape_progress
% blocks_per_unit
)
9389 super
->migr_rec
->curr_migr_unit
=
9390 __cpu_to_le32(curr_migr_unit
);
9391 super
->migr_rec
->rec_status
= __cpu_to_le32(state
);
9392 super
->migr_rec
->dest_1st_member_lba
=
9393 __cpu_to_le32(curr_migr_unit
*
9394 __le32_to_cpu(super
->migr_rec
->dest_depth_per_unit
));
9395 if (write_imsm_migr_rec(st
) < 0) {
9396 dprintf("imsm: Cannot write migration record "
9397 "outside backup area\n");
9404 /*******************************************************************************
9405 * Function: recover_backup_imsm
9406 * Description: Function recovers critical data from the Migration Copy Area
9407 * while assembling an array.
9409 * super : imsm internal array info
9410 * info : general array info
9412 * 0 : success (or there is no data to recover)
9414 ******************************************************************************/
9415 int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
)
9417 struct intel_super
*super
= st
->sb
;
9418 struct migr_record
*migr_rec
= super
->migr_rec
;
9419 struct imsm_map
*map_dest
= NULL
;
9420 struct intel_dev
*id
= NULL
;
9421 unsigned long long read_offset
;
9422 unsigned long long write_offset
;
9424 int *targets
= NULL
;
9425 int new_disks
, i
, err
;
9428 unsigned long curr_migr_unit
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
9429 unsigned long num_migr_units
= __le32_to_cpu(migr_rec
->num_migr_units
);
9431 int skipped_disks
= 0;
9433 err
= sysfs_get_str(info
, NULL
, "array_state", (char *)buffer
, 20);
9437 /* recover data only during assemblation */
9438 if (strncmp(buffer
, "inactive", 8) != 0)
9440 /* no data to recover */
9441 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
9443 if (curr_migr_unit
>= num_migr_units
)
9446 /* find device during reshape */
9447 for (id
= super
->devlist
; id
; id
= id
->next
)
9448 if (is_gen_migration(id
->dev
))
9453 map_dest
= get_imsm_map(id
->dev
, MAP_0
);
9454 new_disks
= map_dest
->num_members
;
9456 read_offset
= (unsigned long long)
9457 __le32_to_cpu(migr_rec
->ckpt_area_pba
) * 512;
9459 write_offset
= ((unsigned long long)
9460 __le32_to_cpu(migr_rec
->dest_1st_member_lba
) +
9461 pba_of_lba0(map_dest
)) * 512;
9463 unit_len
= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
9464 if (posix_memalign((void **)&buf
, 512, unit_len
) != 0)
9466 targets
= xcalloc(new_disks
, sizeof(int));
9468 if (open_backup_targets(info
, new_disks
, targets
, super
, id
->dev
)) {
9469 pr_err("Cannot open some devices belonging to array.\n");
9473 for (i
= 0; i
< new_disks
; i
++) {
9474 if (targets
[i
] < 0) {
9478 if (lseek64(targets
[i
], read_offset
, SEEK_SET
) < 0) {
9479 pr_err("Cannot seek to block: %s\n",
9484 if ((unsigned)read(targets
[i
], buf
, unit_len
) != unit_len
) {
9485 pr_err("Cannot read copy area block: %s\n",
9490 if (lseek64(targets
[i
], write_offset
, SEEK_SET
) < 0) {
9491 pr_err("Cannot seek to block: %s\n",
9496 if ((unsigned)write(targets
[i
], buf
, unit_len
) != unit_len
) {
9497 pr_err("Cannot restore block: %s\n",
9504 if (skipped_disks
> imsm_get_allowed_degradation(info
->new_level
,
9508 pr_err("Cannot restore data from backup."
9509 " Too many failed disks\n");
9513 if (save_checkpoint_imsm(st
, info
, UNIT_SRC_NORMAL
)) {
9514 /* ignore error == 2, this can mean end of reshape here
9516 dprintf("imsm: Cannot write checkpoint to "
9517 "migration record (UNIT_SRC_NORMAL) during restart\n");
9523 for (i
= 0; i
< new_disks
; i
++)
9532 static char disk_by_path
[] = "/dev/disk/by-path/";
9534 static const char *imsm_get_disk_controller_domain(const char *path
)
9536 char disk_path
[PATH_MAX
];
9540 strcpy(disk_path
, disk_by_path
);
9541 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
9542 if (stat(disk_path
, &st
) == 0) {
9543 struct sys_dev
* hba
;
9546 path
= devt_to_devpath(st
.st_rdev
);
9549 hba
= find_disk_attached_hba(-1, path
);
9550 if (hba
&& hba
->type
== SYS_DEV_SAS
)
9552 else if (hba
&& hba
->type
== SYS_DEV_SATA
)
9556 dprintf("path: %s hba: %s attached: %s\n",
9557 path
, (hba
) ? hba
->path
: "NULL", drv
);
9563 static char *imsm_find_array_devnm_by_subdev(int subdev
, char *container
)
9565 static char devnm
[32];
9566 char subdev_name
[20];
9567 struct mdstat_ent
*mdstat
;
9569 sprintf(subdev_name
, "%d", subdev
);
9570 mdstat
= mdstat_by_subdev(subdev_name
, container
);
9574 strcpy(devnm
, mdstat
->devnm
);
9575 free_mdstat(mdstat
);
9579 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
9580 struct geo_params
*geo
,
9581 int *old_raid_disks
,
9584 /* currently we only support increasing the number of devices
9585 * for a container. This increases the number of device for each
9586 * member array. They must all be RAID0 or RAID5.
9589 struct mdinfo
*info
, *member
;
9590 int devices_that_can_grow
= 0;
9592 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): "
9593 "st->devnm = (%s)\n", st
->devnm
);
9595 if (geo
->size
> 0 ||
9596 geo
->level
!= UnSet
||
9597 geo
->layout
!= UnSet
||
9598 geo
->chunksize
!= 0 ||
9599 geo
->raid_disks
== UnSet
) {
9600 dprintf("imsm: Container operation is allowed for "
9601 "raid disks number change only.\n");
9605 if (direction
== ROLLBACK_METADATA_CHANGES
) {
9606 dprintf("imsm: Metadata changes rollback is not supported for "
9607 "container operation.\n");
9611 info
= container_content_imsm(st
, NULL
);
9612 for (member
= info
; member
; member
= member
->next
) {
9615 dprintf("imsm: checking device_num: %i\n",
9616 member
->container_member
);
9618 if (geo
->raid_disks
<= member
->array
.raid_disks
) {
9619 /* we work on container for Online Capacity Expansion
9620 * only so raid_disks has to grow
9622 dprintf("imsm: for container operation raid disks "
9623 "increase is required\n");
9627 if ((info
->array
.level
!= 0) &&
9628 (info
->array
.level
!= 5)) {
9629 /* we cannot use this container with other raid level
9631 dprintf("imsm: for container operation wrong"
9632 " raid level (%i) detected\n",
9636 /* check for platform support
9637 * for this raid level configuration
9639 struct intel_super
*super
= st
->sb
;
9640 if (!is_raid_level_supported(super
->orom
,
9641 member
->array
.level
,
9643 dprintf("platform does not support raid%d with"
9647 geo
->raid_disks
> 1 ? "s" : "");
9650 /* check if component size is aligned to chunk size
9652 if (info
->component_size
%
9653 (info
->array
.chunk_size
/512)) {
9654 dprintf("Component size is not aligned to "
9660 if (*old_raid_disks
&&
9661 info
->array
.raid_disks
!= *old_raid_disks
)
9663 *old_raid_disks
= info
->array
.raid_disks
;
9665 /* All raid5 and raid0 volumes in container
9666 * have to be ready for Online Capacity Expansion
9667 * so they need to be assembled. We have already
9668 * checked that no recovery etc is happening.
9670 result
= imsm_find_array_devnm_by_subdev(member
->container_member
,
9671 st
->container_devnm
);
9672 if (result
== NULL
) {
9673 dprintf("imsm: cannot find array\n");
9676 devices_that_can_grow
++;
9679 if (!member
&& devices_that_can_grow
)
9683 dprintf("\tContainer operation allowed\n");
9685 dprintf("\tError: %i\n", ret_val
);
9690 /* Function: get_spares_for_grow
9691 * Description: Allocates memory and creates list of spare devices
9692 * avaliable in container. Checks if spare drive size is acceptable.
9693 * Parameters: Pointer to the supertype structure
9694 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
9697 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
9699 unsigned long long min_size
= min_acceptable_spare_size_imsm(st
);
9700 return container_choose_spares(st
, min_size
, NULL
, NULL
, NULL
, 0);
9703 /******************************************************************************
9704 * function: imsm_create_metadata_update_for_reshape
9705 * Function creates update for whole IMSM container.
9707 ******************************************************************************/
9708 static int imsm_create_metadata_update_for_reshape(
9709 struct supertype
*st
,
9710 struct geo_params
*geo
,
9712 struct imsm_update_reshape
**updatep
)
9714 struct intel_super
*super
= st
->sb
;
9715 struct imsm_super
*mpb
= super
->anchor
;
9716 int update_memory_size
= 0;
9717 struct imsm_update_reshape
*u
= NULL
;
9718 struct mdinfo
*spares
= NULL
;
9720 int delta_disks
= 0;
9723 dprintf("imsm_update_metadata_for_reshape(enter) raid_disks = %i\n",
9726 delta_disks
= geo
->raid_disks
- old_raid_disks
;
9728 /* size of all update data without anchor */
9729 update_memory_size
= sizeof(struct imsm_update_reshape
);
9731 /* now add space for spare disks that we need to add. */
9732 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
9734 u
= xcalloc(1, update_memory_size
);
9735 u
->type
= update_reshape_container_disks
;
9736 u
->old_raid_disks
= old_raid_disks
;
9737 u
->new_raid_disks
= geo
->raid_disks
;
9739 /* now get spare disks list
9741 spares
= get_spares_for_grow(st
);
9744 || delta_disks
> spares
->array
.spare_disks
) {
9745 pr_err("imsm: ERROR: Cannot get spare devices "
9746 "for %s.\n", geo
->dev_name
);
9751 /* we have got spares
9752 * update disk list in imsm_disk list table in anchor
9754 dprintf("imsm: %i spares are available.\n\n",
9755 spares
->array
.spare_disks
);
9758 for (i
= 0; i
< delta_disks
; i
++) {
9763 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
9765 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
9766 dl
->index
= mpb
->num_disks
;
9776 dprintf("imsm: reshape update preparation :");
9777 if (i
== delta_disks
) {
9780 return update_memory_size
;
9783 dprintf(" Error\n");
9788 /******************************************************************************
9789 * function: imsm_create_metadata_update_for_size_change()
9790 * Creates update for IMSM array for array size change.
9792 ******************************************************************************/
9793 static int imsm_create_metadata_update_for_size_change(
9794 struct supertype
*st
,
9795 struct geo_params
*geo
,
9796 struct imsm_update_size_change
**updatep
)
9798 struct intel_super
*super
= st
->sb
;
9799 int update_memory_size
= 0;
9800 struct imsm_update_size_change
*u
= NULL
;
9802 dprintf("imsm_create_metadata_update_for_size_change(enter)"
9803 " New size = %llu\n", geo
->size
);
9805 /* size of all update data without anchor */
9806 update_memory_size
= sizeof(struct imsm_update_size_change
);
9808 u
= xcalloc(1, update_memory_size
);
9809 u
->type
= update_size_change
;
9810 u
->subdev
= super
->current_vol
;
9811 u
->new_size
= geo
->size
;
9813 dprintf("imsm: reshape update preparation : OK\n");
9816 return update_memory_size
;
9819 /******************************************************************************
9820 * function: imsm_create_metadata_update_for_migration()
9821 * Creates update for IMSM array.
9823 ******************************************************************************/
9824 static int imsm_create_metadata_update_for_migration(
9825 struct supertype
*st
,
9826 struct geo_params
*geo
,
9827 struct imsm_update_reshape_migration
**updatep
)
9829 struct intel_super
*super
= st
->sb
;
9830 int update_memory_size
= 0;
9831 struct imsm_update_reshape_migration
*u
= NULL
;
9832 struct imsm_dev
*dev
;
9833 int previous_level
= -1;
9835 dprintf("imsm_create_metadata_update_for_migration(enter)"
9836 " New Level = %i\n", geo
->level
);
9838 /* size of all update data without anchor */
9839 update_memory_size
= sizeof(struct imsm_update_reshape_migration
);
9841 u
= xcalloc(1, update_memory_size
);
9842 u
->type
= update_reshape_migration
;
9843 u
->subdev
= super
->current_vol
;
9844 u
->new_level
= geo
->level
;
9845 u
->new_layout
= geo
->layout
;
9846 u
->new_raid_disks
= u
->old_raid_disks
= geo
->raid_disks
;
9847 u
->new_disks
[0] = -1;
9848 u
->new_chunksize
= -1;
9850 dev
= get_imsm_dev(super
, u
->subdev
);
9852 struct imsm_map
*map
;
9854 map
= get_imsm_map(dev
, MAP_0
);
9856 int current_chunk_size
=
9857 __le16_to_cpu(map
->blocks_per_strip
) / 2;
9859 if (geo
->chunksize
!= current_chunk_size
) {
9860 u
->new_chunksize
= geo
->chunksize
/ 1024;
9862 "chunk size change from %i to %i\n",
9863 current_chunk_size
, u
->new_chunksize
);
9865 previous_level
= map
->raid_level
;
9868 if ((geo
->level
== 5) && (previous_level
== 0)) {
9869 struct mdinfo
*spares
= NULL
;
9871 u
->new_raid_disks
++;
9872 spares
= get_spares_for_grow(st
);
9873 if ((spares
== NULL
) || (spares
->array
.spare_disks
< 1)) {
9876 update_memory_size
= 0;
9877 dprintf("error: cannot get spare device "
9878 "for requested migration");
9883 dprintf("imsm: reshape update preparation : OK\n");
9886 return update_memory_size
;
9889 static void imsm_update_metadata_locally(struct supertype
*st
,
9892 struct metadata_update mu
;
9897 mu
.space_list
= NULL
;
9899 if (imsm_prepare_update(st
, &mu
))
9900 imsm_process_update(st
, &mu
);
9902 while (mu
.space_list
) {
9903 void **space
= mu
.space_list
;
9904 mu
.space_list
= *space
;
9909 /***************************************************************************
9910 * Function: imsm_analyze_change
9911 * Description: Function analyze change for single volume
9912 * and validate if transition is supported
9913 * Parameters: Geometry parameters, supertype structure,
9914 * metadata change direction (apply/rollback)
9915 * Returns: Operation type code on success, -1 if fail
9916 ****************************************************************************/
9917 enum imsm_reshape_type
imsm_analyze_change(struct supertype
*st
,
9918 struct geo_params
*geo
,
9925 /* number of added/removed disks in operation result */
9926 int devNumChange
= 0;
9927 /* imsm compatible layout value for array geometry verification */
9928 int imsm_layout
= -1;
9930 struct imsm_dev
*dev
;
9931 struct intel_super
*super
;
9932 unsigned long long current_size
;
9933 unsigned long long free_size
;
9934 unsigned long long max_size
;
9937 getinfo_super_imsm_volume(st
, &info
, NULL
);
9938 if ((geo
->level
!= info
.array
.level
) &&
9939 (geo
->level
>= 0) &&
9940 (geo
->level
!= UnSet
)) {
9941 switch (info
.array
.level
) {
9943 if (geo
->level
== 5) {
9944 change
= CH_MIGRATION
;
9945 if (geo
->layout
!= ALGORITHM_LEFT_ASYMMETRIC
) {
9946 pr_err("Error. Requested Layout "
9947 "not supported (left-asymmetric layout "
9948 "is supported only)!\n");
9950 goto analyse_change_exit
;
9952 imsm_layout
= geo
->layout
;
9954 devNumChange
= 1; /* parity disk added */
9955 } else if (geo
->level
== 10) {
9956 change
= CH_TAKEOVER
;
9958 devNumChange
= 2; /* two mirrors added */
9959 imsm_layout
= 0x102; /* imsm supported layout */
9964 if (geo
->level
== 0) {
9965 change
= CH_TAKEOVER
;
9967 devNumChange
= -(geo
->raid_disks
/2);
9968 imsm_layout
= 0; /* imsm raid0 layout */
9973 pr_err("Error. Level Migration from %d to %d "
9975 info
.array
.level
, geo
->level
);
9976 goto analyse_change_exit
;
9979 geo
->level
= info
.array
.level
;
9981 if ((geo
->layout
!= info
.array
.layout
)
9982 && ((geo
->layout
!= UnSet
) && (geo
->layout
!= -1))) {
9983 change
= CH_MIGRATION
;
9984 if ((info
.array
.layout
== 0)
9985 && (info
.array
.level
== 5)
9986 && (geo
->layout
== 5)) {
9987 /* reshape 5 -> 4 */
9988 } else if ((info
.array
.layout
== 5)
9989 && (info
.array
.level
== 5)
9990 && (geo
->layout
== 0)) {
9991 /* reshape 4 -> 5 */
9995 pr_err("Error. Layout Migration from %d to %d "
9997 info
.array
.layout
, geo
->layout
);
9999 goto analyse_change_exit
;
10002 geo
->layout
= info
.array
.layout
;
10003 if (imsm_layout
== -1)
10004 imsm_layout
= info
.array
.layout
;
10007 if ((geo
->chunksize
> 0) && (geo
->chunksize
!= UnSet
)
10008 && (geo
->chunksize
!= info
.array
.chunk_size
))
10009 change
= CH_MIGRATION
;
10011 geo
->chunksize
= info
.array
.chunk_size
;
10013 chunk
= geo
->chunksize
/ 1024;
10016 dev
= get_imsm_dev(super
, super
->current_vol
);
10017 data_disks
= imsm_num_data_members(dev
, MAP_0
);
10018 /* compute current size per disk member
10020 current_size
= info
.custom_array_size
/ data_disks
;
10022 if ((geo
->size
> 0) && (geo
->size
!= MAX_SIZE
)) {
10023 /* align component size
10025 geo
->size
= imsm_component_size_aligment_check(
10026 get_imsm_raid_level(dev
->vol
.map
),
10029 if (geo
->size
== 0) {
10030 pr_err("Error. Size expansion is " \
10031 "supported only (current size is %llu, " \
10032 "requested size /rounded/ is 0).\n",
10034 goto analyse_change_exit
;
10038 if ((current_size
!= geo
->size
) && (geo
->size
> 0)) {
10039 if (change
!= -1) {
10040 pr_err("Error. Size change should be the only "
10041 "one at a time.\n");
10043 goto analyse_change_exit
;
10045 if ((super
->current_vol
+ 1) != super
->anchor
->num_raid_devs
) {
10046 pr_err("Error. The last volume in container "
10047 "can be expanded only (%i/%s).\n",
10048 super
->current_vol
, st
->devnm
);
10049 goto analyse_change_exit
;
10051 /* check the maximum available size
10053 rv
= imsm_get_free_size(st
, dev
->vol
.map
->num_members
,
10054 0, chunk
, &free_size
);
10056 /* Cannot find maximum available space
10060 max_size
= free_size
+ current_size
;
10061 /* align component size
10063 max_size
= imsm_component_size_aligment_check(
10064 get_imsm_raid_level(dev
->vol
.map
),
10068 if (geo
->size
== MAX_SIZE
) {
10069 /* requested size change to the maximum available size
10071 if (max_size
== 0) {
10072 pr_err("Error. Cannot find "
10073 "maximum available space.\n");
10075 goto analyse_change_exit
;
10077 geo
->size
= max_size
;
10080 if ((direction
== ROLLBACK_METADATA_CHANGES
)) {
10081 /* accept size for rollback only
10084 /* round size due to metadata compatibility
10086 geo
->size
= (geo
->size
>> SECT_PER_MB_SHIFT
)
10087 << SECT_PER_MB_SHIFT
;
10088 dprintf("Prepare update for size change to %llu\n",
10090 if (current_size
>= geo
->size
) {
10091 pr_err("Error. Size expansion is "
10092 "supported only (current size is %llu, "
10093 "requested size /rounded/ is %llu).\n",
10094 current_size
, geo
->size
);
10095 goto analyse_change_exit
;
10097 if (max_size
&& geo
->size
> max_size
) {
10098 pr_err("Error. Requested size is larger "
10099 "than maximum available size (maximum "
10100 "available size is %llu, "
10101 "requested size /rounded/ is %llu).\n",
10102 max_size
, geo
->size
);
10103 goto analyse_change_exit
;
10106 geo
->size
*= data_disks
;
10107 geo
->raid_disks
= dev
->vol
.map
->num_members
;
10108 change
= CH_ARRAY_SIZE
;
10110 if (!validate_geometry_imsm(st
,
10113 geo
->raid_disks
+ devNumChange
,
10115 geo
->size
, INVALID_SECTORS
,
10120 struct intel_super
*super
= st
->sb
;
10121 struct imsm_super
*mpb
= super
->anchor
;
10123 if (mpb
->num_raid_devs
> 1) {
10124 pr_err("Error. Cannot perform operation on %s"
10125 "- for this operation it MUST be single "
10126 "array in container\n",
10132 analyse_change_exit
:
10133 if ((direction
== ROLLBACK_METADATA_CHANGES
) &&
10134 ((change
== CH_MIGRATION
) || (change
== CH_TAKEOVER
))) {
10135 dprintf("imsm: Metadata changes rollback is not supported for "
10136 "migration and takeover operations.\n");
10142 int imsm_takeover(struct supertype
*st
, struct geo_params
*geo
)
10144 struct intel_super
*super
= st
->sb
;
10145 struct imsm_update_takeover
*u
;
10147 u
= xmalloc(sizeof(struct imsm_update_takeover
));
10149 u
->type
= update_takeover
;
10150 u
->subarray
= super
->current_vol
;
10152 /* 10->0 transition */
10153 if (geo
->level
== 0)
10154 u
->direction
= R10_TO_R0
;
10156 /* 0->10 transition */
10157 if (geo
->level
== 10)
10158 u
->direction
= R0_TO_R10
;
10160 /* update metadata locally */
10161 imsm_update_metadata_locally(st
, u
,
10162 sizeof(struct imsm_update_takeover
));
10163 /* and possibly remotely */
10164 if (st
->update_tail
)
10165 append_metadata_update(st
, u
,
10166 sizeof(struct imsm_update_takeover
));
10173 static int imsm_reshape_super(struct supertype
*st
, unsigned long long size
,
10175 int layout
, int chunksize
, int raid_disks
,
10176 int delta_disks
, char *backup
, char *dev
,
10177 int direction
, int verbose
)
10180 struct geo_params geo
;
10182 dprintf("imsm: reshape_super called.\n");
10184 memset(&geo
, 0, sizeof(struct geo_params
));
10186 geo
.dev_name
= dev
;
10187 strcpy(geo
.devnm
, st
->devnm
);
10190 geo
.layout
= layout
;
10191 geo
.chunksize
= chunksize
;
10192 geo
.raid_disks
= raid_disks
;
10193 if (delta_disks
!= UnSet
)
10194 geo
.raid_disks
+= delta_disks
;
10196 dprintf("\tfor level : %i\n", geo
.level
);
10197 dprintf("\tfor raid_disks : %i\n", geo
.raid_disks
);
10199 if (experimental() == 0)
10202 if (strcmp(st
->container_devnm
, st
->devnm
) == 0) {
10203 /* On container level we can only increase number of devices. */
10204 dprintf("imsm: info: Container operation\n");
10205 int old_raid_disks
= 0;
10207 if (imsm_reshape_is_allowed_on_container(
10208 st
, &geo
, &old_raid_disks
, direction
)) {
10209 struct imsm_update_reshape
*u
= NULL
;
10212 len
= imsm_create_metadata_update_for_reshape(
10213 st
, &geo
, old_raid_disks
, &u
);
10216 dprintf("imsm: Cannot prepare update\n");
10217 goto exit_imsm_reshape_super
;
10221 /* update metadata locally */
10222 imsm_update_metadata_locally(st
, u
, len
);
10223 /* and possibly remotely */
10224 if (st
->update_tail
)
10225 append_metadata_update(st
, u
, len
);
10230 pr_err("(imsm) Operation "
10231 "is not allowed on this container\n");
10234 /* On volume level we support following operations
10235 * - takeover: raid10 -> raid0; raid0 -> raid10
10236 * - chunk size migration
10237 * - migration: raid5 -> raid0; raid0 -> raid5
10239 struct intel_super
*super
= st
->sb
;
10240 struct intel_dev
*dev
= super
->devlist
;
10242 dprintf("imsm: info: Volume operation\n");
10243 /* find requested device */
10246 imsm_find_array_devnm_by_subdev(
10247 dev
->index
, st
->container_devnm
);
10248 if (devnm
&& strcmp(devnm
, geo
.devnm
) == 0)
10253 pr_err("Cannot find %s (%s) subarray\n",
10254 geo
.dev_name
, geo
.devnm
);
10255 goto exit_imsm_reshape_super
;
10257 super
->current_vol
= dev
->index
;
10258 change
= imsm_analyze_change(st
, &geo
, direction
);
10261 ret_val
= imsm_takeover(st
, &geo
);
10263 case CH_MIGRATION
: {
10264 struct imsm_update_reshape_migration
*u
= NULL
;
10266 imsm_create_metadata_update_for_migration(
10270 "Cannot prepare update\n");
10274 /* update metadata locally */
10275 imsm_update_metadata_locally(st
, u
, len
);
10276 /* and possibly remotely */
10277 if (st
->update_tail
)
10278 append_metadata_update(st
, u
, len
);
10283 case CH_ARRAY_SIZE
: {
10284 struct imsm_update_size_change
*u
= NULL
;
10286 imsm_create_metadata_update_for_size_change(
10290 "Cannot prepare update\n");
10294 /* update metadata locally */
10295 imsm_update_metadata_locally(st
, u
, len
);
10296 /* and possibly remotely */
10297 if (st
->update_tail
)
10298 append_metadata_update(st
, u
, len
);
10308 exit_imsm_reshape_super
:
10309 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
10313 /*******************************************************************************
10314 * Function: wait_for_reshape_imsm
10315 * Description: Function writes new sync_max value and waits until
10316 * reshape process reach new position
10318 * sra : general array info
10319 * ndata : number of disks in new array's layout
10322 * 1 : there is no reshape in progress,
10324 ******************************************************************************/
10325 int wait_for_reshape_imsm(struct mdinfo
*sra
, int ndata
)
10327 int fd
= sysfs_get_fd(sra
, NULL
, "sync_completed");
10328 unsigned long long completed
;
10329 /* to_complete : new sync_max position */
10330 unsigned long long to_complete
= sra
->reshape_progress
;
10331 unsigned long long position_to_set
= to_complete
/ ndata
;
10334 dprintf("imsm: wait_for_reshape_imsm() "
10335 "cannot open reshape_position\n");
10339 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
10340 dprintf("imsm: wait_for_reshape_imsm() "
10341 "cannot read reshape_position (no reshape in progres)\n");
10346 if (completed
> position_to_set
) {
10347 dprintf("imsm: wait_for_reshape_imsm() "
10348 "wrong next position to set %llu (%llu)\n",
10349 to_complete
, position_to_set
);
10353 dprintf("Position set: %llu\n", position_to_set
);
10354 if (sysfs_set_num(sra
, NULL
, "sync_max",
10355 position_to_set
) != 0) {
10356 dprintf("imsm: wait_for_reshape_imsm() "
10357 "cannot set reshape position to %llu\n",
10365 sysfs_wait(fd
, NULL
);
10366 if (sysfs_get_str(sra
, NULL
, "sync_action",
10368 strncmp(action
, "reshape", 7) != 0)
10370 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
10371 dprintf("imsm: wait_for_reshape_imsm() "
10372 "cannot read reshape_position (in loop)\n");
10376 } while (completed
< position_to_set
);
10382 /*******************************************************************************
10383 * Function: check_degradation_change
10384 * Description: Check that array hasn't become failed.
10386 * info : for sysfs access
10387 * sources : source disks descriptors
10388 * degraded: previous degradation level
10390 * degradation level
10391 ******************************************************************************/
10392 int check_degradation_change(struct mdinfo
*info
,
10396 unsigned long long new_degraded
;
10399 rv
= sysfs_get_ll(info
, NULL
, "degraded", &new_degraded
);
10400 if ((rv
== -1) || (new_degraded
!= (unsigned long long)degraded
)) {
10401 /* check each device to ensure it is still working */
10404 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
10405 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
10407 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
10409 if (sysfs_get_str(info
,
10410 sd
, "state", sbuf
, 20) < 0 ||
10411 strstr(sbuf
, "faulty") ||
10412 strstr(sbuf
, "in_sync") == NULL
) {
10413 /* this device is dead */
10414 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
10415 if (sd
->disk
.raid_disk
>= 0 &&
10416 sources
[sd
->disk
.raid_disk
] >= 0) {
10418 sd
->disk
.raid_disk
]);
10419 sources
[sd
->disk
.raid_disk
] =
10428 return new_degraded
;
10431 /*******************************************************************************
10432 * Function: imsm_manage_reshape
10433 * Description: Function finds array under reshape and it manages reshape
10434 * process. It creates stripes backups (if required) and sets
10437 * afd : Backup handle (nattive) - not used
10438 * sra : general array info
10439 * reshape : reshape parameters - not used
10440 * st : supertype structure
10441 * blocks : size of critical section [blocks]
10442 * fds : table of source device descriptor
10443 * offsets : start of array (offest per devices)
10445 * destfd : table of destination device descriptor
10446 * destoffsets : table of destination offsets (per device)
10448 * 1 : success, reshape is done
10450 ******************************************************************************/
10451 static int imsm_manage_reshape(
10452 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
10453 struct supertype
*st
, unsigned long backup_blocks
,
10454 int *fds
, unsigned long long *offsets
,
10455 int dests
, int *destfd
, unsigned long long *destoffsets
)
10458 struct intel_super
*super
= st
->sb
;
10459 struct intel_dev
*dv
= NULL
;
10460 struct imsm_dev
*dev
= NULL
;
10461 struct imsm_map
*map_src
;
10462 int migr_vol_qan
= 0;
10463 int ndata
, odata
; /* [bytes] */
10464 int chunk
; /* [bytes] */
10465 struct migr_record
*migr_rec
;
10467 unsigned int buf_size
; /* [bytes] */
10468 unsigned long long max_position
; /* array size [bytes] */
10469 unsigned long long next_step
; /* [blocks]/[bytes] */
10470 unsigned long long old_data_stripe_length
;
10471 unsigned long long start_src
; /* [bytes] */
10472 unsigned long long start
; /* [bytes] */
10473 unsigned long long start_buf_shift
; /* [bytes] */
10475 int source_layout
= 0;
10477 if (!fds
|| !offsets
|| !sra
)
10480 /* Find volume during the reshape */
10481 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
10482 if (dv
->dev
->vol
.migr_type
== MIGR_GEN_MIGR
10483 && dv
->dev
->vol
.migr_state
== 1) {
10488 /* Only one volume can migrate at the same time */
10489 if (migr_vol_qan
!= 1) {
10490 pr_err(": %s", migr_vol_qan
?
10491 "Number of migrating volumes greater than 1\n" :
10492 "There is no volume during migrationg\n");
10496 map_src
= get_imsm_map(dev
, MAP_1
);
10497 if (map_src
== NULL
)
10500 ndata
= imsm_num_data_members(dev
, MAP_0
);
10501 odata
= imsm_num_data_members(dev
, MAP_1
);
10503 chunk
= __le16_to_cpu(map_src
->blocks_per_strip
) * 512;
10504 old_data_stripe_length
= odata
* chunk
;
10506 migr_rec
= super
->migr_rec
;
10508 /* initialize migration record for start condition */
10509 if (sra
->reshape_progress
== 0)
10510 init_migr_record_imsm(st
, dev
, sra
);
10512 if (__le32_to_cpu(migr_rec
->rec_status
) != UNIT_SRC_NORMAL
) {
10513 dprintf("imsm: cannot restart migration when data "
10514 "are present in copy area.\n");
10517 /* Save checkpoint to update migration record for current
10518 * reshape position (in md). It can be farther than current
10519 * reshape position in metadata.
10521 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
10522 /* ignore error == 2, this can mean end of reshape here
10524 dprintf("imsm: Cannot write checkpoint to "
10525 "migration record (UNIT_SRC_NORMAL, "
10526 "initial save)\n");
10531 /* size for data */
10532 buf_size
= __le32_to_cpu(migr_rec
->blocks_per_unit
) * 512;
10533 /* extend buffer size for parity disk */
10534 buf_size
+= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
10535 /* add space for stripe aligment */
10536 buf_size
+= old_data_stripe_length
;
10537 if (posix_memalign((void **)&buf
, 4096, buf_size
)) {
10538 dprintf("imsm: Cannot allocate checpoint buffer\n");
10542 max_position
= sra
->component_size
* ndata
;
10543 source_layout
= imsm_level_to_layout(map_src
->raid_level
);
10545 while (__le32_to_cpu(migr_rec
->curr_migr_unit
) <
10546 __le32_to_cpu(migr_rec
->num_migr_units
)) {
10547 /* current reshape position [blocks] */
10548 unsigned long long current_position
=
10549 __le32_to_cpu(migr_rec
->blocks_per_unit
)
10550 * __le32_to_cpu(migr_rec
->curr_migr_unit
);
10551 unsigned long long border
;
10553 /* Check that array hasn't become failed.
10555 degraded
= check_degradation_change(sra
, fds
, degraded
);
10556 if (degraded
> 1) {
10557 dprintf("imsm: Abort reshape due to degradation"
10558 " level (%i)\n", degraded
);
10562 next_step
= __le32_to_cpu(migr_rec
->blocks_per_unit
);
10564 if ((current_position
+ next_step
) > max_position
)
10565 next_step
= max_position
- current_position
;
10567 start
= current_position
* 512;
10569 /* allign reading start to old geometry */
10570 start_buf_shift
= start
% old_data_stripe_length
;
10571 start_src
= start
- start_buf_shift
;
10573 border
= (start_src
/ odata
) - (start
/ ndata
);
10575 if (border
<= __le32_to_cpu(migr_rec
->dest_depth_per_unit
)) {
10576 /* save critical stripes to buf
10577 * start - start address of current unit
10578 * to backup [bytes]
10579 * start_src - start address of current unit
10580 * to backup alligned to source array
10583 unsigned long long next_step_filler
= 0;
10584 unsigned long long copy_length
= next_step
* 512;
10586 /* allign copy area length to stripe in old geometry */
10587 next_step_filler
= ((copy_length
+ start_buf_shift
)
10588 % old_data_stripe_length
);
10589 if (next_step_filler
)
10590 next_step_filler
= (old_data_stripe_length
10591 - next_step_filler
);
10592 dprintf("save_stripes() parameters: start = %llu,"
10593 "\tstart_src = %llu,\tnext_step*512 = %llu,"
10594 "\tstart_in_buf_shift = %llu,"
10595 "\tnext_step_filler = %llu\n",
10596 start
, start_src
, copy_length
,
10597 start_buf_shift
, next_step_filler
);
10599 if (save_stripes(fds
, offsets
, map_src
->num_members
,
10600 chunk
, map_src
->raid_level
,
10601 source_layout
, 0, NULL
, start_src
,
10603 next_step_filler
+ start_buf_shift
,
10605 dprintf("imsm: Cannot save stripes"
10609 /* Convert data to destination format and store it
10610 * in backup general migration area
10612 if (save_backup_imsm(st
, dev
, sra
,
10613 buf
+ start_buf_shift
, copy_length
)) {
10614 dprintf("imsm: Cannot save stripes to "
10615 "target devices\n");
10618 if (save_checkpoint_imsm(st
, sra
,
10619 UNIT_SRC_IN_CP_AREA
)) {
10620 dprintf("imsm: Cannot write checkpoint to "
10621 "migration record (UNIT_SRC_IN_CP_AREA)\n");
10625 /* set next step to use whole border area */
10626 border
/= next_step
;
10628 next_step
*= border
;
10630 /* When data backed up, checkpoint stored,
10631 * kick the kernel to reshape unit of data
10633 next_step
= next_step
+ sra
->reshape_progress
;
10634 /* limit next step to array max position */
10635 if (next_step
> max_position
)
10636 next_step
= max_position
;
10637 sysfs_set_num(sra
, NULL
, "suspend_lo", sra
->reshape_progress
);
10638 sysfs_set_num(sra
, NULL
, "suspend_hi", next_step
);
10639 sra
->reshape_progress
= next_step
;
10641 /* wait until reshape finish */
10642 if (wait_for_reshape_imsm(sra
, ndata
) < 0) {
10643 dprintf("wait_for_reshape_imsm returned error!\n");
10649 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
10650 /* ignore error == 2, this can mean end of reshape here
10652 dprintf("imsm: Cannot write checkpoint to "
10653 "migration record (UNIT_SRC_NORMAL)\n");
10659 /* clear migr_rec on disks after successful migration */
10662 memset(super
->migr_rec_buf
, 0, MIGR_REC_BUF_SIZE
);
10663 for (d
= super
->disks
; d
; d
= d
->next
) {
10664 if (d
->index
< 0 || is_failed(&d
->disk
))
10666 unsigned long long dsize
;
10668 get_dev_size(d
->fd
, NULL
, &dsize
);
10669 if (lseek64(d
->fd
, dsize
- MIGR_REC_POSITION
,
10671 if (write(d
->fd
, super
->migr_rec_buf
,
10672 MIGR_REC_BUF_SIZE
) != MIGR_REC_BUF_SIZE
)
10673 perror("Write migr_rec failed");
10677 /* return '1' if done */
10681 abort_reshape(sra
);
10686 #endif /* MDASSEMBLE */
10688 struct superswitch super_imsm
= {
10690 .examine_super
= examine_super_imsm
,
10691 .brief_examine_super
= brief_examine_super_imsm
,
10692 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
10693 .export_examine_super
= export_examine_super_imsm
,
10694 .detail_super
= detail_super_imsm
,
10695 .brief_detail_super
= brief_detail_super_imsm
,
10696 .write_init_super
= write_init_super_imsm
,
10697 .validate_geometry
= validate_geometry_imsm
,
10698 .add_to_super
= add_to_super_imsm
,
10699 .remove_from_super
= remove_from_super_imsm
,
10700 .detail_platform
= detail_platform_imsm
,
10701 .export_detail_platform
= export_detail_platform_imsm
,
10702 .kill_subarray
= kill_subarray_imsm
,
10703 .update_subarray
= update_subarray_imsm
,
10704 .load_container
= load_container_imsm
,
10705 .default_geometry
= default_geometry_imsm
,
10706 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
10707 .reshape_super
= imsm_reshape_super
,
10708 .manage_reshape
= imsm_manage_reshape
,
10709 .recover_backup
= recover_backup_imsm
,
10710 .copy_metadata
= copy_metadata_imsm
,
10712 .match_home
= match_home_imsm
,
10713 .uuid_from_super
= uuid_from_super_imsm
,
10714 .getinfo_super
= getinfo_super_imsm
,
10715 .getinfo_super_disks
= getinfo_super_disks_imsm
,
10716 .update_super
= update_super_imsm
,
10718 .avail_size
= avail_size_imsm
,
10719 .min_acceptable_spare_size
= min_acceptable_spare_size_imsm
,
10721 .compare_super
= compare_super_imsm
,
10723 .load_super
= load_super_imsm
,
10724 .init_super
= init_super_imsm
,
10725 .store_super
= store_super_imsm
,
10726 .free_super
= free_super_imsm
,
10727 .match_metadata_desc
= match_metadata_desc_imsm
,
10728 .container_content
= container_content_imsm
,
10729 .validate_container
= validate_container_imsm
,
10736 .open_new
= imsm_open_new
,
10737 .set_array_state
= imsm_set_array_state
,
10738 .set_disk
= imsm_set_disk
,
10739 .sync_metadata
= imsm_sync_metadata
,
10740 .activate_spare
= imsm_activate_spare
,
10741 .process_update
= imsm_process_update
,
10742 .prepare_update
= imsm_prepare_update
,
10743 #endif /* MDASSEMBLE */