1 #define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt
3 #include <linux/notifier.h>
6 #include <xen/xenbus.h>
8 #include <asm/xen/hypervisor.h>
11 static void enable_hotplug_cpu(int cpu
)
13 if (!cpu_present(cpu
))
14 xen_arch_register_cpu(cpu
);
16 set_cpu_present(cpu
, true);
19 static void disable_hotplug_cpu(int cpu
)
21 if (cpu_online(cpu
)) {
22 lock_device_hotplug();
23 device_offline(get_cpu_device(cpu
));
24 unlock_device_hotplug();
27 xen_arch_unregister_cpu(cpu
);
29 set_cpu_present(cpu
, false);
32 static int vcpu_online(unsigned int cpu
)
35 char dir
[16], state
[16];
37 sprintf(dir
, "cpu/%u", cpu
);
38 err
= xenbus_scanf(XBT_NIL
, dir
, "availability", "%15s", state
);
40 if (!xen_initial_domain())
41 pr_err("Unable to read cpu state\n");
45 if (strcmp(state
, "online") == 0)
47 else if (strcmp(state
, "offline") == 0)
50 pr_err("unknown state(%s) on CPU%d\n", state
, cpu
);
53 static void vcpu_hotplug(unsigned int cpu
)
55 if (!cpu_possible(cpu
))
58 switch (vcpu_online(cpu
)) {
60 enable_hotplug_cpu(cpu
);
63 disable_hotplug_cpu(cpu
);
70 static void handle_vcpu_hotplug_event(struct xenbus_watch
*watch
,
71 const char *path
, const char *token
)
76 cpustr
= strstr(path
, "cpu/");
78 sscanf(cpustr
, "cpu/%u", &cpu
);
83 static int setup_cpu_watcher(struct notifier_block
*notifier
,
84 unsigned long event
, void *data
)
87 static struct xenbus_watch cpu_watch
= {
89 .callback
= handle_vcpu_hotplug_event
};
91 (void)register_xenbus_watch(&cpu_watch
);
93 for_each_possible_cpu(cpu
) {
94 if (vcpu_online(cpu
) == 0) {
96 set_cpu_present(cpu
, false);
103 static int __init
setup_vcpu_hotplug_event(void)
105 static struct notifier_block xsn_cpu
= {
106 .notifier_call
= setup_cpu_watcher
};
109 if (!xen_pv_domain() && !xen_pvh_domain())
115 register_xenstore_notifier(&xsn_cpu
);
120 arch_initcall(setup_vcpu_hotplug_event
);