瀏覽代碼

Allow only one connection per (node, pid, grp)

This patch allows only one connection per (node, pid, grp_name) tuple.
This means, you cannot make more connection from one process to same
group_name. This is (I hope) how cpg should behave. In case, you will
try to do that, CPG_ERR_EXISTS error is returned.

Of course, there is no problem with creating:
- more connection with same (pid, grp) if nodeid is different
- more connection with same (node, grp) if pid is different (for example
  after fork, or two distinct processes)
- more connection with same (node, pid) if grp is different (connect
  one process to more cpgs).


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2364 fd59a12c-fef9-0310-b244-a6a79926bd2f
Jan Friesse 16 年之前
父節點
當前提交
33c0b60b58
共有 1 個文件被更改,包括 15 次插入0 次删除
  1. 15 0
      services/cpg.c

+ 15 - 0
services/cpg.c

@@ -942,6 +942,20 @@ static void message_handler_req_lib_cpg_join (void *conn, const void *message)
 	struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
 	struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn);
 	struct res_lib_cpg_join res_lib_cpg_join;
 	struct res_lib_cpg_join res_lib_cpg_join;
 	cs_error_t error = CPG_OK;
 	cs_error_t error = CPG_OK;
+	struct list_head *iter;
+
+	/* Test, if we don't have same pid and group name joined */
+	for (iter = cpg_pd_list_head.next; iter != &cpg_pd_list_head; iter = iter->next) {
+		struct cpg_pd *cpd_item = list_entry (iter, struct cpg_pd, list);
+
+		if (cpd_item->pid == req_lib_cpg_join->pid &&
+			mar_name_compare(&req_lib_cpg_join->group_name, &cpd_item->group_name) == 0) {
+
+			/* We have same pid and group name joined -> return error */
+			error = CPG_ERR_EXIST;
+			goto response_send;
+		}
+	}
 
 
 	switch (cpd->cpd_state) {
 	switch (cpd->cpd_state) {
 	case CPD_STATE_UNJOINED:
 	case CPD_STATE_UNJOINED:
@@ -966,6 +980,7 @@ static void message_handler_req_lib_cpg_join (void *conn, const void *message)
 		break;
 		break;
 	}
 	}
 
 
+response_send:
 	res_lib_cpg_join.header.size = sizeof(res_lib_cpg_join);
 	res_lib_cpg_join.header.size = sizeof(res_lib_cpg_join);
         res_lib_cpg_join.header.id = MESSAGE_RES_CPG_JOIN;
         res_lib_cpg_join.header.id = MESSAGE_RES_CPG_JOIN;
         res_lib_cpg_join.header.error = error;
         res_lib_cpg_join.header.error = error;