summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd
diff options
context:
space:
mode:
authorshishir gowda <shishirng@gluster.com>2010-08-25 06:16:46 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-08-26 00:09:17 -0700
commit7c7219fd881dd6485fbad2e80121a3c2dffd6d9b (patch)
treea9687f7f7fc57e117d00c7bc93d11969f6d989f0 /xlators/mgmt/glusterd
parent194ec62165c89a84ad7d36013dd77e981a374c93 (diff)
Cli volume create validation
Signed-off-by: shishir gowda <shishirng@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1185 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1185
Diffstat (limited to 'xlators/mgmt/glusterd')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c102
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c6
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.h4
3 files changed, 112 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 463213ec130..fb5a0df0338 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -952,9 +952,22 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
int32_t ret = -1;
gf1_cli_create_vol_req cli_req = {0,};
dict_t *dict = NULL;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ char *brick = NULL;
+ char *bricks = NULL;
+ char *volname = NULL;
+ 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[1048];
+ gf1_cli_create_vol_rsp rsp = {0,};
GF_ASSERT (req);
+
if (!gf_xdr_to_cli_create_vol_req (req->msg[0], &cli_req)) {
//failed to decode msg;
req->rpc_err = GARBAGE_ARGS;
@@ -978,6 +991,95 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
}
}
+ ret = dict_get_str (dict, "volname", &volname);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get volume name");
+ goto out;
+ }
+
+ 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
+ goto out;
+ }
+
+ ret = dict_get_int32 (dict, "count", &brick_count);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get count");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "bricks", &bricks);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get bricks");
+ goto out;
+ }
+
+ if (bricks)
+ brick_list = gf_strdup (bricks);
+
+ while ( i < brick_count) {
+ i++;
+ brick= strtok_r (brick_list, " \n", &tmpptr);
+ brick_list = tmpptr;
+ ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
+ if (ret)
+ goto out;
+ if(!(ret = glusterd_is_local_addr(brickinfo->hostname)))
+ continue; //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
+ 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
+ goto out;
+ }
+ }
ret = glusterd_create_volume (req, dict);
out:
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 720e7921d7c..5d3323f0dc7 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -2352,6 +2352,7 @@ glusterd_op_send_cli_response (int32_t op, int32_t op_ret,
rsp.op_ret = op_ret;
rsp.op_errno = op_errno;
rsp.volname = "";
+ rsp.op_errstr = "";
cli_rsp = &rsp;
sfunc = gf_xdr_serialize_cli_create_vol_rsp;
break;
@@ -3055,3 +3056,8 @@ glusterd_op_sm_init ()
INIT_LIST_HEAD (&gd_op_sm_queue);
return 0;
}
+
+int32_t
+glusterd_opinfo_unlock(){
+ return (pthread_mutex_unlock(&opinfo.lock));
+}
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
index 535d57b8bbb..afb134637e1 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
@@ -212,4 +212,8 @@ glusterd_op_clear_op (glusterd_op_t op);
int32_t
glusterd_op_clear_ctx (glusterd_op_t op);
+
+int32_t
+glusterd_opinfo_unlock();
+
#endif