]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super1.c
Consistently print program Name and __func__ in debug messages.
[thirdparty/mdadm.git] / super1.c
index fcdb710bb28dec5b06b2d79ca33a21bf3f338f5d..0fd84e25bfde2fbfd1f5fb814f0d1e42bd7c57f8 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -22,6 +22,7 @@
  *    Email: <neilb@suse.de>
  */
 
+#include <stddef.h>
 #include "mdadm.h"
 /*
  * The version-1 superblock :
@@ -133,9 +134,6 @@ struct misc_dev_info {
                                        |MD_FEATURE_NEW_OFFSET          \
                                        )
 
-#ifndef offsetof
-#define offsetof(t,f) ((size_t)&(((t*)0)->f))
-#endif
 static unsigned int calc_sb_1_csum(struct mdp_superblock_1 * sb)
 {
        unsigned int disk_csum, csum;
@@ -813,7 +811,7 @@ static int examine_badblocks_super1(struct supertype *st, int fd, char *devname)
 
        size = __le32_to_cpu(sb->bblog_size)* 512;
        if (posix_memalign((void**)&bbl, 4096, size) != 0) {
-               pr_err("%s could not allocate badblocks list\n", __func__);
+               pr_err("could not allocate badblocks list\n");
                return 0;
        }
        offset = __le64_to_cpu(sb->super_offset) +
@@ -1247,12 +1245,8 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                /* set data_size to device size less data_offset */
                struct misc_dev_info *misc = (struct misc_dev_info*)
                        (st->sb + MAX_SB_SIZE + BM_SUPER_SIZE);
-               printf("Size was %llu\n", (unsigned long long)
-                      __le64_to_cpu(sb->data_size));
                sb->data_size = __cpu_to_le64(
                        misc->device_size - __le64_to_cpu(sb->data_offset));
-               printf("Size is %llu\n", (unsigned long long)
-                      __le64_to_cpu(sb->data_size));
        } else if (strcmp(update, "revert-reshape") == 0) {
                rv = -2;
                if (!(sb->feature_map & __cpu_to_le32(MD_FEATURE_RESHAPE_ACTIVE)))
@@ -1334,7 +1328,7 @@ static int init_super1(struct supertype *st, mdu_array_info_t *info,
        int sbsize;
 
        if (posix_memalign((void**)&sb, 4096, SUPER1_SIZE) != 0) {
-               pr_err("%s could not allocate superblock\n", __func__);
+               pr_err("could not allocate superblock\n");
                return 0;
        }
        memset(sb, 0, SUPER1_SIZE);
@@ -1559,7 +1553,7 @@ static int write_init_super1(struct supertype *st)
        unsigned long long data_offset;
 
        for (di = st->info; di; di = di->next) {
-               if (di->disk.state == 1)
+               if (di->disk.state & (1 << MD_DISK_FAULTY))
                        continue;
                if (di->fd < 0)
                        continue;
@@ -1638,6 +1632,7 @@ static int write_init_super1(struct supertype *st)
                        sb_offset = dsize;
                        sb_offset -= 8*2;
                        sb_offset &= ~(4*2-1);
+                       sb->data_offset = __cpu_to_le64(data_offset);
                        sb->super_offset = __cpu_to_le64(sb_offset);
                        if (sb_offset < array_size + bm_space)
                                bm_space = sb_offset - array_size;
@@ -1689,6 +1684,10 @@ static int write_init_super1(struct supertype *st)
                        rv = -EINVAL;
                        goto out;
                }
+               if (conf_get_create_info()->bblist == 0) {
+                       sb->bblog_size = 0;
+                       sb->bblog_offset = 0;
+               }
 
                sb->sb_csum = calc_sb_1_csum(sb);
                rv = store_super1(st, di->fd);
@@ -1727,7 +1726,7 @@ static int compare_super1(struct supertype *st, struct supertype *tst)
 
        if (!first) {
                if (posix_memalign((void**)&first, 4096, SUPER1_SIZE) != 0) {
-                       pr_err("%s could not allocate superblock\n", __func__);
+                       pr_err("could not allocate superblock\n");
                        return 1;
                }
                memcpy(first, second, SUPER1_SIZE);
@@ -1838,8 +1837,7 @@ static int load_super1(struct supertype *st, int fd, char *devname)
        }
 
        if (posix_memalign((void**)&super, 4096, SUPER1_SIZE) != 0) {
-               pr_err("%s could not allocate superblock\n",
-                       __func__);
+               pr_err("could not allocate superblock\n");
                return 1;
        }
 
@@ -2045,8 +2043,8 @@ add_internal_bitmap1(struct supertype *st,
                         * been left.
                         */
                        offset = 0;
-                       room = choose_bm_space(__le64_to_cpu(sb->size));
                        bbl_size = 8;
+                       room = choose_bm_space(__le64_to_cpu(sb->size)) + bbl_size;
                } else {
                        room = __le64_to_cpu(sb->super_offset)
                                - __le64_to_cpu(sb->data_offset)
@@ -2072,8 +2070,8 @@ add_internal_bitmap1(struct supertype *st,
        case 2: /* between superblock and data */
                if (creating) {
                        offset = 4*2;
-                       room = choose_bm_space(__le64_to_cpu(sb->size));
                        bbl_size = 8;
+                       room = choose_bm_space(__le64_to_cpu(sb->size)) + bbl_size;
                } else {
                        room = __le64_to_cpu(sb->data_offset)
                                - __le64_to_cpu(sb->super_offset);
@@ -2102,6 +2100,10 @@ add_internal_bitmap1(struct supertype *st,
                /* Limit to 128K of bitmap when chunk size not requested */
                room = 128*2;
 
+       if (room <= 1)
+               /* No room for a bitmap */
+               return 0;
+
        max_bits = (room * 512 - sizeof(bitmap_super_t)) * 8;
 
        min_chunk = 4096; /* sub-page chunks don't work yet.. */
@@ -2311,7 +2313,7 @@ static int validate_geometry1(struct supertype *st, int level,
        case 0: /* metadata at end.  Round down and subtract space to reserve */
                devsize = (devsize & ~(4ULL*2-1));
                /* space for metadata, bblog, bitmap */
-               devsize -= 8*2 - 8 - bmspace;
+               devsize -= 8*2 + 8 + bmspace;
                break;
        case 1:
        case 2: