Skip to content

Commit

Permalink
Keep the timestamp consistent across whole genimage invocation to mak…
Browse files Browse the repository at this point in the history
…e sure all member disks refer to the same array

Signed-off-by: Tomas Mudrunka <[email protected]>
  • Loading branch information
Harvie committed Dec 29, 2024
1 parent 7857b56 commit 79abd4a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions image-mdraid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit 79abd4a

Please sign in to comment.