[sheepdog] [PATCH] collie: add more error msg for send_light_req()

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Fri Jul 27 13:39:19 CEST 2012


At Fri, 27 Jul 2012 17:58:35 +0800,
Liu Yuan wrote:
> 
> From: Liu Yuan <tailai.ly at taobao.com>
> 
> - also move it out of lib/net.c since only collie use it, thus we can use
>   fprintf(stderr, ...) inside to indicate which phase to fail.
> 
> Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
> ---
>  collie/cluster.c |   18 +++++++++++++-----
>  collie/collie.h  |    1 +
>  collie/common.c  |   32 ++++++++++++++++++++++++++++++++
>  collie/debug.c   |    2 +-
>  include/net.h    |    1 -
>  lib/net.c        |   28 ----------------------------
>  6 files changed, 47 insertions(+), 35 deletions(-)
> 
> diff --git a/collie/cluster.c b/collie/cluster.c
> index 45d39a4..e70e7a4 100644
> --- a/collie/cluster.c
> +++ b/collie/cluster.c
> @@ -211,8 +211,10 @@ static int cluster_shutdown(int argc, char **argv)
>  	hdr.epoch = sd_epoch;
>  
>  	ret = send_light_req(&hdr, sdhost, sdport);
> -	if (ret)
> +	if (ret) {
> +		fprintf(stderr, "failed to execute request\n");
>  		return EXIT_FAILURE;
> +	}
>  
>  	return EXIT_SUCCESS;
>  }
> @@ -226,8 +228,10 @@ static int restore_snap(uint32_t epoch)
>  	hdr.obj.tgt_epoch = epoch;
>  
>  	ret = send_light_req(&hdr, sdhost, sdport);
> -	if (ret)
> +	if (ret) {
> +		fprintf(stderr, "failed to execute request\n");
>  		return EXIT_FAILURE;
> +	}
>  
>  	printf("Cluster restore to the snapshot %d\n", epoch);
>  	return EXIT_SUCCESS;
> @@ -297,8 +301,10 @@ static int do_snapshot(void)
>  	sd_init_req(&hdr, SD_OP_SNAPSHOT);
>  
>  	ret = send_light_req(&hdr, sdhost, sdport);
> -	if (ret)
> +	if (ret) {
> +		fprintf(stderr, "failed to execute request\n");
>  		return EXIT_FAILURE;
> +	}
>  
>  	return EXIT_SUCCESS;
>  }
> @@ -323,8 +329,10 @@ static int cluster_cleanup(int argc, char **argv)
>  	sd_init_req(&hdr, SD_OP_CLEANUP);
>  
>  	ret = send_light_req(&hdr, sdhost, sdport);
> -	if (ret)
> +	if (ret) {
> +		fprintf(stderr, "failed to execute request\n");
>  		return EXIT_FAILURE;
> +	}
>  
>  	return EXIT_SUCCESS;
>  }
> @@ -361,7 +369,7 @@ static int cluster_recover(int argc, char **argv)
>  
>  	ret = send_light_req(&hdr, sdhost, sdport);
>  	if (ret) {
> -		fprintf(stderr, "Recovery failed\n");
> +		fprintf(stderr, "failed to execute request\n");
>  		return EXIT_FAILURE;
>  	}
>  
> diff --git a/collie/collie.h b/collie/collie.h
> index 3657232..75a675c 100644
> --- a/collie/collie.h
> +++ b/collie/collie.h
> @@ -71,6 +71,7 @@ int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
>  		   uint64_t offset);
>  int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data, unsigned int datalen,
>  		    uint64_t offset, uint32_t flags, int copies, int create);
> +int send_light_req(struct sd_req *hdr, const char *host, int port);
>  
>  extern struct command vdi_command;
>  extern struct command node_command;
> diff --git a/collie/common.c b/collie/common.c
> index 2918773..b93bbd4 100644
> --- a/collie/common.c
> +++ b/collie/common.c
> @@ -191,3 +191,35 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
>  
>  	return 0;
>  }
> +
> +/*
> + * Light request only contains header, without body content.
> + */
> +int send_light_req(struct sd_req *hdr, const char *host, int port)
> +{
> +	int fd, ret;
> +	struct sd_rsp *rsp = (struct sd_rsp *)hdr;
> +	unsigned rlen, wlen;
> +
> +	fd = connect_to(host, port);
> +	if (fd < 0)
> +		return -1;
> +
> +	rlen = 0;
> +	wlen = 0;
> +	ret = exec_req(fd, hdr, NULL, &wlen, &rlen);
> +	close(fd);
> +	if (ret) {
> +		fprintf(stderr, "failed to connect to  %s:%d\n",
> +			host, port);
> +		return -1;
> +	}
> +
> +	if (rsp->result != SD_RES_SUCCESS) {
> +		fprintf(stderr, "Response's result: %s\n",
> +			sd_strerror(rsp->result));
> +		return -1;
> +	}
> +
> +	return 0;
> +}
> diff --git a/collie/debug.c b/collie/debug.c
> index d016e85..1339db8 100644
> --- a/collie/debug.c
> +++ b/collie/debug.c
> @@ -101,7 +101,7 @@ static int debug_trace(int argc, char **argv)
>  	hdr.epoch = sd_epoch;
>  	hdr.data_length = enabled;
>  
> -	ret = send_light_req(&hdr, sdhost, sdport);
> +	ret = end_light_req(&hdr, sdhost, sdport);

Seems that this line was changed wrongly. :)

Applied after fixing this, thanks!

Kazutaka


>  	if (ret) {
>  		fprintf(stderr, "Trace failed: %s\n",
>  				sd_strerror(rsp->result));
> diff --git a/include/net.h b/include/net.h
> index 42c3620..4ee0eb6 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -41,7 +41,6 @@ int do_read(int sockfd, void *buf, int len);
>  int rx(struct connection *conn, enum conn_state next_state);
>  int tx(struct connection *conn, enum conn_state next_state, int flags);
>  int connect_to(const char *name, int port);
> -int send_light_req(struct sd_req *hdr, const char *host, int port);
>  int send_req(int sockfd, struct sd_req *hdr, void *data, unsigned int *wlen);
>  int exec_req(int sockfd, struct sd_req *hdr, void *data,
>  	     unsigned int *wlen, unsigned int *rlen);
> diff --git a/lib/net.c b/lib/net.c
> index a832244..6ed046a 100644
> --- a/lib/net.c
> +++ b/lib/net.c
> @@ -371,34 +371,6 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data,
>  	return 0;
>  }
>  
> -/*
> - * Light request only contains header, without body content.
> - */
> -int send_light_req(struct sd_req *hdr, const char *host, int port)
> -{
> -	int fd, ret;
> -	struct sd_rsp *rsp = (struct sd_rsp *)hdr;
> -	unsigned rlen, wlen;
> -
> -	fd = connect_to(host, port);
> -	if (fd < 0)
> -		return -1;
> -
> -	rlen = 0;
> -	wlen = 0;
> -	ret = exec_req(fd, hdr, NULL, &wlen, &rlen);
> -	close(fd);
> -	if (ret)
> -		return -1;
> -
> -	if (rsp->result != SD_RES_SUCCESS) {
> -		eprintf("Response's result: %s\n", sd_strerror(rsp->result));
> -		return -1;
> -	}
> -
> -	return 0;
> -}
> -
>  char *addr_to_str(char *str, int size, uint8_t *addr, uint16_t port)
>  {
>  	int  af = AF_INET6;
> -- 
> 1.7.10.2
> 
> -- 
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog



More information about the sheepdog mailing list