[sheepdog] [PATCH] collie: fix a bug that 'collie node recovery' gives invalid output

levin li levin108 at gmail.com
Sun Aug 5 15:50:06 CEST 2012


From: levin li <xingke.lwp at taobao.com>


Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 collie/node.c |   23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/collie/node.c b/collie/node.c
index 2af4eb3..ccdf58e 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -119,15 +119,28 @@ static int node_recovery(int argc, char **argv)
 
 	for (i = 0; i < sd_nodes_nr; i++) {
 		char host[128];
-		struct sd_node_req req;
+		struct sd_req hdr;
+		struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
+		unsigned rlen = 0, wlen = 0;
+		int fd;
 
 		addr_to_str(host, sizeof(host), sd_nodes[i].nid.addr, 0);
 
-		sd_init_req((struct sd_req *)&req, SD_OP_STAT_RECOVERY);
+		fd = connect_to(host, sd_nodes[i].nid.port);
+		if (fd < 0)
+			return -1;
 
-		ret = send_light_req((struct sd_req *)&req, host,
-				     sd_nodes[i].nid.port);
-		if (!ret) {
+		sd_init_req((struct sd_req *)&hdr, SD_OP_STAT_RECOVERY);
+		ret = exec_req(fd, &hdr, NULL, &wlen, &rlen);
+		close(fd);
+
+		if (ret) {
+			fprintf(stderr, "failed to connect to  %s:%d\n",
+				host, sd_nodes[i].nid.port);
+			return -1;
+		}
+
+		if (rsp->result == SD_RES_SUCCESS) {
 			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




More information about the sheepdog mailing list