[sheepdog] [PATCH v10 2/4] collie: check an error during issuing request correctly
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Wed Jul 31 11:44:10 CEST 2013
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>
---
v10
- recover correct result checking in node_recovery()
- reorder previous 2nd and 4th for removing reversed dependency
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 b2b9fb1..38bba09 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -189,7 +189,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.7.10.4
More information about the sheepdog
mailing list