Support updating of uuid during --assemble.

Signed-off-by: Neil Brown <neilb@suse.de>
This commit is contained in:
Neil Brown 2005-12-05 05:56:33 +00:00
parent ee04451c56
commit 7d99579f6a
6 changed files with 38 additions and 4 deletions

View File

@ -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);

View File

@ -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.

11
mdadm.8
View File

@ -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

View File

@ -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 */

View File

@ -359,6 +359,12 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, char *dev
sb->state &= ~(1<<MD_SB_CLEAN);
sb->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;

View File

@ -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;