Skip to content

Commit 8ae94eb

Browse files
Christoph Hellwigaxboe
authored andcommitted
block/bsg: move queue creation into bsg_setup_queue
Simply the boilerplate code needed for bsg nodes a bit. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent e9c787e commit 8ae94eb

File tree

4 files changed

+25
-52
lines changed

4 files changed

+25
-52
lines changed

block/bsg-lib.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static int bsg_create_job(struct device *dev, struct request *req)
177177
*
178178
* Drivers/subsys should pass this to the queue init function.
179179
*/
180-
void bsg_request_fn(struct request_queue *q)
180+
static void bsg_request_fn(struct request_queue *q)
181181
__releases(q->queue_lock)
182182
__acquires(q->queue_lock)
183183
{
@@ -214,24 +214,24 @@ void bsg_request_fn(struct request_queue *q)
214214
put_device(dev);
215215
spin_lock_irq(q->queue_lock);
216216
}
217-
EXPORT_SYMBOL_GPL(bsg_request_fn);
218217

219218
/**
220219
* bsg_setup_queue - Create and add the bsg hooks so we can receive requests
221220
* @dev: device to attach bsg device to
222-
* @q: request queue setup by caller
223221
* @name: device to give bsg device
224222
* @job_fn: bsg job handler
225223
* @dd_job_size: size of LLD data needed for each job
226-
*
227-
* The caller should have setup the reuqest queue with bsg_request_fn
228-
* as the request_fn.
229224
*/
230-
int bsg_setup_queue(struct device *dev, struct request_queue *q,
231-
char *name, bsg_job_fn *job_fn, int dd_job_size)
225+
struct request_queue *bsg_setup_queue(struct device *dev, char *name,
226+
bsg_job_fn *job_fn, int dd_job_size)
232227
{
228+
struct request_queue *q;
233229
int ret;
234230

231+
q = blk_init_queue(bsg_request_fn, NULL);
232+
if (!q)
233+
return ERR_PTR(-ENOMEM);
234+
235235
q->queuedata = dev;
236236
q->bsg_job_size = dd_job_size;
237237
q->bsg_job_fn = job_fn;
@@ -243,9 +243,10 @@ int bsg_setup_queue(struct device *dev, struct request_queue *q,
243243
if (ret) {
244244
printk(KERN_ERR "%s: bsg interface failed to "
245245
"initialize - register queue\n", dev->kobj.name);
246-
return ret;
246+
blk_cleanup_queue(q);
247+
return ERR_PTR(ret);
247248
}
248249

249-
return 0;
250+
return q;
250251
}
251252
EXPORT_SYMBOL_GPL(bsg_setup_queue);

drivers/scsi/scsi_transport_fc.c

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3765,7 +3765,6 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host)
37653765
struct device *dev = &shost->shost_gendev;
37663766
struct fc_internal *i = to_fc_internal(shost->transportt);
37673767
struct request_queue *q;
3768-
int err;
37693768
char bsg_name[20];
37703769

37713770
fc_host->rqst_q = NULL;
@@ -3776,24 +3775,14 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host)
37763775
snprintf(bsg_name, sizeof(bsg_name),
37773776
"fc_host%d", shost->host_no);
37783777

3779-
q = blk_init_queue(bsg_request_fn, NULL);
3780-
if (!q) {
3781-
dev_err(dev,
3782-
"fc_host%d: bsg interface failed to initialize - no request queue\n",
3783-
shost->host_no);
3784-
return -ENOMEM;
3785-
}
3786-
3787-
__scsi_init_queue(shost, q);
3788-
err = bsg_setup_queue(dev, q, bsg_name, fc_bsg_dispatch,
3789-
i->f->dd_bsg_size);
3790-
if (err) {
3778+
q = bsg_setup_queue(dev, bsg_name, fc_bsg_dispatch, i->f->dd_bsg_size);
3779+
if (IS_ERR(q)) {
37913780
dev_err(dev,
37923781
"fc_host%d: bsg interface failed to initialize - setup queue\n",
37933782
shost->host_no);
3794-
blk_cleanup_queue(q);
3795-
return err;
3783+
return PTR_ERR(q);
37963784
}
3785+
__scsi_init_queue(shost, q);
37973786
blk_queue_rq_timed_out(q, fc_bsg_job_timeout);
37983787
blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT);
37993788
fc_host->rqst_q = q;
@@ -3825,27 +3814,18 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport)
38253814
struct device *dev = &rport->dev;
38263815
struct fc_internal *i = to_fc_internal(shost->transportt);
38273816
struct request_queue *q;
3828-
int err;
38293817

38303818
rport->rqst_q = NULL;
38313819

38323820
if (!i->f->bsg_request)
38333821
return -ENOTSUPP;
38343822

3835-
q = blk_init_queue(bsg_request_fn, NULL);
3836-
if (!q) {
3837-
dev_err(dev, "bsg interface failed to initialize - no request queue\n");
3838-
return -ENOMEM;
3839-
}
3840-
3841-
__scsi_init_queue(shost, q);
3842-
err = bsg_setup_queue(dev, q, NULL, fc_bsg_dispatch, i->f->dd_bsg_size);
3843-
if (err) {
3823+
q = bsg_setup_queue(dev, NULL, fc_bsg_dispatch, i->f->dd_bsg_size);
3824+
if (IS_ERR(q)) {
38443825
dev_err(dev, "failed to setup bsg queue\n");
3845-
blk_cleanup_queue(q);
3846-
return err;
3826+
return PTR_ERR(q);
38473827
}
3848-
3828+
__scsi_init_queue(shost, q);
38493829
blk_queue_prep_rq(q, fc_bsg_rport_prep);
38503830
blk_queue_rq_timed_out(q, fc_bsg_job_timeout);
38513831
blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);

drivers/scsi/scsi_transport_iscsi.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,25 +1537,18 @@ iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
15371537
struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
15381538
struct request_queue *q;
15391539
char bsg_name[20];
1540-
int ret;
15411540

15421541
if (!i->iscsi_transport->bsg_request)
15431542
return -ENOTSUPP;
15441543

15451544
snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no);
1546-
1547-
q = blk_init_queue(bsg_request_fn, NULL);
1548-
if (!q)
1549-
return -ENOMEM;
1550-
1551-
__scsi_init_queue(shost, q);
1552-
ret = bsg_setup_queue(dev, q, bsg_name, iscsi_bsg_host_dispatch, 0);
1553-
if (ret) {
1545+
q = bsg_setup_queue(dev, bsg_name, iscsi_bsg_host_dispatch, 0);
1546+
if (IS_ERR(q)) {
15541547
shost_printk(KERN_ERR, shost, "bsg interface failed to "
15551548
"initialize - no request queue\n");
1556-
blk_cleanup_queue(q);
1557-
return ret;
1549+
return PTR_ERR(q);
15581550
}
1551+
__scsi_init_queue(shost, q);
15591552

15601553
ihost->bsg_q = q;
15611554
return 0;

include/linux/bsg-lib.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ struct bsg_job {
6666

6767
void bsg_job_done(struct bsg_job *job, int result,
6868
unsigned int reply_payload_rcv_len);
69-
int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
70-
bsg_job_fn *job_fn, int dd_job_size);
71-
void bsg_request_fn(struct request_queue *q);
69+
struct request_queue *bsg_setup_queue(struct device *dev, char *name,
70+
bsg_job_fn *job_fn, int dd_job_size);
7271
void bsg_job_put(struct bsg_job *job);
7372
int __must_check bsg_job_get(struct bsg_job *job);
7473

0 commit comments

Comments
 (0)