summaryrefslogtreecommitdiffstats
path: root/super0.c
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2006-12-14 17:33:10 +1100
committerNeil Brown <neilb@suse.de>2006-12-14 17:33:10 +1100
commit3d3dd91e3837d5eb6eeaa876c39153f2b0a4929d (patch)
tree912f688af1c896c0ee76ef5a517a2e25e3860e58 /super0.c
parent4855f95c7081d7438b55fed8f8808cc656f0ccc0 (diff)
downloadmdadm-3d3dd91e3837d5eb6eeaa876c39153f2b0a4929d.tar.gz
mdadm-3d3dd91e3837d5eb6eeaa876c39153f2b0a4929d.tar.xz
mdadm-3d3dd91e3837d5eb6eeaa876c39153f2b0a4929d.zip
Support --uuid= with --create to choose your own UUID.
Diffstat (limited to 'super0.c')
-rw-r--r--super0.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/super0.c b/super0.c
index 770d96e..757d905 100644
--- a/super0.c
+++ b/super0.c
@@ -505,11 +505,11 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update,
static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
- unsigned long long size, char *ignored_name, char *homehost)
+ unsigned long long size, char *ignored_name, char *homehost,
+ int *uuid)
{
mdp_super_t *sb = malloc(MD_SB_BYTES + sizeof(bitmap_super_t));
int spares;
- int rfd;
memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
if (info->major_version == -1) {
@@ -525,14 +525,11 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
return 0;
}
- rfd = open("/dev/urandom", O_RDONLY);
sb->md_magic = MD_SB_MAGIC;
sb->major_version = 0;
sb->minor_version = 90;
sb->patch_version = 0;
sb->gvalid_words = 0; /* ignored */
- if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
- sb->set_uuid0 = random();
sb->ctime = time(0);
sb->level = info->level;
if (size != info->size)
@@ -542,13 +539,23 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
sb->raid_disks = info->raid_disks;
sb->md_minor = info->md_minor;
sb->not_persistent = 0;
- if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
- sb->set_uuid1 = random();
- sb->set_uuid2 = random();
- sb->set_uuid3 = random();
+ if (uuid) {
+ sb->set_uuid0 = uuid[0];
+ sb->set_uuid1 = uuid[1];
+ sb->set_uuid2 = uuid[2];
+ sb->set_uuid3 = uuid[3];
+ } else {
+ int rfd = open("/dev/urandom", O_RDONLY);
+ if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
+ sb->set_uuid0 = random();
+ if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
+ sb->set_uuid1 = random();
+ sb->set_uuid2 = random();
+ sb->set_uuid3 = random();
+ }
+ if (rfd >= 0)
+ close(rfd);
}
- if (rfd >= 0)
- close(rfd);
if (homehost) {
char buf[20];
char *hash = sha1_buffer(homehost,