Skip to content

Commit

Permalink
block: misc updates to blk_get_queue()
Browse files Browse the repository at this point in the history
* blk_get_queue() is peculiar in that it returns 0 on success and 1 on
  failure instead of 0 / -errno or boolean.  Update it such that it
  returns %true on success and %false on failure.

* Make sure the caller checks for the return value.

* Separate out __blk_get_queue() which doesn't check whether @q is
  dead and put it in blk.h.  This will be used later.

This patch doesn't introduce any functional changes.

Signed-off-by: Tejun Heo <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
htejun authored and axboe committed Dec 13, 2011
1 parent 6e736be commit 09ac46c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,14 +626,14 @@ blk_init_allocated_queue_node(struct request_queue *q, request_fn_proc *rfn,
}
EXPORT_SYMBOL(blk_init_allocated_queue_node);

int blk_get_queue(struct request_queue *q)
bool blk_get_queue(struct request_queue *q)
{
if (likely(!blk_queue_dead(q))) {
kobject_get(&q->kobj);
return 0;
__blk_get_queue(q);
return true;
}

return 1;
return false;
}
EXPORT_SYMBOL(blk_get_queue);

Expand Down
5 changes: 5 additions & 0 deletions block/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ extern struct kmem_cache *blk_requestq_cachep;
extern struct kobj_type blk_queue_ktype;
extern struct ida blk_queue_ida;

static inline void __blk_get_queue(struct request_queue *q)
{
kobject_get(&q->kobj);
}

void init_request_from_bio(struct request *req, struct bio *bio);
void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
struct bio *bio);
Expand Down
4 changes: 1 addition & 3 deletions block/bsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,10 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
struct file *file)
{
struct bsg_device *bd;
int ret;
#ifdef BSG_DEBUG
unsigned char buf[32];
#endif
ret = blk_get_queue(rq);
if (ret)
if (!blk_get_queue(rq))
return ERR_PTR(-ENXIO);

bd = bsg_alloc_device();
Expand Down
2 changes: 1 addition & 1 deletion block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ void add_disk(struct gendisk *disk)
* Take an extra ref on queue which will be put on disk_release()
* so that it sticks around as long as @disk is there.
*/
WARN_ON_ONCE(blk_get_queue(disk->queue));
WARN_ON_ONCE(!blk_get_queue(disk->queue));

retval = sysfs_create_link(&disk_to_dev(disk)->kobj, &bdi->dev->kobj,
"bdi");
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/scsi_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
kfree(sdev);
goto out;
}
blk_get_queue(sdev->request_queue);
WARN_ON_ONCE(!blk_get_queue(sdev->request_queue));
sdev->request_queue->queuedata = sdev;
scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);

Expand Down
2 changes: 1 addition & 1 deletion include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ extern int blk_rq_map_sg(struct request_queue *, struct request *, struct scatte
extern void blk_dump_rq_flags(struct request *, char *);
extern long nr_blockdev_pages(void);

int blk_get_queue(struct request_queue *);
bool __must_check blk_get_queue(struct request_queue *);
struct request_queue *blk_alloc_queue(gfp_t);
struct request_queue *blk_alloc_queue_node(gfp_t, int);
extern void blk_put_queue(struct request_queue *);
Expand Down

0 comments on commit 09ac46c

Please sign in to comment.