From 39dca558a5b52b63e49bc234a7e887be092aa690 Mon Sep 17 00:00:00 2001 From: James Bottomley Date: Fri, 20 Jul 2007 18:22:17 -0500 Subject: [SCSI] bsg: make class backlinks Currently, bsg doesn't make class backlinks (a process whereby you'd get a link to bsg in the device directory in the same way you get one for sg). This is because the bsg device is uninitialised, so the class device has nothing it can attach to. The fix is to make the bsg device point to the cdevice of the entity creating the bsg, necessitating changing the bsg_register_queue() prototype into a form that takes the generic device. Acked-by: FUJITA Tomonori Signed-off-by: James Bottomley --- block/bsg.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'block') diff --git a/block/bsg.c b/block/bsg.c index 0e3d5d490d2..4eebcd5c731 100644 --- a/block/bsg.c +++ b/block/bsg.c @@ -936,20 +936,29 @@ void bsg_unregister_queue(struct request_queue *q) mutex_lock(&bsg_mutex); sysfs_remove_link(&q->kobj, "bsg"); - class_device_destroy(bsg_class, MKDEV(bsg_major, bcd->minor)); + class_device_unregister(bcd->class_dev); + put_device(bcd->dev); bcd->class_dev = NULL; + bcd->dev = NULL; list_del_init(&bcd->list); bsg_device_nr--; mutex_unlock(&bsg_mutex); } EXPORT_SYMBOL_GPL(bsg_unregister_queue); -int bsg_register_queue(struct request_queue *q, const char *name) +int bsg_register_queue(struct request_queue *q, struct device *gdev, + const char *name) { struct bsg_class_device *bcd, *__bcd; dev_t dev; int ret = -EMFILE; struct class_device *class_dev = NULL; + const char *devname; + + if (name) + devname = name; + else + devname = gdev->bus_id; /* * we need a proper transport to send commands, not a stacked device @@ -982,11 +991,13 @@ retry: bsg_minor_idx = 0; bcd->queue = q; + bcd->dev = get_device(gdev); dev = MKDEV(bsg_major, bcd->minor); - class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", name); + class_dev = class_device_create(bsg_class, NULL, dev, gdev, "%s", + devname); if (IS_ERR(class_dev)) { ret = PTR_ERR(class_dev); - goto err; + goto err_put; } bcd->class_dev = class_dev; @@ -1004,6 +1015,8 @@ retry: err_unregister: class_device_unregister(class_dev); +err_put: + put_device(gdev); err: mutex_unlock(&bsg_mutex); return ret; -- cgit v1.2.3