Skip to content

Commit b0ed433

Browse files
hreineckejejb
authored andcommitted
[SCSI] add scsi_host and scsi_target to scsi_bus
This patch implements scsi_host and scsi_target device types and adds both to the scsi_bus. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
1 parent cb6b7f4 commit b0ed433

4 files changed

Lines changed: 50 additions & 10 deletions

File tree

‎drivers/scsi/hosts.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ static void scsi_host_dev_release(struct device *dev)
284284
kfree(shost);
285285
}
286286

287+
struct device_type scsi_host_type = {
288+
.name = "scsi_host",
289+
.release = scsi_host_dev_release,
290+
};
291+
287292
/**
288293
* scsi_host_alloc - register a scsi host adapter instance.
289294
* @sht: pointer to scsi host template
@@ -383,7 +388,10 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
383388
device_initialize(&shost->shost_gendev);
384389
snprintf(shost->shost_gendev.bus_id, BUS_ID_SIZE, "host%d",
385390
shost->host_no);
386-
shost->shost_gendev.release = scsi_host_dev_release;
391+
#ifndef CONFIG_SYSFS_DEPRECATED
392+
shost->shost_gendev.bus = &scsi_bus_type;
393+
#endif
394+
shost->shost_gendev.type = &scsi_host_type;
387395

388396
device_initialize(&shost->shost_dev);
389397
shost->shost_dev.parent = &shost->shost_gendev;
@@ -496,7 +504,7 @@ void scsi_exit_hosts(void)
496504

497505
int scsi_is_host_device(const struct device *dev)
498506
{
499-
return dev->release == scsi_host_dev_release;
507+
return dev->type == &scsi_host_type;
500508
}
501509
EXPORT_SYMBOL(scsi_is_host_device);
502510

‎drivers/scsi/scsi_proc.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,14 @@ void scsi_proc_host_rm(struct Scsi_Host *shost)
190190
*/
191191
static int proc_print_scsidevice(struct device *dev, void *data)
192192
{
193-
struct scsi_device *sdev = to_scsi_device(dev);
193+
struct scsi_device *sdev;
194194
struct seq_file *s = data;
195195
int i;
196196

197+
if (!scsi_is_sdev_device(dev))
198+
goto out;
199+
200+
sdev = to_scsi_device(dev);
197201
seq_printf(s,
198202
"Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n Vendor: ",
199203
sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
@@ -230,6 +234,7 @@ static int proc_print_scsidevice(struct device *dev, void *data)
230234
else
231235
seq_printf(s, "\n");
232236

237+
out:
233238
return 0;
234239
}
235240

‎drivers/scsi/scsi_scan.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,14 @@ static void scsi_target_dev_release(struct device *dev)
331331
put_device(parent);
332332
}
333333

334+
struct device_type scsi_target_type = {
335+
.name = "scsi_target",
336+
.release = scsi_target_dev_release,
337+
};
338+
334339
int scsi_is_target_device(const struct device *dev)
335340
{
336-
return dev->release == scsi_target_dev_release;
341+
return dev->type == &scsi_target_type;
337342
}
338343
EXPORT_SYMBOL(scsi_is_target_device);
339344

@@ -391,9 +396,12 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
391396
device_initialize(dev);
392397
starget->reap_ref = 1;
393398
dev->parent = get_device(parent);
394-
dev->release = scsi_target_dev_release;
395399
sprintf(dev->bus_id, "target%d:%d:%d",
396400
shost->host_no, channel, id);
401+
#ifndef CONFIG_SYSFS_DEPRECATED
402+
dev->bus = &scsi_bus_type;
403+
#endif
404+
dev->type = &scsi_target_type;
397405
starget->id = id;
398406
starget->channel = channel;
399407
INIT_LIST_HEAD(&starget->siblings);

‎drivers/scsi/scsi_sysfs.c‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "scsi_priv.h"
2222
#include "scsi_logging.h"
2323

24+
static struct device_type scsi_dev_type;
25+
2426
static const struct {
2527
enum scsi_device_state value;
2628
char *name;
@@ -335,7 +337,12 @@ static struct class sdev_class = {
335337
/* all probing is done in the individual ->probe routines */
336338
static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
337339
{
338-
struct scsi_device *sdp = to_scsi_device(dev);
340+
struct scsi_device *sdp;
341+
342+
if (dev->type != &scsi_dev_type)
343+
return 0;
344+
345+
sdp = to_scsi_device(dev);
339346
if (sdp->no_uld_attach)
340347
return 0;
341348
return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0;
@@ -351,10 +358,16 @@ static int scsi_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
351358

352359
static int scsi_bus_suspend(struct device * dev, pm_message_t state)
353360
{
354-
struct device_driver *drv = dev->driver;
355-
struct scsi_device *sdev = to_scsi_device(dev);
361+
struct device_driver *drv;
362+
struct scsi_device *sdev;
356363
int err;
357364

365+
if (dev->type != &scsi_dev_type)
366+
return 0;
367+
368+
drv = dev->driver;
369+
sdev = to_scsi_device(dev);
370+
358371
err = scsi_device_quiesce(sdev);
359372
if (err)
360373
return err;
@@ -370,10 +383,16 @@ static int scsi_bus_suspend(struct device * dev, pm_message_t state)
370383

371384
static int scsi_bus_resume(struct device * dev)
372385
{
373-
struct device_driver *drv = dev->driver;
374-
struct scsi_device *sdev = to_scsi_device(dev);
386+
struct device_driver *drv;
387+
struct scsi_device *sdev;
375388
int err = 0;
376389

390+
if (dev->type != &scsi_dev_type)
391+
return 0;
392+
393+
drv = dev->driver;
394+
sdev = to_scsi_device(dev);
395+
377396
if (drv && drv->resume)
378397
err = drv->resume(dev);
379398

0 commit comments

Comments
 (0)