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])
2. Linux-HA CVS: cim by panjiam from
([email protected])
3. Linux-HA CVS: cim by panjiam from
([email protected])
----------------------------------------------------------------------
Message: 1
Date: Tue, 25 Apr 2006 11:34:50 -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:
mgmt_client.c
Log Message:
more logs, LOG_ERR->LOG_WARNING
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/cim/mgmt_client.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- mgmt_client.c 13 Apr 2006 08:31:54 -0000 1.3
+++ mgmt_client.c 25 Apr 2006 17:34:50 -0000 1.4
@@ -174,8 +174,9 @@
__FUNCTION__, client->cmnd, result);
if ( ! mgmt_result_ok(result) ) {
- cl_log(LOG_ERR, "mclient_process: client return \'failed\'.");
- cl_log(LOG_ERR, "mclient_process: %s", result);
+ cl_log(LOG_WARN, "mclient_process: client return \'failed\'.");
+ cl_log(LOG_WARN, "mclient_process: cmnd %s", client->cmnd);
+ cl_log(LOG_WARN, "mclient_process: %s", result);
rc = MC_FAIL;
goto exit1;
}
------------------------------
Message: 2
Date: Tue, 25 Apr 2006 11:36:10 -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/tests
Modified Files:
ResourceTest.sh
Log Message:
wait till cib updated
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/cim/tests/ResourceTest.sh,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- ResourceTest.sh 25 Apr 2006 08:59:56 -0000 1.2
+++ ResourceTest.sh 25 Apr 2006 17:36:10 -0000 1.3
@@ -10,6 +10,11 @@
PASSWD=$2
CIB=/var/lib/heartbeat/crm/cib.xml
+function wait_cib_updated()
+{
+ sleep 2
+}
+
function resource_query ()
{
crm_resource -Q -r $1
@@ -118,9 +123,8 @@
create_primitive_resource "IPaddr" "$RESOURCE_ID"
create_attribute $RESOURCE_ID $ATTRIBUTE_ID "ip" "127.0.0.111"
-
cib_add_resource $RESOURCE_ID
-sleep 2
+wait_cib_updated
rc=0
resource_query $RESOURCE_ID
@@ -139,21 +143,20 @@
# resource group
#############################################################
+GROUP_ID=test_resource_group
+delete_resource HA_ResourceGroup $GROUP_ID
+
echo "---------------------------------------------------"
echo "Resource Group Creation test"
echo "---------------------------------------------------"
SUB_RESOURCE_ID=sub_resource_1
SUB_ATTRIBUTE_ID=${SUB_RESOURCE_ID}_ip
-GROUP_ID=test_resource_group
create_primitive_resource "IPaddr" "$SUB_RESOURCE_ID"
create_attribute $SUB_RESOURCE_ID $SUB_ATTRIBUTE_ID "ip" "127.0.0.111"
-
create_resource_group $GROUP_ID
group_add_resource $GROUP_ID $SUB_RESOURCE_ID
-
-cib_add_resource $GROUP_ID
-sleep 2
+wait_cib_updated
resource_query $GROUP_ID
rc=0
@@ -167,7 +170,6 @@
if [ $rc = 0 ]; then
echo "[OK] create resource group:$GROUP_ID successfully."
fi
-
echo "---------------------------------------------------"
echo "Resource Group Add Resource test"
echo "---------------------------------------------------"
@@ -177,8 +179,7 @@
create_primitive_resource "IPaddr" $SUB_RESOURCE_ID2
create_attribute $SUB_RESOURCE_ID2 $SUB_ATTRIBUTE_ID2 "ip" "127.0.0.112"
group_add_resource $GROUP_ID $SUB_RESOURCE_ID2
-
-sleep 2
+wait_cib_updated
resource_query $GROUP_ID
resource_query $GROUP_ID | grep $SUB_RESOURCE_ID2 >/dev/null \
|| { echo "[FAILED] $SUB_RESOURCE_ID2 not found in CIB." && rc=1; }
------------------------------
Message: 3
Date: Tue, 25 Apr 2006 11:45:12 -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:
utils.h utils.c
Log Message:
1. removed the old codes.
2. moved msg handling functions from cluster_info.c to utils.c
3. implemented a simple file db based on ha_msg to simplify the cache
management, the performance was not well considered.
for a management tool, i supposed this performance was insignificant,
becuase most of the cpu time is spent on the communication.
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/cim/utils.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- utils.h 10 Apr 2006 10:27:16 -0000 1.4
+++ utils.h 25 Apr 2006 17:45:12 -0000 1.5
@@ -73,118 +73,7 @@
cl_log(LOG_INFO, "%s", msg2string(msg));\
}while (0)
-/* container */
-enum ContainerType { T_ARRAY, T_TABLE };
-/* container and element type */
-typedef struct {
- GHashTable * table; /* must be the 1st */
- int type;
- } CIMTable;
-
-typedef struct {
- GPtrArray * array; /* must be the 1st */
- int type;
- } CIMArray;
-
-enum DataType { TYPEString, TYPEUint32, TYPEUint16, TYPEArray,
TYPETable };
-
-typedef struct cimdata_t_s {
- union {
- char * str;
- uint32_t uint32;
- CIMArray * array;
- CIMTable * table;
- } v; /* this must be the first */
- int type;
-} cimdata_t;
-
-#define makeStrData(s) ({ \
- cimdata_t * data = (cimdata_t*)cim_malloc(sizeof(cimdata_t)); \
- if(data) { \
- data->type = TYPEString; \
- data->v.str = cim_strdup(s); \
- }; \
- data; \
-})
-
-#define makeUint32Data(i) ({ \
- cimdata_t * data = (cimdata_t*)cim_malloc(sizeof(cimdata_t)); \
- if(data) { \
- data->type = TYPEUint32; \
- data->v.uint32 = i; \
- }; \
- data; \
-})
-
-#define makeArrayData(x) ({ \
- cimdata_t * data = (cimdata_t*)cim_malloc(sizeof(cimdata_t)); \
- if(data) { \
- data->type = TYPEArray; \
- data->v.array = x; \
- }; \
- data; \
-})
-
-
-#define makeTableData(x) ({ \
- cimdata_t * data = (cimdata_t*)cim_malloc(sizeof(cimdata_t)); \
- if(data) { \
- data->type = TYPETable; \
- data->v.table = x; \
- }; \
- data; \
-})
-
-
-/* table */
-#define cim_table_new() ({ \
- CIMTable * t = (CIMTable*)cim_malloc(sizeof(CIMTable)); \
- if (t) { \
- t->table = g_hash_table_new_full(g_str_hash, g_str_equal, \
- cim_free, cimdata_free); \
- t->type = T_TABLE; \
- } \
- t; \
-})
-
-
-#define cim_table_lookup(t,k) ((cimdata_t*)g_hash_table_lookup(t->table,k))
-#define cim_table_lookup_v(t,k) ({
\
- cimdata_t zero_data = { {NULL}, 0 }; \
- cimdata_t * d = (cimdata_t*)g_hash_table_lookup(t->table,k); \
- (d? (*d) : zero_data); \
-})
-
-#define cim_table_foreach(x,a,b) g_hash_table_foreach(x->table, a,b)
-#define cim_table_replace(t,k,v) g_hash_table_replace(t->table,k,v)
-#define cim_table_insert(t,k,v) g_hash_table_insert(t->table,k,v)
-
-/* array */
-#define cim_array_new() ({ \
- CIMArray * a = (CIMArray*)cim_malloc(sizeof(CIMArray)); \
- if (a) { \
- a->array = g_ptr_array_new(); \
- a->type = T_ARRAY; \
- }; \
- a; \
-})
-
-#define cim_array_append(a,p) g_ptr_array_add(a->array,p)
-#define cim_array_index(a,i) g_ptr_array_index(a->array,i)
-#define cim_array_index_v(a,i) ({ \
- cimdata_t zero_data = {{NULL}, 0}; \
- cimdata_t * d = (cimdata_t*)cim_array_index(a,i); \
- (d?(*d) : zero_data ); \
-})
-
-#define cim_array_len(a) ((a && a->array)?a->array->len:0)
-
-void cim_table_free(void * table);
-void cim_array_free(void*);
-void cimdata_free(void * data);
-int cim_table_strdup_replace(CIMTable*table, const char*key, const
char*val);
-void dump_cim_table(CIMTable *table, const char *id);
int cim_init_logger(const char* entity);
void cim_assert(const char* assertion, int line, const char* file);
int run_shell_cmnd(const char* cmnd,int* ret,char*** out,char***);
@@ -194,4 +83,46 @@
char* uuid_to_str(const cl_uuid_t * uuid);
char** split_string(const char *string, int *len, const char *delim);
+
+#define cim_dbget_msg(pathname, key) ({ \
+ struct ha_msg *msg = NULL; \
+ char *value = cim_dbget(pathname, key); \
+ if (value) { \
+ msg = string2msg(value, strlen(value)); \
+ cim_free(value); \
+ } \
+ msg; \
+})
+
+#define cim_dbput_msg(pathname,key,msg) \
+ cim_dbput(pathname, key, msg?msg2string(msg):NULL)
+
+struct ha_msg* cim_disk2msg(const char *objpathname);
+int cim_msg2disk(const char *objpathname, struct ha_msg *);
+int cim_disk_msg_del(const char *objpathname);
+
+char* cim_dbget(const char *pathname, const char*key);
+int cim_dbput(const char *pathname, const char*key, const char*value);
+int cim_dbdel(const char *pathname, const char*key);
+struct ha_msg* cim_dbkeys(const char *pathname);
+
+
+int cim_list_find(struct ha_msg *list, const char *value);
+#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
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/cim/utils.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- utils.c 10 Apr 2006 10:27:16 -0000 1.5
+++ utils.c 25 Apr 2006 17:45:12 -0000 1.6
@@ -40,6 +40,8 @@
int debug_level = 10;
+static char * pathname_encode(const char *);
+
int
cim_init_logger(const char * entity)
{
@@ -213,30 +215,6 @@
exit(1);
}
-static void
-dump_foreach(void * key, void * value, void * user)
-{
- cimdata_t * d = (cimdata_t *) value;
- if ( d == NULL ) {
- return;
- }
- if ( d->type == TYPEString) {
- cl_log(LOG_INFO, "DUMP: %s: %s", (char *)key, d->v.str);
- } else if (d->type == TYPETable) {
- cl_log(LOG_INFO, "DUMP: %s: <table>", (char *)key);
- } else if ( d->type == TYPEArray ) {
- cl_log(LOG_INFO, "DUMP: %s: <array>", (char *)key);
- }
-}
-
-void
-dump_cim_table(CIMTable * table, const char * id)
-{
- cl_log(LOG_INFO, "--- Begin dump %s ---", id? id : "<NULL>");
- cim_table_foreach(table, dump_foreach, NULL);
- cl_log(LOG_INFO, "--- End dump %s ---", id? id : "<NULL>");
-
-}
char **
split_string(const char* string, int *len, const char *delim)
@@ -282,66 +260,300 @@
return strings;
}
-int
-cim_table_strdup_replace(CIMTable *table, const char *key,const char* val)
+int
+cim_msg2disk(const char *objpathname, struct ha_msg *msg)
{
- char * dupkey = NULL;
- cimdata_t * data;
- if ((dupkey = cim_strdup(key)) == NULL ) {
- cl_log(LOG_ERR, "cim_table:can't duplicate key.");
+ struct stat st;
+ FILE *fobj;
+ char pathname[MAXLEN], *buf;
+ char *msgstr = NULL;
+
+ 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;
}
- if ((data = makeStrData(val)) == NULL){
- cl_log(LOG_ERR, "cim_table:can't make data.");
- cim_free(dupkey);
+ 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;
- }
-
- cl_log(LOG_INFO, "[%s] <- %s", dupkey, val);
- cim_table_replace(table, dupkey, data);
+ }
+ if ( msg->nfields == 0 ) {
+ fclose(fobj);
+ return HA_OK;
+ }
+
+ if ((msgstr = msg2string(msg)) == NULL ) {
+ cl_log(LOG_ERR, "cim_msg2disk: msgstr NULL.");
+ return HA_FAIL;
+ }
+
+ fprintf(fobj, "%s", msgstr);
+ fclose(fobj);
return HA_OK;
}
+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 (st.st_size == 0 ) {
+ cl_log(LOG_WARNING, "disk2msg: size of %s is zero.",
objpathname);
+ return NULL;
+ }
+
+ if ((buf = cim_malloc(st.st_size)) == NULL ) {
+ cl_log(LOG_ERR, "disk2msg: alloc msg failed for %s.",
objpathname);
+ 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 for %s.", objpathname);
+ 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;
+}
+
+
+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;
+}
-void
-cimdata_free(void * data)
+
+char*
+cim_dbget(const char *pathname, const char*key)
{
- cimdata_t * d = (cimdata_t *)data;
- if ( d == NULL ) {
- return ;
+ struct ha_msg *db = cim_disk2msg(pathname);
+ const char * value;
+
+ if ( db == NULL ) {
+ return NULL;
}
- switch(d->type){
- case TYPEString: cim_free(d->v.str); break;
- case TYPETable: cim_table_free(d->v.table); break;
- case TYPEArray: cim_array_free(d->v.array); break;
- default:
- cl_log(LOG_WARNING, "cimdata_free: unknown data type");
- break;
+ value = cl_get_string(db, key);
+ if ( value == NULL || strncmp(value, "null", MAXLEN) == 0) {
+ return NULL;
}
- cim_free(d);
+ return cim_strdup(value);
}
-void
-cim_array_free(void * array)
+int
+cim_dbput(const char *pathname, const char*key, const char*value)
{
+ int ret;
+ struct ha_msg* db = cim_disk2msg(pathname);
+ if ( db == NULL ) {
+ if ( (db = ha_msg_new(1)) == NULL ) {
+ cl_log(LOG_ERR, "cim_dbput: alloc db failed.");
+ return HA_FAIL;
+ }
+ }
+
+ if ((cl_msg_modstring(db, key, value?value:"null")) != HA_OK ) {
+ ha_msg_del(db);
+ cl_log(LOG_ERR, "cim_dbput: put value failed.");
+ return HA_FAIL;
+ }
+
+ ret = cim_msg2disk(pathname, db);
+ ha_msg_del(db);
+ return HA_OK;
+}
+
+int
+cim_dbdel(const char *pathname, const char*key)
+{
+ int ret;
+ struct ha_msg* db = cim_disk2msg(pathname);
+ if ( db == NULL ) {
+ cl_log(LOG_ERR, "cim_dbdel: get db failed.");
+ return HA_FAIL;
+ }
+
+ if ((cl_msg_remove(db, key)) != HA_OK ) {
+ ha_msg_del(db);
+ cl_log(LOG_ERR, "cim_dbdel: remove failed.");
+ return HA_FAIL;
+ }
+
+ ret = cim_msg2disk(pathname, db);
+ ha_msg_del(db);
+ return HA_OK;
+}
+
+struct ha_msg*
+cim_dbkeys(const char *pathname)
+{
+ struct ha_msg * db = cim_disk2msg(pathname);
+ struct ha_msg * list;
int i;
- CIMArray * a = (CIMArray*)array;
- for (i=0; i<a->array->len; i++){
- cimdata_t * d = cim_array_index(a,i);
- cimdata_free(d);
+
+ if ( db == NULL ) {
+ cl_log(LOG_ERR, "cim_dbkeys: get db failed.");
+ return NULL;
}
- g_ptr_array_free(a->array, FALSE);
- cim_free(array);
+
+ if ( (list = ha_msg_new(1)) == NULL ) {
+ ha_msg_del(db);
+ cl_log(LOG_ERR, "cim_dbkeys: alloc list failed.");
+ return NULL;
+ }
+
+ for (i = 0; i < db->nfields; i++) {
+ cim_list_add(list, db->names[i]);
+ }
+
+ ha_msg_del(db);
+ return list;
}
-void
-cim_table_free(void * table)
+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;
+}
+
+
+/****************************************************
+ * msg
+ ****************************************************/
+int
+cim_msg_children_count(struct ha_msg *parent)
{
- CIMTable * t = (CIMTable *)table;
- g_hash_table_destroy(t->table);
- cim_free(t);
+ 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;
+}
+
+int
+cim_list_find(struct ha_msg *list, const char *value)
+{
+ int len = cim_list_length(list);
+ int i = 0;
+ for (i = 0; i<len; i++) {
+ char * v = cim_list_index(list, i);
+ if ( v && (strncmp(v, value, MAXLEN) == 0)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
------------------------------
_______________________________________________
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 129
*********************************************