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 SECT_PER_MB_SHIFT 11
93 /* Disk configuration info. */
94 #define IMSM_MAX_DEVICES 255
96 __u8 serial
[MAX_RAID_SERIAL_LEN
];/* 0xD8 - 0xE7 ascii serial number */
97 __u32 total_blocks
; /* 0xE8 - 0xEB total blocks */
98 __u32 scsi_id
; /* 0xEC - 0xEF scsi ID */
99 #define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
100 #define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
101 #define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
102 __u32 status
; /* 0xF0 - 0xF3 */
103 __u32 owner_cfg_num
; /* which config 0,1,2... owns this disk */
104 #define IMSM_DISK_FILLERS 4
105 __u32 filler
[IMSM_DISK_FILLERS
]; /* 0xF4 - 0x107 MPB_DISK_FILLERS for future expansion */
108 /* RAID map configuration infos. */
110 __u32 pba_of_lba0
; /* start address of partition */
111 __u32 blocks_per_member
;/* blocks per member */
112 __u32 num_data_stripes
; /* number of data stripes */
113 __u16 blocks_per_strip
;
114 __u8 map_state
; /* Normal, Uninitialized, Degraded, Failed */
115 #define IMSM_T_STATE_NORMAL 0
116 #define IMSM_T_STATE_UNINITIALIZED 1
117 #define IMSM_T_STATE_DEGRADED 2
118 #define IMSM_T_STATE_FAILED 3
120 #define IMSM_T_RAID0 0
121 #define IMSM_T_RAID1 1
122 #define IMSM_T_RAID5 5 /* since metadata version 1.2.02 ? */
123 __u8 num_members
; /* number of member disks */
124 __u8 num_domains
; /* number of parity domains */
125 __u8 failed_disk_num
; /* valid only when state is degraded */
127 __u32 filler
[7]; /* expansion area */
128 #define IMSM_ORD_REBUILD (1 << 24)
129 __u32 disk_ord_tbl
[1]; /* disk_ord_tbl[num_members],
130 * top byte contains some flags
132 } __attribute__ ((packed
));
135 __u32 curr_migr_unit
;
136 __u32 checkpoint_id
; /* id to access curr_migr_unit */
137 __u8 migr_state
; /* Normal or Migrating */
139 #define MIGR_REBUILD 1
140 #define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
141 #define MIGR_GEN_MIGR 3
142 #define MIGR_STATE_CHANGE 4
143 #define MIGR_REPAIR 5
144 __u8 migr_type
; /* Initializing, Rebuilding, ... */
146 __u8 fs_state
; /* fast-sync state for CnG (0xff == disabled) */
147 __u16 verify_errors
; /* number of mismatches */
148 __u16 bad_blocks
; /* number of bad blocks during verify */
150 struct imsm_map map
[1];
151 /* here comes another one if migr_state */
152 } __attribute__ ((packed
));
155 __u8 volume
[MAX_RAID_SERIAL_LEN
];
158 #define DEV_BOOTABLE __cpu_to_le32(0x01)
159 #define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
160 #define DEV_READ_COALESCING __cpu_to_le32(0x04)
161 #define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
162 #define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
163 #define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
164 #define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
165 #define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
166 #define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
167 #define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
168 #define DEV_CLONE_N_GO __cpu_to_le32(0x400)
169 #define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
170 #define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
171 __u32 status
; /* Persistent RaidDev status */
172 __u32 reserved_blocks
; /* Reserved blocks at beginning of volume */
176 __u8 cng_master_disk
;
180 #define IMSM_DEV_FILLERS 10
181 __u32 filler
[IMSM_DEV_FILLERS
];
183 } __attribute__ ((packed
));
186 __u8 sig
[MAX_SIGNATURE_LENGTH
]; /* 0x00 - 0x1F */
187 __u32 check_sum
; /* 0x20 - 0x23 MPB Checksum */
188 __u32 mpb_size
; /* 0x24 - 0x27 Size of MPB */
189 __u32 family_num
; /* 0x28 - 0x2B Checksum from first time this config was written */
190 __u32 generation_num
; /* 0x2C - 0x2F Incremented each time this array's MPB is written */
191 __u32 error_log_size
; /* 0x30 - 0x33 in bytes */
192 __u32 attributes
; /* 0x34 - 0x37 */
193 __u8 num_disks
; /* 0x38 Number of configured disks */
194 __u8 num_raid_devs
; /* 0x39 Number of configured volumes */
195 __u8 error_log_pos
; /* 0x3A */
196 __u8 fill
[1]; /* 0x3B */
197 __u32 cache_size
; /* 0x3c - 0x40 in mb */
198 __u32 orig_family_num
; /* 0x40 - 0x43 original family num */
199 __u32 pwr_cycle_count
; /* 0x44 - 0x47 simulated power cycle count for array */
200 __u32 bbm_log_size
; /* 0x48 - 0x4B - size of bad Block Mgmt Log in bytes */
201 #define IMSM_FILLERS 35
202 __u32 filler
[IMSM_FILLERS
]; /* 0x4C - 0xD7 RAID_MPB_FILLERS */
203 struct imsm_disk disk
[1]; /* 0xD8 diskTbl[numDisks] */
204 /* here comes imsm_dev[num_raid_devs] */
205 /* here comes BBM logs */
206 } __attribute__ ((packed
));
208 #define BBM_LOG_MAX_ENTRIES 254
210 struct bbm_log_entry
{
211 __u64 defective_block_start
;
212 #define UNREADABLE 0xFFFFFFFF
213 __u32 spare_block_offset
;
214 __u16 remapped_marked_count
;
216 } __attribute__ ((__packed__
));
219 __u32 signature
; /* 0xABADB10C */
221 __u32 reserved_spare_block_count
; /* 0 */
222 __u32 reserved
; /* 0xFFFF */
223 __u64 first_spare_lba
;
224 struct bbm_log_entry mapped_block_entries
[BBM_LOG_MAX_ENTRIES
];
225 } __attribute__ ((__packed__
));
229 static char *map_state_str
[] = { "normal", "uninitialized", "degraded", "failed" };
232 #define RAID_DISK_RESERVED_BLOCKS_IMSM_HI 2209
234 #define GEN_MIGR_AREA_SIZE 2048 /* General Migration Copy Area size in blocks */
236 #define UNIT_SRC_NORMAL 0 /* Source data for curr_migr_unit must
237 * be recovered using srcMap */
238 #define UNIT_SRC_IN_CP_AREA 1 /* Source data for curr_migr_unit has
239 * already been migrated and must
240 * be recovered from checkpoint area */
242 __u32 rec_status
; /* Status used to determine how to restart
243 * migration in case it aborts
245 __u32 curr_migr_unit
; /* 0..numMigrUnits-1 */
246 __u32 family_num
; /* Family number of MPB
247 * containing the RaidDev
248 * that is migrating */
249 __u32 ascending_migr
; /* True if migrating in increasing
251 __u32 blocks_per_unit
; /* Num disk blocks per unit of operation */
252 __u32 dest_depth_per_unit
; /* Num member blocks each destMap
254 * advances per unit-of-operation */
255 __u32 ckpt_area_pba
; /* Pba of first block of ckpt copy area */
256 __u32 dest_1st_member_lba
; /* First member lba on first
257 * stripe of destination */
258 __u32 num_migr_units
; /* Total num migration units-of-op */
259 __u32 post_migr_vol_cap
; /* Size of volume after
260 * migration completes */
261 __u32 post_migr_vol_cap_hi
; /* Expansion space for LBA64 */
262 __u32 ckpt_read_disk_num
; /* Which member disk in destSubMap[0] the
263 * migration ckpt record was read from
264 * (for recovered migrations) */
265 } __attribute__ ((__packed__
));
267 static __u8
migr_type(struct imsm_dev
*dev
)
269 if (dev
->vol
.migr_type
== MIGR_VERIFY
&&
270 dev
->status
& DEV_VERIFY_AND_FIX
)
273 return dev
->vol
.migr_type
;
276 static void set_migr_type(struct imsm_dev
*dev
, __u8 migr_type
)
278 /* for compatibility with older oroms convert MIGR_REPAIR, into
279 * MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status
281 if (migr_type
== MIGR_REPAIR
) {
282 dev
->vol
.migr_type
= MIGR_VERIFY
;
283 dev
->status
|= DEV_VERIFY_AND_FIX
;
285 dev
->vol
.migr_type
= migr_type
;
286 dev
->status
&= ~DEV_VERIFY_AND_FIX
;
290 static unsigned int sector_count(__u32 bytes
)
292 return ((bytes
+ (512-1)) & (~(512-1))) / 512;
295 static unsigned int mpb_sectors(struct imsm_super
*mpb
)
297 return sector_count(__le32_to_cpu(mpb
->mpb_size
));
301 struct imsm_dev
*dev
;
302 struct intel_dev
*next
;
307 enum sys_dev_type type
;
310 struct intel_hba
*next
;
317 /* internal representation of IMSM metadata */
320 void *buf
; /* O_DIRECT buffer for reading/writing metadata */
321 struct imsm_super
*anchor
; /* immovable parameters */
324 void *migr_rec_buf
; /* buffer for I/O operations */
325 struct migr_record
*migr_rec
; /* migration record */
327 size_t len
; /* size of the 'buf' allocation */
328 void *next_buf
; /* for realloc'ing buf from the manager */
330 int updates_pending
; /* count of pending updates for mdmon */
331 int current_vol
; /* index of raid device undergoing creation */
332 __u32 create_offset
; /* common start for 'current_vol' */
333 __u32 random
; /* random data for seeding new family numbers */
334 struct intel_dev
*devlist
;
338 __u8 serial
[MAX_RAID_SERIAL_LEN
];
341 struct imsm_disk disk
;
344 struct extent
*e
; /* for determining freespace @ create */
345 int raiddisk
; /* slot to fill in autolayout */
347 } *disks
, *current_disk
;
348 struct dl
*disk_mgmt_list
; /* list of disks to add/remove while mdmon
350 struct dl
*missing
; /* disks removed while we weren't looking */
351 struct bbm_log
*bbm_log
;
352 struct intel_hba
*hba
; /* device path of the raid controller for this metadata */
353 const struct imsm_orom
*orom
; /* platform firmware support */
354 struct intel_super
*next
; /* (temp) list for disambiguating family_num */
358 struct imsm_disk disk
;
359 #define IMSM_UNKNOWN_OWNER (-1)
361 struct intel_disk
*next
;
365 unsigned long long start
, size
;
368 /* definitions of reshape process types */
369 enum imsm_reshape_type
{
374 /* definition of messages passed to imsm_process_update */
375 enum imsm_update_type
{
376 update_activate_spare
,
380 update_add_remove_disk
,
381 update_reshape_container_disks
,
382 update_reshape_migration
,
384 update_general_migration_checkpoint
,
387 struct imsm_update_activate_spare
{
388 enum imsm_update_type type
;
392 struct imsm_update_activate_spare
*next
;
405 enum takeover_direction
{
409 struct imsm_update_takeover
{
410 enum imsm_update_type type
;
412 enum takeover_direction direction
;
415 struct imsm_update_reshape
{
416 enum imsm_update_type type
;
420 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
423 struct imsm_update_reshape_migration
{
424 enum imsm_update_type type
;
427 /* fields for array migration changes
434 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
437 struct imsm_update_general_migration_checkpoint
{
438 enum imsm_update_type type
;
439 __u32 curr_migr_unit
;
443 __u8 serial
[MAX_RAID_SERIAL_LEN
];
446 struct imsm_update_create_array
{
447 enum imsm_update_type type
;
452 struct imsm_update_kill_array
{
453 enum imsm_update_type type
;
457 struct imsm_update_rename_array
{
458 enum imsm_update_type type
;
459 __u8 name
[MAX_RAID_SERIAL_LEN
];
463 struct imsm_update_add_remove_disk
{
464 enum imsm_update_type type
;
468 static const char *_sys_dev_type
[] = {
469 [SYS_DEV_UNKNOWN
] = "Unknown",
470 [SYS_DEV_SAS
] = "SAS",
471 [SYS_DEV_SATA
] = "SATA"
474 const char *get_sys_dev_type(enum sys_dev_type type
)
476 if (type
>= SYS_DEV_MAX
)
477 type
= SYS_DEV_UNKNOWN
;
479 return _sys_dev_type
[type
];
482 static struct intel_hba
* alloc_intel_hba(struct sys_dev
*device
)
484 struct intel_hba
*result
= malloc(sizeof(*result
));
486 result
->type
= device
->type
;
487 result
->path
= strdup(device
->path
);
489 if (result
->path
&& (result
->pci_id
= strrchr(result
->path
, '/')) != NULL
)
495 static struct intel_hba
* find_intel_hba(struct intel_hba
*hba
, struct sys_dev
*device
)
497 struct intel_hba
*result
=NULL
;
498 for (result
= hba
; result
; result
= result
->next
) {
499 if (result
->type
== device
->type
&& strcmp(result
->path
, device
->path
) == 0)
505 static int attach_hba_to_super(struct intel_super
*super
, struct sys_dev
*device
)
507 struct intel_hba
*hba
;
509 /* check if disk attached to Intel HBA */
510 hba
= find_intel_hba(super
->hba
, device
);
513 /* Check if HBA is already attached to super */
514 if (super
->hba
== NULL
) {
515 super
->hba
= alloc_intel_hba(device
);
520 /* Intel metadata allows for all disks attached to the same type HBA.
521 * Do not sypport odf HBA types mixing
523 if (device
->type
!= hba
->type
)
529 hba
->next
= alloc_intel_hba(device
);
533 static struct sys_dev
* find_disk_attached_hba(int fd
, const char *devname
)
535 struct sys_dev
*list
, *elem
, *prev
;
538 if ((list
= find_intel_devices()) == NULL
)
542 disk_path
= (char *) devname
;
544 disk_path
= diskfd_to_devpath(fd
);
551 for (prev
= NULL
, elem
= list
; elem
; prev
= elem
, elem
= elem
->next
) {
552 if (path_attached_to_hba(disk_path
, elem
->path
)) {
556 prev
->next
= elem
->next
;
558 if (disk_path
!= devname
)
564 if (disk_path
!= devname
)
572 static int find_intel_hba_capability(int fd
, struct intel_super
*super
,
575 static struct supertype
*match_metadata_desc_imsm(char *arg
)
577 struct supertype
*st
;
579 if (strcmp(arg
, "imsm") != 0 &&
580 strcmp(arg
, "default") != 0
584 st
= malloc(sizeof(*st
));
587 memset(st
, 0, sizeof(*st
));
588 st
->container_dev
= NoMdDev
;
589 st
->ss
= &super_imsm
;
590 st
->max_devs
= IMSM_MAX_DEVICES
;
591 st
->minor_version
= 0;
597 static __u8
*get_imsm_version(struct imsm_super
*mpb
)
599 return &mpb
->sig
[MPB_SIG_LEN
];
603 /* retrieve a disk directly from the anchor when the anchor is known to be
604 * up-to-date, currently only at load time
606 static struct imsm_disk
*__get_imsm_disk(struct imsm_super
*mpb
, __u8 index
)
608 if (index
>= mpb
->num_disks
)
610 return &mpb
->disk
[index
];
613 /* retrieve the disk description based on a index of the disk
616 static struct dl
*get_imsm_dl_disk(struct intel_super
*super
, __u8 index
)
620 for (d
= super
->disks
; d
; d
= d
->next
)
621 if (d
->index
== index
)
626 /* retrieve a disk from the parsed metadata */
627 static struct imsm_disk
*get_imsm_disk(struct intel_super
*super
, __u8 index
)
631 dl
= get_imsm_dl_disk(super
, index
);
638 /* generate a checksum directly from the anchor when the anchor is known to be
639 * up-to-date, currently only at load or write_super after coalescing
641 static __u32
__gen_imsm_checksum(struct imsm_super
*mpb
)
643 __u32 end
= mpb
->mpb_size
/ sizeof(end
);
644 __u32
*p
= (__u32
*) mpb
;
648 sum
+= __le32_to_cpu(*p
);
652 return sum
- __le32_to_cpu(mpb
->check_sum
);
655 static size_t sizeof_imsm_map(struct imsm_map
*map
)
657 return sizeof(struct imsm_map
) + sizeof(__u32
) * (map
->num_members
- 1);
660 struct imsm_map
*get_imsm_map(struct imsm_dev
*dev
, int second_map
)
662 /* A device can have 2 maps if it is in the middle of a migration.
664 * 0 - we return the first map
665 * 1 - we return the second map if it exists, else NULL
666 * -1 - we return the second map if it exists, else the first
668 struct imsm_map
*map
= &dev
->vol
.map
[0];
670 if (second_map
== 1 && !dev
->vol
.migr_state
)
672 else if (second_map
== 1 ||
673 (second_map
< 0 && dev
->vol
.migr_state
)) {
676 return ptr
+ sizeof_imsm_map(map
);
682 /* return the size of the device.
683 * migr_state increases the returned size if map[0] were to be duplicated
685 static size_t sizeof_imsm_dev(struct imsm_dev
*dev
, int migr_state
)
687 size_t size
= sizeof(*dev
) - sizeof(struct imsm_map
) +
688 sizeof_imsm_map(get_imsm_map(dev
, 0));
690 /* migrating means an additional map */
691 if (dev
->vol
.migr_state
)
692 size
+= sizeof_imsm_map(get_imsm_map(dev
, 1));
694 size
+= sizeof_imsm_map(get_imsm_map(dev
, 0));
700 /* retrieve disk serial number list from a metadata update */
701 static struct disk_info
*get_disk_info(struct imsm_update_create_array
*update
)
704 struct disk_info
*inf
;
706 inf
= u
+ sizeof(*update
) - sizeof(struct imsm_dev
) +
707 sizeof_imsm_dev(&update
->dev
, 0);
713 static struct imsm_dev
*__get_imsm_dev(struct imsm_super
*mpb
, __u8 index
)
719 if (index
>= mpb
->num_raid_devs
)
722 /* devices start after all disks */
723 offset
= ((void *) &mpb
->disk
[mpb
->num_disks
]) - _mpb
;
725 for (i
= 0; i
<= index
; i
++)
727 return _mpb
+ offset
;
729 offset
+= sizeof_imsm_dev(_mpb
+ offset
, 0);
734 static struct imsm_dev
*get_imsm_dev(struct intel_super
*super
, __u8 index
)
736 struct intel_dev
*dv
;
738 if (index
>= super
->anchor
->num_raid_devs
)
740 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
741 if (dv
->index
== index
)
749 * == 1 get second map
750 * == -1 than get map according to the current migr_state
752 static __u32
get_imsm_ord_tbl_ent(struct imsm_dev
*dev
,
756 struct imsm_map
*map
;
758 map
= get_imsm_map(dev
, second_map
);
760 /* top byte identifies disk under rebuild */
761 return __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
764 #define ord_to_idx(ord) (((ord) << 8) >> 8)
765 static __u32
get_imsm_disk_idx(struct imsm_dev
*dev
, int slot
, int second_map
)
767 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, second_map
);
769 return ord_to_idx(ord
);
772 static void set_imsm_ord_tbl_ent(struct imsm_map
*map
, int slot
, __u32 ord
)
774 map
->disk_ord_tbl
[slot
] = __cpu_to_le32(ord
);
777 static int get_imsm_disk_slot(struct imsm_map
*map
, unsigned idx
)
782 for (slot
= 0; slot
< map
->num_members
; slot
++) {
783 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
784 if (ord_to_idx(ord
) == idx
)
791 static int get_imsm_raid_level(struct imsm_map
*map
)
793 if (map
->raid_level
== 1) {
794 if (map
->num_members
== 2)
800 return map
->raid_level
;
803 static int cmp_extent(const void *av
, const void *bv
)
805 const struct extent
*a
= av
;
806 const struct extent
*b
= bv
;
807 if (a
->start
< b
->start
)
809 if (a
->start
> b
->start
)
814 static int count_memberships(struct dl
*dl
, struct intel_super
*super
)
819 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
820 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
821 struct imsm_map
*map
= get_imsm_map(dev
, 0);
823 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
830 static struct extent
*get_extents(struct intel_super
*super
, struct dl
*dl
)
832 /* find a list of used extents on the given physical device */
833 struct extent
*rv
, *e
;
835 int memberships
= count_memberships(dl
, super
);
838 /* trim the reserved area for spares, so they can join any array
839 * regardless of whether the OROM has assigned sectors from the
840 * IMSM_RESERVED_SECTORS region
843 reservation
= MPB_SECTOR_CNT
;
845 reservation
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
847 rv
= malloc(sizeof(struct extent
) * (memberships
+ 1));
852 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
853 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
854 struct imsm_map
*map
= get_imsm_map(dev
, 0);
856 if (get_imsm_disk_slot(map
, dl
->index
) >= 0) {
857 e
->start
= __le32_to_cpu(map
->pba_of_lba0
);
858 e
->size
= __le32_to_cpu(map
->blocks_per_member
);
862 qsort(rv
, memberships
, sizeof(*rv
), cmp_extent
);
864 /* determine the start of the metadata
865 * when no raid devices are defined use the default
866 * ...otherwise allow the metadata to truncate the value
867 * as is the case with older versions of imsm
870 struct extent
*last
= &rv
[memberships
- 1];
873 remainder
= __le32_to_cpu(dl
->disk
.total_blocks
) -
874 (last
->start
+ last
->size
);
875 /* round down to 1k block to satisfy precision of the kernel
879 /* make sure remainder is still sane */
880 if (remainder
< (unsigned)ROUND_UP(super
->len
, 512) >> 9)
881 remainder
= ROUND_UP(super
->len
, 512) >> 9;
882 if (reservation
> remainder
)
883 reservation
= remainder
;
885 e
->start
= __le32_to_cpu(dl
->disk
.total_blocks
) - reservation
;
890 /* try to determine how much space is reserved for metadata from
891 * the last get_extents() entry, otherwise fallback to the
894 static __u32
imsm_reserved_sectors(struct intel_super
*super
, struct dl
*dl
)
900 /* for spares just return a minimal reservation which will grow
901 * once the spare is picked up by an array
904 return MPB_SECTOR_CNT
;
906 e
= get_extents(super
, dl
);
908 return MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
910 /* scroll to last entry */
911 for (i
= 0; e
[i
].size
; i
++)
914 rv
= __le32_to_cpu(dl
->disk
.total_blocks
) - e
[i
].start
;
921 static int is_spare(struct imsm_disk
*disk
)
923 return (disk
->status
& SPARE_DISK
) == SPARE_DISK
;
926 static int is_configured(struct imsm_disk
*disk
)
928 return (disk
->status
& CONFIGURED_DISK
) == CONFIGURED_DISK
;
931 static int is_failed(struct imsm_disk
*disk
)
933 return (disk
->status
& FAILED_DISK
) == FAILED_DISK
;
936 /* Return minimum size of a spare that can be used in this array*/
937 static unsigned long long min_acceptable_spare_size_imsm(struct supertype
*st
)
939 struct intel_super
*super
= st
->sb
;
943 unsigned long long rv
= 0;
947 /* find first active disk in array */
949 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
953 /* find last lba used by subarrays */
954 e
= get_extents(super
, dl
);
957 for (i
= 0; e
[i
].size
; i
++)
960 rv
= e
[i
-1].start
+ e
[i
-1].size
;
962 /* add the amount of space needed for metadata */
963 rv
= rv
+ MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
968 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
969 struct imsm_dev
*dev
);
971 static void print_imsm_dev(struct intel_super
*super
,
972 struct imsm_dev
*dev
,
978 struct imsm_map
*map
= get_imsm_map(dev
, 0);
979 struct imsm_map
*map2
= get_imsm_map(dev
, 1);
983 printf("[%.16s]:\n", dev
->volume
);
984 printf(" UUID : %s\n", uuid
);
985 printf(" RAID Level : %d", get_imsm_raid_level(map
));
987 printf(" <-- %d", get_imsm_raid_level(map2
));
989 printf(" Members : %d", map
->num_members
);
991 printf(" <-- %d", map2
->num_members
);
993 printf(" Slots : [");
994 for (i
= 0; i
< map
->num_members
; i
++) {
995 ord
= get_imsm_ord_tbl_ent(dev
, i
, 0);
996 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1001 for (i
= 0; i
< map2
->num_members
; i
++) {
1002 ord
= get_imsm_ord_tbl_ent(dev
, i
, 1);
1003 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
1008 printf(" Failed disk : ");
1009 if (map
->failed_disk_num
== 0xff)
1012 printf("%i", map
->failed_disk_num
);
1014 slot
= get_imsm_disk_slot(map
, disk_idx
);
1016 ord
= get_imsm_ord_tbl_ent(dev
, slot
, -1);
1017 printf(" This Slot : %d%s\n", slot
,
1018 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
1020 printf(" This Slot : ?\n");
1021 sz
= __le32_to_cpu(dev
->size_high
);
1023 sz
+= __le32_to_cpu(dev
->size_low
);
1024 printf(" Array Size : %llu%s\n", (unsigned long long)sz
,
1025 human_size(sz
* 512));
1026 sz
= __le32_to_cpu(map
->blocks_per_member
);
1027 printf(" Per Dev Size : %llu%s\n", (unsigned long long)sz
,
1028 human_size(sz
* 512));
1029 printf(" Sector Offset : %u\n",
1030 __le32_to_cpu(map
->pba_of_lba0
));
1031 printf(" Num Stripes : %u\n",
1032 __le32_to_cpu(map
->num_data_stripes
));
1033 printf(" Chunk Size : %u KiB",
1034 __le16_to_cpu(map
->blocks_per_strip
) / 2);
1036 printf(" <-- %u KiB",
1037 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
1039 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
1040 printf(" Migrate State : ");
1041 if (dev
->vol
.migr_state
) {
1042 if (migr_type(dev
) == MIGR_INIT
)
1043 printf("initialize\n");
1044 else if (migr_type(dev
) == MIGR_REBUILD
)
1045 printf("rebuild\n");
1046 else if (migr_type(dev
) == MIGR_VERIFY
)
1048 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
1049 printf("general migration\n");
1050 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
1051 printf("state change\n");
1052 else if (migr_type(dev
) == MIGR_REPAIR
)
1055 printf("<unknown:%d>\n", migr_type(dev
));
1058 printf(" Map State : %s", map_state_str
[map
->map_state
]);
1059 if (dev
->vol
.migr_state
) {
1060 struct imsm_map
*map
= get_imsm_map(dev
, 1);
1062 printf(" <-- %s", map_state_str
[map
->map_state
]);
1063 printf("\n Checkpoint : %u (%llu)",
1064 __le32_to_cpu(dev
->vol
.curr_migr_unit
),
1065 (unsigned long long)blocks_per_migr_unit(super
, dev
));
1068 printf(" Dirty State : %s\n", dev
->vol
.dirty
? "dirty" : "clean");
1071 static void print_imsm_disk(struct imsm_disk
*disk
, int index
, __u32 reserved
)
1073 char str
[MAX_RAID_SERIAL_LEN
+ 1];
1076 if (index
< -1 || !disk
)
1080 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
1082 printf(" Disk%02d Serial : %s\n", index
, str
);
1084 printf(" Disk Serial : %s\n", str
);
1085 printf(" State :%s%s%s\n", is_spare(disk
) ? " spare" : "",
1086 is_configured(disk
) ? " active" : "",
1087 is_failed(disk
) ? " failed" : "");
1088 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
1089 sz
= __le32_to_cpu(disk
->total_blocks
) - reserved
;
1090 printf(" Usable Size : %llu%s\n", (unsigned long long)sz
,
1091 human_size(sz
* 512));
1094 static int is_gen_migration(struct imsm_dev
*dev
);
1096 void examine_migr_rec_imsm(struct intel_super
*super
)
1098 struct migr_record
*migr_rec
= super
->migr_rec
;
1099 struct imsm_super
*mpb
= super
->anchor
;
1102 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1103 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1104 if (is_gen_migration(dev
) == 0)
1107 printf("\nMigration Record Information:");
1108 if (super
->disks
->index
> 1) {
1109 printf(" Empty\n ");
1110 printf("Examine one of first two disks in array\n");
1113 printf("\n Status : ");
1114 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
1117 printf("Contains Data\n");
1118 printf(" Current Unit : %u\n",
1119 __le32_to_cpu(migr_rec
->curr_migr_unit
));
1120 printf(" Family : %u\n",
1121 __le32_to_cpu(migr_rec
->family_num
));
1122 printf(" Ascending : %u\n",
1123 __le32_to_cpu(migr_rec
->ascending_migr
));
1124 printf(" Blocks Per Unit : %u\n",
1125 __le32_to_cpu(migr_rec
->blocks_per_unit
));
1126 printf(" Dest. Depth Per Unit : %u\n",
1127 __le32_to_cpu(migr_rec
->dest_depth_per_unit
));
1128 printf(" Checkpoint Area pba : %u\n",
1129 __le32_to_cpu(migr_rec
->ckpt_area_pba
));
1130 printf(" First member lba : %u\n",
1131 __le32_to_cpu(migr_rec
->dest_1st_member_lba
));
1132 printf(" Total Number of Units : %u\n",
1133 __le32_to_cpu(migr_rec
->num_migr_units
));
1134 printf(" Size of volume : %u\n",
1135 __le32_to_cpu(migr_rec
->post_migr_vol_cap
));
1136 printf(" Expansion space for LBA64 : %u\n",
1137 __le32_to_cpu(migr_rec
->post_migr_vol_cap_hi
));
1138 printf(" Record was read from : %u\n",
1139 __le32_to_cpu(migr_rec
->ckpt_read_disk_num
));
1144 #endif /* MDASSEMBLE */
1145 /*******************************************************************************
1146 * function: imsm_check_attributes
1147 * Description: Function checks if features represented by attributes flags
1148 * are supported by mdadm.
1150 * attributes - Attributes read from metadata
1152 * 0 - passed attributes contains unsupported features flags
1153 * 1 - all features are supported
1154 ******************************************************************************/
1155 static int imsm_check_attributes(__u32 attributes
)
1158 __u32 not_supported
= MPB_ATTRIB_SUPPORTED
^0xffffffff;
1160 not_supported
&= ~MPB_ATTRIB_IGNORED
;
1162 not_supported
&= attributes
;
1163 if (not_supported
) {
1164 fprintf(stderr
, Name
"(IMSM): Unsupported attributes : %x\n",
1165 (unsigned)__le32_to_cpu(not_supported
));
1166 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1167 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY \n");
1168 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1170 if (not_supported
& MPB_ATTRIB_2TB
) {
1171 dprintf("\t\tMPB_ATTRIB_2TB\n");
1172 not_supported
^= MPB_ATTRIB_2TB
;
1174 if (not_supported
& MPB_ATTRIB_RAID0
) {
1175 dprintf("\t\tMPB_ATTRIB_RAID0\n");
1176 not_supported
^= MPB_ATTRIB_RAID0
;
1178 if (not_supported
& MPB_ATTRIB_RAID1
) {
1179 dprintf("\t\tMPB_ATTRIB_RAID1\n");
1180 not_supported
^= MPB_ATTRIB_RAID1
;
1182 if (not_supported
& MPB_ATTRIB_RAID10
) {
1183 dprintf("\t\tMPB_ATTRIB_RAID10\n");
1184 not_supported
^= MPB_ATTRIB_RAID10
;
1186 if (not_supported
& MPB_ATTRIB_RAID1E
) {
1187 dprintf("\t\tMPB_ATTRIB_RAID1E\n");
1188 not_supported
^= MPB_ATTRIB_RAID1E
;
1190 if (not_supported
& MPB_ATTRIB_RAID5
) {
1191 dprintf("\t\tMPB_ATTRIB_RAID5\n");
1192 not_supported
^= MPB_ATTRIB_RAID5
;
1194 if (not_supported
& MPB_ATTRIB_RAIDCNG
) {
1195 dprintf("\t\tMPB_ATTRIB_RAIDCNG\n");
1196 not_supported
^= MPB_ATTRIB_RAIDCNG
;
1198 if (not_supported
& MPB_ATTRIB_BBM
) {
1199 dprintf("\t\tMPB_ATTRIB_BBM\n");
1200 not_supported
^= MPB_ATTRIB_BBM
;
1202 if (not_supported
& MPB_ATTRIB_CHECKSUM_VERIFY
) {
1203 dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY (== MPB_ATTRIB_LEGACY)\n");
1204 not_supported
^= MPB_ATTRIB_CHECKSUM_VERIFY
;
1206 if (not_supported
& MPB_ATTRIB_EXP_STRIPE_SIZE
) {
1207 dprintf("\t\tMPB_ATTRIB_EXP_STRIP_SIZE\n");
1208 not_supported
^= MPB_ATTRIB_EXP_STRIPE_SIZE
;
1210 if (not_supported
& MPB_ATTRIB_2TB_DISK
) {
1211 dprintf("\t\tMPB_ATTRIB_2TB_DISK\n");
1212 not_supported
^= MPB_ATTRIB_2TB_DISK
;
1214 if (not_supported
& MPB_ATTRIB_NEVER_USE2
) {
1215 dprintf("\t\tMPB_ATTRIB_NEVER_USE2\n");
1216 not_supported
^= MPB_ATTRIB_NEVER_USE2
;
1218 if (not_supported
& MPB_ATTRIB_NEVER_USE
) {
1219 dprintf("\t\tMPB_ATTRIB_NEVER_USE\n");
1220 not_supported
^= MPB_ATTRIB_NEVER_USE
;
1224 dprintf(Name
"(IMSM): Unknown attributes : %x\n", not_supported
);
1233 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
1235 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
1237 struct intel_super
*super
= st
->sb
;
1238 struct imsm_super
*mpb
= super
->anchor
;
1239 char str
[MAX_SIGNATURE_LENGTH
];
1244 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
1247 snprintf(str
, MPB_SIG_LEN
, "%s", mpb
->sig
);
1248 printf(" Magic : %s\n", str
);
1249 snprintf(str
, strlen(MPB_VERSION_RAID0
), "%s", get_imsm_version(mpb
));
1250 printf(" Version : %s\n", get_imsm_version(mpb
));
1251 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
1252 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
1253 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
1254 printf(" Attributes : ");
1255 if (imsm_check_attributes(mpb
->attributes
))
1256 printf("All supported\n");
1258 printf("not supported\n");
1259 getinfo_super_imsm(st
, &info
, NULL
);
1260 fname_from_uuid(st
, &info
, nbuf
, ':');
1261 printf(" UUID : %s\n", nbuf
+ 5);
1262 sum
= __le32_to_cpu(mpb
->check_sum
);
1263 printf(" Checksum : %08x %s\n", sum
,
1264 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
1265 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
));
1266 printf(" Disks : %d\n", mpb
->num_disks
);
1267 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
1268 print_imsm_disk(__get_imsm_disk(mpb
, super
->disks
->index
), super
->disks
->index
, reserved
);
1269 if (super
->bbm_log
) {
1270 struct bbm_log
*log
= super
->bbm_log
;
1273 printf("Bad Block Management Log:\n");
1274 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
1275 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
1276 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
1277 printf(" Spare Blocks : %d\n", __le32_to_cpu(log
->reserved_spare_block_count
));
1278 printf(" First Spare : %llx\n",
1279 (unsigned long long) __le64_to_cpu(log
->first_spare_lba
));
1281 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1283 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1285 super
->current_vol
= i
;
1286 getinfo_super_imsm(st
, &info
, NULL
);
1287 fname_from_uuid(st
, &info
, nbuf
, ':');
1288 print_imsm_dev(super
, dev
, nbuf
+ 5, super
->disks
->index
);
1290 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1291 if (i
== super
->disks
->index
)
1293 print_imsm_disk(__get_imsm_disk(mpb
, i
), i
, reserved
);
1296 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
1297 if (dl
->index
== -1)
1298 print_imsm_disk(&dl
->disk
, -1, reserved
);
1300 examine_migr_rec_imsm(super
);
1303 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
1305 /* We just write a generic IMSM ARRAY entry */
1308 struct intel_super
*super
= st
->sb
;
1310 if (!super
->anchor
->num_raid_devs
) {
1311 printf("ARRAY metadata=imsm\n");
1315 getinfo_super_imsm(st
, &info
, NULL
);
1316 fname_from_uuid(st
, &info
, nbuf
, ':');
1317 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
1320 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
1322 /* We just write a generic IMSM ARRAY entry */
1326 struct intel_super
*super
= st
->sb
;
1329 if (!super
->anchor
->num_raid_devs
)
1332 getinfo_super_imsm(st
, &info
, NULL
);
1333 fname_from_uuid(st
, &info
, nbuf
, ':');
1334 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1335 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1337 super
->current_vol
= i
;
1338 getinfo_super_imsm(st
, &info
, NULL
);
1339 fname_from_uuid(st
, &info
, nbuf1
, ':');
1340 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
1341 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
1345 static void export_examine_super_imsm(struct supertype
*st
)
1347 struct intel_super
*super
= st
->sb
;
1348 struct imsm_super
*mpb
= super
->anchor
;
1352 getinfo_super_imsm(st
, &info
, NULL
);
1353 fname_from_uuid(st
, &info
, nbuf
, ':');
1354 printf("MD_METADATA=imsm\n");
1355 printf("MD_LEVEL=container\n");
1356 printf("MD_UUID=%s\n", nbuf
+5);
1357 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
1360 static void detail_super_imsm(struct supertype
*st
, char *homehost
)
1365 getinfo_super_imsm(st
, &info
, NULL
);
1366 fname_from_uuid(st
, &info
, nbuf
, ':');
1367 printf("\n UUID : %s\n", nbuf
+ 5);
1370 static void brief_detail_super_imsm(struct supertype
*st
)
1374 getinfo_super_imsm(st
, &info
, NULL
);
1375 fname_from_uuid(st
, &info
, nbuf
, ':');
1376 printf(" UUID=%s", nbuf
+ 5);
1379 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
);
1380 static void fd2devname(int fd
, char *name
);
1382 static int ahci_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
1384 /* dump an unsorted list of devices attached to AHCI Intel storage
1385 * controller, as well as non-connected ports
1387 int hba_len
= strlen(hba_path
) + 1;
1392 unsigned long port_mask
= (1 << port_count
) - 1;
1394 if (port_count
> (int)sizeof(port_mask
) * 8) {
1396 fprintf(stderr
, Name
": port_count %d out of range\n", port_count
);
1400 /* scroll through /sys/dev/block looking for devices attached to
1403 dir
= opendir("/sys/dev/block");
1404 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
1415 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
1417 path
= devt_to_devpath(makedev(major
, minor
));
1420 if (!path_attached_to_hba(path
, hba_path
)) {
1426 /* retrieve the scsi device type */
1427 if (asprintf(&device
, "/sys/dev/block/%d:%d/device/xxxxxxx", major
, minor
) < 0) {
1429 fprintf(stderr
, Name
": failed to allocate 'device'\n");
1433 sprintf(device
, "/sys/dev/block/%d:%d/device/type", major
, minor
);
1434 if (load_sys(device
, buf
) != 0) {
1436 fprintf(stderr
, Name
": failed to read device type for %s\n",
1442 type
= strtoul(buf
, NULL
, 10);
1444 /* if it's not a disk print the vendor and model */
1445 if (!(type
== 0 || type
== 7 || type
== 14)) {
1448 sprintf(device
, "/sys/dev/block/%d:%d/device/vendor", major
, minor
);
1449 if (load_sys(device
, buf
) == 0) {
1450 strncpy(vendor
, buf
, sizeof(vendor
));
1451 vendor
[sizeof(vendor
) - 1] = '\0';
1452 c
= (char *) &vendor
[sizeof(vendor
) - 1];
1453 while (isspace(*c
) || *c
== '\0')
1457 sprintf(device
, "/sys/dev/block/%d:%d/device/model", major
, minor
);
1458 if (load_sys(device
, buf
) == 0) {
1459 strncpy(model
, buf
, sizeof(model
));
1460 model
[sizeof(model
) - 1] = '\0';
1461 c
= (char *) &model
[sizeof(model
) - 1];
1462 while (isspace(*c
) || *c
== '\0')
1466 if (vendor
[0] && model
[0])
1467 sprintf(buf
, "%.64s %.64s", vendor
, model
);
1469 switch (type
) { /* numbers from hald/linux/device.c */
1470 case 1: sprintf(buf
, "tape"); break;
1471 case 2: sprintf(buf
, "printer"); break;
1472 case 3: sprintf(buf
, "processor"); break;
1474 case 5: sprintf(buf
, "cdrom"); break;
1475 case 6: sprintf(buf
, "scanner"); break;
1476 case 8: sprintf(buf
, "media_changer"); break;
1477 case 9: sprintf(buf
, "comm"); break;
1478 case 12: sprintf(buf
, "raid"); break;
1479 default: sprintf(buf
, "unknown");
1485 /* chop device path to 'host%d' and calculate the port number */
1486 c
= strchr(&path
[hba_len
], '/');
1489 fprintf(stderr
, Name
": %s - invalid path name\n", path
+ hba_len
);
1494 if (sscanf(&path
[hba_len
], "host%d", &port
) == 1)
1498 *c
= '/'; /* repair the full string */
1499 fprintf(stderr
, Name
": failed to determine port number for %s\n",
1506 /* mark this port as used */
1507 port_mask
&= ~(1 << port
);
1509 /* print out the device information */
1511 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
1515 fd
= dev_open(ent
->d_name
, O_RDONLY
);
1517 printf(" Port%d : - disk info unavailable -\n", port
);
1519 fd2devname(fd
, buf
);
1520 printf(" Port%d : %s", port
, buf
);
1521 if (imsm_read_serial(fd
, NULL
, (__u8
*) buf
) == 0)
1522 printf(" (%.*s)\n", MAX_RAID_SERIAL_LEN
, buf
);
1537 for (i
= 0; i
< port_count
; i
++)
1538 if (port_mask
& (1 << i
))
1539 printf(" Port%d : - no device attached -\n", i
);
1545 static void print_found_intel_controllers(struct sys_dev
*elem
)
1547 for (; elem
; elem
= elem
->next
) {
1548 fprintf(stderr
, Name
": found Intel(R) ");
1549 if (elem
->type
== SYS_DEV_SATA
)
1550 fprintf(stderr
, "SATA ");
1551 else if (elem
->type
== SYS_DEV_SAS
)
1552 fprintf(stderr
, "SAS ");
1553 fprintf(stderr
, "RAID controller");
1555 fprintf(stderr
, " at %s", elem
->pci_id
);
1556 fprintf(stderr
, ".\n");
1561 static int ahci_get_port_count(const char *hba_path
, int *port_count
)
1568 if ((dir
= opendir(hba_path
)) == NULL
)
1571 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
1574 if (sscanf(ent
->d_name
, "host%d", &host
) != 1)
1576 if (*port_count
== 0)
1578 else if (host
< host_base
)
1581 if (host
+ 1 > *port_count
+ host_base
)
1582 *port_count
= host
+ 1 - host_base
;
1588 static void print_imsm_capability(const struct imsm_orom
*orom
)
1590 printf(" Platform : Intel(R) Matrix Storage Manager\n");
1591 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
1592 orom
->hotfix_ver
, orom
->build
);
1593 printf(" RAID Levels :%s%s%s%s%s\n",
1594 imsm_orom_has_raid0(orom
) ? " raid0" : "",
1595 imsm_orom_has_raid1(orom
) ? " raid1" : "",
1596 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
1597 imsm_orom_has_raid10(orom
) ? " raid10" : "",
1598 imsm_orom_has_raid5(orom
) ? " raid5" : "");
1599 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1600 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
1601 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
1602 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
1603 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
1604 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
1605 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
1606 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
1607 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
1608 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
1609 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
1610 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
1611 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
1612 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
1613 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
1614 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
1615 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
1616 printf(" Max Disks : %d\n", orom
->tds
);
1617 printf(" Max Volumes : %d\n", orom
->vpa
);
1621 static int detail_platform_imsm(int verbose
, int enumerate_only
)
1623 /* There are two components to imsm platform support, the ahci SATA
1624 * controller and the option-rom. To find the SATA controller we
1625 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
1626 * controller with the Intel vendor id is present. This approach
1627 * allows mdadm to leverage the kernel's ahci detection logic, with the
1628 * caveat that if ahci.ko is not loaded mdadm will not be able to
1629 * detect platform raid capabilities. The option-rom resides in a
1630 * platform "Adapter ROM". We scan for its signature to retrieve the
1631 * platform capabilities. If raid support is disabled in the BIOS the
1632 * option-rom capability structure will not be available.
1634 const struct imsm_orom
*orom
;
1635 struct sys_dev
*list
, *hba
;
1640 if (enumerate_only
) {
1641 if (check_env("IMSM_NO_PLATFORM"))
1643 list
= find_intel_devices();
1646 for (hba
= list
; hba
; hba
= hba
->next
) {
1647 orom
= find_imsm_capability(hba
->type
);
1653 free_sys_dev(&list
);
1657 list
= find_intel_devices();
1660 fprintf(stderr
, Name
": no active Intel(R) RAID "
1661 "controller found.\n");
1662 free_sys_dev(&list
);
1665 print_found_intel_controllers(list
);
1667 for (hba
= list
; hba
; hba
= hba
->next
) {
1668 orom
= find_imsm_capability(hba
->type
);
1670 fprintf(stderr
, Name
": imsm capabilities not found for controller: %s (type %s)\n",
1671 hba
->path
, get_sys_dev_type(hba
->type
));
1673 print_imsm_capability(orom
);
1676 for (hba
= list
; hba
; hba
= hba
->next
) {
1677 printf(" I/O Controller : %s (%s)\n",
1678 hba
->path
, get_sys_dev_type(hba
->type
));
1680 if (hba
->type
== SYS_DEV_SATA
) {
1681 host_base
= ahci_get_port_count(hba
->path
, &port_count
);
1682 if (ahci_enumerate_ports(hba
->path
, port_count
, host_base
, verbose
)) {
1684 fprintf(stderr
, Name
": failed to enumerate "
1685 "ports on SATA controller at %s.", hba
->pci_id
);
1691 free_sys_dev(&list
);
1696 static int match_home_imsm(struct supertype
*st
, char *homehost
)
1698 /* the imsm metadata format does not specify any host
1699 * identification information. We return -1 since we can never
1700 * confirm nor deny whether a given array is "meant" for this
1701 * host. We rely on compare_super and the 'family_num' fields to
1702 * exclude member disks that do not belong, and we rely on
1703 * mdadm.conf to specify the arrays that should be assembled.
1704 * Auto-assembly may still pick up "foreign" arrays.
1710 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
1712 /* The uuid returned here is used for:
1713 * uuid to put into bitmap file (Create, Grow)
1714 * uuid for backup header when saving critical section (Grow)
1715 * comparing uuids when re-adding a device into an array
1716 * In these cases the uuid required is that of the data-array,
1717 * not the device-set.
1718 * uuid to recognise same set when adding a missing device back
1719 * to an array. This is a uuid for the device-set.
1721 * For each of these we can make do with a truncated
1722 * or hashed uuid rather than the original, as long as
1724 * In each case the uuid required is that of the data-array,
1725 * not the device-set.
1727 /* imsm does not track uuid's so we synthesis one using sha1 on
1728 * - The signature (Which is constant for all imsm array, but no matter)
1729 * - the orig_family_num of the container
1730 * - the index number of the volume
1731 * - the 'serial' number of the volume.
1732 * Hopefully these are all constant.
1734 struct intel_super
*super
= st
->sb
;
1737 struct sha1_ctx ctx
;
1738 struct imsm_dev
*dev
= NULL
;
1741 /* some mdadm versions failed to set ->orig_family_num, in which
1742 * case fall back to ->family_num. orig_family_num will be
1743 * fixed up with the first metadata update.
1745 family_num
= super
->anchor
->orig_family_num
;
1746 if (family_num
== 0)
1747 family_num
= super
->anchor
->family_num
;
1748 sha1_init_ctx(&ctx
);
1749 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
1750 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
1751 if (super
->current_vol
>= 0)
1752 dev
= get_imsm_dev(super
, super
->current_vol
);
1754 __u32 vol
= super
->current_vol
;
1755 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
1756 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
1758 sha1_finish_ctx(&ctx
, buf
);
1759 memcpy(uuid
, buf
, 4*4);
1764 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
1766 __u8
*v
= get_imsm_version(mpb
);
1767 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
1768 char major
[] = { 0, 0, 0 };
1769 char minor
[] = { 0 ,0, 0 };
1770 char patch
[] = { 0, 0, 0 };
1771 char *ver_parse
[] = { major
, minor
, patch
};
1775 while (*v
!= '\0' && v
< end
) {
1776 if (*v
!= '.' && j
< 2)
1777 ver_parse
[i
][j
++] = *v
;
1785 *m
= strtol(minor
, NULL
, 0);
1786 *p
= strtol(patch
, NULL
, 0);
1790 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
1792 /* migr_strip_size when repairing or initializing parity */
1793 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1794 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1796 switch (get_imsm_raid_level(map
)) {
1801 return 128*1024 >> 9;
1805 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
1807 /* migr_strip_size when rebuilding a degraded disk, no idea why
1808 * this is different than migr_strip_size_resync(), but it's good
1811 struct imsm_map
*map
= get_imsm_map(dev
, 1);
1812 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1814 switch (get_imsm_raid_level(map
)) {
1817 if (map
->num_members
% map
->num_domains
== 0)
1818 return 128*1024 >> 9;
1822 return max((__u32
) 64*1024 >> 9, chunk
);
1824 return 128*1024 >> 9;
1828 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
1830 struct imsm_map
*lo
= get_imsm_map(dev
, 0);
1831 struct imsm_map
*hi
= get_imsm_map(dev
, 1);
1832 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
1833 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
1835 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
1838 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
1840 struct imsm_map
*lo
= get_imsm_map(dev
, 0);
1841 int level
= get_imsm_raid_level(lo
);
1843 if (level
== 1 || level
== 10) {
1844 struct imsm_map
*hi
= get_imsm_map(dev
, 1);
1846 return hi
->num_domains
;
1848 return num_stripes_per_unit_resync(dev
);
1851 static __u8
imsm_num_data_members(struct imsm_dev
*dev
, int second_map
)
1853 /* named 'imsm_' because raid0, raid1 and raid10
1854 * counter-intuitively have the same number of data disks
1856 struct imsm_map
*map
= get_imsm_map(dev
, second_map
);
1858 switch (get_imsm_raid_level(map
)) {
1862 return map
->num_members
;
1864 return map
->num_members
- 1;
1866 dprintf("%s: unsupported raid level\n", __func__
);
1871 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
1873 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1874 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1876 switch(get_imsm_raid_level(map
)) {
1879 return chunk
* map
->num_domains
;
1881 return chunk
* map
->num_members
;
1887 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
1889 struct imsm_map
*map
= get_imsm_map(dev
, 1);
1890 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1891 __u32 strip
= block
/ chunk
;
1893 switch (get_imsm_raid_level(map
)) {
1896 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
1897 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
1899 return vol_stripe
* chunk
+ block
% chunk
;
1901 __u32 stripe
= strip
/ (map
->num_members
- 1);
1903 return stripe
* chunk
+ block
% chunk
;
1910 static __u64
blocks_per_migr_unit(struct intel_super
*super
,
1911 struct imsm_dev
*dev
)
1913 /* calculate the conversion factor between per member 'blocks'
1914 * (md/{resync,rebuild}_start) and imsm migration units, return
1915 * 0 for the 'not migrating' and 'unsupported migration' cases
1917 if (!dev
->vol
.migr_state
)
1920 switch (migr_type(dev
)) {
1921 case MIGR_GEN_MIGR
: {
1922 struct migr_record
*migr_rec
= super
->migr_rec
;
1923 return __le32_to_cpu(migr_rec
->blocks_per_unit
);
1928 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1929 __u32 stripes_per_unit
;
1930 __u32 blocks_per_unit
;
1939 /* yes, this is really the translation of migr_units to
1940 * per-member blocks in the 'resync' case
1942 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
1943 migr_chunk
= migr_strip_blocks_resync(dev
);
1944 disks
= imsm_num_data_members(dev
, 0);
1945 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
1946 stripe
= __le16_to_cpu(map
->blocks_per_strip
) * disks
;
1947 segment
= blocks_per_unit
/ stripe
;
1948 block_rel
= blocks_per_unit
- segment
* stripe
;
1949 parity_depth
= parity_segment_depth(dev
);
1950 block_map
= map_migr_block(dev
, block_rel
);
1951 return block_map
+ parity_depth
* segment
;
1953 case MIGR_REBUILD
: {
1954 __u32 stripes_per_unit
;
1957 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
1958 migr_chunk
= migr_strip_blocks_rebuild(dev
);
1959 return migr_chunk
* stripes_per_unit
;
1961 case MIGR_STATE_CHANGE
:
1967 static int imsm_level_to_layout(int level
)
1975 return ALGORITHM_LEFT_ASYMMETRIC
;
1982 /*******************************************************************************
1983 * Function: read_imsm_migr_rec
1984 * Description: Function reads imsm migration record from last sector of disk
1986 * fd : disk descriptor
1987 * super : metadata info
1991 ******************************************************************************/
1992 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
)
1995 unsigned long long dsize
;
1997 get_dev_size(fd
, NULL
, &dsize
);
1998 if (lseek64(fd
, dsize
- 512, SEEK_SET
) < 0) {
2000 Name
": Cannot seek to anchor block: %s\n",
2004 if (read(fd
, super
->migr_rec_buf
, 512) != 512) {
2006 Name
": Cannot read migr record block: %s\n",
2016 /*******************************************************************************
2017 * Function: load_imsm_migr_rec
2018 * Description: Function reads imsm migration record (it is stored at the last
2021 * super : imsm internal array info
2022 * info : general array info
2026 ******************************************************************************/
2027 static int load_imsm_migr_rec(struct intel_super
*super
, struct mdinfo
*info
)
2030 struct dl
*dl
= NULL
;
2036 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
2037 /* read only from one of the first two slots */
2038 if ((sd
->disk
.raid_disk
> 1) ||
2039 (sd
->disk
.raid_disk
< 0))
2041 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
2042 fd
= dev_open(nm
, O_RDONLY
);
2048 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
2049 /* read only from one of the first two slots */
2052 sprintf(nm
, "%d:%d", dl
->major
, dl
->minor
);
2053 fd
= dev_open(nm
, O_RDONLY
);
2060 retval
= read_imsm_migr_rec(fd
, super
);
2069 /*******************************************************************************
2070 * function: imsm_create_metadata_checkpoint_update
2071 * Description: It creates update for checkpoint change.
2073 * super : imsm internal array info
2074 * u : pointer to prepared update
2077 * If length is equal to 0, input pointer u contains no update
2078 ******************************************************************************/
2079 static int imsm_create_metadata_checkpoint_update(
2080 struct intel_super
*super
,
2081 struct imsm_update_general_migration_checkpoint
**u
)
2084 int update_memory_size
= 0;
2086 dprintf("imsm_create_metadata_checkpoint_update(enter)\n");
2092 /* size of all update data without anchor */
2093 update_memory_size
=
2094 sizeof(struct imsm_update_general_migration_checkpoint
);
2096 *u
= calloc(1, update_memory_size
);
2098 dprintf("error: cannot get memory for "
2099 "imsm_create_metadata_checkpoint_update update\n");
2102 (*u
)->type
= update_general_migration_checkpoint
;
2103 (*u
)->curr_migr_unit
= __le32_to_cpu(super
->migr_rec
->curr_migr_unit
);
2104 dprintf("imsm_create_metadata_checkpoint_update: prepared for %u\n",
2105 (*u
)->curr_migr_unit
);
2107 return update_memory_size
;
2111 static void imsm_update_metadata_locally(struct supertype
*st
,
2112 void *buf
, int len
);
2114 /*******************************************************************************
2115 * Function: write_imsm_migr_rec
2116 * Description: Function writes imsm migration record
2117 * (at the last sector of disk)
2119 * super : imsm internal array info
2123 ******************************************************************************/
2124 static int write_imsm_migr_rec(struct supertype
*st
)
2126 struct intel_super
*super
= st
->sb
;
2127 unsigned long long dsize
;
2133 struct imsm_update_general_migration_checkpoint
*u
;
2135 for (sd
= super
->disks
; sd
; sd
= sd
->next
) {
2136 /* write to 2 first slots only */
2137 if ((sd
->index
< 0) || (sd
->index
> 1))
2139 sprintf(nm
, "%d:%d", sd
->major
, sd
->minor
);
2140 fd
= dev_open(nm
, O_RDWR
);
2143 get_dev_size(fd
, NULL
, &dsize
);
2144 if (lseek64(fd
, dsize
- 512, SEEK_SET
) < 0) {
2146 Name
": Cannot seek to anchor block: %s\n",
2150 if (write(fd
, super
->migr_rec_buf
, 512) != 512) {
2152 Name
": Cannot write migr record block: %s\n",
2159 /* update checkpoint information in metadata */
2160 len
= imsm_create_metadata_checkpoint_update(super
, &u
);
2163 dprintf("imsm: Cannot prepare update\n");
2166 /* update metadata locally */
2167 imsm_update_metadata_locally(st
, u
, len
);
2168 /* and possibly remotely */
2169 if (st
->update_tail
) {
2170 append_metadata_update(st
, u
, len
);
2171 /* during reshape we do all work inside metadata handler
2172 * manage_reshape(), so metadata update has to be triggered
2175 flush_metadata_updates(st
);
2176 st
->update_tail
= &st
->updates
;
2186 #endif /* MDASSEMBLE */
2188 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
2190 struct intel_super
*super
= st
->sb
;
2191 struct migr_record
*migr_rec
= super
->migr_rec
;
2192 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
2193 struct imsm_map
*map
= get_imsm_map(dev
, 0);
2194 struct imsm_map
*prev_map
= get_imsm_map(dev
, 1);
2195 struct imsm_map
*map_to_analyse
= map
;
2198 unsigned int component_size_alligment
;
2199 int map_disks
= info
->array
.raid_disks
;
2201 memset(info
, 0, sizeof(*info
));
2203 map_to_analyse
= prev_map
;
2205 dl
= super
->current_disk
;
2207 info
->container_member
= super
->current_vol
;
2208 info
->array
.raid_disks
= map
->num_members
;
2209 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
2210 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
2211 info
->array
.md_minor
= -1;
2212 info
->array
.ctime
= 0;
2213 info
->array
.utime
= 0;
2214 info
->array
.chunk_size
=
2215 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
2216 info
->array
.state
= !dev
->vol
.dirty
;
2217 info
->custom_array_size
= __le32_to_cpu(dev
->size_high
);
2218 info
->custom_array_size
<<= 32;
2219 info
->custom_array_size
|= __le32_to_cpu(dev
->size_low
);
2220 if (prev_map
&& map
->map_state
== prev_map
->map_state
) {
2221 info
->reshape_active
= 1;
2222 info
->new_level
= get_imsm_raid_level(map
);
2223 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
2224 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
2225 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
2226 if (info
->delta_disks
) {
2227 /* this needs to be applied to every array
2230 info
->reshape_active
= 2;
2232 /* We shape information that we give to md might have to be
2233 * modify to cope with md's requirement for reshaping arrays.
2234 * For example, when reshaping a RAID0, md requires it to be
2235 * presented as a degraded RAID4.
2236 * Also if a RAID0 is migrating to a RAID5 we need to specify
2237 * the array as already being RAID5, but the 'before' layout
2238 * is a RAID4-like layout.
2240 switch (info
->array
.level
) {
2242 switch(info
->new_level
) {
2244 /* conversion is happening as RAID4 */
2245 info
->array
.level
= 4;
2246 info
->array
.raid_disks
+= 1;
2249 /* conversion is happening as RAID5 */
2250 info
->array
.level
= 5;
2251 info
->array
.layout
= ALGORITHM_PARITY_N
;
2252 info
->delta_disks
-= 1;
2255 /* FIXME error message */
2256 info
->array
.level
= UnSet
;
2262 info
->new_level
= UnSet
;
2263 info
->new_layout
= UnSet
;
2264 info
->new_chunk
= info
->array
.chunk_size
;
2265 info
->delta_disks
= 0;
2269 info
->disk
.major
= dl
->major
;
2270 info
->disk
.minor
= dl
->minor
;
2271 info
->disk
.number
= dl
->index
;
2272 info
->disk
.raid_disk
= get_imsm_disk_slot(map_to_analyse
,
2276 info
->data_offset
= __le32_to_cpu(map_to_analyse
->pba_of_lba0
);
2277 info
->component_size
=
2278 __le32_to_cpu(map_to_analyse
->blocks_per_member
);
2280 /* check component size aligment
2282 component_size_alligment
=
2283 info
->component_size
% (info
->array
.chunk_size
/512);
2285 if (component_size_alligment
&&
2286 (info
->array
.level
!= 1) && (info
->array
.level
!= UnSet
)) {
2287 dprintf("imsm: reported component size alligned from %llu ",
2288 info
->component_size
);
2289 info
->component_size
-= component_size_alligment
;
2290 dprintf("to %llu (%i).\n",
2291 info
->component_size
, component_size_alligment
);
2294 memset(info
->uuid
, 0, sizeof(info
->uuid
));
2295 info
->recovery_start
= MaxSector
;
2297 info
->reshape_progress
= 0;
2298 info
->resync_start
= MaxSector
;
2299 if (map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
2301 info
->resync_start
= 0;
2303 if (dev
->vol
.migr_state
) {
2304 switch (migr_type(dev
)) {
2307 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
2309 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
2311 info
->resync_start
= blocks_per_unit
* units
;
2314 case MIGR_GEN_MIGR
: {
2315 __u64 blocks_per_unit
= blocks_per_migr_unit(super
,
2317 __u64 units
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
2318 unsigned long long array_blocks
;
2321 if (__le32_to_cpu(migr_rec
->ascending_migr
) &&
2323 (__le32_to_cpu(migr_rec
->num_migr_units
)-1)) &&
2324 (super
->migr_rec
->rec_status
==
2325 __cpu_to_le32(UNIT_SRC_IN_CP_AREA
)))
2328 info
->reshape_progress
= blocks_per_unit
* units
;
2330 dprintf("IMSM: General Migration checkpoint : %llu "
2331 "(%llu) -> read reshape progress : %llu\n",
2332 (unsigned long long)units
,
2333 (unsigned long long)blocks_per_unit
,
2334 info
->reshape_progress
);
2336 used_disks
= imsm_num_data_members(dev
, 1);
2337 if (used_disks
> 0) {
2338 array_blocks
= map
->blocks_per_member
*
2340 /* round array size down to closest MB
2342 info
->custom_array_size
= (array_blocks
2343 >> SECT_PER_MB_SHIFT
)
2344 << SECT_PER_MB_SHIFT
;
2348 /* we could emulate the checkpointing of
2349 * 'sync_action=check' migrations, but for now
2350 * we just immediately complete them
2353 /* this is handled by container_content_imsm() */
2354 case MIGR_STATE_CHANGE
:
2355 /* FIXME handle other migrations */
2357 /* we are not dirty, so... */
2358 info
->resync_start
= MaxSector
;
2362 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
2363 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
2365 info
->array
.major_version
= -1;
2366 info
->array
.minor_version
= -2;
2367 devname
= devnum2devname(st
->container_dev
);
2368 *info
->text_version
= '\0';
2370 sprintf(info
->text_version
, "/%s/%d", devname
, info
->container_member
);
2372 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
2373 uuid_from_super_imsm(st
, info
->uuid
);
2377 for (i
=0; i
<map_disks
; i
++) {
2379 if (i
< info
->array
.raid_disks
) {
2380 struct imsm_disk
*dsk
;
2381 j
= get_imsm_disk_idx(dev
, i
, -1);
2382 dsk
= get_imsm_disk(super
, j
);
2383 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
2390 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
, int failed
);
2391 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
);
2393 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
2397 for (d
= super
->missing
; d
; d
= d
->next
)
2398 if (d
->index
== index
)
2403 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
2405 struct intel_super
*super
= st
->sb
;
2406 struct imsm_disk
*disk
;
2407 int map_disks
= info
->array
.raid_disks
;
2408 int max_enough
= -1;
2410 struct imsm_super
*mpb
;
2412 if (super
->current_vol
>= 0) {
2413 getinfo_super_imsm_volume(st
, info
, map
);
2416 memset(info
, 0, sizeof(*info
));
2418 /* Set raid_disks to zero so that Assemble will always pull in valid
2421 info
->array
.raid_disks
= 0;
2422 info
->array
.level
= LEVEL_CONTAINER
;
2423 info
->array
.layout
= 0;
2424 info
->array
.md_minor
= -1;
2425 info
->array
.ctime
= 0; /* N/A for imsm */
2426 info
->array
.utime
= 0;
2427 info
->array
.chunk_size
= 0;
2429 info
->disk
.major
= 0;
2430 info
->disk
.minor
= 0;
2431 info
->disk
.raid_disk
= -1;
2432 info
->reshape_active
= 0;
2433 info
->array
.major_version
= -1;
2434 info
->array
.minor_version
= -2;
2435 strcpy(info
->text_version
, "imsm");
2436 info
->safe_mode_delay
= 0;
2437 info
->disk
.number
= -1;
2438 info
->disk
.state
= 0;
2440 info
->recovery_start
= MaxSector
;
2442 /* do we have the all the insync disks that we expect? */
2443 mpb
= super
->anchor
;
2445 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
2446 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
2447 int failed
, enough
, j
, missing
= 0;
2448 struct imsm_map
*map
;
2451 failed
= imsm_count_failed(super
, dev
);
2452 state
= imsm_check_degraded(super
, dev
, failed
);
2453 map
= get_imsm_map(dev
, dev
->vol
.migr_state
);
2455 /* any newly missing disks?
2456 * (catches single-degraded vs double-degraded)
2458 for (j
= 0; j
< map
->num_members
; j
++) {
2459 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, -1);
2460 __u32 idx
= ord_to_idx(ord
);
2462 if (!(ord
& IMSM_ORD_REBUILD
) &&
2463 get_imsm_missing(super
, idx
)) {
2469 if (state
== IMSM_T_STATE_FAILED
)
2471 else if (state
== IMSM_T_STATE_DEGRADED
&&
2472 (state
!= map
->map_state
|| missing
))
2474 else /* we're normal, or already degraded */
2477 /* in the missing/failed disk case check to see
2478 * if at least one array is runnable
2480 max_enough
= max(max_enough
, enough
);
2482 dprintf("%s: enough: %d\n", __func__
, max_enough
);
2483 info
->container_enough
= max_enough
;
2486 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
2488 disk
= &super
->disks
->disk
;
2489 info
->data_offset
= __le32_to_cpu(disk
->total_blocks
) - reserved
;
2490 info
->component_size
= reserved
;
2491 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
2492 /* we don't change info->disk.raid_disk here because
2493 * this state will be finalized in mdmon after we have
2494 * found the 'most fresh' version of the metadata
2496 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
2497 info
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
2500 /* only call uuid_from_super_imsm when this disk is part of a populated container,
2501 * ->compare_super may have updated the 'num_raid_devs' field for spares
2503 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
2504 uuid_from_super_imsm(st
, info
->uuid
);
2506 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
2508 /* I don't know how to compute 'map' on imsm, so use safe default */
2511 for (i
= 0; i
< map_disks
; i
++)
2517 /* allocates memory and fills disk in mdinfo structure
2518 * for each disk in array */
2519 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
2521 struct mdinfo
*mddev
= NULL
;
2522 struct intel_super
*super
= st
->sb
;
2523 struct imsm_disk
*disk
;
2526 if (!super
|| !super
->disks
)
2529 mddev
= malloc(sizeof(*mddev
));
2531 fprintf(stderr
, Name
": Failed to allocate memory.\n");
2534 memset(mddev
, 0, sizeof(*mddev
));
2538 tmp
= malloc(sizeof(*tmp
));
2540 fprintf(stderr
, Name
": Failed to allocate memory.\n");
2545 memset(tmp
, 0, sizeof(*tmp
));
2547 tmp
->next
= mddev
->devs
;
2549 tmp
->disk
.number
= count
++;
2550 tmp
->disk
.major
= dl
->major
;
2551 tmp
->disk
.minor
= dl
->minor
;
2552 tmp
->disk
.state
= is_configured(disk
) ?
2553 (1 << MD_DISK_ACTIVE
) : 0;
2554 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
2555 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
2556 tmp
->disk
.raid_disk
= -1;
2562 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
2563 char *update
, char *devname
, int verbose
,
2564 int uuid_set
, char *homehost
)
2566 /* For 'assemble' and 'force' we need to return non-zero if any
2567 * change was made. For others, the return value is ignored.
2568 * Update options are:
2569 * force-one : This device looks a bit old but needs to be included,
2570 * update age info appropriately.
2571 * assemble: clear any 'faulty' flag to allow this device to
2573 * force-array: Array is degraded but being forced, mark it clean
2574 * if that will be needed to assemble it.
2576 * newdev: not used ????
2577 * grow: Array has gained a new device - this is currently for
2579 * resync: mark as dirty so a resync will happen.
2580 * name: update the name - preserving the homehost
2581 * uuid: Change the uuid of the array to match watch is given
2583 * Following are not relevant for this imsm:
2584 * sparc2.2 : update from old dodgey metadata
2585 * super-minor: change the preferred_minor number
2586 * summaries: update redundant counters.
2587 * homehost: update the recorded homehost
2588 * _reshape_progress: record new reshape_progress position.
2591 struct intel_super
*super
= st
->sb
;
2592 struct imsm_super
*mpb
;
2594 /* we can only update container info */
2595 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
2598 mpb
= super
->anchor
;
2600 if (strcmp(update
, "uuid") == 0 && uuid_set
&& !info
->update_private
)
2602 else if (strcmp(update
, "uuid") == 0 && uuid_set
&& info
->update_private
) {
2603 mpb
->orig_family_num
= *((__u32
*) info
->update_private
);
2605 } else if (strcmp(update
, "uuid") == 0) {
2606 __u32
*new_family
= malloc(sizeof(*new_family
));
2608 /* update orig_family_number with the incoming random
2609 * data, report the new effective uuid, and store the
2610 * new orig_family_num for future updates.
2613 memcpy(&mpb
->orig_family_num
, info
->uuid
, sizeof(__u32
));
2614 uuid_from_super_imsm(st
, info
->uuid
);
2615 *new_family
= mpb
->orig_family_num
;
2616 info
->update_private
= new_family
;
2619 } else if (strcmp(update
, "assemble") == 0)
2624 /* successful update? recompute checksum */
2626 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
2631 static size_t disks_to_mpb_size(int disks
)
2635 size
= sizeof(struct imsm_super
);
2636 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
2637 size
+= 2 * sizeof(struct imsm_dev
);
2638 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
2639 size
+= (4 - 2) * sizeof(struct imsm_map
);
2640 /* 4 possible disk_ord_tbl's */
2641 size
+= 4 * (disks
- 1) * sizeof(__u32
);
2646 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
)
2648 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
2651 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
2654 static void free_devlist(struct intel_super
*super
)
2656 struct intel_dev
*dv
;
2658 while (super
->devlist
) {
2659 dv
= super
->devlist
->next
;
2660 free(super
->devlist
->dev
);
2661 free(super
->devlist
);
2662 super
->devlist
= dv
;
2666 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
2668 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
2671 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
)
2675 * 0 same, or first was empty, and second was copied
2676 * 1 second had wrong number
2678 * 3 wrong other info
2680 struct intel_super
*first
= st
->sb
;
2681 struct intel_super
*sec
= tst
->sb
;
2688 /* in platform dependent environment test if the disks
2689 * use the same Intel hba
2691 if (!check_env("IMSM_NO_PLATFORM")) {
2692 if (!first
->hba
|| !sec
->hba
||
2693 (first
->hba
->type
!= sec
->hba
->type
)) {
2695 "HBAs of devices does not match %s != %s\n",
2696 first
->hba
? get_sys_dev_type(first
->hba
->type
) : NULL
,
2697 sec
->hba
? get_sys_dev_type(sec
->hba
->type
) : NULL
);
2702 /* if an anchor does not have num_raid_devs set then it is a free
2705 if (first
->anchor
->num_raid_devs
> 0 &&
2706 sec
->anchor
->num_raid_devs
> 0) {
2707 /* Determine if these disks might ever have been
2708 * related. Further disambiguation can only take place
2709 * in load_super_imsm_all
2711 __u32 first_family
= first
->anchor
->orig_family_num
;
2712 __u32 sec_family
= sec
->anchor
->orig_family_num
;
2714 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
2715 MAX_SIGNATURE_LENGTH
) != 0)
2718 if (first_family
== 0)
2719 first_family
= first
->anchor
->family_num
;
2720 if (sec_family
== 0)
2721 sec_family
= sec
->anchor
->family_num
;
2723 if (first_family
!= sec_family
)
2729 /* if 'first' is a spare promote it to a populated mpb with sec's
2732 if (first
->anchor
->num_raid_devs
== 0 &&
2733 sec
->anchor
->num_raid_devs
> 0) {
2735 struct intel_dev
*dv
;
2736 struct imsm_dev
*dev
;
2738 /* we need to copy raid device info from sec if an allocation
2739 * fails here we don't associate the spare
2741 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++) {
2742 dv
= malloc(sizeof(*dv
));
2745 dev
= malloc(sizeof_imsm_dev(get_imsm_dev(sec
, i
), 1));
2752 dv
->next
= first
->devlist
;
2753 first
->devlist
= dv
;
2755 if (i
< sec
->anchor
->num_raid_devs
) {
2756 /* allocation failure */
2757 free_devlist(first
);
2758 fprintf(stderr
, "imsm: failed to associate spare\n");
2761 first
->anchor
->num_raid_devs
= sec
->anchor
->num_raid_devs
;
2762 first
->anchor
->orig_family_num
= sec
->anchor
->orig_family_num
;
2763 first
->anchor
->family_num
= sec
->anchor
->family_num
;
2764 memcpy(first
->anchor
->sig
, sec
->anchor
->sig
, MAX_SIGNATURE_LENGTH
);
2765 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++)
2766 imsm_copy_dev(get_imsm_dev(first
, i
), get_imsm_dev(sec
, i
));
2772 static void fd2devname(int fd
, char *name
)
2776 char dname
[PATH_MAX
];
2781 if (fstat(fd
, &st
) != 0)
2783 sprintf(path
, "/sys/dev/block/%d:%d",
2784 major(st
.st_rdev
), minor(st
.st_rdev
));
2786 rv
= readlink(path
, dname
, sizeof(dname
));
2791 nm
= strrchr(dname
, '/');
2793 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
2796 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
2798 static int imsm_read_serial(int fd
, char *devname
,
2799 __u8 serial
[MAX_RAID_SERIAL_LEN
])
2801 unsigned char scsi_serial
[255];
2810 memset(scsi_serial
, 0, sizeof(scsi_serial
));
2812 rv
= scsi_get_serial(fd
, scsi_serial
, sizeof(scsi_serial
));
2814 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
2815 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
2816 fd2devname(fd
, (char *) serial
);
2823 Name
": Failed to retrieve serial for %s\n",
2828 rsp_len
= scsi_serial
[3];
2832 Name
": Failed to retrieve serial for %s\n",
2836 rsp_buf
= (char *) &scsi_serial
[4];
2838 /* trim all whitespace and non-printable characters and convert
2841 for (i
= 0, dest
= rsp_buf
; i
< rsp_len
; i
++) {
2844 /* ':' is reserved for use in placeholder serial
2845 * numbers for missing disks
2853 len
= dest
- rsp_buf
;
2856 /* truncate leading characters */
2857 if (len
> MAX_RAID_SERIAL_LEN
) {
2858 dest
+= len
- MAX_RAID_SERIAL_LEN
;
2859 len
= MAX_RAID_SERIAL_LEN
;
2862 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
2863 memcpy(serial
, dest
, len
);
2868 static int serialcmp(__u8
*s1
, __u8
*s2
)
2870 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
2873 static void serialcpy(__u8
*dest
, __u8
*src
)
2875 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
2878 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
2882 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
2883 if (serialcmp(dl
->serial
, serial
) == 0)
2889 static struct imsm_disk
*
2890 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
2894 for (i
= 0; i
< mpb
->num_disks
; i
++) {
2895 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
2897 if (serialcmp(disk
->serial
, serial
) == 0) {
2908 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
2910 struct imsm_disk
*disk
;
2915 __u8 serial
[MAX_RAID_SERIAL_LEN
];
2917 rv
= imsm_read_serial(fd
, devname
, serial
);
2922 dl
= calloc(1, sizeof(*dl
));
2926 Name
": failed to allocate disk buffer for %s\n",
2932 dl
->major
= major(stb
.st_rdev
);
2933 dl
->minor
= minor(stb
.st_rdev
);
2934 dl
->next
= super
->disks
;
2935 dl
->fd
= keep_fd
? fd
: -1;
2936 assert(super
->disks
== NULL
);
2938 serialcpy(dl
->serial
, serial
);
2941 fd2devname(fd
, name
);
2943 dl
->devname
= strdup(devname
);
2945 dl
->devname
= strdup(name
);
2947 /* look up this disk's index in the current anchor */
2948 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
2951 /* only set index on disks that are a member of a
2952 * populated contianer, i.e. one with raid_devs
2954 if (is_failed(&dl
->disk
))
2956 else if (is_spare(&dl
->disk
))
2964 /* When migrating map0 contains the 'destination' state while map1
2965 * contains the current state. When not migrating map0 contains the
2966 * current state. This routine assumes that map[0].map_state is set to
2967 * the current array state before being called.
2969 * Migration is indicated by one of the following states
2970 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
2971 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
2972 * map1state=unitialized)
2973 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
2975 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
2976 * map1state=degraded)
2977 * 5/ Migration (mig_state=1 migr_type=MIGR_GEN_MIGR map0state=normal
2980 static void migrate(struct imsm_dev
*dev
, struct intel_super
*super
,
2981 __u8 to_state
, int migr_type
)
2983 struct imsm_map
*dest
;
2984 struct imsm_map
*src
= get_imsm_map(dev
, 0);
2986 dev
->vol
.migr_state
= 1;
2987 set_migr_type(dev
, migr_type
);
2988 dev
->vol
.curr_migr_unit
= 0;
2989 dest
= get_imsm_map(dev
, 1);
2991 /* duplicate and then set the target end state in map[0] */
2992 memcpy(dest
, src
, sizeof_imsm_map(src
));
2993 if ((migr_type
== MIGR_REBUILD
) ||
2994 (migr_type
== MIGR_GEN_MIGR
)) {
2998 for (i
= 0; i
< src
->num_members
; i
++) {
2999 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
3000 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
3004 if (migr_type
== MIGR_GEN_MIGR
)
3005 /* Clear migration record */
3006 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
3008 src
->map_state
= to_state
;
3011 static void end_migration(struct imsm_dev
*dev
, __u8 map_state
)
3013 struct imsm_map
*map
= get_imsm_map(dev
, 0);
3014 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
);
3017 /* merge any IMSM_ORD_REBUILD bits that were not successfully
3018 * completed in the last migration.
3020 * FIXME add support for raid-level-migration
3022 for (i
= 0; i
< prev
->num_members
; i
++)
3023 for (j
= 0; j
< map
->num_members
; j
++)
3024 /* during online capacity expansion
3025 * disks position can be changed if takeover is used
3027 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
3028 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
3029 map
->disk_ord_tbl
[j
] |= prev
->disk_ord_tbl
[i
];
3033 dev
->vol
.migr_state
= 0;
3034 dev
->vol
.migr_type
= 0;
3035 dev
->vol
.curr_migr_unit
= 0;
3036 map
->map_state
= map_state
;
3040 static int parse_raid_devices(struct intel_super
*super
)
3043 struct imsm_dev
*dev_new
;
3044 size_t len
, len_migr
;
3046 size_t space_needed
= 0;
3047 struct imsm_super
*mpb
= super
->anchor
;
3049 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3050 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3051 struct intel_dev
*dv
;
3053 len
= sizeof_imsm_dev(dev_iter
, 0);
3054 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
3056 space_needed
+= len_migr
- len
;
3058 dv
= malloc(sizeof(*dv
));
3061 if (max_len
< len_migr
)
3063 if (max_len
> len_migr
)
3064 space_needed
+= max_len
- len_migr
;
3065 dev_new
= malloc(max_len
);
3070 imsm_copy_dev(dev_new
, dev_iter
);
3073 dv
->next
= super
->devlist
;
3074 super
->devlist
= dv
;
3077 /* ensure that super->buf is large enough when all raid devices
3080 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
3083 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
, 512);
3084 if (posix_memalign(&buf
, 512, len
) != 0)
3087 memcpy(buf
, super
->buf
, super
->len
);
3088 memset(buf
+ super
->len
, 0, len
- super
->len
);
3097 /* retrieve a pointer to the bbm log which starts after all raid devices */
3098 struct bbm_log
*__get_imsm_bbm_log(struct imsm_super
*mpb
)
3102 if (__le32_to_cpu(mpb
->bbm_log_size
)) {
3104 ptr
+= mpb
->mpb_size
- __le32_to_cpu(mpb
->bbm_log_size
);
3110 /*******************************************************************************
3111 * Function: check_mpb_migr_compatibility
3112 * Description: Function checks for unsupported migration features:
3113 * - migration optimization area (pba_of_lba0)
3114 * - descending reshape (ascending_migr)
3116 * super : imsm metadata information
3118 * 0 : migration is compatible
3119 * -1 : migration is not compatible
3120 ******************************************************************************/
3121 int check_mpb_migr_compatibility(struct intel_super
*super
)
3123 struct imsm_map
*map0
, *map1
;
3124 struct migr_record
*migr_rec
= super
->migr_rec
;
3127 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
3128 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
3131 dev_iter
->vol
.migr_state
== 1 &&
3132 dev_iter
->vol
.migr_type
== MIGR_GEN_MIGR
) {
3133 /* This device is migrating */
3134 map0
= get_imsm_map(dev_iter
, 0);
3135 map1
= get_imsm_map(dev_iter
, 1);
3136 if (map0
->pba_of_lba0
!= map1
->pba_of_lba0
)
3137 /* migration optimization area was used */
3139 if (migr_rec
->ascending_migr
== 0
3140 && migr_rec
->dest_depth_per_unit
> 0)
3141 /* descending reshape not supported yet */
3148 static void __free_imsm(struct intel_super
*super
, int free_disks
);
3150 /* load_imsm_mpb - read matrix metadata
3151 * allocates super->mpb to be freed by free_imsm
3153 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
3155 unsigned long long dsize
;
3156 unsigned long long sectors
;
3158 struct imsm_super
*anchor
;
3161 get_dev_size(fd
, NULL
, &dsize
);
3165 Name
": %s: device to small for imsm\n",
3170 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0) {
3172 fprintf(stderr
, Name
3173 ": Cannot seek to anchor block on %s: %s\n",
3174 devname
, strerror(errno
));
3178 if (posix_memalign((void**)&anchor
, 512, 512) != 0) {
3181 Name
": Failed to allocate imsm anchor buffer"
3182 " on %s\n", devname
);
3185 if (read(fd
, anchor
, 512) != 512) {
3188 Name
": Cannot read anchor block on %s: %s\n",
3189 devname
, strerror(errno
));
3194 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
3197 Name
": no IMSM anchor on %s\n", devname
);
3202 __free_imsm(super
, 0);
3203 /* reload capability and hba */
3205 /* capability and hba must be updated with new super allocation */
3206 find_intel_hba_capability(fd
, super
, devname
);
3207 super
->len
= ROUND_UP(anchor
->mpb_size
, 512);
3208 if (posix_memalign(&super
->buf
, 512, super
->len
) != 0) {
3211 Name
": unable to allocate %zu byte mpb buffer\n",
3216 memcpy(super
->buf
, anchor
, 512);
3218 sectors
= mpb_sectors(anchor
) - 1;
3221 if (posix_memalign(&super
->migr_rec_buf
, 512, 512) != 0) {
3222 fprintf(stderr
, Name
3223 ": %s could not allocate migr_rec buffer\n", __func__
);
3229 check_sum
= __gen_imsm_checksum(super
->anchor
);
3230 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
3233 Name
": IMSM checksum %x != %x on %s\n",
3235 __le32_to_cpu(super
->anchor
->check_sum
),
3243 /* read the extended mpb */
3244 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0) {
3247 Name
": Cannot seek to extended mpb on %s: %s\n",
3248 devname
, strerror(errno
));
3252 if ((unsigned)read(fd
, super
->buf
+ 512, super
->len
- 512) != super
->len
- 512) {
3255 Name
": Cannot read extended mpb on %s: %s\n",
3256 devname
, strerror(errno
));
3260 check_sum
= __gen_imsm_checksum(super
->anchor
);
3261 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
3264 Name
": IMSM checksum %x != %x on %s\n",
3265 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
3270 /* FIXME the BBM log is disk specific so we cannot use this global
3271 * buffer for all disks. Ok for now since we only look at the global
3272 * bbm_log_size parameter to gate assembly
3274 super
->bbm_log
= __get_imsm_bbm_log(super
->anchor
);
3279 static int read_imsm_migr_rec(int fd
, struct intel_super
*super
);
3282 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
3286 err
= load_imsm_mpb(fd
, super
, devname
);
3289 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
3292 err
= parse_raid_devices(super
);
3297 static void __free_imsm_disk(struct dl
*d
)
3309 static void free_imsm_disks(struct intel_super
*super
)
3313 while (super
->disks
) {
3315 super
->disks
= d
->next
;
3316 __free_imsm_disk(d
);
3318 while (super
->disk_mgmt_list
) {
3319 d
= super
->disk_mgmt_list
;
3320 super
->disk_mgmt_list
= d
->next
;
3321 __free_imsm_disk(d
);
3323 while (super
->missing
) {
3325 super
->missing
= d
->next
;
3326 __free_imsm_disk(d
);
3331 /* free all the pieces hanging off of a super pointer */
3332 static void __free_imsm(struct intel_super
*super
, int free_disks
)
3334 struct intel_hba
*elem
, *next
;
3340 /* unlink capability description */
3342 if (super
->migr_rec_buf
) {
3343 free(super
->migr_rec_buf
);
3344 super
->migr_rec_buf
= NULL
;
3347 free_imsm_disks(super
);
3348 free_devlist(super
);
3352 free((void *)elem
->path
);
3360 static void free_imsm(struct intel_super
*super
)
3362 __free_imsm(super
, 1);
3366 static void free_super_imsm(struct supertype
*st
)
3368 struct intel_super
*super
= st
->sb
;
3377 static struct intel_super
*alloc_super(void)
3379 struct intel_super
*super
= malloc(sizeof(*super
));
3382 memset(super
, 0, sizeof(*super
));
3383 super
->current_vol
= -1;
3384 super
->create_offset
= ~((__u32
) 0);
3390 * find and allocate hba and OROM/EFI based on valid fd of RAID component device
3392 static int find_intel_hba_capability(int fd
, struct intel_super
*super
, char *devname
)
3394 struct sys_dev
*hba_name
;
3397 if ((fd
< 0) || check_env("IMSM_NO_PLATFORM")) {
3402 hba_name
= find_disk_attached_hba(fd
, NULL
);
3406 Name
": %s is not attached to Intel(R) RAID controller.\n",
3410 rv
= attach_hba_to_super(super
, hba_name
);
3413 struct intel_hba
*hba
= super
->hba
;
3415 fprintf(stderr
, Name
": %s is attached to Intel(R) %s RAID "
3416 "controller (%s),\n"
3417 " but the container is assigned to Intel(R) "
3418 "%s RAID controller (",
3421 hba_name
->pci_id
? : "Err!",
3422 get_sys_dev_type(hba_name
->type
));
3425 fprintf(stderr
, "%s", hba
->pci_id
? : "Err!");
3427 fprintf(stderr
, ", ");
3431 fprintf(stderr
, ").\n"
3432 " Mixing devices attached to different controllers "
3433 "is not allowed.\n");
3435 free_sys_dev(&hba_name
);
3438 super
->orom
= find_imsm_capability(hba_name
->type
);
3439 free_sys_dev(&hba_name
);
3445 /* find_missing - helper routine for load_super_imsm_all that identifies
3446 * disks that have disappeared from the system. This routine relies on
3447 * the mpb being uptodate, which it is at load time.
3449 static int find_missing(struct intel_super
*super
)
3452 struct imsm_super
*mpb
= super
->anchor
;
3454 struct imsm_disk
*disk
;
3456 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3457 disk
= __get_imsm_disk(mpb
, i
);
3458 dl
= serial_to_dl(disk
->serial
, super
);
3462 dl
= malloc(sizeof(*dl
));
3468 dl
->devname
= strdup("missing");
3470 serialcpy(dl
->serial
, disk
->serial
);
3473 dl
->next
= super
->missing
;
3474 super
->missing
= dl
;
3481 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
3483 struct intel_disk
*idisk
= disk_list
;
3486 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
3488 idisk
= idisk
->next
;
3494 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
3495 struct intel_super
*super
,
3496 struct intel_disk
**disk_list
)
3498 struct imsm_disk
*d
= &super
->disks
->disk
;
3499 struct imsm_super
*mpb
= super
->anchor
;
3502 for (i
= 0; i
< tbl_size
; i
++) {
3503 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
3504 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
3506 if (tbl_mpb
->family_num
== mpb
->family_num
) {
3507 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
3508 dprintf("%s: mpb from %d:%d matches %d:%d\n",
3509 __func__
, super
->disks
->major
,
3510 super
->disks
->minor
,
3511 table
[i
]->disks
->major
,
3512 table
[i
]->disks
->minor
);
3516 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
3517 is_configured(d
) == is_configured(tbl_d
)) &&
3518 tbl_mpb
->generation_num
< mpb
->generation_num
) {
3519 /* current version of the mpb is a
3520 * better candidate than the one in
3521 * super_table, but copy over "cross
3522 * generational" status
3524 struct intel_disk
*idisk
;
3526 dprintf("%s: mpb from %d:%d replaces %d:%d\n",
3527 __func__
, super
->disks
->major
,
3528 super
->disks
->minor
,
3529 table
[i
]->disks
->major
,
3530 table
[i
]->disks
->minor
);
3532 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
3533 if (idisk
&& is_failed(&idisk
->disk
))
3534 tbl_d
->status
|= FAILED_DISK
;
3537 struct intel_disk
*idisk
;
3538 struct imsm_disk
*disk
;
3540 /* tbl_mpb is more up to date, but copy
3541 * over cross generational status before
3544 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
3545 if (disk
&& is_failed(disk
))
3546 d
->status
|= FAILED_DISK
;
3548 idisk
= disk_list_get(d
->serial
, *disk_list
);
3551 if (disk
&& is_configured(disk
))
3552 idisk
->disk
.status
|= CONFIGURED_DISK
;
3555 dprintf("%s: mpb from %d:%d prefer %d:%d\n",
3556 __func__
, super
->disks
->major
,
3557 super
->disks
->minor
,
3558 table
[i
]->disks
->major
,
3559 table
[i
]->disks
->minor
);
3567 table
[tbl_size
++] = super
;
3571 /* update/extend the merged list of imsm_disk records */
3572 for (j
= 0; j
< mpb
->num_disks
; j
++) {
3573 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
3574 struct intel_disk
*idisk
;
3576 idisk
= disk_list_get(disk
->serial
, *disk_list
);
3578 idisk
->disk
.status
|= disk
->status
;
3579 if (is_configured(&idisk
->disk
) ||
3580 is_failed(&idisk
->disk
))
3581 idisk
->disk
.status
&= ~(SPARE_DISK
);
3583 idisk
= calloc(1, sizeof(*idisk
));
3586 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
3587 idisk
->disk
= *disk
;
3588 idisk
->next
= *disk_list
;
3592 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
3599 static struct intel_super
*
3600 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
3603 struct imsm_super
*mpb
= super
->anchor
;
3607 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3608 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
3609 struct intel_disk
*idisk
;
3611 idisk
= disk_list_get(disk
->serial
, disk_list
);
3613 if (idisk
->owner
== owner
||
3614 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
3617 dprintf("%s: '%.16s' owner %d != %d\n",
3618 __func__
, disk
->serial
, idisk
->owner
,
3621 dprintf("%s: unknown disk %x [%d]: %.16s\n",
3622 __func__
, __le32_to_cpu(mpb
->family_num
), i
,
3628 if (ok_count
== mpb
->num_disks
)
3633 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
3635 struct intel_super
*s
;
3637 for (s
= super_list
; s
; s
= s
->next
) {
3638 if (family_num
!= s
->anchor
->family_num
)
3640 fprintf(stderr
, "Conflict, offlining family %#x on '%s'\n",
3641 __le32_to_cpu(family_num
), s
->disks
->devname
);
3645 static struct intel_super
*
3646 imsm_thunderdome(struct intel_super
**super_list
, int len
)
3648 struct intel_super
*super_table
[len
];
3649 struct intel_disk
*disk_list
= NULL
;
3650 struct intel_super
*champion
, *spare
;
3651 struct intel_super
*s
, **del
;
3656 memset(super_table
, 0, sizeof(super_table
));
3657 for (s
= *super_list
; s
; s
= s
->next
)
3658 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
3660 for (i
= 0; i
< tbl_size
; i
++) {
3661 struct imsm_disk
*d
;
3662 struct intel_disk
*idisk
;
3663 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
3666 d
= &s
->disks
->disk
;
3668 /* 'd' must appear in merged disk list for its
3669 * configuration to be valid
3671 idisk
= disk_list_get(d
->serial
, disk_list
);
3672 if (idisk
&& idisk
->owner
== i
)
3673 s
= validate_members(s
, disk_list
, i
);
3678 dprintf("%s: marking family: %#x from %d:%d offline\n",
3679 __func__
, mpb
->family_num
,
3680 super_table
[i
]->disks
->major
,
3681 super_table
[i
]->disks
->minor
);
3685 /* This is where the mdadm implementation differs from the Windows
3686 * driver which has no strict concept of a container. We can only
3687 * assemble one family from a container, so when returning a prodigal
3688 * array member to this system the code will not be able to disambiguate
3689 * the container contents that should be assembled ("foreign" versus
3690 * "local"). It requires user intervention to set the orig_family_num
3691 * to a new value to establish a new container. The Windows driver in
3692 * this situation fixes up the volume name in place and manages the
3693 * foreign array as an independent entity.
3698 for (i
= 0; i
< tbl_size
; i
++) {
3699 struct intel_super
*tbl_ent
= super_table
[i
];
3705 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
3710 if (s
&& !is_spare
) {
3711 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
3713 } else if (!s
&& !is_spare
)
3726 fprintf(stderr
, "Chose family %#x on '%s', "
3727 "assemble conflicts to new container with '--update=uuid'\n",
3728 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
3730 /* collect all dl's onto 'champion', and update them to
3731 * champion's version of the status
3733 for (s
= *super_list
; s
; s
= s
->next
) {
3734 struct imsm_super
*mpb
= champion
->anchor
;
3735 struct dl
*dl
= s
->disks
;
3740 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3741 struct imsm_disk
*disk
;
3743 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
3746 /* only set index on disks that are a member of
3747 * a populated contianer, i.e. one with
3750 if (is_failed(&dl
->disk
))
3752 else if (is_spare(&dl
->disk
))
3758 if (i
>= mpb
->num_disks
) {
3759 struct intel_disk
*idisk
;
3761 idisk
= disk_list_get(dl
->serial
, disk_list
);
3762 if (idisk
&& is_spare(&idisk
->disk
) &&
3763 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
3771 dl
->next
= champion
->disks
;
3772 champion
->disks
= dl
;
3776 /* delete 'champion' from super_list */
3777 for (del
= super_list
; *del
; ) {
3778 if (*del
== champion
) {
3779 *del
= (*del
)->next
;
3782 del
= &(*del
)->next
;
3784 champion
->next
= NULL
;
3788 struct intel_disk
*idisk
= disk_list
;
3790 disk_list
= disk_list
->next
;
3797 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
3801 struct intel_super
*super_list
= NULL
;
3802 struct intel_super
*super
= NULL
;
3803 int devnum
= fd2devnum(fd
);
3809 /* check if 'fd' an opened container */
3810 sra
= sysfs_read(fd
, 0, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
3814 if (sra
->array
.major_version
!= -1 ||
3815 sra
->array
.minor_version
!= -2 ||
3816 strcmp(sra
->text_version
, "imsm") != 0) {
3821 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
3822 struct intel_super
*s
= alloc_super();
3830 s
->next
= super_list
;
3834 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
3835 dfd
= dev_open(nm
, O_RDWR
);
3839 rv
= find_intel_hba_capability(dfd
, s
, devname
);
3840 /* no orom/efi or non-intel hba of the disk */
3844 err
= load_and_parse_mpb(dfd
, s
, NULL
, 1);
3846 /* retry the load if we might have raced against mdmon */
3847 if (err
== 3 && mdmon_running(devnum
))
3848 for (retry
= 0; retry
< 3; retry
++) {
3850 err
= load_and_parse_mpb(dfd
, s
, NULL
, 1);
3858 /* all mpbs enter, maybe one leaves */
3859 super
= imsm_thunderdome(&super_list
, i
);
3865 if (find_missing(super
) != 0) {
3871 /* load migration record */
3872 err
= load_imsm_migr_rec(super
, NULL
);
3878 /* Check migration compatibility */
3879 if (check_mpb_migr_compatibility(super
) != 0) {
3880 fprintf(stderr
, Name
": Unsupported migration detected");
3882 fprintf(stderr
, " on %s\n", devname
);
3884 fprintf(stderr
, " (IMSM).\n");
3893 while (super_list
) {
3894 struct intel_super
*s
= super_list
;
3896 super_list
= super_list
->next
;
3905 st
->container_dev
= devnum
;
3906 if (err
== 0 && st
->ss
== NULL
) {
3907 st
->ss
= &super_imsm
;
3908 st
->minor_version
= 0;
3909 st
->max_devs
= IMSM_MAX_DEVICES
;
3914 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
3916 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
);
3920 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
3922 struct intel_super
*super
;
3925 if (test_partition(fd
))
3926 /* IMSM not allowed on partitions */
3929 free_super_imsm(st
);
3931 super
= alloc_super();
3934 Name
": malloc of %zu failed.\n",
3938 /* Load hba and capabilities if they exist.
3939 * But do not preclude loading metadata in case capabilities or hba are
3940 * non-compliant and ignore_hw_compat is set.
3942 rv
= find_intel_hba_capability(fd
, super
, devname
);
3943 /* no orom/efi or non-intel hba of the disk */
3944 if ((rv
!= 0) && (st
->ignore_hw_compat
== 0)) {
3947 Name
": No OROM/EFI properties for %s\n", devname
);
3951 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
3956 Name
": Failed to load all information "
3957 "sections on %s\n", devname
);
3963 if (st
->ss
== NULL
) {
3964 st
->ss
= &super_imsm
;
3965 st
->minor_version
= 0;
3966 st
->max_devs
= IMSM_MAX_DEVICES
;
3969 /* load migration record */
3970 if (load_imsm_migr_rec(super
, NULL
) == 0) {
3971 /* Check for unsupported migration features */
3972 if (check_mpb_migr_compatibility(super
) != 0) {
3974 Name
": Unsupported migration detected");
3976 fprintf(stderr
, " on %s\n", devname
);
3978 fprintf(stderr
, " (IMSM).\n");
3986 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
3988 if (info
->level
== 1)
3990 return info
->chunk_size
>> 9;
3993 static __u32
info_to_num_data_stripes(mdu_array_info_t
*info
, int num_domains
)
3997 num_stripes
= (info
->size
* 2) / info_to_blocks_per_strip(info
);
3998 num_stripes
/= num_domains
;
4003 static __u32
info_to_blocks_per_member(mdu_array_info_t
*info
)
4005 if (info
->level
== 1)
4006 return info
->size
* 2;
4008 return (info
->size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
4011 static void imsm_update_version_info(struct intel_super
*super
)
4013 /* update the version and attributes */
4014 struct imsm_super
*mpb
= super
->anchor
;
4016 struct imsm_dev
*dev
;
4017 struct imsm_map
*map
;
4020 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4021 dev
= get_imsm_dev(super
, i
);
4022 map
= get_imsm_map(dev
, 0);
4023 if (__le32_to_cpu(dev
->size_high
) > 0)
4024 mpb
->attributes
|= MPB_ATTRIB_2TB
;
4026 /* FIXME detect when an array spans a port multiplier */
4028 mpb
->attributes
|= MPB_ATTRIB_PM
;
4031 if (mpb
->num_raid_devs
> 1 ||
4032 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
4033 version
= MPB_VERSION_ATTRIBS
;
4034 switch (get_imsm_raid_level(map
)) {
4035 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
4036 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
4037 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
4038 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
4041 if (map
->num_members
>= 5)
4042 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
4043 else if (dev
->status
== DEV_CLONE_N_GO
)
4044 version
= MPB_VERSION_CNG
;
4045 else if (get_imsm_raid_level(map
) == 5)
4046 version
= MPB_VERSION_RAID5
;
4047 else if (map
->num_members
>= 3)
4048 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
4049 else if (get_imsm_raid_level(map
) == 1)
4050 version
= MPB_VERSION_RAID1
;
4052 version
= MPB_VERSION_RAID0
;
4054 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
4058 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
4060 struct imsm_super
*mpb
= super
->anchor
;
4061 char *reason
= NULL
;
4064 if (strlen(name
) > MAX_RAID_SERIAL_LEN
)
4065 reason
= "must be 16 characters or less";
4067 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4068 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
4070 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
4071 reason
= "already exists";
4076 if (reason
&& !quiet
)
4077 fprintf(stderr
, Name
": imsm volume name %s\n", reason
);
4082 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
4083 unsigned long long size
, char *name
,
4084 char *homehost
, int *uuid
)
4086 /* We are creating a volume inside a pre-existing container.
4087 * so st->sb is already set.
4089 struct intel_super
*super
= st
->sb
;
4090 struct imsm_super
*mpb
= super
->anchor
;
4091 struct intel_dev
*dv
;
4092 struct imsm_dev
*dev
;
4093 struct imsm_vol
*vol
;
4094 struct imsm_map
*map
;
4095 int idx
= mpb
->num_raid_devs
;
4097 unsigned long long array_blocks
;
4098 size_t size_old
, size_new
;
4099 __u32 num_data_stripes
;
4101 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
4102 fprintf(stderr
, Name
": This imsm-container already has the "
4103 "maximum of %d volumes\n", super
->orom
->vpa
);
4107 /* ensure the mpb is large enough for the new data */
4108 size_old
= __le32_to_cpu(mpb
->mpb_size
);
4109 size_new
= disks_to_mpb_size(info
->nr_disks
);
4110 if (size_new
> size_old
) {
4112 size_t size_round
= ROUND_UP(size_new
, 512);
4114 if (posix_memalign(&mpb_new
, 512, size_round
) != 0) {
4115 fprintf(stderr
, Name
": could not allocate new mpb\n");
4118 if (posix_memalign(&super
->migr_rec_buf
, 512, 512) != 0) {
4119 fprintf(stderr
, Name
4120 ": %s could not allocate migr_rec buffer\n",
4126 memcpy(mpb_new
, mpb
, size_old
);
4129 super
->anchor
= mpb_new
;
4130 mpb
->mpb_size
= __cpu_to_le32(size_new
);
4131 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
4133 super
->current_vol
= idx
;
4135 /* handle 'failed_disks' by either:
4136 * a) create dummy disk entries in the table if this the first
4137 * volume in the array. We add them here as this is the only
4138 * opportunity to add them. add_to_super_imsm_volume()
4139 * handles the non-failed disks and continues incrementing
4141 * b) validate that 'failed_disks' matches the current number
4142 * of missing disks if the container is populated
4144 if (super
->current_vol
== 0) {
4146 for (i
= 0; i
< info
->failed_disks
; i
++) {
4147 struct imsm_disk
*disk
;
4150 disk
= __get_imsm_disk(mpb
, i
);
4151 disk
->status
= CONFIGURED_DISK
| FAILED_DISK
;
4152 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
4153 snprintf((char *) disk
->serial
, MAX_RAID_SERIAL_LEN
,
4156 find_missing(super
);
4161 for (d
= super
->missing
; d
; d
= d
->next
)
4163 if (info
->failed_disks
> missing
) {
4164 fprintf(stderr
, Name
": unable to add 'missing' disk to container\n");
4169 if (!check_name(super
, name
, 0))
4171 dv
= malloc(sizeof(*dv
));
4173 fprintf(stderr
, Name
": failed to allocate device list entry\n");
4176 dev
= calloc(1, sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
4179 fprintf(stderr
, Name
": could not allocate raid device\n");
4183 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
4184 if (info
->level
== 1)
4185 array_blocks
= info_to_blocks_per_member(info
);
4187 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
4188 info
->layout
, info
->chunk_size
,
4190 /* round array size down to closest MB */
4191 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
4193 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
4194 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
4195 dev
->status
= (DEV_READ_COALESCING
| DEV_WRITE_COALESCING
);
4197 vol
->migr_state
= 0;
4198 set_migr_type(dev
, MIGR_INIT
);
4199 vol
->dirty
= !info
->state
;
4200 vol
->curr_migr_unit
= 0;
4201 map
= get_imsm_map(dev
, 0);
4202 map
->pba_of_lba0
= __cpu_to_le32(super
->create_offset
);
4203 map
->blocks_per_member
= __cpu_to_le32(info_to_blocks_per_member(info
));
4204 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
4205 map
->failed_disk_num
= ~0;
4206 map
->map_state
= info
->failed_disks
? IMSM_T_STATE_DEGRADED
: IMSM_T_STATE_NORMAL
;
4209 if (info
->level
== 1 && info
->raid_disks
> 2) {
4212 fprintf(stderr
, Name
": imsm does not support more than 2 disks"
4213 "in a raid1 volume\n");
4217 map
->raid_level
= info
->level
;
4218 if (info
->level
== 10) {
4219 map
->raid_level
= 1;
4220 map
->num_domains
= info
->raid_disks
/ 2;
4221 } else if (info
->level
== 1)
4222 map
->num_domains
= info
->raid_disks
;
4224 map
->num_domains
= 1;
4226 num_data_stripes
= info_to_num_data_stripes(info
, map
->num_domains
);
4227 map
->num_data_stripes
= __cpu_to_le32(num_data_stripes
);
4229 map
->num_members
= info
->raid_disks
;
4230 for (i
= 0; i
< map
->num_members
; i
++) {
4231 /* initialized in add_to_super */
4232 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
4234 mpb
->num_raid_devs
++;
4237 dv
->index
= super
->current_vol
;
4238 dv
->next
= super
->devlist
;
4239 super
->devlist
= dv
;
4241 imsm_update_version_info(super
);
4246 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
4247 unsigned long long size
, char *name
,
4248 char *homehost
, int *uuid
)
4250 /* This is primarily called by Create when creating a new array.
4251 * We will then get add_to_super called for each component, and then
4252 * write_init_super called to write it out to each device.
4253 * For IMSM, Create can create on fresh devices or on a pre-existing
4255 * To create on a pre-existing array a different method will be called.
4256 * This one is just for fresh drives.
4258 struct intel_super
*super
;
4259 struct imsm_super
*mpb
;
4264 return init_super_imsm_volume(st
, info
, size
, name
, homehost
, uuid
);
4267 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
4271 super
= alloc_super();
4272 if (super
&& posix_memalign(&super
->buf
, 512, mpb_size
) != 0) {
4277 fprintf(stderr
, Name
4278 ": %s could not allocate superblock\n", __func__
);
4281 if (posix_memalign(&super
->migr_rec_buf
, 512, 512) != 0) {
4282 fprintf(stderr
, Name
4283 ": %s could not allocate migr_rec buffer\n", __func__
);
4288 memset(super
->buf
, 0, mpb_size
);
4290 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
4294 /* zeroing superblock */
4298 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
4300 version
= (char *) mpb
->sig
;
4301 strcpy(version
, MPB_SIGNATURE
);
4302 version
+= strlen(MPB_SIGNATURE
);
4303 strcpy(version
, MPB_VERSION_RAID0
);
4309 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
4310 int fd
, char *devname
)
4312 struct intel_super
*super
= st
->sb
;
4313 struct imsm_super
*mpb
= super
->anchor
;
4314 struct imsm_disk
*_disk
;
4315 struct imsm_dev
*dev
;
4316 struct imsm_map
*map
;
4320 dev
= get_imsm_dev(super
, super
->current_vol
);
4321 map
= get_imsm_map(dev
, 0);
4323 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
4324 fprintf(stderr
, Name
": %s: Cannot add spare devices to IMSM volume\n",
4330 /* we're doing autolayout so grab the pre-marked (in
4331 * validate_geometry) raid_disk
4333 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4334 if (dl
->raiddisk
== dk
->raid_disk
)
4337 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4338 if (dl
->major
== dk
->major
&&
4339 dl
->minor
== dk
->minor
)
4344 fprintf(stderr
, Name
": %s is not a member of the same container\n", devname
);
4348 /* add a pristine spare to the metadata */
4349 if (dl
->index
< 0) {
4350 dl
->index
= super
->anchor
->num_disks
;
4351 super
->anchor
->num_disks
++;
4353 /* Check the device has not already been added */
4354 slot
= get_imsm_disk_slot(map
, dl
->index
);
4356 (get_imsm_ord_tbl_ent(dev
, slot
, -1) & IMSM_ORD_REBUILD
) == 0) {
4357 fprintf(stderr
, Name
": %s has been included in this array twice\n",
4361 set_imsm_ord_tbl_ent(map
, dk
->raid_disk
, dl
->index
);
4362 dl
->disk
.status
= CONFIGURED_DISK
;
4364 /* update size of 'missing' disks to be at least as large as the
4365 * largest acitve member (we only have dummy missing disks when
4366 * creating the first volume)
4368 if (super
->current_vol
== 0) {
4369 for (df
= super
->missing
; df
; df
= df
->next
) {
4370 if (dl
->disk
.total_blocks
> df
->disk
.total_blocks
)
4371 df
->disk
.total_blocks
= dl
->disk
.total_blocks
;
4372 _disk
= __get_imsm_disk(mpb
, df
->index
);
4377 /* refresh unset/failed slots to point to valid 'missing' entries */
4378 for (df
= super
->missing
; df
; df
= df
->next
)
4379 for (slot
= 0; slot
< mpb
->num_disks
; slot
++) {
4380 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, -1);
4382 if ((ord
& IMSM_ORD_REBUILD
) == 0)
4384 set_imsm_ord_tbl_ent(map
, slot
, df
->index
| IMSM_ORD_REBUILD
);
4385 dprintf("set slot:%d to missing disk:%d\n", slot
, df
->index
);
4389 /* if we are creating the first raid device update the family number */
4390 if (super
->current_vol
== 0) {
4392 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
4394 _disk
= __get_imsm_disk(mpb
, dl
->index
);
4395 if (!_dev
|| !_disk
) {
4396 fprintf(stderr
, Name
": BUG mpb setup error\n");
4402 sum
+= __gen_imsm_checksum(mpb
);
4403 mpb
->family_num
= __cpu_to_le32(sum
);
4404 mpb
->orig_family_num
= mpb
->family_num
;
4406 super
->current_disk
= dl
;
4411 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
4412 int fd
, char *devname
)
4414 struct intel_super
*super
= st
->sb
;
4416 unsigned long long size
;
4421 /* If we are on an RAID enabled platform check that the disk is
4422 * attached to the raid controller.
4423 * We do not need to test disks attachment for container based additions,
4424 * they shall be already tested when container was created/assembled.
4426 rv
= find_intel_hba_capability(fd
, super
, devname
);
4427 /* no orom/efi or non-intel hba of the disk */
4429 dprintf("capability: %p fd: %d ret: %d\n",
4430 super
->orom
, fd
, rv
);
4434 if (super
->current_vol
>= 0)
4435 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
4438 dd
= malloc(sizeof(*dd
));
4441 Name
": malloc failed %s:%d.\n", __func__
, __LINE__
);
4444 memset(dd
, 0, sizeof(*dd
));
4445 dd
->major
= major(stb
.st_rdev
);
4446 dd
->minor
= minor(stb
.st_rdev
);
4448 dd
->devname
= devname
? strdup(devname
) : NULL
;
4451 dd
->action
= DISK_ADD
;
4452 rv
= imsm_read_serial(fd
, devname
, dd
->serial
);
4455 Name
": failed to retrieve scsi serial, aborting\n");
4460 get_dev_size(fd
, NULL
, &size
);
4462 serialcpy(dd
->disk
.serial
, dd
->serial
);
4463 dd
->disk
.total_blocks
= __cpu_to_le32(size
);
4464 dd
->disk
.status
= SPARE_DISK
;
4465 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
4466 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
4468 dd
->disk
.scsi_id
= __cpu_to_le32(0);
4470 if (st
->update_tail
) {
4471 dd
->next
= super
->disk_mgmt_list
;
4472 super
->disk_mgmt_list
= dd
;
4474 dd
->next
= super
->disks
;
4476 super
->updates_pending
++;
4483 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
4485 struct intel_super
*super
= st
->sb
;
4488 /* remove from super works only in mdmon - for communication
4489 * manager - monitor. Check if communication memory buffer
4492 if (!st
->update_tail
) {
4494 Name
": %s shall be used in mdmon context only"
4495 "(line %d).\n", __func__
, __LINE__
);
4498 dd
= malloc(sizeof(*dd
));
4501 Name
": malloc failed %s:%d.\n", __func__
, __LINE__
);
4504 memset(dd
, 0, sizeof(*dd
));
4505 dd
->major
= dk
->major
;
4506 dd
->minor
= dk
->minor
;
4509 dd
->disk
.status
= SPARE_DISK
;
4510 dd
->action
= DISK_REMOVE
;
4512 dd
->next
= super
->disk_mgmt_list
;
4513 super
->disk_mgmt_list
= dd
;
4519 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
4523 struct imsm_super anchor
;
4524 } spare_record
__attribute__ ((aligned(512)));
4526 /* spare records have their own family number and do not have any defined raid
4529 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
4531 struct imsm_super
*mpb
= super
->anchor
;
4532 struct imsm_super
*spare
= &spare_record
.anchor
;
4536 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
)),
4537 spare
->generation_num
= __cpu_to_le32(1UL),
4538 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
4539 spare
->num_disks
= 1,
4540 spare
->num_raid_devs
= 0,
4541 spare
->cache_size
= mpb
->cache_size
,
4542 spare
->pwr_cycle_count
= __cpu_to_le32(1),
4544 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
4545 MPB_SIGNATURE MPB_VERSION_RAID0
);
4547 for (d
= super
->disks
; d
; d
= d
->next
) {
4551 spare
->disk
[0] = d
->disk
;
4552 sum
= __gen_imsm_checksum(spare
);
4553 spare
->family_num
= __cpu_to_le32(sum
);
4554 spare
->orig_family_num
= 0;
4555 sum
= __gen_imsm_checksum(spare
);
4556 spare
->check_sum
= __cpu_to_le32(sum
);
4558 if (store_imsm_mpb(d
->fd
, spare
)) {
4559 fprintf(stderr
, "%s: failed for device %d:%d %s\n",
4560 __func__
, d
->major
, d
->minor
, strerror(errno
));
4572 static int write_super_imsm(struct supertype
*st
, int doclose
)
4574 struct intel_super
*super
= st
->sb
;
4575 struct imsm_super
*mpb
= super
->anchor
;
4581 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
4583 int clear_migration_record
= 1;
4585 /* 'generation' is incremented everytime the metadata is written */
4586 generation
= __le32_to_cpu(mpb
->generation_num
);
4588 mpb
->generation_num
= __cpu_to_le32(generation
);
4590 /* fix up cases where previous mdadm releases failed to set
4593 if (mpb
->orig_family_num
== 0)
4594 mpb
->orig_family_num
= mpb
->family_num
;
4596 for (d
= super
->disks
; d
; d
= d
->next
) {
4600 mpb
->disk
[d
->index
] = d
->disk
;
4604 for (d
= super
->missing
; d
; d
= d
->next
) {
4605 mpb
->disk
[d
->index
] = d
->disk
;
4608 mpb
->num_disks
= num_disks
;
4609 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
4611 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4612 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
4613 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
4615 imsm_copy_dev(dev
, dev2
);
4616 mpb_size
+= sizeof_imsm_dev(dev
, 0);
4618 if (is_gen_migration(dev2
))
4619 clear_migration_record
= 0;
4621 mpb_size
+= __le32_to_cpu(mpb
->bbm_log_size
);
4622 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
4624 /* recalculate checksum */
4625 sum
= __gen_imsm_checksum(mpb
);
4626 mpb
->check_sum
= __cpu_to_le32(sum
);
4628 if (clear_migration_record
)
4629 memset(super
->migr_rec_buf
, 0, 512);
4631 /* write the mpb for disks that compose raid devices */
4632 for (d
= super
->disks
; d
; d
= d
->next
) {
4633 if (d
->index
< 0 || is_failed(&d
->disk
))
4635 if (store_imsm_mpb(d
->fd
, mpb
))
4636 fprintf(stderr
, "%s: failed for device %d:%d %s\n",
4637 __func__
, d
->major
, d
->minor
, strerror(errno
));
4638 if (clear_migration_record
) {
4639 unsigned long long dsize
;
4641 get_dev_size(d
->fd
, NULL
, &dsize
);
4642 if (lseek64(d
->fd
, dsize
- 512, SEEK_SET
) >= 0) {
4643 if (write(d
->fd
, super
->migr_rec_buf
, 512) != 512)
4644 perror("Write migr_rec failed");
4654 return write_super_imsm_spares(super
, doclose
);
4660 static int create_array(struct supertype
*st
, int dev_idx
)
4663 struct imsm_update_create_array
*u
;
4664 struct intel_super
*super
= st
->sb
;
4665 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
4666 struct imsm_map
*map
= get_imsm_map(dev
, 0);
4667 struct disk_info
*inf
;
4668 struct imsm_disk
*disk
;
4671 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
4672 sizeof(*inf
) * map
->num_members
;
4675 fprintf(stderr
, "%s: failed to allocate update buffer\n",
4680 u
->type
= update_create_array
;
4681 u
->dev_idx
= dev_idx
;
4682 imsm_copy_dev(&u
->dev
, dev
);
4683 inf
= get_disk_info(u
);
4684 for (i
= 0; i
< map
->num_members
; i
++) {
4685 int idx
= get_imsm_disk_idx(dev
, i
, -1);
4687 disk
= get_imsm_disk(super
, idx
);
4688 serialcpy(inf
[i
].serial
, disk
->serial
);
4690 append_metadata_update(st
, u
, len
);
4695 static int mgmt_disk(struct supertype
*st
)
4697 struct intel_super
*super
= st
->sb
;
4699 struct imsm_update_add_remove_disk
*u
;
4701 if (!super
->disk_mgmt_list
)
4707 fprintf(stderr
, "%s: failed to allocate update buffer\n",
4712 u
->type
= update_add_remove_disk
;
4713 append_metadata_update(st
, u
, len
);
4718 static int write_init_super_imsm(struct supertype
*st
)
4720 struct intel_super
*super
= st
->sb
;
4721 int current_vol
= super
->current_vol
;
4723 /* we are done with current_vol reset it to point st at the container */
4724 super
->current_vol
= -1;
4726 if (st
->update_tail
) {
4727 /* queue the recently created array / added disk
4728 * as a metadata update */
4731 /* determine if we are creating a volume or adding a disk */
4732 if (current_vol
< 0) {
4733 /* in the mgmt (add/remove) disk case we are running
4734 * in mdmon context, so don't close fd's
4736 return mgmt_disk(st
);
4738 rv
= create_array(st
, current_vol
);
4743 for (d
= super
->disks
; d
; d
= d
->next
)
4744 Kill(d
->devname
, NULL
, 0, 1, 1);
4745 return write_super_imsm(st
, 1);
4750 static int store_super_imsm(struct supertype
*st
, int fd
)
4752 struct intel_super
*super
= st
->sb
;
4753 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
4759 return store_imsm_mpb(fd
, mpb
);
4765 static int imsm_bbm_log_size(struct imsm_super
*mpb
)
4767 return __le32_to_cpu(mpb
->bbm_log_size
);
4771 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
4772 int layout
, int raiddisks
, int chunk
,
4773 unsigned long long size
, char *dev
,
4774 unsigned long long *freesize
,
4778 unsigned long long ldsize
;
4779 struct intel_super
*super
=NULL
;
4782 if (level
!= LEVEL_CONTAINER
)
4787 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
4790 fprintf(stderr
, Name
": imsm: Cannot open %s: %s\n",
4791 dev
, strerror(errno
));
4794 if (!get_dev_size(fd
, dev
, &ldsize
)) {
4799 /* capabilities retrieve could be possible
4800 * note that there is no fd for the disks in array.
4802 super
= alloc_super();
4805 Name
": malloc of %zu failed.\n",
4811 rv
= find_intel_hba_capability(fd
, super
, verbose
? dev
: NULL
);
4815 fd2devname(fd
, str
);
4816 dprintf("validate_geometry_imsm_container: fd: %d %s orom: %p rv: %d raiddisk: %d\n",
4817 fd
, str
, super
->orom
, rv
, raiddisks
);
4819 /* no orom/efi or non-intel hba of the disk */
4825 if (super
->orom
&& raiddisks
> super
->orom
->tds
) {
4827 fprintf(stderr
, Name
": %d exceeds maximum number of"
4828 " platform supported disks: %d\n",
4829 raiddisks
, super
->orom
->tds
);
4835 *freesize
= avail_size_imsm(st
, ldsize
>> 9);
4841 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
4843 const unsigned long long base_start
= e
[*idx
].start
;
4844 unsigned long long end
= base_start
+ e
[*idx
].size
;
4847 if (base_start
== end
)
4851 for (i
= *idx
; i
< num_extents
; i
++) {
4852 /* extend overlapping extents */
4853 if (e
[i
].start
>= base_start
&&
4854 e
[i
].start
<= end
) {
4857 if (e
[i
].start
+ e
[i
].size
> end
)
4858 end
= e
[i
].start
+ e
[i
].size
;
4859 } else if (e
[i
].start
> end
) {
4865 return end
- base_start
;
4868 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
4870 /* build a composite disk with all known extents and generate a new
4871 * 'maxsize' given the "all disks in an array must share a common start
4872 * offset" constraint
4874 struct extent
*e
= calloc(sum_extents
, sizeof(*e
));
4878 unsigned long long pos
;
4879 unsigned long long start
= 0;
4880 unsigned long long maxsize
;
4881 unsigned long reserve
;
4886 /* coalesce and sort all extents. also, check to see if we need to
4887 * reserve space between member arrays
4890 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
4893 for (i
= 0; i
< dl
->extent_cnt
; i
++)
4896 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
4901 while (i
< sum_extents
) {
4902 e
[j
].start
= e
[i
].start
;
4903 e
[j
].size
= find_size(e
, &i
, sum_extents
);
4905 if (e
[j
-1].size
== 0)
4914 unsigned long long esize
;
4916 esize
= e
[i
].start
- pos
;
4917 if (esize
>= maxsize
) {
4922 pos
= e
[i
].start
+ e
[i
].size
;
4924 } while (e
[i
-1].size
);
4930 /* FIXME assumes volume at offset 0 is the first volume in a
4933 if (start_extent
> 0)
4934 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
4938 if (maxsize
< reserve
)
4941 super
->create_offset
= ~((__u32
) 0);
4942 if (start
+ reserve
> super
->create_offset
)
4943 return 0; /* start overflows create_offset */
4944 super
->create_offset
= start
+ reserve
;
4946 return maxsize
- reserve
;
4949 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
4951 if (level
< 0 || level
== 6 || level
== 4)
4954 /* if we have an orom prevent invalid raid levels */
4957 case 0: return imsm_orom_has_raid0(orom
);
4960 return imsm_orom_has_raid1e(orom
);
4961 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
4962 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
4963 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
4966 return 1; /* not on an Intel RAID platform so anything goes */
4971 static int imsm_default_chunk(const struct imsm_orom
*orom
)
4973 /* up to 512 if the plaform supports it, otherwise the platform max.
4974 * 128 if no platform detected
4976 int fs
= max(7, orom
? fls(orom
->sss
) : 0);
4978 return min(512, (1 << fs
));
4981 #define pr_vrb(fmt, arg...) (void) (verbose && fprintf(stderr, Name fmt, ##arg))
4983 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
4984 int raiddisks
, int *chunk
, int verbose
)
4986 /* check/set platform and metadata limits/defaults */
4987 if (super
->orom
&& raiddisks
> super
->orom
->dpa
) {
4988 pr_vrb(": platform supports a maximum of %d disks per array\n",
4993 /* capabilities of OROM tested - copied from validate_geometry_imsm_volume */
4994 if (!is_raid_level_supported(super
->orom
, level
, raiddisks
)) {
4995 pr_vrb(": platform does not support raid%d with %d disk%s\n",
4996 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
5000 if (chunk
&& (*chunk
== 0 || *chunk
== UnSet
))
5001 *chunk
= imsm_default_chunk(super
->orom
);
5003 if (super
->orom
&& chunk
&& !imsm_orom_has_chunk(super
->orom
, *chunk
)) {
5004 pr_vrb(": platform does not support a chunk size of: "
5009 if (layout
!= imsm_level_to_layout(level
)) {
5011 pr_vrb(": imsm raid 5 only supports the left-asymmetric layout\n");
5012 else if (level
== 10)
5013 pr_vrb(": imsm raid 10 only supports the n2 layout\n");
5015 pr_vrb(": imsm unknown layout %#x for this raid level %d\n",
5022 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
5023 * FIX ME add ahci details
5025 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
5026 int layout
, int raiddisks
, int *chunk
,
5027 unsigned long long size
, char *dev
,
5028 unsigned long long *freesize
,
5032 struct intel_super
*super
= st
->sb
;
5033 struct imsm_super
*mpb
= super
->anchor
;
5035 unsigned long long pos
= 0;
5036 unsigned long long maxsize
;
5040 /* We must have the container info already read in. */
5044 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, verbose
)) {
5045 fprintf(stderr
, Name
": RAID gemetry validation failed. "
5046 "Cannot proceed with the action(s).\n");
5050 /* General test: make sure there is space for
5051 * 'raiddisks' device extents of size 'size' at a given
5054 unsigned long long minsize
= size
;
5055 unsigned long long start_offset
= MaxSector
;
5058 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
5059 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5064 e
= get_extents(super
, dl
);
5067 unsigned long long esize
;
5068 esize
= e
[i
].start
- pos
;
5069 if (esize
>= minsize
)
5071 if (found
&& start_offset
== MaxSector
) {
5074 } else if (found
&& pos
!= start_offset
) {
5078 pos
= e
[i
].start
+ e
[i
].size
;
5080 } while (e
[i
-1].size
);
5085 if (dcnt
< raiddisks
) {
5087 fprintf(stderr
, Name
": imsm: Not enough "
5088 "devices with space for this array "
5096 /* This device must be a member of the set */
5097 if (stat(dev
, &stb
) < 0)
5099 if ((S_IFMT
& stb
.st_mode
) != S_IFBLK
)
5101 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5102 if (dl
->major
== (int)major(stb
.st_rdev
) &&
5103 dl
->minor
== (int)minor(stb
.st_rdev
))
5108 fprintf(stderr
, Name
": %s is not in the "
5109 "same imsm set\n", dev
);
5111 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
5112 /* If a volume is present then the current creation attempt
5113 * cannot incorporate new spares because the orom may not
5114 * understand this configuration (all member disks must be
5115 * members of each array in the container).
5117 fprintf(stderr
, Name
": %s is a spare and a volume"
5118 " is already defined for this container\n", dev
);
5119 fprintf(stderr
, Name
": The option-rom requires all member"
5120 " disks to be a member of all volumes\n");
5124 /* retrieve the largest free space block */
5125 e
= get_extents(super
, dl
);
5130 unsigned long long esize
;
5132 esize
= e
[i
].start
- pos
;
5133 if (esize
>= maxsize
)
5135 pos
= e
[i
].start
+ e
[i
].size
;
5137 } while (e
[i
-1].size
);
5142 fprintf(stderr
, Name
": unable to determine free space for: %s\n",
5146 if (maxsize
< size
) {
5148 fprintf(stderr
, Name
": %s not enough space (%llu < %llu)\n",
5149 dev
, maxsize
, size
);
5153 /* count total number of extents for merge */
5155 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5157 i
+= dl
->extent_cnt
;
5159 maxsize
= merge_extents(super
, i
);
5160 if (maxsize
< size
|| maxsize
== 0) {
5162 fprintf(stderr
, Name
": not enough space after merge (%llu < %llu)\n",
5167 *freesize
= maxsize
;
5172 static int reserve_space(struct supertype
*st
, int raiddisks
,
5173 unsigned long long size
, int chunk
,
5174 unsigned long long *freesize
)
5176 struct intel_super
*super
= st
->sb
;
5177 struct imsm_super
*mpb
= super
->anchor
;
5182 unsigned long long maxsize
;
5183 unsigned long long minsize
;
5187 /* find the largest common start free region of the possible disks */
5191 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5197 /* don't activate new spares if we are orom constrained
5198 * and there is already a volume active in the container
5200 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
5203 e
= get_extents(super
, dl
);
5206 for (i
= 1; e
[i
-1].size
; i
++)
5214 maxsize
= merge_extents(super
, extent_cnt
);
5218 minsize
= chunk
* 2;
5220 if (cnt
< raiddisks
||
5221 (super
->orom
&& used
&& used
!= raiddisks
) ||
5222 maxsize
< minsize
||
5224 fprintf(stderr
, Name
": not enough devices with space to create array.\n");
5225 return 0; /* No enough free spaces large enough */
5237 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5239 dl
->raiddisk
= cnt
++;
5246 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
5247 int raiddisks
, int *chunk
, unsigned long long size
,
5248 char *dev
, unsigned long long *freesize
,
5256 * if given unused devices create a container
5257 * if given given devices in a container create a member volume
5259 if (level
== LEVEL_CONTAINER
) {
5260 /* Must be a fresh device to add to a container */
5261 return validate_geometry_imsm_container(st
, level
, layout
,
5263 chunk
?*chunk
:0, size
,
5269 if (st
->sb
&& freesize
) {
5270 /* we are being asked to automatically layout a
5271 * new volume based on the current contents of
5272 * the container. If the the parameters can be
5273 * satisfied reserve_space will record the disks,
5274 * start offset, and size of the volume to be
5275 * created. add_to_super and getinfo_super
5276 * detect when autolayout is in progress.
5278 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
5282 return reserve_space(st
, raiddisks
, size
,
5283 chunk
?*chunk
:0, freesize
);
5288 /* creating in a given container */
5289 return validate_geometry_imsm_volume(st
, level
, layout
,
5290 raiddisks
, chunk
, size
,
5291 dev
, freesize
, verbose
);
5294 /* This device needs to be a device in an 'imsm' container */
5295 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
5299 Name
": Cannot create this array on device %s\n",
5304 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
5306 fprintf(stderr
, Name
": Cannot open %s: %s\n",
5307 dev
, strerror(errno
));
5310 /* Well, it is in use by someone, maybe an 'imsm' container. */
5311 cfd
= open_container(fd
);
5315 fprintf(stderr
, Name
": Cannot use %s: It is busy\n",
5319 sra
= sysfs_read(cfd
, 0, GET_VERSION
);
5320 if (sra
&& sra
->array
.major_version
== -1 &&
5321 strcmp(sra
->text_version
, "imsm") == 0)
5325 /* This is a member of a imsm container. Load the container
5326 * and try to create a volume
5328 struct intel_super
*super
;
5330 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
) == 0) {
5332 st
->container_dev
= fd2devnum(cfd
);
5334 return validate_geometry_imsm_volume(st
, level
, layout
,
5342 fprintf(stderr
, Name
": failed container membership check\n");
5348 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
5350 struct intel_super
*super
= st
->sb
;
5352 if (level
&& *level
== UnSet
)
5353 *level
= LEVEL_CONTAINER
;
5355 if (level
&& layout
&& *layout
== UnSet
)
5356 *layout
= imsm_level_to_layout(*level
);
5358 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0))
5359 *chunk
= imsm_default_chunk(super
->orom
);
5362 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
5364 static int kill_subarray_imsm(struct supertype
*st
)
5366 /* remove the subarray currently referenced by ->current_vol */
5368 struct intel_dev
**dp
;
5369 struct intel_super
*super
= st
->sb
;
5370 __u8 current_vol
= super
->current_vol
;
5371 struct imsm_super
*mpb
= super
->anchor
;
5373 if (super
->current_vol
< 0)
5375 super
->current_vol
= -1; /* invalidate subarray cursor */
5377 /* block deletions that would change the uuid of active subarrays
5379 * FIXME when immutable ids are available, but note that we'll
5380 * also need to fixup the invalidated/active subarray indexes in
5383 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5386 if (i
< current_vol
)
5388 sprintf(subarray
, "%u", i
);
5389 if (is_subarray_active(subarray
, st
->devname
)) {
5391 Name
": deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
5398 if (st
->update_tail
) {
5399 struct imsm_update_kill_array
*u
= malloc(sizeof(*u
));
5403 u
->type
= update_kill_array
;
5404 u
->dev_idx
= current_vol
;
5405 append_metadata_update(st
, u
, sizeof(*u
));
5410 for (dp
= &super
->devlist
; *dp
;)
5411 if ((*dp
)->index
== current_vol
) {
5414 handle_missing(super
, (*dp
)->dev
);
5415 if ((*dp
)->index
> current_vol
)
5420 /* no more raid devices, all active components are now spares,
5421 * but of course failed are still failed
5423 if (--mpb
->num_raid_devs
== 0) {
5426 for (d
= super
->disks
; d
; d
= d
->next
)
5427 if (d
->index
> -2) {
5429 d
->disk
.status
= SPARE_DISK
;
5433 super
->updates_pending
++;
5438 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
5439 char *update
, struct mddev_ident
*ident
)
5441 /* update the subarray currently referenced by ->current_vol */
5442 struct intel_super
*super
= st
->sb
;
5443 struct imsm_super
*mpb
= super
->anchor
;
5445 if (strcmp(update
, "name") == 0) {
5446 char *name
= ident
->name
;
5450 if (is_subarray_active(subarray
, st
->devname
)) {
5452 Name
": Unable to update name of active subarray\n");
5456 if (!check_name(super
, name
, 0))
5459 vol
= strtoul(subarray
, &ep
, 10);
5460 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
5463 if (st
->update_tail
) {
5464 struct imsm_update_rename_array
*u
= malloc(sizeof(*u
));
5468 u
->type
= update_rename_array
;
5470 snprintf((char *) u
->name
, MAX_RAID_SERIAL_LEN
, "%s", name
);
5471 append_metadata_update(st
, u
, sizeof(*u
));
5473 struct imsm_dev
*dev
;
5476 dev
= get_imsm_dev(super
, vol
);
5477 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
5478 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5479 dev
= get_imsm_dev(super
, i
);
5480 handle_missing(super
, dev
);
5482 super
->updates_pending
++;
5490 static int is_gen_migration(struct imsm_dev
*dev
)
5495 if (!dev
->vol
.migr_state
)
5498 if (migr_type(dev
) == MIGR_GEN_MIGR
)
5503 #endif /* MDASSEMBLE */
5505 static int is_rebuilding(struct imsm_dev
*dev
)
5507 struct imsm_map
*migr_map
;
5509 if (!dev
->vol
.migr_state
)
5512 if (migr_type(dev
) != MIGR_REBUILD
)
5515 migr_map
= get_imsm_map(dev
, 1);
5517 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
5523 static void update_recovery_start(struct intel_super
*super
,
5524 struct imsm_dev
*dev
,
5525 struct mdinfo
*array
)
5527 struct mdinfo
*rebuild
= NULL
;
5531 if (!is_rebuilding(dev
))
5534 /* Find the rebuild target, but punt on the dual rebuild case */
5535 for (d
= array
->devs
; d
; d
= d
->next
)
5536 if (d
->recovery_start
== 0) {
5543 /* (?) none of the disks are marked with
5544 * IMSM_ORD_REBUILD, so assume they are missing and the
5545 * disk_ord_tbl was not correctly updated
5547 dprintf("%s: failed to locate out-of-sync disk\n", __func__
);
5551 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
5552 rebuild
->recovery_start
= units
* blocks_per_migr_unit(super
, dev
);
5556 static int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
);
5559 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
5561 /* Given a container loaded by load_super_imsm_all,
5562 * extract information about all the arrays into
5564 * If 'subarray' is given, just extract info about that array.
5566 * For each imsm_dev create an mdinfo, fill it in,
5567 * then look for matching devices in super->disks
5568 * and create appropriate device mdinfo.
5570 struct intel_super
*super
= st
->sb
;
5571 struct imsm_super
*mpb
= super
->anchor
;
5572 struct mdinfo
*rest
= NULL
;
5576 int spare_disks
= 0;
5578 /* do not assemble arrays when not all attributes are supported */
5579 if (imsm_check_attributes(mpb
->attributes
) == 0) {
5580 fprintf(stderr
, Name
": IMSM metadata loading not allowed "
5581 "due to attributes incompatibility.\n");
5585 /* check for bad blocks */
5586 if (imsm_bbm_log_size(super
->anchor
))
5589 /* count spare devices, not used in maps
5591 for (d
= super
->disks
; d
; d
= d
->next
)
5595 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5596 struct imsm_dev
*dev
;
5597 struct imsm_map
*map
;
5598 struct imsm_map
*map2
;
5599 struct mdinfo
*this;
5604 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
5607 dev
= get_imsm_dev(super
, i
);
5608 map
= get_imsm_map(dev
, 0);
5609 map2
= get_imsm_map(dev
, 1);
5611 /* do not publish arrays that are in the middle of an
5612 * unsupported migration
5614 if (dev
->vol
.migr_state
&&
5615 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
5616 fprintf(stderr
, Name
": cannot assemble volume '%.16s':"
5617 " unsupported migration in progress\n",
5621 /* do not publish arrays that are not support by controller's
5625 chunk
= __le16_to_cpu(map
->blocks_per_strip
) >> 1;
5627 if (!validate_geometry_imsm_orom(super
,
5628 get_imsm_raid_level(map
), /* RAID level */
5629 imsm_level_to_layout(get_imsm_raid_level(map
)),
5630 map
->num_members
, /* raid disks */
5633 fprintf(stderr
, Name
": RAID gemetry validation failed. "
5634 "Cannot proceed with the action(s).\n");
5637 #endif /* MDASSEMBLE */
5638 this = malloc(sizeof(*this));
5640 fprintf(stderr
, Name
": failed to allocate %zu bytes\n",
5645 super
->current_vol
= i
;
5646 getinfo_super_imsm_volume(st
, this, NULL
);
5648 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
5649 unsigned long long recovery_start
;
5650 struct mdinfo
*info_d
;
5657 idx
= get_imsm_disk_idx(dev
, slot
, 0);
5658 ord
= get_imsm_ord_tbl_ent(dev
, slot
, -1);
5659 for (d
= super
->disks
; d
; d
= d
->next
)
5660 if (d
->index
== idx
)
5663 recovery_start
= MaxSector
;
5666 if (d
&& is_failed(&d
->disk
))
5668 if (ord
& IMSM_ORD_REBUILD
)
5672 * if we skip some disks the array will be assmebled degraded;
5673 * reset resync start to avoid a dirty-degraded
5674 * situation when performing the intial sync
5676 * FIXME handle dirty degraded
5678 if ((skip
|| recovery_start
== 0) && !dev
->vol
.dirty
)
5679 this->resync_start
= MaxSector
;
5683 info_d
= calloc(1, sizeof(*info_d
));
5685 fprintf(stderr
, Name
": failed to allocate disk"
5686 " for volume %.16s\n", dev
->volume
);
5687 info_d
= this->devs
;
5689 struct mdinfo
*d
= info_d
->next
;
5698 info_d
->next
= this->devs
;
5699 this->devs
= info_d
;
5701 info_d
->disk
.number
= d
->index
;
5702 info_d
->disk
.major
= d
->major
;
5703 info_d
->disk
.minor
= d
->minor
;
5704 info_d
->disk
.raid_disk
= slot
;
5705 info_d
->recovery_start
= recovery_start
;
5707 if (slot
< map2
->num_members
)
5708 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
5710 this->array
.spare_disks
++;
5712 if (slot
< map
->num_members
)
5713 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
5715 this->array
.spare_disks
++;
5717 if (info_d
->recovery_start
== MaxSector
)
5718 this->array
.working_disks
++;
5720 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
5721 info_d
->data_offset
= __le32_to_cpu(map
->pba_of_lba0
);
5722 info_d
->component_size
= __le32_to_cpu(map
->blocks_per_member
);
5724 /* now that the disk list is up-to-date fixup recovery_start */
5725 update_recovery_start(super
, dev
, this);
5726 this->array
.spare_disks
+= spare_disks
;
5729 /* check for reshape */
5730 if (this->reshape_active
== 1)
5731 recover_backup_imsm(st
, this);
5736 /* if array has bad blocks, set suitable bit in array status */
5738 rest
->array
.state
|= (1<<MD_SB_BBM_ERRORS
);
5744 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
, int failed
)
5746 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5749 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
5750 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
5752 switch (get_imsm_raid_level(map
)) {
5754 return IMSM_T_STATE_FAILED
;
5757 if (failed
< map
->num_members
)
5758 return IMSM_T_STATE_DEGRADED
;
5760 return IMSM_T_STATE_FAILED
;
5765 * check to see if any mirrors have failed, otherwise we
5766 * are degraded. Even numbered slots are mirrored on
5770 /* gcc -Os complains that this is unused */
5771 int insync
= insync
;
5773 for (i
= 0; i
< map
->num_members
; i
++) {
5774 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, -1);
5775 int idx
= ord_to_idx(ord
);
5776 struct imsm_disk
*disk
;
5778 /* reset the potential in-sync count on even-numbered
5779 * slots. num_copies is always 2 for imsm raid10
5784 disk
= get_imsm_disk(super
, idx
);
5785 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
5788 /* no in-sync disks left in this mirror the
5792 return IMSM_T_STATE_FAILED
;
5795 return IMSM_T_STATE_DEGRADED
;
5799 return IMSM_T_STATE_DEGRADED
;
5801 return IMSM_T_STATE_FAILED
;
5807 return map
->map_state
;
5810 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
)
5814 struct imsm_disk
*disk
;
5815 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5816 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
);
5820 /* at the beginning of migration we set IMSM_ORD_REBUILD on
5821 * disks that are being rebuilt. New failures are recorded to
5822 * map[0]. So we look through all the disks we started with and
5823 * see if any failures are still present, or if any new ones
5826 * FIXME add support for online capacity expansion and
5827 * raid-level-migration
5829 for (i
= 0; i
< prev
->num_members
; i
++) {
5830 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
5831 ord
|= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
5832 idx
= ord_to_idx(ord
);
5834 disk
= get_imsm_disk(super
, idx
);
5835 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
5843 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
5846 struct intel_super
*super
= c
->sb
;
5847 struct imsm_super
*mpb
= super
->anchor
;
5849 if (atoi(inst
) >= mpb
->num_raid_devs
) {
5850 fprintf(stderr
, "%s: subarry index %d, out of range\n",
5851 __func__
, atoi(inst
));
5855 dprintf("imsm: open_new %s\n", inst
);
5856 a
->info
.container_member
= atoi(inst
);
5860 static int is_resyncing(struct imsm_dev
*dev
)
5862 struct imsm_map
*migr_map
;
5864 if (!dev
->vol
.migr_state
)
5867 if (migr_type(dev
) == MIGR_INIT
||
5868 migr_type(dev
) == MIGR_REPAIR
)
5871 if (migr_type(dev
) == MIGR_GEN_MIGR
)
5874 migr_map
= get_imsm_map(dev
, 1);
5876 if ((migr_map
->map_state
== IMSM_T_STATE_NORMAL
) &&
5877 (dev
->vol
.migr_type
!= MIGR_GEN_MIGR
))
5883 /* return true if we recorded new information */
5884 static int mark_failure(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
5888 struct imsm_map
*map
;
5889 char buf
[MAX_RAID_SERIAL_LEN
+3];
5890 unsigned int len
, shift
= 0;
5892 /* new failures are always set in map[0] */
5893 map
= get_imsm_map(dev
, 0);
5895 slot
= get_imsm_disk_slot(map
, idx
);
5899 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
5900 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
5903 sprintf(buf
, "%s:0", disk
->serial
);
5904 if ((len
= strlen(buf
)) >= MAX_RAID_SERIAL_LEN
)
5905 shift
= len
- MAX_RAID_SERIAL_LEN
+ 1;
5906 strncpy((char *)disk
->serial
, &buf
[shift
], MAX_RAID_SERIAL_LEN
);
5908 disk
->status
|= FAILED_DISK
;
5909 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
5910 if (map
->failed_disk_num
== 0xff)
5911 map
->failed_disk_num
= slot
;
5915 static void mark_missing(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
5917 mark_failure(dev
, disk
, idx
);
5919 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
5922 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
5923 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
5926 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
5932 if (!super
->missing
)
5934 failed
= imsm_count_failed(super
, dev
);
5935 map_state
= imsm_check_degraded(super
, dev
, failed
);
5937 dprintf("imsm: mark missing\n");
5938 end_migration(dev
, map_state
);
5939 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
5940 mark_missing(dev
, &dl
->disk
, dl
->index
);
5941 super
->updates_pending
++;
5944 static unsigned long long imsm_set_array_size(struct imsm_dev
*dev
)
5946 int used_disks
= imsm_num_data_members(dev
, 0);
5947 unsigned long long array_blocks
;
5948 struct imsm_map
*map
;
5950 if (used_disks
== 0) {
5951 /* when problems occures
5952 * return current array_blocks value
5954 array_blocks
= __le32_to_cpu(dev
->size_high
);
5955 array_blocks
= array_blocks
<< 32;
5956 array_blocks
+= __le32_to_cpu(dev
->size_low
);
5958 return array_blocks
;
5961 /* set array size in metadata
5963 map
= get_imsm_map(dev
, 0);
5964 array_blocks
= map
->blocks_per_member
* used_disks
;
5966 /* round array size down to closest MB
5968 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
5969 dev
->size_low
= __cpu_to_le32((__u32
)array_blocks
);
5970 dev
->size_high
= __cpu_to_le32((__u32
)(array_blocks
>> 32));
5972 return array_blocks
;
5975 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
5977 static void imsm_progress_container_reshape(struct intel_super
*super
)
5979 /* if no device has a migr_state, but some device has a
5980 * different number of members than the previous device, start
5981 * changing the number of devices in this device to match
5984 struct imsm_super
*mpb
= super
->anchor
;
5985 int prev_disks
= -1;
5989 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5990 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
5991 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5992 struct imsm_map
*map2
;
5993 int prev_num_members
;
5995 if (dev
->vol
.migr_state
)
5998 if (prev_disks
== -1)
5999 prev_disks
= map
->num_members
;
6000 if (prev_disks
== map
->num_members
)
6003 /* OK, this array needs to enter reshape mode.
6004 * i.e it needs a migr_state
6007 copy_map_size
= sizeof_imsm_map(map
);
6008 prev_num_members
= map
->num_members
;
6009 map
->num_members
= prev_disks
;
6010 dev
->vol
.migr_state
= 1;
6011 dev
->vol
.curr_migr_unit
= 0;
6012 dev
->vol
.migr_type
= MIGR_GEN_MIGR
;
6013 for (i
= prev_num_members
;
6014 i
< map
->num_members
; i
++)
6015 set_imsm_ord_tbl_ent(map
, i
, i
);
6016 map2
= get_imsm_map(dev
, 1);
6017 /* Copy the current map */
6018 memcpy(map2
, map
, copy_map_size
);
6019 map2
->num_members
= prev_num_members
;
6021 imsm_set_array_size(dev
);
6022 super
->updates_pending
++;
6026 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
6027 * states are handled in imsm_set_disk() with one exception, when a
6028 * resync is stopped due to a new failure this routine will set the
6029 * 'degraded' state for the array.
6031 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
6033 int inst
= a
->info
.container_member
;
6034 struct intel_super
*super
= a
->container
->sb
;
6035 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
6036 struct imsm_map
*map
= get_imsm_map(dev
, 0);
6037 int failed
= imsm_count_failed(super
, dev
);
6038 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
);
6039 __u32 blocks_per_unit
;
6041 if (dev
->vol
.migr_state
&&
6042 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
6043 /* array state change is blocked due to reshape action
6045 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
6046 * - finish the reshape (if last_checkpoint is big and action != reshape)
6047 * - update curr_migr_unit
6049 if (a
->curr_action
== reshape
) {
6050 /* still reshaping, maybe update curr_migr_unit */
6051 goto mark_checkpoint
;
6053 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
6054 /* for some reason we aborted the reshape.
6056 * disable automatic metadata rollback
6057 * user action is required to recover process
6060 struct imsm_map
*map2
= get_imsm_map(dev
, 1);
6061 dev
->vol
.migr_state
= 0;
6062 dev
->vol
.migr_type
= 0;
6063 dev
->vol
.curr_migr_unit
= 0;
6064 memcpy(map
, map2
, sizeof_imsm_map(map2
));
6065 super
->updates_pending
++;
6068 if (a
->last_checkpoint
>= a
->info
.component_size
) {
6069 unsigned long long array_blocks
;
6073 used_disks
= imsm_num_data_members(dev
, 0);
6074 if (used_disks
> 0) {
6076 map
->blocks_per_member
*
6078 /* round array size down to closest MB
6080 array_blocks
= (array_blocks
6081 >> SECT_PER_MB_SHIFT
)
6082 << SECT_PER_MB_SHIFT
;
6083 a
->info
.custom_array_size
= array_blocks
;
6084 /* encourage manager to update array
6088 a
->check_reshape
= 1;
6090 /* finalize online capacity expansion/reshape */
6091 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
6093 mdi
->disk
.raid_disk
,
6096 imsm_progress_container_reshape(super
);
6101 /* before we activate this array handle any missing disks */
6102 if (consistent
== 2)
6103 handle_missing(super
, dev
);
6105 if (consistent
== 2 &&
6106 (!is_resync_complete(&a
->info
) ||
6107 map_state
!= IMSM_T_STATE_NORMAL
||
6108 dev
->vol
.migr_state
))
6111 if (is_resync_complete(&a
->info
)) {
6112 /* complete intialization / resync,
6113 * recovery and interrupted recovery is completed in
6116 if (is_resyncing(dev
)) {
6117 dprintf("imsm: mark resync done\n");
6118 end_migration(dev
, map_state
);
6119 super
->updates_pending
++;
6120 a
->last_checkpoint
= 0;
6122 } else if (!is_resyncing(dev
) && !failed
) {
6123 /* mark the start of the init process if nothing is failed */
6124 dprintf("imsm: mark resync start\n");
6125 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
6126 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
6128 migrate(dev
, super
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
6129 super
->updates_pending
++;
6133 /* skip checkpointing for general migration,
6134 * it is controlled in mdadm
6136 if (is_gen_migration(dev
))
6137 goto skip_mark_checkpoint
;
6139 /* check if we can update curr_migr_unit from resync_start, recovery_start */
6140 blocks_per_unit
= blocks_per_migr_unit(super
, dev
);
6141 if (blocks_per_unit
) {
6145 units
= a
->last_checkpoint
/ blocks_per_unit
;
6148 /* check that we did not overflow 32-bits, and that
6149 * curr_migr_unit needs updating
6151 if (units32
== units
&&
6153 __le32_to_cpu(dev
->vol
.curr_migr_unit
) != units32
) {
6154 dprintf("imsm: mark checkpoint (%u)\n", units32
);
6155 dev
->vol
.curr_migr_unit
= __cpu_to_le32(units32
);
6156 super
->updates_pending
++;
6160 skip_mark_checkpoint
:
6161 /* mark dirty / clean */
6162 if (dev
->vol
.dirty
!= !consistent
) {
6163 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
6168 super
->updates_pending
++;
6174 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
6176 int inst
= a
->info
.container_member
;
6177 struct intel_super
*super
= a
->container
->sb
;
6178 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
6179 struct imsm_map
*map
= get_imsm_map(dev
, 0);
6180 struct imsm_disk
*disk
;
6185 if (n
> map
->num_members
)
6186 fprintf(stderr
, "imsm: set_disk %d out of range 0..%d\n",
6187 n
, map
->num_members
- 1);
6192 dprintf("imsm: set_disk %d:%x\n", n
, state
);
6194 ord
= get_imsm_ord_tbl_ent(dev
, n
, -1);
6195 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
6197 /* check for new failures */
6198 if (state
& DS_FAULTY
) {
6199 if (mark_failure(dev
, disk
, ord_to_idx(ord
)))
6200 super
->updates_pending
++;
6203 /* check if in_sync */
6204 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
6205 struct imsm_map
*migr_map
= get_imsm_map(dev
, 1);
6207 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
6208 super
->updates_pending
++;
6211 failed
= imsm_count_failed(super
, dev
);
6212 map_state
= imsm_check_degraded(super
, dev
, failed
);
6214 /* check if recovery complete, newly degraded, or failed */
6215 if (map_state
== IMSM_T_STATE_NORMAL
&& is_rebuilding(dev
)) {
6216 end_migration(dev
, map_state
);
6217 map
= get_imsm_map(dev
, 0);
6218 map
->failed_disk_num
= ~0;
6219 super
->updates_pending
++;
6220 a
->last_checkpoint
= 0;
6221 } else if (map_state
== IMSM_T_STATE_DEGRADED
&&
6222 map
->map_state
!= map_state
&&
6223 !dev
->vol
.migr_state
) {
6224 dprintf("imsm: mark degraded\n");
6225 map
->map_state
= map_state
;
6226 super
->updates_pending
++;
6227 a
->last_checkpoint
= 0;
6228 } else if (map_state
== IMSM_T_STATE_FAILED
&&
6229 map
->map_state
!= map_state
) {
6230 dprintf("imsm: mark failed\n");
6231 end_migration(dev
, map_state
);
6232 super
->updates_pending
++;
6233 a
->last_checkpoint
= 0;
6234 } else if (is_gen_migration(dev
)) {
6235 dprintf("imsm: Detected General Migration in state: ");
6236 if (map_state
== IMSM_T_STATE_NORMAL
) {
6237 end_migration(dev
, map_state
);
6238 map
= get_imsm_map(dev
, 0);
6239 map
->failed_disk_num
= ~0;
6240 dprintf("normal\n");
6242 if (map_state
== IMSM_T_STATE_DEGRADED
) {
6243 printf("degraded\n");
6244 end_migration(dev
, map_state
);
6246 dprintf("failed\n");
6248 map
->map_state
= map_state
;
6250 super
->updates_pending
++;
6254 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
6257 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
6258 unsigned long long dsize
;
6259 unsigned long long sectors
;
6261 get_dev_size(fd
, NULL
, &dsize
);
6263 if (mpb_size
> 512) {
6264 /* -1 to account for anchor */
6265 sectors
= mpb_sectors(mpb
) - 1;
6267 /* write the extended mpb to the sectors preceeding the anchor */
6268 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0)
6271 if ((unsigned long long)write(fd
, buf
+ 512, 512 * sectors
)
6276 /* first block is stored on second to last sector of the disk */
6277 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0)
6280 if (write(fd
, buf
, 512) != 512)
6286 static void imsm_sync_metadata(struct supertype
*container
)
6288 struct intel_super
*super
= container
->sb
;
6290 dprintf("sync metadata: %d\n", super
->updates_pending
);
6291 if (!super
->updates_pending
)
6294 write_super_imsm(container
, 0);
6296 super
->updates_pending
= 0;
6299 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
6301 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
6302 int i
= get_imsm_disk_idx(dev
, idx
, -1);
6305 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6309 if (dl
&& is_failed(&dl
->disk
))
6313 dprintf("%s: found %x:%x\n", __func__
, dl
->major
, dl
->minor
);
6318 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
6319 struct active_array
*a
, int activate_new
,
6320 struct mdinfo
*additional_test_list
)
6322 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
6323 int idx
= get_imsm_disk_idx(dev
, slot
, -1);
6324 struct imsm_super
*mpb
= super
->anchor
;
6325 struct imsm_map
*map
;
6326 unsigned long long pos
;
6331 __u32 array_start
= 0;
6332 __u32 array_end
= 0;
6334 struct mdinfo
*test_list
;
6336 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6337 /* If in this array, skip */
6338 for (d
= a
->info
.devs
; d
; d
= d
->next
)
6339 if (d
->state_fd
>= 0 &&
6340 d
->disk
.major
== dl
->major
&&
6341 d
->disk
.minor
== dl
->minor
) {
6342 dprintf("%x:%x already in array\n",
6343 dl
->major
, dl
->minor
);
6348 test_list
= additional_test_list
;
6350 if (test_list
->disk
.major
== dl
->major
&&
6351 test_list
->disk
.minor
== dl
->minor
) {
6352 dprintf("%x:%x already in additional test list\n",
6353 dl
->major
, dl
->minor
);
6356 test_list
= test_list
->next
;
6361 /* skip in use or failed drives */
6362 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
6364 dprintf("%x:%x status (failed: %d index: %d)\n",
6365 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
6369 /* skip pure spares when we are looking for partially
6370 * assimilated drives
6372 if (dl
->index
== -1 && !activate_new
)
6375 /* Does this unused device have the requisite free space?
6376 * It needs to be able to cover all member volumes
6378 ex
= get_extents(super
, dl
);
6380 dprintf("cannot get extents\n");
6383 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6384 dev
= get_imsm_dev(super
, i
);
6385 map
= get_imsm_map(dev
, 0);
6387 /* check if this disk is already a member of
6390 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
6396 array_start
= __le32_to_cpu(map
->pba_of_lba0
);
6397 array_end
= array_start
+
6398 __le32_to_cpu(map
->blocks_per_member
) - 1;
6401 /* check that we can start at pba_of_lba0 with
6402 * blocks_per_member of space
6404 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
6408 pos
= ex
[j
].start
+ ex
[j
].size
;
6410 } while (ex
[j
-1].size
);
6417 if (i
< mpb
->num_raid_devs
) {
6418 dprintf("%x:%x does not have %u to %u available\n",
6419 dl
->major
, dl
->minor
, array_start
, array_end
);
6430 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
6432 struct imsm_dev
*dev2
;
6433 struct imsm_map
*map
;
6439 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
6441 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
);
6442 if (state
== IMSM_T_STATE_FAILED
) {
6443 map
= get_imsm_map(dev2
, 0);
6446 for (slot
= 0; slot
< map
->num_members
; slot
++) {
6448 * Check if failed disks are deleted from intel
6449 * disk list or are marked to be deleted
6451 idx
= get_imsm_disk_idx(dev2
, slot
, -1);
6452 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
6454 * Do not rebuild the array if failed disks
6455 * from failed sub-array are not removed from
6459 is_failed(&idisk
->disk
) &&
6460 (idisk
->action
!= DISK_REMOVE
))
6468 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
6469 struct metadata_update
**updates
)
6472 * Find a device with unused free space and use it to replace a
6473 * failed/vacant region in an array. We replace failed regions one a
6474 * array at a time. The result is that a new spare disk will be added
6475 * to the first failed array and after the monitor has finished
6476 * propagating failures the remainder will be consumed.
6478 * FIXME add a capability for mdmon to request spares from another
6482 struct intel_super
*super
= a
->container
->sb
;
6483 int inst
= a
->info
.container_member
;
6484 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
6485 struct imsm_map
*map
= get_imsm_map(dev
, 0);
6486 int failed
= a
->info
.array
.raid_disks
;
6487 struct mdinfo
*rv
= NULL
;
6490 struct metadata_update
*mu
;
6492 struct imsm_update_activate_spare
*u
;
6497 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
6498 if ((d
->curr_state
& DS_FAULTY
) &&
6500 /* wait for Removal to happen */
6502 if (d
->state_fd
>= 0)
6506 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
6507 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
6509 if (dev
->vol
.migr_state
&&
6510 dev
->vol
.migr_type
== MIGR_GEN_MIGR
)
6511 /* No repair during migration */
6514 if (a
->info
.array
.level
== 4)
6515 /* No repair for takeovered array
6516 * imsm doesn't support raid4
6520 if (imsm_check_degraded(super
, dev
, failed
) != IMSM_T_STATE_DEGRADED
)
6524 * If there are any failed disks check state of the other volume.
6525 * Block rebuild if the another one is failed until failed disks
6526 * are removed from container.
6529 dprintf("found failed disks in %s, check if there another"
6530 "failed sub-array.\n",
6532 /* check if states of the other volumes allow for rebuild */
6533 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
6535 allowed
= imsm_rebuild_allowed(a
->container
,
6543 /* For each slot, if it is not working, find a spare */
6544 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
6545 for (d
= a
->info
.devs
; d
; d
= d
->next
)
6546 if (d
->disk
.raid_disk
== i
)
6548 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
6549 if (d
&& (d
->state_fd
>= 0))
6553 * OK, this device needs recovery. Try to re-add the
6554 * previous occupant of this slot, if this fails see if
6555 * we can continue the assimilation of a spare that was
6556 * partially assimilated, finally try to activate a new
6559 dl
= imsm_readd(super
, i
, a
);
6561 dl
= imsm_add_spare(super
, i
, a
, 0, NULL
);
6563 dl
= imsm_add_spare(super
, i
, a
, 1, NULL
);
6567 /* found a usable disk with enough space */
6568 di
= malloc(sizeof(*di
));
6571 memset(di
, 0, sizeof(*di
));
6573 /* dl->index will be -1 in the case we are activating a
6574 * pristine spare. imsm_process_update() will create a
6575 * new index in this case. Once a disk is found to be
6576 * failed in all member arrays it is kicked from the
6579 di
->disk
.number
= dl
->index
;
6581 /* (ab)use di->devs to store a pointer to the device
6584 di
->devs
= (struct mdinfo
*) dl
;
6586 di
->disk
.raid_disk
= i
;
6587 di
->disk
.major
= dl
->major
;
6588 di
->disk
.minor
= dl
->minor
;
6590 di
->recovery_start
= 0;
6591 di
->data_offset
= __le32_to_cpu(map
->pba_of_lba0
);
6592 di
->component_size
= a
->info
.component_size
;
6593 di
->container_member
= inst
;
6594 super
->random
= random32();
6598 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
6599 i
, di
->data_offset
);
6605 /* No spares found */
6607 /* Now 'rv' has a list of devices to return.
6608 * Create a metadata_update record to update the
6609 * disk_ord_tbl for the array
6611 mu
= malloc(sizeof(*mu
));
6613 mu
->buf
= malloc(sizeof(struct imsm_update_activate_spare
) * num_spares
);
6614 if (mu
->buf
== NULL
) {
6621 struct mdinfo
*n
= rv
->next
;
6630 mu
->space_list
= NULL
;
6631 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
6632 mu
->next
= *updates
;
6633 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
6635 for (di
= rv
; di
; di
= di
->next
) {
6636 u
->type
= update_activate_spare
;
6637 u
->dl
= (struct dl
*) di
->devs
;
6639 u
->slot
= di
->disk
.raid_disk
;
6650 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
6652 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
6653 struct imsm_map
*map
= get_imsm_map(dev
, 0);
6654 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, 0);
6655 struct disk_info
*inf
= get_disk_info(u
);
6656 struct imsm_disk
*disk
;
6660 for (i
= 0; i
< map
->num_members
; i
++) {
6661 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, -1));
6662 for (j
= 0; j
< new_map
->num_members
; j
++)
6663 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
6671 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
6673 struct dl
*dl
= NULL
;
6674 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6675 if ((dl
->major
== major
) && (dl
->minor
== minor
))
6680 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
6682 struct dl
*prev
= NULL
;
6686 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6687 if ((dl
->major
== major
) && (dl
->minor
== minor
)) {
6690 prev
->next
= dl
->next
;
6692 super
->disks
= dl
->next
;
6694 __free_imsm_disk(dl
);
6695 dprintf("%s: removed %x:%x\n",
6696 __func__
, major
, minor
);
6704 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
6706 static int add_remove_disk_update(struct intel_super
*super
)
6708 int check_degraded
= 0;
6709 struct dl
*disk
= NULL
;
6710 /* add/remove some spares to/from the metadata/contrainer */
6711 while (super
->disk_mgmt_list
) {
6712 struct dl
*disk_cfg
;
6714 disk_cfg
= super
->disk_mgmt_list
;
6715 super
->disk_mgmt_list
= disk_cfg
->next
;
6716 disk_cfg
->next
= NULL
;
6718 if (disk_cfg
->action
== DISK_ADD
) {
6719 disk_cfg
->next
= super
->disks
;
6720 super
->disks
= disk_cfg
;
6722 dprintf("%s: added %x:%x\n",
6723 __func__
, disk_cfg
->major
,
6725 } else if (disk_cfg
->action
== DISK_REMOVE
) {
6726 dprintf("Disk remove action processed: %x.%x\n",
6727 disk_cfg
->major
, disk_cfg
->minor
);
6728 disk
= get_disk_super(super
,
6732 /* store action status */
6733 disk
->action
= DISK_REMOVE
;
6734 /* remove spare disks only */
6735 if (disk
->index
== -1) {
6736 remove_disk_super(super
,
6741 /* release allocate disk structure */
6742 __free_imsm_disk(disk_cfg
);
6745 return check_degraded
;
6749 static int apply_reshape_migration_update(struct imsm_update_reshape_migration
*u
,
6750 struct intel_super
*super
,
6753 struct intel_dev
*id
;
6754 void **tofree
= NULL
;
6757 dprintf("apply_reshape_migration_update()\n");
6758 if ((u
->subdev
< 0) ||
6760 dprintf("imsm: Error: Wrong subdev: %i\n", u
->subdev
);
6763 if ((space_list
== NULL
) || (*space_list
== NULL
)) {
6764 dprintf("imsm: Error: Memory is not allocated\n");
6768 for (id
= super
->devlist
; id
; id
= id
->next
) {
6769 if (id
->index
== (unsigned)u
->subdev
) {
6770 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subdev
);
6771 struct imsm_map
*map
;
6772 struct imsm_dev
*new_dev
=
6773 (struct imsm_dev
*)*space_list
;
6774 struct imsm_map
*migr_map
= get_imsm_map(dev
, 1);
6776 struct dl
*new_disk
;
6778 if (new_dev
== NULL
)
6780 *space_list
= **space_list
;
6781 memcpy(new_dev
, dev
, sizeof_imsm_dev(dev
, 0));
6782 map
= get_imsm_map(new_dev
, 0);
6784 dprintf("imsm: Error: migration in progress");
6788 to_state
= map
->map_state
;
6789 if ((u
->new_level
== 5) && (map
->raid_level
== 0)) {
6791 /* this should not happen */
6792 if (u
->new_disks
[0] < 0) {
6793 map
->failed_disk_num
=
6794 map
->num_members
- 1;
6795 to_state
= IMSM_T_STATE_DEGRADED
;
6797 to_state
= IMSM_T_STATE_NORMAL
;
6799 migrate(new_dev
, super
, to_state
, MIGR_GEN_MIGR
);
6800 if (u
->new_level
> -1)
6801 map
->raid_level
= u
->new_level
;
6802 migr_map
= get_imsm_map(new_dev
, 1);
6803 if ((u
->new_level
== 5) &&
6804 (migr_map
->raid_level
== 0)) {
6805 int ord
= map
->num_members
- 1;
6806 migr_map
->num_members
--;
6807 if (u
->new_disks
[0] < 0)
6808 ord
|= IMSM_ORD_REBUILD
;
6809 set_imsm_ord_tbl_ent(map
,
6810 map
->num_members
- 1,
6814 tofree
= (void **)dev
;
6816 /* update chunk size
6818 if (u
->new_chunksize
> 0)
6819 map
->blocks_per_strip
=
6820 __cpu_to_le16(u
->new_chunksize
* 2);
6824 if ((u
->new_level
!= 5) ||
6825 (migr_map
->raid_level
!= 0) ||
6826 (migr_map
->raid_level
== map
->raid_level
))
6829 if (u
->new_disks
[0] >= 0) {
6832 new_disk
= get_disk_super(super
,
6833 major(u
->new_disks
[0]),
6834 minor(u
->new_disks
[0]));
6835 dprintf("imsm: new disk for reshape is: %i:%i "
6836 "(%p, index = %i)\n",
6837 major(u
->new_disks
[0]),
6838 minor(u
->new_disks
[0]),
6839 new_disk
, new_disk
->index
);
6840 if (new_disk
== NULL
)
6841 goto error_disk_add
;
6843 new_disk
->index
= map
->num_members
- 1;
6844 /* slot to fill in autolayout
6846 new_disk
->raiddisk
= new_disk
->index
;
6847 new_disk
->disk
.status
|= CONFIGURED_DISK
;
6848 new_disk
->disk
.status
&= ~SPARE_DISK
;
6850 goto error_disk_add
;
6853 *tofree
= *space_list
;
6854 /* calculate new size
6856 imsm_set_array_size(new_dev
);
6863 *space_list
= tofree
;
6867 dprintf("Error: imsm: Cannot find disk.\n");
6872 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
6873 struct intel_super
*super
,
6876 struct dl
*new_disk
;
6877 struct intel_dev
*id
;
6879 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
6880 int disk_count
= u
->old_raid_disks
;
6881 void **tofree
= NULL
;
6882 int devices_to_reshape
= 1;
6883 struct imsm_super
*mpb
= super
->anchor
;
6885 unsigned int dev_id
;
6887 dprintf("imsm: apply_reshape_container_disks_update()\n");
6889 /* enable spares to use in array */
6890 for (i
= 0; i
< delta_disks
; i
++) {
6891 new_disk
= get_disk_super(super
,
6892 major(u
->new_disks
[i
]),
6893 minor(u
->new_disks
[i
]));
6894 dprintf("imsm: new disk for reshape is: %i:%i "
6895 "(%p, index = %i)\n",
6896 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
6897 new_disk
, new_disk
->index
);
6898 if ((new_disk
== NULL
) ||
6899 ((new_disk
->index
>= 0) &&
6900 (new_disk
->index
< u
->old_raid_disks
)))
6901 goto update_reshape_exit
;
6902 new_disk
->index
= disk_count
++;
6903 /* slot to fill in autolayout
6905 new_disk
->raiddisk
= new_disk
->index
;
6906 new_disk
->disk
.status
|=
6908 new_disk
->disk
.status
&= ~SPARE_DISK
;
6911 dprintf("imsm: volume set mpb->num_raid_devs = %i\n",
6912 mpb
->num_raid_devs
);
6913 /* manage changes in volume
6915 for (dev_id
= 0; dev_id
< mpb
->num_raid_devs
; dev_id
++) {
6916 void **sp
= *space_list
;
6917 struct imsm_dev
*newdev
;
6918 struct imsm_map
*newmap
, *oldmap
;
6920 for (id
= super
->devlist
; id
; id
= id
->next
) {
6921 if (id
->index
== dev_id
)
6930 /* Copy the dev, but not (all of) the map */
6931 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
6932 oldmap
= get_imsm_map(id
->dev
, 0);
6933 newmap
= get_imsm_map(newdev
, 0);
6934 /* Copy the current map */
6935 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
6936 /* update one device only
6938 if (devices_to_reshape
) {
6939 dprintf("imsm: modifying subdev: %i\n",
6941 devices_to_reshape
--;
6942 newdev
->vol
.migr_state
= 1;
6943 newdev
->vol
.curr_migr_unit
= 0;
6944 newdev
->vol
.migr_type
= MIGR_GEN_MIGR
;
6945 newmap
->num_members
= u
->new_raid_disks
;
6946 for (i
= 0; i
< delta_disks
; i
++) {
6947 set_imsm_ord_tbl_ent(newmap
,
6948 u
->old_raid_disks
+ i
,
6949 u
->old_raid_disks
+ i
);
6951 /* New map is correct, now need to save old map
6953 newmap
= get_imsm_map(newdev
, 1);
6954 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
6956 imsm_set_array_size(newdev
);
6959 sp
= (void **)id
->dev
;
6964 /* Clear migration record */
6965 memset(super
->migr_rec
, 0, sizeof(struct migr_record
));
6968 *space_list
= tofree
;
6971 update_reshape_exit
:
6976 static int apply_takeover_update(struct imsm_update_takeover
*u
,
6977 struct intel_super
*super
,
6980 struct imsm_dev
*dev
= NULL
;
6981 struct intel_dev
*dv
;
6982 struct imsm_dev
*dev_new
;
6983 struct imsm_map
*map
;
6987 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
6988 if (dv
->index
== (unsigned int)u
->subarray
) {
6996 map
= get_imsm_map(dev
, 0);
6998 if (u
->direction
== R10_TO_R0
) {
6999 /* Number of failed disks must be half of initial disk number */
7000 if (imsm_count_failed(super
, dev
) != (map
->num_members
/ 2))
7003 /* iterate through devices to mark removed disks as spare */
7004 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
7005 if (dm
->disk
.status
& FAILED_DISK
) {
7006 int idx
= dm
->index
;
7007 /* update indexes on the disk list */
7008 /* FIXME this loop-with-the-loop looks wrong, I'm not convinced
7009 the index values will end up being correct.... NB */
7010 for (du
= super
->disks
; du
; du
= du
->next
)
7011 if (du
->index
> idx
)
7013 /* mark as spare disk */
7014 dm
->disk
.status
= SPARE_DISK
;
7019 map
->num_members
= map
->num_members
/ 2;
7020 map
->map_state
= IMSM_T_STATE_NORMAL
;
7021 map
->num_domains
= 1;
7022 map
->raid_level
= 0;
7023 map
->failed_disk_num
= -1;
7026 if (u
->direction
== R0_TO_R10
) {
7028 /* update slots in current disk list */
7029 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
7033 /* create new *missing* disks */
7034 for (i
= 0; i
< map
->num_members
; i
++) {
7035 space
= *space_list
;
7038 *space_list
= *space
;
7040 memcpy(du
, super
->disks
, sizeof(*du
));
7044 du
->index
= (i
* 2) + 1;
7045 sprintf((char *)du
->disk
.serial
,
7046 " MISSING_%d", du
->index
);
7047 sprintf((char *)du
->serial
,
7048 "MISSING_%d", du
->index
);
7049 du
->next
= super
->missing
;
7050 super
->missing
= du
;
7052 /* create new dev and map */
7053 space
= *space_list
;
7056 *space_list
= *space
;
7057 dev_new
= (void *)space
;
7058 memcpy(dev_new
, dev
, sizeof(*dev
));
7059 /* update new map */
7060 map
= get_imsm_map(dev_new
, 0);
7061 map
->num_members
= map
->num_members
* 2;
7062 map
->map_state
= IMSM_T_STATE_DEGRADED
;
7063 map
->num_domains
= 2;
7064 map
->raid_level
= 1;
7065 /* replace dev<->dev_new */
7068 /* update disk order table */
7069 for (du
= super
->disks
; du
; du
= du
->next
)
7071 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
7072 for (du
= super
->missing
; du
; du
= du
->next
)
7073 if (du
->index
>= 0) {
7074 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
7075 mark_missing(dv
->dev
, &du
->disk
, du
->index
);
7081 static void imsm_process_update(struct supertype
*st
,
7082 struct metadata_update
*update
)
7085 * crack open the metadata_update envelope to find the update record
7086 * update can be one of:
7087 * update_reshape_container_disks - all the arrays in the container
7088 * are being reshaped to have more devices. We need to mark
7089 * the arrays for general migration and convert selected spares
7090 * into active devices.
7091 * update_activate_spare - a spare device has replaced a failed
7092 * device in an array, update the disk_ord_tbl. If this disk is
7093 * present in all member arrays then also clear the SPARE_DISK
7095 * update_create_array
7097 * update_rename_array
7098 * update_add_remove_disk
7100 struct intel_super
*super
= st
->sb
;
7101 struct imsm_super
*mpb
;
7102 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
7104 /* update requires a larger buf but the allocation failed */
7105 if (super
->next_len
&& !super
->next_buf
) {
7106 super
->next_len
= 0;
7110 if (super
->next_buf
) {
7111 memcpy(super
->next_buf
, super
->buf
, super
->len
);
7113 super
->len
= super
->next_len
;
7114 super
->buf
= super
->next_buf
;
7116 super
->next_len
= 0;
7117 super
->next_buf
= NULL
;
7120 mpb
= super
->anchor
;
7123 case update_general_migration_checkpoint
: {
7124 struct intel_dev
*id
;
7125 struct imsm_update_general_migration_checkpoint
*u
=
7126 (void *)update
->buf
;
7128 dprintf("imsm: process_update() "
7129 "for update_general_migration_checkpoint called\n");
7131 /* find device under general migration */
7132 for (id
= super
->devlist
; id
; id
= id
->next
) {
7133 if (is_gen_migration(id
->dev
)) {
7134 id
->dev
->vol
.curr_migr_unit
=
7135 __cpu_to_le32(u
->curr_migr_unit
);
7136 super
->updates_pending
++;
7141 case update_takeover
: {
7142 struct imsm_update_takeover
*u
= (void *)update
->buf
;
7143 if (apply_takeover_update(u
, super
, &update
->space_list
)) {
7144 imsm_update_version_info(super
);
7145 super
->updates_pending
++;
7150 case update_reshape_container_disks
: {
7151 struct imsm_update_reshape
*u
= (void *)update
->buf
;
7152 if (apply_reshape_container_disks_update(
7153 u
, super
, &update
->space_list
))
7154 super
->updates_pending
++;
7157 case update_reshape_migration
: {
7158 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
7159 if (apply_reshape_migration_update(
7160 u
, super
, &update
->space_list
))
7161 super
->updates_pending
++;
7164 case update_activate_spare
: {
7165 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
7166 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
7167 struct imsm_map
*map
= get_imsm_map(dev
, 0);
7168 struct imsm_map
*migr_map
;
7169 struct active_array
*a
;
7170 struct imsm_disk
*disk
;
7175 int victim
= get_imsm_disk_idx(dev
, u
->slot
, -1);
7178 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
7183 fprintf(stderr
, "error: imsm_activate_spare passed "
7184 "an unknown disk (index: %d)\n",
7189 super
->updates_pending
++;
7190 /* count failures (excluding rebuilds and the victim)
7191 * to determine map[0] state
7194 for (i
= 0; i
< map
->num_members
; i
++) {
7197 disk
= get_imsm_disk(super
,
7198 get_imsm_disk_idx(dev
, i
, -1));
7199 if (!disk
|| is_failed(disk
))
7203 /* adding a pristine spare, assign a new index */
7204 if (dl
->index
< 0) {
7205 dl
->index
= super
->anchor
->num_disks
;
7206 super
->anchor
->num_disks
++;
7209 disk
->status
|= CONFIGURED_DISK
;
7210 disk
->status
&= ~SPARE_DISK
;
7213 to_state
= imsm_check_degraded(super
, dev
, failed
);
7214 map
->map_state
= IMSM_T_STATE_DEGRADED
;
7215 migrate(dev
, super
, to_state
, MIGR_REBUILD
);
7216 migr_map
= get_imsm_map(dev
, 1);
7217 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
7218 set_imsm_ord_tbl_ent(migr_map
, u
->slot
, dl
->index
| IMSM_ORD_REBUILD
);
7220 /* update the family_num to mark a new container
7221 * generation, being careful to record the existing
7222 * family_num in orig_family_num to clean up after
7223 * earlier mdadm versions that neglected to set it.
7225 if (mpb
->orig_family_num
== 0)
7226 mpb
->orig_family_num
= mpb
->family_num
;
7227 mpb
->family_num
+= super
->random
;
7229 /* count arrays using the victim in the metadata */
7231 for (a
= st
->arrays
; a
; a
= a
->next
) {
7232 dev
= get_imsm_dev(super
, a
->info
.container_member
);
7233 map
= get_imsm_map(dev
, 0);
7235 if (get_imsm_disk_slot(map
, victim
) >= 0)
7239 /* delete the victim if it is no longer being
7245 /* We know that 'manager' isn't touching anything,
7246 * so it is safe to delete
7248 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
7249 if ((*dlp
)->index
== victim
)
7252 /* victim may be on the missing list */
7254 for (dlp
= &super
->missing
; *dlp
; dlp
= &(*dlp
)->next
)
7255 if ((*dlp
)->index
== victim
)
7257 imsm_delete(super
, dlp
, victim
);
7261 case update_create_array
: {
7262 /* someone wants to create a new array, we need to be aware of
7263 * a few races/collisions:
7264 * 1/ 'Create' called by two separate instances of mdadm
7265 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
7266 * devices that have since been assimilated via
7268 * In the event this update can not be carried out mdadm will
7269 * (FIX ME) notice that its update did not take hold.
7271 struct imsm_update_create_array
*u
= (void *) update
->buf
;
7272 struct intel_dev
*dv
;
7273 struct imsm_dev
*dev
;
7274 struct imsm_map
*map
, *new_map
;
7275 unsigned long long start
, end
;
7276 unsigned long long new_start
, new_end
;
7278 struct disk_info
*inf
;
7281 /* handle racing creates: first come first serve */
7282 if (u
->dev_idx
< mpb
->num_raid_devs
) {
7283 dprintf("%s: subarray %d already defined\n",
7284 __func__
, u
->dev_idx
);
7288 /* check update is next in sequence */
7289 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
7290 dprintf("%s: can not create array %d expected index %d\n",
7291 __func__
, u
->dev_idx
, mpb
->num_raid_devs
);
7295 new_map
= get_imsm_map(&u
->dev
, 0);
7296 new_start
= __le32_to_cpu(new_map
->pba_of_lba0
);
7297 new_end
= new_start
+ __le32_to_cpu(new_map
->blocks_per_member
);
7298 inf
= get_disk_info(u
);
7300 /* handle activate_spare versus create race:
7301 * check to make sure that overlapping arrays do not include
7304 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7305 dev
= get_imsm_dev(super
, i
);
7306 map
= get_imsm_map(dev
, 0);
7307 start
= __le32_to_cpu(map
->pba_of_lba0
);
7308 end
= start
+ __le32_to_cpu(map
->blocks_per_member
);
7309 if ((new_start
>= start
&& new_start
<= end
) ||
7310 (start
>= new_start
&& start
<= new_end
))
7315 if (disks_overlap(super
, i
, u
)) {
7316 dprintf("%s: arrays overlap\n", __func__
);
7321 /* check that prepare update was successful */
7322 if (!update
->space
) {
7323 dprintf("%s: prepare update failed\n", __func__
);
7327 /* check that all disks are still active before committing
7328 * changes. FIXME: could we instead handle this by creating a
7329 * degraded array? That's probably not what the user expects,
7330 * so better to drop this update on the floor.
7332 for (i
= 0; i
< new_map
->num_members
; i
++) {
7333 dl
= serial_to_dl(inf
[i
].serial
, super
);
7335 dprintf("%s: disk disappeared\n", __func__
);
7340 super
->updates_pending
++;
7342 /* convert spares to members and fixup ord_tbl */
7343 for (i
= 0; i
< new_map
->num_members
; i
++) {
7344 dl
= serial_to_dl(inf
[i
].serial
, super
);
7345 if (dl
->index
== -1) {
7346 dl
->index
= mpb
->num_disks
;
7348 dl
->disk
.status
|= CONFIGURED_DISK
;
7349 dl
->disk
.status
&= ~SPARE_DISK
;
7351 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
7356 update
->space
= NULL
;
7357 imsm_copy_dev(dev
, &u
->dev
);
7358 dv
->index
= u
->dev_idx
;
7359 dv
->next
= super
->devlist
;
7360 super
->devlist
= dv
;
7361 mpb
->num_raid_devs
++;
7363 imsm_update_version_info(super
);
7366 /* mdmon knows how to release update->space, but not
7367 * ((struct intel_dev *) update->space)->dev
7369 if (update
->space
) {
7375 case update_kill_array
: {
7376 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
7377 int victim
= u
->dev_idx
;
7378 struct active_array
*a
;
7379 struct intel_dev
**dp
;
7380 struct imsm_dev
*dev
;
7382 /* sanity check that we are not affecting the uuid of
7383 * active arrays, or deleting an active array
7385 * FIXME when immutable ids are available, but note that
7386 * we'll also need to fixup the invalidated/active
7387 * subarray indexes in mdstat
7389 for (a
= st
->arrays
; a
; a
= a
->next
)
7390 if (a
->info
.container_member
>= victim
)
7392 /* by definition if mdmon is running at least one array
7393 * is active in the container, so checking
7394 * mpb->num_raid_devs is just extra paranoia
7396 dev
= get_imsm_dev(super
, victim
);
7397 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
7398 dprintf("failed to delete subarray-%d\n", victim
);
7402 for (dp
= &super
->devlist
; *dp
;)
7403 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
7406 if ((*dp
)->index
> (unsigned)victim
)
7410 mpb
->num_raid_devs
--;
7411 super
->updates_pending
++;
7414 case update_rename_array
: {
7415 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
7416 char name
[MAX_RAID_SERIAL_LEN
+1];
7417 int target
= u
->dev_idx
;
7418 struct active_array
*a
;
7419 struct imsm_dev
*dev
;
7421 /* sanity check that we are not affecting the uuid of
7424 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
7425 name
[MAX_RAID_SERIAL_LEN
] = '\0';
7426 for (a
= st
->arrays
; a
; a
= a
->next
)
7427 if (a
->info
.container_member
== target
)
7429 dev
= get_imsm_dev(super
, u
->dev_idx
);
7430 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
7431 dprintf("failed to rename subarray-%d\n", target
);
7435 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
7436 super
->updates_pending
++;
7439 case update_add_remove_disk
: {
7440 /* we may be able to repair some arrays if disks are
7441 * being added, check teh status of add_remove_disk
7442 * if discs has been added.
7444 if (add_remove_disk_update(super
)) {
7445 struct active_array
*a
;
7447 super
->updates_pending
++;
7448 for (a
= st
->arrays
; a
; a
= a
->next
)
7449 a
->check_degraded
= 1;
7454 fprintf(stderr
, "error: unsuported process update type:"
7455 "(type: %d)\n", type
);
7459 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
);
7461 static void imsm_prepare_update(struct supertype
*st
,
7462 struct metadata_update
*update
)
7465 * Allocate space to hold new disk entries, raid-device entries or a new
7466 * mpb if necessary. The manager synchronously waits for updates to
7467 * complete in the monitor, so new mpb buffers allocated here can be
7468 * integrated by the monitor thread without worrying about live pointers
7469 * in the manager thread.
7471 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
7472 struct intel_super
*super
= st
->sb
;
7473 struct imsm_super
*mpb
= super
->anchor
;
7478 case update_general_migration_checkpoint
:
7479 dprintf("imsm: prepare_update() "
7480 "for update_general_migration_checkpoint called\n");
7482 case update_takeover
: {
7483 struct imsm_update_takeover
*u
= (void *)update
->buf
;
7484 if (u
->direction
== R0_TO_R10
) {
7485 void **tail
= (void **)&update
->space_list
;
7486 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subarray
);
7487 struct imsm_map
*map
= get_imsm_map(dev
, 0);
7488 int num_members
= map
->num_members
;
7492 /* allocate memory for added disks */
7493 for (i
= 0; i
< num_members
; i
++) {
7494 size
= sizeof(struct dl
);
7495 space
= malloc(size
);
7504 /* allocate memory for new device */
7505 size
= sizeof_imsm_dev(super
->devlist
->dev
, 0) +
7506 (num_members
* sizeof(__u32
));
7507 space
= malloc(size
);
7516 len
= disks_to_mpb_size(num_members
* 2);
7518 /* if allocation didn't success, free buffer */
7519 while (update
->space_list
) {
7520 void **sp
= update
->space_list
;
7521 update
->space_list
= *sp
;
7529 case update_reshape_container_disks
: {
7530 /* Every raid device in the container is about to
7531 * gain some more devices, and we will enter a
7533 * So each 'imsm_map' will be bigger, and the imsm_vol
7534 * will now hold 2 of them.
7535 * Thus we need new 'struct imsm_dev' allocations sized
7536 * as sizeof_imsm_dev but with more devices in both maps.
7538 struct imsm_update_reshape
*u
= (void *)update
->buf
;
7539 struct intel_dev
*dl
;
7540 void **space_tail
= (void**)&update
->space_list
;
7542 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
7544 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
7545 int size
= sizeof_imsm_dev(dl
->dev
, 1);
7547 if (u
->new_raid_disks
> u
->old_raid_disks
)
7548 size
+= sizeof(__u32
)*2*
7549 (u
->new_raid_disks
- u
->old_raid_disks
);
7558 len
= disks_to_mpb_size(u
->new_raid_disks
);
7559 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
7562 case update_reshape_migration
: {
7563 /* for migration level 0->5 we need to add disks
7564 * so the same as for container operation we will copy
7565 * device to the bigger location.
7566 * in memory prepared device and new disk area are prepared
7567 * for usage in process update
7569 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
7570 struct intel_dev
*id
;
7571 void **space_tail
= (void **)&update
->space_list
;
7574 int current_level
= -1;
7576 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
7578 /* add space for bigger array in update
7580 for (id
= super
->devlist
; id
; id
= id
->next
) {
7581 if (id
->index
== (unsigned)u
->subdev
) {
7582 size
= sizeof_imsm_dev(id
->dev
, 1);
7583 if (u
->new_raid_disks
> u
->old_raid_disks
)
7584 size
+= sizeof(__u32
)*2*
7585 (u
->new_raid_disks
- u
->old_raid_disks
);
7595 if (update
->space_list
== NULL
)
7598 /* add space for disk in update
7600 size
= sizeof(struct dl
);
7603 free(update
->space_list
);
7604 update
->space_list
= NULL
;
7611 /* add spare device to update
7613 for (id
= super
->devlist
; id
; id
= id
->next
)
7614 if (id
->index
== (unsigned)u
->subdev
) {
7615 struct imsm_dev
*dev
;
7616 struct imsm_map
*map
;
7618 dev
= get_imsm_dev(super
, u
->subdev
);
7619 map
= get_imsm_map(dev
, 0);
7620 current_level
= map
->raid_level
;
7623 if ((u
->new_level
== 5) && (u
->new_level
!= current_level
)) {
7624 struct mdinfo
*spares
;
7626 spares
= get_spares_for_grow(st
);
7634 makedev(dev
->disk
.major
,
7636 dl
= get_disk_super(super
,
7639 dl
->index
= u
->old_raid_disks
;
7645 len
= disks_to_mpb_size(u
->new_raid_disks
);
7646 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
7649 case update_create_array
: {
7650 struct imsm_update_create_array
*u
= (void *) update
->buf
;
7651 struct intel_dev
*dv
;
7652 struct imsm_dev
*dev
= &u
->dev
;
7653 struct imsm_map
*map
= get_imsm_map(dev
, 0);
7655 struct disk_info
*inf
;
7659 inf
= get_disk_info(u
);
7660 len
= sizeof_imsm_dev(dev
, 1);
7661 /* allocate a new super->devlist entry */
7662 dv
= malloc(sizeof(*dv
));
7664 dv
->dev
= malloc(len
);
7669 update
->space
= NULL
;
7673 /* count how many spares will be converted to members */
7674 for (i
= 0; i
< map
->num_members
; i
++) {
7675 dl
= serial_to_dl(inf
[i
].serial
, super
);
7677 /* hmm maybe it failed?, nothing we can do about
7682 if (count_memberships(dl
, super
) == 0)
7685 len
+= activate
* sizeof(struct imsm_disk
);
7692 /* check if we need a larger metadata buffer */
7693 if (super
->next_buf
)
7694 buf_len
= super
->next_len
;
7696 buf_len
= super
->len
;
7698 if (__le32_to_cpu(mpb
->mpb_size
) + len
> buf_len
) {
7699 /* ok we need a larger buf than what is currently allocated
7700 * if this allocation fails process_update will notice that
7701 * ->next_len is set and ->next_buf is NULL
7703 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + len
, 512);
7704 if (super
->next_buf
)
7705 free(super
->next_buf
);
7707 super
->next_len
= buf_len
;
7708 if (posix_memalign(&super
->next_buf
, 512, buf_len
) == 0)
7709 memset(super
->next_buf
, 0, buf_len
);
7711 super
->next_buf
= NULL
;
7715 /* must be called while manager is quiesced */
7716 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
7718 struct imsm_super
*mpb
= super
->anchor
;
7720 struct imsm_dev
*dev
;
7721 struct imsm_map
*map
;
7722 int i
, j
, num_members
;
7725 dprintf("%s: deleting device[%d] from imsm_super\n",
7728 /* shift all indexes down one */
7729 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
7730 if (iter
->index
> (int)index
)
7732 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
7733 if (iter
->index
> (int)index
)
7736 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
7737 dev
= get_imsm_dev(super
, i
);
7738 map
= get_imsm_map(dev
, 0);
7739 num_members
= map
->num_members
;
7740 for (j
= 0; j
< num_members
; j
++) {
7741 /* update ord entries being careful not to propagate
7742 * ord-flags to the first map
7744 ord
= get_imsm_ord_tbl_ent(dev
, j
, -1);
7746 if (ord_to_idx(ord
) <= index
)
7749 map
= get_imsm_map(dev
, 0);
7750 set_imsm_ord_tbl_ent(map
, j
, ord_to_idx(ord
- 1));
7751 map
= get_imsm_map(dev
, 1);
7753 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
7758 super
->updates_pending
++;
7760 struct dl
*dl
= *dlp
;
7762 *dlp
= (*dlp
)->next
;
7763 __free_imsm_disk(dl
);
7766 #endif /* MDASSEMBLE */
7767 /*******************************************************************************
7768 * Function: open_backup_targets
7769 * Description: Function opens file descriptors for all devices given in
7772 * info : general array info
7773 * raid_disks : number of disks
7774 * raid_fds : table of device's file descriptors
7778 ******************************************************************************/
7779 int open_backup_targets(struct mdinfo
*info
, int raid_disks
, int *raid_fds
)
7783 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
7786 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
)) {
7787 dprintf("disk is faulty!!\n");
7791 if ((sd
->disk
.raid_disk
>= raid_disks
) ||
7792 (sd
->disk
.raid_disk
< 0))
7795 dn
= map_dev(sd
->disk
.major
,
7797 raid_fds
[sd
->disk
.raid_disk
] = dev_open(dn
, O_RDWR
);
7798 if (raid_fds
[sd
->disk
.raid_disk
] < 0) {
7799 fprintf(stderr
, "cannot open component\n");
7807 /*******************************************************************************
7808 * Function: init_migr_record_imsm
7809 * Description: Function inits imsm migration record
7811 * super : imsm internal array info
7812 * dev : device under migration
7813 * info : general array info to find the smallest device
7816 ******************************************************************************/
7817 void init_migr_record_imsm(struct supertype
*st
, struct imsm_dev
*dev
,
7818 struct mdinfo
*info
)
7820 struct intel_super
*super
= st
->sb
;
7821 struct migr_record
*migr_rec
= super
->migr_rec
;
7823 unsigned long long dsize
, dev_sectors
;
7824 long long unsigned min_dev_sectors
= -1LLU;
7828 struct imsm_map
*map_dest
= get_imsm_map(dev
, 0);
7829 struct imsm_map
*map_src
= get_imsm_map(dev
, 1);
7830 unsigned long long num_migr_units
;
7831 unsigned long long array_blocks
;
7833 memset(migr_rec
, 0, sizeof(struct migr_record
));
7834 migr_rec
->family_num
= __cpu_to_le32(super
->anchor
->family_num
);
7836 /* only ascending reshape supported now */
7837 migr_rec
->ascending_migr
= __cpu_to_le32(1);
7839 migr_rec
->dest_depth_per_unit
= GEN_MIGR_AREA_SIZE
/
7840 max(map_dest
->blocks_per_strip
, map_src
->blocks_per_strip
);
7841 migr_rec
->dest_depth_per_unit
*= map_dest
->blocks_per_strip
;
7842 new_data_disks
= imsm_num_data_members(dev
, 0);
7843 migr_rec
->blocks_per_unit
=
7844 __cpu_to_le32(migr_rec
->dest_depth_per_unit
* new_data_disks
);
7845 migr_rec
->dest_depth_per_unit
=
7846 __cpu_to_le32(migr_rec
->dest_depth_per_unit
);
7847 array_blocks
= info
->component_size
* new_data_disks
;
7849 array_blocks
/ __le32_to_cpu(migr_rec
->blocks_per_unit
);
7851 if (array_blocks
% __le32_to_cpu(migr_rec
->blocks_per_unit
))
7853 migr_rec
->num_migr_units
= __cpu_to_le32(num_migr_units
);
7855 migr_rec
->post_migr_vol_cap
= dev
->size_low
;
7856 migr_rec
->post_migr_vol_cap_hi
= dev
->size_high
;
7859 /* Find the smallest dev */
7860 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
7861 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
7862 fd
= dev_open(nm
, O_RDONLY
);
7865 get_dev_size(fd
, NULL
, &dsize
);
7866 dev_sectors
= dsize
/ 512;
7867 if (dev_sectors
< min_dev_sectors
)
7868 min_dev_sectors
= dev_sectors
;
7871 migr_rec
->ckpt_area_pba
= __cpu_to_le32(min_dev_sectors
-
7872 RAID_DISK_RESERVED_BLOCKS_IMSM_HI
);
7874 write_imsm_migr_rec(st
);
7879 /*******************************************************************************
7880 * Function: save_backup_imsm
7881 * Description: Function saves critical data stripes to Migration Copy Area
7882 * and updates the current migration unit status.
7883 * Use restore_stripes() to form a destination stripe,
7884 * and to write it to the Copy Area.
7886 * st : supertype information
7887 * dev : imsm device that backup is saved for
7888 * info : general array info
7889 * buf : input buffer
7890 * length : length of data to backup (blocks_per_unit)
7894 ******************************************************************************/
7895 int save_backup_imsm(struct supertype
*st
,
7896 struct imsm_dev
*dev
,
7897 struct mdinfo
*info
,
7902 struct intel_super
*super
= st
->sb
;
7903 unsigned long long *target_offsets
= NULL
;
7904 int *targets
= NULL
;
7906 struct imsm_map
*map_dest
= get_imsm_map(dev
, 0);
7907 int new_disks
= map_dest
->num_members
;
7908 int dest_layout
= 0;
7910 unsigned long long start
;
7911 int data_disks
= imsm_num_data_members(dev
, 0);
7913 targets
= malloc(new_disks
* sizeof(int));
7917 for (i
= 0; i
< new_disks
; i
++)
7920 target_offsets
= malloc(new_disks
* sizeof(unsigned long long));
7921 if (!target_offsets
)
7924 start
= info
->reshape_progress
* 512;
7925 for (i
= 0; i
< new_disks
; i
++) {
7926 target_offsets
[i
] = (unsigned long long)
7927 __le32_to_cpu(super
->migr_rec
->ckpt_area_pba
) * 512;
7928 /* move back copy area adderss, it will be moved forward
7929 * in restore_stripes() using start input variable
7931 target_offsets
[i
] -= start
/data_disks
;
7934 if (open_backup_targets(info
, new_disks
, targets
))
7937 dest_layout
= imsm_level_to_layout(map_dest
->raid_level
);
7938 dest_chunk
= __le16_to_cpu(map_dest
->blocks_per_strip
) * 512;
7940 if (restore_stripes(targets
, /* list of dest devices */
7941 target_offsets
, /* migration record offsets */
7944 map_dest
->raid_level
,
7946 -1, /* source backup file descriptor */
7947 0, /* input buf offset
7948 * always 0 buf is already offseted */
7952 fprintf(stderr
, Name
": Error restoring stripes\n");
7960 for (i
= 0; i
< new_disks
; i
++)
7961 if (targets
[i
] >= 0)
7965 free(target_offsets
);
7970 /*******************************************************************************
7971 * Function: save_checkpoint_imsm
7972 * Description: Function called for current unit status update
7973 * in the migration record. It writes it to disk.
7975 * super : imsm internal array info
7976 * info : general array info
7980 * 2: failure, means no valid migration record
7981 * / no general migration in progress /
7982 ******************************************************************************/
7983 int save_checkpoint_imsm(struct supertype
*st
, struct mdinfo
*info
, int state
)
7985 struct intel_super
*super
= st
->sb
;
7986 unsigned long long blocks_per_unit
;
7987 unsigned long long curr_migr_unit
;
7989 if (load_imsm_migr_rec(super
, info
) != 0) {
7990 dprintf("imsm: ERROR: Cannot read migration record "
7991 "for checkpoint save.\n");
7995 blocks_per_unit
= __le32_to_cpu(super
->migr_rec
->blocks_per_unit
);
7996 if (blocks_per_unit
== 0) {
7997 dprintf("imsm: no migration in progress.\n");
8000 curr_migr_unit
= info
->reshape_progress
/ blocks_per_unit
;
8001 /* check if array is alligned to copy area
8002 * if it is not alligned, add one to current migration unit value
8003 * this can happend on array reshape finish only
8005 if (info
->reshape_progress
% blocks_per_unit
)
8008 super
->migr_rec
->curr_migr_unit
=
8009 __cpu_to_le32(curr_migr_unit
);
8010 super
->migr_rec
->rec_status
= __cpu_to_le32(state
);
8011 super
->migr_rec
->dest_1st_member_lba
=
8012 __cpu_to_le32(curr_migr_unit
*
8013 __le32_to_cpu(super
->migr_rec
->dest_depth_per_unit
));
8014 if (write_imsm_migr_rec(st
) < 0) {
8015 dprintf("imsm: Cannot write migration record "
8016 "outside backup area\n");
8023 /*******************************************************************************
8024 * Function: recover_backup_imsm
8025 * Description: Function recovers critical data from the Migration Copy Area
8026 * while assembling an array.
8028 * super : imsm internal array info
8029 * info : general array info
8031 * 0 : success (or there is no data to recover)
8033 ******************************************************************************/
8034 int recover_backup_imsm(struct supertype
*st
, struct mdinfo
*info
)
8036 struct intel_super
*super
= st
->sb
;
8037 struct migr_record
*migr_rec
= super
->migr_rec
;
8038 struct imsm_map
*map_dest
= NULL
;
8039 struct intel_dev
*id
= NULL
;
8040 unsigned long long read_offset
;
8041 unsigned long long write_offset
;
8043 int *targets
= NULL
;
8044 int new_disks
, i
, err
;
8047 unsigned long curr_migr_unit
= __le32_to_cpu(migr_rec
->curr_migr_unit
);
8048 unsigned long num_migr_units
= __le32_to_cpu(migr_rec
->num_migr_units
);
8050 int skipped_disks
= 0;
8051 int max_degradation
;
8053 err
= sysfs_get_str(info
, NULL
, "array_state", (char *)buffer
, 20);
8057 /* recover data only during assemblation */
8058 if (strncmp(buffer
, "inactive", 8) != 0)
8060 /* no data to recover */
8061 if (__le32_to_cpu(migr_rec
->rec_status
) == UNIT_SRC_NORMAL
)
8063 if (curr_migr_unit
>= num_migr_units
)
8066 /* find device during reshape */
8067 for (id
= super
->devlist
; id
; id
= id
->next
)
8068 if (is_gen_migration(id
->dev
))
8073 map_dest
= get_imsm_map(id
->dev
, 0);
8074 new_disks
= map_dest
->num_members
;
8075 max_degradation
= new_disks
- imsm_num_data_members(id
->dev
, 0);
8077 read_offset
= (unsigned long long)
8078 __le32_to_cpu(migr_rec
->ckpt_area_pba
) * 512;
8080 write_offset
= ((unsigned long long)
8081 __le32_to_cpu(migr_rec
->dest_1st_member_lba
) +
8082 __le32_to_cpu(map_dest
->pba_of_lba0
)) * 512;
8084 unit_len
= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
8085 if (posix_memalign((void **)&buf
, 512, unit_len
) != 0)
8087 targets
= malloc(new_disks
* sizeof(int));
8091 open_backup_targets(info
, new_disks
, targets
);
8093 for (i
= 0; i
< new_disks
; i
++) {
8094 if (targets
[i
] < 0) {
8098 if (lseek64(targets
[i
], read_offset
, SEEK_SET
) < 0) {
8100 Name
": Cannot seek to block: %s\n",
8104 if ((unsigned)read(targets
[i
], buf
, unit_len
) != unit_len
) {
8106 Name
": Cannot read copy area block: %s\n",
8110 if (lseek64(targets
[i
], write_offset
, SEEK_SET
) < 0) {
8112 Name
": Cannot seek to block: %s\n",
8116 if ((unsigned)write(targets
[i
], buf
, unit_len
) != unit_len
) {
8118 Name
": Cannot restore block: %s\n",
8124 if (skipped_disks
> max_degradation
) {
8126 Name
": Cannot restore data from backup."
8127 " Too many failed disks\n");
8131 if (save_checkpoint_imsm(st
, info
, UNIT_SRC_NORMAL
)) {
8132 /* ignore error == 2, this can mean end of reshape here
8134 dprintf("imsm: Cannot write checkpoint to "
8135 "migration record (UNIT_SRC_NORMAL) during restart\n");
8141 for (i
= 0; i
< new_disks
; i
++)
8150 static char disk_by_path
[] = "/dev/disk/by-path/";
8152 static const char *imsm_get_disk_controller_domain(const char *path
)
8154 char disk_path
[PATH_MAX
];
8158 strncpy(disk_path
, disk_by_path
, PATH_MAX
- 1);
8159 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
8160 if (stat(disk_path
, &st
) == 0) {
8161 struct sys_dev
* hba
;
8164 path
= devt_to_devpath(st
.st_rdev
);
8167 hba
= find_disk_attached_hba(-1, path
);
8168 if (hba
&& hba
->type
== SYS_DEV_SAS
)
8170 else if (hba
&& hba
->type
== SYS_DEV_SATA
)
8174 dprintf("path: %s hba: %s attached: %s\n",
8175 path
, (hba
) ? hba
->path
: "NULL", drv
);
8183 static int imsm_find_array_minor_by_subdev(int subdev
, int container
, int *minor
)
8185 char subdev_name
[20];
8186 struct mdstat_ent
*mdstat
;
8188 sprintf(subdev_name
, "%d", subdev
);
8189 mdstat
= mdstat_by_subdev(subdev_name
, container
);
8193 *minor
= mdstat
->devnum
;
8194 free_mdstat(mdstat
);
8198 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
8199 struct geo_params
*geo
,
8200 int *old_raid_disks
)
8202 /* currently we only support increasing the number of devices
8203 * for a container. This increases the number of device for each
8204 * member array. They must all be RAID0 or RAID5.
8207 struct mdinfo
*info
, *member
;
8208 int devices_that_can_grow
= 0;
8210 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): "
8211 "st->devnum = (%i)\n",
8214 if (geo
->size
!= -1 ||
8215 geo
->level
!= UnSet
||
8216 geo
->layout
!= UnSet
||
8217 geo
->chunksize
!= 0 ||
8218 geo
->raid_disks
== UnSet
) {
8219 dprintf("imsm: Container operation is allowed for "
8220 "raid disks number change only.\n");
8224 info
= container_content_imsm(st
, NULL
);
8225 for (member
= info
; member
; member
= member
->next
) {
8229 dprintf("imsm: checking device_num: %i\n",
8230 member
->container_member
);
8232 if (geo
->raid_disks
<= member
->array
.raid_disks
) {
8233 /* we work on container for Online Capacity Expansion
8234 * only so raid_disks has to grow
8236 dprintf("imsm: for container operation raid disks "
8237 "increase is required\n");
8241 if ((info
->array
.level
!= 0) &&
8242 (info
->array
.level
!= 5)) {
8243 /* we cannot use this container with other raid level
8245 dprintf("imsm: for container operation wrong"
8246 " raid level (%i) detected\n",
8250 /* check for platform support
8251 * for this raid level configuration
8253 struct intel_super
*super
= st
->sb
;
8254 if (!is_raid_level_supported(super
->orom
,
8255 member
->array
.level
,
8257 dprintf("platform does not support raid%d with"
8261 geo
->raid_disks
> 1 ? "s" : "");
8264 /* check if component size is aligned to chunk size
8266 if (info
->component_size
%
8267 (info
->array
.chunk_size
/512)) {
8268 dprintf("Component size is not aligned to "
8274 if (*old_raid_disks
&&
8275 info
->array
.raid_disks
!= *old_raid_disks
)
8277 *old_raid_disks
= info
->array
.raid_disks
;
8279 /* All raid5 and raid0 volumes in container
8280 * have to be ready for Online Capacity Expansion
8281 * so they need to be assembled. We have already
8282 * checked that no recovery etc is happening.
8284 result
= imsm_find_array_minor_by_subdev(member
->container_member
,
8288 dprintf("imsm: cannot find array\n");
8291 devices_that_can_grow
++;
8294 if (!member
&& devices_that_can_grow
)
8298 dprintf("\tContainer operation allowed\n");
8300 dprintf("\tError: %i\n", ret_val
);
8305 /* Function: get_spares_for_grow
8306 * Description: Allocates memory and creates list of spare devices
8307 * avaliable in container. Checks if spare drive size is acceptable.
8308 * Parameters: Pointer to the supertype structure
8309 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
8312 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
8314 unsigned long long min_size
= min_acceptable_spare_size_imsm(st
);
8315 return container_choose_spares(st
, min_size
, NULL
, NULL
, NULL
, 0);
8318 /******************************************************************************
8319 * function: imsm_create_metadata_update_for_reshape
8320 * Function creates update for whole IMSM container.
8322 ******************************************************************************/
8323 static int imsm_create_metadata_update_for_reshape(
8324 struct supertype
*st
,
8325 struct geo_params
*geo
,
8327 struct imsm_update_reshape
**updatep
)
8329 struct intel_super
*super
= st
->sb
;
8330 struct imsm_super
*mpb
= super
->anchor
;
8331 int update_memory_size
= 0;
8332 struct imsm_update_reshape
*u
= NULL
;
8333 struct mdinfo
*spares
= NULL
;
8335 int delta_disks
= 0;
8338 dprintf("imsm_update_metadata_for_reshape(enter) raid_disks = %i\n",
8341 delta_disks
= geo
->raid_disks
- old_raid_disks
;
8343 /* size of all update data without anchor */
8344 update_memory_size
= sizeof(struct imsm_update_reshape
);
8346 /* now add space for spare disks that we need to add. */
8347 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
8349 u
= calloc(1, update_memory_size
);
8352 "cannot get memory for imsm_update_reshape update\n");
8355 u
->type
= update_reshape_container_disks
;
8356 u
->old_raid_disks
= old_raid_disks
;
8357 u
->new_raid_disks
= geo
->raid_disks
;
8359 /* now get spare disks list
8361 spares
= get_spares_for_grow(st
);
8364 || delta_disks
> spares
->array
.spare_disks
) {
8365 fprintf(stderr
, Name
": imsm: ERROR: Cannot get spare devices "
8366 "for %s.\n", geo
->dev_name
);
8371 /* we have got spares
8372 * update disk list in imsm_disk list table in anchor
8374 dprintf("imsm: %i spares are available.\n\n",
8375 spares
->array
.spare_disks
);
8378 for (i
= 0; i
< delta_disks
; i
++) {
8383 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
8385 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
8386 dl
->index
= mpb
->num_disks
;
8396 dprintf("imsm: reshape update preparation :");
8397 if (i
== delta_disks
) {
8400 return update_memory_size
;
8403 dprintf(" Error\n");
8408 /******************************************************************************
8409 * function: imsm_create_metadata_update_for_migration()
8410 * Creates update for IMSM array.
8412 ******************************************************************************/
8413 static int imsm_create_metadata_update_for_migration(
8414 struct supertype
*st
,
8415 struct geo_params
*geo
,
8416 struct imsm_update_reshape_migration
**updatep
)
8418 struct intel_super
*super
= st
->sb
;
8419 int update_memory_size
= 0;
8420 struct imsm_update_reshape_migration
*u
= NULL
;
8421 struct imsm_dev
*dev
;
8422 int previous_level
= -1;
8424 dprintf("imsm_create_metadata_update_for_migration(enter)"
8425 " New Level = %i\n", geo
->level
);
8427 /* size of all update data without anchor */
8428 update_memory_size
= sizeof(struct imsm_update_reshape_migration
);
8430 u
= calloc(1, update_memory_size
);
8432 dprintf("error: cannot get memory for "
8433 "imsm_create_metadata_update_for_migration\n");
8436 u
->type
= update_reshape_migration
;
8437 u
->subdev
= super
->current_vol
;
8438 u
->new_level
= geo
->level
;
8439 u
->new_layout
= geo
->layout
;
8440 u
->new_raid_disks
= u
->old_raid_disks
= geo
->raid_disks
;
8441 u
->new_disks
[0] = -1;
8442 u
->new_chunksize
= -1;
8444 dev
= get_imsm_dev(super
, u
->subdev
);
8446 struct imsm_map
*map
;
8448 map
= get_imsm_map(dev
, 0);
8450 int current_chunk_size
=
8451 __le16_to_cpu(map
->blocks_per_strip
) / 2;
8453 if (geo
->chunksize
!= current_chunk_size
) {
8454 u
->new_chunksize
= geo
->chunksize
/ 1024;
8456 "chunk size change from %i to %i\n",
8457 current_chunk_size
, u
->new_chunksize
);
8459 previous_level
= map
->raid_level
;
8462 if ((geo
->level
== 5) && (previous_level
== 0)) {
8463 struct mdinfo
*spares
= NULL
;
8465 u
->new_raid_disks
++;
8466 spares
= get_spares_for_grow(st
);
8467 if ((spares
== NULL
) || (spares
->array
.spare_disks
< 1)) {
8470 update_memory_size
= 0;
8471 dprintf("error: cannot get spare device "
8472 "for requested migration");
8477 dprintf("imsm: reshape update preparation : OK\n");
8480 return update_memory_size
;
8483 static void imsm_update_metadata_locally(struct supertype
*st
,
8486 struct metadata_update mu
;
8491 mu
.space_list
= NULL
;
8493 imsm_prepare_update(st
, &mu
);
8494 imsm_process_update(st
, &mu
);
8496 while (mu
.space_list
) {
8497 void **space
= mu
.space_list
;
8498 mu
.space_list
= *space
;
8503 /***************************************************************************
8504 * Function: imsm_analyze_change
8505 * Description: Function analyze change for single volume
8506 * and validate if transition is supported
8507 * Parameters: Geometry parameters, supertype structure
8508 * Returns: Operation type code on success, -1 if fail
8509 ****************************************************************************/
8510 enum imsm_reshape_type
imsm_analyze_change(struct supertype
*st
,
8511 struct geo_params
*geo
)
8518 getinfo_super_imsm_volume(st
, &info
, NULL
);
8519 if ((geo
->level
!= info
.array
.level
) &&
8520 (geo
->level
>= 0) &&
8521 (geo
->level
!= UnSet
)) {
8522 switch (info
.array
.level
) {
8524 if (geo
->level
== 5) {
8525 change
= CH_MIGRATION
;
8526 if (geo
->layout
!= ALGORITHM_LEFT_ASYMMETRIC
) {
8528 Name
" Error. Requested Layout "
8529 "not supported (left-asymmetric layout "
8530 "is supported only)!\n");
8532 goto analyse_change_exit
;
8536 if (geo
->level
== 10) {
8537 change
= CH_TAKEOVER
;
8542 if (geo
->level
== 0) {
8543 change
= CH_TAKEOVER
;
8548 if (geo
->level
== 0) {
8549 change
= CH_TAKEOVER
;
8556 Name
" Error. Level Migration from %d to %d "
8558 info
.array
.level
, geo
->level
);
8559 goto analyse_change_exit
;
8562 geo
->level
= info
.array
.level
;
8564 if ((geo
->layout
!= info
.array
.layout
)
8565 && ((geo
->layout
!= UnSet
) && (geo
->layout
!= -1))) {
8566 change
= CH_MIGRATION
;
8567 if ((info
.array
.layout
== 0)
8568 && (info
.array
.level
== 5)
8569 && (geo
->layout
== 5)) {
8570 /* reshape 5 -> 4 */
8571 } else if ((info
.array
.layout
== 5)
8572 && (info
.array
.level
== 5)
8573 && (geo
->layout
== 0)) {
8574 /* reshape 4 -> 5 */
8579 Name
" Error. Layout Migration from %d to %d "
8581 info
.array
.layout
, geo
->layout
);
8583 goto analyse_change_exit
;
8586 geo
->layout
= info
.array
.layout
;
8588 if ((geo
->chunksize
> 0) && (geo
->chunksize
!= UnSet
)
8589 && (geo
->chunksize
!= info
.array
.chunk_size
))
8590 change
= CH_MIGRATION
;
8592 geo
->chunksize
= info
.array
.chunk_size
;
8594 chunk
= geo
->chunksize
/ 1024;
8595 if (!validate_geometry_imsm(st
,
8605 struct intel_super
*super
= st
->sb
;
8606 struct imsm_super
*mpb
= super
->anchor
;
8608 if (mpb
->num_raid_devs
> 1) {
8610 Name
" Error. Cannot perform operation on %s"
8611 "- for this operation it MUST be single "
8612 "array in container\n",
8618 analyse_change_exit
:
8623 int imsm_takeover(struct supertype
*st
, struct geo_params
*geo
)
8625 struct intel_super
*super
= st
->sb
;
8626 struct imsm_update_takeover
*u
;
8628 u
= malloc(sizeof(struct imsm_update_takeover
));
8632 u
->type
= update_takeover
;
8633 u
->subarray
= super
->current_vol
;
8635 /* 10->0 transition */
8636 if (geo
->level
== 0)
8637 u
->direction
= R10_TO_R0
;
8639 /* 0->10 transition */
8640 if (geo
->level
== 10)
8641 u
->direction
= R0_TO_R10
;
8643 /* update metadata locally */
8644 imsm_update_metadata_locally(st
, u
,
8645 sizeof(struct imsm_update_takeover
));
8646 /* and possibly remotely */
8647 if (st
->update_tail
)
8648 append_metadata_update(st
, u
,
8649 sizeof(struct imsm_update_takeover
));
8656 static int imsm_reshape_super(struct supertype
*st
, long long size
, int level
,
8657 int layout
, int chunksize
, int raid_disks
,
8658 int delta_disks
, char *backup
, char *dev
,
8662 struct geo_params geo
;
8664 dprintf("imsm: reshape_super called.\n");
8666 memset(&geo
, 0, sizeof(struct geo_params
));
8669 geo
.dev_id
= st
->devnum
;
8672 geo
.layout
= layout
;
8673 geo
.chunksize
= chunksize
;
8674 geo
.raid_disks
= raid_disks
;
8675 if (delta_disks
!= UnSet
)
8676 geo
.raid_disks
+= delta_disks
;
8678 dprintf("\tfor level : %i\n", geo
.level
);
8679 dprintf("\tfor raid_disks : %i\n", geo
.raid_disks
);
8681 if (experimental() == 0)
8684 if (st
->container_dev
== st
->devnum
) {
8685 /* On container level we can only increase number of devices. */
8686 dprintf("imsm: info: Container operation\n");
8687 int old_raid_disks
= 0;
8689 if (imsm_reshape_is_allowed_on_container(
8690 st
, &geo
, &old_raid_disks
)) {
8691 struct imsm_update_reshape
*u
= NULL
;
8694 len
= imsm_create_metadata_update_for_reshape(
8695 st
, &geo
, old_raid_disks
, &u
);
8698 dprintf("imsm: Cannot prepare update\n");
8699 goto exit_imsm_reshape_super
;
8703 /* update metadata locally */
8704 imsm_update_metadata_locally(st
, u
, len
);
8705 /* and possibly remotely */
8706 if (st
->update_tail
)
8707 append_metadata_update(st
, u
, len
);
8712 fprintf(stderr
, Name
": (imsm) Operation "
8713 "is not allowed on this container\n");
8716 /* On volume level we support following operations
8717 * - takeover: raid10 -> raid0; raid0 -> raid10
8718 * - chunk size migration
8719 * - migration: raid5 -> raid0; raid0 -> raid5
8721 struct intel_super
*super
= st
->sb
;
8722 struct intel_dev
*dev
= super
->devlist
;
8724 dprintf("imsm: info: Volume operation\n");
8725 /* find requested device */
8727 if (imsm_find_array_minor_by_subdev(
8728 dev
->index
, st
->container_dev
, &devnum
) == 0
8729 && devnum
== geo
.dev_id
)
8734 fprintf(stderr
, Name
" Cannot find %s (%i) subarray\n",
8735 geo
.dev_name
, geo
.dev_id
);
8736 goto exit_imsm_reshape_super
;
8738 super
->current_vol
= dev
->index
;
8739 change
= imsm_analyze_change(st
, &geo
);
8742 ret_val
= imsm_takeover(st
, &geo
);
8744 case CH_MIGRATION
: {
8745 struct imsm_update_reshape_migration
*u
= NULL
;
8747 imsm_create_metadata_update_for_migration(
8751 "Cannot prepare update\n");
8755 /* update metadata locally */
8756 imsm_update_metadata_locally(st
, u
, len
);
8757 /* and possibly remotely */
8758 if (st
->update_tail
)
8759 append_metadata_update(st
, u
, len
);
8769 exit_imsm_reshape_super
:
8770 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
8774 /*******************************************************************************
8775 * Function: wait_for_reshape_imsm
8776 * Description: Function writes new sync_max value and waits until
8777 * reshape process reach new position
8779 * sra : general array info
8780 * ndata : number of disks in new array's layout
8783 * 1 : there is no reshape in progress,
8785 ******************************************************************************/
8786 int wait_for_reshape_imsm(struct mdinfo
*sra
, int ndata
)
8788 int fd
= sysfs_get_fd(sra
, NULL
, "reshape_position");
8789 unsigned long long completed
;
8790 /* to_complete : new sync_max position */
8791 unsigned long long to_complete
= sra
->reshape_progress
;
8792 unsigned long long position_to_set
= to_complete
/ ndata
;
8795 dprintf("imsm: wait_for_reshape_imsm() "
8796 "cannot open reshape_position\n");
8800 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
8801 dprintf("imsm: wait_for_reshape_imsm() "
8802 "cannot read reshape_position (no reshape in progres)\n");
8807 if (completed
> to_complete
) {
8808 dprintf("imsm: wait_for_reshape_imsm() "
8809 "wrong next position to set %llu (%llu)\n",
8810 to_complete
, completed
);
8814 dprintf("Position set: %llu\n", position_to_set
);
8815 if (sysfs_set_num(sra
, NULL
, "sync_max",
8816 position_to_set
) != 0) {
8817 dprintf("imsm: wait_for_reshape_imsm() "
8818 "cannot set reshape position to %llu\n",
8829 select(fd
+1, &rfds
, NULL
, NULL
, NULL
);
8830 if (sysfs_get_str(sra
, NULL
, "sync_action",
8832 strncmp(action
, "reshape", 7) != 0)
8834 if (sysfs_fd_get_ll(fd
, &completed
) < 0) {
8835 dprintf("imsm: wait_for_reshape_imsm() "
8836 "cannot read reshape_position (in loop)\n");
8840 } while (completed
< to_complete
);
8846 /*******************************************************************************
8847 * Function: check_degradation_change
8848 * Description: Check that array hasn't become failed.
8850 * info : for sysfs access
8851 * sources : source disks descriptors
8852 * degraded: previous degradation level
8855 ******************************************************************************/
8856 int check_degradation_change(struct mdinfo
*info
,
8860 unsigned long long new_degraded
;
8861 sysfs_get_ll(info
, NULL
, "degraded", &new_degraded
);
8862 if (new_degraded
!= (unsigned long long)degraded
) {
8863 /* check each device to ensure it is still working */
8866 for (sd
= info
->devs
; sd
; sd
= sd
->next
) {
8867 if (sd
->disk
.state
& (1<<MD_DISK_FAULTY
))
8869 if (sd
->disk
.state
& (1<<MD_DISK_SYNC
)) {
8871 if (sysfs_get_str(info
,
8872 sd
, "state", sbuf
, 20) < 0 ||
8873 strstr(sbuf
, "faulty") ||
8874 strstr(sbuf
, "in_sync") == NULL
) {
8875 /* this device is dead */
8876 sd
->disk
.state
= (1<<MD_DISK_FAULTY
);
8877 if (sd
->disk
.raid_disk
>= 0 &&
8878 sources
[sd
->disk
.raid_disk
] >= 0) {
8880 sd
->disk
.raid_disk
]);
8881 sources
[sd
->disk
.raid_disk
] =
8890 return new_degraded
;
8893 /*******************************************************************************
8894 * Function: imsm_manage_reshape
8895 * Description: Function finds array under reshape and it manages reshape
8896 * process. It creates stripes backups (if required) and sets
8899 * afd : Backup handle (nattive) - not used
8900 * sra : general array info
8901 * reshape : reshape parameters - not used
8902 * st : supertype structure
8903 * blocks : size of critical section [blocks]
8904 * fds : table of source device descriptor
8905 * offsets : start of array (offest per devices)
8907 * destfd : table of destination device descriptor
8908 * destoffsets : table of destination offsets (per device)
8910 * 1 : success, reshape is done
8912 ******************************************************************************/
8913 static int imsm_manage_reshape(
8914 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
8915 struct supertype
*st
, unsigned long backup_blocks
,
8916 int *fds
, unsigned long long *offsets
,
8917 int dests
, int *destfd
, unsigned long long *destoffsets
)
8920 struct intel_super
*super
= st
->sb
;
8921 struct intel_dev
*dv
= NULL
;
8922 struct imsm_dev
*dev
= NULL
;
8923 struct imsm_map
*map_src
;
8924 int migr_vol_qan
= 0;
8925 int ndata
, odata
; /* [bytes] */
8926 int chunk
; /* [bytes] */
8927 struct migr_record
*migr_rec
;
8929 unsigned int buf_size
; /* [bytes] */
8930 unsigned long long max_position
; /* array size [bytes] */
8931 unsigned long long next_step
; /* [blocks]/[bytes] */
8932 unsigned long long old_data_stripe_length
;
8933 unsigned long long start_src
; /* [bytes] */
8934 unsigned long long start
; /* [bytes] */
8935 unsigned long long start_buf_shift
; /* [bytes] */
8937 int source_layout
= 0;
8939 if (!fds
|| !offsets
|| !sra
)
8942 /* Find volume during the reshape */
8943 for (dv
= super
->devlist
; dv
; dv
= dv
->next
) {
8944 if (dv
->dev
->vol
.migr_type
== MIGR_GEN_MIGR
8945 && dv
->dev
->vol
.migr_state
== 1) {
8950 /* Only one volume can migrate at the same time */
8951 if (migr_vol_qan
!= 1) {
8952 fprintf(stderr
, Name
" : %s", migr_vol_qan
?
8953 "Number of migrating volumes greater than 1\n" :
8954 "There is no volume during migrationg\n");
8958 map_src
= get_imsm_map(dev
, 1);
8959 if (map_src
== NULL
)
8962 ndata
= imsm_num_data_members(dev
, 0);
8963 odata
= imsm_num_data_members(dev
, 1);
8965 chunk
= __le16_to_cpu(map_src
->blocks_per_strip
) * 512;
8966 old_data_stripe_length
= odata
* chunk
;
8968 migr_rec
= super
->migr_rec
;
8970 /* initialize migration record for start condition */
8971 if (sra
->reshape_progress
== 0)
8972 init_migr_record_imsm(st
, dev
, sra
);
8974 if (__le32_to_cpu(migr_rec
->rec_status
) != UNIT_SRC_NORMAL
) {
8975 dprintf("imsm: cannot restart migration when data "
8976 "are present in copy area.\n");
8982 buf_size
= __le32_to_cpu(migr_rec
->blocks_per_unit
) * 512;
8983 /* extend buffer size for parity disk */
8984 buf_size
+= __le32_to_cpu(migr_rec
->dest_depth_per_unit
) * 512;
8985 /* add space for stripe aligment */
8986 buf_size
+= old_data_stripe_length
;
8987 if (posix_memalign((void **)&buf
, 4096, buf_size
)) {
8988 dprintf("imsm: Cannot allocate checpoint buffer\n");
8992 max_position
= sra
->component_size
* ndata
;
8993 source_layout
= imsm_level_to_layout(map_src
->raid_level
);
8995 while (__le32_to_cpu(migr_rec
->curr_migr_unit
) <
8996 __le32_to_cpu(migr_rec
->num_migr_units
)) {
8997 /* current reshape position [blocks] */
8998 unsigned long long current_position
=
8999 __le32_to_cpu(migr_rec
->blocks_per_unit
)
9000 * __le32_to_cpu(migr_rec
->curr_migr_unit
);
9001 unsigned long long border
;
9003 /* Check that array hasn't become failed.
9005 degraded
= check_degradation_change(sra
, fds
, degraded
);
9007 dprintf("imsm: Abort reshape due to degradation"
9008 " level (%i)\n", degraded
);
9012 next_step
= __le32_to_cpu(migr_rec
->blocks_per_unit
);
9014 if ((current_position
+ next_step
) > max_position
)
9015 next_step
= max_position
- current_position
;
9017 start
= current_position
* 512;
9019 /* allign reading start to old geometry */
9020 start_buf_shift
= start
% old_data_stripe_length
;
9021 start_src
= start
- start_buf_shift
;
9023 border
= (start_src
/ odata
) - (start
/ ndata
);
9025 if (border
<= __le32_to_cpu(migr_rec
->dest_depth_per_unit
)) {
9026 /* save critical stripes to buf
9027 * start - start address of current unit
9029 * start_src - start address of current unit
9030 * to backup alligned to source array
9033 unsigned long long next_step_filler
= 0;
9034 unsigned long long copy_length
= next_step
* 512;
9036 /* allign copy area length to stripe in old geometry */
9037 next_step_filler
= ((copy_length
+ start_buf_shift
)
9038 % old_data_stripe_length
);
9039 if (next_step_filler
)
9040 next_step_filler
= (old_data_stripe_length
9041 - next_step_filler
);
9042 dprintf("save_stripes() parameters: start = %llu,"
9043 "\tstart_src = %llu,\tnext_step*512 = %llu,"
9044 "\tstart_in_buf_shift = %llu,"
9045 "\tnext_step_filler = %llu\n",
9046 start
, start_src
, copy_length
,
9047 start_buf_shift
, next_step_filler
);
9049 if (save_stripes(fds
, offsets
, map_src
->num_members
,
9050 chunk
, map_src
->raid_level
,
9051 source_layout
, 0, NULL
, start_src
,
9053 next_step_filler
+ start_buf_shift
,
9055 dprintf("imsm: Cannot save stripes"
9059 /* Convert data to destination format and store it
9060 * in backup general migration area
9062 if (save_backup_imsm(st
, dev
, sra
,
9063 buf
+ start_buf_shift
, copy_length
)) {
9064 dprintf("imsm: Cannot save stripes to "
9065 "target devices\n");
9068 if (save_checkpoint_imsm(st
, sra
,
9069 UNIT_SRC_IN_CP_AREA
)) {
9070 dprintf("imsm: Cannot write checkpoint to "
9071 "migration record (UNIT_SRC_IN_CP_AREA)\n");
9075 /* set next step to use whole border area */
9076 border
/= next_step
;
9078 next_step
*= border
;
9080 /* When data backed up, checkpoint stored,
9081 * kick the kernel to reshape unit of data
9083 next_step
= next_step
+ sra
->reshape_progress
;
9084 /* limit next step to array max position */
9085 if (next_step
> max_position
)
9086 next_step
= max_position
;
9087 sysfs_set_num(sra
, NULL
, "suspend_lo", sra
->reshape_progress
);
9088 sysfs_set_num(sra
, NULL
, "suspend_hi", next_step
);
9089 sra
->reshape_progress
= next_step
;
9091 /* wait until reshape finish */
9092 if (wait_for_reshape_imsm(sra
, ndata
) < 0) {
9093 dprintf("wait_for_reshape_imsm returned error!\n");
9097 if (save_checkpoint_imsm(st
, sra
, UNIT_SRC_NORMAL
) == 1) {
9098 /* ignore error == 2, this can mean end of reshape here
9100 dprintf("imsm: Cannot write checkpoint to "
9101 "migration record (UNIT_SRC_NORMAL)\n");
9107 /* return '1' if done */
9115 #endif /* MDASSEMBLE */
9117 struct superswitch super_imsm
= {
9119 .examine_super
= examine_super_imsm
,
9120 .brief_examine_super
= brief_examine_super_imsm
,
9121 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
9122 .export_examine_super
= export_examine_super_imsm
,
9123 .detail_super
= detail_super_imsm
,
9124 .brief_detail_super
= brief_detail_super_imsm
,
9125 .write_init_super
= write_init_super_imsm
,
9126 .validate_geometry
= validate_geometry_imsm
,
9127 .add_to_super
= add_to_super_imsm
,
9128 .remove_from_super
= remove_from_super_imsm
,
9129 .detail_platform
= detail_platform_imsm
,
9130 .kill_subarray
= kill_subarray_imsm
,
9131 .update_subarray
= update_subarray_imsm
,
9132 .load_container
= load_container_imsm
,
9133 .default_geometry
= default_geometry_imsm
,
9134 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
9135 .reshape_super
= imsm_reshape_super
,
9136 .manage_reshape
= imsm_manage_reshape
,
9137 .recover_backup
= recover_backup_imsm
,
9139 .match_home
= match_home_imsm
,
9140 .uuid_from_super
= uuid_from_super_imsm
,
9141 .getinfo_super
= getinfo_super_imsm
,
9142 .getinfo_super_disks
= getinfo_super_disks_imsm
,
9143 .update_super
= update_super_imsm
,
9145 .avail_size
= avail_size_imsm
,
9146 .min_acceptable_spare_size
= min_acceptable_spare_size_imsm
,
9148 .compare_super
= compare_super_imsm
,
9150 .load_super
= load_super_imsm
,
9151 .init_super
= init_super_imsm
,
9152 .store_super
= store_super_imsm
,
9153 .free_super
= free_super_imsm
,
9154 .match_metadata_desc
= match_metadata_desc_imsm
,
9155 .container_content
= container_content_imsm
,
9163 .open_new
= imsm_open_new
,
9164 .set_array_state
= imsm_set_array_state
,
9165 .set_disk
= imsm_set_disk
,
9166 .sync_metadata
= imsm_sync_metadata
,
9167 .activate_spare
= imsm_activate_spare
,
9168 .process_update
= imsm_process_update
,
9169 .prepare_update
= imsm_prepare_update
,
9170 #endif /* MDASSEMBLE */