aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2007-07-09 06:40:35 -0400
committerJens Axboe <jens.axboe@oracle.com>2007-07-16 02:52:46 -0400
commitd351af01b9307566135cb0f355ca65d0952c10b5 (patch)
tree6d6b964e5d6474f427907ca259e6c6ac76ed9d90 /block
parent45e79a3acdcf54113b3d7b23e9e64e6541dbfeb5 (diff)
bsg: bind bsg to request_queue instead of gendisk
This patch binds bsg devices to request_queue instead of gendisk. Any objects (like transport entities) can define own request_handler and create own bsg device. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'block')
-rw-r--r--block/bsg.c37
-rw-r--r--block/ll_rw_blk.c4
2 files changed, 19 insertions, 22 deletions
diff --git a/block/bsg.c b/block/bsg.c
index 0427ece9b6d8..4ea4bedb413f 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -34,7 +34,6 @@
34static char bsg_version[] = "block layer sg (bsg) 0.4"; 34static char bsg_version[] = "block layer sg (bsg) 0.4";
35 35
36struct bsg_device { 36struct bsg_device {
37 struct gendisk *disk;
38 request_queue_t *queue; 37 request_queue_t *queue;
39 spinlock_t lock; 38 spinlock_t lock;
40 struct list_head busy_list; 39 struct list_head busy_list;
@@ -46,7 +45,7 @@ struct bsg_device {
46 int done_cmds; 45 int done_cmds;
47 wait_queue_head_t wq_done; 46 wait_queue_head_t wq_done;
48 wait_queue_head_t wq_free; 47 wait_queue_head_t wq_free;
49 char name[BDEVNAME_SIZE]; 48 char name[BUS_ID_SIZE];
50 int max_queue; 49 int max_queue;
51 unsigned long flags; 50 unsigned long flags;
52}; 51};
@@ -375,7 +374,7 @@ static void bsg_add_command(struct bsg_device *bd, request_queue_t *q,
375 dprintk("%s: queueing rq %p, bc %p\n", bd->name, rq, bc); 374 dprintk("%s: queueing rq %p, bc %p\n", bd->name, rq, bc);
376 375
377 rq->end_io_data = bc; 376 rq->end_io_data = bc;
378 blk_execute_rq_nowait(q, bd->disk, rq, 1, bsg_rq_end_io); 377 blk_execute_rq_nowait(q, NULL, rq, 1, bsg_rq_end_io);
379} 378}
380 379
381static inline struct bsg_command *bsg_next_done_cmd(struct bsg_device *bd) 380static inline struct bsg_command *bsg_next_done_cmd(struct bsg_device *bd)
@@ -741,7 +740,7 @@ out:
741} 740}
742 741
743static struct bsg_device *bsg_add_device(struct inode *inode, 742static struct bsg_device *bsg_add_device(struct inode *inode,
744 struct gendisk *disk, 743 struct request_queue *rq,
745 struct file *file) 744 struct file *file)
746{ 745{
747 struct bsg_device *bd = NULL; 746 struct bsg_device *bd = NULL;
@@ -753,17 +752,16 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
753 if (!bd) 752 if (!bd)
754 return ERR_PTR(-ENOMEM); 753 return ERR_PTR(-ENOMEM);
755 754
756 bd->disk = disk; 755 bd->queue = rq;
757 bd->queue = disk->queue; 756 kobject_get(&rq->kobj);
758 kobject_get(&disk->queue->kobj);
759 bsg_set_block(bd, file); 757 bsg_set_block(bd, file);
760 758
761 atomic_set(&bd->ref_count, 1); 759 atomic_set(&bd->ref_count, 1);
762 bd->minor = iminor(inode); 760 bd->minor = iminor(inode);
763 mutex_lock(&bsg_mutex); 761 mutex_lock(&bsg_mutex);
764 hlist_add_head(&bd->dev_list,&bsg_device_list[bsg_list_idx(bd->minor)]); 762 hlist_add_head(&bd->dev_list, &bsg_device_list[bsg_list_idx(bd->minor)]);
765 763
766 strncpy(bd->name, disk->disk_name, sizeof(bd->name) - 1); 764 strncpy(bd->name, rq->bsg_dev.class_dev->class_id, sizeof(bd->name) - 1);
767 dprintk("bound to <%s>, max queue %d\n", 765 dprintk("bound to <%s>, max queue %d\n",
768 format_dev_t(buf, inode->i_rdev), bd->max_queue); 766 format_dev_t(buf, inode->i_rdev), bd->max_queue);
769 767
@@ -817,7 +815,7 @@ static struct bsg_device *bsg_get_device(struct inode *inode, struct file *file)
817 if (!bcd) 815 if (!bcd)
818 return ERR_PTR(-ENODEV); 816 return ERR_PTR(-ENODEV);
819 817
820 return bsg_add_device(inode, bcd->disk, file); 818 return bsg_add_device(inode, bcd->queue, file);
821} 819}
822 820
823static int bsg_open(struct inode *inode, struct file *file) 821static int bsg_open(struct inode *inode, struct file *file)
@@ -900,7 +898,7 @@ bsg_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
900 case SG_EMULATED_HOST: 898 case SG_EMULATED_HOST:
901 case SCSI_IOCTL_SEND_COMMAND: { 899 case SCSI_IOCTL_SEND_COMMAND: {
902 void __user *uarg = (void __user *) arg; 900 void __user *uarg = (void __user *) arg;
903 return scsi_cmd_ioctl(file, bd->queue, bd->disk, cmd, uarg); 901 return scsi_cmd_ioctl(file, bd->queue, NULL, cmd, uarg);
904 } 902 }
905 case SG_IO: { 903 case SG_IO: {
906 struct request *rq; 904 struct request *rq;
@@ -915,7 +913,7 @@ bsg_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
915 return PTR_ERR(rq); 913 return PTR_ERR(rq);
916 914
917 bio = rq->bio; 915 bio = rq->bio;
918 blk_execute_rq(bd->queue, bd->disk, rq, 0); 916 blk_execute_rq(bd->queue, NULL, rq, 0);
919 blk_complete_sgv4_hdr_rq(rq, &hdr, bio); 917 blk_complete_sgv4_hdr_rq(rq, &hdr, bio);
920 918
921 if (copy_to_user(uarg, &hdr, sizeof(hdr))) 919 if (copy_to_user(uarg, &hdr, sizeof(hdr)))
@@ -945,24 +943,23 @@ static struct file_operations bsg_fops = {
945 .owner = THIS_MODULE, 943 .owner = THIS_MODULE,
946}; 944};
947 945
948void bsg_unregister_disk(struct gendisk *disk) 946void bsg_unregister_queue(struct request_queue *q)
949{ 947{
950 struct bsg_class_device *bcd = &disk->bsg_dev; 948 struct bsg_class_device *bcd = &q->bsg_dev;
951 949
952 if (!bcd->class_dev) 950 if (!bcd->class_dev)
953 return; 951 return;
954 952
955 mutex_lock(&bsg_mutex); 953 mutex_lock(&bsg_mutex);
956 sysfs_remove_link(&bcd->disk->queue->kobj, "bsg"); 954 sysfs_remove_link(&q->kobj, "bsg");
957 class_device_destroy(bsg_class, MKDEV(BSG_MAJOR, bcd->minor)); 955 class_device_destroy(bsg_class, MKDEV(BSG_MAJOR, bcd->minor));
958 bcd->class_dev = NULL; 956 bcd->class_dev = NULL;
959 list_del_init(&bcd->list); 957 list_del_init(&bcd->list);
960 mutex_unlock(&bsg_mutex); 958 mutex_unlock(&bsg_mutex);
961} 959}
962 960
963int bsg_register_disk(struct gendisk *disk) 961int bsg_register_queue(struct request_queue *q, char *name)
964{ 962{
965 request_queue_t *q = disk->queue;
966 struct bsg_class_device *bcd; 963 struct bsg_class_device *bcd;
967 dev_t dev; 964 dev_t dev;
968 965
@@ -972,7 +969,7 @@ int bsg_register_disk(struct gendisk *disk)
972 if (!q->request_fn) 969 if (!q->request_fn)
973 return 0; 970 return 0;
974 971
975 bcd = &disk->bsg_dev; 972 bcd = &q->bsg_dev;
976 memset(bcd, 0, sizeof(*bcd)); 973 memset(bcd, 0, sizeof(*bcd));
977 INIT_LIST_HEAD(&bcd->list); 974 INIT_LIST_HEAD(&bcd->list);
978 975
@@ -980,8 +977,8 @@ int bsg_register_disk(struct gendisk *disk)
980 dev = MKDEV(BSG_MAJOR, bsg_device_nr); 977 dev = MKDEV(BSG_MAJOR, bsg_device_nr);
981 bcd->minor = bsg_device_nr; 978 bcd->minor = bsg_device_nr;
982 bsg_device_nr++; 979 bsg_device_nr++;
983 bcd->disk = disk; 980 bcd->queue = q;
984 bcd->class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", disk->disk_name); 981 bcd->class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", name);
985 if (!bcd->class_dev) 982 if (!bcd->class_dev)
986 goto err; 983 goto err;
987 list_add_tail(&bcd->list, &bsg_class_list); 984 list_add_tail(&bcd->list, &bsg_class_list);
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 3795e0708a22..74a5498c29a1 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -4091,7 +4091,7 @@ int blk_register_queue(struct gendisk *disk)
4091 return ret; 4091 return ret;
4092 } 4092 }
4093 4093
4094 ret = bsg_register_disk(disk); 4094 ret = bsg_register_queue(q, disk->disk_name);
4095 if (ret) { 4095 if (ret) {
4096 elv_unregister_queue(q); 4096 elv_unregister_queue(q);
4097 kobject_unregister(&q->kobj); 4097 kobject_unregister(&q->kobj);
@@ -4106,7 +4106,7 @@ void blk_unregister_queue(struct gendisk *disk)
4106 request_queue_t *q = disk->queue; 4106 request_queue_t *q = disk->queue;
4107 4107
4108 if (q && q->request_fn) { 4108 if (q && q->request_fn) {
4109 bsg_unregister_disk(disk); 4109 bsg_unregister_queue(q);
4110 elv_unregister_queue(q); 4110 elv_unregister_queue(q);
4111 4111
4112 kobject_uevent(&q->kobj, KOBJ_REMOVE); 4112 kobject_uevent(&q->kobj, KOBJ_REMOVE);