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 @@
* Copyright (C) 2011 Red Hat, Inc. All rights reserved.
* Copyright (C) 2011 Mike Christie
*/
#include <linux/bsg.h>
#include <linux/slab.h>
#include <linux/blk-mq.h>
#include <linux/delay.h>
......@@ -19,6 +20,7 @@
struct bsg_set {
struct blk_mq_tag_set tag_set;
struct bsg_device *bd;
bsg_job_fn *job_fn;
bsg_timeout_fn *timeout_fn;
};
......@@ -327,7 +329,7 @@ void bsg_remove_queue(struct request_queue *q)
struct bsg_set *bset =
container_of(q->tag_set, struct bsg_set, tag_set);
bsg_unregister_queue(q);
bsg_unregister_queue(bset->bd);
blk_cleanup_queue(q);
blk_mq_free_tag_set(&bset->tag_set);
kfree(bset);
......@@ -396,10 +398,9 @@ struct request_queue *bsg_setup_queue(struct device *dev, const char *name,
q->queuedata = dev;
blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
ret = bsg_register_queue(q, dev, name, &bsg_transport_ops);
if (ret) {
printk(KERN_ERR "%s: bsg interface failed to "
"initialize - register queue\n", dev->kobj.name);
bset->bd = bsg_register_queue(q, dev, name, &bsg_transport_ops);
if (IS_ERR(bset->bd)) {
ret = PTR_ERR(bset->bd);
goto out_cleanup_queue;
}
......
This diff is collapsed.
......@@ -89,7 +89,8 @@ static const struct bsg_ops scsi_bsg_ops = {
.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 @@
#include <scsi/scsi_device.h>
#include <linux/sbitmap.h>
struct bsg_device;
struct request_queue;
struct request;
struct scsi_cmnd;
......@@ -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) { }
#endif
#ifdef CONFIG_BLK_DEV_BSG
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
struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev);
extern int scsi_device_max_queue_depth(struct scsi_device *sdev);
......
......@@ -13,6 +13,7 @@
#include <linux/blkdev.h>
#include <linux/device.h>
#include <linux/pm_runtime.h>
#include <linux/bsg.h>
#include <scsi/scsi.h>
#include <scsi/scsi_device.h>
......@@ -1327,7 +1328,6 @@ static int scsi_target_add(struct scsi_target *starget)
int scsi_sysfs_add_sdev(struct scsi_device *sdev)
{
int error, i;
struct request_queue *rq = sdev->request_queue;
struct scsi_target *starget = sdev->sdev_target;
error = scsi_target_add(starget);
......@@ -1366,12 +1366,19 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
transport_add_device(&sdev->sdev_gendev);
sdev->is_visible = 1;
error = scsi_bsg_register_queue(rq, &sdev->sdev_gendev);
if (error)
/* we're treating error on bsg register as non-fatal,
* so pretend nothing went wrong */
sdev_printk(KERN_INFO, sdev,
"Failed to register bsg queue, errno=%d\n", error);
if (IS_ENABLED(CONFIG_BLK_DEV_BSG)) {
sdev->bsg_dev = scsi_bsg_register_queue(sdev);
if (IS_ERR(sdev->bsg_dev)) {
/*
* We're treating error on bsg register as non-fatal, so
* 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 */
if (sdev->host->hostt->sdev_attrs) {
......@@ -1433,7 +1440,8 @@ void __scsi_remove_device(struct scsi_device *sdev)
sysfs_remove_groups(&sdev->sdev_gendev.kobj,
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);
transport_remove_device(dev);
device_del(dev);
......
......@@ -18,7 +18,6 @@
#include <linux/bio.h>
#include <linux/stringify.h>
#include <linux/gfp.h>
#include <linux/bsg.h>
#include <linux/smp.h>
#include <linux/rcupdate.h>
#include <linux/percpu-refcount.h>
......@@ -33,7 +32,6 @@ struct elevator_queue;
struct blk_trace;
struct request;
struct sg_io_hdr;
struct bsg_job;
struct blkcg_gq;
struct blk_flush_queue;
struct pr_ops;
......@@ -535,10 +533,6 @@ struct request_queue {
int mq_freeze_depth;
#if IS_ENABLED(CONFIG_BLK_DEV_BSG_COMMON)
struct bsg_class_device bsg_dev;
#endif
#ifdef CONFIG_BLK_DEV_THROTTLING
/* Throttle data */
struct throtl_data *td;
......
......@@ -12,6 +12,7 @@
#include <linux/blkdev.h>
#include <scsi/scsi_request.h>
struct bsg_job;
struct request;
struct device;
struct scatterlist;
......
......@@ -4,10 +4,11 @@
#include <uapi/linux/bsg.h>
struct bsg_device;
struct device;
struct request;
struct request_queue;
#ifdef CONFIG_BLK_DEV_BSG_COMMON
struct bsg_ops {
int (*check_proto)(struct sg_io_v4 *hdr);
int (*fill_hdr)(struct request *rq, struct sg_io_v4 *hdr,
......@@ -16,19 +17,9 @@ struct bsg_ops {
void (*free_rq)(struct request *rq);
};
struct bsg_class_device {
struct device *class_dev;
int minor;
struct request_queue *queue;
const struct bsg_ops *ops;
};
struct bsg_device *bsg_register_queue(struct request_queue *q,
struct device *parent, const char *name,
const struct bsg_ops *ops);
void bsg_unregister_queue(struct bsg_device *bcd);
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 */
......@@ -10,6 +10,7 @@
#include <linux/atomic.h>
#include <linux/sbitmap.h>
struct bsg_device;
struct device;
struct request_queue;
struct scsi_cmnd;
......@@ -235,6 +236,7 @@ struct scsi_device {
size_t dma_drain_len;
void *dma_drain_buf;
struct bsg_device *bsg_dev;
unsigned char access_state;
struct mutex state_mutex;
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