From 915adb9c1291d140e57765b7fad0c5bb0e7d5ed5 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Thu, 8 Jul 2010 08:16:13 +0000 Subject: gluster-CLI-and-mgmt-glusterd-added-to-codebase Signed-off-by: Vijay Bellur Signed-off-by: Amar Tumballi Signed-off-by: Anand V. Avati BUG: 971 (dynamic volume management) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=971 --- cli/src/cli3_1-cops.c | 805 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 805 insertions(+) create mode 100644 cli/src/cli3_1-cops.c (limited to 'cli/src/cli3_1-cops.c') diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c new file mode 100644 index 00000000000..a3d5ddd8950 --- /dev/null +++ b/cli/src/cli3_1-cops.c @@ -0,0 +1,805 @@ +/* + Copyright (c) 2010 Gluster, Inc. + This file is part of GlusterFS. + + GlusterFS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + GlusterFS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ + + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "cli.h" +#include "gluster1.h" +#include "cli-xdr.h" +#include "compat-errno.h" +#include "protocol-common.h" +#include "cli-cmd.h" +#include + +extern rpc_clnt_prog_t *cli_rpc_prog; + +int +gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_probe_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_probe_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + //rsp.op_ret = -1; + //rsp.op_errno = EINVAL; + goto out; + } + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe"); + cli_out ("Probe %s", (rsp.op_ret) ? "Unsuccessful": "Successful"); + + cli_cmd_broadcast_response (); + + ret = 0; + +out: + return ret; +} + +int +gf_cli3_1_create_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_create_vol_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_create_vol_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to create volume"); + cli_out ("Create Volume %s", (rsp.op_ret) ? "Unsuccessful": + "Successful"); + + ret = 0; + +out: + return ret; +} + +int +gf_cli3_1_delete_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_delete_vol_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_delete_vol_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to delete volume"); + cli_out ("Delete Volume %s", (rsp.op_ret) ? "Unsuccessful": + "Successful"); + + ret = 0; + +out: + return ret; +} + +int +gf_cli3_1_start_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_start_vol_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_start_vol_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to start volume"); + cli_out ("Start Volume %s", (rsp.op_ret) ? "Unsuccessful": + "Successful"); + + ret = 0; + +out: + return ret; +} + +int +gf_cli3_1_stop_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_stop_vol_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_stop_vol_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to stop volume"); + cli_out ("Delete Volume %s", (rsp.op_ret) ? "Unsuccessful": + "Successful"); + + ret = 0; + +out: + return ret; +} + +int +gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_defrag_vol_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_defrag_vol_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe"); + cli_out ("Defrag Volume %s", (rsp.op_ret) ? "Unsuccessful": + "Successful"); + + ret = 0; + +out: + return ret; +} + +int +gf_cli3_1_rename_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_rename_vol_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_rename_vol_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe"); + cli_out ("Rename Volume %s", (rsp.op_ret) ? "Unsuccessful": + "Successful"); + + ret = 0; + +out: + return ret; +} + +int +gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_set_vol_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_set_vol_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to set"); + cli_out ("Set Volume %s", (rsp.op_ret) ? "Unsuccessful": + "Successful"); + + ret = 0; + +out: + return ret; +} + +int +gf_cli3_1_add_brick_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_add_brick_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_add_brick_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to add brick"); + cli_out ("Add Brick %s", (rsp.op_ret) ? "Unsuccessful": + "Successful"); + + ret = 0; + +out: + return ret; +} + + +int +gf_cli3_1_remove_brick_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_remove_brick_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_remove_brick_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to remove brick"); + cli_out ("Remove Brick %s", (rsp.op_ret) ? "Unsuccessful": + "Successful"); + + ret = 0; + +out: + return ret; +} + + +int +gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_replace_brick_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_replace_brick_req (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to replace brick"); + cli_out ("Replace Brick %s", (rsp.op_ret) ? "Unsuccessful": + "Successful"); + + ret = 0; + +out: + return ret; +} + +int32_t +gf_cli3_1_probe (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_probe_req req = {0,}; + int ret = 0; + char *hostname = NULL; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + hostname = data; + + req.hostname = hostname; + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_PROBE, NULL, gf_xdr_from_cli_probe_req, + this, gf_cli3_1_probe_cbk); + + if (!ret) { + //ret = cli_cmd_await_response (); + } +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + return ret; +} + +int32_t +gf_cli3_1_create_volume (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_create_vol_req req = {0,}; + int ret = 0; + dict_t *dict = NULL; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + dict = data; + + ret = dict_get_str (dict, "volname", &req.volname); + + if (ret) + goto out; + + ret = dict_get_int32 (dict, "type", (int32_t *)&req.type); + + if (ret) + goto out; + + ret = dict_get_int32 (dict, "count", &req.count); + + if (ret) + goto out; + + ret = dict_allocate_and_serialize (dict, + &req.bricks.bricks_val, + (size_t *)&req.bricks.bricks_len); + if (ret < 0) { + gf_log (this->name, GF_LOG_DEBUG, + "failed to get serialized length of dict"); + goto out; + } + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_CREATE_VOLUME, NULL, + gf_xdr_from_cli_create_vol_req, + this, gf_cli3_1_create_volume_cbk); + + if (!ret) { + //ret = cli_cmd_await_response (); + } + + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + if (req.bricks.bricks_val) { + GF_FREE (req.bricks.bricks_val); + } + + return ret; +} + +int32_t +gf_cli3_1_delete_volume (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_delete_vol_req req = {0,}; + int ret = 0; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + req.volname = data; + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_DELETE_VOLUME, NULL, + gf_xdr_from_cli_delete_vol_req, + this, gf_cli3_1_delete_volume_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + +int32_t +gf_cli3_1_start_volume (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_start_vol_req req = {0,}; + int ret = 0; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + req.volname = data; + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_START_VOLUME, NULL, + gf_xdr_from_cli_start_vol_req, + this, gf_cli3_1_start_volume_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + +int32_t +gf_cli3_1_stop_volume (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_stop_vol_req req = {0,}; + int ret = 0; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + req.volname = data; + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_STOP_VOLUME, NULL, + gf_xdr_from_cli_stop_vol_req, + this, gf_cli3_1_stop_volume_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + +int32_t +gf_cli3_1_defrag_volume (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_defrag_vol_req req = {0,}; + int ret = 0; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + req.volname = data; + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_DEFRAG_VOLUME, NULL, + gf_xdr_from_cli_defrag_vol_req, + this, gf_cli3_1_defrag_volume_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + +int32_t +gf_cli3_1_rename_volume (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_rename_vol_req req = {0,}; + int ret = 0; + dict_t *dict = NULL; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + dict = data; + + ret = dict_get_str (dict, "old-volname", &req.old_volname); + + if (ret) + goto out; + + ret = dict_get_str (dict, "new-volname", &req.new_volname); + + if (ret) + goto out; + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_RENAME_VOLUME, NULL, + gf_xdr_from_cli_rename_vol_req, + this, gf_cli3_1_rename_volume_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + +int32_t +gf_cli3_1_set_volume (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_set_vol_req req = {0,}; + int ret = 0; + dict_t *dict = NULL; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + dict = data; + + ret = dict_get_str (dict, "volname", &req.volname); + + if (ret) + goto out; + + ret = dict_allocate_and_serialize (dict, + &req.dict.dict_val, + (size_t *)&req.dict.dict_len); + if (ret < 0) { + gf_log (this->name, GF_LOG_DEBUG, + "failed to get serialized length of dict"); + goto out; + } + + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_SET_VOLUME, NULL, + gf_xdr_from_cli_set_vol_req, + this, gf_cli3_1_set_volume_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + +int32_t +gf_cli3_1_add_brick (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_add_brick_req req = {0,}; + int ret = 0; + dict_t *dict = NULL; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + dict = data; + + ret = dict_get_str (dict, "volname", &req.volname); + + if (ret) + goto out; + + ret = dict_get_int32 (dict, "type", (int32_t *)&req.type); + + if (ret) + goto out; + + ret = dict_get_int32 (dict, "count", &req.count); + + if (ret) + goto out; + + ret = dict_allocate_and_serialize (dict, + &req.bricks.bricks_val, + (size_t *)&req.bricks.bricks_len); + if (ret < 0) { + gf_log (this->name, GF_LOG_DEBUG, + "failed to get serialized length of dict"); + goto out; + } + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_ADD_BRICK, NULL, + gf_xdr_from_cli_add_brick_req, + this, gf_cli3_1_add_brick_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + if (req.bricks.bricks_val) { + GF_FREE (req.bricks.bricks_val); + } + + return ret; +} + +int32_t +gf_cli3_1_remove_brick (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_remove_brick_req req = {0,}; + int ret = 0; + dict_t *dict = NULL; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + dict = data; + + ret = dict_get_str (dict, "volname", &req.volname); + + if (ret) + goto out; + + ret = dict_get_int32 (dict, "type", (int32_t *)&req.type); + + if (ret) + goto out; + + ret = dict_get_int32 (dict, "count", &req.count); + + if (ret) + goto out; + + ret = dict_allocate_and_serialize (dict, + &req.bricks.bricks_val, + (size_t *)&req.bricks.bricks_len); + if (ret < 0) { + gf_log (this->name, GF_LOG_DEBUG, + "failed to get serialized length of dict"); + goto out; + } + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_REMOVE_BRICK, NULL, + gf_xdr_from_cli_remove_brick_req, + this, gf_cli3_1_remove_brick_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + if (req.bricks.bricks_val) { + GF_FREE (req.bricks.bricks_val); + } + + return ret; +} + +int32_t +gf_cli3_1_replace_brick (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_replace_brick_req req = {0,}; + int ret = 0; + dict_t *dict = NULL; + char *src_brick = NULL; + char *dst_brick = NULL; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + dict = data; + + ret = dict_get_str (dict, "volname", &req.volname); + + if (ret) + goto out; + + ret = dict_get_int32 (dict, "operation", (int32_t *)&req.op); + + if (ret) + goto out; + + if (GF_REPLACE_OP_START == req.op) { + ret = dict_get_str (dict, "src-brick", &src_brick); + + if (ret) + goto out; + + req.src_brick.src_brick_len = strlen (src_brick); + req.src_brick.src_brick_val = src_brick; + + ret = dict_get_str (dict, "src-brick", &dst_brick); + + if (ret) + goto out; + + req.dst_brick.dst_brick_len = strlen (dst_brick); + req.dst_brick.dst_brick_val = dst_brick; + } + + ret = cli_submit_request (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_REPLACE_BRICK, NULL, + gf_xdr_from_cli_replace_brick_req, + this, gf_cli3_1_replace_brick_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + if (req.src_brick.src_brick_val) { + GF_FREE (req.src_brick.src_brick_val); + } + + if (req.dst_brick.dst_brick_val) { + GF_FREE (req.dst_brick.dst_brick_val); + } + + return ret; +} + +struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = { + [GF1_CLI_NULL] = {"NULL", NULL }, + [GF1_CLI_PROBE] = { "PROBE_QUERY", gf_cli3_1_probe}, + [GF1_CLI_CREATE_VOLUME] = {"CREATE_VOLUME", gf_cli3_1_create_volume}, + [GF1_CLI_DELETE_VOLUME] = {"DELETE_VOLUME", gf_cli3_1_delete_volume}, + [GF1_CLI_START_VOLUME] = {"START_VOLUME", gf_cli3_1_start_volume}, + [GF1_CLI_STOP_VOLUME] = {"STOP_VOLUME", gf_cli3_1_stop_volume}, + [GF1_CLI_RENAME_VOLUME] = {"RENAME_VOLUME", gf_cli3_1_rename_volume}, + [GF1_CLI_DEFRAG_VOLUME] = {"DEFRAG_VOLUME", gf_cli3_1_defrag_volume}, + [GF1_CLI_SET_VOLUME] = {"SET_VOLUME", gf_cli3_1_set_volume}, + [GF1_CLI_ADD_BRICK] = {"ADD_BRICK", gf_cli3_1_add_brick}, + [GF1_CLI_REMOVE_BRICK] = {"REMOVE_BRICK", gf_cli3_1_remove_brick}, + [GF1_CLI_REPLACE_BRICK] = {"REPLACE_BRICK", gf_cli3_1_replace_brick}, +}; + +struct rpc_clnt_program cli3_1_prog = { + .progname = "CLI 3.1", + .prognum = GLUSTER3_1_CLI_PROGRAM, + .progver = GLUSTER3_1_CLI_VERSION, + .proctable = gluster3_1_cli_actors, + .numproc = GLUSTER3_1_CLI_PROCCNT, +}; -- cgit