Commit a2dec7b3 authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

block: hide request sector and data_len

Block low level drivers for some reason have been pretty good at
abusing block layer API.  Especially struct request's fields tend to
get violated in all possible ways.  Make it clear that low level
drivers MUST NOT access or manipulate rq->sector and rq->data_len
directly by prefixing them with double underscores.

This change is also necessary to break build of out-of-tree codes
which assume the previous block API where internal fields can be
manipulated and rq->data_len carries residual count on completion.

[ Impact: hide internal fields, block API change ]
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 34b7d2c9
...@@ -127,7 +127,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq) ...@@ -127,7 +127,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
INIT_LIST_HEAD(&rq->timeout_list); INIT_LIST_HEAD(&rq->timeout_list);
rq->cpu = -1; rq->cpu = -1;
rq->q = q; rq->q = q;
rq->sector = (sector_t) -1; rq->__sector = (sector_t) -1;
INIT_HLIST_NODE(&rq->hash); INIT_HLIST_NODE(&rq->hash);
RB_CLEAR_NODE(&rq->rb_node); RB_CLEAR_NODE(&rq->rb_node);
rq->cmd = rq->__cmd; rq->cmd = rq->__cmd;
...@@ -1095,7 +1095,7 @@ void init_request_from_bio(struct request *req, struct bio *bio) ...@@ -1095,7 +1095,7 @@ void init_request_from_bio(struct request *req, struct bio *bio)
req->cmd_flags |= REQ_NOIDLE; req->cmd_flags |= REQ_NOIDLE;
req->errors = 0; req->errors = 0;
req->sector = bio->bi_sector; req->__sector = bio->bi_sector;
req->ioprio = bio_prio(bio); req->ioprio = bio_prio(bio);
blk_rq_bio_prep(req->q, req, bio); blk_rq_bio_prep(req->q, req, bio);
} }
...@@ -1143,7 +1143,7 @@ static int __make_request(struct request_queue *q, struct bio *bio) ...@@ -1143,7 +1143,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
req->biotail->bi_next = bio; req->biotail->bi_next = bio;
req->biotail = bio; req->biotail = bio;
req->data_len += bytes; req->__data_len += bytes;
req->ioprio = ioprio_best(req->ioprio, prio); req->ioprio = ioprio_best(req->ioprio, prio);
if (!blk_rq_cpu_valid(req)) if (!blk_rq_cpu_valid(req))
req->cpu = bio->bi_comp_cpu; req->cpu = bio->bi_comp_cpu;
...@@ -1169,8 +1169,8 @@ static int __make_request(struct request_queue *q, struct bio *bio) ...@@ -1169,8 +1169,8 @@ static int __make_request(struct request_queue *q, struct bio *bio)
* not touch req->buffer either... * not touch req->buffer either...
*/ */
req->buffer = bio_data(bio); req->buffer = bio_data(bio);
req->sector = bio->bi_sector; req->__sector = bio->bi_sector;
req->data_len += bytes; req->__data_len += bytes;
req->ioprio = ioprio_best(req->ioprio, prio); req->ioprio = ioprio_best(req->ioprio, prio);
if (!blk_rq_cpu_valid(req)) if (!blk_rq_cpu_valid(req))
req->cpu = bio->bi_comp_cpu; req->cpu = bio->bi_comp_cpu;
...@@ -1878,7 +1878,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes) ...@@ -1878,7 +1878,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
* can find how many bytes remain in the request * can find how many bytes remain in the request
* later. * later.
*/ */
req->data_len = 0; req->__data_len = 0;
return false; return false;
} }
...@@ -1892,12 +1892,12 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes) ...@@ -1892,12 +1892,12 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
bio_iovec(bio)->bv_len -= nr_bytes; bio_iovec(bio)->bv_len -= nr_bytes;
} }
req->data_len -= total_bytes; req->__data_len -= total_bytes;
req->buffer = bio_data(req->bio); req->buffer = bio_data(req->bio);
/* update sector only for requests with clear definition of sector */ /* update sector only for requests with clear definition of sector */
if (blk_fs_request(req) || blk_discard_rq(req)) if (blk_fs_request(req) || blk_discard_rq(req))
req->sector += total_bytes >> 9; req->__sector += total_bytes >> 9;
/* /*
* If total number of sectors is less than the first segment * If total number of sectors is less than the first segment
...@@ -1905,7 +1905,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes) ...@@ -1905,7 +1905,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
*/ */
if (blk_rq_bytes(req) < blk_rq_cur_bytes(req)) { if (blk_rq_bytes(req) < blk_rq_cur_bytes(req)) {
printk(KERN_ERR "blk: request botched\n"); printk(KERN_ERR "blk: request botched\n");
req->data_len = blk_rq_cur_bytes(req); req->__data_len = blk_rq_cur_bytes(req);
} }
/* recalculate the number of segments */ /* recalculate the number of segments */
...@@ -2032,7 +2032,7 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq, ...@@ -2032,7 +2032,7 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
rq->nr_phys_segments = bio_phys_segments(q, bio); rq->nr_phys_segments = bio_phys_segments(q, bio);
rq->buffer = bio_data(bio); rq->buffer = bio_data(bio);
} }
rq->data_len = bio->bi_size; rq->__data_len = bio->bi_size;
rq->bio = rq->biotail = bio; rq->bio = rq->biotail = bio;
if (bio->bi_bdev) if (bio->bi_bdev)
......
...@@ -20,7 +20,7 @@ int blk_rq_append_bio(struct request_queue *q, struct request *rq, ...@@ -20,7 +20,7 @@ int blk_rq_append_bio(struct request_queue *q, struct request *rq,
rq->biotail->bi_next = bio; rq->biotail->bi_next = bio;
rq->biotail = bio; rq->biotail = bio;
rq->data_len += bio->bi_size; rq->__data_len += bio->bi_size;
} }
return 0; return 0;
} }
......
...@@ -370,7 +370,7 @@ static int attempt_merge(struct request_queue *q, struct request *req, ...@@ -370,7 +370,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,
req->biotail->bi_next = next->bio; req->biotail->bi_next = next->bio;
req->biotail = next->biotail; req->biotail = next->biotail;
req->data_len += blk_rq_bytes(next); req->__data_len += blk_rq_bytes(next);
elv_merge_requests(q, req, next); elv_merge_requests(q, req, next);
......
...@@ -166,8 +166,9 @@ struct request { ...@@ -166,8 +166,9 @@ struct request {
enum rq_cmd_type_bits cmd_type; enum rq_cmd_type_bits cmd_type;
unsigned long atomic_flags; unsigned long atomic_flags;
sector_t sector; /* sector cursor */ /* the following two fields are internal, NEVER access directly */
unsigned int data_len; /* total data len, don't access directly */ sector_t __sector; /* sector cursor */
unsigned int __data_len; /* total data len */
struct bio *bio; struct bio *bio;
struct bio *biotail; struct bio *biotail;
...@@ -828,12 +829,12 @@ extern void blkdev_dequeue_request(struct request *req); ...@@ -828,12 +829,12 @@ extern void blkdev_dequeue_request(struct request *req);
*/ */
static inline sector_t blk_rq_pos(const struct request *rq) static inline sector_t blk_rq_pos(const struct request *rq)
{ {
return rq->sector; return rq->__sector;
} }
static inline unsigned int blk_rq_bytes(const struct request *rq) static inline unsigned int blk_rq_bytes(const struct request *rq)
{ {
return rq->data_len; return rq->__data_len;
} }
static inline int blk_rq_cur_bytes(const struct request *rq) static inline int blk_rq_cur_bytes(const struct request *rq)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment