]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Add data_offset arg to ->avail_size
authorNeilBrown <neilb@suse.de>
Wed, 9 May 2012 10:49:31 +0000 (20:49 +1000)
committerNeilBrown <neilb@suse.de>
Wed, 9 May 2012 10:49:31 +0000 (20:49 +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 a61f45336aa58c7b59309ca55fd3fe8ab27f921e..e3639f2e83e1664e8d37111aed2012de46c83996 100644 (file)
@@ -897,7 +897,10 @@ 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
+                                        ? (long long)sra->devs->data_offset : -1)
+                    < sra->component_size)
                    ||
                    (sra->component_size == 0 && devsize < component_size)) {
                        if (verbose > 1)
index 95aa2704bcccae60e3d65b1c2ff1da313a1ec89f..19afba9c0c18083b51cca279e4d03cfc6bd12a52 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -746,7 +746,7 @@ int Manage_subdevs(char *devname, int fd,
                                }
 
                                /* Make sure device is large enough */
-                               if (tst->ss->avail_size(tst, ldsize/512) <
+                               if (tst->ss->avail_size(tst, ldsize/512, -1) <
                                    array_size) {
                                        close(tfd);
                                        tfd = -1;
diff --git a/mdadm.h b/mdadm.h
index 4946d4eac3d74233bfa479b2542fee0bb56bd5aa..410fc7778b23a472accf5ac475d727e4ebb98e54 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -705,7 +705,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,
+                           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 5e51c4cdac765770fb875bea91a71206e4da8356..bfb01606a6f8ff45ac2e8af438ae133d7951685f 100644 (file)
@@ -2497,7 +2497,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,
+                           long long data_offset)
 {
        /* We must reserve the last 32Meg */
        if (devsize <= 32*1024*2)
@@ -2768,7 +2769,7 @@ validate_geometry_ddf_container(struct supertype *st,
        }
        close(fd);
 
-       *freesize = avail_size_ddf(st, ldsize >> 9);
+       *freesize = avail_size_ddf(st, ldsize >> 9, -1);
        if (*freesize == 0)
                return 0;
 
index e2ed95a15232ff1fe7e4947703ef6753450dbcce..5ae48d041402b3e9a0a492b7c298ed6fba6ac0a4 100644 (file)
@@ -2971,7 +2971,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,
+                            long long data_offset)
 {
        if (devsize < (MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS))
                return 0;
@@ -5383,7 +5384,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, -1);
        free_imsm(super);
 
        return 1;
index 137579986b176abf827d682b5bf83c79a9eff361..4da6fa9bcce416e81f1048a2312ab40e8c2c6292 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -981,8 +981,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,
+                        long long data_offset)
 {
+       if (data_offset > 0)
+               return 0ULL;
        if (devsize < MD_RESERVED_SECTORS)
                return 0ULL;
        return MD_NEW_SIZE_SECTORS(devsize);
index be77c330cc789034e97c60a45ea8d25f026ae685..7fc91b29032d7b657b5db6a983b94cd8c63c506d 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -1497,27 +1497,44 @@ 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,
+                        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
 
+
        if (st->minor_version < 0)
                /* not specified, so time to set default */
                st->minor_version = 2;
+
+       if (data_offset > 0)
+               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.
@@ -1780,7 +1797,7 @@ static int validate_geometry1(struct supertype *st, int level,
        }
        close(fd);
 
-       *freesize = avail_size1(st, ldsize >> 9);
+       *freesize = avail_size1(st, ldsize >> 9, -1);
        return 1;
 }
 #endif /* MDASSEMBLE */