diff options
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/node.c | 65 |
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 | ||
547 | static ssize_t print_nodes_possible(struct sysdev_class *class, | 547 | struct 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 | |||
553 | static 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 | |||
560 | static 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 | |||
567 | static 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 | |||
574 | static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL); | ||
575 | static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL); | ||
576 | static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory, | ||
577 | NULL); | ||
578 | static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL); | ||
579 | 551 | ||
580 | #ifdef CONFIG_HIGHMEM | 552 | static ssize_t show_node_state(struct sysdev_class *class, |
581 | static 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 | ||
588 | static 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 | ||
592 | struct sysdev_class_attribute *node_state_attr[] = { | 562 | static 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 | ||
602 | static int node_states_init(void) | 572 | static 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 | } |