]>
Commit | Line | Data |
---|---|---|
cdddbdbc DW |
1 | /* |
2 | * mdadm - Intel(R) Matrix Storage Manager Support | |
3 | * | |
a54d5262 | 4 | * Copyright (C) 2002-2008 Intel Corporation |
cdddbdbc DW |
5 | * |
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. | |
9 | * | |
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 | |
13 | * more details. | |
14 | * | |
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. | |
18 | */ | |
19 | ||
51006d85 | 20 | #define HAVE_STDINT_H 1 |
cdddbdbc | 21 | #include "mdadm.h" |
c2a1e7da | 22 | #include "mdmon.h" |
51006d85 | 23 | #include "sha1.h" |
88c32bb1 | 24 | #include "platform-intel.h" |
cdddbdbc DW |
25 | #include <values.h> |
26 | #include <scsi/sg.h> | |
27 | #include <ctype.h> | |
d665cc31 | 28 | #include <dirent.h> |
cdddbdbc DW |
29 | |
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" | |
fe7ed8cb DW |
35 | #define MPB_VERSION_MANY_VOLUMES_PER_ARRAY "1.2.00" |
36 | #define MPB_VERSION_3OR4_DISK_ARRAY "1.2.01" | |
cdddbdbc | 37 | #define MPB_VERSION_RAID5 "1.2.02" |
fe7ed8cb DW |
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" | |
cdddbdbc DW |
41 | #define MAX_SIGNATURE_LENGTH 32 |
42 | #define MAX_RAID_SERIAL_LEN 16 | |
fe7ed8cb DW |
43 | |
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) | |
53 | ||
c2c087e6 DW |
54 | #define MPB_SECTOR_CNT 418 |
55 | #define IMSM_RESERVED_SECTORS 4096 | |
979d38be | 56 | #define SECT_PER_MB_SHIFT 11 |
cdddbdbc DW |
57 | |
58 | /* Disk configuration info. */ | |
59 | #define IMSM_MAX_DEVICES 255 | |
60 | struct imsm_disk { | |
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 */ | |
f2f27e63 DW |
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 */ | |
cdddbdbc | 67 | __u32 status; /* 0xF0 - 0xF3 */ |
fe7ed8cb DW |
68 | __u32 owner_cfg_num; /* which config 0,1,2... owns this disk */ |
69 | #define IMSM_DISK_FILLERS 4 | |
cdddbdbc DW |
70 | __u32 filler[IMSM_DISK_FILLERS]; /* 0xF4 - 0x107 MPB_DISK_FILLERS for future expansion */ |
71 | }; | |
72 | ||
73 | /* RAID map configuration infos. */ | |
74 | struct imsm_map { | |
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 | |
e3bba0e0 DW |
82 | #define IMSM_T_STATE_DEGRADED 2 |
83 | #define IMSM_T_STATE_FAILED 3 | |
cdddbdbc DW |
84 | __u8 raid_level; |
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 */ | |
fe7ed8cb DW |
89 | __u8 num_domains; /* number of parity domains */ |
90 | __u8 failed_disk_num; /* valid only when state is degraded */ | |
252d23c0 | 91 | __u8 ddf; |
cdddbdbc | 92 | __u32 filler[7]; /* expansion area */ |
7eef0453 | 93 | #define IMSM_ORD_REBUILD (1 << 24) |
cdddbdbc | 94 | __u32 disk_ord_tbl[1]; /* disk_ord_tbl[num_members], |
7eef0453 DW |
95 | * top byte contains some flags |
96 | */ | |
cdddbdbc DW |
97 | } __attribute__ ((packed)); |
98 | ||
99 | struct imsm_vol { | |
f8f603f1 | 100 | __u32 curr_migr_unit; |
fe7ed8cb | 101 | __u32 checkpoint_id; /* id to access curr_migr_unit */ |
cdddbdbc | 102 | __u8 migr_state; /* Normal or Migrating */ |
e3bba0e0 DW |
103 | #define MIGR_INIT 0 |
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 | |
1484e727 | 108 | #define MIGR_REPAIR 5 |
cdddbdbc DW |
109 | __u8 migr_type; /* Initializing, Rebuilding, ... */ |
110 | __u8 dirty; | |
fe7ed8cb DW |
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 */ | |
114 | __u32 filler[4]; | |
cdddbdbc DW |
115 | struct imsm_map map[1]; |
116 | /* here comes another one if migr_state */ | |
117 | } __attribute__ ((packed)); | |
118 | ||
119 | struct imsm_dev { | |
fe7ed8cb | 120 | __u8 volume[MAX_RAID_SERIAL_LEN]; |
cdddbdbc DW |
121 | __u32 size_low; |
122 | __u32 size_high; | |
fe7ed8cb DW |
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) | |
cdddbdbc DW |
136 | __u32 status; /* Persistent RaidDev status */ |
137 | __u32 reserved_blocks; /* Reserved blocks at beginning of volume */ | |
fe7ed8cb DW |
138 | __u8 migr_priority; |
139 | __u8 num_sub_vols; | |
140 | __u8 tid; | |
141 | __u8 cng_master_disk; | |
142 | __u16 cache_policy; | |
143 | __u8 cng_state; | |
144 | __u8 cng_sub_state; | |
145 | #define IMSM_DEV_FILLERS 10 | |
cdddbdbc DW |
146 | __u32 filler[IMSM_DEV_FILLERS]; |
147 | struct imsm_vol vol; | |
148 | } __attribute__ ((packed)); | |
149 | ||
150 | struct imsm_super { | |
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 */ | |
604b746f JD |
156 | __u32 error_log_size; /* 0x30 - 0x33 in bytes */ |
157 | __u32 attributes; /* 0x34 - 0x37 */ | |
cdddbdbc DW |
158 | __u8 num_disks; /* 0x38 Number of configured disks */ |
159 | __u8 num_raid_devs; /* 0x39 Number of configured volumes */ | |
604b746f JD |
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 */ | |
cdddbdbc DW |
168 | struct imsm_disk disk[1]; /* 0xD8 diskTbl[numDisks] */ |
169 | /* here comes imsm_dev[num_raid_devs] */ | |
604b746f | 170 | /* here comes BBM logs */ |
cdddbdbc DW |
171 | } __attribute__ ((packed)); |
172 | ||
604b746f JD |
173 | #define BBM_LOG_MAX_ENTRIES 254 |
174 | ||
175 | struct bbm_log_entry { | |
176 | __u64 defective_block_start; | |
177 | #define UNREADABLE 0xFFFFFFFF | |
178 | __u32 spare_block_offset; | |
179 | __u16 remapped_marked_count; | |
180 | __u16 disk_ordinal; | |
181 | } __attribute__ ((__packed__)); | |
182 | ||
183 | struct bbm_log { | |
184 | __u32 signature; /* 0xABADB10C */ | |
185 | __u32 entry_count; | |
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__)); | |
191 | ||
192 | ||
cdddbdbc DW |
193 | #ifndef MDASSEMBLE |
194 | static char *map_state_str[] = { "normal", "uninitialized", "degraded", "failed" }; | |
195 | #endif | |
196 | ||
1484e727 DW |
197 | static __u8 migr_type(struct imsm_dev *dev) |
198 | { | |
199 | if (dev->vol.migr_type == MIGR_VERIFY && | |
200 | dev->status & DEV_VERIFY_AND_FIX) | |
201 | return MIGR_REPAIR; | |
202 | else | |
203 | return dev->vol.migr_type; | |
204 | } | |
205 | ||
206 | static void set_migr_type(struct imsm_dev *dev, __u8 migr_type) | |
207 | { | |
208 | /* for compatibility with older oroms convert MIGR_REPAIR, into | |
209 | * MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status | |
210 | */ | |
211 | if (migr_type == MIGR_REPAIR) { | |
212 | dev->vol.migr_type = MIGR_VERIFY; | |
213 | dev->status |= DEV_VERIFY_AND_FIX; | |
214 | } else { | |
215 | dev->vol.migr_type = migr_type; | |
216 | dev->status &= ~DEV_VERIFY_AND_FIX; | |
217 | } | |
218 | } | |
219 | ||
87eb16df | 220 | static unsigned int sector_count(__u32 bytes) |
cdddbdbc | 221 | { |
87eb16df DW |
222 | return ((bytes + (512-1)) & (~(512-1))) / 512; |
223 | } | |
cdddbdbc | 224 | |
87eb16df DW |
225 | static unsigned int mpb_sectors(struct imsm_super *mpb) |
226 | { | |
227 | return sector_count(__le32_to_cpu(mpb->mpb_size)); | |
cdddbdbc DW |
228 | } |
229 | ||
ba2de7ba DW |
230 | struct intel_dev { |
231 | struct imsm_dev *dev; | |
232 | struct intel_dev *next; | |
f21e18ca | 233 | unsigned index; |
ba2de7ba DW |
234 | }; |
235 | ||
cdddbdbc DW |
236 | /* internal representation of IMSM metadata */ |
237 | struct intel_super { | |
238 | union { | |
949c47a0 DW |
239 | void *buf; /* O_DIRECT buffer for reading/writing metadata */ |
240 | struct imsm_super *anchor; /* immovable parameters */ | |
cdddbdbc | 241 | }; |
949c47a0 | 242 | size_t len; /* size of the 'buf' allocation */ |
4d7b1503 DW |
243 | void *next_buf; /* for realloc'ing buf from the manager */ |
244 | size_t next_len; | |
c2c087e6 | 245 | int updates_pending; /* count of pending updates for mdmon */ |
bf5a934a | 246 | int current_vol; /* index of raid device undergoing creation */ |
0dcecb2e | 247 | __u32 create_offset; /* common start for 'current_vol' */ |
148acb7b | 248 | __u32 random; /* random data for seeding new family numbers */ |
ba2de7ba | 249 | struct intel_dev *devlist; |
cdddbdbc DW |
250 | struct dl { |
251 | struct dl *next; | |
252 | int index; | |
253 | __u8 serial[MAX_RAID_SERIAL_LEN]; | |
254 | int major, minor; | |
255 | char *devname; | |
b9f594fe | 256 | struct imsm_disk disk; |
cdddbdbc | 257 | int fd; |
0dcecb2e DW |
258 | int extent_cnt; |
259 | struct extent *e; /* for determining freespace @ create */ | |
efb30e7f | 260 | int raiddisk; /* slot to fill in autolayout */ |
cdddbdbc | 261 | } *disks; |
43dad3d6 | 262 | struct dl *add; /* list of disks to add while mdmon active */ |
47ee5a45 | 263 | struct dl *missing; /* disks removed while we weren't looking */ |
43dad3d6 | 264 | struct bbm_log *bbm_log; |
88c32bb1 DW |
265 | const char *hba; /* device path of the raid controller for this metadata */ |
266 | const struct imsm_orom *orom; /* platform firmware support */ | |
a2b97981 DW |
267 | struct intel_super *next; /* (temp) list for disambiguating family_num */ |
268 | }; | |
269 | ||
270 | struct intel_disk { | |
271 | struct imsm_disk disk; | |
272 | #define IMSM_UNKNOWN_OWNER (-1) | |
273 | int owner; | |
274 | struct intel_disk *next; | |
cdddbdbc DW |
275 | }; |
276 | ||
c2c087e6 DW |
277 | struct extent { |
278 | unsigned long long start, size; | |
279 | }; | |
280 | ||
88758e9d DW |
281 | /* definition of messages passed to imsm_process_update */ |
282 | enum imsm_update_type { | |
283 | update_activate_spare, | |
8273f55e | 284 | update_create_array, |
33414a01 | 285 | update_kill_array, |
aa534678 | 286 | update_rename_array, |
43dad3d6 | 287 | update_add_disk, |
88758e9d DW |
288 | }; |
289 | ||
290 | struct imsm_update_activate_spare { | |
291 | enum imsm_update_type type; | |
d23fe947 | 292 | struct dl *dl; |
88758e9d DW |
293 | int slot; |
294 | int array; | |
295 | struct imsm_update_activate_spare *next; | |
296 | }; | |
297 | ||
54c2c1ea DW |
298 | struct disk_info { |
299 | __u8 serial[MAX_RAID_SERIAL_LEN]; | |
300 | }; | |
301 | ||
8273f55e DW |
302 | struct imsm_update_create_array { |
303 | enum imsm_update_type type; | |
8273f55e | 304 | int dev_idx; |
6a3e913e | 305 | struct imsm_dev dev; |
8273f55e DW |
306 | }; |
307 | ||
33414a01 DW |
308 | struct imsm_update_kill_array { |
309 | enum imsm_update_type type; | |
310 | int dev_idx; | |
311 | }; | |
312 | ||
aa534678 DW |
313 | struct imsm_update_rename_array { |
314 | enum imsm_update_type type; | |
315 | __u8 name[MAX_RAID_SERIAL_LEN]; | |
316 | int dev_idx; | |
317 | }; | |
318 | ||
43dad3d6 DW |
319 | struct imsm_update_add_disk { |
320 | enum imsm_update_type type; | |
321 | }; | |
322 | ||
cdddbdbc DW |
323 | static struct supertype *match_metadata_desc_imsm(char *arg) |
324 | { | |
325 | struct supertype *st; | |
326 | ||
327 | if (strcmp(arg, "imsm") != 0 && | |
328 | strcmp(arg, "default") != 0 | |
329 | ) | |
330 | return NULL; | |
331 | ||
332 | st = malloc(sizeof(*st)); | |
4e9d2186 AW |
333 | if (!st) |
334 | return NULL; | |
ef609477 | 335 | memset(st, 0, sizeof(*st)); |
d1d599ea | 336 | st->container_dev = NoMdDev; |
cdddbdbc DW |
337 | st->ss = &super_imsm; |
338 | st->max_devs = IMSM_MAX_DEVICES; | |
339 | st->minor_version = 0; | |
340 | st->sb = NULL; | |
341 | return st; | |
342 | } | |
343 | ||
0e600426 | 344 | #ifndef MDASSEMBLE |
cdddbdbc DW |
345 | static __u8 *get_imsm_version(struct imsm_super *mpb) |
346 | { | |
347 | return &mpb->sig[MPB_SIG_LEN]; | |
348 | } | |
0e600426 | 349 | #endif |
cdddbdbc | 350 | |
949c47a0 DW |
351 | /* retrieve a disk directly from the anchor when the anchor is known to be |
352 | * up-to-date, currently only at load time | |
353 | */ | |
354 | static struct imsm_disk *__get_imsm_disk(struct imsm_super *mpb, __u8 index) | |
cdddbdbc | 355 | { |
949c47a0 | 356 | if (index >= mpb->num_disks) |
cdddbdbc DW |
357 | return NULL; |
358 | return &mpb->disk[index]; | |
359 | } | |
360 | ||
b9f594fe | 361 | /* retrieve a disk from the parsed metadata */ |
949c47a0 DW |
362 | static struct imsm_disk *get_imsm_disk(struct intel_super *super, __u8 index) |
363 | { | |
b9f594fe DW |
364 | struct dl *d; |
365 | ||
366 | for (d = super->disks; d; d = d->next) | |
367 | if (d->index == index) | |
368 | return &d->disk; | |
369 | ||
370 | return NULL; | |
949c47a0 DW |
371 | } |
372 | ||
373 | /* generate a checksum directly from the anchor when the anchor is known to be | |
374 | * up-to-date, currently only at load or write_super after coalescing | |
375 | */ | |
376 | static __u32 __gen_imsm_checksum(struct imsm_super *mpb) | |
cdddbdbc DW |
377 | { |
378 | __u32 end = mpb->mpb_size / sizeof(end); | |
379 | __u32 *p = (__u32 *) mpb; | |
380 | __u32 sum = 0; | |
381 | ||
97f734fd N |
382 | while (end--) { |
383 | sum += __le32_to_cpu(*p); | |
384 | p++; | |
385 | } | |
cdddbdbc DW |
386 | |
387 | return sum - __le32_to_cpu(mpb->check_sum); | |
388 | } | |
389 | ||
a965f303 DW |
390 | static size_t sizeof_imsm_map(struct imsm_map *map) |
391 | { | |
392 | return sizeof(struct imsm_map) + sizeof(__u32) * (map->num_members - 1); | |
393 | } | |
394 | ||
395 | struct imsm_map *get_imsm_map(struct imsm_dev *dev, int second_map) | |
cdddbdbc | 396 | { |
a965f303 DW |
397 | struct imsm_map *map = &dev->vol.map[0]; |
398 | ||
399 | if (second_map && !dev->vol.migr_state) | |
400 | return NULL; | |
401 | else if (second_map) { | |
402 | void *ptr = map; | |
403 | ||
404 | return ptr + sizeof_imsm_map(map); | |
405 | } else | |
406 | return map; | |
407 | ||
408 | } | |
cdddbdbc | 409 | |
3393c6af DW |
410 | /* return the size of the device. |
411 | * migr_state increases the returned size if map[0] were to be duplicated | |
412 | */ | |
413 | static size_t sizeof_imsm_dev(struct imsm_dev *dev, int migr_state) | |
a965f303 DW |
414 | { |
415 | size_t size = sizeof(*dev) - sizeof(struct imsm_map) + | |
416 | sizeof_imsm_map(get_imsm_map(dev, 0)); | |
cdddbdbc DW |
417 | |
418 | /* migrating means an additional map */ | |
a965f303 DW |
419 | if (dev->vol.migr_state) |
420 | size += sizeof_imsm_map(get_imsm_map(dev, 1)); | |
3393c6af DW |
421 | else if (migr_state) |
422 | size += sizeof_imsm_map(get_imsm_map(dev, 0)); | |
cdddbdbc DW |
423 | |
424 | return size; | |
425 | } | |
426 | ||
54c2c1ea DW |
427 | #ifndef MDASSEMBLE |
428 | /* retrieve disk serial number list from a metadata update */ | |
429 | static struct disk_info *get_disk_info(struct imsm_update_create_array *update) | |
430 | { | |
431 | void *u = update; | |
432 | struct disk_info *inf; | |
433 | ||
434 | inf = u + sizeof(*update) - sizeof(struct imsm_dev) + | |
435 | sizeof_imsm_dev(&update->dev, 0); | |
436 | ||
437 | return inf; | |
438 | } | |
439 | #endif | |
440 | ||
949c47a0 | 441 | static struct imsm_dev *__get_imsm_dev(struct imsm_super *mpb, __u8 index) |
cdddbdbc DW |
442 | { |
443 | int offset; | |
444 | int i; | |
445 | void *_mpb = mpb; | |
446 | ||
949c47a0 | 447 | if (index >= mpb->num_raid_devs) |
cdddbdbc DW |
448 | return NULL; |
449 | ||
450 | /* devices start after all disks */ | |
451 | offset = ((void *) &mpb->disk[mpb->num_disks]) - _mpb; | |
452 | ||
453 | for (i = 0; i <= index; i++) | |
454 | if (i == index) | |
455 | return _mpb + offset; | |
456 | else | |
3393c6af | 457 | offset += sizeof_imsm_dev(_mpb + offset, 0); |
cdddbdbc DW |
458 | |
459 | return NULL; | |
460 | } | |
461 | ||
949c47a0 DW |
462 | static struct imsm_dev *get_imsm_dev(struct intel_super *super, __u8 index) |
463 | { | |
ba2de7ba DW |
464 | struct intel_dev *dv; |
465 | ||
949c47a0 DW |
466 | if (index >= super->anchor->num_raid_devs) |
467 | return NULL; | |
ba2de7ba DW |
468 | for (dv = super->devlist; dv; dv = dv->next) |
469 | if (dv->index == index) | |
470 | return dv->dev; | |
471 | return NULL; | |
949c47a0 DW |
472 | } |
473 | ||
7eef0453 DW |
474 | static __u32 get_imsm_ord_tbl_ent(struct imsm_dev *dev, int slot) |
475 | { | |
476 | struct imsm_map *map; | |
477 | ||
478 | if (dev->vol.migr_state) | |
7eef0453 | 479 | map = get_imsm_map(dev, 1); |
fb9bf0d3 DW |
480 | else |
481 | map = get_imsm_map(dev, 0); | |
7eef0453 | 482 | |
ff077194 DW |
483 | /* top byte identifies disk under rebuild */ |
484 | return __le32_to_cpu(map->disk_ord_tbl[slot]); | |
485 | } | |
486 | ||
487 | #define ord_to_idx(ord) (((ord) << 8) >> 8) | |
488 | static __u32 get_imsm_disk_idx(struct imsm_dev *dev, int slot) | |
489 | { | |
490 | __u32 ord = get_imsm_ord_tbl_ent(dev, slot); | |
491 | ||
492 | return ord_to_idx(ord); | |
7eef0453 DW |
493 | } |
494 | ||
be73972f DW |
495 | static void set_imsm_ord_tbl_ent(struct imsm_map *map, int slot, __u32 ord) |
496 | { | |
497 | map->disk_ord_tbl[slot] = __cpu_to_le32(ord); | |
498 | } | |
499 | ||
f21e18ca | 500 | static int get_imsm_disk_slot(struct imsm_map *map, unsigned idx) |
620b1713 DW |
501 | { |
502 | int slot; | |
503 | __u32 ord; | |
504 | ||
505 | for (slot = 0; slot < map->num_members; slot++) { | |
506 | ord = __le32_to_cpu(map->disk_ord_tbl[slot]); | |
507 | if (ord_to_idx(ord) == idx) | |
508 | return slot; | |
509 | } | |
510 | ||
511 | return -1; | |
512 | } | |
513 | ||
cdddbdbc DW |
514 | static int get_imsm_raid_level(struct imsm_map *map) |
515 | { | |
516 | if (map->raid_level == 1) { | |
517 | if (map->num_members == 2) | |
518 | return 1; | |
519 | else | |
520 | return 10; | |
521 | } | |
522 | ||
523 | return map->raid_level; | |
524 | } | |
525 | ||
c2c087e6 DW |
526 | static int cmp_extent(const void *av, const void *bv) |
527 | { | |
528 | const struct extent *a = av; | |
529 | const struct extent *b = bv; | |
530 | if (a->start < b->start) | |
531 | return -1; | |
532 | if (a->start > b->start) | |
533 | return 1; | |
534 | return 0; | |
535 | } | |
536 | ||
0dcecb2e | 537 | static int count_memberships(struct dl *dl, struct intel_super *super) |
c2c087e6 | 538 | { |
c2c087e6 | 539 | int memberships = 0; |
620b1713 | 540 | int i; |
c2c087e6 | 541 | |
949c47a0 DW |
542 | for (i = 0; i < super->anchor->num_raid_devs; i++) { |
543 | struct imsm_dev *dev = get_imsm_dev(super, i); | |
a965f303 | 544 | struct imsm_map *map = get_imsm_map(dev, 0); |
c2c087e6 | 545 | |
620b1713 DW |
546 | if (get_imsm_disk_slot(map, dl->index) >= 0) |
547 | memberships++; | |
c2c087e6 | 548 | } |
0dcecb2e DW |
549 | |
550 | return memberships; | |
551 | } | |
552 | ||
553 | static struct extent *get_extents(struct intel_super *super, struct dl *dl) | |
554 | { | |
555 | /* find a list of used extents on the given physical device */ | |
556 | struct extent *rv, *e; | |
620b1713 | 557 | int i; |
0dcecb2e DW |
558 | int memberships = count_memberships(dl, super); |
559 | __u32 reservation = MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS; | |
560 | ||
c2c087e6 DW |
561 | rv = malloc(sizeof(struct extent) * (memberships + 1)); |
562 | if (!rv) | |
563 | return NULL; | |
564 | e = rv; | |
565 | ||
949c47a0 DW |
566 | for (i = 0; i < super->anchor->num_raid_devs; i++) { |
567 | struct imsm_dev *dev = get_imsm_dev(super, i); | |
a965f303 | 568 | struct imsm_map *map = get_imsm_map(dev, 0); |
c2c087e6 | 569 | |
620b1713 DW |
570 | if (get_imsm_disk_slot(map, dl->index) >= 0) { |
571 | e->start = __le32_to_cpu(map->pba_of_lba0); | |
572 | e->size = __le32_to_cpu(map->blocks_per_member); | |
573 | e++; | |
c2c087e6 DW |
574 | } |
575 | } | |
576 | qsort(rv, memberships, sizeof(*rv), cmp_extent); | |
577 | ||
14e8215b DW |
578 | /* determine the start of the metadata |
579 | * when no raid devices are defined use the default | |
580 | * ...otherwise allow the metadata to truncate the value | |
581 | * as is the case with older versions of imsm | |
582 | */ | |
583 | if (memberships) { | |
584 | struct extent *last = &rv[memberships - 1]; | |
585 | __u32 remainder; | |
586 | ||
587 | remainder = __le32_to_cpu(dl->disk.total_blocks) - | |
588 | (last->start + last->size); | |
dda5855f DW |
589 | /* round down to 1k block to satisfy precision of the kernel |
590 | * 'size' interface | |
591 | */ | |
592 | remainder &= ~1UL; | |
593 | /* make sure remainder is still sane */ | |
f21e18ca | 594 | if (remainder < (unsigned)ROUND_UP(super->len, 512) >> 9) |
dda5855f | 595 | remainder = ROUND_UP(super->len, 512) >> 9; |
14e8215b DW |
596 | if (reservation > remainder) |
597 | reservation = remainder; | |
598 | } | |
599 | e->start = __le32_to_cpu(dl->disk.total_blocks) - reservation; | |
c2c087e6 DW |
600 | e->size = 0; |
601 | return rv; | |
602 | } | |
603 | ||
14e8215b DW |
604 | /* try to determine how much space is reserved for metadata from |
605 | * the last get_extents() entry, otherwise fallback to the | |
606 | * default | |
607 | */ | |
608 | static __u32 imsm_reserved_sectors(struct intel_super *super, struct dl *dl) | |
609 | { | |
610 | struct extent *e; | |
611 | int i; | |
612 | __u32 rv; | |
613 | ||
614 | /* for spares just return a minimal reservation which will grow | |
615 | * once the spare is picked up by an array | |
616 | */ | |
617 | if (dl->index == -1) | |
618 | return MPB_SECTOR_CNT; | |
619 | ||
620 | e = get_extents(super, dl); | |
621 | if (!e) | |
622 | return MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS; | |
623 | ||
624 | /* scroll to last entry */ | |
625 | for (i = 0; e[i].size; i++) | |
626 | continue; | |
627 | ||
628 | rv = __le32_to_cpu(dl->disk.total_blocks) - e[i].start; | |
629 | ||
630 | free(e); | |
631 | ||
632 | return rv; | |
633 | } | |
634 | ||
25ed7e59 DW |
635 | static int is_spare(struct imsm_disk *disk) |
636 | { | |
637 | return (disk->status & SPARE_DISK) == SPARE_DISK; | |
638 | } | |
639 | ||
640 | static int is_configured(struct imsm_disk *disk) | |
641 | { | |
642 | return (disk->status & CONFIGURED_DISK) == CONFIGURED_DISK; | |
643 | } | |
644 | ||
645 | static int is_failed(struct imsm_disk *disk) | |
646 | { | |
647 | return (disk->status & FAILED_DISK) == FAILED_DISK; | |
648 | } | |
649 | ||
1799c9e8 | 650 | #ifndef MDASSEMBLE |
1e5c6983 DW |
651 | static __u64 blocks_per_migr_unit(struct imsm_dev *dev); |
652 | ||
44470971 | 653 | static void print_imsm_dev(struct imsm_dev *dev, char *uuid, int disk_idx) |
cdddbdbc DW |
654 | { |
655 | __u64 sz; | |
0d80bb2f | 656 | int slot, i; |
a965f303 | 657 | struct imsm_map *map = get_imsm_map(dev, 0); |
b10b37b8 | 658 | __u32 ord; |
cdddbdbc DW |
659 | |
660 | printf("\n"); | |
1e7bc0ed | 661 | printf("[%.16s]:\n", dev->volume); |
44470971 | 662 | printf(" UUID : %s\n", uuid); |
cdddbdbc DW |
663 | printf(" RAID Level : %d\n", get_imsm_raid_level(map)); |
664 | printf(" Members : %d\n", map->num_members); | |
0d80bb2f DW |
665 | printf(" Slots : ["); |
666 | for (i = 0; i < map->num_members; i++) { | |
667 | ord = get_imsm_ord_tbl_ent(dev, i); | |
668 | printf("%s", ord & IMSM_ORD_REBUILD ? "_" : "U"); | |
669 | } | |
670 | printf("]\n"); | |
620b1713 DW |
671 | slot = get_imsm_disk_slot(map, disk_idx); |
672 | if (slot >= 0) { | |
b10b37b8 DW |
673 | ord = get_imsm_ord_tbl_ent(dev, slot); |
674 | printf(" This Slot : %d%s\n", slot, | |
675 | ord & IMSM_ORD_REBUILD ? " (out-of-sync)" : ""); | |
676 | } else | |
cdddbdbc DW |
677 | printf(" This Slot : ?\n"); |
678 | sz = __le32_to_cpu(dev->size_high); | |
679 | sz <<= 32; | |
680 | sz += __le32_to_cpu(dev->size_low); | |
681 | printf(" Array Size : %llu%s\n", (unsigned long long)sz, | |
682 | human_size(sz * 512)); | |
683 | sz = __le32_to_cpu(map->blocks_per_member); | |
684 | printf(" Per Dev Size : %llu%s\n", (unsigned long long)sz, | |
685 | human_size(sz * 512)); | |
686 | printf(" Sector Offset : %u\n", | |
687 | __le32_to_cpu(map->pba_of_lba0)); | |
688 | printf(" Num Stripes : %u\n", | |
689 | __le32_to_cpu(map->num_data_stripes)); | |
690 | printf(" Chunk Size : %u KiB\n", | |
691 | __le16_to_cpu(map->blocks_per_strip) / 2); | |
692 | printf(" Reserved : %d\n", __le32_to_cpu(dev->reserved_blocks)); | |
8655a7b1 | 693 | printf(" Migrate State : "); |
1484e727 DW |
694 | if (dev->vol.migr_state) { |
695 | if (migr_type(dev) == MIGR_INIT) | |
8655a7b1 | 696 | printf("initialize\n"); |
1484e727 | 697 | else if (migr_type(dev) == MIGR_REBUILD) |
8655a7b1 | 698 | printf("rebuild\n"); |
1484e727 | 699 | else if (migr_type(dev) == MIGR_VERIFY) |
8655a7b1 | 700 | printf("check\n"); |
1484e727 | 701 | else if (migr_type(dev) == MIGR_GEN_MIGR) |
8655a7b1 | 702 | printf("general migration\n"); |
1484e727 | 703 | else if (migr_type(dev) == MIGR_STATE_CHANGE) |
8655a7b1 | 704 | printf("state change\n"); |
1484e727 | 705 | else if (migr_type(dev) == MIGR_REPAIR) |
8655a7b1 | 706 | printf("repair\n"); |
1484e727 | 707 | else |
8655a7b1 DW |
708 | printf("<unknown:%d>\n", migr_type(dev)); |
709 | } else | |
710 | printf("idle\n"); | |
3393c6af DW |
711 | printf(" Map State : %s", map_state_str[map->map_state]); |
712 | if (dev->vol.migr_state) { | |
713 | struct imsm_map *map = get_imsm_map(dev, 1); | |
1e5c6983 | 714 | |
b10b37b8 | 715 | printf(" <-- %s", map_state_str[map->map_state]); |
1e5c6983 DW |
716 | printf("\n Checkpoint : %u (%llu)", |
717 | __le32_to_cpu(dev->vol.curr_migr_unit), | |
94fcb80a | 718 | (unsigned long long)blocks_per_migr_unit(dev)); |
3393c6af DW |
719 | } |
720 | printf("\n"); | |
cdddbdbc | 721 | printf(" Dirty State : %s\n", dev->vol.dirty ? "dirty" : "clean"); |
cdddbdbc DW |
722 | } |
723 | ||
14e8215b | 724 | static void print_imsm_disk(struct imsm_super *mpb, int index, __u32 reserved) |
cdddbdbc | 725 | { |
949c47a0 | 726 | struct imsm_disk *disk = __get_imsm_disk(mpb, index); |
1f24f035 | 727 | char str[MAX_RAID_SERIAL_LEN + 1]; |
cdddbdbc DW |
728 | __u64 sz; |
729 | ||
d362da3d | 730 | if (index < 0 || !disk) |
e9d82038 DW |
731 | return; |
732 | ||
cdddbdbc | 733 | printf("\n"); |
1f24f035 | 734 | snprintf(str, MAX_RAID_SERIAL_LEN + 1, "%s", disk->serial); |
cdddbdbc | 735 | printf(" Disk%02d Serial : %s\n", index, str); |
25ed7e59 DW |
736 | printf(" State :%s%s%s\n", is_spare(disk) ? " spare" : "", |
737 | is_configured(disk) ? " active" : "", | |
738 | is_failed(disk) ? " failed" : ""); | |
cdddbdbc | 739 | printf(" Id : %08x\n", __le32_to_cpu(disk->scsi_id)); |
14e8215b | 740 | sz = __le32_to_cpu(disk->total_blocks) - reserved; |
cdddbdbc DW |
741 | printf(" Usable Size : %llu%s\n", (unsigned long long)sz, |
742 | human_size(sz * 512)); | |
743 | } | |
744 | ||
a5d85af7 | 745 | static void getinfo_super_imsm(struct supertype *st, struct mdinfo *info, char *map); |
44470971 | 746 | |
cdddbdbc DW |
747 | static void examine_super_imsm(struct supertype *st, char *homehost) |
748 | { | |
749 | struct intel_super *super = st->sb; | |
949c47a0 | 750 | struct imsm_super *mpb = super->anchor; |
cdddbdbc DW |
751 | char str[MAX_SIGNATURE_LENGTH]; |
752 | int i; | |
27fd6274 DW |
753 | struct mdinfo info; |
754 | char nbuf[64]; | |
cdddbdbc | 755 | __u32 sum; |
14e8215b | 756 | __u32 reserved = imsm_reserved_sectors(super, super->disks); |
cdddbdbc | 757 | |
27fd6274 | 758 | |
cdddbdbc DW |
759 | snprintf(str, MPB_SIG_LEN, "%s", mpb->sig); |
760 | printf(" Magic : %s\n", str); | |
761 | snprintf(str, strlen(MPB_VERSION_RAID0), "%s", get_imsm_version(mpb)); | |
762 | printf(" Version : %s\n", get_imsm_version(mpb)); | |
148acb7b | 763 | printf(" Orig Family : %08x\n", __le32_to_cpu(mpb->orig_family_num)); |
cdddbdbc DW |
764 | printf(" Family : %08x\n", __le32_to_cpu(mpb->family_num)); |
765 | printf(" Generation : %08x\n", __le32_to_cpu(mpb->generation_num)); | |
a5d85af7 | 766 | getinfo_super_imsm(st, &info, NULL); |
ae2bfd4e | 767 | fname_from_uuid(st, &info, nbuf, ':'); |
27fd6274 | 768 | printf(" UUID : %s\n", nbuf + 5); |
cdddbdbc DW |
769 | sum = __le32_to_cpu(mpb->check_sum); |
770 | printf(" Checksum : %08x %s\n", sum, | |
949c47a0 | 771 | __gen_imsm_checksum(mpb) == sum ? "correct" : "incorrect"); |
87eb16df | 772 | printf(" MPB Sectors : %d\n", mpb_sectors(mpb)); |
cdddbdbc DW |
773 | printf(" Disks : %d\n", mpb->num_disks); |
774 | printf(" RAID Devices : %d\n", mpb->num_raid_devs); | |
14e8215b | 775 | print_imsm_disk(mpb, super->disks->index, reserved); |
604b746f JD |
776 | if (super->bbm_log) { |
777 | struct bbm_log *log = super->bbm_log; | |
778 | ||
779 | printf("\n"); | |
780 | printf("Bad Block Management Log:\n"); | |
781 | printf(" Log Size : %d\n", __le32_to_cpu(mpb->bbm_log_size)); | |
782 | printf(" Signature : %x\n", __le32_to_cpu(log->signature)); | |
783 | printf(" Entry Count : %d\n", __le32_to_cpu(log->entry_count)); | |
784 | printf(" Spare Blocks : %d\n", __le32_to_cpu(log->reserved_spare_block_count)); | |
13a3b65d N |
785 | printf(" First Spare : %llx\n", |
786 | (unsigned long long) __le64_to_cpu(log->first_spare_lba)); | |
604b746f | 787 | } |
44470971 DW |
788 | for (i = 0; i < mpb->num_raid_devs; i++) { |
789 | struct mdinfo info; | |
790 | struct imsm_dev *dev = __get_imsm_dev(mpb, i); | |
791 | ||
792 | super->current_vol = i; | |
a5d85af7 | 793 | getinfo_super_imsm(st, &info, NULL); |
ae2bfd4e | 794 | fname_from_uuid(st, &info, nbuf, ':'); |
44470971 DW |
795 | print_imsm_dev(dev, nbuf + 5, super->disks->index); |
796 | } | |
cdddbdbc DW |
797 | for (i = 0; i < mpb->num_disks; i++) { |
798 | if (i == super->disks->index) | |
799 | continue; | |
14e8215b | 800 | print_imsm_disk(mpb, i, reserved); |
cdddbdbc DW |
801 | } |
802 | } | |
803 | ||
061f2c6a | 804 | static void brief_examine_super_imsm(struct supertype *st, int verbose) |
cdddbdbc | 805 | { |
27fd6274 | 806 | /* We just write a generic IMSM ARRAY entry */ |
ff54de6e N |
807 | struct mdinfo info; |
808 | char nbuf[64]; | |
1e7bc0ed | 809 | struct intel_super *super = st->sb; |
1e7bc0ed | 810 | |
0d5a423f DW |
811 | if (!super->anchor->num_raid_devs) { |
812 | printf("ARRAY metadata=imsm\n"); | |
1e7bc0ed | 813 | return; |
0d5a423f | 814 | } |
ff54de6e | 815 | |
a5d85af7 | 816 | getinfo_super_imsm(st, &info, NULL); |
4737ae25 N |
817 | fname_from_uuid(st, &info, nbuf, ':'); |
818 | printf("ARRAY metadata=imsm UUID=%s\n", nbuf + 5); | |
819 | } | |
820 | ||
821 | static void brief_examine_subarrays_imsm(struct supertype *st, int verbose) | |
822 | { | |
823 | /* We just write a generic IMSM ARRAY entry */ | |
824 | struct mdinfo info; | |
825 | char nbuf[64]; | |
826 | char nbuf1[64]; | |
827 | struct intel_super *super = st->sb; | |
828 | int i; | |
829 | ||
830 | if (!super->anchor->num_raid_devs) | |
831 | return; | |
832 | ||
a5d85af7 | 833 | getinfo_super_imsm(st, &info, NULL); |
ae2bfd4e | 834 | fname_from_uuid(st, &info, nbuf, ':'); |
1e7bc0ed DW |
835 | for (i = 0; i < super->anchor->num_raid_devs; i++) { |
836 | struct imsm_dev *dev = get_imsm_dev(super, i); | |
837 | ||
838 | super->current_vol = i; | |
a5d85af7 | 839 | getinfo_super_imsm(st, &info, NULL); |
ae2bfd4e | 840 | fname_from_uuid(st, &info, nbuf1, ':'); |
1124b3cf | 841 | printf("ARRAY /dev/md/%.16s container=%s member=%d UUID=%s\n", |
cf8de691 | 842 | dev->volume, nbuf + 5, i, nbuf1 + 5); |
1e7bc0ed | 843 | } |
cdddbdbc DW |
844 | } |
845 | ||
9d84c8ea DW |
846 | static void export_examine_super_imsm(struct supertype *st) |
847 | { | |
848 | struct intel_super *super = st->sb; | |
849 | struct imsm_super *mpb = super->anchor; | |
850 | struct mdinfo info; | |
851 | char nbuf[64]; | |
852 | ||
a5d85af7 | 853 | getinfo_super_imsm(st, &info, NULL); |
9d84c8ea DW |
854 | fname_from_uuid(st, &info, nbuf, ':'); |
855 | printf("MD_METADATA=imsm\n"); | |
856 | printf("MD_LEVEL=container\n"); | |
857 | printf("MD_UUID=%s\n", nbuf+5); | |
858 | printf("MD_DEVICES=%u\n", mpb->num_disks); | |
859 | } | |
860 | ||
cdddbdbc DW |
861 | static void detail_super_imsm(struct supertype *st, char *homehost) |
862 | { | |
3ebe00a1 DW |
863 | struct mdinfo info; |
864 | char nbuf[64]; | |
865 | ||
a5d85af7 | 866 | getinfo_super_imsm(st, &info, NULL); |
ae2bfd4e | 867 | fname_from_uuid(st, &info, nbuf, ':'); |
3ebe00a1 | 868 | printf("\n UUID : %s\n", nbuf + 5); |
cdddbdbc DW |
869 | } |
870 | ||
871 | static void brief_detail_super_imsm(struct supertype *st) | |
872 | { | |
ff54de6e N |
873 | struct mdinfo info; |
874 | char nbuf[64]; | |
a5d85af7 | 875 | getinfo_super_imsm(st, &info, NULL); |
ae2bfd4e | 876 | fname_from_uuid(st, &info, nbuf, ':'); |
ff54de6e | 877 | printf(" UUID=%s", nbuf + 5); |
cdddbdbc | 878 | } |
d665cc31 DW |
879 | |
880 | static int imsm_read_serial(int fd, char *devname, __u8 *serial); | |
881 | static void fd2devname(int fd, char *name); | |
882 | ||
883 | static int imsm_enumerate_ports(const char *hba_path, int port_count, int host_base, int verbose) | |
884 | { | |
885 | /* dump an unsorted list of devices attached to ahci, as well as | |
886 | * non-connected ports | |
887 | */ | |
888 | int hba_len = strlen(hba_path) + 1; | |
889 | struct dirent *ent; | |
890 | DIR *dir; | |
891 | char *path = NULL; | |
892 | int err = 0; | |
893 | unsigned long port_mask = (1 << port_count) - 1; | |
894 | ||
f21e18ca | 895 | if (port_count > (int)sizeof(port_mask) * 8) { |
d665cc31 DW |
896 | if (verbose) |
897 | fprintf(stderr, Name ": port_count %d out of range\n", port_count); | |
898 | return 2; | |
899 | } | |
900 | ||
901 | /* scroll through /sys/dev/block looking for devices attached to | |
902 | * this hba | |
903 | */ | |
904 | dir = opendir("/sys/dev/block"); | |
905 | for (ent = dir ? readdir(dir) : NULL; ent; ent = readdir(dir)) { | |
906 | int fd; | |
907 | char model[64]; | |
908 | char vendor[64]; | |
909 | char buf[1024]; | |
910 | int major, minor; | |
911 | char *device; | |
912 | char *c; | |
913 | int port; | |
914 | int type; | |
915 | ||
916 | if (sscanf(ent->d_name, "%d:%d", &major, &minor) != 2) | |
917 | continue; | |
918 | path = devt_to_devpath(makedev(major, minor)); | |
919 | if (!path) | |
920 | continue; | |
921 | if (!path_attached_to_hba(path, hba_path)) { | |
922 | free(path); | |
923 | path = NULL; | |
924 | continue; | |
925 | } | |
926 | ||
927 | /* retrieve the scsi device type */ | |
928 | if (asprintf(&device, "/sys/dev/block/%d:%d/device/xxxxxxx", major, minor) < 0) { | |
929 | if (verbose) | |
930 | fprintf(stderr, Name ": failed to allocate 'device'\n"); | |
931 | err = 2; | |
932 | break; | |
933 | } | |
934 | sprintf(device, "/sys/dev/block/%d:%d/device/type", major, minor); | |
935 | if (load_sys(device, buf) != 0) { | |
936 | if (verbose) | |
937 | fprintf(stderr, Name ": failed to read device type for %s\n", | |
938 | path); | |
939 | err = 2; | |
940 | free(device); | |
941 | break; | |
942 | } | |
943 | type = strtoul(buf, NULL, 10); | |
944 | ||
945 | /* if it's not a disk print the vendor and model */ | |
946 | if (!(type == 0 || type == 7 || type == 14)) { | |
947 | vendor[0] = '\0'; | |
948 | model[0] = '\0'; | |
949 | sprintf(device, "/sys/dev/block/%d:%d/device/vendor", major, minor); | |
950 | if (load_sys(device, buf) == 0) { | |
951 | strncpy(vendor, buf, sizeof(vendor)); | |
952 | vendor[sizeof(vendor) - 1] = '\0'; | |
953 | c = (char *) &vendor[sizeof(vendor) - 1]; | |
954 | while (isspace(*c) || *c == '\0') | |
955 | *c-- = '\0'; | |
956 | ||
957 | } | |
958 | sprintf(device, "/sys/dev/block/%d:%d/device/model", major, minor); | |
959 | if (load_sys(device, buf) == 0) { | |
960 | strncpy(model, buf, sizeof(model)); | |
961 | model[sizeof(model) - 1] = '\0'; | |
962 | c = (char *) &model[sizeof(model) - 1]; | |
963 | while (isspace(*c) || *c == '\0') | |
964 | *c-- = '\0'; | |
965 | } | |
966 | ||
967 | if (vendor[0] && model[0]) | |
968 | sprintf(buf, "%.64s %.64s", vendor, model); | |
969 | else | |
970 | switch (type) { /* numbers from hald/linux/device.c */ | |
971 | case 1: sprintf(buf, "tape"); break; | |
972 | case 2: sprintf(buf, "printer"); break; | |
973 | case 3: sprintf(buf, "processor"); break; | |
974 | case 4: | |
975 | case 5: sprintf(buf, "cdrom"); break; | |
976 | case 6: sprintf(buf, "scanner"); break; | |
977 | case 8: sprintf(buf, "media_changer"); break; | |
978 | case 9: sprintf(buf, "comm"); break; | |
979 | case 12: sprintf(buf, "raid"); break; | |
980 | default: sprintf(buf, "unknown"); | |
981 | } | |
982 | } else | |
983 | buf[0] = '\0'; | |
984 | free(device); | |
985 | ||
986 | /* chop device path to 'host%d' and calculate the port number */ | |
987 | c = strchr(&path[hba_len], '/'); | |
4e5e717d AW |
988 | if (!c) { |
989 | if (verbose) | |
990 | fprintf(stderr, Name ": %s - invalid path name\n", path + hba_len); | |
991 | err = 2; | |
992 | break; | |
993 | } | |
d665cc31 DW |
994 | *c = '\0'; |
995 | if (sscanf(&path[hba_len], "host%d", &port) == 1) | |
996 | port -= host_base; | |
997 | else { | |
998 | if (verbose) { | |
999 | *c = '/'; /* repair the full string */ | |
1000 | fprintf(stderr, Name ": failed to determine port number for %s\n", | |
1001 | path); | |
1002 | } | |
1003 | err = 2; | |
1004 | break; | |
1005 | } | |
1006 | ||
1007 | /* mark this port as used */ | |
1008 | port_mask &= ~(1 << port); | |
1009 | ||
1010 | /* print out the device information */ | |
1011 | if (buf[0]) { | |
1012 | printf(" Port%d : - non-disk device (%s) -\n", port, buf); | |
1013 | continue; | |
1014 | } | |
1015 | ||
1016 | fd = dev_open(ent->d_name, O_RDONLY); | |
1017 | if (fd < 0) | |
1018 | printf(" Port%d : - disk info unavailable -\n", port); | |
1019 | else { | |
1020 | fd2devname(fd, buf); | |
1021 | printf(" Port%d : %s", port, buf); | |
1022 | if (imsm_read_serial(fd, NULL, (__u8 *) buf) == 0) | |
1023 | printf(" (%s)\n", buf); | |
1024 | else | |
1025 | printf("()\n"); | |
1026 | } | |
1027 | close(fd); | |
1028 | free(path); | |
1029 | path = NULL; | |
1030 | } | |
1031 | if (path) | |
1032 | free(path); | |
1033 | if (dir) | |
1034 | closedir(dir); | |
1035 | if (err == 0) { | |
1036 | int i; | |
1037 | ||
1038 | for (i = 0; i < port_count; i++) | |
1039 | if (port_mask & (1 << i)) | |
1040 | printf(" Port%d : - no device attached -\n", i); | |
1041 | } | |
1042 | ||
1043 | return err; | |
1044 | } | |
1045 | ||
5615172f | 1046 | static int detail_platform_imsm(int verbose, int enumerate_only) |
d665cc31 DW |
1047 | { |
1048 | /* There are two components to imsm platform support, the ahci SATA | |
1049 | * controller and the option-rom. To find the SATA controller we | |
1050 | * simply look in /sys/bus/pci/drivers/ahci to see if an ahci | |
1051 | * controller with the Intel vendor id is present. This approach | |
1052 | * allows mdadm to leverage the kernel's ahci detection logic, with the | |
1053 | * caveat that if ahci.ko is not loaded mdadm will not be able to | |
1054 | * detect platform raid capabilities. The option-rom resides in a | |
1055 | * platform "Adapter ROM". We scan for its signature to retrieve the | |
1056 | * platform capabilities. If raid support is disabled in the BIOS the | |
1057 | * option-rom capability structure will not be available. | |
1058 | */ | |
1059 | const struct imsm_orom *orom; | |
1060 | struct sys_dev *list, *hba; | |
1061 | DIR *dir; | |
1062 | struct dirent *ent; | |
1063 | const char *hba_path; | |
1064 | int host_base = 0; | |
1065 | int port_count = 0; | |
1066 | ||
5615172f DW |
1067 | if (enumerate_only) { |
1068 | if (check_env("IMSM_NO_PLATFORM") || find_imsm_orom()) | |
1069 | return 0; | |
1070 | return 2; | |
1071 | } | |
1072 | ||
d665cc31 DW |
1073 | list = find_driver_devices("pci", "ahci"); |
1074 | for (hba = list; hba; hba = hba->next) | |
1075 | if (devpath_to_vendor(hba->path) == 0x8086) | |
1076 | break; | |
1077 | ||
1078 | if (!hba) { | |
1079 | if (verbose) | |
1080 | fprintf(stderr, Name ": unable to find active ahci controller\n"); | |
1081 | free_sys_dev(&list); | |
1082 | return 2; | |
1083 | } else if (verbose) | |
1084 | fprintf(stderr, Name ": found Intel SATA AHCI Controller\n"); | |
1085 | hba_path = hba->path; | |
1086 | hba->path = NULL; | |
1087 | free_sys_dev(&list); | |
1088 | ||
1089 | orom = find_imsm_orom(); | |
1090 | if (!orom) { | |
1091 | if (verbose) | |
1092 | fprintf(stderr, Name ": imsm option-rom not found\n"); | |
1093 | return 2; | |
1094 | } | |
1095 | ||
1096 | printf(" Platform : Intel(R) Matrix Storage Manager\n"); | |
1097 | printf(" Version : %d.%d.%d.%d\n", orom->major_ver, orom->minor_ver, | |
1098 | orom->hotfix_ver, orom->build); | |
1099 | printf(" RAID Levels :%s%s%s%s%s\n", | |
1100 | imsm_orom_has_raid0(orom) ? " raid0" : "", | |
1101 | imsm_orom_has_raid1(orom) ? " raid1" : "", | |
1102 | imsm_orom_has_raid1e(orom) ? " raid1e" : "", | |
1103 | imsm_orom_has_raid10(orom) ? " raid10" : "", | |
1104 | imsm_orom_has_raid5(orom) ? " raid5" : ""); | |
8be094f0 DW |
1105 | printf(" Chunk Sizes :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", |
1106 | imsm_orom_has_chunk(orom, 2) ? " 2k" : "", | |
1107 | imsm_orom_has_chunk(orom, 4) ? " 4k" : "", | |
1108 | imsm_orom_has_chunk(orom, 8) ? " 8k" : "", | |
1109 | imsm_orom_has_chunk(orom, 16) ? " 16k" : "", | |
1110 | imsm_orom_has_chunk(orom, 32) ? " 32k" : "", | |
1111 | imsm_orom_has_chunk(orom, 64) ? " 64k" : "", | |
1112 | imsm_orom_has_chunk(orom, 128) ? " 128k" : "", | |
1113 | imsm_orom_has_chunk(orom, 256) ? " 256k" : "", | |
1114 | imsm_orom_has_chunk(orom, 512) ? " 512k" : "", | |
1115 | imsm_orom_has_chunk(orom, 1024*1) ? " 1M" : "", | |
1116 | imsm_orom_has_chunk(orom, 1024*2) ? " 2M" : "", | |
1117 | imsm_orom_has_chunk(orom, 1024*4) ? " 4M" : "", | |
1118 | imsm_orom_has_chunk(orom, 1024*8) ? " 8M" : "", | |
1119 | imsm_orom_has_chunk(orom, 1024*16) ? " 16M" : "", | |
1120 | imsm_orom_has_chunk(orom, 1024*32) ? " 32M" : "", | |
1121 | imsm_orom_has_chunk(orom, 1024*64) ? " 64M" : ""); | |
d665cc31 DW |
1122 | printf(" Max Disks : %d\n", orom->tds); |
1123 | printf(" Max Volumes : %d\n", orom->vpa); | |
1124 | printf(" I/O Controller : %s\n", hba_path); | |
1125 | ||
1126 | /* find the smallest scsi host number to determine a port number base */ | |
1127 | dir = opendir(hba_path); | |
1128 | for (ent = dir ? readdir(dir) : NULL; ent; ent = readdir(dir)) { | |
1129 | int host; | |
1130 | ||
1131 | if (sscanf(ent->d_name, "host%d", &host) != 1) | |
1132 | continue; | |
1133 | if (port_count == 0) | |
1134 | host_base = host; | |
1135 | else if (host < host_base) | |
1136 | host_base = host; | |
1137 | ||
1138 | if (host + 1 > port_count + host_base) | |
1139 | port_count = host + 1 - host_base; | |
1140 | ||
1141 | } | |
1142 | if (dir) | |
1143 | closedir(dir); | |
1144 | ||
1145 | if (!port_count || imsm_enumerate_ports(hba_path, port_count, | |
1146 | host_base, verbose) != 0) { | |
1147 | if (verbose) | |
1148 | fprintf(stderr, Name ": failed to enumerate ports\n"); | |
1149 | return 2; | |
1150 | } | |
1151 | ||
1152 | return 0; | |
1153 | } | |
cdddbdbc DW |
1154 | #endif |
1155 | ||
1156 | static int match_home_imsm(struct supertype *st, char *homehost) | |
1157 | { | |
5115ca67 DW |
1158 | /* the imsm metadata format does not specify any host |
1159 | * identification information. We return -1 since we can never | |
1160 | * confirm nor deny whether a given array is "meant" for this | |
148acb7b | 1161 | * host. We rely on compare_super and the 'family_num' fields to |
5115ca67 DW |
1162 | * exclude member disks that do not belong, and we rely on |
1163 | * mdadm.conf to specify the arrays that should be assembled. | |
1164 | * Auto-assembly may still pick up "foreign" arrays. | |
1165 | */ | |
cdddbdbc | 1166 | |
9362c1c8 | 1167 | return -1; |
cdddbdbc DW |
1168 | } |
1169 | ||
1170 | static void uuid_from_super_imsm(struct supertype *st, int uuid[4]) | |
1171 | { | |
51006d85 N |
1172 | /* The uuid returned here is used for: |
1173 | * uuid to put into bitmap file (Create, Grow) | |
1174 | * uuid for backup header when saving critical section (Grow) | |
1175 | * comparing uuids when re-adding a device into an array | |
1176 | * In these cases the uuid required is that of the data-array, | |
1177 | * not the device-set. | |
1178 | * uuid to recognise same set when adding a missing device back | |
1179 | * to an array. This is a uuid for the device-set. | |
1180 | * | |
1181 | * For each of these we can make do with a truncated | |
1182 | * or hashed uuid rather than the original, as long as | |
1183 | * everyone agrees. | |
1184 | * In each case the uuid required is that of the data-array, | |
1185 | * not the device-set. | |
43dad3d6 | 1186 | */ |
51006d85 N |
1187 | /* imsm does not track uuid's so we synthesis one using sha1 on |
1188 | * - The signature (Which is constant for all imsm array, but no matter) | |
148acb7b | 1189 | * - the orig_family_num of the container |
51006d85 N |
1190 | * - the index number of the volume |
1191 | * - the 'serial' number of the volume. | |
1192 | * Hopefully these are all constant. | |
1193 | */ | |
1194 | struct intel_super *super = st->sb; | |
43dad3d6 | 1195 | |
51006d85 N |
1196 | char buf[20]; |
1197 | struct sha1_ctx ctx; | |
1198 | struct imsm_dev *dev = NULL; | |
148acb7b | 1199 | __u32 family_num; |
51006d85 | 1200 | |
148acb7b DW |
1201 | /* some mdadm versions failed to set ->orig_family_num, in which |
1202 | * case fall back to ->family_num. orig_family_num will be | |
1203 | * fixed up with the first metadata update. | |
1204 | */ | |
1205 | family_num = super->anchor->orig_family_num; | |
1206 | if (family_num == 0) | |
1207 | family_num = super->anchor->family_num; | |
51006d85 | 1208 | sha1_init_ctx(&ctx); |
92bd8f8d | 1209 | sha1_process_bytes(super->anchor->sig, MPB_SIG_LEN, &ctx); |
148acb7b | 1210 | sha1_process_bytes(&family_num, sizeof(__u32), &ctx); |
51006d85 N |
1211 | if (super->current_vol >= 0) |
1212 | dev = get_imsm_dev(super, super->current_vol); | |
1213 | if (dev) { | |
1214 | __u32 vol = super->current_vol; | |
1215 | sha1_process_bytes(&vol, sizeof(vol), &ctx); | |
1216 | sha1_process_bytes(dev->volume, MAX_RAID_SERIAL_LEN, &ctx); | |
1217 | } | |
1218 | sha1_finish_ctx(&ctx, buf); | |
1219 | memcpy(uuid, buf, 4*4); | |
cdddbdbc DW |
1220 | } |
1221 | ||
0d481d37 | 1222 | #if 0 |
4f5bc454 DW |
1223 | static void |
1224 | get_imsm_numerical_version(struct imsm_super *mpb, int *m, int *p) | |
cdddbdbc | 1225 | { |
cdddbdbc DW |
1226 | __u8 *v = get_imsm_version(mpb); |
1227 | __u8 *end = mpb->sig + MAX_SIGNATURE_LENGTH; | |
1228 | char major[] = { 0, 0, 0 }; | |
1229 | char minor[] = { 0 ,0, 0 }; | |
1230 | char patch[] = { 0, 0, 0 }; | |
1231 | char *ver_parse[] = { major, minor, patch }; | |
1232 | int i, j; | |
1233 | ||
1234 | i = j = 0; | |
1235 | while (*v != '\0' && v < end) { | |
1236 | if (*v != '.' && j < 2) | |
1237 | ver_parse[i][j++] = *v; | |
1238 | else { | |
1239 | i++; | |
1240 | j = 0; | |
1241 | } | |
1242 | v++; | |
1243 | } | |
1244 | ||
4f5bc454 DW |
1245 | *m = strtol(minor, NULL, 0); |
1246 | *p = strtol(patch, NULL, 0); | |
1247 | } | |
0d481d37 | 1248 | #endif |
4f5bc454 | 1249 | |
1e5c6983 DW |
1250 | static __u32 migr_strip_blocks_resync(struct imsm_dev *dev) |
1251 | { | |
1252 | /* migr_strip_size when repairing or initializing parity */ | |
1253 | struct imsm_map *map = get_imsm_map(dev, 0); | |
1254 | __u32 chunk = __le32_to_cpu(map->blocks_per_strip); | |
1255 | ||
1256 | switch (get_imsm_raid_level(map)) { | |
1257 | case 5: | |
1258 | case 10: | |
1259 | return chunk; | |
1260 | default: | |
1261 | return 128*1024 >> 9; | |
1262 | } | |
1263 | } | |
1264 | ||
1265 | static __u32 migr_strip_blocks_rebuild(struct imsm_dev *dev) | |
1266 | { | |
1267 | /* migr_strip_size when rebuilding a degraded disk, no idea why | |
1268 | * this is different than migr_strip_size_resync(), but it's good | |
1269 | * to be compatible | |
1270 | */ | |
1271 | struct imsm_map *map = get_imsm_map(dev, 1); | |
1272 | __u32 chunk = __le32_to_cpu(map->blocks_per_strip); | |
1273 | ||
1274 | switch (get_imsm_raid_level(map)) { | |
1275 | case 1: | |
1276 | case 10: | |
1277 | if (map->num_members % map->num_domains == 0) | |
1278 | return 128*1024 >> 9; | |
1279 | else | |
1280 | return chunk; | |
1281 | case 5: | |
1282 | return max((__u32) 64*1024 >> 9, chunk); | |
1283 | default: | |
1284 | return 128*1024 >> 9; | |
1285 | } | |
1286 | } | |
1287 | ||
1288 | static __u32 num_stripes_per_unit_resync(struct imsm_dev *dev) | |
1289 | { | |
1290 | struct imsm_map *lo = get_imsm_map(dev, 0); | |
1291 | struct imsm_map *hi = get_imsm_map(dev, 1); | |
1292 | __u32 lo_chunk = __le32_to_cpu(lo->blocks_per_strip); | |
1293 | __u32 hi_chunk = __le32_to_cpu(hi->blocks_per_strip); | |
1294 | ||
1295 | return max((__u32) 1, hi_chunk / lo_chunk); | |
1296 | } | |
1297 | ||
1298 | static __u32 num_stripes_per_unit_rebuild(struct imsm_dev *dev) | |
1299 | { | |
1300 | struct imsm_map *lo = get_imsm_map(dev, 0); | |
1301 | int level = get_imsm_raid_level(lo); | |
1302 | ||
1303 | if (level == 1 || level == 10) { | |
1304 | struct imsm_map *hi = get_imsm_map(dev, 1); | |
1305 | ||
1306 | return hi->num_domains; | |
1307 | } else | |
1308 | return num_stripes_per_unit_resync(dev); | |
1309 | } | |
1310 | ||
1311 | static __u8 imsm_num_data_members(struct imsm_dev *dev) | |
1312 | { | |
1313 | /* named 'imsm_' because raid0, raid1 and raid10 | |
1314 | * counter-intuitively have the same number of data disks | |
1315 | */ | |
1316 | struct imsm_map *map = get_imsm_map(dev, 0); | |
1317 | ||
1318 | switch (get_imsm_raid_level(map)) { | |
1319 | case 0: | |
1320 | case 1: | |
1321 | case 10: | |
1322 | return map->num_members; | |
1323 | case 5: | |
1324 | return map->num_members - 1; | |
1325 | default: | |
1326 | dprintf("%s: unsupported raid level\n", __func__); | |
1327 | return 0; | |
1328 | } | |
1329 | } | |
1330 | ||
1331 | static __u32 parity_segment_depth(struct imsm_dev *dev) | |
1332 | { | |
1333 | struct imsm_map *map = get_imsm_map(dev, 0); | |
1334 | __u32 chunk = __le32_to_cpu(map->blocks_per_strip); | |
1335 | ||
1336 | switch(get_imsm_raid_level(map)) { | |
1337 | case 1: | |
1338 | case 10: | |
1339 | return chunk * map->num_domains; | |
1340 | case 5: | |
1341 | return chunk * map->num_members; | |
1342 | default: | |
1343 | return chunk; | |
1344 | } | |
1345 | } | |
1346 | ||
1347 | static __u32 map_migr_block(struct imsm_dev *dev, __u32 block) | |
1348 | { | |
1349 | struct imsm_map *map = get_imsm_map(dev, 1); | |
1350 | __u32 chunk = __le32_to_cpu(map->blocks_per_strip); | |
1351 | __u32 strip = block / chunk; | |
1352 | ||
1353 | switch (get_imsm_raid_level(map)) { | |
1354 | case 1: | |
1355 | case 10: { | |
1356 | __u32 vol_strip = (strip * map->num_domains) + 1; | |
1357 | __u32 vol_stripe = vol_strip / map->num_members; | |
1358 | ||
1359 | return vol_stripe * chunk + block % chunk; | |
1360 | } case 5: { | |
1361 | __u32 stripe = strip / (map->num_members - 1); | |
1362 | ||
1363 | return stripe * chunk + block % chunk; | |
1364 | } | |
1365 | default: | |
1366 | return 0; | |
1367 | } | |
1368 | } | |
1369 | ||
1370 | static __u64 blocks_per_migr_unit(struct imsm_dev *dev) | |
1371 | { | |
1372 | /* calculate the conversion factor between per member 'blocks' | |
1373 | * (md/{resync,rebuild}_start) and imsm migration units, return | |
1374 | * 0 for the 'not migrating' and 'unsupported migration' cases | |
1375 | */ | |
1376 | if (!dev->vol.migr_state) | |
1377 | return 0; | |
1378 | ||
1379 | switch (migr_type(dev)) { | |
1380 | case MIGR_VERIFY: | |
1381 | case MIGR_REPAIR: | |
1382 | case MIGR_INIT: { | |
1383 | struct imsm_map *map = get_imsm_map(dev, 0); | |
1384 | __u32 stripes_per_unit; | |
1385 | __u32 blocks_per_unit; | |
1386 | __u32 parity_depth; | |
1387 | __u32 migr_chunk; | |
1388 | __u32 block_map; | |
1389 | __u32 block_rel; | |
1390 | __u32 segment; | |
1391 | __u32 stripe; | |
1392 | __u8 disks; | |
1393 | ||
1394 | /* yes, this is really the translation of migr_units to | |
1395 | * per-member blocks in the 'resync' case | |
1396 | */ | |
1397 | stripes_per_unit = num_stripes_per_unit_resync(dev); | |
1398 | migr_chunk = migr_strip_blocks_resync(dev); | |
1399 | disks = imsm_num_data_members(dev); | |
1400 | blocks_per_unit = stripes_per_unit * migr_chunk * disks; | |
1401 | stripe = __le32_to_cpu(map->blocks_per_strip) * disks; | |
1402 | segment = blocks_per_unit / stripe; | |
1403 | block_rel = blocks_per_unit - segment * stripe; | |
1404 | parity_depth = parity_segment_depth(dev); | |
1405 | block_map = map_migr_block(dev, block_rel); | |
1406 | return block_map + parity_depth * segment; | |
1407 | } | |
1408 | case MIGR_REBUILD: { | |
1409 | __u32 stripes_per_unit; | |
1410 | __u32 migr_chunk; | |
1411 | ||
1412 | stripes_per_unit = num_stripes_per_unit_rebuild(dev); | |
1413 | migr_chunk = migr_strip_blocks_rebuild(dev); | |
1414 | return migr_chunk * stripes_per_unit; | |
1415 | } | |
1416 | case MIGR_GEN_MIGR: | |
1417 | case MIGR_STATE_CHANGE: | |
1418 | default: | |
1419 | return 0; | |
1420 | } | |
1421 | } | |
1422 | ||
c2c087e6 DW |
1423 | static int imsm_level_to_layout(int level) |
1424 | { | |
1425 | switch (level) { | |
1426 | case 0: | |
1427 | case 1: | |
1428 | return 0; | |
1429 | case 5: | |
1430 | case 6: | |
a380c027 | 1431 | return ALGORITHM_LEFT_ASYMMETRIC; |
c2c087e6 | 1432 | case 10: |
c92a2527 | 1433 | return 0x102; |
c2c087e6 | 1434 | } |
a18a888e | 1435 | return UnSet; |
c2c087e6 DW |
1436 | } |
1437 | ||
a5d85af7 | 1438 | static void getinfo_super_imsm_volume(struct supertype *st, struct mdinfo *info, char *dmap) |
bf5a934a DW |
1439 | { |
1440 | struct intel_super *super = st->sb; | |
949c47a0 | 1441 | struct imsm_dev *dev = get_imsm_dev(super, super->current_vol); |
a965f303 | 1442 | struct imsm_map *map = get_imsm_map(dev, 0); |
efb30e7f | 1443 | struct dl *dl; |
e207da2f | 1444 | char *devname; |
a5d85af7 | 1445 | int map_disks = info->array.raid_disks; |
bf5a934a | 1446 | |
efb30e7f DW |
1447 | for (dl = super->disks; dl; dl = dl->next) |
1448 | if (dl->raiddisk == info->disk.raid_disk) | |
1449 | break; | |
bf5a934a DW |
1450 | info->container_member = super->current_vol; |
1451 | info->array.raid_disks = map->num_members; | |
1452 | info->array.level = get_imsm_raid_level(map); | |
1453 | info->array.layout = imsm_level_to_layout(info->array.level); | |
1454 | info->array.md_minor = -1; | |
1455 | info->array.ctime = 0; | |
1456 | info->array.utime = 0; | |
301406c9 DW |
1457 | info->array.chunk_size = __le16_to_cpu(map->blocks_per_strip) << 9; |
1458 | info->array.state = !dev->vol.dirty; | |
da9b4a62 DW |
1459 | info->custom_array_size = __le32_to_cpu(dev->size_high); |
1460 | info->custom_array_size <<= 32; | |
1461 | info->custom_array_size |= __le32_to_cpu(dev->size_low); | |
301406c9 DW |
1462 | |
1463 | info->disk.major = 0; | |
1464 | info->disk.minor = 0; | |
efb30e7f DW |
1465 | if (dl) { |
1466 | info->disk.major = dl->major; | |
1467 | info->disk.minor = dl->minor; | |
1468 | } | |
bf5a934a DW |
1469 | |
1470 | info->data_offset = __le32_to_cpu(map->pba_of_lba0); | |
1471 | info->component_size = __le32_to_cpu(map->blocks_per_member); | |
301406c9 | 1472 | memset(info->uuid, 0, sizeof(info->uuid)); |
921d9e16 | 1473 | info->recovery_start = MaxSector; |
624c5ad4 | 1474 | info->reshape_active = 0; |
bf5a934a | 1475 | |
1e5c6983 | 1476 | if (map->map_state == IMSM_T_STATE_UNINITIALIZED || dev->vol.dirty) { |
301406c9 | 1477 | info->resync_start = 0; |
1e5c6983 DW |
1478 | } else if (dev->vol.migr_state) { |
1479 | switch (migr_type(dev)) { | |
1480 | case MIGR_REPAIR: | |
1481 | case MIGR_INIT: { | |
1482 | __u64 blocks_per_unit = blocks_per_migr_unit(dev); | |
1483 | __u64 units = __le32_to_cpu(dev->vol.curr_migr_unit); | |
1484 | ||
1485 | info->resync_start = blocks_per_unit * units; | |
1486 | break; | |
1487 | } | |
1488 | case MIGR_VERIFY: | |
1489 | /* we could emulate the checkpointing of | |
1490 | * 'sync_action=check' migrations, but for now | |
1491 | * we just immediately complete them | |
1492 | */ | |
1493 | case MIGR_REBUILD: | |
1494 | /* this is handled by container_content_imsm() */ | |
1495 | case MIGR_GEN_MIGR: | |
1496 | case MIGR_STATE_CHANGE: | |
1497 | /* FIXME handle other migrations */ | |
1498 | default: | |
1499 | /* we are not dirty, so... */ | |
1500 | info->resync_start = MaxSector; | |
1501 | } | |
1502 | } else | |
b7528a20 | 1503 | info->resync_start = MaxSector; |
301406c9 DW |
1504 | |
1505 | strncpy(info->name, (char *) dev->volume, MAX_RAID_SERIAL_LEN); | |
1506 | info->name[MAX_RAID_SERIAL_LEN] = 0; | |
bf5a934a | 1507 | |
f35f2525 N |
1508 | info->array.major_version = -1; |
1509 | info->array.minor_version = -2; | |
e207da2f AW |
1510 | devname = devnum2devname(st->container_dev); |
1511 | *info->text_version = '\0'; | |
1512 | if (devname) | |
1513 | sprintf(info->text_version, "/%s/%d", devname, info->container_member); | |
1514 | free(devname); | |
a67dd8cc | 1515 | info->safe_mode_delay = 4000; /* 4 secs like the Matrix driver */ |
51006d85 | 1516 | uuid_from_super_imsm(st, info->uuid); |
a5d85af7 N |
1517 | |
1518 | if (dmap) { | |
1519 | int i, j; | |
1520 | for (i=0; i<map_disks; i++) { | |
1521 | dmap[i] = 0; | |
1522 | if (i < info->array.raid_disks) { | |
1523 | struct imsm_disk *dsk; | |
1524 | j = get_imsm_disk_idx(dev, i); | |
1525 | dsk = get_imsm_disk(super, j); | |
1526 | if (dsk && (dsk->status & CONFIGURED_DISK)) | |
1527 | dmap[i] = 1; | |
1528 | } | |
1529 | } | |
1530 | } | |
1531 | } | |
bf5a934a | 1532 | |
7a70e8aa DW |
1533 | /* check the config file to see if we can return a real uuid for this spare */ |
1534 | static void fixup_container_spare_uuid(struct mdinfo *inf) | |
1535 | { | |
fa56eddb | 1536 | struct mddev_ident *array_list; |
7a70e8aa DW |
1537 | |
1538 | if (inf->array.level != LEVEL_CONTAINER || | |
1539 | memcmp(inf->uuid, uuid_match_any, sizeof(int[4])) != 0) | |
1540 | return; | |
1541 | ||
1542 | array_list = conf_get_ident(NULL); | |
1543 | ||
1544 | for (; array_list; array_list = array_list->next) { | |
1545 | if (array_list->uuid_set) { | |
1546 | struct supertype *_sst; /* spare supertype */ | |
1547 | struct supertype *_cst; /* container supertype */ | |
1548 | ||
1549 | _cst = array_list->st; | |
7e8545e9 DW |
1550 | if (_cst) |
1551 | _sst = _cst->ss->match_metadata_desc(inf->text_version); | |
1552 | else | |
1553 | _sst = NULL; | |
1554 | ||
7a70e8aa DW |
1555 | if (_sst) { |
1556 | memcpy(inf->uuid, array_list->uuid, sizeof(int[4])); | |
1557 | free(_sst); | |
1558 | break; | |
1559 | } | |
1560 | } | |
1561 | } | |
1562 | } | |
bf5a934a | 1563 | |
97b4d0e9 DW |
1564 | |
1565 | static __u8 imsm_check_degraded(struct intel_super *super, struct imsm_dev *dev, int failed); | |
1566 | static int imsm_count_failed(struct intel_super *super, struct imsm_dev *dev); | |
1567 | ||
1568 | static struct imsm_disk *get_imsm_missing(struct intel_super *super, __u8 index) | |
1569 | { | |
1570 | struct dl *d; | |
1571 | ||
1572 | for (d = super->missing; d; d = d->next) | |
1573 | if (d->index == index) | |
1574 | return &d->disk; | |
1575 | return NULL; | |
1576 | } | |
1577 | ||
a5d85af7 | 1578 | static void getinfo_super_imsm(struct supertype *st, struct mdinfo *info, char *map) |
4f5bc454 DW |
1579 | { |
1580 | struct intel_super *super = st->sb; | |
4f5bc454 | 1581 | struct imsm_disk *disk; |
a5d85af7 | 1582 | int map_disks = info->array.raid_disks; |
ab3cb6b3 N |
1583 | int max_enough = -1; |
1584 | int i; | |
1585 | struct imsm_super *mpb; | |
4f5bc454 | 1586 | |
bf5a934a | 1587 | if (super->current_vol >= 0) { |
a5d85af7 | 1588 | getinfo_super_imsm_volume(st, info, map); |
bf5a934a DW |
1589 | return; |
1590 | } | |
d23fe947 DW |
1591 | |
1592 | /* Set raid_disks to zero so that Assemble will always pull in valid | |
1593 | * spares | |
1594 | */ | |
1595 | info->array.raid_disks = 0; | |
cdddbdbc DW |
1596 | info->array.level = LEVEL_CONTAINER; |
1597 | info->array.layout = 0; | |
1598 | info->array.md_minor = -1; | |
c2c087e6 | 1599 | info->array.ctime = 0; /* N/A for imsm */ |
cdddbdbc DW |
1600 | info->array.utime = 0; |
1601 | info->array.chunk_size = 0; | |
1602 | ||
1603 | info->disk.major = 0; | |
1604 | info->disk.minor = 0; | |
cdddbdbc | 1605 | info->disk.raid_disk = -1; |
c2c087e6 | 1606 | info->reshape_active = 0; |
f35f2525 N |
1607 | info->array.major_version = -1; |
1608 | info->array.minor_version = -2; | |
c2c087e6 | 1609 | strcpy(info->text_version, "imsm"); |
a67dd8cc | 1610 | info->safe_mode_delay = 0; |
c2c087e6 DW |
1611 | info->disk.number = -1; |
1612 | info->disk.state = 0; | |
c5afc314 | 1613 | info->name[0] = 0; |
921d9e16 | 1614 | info->recovery_start = MaxSector; |
c2c087e6 | 1615 | |
97b4d0e9 | 1616 | /* do we have the all the insync disks that we expect? */ |
ab3cb6b3 | 1617 | mpb = super->anchor; |
97b4d0e9 | 1618 | |
ab3cb6b3 N |
1619 | for (i = 0; i < mpb->num_raid_devs; i++) { |
1620 | struct imsm_dev *dev = get_imsm_dev(super, i); | |
1621 | int failed, enough, j, missing = 0; | |
1622 | struct imsm_map *map; | |
1623 | __u8 state; | |
97b4d0e9 | 1624 | |
ab3cb6b3 N |
1625 | failed = imsm_count_failed(super, dev); |
1626 | state = imsm_check_degraded(super, dev, failed); | |
1627 | map = get_imsm_map(dev, dev->vol.migr_state); | |
1628 | ||
1629 | /* any newly missing disks? | |
1630 | * (catches single-degraded vs double-degraded) | |
1631 | */ | |
1632 | for (j = 0; j < map->num_members; j++) { | |
1633 | __u32 ord = get_imsm_ord_tbl_ent(dev, i); | |
1634 | __u32 idx = ord_to_idx(ord); | |
1635 | ||
1636 | if (!(ord & IMSM_ORD_REBUILD) && | |
1637 | get_imsm_missing(super, idx)) { | |
1638 | missing = 1; | |
1639 | break; | |
1640 | } | |
97b4d0e9 | 1641 | } |
ab3cb6b3 N |
1642 | |
1643 | if (state == IMSM_T_STATE_FAILED) | |
1644 | enough = -1; | |
1645 | else if (state == IMSM_T_STATE_DEGRADED && | |
1646 | (state != map->map_state || missing)) | |
1647 | enough = 0; | |
1648 | else /* we're normal, or already degraded */ | |
1649 | enough = 1; | |
1650 | ||
1651 | /* in the missing/failed disk case check to see | |
1652 | * if at least one array is runnable | |
1653 | */ | |
1654 | max_enough = max(max_enough, enough); | |
1655 | } | |
1656 | dprintf("%s: enough: %d\n", __func__, max_enough); | |
1657 | info->container_enough = max_enough; | |
97b4d0e9 | 1658 | |
4a04ec6c | 1659 | if (super->disks) { |
14e8215b DW |
1660 | __u32 reserved = imsm_reserved_sectors(super, super->disks); |
1661 | ||
b9f594fe | 1662 | disk = &super->disks->disk; |
14e8215b DW |
1663 | info->data_offset = __le32_to_cpu(disk->total_blocks) - reserved; |
1664 | info->component_size = reserved; | |
25ed7e59 | 1665 | info->disk.state = is_configured(disk) ? (1 << MD_DISK_ACTIVE) : 0; |
df474657 DW |
1666 | /* we don't change info->disk.raid_disk here because |
1667 | * this state will be finalized in mdmon after we have | |
1668 | * found the 'most fresh' version of the metadata | |
1669 | */ | |
25ed7e59 DW |
1670 | info->disk.state |= is_failed(disk) ? (1 << MD_DISK_FAULTY) : 0; |
1671 | info->disk.state |= is_spare(disk) ? 0 : (1 << MD_DISK_SYNC); | |
cdddbdbc | 1672 | } |
a575e2a7 DW |
1673 | |
1674 | /* only call uuid_from_super_imsm when this disk is part of a populated container, | |
1675 | * ->compare_super may have updated the 'num_raid_devs' field for spares | |
1676 | */ | |
1677 | if (info->disk.state & (1 << MD_DISK_SYNC) || super->anchor->num_raid_devs) | |
36ba7d48 | 1678 | uuid_from_super_imsm(st, info->uuid); |
7a70e8aa | 1679 | else { |
032e9e29 | 1680 | memcpy(info->uuid, uuid_match_any, sizeof(int[4])); |
7a70e8aa DW |
1681 | fixup_container_spare_uuid(info); |
1682 | } | |
a5d85af7 N |
1683 | |
1684 | /* I don't know how to compute 'map' on imsm, so use safe default */ | |
1685 | if (map) { | |
1686 | int i; | |
1687 | for (i = 0; i < map_disks; i++) | |
1688 | map[i] = 1; | |
1689 | } | |
1690 | ||
cdddbdbc DW |
1691 | } |
1692 | ||
cdddbdbc DW |
1693 | static int update_super_imsm(struct supertype *st, struct mdinfo *info, |
1694 | char *update, char *devname, int verbose, | |
1695 | int uuid_set, char *homehost) | |
1696 | { | |
f352c545 DW |
1697 | /* For 'assemble' and 'force' we need to return non-zero if any |
1698 | * change was made. For others, the return value is ignored. | |
1699 | * Update options are: | |
1700 | * force-one : This device looks a bit old but needs to be included, | |
1701 | * update age info appropriately. | |
1702 | * assemble: clear any 'faulty' flag to allow this device to | |
1703 | * be assembled. | |
1704 | * force-array: Array is degraded but being forced, mark it clean | |
1705 | * if that will be needed to assemble it. | |
1706 | * | |
1707 | * newdev: not used ???? | |
1708 | * grow: Array has gained a new device - this is currently for | |
1709 | * linear only | |
1710 | * resync: mark as dirty so a resync will happen. | |
1711 | * name: update the name - preserving the homehost | |
6e46bf34 | 1712 | * uuid: Change the uuid of the array to match watch is given |
f352c545 DW |
1713 | * |
1714 | * Following are not relevant for this imsm: | |
1715 | * sparc2.2 : update from old dodgey metadata | |
1716 | * super-minor: change the preferred_minor number | |
1717 | * summaries: update redundant counters. | |
f352c545 DW |
1718 | * homehost: update the recorded homehost |
1719 | * _reshape_progress: record new reshape_progress position. | |
1720 | */ | |
6e46bf34 DW |
1721 | int rv = 1; |
1722 | struct intel_super *super = st->sb; | |
1723 | struct imsm_super *mpb; | |
f352c545 | 1724 | |
6e46bf34 DW |
1725 | /* we can only update container info */ |
1726 | if (!super || super->current_vol >= 0 || !super->anchor) | |
1727 | return 1; | |
1728 | ||
1729 | mpb = super->anchor; | |
1730 | ||
1731 | if (strcmp(update, "uuid") == 0 && uuid_set && !info->update_private) | |
1e2b2765 | 1732 | rv = -1; |
6e46bf34 DW |
1733 | else if (strcmp(update, "uuid") == 0 && uuid_set && info->update_private) { |
1734 | mpb->orig_family_num = *((__u32 *) info->update_private); | |
1735 | rv = 0; | |
1736 | } else if (strcmp(update, "uuid") == 0) { | |
1737 | __u32 *new_family = malloc(sizeof(*new_family)); | |
1738 | ||
1739 | /* update orig_family_number with the incoming random | |
1740 | * data, report the new effective uuid, and store the | |
1741 | * new orig_family_num for future updates. | |
1742 | */ | |
1743 | if (new_family) { | |
1744 | memcpy(&mpb->orig_family_num, info->uuid, sizeof(__u32)); | |
1745 | uuid_from_super_imsm(st, info->uuid); | |
1746 | *new_family = mpb->orig_family_num; | |
1747 | info->update_private = new_family; | |
1748 | rv = 0; | |
1749 | } | |
1750 | } else if (strcmp(update, "assemble") == 0) | |
1751 | rv = 0; | |
1752 | else | |
1e2b2765 | 1753 | rv = -1; |
f352c545 | 1754 | |
6e46bf34 DW |
1755 | /* successful update? recompute checksum */ |
1756 | if (rv == 0) | |
1757 | mpb->check_sum = __le32_to_cpu(__gen_imsm_checksum(mpb)); | |
f352c545 DW |
1758 | |
1759 | return rv; | |
cdddbdbc DW |
1760 | } |
1761 | ||
c2c087e6 | 1762 | static size_t disks_to_mpb_size(int disks) |
cdddbdbc | 1763 | { |
c2c087e6 | 1764 | size_t size; |
cdddbdbc | 1765 | |
c2c087e6 DW |
1766 | size = sizeof(struct imsm_super); |
1767 | size += (disks - 1) * sizeof(struct imsm_disk); | |
1768 | size += 2 * sizeof(struct imsm_dev); | |
1769 | /* up to 2 maps per raid device (-2 for imsm_maps in imsm_dev */ | |
1770 | size += (4 - 2) * sizeof(struct imsm_map); | |
1771 | /* 4 possible disk_ord_tbl's */ | |
1772 | size += 4 * (disks - 1) * sizeof(__u32); | |
1773 | ||
1774 | return size; | |
1775 | } | |
1776 | ||
1777 | static __u64 avail_size_imsm(struct supertype *st, __u64 devsize) | |
1778 | { | |
1779 | if (devsize < (MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS)) | |
1780 | return 0; | |
1781 | ||
1782 | return devsize - (MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS); | |
cdddbdbc DW |
1783 | } |
1784 | ||
ba2de7ba DW |
1785 | static void free_devlist(struct intel_super *super) |
1786 | { | |
1787 | struct intel_dev *dv; | |
1788 | ||
1789 | while (super->devlist) { | |
1790 | dv = super->devlist->next; | |
1791 | free(super->devlist->dev); | |
1792 | free(super->devlist); | |
1793 | super->devlist = dv; | |
1794 | } | |
1795 | } | |
1796 | ||
1797 | static void imsm_copy_dev(struct imsm_dev *dest, struct imsm_dev *src) | |
1798 | { | |
1799 | memcpy(dest, src, sizeof_imsm_dev(src, 0)); | |
1800 | } | |
1801 | ||
cdddbdbc DW |
1802 | static int compare_super_imsm(struct supertype *st, struct supertype *tst) |
1803 | { | |
1804 | /* | |
1805 | * return: | |
1806 | * 0 same, or first was empty, and second was copied | |
1807 | * 1 second had wrong number | |
1808 | * 2 wrong uuid | |
1809 | * 3 wrong other info | |
1810 | */ | |
1811 | struct intel_super *first = st->sb; | |
1812 | struct intel_super *sec = tst->sb; | |
1813 | ||
1814 | if (!first) { | |
1815 | st->sb = tst->sb; | |
1816 | tst->sb = NULL; | |
1817 | return 0; | |
1818 | } | |
1819 | ||
d23fe947 DW |
1820 | /* if an anchor does not have num_raid_devs set then it is a free |
1821 | * floating spare | |
1822 | */ | |
1823 | if (first->anchor->num_raid_devs > 0 && | |
1824 | sec->anchor->num_raid_devs > 0) { | |
a2b97981 DW |
1825 | /* Determine if these disks might ever have been |
1826 | * related. Further disambiguation can only take place | |
1827 | * in load_super_imsm_all | |
1828 | */ | |
1829 | __u32 first_family = first->anchor->orig_family_num; | |
1830 | __u32 sec_family = sec->anchor->orig_family_num; | |
1831 | ||
f796af5d DW |
1832 | if (memcmp(first->anchor->sig, sec->anchor->sig, |
1833 | MAX_SIGNATURE_LENGTH) != 0) | |
1834 | return 3; | |
1835 | ||
a2b97981 DW |
1836 | if (first_family == 0) |
1837 | first_family = first->anchor->family_num; | |
1838 | if (sec_family == 0) | |
1839 | sec_family = sec->anchor->family_num; | |
1840 | ||
1841 | if (first_family != sec_family) | |
d23fe947 | 1842 | return 3; |
f796af5d | 1843 | |
d23fe947 | 1844 | } |
cdddbdbc | 1845 | |
f796af5d | 1846 | |
3e372e5a DW |
1847 | /* if 'first' is a spare promote it to a populated mpb with sec's |
1848 | * family number | |
1849 | */ | |
1850 | if (first->anchor->num_raid_devs == 0 && | |
1851 | sec->anchor->num_raid_devs > 0) { | |
78d30f94 | 1852 | int i; |
ba2de7ba DW |
1853 | struct intel_dev *dv; |
1854 | struct imsm_dev *dev; | |
78d30f94 DW |
1855 | |
1856 | /* we need to copy raid device info from sec if an allocation | |
1857 | * fails here we don't associate the spare | |
1858 | */ | |
1859 | for (i = 0; i < sec->anchor->num_raid_devs; i++) { | |
ba2de7ba DW |
1860 | dv = malloc(sizeof(*dv)); |
1861 | if (!dv) | |
1862 | break; | |
1863 | dev = malloc(sizeof_imsm_dev(get_imsm_dev(sec, i), 1)); | |
1864 | if (!dev) { | |
1865 | free(dv); | |
1866 | break; | |
78d30f94 | 1867 | } |
ba2de7ba DW |
1868 | dv->dev = dev; |
1869 | dv->index = i; | |
1870 | dv->next = first->devlist; | |
1871 | first->devlist = dv; | |
78d30f94 | 1872 | } |
709743c5 | 1873 | if (i < sec->anchor->num_raid_devs) { |
ba2de7ba DW |
1874 | /* allocation failure */ |
1875 | free_devlist(first); | |
1876 | fprintf(stderr, "imsm: failed to associate spare\n"); | |
1877 | return 3; | |
78d30f94 | 1878 | } |
3e372e5a | 1879 | first->anchor->num_raid_devs = sec->anchor->num_raid_devs; |
148acb7b | 1880 | first->anchor->orig_family_num = sec->anchor->orig_family_num; |
3e372e5a | 1881 | first->anchor->family_num = sec->anchor->family_num; |
ac6449be | 1882 | memcpy(first->anchor->sig, sec->anchor->sig, MAX_SIGNATURE_LENGTH); |
709743c5 DW |
1883 | for (i = 0; i < sec->anchor->num_raid_devs; i++) |
1884 | imsm_copy_dev(get_imsm_dev(first, i), get_imsm_dev(sec, i)); | |
3e372e5a DW |
1885 | } |
1886 | ||
cdddbdbc DW |
1887 | return 0; |
1888 | } | |
1889 | ||
0030e8d6 DW |
1890 | static void fd2devname(int fd, char *name) |
1891 | { | |
1892 | struct stat st; | |
1893 | char path[256]; | |
33a6535d | 1894 | char dname[PATH_MAX]; |
0030e8d6 DW |
1895 | char *nm; |
1896 | int rv; | |
1897 | ||
1898 | name[0] = '\0'; | |
1899 | if (fstat(fd, &st) != 0) | |
1900 | return; | |
1901 | sprintf(path, "/sys/dev/block/%d:%d", | |
1902 | major(st.st_rdev), minor(st.st_rdev)); | |
1903 | ||
1904 | rv = readlink(path, dname, sizeof(dname)); | |
1905 | if (rv <= 0) | |
1906 | return; | |
1907 | ||
1908 | dname[rv] = '\0'; | |
1909 | nm = strrchr(dname, '/'); | |
1910 | nm++; | |
1911 | snprintf(name, MAX_RAID_SERIAL_LEN, "/dev/%s", nm); | |
1912 | } | |
1913 | ||
cdddbdbc DW |
1914 | extern int scsi_get_serial(int fd, void *buf, size_t buf_len); |
1915 | ||
1916 | static int imsm_read_serial(int fd, char *devname, | |
1917 | __u8 serial[MAX_RAID_SERIAL_LEN]) | |
1918 | { | |
1919 | unsigned char scsi_serial[255]; | |
cdddbdbc DW |
1920 | int rv; |
1921 | int rsp_len; | |
1f24f035 | 1922 | int len; |
316e2bf4 DW |
1923 | char *dest; |
1924 | char *src; | |
1925 | char *rsp_buf; | |
1926 | int i; | |
cdddbdbc DW |
1927 | |
1928 | memset(scsi_serial, 0, sizeof(scsi_serial)); | |
cdddbdbc | 1929 | |
f9ba0ff1 DW |
1930 | rv = scsi_get_serial(fd, scsi_serial, sizeof(scsi_serial)); |
1931 | ||
40ebbb9c | 1932 | if (rv && check_env("IMSM_DEVNAME_AS_SERIAL")) { |
f9ba0ff1 DW |
1933 | memset(serial, 0, MAX_RAID_SERIAL_LEN); |
1934 | fd2devname(fd, (char *) serial); | |
0030e8d6 DW |
1935 | return 0; |
1936 | } | |
1937 | ||
cdddbdbc DW |
1938 | if (rv != 0) { |
1939 | if (devname) | |
1940 | fprintf(stderr, | |
1941 | Name ": Failed to retrieve serial for %s\n", | |
1942 | devname); | |
1943 | return rv; | |
1944 | } | |
1945 | ||
1946 | rsp_len = scsi_serial[3]; | |
03cd4cc8 DW |
1947 | if (!rsp_len) { |
1948 | if (devname) | |
1949 | fprintf(stderr, | |
1950 | Name ": Failed to retrieve serial for %s\n", | |
1951 | devname); | |
1952 | return 2; | |
1953 | } | |
1f24f035 | 1954 | rsp_buf = (char *) &scsi_serial[4]; |
5c3db629 | 1955 | |
316e2bf4 DW |
1956 | /* trim all whitespace and non-printable characters and convert |
1957 | * ':' to ';' | |
1958 | */ | |
1959 | for (i = 0, dest = rsp_buf; i < rsp_len; i++) { | |
1960 | src = &rsp_buf[i]; | |
1961 | if (*src > 0x20) { | |
1962 | /* ':' is reserved for use in placeholder serial | |
1963 | * numbers for missing disks | |
1964 | */ | |
1965 | if (*src == ':') | |
1966 | *dest++ = ';'; | |
1967 | else | |
1968 | *dest++ = *src; | |
1969 | } | |
1970 | } | |
1971 | len = dest - rsp_buf; | |
1972 | dest = rsp_buf; | |
1973 | ||
1974 | /* truncate leading characters */ | |
1975 | if (len > MAX_RAID_SERIAL_LEN) { | |
1976 | dest += len - MAX_RAID_SERIAL_LEN; | |
1f24f035 | 1977 | len = MAX_RAID_SERIAL_LEN; |
316e2bf4 | 1978 | } |
5c3db629 | 1979 | |
5c3db629 | 1980 | memset(serial, 0, MAX_RAID_SERIAL_LEN); |
316e2bf4 | 1981 | memcpy(serial, dest, len); |
cdddbdbc DW |
1982 | |
1983 | return 0; | |
1984 | } | |
1985 | ||
1f24f035 DW |
1986 | static int serialcmp(__u8 *s1, __u8 *s2) |
1987 | { | |
1988 | return strncmp((char *) s1, (char *) s2, MAX_RAID_SERIAL_LEN); | |
1989 | } | |
1990 | ||
1991 | static void serialcpy(__u8 *dest, __u8 *src) | |
1992 | { | |
1993 | strncpy((char *) dest, (char *) src, MAX_RAID_SERIAL_LEN); | |
1994 | } | |
1995 | ||
1799c9e8 | 1996 | #ifndef MDASSEMBLE |
54c2c1ea DW |
1997 | static struct dl *serial_to_dl(__u8 *serial, struct intel_super *super) |
1998 | { | |
1999 | struct dl *dl; | |
2000 | ||
2001 | for (dl = super->disks; dl; dl = dl->next) | |
2002 | if (serialcmp(dl->serial, serial) == 0) | |
2003 | break; | |
2004 | ||
2005 | return dl; | |
2006 | } | |
1799c9e8 | 2007 | #endif |
54c2c1ea | 2008 | |
a2b97981 DW |
2009 | static struct imsm_disk * |
2010 | __serial_to_disk(__u8 *serial, struct imsm_super *mpb, int *idx) | |
2011 | { | |
2012 | int i; | |
2013 | ||
2014 | for (i = 0; i < mpb->num_disks; i++) { | |
2015 | struct imsm_disk *disk = __get_imsm_disk(mpb, i); | |
2016 | ||
2017 | if (serialcmp(disk->serial, serial) == 0) { | |
2018 | if (idx) | |
2019 | *idx = i; | |
2020 | return disk; | |
2021 | } | |
2022 | } | |
2023 | ||
2024 | return NULL; | |
2025 | } | |
2026 | ||
cdddbdbc DW |
2027 | static int |
2028 | load_imsm_disk(int fd, struct intel_super *super, char *devname, int keep_fd) | |
2029 | { | |
a2b97981 | 2030 | struct imsm_disk *disk; |
cdddbdbc DW |
2031 | struct dl *dl; |
2032 | struct stat stb; | |
cdddbdbc | 2033 | int rv; |
a2b97981 | 2034 | char name[40]; |
d23fe947 DW |
2035 | __u8 serial[MAX_RAID_SERIAL_LEN]; |
2036 | ||
2037 | rv = imsm_read_serial(fd, devname, serial); | |
2038 | ||
2039 | if (rv != 0) | |
2040 | return 2; | |
2041 | ||
a2b97981 | 2042 | dl = calloc(1, sizeof(*dl)); |
b9f594fe | 2043 | if (!dl) { |
cdddbdbc DW |
2044 | if (devname) |
2045 | fprintf(stderr, | |
2046 | Name ": failed to allocate disk buffer for %s\n", | |
2047 | devname); | |
2048 | return 2; | |
2049 | } | |
cdddbdbc | 2050 | |
a2b97981 DW |
2051 | fstat(fd, &stb); |
2052 | dl->major = major(stb.st_rdev); | |
2053 | dl->minor = minor(stb.st_rdev); | |
2054 | dl->next = super->disks; | |
2055 | dl->fd = keep_fd ? fd : -1; | |
2056 | assert(super->disks == NULL); | |
2057 | super->disks = dl; | |
2058 | serialcpy(dl->serial, serial); | |
2059 | dl->index = -2; | |
2060 | dl->e = NULL; | |
2061 | fd2devname(fd, name); | |
2062 | if (devname) | |
2063 | dl->devname = strdup(devname); | |
2064 | else | |
2065 | dl->devname = strdup(name); | |
cdddbdbc | 2066 | |
d23fe947 | 2067 | /* look up this disk's index in the current anchor */ |
a2b97981 DW |
2068 | disk = __serial_to_disk(dl->serial, super->anchor, &dl->index); |
2069 | if (disk) { | |
2070 | dl->disk = *disk; | |
2071 | /* only set index on disks that are a member of a | |
2072 | * populated contianer, i.e. one with raid_devs | |
2073 | */ | |
2074 | if (is_failed(&dl->disk)) | |
3f6efecc | 2075 | dl->index = -2; |
a2b97981 DW |
2076 | else if (is_spare(&dl->disk)) |
2077 | dl->index = -1; | |
3f6efecc DW |
2078 | } |
2079 | ||
949c47a0 DW |
2080 | return 0; |
2081 | } | |
2082 | ||
0e600426 | 2083 | #ifndef MDASSEMBLE |
0c046afd DW |
2084 | /* When migrating map0 contains the 'destination' state while map1 |
2085 | * contains the current state. When not migrating map0 contains the | |
2086 | * current state. This routine assumes that map[0].map_state is set to | |
2087 | * the current array state before being called. | |
2088 | * | |
2089 | * Migration is indicated by one of the following states | |
2090 | * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed) | |
e3bba0e0 | 2091 | * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal |
0c046afd | 2092 | * map1state=unitialized) |
1484e727 | 2093 | * 3/ Repair (Resync) (migr_state=1 migr_type=MIGR_REPAIR map0state=normal |
0c046afd | 2094 | * map1state=normal) |
e3bba0e0 | 2095 | * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal |
0c046afd DW |
2096 | * map1state=degraded) |
2097 | */ | |
0556e1a2 | 2098 | static void migrate(struct imsm_dev *dev, __u8 to_state, int migr_type) |
3393c6af | 2099 | { |
0c046afd | 2100 | struct imsm_map *dest; |
3393c6af DW |
2101 | struct imsm_map *src = get_imsm_map(dev, 0); |
2102 | ||
0c046afd | 2103 | dev->vol.migr_state = 1; |
1484e727 | 2104 | set_migr_type(dev, migr_type); |
f8f603f1 | 2105 | dev->vol.curr_migr_unit = 0; |
0c046afd DW |
2106 | dest = get_imsm_map(dev, 1); |
2107 | ||
0556e1a2 | 2108 | /* duplicate and then set the target end state in map[0] */ |
3393c6af | 2109 | memcpy(dest, src, sizeof_imsm_map(src)); |
0556e1a2 DW |
2110 | if (migr_type == MIGR_REBUILD) { |
2111 | __u32 ord; | |
2112 | int i; | |
2113 | ||
2114 | for (i = 0; i < src->num_members; i++) { | |
2115 | ord = __le32_to_cpu(src->disk_ord_tbl[i]); | |
2116 | set_imsm_ord_tbl_ent(src, i, ord_to_idx(ord)); | |
2117 | } | |
2118 | } | |
2119 | ||
0c046afd | 2120 | src->map_state = to_state; |
949c47a0 | 2121 | } |
f8f603f1 DW |
2122 | |
2123 | static void end_migration(struct imsm_dev *dev, __u8 map_state) | |
2124 | { | |
2125 | struct imsm_map *map = get_imsm_map(dev, 0); | |
0556e1a2 DW |
2126 | struct imsm_map *prev = get_imsm_map(dev, dev->vol.migr_state); |
2127 | int i; | |
2128 | ||
2129 | /* merge any IMSM_ORD_REBUILD bits that were not successfully | |
2130 | * completed in the last migration. | |
2131 | * | |
2132 | * FIXME add support for online capacity expansion and | |
2133 | * raid-level-migration | |
2134 | */ | |
2135 | for (i = 0; i < prev->num_members; i++) | |
2136 | map->disk_ord_tbl[i] |= prev->disk_ord_tbl[i]; | |
f8f603f1 DW |
2137 | |
2138 | dev->vol.migr_state = 0; | |
2139 | dev->vol.curr_migr_unit = 0; | |
2140 | map->map_state = map_state; | |
2141 | } | |
0e600426 | 2142 | #endif |
949c47a0 DW |
2143 | |
2144 | static int parse_raid_devices(struct intel_super *super) | |
2145 | { | |
2146 | int i; | |
2147 | struct imsm_dev *dev_new; | |
4d7b1503 DW |
2148 | size_t len, len_migr; |
2149 | size_t space_needed = 0; | |
2150 | struct imsm_super *mpb = super->anchor; | |
949c47a0 DW |
2151 | |
2152 | for (i = 0; i < super->anchor->num_raid_devs; i++) { | |
2153 | struct imsm_dev *dev_iter = __get_imsm_dev(super->anchor, i); | |
ba2de7ba | 2154 | struct intel_dev *dv; |
949c47a0 | 2155 | |
4d7b1503 DW |
2156 | len = sizeof_imsm_dev(dev_iter, 0); |
2157 | len_migr = sizeof_imsm_dev(dev_iter, 1); | |
2158 | if (len_migr > len) | |
2159 | space_needed += len_migr - len; | |
2160 | ||
ba2de7ba DW |
2161 | dv = malloc(sizeof(*dv)); |
2162 | if (!dv) | |
2163 | return 1; | |
4d7b1503 | 2164 | dev_new = malloc(len_migr); |
ba2de7ba DW |
2165 | if (!dev_new) { |
2166 | free(dv); | |
949c47a0 | 2167 | return 1; |
ba2de7ba | 2168 | } |
949c47a0 | 2169 | imsm_copy_dev(dev_new, dev_iter); |
ba2de7ba DW |
2170 | dv->dev = dev_new; |
2171 | dv->index = i; | |
2172 | dv->next = super->devlist; | |
2173 | super->devlist = dv; | |
949c47a0 | 2174 | } |
cdddbdbc | 2175 | |
4d7b1503 DW |
2176 | /* ensure that super->buf is large enough when all raid devices |
2177 | * are migrating | |
2178 | */ | |
2179 | if (__le32_to_cpu(mpb->mpb_size) + space_needed > super->len) { | |
2180 | void *buf; | |
2181 | ||
2182 | len = ROUND_UP(__le32_to_cpu(mpb->mpb_size) + space_needed, 512); | |
2183 | if (posix_memalign(&buf, 512, len) != 0) | |
2184 | return 1; | |
2185 | ||
1f45a8ad DW |
2186 | memcpy(buf, super->buf, super->len); |
2187 | memset(buf + super->len, 0, len - super->len); | |
4d7b1503 DW |
2188 | free(super->buf); |
2189 | super->buf = buf; | |
2190 | super->len = len; | |
2191 | } | |
2192 | ||
cdddbdbc DW |
2193 | return 0; |
2194 | } | |
2195 | ||
604b746f JD |
2196 | /* retrieve a pointer to the bbm log which starts after all raid devices */ |
2197 | struct bbm_log *__get_imsm_bbm_log(struct imsm_super *mpb) | |
2198 | { | |
2199 | void *ptr = NULL; | |
2200 | ||
2201 | if (__le32_to_cpu(mpb->bbm_log_size)) { | |
2202 | ptr = mpb; | |
2203 | ptr += mpb->mpb_size - __le32_to_cpu(mpb->bbm_log_size); | |
2204 | } | |
2205 | ||
2206 | return ptr; | |
2207 | } | |
2208 | ||
d23fe947 | 2209 | static void __free_imsm(struct intel_super *super, int free_disks); |
9ca2c81c | 2210 | |
cdddbdbc DW |
2211 | /* load_imsm_mpb - read matrix metadata |
2212 | * allocates super->mpb to be freed by free_super | |
2213 | */ | |
2214 | static int load_imsm_mpb(int fd, struct intel_super *super, char *devname) | |
2215 | { | |
2216 | unsigned long long dsize; | |
cdddbdbc DW |
2217 | unsigned long long sectors; |
2218 | struct stat; | |
6416d527 | 2219 | struct imsm_super *anchor; |
cdddbdbc DW |
2220 | __u32 check_sum; |
2221 | ||
cdddbdbc | 2222 | get_dev_size(fd, NULL, &dsize); |
64436f06 N |
2223 | if (dsize < 1024) { |
2224 | if (devname) | |
2225 | fprintf(stderr, | |
2226 | Name ": %s: device to small for imsm\n", | |
2227 | devname); | |
2228 | return 1; | |
2229 | } | |
cdddbdbc DW |
2230 | |
2231 | if (lseek64(fd, dsize - (512 * 2), SEEK_SET) < 0) { | |
2232 | if (devname) | |
2233 | fprintf(stderr, | |
2234 | Name ": Cannot seek to anchor block on %s: %s\n", | |
2235 | devname, strerror(errno)); | |
2236 | return 1; | |
2237 | } | |
2238 | ||
949c47a0 | 2239 | if (posix_memalign((void**)&anchor, 512, 512) != 0) { |
ad97895e DW |
2240 | if (devname) |
2241 | fprintf(stderr, | |
2242 | Name ": Failed to allocate imsm anchor buffer" | |
2243 | " on %s\n", devname); | |
2244 | return 1; | |
2245 | } | |
949c47a0 | 2246 | if (read(fd, anchor, 512) != 512) { |
cdddbdbc DW |
2247 | if (devname) |
2248 | fprintf(stderr, | |
2249 | Name ": Cannot read anchor block on %s: %s\n", | |
2250 | devname, strerror(errno)); | |
6416d527 | 2251 | free(anchor); |
cdddbdbc DW |
2252 | return 1; |
2253 | } | |
2254 | ||
6416d527 | 2255 | if (strncmp((char *) anchor->sig, MPB_SIGNATURE, MPB_SIG_LEN) != 0) { |
cdddbdbc DW |
2256 | if (devname) |
2257 | fprintf(stderr, | |
2258 | Name ": no IMSM anchor on %s\n", devname); | |
6416d527 | 2259 | free(anchor); |
cdddbdbc DW |
2260 | return 2; |
2261 | } | |
2262 | ||
d23fe947 | 2263 | __free_imsm(super, 0); |
949c47a0 DW |
2264 | super->len = ROUND_UP(anchor->mpb_size, 512); |
2265 | if (posix_memalign(&super->buf, 512, super->len) != 0) { | |
cdddbdbc DW |
2266 | if (devname) |
2267 | fprintf(stderr, | |
2268 | Name ": unable to allocate %zu byte mpb buffer\n", | |
949c47a0 | 2269 | super->len); |
6416d527 | 2270 | free(anchor); |
cdddbdbc DW |
2271 | return 2; |
2272 | } | |
949c47a0 | 2273 | memcpy(super->buf, anchor, 512); |
cdddbdbc | 2274 | |
6416d527 NB |
2275 | sectors = mpb_sectors(anchor) - 1; |
2276 | free(anchor); | |
949c47a0 | 2277 | if (!sectors) { |
ecf45690 DW |
2278 | check_sum = __gen_imsm_checksum(super->anchor); |
2279 | if (check_sum != __le32_to_cpu(super->anchor->check_sum)) { | |
2280 | if (devname) | |
2281 | fprintf(stderr, | |
2282 | Name ": IMSM checksum %x != %x on %s\n", | |
2283 | check_sum, | |
2284 | __le32_to_cpu(super->anchor->check_sum), | |
2285 | devname); | |
2286 | return 2; | |
2287 | } | |
2288 | ||
a2b97981 | 2289 | return 0; |
949c47a0 | 2290 | } |
cdddbdbc DW |
2291 | |
2292 | /* read the extended mpb */ | |
2293 | if (lseek64(fd, dsize - (512 * (2 + sectors)), SEEK_SET) < 0) { | |
2294 | if (devname) | |
2295 | fprintf(stderr, | |
2296 | Name ": Cannot seek to extended mpb on %s: %s\n", | |
2297 | devname, strerror(errno)); | |
2298 | return 1; | |
2299 | } | |
2300 | ||
f21e18ca | 2301 | if ((unsigned)read(fd, super->buf + 512, super->len - 512) != super->len - 512) { |
cdddbdbc DW |
2302 | if (devname) |
2303 | fprintf(stderr, | |
2304 | Name ": Cannot read extended mpb on %s: %s\n", | |
2305 | devname, strerror(errno)); | |
2306 | return 2; | |
2307 | } | |
2308 | ||
949c47a0 DW |
2309 | check_sum = __gen_imsm_checksum(super->anchor); |
2310 | if (check_sum != __le32_to_cpu(super->anchor->check_sum)) { | |
cdddbdbc DW |
2311 | if (devname) |
2312 | fprintf(stderr, | |
2313 | Name ": IMSM checksum %x != %x on %s\n", | |
949c47a0 | 2314 | check_sum, __le32_to_cpu(super->anchor->check_sum), |
cdddbdbc | 2315 | devname); |
db575f3b | 2316 | return 3; |
cdddbdbc DW |
2317 | } |
2318 | ||
604b746f JD |
2319 | /* FIXME the BBM log is disk specific so we cannot use this global |
2320 | * buffer for all disks. Ok for now since we only look at the global | |
2321 | * bbm_log_size parameter to gate assembly | |
2322 | */ | |
2323 | super->bbm_log = __get_imsm_bbm_log(super->anchor); | |
2324 | ||
a2b97981 DW |
2325 | return 0; |
2326 | } | |
2327 | ||
2328 | static int | |
2329 | load_and_parse_mpb(int fd, struct intel_super *super, char *devname, int keep_fd) | |
2330 | { | |
2331 | int err; | |
2332 | ||
2333 | err = load_imsm_mpb(fd, super, devname); | |
2334 | if (err) | |
2335 | return err; | |
2336 | err = load_imsm_disk(fd, super, devname, keep_fd); | |
2337 | if (err) | |
2338 | return err; | |
2339 | err = parse_raid_devices(super); | |
4d7b1503 | 2340 | |
a2b97981 | 2341 | return err; |
cdddbdbc DW |
2342 | } |
2343 | ||
ae6aad82 DW |
2344 | static void __free_imsm_disk(struct dl *d) |
2345 | { | |
2346 | if (d->fd >= 0) | |
2347 | close(d->fd); | |
2348 | if (d->devname) | |
2349 | free(d->devname); | |
0dcecb2e DW |
2350 | if (d->e) |
2351 | free(d->e); | |
ae6aad82 DW |
2352 | free(d); |
2353 | ||
2354 | } | |
cdddbdbc DW |
2355 | static void free_imsm_disks(struct intel_super *super) |
2356 | { | |
47ee5a45 | 2357 | struct dl *d; |
cdddbdbc | 2358 | |
47ee5a45 DW |
2359 | while (super->disks) { |
2360 | d = super->disks; | |
cdddbdbc | 2361 | super->disks = d->next; |
ae6aad82 | 2362 | __free_imsm_disk(d); |
cdddbdbc | 2363 | } |
47ee5a45 DW |
2364 | while (super->missing) { |
2365 | d = super->missing; | |
2366 | super->missing = d->next; | |
2367 | __free_imsm_disk(d); | |
2368 | } | |
2369 | ||
cdddbdbc DW |
2370 | } |
2371 | ||
9ca2c81c | 2372 | /* free all the pieces hanging off of a super pointer */ |
d23fe947 | 2373 | static void __free_imsm(struct intel_super *super, int free_disks) |
cdddbdbc | 2374 | { |
9ca2c81c | 2375 | if (super->buf) { |
949c47a0 | 2376 | free(super->buf); |
9ca2c81c DW |
2377 | super->buf = NULL; |
2378 | } | |
d23fe947 DW |
2379 | if (free_disks) |
2380 | free_imsm_disks(super); | |
ba2de7ba | 2381 | free_devlist(super); |
88c32bb1 DW |
2382 | if (super->hba) { |
2383 | free((void *) super->hba); | |
2384 | super->hba = NULL; | |
2385 | } | |
cdddbdbc DW |
2386 | } |
2387 | ||
9ca2c81c DW |
2388 | static void free_imsm(struct intel_super *super) |
2389 | { | |
d23fe947 | 2390 | __free_imsm(super, 1); |
9ca2c81c DW |
2391 | free(super); |
2392 | } | |
cdddbdbc DW |
2393 | |
2394 | static void free_super_imsm(struct supertype *st) | |
2395 | { | |
2396 | struct intel_super *super = st->sb; | |
2397 | ||
2398 | if (!super) | |
2399 | return; | |
2400 | ||
2401 | free_imsm(super); | |
2402 | st->sb = NULL; | |
2403 | } | |
2404 | ||
49133e57 | 2405 | static struct intel_super *alloc_super(void) |
c2c087e6 DW |
2406 | { |
2407 | struct intel_super *super = malloc(sizeof(*super)); | |
2408 | ||
2409 | if (super) { | |
2410 | memset(super, 0, sizeof(*super)); | |
bf5a934a | 2411 | super->current_vol = -1; |
0dcecb2e | 2412 | super->create_offset = ~((__u32 ) 0); |
88c32bb1 DW |
2413 | if (!check_env("IMSM_NO_PLATFORM")) |
2414 | super->orom = find_imsm_orom(); | |
cceebc67 | 2415 | if (super->orom && !check_env("IMSM_TEST_OROM")) { |
88c32bb1 DW |
2416 | struct sys_dev *list, *ent; |
2417 | ||
2418 | /* find the first intel ahci controller */ | |
2419 | list = find_driver_devices("pci", "ahci"); | |
2420 | for (ent = list; ent; ent = ent->next) | |
2421 | if (devpath_to_vendor(ent->path) == 0x8086) | |
2422 | break; | |
2423 | if (ent) { | |
2424 | super->hba = ent->path; | |
2425 | ent->path = NULL; | |
2426 | } | |
2427 | free_sys_dev(&list); | |
2428 | } | |
c2c087e6 DW |
2429 | } |
2430 | ||
2431 | return super; | |
2432 | } | |
2433 | ||
cdddbdbc | 2434 | #ifndef MDASSEMBLE |
47ee5a45 DW |
2435 | /* find_missing - helper routine for load_super_imsm_all that identifies |
2436 | * disks that have disappeared from the system. This routine relies on | |
2437 | * the mpb being uptodate, which it is at load time. | |
2438 | */ | |
2439 | static int find_missing(struct intel_super *super) | |
2440 | { | |
2441 | int i; | |
2442 | struct imsm_super *mpb = super->anchor; | |
2443 | struct dl *dl; | |
2444 | struct imsm_disk *disk; | |
47ee5a45 DW |
2445 | |
2446 | for (i = 0; i < mpb->num_disks; i++) { | |
2447 | disk = __get_imsm_disk(mpb, i); | |
54c2c1ea | 2448 | dl = serial_to_dl(disk->serial, super); |
47ee5a45 DW |
2449 | if (dl) |
2450 | continue; | |
47ee5a45 DW |
2451 | |
2452 | dl = malloc(sizeof(*dl)); | |
2453 | if (!dl) | |
2454 | return 1; | |
2455 | dl->major = 0; | |
2456 | dl->minor = 0; | |
2457 | dl->fd = -1; | |
2458 | dl->devname = strdup("missing"); | |
2459 | dl->index = i; | |
2460 | serialcpy(dl->serial, disk->serial); | |
2461 | dl->disk = *disk; | |
689c9bf3 | 2462 | dl->e = NULL; |
47ee5a45 DW |
2463 | dl->next = super->missing; |
2464 | super->missing = dl; | |
2465 | } | |
2466 | ||
2467 | return 0; | |
2468 | } | |
2469 | ||
a2b97981 DW |
2470 | static struct intel_disk *disk_list_get(__u8 *serial, struct intel_disk *disk_list) |
2471 | { | |
2472 | struct intel_disk *idisk = disk_list; | |
2473 | ||
2474 | while (idisk) { | |
2475 | if (serialcmp(idisk->disk.serial, serial) == 0) | |
2476 | break; | |
2477 | idisk = idisk->next; | |
2478 | } | |
2479 | ||
2480 | return idisk; | |
2481 | } | |
2482 | ||
2483 | static int __prep_thunderdome(struct intel_super **table, int tbl_size, | |
2484 | struct intel_super *super, | |
2485 | struct intel_disk **disk_list) | |
2486 | { | |
2487 | struct imsm_disk *d = &super->disks->disk; | |
2488 | struct imsm_super *mpb = super->anchor; | |
2489 | int i, j; | |
2490 | ||
2491 | for (i = 0; i < tbl_size; i++) { | |
2492 | struct imsm_super *tbl_mpb = table[i]->anchor; | |
2493 | struct imsm_disk *tbl_d = &table[i]->disks->disk; | |
2494 | ||
2495 | if (tbl_mpb->family_num == mpb->family_num) { | |
2496 | if (tbl_mpb->check_sum == mpb->check_sum) { | |
2497 | dprintf("%s: mpb from %d:%d matches %d:%d\n", | |
2498 | __func__, super->disks->major, | |
2499 | super->disks->minor, | |
2500 | table[i]->disks->major, | |
2501 | table[i]->disks->minor); | |
2502 | break; | |
2503 | } | |
2504 | ||
2505 | if (((is_configured(d) && !is_configured(tbl_d)) || | |
2506 | is_configured(d) == is_configured(tbl_d)) && | |
2507 | tbl_mpb->generation_num < mpb->generation_num) { | |
2508 | /* current version of the mpb is a | |
2509 | * better candidate than the one in | |
2510 | * super_table, but copy over "cross | |
2511 | * generational" status | |
2512 | */ | |
2513 | struct intel_disk *idisk; | |
2514 | ||
2515 | dprintf("%s: mpb from %d:%d replaces %d:%d\n", | |
2516 | __func__, super->disks->major, | |
2517 | super->disks->minor, | |
2518 | table[i]->disks->major, | |
2519 | table[i]->disks->minor); | |
2520 | ||
2521 | idisk = disk_list_get(tbl_d->serial, *disk_list); | |
2522 | if (idisk && is_failed(&idisk->disk)) | |
2523 | tbl_d->status |= FAILED_DISK; | |
2524 | break; | |
2525 | } else { | |
2526 | struct intel_disk *idisk; | |
2527 | struct imsm_disk *disk; | |
2528 | ||
2529 | /* tbl_mpb is more up to date, but copy | |
2530 | * over cross generational status before | |
2531 | * returning | |
2532 | */ | |
2533 | disk = __serial_to_disk(d->serial, mpb, NULL); | |
2534 | if (disk && is_failed(disk)) | |
2535 | d->status |= FAILED_DISK; | |
2536 | ||
2537 | idisk = disk_list_get(d->serial, *disk_list); | |
2538 | if (idisk) { | |
2539 | idisk->owner = i; | |
2540 | if (disk && is_configured(disk)) | |
2541 | idisk->disk.status |= CONFIGURED_DISK; | |
2542 | } | |
2543 | ||
2544 | dprintf("%s: mpb from %d:%d prefer %d:%d\n", | |
2545 | __func__, super->disks->major, | |
2546 | super->disks->minor, | |
2547 | table[i]->disks->major, | |
2548 | table[i]->disks->minor); | |
2549 | ||
2550 | return tbl_size; | |
2551 | } | |
2552 | } | |
2553 | } | |
2554 | ||
2555 | if (i >= tbl_size) | |
2556 | table[tbl_size++] = super; | |
2557 | else | |
2558 | table[i] = super; | |
2559 | ||
2560 | /* update/extend the merged list of imsm_disk records */ | |
2561 | for (j = 0; j < mpb->num_disks; j++) { | |
2562 | struct imsm_disk *disk = __get_imsm_disk(mpb, j); | |
2563 | struct intel_disk *idisk; | |
2564 | ||
2565 | idisk = disk_list_get(disk->serial, *disk_list); | |
2566 | if (idisk) { | |
2567 | idisk->disk.status |= disk->status; | |
2568 | if (is_configured(&idisk->disk) || | |
2569 | is_failed(&idisk->disk)) | |
2570 | idisk->disk.status &= ~(SPARE_DISK); | |
2571 | } else { | |
2572 | idisk = calloc(1, sizeof(*idisk)); | |
2573 | if (!idisk) | |
2574 | return -1; | |
2575 | idisk->owner = IMSM_UNKNOWN_OWNER; | |
2576 | idisk->disk = *disk; | |
2577 | idisk->next = *disk_list; | |
2578 | *disk_list = idisk; | |
2579 | } | |
2580 | ||
2581 | if (serialcmp(idisk->disk.serial, d->serial) == 0) | |
2582 | idisk->owner = i; | |
2583 | } | |
2584 | ||
2585 | return tbl_size; | |
2586 | } | |
2587 | ||
2588 | static struct intel_super * | |
2589 | validate_members(struct intel_super *super, struct intel_disk *disk_list, | |
2590 | const int owner) | |
2591 | { | |
2592 | struct imsm_super *mpb = super->anchor; | |
2593 | int ok_count = 0; | |
2594 | int i; | |
2595 | ||
2596 | for (i = 0; i < mpb->num_disks; i++) { | |
2597 | struct imsm_disk *disk = __get_imsm_disk(mpb, i); | |
2598 | struct intel_disk *idisk; | |
2599 | ||
2600 | idisk = disk_list_get(disk->serial, disk_list); | |
2601 | if (idisk) { | |
2602 | if (idisk->owner == owner || | |
2603 | idisk->owner == IMSM_UNKNOWN_OWNER) | |
2604 | ok_count++; | |
2605 | else | |
2606 | dprintf("%s: '%.16s' owner %d != %d\n", | |
2607 | __func__, disk->serial, idisk->owner, | |
2608 | owner); | |
2609 | } else { | |
2610 | dprintf("%s: unknown disk %x [%d]: %.16s\n", | |
2611 | __func__, __le32_to_cpu(mpb->family_num), i, | |
2612 | disk->serial); | |
2613 | break; | |
2614 | } | |
2615 | } | |
2616 | ||
2617 | if (ok_count == mpb->num_disks) | |
2618 | return super; | |
2619 | return NULL; | |
2620 | } | |
2621 | ||
2622 | static void show_conflicts(__u32 family_num, struct intel_super *super_list) | |
2623 | { | |
2624 | struct intel_super *s; | |
2625 | ||
2626 | for (s = super_list; s; s = s->next) { | |
2627 | if (family_num != s->anchor->family_num) | |
2628 | continue; | |
2629 | fprintf(stderr, "Conflict, offlining family %#x on '%s'\n", | |
2630 | __le32_to_cpu(family_num), s->disks->devname); | |
2631 | } | |
2632 | } | |
2633 | ||
2634 | static struct intel_super * | |
2635 | imsm_thunderdome(struct intel_super **super_list, int len) | |
2636 | { | |
2637 | struct intel_super *super_table[len]; | |
2638 | struct intel_disk *disk_list = NULL; | |
2639 | struct intel_super *champion, *spare; | |
2640 | struct intel_super *s, **del; | |
2641 | int tbl_size = 0; | |
2642 | int conflict; | |
2643 | int i; | |
2644 | ||
2645 | memset(super_table, 0, sizeof(super_table)); | |
2646 | for (s = *super_list; s; s = s->next) | |
2647 | tbl_size = __prep_thunderdome(super_table, tbl_size, s, &disk_list); | |
2648 | ||
2649 | for (i = 0; i < tbl_size; i++) { | |
2650 | struct imsm_disk *d; | |
2651 | struct intel_disk *idisk; | |
2652 | struct imsm_super *mpb = super_table[i]->anchor; | |
2653 | ||
2654 | s = super_table[i]; | |
2655 | d = &s->disks->disk; | |
2656 | ||
2657 | /* 'd' must appear in merged disk list for its | |
2658 | * configuration to be valid | |
2659 | */ | |
2660 | idisk = disk_list_get(d->serial, disk_list); | |
2661 | if (idisk && idisk->owner == i) | |
2662 | s = validate_members(s, disk_list, i); | |
2663 | else | |
2664 | s = NULL; | |
2665 | ||
2666 | if (!s) | |
2667 | dprintf("%s: marking family: %#x from %d:%d offline\n", | |
2668 | __func__, mpb->family_num, | |
2669 | super_table[i]->disks->major, | |
2670 | super_table[i]->disks->minor); | |
2671 | super_table[i] = s; | |
2672 | } | |
2673 | ||
2674 | /* This is where the mdadm implementation differs from the Windows | |
2675 | * driver which has no strict concept of a container. We can only | |
2676 | * assemble one family from a container, so when returning a prodigal | |
2677 | * array member to this system the code will not be able to disambiguate | |
2678 | * the container contents that should be assembled ("foreign" versus | |
2679 | * "local"). It requires user intervention to set the orig_family_num | |
2680 | * to a new value to establish a new container. The Windows driver in | |
2681 | * this situation fixes up the volume name in place and manages the | |
2682 | * foreign array as an independent entity. | |
2683 | */ | |
2684 | s = NULL; | |
2685 | spare = NULL; | |
2686 | conflict = 0; | |
2687 | for (i = 0; i < tbl_size; i++) { | |
2688 | struct intel_super *tbl_ent = super_table[i]; | |
2689 | int is_spare = 0; | |
2690 | ||
2691 | if (!tbl_ent) | |
2692 | continue; | |
2693 | ||
2694 | if (tbl_ent->anchor->num_raid_devs == 0) { | |
2695 | spare = tbl_ent; | |
2696 | is_spare = 1; | |
2697 | } | |
2698 | ||
2699 | if (s && !is_spare) { | |
2700 | show_conflicts(tbl_ent->anchor->family_num, *super_list); | |
2701 | conflict++; | |
2702 | } else if (!s && !is_spare) | |
2703 | s = tbl_ent; | |
2704 | } | |
2705 | ||
2706 | if (!s) | |
2707 | s = spare; | |
2708 | if (!s) { | |
2709 | champion = NULL; | |
2710 | goto out; | |
2711 | } | |
2712 | champion = s; | |
2713 | ||
2714 | if (conflict) | |
2715 | fprintf(stderr, "Chose family %#x on '%s', " | |
2716 | "assemble conflicts to new container with '--update=uuid'\n", | |
2717 | __le32_to_cpu(s->anchor->family_num), s->disks->devname); | |
2718 | ||
2719 | /* collect all dl's onto 'champion', and update them to | |
2720 | * champion's version of the status | |
2721 | */ | |
2722 | for (s = *super_list; s; s = s->next) { | |
2723 | struct imsm_super *mpb = champion->anchor; | |
2724 | struct dl *dl = s->disks; | |
2725 | ||
2726 | if (s == champion) | |
2727 | continue; | |
2728 | ||
2729 | for (i = 0; i < mpb->num_disks; i++) { | |
2730 | struct imsm_disk *disk; | |
2731 | ||
2732 | disk = __serial_to_disk(dl->serial, mpb, &dl->index); | |
2733 | if (disk) { | |
2734 | dl->disk = *disk; | |
2735 | /* only set index on disks that are a member of | |
2736 | * a populated contianer, i.e. one with | |
2737 | * raid_devs | |
2738 | */ | |
2739 | if (is_failed(&dl->disk)) | |
2740 | dl->index = -2; | |
2741 | else if (is_spare(&dl->disk)) | |
2742 | dl->index = -1; | |
2743 | break; | |
2744 | } | |
2745 | } | |
2746 | ||
2747 | if (i >= mpb->num_disks) { | |
2748 | struct intel_disk *idisk; | |
2749 | ||
2750 | idisk = disk_list_get(dl->serial, disk_list); | |
ecf408e9 | 2751 | if (idisk && is_spare(&idisk->disk) && |
a2b97981 DW |
2752 | !is_failed(&idisk->disk) && !is_configured(&idisk->disk)) |
2753 | dl->index = -1; | |
2754 | else { | |
2755 | dl->index = -2; | |
2756 | continue; | |
2757 | } | |
2758 | } | |
2759 | ||
2760 | dl->next = champion->disks; | |
2761 | champion->disks = dl; | |
2762 | s->disks = NULL; | |
2763 | } | |
2764 | ||
2765 | /* delete 'champion' from super_list */ | |
2766 | for (del = super_list; *del; ) { | |
2767 | if (*del == champion) { | |
2768 | *del = (*del)->next; | |
2769 | break; | |
2770 | } else | |
2771 | del = &(*del)->next; | |
2772 | } | |
2773 | champion->next = NULL; | |
2774 | ||
2775 | out: | |
2776 | while (disk_list) { | |
2777 | struct intel_disk *idisk = disk_list; | |
2778 | ||
2779 | disk_list = disk_list->next; | |
2780 | free(idisk); | |
2781 | } | |
2782 | ||
2783 | return champion; | |
2784 | } | |
2785 | ||
cdddbdbc | 2786 | static int load_super_imsm_all(struct supertype *st, int fd, void **sbp, |
e1902a7b | 2787 | char *devname) |
cdddbdbc DW |
2788 | { |
2789 | struct mdinfo *sra; | |
a2b97981 DW |
2790 | struct intel_super *super_list = NULL; |
2791 | struct intel_super *super = NULL; | |
db575f3b | 2792 | int devnum = fd2devnum(fd); |
a2b97981 | 2793 | struct mdinfo *sd; |
db575f3b | 2794 | int retry; |
a2b97981 DW |
2795 | int err = 0; |
2796 | int i; | |
dab4a513 DW |
2797 | |
2798 | /* check if 'fd' an opened container */ | |
b526e52d | 2799 | sra = sysfs_read(fd, 0, GET_LEVEL|GET_VERSION|GET_DEVS|GET_STATE); |
cdddbdbc DW |
2800 | if (!sra) |
2801 | return 1; | |
2802 | ||
2803 | if (sra->array.major_version != -1 || | |
2804 | sra->array.minor_version != -2 || | |
1602d52c AW |
2805 | strcmp(sra->text_version, "imsm") != 0) { |
2806 | err = 1; | |
2807 | goto error; | |
2808 | } | |
a2b97981 DW |
2809 | /* load all mpbs */ |
2810 | for (sd = sra->devs, i = 0; sd; sd = sd->next, i++) { | |
49133e57 | 2811 | struct intel_super *s = alloc_super(); |
7a6ecd55 | 2812 | char nm[32]; |
a2b97981 DW |
2813 | int dfd; |
2814 | ||
2815 | err = 1; | |
2816 | if (!s) | |
2817 | goto error; | |
2818 | s->next = super_list; | |
2819 | super_list = s; | |
cdddbdbc | 2820 | |
a2b97981 | 2821 | err = 2; |
cdddbdbc | 2822 | sprintf(nm, "%d:%d", sd->disk.major, sd->disk.minor); |
e1902a7b | 2823 | dfd = dev_open(nm, O_RDWR); |
a2b97981 DW |
2824 | if (dfd < 0) |
2825 | goto error; | |
2826 | ||
e1902a7b | 2827 | err = load_and_parse_mpb(dfd, s, NULL, 1); |
db575f3b DW |
2828 | |
2829 | /* retry the load if we might have raced against mdmon */ | |
a2b97981 | 2830 | if (err == 3 && mdmon_running(devnum)) |
db575f3b DW |
2831 | for (retry = 0; retry < 3; retry++) { |
2832 | usleep(3000); | |
e1902a7b | 2833 | err = load_and_parse_mpb(dfd, s, NULL, 1); |
a2b97981 | 2834 | if (err != 3) |
db575f3b DW |
2835 | break; |
2836 | } | |
a2b97981 DW |
2837 | if (err) |
2838 | goto error; | |
cdddbdbc DW |
2839 | } |
2840 | ||
a2b97981 DW |
2841 | /* all mpbs enter, maybe one leaves */ |
2842 | super = imsm_thunderdome(&super_list, i); | |
2843 | if (!super) { | |
2844 | err = 1; | |
2845 | goto error; | |
cdddbdbc DW |
2846 | } |
2847 | ||
47ee5a45 DW |
2848 | if (find_missing(super) != 0) { |
2849 | free_imsm(super); | |
a2b97981 DW |
2850 | err = 2; |
2851 | goto error; | |
47ee5a45 | 2852 | } |
a2b97981 DW |
2853 | err = 0; |
2854 | ||
2855 | error: | |
2856 | while (super_list) { | |
2857 | struct intel_super *s = super_list; | |
2858 | ||
2859 | super_list = super_list->next; | |
2860 | free_imsm(s); | |
2861 | } | |
1602d52c | 2862 | sysfs_free(sra); |
a2b97981 DW |
2863 | |
2864 | if (err) | |
2865 | return err; | |
f7e7067b | 2866 | |
cdddbdbc | 2867 | *sbp = super; |
db575f3b | 2868 | st->container_dev = devnum; |
a2b97981 | 2869 | if (err == 0 && st->ss == NULL) { |
bf5a934a | 2870 | st->ss = &super_imsm; |
cdddbdbc DW |
2871 | st->minor_version = 0; |
2872 | st->max_devs = IMSM_MAX_DEVICES; | |
2873 | } | |
cdddbdbc DW |
2874 | return 0; |
2875 | } | |
2b959fbf N |
2876 | |
2877 | static int load_container_imsm(struct supertype *st, int fd, char *devname) | |
2878 | { | |
2879 | return load_super_imsm_all(st, fd, &st->sb, devname); | |
2880 | } | |
cdddbdbc DW |
2881 | #endif |
2882 | ||
2883 | static int load_super_imsm(struct supertype *st, int fd, char *devname) | |
2884 | { | |
2885 | struct intel_super *super; | |
2886 | int rv; | |
2887 | ||
2888 | #ifndef MDASSEMBLE | |
e1902a7b | 2889 | if (load_super_imsm_all(st, fd, &st->sb, devname) == 0) |
cdddbdbc DW |
2890 | return 0; |
2891 | #endif | |
2892 | ||
691c6ee1 N |
2893 | if (test_partition(fd)) |
2894 | /* IMSM not allowed on partitions */ | |
2895 | return 1; | |
2896 | ||
37424f13 DW |
2897 | free_super_imsm(st); |
2898 | ||
49133e57 | 2899 | super = alloc_super(); |
cdddbdbc DW |
2900 | if (!super) { |
2901 | fprintf(stderr, | |
2902 | Name ": malloc of %zu failed.\n", | |
2903 | sizeof(*super)); | |
2904 | return 1; | |
2905 | } | |
2906 | ||
a2b97981 | 2907 | rv = load_and_parse_mpb(fd, super, devname, 0); |
cdddbdbc DW |
2908 | |
2909 | if (rv) { | |
2910 | if (devname) | |
2911 | fprintf(stderr, | |
2912 | Name ": Failed to load all information " | |
2913 | "sections on %s\n", devname); | |
2914 | free_imsm(super); | |
2915 | return rv; | |
2916 | } | |
2917 | ||
2918 | st->sb = super; | |
2919 | if (st->ss == NULL) { | |
2920 | st->ss = &super_imsm; | |
2921 | st->minor_version = 0; | |
2922 | st->max_devs = IMSM_MAX_DEVICES; | |
2923 | } | |
cdddbdbc DW |
2924 | return 0; |
2925 | } | |
2926 | ||
ef6ffade DW |
2927 | static __u16 info_to_blocks_per_strip(mdu_array_info_t *info) |
2928 | { | |
2929 | if (info->level == 1) | |
2930 | return 128; | |
2931 | return info->chunk_size >> 9; | |
2932 | } | |
2933 | ||
ff596308 | 2934 | static __u32 info_to_num_data_stripes(mdu_array_info_t *info, int num_domains) |
ef6ffade DW |
2935 | { |
2936 | __u32 num_stripes; | |
2937 | ||
2938 | num_stripes = (info->size * 2) / info_to_blocks_per_strip(info); | |
ff596308 | 2939 | num_stripes /= num_domains; |
ef6ffade DW |
2940 | |
2941 | return num_stripes; | |
2942 | } | |
2943 | ||
fcfd9599 DW |
2944 | static __u32 info_to_blocks_per_member(mdu_array_info_t *info) |
2945 | { | |
4025c288 DW |
2946 | if (info->level == 1) |
2947 | return info->size * 2; | |
2948 | else | |
2949 | return (info->size * 2) & ~(info_to_blocks_per_strip(info) - 1); | |
fcfd9599 DW |
2950 | } |
2951 | ||
4d1313e9 DW |
2952 | static void imsm_update_version_info(struct intel_super *super) |
2953 | { | |
2954 | /* update the version and attributes */ | |
2955 | struct imsm_super *mpb = super->anchor; | |
2956 | char *version; | |
2957 | struct imsm_dev *dev; | |
2958 | struct imsm_map *map; | |
2959 | int i; | |
2960 | ||
2961 | for (i = 0; i < mpb->num_raid_devs; i++) { | |
2962 | dev = get_imsm_dev(super, i); | |
2963 | map = get_imsm_map(dev, 0); | |
2964 | if (__le32_to_cpu(dev->size_high) > 0) | |
2965 | mpb->attributes |= MPB_ATTRIB_2TB; | |
2966 | ||
2967 | /* FIXME detect when an array spans a port multiplier */ | |
2968 | #if 0 | |
2969 | mpb->attributes |= MPB_ATTRIB_PM; | |
2970 | #endif | |
2971 | ||
2972 | if (mpb->num_raid_devs > 1 || | |
2973 | mpb->attributes != MPB_ATTRIB_CHECKSUM_VERIFY) { | |
2974 | version = MPB_VERSION_ATTRIBS; | |
2975 | switch (get_imsm_raid_level(map)) { | |
2976 | case 0: mpb->attributes |= MPB_ATTRIB_RAID0; break; | |
2977 | case 1: mpb->attributes |= MPB_ATTRIB_RAID1; break; | |
2978 | case 10: mpb->attributes |= MPB_ATTRIB_RAID10; break; | |
2979 | case 5: mpb->attributes |= MPB_ATTRIB_RAID5; break; | |
2980 | } | |
2981 | } else { | |
2982 | if (map->num_members >= 5) | |
2983 | version = MPB_VERSION_5OR6_DISK_ARRAY; | |
2984 | else if (dev->status == DEV_CLONE_N_GO) | |
2985 | version = MPB_VERSION_CNG; | |
2986 | else if (get_imsm_raid_level(map) == 5) | |
2987 | version = MPB_VERSION_RAID5; | |
2988 | else if (map->num_members >= 3) | |
2989 | version = MPB_VERSION_3OR4_DISK_ARRAY; | |
2990 | else if (get_imsm_raid_level(map) == 1) | |
2991 | version = MPB_VERSION_RAID1; | |
2992 | else | |
2993 | version = MPB_VERSION_RAID0; | |
2994 | } | |
2995 | strcpy(((char *) mpb->sig) + strlen(MPB_SIGNATURE), version); | |
2996 | } | |
2997 | } | |
2998 | ||
aa534678 DW |
2999 | static int check_name(struct intel_super *super, char *name, int quiet) |
3000 | { | |
3001 | struct imsm_super *mpb = super->anchor; | |
3002 | char *reason = NULL; | |
3003 | int i; | |
3004 | ||
3005 | if (strlen(name) > MAX_RAID_SERIAL_LEN) | |
3006 | reason = "must be 16 characters or less"; | |
3007 | ||
3008 | for (i = 0; i < mpb->num_raid_devs; i++) { | |
3009 | struct imsm_dev *dev = get_imsm_dev(super, i); | |
3010 | ||
3011 | if (strncmp((char *) dev->volume, name, MAX_RAID_SERIAL_LEN) == 0) { | |
3012 | reason = "already exists"; | |
3013 | break; | |
3014 | } | |
3015 | } | |
3016 | ||
3017 | if (reason && !quiet) | |
3018 | fprintf(stderr, Name ": imsm volume name %s\n", reason); | |
3019 | ||
3020 | return !reason; | |
3021 | } | |
3022 | ||
8b353278 DW |
3023 | static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info, |
3024 | unsigned long long size, char *name, | |
3025 | char *homehost, int *uuid) | |
cdddbdbc | 3026 | { |
c2c087e6 DW |
3027 | /* We are creating a volume inside a pre-existing container. |
3028 | * so st->sb is already set. | |
3029 | */ | |
3030 | struct intel_super *super = st->sb; | |
949c47a0 | 3031 | struct imsm_super *mpb = super->anchor; |
ba2de7ba | 3032 | struct intel_dev *dv; |
c2c087e6 DW |
3033 | struct imsm_dev *dev; |
3034 | struct imsm_vol *vol; | |
3035 | struct imsm_map *map; | |
3036 | int idx = mpb->num_raid_devs; | |
3037 | int i; | |
3038 | unsigned long long array_blocks; | |
2c092cad | 3039 | size_t size_old, size_new; |
ff596308 | 3040 | __u32 num_data_stripes; |
cdddbdbc | 3041 | |
88c32bb1 | 3042 | if (super->orom && mpb->num_raid_devs >= super->orom->vpa) { |
c2c087e6 | 3043 | fprintf(stderr, Name": This imsm-container already has the " |
88c32bb1 | 3044 | "maximum of %d volumes\n", super->orom->vpa); |
c2c087e6 DW |
3045 | return 0; |
3046 | } | |
3047 | ||
2c092cad DW |
3048 | /* ensure the mpb is large enough for the new data */ |
3049 | size_old = __le32_to_cpu(mpb->mpb_size); | |
3050 | size_new = disks_to_mpb_size(info->nr_disks); | |
3051 | if (size_new > size_old) { | |
3052 | void *mpb_new; | |
3053 | size_t size_round = ROUND_UP(size_new, 512); | |
3054 | ||
3055 | if (posix_memalign(&mpb_new, 512, size_round) != 0) { | |
3056 | fprintf(stderr, Name": could not allocate new mpb\n"); | |
3057 | return 0; | |
3058 | } | |
3059 | memcpy(mpb_new, mpb, size_old); | |
3060 | free(mpb); | |
3061 | mpb = mpb_new; | |
949c47a0 | 3062 | super->anchor = mpb_new; |
2c092cad DW |
3063 | mpb->mpb_size = __cpu_to_le32(size_new); |
3064 | memset(mpb_new + size_old, 0, size_round - size_old); | |
3065 | } | |
bf5a934a | 3066 | super->current_vol = idx; |
d23fe947 DW |
3067 | /* when creating the first raid device in this container set num_disks |
3068 | * to zero, i.e. delete this spare and add raid member devices in | |
3069 | * add_to_super_imsm_volume() | |
3070 | */ | |
3071 | if (super->current_vol == 0) | |
3072 | mpb->num_disks = 0; | |
5a038140 | 3073 | |
aa534678 DW |
3074 | if (!check_name(super, name, 0)) |
3075 | return 0; | |
ba2de7ba DW |
3076 | dv = malloc(sizeof(*dv)); |
3077 | if (!dv) { | |
3078 | fprintf(stderr, Name ": failed to allocate device list entry\n"); | |
3079 | return 0; | |
3080 | } | |
949c47a0 DW |
3081 | dev = malloc(sizeof(*dev) + sizeof(__u32) * (info->raid_disks - 1)); |
3082 | if (!dev) { | |
ba2de7ba | 3083 | free(dv); |
949c47a0 DW |
3084 | fprintf(stderr, Name": could not allocate raid device\n"); |
3085 | return 0; | |
3086 | } | |
c2c087e6 | 3087 | strncpy((char *) dev->volume, name, MAX_RAID_SERIAL_LEN); |
03bcbc65 DW |
3088 | if (info->level == 1) |
3089 | array_blocks = info_to_blocks_per_member(info); | |
3090 | else | |
3091 | array_blocks = calc_array_size(info->level, info->raid_disks, | |
3092 | info->layout, info->chunk_size, | |
3093 | info->size*2); | |
979d38be DW |
3094 | /* round array size down to closest MB */ |
3095 | array_blocks = (array_blocks >> SECT_PER_MB_SHIFT) << SECT_PER_MB_SHIFT; | |
3096 | ||
c2c087e6 DW |
3097 | dev->size_low = __cpu_to_le32((__u32) array_blocks); |
3098 | dev->size_high = __cpu_to_le32((__u32) (array_blocks >> 32)); | |
3099 | dev->status = __cpu_to_le32(0); | |
3100 | dev->reserved_blocks = __cpu_to_le32(0); | |
3101 | vol = &dev->vol; | |
3102 | vol->migr_state = 0; | |
1484e727 | 3103 | set_migr_type(dev, MIGR_INIT); |
c2c087e6 | 3104 | vol->dirty = 0; |
f8f603f1 | 3105 | vol->curr_migr_unit = 0; |
a965f303 | 3106 | map = get_imsm_map(dev, 0); |
0dcecb2e | 3107 | map->pba_of_lba0 = __cpu_to_le32(super->create_offset); |
fcfd9599 | 3108 | map->blocks_per_member = __cpu_to_le32(info_to_blocks_per_member(info)); |
ef6ffade | 3109 | map->blocks_per_strip = __cpu_to_le16(info_to_blocks_per_strip(info)); |
0556e1a2 | 3110 | map->failed_disk_num = ~0; |
c2c087e6 DW |
3111 | map->map_state = info->level ? IMSM_T_STATE_UNINITIALIZED : |
3112 | IMSM_T_STATE_NORMAL; | |
252d23c0 | 3113 | map->ddf = 1; |
ef6ffade DW |
3114 | |
3115 | if (info->level == 1 && info->raid_disks > 2) { | |
38950822 AW |
3116 | free(dev); |
3117 | free(dv); | |
ef6ffade DW |
3118 | fprintf(stderr, Name": imsm does not support more than 2 disks" |
3119 | "in a raid1 volume\n"); | |
3120 | return 0; | |
3121 | } | |
81062a36 DW |
3122 | |
3123 | map->raid_level = info->level; | |
4d1313e9 | 3124 | if (info->level == 10) { |
c2c087e6 | 3125 | map->raid_level = 1; |
4d1313e9 | 3126 | map->num_domains = info->raid_disks / 2; |
81062a36 DW |
3127 | } else if (info->level == 1) |
3128 | map->num_domains = info->raid_disks; | |
3129 | else | |
ff596308 | 3130 | map->num_domains = 1; |
81062a36 | 3131 | |
ff596308 DW |
3132 | num_data_stripes = info_to_num_data_stripes(info, map->num_domains); |
3133 | map->num_data_stripes = __cpu_to_le32(num_data_stripes); | |
ef6ffade | 3134 | |
c2c087e6 DW |
3135 | map->num_members = info->raid_disks; |
3136 | for (i = 0; i < map->num_members; i++) { | |
3137 | /* initialized in add_to_super */ | |
4eb26970 | 3138 | set_imsm_ord_tbl_ent(map, i, IMSM_ORD_REBUILD); |
c2c087e6 | 3139 | } |
949c47a0 | 3140 | mpb->num_raid_devs++; |
ba2de7ba DW |
3141 | |
3142 | dv->dev = dev; | |
3143 | dv->index = super->current_vol; | |
3144 | dv->next = super->devlist; | |
3145 | super->devlist = dv; | |
c2c087e6 | 3146 | |
4d1313e9 DW |
3147 | imsm_update_version_info(super); |
3148 | ||
c2c087e6 | 3149 | return 1; |
cdddbdbc DW |
3150 | } |
3151 | ||
bf5a934a DW |
3152 | static int init_super_imsm(struct supertype *st, mdu_array_info_t *info, |
3153 | unsigned long long size, char *name, | |
3154 | char *homehost, int *uuid) | |
3155 | { | |
3156 | /* This is primarily called by Create when creating a new array. | |
3157 | * We will then get add_to_super called for each component, and then | |
3158 | * write_init_super called to write it out to each device. | |
3159 | * For IMSM, Create can create on fresh devices or on a pre-existing | |
3160 | * array. | |
3161 | * To create on a pre-existing array a different method will be called. | |
3162 | * This one is just for fresh drives. | |
3163 | */ | |
3164 | struct intel_super *super; | |
3165 | struct imsm_super *mpb; | |
3166 | size_t mpb_size; | |
4d1313e9 | 3167 | char *version; |
bf5a934a | 3168 | |
bf5a934a | 3169 | if (st->sb) |
e683ca88 DW |
3170 | return init_super_imsm_volume(st, info, size, name, homehost, uuid); |
3171 | ||
3172 | if (info) | |
3173 | mpb_size = disks_to_mpb_size(info->nr_disks); | |
3174 | else | |
3175 | mpb_size = 512; | |
bf5a934a | 3176 | |
49133e57 | 3177 | super = alloc_super(); |
e683ca88 | 3178 | if (super && posix_memalign(&super->buf, 512, mpb_size) != 0) { |
bf5a934a | 3179 | free(super); |
e683ca88 DW |
3180 | super = NULL; |
3181 | } | |
3182 | if (!super) { | |
3183 | fprintf(stderr, Name | |
3184 | ": %s could not allocate superblock\n", __func__); | |
bf5a934a DW |
3185 | return 0; |
3186 | } | |
e683ca88 | 3187 | memset(super->buf, 0, mpb_size); |
ef649044 | 3188 | mpb = super->buf; |
e683ca88 DW |
3189 | mpb->mpb_size = __cpu_to_le32(mpb_size); |
3190 | st->sb = super; | |
3191 | ||
3192 | if (info == NULL) { | |
3193 | /* zeroing superblock */ | |
3194 | return 0; | |
3195 | } | |
bf5a934a | 3196 | |
4d1313e9 DW |
3197 | mpb->attributes = MPB_ATTRIB_CHECKSUM_VERIFY; |
3198 | ||
3199 | version = (char *) mpb->sig; | |
3200 | strcpy(version, MPB_SIGNATURE); | |
3201 | version += strlen(MPB_SIGNATURE); | |
3202 | strcpy(version, MPB_VERSION_RAID0); | |
bf5a934a | 3203 | |
bf5a934a DW |
3204 | return 1; |
3205 | } | |
3206 | ||
0e600426 | 3207 | #ifndef MDASSEMBLE |
f20c3968 | 3208 | static int add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk, |
bf5a934a DW |
3209 | int fd, char *devname) |
3210 | { | |
3211 | struct intel_super *super = st->sb; | |
d23fe947 | 3212 | struct imsm_super *mpb = super->anchor; |
bf5a934a DW |
3213 | struct dl *dl; |
3214 | struct imsm_dev *dev; | |
3215 | struct imsm_map *map; | |
4eb26970 | 3216 | int slot; |
bf5a934a | 3217 | |
949c47a0 | 3218 | dev = get_imsm_dev(super, super->current_vol); |
a965f303 | 3219 | map = get_imsm_map(dev, 0); |
bf5a934a | 3220 | |
208933a7 N |
3221 | if (! (dk->state & (1<<MD_DISK_SYNC))) { |
3222 | fprintf(stderr, Name ": %s: Cannot add spare devices to IMSM volume\n", | |
3223 | devname); | |
3224 | return 1; | |
3225 | } | |
3226 | ||
efb30e7f DW |
3227 | if (fd == -1) { |
3228 | /* we're doing autolayout so grab the pre-marked (in | |
3229 | * validate_geometry) raid_disk | |
3230 | */ | |
3231 | for (dl = super->disks; dl; dl = dl->next) | |
3232 | if (dl->raiddisk == dk->raid_disk) | |
3233 | break; | |
3234 | } else { | |
3235 | for (dl = super->disks; dl ; dl = dl->next) | |
3236 | if (dl->major == dk->major && | |
3237 | dl->minor == dk->minor) | |
3238 | break; | |
3239 | } | |
d23fe947 | 3240 | |
208933a7 N |
3241 | if (!dl) { |
3242 | fprintf(stderr, Name ": %s is not a member of the same container\n", devname); | |
f20c3968 | 3243 | return 1; |
208933a7 | 3244 | } |
bf5a934a | 3245 | |
d23fe947 DW |
3246 | /* add a pristine spare to the metadata */ |
3247 | if (dl->index < 0) { | |
3248 | dl->index = super->anchor->num_disks; | |
3249 | super->anchor->num_disks++; | |
3250 | } | |
4eb26970 DW |
3251 | /* Check the device has not already been added */ |
3252 | slot = get_imsm_disk_slot(map, dl->index); | |
3253 | if (slot >= 0 && | |
3254 | (get_imsm_ord_tbl_ent(dev, slot) & IMSM_ORD_REBUILD) == 0) { | |
3255 | fprintf(stderr, Name ": %s has been included in this array twice\n", | |
3256 | devname); | |
3257 | return 1; | |
3258 | } | |
be73972f | 3259 | set_imsm_ord_tbl_ent(map, dk->number, dl->index); |
ee5aad5a | 3260 | dl->disk.status = CONFIGURED_DISK; |
d23fe947 DW |
3261 | |
3262 | /* if we are creating the first raid device update the family number */ | |
3263 | if (super->current_vol == 0) { | |
3264 | __u32 sum; | |
3265 | struct imsm_dev *_dev = __get_imsm_dev(mpb, 0); | |
3266 | struct imsm_disk *_disk = __get_imsm_disk(mpb, dl->index); | |
3267 | ||
791b666a AW |
3268 | if (!_dev || !_disk) { |
3269 | fprintf(stderr, Name ": BUG mpb setup error\n"); | |
3270 | return 1; | |
3271 | } | |
d23fe947 DW |
3272 | *_dev = *dev; |
3273 | *_disk = dl->disk; | |
148acb7b DW |
3274 | sum = random32(); |
3275 | sum += __gen_imsm_checksum(mpb); | |
d23fe947 | 3276 | mpb->family_num = __cpu_to_le32(sum); |
148acb7b | 3277 | mpb->orig_family_num = mpb->family_num; |
d23fe947 | 3278 | } |
f20c3968 DW |
3279 | |
3280 | return 0; | |
bf5a934a DW |
3281 | } |
3282 | ||
f20c3968 | 3283 | static int add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk, |
cdddbdbc DW |
3284 | int fd, char *devname) |
3285 | { | |
c2c087e6 | 3286 | struct intel_super *super = st->sb; |
c2c087e6 DW |
3287 | struct dl *dd; |
3288 | unsigned long long size; | |
f2f27e63 | 3289 | __u32 id; |
c2c087e6 DW |
3290 | int rv; |
3291 | struct stat stb; | |
3292 | ||
88c32bb1 DW |
3293 | /* if we are on an RAID enabled platform check that the disk is |
3294 | * attached to the raid controller | |
3295 | */ | |
3296 | if (super->hba && !disk_attached_to_hba(fd, super->hba)) { | |
3297 | fprintf(stderr, | |
3298 | Name ": %s is not attached to the raid controller: %s\n", | |
3299 | devname ? : "disk", super->hba); | |
3300 | return 1; | |
3301 | } | |
3302 | ||
f20c3968 DW |
3303 | if (super->current_vol >= 0) |
3304 | return add_to_super_imsm_volume(st, dk, fd, devname); | |
bf5a934a | 3305 | |
c2c087e6 DW |
3306 | fstat(fd, &stb); |
3307 | dd = malloc(sizeof(*dd)); | |
b9f594fe | 3308 | if (!dd) { |
c2c087e6 DW |
3309 | fprintf(stderr, |
3310 | Name ": malloc failed %s:%d.\n", __func__, __LINE__); | |
f20c3968 | 3311 | return 1; |
c2c087e6 DW |
3312 | } |
3313 | memset(dd, 0, sizeof(*dd)); | |
3314 | dd->major = major(stb.st_rdev); | |
3315 | dd->minor = minor(stb.st_rdev); | |
b9f594fe | 3316 | dd->index = -1; |
c2c087e6 | 3317 | dd->devname = devname ? strdup(devname) : NULL; |
c2c087e6 | 3318 | dd->fd = fd; |
689c9bf3 | 3319 | dd->e = NULL; |
c2c087e6 | 3320 | rv = imsm_read_serial(fd, devname, dd->serial); |
32ba9157 | 3321 | if (rv) { |
c2c087e6 | 3322 | fprintf(stderr, |
0030e8d6 | 3323 | Name ": failed to retrieve scsi serial, aborting\n"); |
949c47a0 | 3324 | free(dd); |
0030e8d6 | 3325 | abort(); |
c2c087e6 DW |
3326 | } |
3327 | ||
c2c087e6 DW |
3328 | get_dev_size(fd, NULL, &size); |
3329 | size /= 512; | |
1f24f035 | 3330 | serialcpy(dd->disk.serial, dd->serial); |
b9f594fe | 3331 | dd->disk.total_blocks = __cpu_to_le32(size); |
ee5aad5a | 3332 | dd->disk.status = SPARE_DISK; |
c2c087e6 | 3333 | if (sysfs_disk_to_scsi_id(fd, &id) == 0) |
b9f594fe | 3334 | dd->disk.scsi_id = __cpu_to_le32(id); |
c2c087e6 | 3335 | else |
b9f594fe | 3336 | dd->disk.scsi_id = __cpu_to_le32(0); |
43dad3d6 DW |
3337 | |
3338 | if (st->update_tail) { | |
3339 | dd->next = super->add; | |
3340 | super->add = dd; | |
3341 | } else { | |
3342 | dd->next = super->disks; | |
3343 | super->disks = dd; | |
3344 | } | |
f20c3968 DW |
3345 | |
3346 | return 0; | |
cdddbdbc DW |
3347 | } |
3348 | ||
f796af5d DW |
3349 | static int store_imsm_mpb(int fd, struct imsm_super *mpb); |
3350 | ||
3351 | static union { | |
3352 | char buf[512]; | |
3353 | struct imsm_super anchor; | |
3354 | } spare_record __attribute__ ((aligned(512))); | |
c2c087e6 | 3355 | |
d23fe947 DW |
3356 | /* spare records have their own family number and do not have any defined raid |
3357 | * devices | |
3358 | */ | |
3359 | static int write_super_imsm_spares(struct intel_super *super, int doclose) | |
3360 | { | |
d23fe947 | 3361 | struct imsm_super *mpb = super->anchor; |
f796af5d | 3362 | struct imsm_super *spare = &spare_record.anchor; |
d23fe947 DW |
3363 | __u32 sum; |
3364 | struct dl *d; | |
3365 | ||
f796af5d DW |
3366 | spare->mpb_size = __cpu_to_le32(sizeof(struct imsm_super)), |
3367 | spare->generation_num = __cpu_to_le32(1UL), | |
3368 | spare->attributes = MPB_ATTRIB_CHECKSUM_VERIFY; | |
3369 | spare->num_disks = 1, | |
3370 | spare->num_raid_devs = 0, | |
3371 | spare->cache_size = mpb->cache_size, | |
3372 | spare->pwr_cycle_count = __cpu_to_le32(1), | |
3373 | ||
3374 | snprintf((char *) spare->sig, MAX_SIGNATURE_LENGTH, | |
3375 | MPB_SIGNATURE MPB_VERSION_RAID0); | |
d23fe947 DW |
3376 | |
3377 | for (d = super->disks; d; d = d->next) { | |
8796fdc4 | 3378 | if (d->index != -1) |
d23fe947 DW |
3379 | continue; |
3380 | ||
f796af5d DW |
3381 | spare->disk[0] = d->disk; |
3382 | sum = __gen_imsm_checksum(spare); | |
3383 | spare->family_num = __cpu_to_le32(sum); | |
3384 | spare->orig_family_num = 0; | |
3385 | sum = __gen_imsm_checksum(spare); | |
3386 | spare->check_sum = __cpu_to_le32(sum); | |
d23fe947 | 3387 | |
f796af5d | 3388 | if (store_imsm_mpb(d->fd, spare)) { |
d23fe947 DW |
3389 | fprintf(stderr, "%s: failed for device %d:%d %s\n", |
3390 | __func__, d->major, d->minor, strerror(errno)); | |
e74255d9 | 3391 | return 1; |
d23fe947 DW |
3392 | } |
3393 | if (doclose) { | |
3394 | close(d->fd); | |
3395 | d->fd = -1; | |
3396 | } | |
3397 | } | |
3398 | ||
e74255d9 | 3399 | return 0; |
d23fe947 DW |
3400 | } |
3401 | ||
c2c087e6 | 3402 | static int write_super_imsm(struct intel_super *super, int doclose) |
cdddbdbc | 3403 | { |
949c47a0 | 3404 | struct imsm_super *mpb = super->anchor; |
c2c087e6 DW |
3405 | struct dl *d; |
3406 | __u32 generation; | |
3407 | __u32 sum; | |
d23fe947 | 3408 | int spares = 0; |
949c47a0 | 3409 | int i; |
a48ac0a8 | 3410 | __u32 mpb_size = sizeof(struct imsm_super) - sizeof(struct imsm_disk); |
cdddbdbc | 3411 | |
c2c087e6 DW |
3412 | /* 'generation' is incremented everytime the metadata is written */ |
3413 | generation = __le32_to_cpu(mpb->generation_num); | |
3414 | generation++; | |
3415 | mpb->generation_num = __cpu_to_le32(generation); | |
3416 | ||
148acb7b DW |
3417 | /* fix up cases where previous mdadm releases failed to set |
3418 | * orig_family_num | |
3419 | */ | |
3420 | if (mpb->orig_family_num == 0) | |
3421 | mpb->orig_family_num = mpb->family_num; | |
3422 | ||
1ee1e9fc | 3423 | mpb_size += sizeof(struct imsm_disk) * mpb->num_disks; |
d23fe947 | 3424 | for (d = super->disks; d; d = d->next) { |
8796fdc4 | 3425 | if (d->index == -1) |
d23fe947 | 3426 | spares++; |
1ee1e9fc | 3427 | else |
d23fe947 | 3428 | mpb->disk[d->index] = d->disk; |
d23fe947 | 3429 | } |
47ee5a45 DW |
3430 | for (d = super->missing; d; d = d->next) |
3431 | mpb->disk[d->index] = d->disk; | |
b9f594fe | 3432 | |
949c47a0 DW |
3433 | for (i = 0; i < mpb->num_raid_devs; i++) { |
3434 | struct imsm_dev *dev = __get_imsm_dev(mpb, i); | |
3435 | ||
ba2de7ba | 3436 | imsm_copy_dev(dev, get_imsm_dev(super, i)); |
a48ac0a8 | 3437 | mpb_size += sizeof_imsm_dev(dev, 0); |
949c47a0 | 3438 | } |
a48ac0a8 DW |
3439 | mpb_size += __le32_to_cpu(mpb->bbm_log_size); |
3440 | mpb->mpb_size = __cpu_to_le32(mpb_size); | |
949c47a0 | 3441 | |
c2c087e6 | 3442 | /* recalculate checksum */ |
949c47a0 | 3443 | sum = __gen_imsm_checksum(mpb); |
c2c087e6 DW |
3444 | mpb->check_sum = __cpu_to_le32(sum); |
3445 | ||
d23fe947 | 3446 | /* write the mpb for disks that compose raid devices */ |
c2c087e6 | 3447 | for (d = super->disks; d ; d = d->next) { |
d23fe947 DW |
3448 | if (d->index < 0) |
3449 | continue; | |
f796af5d | 3450 | if (store_imsm_mpb(d->fd, mpb)) |
c2c087e6 DW |
3451 | fprintf(stderr, "%s: failed for device %d:%d %s\n", |
3452 | __func__, d->major, d->minor, strerror(errno)); | |
c2c087e6 DW |
3453 | if (doclose) { |
3454 | close(d->fd); | |
3455 | d->fd = -1; | |
3456 | } | |
3457 | } | |
3458 | ||
d23fe947 DW |
3459 | if (spares) |
3460 | return write_super_imsm_spares(super, doclose); | |
3461 | ||
e74255d9 | 3462 | return 0; |
c2c087e6 DW |
3463 | } |
3464 | ||
0e600426 | 3465 | |
9b1fb677 | 3466 | static int create_array(struct supertype *st, int dev_idx) |
43dad3d6 DW |
3467 | { |
3468 | size_t len; | |
3469 | struct imsm_update_create_array *u; | |
3470 | struct intel_super *super = st->sb; | |
9b1fb677 | 3471 | struct imsm_dev *dev = get_imsm_dev(super, dev_idx); |
54c2c1ea DW |
3472 | struct imsm_map *map = get_imsm_map(dev, 0); |
3473 | struct disk_info *inf; | |
3474 | struct imsm_disk *disk; | |
3475 | int i; | |
43dad3d6 | 3476 | |
54c2c1ea DW |
3477 | len = sizeof(*u) - sizeof(*dev) + sizeof_imsm_dev(dev, 0) + |
3478 | sizeof(*inf) * map->num_members; | |
43dad3d6 DW |
3479 | u = malloc(len); |
3480 | if (!u) { | |
3481 | fprintf(stderr, "%s: failed to allocate update buffer\n", | |
3482 | __func__); | |
3483 | return 1; | |
3484 | } | |
3485 | ||
3486 | u->type = update_create_array; | |
9b1fb677 | 3487 | u->dev_idx = dev_idx; |
43dad3d6 | 3488 | imsm_copy_dev(&u->dev, dev); |
54c2c1ea DW |
3489 | inf = get_disk_info(u); |
3490 | for (i = 0; i < map->num_members; i++) { | |
9b1fb677 DW |
3491 | int idx = get_imsm_disk_idx(dev, i); |
3492 | ||
54c2c1ea DW |
3493 | disk = get_imsm_disk(super, idx); |
3494 | serialcpy(inf[i].serial, disk->serial); | |
3495 | } | |
43dad3d6 DW |
3496 | append_metadata_update(st, u, len); |
3497 | ||
3498 | return 0; | |
3499 | } | |
3500 | ||
7801ac20 | 3501 | static int _add_disk(struct supertype *st) |
43dad3d6 DW |
3502 | { |
3503 | struct intel_super *super = st->sb; | |
3504 | size_t len; | |
3505 | struct imsm_update_add_disk *u; | |
3506 | ||
3507 | if (!super->add) | |
3508 | return 0; | |
3509 | ||
3510 | len = sizeof(*u); | |
3511 | u = malloc(len); | |
3512 | if (!u) { | |
3513 | fprintf(stderr, "%s: failed to allocate update buffer\n", | |
3514 | __func__); | |
3515 | return 1; | |
3516 | } | |
3517 | ||
3518 | u->type = update_add_disk; | |
3519 | append_metadata_update(st, u, len); | |
3520 | ||
3521 | return 0; | |
3522 | } | |
3523 | ||
c2c087e6 DW |
3524 | static int write_init_super_imsm(struct supertype *st) |
3525 | { | |
9b1fb677 DW |
3526 | struct intel_super *super = st->sb; |
3527 | int current_vol = super->current_vol; | |
3528 | ||
3529 | /* we are done with current_vol reset it to point st at the container */ | |
3530 | super->current_vol = -1; | |
3531 | ||
8273f55e | 3532 | if (st->update_tail) { |
43dad3d6 DW |
3533 | /* queue the recently created array / added disk |
3534 | * as a metadata update */ | |
8273f55e | 3535 | struct dl *d; |
43dad3d6 | 3536 | int rv; |
8273f55e | 3537 | |
43dad3d6 | 3538 | /* determine if we are creating a volume or adding a disk */ |
9b1fb677 | 3539 | if (current_vol < 0) { |
43dad3d6 DW |
3540 | /* in the add disk case we are running in mdmon |
3541 | * context, so don't close fd's | |
3542 | */ | |
7801ac20 | 3543 | return _add_disk(st); |
43dad3d6 | 3544 | } else |
9b1fb677 | 3545 | rv = create_array(st, current_vol); |
8273f55e DW |
3546 | |
3547 | for (d = super->disks; d ; d = d->next) { | |
3548 | close(d->fd); | |
3549 | d->fd = -1; | |
3550 | } | |
3551 | ||
43dad3d6 | 3552 | return rv; |
d682f344 N |
3553 | } else { |
3554 | struct dl *d; | |
3555 | for (d = super->disks; d; d = d->next) | |
3556 | Kill(d->devname, NULL, 0, 1, 1); | |
8273f55e | 3557 | return write_super_imsm(st->sb, 1); |
d682f344 | 3558 | } |
cdddbdbc | 3559 | } |
0e600426 | 3560 | #endif |
cdddbdbc | 3561 | |
e683ca88 | 3562 | static int store_super_imsm(struct supertype *st, int fd) |
cdddbdbc | 3563 | { |
e683ca88 DW |
3564 | struct intel_super *super = st->sb; |
3565 | struct imsm_super *mpb = super ? super->anchor : NULL; | |
551c80c1 | 3566 | |
e683ca88 | 3567 | if (!mpb) |
ad97895e DW |
3568 | return 1; |
3569 | ||
1799c9e8 | 3570 | #ifndef MDASSEMBLE |
e683ca88 | 3571 | return store_imsm_mpb(fd, mpb); |
1799c9e8 N |
3572 | #else |
3573 | return 1; | |
3574 | #endif | |
cdddbdbc DW |
3575 | } |
3576 | ||
0e600426 N |
3577 | static int imsm_bbm_log_size(struct imsm_super *mpb) |
3578 | { | |
3579 | return __le32_to_cpu(mpb->bbm_log_size); | |
3580 | } | |
3581 | ||
3582 | #ifndef MDASSEMBLE | |
cdddbdbc DW |
3583 | static int validate_geometry_imsm_container(struct supertype *st, int level, |
3584 | int layout, int raiddisks, int chunk, | |
c2c087e6 | 3585 | unsigned long long size, char *dev, |
2c514b71 NB |
3586 | unsigned long long *freesize, |
3587 | int verbose) | |
cdddbdbc | 3588 | { |
c2c087e6 DW |
3589 | int fd; |
3590 | unsigned long long ldsize; | |
88c32bb1 | 3591 | const struct imsm_orom *orom; |
cdddbdbc | 3592 | |
c2c087e6 DW |
3593 | if (level != LEVEL_CONTAINER) |
3594 | return 0; | |
3595 | if (!dev) | |
3596 | return 1; | |
3597 | ||
88c32bb1 DW |
3598 | if (check_env("IMSM_NO_PLATFORM")) |
3599 | orom = NULL; | |
3600 | else | |
3601 | orom = find_imsm_orom(); | |
3602 | if (orom && raiddisks > orom->tds) { | |
3603 | if (verbose) | |
3604 | fprintf(stderr, Name ": %d exceeds maximum number of" | |
3605 | " platform supported disks: %d\n", | |
3606 | raiddisks, orom->tds); | |
3607 | return 0; | |
3608 | } | |
3609 | ||
c2c087e6 DW |
3610 | fd = open(dev, O_RDONLY|O_EXCL, 0); |
3611 | if (fd < 0) { | |
2c514b71 NB |
3612 | if (verbose) |
3613 | fprintf(stderr, Name ": imsm: Cannot open %s: %s\n", | |
3614 | dev, strerror(errno)); | |
c2c087e6 DW |
3615 | return 0; |
3616 | } | |
3617 | if (!get_dev_size(fd, dev, &ldsize)) { | |
3618 | close(fd); | |
3619 | return 0; | |
3620 | } | |
3621 | close(fd); | |
3622 | ||
3623 | *freesize = avail_size_imsm(st, ldsize >> 9); | |
3624 | ||
3625 | return 1; | |
cdddbdbc DW |
3626 | } |
3627 | ||
0dcecb2e DW |
3628 | static unsigned long long find_size(struct extent *e, int *idx, int num_extents) |
3629 | { | |
3630 | const unsigned long long base_start = e[*idx].start; | |
3631 | unsigned long long end = base_start + e[*idx].size; | |
3632 | int i; | |
3633 | ||
3634 | if (base_start == end) | |
3635 | return 0; | |
3636 | ||
3637 | *idx = *idx + 1; | |
3638 | for (i = *idx; i < num_extents; i++) { | |
3639 | /* extend overlapping extents */ | |
3640 | if (e[i].start >= base_start && | |
3641 | e[i].start <= end) { | |
3642 | if (e[i].size == 0) | |
3643 | return 0; | |
3644 | if (e[i].start + e[i].size > end) | |
3645 | end = e[i].start + e[i].size; | |
3646 | } else if (e[i].start > end) { | |
3647 | *idx = i; | |
3648 | break; | |
3649 | } | |
3650 | } | |
3651 | ||
3652 | return end - base_start; | |
3653 | } | |
3654 | ||
3655 | static unsigned long long merge_extents(struct intel_super *super, int sum_extents) | |
3656 | { | |
3657 | /* build a composite disk with all known extents and generate a new | |
3658 | * 'maxsize' given the "all disks in an array must share a common start | |
3659 | * offset" constraint | |
3660 | */ | |
3661 | struct extent *e = calloc(sum_extents, sizeof(*e)); | |
3662 | struct dl *dl; | |
3663 | int i, j; | |
3664 | int start_extent; | |
3665 | unsigned long long pos; | |
b9d77223 | 3666 | unsigned long long start = 0; |
0dcecb2e DW |
3667 | unsigned long long maxsize; |
3668 | unsigned long reserve; | |
3669 | ||
3670 | if (!e) | |
a7dd165b | 3671 | return 0; |
0dcecb2e DW |
3672 | |
3673 | /* coalesce and sort all extents. also, check to see if we need to | |
3674 | * reserve space between member arrays | |
3675 | */ | |
3676 | j = 0; | |
3677 | for (dl = super->disks; dl; dl = dl->next) { | |
3678 | if (!dl->e) | |
3679 | continue; | |
3680 | for (i = 0; i < dl->extent_cnt; i++) | |
3681 | e[j++] = dl->e[i]; | |
3682 | } | |
3683 | qsort(e, sum_extents, sizeof(*e), cmp_extent); | |
3684 | ||
3685 | /* merge extents */ | |
3686 | i = 0; | |
3687 | j = 0; | |
3688 | while (i < sum_extents) { | |
3689 | e[j].start = e[i].start; | |
3690 | e[j].size = find_size(e, &i, sum_extents); | |
3691 | j++; | |
3692 | if (e[j-1].size == 0) | |
3693 | break; | |
3694 | } | |
3695 | ||
3696 | pos = 0; | |
3697 | maxsize = 0; | |
3698 | start_extent = 0; | |
3699 | i = 0; | |
3700 | do { | |
3701 | unsigned long long esize; | |
3702 | ||
3703 | esize = e[i].start - pos; | |
3704 | if (esize >= maxsize) { | |
3705 | maxsize = esize; | |
3706 | start = pos; | |
3707 | start_extent = i; | |
3708 | } | |
3709 | pos = e[i].start + e[i].size; | |
3710 | i++; | |
3711 | } while (e[i-1].size); | |
3712 | free(e); | |
3713 | ||
a7dd165b DW |
3714 | if (maxsize == 0) |
3715 | return 0; | |
3716 | ||
3717 | /* FIXME assumes volume at offset 0 is the first volume in a | |
3718 | * container | |
3719 | */ | |
0dcecb2e DW |
3720 | if (start_extent > 0) |
3721 | reserve = IMSM_RESERVED_SECTORS; /* gap between raid regions */ | |
3722 | else | |
3723 | reserve = 0; | |
3724 | ||
3725 | if (maxsize < reserve) | |
a7dd165b | 3726 | return 0; |
0dcecb2e DW |
3727 | |
3728 | super->create_offset = ~((__u32) 0); | |
3729 | if (start + reserve > super->create_offset) | |
a7dd165b | 3730 | return 0; /* start overflows create_offset */ |
0dcecb2e DW |
3731 | super->create_offset = start + reserve; |
3732 | ||
3733 | return maxsize - reserve; | |
3734 | } | |
3735 | ||
88c32bb1 DW |
3736 | static int is_raid_level_supported(const struct imsm_orom *orom, int level, int raiddisks) |
3737 | { | |
3738 | if (level < 0 || level == 6 || level == 4) | |
3739 | return 0; | |
3740 | ||
3741 | /* if we have an orom prevent invalid raid levels */ | |
3742 | if (orom) | |
3743 | switch (level) { | |
3744 | case 0: return imsm_orom_has_raid0(orom); | |
3745 | case 1: | |
3746 | if (raiddisks > 2) | |
3747 | return imsm_orom_has_raid1e(orom); | |
1c556e92 DW |
3748 | return imsm_orom_has_raid1(orom) && raiddisks == 2; |
3749 | case 10: return imsm_orom_has_raid10(orom) && raiddisks == 4; | |
3750 | case 5: return imsm_orom_has_raid5(orom) && raiddisks > 2; | |
88c32bb1 DW |
3751 | } |
3752 | else | |
3753 | return 1; /* not on an Intel RAID platform so anything goes */ | |
3754 | ||
3755 | return 0; | |
3756 | } | |
3757 | ||
35f81cbb | 3758 | #define pr_vrb(fmt, arg...) (void) (verbose && fprintf(stderr, Name fmt, ##arg)) |
6592ce37 DW |
3759 | static int |
3760 | validate_geometry_imsm_orom(struct intel_super *super, int level, int layout, | |
3761 | int raiddisks, int chunk, int verbose) | |
3762 | { | |
3763 | if (!is_raid_level_supported(super->orom, level, raiddisks)) { | |
3764 | pr_vrb(": platform does not support raid%d with %d disk%s\n", | |
3765 | level, raiddisks, raiddisks > 1 ? "s" : ""); | |
3766 | return 0; | |
3767 | } | |
3768 | if (super->orom && level != 1 && | |
3769 | !imsm_orom_has_chunk(super->orom, chunk)) { | |
3770 | pr_vrb(": platform does not support a chunk size of: %d\n", chunk); | |
3771 | return 0; | |
3772 | } | |
3773 | if (layout != imsm_level_to_layout(level)) { | |
3774 | if (level == 5) | |
3775 | pr_vrb(": imsm raid 5 only supports the left-asymmetric layout\n"); | |
3776 | else if (level == 10) | |
3777 | pr_vrb(": imsm raid 10 only supports the n2 layout\n"); | |
3778 | else | |
3779 | pr_vrb(": imsm unknown layout %#x for this raid level %d\n", | |
3780 | layout, level); | |
3781 | return 0; | |
3782 | } | |
3783 | ||
3784 | return 1; | |
3785 | } | |
3786 | ||
c2c087e6 DW |
3787 | /* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd |
3788 | * FIX ME add ahci details | |
3789 | */ | |
8b353278 DW |
3790 | static int validate_geometry_imsm_volume(struct supertype *st, int level, |
3791 | int layout, int raiddisks, int chunk, | |
c2c087e6 | 3792 | unsigned long long size, char *dev, |
2c514b71 NB |
3793 | unsigned long long *freesize, |
3794 | int verbose) | |
cdddbdbc | 3795 | { |
c2c087e6 DW |
3796 | struct stat stb; |
3797 | struct intel_super *super = st->sb; | |
a20d2ba5 | 3798 | struct imsm_super *mpb = super->anchor; |
c2c087e6 DW |
3799 | struct dl *dl; |
3800 | unsigned long long pos = 0; | |
3801 | unsigned long long maxsize; | |
3802 | struct extent *e; | |
3803 | int i; | |
cdddbdbc | 3804 | |
88c32bb1 DW |
3805 | /* We must have the container info already read in. */ |
3806 | if (!super) | |
c2c087e6 DW |
3807 | return 0; |
3808 | ||
6592ce37 | 3809 | if (!validate_geometry_imsm_orom(super, level, layout, raiddisks, chunk, verbose)) |
c2c087e6 | 3810 | return 0; |
c2c087e6 DW |
3811 | |
3812 | if (!dev) { | |
3813 | /* General test: make sure there is space for | |
2da8544a DW |
3814 | * 'raiddisks' device extents of size 'size' at a given |
3815 | * offset | |
c2c087e6 | 3816 | */ |
e46273eb | 3817 | unsigned long long minsize = size; |
b7528a20 | 3818 | unsigned long long start_offset = MaxSector; |
c2c087e6 DW |
3819 | int dcnt = 0; |
3820 | if (minsize == 0) | |
3821 | minsize = MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS; | |
3822 | for (dl = super->disks; dl ; dl = dl->next) { | |
3823 | int found = 0; | |
3824 | ||
bf5a934a | 3825 | pos = 0; |
c2c087e6 DW |
3826 | i = 0; |
3827 | e = get_extents(super, dl); | |
3828 | if (!e) continue; | |
3829 | do { | |
3830 | unsigned long long esize; | |
3831 | esize = e[i].start - pos; | |
3832 | if (esize >= minsize) | |
3833 | found = 1; | |
b7528a20 | 3834 | if (found && start_offset == MaxSector) { |
2da8544a DW |
3835 | start_offset = pos; |
3836 | break; | |
3837 | } else if (found && pos != start_offset) { | |
3838 | found = 0; | |
3839 | break; | |
3840 | } | |
c2c087e6 DW |
3841 | pos = e[i].start + e[i].size; |
3842 | i++; | |
3843 | } while (e[i-1].size); | |
3844 | if (found) | |
3845 | dcnt++; | |
3846 | free(e); | |
3847 | } | |
3848 | if (dcnt < raiddisks) { | |
2c514b71 NB |
3849 | if (verbose) |
3850 | fprintf(stderr, Name ": imsm: Not enough " | |
3851 | "devices with space for this array " | |
3852 | "(%d < %d)\n", | |
3853 | dcnt, raiddisks); | |
c2c087e6 DW |
3854 | return 0; |
3855 | } | |
3856 | return 1; | |
3857 | } | |
0dcecb2e | 3858 | |
c2c087e6 DW |
3859 | /* This device must be a member of the set */ |
3860 | if (stat(dev, &stb) < 0) | |
3861 | return 0; | |
3862 | if ((S_IFMT & stb.st_mode) != S_IFBLK) | |
3863 | return 0; | |
3864 | for (dl = super->disks ; dl ; dl = dl->next) { | |
f21e18ca N |
3865 | if (dl->major == (int)major(stb.st_rdev) && |
3866 | dl->minor == (int)minor(stb.st_rdev)) | |
c2c087e6 DW |
3867 | break; |
3868 | } | |
3869 | if (!dl) { | |
2c514b71 NB |
3870 | if (verbose) |
3871 | fprintf(stderr, Name ": %s is not in the " | |
3872 | "same imsm set\n", dev); | |
c2c087e6 | 3873 | return 0; |
a20d2ba5 DW |
3874 | } else if (super->orom && dl->index < 0 && mpb->num_raid_devs) { |
3875 | /* If a volume is present then the current creation attempt | |
3876 | * cannot incorporate new spares because the orom may not | |
3877 | * understand this configuration (all member disks must be | |
3878 | * members of each array in the container). | |
3879 | */ | |
3880 | fprintf(stderr, Name ": %s is a spare and a volume" | |
3881 | " is already defined for this container\n", dev); | |
3882 | fprintf(stderr, Name ": The option-rom requires all member" | |
3883 | " disks to be a member of all volumes\n"); | |
3884 | return 0; | |
c2c087e6 | 3885 | } |
0dcecb2e DW |
3886 | |
3887 | /* retrieve the largest free space block */ | |
c2c087e6 DW |
3888 | e = get_extents(super, dl); |
3889 | maxsize = 0; | |
3890 | i = 0; | |
0dcecb2e DW |
3891 | if (e) { |
3892 | do { | |
3893 | unsigned long long esize; | |
3894 | ||
3895 | esize = e[i].start - pos; | |
3896 | if (esize >= maxsize) | |
3897 | maxsize = esize; | |
3898 | pos = e[i].start + e[i].size; | |
3899 | i++; | |
3900 | } while (e[i-1].size); | |
3901 | dl->e = e; | |
3902 | dl->extent_cnt = i; | |
3903 | } else { | |
3904 | if (verbose) | |
3905 | fprintf(stderr, Name ": unable to determine free space for: %s\n", | |
3906 | dev); | |
3907 | return 0; | |
3908 | } | |
3909 | if (maxsize < size) { | |
3910 | if (verbose) | |
3911 | fprintf(stderr, Name ": %s not enough space (%llu < %llu)\n", | |
3912 | dev, maxsize, size); | |
3913 | return 0; | |
3914 | } | |
3915 | ||
3916 | /* count total number of extents for merge */ | |
3917 | i = 0; | |
3918 | for (dl = super->disks; dl; dl = dl->next) | |
3919 | if (dl->e) | |
3920 | i += dl->extent_cnt; | |
3921 | ||
3922 | maxsize = merge_extents(super, i); | |
a7dd165b | 3923 | if (maxsize < size || maxsize == 0) { |
0dcecb2e DW |
3924 | if (verbose) |
3925 | fprintf(stderr, Name ": not enough space after merge (%llu < %llu)\n", | |
3926 | maxsize, size); | |
3927 | return 0; | |
0dcecb2e DW |
3928 | } |
3929 | ||
c2c087e6 DW |
3930 | *freesize = maxsize; |
3931 | ||
3932 | return 1; | |
cdddbdbc DW |
3933 | } |
3934 | ||
efb30e7f DW |
3935 | static int reserve_space(struct supertype *st, int raiddisks, |
3936 | unsigned long long size, int chunk, | |
3937 | unsigned long long *freesize) | |
3938 | { | |
3939 | struct intel_super *super = st->sb; | |
3940 | struct imsm_super *mpb = super->anchor; | |
3941 | struct dl *dl; | |
3942 | int i; | |
3943 | int extent_cnt; | |
3944 | struct extent *e; | |
3945 | unsigned long long maxsize; | |
3946 | unsigned long long minsize; | |
3947 | int cnt; | |
3948 | int used; | |
3949 | ||
3950 | /* find the largest common start free region of the possible disks */ | |
3951 | used = 0; | |
3952 | extent_cnt = 0; | |
3953 | cnt = 0; | |
3954 | for (dl = super->disks; dl; dl = dl->next) { | |
3955 | dl->raiddisk = -1; | |
3956 | ||
3957 | if (dl->index >= 0) | |
3958 | used++; | |
3959 | ||
3960 | /* don't activate new spares if we are orom constrained | |
3961 | * and there is already a volume active in the container | |
3962 | */ | |
3963 | if (super->orom && dl->index < 0 && mpb->num_raid_devs) | |
3964 | continue; | |
3965 | ||
3966 | e = get_extents(super, dl); | |
3967 | if (!e) | |
3968 | continue; | |
3969 | for (i = 1; e[i-1].size; i++) | |
3970 | ; | |
3971 | dl->e = e; | |
3972 | dl->extent_cnt = i; | |
3973 | extent_cnt += i; | |
3974 | cnt++; | |
3975 | } | |
3976 | ||
3977 | maxsize = merge_extents(super, extent_cnt); | |
3978 | minsize = size; | |
3979 | if (size == 0) | |
3980 | minsize = chunk; | |
3981 | ||
3982 | if (cnt < raiddisks || | |
3983 | (super->orom && used && used != raiddisks) || | |
a7dd165b DW |
3984 | maxsize < minsize || |
3985 | maxsize == 0) { | |
efb30e7f DW |
3986 | fprintf(stderr, Name ": not enough devices with space to create array.\n"); |
3987 | return 0; /* No enough free spaces large enough */ | |
3988 | } | |
3989 | ||
3990 | if (size == 0) { | |
3991 | size = maxsize; | |
3992 | if (chunk) { | |
3993 | size /= chunk; | |
3994 | size *= chunk; | |
3995 | } | |
3996 | } | |
3997 | ||
3998 | cnt = 0; | |
3999 | for (dl = super->disks; dl; dl = dl->next) | |
4000 | if (dl->e) | |
4001 | dl->raiddisk = cnt++; | |
4002 | ||
4003 | *freesize = size; | |
4004 | ||
4005 | return 1; | |
4006 | } | |
4007 | ||
bf5a934a DW |
4008 | static int validate_geometry_imsm(struct supertype *st, int level, int layout, |
4009 | int raiddisks, int chunk, unsigned long long size, | |
4010 | char *dev, unsigned long long *freesize, | |
4011 | int verbose) | |
4012 | { | |
4013 | int fd, cfd; | |
4014 | struct mdinfo *sra; | |
20cbe8d2 | 4015 | int is_member = 0; |
bf5a934a DW |
4016 | |
4017 | /* if given unused devices create a container | |
4018 | * if given given devices in a container create a member volume | |
4019 | */ | |
4020 | if (level == LEVEL_CONTAINER) { | |
4021 | /* Must be a fresh device to add to a container */ | |
4022 | return validate_geometry_imsm_container(st, level, layout, | |
4023 | raiddisks, chunk, size, | |
4024 | dev, freesize, | |
4025 | verbose); | |
4026 | } | |
4027 | ||
8592f29d N |
4028 | if (!dev) { |
4029 | if (st->sb && freesize) { | |
efb30e7f DW |
4030 | /* we are being asked to automatically layout a |
4031 | * new volume based on the current contents of | |
4032 | * the container. If the the parameters can be | |
4033 | * satisfied reserve_space will record the disks, | |
4034 | * start offset, and size of the volume to be | |
4035 | * created. add_to_super and getinfo_super | |
4036 | * detect when autolayout is in progress. | |
4037 | */ | |
6592ce37 DW |
4038 | if (!validate_geometry_imsm_orom(st->sb, level, layout, |
4039 | raiddisks, chunk, | |
4040 | verbose)) | |
4041 | return 0; | |
efb30e7f | 4042 | return reserve_space(st, raiddisks, size, chunk, freesize); |
8592f29d N |
4043 | } |
4044 | return 1; | |
4045 | } | |
bf5a934a DW |
4046 | if (st->sb) { |
4047 | /* creating in a given container */ | |
4048 | return validate_geometry_imsm_volume(st, level, layout, | |
4049 | raiddisks, chunk, size, | |
4050 | dev, freesize, verbose); | |
4051 | } | |
4052 | ||
bf5a934a DW |
4053 | /* This device needs to be a device in an 'imsm' container */ |
4054 | fd = open(dev, O_RDONLY|O_EXCL, 0); | |
4055 | if (fd >= 0) { | |
4056 | if (verbose) | |
4057 | fprintf(stderr, | |
4058 | Name ": Cannot create this array on device %s\n", | |
4059 | dev); | |
4060 | close(fd); | |
4061 | return 0; | |
4062 | } | |
4063 | if (errno != EBUSY || (fd = open(dev, O_RDONLY, 0)) < 0) { | |
4064 | if (verbose) | |
4065 | fprintf(stderr, Name ": Cannot open %s: %s\n", | |
4066 | dev, strerror(errno)); | |
4067 | return 0; | |
4068 | } | |
4069 | /* Well, it is in use by someone, maybe an 'imsm' container. */ | |
4070 | cfd = open_container(fd); | |
20cbe8d2 | 4071 | close(fd); |
bf5a934a | 4072 | if (cfd < 0) { |
bf5a934a DW |
4073 | if (verbose) |
4074 | fprintf(stderr, Name ": Cannot use %s: It is busy\n", | |
4075 | dev); | |
4076 | return 0; | |
4077 | } | |
4078 | sra = sysfs_read(cfd, 0, GET_VERSION); | |
bf5a934a | 4079 | if (sra && sra->array.major_version == -1 && |
20cbe8d2 AW |
4080 | strcmp(sra->text_version, "imsm") == 0) |
4081 | is_member = 1; | |
4082 | sysfs_free(sra); | |
4083 | if (is_member) { | |
bf5a934a DW |
4084 | /* This is a member of a imsm container. Load the container |
4085 | * and try to create a volume | |
4086 | */ | |
4087 | struct intel_super *super; | |
4088 | ||
e1902a7b | 4089 | if (load_super_imsm_all(st, cfd, (void **) &super, NULL) == 0) { |
bf5a934a DW |
4090 | st->sb = super; |
4091 | st->container_dev = fd2devnum(cfd); | |
4092 | close(cfd); | |
4093 | return validate_geometry_imsm_volume(st, level, layout, | |
4094 | raiddisks, chunk, | |
4095 | size, dev, | |
4096 | freesize, verbose); | |
4097 | } | |
20cbe8d2 | 4098 | } |
bf5a934a | 4099 | |
20cbe8d2 AW |
4100 | if (verbose) |
4101 | fprintf(stderr, Name ": failed container membership check\n"); | |
4102 | ||
4103 | close(cfd); | |
4104 | return 0; | |
bf5a934a | 4105 | } |
0bd16cf2 DJ |
4106 | |
4107 | static int default_chunk_imsm(struct supertype *st) | |
4108 | { | |
4109 | struct intel_super *super = st->sb; | |
4110 | ||
4111 | if (!super->orom) | |
4112 | return 0; | |
4113 | ||
4114 | return imsm_orom_default_chunk(super->orom); | |
4115 | } | |
4116 | ||
33414a01 DW |
4117 | static void handle_missing(struct intel_super *super, struct imsm_dev *dev); |
4118 | ||
4119 | static int kill_subarray_imsm(struct supertype *st) | |
4120 | { | |
4121 | /* remove the subarray currently referenced by ->current_vol */ | |
4122 | __u8 i; | |
4123 | struct intel_dev **dp; | |
4124 | struct intel_super *super = st->sb; | |
4125 | __u8 current_vol = super->current_vol; | |
4126 | struct imsm_super *mpb = super->anchor; | |
4127 | ||
4128 | if (super->current_vol < 0) | |
4129 | return 2; | |
4130 | super->current_vol = -1; /* invalidate subarray cursor */ | |
4131 | ||
4132 | /* block deletions that would change the uuid of active subarrays | |
4133 | * | |
4134 | * FIXME when immutable ids are available, but note that we'll | |
4135 | * also need to fixup the invalidated/active subarray indexes in | |
4136 | * mdstat | |
4137 | */ | |
4138 | for (i = 0; i < mpb->num_raid_devs; i++) { | |
4139 | char subarray[4]; | |
4140 | ||
4141 | if (i < current_vol) | |
4142 | continue; | |
4143 | sprintf(subarray, "%u", i); | |
4144 | if (is_subarray_active(subarray, st->devname)) { | |
4145 | fprintf(stderr, | |
4146 | Name ": deleting subarray-%d would change the UUID of active subarray-%d, aborting\n", | |
4147 | current_vol, i); | |
4148 | ||
4149 | return 2; | |
4150 | } | |
4151 | } | |
4152 | ||
4153 | if (st->update_tail) { | |
4154 | struct imsm_update_kill_array *u = malloc(sizeof(*u)); | |
4155 | ||
4156 | if (!u) | |
4157 | return 2; | |
4158 | u->type = update_kill_array; | |
4159 | u->dev_idx = current_vol; | |
4160 | append_metadata_update(st, u, sizeof(*u)); | |
4161 | ||
4162 | return 0; | |
4163 | } | |
4164 | ||
4165 | for (dp = &super->devlist; *dp;) | |
4166 | if ((*dp)->index == current_vol) { | |
4167 | *dp = (*dp)->next; | |
4168 | } else { | |
4169 | handle_missing(super, (*dp)->dev); | |
4170 | if ((*dp)->index > current_vol) | |
4171 | (*dp)->index--; | |
4172 | dp = &(*dp)->next; | |
4173 | } | |
4174 | ||
4175 | /* no more raid devices, all active components are now spares, | |
4176 | * but of course failed are still failed | |
4177 | */ | |
4178 | if (--mpb->num_raid_devs == 0) { | |
4179 | struct dl *d; | |
4180 | ||
4181 | for (d = super->disks; d; d = d->next) | |
4182 | if (d->index > -2) { | |
4183 | d->index = -1; | |
4184 | d->disk.status = SPARE_DISK; | |
4185 | } | |
4186 | } | |
4187 | ||
4188 | super->updates_pending++; | |
4189 | ||
4190 | return 0; | |
4191 | } | |
aa534678 | 4192 | |
a951a4f7 | 4193 | static int update_subarray_imsm(struct supertype *st, char *subarray, |
fa56eddb | 4194 | char *update, struct mddev_ident *ident) |
aa534678 DW |
4195 | { |
4196 | /* update the subarray currently referenced by ->current_vol */ | |
4197 | struct intel_super *super = st->sb; | |
4198 | struct imsm_super *mpb = super->anchor; | |
4199 | ||
aa534678 DW |
4200 | if (strcmp(update, "name") == 0) { |
4201 | char *name = ident->name; | |
a951a4f7 N |
4202 | char *ep; |
4203 | int vol; | |
aa534678 | 4204 | |
a951a4f7 | 4205 | if (is_subarray_active(subarray, st->devname)) { |
aa534678 DW |
4206 | fprintf(stderr, |
4207 | Name ": Unable to update name of active subarray\n"); | |
4208 | return 2; | |
4209 | } | |
4210 | ||
4211 | if (!check_name(super, name, 0)) | |
4212 | return 2; | |
4213 | ||
a951a4f7 N |
4214 | vol = strtoul(subarray, &ep, 10); |
4215 | if (*ep != '\0' || vol >= super->anchor->num_raid_devs) | |
4216 | return 2; | |
4217 | ||
aa534678 DW |
4218 | if (st->update_tail) { |
4219 | struct imsm_update_rename_array *u = malloc(sizeof(*u)); | |
4220 | ||
4221 | if (!u) | |
4222 | return 2; | |
4223 | u->type = update_rename_array; | |
a951a4f7 | 4224 | u->dev_idx = vol; |
aa534678 DW |
4225 | snprintf((char *) u->name, MAX_RAID_SERIAL_LEN, "%s", name); |
4226 | append_metadata_update(st, u, sizeof(*u)); | |
4227 | } else { | |
4228 | struct imsm_dev *dev; | |
4229 | int i; | |
4230 | ||
a951a4f7 | 4231 | dev = get_imsm_dev(super, vol); |
aa534678 DW |
4232 | snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, "%s", name); |
4233 | for (i = 0; i < mpb->num_raid_devs; i++) { | |
4234 | dev = get_imsm_dev(super, i); | |
4235 | handle_missing(super, dev); | |
4236 | } | |
4237 | super->updates_pending++; | |
4238 | } | |
4239 | } else | |
4240 | return 2; | |
4241 | ||
4242 | return 0; | |
4243 | } | |
0e600426 | 4244 | #endif /* MDASSEMBLE */ |
bf5a934a | 4245 | |
1e5c6983 DW |
4246 | static int is_rebuilding(struct imsm_dev *dev) |
4247 | { | |
4248 | struct imsm_map *migr_map; | |
4249 | ||
4250 | if (!dev->vol.migr_state) | |
4251 | return 0; | |
4252 | ||
4253 | if (migr_type(dev) != MIGR_REBUILD) | |
4254 | return 0; | |
4255 | ||
4256 | migr_map = get_imsm_map(dev, 1); | |
4257 | ||
4258 | if (migr_map->map_state == IMSM_T_STATE_DEGRADED) | |
4259 | return 1; | |
4260 | else | |
4261 | return 0; | |
4262 | } | |
4263 | ||
4264 | static void update_recovery_start(struct imsm_dev *dev, struct mdinfo *array) | |
4265 | { | |
4266 | struct mdinfo *rebuild = NULL; | |
4267 | struct mdinfo *d; | |
4268 | __u32 units; | |
4269 | ||
4270 | if (!is_rebuilding(dev)) | |
4271 | return; | |
4272 | ||
4273 | /* Find the rebuild target, but punt on the dual rebuild case */ | |
4274 | for (d = array->devs; d; d = d->next) | |
4275 | if (d->recovery_start == 0) { | |
4276 | if (rebuild) | |
4277 | return; | |
4278 | rebuild = d; | |
4279 | } | |
4280 | ||
4363fd80 DW |
4281 | if (!rebuild) { |
4282 | /* (?) none of the disks are marked with | |
4283 | * IMSM_ORD_REBUILD, so assume they are missing and the | |
4284 | * disk_ord_tbl was not correctly updated | |
4285 | */ | |
4286 | dprintf("%s: failed to locate out-of-sync disk\n", __func__); | |
4287 | return; | |
4288 | } | |
4289 | ||
1e5c6983 DW |
4290 | units = __le32_to_cpu(dev->vol.curr_migr_unit); |
4291 | rebuild->recovery_start = units * blocks_per_migr_unit(dev); | |
4292 | } | |
4293 | ||
4294 | ||
00bbdbda | 4295 | static struct mdinfo *container_content_imsm(struct supertype *st, char *subarray) |
cdddbdbc | 4296 | { |
4f5bc454 DW |
4297 | /* Given a container loaded by load_super_imsm_all, |
4298 | * extract information about all the arrays into | |
4299 | * an mdinfo tree. | |
00bbdbda | 4300 | * If 'subarray' is given, just extract info about that array. |
4f5bc454 DW |
4301 | * |
4302 | * For each imsm_dev create an mdinfo, fill it in, | |
4303 | * then look for matching devices in super->disks | |
4304 | * and create appropriate device mdinfo. | |
4305 | */ | |
4306 | struct intel_super *super = st->sb; | |
949c47a0 | 4307 | struct imsm_super *mpb = super->anchor; |
4f5bc454 | 4308 | struct mdinfo *rest = NULL; |
00bbdbda | 4309 | unsigned int i; |
cdddbdbc | 4310 | |
604b746f JD |
4311 | /* do not assemble arrays that might have bad blocks */ |
4312 | if (imsm_bbm_log_size(super->anchor)) { | |
4313 | fprintf(stderr, Name ": BBM log found in metadata. " | |
4314 | "Cannot activate array(s).\n"); | |
4315 | return NULL; | |
4316 | } | |
4317 | ||
4f5bc454 | 4318 | for (i = 0; i < mpb->num_raid_devs; i++) { |
00bbdbda N |
4319 | struct imsm_dev *dev; |
4320 | struct imsm_map *map; | |
4f5bc454 | 4321 | struct mdinfo *this; |
4f5bc454 | 4322 | int slot; |
00bbdbda N |
4323 | char *ep; |
4324 | ||
4325 | if (subarray && | |
4326 | (i != strtoul(subarray, &ep, 10) || *ep != '\0')) | |
4327 | continue; | |
4328 | ||
4329 | dev = get_imsm_dev(super, i); | |
4330 | map = get_imsm_map(dev, 0); | |
4f5bc454 | 4331 | |
1ce0101c DW |
4332 | /* do not publish arrays that are in the middle of an |
4333 | * unsupported migration | |
4334 | */ | |
4335 | if (dev->vol.migr_state && | |
4336 | (migr_type(dev) == MIGR_GEN_MIGR || | |
4337 | migr_type(dev) == MIGR_STATE_CHANGE)) { | |
4338 | fprintf(stderr, Name ": cannot assemble volume '%.16s':" | |
4339 | " unsupported migration in progress\n", | |
4340 | dev->volume); | |
4341 | continue; | |
4342 | } | |
4343 | ||
4f5bc454 | 4344 | this = malloc(sizeof(*this)); |
0fbd635c | 4345 | if (!this) { |
cf1be220 | 4346 | fprintf(stderr, Name ": failed to allocate %zu bytes\n", |
0fbd635c AW |
4347 | sizeof(*this)); |
4348 | break; | |
4349 | } | |
4f5bc454 DW |
4350 | memset(this, 0, sizeof(*this)); |
4351 | this->next = rest; | |
4f5bc454 | 4352 | |
301406c9 | 4353 | super->current_vol = i; |
a5d85af7 | 4354 | getinfo_super_imsm_volume(st, this, NULL); |
4f5bc454 | 4355 | for (slot = 0 ; slot < map->num_members; slot++) { |
1e5c6983 | 4356 | unsigned long long recovery_start; |
4f5bc454 DW |
4357 | struct mdinfo *info_d; |
4358 | struct dl *d; | |
4359 | int idx; | |
9a1608e5 | 4360 | int skip; |
7eef0453 | 4361 | __u32 ord; |
4f5bc454 | 4362 | |
9a1608e5 | 4363 | skip = 0; |
ff077194 | 4364 | idx = get_imsm_disk_idx(dev, slot); |
7eef0453 | 4365 | ord = get_imsm_ord_tbl_ent(dev, slot); |
4f5bc454 DW |
4366 | for (d = super->disks; d ; d = d->next) |
4367 | if (d->index == idx) | |
0fbd635c | 4368 | break; |
4f5bc454 | 4369 | |
1e5c6983 | 4370 | recovery_start = MaxSector; |
4f5bc454 | 4371 | if (d == NULL) |
9a1608e5 | 4372 | skip = 1; |
25ed7e59 | 4373 | if (d && is_failed(&d->disk)) |
9a1608e5 | 4374 | skip = 1; |
7eef0453 | 4375 | if (ord & IMSM_ORD_REBUILD) |
1e5c6983 | 4376 | recovery_start = 0; |
9a1608e5 DW |
4377 | |
4378 | /* | |
4379 | * if we skip some disks the array will be assmebled degraded; | |
1e5c6983 DW |
4380 | * reset resync start to avoid a dirty-degraded |
4381 | * situation when performing the intial sync | |
9a1608e5 DW |
4382 | * |
4383 | * FIXME handle dirty degraded | |
4384 | */ | |
1e5c6983 | 4385 | if ((skip || recovery_start == 0) && !dev->vol.dirty) |
b7528a20 | 4386 | this->resync_start = MaxSector; |
9a1608e5 DW |
4387 | if (skip) |
4388 | continue; | |
4f5bc454 | 4389 | |
1e5c6983 | 4390 | info_d = calloc(1, sizeof(*info_d)); |
9a1608e5 DW |
4391 | if (!info_d) { |
4392 | fprintf(stderr, Name ": failed to allocate disk" | |
1ce0101c | 4393 | " for volume %.16s\n", dev->volume); |
1e5c6983 DW |
4394 | info_d = this->devs; |
4395 | while (info_d) { | |
4396 | struct mdinfo *d = info_d->next; | |
4397 | ||
4398 | free(info_d); | |
4399 | info_d = d; | |
4400 | } | |
9a1608e5 DW |
4401 | free(this); |
4402 | this = rest; | |
4403 | break; | |
4404 | } | |
4f5bc454 DW |
4405 | info_d->next = this->devs; |
4406 | this->devs = info_d; | |
4407 | ||
4f5bc454 DW |
4408 | info_d->disk.number = d->index; |
4409 | info_d->disk.major = d->major; | |
4410 | info_d->disk.minor = d->minor; | |
4411 | info_d->disk.raid_disk = slot; | |
1e5c6983 | 4412 | info_d->recovery_start = recovery_start; |
4f5bc454 | 4413 | |
1e5c6983 DW |
4414 | if (info_d->recovery_start == MaxSector) |
4415 | this->array.working_disks++; | |
4f5bc454 DW |
4416 | |
4417 | info_d->events = __le32_to_cpu(mpb->generation_num); | |
4418 | info_d->data_offset = __le32_to_cpu(map->pba_of_lba0); | |
4419 | info_d->component_size = __le32_to_cpu(map->blocks_per_member); | |
4f5bc454 | 4420 | } |
1e5c6983 DW |
4421 | /* now that the disk list is up-to-date fixup recovery_start */ |
4422 | update_recovery_start(dev, this); | |
9a1608e5 | 4423 | rest = this; |
4f5bc454 DW |
4424 | } |
4425 | ||
4426 | return rest; | |
cdddbdbc DW |
4427 | } |
4428 | ||
845dea95 | 4429 | |
fb49eef2 | 4430 | static __u8 imsm_check_degraded(struct intel_super *super, struct imsm_dev *dev, int failed) |
c2a1e7da | 4431 | { |
a965f303 | 4432 | struct imsm_map *map = get_imsm_map(dev, 0); |
c2a1e7da DW |
4433 | |
4434 | if (!failed) | |
3393c6af DW |
4435 | return map->map_state == IMSM_T_STATE_UNINITIALIZED ? |
4436 | IMSM_T_STATE_UNINITIALIZED : IMSM_T_STATE_NORMAL; | |
c2a1e7da DW |
4437 | |
4438 | switch (get_imsm_raid_level(map)) { | |
4439 | case 0: | |
4440 | return IMSM_T_STATE_FAILED; | |
4441 | break; | |
4442 | case 1: | |
4443 | if (failed < map->num_members) | |
4444 | return IMSM_T_STATE_DEGRADED; | |
4445 | else | |
4446 | return IMSM_T_STATE_FAILED; | |
4447 | break; | |
4448 | case 10: | |
4449 | { | |
4450 | /** | |
c92a2527 DW |
4451 | * check to see if any mirrors have failed, otherwise we |
4452 | * are degraded. Even numbered slots are mirrored on | |
4453 | * slot+1 | |
c2a1e7da | 4454 | */ |
c2a1e7da | 4455 | int i; |
d9b420a5 N |
4456 | /* gcc -Os complains that this is unused */ |
4457 | int insync = insync; | |
c2a1e7da DW |
4458 | |
4459 | for (i = 0; i < map->num_members; i++) { | |
c92a2527 DW |
4460 | __u32 ord = get_imsm_ord_tbl_ent(dev, i); |
4461 | int idx = ord_to_idx(ord); | |
4462 | struct imsm_disk *disk; | |
c2a1e7da | 4463 | |
c92a2527 DW |
4464 | /* reset the potential in-sync count on even-numbered |
4465 | * slots. num_copies is always 2 for imsm raid10 | |
4466 | */ | |
4467 | if ((i & 1) == 0) | |
4468 | insync = 2; | |
c2a1e7da | 4469 | |
c92a2527 | 4470 | disk = get_imsm_disk(super, idx); |
25ed7e59 | 4471 | if (!disk || is_failed(disk) || ord & IMSM_ORD_REBUILD) |
c92a2527 | 4472 | insync--; |
c2a1e7da | 4473 | |
c92a2527 DW |
4474 | /* no in-sync disks left in this mirror the |
4475 | * array has failed | |
4476 | */ | |
4477 | if (insync == 0) | |
4478 | return IMSM_T_STATE_FAILED; | |
c2a1e7da DW |
4479 | } |
4480 | ||
4481 | return IMSM_T_STATE_DEGRADED; | |
4482 | } | |
4483 | case 5: | |
4484 | if (failed < 2) | |
4485 | return IMSM_T_STATE_DEGRADED; | |
4486 | else | |
4487 | return IMSM_T_STATE_FAILED; | |
4488 | break; | |
4489 | default: | |
4490 | break; | |
4491 | } | |
4492 | ||
4493 | return map->map_state; | |
4494 | } | |
4495 | ||
ff077194 | 4496 | static int imsm_count_failed(struct intel_super *super, struct imsm_dev *dev) |
c2a1e7da DW |
4497 | { |
4498 | int i; | |
4499 | int failed = 0; | |
4500 | struct imsm_disk *disk; | |
ff077194 | 4501 | struct imsm_map *map = get_imsm_map(dev, 0); |
0556e1a2 DW |
4502 | struct imsm_map *prev = get_imsm_map(dev, dev->vol.migr_state); |
4503 | __u32 ord; | |
4504 | int idx; | |
c2a1e7da | 4505 | |
0556e1a2 DW |
4506 | /* at the beginning of migration we set IMSM_ORD_REBUILD on |
4507 | * disks that are being rebuilt. New failures are recorded to | |
4508 | * map[0]. So we look through all the disks we started with and | |
4509 | * see if any failures are still present, or if any new ones | |
4510 | * have arrived | |
4511 | * | |
4512 | * FIXME add support for online capacity expansion and | |
4513 | * raid-level-migration | |
4514 | */ | |
4515 | for (i = 0; i < prev->num_members; i++) { | |
4516 | ord = __le32_to_cpu(prev->disk_ord_tbl[i]); | |
4517 | ord |= __le32_to_cpu(map->disk_ord_tbl[i]); | |
4518 | idx = ord_to_idx(ord); | |
c2a1e7da | 4519 | |
949c47a0 | 4520 | disk = get_imsm_disk(super, idx); |
25ed7e59 | 4521 | if (!disk || is_failed(disk) || ord & IMSM_ORD_REBUILD) |
fcb84475 | 4522 | failed++; |
c2a1e7da DW |
4523 | } |
4524 | ||
4525 | return failed; | |
845dea95 NB |
4526 | } |
4527 | ||
97b4d0e9 DW |
4528 | #ifndef MDASSEMBLE |
4529 | static int imsm_open_new(struct supertype *c, struct active_array *a, | |
4530 | char *inst) | |
4531 | { | |
4532 | struct intel_super *super = c->sb; | |
4533 | struct imsm_super *mpb = super->anchor; | |
4534 | ||
4535 | if (atoi(inst) >= mpb->num_raid_devs) { | |
4536 | fprintf(stderr, "%s: subarry index %d, out of range\n", | |
4537 | __func__, atoi(inst)); | |
4538 | return -ENODEV; | |
4539 | } | |
4540 | ||
4541 | dprintf("imsm: open_new %s\n", inst); | |
4542 | a->info.container_member = atoi(inst); | |
4543 | return 0; | |
4544 | } | |
4545 | ||
0c046afd DW |
4546 | static int is_resyncing(struct imsm_dev *dev) |
4547 | { | |
4548 | struct imsm_map *migr_map; | |
4549 | ||
4550 | if (!dev->vol.migr_state) | |
4551 | return 0; | |
4552 | ||
1484e727 DW |
4553 | if (migr_type(dev) == MIGR_INIT || |
4554 | migr_type(dev) == MIGR_REPAIR) | |
0c046afd DW |
4555 | return 1; |
4556 | ||
4557 | migr_map = get_imsm_map(dev, 1); | |
4558 | ||
4559 | if (migr_map->map_state == IMSM_T_STATE_NORMAL) | |
4560 | return 1; | |
4561 | else | |
4562 | return 0; | |
4563 | } | |
4564 | ||
0556e1a2 DW |
4565 | /* return true if we recorded new information */ |
4566 | static int mark_failure(struct imsm_dev *dev, struct imsm_disk *disk, int idx) | |
47ee5a45 | 4567 | { |
0556e1a2 DW |
4568 | __u32 ord; |
4569 | int slot; | |
4570 | struct imsm_map *map; | |
4571 | ||
4572 | /* new failures are always set in map[0] */ | |
4573 | map = get_imsm_map(dev, 0); | |
4574 | ||
4575 | slot = get_imsm_disk_slot(map, idx); | |
4576 | if (slot < 0) | |
4577 | return 0; | |
4578 | ||
4579 | ord = __le32_to_cpu(map->disk_ord_tbl[slot]); | |
25ed7e59 | 4580 | if (is_failed(disk) && (ord & IMSM_ORD_REBUILD)) |
0556e1a2 DW |
4581 | return 0; |
4582 | ||
f2f27e63 | 4583 | disk->status |= FAILED_DISK; |
cf53434e | 4584 | disk->status &= ~CONFIGURED_DISK; |
0556e1a2 | 4585 | set_imsm_ord_tbl_ent(map, slot, idx | IMSM_ORD_REBUILD); |
f21e18ca | 4586 | if (map->failed_disk_num == 0xff) |
0556e1a2 DW |
4587 | map->failed_disk_num = slot; |
4588 | return 1; | |
4589 | } | |
4590 | ||
4591 | static void mark_missing(struct imsm_dev *dev, struct imsm_disk *disk, int idx) | |
4592 | { | |
4593 | mark_failure(dev, disk, idx); | |
4594 | ||
4595 | if (disk->scsi_id == __cpu_to_le32(~(__u32)0)) | |
4596 | return; | |
4597 | ||
47ee5a45 DW |
4598 | disk->scsi_id = __cpu_to_le32(~(__u32)0); |
4599 | memmove(&disk->serial[0], &disk->serial[1], MAX_RAID_SERIAL_LEN - 1); | |
4600 | } | |
4601 | ||
33414a01 DW |
4602 | static void handle_missing(struct intel_super *super, struct imsm_dev *dev) |
4603 | { | |
4604 | __u8 map_state; | |
4605 | struct dl *dl; | |
4606 | int failed; | |
4607 | ||
4608 | if (!super->missing) | |
4609 | return; | |
4610 | failed = imsm_count_failed(super, dev); | |
4611 | map_state = imsm_check_degraded(super, dev, failed); | |
4612 | ||
4613 | dprintf("imsm: mark missing\n"); | |
4614 | end_migration(dev, map_state); | |
4615 | for (dl = super->missing; dl; dl = dl->next) | |
4616 | mark_missing(dev, &dl->disk, dl->index); | |
4617 | super->updates_pending++; | |
4618 | } | |
4619 | ||
0c046afd DW |
4620 | /* Handle dirty -> clean transititions and resync. Degraded and rebuild |
4621 | * states are handled in imsm_set_disk() with one exception, when a | |
4622 | * resync is stopped due to a new failure this routine will set the | |
4623 | * 'degraded' state for the array. | |
4624 | */ | |
01f157d7 | 4625 | static int imsm_set_array_state(struct active_array *a, int consistent) |
a862209d DW |
4626 | { |
4627 | int inst = a->info.container_member; | |
4628 | struct intel_super *super = a->container->sb; | |
949c47a0 | 4629 | struct imsm_dev *dev = get_imsm_dev(super, inst); |
a965f303 | 4630 | struct imsm_map *map = get_imsm_map(dev, 0); |
0c046afd DW |
4631 | int failed = imsm_count_failed(super, dev); |
4632 | __u8 map_state = imsm_check_degraded(super, dev, failed); | |
1e5c6983 | 4633 | __u32 blocks_per_unit; |
a862209d | 4634 | |
47ee5a45 | 4635 | /* before we activate this array handle any missing disks */ |
33414a01 DW |
4636 | if (consistent == 2) |
4637 | handle_missing(super, dev); | |
1e5c6983 | 4638 | |
0c046afd | 4639 | if (consistent == 2 && |
b7941fd6 | 4640 | (!is_resync_complete(&a->info) || |
0c046afd DW |
4641 | map_state != IMSM_T_STATE_NORMAL || |
4642 | dev->vol.migr_state)) | |
01f157d7 | 4643 | consistent = 0; |
272906ef | 4644 | |
b7941fd6 | 4645 | if (is_resync_complete(&a->info)) { |
0c046afd | 4646 | /* complete intialization / resync, |
0556e1a2 DW |
4647 | * recovery and interrupted recovery is completed in |
4648 | * ->set_disk | |
0c046afd DW |
4649 | */ |
4650 | if (is_resyncing(dev)) { | |
4651 | dprintf("imsm: mark resync done\n"); | |
f8f603f1 | 4652 | end_migration(dev, map_state); |
115c3803 | 4653 | super->updates_pending++; |
484240d8 | 4654 | a->last_checkpoint = 0; |
115c3803 | 4655 | } |
0c046afd DW |
4656 | } else if (!is_resyncing(dev) && !failed) { |
4657 | /* mark the start of the init process if nothing is failed */ | |
b7941fd6 | 4658 | dprintf("imsm: mark resync start\n"); |
1484e727 | 4659 | if (map->map_state == IMSM_T_STATE_UNINITIALIZED) |
e3bba0e0 | 4660 | migrate(dev, IMSM_T_STATE_NORMAL, MIGR_INIT); |
1484e727 DW |
4661 | else |
4662 | migrate(dev, IMSM_T_STATE_NORMAL, MIGR_REPAIR); | |
3393c6af | 4663 | super->updates_pending++; |
115c3803 | 4664 | } |
a862209d | 4665 | |
1e5c6983 DW |
4666 | /* check if we can update curr_migr_unit from resync_start, recovery_start */ |
4667 | blocks_per_unit = blocks_per_migr_unit(dev); | |
4f0a7acc | 4668 | if (blocks_per_unit) { |
1e5c6983 DW |
4669 | __u32 units32; |
4670 | __u64 units; | |
4671 | ||
4f0a7acc | 4672 | units = a->last_checkpoint / blocks_per_unit; |
1e5c6983 DW |
4673 | units32 = units; |
4674 | ||
4675 | /* check that we did not overflow 32-bits, and that | |
4676 | * curr_migr_unit needs updating | |
4677 | */ | |
4678 | if (units32 == units && | |
4679 | __le32_to_cpu(dev->vol.curr_migr_unit) != units32) { | |
4680 | dprintf("imsm: mark checkpoint (%u)\n", units32); | |
4681 | dev->vol.curr_migr_unit = __cpu_to_le32(units32); | |
4682 | super->updates_pending++; | |
4683 | } | |
4684 | } | |
f8f603f1 | 4685 | |
3393c6af | 4686 | /* mark dirty / clean */ |
0c046afd | 4687 | if (dev->vol.dirty != !consistent) { |
b7941fd6 | 4688 | dprintf("imsm: mark '%s'\n", consistent ? "clean" : "dirty"); |
0c046afd DW |
4689 | if (consistent) |
4690 | dev->vol.dirty = 0; | |
4691 | else | |
4692 | dev->vol.dirty = 1; | |
a862209d DW |
4693 | super->updates_pending++; |
4694 | } | |
01f157d7 | 4695 | return consistent; |
a862209d DW |
4696 | } |
4697 | ||
8d45d196 | 4698 | static void imsm_set_disk(struct active_array *a, int n, int state) |
845dea95 | 4699 | { |
8d45d196 DW |
4700 | int inst = a->info.container_member; |
4701 | struct intel_super *super = a->container->sb; | |
949c47a0 | 4702 | struct imsm_dev *dev = get_imsm_dev(super, inst); |
a965f303 | 4703 | struct imsm_map *map = get_imsm_map(dev, 0); |
8d45d196 | 4704 | struct imsm_disk *disk; |
0c046afd | 4705 | int failed; |
b10b37b8 | 4706 | __u32 ord; |
0c046afd | 4707 | __u8 map_state; |
8d45d196 DW |
4708 | |
4709 | if (n > map->num_members) | |
4710 | fprintf(stderr, "imsm: set_disk %d out of range 0..%d\n", | |
4711 | n, map->num_members - 1); | |
4712 | ||
4713 | if (n < 0) | |
4714 | return; | |
4715 | ||
4e6e574a | 4716 | dprintf("imsm: set_disk %d:%x\n", n, state); |
8d45d196 | 4717 | |
b10b37b8 DW |
4718 | ord = get_imsm_ord_tbl_ent(dev, n); |
4719 | disk = get_imsm_disk(super, ord_to_idx(ord)); | |
8d45d196 | 4720 | |
5802a811 | 4721 | /* check for new failures */ |
0556e1a2 DW |
4722 | if (state & DS_FAULTY) { |
4723 | if (mark_failure(dev, disk, ord_to_idx(ord))) | |
4724 | super->updates_pending++; | |
8d45d196 | 4725 | } |
47ee5a45 | 4726 | |
19859edc | 4727 | /* check if in_sync */ |
0556e1a2 | 4728 | if (state & DS_INSYNC && ord & IMSM_ORD_REBUILD && is_rebuilding(dev)) { |
b10b37b8 DW |
4729 | struct imsm_map *migr_map = get_imsm_map(dev, 1); |
4730 | ||
4731 | set_imsm_ord_tbl_ent(migr_map, n, ord_to_idx(ord)); | |
19859edc DW |
4732 | super->updates_pending++; |
4733 | } | |
8d45d196 | 4734 | |
0c046afd DW |
4735 | failed = imsm_count_failed(super, dev); |
4736 | map_state = imsm_check_degraded(super, dev, failed); | |
5802a811 | 4737 | |
0c046afd DW |
4738 | /* check if recovery complete, newly degraded, or failed */ |
4739 | if (map_state == IMSM_T_STATE_NORMAL && is_rebuilding(dev)) { | |
f8f603f1 | 4740 | end_migration(dev, map_state); |
0556e1a2 DW |
4741 | map = get_imsm_map(dev, 0); |
4742 | map->failed_disk_num = ~0; | |
0c046afd | 4743 | super->updates_pending++; |
484240d8 | 4744 | a->last_checkpoint = 0; |
0c046afd DW |
4745 | } else if (map_state == IMSM_T_STATE_DEGRADED && |
4746 | map->map_state != map_state && | |
4747 | !dev->vol.migr_state) { | |
4748 | dprintf("imsm: mark degraded\n"); | |
4749 | map->map_state = map_state; | |
4750 | super->updates_pending++; | |
484240d8 | 4751 | a->last_checkpoint = 0; |
0c046afd DW |
4752 | } else if (map_state == IMSM_T_STATE_FAILED && |
4753 | map->map_state != map_state) { | |
4754 | dprintf("imsm: mark failed\n"); | |
f8f603f1 | 4755 | end_migration(dev, map_state); |
0c046afd | 4756 | super->updates_pending++; |
484240d8 | 4757 | a->last_checkpoint = 0; |
5802a811 | 4758 | } |
845dea95 NB |
4759 | } |
4760 | ||
f796af5d | 4761 | static int store_imsm_mpb(int fd, struct imsm_super *mpb) |
c2a1e7da | 4762 | { |
f796af5d | 4763 | void *buf = mpb; |
c2a1e7da DW |
4764 | __u32 mpb_size = __le32_to_cpu(mpb->mpb_size); |
4765 | unsigned long long dsize; | |
4766 | unsigned long long sectors; | |
4767 | ||
4768 | get_dev_size(fd, NULL, &dsize); | |
4769 | ||
272f648f DW |
4770 | if (mpb_size > 512) { |
4771 | /* -1 to account for anchor */ | |
4772 | sectors = mpb_sectors(mpb) - 1; | |
c2a1e7da | 4773 | |
272f648f DW |
4774 | /* write the extended mpb to the sectors preceeding the anchor */ |
4775 | if (lseek64(fd, dsize - (512 * (2 + sectors)), SEEK_SET) < 0) | |
4776 | return 1; | |
c2a1e7da | 4777 | |
f21e18ca N |
4778 | if ((unsigned long long)write(fd, buf + 512, 512 * sectors) |
4779 | != 512 * sectors) | |
272f648f DW |
4780 | return 1; |
4781 | } | |
c2a1e7da | 4782 | |
272f648f DW |
4783 | /* first block is stored on second to last sector of the disk */ |
4784 | if (lseek64(fd, dsize - (512 * 2), SEEK_SET) < 0) | |
c2a1e7da DW |
4785 | return 1; |
4786 | ||
f796af5d | 4787 | if (write(fd, buf, 512) != 512) |
c2a1e7da DW |
4788 | return 1; |
4789 | ||
c2a1e7da DW |
4790 | return 0; |
4791 | } | |
4792 | ||
2e735d19 | 4793 | static void imsm_sync_metadata(struct supertype *container) |
845dea95 | 4794 | { |
2e735d19 | 4795 | struct intel_super *super = container->sb; |
c2a1e7da DW |
4796 | |
4797 | if (!super->updates_pending) | |
4798 | return; | |
4799 | ||
c2c087e6 | 4800 | write_super_imsm(super, 0); |
c2a1e7da DW |
4801 | |
4802 | super->updates_pending = 0; | |
845dea95 NB |
4803 | } |
4804 | ||
272906ef DW |
4805 | static struct dl *imsm_readd(struct intel_super *super, int idx, struct active_array *a) |
4806 | { | |
4807 | struct imsm_dev *dev = get_imsm_dev(super, a->info.container_member); | |
ff077194 | 4808 | int i = get_imsm_disk_idx(dev, idx); |
272906ef DW |
4809 | struct dl *dl; |
4810 | ||
4811 | for (dl = super->disks; dl; dl = dl->next) | |
4812 | if (dl->index == i) | |
4813 | break; | |
4814 | ||
25ed7e59 | 4815 | if (dl && is_failed(&dl->disk)) |
272906ef DW |
4816 | dl = NULL; |
4817 | ||
4818 | if (dl) | |
4819 | dprintf("%s: found %x:%x\n", __func__, dl->major, dl->minor); | |
4820 | ||
4821 | return dl; | |
4822 | } | |
4823 | ||
a20d2ba5 DW |
4824 | static struct dl *imsm_add_spare(struct intel_super *super, int slot, |
4825 | struct active_array *a, int activate_new) | |
272906ef DW |
4826 | { |
4827 | struct imsm_dev *dev = get_imsm_dev(super, a->info.container_member); | |
e553d2a4 | 4828 | int idx = get_imsm_disk_idx(dev, slot); |
a20d2ba5 DW |
4829 | struct imsm_super *mpb = super->anchor; |
4830 | struct imsm_map *map; | |
272906ef DW |
4831 | unsigned long long pos; |
4832 | struct mdinfo *d; | |
4833 | struct extent *ex; | |
a20d2ba5 | 4834 | int i, j; |
272906ef | 4835 | int found; |
569cc43f DW |
4836 | __u32 array_start = 0; |
4837 | __u32 array_end = 0; | |
272906ef DW |
4838 | struct dl *dl; |
4839 | ||
4840 | for (dl = super->disks; dl; dl = dl->next) { | |
4841 | /* If in this array, skip */ | |
4842 | for (d = a->info.devs ; d ; d = d->next) | |
e553d2a4 DW |
4843 | if (d->state_fd >= 0 && |
4844 | d->disk.major == dl->major && | |
272906ef DW |
4845 | d->disk.minor == dl->minor) { |
4846 | dprintf("%x:%x already in array\n", dl->major, dl->minor); | |
4847 | break; | |
4848 | } | |
4849 | if (d) | |
4850 | continue; | |
4851 | ||
e553d2a4 | 4852 | /* skip in use or failed drives */ |
25ed7e59 | 4853 | if (is_failed(&dl->disk) || idx == dl->index || |
df474657 DW |
4854 | dl->index == -2) { |
4855 | dprintf("%x:%x status (failed: %d index: %d)\n", | |
25ed7e59 | 4856 | dl->major, dl->minor, is_failed(&dl->disk), idx); |
9a1608e5 DW |
4857 | continue; |
4858 | } | |
4859 | ||
a20d2ba5 DW |
4860 | /* skip pure spares when we are looking for partially |
4861 | * assimilated drives | |
4862 | */ | |
4863 | if (dl->index == -1 && !activate_new) | |
4864 | continue; | |
4865 | ||
272906ef | 4866 | /* Does this unused device have the requisite free space? |
a20d2ba5 | 4867 | * It needs to be able to cover all member volumes |
272906ef DW |
4868 | */ |
4869 | ex = get_extents(super, dl); | |
4870 | if (!ex) { | |
4871 | dprintf("cannot get extents\n"); | |
4872 | continue; | |
4873 | } | |
a20d2ba5 DW |
4874 | for (i = 0; i < mpb->num_raid_devs; i++) { |
4875 | dev = get_imsm_dev(super, i); | |
4876 | map = get_imsm_map(dev, 0); | |
272906ef | 4877 | |
a20d2ba5 DW |
4878 | /* check if this disk is already a member of |
4879 | * this array | |
272906ef | 4880 | */ |
620b1713 | 4881 | if (get_imsm_disk_slot(map, dl->index) >= 0) |
a20d2ba5 DW |
4882 | continue; |
4883 | ||
4884 | found = 0; | |
4885 | j = 0; | |
4886 | pos = 0; | |
4887 | array_start = __le32_to_cpu(map->pba_of_lba0); | |
329c8278 DW |
4888 | array_end = array_start + |
4889 | __le32_to_cpu(map->blocks_per_member) - 1; | |
a20d2ba5 DW |
4890 | |
4891 | do { | |
4892 | /* check that we can start at pba_of_lba0 with | |
4893 | * blocks_per_member of space | |
4894 | */ | |
329c8278 | 4895 | if (array_start >= pos && array_end < ex[j].start) { |
a20d2ba5 DW |
4896 | found = 1; |
4897 | break; | |
4898 | } | |
4899 | pos = ex[j].start + ex[j].size; | |
4900 | j++; | |
4901 | } while (ex[j-1].size); | |
4902 | ||
4903 | if (!found) | |
272906ef | 4904 | break; |
a20d2ba5 | 4905 | } |
272906ef DW |
4906 | |
4907 | free(ex); | |
a20d2ba5 | 4908 | if (i < mpb->num_raid_devs) { |
329c8278 DW |
4909 | dprintf("%x:%x does not have %u to %u available\n", |
4910 | dl->major, dl->minor, array_start, array_end); | |
272906ef DW |
4911 | /* No room */ |
4912 | continue; | |
a20d2ba5 DW |
4913 | } |
4914 | return dl; | |
272906ef DW |
4915 | } |
4916 | ||
4917 | return dl; | |
4918 | } | |
4919 | ||
88758e9d DW |
4920 | static struct mdinfo *imsm_activate_spare(struct active_array *a, |
4921 | struct metadata_update **updates) | |
4922 | { | |
4923 | /** | |
d23fe947 DW |
4924 | * Find a device with unused free space and use it to replace a |
4925 | * failed/vacant region in an array. We replace failed regions one a | |
4926 | * array at a time. The result is that a new spare disk will be added | |
4927 | * to the first failed array and after the monitor has finished | |
4928 | * propagating failures the remainder will be consumed. | |
88758e9d | 4929 | * |
d23fe947 DW |
4930 | * FIXME add a capability for mdmon to request spares from another |
4931 | * container. | |
88758e9d DW |
4932 | */ |
4933 | ||
4934 | struct intel_super *super = a->container->sb; | |
88758e9d | 4935 | int inst = a->info.container_member; |
949c47a0 | 4936 | struct imsm_dev *dev = get_imsm_dev(super, inst); |
a965f303 | 4937 | struct imsm_map *map = get_imsm_map(dev, 0); |
88758e9d DW |
4938 | int failed = a->info.array.raid_disks; |
4939 | struct mdinfo *rv = NULL; | |
4940 | struct mdinfo *d; | |
4941 | struct mdinfo *di; | |
4942 | struct metadata_update *mu; | |
4943 | struct dl *dl; | |
4944 | struct imsm_update_activate_spare *u; | |
4945 | int num_spares = 0; | |
4946 | int i; | |
4947 | ||
4948 | for (d = a->info.devs ; d ; d = d->next) { | |
4949 | if ((d->curr_state & DS_FAULTY) && | |
4950 | d->state_fd >= 0) | |
4951 | /* wait for Removal to happen */ | |
4952 | return NULL; | |
4953 | if (d->state_fd >= 0) | |
4954 | failed--; | |
4955 | } | |
4956 | ||
4957 | dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n", | |
4958 | inst, failed, a->info.array.raid_disks, a->info.array.level); | |
fb49eef2 | 4959 | if (imsm_check_degraded(super, dev, failed) != IMSM_T_STATE_DEGRADED) |
88758e9d DW |
4960 | return NULL; |
4961 | ||
4962 | /* For each slot, if it is not working, find a spare */ | |
88758e9d DW |
4963 | for (i = 0; i < a->info.array.raid_disks; i++) { |
4964 | for (d = a->info.devs ; d ; d = d->next) | |
4965 | if (d->disk.raid_disk == i) | |
4966 | break; | |
4967 | dprintf("found %d: %p %x\n", i, d, d?d->curr_state:0); | |
4968 | if (d && (d->state_fd >= 0)) | |
4969 | continue; | |
4970 | ||
272906ef | 4971 | /* |
a20d2ba5 DW |
4972 | * OK, this device needs recovery. Try to re-add the |
4973 | * previous occupant of this slot, if this fails see if | |
4974 | * we can continue the assimilation of a spare that was | |
4975 | * partially assimilated, finally try to activate a new | |
4976 | * spare. | |
272906ef DW |
4977 | */ |
4978 | dl = imsm_readd(super, i, a); | |
4979 | if (!dl) | |
a20d2ba5 DW |
4980 | dl = imsm_add_spare(super, i, a, 0); |
4981 | if (!dl) | |
4982 | dl = imsm_add_spare(super, i, a, 1); | |
272906ef DW |
4983 | if (!dl) |
4984 | continue; | |
4985 | ||
4986 | /* found a usable disk with enough space */ | |
4987 | di = malloc(sizeof(*di)); | |
79244939 DW |
4988 | if (!di) |
4989 | continue; | |
272906ef DW |
4990 | memset(di, 0, sizeof(*di)); |
4991 | ||
4992 | /* dl->index will be -1 in the case we are activating a | |
4993 | * pristine spare. imsm_process_update() will create a | |
4994 | * new index in this case. Once a disk is found to be | |
4995 | * failed in all member arrays it is kicked from the | |
4996 | * metadata | |
4997 | */ | |
4998 | di->disk.number = dl->index; | |
d23fe947 | 4999 | |
272906ef DW |
5000 | /* (ab)use di->devs to store a pointer to the device |
5001 | * we chose | |
5002 | */ | |
5003 | di->devs = (struct mdinfo *) dl; | |
5004 | ||
5005 | di->disk.raid_disk = i; | |
5006 | di->disk.major = dl->major; | |
5007 | di->disk.minor = dl->minor; | |
5008 | di->disk.state = 0; | |
d23534e4 | 5009 | di->recovery_start = 0; |
272906ef DW |
5010 | di->data_offset = __le32_to_cpu(map->pba_of_lba0); |
5011 | di->component_size = a->info.component_size; | |
5012 | di->container_member = inst; | |
148acb7b | 5013 | super->random = random32(); |
272906ef DW |
5014 | di->next = rv; |
5015 | rv = di; | |
5016 | num_spares++; | |
5017 | dprintf("%x:%x to be %d at %llu\n", dl->major, dl->minor, | |
5018 | i, di->data_offset); | |
88758e9d | 5019 | |
272906ef | 5020 | break; |
88758e9d DW |
5021 | } |
5022 | ||
5023 | if (!rv) | |
5024 | /* No spares found */ | |
5025 | return rv; | |
5026 | /* Now 'rv' has a list of devices to return. | |
5027 | * Create a metadata_update record to update the | |
5028 | * disk_ord_tbl for the array | |
5029 | */ | |
5030 | mu = malloc(sizeof(*mu)); | |
79244939 DW |
5031 | if (mu) { |
5032 | mu->buf = malloc(sizeof(struct imsm_update_activate_spare) * num_spares); | |
5033 | if (mu->buf == NULL) { | |
5034 | free(mu); | |
5035 | mu = NULL; | |
5036 | } | |
5037 | } | |
5038 | if (!mu) { | |
5039 | while (rv) { | |
5040 | struct mdinfo *n = rv->next; | |
5041 | ||
5042 | free(rv); | |
5043 | rv = n; | |
5044 | } | |
5045 | return NULL; | |
5046 | } | |
5047 | ||
88758e9d DW |
5048 | mu->space = NULL; |
5049 | mu->len = sizeof(struct imsm_update_activate_spare) * num_spares; | |
5050 | mu->next = *updates; | |
5051 | u = (struct imsm_update_activate_spare *) mu->buf; | |
5052 | ||
5053 | for (di = rv ; di ; di = di->next) { | |
5054 | u->type = update_activate_spare; | |
d23fe947 DW |
5055 | u->dl = (struct dl *) di->devs; |
5056 | di->devs = NULL; | |
88758e9d DW |
5057 | u->slot = di->disk.raid_disk; |
5058 | u->array = inst; | |
5059 | u->next = u + 1; | |
5060 | u++; | |
5061 | } | |
5062 | (u-1)->next = NULL; | |
5063 | *updates = mu; | |
5064 | ||
5065 | return rv; | |
5066 | } | |
5067 | ||
54c2c1ea | 5068 | static int disks_overlap(struct intel_super *super, int idx, struct imsm_update_create_array *u) |
8273f55e | 5069 | { |
54c2c1ea DW |
5070 | struct imsm_dev *dev = get_imsm_dev(super, idx); |
5071 | struct imsm_map *map = get_imsm_map(dev, 0); | |
5072 | struct imsm_map *new_map = get_imsm_map(&u->dev, 0); | |
5073 | struct disk_info *inf = get_disk_info(u); | |
5074 | struct imsm_disk *disk; | |
8273f55e DW |
5075 | int i; |
5076 | int j; | |
8273f55e | 5077 | |
54c2c1ea DW |
5078 | for (i = 0; i < map->num_members; i++) { |
5079 | disk = get_imsm_disk(super, get_imsm_disk_idx(dev, i)); | |
5080 | for (j = 0; j < new_map->num_members; j++) | |
5081 | if (serialcmp(disk->serial, inf[j].serial) == 0) | |
8273f55e DW |
5082 | return 1; |
5083 | } | |
5084 | ||
5085 | return 0; | |
5086 | } | |
5087 | ||
f21e18ca | 5088 | static void imsm_delete(struct intel_super *super, struct dl **dlp, unsigned index); |
ae6aad82 | 5089 | |
e8319a19 DW |
5090 | static void imsm_process_update(struct supertype *st, |
5091 | struct metadata_update *update) | |
5092 | { | |
5093 | /** | |
5094 | * crack open the metadata_update envelope to find the update record | |
5095 | * update can be one of: | |
5096 | * update_activate_spare - a spare device has replaced a failed | |
5097 | * device in an array, update the disk_ord_tbl. If this disk is | |
5098 | * present in all member arrays then also clear the SPARE_DISK | |
5099 | * flag | |
5100 | */ | |
5101 | struct intel_super *super = st->sb; | |
4d7b1503 | 5102 | struct imsm_super *mpb; |
e8319a19 DW |
5103 | enum imsm_update_type type = *(enum imsm_update_type *) update->buf; |
5104 | ||
4d7b1503 DW |
5105 | /* update requires a larger buf but the allocation failed */ |
5106 | if (super->next_len && !super->next_buf) { | |
5107 | super->next_len = 0; | |
5108 | return; | |
5109 | } | |
5110 | ||
5111 | if (super->next_buf) { | |
5112 | memcpy(super->next_buf, super->buf, super->len); | |
5113 | free(super->buf); | |
5114 | super->len = super->next_len; | |
5115 | super->buf = super->next_buf; | |
5116 | ||
5117 | super->next_len = 0; | |
5118 | super->next_buf = NULL; | |
5119 | } | |
5120 | ||
5121 | mpb = super->anchor; | |
5122 | ||
e8319a19 DW |
5123 | switch (type) { |
5124 | case update_activate_spare: { | |
5125 | struct imsm_update_activate_spare *u = (void *) update->buf; | |
949c47a0 | 5126 | struct imsm_dev *dev = get_imsm_dev(super, u->array); |
a965f303 | 5127 | struct imsm_map *map = get_imsm_map(dev, 0); |
0c046afd | 5128 | struct imsm_map *migr_map; |
e8319a19 DW |
5129 | struct active_array *a; |
5130 | struct imsm_disk *disk; | |
0c046afd | 5131 | __u8 to_state; |
e8319a19 | 5132 | struct dl *dl; |
e8319a19 | 5133 | unsigned int found; |
0c046afd DW |
5134 | int failed; |
5135 | int victim = get_imsm_disk_idx(dev, u->slot); | |
e8319a19 DW |
5136 | int i; |
5137 | ||
5138 | for (dl = super->disks; dl; dl = dl->next) | |
d23fe947 | 5139 | if (dl == u->dl) |
e8319a19 DW |
5140 | break; |
5141 | ||
5142 | if (!dl) { | |
5143 | fprintf(stderr, "error: imsm_activate_spare passed " | |
1f24f035 DW |
5144 | "an unknown disk (index: %d)\n", |
5145 | u->dl->index); | |
e8319a19 DW |
5146 | return; |
5147 | } | |
5148 | ||
5149 | super->updates_pending++; | |
5150 | ||
0c046afd DW |
5151 | /* count failures (excluding rebuilds and the victim) |
5152 | * to determine map[0] state | |
5153 | */ | |
5154 | failed = 0; | |
5155 | for (i = 0; i < map->num_members; i++) { | |
5156 | if (i == u->slot) | |
5157 | continue; | |
5158 | disk = get_imsm_disk(super, get_imsm_disk_idx(dev, i)); | |
25ed7e59 | 5159 | if (!disk || is_failed(disk)) |
0c046afd DW |
5160 | failed++; |
5161 | } | |
5162 | ||
d23fe947 DW |
5163 | /* adding a pristine spare, assign a new index */ |
5164 | if (dl->index < 0) { | |
5165 | dl->index = super->anchor->num_disks; | |
5166 | super->anchor->num_disks++; | |
5167 | } | |
d23fe947 | 5168 | disk = &dl->disk; |
f2f27e63 DW |
5169 | disk->status |= CONFIGURED_DISK; |
5170 | disk->status &= ~SPARE_DISK; | |
e8319a19 | 5171 | |
0c046afd DW |
5172 | /* mark rebuild */ |
5173 | to_state = imsm_check_degraded(super, dev, failed); | |
5174 | map->map_state = IMSM_T_STATE_DEGRADED; | |
e3bba0e0 | 5175 | migrate(dev, to_state, MIGR_REBUILD); |
0c046afd DW |
5176 | migr_map = get_imsm_map(dev, 1); |
5177 | set_imsm_ord_tbl_ent(map, u->slot, dl->index); | |
5178 | set_imsm_ord_tbl_ent(migr_map, u->slot, dl->index | IMSM_ORD_REBUILD); | |
5179 | ||
148acb7b DW |
5180 | /* update the family_num to mark a new container |
5181 | * generation, being careful to record the existing | |
5182 | * family_num in orig_family_num to clean up after | |
5183 | * earlier mdadm versions that neglected to set it. | |
5184 | */ | |
5185 | if (mpb->orig_family_num == 0) | |
5186 | mpb->orig_family_num = mpb->family_num; | |
5187 | mpb->family_num += super->random; | |
5188 | ||
e8319a19 DW |
5189 | /* count arrays using the victim in the metadata */ |
5190 | found = 0; | |
5191 | for (a = st->arrays; a ; a = a->next) { | |
949c47a0 | 5192 | dev = get_imsm_dev(super, a->info.container_member); |
620b1713 DW |
5193 | map = get_imsm_map(dev, 0); |
5194 | ||
5195 | if (get_imsm_disk_slot(map, victim) >= 0) | |
5196 | found++; | |
e8319a19 DW |
5197 | } |
5198 | ||
24565c9a | 5199 | /* delete the victim if it is no longer being |
e8319a19 DW |
5200 | * utilized anywhere |
5201 | */ | |
e8319a19 | 5202 | if (!found) { |
ae6aad82 | 5203 | struct dl **dlp; |
24565c9a | 5204 | |
47ee5a45 DW |
5205 | /* We know that 'manager' isn't touching anything, |
5206 | * so it is safe to delete | |
5207 | */ | |
24565c9a | 5208 | for (dlp = &super->disks; *dlp; dlp = &(*dlp)->next) |
ae6aad82 DW |
5209 | if ((*dlp)->index == victim) |
5210 | break; | |
47ee5a45 DW |
5211 | |
5212 | /* victim may be on the missing list */ | |
5213 | if (!*dlp) | |
5214 | for (dlp = &super->missing; *dlp; dlp = &(*dlp)->next) | |
5215 | if ((*dlp)->index == victim) | |
5216 | break; | |
24565c9a | 5217 | imsm_delete(super, dlp, victim); |
e8319a19 | 5218 | } |
8273f55e DW |
5219 | break; |
5220 | } | |
5221 | case update_create_array: { | |
5222 | /* someone wants to create a new array, we need to be aware of | |
5223 | * a few races/collisions: | |
5224 | * 1/ 'Create' called by two separate instances of mdadm | |
5225 | * 2/ 'Create' versus 'activate_spare': mdadm has chosen | |
5226 | * devices that have since been assimilated via | |
5227 | * activate_spare. | |
5228 | * In the event this update can not be carried out mdadm will | |
5229 | * (FIX ME) notice that its update did not take hold. | |
5230 | */ | |
5231 | struct imsm_update_create_array *u = (void *) update->buf; | |
ba2de7ba | 5232 | struct intel_dev *dv; |
8273f55e DW |
5233 | struct imsm_dev *dev; |
5234 | struct imsm_map *map, *new_map; | |
5235 | unsigned long long start, end; | |
5236 | unsigned long long new_start, new_end; | |
5237 | int i; | |
54c2c1ea DW |
5238 | struct disk_info *inf; |
5239 | struct dl *dl; | |
8273f55e DW |
5240 | |
5241 | /* handle racing creates: first come first serve */ | |
5242 | if (u->dev_idx < mpb->num_raid_devs) { | |
5243 | dprintf("%s: subarray %d already defined\n", | |
5244 | __func__, u->dev_idx); | |
ba2de7ba | 5245 | goto create_error; |
8273f55e DW |
5246 | } |
5247 | ||
5248 | /* check update is next in sequence */ | |
5249 | if (u->dev_idx != mpb->num_raid_devs) { | |
6a3e913e DW |
5250 | dprintf("%s: can not create array %d expected index %d\n", |
5251 | __func__, u->dev_idx, mpb->num_raid_devs); | |
ba2de7ba | 5252 | goto create_error; |
8273f55e DW |
5253 | } |
5254 | ||
a965f303 | 5255 | new_map = get_imsm_map(&u->dev, 0); |
8273f55e DW |
5256 | new_start = __le32_to_cpu(new_map->pba_of_lba0); |
5257 | new_end = new_start + __le32_to_cpu(new_map->blocks_per_member); | |
54c2c1ea | 5258 | inf = get_disk_info(u); |
8273f55e DW |
5259 | |
5260 | /* handle activate_spare versus create race: | |
5261 | * check to make sure that overlapping arrays do not include | |
5262 | * overalpping disks | |
5263 | */ | |
5264 | for (i = 0; i < mpb->num_raid_devs; i++) { | |
949c47a0 | 5265 | dev = get_imsm_dev(super, i); |
a965f303 | 5266 | map = get_imsm_map(dev, 0); |
8273f55e DW |
5267 | start = __le32_to_cpu(map->pba_of_lba0); |
5268 | end = start + __le32_to_cpu(map->blocks_per_member); | |
5269 | if ((new_start >= start && new_start <= end) || | |
5270 | (start >= new_start && start <= new_end)) | |
54c2c1ea DW |
5271 | /* overlap */; |
5272 | else | |
5273 | continue; | |
5274 | ||
5275 | if (disks_overlap(super, i, u)) { | |
8273f55e | 5276 | dprintf("%s: arrays overlap\n", __func__); |
ba2de7ba | 5277 | goto create_error; |
8273f55e DW |
5278 | } |
5279 | } | |
8273f55e | 5280 | |
949c47a0 DW |
5281 | /* check that prepare update was successful */ |
5282 | if (!update->space) { | |
5283 | dprintf("%s: prepare update failed\n", __func__); | |
ba2de7ba | 5284 | goto create_error; |
949c47a0 DW |
5285 | } |
5286 | ||
54c2c1ea DW |
5287 | /* check that all disks are still active before committing |
5288 | * changes. FIXME: could we instead handle this by creating a | |
5289 | * degraded array? That's probably not what the user expects, | |
5290 | * so better to drop this update on the floor. | |
5291 | */ | |
5292 | for (i = 0; i < new_map->num_members; i++) { | |
5293 | dl = serial_to_dl(inf[i].serial, super); | |
5294 | if (!dl) { | |
5295 | dprintf("%s: disk disappeared\n", __func__); | |
ba2de7ba | 5296 | goto create_error; |
54c2c1ea | 5297 | } |
949c47a0 DW |
5298 | } |
5299 | ||
8273f55e | 5300 | super->updates_pending++; |
54c2c1ea DW |
5301 | |
5302 | /* convert spares to members and fixup ord_tbl */ | |
5303 | for (i = 0; i < new_map->num_members; i++) { | |
5304 | dl = serial_to_dl(inf[i].serial, super); | |
5305 | if (dl->index == -1) { | |
5306 | dl->index = mpb->num_disks; | |
5307 | mpb->num_disks++; | |
5308 | dl->disk.status |= CONFIGURED_DISK; | |
5309 | dl->disk.status &= ~SPARE_DISK; | |
5310 | } | |
5311 | set_imsm_ord_tbl_ent(new_map, i, dl->index); | |
5312 | } | |
5313 | ||
ba2de7ba DW |
5314 | dv = update->space; |
5315 | dev = dv->dev; | |
949c47a0 DW |
5316 | update->space = NULL; |
5317 | imsm_copy_dev(dev, &u->dev); | |
ba2de7ba DW |
5318 | dv->index = u->dev_idx; |
5319 | dv->next = super->devlist; | |
5320 | super->devlist = dv; | |
8273f55e | 5321 | mpb->num_raid_devs++; |
8273f55e | 5322 | |
4d1313e9 | 5323 | imsm_update_version_info(super); |
8273f55e | 5324 | break; |
ba2de7ba DW |
5325 | create_error: |
5326 | /* mdmon knows how to release update->space, but not | |
5327 | * ((struct intel_dev *) update->space)->dev | |
5328 | */ | |
5329 | if (update->space) { | |
5330 | dv = update->space; | |
5331 | free(dv->dev); | |
5332 | } | |
8273f55e | 5333 | break; |
e8319a19 | 5334 | } |
33414a01 DW |
5335 | case update_kill_array: { |
5336 | struct imsm_update_kill_array *u = (void *) update->buf; | |
5337 | int victim = u->dev_idx; | |
5338 | struct active_array *a; | |
5339 | struct intel_dev **dp; | |
5340 | struct imsm_dev *dev; | |
5341 | ||
5342 | /* sanity check that we are not affecting the uuid of | |
5343 | * active arrays, or deleting an active array | |
5344 | * | |
5345 | * FIXME when immutable ids are available, but note that | |
5346 | * we'll also need to fixup the invalidated/active | |
5347 | * subarray indexes in mdstat | |
5348 | */ | |
5349 | for (a = st->arrays; a; a = a->next) | |
5350 | if (a->info.container_member >= victim) | |
5351 | break; | |
5352 | /* by definition if mdmon is running at least one array | |
5353 | * is active in the container, so checking | |
5354 | * mpb->num_raid_devs is just extra paranoia | |
5355 | */ | |
5356 | dev = get_imsm_dev(super, victim); | |
5357 | if (a || !dev || mpb->num_raid_devs == 1) { | |
5358 | dprintf("failed to delete subarray-%d\n", victim); | |
5359 | break; | |
5360 | } | |
5361 | ||
5362 | for (dp = &super->devlist; *dp;) | |
f21e18ca | 5363 | if ((*dp)->index == (unsigned)super->current_vol) { |
33414a01 DW |
5364 | *dp = (*dp)->next; |
5365 | } else { | |
f21e18ca | 5366 | if ((*dp)->index > (unsigned)victim) |
33414a01 DW |
5367 | (*dp)->index--; |
5368 | dp = &(*dp)->next; | |
5369 | } | |
5370 | mpb->num_raid_devs--; | |
5371 | super->updates_pending++; | |
5372 | break; | |
5373 | } | |
aa534678 DW |
5374 | case update_rename_array: { |
5375 | struct imsm_update_rename_array *u = (void *) update->buf; | |
5376 | char name[MAX_RAID_SERIAL_LEN+1]; | |
5377 | int target = u->dev_idx; | |
5378 | struct active_array *a; | |
5379 | struct imsm_dev *dev; | |
5380 | ||
5381 | /* sanity check that we are not affecting the uuid of | |
5382 | * an active array | |
5383 | */ | |
5384 | snprintf(name, MAX_RAID_SERIAL_LEN, "%s", (char *) u->name); | |
5385 | name[MAX_RAID_SERIAL_LEN] = '\0'; | |
5386 | for (a = st->arrays; a; a = a->next) | |
5387 | if (a->info.container_member == target) | |
5388 | break; | |
5389 | dev = get_imsm_dev(super, u->dev_idx); | |
5390 | if (a || !dev || !check_name(super, name, 1)) { | |
5391 | dprintf("failed to rename subarray-%d\n", target); | |
5392 | break; | |
5393 | } | |
5394 | ||
cdbe98cd | 5395 | snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, "%s", name); |
aa534678 DW |
5396 | super->updates_pending++; |
5397 | break; | |
5398 | } | |
43dad3d6 DW |
5399 | case update_add_disk: |
5400 | ||
5401 | /* we may be able to repair some arrays if disks are | |
5402 | * being added */ | |
5403 | if (super->add) { | |
5404 | struct active_array *a; | |
072b727f DW |
5405 | |
5406 | super->updates_pending++; | |
43dad3d6 DW |
5407 | for (a = st->arrays; a; a = a->next) |
5408 | a->check_degraded = 1; | |
5409 | } | |
e553d2a4 | 5410 | /* add some spares to the metadata */ |
43dad3d6 | 5411 | while (super->add) { |
e553d2a4 DW |
5412 | struct dl *al; |
5413 | ||
43dad3d6 DW |
5414 | al = super->add; |
5415 | super->add = al->next; | |
43dad3d6 DW |
5416 | al->next = super->disks; |
5417 | super->disks = al; | |
e553d2a4 DW |
5418 | dprintf("%s: added %x:%x\n", |
5419 | __func__, al->major, al->minor); | |
43dad3d6 DW |
5420 | } |
5421 | ||
5422 | break; | |
e8319a19 DW |
5423 | } |
5424 | } | |
88758e9d | 5425 | |
8273f55e DW |
5426 | static void imsm_prepare_update(struct supertype *st, |
5427 | struct metadata_update *update) | |
5428 | { | |
949c47a0 | 5429 | /** |
4d7b1503 DW |
5430 | * Allocate space to hold new disk entries, raid-device entries or a new |
5431 | * mpb if necessary. The manager synchronously waits for updates to | |
5432 | * complete in the monitor, so new mpb buffers allocated here can be | |
5433 | * integrated by the monitor thread without worrying about live pointers | |
5434 | * in the manager thread. | |
8273f55e | 5435 | */ |
949c47a0 | 5436 | enum imsm_update_type type = *(enum imsm_update_type *) update->buf; |
4d7b1503 DW |
5437 | struct intel_super *super = st->sb; |
5438 | struct imsm_super *mpb = super->anchor; | |
5439 | size_t buf_len; | |
5440 | size_t len = 0; | |
949c47a0 DW |
5441 | |
5442 | switch (type) { | |
5443 | case update_create_array: { | |
5444 | struct imsm_update_create_array *u = (void *) update->buf; | |
ba2de7ba | 5445 | struct intel_dev *dv; |
54c2c1ea DW |
5446 | struct imsm_dev *dev = &u->dev; |
5447 | struct imsm_map *map = get_imsm_map(dev, 0); | |
5448 | struct dl *dl; | |
5449 | struct disk_info *inf; | |
5450 | int i; | |
5451 | int activate = 0; | |
949c47a0 | 5452 | |
54c2c1ea DW |
5453 | inf = get_disk_info(u); |
5454 | len = sizeof_imsm_dev(dev, 1); | |
ba2de7ba DW |
5455 | /* allocate a new super->devlist entry */ |
5456 | dv = malloc(sizeof(*dv)); | |
5457 | if (dv) { | |
5458 | dv->dev = malloc(len); | |
5459 | if (dv->dev) | |
5460 | update->space = dv; | |
5461 | else { | |
5462 | free(dv); | |
5463 | update->space = NULL; | |
5464 | } | |
5465 | } | |
949c47a0 | 5466 | |
54c2c1ea DW |
5467 | /* count how many spares will be converted to members */ |
5468 | for (i = 0; i < map->num_members; i++) { | |
5469 | dl = serial_to_dl(inf[i].serial, super); | |
5470 | if (!dl) { | |
5471 | /* hmm maybe it failed?, nothing we can do about | |
5472 | * it here | |
5473 | */ | |
5474 | continue; | |
5475 | } | |
5476 | if (count_memberships(dl, super) == 0) | |
5477 | activate++; | |
5478 | } | |
5479 | len += activate * sizeof(struct imsm_disk); | |
949c47a0 DW |
5480 | break; |
5481 | default: | |
5482 | break; | |
5483 | } | |
5484 | } | |
8273f55e | 5485 | |
4d7b1503 DW |
5486 | /* check if we need a larger metadata buffer */ |
5487 | if (super->next_buf) | |
5488 | buf_len = super->next_len; | |
5489 | else | |
5490 | buf_len = super->len; | |
5491 | ||
5492 | if (__le32_to_cpu(mpb->mpb_size) + len > buf_len) { | |
5493 | /* ok we need a larger buf than what is currently allocated | |
5494 | * if this allocation fails process_update will notice that | |
5495 | * ->next_len is set and ->next_buf is NULL | |
5496 | */ | |
5497 | buf_len = ROUND_UP(__le32_to_cpu(mpb->mpb_size) + len, 512); | |
5498 | if (super->next_buf) | |
5499 | free(super->next_buf); | |
5500 | ||
5501 | super->next_len = buf_len; | |
1f45a8ad DW |
5502 | if (posix_memalign(&super->next_buf, 512, buf_len) == 0) |
5503 | memset(super->next_buf, 0, buf_len); | |
5504 | else | |
4d7b1503 DW |
5505 | super->next_buf = NULL; |
5506 | } | |
8273f55e DW |
5507 | } |
5508 | ||
ae6aad82 | 5509 | /* must be called while manager is quiesced */ |
f21e18ca | 5510 | static void imsm_delete(struct intel_super *super, struct dl **dlp, unsigned index) |
ae6aad82 DW |
5511 | { |
5512 | struct imsm_super *mpb = super->anchor; | |
ae6aad82 DW |
5513 | struct dl *iter; |
5514 | struct imsm_dev *dev; | |
5515 | struct imsm_map *map; | |
24565c9a DW |
5516 | int i, j, num_members; |
5517 | __u32 ord; | |
ae6aad82 | 5518 | |
24565c9a DW |
5519 | dprintf("%s: deleting device[%d] from imsm_super\n", |
5520 | __func__, index); | |
ae6aad82 DW |
5521 | |
5522 | /* shift all indexes down one */ | |
5523 | for (iter = super->disks; iter; iter = iter->next) | |
f21e18ca | 5524 | if (iter->index > (int)index) |
ae6aad82 | 5525 | iter->index--; |
47ee5a45 | 5526 | for (iter = super->missing; iter; iter = iter->next) |
f21e18ca | 5527 | if (iter->index > (int)index) |
47ee5a45 | 5528 | iter->index--; |
ae6aad82 DW |
5529 | |
5530 | for (i = 0; i < mpb->num_raid_devs; i++) { | |
5531 | dev = get_imsm_dev(super, i); | |
5532 | map = get_imsm_map(dev, 0); | |
24565c9a DW |
5533 | num_members = map->num_members; |
5534 | for (j = 0; j < num_members; j++) { | |
5535 | /* update ord entries being careful not to propagate | |
5536 | * ord-flags to the first map | |
5537 | */ | |
5538 | ord = get_imsm_ord_tbl_ent(dev, j); | |
ae6aad82 | 5539 | |
24565c9a DW |
5540 | if (ord_to_idx(ord) <= index) |
5541 | continue; | |
ae6aad82 | 5542 | |
24565c9a DW |
5543 | map = get_imsm_map(dev, 0); |
5544 | set_imsm_ord_tbl_ent(map, j, ord_to_idx(ord - 1)); | |
5545 | map = get_imsm_map(dev, 1); | |
5546 | if (map) | |
5547 | set_imsm_ord_tbl_ent(map, j, ord - 1); | |
ae6aad82 DW |
5548 | } |
5549 | } | |
5550 | ||
5551 | mpb->num_disks--; | |
5552 | super->updates_pending++; | |
24565c9a DW |
5553 | if (*dlp) { |
5554 | struct dl *dl = *dlp; | |
5555 | ||
5556 | *dlp = (*dlp)->next; | |
5557 | __free_imsm_disk(dl); | |
5558 | } | |
ae6aad82 | 5559 | } |
0e600426 | 5560 | #endif /* MDASSEMBLE */ |
ae6aad82 | 5561 | |
cdddbdbc DW |
5562 | struct superswitch super_imsm = { |
5563 | #ifndef MDASSEMBLE | |
5564 | .examine_super = examine_super_imsm, | |
5565 | .brief_examine_super = brief_examine_super_imsm, | |
4737ae25 | 5566 | .brief_examine_subarrays = brief_examine_subarrays_imsm, |
9d84c8ea | 5567 | .export_examine_super = export_examine_super_imsm, |
cdddbdbc DW |
5568 | .detail_super = detail_super_imsm, |
5569 | .brief_detail_super = brief_detail_super_imsm, | |
bf5a934a | 5570 | .write_init_super = write_init_super_imsm, |
0e600426 | 5571 | .validate_geometry = validate_geometry_imsm, |
0bd16cf2 | 5572 | .default_chunk = default_chunk_imsm, |
0e600426 | 5573 | .add_to_super = add_to_super_imsm, |
d665cc31 | 5574 | .detail_platform = detail_platform_imsm, |
33414a01 | 5575 | .kill_subarray = kill_subarray_imsm, |
aa534678 | 5576 | .update_subarray = update_subarray_imsm, |
2b959fbf | 5577 | .load_container = load_container_imsm, |
cdddbdbc DW |
5578 | #endif |
5579 | .match_home = match_home_imsm, | |
5580 | .uuid_from_super= uuid_from_super_imsm, | |
5581 | .getinfo_super = getinfo_super_imsm, | |
5582 | .update_super = update_super_imsm, | |
5583 | ||
5584 | .avail_size = avail_size_imsm, | |
5585 | ||
5586 | .compare_super = compare_super_imsm, | |
5587 | ||
5588 | .load_super = load_super_imsm, | |
bf5a934a | 5589 | .init_super = init_super_imsm, |
e683ca88 | 5590 | .store_super = store_super_imsm, |
cdddbdbc DW |
5591 | .free_super = free_super_imsm, |
5592 | .match_metadata_desc = match_metadata_desc_imsm, | |
bf5a934a | 5593 | .container_content = container_content_imsm, |
a18a888e | 5594 | .default_layout = imsm_level_to_layout, |
cdddbdbc | 5595 | |
cdddbdbc | 5596 | .external = 1, |
4cce4069 | 5597 | .name = "imsm", |
845dea95 | 5598 | |
0e600426 | 5599 | #ifndef MDASSEMBLE |
845dea95 NB |
5600 | /* for mdmon */ |
5601 | .open_new = imsm_open_new, | |
ed9d66aa | 5602 | .set_array_state= imsm_set_array_state, |
845dea95 NB |
5603 | .set_disk = imsm_set_disk, |
5604 | .sync_metadata = imsm_sync_metadata, | |
88758e9d | 5605 | .activate_spare = imsm_activate_spare, |
e8319a19 | 5606 | .process_update = imsm_process_update, |
8273f55e | 5607 | .prepare_update = imsm_prepare_update, |
0e600426 | 5608 | #endif /* MDASSEMBLE */ |
cdddbdbc | 5609 | }; |