提交 aebbb583 编写于 作者: C Christoph Hellwig 提交者: Jens Axboe

sg: do not allocate a gendisk

sg is a character driver and thus does not need to allocate a gendisk,
which is only used for file system-like block layer I/O on block
devices.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NLuis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20210816131910.615153-4-hch@lst.deSigned-off-by: NJens Axboe <axboe@kernel.dk>
上级 45938335
...@@ -166,7 +166,7 @@ typedef struct sg_device { /* holds the state of each scsi generic device */ ...@@ -166,7 +166,7 @@ typedef struct sg_device { /* holds the state of each scsi generic device */
bool exclude; /* 1->open(O_EXCL) succeeded and is active */ bool exclude; /* 1->open(O_EXCL) succeeded and is active */
int open_cnt; /* count of opens (perhaps < num(sfds) ) */ int open_cnt; /* count of opens (perhaps < num(sfds) ) */
char sgdebug; /* 0->off, 1->sense, 9->dump dev, 10-> all devs */ char sgdebug; /* 0->off, 1->sense, 9->dump dev, 10-> all devs */
struct gendisk *disk; char name[DISK_NAME_LEN];
struct cdev * cdev; /* char_dev [sysfs: /sys/cdev/major/sg<n>] */ struct cdev * cdev; /* char_dev [sysfs: /sys/cdev/major/sg<n>] */
struct kref d_ref; struct kref d_ref;
} Sg_device; } Sg_device;
...@@ -202,8 +202,7 @@ static void sg_device_destroy(struct kref *kref); ...@@ -202,8 +202,7 @@ static void sg_device_destroy(struct kref *kref);
#define SZ_SG_REQ_INFO sizeof(sg_req_info_t) #define SZ_SG_REQ_INFO sizeof(sg_req_info_t)
#define sg_printk(prefix, sdp, fmt, a...) \ #define sg_printk(prefix, sdp, fmt, a...) \
sdev_prefix_printk(prefix, (sdp)->device, \ sdev_prefix_printk(prefix, (sdp)->device, (sdp)->name, fmt, ##a)
(sdp)->disk->disk_name, fmt, ##a)
/* /*
* The SCSI interfaces that use read() and write() as an asynchronous variant of * The SCSI interfaces that use read() and write() as an asynchronous variant of
...@@ -832,7 +831,7 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp, ...@@ -832,7 +831,7 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp,
srp->rq->timeout = timeout; srp->rq->timeout = timeout;
kref_get(&sfp->f_ref); /* sg_rq_end_io() does kref_put(). */ kref_get(&sfp->f_ref); /* sg_rq_end_io() does kref_put(). */
blk_execute_rq_nowait(sdp->disk, srp->rq, at_head, sg_rq_end_io); blk_execute_rq_nowait(NULL, srp->rq, at_head, sg_rq_end_io);
return 0; return 0;
} }
...@@ -1119,8 +1118,7 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp, ...@@ -1119,8 +1118,7 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,
return put_user(max_sectors_bytes(sdp->device->request_queue), return put_user(max_sectors_bytes(sdp->device->request_queue),
ip); ip);
case BLKTRACESETUP: case BLKTRACESETUP:
return blk_trace_setup(sdp->device->request_queue, return blk_trace_setup(sdp->device->request_queue, NULL,
sdp->disk->disk_name,
MKDEV(SCSI_GENERIC_MAJOR, sdp->index), MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
NULL, p); NULL, p);
case BLKTRACESTART: case BLKTRACESTART:
...@@ -1456,7 +1454,7 @@ static struct class *sg_sysfs_class; ...@@ -1456,7 +1454,7 @@ static struct class *sg_sysfs_class;
static int sg_sysfs_valid = 0; static int sg_sysfs_valid = 0;
static Sg_device * static Sg_device *
sg_alloc(struct gendisk *disk, struct scsi_device *scsidp) sg_alloc(struct scsi_device *scsidp)
{ {
struct request_queue *q = scsidp->request_queue; struct request_queue *q = scsidp->request_queue;
Sg_device *sdp; Sg_device *sdp;
...@@ -1492,9 +1490,7 @@ sg_alloc(struct gendisk *disk, struct scsi_device *scsidp) ...@@ -1492,9 +1490,7 @@ sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
SCSI_LOG_TIMEOUT(3, sdev_printk(KERN_INFO, scsidp, SCSI_LOG_TIMEOUT(3, sdev_printk(KERN_INFO, scsidp,
"sg_alloc: dev=%d \n", k)); "sg_alloc: dev=%d \n", k));
sprintf(disk->disk_name, "sg%d", k); sprintf(sdp->name, "sg%d", k);
disk->first_minor = k;
sdp->disk = disk;
sdp->device = scsidp; sdp->device = scsidp;
mutex_init(&sdp->open_rel_lock); mutex_init(&sdp->open_rel_lock);
INIT_LIST_HEAD(&sdp->sfds); INIT_LIST_HEAD(&sdp->sfds);
...@@ -1521,19 +1517,11 @@ static int ...@@ -1521,19 +1517,11 @@ static int
sg_add_device(struct device *cl_dev, struct class_interface *cl_intf) sg_add_device(struct device *cl_dev, struct class_interface *cl_intf)
{ {
struct scsi_device *scsidp = to_scsi_device(cl_dev->parent); struct scsi_device *scsidp = to_scsi_device(cl_dev->parent);
struct gendisk *disk;
Sg_device *sdp = NULL; Sg_device *sdp = NULL;
struct cdev * cdev = NULL; struct cdev * cdev = NULL;
int error; int error;
unsigned long iflags; unsigned long iflags;
disk = alloc_disk(1);
if (!disk) {
pr_warn("%s: alloc_disk failed\n", __func__);
return -ENOMEM;
}
disk->major = SCSI_GENERIC_MAJOR;
error = -ENOMEM; error = -ENOMEM;
cdev = cdev_alloc(); cdev = cdev_alloc();
if (!cdev) { if (!cdev) {
...@@ -1543,7 +1531,7 @@ sg_add_device(struct device *cl_dev, struct class_interface *cl_intf) ...@@ -1543,7 +1531,7 @@ sg_add_device(struct device *cl_dev, struct class_interface *cl_intf)
cdev->owner = THIS_MODULE; cdev->owner = THIS_MODULE;
cdev->ops = &sg_fops; cdev->ops = &sg_fops;
sdp = sg_alloc(disk, scsidp); sdp = sg_alloc(scsidp);
if (IS_ERR(sdp)) { if (IS_ERR(sdp)) {
pr_warn("%s: sg_alloc failed\n", __func__); pr_warn("%s: sg_alloc failed\n", __func__);
error = PTR_ERR(sdp); error = PTR_ERR(sdp);
...@@ -1561,7 +1549,7 @@ sg_add_device(struct device *cl_dev, struct class_interface *cl_intf) ...@@ -1561,7 +1549,7 @@ sg_add_device(struct device *cl_dev, struct class_interface *cl_intf)
sg_class_member = device_create(sg_sysfs_class, cl_dev->parent, sg_class_member = device_create(sg_sysfs_class, cl_dev->parent,
MKDEV(SCSI_GENERIC_MAJOR, MKDEV(SCSI_GENERIC_MAJOR,
sdp->index), sdp->index),
sdp, "%s", disk->disk_name); sdp, "%s", sdp->name);
if (IS_ERR(sg_class_member)) { if (IS_ERR(sg_class_member)) {
pr_err("%s: device_create failed\n", __func__); pr_err("%s: device_create failed\n", __func__);
error = PTR_ERR(sg_class_member); error = PTR_ERR(sg_class_member);
...@@ -1589,7 +1577,6 @@ sg_add_device(struct device *cl_dev, struct class_interface *cl_intf) ...@@ -1589,7 +1577,6 @@ sg_add_device(struct device *cl_dev, struct class_interface *cl_intf)
kfree(sdp); kfree(sdp);
out: out:
put_disk(disk);
if (cdev) if (cdev)
cdev_del(cdev); cdev_del(cdev);
return error; return error;
...@@ -1613,7 +1600,6 @@ sg_device_destroy(struct kref *kref) ...@@ -1613,7 +1600,6 @@ sg_device_destroy(struct kref *kref)
SCSI_LOG_TIMEOUT(3, SCSI_LOG_TIMEOUT(3,
sg_printk(KERN_INFO, sdp, "sg_device_destroy\n")); sg_printk(KERN_INFO, sdp, "sg_device_destroy\n"));
put_disk(sdp->disk);
kfree(sdp); kfree(sdp);
} }
...@@ -2606,7 +2592,7 @@ static int sg_proc_seq_show_debug(struct seq_file *s, void *v) ...@@ -2606,7 +2592,7 @@ static int sg_proc_seq_show_debug(struct seq_file *s, void *v)
goto skip; goto skip;
read_lock(&sdp->sfd_lock); read_lock(&sdp->sfd_lock);
if (!list_empty(&sdp->sfds)) { if (!list_empty(&sdp->sfds)) {
seq_printf(s, " >>> device=%s ", sdp->disk->disk_name); seq_printf(s, " >>> device=%s ", sdp->name);
if (atomic_read(&sdp->detaching)) if (atomic_read(&sdp->detaching))
seq_puts(s, "detaching pending close "); seq_puts(s, "detaching pending close ");
else if (sdp->device) { else if (sdp->device) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册