diff options
Diffstat (limited to 'drivers/base/node.c')
-rw-r--r-- | drivers/base/node.c | 81 |
1 files changed, 30 insertions, 51 deletions
diff --git a/drivers/base/node.c b/drivers/base/node.c index 70122791683d..ad43185ec15a 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 | ||
19 | static struct sysdev_class_attribute *node_state_attrs[]; | ||
20 | |||
19 | static struct sysdev_class node_class = { | 21 | static struct sysdev_class node_class = { |
20 | .name = "node", | 22 | .name = "node", |
23 | .attrs = node_state_attrs, | ||
21 | }; | 24 | }; |
22 | 25 | ||
23 | 26 | ||
@@ -544,76 +547,52 @@ static ssize_t print_nodes_state(enum node_states state, char *buf) | |||
544 | return n; | 547 | return n; |
545 | } | 548 | } |
546 | 549 | ||
547 | static ssize_t print_nodes_possible(struct sysdev_class *class, char *buf) | 550 | struct node_attr { |
548 | { | 551 | struct sysdev_class_attribute attr; |
549 | return print_nodes_state(N_POSSIBLE, buf); | 552 | enum node_states state; |
550 | } | 553 | }; |
551 | |||
552 | static ssize_t print_nodes_online(struct sysdev_class *class, char *buf) | ||
553 | { | ||
554 | return print_nodes_state(N_ONLINE, buf); | ||
555 | } | ||
556 | |||
557 | static 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 | 554 | ||
563 | static ssize_t print_nodes_has_cpu(struct sysdev_class *class, char *buf) | 555 | static ssize_t show_node_state(struct sysdev_class *class, |
556 | struct sysdev_class_attribute *attr, char *buf) | ||
564 | { | 557 | { |
565 | return print_nodes_state(N_CPU, buf); | 558 | struct node_attr *na = container_of(attr, struct node_attr, attr); |
559 | return print_nodes_state(na->state, buf); | ||
566 | } | 560 | } |
567 | 561 | ||
568 | static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL); | 562 | #define _NODE_ATTR(name, state) \ |
569 | static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL); | 563 | { _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state } |
570 | static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory, | ||
571 | NULL); | ||
572 | static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL); | ||
573 | 564 | ||
565 | static struct node_attr node_state_attr[] = { | ||
566 | _NODE_ATTR(possible, N_POSSIBLE), | ||
567 | _NODE_ATTR(online, N_ONLINE), | ||
568 | _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY), | ||
569 | _NODE_ATTR(has_cpu, N_CPU), | ||
574 | #ifdef CONFIG_HIGHMEM | 570 | #ifdef CONFIG_HIGHMEM |
575 | static ssize_t print_nodes_has_high_memory(struct sysdev_class *class, | 571 | _NODE_ATTR(has_high_memory, N_HIGH_MEMORY), |
576 | char *buf) | ||
577 | { | ||
578 | return print_nodes_state(N_HIGH_MEMORY, buf); | ||
579 | } | ||
580 | |||
581 | static SYSDEV_CLASS_ATTR(has_high_memory, 0444, print_nodes_has_high_memory, | ||
582 | NULL); | ||
583 | #endif | 572 | #endif |
573 | }; | ||
584 | 574 | ||
585 | struct sysdev_class_attribute *node_state_attr[] = { | 575 | static struct sysdev_class_attribute *node_state_attrs[] = { |
586 | &attr_possible, | 576 | &node_state_attr[0].attr, |
587 | &attr_online, | 577 | &node_state_attr[1].attr, |
588 | &attr_has_normal_memory, | 578 | &node_state_attr[2].attr, |
579 | &node_state_attr[3].attr, | ||
589 | #ifdef CONFIG_HIGHMEM | 580 | #ifdef CONFIG_HIGHMEM |
590 | &attr_has_high_memory, | 581 | &node_state_attr[4].attr, |
591 | #endif | 582 | #endif |
592 | &attr_has_cpu, | 583 | NULL |
593 | }; | 584 | }; |
594 | 585 | ||
595 | static 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 */ | 586 | #define NODE_CALLBACK_PRI 2 /* lower than SLAB */ |
610 | static int __init register_node_type(void) | 587 | static int __init register_node_type(void) |
611 | { | 588 | { |
612 | int ret; | 589 | int ret; |
613 | 590 | ||
591 | BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES); | ||
592 | BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES); | ||
593 | |||
614 | ret = sysdev_class_register(&node_class); | 594 | ret = sysdev_class_register(&node_class); |
615 | if (!ret) { | 595 | if (!ret) { |
616 | ret = node_states_init(); | ||
617 | hotplug_memory_notifier(node_memory_callback, | 596 | hotplug_memory_notifier(node_memory_callback, |
618 | NODE_CALLBACK_PRI); | 597 | NODE_CALLBACK_PRI); |
619 | } | 598 | } |