History

scsi: bsg: Simplify device registration

Use the per-device cdev_device_interface to store the bsg data in the char device inode, and thus remove the need to embedd the bsg_class_device structure in the request_queue.

Christoph Hellwig committed 5 years ago

Commit ead09dd1 parent ba51bda9 files · +108 −277Browse files

Unified · Split

9 files
  1. block/bsg-lib.c +6 −5
  2. block/bsg.c +72 −232
  3. drivers/scsi/scsi_bsg.c +3 −2
  4. drivers/scsi/scsi_priv.h +2 −9
  5. drivers/scsi/scsi_sysfs.c +16 −8
  6. include/linux/blkdev.h +0 −6
  7. include/linux/bsg-lib.h +1 −0
  8. include/linux/bsg.h +6 −15
  9. include/scsi/scsi_device.h +2 −0
block/bsg-lib.c+6−5
@@ -6,6 +6,7 @@ · 5 unmodified lines
6 * Copyright (C) 2011 Red Hat, Inc. All rights reserved.6 * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
7 * Copyright (C) 2011 Mike Christie7 * Copyright (C) 2011 Mike Christie
8 */8 */
9#include <linux/bsg.h>
9#include <linux/slab.h>10#include <linux/slab.h>
10#include <linux/blk-mq.h>11#include <linux/blk-mq.h>
11#include <linux/delay.h>12#include <linux/delay.h>
@@ -19,6 +20,7 @@ · 7 unmodified lines
19 20
20struct bsg_set {21struct bsg_set {
21 struct blk_mq_tag_set tag_set;22 struct blk_mq_tag_set tag_set;
23 struct bsg_device *bd;
22 bsg_job_fn *job_fn;24 bsg_job_fn *job_fn;
23 bsg_timeout_fn *timeout_fn;25 bsg_timeout_fn *timeout_fn;
24};26};
@@ -327,7 +329,7 @@ void bsg_remove_queue(struct request_queue *q) · 302 unmodified lines
327 struct bsg_set *bset =329 struct bsg_set *bset =
328 container_of(q->tag_set, struct bsg_set, tag_set);330 container_of(q->tag_set, struct bsg_set, tag_set);
329 331
330 bsg_unregister_queue(q);332 bsg_unregister_queue(bset->bd);
331 blk_cleanup_queue(q);333 blk_cleanup_queue(q);
332 blk_mq_free_tag_set(&bset->tag_set);334 blk_mq_free_tag_set(&bset->tag_set);
333 kfree(bset);335 kfree(bset);
@@ -396,10 +398,9 @@ struct request_queue *bsg_setup_queue(struct device *dev, const char *name, · 62 unmodified lines
396 q->queuedata = dev;398 q->queuedata = dev;
397 blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);399 blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
398 400
399 ret = bsg_register_queue(q, dev, name, &bsg_transport_ops);401 bset->bd = bsg_register_queue(q, dev, name, &bsg_transport_ops);
400 if (ret) {402 if (IS_ERR(bset->bd)) {
401 printk(KERN_ERR "%s: bsg interface failed to "403 ret = PTR_ERR(bset->bd);
402 "initialize - register queue\n", dev->kobj.name);
403 goto out_cleanup_queue;404 goto out_cleanup_queue;
404 }405 }
405 406
block/bsg.c+72−232
@@ -20,38 +20,29 @@ · 19 unmodified lines
20#define BSG_DESCRIPTION "Block layer SCSI generic (bsg) driver"20#define BSG_DESCRIPTION "Block layer SCSI generic (bsg) driver"
21#define BSG_VERSION "0.4"21#define BSG_VERSION "0.4"
22 22
23#define bsg_dbg(bd, fmt, ...) \
24 pr_debug("%s: " fmt, (bd)->name, ##__VA_ARGS__)
25
26struct bsg_device {23struct bsg_device {
27 struct request_queue *queue;24 struct request_queue *queue;
28 spinlock_t lock;25 const struct bsg_ops *ops;
29 struct hlist_node dev_list;26 struct device device;
30 refcount_t ref_count;27 struct cdev cdev;
31 char name[20];
32 int max_queue;28 int max_queue;
33};29};
34 30
31static inline struct bsg_device *to_bsg_device(struct inode *inode)
32{
33 return container_of(inode->i_cdev, struct bsg_device, cdev);
34}
35
35#define BSG_DEFAULT_CMDS 6436#define BSG_DEFAULT_CMDS 64
36#define BSG_MAX_DEVS 3276837#define BSG_MAX_DEVS 32768
37 38
38static DEFINE_MUTEX(bsg_mutex);39static DEFINE_IDA(bsg_minor_ida);
39static DEFINE_IDR(bsg_minor_idr);
40
41#define BSG_LIST_ARRAY_SIZE 8
42static struct hlist_head bsg_device_list[BSG_LIST_ARRAY_SIZE];
43
44static struct class *bsg_class;40static struct class *bsg_class;
45static int bsg_major;41static int bsg_major;
46 42
47static inline struct hlist_head *bsg_dev_idx_hash(int index)
48{
49 return &bsg_device_list[index & (BSG_LIST_ARRAY_SIZE - 1)];
50}
51
52#define uptr64(val) ((void __user *)(uintptr_t)(val))43#define uptr64(val) ((void __user *)(uintptr_t)(val))
53 44
54static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg)45static int bsg_sg_io(struct bsg_device *bd, fmode_t mode, void __user *uarg)
55{46{
56 struct request *rq;47 struct request *rq;
57 struct bio *bio;48 struct bio *bio;
@@ -61,21 +52,18 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) · 3 unmodified lines
61 if (copy_from_user(&hdr, uarg, sizeof(hdr)))52 if (copy_from_user(&hdr, uarg, sizeof(hdr)))
62 return -EFAULT;53 return -EFAULT;
63 54
64 if (!q->bsg_dev.class_dev)
65 return -ENXIO;
66
67 if (hdr.guard != 'Q')55 if (hdr.guard != 'Q')
68 return -EINVAL;56 return -EINVAL;
69 ret = q->bsg_dev.ops->check_proto(&hdr);57 ret = bd->ops->check_proto(&hdr);
70 if (ret)58 if (ret)
71 return ret;59 return ret;
72 60
73 rq = blk_get_request(q, hdr.dout_xfer_len ?61 rq = blk_get_request(bd->queue, hdr.dout_xfer_len ?
74 REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);62 REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
75 if (IS_ERR(rq))63 if (IS_ERR(rq))
76 return PTR_ERR(rq);64 return PTR_ERR(rq);
77 65
78 ret = q->bsg_dev.ops->fill_hdr(rq, &hdr, mode);66 ret = bd->ops->fill_hdr(rq, &hdr, mode);
79 if (ret) {67 if (ret) {
80 blk_put_request(rq);68 blk_put_request(rq);
81 return ret;69 return ret;
@@ -83,17 +71,17 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) · 1 unmodified line
83 71
84 rq->timeout = msecs_to_jiffies(hdr.timeout);72 rq->timeout = msecs_to_jiffies(hdr.timeout);
85 if (!rq->timeout)73 if (!rq->timeout)
86 rq->timeout = q->sg_timeout;74 rq->timeout = rq->q->sg_timeout;
87 if (!rq->timeout)75 if (!rq->timeout)
88 rq->timeout = BLK_DEFAULT_SG_TIMEOUT;76 rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
89 if (rq->timeout < BLK_MIN_SG_TIMEOUT)77 if (rq->timeout < BLK_MIN_SG_TIMEOUT)
90 rq->timeout = BLK_MIN_SG_TIMEOUT;78 rq->timeout = BLK_MIN_SG_TIMEOUT;
91 79
92 if (hdr.dout_xfer_len) {80 if (hdr.dout_xfer_len) {
93 ret = blk_rq_map_user(q, rq, NULL, uptr64(hdr.dout_xferp),81 ret = blk_rq_map_user(rq->q, rq, NULL, uptr64(hdr.dout_xferp),
94 hdr.dout_xfer_len, GFP_KERNEL);82 hdr.dout_xfer_len, GFP_KERNEL);
95 } else if (hdr.din_xfer_len) {83 } else if (hdr.din_xfer_len) {
96 ret = blk_rq_map_user(q, rq, NULL, uptr64(hdr.din_xferp),84 ret = blk_rq_map_user(rq->q, rq, NULL, uptr64(hdr.din_xferp),
97 hdr.din_xfer_len, GFP_KERNEL);85 hdr.din_xfer_len, GFP_KERNEL);
98 }86 }
99 87
@@ -103,171 +91,50 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) · 3 unmodified lines
103 bio = rq->bio;91 bio = rq->bio;
104 92
105 blk_execute_rq(NULL, rq, !(hdr.flags & BSG_FLAG_Q_AT_TAIL));93 blk_execute_rq(NULL, rq, !(hdr.flags & BSG_FLAG_Q_AT_TAIL));
106 ret = rq->q->bsg_dev.ops->complete_rq(rq, &hdr);94 ret = bd->ops->complete_rq(rq, &hdr);
107 blk_rq_unmap_user(bio);95 blk_rq_unmap_user(bio);
108 96
109out_free_rq:97out_free_rq:
110 rq->q->bsg_dev.ops->free_rq(rq);98 bd->ops->free_rq(rq);
111 blk_put_request(rq);99 blk_put_request(rq);
112 if (!ret && copy_to_user(uarg, &hdr, sizeof(hdr)))100 if (!ret && copy_to_user(uarg, &hdr, sizeof(hdr)))
113 return -EFAULT;101 return -EFAULT;
114 return ret;102 return ret;
115}103}
116 104
117static struct bsg_device *bsg_alloc_device(void)
118{
119 struct bsg_device *bd;
120
121 bd = kzalloc(sizeof(struct bsg_device), GFP_KERNEL);
122 if (unlikely(!bd))
123 return NULL;
124
125 spin_lock_init(&bd->lock);
126 bd->max_queue = BSG_DEFAULT_CMDS;
127 INIT_HLIST_NODE(&bd->dev_list);
128 return bd;
129}
130
131static int bsg_put_device(struct bsg_device *bd)
132{
133 struct request_queue *q = bd->queue;
134
135 mutex_lock(&bsg_mutex);
136
137 if (!refcount_dec_and_test(&bd->ref_count)) {
138 mutex_unlock(&bsg_mutex);
139 return 0;
140 }
141
142 hlist_del(&bd->dev_list);
143 mutex_unlock(&bsg_mutex);
144
145 bsg_dbg(bd, "tearing down\n");
146
147 /*
148 * close can always block
149 */
150 kfree(bd);
151 blk_put_queue(q);
152 return 0;
153}
154
155static struct bsg_device *bsg_add_device(struct inode *inode,
156 struct request_queue *rq,
157 struct file *file)
158{
159 struct bsg_device *bd;
160 unsigned char buf[32];
161
162 lockdep_assert_held(&bsg_mutex);
163
164 if (!blk_get_queue(rq))
165 return ERR_PTR(-ENXIO);
166
167 bd = bsg_alloc_device();
168 if (!bd) {
169 blk_put_queue(rq);
170 return ERR_PTR(-ENOMEM);
171 }
172
173 bd->queue = rq;
174
175 refcount_set(&bd->ref_count, 1);
176 hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode)));
177
178 strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1);
179 bsg_dbg(bd, "bound to <%s>, max queue %d\n",
180 format_dev_t(buf, inode->i_rdev), bd->max_queue);
181
182 return bd;
183}
184
185static struct bsg_device *__bsg_get_device(int minor, struct request_queue *q)
186{
187 struct bsg_device *bd;
188
189 lockdep_assert_held(&bsg_mutex);
190
191 hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) {
192 if (bd->queue == q) {
193 refcount_inc(&bd->ref_count);
194 goto found;
195 }
196 }
197 bd = NULL;
198found:
199 return bd;
200}
201
202static struct bsg_device *bsg_get_device(struct inode *inode, struct file *file)
203{
204 struct bsg_device *bd;
205 struct bsg_class_device *bcd;
206
207 /*
208 * find the class device
209 */
210 mutex_lock(&bsg_mutex);
211 bcd = idr_find(&bsg_minor_idr, iminor(inode));
212
213 if (!bcd) {
214 bd = ERR_PTR(-ENODEV);
215 goto out_unlock;
216 }
217
218 bd = __bsg_get_device(iminor(inode), bcd->queue);
219 if (!bd)
220 bd = bsg_add_device(inode, bcd->queue, file);
221
222out_unlock:
223 mutex_unlock(&bsg_mutex);
224 return bd;
225}
226
227static int bsg_open(struct inode *inode, struct file *file)105static int bsg_open(struct inode *inode, struct file *file)
228{106{
229 struct bsg_device *bd;107 if (!blk_get_queue(to_bsg_device(inode)->queue))
230 108 return -ENXIO;
231 bd = bsg_get_device(inode, file);
232
233 if (IS_ERR(bd))
234 return PTR_ERR(bd);
235
236 file->private_data = bd;
237 return 0;109 return 0;
238}110}
239 111
240static int bsg_release(struct inode *inode, struct file *file)112static int bsg_release(struct inode *inode, struct file *file)
241{113{
242 struct bsg_device *bd = file->private_data;114 blk_put_queue(to_bsg_device(inode)->queue);
243 115 return 0;
244 file->private_data = NULL;
245 return bsg_put_device(bd);
246}116}
247 117
248static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg)118static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg)
249{119{
250 return put_user(bd->max_queue, uarg);120 return put_user(READ_ONCE(bd->max_queue), uarg);
251}121}
252 122
253static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg)123static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg)
254{124{
255 int queue;125 int max_queue;
256 126
257 if (get_user(queue, uarg))127 if (get_user(max_queue, uarg))
258 return -EFAULT;128 return -EFAULT;
259 if (queue < 1)129 if (max_queue < 1)
260 return -EINVAL;130 return -EINVAL;
261 131 WRITE_ONCE(bd->max_queue, max_queue);
262 spin_lock_irq(&bd->lock);
263 bd->max_queue = queue;
264 spin_unlock_irq(&bd->lock);
265 return 0;132 return 0;
266}133}
267 134
268static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)135static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
269{136{
270 struct bsg_device *bd = file->private_data;137 struct bsg_device *bd = to_bsg_device(file_inode(file));
271 struct request_queue *q = bd->queue;138 struct request_queue *q = bd->queue;
272 void __user *uarg = (void __user *) arg;139 void __user *uarg = (void __user *) arg;
273 int __user *intp = uarg;140 int __user *intp = uarg;
@@ -312,7 +179,7 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 38 unmodified lines
312 case SG_EMULATED_HOST:179 case SG_EMULATED_HOST:
313 return put_user(1, intp);180 return put_user(1, intp);
314 case SG_IO:181 case SG_IO:
315 return bsg_sg_io(q, file->f_mode, uarg);182 return bsg_sg_io(bd, file->f_mode, uarg);
316 case SCSI_IOCTL_SEND_COMMAND:183 case SCSI_IOCTL_SEND_COMMAND:
317 pr_warn_ratelimited("%s: calling unsupported SCSI_IOCTL_SEND_COMMAND\n",184 pr_warn_ratelimited("%s: calling unsupported SCSI_IOCTL_SEND_COMMAND\n",
318 current->comm);185 current->comm);
@@ -331,83 +198,66 @@ static const struct file_operations bsg_fops = { · 12 unmodified lines
331 .llseek = default_llseek,198 .llseek = default_llseek,
332};199};
333 200
334void bsg_unregister_queue(struct request_queue *q)201void bsg_unregister_queue(struct bsg_device *bd)
335{202{
336 struct bsg_class_device *bcd = &q->bsg_dev;203 if (bd->queue->kobj.sd)
337 204 sysfs_remove_link(&bd->queue->kobj, "bsg");
338 if (!bcd->class_dev)205 cdev_device_del(&bd->cdev, &bd->device);
339 return;206 ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt));
340 207 kfree(bd);
341 mutex_lock(&bsg_mutex);
342 idr_remove(&bsg_minor_idr, bcd->minor);
343 if (q->kobj.sd)
344 sysfs_remove_link(&q->kobj, "bsg");
345 device_unregister(bcd->class_dev);
346 bcd->class_dev = NULL;
347 mutex_unlock(&bsg_mutex);
348}208}
349EXPORT_SYMBOL_GPL(bsg_unregister_queue);209EXPORT_SYMBOL_GPL(bsg_unregister_queue);
350 210
351int bsg_register_queue(struct request_queue *q, struct device *parent,211struct bsg_device *bsg_register_queue(struct request_queue *q,
352 const char *name, const struct bsg_ops *ops)212 struct device *parent, const char *name,
213 const struct bsg_ops *ops)
353{214{
354 struct bsg_class_device *bcd;215 struct bsg_device *bd;
355 dev_t dev;
356 int ret;216 int ret;
357 struct device *class_dev = NULL;
358
359 /*
360 * we need a proper transport to send commands, not a stacked device
361 */
362 if (!queue_is_mq(q))
363 return 0;
364 217
365 bcd = &q->bsg_dev;218 bd = kzalloc(sizeof(*bd), GFP_KERNEL);
366 memset(bcd, 0, sizeof(*bcd));219 if (!bd)
367 220 return ERR_PTR(-ENOMEM);
368 mutex_lock(&bsg_mutex);221 bd->max_queue = BSG_DEFAULT_CMDS;
222 bd->queue = q;
223 bd->ops = ops;
369 224
370 ret = idr_alloc(&bsg_minor_idr, bcd, 0, BSG_MAX_DEVS, GFP_KERNEL);225 ret = ida_simple_get(&bsg_minor_ida, 0, BSG_MAX_DEVS, GFP_KERNEL);
371 if (ret < 0) {226 if (ret < 0) {
372 if (ret == -ENOSPC) {227 if (ret == -ENOSPC)
373 printk(KERN_ERR "bsg: too many bsg devices\n");228 dev_err(parent, "bsg: too many bsg devices\n");
374 ret = -EINVAL;229 goto out_kfree;
375 }
376 goto unlock;
377 }
378
379 bcd->minor = ret;
380 bcd->queue = q;
381 bcd->ops = ops;
382 dev = MKDEV(bsg_major, bcd->minor);
383 class_dev = device_create(bsg_class, parent, dev, NULL, "%s", name);
384 if (IS_ERR(class_dev)) {
385 ret = PTR_ERR(class_dev);
386 goto idr_remove;
387 }230 }
388 bcd->class_dev = class_dev;231 bd->device.devt = MKDEV(bsg_major, ret);
232 bd->device.class = bsg_class;
233 bd->device.parent = parent;
234 dev_set_name(&bd->device, "%s", name);
235 device_initialize(&bd->device);
236
237 cdev_init(&bd->cdev, &bsg_fops);
238 bd->cdev.owner = THIS_MODULE;
239 ret = cdev_device_add(&bd->cdev, &bd->device);
240 if (ret)
241 goto out_ida_remove;
389 242
390 if (q->kobj.sd) {243 if (q->kobj.sd) {
391 ret = sysfs_create_link(&q->kobj, &bcd->class_dev->kobj, "bsg");244 ret = sysfs_create_link(&q->kobj, &bd->device.kobj, "bsg");
392 if (ret)245 if (ret)
393 goto unregister_class_dev;246 goto out_device_del;
394 }247 }
395 248
396 mutex_unlock(&bsg_mutex);249 return bd;
397 return 0;
398 250
399unregister_class_dev:251out_device_del:
400 device_unregister(class_dev);252 cdev_device_del(&bd->cdev, &bd->device);
401idr_remove:253out_ida_remove:
402 idr_remove(&bsg_minor_idr, bcd->minor);254 ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt));
403unlock:255out_kfree:
404 mutex_unlock(&bsg_mutex);256 kfree(bd);
405 return ret;257 return ERR_PTR(ret);
406}258}
407EXPORT_SYMBOL_GPL(bsg_register_queue);259EXPORT_SYMBOL_GPL(bsg_register_queue);
408 260
409static struct cdev bsg_cdev;
410
411static char *bsg_devnode(struct device *dev, umode_t *mode)261static char *bsg_devnode(struct device *dev, umode_t *mode)
412{262{
413 return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev));263 return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev));
@@ -415,11 +265,8 @@ static char *bsg_devnode(struct device *dev, umode_t *mode) · 1 unmodified line
415 265
416static int __init bsg_init(void)266static int __init bsg_init(void)
417{267{
418 int ret, i;
419 dev_t devid;268 dev_t devid;
420 269 int ret;
421 for (i = 0; i < BSG_LIST_ARRAY_SIZE; i++)
422 INIT_HLIST_HEAD(&bsg_device_list[i]);
423 270
424 bsg_class = class_create(THIS_MODULE, "bsg");271 bsg_class = class_create(THIS_MODULE, "bsg");
425 if (IS_ERR(bsg_class))272 if (IS_ERR(bsg_class))
@@ -429,19 +276,12 @@ static int __init bsg_init(void) · 3 unmodified lines
429 ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");276 ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
430 if (ret)277 if (ret)
431 goto destroy_bsg_class;278 goto destroy_bsg_class;
432
433 bsg_major = MAJOR(devid);279 bsg_major = MAJOR(devid);
434 280
435 cdev_init(&bsg_cdev, &bsg_fops);
436 ret = cdev_add(&bsg_cdev, MKDEV(bsg_major, 0), BSG_MAX_DEVS);
437 if (ret)
438 goto unregister_chrdev;
439
440 printk(KERN_INFO BSG_DESCRIPTION " version " BSG_VERSION281 printk(KERN_INFO BSG_DESCRIPTION " version " BSG_VERSION
441 " loaded (major %d)\n", bsg_major);282 " loaded (major %d)\n", bsg_major);
442 return 0;283 return 0;
443unregister_chrdev:284
444 unregister_chrdev_region(MKDEV(bsg_major, 0), BSG_MAX_DEVS);
445destroy_bsg_class:285destroy_bsg_class:
446 class_destroy(bsg_class);286 class_destroy(bsg_class);
447 return ret;287 return ret;
drivers/scsi/scsi_bsg.c+3−2
@@ -89,7 +89,8 @@ static const struct bsg_ops scsi_bsg_ops = { · 88 unmodified lines
89 .free_rq = scsi_bsg_free_rq,89 .free_rq = scsi_bsg_free_rq,
90};90};
91 91
92int scsi_bsg_register_queue(struct request_queue *q, struct device *parent)92struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev)
93{93{
94 return bsg_register_queue(q, parent, dev_name(parent), &scsi_bsg_ops);94 return bsg_register_queue(sdev->request_queue, &sdev->sdev_gendev,
95 dev_name(&sdev->sdev_gendev), &scsi_bsg_ops);
95}96}
drivers/scsi/scsi_priv.h+2−9
@@ -7,6 +7,7 @@ · 6 unmodified lines
7#include <scsi/scsi_device.h>7#include <scsi/scsi_device.h>
8#include <linux/sbitmap.h>8#include <linux/sbitmap.h>
9 9
10struct bsg_device;
10struct request_queue;11struct request_queue;
11struct request;12struct request;
12struct scsi_cmnd;13struct scsi_cmnd;
@@ -180,15 +181,7 @@ static inline void scsi_dh_add_device(struct scsi_device *sdev) { } · 167 unmodified lines
180static inline void scsi_dh_release_device(struct scsi_device *sdev) { }181static inline void scsi_dh_release_device(struct scsi_device *sdev) { }
181#endif182#endif
182 183
183#ifdef CONFIG_BLK_DEV_BSG184struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev);
184int scsi_bsg_register_queue(struct request_queue *q, struct device *parent);
185#else
186static inline int scsi_bsg_register_queue(struct request_queue *q,
187 struct device *parent)
188{
189 return 0;
190}
191#endif
192 185
193extern int scsi_device_max_queue_depth(struct scsi_device *sdev);186extern int scsi_device_max_queue_depth(struct scsi_device *sdev);
194 187
drivers/scsi/scsi_sysfs.c+16−8
@@ -13,6 +13,7 @@ · 12 unmodified lines
13#include <linux/blkdev.h>13#include <linux/blkdev.h>
14#include <linux/device.h>14#include <linux/device.h>
15#include <linux/pm_runtime.h>15#include <linux/pm_runtime.h>
16#include <linux/bsg.h>
16 17
17#include <scsi/scsi.h>18#include <scsi/scsi.h>
18#include <scsi/scsi_device.h>19#include <scsi/scsi_device.h>
@@ -1327,7 +1328,6 @@ static int scsi_target_add(struct scsi_target *starget) · 1308 unmodified lines
1327int scsi_sysfs_add_sdev(struct scsi_device *sdev)1328int scsi_sysfs_add_sdev(struct scsi_device *sdev)
1328{1329{
1329 int error, i;1330 int error, i;
1330 struct request_queue *rq = sdev->request_queue;
1331 struct scsi_target *starget = sdev->sdev_target;1331 struct scsi_target *starget = sdev->sdev_target;
1332 1332
1333 error = scsi_target_add(starget);1333 error = scsi_target_add(starget);
@@ -1366,12 +1366,19 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) · 32 unmodified lines
1366 transport_add_device(&sdev->sdev_gendev);1366 transport_add_device(&sdev->sdev_gendev);
1367 sdev->is_visible = 1;1367 sdev->is_visible = 1;
1368 1368
1369 error = scsi_bsg_register_queue(rq, &sdev->sdev_gendev);1369 if (IS_ENABLED(CONFIG_BLK_DEV_BSG)) {
1370 if (error)1370 sdev->bsg_dev = scsi_bsg_register_queue(sdev);
1371 /* we're treating error on bsg register as non-fatal,1371 if (IS_ERR(sdev->bsg_dev)) {
1372 * so pretend nothing went wrong */1372 /*
1373 sdev_printk(KERN_INFO, sdev,1373 * We're treating error on bsg register as non-fatal, so
1374 "Failed to register bsg queue, errno=%d\n", error);1374 * pretend nothing went wrong.
1375 */
1376 sdev_printk(KERN_INFO, sdev,
1377 "Failed to register bsg queue, errno=%d\n",
1378 error);
1379 sdev->bsg_dev = NULL;
1380 }
1381 }
1375 1382
1376 /* add additional host specific attributes */1383 /* add additional host specific attributes */
1377 if (sdev->host->hostt->sdev_attrs) {1384 if (sdev->host->hostt->sdev_attrs) {
@@ -1433,7 +1440,8 @@ void __scsi_remove_device(struct scsi_device *sdev) · 55 unmodified lines
1433 sysfs_remove_groups(&sdev->sdev_gendev.kobj,1440 sysfs_remove_groups(&sdev->sdev_gendev.kobj,
1434 sdev->host->hostt->sdev_groups);1441 sdev->host->hostt->sdev_groups);
1435 1442
1436 bsg_unregister_queue(sdev->request_queue);1443 if (IS_ENABLED(CONFIG_BLK_DEV_BSG) && sdev->bsg_dev)
1444 bsg_unregister_queue(sdev->bsg_dev);
1437 device_unregister(&sdev->sdev_dev);1445 device_unregister(&sdev->sdev_dev);
1438 transport_remove_device(dev);1446 transport_remove_device(dev);
1439 device_del(dev);1447 device_del(dev);
include/linux/blkdev.h+0−6
@@ -18,7 +18,6 @@ · 17 unmodified lines
18#include <linux/bio.h>18#include <linux/bio.h>
19#include <linux/stringify.h>19#include <linux/stringify.h>
20#include <linux/gfp.h>20#include <linux/gfp.h>
21#include <linux/bsg.h>
22#include <linux/smp.h>21#include <linux/smp.h>
23#include <linux/rcupdate.h>22#include <linux/rcupdate.h>
24#include <linux/percpu-refcount.h>23#include <linux/percpu-refcount.h>
@@ -33,7 +32,6 @@ struct elevator_queue; · 8 unmodified lines
33struct blk_trace;32struct blk_trace;
34struct request;33struct request;
35struct sg_io_hdr;34struct sg_io_hdr;
36struct bsg_job;
37struct blkcg_gq;35struct blkcg_gq;
38struct blk_flush_queue;36struct blk_flush_queue;
39struct pr_ops;37struct pr_ops;
@@ -535,10 +533,6 @@ struct request_queue { · 495 unmodified lines
535 533
536 int mq_freeze_depth;534 int mq_freeze_depth;
537 535
538#if IS_ENABLED(CONFIG_BLK_DEV_BSG_COMMON)
539 struct bsg_class_device bsg_dev;
540#endif
541
542#ifdef CONFIG_BLK_DEV_THROTTLING536#ifdef CONFIG_BLK_DEV_THROTTLING
543 /* Throttle data */537 /* Throttle data */
544 struct throtl_data *td;538 struct throtl_data *td;
include/linux/bsg-lib.h+1−0
@@ -12,6 +12,7 @@ · 11 unmodified lines
12#include <linux/blkdev.h>12#include <linux/blkdev.h>
13#include <scsi/scsi_request.h>13#include <scsi/scsi_request.h>
14 14
15struct bsg_job;
15struct request;16struct request;
16struct device;17struct device;
17struct scatterlist;18struct scatterlist;
include/linux/bsg.h+6−15
@@ -4,10 +4,11 @@ · 3 unmodified lines
4 4
5#include <uapi/linux/bsg.h>5#include <uapi/linux/bsg.h>
6 6
7struct bsg_device;
8struct device;
7struct request;9struct request;
8struct request_queue;10struct request_queue;
9 11
10#ifdef CONFIG_BLK_DEV_BSG_COMMON
11struct bsg_ops {12struct bsg_ops {
12 int (*check_proto)(struct sg_io_v4 *hdr);13 int (*check_proto)(struct sg_io_v4 *hdr);
13 int (*fill_hdr)(struct request *rq, struct sg_io_v4 *hdr,14 int (*fill_hdr)(struct request *rq, struct sg_io_v4 *hdr,
@@ -16,19 +17,9 @@ struct bsg_ops { · 2 unmodified lines
16 void (*free_rq)(struct request *rq);17 void (*free_rq)(struct request *rq);
17};18};
18 19
19struct bsg_class_device {20struct bsg_device *bsg_register_queue(struct request_queue *q,
20 struct device *class_dev;21 struct device *parent, const char *name,
21 int minor;22 const struct bsg_ops *ops);
22 struct request_queue *queue;23void bsg_unregister_queue(struct bsg_device *bcd);
23 const struct bsg_ops *ops;
24};
25 24
26int bsg_register_queue(struct request_queue *q, struct device *parent,
27 const char *name, const struct bsg_ops *ops);
28void bsg_unregister_queue(struct request_queue *q);
29#else
30static inline void bsg_unregister_queue(struct request_queue *q)
31{
32}
33#endif /* CONFIG_BLK_DEV_BSG_COMMON */
34#endif /* _LINUX_BSG_H */25#endif /* _LINUX_BSG_H */
include/scsi/scsi_device.h+2−0
@@ -10,6 +10,7 @@ · 9 unmodified lines
10#include <linux/atomic.h>10#include <linux/atomic.h>
11#include <linux/sbitmap.h>11#include <linux/sbitmap.h>
12 12
13struct bsg_device;
13struct device;14struct device;
14struct request_queue;15struct request_queue;
15struct scsi_cmnd;16struct scsi_cmnd;
@@ -235,6 +236,7 @@ struct scsi_device { · 219 unmodified lines
235 size_t dma_drain_len;236 size_t dma_drain_len;
236 void *dma_drain_buf;237 void *dma_drain_buf;
237 238
239 struct bsg_device *bsg_dev;
238 unsigned char access_state;240 unsigned char access_state;
239 struct mutex state_mutex;241 struct mutex state_mutex;
240 enum scsi_device_state sdev_state;242 enum scsi_device_state sdev_state;