⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lrmadmin.c

📁 linux集群服务器软件代码包
💻 C
📖 第 1 页 / 共 2 页
字号:
		default:			fprintf(stderr, "This option is not supported yet.\n");			ret_value = -1;			ASYN_OPS = FALSE;			break;		}	if (ASYN_OPS) {		printf( "waiting for calling result from the lrmd.\n");		lrmd->lrm_ops->rcvmsg(lrmd,TRUE);	}	lrmd->lrm_ops->signoff(lrmd);	return ret_value;}static voidlrm_op_done_callback(lrm_op_t* op){	if (!op) {		cl_log(LOG_ERR, "In callback function, op is NULL pointer.");		return;	}	printf("----------------operation--------------\n");	printf("type:%s\n", op->op_type);	printf("operation status:%s\n", status_msg[op->op_status-LRM_OP_DONE]);	if ( op->op_status==LRM_OP_DONE ) {		printf("return code:%d\n", op->rc);		printf("output data:\n%s\n", op->output);	}	printf("---------------------------------------\n\n");	/* Don't need ?	 * g_free(op->rsc);  	 * g_free(op);	 */}static int resource_operation(ll_lrm_t * lrmd, int argc, int optind, char * argv[]){	char rsc_id[RID_LEN];	GHashTable * params_ht = NULL;	lrm_op_t op;	lrm_rsc_t * lrm_rsc;	int call_id;		if ((argc - optind) < 3) {		cl_log(LOG_ERR,"No enough parameters.");		return -2;	}	rsc_id[RID_LEN-1] = '\0';	strncpy(rsc_id, argv[optind], RID_LEN-1);	lrm_rsc = lrmd->lrm_ops->get_rsc(lrmd, rsc_id);		if (!lrm_rsc) {		return -1;	}	op.op_type = argv[optind+1];	op.timeout = atoi(argv[optind+2]);	op.interval = atoi(argv[optind+3]);	op.user_data = NULL;	op.user_data_len = 0;	if (0 == strcmp(argv[optind+4], "EVERYTIME")) {		op.target_rc = EVERYTIME;	}	else	if (0 == strcmp(argv[optind+4], "CHANGED")) {		op.target_rc = CHANGED;	}	else {		op.target_rc = atoi(argv[optind+4]);	}	if ((argc - optind) > 3) {		if (0 > transfer_cmd_params(argc, optind+5, argv, 				lrm_rsc->class, &params_ht) ) {			return -2;		}	}	op.params = params_ht;	call_id = lrm_rsc->ops->perform_op(lrm_rsc, &op);	/* g_free(lrm_rsc);   don't need to free it ? */	if (params_ht) {		g_hash_table_foreach(params_ht, free_stritem_of_hashtable, NULL);		g_hash_table_destroy(params_ht);	}	return call_id;}static intra_metadata(ll_lrm_t * lrmd, int argc, int optind, char * argv[]){	const char * class = argv[optind-1];	const char * type = argv[optind];	const char * provider = argv[optind+1];	char* metadata;	if(argc < 5) {		cl_log(LOG_ERR,"No enough parameters.");		return -2;	}	if (0 == strncmp(provider,"NULL",strlen("NULL"))) {		provider=NULL;	}	metadata = lrmd->lrm_ops->get_rsc_type_metadata(lrmd, class, type, provider);	if (NULL!=metadata) {		printf ("metadata of %s(%s) is: %s\n",type,class,metadata);		g_free (metadata);	}	return 0;}static intra_provider(ll_lrm_t * lrmd, int argc, int optind, char * argv[]){	const char * class = argv[optind-1];	const char * type = argv[optind];	GList* providers = NULL;	GList* provider = NULL;		if(argc < 4) {		cl_log(LOG_ERR,"No enough parameters.");		return -2;	}	providers = lrmd->lrm_ops->get_rsc_provider_supported(lrmd,class,type);		while (NULL != (provider = g_list_first(providers))) {		printf("%s\n",(char*)provider->data);		providers = g_list_remove(providers, provider->data);		g_free(provider->data);	}	g_list_free(providers);	return 0;}static int add_resource(ll_lrm_t * lrmd, int argc, int optind, char * argv[]){	char rsc_id[RID_LEN];	const char * class = argv[optind+1];	const char * type = argv[optind+2];	const char * provider = argv[optind+3];	GHashTable * params_ht = NULL;	int tmp_ret;	if ((argc - optind) < 4) {		cl_log(LOG_ERR,"No enough parameters.");		return -2;	}		rsc_id[RID_LEN-1]='\0';	strncpy(rsc_id, argv[optind], RID_LEN-1);	if (0 == strncmp(provider, "NULL", strlen("NULL"))) {		provider=NULL;	}		/* delete Hashtable */	if ((argc - optind) > 4) {		if ( 0 > transfer_cmd_params(argc, optind+4, argv, class,					&params_ht) ) {			return -1;		}	}	tmp_ret = lrmd->lrm_ops->add_rsc(lrmd, rsc_id, class, 						type, provider, params_ht);	/*delete params_ht*/	if (params_ht) {		g_hash_table_foreach(params_ht, free_stritem_of_hashtable, NULL);		g_hash_table_destroy(params_ht);	}	return (tmp_ret ? 0 : -1); /* tmp_ret is HA_OK=1 or HA_FAIL=0 */}static inttransfer_cmd_params(int amount, int start, char * argv[], const char * class, GHashTable ** params_ht){	int i, len_tmp;	char * delimit, * key, * value;	char buffer[21];	if (amount < start) {		return -1;	}	if ( strncmp("ocf", class, strlen("ocf"))==0	    || strncmp("stonith", class, strlen("stonith"))==0) {		*params_ht = g_hash_table_new(g_str_hash, g_str_equal);		for (i=start; i<amount; i++) {			delimit = strchr(argv[i], '=');			if (!delimit) {				cl_log(LOG_ERR, "parameter %s is invalid for "					"OCF standard.", argv[i]);				goto error_return; /* Have to */			}			len_tmp = strnlen(delimit+1, 80) + 1;			value = g_new(gchar, len_tmp);			strncpy(value, delimit+1, len_tmp);			len_tmp = strnlen(argv[i], 80) - strnlen(delimit, 80);			key = g_new(gchar, len_tmp+1);			key[len_tmp] = '\0';			strncpy(key, argv[i], len_tmp);						g_hash_table_insert(*params_ht, key, value);		}	} else if ( strncmp("lsb", class, strlen("lsb")) == 0		   || strncmp("heartbeat", class, strlen("heartbeat")) == 0 ) {		/* Pay attention: for parameter ordring issue */		*params_ht = g_hash_table_new(g_str_hash, g_str_equal);		memset(buffer, '0', 21);		for (i=start; i<amount; i++) {			snprintf(buffer, 20, "%d", i-start+1);			g_hash_table_insert( *params_ht, g_strdup(buffer), 						g_strdup(argv[i]));			/* printf("index: %d  value: %s \n", i-start+1, argv[i]); */		}	} else {		fprintf(stderr, "Not supported resource agency class.\n");		return -1;	}	return 0;error_return:	if (*params_ht) {		g_hash_table_foreach(*params_ht, free_stritem_of_hashtable, NULL);		g_hash_table_destroy(*params_ht);		*params_ht = NULL;	}	return -1;}static char * params_hashtable_to_str(const char * class, GHashTable * ht){	int i,ht_size;	gchar * params_str = NULL;	GString * gstr_tmp;	gchar * tmp_str;	if (!ht) {		 return NULL;	}	if (   strncmp("ocf", class, strlen("ocf")) == 0 	    || strncmp("stonith", class, strlen("stonith")) == 0) {		gstr_tmp = g_string_new("");		g_hash_table_foreach(ht, ocf_params_hash_to_str, &gstr_tmp);		params_str = g_new(gchar, gstr_tmp->len+1);				strncpy(params_str, gstr_tmp->str, gstr_tmp->len+1);		g_string_free(gstr_tmp, TRUE);	} else if (   strncmp("lsb", class, strlen("lsb")) == 0		   || strncmp("heartbeat", class, strlen("heartbeat")) == 0 ) {		ht_size = g_hash_table_size(ht);		tmp_str = g_new(gchar, ht_size*ARGVI_MAX_LEN); 			memset(tmp_str, ' ', ht_size*ARGVI_MAX_LEN);		tmp_str[ht_size*ARGVI_MAX_LEN-1] = '\0';		g_hash_table_foreach(ht, normal_params_hash_to_str, &tmp_str);		gstr_tmp = g_string_new("");		for (i=0; i< ht_size; i++) {			gstr_tmp = g_string_append(gstr_tmp						, tmp_str + i*ARGVI_MAX_LEN );			gstr_tmp = g_string_append(gstr_tmp, "  ");		}		params_str = g_new(gchar, gstr_tmp->len+1);				strncpy(params_str, gstr_tmp->str, gstr_tmp->len+1);		g_string_free(gstr_tmp, TRUE);	} else {		fprintf(stderr, "Not supported resource agency class.\n");	}	return params_str;}static voidg_print_stringitem(gpointer data, gpointer user_data){	printf("%s\n", (char*)data);	g_free(data);  /*  ?  */}static voidg_print_rainfo_item(gpointer data, gpointer user_data){/*	rsc_info_t * rsc_info = (rsc_info_t *) data; */	printf("RA type name: %s\n", (char *)data);/*	printf("RA type name: %s  Version: %s\n", 		rsc_info->rsc_type, rsc_info->version);*/	g_free(data); /*  ?  */}static voidg_print_ops(gpointer data, gpointer user_data){	printf("%s  ", (char*)data);	g_free(data);  /*  ?  */}static voidg_get_rsc_description(gpointer data, gpointer user_data){	ll_lrm_t* lrmd = (ll_lrm_t *)user_data;	lrm_rsc_t * lrm_rsc;	char rsc_id_tmp[RID_LEN];		if (!(user_data)) {		return;	}	memset(rsc_id_tmp, '\0', RID_LEN);	strncpy(rsc_id_tmp, data, RID_LEN-1);	lrm_rsc = lrmd->lrm_ops->get_rsc(lrmd, rsc_id_tmp);	if (lrm_rsc) {		print_rsc_inf(lrm_rsc);		g_free(lrm_rsc);   /* ? */	} else		cl_log(LOG_ERR, "There is a invalid resource id %s.", 			rsc_id_tmp);		g_free(data); /* ? */}static voidprint_rsc_inf(lrm_rsc_t * lrm_rsc){	char rscid_str_tmp[RID_LEN];	char * tmp = NULL;	if (!lrm_rsc) {		return;	}	rscid_str_tmp[RID_LEN-1] = '\0';	strncpy(rscid_str_tmp, lrm_rsc->id, RID_LEN-1);	printf("\nResource ID:%s\n", rscid_str_tmp);	printf("Resource agency class:%s\n", lrm_rsc->class);	printf("Resource agency type:%s\n", lrm_rsc->type);	printf("Resource agency provider:%s\n", lrm_rsc->provider?lrm_rsc->provider:"default");	if (lrm_rsc->params) {		tmp = params_hashtable_to_str(lrm_rsc->class, 				lrm_rsc->params);		printf("Resource agency parameters:%s\n", tmp);		g_free(tmp);	}}static voidfree_stritem_of_hashtable(gpointer key, gpointer value, gpointer user_data){	/*printf("key=%s   value=%s\n", (char *)key, (char *)value);*/	g_free(key);	g_free(value);}static voidocf_params_hash_to_str(gpointer key, gpointer value, gpointer user_data){	GString * gstr_tmp = *(GString **)user_data;	gstr_tmp = g_string_append(gstr_tmp, (char*)key);	gstr_tmp = g_string_append(gstr_tmp, "=");	gstr_tmp = g_string_append(gstr_tmp, (char *)value);	gstr_tmp = g_string_append(gstr_tmp, "  ");}static voidnormal_params_hash_to_str(gpointer key, gpointer value, gpointer user_data){	gint key_int;	gchar * str_tmp = *(gchar **) user_data;	if (str_tmp == NULL ) {		return;	}	key_int = atoi((char *)key) - 1;	strncpy(str_tmp + key_int * ARGVI_MAX_LEN, (char*)value,		ARGVI_MAX_LEN - 1);}static lrm_rsc_t * get_lrm_rsc(ll_lrm_t * lrmd, char * rscid){	char uuid_str_tmp[RID_LEN];	lrm_rsc_t * lrm_rsc;	lrm_rsc = lrmd->lrm_ops->get_rsc(lrmd, rscid);	if (!(lrm_rsc)) {		uuid_str_tmp[RID_LEN-1] = '\0';		strncpy(uuid_str_tmp, rscid, RID_LEN-1);		cl_log(LOG_ERR,"No this resource %s.", uuid_str_tmp);	}	return lrm_rsc;}/* * $Log: lrmadmin.c,v $ * Revision 1.25  2004/12/09 07:16:58  sunjd * add the support to stonith RA; some minor polish * * Revision 1.24  2004/12/05 13:18:32  sunjd * add the support to stonith RAs * * Revision 1.23  2004/11/23 20:58:18  andrew * Commit zhenh's patch for preserving user data across connections * Only supports flat objects (ie. char* or structs without pointers in them) * * Revision 1.22  2004/10/24 12:38:33  lge * -pedantic-errors fixes take one: * * error: ISO C89 forbids mixed declarations and code * * Revision 1.21  2004/10/11 02:11:07  zhenh * remove comment line with // * * Revision 1.20  2004/10/10 09:27:53  zhenh * change some output information to make it more clear * * Revision 1.19  2004/10/08 04:47:54  zhenh * fix a bug: checking the return value of get_rsc_type_metadata * * Revision 1.18  2004/09/16 06:16:45  sunjd * BEAM bug fix: passing NULL to argument 1 of g_free * * Revision 1.17  2004/09/14 09:17:35  sunjd * fix two pointer bugs found by BEAM * * Revision 1.16  2004/09/10 10:25:50  sunjd * Minor polish to message format * * Revision 1.15  2004/09/10 00:28:17  zhenh * change the usage information * * Revision 1.14  2004/09/09 03:32:50  zhenh * fix a mis type * * Revision 1.13  2004/09/03 01:29:44  zhenh * add provider for resource * * Revision 1.12  2004/08/30 03:17:40  msoffen * Fixed more comments from // to standard C comments * * Revision 1.11  2004/08/29 04:42:03  msoffen * Added missing ID and Log * */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -