]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Add data_offset arg to ->avail_size
authorNeilBrown <neilb@suse.de>
Thu, 4 Oct 2012 06:34:20 +0000 (16:34 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 4 Oct 2012 06:34:20 +0000 (16:34 +1000)
This is currently only useful for 1.x metadata and will allow an
explicit --data-offset request on command line.

Signed-off-by: NeilBrown <neilb@suse.de>
Incremental.c
Manage.c
mdadm.h
super-ddf.c
super-intel.c
super0.c
super1.c

index f88b30ed796ebdcb5437d77981cd328e36964e8a..8e101d7035ecf329edf17369da0b95b501bb7a53 100644 (file)
@@ -867,7 +867,11 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                        close(mdfd);
                }
                if ((sra->component_size > 0 &&
-                    st2->ss->avail_size(st2, devsize) < sra->component_size)
+                    st2->ss->avail_size(st2, devsize,
+                                        sra->devs
+                                        ? sra->devs->data_offset
+                                        : INVALID_SECTORS)
+                    < sra->component_size)
                    ||
                    (sra->component_size == 0 && devsize < component_size)) {
                        if (verbose > 1)
index 9e6225315a139300a32e86c82d1554f85b2a0452..9b5c82b56485294f009ad8107c43241be1062f0b 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -628,7 +628,7 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
                }
 
                /* Make sure device is large enough */
-               if (tst->ss->avail_size(tst, ldsize/512) <
+               if (tst->ss->avail_size(tst, ldsize/512, INVALID_SECTORS) <
                    array_size) {
                        if (dv->disposition == 'M')
                                return 0;
diff --git a/mdadm.h b/mdadm.h
index 6db7714a291774552ba82763a3d76719f8b89365..322af06d25e2069413b0ec19b28692c234863966 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -750,7 +750,8 @@ extern struct superswitch {
        int (*load_super)(struct supertype *st, int fd, char *devname);
        int (*load_container)(struct supertype *st, int fd, char *devname);
        struct supertype * (*match_metadata_desc)(char *arg);
-       __u64 (*avail_size)(struct supertype *st, __u64 size);
+       __u64 (*avail_size)(struct supertype *st, __u64 size,
+                           unsigned long long data_offset);
        unsigned long long (*min_acceptable_spare_size)(struct supertype *st);
        int (*add_internal_bitmap)(struct supertype *st, int *chunkp,
                                   int delay, int write_behind,
index 14a8e3b143158761974f1aaa4ddcd6f703f8b5cb..fbcdef6242f394dc5239ee439921623990e747e2 100644 (file)
@@ -2479,7 +2479,8 @@ static int write_init_super_ddf(struct supertype *st)
 
 #endif
 
-static __u64 avail_size_ddf(struct supertype *st, __u64 devsize)
+static __u64 avail_size_ddf(struct supertype *st, __u64 devsize,
+                           unsigned long long data_offset)
 {
        /* We must reserve the last 32Meg */
        if (devsize <= 32*1024*2)
@@ -2747,7 +2748,7 @@ validate_geometry_ddf_container(struct supertype *st,
        }
        close(fd);
 
-       *freesize = avail_size_ddf(st, ldsize >> 9);
+       *freesize = avail_size_ddf(st, ldsize >> 9, INVALID_SECTORS);
        if (*freesize == 0)
                return 0;
 
index 64f181e36087fd2c132ba72bf79e4d77644459de..74b6f61077256b6922ed3fb523b36827e9695834 100644 (file)
@@ -3024,7 +3024,8 @@ static size_t disks_to_mpb_size(int disks)
        return size;
 }
 
-static __u64 avail_size_imsm(struct supertype *st, __u64 devsize)
+static __u64 avail_size_imsm(struct supertype *st, __u64 devsize,
+                            unsigned long long data_offset)
 {
        if (devsize < (MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS))
                return 0;
@@ -5340,7 +5341,7 @@ static int validate_geometry_imsm_container(struct supertype *st, int level,
                }
        }
 
-       *freesize = avail_size_imsm(st, ldsize >> 9);
+       *freesize = avail_size_imsm(st, ldsize >> 9, INVALID_SECTORS);
        free_imsm(super);
 
        return 1;
index 8ca82e1b159181ac2bbcee7602a3251f0ce9c360..a26e2e002e15945cb7508b757672f607e20a2775 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -975,8 +975,11 @@ static struct supertype *match_metadata_desc0(char *arg)
        return NULL;
 }
 
-static __u64 avail_size0(struct supertype *st, __u64 devsize)
+static __u64 avail_size0(struct supertype *st, __u64 devsize,
+                        unsigned long long data_offset)
 {
+       if (data_offset != 0 && data_offset != INVALID_SECTORS)
+               return 0ULL;
        if (devsize < MD_RESERVED_SECTORS)
                return 0ULL;
        return MD_NEW_SIZE_SECTORS(devsize);
index 96d5b1b016a67715310f05c8e3cc81b1a9eb55d6..1e4597bd66849857ce3f8626cae36cabaaacd8b6 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -1609,21 +1609,23 @@ static struct supertype *match_metadata_desc1(char *arg)
  * superblock type st, and reserving 'reserve' sectors for
  * a possible bitmap
  */
-static __u64 avail_size1(struct supertype *st, __u64 devsize)
+static __u64 avail_size1(struct supertype *st, __u64 devsize,
+                        unsigned long long data_offset)
 {
        struct mdp_superblock_1 *super = st->sb;
+       int bmspace = 0;
        if (devsize < 24)
                return 0;
 
        if (super == NULL)
                /* creating:  allow suitable space for bitmap */
-               devsize -= choose_bm_space(devsize);
+               bmspace = choose_bm_space(devsize);
 #ifndef MDASSEMBLE
        else if (__le32_to_cpu(super->feature_map)&MD_FEATURE_BITMAP_OFFSET) {
                /* hot-add. allow for actual size of bitmap */
                struct bitmap_super_s *bsb;
                bsb = (struct bitmap_super_s *)(((char*)super)+MAX_SB_SIZE);
-               devsize -= bitmap_sectors(bsb);
+               bmspace = bitmap_sectors(bsb);
        }
 #endif
        /* Allow space for bad block log */
@@ -1632,9 +1634,24 @@ static __u64 avail_size1(struct supertype *st, __u64 devsize)
        else
                devsize -= 8;
 
+
        if (st->minor_version < 0)
                /* not specified, so time to set default */
                st->minor_version = 2;
+
+       if (data_offset != INVALID_SECTORS)
+               switch(st->minor_version) {
+               case 0:
+                       return devsize - data_offset - 8*2;
+               case 1:
+               case 2:
+                       return devsize - data_offset;
+               default:
+                       return 0;
+               }
+
+       devsize -= bmspace;
+
        if (super == NULL && st->minor_version > 0) {
                /* haven't committed to a size yet, so allow some
                 * slack for space for reshape.
@@ -1916,7 +1933,7 @@ static int validate_geometry1(struct supertype *st, int level,
        }
        close(fd);
 
-       *freesize = avail_size1(st, ldsize >> 9);
+       *freesize = avail_size1(st, ldsize >> 9, INVALID_SECTORS);
        return 1;
 }
 #endif /* MDASSEMBLE */