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