Commit 32fab448e5e86694beade415e750363538ea5f49
Committed by
Jens Axboe
1 parent
e3335de940
Exists in
master
and in
7 other branches
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>
Showing 2 changed files with 50 additions and 9 deletions Side-by-side Diff
block/blk-core.c
... | ... | @@ -1806,6 +1806,22 @@ |
1806 | 1806 | } |
1807 | 1807 | EXPORT_SYMBOL(end_request); |
1808 | 1808 | |
1809 | +static 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 | 1826 | * blk_end_io - Generic end_io function to complete a request. |
1811 | 1827 | * @rq: the request being processed |
1812 | 1828 | |
... | ... | @@ -1832,16 +1848,9 @@ |
1832 | 1848 | struct request_queue *q = rq->q; |
1833 | 1849 | unsigned long flags = 0UL; |
1834 | 1850 | |
1835 | - if (rq->bio) { | |
1836 | - if (__end_that_request_first(rq, error, nr_bytes)) | |
1837 | - return 1; | |
1851 | + if (end_that_request_data(rq, error, nr_bytes, bidi_bytes)) | |
1852 | + return 1; | |
1838 | 1853 | |
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 | - | |
1845 | 1854 | /* Special feature for tricky drivers */ |
1846 | 1855 | if (drv_callback && drv_callback(rq)) |
1847 | 1856 | return 1; |
... | ... | @@ -1921,6 +1930,36 @@ |
1921 | 1930 | return blk_end_io(rq, error, nr_bytes, bidi_bytes, NULL); |
1922 | 1931 | } |
1923 | 1932 | EXPORT_SYMBOL_GPL(blk_end_bidi_request); |
1933 | + | |
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 | + */ | |
1949 | +void 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 | +} | |
1962 | +EXPORT_SYMBOL_GPL(blk_update_request); | |
1924 | 1963 | |
1925 | 1964 | /** |
1926 | 1965 | * blk_end_request_callback - Special helper function for tricky drivers |
include/linux/blkdev.h
... | ... | @@ -791,6 +791,8 @@ |
791 | 791 | extern void __blk_complete_request(struct request *); |
792 | 792 | extern void blk_abort_request(struct request *); |
793 | 793 | extern void blk_abort_queue(struct request_queue *); |
794 | +extern void blk_update_request(struct request *rq, int error, | |
795 | + unsigned int nr_bytes); | |
794 | 796 | |
795 | 797 | /* |
796 | 798 | * blk_end_request() takes bytes instead of sectors as a complete size. |