From 992e580df4a38bb96b0114a3b033d0dc0b8425b7 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Tue, 23 Aug 2011 10:25:35 +0530 Subject: mgmt/glusterd: code re-structuring created new files per operations, (or group of operations) Change-Id: Iccb2a6a0cd9661bf940118344b2f7f723e23ab8b BUG: 3158 Reviewed-on: http://review.gluster.com/281 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/mgmt/glusterd/src/glusterd-handler.c | 1325 +------------------------- 1 file changed, 1 insertion(+), 1324 deletions(-) (limited to 'xlators/mgmt/glusterd/src/glusterd-handler.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index d13f32500..08ba9bc46 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -855,679 +855,6 @@ glusterd_op_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx) return ret; } -int -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; - char *brick_list = NULL; - void *cli_rsp = NULL; - char err_str[2048] = {0,}; - gf1_cli_create_vol_rsp rsp = {0,}; - glusterd_conf_t *priv = NULL; - xlator_t *this = NULL; - char *free_ptr = NULL; - char *trans_type = NULL; - uuid_t volume_id = {0,}; - glusterd_brickinfo_t *tmpbrkinfo = NULL; - glusterd_volinfo_t tmpvolinfo = {{0},}; - - GF_ASSERT (req); - - INIT_LIST_HEAD (&tmpvolinfo.bricks); - - this = THIS; - GF_ASSERT(this); - - priv = this->private; - - ret = -1; - if (!gf_xdr_to_cli_create_vol_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - snprintf (err_str, sizeof (err_str), "Garbage args received"); - goto out; - } - - gf_log ("glusterd", GF_LOG_INFO, "Received create volume req"); - - if (cli_req.bricks.bricks_len) { - /* Unserialize the dictionary */ - dict = dict_new (); - - ret = dict_unserialize (cli_req.bricks.bricks_val, - cli_req.bricks.bricks_len, - &dict); - if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, - "failed to " - "unserialize req-buffer to dictionary"); - snprintf (err_str, sizeof (err_str), "Unable to decode " - "the buffer"); - goto out; - } else { - dict->extra_stdfree = cli_req.bricks.bricks_val; - } - } - - ret = dict_get_str (dict, "volname", &volname); - - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get volume name"); - snprintf (err_str, sizeof (err_str), "Unable to get volume " - "name"); - goto out; - } - gf_cmd_log ("Volume create", "on volname: %s attempted", volname); - - if ((ret = glusterd_check_volume_exists (volname))) { - snprintf(err_str, 2048, "Volume %s already exists", volname); - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); - goto out; - } - - ret = dict_get_int32 (dict, "count", &brick_count); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get count"); - snprintf (err_str, sizeof (err_str), "Unable to get volume " - "brick count"); - goto out; - } - - ret = dict_get_str (dict, "transport", &trans_type); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get transport-type"); - snprintf (err_str, sizeof (err_str), "Unable to get volume " - "transport-type"); - goto out; - } - ret = dict_get_str (dict, "bricks", &bricks); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get bricks"); - snprintf (err_str, sizeof (err_str), "Unable to get volume " - "bricks"); - goto out; - } - - uuid_generate (volume_id); - free_ptr = gf_strdup (uuid_utoa (volume_id)); - ret = dict_set_dynstr (dict, "volume-id", free_ptr); - if (ret) { - gf_log ("", GF_LOG_ERROR, "unable to set volume-id"); - snprintf (err_str, sizeof (err_str), "Unable to set volume " - "id"); - goto out; - } - free_ptr = NULL; - - if (bricks) { - brick_list = gf_strdup (bricks); - free_ptr = brick_list; - } - - gf_cmd_log ("Volume create", "on volname: %s type:%s count:%d bricks:%s", - cli_req.volname, ((cli_req.type == 0)? "DEFAULT": - ((cli_req.type == 1)? "STRIPE":"REPLICATE")), cli_req.count, - 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) { - snprintf (err_str, sizeof (err_str), "Unable to get " - "brick info from brick %s", brick); - goto out; - } - - ret = glusterd_new_brick_validate (brick, brickinfo, err_str, - sizeof (err_str)); - if (ret) - goto out; - ret = glusterd_volume_brickinfo_get (brickinfo->uuid, - brickinfo->hostname, - brickinfo->path, - &tmpvolinfo, &tmpbrkinfo); - if (!ret) { - ret = -1; - snprintf (err_str, sizeof (err_str), "Brick: %s:%s, %s" - " one of the arguments contain the other", - tmpbrkinfo->hostname, tmpbrkinfo->path, brick); - goto out; - } - list_add_tail (&brickinfo->brick_list, &tmpvolinfo.bricks); - brickinfo = NULL; - } - - ret = glusterd_op_begin (req, GD_OP_CREATE_VOLUME, dict); - gf_cmd_log ("Volume create", "on volname: %s %s", volname, - (ret != 0) ? "FAILED": "SUCCESS"); - -out: - if (ret) { - if (dict) - dict_unref (dict); - rsp.op_ret = -1; - rsp.op_errno = 0; - rsp.volname = ""; - if (err_str[0] == '\0') - snprintf (err_str, sizeof (err_str), "Operation failed"); - rsp.op_errstr = err_str; - cli_rsp = &rsp; - glusterd_submit_reply(req, cli_rsp, NULL, 0, NULL, - gf_xdr_serialize_cli_create_vol_rsp, - (xdrproc_t)xdr_gf1_cli_create_vol_rsp); - - ret = 0; //Client response sent, prevent second response - } - - if (free_ptr) - GF_FREE(free_ptr); - - glusterd_volume_brickinfos_delete (&tmpvolinfo); - if (brickinfo) - glusterd_brickinfo_delete (brickinfo); - if (cli_req.volname) - free (cli_req.volname); // its a malloced by xdr - - glusterd_friend_sm (); - glusterd_op_sm (); - - return ret; -} - -int -glusterd_handle_cli_start_volume (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf1_cli_start_vol_req cli_req = {0,}; - char *dup_volname = NULL; - dict_t *dict = NULL; - glusterd_op_t cli_op = GD_OP_START_VOLUME; - - GF_ASSERT (req); - - if (!gf_xdr_to_cli_start_vol_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - gf_log ("glusterd", GF_LOG_INFO, "Received start vol req" - "for volume %s", cli_req.volname); - - dict = dict_new (); - - if (!dict) - goto out; - - dup_volname = gf_strdup (cli_req.volname); - if (!dup_volname) - goto out; - - ret = dict_set_dynstr (dict, "volname", dup_volname); - if (ret) - goto out; - - ret = dict_set_int32 (dict, "flags", cli_req.flags); - if (ret) - goto out; - ret = glusterd_op_begin (req, GD_OP_START_VOLUME, dict); - - gf_cmd_log ("volume start","on volname: %s %s", cli_req.volname, - ((ret == 0) ? "SUCCESS": "FAILED")); - -out: - if (ret && dict) - dict_unref (dict); - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr - - glusterd_friend_sm (); - glusterd_op_sm (); - - if (ret) - ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - NULL, "operation failed"); - - return ret; -} - - -int -glusterd_handle_cli_stop_volume (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf1_cli_stop_vol_req cli_req = {0,}; - char *dup_volname = NULL; - dict_t *dict = NULL; - glusterd_op_t cli_op = GD_OP_STOP_VOLUME; - - GF_ASSERT (req); - - if (!gf_xdr_to_cli_stop_vol_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - gf_log ("glusterd", GF_LOG_INFO, "Received stop vol req" - "for volume %s", cli_req.volname); - - dict = dict_new (); - - if (!dict) - goto out; - - dup_volname = gf_strdup (cli_req.volname); - if (!dup_volname) - goto out; - - ret = dict_set_dynstr (dict, "volname", dup_volname); - if (ret) - goto out; - - ret = dict_set_int32 (dict, "flags", cli_req.flags); - if (ret) - goto out; - - ret = glusterd_op_begin (req, GD_OP_STOP_VOLUME, dict); - gf_cmd_log ("Volume stop","on volname: %s %s", cli_req.volname, - ((ret)?"FAILED":"SUCCESS")); - -out: - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr - - glusterd_friend_sm (); - glusterd_op_sm (); - - if (ret) { - if (dict) - dict_unref (dict); - ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - NULL, "operation failed"); - } - - return ret; -} - -int -glusterd_handle_cli_delete_volume (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf1_cli_delete_vol_req cli_req = {0,}; - glusterd_op_delete_volume_ctx_t *ctx = NULL; - glusterd_op_t cli_op = GD_OP_DELETE_VOLUME; - - GF_ASSERT (req); - - if (!gf_xdr_to_cli_delete_vol_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - gf_cmd_log ("Volume delete","on volname: %s attempted", cli_req.volname); - - gf_log ("glusterd", GF_LOG_INFO, "Received delete vol req" - "for volume %s", cli_req.volname); - - - ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_delete_volume_ctx_t); - if (!ctx) - goto out; - - strncpy (ctx->volume_name, cli_req.volname, GD_VOLUME_NAME_MAX); - - ret = glusterd_op_begin (req, GD_OP_DELETE_VOLUME, ctx); - gf_cmd_log ("Volume delete", "on volname: %s %s", cli_req.volname, - ((ret) ? "FAILED" : "SUCCESS")); - -out: - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr - - glusterd_friend_sm (); - glusterd_op_sm (); - - if (ret) { - if (ctx) - GF_FREE (ctx); - - ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - NULL, "operation failed"); - } - - return ret; -} - -int -glusterd_handle_add_brick (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf1_cli_add_brick_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; - char *brick_list = NULL; - void *cli_rsp = NULL; - char err_str[2048] = {0,}; - gf1_cli_add_brick_rsp rsp = {0,}; - glusterd_volinfo_t *volinfo = NULL; - glusterd_conf_t *priv = NULL; - xlator_t *this = NULL; - char *free_ptr = NULL; - glusterd_brickinfo_t *tmpbrkinfo = NULL; - glusterd_volinfo_t tmpvolinfo = {{0},}; - int total_bricks = 0; - - this = THIS; - GF_ASSERT(this); - - priv = this->private; - - GF_ASSERT (req); - - INIT_LIST_HEAD (&tmpvolinfo.bricks); - - if (!gf_xdr_to_cli_add_brick_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - snprintf (err_str, sizeof (err_str), "Garbage args received"); - goto out; - } - - gf_cmd_log ("Volume add-brick", "on volname: %s attempted", - cli_req.volname); - gf_log ("glusterd", GF_LOG_INFO, "Received add brick req"); - - if (cli_req.bricks.bricks_len) { - /* Unserialize the dictionary */ - dict = dict_new (); - - ret = dict_unserialize (cli_req.bricks.bricks_val, - cli_req.bricks.bricks_len, - &dict); - if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, - "failed to " - "unserialize req-buffer to dictionary"); - snprintf (err_str, sizeof (err_str), "Unable to decode " - "the buffer"); - goto out; - } else { - dict->extra_stdfree = cli_req.bricks.bricks_val; - } - } - - ret = dict_get_str (dict, "volname", &volname); - - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get volume name"); - snprintf (err_str, sizeof (err_str), "Unable to get volume " - "name"); - goto out; - } - - if (!(ret = glusterd_check_volume_exists (volname))) { - ret = -1; - snprintf(err_str, 2048, "Volume %s does not exist", volname); - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); - goto out; - } - - ret = dict_get_int32 (dict, "count", &brick_count); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get count"); - snprintf (err_str, sizeof (err_str), "Unable to get volume " - "brick count"); - goto out; - } - - if (!(ret = glusterd_volinfo_find (volname, &volinfo))) { - if (volinfo->type == GF_CLUSTER_TYPE_NONE) - goto brick_val; - if (!brick_count || !volinfo->sub_count) - goto brick_val; - - total_bricks = volinfo->brick_count + brick_count; - /* If the brick count is less than sub_count then, allow add-brick only for - plain replicate volume since in plain stripe brick_count becoming less than - the sub_count is not allowed */ - if (volinfo->brick_count < volinfo->sub_count && - (volinfo->type == GF_CLUSTER_TYPE_REPLICATE)) { - if (total_bricks <= volinfo->sub_count) - goto brick_val; - } - - if ((brick_count % volinfo->sub_count) != 0) { - snprintf(err_str, 2048, "Incorrect number of bricks" - " supplied %d for type %s with count %d", - brick_count, (volinfo->type == 1)? "STRIPE": - "REPLICATE", volinfo->sub_count); - gf_log("glusterd", GF_LOG_ERROR, "%s", err_str); - ret = -1; - goto out; - } - } else { - snprintf (err_str, sizeof (err_str), "Unable to get volinfo " - "for volume name %s", volname); - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); - goto out; - } - -brick_val: - ret = dict_get_str (dict, "bricks", &bricks); - if (ret) { - snprintf (err_str, sizeof (err_str), "Unable to get volume " - "bricks"); - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); - goto out; - } - - if (bricks) - brick_list = gf_strdup (bricks); - if (!brick_list) { - ret = -1; - snprintf (err_str, sizeof (err_str), "Out of memory"); - goto out; - } else { - free_ptr = brick_list; - } - - gf_cmd_log ("Volume add-brick", "volname: %s type %s count:%d bricks:%s" - ,volname, ((volinfo->type == 0)? "DEFAULT" : ((volinfo->type - == 1)? "STRIPE": "REPLICATE")), brick_count, brick_list); - - - 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) { - snprintf (err_str, sizeof (err_str), "Unable to get " - "brick info from brick %s", brick); - goto out; - } - ret = glusterd_new_brick_validate (brick, brickinfo, err_str, - sizeof (err_str)); - if (ret) - goto out; - ret = glusterd_volume_brickinfo_get (brickinfo->uuid, - brickinfo->hostname, - brickinfo->path, - &tmpvolinfo, &tmpbrkinfo); - if (!ret) { - ret = -1; - snprintf (err_str, sizeof (err_str), "Brick: %s:%s, %s" - " one of the arguments contain the other", - tmpbrkinfo->hostname, tmpbrkinfo->path, brick); - goto out; - } - list_add_tail (&brickinfo->brick_list, &tmpvolinfo.bricks); - brickinfo = NULL; - } - - ret = glusterd_op_begin (req, GD_OP_ADD_BRICK, dict); - gf_cmd_log ("Volume add-brick","on volname: %s %s", volname, - (ret != 0)? "FAILED" : "SUCCESS"); - -out: - if (ret) { - if (dict) - dict_unref (dict); - rsp.op_ret = -1; - rsp.op_errno = 0; - rsp.volname = ""; - if (err_str[0] == '\0') - snprintf (err_str, sizeof (err_str), "Operation failed"); - rsp.op_errstr = err_str; - cli_rsp = &rsp; - glusterd_submit_reply(req, cli_rsp, NULL, 0, NULL, - gf_xdr_serialize_cli_add_brick_rsp, - (xdrproc_t)xdr_gf1_cli_add_brick_rsp); - ret = 0; //sent error to cli, prevent second reply - } - - glusterd_friend_sm (); - glusterd_op_sm (); - - if (free_ptr) - GF_FREE (free_ptr); - glusterd_volume_brickinfos_delete (&tmpvolinfo); - if (brickinfo) - glusterd_brickinfo_delete (brickinfo); - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr - - return ret; -} - -int -glusterd_handle_replace_brick (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf1_cli_replace_brick_req cli_req = {0,}; - dict_t *dict = NULL; - char *src_brick = NULL; - char *dst_brick = NULL; - int32_t op = 0; - char operation[256]; - glusterd_op_t cli_op = GD_OP_REPLACE_BRICK; - - GF_ASSERT (req); - - if (!gf_xdr_to_cli_replace_brick_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - gf_log ("glusterd", GF_LOG_INFO, "Received replace brick req"); - - if (cli_req.bricks.bricks_len) { - /* Unserialize the dictionary */ - dict = dict_new (); - - ret = dict_unserialize (cli_req.bricks.bricks_val, - cli_req.bricks.bricks_len, - &dict); - if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, - "failed to " - "unserialize req-buffer to dictionary"); - goto out; - } else { - dict->extra_stdfree = cli_req.bricks.bricks_val; - } - } - - ret = dict_get_int32 (dict, "operation", &op); - if (ret) { - gf_log ("", GF_LOG_DEBUG, - "dict_get on operation failed"); - goto out; - } - - ret = dict_get_str (dict, "src-brick", &src_brick); - - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get src brick"); - goto out; - } - gf_log ("", GF_LOG_DEBUG, - "src brick=%s", src_brick); - - ret = dict_get_str (dict, "dst-brick", &dst_brick); - - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get dest brick"); - goto out; - } - - gf_log ("", GF_LOG_DEBUG, - "dst brick=%s", dst_brick); - - switch (op) { - case GF_REPLACE_OP_START: strcpy (operation, "start"); - break; - case GF_REPLACE_OP_COMMIT: strcpy (operation, "commit"); - break; - case GF_REPLACE_OP_PAUSE: strcpy (operation, "pause"); - break; - case GF_REPLACE_OP_ABORT: strcpy (operation, "abort"); - break; - case GF_REPLACE_OP_STATUS: strcpy (operation, "status"); - break; - case GF_REPLACE_OP_COMMIT_FORCE: strcpy (operation, "commit-force"); - break; - default:strcpy (operation, "unknown"); - break; - } - - gf_log ("glusterd", GF_LOG_INFO, "Received replace brick %s request", operation); - gf_cmd_log ("Volume replace-brick","volname: %s src_brick:%s" - " dst_brick:%s op:%s",cli_req.volname, src_brick, dst_brick - ,operation); - - ret = glusterd_op_begin (req, GD_OP_REPLACE_BRICK, dict); - gf_cmd_log ("Volume replace-brick","on volname: %s %s", cli_req.volname, - (ret) ? "FAILED" : "SUCCESS"); - -out: - if (ret && dict) - dict_unref (dict); - if (cli_req.volname) - free (cli_req.volname);//malloced by xdr - - glusterd_friend_sm (); - glusterd_op_sm (); - - if (ret) - ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - NULL, "operation failed"); - - return ret; -} - - int @@ -1582,206 +909,7 @@ out: return ret; } - -int -glusterd_handle_gsync_set (rpcsvc_request_t *req) -{ - int32_t ret = 0; - dict_t *dict = NULL; - gf1_cli_gsync_set_req cli_req = {{0},}; - glusterd_op_t cli_op = GD_OP_GSYNC_SET; - char *master = NULL; - char *slave = NULL; - char operation[256] = {0,}; - int type = 0; - glusterd_conf_t *priv = NULL; - char *host_uuid = NULL; - - GF_ASSERT (req); - GF_ASSERT (THIS); - GF_ASSERT (THIS->private); - - priv = THIS->private; - - if (!gf_xdr_to_cli_gsync_set_req (req->msg[0], &cli_req)) { - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - if (cli_req.dict.dict_len) { - dict = dict_new (); - if (!dict) - goto out; - - ret = dict_unserialize (cli_req.dict.dict_val, - cli_req.dict.dict_len, - &dict); - if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, "failed to " - "unserialize req-buffer to dictionary"); - goto out; - } else { - dict->extra_stdfree = cli_req.dict.dict_val; - } - - host_uuid = gf_strdup (uuid_utoa(priv->uuid)); - if (host_uuid == NULL) { - gf_log ("glusterd", GF_LOG_ERROR, "failed to get" - "the uuid of the host machine"); - ret = -1; - goto out; - } - ret = dict_set_dynstr (dict, "host-uuid", host_uuid); - if (ret) - goto out; - - } - - ret = dict_get_str (dict, "master", &master); - if (ret < 0) { - gf_log ("", GF_LOG_INFO, "master not found, while handling" - GEOREP" options"); - master = "(No Master)"; - } - - ret = dict_get_str (dict, "slave", &slave); - if (ret < 0) { - gf_log ("", GF_LOG_INFO, "slave not not found, while" - "handling "GEOREP" options"); - slave = "(No Slave)"; - } - - ret = dict_get_int32 (dict, "type", &type); - if (ret < 0) { - gf_log ("", GF_LOG_WARNING, "command type not found, while" - "handling "GEOREP" options"); - goto out; - } - - switch (type) { - - case GF_GSYNC_OPTION_TYPE_START: - strncpy (operation, "start", sizeof (operation)); - break; - - case GF_GSYNC_OPTION_TYPE_STOP: - strncpy (operation, "stop", sizeof (operation)); - break; - - case GF_GSYNC_OPTION_TYPE_CONFIG: - strncpy (operation, "config", sizeof (operation)); - break; - - case GF_GSYNC_OPTION_TYPE_STATUS: - strncpy (operation, "status", sizeof (operation)); - break; - } - - gf_cmd_log ("volume "GEOREP, " %s command on %s,%s", operation, master, - slave); - ret = glusterd_op_begin (req, GD_OP_GSYNC_SET, dict); - gf_cmd_log ("volume "GEOREP, " %s command on %s,%s %s ", operation, - master, slave, (ret != 0)? "FAILED" : "SUCCEEDED"); - -out: - glusterd_friend_sm (); - glusterd_op_sm (); - - if (ret) { - if (dict) - dict_unref (dict); - ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - NULL, "operation failed"); - } - return ret; -} - -int -glusterd_handle_quota (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf1_cli_quota_req cli_req = {0,}; - dict_t *dict = NULL; - glusterd_op_t cli_op = GD_OP_QUOTA; - char operation[256] = {0, }; - char *volname = NULL; - int32_t type = 0; - - GF_ASSERT (req); - - if (!gf_xdr_to_cli_quota_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - if (cli_req.dict.dict_len) { - /* Unserialize the dictionary */ - dict = dict_new (); - - ret = dict_unserialize (cli_req.dict.dict_val, - cli_req.dict.dict_len, - &dict); - if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, "failed to " - "unserialize req-buffer to dictionary"); - goto out; - } else { - dict->extra_stdfree = cli_req.dict.dict_val; - } - } - - ret = dict_get_str (dict, "volname", &volname); - if (ret) { - gf_log ("", GF_LOG_WARNING, "Unable to get volume name, while" - "handling quota command"); - goto out; - } - - ret = dict_get_int32 (dict, "type", &type); - if (ret) { - gf_log ("", GF_LOG_WARNING, "Unable to get type of cmd. , while" - "handling quota command"); - goto out; - } - - switch (type) { - case GF_QUOTA_OPTION_TYPE_ENABLE: - strncpy (operation, "enable", sizeof (operation)); - break; - - case GF_QUOTA_OPTION_TYPE_DISABLE: - strncpy (operation, "disable", sizeof (operation)); - break; - - case GF_QUOTA_OPTION_TYPE_LIMIT_USAGE: - strncpy (operation, "limit-usage", sizeof (operation)); - break; - - case GF_QUOTA_OPTION_TYPE_REMOVE: - strncpy (operation, "remove", sizeof (operation)); - break; - } - gf_cmd_log ("volume quota", " %s command on %s", operation, volname); - ret = glusterd_op_begin (req, GD_OP_QUOTA, dict); - gf_cmd_log ("volume quota", " %s command on %s %s", operation,volname, - (ret != 0)? "FAILED" : "SUCCEEDED"); - -out: - glusterd_friend_sm (); - glusterd_op_sm (); - - if (ret) { - if (dict) - dict_unref (dict); - ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - NULL, "operation failed"); - } - if (cli_req.volname) - free (cli_req.volname); //malloced by xdr - - return ret; -} + int glusterd_handle_set_volume (rpcsvc_request_t *req) @@ -1866,457 +994,6 @@ out: return ret; } -int -glusterd_handle_remove_brick (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf1_cli_remove_brick_req cli_req = {0,}; - dict_t *dict = NULL; - int32_t count = 0; - char *brick = NULL; - char key[256] = {0,}; - char *brick_list = NULL; - int i = 1; - glusterd_volinfo_t *volinfo = NULL; - glusterd_brickinfo_t *brickinfo = NULL; - int32_t pos = 0; - int32_t sub_volume = 0; - int32_t sub_volume_start = 0; - int32_t sub_volume_end = 0; - glusterd_brickinfo_t *tmp = NULL; - char err_str[2048] = {0}; - gf1_cli_remove_brick_rsp rsp = {0,}; - void *cli_rsp = NULL; - char vol_type[256] = {0,}; - - GF_ASSERT (req); - - if (!gf_xdr_to_cli_remove_brick_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - gf_cmd_log ("Volume remove-brick","on volname: %s attempted",cli_req.volname); - gf_log ("glusterd", GF_LOG_INFO, "Received rem brick req"); - - if (cli_req.bricks.bricks_len) { - /* Unserialize the dictionary */ - dict = dict_new (); - - ret = dict_unserialize (cli_req.bricks.bricks_val, - cli_req.bricks.bricks_len, - &dict); - if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, - "failed to " - "unserialize req-buffer to dictionary"); - goto out; - } else { - dict->extra_stdfree = cli_req.bricks.bricks_val; - } - } - - ret = dict_get_int32 (dict, "count", &count); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get count"); - goto out; - } - - ret = glusterd_volinfo_find (cli_req.volname, &volinfo); - if (ret) { - snprintf (err_str, 2048, "Volume %s does not exist", - cli_req.volname); - gf_log ("", GF_LOG_ERROR, "%s", err_str); - goto out; - } - - if (volinfo->type == GF_CLUSTER_TYPE_REPLICATE) - strcpy (vol_type, "replica"); - else if (volinfo->type == GF_CLUSTER_TYPE_STRIPE) - strcpy (vol_type, "stripe"); - else - strcpy (vol_type, "distribute"); - - /* Do not allow remove-brick if the volume is plain stripe */ - if ((volinfo->type == GF_CLUSTER_TYPE_STRIPE) && (volinfo->brick_count == volinfo->sub_count)) { - snprintf (err_str, 2048, "Removing brick from a plain stripe is not allowed"); - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); - ret = -1; - goto out; - } - - /* Do not allow remove-brick if the bricks given is less than the replica count - or stripe count */ - if (((volinfo->type == GF_CLUSTER_TYPE_REPLICATE) || (volinfo->type == GF_CLUSTER_TYPE_STRIPE)) - && !(volinfo->brick_count <= volinfo->sub_count)) { - if (volinfo->sub_count && (count % volinfo->sub_count != 0)) { - snprintf (err_str, 2048, "Remove brick incorrect" - " brick count of %d for %s %d", - count, vol_type, volinfo->sub_count); - gf_log ("", GF_LOG_ERROR, "%s", err_str); - ret = -1; - goto out; - } - } - - brick_list = GF_MALLOC (120000 * sizeof(*brick_list),gf_common_mt_char); - - if (!brick_list) { - ret = -1; - goto out; - } - - strcpy (brick_list, " "); - while ( i <= count) { - snprintf (key, 256, "brick%d", i); - ret = dict_get_str (dict, key, &brick); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get %s", key); - goto out; - } - gf_log ("", GF_LOG_DEBUG, "Remove brick count %d brick: %s", - i, brick); - - ret = glusterd_volume_brickinfo_get_by_brick(brick, volinfo, &brickinfo); - if (ret) { - snprintf(err_str, 2048,"Incorrect brick %s for volume" - " %s", brick, cli_req.volname); - gf_log ("", GF_LOG_ERROR, "%s", err_str); - goto out; - } - strcat(brick_list, brick); - strcat(brick_list, " "); - - i++; - if ((volinfo->type == GF_CLUSTER_TYPE_NONE) || - (volinfo->brick_count <= volinfo->sub_count)) - continue; - - pos = 0; - list_for_each_entry (tmp, &volinfo->bricks, brick_list) { - - if ((!strcmp (tmp->hostname,brickinfo->hostname)) && - !strcmp (tmp->path, brickinfo->path)) { - gf_log ("", GF_LOG_INFO, "Found brick"); - if (!sub_volume && volinfo->sub_count) { - sub_volume = (pos / volinfo-> - sub_count) + 1; - sub_volume_start = volinfo->sub_count * - (sub_volume - 1); - sub_volume_end = (volinfo->sub_count * - sub_volume) -1 ; - } else { - if (pos < sub_volume_start || - pos >sub_volume_end) { - ret = -1; - snprintf(err_str, 2048,"Bricks" - " not from same subvol" - " for %s", vol_type); - gf_log ("",GF_LOG_ERROR, - "%s", err_str); - goto out; - } - } - break; - } - pos++; - } - } - gf_cmd_log ("Volume remove-brick","volname: %s count:%d bricks:%s", - cli_req.volname, count, brick_list); - - ret = glusterd_op_begin (req, GD_OP_REMOVE_BRICK, dict); - gf_cmd_log ("Volume remove-brick","on volname: %s %s",cli_req.volname, - (ret) ? "FAILED" : "SUCCESS"); - -out: - if (ret) { - if (dict) - dict_unref (dict); - rsp.op_ret = -1; - rsp.op_errno = 0; - rsp.volname = ""; - if (err_str[0] == '\0') - snprintf (err_str, sizeof (err_str), "Operation failed"); - gf_log ("", GF_LOG_ERROR, "%s", err_str); - rsp.op_errstr = err_str; - cli_rsp = &rsp; - glusterd_submit_reply(req, cli_rsp, NULL, 0, NULL, - gf_xdr_serialize_cli_remove_brick_rsp, - (xdrproc_t)xdr_gf1_cli_remove_brick_rsp); - - ret = 0; //sent error to cli, prevent second reply - - } - if (brick_list) - GF_FREE (brick_list); - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr - - glusterd_friend_sm (); - glusterd_op_sm (); - - return ret; -} - -int -glusterd_handle_log_filename (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf1_cli_log_filename_req cli_req = {0,}; - dict_t *dict = NULL; - glusterd_op_t cli_op = GD_OP_LOG_FILENAME; - - GF_ASSERT (req); - - if (!gf_xdr_to_cli_log_filename_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - gf_log ("glusterd", GF_LOG_INFO, "Received log filename req " - "for volume %s", cli_req.volname); - - dict = dict_new (); - if (!dict) - goto out; - - ret = dict_set_dynmstr (dict, "volname", cli_req.volname); - if (ret) - goto out; - ret = dict_set_dynmstr (dict, "brick", cli_req.brick); - if (ret) - goto out; - ret = dict_set_dynmstr (dict, "path", cli_req.path); - if (ret) - goto out; - - ret = glusterd_op_begin (req, GD_OP_LOG_FILENAME, dict); - -out: - if (ret && dict) - dict_unref (dict); - - glusterd_friend_sm (); - glusterd_op_sm (); - - if (ret) - ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - NULL, "operation failed"); - - return ret; -} - -int -glusterd_handle_log_locate (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf1_cli_log_locate_req cli_req = {0,}; - gf1_cli_log_locate_rsp rsp = {0,}; - glusterd_conf_t *priv = NULL; - glusterd_volinfo_t *volinfo = NULL; - glusterd_brickinfo_t *brickinfo = NULL; - char tmp_str[PATH_MAX] = {0,}; - char *tmp_brick = NULL; - uint32_t found = 0; - glusterd_brickinfo_t *tmpbrkinfo = NULL; - - GF_ASSERT (req); - - priv = THIS->private; - - if (!gf_xdr_to_cli_log_locate_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - gf_log ("glusterd", GF_LOG_INFO, "Received log locate req " - "for volume %s", cli_req.volname); - - if (strchr (cli_req.brick, ':')) { - /* TODO: need to get info of only that brick and then - tell what is the exact location */ - tmp_brick = gf_strdup (cli_req.brick); - if (!tmp_brick) - goto out; - - gf_log ("", GF_LOG_DEBUG, "brick : %s", cli_req.brick); - ret = glusterd_brickinfo_from_brick (tmp_brick, &tmpbrkinfo); - if (ret) { - gf_log ("glusterd", GF_LOG_ERROR, - "Cannot get brickinfo from the brick"); - goto out; - } - } - - ret = glusterd_volinfo_find (cli_req.volname, &volinfo); - if (ret) { - rsp.path = "request sent on non-existent volume"; - goto out; - } - - list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { - if (tmpbrkinfo) { - ret = glusterd_resolve_brick (tmpbrkinfo); - if (ret) { - gf_log ("glusterd", GF_LOG_ERROR, - "cannot resolve the brick"); - goto out; - } - if (uuid_compare (tmpbrkinfo->uuid, brickinfo->uuid) || strcmp (brickinfo->path, tmpbrkinfo->path)) - continue; - } - - if (brickinfo->logfile) { - strcpy (tmp_str, brickinfo->logfile); - rsp.path = dirname (tmp_str); - found = 1; - } else { - snprintf (tmp_str, PATH_MAX, "%s/bricks/", - DEFAULT_LOG_FILE_DIRECTORY); - rsp.path = tmp_str; - found = 1; - } - break; - } - - if (!found) { - snprintf (tmp_str, PATH_MAX, "brick %s:%s does not exitst in the volume %s", - tmpbrkinfo->hostname, tmpbrkinfo->path, cli_req.volname); - rsp.path = tmp_str; - } - - ret = 0; -out: - if (tmp_brick) - GF_FREE (tmp_brick); - if (tmpbrkinfo) - glusterd_brickinfo_delete (tmpbrkinfo); - rsp.op_ret = ret; - if (!rsp.path) - rsp.path = "Operation failed"; - - ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL, - gf_xdr_serialize_cli_log_locate_rsp, - (xdrproc_t)xdr_gf1_cli_log_locate_rsp); - - if (cli_req.brick) - free (cli_req.brick); //its malloced by xdr - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr - - glusterd_friend_sm (); - glusterd_op_sm (); - - return ret; -} - -int -glusterd_handle_log_level (rpcsvc_request_t *req) -{ - int32_t ret = -1; - dict_t *dict = NULL; - gf1_cli_log_level_req cli_req = {0,}; - glusterd_op_t cli_op = GD_OP_LOG_LEVEL; - - GF_ASSERT(req); - - - if (!gf_xdr_to_cli_log_level_req(req->msg[0], &cli_req)) { - gf_log ("glusterd", GF_LOG_ERROR, "Failed to decode rpc message"); - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - gf_log ("glusterd", GF_LOG_DEBUG, "Got log level request for: Volume [%s]" - " Xlator [%s] LogLevel [\"%s\"]", cli_req.volname, cli_req.xlator, cli_req.loglevel); - - dict = dict_new (); - if (!dict) - goto out; - - ret = dict_set_dynmstr (dict, "volname", cli_req.volname); - if (ret) - goto out; - - ret = dict_set_dynmstr (dict, "xlator", cli_req.xlator); - if (ret) - goto out; - - ret = dict_set_dynmstr (dict, "loglevel", cli_req.loglevel); - if (ret) - goto out; - - ret = glusterd_op_begin (req, cli_op, dict); - - out: - if (ret && dict) - dict_unref (dict); - - glusterd_friend_sm(); - glusterd_op_sm(); - - if (ret) - ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, NULL, - "Operation failed"); - - return ret; -} - -int -glusterd_handle_log_rotate (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf1_cli_log_rotate_req cli_req = {0,}; - dict_t *dict = NULL; - glusterd_op_t cli_op = GD_OP_LOG_ROTATE; - - GF_ASSERT (req); - - if (!gf_xdr_to_cli_log_rotate_req (req->msg[0], &cli_req)) { - //failed to decode msg; - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - gf_log ("glusterd", GF_LOG_INFO, "Received log rotate req " - "for volume %s", cli_req.volname); - - dict = dict_new (); - if (!dict) - goto out; - - ret = dict_set_dynmstr (dict, "volname", cli_req.volname); - if (ret) - goto out; - - ret = dict_set_dynmstr (dict, "brick", cli_req.brick); - if (ret) - goto out; - - ret = dict_set_uint64 (dict, "rotate-key", (uint64_t)time (NULL)); - if (ret) - goto out; - - ret = glusterd_op_begin (req, GD_OP_LOG_ROTATE, dict); - -out: - if (ret && dict) - dict_unref (dict); - - glusterd_friend_sm (); - glusterd_op_sm (); - - if (ret) - ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - NULL, "operation failed"); - - return ret; -} - int glusterd_handle_sync_volume (rpcsvc_request_t *req) { -- cgit