aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--block/blk-core.c57
-rw-r--r--include/linux/blkdev.h2
2 files changed, 50 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
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index e23b838825bd..e82a84c9f37a 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -791,6 +791,8 @@ extern void blk_complete_request(struct request *);
791extern void __blk_complete_request(struct request *); 791extern void __blk_complete_request(struct request *);
792extern void blk_abort_request(struct request *); 792extern void blk_abort_request(struct request *);
793extern void blk_abort_queue(struct request_queue *); 793extern void blk_abort_queue(struct request_queue *);
794extern void blk_update_request(struct request *rq, int error,
795 unsigned int nr_bytes);
794 796
795/* 797/*
796 * blk_end_request() takes bytes instead of sectors as a complete size. 798 * blk_end_request() takes bytes instead of sectors as a complete size.