aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kobject.c
diff options
context:
space:
mode:
authorCornelia Huck <cornelia.huck@de.ibm.com>2006-11-20 11:07:51 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-12-01 17:52:01 -0500
commit8a82472f86bf693b8e91ed56c9ca4f62fbbdcfa3 (patch)
tree79d148ee548f4b57e6f5a4a69cf6cdb81e7a1bf2 /lib/kobject.c
parentaf9e0765362151b27372c14d9d6dc417184182d3 (diff)
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>
Diffstat (limited to 'lib/kobject.c')
-rw-r--r--lib/kobject.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index 7dd5c0e9d996..744a4b102c7f 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -311,6 +311,56 @@ int kobject_rename(struct kobject * kobj, const char *new_name)
311} 311}
312 312
313/** 313/**
314 * kobject_move - move object to another parent
315 * @kobj: object in question.
316 * @new_parent: object's new parent
317 */
318
319int kobject_move(struct kobject *kobj, struct kobject *new_parent)
320{
321 int error;
322 struct kobject *old_parent;
323 const char *devpath = NULL;
324 char *devpath_string = NULL;
325 char *envp[2];
326
327 kobj = kobject_get(kobj);
328 if (!kobj)
329 return -EINVAL;
330 new_parent = kobject_get(new_parent);
331 if (!new_parent) {
332 error = -EINVAL;
333 goto out;
334 }
335 /* old object path */
336 devpath = kobject_get_path(kobj, GFP_KERNEL);
337 if (!devpath) {
338 error = -ENOMEM;
339 goto out;
340 }
341 devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
342 if (!devpath_string) {
343 error = -ENOMEM;
344 goto out;
345 }
346 sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
347 envp[0] = devpath_string;
348 envp[1] = NULL;
349 error = sysfs_move_dir(kobj, new_parent);
350 if (error)
351 goto out;
352 old_parent = kobj->parent;
353 kobj->parent = new_parent;
354 kobject_put(old_parent);
355 kobject_uevent_env(kobj, KOBJ_MOVE, envp);
356out:
357 kobject_put(kobj);
358 kfree(devpath_string);
359 kfree(devpath);
360 return error;
361}
362
363/**
314 * kobject_del - unlink kobject from hierarchy. 364 * kobject_del - unlink kobject from hierarchy.
315 * @kobj: object. 365 * @kobj: object.
316 */ 366 */