]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
Support bitmaps with raid10
[thirdparty/mdadm.git] / super0.c
index e33643905624033cbd93d1d7ca753ae1f1974414..6b8c2081799db396dbb3e477cc87572f676e0aff 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -131,6 +131,10 @@ static void examine_super0(void *sbv)
                c = map_num(r5layout, sb->layout);
                printf("         Layout : %s\n", c?c:"-unknown-");
        }
+       if (sb->level == 10) {
+               printf("         Layout : near=%d, far=%d\n",
+                      sb->layout&255, (sb->layout>>8)&255);
+       }
        switch(sb->level) {
        case 0:
        case 4:
@@ -223,7 +227,7 @@ static void uuid_from_super0(int uuid[4], void * sbv)
        }
 }
 
-static void getinfo_super0(struct mdinfo *info, void *sbv)
+static void getinfo_super0(struct mdinfo *info, mddev_ident_t ident, void *sbv)
 {
        mdp_super_t *sb = sbv;
        int working = 0;
@@ -234,6 +238,7 @@ static void getinfo_super0(struct mdinfo *info, void *sbv)
        info->array.patch_version = sb->patch_version;
        info->array.raid_disks = sb->raid_disks;
        info->array.level = sb->level;
+       info->array.layout = sb->layout;
        info->array.md_minor = sb->md_minor;
        info->array.ctime = sb->ctime;
 
@@ -246,7 +251,8 @@ static void getinfo_super0(struct mdinfo *info, void *sbv)
        info->events = md_event(sb);
 
        uuid_from_super0(info->uuid, sbv);
-       
+
+       ident->name[0] = 0;
        /* work_disks is calculated rather than read directly */
        for (i=0; i < MD_SB_DISKS; i++)
                if ((sb->disks[i].state & (1<<MD_DISK_SYNC)) &&
@@ -270,12 +276,13 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, char *dev
                memcpy(sb32+MD_SB_GENERIC_CONSTANT_WORDS+7,
                       sb32+MD_SB_GENERIC_CONSTANT_WORDS+7+1,
                       (MD_SB_WORDS - (MD_SB_GENERIC_CONSTANT_WORDS+7+1))*4);
-               fprintf (stderr, Name ": adjusting superblock of %s for 2.2/sparc compatability.\n",
-                        devname);
+               if (verbose >= 0)
+                       fprintf (stderr, Name ": adjusting superblock of %s for 2.2/sparc compatability.\n",
+                                devname);
        }
        if (strcmp(update, "super-minor") ==0) {
                sb->md_minor = info->array.md_minor;
-               if (verbose)
+               if (verbose > 0)
                        fprintf(stderr, Name ": updating superblock of %s with minor number %d\n",
                                devname, info->array.md_minor);
        }
@@ -365,7 +372,7 @@ static __u64 event_super0(void *sbv)
 
 
 
-static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info)
+static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info, char *ignored_name)
 {
        mdp_super_t *sb = malloc(MD_SB_BYTES + sizeof(bitmap_super_t));
        int spares;
@@ -488,27 +495,8 @@ static int write_init_super0(struct supertype *st, void *sbv, mdu_disk_info_t *d
        sb->sb_csum = calc_sb0_csum(sb);
        rv = store_super0(st, fd, sb);
 
-       if (sb->state & (1<<MD_SB_BITMAP_PRESENT)) {
-               int towrite, n;
-               char buf[4096];
-
-               write(fd, ((char*)sb)+MD_SB_BYTES, sizeof(bitmap_super_t));
-               towrite = 64*1024 - MD_SB_BYTES - sizeof(bitmap_super_t);
-               memset(buf, 0xff, sizeof(buf));
-               while (towrite > 0) {
-                       n = towrite;
-                       if (n > sizeof(buf)) 
-                               n = sizeof(buf);
-                       n = write(fd, buf, n);
-                       if (n > 0)
-                               towrite -= n;
-                       else
-                               break;
-               }
-               fsync(fd);
-               if (towrite)
-                       rv = -2;
-       }
+       if (rv == 0 && (sb->state & (1<<MD_SB_BITMAP_PRESENT)))
+               rv = st->ss->write_bitmap(st, fd, sbv);
 
        close(fd);
        if (rv)
@@ -662,14 +650,14 @@ static struct supertype *match_metadata_desc0(char *arg)
        return NULL;
 }
 
-static __u64 avail_size0(__u64 devsize)
+static __u64 avail_size0(struct supertype *st, __u64 devsize)
 {
        if (devsize < MD_RESERVED_SECTORS*2)
                return 0ULL;
        return MD_NEW_SIZE_SECTORS(devsize);
 }
 
-static int add_internal_bitmap0(void *sbv, int chunk, int delay, int write_behind, unsigned long long size)
+static int add_internal_bitmap0(struct supertype *st, void *sbv, int chunk, int delay, int write_behind, unsigned long long size, int may_change, int major)
 {
        /*
         * The bitmap comes immediately after the superblock and must be 60K in size
@@ -677,8 +665,7 @@ static int add_internal_bitmap0(void *sbv, int chunk, int delay, int write_behin
         *
         * size is in K,  chunk is in bytes !!!
         */
-
-       unsigned long long bits = size;
+       unsigned long long bits;
        unsigned long long max_bits = 60*1024*8;
        unsigned long long min_chunk;
        mdp_super_t *sb = sbv;
@@ -686,6 +673,7 @@ static int add_internal_bitmap0(void *sbv, int chunk, int delay, int write_behin
 
        
        min_chunk = 4096; /* sub-page chunks don't work yet.. */
+       bits = (size * 512)/ min_chunk +1;
        while (bits > max_bits) {
                min_chunk *= 2;
                bits = (bits+1)/2;
@@ -699,7 +687,7 @@ static int add_internal_bitmap0(void *sbv, int chunk, int delay, int write_behin
 
        memset(bms, sizeof(*bms), 0);
        bms->magic = __cpu_to_le32(BITMAP_MAGIC);
-       bms->version = __cpu_to_le32(BITMAP_MAJOR);
+       bms->version = __cpu_to_le32(major);
        uuid_from_super0((int*)bms->uuid, sb);
        bms->chunksize = __cpu_to_le32(chunk);
        bms->daemon_sleep = __cpu_to_le32(delay);
@@ -712,7 +700,7 @@ static int add_internal_bitmap0(void *sbv, int chunk, int delay, int write_behin
 }
                
 
-void locate_bitmap0(struct supertype *st, int fd)
+void locate_bitmap0(struct supertype *st, int fd, void *sbv)
 {
        unsigned long long dsize;
        unsigned long size;