Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 106578
b: refs/heads/master
c: 4c05ae5
h: refs/heads/master
v: v3
  • Loading branch information
Hannes Reinecke authored and James Bottomley committed Jul 26, 2008
1 parent 9f05962 commit 7d76af3
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 765cbc6dad16b87724803e359d6be792ddf08614
refs/heads/master: 4c05ae52fcb0e27a2ee4a16d1f31f8c547fd4886
103 changes: 102 additions & 1 deletion trunk/drivers/scsi/device_handler/scsi_dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,
* @scsi_dh - Device handler to be detached
*
* Detach from a device handler. If a device handler is specified,
* only detach if the currently attached handler is equal to it.
* only detach if the currently attached handler matches @scsi_dh.
*/
static void scsi_dh_handler_detach(struct scsi_device *sdev,
struct scsi_device_handler *scsi_dh)
Expand All @@ -102,6 +102,98 @@ static void scsi_dh_handler_detach(struct scsi_device *sdev,
scsi_dh->detach(sdev);
}

/*
* Functions for sysfs attribute 'dh_state'
*/
static ssize_t
store_dh_state(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct scsi_device *sdev = to_scsi_device(dev);
struct scsi_device_handler *scsi_dh;
int err = -EINVAL;

if (!sdev->scsi_dh_data) {
/*
* Attach to a device handler
*/
if (!(scsi_dh = get_device_handler(buf)))
return err;
err = scsi_dh_handler_attach(sdev, scsi_dh);
} else {
scsi_dh = sdev->scsi_dh_data->scsi_dh;
if (!strncmp(buf, "detach", 6)) {
/*
* Detach from a device handler
*/
scsi_dh_handler_detach(sdev, scsi_dh);
err = 0;
} else if (!strncmp(buf, "activate", 8)) {
/*
* Activate a device handler
*/
if (scsi_dh->activate)
err = scsi_dh->activate(sdev);
else
err = 0;
}
}

return err<0?err:count;
}

static ssize_t
show_dh_state(struct device *dev, struct device_attribute *attr, char *buf)
{
struct scsi_device *sdev = to_scsi_device(dev);

if (!sdev->scsi_dh_data)
return snprintf(buf, 20, "detached\n");

return snprintf(buf, 20, "%s\n", sdev->scsi_dh_data->scsi_dh->name);
}

static struct device_attribute scsi_dh_state_attr =
__ATTR(dh_state, S_IRUGO | S_IWUSR, show_dh_state,
store_dh_state);

/*
* scsi_dh_sysfs_attr_add - Callback for scsi_init_dh
*/
static int scsi_dh_sysfs_attr_add(struct device *dev, void *data)
{
struct scsi_device *sdev;
int err;

if (!scsi_is_sdev_device(dev))
return 0;

sdev = to_scsi_device(dev);

err = device_create_file(&sdev->sdev_gendev,
&scsi_dh_state_attr);

return 0;
}

/*
* scsi_dh_sysfs_attr_remove - Callback for scsi_exit_dh
*/
static int scsi_dh_sysfs_attr_remove(struct device *dev, void *data)
{
struct scsi_device *sdev;

if (!scsi_is_sdev_device(dev))
return 0;

sdev = to_scsi_device(dev);

device_remove_file(&sdev->sdev_gendev,
&scsi_dh_state_attr);

return 0;
}

/*
* scsi_dh_notifier - notifier chain callback
*/
Expand Down Expand Up @@ -132,7 +224,10 @@ static int scsi_dh_notifier(struct notifier_block *nb,

if (action == BUS_NOTIFY_ADD_DEVICE) {
err = scsi_dh_handler_attach(sdev, devinfo);
if (!err)
err = device_create_file(dev, &scsi_dh_state_attr);
} else if (action == BUS_NOTIFY_DEL_DEVICE) {
device_remove_file(dev, &scsi_dh_state_attr);
scsi_dh_handler_detach(sdev, NULL);
}
out:
Expand Down Expand Up @@ -284,11 +379,17 @@ static int __init scsi_dh_init(void)

r = bus_register_notifier(&scsi_bus_type, &scsi_dh_nb);

if (!r)
bus_for_each_dev(&scsi_bus_type, NULL, NULL,
scsi_dh_sysfs_attr_add);

return r;
}

static void __exit scsi_dh_exit(void)
{
bus_for_each_dev(&scsi_bus_type, NULL, NULL,
scsi_dh_sysfs_attr_remove);
bus_unregister_notifier(&scsi_bus_type, &scsi_dh_nb);
}

Expand Down

0 comments on commit 7d76af3

Please sign in to comment.