dm table: pass correct dev area size to device_area_is_valid
authorMike Snitzer <snitzer@redhat.com>
Thu, 23 Jul 2009 19:30:42 +0000 (20:30 +0100)
committerAlasdair G Kergon <agk@redhat.com>
Thu, 23 Jul 2009 19:30:42 +0000 (20:30 +0100)
Incorrect device area lengths are being passed to device_area_is_valid().

The regression appeared in 2.6.31-rc1 through commit
754c5fc7ebb417b23601a6222a6005cc2e7f2913.

With the dm-stripe target, the size of the target (ti->len) was used
instead of the stripe_width (ti->len/#stripes).  An example of a
consequent incorrect error message is:

  device-mapper: table: 254:0: sdb too small for target

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
drivers/md/dm-crypt.c
drivers/md/dm-delay.c
drivers/md/dm-linear.c
drivers/md/dm-mpath.c
drivers/md/dm-raid1.c
drivers/md/dm-stripe.c
drivers/md/dm-table.c
include/linux/device-mapper.h

index 529e2ba505c30055440be381d908c52b3113f44d..ed1038164019a1d5935937037c6aae2bd429c666 100644 (file)
@@ -1318,7 +1318,7 @@ static int crypt_iterate_devices(struct dm_target *ti,
 {
        struct crypt_config *cc = ti->private;
 
-       return fn(ti, cc->dev, cc->start, data);
+       return fn(ti, cc->dev, cc->start, ti->len, data);
 }
 
 static struct target_type crypt_target = {
index 4e5b843cd4d77fb388920991eefd5540e2399aef..ebe7381f47c8fd5b1d86cd4e603acad20eebe98f 100644 (file)
@@ -324,12 +324,12 @@ static int delay_iterate_devices(struct dm_target *ti,
        struct delay_c *dc = ti->private;
        int ret = 0;
 
-       ret = fn(ti, dc->dev_read, dc->start_read, data);
+       ret = fn(ti, dc->dev_read, dc->start_read, ti->len, data);
        if (ret)
                goto out;
 
        if (dc->dev_write)
-               ret = fn(ti, dc->dev_write, dc->start_write, data);
+               ret = fn(ti, dc->dev_write, dc->start_write, ti->len, data);
 
 out:
        return ret;
index 9184b6deb8685dc3660e21dd438f6aa8fcd200b3..82f7d6e6b1eab551588ae6b8e917622151c4d4ff 100644 (file)
@@ -139,7 +139,7 @@ static int linear_iterate_devices(struct dm_target *ti,
 {
        struct linear_c *lc = ti->private;
 
-       return fn(ti, lc->dev, lc->start, data);
+       return fn(ti, lc->dev, lc->start, ti->len, data);
 }
 
 static struct target_type linear_target = {
index c70604a208979b4b1f87e4a9e98f10b5ce00036d..6f0d90d4a541962e0ba289e5e2568da51d6445cb 100644 (file)
@@ -1453,7 +1453,7 @@ static int multipath_iterate_devices(struct dm_target *ti,
 
        list_for_each_entry(pg, &m->priority_groups, list) {
                list_for_each_entry(p, &pg->pgpaths, list) {
-                       ret = fn(ti, p->path.dev, ti->begin, data);
+                       ret = fn(ti, p->path.dev, ti->begin, ti->len, data);
                        if (ret)
                                goto out;
                }
index 42a3e4341d60347f5abfaa57af0e6456879b347c..9726577cde493f2ca21b7fd28386d1d2a31c8786 100644 (file)
@@ -1293,7 +1293,7 @@ static int mirror_iterate_devices(struct dm_target *ti,
 
        for (i = 0; !ret && i < ms->nr_mirrors; i++)
                ret = fn(ti, ms->mirror[i].dev,
-                        ms->mirror[i].offset, data);
+                        ms->mirror[i].offset, ti->len, data);
 
        return ret;
 }
index b240e85ae39aa4b444135b0a71823e35b03aac49..4e0e5937e42afc6f35274fc8856c3a8190cd1c20 100644 (file)
@@ -320,10 +320,11 @@ static int stripe_iterate_devices(struct dm_target *ti,
        int ret = 0;
        unsigned i = 0;
 
-       do
+       do {
                ret = fn(ti, sc->stripe[i].dev,
-                        sc->stripe[i].physical_start, data);
-       while (!ret && ++i < sc->stripes);
+                        sc->stripe[i].physical_start,
+                        sc->stripe_width, data);
+       } while (!ret && ++i < sc->stripes);
 
        return ret;
 }
index 5d16d06613aacb7cdc282c016f5c0c0367c67a61..d952b3441913a74b15c09f6ba7ea6237bd1e8aa0 100644 (file)
@@ -346,7 +346,7 @@ static void close_dev(struct dm_dev_internal *d, struct mapped_device *md)
  * If possible, this checks an area of a destination device is valid.
  */
 static int device_area_is_valid(struct dm_target *ti, struct dm_dev *dev,
-                               sector_t start, void *data)
+                               sector_t start, sector_t len, void *data)
 {
        struct queue_limits *limits = data;
        struct block_device *bdev = dev->bdev;
@@ -359,7 +359,7 @@ static int device_area_is_valid(struct dm_target *ti, struct dm_dev *dev,
        if (!dev_size)
                return 1;
 
-       if ((start >= dev_size) || (start + ti->len > dev_size)) {
+       if ((start >= dev_size) || (start + len > dev_size)) {
                DMWARN("%s: %s too small for target",
                       dm_device_name(ti->table->md), bdevname(bdev, b));
                return 0;
@@ -377,11 +377,11 @@ static int device_area_is_valid(struct dm_target *ti, struct dm_dev *dev,
                return 0;
        }
 
-       if (ti->len & (logical_block_size_sectors - 1)) {
+       if (len & (logical_block_size_sectors - 1)) {
                DMWARN("%s: len=%llu not aligned to h/w "
                       "logical block size %hu of %s",
                       dm_device_name(ti->table->md),
-                      (unsigned long long)ti->len,
+                      (unsigned long long)len,
                       limits->logical_block_size, bdevname(bdev, b));
                return 0;
        }
@@ -482,7 +482,7 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
 #define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r))
 
 int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
-                        sector_t start, void *data)
+                        sector_t start, sector_t len, void *data)
 {
        struct queue_limits *limits = data;
        struct block_device *bdev = dev->bdev;
index 0d6310657f32a41cc6f5af7150f13db9c35a51e7..655e7721580a450e93c8467316244a829cd5eace 100644 (file)
@@ -84,7 +84,7 @@ typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
 
 typedef int (*iterate_devices_callout_fn) (struct dm_target *ti,
                                           struct dm_dev *dev,
-                                          sector_t physical_start,
+                                          sector_t start, sector_t len,
                                           void *data);
 
 typedef int (*dm_iterate_devices_fn) (struct dm_target *ti,
@@ -104,7 +104,7 @@ void dm_error(const char *message);
  * Combine device limits.
  */
 int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
-                        sector_t start, void *data);
+                        sector_t start, sector_t len, void *data);
 
 struct dm_dev {
        struct block_device *bdev;