All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bind bsg to request_queue instead of gendisk
@ 2007-02-13 17:53 FUJITA Tomonori
  2007-02-13 18:00 ` Jeff Garzik
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: FUJITA Tomonori @ 2007-02-13 17:53 UTC (permalink / raw)
  To: linux-scsi; +Cc: jens.axboe, James.Smart, hch

It seems that it would be better to bind bsg devices to request_queue
instead of gendisk. This enables any objects to define own
request_handler and create own bsg device (under sysfs).

Possible enhancements:

- I removed gendisk but it would be better for objects having gendisk
to keep it for nice features like disk stats.

- Objects that wants to use bsg need to setup a request_queue. Maybe
wrapper functions to setup a request_queue for them would be useful.

This patch was tested only with disk drivers.


Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 block/bsg.c            |   37 +++++++++++++++++--------------------
 block/ll_rw_blk.c      |    4 ++--
 include/linux/blkdev.h |    5 +++++
 include/linux/bsg.h    |    6 +++---
 include/linux/genhd.h  |    2 --
 5 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/block/bsg.c b/block/bsg.c
index c85d961..e261997 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -34,7 +34,6 @@
 static char bsg_version[] = "block layer sg (bsg) 0.4";
 
 struct bsg_device {
-	struct gendisk *disk;
 	request_queue_t *queue;
 	spinlock_t lock;
 	struct list_head busy_list;
@@ -46,7 +45,7 @@ struct bsg_device {
 	int done_cmds;
 	wait_queue_head_t wq_done;
 	wait_queue_head_t wq_free;
-	char name[BDEVNAME_SIZE];
+	char name[BUS_ID_SIZE];
 	int max_queue;
 	unsigned long flags;
 };
@@ -375,7 +374,7 @@ static void bsg_add_command(struct bsg_device *bd, request_queue_t *q,
 	dprintk("%s: queueing rq %p, bc %p\n", bd->name, rq, bc);
 
 	rq->end_io_data = bc;
-	blk_execute_rq_nowait(q, bd->disk, rq, 1, bsg_rq_end_io);
+	blk_execute_rq_nowait(q, NULL, rq, 1, bsg_rq_end_io);
 }
 
 static inline struct bsg_command *bsg_next_done_cmd(struct bsg_device *bd)
@@ -741,7 +740,7 @@ out:
 }
 
 static struct bsg_device *bsg_add_device(struct inode *inode,
-					 struct gendisk *disk,
+					 struct request_queue *rq,
 					 struct file *file)
 {
 	struct bsg_device *bd = NULL;
@@ -753,17 +752,16 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
 	if (!bd)
 		return ERR_PTR(-ENOMEM);
 
-	bd->disk = disk;
-	bd->queue = disk->queue;
-	kobject_get(&disk->queue->kobj);
+	bd->queue = rq;
+	kobject_get(&rq->kobj);
 	bsg_set_block(bd, file);
 
 	atomic_set(&bd->ref_count, 1);
 	bd->minor = iminor(inode);
 	mutex_lock(&bsg_mutex);
-	hlist_add_head(&bd->dev_list,&bsg_device_list[bsg_list_idx(bd->minor)]);
+	hlist_add_head(&bd->dev_list, &bsg_device_list[bsg_list_idx(bd->minor)]);
 
-	strncpy(bd->name, disk->disk_name, sizeof(bd->name) - 1);
+	strncpy(bd->name, rq->bsg_dev.class_dev->class_id, sizeof(bd->name) - 1);
 	dprintk("bound to <%s>, max queue %d\n",
 		format_dev_t(buf, inode->i_rdev), bd->max_queue);
 
@@ -817,7 +815,7 @@ static struct bsg_device *bsg_get_device(struct inode *inode, struct file *file)
 	if (!bcd)
 		return ERR_PTR(-ENODEV);
 
-	return bsg_add_device(inode, bcd->disk, file);
+	return bsg_add_device(inode, bcd->queue, file);
 }
 
 static int bsg_open(struct inode *inode, struct file *file)
@@ -900,7 +898,7 @@ bsg_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 	case SG_EMULATED_HOST:
 	case SCSI_IOCTL_SEND_COMMAND: {
 		void __user *uarg = (void __user *) arg;
-		return scsi_cmd_ioctl(file, bd->disk, cmd, uarg);
+		return scsi_cmd_ioctl(file, NULL, cmd, uarg);
 	}
 	case SG_IO: {
 		struct request *rq;
@@ -915,7 +913,7 @@ bsg_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 			return PTR_ERR(rq);
 
 		bio = rq->bio;
-		blk_execute_rq(bd->queue, bd->disk, rq, 0);
+		blk_execute_rq(bd->queue, NULL, rq, 0);
 		blk_complete_sgv4_hdr_rq(rq, &hdr, bio);
 
 		if (copy_to_user(uarg, &hdr, sizeof(hdr)))
@@ -945,24 +943,23 @@ static struct file_operations bsg_fops = {
 	.owner		=	THIS_MODULE,
 };
 
-void bsg_unregister_disk(struct gendisk *disk)
+void bsg_unregister_rq(struct request_queue *q)
 {
-	struct bsg_class_device *bcd = &disk->bsg_dev;
+	struct bsg_class_device *bcd = &q->bsg_dev;
 
 	if (!bcd->class_dev)
 		return;
 
 	mutex_lock(&bsg_mutex);
-	sysfs_remove_link(&bcd->disk->queue->kobj, "bsg");
+	sysfs_remove_link(&q->kobj, "bsg");
 	class_device_destroy(bsg_class, MKDEV(BSG_MAJOR, bcd->minor));
 	bcd->class_dev = NULL;
 	list_del_init(&bcd->list);
 	mutex_unlock(&bsg_mutex);
 }
 
-int bsg_register_disk(struct gendisk *disk)
+int bsg_register_rq(struct request_queue *q, char *name)
 {
-	request_queue_t *q = disk->queue;
 	struct bsg_class_device *bcd;
 	dev_t dev;
 
@@ -972,7 +969,7 @@ int bsg_register_disk(struct gendisk *disk)
 	if (!q->request_fn)
 		return 0;
 
-	bcd = &disk->bsg_dev;
+	bcd = &q->bsg_dev;
 	memset(bcd, 0, sizeof(*bcd));
 	INIT_LIST_HEAD(&bcd->list);
 
@@ -980,8 +977,8 @@ int bsg_register_disk(struct gendisk *disk)
 	dev = MKDEV(BSG_MAJOR, bsg_device_nr);
 	bcd->minor = bsg_device_nr;
 	bsg_device_nr++;
-	bcd->disk = disk;
-	bcd->class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", disk->disk_name);
+	bcd->queue = q;
+	bcd->class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", name);
 	if (!bcd->class_dev)
 		goto err;
 	list_add_tail(&bcd->list, &bsg_class_list);
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 45bbf8b..268a39f 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -4038,7 +4038,7 @@ int blk_register_queue(struct gendisk *disk)
 		return ret;
 	}
 
-	ret = bsg_register_disk(disk);
+	ret = bsg_register_rq(q, disk->disk_name);
 	if (ret) {
 		elv_unregister_queue(q);
 		kobject_unregister(&q->kobj);
@@ -4053,7 +4053,7 @@ void blk_unregister_queue(struct gendisk *disk)
 	request_queue_t *q = disk->queue;
 
 	if (q && q->request_fn) {
-		bsg_unregister_disk(disk);
+		bsg_unregister_rq(q);
 		elv_unregister_queue(q);
 
 		kobject_uevent(&q->kobj, KOBJ_REMOVE);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 9c55749..6efcfd4 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -14,6 +14,7 @@
 #include <linux/bio.h>
 #include <linux/module.h>
 #include <linux/stringify.h>
+#include <linux/bsg.h>
 
 #include <asm/scatterlist.h>
 
@@ -470,6 +471,10 @@ struct request_queue
 	unsigned int		bi_size;
 
 	struct mutex		sysfs_lock;
+
+#if defined(CONFIG_BLK_DEV_BSG)
+	struct bsg_class_device bsg_dev;
+#endif
 };
 
 #define QUEUE_FLAG_CLUSTER	0	/* cluster several segments into 1 */
diff --git a/include/linux/bsg.h b/include/linux/bsg.h
index 2154a6d..51152cb 100644
--- a/include/linux/bsg.h
+++ b/include/linux/bsg.h
@@ -47,12 +47,12 @@ struct bsg_class_device {
 	struct class_device *class_dev;
 	struct device *dev;
 	int minor;
-	struct gendisk *disk;
 	struct list_head list;
+	struct request_queue *queue;
 };
 
-extern int bsg_register_disk(struct gendisk *);
-extern void bsg_unregister_disk(struct gendisk *);
+extern int bsg_register_rq(struct request_queue *, char *);
+extern void bsg_unregister_rq(struct request_queue *);
 #else
 struct bsg_class_device { };
 #define bsg_register_disk(disk)		(0)
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 8bfe5d1..0a022b2 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -62,7 +62,6 @@ struct partition {
 #include <linux/smp.h>
 #include <linux/string.h>
 #include <linux/fs.h>
-#include <linux/bsg.h>
 
 struct partition {
 	unsigned char boot_ind;		/* 0x80 - active */
@@ -135,7 +134,6 @@ struct gendisk {
 #else
 	struct disk_stats dkstats;
 #endif
-	struct bsg_class_device bsg_dev;
 };
 
 /* Structure for sysfs attributes on block devices */
-- 
1.4.4.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] bind bsg to request_queue instead of gendisk
  2007-02-13 17:53 [PATCH] bind bsg to request_queue instead of gendisk FUJITA Tomonori
@ 2007-02-13 18:00 ` Jeff Garzik
  2007-02-14 14:07   ` Douglas Gilbert
  2007-02-15  2:13   ` FUJITA Tomonori
  2007-02-14 20:56 ` Pete Wyckoff
  2007-02-14 21:25 ` Jens Axboe
  2 siblings, 2 replies; 9+ messages in thread
From: Jeff Garzik @ 2007-02-13 18:00 UTC (permalink / raw)
  To: FUJITA Tomonori; +Cc: linux-scsi, jens.axboe, James.Smart, hch

On Wed, Feb 14, 2007 at 02:53:31AM +0900, FUJITA Tomonori wrote:
> It seems that it would be better to bind bsg devices to request_queue
> instead of gendisk. This enables any objects to define own
> request_handler and create own bsg device (under sysfs).
> 
> Possible enhancements:
> 
> - I removed gendisk but it would be better for objects having gendisk
> to keep it for nice features like disk stats.
> 
> - Objects that wants to use bsg need to setup a request_queue. Maybe
> wrapper functions to setup a request_queue for them would be useful.
> 
> This patch was tested only with disk drivers.
> 
> 
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> ---
>  block/bsg.c            |   37 +++++++++++++++++--------------------

What is this patch against?  scsi-misc?

I certainly like the bsg solution, but block/bsg.c does not exist in my
vanilla linux-2.6.git tree :)

	Jeff




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] bind bsg to request_queue instead of gendisk
  2007-02-13 18:00 ` Jeff Garzik
@ 2007-02-14 14:07   ` Douglas Gilbert
  2007-02-15  2:13   ` FUJITA Tomonori
  1 sibling, 0 replies; 9+ messages in thread
From: Douglas Gilbert @ 2007-02-14 14:07 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: FUJITA Tomonori, linux-scsi, jens.axboe, James.Smart, hch

Jeff Garzik wrote:
> On Wed, Feb 14, 2007 at 02:53:31AM +0900, FUJITA Tomonori wrote:
>> It seems that it would be better to bind bsg devices to request_queue
>> instead of gendisk. This enables any objects to define own
>> request_handler and create own bsg device (under sysfs).
>>
>> Possible enhancements:
>>
>> - I removed gendisk but it would be better for objects having gendisk
>> to keep it for nice features like disk stats.
>>
>> - Objects that wants to use bsg need to setup a request_queue. Maybe
>> wrapper functions to setup a request_queue for them would be useful.
>>
>> This patch was tested only with disk drivers.
>>
>>
>> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
>> ---
>>  block/bsg.c            |   37 +++++++++++++++++--------------------
> 
> What is this patch against?  scsi-misc?
> 
> I certainly like the bsg solution, but block/bsg.c does not exist in my
> vanilla linux-2.6.git tree :)

www.kernel.org/pub/scm/linux/kernel/git/axboe/linux-2.6-block.git

branch: bsg


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] bind bsg to request_queue instead of gendisk
  2007-02-13 17:53 [PATCH] bind bsg to request_queue instead of gendisk FUJITA Tomonori
  2007-02-13 18:00 ` Jeff Garzik
@ 2007-02-14 20:56 ` Pete Wyckoff
  2007-02-14 21:14   ` James Smart
  2007-02-14 21:25 ` Jens Axboe
  2 siblings, 1 reply; 9+ messages in thread
From: Pete Wyckoff @ 2007-02-14 20:56 UTC (permalink / raw)
  To: FUJITA Tomonori; +Cc: linux-scsi, jens.axboe, James.Smart, hch

fujita.tomonori@lab.ntt.co.jp wrote on Wed, 14 Feb 2007 02:53 +0900:
> It seems that it would be better to bind bsg devices to request_queue
> instead of gendisk. This enables any objects to define own
> request_handler and create own bsg device (under sysfs).
> 
> Possible enhancements:
> 
> - I removed gendisk but it would be better for objects having gendisk
> to keep it for nice features like disk stats.
> 
> - Objects that wants to use bsg need to setup a request_queue. Maybe
> wrapper functions to setup a request_queue for them would be useful.
> 
> This patch was tested only with disk drivers.

The only place that bsg_register_rq is called is via
blk_register_queue, which is only called by add_disk.  But not all
devices have a block interface or need the gendisk that these
functions assume.

This change registers all SCSI devices with bsg, even ones that are
not accessed through a block interface.  They already have a
request_queue; this just presents it to bsg at LUN scan time.
It uses the bus_id as the name for sysfs.

Devices that happen to be block SCSI devices are thus registered
twice, which is probably not good, but preserves the exsiting "sda"
entry, e.g., in /sys/class/bsg.

Signed-off-by: Pete Wyckoff <pw@osc.edu>
---
 block/bsg.c               |   16 +++++++++++++---
 drivers/scsi/scsi_scan.c  |    6 ++++++
 drivers/scsi/scsi_sysfs.c |    1 +
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/block/bsg.c b/block/bsg.c
index e261997..e100efe 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -962,6 +962,7 @@ int bsg_register_rq(struct request_queue *q, char *name)
 {
 	struct bsg_class_device *bcd;
 	dev_t dev;
+	int ret = -ENOMEM;
 
 	/*
 	 * we need a proper transport to send commands, not a stacked device
@@ -981,9 +982,18 @@ int bsg_register_rq(struct request_queue *q, char *name)
 	bcd->class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", name);
 	if (!bcd->class_dev)
 		goto err;
+
+	/*
+	 * Put a link, e.g., /sys/block/sda/queue/bsg -> /sys/class/bsg/sda,
+	 * if a sysfs entry for the queue exists.
+	 */
+	if (q->kobj.dentry) {
+		ret = sysfs_create_link(&q->kobj, &bcd->class_dev->kobj, "bsg");
+		if (ret)
+			goto err;
+	}
+
 	list_add_tail(&bcd->list, &bsg_class_list);
-	if (sysfs_create_link(&q->kobj, &bcd->class_dev->kobj, "bsg"))
-		goto err;
 	mutex_unlock(&bsg_mutex);
 	return 0;
 err:
@@ -991,7 +1001,7 @@ err:
 	if (bcd->class_dev)
 		class_device_destroy(bsg_class, MKDEV(BSG_MAJOR, bcd->minor));
 	mutex_unlock(&bsg_mutex);
-	return -ENOMEM;
+	return ret;
 }
 
 static int __init bsg_init(void)
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 23ab62e..8aa4c3c 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -895,6 +895,12 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
 	}
 
 	/*
+	 * Register bsg interface for every SCSI device.
+	 */
+	if (bsg_register_rq(sdev->request_queue, sdev->sdev_gendev.bus_id))
+		return SCSI_SCAN_NO_RESPONSE;
+
+	/*
 	 * Ok, the device is now all set up, we can
 	 * register it and tell the rest of the kernel
 	 * about it.
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 259c90c..bc694a5 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -238,6 +238,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
 	spin_unlock_irqrestore(sdev->host->host_lock, flags);
 
 	if (sdev->request_queue) {
+		bsg_unregister_rq(sdev->request_queue);
 		sdev->request_queue->queuedata = NULL;
 		/* user context needed to free queue */
 		scsi_free_queue(sdev->request_queue);
-- 
1.4.4.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] bind bsg to request_queue instead of gendisk
  2007-02-14 20:56 ` Pete Wyckoff
@ 2007-02-14 21:14   ` James Smart
  0 siblings, 0 replies; 9+ messages in thread
From: James Smart @ 2007-02-14 21:14 UTC (permalink / raw)
  To: Pete Wyckoff; +Cc: FUJITA Tomonori, linux-scsi, jens.axboe, hch


Pete Wyckoff wrote:
> The only place that bsg_register_rq is called is via
> blk_register_queue, which is only called by add_disk.  But not all
> devices have a block interface or need the gendisk that these
> functions assume.

FYI - very shortly, we expect dynamic transport entities to start calling
bsg_register_rq() as well.

-- james s


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] bind bsg to request_queue instead of gendisk
  2007-02-13 17:53 [PATCH] bind bsg to request_queue instead of gendisk FUJITA Tomonori
  2007-02-13 18:00 ` Jeff Garzik
  2007-02-14 20:56 ` Pete Wyckoff
@ 2007-02-14 21:25 ` Jens Axboe
  2007-03-19 10:25   ` FUJITA Tomonori
  2 siblings, 1 reply; 9+ messages in thread
From: Jens Axboe @ 2007-02-14 21:25 UTC (permalink / raw)
  To: FUJITA Tomonori; +Cc: linux-scsi, James.Smart, hch

On Wed, Feb 14 2007, FUJITA Tomonori wrote:
> It seems that it would be better to bind bsg devices to request_queue
> instead of gendisk. This enables any objects to define own
> request_handler and create own bsg device (under sysfs).
> 
> Possible enhancements:
> 
> - I removed gendisk but it would be better for objects having gendisk
> to keep it for nice features like disk stats.
> 
> - Objects that wants to use bsg need to setup a request_queue. Maybe
> wrapper functions to setup a request_queue for them would be useful.
> 
> This patch was tested only with disk drivers.

Looks good, as discussed in-person I just want to change the _rq name as
that usually implies "struct request" in the block layer. _queue is much
better.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] bind bsg to request_queue instead of gendisk
  2007-02-13 18:00 ` Jeff Garzik
  2007-02-14 14:07   ` Douglas Gilbert
@ 2007-02-15  2:13   ` FUJITA Tomonori
  1 sibling, 0 replies; 9+ messages in thread
From: FUJITA Tomonori @ 2007-02-15  2:13 UTC (permalink / raw)
  To: jeff; +Cc: fujita.tomonori, linux-scsi, jens.axboe, James.Smart, hch

From: Jeff Garzik <jeff@garzik.org>
Subject: Re: [PATCH] bind bsg to request_queue instead of gendisk
Date: Tue, 13 Feb 2007 13:00:33 -0500

> On Wed, Feb 14, 2007 at 02:53:31AM +0900, FUJITA Tomonori wrote:
> > It seems that it would be better to bind bsg devices to request_queue
> > instead of gendisk. This enables any objects to define own
> > request_handler and create own bsg device (under sysfs).
> > 
> > Possible enhancements:
> > 
> > - I removed gendisk but it would be better for objects having gendisk
> > to keep it for nice features like disk stats.
> > 
> > - Objects that wants to use bsg need to setup a request_queue. Maybe
> > wrapper functions to setup a request_queue for them would be useful.
> > 
> > This patch was tested only with disk drivers.
> > 
> > 
> > Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> > ---
> >  block/bsg.c            |   37 +++++++++++++++++--------------------
> 
> What is this patch against?  scsi-misc?

Oops. As Doug said, it's against Jens's block tree (bsg branch).


> I certainly like the bsg solution, but block/bsg.c does not exist in my
> vanilla linux-2.6.git tree :)

Hopefully we see it in mainline soon. :)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] bind bsg to request_queue instead of gendisk
  2007-02-14 21:25 ` Jens Axboe
@ 2007-03-19 10:25   ` FUJITA Tomonori
  2007-03-19 19:03     ` FUJITA Tomonori
  0 siblings, 1 reply; 9+ messages in thread
From: FUJITA Tomonori @ 2007-03-19 10:25 UTC (permalink / raw)
  To: jens.axboe; +Cc: fujita.tomonori, linux-scsi, James.Smart, hch

From: Jens Axboe <jens.axboe@oracle.com>
Subject: Re: [PATCH] bind bsg to request_queue instead of gendisk
Date: Wed, 14 Feb 2007 22:25:00 +0100

> On Wed, Feb 14 2007, FUJITA Tomonori wrote:
> > It seems that it would be better to bind bsg devices to request_queue
> > instead of gendisk. This enables any objects to define own
> > request_handler and create own bsg device (under sysfs).
> > 
> > Possible enhancements:
> > 
> > - I removed gendisk but it would be better for objects having gendisk
> > to keep it for nice features like disk stats.
> > 
> > - Objects that wants to use bsg need to setup a request_queue. Maybe
> > wrapper functions to setup a request_queue for them would be useful.
> > 
> > This patch was tested only with disk drivers.
> 
> Looks good, as discussed in-person I just want to change the _rq name as
> that usually implies "struct request" in the block layer. _queue is much
> better.

Here is a resend though including the following updates.

- bsg_register/unregister_rq are renamed bsg_register/unregister_queue

- fix !CONFIG_BLK_DEV_BSG compilation

---
From: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>

This binds bsg devices to request_queue instead of gendisk. It enables
any objects (like transport entities) to define own request_handler
and create own bsg device.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
---
 block/bsg.c            |   37 +++++++++++++++++--------------------
 block/ll_rw_blk.c      |    4 ++--
 include/linux/blkdev.h |    5 +++++
 include/linux/bsg.h    |   10 +++++-----
 include/linux/genhd.h  |    2 --
 5 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/block/bsg.c b/block/bsg.c
index c85d961..b64d004 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -34,7 +34,6 @@ #include <scsi/sg.h>
 static char bsg_version[] = "block layer sg (bsg) 0.4";
 
 struct bsg_device {
-	struct gendisk *disk;
 	request_queue_t *queue;
 	spinlock_t lock;
 	struct list_head busy_list;
@@ -46,7 +45,7 @@ struct bsg_device {
 	int done_cmds;
 	wait_queue_head_t wq_done;
 	wait_queue_head_t wq_free;
-	char name[BDEVNAME_SIZE];
+	char name[BUS_ID_SIZE];
 	int max_queue;
 	unsigned long flags;
 };
@@ -375,7 +374,7 @@ static void bsg_add_command(struct bsg_d
 	dprintk("%s: queueing rq %p, bc %p\n", bd->name, rq, bc);
 
 	rq->end_io_data = bc;
-	blk_execute_rq_nowait(q, bd->disk, rq, 1, bsg_rq_end_io);
+	blk_execute_rq_nowait(q, NULL, rq, 1, bsg_rq_end_io);
 }
 
 static inline struct bsg_command *bsg_next_done_cmd(struct bsg_device *bd)
@@ -741,7 +740,7 @@ out:
 }
 
 static struct bsg_device *bsg_add_device(struct inode *inode,
-					 struct gendisk *disk,
+					 struct request_queue *rq,
 					 struct file *file)
 {
 	struct bsg_device *bd = NULL;
@@ -753,17 +752,16 @@ #endif
 	if (!bd)
 		return ERR_PTR(-ENOMEM);
 
-	bd->disk = disk;
-	bd->queue = disk->queue;
-	kobject_get(&disk->queue->kobj);
+	bd->queue = rq;
+	kobject_get(&rq->kobj);
 	bsg_set_block(bd, file);
 
 	atomic_set(&bd->ref_count, 1);
 	bd->minor = iminor(inode);
 	mutex_lock(&bsg_mutex);
-	hlist_add_head(&bd->dev_list,&bsg_device_list[bsg_list_idx(bd->minor)]);
+	hlist_add_head(&bd->dev_list, &bsg_device_list[bsg_list_idx(bd->minor)]);
 
-	strncpy(bd->name, disk->disk_name, sizeof(bd->name) - 1);
+	strncpy(bd->name, rq->bsg_dev.class_dev->class_id, sizeof(bd->name) - 1);
 	dprintk("bound to <%s>, max queue %d\n",
 		format_dev_t(buf, inode->i_rdev), bd->max_queue);
 
@@ -817,7 +815,7 @@ static struct bsg_device *bsg_get_device
 	if (!bcd)
 		return ERR_PTR(-ENODEV);
 
-	return bsg_add_device(inode, bcd->disk, file);
+	return bsg_add_device(inode, bcd->queue, file);
 }
 
 static int bsg_open(struct inode *inode, struct file *file)
@@ -900,7 +898,7 @@ bsg_ioctl(struct inode *inode, struct fi
 	case SG_EMULATED_HOST:
 	case SCSI_IOCTL_SEND_COMMAND: {
 		void __user *uarg = (void __user *) arg;
-		return scsi_cmd_ioctl(file, bd->disk, cmd, uarg);
+		return scsi_cmd_ioctl(file, NULL, cmd, uarg);
 	}
 	case SG_IO: {
 		struct request *rq;
@@ -915,7 +913,7 @@ bsg_ioctl(struct inode *inode, struct fi
 			return PTR_ERR(rq);
 
 		bio = rq->bio;
-		blk_execute_rq(bd->queue, bd->disk, rq, 0);
+		blk_execute_rq(bd->queue, NULL, rq, 0);
 		blk_complete_sgv4_hdr_rq(rq, &hdr, bio);
 
 		if (copy_to_user(uarg, &hdr, sizeof(hdr)))
@@ -945,24 +943,23 @@ static struct file_operations bsg_fops =
 	.owner		=	THIS_MODULE,
 };
 
-void bsg_unregister_disk(struct gendisk *disk)
+void bsg_unregister_queue(struct request_queue *q)
 {
-	struct bsg_class_device *bcd = &disk->bsg_dev;
+	struct bsg_class_device *bcd = &q->bsg_dev;
 
 	if (!bcd->class_dev)
 		return;
 
 	mutex_lock(&bsg_mutex);
-	sysfs_remove_link(&bcd->disk->queue->kobj, "bsg");
+	sysfs_remove_link(&q->kobj, "bsg");
 	class_device_destroy(bsg_class, MKDEV(BSG_MAJOR, bcd->minor));
 	bcd->class_dev = NULL;
 	list_del_init(&bcd->list);
 	mutex_unlock(&bsg_mutex);
 }
 
-int bsg_register_disk(struct gendisk *disk)
+int bsg_register_queue(struct request_queue *q, char *name)
 {
-	request_queue_t *q = disk->queue;
 	struct bsg_class_device *bcd;
 	dev_t dev;
 
@@ -972,7 +969,7 @@ int bsg_register_disk(struct gendisk *di
 	if (!q->request_fn)
 		return 0;
 
-	bcd = &disk->bsg_dev;
+	bcd = &q->bsg_dev;
 	memset(bcd, 0, sizeof(*bcd));
 	INIT_LIST_HEAD(&bcd->list);
 
@@ -980,8 +977,8 @@ int bsg_register_disk(struct gendisk *di
 	dev = MKDEV(BSG_MAJOR, bsg_device_nr);
 	bcd->minor = bsg_device_nr;
 	bsg_device_nr++;
-	bcd->disk = disk;
-	bcd->class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", disk->disk_name);
+	bcd->queue = q;
+	bcd->class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", name);
 	if (!bcd->class_dev)
 		goto err;
 	list_add_tail(&bcd->list, &bsg_class_list);
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index a08e9ca..fccc3a1 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -4038,7 +4038,7 @@ int blk_register_queue(struct gendisk *d
 		return ret;
 	}
 
-	ret = bsg_register_disk(disk);
+	ret = bsg_register_queue(q, disk->disk_name);
 	if (ret) {
 		elv_unregister_queue(q);
 		kobject_unregister(&q->kobj);
@@ -4053,7 +4053,7 @@ void blk_unregister_queue(struct gendisk
 	request_queue_t *q = disk->queue;
 
 	if (q && q->request_fn) {
-		bsg_unregister_disk(disk);
+		bsg_unregister_queue(q);
 		elv_unregister_queue(q);
 
 		kobject_uevent(&q->kobj, KOBJ_REMOVE);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index aa000d2..b114d7e 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -14,6 +14,7 @@ #include <linux/mempool.h>
 #include <linux/bio.h>
 #include <linux/module.h>
 #include <linux/stringify.h>
+#include <linux/bsg.h>
 
 #include <asm/scatterlist.h>
 
@@ -469,6 +470,10 @@ #endif
 	unsigned int		bi_size;
 
 	struct mutex		sysfs_lock;
+
+#if defined(CONFIG_BLK_DEV_BSG)
+	struct bsg_class_device bsg_dev;
+#endif
 };
 
 #define QUEUE_FLAG_CLUSTER	0	/* cluster several segments into 1 */
diff --git a/include/linux/bsg.h b/include/linux/bsg.h
index 2154a6d..0475a6d 100644
--- a/include/linux/bsg.h
+++ b/include/linux/bsg.h
@@ -47,16 +47,16 @@ struct bsg_class_device {
 	struct class_device *class_dev;
 	struct device *dev;
 	int minor;
-	struct gendisk *disk;
 	struct list_head list;
+	struct request_queue *queue;
 };
 
-extern int bsg_register_disk(struct gendisk *);
-extern void bsg_unregister_disk(struct gendisk *);
+extern int bsg_register_queue(struct request_queue *, char *);
+extern void bsg_unregister_queue(struct request_queue *);
 #else
 struct bsg_class_device { };
-#define bsg_register_disk(disk)		(0)
-#define bsg_unregister_disk(disk)	do { } while (0)
+#define bsg_register_queue(disk, name)		(0)
+#define bsg_unregister_queue(disk)	do { } while (0)
 #endif
 
 #endif /* __KERNEL__ */
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 0dcfc3b..2c65da7 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -66,7 +66,6 @@ #include <linux/device.h>
 #include <linux/smp.h>
 #include <linux/string.h>
 #include <linux/fs.h>
-#include <linux/bsg.h>
 
 struct partition {
 	unsigned char boot_ind;		/* 0x80 - active */
@@ -139,7 +138,6 @@ #ifdef	CONFIG_SMP
 #else
 	struct disk_stats dkstats;
 #endif
-	struct bsg_class_device bsg_dev;
 };
 
 /* Structure for sysfs attributes on block devices */
-- 
1.4.3.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] bind bsg to request_queue instead of gendisk
  2007-03-19 10:25   ` FUJITA Tomonori
@ 2007-03-19 19:03     ` FUJITA Tomonori
  0 siblings, 0 replies; 9+ messages in thread
From: FUJITA Tomonori @ 2007-03-19 19:03 UTC (permalink / raw)
  To: jens.axboe; +Cc: linux-scsi, James.Smart, hch

From: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Subject: Re: [PATCH] bind bsg to request_queue instead of gendisk
Date: Mon, 19 Mar 2007 19:25:34 +0900

> From: Jens Axboe <jens.axboe@oracle.com>
> Subject: Re: [PATCH] bind bsg to request_queue instead of gendisk
> Date: Wed, 14 Feb 2007 22:25:00 +0100
> 
> > On Wed, Feb 14 2007, FUJITA Tomonori wrote:
> > > It seems that it would be better to bind bsg devices to request_queue
> > > instead of gendisk. This enables any objects to define own
> > > request_handler and create own bsg device (under sysfs).
> > > 
> > > Possible enhancements:
> > > 
> > > - I removed gendisk but it would be better for objects having gendisk
> > > to keep it for nice features like disk stats.
> > > 
> > > - Objects that wants to use bsg need to setup a request_queue. Maybe
> > > wrapper functions to setup a request_queue for them would be useful.
> > > 
> > > This patch was tested only with disk drivers.
> > 
> > Looks good, as discussed in-person I just want to change the _rq name as
> > that usually implies "struct request" in the block layer. _queue is much
> > better.
> 
> Here is a resend though including the following updates.
> 
> - bsg_register/unregister_rq are renamed bsg_register/unregister_queue
> 
> - fix !CONFIG_BLK_DEV_BSG compilation
> 
> ---
> From: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> 
> This binds bsg devices to request_queue instead of gendisk. It enables
> any objects (like transport entities) to define own request_handler
> and create own bsg device.
> 
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>

Sorry, this patch doesn't work. I'll resend an updated patch later.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-03-19 19:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-13 17:53 [PATCH] bind bsg to request_queue instead of gendisk FUJITA Tomonori
2007-02-13 18:00 ` Jeff Garzik
2007-02-14 14:07   ` Douglas Gilbert
2007-02-15  2:13   ` FUJITA Tomonori
2007-02-14 20:56 ` Pete Wyckoff
2007-02-14 21:14   ` James Smart
2007-02-14 21:25 ` Jens Axboe
2007-03-19 10:25   ` FUJITA Tomonori
2007-03-19 19:03     ` FUJITA Tomonori

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.