[Linux-cluster] [PATCH] /config/dlm/<cluster>/comms/<comm>/addr_list

Masatake YAMATO yamato at redhat.com
Thu Jun 30 12:37:10 UTC 2011


Hi,

> On Thu, Jun 09, 2011 at 05:55:29PM +0900, Masatake YAMATO wrote:
>> Hi,
>> 
>> I've found /config/dlm/<cluster>/comms/<comm>/addr is readable 
>> (in meaning of ls -l) but no handler(comm_addr_read) is defined in 
>> dlm/fs/dlm/config.c.
>> 
>> If cat command works fine with /config/dlm/<cluster>/comms/<comm>/addr,
>> it will be nice to understand the status of dlm. So I'm thinking about
>> writing a patch.
>> 
>> But after reading the source code, I've found its difficulties;
>> /config/dlm/<cluster>/comms/<comm>/addr holds 'struct
>> sockaddr_storage'.
> 
> Another problem is that you can write multiple addr's to that file
> sequentially when using SCTP, so which do you get when you read it?
> 
>>     3. Make /config/dlm/<cluster>/comms/<comm>/addr unreadable (in meaning of ls -l)
>> 
>>        e.g.
>>        # ls -l /config/dlm/<cluster>/comms/<comm>/addr
>>        --w-------. 1 root root 4096 Jun  9 08:51 /config/dlm/<cluster>/comms/<comm>/addr
>> 
>>        Advantage: easy to implement.
>>        Disadvantage: no way to know the value of node addr of dlm view.
> 
> I suggest this.  If you want a way to read them, I'd add a new readonly
> file addr_list,
> 
> # cat /config/dlm/<cluster>/comms/<comm>/addr_list
> AF_INET 192.168.151.1
> AF_INET 192.168.151.2
> 
> Dave
> 

Added addr_list. Could you try my patch?

Signed-off-by: Masatake YAMATO <yamato at redhat.com>



diff --git a/fs/dlm/config.c b/fs/dlm/config.c
index 0d329ff..adfd90b 100644
--- a/fs/dlm/config.c
+++ b/fs/dlm/config.c
@@ -28,7 +28,8 @@
  * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/weight
  * /config/dlm/<cluster>/comms/<comm>/nodeid
  * /config/dlm/<cluster>/comms/<comm>/local
- * /config/dlm/<cluster>/comms/<comm>/addr
+ * /config/dlm/<cluster>/comms/<comm>/addr      (write only)
+ * /config/dlm/<cluster>/comms/<comm>/addr_list (read only)
  * The <cluster> level is useless, but I haven't figured out how to avoid it.
  */
 
@@ -80,6 +81,7 @@ static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
 				size_t len);
 static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf,
 				size_t len);
+static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf);
 static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf);
 static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
 				size_t len);
@@ -186,6 +188,7 @@ enum {
 	COMM_ATTR_NODEID = 0,
 	COMM_ATTR_LOCAL,
 	COMM_ATTR_ADDR,
+	COMM_ATTR_ADDR_LIST,
 };
 
 struct comm_attribute {
@@ -213,14 +216,22 @@ static struct comm_attribute comm_attr_local = {
 static struct comm_attribute comm_attr_addr = {
 	.attr   = { .ca_owner = THIS_MODULE,
                     .ca_name = "addr",
-                    .ca_mode = S_IRUGO | S_IWUSR },
+                    .ca_mode = S_IWUSR },
 	.store  = comm_addr_write,
 };
 
+static struct comm_attribute comm_attr_addr_list = {
+	.attr   = { .ca_owner = THIS_MODULE,
+                    .ca_name = "addr_list",
+                    .ca_mode = S_IRUGO },
+	.show   = comm_addr_list_read,
+};
+
 static struct configfs_attribute *comm_attrs[] = {
 	[COMM_ATTR_NODEID] = &comm_attr_nodeid.attr,
 	[COMM_ATTR_LOCAL] = &comm_attr_local.attr,
 	[COMM_ATTR_ADDR] = &comm_attr_addr.attr,
+	[COMM_ATTR_ADDR_LIST] = &comm_attr_addr_list.attr,
 	NULL,
 };
 
@@ -715,6 +726,50 @@ static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len)
 	return len;
 }
 
+static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf)
+{
+	ssize_t s;
+	ssize_t allowance;
+	int i;
+	struct sockaddr_storage *addr;
+	struct sockaddr_in *addr_in;
+	struct sockaddr_in6 *addr_in6;
+	
+	/* Taken from ip6_addr_string() defined in lib/vsprintf.c */
+	char buf0[sizeof("AF_INET6	xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255\n")];
+	
+
+	/* Derived from SIMPLE_ATTR_SIZE of fs/configfs/file.c */
+	allowance = 4096;
+	buf[0] = '\0';
+
+	for (i = 0; i < cm->addr_count; i++) {
+		addr = cm->addr[i];
+
+		switch(addr->ss_family) {
+		case AF_INET:
+			addr_in = (struct sockaddr_in *)addr;
+			s = sprintf(buf0, "AF_INET	%pI4\n", &addr_in->sin_addr.s_addr);
+			break;
+		case AF_INET6:
+			addr_in6 = (struct sockaddr_in6 *)addr;
+			s = sprintf(buf0, "AF_INET6	%pI6\n", &addr_in6->sin6_addr);
+			break;
+		default:
+			s = sprintf(buf0, "%s\n", "<UNKNOWN>");
+			break;
+		}
+		allowance -= s;
+		if (allowance >= 0)
+			strcat(buf, buf0);
+		else {
+			allowance += s;
+			break;
+		}
+	}
+	return 4096 - allowance;
+}
+
 static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
 			 char *buf)
 {




More information about the Linux-cluster mailing list