Gitweb:
http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: 397a3d2f04f8ef0c5f771a394f513b727f1de337
Parent: 5237439984d1af73389de59bd3b1f6638186f34b
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Apr 10 15:25:51 2012 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Apr 10 15:35:06 2012 -0500
dlm_controld: lockspace config
read lockspace config from dlm.conf;
nodir and master weights
Signed-off-by: David Teigland <teigland(a)redhat.com>
---
dlm_controld/action.c | 15 ++++-
dlm_controld/config.c | 153 +++++++++++++++++++++++++++++++++++++++----
dlm_controld/cpg.c | 7 ++-
dlm_controld/dlm_daemon.h | 20 ++++--
dlm_controld/fence_config.c | 4 +-
dlm_controld/main.c | 5 +-
6 files changed, 175 insertions(+), 29 deletions(-)
diff --git a/dlm_controld/action.c b/dlm_controld/action.c
index 8ac05b6..d37d6ba 100644
--- a/dlm_controld/action.c
+++ b/dlm_controld/action.c
@@ -160,6 +160,16 @@ int set_sysfs_id(char *name, uint32_t id)
return do_sysfs(name, "id", buf);
}
+int set_sysfs_nodir(char *name, int val)
+{
+ char buf[32];
+
+ memset(buf, 0, sizeof(buf));
+ snprintf(buf, 32, "%d", val);
+
+ return do_sysfs(name, "nodir", buf);
+}
+
static int update_dir_members(char *name)
{
char path[PATH_MAX];
@@ -234,7 +244,8 @@ int path_exists(const char *path)
call to set_members(). We rmdir/mkdir for these nodes so dlm-kernel
can notice they've left and rejoined. */
-int set_configfs_members(char *name, int new_count, int *new_members,
+int set_configfs_members(struct lockspace *ls, char *name,
+ int new_count, int *new_members,
int renew_count, int *renew_members)
{
char path[PATH_MAX];
@@ -364,7 +375,7 @@ int set_configfs_members(char *name, int new_count, int *new_members,
* set node's weight
*/
- w = get_weight(id, name);
+ w = get_weight(ls, id);
memset(path, 0, PATH_MAX);
snprintf(path, PATH_MAX, "%s/%s/nodes/%d/weight",
diff --git a/dlm_controld/config.c b/dlm_controld/config.c
index 93c8d64..830a619 100644
--- a/dlm_controld/config.c
+++ b/dlm_controld/config.c
@@ -8,20 +8,145 @@
#include "dlm_daemon.h"
-/*
- * TODO: lockspace master/nodir/weight
- */
+#if 0
+
+lockspace ls_name [ls_args]
+master ls_name node=nodeid [node_args]
+master ls_name node=nodeid [node_args]
+master ls_name node=nodeid [node_args]
+
+lockspace foo nodir=1
+master node=1 weight=2
+master node=2 weight=1
+
+#endif
+
+/* The max line length in dlm.conf */
+
+#define MAX_LINE 256
+
+int get_weight(struct lockspace *ls, int nodeid)
+{
+ int i;
+
+ /* if no masters are defined, everyone defaults to weight 1 */
+
+ if (!ls->master_count)
+ return 1;
+
+ for (i = 0; i < ls->master_count; i++) {
+ if (ls->master_nodeid[i] == nodeid)
+ return ls->master_weight[i];
+ }
+
+ /* if masters are defined, non-masters default to weight 0 */
+
+ return 0;
+}
-int get_weight(int nodeid, char *lockspace)
+static void read_master_config(struct lockspace *ls, FILE *file)
{
- /* default weight is 1 */
- return 1;
+ char line[MAX_LINE];
+ char name[MAX_LINE];
+ char args[MAX_LINE];
+ char *k;
+ int nodeid, weight, i;
+
+ while (fgets(line, MAX_LINE, file)) {
+ if (line[0] == '\n')
+ break;
+ if (line[0] == ' ')
+ break;
+ if (line[0] == '#')
+ continue;
+
+ if (strncmp(line, "master", strlen("master")))
+ break;
+
+ memset(name, 0, sizeof(name));
+ memset(args, 0, sizeof(args));
+ nodeid = 0;
+ weight = 1;
+
+ sscanf(line, "master %s %[^\n]s", name, args);
+
+ if (strcmp(name, ls->name))
+ break;
+
+ k = strstr(args, "node=");
+ if (!k)
+ break;
+
+ sscanf(k, "node=%d", &nodeid);
+ if (!nodeid)
+ break;
+
+ k = strstr(args, "weight=");
+ if (k)
+ sscanf(k, "weight=%d", &weight);
+
+ log_debug("config lockspace %s nodeid %d weight %d",
+ ls->name, nodeid, weight);
+
+ i = ls->master_count++;
+ ls->master_nodeid[i] = nodeid;
+ ls->master_weight[i] = weight;
+
+ if (ls->master_count >= MAX_NODES)
+ break;
+ }
+}
+
+void setup_lockspace_config(struct lockspace *ls)
+{
+ FILE *file;
+ char line[MAX_LINE];
+ char name[MAX_LINE];
+ char args[MAX_LINE];
+ char *k;
+ int val;
+
+ if (!path_exists(CONF_FILE_PATH))
+ return;
+
+ file = fopen(CONF_FILE_PATH, "r");
+ if (!file)
+ return;
+
+ while (fgets(line, MAX_LINE, file)) {
+ if (line[0] == '#')
+ continue;
+ if (line[0] == '\n')
+ continue;
+
+ if (strncmp(line, "lockspace", strlen("lockspace")))
+ continue;
+
+ memset(name, 0, sizeof(name));
+ memset(args, 0, sizeof(args));
+ val = 0;
+
+ sscanf(line, "lockspace %s %[^\n]s", name, args);
+
+ if (strcmp(name, ls->name))
+ continue;
+
+ k = strstr(args, "nodir=");
+ if (k) {
+ sscanf(k, "nodir=%d", &val);
+ ls->nodir = val;
+ }
+
+ read_master_config(ls, file);
+ }
+
+ fclose(file);
}
static void get_val_int(char *line, int *val_out)
{
- char key[PATH_MAX];
- char val[PATH_MAX];
+ char key[MAX_LINE];
+ char val[MAX_LINE];
int rv;
rv = sscanf(line, "%[^=]=%s", key, val);
@@ -33,8 +158,8 @@ static void get_val_int(char *line, int *val_out)
static void get_val_str(char *line, char *val_out)
{
- char key[PATH_MAX];
- char val[PATH_MAX];
+ char key[MAX_LINE];
+ char val[MAX_LINE];
int rv;
rv = sscanf(line, "%[^=]=%s", key, val);
@@ -48,8 +173,8 @@ void set_opt_file(int update)
{
struct dlm_option *o;
FILE *file;
- char line[PATH_MAX];
- char str[PATH_MAX];
+ char line[MAX_LINE];
+ char str[MAX_LINE];
int i, val;
if (!path_exists(CONF_FILE_PATH))
@@ -59,7 +184,7 @@ void set_opt_file(int update)
if (!file)
return;
- while (fgets(line, PATH_MAX, file)) {
+ while (fgets(line, MAX_LINE, file)) {
if (line[0] == '#')
continue;
if (line[0] == '\n')
@@ -67,7 +192,7 @@ void set_opt_file(int update)
memset(str, 0, sizeof(str));
- for (i = 0; i < PATH_MAX; i++) {
+ for (i = 0; i < MAX_LINE; i++) {
if (line[i] == ' ')
break;
if (line[i] == '=')
diff --git a/dlm_controld/cpg.c b/dlm_controld/cpg.c
index 49fb06a..6e508d2 100644
--- a/dlm_controld/cpg.c
+++ b/dlm_controld/cpg.c
@@ -552,9 +552,12 @@ static void start_kernel(struct lockspace *ls)
if (ls->joining)
set_sysfs_id(ls->name, ls->global_id);
+ if (ls->nodir)
+ set_sysfs_nodir(ls->name, 1);
+
format_member_ids(ls);
format_renew_ids(ls);
- set_configfs_members(ls->name, member_count, member_ids,
+ set_configfs_members(ls, ls->name, member_count, member_ids,
renew_count, renew_ids);
set_sysfs_control(ls->name, 1);
ls->kernel_stopped = 0;
@@ -1347,7 +1350,7 @@ static void confchg_cb(cpg_handle_t handle,
cpg callback we receive */
log_group(ls, "confchg for our leave");
stop_kernel(ls, 0);
- set_configfs_members(ls->name, 0, NULL, 0, NULL);
+ set_configfs_members(ls, ls->name, 0, NULL, 0, NULL);
set_sysfs_event_done(ls->name, 0);
cpg_finalize(ls->cpg_handle);
client_dead(ls->cpg_client);
diff --git a/dlm_controld/dlm_daemon.h b/dlm_controld/dlm_daemon.h
index 6fef5b4..93451ee 100644
--- a/dlm_controld/dlm_daemon.h
+++ b/dlm_controld/dlm_daemon.h
@@ -155,10 +155,6 @@ EXTERN struct dlm_option dlm_options[dlm_options_max];
#define MAX_NODE_ADDRESSES 4
-/* Max string length printed on a line, for debugging/dump output. */
-
-#define MAXLINE 256
-
#define PROTO_TCP 0
#define PROTO_SCTP 1
#define PROTO_DETECT 2
@@ -243,6 +239,13 @@ struct lockspace {
char name[DLM_LOCKSPACE_LEN+1];
uint32_t global_id;
+ /* dlm.conf config */
+
+ int nodir;
+ int master_count;
+ int master_nodeid[MAX_NODES];
+ int master_weight[MAX_NODES];
+
/* lockspace membership stuff */
cpg_handle_t cpg_handle;
@@ -295,8 +298,10 @@ struct lockspace {
int set_sysfs_control(char *name, int val);
int set_sysfs_event_done(char *name, int val);
int set_sysfs_id(char *name, uint32_t id);
-int set_configfs_members(char *name, int new_count, int *new_members,
- int renew_count, int *renew_members);
+int set_sysfs_nodir(char *name, int val);
+int set_configfs_members(struct lockspace *ls, char *name,
+ int new_count, int *new_members,
+ int renew_count, int *renew_members);
int add_configfs_node(int nodeid, char *addr, int addrlen, int local);
void del_configfs_node(int nodeid);
void clear_configfs(void);
@@ -308,7 +313,8 @@ int path_exists(const char *path);
/* config.c */
void set_opt_file(int update);
-int get_weight(int nodeid, char *lockspace);
+int get_weight(struct lockspace *ls, int nodeid);
+void setup_lockspace_config(struct lockspace *ls);
/* cpg.c */
void process_lockspace_changes(void);
diff --git a/dlm_controld/fence_config.c b/dlm_controld/fence_config.c
index f886630..66a1ad6 100644
--- a/dlm_controld/fence_config.c
+++ b/dlm_controld/fence_config.c
@@ -157,9 +157,7 @@ static int read_config_section(unsigned int nodeid, FILE *file, char
*dev_line,
memset(con_name, 0, sizeof(con_name));
memset(con_args, 0, sizeof(con_args));
- rv = sscanf(line, "%s %s %[^\n]s", unused, con_name, con_args);
- if (rv < 3)
- return -EINVAL;
+ sscanf(line, "%s %s %[^\n]s", unused, con_name, con_args);
/* invalid config */
if (strncmp(dev_name, con_name, FENCE_CONFIG_NAME_MAX))
diff --git a/dlm_controld/main.c b/dlm_controld/main.c
index 14ac1c7..95abe12 100644
--- a/dlm_controld/main.c
+++ b/dlm_controld/main.c
@@ -188,6 +188,7 @@ static struct lockspace *create_ls(char *name)
INIT_LIST_HEAD(&ls->transactions);
INIT_LIST_HEAD(&ls->resources);
#endif
+ setup_lockspace_config(ls);
out:
return ls;
}
@@ -312,10 +313,12 @@ const char *dlm_mode_str(int mode)
/* recv "online" (join) and "offline" (leave) messages from dlm via
uevents */
+#define MAX_LINE_UEVENT 256
+
static void process_uevent(int ci)
{
struct lockspace *ls;
- char buf[MAXLINE];
+ char buf[MAX_LINE_UEVENT];
char *argv[MAXARGS], *act, *sys;
int rv, argc = 0;