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