[SCSI] scsi_transport_sas: add destructor for bsg

There's currently no destructor for the bsg components. If you insert
and remove the module, you see the bsg devices building up and up. This
patch adds the destructor in the correct place in the transport class so
that the bsg and request queue are removed just before the device
destruction.

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 b6aff669 e7cbff13

+37 -1
+35 -1
drivers/scsi/scsi_transport_sas.c
··· 42 42 struct sas_host_attrs { 43 43 struct list_head rphy_list; 44 44 struct mutex lock; 45 + struct request_queue *q; 45 46 u32 next_target_id; 46 47 u32 next_expander_id; 47 48 int next_port_id; ··· 216 215 } 217 216 218 217 if (rphy) 218 + rphy->q = q; 219 + else 220 + to_sas_host_attrs(shost)->q = q; 221 + 222 + if (rphy) 219 223 q->queuedata = rphy; 220 224 else 221 225 q->queuedata = shost; ··· 228 222 set_bit(QUEUE_FLAG_BIDI, &q->queue_flags); 229 223 230 224 return 0; 225 + } 226 + 227 + static void sas_bsg_remove(struct Scsi_Host *shost, struct sas_rphy *rphy) 228 + { 229 + struct request_queue *q; 230 + 231 + if (rphy) 232 + q = rphy->q; 233 + else 234 + q = to_sas_host_attrs(shost)->q; 235 + 236 + if (!q) 237 + return; 238 + 239 + bsg_unregister_queue(q); 240 + blk_cleanup_queue(q); 231 241 } 232 242 233 243 /* ··· 271 249 return 0; 272 250 } 273 251 252 + static int sas_host_remove(struct transport_container *tc, struct device *dev, 253 + struct class_device *cdev) 254 + { 255 + struct Scsi_Host *shost = dev_to_shost(dev); 256 + 257 + sas_bsg_remove(shost, NULL); 258 + 259 + return 0; 260 + } 261 + 274 262 static DECLARE_TRANSPORT_CLASS(sas_host_class, 275 - "sas_host", sas_host_setup, NULL, NULL); 263 + "sas_host", sas_host_setup, sas_host_remove, NULL); 276 264 277 265 static int sas_host_match(struct attribute_container *cont, 278 266 struct device *dev) ··· 1445 1413 mutex_lock(&sas_host->lock); 1446 1414 list_del(&rphy->list); 1447 1415 mutex_unlock(&sas_host->lock); 1416 + 1417 + sas_bsg_remove(shost, rphy); 1448 1418 1449 1419 transport_destroy_device(dev); 1450 1420
+2
include/scsi/scsi_transport_sas.h
··· 91 91 #define phy_to_shost(phy) \ 92 92 dev_to_shost((phy)->dev.parent) 93 93 94 + struct request_queue; 94 95 struct sas_rphy { 95 96 struct device dev; 96 97 struct sas_identify identify; 97 98 struct list_head list; 99 + struct request_queue *q; 98 100 u32 scsi_target_id; 99 101 }; 100 102