David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | ******************************************************************************* |
| 3 | ** |
| 4 | ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 5 | ** Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 6 | ** |
| 7 | ** This copyrighted material is made available to anyone wishing to use, |
| 8 | ** modify, copy, or redistribute it subject to the terms and conditions |
| 9 | ** of the GNU General Public License v.2. |
| 10 | ** |
| 11 | ******************************************************************************* |
| 12 | ******************************************************************************/ |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/configfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
David Teigland | 44be6fd | 2008-08-28 11:36:19 -0500 | [diff] [blame] | 18 | #include <linux/in.h> |
| 19 | #include <linux/in6.h> |
| 20 | #include <net/ipv6.h> |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 21 | #include <net/sock.h> |
| 22 | |
| 23 | #include "config.h" |
David Teigland | 1c032c0 | 2006-04-28 10:50:41 -0400 | [diff] [blame] | 24 | #include "lowcomms.h" |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 25 | |
| 26 | /* |
| 27 | * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid |
| 28 | * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/weight |
| 29 | * /config/dlm/<cluster>/comms/<comm>/nodeid |
| 30 | * /config/dlm/<cluster>/comms/<comm>/local |
Masatake YAMATO | 55b3286 | 2011-06-30 21:37:10 +0900 | [diff] [blame] | 31 | * /config/dlm/<cluster>/comms/<comm>/addr (write only) |
| 32 | * /config/dlm/<cluster>/comms/<comm>/addr_list (read only) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 33 | * The <cluster> level is useless, but I haven't figured out how to avoid it. |
| 34 | */ |
| 35 | |
| 36 | static struct config_group *space_list; |
| 37 | static struct config_group *comm_list; |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 38 | static struct dlm_comm *local_comm; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 39 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 40 | struct dlm_clusters; |
| 41 | struct dlm_cluster; |
| 42 | struct dlm_spaces; |
| 43 | struct dlm_space; |
| 44 | struct dlm_comms; |
| 45 | struct dlm_comm; |
| 46 | struct dlm_nodes; |
| 47 | struct dlm_node; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 48 | |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 49 | static struct config_group *make_cluster(struct config_group *, const char *); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 50 | static void drop_cluster(struct config_group *, struct config_item *); |
| 51 | static void release_cluster(struct config_item *); |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 52 | static struct config_group *make_space(struct config_group *, const char *); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 53 | static void drop_space(struct config_group *, struct config_item *); |
| 54 | static void release_space(struct config_item *); |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 55 | static struct config_item *make_comm(struct config_group *, const char *); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 56 | static void drop_comm(struct config_group *, struct config_item *); |
| 57 | static void release_comm(struct config_item *); |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 58 | static struct config_item *make_node(struct config_group *, const char *); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 59 | static void drop_node(struct config_group *, struct config_item *); |
| 60 | static void release_node(struct config_item *); |
| 61 | |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 62 | static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a, |
| 63 | char *buf); |
| 64 | static ssize_t store_cluster(struct config_item *i, |
| 65 | struct configfs_attribute *a, |
| 66 | const char *buf, size_t len); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 67 | static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a, |
| 68 | char *buf); |
| 69 | static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a, |
| 70 | const char *buf, size_t len); |
| 71 | static ssize_t show_node(struct config_item *i, struct configfs_attribute *a, |
| 72 | char *buf); |
| 73 | static ssize_t store_node(struct config_item *i, struct configfs_attribute *a, |
| 74 | const char *buf, size_t len); |
| 75 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 76 | static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf); |
| 77 | static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf, |
| 78 | size_t len); |
| 79 | static ssize_t comm_local_read(struct dlm_comm *cm, char *buf); |
| 80 | static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf, |
| 81 | size_t len); |
| 82 | static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, |
| 83 | size_t len); |
Masatake YAMATO | 55b3286 | 2011-06-30 21:37:10 +0900 | [diff] [blame] | 84 | static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf); |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 85 | static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf); |
| 86 | static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf, |
| 87 | size_t len); |
| 88 | static ssize_t node_weight_read(struct dlm_node *nd, char *buf); |
| 89 | static ssize_t node_weight_write(struct dlm_node *nd, const char *buf, |
| 90 | size_t len); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 91 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 92 | struct dlm_cluster { |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 93 | struct config_group group; |
| 94 | unsigned int cl_tcp_port; |
| 95 | unsigned int cl_buffer_size; |
| 96 | unsigned int cl_rsbtbl_size; |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 97 | unsigned int cl_dirtbl_size; |
| 98 | unsigned int cl_recover_timer; |
| 99 | unsigned int cl_toss_secs; |
| 100 | unsigned int cl_scan_secs; |
| 101 | unsigned int cl_log_debug; |
Patrick Caulfield | 6ed7257 | 2007-04-17 15:39:57 +0100 | [diff] [blame] | 102 | unsigned int cl_protocol; |
David Teigland | 3ae1acf | 2007-05-18 08:59:31 -0500 | [diff] [blame] | 103 | unsigned int cl_timewarn_cs; |
David Teigland | c6ff669 | 2011-03-28 14:17:26 -0500 | [diff] [blame] | 104 | unsigned int cl_waitwarn_us; |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | enum { |
| 108 | CLUSTER_ATTR_TCP_PORT = 0, |
| 109 | CLUSTER_ATTR_BUFFER_SIZE, |
| 110 | CLUSTER_ATTR_RSBTBL_SIZE, |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 111 | CLUSTER_ATTR_DIRTBL_SIZE, |
| 112 | CLUSTER_ATTR_RECOVER_TIMER, |
| 113 | CLUSTER_ATTR_TOSS_SECS, |
| 114 | CLUSTER_ATTR_SCAN_SECS, |
| 115 | CLUSTER_ATTR_LOG_DEBUG, |
Patrick Caulfield | 6ed7257 | 2007-04-17 15:39:57 +0100 | [diff] [blame] | 116 | CLUSTER_ATTR_PROTOCOL, |
David Teigland | 3ae1acf | 2007-05-18 08:59:31 -0500 | [diff] [blame] | 117 | CLUSTER_ATTR_TIMEWARN_CS, |
David Teigland | c6ff669 | 2011-03-28 14:17:26 -0500 | [diff] [blame] | 118 | CLUSTER_ATTR_WAITWARN_US, |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | struct cluster_attribute { |
| 122 | struct configfs_attribute attr; |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 123 | ssize_t (*show)(struct dlm_cluster *, char *); |
| 124 | ssize_t (*store)(struct dlm_cluster *, const char *, size_t); |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 125 | }; |
| 126 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 127 | static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field, |
Harvey Harrison | 5416b70 | 2008-02-13 16:54:29 -0800 | [diff] [blame] | 128 | int *info_field, int check_zero, |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 129 | const char *buf, size_t len) |
| 130 | { |
| 131 | unsigned int x; |
| 132 | |
| 133 | if (!capable(CAP_SYS_ADMIN)) |
| 134 | return -EACCES; |
| 135 | |
| 136 | x = simple_strtoul(buf, NULL, 0); |
| 137 | |
| 138 | if (check_zero && !x) |
| 139 | return -EINVAL; |
| 140 | |
| 141 | *cl_field = x; |
| 142 | *info_field = x; |
| 143 | |
| 144 | return len; |
| 145 | } |
| 146 | |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 147 | #define CLUSTER_ATTR(name, check_zero) \ |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 148 | static ssize_t name##_write(struct dlm_cluster *cl, const char *buf, size_t len) \ |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 149 | { \ |
| 150 | return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \ |
| 151 | check_zero, buf, len); \ |
| 152 | } \ |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 153 | static ssize_t name##_read(struct dlm_cluster *cl, char *buf) \ |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 154 | { \ |
| 155 | return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \ |
| 156 | } \ |
| 157 | static struct cluster_attribute cluster_attr_##name = \ |
| 158 | __CONFIGFS_ATTR(name, 0644, name##_read, name##_write) |
| 159 | |
| 160 | CLUSTER_ATTR(tcp_port, 1); |
| 161 | CLUSTER_ATTR(buffer_size, 1); |
| 162 | CLUSTER_ATTR(rsbtbl_size, 1); |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 163 | CLUSTER_ATTR(dirtbl_size, 1); |
| 164 | CLUSTER_ATTR(recover_timer, 1); |
| 165 | CLUSTER_ATTR(toss_secs, 1); |
| 166 | CLUSTER_ATTR(scan_secs, 1); |
| 167 | CLUSTER_ATTR(log_debug, 0); |
Patrick Caulfield | 6ed7257 | 2007-04-17 15:39:57 +0100 | [diff] [blame] | 168 | CLUSTER_ATTR(protocol, 0); |
David Teigland | 3ae1acf | 2007-05-18 08:59:31 -0500 | [diff] [blame] | 169 | CLUSTER_ATTR(timewarn_cs, 1); |
David Teigland | c6ff669 | 2011-03-28 14:17:26 -0500 | [diff] [blame] | 170 | CLUSTER_ATTR(waitwarn_us, 0); |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 171 | |
| 172 | static struct configfs_attribute *cluster_attrs[] = { |
| 173 | [CLUSTER_ATTR_TCP_PORT] = &cluster_attr_tcp_port.attr, |
| 174 | [CLUSTER_ATTR_BUFFER_SIZE] = &cluster_attr_buffer_size.attr, |
| 175 | [CLUSTER_ATTR_RSBTBL_SIZE] = &cluster_attr_rsbtbl_size.attr, |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 176 | [CLUSTER_ATTR_DIRTBL_SIZE] = &cluster_attr_dirtbl_size.attr, |
| 177 | [CLUSTER_ATTR_RECOVER_TIMER] = &cluster_attr_recover_timer.attr, |
| 178 | [CLUSTER_ATTR_TOSS_SECS] = &cluster_attr_toss_secs.attr, |
| 179 | [CLUSTER_ATTR_SCAN_SECS] = &cluster_attr_scan_secs.attr, |
| 180 | [CLUSTER_ATTR_LOG_DEBUG] = &cluster_attr_log_debug.attr, |
Patrick Caulfield | 6ed7257 | 2007-04-17 15:39:57 +0100 | [diff] [blame] | 181 | [CLUSTER_ATTR_PROTOCOL] = &cluster_attr_protocol.attr, |
David Teigland | 3ae1acf | 2007-05-18 08:59:31 -0500 | [diff] [blame] | 182 | [CLUSTER_ATTR_TIMEWARN_CS] = &cluster_attr_timewarn_cs.attr, |
David Teigland | c6ff669 | 2011-03-28 14:17:26 -0500 | [diff] [blame] | 183 | [CLUSTER_ATTR_WAITWARN_US] = &cluster_attr_waitwarn_us.attr, |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 184 | NULL, |
| 185 | }; |
| 186 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 187 | enum { |
| 188 | COMM_ATTR_NODEID = 0, |
| 189 | COMM_ATTR_LOCAL, |
| 190 | COMM_ATTR_ADDR, |
Masatake YAMATO | 55b3286 | 2011-06-30 21:37:10 +0900 | [diff] [blame] | 191 | COMM_ATTR_ADDR_LIST, |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | struct comm_attribute { |
| 195 | struct configfs_attribute attr; |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 196 | ssize_t (*show)(struct dlm_comm *, char *); |
| 197 | ssize_t (*store)(struct dlm_comm *, const char *, size_t); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | static struct comm_attribute comm_attr_nodeid = { |
| 201 | .attr = { .ca_owner = THIS_MODULE, |
| 202 | .ca_name = "nodeid", |
| 203 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 204 | .show = comm_nodeid_read, |
| 205 | .store = comm_nodeid_write, |
| 206 | }; |
| 207 | |
| 208 | static struct comm_attribute comm_attr_local = { |
| 209 | .attr = { .ca_owner = THIS_MODULE, |
| 210 | .ca_name = "local", |
| 211 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 212 | .show = comm_local_read, |
| 213 | .store = comm_local_write, |
| 214 | }; |
| 215 | |
| 216 | static struct comm_attribute comm_attr_addr = { |
| 217 | .attr = { .ca_owner = THIS_MODULE, |
| 218 | .ca_name = "addr", |
Masatake YAMATO | 55b3286 | 2011-06-30 21:37:10 +0900 | [diff] [blame] | 219 | .ca_mode = S_IWUSR }, |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 220 | .store = comm_addr_write, |
| 221 | }; |
| 222 | |
Masatake YAMATO | 55b3286 | 2011-06-30 21:37:10 +0900 | [diff] [blame] | 223 | static struct comm_attribute comm_attr_addr_list = { |
| 224 | .attr = { .ca_owner = THIS_MODULE, |
| 225 | .ca_name = "addr_list", |
| 226 | .ca_mode = S_IRUGO }, |
| 227 | .show = comm_addr_list_read, |
| 228 | }; |
| 229 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 230 | static struct configfs_attribute *comm_attrs[] = { |
| 231 | [COMM_ATTR_NODEID] = &comm_attr_nodeid.attr, |
| 232 | [COMM_ATTR_LOCAL] = &comm_attr_local.attr, |
| 233 | [COMM_ATTR_ADDR] = &comm_attr_addr.attr, |
Masatake YAMATO | 55b3286 | 2011-06-30 21:37:10 +0900 | [diff] [blame] | 234 | [COMM_ATTR_ADDR_LIST] = &comm_attr_addr_list.attr, |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 235 | NULL, |
| 236 | }; |
| 237 | |
| 238 | enum { |
| 239 | NODE_ATTR_NODEID = 0, |
| 240 | NODE_ATTR_WEIGHT, |
| 241 | }; |
| 242 | |
| 243 | struct node_attribute { |
| 244 | struct configfs_attribute attr; |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 245 | ssize_t (*show)(struct dlm_node *, char *); |
| 246 | ssize_t (*store)(struct dlm_node *, const char *, size_t); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | static struct node_attribute node_attr_nodeid = { |
| 250 | .attr = { .ca_owner = THIS_MODULE, |
| 251 | .ca_name = "nodeid", |
| 252 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 253 | .show = node_nodeid_read, |
| 254 | .store = node_nodeid_write, |
| 255 | }; |
| 256 | |
| 257 | static struct node_attribute node_attr_weight = { |
| 258 | .attr = { .ca_owner = THIS_MODULE, |
| 259 | .ca_name = "weight", |
| 260 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 261 | .show = node_weight_read, |
| 262 | .store = node_weight_write, |
| 263 | }; |
| 264 | |
| 265 | static struct configfs_attribute *node_attrs[] = { |
| 266 | [NODE_ATTR_NODEID] = &node_attr_nodeid.attr, |
| 267 | [NODE_ATTR_WEIGHT] = &node_attr_weight.attr, |
| 268 | NULL, |
| 269 | }; |
| 270 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 271 | struct dlm_clusters { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 272 | struct configfs_subsystem subsys; |
| 273 | }; |
| 274 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 275 | struct dlm_spaces { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 276 | struct config_group ss_group; |
| 277 | }; |
| 278 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 279 | struct dlm_space { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 280 | struct config_group group; |
| 281 | struct list_head members; |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 282 | struct mutex members_lock; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 283 | int members_count; |
| 284 | }; |
| 285 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 286 | struct dlm_comms { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 287 | struct config_group cs_group; |
| 288 | }; |
| 289 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 290 | struct dlm_comm { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 291 | struct config_item item; |
| 292 | int nodeid; |
| 293 | int local; |
| 294 | int addr_count; |
| 295 | struct sockaddr_storage *addr[DLM_MAX_ADDR_COUNT]; |
| 296 | }; |
| 297 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 298 | struct dlm_nodes { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 299 | struct config_group ns_group; |
| 300 | }; |
| 301 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 302 | struct dlm_node { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 303 | struct config_item item; |
| 304 | struct list_head list; /* space->members */ |
| 305 | int nodeid; |
| 306 | int weight; |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 307 | int new; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | static struct configfs_group_operations clusters_ops = { |
| 311 | .make_group = make_cluster, |
| 312 | .drop_item = drop_cluster, |
| 313 | }; |
| 314 | |
| 315 | static struct configfs_item_operations cluster_ops = { |
| 316 | .release = release_cluster, |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 317 | .show_attribute = show_cluster, |
| 318 | .store_attribute = store_cluster, |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 319 | }; |
| 320 | |
| 321 | static struct configfs_group_operations spaces_ops = { |
| 322 | .make_group = make_space, |
| 323 | .drop_item = drop_space, |
| 324 | }; |
| 325 | |
| 326 | static struct configfs_item_operations space_ops = { |
| 327 | .release = release_space, |
| 328 | }; |
| 329 | |
| 330 | static struct configfs_group_operations comms_ops = { |
| 331 | .make_item = make_comm, |
| 332 | .drop_item = drop_comm, |
| 333 | }; |
| 334 | |
| 335 | static struct configfs_item_operations comm_ops = { |
| 336 | .release = release_comm, |
| 337 | .show_attribute = show_comm, |
| 338 | .store_attribute = store_comm, |
| 339 | }; |
| 340 | |
| 341 | static struct configfs_group_operations nodes_ops = { |
| 342 | .make_item = make_node, |
| 343 | .drop_item = drop_node, |
| 344 | }; |
| 345 | |
| 346 | static struct configfs_item_operations node_ops = { |
| 347 | .release = release_node, |
| 348 | .show_attribute = show_node, |
| 349 | .store_attribute = store_node, |
| 350 | }; |
| 351 | |
| 352 | static struct config_item_type clusters_type = { |
| 353 | .ct_group_ops = &clusters_ops, |
| 354 | .ct_owner = THIS_MODULE, |
| 355 | }; |
| 356 | |
| 357 | static struct config_item_type cluster_type = { |
| 358 | .ct_item_ops = &cluster_ops, |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 359 | .ct_attrs = cluster_attrs, |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 360 | .ct_owner = THIS_MODULE, |
| 361 | }; |
| 362 | |
| 363 | static struct config_item_type spaces_type = { |
| 364 | .ct_group_ops = &spaces_ops, |
| 365 | .ct_owner = THIS_MODULE, |
| 366 | }; |
| 367 | |
| 368 | static struct config_item_type space_type = { |
| 369 | .ct_item_ops = &space_ops, |
| 370 | .ct_owner = THIS_MODULE, |
| 371 | }; |
| 372 | |
| 373 | static struct config_item_type comms_type = { |
| 374 | .ct_group_ops = &comms_ops, |
| 375 | .ct_owner = THIS_MODULE, |
| 376 | }; |
| 377 | |
| 378 | static struct config_item_type comm_type = { |
| 379 | .ct_item_ops = &comm_ops, |
| 380 | .ct_attrs = comm_attrs, |
| 381 | .ct_owner = THIS_MODULE, |
| 382 | }; |
| 383 | |
| 384 | static struct config_item_type nodes_type = { |
| 385 | .ct_group_ops = &nodes_ops, |
| 386 | .ct_owner = THIS_MODULE, |
| 387 | }; |
| 388 | |
| 389 | static struct config_item_type node_type = { |
| 390 | .ct_item_ops = &node_ops, |
| 391 | .ct_attrs = node_attrs, |
| 392 | .ct_owner = THIS_MODULE, |
| 393 | }; |
| 394 | |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 395 | static struct dlm_cluster *config_item_to_cluster(struct config_item *i) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 396 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 397 | return i ? container_of(to_config_group(i), struct dlm_cluster, group) : |
| 398 | NULL; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 401 | static struct dlm_space *config_item_to_space(struct config_item *i) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 402 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 403 | return i ? container_of(to_config_group(i), struct dlm_space, group) : |
| 404 | NULL; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 407 | static struct dlm_comm *config_item_to_comm(struct config_item *i) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 408 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 409 | return i ? container_of(i, struct dlm_comm, item) : NULL; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 412 | static struct dlm_node *config_item_to_node(struct config_item *i) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 413 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 414 | return i ? container_of(i, struct dlm_node, item) : NULL; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 417 | static struct config_group *make_cluster(struct config_group *g, |
| 418 | const char *name) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 419 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 420 | struct dlm_cluster *cl = NULL; |
| 421 | struct dlm_spaces *sps = NULL; |
| 422 | struct dlm_comms *cms = NULL; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 423 | void *gps = NULL; |
| 424 | |
David Teigland | 573c24c | 2009-11-30 16:34:43 -0600 | [diff] [blame] | 425 | cl = kzalloc(sizeof(struct dlm_cluster), GFP_NOFS); |
| 426 | gps = kcalloc(3, sizeof(struct config_group *), GFP_NOFS); |
| 427 | sps = kzalloc(sizeof(struct dlm_spaces), GFP_NOFS); |
| 428 | cms = kzalloc(sizeof(struct dlm_comms), GFP_NOFS); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 429 | |
| 430 | if (!cl || !gps || !sps || !cms) |
| 431 | goto fail; |
| 432 | |
| 433 | config_group_init_type_name(&cl->group, name, &cluster_type); |
| 434 | config_group_init_type_name(&sps->ss_group, "spaces", &spaces_type); |
| 435 | config_group_init_type_name(&cms->cs_group, "comms", &comms_type); |
| 436 | |
| 437 | cl->group.default_groups = gps; |
| 438 | cl->group.default_groups[0] = &sps->ss_group; |
| 439 | cl->group.default_groups[1] = &cms->cs_group; |
| 440 | cl->group.default_groups[2] = NULL; |
| 441 | |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 442 | cl->cl_tcp_port = dlm_config.ci_tcp_port; |
| 443 | cl->cl_buffer_size = dlm_config.ci_buffer_size; |
| 444 | cl->cl_rsbtbl_size = dlm_config.ci_rsbtbl_size; |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 445 | cl->cl_dirtbl_size = dlm_config.ci_dirtbl_size; |
| 446 | cl->cl_recover_timer = dlm_config.ci_recover_timer; |
| 447 | cl->cl_toss_secs = dlm_config.ci_toss_secs; |
| 448 | cl->cl_scan_secs = dlm_config.ci_scan_secs; |
| 449 | cl->cl_log_debug = dlm_config.ci_log_debug; |
David Teigland | 0b7cac0 | 2007-05-29 08:47:51 -0500 | [diff] [blame] | 450 | cl->cl_protocol = dlm_config.ci_protocol; |
David Teigland | 84d8cd6 | 2007-05-29 08:44:23 -0500 | [diff] [blame] | 451 | cl->cl_timewarn_cs = dlm_config.ci_timewarn_cs; |
David Teigland | c6ff669 | 2011-03-28 14:17:26 -0500 | [diff] [blame] | 452 | cl->cl_waitwarn_us = dlm_config.ci_waitwarn_us; |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 453 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 454 | space_list = &sps->ss_group; |
| 455 | comm_list = &cms->cs_group; |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 456 | return &cl->group; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 457 | |
| 458 | fail: |
| 459 | kfree(cl); |
| 460 | kfree(gps); |
| 461 | kfree(sps); |
| 462 | kfree(cms); |
Joel Becker | a6795e9 | 2008-07-17 15:21:29 -0700 | [diff] [blame] | 463 | return ERR_PTR(-ENOMEM); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void drop_cluster(struct config_group *g, struct config_item *i) |
| 467 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 468 | struct dlm_cluster *cl = config_item_to_cluster(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 469 | struct config_item *tmp; |
| 470 | int j; |
| 471 | |
| 472 | for (j = 0; cl->group.default_groups[j]; j++) { |
| 473 | tmp = &cl->group.default_groups[j]->cg_item; |
| 474 | cl->group.default_groups[j] = NULL; |
| 475 | config_item_put(tmp); |
| 476 | } |
| 477 | |
| 478 | space_list = NULL; |
| 479 | comm_list = NULL; |
| 480 | |
| 481 | config_item_put(i); |
| 482 | } |
| 483 | |
| 484 | static void release_cluster(struct config_item *i) |
| 485 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 486 | struct dlm_cluster *cl = config_item_to_cluster(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 487 | kfree(cl->group.default_groups); |
| 488 | kfree(cl); |
| 489 | } |
| 490 | |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 491 | static struct config_group *make_space(struct config_group *g, const char *name) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 492 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 493 | struct dlm_space *sp = NULL; |
| 494 | struct dlm_nodes *nds = NULL; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 495 | void *gps = NULL; |
| 496 | |
David Teigland | 573c24c | 2009-11-30 16:34:43 -0600 | [diff] [blame] | 497 | sp = kzalloc(sizeof(struct dlm_space), GFP_NOFS); |
| 498 | gps = kcalloc(2, sizeof(struct config_group *), GFP_NOFS); |
| 499 | nds = kzalloc(sizeof(struct dlm_nodes), GFP_NOFS); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 500 | |
| 501 | if (!sp || !gps || !nds) |
| 502 | goto fail; |
| 503 | |
| 504 | config_group_init_type_name(&sp->group, name, &space_type); |
| 505 | config_group_init_type_name(&nds->ns_group, "nodes", &nodes_type); |
| 506 | |
| 507 | sp->group.default_groups = gps; |
| 508 | sp->group.default_groups[0] = &nds->ns_group; |
| 509 | sp->group.default_groups[1] = NULL; |
| 510 | |
| 511 | INIT_LIST_HEAD(&sp->members); |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 512 | mutex_init(&sp->members_lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 513 | sp->members_count = 0; |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 514 | return &sp->group; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 515 | |
| 516 | fail: |
| 517 | kfree(sp); |
| 518 | kfree(gps); |
| 519 | kfree(nds); |
Joel Becker | a6795e9 | 2008-07-17 15:21:29 -0700 | [diff] [blame] | 520 | return ERR_PTR(-ENOMEM); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static void drop_space(struct config_group *g, struct config_item *i) |
| 524 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 525 | struct dlm_space *sp = config_item_to_space(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 526 | struct config_item *tmp; |
| 527 | int j; |
| 528 | |
| 529 | /* assert list_empty(&sp->members) */ |
| 530 | |
| 531 | for (j = 0; sp->group.default_groups[j]; j++) { |
| 532 | tmp = &sp->group.default_groups[j]->cg_item; |
| 533 | sp->group.default_groups[j] = NULL; |
| 534 | config_item_put(tmp); |
| 535 | } |
| 536 | |
| 537 | config_item_put(i); |
| 538 | } |
| 539 | |
| 540 | static void release_space(struct config_item *i) |
| 541 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 542 | struct dlm_space *sp = config_item_to_space(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 543 | kfree(sp->group.default_groups); |
| 544 | kfree(sp); |
| 545 | } |
| 546 | |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 547 | static struct config_item *make_comm(struct config_group *g, const char *name) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 548 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 549 | struct dlm_comm *cm; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 550 | |
David Teigland | 573c24c | 2009-11-30 16:34:43 -0600 | [diff] [blame] | 551 | cm = kzalloc(sizeof(struct dlm_comm), GFP_NOFS); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 552 | if (!cm) |
Joel Becker | a6795e9 | 2008-07-17 15:21:29 -0700 | [diff] [blame] | 553 | return ERR_PTR(-ENOMEM); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 554 | |
| 555 | config_item_init_type_name(&cm->item, name, &comm_type); |
| 556 | cm->nodeid = -1; |
| 557 | cm->local = 0; |
| 558 | cm->addr_count = 0; |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 559 | return &cm->item; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | static void drop_comm(struct config_group *g, struct config_item *i) |
| 563 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 564 | struct dlm_comm *cm = config_item_to_comm(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 565 | if (local_comm == cm) |
| 566 | local_comm = NULL; |
David Teigland | 1c032c0 | 2006-04-28 10:50:41 -0400 | [diff] [blame] | 567 | dlm_lowcomms_close(cm->nodeid); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 568 | while (cm->addr_count--) |
| 569 | kfree(cm->addr[cm->addr_count]); |
| 570 | config_item_put(i); |
| 571 | } |
| 572 | |
| 573 | static void release_comm(struct config_item *i) |
| 574 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 575 | struct dlm_comm *cm = config_item_to_comm(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 576 | kfree(cm); |
| 577 | } |
| 578 | |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 579 | static struct config_item *make_node(struct config_group *g, const char *name) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 580 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 581 | struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent); |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 582 | struct dlm_node *nd; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 583 | |
David Teigland | 573c24c | 2009-11-30 16:34:43 -0600 | [diff] [blame] | 584 | nd = kzalloc(sizeof(struct dlm_node), GFP_NOFS); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 585 | if (!nd) |
Joel Becker | a6795e9 | 2008-07-17 15:21:29 -0700 | [diff] [blame] | 586 | return ERR_PTR(-ENOMEM); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 587 | |
| 588 | config_item_init_type_name(&nd->item, name, &node_type); |
| 589 | nd->nodeid = -1; |
| 590 | nd->weight = 1; /* default weight of 1 if none is set */ |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 591 | nd->new = 1; /* set to 0 once it's been read by dlm_nodeid_list() */ |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 592 | |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 593 | mutex_lock(&sp->members_lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 594 | list_add(&nd->list, &sp->members); |
| 595 | sp->members_count++; |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 596 | mutex_unlock(&sp->members_lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 597 | |
Joel Becker | f89ab86 | 2008-07-17 14:53:48 -0700 | [diff] [blame] | 598 | return &nd->item; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | static void drop_node(struct config_group *g, struct config_item *i) |
| 602 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 603 | struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent); |
| 604 | struct dlm_node *nd = config_item_to_node(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 605 | |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 606 | mutex_lock(&sp->members_lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 607 | list_del(&nd->list); |
| 608 | sp->members_count--; |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 609 | mutex_unlock(&sp->members_lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 610 | |
| 611 | config_item_put(i); |
| 612 | } |
| 613 | |
| 614 | static void release_node(struct config_item *i) |
| 615 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 616 | struct dlm_node *nd = config_item_to_node(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 617 | kfree(nd); |
| 618 | } |
| 619 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 620 | static struct dlm_clusters clusters_root = { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 621 | .subsys = { |
| 622 | .su_group = { |
| 623 | .cg_item = { |
| 624 | .ci_namebuf = "dlm", |
| 625 | .ci_type = &clusters_type, |
| 626 | }, |
| 627 | }, |
| 628 | }, |
| 629 | }; |
| 630 | |
Denis Cheng | 3072717 | 2008-02-02 01:53:46 +0800 | [diff] [blame] | 631 | int __init dlm_config_init(void) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 632 | { |
| 633 | config_group_init(&clusters_root.subsys.su_group); |
Joel Becker | e6bd07a | 2007-07-06 23:33:17 -0700 | [diff] [blame] | 634 | mutex_init(&clusters_root.subsys.su_mutex); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 635 | return configfs_register_subsystem(&clusters_root.subsys); |
| 636 | } |
| 637 | |
| 638 | void dlm_config_exit(void) |
| 639 | { |
| 640 | configfs_unregister_subsystem(&clusters_root.subsys); |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | * Functions for user space to read/write attributes |
| 645 | */ |
| 646 | |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 647 | static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a, |
| 648 | char *buf) |
| 649 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 650 | struct dlm_cluster *cl = config_item_to_cluster(i); |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 651 | struct cluster_attribute *cla = |
| 652 | container_of(a, struct cluster_attribute, attr); |
| 653 | return cla->show ? cla->show(cl, buf) : 0; |
| 654 | } |
| 655 | |
| 656 | static ssize_t store_cluster(struct config_item *i, |
| 657 | struct configfs_attribute *a, |
| 658 | const char *buf, size_t len) |
| 659 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 660 | struct dlm_cluster *cl = config_item_to_cluster(i); |
David Teigland | d200778 | 2007-01-09 09:46:02 -0600 | [diff] [blame] | 661 | struct cluster_attribute *cla = |
| 662 | container_of(a, struct cluster_attribute, attr); |
| 663 | return cla->store ? cla->store(cl, buf, len) : -EINVAL; |
| 664 | } |
| 665 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 666 | static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a, |
| 667 | char *buf) |
| 668 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 669 | struct dlm_comm *cm = config_item_to_comm(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 670 | struct comm_attribute *cma = |
| 671 | container_of(a, struct comm_attribute, attr); |
| 672 | return cma->show ? cma->show(cm, buf) : 0; |
| 673 | } |
| 674 | |
| 675 | static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a, |
| 676 | const char *buf, size_t len) |
| 677 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 678 | struct dlm_comm *cm = config_item_to_comm(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 679 | struct comm_attribute *cma = |
| 680 | container_of(a, struct comm_attribute, attr); |
| 681 | return cma->store ? cma->store(cm, buf, len) : -EINVAL; |
| 682 | } |
| 683 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 684 | static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 685 | { |
| 686 | return sprintf(buf, "%d\n", cm->nodeid); |
| 687 | } |
| 688 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 689 | static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf, |
| 690 | size_t len) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 691 | { |
| 692 | cm->nodeid = simple_strtol(buf, NULL, 0); |
| 693 | return len; |
| 694 | } |
| 695 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 696 | static ssize_t comm_local_read(struct dlm_comm *cm, char *buf) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 697 | { |
| 698 | return sprintf(buf, "%d\n", cm->local); |
| 699 | } |
| 700 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 701 | static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf, |
| 702 | size_t len) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 703 | { |
| 704 | cm->local= simple_strtol(buf, NULL, 0); |
| 705 | if (cm->local && !local_comm) |
| 706 | local_comm = cm; |
| 707 | return len; |
| 708 | } |
| 709 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 710 | static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 711 | { |
| 712 | struct sockaddr_storage *addr; |
| 713 | |
| 714 | if (len != sizeof(struct sockaddr_storage)) |
| 715 | return -EINVAL; |
| 716 | |
| 717 | if (cm->addr_count >= DLM_MAX_ADDR_COUNT) |
| 718 | return -ENOSPC; |
| 719 | |
David Teigland | 573c24c | 2009-11-30 16:34:43 -0600 | [diff] [blame] | 720 | addr = kzalloc(sizeof(*addr), GFP_NOFS); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 721 | if (!addr) |
| 722 | return -ENOMEM; |
| 723 | |
| 724 | memcpy(addr, buf, len); |
| 725 | cm->addr[cm->addr_count++] = addr; |
| 726 | return len; |
| 727 | } |
| 728 | |
Masatake YAMATO | 55b3286 | 2011-06-30 21:37:10 +0900 | [diff] [blame] | 729 | static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf) |
| 730 | { |
| 731 | ssize_t s; |
| 732 | ssize_t allowance; |
| 733 | int i; |
| 734 | struct sockaddr_storage *addr; |
| 735 | struct sockaddr_in *addr_in; |
| 736 | struct sockaddr_in6 *addr_in6; |
| 737 | |
| 738 | /* Taken from ip6_addr_string() defined in lib/vsprintf.c */ |
| 739 | char buf0[sizeof("AF_INET6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255\n")]; |
| 740 | |
| 741 | |
| 742 | /* Derived from SIMPLE_ATTR_SIZE of fs/configfs/file.c */ |
| 743 | allowance = 4096; |
| 744 | buf[0] = '\0'; |
| 745 | |
| 746 | for (i = 0; i < cm->addr_count; i++) { |
| 747 | addr = cm->addr[i]; |
| 748 | |
| 749 | switch(addr->ss_family) { |
| 750 | case AF_INET: |
| 751 | addr_in = (struct sockaddr_in *)addr; |
| 752 | s = sprintf(buf0, "AF_INET %pI4\n", &addr_in->sin_addr.s_addr); |
| 753 | break; |
| 754 | case AF_INET6: |
| 755 | addr_in6 = (struct sockaddr_in6 *)addr; |
| 756 | s = sprintf(buf0, "AF_INET6 %pI6\n", &addr_in6->sin6_addr); |
| 757 | break; |
| 758 | default: |
| 759 | s = sprintf(buf0, "%s\n", "<UNKNOWN>"); |
| 760 | break; |
| 761 | } |
| 762 | allowance -= s; |
| 763 | if (allowance >= 0) |
| 764 | strcat(buf, buf0); |
| 765 | else { |
| 766 | allowance += s; |
| 767 | break; |
| 768 | } |
| 769 | } |
| 770 | return 4096 - allowance; |
| 771 | } |
| 772 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 773 | static ssize_t show_node(struct config_item *i, struct configfs_attribute *a, |
| 774 | char *buf) |
| 775 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 776 | struct dlm_node *nd = config_item_to_node(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 777 | struct node_attribute *nda = |
| 778 | container_of(a, struct node_attribute, attr); |
| 779 | return nda->show ? nda->show(nd, buf) : 0; |
| 780 | } |
| 781 | |
| 782 | static ssize_t store_node(struct config_item *i, struct configfs_attribute *a, |
| 783 | const char *buf, size_t len) |
| 784 | { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 785 | struct dlm_node *nd = config_item_to_node(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 786 | struct node_attribute *nda = |
| 787 | container_of(a, struct node_attribute, attr); |
| 788 | return nda->store ? nda->store(nd, buf, len) : -EINVAL; |
| 789 | } |
| 790 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 791 | static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 792 | { |
| 793 | return sprintf(buf, "%d\n", nd->nodeid); |
| 794 | } |
| 795 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 796 | static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf, |
| 797 | size_t len) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 798 | { |
| 799 | nd->nodeid = simple_strtol(buf, NULL, 0); |
| 800 | return len; |
| 801 | } |
| 802 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 803 | static ssize_t node_weight_read(struct dlm_node *nd, char *buf) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 804 | { |
| 805 | return sprintf(buf, "%d\n", nd->weight); |
| 806 | } |
| 807 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 808 | static ssize_t node_weight_write(struct dlm_node *nd, const char *buf, |
| 809 | size_t len) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 810 | { |
| 811 | nd->weight = simple_strtol(buf, NULL, 0); |
| 812 | return len; |
| 813 | } |
| 814 | |
| 815 | /* |
| 816 | * Functions for the dlm to get the info that's been configured |
| 817 | */ |
| 818 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 819 | static struct dlm_space *get_space(char *name) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 820 | { |
Satyam Sharma | 3168b07 | 2007-05-08 09:18:58 +0100 | [diff] [blame] | 821 | struct config_item *i; |
| 822 | |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 823 | if (!space_list) |
| 824 | return NULL; |
Satyam Sharma | 3168b07 | 2007-05-08 09:18:58 +0100 | [diff] [blame] | 825 | |
Joel Becker | e6bd07a | 2007-07-06 23:33:17 -0700 | [diff] [blame] | 826 | mutex_lock(&space_list->cg_subsys->su_mutex); |
Satyam Sharma | 3fe6c5c | 2007-07-04 16:37:16 +0530 | [diff] [blame] | 827 | i = config_group_find_item(space_list, name); |
Joel Becker | e6bd07a | 2007-07-06 23:33:17 -0700 | [diff] [blame] | 828 | mutex_unlock(&space_list->cg_subsys->su_mutex); |
Satyam Sharma | 3168b07 | 2007-05-08 09:18:58 +0100 | [diff] [blame] | 829 | |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 830 | return config_item_to_space(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 831 | } |
| 832 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 833 | static void put_space(struct dlm_space *sp) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 834 | { |
| 835 | config_item_put(&sp->group.cg_item); |
| 836 | } |
| 837 | |
David Teigland | 44be6fd | 2008-08-28 11:36:19 -0500 | [diff] [blame] | 838 | static int addr_compare(struct sockaddr_storage *x, struct sockaddr_storage *y) |
| 839 | { |
| 840 | switch (x->ss_family) { |
| 841 | case AF_INET: { |
| 842 | struct sockaddr_in *sinx = (struct sockaddr_in *)x; |
| 843 | struct sockaddr_in *siny = (struct sockaddr_in *)y; |
| 844 | if (sinx->sin_addr.s_addr != siny->sin_addr.s_addr) |
| 845 | return 0; |
| 846 | if (sinx->sin_port != siny->sin_port) |
| 847 | return 0; |
| 848 | break; |
| 849 | } |
| 850 | case AF_INET6: { |
| 851 | struct sockaddr_in6 *sinx = (struct sockaddr_in6 *)x; |
| 852 | struct sockaddr_in6 *siny = (struct sockaddr_in6 *)y; |
| 853 | if (!ipv6_addr_equal(&sinx->sin6_addr, &siny->sin6_addr)) |
| 854 | return 0; |
| 855 | if (sinx->sin6_port != siny->sin6_port) |
| 856 | return 0; |
| 857 | break; |
| 858 | } |
| 859 | default: |
| 860 | return 0; |
| 861 | } |
| 862 | return 1; |
| 863 | } |
| 864 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 865 | static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 866 | { |
| 867 | struct config_item *i; |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 868 | struct dlm_comm *cm = NULL; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 869 | int found = 0; |
| 870 | |
| 871 | if (!comm_list) |
| 872 | return NULL; |
| 873 | |
Joel Becker | e6bd07a | 2007-07-06 23:33:17 -0700 | [diff] [blame] | 874 | mutex_lock(&clusters_root.subsys.su_mutex); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 875 | |
| 876 | list_for_each_entry(i, &comm_list->cg_children, ci_entry) { |
Andrew Morton | 27eccf4 | 2008-09-05 08:42:08 -0500 | [diff] [blame] | 877 | cm = config_item_to_comm(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 878 | |
| 879 | if (nodeid) { |
| 880 | if (cm->nodeid != nodeid) |
| 881 | continue; |
| 882 | found = 1; |
Satyam Sharma | 3168b07 | 2007-05-08 09:18:58 +0100 | [diff] [blame] | 883 | config_item_get(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 884 | break; |
| 885 | } else { |
David Teigland | 44be6fd | 2008-08-28 11:36:19 -0500 | [diff] [blame] | 886 | if (!cm->addr_count || !addr_compare(cm->addr[0], addr)) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 887 | continue; |
| 888 | found = 1; |
Satyam Sharma | 3168b07 | 2007-05-08 09:18:58 +0100 | [diff] [blame] | 889 | config_item_get(i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 890 | break; |
| 891 | } |
| 892 | } |
Joel Becker | e6bd07a | 2007-07-06 23:33:17 -0700 | [diff] [blame] | 893 | mutex_unlock(&clusters_root.subsys.su_mutex); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 894 | |
Satyam Sharma | 3168b07 | 2007-05-08 09:18:58 +0100 | [diff] [blame] | 895 | if (!found) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 896 | cm = NULL; |
| 897 | return cm; |
| 898 | } |
| 899 | |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 900 | static void put_comm(struct dlm_comm *cm) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 901 | { |
| 902 | config_item_put(&cm->item); |
| 903 | } |
| 904 | |
| 905 | /* caller must free mem */ |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 906 | int dlm_nodeid_list(char *lsname, int **ids_out, int *ids_count_out, |
| 907 | int **new_out, int *new_count_out) |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 908 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 909 | struct dlm_space *sp; |
| 910 | struct dlm_node *nd; |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 911 | int i = 0, rv = 0, ids_count = 0, new_count = 0; |
| 912 | int *ids, *new; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 913 | |
| 914 | sp = get_space(lsname); |
| 915 | if (!sp) |
| 916 | return -EEXIST; |
| 917 | |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 918 | mutex_lock(&sp->members_lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 919 | if (!sp->members_count) { |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 920 | rv = -EINVAL; |
| 921 | printk(KERN_ERR "dlm: zero members_count\n"); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 922 | goto out; |
| 923 | } |
| 924 | |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 925 | ids_count = sp->members_count; |
| 926 | |
David Teigland | 573c24c | 2009-11-30 16:34:43 -0600 | [diff] [blame] | 927 | ids = kcalloc(ids_count, sizeof(int), GFP_NOFS); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 928 | if (!ids) { |
| 929 | rv = -ENOMEM; |
| 930 | goto out; |
| 931 | } |
| 932 | |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 933 | list_for_each_entry(nd, &sp->members, list) { |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 934 | ids[i++] = nd->nodeid; |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 935 | if (nd->new) |
| 936 | new_count++; |
| 937 | } |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 938 | |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 939 | if (ids_count != i) |
| 940 | printk(KERN_ERR "dlm: bad nodeid count %d %d\n", ids_count, i); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 941 | |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 942 | if (!new_count) |
| 943 | goto out_ids; |
| 944 | |
David Teigland | 573c24c | 2009-11-30 16:34:43 -0600 | [diff] [blame] | 945 | new = kcalloc(new_count, sizeof(int), GFP_NOFS); |
David Teigland | d44e0fc | 2008-03-18 14:22:11 -0500 | [diff] [blame] | 946 | if (!new) { |
| 947 | kfree(ids); |
| 948 | rv = -ENOMEM; |
| 949 | goto out; |
| 950 | } |
| 951 | |
| 952 | i = 0; |
| 953 | list_for_each_entry(nd, &sp->members, list) { |
| 954 | if (nd->new) { |
| 955 | new[i++] = nd->nodeid; |
| 956 | nd->new = 0; |
| 957 | } |
| 958 | } |
| 959 | *new_count_out = new_count; |
| 960 | *new_out = new; |
| 961 | |
| 962 | out_ids: |
| 963 | *ids_count_out = ids_count; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 964 | *ids_out = ids; |
| 965 | out: |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 966 | mutex_unlock(&sp->members_lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 967 | put_space(sp); |
| 968 | return rv; |
| 969 | } |
| 970 | |
| 971 | int dlm_node_weight(char *lsname, int nodeid) |
| 972 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 973 | struct dlm_space *sp; |
| 974 | struct dlm_node *nd; |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 975 | int w = -EEXIST; |
| 976 | |
| 977 | sp = get_space(lsname); |
| 978 | if (!sp) |
| 979 | goto out; |
| 980 | |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 981 | mutex_lock(&sp->members_lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 982 | list_for_each_entry(nd, &sp->members, list) { |
| 983 | if (nd->nodeid != nodeid) |
| 984 | continue; |
| 985 | w = nd->weight; |
| 986 | break; |
| 987 | } |
David Teigland | 9013592 | 2006-01-20 08:47:07 +0000 | [diff] [blame] | 988 | mutex_unlock(&sp->members_lock); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 989 | put_space(sp); |
| 990 | out: |
| 991 | return w; |
| 992 | } |
| 993 | |
| 994 | int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr) |
| 995 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 996 | struct dlm_comm *cm = get_comm(nodeid, NULL); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 997 | if (!cm) |
| 998 | return -EEXIST; |
| 999 | if (!cm->addr_count) |
| 1000 | return -ENOENT; |
| 1001 | memcpy(addr, cm->addr[0], sizeof(*addr)); |
| 1002 | put_comm(cm); |
| 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid) |
| 1007 | { |
David Teigland | 5140934 | 2008-07-31 09:31:53 -0500 | [diff] [blame] | 1008 | struct dlm_comm *cm = get_comm(0, addr); |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 1009 | if (!cm) |
| 1010 | return -EEXIST; |
| 1011 | *nodeid = cm->nodeid; |
| 1012 | put_comm(cm); |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | int dlm_our_nodeid(void) |
| 1017 | { |
| 1018 | return local_comm ? local_comm->nodeid : 0; |
| 1019 | } |
| 1020 | |
| 1021 | /* num 0 is first addr, num 1 is second addr */ |
| 1022 | int dlm_our_addr(struct sockaddr_storage *addr, int num) |
| 1023 | { |
| 1024 | if (!local_comm) |
| 1025 | return -1; |
| 1026 | if (num + 1 > local_comm->addr_count) |
| 1027 | return -1; |
| 1028 | memcpy(addr, local_comm->addr[num], sizeof(*addr)); |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | /* Config file defaults */ |
| 1033 | #define DEFAULT_TCP_PORT 21064 |
| 1034 | #define DEFAULT_BUFFER_SIZE 4096 |
David Teigland | e3853a9 | 2011-03-10 13:07:17 -0600 | [diff] [blame] | 1035 | #define DEFAULT_RSBTBL_SIZE 1024 |
David Teigland | e3853a9 | 2011-03-10 13:07:17 -0600 | [diff] [blame] | 1036 | #define DEFAULT_DIRTBL_SIZE 1024 |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 1037 | #define DEFAULT_RECOVER_TIMER 5 |
| 1038 | #define DEFAULT_TOSS_SECS 10 |
| 1039 | #define DEFAULT_SCAN_SECS 5 |
David Teigland | 99fc648 | 2007-01-09 09:44:01 -0600 | [diff] [blame] | 1040 | #define DEFAULT_LOG_DEBUG 0 |
Patrick Caulfield | 6ed7257 | 2007-04-17 15:39:57 +0100 | [diff] [blame] | 1041 | #define DEFAULT_PROTOCOL 0 |
David Teigland | 3ae1acf | 2007-05-18 08:59:31 -0500 | [diff] [blame] | 1042 | #define DEFAULT_TIMEWARN_CS 500 /* 5 sec = 500 centiseconds */ |
David Teigland | c6ff669 | 2011-03-28 14:17:26 -0500 | [diff] [blame] | 1043 | #define DEFAULT_WAITWARN_US 0 |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 1044 | |
| 1045 | struct dlm_config_info dlm_config = { |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 1046 | .ci_tcp_port = DEFAULT_TCP_PORT, |
| 1047 | .ci_buffer_size = DEFAULT_BUFFER_SIZE, |
| 1048 | .ci_rsbtbl_size = DEFAULT_RSBTBL_SIZE, |
David Teigland | 68c817a | 2007-01-09 09:41:48 -0600 | [diff] [blame] | 1049 | .ci_dirtbl_size = DEFAULT_DIRTBL_SIZE, |
| 1050 | .ci_recover_timer = DEFAULT_RECOVER_TIMER, |
| 1051 | .ci_toss_secs = DEFAULT_TOSS_SECS, |
David Teigland | 99fc648 | 2007-01-09 09:44:01 -0600 | [diff] [blame] | 1052 | .ci_scan_secs = DEFAULT_SCAN_SECS, |
Patrick Caulfield | 6ed7257 | 2007-04-17 15:39:57 +0100 | [diff] [blame] | 1053 | .ci_log_debug = DEFAULT_LOG_DEBUG, |
David Teigland | 3ae1acf | 2007-05-18 08:59:31 -0500 | [diff] [blame] | 1054 | .ci_protocol = DEFAULT_PROTOCOL, |
David Teigland | c6ff669 | 2011-03-28 14:17:26 -0500 | [diff] [blame] | 1055 | .ci_timewarn_cs = DEFAULT_TIMEWARN_CS, |
| 1056 | .ci_waitwarn_us = DEFAULT_WAITWARN_US |
David Teigland | e7fd417 | 2006-01-18 09:30:29 +0000 | [diff] [blame] | 1057 | }; |
| 1058 | |