aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kobject_uevent.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kobject_uevent.c')
-rw-r--r--lib/kobject_uevent.c57
1 files changed, 44 insertions, 13 deletions
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 5ccda460262c..a8efb48dca54 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -23,17 +23,6 @@
23#include <net/sock.h> 23#include <net/sock.h>
24 24
25 25
26/* the strings here must match the enum in include/linux/kobject.h */
27const char *kobject_actions[] = {
28 "add",
29 "remove",
30 "change",
31 "move",
32 "online",
33 "offline",
34};
35
36#if defined(CONFIG_HOTPLUG)
37u64 uevent_seqnum; 26u64 uevent_seqnum;
38char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH; 27char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH;
39static DEFINE_SPINLOCK(sequence_lock); 28static DEFINE_SPINLOCK(sequence_lock);
@@ -41,6 +30,50 @@ static DEFINE_SPINLOCK(sequence_lock);
41static struct sock *uevent_sock; 30static struct sock *uevent_sock;
42#endif 31#endif
43 32
33/* the strings here must match the enum in include/linux/kobject.h */
34static const char *kobject_actions[] = {
35 [KOBJ_ADD] = "add",
36 [KOBJ_REMOVE] = "remove",
37 [KOBJ_CHANGE] = "change",
38 [KOBJ_MOVE] = "move",
39 [KOBJ_ONLINE] = "online",
40 [KOBJ_OFFLINE] = "offline",
41};
42
43/**
44 * kobject_action_type - translate action string to numeric type
45 *
46 * @buf: buffer containing the action string, newline is ignored
47 * @len: length of buffer
48 * @type: pointer to the location to store the action type
49 *
50 * Returns 0 if the action string was recognized.
51 */
52int kobject_action_type(const char *buf, size_t count,
53 enum kobject_action *type)
54{
55 enum kobject_action action;
56 int ret = -EINVAL;
57
58 if (count && buf[count-1] == '\n')
59 count--;
60
61 if (!count)
62 goto out;
63
64 for (action = 0; action < ARRAY_SIZE(kobject_actions); action++) {
65 if (strncmp(kobject_actions[action], buf, count) != 0)
66 continue;
67 if (kobject_actions[action][count] != '\0')
68 continue;
69 *type = action;
70 ret = 0;
71 break;
72 }
73out:
74 return ret;
75}
76
44/** 77/**
45 * kobject_uevent_env - send an uevent with environmental data 78 * kobject_uevent_env - send an uevent with environmental data
46 * 79 *
@@ -270,5 +303,3 @@ static int __init kobject_uevent_init(void)
270 303
271postcore_initcall(kobject_uevent_init); 304postcore_initcall(kobject_uevent_init);
272#endif 305#endif
273
274#endif /* CONFIG_HOTPLUG */