From cd88d3db0f48c4354711a606937a2f0b9ba7f87a Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Tue, 29 May 2012 17:21:34 +0530 Subject: glusterd: cut out a standalone socket path calculation routine Change-Id: If5f196c9154ea59e37b83d3e4cad445fee6e9d45 BUG: 826512 Signed-off-by: Csaba Henk Reviewed-on: http://review.gluster.com/3490 Tested-by: Gluster Build System Reviewed-by: Pranith Kumar Karampuri --- xlators/mgmt/glusterd/src/glusterd-utils.c | 20 +++++++++++++------- xlators/mgmt/glusterd/src/glusterd-utils.h | 3 +++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index f2d96e363..b3b39a1f5 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -1049,6 +1049,15 @@ out: return ret; } +void +glusterd_set_socket_filepath (char *sock_filepath, char *sockpath, size_t len) +{ + char md5_sum[MD5_DIGEST_LENGTH*2+1] = {0,}; + + md5_wrapper ((unsigned char *) sock_filepath, strlen(sock_filepath), md5_sum); + snprintf (sockpath, len, "%s/%s.socket", glusterd_sock_dir, md5_sum); +} + void glusterd_set_brick_socket_filepath (glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *brickinfo, @@ -1056,7 +1065,6 @@ glusterd_set_brick_socket_filepath (glusterd_volinfo_t *volinfo, { char export_path[PATH_MAX] = {0,}; char sock_filepath[PATH_MAX] = {0,}; - char md5_sum[MD5_DIGEST_LENGTH*2+1] = {0,}; char volume_dir[PATH_MAX] = {0,}; xlator_t *this = NULL; glusterd_conf_t *priv = NULL; @@ -1074,8 +1082,8 @@ glusterd_set_brick_socket_filepath (glusterd_volinfo_t *volinfo, GLUSTERD_REMOVE_SLASH_FROM_PATH (brickinfo->path, export_path); snprintf (sock_filepath, PATH_MAX, "%s/run/%s-%s", volume_dir, brickinfo->hostname, export_path); - md5_wrapper ((unsigned char *) sock_filepath, strlen(sock_filepath), md5_sum); - snprintf (sockpath, len, "%s/%s.socket", glusterd_sock_dir, md5_sum); + + glusterd_set_socket_filepath (sock_filepath, sockpath, len); } /* connection happens only if it is not aleady connected, @@ -2699,13 +2707,11 @@ glusterd_nodesvc_set_socket_filepath (char *rundir, uuid_t uuid, char *socketpath, int len) { char sockfilepath[PATH_MAX] = {0,}; - char md5_str[MD5_DIGEST_LENGTH*2+1] = {0,}; snprintf (sockfilepath, sizeof (sockfilepath), "%s/run-%s", rundir, uuid_utoa (uuid)); - md5_wrapper ((unsigned char *) sockfilepath, strlen (sockfilepath), md5_str); - snprintf (socketpath, len, "%s/%s.socket", glusterd_sock_dir, - md5_str); + + glusterd_set_socket_filepath (sockfilepath, socketpath, len); return 0; } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index 0297d9a22..0990ae524 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -195,6 +195,9 @@ glusterd_shd_start (); int32_t glusterd_shd_stop (); +void +glusterd_set_socket_filepath (char *sock_filepath, char *sockpath, size_t len); + int32_t glusterd_nodesvc_set_socket_filepath (char *rundir, uuid_t uuid, char *socketpath, int len); -- cgit