Skip to content

Commit

Permalink
block: remove support for bio remapping from ->make_request
Browse files Browse the repository at this point in the history
There is very little benefit in allowing to let a ->make_request
instance update the bios device and sector and loop around it in
__generic_make_request when we can archive the same through calling
generic_make_request from the driver and letting the loop in
generic_make_request handle it.

Note that various drivers got the return value from ->make_request and
returned non-zero values for errors.

Signed-off-by: Christoph Hellwig <[email protected]>
Acked-by: NeilBrown <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and Jens Axboe committed Sep 12, 2011
1 parent c20e8de commit 5a7bbad
Show file tree
Hide file tree
Showing 25 changed files with 151 additions and 215 deletions.
3 changes: 1 addition & 2 deletions arch/m68k/emu/nfblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct nfhd_device {
struct gendisk *disk;
};

static int nfhd_make_request(struct request_queue *queue, struct bio *bio)
static void nfhd_make_request(struct request_queue *queue, struct bio *bio)
{
struct nfhd_device *dev = queue->queuedata;
struct bio_vec *bvec;
Expand All @@ -76,7 +76,6 @@ static int nfhd_make_request(struct request_queue *queue, struct bio *bio)
sec += len;
}
bio_endio(bio, 0);
return 0;
}

static int nfhd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
Expand Down
8 changes: 2 additions & 6 deletions arch/powerpc/sysdev/axonram.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ axon_ram_irq_handler(int irq, void *dev)
* axon_ram_make_request - make_request() method for block device
* @queue, @bio: see blk_queue_make_request()
*/
static int
static void
axon_ram_make_request(struct request_queue *queue, struct bio *bio)
{
struct axon_ram_bank *bank = bio->bi_bdev->bd_disk->private_data;
Expand All @@ -113,16 +113,14 @@ axon_ram_make_request(struct request_queue *queue, struct bio *bio)
struct bio_vec *vec;
unsigned int transfered;
unsigned short idx;
int rc = 0;

phys_mem = bank->io_addr + (bio->bi_sector << AXON_RAM_SECTOR_SHIFT);
phys_end = bank->io_addr + bank->size;
transfered = 0;
bio_for_each_segment(vec, bio, idx) {
if (unlikely(phys_mem + vec->bv_len > phys_end)) {
bio_io_error(bio);
rc = -ERANGE;
break;
return;
}

user_mem = page_address(vec->bv_page) + vec->bv_offset;
Expand All @@ -135,8 +133,6 @@ axon_ram_make_request(struct request_queue *queue, struct bio *bio)
transfered += vec->bv_len;
}
bio_endio(bio, 0);

return rc;
}

/**
Expand Down
153 changes: 62 additions & 91 deletions block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ void init_request_from_bio(struct request *req, struct bio *bio)
blk_rq_bio_prep(req->q, req, bio);
}

int blk_queue_bio(struct request_queue *q, struct bio *bio)
void blk_queue_bio(struct request_queue *q, struct bio *bio)
{
const bool sync = !!(bio->bi_rw & REQ_SYNC);
struct blk_plug *plug;
Expand All @@ -1236,7 +1236,7 @@ int blk_queue_bio(struct request_queue *q, struct bio *bio)
* any locks.
*/
if (attempt_plug_merge(current, q, bio))
goto out;
return;

spin_lock_irq(q->queue_lock);

Expand Down Expand Up @@ -1312,8 +1312,6 @@ int blk_queue_bio(struct request_queue *q, struct bio *bio)
out_unlock:
spin_unlock_irq(q->queue_lock);
}
out:
return 0;
}
EXPORT_SYMBOL_GPL(blk_queue_bio); /* for device mapper only */

Expand Down Expand Up @@ -1441,112 +1439,85 @@ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
static inline void __generic_make_request(struct bio *bio)
{
struct request_queue *q;
sector_t old_sector;
int ret, nr_sectors = bio_sectors(bio);
dev_t old_dev;
int nr_sectors = bio_sectors(bio);
int err = -EIO;
char b[BDEVNAME_SIZE];
struct hd_struct *part;

might_sleep();

if (bio_check_eod(bio, nr_sectors))
goto end_io;

/*
* Resolve the mapping until finished. (drivers are
* still free to implement/resolve their own stacking
* by explicitly returning 0)
*
* NOTE: we don't repeat the blk_size check for each new device.
* Stacking drivers are expected to know what they are doing.
*/
old_sector = -1;
old_dev = 0;
do {
char b[BDEVNAME_SIZE];
struct hd_struct *part;

q = bdev_get_queue(bio->bi_bdev);
if (unlikely(!q)) {
printk(KERN_ERR
"generic_make_request: Trying to access "
"nonexistent block-device %s (%Lu)\n",
bdevname(bio->bi_bdev, b),
(long long) bio->bi_sector);
goto end_io;
}

if (unlikely(!(bio->bi_rw & REQ_DISCARD) &&
nr_sectors > queue_max_hw_sectors(q))) {
printk(KERN_ERR "bio too big device %s (%u > %u)\n",
bdevname(bio->bi_bdev, b),
bio_sectors(bio),
queue_max_hw_sectors(q));
goto end_io;
}

if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
goto end_io;

part = bio->bi_bdev->bd_part;
if (should_fail_request(part, bio->bi_size) ||
should_fail_request(&part_to_disk(part)->part0,
bio->bi_size))
goto end_io;
q = bdev_get_queue(bio->bi_bdev);
if (unlikely(!q)) {
printk(KERN_ERR
"generic_make_request: Trying to access "
"nonexistent block-device %s (%Lu)\n",
bdevname(bio->bi_bdev, b),
(long long) bio->bi_sector);
goto end_io;
}

/*
* If this device has partitions, remap block n
* of partition p to block n+start(p) of the disk.
*/
blk_partition_remap(bio);
if (unlikely(!(bio->bi_rw & REQ_DISCARD) &&
nr_sectors > queue_max_hw_sectors(q))) {
printk(KERN_ERR "bio too big device %s (%u > %u)\n",
bdevname(bio->bi_bdev, b),
bio_sectors(bio),
queue_max_hw_sectors(q));
goto end_io;
}

if (bio_integrity_enabled(bio) && bio_integrity_prep(bio))
goto end_io;
if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
goto end_io;

if (old_sector != -1)
trace_block_bio_remap(q, bio, old_dev, old_sector);
part = bio->bi_bdev->bd_part;
if (should_fail_request(part, bio->bi_size) ||
should_fail_request(&part_to_disk(part)->part0,
bio->bi_size))
goto end_io;

old_sector = bio->bi_sector;
old_dev = bio->bi_bdev->bd_dev;
/*
* If this device has partitions, remap block n
* of partition p to block n+start(p) of the disk.
*/
blk_partition_remap(bio);

if (bio_check_eod(bio, nr_sectors))
goto end_io;
if (bio_integrity_enabled(bio) && bio_integrity_prep(bio))
goto end_io;

/*
* Filter flush bio's early so that make_request based
* drivers without flush support don't have to worry
* about them.
*/
if ((bio->bi_rw & (REQ_FLUSH | REQ_FUA)) && !q->flush_flags) {
bio->bi_rw &= ~(REQ_FLUSH | REQ_FUA);
if (!nr_sectors) {
err = 0;
goto end_io;
}
}
if (bio_check_eod(bio, nr_sectors))
goto end_io;

if ((bio->bi_rw & REQ_DISCARD) &&
(!blk_queue_discard(q) ||
((bio->bi_rw & REQ_SECURE) &&
!blk_queue_secdiscard(q)))) {
err = -EOPNOTSUPP;
/*
* Filter flush bio's early so that make_request based
* drivers without flush support don't have to worry
* about them.
*/
if ((bio->bi_rw & (REQ_FLUSH | REQ_FUA)) && !q->flush_flags) {
bio->bi_rw &= ~(REQ_FLUSH | REQ_FUA);
if (!nr_sectors) {
err = 0;
goto end_io;
}
}

if (blk_throtl_bio(q, &bio))
goto end_io;

/*
* If bio = NULL, bio has been throttled and will be submitted
* later.
*/
if (!bio)
break;

trace_block_bio_queue(q, bio);
if ((bio->bi_rw & REQ_DISCARD) &&
(!blk_queue_discard(q) ||
((bio->bi_rw & REQ_SECURE) &&
!blk_queue_secdiscard(q)))) {
err = -EOPNOTSUPP;
goto end_io;
}

ret = q->make_request_fn(q, bio);
} while (ret);
if (blk_throtl_bio(q, &bio))
goto end_io;

/* if bio = NULL, bio has been throttled and will be submitted later. */
if (!bio)
return;
trace_block_bio_queue(q, bio);
q->make_request_fn(q, bio);
return;

end_io:
Expand Down
14 changes: 6 additions & 8 deletions drivers/block/aoe/aoeblk.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ aoeblk_release(struct gendisk *disk, fmode_t mode)
return 0;
}

static int
static void
aoeblk_make_request(struct request_queue *q, struct bio *bio)
{
struct sk_buff_head queue;
Expand All @@ -172,25 +172,25 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
if (bio == NULL) {
printk(KERN_ERR "aoe: bio is NULL\n");
BUG();
return 0;
return;
}
d = bio->bi_bdev->bd_disk->private_data;
if (d == NULL) {
printk(KERN_ERR "aoe: bd_disk->private_data is NULL\n");
BUG();
bio_endio(bio, -ENXIO);
return 0;
return;
} else if (bio->bi_io_vec == NULL) {
printk(KERN_ERR "aoe: bi_io_vec is NULL\n");
BUG();
bio_endio(bio, -ENXIO);
return 0;
return;
}
buf = mempool_alloc(d->bufpool, GFP_NOIO);
if (buf == NULL) {
printk(KERN_INFO "aoe: buf allocation failure\n");
bio_endio(bio, -ENOMEM);
return 0;
return;
}
memset(buf, 0, sizeof(*buf));
INIT_LIST_HEAD(&buf->bufs);
Expand All @@ -211,7 +211,7 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
spin_unlock_irqrestore(&d->lock, flags);
mempool_free(buf, d->bufpool);
bio_endio(bio, -ENXIO);
return 0;
return;
}

list_add_tail(&buf->bufs, &d->bufq);
Expand All @@ -222,8 +222,6 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)

spin_unlock_irqrestore(&d->lock, flags);
aoenet_xmit(&queue);

return 0;
}

static int
Expand Down
4 changes: 1 addition & 3 deletions drivers/block/brd.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ static int brd_do_bvec(struct brd_device *brd, struct page *page,
return err;
}

static int brd_make_request(struct request_queue *q, struct bio *bio)
static void brd_make_request(struct request_queue *q, struct bio *bio)
{
struct block_device *bdev = bio->bi_bdev;
struct brd_device *brd = bdev->bd_disk->private_data;
Expand Down Expand Up @@ -359,8 +359,6 @@ static int brd_make_request(struct request_queue *q, struct bio *bio)

out:
bio_endio(bio, err);

return 0;
}

#ifdef CONFIG_BLK_DEV_XIP
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/drbd/drbd_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ extern void drbd_free_mdev(struct drbd_conf *mdev);
extern int proc_details;

/* drbd_req */
extern int drbd_make_request(struct request_queue *q, struct bio *bio);
extern void drbd_make_request(struct request_queue *q, struct bio *bio);
extern int drbd_read_remote(struct drbd_conf *mdev, struct drbd_request *req);
extern int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec);
extern int is_valid_ar_handle(struct drbd_request *, sector_t);
Expand Down
8 changes: 4 additions & 4 deletions drivers/block/drbd/drbd_req.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,15 +1073,15 @@ static int drbd_fail_request_early(struct drbd_conf *mdev, int is_write)
return 0;
}

int drbd_make_request(struct request_queue *q, struct bio *bio)
void drbd_make_request(struct request_queue *q, struct bio *bio)
{
unsigned int s_enr, e_enr;
struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata;
unsigned long start_time;

if (drbd_fail_request_early(mdev, bio_data_dir(bio) & WRITE)) {
bio_endio(bio, -EPERM);
return 0;
return;
}

start_time = jiffies;
Expand All @@ -1100,7 +1100,8 @@ int drbd_make_request(struct request_queue *q, struct bio *bio)

if (likely(s_enr == e_enr)) {
inc_ap_bio(mdev, 1);
return drbd_make_request_common(mdev, bio, start_time);
drbd_make_request_common(mdev, bio, start_time);
return;
}

/* can this bio be split generically?
Expand Down Expand Up @@ -1148,7 +1149,6 @@ int drbd_make_request(struct request_queue *q, struct bio *bio)

bio_pair_release(bp);
}
return 0;
}

/* This is called by bio_add_page(). With this function we reduce
Expand Down
5 changes: 2 additions & 3 deletions drivers/block/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ static struct bio *loop_get_bio(struct loop_device *lo)
return bio_list_pop(&lo->lo_bio_list);
}

static int loop_make_request(struct request_queue *q, struct bio *old_bio)
static void loop_make_request(struct request_queue *q, struct bio *old_bio)
{
struct loop_device *lo = q->queuedata;
int rw = bio_rw(old_bio);
Expand All @@ -532,12 +532,11 @@ static int loop_make_request(struct request_queue *q, struct bio *old_bio)
loop_add_bio(lo, old_bio);
wake_up(&lo->lo_event);
spin_unlock_irq(&lo->lo_lock);
return 0;
return;

out:
spin_unlock_irq(&lo->lo_lock);
bio_io_error(old_bio);
return 0;
}

struct switch_request {
Expand Down
Loading

0 comments on commit 5a7bbad

Please sign in to comment.