dm: introduce target_type method .iterate_devices
RFC PATCH 1/2 dm: introduce target_type method .iterate_devices
Added .iterate_devices to 'struct target_type' to allow a function to be called for all devices in a DM target. Implemented it for both the linear and stripe targets.
Once I get confirmation that this infrastructure looks reasonable I'll implement .iterate_devices for the remaining targets.
I've not yet bumped each target_type's .version but I assume I need to given the introduction of a new method.
--- drivers/md/dm-linear.c | 8 ++++++++ drivers/md/dm-stripe.c | 21 +++++++++++++++++++++ include/linux/device-mapper.h | 11 +++++++++++ 3 files changed, 40 insertions(+)
drivers/md/dm-linear.c +8 -0
@@ -132,6 +132,13 @@ static int linear_merge(struct dm_targetreturn min (max_size, q->merge_bvec_fn (q, bvm, biovec)); } +static int linear_iterate_devices (struct dm_target *ti, +iterate_devices_callout_fn fn,void *data) +{ +struct linear_c *lc = (struct linear_c *) ti->private; +return (fn ?fn (ti, lc->dev, lc->start, data) :0 ); +} +static struct target_type linear_target = { .name ="linear" , .version= {1 ,0 ,3 },
@@ -142,6 +149,7 @@ static struct target_type linear_target .status = linear_status, .ioctl = linear_ioctl, .merge = linear_merge, + .iterate_devices = linear_iterate_devices, };int __init dm_linear_init (void )
include/linux/device-mapper.h +11 -0
@@ -11,6 +11,7 @@#include <linux/bio.h> #include <linux/blkdev.h> +struct dm_dev ;struct dm_target ;struct dm_table ;struct mapped_device ;
@@ -87,6 +88,15 @@ typedef int (*dm_merge_fn) (struct dm_ta*/ typedef int (*dm_busy_fn ) (struct dm_target *ti); +typedef int (*iterate_devices_callout_fn ) (struct dm_target *ti, +struct dm_dev *dev, +sector_t physical_start, +void *data); + +typedef int (*dm_iterate_devices_fn ) (struct dm_target *ti, +iterate_devices_callout_fn fn, +void *data); +void dm_error (const char *message);/*
@@ -138,6 +148,7 @@ struct target_type {dm_ioctl_fn ioctl;dm_merge_fn merge;dm_busy_fn busy; +dm_iterate_devices_fn iterate_devices;/* For internal device-mapper use. */ struct list_head list;
drivers/md/dm-stripe.c +21 -0
@@ -304,6 +304,26 @@ static int stripe_end_io(struct dm_targereturn error; } +static int stripe_iterate_devices (struct dm_target *ti, +iterate_devices_callout_fn fn,void *data) +{ +unsigned i; +struct stripe_c *sc = (struct stripe_c *) ti->private; +int ret =0 ; + +if (!fn) +return ret; + +for (i =0 ; i < sc->stripes; i++) { + ret =fn (ti, sc->stripe[i].dev, + sc->stripe[i].physical_start, data); +if (ret) +break ; + } + +return ret; +} +static struct target_type stripe_target = { .name ="striped" , .version = {1 ,1 ,0 },
@@ -313,6 +333,7 @@ static struct target_type stripe_target .map = stripe_map, .end_io = stripe_end_io, .status = stripe_status, + .iterate_devices = stripe_iterate_devices, };int __init dm_stripe_init (void )
RFC PATCH 2/2 dm: establish queue limits just before table resume
Initialization and validation of a DM device's queue_limits is now done just before dm_swap_table() discards the previous table. Doing so allows for the limits to be properly calculated (relative to other DM tables that may have also been loaded in the same transaction). This eliminates a restriction that was inadvertantly introduced on userspace (e.g. LVM2) relative to having to resume devices that a new device was dependent on for it's table load.
The 'limits' (struct queue_limits) member has been removed from both the dm_table and dm_target structures (reducing DM's memory consumption).
The dm-log.c changes highlight the somewhat awkward nature of not having queue_limits be a member of 'struct dm_target'. The same pattern, recalculating the target's queue_limits, is also used in various places in dm-table.c.
dm-table.c:dm_set_device_limits now passes the 'start' of the device's data area (aka pe_start) as the 'offset' to blk_stack_limits().
init_valid_queue_limits() was removed in favor of Martin Petersen's pending blk_set_default_limits().
--- drivers/md/dm-log.c | 12 ++ drivers/md/dm-table.c | 188 +++++++++++++++++++++++------------------- drivers/md/dm.c | 12 ++ drivers/md/dm.h | 4 include/linux/device-mapper.h | 9 -- 5 files changed, 130 insertions(+), 95 deletions(-)
drivers/md/dm.c +9 -3
@@ -1255,7 +1255,8 @@ static void __set_size(struct mapped_devmutex_unlock (&md->suspended_bdev->bd_inode->i_mutex); } -static int __bind (struct mapped_device *md,struct dm_table *t) +static int __bind (struct mapped_device *md,struct dm_table *t, +struct queue_limits *limits) {struct request_queue *q = md->queue;sector_t size;
@@ -1280,7 +1281,7 @@ static int __bind(struct mapped_device *write_lock (&md->map_lock); md->map = t; -dm_table_set_restrictions (t, q); +dm_table_set_restrictions (t, q, limits);write_unlock (&md->map_lock);return 0 ;
@@ -1503,6 +1504,7 @@ static void dm_queue_flush(struct mapped*/ int dm_swap_table (struct mapped_device *md,struct dm_table *table) { +struct queue_limits limits;int r = -EINVAL ;mutex_lock (&md->suspend_lock);
@@ -1516,8 +1518,12 @@ int dm_swap_table(struct mapped_device *if (get_capacity (md->disk) !=dm_table_get_size (table)) goto out; + r =dm_set_limits (table, &limits); +if (r) + goto out; +__unbind (md); - r =__bind (md, table); + r =__bind (md, table, &limits); out:mutex_unlock (&md->suspend_lock);
drivers/md/dm-table.c +105 -83
318 lines not on this page · raw message
include/linux/device-mapper.h +2 -7
@@ -102,7 +102,8 @@ void dm_error(const char *message);/* * Combine device limits. */ -void dm_set_device_limits (struct dm_target *ti,struct block_device *bdev); +int dm_set_device_limits (struct dm_target *ti,struct dm_dev *dev, +sector_t start,void *data);struct dm_dev {struct block_device *bdev;
@@ -166,12 +167,6 @@ struct dm_target {/* Always a power of 2 */ sector_t split_io; -/* -* These are automatically filled in by -* dm_table_get_device. -*/ -struct queue_limits limits; -/* target specific data */ void *private;
drivers/md/dm.h +3 -1
@@ -41,7 +41,9 @@ void dm_table_event_callback(struct dm_t void (*fn)(void *), void *context);struct dm_target *dm_table_get_target (struct dm_table *t,unsigned int index);struct dm_target *dm_table_find_target (struct dm_table *t,sector_t sector); -void dm_table_set_restrictions (struct dm_table *t,struct request_queue *q); +int dm_set_limits (struct dm_table *table,struct queue_limits *limits); +void dm_table_set_restrictions (struct dm_table *t,struct request_queue *q, +struct queue_limits *limits);struct list_head *dm_table_get_devices (struct dm_table *t);void dm_table_presuspend_targets (struct dm_table *t);void dm_table_postsuspend_targets (struct dm_table *t);
drivers/md/dm-log.c +11 -1
@@ -343,6 +343,7 @@ static int create_log_context(struct dm_struct log_c *lc;uint32_t region_size;unsigned int region_count; +struct queue_limits ti_limits;size_t bitset_size, buf_size;int r;
@@ -410,11 +411,20 @@ static int create_log_context(struct dm_ lc->header_location.sector =0 ;/* +* combine all target devices' limits +* - limits are recalculated rather than stored in target +*/ +blk_set_default_limits (&ti_limits); +if (ti->type->iterate_devices) + ti->type->iterate_devices (ti, dm_set_device_limits, + &ti_limits); + +/* * Buffer holds both header and bitset. */ buf_size =dm_round_up ((LOG_OFFSET <<SECTOR_SHIFT ) + bitset_size, - ti->limits.logical_block_size); + ti_limits.logical_block_size);if (buf_size >i_size_read (dev->bdev->bd_inode)) { DMWARN("log device %s too small: need %llu bytes",
Re: [RFC][PATCH 2/2] dm: establish queue limits just before table resume
Quoted 25 lines · Mike Snitzer
Initialization and validation of a DM device's
queue_limitsis now done just beforedm_swap_table()discards the previous table. Doing so allows for the limits to be properly calculated (relative to other DM tables that may have also been loaded in the same transaction). This eliminates a restriction that was inadvertantly introduced on userspace (e.g. LVM2) relative to having to resume devices that a new device was dependent on for it's table load.The 'limits' (struct
queue_limits) member has been removed from both thedm_tableanddm_targetstructures (reducing DM's memory consumption).The
dm-log.cchanges highlight the somewhat awkward nature of not havingqueue_limitsbe a member of 'structdm_target'. The same pattern, recalculating the target'squeue_limits, is also used in various places indm-table.c.dm-table.c:dm_set_device_limits now passes the 'start' of the device's data area (aka
pe_start) as the 'offset' toblk_stack_limits().
init_valid_queue_limits()was removed in favor of Martin Petersen's pendingblk_set_default_limits().
Quoted 7 lines
--- drivers/md/dm-log.c | 12 ++ drivers/md/dm-table.c | 188 +++++++++++++++++++++++------------------- drivers/md/dm.c | 12 ++ drivers/md/dm.h | 4 include/linux/device-mapper.h | 9 -- 5 files changed, 130 insertions(+), 95 deletions(-)
Alasdair,
I've tested the patches to work as expected _after_ applying the following small fixup patch. I'll hold off on sending out updated "final" patches until share how you think things look. In the meantime I'll work on implementing .iterate_devices for all the other targets.
Mike
drivers/md/dm-table.c +2 -3
@@ -889,7 +889,6 @@ int dm_set_limits(struct dm_table *table, struct queue_limits *limits)while (i <dm_table_get_num_targets (table)) {struct queue_limits ti_limits; -blk_set_default_limits (&ti_limits); ti =dm_table_get_target (table, i++);
@@ -906,8 +905,8 @@ int dm_set_limits(struct dm_table *table, struct queue_limits *limits)* the top-level limits because they are needed * to validate the target's device area */ -if (ti->type->iterate_devices (ti, device_area_is_valid, - &ti_limits) !=0 ) +if (!ti->type->iterate_devices (ti, device_area_is_valid, + &ti_limits)) goto out;/* combine target's limits into table's limits */
include/linux/device-mapper.h +0 -1
@@ -163,7 +163,6 @@ struct dm_target {sector_t begin;sector_t len; -/* FIXME: turn this into a mask, and merge with queue_limits */ /* Always a power of 2 */ sector_t split_io;