aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/node.c')
-rw-r--r--drivers/base/node.c91
1 files changed, 90 insertions, 1 deletions
diff --git a/drivers/base/node.c b/drivers/base/node.c
index cae346ef1b20..88eeed72b5d6 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -12,6 +12,7 @@
12#include <linux/topology.h> 12#include <linux/topology.h>
13#include <linux/nodemask.h> 13#include <linux/nodemask.h>
14#include <linux/cpu.h> 14#include <linux/cpu.h>
15#include <linux/device.h>
15 16
16static struct sysdev_class node_class = { 17static struct sysdev_class node_class = {
17 set_kset_name("node"), 18 set_kset_name("node"),
@@ -232,8 +233,96 @@ void unregister_one_node(int nid)
232 unregister_node(&node_devices[nid]); 233 unregister_node(&node_devices[nid]);
233} 234}
234 235
236/*
237 * node states attributes
238 */
239
240static ssize_t print_nodes_state(enum node_states state, char *buf)
241{
242 int n;
243
244 n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
245 if (n > 0 && PAGE_SIZE > n + 1) {
246 *(buf + n++) = '\n';
247 *(buf + n++) = '\0';
248 }
249 return n;
250}
251
252static ssize_t print_nodes_possible(struct sysdev_class *class, char *buf)
253{
254 return print_nodes_state(N_POSSIBLE, buf);
255}
256
257static ssize_t print_nodes_online(struct sysdev_class *class, char *buf)
258{
259 return print_nodes_state(N_ONLINE, buf);
260}
261
262static ssize_t print_nodes_has_normal_memory(struct sysdev_class *class,
263 char *buf)
264{
265 return print_nodes_state(N_NORMAL_MEMORY, buf);
266}
267
268static ssize_t print_nodes_has_cpu(struct sysdev_class *class, char *buf)
269{
270 return print_nodes_state(N_CPU, buf);
271}
272
273static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL);
274static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL);
275static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory,
276 NULL);
277static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL);
278
279#ifdef CONFIG_HIGHMEM
280static ssize_t print_nodes_has_high_memory(struct sysdev_class *class,
281 char *buf)
282{
283 return print_nodes_state(N_HIGH_MEMORY, buf);
284}
285
286static SYSDEV_CLASS_ATTR(has_high_memory, 0444, print_nodes_has_high_memory,
287 NULL);
288#endif
289
290struct sysdev_class_attribute *node_state_attr[] = {
291 &attr_possible,
292 &attr_online,
293 &attr_has_normal_memory,
294#ifdef CONFIG_HIGHMEM
295 &attr_has_high_memory,
296#endif
297 &attr_has_cpu,
298};
299
300static int node_states_init(void)
301{
302 int i;
303 int err = 0;
304
305 for (i = 0; i < NR_NODE_STATES; i++) {
306 int ret;
307 ret = sysdev_class_create_file(&node_class, node_state_attr[i]);
308 if (!err)
309 err = ret;
310 }
311 return err;
312}
313
235static int __init register_node_type(void) 314static int __init register_node_type(void)
236{ 315{
237 return sysdev_class_register(&node_class); 316 int ret;
317
318 ret = sysdev_class_register(&node_class);
319 if (!ret)
320 ret = node_states_init();
321
322 /*
323 * Note: we're not going to unregister the node class if we fail
324 * to register the node state class attribute files.
325 */
326 return ret;
238} 327}
239postcore_initcall(register_node_type); 328postcore_initcall(register_node_type);