forked from md-raid-utilities/mdadm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
super-intel.c
13217 lines (11486 loc) · 347 KB
/
super-intel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* mdadm - Intel(R) Matrix Storage Manager Support
*
* Copyright (C) 2002-2008 Intel Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define HAVE_STDINT_H 1
#include "mdadm.h"
#include "mdmon.h"
#include "dlink.h"
#include "sha1.h"
#include "platform-intel.h"
#include <values.h>
#include <scsi/sg.h>
#include <ctype.h>
#include <dirent.h>
#include "drive_encryption.h"
/* MPB == Metadata Parameter Block */
#define MPB_SIGNATURE "Intel Raid ISM Cfg Sig. "
#define MPB_SIG_LEN (strlen(MPB_SIGNATURE))
/* Legacy IMSM versions:
* MPB_VERSION_RAID0 1.0.00
* MPB_VERSION_RAID1 1.1.00
* MPB_VERSION_MANY_VOLUMES_PER_ARRAY 1.2.00
* MPB_VERSION_3OR4_DISK_ARRAY 1.2.01
* MPB_VERSION_RAID5 1.2.02
* MPB_VERSION_5OR6_DISK_ARRAY 1.2.04
* MPB_VERSION_CNG 1.2.06
*/
#define MPB_VERSION_ATTRIBS "1.3.00"
#define MPB_VERSION_ATTRIBS_JD "2.0.00"
#define MAX_SIGNATURE_LENGTH 32
#define MAX_RAID_SERIAL_LEN 16
/* supports RAID0 */
#define MPB_ATTRIB_RAID0 __cpu_to_le32(0x00000001)
/* supports RAID1 */
#define MPB_ATTRIB_RAID1 __cpu_to_le32(0x00000002)
/* supports RAID10 */
#define MPB_ATTRIB_RAID10 __cpu_to_le32(0x00000004)
/* supports RAID1E */
#define MPB_ATTRIB_RAID1E __cpu_to_le32(0x00000008)
/* supports RAID5 */
#define MPB_ATTRIB_RAID5 __cpu_to_le32(0x00000010)
/* supports RAID CNG */
#define MPB_ATTRIB_RAIDCNG __cpu_to_le32(0x00000020)
/* supports expanded stripe sizes of 256K, 512K and 1MB */
#define MPB_ATTRIB_EXP_STRIPE_SIZE __cpu_to_le32(0x00000040)
/* supports RAID10 with more than 4 drives */
#define MPB_ATTRIB_RAID10_EXT __cpu_to_le32(0x00000080)
/* The OROM Support RST Caching of Volumes */
#define MPB_ATTRIB_NVM __cpu_to_le32(0x02000000)
/* The OROM supports creating disks greater than 2TB */
#define MPB_ATTRIB_2TB_DISK __cpu_to_le32(0x04000000)
/* The OROM supports Bad Block Management */
#define MPB_ATTRIB_BBM __cpu_to_le32(0x08000000)
/* THe OROM Supports NVM Caching of Volumes */
#define MPB_ATTRIB_NEVER_USE2 __cpu_to_le32(0x10000000)
/* The OROM supports creating volumes greater than 2TB */
#define MPB_ATTRIB_2TB __cpu_to_le32(0x20000000)
/* originally for PMP, now it's wasted b/c. Never use this bit! */
#define MPB_ATTRIB_NEVER_USE __cpu_to_le32(0x40000000)
/* Verify MPB contents against checksum after reading MPB */
#define MPB_ATTRIB_CHECKSUM_VERIFY __cpu_to_le32(0x80000000)
/* Define all supported attributes that have to be accepted by mdadm
*/
#define MPB_ATTRIB_SUPPORTED (MPB_ATTRIB_CHECKSUM_VERIFY | \
MPB_ATTRIB_2TB | \
MPB_ATTRIB_2TB_DISK | \
MPB_ATTRIB_RAID0 | \
MPB_ATTRIB_RAID1 | \
MPB_ATTRIB_RAID10 | \
MPB_ATTRIB_RAID5 | \
MPB_ATTRIB_EXP_STRIPE_SIZE | \
MPB_ATTRIB_RAID10_EXT | \
MPB_ATTRIB_BBM)
/* Define attributes that are unused but not harmful */
#define MPB_ATTRIB_IGNORED (MPB_ATTRIB_NEVER_USE)
#define MPB_SECTOR_CNT 2210
#define IMSM_RESERVED_SECTORS 8192
#define NUM_BLOCKS_DIRTY_STRIPE_REGION 2048
#define SECT_PER_MB_SHIFT 11
#define MAX_SECTOR_SIZE 4096
#define MULTIPLE_PPL_AREA_SIZE_IMSM (1024 * 1024) /* Size of the whole
* mutliple PPL area
*/
/*
* Internal Write-intent bitmap is stored in the same area where PPL.
* Both features are mutually exclusive, so it is not an issue.
* The first 8KiB of the area are reserved and shall not be used.
*/
#define IMSM_BITMAP_AREA_RESERVED_SIZE 8192
#define IMSM_BITMAP_HEADER_OFFSET (IMSM_BITMAP_AREA_RESERVED_SIZE)
#define IMSM_BITMAP_HEADER_SIZE MAX_SECTOR_SIZE
#define IMSM_BITMAP_START_OFFSET (IMSM_BITMAP_HEADER_OFFSET + IMSM_BITMAP_HEADER_SIZE)
#define IMSM_BITMAP_AREA_SIZE (MULTIPLE_PPL_AREA_SIZE_IMSM - IMSM_BITMAP_START_OFFSET)
#define IMSM_BITMAP_AND_HEADER_SIZE (IMSM_BITMAP_AREA_SIZE + IMSM_BITMAP_HEADER_SIZE)
#define IMSM_DEFAULT_BITMAP_CHUNKSIZE (64 * 1024 * 1024)
#define IMSM_DEFAULT_BITMAP_DAEMON_SLEEP 5
/*
* This macro let's us ensure that no-one accidentally
* changes the size of a struct
*/
#define ASSERT_SIZE(_struct, size) \
static inline void __assert_size_##_struct(void) \
{ \
switch (0) { \
case 0: break; \
case (sizeof(struct _struct) == size): break; \
} \
}
/* Disk configuration info. */
#define IMSM_MAX_DEVICES 255
struct imsm_disk {
__u8 serial[MAX_RAID_SERIAL_LEN];/* 0xD8 - 0xE7 ascii serial number */
__u32 total_blocks_lo; /* 0xE8 - 0xEB total blocks lo */
__u32 scsi_id; /* 0xEC - 0xEF scsi ID */
#define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
#define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
#define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
#define JOURNAL_DISK __cpu_to_le32(0x2000000) /* Device marked as Journaling Drive */
__u32 status; /* 0xF0 - 0xF3 */
__u32 owner_cfg_num; /* which config 0,1,2... owns this disk */
__u32 total_blocks_hi; /* 0xF4 - 0xF5 total blocks hi */
#define IMSM_DISK_FILLERS 3
__u32 filler[IMSM_DISK_FILLERS]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
};
ASSERT_SIZE(imsm_disk, 48)
/* map selector for map managment
*/
#define MAP_0 0
#define MAP_1 1
#define MAP_X -1
/* RAID map configuration infos. */
struct imsm_map {
__u32 pba_of_lba0_lo; /* start address of partition */
__u32 blocks_per_member_lo;/* blocks per member */
__u32 num_data_stripes_lo; /* number of data stripes */
__u16 blocks_per_strip;
__u8 map_state; /* Normal, Uninitialized, Degraded, Failed */
#define IMSM_T_STATE_NORMAL 0
#define IMSM_T_STATE_UNINITIALIZED 1
#define IMSM_T_STATE_DEGRADED 2
#define IMSM_T_STATE_FAILED 3
__u8 raid_level;
#define IMSM_T_RAID0 0
#define IMSM_T_RAID1 1
#define IMSM_T_RAID5 5
#define IMSM_T_RAID10 10
__u8 num_members; /* number of member disks */
__u8 num_domains; /* number of parity domains */
__u8 failed_disk_num; /* valid only when state is degraded */
__u8 ddf;
__u32 pba_of_lba0_hi;
__u32 blocks_per_member_hi;
__u32 num_data_stripes_hi;
__u32 filler[4]; /* expansion area */
#define IMSM_ORD_REBUILD (1 << 24)
__u32 disk_ord_tbl[1]; /* disk_ord_tbl[num_members],
* top byte contains some flags
*/
};
ASSERT_SIZE(imsm_map, 52)
struct imsm_vol {
__u32 curr_migr_unit_lo;
__u32 checkpoint_id; /* id to access curr_migr_unit */
#define MIGR_STATE_NORMAL 0
#define MIGR_STATE_MIGRATING 1
__u8 migr_state; /* Normal or Migrating */
#define MIGR_INIT 0
#define MIGR_REBUILD 1
#define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
#define MIGR_GEN_MIGR 3
#define MIGR_STATE_CHANGE 4
#define MIGR_REPAIR 5
__u8 migr_type; /* Initializing, Rebuilding, ... */
#define RAIDVOL_CLEAN 0
#define RAIDVOL_DIRTY 1
#define RAIDVOL_DSRECORD_VALID 2
__u8 dirty;
__u8 fs_state; /* fast-sync state for CnG (0xff == disabled) */
__u16 verify_errors; /* number of mismatches */
__u16 bad_blocks; /* number of bad blocks during verify */
__u32 curr_migr_unit_hi;
__u32 filler[3];
struct imsm_map map[1];
/* here comes another one if migr_state */
};
ASSERT_SIZE(imsm_vol, 84)
struct imsm_dev {
__u8 volume[MAX_RAID_SERIAL_LEN];
__u32 size_low;
__u32 size_high;
#define DEV_BOOTABLE __cpu_to_le32(0x01)
#define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
#define DEV_READ_COALESCING __cpu_to_le32(0x04)
#define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
#define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
#define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
#define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
#define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
#define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
#define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
#define DEV_CLONE_N_GO __cpu_to_le32(0x400)
#define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
#define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
__u32 status; /* Persistent RaidDev status */
__u32 reserved_blocks; /* Reserved blocks at beginning of volume */
__u8 migr_priority;
__u8 num_sub_vols;
__u8 tid;
__u8 cng_master_disk;
__u16 cache_policy;
__u8 cng_state;
__u8 cng_sub_state;
__u16 my_vol_raid_dev_num; /* Used in Unique volume Id for this RaidDev */
/* NVM_EN */
__u8 nv_cache_mode;
__u8 nv_cache_flags;
/* Unique Volume Id of the NvCache Volume associated with this volume */
__u32 nvc_vol_orig_family_num;
__u16 nvc_vol_raid_dev_num;
#define RWH_OFF 0
#define RWH_DISTRIBUTED 1
#define RWH_JOURNALING_DRIVE 2
#define RWH_MULTIPLE_DISTRIBUTED 3
#define RWH_MULTIPLE_PPLS_JOURNALING_DRIVE 4
#define RWH_MULTIPLE_OFF 5
#define RWH_BITMAP 6
__u8 rwh_policy; /* Raid Write Hole Policy */
__u8 jd_serial[MAX_RAID_SERIAL_LEN]; /* Journal Drive serial number */
__u8 filler1;
#define IMSM_DEV_FILLERS 3
__u32 filler[IMSM_DEV_FILLERS];
struct imsm_vol vol;
};
ASSERT_SIZE(imsm_dev, 164)
struct imsm_super {
__u8 sig[MAX_SIGNATURE_LENGTH]; /* 0x00 - 0x1F */
__u32 check_sum; /* 0x20 - 0x23 MPB Checksum */
__u32 mpb_size; /* 0x24 - 0x27 Size of MPB */
__u32 family_num; /* 0x28 - 0x2B Checksum from first time this config was written */
__u32 generation_num; /* 0x2C - 0x2F Incremented each time this array's MPB is written */
__u32 error_log_size; /* 0x30 - 0x33 in bytes */
__u32 attributes; /* 0x34 - 0x37 */
__u8 num_disks; /* 0x38 Number of configured disks */
__u8 num_raid_devs; /* 0x39 Number of configured volumes */
__u8 error_log_pos; /* 0x3A */
__u8 fill[1]; /* 0x3B */
__u32 cache_size; /* 0x3c - 0x40 in mb */
__u32 orig_family_num; /* 0x40 - 0x43 original family num */
__u32 pwr_cycle_count; /* 0x44 - 0x47 simulated power cycle count for array */
__u32 bbm_log_size; /* 0x48 - 0x4B - size of bad Block Mgmt Log in bytes */
__u16 num_raid_devs_created; /* 0x4C - 0x4D Used for generating unique
* volume IDs for raid_dev created in this array
* (starts at 1)
*/
__u16 filler1; /* 0x4E - 0x4F */
__u64 creation_time; /* 0x50 - 0x57 Array creation time */
#define IMSM_FILLERS 32
__u32 filler[IMSM_FILLERS]; /* 0x58 - 0xD7 RAID_MPB_FILLERS */
struct imsm_disk disk[1]; /* 0xD8 diskTbl[numDisks] */
/* here comes imsm_dev[num_raid_devs] */
/* here comes BBM logs */
};
ASSERT_SIZE(imsm_super, 264)
#define BBM_LOG_MAX_ENTRIES 254
#define BBM_LOG_MAX_LBA_ENTRY_VAL 256 /* Represents 256 LBAs */
#define BBM_LOG_SIGNATURE 0xabadb10c
struct bbm_log_block_addr {
__u16 w1;
__u32 dw1;
} __attribute__ ((__packed__));
struct bbm_log_entry {
__u8 marked_count; /* Number of blocks marked - 1 */
__u8 disk_ordinal; /* Disk entry within the imsm_super */
struct bbm_log_block_addr defective_block_start;
} __attribute__ ((__packed__));
struct bbm_log {
__u32 signature; /* 0xABADB10C */
__u32 entry_count;
struct bbm_log_entry marked_block_entries[BBM_LOG_MAX_ENTRIES];
};
ASSERT_SIZE(bbm_log, 2040)
static char *map_state_str[] = { "normal", "uninitialized", "degraded", "failed" };
#define BLOCKS_PER_KB (1024/512)
#define RAID_DISK_RESERVED_BLOCKS_IMSM_HI 2209
#define GEN_MIGR_AREA_SIZE 2048 /* General Migration Copy Area size in blocks */
#define MIGR_REC_BUF_SECTORS 1 /* size of migr_record i/o buffer in sectors */
#define MIGR_REC_SECTOR_POSITION 1 /* migr_record position offset on disk,
* MIGR_REC_BUF_SECTORS <= MIGR_REC_SECTOR_POS
*/
#define UNIT_SRC_NORMAL 0 /* Source data for curr_migr_unit must
* be recovered using srcMap */
#define UNIT_SRC_IN_CP_AREA 1 /* Source data for curr_migr_unit has
* already been migrated and must
* be recovered from checkpoint area */
#define PPL_ENTRY_SPACE (128 * 1024) /* Size of single PPL, without the header */
struct migr_record {
__u32 rec_status; /* Status used to determine how to restart
* migration in case it aborts
* in some fashion */
__u32 curr_migr_unit_lo; /* 0..numMigrUnits-1 */
__u32 family_num; /* Family number of MPB
* containing the RaidDev
* that is migrating */
__u32 ascending_migr; /* True if migrating in increasing
* order of lbas */
__u32 blocks_per_unit; /* Num disk blocks per unit of operation */
__u32 dest_depth_per_unit; /* Num member blocks each destMap
* member disk
* advances per unit-of-operation */
__u32 ckpt_area_pba_lo; /* Pba of first block of ckpt copy area */
__u32 dest_1st_member_lba_lo; /* First member lba on first
* stripe of destination */
__u32 num_migr_units_lo; /* Total num migration units-of-op */
__u32 post_migr_vol_cap; /* Size of volume after
* migration completes */
__u32 post_migr_vol_cap_hi; /* Expansion space for LBA64 */
__u32 ckpt_read_disk_num; /* Which member disk in destSubMap[0] the
* migration ckpt record was read from
* (for recovered migrations) */
__u32 curr_migr_unit_hi; /* 0..numMigrUnits-1 high order 32 bits */
__u32 ckpt_area_pba_hi; /* Pba of first block of ckpt copy area
* high order 32 bits */
__u32 dest_1st_member_lba_hi; /* First member lba on first stripe of
* destination - high order 32 bits */
__u32 num_migr_units_hi; /* Total num migration units-of-op
* high order 32 bits */
__u32 filler[16];
};
ASSERT_SIZE(migr_record, 128)
/**
* enum imsm_status - internal IMSM return values representation.
* @STATUS_OK: function succeeded.
* @STATUS_ERROR: General error ocurred (not specified).
*
* Typedefed to imsm_status_t.
*/
typedef enum imsm_status {
IMSM_STATUS_ERROR = -1,
IMSM_STATUS_OK = 0,
} imsm_status_t;
struct md_list {
/* usage marker:
* 1: load metadata
* 2: metadata does not match
* 4: already checked
*/
int used;
char *devname;
int found;
int container;
dev_t st_rdev;
struct md_list *next;
};
static __u8 migr_type(struct imsm_dev *dev)
{
if (dev->vol.migr_type == MIGR_VERIFY &&
dev->status & DEV_VERIFY_AND_FIX)
return MIGR_REPAIR;
else
return dev->vol.migr_type;
}
static void set_migr_type(struct imsm_dev *dev, __u8 migr_type)
{
/* for compatibility with older oroms convert MIGR_REPAIR, into
* MIGR_VERIFY w/ DEV_VERIFY_AND_FIX status
*/
if (migr_type == MIGR_REPAIR) {
dev->vol.migr_type = MIGR_VERIFY;
dev->status |= DEV_VERIFY_AND_FIX;
} else {
dev->vol.migr_type = migr_type;
dev->status &= ~DEV_VERIFY_AND_FIX;
}
}
static unsigned int sector_count(__u32 bytes, unsigned int sector_size)
{
return ROUND_UP(bytes, sector_size) / sector_size;
}
static unsigned int mpb_sectors(struct imsm_super *mpb,
unsigned int sector_size)
{
return sector_count(__le32_to_cpu(mpb->mpb_size), sector_size);
}
struct intel_dev {
struct imsm_dev *dev;
struct intel_dev *next;
unsigned index;
};
struct intel_hba {
enum sys_dev_type type;
char *path;
char *pci_id;
struct intel_hba *next;
};
enum action {
DISK_REMOVE = 1,
DISK_ADD
};
/* internal representation of IMSM metadata */
struct intel_super {
union {
void *buf; /* O_DIRECT buffer for reading/writing metadata */
struct imsm_super *anchor; /* immovable parameters */
};
union {
void *migr_rec_buf; /* buffer for I/O operations */
struct migr_record *migr_rec; /* migration record */
};
int clean_migration_record_by_mdmon; /* when reshape is switched to next
array, it indicates that mdmon is allowed to clean migration
record */
size_t len; /* size of the 'buf' allocation */
size_t extra_space; /* extra space in 'buf' that is not used yet */
void *next_buf; /* for realloc'ing buf from the manager */
size_t next_len;
int updates_pending; /* count of pending updates for mdmon */
int current_vol; /* index of raid device undergoing creation */
unsigned long long create_offset; /* common start for 'current_vol' */
__u32 random; /* random data for seeding new family numbers */
struct intel_dev *devlist;
unsigned int sector_size; /* sector size of used member drives */
struct dl {
struct dl *next;
int index;
__u8 serial[MAX_RAID_SERIAL_LEN];
int major, minor;
char *devname;
struct imsm_disk disk;
int fd;
int extent_cnt;
struct extent *e; /* for determining freespace @ create */
int raiddisk; /* slot to fill in autolayout */
enum action action;
} *disks, *current_disk;
struct dl *disk_mgmt_list; /* list of disks to add/remove while mdmon
active */
struct dl *missing; /* disks removed while we weren't looking */
struct bbm_log *bbm_log;
struct intel_hba *hba; /* device path of the raid controller for this metadata */
const struct imsm_orom *orom; /* platform firmware support */
struct intel_super *next; /* (temp) list for disambiguating family_num */
struct md_bb bb; /* memory for get_bad_blocks call */
};
struct intel_disk {
struct imsm_disk disk;
#define IMSM_UNKNOWN_OWNER (-1)
int owner;
struct intel_disk *next;
};
/**
* struct extent - reserved space details.
* @start: start offset.
* @size: size of reservation, set to 0 for metadata reservation.
* @vol: index of the volume, meaningful if &size is set.
*/
struct extent {
unsigned long long start, size;
int vol;
};
/* definitions of reshape process types */
enum imsm_reshape_type {
CH_TAKEOVER,
CH_MIGRATION,
CH_ARRAY_SIZE,
CH_ABORT
};
/* definition of messages passed to imsm_process_update */
enum imsm_update_type {
update_activate_spare,
update_create_array,
update_kill_array,
update_rename_array,
update_add_remove_disk,
update_reshape_container_disks,
update_reshape_migration,
update_takeover,
update_general_migration_checkpoint,
update_size_change,
update_prealloc_badblocks_mem,
update_rwh_policy,
};
struct imsm_update_activate_spare {
enum imsm_update_type type;
struct dl *dl;
int slot;
int array;
struct imsm_update_activate_spare *next;
};
struct geo_params {
char devnm[32];
char *dev_name;
unsigned long long size;
int level;
int layout;
int chunksize;
int raid_disks;
};
enum takeover_direction {
R10_TO_R0,
R0_TO_R10
};
struct imsm_update_takeover {
enum imsm_update_type type;
int subarray;
enum takeover_direction direction;
};
struct imsm_update_reshape {
enum imsm_update_type type;
int old_raid_disks;
int new_raid_disks;
int new_disks[1]; /* new_raid_disks - old_raid_disks makedev number */
};
struct imsm_update_reshape_migration {
enum imsm_update_type type;
int old_raid_disks;
int new_raid_disks;
/* fields for array migration changes
*/
int subdev;
int new_level;
int new_layout;
int new_chunksize;
int new_disks[1]; /* new_raid_disks - old_raid_disks makedev number */
};
struct imsm_update_size_change {
enum imsm_update_type type;
int subdev;
long long new_size;
};
struct imsm_update_general_migration_checkpoint {
enum imsm_update_type type;
__u64 curr_migr_unit;
};
struct disk_info {
__u8 serial[MAX_RAID_SERIAL_LEN];
};
struct imsm_update_create_array {
enum imsm_update_type type;
int dev_idx;
struct imsm_dev dev;
};
struct imsm_update_kill_array {
enum imsm_update_type type;
int dev_idx;
};
struct imsm_update_rename_array {
enum imsm_update_type type;
__u8 name[MAX_RAID_SERIAL_LEN];
int dev_idx;
};
struct imsm_update_add_remove_disk {
enum imsm_update_type type;
};
struct imsm_update_prealloc_bb_mem {
enum imsm_update_type type;
};
struct imsm_update_rwh_policy {
enum imsm_update_type type;
int new_policy;
int dev_idx;
};
static const char *_sys_dev_type[] = {
[SYS_DEV_UNKNOWN] = "Unknown",
[SYS_DEV_SAS] = "SAS",
[SYS_DEV_SATA] = "SATA",
[SYS_DEV_NVME] = "NVMe",
[SYS_DEV_VMD] = "VMD",
[SYS_DEV_SATA_VMD] = "SATA VMD"
};
struct imsm_chunk_ops {
uint chunk;
char *chunk_str;
};
static const struct imsm_chunk_ops imsm_chunk_ops[] = {
{IMSM_OROM_SSS_2kB, "2k"},
{IMSM_OROM_SSS_4kB, "4k"},
{IMSM_OROM_SSS_8kB, "8k"},
{IMSM_OROM_SSS_16kB, "16k"},
{IMSM_OROM_SSS_32kB, "32k"},
{IMSM_OROM_SSS_64kB, "64k"},
{IMSM_OROM_SSS_128kB, "128k"},
{IMSM_OROM_SSS_256kB, "256k"},
{IMSM_OROM_SSS_512kB, "512k"},
{IMSM_OROM_SSS_1MB, "1M"},
{IMSM_OROM_SSS_2MB, "2M"},
{IMSM_OROM_SSS_4MB, "4M"},
{IMSM_OROM_SSS_8MB, "8M"},
{IMSM_OROM_SSS_16MB, "16M"},
{IMSM_OROM_SSS_32MB, "32M"},
{IMSM_OROM_SSS_64MB, "64M"},
{0, NULL}
};
static int no_platform = -1;
static int check_no_platform(void)
{
static const char search[] = "mdadm.imsm.test=1";
FILE *fp;
if (no_platform >= 0)
return no_platform;
if (check_env("IMSM_NO_PLATFORM")) {
no_platform = 1;
return 1;
}
fp = fopen("/proc/cmdline", "r");
if (fp) {
char *l = conf_line(fp);
char *w = l;
if (l == NULL) {
fclose(fp);
return 0;
}
do {
if (strcmp(w, search) == 0)
no_platform = 1;
w = dl_next(w);
} while (w != l);
free_line(l);
fclose(fp);
if (no_platform >= 0)
return no_platform;
}
no_platform = 0;
return 0;
}
void imsm_set_no_platform(int v)
{
no_platform = v;
}
const char *get_sys_dev_type(enum sys_dev_type type)
{
if (type >= SYS_DEV_MAX)
type = SYS_DEV_UNKNOWN;
return _sys_dev_type[type];
}
static struct intel_hba * alloc_intel_hba(struct sys_dev *device)
{
struct intel_hba *result = xmalloc(sizeof(*result));
result->type = device->type;
result->path = xstrdup(device->path);
result->next = NULL;
if (result->path && (result->pci_id = strrchr(result->path, '/')) != NULL)
result->pci_id++;
return result;
}
static struct intel_hba * find_intel_hba(struct intel_hba *hba, struct sys_dev *device)
{
struct intel_hba *result;
for (result = hba; result; result = result->next) {
if (result->type == device->type && strcmp(result->path, device->path) == 0)
break;
}
return result;
}
static int attach_hba_to_super(struct intel_super *super, struct sys_dev *device)
{
struct intel_hba *hba;
/* check if disk attached to Intel HBA */
hba = find_intel_hba(super->hba, device);
if (hba != NULL)
return 1;
/* Check if HBA is already attached to super */
if (super->hba == NULL) {
super->hba = alloc_intel_hba(device);
return 1;
}
hba = super->hba;
/* Intel metadata allows for all disks attached to the same type HBA.
* Do not support HBA types mixing
*/
if (device->type != hba->type)
return 2;
/* Multiple same type HBAs can be used if they share the same OROM */
const struct imsm_orom *device_orom = get_orom_by_device_id(device->dev_id);
if (device_orom != super->orom)
return 2;
while (hba->next)
hba = hba->next;
hba->next = alloc_intel_hba(device);
return 1;
}
static struct sys_dev* find_disk_attached_hba(int fd, const char *devname)
{
struct sys_dev *list, *elem;
char *disk_path;
if ((list = find_intel_devices()) == NULL)
return 0;
if (!is_fd_valid(fd))
disk_path = (char *) devname;
else
disk_path = diskfd_to_devpath(fd, 1, NULL);
if (!disk_path)
return 0;
for (elem = list; elem; elem = elem->next)
if (is_path_attached_to_hba(disk_path, elem->path))
break;
if (disk_path != devname)
free(disk_path);
return elem;
}
static int find_intel_hba_capability(int fd, struct intel_super *super,
char *devname);
static struct supertype *match_metadata_desc_imsm(char *arg)
{
struct supertype *st;
if (strcmp(arg, "imsm") != 0 &&
strcmp(arg, "default") != 0
)
return NULL;
st = xcalloc(1, sizeof(*st));
st->ss = &super_imsm;
st->max_devs = IMSM_MAX_DEVICES;
st->minor_version = 0;
st->sb = NULL;
return st;
}
static __u8 *get_imsm_version(struct imsm_super *mpb)
{
return &mpb->sig[MPB_SIG_LEN];
}
/* retrieve a disk directly from the anchor when the anchor is known to be
* up-to-date, currently only at load time
*/
static struct imsm_disk *__get_imsm_disk(struct imsm_super *mpb, __u8 index)
{
if (index >= mpb->num_disks)
return NULL;
return &mpb->disk[index];
}
/* retrieve the disk description based on a index of the disk
* in the sub-array
*/
static struct dl *get_imsm_dl_disk(struct intel_super *super, __u8 index)
{
struct dl *d;
for (d = super->disks; d; d = d->next)
if (d->index == index)
return d;
return NULL;
}
/* retrieve a disk from the parsed metadata */
static struct imsm_disk *get_imsm_disk(struct intel_super *super, __u8 index)
{
struct dl *dl;
dl = get_imsm_dl_disk(super, index);
if (dl)
return &dl->disk;
return NULL;
}
/* generate a checksum directly from the anchor when the anchor is known to be
* up-to-date, currently only at load or write_super after coalescing
*/
static __u32 __gen_imsm_checksum(struct imsm_super *mpb)
{
__u32 end = mpb->mpb_size / sizeof(end);
__u32 *p = (__u32 *) mpb;
__u32 sum = 0;
while (end--) {
sum += __le32_to_cpu(*p);
p++;
}
return sum - __le32_to_cpu(mpb->check_sum);
}
static size_t sizeof_imsm_map(struct imsm_map *map)
{
return sizeof(struct imsm_map) + sizeof(__u32) * (map->num_members - 1);
}
struct imsm_map *get_imsm_map(struct imsm_dev *dev, int second_map)
{
/* A device can have 2 maps if it is in the middle of a migration.
* If second_map is:
* MAP_0 - we return the first map
* MAP_1 - we return the second map if it exists, else NULL
* MAP_X - we return the second map if it exists, else the first
*/
struct imsm_map *map = &dev->vol.map[0];
struct imsm_map *map2 = NULL;
if (dev->vol.migr_state)
map2 = (void *)map + sizeof_imsm_map(map);
switch (second_map) {
case MAP_0:
break;
case MAP_1:
map = map2;
break;
case MAP_X:
if (map2)
map = map2;
break;
default:
map = NULL;
}
return map;
}
/* return the size of the device.
* migr_state increases the returned size if map[0] were to be duplicated
*/
static size_t sizeof_imsm_dev(struct imsm_dev *dev, int migr_state)
{
size_t size = sizeof(*dev) - sizeof(struct imsm_map) +
sizeof_imsm_map(get_imsm_map(dev, MAP_0));
/* migrating means an additional map */
if (dev->vol.migr_state)
size += sizeof_imsm_map(get_imsm_map(dev, MAP_1));
else if (migr_state)
size += sizeof_imsm_map(get_imsm_map(dev, MAP_0));
return size;
}
/* retrieve disk serial number list from a metadata update */
static struct disk_info *get_disk_info(struct imsm_update_create_array *update)
{
void *u = update;
struct disk_info *inf;
inf = u + sizeof(*update) - sizeof(struct imsm_dev) +
sizeof_imsm_dev(&update->dev, 0);
return inf;
}
/**
* __get_imsm_dev() - Get device with index from imsm_super.
* @mpb: &imsm_super pointer, not NULL.
* @index: Device index.
*
* Function works as non-NULL, aborting in such a case,
* when NULL would be returned.
*
* Device index should be in range 0 up to num_raid_devs.
* Function assumes the index was already verified.
* Index must be valid, otherwise abort() is called.
*
* Return: Pointer to corresponding imsm_dev.
*
*/
static struct imsm_dev *__get_imsm_dev(struct imsm_super *mpb, __u8 index)
{
int offset;
int i;
void *_mpb = mpb;
if (index >= mpb->num_raid_devs)
goto error;
/* devices start after all disks */
offset = ((void *) &mpb->disk[mpb->num_disks]) - _mpb;
for (i = 0; i <= index; i++, offset += sizeof_imsm_dev(_mpb + offset, 0))
if (i == index)
return _mpb + offset;
error:
pr_err("cannot find imsm_dev with index %u in imsm_super\n", index);
abort();
}
/**
* get_imsm_dev() - Get device with index from intel_super.
* @super: &intel_super pointer, not NULL.
* @index: Device index.
*
* Function works as non-NULL, aborting in such a case,
* when NULL would be returned.
*
* Device index should be in range 0 up to num_raid_devs.
* Function assumes the index was already verified.
* Index must be valid, otherwise abort() is called.
*