s390/con3270: fix insufficient space padding
[pandora-kernel.git] / drivers / md / raid0.c
index 0eb08a4..c0b4a21 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <linux/blkdev.h>
 #include <linux/seq_file.h>
+#include <linux/module.h>
 #include <linux/slab.h>
 #include "md.h"
 #include "raid0.h"
@@ -87,6 +88,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
        char b[BDEVNAME_SIZE];
        char b2[BDEVNAME_SIZE];
        struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
+       unsigned short blksize = 512;
 
        if (!conf)
                return -ENOMEM;
@@ -101,6 +103,9 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
                sector_div(sectors, mddev->chunk_sectors);
                rdev1->sectors = sectors * mddev->chunk_sectors;
 
+               blksize = max(blksize, queue_logical_block_size(
+                                     rdev1->bdev->bd_disk->queue));
+
                list_for_each_entry(rdev2, &mddev->disks, same_set) {
                        pr_debug("md/raid0:%s:   comparing %s(%llu)"
                                 " with %s(%llu)\n",
@@ -137,6 +142,18 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
        }
        pr_debug("md/raid0:%s: FINAL %d zones\n",
                 mdname(mddev), conf->nr_strip_zones);
+       /*
+        * now since we have the hard sector sizes, we can make sure
+        * chunk size is a multiple of that sector size
+        */
+       if ((mddev->chunk_sectors << 9) % blksize) {
+               printk(KERN_ERR "md/raid0:%s: chunk_size of %d not multiple of block size %d\n",
+                      mdname(mddev),
+                      mddev->chunk_sectors << 9, blksize);
+               err = -EINVAL;
+               goto abort;
+       }
+
        err = -ENOMEM;
        conf->strip_zone = kzalloc(sizeof(struct strip_zone)*
                                conf->nr_strip_zones, GFP_KERNEL);
@@ -185,8 +202,6 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
                }
                dev[j] = rdev1;
 
-               disk_stack_limits(mddev->gendisk, rdev1->bdev,
-                                 rdev1->data_offset << 9);
                /* as we don't honour merge_bvec_fn, we must never risk
                 * violating it, so limit ->max_segments to 1, lying within
                 * a single page.
@@ -262,21 +277,6 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
        mddev->queue->backing_dev_info.congested_fn = raid0_congested;
        mddev->queue->backing_dev_info.congested_data = mddev;
 
-       /*
-        * now since we have the hard sector sizes, we can make sure
-        * chunk size is a multiple of that sector size
-        */
-       if ((mddev->chunk_sectors << 9) % queue_logical_block_size(mddev->queue)) {
-               printk(KERN_ERR "md/raid0:%s: chunk_size of %d not valid\n",
-                      mdname(mddev),
-                      mddev->chunk_sectors << 9);
-               goto abort;
-       }
-
-       blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);
-       blk_queue_io_opt(mddev->queue,
-                        (mddev->chunk_sectors << 9) * mddev->raid_disks);
-
        pr_debug("md/raid0:%s: done.\n", mdname(mddev));
        *private_conf = conf;
 
@@ -285,7 +285,7 @@ abort:
        kfree(conf->strip_zone);
        kfree(conf->devlist);
        kfree(conf);
-       *private_conf = NULL;
+       *private_conf = ERR_PTR(err);
        return err;
 }
 
@@ -329,7 +329,8 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disks
                  "%s does not support generic reshape\n", __func__);
 
        list_for_each_entry(rdev, &mddev->disks, same_set)
-               array_sectors += rdev->sectors;
+               array_sectors += (rdev->sectors &
+                                 ~(sector_t)(mddev->chunk_sectors-1));
 
        return array_sectors;
 }
@@ -338,6 +339,7 @@ static int raid0_run(struct mddev *mddev)
 {
        struct r0conf *conf;
        int ret;
+       struct md_rdev *rdev;
 
        if (mddev->chunk_sectors == 0) {
                printk(KERN_ERR "md/raid0:%s: chunk size must be set.\n",
@@ -346,7 +348,6 @@ static int raid0_run(struct mddev *mddev)
        }
        if (md_check_no_bitmap(mddev))
                return -EINVAL;
-       blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors);
 
        /* if private is not null, we are here after takeover */
        if (mddev->private == NULL) {
@@ -357,6 +358,17 @@ static int raid0_run(struct mddev *mddev)
        }
        conf = mddev->private;
 
+       blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors);
+
+       blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);
+       blk_queue_io_opt(mddev->queue,
+                        (mddev->chunk_sectors << 9) * mddev->raid_disks);
+
+       list_for_each_entry(rdev, &mddev->disks, same_set) {
+               disk_stack_limits(mddev->gendisk, rdev->bdev,
+                                 rdev->data_offset << 9);
+       }
+
        /* calculate array device size */
        md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
 
@@ -468,7 +480,7 @@ static inline int is_io_in_chunk_boundary(struct mddev *mddev,
        }
 }
 
-static int raid0_make_request(struct mddev *mddev, struct bio *bio)
+static void raid0_make_request(struct mddev *mddev, struct bio *bio)
 {
        unsigned int chunk_sects;
        sector_t sector_offset;
@@ -477,7 +489,7 @@ static int raid0_make_request(struct mddev *mddev, struct bio *bio)
 
        if (unlikely(bio->bi_rw & REQ_FLUSH)) {
                md_flush_request(mddev, bio);
-               return 0;
+               return;
        }
 
        chunk_sects = mddev->chunk_sectors;
@@ -497,13 +509,10 @@ static int raid0_make_request(struct mddev *mddev, struct bio *bio)
                else
                        bp = bio_split(bio, chunk_sects -
                                       sector_div(sector, chunk_sects));
-               if (raid0_make_request(mddev, &bp->bio1))
-                       generic_make_request(&bp->bio1);
-               if (raid0_make_request(mddev, &bp->bio2))
-                       generic_make_request(&bp->bio2);
-
+               raid0_make_request(mddev, &bp->bio1);
+               raid0_make_request(mddev, &bp->bio2);
                bio_pair_release(bp);
-               return 0;
+               return;
        }
 
        sector_offset = bio->bi_sector;
@@ -513,10 +522,9 @@ static int raid0_make_request(struct mddev *mddev, struct bio *bio)
        bio->bi_bdev = tmp_dev->bdev;
        bio->bi_sector = sector_offset + zone->dev_start +
                tmp_dev->data_offset;
-       /*
-        * Let the main block layer submit the IO and resolve recursion:
-        */
-       return 1;
+
+       generic_make_request(bio);
+       return;
 
 bad_map:
        printk("md/raid0:%s: make_request bug: can't convert block across chunks"
@@ -525,7 +533,7 @@ bad_map:
               (unsigned long long)bio->bi_sector, bio->bi_size >> 10);
 
        bio_io_error(bio);
-       return 0;
+       return;
 }
 
 static void raid0_status(struct seq_file *seq, struct mddev *mddev)