summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd
diff options
context:
space:
mode:
authorPranith K <pranithk@gluster.com>2010-10-04 08:54:55 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-10-04 08:28:35 -0700
commit64609b65c2ffc34577b342dab12595b13a52d8a2 (patch)
tree12dca1508bbae245f94c24aa24aead95e6809241 /xlators/mgmt/glusterd
parent85c013f3accfc409c1a520d0ad529a2c1c16c653 (diff)
mgmt/glusterd: added new brick validation functionality
Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1726 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1726
Diffstat (limited to 'xlators/mgmt/glusterd')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c175
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c18
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c218
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h26
4 files changed, 242 insertions, 195 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index c21cd906cd2..6e391670805 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -62,38 +62,6 @@
glusterd_volume_txn (req, volname, flags, GD_OP_STOP_VOLUME)
static int
-glusterd_friend_find_by_uuid (uuid_t uuid,
- glusterd_peerinfo_t **peerinfo)
-{
- int ret = -1;
- glusterd_conf_t *priv = NULL;
- glusterd_peerinfo_t *entry = NULL;
-
- GF_ASSERT (peerinfo);
-
- *peerinfo = NULL;
- priv = THIS->private;
-
- GF_ASSERT (priv);
-
- if (uuid_is_null (uuid))
- return -1;
-
- list_for_each_entry (entry, &priv->peers, uuid_list) {
- if (!uuid_compare (entry->uuid, uuid)) {
-
- gf_log ("glusterd", GF_LOG_NORMAL,
- "Friend found.. state: %d",
- entry->state.state);
- *peerinfo = entry;
- return 0;
- }
- }
-
- return ret;
-}
-
-static int
glusterd_handle_friend_req (rpcsvc_request_t *req, uuid_t uuid,
char *hostname, int port, dict_t *dict)
{
@@ -717,7 +685,6 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
int brick_count = 0;
char *tmpptr = NULL;
int i = 0;
- glusterd_peerinfo_t *peerinfo = NULL;
char *brick_list = NULL;
void *cli_rsp = NULL;
char err_str[2048] = {0,};
@@ -730,9 +697,7 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
uuid_t volume_id = {0,};
char volid[64] = {0,};
glusterd_brickinfo_t *tmpbrkinfo = NULL;
- glusterd_brickinfo_t *tmp = NULL;
- glusterd_brickinfo_t *tmp2 = NULL;
- uint32_t delete_list = 0;
+ glusterd_volinfo_t tmpvolinfo = {{0},};
GF_ASSERT (req);
@@ -819,63 +784,35 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
((cli_req.type == 1)? "STRIPE":"REPLICATE")), cli_req.count,
bricks);
+ INIT_LIST_HEAD (&tmpvolinfo.bricks);
while ( i < brick_count) {
i++;
brick= strtok_r (brick_list, " \n", &tmpptr);
brick_list = tmpptr;
- brickinfo = NULL;
ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
if (ret)
goto out;
- if(!(ret = glusterd_is_local_addr (brickinfo->hostname)))
- goto brick_validation; //localhost, continue without validation
-
- ret = glusterd_friend_find_by_hostname (brickinfo->hostname,
- &peerinfo);
+ ret = glusterd_new_brick_validate (brick, brickinfo, err_str,
+ sizeof (err_str));
if (ret) {
- snprintf (err_str, 2048, "Host %s not a friend",
- brickinfo->hostname);
- gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
err_ret = 1;
goto out;
}
- if ((!peerinfo->connected) ||
- (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)) {
- snprintf(err_str, 2048, "Host %s not connected",
- brickinfo->hostname);
- gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
+ ret = glusterd_volume_brickinfo_get (brickinfo->uuid,
+ brickinfo->hostname,
+ brickinfo->path,
+ &tmpvolinfo, &tmpbrkinfo);
+ if (!ret) {
err_ret = 1;
+ snprintf (err_str, sizeof (err_str), "Brick: %s:%s, %s"
+ " in the arguments mean the same",
+ tmpbrkinfo->hostname, tmpbrkinfo->path,
+ brick);
goto out;
}
-brick_validation:
- err_ret = glusterd_is_exisiting_brick (brickinfo->hostname,
- brickinfo->path);
- if (err_ret) {
- snprintf(err_str, 2048, "Brick: %s already in use",
- brick);
- goto out;
- }
-
- if (1 < i)
- list_add_tail (&brickinfo->brick_list, &tmpbrkinfo->brick_list);
- else
- tmpbrkinfo = brickinfo;
- }
-
- list_for_each_entry (tmp, &tmpbrkinfo->brick_list, brick_list) {
- list_for_each_entry (tmp2, &tmp->brick_list, brick_list) {
- if ((!glusterd_is_local_addr (tmp->hostname)) && (!glusterd_is_local_addr (tmp2->hostname))
- && (!strcmp (tmp->path, tmp2->path))) {
- snprintf (err_str, 2048, "%s:%s and %s:%s are one and the same",
- tmp->hostname, tmp->path, tmp2->hostname, tmp2->path);
- gf_log ("glusterd", GF_LOG_ERROR,
- "%s",err_str);
- err_ret = 1;
- delete_list = 1;
- goto out;
- }
- }
+ list_add_tail (&brickinfo->brick_list, &tmpvolinfo.bricks);
+ brickinfo = NULL;
}
ret = glusterd_create_volume (req, dict);
@@ -883,7 +820,6 @@ brick_validation:
gf_cmd_log ("Volume create", "on volname: %s %s", volname,
((ret || err_ret) != 0) ? "FAILED": "SUCCESS");
- delete_list = 1;
out:
if ((err_ret || ret) && dict)
dict_unref (dict);
@@ -904,12 +840,9 @@ out:
if (free_ptr)
GF_FREE(free_ptr);
- if (delete_list) {
- list_for_each_entry_safe (tmp, tmp2, &tmpbrkinfo->brick_list, brick_list) {
- glusterd_brickinfo_delete (tmp);
- }
- }
-
+ ret = glusterd_volume_bricks_delete (&tmpvolinfo);
+ if (brickinfo)
+ glusterd_brickinfo_delete (brickinfo);
if (cli_req.volname)
free (cli_req.volname); // its a malloced by xdr
return ret;
@@ -1015,7 +948,6 @@ glusterd_handle_add_brick (rpcsvc_request_t *req)
int brick_count = 0;
char *tmpptr = NULL;
int i = 0;
- glusterd_peerinfo_t *peerinfo = NULL;
char *brick_list = NULL;
void *cli_rsp = NULL;
char err_str[2048] = {0,};
@@ -1026,9 +958,7 @@ glusterd_handle_add_brick (rpcsvc_request_t *req)
xlator_t *this = NULL;
char *free_ptr = NULL;
glusterd_brickinfo_t *tmpbrkinfo = NULL;
- glusterd_brickinfo_t *tmp = NULL;
- glusterd_brickinfo_t *tmp2 = NULL;
- uint32_t delete_list = 0;
+ glusterd_volinfo_t tmpvolinfo = {{0},};
this = THIS;
GF_ASSERT(this);
@@ -1135,6 +1065,7 @@ brick_val:
,volname, ((volinfo->type == 0)? "DEFAULT" : ((volinfo->type
== 1)? "STRIPE": "REPLICATE")), brick_count, brick_list);
+ INIT_LIST_HEAD (&tmpvolinfo.bricks);
while ( i < brick_count) {
i++;
brick= strtok_r (brick_list, " \n", &tmpptr);
@@ -1143,61 +1074,32 @@ brick_val:
ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
if (ret)
goto out;
- if(!(ret = glusterd_is_local_addr(brickinfo->hostname)))
- goto brick_validation; //localhost, continue without validation
- ret = glusterd_friend_find_by_hostname(brickinfo->hostname,
- &peerinfo);
+ ret = glusterd_new_brick_validate (brick, brickinfo, err_str,
+ sizeof (err_str));
if (ret) {
- snprintf(err_str, 2048, "Host %s not a friend",
- brickinfo->hostname);
- gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
err_ret = 1;
goto out;
}
- if ((!peerinfo->connected) ||
- (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)) {
- snprintf(err_str, 2048, "Host %s not connected",
- brickinfo->hostname);
- gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
+ ret = glusterd_volume_brickinfo_get (brickinfo->uuid,
+ brickinfo->hostname,
+ brickinfo->path,
+ &tmpvolinfo, &tmpbrkinfo);
+ if (!ret) {
err_ret = 1;
+ snprintf (err_str, sizeof (err_str), "Brick: %s:%s, %s"
+ " in the arguments mean the same",
+ tmpbrkinfo->hostname, tmpbrkinfo->path,
+ brick);
goto out;
}
-brick_validation:
- err_ret = glusterd_is_exisiting_brick (brickinfo->hostname,
- brickinfo->path);
- if (err_ret) {
- snprintf(err_str, 2048, "Brick: %s already in use",
- brick);
- goto out;
- }
-
- if (1 < i)
- list_add_tail (&brickinfo->brick_list, &tmpbrkinfo->brick_list);
- else
- tmpbrkinfo = brickinfo;
-
- }
-
- list_for_each_entry (tmp, &tmpbrkinfo->brick_list, brick_list) {
- list_for_each_entry (tmp2, &tmp->brick_list, brick_list) {
- if ((!glusterd_is_local_addr (tmp->hostname)) && (!glusterd_is_local_addr (tmp2->hostname))
- && (!strcmp (tmp->path, tmp2->path))) {
- snprintf (err_str, 2048, "%s:%s and %s:%s are one and the same",
- tmp->hostname, tmp->path, tmp2->hostname, tmp2->path);
- gf_log ("glusterd", GF_LOG_ERROR,
- "%s",err_str);
- err_ret = 1;
- delete_list = 1;
- goto out;
- }
- }
+ list_add_tail (&brickinfo->brick_list, &tmpvolinfo.bricks);
+ brickinfo = NULL;
}
ret = glusterd_add_brick (req, dict);
gf_cmd_log ("Volume add-brick","on volname: %s %s", volname,
((ret || err_ret) != 0)? "FAILED" : "SUCCESS");
- delete_list = 1;
out:
if ((err_ret || ret) && dict)
@@ -1217,14 +1119,11 @@ out:
ret = 0; //sent error to cli, prevent second reply
}
- if (delete_list) {
- list_for_each_entry_safe (tmp, tmp2, &tmpbrkinfo->brick_list, brick_list) {
- glusterd_brickinfo_delete (tmp);
- }
- }
-
if (free_ptr)
GF_FREE (free_ptr);
+ ret = glusterd_volume_bricks_delete (&tmpvolinfo);
+ if (brickinfo)
+ glusterd_brickinfo_delete (brickinfo);
if (cli_req.volname)
free (cli_req.volname); //its malloced by xdr
return ret;
@@ -1540,7 +1439,7 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req)
gf_log ("", GF_LOG_DEBUG, "Remove brick count %d brick: %s",
i, brick);
- ret = glusterd_brickinfo_get(brick, volinfo, &brickinfo);
+ ret = glusterd_volume_brickinfo_get_by_brick(brick, volinfo, &brickinfo);
if (ret) {
snprintf(err_str, 2048," Incorrect brick %s for volname"
" %s", brick, cli_req.volname);
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 52ebd1b2cda..3109e173b34 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -712,7 +712,7 @@ glusterd_op_stage_add_brick (gd1_mgmt_stage_op_req *req, char **op_errstr)
brick = strtok_r (brick_list+1, " \n", &saveptr);
while ( i < count) {
- ret = glusterd_brickinfo_get (brick, volinfo, &brickinfo);
+ ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo, &brickinfo);
if (!ret) {
gf_log ("", GF_LOG_ERROR, "Adding duplicate brick: %s",
brick);
@@ -863,7 +863,7 @@ glusterd_op_stage_replace_brick (gd1_mgmt_stage_op_req *req, char **op_errstr)
goto out;
}
- ret = glusterd_brickinfo_get (src_brick, volinfo,
+ ret = glusterd_volume_brickinfo_get_by_brick (src_brick, volinfo,
&src_brickinfo);
if (ret) {
snprintf (msg, sizeof (msg), "brick: %s does not exist in "
@@ -893,7 +893,7 @@ glusterd_op_stage_replace_brick (gd1_mgmt_stage_op_req *req, char **op_errstr)
ret = -1;
goto out;
}
- if (glusterd_is_exisiting_brick (host, path)) {
+ if (!glusterd_brickinfo_get (NULL, host, path, NULL)) {
snprintf(msg, sizeof(msg), "Brick: %s:%s already in use",
host, path);
*op_errstr = gf_strdup (msg);
@@ -1186,7 +1186,7 @@ glusterd_op_perform_remove_brick (glusterd_volinfo_t *volinfo, char *brick)
if (!dup_brick)
goto out;
- ret = glusterd_brickinfo_get (dup_brick, volinfo, &brickinfo);
+ ret = glusterd_volume_brickinfo_get_by_brick (dup_brick, volinfo, &brickinfo);
if (ret)
goto out;
@@ -1234,7 +1234,7 @@ glusterd_op_perform_replace_brick (glusterd_volinfo_t *volinfo,
if (ret)
goto out;
- ret = glusterd_brickinfo_get (old_brick, volinfo,
+ ret = glusterd_volume_brickinfo_get_by_brick (old_brick, volinfo,
&old_brickinfo);
if (ret)
goto out;
@@ -1320,7 +1320,7 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count,
while (i <= count) {
- ret = glusterd_brickinfo_get (brick, volinfo, &brickinfo);
+ ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo, &brickinfo);
if (ret)
goto out;
@@ -2613,7 +2613,7 @@ glusterd_op_replace_brick (gd1_mgmt_stage_op_req *req, dict_t *rsp_dict)
goto out;
}
- ret = glusterd_brickinfo_get (src_brick, volinfo, &src_brickinfo);
+ ret = glusterd_volume_brickinfo_get_by_brick (src_brick, volinfo, &src_brickinfo);
if (ret) {
gf_log ("", GF_LOG_DEBUG, "Unable to get src-brickinfo");
goto out;
@@ -3970,7 +3970,7 @@ glusterd_do_replace_brick (void *data)
goto out;
}
- ret = glusterd_brickinfo_get (src_brick, volinfo, &src_brickinfo);
+ ret = glusterd_volume_brickinfo_get_by_brick (src_brick, volinfo, &src_brickinfo);
if (ret) {
gf_log ("", GF_LOG_DEBUG, "Unable to get src-brickinfo");
goto out;
@@ -4527,7 +4527,7 @@ glusterd_op_stage_validate (gd1_mgmt_stage_op_req *req, char **op_errstr)
case GD_OP_SET_VOLUME:
ret = glusterd_op_stage_set_volume (req);
break;
-
+
case GD_OP_RESET_VOLUME:
ret = glusterd_op_stage_reset_volume (req);
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 6f1cd07265e..3649ef8639d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -531,16 +531,14 @@ glusterd_brickinfo_delete (glusterd_brickinfo_t *brickinfo)
}
int32_t
-glusterd_volinfo_delete (glusterd_volinfo_t *volinfo)
+glusterd_volume_bricks_delete (glusterd_volinfo_t *volinfo)
{
- int32_t ret = -1;
glusterd_brickinfo_t *brickinfo = NULL;
glusterd_brickinfo_t *tmp = NULL;
+ int32_t ret = -1;
GF_ASSERT (volinfo);
- list_del_init (&volinfo->vol_list);
-
list_for_each_entry_safe (brickinfo, tmp, &volinfo->bricks,
brick_list) {
ret = glusterd_brickinfo_delete (brickinfo);
@@ -548,6 +546,23 @@ glusterd_volinfo_delete (glusterd_volinfo_t *volinfo)
goto out;
}
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+int32_t
+glusterd_volinfo_delete (glusterd_volinfo_t *volinfo)
+{
+ int32_t ret = -1;
+
+ GF_ASSERT (volinfo);
+
+ list_del_init (&volinfo->vol_list);
+
+ ret = glusterd_volume_bricks_delete (volinfo);
+ if (ret)
+ goto out;
dict_unref (volinfo->dict);
GF_FREE (volinfo);
@@ -642,19 +657,56 @@ out:
}
int32_t
-glusterd_brickinfo_get (char *brick, glusterd_volinfo_t *volinfo,
- glusterd_brickinfo_t **brickinfo)
+glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path,
+ glusterd_volinfo_t *volinfo,
+ glusterd_brickinfo_t **brickinfo)
+{
+ glusterd_brickinfo_t *brickiter = NULL;
+ uuid_t peer_uuid = {0};
+ int32_t ret = -1;
+
+ if (uuid) {
+ uuid_copy (peer_uuid, uuid);
+ } else {
+ ret = glusterd_hostname_to_uuid (hostname, peer_uuid);
+ if (ret)
+ goto out;
+ }
+ ret = -1;
+ list_for_each_entry (brickiter, &volinfo->bricks, brick_list) {
+
+ if (uuid_is_null (brickiter->uuid)) {
+ ret = glusterd_resolve_brick (brickiter);
+ if (ret)
+ goto out;
+ }
+ if ((!uuid_compare (peer_uuid, brickiter->uuid)) &&
+ !strcmp (brickiter->path, path)) {
+ gf_log ("", GF_LOG_NORMAL, "Found brick");
+ ret = 0;
+ if (brickinfo)
+ *brickinfo = brickiter;
+ break;
+ }
+ }
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+int32_t
+glusterd_volume_brickinfo_get_by_brick (char *brick,
+ glusterd_volinfo_t *volinfo,
+ glusterd_brickinfo_t **brickinfo)
{
int32_t ret = -1;
char *hostname = NULL;
char *path = NULL;
char *dup_brick = NULL;
char *free_ptr = NULL;
- glusterd_brickinfo_t *tmp = NULL;
- uuid_t uuid = {0};
GF_ASSERT (brick);
- GF_ASSERT (brickinfo);
GF_ASSERT (volinfo);
gf_log ("", GF_LOG_NORMAL, "brick: %s", brick);
@@ -680,26 +732,8 @@ glusterd_brickinfo_get (char *brick, glusterd_volinfo_t *volinfo,
goto out;
}
- ret = glusterd_hostname_to_uuid (hostname, uuid);
- if (ret)
- goto out;
- ret = -1;
- list_for_each_entry (tmp, &volinfo->bricks, brick_list) {
-
- if (uuid_is_null (tmp->uuid)) {
- ret = glusterd_resolve_brick (tmp);
- if (ret)
- goto out;
- }
- if ((!uuid_compare (uuid, tmp->uuid)) &&
- !strcmp (tmp->path, path)) {
- gf_log ("", GF_LOG_NORMAL, "Found brick");
- ret = 0;
- *brickinfo = tmp;
- break;
- }
- }
-
+ ret = glusterd_volume_brickinfo_get (NULL, hostname, path, volinfo,
+ brickinfo);
out:
if (free_ptr)
GF_FREE (free_ptr);
@@ -1757,15 +1791,14 @@ glusterd_volume_count_get (void)
}
int
-glusterd_is_exisiting_brick (char *hostname, char *path)
+glusterd_brickinfo_get (uuid_t uuid, char *hostname, char *path,
+ glusterd_brickinfo_t **brickinfo)
{
- glusterd_brickinfo_t *tmpbrkinfo = NULL;
glusterd_volinfo_t *volinfo = NULL;
glusterd_conf_t *priv = NULL;
xlator_t *this = NULL;
- int ret = 0;
+ int ret = -1;
- GF_ASSERT (hostname);
GF_ASSERT (path);
this = THIS;
@@ -1775,16 +1808,11 @@ glusterd_is_exisiting_brick (char *hostname, char *path)
list_for_each_entry (volinfo, &priv->volumes, vol_list) {
- list_for_each_entry (tmpbrkinfo, &volinfo->bricks,
- brick_list) {
- if ((!glusterd_is_local_addr (hostname)) && (!glusterd_is_local_addr (tmpbrkinfo->hostname))
- && !strcmp(path, tmpbrkinfo->path)) {
- gf_log ("glusterd", GF_LOG_ERROR, "Brick %s:%s"
- " already in use", hostname, path);
- ret = 1;
- goto out;
- }
- }
+ ret = glusterd_volume_brickinfo_get (uuid, hostname, path,
+ volinfo,
+ brickinfo);
+ if (!ret)
+ goto out;
}
out:
return ret;
@@ -1955,6 +1983,39 @@ out:
}
int
+glusterd_friend_find_by_uuid (uuid_t uuid,
+ glusterd_peerinfo_t **peerinfo)
+{
+ int ret = -1;
+ glusterd_conf_t *priv = NULL;
+ glusterd_peerinfo_t *entry = NULL;
+
+ GF_ASSERT (peerinfo);
+
+ *peerinfo = NULL;
+ priv = THIS->private;
+
+ GF_ASSERT (priv);
+
+ if (uuid_is_null (uuid))
+ return -1;
+
+ list_for_each_entry (entry, &priv->peers, uuid_list) {
+ if (!uuid_compare (entry->uuid, uuid)) {
+
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Friend found.. state: %d",
+ entry->state.state);
+ *peerinfo = entry;
+ return 0;
+ }
+ }
+
+ return ret;
+}
+
+
+int
glusterd_friend_find_by_hostname (const char *hoststr,
glusterd_peerinfo_t **peerinfo)
{
@@ -2127,3 +2188,74 @@ glusterd_is_defrag_on (glusterd_volinfo_t *volinfo)
return ((volinfo->defrag_status == GF_DEFRAG_STATUS_STARTED) ||
(volinfo->defrag_status == GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE));
}
+
+int
+glusterd_new_brick_validate (char *brick, glusterd_brickinfo_t *brickinfo,
+ char *op_errstr, size_t len)
+{
+ glusterd_brickinfo_t *newbrickinfo = NULL;
+ glusterd_brickinfo_t *tmpbrkinfo = NULL;
+ int ret = -1;
+ gf_boolean_t is_allocated = _gf_false;
+ glusterd_peerinfo_t *peerinfo = NULL;
+ glusterd_conf_t *priv = NULL;
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
+ priv = this->private;
+ GF_ASSERT (priv);
+
+
+ GF_ASSERT (brick);
+ GF_ASSERT (op_errstr);
+
+ if (!brickinfo) {
+ ret = glusterd_brickinfo_from_brick (brick, &newbrickinfo);
+ if (ret)
+ goto out;
+ is_allocated = _gf_true;
+ } else {
+ newbrickinfo = brickinfo;
+ }
+
+ ret = glusterd_resolve_brick (newbrickinfo);
+ if (ret) {
+ snprintf (op_errstr, len, "Host %s not a friend",
+ newbrickinfo->hostname);
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", op_errstr);
+ goto out;
+ }
+
+ if (!uuid_compare (priv->uuid, newbrickinfo->uuid))
+ goto brick_validation;
+ ret = glusterd_friend_find_by_uuid (newbrickinfo->uuid, &peerinfo);
+ if (ret)
+ goto out;
+ if ((!peerinfo->connected) ||
+ (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)) {
+ snprintf(op_errstr, len, "Host %s not connected",
+ newbrickinfo->hostname);
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", op_errstr);
+ ret = -1;
+ goto out;
+ }
+brick_validation:
+ ret = glusterd_brickinfo_get (newbrickinfo->uuid,
+ newbrickinfo->hostname,
+ newbrickinfo->path, &tmpbrkinfo);
+ if (!ret) {
+ snprintf(op_errstr, len, "Brick: %s already in use",
+ brick);
+ gf_log ("", GF_LOG_ERROR, op_errstr);
+ ret = -1;
+ goto out;
+ } else {
+ ret = 0;
+ }
+out:
+ if (is_allocated && newbrickinfo)
+ glusterd_brickinfo_delete (newbrickinfo);
+ gf_log ("", GF_LOG_DEBUG, "returning %d ", ret);
+ return ret;
+}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index e2736bf1631..74b837773fc 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -119,8 +119,9 @@ gf_boolean_t
glusterd_is_cli_op_req (int32_t op);
int32_t
-glusterd_brickinfo_get (char *brick, glusterd_volinfo_t *volinfo,
- glusterd_brickinfo_t **brickinfo);
+glusterd_volume_brickinfo_get_by_brick (char *brick,
+ glusterd_volinfo_t *volinfo,
+ glusterd_brickinfo_t **brickinfo);
int32_t
glusterd_is_local_addr (char *hostname);
@@ -161,9 +162,6 @@ int32_t
glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo,
dict_t *dict, int32_t count);
int
-glusterd_is_exisiting_brick (char *hostname, char *path);
-
-int
glusterd_get_brickinfo (xlator_t *this, const char *brickname,
int port, gf_boolean_t localhost,
glusterd_brickinfo_t **brickinfo);
@@ -196,4 +194,22 @@ glusterd_brick_stop (glusterd_volinfo_t *volinfo,
int
glusterd_is_defrag_on (glusterd_volinfo_t *volinfo);
+
+int32_t
+glusterd_volinfo_bricks_delete (glusterd_volinfo_t *volinfo);
+int
+glusterd_friend_find_by_uuid (uuid_t uuid,
+ glusterd_peerinfo_t **peerinfo);
+int
+glusterd_new_brick_validate (char *brick, glusterd_brickinfo_t *brickinfo,
+ char *op_errstr, size_t len);
+int32_t
+glusterd_volume_bricks_delete (glusterd_volinfo_t *volinfo);
+int32_t
+glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path,
+ glusterd_volinfo_t *volinfo,
+ glusterd_brickinfo_t **brickinfo);
+int
+glusterd_brickinfo_get (uuid_t uuid, char *hostname, char *path,
+ glusterd_brickinfo_t **brickinfo);
#endif