diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-handler.c')
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 102 | 
1 files changed, 102 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:  | 
