diff options
| author | Linus Torvalds <torvalds@woody.osdl.org> | 2006-12-01 19:41:07 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.osdl.org> | 2006-12-01 19:41:07 -0500 |
| commit | 4549df891a31b9a05b7d183106c09049b79327be (patch) | |
| tree | d4dfd0921f0dd0dba2525fd33c0962b26ba5ff1e /lib | |
| parent | 6b8cc71ab2619a776b02869fd733ac1ead3db4e8 (diff) | |
| parent | e17e0f51aeea4e59c7e450a1c0f26605b91c1260 (diff) | |
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6: (36 commits)
Driver core: show drivers in /sys/module/
Documentation/driver-model/platform.txt update/rewrite
Driver core: platform_driver_probe(), can save codespace
driver core: Use klist_remove() in device_move()
driver core: Introduce device_move(): move a device to a new parent.
Driver core: make drivers/base/core.c:setup_parent() static
driver core: Introduce device_find_child().
sysfs: sysfs_write_file() writes zero terminated data
cpu topology: consider sysfs_create_group return value
Driver core: Call platform_notify_remove later
ACPI: Change ACPI to use dev_archdata instead of firmware_data
Driver core: add dev_archdata to struct device
Driver core: convert sound core to use struct device
Driver core: change mem class_devices to be real devices
Driver core: convert fb code to use struct device
Driver core: convert firmware code to use struct device
Driver core: convert mmc code to use struct device
Driver core: convert ppdev code to use struct device
Driver core: convert PPP code to use struct device
Driver core: convert cpuid code to use struct device
...
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/kobject.c | 50 | ||||
| -rw-r--r-- | lib/kobject_uevent.c | 28 |
2 files changed, 74 insertions, 4 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 | |||
| 319 | int 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); | ||
| 356 | out: | ||
| 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 | */ |
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index 7f20e7b857cb..a1922765ff31 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c | |||
| @@ -50,18 +50,22 @@ static char *action_to_string(enum kobject_action action) | |||
| 50 | return "offline"; | 50 | return "offline"; |
| 51 | case KOBJ_ONLINE: | 51 | case KOBJ_ONLINE: |
| 52 | return "online"; | 52 | return "online"; |
| 53 | case KOBJ_MOVE: | ||
| 54 | return "move"; | ||
| 53 | default: | 55 | default: |
| 54 | return NULL; | 56 | return NULL; |
| 55 | } | 57 | } |
| 56 | } | 58 | } |
| 57 | 59 | ||
| 58 | /** | 60 | /** |
| 59 | * kobject_uevent - notify userspace by ending an uevent | 61 | * kobject_uevent_env - send an uevent with environmental data |
| 60 | * | 62 | * |
| 61 | * @action: action that is happening (usually KOBJ_ADD and KOBJ_REMOVE) | 63 | * @action: action that is happening (usually KOBJ_MOVE) |
| 62 | * @kobj: struct kobject that the action is happening to | 64 | * @kobj: struct kobject that the action is happening to |
| 65 | * @envp_ext: pointer to environmental data | ||
| 63 | */ | 66 | */ |
| 64 | void kobject_uevent(struct kobject *kobj, enum kobject_action action) | 67 | void kobject_uevent_env(struct kobject *kobj, enum kobject_action action, |
| 68 | char *envp_ext[]) | ||
| 65 | { | 69 | { |
| 66 | char **envp; | 70 | char **envp; |
| 67 | char *buffer; | 71 | char *buffer; |
| @@ -76,6 +80,7 @@ void kobject_uevent(struct kobject *kobj, enum kobject_action action) | |||
| 76 | char *seq_buff; | 80 | char *seq_buff; |
| 77 | int i = 0; | 81 | int i = 0; |
| 78 | int retval; | 82 | int retval; |
| 83 | int j; | ||
| 79 | 84 | ||
| 80 | pr_debug("%s\n", __FUNCTION__); | 85 | pr_debug("%s\n", __FUNCTION__); |
| 81 | 86 | ||
| @@ -134,7 +139,8 @@ void kobject_uevent(struct kobject *kobj, enum kobject_action action) | |||
| 134 | scratch += sprintf (scratch, "DEVPATH=%s", devpath) + 1; | 139 | scratch += sprintf (scratch, "DEVPATH=%s", devpath) + 1; |
| 135 | envp [i++] = scratch; | 140 | envp [i++] = scratch; |
| 136 | scratch += sprintf(scratch, "SUBSYSTEM=%s", subsystem) + 1; | 141 | scratch += sprintf(scratch, "SUBSYSTEM=%s", subsystem) + 1; |
| 137 | 142 | for (j = 0; envp_ext && envp_ext[j]; j++) | |
| 143 | envp[i++] = envp_ext[j]; | ||
| 138 | /* just reserve the space, overwrite it after kset call has returned */ | 144 | /* just reserve the space, overwrite it after kset call has returned */ |
| 139 | envp[i++] = seq_buff = scratch; | 145 | envp[i++] = seq_buff = scratch; |
| 140 | scratch += strlen("SEQNUM=18446744073709551616") + 1; | 146 | scratch += strlen("SEQNUM=18446744073709551616") + 1; |
| @@ -200,6 +206,20 @@ exit: | |||
| 200 | kfree(envp); | 206 | kfree(envp); |
| 201 | return; | 207 | return; |
| 202 | } | 208 | } |
| 209 | |||
| 210 | EXPORT_SYMBOL_GPL(kobject_uevent_env); | ||
| 211 | |||
| 212 | /** | ||
| 213 | * kobject_uevent - notify userspace by ending an uevent | ||
| 214 | * | ||
| 215 | * @action: action that is happening (usually KOBJ_ADD and KOBJ_REMOVE) | ||
| 216 | * @kobj: struct kobject that the action is happening to | ||
| 217 | */ | ||
| 218 | void kobject_uevent(struct kobject *kobj, enum kobject_action action) | ||
| 219 | { | ||
| 220 | kobject_uevent_env(kobj, action, NULL); | ||
| 221 | } | ||
| 222 | |||
| 203 | EXPORT_SYMBOL_GPL(kobject_uevent); | 223 | EXPORT_SYMBOL_GPL(kobject_uevent); |
| 204 | 224 | ||
| 205 | /** | 225 | /** |
