Skip to content

Commit

Permalink
block: remove struct request buffer member
Browse files Browse the repository at this point in the history
This was used in the olden days, back when onions were proper
yellow. Basically it mapped to the current buffer to be
transferred. With highmem being added more than a decade ago,
most drivers map pages out of a bio, and rq->buffer isn't
pointing at anything valid.

Convert old style drivers to just use bio_data().

For the discard payload use case, just reference the page
in the bio.

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Apr 15, 2014
1 parent f89e0dd commit b4f42e2
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 75 deletions.
21 changes: 6 additions & 15 deletions block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
printk(KERN_INFO " sector %llu, nr/cnr %u/%u\n",
(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, blk_rq_bytes(rq));
printk(KERN_INFO " bio %p, biotail %p, len %u\n",
rq->bio, rq->biotail, blk_rq_bytes(rq));

if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
printk(KERN_INFO " cdb: ");
Expand Down Expand Up @@ -1360,7 +1360,6 @@ void blk_add_request_payload(struct request *rq, struct page *page,

rq->__data_len = rq->resid_len = len;
rq->nr_phys_segments = 1;
rq->buffer = bio_data(bio);
}
EXPORT_SYMBOL_GPL(blk_add_request_payload);

Expand Down Expand Up @@ -1402,12 +1401,6 @@ bool bio_attempt_front_merge(struct request_queue *q, struct request *req,
bio->bi_next = req->bio;
req->bio = bio;

/*
* may not be valid. if the low level driver said
* it didn't need a bounce buffer then it better
* not touch req->buffer either...
*/
req->buffer = bio_data(bio);
req->__sector = bio->bi_iter.bi_sector;
req->__data_len += bio->bi_iter.bi_size;
req->ioprio = ioprio_best(req->ioprio, bio_prio(bio));
Expand Down Expand Up @@ -2434,7 +2427,6 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
}

req->__data_len -= total_bytes;
req->buffer = bio_data(req->bio);

/* update sector only for requests with clear definition of sector */
if (req->cmd_type == REQ_TYPE_FS)
Expand Down Expand Up @@ -2752,10 +2744,9 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
/* Bit 0 (R/W) is identical in rq->cmd_flags and bio->bi_rw */
rq->cmd_flags |= bio->bi_rw & REQ_WRITE;

if (bio_has_data(bio)) {
if (bio_has_data(bio))
rq->nr_phys_segments = bio_phys_segments(q, bio);
rq->buffer = bio_data(bio);
}

rq->__data_len = bio->bi_iter.bi_size;
rq->bio = rq->biotail = bio;

Expand Down Expand Up @@ -2831,7 +2822,7 @@ EXPORT_SYMBOL_GPL(blk_rq_unprep_clone);

/*
* Copy attributes of the original request to the clone request.
* The actual data parts (e.g. ->cmd, ->buffer, ->sense) are not copied.
* The actual data parts (e.g. ->cmd, ->sense) are not copied.
*/
static void __blk_rq_prep_clone(struct request *dst, struct request *src)
{
Expand All @@ -2857,7 +2848,7 @@ static void __blk_rq_prep_clone(struct request *dst, struct request *src)
*
* Description:
* Clones bios in @rq_src to @rq, and copies attributes of @rq_src to @rq.
* The actual data parts of @rq_src (e.g. ->cmd, ->buffer, ->sense)
* The actual data parts of @rq_src (e.g. ->cmd, ->sense)
* are not copied, and copying such parts is the caller's responsibility.
* Also, pages which the original bios are pointing to are not copied
* and the cloned bios just point same pages.
Expand Down
3 changes: 0 additions & 3 deletions block/blk-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq,
if (!bio_flagged(bio, BIO_USER_MAPPED))
rq->cmd_flags |= REQ_COPY_USER;

rq->buffer = NULL;
return 0;
unmap_rq:
blk_rq_unmap_user(bio);
Expand Down Expand Up @@ -238,7 +237,6 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
blk_queue_bounce(q, &bio);
bio_get(bio);
blk_rq_bio_prep(q, rq, bio);
rq->buffer = NULL;
return 0;
}
EXPORT_SYMBOL(blk_rq_map_user_iov);
Expand Down Expand Up @@ -325,7 +323,6 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
}

blk_queue_bounce(q, &rq->bio);
rq->buffer = NULL;
return 0;
}
EXPORT_SYMBOL(blk_rq_map_kern);
2 changes: 1 addition & 1 deletion drivers/block/amiflop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ static void redo_fd_request(void)

track = block / (floppy->dtype->sects * floppy->type->sect_mult);
sector = block % (floppy->dtype->sects * floppy->type->sect_mult);
data = rq->buffer + 512 * cnt;
data = bio_data(rq->bio) + 512 * cnt;
#ifdef DEBUG
printk("access to track %d, sector %d, with buffer at "
"0x%08lx\n", track, sector, data);
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/ataflop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ static void redo_fd_request(void)
ReqCnt = 0;
ReqCmd = rq_data_dir(fd_request);
ReqBlock = blk_rq_pos(fd_request);
ReqBuffer = fd_request->buffer;
ReqBuffer = bio_data(fd_request->bio);
setup_req_params( drive );
do_fd_action( drive );

Expand Down
18 changes: 9 additions & 9 deletions drivers/block/floppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,7 @@ static void rw_interrupt(void)
}

if (CT(COMMAND) != FD_READ ||
raw_cmd->kernel_data == current_req->buffer) {
raw_cmd->kernel_data == bio_data(current_req->bio)) {
/* transfer directly from buffer */
cont->done(1);
} else if (CT(COMMAND) == FD_READ) {
Expand Down Expand Up @@ -2640,7 +2640,7 @@ static int make_raw_rw_request(void)
raw_cmd->flags &= ~FD_RAW_WRITE;
raw_cmd->flags |= FD_RAW_READ;
COMMAND = FM_MODE(_floppy, FD_READ);
} else if ((unsigned long)current_req->buffer < MAX_DMA_ADDRESS) {
} else if ((unsigned long)bio_data(current_req->bio) < MAX_DMA_ADDRESS) {
unsigned long dma_limit;
int direct, indirect;

Expand All @@ -2654,13 +2654,13 @@ static int make_raw_rw_request(void)
*/
max_size = buffer_chain_size();
dma_limit = (MAX_DMA_ADDRESS -
((unsigned long)current_req->buffer)) >> 9;
((unsigned long)bio_data(current_req->bio))) >> 9;
if ((unsigned long)max_size > dma_limit)
max_size = dma_limit;
/* 64 kb boundaries */
if (CROSS_64KB(current_req->buffer, max_size << 9))
if (CROSS_64KB(bio_data(current_req->bio), max_size << 9))
max_size = (K_64 -
((unsigned long)current_req->buffer) %
((unsigned long)bio_data(current_req->bio)) %
K_64) >> 9;
direct = transfer_size(ssize, max_sector, max_size) - fsector_t;
/*
Expand All @@ -2677,7 +2677,7 @@ static int make_raw_rw_request(void)
(DP->read_track & (1 << DRS->probed_format)))))) {
max_size = blk_rq_sectors(current_req);
} else {
raw_cmd->kernel_data = current_req->buffer;
raw_cmd->kernel_data = bio_data(current_req->bio);
raw_cmd->length = current_count_sectors << 9;
if (raw_cmd->length == 0) {
DPRINT("%s: zero dma transfer attempted\n", __func__);
Expand Down Expand Up @@ -2731,15 +2731,15 @@ static int make_raw_rw_request(void)
raw_cmd->length = ((raw_cmd->length - 1) | (ssize - 1)) + 1;
raw_cmd->length <<= 9;
if ((raw_cmd->length < current_count_sectors << 9) ||
(raw_cmd->kernel_data != current_req->buffer &&
(raw_cmd->kernel_data != bio_data(current_req->bio) &&
CT(COMMAND) == FD_WRITE &&
(aligned_sector_t + (raw_cmd->length >> 9) > buffer_max ||
aligned_sector_t < buffer_min)) ||
raw_cmd->length % (128 << SIZECODE) ||
raw_cmd->length <= 0 || current_count_sectors <= 0) {
DPRINT("fractionary current count b=%lx s=%lx\n",
raw_cmd->length, current_count_sectors);
if (raw_cmd->kernel_data != current_req->buffer)
if (raw_cmd->kernel_data != bio_data(current_req->bio))
pr_info("addr=%d, length=%ld\n",
(int)((raw_cmd->kernel_data -
floppy_track_buffer) >> 9),
Expand All @@ -2756,7 +2756,7 @@ static int make_raw_rw_request(void)
return 0;
}

if (raw_cmd->kernel_data != current_req->buffer) {
if (raw_cmd->kernel_data != bio_data(current_req->bio)) {
if (raw_cmd->kernel_data < floppy_track_buffer ||
current_count_sectors < 0 ||
raw_cmd->length < 0 ||
Expand Down
10 changes: 5 additions & 5 deletions drivers/block/hd.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,11 @@ static void read_intr(void)

ok_to_read:
req = hd_req;
insw(HD_DATA, req->buffer, 256);
insw(HD_DATA, bio_data(req->bio), 256);
#ifdef DEBUG
printk("%s: read: sector %ld, remaining = %u, buffer=%p\n",
req->rq_disk->disk_name, blk_rq_pos(req) + 1,
blk_rq_sectors(req) - 1, req->buffer+512);
blk_rq_sectors(req) - 1, bio_data(req->bio)+512);
#endif
if (hd_end_request(0, 512)) {
SET_HANDLER(&read_intr);
Expand Down Expand Up @@ -505,7 +505,7 @@ static void write_intr(void)
ok_to_write:
if (hd_end_request(0, 512)) {
SET_HANDLER(&write_intr);
outsw(HD_DATA, req->buffer, 256);
outsw(HD_DATA, bio_data(req->bio), 256);
return;
}

Expand Down Expand Up @@ -624,7 +624,7 @@ static void hd_request(void)
printk("%s: %sing: CHS=%d/%d/%d, sectors=%d, buffer=%p\n",
req->rq_disk->disk_name,
req_data_dir(req) == READ ? "read" : "writ",
cyl, head, sec, nsect, req->buffer);
cyl, head, sec, nsect, bio_data(req->bio));
#endif
if (req->cmd_type == REQ_TYPE_FS) {
switch (rq_data_dir(req)) {
Expand All @@ -643,7 +643,7 @@ static void hd_request(void)
bad_rw_intr();
goto repeat;
}
outsw(HD_DATA, req->buffer, 256);
outsw(HD_DATA, bio_data(req->bio), 256);
break;
default:
printk("unknown hd-command\n");
Expand Down
12 changes: 6 additions & 6 deletions drivers/block/mg_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ static unsigned int mg_out(struct mg_host *host,

static void mg_read_one(struct mg_host *host, struct request *req)
{
u16 *buff = (u16 *)req->buffer;
u16 *buff = (u16 *)bio_data(req->bio);
u32 i;

for (i = 0; i < MG_SECTOR_SIZE >> 1; i++)
Expand All @@ -496,7 +496,7 @@ static void mg_read(struct request *req)
mg_bad_rw_intr(host);

MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
blk_rq_sectors(req), blk_rq_pos(req), req->buffer);
blk_rq_sectors(req), blk_rq_pos(req), bio_data(req->bio));

do {
if (mg_wait(host, ATA_DRQ,
Expand All @@ -514,7 +514,7 @@ static void mg_read(struct request *req)

static void mg_write_one(struct mg_host *host, struct request *req)
{
u16 *buff = (u16 *)req->buffer;
u16 *buff = (u16 *)bio_data(req->bio);
u32 i;

for (i = 0; i < MG_SECTOR_SIZE >> 1; i++)
Expand All @@ -534,7 +534,7 @@ static void mg_write(struct request *req)
}

MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
rem, blk_rq_pos(req), req->buffer);
rem, blk_rq_pos(req), bio_data(req->bio));

if (mg_wait(host, ATA_DRQ,
MG_TMAX_WAIT_WR_DRQ) != MG_ERR_NONE) {
Expand Down Expand Up @@ -585,7 +585,7 @@ static void mg_read_intr(struct mg_host *host)
mg_read_one(host, req);

MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
blk_rq_pos(req), blk_rq_sectors(req) - 1, req->buffer);
blk_rq_pos(req), blk_rq_sectors(req) - 1, bio_data(req->bio));

/* send read confirm */
outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
Expand Down Expand Up @@ -624,7 +624,7 @@ static void mg_write_intr(struct mg_host *host)
/* write 1 sector and set handler if remains */
mg_write_one(host, req);
MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
blk_rq_pos(req), blk_rq_sectors(req), req->buffer);
blk_rq_pos(req), blk_rq_sectors(req), bio_data(req->bio));
host->mg_do_intr = mg_write_intr;
mod_timer(&host->timer, jiffies + 3 * HZ);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/paride/pcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ static void do_pcd_request(struct request_queue * q)
pcd_current = cd;
pcd_sector = blk_rq_pos(pcd_req);
pcd_count = blk_rq_cur_sectors(pcd_req);
pcd_buf = pcd_req->buffer;
pcd_buf = bio_data(pcd_req->bio);
pcd_busy = 1;
ps_set_intr(do_pcd_read, NULL, 0, nice);
return;
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/paride/pd.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ static enum action do_pd_io_start(void)
if (pd_block + pd_count > get_capacity(pd_req->rq_disk))
return Fail;
pd_run = blk_rq_sectors(pd_req);
pd_buf = pd_req->buffer;
pd_buf = bio_data(pd_req->bio);
pd_retries = 0;
if (pd_cmd == READ)
return do_pd_read_start();
Expand Down Expand Up @@ -485,7 +485,7 @@ static int pd_next_buf(void)
spin_lock_irqsave(&pd_lock, saved_flags);
__blk_end_request_cur(pd_req, 0);
pd_count = blk_rq_cur_sectors(pd_req);
pd_buf = pd_req->buffer;
pd_buf = bio_data(pd_req->bio);
spin_unlock_irqrestore(&pd_lock, saved_flags);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/paride/pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ static void do_pf_request(struct request_queue * q)
}

pf_cmd = rq_data_dir(pf_req);
pf_buf = pf_req->buffer;
pf_buf = bio_data(pf_req->bio);
pf_retries = 0;

pf_busy = 1;
Expand Down Expand Up @@ -827,7 +827,7 @@ static int pf_next_buf(void)
if (!pf_req)
return 1;
pf_count = blk_rq_cur_sectors(pf_req);
pf_buf = pf_req->buffer;
pf_buf = bio_data(pf_req->bio);
}
return 0;
}
Expand Down
5 changes: 2 additions & 3 deletions drivers/block/skd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ skd_prep_discard_cdb(struct skd_scsi_request *scsi_req,

req = skreq->req;
blk_add_request_payload(req, page, len);
req->buffer = buf;
}

static void skd_request_fn_not_online(struct request_queue *q);
Expand Down Expand Up @@ -856,10 +855,10 @@ static void skd_end_request(struct skd_device *skdev,

if ((io_flags & REQ_DISCARD) &&
(skreq->discard_page == 1)) {
struct bio *bio = req->bio;
pr_debug("%s:%s:%d, free the page!",
skdev->name, __func__, __LINE__);
free_page((unsigned long)req->buffer);
req->buffer = NULL;
__free_page(bio->bi_io_vec->bv_page);
}

if (unlikely(error)) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/swim.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ static void redo_fd_request(struct request_queue *q)
case READ:
err = floppy_read_sectors(fs, blk_rq_pos(req),
blk_rq_cur_sectors(req),
req->buffer);
bio_data(req->bio));
break;
}
done:
Expand Down
6 changes: 3 additions & 3 deletions drivers/block/swim3.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static void start_request(struct floppy_state *fs)
swim3_dbg("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%u buf=%p\n",
req->rq_disk->disk_name, req->cmd,
(long)blk_rq_pos(req), blk_rq_sectors(req),
req->buffer);
bio_data(req->bio));
swim3_dbg(" errors=%d current_nr_sectors=%u\n",
req->errors, blk_rq_cur_sectors(req));
#endif
Expand Down Expand Up @@ -479,11 +479,11 @@ static inline void setup_transfer(struct floppy_state *fs)
/* Set up 3 dma commands: write preamble, data, postamble */
init_dma(cp, OUTPUT_MORE, write_preamble, sizeof(write_preamble));
++cp;
init_dma(cp, OUTPUT_MORE, req->buffer, 512);
init_dma(cp, OUTPUT_MORE, bio_data(req->bio), 512);
++cp;
init_dma(cp, OUTPUT_LAST, write_postamble, sizeof(write_postamble));
} else {
init_dma(cp, INPUT_LAST, req->buffer, n * 512);
init_dma(cp, INPUT_LAST, bio_data(req->bio), n * 512);
}
++cp;
out_le16(&cp->command, DBDMA_STOP);
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/xen-blkfront.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,10 @@ static void do_blkif_request(struct request_queue *rq)
}

pr_debug("do_blk_req %p: cmd %p, sec %lx, "
"(%u/%u) buffer:%p [%s]\n",
"(%u/%u) [%s]\n",
req, req->cmd, (unsigned long)blk_rq_pos(req),
blk_rq_cur_sectors(req), blk_rq_sectors(req),
req->buffer, rq_data_dir(req) ? "write" : "read");
rq_data_dir(req) ? "write" : "read");

if (blkif_queue_request(req)) {
blk_requeue_request(rq, req);
Expand Down
Loading

0 comments on commit b4f42e2

Please sign in to comment.