blob: b54bca03d92f467da2d0e09ef74a341c1cdaa5ce [file] [log] [blame]
David Teiglande7fd4172006-01-18 09:30:29 +00001/******************************************************************************
2*******************************************************************************
3**
4** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
David Teigland51409342008-07-31 09:31:53 -05005** Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
David Teiglande7fd4172006-01-18 09:30:29 +00006**
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 Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
David Teigland44be6fd2008-08-28 11:36:19 -050018#include <linux/in.h>
19#include <linux/in6.h>
20#include <net/ipv6.h>
David Teiglande7fd4172006-01-18 09:30:29 +000021#include <net/sock.h>
22
23#include "config.h"
David Teigland1c032c02006-04-28 10:50:41 -040024#include "lowcomms.h"
David Teiglande7fd4172006-01-18 09:30:29 +000025
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
35static struct config_group *space_list;
36static struct config_group *comm_list;
David Teigland51409342008-07-31 09:31:53 -050037static struct dlm_comm *local_comm;
David Teiglande7fd4172006-01-18 09:30:29 +000038
David Teigland51409342008-07-31 09:31:53 -050039struct dlm_clusters;
40struct dlm_cluster;
41struct dlm_spaces;
42struct dlm_space;
43struct dlm_comms;
44struct dlm_comm;
45struct dlm_nodes;
46struct dlm_node;
David Teiglande7fd4172006-01-18 09:30:29 +000047
Joel Beckerf89ab862008-07-17 14:53:48 -070048static struct config_group *make_cluster(struct config_group *, const char *);
David Teiglande7fd4172006-01-18 09:30:29 +000049static void drop_cluster(struct config_group *, struct config_item *);
50static void release_cluster(struct config_item *);
Joel Beckerf89ab862008-07-17 14:53:48 -070051static struct config_group *make_space(struct config_group *, const char *);
David Teiglande7fd4172006-01-18 09:30:29 +000052static void drop_space(struct config_group *, struct config_item *);
53static void release_space(struct config_item *);
Joel Beckerf89ab862008-07-17 14:53:48 -070054static struct config_item *make_comm(struct config_group *, const char *);
David Teiglande7fd4172006-01-18 09:30:29 +000055static void drop_comm(struct config_group *, struct config_item *);
56static void release_comm(struct config_item *);
Joel Beckerf89ab862008-07-17 14:53:48 -070057static struct config_item *make_node(struct config_group *, const char *);
David Teiglande7fd4172006-01-18 09:30:29 +000058static void drop_node(struct config_group *, struct config_item *);
59static void release_node(struct config_item *);
60
David Teiglandd2007782007-01-09 09:46:02 -060061static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a,
62 char *buf);
63static ssize_t store_cluster(struct config_item *i,
64 struct configfs_attribute *a,
65 const char *buf, size_t len);
David Teiglande7fd4172006-01-18 09:30:29 +000066static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
67 char *buf);
68static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
69 const char *buf, size_t len);
70static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
71 char *buf);
72static ssize_t store_node(struct config_item *i, struct configfs_attribute *a,
73 const char *buf, size_t len);
74
David Teigland51409342008-07-31 09:31:53 -050075static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf);
76static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf,
77 size_t len);
78static ssize_t comm_local_read(struct dlm_comm *cm, char *buf);
79static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
80 size_t len);
81static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf,
82 size_t len);
83static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf);
84static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
85 size_t len);
86static ssize_t node_weight_read(struct dlm_node *nd, char *buf);
87static ssize_t node_weight_write(struct dlm_node *nd, const char *buf,
88 size_t len);
David Teiglande7fd4172006-01-18 09:30:29 +000089
David Teigland51409342008-07-31 09:31:53 -050090struct dlm_cluster {
David Teiglandd2007782007-01-09 09:46:02 -060091 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 Caulfield6ed72572007-04-17 15:39:57 +0100101 unsigned int cl_protocol;
David Teigland3ae1acf2007-05-18 08:59:31 -0500102 unsigned int cl_timewarn_cs;
David Teiglandd2007782007-01-09 09:46:02 -0600103};
104
105enum {
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 Caulfield6ed72572007-04-17 15:39:57 +0100115 CLUSTER_ATTR_PROTOCOL,
David Teigland3ae1acf2007-05-18 08:59:31 -0500116 CLUSTER_ATTR_TIMEWARN_CS,
David Teiglandd2007782007-01-09 09:46:02 -0600117};
118
119struct cluster_attribute {
120 struct configfs_attribute attr;
David Teigland51409342008-07-31 09:31:53 -0500121 ssize_t (*show)(struct dlm_cluster *, char *);
122 ssize_t (*store)(struct dlm_cluster *, const char *, size_t);
David Teiglandd2007782007-01-09 09:46:02 -0600123};
124
David Teigland51409342008-07-31 09:31:53 -0500125static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
Harvey Harrison5416b702008-02-13 16:54:29 -0800126 int *info_field, int check_zero,
David Teiglandd2007782007-01-09 09:46:02 -0600127 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 Teiglandd2007782007-01-09 09:46:02 -0600145#define CLUSTER_ATTR(name, check_zero) \
David Teigland51409342008-07-31 09:31:53 -0500146static ssize_t name##_write(struct dlm_cluster *cl, const char *buf, size_t len) \
David Teiglandd2007782007-01-09 09:46:02 -0600147{ \
148 return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \
149 check_zero, buf, len); \
150} \
David Teigland51409342008-07-31 09:31:53 -0500151static ssize_t name##_read(struct dlm_cluster *cl, char *buf) \
David Teiglandd2007782007-01-09 09:46:02 -0600152{ \
153 return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \
154} \
155static struct cluster_attribute cluster_attr_##name = \
156__CONFIGFS_ATTR(name, 0644, name##_read, name##_write)
157
158CLUSTER_ATTR(tcp_port, 1);
159CLUSTER_ATTR(buffer_size, 1);
160CLUSTER_ATTR(rsbtbl_size, 1);
161CLUSTER_ATTR(lkbtbl_size, 1);
162CLUSTER_ATTR(dirtbl_size, 1);
163CLUSTER_ATTR(recover_timer, 1);
164CLUSTER_ATTR(toss_secs, 1);
165CLUSTER_ATTR(scan_secs, 1);
166CLUSTER_ATTR(log_debug, 0);
Patrick Caulfield6ed72572007-04-17 15:39:57 +0100167CLUSTER_ATTR(protocol, 0);
David Teigland3ae1acf2007-05-18 08:59:31 -0500168CLUSTER_ATTR(timewarn_cs, 1);
David Teiglandd2007782007-01-09 09:46:02 -0600169
170static 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 Caulfield6ed72572007-04-17 15:39:57 +0100180 [CLUSTER_ATTR_PROTOCOL] = &cluster_attr_protocol.attr,
David Teigland3ae1acf2007-05-18 08:59:31 -0500181 [CLUSTER_ATTR_TIMEWARN_CS] = &cluster_attr_timewarn_cs.attr,
David Teiglandd2007782007-01-09 09:46:02 -0600182 NULL,
183};
184
David Teiglande7fd4172006-01-18 09:30:29 +0000185enum {
186 COMM_ATTR_NODEID = 0,
187 COMM_ATTR_LOCAL,
188 COMM_ATTR_ADDR,
189};
190
191struct comm_attribute {
192 struct configfs_attribute attr;
David Teigland51409342008-07-31 09:31:53 -0500193 ssize_t (*show)(struct dlm_comm *, char *);
194 ssize_t (*store)(struct dlm_comm *, const char *, size_t);
David Teiglande7fd4172006-01-18 09:30:29 +0000195};
196
197static 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
205static 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
213static 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
220static 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
227enum {
228 NODE_ATTR_NODEID = 0,
229 NODE_ATTR_WEIGHT,
230};
231
232struct node_attribute {
233 struct configfs_attribute attr;
David Teigland51409342008-07-31 09:31:53 -0500234 ssize_t (*show)(struct dlm_node *, char *);
235 ssize_t (*store)(struct dlm_node *, const char *, size_t);
David Teiglande7fd4172006-01-18 09:30:29 +0000236};
237
238static 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
246static 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
254static 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 Teigland51409342008-07-31 09:31:53 -0500260struct dlm_clusters {
David Teiglande7fd4172006-01-18 09:30:29 +0000261 struct configfs_subsystem subsys;
262};
263
David Teigland51409342008-07-31 09:31:53 -0500264struct dlm_spaces {
David Teiglande7fd4172006-01-18 09:30:29 +0000265 struct config_group ss_group;
266};
267
David Teigland51409342008-07-31 09:31:53 -0500268struct dlm_space {
David Teiglande7fd4172006-01-18 09:30:29 +0000269 struct config_group group;
270 struct list_head members;
David Teigland90135922006-01-20 08:47:07 +0000271 struct mutex members_lock;
David Teiglande7fd4172006-01-18 09:30:29 +0000272 int members_count;
273};
274
David Teigland51409342008-07-31 09:31:53 -0500275struct dlm_comms {
David Teiglande7fd4172006-01-18 09:30:29 +0000276 struct config_group cs_group;
277};
278
David Teigland51409342008-07-31 09:31:53 -0500279struct dlm_comm {
David Teiglande7fd4172006-01-18 09:30:29 +0000280 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 Teigland51409342008-07-31 09:31:53 -0500287struct dlm_nodes {
David Teiglande7fd4172006-01-18 09:30:29 +0000288 struct config_group ns_group;
289};
290
David Teigland51409342008-07-31 09:31:53 -0500291struct dlm_node {
David Teiglande7fd4172006-01-18 09:30:29 +0000292 struct config_item item;
293 struct list_head list; /* space->members */
294 int nodeid;
295 int weight;
David Teiglandd44e0fc2008-03-18 14:22:11 -0500296 int new;
David Teiglande7fd4172006-01-18 09:30:29 +0000297};
298
299static struct configfs_group_operations clusters_ops = {
300 .make_group = make_cluster,
301 .drop_item = drop_cluster,
302};
303
304static struct configfs_item_operations cluster_ops = {
305 .release = release_cluster,
David Teiglandd2007782007-01-09 09:46:02 -0600306 .show_attribute = show_cluster,
307 .store_attribute = store_cluster,
David Teiglande7fd4172006-01-18 09:30:29 +0000308};
309
310static struct configfs_group_operations spaces_ops = {
311 .make_group = make_space,
312 .drop_item = drop_space,
313};
314
315static struct configfs_item_operations space_ops = {
316 .release = release_space,
317};
318
319static struct configfs_group_operations comms_ops = {
320 .make_item = make_comm,
321 .drop_item = drop_comm,
322};
323
324static struct configfs_item_operations comm_ops = {
325 .release = release_comm,
326 .show_attribute = show_comm,
327 .store_attribute = store_comm,
328};
329
330static struct configfs_group_operations nodes_ops = {
331 .make_item = make_node,
332 .drop_item = drop_node,
333};
334
335static struct configfs_item_operations node_ops = {
336 .release = release_node,
337 .show_attribute = show_node,
338 .store_attribute = store_node,
339};
340
341static struct config_item_type clusters_type = {
342 .ct_group_ops = &clusters_ops,
343 .ct_owner = THIS_MODULE,
344};
345
346static struct config_item_type cluster_type = {
347 .ct_item_ops = &cluster_ops,
David Teiglandd2007782007-01-09 09:46:02 -0600348 .ct_attrs = cluster_attrs,
David Teiglande7fd4172006-01-18 09:30:29 +0000349 .ct_owner = THIS_MODULE,
350};
351
352static struct config_item_type spaces_type = {
353 .ct_group_ops = &spaces_ops,
354 .ct_owner = THIS_MODULE,
355};
356
357static struct config_item_type space_type = {
358 .ct_item_ops = &space_ops,
359 .ct_owner = THIS_MODULE,
360};
361
362static struct config_item_type comms_type = {
363 .ct_group_ops = &comms_ops,
364 .ct_owner = THIS_MODULE,
365};
366
367static struct config_item_type comm_type = {
368 .ct_item_ops = &comm_ops,
369 .ct_attrs = comm_attrs,
370 .ct_owner = THIS_MODULE,
371};
372
373static struct config_item_type nodes_type = {
374 .ct_group_ops = &nodes_ops,
375 .ct_owner = THIS_MODULE,
376};
377
378static 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 Morton27eccf42008-09-05 08:42:08 -0500384static struct dlm_cluster *config_item_to_cluster(struct config_item *i)
David Teiglande7fd4172006-01-18 09:30:29 +0000385{
David Teigland51409342008-07-31 09:31:53 -0500386 return i ? container_of(to_config_group(i), struct dlm_cluster, group) :
387 NULL;
David Teiglande7fd4172006-01-18 09:30:29 +0000388}
389
Andrew Morton27eccf42008-09-05 08:42:08 -0500390static struct dlm_space *config_item_to_space(struct config_item *i)
David Teiglande7fd4172006-01-18 09:30:29 +0000391{
David Teigland51409342008-07-31 09:31:53 -0500392 return i ? container_of(to_config_group(i), struct dlm_space, group) :
393 NULL;
David Teiglande7fd4172006-01-18 09:30:29 +0000394}
395
Andrew Morton27eccf42008-09-05 08:42:08 -0500396static struct dlm_comm *config_item_to_comm(struct config_item *i)
David Teiglande7fd4172006-01-18 09:30:29 +0000397{
David Teigland51409342008-07-31 09:31:53 -0500398 return i ? container_of(i, struct dlm_comm, item) : NULL;
David Teiglande7fd4172006-01-18 09:30:29 +0000399}
400
Andrew Morton27eccf42008-09-05 08:42:08 -0500401static struct dlm_node *config_item_to_node(struct config_item *i)
David Teiglande7fd4172006-01-18 09:30:29 +0000402{
David Teigland51409342008-07-31 09:31:53 -0500403 return i ? container_of(i, struct dlm_node, item) : NULL;
David Teiglande7fd4172006-01-18 09:30:29 +0000404}
405
Joel Beckerf89ab862008-07-17 14:53:48 -0700406static struct config_group *make_cluster(struct config_group *g,
407 const char *name)
David Teiglande7fd4172006-01-18 09:30:29 +0000408{
David Teigland51409342008-07-31 09:31:53 -0500409 struct dlm_cluster *cl = NULL;
410 struct dlm_spaces *sps = NULL;
411 struct dlm_comms *cms = NULL;
David Teiglande7fd4172006-01-18 09:30:29 +0000412 void *gps = NULL;
413
David Teigland573c24c2009-11-30 16:34:43 -0600414 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 Teiglande7fd4172006-01-18 09:30:29 +0000418
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 Teiglandd2007782007-01-09 09:46:02 -0600431 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 Teigland0b7cac02007-05-29 08:47:51 -0500440 cl->cl_protocol = dlm_config.ci_protocol;
David Teigland84d8cd62007-05-29 08:44:23 -0500441 cl->cl_timewarn_cs = dlm_config.ci_timewarn_cs;
David Teiglandd2007782007-01-09 09:46:02 -0600442
David Teiglande7fd4172006-01-18 09:30:29 +0000443 space_list = &sps->ss_group;
444 comm_list = &cms->cs_group;
Joel Beckerf89ab862008-07-17 14:53:48 -0700445 return &cl->group;
David Teiglande7fd4172006-01-18 09:30:29 +0000446
447 fail:
448 kfree(cl);
449 kfree(gps);
450 kfree(sps);
451 kfree(cms);
Joel Beckera6795e92008-07-17 15:21:29 -0700452 return ERR_PTR(-ENOMEM);
David Teiglande7fd4172006-01-18 09:30:29 +0000453}
454
455static void drop_cluster(struct config_group *g, struct config_item *i)
456{
Andrew Morton27eccf42008-09-05 08:42:08 -0500457 struct dlm_cluster *cl = config_item_to_cluster(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000458 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
473static void release_cluster(struct config_item *i)
474{
Andrew Morton27eccf42008-09-05 08:42:08 -0500475 struct dlm_cluster *cl = config_item_to_cluster(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000476 kfree(cl->group.default_groups);
477 kfree(cl);
478}
479
Joel Beckerf89ab862008-07-17 14:53:48 -0700480static struct config_group *make_space(struct config_group *g, const char *name)
David Teiglande7fd4172006-01-18 09:30:29 +0000481{
David Teigland51409342008-07-31 09:31:53 -0500482 struct dlm_space *sp = NULL;
483 struct dlm_nodes *nds = NULL;
David Teiglande7fd4172006-01-18 09:30:29 +0000484 void *gps = NULL;
485
David Teigland573c24c2009-11-30 16:34:43 -0600486 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 Teiglande7fd4172006-01-18 09:30:29 +0000489
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 Teigland90135922006-01-20 08:47:07 +0000501 mutex_init(&sp->members_lock);
David Teiglande7fd4172006-01-18 09:30:29 +0000502 sp->members_count = 0;
Joel Beckerf89ab862008-07-17 14:53:48 -0700503 return &sp->group;
David Teiglande7fd4172006-01-18 09:30:29 +0000504
505 fail:
506 kfree(sp);
507 kfree(gps);
508 kfree(nds);
Joel Beckera6795e92008-07-17 15:21:29 -0700509 return ERR_PTR(-ENOMEM);
David Teiglande7fd4172006-01-18 09:30:29 +0000510}
511
512static void drop_space(struct config_group *g, struct config_item *i)
513{
Andrew Morton27eccf42008-09-05 08:42:08 -0500514 struct dlm_space *sp = config_item_to_space(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000515 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
529static void release_space(struct config_item *i)
530{
Andrew Morton27eccf42008-09-05 08:42:08 -0500531 struct dlm_space *sp = config_item_to_space(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000532 kfree(sp->group.default_groups);
533 kfree(sp);
534}
535
Joel Beckerf89ab862008-07-17 14:53:48 -0700536static struct config_item *make_comm(struct config_group *g, const char *name)
David Teiglande7fd4172006-01-18 09:30:29 +0000537{
David Teigland51409342008-07-31 09:31:53 -0500538 struct dlm_comm *cm;
David Teiglande7fd4172006-01-18 09:30:29 +0000539
David Teigland573c24c2009-11-30 16:34:43 -0600540 cm = kzalloc(sizeof(struct dlm_comm), GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +0000541 if (!cm)
Joel Beckera6795e92008-07-17 15:21:29 -0700542 return ERR_PTR(-ENOMEM);
David Teiglande7fd4172006-01-18 09:30:29 +0000543
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 Beckerf89ab862008-07-17 14:53:48 -0700548 return &cm->item;
David Teiglande7fd4172006-01-18 09:30:29 +0000549}
550
551static void drop_comm(struct config_group *g, struct config_item *i)
552{
Andrew Morton27eccf42008-09-05 08:42:08 -0500553 struct dlm_comm *cm = config_item_to_comm(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000554 if (local_comm == cm)
555 local_comm = NULL;
David Teigland1c032c02006-04-28 10:50:41 -0400556 dlm_lowcomms_close(cm->nodeid);
David Teiglande7fd4172006-01-18 09:30:29 +0000557 while (cm->addr_count--)
558 kfree(cm->addr[cm->addr_count]);
559 config_item_put(i);
560}
561
562static void release_comm(struct config_item *i)
563{
Andrew Morton27eccf42008-09-05 08:42:08 -0500564 struct dlm_comm *cm = config_item_to_comm(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000565 kfree(cm);
566}
567
Joel Beckerf89ab862008-07-17 14:53:48 -0700568static struct config_item *make_node(struct config_group *g, const char *name)
David Teiglande7fd4172006-01-18 09:30:29 +0000569{
Andrew Morton27eccf42008-09-05 08:42:08 -0500570 struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent);
David Teigland51409342008-07-31 09:31:53 -0500571 struct dlm_node *nd;
David Teiglande7fd4172006-01-18 09:30:29 +0000572
David Teigland573c24c2009-11-30 16:34:43 -0600573 nd = kzalloc(sizeof(struct dlm_node), GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +0000574 if (!nd)
Joel Beckera6795e92008-07-17 15:21:29 -0700575 return ERR_PTR(-ENOMEM);
David Teiglande7fd4172006-01-18 09:30:29 +0000576
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 Teiglandd44e0fc2008-03-18 14:22:11 -0500580 nd->new = 1; /* set to 0 once it's been read by dlm_nodeid_list() */
David Teiglande7fd4172006-01-18 09:30:29 +0000581
David Teigland90135922006-01-20 08:47:07 +0000582 mutex_lock(&sp->members_lock);
David Teiglande7fd4172006-01-18 09:30:29 +0000583 list_add(&nd->list, &sp->members);
584 sp->members_count++;
David Teigland90135922006-01-20 08:47:07 +0000585 mutex_unlock(&sp->members_lock);
David Teiglande7fd4172006-01-18 09:30:29 +0000586
Joel Beckerf89ab862008-07-17 14:53:48 -0700587 return &nd->item;
David Teiglande7fd4172006-01-18 09:30:29 +0000588}
589
590static void drop_node(struct config_group *g, struct config_item *i)
591{
Andrew Morton27eccf42008-09-05 08:42:08 -0500592 struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent);
593 struct dlm_node *nd = config_item_to_node(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000594
David Teigland90135922006-01-20 08:47:07 +0000595 mutex_lock(&sp->members_lock);
David Teiglande7fd4172006-01-18 09:30:29 +0000596 list_del(&nd->list);
597 sp->members_count--;
David Teigland90135922006-01-20 08:47:07 +0000598 mutex_unlock(&sp->members_lock);
David Teiglande7fd4172006-01-18 09:30:29 +0000599
600 config_item_put(i);
601}
602
603static void release_node(struct config_item *i)
604{
Andrew Morton27eccf42008-09-05 08:42:08 -0500605 struct dlm_node *nd = config_item_to_node(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000606 kfree(nd);
607}
608
David Teigland51409342008-07-31 09:31:53 -0500609static struct dlm_clusters clusters_root = {
David Teiglande7fd4172006-01-18 09:30:29 +0000610 .subsys = {
611 .su_group = {
612 .cg_item = {
613 .ci_namebuf = "dlm",
614 .ci_type = &clusters_type,
615 },
616 },
617 },
618};
619
Denis Cheng30727172008-02-02 01:53:46 +0800620int __init dlm_config_init(void)
David Teiglande7fd4172006-01-18 09:30:29 +0000621{
622 config_group_init(&clusters_root.subsys.su_group);
Joel Beckere6bd07a2007-07-06 23:33:17 -0700623 mutex_init(&clusters_root.subsys.su_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000624 return configfs_register_subsystem(&clusters_root.subsys);
625}
626
627void 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 Teiglandd2007782007-01-09 09:46:02 -0600636static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a,
637 char *buf)
638{
Andrew Morton27eccf42008-09-05 08:42:08 -0500639 struct dlm_cluster *cl = config_item_to_cluster(i);
David Teiglandd2007782007-01-09 09:46:02 -0600640 struct cluster_attribute *cla =
641 container_of(a, struct cluster_attribute, attr);
642 return cla->show ? cla->show(cl, buf) : 0;
643}
644
645static ssize_t store_cluster(struct config_item *i,
646 struct configfs_attribute *a,
647 const char *buf, size_t len)
648{
Andrew Morton27eccf42008-09-05 08:42:08 -0500649 struct dlm_cluster *cl = config_item_to_cluster(i);
David Teiglandd2007782007-01-09 09:46:02 -0600650 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 Teiglande7fd4172006-01-18 09:30:29 +0000655static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
656 char *buf)
657{
Andrew Morton27eccf42008-09-05 08:42:08 -0500658 struct dlm_comm *cm = config_item_to_comm(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000659 struct comm_attribute *cma =
660 container_of(a, struct comm_attribute, attr);
661 return cma->show ? cma->show(cm, buf) : 0;
662}
663
664static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
665 const char *buf, size_t len)
666{
Andrew Morton27eccf42008-09-05 08:42:08 -0500667 struct dlm_comm *cm = config_item_to_comm(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000668 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 Teigland51409342008-07-31 09:31:53 -0500673static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf)
David Teiglande7fd4172006-01-18 09:30:29 +0000674{
675 return sprintf(buf, "%d\n", cm->nodeid);
676}
677
David Teigland51409342008-07-31 09:31:53 -0500678static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf,
679 size_t len)
David Teiglande7fd4172006-01-18 09:30:29 +0000680{
681 cm->nodeid = simple_strtol(buf, NULL, 0);
682 return len;
683}
684
David Teigland51409342008-07-31 09:31:53 -0500685static ssize_t comm_local_read(struct dlm_comm *cm, char *buf)
David Teiglande7fd4172006-01-18 09:30:29 +0000686{
687 return sprintf(buf, "%d\n", cm->local);
688}
689
David Teigland51409342008-07-31 09:31:53 -0500690static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
691 size_t len)
David Teiglande7fd4172006-01-18 09:30:29 +0000692{
693 cm->local= simple_strtol(buf, NULL, 0);
694 if (cm->local && !local_comm)
695 local_comm = cm;
696 return len;
697}
698
David Teigland51409342008-07-31 09:31:53 -0500699static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len)
David Teiglande7fd4172006-01-18 09:30:29 +0000700{
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 Teigland573c24c2009-11-30 16:34:43 -0600709 addr = kzalloc(sizeof(*addr), GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +0000710 if (!addr)
711 return -ENOMEM;
712
713 memcpy(addr, buf, len);
714 cm->addr[cm->addr_count++] = addr;
715 return len;
716}
717
718static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
719 char *buf)
720{
Andrew Morton27eccf42008-09-05 08:42:08 -0500721 struct dlm_node *nd = config_item_to_node(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000722 struct node_attribute *nda =
723 container_of(a, struct node_attribute, attr);
724 return nda->show ? nda->show(nd, buf) : 0;
725}
726
727static ssize_t store_node(struct config_item *i, struct configfs_attribute *a,
728 const char *buf, size_t len)
729{
Andrew Morton27eccf42008-09-05 08:42:08 -0500730 struct dlm_node *nd = config_item_to_node(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000731 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 Teigland51409342008-07-31 09:31:53 -0500736static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf)
David Teiglande7fd4172006-01-18 09:30:29 +0000737{
738 return sprintf(buf, "%d\n", nd->nodeid);
739}
740
David Teigland51409342008-07-31 09:31:53 -0500741static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
742 size_t len)
David Teiglande7fd4172006-01-18 09:30:29 +0000743{
744 nd->nodeid = simple_strtol(buf, NULL, 0);
745 return len;
746}
747
David Teigland51409342008-07-31 09:31:53 -0500748static ssize_t node_weight_read(struct dlm_node *nd, char *buf)
David Teiglande7fd4172006-01-18 09:30:29 +0000749{
750 return sprintf(buf, "%d\n", nd->weight);
751}
752
David Teigland51409342008-07-31 09:31:53 -0500753static ssize_t node_weight_write(struct dlm_node *nd, const char *buf,
754 size_t len)
David Teiglande7fd4172006-01-18 09:30:29 +0000755{
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 Teigland51409342008-07-31 09:31:53 -0500764static struct dlm_space *get_space(char *name)
David Teiglande7fd4172006-01-18 09:30:29 +0000765{
Satyam Sharma3168b072007-05-08 09:18:58 +0100766 struct config_item *i;
767
David Teiglande7fd4172006-01-18 09:30:29 +0000768 if (!space_list)
769 return NULL;
Satyam Sharma3168b072007-05-08 09:18:58 +0100770
Joel Beckere6bd07a2007-07-06 23:33:17 -0700771 mutex_lock(&space_list->cg_subsys->su_mutex);
Satyam Sharma3fe6c5c2007-07-04 16:37:16 +0530772 i = config_group_find_item(space_list, name);
Joel Beckere6bd07a2007-07-06 23:33:17 -0700773 mutex_unlock(&space_list->cg_subsys->su_mutex);
Satyam Sharma3168b072007-05-08 09:18:58 +0100774
Andrew Morton27eccf42008-09-05 08:42:08 -0500775 return config_item_to_space(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000776}
777
David Teigland51409342008-07-31 09:31:53 -0500778static void put_space(struct dlm_space *sp)
David Teiglande7fd4172006-01-18 09:30:29 +0000779{
780 config_item_put(&sp->group.cg_item);
781}
782
David Teigland44be6fd2008-08-28 11:36:19 -0500783static 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 Teigland51409342008-07-31 09:31:53 -0500810static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr)
David Teiglande7fd4172006-01-18 09:30:29 +0000811{
812 struct config_item *i;
David Teigland51409342008-07-31 09:31:53 -0500813 struct dlm_comm *cm = NULL;
David Teiglande7fd4172006-01-18 09:30:29 +0000814 int found = 0;
815
816 if (!comm_list)
817 return NULL;
818
Joel Beckere6bd07a2007-07-06 23:33:17 -0700819 mutex_lock(&clusters_root.subsys.su_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000820
821 list_for_each_entry(i, &comm_list->cg_children, ci_entry) {
Andrew Morton27eccf42008-09-05 08:42:08 -0500822 cm = config_item_to_comm(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000823
824 if (nodeid) {
825 if (cm->nodeid != nodeid)
826 continue;
827 found = 1;
Satyam Sharma3168b072007-05-08 09:18:58 +0100828 config_item_get(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000829 break;
830 } else {
David Teigland44be6fd2008-08-28 11:36:19 -0500831 if (!cm->addr_count || !addr_compare(cm->addr[0], addr))
David Teiglande7fd4172006-01-18 09:30:29 +0000832 continue;
833 found = 1;
Satyam Sharma3168b072007-05-08 09:18:58 +0100834 config_item_get(i);
David Teiglande7fd4172006-01-18 09:30:29 +0000835 break;
836 }
837 }
Joel Beckere6bd07a2007-07-06 23:33:17 -0700838 mutex_unlock(&clusters_root.subsys.su_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000839
Satyam Sharma3168b072007-05-08 09:18:58 +0100840 if (!found)
David Teiglande7fd4172006-01-18 09:30:29 +0000841 cm = NULL;
842 return cm;
843}
844
David Teigland51409342008-07-31 09:31:53 -0500845static void put_comm(struct dlm_comm *cm)
David Teiglande7fd4172006-01-18 09:30:29 +0000846{
847 config_item_put(&cm->item);
848}
849
850/* caller must free mem */
David Teiglandd44e0fc2008-03-18 14:22:11 -0500851int dlm_nodeid_list(char *lsname, int **ids_out, int *ids_count_out,
852 int **new_out, int *new_count_out)
David Teiglande7fd4172006-01-18 09:30:29 +0000853{
David Teigland51409342008-07-31 09:31:53 -0500854 struct dlm_space *sp;
855 struct dlm_node *nd;
David Teiglandd44e0fc2008-03-18 14:22:11 -0500856 int i = 0, rv = 0, ids_count = 0, new_count = 0;
857 int *ids, *new;
David Teiglande7fd4172006-01-18 09:30:29 +0000858
859 sp = get_space(lsname);
860 if (!sp)
861 return -EEXIST;
862
David Teigland90135922006-01-20 08:47:07 +0000863 mutex_lock(&sp->members_lock);
David Teiglande7fd4172006-01-18 09:30:29 +0000864 if (!sp->members_count) {
David Teiglandd44e0fc2008-03-18 14:22:11 -0500865 rv = -EINVAL;
866 printk(KERN_ERR "dlm: zero members_count\n");
David Teiglande7fd4172006-01-18 09:30:29 +0000867 goto out;
868 }
869
David Teiglandd44e0fc2008-03-18 14:22:11 -0500870 ids_count = sp->members_count;
871
David Teigland573c24c2009-11-30 16:34:43 -0600872 ids = kcalloc(ids_count, sizeof(int), GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +0000873 if (!ids) {
874 rv = -ENOMEM;
875 goto out;
876 }
877
David Teiglandd44e0fc2008-03-18 14:22:11 -0500878 list_for_each_entry(nd, &sp->members, list) {
David Teiglande7fd4172006-01-18 09:30:29 +0000879 ids[i++] = nd->nodeid;
David Teiglandd44e0fc2008-03-18 14:22:11 -0500880 if (nd->new)
881 new_count++;
882 }
David Teiglande7fd4172006-01-18 09:30:29 +0000883
David Teiglandd44e0fc2008-03-18 14:22:11 -0500884 if (ids_count != i)
885 printk(KERN_ERR "dlm: bad nodeid count %d %d\n", ids_count, i);
David Teiglande7fd4172006-01-18 09:30:29 +0000886
David Teiglandd44e0fc2008-03-18 14:22:11 -0500887 if (!new_count)
888 goto out_ids;
889
David Teigland573c24c2009-11-30 16:34:43 -0600890 new = kcalloc(new_count, sizeof(int), GFP_NOFS);
David Teiglandd44e0fc2008-03-18 14:22:11 -0500891 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 Teiglande7fd4172006-01-18 09:30:29 +0000909 *ids_out = ids;
910 out:
David Teigland90135922006-01-20 08:47:07 +0000911 mutex_unlock(&sp->members_lock);
David Teiglande7fd4172006-01-18 09:30:29 +0000912 put_space(sp);
913 return rv;
914}
915
916int dlm_node_weight(char *lsname, int nodeid)
917{
David Teigland51409342008-07-31 09:31:53 -0500918 struct dlm_space *sp;
919 struct dlm_node *nd;
David Teiglande7fd4172006-01-18 09:30:29 +0000920 int w = -EEXIST;
921
922 sp = get_space(lsname);
923 if (!sp)
924 goto out;
925
David Teigland90135922006-01-20 08:47:07 +0000926 mutex_lock(&sp->members_lock);
David Teiglande7fd4172006-01-18 09:30:29 +0000927 list_for_each_entry(nd, &sp->members, list) {
928 if (nd->nodeid != nodeid)
929 continue;
930 w = nd->weight;
931 break;
932 }
David Teigland90135922006-01-20 08:47:07 +0000933 mutex_unlock(&sp->members_lock);
David Teiglande7fd4172006-01-18 09:30:29 +0000934 put_space(sp);
935 out:
936 return w;
937}
938
939int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr)
940{
David Teigland51409342008-07-31 09:31:53 -0500941 struct dlm_comm *cm = get_comm(nodeid, NULL);
David Teiglande7fd4172006-01-18 09:30:29 +0000942 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
951int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid)
952{
David Teigland51409342008-07-31 09:31:53 -0500953 struct dlm_comm *cm = get_comm(0, addr);
David Teiglande7fd4172006-01-18 09:30:29 +0000954 if (!cm)
955 return -EEXIST;
956 *nodeid = cm->nodeid;
957 put_comm(cm);
958 return 0;
959}
960
961int 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 */
967int 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 Teigland99fc6482007-01-09 09:44:01 -0600986#define DEFAULT_LOG_DEBUG 0
Patrick Caulfield6ed72572007-04-17 15:39:57 +0100987#define DEFAULT_PROTOCOL 0
David Teigland3ae1acf2007-05-18 08:59:31 -0500988#define DEFAULT_TIMEWARN_CS 500 /* 5 sec = 500 centiseconds */
David Teiglande7fd4172006-01-18 09:30:29 +0000989
990struct dlm_config_info dlm_config = {
David Teigland68c817a2007-01-09 09:41:48 -0600991 .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 Teigland99fc6482007-01-09 09:44:01 -0600998 .ci_scan_secs = DEFAULT_SCAN_SECS,
Patrick Caulfield6ed72572007-04-17 15:39:57 +0100999 .ci_log_debug = DEFAULT_LOG_DEBUG,
David Teigland3ae1acf2007-05-18 08:59:31 -05001000 .ci_protocol = DEFAULT_PROTOCOL,
1001 .ci_timewarn_cs = DEFAULT_TIMEWARN_CS
David Teiglande7fd4172006-01-18 09:30:29 +00001002};
1003