]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super1.c
imsm: fix reserved sectors for spares
[thirdparty/mdadm.git] / super1.c
index be0591677c2f6f2fed705af679dd9a9738597665..35e92a3145578ed3e0277da6254a4a4ce238f735 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;
@@ -698,6 +694,20 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                        sb->dev_roles[d] = __cpu_to_le16(want);
                        rv = 1;
                }
+               if (info->reshape_active &&
+                   sb->feature_map & __le32_to_cpu(MD_FEATURE_RESHAPE_ACTIVE) &&
+                   info->delta_disks >= 0 &&
+                   info->reshape_progress < __le64_to_cpu(sb->reshape_position)) {
+                       sb->reshape_position = __cpu_to_le64(info->reshape_progress);
+                       rv = 1;
+               }
+               if (info->reshape_active &&
+                   sb->feature_map & __le32_to_cpu(MD_FEATURE_RESHAPE_ACTIVE) &&
+                   info->delta_disks < 0 &&
+                   info->reshape_progress > __le64_to_cpu(sb->reshape_position)) {
+                       sb->reshape_position = __cpu_to_le64(info->reshape_progress);
+                       rv = 1;
+               }
        } else if (strcmp(update, "linear-grow-new") == 0) {
                unsigned int i;
                int rfd, fd;
@@ -758,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, ':');
@@ -1046,6 +1056,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) {
@@ -1483,6 +1495,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:
@@ -1570,7 +1583,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);
@@ -1666,12 +1680,12 @@ static int validate_geometry1(struct supertype *st, int level,
                        fprintf(stderr, Name ": 1.x metadata does not support containers\n");
                return 0;
        }
+       if (chunk && *chunk == UnSet)
+               *chunk = DEFAULT_CHUNK;
+
        if (!subdev)
                return 1;
 
-       if (chunk && (*chunk == 0 || *chunk == UnSet))
-               *chunk = DEFAULT_CHUNK;
-
        fd = open(subdev, O_RDONLY|O_EXCL, 0);
        if (fd < 0) {
                if (verbose)