aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/node.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2010-04-03 18:49:14 -0400
committerDavid S. Miller <davem@davemloft.net>2010-04-03 18:49:14 -0400
commit87e8b821ed8db3dab03d96cd542e29666bf210aa (patch)
tree0027060473aafbbb125655ba027319c8a1a665fc /drivers/base/node.c
parent33cd9dfa3a13e3d8e41aef225a9f98169816723b (diff)
parent5e11611a5d22252f3f9c169a3c9377eac0c32033 (diff)
Merge branch 'master' of /home/davem/src/GIT/linux-2.6/
Diffstat (limited to 'drivers/base/node.c')
-rw-r--r--drivers/base/node.c88
1 files changed, 35 insertions, 53 deletions
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 70122791683d..93b3ac65c2d4 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -16,8 +16,11 @@
16#include <linux/device.h> 16#include <linux/device.h>
17#include <linux/swap.h> 17#include <linux/swap.h>
18 18
19static struct sysdev_class_attribute *node_state_attrs[];
20
19static struct sysdev_class node_class = { 21static struct sysdev_class node_class = {
20 .name = "node", 22 .name = "node",
23 .attrs = node_state_attrs,
21}; 24};
22 25
23 26
@@ -162,8 +165,11 @@ static ssize_t node_read_distance(struct sys_device * dev,
162 int len = 0; 165 int len = 0;
163 int i; 166 int i;
164 167
165 /* buf currently PAGE_SIZE, need ~4 chars per node */ 168 /*
166 BUILD_BUG_ON(MAX_NUMNODES*4 > PAGE_SIZE/2); 169 * buf is currently PAGE_SIZE in length and each node needs 4 chars
170 * at the most (distance + space or newline).
171 */
172 BUILD_BUG_ON(MAX_NUMNODES * 4 > PAGE_SIZE);
167 173
168 for_each_online_node(i) 174 for_each_online_node(i)
169 len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i)); 175 len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i));
@@ -544,76 +550,52 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
544 return n; 550 return n;
545} 551}
546 552
547static ssize_t print_nodes_possible(struct sysdev_class *class, char *buf) 553struct node_attr {
548{ 554 struct sysdev_class_attribute attr;
549 return print_nodes_state(N_POSSIBLE, buf); 555 enum node_states state;
550} 556};
551
552static ssize_t print_nodes_online(struct sysdev_class *class, char *buf)
553{
554 return print_nodes_state(N_ONLINE, buf);
555}
556
557static ssize_t print_nodes_has_normal_memory(struct sysdev_class *class,
558 char *buf)
559{
560 return print_nodes_state(N_NORMAL_MEMORY, buf);
561}
562 557
563static ssize_t print_nodes_has_cpu(struct sysdev_class *class, char *buf) 558static ssize_t show_node_state(struct sysdev_class *class,
559 struct sysdev_class_attribute *attr, char *buf)
564{ 560{
565 return print_nodes_state(N_CPU, buf); 561 struct node_attr *na = container_of(attr, struct node_attr, attr);
562 return print_nodes_state(na->state, buf);
566} 563}
567 564
568static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL); 565#define _NODE_ATTR(name, state) \
569static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL); 566 { _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state }
570static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory,
571 NULL);
572static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL);
573 567
568static struct node_attr node_state_attr[] = {
569 _NODE_ATTR(possible, N_POSSIBLE),
570 _NODE_ATTR(online, N_ONLINE),
571 _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
572 _NODE_ATTR(has_cpu, N_CPU),
574#ifdef CONFIG_HIGHMEM 573#ifdef CONFIG_HIGHMEM
575static ssize_t print_nodes_has_high_memory(struct sysdev_class *class, 574 _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
576 char *buf)
577{
578 return print_nodes_state(N_HIGH_MEMORY, buf);
579}
580
581static SYSDEV_CLASS_ATTR(has_high_memory, 0444, print_nodes_has_high_memory,
582 NULL);
583#endif 575#endif
576};
584 577
585struct sysdev_class_attribute *node_state_attr[] = { 578static struct sysdev_class_attribute *node_state_attrs[] = {
586 &attr_possible, 579 &node_state_attr[0].attr,
587 &attr_online, 580 &node_state_attr[1].attr,
588 &attr_has_normal_memory, 581 &node_state_attr[2].attr,
582 &node_state_attr[3].attr,
589#ifdef CONFIG_HIGHMEM 583#ifdef CONFIG_HIGHMEM
590 &attr_has_high_memory, 584 &node_state_attr[4].attr,
591#endif 585#endif
592 &attr_has_cpu, 586 NULL
593}; 587};
594 588
595static int node_states_init(void)
596{
597 int i;
598 int err = 0;
599
600 for (i = 0; i < NR_NODE_STATES; i++) {
601 int ret;
602 ret = sysdev_class_create_file(&node_class, node_state_attr[i]);
603 if (!err)
604 err = ret;
605 }
606 return err;
607}
608
609#define NODE_CALLBACK_PRI 2 /* lower than SLAB */ 589#define NODE_CALLBACK_PRI 2 /* lower than SLAB */
610static int __init register_node_type(void) 590static int __init register_node_type(void)
611{ 591{
612 int ret; 592 int ret;
613 593
594 BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
595 BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES);
596
614 ret = sysdev_class_register(&node_class); 597 ret = sysdev_class_register(&node_class);
615 if (!ret) { 598 if (!ret) {
616 ret = node_states_init();
617 hotplug_memory_notifier(node_memory_callback, 599 hotplug_memory_notifier(node_memory_callback,
618 NODE_CALLBACK_PRI); 600 NODE_CALLBACK_PRI);
619 } 601 }