1 /******************************************************************************
2 *******************************************************************************
4 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5 ** Copyright (C) 2004-2008 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>
17 #include <linux/slab.h>
19 #include <linux/in6.h>
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.
35 static struct config_group
*space_list
;
36 static struct config_group
*comm_list
;
37 static struct dlm_comm
*local_comm
;
48 static struct config_group
*make_cluster(struct config_group
*, const char *);
49 static void drop_cluster(struct config_group
*, struct config_item
*);
50 static void release_cluster(struct config_item
*);
51 static struct config_group
*make_space(struct config_group
*, const char *);
52 static void drop_space(struct config_group
*, struct config_item
*);
53 static void release_space(struct config_item
*);
54 static struct config_item
*make_comm(struct config_group
*, const char *);
55 static void drop_comm(struct config_group
*, struct config_item
*);
56 static void release_comm(struct config_item
*);
57 static struct config_item
*make_node(struct config_group
*, const char *);
58 static void drop_node(struct config_group
*, struct config_item
*);
59 static void release_node(struct config_item
*);
61 static ssize_t
show_cluster(struct config_item
*i
, struct configfs_attribute
*a
,
63 static ssize_t
store_cluster(struct config_item
*i
,
64 struct configfs_attribute
*a
,
65 const char *buf
, size_t len
);
66 static ssize_t
show_comm(struct config_item
*i
, struct configfs_attribute
*a
,
68 static ssize_t
store_comm(struct config_item
*i
, struct configfs_attribute
*a
,
69 const char *buf
, size_t len
);
70 static ssize_t
show_node(struct config_item
*i
, struct configfs_attribute
*a
,
72 static ssize_t
store_node(struct config_item
*i
, struct configfs_attribute
*a
,
73 const char *buf
, size_t len
);
75 static ssize_t
comm_nodeid_read(struct dlm_comm
*cm
, char *buf
);
76 static ssize_t
comm_nodeid_write(struct dlm_comm
*cm
, const char *buf
,
78 static ssize_t
comm_local_read(struct dlm_comm
*cm
, char *buf
);
79 static ssize_t
comm_local_write(struct dlm_comm
*cm
, const char *buf
,
81 static ssize_t
comm_addr_write(struct dlm_comm
*cm
, const char *buf
,
83 static ssize_t
node_nodeid_read(struct dlm_node
*nd
, char *buf
);
84 static ssize_t
node_nodeid_write(struct dlm_node
*nd
, const char *buf
,
86 static ssize_t
node_weight_read(struct dlm_node
*nd
, char *buf
);
87 static ssize_t
node_weight_write(struct dlm_node
*nd
, const char *buf
,
91 struct config_group group
;
92 unsigned int cl_tcp_port
;
93 unsigned int cl_buffer_size
;
94 unsigned int cl_rsbtbl_size
;
95 unsigned int cl_lkbtbl_size
;
96 unsigned int cl_dirtbl_size
;
97 unsigned int cl_recover_timer
;
98 unsigned int cl_toss_secs
;
99 unsigned int cl_scan_secs
;
100 unsigned int cl_log_debug
;
101 unsigned int cl_protocol
;
102 unsigned int cl_timewarn_cs
;
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
,
115 CLUSTER_ATTR_PROTOCOL
,
116 CLUSTER_ATTR_TIMEWARN_CS
,
119 struct cluster_attribute
{
120 struct configfs_attribute attr
;
121 ssize_t (*show
)(struct dlm_cluster
*, char *);
122 ssize_t (*store
)(struct dlm_cluster
*, const char *, size_t);
125 static ssize_t
cluster_set(struct dlm_cluster
*cl
, unsigned int *cl_field
,
126 int *info_field
, int check_zero
,
127 const char *buf
, size_t len
)
131 if (!capable(CAP_SYS_ADMIN
))
134 x
= simple_strtoul(buf
, NULL
, 0);
136 if (check_zero
&& !x
)
145 #define CLUSTER_ATTR(name, check_zero) \
146 static ssize_t name##_write(struct dlm_cluster *cl, const char *buf, size_t len) \
148 return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \
149 check_zero, buf, len); \
151 static ssize_t name##_read(struct dlm_cluster *cl, char *buf) \
153 return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \
155 static struct cluster_attribute cluster_attr_##name = \
156 __CONFIGFS_ATTR(name, 0644, name##_read, name##_write)
158 CLUSTER_ATTR(tcp_port
, 1);
159 CLUSTER_ATTR(buffer_size
, 1);
160 CLUSTER_ATTR(rsbtbl_size
, 1);
161 CLUSTER_ATTR(lkbtbl_size
, 1);
162 CLUSTER_ATTR(dirtbl_size
, 1);
163 CLUSTER_ATTR(recover_timer
, 1);
164 CLUSTER_ATTR(toss_secs
, 1);
165 CLUSTER_ATTR(scan_secs
, 1);
166 CLUSTER_ATTR(log_debug
, 0);
167 CLUSTER_ATTR(protocol
, 0);
168 CLUSTER_ATTR(timewarn_cs
, 1);
170 static struct configfs_attribute
*cluster_attrs
[] = {
171 [CLUSTER_ATTR_TCP_PORT
] = &cluster_attr_tcp_port
.attr
,
172 [CLUSTER_ATTR_BUFFER_SIZE
] = &cluster_attr_buffer_size
.attr
,
173 [CLUSTER_ATTR_RSBTBL_SIZE
] = &cluster_attr_rsbtbl_size
.attr
,
174 [CLUSTER_ATTR_LKBTBL_SIZE
] = &cluster_attr_lkbtbl_size
.attr
,
175 [CLUSTER_ATTR_DIRTBL_SIZE
] = &cluster_attr_dirtbl_size
.attr
,
176 [CLUSTER_ATTR_RECOVER_TIMER
] = &cluster_attr_recover_timer
.attr
,
177 [CLUSTER_ATTR_TOSS_SECS
] = &cluster_attr_toss_secs
.attr
,
178 [CLUSTER_ATTR_SCAN_SECS
] = &cluster_attr_scan_secs
.attr
,
179 [CLUSTER_ATTR_LOG_DEBUG
] = &cluster_attr_log_debug
.attr
,
180 [CLUSTER_ATTR_PROTOCOL
] = &cluster_attr_protocol
.attr
,
181 [CLUSTER_ATTR_TIMEWARN_CS
] = &cluster_attr_timewarn_cs
.attr
,
186 COMM_ATTR_NODEID
= 0,
191 struct comm_attribute
{
192 struct configfs_attribute attr
;
193 ssize_t (*show
)(struct dlm_comm
*, char *);
194 ssize_t (*store
)(struct dlm_comm
*, const char *, size_t);
197 static struct comm_attribute comm_attr_nodeid
= {
198 .attr
= { .ca_owner
= THIS_MODULE
,
200 .ca_mode
= S_IRUGO
| S_IWUSR
},
201 .show
= comm_nodeid_read
,
202 .store
= comm_nodeid_write
,
205 static struct comm_attribute comm_attr_local
= {
206 .attr
= { .ca_owner
= THIS_MODULE
,
208 .ca_mode
= S_IRUGO
| S_IWUSR
},
209 .show
= comm_local_read
,
210 .store
= comm_local_write
,
213 static struct comm_attribute comm_attr_addr
= {
214 .attr
= { .ca_owner
= THIS_MODULE
,
216 .ca_mode
= S_IRUGO
| S_IWUSR
},
217 .store
= comm_addr_write
,
220 static struct configfs_attribute
*comm_attrs
[] = {
221 [COMM_ATTR_NODEID
] = &comm_attr_nodeid
.attr
,
222 [COMM_ATTR_LOCAL
] = &comm_attr_local
.attr
,
223 [COMM_ATTR_ADDR
] = &comm_attr_addr
.attr
,
228 NODE_ATTR_NODEID
= 0,
232 struct node_attribute
{
233 struct configfs_attribute attr
;
234 ssize_t (*show
)(struct dlm_node
*, char *);
235 ssize_t (*store
)(struct dlm_node
*, const char *, size_t);
238 static struct node_attribute node_attr_nodeid
= {
239 .attr
= { .ca_owner
= THIS_MODULE
,
241 .ca_mode
= S_IRUGO
| S_IWUSR
},
242 .show
= node_nodeid_read
,
243 .store
= node_nodeid_write
,
246 static struct node_attribute node_attr_weight
= {
247 .attr
= { .ca_owner
= THIS_MODULE
,
249 .ca_mode
= S_IRUGO
| S_IWUSR
},
250 .show
= node_weight_read
,
251 .store
= node_weight_write
,
254 static struct configfs_attribute
*node_attrs
[] = {
255 [NODE_ATTR_NODEID
] = &node_attr_nodeid
.attr
,
256 [NODE_ATTR_WEIGHT
] = &node_attr_weight
.attr
,
260 struct dlm_clusters
{
261 struct configfs_subsystem subsys
;
265 struct config_group ss_group
;
269 struct config_group group
;
270 struct list_head members
;
271 struct mutex members_lock
;
276 struct config_group cs_group
;
280 struct config_item item
;
284 struct sockaddr_storage
*addr
[DLM_MAX_ADDR_COUNT
];
288 struct config_group ns_group
;
292 struct config_item item
;
293 struct list_head list
; /* space->members */
299 static struct configfs_group_operations clusters_ops
= {
300 .make_group
= make_cluster
,
301 .drop_item
= drop_cluster
,
304 static struct configfs_item_operations cluster_ops
= {
305 .release
= release_cluster
,
306 .show_attribute
= show_cluster
,
307 .store_attribute
= store_cluster
,
310 static struct configfs_group_operations spaces_ops
= {
311 .make_group
= make_space
,
312 .drop_item
= drop_space
,
315 static struct configfs_item_operations space_ops
= {
316 .release
= release_space
,
319 static struct configfs_group_operations comms_ops
= {
320 .make_item
= make_comm
,
321 .drop_item
= drop_comm
,
324 static struct configfs_item_operations comm_ops
= {
325 .release
= release_comm
,
326 .show_attribute
= show_comm
,
327 .store_attribute
= store_comm
,
330 static struct configfs_group_operations nodes_ops
= {
331 .make_item
= make_node
,
332 .drop_item
= drop_node
,
335 static struct configfs_item_operations node_ops
= {
336 .release
= release_node
,
337 .show_attribute
= show_node
,
338 .store_attribute
= store_node
,
341 static struct config_item_type clusters_type
= {
342 .ct_group_ops
= &clusters_ops
,
343 .ct_owner
= THIS_MODULE
,
346 static struct config_item_type cluster_type
= {
347 .ct_item_ops
= &cluster_ops
,
348 .ct_attrs
= cluster_attrs
,
349 .ct_owner
= THIS_MODULE
,
352 static struct config_item_type spaces_type
= {
353 .ct_group_ops
= &spaces_ops
,
354 .ct_owner
= THIS_MODULE
,
357 static struct config_item_type space_type
= {
358 .ct_item_ops
= &space_ops
,
359 .ct_owner
= THIS_MODULE
,
362 static struct config_item_type comms_type
= {
363 .ct_group_ops
= &comms_ops
,
364 .ct_owner
= THIS_MODULE
,
367 static struct config_item_type comm_type
= {
368 .ct_item_ops
= &comm_ops
,
369 .ct_attrs
= comm_attrs
,
370 .ct_owner
= THIS_MODULE
,
373 static struct config_item_type nodes_type
= {
374 .ct_group_ops
= &nodes_ops
,
375 .ct_owner
= THIS_MODULE
,
378 static struct config_item_type node_type
= {
379 .ct_item_ops
= &node_ops
,
380 .ct_attrs
= node_attrs
,
381 .ct_owner
= THIS_MODULE
,
384 static struct dlm_cluster
*config_item_to_cluster(struct config_item
*i
)
386 return i
? container_of(to_config_group(i
), struct dlm_cluster
, group
) :
390 static struct dlm_space
*config_item_to_space(struct config_item
*i
)
392 return i
? container_of(to_config_group(i
), struct dlm_space
, group
) :
396 static struct dlm_comm
*config_item_to_comm(struct config_item
*i
)
398 return i
? container_of(i
, struct dlm_comm
, item
) : NULL
;
401 static struct dlm_node
*config_item_to_node(struct config_item
*i
)
403 return i
? container_of(i
, struct dlm_node
, item
) : NULL
;
406 static struct config_group
*make_cluster(struct config_group
*g
,
409 struct dlm_cluster
*cl
= NULL
;
410 struct dlm_spaces
*sps
= NULL
;
411 struct dlm_comms
*cms
= NULL
;
414 cl
= kzalloc(sizeof(struct dlm_cluster
), GFP_NOFS
);
415 gps
= kcalloc(3, sizeof(struct config_group
*), GFP_NOFS
);
416 sps
= kzalloc(sizeof(struct dlm_spaces
), GFP_NOFS
);
417 cms
= kzalloc(sizeof(struct dlm_comms
), GFP_NOFS
);
419 if (!cl
|| !gps
|| !sps
|| !cms
)
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
);
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
;
431 cl
->cl_tcp_port
= dlm_config
.ci_tcp_port
;
432 cl
->cl_buffer_size
= dlm_config
.ci_buffer_size
;
433 cl
->cl_rsbtbl_size
= dlm_config
.ci_rsbtbl_size
;
434 cl
->cl_lkbtbl_size
= dlm_config
.ci_lkbtbl_size
;
435 cl
->cl_dirtbl_size
= dlm_config
.ci_dirtbl_size
;
436 cl
->cl_recover_timer
= dlm_config
.ci_recover_timer
;
437 cl
->cl_toss_secs
= dlm_config
.ci_toss_secs
;
438 cl
->cl_scan_secs
= dlm_config
.ci_scan_secs
;
439 cl
->cl_log_debug
= dlm_config
.ci_log_debug
;
440 cl
->cl_protocol
= dlm_config
.ci_protocol
;
441 cl
->cl_timewarn_cs
= dlm_config
.ci_timewarn_cs
;
443 space_list
= &sps
->ss_group
;
444 comm_list
= &cms
->cs_group
;
452 return ERR_PTR(-ENOMEM
);
455 static void drop_cluster(struct config_group
*g
, struct config_item
*i
)
457 struct dlm_cluster
*cl
= config_item_to_cluster(i
);
458 struct config_item
*tmp
;
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
);
473 static void release_cluster(struct config_item
*i
)
475 struct dlm_cluster
*cl
= config_item_to_cluster(i
);
476 kfree(cl
->group
.default_groups
);
480 static struct config_group
*make_space(struct config_group
*g
, const char *name
)
482 struct dlm_space
*sp
= NULL
;
483 struct dlm_nodes
*nds
= NULL
;
486 sp
= kzalloc(sizeof(struct dlm_space
), GFP_NOFS
);
487 gps
= kcalloc(2, sizeof(struct config_group
*), GFP_NOFS
);
488 nds
= kzalloc(sizeof(struct dlm_nodes
), GFP_NOFS
);
490 if (!sp
|| !gps
|| !nds
)
493 config_group_init_type_name(&sp
->group
, name
, &space_type
);
494 config_group_init_type_name(&nds
->ns_group
, "nodes", &nodes_type
);
496 sp
->group
.default_groups
= gps
;
497 sp
->group
.default_groups
[0] = &nds
->ns_group
;
498 sp
->group
.default_groups
[1] = NULL
;
500 INIT_LIST_HEAD(&sp
->members
);
501 mutex_init(&sp
->members_lock
);
502 sp
->members_count
= 0;
509 return ERR_PTR(-ENOMEM
);
512 static void drop_space(struct config_group
*g
, struct config_item
*i
)
514 struct dlm_space
*sp
= config_item_to_space(i
);
515 struct config_item
*tmp
;
518 /* assert list_empty(&sp->members) */
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
);
529 static void release_space(struct config_item
*i
)
531 struct dlm_space
*sp
= config_item_to_space(i
);
532 kfree(sp
->group
.default_groups
);
536 static struct config_item
*make_comm(struct config_group
*g
, const char *name
)
540 cm
= kzalloc(sizeof(struct dlm_comm
), GFP_NOFS
);
542 return ERR_PTR(-ENOMEM
);
544 config_item_init_type_name(&cm
->item
, name
, &comm_type
);
551 static void drop_comm(struct config_group
*g
, struct config_item
*i
)
553 struct dlm_comm
*cm
= config_item_to_comm(i
);
554 if (local_comm
== cm
)
556 dlm_lowcomms_close(cm
->nodeid
);
557 while (cm
->addr_count
--)
558 kfree(cm
->addr
[cm
->addr_count
]);
562 static void release_comm(struct config_item
*i
)
564 struct dlm_comm
*cm
= config_item_to_comm(i
);
568 static struct config_item
*make_node(struct config_group
*g
, const char *name
)
570 struct dlm_space
*sp
= config_item_to_space(g
->cg_item
.ci_parent
);
573 nd
= kzalloc(sizeof(struct dlm_node
), GFP_NOFS
);
575 return ERR_PTR(-ENOMEM
);
577 config_item_init_type_name(&nd
->item
, name
, &node_type
);
579 nd
->weight
= 1; /* default weight of 1 if none is set */
580 nd
->new = 1; /* set to 0 once it's been read by dlm_nodeid_list() */
582 mutex_lock(&sp
->members_lock
);
583 list_add(&nd
->list
, &sp
->members
);
585 mutex_unlock(&sp
->members_lock
);
590 static void drop_node(struct config_group
*g
, struct config_item
*i
)
592 struct dlm_space
*sp
= config_item_to_space(g
->cg_item
.ci_parent
);
593 struct dlm_node
*nd
= config_item_to_node(i
);
595 mutex_lock(&sp
->members_lock
);
598 mutex_unlock(&sp
->members_lock
);
603 static void release_node(struct config_item
*i
)
605 struct dlm_node
*nd
= config_item_to_node(i
);
609 static struct dlm_clusters clusters_root
= {
614 .ci_type
= &clusters_type
,
620 int __init
dlm_config_init(void)
622 config_group_init(&clusters_root
.subsys
.su_group
);
623 mutex_init(&clusters_root
.subsys
.su_mutex
);
624 return configfs_register_subsystem(&clusters_root
.subsys
);
627 void dlm_config_exit(void)
629 configfs_unregister_subsystem(&clusters_root
.subsys
);
633 * Functions for user space to read/write attributes
636 static ssize_t
show_cluster(struct config_item
*i
, struct configfs_attribute
*a
,
639 struct dlm_cluster
*cl
= config_item_to_cluster(i
);
640 struct cluster_attribute
*cla
=
641 container_of(a
, struct cluster_attribute
, attr
);
642 return cla
->show
? cla
->show(cl
, buf
) : 0;
645 static ssize_t
store_cluster(struct config_item
*i
,
646 struct configfs_attribute
*a
,
647 const char *buf
, size_t len
)
649 struct dlm_cluster
*cl
= config_item_to_cluster(i
);
650 struct cluster_attribute
*cla
=
651 container_of(a
, struct cluster_attribute
, attr
);
652 return cla
->store
? cla
->store(cl
, buf
, len
) : -EINVAL
;
655 static ssize_t
show_comm(struct config_item
*i
, struct configfs_attribute
*a
,
658 struct dlm_comm
*cm
= config_item_to_comm(i
);
659 struct comm_attribute
*cma
=
660 container_of(a
, struct comm_attribute
, attr
);
661 return cma
->show
? cma
->show(cm
, buf
) : 0;
664 static ssize_t
store_comm(struct config_item
*i
, struct configfs_attribute
*a
,
665 const char *buf
, size_t len
)
667 struct dlm_comm
*cm
= config_item_to_comm(i
);
668 struct comm_attribute
*cma
=
669 container_of(a
, struct comm_attribute
, attr
);
670 return cma
->store
? cma
->store(cm
, buf
, len
) : -EINVAL
;
673 static ssize_t
comm_nodeid_read(struct dlm_comm
*cm
, char *buf
)
675 return sprintf(buf
, "%d\n", cm
->nodeid
);
678 static ssize_t
comm_nodeid_write(struct dlm_comm
*cm
, const char *buf
,
681 cm
->nodeid
= simple_strtol(buf
, NULL
, 0);
685 static ssize_t
comm_local_read(struct dlm_comm
*cm
, char *buf
)
687 return sprintf(buf
, "%d\n", cm
->local
);
690 static ssize_t
comm_local_write(struct dlm_comm
*cm
, const char *buf
,
693 cm
->local
= simple_strtol(buf
, NULL
, 0);
694 if (cm
->local
&& !local_comm
)
699 static ssize_t
comm_addr_write(struct dlm_comm
*cm
, const char *buf
, size_t len
)
701 struct sockaddr_storage
*addr
;
703 if (len
!= sizeof(struct sockaddr_storage
))
706 if (cm
->addr_count
>= DLM_MAX_ADDR_COUNT
)
709 addr
= kzalloc(sizeof(*addr
), GFP_NOFS
);
713 memcpy(addr
, buf
, len
);
714 cm
->addr
[cm
->addr_count
++] = addr
;
718 static ssize_t
show_node(struct config_item
*i
, struct configfs_attribute
*a
,
721 struct dlm_node
*nd
= config_item_to_node(i
);
722 struct node_attribute
*nda
=
723 container_of(a
, struct node_attribute
, attr
);
724 return nda
->show
? nda
->show(nd
, buf
) : 0;
727 static ssize_t
store_node(struct config_item
*i
, struct configfs_attribute
*a
,
728 const char *buf
, size_t len
)
730 struct dlm_node
*nd
= config_item_to_node(i
);
731 struct node_attribute
*nda
=
732 container_of(a
, struct node_attribute
, attr
);
733 return nda
->store
? nda
->store(nd
, buf
, len
) : -EINVAL
;
736 static ssize_t
node_nodeid_read(struct dlm_node
*nd
, char *buf
)
738 return sprintf(buf
, "%d\n", nd
->nodeid
);
741 static ssize_t
node_nodeid_write(struct dlm_node
*nd
, const char *buf
,
744 nd
->nodeid
= simple_strtol(buf
, NULL
, 0);
748 static ssize_t
node_weight_read(struct dlm_node
*nd
, char *buf
)
750 return sprintf(buf
, "%d\n", nd
->weight
);
753 static ssize_t
node_weight_write(struct dlm_node
*nd
, const char *buf
,
756 nd
->weight
= simple_strtol(buf
, NULL
, 0);
761 * Functions for the dlm to get the info that's been configured
764 static struct dlm_space
*get_space(char *name
)
766 struct config_item
*i
;
771 mutex_lock(&space_list
->cg_subsys
->su_mutex
);
772 i
= config_group_find_item(space_list
, name
);
773 mutex_unlock(&space_list
->cg_subsys
->su_mutex
);
775 return config_item_to_space(i
);
778 static void put_space(struct dlm_space
*sp
)
780 config_item_put(&sp
->group
.cg_item
);
783 static int addr_compare(struct sockaddr_storage
*x
, struct sockaddr_storage
*y
)
785 switch (x
->ss_family
) {
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
)
791 if (sinx
->sin_port
!= siny
->sin_port
)
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
))
800 if (sinx
->sin6_port
!= siny
->sin6_port
)
810 static struct dlm_comm
*get_comm(int nodeid
, struct sockaddr_storage
*addr
)
812 struct config_item
*i
;
813 struct dlm_comm
*cm
= NULL
;
819 mutex_lock(&clusters_root
.subsys
.su_mutex
);
821 list_for_each_entry(i
, &comm_list
->cg_children
, ci_entry
) {
822 cm
= config_item_to_comm(i
);
825 if (cm
->nodeid
!= nodeid
)
831 if (!cm
->addr_count
|| !addr_compare(cm
->addr
[0], addr
))
838 mutex_unlock(&clusters_root
.subsys
.su_mutex
);
845 static void put_comm(struct dlm_comm
*cm
)
847 config_item_put(&cm
->item
);
850 /* caller must free mem */
851 int dlm_nodeid_list(char *lsname
, int **ids_out
, int *ids_count_out
,
852 int **new_out
, int *new_count_out
)
854 struct dlm_space
*sp
;
856 int i
= 0, rv
= 0, ids_count
= 0, new_count
= 0;
859 sp
= get_space(lsname
);
863 mutex_lock(&sp
->members_lock
);
864 if (!sp
->members_count
) {
866 printk(KERN_ERR
"dlm: zero members_count\n");
870 ids_count
= sp
->members_count
;
872 ids
= kcalloc(ids_count
, sizeof(int), GFP_NOFS
);
878 list_for_each_entry(nd
, &sp
->members
, list
) {
879 ids
[i
++] = nd
->nodeid
;
885 printk(KERN_ERR
"dlm: bad nodeid count %d %d\n", ids_count
, i
);
890 new = kcalloc(new_count
, sizeof(int), GFP_NOFS
);
898 list_for_each_entry(nd
, &sp
->members
, list
) {
900 new[i
++] = nd
->nodeid
;
904 *new_count_out
= new_count
;
908 *ids_count_out
= ids_count
;
911 mutex_unlock(&sp
->members_lock
);
916 int dlm_node_weight(char *lsname
, int nodeid
)
918 struct dlm_space
*sp
;
922 sp
= get_space(lsname
);
926 mutex_lock(&sp
->members_lock
);
927 list_for_each_entry(nd
, &sp
->members
, list
) {
928 if (nd
->nodeid
!= nodeid
)
933 mutex_unlock(&sp
->members_lock
);
939 int dlm_nodeid_to_addr(int nodeid
, struct sockaddr_storage
*addr
)
941 struct dlm_comm
*cm
= get_comm(nodeid
, NULL
);
946 memcpy(addr
, cm
->addr
[0], sizeof(*addr
));
951 int dlm_addr_to_nodeid(struct sockaddr_storage
*addr
, int *nodeid
)
953 struct dlm_comm
*cm
= get_comm(0, addr
);
956 *nodeid
= cm
->nodeid
;
961 int dlm_our_nodeid(void)
963 return local_comm
? local_comm
->nodeid
: 0;
966 /* num 0 is first addr, num 1 is second addr */
967 int dlm_our_addr(struct sockaddr_storage
*addr
, int num
)
971 if (num
+ 1 > local_comm
->addr_count
)
973 memcpy(addr
, local_comm
->addr
[num
], sizeof(*addr
));
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
986 #define DEFAULT_LOG_DEBUG 0
987 #define DEFAULT_PROTOCOL 0
988 #define DEFAULT_TIMEWARN_CS 500 /* 5 sec = 500 centiseconds */
990 struct dlm_config_info dlm_config
= {
991 .ci_tcp_port
= DEFAULT_TCP_PORT
,
992 .ci_buffer_size
= DEFAULT_BUFFER_SIZE
,
993 .ci_rsbtbl_size
= DEFAULT_RSBTBL_SIZE
,
994 .ci_lkbtbl_size
= DEFAULT_LKBTBL_SIZE
,
995 .ci_dirtbl_size
= DEFAULT_DIRTBL_SIZE
,
996 .ci_recover_timer
= DEFAULT_RECOVER_TIMER
,
997 .ci_toss_secs
= DEFAULT_TOSS_SECS
,
998 .ci_scan_secs
= DEFAULT_SCAN_SECS
,
999 .ci_log_debug
= DEFAULT_LOG_DEBUG
,
1000 .ci_protocol
= DEFAULT_PROTOCOL
,
1001 .ci_timewarn_cs
= DEFAULT_TIMEWARN_CS