]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super-intel.c
Change 'size' argument to validate_geometry to be sectors, not K
[thirdparty/mdadm.git] / super-intel.c
index 6ef2e5198ac1b8b157dfa88c95a8eaeed334d739..f78957f13549325932cb22d7c45c89a21b154a82 100644 (file)
@@ -489,6 +489,13 @@ static struct extent *get_extents(struct intel_super *super, struct dl *dl)
 
                remainder = __le32_to_cpu(dl->disk.total_blocks) - 
                            (last->start + last->size);
+               /* round down to 1k block to satisfy precision of the kernel
+                * 'size' interface
+                */
+               remainder &= ~1UL;
+               /* make sure remainder is still sane */
+               if (remainder < ROUND_UP(super->len, 512) >> 9)
+                       remainder = ROUND_UP(super->len, 512) >> 9;
                if (reservation > remainder)
                        reservation = remainder;
        }
@@ -751,7 +758,7 @@ static void uuid_from_super_imsm(struct supertype *st, int uuid[4])
        struct imsm_dev *dev = NULL;
 
        sha1_init_ctx(&ctx);
-       sha1_process_bytes(super->anchor->sig, MAX_SIGNATURE_LENGTH, &ctx);
+       sha1_process_bytes(super->anchor->sig, MPB_SIG_LEN, &ctx);
        sha1_process_bytes(&super->anchor->family_num, sizeof(__u32), &ctx);
        if (super->current_vol >= 0)
                dev = get_imsm_dev(super, super->current_vol);
@@ -1911,7 +1918,7 @@ static int init_super_imsm(struct supertype *st, mdu_array_info_t *info,
 }
 
 #ifndef MDASSEMBLE
-static void add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
+static int add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
                                     int fd, char *devname)
 {
        struct intel_super *super = st->sb;
@@ -1923,13 +1930,21 @@ static void add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
        dev = get_imsm_dev(super, super->current_vol);
        map = get_imsm_map(dev, 0);
 
+       if (! (dk->state & (1<<MD_DISK_SYNC))) {
+               fprintf(stderr, Name ": %s: Cannot add spare devices to IMSM volume\n",
+                       devname);
+               return 1;
+       }
+
        for (dl = super->disks; dl ; dl = dl->next)
                if (dl->major == dk->major &&
                    dl->minor == dk->minor)
                        break;
 
-       if (!dl || ! (dk->state & (1<<MD_DISK_SYNC)))
-               return;
+       if (!dl) {
+               fprintf(stderr, Name ": %s is not a member of the same container\n", devname);
+               return 1;
+       }
 
        /* add a pristine spare to the metadata */
        if (dl->index < 0) {
@@ -1950,9 +1965,11 @@ static void add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
                sum = __gen_imsm_checksum(mpb);
                mpb->family_num = __cpu_to_le32(sum);
        }
+
+       return 0;
 }
 
-static void add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
+static int add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
                              int fd, char *devname)
 {
        struct intel_super *super = st->sb;
@@ -1962,17 +1979,15 @@ static void add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
        int rv;
        struct stat stb;
 
-       if (super->current_vol >= 0) {
-               add_to_super_imsm_volume(st, dk, fd, devname);
-               return;
-       }
+       if (super->current_vol >= 0)
+               return add_to_super_imsm_volume(st, dk, fd, devname);
 
        fstat(fd, &stb);
        dd = malloc(sizeof(*dd));
        if (!dd) {
                fprintf(stderr,
                        Name ": malloc failed %s:%d.\n", __func__, __LINE__);
-               abort();
+               return 1;
        }
        memset(dd, 0, sizeof(*dd));
        dd->major = major(stb.st_rdev);
@@ -2005,6 +2020,8 @@ static void add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
                dd->next = super->disks;
                super->disks = dd;
        }
+
+       return 0;
 }
 
 static int store_imsm_mpb(int fd, struct intel_super *super);
@@ -2278,7 +2295,7 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level,
                 * 'raiddisks' device extents of size 'size' at a given
                 * offset
                 */
-               unsigned long long minsize = size*2 /* convert to blocks */;
+               unsigned long long minsize = size;
                unsigned long long start_offset = ~0ULL;
                int dcnt = 0;
                if (minsize == 0)