summaryrefslogtreecommitdiffstats
path: root/drivers/base/attribute_container.c
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@steeleye.com>2005-08-14 17:09:01 -0500
committerJames Bottomley <jejb@mulgrave.(none)>2005-08-14 17:21:27 -0500
commitd0a7e574007fd547d72ec693bfa35778623d0738 (patch)
tree3457bdf4e8eaf870971aab03c99c31534ba85658 /drivers/base/attribute_container.c
parent10c1b88987d618f4f89c10e11e574c76de73b5e7 (diff)
downloadop-kernel-dev-d0a7e574007fd547d72ec693bfa35778623d0738.zip
op-kernel-dev-d0a7e574007fd547d72ec693bfa35778623d0738.tar.gz
[SCSI] correct transport class abstraction to work outside SCSI
I recently tried to construct a totally generic transport class and found there were certain features missing from the current abstract transport class. Most notable is that you have to hang the data on the class_device but most of the API is framed in terms of the generic device, not the class_device. These changes are two fold - Provide the class_device to all of the setup and configure APIs - Provide and extra API to take the device and the attribute class and return the corresponding class_device Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/base/attribute_container.c')
-rw-r--r--drivers/base/attribute_container.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index ec615d8..62c093d 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -58,6 +58,7 @@ attribute_container_register(struct attribute_container *cont)
{
INIT_LIST_HEAD(&cont->node);
INIT_LIST_HEAD(&cont->containers);
+ spin_lock_init(&cont->containers_lock);
down(&attribute_container_mutex);
list_add_tail(&cont->node, &attribute_container_list);
@@ -77,11 +78,13 @@ attribute_container_unregister(struct attribute_container *cont)
{
int retval = -EBUSY;
down(&attribute_container_mutex);
+ spin_lock(&cont->containers_lock);
if (!list_empty(&cont->containers))
goto out;
retval = 0;
list_del(&cont->node);
out:
+ spin_unlock(&cont->containers_lock);
up(&attribute_container_mutex);
return retval;
@@ -151,7 +154,9 @@ attribute_container_add_device(struct device *dev,
fn(cont, dev, &ic->classdev);
else
attribute_container_add_class_device(&ic->classdev);
+ spin_lock(&cont->containers_lock);
list_add_tail(&ic->node, &cont->containers);
+ spin_unlock(&cont->containers_lock);
}
up(&attribute_container_mutex);
}
@@ -189,6 +194,7 @@ attribute_container_remove_device(struct device *dev,
if (!cont->match(cont, dev))
continue;
+ spin_lock(&cont->containers_lock);
list_for_each_entry_safe(ic, tmp, &cont->containers, node) {
if (dev != ic->classdev.dev)
continue;
@@ -200,6 +206,7 @@ attribute_container_remove_device(struct device *dev,
class_device_unregister(&ic->classdev);
}
}
+ spin_unlock(&cont->containers_lock);
}
up(&attribute_container_mutex);
}
@@ -230,10 +237,12 @@ attribute_container_device_trigger(struct device *dev,
if (!cont->match(cont, dev))
continue;
+ spin_lock(&cont->containers_lock);
list_for_each_entry_safe(ic, tmp, &cont->containers, node) {
if (dev == ic->classdev.dev)
fn(cont, dev, &ic->classdev);
}
+ spin_unlock(&cont->containers_lock);
}
up(&attribute_container_mutex);
}
@@ -368,6 +377,35 @@ attribute_container_class_device_del(struct class_device *classdev)
}
EXPORT_SYMBOL_GPL(attribute_container_class_device_del);
+/**
+ * attribute_container_find_class_device - find the corresponding class_device
+ *
+ * @cont: the container
+ * @dev: the generic device
+ *
+ * Looks up the device in the container's list of class devices and returns
+ * the corresponding class_device.
+ */
+struct class_device *
+attribute_container_find_class_device(struct attribute_container *cont,
+ struct device *dev)
+{
+ struct class_device *cdev = NULL;
+ struct internal_container *ic;
+
+ spin_lock(&cont->containers_lock);
+ list_for_each_entry(ic, &cont->containers, node) {
+ if (ic->classdev.dev == dev) {
+ cdev = &ic->classdev;
+ break;
+ }
+ }
+ spin_unlock(&cont->containers_lock);
+
+ return cdev;
+}
+EXPORT_SYMBOL_GPL(attribute_container_find_class_device);
+
int __init
attribute_container_init(void)
{
OpenPOWER on IntegriCloud