Skip to content

Commit

Permalink
blk_end_request: add/export functions to get request size (take 4)
Browse files Browse the repository at this point in the history
This patch adds/exports functions to get the size of request in bytes.
They are useful because blk_end_request interfaces take bytes
as a completed I/O size instead of sectors.

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>
  • Loading branch information
Kiyoshi Ueda authored and Jens Axboe committed Jan 28, 2008
1 parent 336cdb4 commit 3b11313
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
25 changes: 22 additions & 3 deletions block/ll_rw_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3723,13 +3723,32 @@ static inline void __end_request(struct request *rq, int uptodate,
}
}

static unsigned int rq_byte_size(struct request *rq)
/**
* blk_rq_bytes - Returns bytes left to complete in the entire request
**/
unsigned int blk_rq_bytes(struct request *rq)
{
if (blk_fs_request(rq))
return rq->hard_nr_sectors << 9;

return rq->data_len;
}
EXPORT_SYMBOL_GPL(blk_rq_bytes);

/**
* blk_rq_cur_bytes - Returns bytes left to complete in the current segment
**/
unsigned int blk_rq_cur_bytes(struct request *rq)
{
if (blk_fs_request(rq))
return rq->current_nr_sectors << 9;

if (rq->bio)
return rq->bio->bi_size;

return rq->data_len;
}
EXPORT_SYMBOL_GPL(blk_rq_cur_bytes);

/**
* end_queued_request - end all I/O on a queued request
Expand All @@ -3744,7 +3763,7 @@ static unsigned int rq_byte_size(struct request *rq)
**/
void end_queued_request(struct request *rq, int uptodate)
{
__end_request(rq, uptodate, rq_byte_size(rq), 1);
__end_request(rq, uptodate, blk_rq_bytes(rq), 1);
}
EXPORT_SYMBOL(end_queued_request);

Expand All @@ -3761,7 +3780,7 @@ EXPORT_SYMBOL(end_queued_request);
**/
void end_dequeued_request(struct request *rq, int uptodate)
{
__end_request(rq, uptodate, rq_byte_size(rq), 0);
__end_request(rq, uptodate, blk_rq_bytes(rq), 0);
}
EXPORT_SYMBOL(end_dequeued_request);

Expand Down
8 changes: 8 additions & 0 deletions include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,14 @@ extern void end_queued_request(struct request *, int);
extern void end_dequeued_request(struct request *, int);
extern void blk_complete_request(struct request *);

/*
* blk_end_request() takes bytes instead of sectors as a complete size.
* blk_rq_bytes() returns bytes left to complete in the entire request.
* blk_rq_cur_bytes() returns bytes left to complete in the current segment.
*/
extern unsigned int blk_rq_bytes(struct request *rq);
extern unsigned int blk_rq_cur_bytes(struct request *rq);

/*
* end_that_request_first/chunk() takes an uptodate argument. we account
* any value <= as an io error. 0 means -EIO for compatability reasons,
Expand Down

0 comments on commit 3b11313

Please sign in to comment.