mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: linux-kernel@vger.kernel.org, greg@kroah.com
Subject: [PATCH] [2/12] SYSFS: Convert node driver class attributes to be data driven
Date: Tue,  5 Jan 2010 12:47:59 +0100 (CET)	[thread overview]
Message-ID: <20100105114759.7A2EEB17C2@basil.firstfloor.org> (raw)
In-Reply-To: <201001051247.104464547@firstfloor.org>


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>

---
 drivers/base/node.c |   65 ++++++++++++++--------------------------------------
 1 file changed, 18 insertions(+), 47 deletions(-)

Index: linux-2.6.33-rc2-ak/drivers/base/node.c
===================================================================
--- linux-2.6.33-rc2-ak.orig/drivers/base/node.c
+++ linux-2.6.33-rc2-ak/drivers/base/node.c
@@ -544,59 +544,29 @@ static ssize_t print_nodes_state(enum no
 	return n;
 }
 
-static ssize_t print_nodes_possible(struct sysdev_class *class,
-				    struct sysdev_class_attribute *attr, char *buf)
-{
-	return print_nodes_state(N_POSSIBLE, buf);
-}
-
-static ssize_t print_nodes_online(struct sysdev_class *class,
-				  struct sysdev_class_attribute *attr,
-				  char *buf)
-{
-	return print_nodes_state(N_ONLINE, buf);
-}
-
-static ssize_t print_nodes_has_normal_memory(struct sysdev_class *class,
-					     struct sysdev_class_attribute *attr,
-					     char *buf)
-{
-	return print_nodes_state(N_NORMAL_MEMORY, buf);
-}
-
-static ssize_t print_nodes_has_cpu(struct sysdev_class *class,
-				   struct sysdev_class_attribute *attr,
-				   char *buf)
-{
-	return print_nodes_state(N_CPU, buf);
-}
-
-static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL);
-static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL);
-static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory,
-									NULL);
-static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL);
+struct node_attr {
+	struct sysdev_class_attribute attr;
+	enum node_states state;
+};
 
-#ifdef CONFIG_HIGHMEM
-static ssize_t print_nodes_has_high_memory(struct sysdev_class *class,
-					   struct sysdev_class_attribute *attr,
-					   char *buf)
+static ssize_t show_node_state(struct sysdev_class *class,
+			       struct sysdev_class_attribute *attr, char *buf)
 {
-	return print_nodes_state(N_HIGH_MEMORY, buf);
+	struct node_attr *na = container_of(attr, struct node_attr, attr);
+	return print_nodes_state(na->state, buf);
 }
 
-static SYSDEV_CLASS_ATTR(has_high_memory, 0444, print_nodes_has_high_memory,
-									 NULL);
-#endif
+#define _NODE_ATTR(name, state) \
+	{ _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state }
 
-struct sysdev_class_attribute *node_state_attr[] = {
-	&attr_possible,
-	&attr_online,
-	&attr_has_normal_memory,
+static struct node_attr node_state_attr[] = {
+	_NODE_ATTR(possible, N_POSSIBLE),
+	_NODE_ATTR(online, N_ONLINE),
+	_NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
+	_NODE_ATTR(has_cpu, N_CPU),
 #ifdef CONFIG_HIGHMEM
-	&attr_has_high_memory,
+	_NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
 #endif
-	&attr_has_cpu,
 };
 
 static int node_states_init(void)
@@ -604,9 +574,10 @@ static int node_states_init(void)
 	int i;
 	int err = 0;
 
+	BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
 	for (i = 0;  i < NR_NODE_STATES; i++) {
 		int ret;
-		ret = sysdev_class_create_file(&node_class, node_state_attr[i]);
+		ret = sysdev_class_create_file(&node_class, &node_state_attr[i].attr);
 		if (!err)
 			err = ret;
 	}

  parent reply	other threads:[~2010-01-05 11:48 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-05 11:47 [PATCH] [0/12] SYSFS: Sysfs attribute improvements Andi Kleen
2010-01-05 11:47 ` [PATCH] [1/12] SYSFS: Pass attribute in sysdev_class attributes show/store Andi Kleen
2010-01-05 14:53   ` Greg KH
2010-01-05 11:47 ` Andi Kleen [this message]
2010-01-05 11:48 ` [PATCH] [3/12] SYSDEV: Convert cpu driver sysdev class attributes Andi Kleen
2010-01-05 11:48 ` [PATCH] [4/12] SYSFS: Add sysfs_add/remove_files utility functions Andi Kleen
2010-01-05 14:53   ` Greg KH
2010-01-05 16:21     ` Andi Kleen
2010-01-05 23:20       ` Greg KH
2010-01-05 11:48 ` [PATCH] [5/12] SYSFS: Add attribute array to sysdev classes Andi Kleen
2010-01-05 14:54   ` Greg KH
2010-01-05 16:24     ` Andi Kleen
2010-01-05 23:20       ` Greg KH
2010-01-05 11:48 ` [PATCH] [6/12] SYSDEV: Convert node driver Andi Kleen
2010-01-05 11:48 ` [PATCH] [7/12] SYSDEV: Use sysdev_class attribute arrays in " Andi Kleen
2010-01-05 11:48 ` [PATCH] [8/12] SYSFS: Add sysdev_create/remove_files Andi Kleen
2010-01-05 11:48 ` [PATCH] [9/12] SYSFS: Fix type of sysdev class attribute in memory driver Andi Kleen
2010-01-05 11:48 ` [PATCH] [10/12] SYSDEV: Add attribute argument to class_attribute show/store Andi Kleen
2010-01-05 11:48 ` [PATCH] [11/12] SYSFS: Add class_attr_string for simple read-only string Andi Kleen
2010-01-05 11:48 ` [PATCH] [12/12] SYSFS: Convert some drivers to CLASS_ATTR_STRING Andi Kleen
2010-01-05 14:55 ` [PATCH] [0/12] SYSFS: Sysfs attribute improvements Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100105114759.7A2EEB17C2@basil.firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome