1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2fc5a40a2SDavid Howells /*
3fc5a40a2SDavid Howells md_p.h : physical layout of Linux RAID devices
4fc5a40a2SDavid Howells Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman
5fc5a40a2SDavid Howells
6fc5a40a2SDavid Howells This program is free software; you can redistribute it and/or modify
7fc5a40a2SDavid Howells it under the terms of the GNU General Public License as published by
8fc5a40a2SDavid Howells the Free Software Foundation; either version 2, or (at your option)
9fc5a40a2SDavid Howells any later version.
10fc5a40a2SDavid Howells */
11fc5a40a2SDavid Howells
12fc5a40a2SDavid Howells #ifndef _MD_P_H
13fc5a40a2SDavid Howells #define _MD_P_H
14fc5a40a2SDavid Howells
15fc5a40a2SDavid Howells #include <linux/types.h>
16c0f8bd14SAurelien Jarno #include <asm/byteorder.h>
17fc5a40a2SDavid Howells
18fc5a40a2SDavid Howells /*
19fc5a40a2SDavid Howells * RAID superblock.
20fc5a40a2SDavid Howells *
21fc5a40a2SDavid Howells * The RAID superblock maintains some statistics on each RAID configuration.
22fc5a40a2SDavid Howells * Each real device in the RAID set contains it near the end of the device.
23fc5a40a2SDavid Howells * Some of the ideas are copied from the ext2fs implementation.
24fc5a40a2SDavid Howells *
25fc5a40a2SDavid Howells * We currently use 4096 bytes as follows:
26fc5a40a2SDavid Howells *
27fc5a40a2SDavid Howells * word offset function
28fc5a40a2SDavid Howells *
29fc5a40a2SDavid Howells * 0 - 31 Constant generic RAID device information.
30fc5a40a2SDavid Howells * 32 - 63 Generic state information.
31fc5a40a2SDavid Howells * 64 - 127 Personality specific information.
32fc5a40a2SDavid Howells * 128 - 511 12 32-words descriptors of the disks in the raid set.
33fc5a40a2SDavid Howells * 512 - 911 Reserved.
34fc5a40a2SDavid Howells * 912 - 1023 Disk specific descriptor.
35fc5a40a2SDavid Howells */
36fc5a40a2SDavid Howells
37fc5a40a2SDavid Howells /*
38fc5a40a2SDavid Howells * If x is the real device size in bytes, we return an apparent size of:
39fc5a40a2SDavid Howells *
40fc5a40a2SDavid Howells * y = (x & ~(MD_RESERVED_BYTES - 1)) - MD_RESERVED_BYTES
41fc5a40a2SDavid Howells *
42fc5a40a2SDavid Howells * and place the 4kB superblock at offset y.
43fc5a40a2SDavid Howells */
44fc5a40a2SDavid Howells #define MD_RESERVED_BYTES (64 * 1024)
45fc5a40a2SDavid Howells #define MD_RESERVED_SECTORS (MD_RESERVED_BYTES / 512)
46fc5a40a2SDavid Howells
47fc5a40a2SDavid Howells #define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS)
48fc5a40a2SDavid Howells
49fc5a40a2SDavid Howells #define MD_SB_BYTES 4096
50fc5a40a2SDavid Howells #define MD_SB_WORDS (MD_SB_BYTES / 4)
51fc5a40a2SDavid Howells #define MD_SB_SECTORS (MD_SB_BYTES / 512)
52fc5a40a2SDavid Howells
53fc5a40a2SDavid Howells /*
54fc5a40a2SDavid Howells * The following are counted in 32-bit words
55fc5a40a2SDavid Howells */
56fc5a40a2SDavid Howells #define MD_SB_GENERIC_OFFSET 0
57fc5a40a2SDavid Howells #define MD_SB_PERSONALITY_OFFSET 64
58fc5a40a2SDavid Howells #define MD_SB_DISKS_OFFSET 128
59fc5a40a2SDavid Howells #define MD_SB_DESCRIPTOR_OFFSET 992
60fc5a40a2SDavid Howells
61fc5a40a2SDavid Howells #define MD_SB_GENERIC_CONSTANT_WORDS 32
62fc5a40a2SDavid Howells #define MD_SB_GENERIC_STATE_WORDS 32
63fc5a40a2SDavid Howells #define MD_SB_GENERIC_WORDS (MD_SB_GENERIC_CONSTANT_WORDS + MD_SB_GENERIC_STATE_WORDS)
64fc5a40a2SDavid Howells #define MD_SB_PERSONALITY_WORDS 64
65fc5a40a2SDavid Howells #define MD_SB_DESCRIPTOR_WORDS 32
66fc5a40a2SDavid Howells #define MD_SB_DISKS 27
67fc5a40a2SDavid Howells #define MD_SB_DISKS_WORDS (MD_SB_DISKS*MD_SB_DESCRIPTOR_WORDS)
68fc5a40a2SDavid Howells #define MD_SB_RESERVED_WORDS (1024 - MD_SB_GENERIC_WORDS - MD_SB_PERSONALITY_WORDS - MD_SB_DISKS_WORDS - MD_SB_DESCRIPTOR_WORDS)
69fc5a40a2SDavid Howells #define MD_SB_EQUAL_WORDS (MD_SB_GENERIC_WORDS + MD_SB_PERSONALITY_WORDS + MD_SB_DISKS_WORDS)
70fc5a40a2SDavid Howells
71fc5a40a2SDavid Howells /*
72fc5a40a2SDavid Howells * Device "operational" state bits
73fc5a40a2SDavid Howells */
74fc5a40a2SDavid Howells #define MD_DISK_FAULTY 0 /* disk is faulty / operational */
75fc5a40a2SDavid Howells #define MD_DISK_ACTIVE 1 /* disk is running or spare disk */
76fc5a40a2SDavid Howells #define MD_DISK_SYNC 2 /* disk is in sync with the raid set */
77fc5a40a2SDavid Howells #define MD_DISK_REMOVED 3 /* disk is in sync with the raid set */
781aee41f6SGoldwyn Rodrigues #define MD_DISK_CLUSTER_ADD 4 /* Initiate a disk add across the cluster
791aee41f6SGoldwyn Rodrigues * For clustered enviroments only.
801aee41f6SGoldwyn Rodrigues */
811aee41f6SGoldwyn Rodrigues #define MD_DISK_CANDIDATE 5 /* disk is added as spare (local) until confirmed
821aee41f6SGoldwyn Rodrigues * For clustered enviroments only.
831aee41f6SGoldwyn Rodrigues */
84688834e6SNeilBrown #define MD_DISK_FAILFAST 10 /* Send REQ_FAILFAST if there are multiple
85688834e6SNeilBrown * devices available - and don't try to
86688834e6SNeilBrown * correct read errors.
87688834e6SNeilBrown */
88fc5a40a2SDavid Howells
89fc5a40a2SDavid Howells #define MD_DISK_WRITEMOSTLY 9 /* disk is "write-mostly" is RAID1 config.
90fc5a40a2SDavid Howells * read requests will only be sent here in
91fc5a40a2SDavid Howells * dire need
92fc5a40a2SDavid Howells */
93bac624f3SSong Liu #define MD_DISK_JOURNAL 18 /* disk is used as the write journal in RAID-5/6 */
94fc5a40a2SDavid Howells
95c4d4c91bSSong Liu #define MD_DISK_ROLE_SPARE 0xffff
96c4d4c91bSSong Liu #define MD_DISK_ROLE_FAULTY 0xfffe
97bac624f3SSong Liu #define MD_DISK_ROLE_JOURNAL 0xfffd
98c4d4c91bSSong Liu #define MD_DISK_ROLE_MAX 0xff00 /* max value of regular disk role */
99c4d4c91bSSong Liu
100fc5a40a2SDavid Howells typedef struct mdp_device_descriptor_s {
101fc5a40a2SDavid Howells __u32 number; /* 0 Device number in the entire set */
102fc5a40a2SDavid Howells __u32 major; /* 1 Device major number */
103fc5a40a2SDavid Howells __u32 minor; /* 2 Device minor number */
104fc5a40a2SDavid Howells __u32 raid_disk; /* 3 The role of the device in the raid set */
105fc5a40a2SDavid Howells __u32 state; /* 4 Operational state */
106fc5a40a2SDavid Howells __u32 reserved[MD_SB_DESCRIPTOR_WORDS - 5];
107fc5a40a2SDavid Howells } mdp_disk_t;
108fc5a40a2SDavid Howells
109fc5a40a2SDavid Howells #define MD_SB_MAGIC 0xa92b4efc
110fc5a40a2SDavid Howells
111fc5a40a2SDavid Howells /*
112fc5a40a2SDavid Howells * Superblock state bits
113fc5a40a2SDavid Howells */
114fc5a40a2SDavid Howells #define MD_SB_CLEAN 0
115fc5a40a2SDavid Howells #define MD_SB_ERRORS 1
116fc5a40a2SDavid Howells
117ca8895d9SGoldwyn Rodrigues #define MD_SB_CLUSTERED 5 /* MD is clustered */
118fc5a40a2SDavid Howells #define MD_SB_BITMAP_PRESENT 8 /* bitmap may be present nearby */
119fc5a40a2SDavid Howells
120fc5a40a2SDavid Howells /*
121fc5a40a2SDavid Howells * Notes:
122c333f949SRandy Dunlap * - if an array is being reshaped (restriped) in order to change
123fc5a40a2SDavid Howells * the number of active devices in the array, 'raid_disks' will be
124fc5a40a2SDavid Howells * the larger of the old and new numbers. 'delta_disks' will
125fc5a40a2SDavid Howells * be the "new - old". So if +ve, raid_disks is the new value, and
126fc5a40a2SDavid Howells * "raid_disks-delta_disks" is the old. If -ve, raid_disks is the
127fc5a40a2SDavid Howells * old value and "raid_disks+delta_disks" is the new (smaller) value.
128fc5a40a2SDavid Howells */
129fc5a40a2SDavid Howells
130fc5a40a2SDavid Howells
131fc5a40a2SDavid Howells typedef struct mdp_superblock_s {
132fc5a40a2SDavid Howells /*
133fc5a40a2SDavid Howells * Constant generic information
134fc5a40a2SDavid Howells */
135fc5a40a2SDavid Howells __u32 md_magic; /* 0 MD identifier */
136fc5a40a2SDavid Howells __u32 major_version; /* 1 major version to which the set conforms */
137fc5a40a2SDavid Howells __u32 minor_version; /* 2 minor version ... */
138fc5a40a2SDavid Howells __u32 patch_version; /* 3 patchlevel version ... */
139fc5a40a2SDavid Howells __u32 gvalid_words; /* 4 Number of used words in this section */
140fc5a40a2SDavid Howells __u32 set_uuid0; /* 5 Raid set identifier */
141fc5a40a2SDavid Howells __u32 ctime; /* 6 Creation time */
142fc5a40a2SDavid Howells __u32 level; /* 7 Raid personality */
143fc5a40a2SDavid Howells __u32 size; /* 8 Apparent size of each individual disk */
144fc5a40a2SDavid Howells __u32 nr_disks; /* 9 total disks in the raid set */
145fc5a40a2SDavid Howells __u32 raid_disks; /* 10 disks in a fully functional raid set */
146fc5a40a2SDavid Howells __u32 md_minor; /* 11 preferred MD minor device number */
147fc5a40a2SDavid Howells __u32 not_persistent; /* 12 does it have a persistent superblock */
148fc5a40a2SDavid Howells __u32 set_uuid1; /* 13 Raid set identifier #2 */
149fc5a40a2SDavid Howells __u32 set_uuid2; /* 14 Raid set identifier #3 */
150fc5a40a2SDavid Howells __u32 set_uuid3; /* 15 Raid set identifier #4 */
151fc5a40a2SDavid Howells __u32 gstate_creserved[MD_SB_GENERIC_CONSTANT_WORDS - 16];
152fc5a40a2SDavid Howells
153fc5a40a2SDavid Howells /*
154fc5a40a2SDavid Howells * Generic state information
155fc5a40a2SDavid Howells */
156fc5a40a2SDavid Howells __u32 utime; /* 0 Superblock update time */
157fc5a40a2SDavid Howells __u32 state; /* 1 State bits (clean, ...) */
158fc5a40a2SDavid Howells __u32 active_disks; /* 2 Number of currently active disks */
159fc5a40a2SDavid Howells __u32 working_disks; /* 3 Number of working disks */
160fc5a40a2SDavid Howells __u32 failed_disks; /* 4 Number of failed disks */
161fc5a40a2SDavid Howells __u32 spare_disks; /* 5 Number of spare disks */
162fc5a40a2SDavid Howells __u32 sb_csum; /* 6 checksum of the whole superblock */
163ca044f9aSDavid Howells #if defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : defined(__BIG_ENDIAN)
164fc5a40a2SDavid Howells __u32 events_hi; /* 7 high-order of superblock update count */
165fc5a40a2SDavid Howells __u32 events_lo; /* 8 low-order of superblock update count */
166fc5a40a2SDavid Howells __u32 cp_events_hi; /* 9 high-order of checkpoint update count */
167fc5a40a2SDavid Howells __u32 cp_events_lo; /* 10 low-order of checkpoint update count */
168ca044f9aSDavid Howells #elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
169fc5a40a2SDavid Howells __u32 events_lo; /* 7 low-order of superblock update count */
170fc5a40a2SDavid Howells __u32 events_hi; /* 8 high-order of superblock update count */
171fc5a40a2SDavid Howells __u32 cp_events_lo; /* 9 low-order of checkpoint update count */
172fc5a40a2SDavid Howells __u32 cp_events_hi; /* 10 high-order of checkpoint update count */
173ca044f9aSDavid Howells #else
174ca044f9aSDavid Howells #error unspecified endianness
175fc5a40a2SDavid Howells #endif
176fc5a40a2SDavid Howells __u32 recovery_cp; /* 11 recovery checkpoint sector count */
177fc5a40a2SDavid Howells /* There are only valid for minor_version > 90 */
178fc5a40a2SDavid Howells __u64 reshape_position; /* 12,13 next address in array-space for reshape */
179fc5a40a2SDavid Howells __u32 new_level; /* 14 new level we are reshaping to */
180fc5a40a2SDavid Howells __u32 delta_disks; /* 15 change in number of raid_disks */
181fc5a40a2SDavid Howells __u32 new_layout; /* 16 new layout */
182fc5a40a2SDavid Howells __u32 new_chunk; /* 17 new chunk size (bytes) */
183fc5a40a2SDavid Howells __u32 gstate_sreserved[MD_SB_GENERIC_STATE_WORDS - 18];
184fc5a40a2SDavid Howells
185fc5a40a2SDavid Howells /*
186fc5a40a2SDavid Howells * Personality information
187fc5a40a2SDavid Howells */
188fc5a40a2SDavid Howells __u32 layout; /* 0 the array's physical layout */
189fc5a40a2SDavid Howells __u32 chunk_size; /* 1 chunk size in bytes */
190fc5a40a2SDavid Howells __u32 root_pv; /* 2 LV root PV */
191fc5a40a2SDavid Howells __u32 root_block; /* 3 LV root block */
192fc5a40a2SDavid Howells __u32 pstate_reserved[MD_SB_PERSONALITY_WORDS - 4];
193fc5a40a2SDavid Howells
194fc5a40a2SDavid Howells /*
195fc5a40a2SDavid Howells * Disks information
196fc5a40a2SDavid Howells */
197fc5a40a2SDavid Howells mdp_disk_t disks[MD_SB_DISKS];
198fc5a40a2SDavid Howells
199fc5a40a2SDavid Howells /*
200fc5a40a2SDavid Howells * Reserved
201fc5a40a2SDavid Howells */
202fc5a40a2SDavid Howells __u32 reserved[MD_SB_RESERVED_WORDS];
203fc5a40a2SDavid Howells
204fc5a40a2SDavid Howells /*
205fc5a40a2SDavid Howells * Active descriptor
206fc5a40a2SDavid Howells */
207fc5a40a2SDavid Howells mdp_disk_t this_disk;
208fc5a40a2SDavid Howells
209fc5a40a2SDavid Howells } mdp_super_t;
210fc5a40a2SDavid Howells
md_event(mdp_super_t * sb)211fc5a40a2SDavid Howells static inline __u64 md_event(mdp_super_t *sb) {
212fc5a40a2SDavid Howells __u64 ev = sb->events_hi;
213fc5a40a2SDavid Howells return (ev<<32)| sb->events_lo;
214fc5a40a2SDavid Howells }
215fc5a40a2SDavid Howells
216fc5a40a2SDavid Howells #define MD_SUPERBLOCK_1_TIME_SEC_MASK ((1ULL<<40) - 1)
217fc5a40a2SDavid Howells
218fc5a40a2SDavid Howells /*
219fc5a40a2SDavid Howells * The version-1 superblock :
220fc5a40a2SDavid Howells * All numeric fields are little-endian.
221fc5a40a2SDavid Howells *
222fc5a40a2SDavid Howells * total size: 256 bytes plus 2 per device.
223fc5a40a2SDavid Howells * 1K allows 384 devices.
224fc5a40a2SDavid Howells */
225fc5a40a2SDavid Howells struct mdp_superblock_1 {
226fc5a40a2SDavid Howells /* constant array information - 128 bytes */
227fc5a40a2SDavid Howells __le32 magic; /* MD_SB_MAGIC: 0xa92b4efc - little endian */
228fc5a40a2SDavid Howells __le32 major_version; /* 1 */
229fc5a40a2SDavid Howells __le32 feature_map; /* bit 0 set if 'bitmap_offset' is meaningful */
230fc5a40a2SDavid Howells __le32 pad0; /* always set to 0 when writing */
231fc5a40a2SDavid Howells
232fc5a40a2SDavid Howells __u8 set_uuid[16]; /* user-space generated. */
233fc5a40a2SDavid Howells char set_name[32]; /* set and interpreted by user-space */
234fc5a40a2SDavid Howells
235fc5a40a2SDavid Howells __le64 ctime; /* lo 40 bits are seconds, top 24 are microseconds or 0*/
236*127186cfSYu Kuai __le32 level; /* 0,1,4,5, -1 (linear) */
237fc5a40a2SDavid Howells __le32 layout; /* only for raid5 and raid10 currently */
238fc5a40a2SDavid Howells __le64 size; /* used size of component devices, in 512byte sectors */
239fc5a40a2SDavid Howells
240fc5a40a2SDavid Howells __le32 chunksize; /* in 512byte sectors */
241fc5a40a2SDavid Howells __le32 raid_disks;
242ea0213e0SArtur Paszkiewicz union {
243fc5a40a2SDavid Howells __le32 bitmap_offset; /* sectors after start of superblock that bitmap starts
244fc5a40a2SDavid Howells * NOTE: signed, so bitmap can be before superblock
245fc5a40a2SDavid Howells * only meaningful of feature_map[0] is set.
246fc5a40a2SDavid Howells */
247fc5a40a2SDavid Howells
248ea0213e0SArtur Paszkiewicz /* only meaningful when feature_map[MD_FEATURE_PPL] is set */
249ea0213e0SArtur Paszkiewicz struct {
250ea0213e0SArtur Paszkiewicz __le16 offset; /* sectors from start of superblock that ppl starts (signed) */
251ea0213e0SArtur Paszkiewicz __le16 size; /* ppl size in sectors */
252ea0213e0SArtur Paszkiewicz } ppl;
253ea0213e0SArtur Paszkiewicz };
254ea0213e0SArtur Paszkiewicz
255fc5a40a2SDavid Howells /* These are only valid with feature bit '4' */
256fc5a40a2SDavid Howells __le32 new_level; /* new level we are reshaping to */
257fc5a40a2SDavid Howells __le64 reshape_position; /* next address in array-space for reshape */
258fc5a40a2SDavid Howells __le32 delta_disks; /* change in number of raid_disks */
259fc5a40a2SDavid Howells __le32 new_layout; /* new layout */
260fc5a40a2SDavid Howells __le32 new_chunk; /* new chunk size (512byte sectors) */
261fc5a40a2SDavid Howells __le32 new_offset; /* signed number to add to data_offset in new
262fc5a40a2SDavid Howells * layout. 0 == no-change. This can be
263fc5a40a2SDavid Howells * different on each device in the array.
264fc5a40a2SDavid Howells */
265fc5a40a2SDavid Howells
266fc5a40a2SDavid Howells /* constant this-device information - 64 bytes */
267fc5a40a2SDavid Howells __le64 data_offset; /* sector start of data, often 0 */
268fc5a40a2SDavid Howells __le64 data_size; /* sectors in this device that can be used for data */
269fc5a40a2SDavid Howells __le64 super_offset; /* sector start of this superblock */
2703069aa8dSShaohua Li union {
271fc5a40a2SDavid Howells __le64 recovery_offset;/* sectors before this offset (from data_offset) have been recovered */
2723069aa8dSShaohua Li __le64 journal_tail;/* journal tail of journal device (from data_offset) */
2733069aa8dSShaohua Li };
274fc5a40a2SDavid Howells __le32 dev_number; /* permanent identifier of this device - not role in raid */
275fc5a40a2SDavid Howells __le32 cnt_corrected_read; /* number of read errors that were corrected by re-writing */
276fc5a40a2SDavid Howells __u8 device_uuid[16]; /* user-space setable, ignored by kernel */
277688834e6SNeilBrown __u8 devflags; /* per-device flags. Only two defined...*/
278fc5a40a2SDavid Howells #define WriteMostly1 1 /* mask for writemostly flag in above */
279688834e6SNeilBrown #define FailFast1 2 /* Should avoid retries and fixups and just fail */
280fc5a40a2SDavid Howells /* Bad block log. If there are any bad blocks the feature flag is set.
281fc5a40a2SDavid Howells * If offset and size are non-zero, that space is reserved and available
282fc5a40a2SDavid Howells */
283fc5a40a2SDavid Howells __u8 bblog_shift; /* shift from sectors to block size */
284fc5a40a2SDavid Howells __le16 bblog_size; /* number of sectors reserved for list */
285fc5a40a2SDavid Howells __le32 bblog_offset; /* sector offset from superblock to bblog,
286fc5a40a2SDavid Howells * signed - not unsigned */
287fc5a40a2SDavid Howells
288fc5a40a2SDavid Howells /* array state information - 64 bytes */
289fc5a40a2SDavid Howells __le64 utime; /* 40 bits second, 24 bits microseconds */
290fc5a40a2SDavid Howells __le64 events; /* incremented when superblock updated */
291fc5a40a2SDavid Howells __le64 resync_offset; /* data before this offset (from data_offset) known to be in sync */
292fc5a40a2SDavid Howells __le32 sb_csum; /* checksum up to devs[max_dev] */
293fc5a40a2SDavid Howells __le32 max_dev; /* size of devs[] array to consider */
294fc5a40a2SDavid Howells __u8 pad3[64-32]; /* set to 0 when writing */
295fc5a40a2SDavid Howells
296fc5a40a2SDavid Howells /* device state information. Indexed by dev_number.
297fc5a40a2SDavid Howells * 2 bytes per device
298fc5a40a2SDavid Howells * Note there are no per-device state flags. State information is rolled
299fc5a40a2SDavid Howells * into the 'roles' value. If a device is spare or faulty, then it doesn't
300fc5a40a2SDavid Howells * have a meaningful role.
301fc5a40a2SDavid Howells */
30294dfc73eSGustavo A. R. Silva __le16 dev_roles[]; /* role in array, or 0xffff for a spare, or 0xfffe for faulty */
303fc5a40a2SDavid Howells };
304fc5a40a2SDavid Howells
305fc5a40a2SDavid Howells /* feature_map bits */
306fc5a40a2SDavid Howells #define MD_FEATURE_BITMAP_OFFSET 1
307fc5a40a2SDavid Howells #define MD_FEATURE_RECOVERY_OFFSET 2 /* recovery_offset is present and
308fc5a40a2SDavid Howells * must be honoured
309fc5a40a2SDavid Howells */
310fc5a40a2SDavid Howells #define MD_FEATURE_RESHAPE_ACTIVE 4
311fc5a40a2SDavid Howells #define MD_FEATURE_BAD_BLOCKS 8 /* badblock list is not empty */
312fc5a40a2SDavid Howells #define MD_FEATURE_REPLACEMENT 16 /* This device is replacing an
313fc5a40a2SDavid Howells * active device with same 'role'.
314fc5a40a2SDavid Howells * 'recovery_offset' is also set.
315fc5a40a2SDavid Howells */
316fc5a40a2SDavid Howells #define MD_FEATURE_RESHAPE_BACKWARDS 32 /* Reshape doesn't change number
317fc5a40a2SDavid Howells * of devices, but is going
318fc5a40a2SDavid Howells * backwards anyway.
319fc5a40a2SDavid Howells */
320fc5a40a2SDavid Howells #define MD_FEATURE_NEW_OFFSET 64 /* new_offset must be honoured */
321f466722cSNeilBrown #define MD_FEATURE_RECOVERY_BITMAP 128 /* recovery that is happening
322f466722cSNeilBrown * is guided by bitmap.
323f466722cSNeilBrown */
3243c462c88SGoldwyn Rodrigues #define MD_FEATURE_CLUSTERED 256 /* clustered MD */
325bac624f3SSong Liu #define MD_FEATURE_JOURNAL 512 /* support write cache */
326ea0213e0SArtur Paszkiewicz #define MD_FEATURE_PPL 1024 /* support PPL */
327ddc08823SPawel Baldysiak #define MD_FEATURE_MULTIPLE_PPLS 2048 /* support for multiple PPLs */
32833f2c35aSNeilBrown #define MD_FEATURE_RAID0_LAYOUT 4096 /* layout is meaningful for RAID0 */
329fc5a40a2SDavid Howells #define MD_FEATURE_ALL (MD_FEATURE_BITMAP_OFFSET \
330fc5a40a2SDavid Howells |MD_FEATURE_RECOVERY_OFFSET \
331fc5a40a2SDavid Howells |MD_FEATURE_RESHAPE_ACTIVE \
332fc5a40a2SDavid Howells |MD_FEATURE_BAD_BLOCKS \
333fc5a40a2SDavid Howells |MD_FEATURE_REPLACEMENT \
334fc5a40a2SDavid Howells |MD_FEATURE_RESHAPE_BACKWARDS \
335fc5a40a2SDavid Howells |MD_FEATURE_NEW_OFFSET \
336f466722cSNeilBrown |MD_FEATURE_RECOVERY_BITMAP \
3373c462c88SGoldwyn Rodrigues |MD_FEATURE_CLUSTERED \
3385c7e81c3SShaohua Li |MD_FEATURE_JOURNAL \
339ea0213e0SArtur Paszkiewicz |MD_FEATURE_PPL \
340ddc08823SPawel Baldysiak |MD_FEATURE_MULTIPLE_PPLS \
34133f2c35aSNeilBrown |MD_FEATURE_RAID0_LAYOUT \
342fc5a40a2SDavid Howells )
343fc5a40a2SDavid Howells
344f6bed0efSShaohua Li struct r5l_payload_header {
345f6bed0efSShaohua Li __le16 type;
346f6bed0efSShaohua Li __le16 flags;
347f6bed0efSShaohua Li } __attribute__ ((__packed__));
348f6bed0efSShaohua Li
349f6bed0efSShaohua Li enum r5l_payload_type {
350f6bed0efSShaohua Li R5LOG_PAYLOAD_DATA = 0,
351f6bed0efSShaohua Li R5LOG_PAYLOAD_PARITY = 1,
352f6bed0efSShaohua Li R5LOG_PAYLOAD_FLUSH = 2,
353f6bed0efSShaohua Li };
354f6bed0efSShaohua Li
355f6bed0efSShaohua Li struct r5l_payload_data_parity {
356f6bed0efSShaohua Li struct r5l_payload_header header;
357f6bed0efSShaohua Li __le32 size; /* sector. data/parity size. each 4k
358f6bed0efSShaohua Li * has a checksum */
359f6bed0efSShaohua Li __le64 location; /* sector. For data, it's raid sector. For
360f6bed0efSShaohua Li * parity, it's stripe sector */
361f6bed0efSShaohua Li __le32 checksum[];
362f6bed0efSShaohua Li } __attribute__ ((__packed__));
363f6bed0efSShaohua Li
364f6bed0efSShaohua Li enum r5l_payload_data_parity_flag {
365f6bed0efSShaohua Li R5LOG_PAYLOAD_FLAG_DISCARD = 1, /* payload is discard */
366f6bed0efSShaohua Li /*
367f6bed0efSShaohua Li * RESHAPED/RESHAPING is only set when there is reshape activity. Note,
368f6bed0efSShaohua Li * both data/parity of a stripe should have the same flag set
369f6bed0efSShaohua Li *
370f6bed0efSShaohua Li * RESHAPED: reshape is running, and this stripe finished reshape
371f6bed0efSShaohua Li * RESHAPING: reshape is running, and this stripe isn't reshaped
372f6bed0efSShaohua Li */
373f6bed0efSShaohua Li R5LOG_PAYLOAD_FLAG_RESHAPED = 2,
374f6bed0efSShaohua Li R5LOG_PAYLOAD_FLAG_RESHAPING = 3,
375f6bed0efSShaohua Li };
376f6bed0efSShaohua Li
377f6bed0efSShaohua Li struct r5l_payload_flush {
378f6bed0efSShaohua Li struct r5l_payload_header header;
379f6bed0efSShaohua Li __le32 size; /* flush_stripes size, bytes */
380f6bed0efSShaohua Li __le64 flush_stripes[];
381f6bed0efSShaohua Li } __attribute__ ((__packed__));
382f6bed0efSShaohua Li
383f6bed0efSShaohua Li enum r5l_payload_flush_flag {
384f6bed0efSShaohua Li R5LOG_PAYLOAD_FLAG_FLUSH_STRIPE = 1, /* data represents whole stripe */
385f6bed0efSShaohua Li };
386f6bed0efSShaohua Li
387f6bed0efSShaohua Li struct r5l_meta_block {
388f6bed0efSShaohua Li __le32 magic;
389f6bed0efSShaohua Li __le32 checksum;
390f6bed0efSShaohua Li __u8 version;
391f6bed0efSShaohua Li __u8 __zero_pading_1;
392f6bed0efSShaohua Li __le16 __zero_pading_2;
393f6bed0efSShaohua Li __le32 meta_size; /* whole size of the block */
394f6bed0efSShaohua Li
395f6bed0efSShaohua Li __le64 seq;
396f6bed0efSShaohua Li __le64 position; /* sector, start from rdev->data_offset, current position */
397f6bed0efSShaohua Li struct r5l_payload_header payloads[];
398f6bed0efSShaohua Li } __attribute__ ((__packed__));
399f6bed0efSShaohua Li
400f6bed0efSShaohua Li #define R5LOG_VERSION 0x1
401f6bed0efSShaohua Li #define R5LOG_MAGIC 0x6433c509
4023418d036SArtur Paszkiewicz
4033418d036SArtur Paszkiewicz struct ppl_header_entry {
4043418d036SArtur Paszkiewicz __le64 data_sector; /* raid sector of the new data */
4053418d036SArtur Paszkiewicz __le32 pp_size; /* length of partial parity */
4063418d036SArtur Paszkiewicz __le32 data_size; /* length of data */
4073418d036SArtur Paszkiewicz __le32 parity_disk; /* member disk containing parity */
4083418d036SArtur Paszkiewicz __le32 checksum; /* checksum of partial parity data for this
4093418d036SArtur Paszkiewicz * entry (~crc32c) */
4103418d036SArtur Paszkiewicz } __attribute__ ((__packed__));
4113418d036SArtur Paszkiewicz
4123418d036SArtur Paszkiewicz #define PPL_HEADER_SIZE 4096
4133418d036SArtur Paszkiewicz #define PPL_HDR_RESERVED 512
4143418d036SArtur Paszkiewicz #define PPL_HDR_ENTRY_SPACE \
415fc6d2a3cSArtur Paszkiewicz (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(__le32) - sizeof(__le64))
4163418d036SArtur Paszkiewicz #define PPL_HDR_MAX_ENTRIES \
4173418d036SArtur Paszkiewicz (PPL_HDR_ENTRY_SPACE / sizeof(struct ppl_header_entry))
4183418d036SArtur Paszkiewicz
4193418d036SArtur Paszkiewicz struct ppl_header {
4203418d036SArtur Paszkiewicz __u8 reserved[PPL_HDR_RESERVED];/* reserved space, fill with 0xff */
4213418d036SArtur Paszkiewicz __le32 signature; /* signature (family number of volume) */
4223418d036SArtur Paszkiewicz __le32 padding; /* zero pad */
4233418d036SArtur Paszkiewicz __le64 generation; /* generation number of the header */
4243418d036SArtur Paszkiewicz __le32 entries_count; /* number of entries in entry array */
4253418d036SArtur Paszkiewicz __le32 checksum; /* checksum of the header (~crc32c) */
4263418d036SArtur Paszkiewicz struct ppl_header_entry entries[PPL_HDR_MAX_ENTRIES];
4273418d036SArtur Paszkiewicz } __attribute__ ((__packed__));
4283418d036SArtur Paszkiewicz
429fc5a40a2SDavid Howells #endif
430