aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/node.c
diff options
context:
space:
mode:
authorAndi Kleen <andi@firstfloor.org>2010-01-05 06:47:59 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2010-03-07 20:04:47 -0500
commitb15f562fc2f5429f27e5dfb0b0ee5ec44f661986 (patch)
tree545b4c0a9a0ea0647a61b80a9461b6f72736e7f1 /drivers/base/node.c
parentc9be0a36f9bf392a7984473124a67a12964df11f (diff)
sysdev: Convert node driver class attributes to be data driven
Using the new attribute argument convert the node driver class attributes to carry the node state. Then use a shared function to do what a lot of individual functions did before. Signed-off-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/node.c')
-rw-r--r--drivers/base/node.c65
1 files changed, 18 insertions, 47 deletions
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 85c9d30d7004..aa8bc4bff4f6 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -544,59 +544,29 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
544 return n; 544 return n;
545} 545}
546 546
547static ssize_t print_nodes_possible(struct sysdev_class *class, 547struct node_attr {
548 struct sysdev_class_attribute *attr, char *buf) 548 struct sysdev_class_attribute attr;
549{ 549 enum node_states state;
550 return print_nodes_state(N_POSSIBLE, buf); 550};
551}
552
553static ssize_t print_nodes_online(struct sysdev_class *class,
554 struct sysdev_class_attribute *attr,
555 char *buf)
556{
557 return print_nodes_state(N_ONLINE, buf);
558}
559
560static ssize_t print_nodes_has_normal_memory(struct sysdev_class *class,
561 struct sysdev_class_attribute *attr,
562 char *buf)
563{
564 return print_nodes_state(N_NORMAL_MEMORY, buf);
565}
566
567static ssize_t print_nodes_has_cpu(struct sysdev_class *class,
568 struct sysdev_class_attribute *attr,
569 char *buf)
570{
571 return print_nodes_state(N_CPU, buf);
572}
573
574static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL);
575static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL);
576static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory,
577 NULL);
578static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL);
579 551
580#ifdef CONFIG_HIGHMEM 552static ssize_t show_node_state(struct sysdev_class *class,
581static ssize_t print_nodes_has_high_memory(struct sysdev_class *class, 553 struct sysdev_class_attribute *attr, char *buf)
582 struct sysdev_class_attribute *attr,
583 char *buf)
584{ 554{
585 return print_nodes_state(N_HIGH_MEMORY, buf); 555 struct node_attr *na = container_of(attr, struct node_attr, attr);
556 return print_nodes_state(na->state, buf);
586} 557}
587 558
588static SYSDEV_CLASS_ATTR(has_high_memory, 0444, print_nodes_has_high_memory, 559#define _NODE_ATTR(name, state) \
589 NULL); 560 { _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state }
590#endif
591 561
592struct sysdev_class_attribute *node_state_attr[] = { 562static struct node_attr node_state_attr[] = {
593 &attr_possible, 563 _NODE_ATTR(possible, N_POSSIBLE),
594 &attr_online, 564 _NODE_ATTR(online, N_ONLINE),
595 &attr_has_normal_memory, 565 _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
566 _NODE_ATTR(has_cpu, N_CPU),
596#ifdef CONFIG_HIGHMEM 567#ifdef CONFIG_HIGHMEM
597 &attr_has_high_memory, 568 _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
598#endif 569#endif
599 &attr_has_cpu,
600}; 570};
601 571
602static int node_states_init(void) 572static int node_states_init(void)
@@ -604,9 +574,10 @@ static int node_states_init(void)
604 int i; 574 int i;
605 int err = 0; 575 int err = 0;
606 576
577 BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
607 for (i = 0; i < NR_NODE_STATES; i++) { 578 for (i = 0; i < NR_NODE_STATES; i++) {
608 int ret; 579 int ret;
609 ret = sysdev_class_create_file(&node_class, node_state_attr[i]); 580 ret = sysdev_class_create_file(&node_class, &node_state_attr[i].attr);
610 if (!err) 581 if (!err)
611 err = ret; 582 err = ret;
612 } 583 }