From 79abd4a0feea1ccfa8ca60adc4123f457520c70b Mon Sep 17 00:00:00 2001 From: Tomas Mudrunka Date: Sun, 29 Dec 2024 15:35:10 +0100 Subject: [PATCH] Keep the timestamp consistent across whole genimage invocation to make sure all member disks refer to the same array Signed-off-by: Tomas Mudrunka --- image-mdraid.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/image-mdraid.c b/image-mdraid.c index f66829f..c7feaa2 100644 --- a/image-mdraid.c +++ b/image-mdraid.c @@ -46,6 +46,8 @@ Some docs: #define BITMAP_SECTORS_MAX 256 #define MDRAID_ALIGN_BYTES 8*512 //(should be divisible by 8 sectors to keep 4kB alignment) +static time_t mdraid_time = 0; //Creation timestamp has to be unique across all the raid members, so we share it between invocations + /* * bitmap structures: @@ -165,7 +167,7 @@ static int mdraid_generate(struct image *image) { 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->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 */ @@ -270,7 +272,10 @@ static int mdraid_generate(struct image *image) { } static int mdraid_setup(struct image *image, cfg_t *cfg) { - srand(time(NULL)); //TODO: Should we seed UUID in more unique way? + if(!mdraid_time) { + mdraid_time = time(NULL); + srandom(mdraid_time); //For UUID generation + } int raid_level = cfg_getint(image->imagesec, "level");