aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorKiyoshi Ueda <k-ueda@ct.jp.nec.com>2008-09-18 10:45:09 -0400
committerJens Axboe <jens.axboe@oracle.com>2008-10-09 02:56:18 -0400
commit32fab448e5e86694beade415e750363538ea5f49 (patch)
tree6eab6189afba893c302fa6acca1a89406fd620c6 /block
parente3335de94067dbebe22e3962632ead34e832cb60 (diff)
block: add request update interface
This patch adds blk_update_request(), which updates struct request with completing its data part, but doesn't complete the struct request itself. Though it looks like end_that_request_first() of older kernels, blk_update_request() should be used only by request stacking drivers. Request-based dm will use it in bio->bi_end_io callback to update the original request when a data part of a cloned request completes. Followings are additional background information of why request-based dm needs this interface. - Request stacking drivers can't use blk_end_request() directly from the lower driver's completion context (bio->bi_end_io or rq->end_io), because some device drivers (e.g. ide) may try to complete their request with queue lock held, and it may cause deadlock. See below for detailed description of possible deadlock: <http://marc.info/?l=linux-kernel&m=120311479108569&w=2> - To solve that, request-based dm offloads the completion of cloned struct request to softirq context (i.e. using blk_complete_request() from rq->end_io). - Though it is possible to use the same solution from bio->bi_end_io, it will delay the notification of bio completion to the original submitter. Also, it will cause inefficient partial completion, because the lower driver can't perform the cloned request anymore and request-based dm needs to requeue and redispatch it to the lower driver again later. That's not good. - So request-based dm needs blk_update_request() to perform the bio completion in the lower driver's completion context, which is more efficient. Signed-off-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com> Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'block')
-rw-r--r--block/blk-core.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index 37fba001bdcf..527d43e982bb 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1806,6 +1806,22 @@ void end_request(struct request *req, int uptodate)
1806} 1806}
1807EXPORT_SYMBOL(end_request); 1807EXPORT_SYMBOL(end_request);
1808 1808
1809static int end_that_request_data(struct request *rq, int error,
1810 unsigned int nr_bytes, unsigned int bidi_bytes)
1811{
1812 if (rq->bio) {
1813 if (__end_that_request_first(rq, error, nr_bytes))
1814 return 1;
1815
1816 /* Bidi request must be completed as a whole */
1817 if (blk_bidi_rq(rq) &&
1818 __end_that_request_first(rq->next_rq, error, bidi_bytes))
1819 return 1;
1820 }
1821
1822 return 0;
1823}
1824
1809/** 1825/**
1810 * blk_end_io - Generic end_io function to complete a request. 1826 * blk_end_io - Generic end_io function to complete a request.
1811 * @rq: the request being processed 1827 * @rq: the request being processed
@@ -1832,15 +1848,8 @@ static int blk_end_io(struct request *rq, int error, unsigned int nr_bytes,
1832 struct request_queue *q = rq->q; 1848 struct request_queue *q = rq->q;
1833 unsigned long flags = 0UL; 1849 unsigned long flags = 0UL;
1834 1850
1835 if (rq->bio) { 1851 if (end_that_request_data(rq, error, nr_bytes, bidi_bytes))
1836 if (__end_that_request_first(rq, error, nr_bytes)) 1852 return 1;
1837 return 1;
1838
1839 /* Bidi request must be completed as a whole */
1840 if (blk_bidi_rq(rq) &&
1841 __end_that_request_first(rq->next_rq, error, bidi_bytes))
1842 return 1;
1843 }
1844 1853
1845 /* Special feature for tricky drivers */ 1854 /* Special feature for tricky drivers */
1846 if (drv_callback && drv_callback(rq)) 1855 if (drv_callback && drv_callback(rq))
@@ -1923,6 +1932,36 @@ int blk_end_bidi_request(struct request *rq, int error, unsigned int nr_bytes,
1923EXPORT_SYMBOL_GPL(blk_end_bidi_request); 1932EXPORT_SYMBOL_GPL(blk_end_bidi_request);
1924 1933
1925/** 1934/**
1935 * blk_update_request - Special helper function for request stacking drivers
1936 * @rq: the request being processed
1937 * @error: %0 for success, < %0 for error
1938 * @nr_bytes: number of bytes to complete @rq
1939 *
1940 * Description:
1941 * Ends I/O on a number of bytes attached to @rq, but doesn't complete
1942 * the request structure even if @rq doesn't have leftover.
1943 * If @rq has leftover, sets it up for the next range of segments.
1944 *
1945 * This special helper function is only for request stacking drivers
1946 * (e.g. request-based dm) so that they can handle partial completion.
1947 * Actual device drivers should use blk_end_request instead.
1948 */
1949void blk_update_request(struct request *rq, int error, unsigned int nr_bytes)
1950{
1951 if (!end_that_request_data(rq, error, nr_bytes, 0)) {
1952 /*
1953 * These members are not updated in end_that_request_data()
1954 * when all bios are completed.
1955 * Update them so that the request stacking driver can find
1956 * how many bytes remain in the request later.
1957 */
1958 rq->nr_sectors = rq->hard_nr_sectors = 0;
1959 rq->current_nr_sectors = rq->hard_cur_sectors = 0;
1960 }
1961}
1962EXPORT_SYMBOL_GPL(blk_update_request);
1963
1964/**
1926 * blk_end_request_callback - Special helper function for tricky drivers 1965 * blk_end_request_callback - Special helper function for tricky drivers
1927 * @rq: the request being processed 1966 * @rq: the request being processed
1928 * @error: %0 for success, < %0 for error 1967 * @error: %0 for success, < %0 for error