Skip to content

Commit

Permalink
[SCSI] add scsi_host and scsi_target to scsi_bus
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Hannes Reinecke authored and James Bottomley committed Apr 22, 2008
1 parent cb6b7f4 commit b0ed433
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
12 changes: 10 additions & 2 deletions drivers/scsi/hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ static void scsi_host_dev_release(struct device *dev)
kfree(shost);
}

struct device_type scsi_host_type = {
.name = "scsi_host",
.release = scsi_host_dev_release,
};

/**
* scsi_host_alloc - register a scsi host adapter instance.
* @sht: pointer to scsi host template
Expand Down Expand Up @@ -383,7 +388,10 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
device_initialize(&shost->shost_gendev);
snprintf(shost->shost_gendev.bus_id, BUS_ID_SIZE, "host%d",
shost->host_no);
shost->shost_gendev.release = scsi_host_dev_release;
#ifndef CONFIG_SYSFS_DEPRECATED
shost->shost_gendev.bus = &scsi_bus_type;
#endif
shost->shost_gendev.type = &scsi_host_type;

device_initialize(&shost->shost_dev);
shost->shost_dev.parent = &shost->shost_gendev;
Expand Down Expand Up @@ -496,7 +504,7 @@ void scsi_exit_hosts(void)

int scsi_is_host_device(const struct device *dev)
{
return dev->release == scsi_host_dev_release;
return dev->type == &scsi_host_type;
}
EXPORT_SYMBOL(scsi_is_host_device);

Expand Down
7 changes: 6 additions & 1 deletion drivers/scsi/scsi_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,14 @@ void scsi_proc_host_rm(struct Scsi_Host *shost)
*/
static int proc_print_scsidevice(struct device *dev, void *data)
{
struct scsi_device *sdev = to_scsi_device(dev);
struct scsi_device *sdev;
struct seq_file *s = data;
int i;

if (!scsi_is_sdev_device(dev))
goto out;

sdev = to_scsi_device(dev);
seq_printf(s,
"Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n Vendor: ",
sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
Expand Down Expand Up @@ -230,6 +234,7 @@ static int proc_print_scsidevice(struct device *dev, void *data)
else
seq_printf(s, "\n");

out:
return 0;
}

Expand Down
12 changes: 10 additions & 2 deletions drivers/scsi/scsi_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,14 @@ static void scsi_target_dev_release(struct device *dev)
put_device(parent);
}

struct device_type scsi_target_type = {
.name = "scsi_target",
.release = scsi_target_dev_release,
};

int scsi_is_target_device(const struct device *dev)
{
return dev->release == scsi_target_dev_release;
return dev->type == &scsi_target_type;
}
EXPORT_SYMBOL(scsi_is_target_device);

Expand Down Expand Up @@ -391,9 +396,12 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
device_initialize(dev);
starget->reap_ref = 1;
dev->parent = get_device(parent);
dev->release = scsi_target_dev_release;
sprintf(dev->bus_id, "target%d:%d:%d",
shost->host_no, channel, id);
#ifndef CONFIG_SYSFS_DEPRECATED
dev->bus = &scsi_bus_type;
#endif
dev->type = &scsi_target_type;
starget->id = id;
starget->channel = channel;
INIT_LIST_HEAD(&starget->siblings);
Expand Down
29 changes: 24 additions & 5 deletions drivers/scsi/scsi_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "scsi_priv.h"
#include "scsi_logging.h"

static struct device_type scsi_dev_type;

static const struct {
enum scsi_device_state value;
char *name;
Expand Down Expand Up @@ -335,7 +337,12 @@ static struct class sdev_class = {
/* all probing is done in the individual ->probe routines */
static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
{
struct scsi_device *sdp = to_scsi_device(dev);
struct scsi_device *sdp;

if (dev->type != &scsi_dev_type)
return 0;

sdp = to_scsi_device(dev);
if (sdp->no_uld_attach)
return 0;
return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0;
Expand All @@ -351,10 +358,16 @@ static int scsi_bus_uevent(struct device *dev, struct kobj_uevent_env *env)

static int scsi_bus_suspend(struct device * dev, pm_message_t state)
{
struct device_driver *drv = dev->driver;
struct scsi_device *sdev = to_scsi_device(dev);
struct device_driver *drv;
struct scsi_device *sdev;
int err;

if (dev->type != &scsi_dev_type)
return 0;

drv = dev->driver;
sdev = to_scsi_device(dev);

err = scsi_device_quiesce(sdev);
if (err)
return err;
Expand All @@ -370,10 +383,16 @@ static int scsi_bus_suspend(struct device * dev, pm_message_t state)

static int scsi_bus_resume(struct device * dev)
{
struct device_driver *drv = dev->driver;
struct scsi_device *sdev = to_scsi_device(dev);
struct device_driver *drv;
struct scsi_device *sdev;
int err = 0;

if (dev->type != &scsi_dev_type)
return 0;

drv = dev->driver;
sdev = to_scsi_device(dev);

if (drv && drv->resume)
err = drv->resume(dev);

Expand Down

0 comments on commit b0ed433

Please sign in to comment.