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>
18 #include <linux/in6.h>
26 * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid
27 * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/weight
28 * /config/dlm/<cluster>/comms/<comm>/nodeid
29 * /config/dlm/<cluster>/comms/<comm>/local
30 * /config/dlm/<cluster>/comms/<comm>/addr
31 * The <cluster> level is useless, but I haven't figured out how to avoid it.
34 static struct config_group *space_list;
35 static struct config_group *comm_list;
36 static struct dlm_comm *local_comm;
47 static struct config_group *make_cluster(struct config_group *, const char *);
48 static void drop_cluster(struct config_group *, struct config_item *);
49 static void release_cluster(struct config_item *);
50 static struct config_group *make_space(struct config_group *, const char *);
51 static void drop_space(struct config_group *, struct config_item *);
52 static void release_space(struct config_item *);
53 static struct config_item *make_comm(struct config_group *, const char *);
54 static void drop_comm(struct config_group *, struct config_item *);
55 static void release_comm(struct config_item *);
56 static struct config_item *make_node(struct config_group *, const char *);
57 static void drop_node(struct config_group *, struct config_item *);
58 static void release_node(struct config_item *);
60 static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a,
62 static ssize_t store_cluster(struct config_item *i,
63 struct configfs_attribute *a,
64 const char *buf, size_t len);
65 static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
67 static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
68 const char *buf, size_t len);
69 static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
71 static ssize_t store_node(struct config_item *i, struct configfs_attribute *a,
72 const char *buf, size_t len);
74 static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf);
75 static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf,
77 static ssize_t comm_local_read(struct dlm_comm *cm, char *buf);
78 static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
80 static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf,
82 static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf);
83 static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
85 static ssize_t node_weight_read(struct dlm_node *nd, char *buf);
86 static ssize_t node_weight_write(struct dlm_node *nd, const char *buf,
90 struct config_group group;
91 unsigned int cl_tcp_port;
92 unsigned int cl_buffer_size;
93 unsigned int cl_rsbtbl_size;
94 unsigned int cl_lkbtbl_size;
95 unsigned int cl_dirtbl_size;
96 unsigned int cl_recover_timer;
97 unsigned int cl_toss_secs;
98 unsigned int cl_scan_secs;
99 unsigned int cl_log_debug;
100 unsigned int cl_protocol;
101 unsigned int cl_timewarn_cs;
105 CLUSTER_ATTR_TCP_PORT = 0,
106 CLUSTER_ATTR_BUFFER_SIZE,
107 CLUSTER_ATTR_RSBTBL_SIZE,
108 CLUSTER_ATTR_LKBTBL_SIZE,
109 CLUSTER_ATTR_DIRTBL_SIZE,
110 CLUSTER_ATTR_RECOVER_TIMER,
111 CLUSTER_ATTR_TOSS_SECS,
112 CLUSTER_ATTR_SCAN_SECS,
113 CLUSTER_ATTR_LOG_DEBUG,
114 CLUSTER_ATTR_PROTOCOL,
115 CLUSTER_ATTR_TIMEWARN_CS,
118 struct cluster_attribute {
119 struct configfs_attribute attr;
120 ssize_t (*show)(struct dlm_cluster *, char *);
121 ssize_t (*store)(struct dlm_cluster *, const char *, size_t);
124 static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
125 int *info_field, int check_zero,
126 const char *buf, size_t len)
130 if (!capable(CAP_SYS_ADMIN))
133 x = simple_strtoul(buf, NULL, 0);
135 if (check_zero && !x)
144 #define CLUSTER_ATTR(name, check_zero) \
145 static ssize_t name##_write(struct dlm_cluster *cl, const char *buf, size_t len) \
147 return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \
148 check_zero, buf, len); \
150 static ssize_t name##_read(struct dlm_cluster *cl, char *buf) \
152 return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \
154 static struct cluster_attribute cluster_attr_##name = \
155 __CONFIGFS_ATTR(name, 0644, name##_read, name##_write)
157 CLUSTER_ATTR(tcp_port, 1);
158 CLUSTER_ATTR(buffer_size, 1);
159 CLUSTER_ATTR(rsbtbl_size, 1);
160 CLUSTER_ATTR(lkbtbl_size, 1);
161 CLUSTER_ATTR(dirtbl_size, 1);
162 CLUSTER_ATTR(recover_timer, 1);
163 CLUSTER_ATTR(toss_secs, 1);
164 CLUSTER_ATTR(scan_secs, 1);
165 CLUSTER_ATTR(log_debug, 0);
166 CLUSTER_ATTR(protocol, 0);
167 CLUSTER_ATTR(timewarn_cs, 1);
169 static struct configfs_attribute *cluster_attrs[] = {
170 [CLUSTER_ATTR_TCP_PORT] = &cluster_attr_tcp_port.attr,
171 [CLUSTER_ATTR_BUFFER_SIZE] = &cluster_attr_buffer_size.attr,
172 [CLUSTER_ATTR_RSBTBL_SIZE] = &cluster_attr_rsbtbl_size.attr,
173 [CLUSTER_ATTR_LKBTBL_SIZE] = &cluster_attr_lkbtbl_size.attr,
174 [CLUSTER_ATTR_DIRTBL_SIZE] = &cluster_attr_dirtbl_size.attr,
175 [CLUSTER_ATTR_RECOVER_TIMER] = &cluster_attr_recover_timer.attr,
176 [CLUSTER_ATTR_TOSS_SECS] = &cluster_attr_toss_secs.attr,
177 [CLUSTER_ATTR_SCAN_SECS] = &cluster_attr_scan_secs.attr,
178 [CLUSTER_ATTR_LOG_DEBUG] = &cluster_attr_log_debug.attr,
179 [CLUSTER_ATTR_PROTOCOL] = &cluster_attr_protocol.attr,
180 [CLUSTER_ATTR_TIMEWARN_CS] = &cluster_attr_timewarn_cs.attr,
185 COMM_ATTR_NODEID = 0,
190 struct comm_attribute {
191 struct configfs_attribute attr;
192 ssize_t (*show)(struct dlm_comm *, char *);
193 ssize_t (*store)(struct dlm_comm *, const char *, size_t);
196 static struct comm_attribute comm_attr_nodeid = {
197 .attr = { .ca_owner = THIS_MODULE,
199 .ca_mode = S_IRUGO | S_IWUSR },
200 .show = comm_nodeid_read,
201 .store = comm_nodeid_write,
204 static struct comm_attribute comm_attr_local = {
205 .attr = { .ca_owner = THIS_MODULE,
207 .ca_mode = S_IRUGO | S_IWUSR },
208 .show = comm_local_read,
209 .store = comm_local_write,
212 static struct comm_attribute comm_attr_addr = {
213 .attr = { .ca_owner = THIS_MODULE,
215 .ca_mode = S_IRUGO | S_IWUSR },
216 .store = comm_addr_write,
219 static struct configfs_attribute *comm_attrs[] = {
220 [COMM_ATTR_NODEID] = &comm_attr_nodeid.attr,
221 [COMM_ATTR_LOCAL] = &comm_attr_local.attr,
222 [COMM_ATTR_ADDR] = &comm_attr_addr.attr,
227 NODE_ATTR_NODEID = 0,
231 struct node_attribute {
232 struct configfs_attribute attr;
233 ssize_t (*show)(struct dlm_node *, char *);
234 ssize_t (*store)(struct dlm_node *, const char *, size_t);
237 static struct node_attribute node_attr_nodeid = {
238 .attr = { .ca_owner = THIS_MODULE,
240 .ca_mode = S_IRUGO | S_IWUSR },
241 .show = node_nodeid_read,
242 .store = node_nodeid_write,
245 static struct node_attribute node_attr_weight = {
246 .attr = { .ca_owner = THIS_MODULE,
248 .ca_mode = S_IRUGO | S_IWUSR },
249 .show = node_weight_read,
250 .store = node_weight_write,
253 static struct configfs_attribute *node_attrs[] = {
254 [NODE_ATTR_NODEID] = &node_attr_nodeid.attr,
255 [NODE_ATTR_WEIGHT] = &node_attr_weight.attr,
259 struct dlm_clusters {
260 struct configfs_subsystem subsys;
264 struct config_group ss_group;
268 struct config_group group;
269 struct list_head members;
270 struct mutex members_lock;
275 struct config_group cs_group;
279 struct config_item item;
283 struct sockaddr_storage *addr[DLM_MAX_ADDR_COUNT];
287 struct config_group ns_group;
291 struct config_item item;
292 struct list_head list; /* space->members */
298 static struct configfs_group_operations clusters_ops = {
299 .make_group = make_cluster,
300 .drop_item = drop_cluster,
303 static struct configfs_item_operations cluster_ops = {
304 .release = release_cluster,
305 .show_attribute = show_cluster,
306 .store_attribute = store_cluster,
309 static struct configfs_group_operations spaces_ops = {
310 .make_group = make_space,
311 .drop_item = drop_space,
314 static struct configfs_item_operations space_ops = {
315 .release = release_space,
318 static struct configfs_group_operations comms_ops = {
319 .make_item = make_comm,
320 .drop_item = drop_comm,
323 static struct configfs_item_operations comm_ops = {
324 .release = release_comm,
325 .show_attribute = show_comm,
326 .store_attribute = store_comm,
329 static struct configfs_group_operations nodes_ops = {
330 .make_item = make_node,
331 .drop_item = drop_node,
334 static struct configfs_item_operations node_ops = {
335 .release = release_node,
336 .show_attribute = show_node,
337 .store_attribute = store_node,
340 static struct config_item_type clusters_type = {
341 .ct_group_ops = &clusters_ops,
342 .ct_owner = THIS_MODULE,
345 static struct config_item_type cluster_type = {
346 .ct_item_ops = &cluster_ops,
347 .ct_attrs = cluster_attrs,
348 .ct_owner = THIS_MODULE,
351 static struct config_item_type spaces_type = {
352 .ct_group_ops = &spaces_ops,
353 .ct_owner = THIS_MODULE,
356 static struct config_item_type space_type = {
357 .ct_item_ops = &space_ops,
358 .ct_owner = THIS_MODULE,
361 static struct config_item_type comms_type = {
362 .ct_group_ops = &comms_ops,
363 .ct_owner = THIS_MODULE,
366 static struct config_item_type comm_type = {
367 .ct_item_ops = &comm_ops,
368 .ct_attrs = comm_attrs,
369 .ct_owner = THIS_MODULE,
372 static struct config_item_type nodes_type = {
373 .ct_group_ops = &nodes_ops,
374 .ct_owner = THIS_MODULE,
377 static struct config_item_type node_type = {
378 .ct_item_ops = &node_ops,
379 .ct_attrs = node_attrs,
380 .ct_owner = THIS_MODULE,
383 static struct dlm_cluster *config_item_to_cluster(struct config_item *i)
385 return i ? container_of(to_config_group(i), struct dlm_cluster, group) :
389 static struct dlm_space *config_item_to_space(struct config_item *i)
391 return i ? container_of(to_config_group(i), struct dlm_space, group) :
395 static struct dlm_comm *config_item_to_comm(struct config_item *i)
397 return i ? container_of(i, struct dlm_comm, item) : NULL;
400 static struct dlm_node *config_item_to_node(struct config_item *i)
402 return i ? container_of(i, struct dlm_node, item) : NULL;
405 static struct config_group *make_cluster(struct config_group *g,
408 struct dlm_cluster *cl = NULL;
409 struct dlm_spaces *sps = NULL;
410 struct dlm_comms *cms = NULL;
413 cl = kzalloc(sizeof(struct dlm_cluster), GFP_KERNEL);
414 gps = kcalloc(3, sizeof(struct config_group *), GFP_KERNEL);
415 sps = kzalloc(sizeof(struct dlm_spaces), GFP_KERNEL);
416 cms = kzalloc(sizeof(struct dlm_comms), GFP_KERNEL);
418 if (!cl || !gps || !sps || !cms)
421 config_group_init_type_name(&cl->group, name, &cluster_type);
422 config_group_init_type_name(&sps->ss_group, "spaces", &spaces_type);
423 config_group_init_type_name(&cms->cs_group, "comms", &comms_type);
425 cl->group.default_groups = gps;
426 cl->group.default_groups[0] = &sps->ss_group;
427 cl->group.default_groups[1] = &cms->cs_group;
428 cl->group.default_groups[2] = NULL;
430 cl->cl_tcp_port = dlm_config.ci_tcp_port;
431 cl->cl_buffer_size = dlm_config.ci_buffer_size;
432 cl->cl_rsbtbl_size = dlm_config.ci_rsbtbl_size;
433 cl->cl_lkbtbl_size = dlm_config.ci_lkbtbl_size;
434 cl->cl_dirtbl_size = dlm_config.ci_dirtbl_size;
435 cl->cl_recover_timer = dlm_config.ci_recover_timer;
436 cl->cl_toss_secs = dlm_config.ci_toss_secs;
437 cl->cl_scan_secs = dlm_config.ci_scan_secs;
438 cl->cl_log_debug = dlm_config.ci_log_debug;
439 cl->cl_protocol = dlm_config.ci_protocol;
440 cl->cl_timewarn_cs = dlm_config.ci_timewarn_cs;
442 space_list = &sps->ss_group;
443 comm_list = &cms->cs_group;
451 return ERR_PTR(-ENOMEM);
454 static void drop_cluster(struct config_group *g, struct config_item *i)
456 struct dlm_cluster *cl = config_item_to_cluster(i);
457 struct config_item *tmp;
460 for (j = 0; cl->group.default_groups[j]; j++) {
461 tmp = &cl->group.default_groups[j]->cg_item;
462 cl->group.default_groups[j] = NULL;
463 config_item_put(tmp);
472 static void release_cluster(struct config_item *i)
474 struct dlm_cluster *cl = config_item_to_cluster(i);
475 kfree(cl->group.default_groups);
479 static struct config_group *make_space(struct config_group *g, const char *name)
481 struct dlm_space *sp = NULL;
482 struct dlm_nodes *nds = NULL;
485 sp = kzalloc(sizeof(struct dlm_space), GFP_KERNEL);
486 gps = kcalloc(2, sizeof(struct config_group *), GFP_KERNEL);
487 nds = kzalloc(sizeof(struct dlm_nodes), GFP_KERNEL);
489 if (!sp || !gps || !nds)
492 config_group_init_type_name(&sp->group, name, &space_type);
493 config_group_init_type_name(&nds->ns_group, "nodes", &nodes_type);
495 sp->group.default_groups = gps;
496 sp->group.default_groups[0] = &nds->ns_group;
497 sp->group.default_groups[1] = NULL;
499 INIT_LIST_HEAD(&sp->members);
500 mutex_init(&sp->members_lock);
501 sp->members_count = 0;
508 return ERR_PTR(-ENOMEM);
511 static void drop_space(struct config_group *g, struct config_item *i)
513 struct dlm_space *sp = config_item_to_space(i);
514 struct config_item *tmp;
517 /* assert list_empty(&sp->members) */
519 for (j = 0; sp->group.default_groups[j]; j++) {
520 tmp = &sp->group.default_groups[j]->cg_item;
521 sp->group.default_groups[j] = NULL;
522 config_item_put(tmp);
528 static void release_space(struct config_item *i)
530 struct dlm_space *sp = config_item_to_space(i);
531 kfree(sp->group.default_groups);
535 static struct config_item *make_comm(struct config_group *g, const char *name)
539 cm = kzalloc(sizeof(struct dlm_comm), GFP_KERNEL);
541 return ERR_PTR(-ENOMEM);
543 config_item_init_type_name(&cm->item, name, &comm_type);
550 static void drop_comm(struct config_group *g, struct config_item *i)
552 struct dlm_comm *cm = config_item_to_comm(i);
553 if (local_comm == cm)
555 dlm_lowcomms_close(cm->nodeid);
556 while (cm->addr_count--)
557 kfree(cm->addr[cm->addr_count]);
561 static void release_comm(struct config_item *i)
563 struct dlm_comm *cm = config_item_to_comm(i);
567 static struct config_item *make_node(struct config_group *g, const char *name)
569 struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent);
572 nd = kzalloc(sizeof(struct dlm_node), GFP_KERNEL);
574 return ERR_PTR(-ENOMEM);
576 config_item_init_type_name(&nd->item, name, &node_type);
578 nd->weight = 1; /* default weight of 1 if none is set */
579 nd->new = 1; /* set to 0 once it's been read by dlm_nodeid_list() */
581 mutex_lock(&sp->members_lock);
582 list_add(&nd->list, &sp->members);
584 mutex_unlock(&sp->members_lock);
589 static void drop_node(struct config_group *g, struct config_item *i)
591 struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent);
592 struct dlm_node *nd = config_item_to_node(i);
594 mutex_lock(&sp->members_lock);
597 mutex_unlock(&sp->members_lock);
602 static void release_node(struct config_item *i)
604 struct dlm_node *nd = config_item_to_node(i);
608 static struct dlm_clusters clusters_root = {
613 .ci_type = &clusters_type,
619 int __init dlm_config_init(void)
621 config_group_init(&clusters_root.subsys.su_group);
622 mutex_init(&clusters_root.subsys.su_mutex);
623 return configfs_register_subsystem(&clusters_root.subsys);
626 void dlm_config_exit(void)
628 configfs_unregister_subsystem(&clusters_root.subsys);
632 * Functions for user space to read/write attributes
635 static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a,
638 struct dlm_cluster *cl = config_item_to_cluster(i);
639 struct cluster_attribute *cla =
640 container_of(a, struct cluster_attribute, attr);
641 return cla->show ? cla->show(cl, buf) : 0;
644 static ssize_t store_cluster(struct config_item *i,
645 struct configfs_attribute *a,
646 const char *buf, size_t len)
648 struct dlm_cluster *cl = config_item_to_cluster(i);
649 struct cluster_attribute *cla =
650 container_of(a, struct cluster_attribute, attr);
651 return cla->store ? cla->store(cl, buf, len) : -EINVAL;
654 static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
657 struct dlm_comm *cm = config_item_to_comm(i);
658 struct comm_attribute *cma =
659 container_of(a, struct comm_attribute, attr);
660 return cma->show ? cma->show(cm, buf) : 0;
663 static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
664 const char *buf, size_t len)
666 struct dlm_comm *cm = config_item_to_comm(i);
667 struct comm_attribute *cma =
668 container_of(a, struct comm_attribute, attr);
669 return cma->store ? cma->store(cm, buf, len) : -EINVAL;
672 static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf)
674 return sprintf(buf, "%d\n", cm->nodeid);
677 static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf,
680 cm->nodeid = simple_strtol(buf, NULL, 0);
684 static ssize_t comm_local_read(struct dlm_comm *cm, char *buf)
686 return sprintf(buf, "%d\n", cm->local);
689 static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
692 cm->local= simple_strtol(buf, NULL, 0);
693 if (cm->local && !local_comm)
698 static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len)
700 struct sockaddr_storage *addr;
702 if (len != sizeof(struct sockaddr_storage))
705 if (cm->addr_count >= DLM_MAX_ADDR_COUNT)
708 addr = kzalloc(sizeof(*addr), GFP_KERNEL);
712 memcpy(addr, buf, len);
713 cm->addr[cm->addr_count++] = addr;
717 static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
720 struct dlm_node *nd = config_item_to_node(i);
721 struct node_attribute *nda =
722 container_of(a, struct node_attribute, attr);
723 return nda->show ? nda->show(nd, buf) : 0;
726 static ssize_t store_node(struct config_item *i, struct configfs_attribute *a,
727 const char *buf, size_t len)
729 struct dlm_node *nd = config_item_to_node(i);
730 struct node_attribute *nda =
731 container_of(a, struct node_attribute, attr);
732 return nda->store ? nda->store(nd, buf, len) : -EINVAL;
735 static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf)
737 return sprintf(buf, "%d\n", nd->nodeid);
740 static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
743 nd->nodeid = simple_strtol(buf, NULL, 0);
747 static ssize_t node_weight_read(struct dlm_node *nd, char *buf)
749 return sprintf(buf, "%d\n", nd->weight);
752 static ssize_t node_weight_write(struct dlm_node *nd, const char *buf,
755 nd->weight = simple_strtol(buf, NULL, 0);
760 * Functions for the dlm to get the info that's been configured
763 static struct dlm_space *get_space(char *name)
765 struct config_item *i;
770 mutex_lock(&space_list->cg_subsys->su_mutex);
771 i = config_group_find_item(space_list, name);
772 mutex_unlock(&space_list->cg_subsys->su_mutex);
774 return config_item_to_space(i);
777 static void put_space(struct dlm_space *sp)
779 config_item_put(&sp->group.cg_item);
782 static int addr_compare(struct sockaddr_storage *x, struct sockaddr_storage *y)
784 switch (x->ss_family) {
786 struct sockaddr_in *sinx = (struct sockaddr_in *)x;
787 struct sockaddr_in *siny = (struct sockaddr_in *)y;
788 if (sinx->sin_addr.s_addr != siny->sin_addr.s_addr)
790 if (sinx->sin_port != siny->sin_port)
795 struct sockaddr_in6 *sinx = (struct sockaddr_in6 *)x;
796 struct sockaddr_in6 *siny = (struct sockaddr_in6 *)y;
797 if (!ipv6_addr_equal(&sinx->sin6_addr, &siny->sin6_addr))
799 if (sinx->sin6_port != siny->sin6_port)
809 static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr)
811 struct config_item *i;
812 struct dlm_comm *cm = NULL;
818 mutex_lock(&clusters_root.subsys.su_mutex);
820 list_for_each_entry(i, &comm_list->cg_children, ci_entry) {
821 cm = config_item_to_comm(i);
824 if (cm->nodeid != nodeid)
830 if (!cm->addr_count || !addr_compare(cm->addr[0], addr))
837 mutex_unlock(&clusters_root.subsys.su_mutex);
844 static void put_comm(struct dlm_comm *cm)
846 config_item_put(&cm->item);
849 /* caller must free mem */
850 int dlm_nodeid_list(char *lsname, int **ids_out, int *ids_count_out,
851 int **new_out, int *new_count_out)
853 struct dlm_space *sp;
855 int i = 0, rv = 0, ids_count = 0, new_count = 0;
858 sp = get_space(lsname);
862 mutex_lock(&sp->members_lock);
863 if (!sp->members_count) {
865 printk(KERN_ERR "dlm: zero members_count\n");
869 ids_count = sp->members_count;
871 ids = kcalloc(ids_count, sizeof(int), GFP_KERNEL);
877 list_for_each_entry(nd, &sp->members, list) {
878 ids[i++] = nd->nodeid;
884 printk(KERN_ERR "dlm: bad nodeid count %d %d\n", ids_count, i);
889 new = kcalloc(new_count, sizeof(int), GFP_KERNEL);
897 list_for_each_entry(nd, &sp->members, list) {
899 new[i++] = nd->nodeid;
903 *new_count_out = new_count;
907 *ids_count_out = ids_count;
910 mutex_unlock(&sp->members_lock);
915 int dlm_node_weight(char *lsname, int nodeid)
917 struct dlm_space *sp;
921 sp = get_space(lsname);
925 mutex_lock(&sp->members_lock);
926 list_for_each_entry(nd, &sp->members, list) {
927 if (nd->nodeid != nodeid)
932 mutex_unlock(&sp->members_lock);
938 int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr)
940 struct dlm_comm *cm = get_comm(nodeid, NULL);
945 memcpy(addr, cm->addr[0], sizeof(*addr));
950 int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid)
952 struct dlm_comm *cm = get_comm(0, addr);
955 *nodeid = cm->nodeid;
960 int dlm_our_nodeid(void)
962 return local_comm ? local_comm->nodeid : 0;
965 /* num 0 is first addr, num 1 is second addr */
966 int dlm_our_addr(struct sockaddr_storage *addr, int num)
970 if (num + 1 > local_comm->addr_count)
972 memcpy(addr, local_comm->addr[num], sizeof(*addr));
976 /* Config file defaults */
977 #define DEFAULT_TCP_PORT 21064
978 #define DEFAULT_BUFFER_SIZE 4096
979 #define DEFAULT_RSBTBL_SIZE 256
980 #define DEFAULT_LKBTBL_SIZE 1024
981 #define DEFAULT_DIRTBL_SIZE 512
982 #define DEFAULT_RECOVER_TIMER 5
983 #define DEFAULT_TOSS_SECS 10
984 #define DEFAULT_SCAN_SECS 5
985 #define DEFAULT_LOG_DEBUG 0
986 #define DEFAULT_PROTOCOL 0
987 #define DEFAULT_TIMEWARN_CS 500 /* 5 sec = 500 centiseconds */
989 struct dlm_config_info dlm_config = {
990 .ci_tcp_port = DEFAULT_TCP_PORT,
991 .ci_buffer_size = DEFAULT_BUFFER_SIZE,
992 .ci_rsbtbl_size = DEFAULT_RSBTBL_SIZE,
993 .ci_lkbtbl_size = DEFAULT_LKBTBL_SIZE,
994 .ci_dirtbl_size = DEFAULT_DIRTBL_SIZE,
995 .ci_recover_timer = DEFAULT_RECOVER_TIMER,
996 .ci_toss_secs = DEFAULT_TOSS_SECS,
997 .ci_scan_secs = DEFAULT_SCAN_SECS,
998 .ci_log_debug = DEFAULT_LOG_DEBUG,
999 .ci_protocol = DEFAULT_PROTOCOL,
1000 .ci_timewarn_cs = DEFAULT_TIMEWARN_CS