From f080798f88e0ec9bd3c194e15f2fd0629e73ede7 Mon Sep 17 00:00:00 2001 From: Tomas Mudrunka Date: Fri, 10 Jan 2025 15:37:08 +0100 Subject: [PATCH] Unified comment style Signed-off-by: Tomas Mudrunka --- image-mdraid.c | 136 ++++++++++++++++++++++++------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/image-mdraid.c b/image-mdraid.c index d9280c1..7a48f22 100644 --- a/image-mdraid.c +++ b/image-mdraid.c @@ -54,32 +54,32 @@ static time_t mdraid_time = 0; //Array creation timestamp has to be identical ac */ #ifndef BITMAP_MAGIC -#define BITMAP_MAGIC 0x6d746962 /* This is actualy just char string saying "bitm" :-) */ +#define BITMAP_MAGIC 0x6d746962 // This is actualy just char string saying "bitm" :-) -/* use these for bitmap->flags and bitmap->sb->state bit-fields */ +// use these for bitmap->flags and bitmap->sb->state bit-fields enum bitmap_state { - BITMAP_STALE = 1, /* the bitmap file is out of date or had -EIO */ - BITMAP_WRITE_ERROR = 2, /* A write error has occurred */ + BITMAP_STALE = 1, // the bitmap file is out of date or had -EIO + BITMAP_WRITE_ERROR = 2, // A write error has occurred BITMAP_HOSTENDIAN = 15, }; -/* the superblock at the front of the bitmap file -- little endian */ +// the superblock at the front of the bitmap file -- little endian typedef struct bitmap_super_s { - __le32 magic; /* 0 BITMAP_MAGIC */ - __le32 version; /* 4 the bitmap major for now, could change... */ - __u8 uuid[16]; /* 8 128 bit uuid - must match md device uuid */ - __le64 events; /* 24 event counter for the bitmap (1)*/ - __le64 events_cleared; /*32 event counter when last bit cleared (2) */ - __le64 sync_size; /* 40 the size of the md device's sync range(3) */ - __le32 state; /* 48 bitmap state information */ - __le32 chunksize; /* 52 the bitmap chunk size in bytes */ - __le32 daemon_sleep; /* 56 seconds between disk flushes */ - __le32 write_behind; /* 60 number of outstanding write-behind writes */ - __le32 sectors_reserved; /* 64 number of 512-byte sectors that are - * reserved for the bitmap. */ - __le32 nodes; /* 68 the maximum number of nodes in cluster. */ - __u8 cluster_name[64]; /* 72 cluster name to which this md belongs */ - __u8 pad[256 - 136]; /* set to zero */ + __le32 magic; // 0 BITMAP_MAGIC + __le32 version; // 4 the bitmap major for now, could change... + __u8 uuid[16]; // 8 128 bit uuid - must match md device uuid + __le64 events; // 24 event counter for the bitmap (1)*/ + __le64 events_cleared; // 32 event counter when last bit cleared (2) + __le64 sync_size; // 40 the size of the md device's sync range(3) + __le32 state; // 48 bitmap state information + __le32 chunksize; // 52 the bitmap chunk size in bytes + __le32 daemon_sleep; // 56 seconds between disk flushes + __le32 write_behind; // 60 number of outstanding write-behind writes + __le32 sectors_reserved; // 64 number of 512-byte sectors that are + // reserved for the bitmap. + __le32 nodes; // 68 the maximum number of nodes in cluster. + __u8 cluster_name[64]; // 72 cluster name to which this md belongs + __u8 pad[256 - 136]; // set to zero } bitmap_super_t; /* notes: @@ -186,32 +186,32 @@ static int mdraid_generate(struct image *image) char *name = cfg_getstr(image->imagesec, "label"); - /* constant array information - 128 bytes */ - sb->magic = MD_SB_MAGIC; /* MD_SB_MAGIC: 0xa92b4efc - little endian. */ - sb->major_version = 1; /* Always 1 for 1.xx metadata version :-) */ - sb->feature_map = MD_FEATURE_BITMAP_OFFSET; /* bit 0 set if 'bitmap_offset' is meaningful */ - sb->pad0 = 0; /* always set to 0 when writing */ + //constant array information - 128 bytes + sb->magic = MD_SB_MAGIC; // MD_SB_MAGIC: 0xa92b4efc - little endian. + sb->major_version = 1; // Always 1 for 1.xx metadata version :-) + sb->feature_map = MD_FEATURE_BITMAP_OFFSET; // bit 0 set if 'bitmap_offset' is meaningful + sb->pad0 = 0; // always set to 0 when writing char *raid_uuid = cfg_getstr(image->imagesec, "raid-uuid"); if (!raid_uuid) raid_uuid = uuid_random(); - uuid_parse(raid_uuid, sb->set_uuid); /* user-space generated. U8[16]*/ + uuid_parse(raid_uuid, sb->set_uuid); // user-space generated. U8[16] strncpy(sb->set_name, name, 32); - sb->set_name[31] = 0; /* set and interpreted by user-space. CHAR[32] */ + sb->set_name[31] = 0; // set and interpreted by user-space. CHAR[32] long int timestamp = cfg_getint(image->imagesec, "timestamp"); if (timestamp >= 0) { sb->ctime = timestamp & 0xffffffffff; } else { - sb->ctime = mdraid_time & 0xffffffffff; /* lo 40 bits are seconds, top 24 are microseconds or 0*/ + sb->ctime = mdraid_time & 0xffffffffff; // lo 40 bits are seconds, top 24 are microseconds or 0 } - sb->level = 1; /* -4 (multipath), -1 (linear), 0,1,4,5 */ - //sb->layout; /* only for raid5 and raid10 currently */ - sb->size = (image->size - DATA_OFFSET_BYTES) / 512; /* used size of component devices, in 512byte sectors */ + sb->level = 1; // -4 (multipath), -1 (linear), 0,1,4,5 + //sb->layout; // only for raid5 and raid10 currently + sb->size = (image->size - DATA_OFFSET_BYTES) / 512; // used size of component devices, in 512byte sectors - sb->chunksize = 0; /* in 512byte sectors - not used in raid 1 */ + sb->chunksize = 0; // in 512byte sectors - not used in raid 1 sb->raid_disks = max_devices; } @@ -220,36 +220,36 @@ static int mdraid_generate(struct image *image) * only meaningful of feature_map[0] is set. */ - /* constant this-device information - 64 bytes */ - sb->data_offset = DATA_OFFSET_SECTORS; /* sector start of data, often 0 */ - sb->data_size = sb->size; /* sectors in this device that can be used for data */ - sb->super_offset = 8; /* sector start of this superblock */ + // constant this-device information - 64 bytes + sb->data_offset = DATA_OFFSET_SECTORS; // sector start of data, often 0 + sb->data_size = sb->size; // sectors in this device that can be used for data + sb->super_offset = 8; // sector start of this superblock - sb->dev_number = role; /* permanent identifier of this device - not role in raid (They can be equal tho). */ - sb->cnt_corrected_read = 0; /* number of read errors that were corrected by re-writing */ + sb->dev_number = role; // permanent identifier of this device - not role in raid (They can be equal tho). + sb->cnt_corrected_read = 0; // number of read errors that were corrected by re-writing char *disk_uuid = cfg_getstr(image->imagesec, "disk-uuid"); if (!disk_uuid) disk_uuid = uuid_random(); - uuid_parse(disk_uuid, sb->device_uuid); /* user-space setable, ignored by kernel U8[16] */ + uuid_parse(disk_uuid, sb->device_uuid); // user-space setable, ignored by kernel U8[16] - sb->devflags = 0; /* per-device flags. Only two defined...*/ - //#define WriteMostly1 1 /* mask for writemostly flag in above */ - //#define FailFast1 2 /* Should avoid retries and fixups and just fail */ + sb->devflags = 0; // per-device flags. Only two defined... + //#define WriteMostly1 1 // mask for writemostly flag in above + //#define FailFast1 2 // Should avoid retries and fixups and just fail /* Bad block log. If there are any bad blocks the feature flag is set. * If offset and size are non-zero, that space is reserved and available */ - sb->bblog_shift = 9; /* shift from sectors to badblock size, typicaly 9-12 (shift by 9 is equal to 512 sectors per badblock) */ - sb->bblog_size = 8; /* number of sectors reserved for list */ - sb->bblog_offset = sb->bitmap_offset + BITMAP_SECTORS_MAX + 8; /* sector offset from superblock to bblog, signed - not unsigned */ + sb->bblog_shift = 9; // shift from sectors to badblock size, typicaly 9-12 (shift by 9 is equal to 512 sectors per badblock) + sb->bblog_size = 8; // number of sectors reserved for list + sb->bblog_offset = sb->bitmap_offset + BITMAP_SECTORS_MAX + 8; // sector offset from superblock to bblog, signed - not unsigned - /* array state information - 64 bytes */ - sb->utime = sb->ctime; /* 40 bits second, 24 bits microseconds */ - sb->events = 0; /* incremented when superblock updated */ - sb->resync_offset = 0; /* data before this offset (from data_offset) known to be in sync */ - sb->max_dev = max_devices; /* size of devs[] array to consider */ - //__u8 pad3[64-32]; /* set to 0 when writing */ + // array state information - 64 bytes + sb->utime = sb->ctime; // 40 bits second, 24 bits microseconds + sb->events = 0; // incremented when superblock updated + sb->resync_offset = 0; // data before this offset (from data_offset) known to be in sync + sb->max_dev = max_devices; // size of devs[] array to consider + //__u8 pad3[64-32]; // set to 0 when writing /* device state information. Indexed by dev_number. * 2 bytes per device @@ -257,30 +257,30 @@ static int mdraid_generate(struct image *image) * into the 'roles' value. If a device is spare or faulty, then it doesn't * have a meaningful role. */ - __le16 *dev_roles = (__le16 *)((char *)sb + sizeof(struct mdp_superblock_1)); /* role in array, or 0xffff for a spare, or 0xfffe for faulty */ + __le16 *dev_roles = (__le16 *)((char *)sb + sizeof(struct mdp_superblock_1)); // role in array, or 0xffff for a spare, or 0xfffe for faulty //memset(dev_roles, 0xFF, max_devices*2); //All devices in array are set as inactive initialy - for (int i = 0; i < max_devices; i++) { //All devices are assigned roles equal to their dev_number initialy - dev_roles[i] = i; //Assign active role to all devices + for (int i = 0; i < max_devices; i++) { //All devices are assigned roles equal to their dev_number initialy + dev_roles[i] = i; //Assign active role to all devices } //Calculate superblock checksum sb->sb_csum = calc_sb_1_csum(sb); //Prepare bitmap superblock (bitmaps don't have checksums for performance reasons) - bsb->magic = BITMAP_MAGIC; /* 0 BITMAP_MAGIC - This is actualy just char string saying "bitm" :-) */ - bsb->version = 4; /* v4 is compatible with mdraid v1.2, 4 the bitmap major for now, could change... */ - memcpy(bsb->uuid, sb->set_uuid, sizeof(bsb->uuid)); /* 8 128 bit uuid - must match md device uuid */ - //bsb->events = 0; /* 24 event counter for the bitmap (1)*/ - //bsb->events_cleared = 0;/*32 event counter when last bit cleared (2) */ - bsb->sync_size = sb->data_size; /* 40 the size of the md device's sync range(3) */ - //bsb->state = 0; /* 48 bitmap state information */ - bsb->chunksize = 64 * 1024 * 1024; /* 52 the bitmap chunk size in bytes, 64MB is default on linux */ - bsb->daemon_sleep = 5; /* 5 is considered safe default. 56 seconds between disk flushes */ - //bsb->write_behind = 0; /* 60 number of outstanding write-behind writes */ - bsb->sectors_reserved = roundup(bsb->sync_size / bsb->chunksize, 8); /* 64 number of 512-byte sectors that are reserved for the bitmap. */ - //bsb->nodes; /* 68 the maximum number of nodes in cluster. */ - //bsb->cluster_name[64]; /* 72 cluster name to which this md belongs */ - //__u8 pad[256 - 136]; /* set to zero */ + bsb->magic = BITMAP_MAGIC; // 0 BITMAP_MAGIC - This is actualy just char string saying "bitm" :-) + bsb->version = 4; // v4 is compatible with mdraid v1.2, 4 the bitmap major for now, could change... + memcpy(bsb->uuid, sb->set_uuid, sizeof(bsb->uuid)); // 8 128 bit uuid - must match md device uuid + //bsb->events = 0; // 24 event counter for the bitmap (1)*/ + //bsb->events_cleared = 0; // 32 event counter when last bit cleared (2) + bsb->sync_size = sb->data_size; // 40 the size of the md device's sync range(3) + //bsb->state = 0; // 48 bitmap state information + bsb->chunksize = 64 * 1024 * 1024; // 52 the bitmap chunk size in bytes, 64MB is default on linux + bsb->daemon_sleep = 5; // 5 is considered safe default. 56 seconds between disk flushes + //bsb->write_behind = 0; // 60 number of outstanding write-behind writes + bsb->sectors_reserved = roundup(bsb->sync_size / bsb->chunksize, 8); // 64 number of 512-byte sectors that are reserved for the bitmap. + //bsb->nodes; // 68 the maximum number of nodes in cluster. + //bsb->cluster_name[64]; // 72 cluster name to which this md belongs + //__u8 pad[256 - 136]; // set to zero //Increase bitmap chunk size till we fit in sectors max while (bsb->sectors_reserved > BITMAP_SECTORS_MAX) {