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
66 * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
77 * Copyright (C) 2011 Mike Christie
88 */
9+#include <linux/bsg.h>
910 #include <linux/slab.h>
1011 #include <linux/blk-mq.h>
1112 #include <linux/delay.h>
@@ -19,6 +20,7 @@ · 7 unmodified lines
1920
2021 struct bsg_set {
2122 struct blk_mq_tag_set tag_set;
23+ struct bsg_device *bd;
2224 bsg_job_fn *job_fn;
2325 bsg_timeout_fn *timeout_fn;
2426 };
@@ -327,7 +329,7 @@ void bsg_remove_queue(struct request_queue *q) · 302 unmodified lines
327329 struct bsg_set *bset =
328330 container_of(q->tag_set, struct bsg_set, tag_set);
329331
330− bsg_unregister_queue(q);
332+ bsg_unregister_queue(bset->bd);
331333 blk_cleanup_queue(q);
332334 blk_mq_free_tag_set(&bset->tag_set);
333335 kfree(bset);
@@ -396,10 +398,9 @@ struct request_queue *bsg_setup_queue(struct device *dev, const char *name, · 62 unmodified lines
396398 q->queuedata = dev;
397399 blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
398400
399− ret = bsg_register_queue(q, dev, name, &bsg_transport_ops);
400− if (ret) {
401− printk(KERN_ERR "%s: bsg interface failed to "
402− "initialize - register queue\n", dev->kobj.name);
401+ bset->bd = bsg_register_queue(q, dev, name, &bsg_transport_ops);
402+ if (IS_ERR(bset->bd)) {
403+ ret = PTR_ERR(bset->bd);
403404 goto out_cleanup_queue;
404405 }
405406
block/bsg.c+72−232
@@ -20,38 +20,29 @@ · 19 unmodified lines
2020 #define BSG_DESCRIPTION "Block layer SCSI generic (bsg) driver"
2121 #define BSG_VERSION "0.4"
2222
23−#define bsg_dbg(bd, fmt, ...) \
24− pr_debug("%s: " fmt, (bd)->name, ##__VA_ARGS__)
25−
2623 struct bsg_device {
2724 struct request_queue *queue;
28− spinlock_t lock;
29− struct hlist_node dev_list;
30− refcount_t ref_count;
31− char name[20];
25+ const struct bsg_ops *ops;
26+ struct device device;
27+ struct cdev cdev;
3228 int max_queue;
3329 };
3430
31+static inline struct bsg_device *to_bsg_device(struct inode *inode)
32+{
33+ return container_of(inode->i_cdev, struct bsg_device, cdev);
34+}
35+
3536 #define BSG_DEFAULT_CMDS 64
3637 #define BSG_MAX_DEVS 32768
3738
38−static DEFINE_MUTEX(bsg_mutex);
39−static DEFINE_IDR(bsg_minor_idr);
40−
41−#define BSG_LIST_ARRAY_SIZE 8
42−static struct hlist_head bsg_device_list[BSG_LIST_ARRAY_SIZE];
43−
39+static DEFINE_IDA(bsg_minor_ida);
4440 static struct class *bsg_class;
4541 static int bsg_major;
4642
47−static inline struct hlist_head *bsg_dev_idx_hash(int index)
48−{
49− return &bsg_device_list[index & (BSG_LIST_ARRAY_SIZE - 1)];
50−}
51−
5243 #define uptr64(val) ((void __user *)(uintptr_t)(val))
5344
54−static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg)
45+static int bsg_sg_io(struct bsg_device *bd, fmode_t mode, void __user *uarg)
5546 {
5647 struct request *rq;
5748 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
6152 if (copy_from_user(&hdr, uarg, sizeof(hdr)))
6253 return -EFAULT;
6354
64− if (!q->bsg_dev.class_dev)
65− return -ENXIO;
66−
6755 if (hdr.guard != 'Q')
6856 return -EINVAL;
69− ret = q->bsg_dev.ops->check_proto(&hdr);
57+ ret = bd->ops->check_proto(&hdr);
7058 if (ret)
7159 return ret;
7260
73− rq = blk_get_request(q, hdr.dout_xfer_len ?
61+ rq = blk_get_request(bd->queue, hdr.dout_xfer_len ?
7462 REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
7563 if (IS_ERR(rq))
7664 return PTR_ERR(rq);
7765
78− ret = q->bsg_dev.ops->fill_hdr(rq, &hdr, mode);
66+ ret = bd->ops->fill_hdr(rq, &hdr, mode);
7967 if (ret) {
8068 blk_put_request(rq);
8169 return ret;
@@ -83,17 +71,17 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) · 1 unmodified line
8371
8472 rq->timeout = msecs_to_jiffies(hdr.timeout);
8573 if (!rq->timeout)
86− rq->timeout = q->sg_timeout;
74+ rq->timeout = rq->q->sg_timeout;
8775 if (!rq->timeout)
8876 rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
8977 if (rq->timeout < BLK_MIN_SG_TIMEOUT)
9078 rq->timeout = BLK_MIN_SG_TIMEOUT;
9179
9280 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),
9482 hdr.dout_xfer_len, GFP_KERNEL);
9583 } 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),
9785 hdr.din_xfer_len, GFP_KERNEL);
9886 }
9987
@@ -103,171 +91,50 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) · 3 unmodified lines
10391 bio = rq->bio;
10492
10593 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);
10795 blk_rq_unmap_user(bio);
10896
10997 out_free_rq:
110− rq->q->bsg_dev.ops->free_rq(rq);
98+ bd->ops->free_rq(rq);
11199 blk_put_request(rq);
112100 if (!ret && copy_to_user(uarg, &hdr, sizeof(hdr)))
113101 return -EFAULT;
114102 return ret;
115103 }
116104
117−static 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−
131−static 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−
155−static 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−
185−static 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;
198−found:
199− return bd;
200−}
201−
202−static 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−
222−out_unlock:
223− mutex_unlock(&bsg_mutex);
224− return bd;
225−}
226−
227105 static int bsg_open(struct inode *inode, struct file *file)
228106 {
229− struct bsg_device *bd;
230−
231− bd = bsg_get_device(inode, file);
232−
233− if (IS_ERR(bd))
234− return PTR_ERR(bd);
235−
236− file->private_data = bd;
107+ if (!blk_get_queue(to_bsg_device(inode)->queue))
108+ return -ENXIO;
237109 return 0;
238110 }
239111
240112 static int bsg_release(struct inode *inode, struct file *file)
241113 {
242− struct bsg_device *bd = file->private_data;
243−
244− file->private_data = NULL;
245− return bsg_put_device(bd);
114+ blk_put_queue(to_bsg_device(inode)->queue);
115+ return 0;
246116 }
247117
248118 static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg)
249119 {
250− return put_user(bd->max_queue, uarg);
120+ return put_user(READ_ONCE(bd->max_queue), uarg);
251121 }
252122
253123 static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg)
254124 {
255− int queue;
125+ int max_queue;
256126
257− if (get_user(queue, uarg))
127+ if (get_user(max_queue, uarg))
258128 return -EFAULT;
259− if (queue < 1)
129+ if (max_queue < 1)
260130 return -EINVAL;
261−
262− spin_lock_irq(&bd->lock);
263− bd->max_queue = queue;
264− spin_unlock_irq(&bd->lock);
131+ WRITE_ONCE(bd->max_queue, max_queue);
265132 return 0;
266133 }
267134
268135 static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
269136 {
270− struct bsg_device *bd = file->private_data;
137+ struct bsg_device *bd = to_bsg_device(file_inode(file));
271138 struct request_queue *q = bd->queue;
272139 void __user *uarg = (void __user *) arg;
273140 int __user *intp = uarg;
@@ -312,7 +179,7 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 38 unmodified lines
312179 case SG_EMULATED_HOST:
313180 return put_user(1, intp);
314181 case SG_IO:
315− return bsg_sg_io(q, file->f_mode, uarg);
182+ return bsg_sg_io(bd, file->f_mode, uarg);
316183 case SCSI_IOCTL_SEND_COMMAND:
317184 pr_warn_ratelimited("%s: calling unsupported SCSI_IOCTL_SEND_COMMAND\n",
318185 current->comm);
@@ -331,83 +198,66 @@ static const struct file_operations bsg_fops = { · 12 unmodified lines
331198 .llseek = default_llseek,
332199 };
333200
334−void bsg_unregister_queue(struct request_queue *q)
201+void bsg_unregister_queue(struct bsg_device *bd)
335202 {
336− struct bsg_class_device *bcd = &q->bsg_dev;
337−
338− if (!bcd->class_dev)
339− return;
340−
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);
203+ if (bd->queue->kobj.sd)
204+ sysfs_remove_link(&bd->queue->kobj, "bsg");
205+ cdev_device_del(&bd->cdev, &bd->device);
206+ ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt));
207+ kfree(bd);
348208 }
349209 EXPORT_SYMBOL_GPL(bsg_unregister_queue);
350210
351−int bsg_register_queue(struct request_queue *q, struct device *parent,
352− const char *name, const struct bsg_ops *ops)
211+struct bsg_device *bsg_register_queue(struct request_queue *q,
212+ struct device *parent, const char *name,
213+ const struct bsg_ops *ops)
353214 {
354− struct bsg_class_device *bcd;
355− dev_t dev;
215+ struct bsg_device *bd;
356216 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;
364217
365− bcd = &q->bsg_dev;
366− memset(bcd, 0, sizeof(*bcd));
367−
368− mutex_lock(&bsg_mutex);
218+ bd = kzalloc(sizeof(*bd), GFP_KERNEL);
219+ if (!bd)
220+ return ERR_PTR(-ENOMEM);
221+ bd->max_queue = BSG_DEFAULT_CMDS;
222+ bd->queue = q;
223+ bd->ops = ops;
369224
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);
371226 if (ret < 0) {
372− if (ret == -ENOSPC) {
373− printk(KERN_ERR "bsg: too many bsg devices\n");
374− ret = -EINVAL;
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;
227+ if (ret == -ENOSPC)
228+ dev_err(parent, "bsg: too many bsg devices\n");
229+ goto out_kfree;
387230 }
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;
389242
390243 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");
392245 if (ret)
393− goto unregister_class_dev;
246+ goto out_device_del;
394247 }
395248
396− mutex_unlock(&bsg_mutex);
397− return 0;
249+ return bd;
398250
399−unregister_class_dev:
400− device_unregister(class_dev);
401−idr_remove:
402− idr_remove(&bsg_minor_idr, bcd->minor);
403−unlock:
404− mutex_unlock(&bsg_mutex);
405− return ret;
251+out_device_del:
252+ cdev_device_del(&bd->cdev, &bd->device);
253+out_ida_remove:
254+ ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt));
255+out_kfree:
256+ kfree(bd);
257+ return ERR_PTR(ret);
406258 }
407259 EXPORT_SYMBOL_GPL(bsg_register_queue);
408260
409−static struct cdev bsg_cdev;
410−
411261 static char *bsg_devnode(struct device *dev, umode_t *mode)
412262 {
413263 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
415265
416266 static int __init bsg_init(void)
417267 {
418− int ret, i;
419268 dev_t devid;
420−
421− for (i = 0; i < BSG_LIST_ARRAY_SIZE; i++)
422− INIT_HLIST_HEAD(&bsg_device_list[i]);
269+ int ret;
423270
424271 bsg_class = class_create(THIS_MODULE, "bsg");
425272 if (IS_ERR(bsg_class))
@@ -429,19 +276,12 @@ static int __init bsg_init(void) · 3 unmodified lines
429276 ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
430277 if (ret)
431278 goto destroy_bsg_class;
432−
433279 bsg_major = MAJOR(devid);
434280
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−
440281 printk(KERN_INFO BSG_DESCRIPTION " version " BSG_VERSION
441282 " loaded (major %d)\n", bsg_major);
442283 return 0;
443−unregister_chrdev:
444− unregister_chrdev_region(MKDEV(bsg_major, 0), BSG_MAX_DEVS);
284+
445285 destroy_bsg_class:
446286 class_destroy(bsg_class);
447287 return ret;
drivers/scsi/scsi_bsg.c+3−2
@@ -89,7 +89,8 @@ static const struct bsg_ops scsi_bsg_ops = { · 88 unmodified lines
8989 .free_rq = scsi_bsg_free_rq,
9090 };
9191
92−int scsi_bsg_register_queue(struct request_queue *q, struct device *parent)
92+struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev)
9393 {
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);
9596 }
drivers/scsi/scsi_priv.h+2−9
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 #include <scsi/scsi_device.h>
88 #include <linux/sbitmap.h>
99
10+struct bsg_device;
1011 struct request_queue;
1112 struct request;
1213 struct scsi_cmnd;
@@ -180,15 +181,7 @@ static inline void scsi_dh_add_device(struct scsi_device *sdev) { } · 167 unmodified lines
180181 static inline void scsi_dh_release_device(struct scsi_device *sdev) { }
181182 #endif
182183
183−#ifdef CONFIG_BLK_DEV_BSG
184−int scsi_bsg_register_queue(struct request_queue *q, struct device *parent);
185−#else
186−static inline int scsi_bsg_register_queue(struct request_queue *q,
187− struct device *parent)
188−{
189− return 0;
190−}
191−#endif
184+struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev);
192185
193186 extern int scsi_device_max_queue_depth(struct scsi_device *sdev);
194187
drivers/scsi/scsi_sysfs.c+16−8
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #include <linux/blkdev.h>
1414 #include <linux/device.h>
1515 #include <linux/pm_runtime.h>
16+#include <linux/bsg.h>
1617
1718 #include <scsi/scsi.h>
1819 #include <scsi/scsi_device.h>
@@ -1327,7 +1328,6 @@ static int scsi_target_add(struct scsi_target *starget) · 1308 unmodified lines
13271328 int scsi_sysfs_add_sdev(struct scsi_device *sdev)
13281329 {
13291330 int error, i;
1330− struct request_queue *rq = sdev->request_queue;
13311331 struct scsi_target *starget = sdev->sdev_target;
13321332
13331333 error = scsi_target_add(starget);
@@ -1366,12 +1366,19 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) · 32 unmodified lines
13661366 transport_add_device(&sdev->sdev_gendev);
13671367 sdev->is_visible = 1;
13681368
1369− error = scsi_bsg_register_queue(rq, &sdev->sdev_gendev);
1370− if (error)
1371− /* we're treating error on bsg register as non-fatal,
1372− * so pretend nothing went wrong */
1373− sdev_printk(KERN_INFO, sdev,
1374− "Failed to register bsg queue, errno=%d\n", error);
1369+ if (IS_ENABLED(CONFIG_BLK_DEV_BSG)) {
1370+ sdev->bsg_dev = scsi_bsg_register_queue(sdev);
1371+ if (IS_ERR(sdev->bsg_dev)) {
1372+ /*
1373+ * We're treating error on bsg register as non-fatal, so
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+ }
13751382
13761383 /* add additional host specific attributes */
13771384 if (sdev->host->hostt->sdev_attrs) {
@@ -1433,7 +1440,8 @@ void __scsi_remove_device(struct scsi_device *sdev) · 55 unmodified lines
14331440 sysfs_remove_groups(&sdev->sdev_gendev.kobj,
14341441 sdev->host->hostt->sdev_groups);
14351442
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);
14371445 device_unregister(&sdev->sdev_dev);
14381446 transport_remove_device(dev);
14391447 device_del(dev);
include/linux/blkdev.h+0−6
@@ -18,7 +18,6 @@ · 17 unmodified lines
1818 #include <linux/bio.h>
1919 #include <linux/stringify.h>
2020 #include <linux/gfp.h>
21−#include <linux/bsg.h>
2221 #include <linux/smp.h>
2322 #include <linux/rcupdate.h>
2423 #include <linux/percpu-refcount.h>
@@ -33,7 +32,6 @@ struct elevator_queue; · 8 unmodified lines
3332 struct blk_trace;
3433 struct request;
3534 struct sg_io_hdr;
36−struct bsg_job;
3735 struct blkcg_gq;
3836 struct blk_flush_queue;
3937 struct pr_ops;
@@ -535,10 +533,6 @@ struct request_queue { · 495 unmodified lines
535533
536534 int mq_freeze_depth;
537535
538−#if IS_ENABLED(CONFIG_BLK_DEV_BSG_COMMON)
539− struct bsg_class_device bsg_dev;
540−#endif
541−
542536 #ifdef CONFIG_BLK_DEV_THROTTLING
543537 /* Throttle data */
544538 struct throtl_data *td;
include/linux/bsg-lib.h+1−0
@@ -12,6 +12,7 @@ · 11 unmodified lines
1212 #include <linux/blkdev.h>
1313 #include <scsi/scsi_request.h>
1414
15+struct bsg_job;
1516 struct request;
1617 struct device;
1718 struct scatterlist;
include/linux/bsg.h+6−15
@@ -4,10 +4,11 @@ · 3 unmodified lines
44
55 #include <uapi/linux/bsg.h>
66
7+struct bsg_device;
8+struct device;
79 struct request;
810 struct request_queue;
911
10−#ifdef CONFIG_BLK_DEV_BSG_COMMON
1112 struct bsg_ops {
1213 int (*check_proto)(struct sg_io_v4 *hdr);
1314 int (*fill_hdr)(struct request *rq, struct sg_io_v4 *hdr,
@@ -16,19 +17,9 @@ struct bsg_ops { · 2 unmodified lines
1617 void (*free_rq)(struct request *rq);
1718 };
1819
19−struct bsg_class_device {
20− struct device *class_dev;
21− int minor;
22− struct request_queue *queue;
23− const struct bsg_ops *ops;
24−};
20+struct bsg_device *bsg_register_queue(struct request_queue *q,
21+ struct device *parent, const char *name,
22+ const struct bsg_ops *ops);
23+void bsg_unregister_queue(struct bsg_device *bcd);
2524
26−int bsg_register_queue(struct request_queue *q, struct device *parent,
27− const char *name, const struct bsg_ops *ops);
28−void bsg_unregister_queue(struct request_queue *q);
29−#else
30−static inline void bsg_unregister_queue(struct request_queue *q)
31−{
32−}
33−#endif /* CONFIG_BLK_DEV_BSG_COMMON */
3425 #endif /* _LINUX_BSG_H */
include/scsi/scsi_device.h+2−0
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010 #include <linux/atomic.h>
1111 #include <linux/sbitmap.h>
1212
13+struct bsg_device;
1314 struct device;
1415 struct request_queue;
1516 struct scsi_cmnd;
@@ -235,6 +236,7 @@ struct scsi_device { · 219 unmodified lines
235236 size_t dma_drain_len;
236237 void *dma_drain_buf;
237238
239+ struct bsg_device *bsg_dev;
238240 unsigned char access_state;
239241 struct mutex state_mutex;
240242 enum scsi_device_state sdev_state;