summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorshishir gowda <shishirng@gluster.com>2010-08-27 05:55:02 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-08-27 05:53:55 -0700
commitfd282c4299a5354aa272345e312ac600d9dcc680 (patch)
tree8ff5f52bafcc6f987cf2fe3832f70265ea925669 /xlators
parentcd5578895e7a218518ed20eaa34c6d833ea65aaa (diff)
Volume create checks for used bricks
Added check for create volume from using bricks already in use. Also cleaned up the error handling fixes in glusterd_handle_create_volume Volume create should now fail if a brick is specified that is already in use. Signed-off-by: shishir gowda <shishirng@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
Diffstat (limited to 'xlators')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c87
1 files changed, 47 insertions, 40 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 9eefd89b4..f27853165 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -968,9 +968,17 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
void *cli_rsp = NULL;
char err_str[1048];
gf1_cli_create_vol_rsp rsp = {0,};
-
+ glusterd_conf_t *priv = NULL;
+ int err_ret = 0;
+ glusterd_brickinfo_t *tmpbrkinfo = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ xlator_t *this = NULL;
GF_ASSERT (req);
+ this = THIS;
+ priv = this->private;
+
+ GF_ASSERT(this);
if (!gf_xdr_to_cli_create_vol_req (req->msg[0], &cli_req)) {
//failed to decode msg;
@@ -1003,22 +1011,10 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
}
if ((ret = glusterd_check_volume_exists (volname))) {
- gf_log ("", GF_LOG_ERROR, "Volname %s already exists",
- volname);
- rsp.op_ret = -1;
- rsp.op_errno = 0;
- rsp.volname = "";
snprintf(err_str, 1048, "Volname %s already exists",
volname);
- rsp.op_errstr = err_str;
- cli_rsp = &rsp;
- glusterd_submit_reply(req, cli_rsp, NULL, 0, NULL,
- gf_xdr_serialize_cli_create_vol_rsp);
- if (!glusterd_opinfo_unlock())
- gf_log ("glusterd", GF_LOG_ERROR, "Unlock on opinfo"
- " failed");
-
- ret = 0; //sent error to cli, prevent second reply
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
+ err_ret = 1;
goto out;
}
@@ -1045,48 +1041,59 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
if (ret)
goto out;
if(!(ret = glusterd_is_local_addr(brickinfo->hostname)))
- continue; //localhost, continue without validation
+ goto brick_validation; //localhost, continue without validation
ret = glusterd_friend_find_by_hostname(brickinfo->hostname,
&peerinfo);
if (ret) {
- rsp.op_ret = -1;
- rsp.op_errno = 0;
- rsp.volname = "";
snprintf(err_str, 1048, "Host %s not a friend",
brickinfo->hostname);
- rsp.op_errstr = err_str;
- cli_rsp = &rsp;
- glusterd_submit_reply(req, cli_rsp, NULL, 0, NULL,
- gf_xdr_serialize_cli_create_vol_rsp);
- if (!glusterd_opinfo_unlock())
- gf_log ("glusterd", GF_LOG_ERROR, "Unlock on "
- "opinfo failed");
-
- ret = 0; //sent error to cli, prevent second reply
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
+ err_ret = 1;
goto out;
}
if ((!peerinfo->connected) &&
(peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)) {
- rsp.op_ret = -1;
- rsp.op_errno = 0;
- rsp.volname = "";
snprintf(err_str, 1048, "Host %s not connected",
brickinfo->hostname);
- rsp.op_errstr = err_str;
- cli_rsp = &rsp;
- glusterd_submit_reply(req, cli_rsp, NULL, 0, NULL,
- gf_xdr_serialize_cli_create_vol_rsp);
- if (!glusterd_opinfo_unlock())
- gf_log ("glusterd", GF_LOG_ERROR, "Unlock on "
- "opinfo failed");
-
- ret = 0; //sent error to cli, prevent second reply
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
+ err_ret = 1;
goto out;
}
+brick_validation:
+ list_for_each_entry (volinfo, &priv->volumes, vol_list) {
+
+ list_for_each_entry (tmpbrkinfo, &volinfo->bricks,
+ brick_list) {
+
+ if ((!strcmp(brickinfo->hostname, tmpbrkinfo->
+ hostname) && !strcmp(brickinfo->path,
+ tmpbrkinfo->path))) {
+ snprintf(err_str, 1048, "Brick %s already"
+ "in use", brick);
+ gf_log ("glusterd", GF_LOG_ERROR, "%s",
+ err_str);
+ err_ret = 1;
+ goto out;
+ }
+ }
+ }
}
ret = glusterd_create_volume (req, dict);
out:
+ if (err_ret) {
+ rsp.op_ret = -1;
+ rsp.op_errno = 0;
+ rsp.volname = "";
+ rsp.op_errstr = err_str;
+ cli_rsp = &rsp;
+ glusterd_submit_reply(req, cli_rsp, NULL, 0, NULL,
+ gf_xdr_serialize_cli_create_vol_rsp);
+ if (!glusterd_opinfo_unlock())
+ gf_log ("glusterd", GF_LOG_ERROR, "Unlock on opinfo"
+ " failed");
+ ret = 0; //Client response sent, prevent second response
+ }
return ret;
}