]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
mdadm: improve the dlm locking mechanism for clustered raid
[thirdparty/mdadm.git] / super0.c
index 1f4dc750722bafb7313fb6bf47890e270a2ce1de..756cab5e9d009347090677dce6b72bad1ce7ece0 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -36,7 +36,6 @@
  * .. other stuff
  */
 
-
 static unsigned long calc_sb0_csum(mdp_super_t *super)
 {
        unsigned long csum = super->sb_csum;
@@ -47,7 +46,6 @@ static unsigned long calc_sb0_csum(mdp_super_t *super)
        return newcsum;
 }
 
-
 static void super0_swap_endian(struct mdp_superblock_s *sb)
 {
        /* as super0 superblocks are host-endian, it is sometimes
@@ -78,8 +76,6 @@ static void super0_swap_endian(struct mdp_superblock_s *sb)
 
 }
 
-#ifndef MDASSEMBLE
-
 static void examine_super0(struct supertype *st, char *homehost)
 {
        mdp_super_t *sb = st->sb;
@@ -89,17 +85,17 @@ static void examine_super0(struct supertype *st, char *homehost)
        char *c;
 
        printf("          Magic : %08x\n", sb->md_magic);
-       printf("        Version : %d.%02d.%02d\n", sb->major_version, sb->minor_version,
-              sb->patch_version);
+       printf("        Version : %d.%02d.%02d\n",
+              sb->major_version, sb->minor_version, sb->patch_version);
        if (sb->minor_version >= 90) {
-               printf("           UUID : %08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
-                      sb->set_uuid2, sb->set_uuid3);
+               printf("           UUID : %08x:%08x:%08x:%08x", sb->set_uuid0,
+                      sb->set_uuid1, sb->set_uuid2, sb->set_uuid3);
                if (homehost) {
                        char buf[20];
-                       void *hash = sha1_buffer(homehost,
-                                                strlen(homehost),
-                                                buf);
-                       if (memcmp(&sb->set_uuid2, hash, 8)==0)
+                       void *hash;
+
+                       hash = sha1_buffer(homehost, strlen(homehost), buf);
+                       if (memcmp(&sb->set_uuid2, hash, 8) == 0)
                                printf(" (local to host %s)", homehost);
                }
                printf("\n");
@@ -111,19 +107,27 @@ static void examine_super0(struct supertype *st, char *homehost)
 
        atime = sb->ctime;
        printf("  Creation Time : %.24s\n", ctime(&atime));
-       c=map_num(pers, sb->level);
+       c = map_num(pers, sb->level);
        printf("     Raid Level : %s\n", c?c:"-unknown-");
        if ((int)sb->level > 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) {
-               case 1: ddsks=1;break;
+               case 1:
+                       ddsks=1;
+                       break;
                case 4:
-               case 5: ddsks = sb->raid_disks-1; break;
-               case 6: ddsks = sb->raid_disks-2; break;
-               case 10: ddsks = sb->raid_disks;
-                       ddsks_denom =  (sb->layout&255) * ((sb->layout>>8)&255);
+               case 5:
+                       ddsks = sb->raid_disks - 1;
+                       break;
+               case 6:
+                       ddsks = sb->raid_disks - 2;
+                       break;
+               case 10:
+                       ddsks = sb->raid_disks;
+                       ddsks_denom =
+                               (sb->layout & 255) * ((sb->layout >> 8) & 255);
                }
                if (ddsks) {
                        long long asize = sb->size;
@@ -136,11 +140,14 @@ static void examine_super0(struct supertype *st, char *homehost)
        printf("  Total Devices : %d\n", sb->nr_disks);
        printf("Preferred Minor : %d\n", sb->md_minor);
        printf("\n");
-       if (sb->minor_version > 90 && (sb->reshape_position+1) != 0) {
-               printf("  Reshape pos'n : %llu%s\n", (unsigned long long)sb->reshape_position/2, human_size((long long)sb->reshape_position<<9));
+       if (sb->minor_version > 90 && (sb->reshape_position + 1) != 0) {
+               printf("  Reshape pos'n : %llu%s\n",
+                      (unsigned long long)sb->reshape_position / 2,
+                      human_size((long long)sb->reshape_position << 9));
                if (sb->delta_disks) {
                        printf("  Delta Devices : %d", sb->delta_disks);
-                       printf(" (%d->%d)\n", sb->raid_disks-sb->delta_disks, sb->raid_disks);
+                       printf(" (%d->%d)\n", sb->raid_disks-sb->delta_disks,
+                              sb->raid_disks);
                        if (((int)sb->delta_disks) < 0)
                                delta_extra = - sb->delta_disks;
                }
@@ -151,11 +158,13 @@ static void examine_super0(struct supertype *st, char *homehost)
                if (sb->new_layout != sb->layout) {
                        if (sb->level == 5) {
                                c = map_num(r5layout, sb->new_layout);
-                               printf("     New Layout : %s\n", c?c:"-unknown-");
+                               printf("     New Layout : %s\n",
+                                      c?c:"-unknown-");
                        }
                        if (sb->level == 6) {
                                c = map_num(r6layout, sb->new_layout);
-                               printf("     New Layout : %s\n", c?c:"-unknown-");
+                               printf("     New Layout : %s\n",
+                                      c?c:"-unknown-");
                        }
                        if (sb->level == 10) {
                                printf("     New Layout : near=%d, %s=%d\n",
@@ -171,8 +180,8 @@ static void examine_super0(struct supertype *st, char *homehost)
        atime = sb->utime;
        printf("    Update Time : %.24s\n", ctime(&atime));
        printf("          State : %s\n",
-              (sb->state&(1<<MD_SB_CLEAN))?"clean":"active");
-       if (sb->state & (1<<MD_SB_BITMAP_PRESENT))
+              (sb->state&(1 << MD_SB_CLEAN)) ? "clean":"active");
+       if (sb->state & (1 << MD_SB_BITMAP_PRESENT))
                printf("Internal Bitmap : present\n");
        printf(" Active Devices : %d\n", sb->active_disks);
        printf("Working Devices : %d\n", sb->working_disks);
@@ -181,10 +190,10 @@ static void examine_super0(struct supertype *st, char *homehost)
        if (calc_sb0_csum(sb) == sb->sb_csum)
                printf("       Checksum : %x - correct\n", sb->sb_csum);
        else
-               printf("       Checksum : %x - expected %lx\n", sb->sb_csum, calc_sb0_csum(sb));
+               printf("       Checksum : %x - expected %lx\n",
+                      sb->sb_csum, calc_sb0_csum(sb));
        printf("         Events : %llu\n",
-              ((unsigned long long)sb->events_hi << 32)
-              + sb->events_lo);
+              ((unsigned long long)sb->events_hi << 32) + sb->events_lo);
        printf("\n");
        if (sb->level == 5) {
                c = map_num(r5layout, sb->layout);
@@ -205,37 +214,50 @@ static void examine_super0(struct supertype *st, char *homehost)
        case 5:
        case 6:
        case 10:
-               printf("     Chunk Size : %dK\n", sb->chunk_size/1024);
+               printf("     Chunk Size : %dK\n", sb->chunk_size / 1024);
                break;
        case -1:
-               printf("       Rounding : %dK\n", sb->chunk_size/1024);
+               printf("       Rounding : %dK\n", sb->chunk_size / 1024);
+               break;
+       default:
                break;
-       default: break;
        }
        printf("\n");
        printf("      Number   Major   Minor   RaidDevice State\n");
-       for (d= -1; d<(signed int)(sb->raid_disks+delta_extra + sb->spare_disks); d++) {
+       for (d = -1;
+            d < (signed int)(sb->raid_disks + delta_extra + sb->spare_disks);
+            d++) {
                mdp_disk_t *dp;
                char *dv;
-               char nb[5];
-               int wonly;
+               char nb[11];
+               int wonly, failfast;
                if (d>=0) dp = &sb->disks[d];
                else dp = &sb->this_disk;
                snprintf(nb, sizeof(nb), "%4d", d);
-               printf("%4s %5d   %5d    %5d    %5d     ", d < 0 ? "this" :  nb,
+               printf("%4s %5d   %5d    %5d    %5d     ", d < 0 ? "this" : nb,
                       dp->number, dp->major, dp->minor, dp->raid_disk);
-               wonly = dp->state & (1<<MD_DISK_WRITEMOSTLY);
-               dp->state &= ~(1<<MD_DISK_WRITEMOSTLY);
-               if (dp->state & (1<<MD_DISK_FAULTY)) printf(" faulty");
-               if (dp->state & (1<<MD_DISK_ACTIVE)) printf(" active");
-               if (dp->state & (1<<MD_DISK_SYNC)) printf(" sync");
-               if (dp->state & (1<<MD_DISK_REMOVED)) printf(" removed");
-               if (wonly) printf(" write-mostly");
-               if (dp->state == 0) printf(" spare");
-               if ((dv=map_dev(dp->major, dp->minor, 0)))
+               wonly = dp->state & (1 << MD_DISK_WRITEMOSTLY);
+               failfast = dp->state & (1<<MD_DISK_FAILFAST);
+               dp->state &= ~(wonly | failfast);
+               if (dp->state & (1 << MD_DISK_FAULTY))
+                       printf(" faulty");
+               if (dp->state & (1 << MD_DISK_ACTIVE))
+                       printf(" active");
+               if (dp->state & (1 << MD_DISK_SYNC))
+                       printf(" sync");
+               if (dp->state & (1 << MD_DISK_REMOVED))
+                       printf(" removed");
+               if (wonly)
+                       printf(" write-mostly");
+               if (failfast)
+                       printf(" failfast");
+               if (dp->state == 0)
+                       printf(" spare");
+               if ((dv = map_dev(dp->major, dp->minor, 0)))
                        printf("   %s", dv);
                printf("\n");
-               if (d == -1) printf("\n");
+               if (d == -1)
+                       printf("\n");
        }
 }
 
@@ -281,10 +303,55 @@ static void export_examine_super0(struct supertype *st)
               + sb->events_lo);
 }
 
+static int copy_metadata0(struct supertype *st, int from, int to)
+{
+       /* Read 64K from the appropriate offset of 'from'
+        * and if it looks a little like a 0.90 superblock,
+        * write it to the same offset of 'to'
+        */
+       void *buf;
+       unsigned long long dsize, offset;
+       const int bufsize = 64*1024;
+       mdp_super_t *super;
+
+       if (posix_memalign(&buf, 4096, bufsize) != 0)
+               return 1;
+
+       if (!get_dev_size(from, NULL, &dsize))
+               goto err;
+
+       if (dsize < MD_RESERVED_SECTORS*512)
+               goto err;
+
+       offset = MD_NEW_SIZE_SECTORS(dsize>>9);
+
+       offset *= 512;
+
+       if (lseek64(from, offset, 0) < 0LL)
+               goto err;
+       if (read(from, buf, bufsize) != bufsize)
+               goto err;
+
+       if (lseek64(to, offset, 0) < 0LL)
+               goto err;
+       super = buf;
+       if (super->md_magic != MD_SB_MAGIC ||
+           super->major_version != 0 ||
+           calc_sb0_csum(super) != super->sb_csum)
+               goto err;
+       if (write(to, buf, bufsize) != bufsize)
+               goto err;
+       free(buf);
+       return 0;
+err:
+       free(buf);
+       return 1;
+}
+
 static void detail_super0(struct supertype *st, char *homehost)
 {
        mdp_super_t *sb = st->sb;
-       printf("           UUID : ");
+       printf("              UUID : ");
        if (sb->minor_version >= 90)
                printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
                       sb->set_uuid2, sb->set_uuid3);
@@ -298,7 +365,7 @@ static void detail_super0(struct supertype *st, char *homehost)
                if (memcmp(&sb->set_uuid2, hash, 8)==0)
                        printf(" (local to host %s)", homehost);
        }
-       printf("\n         Events : %d.%d\n\n", sb->events_hi, sb->events_lo);
+       printf("\n            Events : %d.%d\n\n", sb->events_hi, sb->events_lo);
 }
 
 static void brief_detail_super0(struct supertype *st)
@@ -311,7 +378,6 @@ static void brief_detail_super0(struct supertype *st)
        else
                printf("%08x", sb->set_uuid0);
 }
-#endif
 
 static int match_home0(struct supertype *st, char *homehost)
 {
@@ -362,7 +428,8 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info, char *map)
        info->array.utime = sb->utime;
        info->array.chunk_size = sb->chunk_size;
        info->array.state = sb->state;
-       info->component_size = sb->size*2;
+       info->component_size = sb->size;
+       info->component_size *= 2;
 
        if (sb->state & (1<<MD_SB_BITMAP_PRESENT))
                info->bitmap_offset = 8;
@@ -514,16 +581,17 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
        } else if (strcmp(update, "assemble")==0) {
                int d = info->disk.number;
                int wonly = sb->disks[d].state & (1<<MD_DISK_WRITEMOSTLY);
-               int mask = (1<<MD_DISK_WRITEMOSTLY);
+               int failfast = sb->disks[d].state & (1<<MD_DISK_FAILFAST);
+               int mask = (1<<MD_DISK_WRITEMOSTLY)|(1<<MD_DISK_FAILFAST);
                int add = 0;
                if (sb->minor_version >= 91)
                        /* During reshape we don't insist on everything
                         * being marked 'sync'
                         */
                        add = (1<<MD_DISK_SYNC);
-               if (((sb->disks[d].state & ~mask) | add)
-                   != (unsigned)info->disk.state) {
-                       sb->disks[d].state = info->disk.state | wonly;
+               if (((sb->disks[d].state & ~mask) | add) !=
+                   (unsigned)info->disk.state) {
+                       sb->disks[d].state = info->disk.state | wonly |failfast;
                        rv = 1;
                }
                if (info->reshape_active &&
@@ -581,6 +649,58 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                        uuid_from_super0(st, uuid);
                        memcpy(bm->uuid, uuid, 16);
                }
+       } else if (strcmp(update, "metadata") == 0) {
+               /* Create some v1.0 metadata to match ours but make the
+                * ctime bigger.  Also update info->array.*_version.
+                * We need to arrange that store_super writes out
+                * the v1.0 metadata.
+                * Not permitted for unclean array, or array with
+                * bitmap.
+                */
+               if (info->bitmap_offset) {
+                       pr_err("Cannot update metadata when bitmap is present\n");
+                       rv = -2;
+               } else if (info->array.state != 1) {
+                       pr_err("Cannot update metadata on unclean array\n");
+                       rv = -2;
+               } else {
+                       info->array.major_version = 1;
+                       info->array.minor_version = 0;
+                       uuid_from_super0(st, info->uuid);
+                       st->other = super1_make_v0(st, info, st->sb);
+               }
+       } else if (strcmp(update, "revert-reshape") == 0) {
+               rv = -2;
+               if (sb->minor_version <= 90)
+                       pr_err("No active reshape to revert on %s\n",
+                              devname);
+               else if (sb->delta_disks == 0)
+                       pr_err("%s: Can only revert reshape which changes number of devices\n",
+                              devname);
+               else {
+                       int tmp;
+                       int parity = sb->level == 6 ? 2 : 1;
+                       rv = 0;
+
+                       if (sb->level >= 4 && sb->level <= 6 &&
+                           sb->reshape_position % (
+                                   sb->new_chunk/512 *
+                                   (sb->raid_disks - sb->delta_disks - parity))) {
+                               pr_err("Reshape position is not suitably aligned.\n");
+                               pr_err("Try normal assembly and stop again\n");
+                               return -2;
+                       }
+                       sb->raid_disks -= sb->delta_disks;
+                       sb->delta_disks = -sb->delta_disks;
+
+                       tmp = sb->new_layout;
+                       sb->new_layout = sb->layout;
+                       sb->layout = tmp;
+
+                       tmp = sb->new_chunk;
+                       sb->new_chunk = sb->chunk_size;
+                       sb->chunk_size = tmp;
+               }
        } else if (strcmp(update, "no-bitmap") == 0) {
                sb->state &= ~(1<<MD_SB_BITMAP_PRESENT);
        } else if (strcmp(update, "_reshape_progress")==0)
@@ -597,29 +717,26 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
 }
 
 /*
- * For verion-0 superblock, the homehost is 'stored' in the
- * uuid.  8 bytes for a hash of the host leaving 8 bytes
- * of random material.
- * We use the first 8 bytes (64bits) of the sha1 of the
- * host name
+ * For version-0 superblock, the homehost is 'stored' in the uuid.
+ * 8 bytes for a hash of the host leaving 8 bytes of random material.
+ * We use the first 8 bytes (64bits) of the sha1 of the host name
  */
-
-
 static int init_super0(struct supertype *st, mdu_array_info_t *info,
-                      unsigned long long size, char *ignored_name, char *homehost,
-                      int *uuid, unsigned long long data_offset)
+                      struct shape *s, char *ignored_name,
+                      char *homehost, int *uuid,
+                      unsigned long long data_offset)
 {
        mdp_super_t *sb;
        int spares;
 
        if (data_offset != INVALID_SECTORS) {
-               fprintf(stderr, Name ": data-offset not support for 0.90\n");
+               pr_err("data-offset not support for 0.90\n");
                return 0;
        }
 
        if (posix_memalign((void**)&sb, 4096,
                           MD_SB_BYTES + ROUND_UP(sizeof(bitmap_super_t), 4096)) != 0) {
-               pr_err("%s could not allocate superblock\n", __func__);
+               pr_err("could not allocate superblock\n");
                return 0;
        }
        memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
@@ -644,8 +761,8 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info,
        sb->gvalid_words = 0; /* ignored */
        sb->ctime = time(0);
        sb->level = info->level;
-       sb->size = size;
-       if (size != (unsigned long long)sb->size)
+       sb->size = s->size;
+       if (s->size != (unsigned long long)sb->size)
                return 0;
        sb->nr_disks = info->nr_disks;
        sb->raid_disks = info->raid_disks;
@@ -657,16 +774,12 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info,
                sb->set_uuid2 = uuid[2];
                sb->set_uuid3 = uuid[3];
        } else {
-               int rfd = open("/dev/urandom", O_RDONLY);
-               if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
-                       sb->set_uuid0 = random();
-               if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
-                       sb->set_uuid1 = random();
-                       sb->set_uuid2 = random();
-                       sb->set_uuid3 = random();
-               }
-               if (rfd >= 0)
-                       close(rfd);
+               __u32 r[4];
+               random_uuid((__u8 *)r);
+               sb->set_uuid0 = r[0];
+               sb->set_uuid1 = r[1];
+               sb->set_uuid2 = r[2];
+               sb->set_uuid3 = r[3];
        }
        if (homehost && !uuid) {
                char buf[20];
@@ -698,7 +811,6 @@ struct devinfo {
        struct devinfo *next;
 };
 
-#ifndef MDASSEMBLE
 /* Add a device to the superblock being created */
 static int add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
                         int fd, char *devname, unsigned long long data_offset)
@@ -711,9 +823,8 @@ static int add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
        dk->major = dinfo->major;
        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);
+       dk->state = dinfo->state & ((1<<MD_DISK_ACTIVE) |
+                                   (1<<MD_DISK_SYNC));
 
        sb->this_disk = sb->disks[dinfo->number];
        sb->sb_csum = calc_sb0_csum(sb);
@@ -730,7 +841,6 @@ static int add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
 
        return 0;
 }
-#endif
 
 static int store_super0(struct supertype *st, int fd)
 {
@@ -744,6 +854,24 @@ static int store_super0(struct supertype *st, int fd)
        if (dsize < MD_RESERVED_SECTORS*512)
                return 2;
 
+       if (st->other) {
+               /* Writing out v1.0 metadata for --update=metadata */
+               int ret = 0;
+
+               offset = dsize/512 - 8*2;
+               offset &= ~(4*2-1);
+               offset *= 512;
+               if (lseek64(fd, offset, 0)< 0LL)
+                       ret = 3;
+               else if (write(fd, st->other, 1024) != 1024)
+                       ret = 4;
+               else
+                       fsync(fd);
+               free(st->other);
+               st->other = NULL;
+               return ret;
+       }
+
        offset = MD_NEW_SIZE_SECTORS(dsize>>9);
 
        offset *= 512;
@@ -757,7 +885,7 @@ static int store_super0(struct supertype *st, int fd)
        if (super->state & (1<<MD_SB_BITMAP_PRESENT)) {
                struct bitmap_super_s * bm = (struct bitmap_super_s*)(super+1);
                if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC)
-                       if (write(fd, bm, ROUND_UP(sizeof(*bm),4096)) != 
+                       if (write(fd, bm, ROUND_UP(sizeof(*bm),4096)) !=
                            ROUND_UP(sizeof(*bm),4096))
                            return 5;
        }
@@ -766,7 +894,6 @@ static int store_super0(struct supertype *st, int fd)
        return 0;
 }
 
-#ifndef MDASSEMBLE
 static int write_init_super0(struct supertype *st)
 {
        mdp_super_t *sb = st->sb;
@@ -775,7 +902,7 @@ static int write_init_super0(struct supertype *st)
 
        for (di = st->info ; di && ! rv ; di = di->next) {
 
-               if (di->disk.state == 1)
+               if (di->disk.state & (1 << MD_DISK_FAULTY))
                        continue;
                if (di->fd == -1)
                        continue;
@@ -789,7 +916,7 @@ static int write_init_super0(struct supertype *st)
                rv = store_super0(st, di->fd);
 
                if (rv == 0 && (sb->state & (1<<MD_SB_BITMAP_PRESENT)))
-                       rv = st->ss->write_bitmap(st, di->fd);
+                       rv = st->ss->write_bitmap(st, di->fd, NoUpdate);
 
                if (rv)
                        pr_err("failed to write superblock to %s\n",
@@ -797,7 +924,6 @@ static int write_init_super0(struct supertype *st)
        }
        return rv;
 }
-#endif
 
 static int compare_super0(struct supertype *st, struct supertype *tst)
 {
@@ -816,9 +942,9 @@ static int compare_super0(struct supertype *st, struct supertype *tst)
                return 1;
        if (!first) {
                if (posix_memalign((void**)&first, 4096,
-                            MD_SB_BYTES + 
+                            MD_SB_BYTES +
                             ROUND_UP(sizeof(struct bitmap_super_s), 4096)) != 0) {
-                       pr_err("%s could not allocate superblock\n", __func__);
+                       pr_err("could not allocate superblock\n");
                        return 1;
                }
                memcpy(first, second, MD_SB_BYTES + sizeof(struct bitmap_super_s));
@@ -843,7 +969,6 @@ static int compare_super0(struct supertype *st, struct supertype *tst)
        return 0;
 }
 
-
 static void free_super0(struct supertype *st);
 
 static int load_super0(struct supertype *st, int fd, char *devname)
@@ -871,6 +996,7 @@ static int load_super0(struct supertype *st, int fd, char *devname)
                               devname, dsize);
                return 1;
        }
+       st->devsize = dsize;
 
        offset = MD_NEW_SIZE_SECTORS(dsize>>9);
 
@@ -886,7 +1012,7 @@ static int load_super0(struct supertype *st, int fd, char *devname)
        if (posix_memalign((void**)&super, 4096,
                           MD_SB_BYTES +
                           ROUND_UP(sizeof(bitmap_super_t), 4096)) != 0) {
-               pr_err("%s could not allocate superblock\n", __func__);
+               pr_err("could not allocate superblock\n");
                return 1;
        }
 
@@ -932,8 +1058,8 @@ static int load_super0(struct supertype *st, int fd, char *devname)
         * valid.  If it doesn't clear the bit.  An --assemble --force
         * should get that written out.
         */
-       if (read(fd, super+1, ROUND_UP(sizeof(struct bitmap_super_s),4096))
-           != ROUND_UP(sizeof(struct bitmap_super_s),4096))
+       if (read(fd, super+1, ROUND_UP(sizeof(struct bitmap_super_s),4096)) !=
+           ROUND_UP(sizeof(struct bitmap_super_s), 4096))
                goto no_bitmap;
 
        uuid_from_super0(st, uuid);
@@ -1013,7 +1139,6 @@ static int add_internal_bitmap0(struct supertype *st, int *chunkp,
        bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MD_SB_BYTES);
        int uuid[4];
 
-
        min_chunk = 4096; /* sub-page chunks don't work yet.. */
        bits = (size * 512) / min_chunk + 1;
        while (bits > max_bits) {
@@ -1028,7 +1153,7 @@ static int add_internal_bitmap0(struct supertype *st, int *chunkp,
                if (chunk < 64*1024*1024)
                        chunk = 64*1024*1024;
        } else if ((unsigned long long)chunk < min_chunk)
-               return 0; /* chunk size too small */
+               return -EINVAL; /* chunk size too small */
 
        sb->state |= (1<<MD_SB_BITMAP_PRESENT);
 
@@ -1042,20 +1167,19 @@ static int add_internal_bitmap0(struct supertype *st, int *chunkp,
        bms->sync_size = __cpu_to_le64(size);
        bms->write_behind = __cpu_to_le32(write_behind);
        *chunkp = chunk;
-       return 1;
+       return 0;
 }
 
-
-static void locate_bitmap0(struct supertype *st, int fd)
+static int locate_bitmap0(struct supertype *st, int fd, int node_num)
 {
        unsigned long long dsize;
        unsigned long long offset;
 
        if (!get_dev_size(fd, NULL, &dsize))
-               return;
+               return -1;
 
        if (dsize < MD_RESERVED_SECTORS*512)
-               return;
+               return -1;
 
        offset = MD_NEW_SIZE_SECTORS(dsize>>9);
 
@@ -1064,9 +1188,10 @@ static void locate_bitmap0(struct supertype *st, int fd)
        offset += MD_SB_BYTES;
 
        lseek64(fd, offset, 0);
+       return 0;
 }
 
-static int write_bitmap0(struct supertype *st, int fd)
+static int write_bitmap0(struct supertype *st, int fd, enum bitmap_update update)
 {
        unsigned long long dsize;
        unsigned long long offset;
@@ -1129,13 +1254,12 @@ static void free_super0(struct supertype *st)
        st->sb = NULL;
 }
 
-#ifndef MDASSEMBLE
 static int validate_geometry0(struct supertype *st, int level,
                              int layout, int raiddisks,
                              int *chunk, unsigned long long size,
                              unsigned long long data_offset,
                              char *subdev, unsigned long long *freesize,
-                             int verbose)
+                             int consistency_policy, int verbose)
 {
        unsigned long long ldsize;
        int fd;
@@ -1160,11 +1284,10 @@ static int validate_geometry0(struct supertype *st, int level,
        }
        if (size >= tbmax * 2ULL*1024*1024*1024) {
                if (verbose)
-                       pr_err("0.90 metadata supports at most "
-                              "%d terabytes per device\n", tbmax);
+                       pr_err("0.90 metadata supports at most %d terabytes per device\n", tbmax);
                return 0;
        }
-       if (chunk && *chunk == UnSet)
+       if (*chunk == UnSet)
                *chunk = DEFAULT_CHUNK;
 
        if (!subdev)
@@ -1189,10 +1312,8 @@ static int validate_geometry0(struct supertype *st, int level,
        *freesize = MD_NEW_SIZE_SECTORS(ldsize >> 9);
        return 1;
 }
-#endif /* MDASSEMBLE */
 
 struct superswitch super0 = {
-#ifndef MDASSEMBLE
        .examine_super = examine_super0,
        .brief_examine_super = brief_examine_super0,
        .export_examine_super = export_examine_super0,
@@ -1201,7 +1322,7 @@ struct superswitch super0 = {
        .write_init_super = write_init_super0,
        .validate_geometry = validate_geometry0,
        .add_to_super = add_to_super0,
-#endif
+       .copy_metadata = copy_metadata0,
        .match_home = match_home0,
        .uuid_from_super = uuid_from_super0,
        .getinfo_super = getinfo_super0,