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
44 #define MPB_ATTRIB_CHECKSUM_VERIFY __cpu_to_le32(0x80000000)
45 #define MPB_ATTRIB_PM __cpu_to_le32(0x40000000)
46 #define MPB_ATTRIB_2TB __cpu_to_le32(0x20000000)
47 #define MPB_ATTRIB_RAID0 __cpu_to_le32(0x00000001)
48 #define MPB_ATTRIB_RAID1 __cpu_to_le32(0x00000002)
49 #define MPB_ATTRIB_RAID10 __cpu_to_le32(0x00000004)
50 #define MPB_ATTRIB_RAID1E __cpu_to_le32(0x00000008)
51 #define MPB_ATTRIB_RAID5 __cpu_to_le32(0x00000010)
52 #define MPB_ATTRIB_RAIDCNG __cpu_to_le32(0x00000020)
54 #define MPB_SECTOR_CNT 418
55 #define IMSM_RESERVED_SECTORS 4096
56 #define SECT_PER_MB_SHIFT 11
58 /* Disk configuration info. */
59 #define IMSM_MAX_DEVICES 255
61 __u8 serial
[MAX_RAID_SERIAL_LEN
];/* 0xD8 - 0xE7 ascii serial number */
62 __u32 total_blocks
; /* 0xE8 - 0xEB total blocks */
63 __u32 scsi_id
; /* 0xEC - 0xEF scsi ID */
64 #define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
65 #define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
66 #define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
67 __u32 status
; /* 0xF0 - 0xF3 */
68 __u32 owner_cfg_num
; /* which config 0,1,2... owns this disk */
69 #define IMSM_DISK_FILLERS 4
70 __u32 filler
[IMSM_DISK_FILLERS
]; /* 0xF4 - 0x107 MPB_DISK_FILLERS for future expansion */
73 /* RAID map configuration infos. */
75 __u32 pba_of_lba0
; /* start address of partition */
76 __u32 blocks_per_member
;/* blocks per member */
77 __u32 num_data_stripes
; /* number of data stripes */
78 __u16 blocks_per_strip
;
79 __u8 map_state
; /* Normal, Uninitialized, Degraded, Failed */
80 #define IMSM_T_STATE_NORMAL 0
81 #define IMSM_T_STATE_UNINITIALIZED 1
82 #define IMSM_T_STATE_DEGRADED 2
83 #define IMSM_T_STATE_FAILED 3
85 #define IMSM_T_RAID0 0
86 #define IMSM_T_RAID1 1
87 #define IMSM_T_RAID5 5 /* since metadata version 1.2.02 ? */
88 __u8 num_members
; /* number of member disks */
89 __u8 num_domains
; /* number of parity domains */
90 __u8 failed_disk_num
; /* valid only when state is degraded */
92 __u32 filler
[7]; /* expansion area */
93 #define IMSM_ORD_REBUILD (1 << 24)
94 __u32 disk_ord_tbl
[1]; /* disk_ord_tbl[num_members],
95 * top byte contains some flags
97 } __attribute__ ((packed
));
100 __u32 curr_migr_unit
;
101 __u32 checkpoint_id
; /* id to access curr_migr_unit */
102 __u8 migr_state
; /* Normal or Migrating */
104 #define MIGR_REBUILD 1
105 #define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
106 #define MIGR_GEN_MIGR 3
107 #define MIGR_STATE_CHANGE 4
108 #define MIGR_REPAIR 5
109 __u8 migr_type
; /* Initializing, Rebuilding, ... */
111 __u8 fs_state
; /* fast-sync state for CnG (0xff == disabled) */
112 __u16 verify_errors
; /* number of mismatches */
113 __u16 bad_blocks
; /* number of bad blocks during verify */
115 struct imsm_map map
[1];
116 /* here comes another one if migr_state */
117 } __attribute__ ((packed
));
120 __u8 volume
[MAX_RAID_SERIAL_LEN
];
123 #define DEV_BOOTABLE __cpu_to_le32(0x01)
124 #define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
125 #define DEV_READ_COALESCING __cpu_to_le32(0x04)
126 #define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
127 #define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
128 #define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
129 #define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
130 #define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
131 #define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
132 #define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
133 #define DEV_CLONE_N_GO __cpu_to_le32(0x400)
134 #define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
135 #define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
136 __u32 status
; /* Persistent RaidDev status */
137 __u32 reserved_blocks
; /* Reserved blocks at beginning of volume */
141 __u8 cng_master_disk
;
145 #define IMSM_DEV_FILLERS 10
146 __u32 filler
[IMSM_DEV_FILLERS
];
148 } __attribute__ ((packed
));
151 __u8 sig
[MAX_SIGNATURE_LENGTH
]; /* 0x00 - 0x1F */
152 __u32 check_sum
; /* 0x20 - 0x23 MPB Checksum */
153 __u32 mpb_size
; /* 0x24 - 0x27 Size of MPB */
154 __u32 family_num
; /* 0x28 - 0x2B Checksum from first time this config was written */
155 __u32 generation_num
; /* 0x2C - 0x2F Incremented each time this array's MPB is written */
156 __u32 error_log_size
; /* 0x30 - 0x33 in bytes */
157 __u32 attributes
; /* 0x34 - 0x37 */
158 __u8 num_disks
; /* 0x38 Number of configured disks */
159 __u8 num_raid_devs
; /* 0x39 Number of configured volumes */
160 __u8 error_log_pos
; /* 0x3A */
161 __u8 fill
[1]; /* 0x3B */
162 __u32 cache_size
; /* 0x3c - 0x40 in mb */
163 __u32 orig_family_num
; /* 0x40 - 0x43 original family num */
164 __u32 pwr_cycle_count
; /* 0x44 - 0x47 simulated power cycle count for array */
165 __u32 bbm_log_size
; /* 0x48 - 0x4B - size of bad Block Mgmt Log in bytes */
166 #define IMSM_FILLERS 35
167 __u32 filler
[IMSM_FILLERS
]; /* 0x4C - 0xD7 RAID_MPB_FILLERS */
168 struct imsm_disk disk
[1]; /* 0xD8 diskTbl[numDisks] */
169 /* here comes imsm_dev[num_raid_devs] */
170 /* here comes BBM logs */
171 } __attribute__ ((packed
));
173 #define BBM_LOG_MAX_ENTRIES 254
175 struct bbm_log_entry
{
176 __u64 defective_block_start
;
177 #define UNREADABLE 0xFFFFFFFF
178 __u32 spare_block_offset
;
179 __u16 remapped_marked_count
;
181 } __attribute__ ((__packed__
));
184 __u32 signature
; /* 0xABADB10C */
186 __u32 reserved_spare_block_count
; /* 0 */
187 __u32 reserved
; /* 0xFFFF */
188 __u64 first_spare_lba
;
189 struct bbm_log_entry mapped_block_entries
[BBM_LOG_MAX_ENTRIES
];
190 } __attribute__ ((__packed__
));
194 static char *map_state_str
[] = { "normal", "uninitialized", "degraded", "failed" };
197 static __u8
migr_type(struct imsm_dev
*dev
)
199 if (dev
->vol
.migr_type
== MIGR_VERIFY
&&
200 dev
->status
& DEV_VERIFY_AND_FIX
)
203 return dev
->vol
.migr_type
;
206 static void set_migr_type(struct imsm_dev
*dev
, __u8 migr_type
)
208 /* for compatibility with older oroms convert MIGR_REPAIR, into
209 * MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status
211 if (migr_type
== MIGR_REPAIR
) {
212 dev
->vol
.migr_type
= MIGR_VERIFY
;
213 dev
->status
|= DEV_VERIFY_AND_FIX
;
215 dev
->vol
.migr_type
= migr_type
;
216 dev
->status
&= ~DEV_VERIFY_AND_FIX
;
220 static unsigned int sector_count(__u32 bytes
)
222 return ((bytes
+ (512-1)) & (~(512-1))) / 512;
225 static unsigned int mpb_sectors(struct imsm_super
*mpb
)
227 return sector_count(__le32_to_cpu(mpb
->mpb_size
));
231 struct imsm_dev
*dev
;
232 struct intel_dev
*next
;
237 enum sys_dev_type type
;
240 struct intel_hba
*next
;
247 /* internal representation of IMSM metadata */
250 void *buf
; /* O_DIRECT buffer for reading/writing metadata */
251 struct imsm_super
*anchor
; /* immovable parameters */
253 size_t len
; /* size of the 'buf' allocation */
254 void *next_buf
; /* for realloc'ing buf from the manager */
256 int updates_pending
; /* count of pending updates for mdmon */
257 int current_vol
; /* index of raid device undergoing creation */
258 __u32 create_offset
; /* common start for 'current_vol' */
259 __u32 random
; /* random data for seeding new family numbers */
260 struct intel_dev
*devlist
;
264 __u8 serial
[MAX_RAID_SERIAL_LEN
];
267 struct imsm_disk disk
;
270 struct extent
*e
; /* for determining freespace @ create */
271 int raiddisk
; /* slot to fill in autolayout */
274 struct dl
*disk_mgmt_list
; /* list of disks to add/remove while mdmon
276 struct dl
*missing
; /* disks removed while we weren't looking */
277 struct bbm_log
*bbm_log
;
278 struct intel_hba
*hba
; /* device path of the raid controller for this metadata */
279 const struct imsm_orom
*orom
; /* platform firmware support */
280 struct intel_super
*next
; /* (temp) list for disambiguating family_num */
284 struct imsm_disk disk
;
285 #define IMSM_UNKNOWN_OWNER (-1)
287 struct intel_disk
*next
;
291 unsigned long long start
, size
;
294 /* definitions of reshape process types */
295 enum imsm_reshape_type
{
300 /* definition of messages passed to imsm_process_update */
301 enum imsm_update_type
{
302 update_activate_spare
,
306 update_add_remove_disk
,
307 update_reshape_container_disks
,
308 update_reshape_migration
,
312 struct imsm_update_activate_spare
{
313 enum imsm_update_type type
;
317 struct imsm_update_activate_spare
*next
;
330 enum takeover_direction
{
334 struct imsm_update_takeover
{
335 enum imsm_update_type type
;
337 enum takeover_direction direction
;
340 struct imsm_update_reshape
{
341 enum imsm_update_type type
;
345 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
348 struct imsm_update_reshape_migration
{
349 enum imsm_update_type type
;
352 /* fields for array migration changes
358 int new_disks
[1]; /* new_raid_disks - old_raid_disks makedev number */
362 __u8 serial
[MAX_RAID_SERIAL_LEN
];
365 struct imsm_update_create_array
{
366 enum imsm_update_type type
;
371 struct imsm_update_kill_array
{
372 enum imsm_update_type type
;
376 struct imsm_update_rename_array
{
377 enum imsm_update_type type
;
378 __u8 name
[MAX_RAID_SERIAL_LEN
];
382 struct imsm_update_add_remove_disk
{
383 enum imsm_update_type type
;
387 static const char *_sys_dev_type
[] = {
388 [SYS_DEV_UNKNOWN
] = "Unknown",
389 [SYS_DEV_SAS
] = "SAS",
390 [SYS_DEV_SATA
] = "SATA"
393 const char *get_sys_dev_type(enum sys_dev_type type
)
395 if (type
>= SYS_DEV_MAX
)
396 type
= SYS_DEV_UNKNOWN
;
398 return _sys_dev_type
[type
];
401 static struct intel_hba
* alloc_intel_hba(struct sys_dev
*device
)
403 struct intel_hba
*result
= malloc(sizeof(*result
));
405 result
->type
= device
->type
;
406 result
->path
= strdup(device
->path
);
408 if (result
->path
&& (result
->pci_id
= strrchr(result
->path
, '/')) != NULL
)
414 static struct intel_hba
* find_intel_hba(struct intel_hba
*hba
, struct sys_dev
*device
)
416 struct intel_hba
*result
=NULL
;
417 for (result
= hba
; result
; result
= result
->next
) {
418 if (result
->type
== device
->type
&& strcmp(result
->path
, device
->path
) == 0)
424 static int attach_hba_to_super(struct intel_super
*super
, struct sys_dev
*device
)
426 struct intel_hba
*hba
;
428 /* check if disk attached to Intel HBA */
429 hba
= find_intel_hba(super
->hba
, device
);
432 /* Check if HBA is already attached to super */
433 if (super
->hba
== NULL
) {
434 super
->hba
= alloc_intel_hba(device
);
439 /* Intel metadata allows for all disks attached to the same type HBA.
440 * Do not sypport odf HBA types mixing
442 if (device
->type
!= hba
->type
)
448 hba
->next
= alloc_intel_hba(device
);
452 static struct sys_dev
* find_disk_attached_hba(int fd
, const char *devname
)
454 struct sys_dev
*list
, *elem
, *prev
;
457 if ((list
= find_intel_devices()) == NULL
)
461 disk_path
= (char *) devname
;
463 disk_path
= diskfd_to_devpath(fd
);
470 for (prev
= NULL
, elem
= list
; elem
; prev
= elem
, elem
= elem
->next
) {
471 if (path_attached_to_hba(disk_path
, elem
->path
)) {
475 prev
->next
= elem
->next
;
477 if (disk_path
!= devname
)
483 if (disk_path
!= devname
)
491 static int find_intel_hba_capability(int fd
, struct intel_super
*super
,
494 static struct supertype
*match_metadata_desc_imsm(char *arg
)
496 struct supertype
*st
;
498 if (strcmp(arg
, "imsm") != 0 &&
499 strcmp(arg
, "default") != 0
503 st
= malloc(sizeof(*st
));
506 memset(st
, 0, sizeof(*st
));
507 st
->container_dev
= NoMdDev
;
508 st
->ss
= &super_imsm
;
509 st
->max_devs
= IMSM_MAX_DEVICES
;
510 st
->minor_version
= 0;
516 static __u8
*get_imsm_version(struct imsm_super
*mpb
)
518 return &mpb
->sig
[MPB_SIG_LEN
];
522 /* retrieve a disk directly from the anchor when the anchor is known to be
523 * up-to-date, currently only at load time
525 static struct imsm_disk
*__get_imsm_disk(struct imsm_super
*mpb
, __u8 index
)
527 if (index
>= mpb
->num_disks
)
529 return &mpb
->disk
[index
];
532 /* retrieve the disk description based on a index of the disk
535 static struct dl
*get_imsm_dl_disk(struct intel_super
*super
, __u8 index
)
539 for (d
= super
->disks
; d
; d
= d
->next
)
540 if (d
->index
== index
)
545 /* retrieve a disk from the parsed metadata */
546 static struct imsm_disk
*get_imsm_disk(struct intel_super
*super
, __u8 index
)
550 dl
= get_imsm_dl_disk(super
, index
);
557 /* generate a checksum directly from the anchor when the anchor is known to be
558 * up-to-date, currently only at load or write_super after coalescing
560 static __u32
__gen_imsm_checksum(struct imsm_super
*mpb
)
562 __u32 end
= mpb
->mpb_size
/ sizeof(end
);
563 __u32
*p
= (__u32
*) mpb
;
567 sum
+= __le32_to_cpu(*p
);
571 return sum
- __le32_to_cpu(mpb
->check_sum
);
574 static size_t sizeof_imsm_map(struct imsm_map
*map
)
576 return sizeof(struct imsm_map
) + sizeof(__u32
) * (map
->num_members
- 1);
579 struct imsm_map
*get_imsm_map(struct imsm_dev
*dev
, int second_map
)
581 /* A device can have 2 maps if it is in the middle of a migration.
583 * 0 - we return the first map
584 * 1 - we return the second map if it exists, else NULL
585 * -1 - we return the second map if it exists, else the first
587 struct imsm_map
*map
= &dev
->vol
.map
[0];
589 if (second_map
== 1 && !dev
->vol
.migr_state
)
591 else if (second_map
== 1 ||
592 (second_map
< 0 && dev
->vol
.migr_state
)) {
595 return ptr
+ sizeof_imsm_map(map
);
601 /* return the size of the device.
602 * migr_state increases the returned size if map[0] were to be duplicated
604 static size_t sizeof_imsm_dev(struct imsm_dev
*dev
, int migr_state
)
606 size_t size
= sizeof(*dev
) - sizeof(struct imsm_map
) +
607 sizeof_imsm_map(get_imsm_map(dev
, 0));
609 /* migrating means an additional map */
610 if (dev
->vol
.migr_state
)
611 size
+= sizeof_imsm_map(get_imsm_map(dev
, 1));
613 size
+= sizeof_imsm_map(get_imsm_map(dev
, 0));
619 /* retrieve disk serial number list from a metadata update */
620 static struct disk_info
*get_disk_info(struct imsm_update_create_array
*update
)
623 struct disk_info
*inf
;
625 inf
= u
+ sizeof(*update
) - sizeof(struct imsm_dev
) +
626 sizeof_imsm_dev(&update
->dev
, 0);
632 static struct imsm_dev
*__get_imsm_dev(struct imsm_super
*mpb
, __u8 index
)
638 if (index
>= mpb
->num_raid_devs
)
641 /* devices start after all disks */
642 offset
= ((void *) &mpb
->disk
[mpb
->num_disks
]) - _mpb
;
644 for (i
= 0; i
<= index
; i
++)
646 return _mpb
+ offset
;
648 offset
+= sizeof_imsm_dev(_mpb
+ offset
, 0);
653 static struct imsm_dev
*get_imsm_dev(struct intel_super
*super
, __u8 index
)
655 struct intel_dev
*dv
;
657 if (index
>= super
->anchor
->num_raid_devs
)
659 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
660 if (dv
->index
== index
)
668 * == 1 get second map
669 * == -1 than get map according to the current migr_state
671 static __u32
get_imsm_ord_tbl_ent(struct imsm_dev
*dev
,
675 struct imsm_map
*map
;
677 map
= get_imsm_map(dev
, second_map
);
679 /* top byte identifies disk under rebuild */
680 return __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
683 #define ord_to_idx(ord) (((ord) << 8) >> 8)
684 static __u32
get_imsm_disk_idx(struct imsm_dev
*dev
, int slot
, int second_map
)
686 __u32 ord
= get_imsm_ord_tbl_ent(dev
, slot
, second_map
);
688 return ord_to_idx(ord
);
691 static void set_imsm_ord_tbl_ent(struct imsm_map
*map
, int slot
, __u32 ord
)
693 map
->disk_ord_tbl
[slot
] = __cpu_to_le32(ord
);
696 static int get_imsm_disk_slot(struct imsm_map
*map
, unsigned idx
)
701 for (slot
= 0; slot
< map
->num_members
; slot
++) {
702 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
703 if (ord_to_idx(ord
) == idx
)
710 static int get_imsm_raid_level(struct imsm_map
*map
)
712 if (map
->raid_level
== 1) {
713 if (map
->num_members
== 2)
719 return map
->raid_level
;
722 static int cmp_extent(const void *av
, const void *bv
)
724 const struct extent
*a
= av
;
725 const struct extent
*b
= bv
;
726 if (a
->start
< b
->start
)
728 if (a
->start
> b
->start
)
733 static int count_memberships(struct dl
*dl
, struct intel_super
*super
)
738 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
739 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
740 struct imsm_map
*map
= get_imsm_map(dev
, 0);
742 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
749 static struct extent
*get_extents(struct intel_super
*super
, struct dl
*dl
)
751 /* find a list of used extents on the given physical device */
752 struct extent
*rv
, *e
;
754 int memberships
= count_memberships(dl
, super
);
755 __u32 reservation
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
757 rv
= malloc(sizeof(struct extent
) * (memberships
+ 1));
762 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
763 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
764 struct imsm_map
*map
= get_imsm_map(dev
, 0);
766 if (get_imsm_disk_slot(map
, dl
->index
) >= 0) {
767 e
->start
= __le32_to_cpu(map
->pba_of_lba0
);
768 e
->size
= __le32_to_cpu(map
->blocks_per_member
);
772 qsort(rv
, memberships
, sizeof(*rv
), cmp_extent
);
774 /* determine the start of the metadata
775 * when no raid devices are defined use the default
776 * ...otherwise allow the metadata to truncate the value
777 * as is the case with older versions of imsm
780 struct extent
*last
= &rv
[memberships
- 1];
783 remainder
= __le32_to_cpu(dl
->disk
.total_blocks
) -
784 (last
->start
+ last
->size
);
785 /* round down to 1k block to satisfy precision of the kernel
789 /* make sure remainder is still sane */
790 if (remainder
< (unsigned)ROUND_UP(super
->len
, 512) >> 9)
791 remainder
= ROUND_UP(super
->len
, 512) >> 9;
792 if (reservation
> remainder
)
793 reservation
= remainder
;
795 e
->start
= __le32_to_cpu(dl
->disk
.total_blocks
) - reservation
;
800 /* try to determine how much space is reserved for metadata from
801 * the last get_extents() entry, otherwise fallback to the
804 static __u32
imsm_reserved_sectors(struct intel_super
*super
, struct dl
*dl
)
810 /* for spares just return a minimal reservation which will grow
811 * once the spare is picked up by an array
814 return MPB_SECTOR_CNT
;
816 e
= get_extents(super
, dl
);
818 return MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
820 /* scroll to last entry */
821 for (i
= 0; e
[i
].size
; i
++)
824 rv
= __le32_to_cpu(dl
->disk
.total_blocks
) - e
[i
].start
;
831 static int is_spare(struct imsm_disk
*disk
)
833 return (disk
->status
& SPARE_DISK
) == SPARE_DISK
;
836 static int is_configured(struct imsm_disk
*disk
)
838 return (disk
->status
& CONFIGURED_DISK
) == CONFIGURED_DISK
;
841 static int is_failed(struct imsm_disk
*disk
)
843 return (disk
->status
& FAILED_DISK
) == FAILED_DISK
;
846 /* Return minimum size of a spare that can be used in this array*/
847 static unsigned long long min_acceptable_spare_size_imsm(struct supertype
*st
)
849 struct intel_super
*super
= st
->sb
;
853 unsigned long long rv
= 0;
857 /* find first active disk in array */
859 while (dl
&& (is_failed(&dl
->disk
) || dl
->index
== -1))
863 /* find last lba used by subarrays */
864 e
= get_extents(super
, dl
);
867 for (i
= 0; e
[i
].size
; i
++)
870 rv
= e
[i
-1].start
+ e
[i
-1].size
;
872 /* add the amount of space needed for metadata */
873 rv
= rv
+ MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
878 static __u64
blocks_per_migr_unit(struct imsm_dev
*dev
);
880 static void print_imsm_dev(struct imsm_dev
*dev
, char *uuid
, int disk_idx
)
884 struct imsm_map
*map
= get_imsm_map(dev
, 0);
885 struct imsm_map
*map2
= get_imsm_map(dev
, 1);
889 printf("[%.16s]:\n", dev
->volume
);
890 printf(" UUID : %s\n", uuid
);
891 printf(" RAID Level : %d", get_imsm_raid_level(map
));
893 printf(" <-- %d", get_imsm_raid_level(map2
));
895 printf(" Members : %d", map
->num_members
);
897 printf(" <-- %d", map2
->num_members
);
899 printf(" Slots : [");
900 for (i
= 0; i
< map
->num_members
; i
++) {
901 ord
= get_imsm_ord_tbl_ent(dev
, i
, 0);
902 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
907 for (i
= 0; i
< map2
->num_members
; i
++) {
908 ord
= get_imsm_ord_tbl_ent(dev
, i
, 1);
909 printf("%s", ord
& IMSM_ORD_REBUILD
? "_" : "U");
914 printf(" Failed disk : ");
915 if (map
->failed_disk_num
== 0xff)
918 printf("%i", map
->failed_disk_num
);
920 slot
= get_imsm_disk_slot(map
, disk_idx
);
922 ord
= get_imsm_ord_tbl_ent(dev
, slot
, -1);
923 printf(" This Slot : %d%s\n", slot
,
924 ord
& IMSM_ORD_REBUILD
? " (out-of-sync)" : "");
926 printf(" This Slot : ?\n");
927 sz
= __le32_to_cpu(dev
->size_high
);
929 sz
+= __le32_to_cpu(dev
->size_low
);
930 printf(" Array Size : %llu%s\n", (unsigned long long)sz
,
931 human_size(sz
* 512));
932 sz
= __le32_to_cpu(map
->blocks_per_member
);
933 printf(" Per Dev Size : %llu%s\n", (unsigned long long)sz
,
934 human_size(sz
* 512));
935 printf(" Sector Offset : %u\n",
936 __le32_to_cpu(map
->pba_of_lba0
));
937 printf(" Num Stripes : %u\n",
938 __le32_to_cpu(map
->num_data_stripes
));
939 printf(" Chunk Size : %u KiB",
940 __le16_to_cpu(map
->blocks_per_strip
) / 2);
942 printf(" <-- %u KiB",
943 __le16_to_cpu(map2
->blocks_per_strip
) / 2);
945 printf(" Reserved : %d\n", __le32_to_cpu(dev
->reserved_blocks
));
946 printf(" Migrate State : ");
947 if (dev
->vol
.migr_state
) {
948 if (migr_type(dev
) == MIGR_INIT
)
949 printf("initialize\n");
950 else if (migr_type(dev
) == MIGR_REBUILD
)
952 else if (migr_type(dev
) == MIGR_VERIFY
)
954 else if (migr_type(dev
) == MIGR_GEN_MIGR
)
955 printf("general migration\n");
956 else if (migr_type(dev
) == MIGR_STATE_CHANGE
)
957 printf("state change\n");
958 else if (migr_type(dev
) == MIGR_REPAIR
)
961 printf("<unknown:%d>\n", migr_type(dev
));
964 printf(" Map State : %s", map_state_str
[map
->map_state
]);
965 if (dev
->vol
.migr_state
) {
966 struct imsm_map
*map
= get_imsm_map(dev
, 1);
968 printf(" <-- %s", map_state_str
[map
->map_state
]);
969 printf("\n Checkpoint : %u (%llu)",
970 __le32_to_cpu(dev
->vol
.curr_migr_unit
),
971 (unsigned long long)blocks_per_migr_unit(dev
));
974 printf(" Dirty State : %s\n", dev
->vol
.dirty
? "dirty" : "clean");
977 static void print_imsm_disk(struct imsm_super
*mpb
, int index
, __u32 reserved
)
979 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, index
);
980 char str
[MAX_RAID_SERIAL_LEN
+ 1];
983 if (index
< 0 || !disk
)
987 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
988 printf(" Disk%02d Serial : %s\n", index
, str
);
989 printf(" State :%s%s%s\n", is_spare(disk
) ? " spare" : "",
990 is_configured(disk
) ? " active" : "",
991 is_failed(disk
) ? " failed" : "");
992 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
993 sz
= __le32_to_cpu(disk
->total_blocks
) - reserved
;
994 printf(" Usable Size : %llu%s\n", (unsigned long long)sz
,
995 human_size(sz
* 512));
998 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
);
1000 static void examine_super_imsm(struct supertype
*st
, char *homehost
)
1002 struct intel_super
*super
= st
->sb
;
1003 struct imsm_super
*mpb
= super
->anchor
;
1004 char str
[MAX_SIGNATURE_LENGTH
];
1009 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
1012 snprintf(str
, MPB_SIG_LEN
, "%s", mpb
->sig
);
1013 printf(" Magic : %s\n", str
);
1014 snprintf(str
, strlen(MPB_VERSION_RAID0
), "%s", get_imsm_version(mpb
));
1015 printf(" Version : %s\n", get_imsm_version(mpb
));
1016 printf(" Orig Family : %08x\n", __le32_to_cpu(mpb
->orig_family_num
));
1017 printf(" Family : %08x\n", __le32_to_cpu(mpb
->family_num
));
1018 printf(" Generation : %08x\n", __le32_to_cpu(mpb
->generation_num
));
1019 getinfo_super_imsm(st
, &info
, NULL
);
1020 fname_from_uuid(st
, &info
, nbuf
, ':');
1021 printf(" UUID : %s\n", nbuf
+ 5);
1022 sum
= __le32_to_cpu(mpb
->check_sum
);
1023 printf(" Checksum : %08x %s\n", sum
,
1024 __gen_imsm_checksum(mpb
) == sum
? "correct" : "incorrect");
1025 printf(" MPB Sectors : %d\n", mpb_sectors(mpb
));
1026 printf(" Disks : %d\n", mpb
->num_disks
);
1027 printf(" RAID Devices : %d\n", mpb
->num_raid_devs
);
1028 print_imsm_disk(mpb
, super
->disks
->index
, reserved
);
1029 if (super
->bbm_log
) {
1030 struct bbm_log
*log
= super
->bbm_log
;
1033 printf("Bad Block Management Log:\n");
1034 printf(" Log Size : %d\n", __le32_to_cpu(mpb
->bbm_log_size
));
1035 printf(" Signature : %x\n", __le32_to_cpu(log
->signature
));
1036 printf(" Entry Count : %d\n", __le32_to_cpu(log
->entry_count
));
1037 printf(" Spare Blocks : %d\n", __le32_to_cpu(log
->reserved_spare_block_count
));
1038 printf(" First Spare : %llx\n",
1039 (unsigned long long) __le64_to_cpu(log
->first_spare_lba
));
1041 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
1043 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
1045 super
->current_vol
= i
;
1046 getinfo_super_imsm(st
, &info
, NULL
);
1047 fname_from_uuid(st
, &info
, nbuf
, ':');
1048 print_imsm_dev(dev
, nbuf
+ 5, super
->disks
->index
);
1050 for (i
= 0; i
< mpb
->num_disks
; i
++) {
1051 if (i
== super
->disks
->index
)
1053 print_imsm_disk(mpb
, i
, reserved
);
1055 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
1056 struct imsm_disk
*disk
;
1057 char str
[MAX_RAID_SERIAL_LEN
+ 1];
1065 snprintf(str
, MAX_RAID_SERIAL_LEN
+ 1, "%s", disk
->serial
);
1066 printf(" Disk Serial : %s\n", str
);
1067 printf(" State :%s%s%s\n", is_spare(disk
) ? " spare" : "",
1068 is_configured(disk
) ? " active" : "",
1069 is_failed(disk
) ? " failed" : "");
1070 printf(" Id : %08x\n", __le32_to_cpu(disk
->scsi_id
));
1071 sz
= __le32_to_cpu(disk
->total_blocks
) - reserved
;
1072 printf(" Usable Size : %llu%s\n", (unsigned long long)sz
,
1073 human_size(sz
* 512));
1077 static void brief_examine_super_imsm(struct supertype
*st
, int verbose
)
1079 /* We just write a generic IMSM ARRAY entry */
1082 struct intel_super
*super
= st
->sb
;
1084 if (!super
->anchor
->num_raid_devs
) {
1085 printf("ARRAY metadata=imsm\n");
1089 getinfo_super_imsm(st
, &info
, NULL
);
1090 fname_from_uuid(st
, &info
, nbuf
, ':');
1091 printf("ARRAY metadata=imsm UUID=%s\n", nbuf
+ 5);
1094 static void brief_examine_subarrays_imsm(struct supertype
*st
, int verbose
)
1096 /* We just write a generic IMSM ARRAY entry */
1100 struct intel_super
*super
= st
->sb
;
1103 if (!super
->anchor
->num_raid_devs
)
1106 getinfo_super_imsm(st
, &info
, NULL
);
1107 fname_from_uuid(st
, &info
, nbuf
, ':');
1108 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
1109 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
1111 super
->current_vol
= i
;
1112 getinfo_super_imsm(st
, &info
, NULL
);
1113 fname_from_uuid(st
, &info
, nbuf1
, ':');
1114 printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n",
1115 dev
->volume
, nbuf
+ 5, i
, nbuf1
+ 5);
1119 static void export_examine_super_imsm(struct supertype
*st
)
1121 struct intel_super
*super
= st
->sb
;
1122 struct imsm_super
*mpb
= super
->anchor
;
1126 getinfo_super_imsm(st
, &info
, NULL
);
1127 fname_from_uuid(st
, &info
, nbuf
, ':');
1128 printf("MD_METADATA=imsm\n");
1129 printf("MD_LEVEL=container\n");
1130 printf("MD_UUID=%s\n", nbuf
+5);
1131 printf("MD_DEVICES=%u\n", mpb
->num_disks
);
1134 static void detail_super_imsm(struct supertype
*st
, char *homehost
)
1139 getinfo_super_imsm(st
, &info
, NULL
);
1140 fname_from_uuid(st
, &info
, nbuf
, ':');
1141 printf("\n UUID : %s\n", nbuf
+ 5);
1144 static void brief_detail_super_imsm(struct supertype
*st
)
1148 getinfo_super_imsm(st
, &info
, NULL
);
1149 fname_from_uuid(st
, &info
, nbuf
, ':');
1150 printf(" UUID=%s", nbuf
+ 5);
1153 static int imsm_read_serial(int fd
, char *devname
, __u8
*serial
);
1154 static void fd2devname(int fd
, char *name
);
1156 static int ahci_enumerate_ports(const char *hba_path
, int port_count
, int host_base
, int verbose
)
1158 /* dump an unsorted list of devices attached to AHCI Intel storage
1159 * controller, as well as non-connected ports
1161 int hba_len
= strlen(hba_path
) + 1;
1166 unsigned long port_mask
= (1 << port_count
) - 1;
1168 if (port_count
> (int)sizeof(port_mask
) * 8) {
1170 fprintf(stderr
, Name
": port_count %d out of range\n", port_count
);
1174 /* scroll through /sys/dev/block looking for devices attached to
1177 dir
= opendir("/sys/dev/block");
1178 for (ent
= dir
? readdir(dir
) : NULL
; ent
; ent
= readdir(dir
)) {
1189 if (sscanf(ent
->d_name
, "%d:%d", &major
, &minor
) != 2)
1191 path
= devt_to_devpath(makedev(major
, minor
));
1194 if (!path_attached_to_hba(path
, hba_path
)) {
1200 /* retrieve the scsi device type */
1201 if (asprintf(&device
, "/sys/dev/block/%d:%d/device/xxxxxxx", major
, minor
) < 0) {
1203 fprintf(stderr
, Name
": failed to allocate 'device'\n");
1207 sprintf(device
, "/sys/dev/block/%d:%d/device/type", major
, minor
);
1208 if (load_sys(device
, buf
) != 0) {
1210 fprintf(stderr
, Name
": failed to read device type for %s\n",
1216 type
= strtoul(buf
, NULL
, 10);
1218 /* if it's not a disk print the vendor and model */
1219 if (!(type
== 0 || type
== 7 || type
== 14)) {
1222 sprintf(device
, "/sys/dev/block/%d:%d/device/vendor", major
, minor
);
1223 if (load_sys(device
, buf
) == 0) {
1224 strncpy(vendor
, buf
, sizeof(vendor
));
1225 vendor
[sizeof(vendor
) - 1] = '\0';
1226 c
= (char *) &vendor
[sizeof(vendor
) - 1];
1227 while (isspace(*c
) || *c
== '\0')
1231 sprintf(device
, "/sys/dev/block/%d:%d/device/model", major
, minor
);
1232 if (load_sys(device
, buf
) == 0) {
1233 strncpy(model
, buf
, sizeof(model
));
1234 model
[sizeof(model
) - 1] = '\0';
1235 c
= (char *) &model
[sizeof(model
) - 1];
1236 while (isspace(*c
) || *c
== '\0')
1240 if (vendor
[0] && model
[0])
1241 sprintf(buf
, "%.64s %.64s", vendor
, model
);
1243 switch (type
) { /* numbers from hald/linux/device.c */
1244 case 1: sprintf(buf
, "tape"); break;
1245 case 2: sprintf(buf
, "printer"); break;
1246 case 3: sprintf(buf
, "processor"); break;
1248 case 5: sprintf(buf
, "cdrom"); break;
1249 case 6: sprintf(buf
, "scanner"); break;
1250 case 8: sprintf(buf
, "media_changer"); break;
1251 case 9: sprintf(buf
, "comm"); break;
1252 case 12: sprintf(buf
, "raid"); break;
1253 default: sprintf(buf
, "unknown");
1259 /* chop device path to 'host%d' and calculate the port number */
1260 c
= strchr(&path
[hba_len
], '/');
1263 fprintf(stderr
, Name
": %s - invalid path name\n", path
+ hba_len
);
1268 if (sscanf(&path
[hba_len
], "host%d", &port
) == 1)
1272 *c
= '/'; /* repair the full string */
1273 fprintf(stderr
, Name
": failed to determine port number for %s\n",
1280 /* mark this port as used */
1281 port_mask
&= ~(1 << port
);
1283 /* print out the device information */
1285 printf(" Port%d : - non-disk device (%s) -\n", port
, buf
);
1289 fd
= dev_open(ent
->d_name
, O_RDONLY
);
1291 printf(" Port%d : - disk info unavailable -\n", port
);
1293 fd2devname(fd
, buf
);
1294 printf(" Port%d : %s", port
, buf
);
1295 if (imsm_read_serial(fd
, NULL
, (__u8
*) buf
) == 0)
1296 printf(" (%s)\n", buf
);
1311 for (i
= 0; i
< port_count
; i
++)
1312 if (port_mask
& (1 << i
))
1313 printf(" Port%d : - no device attached -\n", i
);
1321 static void print_found_intel_controllers(struct sys_dev
*elem
)
1323 for (; elem
; elem
= elem
->next
) {
1324 fprintf(stderr
, Name
": found Intel(R) ");
1325 if (elem
->type
== SYS_DEV_SATA
)
1326 fprintf(stderr
, "SATA ");
1327 else if (elem
->type
== SYS_DEV_SAS
)
1328 fprintf(stderr
, "SAS ");
1329 fprintf(stderr
, "RAID controller");
1331 fprintf(stderr
, " at %s", elem
->pci_id
);
1332 fprintf(stderr
, ".\n");
1337 static int ahci_get_port_count(const char *hba_path
, int *port_count
)
1344 if ((dir
= opendir(hba_path
)) == NULL
)
1347 for (ent
= readdir(dir
); ent
; ent
= readdir(dir
)) {
1350 if (sscanf(ent
->d_name
, "host%d", &host
) != 1)
1352 if (*port_count
== 0)
1354 else if (host
< host_base
)
1357 if (host
+ 1 > *port_count
+ host_base
)
1358 *port_count
= host
+ 1 - host_base
;
1364 static void print_imsm_capability(const struct imsm_orom
*orom
)
1366 printf(" Platform : Intel(R) Matrix Storage Manager\n");
1367 printf(" Version : %d.%d.%d.%d\n", orom
->major_ver
, orom
->minor_ver
,
1368 orom
->hotfix_ver
, orom
->build
);
1369 printf(" RAID Levels :%s%s%s%s%s\n",
1370 imsm_orom_has_raid0(orom
) ? " raid0" : "",
1371 imsm_orom_has_raid1(orom
) ? " raid1" : "",
1372 imsm_orom_has_raid1e(orom
) ? " raid1e" : "",
1373 imsm_orom_has_raid10(orom
) ? " raid10" : "",
1374 imsm_orom_has_raid5(orom
) ? " raid5" : "");
1375 printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1376 imsm_orom_has_chunk(orom
, 2) ? " 2k" : "",
1377 imsm_orom_has_chunk(orom
, 4) ? " 4k" : "",
1378 imsm_orom_has_chunk(orom
, 8) ? " 8k" : "",
1379 imsm_orom_has_chunk(orom
, 16) ? " 16k" : "",
1380 imsm_orom_has_chunk(orom
, 32) ? " 32k" : "",
1381 imsm_orom_has_chunk(orom
, 64) ? " 64k" : "",
1382 imsm_orom_has_chunk(orom
, 128) ? " 128k" : "",
1383 imsm_orom_has_chunk(orom
, 256) ? " 256k" : "",
1384 imsm_orom_has_chunk(orom
, 512) ? " 512k" : "",
1385 imsm_orom_has_chunk(orom
, 1024*1) ? " 1M" : "",
1386 imsm_orom_has_chunk(orom
, 1024*2) ? " 2M" : "",
1387 imsm_orom_has_chunk(orom
, 1024*4) ? " 4M" : "",
1388 imsm_orom_has_chunk(orom
, 1024*8) ? " 8M" : "",
1389 imsm_orom_has_chunk(orom
, 1024*16) ? " 16M" : "",
1390 imsm_orom_has_chunk(orom
, 1024*32) ? " 32M" : "",
1391 imsm_orom_has_chunk(orom
, 1024*64) ? " 64M" : "");
1392 printf(" Max Disks : %d\n", orom
->tds
);
1393 printf(" Max Volumes : %d\n", orom
->vpa
);
1397 static int detail_platform_imsm(int verbose
, int enumerate_only
)
1399 /* There are two components to imsm platform support, the ahci SATA
1400 * controller and the option-rom. To find the SATA controller we
1401 * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
1402 * controller with the Intel vendor id is present. This approach
1403 * allows mdadm to leverage the kernel's ahci detection logic, with the
1404 * caveat that if ahci.ko is not loaded mdadm will not be able to
1405 * detect platform raid capabilities. The option-rom resides in a
1406 * platform "Adapter ROM". We scan for its signature to retrieve the
1407 * platform capabilities. If raid support is disabled in the BIOS the
1408 * option-rom capability structure will not be available.
1410 const struct imsm_orom
*orom
;
1411 struct sys_dev
*list
, *hba
;
1416 if (enumerate_only
) {
1417 if (check_env("IMSM_NO_PLATFORM"))
1419 list
= find_intel_devices();
1422 for (hba
= list
; hba
; hba
= hba
->next
) {
1423 orom
= find_imsm_capability(hba
->type
);
1429 free_sys_dev(&list
);
1433 list
= find_intel_devices();
1436 fprintf(stderr
, Name
": no active Intel(R) RAID "
1437 "controller found.\n");
1438 free_sys_dev(&list
);
1441 print_found_intel_controllers(list
);
1443 for (hba
= list
; hba
; hba
= hba
->next
) {
1444 orom
= find_imsm_capability(hba
->type
);
1446 fprintf(stderr
, Name
": imsm capabilities not found for controller: %s (type %s)\n",
1447 hba
->path
, get_sys_dev_type(hba
->type
));
1449 print_imsm_capability(orom
);
1452 for (hba
= list
; hba
; hba
= hba
->next
) {
1453 printf(" I/O Controller : %s (%s)\n",
1454 hba
->path
, get_sys_dev_type(hba
->type
));
1456 if (hba
->type
== SYS_DEV_SATA
) {
1457 host_base
= ahci_get_port_count(hba
->path
, &port_count
);
1458 if (ahci_enumerate_ports(hba
->path
, port_count
, host_base
, verbose
)) {
1460 fprintf(stderr
, Name
": failed to enumerate "
1461 "ports on SATA controller at %s.", hba
->pci_id
);
1467 free_sys_dev(&list
);
1472 static int match_home_imsm(struct supertype
*st
, char *homehost
)
1474 /* the imsm metadata format does not specify any host
1475 * identification information. We return -1 since we can never
1476 * confirm nor deny whether a given array is "meant" for this
1477 * host. We rely on compare_super and the 'family_num' fields to
1478 * exclude member disks that do not belong, and we rely on
1479 * mdadm.conf to specify the arrays that should be assembled.
1480 * Auto-assembly may still pick up "foreign" arrays.
1486 static void uuid_from_super_imsm(struct supertype
*st
, int uuid
[4])
1488 /* The uuid returned here is used for:
1489 * uuid to put into bitmap file (Create, Grow)
1490 * uuid for backup header when saving critical section (Grow)
1491 * comparing uuids when re-adding a device into an array
1492 * In these cases the uuid required is that of the data-array,
1493 * not the device-set.
1494 * uuid to recognise same set when adding a missing device back
1495 * to an array. This is a uuid for the device-set.
1497 * For each of these we can make do with a truncated
1498 * or hashed uuid rather than the original, as long as
1500 * In each case the uuid required is that of the data-array,
1501 * not the device-set.
1503 /* imsm does not track uuid's so we synthesis one using sha1 on
1504 * - The signature (Which is constant for all imsm array, but no matter)
1505 * - the orig_family_num of the container
1506 * - the index number of the volume
1507 * - the 'serial' number of the volume.
1508 * Hopefully these are all constant.
1510 struct intel_super
*super
= st
->sb
;
1513 struct sha1_ctx ctx
;
1514 struct imsm_dev
*dev
= NULL
;
1517 /* some mdadm versions failed to set ->orig_family_num, in which
1518 * case fall back to ->family_num. orig_family_num will be
1519 * fixed up with the first metadata update.
1521 family_num
= super
->anchor
->orig_family_num
;
1522 if (family_num
== 0)
1523 family_num
= super
->anchor
->family_num
;
1524 sha1_init_ctx(&ctx
);
1525 sha1_process_bytes(super
->anchor
->sig
, MPB_SIG_LEN
, &ctx
);
1526 sha1_process_bytes(&family_num
, sizeof(__u32
), &ctx
);
1527 if (super
->current_vol
>= 0)
1528 dev
= get_imsm_dev(super
, super
->current_vol
);
1530 __u32 vol
= super
->current_vol
;
1531 sha1_process_bytes(&vol
, sizeof(vol
), &ctx
);
1532 sha1_process_bytes(dev
->volume
, MAX_RAID_SERIAL_LEN
, &ctx
);
1534 sha1_finish_ctx(&ctx
, buf
);
1535 memcpy(uuid
, buf
, 4*4);
1540 get_imsm_numerical_version(struct imsm_super
*mpb
, int *m
, int *p
)
1542 __u8
*v
= get_imsm_version(mpb
);
1543 __u8
*end
= mpb
->sig
+ MAX_SIGNATURE_LENGTH
;
1544 char major
[] = { 0, 0, 0 };
1545 char minor
[] = { 0 ,0, 0 };
1546 char patch
[] = { 0, 0, 0 };
1547 char *ver_parse
[] = { major
, minor
, patch
};
1551 while (*v
!= '\0' && v
< end
) {
1552 if (*v
!= '.' && j
< 2)
1553 ver_parse
[i
][j
++] = *v
;
1561 *m
= strtol(minor
, NULL
, 0);
1562 *p
= strtol(patch
, NULL
, 0);
1566 static __u32
migr_strip_blocks_resync(struct imsm_dev
*dev
)
1568 /* migr_strip_size when repairing or initializing parity */
1569 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1570 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1572 switch (get_imsm_raid_level(map
)) {
1577 return 128*1024 >> 9;
1581 static __u32
migr_strip_blocks_rebuild(struct imsm_dev
*dev
)
1583 /* migr_strip_size when rebuilding a degraded disk, no idea why
1584 * this is different than migr_strip_size_resync(), but it's good
1587 struct imsm_map
*map
= get_imsm_map(dev
, 1);
1588 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1590 switch (get_imsm_raid_level(map
)) {
1593 if (map
->num_members
% map
->num_domains
== 0)
1594 return 128*1024 >> 9;
1598 return max((__u32
) 64*1024 >> 9, chunk
);
1600 return 128*1024 >> 9;
1604 static __u32
num_stripes_per_unit_resync(struct imsm_dev
*dev
)
1606 struct imsm_map
*lo
= get_imsm_map(dev
, 0);
1607 struct imsm_map
*hi
= get_imsm_map(dev
, 1);
1608 __u32 lo_chunk
= __le32_to_cpu(lo
->blocks_per_strip
);
1609 __u32 hi_chunk
= __le32_to_cpu(hi
->blocks_per_strip
);
1611 return max((__u32
) 1, hi_chunk
/ lo_chunk
);
1614 static __u32
num_stripes_per_unit_rebuild(struct imsm_dev
*dev
)
1616 struct imsm_map
*lo
= get_imsm_map(dev
, 0);
1617 int level
= get_imsm_raid_level(lo
);
1619 if (level
== 1 || level
== 10) {
1620 struct imsm_map
*hi
= get_imsm_map(dev
, 1);
1622 return hi
->num_domains
;
1624 return num_stripes_per_unit_resync(dev
);
1627 static __u8
imsm_num_data_members(struct imsm_dev
*dev
, int second_map
)
1629 /* named 'imsm_' because raid0, raid1 and raid10
1630 * counter-intuitively have the same number of data disks
1632 struct imsm_map
*map
= get_imsm_map(dev
, second_map
);
1634 switch (get_imsm_raid_level(map
)) {
1638 return map
->num_members
;
1640 return map
->num_members
- 1;
1642 dprintf("%s: unsupported raid level\n", __func__
);
1647 static __u32
parity_segment_depth(struct imsm_dev
*dev
)
1649 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1650 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1652 switch(get_imsm_raid_level(map
)) {
1655 return chunk
* map
->num_domains
;
1657 return chunk
* map
->num_members
;
1663 static __u32
map_migr_block(struct imsm_dev
*dev
, __u32 block
)
1665 struct imsm_map
*map
= get_imsm_map(dev
, 1);
1666 __u32 chunk
= __le32_to_cpu(map
->blocks_per_strip
);
1667 __u32 strip
= block
/ chunk
;
1669 switch (get_imsm_raid_level(map
)) {
1672 __u32 vol_strip
= (strip
* map
->num_domains
) + 1;
1673 __u32 vol_stripe
= vol_strip
/ map
->num_members
;
1675 return vol_stripe
* chunk
+ block
% chunk
;
1677 __u32 stripe
= strip
/ (map
->num_members
- 1);
1679 return stripe
* chunk
+ block
% chunk
;
1686 static __u64
blocks_per_migr_unit(struct imsm_dev
*dev
)
1688 /* calculate the conversion factor between per member 'blocks'
1689 * (md/{resync,rebuild}_start) and imsm migration units, return
1690 * 0 for the 'not migrating' and 'unsupported migration' cases
1692 if (!dev
->vol
.migr_state
)
1695 switch (migr_type(dev
)) {
1700 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1701 __u32 stripes_per_unit
;
1702 __u32 blocks_per_unit
;
1711 /* yes, this is really the translation of migr_units to
1712 * per-member blocks in the 'resync' case
1714 stripes_per_unit
= num_stripes_per_unit_resync(dev
);
1715 migr_chunk
= migr_strip_blocks_resync(dev
);
1716 disks
= imsm_num_data_members(dev
, 0);
1717 blocks_per_unit
= stripes_per_unit
* migr_chunk
* disks
;
1718 stripe
= __le32_to_cpu(map
->blocks_per_strip
) * disks
;
1719 segment
= blocks_per_unit
/ stripe
;
1720 block_rel
= blocks_per_unit
- segment
* stripe
;
1721 parity_depth
= parity_segment_depth(dev
);
1722 block_map
= map_migr_block(dev
, block_rel
);
1723 return block_map
+ parity_depth
* segment
;
1725 case MIGR_REBUILD
: {
1726 __u32 stripes_per_unit
;
1729 stripes_per_unit
= num_stripes_per_unit_rebuild(dev
);
1730 migr_chunk
= migr_strip_blocks_rebuild(dev
);
1731 return migr_chunk
* stripes_per_unit
;
1733 case MIGR_STATE_CHANGE
:
1739 static int imsm_level_to_layout(int level
)
1747 return ALGORITHM_LEFT_ASYMMETRIC
;
1754 static void getinfo_super_imsm_volume(struct supertype
*st
, struct mdinfo
*info
, char *dmap
)
1756 struct intel_super
*super
= st
->sb
;
1757 struct imsm_dev
*dev
= get_imsm_dev(super
, super
->current_vol
);
1758 struct imsm_map
*map
= get_imsm_map(dev
, 0);
1759 struct imsm_map
*prev_map
= get_imsm_map(dev
, 1);
1760 struct imsm_map
*map_to_analyse
= map
;
1763 unsigned int component_size_alligment
;
1764 int map_disks
= info
->array
.raid_disks
;
1767 map_to_analyse
= prev_map
;
1769 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
1770 if (dl
->raiddisk
== info
->disk
.raid_disk
)
1772 info
->container_member
= super
->current_vol
;
1773 info
->array
.raid_disks
= map
->num_members
;
1774 info
->array
.level
= get_imsm_raid_level(map_to_analyse
);
1775 info
->array
.layout
= imsm_level_to_layout(info
->array
.level
);
1776 info
->array
.md_minor
= -1;
1777 info
->array
.ctime
= 0;
1778 info
->array
.utime
= 0;
1779 info
->array
.chunk_size
=
1780 __le16_to_cpu(map_to_analyse
->blocks_per_strip
) << 9;
1781 info
->array
.state
= !dev
->vol
.dirty
;
1782 info
->custom_array_size
= __le32_to_cpu(dev
->size_high
);
1783 info
->custom_array_size
<<= 32;
1784 info
->custom_array_size
|= __le32_to_cpu(dev
->size_low
);
1785 if (prev_map
&& map
->map_state
== prev_map
->map_state
) {
1786 info
->reshape_active
= 1;
1787 info
->new_level
= get_imsm_raid_level(map
);
1788 info
->new_layout
= imsm_level_to_layout(info
->new_level
);
1789 info
->new_chunk
= __le16_to_cpu(map
->blocks_per_strip
) << 9;
1790 info
->delta_disks
= map
->num_members
- prev_map
->num_members
;
1791 if (info
->delta_disks
) {
1792 /* this needs to be applied to every array
1795 info
->reshape_active
= 2;
1797 /* We shape information that we give to md might have to be
1798 * modify to cope with md's requirement for reshaping arrays.
1799 * For example, when reshaping a RAID0, md requires it to be
1800 * presented as a degraded RAID4.
1801 * Also if a RAID0 is migrating to a RAID5 we need to specify
1802 * the array as already being RAID5, but the 'before' layout
1803 * is a RAID4-like layout.
1805 switch (info
->array
.level
) {
1807 switch(info
->new_level
) {
1809 /* conversion is happening as RAID4 */
1810 info
->array
.level
= 4;
1811 info
->array
.raid_disks
+= 1;
1814 /* conversion is happening as RAID5 */
1815 info
->array
.level
= 5;
1816 info
->array
.layout
= ALGORITHM_PARITY_N
;
1817 info
->array
.raid_disks
+= 1;
1818 info
->delta_disks
-= 1;
1821 /* FIXME error message */
1822 info
->array
.level
= UnSet
;
1828 info
->new_level
= UnSet
;
1829 info
->new_layout
= UnSet
;
1830 info
->new_chunk
= info
->array
.chunk_size
;
1831 info
->delta_disks
= 0;
1833 info
->disk
.major
= 0;
1834 info
->disk
.minor
= 0;
1836 info
->disk
.major
= dl
->major
;
1837 info
->disk
.minor
= dl
->minor
;
1840 info
->data_offset
= __le32_to_cpu(map_to_analyse
->pba_of_lba0
);
1841 info
->component_size
=
1842 __le32_to_cpu(map_to_analyse
->blocks_per_member
);
1844 /* check component size aligment
1846 component_size_alligment
=
1847 info
->component_size
% (info
->array
.chunk_size
/512);
1849 if (component_size_alligment
&&
1850 (info
->array
.level
!= 1) && (info
->array
.level
!= UnSet
)) {
1851 dprintf("imsm: reported component size alligned from %llu ",
1852 info
->component_size
);
1853 info
->component_size
-= component_size_alligment
;
1854 dprintf("to %llu (%i).\n",
1855 info
->component_size
, component_size_alligment
);
1858 memset(info
->uuid
, 0, sizeof(info
->uuid
));
1859 info
->recovery_start
= MaxSector
;
1861 info
->reshape_progress
= 0;
1862 info
->resync_start
= MaxSector
;
1863 if (map_to_analyse
->map_state
== IMSM_T_STATE_UNINITIALIZED
||
1865 info
->resync_start
= 0;
1867 if (dev
->vol
.migr_state
) {
1868 switch (migr_type(dev
)) {
1871 __u64 blocks_per_unit
= blocks_per_migr_unit(dev
);
1872 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
1874 info
->resync_start
= blocks_per_unit
* units
;
1877 case MIGR_GEN_MIGR
: {
1878 __u64 blocks_per_unit
= blocks_per_migr_unit(dev
);
1879 __u64 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
1880 unsigned long long array_blocks
;
1883 info
->reshape_progress
= blocks_per_unit
* units
;
1885 /* checkpoint is written per disks unit
1886 * recalculate it to reshape position
1888 used_disks
= imsm_num_data_members(dev
, 0);
1889 info
->reshape_progress
*= used_disks
;
1890 dprintf("IMSM: General Migration checkpoint : %llu "
1891 "(%llu) -> read reshape progress : %llu\n",
1892 units
, blocks_per_unit
, info
->reshape_progress
);
1894 used_disks
= imsm_num_data_members(dev
, 1);
1895 if (used_disks
> 0) {
1896 array_blocks
= map
->blocks_per_member
*
1898 /* round array size down to closest MB
1900 info
->custom_array_size
= (array_blocks
1901 >> SECT_PER_MB_SHIFT
)
1902 << SECT_PER_MB_SHIFT
;
1906 /* we could emulate the checkpointing of
1907 * 'sync_action=check' migrations, but for now
1908 * we just immediately complete them
1911 /* this is handled by container_content_imsm() */
1912 case MIGR_STATE_CHANGE
:
1913 /* FIXME handle other migrations */
1915 /* we are not dirty, so... */
1916 info
->resync_start
= MaxSector
;
1920 strncpy(info
->name
, (char *) dev
->volume
, MAX_RAID_SERIAL_LEN
);
1921 info
->name
[MAX_RAID_SERIAL_LEN
] = 0;
1923 info
->array
.major_version
= -1;
1924 info
->array
.minor_version
= -2;
1925 devname
= devnum2devname(st
->container_dev
);
1926 *info
->text_version
= '\0';
1928 sprintf(info
->text_version
, "/%s/%d", devname
, info
->container_member
);
1930 info
->safe_mode_delay
= 4000; /* 4 secs like the Matrix driver */
1931 uuid_from_super_imsm(st
, info
->uuid
);
1935 for (i
=0; i
<map_disks
; i
++) {
1937 if (i
< info
->array
.raid_disks
) {
1938 struct imsm_disk
*dsk
;
1939 j
= get_imsm_disk_idx(dev
, i
, -1);
1940 dsk
= get_imsm_disk(super
, j
);
1941 if (dsk
&& (dsk
->status
& CONFIGURED_DISK
))
1948 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
, int failed
);
1949 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
);
1951 static struct imsm_disk
*get_imsm_missing(struct intel_super
*super
, __u8 index
)
1955 for (d
= super
->missing
; d
; d
= d
->next
)
1956 if (d
->index
== index
)
1961 static void getinfo_super_imsm(struct supertype
*st
, struct mdinfo
*info
, char *map
)
1963 struct intel_super
*super
= st
->sb
;
1964 struct imsm_disk
*disk
;
1965 int map_disks
= info
->array
.raid_disks
;
1966 int max_enough
= -1;
1968 struct imsm_super
*mpb
;
1970 if (super
->current_vol
>= 0) {
1971 getinfo_super_imsm_volume(st
, info
, map
);
1975 /* Set raid_disks to zero so that Assemble will always pull in valid
1978 info
->array
.raid_disks
= 0;
1979 info
->array
.level
= LEVEL_CONTAINER
;
1980 info
->array
.layout
= 0;
1981 info
->array
.md_minor
= -1;
1982 info
->array
.ctime
= 0; /* N/A for imsm */
1983 info
->array
.utime
= 0;
1984 info
->array
.chunk_size
= 0;
1986 info
->disk
.major
= 0;
1987 info
->disk
.minor
= 0;
1988 info
->disk
.raid_disk
= -1;
1989 info
->reshape_active
= 0;
1990 info
->array
.major_version
= -1;
1991 info
->array
.minor_version
= -2;
1992 strcpy(info
->text_version
, "imsm");
1993 info
->safe_mode_delay
= 0;
1994 info
->disk
.number
= -1;
1995 info
->disk
.state
= 0;
1997 info
->recovery_start
= MaxSector
;
1999 /* do we have the all the insync disks that we expect? */
2000 mpb
= super
->anchor
;
2002 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
2003 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
2004 int failed
, enough
, j
, missing
= 0;
2005 struct imsm_map
*map
;
2008 failed
= imsm_count_failed(super
, dev
);
2009 state
= imsm_check_degraded(super
, dev
, failed
);
2010 map
= get_imsm_map(dev
, dev
->vol
.migr_state
);
2012 /* any newly missing disks?
2013 * (catches single-degraded vs double-degraded)
2015 for (j
= 0; j
< map
->num_members
; j
++) {
2016 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, -1);
2017 __u32 idx
= ord_to_idx(ord
);
2019 if (!(ord
& IMSM_ORD_REBUILD
) &&
2020 get_imsm_missing(super
, idx
)) {
2026 if (state
== IMSM_T_STATE_FAILED
)
2028 else if (state
== IMSM_T_STATE_DEGRADED
&&
2029 (state
!= map
->map_state
|| missing
))
2031 else /* we're normal, or already degraded */
2034 /* in the missing/failed disk case check to see
2035 * if at least one array is runnable
2037 max_enough
= max(max_enough
, enough
);
2039 dprintf("%s: enough: %d\n", __func__
, max_enough
);
2040 info
->container_enough
= max_enough
;
2043 __u32 reserved
= imsm_reserved_sectors(super
, super
->disks
);
2045 disk
= &super
->disks
->disk
;
2046 info
->data_offset
= __le32_to_cpu(disk
->total_blocks
) - reserved
;
2047 info
->component_size
= reserved
;
2048 info
->disk
.state
= is_configured(disk
) ? (1 << MD_DISK_ACTIVE
) : 0;
2049 /* we don't change info->disk.raid_disk here because
2050 * this state will be finalized in mdmon after we have
2051 * found the 'most fresh' version of the metadata
2053 info
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
2054 info
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
2057 /* only call uuid_from_super_imsm when this disk is part of a populated container,
2058 * ->compare_super may have updated the 'num_raid_devs' field for spares
2060 if (info
->disk
.state
& (1 << MD_DISK_SYNC
) || super
->anchor
->num_raid_devs
)
2061 uuid_from_super_imsm(st
, info
->uuid
);
2063 memcpy(info
->uuid
, uuid_zero
, sizeof(uuid_zero
));
2065 /* I don't know how to compute 'map' on imsm, so use safe default */
2068 for (i
= 0; i
< map_disks
; i
++)
2074 /* allocates memory and fills disk in mdinfo structure
2075 * for each disk in array */
2076 struct mdinfo
*getinfo_super_disks_imsm(struct supertype
*st
)
2078 struct mdinfo
*mddev
= NULL
;
2079 struct intel_super
*super
= st
->sb
;
2080 struct imsm_disk
*disk
;
2083 if (!super
|| !super
->disks
)
2086 mddev
= malloc(sizeof(*mddev
));
2088 fprintf(stderr
, Name
": Failed to allocate memory.\n");
2091 memset(mddev
, 0, sizeof(*mddev
));
2095 tmp
= malloc(sizeof(*tmp
));
2097 fprintf(stderr
, Name
": Failed to allocate memory.\n");
2102 memset(tmp
, 0, sizeof(*tmp
));
2104 tmp
->next
= mddev
->devs
;
2106 tmp
->disk
.number
= count
++;
2107 tmp
->disk
.major
= dl
->major
;
2108 tmp
->disk
.minor
= dl
->minor
;
2109 tmp
->disk
.state
= is_configured(disk
) ?
2110 (1 << MD_DISK_ACTIVE
) : 0;
2111 tmp
->disk
.state
|= is_failed(disk
) ? (1 << MD_DISK_FAULTY
) : 0;
2112 tmp
->disk
.state
|= is_spare(disk
) ? 0 : (1 << MD_DISK_SYNC
);
2113 tmp
->disk
.raid_disk
= -1;
2119 static int update_super_imsm(struct supertype
*st
, struct mdinfo
*info
,
2120 char *update
, char *devname
, int verbose
,
2121 int uuid_set
, char *homehost
)
2123 /* For 'assemble' and 'force' we need to return non-zero if any
2124 * change was made. For others, the return value is ignored.
2125 * Update options are:
2126 * force-one : This device looks a bit old but needs to be included,
2127 * update age info appropriately.
2128 * assemble: clear any 'faulty' flag to allow this device to
2130 * force-array: Array is degraded but being forced, mark it clean
2131 * if that will be needed to assemble it.
2133 * newdev: not used ????
2134 * grow: Array has gained a new device - this is currently for
2136 * resync: mark as dirty so a resync will happen.
2137 * name: update the name - preserving the homehost
2138 * uuid: Change the uuid of the array to match watch is given
2140 * Following are not relevant for this imsm:
2141 * sparc2.2 : update from old dodgey metadata
2142 * super-minor: change the preferred_minor number
2143 * summaries: update redundant counters.
2144 * homehost: update the recorded homehost
2145 * _reshape_progress: record new reshape_progress position.
2148 struct intel_super
*super
= st
->sb
;
2149 struct imsm_super
*mpb
;
2151 /* we can only update container info */
2152 if (!super
|| super
->current_vol
>= 0 || !super
->anchor
)
2155 mpb
= super
->anchor
;
2157 if (strcmp(update
, "uuid") == 0 && uuid_set
&& !info
->update_private
)
2159 else if (strcmp(update
, "uuid") == 0 && uuid_set
&& info
->update_private
) {
2160 mpb
->orig_family_num
= *((__u32
*) info
->update_private
);
2162 } else if (strcmp(update
, "uuid") == 0) {
2163 __u32
*new_family
= malloc(sizeof(*new_family
));
2165 /* update orig_family_number with the incoming random
2166 * data, report the new effective uuid, and store the
2167 * new orig_family_num for future updates.
2170 memcpy(&mpb
->orig_family_num
, info
->uuid
, sizeof(__u32
));
2171 uuid_from_super_imsm(st
, info
->uuid
);
2172 *new_family
= mpb
->orig_family_num
;
2173 info
->update_private
= new_family
;
2176 } else if (strcmp(update
, "assemble") == 0)
2181 /* successful update? recompute checksum */
2183 mpb
->check_sum
= __le32_to_cpu(__gen_imsm_checksum(mpb
));
2188 static size_t disks_to_mpb_size(int disks
)
2192 size
= sizeof(struct imsm_super
);
2193 size
+= (disks
- 1) * sizeof(struct imsm_disk
);
2194 size
+= 2 * sizeof(struct imsm_dev
);
2195 /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */
2196 size
+= (4 - 2) * sizeof(struct imsm_map
);
2197 /* 4 possible disk_ord_tbl's */
2198 size
+= 4 * (disks
- 1) * sizeof(__u32
);
2203 static __u64
avail_size_imsm(struct supertype
*st
, __u64 devsize
)
2205 if (devsize
< (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
))
2208 return devsize
- (MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
);
2211 static void free_devlist(struct intel_super
*super
)
2213 struct intel_dev
*dv
;
2215 while (super
->devlist
) {
2216 dv
= super
->devlist
->next
;
2217 free(super
->devlist
->dev
);
2218 free(super
->devlist
);
2219 super
->devlist
= dv
;
2223 static void imsm_copy_dev(struct imsm_dev
*dest
, struct imsm_dev
*src
)
2225 memcpy(dest
, src
, sizeof_imsm_dev(src
, 0));
2228 static int compare_super_imsm(struct supertype
*st
, struct supertype
*tst
)
2232 * 0 same, or first was empty, and second was copied
2233 * 1 second had wrong number
2235 * 3 wrong other info
2237 struct intel_super
*first
= st
->sb
;
2238 struct intel_super
*sec
= tst
->sb
;
2245 /* in platform dependent environment test if the disks
2246 * use the same Intel hba
2248 if (!check_env("IMSM_NO_PLATFORM")) {
2249 if (!first
->hba
|| !sec
->hba
||
2250 (first
->hba
->type
!= sec
->hba
->type
)) {
2252 "HBAs of devices does not match %s != %s\n",
2253 first
->hba
? get_sys_dev_type(first
->hba
->type
) : NULL
,
2254 sec
->hba
? get_sys_dev_type(sec
->hba
->type
) : NULL
);
2259 /* if an anchor does not have num_raid_devs set then it is a free
2262 if (first
->anchor
->num_raid_devs
> 0 &&
2263 sec
->anchor
->num_raid_devs
> 0) {
2264 /* Determine if these disks might ever have been
2265 * related. Further disambiguation can only take place
2266 * in load_super_imsm_all
2268 __u32 first_family
= first
->anchor
->orig_family_num
;
2269 __u32 sec_family
= sec
->anchor
->orig_family_num
;
2271 if (memcmp(first
->anchor
->sig
, sec
->anchor
->sig
,
2272 MAX_SIGNATURE_LENGTH
) != 0)
2275 if (first_family
== 0)
2276 first_family
= first
->anchor
->family_num
;
2277 if (sec_family
== 0)
2278 sec_family
= sec
->anchor
->family_num
;
2280 if (first_family
!= sec_family
)
2286 /* if 'first' is a spare promote it to a populated mpb with sec's
2289 if (first
->anchor
->num_raid_devs
== 0 &&
2290 sec
->anchor
->num_raid_devs
> 0) {
2292 struct intel_dev
*dv
;
2293 struct imsm_dev
*dev
;
2295 /* we need to copy raid device info from sec if an allocation
2296 * fails here we don't associate the spare
2298 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++) {
2299 dv
= malloc(sizeof(*dv
));
2302 dev
= malloc(sizeof_imsm_dev(get_imsm_dev(sec
, i
), 1));
2309 dv
->next
= first
->devlist
;
2310 first
->devlist
= dv
;
2312 if (i
< sec
->anchor
->num_raid_devs
) {
2313 /* allocation failure */
2314 free_devlist(first
);
2315 fprintf(stderr
, "imsm: failed to associate spare\n");
2318 first
->anchor
->num_raid_devs
= sec
->anchor
->num_raid_devs
;
2319 first
->anchor
->orig_family_num
= sec
->anchor
->orig_family_num
;
2320 first
->anchor
->family_num
= sec
->anchor
->family_num
;
2321 memcpy(first
->anchor
->sig
, sec
->anchor
->sig
, MAX_SIGNATURE_LENGTH
);
2322 for (i
= 0; i
< sec
->anchor
->num_raid_devs
; i
++)
2323 imsm_copy_dev(get_imsm_dev(first
, i
), get_imsm_dev(sec
, i
));
2329 static void fd2devname(int fd
, char *name
)
2333 char dname
[PATH_MAX
];
2338 if (fstat(fd
, &st
) != 0)
2340 sprintf(path
, "/sys/dev/block/%d:%d",
2341 major(st
.st_rdev
), minor(st
.st_rdev
));
2343 rv
= readlink(path
, dname
, sizeof(dname
));
2348 nm
= strrchr(dname
, '/');
2350 snprintf(name
, MAX_RAID_SERIAL_LEN
, "/dev/%s", nm
);
2353 extern int scsi_get_serial(int fd
, void *buf
, size_t buf_len
);
2355 static int imsm_read_serial(int fd
, char *devname
,
2356 __u8 serial
[MAX_RAID_SERIAL_LEN
])
2358 unsigned char scsi_serial
[255];
2367 memset(scsi_serial
, 0, sizeof(scsi_serial
));
2369 rv
= scsi_get_serial(fd
, scsi_serial
, sizeof(scsi_serial
));
2371 if (rv
&& check_env("IMSM_DEVNAME_AS_SERIAL")) {
2372 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
2373 fd2devname(fd
, (char *) serial
);
2380 Name
": Failed to retrieve serial for %s\n",
2385 rsp_len
= scsi_serial
[3];
2389 Name
": Failed to retrieve serial for %s\n",
2393 rsp_buf
= (char *) &scsi_serial
[4];
2395 /* trim all whitespace and non-printable characters and convert
2398 for (i
= 0, dest
= rsp_buf
; i
< rsp_len
; i
++) {
2401 /* ':' is reserved for use in placeholder serial
2402 * numbers for missing disks
2410 len
= dest
- rsp_buf
;
2413 /* truncate leading characters */
2414 if (len
> MAX_RAID_SERIAL_LEN
) {
2415 dest
+= len
- MAX_RAID_SERIAL_LEN
;
2416 len
= MAX_RAID_SERIAL_LEN
;
2419 memset(serial
, 0, MAX_RAID_SERIAL_LEN
);
2420 memcpy(serial
, dest
, len
);
2425 static int serialcmp(__u8
*s1
, __u8
*s2
)
2427 return strncmp((char *) s1
, (char *) s2
, MAX_RAID_SERIAL_LEN
);
2430 static void serialcpy(__u8
*dest
, __u8
*src
)
2432 strncpy((char *) dest
, (char *) src
, MAX_RAID_SERIAL_LEN
);
2436 static struct dl
*serial_to_dl(__u8
*serial
, struct intel_super
*super
)
2440 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
2441 if (serialcmp(dl
->serial
, serial
) == 0)
2448 static struct imsm_disk
*
2449 __serial_to_disk(__u8
*serial
, struct imsm_super
*mpb
, int *idx
)
2453 for (i
= 0; i
< mpb
->num_disks
; i
++) {
2454 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
2456 if (serialcmp(disk
->serial
, serial
) == 0) {
2467 load_imsm_disk(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
2469 struct imsm_disk
*disk
;
2474 __u8 serial
[MAX_RAID_SERIAL_LEN
];
2476 rv
= imsm_read_serial(fd
, devname
, serial
);
2481 dl
= calloc(1, sizeof(*dl
));
2485 Name
": failed to allocate disk buffer for %s\n",
2491 dl
->major
= major(stb
.st_rdev
);
2492 dl
->minor
= minor(stb
.st_rdev
);
2493 dl
->next
= super
->disks
;
2494 dl
->fd
= keep_fd
? fd
: -1;
2495 assert(super
->disks
== NULL
);
2497 serialcpy(dl
->serial
, serial
);
2500 fd2devname(fd
, name
);
2502 dl
->devname
= strdup(devname
);
2504 dl
->devname
= strdup(name
);
2506 /* look up this disk's index in the current anchor */
2507 disk
= __serial_to_disk(dl
->serial
, super
->anchor
, &dl
->index
);
2510 /* only set index on disks that are a member of a
2511 * populated contianer, i.e. one with raid_devs
2513 if (is_failed(&dl
->disk
))
2515 else if (is_spare(&dl
->disk
))
2523 /* When migrating map0 contains the 'destination' state while map1
2524 * contains the current state. When not migrating map0 contains the
2525 * current state. This routine assumes that map[0].map_state is set to
2526 * the current array state before being called.
2528 * Migration is indicated by one of the following states
2529 * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
2530 * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
2531 * map1state=unitialized)
2532 * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal
2534 * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
2535 * map1state=degraded)
2537 static void migrate(struct imsm_dev
*dev
, __u8 to_state
, int migr_type
)
2539 struct imsm_map
*dest
;
2540 struct imsm_map
*src
= get_imsm_map(dev
, 0);
2542 dev
->vol
.migr_state
= 1;
2543 set_migr_type(dev
, migr_type
);
2544 dev
->vol
.curr_migr_unit
= 0;
2545 dest
= get_imsm_map(dev
, 1);
2547 /* duplicate and then set the target end state in map[0] */
2548 memcpy(dest
, src
, sizeof_imsm_map(src
));
2549 if ((migr_type
== MIGR_REBUILD
) ||
2550 (migr_type
== MIGR_GEN_MIGR
)) {
2554 for (i
= 0; i
< src
->num_members
; i
++) {
2555 ord
= __le32_to_cpu(src
->disk_ord_tbl
[i
]);
2556 set_imsm_ord_tbl_ent(src
, i
, ord_to_idx(ord
));
2560 src
->map_state
= to_state
;
2563 static void end_migration(struct imsm_dev
*dev
, __u8 map_state
)
2565 struct imsm_map
*map
= get_imsm_map(dev
, 0);
2566 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
);
2569 /* merge any IMSM_ORD_REBUILD bits that were not successfully
2570 * completed in the last migration.
2572 * FIXME add support for raid-level-migration
2574 for (i
= 0; i
< prev
->num_members
; i
++)
2575 for (j
= 0; j
< map
->num_members
; j
++)
2576 /* during online capacity expansion
2577 * disks position can be changed if takeover is used
2579 if (ord_to_idx(map
->disk_ord_tbl
[j
]) ==
2580 ord_to_idx(prev
->disk_ord_tbl
[i
])) {
2581 map
->disk_ord_tbl
[j
] |= prev
->disk_ord_tbl
[i
];
2585 dev
->vol
.migr_state
= 0;
2586 dev
->vol
.migr_type
= 0;
2587 dev
->vol
.curr_migr_unit
= 0;
2588 map
->map_state
= map_state
;
2592 static int parse_raid_devices(struct intel_super
*super
)
2595 struct imsm_dev
*dev_new
;
2596 size_t len
, len_migr
;
2598 size_t space_needed
= 0;
2599 struct imsm_super
*mpb
= super
->anchor
;
2601 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
2602 struct imsm_dev
*dev_iter
= __get_imsm_dev(super
->anchor
, i
);
2603 struct intel_dev
*dv
;
2605 len
= sizeof_imsm_dev(dev_iter
, 0);
2606 len_migr
= sizeof_imsm_dev(dev_iter
, 1);
2608 space_needed
+= len_migr
- len
;
2610 dv
= malloc(sizeof(*dv
));
2613 if (max_len
< len_migr
)
2615 if (max_len
> len_migr
)
2616 space_needed
+= max_len
- len_migr
;
2617 dev_new
= malloc(max_len
);
2622 imsm_copy_dev(dev_new
, dev_iter
);
2625 dv
->next
= super
->devlist
;
2626 super
->devlist
= dv
;
2629 /* ensure that super->buf is large enough when all raid devices
2632 if (__le32_to_cpu(mpb
->mpb_size
) + space_needed
> super
->len
) {
2635 len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + space_needed
, 512);
2636 if (posix_memalign(&buf
, 512, len
) != 0)
2639 memcpy(buf
, super
->buf
, super
->len
);
2640 memset(buf
+ super
->len
, 0, len
- super
->len
);
2649 /* retrieve a pointer to the bbm log which starts after all raid devices */
2650 struct bbm_log
*__get_imsm_bbm_log(struct imsm_super
*mpb
)
2654 if (__le32_to_cpu(mpb
->bbm_log_size
)) {
2656 ptr
+= mpb
->mpb_size
- __le32_to_cpu(mpb
->bbm_log_size
);
2662 static void __free_imsm(struct intel_super
*super
, int free_disks
);
2664 /* load_imsm_mpb - read matrix metadata
2665 * allocates super->mpb to be freed by free_imsm
2667 static int load_imsm_mpb(int fd
, struct intel_super
*super
, char *devname
)
2669 unsigned long long dsize
;
2670 unsigned long long sectors
;
2672 struct imsm_super
*anchor
;
2675 get_dev_size(fd
, NULL
, &dsize
);
2679 Name
": %s: device to small for imsm\n",
2684 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0) {
2687 Name
": Cannot seek to anchor block on %s: %s\n",
2688 devname
, strerror(errno
));
2692 if (posix_memalign((void**)&anchor
, 512, 512) != 0) {
2695 Name
": Failed to allocate imsm anchor buffer"
2696 " on %s\n", devname
);
2699 if (read(fd
, anchor
, 512) != 512) {
2702 Name
": Cannot read anchor block on %s: %s\n",
2703 devname
, strerror(errno
));
2708 if (strncmp((char *) anchor
->sig
, MPB_SIGNATURE
, MPB_SIG_LEN
) != 0) {
2711 Name
": no IMSM anchor on %s\n", devname
);
2716 __free_imsm(super
, 0);
2717 /* reload capability and hba */
2719 /* capability and hba must be updated with new super allocation */
2720 find_intel_hba_capability(fd
, super
, devname
);
2721 super
->len
= ROUND_UP(anchor
->mpb_size
, 512);
2722 if (posix_memalign(&super
->buf
, 512, super
->len
) != 0) {
2725 Name
": unable to allocate %zu byte mpb buffer\n",
2730 memcpy(super
->buf
, anchor
, 512);
2732 sectors
= mpb_sectors(anchor
) - 1;
2735 check_sum
= __gen_imsm_checksum(super
->anchor
);
2736 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
2739 Name
": IMSM checksum %x != %x on %s\n",
2741 __le32_to_cpu(super
->anchor
->check_sum
),
2749 /* read the extended mpb */
2750 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0) {
2753 Name
": Cannot seek to extended mpb on %s: %s\n",
2754 devname
, strerror(errno
));
2758 if ((unsigned)read(fd
, super
->buf
+ 512, super
->len
- 512) != super
->len
- 512) {
2761 Name
": Cannot read extended mpb on %s: %s\n",
2762 devname
, strerror(errno
));
2766 check_sum
= __gen_imsm_checksum(super
->anchor
);
2767 if (check_sum
!= __le32_to_cpu(super
->anchor
->check_sum
)) {
2770 Name
": IMSM checksum %x != %x on %s\n",
2771 check_sum
, __le32_to_cpu(super
->anchor
->check_sum
),
2776 /* FIXME the BBM log is disk specific so we cannot use this global
2777 * buffer for all disks. Ok for now since we only look at the global
2778 * bbm_log_size parameter to gate assembly
2780 super
->bbm_log
= __get_imsm_bbm_log(super
->anchor
);
2786 load_and_parse_mpb(int fd
, struct intel_super
*super
, char *devname
, int keep_fd
)
2790 err
= load_imsm_mpb(fd
, super
, devname
);
2793 err
= load_imsm_disk(fd
, super
, devname
, keep_fd
);
2796 err
= parse_raid_devices(super
);
2801 static void __free_imsm_disk(struct dl
*d
)
2813 static void free_imsm_disks(struct intel_super
*super
)
2817 while (super
->disks
) {
2819 super
->disks
= d
->next
;
2820 __free_imsm_disk(d
);
2822 while (super
->disk_mgmt_list
) {
2823 d
= super
->disk_mgmt_list
;
2824 super
->disk_mgmt_list
= d
->next
;
2825 __free_imsm_disk(d
);
2827 while (super
->missing
) {
2829 super
->missing
= d
->next
;
2830 __free_imsm_disk(d
);
2835 /* free all the pieces hanging off of a super pointer */
2836 static void __free_imsm(struct intel_super
*super
, int free_disks
)
2838 struct intel_hba
*elem
, *next
;
2844 /* unlink capability description */
2847 free_imsm_disks(super
);
2848 free_devlist(super
);
2852 free((void *)elem
->path
);
2860 static void free_imsm(struct intel_super
*super
)
2862 __free_imsm(super
, 1);
2866 static void free_super_imsm(struct supertype
*st
)
2868 struct intel_super
*super
= st
->sb
;
2877 static struct intel_super
*alloc_super(void)
2879 struct intel_super
*super
= malloc(sizeof(*super
));
2882 memset(super
, 0, sizeof(*super
));
2883 super
->current_vol
= -1;
2884 super
->create_offset
= ~((__u32
) 0);
2890 * find and allocate hba and OROM/EFI based on valid fd of RAID component device
2892 static int find_intel_hba_capability(int fd
, struct intel_super
*super
, char *devname
)
2894 struct sys_dev
*hba_name
;
2897 if ((fd
< 0) || check_env("IMSM_NO_PLATFORM")) {
2902 hba_name
= find_disk_attached_hba(fd
, NULL
);
2906 Name
": %s is not attached to Intel(R) RAID controller.\n",
2910 rv
= attach_hba_to_super(super
, hba_name
);
2913 struct intel_hba
*hba
= super
->hba
;
2915 fprintf(stderr
, Name
": %s is attached to Intel(R) %s RAID "
2916 "controller (%s),\n"
2917 " but the container is assigned to Intel(R) "
2918 "%s RAID controller (",
2921 hba_name
->pci_id
? : "Err!",
2922 get_sys_dev_type(hba_name
->type
));
2925 fprintf(stderr
, "%s", hba
->pci_id
? : "Err!");
2927 fprintf(stderr
, ", ");
2931 fprintf(stderr
, ").\n"
2932 " Mixing devices attached to different controllers "
2933 "is not allowed.\n");
2935 free_sys_dev(&hba_name
);
2938 super
->orom
= find_imsm_capability(hba_name
->type
);
2939 free_sys_dev(&hba_name
);
2946 /* find_missing - helper routine for load_super_imsm_all that identifies
2947 * disks that have disappeared from the system. This routine relies on
2948 * the mpb being uptodate, which it is at load time.
2950 static int find_missing(struct intel_super
*super
)
2953 struct imsm_super
*mpb
= super
->anchor
;
2955 struct imsm_disk
*disk
;
2957 for (i
= 0; i
< mpb
->num_disks
; i
++) {
2958 disk
= __get_imsm_disk(mpb
, i
);
2959 dl
= serial_to_dl(disk
->serial
, super
);
2963 dl
= malloc(sizeof(*dl
));
2969 dl
->devname
= strdup("missing");
2971 serialcpy(dl
->serial
, disk
->serial
);
2974 dl
->next
= super
->missing
;
2975 super
->missing
= dl
;
2981 static struct intel_disk
*disk_list_get(__u8
*serial
, struct intel_disk
*disk_list
)
2983 struct intel_disk
*idisk
= disk_list
;
2986 if (serialcmp(idisk
->disk
.serial
, serial
) == 0)
2988 idisk
= idisk
->next
;
2994 static int __prep_thunderdome(struct intel_super
**table
, int tbl_size
,
2995 struct intel_super
*super
,
2996 struct intel_disk
**disk_list
)
2998 struct imsm_disk
*d
= &super
->disks
->disk
;
2999 struct imsm_super
*mpb
= super
->anchor
;
3002 for (i
= 0; i
< tbl_size
; i
++) {
3003 struct imsm_super
*tbl_mpb
= table
[i
]->anchor
;
3004 struct imsm_disk
*tbl_d
= &table
[i
]->disks
->disk
;
3006 if (tbl_mpb
->family_num
== mpb
->family_num
) {
3007 if (tbl_mpb
->check_sum
== mpb
->check_sum
) {
3008 dprintf("%s: mpb from %d:%d matches %d:%d\n",
3009 __func__
, super
->disks
->major
,
3010 super
->disks
->minor
,
3011 table
[i
]->disks
->major
,
3012 table
[i
]->disks
->minor
);
3016 if (((is_configured(d
) && !is_configured(tbl_d
)) ||
3017 is_configured(d
) == is_configured(tbl_d
)) &&
3018 tbl_mpb
->generation_num
< mpb
->generation_num
) {
3019 /* current version of the mpb is a
3020 * better candidate than the one in
3021 * super_table, but copy over "cross
3022 * generational" status
3024 struct intel_disk
*idisk
;
3026 dprintf("%s: mpb from %d:%d replaces %d:%d\n",
3027 __func__
, super
->disks
->major
,
3028 super
->disks
->minor
,
3029 table
[i
]->disks
->major
,
3030 table
[i
]->disks
->minor
);
3032 idisk
= disk_list_get(tbl_d
->serial
, *disk_list
);
3033 if (idisk
&& is_failed(&idisk
->disk
))
3034 tbl_d
->status
|= FAILED_DISK
;
3037 struct intel_disk
*idisk
;
3038 struct imsm_disk
*disk
;
3040 /* tbl_mpb is more up to date, but copy
3041 * over cross generational status before
3044 disk
= __serial_to_disk(d
->serial
, mpb
, NULL
);
3045 if (disk
&& is_failed(disk
))
3046 d
->status
|= FAILED_DISK
;
3048 idisk
= disk_list_get(d
->serial
, *disk_list
);
3051 if (disk
&& is_configured(disk
))
3052 idisk
->disk
.status
|= CONFIGURED_DISK
;
3055 dprintf("%s: mpb from %d:%d prefer %d:%d\n",
3056 __func__
, super
->disks
->major
,
3057 super
->disks
->minor
,
3058 table
[i
]->disks
->major
,
3059 table
[i
]->disks
->minor
);
3067 table
[tbl_size
++] = super
;
3071 /* update/extend the merged list of imsm_disk records */
3072 for (j
= 0; j
< mpb
->num_disks
; j
++) {
3073 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, j
);
3074 struct intel_disk
*idisk
;
3076 idisk
= disk_list_get(disk
->serial
, *disk_list
);
3078 idisk
->disk
.status
|= disk
->status
;
3079 if (is_configured(&idisk
->disk
) ||
3080 is_failed(&idisk
->disk
))
3081 idisk
->disk
.status
&= ~(SPARE_DISK
);
3083 idisk
= calloc(1, sizeof(*idisk
));
3086 idisk
->owner
= IMSM_UNKNOWN_OWNER
;
3087 idisk
->disk
= *disk
;
3088 idisk
->next
= *disk_list
;
3092 if (serialcmp(idisk
->disk
.serial
, d
->serial
) == 0)
3099 static struct intel_super
*
3100 validate_members(struct intel_super
*super
, struct intel_disk
*disk_list
,
3103 struct imsm_super
*mpb
= super
->anchor
;
3107 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3108 struct imsm_disk
*disk
= __get_imsm_disk(mpb
, i
);
3109 struct intel_disk
*idisk
;
3111 idisk
= disk_list_get(disk
->serial
, disk_list
);
3113 if (idisk
->owner
== owner
||
3114 idisk
->owner
== IMSM_UNKNOWN_OWNER
)
3117 dprintf("%s: '%.16s' owner %d != %d\n",
3118 __func__
, disk
->serial
, idisk
->owner
,
3121 dprintf("%s: unknown disk %x [%d]: %.16s\n",
3122 __func__
, __le32_to_cpu(mpb
->family_num
), i
,
3128 if (ok_count
== mpb
->num_disks
)
3133 static void show_conflicts(__u32 family_num
, struct intel_super
*super_list
)
3135 struct intel_super
*s
;
3137 for (s
= super_list
; s
; s
= s
->next
) {
3138 if (family_num
!= s
->anchor
->family_num
)
3140 fprintf(stderr
, "Conflict, offlining family %#x on '%s'\n",
3141 __le32_to_cpu(family_num
), s
->disks
->devname
);
3145 static struct intel_super
*
3146 imsm_thunderdome(struct intel_super
**super_list
, int len
)
3148 struct intel_super
*super_table
[len
];
3149 struct intel_disk
*disk_list
= NULL
;
3150 struct intel_super
*champion
, *spare
;
3151 struct intel_super
*s
, **del
;
3156 memset(super_table
, 0, sizeof(super_table
));
3157 for (s
= *super_list
; s
; s
= s
->next
)
3158 tbl_size
= __prep_thunderdome(super_table
, tbl_size
, s
, &disk_list
);
3160 for (i
= 0; i
< tbl_size
; i
++) {
3161 struct imsm_disk
*d
;
3162 struct intel_disk
*idisk
;
3163 struct imsm_super
*mpb
= super_table
[i
]->anchor
;
3166 d
= &s
->disks
->disk
;
3168 /* 'd' must appear in merged disk list for its
3169 * configuration to be valid
3171 idisk
= disk_list_get(d
->serial
, disk_list
);
3172 if (idisk
&& idisk
->owner
== i
)
3173 s
= validate_members(s
, disk_list
, i
);
3178 dprintf("%s: marking family: %#x from %d:%d offline\n",
3179 __func__
, mpb
->family_num
,
3180 super_table
[i
]->disks
->major
,
3181 super_table
[i
]->disks
->minor
);
3185 /* This is where the mdadm implementation differs from the Windows
3186 * driver which has no strict concept of a container. We can only
3187 * assemble one family from a container, so when returning a prodigal
3188 * array member to this system the code will not be able to disambiguate
3189 * the container contents that should be assembled ("foreign" versus
3190 * "local"). It requires user intervention to set the orig_family_num
3191 * to a new value to establish a new container. The Windows driver in
3192 * this situation fixes up the volume name in place and manages the
3193 * foreign array as an independent entity.
3198 for (i
= 0; i
< tbl_size
; i
++) {
3199 struct intel_super
*tbl_ent
= super_table
[i
];
3205 if (tbl_ent
->anchor
->num_raid_devs
== 0) {
3210 if (s
&& !is_spare
) {
3211 show_conflicts(tbl_ent
->anchor
->family_num
, *super_list
);
3213 } else if (!s
&& !is_spare
)
3226 fprintf(stderr
, "Chose family %#x on '%s', "
3227 "assemble conflicts to new container with '--update=uuid'\n",
3228 __le32_to_cpu(s
->anchor
->family_num
), s
->disks
->devname
);
3230 /* collect all dl's onto 'champion', and update them to
3231 * champion's version of the status
3233 for (s
= *super_list
; s
; s
= s
->next
) {
3234 struct imsm_super
*mpb
= champion
->anchor
;
3235 struct dl
*dl
= s
->disks
;
3240 for (i
= 0; i
< mpb
->num_disks
; i
++) {
3241 struct imsm_disk
*disk
;
3243 disk
= __serial_to_disk(dl
->serial
, mpb
, &dl
->index
);
3246 /* only set index on disks that are a member of
3247 * a populated contianer, i.e. one with
3250 if (is_failed(&dl
->disk
))
3252 else if (is_spare(&dl
->disk
))
3258 if (i
>= mpb
->num_disks
) {
3259 struct intel_disk
*idisk
;
3261 idisk
= disk_list_get(dl
->serial
, disk_list
);
3262 if (idisk
&& is_spare(&idisk
->disk
) &&
3263 !is_failed(&idisk
->disk
) && !is_configured(&idisk
->disk
))
3271 dl
->next
= champion
->disks
;
3272 champion
->disks
= dl
;
3276 /* delete 'champion' from super_list */
3277 for (del
= super_list
; *del
; ) {
3278 if (*del
== champion
) {
3279 *del
= (*del
)->next
;
3282 del
= &(*del
)->next
;
3284 champion
->next
= NULL
;
3288 struct intel_disk
*idisk
= disk_list
;
3290 disk_list
= disk_list
->next
;
3297 static int load_super_imsm_all(struct supertype
*st
, int fd
, void **sbp
,
3301 struct intel_super
*super_list
= NULL
;
3302 struct intel_super
*super
= NULL
;
3303 int devnum
= fd2devnum(fd
);
3309 /* check if 'fd' an opened container */
3310 sra
= sysfs_read(fd
, 0, GET_LEVEL
|GET_VERSION
|GET_DEVS
|GET_STATE
);
3314 if (sra
->array
.major_version
!= -1 ||
3315 sra
->array
.minor_version
!= -2 ||
3316 strcmp(sra
->text_version
, "imsm") != 0) {
3321 for (sd
= sra
->devs
, i
= 0; sd
; sd
= sd
->next
, i
++) {
3322 struct intel_super
*s
= alloc_super();
3330 s
->next
= super_list
;
3334 sprintf(nm
, "%d:%d", sd
->disk
.major
, sd
->disk
.minor
);
3335 dfd
= dev_open(nm
, O_RDWR
);
3339 rv
= find_intel_hba_capability(dfd
, s
, devname
);
3340 /* no orom/efi or non-intel hba of the disk */
3344 err
= load_and_parse_mpb(dfd
, s
, NULL
, 1);
3346 /* retry the load if we might have raced against mdmon */
3347 if (err
== 3 && mdmon_running(devnum
))
3348 for (retry
= 0; retry
< 3; retry
++) {
3350 err
= load_and_parse_mpb(dfd
, s
, NULL
, 1);
3358 /* all mpbs enter, maybe one leaves */
3359 super
= imsm_thunderdome(&super_list
, i
);
3365 if (find_missing(super
) != 0) {
3373 while (super_list
) {
3374 struct intel_super
*s
= super_list
;
3376 super_list
= super_list
->next
;
3385 st
->container_dev
= devnum
;
3386 if (err
== 0 && st
->ss
== NULL
) {
3387 st
->ss
= &super_imsm
;
3388 st
->minor_version
= 0;
3389 st
->max_devs
= IMSM_MAX_DEVICES
;
3394 static int load_container_imsm(struct supertype
*st
, int fd
, char *devname
)
3396 return load_super_imsm_all(st
, fd
, &st
->sb
, devname
);
3400 static int load_super_imsm(struct supertype
*st
, int fd
, char *devname
)
3402 struct intel_super
*super
;
3405 if (test_partition(fd
))
3406 /* IMSM not allowed on partitions */
3409 free_super_imsm(st
);
3411 super
= alloc_super();
3414 Name
": malloc of %zu failed.\n",
3418 /* Load hba and capabilities if they exist.
3419 * But do not preclude loading metadata in case capabilities or hba are
3420 * non-compliant and ignore_hw_compat is set.
3422 rv
= find_intel_hba_capability(fd
, super
, devname
);
3423 /* no orom/efi or non-intel hba of the disk */
3424 if ((rv
!= 0) && (st
->ignore_hw_compat
== 0)) {
3427 Name
": No OROM/EFI properties for %s\n", devname
);
3431 rv
= load_and_parse_mpb(fd
, super
, devname
, 0);
3436 Name
": Failed to load all information "
3437 "sections on %s\n", devname
);
3443 if (st
->ss
== NULL
) {
3444 st
->ss
= &super_imsm
;
3445 st
->minor_version
= 0;
3446 st
->max_devs
= IMSM_MAX_DEVICES
;
3451 static __u16
info_to_blocks_per_strip(mdu_array_info_t
*info
)
3453 if (info
->level
== 1)
3455 return info
->chunk_size
>> 9;
3458 static __u32
info_to_num_data_stripes(mdu_array_info_t
*info
, int num_domains
)
3462 num_stripes
= (info
->size
* 2) / info_to_blocks_per_strip(info
);
3463 num_stripes
/= num_domains
;
3468 static __u32
info_to_blocks_per_member(mdu_array_info_t
*info
)
3470 if (info
->level
== 1)
3471 return info
->size
* 2;
3473 return (info
->size
* 2) & ~(info_to_blocks_per_strip(info
) - 1);
3476 static void imsm_update_version_info(struct intel_super
*super
)
3478 /* update the version and attributes */
3479 struct imsm_super
*mpb
= super
->anchor
;
3481 struct imsm_dev
*dev
;
3482 struct imsm_map
*map
;
3485 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
3486 dev
= get_imsm_dev(super
, i
);
3487 map
= get_imsm_map(dev
, 0);
3488 if (__le32_to_cpu(dev
->size_high
) > 0)
3489 mpb
->attributes
|= MPB_ATTRIB_2TB
;
3491 /* FIXME detect when an array spans a port multiplier */
3493 mpb
->attributes
|= MPB_ATTRIB_PM
;
3496 if (mpb
->num_raid_devs
> 1 ||
3497 mpb
->attributes
!= MPB_ATTRIB_CHECKSUM_VERIFY
) {
3498 version
= MPB_VERSION_ATTRIBS
;
3499 switch (get_imsm_raid_level(map
)) {
3500 case 0: mpb
->attributes
|= MPB_ATTRIB_RAID0
; break;
3501 case 1: mpb
->attributes
|= MPB_ATTRIB_RAID1
; break;
3502 case 10: mpb
->attributes
|= MPB_ATTRIB_RAID10
; break;
3503 case 5: mpb
->attributes
|= MPB_ATTRIB_RAID5
; break;
3506 if (map
->num_members
>= 5)
3507 version
= MPB_VERSION_5OR6_DISK_ARRAY
;
3508 else if (dev
->status
== DEV_CLONE_N_GO
)
3509 version
= MPB_VERSION_CNG
;
3510 else if (get_imsm_raid_level(map
) == 5)
3511 version
= MPB_VERSION_RAID5
;
3512 else if (map
->num_members
>= 3)
3513 version
= MPB_VERSION_3OR4_DISK_ARRAY
;
3514 else if (get_imsm_raid_level(map
) == 1)
3515 version
= MPB_VERSION_RAID1
;
3517 version
= MPB_VERSION_RAID0
;
3519 strcpy(((char *) mpb
->sig
) + strlen(MPB_SIGNATURE
), version
);
3523 static int check_name(struct intel_super
*super
, char *name
, int quiet
)
3525 struct imsm_super
*mpb
= super
->anchor
;
3526 char *reason
= NULL
;
3529 if (strlen(name
) > MAX_RAID_SERIAL_LEN
)
3530 reason
= "must be 16 characters or less";
3532 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
3533 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
3535 if (strncmp((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
) == 0) {
3536 reason
= "already exists";
3541 if (reason
&& !quiet
)
3542 fprintf(stderr
, Name
": imsm volume name %s\n", reason
);
3547 static int init_super_imsm_volume(struct supertype
*st
, mdu_array_info_t
*info
,
3548 unsigned long long size
, char *name
,
3549 char *homehost
, int *uuid
)
3551 /* We are creating a volume inside a pre-existing container.
3552 * so st->sb is already set.
3554 struct intel_super
*super
= st
->sb
;
3555 struct imsm_super
*mpb
= super
->anchor
;
3556 struct intel_dev
*dv
;
3557 struct imsm_dev
*dev
;
3558 struct imsm_vol
*vol
;
3559 struct imsm_map
*map
;
3560 int idx
= mpb
->num_raid_devs
;
3562 unsigned long long array_blocks
;
3563 size_t size_old
, size_new
;
3564 __u32 num_data_stripes
;
3566 if (super
->orom
&& mpb
->num_raid_devs
>= super
->orom
->vpa
) {
3567 fprintf(stderr
, Name
": This imsm-container already has the "
3568 "maximum of %d volumes\n", super
->orom
->vpa
);
3572 /* ensure the mpb is large enough for the new data */
3573 size_old
= __le32_to_cpu(mpb
->mpb_size
);
3574 size_new
= disks_to_mpb_size(info
->nr_disks
);
3575 if (size_new
> size_old
) {
3577 size_t size_round
= ROUND_UP(size_new
, 512);
3579 if (posix_memalign(&mpb_new
, 512, size_round
) != 0) {
3580 fprintf(stderr
, Name
": could not allocate new mpb\n");
3583 memcpy(mpb_new
, mpb
, size_old
);
3586 super
->anchor
= mpb_new
;
3587 mpb
->mpb_size
= __cpu_to_le32(size_new
);
3588 memset(mpb_new
+ size_old
, 0, size_round
- size_old
);
3590 super
->current_vol
= idx
;
3591 /* when creating the first raid device in this container set num_disks
3592 * to zero, i.e. delete this spare and add raid member devices in
3593 * add_to_super_imsm_volume()
3595 if (super
->current_vol
== 0)
3598 if (!check_name(super
, name
, 0))
3600 dv
= malloc(sizeof(*dv
));
3602 fprintf(stderr
, Name
": failed to allocate device list entry\n");
3605 dev
= calloc(1, sizeof(*dev
) + sizeof(__u32
) * (info
->raid_disks
- 1));
3608 fprintf(stderr
, Name
": could not allocate raid device\n");
3612 strncpy((char *) dev
->volume
, name
, MAX_RAID_SERIAL_LEN
);
3613 if (info
->level
== 1)
3614 array_blocks
= info_to_blocks_per_member(info
);
3616 array_blocks
= calc_array_size(info
->level
, info
->raid_disks
,
3617 info
->layout
, info
->chunk_size
,
3619 /* round array size down to closest MB */
3620 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
3622 dev
->size_low
= __cpu_to_le32((__u32
) array_blocks
);
3623 dev
->size_high
= __cpu_to_le32((__u32
) (array_blocks
>> 32));
3624 dev
->status
= (DEV_READ_COALESCING
| DEV_WRITE_COALESCING
);
3626 vol
->migr_state
= 0;
3627 set_migr_type(dev
, MIGR_INIT
);
3629 vol
->curr_migr_unit
= 0;
3630 map
= get_imsm_map(dev
, 0);
3631 map
->pba_of_lba0
= __cpu_to_le32(super
->create_offset
);
3632 map
->blocks_per_member
= __cpu_to_le32(info_to_blocks_per_member(info
));
3633 map
->blocks_per_strip
= __cpu_to_le16(info_to_blocks_per_strip(info
));
3634 map
->failed_disk_num
= ~0;
3635 map
->map_state
= info
->level
? IMSM_T_STATE_UNINITIALIZED
:
3636 IMSM_T_STATE_NORMAL
;
3639 if (info
->level
== 1 && info
->raid_disks
> 2) {
3642 fprintf(stderr
, Name
": imsm does not support more than 2 disks"
3643 "in a raid1 volume\n");
3647 map
->raid_level
= info
->level
;
3648 if (info
->level
== 10) {
3649 map
->raid_level
= 1;
3650 map
->num_domains
= info
->raid_disks
/ 2;
3651 } else if (info
->level
== 1)
3652 map
->num_domains
= info
->raid_disks
;
3654 map
->num_domains
= 1;
3656 num_data_stripes
= info_to_num_data_stripes(info
, map
->num_domains
);
3657 map
->num_data_stripes
= __cpu_to_le32(num_data_stripes
);
3659 map
->num_members
= info
->raid_disks
;
3660 for (i
= 0; i
< map
->num_members
; i
++) {
3661 /* initialized in add_to_super */
3662 set_imsm_ord_tbl_ent(map
, i
, IMSM_ORD_REBUILD
);
3664 mpb
->num_raid_devs
++;
3667 dv
->index
= super
->current_vol
;
3668 dv
->next
= super
->devlist
;
3669 super
->devlist
= dv
;
3671 imsm_update_version_info(super
);
3676 static int init_super_imsm(struct supertype
*st
, mdu_array_info_t
*info
,
3677 unsigned long long size
, char *name
,
3678 char *homehost
, int *uuid
)
3680 /* This is primarily called by Create when creating a new array.
3681 * We will then get add_to_super called for each component, and then
3682 * write_init_super called to write it out to each device.
3683 * For IMSM, Create can create on fresh devices or on a pre-existing
3685 * To create on a pre-existing array a different method will be called.
3686 * This one is just for fresh drives.
3688 struct intel_super
*super
;
3689 struct imsm_super
*mpb
;
3694 return init_super_imsm_volume(st
, info
, size
, name
, homehost
, uuid
);
3697 mpb_size
= disks_to_mpb_size(info
->nr_disks
);
3701 super
= alloc_super();
3702 if (super
&& posix_memalign(&super
->buf
, 512, mpb_size
) != 0) {
3707 fprintf(stderr
, Name
3708 ": %s could not allocate superblock\n", __func__
);
3711 memset(super
->buf
, 0, mpb_size
);
3713 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
3717 /* zeroing superblock */
3721 mpb
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
3723 version
= (char *) mpb
->sig
;
3724 strcpy(version
, MPB_SIGNATURE
);
3725 version
+= strlen(MPB_SIGNATURE
);
3726 strcpy(version
, MPB_VERSION_RAID0
);
3732 static int add_to_super_imsm_volume(struct supertype
*st
, mdu_disk_info_t
*dk
,
3733 int fd
, char *devname
)
3735 struct intel_super
*super
= st
->sb
;
3736 struct imsm_super
*mpb
= super
->anchor
;
3738 struct imsm_dev
*dev
;
3739 struct imsm_map
*map
;
3742 dev
= get_imsm_dev(super
, super
->current_vol
);
3743 map
= get_imsm_map(dev
, 0);
3745 if (! (dk
->state
& (1<<MD_DISK_SYNC
))) {
3746 fprintf(stderr
, Name
": %s: Cannot add spare devices to IMSM volume\n",
3752 /* we're doing autolayout so grab the pre-marked (in
3753 * validate_geometry) raid_disk
3755 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3756 if (dl
->raiddisk
== dk
->raid_disk
)
3759 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
3760 if (dl
->major
== dk
->major
&&
3761 dl
->minor
== dk
->minor
)
3766 fprintf(stderr
, Name
": %s is not a member of the same container\n", devname
);
3770 /* add a pristine spare to the metadata */
3771 if (dl
->index
< 0) {
3772 dl
->index
= super
->anchor
->num_disks
;
3773 super
->anchor
->num_disks
++;
3775 /* Check the device has not already been added */
3776 slot
= get_imsm_disk_slot(map
, dl
->index
);
3778 (get_imsm_ord_tbl_ent(dev
, slot
, -1) & IMSM_ORD_REBUILD
) == 0) {
3779 fprintf(stderr
, Name
": %s has been included in this array twice\n",
3783 set_imsm_ord_tbl_ent(map
, dk
->number
, dl
->index
);
3784 dl
->disk
.status
= CONFIGURED_DISK
;
3786 /* if we are creating the first raid device update the family number */
3787 if (super
->current_vol
== 0) {
3789 struct imsm_dev
*_dev
= __get_imsm_dev(mpb
, 0);
3790 struct imsm_disk
*_disk
= __get_imsm_disk(mpb
, dl
->index
);
3792 if (!_dev
|| !_disk
) {
3793 fprintf(stderr
, Name
": BUG mpb setup error\n");
3799 sum
+= __gen_imsm_checksum(mpb
);
3800 mpb
->family_num
= __cpu_to_le32(sum
);
3801 mpb
->orig_family_num
= mpb
->family_num
;
3808 static int add_to_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
,
3809 int fd
, char *devname
)
3811 struct intel_super
*super
= st
->sb
;
3813 unsigned long long size
;
3818 /* If we are on an RAID enabled platform check that the disk is
3819 * attached to the raid controller.
3820 * We do not need to test disks attachment for container based additions,
3821 * they shall be already tested when container was created/assembled.
3823 rv
= find_intel_hba_capability(fd
, super
, devname
);
3824 /* no orom/efi or non-intel hba of the disk */
3826 dprintf("capability: %p fd: %d ret: %d\n",
3827 super
->orom
, fd
, rv
);
3831 if (super
->current_vol
>= 0)
3832 return add_to_super_imsm_volume(st
, dk
, fd
, devname
);
3835 dd
= malloc(sizeof(*dd
));
3838 Name
": malloc failed %s:%d.\n", __func__
, __LINE__
);
3841 memset(dd
, 0, sizeof(*dd
));
3842 dd
->major
= major(stb
.st_rdev
);
3843 dd
->minor
= minor(stb
.st_rdev
);
3845 dd
->devname
= devname
? strdup(devname
) : NULL
;
3848 dd
->action
= DISK_ADD
;
3849 rv
= imsm_read_serial(fd
, devname
, dd
->serial
);
3852 Name
": failed to retrieve scsi serial, aborting\n");
3857 get_dev_size(fd
, NULL
, &size
);
3859 serialcpy(dd
->disk
.serial
, dd
->serial
);
3860 dd
->disk
.total_blocks
= __cpu_to_le32(size
);
3861 dd
->disk
.status
= SPARE_DISK
;
3862 if (sysfs_disk_to_scsi_id(fd
, &id
) == 0)
3863 dd
->disk
.scsi_id
= __cpu_to_le32(id
);
3865 dd
->disk
.scsi_id
= __cpu_to_le32(0);
3867 if (st
->update_tail
) {
3868 dd
->next
= super
->disk_mgmt_list
;
3869 super
->disk_mgmt_list
= dd
;
3871 dd
->next
= super
->disks
;
3873 super
->updates_pending
++;
3880 static int remove_from_super_imsm(struct supertype
*st
, mdu_disk_info_t
*dk
)
3882 struct intel_super
*super
= st
->sb
;
3885 /* remove from super works only in mdmon - for communication
3886 * manager - monitor. Check if communication memory buffer
3889 if (!st
->update_tail
) {
3891 Name
": %s shall be used in mdmon context only"
3892 "(line %d).\n", __func__
, __LINE__
);
3895 dd
= malloc(sizeof(*dd
));
3898 Name
": malloc failed %s:%d.\n", __func__
, __LINE__
);
3901 memset(dd
, 0, sizeof(*dd
));
3902 dd
->major
= dk
->major
;
3903 dd
->minor
= dk
->minor
;
3906 dd
->disk
.status
= SPARE_DISK
;
3907 dd
->action
= DISK_REMOVE
;
3909 dd
->next
= super
->disk_mgmt_list
;
3910 super
->disk_mgmt_list
= dd
;
3916 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
);
3920 struct imsm_super anchor
;
3921 } spare_record
__attribute__ ((aligned(512)));
3923 /* spare records have their own family number and do not have any defined raid
3926 static int write_super_imsm_spares(struct intel_super
*super
, int doclose
)
3928 struct imsm_super
*mpb
= super
->anchor
;
3929 struct imsm_super
*spare
= &spare_record
.anchor
;
3933 spare
->mpb_size
= __cpu_to_le32(sizeof(struct imsm_super
)),
3934 spare
->generation_num
= __cpu_to_le32(1UL),
3935 spare
->attributes
= MPB_ATTRIB_CHECKSUM_VERIFY
;
3936 spare
->num_disks
= 1,
3937 spare
->num_raid_devs
= 0,
3938 spare
->cache_size
= mpb
->cache_size
,
3939 spare
->pwr_cycle_count
= __cpu_to_le32(1),
3941 snprintf((char *) spare
->sig
, MAX_SIGNATURE_LENGTH
,
3942 MPB_SIGNATURE MPB_VERSION_RAID0
);
3944 for (d
= super
->disks
; d
; d
= d
->next
) {
3948 spare
->disk
[0] = d
->disk
;
3949 sum
= __gen_imsm_checksum(spare
);
3950 spare
->family_num
= __cpu_to_le32(sum
);
3951 spare
->orig_family_num
= 0;
3952 sum
= __gen_imsm_checksum(spare
);
3953 spare
->check_sum
= __cpu_to_le32(sum
);
3955 if (store_imsm_mpb(d
->fd
, spare
)) {
3956 fprintf(stderr
, "%s: failed for device %d:%d %s\n",
3957 __func__
, d
->major
, d
->minor
, strerror(errno
));
3969 static int write_super_imsm(struct supertype
*st
, int doclose
)
3971 struct intel_super
*super
= st
->sb
;
3972 struct imsm_super
*mpb
= super
->anchor
;
3978 __u32 mpb_size
= sizeof(struct imsm_super
) - sizeof(struct imsm_disk
);
3981 /* 'generation' is incremented everytime the metadata is written */
3982 generation
= __le32_to_cpu(mpb
->generation_num
);
3984 mpb
->generation_num
= __cpu_to_le32(generation
);
3986 /* fix up cases where previous mdadm releases failed to set
3989 if (mpb
->orig_family_num
== 0)
3990 mpb
->orig_family_num
= mpb
->family_num
;
3992 for (d
= super
->disks
; d
; d
= d
->next
) {
3996 mpb
->disk
[d
->index
] = d
->disk
;
4000 for (d
= super
->missing
; d
; d
= d
->next
) {
4001 mpb
->disk
[d
->index
] = d
->disk
;
4004 mpb
->num_disks
= num_disks
;
4005 mpb_size
+= sizeof(struct imsm_disk
) * mpb
->num_disks
;
4007 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4008 struct imsm_dev
*dev
= __get_imsm_dev(mpb
, i
);
4009 struct imsm_dev
*dev2
= get_imsm_dev(super
, i
);
4011 imsm_copy_dev(dev
, dev2
);
4012 mpb_size
+= sizeof_imsm_dev(dev
, 0);
4015 mpb_size
+= __le32_to_cpu(mpb
->bbm_log_size
);
4016 mpb
->mpb_size
= __cpu_to_le32(mpb_size
);
4018 /* recalculate checksum */
4019 sum
= __gen_imsm_checksum(mpb
);
4020 mpb
->check_sum
= __cpu_to_le32(sum
);
4022 /* write the mpb for disks that compose raid devices */
4023 for (d
= super
->disks
; d
; d
= d
->next
) {
4026 if (store_imsm_mpb(d
->fd
, mpb
))
4027 fprintf(stderr
, "%s: failed for device %d:%d %s\n",
4028 __func__
, d
->major
, d
->minor
, strerror(errno
));
4036 return write_super_imsm_spares(super
, doclose
);
4042 static int create_array(struct supertype
*st
, int dev_idx
)
4045 struct imsm_update_create_array
*u
;
4046 struct intel_super
*super
= st
->sb
;
4047 struct imsm_dev
*dev
= get_imsm_dev(super
, dev_idx
);
4048 struct imsm_map
*map
= get_imsm_map(dev
, 0);
4049 struct disk_info
*inf
;
4050 struct imsm_disk
*disk
;
4053 len
= sizeof(*u
) - sizeof(*dev
) + sizeof_imsm_dev(dev
, 0) +
4054 sizeof(*inf
) * map
->num_members
;
4057 fprintf(stderr
, "%s: failed to allocate update buffer\n",
4062 u
->type
= update_create_array
;
4063 u
->dev_idx
= dev_idx
;
4064 imsm_copy_dev(&u
->dev
, dev
);
4065 inf
= get_disk_info(u
);
4066 for (i
= 0; i
< map
->num_members
; i
++) {
4067 int idx
= get_imsm_disk_idx(dev
, i
, -1);
4069 disk
= get_imsm_disk(super
, idx
);
4070 serialcpy(inf
[i
].serial
, disk
->serial
);
4072 append_metadata_update(st
, u
, len
);
4077 static int mgmt_disk(struct supertype
*st
)
4079 struct intel_super
*super
= st
->sb
;
4081 struct imsm_update_add_remove_disk
*u
;
4083 if (!super
->disk_mgmt_list
)
4089 fprintf(stderr
, "%s: failed to allocate update buffer\n",
4094 u
->type
= update_add_remove_disk
;
4095 append_metadata_update(st
, u
, len
);
4100 static int write_init_super_imsm(struct supertype
*st
)
4102 struct intel_super
*super
= st
->sb
;
4103 int current_vol
= super
->current_vol
;
4105 /* we are done with current_vol reset it to point st at the container */
4106 super
->current_vol
= -1;
4108 if (st
->update_tail
) {
4109 /* queue the recently created array / added disk
4110 * as a metadata update */
4113 /* determine if we are creating a volume or adding a disk */
4114 if (current_vol
< 0) {
4115 /* in the mgmt (add/remove) disk case we are running
4116 * in mdmon context, so don't close fd's
4118 return mgmt_disk(st
);
4120 rv
= create_array(st
, current_vol
);
4125 for (d
= super
->disks
; d
; d
= d
->next
)
4126 Kill(d
->devname
, NULL
, 0, 1, 1);
4127 return write_super_imsm(st
, 1);
4132 static int store_super_imsm(struct supertype
*st
, int fd
)
4134 struct intel_super
*super
= st
->sb
;
4135 struct imsm_super
*mpb
= super
? super
->anchor
: NULL
;
4141 return store_imsm_mpb(fd
, mpb
);
4147 static int imsm_bbm_log_size(struct imsm_super
*mpb
)
4149 return __le32_to_cpu(mpb
->bbm_log_size
);
4153 static int validate_geometry_imsm_container(struct supertype
*st
, int level
,
4154 int layout
, int raiddisks
, int chunk
,
4155 unsigned long long size
, char *dev
,
4156 unsigned long long *freesize
,
4160 unsigned long long ldsize
;
4161 struct intel_super
*super
=NULL
;
4164 if (level
!= LEVEL_CONTAINER
)
4169 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
4172 fprintf(stderr
, Name
": imsm: Cannot open %s: %s\n",
4173 dev
, strerror(errno
));
4176 if (!get_dev_size(fd
, dev
, &ldsize
)) {
4181 /* capabilities retrieve could be possible
4182 * note that there is no fd for the disks in array.
4184 super
= alloc_super();
4187 Name
": malloc of %zu failed.\n",
4193 rv
= find_intel_hba_capability(fd
, super
, verbose
? dev
: NULL
);
4197 fd2devname(fd
, str
);
4198 dprintf("validate_geometry_imsm_container: fd: %d %s orom: %p rv: %d raiddisk: %d\n",
4199 fd
, str
, super
->orom
, rv
, raiddisks
);
4201 /* no orom/efi or non-intel hba of the disk */
4207 if (super
->orom
&& raiddisks
> super
->orom
->tds
) {
4209 fprintf(stderr
, Name
": %d exceeds maximum number of"
4210 " platform supported disks: %d\n",
4211 raiddisks
, super
->orom
->tds
);
4217 *freesize
= avail_size_imsm(st
, ldsize
>> 9);
4223 static unsigned long long find_size(struct extent
*e
, int *idx
, int num_extents
)
4225 const unsigned long long base_start
= e
[*idx
].start
;
4226 unsigned long long end
= base_start
+ e
[*idx
].size
;
4229 if (base_start
== end
)
4233 for (i
= *idx
; i
< num_extents
; i
++) {
4234 /* extend overlapping extents */
4235 if (e
[i
].start
>= base_start
&&
4236 e
[i
].start
<= end
) {
4239 if (e
[i
].start
+ e
[i
].size
> end
)
4240 end
= e
[i
].start
+ e
[i
].size
;
4241 } else if (e
[i
].start
> end
) {
4247 return end
- base_start
;
4250 static unsigned long long merge_extents(struct intel_super
*super
, int sum_extents
)
4252 /* build a composite disk with all known extents and generate a new
4253 * 'maxsize' given the "all disks in an array must share a common start
4254 * offset" constraint
4256 struct extent
*e
= calloc(sum_extents
, sizeof(*e
));
4260 unsigned long long pos
;
4261 unsigned long long start
= 0;
4262 unsigned long long maxsize
;
4263 unsigned long reserve
;
4268 /* coalesce and sort all extents. also, check to see if we need to
4269 * reserve space between member arrays
4272 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
4275 for (i
= 0; i
< dl
->extent_cnt
; i
++)
4278 qsort(e
, sum_extents
, sizeof(*e
), cmp_extent
);
4283 while (i
< sum_extents
) {
4284 e
[j
].start
= e
[i
].start
;
4285 e
[j
].size
= find_size(e
, &i
, sum_extents
);
4287 if (e
[j
-1].size
== 0)
4296 unsigned long long esize
;
4298 esize
= e
[i
].start
- pos
;
4299 if (esize
>= maxsize
) {
4304 pos
= e
[i
].start
+ e
[i
].size
;
4306 } while (e
[i
-1].size
);
4312 /* FIXME assumes volume at offset 0 is the first volume in a
4315 if (start_extent
> 0)
4316 reserve
= IMSM_RESERVED_SECTORS
; /* gap between raid regions */
4320 if (maxsize
< reserve
)
4323 super
->create_offset
= ~((__u32
) 0);
4324 if (start
+ reserve
> super
->create_offset
)
4325 return 0; /* start overflows create_offset */
4326 super
->create_offset
= start
+ reserve
;
4328 return maxsize
- reserve
;
4331 static int is_raid_level_supported(const struct imsm_orom
*orom
, int level
, int raiddisks
)
4333 if (level
< 0 || level
== 6 || level
== 4)
4336 /* if we have an orom prevent invalid raid levels */
4339 case 0: return imsm_orom_has_raid0(orom
);
4342 return imsm_orom_has_raid1e(orom
);
4343 return imsm_orom_has_raid1(orom
) && raiddisks
== 2;
4344 case 10: return imsm_orom_has_raid10(orom
) && raiddisks
== 4;
4345 case 5: return imsm_orom_has_raid5(orom
) && raiddisks
> 2;
4348 return 1; /* not on an Intel RAID platform so anything goes */
4354 #define pr_vrb(fmt, arg...) (void) (verbose && fprintf(stderr, Name fmt, ##arg))
4356 * validate volume parameters with OROM/EFI capabilities
4359 validate_geometry_imsm_orom(struct intel_super
*super
, int level
, int layout
,
4360 int raiddisks
, int *chunk
, int verbose
)
4365 /* validate container capabilities */
4366 if (super
->orom
&& raiddisks
> super
->orom
->tds
) {
4368 fprintf(stderr
, Name
": %d exceeds maximum number of"
4369 " platform supported disks: %d\n",
4370 raiddisks
, super
->orom
->tds
);
4374 /* capabilities of OROM tested - copied from validate_geometry_imsm_volume */
4375 if (super
->orom
&& (!is_raid_level_supported(super
->orom
, level
,
4377 pr_vrb(": platform does not support raid%d with %d disk%s\n",
4378 level
, raiddisks
, raiddisks
> 1 ? "s" : "");
4381 if (super
->orom
&& level
!= 1) {
4382 if (chunk
&& (*chunk
== 0 || *chunk
== UnSet
))
4383 *chunk
= imsm_orom_default_chunk(super
->orom
);
4384 else if (chunk
&& !imsm_orom_has_chunk(super
->orom
, *chunk
)) {
4385 pr_vrb(": platform does not support a chunk size of: "
4390 if (layout
!= imsm_level_to_layout(level
)) {
4392 pr_vrb(": imsm raid 5 only supports the left-asymmetric layout\n");
4393 else if (level
== 10)
4394 pr_vrb(": imsm raid 10 only supports the n2 layout\n");
4396 pr_vrb(": imsm unknown layout %#x for this raid level %d\n",
4403 /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
4404 * FIX ME add ahci details
4406 static int validate_geometry_imsm_volume(struct supertype
*st
, int level
,
4407 int layout
, int raiddisks
, int *chunk
,
4408 unsigned long long size
, char *dev
,
4409 unsigned long long *freesize
,
4413 struct intel_super
*super
= st
->sb
;
4414 struct imsm_super
*mpb
= super
->anchor
;
4416 unsigned long long pos
= 0;
4417 unsigned long long maxsize
;
4421 /* We must have the container info already read in. */
4425 if (!validate_geometry_imsm_orom(super
, level
, layout
, raiddisks
, chunk
, verbose
)) {
4426 fprintf(stderr
, Name
": RAID gemetry validation failed. "
4427 "Cannot proceed with the action(s).\n");
4431 /* General test: make sure there is space for
4432 * 'raiddisks' device extents of size 'size' at a given
4435 unsigned long long minsize
= size
;
4436 unsigned long long start_offset
= MaxSector
;
4439 minsize
= MPB_SECTOR_CNT
+ IMSM_RESERVED_SECTORS
;
4440 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
4445 e
= get_extents(super
, dl
);
4448 unsigned long long esize
;
4449 esize
= e
[i
].start
- pos
;
4450 if (esize
>= minsize
)
4452 if (found
&& start_offset
== MaxSector
) {
4455 } else if (found
&& pos
!= start_offset
) {
4459 pos
= e
[i
].start
+ e
[i
].size
;
4461 } while (e
[i
-1].size
);
4466 if (dcnt
< raiddisks
) {
4468 fprintf(stderr
, Name
": imsm: Not enough "
4469 "devices with space for this array "
4477 /* This device must be a member of the set */
4478 if (stat(dev
, &stb
) < 0)
4480 if ((S_IFMT
& stb
.st_mode
) != S_IFBLK
)
4482 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
4483 if (dl
->major
== (int)major(stb
.st_rdev
) &&
4484 dl
->minor
== (int)minor(stb
.st_rdev
))
4489 fprintf(stderr
, Name
": %s is not in the "
4490 "same imsm set\n", dev
);
4492 } else if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
) {
4493 /* If a volume is present then the current creation attempt
4494 * cannot incorporate new spares because the orom may not
4495 * understand this configuration (all member disks must be
4496 * members of each array in the container).
4498 fprintf(stderr
, Name
": %s is a spare and a volume"
4499 " is already defined for this container\n", dev
);
4500 fprintf(stderr
, Name
": The option-rom requires all member"
4501 " disks to be a member of all volumes\n");
4505 /* retrieve the largest free space block */
4506 e
= get_extents(super
, dl
);
4511 unsigned long long esize
;
4513 esize
= e
[i
].start
- pos
;
4514 if (esize
>= maxsize
)
4516 pos
= e
[i
].start
+ e
[i
].size
;
4518 } while (e
[i
-1].size
);
4523 fprintf(stderr
, Name
": unable to determine free space for: %s\n",
4527 if (maxsize
< size
) {
4529 fprintf(stderr
, Name
": %s not enough space (%llu < %llu)\n",
4530 dev
, maxsize
, size
);
4534 /* count total number of extents for merge */
4536 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4538 i
+= dl
->extent_cnt
;
4540 maxsize
= merge_extents(super
, i
);
4541 if (maxsize
< size
|| maxsize
== 0) {
4543 fprintf(stderr
, Name
": not enough space after merge (%llu < %llu)\n",
4548 *freesize
= maxsize
;
4553 static int reserve_space(struct supertype
*st
, int raiddisks
,
4554 unsigned long long size
, int chunk
,
4555 unsigned long long *freesize
)
4557 struct intel_super
*super
= st
->sb
;
4558 struct imsm_super
*mpb
= super
->anchor
;
4563 unsigned long long maxsize
;
4564 unsigned long long minsize
;
4568 /* find the largest common start free region of the possible disks */
4572 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
4578 /* don't activate new spares if we are orom constrained
4579 * and there is already a volume active in the container
4581 if (super
->orom
&& dl
->index
< 0 && mpb
->num_raid_devs
)
4584 e
= get_extents(super
, dl
);
4587 for (i
= 1; e
[i
-1].size
; i
++)
4595 maxsize
= merge_extents(super
, extent_cnt
);
4599 minsize
= chunk
* 2;
4601 if (cnt
< raiddisks
||
4602 (super
->orom
&& used
&& used
!= raiddisks
) ||
4603 maxsize
< minsize
||
4605 fprintf(stderr
, Name
": not enough devices with space to create array.\n");
4606 return 0; /* No enough free spaces large enough */
4618 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
4620 dl
->raiddisk
= cnt
++;
4627 static int validate_geometry_imsm(struct supertype
*st
, int level
, int layout
,
4628 int raiddisks
, int *chunk
, unsigned long long size
,
4629 char *dev
, unsigned long long *freesize
,
4637 * if given unused devices create a container
4638 * if given given devices in a container create a member volume
4640 if (level
== LEVEL_CONTAINER
) {
4641 /* Must be a fresh device to add to a container */
4642 return validate_geometry_imsm_container(st
, level
, layout
,
4644 chunk
?*chunk
:0, size
,
4650 if (st
->sb
&& freesize
) {
4651 /* we are being asked to automatically layout a
4652 * new volume based on the current contents of
4653 * the container. If the the parameters can be
4654 * satisfied reserve_space will record the disks,
4655 * start offset, and size of the volume to be
4656 * created. add_to_super and getinfo_super
4657 * detect when autolayout is in progress.
4659 if (!validate_geometry_imsm_orom(st
->sb
, level
, layout
,
4663 return reserve_space(st
, raiddisks
, size
,
4664 chunk
?*chunk
:0, freesize
);
4669 /* creating in a given container */
4670 return validate_geometry_imsm_volume(st
, level
, layout
,
4671 raiddisks
, chunk
, size
,
4672 dev
, freesize
, verbose
);
4675 /* This device needs to be a device in an 'imsm' container */
4676 fd
= open(dev
, O_RDONLY
|O_EXCL
, 0);
4680 Name
": Cannot create this array on device %s\n",
4685 if (errno
!= EBUSY
|| (fd
= open(dev
, O_RDONLY
, 0)) < 0) {
4687 fprintf(stderr
, Name
": Cannot open %s: %s\n",
4688 dev
, strerror(errno
));
4691 /* Well, it is in use by someone, maybe an 'imsm' container. */
4692 cfd
= open_container(fd
);
4696 fprintf(stderr
, Name
": Cannot use %s: It is busy\n",
4700 sra
= sysfs_read(cfd
, 0, GET_VERSION
);
4701 if (sra
&& sra
->array
.major_version
== -1 &&
4702 strcmp(sra
->text_version
, "imsm") == 0)
4706 /* This is a member of a imsm container. Load the container
4707 * and try to create a volume
4709 struct intel_super
*super
;
4711 if (load_super_imsm_all(st
, cfd
, (void **) &super
, NULL
) == 0) {
4713 st
->container_dev
= fd2devnum(cfd
);
4715 return validate_geometry_imsm_volume(st
, level
, layout
,
4723 fprintf(stderr
, Name
": failed container membership check\n");
4729 static void default_geometry_imsm(struct supertype
*st
, int *level
, int *layout
, int *chunk
)
4731 struct intel_super
*super
= st
->sb
;
4733 if (level
&& *level
== UnSet
)
4734 *level
= LEVEL_CONTAINER
;
4736 if (level
&& layout
&& *layout
== UnSet
)
4737 *layout
= imsm_level_to_layout(*level
);
4739 if (chunk
&& (*chunk
== UnSet
|| *chunk
== 0) &&
4740 super
&& super
->orom
)
4741 *chunk
= imsm_orom_default_chunk(super
->orom
);
4744 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
);
4746 static int kill_subarray_imsm(struct supertype
*st
)
4748 /* remove the subarray currently referenced by ->current_vol */
4750 struct intel_dev
**dp
;
4751 struct intel_super
*super
= st
->sb
;
4752 __u8 current_vol
= super
->current_vol
;
4753 struct imsm_super
*mpb
= super
->anchor
;
4755 if (super
->current_vol
< 0)
4757 super
->current_vol
= -1; /* invalidate subarray cursor */
4759 /* block deletions that would change the uuid of active subarrays
4761 * FIXME when immutable ids are available, but note that we'll
4762 * also need to fixup the invalidated/active subarray indexes in
4765 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4768 if (i
< current_vol
)
4770 sprintf(subarray
, "%u", i
);
4771 if (is_subarray_active(subarray
, st
->devname
)) {
4773 Name
": deleting subarray-%d would change the UUID of active subarray-%d, aborting\n",
4780 if (st
->update_tail
) {
4781 struct imsm_update_kill_array
*u
= malloc(sizeof(*u
));
4785 u
->type
= update_kill_array
;
4786 u
->dev_idx
= current_vol
;
4787 append_metadata_update(st
, u
, sizeof(*u
));
4792 for (dp
= &super
->devlist
; *dp
;)
4793 if ((*dp
)->index
== current_vol
) {
4796 handle_missing(super
, (*dp
)->dev
);
4797 if ((*dp
)->index
> current_vol
)
4802 /* no more raid devices, all active components are now spares,
4803 * but of course failed are still failed
4805 if (--mpb
->num_raid_devs
== 0) {
4808 for (d
= super
->disks
; d
; d
= d
->next
)
4809 if (d
->index
> -2) {
4811 d
->disk
.status
= SPARE_DISK
;
4815 super
->updates_pending
++;
4820 static int update_subarray_imsm(struct supertype
*st
, char *subarray
,
4821 char *update
, struct mddev_ident
*ident
)
4823 /* update the subarray currently referenced by ->current_vol */
4824 struct intel_super
*super
= st
->sb
;
4825 struct imsm_super
*mpb
= super
->anchor
;
4827 if (strcmp(update
, "name") == 0) {
4828 char *name
= ident
->name
;
4832 if (is_subarray_active(subarray
, st
->devname
)) {
4834 Name
": Unable to update name of active subarray\n");
4838 if (!check_name(super
, name
, 0))
4841 vol
= strtoul(subarray
, &ep
, 10);
4842 if (*ep
!= '\0' || vol
>= super
->anchor
->num_raid_devs
)
4845 if (st
->update_tail
) {
4846 struct imsm_update_rename_array
*u
= malloc(sizeof(*u
));
4850 u
->type
= update_rename_array
;
4852 snprintf((char *) u
->name
, MAX_RAID_SERIAL_LEN
, "%s", name
);
4853 append_metadata_update(st
, u
, sizeof(*u
));
4855 struct imsm_dev
*dev
;
4858 dev
= get_imsm_dev(super
, vol
);
4859 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
4860 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4861 dev
= get_imsm_dev(super
, i
);
4862 handle_missing(super
, dev
);
4864 super
->updates_pending
++;
4872 static int is_gen_migration(struct imsm_dev
*dev
)
4874 if (!dev
->vol
.migr_state
)
4877 if (migr_type(dev
) == MIGR_GEN_MIGR
)
4882 #endif /* MDASSEMBLE */
4884 static int is_rebuilding(struct imsm_dev
*dev
)
4886 struct imsm_map
*migr_map
;
4888 if (!dev
->vol
.migr_state
)
4891 if (migr_type(dev
) != MIGR_REBUILD
)
4894 migr_map
= get_imsm_map(dev
, 1);
4896 if (migr_map
->map_state
== IMSM_T_STATE_DEGRADED
)
4902 static void update_recovery_start(struct imsm_dev
*dev
, struct mdinfo
*array
)
4904 struct mdinfo
*rebuild
= NULL
;
4908 if (!is_rebuilding(dev
))
4911 /* Find the rebuild target, but punt on the dual rebuild case */
4912 for (d
= array
->devs
; d
; d
= d
->next
)
4913 if (d
->recovery_start
== 0) {
4920 /* (?) none of the disks are marked with
4921 * IMSM_ORD_REBUILD, so assume they are missing and the
4922 * disk_ord_tbl was not correctly updated
4924 dprintf("%s: failed to locate out-of-sync disk\n", __func__
);
4928 units
= __le32_to_cpu(dev
->vol
.curr_migr_unit
);
4929 rebuild
->recovery_start
= units
* blocks_per_migr_unit(dev
);
4933 static struct mdinfo
*container_content_imsm(struct supertype
*st
, char *subarray
)
4935 /* Given a container loaded by load_super_imsm_all,
4936 * extract information about all the arrays into
4938 * If 'subarray' is given, just extract info about that array.
4940 * For each imsm_dev create an mdinfo, fill it in,
4941 * then look for matching devices in super->disks
4942 * and create appropriate device mdinfo.
4944 struct intel_super
*super
= st
->sb
;
4945 struct imsm_super
*mpb
= super
->anchor
;
4946 struct mdinfo
*rest
= NULL
;
4950 int spare_disks
= 0;
4952 /* check for bad blocks */
4953 if (imsm_bbm_log_size(super
->anchor
))
4956 /* count spare devices, not used in maps
4958 for (d
= super
->disks
; d
; d
= d
->next
)
4962 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
4963 struct imsm_dev
*dev
;
4964 struct imsm_map
*map
;
4965 struct imsm_map
*map2
;
4966 struct mdinfo
*this;
4971 (i
!= strtoul(subarray
, &ep
, 10) || *ep
!= '\0'))
4974 dev
= get_imsm_dev(super
, i
);
4975 map
= get_imsm_map(dev
, 0);
4976 map2
= get_imsm_map(dev
, 1);
4978 /* do not publish arrays that are in the middle of an
4979 * unsupported migration
4981 if (dev
->vol
.migr_state
&&
4982 (migr_type(dev
) == MIGR_STATE_CHANGE
)) {
4983 fprintf(stderr
, Name
": cannot assemble volume '%.16s':"
4984 " unsupported migration in progress\n",
4988 /* do not publish arrays that are not support by controller's
4992 chunk
= __le16_to_cpu(map
->blocks_per_strip
) >> 1;
4994 if (!validate_geometry_imsm_orom(super
,
4995 get_imsm_raid_level(map
), /* RAID level */
4996 imsm_level_to_layout(get_imsm_raid_level(map
)),
4997 map
->num_members
, /* raid disks */
5000 fprintf(stderr
, Name
": RAID gemetry validation failed. "
5001 "Cannot proceed with the action(s).\n");
5004 #endif /* MDASSEMBLE */
5005 this = malloc(sizeof(*this));
5007 fprintf(stderr
, Name
": failed to allocate %zu bytes\n",
5011 memset(this, 0, sizeof(*this));
5014 super
->current_vol
= i
;
5015 getinfo_super_imsm_volume(st
, this, NULL
);
5016 for (slot
= 0 ; slot
< map
->num_members
; slot
++) {
5017 unsigned long long recovery_start
;
5018 struct mdinfo
*info_d
;
5025 idx
= get_imsm_disk_idx(dev
, slot
, 0);
5026 ord
= get_imsm_ord_tbl_ent(dev
, slot
, -1);
5027 for (d
= super
->disks
; d
; d
= d
->next
)
5028 if (d
->index
== idx
)
5031 recovery_start
= MaxSector
;
5034 if (d
&& is_failed(&d
->disk
))
5036 if (ord
& IMSM_ORD_REBUILD
)
5040 * if we skip some disks the array will be assmebled degraded;
5041 * reset resync start to avoid a dirty-degraded
5042 * situation when performing the intial sync
5044 * FIXME handle dirty degraded
5046 if ((skip
|| recovery_start
== 0) && !dev
->vol
.dirty
)
5047 this->resync_start
= MaxSector
;
5051 info_d
= calloc(1, sizeof(*info_d
));
5053 fprintf(stderr
, Name
": failed to allocate disk"
5054 " for volume %.16s\n", dev
->volume
);
5055 info_d
= this->devs
;
5057 struct mdinfo
*d
= info_d
->next
;
5066 info_d
->next
= this->devs
;
5067 this->devs
= info_d
;
5069 info_d
->disk
.number
= d
->index
;
5070 info_d
->disk
.major
= d
->major
;
5071 info_d
->disk
.minor
= d
->minor
;
5072 info_d
->disk
.raid_disk
= slot
;
5073 info_d
->recovery_start
= recovery_start
;
5075 if (slot
< map2
->num_members
)
5076 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
5078 this->array
.spare_disks
++;
5080 if (slot
< map
->num_members
)
5081 info_d
->disk
.state
= (1 << MD_DISK_ACTIVE
);
5083 this->array
.spare_disks
++;
5085 if (info_d
->recovery_start
== MaxSector
)
5086 this->array
.working_disks
++;
5088 info_d
->events
= __le32_to_cpu(mpb
->generation_num
);
5089 info_d
->data_offset
= __le32_to_cpu(map
->pba_of_lba0
);
5090 info_d
->component_size
= __le32_to_cpu(map
->blocks_per_member
);
5092 /* now that the disk list is up-to-date fixup recovery_start */
5093 update_recovery_start(dev
, this);
5094 this->array
.spare_disks
+= spare_disks
;
5098 /* if array has bad blocks, set suitable bit in array status */
5100 rest
->array
.state
|= (1<<MD_SB_BBM_ERRORS
);
5106 static __u8
imsm_check_degraded(struct intel_super
*super
, struct imsm_dev
*dev
, int failed
)
5108 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5111 return map
->map_state
== IMSM_T_STATE_UNINITIALIZED
?
5112 IMSM_T_STATE_UNINITIALIZED
: IMSM_T_STATE_NORMAL
;
5114 switch (get_imsm_raid_level(map
)) {
5116 return IMSM_T_STATE_FAILED
;
5119 if (failed
< map
->num_members
)
5120 return IMSM_T_STATE_DEGRADED
;
5122 return IMSM_T_STATE_FAILED
;
5127 * check to see if any mirrors have failed, otherwise we
5128 * are degraded. Even numbered slots are mirrored on
5132 /* gcc -Os complains that this is unused */
5133 int insync
= insync
;
5135 for (i
= 0; i
< map
->num_members
; i
++) {
5136 __u32 ord
= get_imsm_ord_tbl_ent(dev
, i
, -1);
5137 int idx
= ord_to_idx(ord
);
5138 struct imsm_disk
*disk
;
5140 /* reset the potential in-sync count on even-numbered
5141 * slots. num_copies is always 2 for imsm raid10
5146 disk
= get_imsm_disk(super
, idx
);
5147 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
5150 /* no in-sync disks left in this mirror the
5154 return IMSM_T_STATE_FAILED
;
5157 return IMSM_T_STATE_DEGRADED
;
5161 return IMSM_T_STATE_DEGRADED
;
5163 return IMSM_T_STATE_FAILED
;
5169 return map
->map_state
;
5172 static int imsm_count_failed(struct intel_super
*super
, struct imsm_dev
*dev
)
5176 struct imsm_disk
*disk
;
5177 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5178 struct imsm_map
*prev
= get_imsm_map(dev
, dev
->vol
.migr_state
);
5182 /* at the beginning of migration we set IMSM_ORD_REBUILD on
5183 * disks that are being rebuilt. New failures are recorded to
5184 * map[0]. So we look through all the disks we started with and
5185 * see if any failures are still present, or if any new ones
5188 * FIXME add support for online capacity expansion and
5189 * raid-level-migration
5191 for (i
= 0; i
< prev
->num_members
; i
++) {
5192 ord
= __le32_to_cpu(prev
->disk_ord_tbl
[i
]);
5193 ord
|= __le32_to_cpu(map
->disk_ord_tbl
[i
]);
5194 idx
= ord_to_idx(ord
);
5196 disk
= get_imsm_disk(super
, idx
);
5197 if (!disk
|| is_failed(disk
) || ord
& IMSM_ORD_REBUILD
)
5205 static int imsm_open_new(struct supertype
*c
, struct active_array
*a
,
5208 struct intel_super
*super
= c
->sb
;
5209 struct imsm_super
*mpb
= super
->anchor
;
5211 if (atoi(inst
) >= mpb
->num_raid_devs
) {
5212 fprintf(stderr
, "%s: subarry index %d, out of range\n",
5213 __func__
, atoi(inst
));
5217 dprintf("imsm: open_new %s\n", inst
);
5218 a
->info
.container_member
= atoi(inst
);
5222 static int is_resyncing(struct imsm_dev
*dev
)
5224 struct imsm_map
*migr_map
;
5226 if (!dev
->vol
.migr_state
)
5229 if (migr_type(dev
) == MIGR_INIT
||
5230 migr_type(dev
) == MIGR_REPAIR
)
5233 if (migr_type(dev
) == MIGR_GEN_MIGR
)
5236 migr_map
= get_imsm_map(dev
, 1);
5238 if ((migr_map
->map_state
== IMSM_T_STATE_NORMAL
) &&
5239 (dev
->vol
.migr_type
!= MIGR_GEN_MIGR
))
5245 /* return true if we recorded new information */
5246 static int mark_failure(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
5250 struct imsm_map
*map
;
5252 /* new failures are always set in map[0] */
5253 map
= get_imsm_map(dev
, 0);
5255 slot
= get_imsm_disk_slot(map
, idx
);
5259 ord
= __le32_to_cpu(map
->disk_ord_tbl
[slot
]);
5260 if (is_failed(disk
) && (ord
& IMSM_ORD_REBUILD
))
5263 disk
->status
|= FAILED_DISK
;
5264 set_imsm_ord_tbl_ent(map
, slot
, idx
| IMSM_ORD_REBUILD
);
5265 if (map
->failed_disk_num
== 0xff)
5266 map
->failed_disk_num
= slot
;
5270 static void mark_missing(struct imsm_dev
*dev
, struct imsm_disk
*disk
, int idx
)
5272 mark_failure(dev
, disk
, idx
);
5274 if (disk
->scsi_id
== __cpu_to_le32(~(__u32
)0))
5277 disk
->scsi_id
= __cpu_to_le32(~(__u32
)0);
5278 memmove(&disk
->serial
[0], &disk
->serial
[1], MAX_RAID_SERIAL_LEN
- 1);
5281 static void handle_missing(struct intel_super
*super
, struct imsm_dev
*dev
)
5287 if (!super
->missing
)
5289 failed
= imsm_count_failed(super
, dev
);
5290 map_state
= imsm_check_degraded(super
, dev
, failed
);
5292 dprintf("imsm: mark missing\n");
5293 end_migration(dev
, map_state
);
5294 for (dl
= super
->missing
; dl
; dl
= dl
->next
)
5295 mark_missing(dev
, &dl
->disk
, dl
->index
);
5296 super
->updates_pending
++;
5299 static unsigned long long imsm_set_array_size(struct imsm_dev
*dev
)
5301 int used_disks
= imsm_num_data_members(dev
, 0);
5302 unsigned long long array_blocks
;
5303 struct imsm_map
*map
;
5305 if (used_disks
== 0) {
5306 /* when problems occures
5307 * return current array_blocks value
5309 array_blocks
= __le32_to_cpu(dev
->size_high
);
5310 array_blocks
= array_blocks
<< 32;
5311 array_blocks
+= __le32_to_cpu(dev
->size_low
);
5313 return array_blocks
;
5316 /* set array size in metadata
5318 map
= get_imsm_map(dev
, 0);
5319 array_blocks
= map
->blocks_per_member
* used_disks
;
5321 /* round array size down to closest MB
5323 array_blocks
= (array_blocks
>> SECT_PER_MB_SHIFT
) << SECT_PER_MB_SHIFT
;
5324 dev
->size_low
= __cpu_to_le32((__u32
)array_blocks
);
5325 dev
->size_high
= __cpu_to_le32((__u32
)(array_blocks
>> 32));
5327 return array_blocks
;
5330 static void imsm_set_disk(struct active_array
*a
, int n
, int state
);
5332 static void imsm_progress_container_reshape(struct intel_super
*super
)
5334 /* if no device has a migr_state, but some device has a
5335 * different number of members than the previous device, start
5336 * changing the number of devices in this device to match
5339 struct imsm_super
*mpb
= super
->anchor
;
5340 int prev_disks
= -1;
5344 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5345 struct imsm_dev
*dev
= get_imsm_dev(super
, i
);
5346 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5347 struct imsm_map
*map2
;
5348 int prev_num_members
;
5350 if (dev
->vol
.migr_state
)
5353 if (prev_disks
== -1)
5354 prev_disks
= map
->num_members
;
5355 if (prev_disks
== map
->num_members
)
5358 /* OK, this array needs to enter reshape mode.
5359 * i.e it needs a migr_state
5362 copy_map_size
= sizeof_imsm_map(map
);
5363 prev_num_members
= map
->num_members
;
5364 map
->num_members
= prev_disks
;
5365 dev
->vol
.migr_state
= 1;
5366 dev
->vol
.curr_migr_unit
= 0;
5367 dev
->vol
.migr_type
= MIGR_GEN_MIGR
;
5368 for (i
= prev_num_members
;
5369 i
< map
->num_members
; i
++)
5370 set_imsm_ord_tbl_ent(map
, i
, i
);
5371 map2
= get_imsm_map(dev
, 1);
5372 /* Copy the current map */
5373 memcpy(map2
, map
, copy_map_size
);
5374 map2
->num_members
= prev_num_members
;
5376 imsm_set_array_size(dev
);
5377 super
->updates_pending
++;
5381 /* Handle dirty -> clean transititions, resync and reshape. Degraded and rebuild
5382 * states are handled in imsm_set_disk() with one exception, when a
5383 * resync is stopped due to a new failure this routine will set the
5384 * 'degraded' state for the array.
5386 static int imsm_set_array_state(struct active_array
*a
, int consistent
)
5388 int inst
= a
->info
.container_member
;
5389 struct intel_super
*super
= a
->container
->sb
;
5390 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
5391 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5392 int failed
= imsm_count_failed(super
, dev
);
5393 __u8 map_state
= imsm_check_degraded(super
, dev
, failed
);
5394 __u32 blocks_per_unit
;
5396 if (dev
->vol
.migr_state
&&
5397 dev
->vol
.migr_type
== MIGR_GEN_MIGR
) {
5398 /* array state change is blocked due to reshape action
5400 * - abort the reshape (if last_checkpoint is 0 and action!= reshape)
5401 * - finish the reshape (if last_checkpoint is big and action != reshape)
5402 * - update curr_migr_unit
5404 if (a
->curr_action
== reshape
) {
5405 /* still reshaping, maybe update curr_migr_unit */
5406 goto mark_checkpoint
;
5408 if (a
->last_checkpoint
== 0 && a
->prev_action
== reshape
) {
5409 /* for some reason we aborted the reshape.
5412 struct imsm_map
*map2
= get_imsm_map(dev
, 1);
5413 dev
->vol
.migr_state
= 0;
5414 dev
->vol
.migr_type
= 0;
5415 dev
->vol
.curr_migr_unit
= 0;
5416 memcpy(map
, map2
, sizeof_imsm_map(map2
));
5417 super
->updates_pending
++;
5419 if (a
->last_checkpoint
>= a
->info
.component_size
) {
5420 unsigned long long array_blocks
;
5424 used_disks
= imsm_num_data_members(dev
, 0);
5425 if (used_disks
> 0) {
5427 map
->blocks_per_member
*
5429 /* round array size down to closest MB
5431 array_blocks
= (array_blocks
5432 >> SECT_PER_MB_SHIFT
)
5433 << SECT_PER_MB_SHIFT
;
5434 a
->info
.custom_array_size
= array_blocks
;
5435 /* encourage manager to update array
5439 a
->check_reshape
= 1;
5441 /* finalize online capacity expansion/reshape */
5442 for (mdi
= a
->info
.devs
; mdi
; mdi
= mdi
->next
)
5444 mdi
->disk
.raid_disk
,
5447 imsm_progress_container_reshape(super
);
5452 /* before we activate this array handle any missing disks */
5453 if (consistent
== 2)
5454 handle_missing(super
, dev
);
5456 if (consistent
== 2 &&
5457 (!is_resync_complete(&a
->info
) ||
5458 map_state
!= IMSM_T_STATE_NORMAL
||
5459 dev
->vol
.migr_state
))
5462 if (is_resync_complete(&a
->info
)) {
5463 /* complete intialization / resync,
5464 * recovery and interrupted recovery is completed in
5467 if (is_resyncing(dev
)) {
5468 dprintf("imsm: mark resync done\n");
5469 end_migration(dev
, map_state
);
5470 super
->updates_pending
++;
5471 a
->last_checkpoint
= 0;
5473 } else if (!is_resyncing(dev
) && !failed
) {
5474 /* mark the start of the init process if nothing is failed */
5475 dprintf("imsm: mark resync start\n");
5476 if (map
->map_state
== IMSM_T_STATE_UNINITIALIZED
)
5477 migrate(dev
, IMSM_T_STATE_NORMAL
, MIGR_INIT
);
5479 migrate(dev
, IMSM_T_STATE_NORMAL
, MIGR_REPAIR
);
5480 super
->updates_pending
++;
5484 /* check if we can update curr_migr_unit from resync_start, recovery_start */
5485 blocks_per_unit
= blocks_per_migr_unit(dev
);
5486 if (blocks_per_unit
) {
5490 units
= a
->last_checkpoint
/ blocks_per_unit
;
5493 /* check that we did not overflow 32-bits, and that
5494 * curr_migr_unit needs updating
5496 if (units32
== units
&&
5498 __le32_to_cpu(dev
->vol
.curr_migr_unit
) != units32
) {
5499 dprintf("imsm: mark checkpoint (%u)\n", units32
);
5500 dev
->vol
.curr_migr_unit
= __cpu_to_le32(units32
);
5501 super
->updates_pending
++;
5505 /* mark dirty / clean */
5506 if (dev
->vol
.dirty
!= !consistent
) {
5507 dprintf("imsm: mark '%s'\n", consistent
? "clean" : "dirty");
5512 super
->updates_pending
++;
5518 static void imsm_set_disk(struct active_array
*a
, int n
, int state
)
5520 int inst
= a
->info
.container_member
;
5521 struct intel_super
*super
= a
->container
->sb
;
5522 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
5523 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5524 struct imsm_disk
*disk
;
5529 if (n
> map
->num_members
)
5530 fprintf(stderr
, "imsm: set_disk %d out of range 0..%d\n",
5531 n
, map
->num_members
- 1);
5536 dprintf("imsm: set_disk %d:%x\n", n
, state
);
5538 ord
= get_imsm_ord_tbl_ent(dev
, n
, -1);
5539 disk
= get_imsm_disk(super
, ord_to_idx(ord
));
5541 /* check for new failures */
5542 if (state
& DS_FAULTY
) {
5543 if (mark_failure(dev
, disk
, ord_to_idx(ord
)))
5544 super
->updates_pending
++;
5547 /* check if in_sync */
5548 if (state
& DS_INSYNC
&& ord
& IMSM_ORD_REBUILD
&& is_rebuilding(dev
)) {
5549 struct imsm_map
*migr_map
= get_imsm_map(dev
, 1);
5551 set_imsm_ord_tbl_ent(migr_map
, n
, ord_to_idx(ord
));
5552 super
->updates_pending
++;
5555 failed
= imsm_count_failed(super
, dev
);
5556 map_state
= imsm_check_degraded(super
, dev
, failed
);
5558 /* check if recovery complete, newly degraded, or failed */
5559 if (map_state
== IMSM_T_STATE_NORMAL
&& is_rebuilding(dev
)) {
5560 end_migration(dev
, map_state
);
5561 map
= get_imsm_map(dev
, 0);
5562 map
->failed_disk_num
= ~0;
5563 super
->updates_pending
++;
5564 a
->last_checkpoint
= 0;
5565 } else if (map_state
== IMSM_T_STATE_DEGRADED
&&
5566 map
->map_state
!= map_state
&&
5567 !dev
->vol
.migr_state
) {
5568 dprintf("imsm: mark degraded\n");
5569 map
->map_state
= map_state
;
5570 super
->updates_pending
++;
5571 a
->last_checkpoint
= 0;
5572 } else if (map_state
== IMSM_T_STATE_FAILED
&&
5573 map
->map_state
!= map_state
) {
5574 dprintf("imsm: mark failed\n");
5575 end_migration(dev
, map_state
);
5576 super
->updates_pending
++;
5577 a
->last_checkpoint
= 0;
5578 } else if (is_gen_migration(dev
)) {
5579 dprintf("imsm: Detected General Migration in state: ");
5580 if (map_state
== IMSM_T_STATE_NORMAL
) {
5581 end_migration(dev
, map_state
);
5582 map
= get_imsm_map(dev
, 0);
5583 map
->failed_disk_num
= ~0;
5584 dprintf("normal\n");
5586 if (map_state
== IMSM_T_STATE_DEGRADED
) {
5587 printf("degraded\n");
5588 end_migration(dev
, map_state
);
5590 dprintf("failed\n");
5592 map
->map_state
= map_state
;
5594 super
->updates_pending
++;
5598 static int store_imsm_mpb(int fd
, struct imsm_super
*mpb
)
5601 __u32 mpb_size
= __le32_to_cpu(mpb
->mpb_size
);
5602 unsigned long long dsize
;
5603 unsigned long long sectors
;
5605 get_dev_size(fd
, NULL
, &dsize
);
5607 if (mpb_size
> 512) {
5608 /* -1 to account for anchor */
5609 sectors
= mpb_sectors(mpb
) - 1;
5611 /* write the extended mpb to the sectors preceeding the anchor */
5612 if (lseek64(fd
, dsize
- (512 * (2 + sectors
)), SEEK_SET
) < 0)
5615 if ((unsigned long long)write(fd
, buf
+ 512, 512 * sectors
)
5620 /* first block is stored on second to last sector of the disk */
5621 if (lseek64(fd
, dsize
- (512 * 2), SEEK_SET
) < 0)
5624 if (write(fd
, buf
, 512) != 512)
5630 static void imsm_sync_metadata(struct supertype
*container
)
5632 struct intel_super
*super
= container
->sb
;
5634 dprintf("sync metadata: %d\n", super
->updates_pending
);
5635 if (!super
->updates_pending
)
5638 write_super_imsm(container
, 0);
5640 super
->updates_pending
= 0;
5643 static struct dl
*imsm_readd(struct intel_super
*super
, int idx
, struct active_array
*a
)
5645 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
5646 int i
= get_imsm_disk_idx(dev
, idx
, -1);
5649 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
5653 if (dl
&& is_failed(&dl
->disk
))
5657 dprintf("%s: found %x:%x\n", __func__
, dl
->major
, dl
->minor
);
5662 static struct dl
*imsm_add_spare(struct intel_super
*super
, int slot
,
5663 struct active_array
*a
, int activate_new
,
5664 struct mdinfo
*additional_test_list
)
5666 struct imsm_dev
*dev
= get_imsm_dev(super
, a
->info
.container_member
);
5667 int idx
= get_imsm_disk_idx(dev
, slot
, -1);
5668 struct imsm_super
*mpb
= super
->anchor
;
5669 struct imsm_map
*map
;
5670 unsigned long long pos
;
5675 __u32 array_start
= 0;
5676 __u32 array_end
= 0;
5678 struct mdinfo
*test_list
;
5680 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
5681 /* If in this array, skip */
5682 for (d
= a
->info
.devs
; d
; d
= d
->next
)
5683 if (d
->state_fd
>= 0 &&
5684 d
->disk
.major
== dl
->major
&&
5685 d
->disk
.minor
== dl
->minor
) {
5686 dprintf("%x:%x already in array\n",
5687 dl
->major
, dl
->minor
);
5692 test_list
= additional_test_list
;
5694 if (test_list
->disk
.major
== dl
->major
&&
5695 test_list
->disk
.minor
== dl
->minor
) {
5696 dprintf("%x:%x already in additional test list\n",
5697 dl
->major
, dl
->minor
);
5700 test_list
= test_list
->next
;
5705 /* skip in use or failed drives */
5706 if (is_failed(&dl
->disk
) || idx
== dl
->index
||
5708 dprintf("%x:%x status (failed: %d index: %d)\n",
5709 dl
->major
, dl
->minor
, is_failed(&dl
->disk
), idx
);
5713 /* skip pure spares when we are looking for partially
5714 * assimilated drives
5716 if (dl
->index
== -1 && !activate_new
)
5719 /* Does this unused device have the requisite free space?
5720 * It needs to be able to cover all member volumes
5722 ex
= get_extents(super
, dl
);
5724 dprintf("cannot get extents\n");
5727 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
5728 dev
= get_imsm_dev(super
, i
);
5729 map
= get_imsm_map(dev
, 0);
5731 /* check if this disk is already a member of
5734 if (get_imsm_disk_slot(map
, dl
->index
) >= 0)
5740 array_start
= __le32_to_cpu(map
->pba_of_lba0
);
5741 array_end
= array_start
+
5742 __le32_to_cpu(map
->blocks_per_member
) - 1;
5745 /* check that we can start at pba_of_lba0 with
5746 * blocks_per_member of space
5748 if (array_start
>= pos
&& array_end
< ex
[j
].start
) {
5752 pos
= ex
[j
].start
+ ex
[j
].size
;
5754 } while (ex
[j
-1].size
);
5761 if (i
< mpb
->num_raid_devs
) {
5762 dprintf("%x:%x does not have %u to %u available\n",
5763 dl
->major
, dl
->minor
, array_start
, array_end
);
5774 static int imsm_rebuild_allowed(struct supertype
*cont
, int dev_idx
, int failed
)
5776 struct imsm_dev
*dev2
;
5777 struct imsm_map
*map
;
5783 dev2
= get_imsm_dev(cont
->sb
, dev_idx
);
5785 state
= imsm_check_degraded(cont
->sb
, dev2
, failed
);
5786 if (state
== IMSM_T_STATE_FAILED
) {
5787 map
= get_imsm_map(dev2
, 0);
5790 for (slot
= 0; slot
< map
->num_members
; slot
++) {
5792 * Check if failed disks are deleted from intel
5793 * disk list or are marked to be deleted
5795 idx
= get_imsm_disk_idx(dev2
, slot
, -1);
5796 idisk
= get_imsm_dl_disk(cont
->sb
, idx
);
5798 * Do not rebuild the array if failed disks
5799 * from failed sub-array are not removed from
5803 is_failed(&idisk
->disk
) &&
5804 (idisk
->action
!= DISK_REMOVE
))
5812 static struct mdinfo
*imsm_activate_spare(struct active_array
*a
,
5813 struct metadata_update
**updates
)
5816 * Find a device with unused free space and use it to replace a
5817 * failed/vacant region in an array. We replace failed regions one a
5818 * array at a time. The result is that a new spare disk will be added
5819 * to the first failed array and after the monitor has finished
5820 * propagating failures the remainder will be consumed.
5822 * FIXME add a capability for mdmon to request spares from another
5826 struct intel_super
*super
= a
->container
->sb
;
5827 int inst
= a
->info
.container_member
;
5828 struct imsm_dev
*dev
= get_imsm_dev(super
, inst
);
5829 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5830 int failed
= a
->info
.array
.raid_disks
;
5831 struct mdinfo
*rv
= NULL
;
5834 struct metadata_update
*mu
;
5836 struct imsm_update_activate_spare
*u
;
5841 for (d
= a
->info
.devs
; d
; d
= d
->next
) {
5842 if ((d
->curr_state
& DS_FAULTY
) &&
5844 /* wait for Removal to happen */
5846 if (d
->state_fd
>= 0)
5850 dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
5851 inst
, failed
, a
->info
.array
.raid_disks
, a
->info
.array
.level
);
5853 if (dev
->vol
.migr_state
&&
5854 dev
->vol
.migr_type
== MIGR_GEN_MIGR
)
5855 /* No repair during migration */
5858 if (a
->info
.array
.level
== 4)
5859 /* No repair for takeovered array
5860 * imsm doesn't support raid4
5864 if (imsm_check_degraded(super
, dev
, failed
) != IMSM_T_STATE_DEGRADED
)
5868 * If there are any failed disks check state of the other volume.
5869 * Block rebuild if the another one is failed until failed disks
5870 * are removed from container.
5873 dprintf("found failed disks in %s, check if there another"
5874 "failed sub-array.\n",
5876 /* check if states of the other volumes allow for rebuild */
5877 for (i
= 0; i
< super
->anchor
->num_raid_devs
; i
++) {
5879 allowed
= imsm_rebuild_allowed(a
->container
,
5887 /* For each slot, if it is not working, find a spare */
5888 for (i
= 0; i
< a
->info
.array
.raid_disks
; i
++) {
5889 for (d
= a
->info
.devs
; d
; d
= d
->next
)
5890 if (d
->disk
.raid_disk
== i
)
5892 dprintf("found %d: %p %x\n", i
, d
, d
?d
->curr_state
:0);
5893 if (d
&& (d
->state_fd
>= 0))
5897 * OK, this device needs recovery. Try to re-add the
5898 * previous occupant of this slot, if this fails see if
5899 * we can continue the assimilation of a spare that was
5900 * partially assimilated, finally try to activate a new
5903 dl
= imsm_readd(super
, i
, a
);
5905 dl
= imsm_add_spare(super
, i
, a
, 0, NULL
);
5907 dl
= imsm_add_spare(super
, i
, a
, 1, NULL
);
5911 /* found a usable disk with enough space */
5912 di
= malloc(sizeof(*di
));
5915 memset(di
, 0, sizeof(*di
));
5917 /* dl->index will be -1 in the case we are activating a
5918 * pristine spare. imsm_process_update() will create a
5919 * new index in this case. Once a disk is found to be
5920 * failed in all member arrays it is kicked from the
5923 di
->disk
.number
= dl
->index
;
5925 /* (ab)use di->devs to store a pointer to the device
5928 di
->devs
= (struct mdinfo
*) dl
;
5930 di
->disk
.raid_disk
= i
;
5931 di
->disk
.major
= dl
->major
;
5932 di
->disk
.minor
= dl
->minor
;
5934 di
->recovery_start
= 0;
5935 di
->data_offset
= __le32_to_cpu(map
->pba_of_lba0
);
5936 di
->component_size
= a
->info
.component_size
;
5937 di
->container_member
= inst
;
5938 super
->random
= random32();
5942 dprintf("%x:%x to be %d at %llu\n", dl
->major
, dl
->minor
,
5943 i
, di
->data_offset
);
5949 /* No spares found */
5951 /* Now 'rv' has a list of devices to return.
5952 * Create a metadata_update record to update the
5953 * disk_ord_tbl for the array
5955 mu
= malloc(sizeof(*mu
));
5957 mu
->buf
= malloc(sizeof(struct imsm_update_activate_spare
) * num_spares
);
5958 if (mu
->buf
== NULL
) {
5965 struct mdinfo
*n
= rv
->next
;
5974 mu
->space_list
= NULL
;
5975 mu
->len
= sizeof(struct imsm_update_activate_spare
) * num_spares
;
5976 mu
->next
= *updates
;
5977 u
= (struct imsm_update_activate_spare
*) mu
->buf
;
5979 for (di
= rv
; di
; di
= di
->next
) {
5980 u
->type
= update_activate_spare
;
5981 u
->dl
= (struct dl
*) di
->devs
;
5983 u
->slot
= di
->disk
.raid_disk
;
5994 static int disks_overlap(struct intel_super
*super
, int idx
, struct imsm_update_create_array
*u
)
5996 struct imsm_dev
*dev
= get_imsm_dev(super
, idx
);
5997 struct imsm_map
*map
= get_imsm_map(dev
, 0);
5998 struct imsm_map
*new_map
= get_imsm_map(&u
->dev
, 0);
5999 struct disk_info
*inf
= get_disk_info(u
);
6000 struct imsm_disk
*disk
;
6004 for (i
= 0; i
< map
->num_members
; i
++) {
6005 disk
= get_imsm_disk(super
, get_imsm_disk_idx(dev
, i
, -1));
6006 for (j
= 0; j
< new_map
->num_members
; j
++)
6007 if (serialcmp(disk
->serial
, inf
[j
].serial
) == 0)
6015 static struct dl
*get_disk_super(struct intel_super
*super
, int major
, int minor
)
6017 struct dl
*dl
= NULL
;
6018 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6019 if ((dl
->major
== major
) && (dl
->minor
== minor
))
6024 static int remove_disk_super(struct intel_super
*super
, int major
, int minor
)
6026 struct dl
*prev
= NULL
;
6030 for (dl
= super
->disks
; dl
; dl
= dl
->next
) {
6031 if ((dl
->major
== major
) && (dl
->minor
== minor
)) {
6034 prev
->next
= dl
->next
;
6036 super
->disks
= dl
->next
;
6038 __free_imsm_disk(dl
);
6039 dprintf("%s: removed %x:%x\n",
6040 __func__
, major
, minor
);
6048 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
);
6050 static int add_remove_disk_update(struct intel_super
*super
)
6052 int check_degraded
= 0;
6053 struct dl
*disk
= NULL
;
6054 /* add/remove some spares to/from the metadata/contrainer */
6055 while (super
->disk_mgmt_list
) {
6056 struct dl
*disk_cfg
;
6058 disk_cfg
= super
->disk_mgmt_list
;
6059 super
->disk_mgmt_list
= disk_cfg
->next
;
6060 disk_cfg
->next
= NULL
;
6062 if (disk_cfg
->action
== DISK_ADD
) {
6063 disk_cfg
->next
= super
->disks
;
6064 super
->disks
= disk_cfg
;
6066 dprintf("%s: added %x:%x\n",
6067 __func__
, disk_cfg
->major
,
6069 } else if (disk_cfg
->action
== DISK_REMOVE
) {
6070 dprintf("Disk remove action processed: %x.%x\n",
6071 disk_cfg
->major
, disk_cfg
->minor
);
6072 disk
= get_disk_super(super
,
6076 /* store action status */
6077 disk
->action
= DISK_REMOVE
;
6078 /* remove spare disks only */
6079 if (disk
->index
== -1) {
6080 remove_disk_super(super
,
6085 /* release allocate disk structure */
6086 __free_imsm_disk(disk_cfg
);
6089 return check_degraded
;
6092 static int apply_reshape_container_disks_update(struct imsm_update_reshape
*u
,
6093 struct intel_super
*super
,
6096 struct dl
*new_disk
;
6097 struct intel_dev
*id
;
6099 int delta_disks
= u
->new_raid_disks
- u
->old_raid_disks
;
6100 int disk_count
= u
->old_raid_disks
;
6101 void **tofree
= NULL
;
6102 int devices_to_reshape
= 1;
6103 struct imsm_super
*mpb
= super
->anchor
;
6105 unsigned int dev_id
;
6107 dprintf("imsm: apply_reshape_container_disks_update()\n");
6109 /* enable spares to use in array */
6110 for (i
= 0; i
< delta_disks
; i
++) {
6111 new_disk
= get_disk_super(super
,
6112 major(u
->new_disks
[i
]),
6113 minor(u
->new_disks
[i
]));
6114 dprintf("imsm: new disk for reshape is: %i:%i "
6115 "(%p, index = %i)\n",
6116 major(u
->new_disks
[i
]), minor(u
->new_disks
[i
]),
6117 new_disk
, new_disk
->index
);
6118 if ((new_disk
== NULL
) ||
6119 ((new_disk
->index
>= 0) &&
6120 (new_disk
->index
< u
->old_raid_disks
)))
6121 goto update_reshape_exit
;
6122 new_disk
->index
= disk_count
++;
6123 /* slot to fill in autolayout
6125 new_disk
->raiddisk
= new_disk
->index
;
6126 new_disk
->disk
.status
|=
6128 new_disk
->disk
.status
&= ~SPARE_DISK
;
6131 dprintf("imsm: volume set mpb->num_raid_devs = %i\n",
6132 mpb
->num_raid_devs
);
6133 /* manage changes in volume
6135 for (dev_id
= 0; dev_id
< mpb
->num_raid_devs
; dev_id
++) {
6136 void **sp
= *space_list
;
6137 struct imsm_dev
*newdev
;
6138 struct imsm_map
*newmap
, *oldmap
;
6140 for (id
= super
->devlist
; id
; id
= id
->next
) {
6141 if (id
->index
== dev_id
)
6150 /* Copy the dev, but not (all of) the map */
6151 memcpy(newdev
, id
->dev
, sizeof(*newdev
));
6152 oldmap
= get_imsm_map(id
->dev
, 0);
6153 newmap
= get_imsm_map(newdev
, 0);
6154 /* Copy the current map */
6155 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
6156 /* update one device only
6158 if (devices_to_reshape
) {
6159 dprintf("imsm: modifying subdev: %i\n",
6161 devices_to_reshape
--;
6162 newdev
->vol
.migr_state
= 1;
6163 newdev
->vol
.curr_migr_unit
= 0;
6164 newdev
->vol
.migr_type
= MIGR_GEN_MIGR
;
6165 newmap
->num_members
= u
->new_raid_disks
;
6166 for (i
= 0; i
< delta_disks
; i
++) {
6167 set_imsm_ord_tbl_ent(newmap
,
6168 u
->old_raid_disks
+ i
,
6169 u
->old_raid_disks
+ i
);
6171 /* New map is correct, now need to save old map
6173 newmap
= get_imsm_map(newdev
, 1);
6174 memcpy(newmap
, oldmap
, sizeof_imsm_map(oldmap
));
6176 imsm_set_array_size(newdev
);
6179 sp
= (void **)id
->dev
;
6185 *space_list
= tofree
;
6188 update_reshape_exit
:
6193 static int apply_takeover_update(struct imsm_update_takeover
*u
,
6194 struct intel_super
*super
,
6197 struct imsm_dev
*dev
= NULL
;
6198 struct intel_dev
*dv
;
6199 struct imsm_dev
*dev_new
;
6200 struct imsm_map
*map
;
6204 for (dv
= super
->devlist
; dv
; dv
= dv
->next
)
6205 if (dv
->index
== (unsigned int)u
->subarray
) {
6213 map
= get_imsm_map(dev
, 0);
6215 if (u
->direction
== R10_TO_R0
) {
6216 /* Number of failed disks must be half of initial disk number */
6217 if (imsm_count_failed(super
, dev
) != (map
->num_members
/ 2))
6220 /* iterate through devices to mark removed disks as spare */
6221 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
6222 if (dm
->disk
.status
& FAILED_DISK
) {
6223 int idx
= dm
->index
;
6224 /* update indexes on the disk list */
6225 /* FIXME this loop-with-the-loop looks wrong, I'm not convinced
6226 the index values will end up being correct.... NB */
6227 for (du
= super
->disks
; du
; du
= du
->next
)
6228 if (du
->index
> idx
)
6230 /* mark as spare disk */
6231 dm
->disk
.status
= SPARE_DISK
;
6236 map
->num_members
= map
->num_members
/ 2;
6237 map
->map_state
= IMSM_T_STATE_NORMAL
;
6238 map
->num_domains
= 1;
6239 map
->raid_level
= 0;
6240 map
->failed_disk_num
= -1;
6243 if (u
->direction
== R0_TO_R10
) {
6245 /* update slots in current disk list */
6246 for (dm
= super
->disks
; dm
; dm
= dm
->next
) {
6250 /* create new *missing* disks */
6251 for (i
= 0; i
< map
->num_members
; i
++) {
6252 space
= *space_list
;
6255 *space_list
= *space
;
6257 memcpy(du
, super
->disks
, sizeof(*du
));
6261 du
->index
= (i
* 2) + 1;
6262 sprintf((char *)du
->disk
.serial
,
6263 " MISSING_%d", du
->index
);
6264 sprintf((char *)du
->serial
,
6265 "MISSING_%d", du
->index
);
6266 du
->next
= super
->missing
;
6267 super
->missing
= du
;
6269 /* create new dev and map */
6270 space
= *space_list
;
6273 *space_list
= *space
;
6274 dev_new
= (void *)space
;
6275 memcpy(dev_new
, dev
, sizeof(*dev
));
6276 /* update new map */
6277 map
= get_imsm_map(dev_new
, 0);
6278 map
->num_members
= map
->num_members
* 2;
6279 map
->map_state
= IMSM_T_STATE_DEGRADED
;
6280 map
->num_domains
= 2;
6281 map
->raid_level
= 1;
6282 /* replace dev<->dev_new */
6285 /* update disk order table */
6286 for (du
= super
->disks
; du
; du
= du
->next
)
6288 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
6289 for (du
= super
->missing
; du
; du
= du
->next
)
6290 if (du
->index
>= 0) {
6291 set_imsm_ord_tbl_ent(map
, du
->index
, du
->index
);
6292 mark_missing(dev_new
, &du
->disk
, du
->index
);
6298 static void imsm_process_update(struct supertype
*st
,
6299 struct metadata_update
*update
)
6302 * crack open the metadata_update envelope to find the update record
6303 * update can be one of:
6304 * update_reshape_container_disks - all the arrays in the container
6305 * are being reshaped to have more devices. We need to mark
6306 * the arrays for general migration and convert selected spares
6307 * into active devices.
6308 * update_activate_spare - a spare device has replaced a failed
6309 * device in an array, update the disk_ord_tbl. If this disk is
6310 * present in all member arrays then also clear the SPARE_DISK
6312 * update_create_array
6314 * update_rename_array
6315 * update_add_remove_disk
6317 struct intel_super
*super
= st
->sb
;
6318 struct imsm_super
*mpb
;
6319 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
6321 /* update requires a larger buf but the allocation failed */
6322 if (super
->next_len
&& !super
->next_buf
) {
6323 super
->next_len
= 0;
6327 if (super
->next_buf
) {
6328 memcpy(super
->next_buf
, super
->buf
, super
->len
);
6330 super
->len
= super
->next_len
;
6331 super
->buf
= super
->next_buf
;
6333 super
->next_len
= 0;
6334 super
->next_buf
= NULL
;
6337 mpb
= super
->anchor
;
6340 case update_takeover
: {
6341 struct imsm_update_takeover
*u
= (void *)update
->buf
;
6342 if (apply_takeover_update(u
, super
, &update
->space_list
)) {
6343 imsm_update_version_info(super
);
6344 super
->updates_pending
++;
6349 case update_reshape_container_disks
: {
6350 struct imsm_update_reshape
*u
= (void *)update
->buf
;
6351 if (apply_reshape_container_disks_update(
6352 u
, super
, &update
->space_list
))
6353 super
->updates_pending
++;
6356 case update_reshape_migration
: {
6359 case update_activate_spare
: {
6360 struct imsm_update_activate_spare
*u
= (void *) update
->buf
;
6361 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->array
);
6362 struct imsm_map
*map
= get_imsm_map(dev
, 0);
6363 struct imsm_map
*migr_map
;
6364 struct active_array
*a
;
6365 struct imsm_disk
*disk
;
6370 int victim
= get_imsm_disk_idx(dev
, u
->slot
, -1);
6373 for (dl
= super
->disks
; dl
; dl
= dl
->next
)
6378 fprintf(stderr
, "error: imsm_activate_spare passed "
6379 "an unknown disk (index: %d)\n",
6384 super
->updates_pending
++;
6386 /* count failures (excluding rebuilds and the victim)
6387 * to determine map[0] state
6390 for (i
= 0; i
< map
->num_members
; i
++) {
6393 disk
= get_imsm_disk(super
,
6394 get_imsm_disk_idx(dev
, i
, -1));
6395 if (!disk
|| is_failed(disk
))
6399 /* adding a pristine spare, assign a new index */
6400 if (dl
->index
< 0) {
6401 dl
->index
= super
->anchor
->num_disks
;
6402 super
->anchor
->num_disks
++;
6405 disk
->status
|= CONFIGURED_DISK
;
6406 disk
->status
&= ~SPARE_DISK
;
6409 to_state
= imsm_check_degraded(super
, dev
, failed
);
6410 map
->map_state
= IMSM_T_STATE_DEGRADED
;
6411 migrate(dev
, to_state
, MIGR_REBUILD
);
6412 migr_map
= get_imsm_map(dev
, 1);
6413 set_imsm_ord_tbl_ent(map
, u
->slot
, dl
->index
);
6414 set_imsm_ord_tbl_ent(migr_map
, u
->slot
, dl
->index
| IMSM_ORD_REBUILD
);
6416 /* update the family_num to mark a new container
6417 * generation, being careful to record the existing
6418 * family_num in orig_family_num to clean up after
6419 * earlier mdadm versions that neglected to set it.
6421 if (mpb
->orig_family_num
== 0)
6422 mpb
->orig_family_num
= mpb
->family_num
;
6423 mpb
->family_num
+= super
->random
;
6425 /* count arrays using the victim in the metadata */
6427 for (a
= st
->arrays
; a
; a
= a
->next
) {
6428 dev
= get_imsm_dev(super
, a
->info
.container_member
);
6429 map
= get_imsm_map(dev
, 0);
6431 if (get_imsm_disk_slot(map
, victim
) >= 0)
6435 /* delete the victim if it is no longer being
6441 /* We know that 'manager' isn't touching anything,
6442 * so it is safe to delete
6444 for (dlp
= &super
->disks
; *dlp
; dlp
= &(*dlp
)->next
)
6445 if ((*dlp
)->index
== victim
)
6448 /* victim may be on the missing list */
6450 for (dlp
= &super
->missing
; *dlp
; dlp
= &(*dlp
)->next
)
6451 if ((*dlp
)->index
== victim
)
6453 imsm_delete(super
, dlp
, victim
);
6457 case update_create_array
: {
6458 /* someone wants to create a new array, we need to be aware of
6459 * a few races/collisions:
6460 * 1/ 'Create' called by two separate instances of mdadm
6461 * 2/ 'Create' versus 'activate_spare': mdadm has chosen
6462 * devices that have since been assimilated via
6464 * In the event this update can not be carried out mdadm will
6465 * (FIX ME) notice that its update did not take hold.
6467 struct imsm_update_create_array
*u
= (void *) update
->buf
;
6468 struct intel_dev
*dv
;
6469 struct imsm_dev
*dev
;
6470 struct imsm_map
*map
, *new_map
;
6471 unsigned long long start
, end
;
6472 unsigned long long new_start
, new_end
;
6474 struct disk_info
*inf
;
6477 /* handle racing creates: first come first serve */
6478 if (u
->dev_idx
< mpb
->num_raid_devs
) {
6479 dprintf("%s: subarray %d already defined\n",
6480 __func__
, u
->dev_idx
);
6484 /* check update is next in sequence */
6485 if (u
->dev_idx
!= mpb
->num_raid_devs
) {
6486 dprintf("%s: can not create array %d expected index %d\n",
6487 __func__
, u
->dev_idx
, mpb
->num_raid_devs
);
6491 new_map
= get_imsm_map(&u
->dev
, 0);
6492 new_start
= __le32_to_cpu(new_map
->pba_of_lba0
);
6493 new_end
= new_start
+ __le32_to_cpu(new_map
->blocks_per_member
);
6494 inf
= get_disk_info(u
);
6496 /* handle activate_spare versus create race:
6497 * check to make sure that overlapping arrays do not include
6500 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6501 dev
= get_imsm_dev(super
, i
);
6502 map
= get_imsm_map(dev
, 0);
6503 start
= __le32_to_cpu(map
->pba_of_lba0
);
6504 end
= start
+ __le32_to_cpu(map
->blocks_per_member
);
6505 if ((new_start
>= start
&& new_start
<= end
) ||
6506 (start
>= new_start
&& start
<= new_end
))
6511 if (disks_overlap(super
, i
, u
)) {
6512 dprintf("%s: arrays overlap\n", __func__
);
6517 /* check that prepare update was successful */
6518 if (!update
->space
) {
6519 dprintf("%s: prepare update failed\n", __func__
);
6523 /* check that all disks are still active before committing
6524 * changes. FIXME: could we instead handle this by creating a
6525 * degraded array? That's probably not what the user expects,
6526 * so better to drop this update on the floor.
6528 for (i
= 0; i
< new_map
->num_members
; i
++) {
6529 dl
= serial_to_dl(inf
[i
].serial
, super
);
6531 dprintf("%s: disk disappeared\n", __func__
);
6536 super
->updates_pending
++;
6538 /* convert spares to members and fixup ord_tbl */
6539 for (i
= 0; i
< new_map
->num_members
; i
++) {
6540 dl
= serial_to_dl(inf
[i
].serial
, super
);
6541 if (dl
->index
== -1) {
6542 dl
->index
= mpb
->num_disks
;
6544 dl
->disk
.status
|= CONFIGURED_DISK
;
6545 dl
->disk
.status
&= ~SPARE_DISK
;
6547 set_imsm_ord_tbl_ent(new_map
, i
, dl
->index
);
6552 update
->space
= NULL
;
6553 imsm_copy_dev(dev
, &u
->dev
);
6554 dv
->index
= u
->dev_idx
;
6555 dv
->next
= super
->devlist
;
6556 super
->devlist
= dv
;
6557 mpb
->num_raid_devs
++;
6559 imsm_update_version_info(super
);
6562 /* mdmon knows how to release update->space, but not
6563 * ((struct intel_dev *) update->space)->dev
6565 if (update
->space
) {
6571 case update_kill_array
: {
6572 struct imsm_update_kill_array
*u
= (void *) update
->buf
;
6573 int victim
= u
->dev_idx
;
6574 struct active_array
*a
;
6575 struct intel_dev
**dp
;
6576 struct imsm_dev
*dev
;
6578 /* sanity check that we are not affecting the uuid of
6579 * active arrays, or deleting an active array
6581 * FIXME when immutable ids are available, but note that
6582 * we'll also need to fixup the invalidated/active
6583 * subarray indexes in mdstat
6585 for (a
= st
->arrays
; a
; a
= a
->next
)
6586 if (a
->info
.container_member
>= victim
)
6588 /* by definition if mdmon is running at least one array
6589 * is active in the container, so checking
6590 * mpb->num_raid_devs is just extra paranoia
6592 dev
= get_imsm_dev(super
, victim
);
6593 if (a
|| !dev
|| mpb
->num_raid_devs
== 1) {
6594 dprintf("failed to delete subarray-%d\n", victim
);
6598 for (dp
= &super
->devlist
; *dp
;)
6599 if ((*dp
)->index
== (unsigned)super
->current_vol
) {
6602 if ((*dp
)->index
> (unsigned)victim
)
6606 mpb
->num_raid_devs
--;
6607 super
->updates_pending
++;
6610 case update_rename_array
: {
6611 struct imsm_update_rename_array
*u
= (void *) update
->buf
;
6612 char name
[MAX_RAID_SERIAL_LEN
+1];
6613 int target
= u
->dev_idx
;
6614 struct active_array
*a
;
6615 struct imsm_dev
*dev
;
6617 /* sanity check that we are not affecting the uuid of
6620 snprintf(name
, MAX_RAID_SERIAL_LEN
, "%s", (char *) u
->name
);
6621 name
[MAX_RAID_SERIAL_LEN
] = '\0';
6622 for (a
= st
->arrays
; a
; a
= a
->next
)
6623 if (a
->info
.container_member
== target
)
6625 dev
= get_imsm_dev(super
, u
->dev_idx
);
6626 if (a
|| !dev
|| !check_name(super
, name
, 1)) {
6627 dprintf("failed to rename subarray-%d\n", target
);
6631 snprintf((char *) dev
->volume
, MAX_RAID_SERIAL_LEN
, "%s", name
);
6632 super
->updates_pending
++;
6635 case update_add_remove_disk
: {
6636 /* we may be able to repair some arrays if disks are
6637 * being added, check teh status of add_remove_disk
6638 * if discs has been added.
6640 if (add_remove_disk_update(super
)) {
6641 struct active_array
*a
;
6643 super
->updates_pending
++;
6644 for (a
= st
->arrays
; a
; a
= a
->next
)
6645 a
->check_degraded
= 1;
6650 fprintf(stderr
, "error: unsuported process update type:"
6651 "(type: %d)\n", type
);
6655 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
);
6657 static void imsm_prepare_update(struct supertype
*st
,
6658 struct metadata_update
*update
)
6661 * Allocate space to hold new disk entries, raid-device entries or a new
6662 * mpb if necessary. The manager synchronously waits for updates to
6663 * complete in the monitor, so new mpb buffers allocated here can be
6664 * integrated by the monitor thread without worrying about live pointers
6665 * in the manager thread.
6667 enum imsm_update_type type
= *(enum imsm_update_type
*) update
->buf
;
6668 struct intel_super
*super
= st
->sb
;
6669 struct imsm_super
*mpb
= super
->anchor
;
6674 case update_takeover
: {
6675 struct imsm_update_takeover
*u
= (void *)update
->buf
;
6676 if (u
->direction
== R0_TO_R10
) {
6677 void **tail
= (void **)&update
->space_list
;
6678 struct imsm_dev
*dev
= get_imsm_dev(super
, u
->subarray
);
6679 struct imsm_map
*map
= get_imsm_map(dev
, 0);
6680 int num_members
= map
->num_members
;
6684 /* allocate memory for added disks */
6685 for (i
= 0; i
< num_members
; i
++) {
6686 size
= sizeof(struct dl
);
6687 space
= malloc(size
);
6696 /* allocate memory for new device */
6697 size
= sizeof_imsm_dev(super
->devlist
->dev
, 0) +
6698 (num_members
* sizeof(__u32
));
6699 space
= malloc(size
);
6708 len
= disks_to_mpb_size(num_members
* 2);
6710 /* if allocation didn't success, free buffer */
6711 while (update
->space_list
) {
6712 void **sp
= update
->space_list
;
6713 update
->space_list
= *sp
;
6721 case update_reshape_container_disks
: {
6722 /* Every raid device in the container is about to
6723 * gain some more devices, and we will enter a
6725 * So each 'imsm_map' will be bigger, and the imsm_vol
6726 * will now hold 2 of them.
6727 * Thus we need new 'struct imsm_dev' allocations sized
6728 * as sizeof_imsm_dev but with more devices in both maps.
6730 struct imsm_update_reshape
*u
= (void *)update
->buf
;
6731 struct intel_dev
*dl
;
6732 void **space_tail
= (void**)&update
->space_list
;
6734 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
6736 for (dl
= super
->devlist
; dl
; dl
= dl
->next
) {
6737 int size
= sizeof_imsm_dev(dl
->dev
, 1);
6739 if (u
->new_raid_disks
> u
->old_raid_disks
)
6740 size
+= sizeof(__u32
)*2*
6741 (u
->new_raid_disks
- u
->old_raid_disks
);
6750 len
= disks_to_mpb_size(u
->new_raid_disks
);
6751 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
6754 case update_reshape_migration
: {
6755 /* for migration level 0->5 we need to add disks
6756 * so the same as for container operation we will copy
6757 * device to the bigger location.
6758 * in memory prepared device and new disk area are prepared
6759 * for usage in process update
6761 struct imsm_update_reshape_migration
*u
= (void *)update
->buf
;
6762 struct intel_dev
*id
;
6763 void **space_tail
= (void **)&update
->space_list
;
6766 int current_level
= -1;
6768 dprintf("imsm: imsm_prepare_update() for update_reshape\n");
6770 /* add space for bigger array in update
6772 for (id
= super
->devlist
; id
; id
= id
->next
) {
6773 if (id
->index
== (unsigned)u
->subdev
) {
6774 size
= sizeof_imsm_dev(id
->dev
, 1);
6775 if (u
->new_raid_disks
> u
->old_raid_disks
)
6776 size
+= sizeof(__u32
)*2*
6777 (u
->new_raid_disks
- u
->old_raid_disks
);
6787 if (update
->space_list
== NULL
)
6790 /* add space for disk in update
6792 size
= sizeof(struct dl
);
6795 free(update
->space_list
);
6796 update
->space_list
= NULL
;
6803 /* add spare device to update
6805 for (id
= super
->devlist
; id
; id
= id
->next
)
6806 if (id
->index
== (unsigned)u
->subdev
) {
6807 struct imsm_dev
*dev
;
6808 struct imsm_map
*map
;
6810 dev
= get_imsm_dev(super
, u
->subdev
);
6811 map
= get_imsm_map(dev
, 0);
6812 current_level
= map
->raid_level
;
6815 if ((u
->new_level
== 5) && (u
->new_level
!= current_level
)) {
6816 struct mdinfo
*spares
;
6818 spares
= get_spares_for_grow(st
);
6826 makedev(dev
->disk
.major
,
6828 dl
= get_disk_super(super
,
6831 dl
->index
= u
->old_raid_disks
;
6837 len
= disks_to_mpb_size(u
->new_raid_disks
);
6838 dprintf("New anchor length is %llu\n", (unsigned long long)len
);
6841 case update_create_array
: {
6842 struct imsm_update_create_array
*u
= (void *) update
->buf
;
6843 struct intel_dev
*dv
;
6844 struct imsm_dev
*dev
= &u
->dev
;
6845 struct imsm_map
*map
= get_imsm_map(dev
, 0);
6847 struct disk_info
*inf
;
6851 inf
= get_disk_info(u
);
6852 len
= sizeof_imsm_dev(dev
, 1);
6853 /* allocate a new super->devlist entry */
6854 dv
= malloc(sizeof(*dv
));
6856 dv
->dev
= malloc(len
);
6861 update
->space
= NULL
;
6865 /* count how many spares will be converted to members */
6866 for (i
= 0; i
< map
->num_members
; i
++) {
6867 dl
= serial_to_dl(inf
[i
].serial
, super
);
6869 /* hmm maybe it failed?, nothing we can do about
6874 if (count_memberships(dl
, super
) == 0)
6877 len
+= activate
* sizeof(struct imsm_disk
);
6884 /* check if we need a larger metadata buffer */
6885 if (super
->next_buf
)
6886 buf_len
= super
->next_len
;
6888 buf_len
= super
->len
;
6890 if (__le32_to_cpu(mpb
->mpb_size
) + len
> buf_len
) {
6891 /* ok we need a larger buf than what is currently allocated
6892 * if this allocation fails process_update will notice that
6893 * ->next_len is set and ->next_buf is NULL
6895 buf_len
= ROUND_UP(__le32_to_cpu(mpb
->mpb_size
) + len
, 512);
6896 if (super
->next_buf
)
6897 free(super
->next_buf
);
6899 super
->next_len
= buf_len
;
6900 if (posix_memalign(&super
->next_buf
, 512, buf_len
) == 0)
6901 memset(super
->next_buf
, 0, buf_len
);
6903 super
->next_buf
= NULL
;
6907 /* must be called while manager is quiesced */
6908 static void imsm_delete(struct intel_super
*super
, struct dl
**dlp
, unsigned index
)
6910 struct imsm_super
*mpb
= super
->anchor
;
6912 struct imsm_dev
*dev
;
6913 struct imsm_map
*map
;
6914 int i
, j
, num_members
;
6917 dprintf("%s: deleting device[%d] from imsm_super\n",
6920 /* shift all indexes down one */
6921 for (iter
= super
->disks
; iter
; iter
= iter
->next
)
6922 if (iter
->index
> (int)index
)
6924 for (iter
= super
->missing
; iter
; iter
= iter
->next
)
6925 if (iter
->index
> (int)index
)
6928 for (i
= 0; i
< mpb
->num_raid_devs
; i
++) {
6929 dev
= get_imsm_dev(super
, i
);
6930 map
= get_imsm_map(dev
, 0);
6931 num_members
= map
->num_members
;
6932 for (j
= 0; j
< num_members
; j
++) {
6933 /* update ord entries being careful not to propagate
6934 * ord-flags to the first map
6936 ord
= get_imsm_ord_tbl_ent(dev
, j
, -1);
6938 if (ord_to_idx(ord
) <= index
)
6941 map
= get_imsm_map(dev
, 0);
6942 set_imsm_ord_tbl_ent(map
, j
, ord_to_idx(ord
- 1));
6943 map
= get_imsm_map(dev
, 1);
6945 set_imsm_ord_tbl_ent(map
, j
, ord
- 1);
6950 super
->updates_pending
++;
6952 struct dl
*dl
= *dlp
;
6954 *dlp
= (*dlp
)->next
;
6955 __free_imsm_disk(dl
);
6959 static char disk_by_path
[] = "/dev/disk/by-path/";
6961 static const char *imsm_get_disk_controller_domain(const char *path
)
6963 char disk_path
[PATH_MAX
];
6967 strncpy(disk_path
, disk_by_path
, PATH_MAX
- 1);
6968 strncat(disk_path
, path
, PATH_MAX
- strlen(disk_path
) - 1);
6969 if (stat(disk_path
, &st
) == 0) {
6970 struct sys_dev
* hba
;
6973 path
= devt_to_devpath(st
.st_rdev
);
6976 hba
= find_disk_attached_hba(-1, path
);
6977 if (hba
&& hba
->type
== SYS_DEV_SAS
)
6979 else if (hba
&& hba
->type
== SYS_DEV_SATA
)
6983 dprintf("path: %s hba: %s attached: %s\n",
6984 path
, (hba
) ? hba
->path
: "NULL", drv
);
6992 static int imsm_find_array_minor_by_subdev(int subdev
, int container
, int *minor
)
6994 char subdev_name
[20];
6995 struct mdstat_ent
*mdstat
;
6997 sprintf(subdev_name
, "%d", subdev
);
6998 mdstat
= mdstat_by_subdev(subdev_name
, container
);
7002 *minor
= mdstat
->devnum
;
7003 free_mdstat(mdstat
);
7007 static int imsm_reshape_is_allowed_on_container(struct supertype
*st
,
7008 struct geo_params
*geo
,
7009 int *old_raid_disks
)
7011 /* currently we only support increasing the number of devices
7012 * for a container. This increases the number of device for each
7013 * member array. They must all be RAID0 or RAID5.
7016 struct mdinfo
*info
, *member
;
7017 int devices_that_can_grow
= 0;
7019 dprintf("imsm: imsm_reshape_is_allowed_on_container(ENTER): "
7020 "st->devnum = (%i)\n",
7023 if (geo
->size
!= -1 ||
7024 geo
->level
!= UnSet
||
7025 geo
->layout
!= UnSet
||
7026 geo
->chunksize
!= 0 ||
7027 geo
->raid_disks
== UnSet
) {
7028 dprintf("imsm: Container operation is allowed for "
7029 "raid disks number change only.\n");
7033 info
= container_content_imsm(st
, NULL
);
7034 for (member
= info
; member
; member
= member
->next
) {
7038 dprintf("imsm: checking device_num: %i\n",
7039 member
->container_member
);
7041 if (geo
->raid_disks
<= member
->array
.raid_disks
) {
7042 /* we work on container for Online Capacity Expansion
7043 * only so raid_disks has to grow
7045 dprintf("imsm: for container operation raid disks "
7046 "increase is required\n");
7050 if ((info
->array
.level
!= 0) &&
7051 (info
->array
.level
!= 5)) {
7052 /* we cannot use this container with other raid level
7054 dprintf("imsm: for container operation wrong"
7055 " raid level (%i) detected\n",
7059 /* check for platform support
7060 * for this raid level configuration
7062 struct intel_super
*super
= st
->sb
;
7063 if (!is_raid_level_supported(super
->orom
,
7064 member
->array
.level
,
7066 dprintf("platform does not support raid%d with"
7070 geo
->raid_disks
> 1 ? "s" : "");
7073 /* check if component size is aligned to chunk size
7075 if (info
->component_size
%
7076 (info
->array
.chunk_size
/512)) {
7077 dprintf("Component size is not aligned to "
7083 if (*old_raid_disks
&&
7084 info
->array
.raid_disks
!= *old_raid_disks
)
7086 *old_raid_disks
= info
->array
.raid_disks
;
7088 /* All raid5 and raid0 volumes in container
7089 * have to be ready for Online Capacity Expansion
7090 * so they need to be assembled. We have already
7091 * checked that no recovery etc is happening.
7093 result
= imsm_find_array_minor_by_subdev(member
->container_member
,
7097 dprintf("imsm: cannot find array\n");
7100 devices_that_can_grow
++;
7103 if (!member
&& devices_that_can_grow
)
7107 dprintf("\tContainer operation allowed\n");
7109 dprintf("\tError: %i\n", ret_val
);
7114 /* Function: get_spares_for_grow
7115 * Description: Allocates memory and creates list of spare devices
7116 * avaliable in container. Checks if spare drive size is acceptable.
7117 * Parameters: Pointer to the supertype structure
7118 * Returns: Pointer to the list of spare devices (mdinfo structure) on success,
7121 static struct mdinfo
*get_spares_for_grow(struct supertype
*st
)
7123 unsigned long long min_size
= min_acceptable_spare_size_imsm(st
);
7124 return container_choose_spares(st
, min_size
, NULL
, NULL
, NULL
, 0);
7127 /******************************************************************************
7128 * function: imsm_create_metadata_update_for_reshape
7129 * Function creates update for whole IMSM container.
7131 ******************************************************************************/
7132 static int imsm_create_metadata_update_for_reshape(
7133 struct supertype
*st
,
7134 struct geo_params
*geo
,
7136 struct imsm_update_reshape
**updatep
)
7138 struct intel_super
*super
= st
->sb
;
7139 struct imsm_super
*mpb
= super
->anchor
;
7140 int update_memory_size
= 0;
7141 struct imsm_update_reshape
*u
= NULL
;
7142 struct mdinfo
*spares
= NULL
;
7144 int delta_disks
= 0;
7147 dprintf("imsm_update_metadata_for_reshape(enter) raid_disks = %i\n",
7150 delta_disks
= geo
->raid_disks
- old_raid_disks
;
7152 /* size of all update data without anchor */
7153 update_memory_size
= sizeof(struct imsm_update_reshape
);
7155 /* now add space for spare disks that we need to add. */
7156 update_memory_size
+= sizeof(u
->new_disks
[0]) * (delta_disks
- 1);
7158 u
= calloc(1, update_memory_size
);
7161 "cannot get memory for imsm_update_reshape update\n");
7164 u
->type
= update_reshape_container_disks
;
7165 u
->old_raid_disks
= old_raid_disks
;
7166 u
->new_raid_disks
= geo
->raid_disks
;
7168 /* now get spare disks list
7170 spares
= get_spares_for_grow(st
);
7173 || delta_disks
> spares
->array
.spare_disks
) {
7174 fprintf(stderr
, Name
": imsm: ERROR: Cannot get spare devices "
7175 "for %s.\n", geo
->dev_name
);
7179 /* we have got spares
7180 * update disk list in imsm_disk list table in anchor
7182 dprintf("imsm: %i spares are available.\n\n",
7183 spares
->array
.spare_disks
);
7186 for (i
= 0; i
< delta_disks
; i
++) {
7191 u
->new_disks
[i
] = makedev(dev
->disk
.major
,
7193 dl
= get_disk_super(super
, dev
->disk
.major
, dev
->disk
.minor
);
7194 dl
->index
= mpb
->num_disks
;
7204 dprintf("imsm: reshape update preparation :");
7205 if (i
== delta_disks
) {
7208 return update_memory_size
;
7211 dprintf(" Error\n");
7216 /******************************************************************************
7217 * function: imsm_create_metadata_update_for_migration()
7218 * Creates update for IMSM array.
7220 ******************************************************************************/
7221 static int imsm_create_metadata_update_for_migration(
7222 struct supertype
*st
,
7223 struct geo_params
*geo
,
7224 struct imsm_update_reshape_migration
**updatep
)
7226 struct intel_super
*super
= st
->sb
;
7227 int update_memory_size
= 0;
7228 struct imsm_update_reshape_migration
*u
= NULL
;
7229 struct imsm_dev
*dev
;
7230 int previous_level
= -1;
7232 dprintf("imsm_create_metadata_update_for_migration(enter)"
7233 " New Level = %i\n", geo
->level
);
7235 /* size of all update data without anchor */
7236 update_memory_size
= sizeof(struct imsm_update_reshape_migration
);
7238 u
= calloc(1, update_memory_size
);
7240 dprintf("error: cannot get memory for "
7241 "imsm_create_metadata_update_for_migration\n");
7244 u
->type
= update_reshape_migration
;
7245 u
->subdev
= super
->current_vol
;
7246 u
->new_level
= geo
->level
;
7247 u
->new_layout
= geo
->layout
;
7248 u
->new_raid_disks
= u
->old_raid_disks
= geo
->raid_disks
;
7249 u
->new_disks
[0] = -1;
7251 dev
= get_imsm_dev(super
, u
->subdev
);
7253 struct imsm_map
*map
;
7255 map
= get_imsm_map(dev
, 0);
7257 previous_level
= map
->raid_level
;
7259 if ((geo
->level
== 5) && (previous_level
== 0)) {
7260 struct mdinfo
*spares
= NULL
;
7262 u
->new_raid_disks
++;
7263 spares
= get_spares_for_grow(st
);
7264 if ((spares
== NULL
) || (spares
->array
.spare_disks
< 1)) {
7267 update_memory_size
= 0;
7268 dprintf("error: cannot get spare device "
7269 "for requested migration");
7274 dprintf("imsm: reshape update preparation : OK\n");
7277 return update_memory_size
;
7280 static void imsm_update_metadata_locally(struct supertype
*st
,
7283 struct metadata_update mu
;
7288 mu
.space_list
= NULL
;
7290 imsm_prepare_update(st
, &mu
);
7291 imsm_process_update(st
, &mu
);
7293 while (mu
.space_list
) {
7294 void **space
= mu
.space_list
;
7295 mu
.space_list
= *space
;
7300 /***************************************************************************
7301 * Function: imsm_analyze_change
7302 * Description: Function analyze change for single volume
7303 * and validate if transition is supported
7304 * Parameters: Geometry parameters, supertype structure
7305 * Returns: Operation type code on success, -1 if fail
7306 ****************************************************************************/
7307 enum imsm_reshape_type
imsm_analyze_change(struct supertype
*st
,
7308 struct geo_params
*geo
)
7315 getinfo_super_imsm_volume(st
, &info
, NULL
);
7317 if ((geo
->level
!= info
.array
.level
) &&
7318 (geo
->level
>= 0) &&
7319 (geo
->level
!= UnSet
)) {
7320 switch (info
.array
.level
) {
7322 if (geo
->level
== 5) {
7323 change
= CH_MIGRATION
;
7326 if (geo
->level
== 10) {
7327 change
= CH_TAKEOVER
;
7332 if (geo
->level
== 0) {
7333 change
= CH_TAKEOVER
;
7338 if (geo
->level
== 0) {
7339 change
= CH_TAKEOVER
;
7346 Name
" Error. Level Migration from %d to %d "
7348 info
.array
.level
, geo
->level
);
7349 goto analyse_change_exit
;
7352 geo
->level
= info
.array
.level
;
7354 if ((geo
->layout
!= info
.array
.layout
)
7355 && ((geo
->layout
!= UnSet
) && (geo
->layout
!= -1))) {
7356 change
= CH_MIGRATION
;
7357 if ((info
.array
.layout
== 0)
7358 && (info
.array
.level
== 5)
7359 && (geo
->layout
== 5)) {
7360 /* reshape 5 -> 4 */
7361 } else if ((info
.array
.layout
== 5)
7362 && (info
.array
.level
== 5)
7363 && (geo
->layout
== 0)) {
7364 /* reshape 4 -> 5 */
7369 Name
" Error. Layout Migration from %d to %d "
7371 info
.array
.layout
, geo
->layout
);
7373 goto analyse_change_exit
;
7376 geo
->layout
= info
.array
.layout
;
7378 if ((geo
->chunksize
> 0) && (geo
->chunksize
!= UnSet
)
7379 && (geo
->chunksize
!= info
.array
.chunk_size
))
7380 change
= CH_MIGRATION
;
7382 geo
->chunksize
= info
.array
.chunk_size
;
7384 chunk
= geo
->chunksize
/ 1024;
7385 if (!validate_geometry_imsm(st
,
7395 struct intel_super
*super
= st
->sb
;
7396 struct imsm_super
*mpb
= super
->anchor
;
7398 if (mpb
->num_raid_devs
> 1) {
7400 Name
" Error. Cannot perform operation on %s"
7401 "- for this operation it MUST be single "
7402 "array in container\n",
7408 analyse_change_exit
:
7413 int imsm_takeover(struct supertype
*st
, struct geo_params
*geo
)
7415 struct intel_super
*super
= st
->sb
;
7416 struct imsm_update_takeover
*u
;
7418 u
= malloc(sizeof(struct imsm_update_takeover
));
7422 u
->type
= update_takeover
;
7423 u
->subarray
= super
->current_vol
;
7425 /* 10->0 transition */
7426 if (geo
->level
== 0)
7427 u
->direction
= R10_TO_R0
;
7429 /* 0->10 transition */
7430 if (geo
->level
== 10)
7431 u
->direction
= R0_TO_R10
;
7433 /* update metadata locally */
7434 imsm_update_metadata_locally(st
, u
,
7435 sizeof(struct imsm_update_takeover
));
7436 /* and possibly remotely */
7437 if (st
->update_tail
)
7438 append_metadata_update(st
, u
,
7439 sizeof(struct imsm_update_takeover
));
7446 static int warn_user_about_risk(void)
7451 "\nThis is an experimental feature. Data on the RAID volume(s) "
7452 "can be lost!!!\n\n"
7453 "To continue command execution please make sure that\n"
7454 "the grow process will not be interrupted. Use safe power\n"
7455 "supply to avoid unexpected system reboot. Make sure that\n"
7456 "reshaped container is not assembled automatically during\n"
7458 "If reshape is interrupted, assemble array manually\n"
7459 "using e.g. '-Ac' option and up to date mdadm.conf file.\n"
7460 "Assembly in scan mode is not possible in such case.\n"
7461 "Growing container with boot array is not possible.\n"
7462 "If boot array reshape is interrupted, whole file system\n"
7463 "can be lost.\n\n");
7464 rv
= ask("Do you want to continue? ");
7465 fprintf(stderr
, "\n");
7470 static int imsm_reshape_super(struct supertype
*st
, long long size
, int level
,
7471 int layout
, int chunksize
, int raid_disks
,
7472 int delta_disks
, char *backup
, char *dev
,
7476 struct geo_params geo
;
7478 dprintf("imsm: reshape_super called.\n");
7480 memset(&geo
, 0, sizeof(struct geo_params
));
7483 geo
.dev_id
= st
->devnum
;
7486 geo
.layout
= layout
;
7487 geo
.chunksize
= chunksize
;
7488 geo
.raid_disks
= raid_disks
;
7489 if (delta_disks
!= UnSet
)
7490 geo
.raid_disks
+= delta_disks
;
7492 dprintf("\tfor level : %i\n", geo
.level
);
7493 dprintf("\tfor raid_disks : %i\n", geo
.raid_disks
);
7495 if (experimental() == 0)
7498 if (st
->container_dev
== st
->devnum
) {
7499 /* On container level we can only increase number of devices. */
7500 dprintf("imsm: info: Container operation\n");
7501 int old_raid_disks
= 0;
7503 /* this warning will be removed when imsm checkpointing
7504 * will be implemented, and restoring from check-point
7505 * operation will be transparent for reboot process
7507 if (warn_user_about_risk() == 0)
7510 if (imsm_reshape_is_allowed_on_container(
7511 st
, &geo
, &old_raid_disks
)) {
7512 struct imsm_update_reshape
*u
= NULL
;
7515 len
= imsm_create_metadata_update_for_reshape(
7516 st
, &geo
, old_raid_disks
, &u
);
7519 dprintf("imsm: Cannot prepare update\n");
7520 goto exit_imsm_reshape_super
;
7524 /* update metadata locally */
7525 imsm_update_metadata_locally(st
, u
, len
);
7526 /* and possibly remotely */
7527 if (st
->update_tail
)
7528 append_metadata_update(st
, u
, len
);
7533 fprintf(stderr
, Name
": (imsm) Operation "
7534 "is not allowed on this container\n");
7537 /* On volume level we support following operations
7538 * - takeover: raid10 -> raid0; raid0 -> raid10
7539 * - chunk size migration
7540 * - migration: raid5 -> raid0; raid0 -> raid5
7542 struct intel_super
*super
= st
->sb
;
7543 struct intel_dev
*dev
= super
->devlist
;
7545 dprintf("imsm: info: Volume operation\n");
7546 /* find requested device */
7548 imsm_find_array_minor_by_subdev(dev
->index
, st
->container_dev
, &devnum
);
7549 if (devnum
== geo
.dev_id
)
7554 fprintf(stderr
, Name
" Cannot find %s (%i) subarray\n",
7555 geo
.dev_name
, geo
.dev_id
);
7556 goto exit_imsm_reshape_super
;
7558 super
->current_vol
= dev
->index
;
7559 change
= imsm_analyze_change(st
, &geo
);
7562 ret_val
= imsm_takeover(st
, &geo
);
7564 case CH_MIGRATION
: {
7565 struct imsm_update_reshape_migration
*u
= NULL
;
7567 imsm_create_metadata_update_for_migration(
7571 "Cannot prepare update\n");
7575 /* update metadata locally */
7576 imsm_update_metadata_locally(st
, u
, len
);
7577 /* and possibly remotely */
7578 if (st
->update_tail
)
7579 append_metadata_update(st
, u
, len
);
7589 exit_imsm_reshape_super
:
7590 dprintf("imsm: reshape_super Exit code = %i\n", ret_val
);
7594 static int imsm_manage_reshape(
7595 int afd
, struct mdinfo
*sra
, struct reshape
*reshape
,
7596 struct supertype
*st
, unsigned long stripes
,
7597 int *fds
, unsigned long long *offsets
,
7598 int dests
, int *destfd
, unsigned long long *destoffsets
)
7600 /* Just use child_monitor for now */
7601 return child_monitor(
7602 afd
, sra
, reshape
, st
, stripes
,
7603 fds
, offsets
, dests
, destfd
, destoffsets
);
7605 #endif /* MDASSEMBLE */
7607 struct superswitch super_imsm
= {
7609 .examine_super
= examine_super_imsm
,
7610 .brief_examine_super
= brief_examine_super_imsm
,
7611 .brief_examine_subarrays
= brief_examine_subarrays_imsm
,
7612 .export_examine_super
= export_examine_super_imsm
,
7613 .detail_super
= detail_super_imsm
,
7614 .brief_detail_super
= brief_detail_super_imsm
,
7615 .write_init_super
= write_init_super_imsm
,
7616 .validate_geometry
= validate_geometry_imsm
,
7617 .add_to_super
= add_to_super_imsm
,
7618 .remove_from_super
= remove_from_super_imsm
,
7619 .detail_platform
= detail_platform_imsm
,
7620 .kill_subarray
= kill_subarray_imsm
,
7621 .update_subarray
= update_subarray_imsm
,
7622 .load_container
= load_container_imsm
,
7623 .default_geometry
= default_geometry_imsm
,
7624 .get_disk_controller_domain
= imsm_get_disk_controller_domain
,
7625 .reshape_super
= imsm_reshape_super
,
7626 .manage_reshape
= imsm_manage_reshape
,
7628 .match_home
= match_home_imsm
,
7629 .uuid_from_super
= uuid_from_super_imsm
,
7630 .getinfo_super
= getinfo_super_imsm
,
7631 .getinfo_super_disks
= getinfo_super_disks_imsm
,
7632 .update_super
= update_super_imsm
,
7634 .avail_size
= avail_size_imsm
,
7635 .min_acceptable_spare_size
= min_acceptable_spare_size_imsm
,
7637 .compare_super
= compare_super_imsm
,
7639 .load_super
= load_super_imsm
,
7640 .init_super
= init_super_imsm
,
7641 .store_super
= store_super_imsm
,
7642 .free_super
= free_super_imsm
,
7643 .match_metadata_desc
= match_metadata_desc_imsm
,
7644 .container_content
= container_content_imsm
,
7651 .open_new
= imsm_open_new
,
7652 .set_array_state
= imsm_set_array_state
,
7653 .set_disk
= imsm_set_disk
,
7654 .sync_metadata
= imsm_sync_metadata
,
7655 .activate_spare
= imsm_activate_spare
,
7656 .process_update
= imsm_process_update
,
7657 .prepare_update
= imsm_prepare_update
,
7658 #endif /* MDASSEMBLE */