diff options
author | Tejun Heo <tj@kernel.org> | 2009-04-22 22:05:18 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2009-04-28 01:37:35 -0400 |
commit | 2e60e02297cf54e367567f2d85b2ca56b1c4a906 (patch) | |
tree | ea824afcaff58be894799a011f74d80c3560f372 /include/linux/blkdev.h | |
parent | 0b302d5aa7975006fa2ec3d66386610b9b36c669 (diff) |
block: clean up request completion API
Request completion has gone through several changes and became a bit
messy over the time. Clean it up.
1. end_that_request_data() is a thin wrapper around
end_that_request_data_first() which checks whether bio is NULL
before doing anything and handles bidi completion.
blk_update_request() is a thin wrapper around
end_that_request_data() which clears nr_sectors on the last
iteration but doesn't use the bidi completion.
Clean it up by moving the initial bio NULL check and nr_sectors
clearing on the last iteration into end_that_request_data() and
renaming it to blk_update_request(), which makes blk_end_io() the
only user of end_that_request_data(). Collapse
end_that_request_data() into blk_end_io().
2. There are four visible completion variants - blk_end_request(),
__blk_end_request(), blk_end_bidi_request() and end_request().
blk_end_request() and blk_end_bidi_request() uses blk_end_request()
as the backend but __blk_end_request() and end_request() use
separate implementation in __blk_end_request() due to different
locking rules.
blk_end_bidi_request() is identical to blk_end_io(). Collapse
blk_end_io() into blk_end_bidi_request(), separate out request
update into internal helper blk_update_bidi_request() and add
__blk_end_bidi_request(). Redefine [__]blk_end_request() as thin
inline wrappers around [__]blk_end_bidi_request().
3. As the whole request issue/completion usages are about to be
modified and audited, it's a good chance to convert completion
functions return bool which better indicates the intended meaning
of return values.
4. The function name end_that_request_last() is from the days when it
was a public interface and slighly confusing. Give it a proper
internal name - blk_finish_request().
5. Add description explaning that blk_end_bidi_request() can be safely
used for uni requests as suggested by Boaz Harrosh.
The only visible behavior change is from #1. nr_sectors counts are
cleared after the final iteration no matter which function is used to
complete the request. I couldn't find any place where the code
assumes those nr_sectors counters contain the values for the last
segment and this change is good as it makes the API much more
consistent as the end result is now same whether a request is
completed using [__]blk_end_request() alone or in combination with
blk_update_request().
API further cleaned up per Christoph's suggestion.
[ Impact: cleanup, rq->*nr_sectors always updated after req completion ]
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Boaz Harrosh <bharrosh@panasas.com>
Cc: Christoph Hellwig <hch@infradead.org>
Diffstat (limited to 'include/linux/blkdev.h')
-rw-r--r-- | include/linux/blkdev.h | 94 |
1 files changed, 82 insertions, 12 deletions
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 1fa9dcf9aa6a..501f6845cc73 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h | |||
@@ -840,27 +840,97 @@ extern unsigned int blk_rq_bytes(struct request *rq); | |||
840 | extern unsigned int blk_rq_cur_bytes(struct request *rq); | 840 | extern unsigned int blk_rq_cur_bytes(struct request *rq); |
841 | 841 | ||
842 | /* | 842 | /* |
843 | * blk_end_request() and friends. | 843 | * Request completion related functions. |
844 | * __blk_end_request() and end_request() must be called with | 844 | * |
845 | * the request queue spinlock acquired. | 845 | * blk_update_request() completes given number of bytes and updates |
846 | * the request without completing it. | ||
847 | * | ||
848 | * blk_end_request() and friends. __blk_end_request() and | ||
849 | * end_request() must be called with the request queue spinlock | ||
850 | * acquired. | ||
846 | * | 851 | * |
847 | * Several drivers define their own end_request and call | 852 | * Several drivers define their own end_request and call |
848 | * blk_end_request() for parts of the original function. | 853 | * blk_end_request() for parts of the original function. |
849 | * This prevents code duplication in drivers. | 854 | * This prevents code duplication in drivers. |
850 | */ | 855 | */ |
851 | extern int blk_end_request(struct request *rq, int error, | 856 | extern bool blk_update_request(struct request *rq, int error, |
852 | unsigned int nr_bytes); | 857 | unsigned int nr_bytes); |
853 | extern int __blk_end_request(struct request *rq, int error, | 858 | extern bool blk_end_bidi_request(struct request *rq, int error, |
854 | unsigned int nr_bytes); | 859 | unsigned int nr_bytes, |
855 | extern int blk_end_bidi_request(struct request *rq, int error, | 860 | unsigned int bidi_bytes); |
856 | unsigned int nr_bytes, unsigned int bidi_bytes); | 861 | extern bool __blk_end_bidi_request(struct request *rq, int error, |
857 | extern void end_request(struct request *, int); | 862 | unsigned int nr_bytes, |
863 | unsigned int bidi_bytes); | ||
864 | |||
865 | /** | ||
866 | * blk_end_request - Helper function for drivers to complete the request. | ||
867 | * @rq: the request being processed | ||
868 | * @error: %0 for success, < %0 for error | ||
869 | * @nr_bytes: number of bytes to complete | ||
870 | * | ||
871 | * Description: | ||
872 | * Ends I/O on a number of bytes attached to @rq. | ||
873 | * If @rq has leftover, sets it up for the next range of segments. | ||
874 | * | ||
875 | * Return: | ||
876 | * %false - we are done with this request | ||
877 | * %true - still buffers pending for this request | ||
878 | **/ | ||
879 | static inline bool blk_end_request(struct request *rq, int error, | ||
880 | unsigned int nr_bytes) | ||
881 | { | ||
882 | return blk_end_bidi_request(rq, error, nr_bytes, 0); | ||
883 | } | ||
884 | |||
885 | /** | ||
886 | * __blk_end_request - Helper function for drivers to complete the request. | ||
887 | * @rq: the request being processed | ||
888 | * @error: %0 for success, < %0 for error | ||
889 | * @nr_bytes: number of bytes to complete | ||
890 | * | ||
891 | * Description: | ||
892 | * Must be called with queue lock held unlike blk_end_request(). | ||
893 | * | ||
894 | * Return: | ||
895 | * %false - we are done with this request | ||
896 | * %true - still buffers pending for this request | ||
897 | **/ | ||
898 | static inline bool __blk_end_request(struct request *rq, int error, | ||
899 | unsigned int nr_bytes) | ||
900 | { | ||
901 | return __blk_end_bidi_request(rq, error, nr_bytes, 0); | ||
902 | } | ||
903 | |||
904 | /** | ||
905 | * end_request - end I/O on the current segment of the request | ||
906 | * @rq: the request being processed | ||
907 | * @uptodate: error value or %0/%1 uptodate flag | ||
908 | * | ||
909 | * Description: | ||
910 | * Ends I/O on the current segment of a request. If that is the only | ||
911 | * remaining segment, the request is also completed and freed. | ||
912 | * | ||
913 | * This is a remnant of how older block drivers handled I/O completions. | ||
914 | * Modern drivers typically end I/O on the full request in one go, unless | ||
915 | * they have a residual value to account for. For that case this function | ||
916 | * isn't really useful, unless the residual just happens to be the | ||
917 | * full current segment. In other words, don't use this function in new | ||
918 | * code. Use blk_end_request() or __blk_end_request() to end a request. | ||
919 | **/ | ||
920 | static inline void end_request(struct request *rq, int uptodate) | ||
921 | { | ||
922 | int error = 0; | ||
923 | |||
924 | if (uptodate <= 0) | ||
925 | error = uptodate ? uptodate : -EIO; | ||
926 | |||
927 | __blk_end_bidi_request(rq, error, rq->hard_cur_sectors << 9, 0); | ||
928 | } | ||
929 | |||
858 | extern void blk_complete_request(struct request *); | 930 | extern void blk_complete_request(struct request *); |
859 | extern void __blk_complete_request(struct request *); | 931 | extern void __blk_complete_request(struct request *); |
860 | extern void blk_abort_request(struct request *); | 932 | extern void blk_abort_request(struct request *); |
861 | extern void blk_abort_queue(struct request_queue *); | 933 | extern void blk_abort_queue(struct request_queue *); |
862 | extern void blk_update_request(struct request *rq, int error, | ||
863 | unsigned int nr_bytes); | ||
864 | 934 | ||
865 | /* | 935 | /* |
866 | * Access functions for manipulating queue properties | 936 | * Access functions for manipulating queue properties |