[Cluster-devel] cluster/rgmanager include/res-ocf.h include/re ...
lhh at sourceware.org
lhh at sourceware.org
Sat Mar 10 00:20:58 UTC 2007
CVSROOT: /cvs/cluster
Module name: cluster
Changes by: lhh at sourceware.org 2007-03-10 00:20:55
Modified files:
rgmanager/include: res-ocf.h resgroup.h reslist.h
rgmanager/src/clulib: rg_strings.c
rgmanager/src/daemons: groups.c restree.c rg_state.c rg_thread.c
test.c
rgmanager/src/resources: Makefile lvm.sh vm.sh
rgmanager/src/utils: clusvcadm.c
Log message:
Strings cleanup. Enable vm.sh live migration.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/include/res-ocf.h.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/include/resgroup.h.diff?cvsroot=cluster&r1=1.17&r2=1.18
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/include/reslist.h.diff?cvsroot=cluster&r1=1.16&r2=1.17
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/clulib/rg_strings.c.diff?cvsroot=cluster&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/daemons/groups.c.diff?cvsroot=cluster&r1=1.27&r2=1.28
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/daemons/restree.c.diff?cvsroot=cluster&r1=1.25&r2=1.26
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/daemons/rg_state.c.diff?cvsroot=cluster&r1=1.28&r2=1.29
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/daemons/rg_thread.c.diff?cvsroot=cluster&r1=1.17&r2=1.18
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/daemons/test.c.diff?cvsroot=cluster&r1=1.7&r2=1.8
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/Makefile.diff?cvsroot=cluster&r1=1.16&r2=1.17
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/lvm.sh.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/vm.sh.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/utils/clusvcadm.c.diff?cvsroot=cluster&r1=1.16&r2=1.17
--- cluster/rgmanager/include/res-ocf.h 2004/08/13 15:36:50 1.1
+++ cluster/rgmanager/include/res-ocf.h 2007/03/10 00:20:54 1.2
@@ -45,4 +45,22 @@
#define OCF_RA_NOT_RUNNING 7
#define OCF_RA_MAX 7
+/*
+ Resource operations - not ocf-specified
+ */
+#define RS_START (0)
+#define RS_STOP (1)
+#define RS_STATUS (2)
+#define RS_RESINFO (3)
+#define RS_RESTART (4)
+#define RS_RELOAD (5)
+#define RS_CONDRESTART (6)
+#define RS_RECOVER (7)
+#define RS_CONDSTART (8) /** Start if flagged with RF_NEEDSTART */
+#define RS_CONDSTOP (9) /** STOP if flagged with RF_NEEDSTOP */
+#define RS_MONITOR (10)
+#define RS_META_DATA (11)
+#define RS_VALIDATE (12)
+#define RS_MIGRATE (13)
+
#endif
--- cluster/rgmanager/include/resgroup.h 2006/12/14 22:18:07 1.17
+++ cluster/rgmanager/include/resgroup.h 2007/03/10 00:20:54 1.18
@@ -81,9 +81,7 @@
#define RG_MIGRATE 22
#define RG_NONE 999
-extern const char *rg_req_strings[];
-
-#define rg_req_str(req) (rg_req_strings[req])
+const char *rg_req_str(int req);
int handle_relocate_req(char *svcName, int request, int preferred_target,
int *new_owner);
@@ -107,9 +105,8 @@
#define DEFAULT_CHECK_INTERVAL 10
-extern const char *rg_state_strings[];
-
-#define rg_state_str(state) (rg_state_strings[state - RG_STATE_BASE])
+const char *rg_state_str(int val);
+const char *agent_op_str(int val);
int rg_status(const char *resgroupname);
int group_op(char *rgname, int op);
@@ -175,7 +172,7 @@
#define RG_YES 1
#define RG_NO 2
-char *rg_strerror(int val);
+const char *rg_strerror(int val);
/*
--- cluster/rgmanager/include/reslist.h 2007/01/26 21:42:24 1.16
+++ cluster/rgmanager/include/reslist.h 2007/03/10 00:20:54 1.17
@@ -40,25 +40,6 @@
#define RES_STARTED (1)
#define RES_FAILED (2)
-/*
- Resource operations
- */
-#define RS_START (0)
-#define RS_STOP (1)
-#define RS_STATUS (2)
-#define RS_RESINFO (3)
-#define RS_RESTART (4)
-#define RS_RELOAD (5)
-#define RS_CONDRESTART (6)
-#define RS_RECOVER (7)
-#define RS_CONDSTART (8) /** Start if flagged with RF_NEEDSTART */
-#define RS_CONDSTOP (9) /** STOP if flagged with RF_NEEDSTOP */
-#define RS_MONITOR (10)
-#define RS_META_DATA (11)
-#define RS_VALIDATE (12)
-#define RS_MIGRATE (13)
-
-
#ifndef SHAREDIR
#define SHAREDIR "/usr/share/rgmanager"
#endif
--- cluster/rgmanager/src/clulib/rg_strings.c 2006/12/14 22:18:07 1.6
+++ cluster/rgmanager/src/clulib/rg_strings.c 2007/03/10 00:20:54 1.7
@@ -16,9 +16,16 @@
Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
MA 02139, USA.
*/
+#include <res-ocf.h>
#include <resgroup.h>
-struct { int val; char *str; } rg_error_strings[] = {
+struct string_val {
+ int val;
+ char *str;
+};
+
+
+const struct string_val rg_error_strings[] = {
{ RG_ERUN, "Service is already running" },
{ RG_EQUORUM, "Operation requires quorum" },
{ RG_EINVAL, "Invalid operation for resource" },
@@ -36,53 +43,107 @@
};
-char *rg_strerror(int err)
+const struct string_val rg_req_strings[] = {
+ {RG_SUCCESS, "success" },
+ {RG_FAIL, "fail"},
+ {RG_START, "start"},
+ {RG_STOP, "stop"},
+ {RG_STATUS, "status"},
+ {RG_DISABLE, "disable"},
+ {RG_STOP_RECOVER, "stop (recovery)"},
+ {RG_START_RECOVER, "start (recovery)"},
+ {RG_RESTART, "restart"},
+ {RG_EXITING, "exiting"},
+ {RG_INIT, "initialize"},
+ {RG_ENABLE, "enable"},
+ {RG_STATUS_NODE, "status inquiry"},
+ {RG_RELOCATE, "relocate"},
+ {RG_CONDSTOP, "conditional stop"},
+ {RG_CONDSTART, "conditional start"},
+ {RG_START_REMOTE,"remote start"},
+ {RG_STOP_USER, "user stop"},
+ {RG_STOP_EXITING, "stop (shutdown)"},
+ {RG_LOCK, "locking"},
+ {RG_UNLOCK, "unlocking"},
+ {RG_QUERY_LOCK, "lock status inquiry"},
+ {RG_MIGRATE, "migrate"},
+ {RG_NONE, "none"},
+ {0, NULL}
+};
+
+
+const struct string_val rg_state_strings[] = {
+ {RG_STATE_STOPPED, "stopped"},
+ {RG_STATE_STARTING, "starting"},
+ {RG_STATE_STARTED, "started"},
+ {RG_STATE_STOPPING, "stopping"},
+ {RG_STATE_FAILED, "failed"},
+ {RG_STATE_UNINITIALIZED, "uninitialized"},
+ {RG_STATE_CHECK, "checking"},
+ {RG_STATE_ERROR, "recoverable"},
+ {RG_STATE_RECOVER, "recovering"},
+ {RG_STATE_DISABLED, "disabled"},
+ {RG_STATE_MIGRATE, "migrating"},
+ {0, NULL}
+};
+
+
+const struct string_val agent_ops[] = {
+ {RS_START, "start"},
+ {RS_STOP, "stop"},
+ {RS_STATUS, "status"},
+ {RS_RESINFO, "resinfo"},
+ {RS_RESTART, "restart"},
+ {RS_RELOAD, "reload"},
+ {RS_CONDRESTART, "condrestart"}, /* Unused */
+ {RS_RECOVER, "recover"},
+ {RS_CONDSTART, "condstart"},
+ {RS_CONDSTOP, "condstop"},
+ {RS_MONITOR, "monitor"},
+ {RS_META_DATA, "meta-data"}, /* printenv */
+ {RS_VALIDATE, "validate-all"},
+ {RS_MIGRATE, "migrate"},
+ {0 , NULL}
+};
+
+
+static inline const char *
+rg_search_table(const struct string_val *table, int val)
{
int x;
- for (x = 0; rg_error_strings[x].str != NULL; x++) {
- if (rg_error_strings[x].val == err) {
- return rg_error_strings[x].str;
+ for (x = 0; table[x].str != NULL; x++) {
+ if (table[x].val == val) {
+ return table[x].str;
}
}
return "Unknown";
}
+
+
+const char *
+rg_strerror(int val)
+{
+ return rg_search_table(rg_error_strings, val);
+}
+const char *
+rg_state_str(int val)
+{
+ return rg_search_table(rg_state_strings, val);
+}
-const char *rg_state_strings[] = {
- "stopped",
- "starting",
- "started",
- "stopping",
- "failed",
- "uninitialized",
- "checking",
- "recoverable",
- "recovering",
- "disabled",
- ""
-};
-const char *rg_req_strings[] = {
- "success",
- "fail",
- "start",
- "stop",
- "status",
- "disable",
- "stop (recovery)",
- "start (recovery)",
- "restart",
- "exiting",
- "initialize",
- "enable",
- "status inquiry",
- "relocate",
- "conditional stop",
- "conditional start",
- "remote start",
- "user stop",
- ""
-};
+const char *
+rg_req_str(int val)
+{
+ return rg_search_table(rg_req_strings, val);
+}
+
+const char *
+agent_op_str(int val)
+{
+ return rg_search_table(agent_ops, val);
+}
--- cluster/rgmanager/src/daemons/groups.c 2007/02/21 20:49:17 1.27
+++ cluster/rgmanager/src/daemons/groups.c 2007/03/10 00:20:54 1.28
@@ -36,7 +36,6 @@
#define cn_svccount cn_address.cna_address[0] /* Theses are uint8_t size */
#define cn_svcexcl cn_address.cna_address[1]
-extern char *res_ops[];
static int config_version = 0;
static resource_t *_resources = NULL;
static resource_rule_t *_rules = NULL;
@@ -734,9 +733,10 @@
int
group_migrate(char *groupname, int target)
{
+ resource_node_t *rn = NULL, *tmp;
resource_t *res;
char *tgt_name;
- int ret = RG_ENOSERVICE;
+ int ret = RG_ENOSERVICE, x = 0;
cluster_member_list_t *membership;
membership = member_list();
@@ -746,15 +746,26 @@
pthread_rwlock_rdlock(&resource_lock);
tgt_name = memb_id_to_name(membership, target);
+ if (!tgt_name) {
+ ret = RG_EINVAL;
+ goto out;
+ }
+
res = find_root_by_ref(&_resources, groupname);
if (!res)
goto out;
- if (!tgt_name) {
- ret = RG_EINVAL;
+ list_do(&_tree, tmp) {
+ if (tmp->rn_resource == res) {
+ rn = tmp;
+ break;
+ }
+ } while (!list_done(&_tree, tmp));
+
+ if (!rn)
goto out;
- }
- ret = res_exec(res, res_ops[RG_MIGRATE], tgt_name);
+
+ ret = res_exec(rn, agent_op_str(RS_MIGRATE), tgt_name);
out:
pthread_rwlock_unlock(&resource_lock);
@@ -1009,7 +1020,8 @@
}
if (svcblk.rs_owner != my_id() ||
- svcblk.rs_state != RG_STATE_STARTED)
+ (svcblk.rs_state != RG_STATE_STARTED &&
+ svcblk.rs_state != RG_STATE_MIGRATE))
continue;
rt_enqueue_request(rg, RG_STATUS,
--- cluster/rgmanager/src/daemons/restree.c 2007/02/22 16:37:28 1.25
+++ cluster/rgmanager/src/daemons/restree.c 2007/03/10 00:20:54 1.26
@@ -60,23 +60,6 @@
time_t get_time(char *action, int depth, resource_node_t *node);
-const char *res_ops[] = {
- "start",
- "stop",
- "status",
- "resinfo",
- "restart",
- "reload",
- "condrestart", /* Unused */
- "recover",
- "condstart",
- "condstop",
- "monitor",
- "meta-data", /* printenv */
- "validate-all",
- "migrate"
-};
-
const char *ocf_errors[] = {
"success", // 0
@@ -97,14 +80,13 @@
const char *
ocf_strerror(int ret)
{
- if (ret < OCF_RA_MAX)
+ if (ret >= 0 && ret < OCF_RA_MAX)
return ocf_errors[ret];
return "unspecified";
}
-
/**
Destroys an environment variable array.
@@ -360,7 +342,7 @@
#endif
#if 0
printf("Exec of script %s, action %s type %s\n",
- res->r_rule->rr_agent, res_ops[op],
+ res->r_rule->rr_agent, agent_op_str(op),
res->r_rule->rr_type);
#endif
@@ -705,7 +687,7 @@
#if 0
printf("%s children of %s type %s (level %d)\n",
- res_ops[op],
+ agent_op_str(op),
node->rn_resource->r_rule->rr_type,
rule->rr_childtypes[x].rc_name, l);
#endif
@@ -748,7 +730,7 @@
/*
printf("%s children of %s type %s (default level)\n",
- res_ops[op],
+ agent_op_str(op),
node->rn_resource->r_rule->rr_type,
rule->rr_childtypes[x].rc_name);
*/
@@ -856,7 +838,7 @@
return 0;
node->rn_actions[idx].ra_last = now;
- if ((x = res_exec(node, res_ops[RS_STATUS], NULL,
+ if ((x = res_exec(node, agent_op_str(RS_STATUS), NULL,
node->rn_actions[idx].ra_depth)) == 0)
return 0;
@@ -864,7 +846,7 @@
return x;
/* Strange/failed status. Try to recover inline. */
- if ((x = res_exec(node, res_ops[RS_RECOVER], NULL, 0)) == 0)
+ if ((x = res_exec(node, agent_op_str(RS_RECOVER), NULL, 0)) == 0)
return 0;
return x;
@@ -969,7 +951,7 @@
me = !first || (node->rn_resource == first);
/*
- printf("begin %s: %s %s [0x%x]\n", res_ops[op],
+ printf("begin %s: %s %s [0x%x]\n", agent_op_str(op),
node->rn_resource->r_rule->rr_type,
primary_attr_value(node->rn_resource),
node->rn_flags);
@@ -1014,7 +996,7 @@
if (me && (op == RS_START)) {
node->rn_flags &= ~RF_NEEDSTART;
- rv = res_exec(node, res_ops[op], NULL, 0);
+ rv = res_exec(node, agent_op_str(op), NULL, 0);
if (rv != 0) {
node->rn_state = RES_FAILED;
return rv;
@@ -1044,7 +1026,7 @@
/* Stop should occur after children have stopped */
if (me && (op == RS_STOP)) {
node->rn_flags &= ~RF_NEEDSTOP;
- rv = res_exec(node, res_ops[op], NULL, 0);
+ rv = res_exec(node, agent_op_str(op), NULL, 0);
if (rv != 0) {
node->rn_state = RES_FAILED;
@@ -1058,7 +1040,7 @@
}
/*
- printf("end %s: %s %s\n", res_ops[op],
+ printf("end %s: %s %s\n", agent_op_str(op),
node->rn_resource->r_rule->rr_type,
primary_attr_value(node->rn_resource));
*/
--- cluster/rgmanager/src/daemons/rg_state.c 2007/02/20 19:54:42 1.28
+++ cluster/rgmanager/src/daemons/rg_state.c 2007/03/10 00:20:54 1.29
@@ -866,6 +866,10 @@
rg_unlock(&lockp);
ret = group_migrate(svcName, target);
+
+ if (ret)
+ svc_fail(svcName);
+
return ret;
}
--- cluster/rgmanager/src/daemons/rg_thread.c 2006/12/14 20:11:04 1.17
+++ cluster/rgmanager/src/daemons/rg_thread.c 2007/03/10 00:20:54 1.18
@@ -163,7 +163,7 @@
char myname[256];
resthread_t *myself;
request_t *req;
- uint32_t ret = RG_FAIL, error = 0;
+ int ret = RG_EFAIL, error = 0;
rg_inc_threads();
@@ -274,7 +274,7 @@
/*
* Bad news.
*/
- ret = RG_FAIL;
+ ret = RG_EFAIL;
}
break;
@@ -289,7 +289,7 @@
if (error == 0)
ret = RG_SUCCESS;
else
- ret = RG_FAIL;
+ ret = RG_EFAIL;
break;
case RG_CONDSTOP:
@@ -321,7 +321,7 @@
/*
* Bad news.
*/
- ret = RG_FAIL;
+ ret = RG_EFAIL;
}
break;
@@ -340,7 +340,7 @@
/*
* Bad news.
*/
- ret = RG_FAIL;
+ ret = RG_EFAIL;
}
pthread_mutex_lock(&my_queue_mutex);
@@ -368,7 +368,7 @@
/*
* Bad news.
*/
- ret = RG_FAIL;
+ ret = RG_EFAIL;
}
break;
@@ -393,7 +393,7 @@
/*
* Bad news.
*/
- ret = RG_FAIL;
+ ret = RG_EFAIL;
}
break;
--- cluster/rgmanager/src/daemons/test.c 2007/02/20 19:56:18 1.7
+++ cluster/rgmanager/src/daemons/test.c 2007/03/10 00:20:54 1.8
@@ -111,7 +111,7 @@
dep_t *depends = NULL;
resource_rule_t *rulelist = NULL, *currule;
resource_t *reslist = NULL, *curres;
- resource_node_t *tree = NULL;
+ resource_node_t *tree = NULL, *tmp, *rn = NULL;
int ccsfd, ret = 0, rules = 0;
fprintf(stderr,"Running in test mode.\n");
@@ -179,6 +179,13 @@
goto out;
}
+ list_do(&tree, tmp) {
+ if (tmp->rn_resource == curres) {
+ rn = tmp;
+ break;
+ }
+ } while (!list_done(&tree, tmp));
+
if (!strcmp(argv[1], "start")) {
printf("Starting %s...\n", argv[3]);
@@ -198,6 +205,23 @@
}
printf("Stop of %s complete\n", argv[3]);
goto out;
+ } else if (!strcmp(argv[1], "migrate")) {
+ printf("Migrating %s to %s...\n", argv[3], argv[4]);
+
+ #if 0
+ if (!group_migratory(curres)) {
+ printf("No can do\n");
+ ret = -1;
+ goto out;
+ }
+ #endif
+
+ if (res_exec(rn, "migrate", argv[4], 0)) {
+ ret = -1;
+ goto out;
+ }
+ printf("Migration of %s complete\n", argv[3]);
+ goto out;
} else if (!strcmp(argv[1], "status")) {
printf("Checking status of %s...\n", argv[3]);
--- cluster/rgmanager/src/resources/Makefile 2007/02/15 22:51:03 1.16
+++ cluster/rgmanager/src/resources/Makefile 2007/03/10 00:20:54 1.17
@@ -20,7 +20,7 @@
RESOURCES=fs.sh service.sh ip.sh nfsclient.sh nfsexport.sh \
script.sh netfs.sh clusterfs.sh smb.sh \
apache.sh openldap.sh samba.sh mysql.sh \
- postgres-8.sh tomcat-5.sh lvm.sh
+ postgres-8.sh tomcat-5.sh lvm.sh vm.sh
METADATA=apache.metadata openldap.metadata samba.metadata \
mysql.metadata postgres-8.metadata tomcat-5.metadata
--- cluster/rgmanager/src/resources/lvm.sh 2007/02/15 22:51:03 1.2
+++ cluster/rgmanager/src/resources/lvm.sh 2007/03/10 00:20:54 1.3
@@ -163,7 +163,7 @@
#
# Check if device is active
#
- if [[ ! $(lvs -o attr --noheadings vg/mirror) =~ ....a. ]]; then
+ if [[ ! $(lvs -o attr --noheadings $lv_path) =~ ....a. ]]; then
return $OCF_ERR_GENERIC
fi
--- cluster/rgmanager/src/resources/vm.sh 2006/10/23 22:47:01 1.1
+++ cluster/rgmanager/src/resources/vm.sh 2007/03/10 00:20:54 1.2
@@ -367,14 +367,15 @@
{
declare target=$1
- # XXX TODO
- return 1
+ xm migrate $OCF_RESKEY_name $target
+ return $?
}
#
# A Resource group is abstract, but the OCF RA API doesn't allow for abstract
# resources, so here it is.
#
+
case $1 in
start)
start
--- cluster/rgmanager/src/utils/clusvcadm.c 2007/03/10 00:19:01 1.16
+++ cluster/rgmanager/src/utils/clusvcadm.c 2007/03/10 00:20:54 1.17
@@ -265,13 +265,13 @@
break;
case 'r':
/* RELOCATE */
- actionstr = "trying to relocate";
+ actionstr = "relocate";
action = RG_RELOCATE;
svcname = optarg;
break;
case 'M':
/* MIGRATE */
- actionstr = "trying to migrate";
+ actionstr = "migrate";
action = RG_MIGRATE;
svcname = optarg;
break;
@@ -359,9 +359,9 @@
msg_open(MSG_SOCKET, 0, RG_PORT, &ctx, 5);
} else {
if (!svctarget)
- printf("Trying to relocate %s", svcname);
+ printf("Trying to %s %s", actionstr, svcname);
else
- printf("Trying to relocate %s to %s", svcname,
+ printf("Trying to %s %s to %s", actionstr, svcname,
nodename);
printf("...");
fflush(stdout);
@@ -392,12 +392,13 @@
swab_SmMessageSt(&msg);
printf("%s\n", rg_strerror(msg.sm_data.d_ret));
-
if (msg.sm_data.d_ret == RG_ERUN)
return 0;
+ if (msg.sm_data.d_ret)
+ return msg.sm_data.d_ret;
switch (action) {
- case RG_MIGRATE:
+ /*case RG_MIGRATE:*/
case RG_RELOCATE:
case RG_START:
case RG_ENABLE:
More information about the Cluster-devel
mailing list