Skip to content

Commit 83096eb

Browse files
htejunJens Axboe
authored andcommitted
block: convert to pos and nr_sectors accessors
With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors. While at it, drop superflous blk_rq_pos() < 0 test in swim.c. [ Impact: use pos and nr_sectors accessors ] Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Tested-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Grant Likely <grant.likely@secretlab.ca> Tested-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Mike Miller <mike.miller@hp.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Cc: Borislav Petkov <petkovbb@googlemail.com> Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com> Cc: Eric Moore <Eric.Moore@lsi.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Pete Zaitcev <zaitcev@redhat.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Paul Clements <paul.clements@steeleye.com> Cc: Tim Waugh <tim@cyberelk.net> Cc: Jeff Garzik <jgarzik@pobox.com> Cc: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Alex Dubov <oakad@yahoo.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Dario Ballabio <ballabio_dario@emc.com> Cc: David S. Miller <davem@davemloft.net> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: unsik Kim <donari75@gmail.com> Cc: Laurent Vivier <Laurent@lvivier.info> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
1 parent 5b93629 commit 83096eb

54 files changed

Lines changed: 292 additions & 279 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/um/drivers/ubd_kern.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ static void do_ubd_request(struct request_queue *q)
12391239
}
12401240

12411241
req = dev->request;
1242-
sector = req->sector;
1242+
sector = blk_rq_pos(req);
12431243
while(dev->start_sg < dev->end_sg){
12441244
struct scatterlist *sg = &dev->sg[dev->start_sg];
12451245

‎block/as-iosched.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ as_choose_req(struct as_data *ad, struct request *rq1, struct request *rq2)
306306
data_dir = rq_is_sync(rq1);
307307

308308
last = ad->last_sector[data_dir];
309-
s1 = rq1->sector;
310-
s2 = rq2->sector;
309+
s1 = blk_rq_pos(rq1);
310+
s2 = blk_rq_pos(rq2);
311311

312312
BUG_ON(data_dir != rq_is_sync(rq2));
313313

@@ -566,13 +566,15 @@ static void as_update_iohist(struct as_data *ad, struct as_io_context *aic,
566566
as_update_thinktime(ad, aic, thinktime);
567567

568568
/* Calculate read -> read seek distance */
569-
if (aic->last_request_pos < rq->sector)
570-
seek_dist = rq->sector - aic->last_request_pos;
569+
if (aic->last_request_pos < blk_rq_pos(rq))
570+
seek_dist = blk_rq_pos(rq) -
571+
aic->last_request_pos;
571572
else
572-
seek_dist = aic->last_request_pos - rq->sector;
573+
seek_dist = aic->last_request_pos -
574+
blk_rq_pos(rq);
573575
as_update_seekdist(ad, aic, seek_dist);
574576
}
575-
aic->last_request_pos = rq->sector + rq->nr_sectors;
577+
aic->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq);
576578
set_bit(AS_TASK_IOSTARTED, &aic->state);
577579
spin_unlock(&aic->lock);
578580
}
@@ -587,7 +589,7 @@ static int as_close_req(struct as_data *ad, struct as_io_context *aic,
587589
{
588590
unsigned long delay; /* jiffies */
589591
sector_t last = ad->last_sector[ad->batch_data_dir];
590-
sector_t next = rq->sector;
592+
sector_t next = blk_rq_pos(rq);
591593
sector_t delta; /* acceptable close offset (in sectors) */
592594
sector_t s;
593595

@@ -981,7 +983,7 @@ static void as_move_to_dispatch(struct as_data *ad, struct request *rq)
981983
* This has to be set in order to be correctly updated by
982984
* as_find_next_rq
983985
*/
984-
ad->last_sector[data_dir] = rq->sector + rq->nr_sectors;
986+
ad->last_sector[data_dir] = blk_rq_pos(rq) + blk_rq_sectors(rq);
985987

986988
if (data_dir == BLK_RW_SYNC) {
987989
struct io_context *ioc = RQ_IOC(rq);

‎block/blk-barrier.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ int blkdev_issue_flush(struct block_device *bdev, sector_t *error_sector)
324324
/*
325325
* The driver must store the error location in ->bi_sector, if
326326
* it supports it. For non-stacked drivers, this should be copied
327-
* from rq->sector.
327+
* from blk_rq_pos(rq).
328328
*/
329329
if (error_sector)
330330
*error_sector = bio->bi_sector;

‎block/blk-core.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static void drive_stat_acct(struct request *rq, int new_io)
7272
return;
7373

7474
cpu = part_stat_lock();
75-
part = disk_map_sector_rcu(rq->rq_disk, rq->sector);
75+
part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq));
7676

7777
if (!new_io)
7878
part_stat_inc(cpu, part, merges[rw]);
@@ -185,10 +185,9 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
185185
rq->rq_disk ? rq->rq_disk->disk_name : "?", rq->cmd_type,
186186
rq->cmd_flags);
187187

188-
printk(KERN_INFO " sector %llu, nr/cnr %lu/%u\n",
189-
(unsigned long long)rq->sector,
190-
rq->nr_sectors,
191-
rq->current_nr_sectors);
188+
printk(KERN_INFO " sector %llu, nr/cnr %u/%u\n",
189+
(unsigned long long)blk_rq_pos(rq),
190+
blk_rq_sectors(rq), blk_rq_cur_sectors(rq));
192191
printk(KERN_INFO " bio %p, biotail %p, buffer %p, len %u\n",
193192
rq->bio, rq->biotail,
194193
rq->buffer, rq->data_len);
@@ -1557,7 +1556,7 @@ EXPORT_SYMBOL(submit_bio);
15571556
*/
15581557
int blk_rq_check_limits(struct request_queue *q, struct request *rq)
15591558
{
1560-
if (rq->nr_sectors > q->max_sectors ||
1559+
if (blk_rq_sectors(rq) > q->max_sectors ||
15611560
rq->data_len > q->max_hw_sectors << 9) {
15621561
printk(KERN_ERR "%s: over max size limit.\n", __func__);
15631562
return -EIO;
@@ -1645,7 +1644,7 @@ static void blk_account_io_completion(struct request *req, unsigned int bytes)
16451644
int cpu;
16461645

16471646
cpu = part_stat_lock();
1648-
part = disk_map_sector_rcu(req->rq_disk, req->sector);
1647+
part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req));
16491648
part_stat_add(cpu, part, sectors[rw], bytes >> 9);
16501649
part_stat_unlock();
16511650
}
@@ -1665,7 +1664,7 @@ static void blk_account_io_done(struct request *req)
16651664
int cpu;
16661665

16671666
cpu = part_stat_lock();
1668-
part = disk_map_sector_rcu(req->rq_disk, req->sector);
1667+
part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req));
16691668

16701669
part_stat_inc(cpu, part, ios[rw]);
16711670
part_stat_add(cpu, part, ticks[rw], duration);
@@ -1846,7 +1845,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
18461845
if (error && (blk_fs_request(req) && !(req->cmd_flags & REQ_QUIET))) {
18471846
printk(KERN_ERR "end_request: I/O error, dev %s, sector %llu\n",
18481847
req->rq_disk ? req->rq_disk->disk_name : "?",
1849-
(unsigned long long)req->sector);
1848+
(unsigned long long)blk_rq_pos(req));
18501849
}
18511850

18521851
blk_account_io_completion(req, nr_bytes);

‎block/blk-merge.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ int ll_back_merge_fn(struct request_queue *q, struct request *req,
259259
else
260260
max_sectors = q->max_sectors;
261261

262-
if (req->nr_sectors + bio_sectors(bio) > max_sectors) {
262+
if (blk_rq_sectors(req) + bio_sectors(bio) > max_sectors) {
263263
req->cmd_flags |= REQ_NOMERGE;
264264
if (req == q->last_merge)
265265
q->last_merge = NULL;
@@ -284,7 +284,7 @@ int ll_front_merge_fn(struct request_queue *q, struct request *req,
284284
max_sectors = q->max_sectors;
285285

286286

287-
if (req->nr_sectors + bio_sectors(bio) > max_sectors) {
287+
if (blk_rq_sectors(req) + bio_sectors(bio) > max_sectors) {
288288
req->cmd_flags |= REQ_NOMERGE;
289289
if (req == q->last_merge)
290290
q->last_merge = NULL;
@@ -315,7 +315,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
315315
/*
316316
* Will it become too large?
317317
*/
318-
if ((req->nr_sectors + next->nr_sectors) > q->max_sectors)
318+
if ((blk_rq_sectors(req) + blk_rq_sectors(next)) > q->max_sectors)
319319
return 0;
320320

321321
total_phys_segments = req->nr_phys_segments + next->nr_phys_segments;
@@ -345,7 +345,7 @@ static void blk_account_io_merge(struct request *req)
345345
int cpu;
346346

347347
cpu = part_stat_lock();
348-
part = disk_map_sector_rcu(req->rq_disk, req->sector);
348+
part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req));
349349

350350
part_round_stats(cpu, part);
351351
part_dec_in_flight(part);
@@ -366,7 +366,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,
366366
/*
367367
* not contiguous
368368
*/
369-
if (req->sector + req->nr_sectors != next->sector)
369+
if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next))
370370
return 0;
371371

372372
if (rq_data_dir(req) != rq_data_dir(next)

‎block/cfq-iosched.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2)
349349
else if (rq_is_meta(rq2) && !rq_is_meta(rq1))
350350
return rq2;
351351

352-
s1 = rq1->sector;
353-
s2 = rq2->sector;
352+
s1 = blk_rq_pos(rq1);
353+
s2 = blk_rq_pos(rq2);
354354

355355
last = cfqd->last_position;
356356

@@ -949,10 +949,10 @@ static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd,
949949
static inline sector_t cfq_dist_from_last(struct cfq_data *cfqd,
950950
struct request *rq)
951951
{
952-
if (rq->sector >= cfqd->last_position)
953-
return rq->sector - cfqd->last_position;
952+
if (blk_rq_pos(rq) >= cfqd->last_position)
953+
return blk_rq_pos(rq) - cfqd->last_position;
954954
else
955-
return cfqd->last_position - rq->sector;
955+
return cfqd->last_position - blk_rq_pos(rq);
956956
}
957957

958958
#define CIC_SEEK_THR 8 * 1024
@@ -1918,10 +1918,10 @@ cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_io_context *cic,
19181918

19191919
if (!cic->last_request_pos)
19201920
sdist = 0;
1921-
else if (cic->last_request_pos < rq->sector)
1922-
sdist = rq->sector - cic->last_request_pos;
1921+
else if (cic->last_request_pos < blk_rq_pos(rq))
1922+
sdist = blk_rq_pos(rq) - cic->last_request_pos;
19231923
else
1924-
sdist = cic->last_request_pos - rq->sector;
1924+
sdist = cic->last_request_pos - blk_rq_pos(rq);
19251925

19261926
/*
19271927
* Don't allow the seek distance to get too large from the
@@ -2071,7 +2071,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
20712071
cfq_update_io_seektime(cfqd, cic, rq);
20722072
cfq_update_idle_window(cfqd, cfqq, cic);
20732073

2074-
cic->last_request_pos = rq->sector + rq->nr_sectors;
2074+
cic->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq);
20752075

20762076
if (cfqq == cfqd->active_queue) {
20772077
/*

‎block/deadline-iosched.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ deadline_merge(struct request_queue *q, struct request **req, struct bio *bio)
138138

139139
__rq = elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector);
140140
if (__rq) {
141-
BUG_ON(sector != __rq->sector);
141+
BUG_ON(sector != blk_rq_pos(__rq));
142142

143143
if (elv_rq_merge_ok(__rq, bio)) {
144144
ret = ELEVATOR_FRONT_MERGE;

‎block/elevator.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static const int elv_hash_shift = 6;
5252
#define ELV_HASH_FN(sec) \
5353
(hash_long(ELV_HASH_BLOCK((sec)), elv_hash_shift))
5454
#define ELV_HASH_ENTRIES (1 << elv_hash_shift)
55-
#define rq_hash_key(rq) ((rq)->sector + (rq)->nr_sectors)
55+
#define rq_hash_key(rq) (blk_rq_pos(rq) + blk_rq_sectors(rq))
5656

5757
DEFINE_TRACE(block_rq_insert);
5858
DEFINE_TRACE(block_rq_issue);
@@ -119,9 +119,9 @@ static inline int elv_try_merge(struct request *__rq, struct bio *bio)
119119
* we can merge and sequence is ok, check if it's possible
120120
*/
121121
if (elv_rq_merge_ok(__rq, bio)) {
122-
if (__rq->sector + __rq->nr_sectors == bio->bi_sector)
122+
if (blk_rq_pos(__rq) + blk_rq_sectors(__rq) == bio->bi_sector)
123123
ret = ELEVATOR_BACK_MERGE;
124-
else if (__rq->sector - bio_sectors(bio) == bio->bi_sector)
124+
else if (blk_rq_pos(__rq) - bio_sectors(bio) == bio->bi_sector)
125125
ret = ELEVATOR_FRONT_MERGE;
126126
}
127127

@@ -370,9 +370,9 @@ struct request *elv_rb_add(struct rb_root *root, struct request *rq)
370370
parent = *p;
371371
__rq = rb_entry(parent, struct request, rb_node);
372372

373-
if (rq->sector < __rq->sector)
373+
if (blk_rq_pos(rq) < blk_rq_pos(__rq))
374374
p = &(*p)->rb_left;
375-
else if (rq->sector > __rq->sector)
375+
else if (blk_rq_pos(rq) > blk_rq_pos(__rq))
376376
p = &(*p)->rb_right;
377377
else
378378
return __rq;
@@ -400,9 +400,9 @@ struct request *elv_rb_find(struct rb_root *root, sector_t sector)
400400
while (n) {
401401
rq = rb_entry(n, struct request, rb_node);
402402

403-
if (sector < rq->sector)
403+
if (sector < blk_rq_pos(rq))
404404
n = n->rb_left;
405-
else if (sector > rq->sector)
405+
else if (sector > blk_rq_pos(rq))
406406
n = n->rb_right;
407407
else
408408
return rq;
@@ -441,14 +441,14 @@ void elv_dispatch_sort(struct request_queue *q, struct request *rq)
441441
break;
442442
if (pos->cmd_flags & stop_flags)
443443
break;
444-
if (rq->sector >= boundary) {
445-
if (pos->sector < boundary)
444+
if (blk_rq_pos(rq) >= boundary) {
445+
if (blk_rq_pos(pos) < boundary)
446446
continue;
447447
} else {
448-
if (pos->sector >= boundary)
448+
if (blk_rq_pos(pos) >= boundary)
449449
break;
450450
}
451-
if (rq->sector >= pos->sector)
451+
if (blk_rq_pos(rq) >= blk_rq_pos(pos))
452452
break;
453453
}
454454

‎drivers/block/DAC960.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,8 +3338,8 @@ static int DAC960_process_queue(DAC960_Controller_T *Controller, struct request_
33383338
}
33393339
Command->Completion = Request->end_io_data;
33403340
Command->LogicalDriveNumber = (long)Request->rq_disk->private_data;
3341-
Command->BlockNumber = Request->sector;
3342-
Command->BlockCount = Request->nr_sectors;
3341+
Command->BlockNumber = blk_rq_pos(Request);
3342+
Command->BlockCount = blk_rq_sectors(Request);
33433343
Command->Request = Request;
33443344
blkdev_dequeue_request(Request);
33453345
Command->SegmentCount = blk_rq_map_sg(req_q,
@@ -3431,7 +3431,7 @@ static void DAC960_queue_partial_rw(DAC960_Command_T *Command)
34313431
* successfully as possible.
34323432
*/
34333433
Command->SegmentCount = 1;
3434-
Command->BlockNumber = Request->sector;
3434+
Command->BlockNumber = blk_rq_pos(Request);
34353435
Command->BlockCount = 1;
34363436
DAC960_QueueReadWriteCommand(Command);
34373437
return;

‎drivers/block/amiflop.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,13 +1351,13 @@ static void redo_fd_request(void)
13511351
drive = floppy - unit;
13521352

13531353
/* Here someone could investigate to be more efficient */
1354-
for (cnt = 0; cnt < CURRENT->current_nr_sectors; cnt++) {
1354+
for (cnt = 0; cnt < blk_rq_cur_sectors(CURRENT); cnt++) {
13551355
#ifdef DEBUG
13561356
printk("fd: sector %ld + %d requested for %s\n",
1357-
CURRENT->sector,cnt,
1357+
blk_rq_pos(CURRENT), cnt,
13581358
(rq_data_dir(CURRENT) == READ) ? "read" : "write");
13591359
#endif
1360-
block = CURRENT->sector + cnt;
1360+
block = blk_rq_pos(CURRENT) + cnt;
13611361
if ((int)block > floppy->blocks) {
13621362
__blk_end_request_cur(CURRENT, -EIO);
13631363
goto repeat;

0 commit comments

Comments
 (0)