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: Tue, 25 Apr 2006 11:46:45 -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:
moved some codes to utils.c, made use of dbget/dbput
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/cim/cluster_info.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- cluster_info.c      14 Apr 2006 03:39:53 -0000      1.7
+++ cluster_info.c      25 Apr 2006 17:46:45 -0000      1.8
@@ -53,11 +53,17 @@
 #define        CONFIG_FILENAME         HA_RC_DIR"/ha.cf"
 #define         BACKUP_CONFIG_NAME     CONFIG_NAME".bak"
 #define        BACKUP_KEYFILE          KEYFILE".bak"
-#define                HA_CIM_VARDIR           "/var/lib/heartbeat/cim"
 
 #define         CONFIG_COMMENT \
                        "#This file was generated by provider\n\n\n"
 
+#define CIM_RSCNAME_TABLE              "resource_name_table"
+#define CIM_RSCTYPE_TABLE              "resource_type_table"
+#define CIM_RSCOPS_TABLE               "resource_operations"
+#define CIM_RSCATTRS_TABLE             "resource_attrubtes_table"
+#define CIM_SUBRSC_NAME_TABLE          "subresource_name_table"
+#define CIM_RESOURCE_TABLE             "resource_table"
+
 
 typedef struct FunContext_s {
        int     func_id;        /* function name */
@@ -84,11 +90,22 @@
 static int InsertOption(struct ha_msg*, const char *, const char * option);
 static int StrIsEmpty(const char * str);
 
-static char *          pathname_encode(const char *);
 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);
+
+static int             cim_rsctype_s2tid(const char * rsctype);
+static const char*     cim_rsctype_tid2s(int rsctype);
+
+#define cim_rscname_table_keys() cim_dbkeys(CIM_RSCNAME_TABLE)
+#define cim_rscname_table_add(rscid)   \
+               cim_dbput(CIM_RSCNAME_TABLE, rscid, "disabled")
+#define cim_rscname_table_del(rscid)   \
+               cim_dbdel(CIM_RSCNAME_TABLE, rscid)
+#define cim_rscname_table_get(rscid)   \
+               cim_dbget(CIM_RSCNAME_TABLE, rscid)
+
+#define cim_rsctype_table_add(rscid,type)      cim_dbput(CIM_RSCTYPE_TABLE, 
rscid, type) 
+#define cim_rsctype_table_del( rscid)  cim_dbdel(CIM_RSCTYPE_TABLE, rscid)
+
 
 #define STR_CONS_ORDER        "rsc_order"
 #define STR_CONS_LOCATION     "rsc_location"
@@ -936,8 +953,6 @@
        return info;
 }
 
-/* set CONFIG_NAME */
-
 static int
 StrIsEmpty(const char * str)
 {
@@ -1042,7 +1057,7 @@
         if ((f = fopen(KEYFILE, "r")) == NULL) {
                 cl_log(LOG_ERR, "Cannot open keyfile [%s].  Stop."
                 ,       KEYFILE);
-                cim_table_free(authinfo);
+                ha_msg_del(authinfo);
                return NULL;
         } 
 
@@ -1051,7 +1066,7 @@
                 cl_log(LOG_ERR, "Bad permissions on keyfile"
                        " [%s], 600 recommended.", KEYFILE);
                 fclose(f);
-                cim_table_free(authinfo);
+                ha_msg_del(authinfo);
                 return NULL;
         }
 
@@ -1168,145 +1183,6 @@
        return NULL;
 }
 
-int 
-cim_msg2disk(const char *objpathname, struct ha_msg *msg)
-{
-       struct stat st;
-       FILE *fobj; 
-       char pathname[MAXLEN], *buf;
-       char *msgstr = msg2string(msg); 
-       
-       if (msgstr == NULL ) {
-               cl_log(LOG_ERR, "cim_msg2disk: msgstr NULL.");
-               return HA_FAIL;
-       }
-
-       if ( stat(HA_CIM_VARDIR, &st) < 0 ) {
-               if ( errno == ENOENT ) {        /* not exist, create */
-                       if (  mkdir(HA_CIM_VARDIR, 0660) < 0){
-                               cl_log(LOG_ERR,"msg2disk: mkdir failed.");      
        
-                               cl_log(LOG_ERR,"reason:%s",strerror(errno)); 
-                               return HA_FAIL;
-                       }
-
-               } else {
-                       cl_log(LOG_ERR, "msg2disk: stat faild.");
-                       cl_log(LOG_ERR,"reason:%d(%s)",errno,strerror(errno)); 
-                       return HA_FAIL;
-               }
-       } 
-
-       /* check stat */
-
-       /* write msg*/
-
-       if((buf = pathname_encode(objpathname))== NULL ) {
-               return HA_FAIL;
-       }
-       snprintf(pathname, MAXLEN, "%s/%s", HA_CIM_VARDIR, buf);
-       cim_free(buf);
-
-        if ( ( fobj = fopen(pathname, "w") ) == NULL ) {
-               cl_log(LOG_WARNING, "msg2disk: can't open file.");
-               cl_log(LOG_WARNING, "reason:%d(%s)", errno, strerror(errno));
-               return HA_FAIL;
-       }
-
-       fprintf(fobj, "%s", msgstr);
-       fclose(fobj); 
-       return HA_OK;
-}
-
-static struct ha_msg*
-cim_disk2msg(const char *objpathname)
-{
-       char pathname[MAXLEN], *buf;
-       FILE *fobj = NULL;
-       int ret;
-       int bytes = 0;
-       struct stat st;
-       struct ha_msg *msg = NULL;
-
-       if((buf = pathname_encode(objpathname))== NULL ) {
-               return NULL;
-       }
-       snprintf(pathname, MAXLEN, "%s/%s", HA_CIM_VARDIR, buf);
-       cim_free(buf);
-
-       if ( ( ret = stat(pathname, &st)) < 0 ) {
-               cl_log(LOG_WARNING, "disk2msg: stat faild for %s.", pathname);
-               cl_log(LOG_WARNING,"reason:%d(%s)",errno,strerror(errno)); 
-               return NULL;
-       } 
-
-       if ((buf = cim_malloc(st.st_size)) == NULL ) {
-               cl_log(LOG_ERR, "disk2msg: alloc msg failed.");
-               return NULL;
-       }
-       
-       if ( (fobj = fopen(pathname, "r")) == NULL ) {
-               cl_log(LOG_WARNING, "msg2disk: can't open file %s.", pathname);
-               cl_log(LOG_WARNING, "reason:%d(%s)", errno, strerror(errno));
-               return NULL;
-       }
-
-       while ( (ret = fread(buf, st.st_size, 1, fobj))){
-               bytes += ret*st.st_size;
-       }
-       
-       if ( !feof(fobj) ) {
-               cl_log(LOG_ERR, "msg2disk: read error");
-               cl_log(LOG_ERR, "reason: %d(%s).", errno, strerror(errno));     
        
-               cim_free(msg);
-               return NULL;
-       }
-
-       if ( bytes != st.st_size ) {
-               cl_log(LOG_ERR, "msg2disk: incompete read:");
-               cl_log(LOG_ERR, "read: %d vs size: %d.", bytes, 
(int)st.st_size);
-               cim_free(msg);
-                       return NULL;
-       }
-       msg = string2msg(buf, bytes);
-       cim_free(buf);
-       fclose(fobj);
-       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)
-{
-       char *new_pathname = NULL;
-       char ch, *p;
-       if ((new_pathname = cim_malloc(strlen(pathname)+1)) == NULL ) {
-               cl_log(LOG_ERR, "pathname_enocde: alloc pathname failed.");
-               return NULL;
-       }
-       p = new_pathname;
-       while( (ch = *(pathname++)) ) {
-               if (ch == '\\' || ch == '/')  {
-                       *(p++) = '_';
-               } else {
-                       *(p++) = ch;
-               }
-       }
-       *p = EOS;
-       return new_pathname;
-}
-
 static int
 cib_changed()
 {
@@ -1314,107 +1190,40 @@
        return 1;
 }
 
-#define CLEAN_RESOURCE_RECORD(resid)   do {                    \
-                cim_update_disabled_rsc_list(0, resid);                \
-                cim_erase_rscattrs(resid);                     \
-                cim_remove_rsctype(resid);                     \
-}while(0)
 
 /****************************************************************
  * resource list
  ***************************************************************/
-#define CIM_DISABLED_RSC_LIST "disabled_resource_list"
 int
-cim_is_rsc_disabled(const char *rscid)
+cim_rsc_is_in_cib(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;
-       }
+       char * value;
+       /*
+       struct ha_msg *list=NULL;
        
-       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);
+       if ((list = cim_query_dispatch(GET_RSC_LIST, NULL, NULL))){
+               if ( cim_list_find(list, rscid)) {
+                       ha_msg_del(list);
+                       cim_debug2(LOG_INFO, "%s: %s is in CIB, "
+                               "reason: it's in the CIB resource list.", 
+                               __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(CIM_DISABLED_RSC_LIST);
-}
-
-int 
-cim_update_disabled_rsc_list(int add, const char *rscid)
-{
-       struct ha_msg *msg = NULL;
-       if ((msg = cim_get_disabled_rsc_list()) == NULL ) {     
-               if ( !add ) {
-                       cl_log(LOG_ERR, "can't remove resource %s"
-                               " from disabled list", rscid);
-                       cl_log(LOG_ERR, "disabled_list not exist.");
-                       return HA_FAIL; 
-               } 
-               if ((msg = ha_msg_new(1)) == NULL ) {
-                       cl_log(LOG_ERR, "update_allrsc:"
-                                       "alloc msg failed.");
-                       return HA_FAIL;
-               }
+       */
+       if ((value = cim_rscname_table_get(rscid)) == NULL ) {
+               return TRUE;
+       } else { 
+               cim_free(value);
+               return FALSE;
        }
+}
 
-       if ( add ) {    /* add rscid */
-               cim_list_add(msg, rscid);       
-       } else {
-               int i, len = cim_list_length(msg);
-               struct ha_msg *new_msg = ha_msg_new(1);
-               if (new_msg == NULL ) {
-                       cl_log(LOG_ERR, "update_allrsc:"
-                                       "alloc new_msg failed.");
-                       return HA_FAIL;
-               }
 
-               for (i=0; i<len; i++) {
-                       char *id = NULL;
-                       id = cim_list_index(msg, i);
-                       if (id == NULL || (strncmp(rscid, id, MAXLEN) == 0)) {
-                               continue;
-                       }
-                       cim_list_add(new_msg, id);
-               }
-               ha_msg_del(msg);
-               msg = new_msg;
-       }
-
-       /* write to disk */
-       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;
-}      
+       
 
 struct ha_msg* 
-cim_get_rsc_list(void)
+cim_get_all_rsc_list(void)
 {
        struct ha_msg *list1 = NULL, *list2;
        int len2;
@@ -1422,12 +1231,12 @@
        /* 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.");
+               cl_log(LOG_ERR, "cim_get_all_rsc_list: can't get list1.");
                return NULL;
        }
 
        /* merge with diabled list */
-       if ((list2 = cim_get_disabled_rsc_list())) {
+       if ((list2 = cim_rscname_table_keys())) {
                int i;
                len2 = cim_list_length(list2);
                cim_debug2(LOG_INFO, "len2 = %d", len2);
@@ -1492,98 +1301,80 @@
  * resource type 
  ********************************************************/
 
-#define CIM_RSCTYPE_TABLE_PATHNAME "resource_type_table"
-int
-cim_add_rsctype(const char* rscid, const char *type)
+
+static int
+cim_rsctype_s2tid(const char *type)
 {
-       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;
-               }
+       int tid = TID_UNKNOWN;
+       if ( type == NULL ) {
+               return TID_UNKNOWN;
+       }
+       if(strncmp(type, S_RES_PRIMITIVE, MAXLEN)== 0){
+               tid = TID_RES_PRIMITIVE;
+       } else if (strncmp(type, S_RES_GROUP, MAXLEN) == 0) {
+               tid = TID_RES_GROUP;
+       } else if (strncmp(type, S_RES_CLONE, MAXLEN) == 0){
+               tid = TID_RES_CLONE;
+       } else if (strncmp(type, S_RES_MASTER, MAXLEN) == 0){
+               tid = TID_RES_MASTER;
        }
-       cl_msg_modstring(typemsg, rscid, type);
-       ret = cim_msg2disk(CIM_RSCTYPE_TABLE_PATHNAME, typemsg);
-       ha_msg_del(typemsg);
-       return ret;
-}
 
-int
-cim_remove_rsctype(const char* rscid)
+       return tid;
+}
+static const char*
+cim_rsctype_tid2s(int 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);
+       const char * rsctype = NULL;
+       if (type == TID_RES_PRIMITIVE ) {
+               rsctype = S_RES_PRIMITIVE;
+       } else if ( type == TID_RES_CLONE ) {
+               rsctype = S_RES_CLONE;
+       } else if ( type == TID_RES_MASTER) {
+               rsctype = S_RES_MASTER;
+       } else if ( type == TID_RES_GROUP ) {
+               rsctype = S_RES_GROUP;
        } else {
-               ret = cim_msg2disk(CIM_RSCTYPE_TABLE_PATHNAME, typemsg);
+               rsctype = S_RES_UNKNOWN;
        }
-       ha_msg_del(typemsg);
-       return ret;
+       return rsctype;
 }
 
 int
 cim_get_rsctype(const char * rscid)
 {
        char * type = NULL;
-       struct ha_msg *msg;
        int tid = TID_UNKNOWN;
-
-       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);
-               }
+       
+       DEBUG_ENTER();
+       if ( RESOURCE_DISABLED(rscid)) {
+               type = cim_dbget(CIM_RSCTYPE_TABLE, rscid);
        } else {
+               struct ha_msg *msg;
                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;
+       tid = cim_rsctype_s2tid(type);
+       if (type) {
+               cim_free(type);
        }
 
-       if(strncmp(type, "native", MAXLEN)== 0){
-               tid = TID_RES_PRIMITIVE;
-       } else if (strncmp(type, "group", MAXLEN) == 0) {
-               tid = TID_RES_GROUP;
-       } else if (strncmp(type, "clone", MAXLEN) == 0){
-               tid = TID_RES_CLONE;
-       } else if (strncmp(type, "master", MAXLEN) == 0){
-               tid = TID_RES_MASTER;
-       }
-       
-       cim_free(type);
+       DEBUG_LEAVE();
        return tid;
 }
 
 /*******************************************************
  * resource operations 
  ******************************************************/
-#define CIM_RSCOPS_PREFIX "operations_of_"
-
 struct ha_msg *
 cim_get_rscops(const char *rscid)
 {
        struct ha_msg *ops = NULL;
-
-       if (!cim_is_rsc_disabled(rscid)) { /* from CIB */
-               ops = cim_query_dispatch(GET_RSC_OPERATIONS, rscid, NULL);
-       } else {
-               char pathname[MAXLEN] = CIM_RSCOPS_PREFIX;
-               strncat(pathname, rscid, MAXLEN);       
-               ops = cim_disk2msg(pathname);
-       }
+       ops = ( RESOURCE_ENABLED(rscid)) ?/* from CIB */
+               cim_query_dispatch(GET_RSC_OPERATIONS, rscid, NULL) :
+               cim_dbget_msg(CIM_RSCOPS_TABLE, rscid);
        return ops;
 }
 
@@ -1592,12 +1383,11 @@
 {
        struct ha_msg *ops;
        int ret;
-       char pathname[MAXLEN] = CIM_RSCOPS_PREFIX;
 
-       if ( ! cim_is_rsc_disabled(rscid) ) {   /* update to CIB */
+       if ( RESOURCE_ENABLED(rscid) ) {        /* update to CIB */
                ret = cim_update_dispatch(DEL_OPERATION, opid, NULL, NULL);
                return ret;
-       };
+       } ;
 
        if ((ops = cim_get_rscops(rscid)) == NULL ) {
                cl_log(LOG_WARNING, "cim_del_rscop: ops not exists");
@@ -1605,12 +1395,7 @@
        }
 
        cim_msg_remove_child(ops, opid);
-
-       /* write back to disk */
-       strncat(pathname, rscid, MAXLEN);
-       ret = cim_msg2disk(pathname, ops);
-       ha_msg_del(ops);        
-
+       ret = cim_dbput_msg(CIM_RSCOPS_TABLE, rscid, ops);
        return ret;
 }
 
@@ -1627,14 +1412,9 @@
        }
 
        cim_msg_add_child(ops, cl_get_string(op, "id"), op);
-       if ( ! cim_is_rsc_disabled(rscid) ) {   /* update into CIB */
-               ret = cim_update_dispatch(UPDATE_OPERATIONS, rscid, ops, NULL);
-       } else {        /* write back to disk */
-               char pathname[MAXLEN] = CIM_RSCOPS_PREFIX;
-               strncat(pathname, rscid, MAXLEN);
-               /* write back to disk */
-               ret = cim_msg2disk(pathname, ops);
-       }
+       ret = ( RESOURCE_ENABLED(rscid) ) ? /* update into CIB */
+               cim_update_dispatch(UPDATE_OPERATIONS, rscid, ops, NULL) :
+               cim_dbput_msg(CIM_RSCOPS_TABLE, rscid, ops);
        ha_msg_del(ops);
        return ret;
 }
@@ -1656,14 +1436,9 @@
        cim_msg_remove_child(ops, id);
        cim_msg_add_child(ops, id, op);
        
-       if ( ! cim_is_rsc_disabled(rscid) ) {   /* update into CIB */
-               ret = cim_update_dispatch(UPDATE_OPERATIONS, rscid, ops, NULL);
-       } else {        /* write back to disk */
-               char pathname [MAXLEN] = CIM_RSCOPS_PREFIX;
-               strncat(pathname, rscid, MAXLEN);
-               /* write back to disk */
-               ret = cim_msg2disk(pathname, ops);
-       }
+       ret = RESOURCE_ENABLED(rscid) ? /* update into CIB */
+               cim_update_dispatch(UPDATE_OPERATIONS, rscid, ops, NULL) :
+               cim_dbput_msg(CIM_RSCOPS_TABLE, rscid, ops);
        ha_msg_del(ops);
        return ret;
 }
@@ -1671,27 +1446,19 @@
 /*********************************************************
  * resource attributes 
  ********************************************************/
-#define CIM_RSCATTRS_PREFIX "attributes_of_"
 int
-cim_erase_rscattrs(const char *rscid)
+cim_rscattrs_del(const char *rscid)
 {
-       char pathname[MAXLEN] = CIM_RSCATTRS_PREFIX;
-       strncat(pathname, rscid, MAXLEN);
-       return cim_disk_msg_del(pathname);
+       return cim_dbdel(CIM_RSCATTRS_TABLE, rscid);
 }
 
 struct ha_msg *
-cim_get_rscattrs(const char *rscid)
+cim_rscattrs_get(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);
-       }
+       attrs = (RESOURCE_ENABLED(rscid)) ?
+                       cim_query_dispatch(GET_RSC_ATTRIBUTES, rscid, NULL) :
+                       cim_dbget_msg(CIM_RSCATTRS_TABLE, rscid);
        return attrs;
 }
 
@@ -1699,9 +1466,8 @@
 cim_update_attrnvpair(const char*rscid, const char*nvid, struct ha_msg *nvpair)
 {
        int ret;
-       struct ha_msg *attrs = cim_get_rscattrs(rscid);
+       struct ha_msg *attrs = cim_rscattrs_get(rscid);
 
-       DEBUG_ENTER();
        if ( attrs == NULL ) {
                if ((attrs = ha_msg_new(1)) == NULL ) {
                        cl_log(LOG_ERR, "%s: attributes not found for %s",
@@ -1711,16 +1477,10 @@
        }
 
        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);
-       }
+       ret =  RESOURCE_DISABLED(rscid)?
+               cim_dbput_msg(CIM_RSCATTRS_TABLE, rscid, attrs) :
+               cim_update_dispatch(UPDATE_ATTRIBUTES, rscid, attrs, NULL);
        ha_msg_del(attrs);
-       DEBUG_LEAVE();
        return ret;
 }
 
@@ -1728,20 +1488,14 @@
 cim_remove_attrnvpair(const char* rscid, const char* nvid)
 {
        int ret;
-       struct ha_msg *attrs = cim_get_rscattrs(rscid);
+       struct ha_msg *attrs = cim_rscattrs_get(rscid);
        if ( attrs == NULL ) {
                return HA_FAIL;
        }
 
        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);
-       }
-
+       ret =  RESOURCE_DISABLED(rscid)? cim_dbdel(CIM_RSCATTRS_TABLE, rscid) :
+                       cim_update_dispatch(DEL_ATTRIBUTES, nvid, NULL, NULL);
        ha_msg_del(attrs);
        return ret;
 }
@@ -1756,15 +1510,14 @@
        int len, i;
        const char * id;
 
+       cim_debug2(LOG_INFO, "In AddPrimitiveForUpdate.");
        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);
-       }
+       attrs = attrs? attrs : cim_rscattrs_get(id);
        if ( attrs == NULL ) {
                cl_log(LOG_ERR, "%s: attributes of %s not found.", 
__FUNCTION__, id);
                return ;
@@ -1778,12 +1531,12 @@
 }
 
 int
-cim_cib_addrsc(const char *rscid)
+cim_rsc_submit(const char *rscid)
 {
        int type, ret;
        struct ha_msg *rsc, *sublist, *msg;
 
-       if ( ! cim_is_rsc_disabled(rscid) ){
+       if ( RESOURCE_ENABLED(rscid) ){
                cl_log(LOG_ERR, "%s: resource %s is already enabled. ",
                        __FUNCTION__, rscid);
                return HA_FAIL;
@@ -1821,7 +1574,7 @@
                        return HA_FAIL;
                }
 
-               CLEAN_RESOURCE_RECORD(rscid);
+               cim_rscdb_cleanup(TID_RES_GROUP, rscid);
 
                /* then add sub primitive resources into group */
                count = cim_list_length(sublist);
@@ -1831,12 +1584,10 @@
                                continue;
                        }
                        primitive = cim_find_rsc(TID_RES_PRIMITIVE, subrscid);
-                       cim_debug_msg(primitive, "%s: primitve to be added to 
group %s",
-                                       __FUNCTION__, rscid);
+                       cim_debug_msg(primitive, "%s: primitve:%s to be added 
to group %s",
+                                       __FUNCTION__, subrscid, rscid);
                        cim_debug2(LOG_INFO, "%s: ready to add", __FUNCTION__);
                        ret = cim_add_subrsc(rsc, primitive);
-
-                       CLEAN_RESOURCE_RECORD(cl_get_string(primitive, "id"));
                }
 
                ha_msg_del(sublist);
@@ -1861,8 +1612,7 @@
                }
                AddPrimitiveForUpdate(msg, primitive, NULL);
                ha_msg_add(msg, "groupid", ""); 
-               ha_msg_add(msg, "advance", 
-                               (type == TID_RES_CLONE) ? "clone":"master");
+               ha_msg_add(msg, "advance", cim_rsctype_tid2s(type)); 
                ha_msg_add(msg, "advance_id", rscid);
                ha_msg_add(msg, "clone_max", 
                                cl_get_string(rsc, "clone_max"));
@@ -1875,7 +1625,8 @@
 
                ret = cim_update_dispatch(CREATE_RESOURCE, NULL, msg, NULL);
 
-               CLEAN_RESOURCE_RECORD(cl_get_string(primitive, "id"));
+               cim_rscdb_cleanup(TID_RES_PRIMITIVE, 
+                               cl_get_string(primitive, "id"));
                ha_msg_del(sublist);
        } else if ( type == TID_RES_PRIMITIVE ) {
                AddPrimitiveForUpdate(msg, rsc, NULL);
@@ -1890,7 +1641,7 @@
 
                /* delete the disk image */
 
-               CLEAN_RESOURCE_RECORD(rscid);
+               cim_rscdb_cleanup(type, rscid);
        }
 
        ha_msg_del(rsc);
@@ -1898,14 +1649,68 @@
        return HA_OK;
 }
 
+int
+cim_rscdb_cleanup(int type, const char * rscid)
+{
+       if ( cim_rscname_table_del(rscid) != HA_OK ) {
+               cl_log(LOG_ERR, "%s: FATAL: can't update %s.",
+                       __FUNCTION__, CIM_RSCNAME_TABLE);
+               return HA_FAIL;
+       }
+
+       if ( type == TID_RES_PRIMITIVE && 
+                       cim_dbdel(CIM_RESOURCE_TABLE, rscid) != HA_OK ) {
+               cl_log(LOG_WARNING, "%s: FATAL: can't update %s.",
+                       __FUNCTION__, CIM_RESOURCE_TABLE);
+       }
+       if ( type == TID_RES_PRIMITIVE && 
+                       cim_rscattrs_del(rscid) != HA_OK ) {
+               cl_log(LOG_WARNING, "%s: FATAL: can't erase the attributes.",
+                       __FUNCTION__);
+       }
+       if ( cim_rsctype_table_del(rscid) != HA_OK ) {
+               cl_log(LOG_WARNING, "%s: FATAL: can't remove from type list..",
+                       __FUNCTION__);
+       }
+
+       if ( type == TID_RES_GROUP ) {
+               cim_debug2(LOG_INFO, "%s: %s is group, clean up subrsc_table.",
+                       __FUNCTION__, rscid);
+               cim_dbdel(CIM_SUBRSC_NAME_TABLE, rscid);        
+       }
+
+       return HA_OK;
+}
 
-#define CIM_RESOURCE_PREFIX "resource_"
 int
-cim_store_rsc(int type, const char *rscid, struct ha_msg *rsc)
+cim_rscdb_store(int type, const char *rscid, struct ha_msg *rsc)
 {
-       char pathname[MAXLEN] = CIM_RESOURCE_PREFIX;
-       strncat(pathname, rscid, MAXLEN);
-       return cim_msg2disk(pathname, rsc);
+       const char *rsctype = NULL;
+       if ( cim_dbput_msg(CIM_RESOURCE_TABLE, rscid, rsc) != HA_OK ) {
+               cl_log(LOG_ERR, "%s: cant't write resource image.", 
+                       __FUNCTION__);
+               return HA_FAIL;
+       }
+
+       /* update rsctype table */
+       rsctype = cim_rsctype_tid2s(type);
+       if (cim_rsctype_table_add(rscid, rsctype) != HA_OK ) {
+               cl_log(LOG_ERR, "%s: cant't update resource type table.", 
+                       __FUNCTION__);
+               cim_dbdel(CIM_RESOURCE_TABLE, rscid);
+               return HA_FAIL;
+       }
+
+       /* update rsc list */
+       if ( cim_rscname_table_add(rscid) != HA_OK) {
+               cl_log(LOG_ERR, "%s: cant't update %s.", 
+                       __FUNCTION__, CIM_RSCNAME_TABLE);
+               cim_dbdel(CIM_RESOURCE_TABLE, rscid);
+               cim_rsctype_table_del(rscid);
+               return HA_FAIL;
+       }
+
+       return HA_OK;
 }
 
 struct ha_msg* 
@@ -1913,12 +1718,8 @@
 {
        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);
+       if (RESOURCE_DISABLED(rscid)) {
+               rsc = cim_dbget_msg(CIM_RESOURCE_TABLE, rscid);
                goto done;
        }
  
@@ -1949,7 +1750,7 @@
 {
        int ret = HA_FAIL;
 
-       if ( ! cim_is_rsc_disabled(rscid) ) {   /* in-cib resource */
+       if ( RESOURCE_ENABLED(rscid) ) {        /* in-cib resource */
                if ( type == TID_RES_CLONE ) {
                        ret = cim_update_dispatch(UPDATE_CLONE, 
                                                NULL, resource, NULL); 
@@ -1960,7 +1761,12 @@
                        ret = HA_OK;
                }
        } else {        /* update disk image */
-               ret = cim_store_rsc(type, rscid, resource);
+               /*
+               char pathname[MAXLEN] = CIM_RESOURCE_PREFIX;
+               strncat(pathname, rscid, MAXLEN);
+               ret = cim_msg2disk(pathname, resource);
+               */
+               ret = cim_dbput_msg(CIM_RESOURCE_TABLE, rscid, resource);
        }
        return ret;
 }
@@ -1970,16 +1776,19 @@
 {
        int ret;
        struct ha_msg * msg;
-       if ( !cim_is_rsc_disabled(rscid)) {
+       if ( RESOURCE_ENABLED(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);
+               if ( cim_get_rsctype(rscid) == TID_RES_PRIMITIVE ) {
+                       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);
+               cim_rscdb_cleanup(cim_get_rsctype(rscid), rscid);
                ret = HA_OK;
        }
        return ret;
@@ -1988,20 +1797,15 @@
 /*****************************************************************
  * 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);
+
+       sublist =  ( RESOURCE_ENABLED(rscid) )?
+               cim_query_dispatch(GET_SUB_RSC, rscid, NULL) :
+               cim_dbget_msg(CIM_SUBRSC_NAME_TABLE, rscid);
+       return sublist;
 }
 
 int
@@ -2009,22 +1813,22 @@
 {
        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");
+       cim_debug2(LOG_INFO, "%s: adding subrsc: %s to %s.",
+                       __FUNCTION__, rscid, subrscid);
 
-       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);
+       if ( RESOURCE_ENABLED(subrscid) ){
+               cl_log(LOG_ERR, "%s: resource %s is already in CIB.",
+                       __FUNCTION__, 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 ( RESOURCE_DISABLED(rscid) ) {       /* write to disk */
+               sublist = cim_dbget_msg(CIM_SUBRSC_NAME_TABLE, rscid);
                if (sublist == NULL ) { /* not exist yet */
                        if ((sublist = ha_msg_new(1)) == NULL ) {
                                cl_log(LOG_ERR, "cim_add_subrsc: "
@@ -2032,13 +1836,9 @@
                                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);
+               ret = cim_dbput_msg(CIM_SUBRSC_NAME_TABLE, rscid, sublist);
        } else {                /* update to CIB */
                struct ha_msg * msg;
 
@@ -2070,59 +1870,10 @@
                cim_debug2(LOG_INFO, "%s: create resource.", __FUNCTION__);
                ret = cim_update_dispatch(CREATE_RESOURCE, NULL, msg, NULL);
        
-               /* update disk status */        
-               CLEAN_RESOURCE_RECORD(subrscid);
-
+               cim_rscdb_cleanup(TID_RES_PRIMITIVE, 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.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- cluster_info.h      13 Apr 2006 07:58:35 -0000      1.6
+++ cluster_info.h      25 Apr 2006 17:46:45 -0000      1.7
@@ -47,12 +47,21 @@
 #define TID_CONS_COLOCATION  0x63
 #define TID_ARRAY            0x100
 
+#define S_RES_PRIMITIVE                "native"
+#define S_RES_GROUP            "group"
+#define S_RES_CLONE            "clone"
+#define S_RES_MASTER           "master"
+#define S_RES_UNKNOWN          "unknown"
+
 #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"
 
+
+#define        HA_CIM_VARDIR           "/var/lib/heartbeat/cim"
+
 enum { HB_RUNNING = 1, HB_STOPED = 2, HB_UNKNOWN = 3 };
 enum { START_HB   = 1, STOP_HB   = 2, RESTART_HB = 3 };
 
@@ -134,17 +143,20 @@
 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);
+#define RESOURCE_ENABLED(rscid) (cim_rsc_is_in_cib(rscid))
+#define RESOURCE_DISABLED(rscid) (!cim_rsc_is_in_cib(rscid))
 
-/* resource type */
-int            cim_add_rsctype(const char* rscid, const char *type);
+/* get a resource's type: TID_RES_PRIMITIVE, etc */
 int            cim_get_rsctype(const char * rscid);
-int            cim_remove_rsctype(const char* rscid);
+
+/* resource list */
+int            cim_rsc_is_in_cib(const char *rscid);
+
+/* not include sub resources */
+struct ha_msg* cim_get_all_rsc_list(void);
+
+/* retrive the closure of the list */
+struct ha_msg*         cim_traverse_allrsc(struct ha_msg* list);
 
 /* resource operations */
 struct ha_msg * cim_get_rscops(const char *rscid);
@@ -153,8 +165,12 @@
 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);
+/* submit a resource to CIB */
+int            cim_rsc_submit(const char *rscid);
+/* store a resource image on the disk */
+int            cim_rscdb_store(int type, const char *rscid, struct ha_msg 
*rsc);
+/* cleanup a resource image from the disk, as well as its attributes, type ... 
*/
+int            cim_rscdb_cleanup(int type, const char * rscid);
 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);
@@ -164,25 +180,9 @@
 int            cim_add_subrsc(struct ha_msg *rsc, struct ha_msg *subrsc);
 
 /* resource attributes */
-struct ha_msg *        cim_get_rscattrs(const char *rscid);
+struct ha_msg *        cim_rscattrs_get(const char *rscid);
+int            cim_rscattrs_del(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)                                      \
-       ((char *)cl_msg_list_nth_data(msg, CIM_MSG_LIST, index))
-
-#define cim_list_add(msg, value)                                       \
-       cl_msg_list_add_string(msg, CIM_MSG_LIST, value)                
-
-#define cim_msg_add_child(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)
-
-int            cim_msg_children_count(struct ha_msg *parent);
-const char *   cim_msg_child_name(struct ha_msg * parent, int index);
-struct ha_msg * cim_msg_child_index(struct ha_msg *parent, int index);
 
 #endif    /* _CLUSTER_INFO_H */




------------------------------

_______________________________________________
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 130
*********************************************

Reply via email to