1 /******************************************************************************
2 *******************************************************************************
4 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5 ** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
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.
11 *******************************************************************************
12 ******************************************************************************/
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/configfs.h>
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.
31 static struct config_group
*space_list
;
32 static struct config_group
*comm_list
;
33 static struct comm
*local_comm
;
44 static struct config_group
*make_cluster(struct config_group
*, const char *);
45 static void drop_cluster(struct config_group
*, struct config_item
*);
46 static void release_cluster(struct config_item
*);
47 static struct config_group
*make_space(struct config_group
*, const char *);
48 static void drop_space(struct config_group
*, struct config_item
*);
49 static void release_space(struct config_item
*);
50 static struct config_item
*make_comm(struct config_group
*, const char *);
51 static void drop_comm(struct config_group
*, struct config_item
*);
52 static void release_comm(struct config_item
*);
53 static struct config_item
*make_node(struct config_group
*, const char *);
54 static void drop_node(struct config_group
*, struct config_item
*);
55 static void release_node(struct config_item
*);
57 static ssize_t
show_cluster(struct config_item
*i
, struct configfs_attribute
*a
,
59 static ssize_t
store_cluster(struct config_item
*i
,
60 struct configfs_attribute
*a
,
61 const char *buf
, size_t len
);
62 static ssize_t
show_comm(struct config_item
*i
, struct configfs_attribute
*a
,
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
,
68 static ssize_t
store_node(struct config_item
*i
, struct configfs_attribute
*a
,
69 const char *buf
, size_t len
);
71 static ssize_t
comm_nodeid_read(struct comm
*cm
, char *buf
);
72 static ssize_t
comm_nodeid_write(struct comm
*cm
, const char *buf
, size_t len
);
73 static ssize_t
comm_local_read(struct comm
*cm
, char *buf
);
74 static ssize_t
comm_local_write(struct comm
*cm
, const char *buf
, size_t len
);
75 static ssize_t
comm_addr_write(struct comm
*cm
, const char *buf
, size_t len
);
76 static ssize_t
node_nodeid_read(struct node
*nd
, char *buf
);
77 static ssize_t
node_nodeid_write(struct node
*nd
, const char *buf
, size_t len
);
78 static ssize_t
node_weight_read(struct node
*nd
, char *buf
);
79 static ssize_t
node_weight_write(struct node
*nd
, const char *buf
, size_t len
);
82 struct config_group group
;
83 unsigned int cl_tcp_port
;
84 unsigned int cl_buffer_size
;
85 unsigned int cl_rsbtbl_size
;
86 unsigned int cl_lkbtbl_size
;
87 unsigned int cl_dirtbl_size
;
88 unsigned int cl_recover_timer
;
89 unsigned int cl_toss_secs
;
90 unsigned int cl_scan_secs
;
91 unsigned int cl_log_debug
;
92 unsigned int cl_protocol
;
93 unsigned int cl_timewarn_cs
;
97 CLUSTER_ATTR_TCP_PORT
= 0,
98 CLUSTER_ATTR_BUFFER_SIZE
,
99 CLUSTER_ATTR_RSBTBL_SIZE
,
100 CLUSTER_ATTR_LKBTBL_SIZE
,
101 CLUSTER_ATTR_DIRTBL_SIZE
,
102 CLUSTER_ATTR_RECOVER_TIMER
,
103 CLUSTER_ATTR_TOSS_SECS
,
104 CLUSTER_ATTR_SCAN_SECS
,
105 CLUSTER_ATTR_LOG_DEBUG
,
106 CLUSTER_ATTR_PROTOCOL
,
107 CLUSTER_ATTR_TIMEWARN_CS
,
110 struct cluster_attribute
{
111 struct configfs_attribute attr
;
112 ssize_t (*show
)(struct cluster
*, char *);
113 ssize_t (*store
)(struct cluster
*, const char *, size_t);
116 static ssize_t
cluster_set(struct cluster
*cl
, unsigned int *cl_field
,
117 unsigned int *info_field
, int check_zero
,
118 const char *buf
, size_t len
)
122 if (!capable(CAP_SYS_ADMIN
))
125 x
= simple_strtoul(buf
, NULL
, 0);
127 if (check_zero
&& !x
)
136 #define CLUSTER_ATTR(name, check_zero) \
137 static ssize_t name##_write(struct cluster *cl, const char *buf, size_t len) \
139 return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \
140 check_zero, buf, len); \
142 static ssize_t name##_read(struct cluster *cl, char *buf) \
144 return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \
146 static struct cluster_attribute cluster_attr_##name = \
147 __CONFIGFS_ATTR(name, 0644, name##_read, name##_write)
149 CLUSTER_ATTR(tcp_port
, 1);
150 CLUSTER_ATTR(buffer_size
, 1);
151 CLUSTER_ATTR(rsbtbl_size
, 1);
152 CLUSTER_ATTR(lkbtbl_size
, 1);
153 CLUSTER_ATTR(dirtbl_size
, 1);
154 CLUSTER_ATTR(recover_timer
, 1);
155 CLUSTER_ATTR(toss_secs
, 1);
156 CLUSTER_ATTR(scan_secs
, 1);
157 CLUSTER_ATTR(log_debug
, 0);
158 CLUSTER_ATTR(protocol
, 0);
159 CLUSTER_ATTR(timewarn_cs
, 1);
161 static struct configfs_attribute
*cluster_attrs
[] = {
162 [CLUSTER_ATTR_TCP_PORT
] = &cluster_attr_tcp_port
.attr
,
163 [CLUSTER_ATTR_BUFFER_SIZE
] = &cluster_attr_buffer_size
.attr
,
164 [CLUSTER_ATTR_RSBTBL_SIZE
] = &cluster_attr_rsbtbl_size
.attr
,
165 [CLUSTER_ATTR_LKBTBL_SIZE
] = &cluster_attr_lkbtbl_size
.attr
,
166 [CLUSTER_ATTR_DIRTBL_SIZE
] = &cluster_attr_dirtbl_size
.attr
,
167 [CLUSTER_ATTR_RECOVER_TIMER
] = &cluster_attr_recover_timer
.attr
,
168 [CLUSTER_ATTR_TOSS_SECS
] = &cluster_attr_toss_secs
.attr
,
169 [CLUSTER_ATTR_SCAN_SECS
] = &cluster_attr_scan_secs
.attr
,
170 [CLUSTER_ATTR_LOG_DEBUG
] = &cluster_attr_log_debug
.attr
,
171 [CLUSTER_ATTR_PROTOCOL
] = &cluster_attr_protocol
.attr
,
172 [CLUSTER_ATTR_TIMEWARN_CS
] = &cluster_attr_timewarn_cs
.attr
,
177 COMM_ATTR_NODEID
= 0,
182 struct comm_attribute
{
183 struct configfs_attribute attr
;
184 ssize_t (*show
)(struct comm
*, char *);
185 ssize_t (*store
)(struct comm
*, const char *, size_t);
188 static struct comm_attribute comm_attr_nodeid
= {
189 .attr
= { .ca_owner
= THIS_MODULE
,
191 .ca_mode
= S_IRUGO
| S_IWUSR
},
192 .show
= comm_nodeid_read
,
193 .store
= comm_nodeid_write
,
196 static struct comm_attribute comm_attr_local
= {
197 .attr
= { .ca_owner
= THIS_MODULE
,
199 .ca_mode
= S_IRUGO
| S_IWUSR
},
200 .show
= comm_local_read
,
201 .store
= comm_local_write
,
204 static struct comm_attribute comm_attr_addr
= {
205 .attr
= { .ca_owner
= THIS_MODULE
,
207 .ca_mode
= S_IRUGO
| S_IWUSR
},
208 .store
= comm_addr_write
,
211 static struct configfs_attribute
*comm_attrs
[] = {
212 [COMM_ATTR_NODEID
] = &comm_attr_nodeid
.attr
,
213 [COMM_ATTR_LOCAL
] = &comm_attr_local
.attr
,
214 [COMM_ATTR_ADDR
] = &comm_attr_addr
.attr
,
219 NODE_ATTR_NODEID
= 0,
223 struct node_attribute
{
224 struct configfs_attribute attr
;
225 ssize_t (*show
)(struct node
*, char *);
226 ssize_t (*store
)(struct node
*, const char *, size_t);
229 static struct node_attribute node_attr_nodeid
= {
230 .attr
= { .ca_owner
= THIS_MODULE
,
232 .ca_mode
= S_IRUGO
| S_IWUSR
},
233 .show
= node_nodeid_read
,
234 .store
= node_nodeid_write
,
237 static struct node_attribute node_attr_weight
= {
238 .attr
= { .ca_owner
= THIS_MODULE
,
240 .ca_mode
= S_IRUGO
| S_IWUSR
},
241 .show
= node_weight_read
,
242 .store
= node_weight_write
,
245 static struct configfs_attribute
*node_attrs
[] = {
246 [NODE_ATTR_NODEID
] = &node_attr_nodeid
.attr
,
247 [NODE_ATTR_WEIGHT
] = &node_attr_weight
.attr
,
252 struct configfs_subsystem subsys
;
256 struct config_group ss_group
;
260 struct config_group group
;
261 struct list_head members
;
262 struct mutex members_lock
;
267 struct config_group cs_group
;
271 struct config_item item
;
275 struct sockaddr_storage
*addr
[DLM_MAX_ADDR_COUNT
];
279 struct config_group ns_group
;
283 struct config_item item
;
284 struct list_head list
; /* space->members */
289 static struct configfs_group_operations clusters_ops
= {
290 .make_group
= make_cluster
,
291 .drop_item
= drop_cluster
,
294 static struct configfs_item_operations cluster_ops
= {
295 .release
= release_cluster
,
296 .show_attribute
= show_cluster
,
297 .store_attribute
= store_cluster
,
300 static struct configfs_group_operations spaces_ops
= {
301 .make_group
= make_space
,
302 .drop_item
= drop_space
,
305 static struct configfs_item_operations space_ops
= {
306 .release
= release_space
,
309 static struct configfs_group_operations comms_ops
= {
310 .make_item
= make_comm
,
311 .drop_item
= drop_comm
,
314 static struct configfs_item_operations comm_ops
= {
315 .release
= release_comm
,
316 .show_attribute
= show_comm
,
317 .store_attribute
= store_comm
,
320 static struct configfs_group_operations nodes_ops
= {
321 .make_item
= make_node
,
322 .drop_item
= drop_node
,
325 static struct configfs_item_operations node_ops
= {
326 .release
= release_node
,
327 .show_attribute
= show_node
,
328 .store_attribute
= store_node
,
331 static struct config_item_type clusters_type
= {
332 .ct_group_ops
= &clusters_ops
,
333 .ct_owner
= THIS_MODULE
,
336 static struct config_item_type cluster_type
= {
337 .ct_item_ops
= &cluster_ops
,
338 .ct_attrs
= cluster_attrs
,
339 .ct_owner
= THIS_MODULE
,
342 static struct config_item_type spaces_type
= {
343 .ct_group_ops
= &spaces_ops
,
344 .ct_owner
= THIS_MODULE
,
347 static struct config_item_type space_type
= {
348 .ct_item_ops
= &space_ops
,
349 .ct_owner
= THIS_MODULE
,
352 static struct config_item_type comms_type
= {
353 .ct_group_ops
= &comms_ops
,
354 .ct_owner
= THIS_MODULE
,
357 static struct config_item_type comm_type
= {
358 .ct_item_ops
= &comm_ops
,
359 .ct_attrs
= comm_attrs
,
360 .ct_owner
= THIS_MODULE
,
363 static struct config_item_type nodes_type
= {
364 .ct_group_ops
= &nodes_ops
,
365 .ct_owner
= THIS_MODULE
,
368 static struct config_item_type node_type
= {
369 .ct_item_ops
= &node_ops
,
370 .ct_attrs
= node_attrs
,
371 .ct_owner
= THIS_MODULE
,
374 static struct cluster
*to_cluster(struct config_item
*i
)
376 return i
? container_of(to_config_group(i
), struct cluster
, group
):NULL
;
379 static struct space
*to_space(struct config_item
*i
)
381 return i
? container_of(to_config_group(i
), struct space
, group
) : NULL
;
384 static struct comm
*to_comm(struct config_item
*i
)
386 return i
? container_of(i
, struct comm
, item
) : NULL
;
389 static struct node
*to_node(struct config_item
*i
)
391 return i
? container_of(i
, struct node
, item
) : NULL
;
394 static struct config_group
*make_cluster(struct config_group
*g
,
397 struct cluster
*cl
= NULL
;
398 struct spaces
*sps
= NULL
;
399 struct comms
*cms
= NULL
;
402 cl
= kzalloc(sizeof(struct cluster
), GFP_KERNEL
);
403 gps
= kcalloc(3, sizeof(struct config_group
*), GFP_KERNEL
);
404 sps
= kzalloc(sizeof(struct spaces
), GFP_KERNEL
);
405 cms
= kzalloc(sizeof(struct comms
), GFP_KERNEL
);
407 if (!cl
|| !gps
|| !sps
|| !cms
)
410 config_group_init_type_name(&cl
->group
, name
, &cluster_type
);
411 config_group_init_type_name(&sps
->ss_group
, "spaces", &spaces_type
);
412 config_group_init_type_name(&cms
->cs_group
, "comms", &comms_type
);
414 cl
->group
.default_groups
= gps
;
415 cl
->group
.default_groups
[0] = &sps
->ss_group
;
416 cl
->group
.default_groups
[1] = &cms
->cs_group
;
417 cl
->group
.default_groups
[2] = NULL
;
419 cl
->cl_tcp_port
= dlm_config
.ci_tcp_port
;
420 cl
->cl_buffer_size
= dlm_config
.ci_buffer_size
;
421 cl
->cl_rsbtbl_size
= dlm_config
.ci_rsbtbl_size
;
422 cl
->cl_lkbtbl_size
= dlm_config
.ci_lkbtbl_size
;
423 cl
->cl_dirtbl_size
= dlm_config
.ci_dirtbl_size
;
424 cl
->cl_recover_timer
= dlm_config
.ci_recover_timer
;
425 cl
->cl_toss_secs
= dlm_config
.ci_toss_secs
;
426 cl
->cl_scan_secs
= dlm_config
.ci_scan_secs
;
427 cl
->cl_log_debug
= dlm_config
.ci_log_debug
;
428 cl
->cl_protocol
= dlm_config
.ci_protocol
;
429 cl
->cl_timewarn_cs
= dlm_config
.ci_timewarn_cs
;
431 space_list
= &sps
->ss_group
;
432 comm_list
= &cms
->cs_group
;
443 static void drop_cluster(struct config_group
*g
, struct config_item
*i
)
445 struct cluster
*cl
= to_cluster(i
);
446 struct config_item
*tmp
;
449 for (j
= 0; cl
->group
.default_groups
[j
]; j
++) {
450 tmp
= &cl
->group
.default_groups
[j
]->cg_item
;
451 cl
->group
.default_groups
[j
] = NULL
;
452 config_item_put(tmp
);
461 static void release_cluster(struct config_item
*i
)
463 struct cluster
*cl
= to_cluster(i
);
464 kfree(cl
->group
.default_groups
);
468 static struct config_group
*make_space(struct config_group
*g
, const char *name
)
470 struct space
*sp
= NULL
;
471 struct nodes
*nds
= NULL
;
474 sp
= kzalloc(sizeof(struct space
), GFP_KERNEL
);
475 gps
= kcalloc(2, sizeof(struct config_group
*), GFP_KERNEL
);
476 nds
= kzalloc(sizeof(struct nodes
), GFP_KERNEL
);
478 if (!sp
|| !gps
|| !nds
)
481 config_group_init_type_name(&sp
->group
, name
, &space_type
);
482 config_group_init_type_name(&nds
->ns_group
, "nodes", &nodes_type
);
484 sp
->group
.default_groups
= gps
;
485 sp
->group
.default_groups
[0] = &nds
->ns_group
;
486 sp
->group
.default_groups
[1] = NULL
;
488 INIT_LIST_HEAD(&sp
->members
);
489 mutex_init(&sp
->members_lock
);
490 sp
->members_count
= 0;
500 static void drop_space(struct config_group
*g
, struct config_item
*i
)
502 struct space
*sp
= to_space(i
);
503 struct config_item
*tmp
;
506 /* assert list_empty(&sp->members) */
508 for (j
= 0; sp
->group
.default_groups
[j
]; j
++) {
509 tmp
= &sp
->group
.default_groups
[j
]->cg_item
;
510 sp
->group
.default_groups
[j
] = NULL
;
511 config_item_put(tmp
);
517 static void release_space(struct config_item
*i
)
519 struct space
*sp
= to_space(i
);
520 kfree(sp
->group
.default_groups
);
524 static struct config_item
*make_comm(struct config_group
*g
, const char *name
)
528 cm
= kzalloc(sizeof(struct comm
), GFP_KERNEL
);
532 config_item_init_type_name(&cm
->item
, name
, &comm_type
);
539 static void drop_comm(struct config_group
*g
, struct config_item
*i
)
541 struct comm
*cm
= to_comm(i
);
542 if (local_comm
== cm
)
544 dlm_lowcomms_close(cm
->nodeid
);
545 while (cm
->addr_count
--)
546 kfree(cm
->addr
[cm
->addr_count
]);
550 static void release_comm(struct config_item
*i
)
552 struct comm
*cm
= to_comm(i
);
556 static struct config_item
*make_node(struct config_group
*g
, const char *name
)
558 struct space
*sp
= to_space(g
->cg_item
.ci_parent
);
561 nd
= kzalloc(sizeof(struct node
), GFP_KERNEL
);
565 config_item_init_type_name(&nd
->item
, name
, &node_type
);
567 nd
->weight
= 1; /* default weight of 1 if none is set */
569 mutex_lock(&sp
->members_lock
);
570 list_add(&nd
->list
, &sp
->members
);
572 mutex_unlock(&sp
->members_lock
);
577 static void drop_node(struct config_group
*g
, struct config_item
*i
)
579 struct space
*sp
= to_space(g
->cg_item
.ci_parent
);
580 struct node
*nd
= to_node(i
);
582 mutex_lock(&sp
->members_lock
);
585 mutex_unlock(&sp
->members_lock
);
590 static void release_node(struct config_item
*i
)
592 struct node
*nd
= to_node(i
);
596 static struct clusters clusters_root
= {
601 .ci_type
= &clusters_type
,
607 int dlm_config_init(void)
609 config_group_init(&clusters_root
.subsys
.su_group
);
610 mutex_init(&clusters_root
.subsys
.su_mutex
);
611 return configfs_register_subsystem(&clusters_root
.subsys
);
614 void dlm_config_exit(void)
616 configfs_unregister_subsystem(&clusters_root
.subsys
);
620 * Functions for user space to read/write attributes
623 static ssize_t
show_cluster(struct config_item
*i
, struct configfs_attribute
*a
,
626 struct cluster
*cl
= to_cluster(i
);
627 struct cluster_attribute
*cla
=
628 container_of(a
, struct cluster_attribute
, attr
);
629 return cla
->show
? cla
->show(cl
, buf
) : 0;
632 static ssize_t
store_cluster(struct config_item
*i
,
633 struct configfs_attribute
*a
,
634 const char *buf
, size_t len
)
636 struct cluster
*cl
= to_cluster(i
);
637 struct cluster_attribute
*cla
=
638 container_of(a
, struct cluster_attribute
, attr
);
639 return cla
->store
? cla
->store(cl
, buf
, len
) : -EINVAL
;
642 static ssize_t
show_comm(struct config_item
*i
, struct configfs_attribute
*a
,
645 struct comm
*cm
= to_comm(i
);
646 struct comm_attribute
*cma
=
647 container_of(a
, struct comm_attribute
, attr
);
648 return cma
->show
? cma
->show(cm
, buf
) : 0;
651 static ssize_t
store_comm(struct config_item
*i
, struct configfs_attribute
*a
,
652 const char *buf
, size_t len
)
654 struct comm
*cm
= to_comm(i
);
655 struct comm_attribute
*cma
=
656 container_of(a
, struct comm_attribute
, attr
);
657 return cma
->store
? cma
->store(cm
, buf
, len
) : -EINVAL
;
660 static ssize_t
comm_nodeid_read(struct comm
*cm
, char *buf
)
662 return sprintf(buf
, "%d\n", cm
->nodeid
);
665 static ssize_t
comm_nodeid_write(struct comm
*cm
, const char *buf
, size_t len
)
667 cm
->nodeid
= simple_strtol(buf
, NULL
, 0);
671 static ssize_t
comm_local_read(struct comm
*cm
, char *buf
)
673 return sprintf(buf
, "%d\n", cm
->local
);
676 static ssize_t
comm_local_write(struct comm
*cm
, const char *buf
, size_t len
)
678 cm
->local
= simple_strtol(buf
, NULL
, 0);
679 if (cm
->local
&& !local_comm
)
684 static ssize_t
comm_addr_write(struct comm
*cm
, const char *buf
, size_t len
)
686 struct sockaddr_storage
*addr
;
688 if (len
!= sizeof(struct sockaddr_storage
))
691 if (cm
->addr_count
>= DLM_MAX_ADDR_COUNT
)
694 addr
= kzalloc(sizeof(*addr
), GFP_KERNEL
);
698 memcpy(addr
, buf
, len
);
699 cm
->addr
[cm
->addr_count
++] = addr
;
703 static ssize_t
show_node(struct config_item
*i
, struct configfs_attribute
*a
,
706 struct node
*nd
= to_node(i
);
707 struct node_attribute
*nda
=
708 container_of(a
, struct node_attribute
, attr
);
709 return nda
->show
? nda
->show(nd
, buf
) : 0;
712 static ssize_t
store_node(struct config_item
*i
, struct configfs_attribute
*a
,
713 const char *buf
, size_t len
)
715 struct node
*nd
= to_node(i
);
716 struct node_attribute
*nda
=
717 container_of(a
, struct node_attribute
, attr
);
718 return nda
->store
? nda
->store(nd
, buf
, len
) : -EINVAL
;
721 static ssize_t
node_nodeid_read(struct node
*nd
, char *buf
)
723 return sprintf(buf
, "%d\n", nd
->nodeid
);
726 static ssize_t
node_nodeid_write(struct node
*nd
, const char *buf
, size_t len
)
728 nd
->nodeid
= simple_strtol(buf
, NULL
, 0);
732 static ssize_t
node_weight_read(struct node
*nd
, char *buf
)
734 return sprintf(buf
, "%d\n", nd
->weight
);
737 static ssize_t
node_weight_write(struct node
*nd
, const char *buf
, size_t len
)
739 nd
->weight
= simple_strtol(buf
, NULL
, 0);
744 * Functions for the dlm to get the info that's been configured
747 static struct space
*get_space(char *name
)
749 struct config_item
*i
;
754 mutex_lock(&space_list
->cg_subsys
->su_mutex
);
755 i
= config_group_find_item(space_list
, name
);
756 mutex_unlock(&space_list
->cg_subsys
->su_mutex
);
761 static void put_space(struct space
*sp
)
763 config_item_put(&sp
->group
.cg_item
);
766 static struct comm
*get_comm(int nodeid
, struct sockaddr_storage
*addr
)
768 struct config_item
*i
;
769 struct comm
*cm
= NULL
;
775 mutex_lock(&clusters_root
.subsys
.su_mutex
);
777 list_for_each_entry(i
, &comm_list
->cg_children
, ci_entry
) {
781 if (cm
->nodeid
!= nodeid
)
787 if (!cm
->addr_count
||
788 memcmp(cm
->addr
[0], addr
, sizeof(*addr
)))
795 mutex_unlock(&clusters_root
.subsys
.su_mutex
);
802 static void put_comm(struct comm
*cm
)
804 config_item_put(&cm
->item
);
807 /* caller must free mem */
808 int dlm_nodeid_list(char *lsname
, int **ids_out
)
815 sp
= get_space(lsname
);
819 mutex_lock(&sp
->members_lock
);
820 if (!sp
->members_count
) {
825 ids
= kcalloc(sp
->members_count
, sizeof(int), GFP_KERNEL
);
831 rv
= sp
->members_count
;
832 list_for_each_entry(nd
, &sp
->members
, list
)
833 ids
[i
++] = nd
->nodeid
;
836 printk("bad nodeid count %d %d\n", rv
, i
);
840 mutex_unlock(&sp
->members_lock
);
845 int dlm_node_weight(char *lsname
, int nodeid
)
851 sp
= get_space(lsname
);
855 mutex_lock(&sp
->members_lock
);
856 list_for_each_entry(nd
, &sp
->members
, list
) {
857 if (nd
->nodeid
!= nodeid
)
862 mutex_unlock(&sp
->members_lock
);
868 int dlm_nodeid_to_addr(int nodeid
, struct sockaddr_storage
*addr
)
870 struct comm
*cm
= get_comm(nodeid
, NULL
);
875 memcpy(addr
, cm
->addr
[0], sizeof(*addr
));
880 int dlm_addr_to_nodeid(struct sockaddr_storage
*addr
, int *nodeid
)
882 struct comm
*cm
= get_comm(0, addr
);
885 *nodeid
= cm
->nodeid
;
890 int dlm_our_nodeid(void)
892 return local_comm
? local_comm
->nodeid
: 0;
895 /* num 0 is first addr, num 1 is second addr */
896 int dlm_our_addr(struct sockaddr_storage
*addr
, int num
)
900 if (num
+ 1 > local_comm
->addr_count
)
902 memcpy(addr
, local_comm
->addr
[num
], sizeof(*addr
));
906 /* Config file defaults */
907 #define DEFAULT_TCP_PORT 21064
908 #define DEFAULT_BUFFER_SIZE 4096
909 #define DEFAULT_RSBTBL_SIZE 256
910 #define DEFAULT_LKBTBL_SIZE 1024
911 #define DEFAULT_DIRTBL_SIZE 512
912 #define DEFAULT_RECOVER_TIMER 5
913 #define DEFAULT_TOSS_SECS 10
914 #define DEFAULT_SCAN_SECS 5
915 #define DEFAULT_LOG_DEBUG 0
916 #define DEFAULT_PROTOCOL 0
917 #define DEFAULT_TIMEWARN_CS 500 /* 5 sec = 500 centiseconds */
919 struct dlm_config_info dlm_config
= {
920 .ci_tcp_port
= DEFAULT_TCP_PORT
,
921 .ci_buffer_size
= DEFAULT_BUFFER_SIZE
,
922 .ci_rsbtbl_size
= DEFAULT_RSBTBL_SIZE
,
923 .ci_lkbtbl_size
= DEFAULT_LKBTBL_SIZE
,
924 .ci_dirtbl_size
= DEFAULT_DIRTBL_SIZE
,
925 .ci_recover_timer
= DEFAULT_RECOVER_TIMER
,
926 .ci_toss_secs
= DEFAULT_TOSS_SECS
,
927 .ci_scan_secs
= DEFAULT_SCAN_SECS
,
928 .ci_log_debug
= DEFAULT_LOG_DEBUG
,
929 .ci_protocol
= DEFAULT_PROTOCOL
,
930 .ci_timewarn_cs
= DEFAULT_TIMEWARN_CS