]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Make sure homehost is set correctly when --update=uuid
authorNeil Brown <neilb@suse.de>
Tue, 23 May 2006 04:51:39 +0000 (04:51 +0000)
committerNeil Brown <neilb@suse.de>
Tue, 23 May 2006 04:51:39 +0000 (04:51 +0000)
Signed-off-by: Neil Brown <neilb@suse.de>
Assemble.c
Examine.c
Grow.c
mdadm.c
mdadm.h
super0.c
super1.c

index 29bf059a2d43643bd1e71b3106183a1d126bc9b2..30cb1aa090eac120f1c58cc38c6290b95bbed954 100644 (file)
@@ -33,7 +33,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
             mddev_ident_t ident, char *conffile,
             mddev_dev_t devlist, char *backup_file,
             int readonly, int runstop,
-            char *update,
+            char *update, char *homehost,
             int verbose, int force)
 {
        /*
@@ -294,11 +294,16 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                                        *(__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);
-                       
+                       strcpy(info.name, ident->name);
+                       st->ss->update_super(&info, super, update, devname, verbose,
+                                            ident->uuid_set, homehost);
+                       if (strcmp(update, "uuid")==0 &&
+                           !ident->uuid_set) {
+                               ident->uuid_set = 1;
+                               memcpy(ident->uuid, info.uuid, 16);
+                       }
                        dfd = dev_open(devname, O_RDWR|O_EXCL);
                        if (dfd < 0)
                                fprintf(stderr, Name ": Cannot open %s for superblock update\n",
@@ -451,7 +456,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                        continue;
                }
                info.events = devices[most_recent].events;
-               st->ss->update_super(&info, super, "force", devices[chosen_drive].devname, verbose);
+               st->ss->update_super(&info, super, "force", devices[chosen_drive].devname, verbose, 0, NULL);
 
                if (st->ss->store_super(st, fd, super)) {
                        close(fd);
@@ -522,7 +527,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                info.disk.state = desired_state;
 
                if (devices[j].uptodate &&
-                   st->ss->update_super(&info, super, "assemble", NULL, verbose)) {
+                   st->ss->update_super(&info, super, "assemble", NULL, verbose, 0, NULL)) {
                        if (force) {
                                if (verbose >= 0)
                                        fprintf(stderr, Name ": "
@@ -547,7 +552,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
        if (force && okcnt == info.array.raid_disks-1) {
                /* FIXME check event count */
                change += st->ss->update_super(&info, super, "force",
-                                       devices[chosen_drive].devname, verbose);
+                                       devices[chosen_drive].devname, verbose, 0, NULL);
        }
 
        if (change) {
index 16b1b9ba5ae241dfdfb59fbd15e0f1095092a808..8a8f8f4461aef2b379d64c77d3842b892190986b 100644 (file)
--- a/Examine.c
+++ b/Examine.c
@@ -98,7 +98,7 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
                }
 
                if (SparcAdjust)
-                       st->ss->update_super(NULL, super, "sparc2.2", devlist->devname,  0);
+                       st->ss->update_super(NULL, super, "sparc2.2", devlist->devname, 0, 0, NULL);
                /* Ok, its good enough to try, though the checksum could be wrong */
                if (brief) {
                        struct array *ap;
diff --git a/Grow.c b/Grow.c
index 9b98e9fd79146d9640cc0f4f9c5610e3665074de..8c8aa285240b5278a911a47b97aa1be0badc6990 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -121,7 +121,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
        info.disk.minor = minor(stb.st_rdev);
        info.disk.raid_disk = d;
        info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
-       st->ss->update_super(&info, super, "grow", newdev, 0);
+       st->ss->update_super(&info, super, "grow", newdev, 0, 0, NULL);
 
        if (st->ss->store_super(st, nfd, super)) {
                fprintf(stderr, Name ": Cannot store new superblock on %s\n", newdev);
@@ -179,7 +179,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                info.disk.minor = minor(stb.st_rdev);
                info.disk.raid_disk = nd;
                info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
-               st->ss->update_super(&info, super, "grow", dv, 0);
+               st->ss->update_super(&info, super, "grow", dv, 0, 0, NULL);
                
                if (st->ss->store_super(st, fd2, super)) {
                        fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv);
@@ -948,7 +948,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
                                continue;
                        st->ss->getinfo_super(&dinfo, super);
                        dinfo.reshape_progress = __le64_to_cpu(bsb.length);
-                       st->ss->update_super(&dinfo, super, "_reshape_progress",NULL,0);
+                       st->ss->update_super(&dinfo, super, "_reshape_progress",NULL,0, 0, NULL);
                        st->ss->store_super(st, fdlist[j], super);
                        free(super);
                }
diff --git a/mdadm.c b/mdadm.c
index dc3e282a6707038b6ec5447725ac4f5c2f5e11a0..880fa94ae21d5882e306f10f5be9081f5fa03a5f 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -939,14 +939,14 @@ int main(int argc, char *argv[])
                                else {
                                        rv |= Assemble(ss, devlist->devname, mdfd, array_ident, configfile,
                                                       NULL, backup_file,
-                                                      readonly, runstop, update, verbose-quiet, force);
+                                                      readonly, runstop, update, homehost, verbose-quiet, force);
                                        close(mdfd);
                                }
                        }
                } else if (!scan)
                        rv = Assemble(ss, devlist->devname, mdfd, &ident, configfile,
                                      devlist->next, backup_file,
-                                     readonly, runstop, update, verbose-quiet, force);
+                                     readonly, runstop, update, homehost, verbose-quiet, force);
                else if (devs_found>0) {
                        if (update && devs_found > 1) {
                                fprintf(stderr, Name ": can only update a single array at a time\n");
@@ -972,7 +972,7 @@ int main(int argc, char *argv[])
                                }
                                rv |= Assemble(ss, dv->devname, mdfd, array_ident, configfile,
                                               NULL, backup_file,
-                                              readonly, runstop, update, verbose-quiet, force);
+                                              readonly, runstop, update, homehost, verbose-quiet, force);
                                close(mdfd);
                        }
                } else {
@@ -1004,7 +1004,7 @@ int main(int argc, char *argv[])
                                                rv |= Assemble(ss, array_list->devname, mdfd,
                                                               array_list, configfile,
                                                               NULL, NULL,
-                                                              readonly, runstop, NULL, verbose-quiet, force);
+                                                              readonly, runstop, NULL, homehost, verbose-quiet, force);
                                        close(mdfd);
                                }
                }
diff --git a/mdadm.h b/mdadm.h
index 25c8b8f4ac06c7dae3d2c0949e15cf98f3007aa8..ecaacd4df6fdc28036825da11cdfff90528a4f6a 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -278,7 +278,9 @@ extern struct superswitch {
        void (*brief_detail_super)(void *sbv);
        void (*uuid_from_super)(int uuid[4], void *sbv);
        void (*getinfo_super)(struct mdinfo *info, void *sbv);
-       int (*update_super)(struct mdinfo *info, void *sbv, char *update, char *devname, int verbose);
+       int (*update_super)(struct mdinfo *info, void *sbv, char *update,
+                           char *devname, int verbose,
+                           int uuid_set, char *homehost);
        __u64 (*event_super)(void *sbv);
        int (*init_super)(struct supertype *st, void **sbp, mdu_array_info_t *info, unsigned long long size, char *name, char *homehost);
        void (*add_to_super)(void *sbv, mdu_disk_info_t *dinfo);
@@ -342,7 +344,7 @@ extern int Assemble(struct supertype *st, char *mddev, int mdfd,
                    char *conffile,
                    mddev_dev_t devlist, char *backup_file,
                    int readonly, int runstop,
-                   char *update,
+                   char *update, char *homehost,
                    int verbose, int force);
 
 extern int Build(char *mddev, int mdfd, int chunk, int level, int layout,
index dbf59c8457819ec3bdc5ac74bcca110a06ba1342..d21032f3a4265760051bafa3bce764ad990e0abb 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -334,7 +334,9 @@ static void getinfo_super0(struct mdinfo *info, void *sbv)
 }
 
 
-static int update_super0(struct mdinfo *info, void *sbv, char *update, char *devname, int verbose)
+static int update_super0(struct mdinfo *info, void *sbv, char *update,
+                        char *devname, int verbose,
+                        int uuid_set, char *homehost)
 {
        /* NOTE: for 'assemble' and 'force' we need to return non-zero if any change was made.
         * For others, the return value is ignored.
@@ -441,6 +443,12 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, char *dev
                sb->recovery_cp = 0;
        }
        if (strcmp(update, "uuid") == 0) {
+               if (!uuid_set && homehost) {
+                       unsigned char *hash = SHA1((unsigned char*)homehost,
+                                                  strlen(homehost),
+                                                  NULL);
+                       memcpy(info->uuid+2, hash, 8);
+               }
                sb->set_uuid0 = info->uuid[0];
                sb->set_uuid1 = info->uuid[1];
                sb->set_uuid2 = info->uuid[2];
index b1ea298fb7f120405b0c5e0aeb8d65cab0f0e94a..533929a303f486654b8ad735f14a119058755166 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -434,7 +434,9 @@ static void getinfo_super1(struct mdinfo *info, void *sbv)
        info->array.working_disks = working;
 }
 
-static int update_super1(struct mdinfo *info, void *sbv, char *update, char *devname, int verbose)
+static int update_super1(struct mdinfo *info, void *sbv, char *update,
+                        char *devname, int verbose,
+                        int uuid_set, char *homehost)
 {
        /* NOTE: for 'assemble' and 'force' we need to return non-zero if any change was made.
         * For others, the return value is ignored.