Send Linux-ha-cvs mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]
You can reach the person managing the list at
[EMAIL PROTECTED]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Linux-ha-cvs digest..."
Today's Topics:
1. Linux-HA CVS: cim by panjiam from
([email protected])
----------------------------------------------------------------------
Message: 1
Date: Thu, 13 Apr 2006 01:58:36 -0600 (MDT)
From: [email protected]
Subject: [Linux-ha-cvs] Linux-HA CVS: cim by panjiam from
To: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>
linux-ha CVS committal
Author : panjiam
Host :
Project : linux-ha
Module : cim
Dir : linux-ha/cim
Modified Files:
cluster_info.c cluster_info.h
Log Message:
1. re-order the functions.
2. add functions for handling attributes update.
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/cim/cluster_info.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- cluster_info.c 10 Apr 2006 10:11:02 -0000 1.5
+++ cluster_info.c 13 Apr 2006 07:58:35 -0000 1.6
@@ -88,6 +88,7 @@
static int cib_changed(void);
static struct ha_msg* cim_disk2msg(const char *objpathname);
static int cim_msg2disk(const char *objpathname, struct ha_msg *);
+static int cim_disk_msg_del(const char *objpathname);
#define STR_CONS_ORDER "rsc_order"
#define STR_CONS_LOCATION "rsc_location"
@@ -215,8 +216,8 @@
END_NODE;
static const char attributes []=
-BEGIN_NODE "instance_attributes"
- BEGIN_NODE "attributes" REPEATE ANYTIMES
+BEGIN_NODE CIM_MSG_INST_ATTR
+ BEGIN_NODE CIM_MSG_ATTR REPEATE ANYTIMES
BEGIN_KEY "id" END_KEY
BEGIN_KEY "name" END_KEY
BEGIN_KEY "value" END_KEY
@@ -364,7 +365,7 @@
BEGIN_KEY "clone_node_max" END_KEY
BEGIN_KEY "master_max" END_KEY
BEGIN_KEY "master_node_max" END_KEY
- BEGIN_NODE "attributes" REPEATE
+ BEGIN_NODE CIM_MSG_ATTR REPEATE
BEGIN_KEY "id" END_KEY
BEGIN_KEY "name" END_KEY
BEGIN_KEY "value" END_KEY
@@ -375,6 +376,8 @@
{DEL_OPERATION, A_1(MSG_DEL_RSC_OP), NULL, NULL},
{DEL_ATTRIBUTES, A_1(MSG_DEL_RSC_PARAM),NULL, NULL},
{DEL_RESOURCE, A_1(MSG_DEL_RSC), NULL, NULL},
+ {CLEANUP_RESOURCE, A_1(MSG_CLEANUP_RSC), NULL, NULL},
+
{CREATE_RSC_GROUP, A_1(MSG_ADD_GRP),NULL, NULL},
{CREATE_RESOURCE, A_1(MSG_ADD_RSC), resource, node_update},
{DEL_ORDER_CONSTRAINT,
@@ -524,7 +527,6 @@
int ret = HA_OK;
int i = 0;
- DEBUG_ENTER();
if ((ctx = find_update_ctx(func_id)) == NULL ) {
cl_log(LOG_ERR, "cim_update: can't find function %d", func_id);
return HA_FAIL;
@@ -548,11 +550,13 @@
}
if ( ret == HA_OK ) {
- mclient_process(client);
+ if ( mclient_process(client) != MC_OK ) {
+ cl_log(LOG_ERR, "%s: update failed.", __FUNCTION__);
+ ret = HA_FAIL;
+ }
}
mclient_free(client);
- DEBUG_LEAVE();
return ret;
}
@@ -1269,6 +1273,19 @@
return msg;
}
+
+static int
+cim_disk_msg_del(const char *objpathname)
+{
+ char fullpathname[MAXLEN];
+ char * pathname = pathname_encode(objpathname);
+ snprintf(fullpathname, MAXLEN, "%s/%s", HA_CIM_VARDIR, pathname);
+ cim_debug2(LOG_INFO, "%s: unlink %s", __FUNCTION__, fullpathname);
+ unlink(fullpathname);
+ cim_free(pathname);
+ return HA_OK;
+}
+
static char*
pathname_encode(const char *pathname)
{
@@ -1297,11 +1314,51 @@
return 1;
}
+#define CLEAN_RESOURCE_RECORD(resid) do { \
+ cim_update_disabled_rsc_list(0, rscid); \
+ cim_erase_rscattrs(rscid); \
+ cim_remove_rsctype(rscid); \
+}while(0)
+
+/****************************************************************
+ * resource list
+ ***************************************************************/
+#define CIM_DISABLED_RSC_LIST "disabled_resource_list"
+int
+cim_is_rsc_disabled(const char *rscid)
+{
+ int len, i;
+ struct ha_msg * msg = NULL;
+
+ if ((msg = cim_get_disabled_rsc_list()) == NULL ) {
+ cim_debug2(LOG_INFO, "%s: %s is enabled", __FUNCTION__, rscid);
+ return FALSE;
+ }
+
+ len = cim_list_length(msg);
+ for(i=0; i < len; i++) {
+ char * rsc = NULL;
+ if((rsc = cim_list_index(msg, i)) == NULL ) {
+ continue;
+ }
+ if ( strncmp(rscid, rsc, MAXLEN) == 0){
+ ha_msg_del(msg);
+ cim_debug2(LOG_INFO, "%s: %s is disabled",
__FUNCTION__, rscid);
+ return TRUE;
+ }
+ }
+
+ ha_msg_del(msg);
+
+ cim_debug2(LOG_INFO, "%s: %s is enabled", __FUNCTION__, rscid);
+ return FALSE;
+}
+
struct ha_msg *
cim_get_disabled_rsc_list(void)
{
cim_debug2(LOG_INFO, "get disabled resource list");
- return cim_disk2msg("disabled_rsc_list");
+ return cim_disk2msg(CIM_DISABLED_RSC_LIST);
}
int
@@ -1346,7 +1403,12 @@
}
/* write to disk */
- cim_msg2disk("disabled_rsc_list", msg);
+ if ( msg->nfields == 0 ) {
+ cim_debug2(LOG_INFO, "%s: delete %s", __FUNCTION__,
CIM_DISABLED_RSC_LIST);
+ cim_disk_msg_del(CIM_DISABLED_RSC_LIST);
+ } else {
+ cim_msg2disk(CIM_DISABLED_RSC_LIST, msg);
+ }
ha_msg_del(msg);
return HA_OK;
}
@@ -1356,13 +1418,15 @@
{
struct ha_msg *list1 = NULL, *list2;
int len2;
-
+
+ /* list in CIB */
list1 = cim_query_dispatch(GET_RSC_LIST, NULL, NULL);
if (list1 == NULL && (list1 = ha_msg_new(1)) == NULL ) {
cl_log(LOG_ERR, "cim_get_rsc_list: can't get list1.");
return NULL;
}
+ /* merge with diabled list */
if ((list2 = cim_get_disabled_rsc_list())) {
int i;
len2 = cim_list_length(list2);
@@ -1399,7 +1463,7 @@
continue;
}
cim_list_add(newlist, rscid);
- if (cim_get_rsc_type(rscid) == TID_RES_PRIMITIVE) {
+ if (cim_get_rsctype(rscid) == TID_RES_PRIMITIVE) {
continue;
}
@@ -1424,89 +1488,78 @@
return newlist;
}
-int
-cim_store_rsc(int type, const char *rscid, struct ha_msg *rsc)
-{
- char tmp[MAXLEN];
- snprintf(tmp, MAXLEN, "resource_%d_%s", type, rscid);
- return cim_msg2disk(tmp, rsc);
-}
+/*********************************************************
+ * resource type
+ ********************************************************/
-struct ha_msg*
-cim_find_rsc(int type, const char * rscid)
+#define CIM_RSCTYPE_TABLE_PATHNAME "resource_type_table"
+int
+cim_add_rsctype(const char* rscid, const char *type)
{
- struct ha_msg *rsc = NULL, * attributes;
- switch(type){
- case TID_RES_PRIMITIVE:
- rsc = cim_query_dispatch(GET_PRIMITIVE, rscid, NULL);
- break;
- case TID_RES_MASTER:
- rsc = cim_query_dispatch(GET_MASTER, rscid, NULL);
- break;
- case TID_RES_CLONE:
- rsc = cim_query_dispatch(GET_CLONE, rscid, NULL);
- break;
- case TID_RES_GROUP:
- if ((rsc = ha_msg_new(1))){
- ha_msg_add(rsc, "id", rscid);
+ struct ha_msg * typemsg;
+ int ret;
+ if ((typemsg = cim_disk2msg(CIM_RSCTYPE_TABLE_PATHNAME)) == NULL) {
+ if ((typemsg = ha_msg_new(1)) == NULL ) {
+ return HA_FAIL;
}
- break;
- default:
- break;
- }
-
- if (rsc == NULL ) {
- char tmp[MAXLEN];
- snprintf(tmp, MAXLEN, "resource_%d_%s", type, rscid);
- cl_log(LOG_INFO, "%s: %s not in CIB, load it from disk.",
- __FUNCTION__, rscid);
- rsc = cim_disk2msg(tmp);
- cl_log(LOG_INFO, "%s: %s loaded", __FUNCTION__, rscid);
- } else {
- attributes=cim_query_dispatch(GET_RSC_ATTRIBUTES,rscid, NULL);
- if (attributes) {
- ha_msg_addstruct(rsc, "attributes", attributes);
- }
}
- return rsc;
+ cl_msg_modstring(typemsg, rscid, type);
+ ret = cim_msg2disk(CIM_RSCTYPE_TABLE_PATHNAME, typemsg);
+ ha_msg_del(typemsg);
+ return ret;
}
int
-cim_store_rsc_type(const char* rscid, struct ha_msg *type)
+cim_remove_rsctype(const char* rscid)
{
- char tmp[MAXLEN];
- snprintf(tmp, MAXLEN, "resource_type_%s", rscid);
- return cim_msg2disk(tmp, type);
+ struct ha_msg * typemsg;
+ int ret;
+ if ((typemsg = cim_disk2msg(CIM_RSCTYPE_TABLE_PATHNAME)) == NULL) {
+ return HA_OK;
+ }
+ cl_msg_remove(typemsg, rscid);
+ if ( typemsg->nfields == 0 ) {
+ ret = cim_disk_msg_del(CIM_RSCTYPE_TABLE_PATHNAME);
+ } else {
+ ret = cim_msg2disk(CIM_RSCTYPE_TABLE_PATHNAME, typemsg);
+ }
+ ha_msg_del(typemsg);
+ return ret;
}
int
-cim_get_rsc_type(const char * rscid)
+cim_get_rsctype(const char * rscid)
{
char * type = NULL;
struct ha_msg *msg;
int tid = TID_UNKNOWN;
- msg = cim_query_dispatch(GET_RSC_TYPE, rscid, NULL);
- if ( msg == NULL ) { /* get msg from disk */
- char tmp[MAXLEN];
- snprintf(tmp, MAXLEN, "resource_type_%s", rscid);
- msg = cim_disk2msg(tmp);
- }
- if ( msg ) {
- type = cim_strdup(cl_get_string(msg, "type"));
- ha_msg_del(msg);
+ if (cim_is_rsc_disabled(rscid)) {
+ const char * constype;
+ msg = cim_disk2msg(CIM_RSCTYPE_TABLE_PATHNAME);
+ if (msg) {
+ constype = cl_get_string(msg, rscid);
+ type = constype? cim_strdup(constype) : NULL;
+ ha_msg_del(msg);
+ }
+ } else {
+ msg = cim_query_dispatch(GET_RSC_TYPE, rscid, NULL);
+ if ( msg ) {
+ type = cim_strdup(cl_get_string(msg, "type"));
+ ha_msg_del(msg);
+ }
}
if ( type == NULL ) {
return TID_UNKNOWN;
}
- if(strcmp(type, "native")== 0){
+ if(strncmp(type, "native", MAXLEN)== 0){
tid = TID_RES_PRIMITIVE;
- } else if (strcmp(type, "group") == 0) {
+ } else if (strncmp(type, "group", MAXLEN) == 0) {
tid = TID_RES_GROUP;
- } else if (strcmp(type, "clone") == 0){
+ } else if (strncmp(type, "clone", MAXLEN) == 0){
tid = TID_RES_CLONE;
- } else if (strcmp(type, "master") == 0){
+ } else if (strncmp(type, "master", MAXLEN) == 0){
tid = TID_RES_MASTER;
}
@@ -1514,199 +1567,34 @@
return tid;
}
-int
-cim_is_rsc_disabled(const char *rscid)
-{
- int len, i;
- struct ha_msg * msg = NULL;
-
- if ((msg = cim_get_disabled_rsc_list()) == NULL ) {
- return FALSE;
- }
-
- len = cim_list_length(msg);
- for(i=0; i < len; i++) {
- char * rsc = NULL;
- if((rsc = cim_list_index(msg, i)) == NULL ) {
- continue;
- }
- if ( strncmp(rscid, rsc, MAXLEN) == 0){
- ha_msg_del(msg);
- return TRUE;
- }
- }
-
- ha_msg_del(msg);
- return FALSE;
-}
-
-int
-cim_store_operation(const char* rscid, const char* opid,struct ha_msg* op)
-{
- char tmp[MAXLEN];
- snprintf(tmp, MAXLEN, "operation_%s_%s", rscid, opid);
- return cim_msg2disk(tmp, op);
-}
-
-struct ha_msg*
-cim_load_operation(const char* rscid, const char * opid)
-{
- char tmp[MAXLEN];
- snprintf(tmp, MAXLEN, "operation_%s_%s", rscid, opid);
- return cim_disk2msg(tmp);
-}
-
-int
-cim_update_rsc(int type, const char *rscid, struct ha_msg *resource)
-{
- int ret = HA_FAIL;
-
- if ( ! cim_is_rsc_disabled(rscid) ) { /* in-cib resource */
- if ( type == TID_RES_CLONE ) {
- ret = cim_update_dispatch(UPDATE_CLONE,
- NULL, resource, NULL);
- } else if (type == TID_RES_MASTER ) {
- ret = cim_update_dispatch(UPDATE_MASTER,
- NULL, resource, NULL);
- } else if (type == TID_RES_PRIMITIVE ) {
- struct ha_msg * attributes;
- attributes = cl_get_struct(resource, "attributes");
- if (attributes ) {
- ret = cim_update_dispatch(UPDATE_ATTRIBUTES,
- rscid, attributes, NULL);
- }
- }
- } else { /* update disk image */
- ret = cim_store_rsc(type, rscid, resource);
- }
- return ret;
-}
+/*******************************************************
+ * resource operations
+ ******************************************************/
+#define CIM_RSCOPS_PREFIX "operations_of_"
struct ha_msg *
-cim_get_subrsc_list(const char *rscid)
-{
- struct ha_msg * sublist;
- char tmp[MAXLEN];
- sublist = cim_query_dispatch(GET_SUB_RSC, rscid, NULL);
- if ( sublist ) { /* found it in CIB */
- return sublist;
- }
- /* not found in CIB, look for it on disk */
- snprintf(tmp, MAXLEN, "subresource_of_%s", rscid);
- return cim_disk2msg(tmp);
-}
-
-static void
-AddPrimitiveForUpdate(struct ha_msg *msg, struct ha_msg* rsc)
-{
- struct ha_msg *attributes;
- int len, i;
-
- ha_msg_add(msg, "id", cl_get_string(rsc, "id"));
- ha_msg_add(msg, "provider", cl_get_string(rsc, "provider"));
- ha_msg_add(msg, "class", cl_get_string(rsc, "class"));
- ha_msg_add(msg, "type", cl_get_string(rsc, "type"));
-
- attributes = cl_get_struct(rsc, "attributes");
- len = cim_msg_children_count(attributes);
- for (i = 0; i < len; i++) {
- struct ha_msg *nvpair = NULL;
- nvpair = cim_msg_child_index(attributes, i);
- cim_msg_add_child(msg, cl_get_string(nvpair, "id"), nvpair);
- }
-}
-
-int
-cim_add_subrsc(struct ha_msg *rsc, struct ha_msg *subrsc)
+cim_get_rscops(const char *rscid)
{
- struct ha_msg * sublist;
- const char * rscid, *subrscid;
- char tmp[MAXLEN];
- int ret, type;
-
- rscid = cl_get_string(rsc, "id");
- subrscid = cl_get_string(subrsc, "id");
- if ( ! cim_is_rsc_disabled(subrscid) ){
- cl_log(LOG_ERR, "%s: resource %s can't be added, "
- "%s not an invalid resource or not disabled",
- __FUNCTION__, subrscid, subrscid);
- return HA_FAIL;
- }
-
- if ( cim_is_rsc_disabled(rscid) ) {
- snprintf(tmp, MAXLEN, "subresource_of_%s", rscid);
- sublist = cim_disk2msg(tmp);
- if (sublist == NULL ) { /* not exist yet */
- if ((sublist = ha_msg_new(1)) == NULL ) {
- cl_log(LOG_ERR, "cim_add_subrsc: "
- "alloc sublist failed.");
- return HA_FAIL;
- }
- }
- cl_log(LOG_INFO, "%s: %s is disabled, write disk.",
- __FUNCTION__, rscid);
+ struct ha_msg *ops = NULL;
- /* add subrscid and write back to disk */
- cim_list_add(sublist, subrscid);
- ret = cim_msg2disk(tmp, sublist);
+ if (!cim_is_rsc_disabled(rscid)) { /* from CIB */
+ ops = cim_query_dispatch(GET_RSC_OPERATIONS, rscid, NULL);
} else {
- struct ha_msg * msg;
-
- type = cim_get_rsc_type(rscid);
- if ( type != TID_RES_GROUP ){
- cl_log(LOG_ERR, "%s: resource %s can't be added to %s,"
- "%s is not a resource group.",
- __FUNCTION__, subrscid, rscid, rscid);
- return HA_FAIL;
- }
-
- if ( (msg = ha_msg_new(16)) == NULL ) {
- cl_log(LOG_ERR, "cim_add_subrsc: copy msg failed.");
- return HA_FAIL;
- }
-
- cim_debug2(LOG_INFO, "%s: call AddPrimitiveForUpdate",
__FUNCTION__);
- AddPrimitiveForUpdate(msg, subrsc);
- if ( type == TID_RES_GROUP ) {
- ha_msg_add(msg, "groupid", rscid);
- ha_msg_add(msg, "advance", "");
- ha_msg_add(msg, "advance_id", "");
- ha_msg_add(msg, "clone_max", "");
- ha_msg_add(msg, "clone_node_max", "");
- ha_msg_add(msg, "master_max", "");
- ha_msg_add(msg, "master_node_max", "");
- }
-
- cim_debug2(LOG_INFO, "%s: create resource.", __FUNCTION__);
- ret = cim_update_dispatch(CREATE_RESOURCE, NULL, msg, NULL);
- ha_msg_del(msg);
- }
- return ret;
-}
-
-
-struct ha_msg *
-cim_get_rscops(const char *rscid)
-{
- struct ha_msg *ops;
- char tmp[MAXLEN];
- ops = cim_query_dispatch(GET_RSC_OPERATIONS, rscid, NULL);
- if (ops) {
- return ops;
+ char pathname[MAXLEN] = CIM_RSCOPS_PREFIX;
+ strncat(pathname, rscid, MAXLEN);
+ ops = cim_disk2msg(pathname);
}
-
- snprintf(tmp, MAXLEN, "operations_of_%s", rscid);
- return cim_disk2msg(tmp);
+ return ops;
}
int
cim_del_rscop(const char *rscid, const char *opid)
{
struct ha_msg *ops;
- char tmp[MAXLEN];
int ret;
+ char pathname[MAXLEN] = CIM_RSCOPS_PREFIX;
- if ( ! cim_is_rsc_disabled(rscid) ) { /* update into CIB */
+ if ( ! cim_is_rsc_disabled(rscid) ) { /* update to CIB */
ret = cim_update_dispatch(DEL_OPERATION, opid, NULL, NULL);
return ret;
};
@@ -1719,9 +1607,10 @@
cim_msg_remove_child(ops, opid);
/* write back to disk */
- snprintf(tmp, MAXLEN, "operations_of_%s", rscid);
- ret = cim_msg2disk(tmp, ops);
+ strncat(pathname, rscid, MAXLEN);
+ ret = cim_msg2disk(pathname, ops);
ha_msg_del(ops);
+
return ret;
}
@@ -1729,7 +1618,6 @@
cim_add_rscop(const char *rscid, struct ha_msg *op)
{
struct ha_msg *ops;
- char tmp[MAXLEN];
int ret;
if ((ops = cim_get_rscops(rscid)) == NULL) {
@@ -1742,11 +1630,13 @@
if ( ! cim_is_rsc_disabled(rscid) ) { /* update into CIB */
ret = cim_update_dispatch(UPDATE_OPERATIONS, rscid, ops, NULL);
} else { /* write back to disk */
- snprintf(tmp, MAXLEN, "operatioins_of_%s", rscid);
- ret = cim_msg2disk(tmp, ops);
+ char pathname[MAXLEN] = CIM_RSCOPS_PREFIX;
+ strncat(pathname, rscid, MAXLEN);
+ /* write back to disk */
+ ret = cim_msg2disk(pathname, ops);
}
ha_msg_del(ops);
- return HA_OK;
+ return ret;
}
@@ -1754,7 +1644,7 @@
cim_update_rscop(const char* rscid, const char* id, struct ha_msg* op)
{
struct ha_msg *ops;
- char tmp[MAXLEN];
+ int ret;
if ((ops = cim_get_rscops(rscid)) == NULL) {
cl_log(LOG_ERR, "%s: ops of %s not found.",
@@ -1767,57 +1657,125 @@
cim_msg_add_child(ops, id, op);
if ( ! cim_is_rsc_disabled(rscid) ) { /* update into CIB */
- return cim_update_dispatch(UPDATE_OPERATIONS, rscid, ops, NULL);
+ ret = cim_update_dispatch(UPDATE_OPERATIONS, rscid, ops, NULL);
} else { /* write back to disk */
- snprintf(tmp, MAXLEN, "operatioins_of_%s", rscid);
- return cim_msg2disk(tmp, ops);
+ char pathname [MAXLEN] = CIM_RSCOPS_PREFIX;
+ strncat(pathname, rscid, MAXLEN);
+ /* write back to disk */
+ ret = cim_msg2disk(pathname, ops);
}
+ ha_msg_del(ops);
+ return ret;
}
+/*********************************************************
+ * resource attributes
+ ********************************************************/
+#define CIM_RSCATTRS_PREFIX "attributes_of_"
int
-cim_msg_children_count(struct ha_msg *parent)
+cim_erase_rscattrs(const char *rscid)
{
- int i, count = 0;
- for (i = 0; i < parent->nfields; i++) {
- if ( parent->types[i] == FT_STRUCT ) {
- count++;
- }
+ char pathname[MAXLEN] = CIM_RSCATTRS_PREFIX;
+ strncat(pathname, rscid, MAXLEN);
+ return cim_disk_msg_del(pathname);
+}
+
+struct ha_msg *
+cim_get_rscattrs(const char *rscid)
+{
+ struct ha_msg *attrs = NULL;
+
+ if (!cim_is_rsc_disabled(rscid)) {
+ attrs = cim_query_dispatch(GET_RSC_ATTRIBUTES, rscid, NULL);
+ } else {
+ char pathname[MAXLEN] = CIM_RSCATTRS_PREFIX;
+ strncat(pathname, rscid, MAXLEN);
+ attrs = cim_disk2msg(pathname);
}
- return count;
+ return attrs;
}
+int
+cim_update_attrnvpair(const char*rscid, const char*nvid, struct ha_msg *nvpair)
+{
+ int ret;
+ struct ha_msg *attrs = cim_get_rscattrs(rscid);
-const char *
-cim_msg_child_name(struct ha_msg *parent, int index)
-{
- int i, current = 0;
- for (i = 0; i < parent->nfields; i++) {
- if ( parent->types[i] == FT_STRUCT ) {
- if ( index == current) {
- return parent->names[i];
- }
- current++;
+ DEBUG_ENTER();
+ if ( attrs == NULL ) {
+ if ((attrs = ha_msg_new(1)) == NULL ) {
+ cl_log(LOG_ERR, "%s: attributes not found for %s",
+ __FUNCTION__, rscid);
+ return HA_FAIL;
}
}
- return NULL;
-}
+ cl_msg_modstruct(attrs, nvid, nvpair);
+ if ( cim_is_rsc_disabled(rscid) ) {
+ char pathname[MAXLEN] = CIM_RSCATTRS_PREFIX;
+ strncat(pathname, rscid, MAXLEN);
+ ret = cim_msg2disk(pathname, attrs);
+ cim_debug_msg(attrs, "%s: write attributes to %s",
__FUNCTION__, pathname);
+ } else {
+ ret = cim_update_dispatch(UPDATE_ATTRIBUTES, rscid, attrs,
NULL);
+ }
+ ha_msg_del(attrs);
+ DEBUG_LEAVE();
+ return ret;
+}
-struct ha_msg *
-cim_msg_child_index(struct ha_msg *parent, int index)
+int
+cim_remove_attrnvpair(const char* rscid, const char* nvid)
{
- int i, current = 0;
- for (i = 0; i < parent->nfields; i++) {
- if ( parent->types[i] == FT_STRUCT ) {
- if ( index == current) {
- return parent->values[i];
- }
- current++;
- }
+ int ret;
+ struct ha_msg *attrs = cim_get_rscattrs(rscid);
+ if ( attrs == NULL ) {
+ return HA_FAIL;
}
- return NULL;
+
+ cl_msg_remove(attrs, nvid);
+ if ( cim_is_rsc_disabled(rscid) ) {
+ char pathname[MAXLEN] = CIM_RSCATTRS_PREFIX;
+ strncat(pathname, rscid, MAXLEN);
+ ret = cim_msg2disk(pathname, attrs);
+ } else {
+ ret = cim_update_dispatch(DEL_ATTRIBUTES, nvid, NULL, NULL);
+ }
+
+ ha_msg_del(attrs);
+ return ret;
}
+/**********************************************************
+ * resource
+ *********************************************************/
+
+static void
+AddPrimitiveForUpdate(struct ha_msg *msg, struct ha_msg* rsc, struct ha_msg
*attrs)
+{
+ int len, i;
+ const char * id;
+
+ id = cl_get_string(rsc, "id");
+ ha_msg_add(msg, "id", cl_get_string(rsc, "id"));
+ ha_msg_add(msg, "provider", cl_get_string(rsc, "provider"));
+ ha_msg_add(msg, "class", cl_get_string(rsc, "class"));
+ ha_msg_add(msg, "type", cl_get_string(rsc, "type"));
+
+ if ( attrs == NULL ) {
+ attrs = cim_get_rscattrs(id);
+ }
+ if ( attrs == NULL ) {
+ cl_log(LOG_ERR, "%s: attributes of %s not found.",
__FUNCTION__, id);
+ return ;
+ }
+ len = cim_msg_children_count(attrs);
+ for (i = 0; i < len; i++) {
+ struct ha_msg *nvpair = NULL;
+ nvpair = cim_msg_child_index(attrs, i);
+ cim_msg_add_child(msg, cl_get_string(nvpair, "id"), nvpair);
+ }
+}
int
cim_cib_addrsc(const char *rscid)
@@ -1830,7 +1788,7 @@
__FUNCTION__, rscid);
return HA_FAIL;
}
- type = cim_get_rsc_type(rscid);
+ type = cim_get_rsctype(rscid);
if ( (rsc = cim_find_rsc(type, rscid)) == NULL ) {
cl_log(LOG_ERR, "%s: resource %s not found.",
__FUNCTION__, rscid);
@@ -1862,13 +1820,7 @@
ha_msg_del(msg);
return HA_FAIL;
}
- /* remove it from disabled list */
- ret = cim_update_disabled_rsc_list(0, rscid);
- if ( ret == HA_FAIL ){
- ha_msg_del(rsc);
- ha_msg_del(msg);
- return HA_FAIL;
- }
+
/* then add sub primitive resources into group */
count = cim_list_length(sublist);
for (i = 0; i < count; i++) {
@@ -1881,7 +1833,11 @@
__FUNCTION__, rscid);
cim_debug2(LOG_INFO, "%s: ready to add", __FUNCTION__);
ret = cim_add_subrsc(rsc, primitive);
+
+ CLEAN_RESOURCE_RECORD(cl_get_string(primitive, "id"));
}
+
+ CLEAN_RESOURCE_RECORD(rscid);
ha_msg_del(sublist);
} else if ( type == TID_RES_CLONE || type == TID_RES_MASTER) {
struct ha_msg *primitive;
@@ -1902,7 +1858,7 @@
ha_msg_del(msg);
return HA_FAIL;
}
- AddPrimitiveForUpdate(msg, primitive);
+ AddPrimitiveForUpdate(msg, primitive, NULL);
ha_msg_add(msg, "groupid", "");
ha_msg_add(msg, "advance",
(type == TID_RES_CLONE) ? "clone":"master");
@@ -1915,9 +1871,13 @@
cl_get_string(rsc, "master_max") : "");
ha_msg_add(msg, "master_node_max", ( type == TID_RES_MASTER ) ?
cl_get_string(rsc, "master_node_max") : "");
+
+ ret = cim_update_dispatch(CREATE_RESOURCE, NULL, msg, NULL);
+
+ CLEAN_RESOURCE_RECORD(cl_get_string(primitive, "id"));
ha_msg_del(sublist);
} else if ( type == TID_RES_PRIMITIVE ) {
- AddPrimitiveForUpdate(msg, rsc);
+ AddPrimitiveForUpdate(msg, rsc, NULL);
ha_msg_add(msg, "groupid", "");
ha_msg_add(msg, "advance", "");
ha_msg_add(msg, "advance_id", "");
@@ -1926,11 +1886,242 @@
ha_msg_add(msg, "master_max", "");
ha_msg_add(msg, "master_node_max", "");
ret = cim_update_dispatch(CREATE_RESOURCE, NULL, msg, NULL);
- }
- /* FIXME: delete the disk image */
+ /* delete the disk image */
+
+ CLEAN_RESOURCE_RECORD(rscid);
+ }
ha_msg_del(rsc);
ha_msg_del(msg);
return HA_OK;
}
+
+
+#define CIM_RESOURCE_PREFIX "resource_"
+int
+cim_store_rsc(int type, const char *rscid, struct ha_msg *rsc)
+{
+ char pathname[MAXLEN] = CIM_RESOURCE_PREFIX;
+ strncat(pathname, rscid, MAXLEN);
+ return cim_msg2disk(pathname, rsc);
+}
+
+struct ha_msg*
+cim_find_rsc(int type, const char * rscid)
+{
+ struct ha_msg *rsc = NULL/*, * attributes*/;
+
+ if (cim_is_rsc_disabled(rscid)) {
+ char pathname[MAXLEN] = CIM_RESOURCE_PREFIX;
+ strncat(pathname, rscid, MAXLEN);
+ cl_log(LOG_INFO, "%s: %s not in CIB, load it from disk.",
+ __FUNCTION__, rscid);
+ rsc = cim_disk2msg(pathname);
+ goto done;
+ }
+
+ switch(type){
+ case TID_RES_PRIMITIVE:
+ rsc = cim_query_dispatch(GET_PRIMITIVE, rscid, NULL);
+ break;
+ case TID_RES_MASTER:
+ rsc = cim_query_dispatch(GET_MASTER, rscid, NULL);
+ break;
+ case TID_RES_CLONE:
+ rsc = cim_query_dispatch(GET_CLONE, rscid, NULL);
+ break;
+ case TID_RES_GROUP:
+ if ((rsc = ha_msg_new(1))){
+ ha_msg_add(rsc, "id", rscid);
+ }
+ break;
+ default:
+ break;
+ }
+done:
+ return rsc;
+}
+
+int
+cim_update_rsc(int type, const char *rscid, struct ha_msg *resource)
+{
+ int ret = HA_FAIL;
+
+ if ( ! cim_is_rsc_disabled(rscid) ) { /* in-cib resource */
+ if ( type == TID_RES_CLONE ) {
+ ret = cim_update_dispatch(UPDATE_CLONE,
+ NULL, resource, NULL);
+ } else if (type == TID_RES_MASTER ) {
+ ret = cim_update_dispatch(UPDATE_MASTER,
+ NULL, resource, NULL);
+ } else if (type == TID_RES_PRIMITIVE ) {
+ ret = HA_OK;
+ }
+ } else { /* update disk image */
+ ret = cim_store_rsc(type, rscid, resource);
+ }
+ return ret;
+}
+
+int
+cim_remove_rsc(const char * rscid)
+{
+ int ret;
+ struct ha_msg * msg;
+ if ( !cim_is_rsc_disabled(rscid)) {
+ ret = cim_update_dispatch(DEL_RESOURCE, rscid, NULL, NULL);
+ msg = cim_query_dispatch(GET_RSC_HOST, rscid, NULL);
+ if (msg) {
+ const char * host = cl_get_string(msg, "host");
+ char * param = mclient_makeup_param(host, rscid);
+ ret = cim_update_dispatch(CLEANUP_RESOURCE, param,
NULL, NULL);
+ }
+ } else {
+ CLEAN_RESOURCE_RECORD(rscid);
+ ret = HA_OK;
+ }
+ return ret;
+}
+
+/*****************************************************************
+ * sub resources
+ ****************************************************************/
+#define CIM_SUBRSC_PREFIX "subresources_of_"
+
+struct ha_msg *
+cim_get_subrsc_list(const char *rscid)
+{
+ struct ha_msg * sublist;
+ char pathname[MAXLEN];
+ sublist = cim_query_dispatch(GET_SUB_RSC, rscid, NULL);
+ if ( sublist ) { /* found it in CIB */
+ return sublist;
+ }
+ /* not found in CIB, look for it on disk */
+ snprintf(pathname, MAXLEN, CIM_SUBRSC_PREFIX"%s", rscid);
+ return cim_disk2msg(pathname);
+}
+
+int
+cim_add_subrsc(struct ha_msg *rsc, struct ha_msg *subrsc)
+{
+ struct ha_msg * sublist;
+ const char * rscid, *subrscid;
+ char pathname[MAXLEN];
+ int ret, type;
+
+ rscid = cl_get_string(rsc, "id");
+ subrscid = cl_get_string(subrsc, "id");
+
+ if ( ! cim_is_rsc_disabled(subrscid) ){
+ cl_log(LOG_ERR, "%s: resource %s can't be added, "
+ "%s not an invalid resource or not disabled",
+ __FUNCTION__, subrscid, subrscid);
+ return HA_FAIL;
+ }
+
+ if ( cim_is_rsc_disabled(rscid) ) { /* write to disk */
+ snprintf(pathname, MAXLEN, CIM_SUBRSC_PREFIX"%s", rscid);
+ sublist = cim_disk2msg(pathname);
+ if (sublist == NULL ) { /* not exist yet */
+ if ((sublist = ha_msg_new(1)) == NULL ) {
+ cl_log(LOG_ERR, "cim_add_subrsc: "
+ "alloc sublist failed.");
+ return HA_FAIL;
+ }
+ }
+ cl_log(LOG_INFO, "%s: %s is disabled, write disk.",
+ __FUNCTION__, rscid);
+
+ /* add subrscid and write back to disk */
+ cim_list_add(sublist, subrscid);
+ ret = cim_msg2disk(pathname, sublist);
+ ha_msg_del(sublist);
+ } else { /* update to CIB */
+ struct ha_msg * msg;
+
+ type = cim_get_rsctype(rscid);
+ if ( type != TID_RES_GROUP ){
+ cl_log(LOG_ERR, "%s: resource %s can't be added to %s,"
+ "%s is not a resource group.",
+ __FUNCTION__, subrscid, rscid, rscid);
+ return HA_FAIL;
+ }
+
+ /* create new resource */
+ if ( (msg = ha_msg_new(16)) == NULL ) {
+ cl_log(LOG_ERR, "cim_add_subrsc: copy msg failed.");
+ return HA_FAIL;
+ }
+ cim_debug2(LOG_INFO, "%s: call AddPrimitiveForUpdate",
__FUNCTION__);
+ AddPrimitiveForUpdate(msg, subrsc, NULL);
+ if ( type == TID_RES_GROUP ) {
+ ha_msg_add(msg, "groupid", rscid);
+ ha_msg_add(msg, "advance", "");
+ ha_msg_add(msg, "advance_id", "");
+ ha_msg_add(msg, "clone_max", "");
+ ha_msg_add(msg, "clone_node_max", "");
+ ha_msg_add(msg, "master_max", "");
+ ha_msg_add(msg, "master_node_max", "");
+ }
+
+ cim_debug2(LOG_INFO, "%s: create resource.", __FUNCTION__);
+ ret = cim_update_dispatch(CREATE_RESOURCE, NULL, msg, NULL);
+
+ /* update disk status */
+ CLEAN_RESOURCE_RECORD(subrscid);
+
+ ha_msg_del(msg);
+ }
+ return ret;
+}
+
+
+/****************************************************
+ * msg
+ ****************************************************/
+int
+cim_msg_children_count(struct ha_msg *parent)
+{
+ int i, count = 0;
+ for (i = 0; i < parent->nfields; i++) {
+ if ( parent->types[i] == FT_STRUCT ) {
+ count++;
+ }
+ }
+ return count;
+}
+
+
+const char *
+cim_msg_child_name(struct ha_msg *parent, int index)
+{
+ int i, current = 0;
+ for (i = 0; i < parent->nfields; i++) {
+ if ( parent->types[i] == FT_STRUCT ) {
+ if ( index == current) {
+ return parent->names[i];
+ }
+ current++;
+ }
+ }
+ return NULL;
+}
+
+
+struct ha_msg *
+cim_msg_child_index(struct ha_msg *parent, int index)
+{
+ int i, current = 0;
+ for (i = 0; i < parent->nfields; i++) {
+ if ( parent->types[i] == FT_STRUCT ) {
+ if ( index == current) {
+ return parent->values[i];
+ }
+ current++;
+ }
+ }
+ return NULL;
+}
+
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/cim/cluster_info.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- cluster_info.h 10 Apr 2006 10:11:02 -0000 1.5
+++ cluster_info.h 13 Apr 2006 07:58:35 -0000 1.6
@@ -50,6 +50,8 @@
#define CIM_MSG_LIST "__list__"
#define CIM_MSG_TAG "__tag__"
#define CIM_MSG_ATTR_ID "id" /* every node-msg should have
this */
+#define CIM_MSG_INST_ATTR "instance_attributes"
+#define CIM_MSG_ATTR "attributes"
enum { HB_RUNNING = 1, HB_STOPED = 2, HB_UNKNOWN = 3 };
enum { START_HB = 1, STOP_HB = 2, RESTART_HB = 3 };
@@ -99,6 +101,8 @@
DEL_RESOURCE = 0 , /* delete a resource */
DEL_OPERATION , /* delete an operation */
DEL_ATTRIBUTES , /* delete an attribute */
+ CLEANUP_RESOURCE ,
+
UPDATE_MASTER , /* update a master-slave resource */
UPDATE_CLONE , /* update a clone resource */
UPDATE_OPERATIONS , /* update operations */
@@ -121,37 +125,49 @@
struct ha_msg * cim_query_dispatch(int id, const char* param, void*
out);
int cim_update_dispatch(int id,const char*param, void*data, void*);
+/* cluster */
+struct ha_msg * cim_get_software_identity(void);
int cim_get_hb_status (void);
int cim_change_hb_state(int state);
struct ha_msg * cim_get_hacf_config (void);
struct ha_msg * cim_get_authkeys (void);
-struct ha_msg * cim_get_software_identity(void);
-
int cim_update_hacf(struct ha_msg *msg);
int cim_update_authkeys(struct ha_msg *msg);
+/* resource list */
struct ha_msg * cim_get_disabled_rsc_list(void);
int cim_update_disabled_rsc_list(int add, const char *rscid);
int cim_is_rsc_disabled(const char *rscid);
struct ha_msg* cim_get_rsc_list(void);
struct ha_msg* cim_traverse_allrsc(struct ha_msg* list);
-int cim_store_rsc(int type, const char *rscid, struct ha_msg *rsc);
-struct ha_msg* cim_find_rsc(int type, const char * rscid);
-int cim_store_rsc_type(const char* rscid, struct ha_msg *type);
-int cim_get_rsc_type(const char * rscid);
-
-int cim_store_operation(const char* rscid,const char* opid,struct ha_msg*);
-struct ha_msg* cim_load_operation(const char* rscid, const char *opid);
-int cim_update_rsc(int type, const char *rscid, struct ha_msg *);
-struct ha_msg * cim_get_subrsc_list(const char *rscid);
-int cim_add_subrsc(struct ha_msg *rsc, struct ha_msg *subrsc);
+/* resource type */
+int cim_add_rsctype(const char* rscid, const char *type);
+int cim_get_rsctype(const char * rscid);
+int cim_remove_rsctype(const char* rscid);
+/* resource operations */
struct ha_msg * cim_get_rscops(const char *rscid);
int cim_add_rscop(const char *rscid, struct ha_msg *op);
int cim_del_rscop(const char *rscid, const char *opid);
int cim_update_rscop(const char*rscid, const char*, struct ha_msg*);
+
+/* resource */
int cim_cib_addrsc(const char *rscid);
+int cim_store_rsc(int type, const char *rscid, struct ha_msg *rsc);
+struct ha_msg* cim_find_rsc(int type, const char * rscid);
+int cim_update_rsc(int type, const char *rscid, struct ha_msg *);
+int cim_remove_rsc(const char * rscid);
+
+/* sub resource */
+struct ha_msg * cim_get_subrsc_list(const char *rscid);
+int cim_add_subrsc(struct ha_msg *rsc, struct ha_msg *subrsc);
+
+/* resource attributes */
+struct ha_msg * cim_get_rscattrs(const char *rscid);
+int cim_update_attrnvpair(const char*, const char*, struct ha_msg*);
+int cim_remove_attrnvpair(const char* rscid, const char* attrid);
+int cim_erase_rscattrs(const char *rscid);
#define cim_list_length(msg) cl_msg_list_length(msg, CIM_MSG_LIST)
#define cim_list_index(msg,index) \
@@ -161,7 +177,7 @@
cl_msg_list_add_string(msg, CIM_MSG_LIST, value)
#define cim_msg_add_child(parent,id, child) \
- ha_msg_addstruct(parent, id, child)
+ ha_msg_addstruct(parent, id, child)
#define cim_msg_find_child(parent, id) cl_get_struct(parent,id)
#define cim_msg_remove_child(parent, id) cl_msg_remove(parent,id)
------------------------------
_______________________________________________
Linux-ha-cvs mailing list
[email protected]
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
End of Linux-ha-cvs Digest, Vol 29, Issue 79
********************************************