Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147007
b: refs/heads/master
c: 2e46e8b
h: refs/heads/master
i:
  147005: 6ae5314
  147003: 0802dac
  146999: 9e1c413
  146991: c5fa0a5
  146975: 5a212cc
  146943: 5d9e81e
v: v3
  • Loading branch information
Tejun Heo authored and Jens Axboe committed May 11, 2009
1 parent 3256003 commit 2fe8f76
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 123 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9780e2dd8254351f6cbe11304849126b51dbd561
refs/heads/master: 2e46e8b27aa57c6bd34b3102b40ee4d0144b4fab
81 changes: 30 additions & 51 deletions trunk/block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
INIT_LIST_HEAD(&rq->timeout_list);
rq->cpu = -1;
rq->q = q;
rq->sector = rq->hard_sector = (sector_t) -1;
rq->sector = (sector_t) -1;
INIT_HLIST_NODE(&rq->hash);
RB_CLEAR_NODE(&rq->rb_node);
rq->cmd = rq->__cmd;
Expand Down Expand Up @@ -189,8 +189,7 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
(unsigned long long)blk_rq_pos(rq),
blk_rq_sectors(rq), blk_rq_cur_sectors(rq));
printk(KERN_INFO " bio %p, biotail %p, buffer %p, len %u\n",
rq->bio, rq->biotail,
rq->buffer, rq->data_len);
rq->bio, rq->biotail, rq->buffer, blk_rq_bytes(rq));

if (blk_pc_request(rq)) {
printk(KERN_INFO " cdb: ");
Expand Down Expand Up @@ -1096,7 +1095,7 @@ void init_request_from_bio(struct request *req, struct bio *bio)
req->cmd_flags |= REQ_NOIDLE;

req->errors = 0;
req->hard_sector = req->sector = bio->bi_sector;
req->sector = bio->bi_sector;
req->ioprio = bio_prio(bio);
blk_rq_bio_prep(req->q, req, bio);
}
Expand All @@ -1113,14 +1112,13 @@ static inline bool queue_should_plug(struct request_queue *q)
static int __make_request(struct request_queue *q, struct bio *bio)
{
struct request *req;
int el_ret, nr_sectors;
int el_ret;
unsigned int bytes = bio->bi_size;
const unsigned short prio = bio_prio(bio);
const int sync = bio_sync(bio);
const int unplug = bio_unplug(bio);
int rw_flags;

nr_sectors = bio_sectors(bio);

/*
* low level driver can indicate that it wants pages above a
* certain limit bounced to low memory (ie for highmem, or even
Expand All @@ -1145,7 +1143,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)

req->biotail->bi_next = bio;
req->biotail = bio;
req->nr_sectors = req->hard_nr_sectors += nr_sectors;
req->data_len += bytes;
req->ioprio = ioprio_best(req->ioprio, prio);
if (!blk_rq_cpu_valid(req))
req->cpu = bio->bi_comp_cpu;
Expand All @@ -1171,10 +1169,8 @@ static int __make_request(struct request_queue *q, struct bio *bio)
* not touch req->buffer either...
*/
req->buffer = bio_data(bio);
req->current_nr_sectors = bio_cur_sectors(bio);
req->hard_cur_sectors = req->current_nr_sectors;
req->sector = req->hard_sector = bio->bi_sector;
req->nr_sectors = req->hard_nr_sectors += nr_sectors;
req->sector = bio->bi_sector;
req->data_len += bytes;
req->ioprio = ioprio_best(req->ioprio, prio);
if (!blk_rq_cpu_valid(req))
req->cpu = bio->bi_comp_cpu;
Expand Down Expand Up @@ -1557,7 +1553,7 @@ EXPORT_SYMBOL(submit_bio);
int blk_rq_check_limits(struct request_queue *q, struct request *rq)
{
if (blk_rq_sectors(rq) > q->max_sectors ||
rq->data_len > q->max_hw_sectors << 9) {
blk_rq_bytes(rq) > q->max_hw_sectors << 9) {
printk(KERN_ERR "%s: over max size limit.\n", __func__);
return -EIO;
}
Expand Down Expand Up @@ -1675,35 +1671,6 @@ static void blk_account_io_done(struct request *req)
}
}

/**
* blk_rq_bytes - Returns bytes left to complete in the entire request
* @rq: the request being processed
**/
unsigned int blk_rq_bytes(struct request *rq)
{
if (blk_fs_request(rq))
return blk_rq_sectors(rq) << 9;

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

/**
* blk_rq_cur_bytes - Returns bytes left to complete in the current segment
* @rq: the request being processed
**/
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);

struct request *elv_next_request(struct request_queue *q)
{
struct request *rq;
Expand Down Expand Up @@ -1736,7 +1703,7 @@ struct request *elv_next_request(struct request_queue *q)
if (rq->cmd_flags & REQ_DONTPREP)
break;

if (q->dma_drain_size && rq->data_len) {
if (q->dma_drain_size && blk_rq_bytes(rq)) {
/*
* make sure space for the drain appears we
* know we can do this because max_hw_segments
Expand All @@ -1759,7 +1726,7 @@ struct request *elv_next_request(struct request_queue *q)
* avoid resource deadlock. REQ_STARTED will
* prevent other fs requests from passing this one.
*/
if (q->dma_drain_size && rq->data_len &&
if (q->dma_drain_size && blk_rq_bytes(rq) &&
!(rq->cmd_flags & REQ_DONTPREP)) {
/*
* remove the space for the drain we added
Expand Down Expand Up @@ -1911,8 +1878,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
* can find how many bytes remain in the request
* later.
*/
req->nr_sectors = req->hard_nr_sectors = 0;
req->current_nr_sectors = req->hard_cur_sectors = 0;
req->data_len = 0;
return false;
}

Expand All @@ -1926,8 +1892,25 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
bio_iovec(bio)->bv_len -= nr_bytes;
}

blk_recalc_rq_sectors(req, total_bytes >> 9);
req->data_len -= total_bytes;
req->buffer = bio_data(req->bio);

/* update sector only for requests with clear definition of sector */
if (blk_fs_request(req) || blk_discard_rq(req))
req->sector += total_bytes >> 9;

/*
* If total number of sectors is less than the first segment
* size, something has gone terribly wrong.
*/
if (blk_rq_bytes(req) < blk_rq_cur_bytes(req)) {
printk(KERN_ERR "blk: request botched\n");
req->data_len = blk_rq_cur_bytes(req);
}

/* recalculate the number of segments */
blk_recalc_rq_segments(req);

return true;
}
EXPORT_SYMBOL_GPL(blk_update_request);
Expand Down Expand Up @@ -2049,11 +2032,7 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
rq->nr_phys_segments = bio_phys_segments(q, bio);
rq->buffer = bio_data(bio);
}
rq->current_nr_sectors = bio_cur_sectors(bio);
rq->hard_cur_sectors = rq->current_nr_sectors;
rq->hard_nr_sectors = rq->nr_sectors = bio_sectors(bio);
rq->data_len = bio->bi_size;

rq->bio = rq->biotail = bio;

if (bio->bi_bdev)
Expand Down
36 changes: 4 additions & 32 deletions trunk/block/blk-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,6 @@

#include "blk.h"

void blk_recalc_rq_sectors(struct request *rq, int nsect)
{
if (blk_fs_request(rq) || blk_discard_rq(rq)) {
rq->hard_sector += nsect;
rq->hard_nr_sectors -= nsect;

/*
* Move the I/O submission pointers ahead if required.
*/
if ((rq->nr_sectors >= rq->hard_nr_sectors) &&
(rq->sector <= rq->hard_sector)) {
rq->sector = rq->hard_sector;
rq->nr_sectors = rq->hard_nr_sectors;
rq->hard_cur_sectors = bio_cur_sectors(rq->bio);
rq->current_nr_sectors = rq->hard_cur_sectors;
rq->buffer = bio_data(rq->bio);
}

/*
* if total number of sectors is less than the first segment
* size, something has gone terribly wrong
*/
if (rq->nr_sectors < rq->current_nr_sectors) {
printk(KERN_ERR "blk: request botched\n");
rq->nr_sectors = rq->current_nr_sectors;
}
}
}

static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
struct bio *bio)
{
Expand Down Expand Up @@ -199,8 +170,9 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,


if (unlikely(rq->cmd_flags & REQ_COPY_USER) &&
(rq->data_len & q->dma_pad_mask)) {
unsigned int pad_len = (q->dma_pad_mask & ~rq->data_len) + 1;
(blk_rq_bytes(rq) & q->dma_pad_mask)) {
unsigned int pad_len =
(q->dma_pad_mask & ~blk_rq_bytes(rq)) + 1;

sg->length += pad_len;
rq->extra_len += pad_len;
Expand Down Expand Up @@ -398,7 +370,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,
req->biotail->bi_next = next->bio;
req->biotail = next->biotail;

req->nr_sectors = req->hard_nr_sectors += next->hard_nr_sectors;
req->data_len += blk_rq_bytes(next);

elv_merge_requests(q, req, next);

Expand Down
1 change: 0 additions & 1 deletion trunk/block/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ int ll_front_merge_fn(struct request_queue *q, struct request *req,
int attempt_back_merge(struct request_queue *q, struct request *rq);
int attempt_front_merge(struct request_queue *q, struct request *rq);
void blk_recalc_rq_segments(struct request *rq);
void blk_recalc_rq_sectors(struct request *rq, int nsect);

void blk_queue_congestion_threshold(struct request_queue *q);

Expand Down
10 changes: 5 additions & 5 deletions trunk/block/cfq-iosched.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,9 @@ cfq_prio_tree_lookup(struct cfq_data *cfqd, struct rb_root *root,
* Sort strictly based on sector. Smallest to the left,
* largest to the right.
*/
if (sector > cfqq->next_rq->sector)
if (sector > blk_rq_pos(cfqq->next_rq))
n = &(*p)->rb_right;
else if (sector < cfqq->next_rq->sector)
else if (sector < blk_rq_pos(cfqq->next_rq))
n = &(*p)->rb_left;
else
break;
Expand Down Expand Up @@ -611,8 +611,8 @@ static void cfq_prio_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq)
return;

cfqq->p_root = &cfqd->prio_trees[cfqq->org_ioprio];
__cfqq = cfq_prio_tree_lookup(cfqd, cfqq->p_root, cfqq->next_rq->sector,
&parent, &p);
__cfqq = cfq_prio_tree_lookup(cfqd, cfqq->p_root,
blk_rq_pos(cfqq->next_rq), &parent, &p);
if (!__cfqq) {
rb_link_node(&cfqq->p_node, parent, p);
rb_insert_color(&cfqq->p_node, cfqq->p_root);
Expand Down Expand Up @@ -996,7 +996,7 @@ static struct cfq_queue *cfqq_close(struct cfq_data *cfqd,
if (cfq_rq_close(cfqd, __cfqq->next_rq))
return __cfqq;

if (__cfqq->next_rq->sector < sector)
if (blk_rq_pos(__cfqq->next_rq) < sector)
node = rb_next(&__cfqq->p_node);
else
node = rb_prev(&__cfqq->p_node);
Expand Down
6 changes: 3 additions & 3 deletions trunk/include/linux/bio.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ struct bio {
#define bio_sectors(bio) ((bio)->bi_size >> 9)
#define bio_empty_barrier(bio) (bio_barrier(bio) && !bio_has_data(bio) && !bio_discard(bio))

static inline unsigned int bio_cur_sectors(struct bio *bio)
static inline unsigned int bio_cur_bytes(struct bio *bio)
{
if (bio->bi_vcnt)
return bio_iovec(bio)->bv_len >> 9;
return bio_iovec(bio)->bv_len;
else /* dataless requests such as discard */
return bio->bi_size >> 9;
return bio->bi_size;
}

static inline void *bio_data(struct bio *bio)
Expand Down
37 changes: 16 additions & 21 deletions trunk/include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,8 @@ struct request {
enum rq_cmd_type_bits cmd_type;
unsigned long atomic_flags;

/* Maintain bio traversal state for part by part I/O submission.
* hard_* are block layer internals, no driver should touch them!
*/

sector_t sector; /* next sector to submit */
sector_t hard_sector; /* next sector to complete */
unsigned long nr_sectors; /* no. of sectors left to submit */
unsigned long hard_nr_sectors; /* no. of sectors left to complete */
/* no. of sectors left to submit in the current segment */
unsigned int current_nr_sectors;

/* no. of sectors left to complete in the current segment */
unsigned int hard_cur_sectors;
sector_t sector; /* sector cursor */
unsigned int data_len; /* total data len, don't access directly */

struct bio *bio;
struct bio *biotail;
Expand Down Expand Up @@ -226,7 +215,6 @@ struct request {
unsigned char __cmd[BLK_MAX_CDB];
unsigned char *cmd;

unsigned int data_len;
unsigned int extra_len; /* length of alignment and padding */
unsigned int sense_len;
unsigned int resid_len; /* residual count */
Expand Down Expand Up @@ -840,20 +828,27 @@ extern void blkdev_dequeue_request(struct request *req);
*/
static inline sector_t blk_rq_pos(const struct request *rq)
{
return rq->hard_sector;
return rq->sector;
}

static inline unsigned int blk_rq_bytes(const struct request *rq)
{
return rq->data_len;
}

extern unsigned int blk_rq_bytes(struct request *rq);
extern unsigned int blk_rq_cur_bytes(struct request *rq);
static inline int blk_rq_cur_bytes(const struct request *rq)
{
return rq->bio ? bio_cur_bytes(rq->bio) : 0;
}

static inline unsigned int blk_rq_sectors(const struct request *rq)
{
return rq->hard_nr_sectors;
return blk_rq_bytes(rq) >> 9;
}

static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
{
return rq->hard_cur_sectors;
return blk_rq_cur_bytes(rq) >> 9;
}

/*
Expand Down Expand Up @@ -928,7 +923,7 @@ static inline void blk_end_request_all(struct request *rq, int error)
*/
static inline bool blk_end_request_cur(struct request *rq, int error)
{
return blk_end_request(rq, error, rq->hard_cur_sectors << 9);
return blk_end_request(rq, error, blk_rq_cur_bytes(rq));
}

/**
Expand Down Expand Up @@ -981,7 +976,7 @@ static inline void __blk_end_request_all(struct request *rq, int error)
*/
static inline bool __blk_end_request_cur(struct request *rq, int error)
{
return __blk_end_request(rq, error, rq->hard_cur_sectors << 9);
return __blk_end_request(rq, error, blk_rq_cur_bytes(rq));
}

extern void blk_complete_request(struct request *);
Expand Down
2 changes: 1 addition & 1 deletion trunk/include/linux/elevator.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ enum {
ELV_MQUEUE_MUST,
};

#define rq_end_sector(rq) ((rq)->sector + (rq)->nr_sectors)
#define rq_end_sector(rq) (blk_rq_pos(rq) + blk_rq_sectors(rq))
#define rb_entry_rq(node) rb_entry((node), struct request, rb_node)

/*
Expand Down
Loading

0 comments on commit 2fe8f76

Please sign in to comment.