/** * enclosure_find - find an enclosure given a parent device * @dev: the parent to match against * @start: Optional enclosure device to start from (NULL if none) * * Looks through the list of registered enclosures to find all those * with @dev as a parent. Returns NULL if no enclosure is * found. @start can be used as a starting point to obtain multiple * enclosures per parent (should begin with NULL and then be set to * each returned enclosure device). Obtains a reference to the * enclosure class device which must be released with put_device(). * If @start is not NULL, a reference must be taken on it which is * released before returning (this allows a loop through all * enclosures to exit with only the reference on the enclosure of * interest held). Note that the @dev may correspond to the actual * device housing the enclosure, in which case no iteration via @start * is required.
*/ struct enclosure_device *enclosure_find(struct device *dev, struct enclosure_device *start)
{ struct enclosure_device *edev;
mutex_lock(&container_list_lock);
edev = list_prepare_entry(start, &container_list, node); if (start)
put_device(&start->edev);
list_for_each_entry_continue(edev, &container_list, node) { struct device *parent = edev->edev.parent; /* parent might not be immediate, so iterate up to
* the root of the tree if necessary */ while (parent) { if (parent == dev) {
get_device(&edev->edev);
mutex_unlock(&container_list_lock); return edev;
}
parent = parent->parent;
}
}
mutex_unlock(&container_list_lock);
return NULL;
}
EXPORT_SYMBOL_GPL(enclosure_find);
/** * enclosure_for_each_device - calls a function for each enclosure * @fn: the function to call * @data: the data to pass to each call * * Loops over all the enclosures calling the function. * * Note, this function uses a mutex which will be held across calls to * @fn, so it must have non atomic context, and @fn may (although it * should not) sleep or otherwise cause the mutex to be held for * indefinite periods
*/ int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *), void *data)
{ int error = 0; struct enclosure_device *edev;
/** * enclosure_register - register device as an enclosure * * @dev: device containing the enclosure * @name: chosen device name * @components: number of components in the enclosure * @cb: platform call-backs * * This sets up the device for being an enclosure. Note that @dev does * not have to be a dedicated enclosure device. It may be some other type * of device that additionally responds to enclosure services
*/ struct enclosure_device *
enclosure_register(struct device *dev, constchar *name, int components, struct enclosure_component_callbacks *cb)
{ struct enclosure_device *edev =
kzalloc(struct_size(edev, component, components), GFP_KERNEL); int err, i;
for (i = 0; i < edev->components; i++) if (edev->component[i].number != -1)
device_unregister(&edev->component[i].cdev);
/* prevent any callbacks into service user */
edev->cb = &enclosure_null_callbacks;
device_unregister(&edev->edev);
}
EXPORT_SYMBOL_GPL(enclosure_unregister);
/* * In odd circumstances, like multipath devices, something else may * already have removed the links, so check for this condition first.
*/ if (cdev->dev->kobj.sd)
sysfs_remove_link(&cdev->dev->kobj, name);
if (cdev->cdev.kobj.sd)
sysfs_remove_link(&cdev->cdev.kobj, "device");
}
staticint enclosure_add_links(struct enclosure_component *cdev)
{ int error; char name[ENCLOSURE_NAME_SIZE];
error = sysfs_create_link(&cdev->cdev.kobj, &cdev->dev->kobj, "device"); if (error) return error;
/** * enclosure_component_alloc - prepare a new enclosure component * @edev: the enclosure to add the component * @number: the device number * @type: the type of component being added * @name: an optional name to appear in sysfs (leave NULL if none) * * The name is optional for enclosures that give their components a unique * name. If not, leave the field NULL and a name will be assigned. * * Returns a pointer to the enclosure component or an error.
*/ struct enclosure_component *
enclosure_component_alloc(struct enclosure_device *edev, unsignedint number, enum enclosure_component_type type, constchar *name)
{ struct enclosure_component *ecomp; struct device *cdev; int i; char newname[COMPONENT_NAME_SIZE];
if (number >= edev->components) return ERR_PTR(-EINVAL);
if (name && name[0]) { /* Some hardware (e.g. enclosure in RX300 S6) has components * with non unique names. Registering duplicates in sysfs * will lead to warnings during bootup. So make the names
* unique by appending consecutive numbers -1, -2, ... */
i = 1;
snprintf(newname, COMPONENT_NAME_SIZE, "%s", name); while (enclosure_component_find_by_name(edev, newname))
snprintf(newname, COMPONENT_NAME_SIZE, "%s-%i", name, i++);
dev_set_name(cdev, "%s", newname);
} else
dev_set_name(cdev, "%u", number);
/** * enclosure_add_device - add a device as being part of an enclosure * @edev: the enclosure device being added to. * @component: the number of the component * @dev: the device being added * * Declares a real device to reside in slot (or identifier) @num of an * enclosure. This will cause the relevant sysfs links to appear. * This function may also be used to change a device associated with * an enclosure without having to call enclosure_remove_device() in * between. * * Returns zero on success or an error.
*/ int enclosure_add_device(struct enclosure_device *edev, int component, struct device *dev)
{ struct enclosure_component *cdev; int err;
if (!edev || component >= edev->components) return -EINVAL;
/** * enclosure_remove_device - remove a device from an enclosure * @edev: the enclosure device * @dev: device to remove/put * * Returns zero on success or an error. *
*/ int enclosure_remove_device(struct enclosure_device *edev, struct device *dev)
{ struct enclosure_component *cdev; int i;
if (!edev || !dev) return -EINVAL;
for (i = 0; i < edev->components; i++) {
cdev = &edev->component[i]; if (cdev->dev == dev) {
enclosure_remove_links(cdev);
put_device(dev);
cdev->dev = NULL; return 0;
}
} return -ENODEV;
}
EXPORT_SYMBOL_GPL(enclosure_remove_device);
if (edev->cb->get_power_status)
edev->cb->get_power_status(edev, ecomp);
/* If still uninitialized, the callback failed or does not exist. */ if (ecomp->power_status == -1) return (edev->cb->get_power_status) ? -EIO : -ENOTTY;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.