From e807fa62fa3b62e1f850c6debd745fd001018c94 Mon Sep 17 00:00:00 2001 From: Tomas Mudrunka Date: Sat, 21 Dec 2024 01:12:37 +0100 Subject: [PATCH] Configurable timestamp and uuids for repeatable builds and testing Signed-off-by: Tomas Mudrunka --- image-mdraid.c | 25 +++++++++++++++++++++---- test/mdraid.config | 3 +++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/image-mdraid.c b/image-mdraid.c index 84e88b8..0cdfad0 100644 --- a/image-mdraid.c +++ b/image-mdraid.c @@ -44,6 +44,7 @@ Some docs: #define DATA_OFFSET_BYTES (DATA_OFFSET_SECTORS*512) #define MDRAID_MAGIC 0xa92b4efc +/* static void random_uuid(__u8 *buf) { __u32 r[4]; @@ -51,6 +52,7 @@ static void random_uuid(__u8 *buf) r[i] = random(); memcpy(buf, r, 16); } +*/ static unsigned int calc_sb_1_csum(struct mdp_superblock_1 * sb) { @@ -100,9 +102,18 @@ static int mdraid_generate(struct image *image) { sb->feature_map = 0; //MD_FEATURE_BITMAP_OFFSET; /* bit 0 set if 'bitmap_offset' is meaningful */ //TODO: internal bitmap bit is ignored, unless there is correct bitmap with BITMAP_MAGIC in place sb->pad0 = 0; /* always set to 0 when writing */ - random_uuid(sb->set_uuid); /* user-space generated. U8[16]*/ //TODO: should we allow user to set this? + 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]*/ + strncpy(sb->set_name, name, 32); sb->set_name[31] = 0; /* set and interpreted by user-space. CHAR[32] */ - sb->ctime = time(NULL) & 0xffffffffff; /* lo 40 bits are seconds, top 24 are microseconds or 0*/ + + long int timestamp = cfg_getint(image->imagesec, "timestamp"); + if (timestamp >= 0) { + sb->ctime = timestamp & 0xffffffffff; + } else { + sb->ctime = time(NULL) & 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 = 2; /* only for raid5 and raid10 currently */ @@ -122,7 +133,11 @@ static int mdraid_generate(struct image *image) { sb->dev_number = 0; /* permanent identifier of this device - not role in raid */ sb->cnt_corrected_read = 0; /* number of read errors that were corrected by re-writing */ - random_uuid(sb->device_uuid); /* user-space setable, ignored by kernel U8[16] */ //TODO: should we allow user to set this? + + 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] */ + 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 */ @@ -181,7 +196,6 @@ static int mdraid_setup(struct image *image, cfg_t *cfg) { return 1; } - struct image *img_in = NULL; struct partition *part; list_for_each_entry(part, &image->partitions, list) { @@ -214,6 +228,9 @@ static int mdraid_setup(struct image *image, cfg_t *cfg) { static cfg_opt_t mdraid_opts[] = { CFG_STR("label", "localhost:42", CFGF_NONE), CFG_INT("level", 1, CFGF_NONE), + CFG_INT("timestamp", -1, CFGF_NONE), + CFG_STR("raid-uuid", NULL, CFGF_NONE), + CFG_STR("disk-uuid", NULL, CFGF_NONE), CFG_END() }; diff --git a/test/mdraid.config b/test/mdraid.config index ef10551..5965ef2 100644 --- a/test/mdraid.config +++ b/test/mdraid.config @@ -1,6 +1,9 @@ image test.mdraid { mdraid { level = 1 + timestamp = 638022222 + raid-uuid = "de9980f1-0449-4e83-84bd-98e4b1ca3fe3" + disk-uuid = "eb3b107b-ae9d-4c6b-994a-ec412d36959b" } size = 5M }