]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
create: Check with OROM limit before setting default chunk size
authorDave Jiang <dave.jiang@intel.com>
Wed, 16 Jun 2010 01:41:53 +0000 (18:41 -0700)
committerDan Williams <dan.j.williams@intel.com>
Wed, 16 Jun 2010 01:41:53 +0000 (18:41 -0700)
Make create check with the appropriate meta data handler and see what the
largest chunk size is supported. The current 512K default is not supported
by existing imsm OROM.

[dan.j.williams@intel.com: trim the upper limit to 512k for future oroms]
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Create.c
mdadm.h
platform-intel.h
super-intel.c

index b04388f5e338205c3136e7ef6ec9a14ea7063a8a..43e5f37e8b7c4685a7565e80a48631ee386c5415 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -235,9 +235,13 @@ int Create(struct supertype *st, char *mddev,
        case 6:
        case 0:
                if (chunk == 0) {
-                       chunk = 512;
+                       if (st && st->ss->default_chunk)
+                               chunk = st->ss->default_chunk(st);
+
+                       chunk = chunk ? : 512;
+
                        if (verbose > 0)
-                               fprintf(stderr, Name ": chunk size defaults to 512K\n");
+                               fprintf(stderr, Name ": chunk size defaults to %dK\n", chunk);
                }
                break;
        case LEVEL_LINEAR:
diff --git a/mdadm.h b/mdadm.h
index 1bf5ac0a44de67ad51088d339a1365f5e807450b..142868ad34ed8cd73aa70573b632c78d21ca46df 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -609,6 +609,8 @@ extern struct superswitch {
        struct mdinfo *(*container_content)(struct supertype *st);
        /* Allow a metadata handler to override mdadm's default layouts */
        int (*default_layout)(int level); /* optional */
+       /* query the supertype for default chunk size */
+       int (*default_chunk)(struct supertype *st); /* optional */
 
 /* for mdmon */
        int (*open_new)(struct supertype *c, struct active_array *a,
index bbdc9f9508b4c95e6322b6ac5e8f776e4c939780..908843618de969bfc86120cecada0513a9d9c389 100644 (file)
@@ -115,6 +115,55 @@ static inline int imsm_orom_has_chunk(const struct imsm_orom *orom, int chunk)
        return !!(orom->sss & (1 << (fs - 1)));
 }
 
+/**
+ * fls - find last (most-significant) bit set
+ * @x: the word to search
+ * The funciton is borrowed from Linux kernel code
+ * include/asm-generic/bitops/fls.h
+ */
+static inline int fls(int x)
+{
+       int r = 32;
+
+       if (!x)
+               return 0;
+       if (!(x & 0xffff0000u)) {
+               x <<= 16;
+               r -= 16;
+       }
+       if (!(x & 0xff000000u)) {
+               x <<= 8;
+               r -= 8;
+       }
+       if (!(x & 0xf0000000u)) {
+               x <<= 4;
+               r -= 4;
+       }
+       if (!(x & 0xc0000000u)) {
+               x <<= 2;
+               r -= 2;
+       }
+       if (!(x & 0x80000000u)) {
+               x <<= 1;
+               r -= 1;
+       }
+       return r;
+}
+
+/**
+ * imsm_orom_default_chunk - return the largest chunk size supported via orom
+ * @orom: orom pointer from find_imsm_orom
+ */
+static inline int imsm_orom_default_chunk(const struct imsm_orom *orom)
+{
+       int fs = fls(orom->sss);
+
+       if (!fs)
+               return 0;
+
+       return min(512, (1 << fs));
+}
+
 struct sys_dev {
        char *path;
        struct sys_dev *next;
index 394ace419dbf8c13e2547057c4b7187f562b3d89..e212d9a0602865e80b2b9aa519063304263aa430 100644 (file)
@@ -4003,6 +4003,17 @@ static int validate_geometry_imsm(struct supertype *st, int level, int layout,
        close(cfd);
        return 0;
 }
+
+static int default_chunk_imsm(struct supertype *st)
+{
+       struct intel_super *super = st->sb;
+
+       if (!super->orom)
+               return 0;
+
+       return imsm_orom_default_chunk(super->orom);
+}
+
 #endif /* MDASSEMBLE */
 
 static int is_rebuilding(struct imsm_dev *dev)
@@ -5240,6 +5251,7 @@ struct superswitch super_imsm = {
        .brief_detail_super = brief_detail_super_imsm,
        .write_init_super = write_init_super_imsm,
        .validate_geometry = validate_geometry_imsm,
+       .default_chunk  = default_chunk_imsm,
        .add_to_super   = add_to_super_imsm,
        .detail_platform = detail_platform_imsm,
 #endif