Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block/bsg: move queue creation into bsg_setup_queue

Simply the boilerplate code needed for bsg nodes a bit.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Jens Axboe <axboe@fb.com>

authored by

Christoph Hellwig and committed by
Jens Axboe
8ae94eb6 e9c787e6

+25 -52
+11 -10
block/bsg-lib.c
··· 177 177 * 178 178 * Drivers/subsys should pass this to the queue init function. 179 179 */ 180 - void bsg_request_fn(struct request_queue *q) 180 + static void bsg_request_fn(struct request_queue *q) 181 181 __releases(q->queue_lock) 182 182 __acquires(q->queue_lock) 183 183 { ··· 214 214 put_device(dev); 215 215 spin_lock_irq(q->queue_lock); 216 216 } 217 - EXPORT_SYMBOL_GPL(bsg_request_fn); 218 217 219 218 /** 220 219 * bsg_setup_queue - Create and add the bsg hooks so we can receive requests 221 220 * @dev: device to attach bsg device to 222 - * @q: request queue setup by caller 223 221 * @name: device to give bsg device 224 222 * @job_fn: bsg job handler 225 223 * @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. 229 224 */ 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) 232 227 { 228 + struct request_queue *q; 233 229 int ret; 230 + 231 + q = blk_init_queue(bsg_request_fn, NULL); 232 + if (!q) 233 + return ERR_PTR(-ENOMEM); 234 234 235 235 q->queuedata = dev; 236 236 q->bsg_job_size = dd_job_size; ··· 243 243 if (ret) { 244 244 printk(KERN_ERR "%s: bsg interface failed to " 245 245 "initialize - register queue\n", dev->kobj.name); 246 - return ret; 246 + blk_cleanup_queue(q); 247 + return ERR_PTR(ret); 247 248 } 248 249 249 - return 0; 250 + return q; 250 251 } 251 252 EXPORT_SYMBOL_GPL(bsg_setup_queue);
+8 -28
drivers/scsi/scsi_transport_fc.c
··· 3765 3765 struct device *dev = &shost->shost_gendev; 3766 3766 struct fc_internal *i = to_fc_internal(shost->transportt); 3767 3767 struct request_queue *q; 3768 - int err; 3769 3768 char bsg_name[20]; 3770 3769 3771 3770 fc_host->rqst_q = NULL; ··· 3775 3776 snprintf(bsg_name, sizeof(bsg_name), 3776 3777 "fc_host%d", shost->host_no); 3777 3778 3778 - q = blk_init_queue(bsg_request_fn, NULL); 3779 - if (!q) { 3780 - dev_err(dev, 3781 - "fc_host%d: bsg interface failed to initialize - no request queue\n", 3782 - shost->host_no); 3783 - return -ENOMEM; 3784 - } 3785 - 3786 - __scsi_init_queue(shost, q); 3787 - err = bsg_setup_queue(dev, q, bsg_name, fc_bsg_dispatch, 3788 - i->f->dd_bsg_size); 3789 - if (err) { 3779 + q = bsg_setup_queue(dev, bsg_name, fc_bsg_dispatch, i->f->dd_bsg_size); 3780 + if (IS_ERR(q)) { 3790 3781 dev_err(dev, 3791 3782 "fc_host%d: bsg interface failed to initialize - setup queue\n", 3792 3783 shost->host_no); 3793 - blk_cleanup_queue(q); 3794 - return err; 3784 + return PTR_ERR(q); 3795 3785 } 3786 + __scsi_init_queue(shost, q); 3796 3787 blk_queue_rq_timed_out(q, fc_bsg_job_timeout); 3797 3788 blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT); 3798 3789 fc_host->rqst_q = q; ··· 3814 3825 struct device *dev = &rport->dev; 3815 3826 struct fc_internal *i = to_fc_internal(shost->transportt); 3816 3827 struct request_queue *q; 3817 - int err; 3818 3828 3819 3829 rport->rqst_q = NULL; 3820 3830 3821 3831 if (!i->f->bsg_request) 3822 3832 return -ENOTSUPP; 3823 3833 3824 - q = blk_init_queue(bsg_request_fn, NULL); 3825 - if (!q) { 3826 - dev_err(dev, "bsg interface failed to initialize - no request queue\n"); 3827 - return -ENOMEM; 3828 - } 3829 - 3830 - __scsi_init_queue(shost, q); 3831 - err = bsg_setup_queue(dev, q, NULL, fc_bsg_dispatch, i->f->dd_bsg_size); 3832 - if (err) { 3834 + q = bsg_setup_queue(dev, NULL, fc_bsg_dispatch, i->f->dd_bsg_size); 3835 + if (IS_ERR(q)) { 3833 3836 dev_err(dev, "failed to setup bsg queue\n"); 3834 - blk_cleanup_queue(q); 3835 - return err; 3837 + return PTR_ERR(q); 3836 3838 } 3837 - 3839 + __scsi_init_queue(shost, q); 3838 3840 blk_queue_prep_rq(q, fc_bsg_rport_prep); 3839 3841 blk_queue_rq_timed_out(q, fc_bsg_job_timeout); 3840 3842 blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
+4 -11
drivers/scsi/scsi_transport_iscsi.c
··· 1537 1537 struct iscsi_internal *i = to_iscsi_internal(shost->transportt); 1538 1538 struct request_queue *q; 1539 1539 char bsg_name[20]; 1540 - int ret; 1541 1540 1542 1541 if (!i->iscsi_transport->bsg_request) 1543 1542 return -ENOTSUPP; 1544 1543 1545 1544 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)) { 1554 1547 shost_printk(KERN_ERR, shost, "bsg interface failed to " 1555 1548 "initialize - no request queue\n"); 1556 - blk_cleanup_queue(q); 1557 - return ret; 1549 + return PTR_ERR(q); 1558 1550 } 1551 + __scsi_init_queue(shost, q); 1559 1552 1560 1553 ihost->bsg_q = q; 1561 1554 return 0;
+2 -3
include/linux/bsg-lib.h
··· 66 66 67 67 void bsg_job_done(struct bsg_job *job, int result, 68 68 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); 72 71 void bsg_job_put(struct bsg_job *job); 73 72 int __must_check bsg_job_get(struct bsg_job *job); 74 73