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