]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
mdmon: ping will wait for manage_mon to catch up.
[thirdparty/mdadm.git] / super0.c
index 1ca35368bb4f92ca8d5b4d2b7d728bef60b11588..ab636605bc6ab66fbd1b8931df6a6e0eb2b97c14 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -53,7 +53,7 @@ static unsigned long calc_sb0_csum(mdp_super_t *super)
 }
 
 
-void super0_swap_endian(struct mdp_superblock_s *sb)
+static void super0_swap_endian(struct mdp_superblock_s *sb)
 {
        /* as super0 superblocks are host-endian, it is sometimes
         * useful to be able to swap the endianness
@@ -369,6 +369,8 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info)
        info->events = md_event(sb);
        info->data_offset = 0;
 
+       sprintf(info->text_version, "0.%d", sb->minor_version);
+
        uuid_from_super0(st, info->uuid);
 
        if (sb->minor_version > 90 && (sb->reshape_position+1) != 0) {
@@ -552,12 +554,14 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info,
                       unsigned long long size, char *ignored_name, char *homehost,
                       int *uuid)
 {
-       mdp_super_t *sb = malloc(MD_SB_BYTES + sizeof(bitmap_super_t));
+       mdp_super_t *sb;
        int spares;
+
+       posix_memalign((void**)&sb, 512, MD_SB_BYTES + sizeof(bitmap_super_t));
        memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
 
        st->sb = sb;
-       if (info->major_version == -1) {
+       if (info == NULL) {
                /* zeroing the superblock */
                return 0;
        }
@@ -643,6 +647,9 @@ static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
        dk->raid_disk = dinfo->raid_disk;
        dk->state = dinfo->state;
 
+       sb->this_disk = sb->disks[dinfo->number];
+       sb->sb_csum = calc_sb0_csum(sb);
+
        dip = (struct devinfo **)&st->info;
        while (*dip)
                dip = &(*dip)->next;
@@ -679,7 +686,8 @@ 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, sizeof(*bm)) != sizeof(*bm))
+                       if (write(fd, bm, ROUND_UP(sizeof(*bm),512)) != 
+                           ROUND_UP(sizeof(*bm),512))
                            return 5;
        }
 
@@ -698,6 +706,8 @@ static int write_init_super0(struct supertype *st)
 
                if (di->disk.state == 1)
                        continue;
+               if (di->fd == -1)
+                       continue;
                Kill(di->devname, 0, 1, 1);
                Kill(di->devname, 0, 1, 1);
 
@@ -737,7 +747,8 @@ static int compare_super0(struct supertype *st, struct supertype *tst)
        if (second->md_magic != MD_SB_MAGIC)
                return 1;
        if (!first) {
-               first = malloc(MD_SB_BYTES + sizeof(struct bitmap_super_s));
+               posix_memalign((void**)&first, 512, 
+                              MD_SB_BYTES + sizeof(struct bitmap_super_s));
                memcpy(first, second, MD_SB_BYTES + sizeof(struct bitmap_super_s));
                st->sb = first;
                return 0;
@@ -779,6 +790,9 @@ static int load_super0(struct supertype *st, int fd, char *devname)
 
        free_super0(st);
 
+       if (st->subarray[0])
+               return 1;
+
        if (!get_dev_size(fd, devname, &dsize))
                return 1;
 
@@ -803,7 +817,7 @@ static int load_super0(struct supertype *st, int fd, char *devname)
                return 1;
        }
 
-       super = malloc(MD_SB_BYTES + sizeof(bitmap_super_t));
+       posix_memalign((void**)&super, 512, MD_SB_BYTES + sizeof(bitmap_super_t)+512);
 
        if (read(fd, super, sizeof(*super)) != MD_SB_BYTES) {
                if (devname)
@@ -847,8 +861,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, sizeof(struct bitmap_super_s))
-           != sizeof(struct bitmap_super_s))
+       if (read(fd, super+1, ROUND_UP(sizeof(struct bitmap_super_s),512))
+           != ROUND_UP(sizeof(struct bitmap_super_s),512))
                goto no_bitmap;
 
        uuid_from_super0(st, uuid);
@@ -947,7 +961,7 @@ static int add_internal_bitmap0(struct supertype *st, int *chunkp,
 }
 
 
-void locate_bitmap0(struct supertype *st, int fd)
+static void locate_bitmap0(struct supertype *st, int fd)
 {
        unsigned long long dsize;
        unsigned long long offset;
@@ -967,7 +981,7 @@ void locate_bitmap0(struct supertype *st, int fd)
        lseek64(fd, offset, 0);
 }
 
-int write_bitmap0(struct supertype *st, int fd)
+static int write_bitmap0(struct supertype *st, int fd)
 {
        unsigned long long dsize;
        unsigned long long offset;
@@ -976,7 +990,8 @@ int write_bitmap0(struct supertype *st, int fd)
        int rv = 0;
 
        int towrite, n;
-       char buf[4096];
+       char abuf[4096+512];
+       char *buf = (char*)(((long)(abuf+512))&~511UL);
 
        if (!get_dev_size(fd, NULL, &dsize))
                return 1;
@@ -992,21 +1007,19 @@ int write_bitmap0(struct supertype *st, int fd)
        if (lseek64(fd, offset + 4096, 0)< 0LL)
                return 3;
 
-
-       if (write(fd, ((char*)sb)+MD_SB_BYTES, sizeof(bitmap_super_t)) !=
-           sizeof(bitmap_super_t))
-               return -2;
-       towrite = 64*1024 - MD_SB_BYTES - sizeof(bitmap_super_t);
-       memset(buf, 0xff, sizeof(buf));
+       memset(buf, 0xff, 4096);
+       memcpy(buf,  ((char*)sb)+MD_SB_BYTES, sizeof(bitmap_super_t));
+       towrite = 64*1024;
        while (towrite > 0) {
                n = towrite;
-               if (n > sizeof(buf))
-                       n = sizeof(buf);
+               if (n > 4096)
+                       n = 4096;
                n = write(fd, buf, n);
                if (n > 0)
                        towrite -= n;
                else
                        break;
+               memset(buf, 0xff, 4096);
        }
        fsync(fd);
        if (towrite)
@@ -1025,7 +1038,8 @@ static void free_super0(struct supertype *st)
 static int validate_geometry0(struct supertype *st, int level,
                              int layout, int raiddisks,
                              int chunk, unsigned long long size,
-                             char *subdev, unsigned long long *freesize)
+                             char *subdev, unsigned long long *freesize,
+                             int verbose)
 {
        unsigned long long ldsize;
        int fd;
@@ -1041,10 +1055,12 @@ static int validate_geometry0(struct supertype *st, int level,
 
        fd = open(subdev, O_RDONLY|O_EXCL, 0);
        if (fd < 0) {
-               fprintf(stderr, Name ": Cannot open %s: %s\n",
-                       subdev, strerror(errno));
+               if (verbose)
+                       fprintf(stderr, Name ": super0.90 cannot open %s: %s\n",
+                               subdev, strerror(errno));
                return 0;
        }
+
        if (!get_dev_size(fd, subdev, &ldsize)) {
                close(fd);
                return 0;
@@ -1085,6 +1101,4 @@ struct superswitch super0 = {
        .write_bitmap = write_bitmap0,
        .free_super = free_super0,
        .validate_geometry = validate_geometry0,
-       .major = 0,
-       .swapuuid = 0,
 };