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