Commit ead09dd3 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Martin K. Petersen

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.

Link: https://lore.kernel.org/r/20210729064845.1044147-2-hch@lst.deSigned-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent ba51bdaf
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Copyright (C) 2011 Red Hat, Inc. All rights reserved. * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
* Copyright (C) 2011 Mike Christie * Copyright (C) 2011 Mike Christie
*/ */
#include <linux/bsg.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/blk-mq.h> #include <linux/blk-mq.h>
#include <linux/delay.h> #include <linux/delay.h>
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
struct bsg_set { struct bsg_set {
struct blk_mq_tag_set tag_set; struct blk_mq_tag_set tag_set;
struct bsg_device *bd;
bsg_job_fn *job_fn; bsg_job_fn *job_fn;
bsg_timeout_fn *timeout_fn; bsg_timeout_fn *timeout_fn;
}; };
...@@ -327,7 +329,7 @@ void bsg_remove_queue(struct request_queue *q) ...@@ -327,7 +329,7 @@ void bsg_remove_queue(struct request_queue *q)
struct bsg_set *bset = struct bsg_set *bset =
container_of(q->tag_set, struct bsg_set, tag_set); container_of(q->tag_set, struct bsg_set, tag_set);
bsg_unregister_queue(q); bsg_unregister_queue(bset->bd);
blk_cleanup_queue(q); blk_cleanup_queue(q);
blk_mq_free_tag_set(&bset->tag_set); blk_mq_free_tag_set(&bset->tag_set);
kfree(bset); kfree(bset);
...@@ -396,10 +398,9 @@ struct request_queue *bsg_setup_queue(struct device *dev, const char *name, ...@@ -396,10 +398,9 @@ struct request_queue *bsg_setup_queue(struct device *dev, const char *name,
q->queuedata = dev; q->queuedata = dev;
blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT); blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
ret = bsg_register_queue(q, dev, name, &bsg_transport_ops); bset->bd = bsg_register_queue(q, dev, name, &bsg_transport_ops);
if (ret) { if (IS_ERR(bset->bd)) {
printk(KERN_ERR "%s: bsg interface failed to " ret = PTR_ERR(bset->bd);
"initialize - register queue\n", dev->kobj.name);
goto out_cleanup_queue; goto out_cleanup_queue;
} }
......
...@@ -20,38 +20,29 @@ ...@@ -20,38 +20,29 @@
#define BSG_DESCRIPTION "Block layer SCSI generic (bsg) driver" #define BSG_DESCRIPTION "Block layer SCSI generic (bsg) driver"
#define BSG_VERSION "0.4" #define BSG_VERSION "0.4"
#define bsg_dbg(bd, fmt, ...) \
pr_debug("%s: " fmt, (bd)->name, ##__VA_ARGS__)
struct bsg_device { struct bsg_device {
struct request_queue *queue; struct request_queue *queue;
spinlock_t lock; const struct bsg_ops *ops;
struct hlist_node dev_list; struct device device;
refcount_t ref_count; struct cdev cdev;
char name[20];
int max_queue; int max_queue;
}; };
static inline struct bsg_device *to_bsg_device(struct inode *inode)
{
return container_of(inode->i_cdev, struct bsg_device, cdev);
}
#define BSG_DEFAULT_CMDS 64 #define BSG_DEFAULT_CMDS 64
#define BSG_MAX_DEVS 32768 #define BSG_MAX_DEVS 32768
static DEFINE_MUTEX(bsg_mutex); static DEFINE_IDA(bsg_minor_ida);
static DEFINE_IDR(bsg_minor_idr);
#define BSG_LIST_ARRAY_SIZE 8
static struct hlist_head bsg_device_list[BSG_LIST_ARRAY_SIZE];
static struct class *bsg_class; static struct class *bsg_class;
static int bsg_major; static int bsg_major;
static inline struct hlist_head *bsg_dev_idx_hash(int index)
{
return &bsg_device_list[index & (BSG_LIST_ARRAY_SIZE - 1)];
}
#define uptr64(val) ((void __user *)(uintptr_t)(val)) #define uptr64(val) ((void __user *)(uintptr_t)(val))
static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) static int bsg_sg_io(struct bsg_device *bd, fmode_t mode, void __user *uarg)
{ {
struct request *rq; struct request *rq;
struct bio *bio; struct bio *bio;
...@@ -61,21 +52,18 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) ...@@ -61,21 +52,18 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg)
if (copy_from_user(&hdr, uarg, sizeof(hdr))) if (copy_from_user(&hdr, uarg, sizeof(hdr)))
return -EFAULT; return -EFAULT;
if (!q->bsg_dev.class_dev)
return -ENXIO;
if (hdr.guard != 'Q') if (hdr.guard != 'Q')
return -EINVAL; return -EINVAL;
ret = q->bsg_dev.ops->check_proto(&hdr); ret = bd->ops->check_proto(&hdr);
if (ret) if (ret)
return ret; return ret;
rq = blk_get_request(q, hdr.dout_xfer_len ? rq = blk_get_request(bd->queue, hdr.dout_xfer_len ?
REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0); REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
if (IS_ERR(rq)) if (IS_ERR(rq))
return PTR_ERR(rq); return PTR_ERR(rq);
ret = q->bsg_dev.ops->fill_hdr(rq, &hdr, mode); ret = bd->ops->fill_hdr(rq, &hdr, mode);
if (ret) { if (ret) {
blk_put_request(rq); blk_put_request(rq);
return ret; return ret;
...@@ -83,17 +71,17 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) ...@@ -83,17 +71,17 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg)
rq->timeout = msecs_to_jiffies(hdr.timeout); rq->timeout = msecs_to_jiffies(hdr.timeout);
if (!rq->timeout) if (!rq->timeout)
rq->timeout = q->sg_timeout; rq->timeout = rq->q->sg_timeout;
if (!rq->timeout) if (!rq->timeout)
rq->timeout = BLK_DEFAULT_SG_TIMEOUT; rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
if (rq->timeout < BLK_MIN_SG_TIMEOUT) if (rq->timeout < BLK_MIN_SG_TIMEOUT)
rq->timeout = BLK_MIN_SG_TIMEOUT; rq->timeout = BLK_MIN_SG_TIMEOUT;
if (hdr.dout_xfer_len) { if (hdr.dout_xfer_len) {
ret = blk_rq_map_user(q, rq, NULL, uptr64(hdr.dout_xferp), ret = blk_rq_map_user(rq->q, rq, NULL, uptr64(hdr.dout_xferp),
hdr.dout_xfer_len, GFP_KERNEL); hdr.dout_xfer_len, GFP_KERNEL);
} else if (hdr.din_xfer_len) { } else if (hdr.din_xfer_len) {
ret = blk_rq_map_user(q, rq, NULL, uptr64(hdr.din_xferp), ret = blk_rq_map_user(rq->q, rq, NULL, uptr64(hdr.din_xferp),
hdr.din_xfer_len, GFP_KERNEL); hdr.din_xfer_len, GFP_KERNEL);
} }
...@@ -103,171 +91,50 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) ...@@ -103,171 +91,50 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg)
bio = rq->bio; bio = rq->bio;
blk_execute_rq(NULL, rq, !(hdr.flags & BSG_FLAG_Q_AT_TAIL)); blk_execute_rq(NULL, rq, !(hdr.flags & BSG_FLAG_Q_AT_TAIL));
ret = rq->q->bsg_dev.ops->complete_rq(rq, &hdr); ret = bd->ops->complete_rq(rq, &hdr);
blk_rq_unmap_user(bio); blk_rq_unmap_user(bio);
out_free_rq: out_free_rq:
rq->q->bsg_dev.ops->free_rq(rq); bd->ops->free_rq(rq);
blk_put_request(rq); blk_put_request(rq);
if (!ret && copy_to_user(uarg, &hdr, sizeof(hdr))) if (!ret && copy_to_user(uarg, &hdr, sizeof(hdr)))
return -EFAULT; return -EFAULT;
return ret; return ret;
} }
static struct bsg_device *bsg_alloc_device(void)
{
struct bsg_device *bd;
bd = kzalloc(sizeof(struct bsg_device), GFP_KERNEL);
if (unlikely(!bd))
return NULL;
spin_lock_init(&bd->lock);
bd->max_queue = BSG_DEFAULT_CMDS;
INIT_HLIST_NODE(&bd->dev_list);
return bd;
}
static int bsg_put_device(struct bsg_device *bd)
{
struct request_queue *q = bd->queue;
mutex_lock(&bsg_mutex);
if (!refcount_dec_and_test(&bd->ref_count)) {
mutex_unlock(&bsg_mutex);
return 0;
}
hlist_del(&bd->dev_list);
mutex_unlock(&bsg_mutex);
bsg_dbg(bd, "tearing down\n");
/*
* close can always block
*/
kfree(bd);
blk_put_queue(q);
return 0;
}
static struct bsg_device *bsg_add_device(struct inode *inode,
struct request_queue *rq,
struct file *file)
{
struct bsg_device *bd;
unsigned char buf[32];
lockdep_assert_held(&bsg_mutex);
if (!blk_get_queue(rq))
return ERR_PTR(-ENXIO);
bd = bsg_alloc_device();
if (!bd) {
blk_put_queue(rq);
return ERR_PTR(-ENOMEM);
}
bd->queue = rq;
refcount_set(&bd->ref_count, 1);
hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode)));
strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1);
bsg_dbg(bd, "bound to <%s>, max queue %d\n",
format_dev_t(buf, inode->i_rdev), bd->max_queue);
return bd;
}
static struct bsg_device *__bsg_get_device(int minor, struct request_queue *q)
{
struct bsg_device *bd;
lockdep_assert_held(&bsg_mutex);
hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) {
if (bd->queue == q) {
refcount_inc(&bd->ref_count);
goto found;
}
}
bd = NULL;
found:
return bd;
}
static struct bsg_device *bsg_get_device(struct inode *inode, struct file *file)
{
struct bsg_device *bd;
struct bsg_class_device *bcd;
/*
* find the class device
*/
mutex_lock(&bsg_mutex);
bcd = idr_find(&bsg_minor_idr, iminor(inode));
if (!bcd) {
bd = ERR_PTR(-ENODEV);
goto out_unlock;
}
bd = __bsg_get_device(iminor(inode), bcd->queue);
if (!bd)
bd = bsg_add_device(inode, bcd->queue, file);
out_unlock:
mutex_unlock(&bsg_mutex);
return bd;
}
static int bsg_open(struct inode *inode, struct file *file) static int bsg_open(struct inode *inode, struct file *file)
{ {
struct bsg_device *bd; if (!blk_get_queue(to_bsg_device(inode)->queue))
return -ENXIO;
bd = bsg_get_device(inode, file);
if (IS_ERR(bd))
return PTR_ERR(bd);
file->private_data = bd;
return 0; return 0;
} }
static int bsg_release(struct inode *inode, struct file *file) static int bsg_release(struct inode *inode, struct file *file)
{ {
struct bsg_device *bd = file->private_data; blk_put_queue(to_bsg_device(inode)->queue);
return 0;
file->private_data = NULL;
return bsg_put_device(bd);
} }
static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg) static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg)
{ {
return put_user(bd->max_queue, uarg); return put_user(READ_ONCE(bd->max_queue), uarg);
} }
static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg) static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg)
{ {
int queue; int max_queue;
if (get_user(queue, uarg)) if (get_user(max_queue, uarg))
return -EFAULT; return -EFAULT;
if (queue < 1) if (max_queue < 1)
return -EINVAL; return -EINVAL;
WRITE_ONCE(bd->max_queue, max_queue);
spin_lock_irq(&bd->lock);
bd->max_queue = queue;
spin_unlock_irq(&bd->lock);
return 0; return 0;
} }
static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
struct bsg_device *bd = file->private_data; struct bsg_device *bd = to_bsg_device(file_inode(file));
struct request_queue *q = bd->queue; struct request_queue *q = bd->queue;
void __user *uarg = (void __user *) arg; void __user *uarg = (void __user *) arg;
int __user *intp = uarg; int __user *intp = uarg;
...@@ -312,7 +179,7 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -312,7 +179,7 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
case SG_EMULATED_HOST: case SG_EMULATED_HOST:
return put_user(1, intp); return put_user(1, intp);
case SG_IO: case SG_IO:
return bsg_sg_io(q, file->f_mode, uarg); return bsg_sg_io(bd, file->f_mode, uarg);
case SCSI_IOCTL_SEND_COMMAND: case SCSI_IOCTL_SEND_COMMAND:
pr_warn_ratelimited("%s: calling unsupported SCSI_IOCTL_SEND_COMMAND\n", pr_warn_ratelimited("%s: calling unsupported SCSI_IOCTL_SEND_COMMAND\n",
current->comm); current->comm);
...@@ -331,83 +198,66 @@ static const struct file_operations bsg_fops = { ...@@ -331,83 +198,66 @@ static const struct file_operations bsg_fops = {
.llseek = default_llseek, .llseek = default_llseek,
}; };
void bsg_unregister_queue(struct request_queue *q) void bsg_unregister_queue(struct bsg_device *bd)
{ {
struct bsg_class_device *bcd = &q->bsg_dev; if (bd->queue->kobj.sd)
sysfs_remove_link(&bd->queue->kobj, "bsg");
if (!bcd->class_dev) cdev_device_del(&bd->cdev, &bd->device);
return; ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt));
kfree(bd);
mutex_lock(&bsg_mutex);
idr_remove(&bsg_minor_idr, bcd->minor);
if (q->kobj.sd)
sysfs_remove_link(&q->kobj, "bsg");
device_unregister(bcd->class_dev);
bcd->class_dev = NULL;
mutex_unlock(&bsg_mutex);
} }
EXPORT_SYMBOL_GPL(bsg_unregister_queue); EXPORT_SYMBOL_GPL(bsg_unregister_queue);
int bsg_register_queue(struct request_queue *q, struct device *parent, struct bsg_device *bsg_register_queue(struct request_queue *q,
const char *name, const struct bsg_ops *ops) struct device *parent, const char *name,
const struct bsg_ops *ops)
{ {
struct bsg_class_device *bcd; struct bsg_device *bd;
dev_t dev;
int ret; int ret;
struct device *class_dev = NULL;
/*
* we need a proper transport to send commands, not a stacked device
*/
if (!queue_is_mq(q))
return 0;
bcd = &q->bsg_dev; bd = kzalloc(sizeof(*bd), GFP_KERNEL);
memset(bcd, 0, sizeof(*bcd)); if (!bd)
return ERR_PTR(-ENOMEM);
mutex_lock(&bsg_mutex); bd->max_queue = BSG_DEFAULT_CMDS;
bd->queue = q;
bd->ops = ops;
ret = idr_alloc(&bsg_minor_idr, bcd, 0, BSG_MAX_DEVS, GFP_KERNEL); ret = ida_simple_get(&bsg_minor_ida, 0, BSG_MAX_DEVS, GFP_KERNEL);
if (ret < 0) { if (ret < 0) {
if (ret == -ENOSPC) { if (ret == -ENOSPC)
printk(KERN_ERR "bsg: too many bsg devices\n"); dev_err(parent, "bsg: too many bsg devices\n");
ret = -EINVAL; goto out_kfree;
}
goto unlock;
}
bcd->minor = ret;
bcd->queue = q;
bcd->ops = ops;
dev = MKDEV(bsg_major, bcd->minor);
class_dev = device_create(bsg_class, parent, dev, NULL, "%s", name);
if (IS_ERR(class_dev)) {
ret = PTR_ERR(class_dev);
goto idr_remove;
} }
bcd->class_dev = class_dev; bd->device.devt = MKDEV(bsg_major, ret);
bd->device.class = bsg_class;
bd->device.parent = parent;
dev_set_name(&bd->device, "%s", name);
device_initialize(&bd->device);
cdev_init(&bd->cdev, &bsg_fops);
bd->cdev.owner = THIS_MODULE;
ret = cdev_device_add(&bd->cdev, &bd->device);
if (ret)
goto out_ida_remove;
if (q->kobj.sd) { if (q->kobj.sd) {
ret = sysfs_create_link(&q->kobj, &bcd->class_dev->kobj, "bsg"); ret = sysfs_create_link(&q->kobj, &bd->device.kobj, "bsg");
if (ret) if (ret)
goto unregister_class_dev; goto out_device_del;
} }
mutex_unlock(&bsg_mutex); return bd;
return 0;
unregister_class_dev: out_device_del:
device_unregister(class_dev); cdev_device_del(&bd->cdev, &bd->device);
idr_remove: out_ida_remove:
idr_remove(&bsg_minor_idr, bcd->minor); ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt));
unlock: out_kfree:
mutex_unlock(&bsg_mutex); kfree(bd);
return ret; return ERR_PTR(ret);
} }
EXPORT_SYMBOL_GPL(bsg_register_queue); EXPORT_SYMBOL_GPL(bsg_register_queue);
static struct cdev bsg_cdev;
static char *bsg_devnode(struct device *dev, umode_t *mode) static char *bsg_devnode(struct device *dev, umode_t *mode)
{ {
return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev)); return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev));
...@@ -415,11 +265,8 @@ static char *bsg_devnode(struct device *dev, umode_t *mode) ...@@ -415,11 +265,8 @@ static char *bsg_devnode(struct device *dev, umode_t *mode)
static int __init bsg_init(void) static int __init bsg_init(void)
{ {
int ret, i;
dev_t devid; dev_t devid;
int ret;
for (i = 0; i < BSG_LIST_ARRAY_SIZE; i++)
INIT_HLIST_HEAD(&bsg_device_list[i]);
bsg_class = class_create(THIS_MODULE, "bsg"); bsg_class = class_create(THIS_MODULE, "bsg");
if (IS_ERR(bsg_class)) if (IS_ERR(bsg_class))
...@@ -429,19 +276,12 @@ static int __init bsg_init(void) ...@@ -429,19 +276,12 @@ static int __init bsg_init(void)
ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg"); ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
if (ret) if (ret)
goto destroy_bsg_class; goto destroy_bsg_class;
bsg_major = MAJOR(devid); bsg_major = MAJOR(devid);
cdev_init(&bsg_cdev, &bsg_fops);
ret = cdev_add(&bsg_cdev, MKDEV(bsg_major, 0), BSG_MAX_DEVS);
if (ret)
goto unregister_chrdev;
printk(KERN_INFO BSG_DESCRIPTION " version " BSG_VERSION printk(KERN_INFO BSG_DESCRIPTION " version " BSG_VERSION
" loaded (major %d)\n", bsg_major); " loaded (major %d)\n", bsg_major);
return 0; return 0;
unregister_chrdev:
unregister_chrdev_region(MKDEV(bsg_major, 0), BSG_MAX_DEVS);
destroy_bsg_class: destroy_bsg_class:
class_destroy(bsg_class); class_destroy(bsg_class);
return ret; return ret;
......
...@@ -89,7 +89,8 @@ static const struct bsg_ops scsi_bsg_ops = { ...@@ -89,7 +89,8 @@ static const struct bsg_ops scsi_bsg_ops = {
.free_rq = scsi_bsg_free_rq, .free_rq = scsi_bsg_free_rq,
}; };
int scsi_bsg_register_queue(struct request_queue *q, struct device *parent) struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev)
{ {
return bsg_register_queue(q, parent, dev_name(parent), &scsi_bsg_ops); return bsg_register_queue(sdev->request_queue, &sdev->sdev_gendev,
dev_name(&sdev->sdev_gendev), &scsi_bsg_ops);
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <scsi/scsi_device.h> #include <scsi/scsi_device.h>
#include <linux/sbitmap.h> #include <linux/sbitmap.h>
struct bsg_device;
struct request_queue; struct request_queue;
struct request; struct request;
struct scsi_cmnd; struct scsi_cmnd;
...@@ -180,15 +181,7 @@ static inline void scsi_dh_add_device(struct scsi_device *sdev) { } ...@@ -180,15 +181,7 @@ static inline void scsi_dh_add_device(struct scsi_device *sdev) { }
static inline void scsi_dh_release_device(struct scsi_device *sdev) { } static inline void scsi_dh_release_device(struct scsi_device *sdev) { }
#endif #endif
#ifdef CONFIG_BLK_DEV_BSG struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev);
int scsi_bsg_register_queue(struct request_queue *q, struct device *parent);
#else
static inline int scsi_bsg_register_queue(struct request_queue *q,
struct device *parent)
{
return 0;
}
#endif
extern int scsi_device_max_queue_depth(struct scsi_device *sdev); extern int scsi_device_max_queue_depth(struct scsi_device *sdev);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/bsg.h>
#include <scsi/scsi.h> #include <scsi/scsi.h>
#include <scsi/scsi_device.h> #include <scsi/scsi_device.h>
...@@ -1327,7 +1328,6 @@ static int scsi_target_add(struct scsi_target *starget) ...@@ -1327,7 +1328,6 @@ static int scsi_target_add(struct scsi_target *starget)
int scsi_sysfs_add_sdev(struct scsi_device *sdev) int scsi_sysfs_add_sdev(struct scsi_device *sdev)
{ {
int error, i; int error, i;
struct request_queue *rq = sdev->request_queue;
struct scsi_target *starget = sdev->sdev_target; struct scsi_target *starget = sdev->sdev_target;
error = scsi_target_add(starget); error = scsi_target_add(starget);
...@@ -1366,12 +1366,19 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) ...@@ -1366,12 +1366,19 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
transport_add_device(&sdev->sdev_gendev); transport_add_device(&sdev->sdev_gendev);
sdev->is_visible = 1; sdev->is_visible = 1;
error = scsi_bsg_register_queue(rq, &sdev->sdev_gendev); if (IS_ENABLED(CONFIG_BLK_DEV_BSG)) {
if (error) sdev->bsg_dev = scsi_bsg_register_queue(sdev);
/* we're treating error on bsg register as non-fatal, if (IS_ERR(sdev->bsg_dev)) {
* so pretend nothing went wrong */ /*
sdev_printk(KERN_INFO, sdev, * We're treating error on bsg register as non-fatal, so
"Failed to register bsg queue, errno=%d\n", error); * pretend nothing went wrong.
*/
sdev_printk(KERN_INFO, sdev,
"Failed to register bsg queue, errno=%d\n",
error);
sdev->bsg_dev = NULL;
}
}
/* add additional host specific attributes */ /* add additional host specific attributes */
if (sdev->host->hostt->sdev_attrs) { if (sdev->host->hostt->sdev_attrs) {
...@@ -1433,7 +1440,8 @@ void __scsi_remove_device(struct scsi_device *sdev) ...@@ -1433,7 +1440,8 @@ void __scsi_remove_device(struct scsi_device *sdev)
sysfs_remove_groups(&sdev->sdev_gendev.kobj, sysfs_remove_groups(&sdev->sdev_gendev.kobj,
sdev->host->hostt->sdev_groups); sdev->host->hostt->sdev_groups);
bsg_unregister_queue(sdev->request_queue); if (IS_ENABLED(CONFIG_BLK_DEV_BSG) && sdev->bsg_dev)
bsg_unregister_queue(sdev->bsg_dev);
device_unregister(&sdev->sdev_dev); device_unregister(&sdev->sdev_dev);
transport_remove_device(dev); transport_remove_device(dev);
device_del(dev); device_del(dev);
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include <linux/bio.h> #include <linux/bio.h>
#include <linux/stringify.h> #include <linux/stringify.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/bsg.h>
#include <linux/smp.h> #include <linux/smp.h>
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <linux/percpu-refcount.h> #include <linux/percpu-refcount.h>
...@@ -33,7 +32,6 @@ struct elevator_queue; ...@@ -33,7 +32,6 @@ struct elevator_queue;
struct blk_trace; struct blk_trace;
struct request; struct request;
struct sg_io_hdr; struct sg_io_hdr;
struct bsg_job;
struct blkcg_gq; struct blkcg_gq;
struct blk_flush_queue; struct blk_flush_queue;
struct pr_ops; struct pr_ops;
...@@ -535,10 +533,6 @@ struct request_queue { ...@@ -535,10 +533,6 @@ struct request_queue {
int mq_freeze_depth; int mq_freeze_depth;
#if IS_ENABLED(CONFIG_BLK_DEV_BSG_COMMON)
struct bsg_class_device bsg_dev;
#endif
#ifdef CONFIG_BLK_DEV_THROTTLING #ifdef CONFIG_BLK_DEV_THROTTLING
/* Throttle data */ /* Throttle data */
struct throtl_data *td; struct throtl_data *td;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <scsi/scsi_request.h> #include <scsi/scsi_request.h>
struct bsg_job;
struct request; struct request;
struct device; struct device;
struct scatterlist; struct scatterlist;
......
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
#include <uapi/linux/bsg.h> #include <uapi/linux/bsg.h>
struct bsg_device;
struct device;
struct request; struct request;
struct request_queue; struct request_queue;
#ifdef CONFIG_BLK_DEV_BSG_COMMON
struct bsg_ops { struct bsg_ops {
int (*check_proto)(struct sg_io_v4 *hdr); int (*check_proto)(struct sg_io_v4 *hdr);
int (*fill_hdr)(struct request *rq, struct sg_io_v4 *hdr, int (*fill_hdr)(struct request *rq, struct sg_io_v4 *hdr,
...@@ -16,19 +17,9 @@ struct bsg_ops { ...@@ -16,19 +17,9 @@ struct bsg_ops {
void (*free_rq)(struct request *rq); void (*free_rq)(struct request *rq);
}; };
struct bsg_class_device { struct bsg_device *bsg_register_queue(struct request_queue *q,
struct device *class_dev; struct device *parent, const char *name,
int minor; const struct bsg_ops *ops);
struct request_queue *queue; void bsg_unregister_queue(struct bsg_device *bcd);
const struct bsg_ops *ops;
};
int bsg_register_queue(struct request_queue *q, struct device *parent,
const char *name, const struct bsg_ops *ops);
void bsg_unregister_queue(struct request_queue *q);
#else
static inline void bsg_unregister_queue(struct request_queue *q)
{
}
#endif /* CONFIG_BLK_DEV_BSG_COMMON */
#endif /* _LINUX_BSG_H */ #endif /* _LINUX_BSG_H */
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/atomic.h> #include <linux/atomic.h>
#include <linux/sbitmap.h> #include <linux/sbitmap.h>
struct bsg_device;
struct device; struct device;
struct request_queue; struct request_queue;
struct scsi_cmnd; struct scsi_cmnd;
...@@ -235,6 +236,7 @@ struct scsi_device { ...@@ -235,6 +236,7 @@ struct scsi_device {
size_t dma_drain_len; size_t dma_drain_len;
void *dma_drain_buf; void *dma_drain_buf;
struct bsg_device *bsg_dev;
unsigned char access_state; unsigned char access_state;
struct mutex state_mutex; struct mutex state_mutex;
enum scsi_device_state sdev_state; enum scsi_device_state sdev_state;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment