diff options
author | Mike Snitzer <snitzer@redhat.com> | 2009-05-15 09:12:34 +1000 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2009-05-15 09:12:34 +1000 |
commit | cc1018ae8a413b595a1f0f822928dd9e81a75e59 (patch) | |
tree | a447e574d19f2aac467b9ef3dff7c018f0fac317 /drivers/md/dm-table.c | |
parent | 7c83ff0fa05e1db5ed1c3a0753e7bf71f1380f42 (diff) |
dm-table-ensure-targets-are-aligned-to-hardsect_size
Ensure I/O is aligned to the hardware sector size of target devices.
Rename check_device_area() to device_area_is_valid() for clarity and
establish the device limits including the hardware sector size prior to
calling it.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md/dm-table.c')
-rw-r--r-- | drivers/md/dm-table.c | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 429b50b975d5..77da472cdb61 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -384,15 +384,42 @@ 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 check_device_area(struct dm_dev_internal *dd, sector_t start, - sector_t len) +static int device_area_is_valid(struct dm_target *ti, struct block_device *bdev, + sector_t start, sector_t len) { - sector_t dev_size = dd->dm_dev.bdev->bd_inode->i_size >> SECTOR_SHIFT; + sector_t dev_size = bdev->bd_inode->i_size >> SECTOR_SHIFT; + unsigned short hardsect_size_sectors = ti->limits.hardsect_size >> + SECTOR_SHIFT; + char b[BDEVNAME_SIZE]; if (!dev_size) return 1; - return ((start < dev_size) && (len <= (dev_size - start))); + 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; + } + + if (hardsect_size_sectors <= 1) + return 1; + + if (start & (hardsect_size_sectors - 1)) { + DMWARN("%s: start=%llu not aligned to h/w sector of %s", + dm_device_name(ti->table->md), + (unsigned long long)start, bdevname(bdev, b)); + return 0; + } + + if (len & (hardsect_size_sectors - 1)) { + DMWARN("%s: len=%llu not aligned to h/w sector size %hu of %s", + dm_device_name(ti->table->md), + (unsigned long long)len, + ti->limits.hardsect_size, bdevname(bdev, b)); + return 0; + } + + return 1; } /* @@ -478,14 +505,7 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti, } atomic_inc(&dd->count); - if (!check_device_area(dd, start, len)) { - DMWARN("device %s too small for target", path); - dm_put_device(ti, &dd->dm_dev); - return -EINVAL; - } - *result = &dd->dm_dev; - return 0; } @@ -553,8 +573,16 @@ int dm_get_device(struct dm_target *ti, const char *path, sector_t start, int r = __table_get_device(ti->table, ti, path, start, len, mode, result); - if (!r) - dm_set_device_limits(ti, (*result)->bdev); + if (r) + return r; + + dm_set_device_limits(ti, (*result)->bdev); + + if (!device_area_is_valid(ti, (*result)->bdev, start, len)) { + dm_put_device(ti, *result); + *result = NULL; + return -EINVAL; + } return r; } |