mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-24 07:31:41 +00:00
driver core: Introduce device_move(): move a device to a new parent.
Provide a function device_move() to move a device to a new parent device. Add auxilliary functions kobject_move() and sysfs_move_dir(). kobject_move() generates a new uevent of type KOBJ_MOVE, containing the previous path (DEVPATH_OLD) in addition to the usual values. For this, a new interface kobject_uevent_env() is created that allows to add further environmental data to the uevent at the kobject layer. Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> Acked-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
af9e076536
commit
8a82472f86
7 changed files with 228 additions and 4 deletions
|
@ -310,6 +310,56 @@ int kobject_rename(struct kobject * kobj, const char *new_name)
|
|||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* kobject_move - move object to another parent
|
||||
* @kobj: object in question.
|
||||
* @new_parent: object's new parent
|
||||
*/
|
||||
|
||||
int kobject_move(struct kobject *kobj, struct kobject *new_parent)
|
||||
{
|
||||
int error;
|
||||
struct kobject *old_parent;
|
||||
const char *devpath = NULL;
|
||||
char *devpath_string = NULL;
|
||||
char *envp[2];
|
||||
|
||||
kobj = kobject_get(kobj);
|
||||
if (!kobj)
|
||||
return -EINVAL;
|
||||
new_parent = kobject_get(new_parent);
|
||||
if (!new_parent) {
|
||||
error = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
/* old object path */
|
||||
devpath = kobject_get_path(kobj, GFP_KERNEL);
|
||||
if (!devpath) {
|
||||
error = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
|
||||
if (!devpath_string) {
|
||||
error = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
|
||||
envp[0] = devpath_string;
|
||||
envp[1] = NULL;
|
||||
error = sysfs_move_dir(kobj, new_parent);
|
||||
if (error)
|
||||
goto out;
|
||||
old_parent = kobj->parent;
|
||||
kobj->parent = new_parent;
|
||||
kobject_put(old_parent);
|
||||
kobject_uevent_env(kobj, KOBJ_MOVE, envp);
|
||||
out:
|
||||
kobject_put(kobj);
|
||||
kfree(devpath_string);
|
||||
kfree(devpath);
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* kobject_del - unlink kobject from hierarchy.
|
||||
* @kobj: object.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue