Use bio markers for request callback
Subsystems (3)
RFC PATCH 1/1 Use bio markers for request callback
Hi all,
this is a proposal for a different implementation of request callbacks. The existing ->endio callback of a request is actually a destructor function, to be called to terminate a request and free all structures.
However, on certain occasions (like request-based multipathing) it is desirable to have a callback function for a request which is called right after the request is finished, ie in end_that_request_first() before any bio->bi_endio callback is called.
So a simple solution for this is to clone the request and add a new 'marker' bio in front of the bio list of the request. This callback will be attached a structure in bi_private which keeps a pointer to the cloned and the original request, thus serving as a callback for the request itself.
Proposed patch attached. As usual comments are welcome.
Cheers,
Hannes
block/ll_rw_blk.c +2 -2
@@ -40,7 +40,6 @@ static void blk_unplug_work(struct work_struct *work);static void blk_unplug_timeout (unsigned long data);static void drive_stat_acct (struct request *rq,int nr_sectors,int new_io);static void init_request_from_bio (struct request *req,struct bio *bio); -static int __make_request (struct request_queue *q,struct bio *bio);static struct io_context *current_io_context (gfp_t gfp_flags,int node);/*
@@ -2912,7 +2911,7 @@ static void init_request_from_bio(struct request *req, struct bio *bio) req->start_time = jiffies; } -static int __make_request (struct request_queue *q,struct bio *bio) +int __make_request (struct request_queue *q,struct bio *bio) {struct request *req;int el_ret, nr_sectors, barrier, err;
@@ -3030,6 +3029,7 @@ end_io:bio_endio (bio, nr_sectors <<9 , err);return 0 ; } +EXPORT_SYMBOL (__make_request);/* * If bio->bi_dev is a partition, remap the location
drivers/md/dm-mpath.c +107 -59
316 lines not on this page · raw message
drivers/md/dm-path-selector.h +4 -1
@@ -75,7 +75,10 @@ struct path_selector_type {int (*status) (struct path_selector *ps,struct dm_path *path,status_type_t type,char *result,unsigned int maxlen); -int (*end_io) (struct path_selector *ps,struct dm_path *path); +int (*start_io) (struct path_selector *ps,struct dm_path *path, +struct request *clone); +int (*end_io) (struct path_selector *ps,struct dm_path *path, +struct request *clone); };/* Register a path selector */
drivers/md/dm-rq-record.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2007 NEC Corporation. +* +* This file is released under the GPL. +*/ + +#ifndef DM_RQ_RECORD_H +#define DM_RQ_RECORD_H + +#include <linux/blkdev.h> + +/* +* There are lots of mutable fields in the request struct that get +* changed by the lower levels of the block layer. Some targets, +* such as multipath, may wish to resubmit a request on error. The +* functions in this file help the target record and restore the +* original request state. +*/ +struct dm_rq_details { +unsigned int cmd_flags; +int ref_count; +}; + +static inline void dm_rq_record (struct dm_rq_details *rd,struct request *rq) +{ + rd->cmd_flags = rq->cmd_flags; + rd->ref_count = rq->ref_count; +} + +static inline void dm_rq_restore (struct dm_rq_details *rd,struct request *rq) +{ + rq->cmd_flags = rd->cmd_flags; + rq->ref_count = rd->ref_count; +} + +#endif
drivers/md/dm-table.c +24 -0
@@ -1033,6 +1033,28 @@ struct mapped_device *dm_table_get_md(struct dm_table *t)return t->md; } +int dm_table_enable_elevator (struct dm_table *t) +{ +struct mapped_device *md =dm_table_get_md (t); + +if (!md) +return 1 ; + +if (dm_enable_elevator (md)) { +dm_put (md); +return 1 ; + } +dm_put (md); + +return 0 ; +} + +void dm_table_disable_elevator (struct dm_table *t) +{ +/* No reference taken */ +dm_disable_elevator (t->md); +} +EXPORT_SYMBOL (dm_vcalloc);EXPORT_SYMBOL (dm_get_device);EXPORT_SYMBOL (dm_put_device);
@@ -1044,3 +1066,5 @@ EXPORT_SYMBOL(dm_table_put);EXPORT_SYMBOL (dm_table_get);EXPORT_SYMBOL (dm_table_unplug_all);EXPORT_SYMBOL (dm_table_flush_all); +EXPORT_SYMBOL (dm_table_enable_elevator); +EXPORT_SYMBOL (dm_table_disable_elevator);
drivers/md/dm.c +533 -18
739 lines not on this page · raw message
drivers/md/dm.h +7 -0
@@ -112,6 +112,8 @@ int dm_table_resume_targets(struct dm_table *t);int dm_table_any_congested (struct dm_table *t,int bdi_bits);void dm_table_unplug_all (struct dm_table *t);int dm_table_flush_all (struct dm_table *t); +int dm_table_enable_elevator (struct dm_table *t); +void dm_table_disable_elevator (struct dm_table *t);/*----------------------------------------------------------------- * A registry of target types.
@@ -182,5 +184,10 @@ void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);union map_info *dm_get_mapinfo (struct bio *bio);int dm_open_count (struct mapped_device *md);int dm_lock_for_deletion (struct mapped_device *md); +void dm_dispatch_request (struct request_queue *q,struct request *rq); +int dm_enable_elevator (struct mapped_device *md); +void dm_disable_elevator (struct mapped_device *md); +struct request_queue *dm_get_queue (struct mapped_device *md); +void dm_put_queue (struct request_queue *q);#endif
include/linux/bio.h +2 -0
@@ -152,6 +152,7 @@ struct bio {#define BIO_RW_FAILFAST 3#define BIO_RW_SYNC 4#define BIO_RW_META 5 +#define BIO_RW_RQCALLBACK 6/* Request callback */ /* * upper 16 bits of bi_rw define the io priority of this bio
@@ -183,6 +184,7 @@ struct bio {#define bio_failfast (bio) ((bio)->bi_rw & (1 << BIO_RW_FAILFAST))#define bio_rw_ahead (bio) ((bio)->bi_rw & (1 << BIO_RW_AHEAD))#define bio_rw_meta (bio) ((bio)->bi_rw & (1 << BIO_RW_META)) +#define bio_rq_callback (bio) ((bio)->bi_rw & (1 << BIO_RW_RQCALLBACK))/* * will die
include/linux/blkdev.h +1 -0
@@ -647,6 +647,7 @@ extern void register_disk(struct gendisk *dev);extern void generic_make_request (struct bio *bio);extern void blk_put_request (struct request *);extern void __blk_put_request (struct request_queue *,struct request *); +extern int __make_request (struct request_queue *q,struct bio *bio);extern void blk_end_sync_rq (struct request *rq,int error);extern struct request *blk_get_request (struct request_queue *,int ,gfp_t );extern void blk_insert_request (struct request_queue *,struct request *,int ,void *);
include/linux/device-mapper.h +20 -0
@@ -14,6 +14,7 @@ struct dm_target;struct dm_table ;struct dm_dev ;struct mapped_device ; +struct request ;typedef enum {STATUSTYPE_INFO ,STATUSTYPE_TABLE }status_type_t ;
@@ -45,6 +46,9 @@ typedef void (*dm_dtr_fn) (struct dm_target *ti);typedef int (*dm_map_fn ) (struct dm_target *ti,struct bio *bio,union map_info *map_context); +typedef int (*dm_map_request_fn ) (struct dm_target *ti,struct request *clone, +union map_info *map_context); +/* * Returns: * < 0 : error (currently ignored)
@@ -57,6 +61,18 @@ typedef int (*dm_endio_fn) (struct dm_target *ti, struct bio *bio, int error, union map_info *map_context); +typedef int (*dm_request_endio_first_fn ) (struct dm_target *ti, +struct request *clone,int error, +union map_info *map_context); + +typedef int (*dm_request_endio_fn ) (struct dm_target *ti, +struct request *clone,int error, +union map_info *map_context); + +typedef void (*dm_request_queue_in_tgt_fn ) (struct dm_target *ti, +struct request *clone, +union map_info *map_context); +typedef void (*dm_flush_fn ) (struct dm_target *ti);typedef void (*dm_presuspend_fn ) (struct dm_target *ti);typedef void (*dm_postsuspend_fn ) (struct dm_target *ti);
@@ -98,7 +114,11 @@ struct target_type {dm_ctr_fn ctr;dm_dtr_fn dtr;dm_map_fn map; +dm_map_request_fn map_rq;dm_endio_fn end_io; +dm_request_endio_first_fn rq_end_io_first; +dm_request_endio_fn rq_end_io; +dm_request_queue_in_tgt_fn queue_in_tgt;dm_flush_fn flush;dm_presuspend_fn presuspend;dm_postsuspend_fn postsuspend;
Quoted 11 lines · Hannes Reinecke
Hi all,
this is a proposal for a different implementation of request callbacks. The existing ->endio callback of a request is actually a destructor function, to be called to terminate a request and free all structures.
However, on certain occasions (like request-based multipathing) it is desirable to have a callback function for a request which is called right after the request is finished, ie in
end_that_request_first()before anybio->bi_endiocallback is called.
Quoted 6 lines
So a simple solution for this is to clone the request and add a new 'marker' bio in front of the bio list of the request. This callback will be attached a structure in
bi_privatewhich keeps a pointer to the cloned and the original request, thus serving as a callback for the request itself.Proposed patch attached. As usual comments are welcome.
Honestly, I think this approach is a much worse design than the NEC callback option. Exporting __make_request() (which is an INTERNAL function) aside, this looks like one big hack with pseudo bio attached to front of list, the enable/disable elevator stuff (does that even work on stacked devices?).
Signature · 1 line
Jens Axboe
Am Tue 11 Sep 2007 01:11:34 PM CEST schrieb Jens Axboe <[email protected]>:
Quoted 17 lines · Hannes Reinecke
Quoted 16 lines
Hi all,
this is a proposal for a different implementation of request callbacks. The existing ->endio callback of a request is actually a destructor function, to be called to terminate a request and free all structures.
However, on certain occasions (like request-based multipathing) it is desirable to have a callback function for a request which is called right after the request is finished, ie in
end_that_request_first()before anybio->bi_endiocallback is called.So a simple solution for this is to clone the request and add a new 'marker' bio in front of the bio list of the request. This callback will be attached a structure in
bi_privatewhich keeps a pointer to the cloned and the original request, thus serving as a callback for the request itself.
Quoted 8 lines
Quoted 1 line
Proposed patch attached. As usual comments are welcome.
Honestly, I think this approach is a much worse design than the NEC callback option. Exporting
__make_request()(which is an INTERNAL function) aside, this looks like one big hack with pseudo bio attached to front of list, the enable/disable elevator stuff (does that even work on stacked devices?).
Hmm; agreed. Main reason for the patch was to show an alternative. Having callbacks within callbacks is not the most straightforward way. But if you're okay with it: you're the maintainer, you get to decide.
Exporting __make_request() is just for enabling elevator support based on the target type. Of course this can be done differently.
Main point here was the marker bio idea. If that's rejected everything else is moot to discuss.
Cheers,
Hannes
---
No .sig today, my .message went away ...
Hi Hannes,
Quoted 10 lines · Hannes Reinecke
this is a proposal for a different implementation of request callbacks. The existing ->endio callback of a request is actually a destructor function, to be called to terminate a request and free all structures.
However, on certain occasions (like request-based multipathing) it is desirable to have a callback function for a request which is called right after the request is finished, ie in
end_that_request_first()before anybio->bi_endiocallback is called.
Quoted 5 lines
So a simple solution for this is to clone the request and add a new 'marker' bio in front of the bio list of the request. This callback will be attached a structure in
bi_privatewhich keeps a pointer to the cloned and the original request, thus serving as a callback for the request itself.
Thank you for another idea for request-based multipath.
However, I disagree with the idea.
I think the design (bio->bi_end_io() completes a request) is complex a little bit and is breaking layer stacking.
Also, I think that the design of completion handling by 2 hooks, bio->bi_end_io() and rq->end_io(), makes error handing in dm-multipath complex.
e.g. Even if we detect an error on the first bio->bi_end_io() hook,
the request can't be retried until the second rq->end_io() hook is called, because the ownership of the request is still on low level drivers until the low level driver calls end_that_request_last().
Although this is just implementation issue, I think that the patch can't handle leftover.
SCSI, scsi_end_request(), may have some leftovers in the request. Then, the marker bio is freed in bio->bi_end_io() and the request is resubmitted in SCSI level. So the resubmitted request doesn't have the marker bio any more.
Thanks,
Kiyoshi Ueda