]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
FIX: resolve make everything compilation error
[thirdparty/mdadm.git] / super0.c
index 62c4ff0c518cd0296dcbad798ab59c9f681ca980..137579986b176abf827d682b5bf83c79a9eff361 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -114,7 +114,7 @@ static void examine_super0(struct supertype *st, char *homehost)
        c=map_num(pers, sb->level);
        printf("     Raid Level : %s\n", c?c:"-unknown-");
        if ((int)sb->level > 0) {
-               int ddsks=0;
+               int ddsks = 0, ddsks_denom = 1;
                printf("  Used Dev Size : %d%s\n", sb->size,
                       human_size((long long)sb->size<<10));
                switch(sb->level) {
@@ -122,11 +122,15 @@ static void examine_super0(struct supertype *st, char *homehost)
                case 4:
                case 5: ddsks = sb->raid_disks-1; break;
                case 6: ddsks = sb->raid_disks-2; break;
-               case 10: ddsks = sb->raid_disks / (sb->layout&255) / ((sb->layout>>8)&255);
+               case 10: ddsks = sb->raid_disks;
+                       ddsks_denom =  (sb->layout&255) * ((sb->layout>>8)&255);
+               }
+               if (ddsks) {
+                       long long asize = sb->size;
+                       asize = (asize << 10) * ddsks / ddsks_denom;
+                       printf("     Array Size : %llu%s\n",
+                              asize >> 10,  human_size(asize));
                }
-               if (ddsks)
-                       printf("     Array Size : %llu%s\n", (unsigned long long)ddsks * sb->size,
-                              human_size(ddsks*(long long)sb->size<<10));
        }
        printf("   Raid Devices : %d\n", sb->raid_disks);
        printf("  Total Devices : %d\n", sb->nr_disks);
@@ -360,6 +364,9 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info, char *map)
        info->array.state = sb->state;
        info->component_size = sb->size*2;
 
+       if (sb->state & (1<<MD_SB_BITMAP_PRESENT))
+               info->bitmap_offset = 8;
+
        info->disk.state = sb->this_disk.state;
        info->disk.major = sb->this_disk.major;
        info->disk.minor = sb->this_disk.minor;
@@ -387,6 +394,8 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info, char *map)
        } else
                info->reshape_active = 0;
 
+       info->recovery_blocked = info->reshape_active;
+
        sprintf(info->name, "%d", sb->md_minor);
        /* work_disks is calculated rather than read directly */
        for (i=0; i < MD_SB_DISKS; i++)
@@ -570,6 +579,10 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                sb->state &= ~(1<<MD_SB_BITMAP_PRESENT);
        } else if (strcmp(update, "_reshape_progress")==0)
                sb->reshape_position = info->reshape_progress;
+       else if (strcmp(update, "writemostly")==0)
+               sb->state |= (1<<MD_DISK_WRITEMOSTLY);
+       else if (strcmp(update, "readwrite")==0)
+               sb->state &= ~(1<<MD_DISK_WRITEMOSTLY);
        else
                rv = -1;
 
@@ -688,6 +701,8 @@ static int add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
        dk->minor = dinfo->minor;
        dk->raid_disk = dinfo->raid_disk;
        dk->state = dinfo->state;
+       /* In case our source disk was writemostly, don't copy that bit */
+       dk->state &= ~(1<<MD_DISK_WRITEMOSTLY);
 
        sb->this_disk = sb->disks[dinfo->number];
        sb->sb_csum = calc_sb0_csum(sb);
@@ -931,10 +946,10 @@ static int load_super0(struct supertype *st, int fd, char *devname)
 
 static struct supertype *match_metadata_desc0(char *arg)
 {
-       struct supertype *st = malloc(sizeof(*st));
-       if (!st) return st;
+       struct supertype *st = calloc(1, sizeof(*st));
+       if (!st)
+               return st;
 
-       memset(st, 0, sizeof(*st));
        st->container_dev = NoMdDev;
        st->ss = &super0;
        st->info = NULL;
@@ -1054,13 +1069,11 @@ static int write_bitmap0(struct supertype *st, int fd)
        int rv = 0;
 
        int towrite, n;
-       char abuf[4096+4096];
-       char *buf = (char*)(((long)(abuf+4096))&~4095L);
+       void *buf;
 
        if (!get_dev_size(fd, NULL, &dsize))
                return 1;
 
-
        if (dsize < MD_RESERVED_SECTORS*512)
                return -1;
 
@@ -1071,6 +1084,9 @@ static int write_bitmap0(struct supertype *st, int fd)
        if (lseek64(fd, offset + 4096, 0)< 0LL)
                return 3;
 
+       if (posix_memalign(&buf, 4096, 4096))
+               return -ENOMEM;
+
        memset(buf, 0xff, 4096);
        memcpy(buf,  ((char*)sb)+MD_SB_BYTES, sizeof(bitmap_super_t));
        towrite = 60*1024;
@@ -1089,6 +1105,7 @@ static int write_bitmap0(struct supertype *st, int fd)
        if (towrite)
                rv = -2;
 
+       free(buf);
        return rv;
 }
 
@@ -1134,7 +1151,7 @@ static int validate_geometry0(struct supertype *st, int level,
                                MD_SB_DISKS);
                return 0;
        }
-       if (size >= tbmax * 1024*1024*1024*2ULL) {
+       if (size >= tbmax * 2ULL*1024*1024*1024) {
                if (verbose)
                        fprintf(stderr, Name ": 0.90 metadata supports at most "
                                "%d terabytes per device\n", tbmax);