]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super1.c
util: make env checking more generic
[thirdparty/mdadm.git] / super1.c
index b7cd962a7e375de6c0c7667749ccf60acaffc88e..4cfd786009a6c9a8b24c944d0fea9f44f04b3321 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -248,10 +248,9 @@ static void examine_super1(struct supertype *st, char *homehost)
                                printf("     New Layout : %s\n", c?c:"-unknown-");
                        }
                        if (__le32_to_cpu(sb->level) == 10) {
-                               printf("     New Layout : near=%d, %s=%d\n",
-                                      __le32_to_cpu(sb->new_layout)&255,
-                                      (__le32_to_cpu(sb->new_layout)&0x10000)?"offset":"far",
-                                      (__le32_to_cpu(sb->new_layout)>>8)&255);
+                               printf("     New Layout :");
+                               print_r10_layout(__le32_to_cpu(sb->new_layout));
+                               printf("\n");
                        }
                }
                if (__le32_to_cpu(sb->new_chunk) != __le32_to_cpu(sb->chunksize))
@@ -281,10 +280,9 @@ static void examine_super1(struct supertype *st, char *homehost)
        }
        if (__le32_to_cpu(sb->level) == 10) {
                int lo = __le32_to_cpu(sb->layout);
-               printf("         Layout : near=%d, %s=%d\n",
-                      lo&255,
-                      (lo&0x10000)?"offset":"far",
-                      (lo>>8)&255);
+               printf("         Layout :");
+               print_r10_layout(lo);
+               printf("\n");
        }
        switch(__le32_to_cpu(sb->level)) {
        case 0:
@@ -597,7 +595,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
        }
        if (strcmp(update, "linear-grow-new") == 0) {
                int i;
-               int rfd;
+               int rfd, fd;
                int max = __le32_to_cpu(sb->max_dev);
 
                for (i=0 ; i < max ; i++)
@@ -618,6 +616,25 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
 
                sb->dev_roles[i] =
                        __cpu_to_le16(info->disk.raid_disk);
+
+               fd = open(devname, O_RDONLY);
+               if (fd >= 0) {
+                       unsigned long long ds;
+                       get_dev_size(fd, devname, &ds);
+                       close(fd);
+                       ds >>= 9;
+                       if (__le64_to_cpu(sb->super_offset) <
+                           __le64_to_cpu(sb->data_offset)) {
+                               sb->data_size = __cpu_to_le64(
+                                       ds - __le64_to_cpu(sb->data_offset));
+                       } else {
+                               ds -= 8*2;
+                               ds &= ~(unsigned long long)(4*2-1);
+                               sb->super_offset = __cpu_to_le64(ds);
+                               sb->data_size = __cpu_to_le64(
+                                       ds - __le64_to_cpu(sb->data_offset));
+                       }
+               }
        }
        if (strcmp(update, "linear-grow-update") == 0) {
                sb->raid_disks = __cpu_to_le32(info->array.raid_disks);
@@ -689,8 +706,12 @@ static int init_super1(struct supertype *st, mdu_array_info_t *info,
        int rfd;
        char defname[10];
 
-       posix_memalign((void**)&sb, 512, (1024 + 512 + 
-                                         sizeof(struct misc_dev_info)));
+       if (posix_memalign((void**)&sb, 512, (1024 + 512 + 
+                          sizeof(struct misc_dev_info))) != 0) {
+               fprintf(stderr, Name
+                       ": %s could not allocate superblock\n", __func__);
+               return 0;
+       }
        memset(sb, 0, 1024);
 
        st->sb = sb;
@@ -1036,9 +1057,13 @@ static int compare_super1(struct supertype *st, struct supertype *tst)
                return 1;
 
        if (!first) {
-               posix_memalign((void**)&first, 512,
+               if (posix_memalign((void**)&first, 512,
                               1024 + 512 +
-                              sizeof(struct misc_dev_info));
+                              sizeof(struct misc_dev_info)) != 0) {
+                       fprintf(stderr, Name
+                               ": %s could not allocate superblock\n", __func__);
+                       return 1;
+               }
                memcpy(first, second, 1024 + 512 + 
                       sizeof(struct misc_dev_info));
                st->sb = first;
@@ -1152,9 +1177,13 @@ static int load_super1(struct supertype *st, int fd, char *devname)
                return 1;
        }
 
-       posix_memalign((void**)&super, 512,
+       if (posix_memalign((void**)&super, 512,
                       1024 + 512 +
-                      sizeof(struct misc_dev_info));
+                      sizeof(struct misc_dev_info)) != 0) {
+               fprintf(stderr, Name ": %s could not allocate superblock\n",
+                       __func__);
+               return 1;
+       }
 
        if (read(fd, super, 1024) != 1024) {
                if (devname)
@@ -1260,10 +1289,21 @@ static struct supertype *match_metadata_desc1(char *arg)
  */
 static __u64 avail_size1(struct supertype *st, __u64 devsize)
 {
+       struct mdp_superblock_1 *super = st->sb;
        if (devsize < 24)
                return 0;
 
-       devsize -= choose_bm_space(devsize);
+       if (super == NULL)
+               /* creating:  allow suitable space for bitmap */
+               devsize -= choose_bm_space(devsize);
+#ifndef MDASSEMBLE
+       else if (__le32_to_cpu(super->feature_map)&MD_FEATURE_BITMAP_OFFSET) {
+               /* hot-add. allow for actual size of bitmap */
+               struct bitmap_super_s *bsb;
+               bsb = (struct bitmap_super_s *)(((char*)super)+1024);
+               devsize -= bitmap_sectors(bsb);
+       }
+#endif
 
        switch(st->minor_version) {
        case -1: /* no specified.  Now time to set default */