[sheepdog] [PATCH stable-0.6] collie: check an error during issuing request correctly

Hitoshi Mitake mitake.hitoshi at gmail.com
Tue Aug 20 17:58:35 CEST 2013


From: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>

Current collie checks error during issuing request by a return value
of collie_exec_req(). But it doesn't work well because
collie_exec_req() returns result code of the request. The code doesn't
represent that the request itself succeeded or not.

This patch lets collie_exec_req() return 0 or -1 for checking the
error which is caused during request issue. And also fixes invalid
error checking done in node_recovery().

In addtion, the last return statement of collie_exec_req() is changed
like this: return ret ? -1 : 0; This ternay operator is required
because exec_req() returns 1 when it fails. Some part of collie check
an error of collie_exec_req() by if (ret < ), and other part check by
if (ret). The above ternay operator is for avoiding return 1 and let
these error handlers work correct.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 collie/common.c | 2 +-
 collie/node.c   | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/collie/common.c b/collie/common.c
index 2b08db1..c305b90 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -187,7 +187,7 @@ int collie_exec_req(const char *host, int port, struct sd_req *hdr, void *data)
 	if (ret)
 		return -1;
 
-	return rsp->result;
+	return ret ? -1 : 0;
 }
 
 /* Light request only contains header, without body content. */
diff --git a/collie/node.c b/collie/node.c
index 0cd7e7a..69229f4 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -132,13 +132,17 @@ static int node_recovery(int argc, char **argv)
 	for (i = 0; i < sd_nodes_nr; i++) {
 		char host[128];
 		struct sd_req req;
+		struct sd_rsp *rsp = (struct sd_rsp *)&req;
 
 		addr_to_str(host, sizeof(host), sd_nodes[i].nid.addr, 0);
 
 		sd_init_req(&req, SD_OP_STAT_RECOVERY);
 
 		ret = collie_exec_req(host, sd_nodes[i].nid.port, &req, NULL);
-		if (ret == SD_RES_NODE_IN_RECOVERY) {
+		if (ret < 0)
+			return EXIT_SYSFAIL;
+
+		if (rsp->result == SD_RES_NODE_IN_RECOVERY) {
 			addr_to_str(host, sizeof(host),
 					sd_nodes[i].nid.addr, sd_nodes[i].nid.port);
 			printf(raw_output ? "%d %s %d %d\n" : "%4d   %-20s%5d%11d\n",
-- 
1.8.1.2




More information about the sheepdog mailing list