From 7d99579f6a52fbf575e4707121ece51d0672277b Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 5 Dec 2005 05:56:33 +0000 Subject: [PATCH] Support updating of uuid during --assemble. Signed-off-by: Neil Brown --- Assemble.c | 18 ++++++++++++++++-- ChangeLog | 1 + mdadm.8 | 11 ++++++++++- mdadm.c | 4 +++- super0.c | 6 ++++++ super1.c | 2 ++ 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Assemble.c b/Assemble.c index 9fbc53e8..05558545 100644 --- a/Assemble.c +++ b/Assemble.c @@ -219,7 +219,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd, } if (dfd >= 0) close(dfd); - if (ident->uuid_set && + if (ident->uuid_set && (!update && strcmp(update, "uuid")!= 0) && (!super || same_uuid(info.uuid, ident->uuid, tst->ss->swapuuid)==0)) { if ((inargv && verbose >= 0) || verbose > 0) fprintf(stderr, Name ": %s has wrong uuid.\n", @@ -281,7 +281,21 @@ int Assemble(struct supertype *st, char *mddev, int mdfd, struct stat stb2; fstat(mdfd, &stb2); info.array.md_minor = minor(stb2.st_rdev); - + + if (strcmp(update, "uuid")==0 && + !ident->uuid_set) { + int rfd; + if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 || + read(rfd, ident->uuid, 16) != 16) { + *(__u32*)(ident->uuid) = random(); + *(__u32*)(ident->uuid+1) = random(); + *(__u32*)(ident->uuid+2) = random(); + *(__u32*)(ident->uuid+3) = random(); + } + if (rfd >= 0) close(rfd); + ident->uuid_set = 1; + } + memcpy(info.uuid, ident->uuid, 16); st->ss->update_super(&info, super, update, devname, verbose); dfd = dev_open(devname, O_RDWR|O_EXCL); diff --git a/ChangeLog b/ChangeLog index a83cb0bb..9c9b4f99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,7 @@ Changes Prior to this release mdadm was insisting the event numbers were identical, but this isn't needed, and is a problem if the crash was while the metadata was being updated. + - Support --update==uuid Changes Prior to 2.1 release - Fix assembling of raid10 array when devices are missing. diff --git a/mdadm.8 b/mdadm.8 index e4f60c19..6123ccc0 100644 --- a/mdadm.8 +++ b/mdadm.8 @@ -610,6 +610,7 @@ Update the superblock on each device while assembling the array. The argument given to this flag can be one of .BR sparc2.2 , .BR summaries , +.BR uuid , .BR resync , .BR byteorder , or @@ -617,7 +618,7 @@ or The .B sparc2.2 -option will adjust the superblock of an array what was created on a Sparc +option will adjust the superblock of an array what was created on a Sparc machine running a patched 2.2 Linux kernel. This kernel got the alignment of part of the superblock wrong. You can use the .B "--examine --sparc2.2" @@ -633,6 +634,14 @@ field on each superblock to match the minor number of the array being assembled. This is not needed on 2.6 and later kernels as they make this adjustment automatically. +The +.B uuid +option will change the uuid of the array. If a UUID is given with the +"--uuid" option that UUID will be used as a new UUID and with +.B NOT +be used to help identify the devices in the array. +If no "--uuid" is given, a random uuid is chosen. + The .B resync option will cause the array to be marked diff --git a/mdadm.c b/mdadm.c index 844f6d4a..60e0c3e3 100644 --- a/mdadm.c +++ b/mdadm.c @@ -593,6 +593,8 @@ int main(int argc, char *argv[]) continue; if (strcmp(update, "resync")==0) continue; + if (strcmp(update, "uuid")==0) + continue; if (strcmp(update, "byteorder")==0) { if (ss) { fprintf(stderr, Name ": must not set metadata type with --update=byteorder.\n"); @@ -607,7 +609,7 @@ int main(int argc, char *argv[]) continue; } - fprintf(stderr, Name ": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'resync' or 'summaries' supported\n",update); + fprintf(stderr, Name ": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update); exit(2); case O(ASSEMBLE,'c'): /* config file */ diff --git a/super0.c b/super0.c index 6b8c2081..64acf1a6 100644 --- a/super0.c +++ b/super0.c @@ -359,6 +359,12 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, char *dev sb->state &= ~(1<recovery_cp = 0; } + if (strcmp(update, "uuid") == 0) { + sb->set_uuid0 = info->uuid[0]; + sb->set_uuid1 = info->uuid[1]; + sb->set_uuid2 = info->uuid[2]; + sb->set_uuid3 = info->uuid[3]; + } sb->sb_csum = calc_sb0_csum(sb); return rv; diff --git a/super1.c b/super1.c index a0a3a682..1157da4a 100644 --- a/super1.c +++ b/super1.c @@ -381,6 +381,8 @@ static int update_super1(struct mdinfo *info, void *sbv, char *update, char *dev /* make sure resync happens */ sb->resync_offset = ~0ULL; } + if (strcmp(update, "uuid") == 0) + memcmp(sb->set_uuid, info->uuid, 16); sb->sb_csum = calc_sb_1_csum(sb); return rv; -- 2.39.2