[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 <tomof@acm.org>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

authored by James Bottomley and committed by James Bottomley 39dca558 0e78d158

+38 -21
+17 -4
block/bsg.c
··· 936 936 937 937 mutex_lock(&bsg_mutex); 938 938 sysfs_remove_link(&q->kobj, "bsg"); 939 - class_device_destroy(bsg_class, MKDEV(bsg_major, bcd->minor)); 939 + class_device_unregister(bcd->class_dev); 940 + put_device(bcd->dev); 940 941 bcd->class_dev = NULL; 942 + bcd->dev = NULL; 941 943 list_del_init(&bcd->list); 942 944 bsg_device_nr--; 943 945 mutex_unlock(&bsg_mutex); 944 946 } 945 947 EXPORT_SYMBOL_GPL(bsg_unregister_queue); 946 948 947 - int bsg_register_queue(struct request_queue *q, const char *name) 949 + int bsg_register_queue(struct request_queue *q, struct device *gdev, 950 + const char *name) 948 951 { 949 952 struct bsg_class_device *bcd, *__bcd; 950 953 dev_t dev; 951 954 int ret = -EMFILE; 952 955 struct class_device *class_dev = NULL; 956 + const char *devname; 957 + 958 + if (name) 959 + devname = name; 960 + else 961 + devname = gdev->bus_id; 953 962 954 963 /* 955 964 * we need a proper transport to send commands, not a stacked device ··· 991 982 bsg_minor_idx = 0; 992 983 993 984 bcd->queue = q; 985 + bcd->dev = get_device(gdev); 994 986 dev = MKDEV(bsg_major, bcd->minor); 995 - class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", name); 987 + class_dev = class_device_create(bsg_class, NULL, dev, gdev, "%s", 988 + devname); 996 989 if (IS_ERR(class_dev)) { 997 990 ret = PTR_ERR(class_dev); 998 - goto err; 991 + goto err_put; 999 992 } 1000 993 bcd->class_dev = class_dev; 1001 994 ··· 1015 1004 1016 1005 err_unregister: 1017 1006 class_device_unregister(class_dev); 1007 + err_put: 1008 + put_device(gdev); 1018 1009 err: 1019 1010 mutex_unlock(&bsg_mutex); 1020 1011 return ret;
+1 -1
drivers/scsi/scsi_sysfs.c
··· 736 736 * released by the sdev_class .release */ 737 737 get_device(&sdev->sdev_gendev); 738 738 739 - error = bsg_register_queue(rq, sdev->sdev_gendev.bus_id); 739 + error = bsg_register_queue(rq, &sdev->sdev_gendev, NULL); 740 740 741 741 if (error) 742 742 sdev_printk(KERN_INFO, sdev,
+18 -14
drivers/scsi/scsi_transport_sas.c
··· 191 191 sas_smp_request(q, rphy_to_shost(rphy), rphy); 192 192 } 193 193 194 - static int sas_bsg_initialize(struct Scsi_Host *shost, struct sas_rphy *rphy, 195 - char *name) 194 + static int sas_bsg_initialize(struct Scsi_Host *shost, struct sas_rphy *rphy) 196 195 { 197 196 struct request_queue *q; 198 197 int error; 198 + struct device *dev; 199 + char namebuf[BUS_ID_SIZE]; 200 + const char *name; 199 201 200 202 if (!to_sas_internal(shost->transportt)->f->smp_handler) { 201 203 printk("%s can't handle SMP requests\n", shost->hostt->name); 202 204 return 0; 203 205 } 204 206 205 - if (rphy) 207 + if (rphy) { 206 208 q = blk_init_queue(sas_non_host_smp_request, NULL); 207 - else 209 + dev = &rphy->dev; 210 + name = dev->bus_id; 211 + } else { 208 212 q = blk_init_queue(sas_host_smp_request, NULL); 213 + dev = &shost->shost_gendev; 214 + snprintf(namebuf, sizeof(namebuf), 215 + "sas_host%d", shost->host_no); 216 + name = namebuf; 217 + } 209 218 if (!q) 210 219 return -ENOMEM; 211 220 212 - error = bsg_register_queue(q, name); 221 + error = bsg_register_queue(q, dev, name); 213 222 if (error) { 214 223 blk_cleanup_queue(q); 215 224 return -ENOMEM; ··· 264 255 { 265 256 struct Scsi_Host *shost = dev_to_shost(dev); 266 257 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); 267 - char name[BUS_ID_SIZE]; 268 258 269 259 INIT_LIST_HEAD(&sas_host->rphy_list); 270 260 mutex_init(&sas_host->lock); ··· 271 263 sas_host->next_expander_id = 0; 272 264 sas_host->next_port_id = 0; 273 265 274 - snprintf(name, sizeof(name), "sas_host%d", shost->host_no); 275 - if (sas_bsg_initialize(shost, NULL, name)) 266 + if (sas_bsg_initialize(shost, NULL)) 276 267 dev_printk(KERN_ERR, dev, "fail to a bsg device %d\n", 277 268 shost->host_no); 278 269 ··· 1339 1332 sas_rphy_initialize(&rdev->rphy); 1340 1333 transport_setup_device(&rdev->rphy.dev); 1341 1334 1342 - if (sas_bsg_initialize(shost, &rdev->rphy, rdev->rphy.dev.bus_id)) 1343 - printk("fail to a bsg device %s\n", rdev->rphy.dev.bus_id); 1344 - 1345 1335 return &rdev->rphy; 1346 1336 } 1347 1337 EXPORT_SYMBOL(sas_end_device_alloc); ··· 1378 1374 sas_rphy_initialize(&rdev->rphy); 1379 1375 transport_setup_device(&rdev->rphy.dev); 1380 1376 1381 - if (sas_bsg_initialize(shost, &rdev->rphy, rdev->rphy.dev.bus_id)) 1382 - printk("fail to a bsg device %s\n", rdev->rphy.dev.bus_id); 1383 - 1384 1377 return &rdev->rphy; 1385 1378 } 1386 1379 EXPORT_SYMBOL(sas_expander_alloc); ··· 1405 1404 return error; 1406 1405 transport_add_device(&rphy->dev); 1407 1406 transport_configure_device(&rphy->dev); 1407 + if (sas_bsg_initialize(shost, rphy)) 1408 + printk("fail to a bsg device %s\n", rphy->dev.bus_id); 1409 + 1408 1410 1409 1411 mutex_lock(&sas_host->lock); 1410 1412 list_add_tail(&rphy->list, &sas_host->rphy_list);
+2 -2
include/linux/bsg.h
··· 57 57 struct request_queue *queue; 58 58 }; 59 59 60 - extern int bsg_register_queue(struct request_queue *, const char *); 60 + extern int bsg_register_queue(struct request_queue *, struct device *, const char *); 61 61 extern void bsg_unregister_queue(struct request_queue *); 62 62 #else 63 - #define bsg_register_queue(disk, name) (0) 63 + #define bsg_register_queue(disk, dev, name) (0) 64 64 #define bsg_unregister_queue(disk) do { } while (0) 65 65 #endif 66 66