]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super1.c
restore_backup() throws core dump
[thirdparty/mdadm.git] / super1.c
index 79bb4d0cdcaf10c2dd95840e283e4f06eb7983af..0cd412400a2fd49824c0ac12cdca15e5759466ac 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -111,7 +111,6 @@ static unsigned int calc_sb_1_csum(struct mdp_superblock_1 * sb)
        unsigned long long newcsum;
        int size = sizeof(*sb) + __le32_to_cpu(sb->max_dev)*2;
        unsigned int *isuper = (unsigned int*)sb;
-       int i;
 
 /* make sure I can count... */
        if (offsetof(struct mdp_superblock_1,data_offset) != 128 ||
@@ -123,7 +122,7 @@ static unsigned int calc_sb_1_csum(struct mdp_superblock_1 * sb)
        disk_csum = sb->sb_csum;
        sb->sb_csum = 0;
        newcsum = 0;
-       for (i=0; size>=4; size -= 4 ) {
+       for (; size>=4; size -= 4 ) {
                newcsum += __le32_to_cpu(*isuper);
                isuper++;
        }
@@ -314,7 +313,7 @@ static void examine_super1(struct supertype *st, char *homehost)
                printf("\n");
        }
        if (sb->devflags) {
-               printf("      Flags :");
+               printf("          Flags :");
                if (sb->devflags & WriteMostly1)
                        printf(" write-mostly");
                printf("\n");
@@ -387,15 +386,11 @@ static void examine_super1(struct supertype *st, char *homehost)
        printf("   Array State : ");
        for (d=0; d<__le32_to_cpu(sb->raid_disks) + delta_extra; d++) {
                int cnt = 0;
-               int me = 0;
                unsigned int i;
                for (i=0; i< __le32_to_cpu(sb->max_dev); i++) {
                        unsigned int role = __le16_to_cpu(sb->dev_roles[i]);
-                       if (role == d) {
-                               if (i == __le32_to_cpu(sb->dev_number))
-                                       me = 1;
+                       if (role == d)
                                cnt++;
-                       }
                }
                if (cnt > 1) printf("?");
                else if (cnt == 1) printf("A");
@@ -566,6 +561,7 @@ static void getinfo_super1(struct supertype *st, struct mdinfo *info, char *map)
        unsigned int role;
        unsigned int map_disks = info->array.raid_disks;
 
+       memset(info, 0, sizeof(*info));
        info->array.major_version = 1;
        info->array.minor_version = st->minor_version;
        info->array.patch_version = 0;
@@ -772,7 +768,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
        } else if (strcmp(update, "no-bitmap") == 0) {
                sb->feature_map &= ~__cpu_to_le32(MD_FEATURE_BITMAP_OFFSET);
        } else if (strcmp(update, "homehost") == 0 &&
-           homehost) {
+                  homehost) {
                char *c;
                update = "name";
                c = strchr(sb->set_name, ':');
@@ -807,6 +803,10 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                       __le64_to_cpu(sb->data_size));
        } else if (strcmp(update, "_reshape_progress")==0)
                sb->reshape_position = __cpu_to_le64(info->reshape_progress);
+       else if (strcmp(update, "writemostly")==0)
+               sb->devflags |= WriteMostly1;
+       else if (strcmp(update, "readwrite")==0)
+               sb->devflags &= ~WriteMostly1;
        else
                rv = -1;
 
@@ -927,6 +927,7 @@ static int add_to_super1(struct supertype *st, mdu_disk_info_t *dk,
                sb->max_dev = __cpu_to_le32(dk->number+1);
 
        sb->dev_number = __cpu_to_le32(dk->number);
+       sb->devflags = 0; /* don't copy another disks flags */
        sb->sb_csum = calc_sb_1_csum(sb);
 
        dip = (struct devinfo **)&st->info;
@@ -1060,6 +1061,8 @@ static int write_init_super1(struct supertype *st)
                sb->dev_number = __cpu_to_le32(di->disk.number);
                if (di->disk.state & (1<<MD_DISK_WRITEMOSTLY))
                        sb->devflags |= __cpu_to_le32(WriteMostly1);
+               else
+                       sb->devflags &= ~(__cpu_to_le32(WriteMostly1));
 
                if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
                    read(rfd, sb->device_uuid, 16) != 16) {
@@ -1497,6 +1500,7 @@ add_internal_bitmap1(struct supertype *st,
        int room = 0;
        struct mdp_superblock_1 *sb = st->sb;
        bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + 1024);
+       int uuid[4];
 
        switch(st->minor_version) {
        case 0:
@@ -1584,7 +1588,8 @@ add_internal_bitmap1(struct supertype *st,
        memset(bms, 0, sizeof(*bms));
        bms->magic = __cpu_to_le32(BITMAP_MAGIC);
        bms->version = __cpu_to_le32(major);
-       uuid_from_super1(st, (int*)bms->uuid);
+       uuid_from_super1(st, uuid);
+       memcpy(bms->uuid, uuid, 16);
        bms->chunksize = __cpu_to_le32(chunk);
        bms->daemon_sleep = __cpu_to_le32(delay);
        bms->sync_size = __cpu_to_le64(size);