]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Support updating of uuid during --assemble.
authorNeil Brown <neilb@suse.de>
Mon, 5 Dec 2005 05:56:33 +0000 (05:56 +0000)
committerNeil Brown <neilb@suse.de>
Mon, 5 Dec 2005 05:56:33 +0000 (05:56 +0000)
Signed-off-by: Neil Brown <neilb@suse.de>
Assemble.c
ChangeLog
mdadm.8
mdadm.c
super0.c
super1.c

index 9fbc53e8539ca9135e2e18643cd338d9015a1f27..05558545ca08a8364bb4809c2bc2aefc4e027da1 100644 (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);
index a83cb0bb41684dcbbe2d65f35486e112225a045f..9c9b4f9944722f14f042f299fe82b1e876f7a47d 100644 (file)
--- 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 e4f60c19d497f0d912a2c5600dd1719403d9b882..6123ccc0261583baa0bcec1ed635a1c07ff6753d 100644 (file)
--- 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 844f6d4af6bd97c1e0e7b06a620014ab069bef90..60e0c3e340dba6f4408f90fc287156995a9a834a 100644 (file)
--- 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 */
index 6b8c2081799db396dbb3e477cc87572f676e0aff..64acf1a609cd22814401308421b1b85803b4177e 100644 (file)
--- 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<<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;
index a0a3a682d85640618fea123ee472080b9d0acdeb..1157da4a4162e49c5e6f6a0d1a2a2c9aec5eea9f 100644 (file)
--- 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;