@@ -54,32 +54,32 @@ static time_t mdraid_time = 0; //Array creation timestamp has to be identical ac
54
54
*/
55
55
56
56
#ifndef BITMAP_MAGIC
57
- #define BITMAP_MAGIC 0x6d746962 /* This is actualy just char string saying "bitm" :-) */
57
+ #define BITMAP_MAGIC 0x6d746962 // This is actualy just char string saying "bitm" :-)
58
58
59
- /* use these for bitmap->flags and bitmap->sb->state bit-fields */
59
+ // use these for bitmap->flags and bitmap->sb->state bit-fields
60
60
enum bitmap_state {
61
- BITMAP_STALE = 1 , /* the bitmap file is out of date or had -EIO */
62
- BITMAP_WRITE_ERROR = 2 , /* A write error has occurred */
61
+ BITMAP_STALE = 1 , // the bitmap file is out of date or had -EIO
62
+ BITMAP_WRITE_ERROR = 2 , // A write error has occurred
63
63
BITMAP_HOSTENDIAN = 15 ,
64
64
};
65
65
66
- /* the superblock at the front of the bitmap file -- little endian */
66
+ // the superblock at the front of the bitmap file -- little endian
67
67
typedef struct bitmap_super_s {
68
- __le32 magic ; /* 0 BITMAP_MAGIC */
69
- __le32 version ; /* 4 the bitmap major for now, could change... */
70
- __u8 uuid [16 ]; /* 8 128 bit uuid - must match md device uuid */
71
- __le64 events ; /* 24 event counter for the bitmap (1)*/
72
- __le64 events_cleared ; /* 32 event counter when last bit cleared (2) */
73
- __le64 sync_size ; /* 40 the size of the md device's sync range(3) */
74
- __le32 state ; /* 48 bitmap state information */
75
- __le32 chunksize ; /* 52 the bitmap chunk size in bytes */
76
- __le32 daemon_sleep ; /* 56 seconds between disk flushes */
77
- __le32 write_behind ; /* 60 number of outstanding write-behind writes */
78
- __le32 sectors_reserved ; /* 64 number of 512-byte sectors that are
79
- * reserved for the bitmap. */
80
- __le32 nodes ; /* 68 the maximum number of nodes in cluster. */
81
- __u8 cluster_name [64 ]; /* 72 cluster name to which this md belongs */
82
- __u8 pad [256 - 136 ]; /* set to zero */
68
+ __le32 magic ; // 0 BITMAP_MAGIC
69
+ __le32 version ; // 4 the bitmap major for now, could change...
70
+ __u8 uuid [16 ]; // 8 128 bit uuid - must match md device uuid
71
+ __le64 events ; // 24 event counter for the bitmap (1)*/
72
+ __le64 events_cleared ; // 32 event counter when last bit cleared (2)
73
+ __le64 sync_size ; // 40 the size of the md device's sync range(3)
74
+ __le32 state ; // 48 bitmap state information
75
+ __le32 chunksize ; // 52 the bitmap chunk size in bytes
76
+ __le32 daemon_sleep ; // 56 seconds between disk flushes
77
+ __le32 write_behind ; // 60 number of outstanding write-behind writes
78
+ __le32 sectors_reserved ; // 64 number of 512-byte sectors that are
79
+ // reserved for the bitmap.
80
+ __le32 nodes ; // 68 the maximum number of nodes in cluster.
81
+ __u8 cluster_name [64 ]; // 72 cluster name to which this md belongs
82
+ __u8 pad [256 - 136 ]; // set to zero
83
83
} bitmap_super_t ;
84
84
85
85
/* notes:
@@ -186,32 +186,32 @@ static int mdraid_generate(struct image *image)
186
186
187
187
char * name = cfg_getstr (image -> imagesec , "label" );
188
188
189
- /* constant array information - 128 bytes */
190
- sb -> magic = MD_SB_MAGIC ; /* MD_SB_MAGIC: 0xa92b4efc - little endian. */
191
- sb -> major_version = 1 ; /* Always 1 for 1.xx metadata version :-) */
192
- sb -> feature_map = MD_FEATURE_BITMAP_OFFSET ; /* bit 0 set if 'bitmap_offset' is meaningful */
193
- sb -> pad0 = 0 ; /* always set to 0 when writing */
189
+ // constant array information - 128 bytes
190
+ sb -> magic = MD_SB_MAGIC ; // MD_SB_MAGIC: 0xa92b4efc - little endian.
191
+ sb -> major_version = 1 ; // Always 1 for 1.xx metadata version :-)
192
+ sb -> feature_map = MD_FEATURE_BITMAP_OFFSET ; // bit 0 set if 'bitmap_offset' is meaningful
193
+ sb -> pad0 = 0 ; // always set to 0 when writing
194
194
195
195
char * raid_uuid = cfg_getstr (image -> imagesec , "raid-uuid" );
196
196
if (!raid_uuid )
197
197
raid_uuid = uuid_random ();
198
- uuid_parse (raid_uuid , sb -> set_uuid ); /* user-space generated. U8[16]*/
198
+ uuid_parse (raid_uuid , sb -> set_uuid ); // user-space generated. U8[16]
199
199
200
200
strncpy (sb -> set_name , name , 32 );
201
- sb -> set_name [31 ] = 0 ; /* set and interpreted by user-space. CHAR[32] */
201
+ sb -> set_name [31 ] = 0 ; // set and interpreted by user-space. CHAR[32]
202
202
203
203
long int timestamp = cfg_getint (image -> imagesec , "timestamp" );
204
204
if (timestamp >= 0 ) {
205
205
sb -> ctime = timestamp & 0xffffffffff ;
206
206
} else {
207
- sb -> ctime = mdraid_time & 0xffffffffff ; /* lo 40 bits are seconds, top 24 are microseconds or 0*/
207
+ sb -> ctime = mdraid_time & 0xffffffffff ; // lo 40 bits are seconds, top 24 are microseconds or 0
208
208
}
209
209
210
- sb -> level = 1 ; /* -4 (multipath), -1 (linear), 0,1,4,5 */
211
- //sb->layout; /* only for raid5 and raid10 currently */
212
- sb -> size = (image -> size - DATA_OFFSET_BYTES ) / 512 ; /* used size of component devices, in 512byte sectors */
210
+ sb -> level = 1 ; // -4 (multipath), -1 (linear), 0,1,4,5
211
+ //sb->layout; // only for raid5 and raid10 currently
212
+ sb -> size = (image -> size - DATA_OFFSET_BYTES ) / 512 ; // used size of component devices, in 512byte sectors
213
213
214
- sb -> chunksize = 0 ; /* in 512byte sectors - not used in raid 1 */
214
+ sb -> chunksize = 0 ; // in 512byte sectors - not used in raid 1
215
215
sb -> raid_disks = max_devices ;
216
216
}
217
217
@@ -220,67 +220,67 @@ static int mdraid_generate(struct image *image)
220
220
* only meaningful of feature_map[0] is set.
221
221
*/
222
222
223
- /* constant this-device information - 64 bytes */
224
- sb -> data_offset = DATA_OFFSET_SECTORS ; /* sector start of data, often 0 */
225
- sb -> data_size = sb -> size ; /* sectors in this device that can be used for data */
226
- sb -> super_offset = 8 ; /* sector start of this superblock */
223
+ // constant this-device information - 64 bytes
224
+ sb -> data_offset = DATA_OFFSET_SECTORS ; // sector start of data, often 0
225
+ sb -> data_size = sb -> size ; // sectors in this device that can be used for data
226
+ sb -> super_offset = 8 ; // sector start of this superblock
227
227
228
- sb -> dev_number = role ; /* permanent identifier of this device - not role in raid (They can be equal tho). */
229
- sb -> cnt_corrected_read = 0 ; /* number of read errors that were corrected by re-writing */
228
+ sb -> dev_number = role ; // permanent identifier of this device - not role in raid (They can be equal tho).
229
+ sb -> cnt_corrected_read = 0 ; // number of read errors that were corrected by re-writing
230
230
231
231
char * disk_uuid = cfg_getstr (image -> imagesec , "disk-uuid" );
232
232
if (!disk_uuid )
233
233
disk_uuid = uuid_random ();
234
- uuid_parse (disk_uuid , sb -> device_uuid ); /* user-space setable, ignored by kernel U8[16] */
234
+ uuid_parse (disk_uuid , sb -> device_uuid ); // user-space setable, ignored by kernel U8[16]
235
235
236
- sb -> devflags = 0 ; /* per-device flags. Only two defined...*/
237
- //#define WriteMostly1 1 /* mask for writemostly flag in above */
238
- //#define FailFast1 2 /* Should avoid retries and fixups and just fail */
236
+ sb -> devflags = 0 ; // per-device flags. Only two defined...
237
+ //#define WriteMostly1 1 // mask for writemostly flag in above
238
+ //#define FailFast1 2 // Should avoid retries and fixups and just fail
239
239
240
240
/* Bad block log. If there are any bad blocks the feature flag is set.
241
241
* If offset and size are non-zero, that space is reserved and available
242
242
*/
243
- sb -> bblog_shift = 9 ; /* shift from sectors to badblock size, typicaly 9-12 (shift by 9 is equal to 512 sectors per badblock) */
244
- sb -> bblog_size = 8 ; /* number of sectors reserved for list */
245
- sb -> bblog_offset = sb -> bitmap_offset + BITMAP_SECTORS_MAX + 8 ; /* sector offset from superblock to bblog, signed - not unsigned */
243
+ sb -> bblog_shift = 9 ; // shift from sectors to badblock size, typicaly 9-12 (shift by 9 is equal to 512 sectors per badblock)
244
+ sb -> bblog_size = 8 ; // number of sectors reserved for list
245
+ sb -> bblog_offset = sb -> bitmap_offset + BITMAP_SECTORS_MAX + 8 ; // sector offset from superblock to bblog, signed - not unsigned
246
246
247
- /* array state information - 64 bytes */
248
- sb -> utime = sb -> ctime ; /* 40 bits second, 24 bits microseconds */
249
- sb -> events = 0 ; /* incremented when superblock updated */
250
- sb -> resync_offset = 0 ; /* data before this offset (from data_offset) known to be in sync */
251
- sb -> max_dev = max_devices ; /* size of devs[] array to consider */
252
- //__u8 pad3[64-32]; /* set to 0 when writing */
247
+ // array state information - 64 bytes
248
+ sb -> utime = sb -> ctime ; // 40 bits second, 24 bits microseconds
249
+ sb -> events = 0 ; // incremented when superblock updated
250
+ sb -> resync_offset = 0 ; // data before this offset (from data_offset) known to be in sync
251
+ sb -> max_dev = max_devices ; // size of devs[] array to consider
252
+ //__u8 pad3[64-32]; // set to 0 when writing
253
253
254
254
/* device state information. Indexed by dev_number.
255
255
* 2 bytes per device
256
256
* Note there are no per-device state flags. State information is rolled
257
257
* into the 'roles' value. If a device is spare or faulty, then it doesn't
258
258
* have a meaningful role.
259
259
*/
260
- __le16 * dev_roles = (__le16 * )((char * )sb + sizeof (struct mdp_superblock_1 )); /* role in array, or 0xffff for a spare, or 0xfffe for faulty */
260
+ __le16 * dev_roles = (__le16 * )((char * )sb + sizeof (struct mdp_superblock_1 )); // role in array, or 0xffff for a spare, or 0xfffe for faulty
261
261
//memset(dev_roles, 0xFF, max_devices*2); //All devices in array are set as inactive initialy
262
- for (int i = 0 ; i < max_devices ; i ++ ) { //All devices are assigned roles equal to their dev_number initialy
263
- dev_roles [i ] = i ; //Assign active role to all devices
262
+ for (int i = 0 ; i < max_devices ; i ++ ) { //All devices are assigned roles equal to their dev_number initialy
263
+ dev_roles [i ] = i ; //Assign active role to all devices
264
264
}
265
265
266
266
//Calculate superblock checksum
267
267
sb -> sb_csum = calc_sb_1_csum (sb );
268
268
269
269
//Prepare bitmap superblock (bitmaps don't have checksums for performance reasons)
270
- bsb -> magic = BITMAP_MAGIC ; /* 0 BITMAP_MAGIC - This is actualy just char string saying "bitm" :-) */
271
- bsb -> version = 4 ; /* v4 is compatible with mdraid v1.2, 4 the bitmap major for now, could change... */
272
- memcpy (bsb -> uuid , sb -> set_uuid , sizeof (bsb -> uuid )); /* 8 128 bit uuid - must match md device uuid */
273
- //bsb->events = 0; /* 24 event counter for the bitmap (1)*/
274
- //bsb->events_cleared = 0;/* 32 event counter when last bit cleared (2) */
275
- bsb -> sync_size = sb -> data_size ; /* 40 the size of the md device's sync range(3) */
276
- //bsb->state = 0; /* 48 bitmap state information */
277
- bsb -> chunksize = 64 * 1024 * 1024 ; /* 52 the bitmap chunk size in bytes, 64MB is default on linux */
278
- bsb -> daemon_sleep = 5 ; /* 5 is considered safe default. 56 seconds between disk flushes */
279
- //bsb->write_behind = 0; /* 60 number of outstanding write-behind writes */
280
- bsb -> sectors_reserved = roundup (bsb -> sync_size / bsb -> chunksize , 8 ); /* 64 number of 512-byte sectors that are reserved for the bitmap. */
281
- //bsb->nodes; /* 68 the maximum number of nodes in cluster. */
282
- //bsb->cluster_name[64]; /* 72 cluster name to which this md belongs */
283
- //__u8 pad[256 - 136]; /* set to zero */
270
+ bsb -> magic = BITMAP_MAGIC ; // 0 BITMAP_MAGIC - This is actualy just char string saying "bitm" :-)
271
+ bsb -> version = 4 ; // v4 is compatible with mdraid v1.2, 4 the bitmap major for now, could change...
272
+ memcpy (bsb -> uuid , sb -> set_uuid , sizeof (bsb -> uuid )); // 8 128 bit uuid - must match md device uuid
273
+ //bsb->events = 0; // 24 event counter for the bitmap (1)*/
274
+ //bsb->events_cleared = 0; // 32 event counter when last bit cleared (2)
275
+ bsb -> sync_size = sb -> data_size ; // 40 the size of the md device's sync range(3)
276
+ //bsb->state = 0; // 48 bitmap state information
277
+ bsb -> chunksize = 64 * 1024 * 1024 ; // 52 the bitmap chunk size in bytes, 64MB is default on linux
278
+ bsb -> daemon_sleep = 5 ; // 5 is considered safe default. 56 seconds between disk flushes
279
+ //bsb->write_behind = 0; // 60 number of outstanding write-behind writes
280
+ bsb -> sectors_reserved = roundup (bsb -> sync_size / bsb -> chunksize , 8 ); // 64 number of 512-byte sectors that are reserved for the bitmap.
281
+ //bsb->nodes; // 68 the maximum number of nodes in cluster.
282
+ //bsb->cluster_name[64]; // 72 cluster name to which this md belongs
283
+ //__u8 pad[256 - 136]; // set to zero
284
284
285
285
//Increase bitmap chunk size till we fit in sectors max
286
286
while (bsb -> sectors_reserved > BITMAP_SECTORS_MAX ) {
0 commit comments