summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd
diff options
context:
space:
mode:
authorVijay Bellur <vijay@gluster.com>2010-07-12 08:19:44 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-07-12 06:59:29 -0700
commit6ef7f0e25fb7c76231b4d4ae05cbc45330de300d (patch)
tree6e5b8537dfbee8b7d8e51cdbb62af1d9d0f31a35 /xlators/mgmt/glusterd
parent9bee476eabb5034a27e994008a12ef684755d76c (diff)
Changes in CLI and glusterd
Signed-off-by: Vijay Bellur <vijay@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 971 (dynamic volume management) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=971
Diffstat (limited to 'xlators/mgmt/glusterd')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-ha.c8
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c462
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c138
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.c190
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.h30
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c30
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h7
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c136
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h63
-rw-r--r--xlators/mgmt/glusterd/src/glusterd3_1-mops.c265
10 files changed, 934 insertions, 395 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-ha.c b/xlators/mgmt/glusterd/src/glusterd-ha.c
index 1c049e5f7..26de16b3a 100644
--- a/xlators/mgmt/glusterd/src/glusterd-ha.c
+++ b/xlators/mgmt/glusterd/src/glusterd-ha.c
@@ -59,7 +59,7 @@ glusterd_ha_create_volume (glusterd_volinfo_t *volinfo)
int fd = -1;
GF_ASSERT (volinfo);
- snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,
+ snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,
volinfo->volname);
ret = mkdir (pathname, 0x777);
@@ -72,7 +72,7 @@ glusterd_ha_create_volume (glusterd_volinfo_t *volinfo)
snprintf (filepath, 1024, "%s/info", pathname);
- fd = open (filepath, O_RDWR | O_CREAT | O_APPEND, 0644);
+ fd = open (filepath, O_RDWR | O_CREAT | O_APPEND, 0644);
if (-1 == fd) {
gf_log ("", GF_LOG_ERROR, "open() failed on path %s,"
@@ -99,7 +99,7 @@ out:
return ret;
}
-
+
int32_t
glusterd_ha_delete_volume (glusterd_volinfo_t *volinfo)
{
@@ -108,7 +108,7 @@ glusterd_ha_delete_volume (glusterd_volinfo_t *volinfo)
char filepath[PATH_MAX] = {0,};
GF_ASSERT (volinfo);
- snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,
+ snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,
volinfo->volname);
snprintf (filepath, 1024, "%s/info", pathname);
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 00067a566..f769693ad 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -44,6 +44,7 @@
#include "gd-xdr.h"
#include "cli-xdr.h"
#include "rpc-clnt.h"
+#include "gluster1.h"
#include <sys/resource.h>
#include <inttypes.h>
@@ -61,7 +62,7 @@
static int
-glusterd_friend_find_by_hostname (const char *hoststr,
+glusterd_friend_find_by_hostname (const char *hoststr,
glusterd_peerinfo_t **peerinfo)
{
int ret = -1;
@@ -79,7 +80,7 @@ glusterd_friend_find_by_hostname (const char *hoststr,
list_for_each_entry (entry, &priv->peers, uuid_list) {
if (entry->hostname && (!strncmp (entry->hostname, hoststr,
sizeof (entry->hostname)))) {
-
+
gf_log ("glusterd", GF_LOG_NORMAL,
"Friend %s found.. state: %d", hoststr,
entry->state.state);
@@ -92,7 +93,7 @@ glusterd_friend_find_by_hostname (const char *hoststr,
}
static int
-glusterd_friend_find_by_uuid (uuid_t uuid,
+glusterd_friend_find_by_uuid (uuid_t uuid,
glusterd_peerinfo_t **peerinfo)
{
int ret = -1;
@@ -108,7 +109,7 @@ glusterd_friend_find_by_uuid (uuid_t uuid,
list_for_each_entry (entry, &priv->peers, uuid_list) {
if (!uuid_compare (entry->uuid, uuid)) {
-
+
gf_log ("glusterd", GF_LOG_NORMAL,
"Friend found.. state: %d",
entry->state.state);
@@ -132,12 +133,12 @@ glusterd_handle_friend_req (rpcsvc_request_t *req, uuid_t uuid, char *hostname)
ret = glusterd_friend_find (uuid, hostname, &peerinfo);
if (ret) {
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Unable to find peer");
}
- ret = glusterd_friend_sm_new_event
+ ret = glusterd_friend_sm_new_event
(GD_FRIEND_EVENT_RCVD_FRIEND_REQ, &event);
if (ret) {
@@ -169,7 +170,7 @@ glusterd_handle_friend_req (rpcsvc_request_t *req, uuid_t uuid, char *hostname)
"ret = %d", event->event, ret);
goto out;
}
-
+
ret = 0;
out:
@@ -184,11 +185,101 @@ out:
}
+static int
+glusterd_handle_unfriend_req (rpcsvc_request_t *req, uuid_t uuid, char *hostname)
+{
+ int ret = -1;
+ glusterd_peerinfo_t *peerinfo = NULL;
+ glusterd_friend_sm_event_t *event = NULL;
+ glusterd_friend_req_ctx_t *ctx = NULL;
+
+ ret = glusterd_friend_find (uuid, hostname, &peerinfo);
+
+ if (ret) {
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Unable to find peer");
+ }
+
+ ret = glusterd_friend_sm_new_event
+ (GD_FRIEND_EVENT_REMOVE_FRIEND, &event);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "event generation failed: %d", ret);
+ return ret;
+ }
+
+ event->peerinfo = peerinfo;
+
+ ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_friend_req_ctx_t);
+
+ if (!ctx) {
+ gf_log ("", GF_LOG_ERROR, "Unable to allocate memory");
+ ret = -1;
+ goto out;
+ }
+
+ uuid_copy (ctx->uuid, uuid);
+ if (hostname)
+ ctx->hostname = gf_strdup (hostname);
+ ctx->req = req;
+
+ event->ctx = ctx;
+
+ ret = glusterd_friend_sm_inject_event (event);
+
+ if (ret) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject event %d, "
+ "ret = %d", event->event, ret);
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ if (0 != ret) {
+ if (ctx && ctx->hostname)
+ GF_FREE (ctx->hostname);
+ if (ctx)
+ GF_FREE (ctx);
+ }
+
+ return ret;
+}
+
+static int
+glusterd_add_peer_detail_to_dict (glusterd_peerinfo_t *peerinfo,
+ dict_t *friends, int count)
+{
+
+ int ret = -1;
+ char key[256] = {0, };
+
+ GF_ASSERT (peerinfo);
+ GF_ASSERT (friends);
+
+ snprintf (key, 256, "friend%d.uuid", count);
+ uuid_unparse (peerinfo->uuid, peerinfo->uuid_str);
+ ret = dict_set_str (friends, key, peerinfo->uuid_str);
+ if (ret)
+ goto out;
+
+ snprintf (key, 256, "friend%d.hostname", count);
+ ret = dict_set_str (friends, key, peerinfo->hostname);
+ if (ret)
+ goto out;
+
+ snprintf (key, 256, "friend%d.state", count);
+ ret = dict_set_int32 (friends, key, (int32_t)peerinfo->state.state);
+ if (ret)
+ goto out;
+
+out:
+ return ret;
+}
int
-glusterd_friend_find (uuid_t uuid, char *hostname,
+glusterd_friend_find (uuid_t uuid, char *hostname,
glusterd_peerinfo_t **peerinfo)
{
int ret = -1;
@@ -197,7 +288,7 @@ glusterd_friend_find (uuid_t uuid, char *hostname,
ret = glusterd_friend_find_by_uuid (uuid, peerinfo);
if (ret) {
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Unable to find peer by uuid");
} else {
goto out;
@@ -238,7 +329,7 @@ glusterd_handle_cluster_lock (rpcsvc_request_t *req)
}
uuid_unparse (lock_req.uuid, str);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Received LOCK from uuid: %s", str);
ret = glusterd_op_sm_new_event (GD_OP_EVENT_LOCK, &event);
@@ -247,7 +338,7 @@ glusterd_handle_cluster_lock (rpcsvc_request_t *req)
//respond back here
return ret;
}
-
+
ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_stage_ctx_t);
if (!ctx) {
@@ -274,11 +365,11 @@ glusterd_handle_stage_op (rpcsvc_request_t *req)
char str[50];
gd1_mgmt_stage_op_req *stage_req = NULL;
glusterd_op_sm_event_t *event = NULL;
- glusterd_op_stage_ctx_t *ctx = NULL;
+ glusterd_op_stage_ctx_t *ctx = NULL;
GF_ASSERT (req);
- stage_req = GF_CALLOC (1, sizeof (*stage_req),
+ stage_req = GF_CALLOC (1, sizeof (*stage_req),
gf_gld_mt_mop_stage_req_t);
GF_ASSERT (stage_req);
@@ -290,7 +381,7 @@ glusterd_handle_stage_op (rpcsvc_request_t *req)
}
uuid_unparse (stage_req->uuid, str);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Received stage op from uuid: %s", str);
ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_OP, &event);
@@ -299,7 +390,7 @@ glusterd_handle_stage_op (rpcsvc_request_t *req)
//respond back here
return ret;
}
-
+
ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_stage_ctx_t);
if (!ctx) {
@@ -314,7 +405,7 @@ glusterd_handle_stage_op (rpcsvc_request_t *req)
ret = glusterd_op_sm_inject_event (event);
-out:
+out:
return ret;
}
@@ -325,7 +416,7 @@ glusterd_handle_commit_op (rpcsvc_request_t *req)
char str[50];
glusterd_op_sm_event_t *event = NULL;
gd1_mgmt_commit_op_req commit_req = {{0},};
- glusterd_op_commit_ctx_t *ctx = NULL;
+ glusterd_op_commit_ctx_t *ctx = NULL;
GF_ASSERT (req);
@@ -337,7 +428,7 @@ glusterd_handle_commit_op (rpcsvc_request_t *req)
uuid_unparse (commit_req.uuid, str);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Received commit op from uuid: %s", str);
ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_OP, &event);
@@ -346,7 +437,7 @@ glusterd_handle_commit_op (rpcsvc_request_t *req)
//respond back here
return ret;
}
-
+
ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_commit_ctx_t);
if (!ctx) {
@@ -389,6 +480,67 @@ out:
}
int
+glusterd_handle_cli_deprobe (rpcsvc_request_t *req)
+{
+ int32_t ret = -1;
+ gf1_cli_probe_req cli_req = {0,};
+
+ GF_ASSERT (req);
+
+ if (!gf_xdr_to_cli_probe_req (req->msg[0], &cli_req)) {
+ //failed to decode msg;
+ req->rpc_err = GARBAGE_ARGS;
+ goto out;
+ }
+
+ gf_log ("glusterd", GF_LOG_NORMAL, "Received CLI deprobe req");
+
+
+ ret = glusterd_deprobe_begin (req, cli_req.hostname);
+
+out:
+ return ret;
+}
+
+int
+glusterd_handle_cli_list_friends (rpcsvc_request_t *req)
+{
+ int32_t ret = -1;
+ gf1_cli_peer_list_req cli_req = {0,};
+ dict_t *dict = NULL;
+
+ GF_ASSERT (req);
+
+ if (!gf_xdr_to_cli_peer_list_req (req->msg[0], &cli_req)) {
+ //failed to decode msg;
+ req->rpc_err = GARBAGE_ARGS;
+ goto out;
+ }
+
+ gf_log ("glusterd", GF_LOG_NORMAL, "Received cli list req");
+
+ 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;
+ }
+ }
+
+ ret = glusterd_list_friends (req, dict, cli_req.flags);
+
+out:
+ return ret;
+}
+
+int
glusterd_handle_create_volume (rpcsvc_request_t *req)
{
int32_t ret = -1;
@@ -409,7 +561,7 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
/* Unserialize the dictionary */
dict = dict_new ();
- ret = dict_unserialize (cli_req.bricks.bricks_val,
+ ret = dict_unserialize (cli_req.bricks.bricks_val,
cli_req.bricks.bricks_len,
&dict);
if (ret < 0) {
@@ -437,10 +589,10 @@ glusterd_op_lock_send_resp (rpcsvc_request_t *req, int32_t status)
glusterd_get_uuid (&rsp.uuid);
rsp.op_ret = status;
- ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gd_xdr_serialize_mgmt_cluster_lock_rsp);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Responded, ret: %d", ret);
return 0;
@@ -457,10 +609,10 @@ glusterd_op_unlock_send_resp (rpcsvc_request_t *req, int32_t status)
rsp.op_ret = status;
glusterd_get_uuid (&rsp.uuid);
- ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gd_xdr_serialize_mgmt_cluster_unlock_rsp);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Responded to unlock, ret: %d", ret);
return ret;
@@ -485,7 +637,7 @@ glusterd_handle_cluster_unlock (rpcsvc_request_t *req)
uuid_unparse (unlock_req.uuid, str);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Received UNLOCK from uuid: %s", str);
ret = glusterd_op_sm_new_event (GD_OP_EVENT_UNLOCK, &event);
@@ -494,7 +646,7 @@ glusterd_handle_cluster_unlock (rpcsvc_request_t *req)
//respond back here
return ret;
}
-
+
ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_lock_ctx_t);
if (!ctx) {
@@ -512,7 +664,7 @@ out:
}
int
-glusterd_op_stage_send_resp (rpcsvc_request_t *req,
+glusterd_op_stage_send_resp (rpcsvc_request_t *req,
int32_t op, int32_t status)
{
@@ -524,17 +676,17 @@ glusterd_op_stage_send_resp (rpcsvc_request_t *req,
glusterd_get_uuid (&rsp.uuid);
rsp.op = op;
- ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gd_xdr_serialize_mgmt_stage_op_rsp);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Responded to stage, ret: %d", ret);
return ret;
}
int
-glusterd_op_commit_send_resp (rpcsvc_request_t *req,
+glusterd_op_commit_send_resp (rpcsvc_request_t *req,
int32_t op, int32_t status)
{
gd1_mgmt_commit_op_rsp rsp = {{0}, };
@@ -545,10 +697,10 @@ glusterd_op_commit_send_resp (rpcsvc_request_t *req,
glusterd_get_uuid (&rsp.uuid);
rsp.op = op;
- ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gd_xdr_serialize_mgmt_commit_op_rsp);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Responded to commit, ret: %d", ret);
return ret;
@@ -569,10 +721,10 @@ glusterd_handle_incoming_friend_req (rpcsvc_request_t *req)
}
uuid_unparse (friend_req.uuid, str);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Received probe from uuid: %s", str);
- ret = glusterd_handle_friend_req (req, friend_req.uuid,
+ ret = glusterd_handle_friend_req (req, friend_req.uuid,
friend_req.hostname);
out:
@@ -581,6 +733,32 @@ out:
}
int
+glusterd_handle_incoming_unfriend_req (rpcsvc_request_t *req)
+{
+ int32_t ret = -1;
+ gd1_mgmt_friend_req friend_req = {{0},};
+ char str[50];
+
+ GF_ASSERT (req);
+ if (!gd_xdr_to_mgmt_friend_req (req->msg[0], &friend_req)) {
+ //failed to decode msg;
+ req->rpc_err = GARBAGE_ARGS;
+ goto out;
+ }
+ uuid_unparse (friend_req.uuid, str);
+
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Received unfriend from uuid: %s", str);
+
+ ret = glusterd_handle_unfriend_req (req, friend_req.uuid,
+ friend_req.hostname);
+
+out:
+
+ return ret;
+}
+
+int
glusterd_handle_probe_query (rpcsvc_request_t *req)
{
int32_t ret = -1;
@@ -604,7 +782,7 @@ glusterd_handle_probe_query (rpcsvc_request_t *req)
uuid_unparse (probe_req.uuid, str);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Received probe from uuid: %s", str);
@@ -615,10 +793,10 @@ glusterd_handle_probe_query (rpcsvc_request_t *req)
uuid_copy (rsp.uuid, conf->uuid);
rsp.hostname = gf_strdup (probe_req.hostname);
- ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gd_xdr_serialize_mgmt_probe_rsp);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Responded to %s, ret: %d", probe_req.hostname, ret);
out:
@@ -644,8 +822,8 @@ glusterd_handle_friend_req_resp (call_frame_t *frame,
op_ret = rsp_hdr->rsp.op_ret;
- gf_log ("glusterd", GF_LOG_NORMAL,
- "Received %s from uuid: %s, host: %s",
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Received %s from uuid: %s, host: %s",
(op_ret)?"RJT":"ACC", str, rsp->hostname);
ret = glusterd_friend_find (rsp->uuid, rsp->hostname, &peerinfo);
@@ -654,7 +832,7 @@ glusterd_handle_friend_req_resp (call_frame_t *frame,
GF_ASSERT (0);
}
- if (op_ret)
+ if (op_ret)
event_type = GD_FRIEND_EVENT_RCVD_ACC;
else
event_type = GD_FRIEND_EVENT_RCVD_RJT;
@@ -676,7 +854,7 @@ glusterd_handle_friend_req_resp (call_frame_t *frame,
}*/
/*int
-glusterd_handle_probe_resp (call_frame_t *frame, gf_hdr_common_t *rsp_hdr,
+glusterd_handle_probe_resp (call_frame_t *frame, gf_hdr_common_t *rsp_hdr,
size_t hdrlen)
{
gf_mop_probe_rsp_t *rsp = NULL;
@@ -691,8 +869,8 @@ glusterd_handle_probe_resp (call_frame_t *frame, gf_hdr_common_t *rsp_hdr,
rsp = gf_param (rsp_hdr);
uuid_unparse (rsp->uuid, str);
- gf_log ("glusterd", GF_LOG_NORMAL,
- "Received probe resp from uuid: %s, host: %s",
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Received probe resp from uuid: %s, host: %s",
str, rsp->hostname);
ret = glusterd_friend_find (rsp->uuid, rsp->hostname, &peerinfo);
@@ -714,7 +892,7 @@ glusterd_handle_probe_resp (call_frame_t *frame, gf_hdr_common_t *rsp_hdr,
GF_ASSERT (peerinfo->hostname);
uuid_copy (peerinfo->uuid, rsp->uuid);
- ret = glusterd_friend_sm_new_event
+ ret = glusterd_friend_sm_new_event
(GD_FRIEND_EVENT_INIT_FRIEND_REQ, &event);
if (ret) {
@@ -870,11 +1048,11 @@ glusterd_xfer_cluster_lock_req (xlator_t *this, int32_t *lock_count)
list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
GF_ASSERT (peerinfo);
- if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
+ if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
continue;
-
- ret = glusterd_submit_request (peerinfo, &req, dummy_frame,
+
+ ret = glusterd_submit_request (peerinfo, &req, dummy_frame,
prog, GD_MGMT_PROBE_QUERY,
NULL, gd_xdr_from_mgmt_probe_req,
this);
@@ -926,13 +1104,13 @@ glusterd_xfer_cluster_unlock_req (xlator_t *this, int32_t *pending_count)
list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
GF_ASSERT (peerinfo);
- if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
+ if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
continue;
-
+
ret = glusterd_xfer (dummy_frame, this,
peerinfo->trans,
- GF_OP_TYPE_MOP_REQUEST,
+ GF_OP_TYPE_MOP_REQUEST,
GF_MOP_CLUSTER_UNLOCK,
hdr, hdrlen, NULL, 0, NULL);
if (!ret)
@@ -953,7 +1131,7 @@ unwind:
int
glusterd_friend_add (const char *hoststr,
- glusterd_peer_state_t state,
+ glusterd_friend_sm_state_t state,
uuid_t *uuid,
struct rpc_clnt *rpc,
glusterd_peerinfo_t **friend)
@@ -987,7 +1165,7 @@ glusterd_friend_add (const char *hoststr,
if (uuid) {
uuid_copy (peerinfo->uuid, *uuid);
- }
+ }
if (hoststr) {
@@ -1006,8 +1184,8 @@ glusterd_friend_add (const char *hoststr,
gf_log ("glusterd", GF_LOG_NORMAL, "remote-port: %d", port_num);
- //ret = dict_set_int32 (options, "remote-port", GLUSTERD_DEFAULT_PORT);
- ret = dict_set_int32 (options, "remote-port", port_num);
+ //ret = dict_set_int32 (options, "remote-port", GLUSTERD_DEFAULT_PORT);
+ ret = dict_set_int32 (options, "remote-port", port_num);
if (ret)
goto out;
@@ -1018,12 +1196,12 @@ glusterd_friend_add (const char *hoststr,
rpc = rpc_clnt_init (&rpc_cfg, options, THIS->ctx, THIS->name);
if (!rpc) {
- gf_log ("glusterd", GF_LOG_ERROR,
+ gf_log ("glusterd", GF_LOG_ERROR,
"rpc init failed for peer: %s!", hoststr);
ret = -1;
goto out;
}
-
+
ret = rpc_clnt_register_notify (rpc, glusterd_rpc_notify,
peerinfo);
@@ -1050,11 +1228,11 @@ glusterd_friend_probe (const char *hoststr)
if (ret) {
//We should not reach this state ideally
GF_ASSERT (0);
- goto out;
+ goto out;
}
-
+
ret = glusterd_xfer_probe_msg (peerinfo, THIS);
-
+
out:
return ret;
}*/
@@ -1075,13 +1253,14 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr)
if (ret) {
gf_log ("glusterd", GF_LOG_NORMAL, "Unable to find peerinfo"
" for host: %s", hoststr);
- ret = glusterd_friend_add ((char *)hoststr, GD_PEER_STATE_NONE,
+ ret = glusterd_friend_add ((char *)hoststr,
+ GD_FRIEND_STATE_DEFAULT,
NULL, NULL, &peerinfo);
}
- ret = glusterd_friend_sm_new_event
+ ret = glusterd_friend_sm_new_event
(GD_FRIEND_EVENT_PROBE, &event);
-
+
if (ret) {
gf_log ("glusterd", GF_LOG_ERROR, "Unable to get new event");
return ret;
@@ -1110,6 +1289,62 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr)
return ret;
}
+int
+glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr)
+{
+ int ret = -1;
+ glusterd_peerinfo_t *peerinfo = NULL;
+ glusterd_friend_sm_event_t *event = NULL;
+ glusterd_probe_ctx_t *ctx = NULL;
+
+ GF_ASSERT (hoststr);
+ GF_ASSERT (req);
+
+ ret = glusterd_friend_find (NULL, (char *)hoststr, &peerinfo);
+
+ if (ret) {
+ gf_log ("glusterd", GF_LOG_NORMAL, "Unable to find peerinfo"
+ " for host: %s", hoststr);
+ goto out;
+ }
+
+ if (!peerinfo->rpc) {
+ //handle this case
+ goto out;
+ }
+
+ ret = glusterd_friend_sm_new_event
+ (GD_FRIEND_EVENT_INIT_REMOVE_FRIEND, &event);
+
+ if (ret) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Unable to get new event");
+ return ret;
+ }
+
+ ctx = GF_CALLOC (1, sizeof(*ctx), gf_gld_mt_probe_ctx_t);
+
+ if (!ctx) {
+ return ret;
+ }
+
+ ctx->hostname = gf_strdup (hoststr);
+ ctx->req = req;
+
+ event->peerinfo = peerinfo;
+ event->ctx = ctx;
+
+ ret = glusterd_friend_sm_inject_event (event);
+
+ if (ret) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject event %d, "
+ "ret = %d", event->event, ret);
+ return ret;
+ }
+
+out:
+ return ret;
+}
+
/*int
glusterd_interpret (xlator_t *this, transport_t *trans,
char *hdr_p, size_t hdrlen, struct iobuf *iobuf)
@@ -1174,6 +1409,33 @@ glusterd_interpret (xlator_t *this, transport_t *trans,
*/
int
+glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname)
+{
+ gd1_mgmt_friend_rsp rsp = {{0}, };
+ int32_t ret = -1;
+ xlator_t *this = NULL;
+ glusterd_conf_t *conf = NULL;
+
+ GF_ASSERT (hostname);
+
+ rsp.op_ret = 0;
+ this = THIS;
+ GF_ASSERT (this);
+
+ conf = this->private;
+
+ uuid_copy (rsp.uuid, conf->uuid);
+ rsp.hostname = hostname;
+
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ gd_xdr_serialize_mgmt_friend_rsp);
+
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Responded to %s, ret: %d", hostname, ret);
+ return ret;
+}
+
+int
glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname)
{
gd1_mgmt_friend_rsp rsp = {{0}, };
@@ -1193,10 +1455,10 @@ glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname)
rsp.hostname = gf_strdup (hostname);
- ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gd_xdr_serialize_mgmt_friend_rsp);
- gf_log ("glusterd", GF_LOG_NORMAL,
+ gf_log ("glusterd", GF_LOG_NORMAL,
"Responded to %s, ret: %d", hostname, ret);
return ret;
}
@@ -1214,7 +1476,7 @@ glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret,
rsp.op_errno = op_errno;
rsp.hostname = hostname;
- ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gf_xdr_serialize_cli_probe_rsp);
gf_log ("glusterd", GF_LOG_NORMAL, "Responded to CLI, ret: %d",ret);
@@ -1305,7 +1567,7 @@ glusterd_create_volume (rpcsvc_request_t *req, dict_t *dict)
snprintf (cmd_str, 8192,
"glusterfs-volgen -n %s -c /etc/glusterd -r 1 %s",
volname, bricks);
- system (cmd_str);
+ ret = system (cmd_str);
break;
}
case GF_CLUSTER_TYPE_STRIPE:
@@ -1316,7 +1578,7 @@ glusterd_create_volume (rpcsvc_request_t *req, dict_t *dict)
snprintf (cmd_str, 8192,
"glusterfs-volgen -n %s -c /etc/glusterd -r 0 %s",
volname, bricks);
- system (cmd_str);
+ ret = system (cmd_str);
break;
}
case GF_CLUSTER_TYPE_NONE:
@@ -1324,7 +1586,7 @@ glusterd_create_volume (rpcsvc_request_t *req, dict_t *dict)
snprintf (cmd_str, 8192,
"glusterfs-volgen -n %s -c /etc/glusterd %s",
volname, bricks);
- system (cmd_str);
+ ret = system (cmd_str);
break;
}
}
@@ -1336,6 +1598,68 @@ out:
}
+int32_t
+glusterd_list_friends (rpcsvc_request_t *req, dict_t *dict, int32_t flags)
+{
+ int32_t ret = -1;
+ glusterd_conf_t *priv = NULL;
+ glusterd_peerinfo_t *entry = NULL;
+ int32_t count = 0;
+ dict_t *friends = NULL;
+ gf1_cli_peer_list_rsp rsp = {0,};
+
+ priv = THIS->private;
+ GF_ASSERT (priv);
+
+ if (!list_empty (&priv->peers)) {
+ friends = dict_new ();
+ if (!friends) {
+ gf_log ("", GF_LOG_WARNING, "Out of Memory");
+ goto out;
+ }
+ } else {
+ ret = 0;
+ goto out;
+ }
+
+ if (flags == GF_CLI_LIST_ALL) {
+ list_for_each_entry (entry, &priv->peers, uuid_list) {
+ count++;
+ ret = glusterd_add_peer_detail_to_dict (entry,
+ friends, count);
+ if (ret)
+ goto out;
+
+ }
+
+ ret = dict_set_int32 (friends, "count", count);
+
+ if (ret)
+ goto out;
+ }
+
+ ret = dict_allocate_and_serialize (friends, &rsp.friends.friends_val,
+ (size_t *)&rsp.friends.friends_len);
+
+ if (ret)
+ goto out;
+
+ ret = 0;
+out:
+
+ if (ret) {
+ if (friends)
+ dict_destroy (friends);
+ }
+
+ rsp.op_ret = ret;
+
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ gf_xdr_serialize_cli_peer_list_rsp);
+
+ return ret;
+}
+
int
glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
void *data)
@@ -1364,7 +1688,7 @@ glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
} else {
//conf->rpc->connected = 1;
ret = default_notify (this, GF_EVENT_CHILD_UP, NULL);
- }
+ }
break;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 41203606c..c6aaf7127 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -77,20 +77,20 @@ glusterd_op_get_len (glusterd_op_t op)
return 0;
}
-int
+int
glusterd_op_build_payload (glusterd_op_t op, gd1_mgmt_stage_op_req **req)
{
int len = 0;
int ret = -1;
gd1_mgmt_stage_op_req *stage_req = NULL;
-
+
GF_ASSERT (op < GD_OP_MAX);
GF_ASSERT (op > GD_OP_NONE);
GF_ASSERT (req);
len = glusterd_op_get_len (op);
- stage_req = GF_CALLOC (1, sizeof (*stage_req),
+ stage_req = GF_CALLOC (1, sizeof (*stage_req),
gf_gld_mt_mop_stage_req_t);
if (!stage_req) {
@@ -98,7 +98,7 @@ glusterd_op_build_payload (glusterd_op_t op, gd1_mgmt_stage_op_req **req)
goto out;
}
- stage_req->buf.buf_val = GF_CALLOC (1, len,
+ stage_req->buf.buf_val = GF_CALLOC (1, len,
gf_gld_mt_mop_stage_req_t);
if (!stage_req->buf.buf_val) {
@@ -116,7 +116,7 @@ glusterd_op_build_payload (glusterd_op_t op, gd1_mgmt_stage_op_req **req)
dict_t *dict = NULL;
dict = glusterd_op_get_ctx (op);
GF_ASSERT (dict);
- ret = dict_serialize (dict,
+ ret = dict_serialize (dict,
stage_req->buf.buf_val);
if (ret) {
goto out;
@@ -166,13 +166,13 @@ glusterd_xfer_stage_req (xlator_t *this, int32_t *lock_count)
//No pending ops, inject stage_acc
glusterd_op_sm_event_t *event = NULL;
-
- ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC,
+
+ ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC,
&event);
if (ret)
goto out;
-
+
ret = glusterd_op_sm_inject_event (event);
return ret;
@@ -192,12 +192,12 @@ glusterd_xfer_stage_req (xlator_t *this, int32_t *lock_count)
list_for_each_entry (peerinfo, &opinfo.op_peers, op_peers_list) {
GF_ASSERT (peerinfo);
- GF_ASSERT (peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED);
+ GF_ASSERT (peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED);
+
-
ret = glusterd_xfer (dummy_frame, this,
peerinfo->trans,
- GF_OP_TYPE_MOP_REQUEST,
+ GF_OP_TYPE_MOP_REQUEST,
GF_MOP_STAGE_OP,
hdr, hdrlen, NULL, 0, NULL);
if (!ret)
@@ -206,7 +206,7 @@ glusterd_xfer_stage_req (xlator_t *this, int32_t *lock_count)
gf_log ("glusterd", GF_LOG_NORMAL, "Sent op req to %d peers",
pending_lock);
- if (i < GD_OP_MAX)
+ if (i < GD_OP_MAX)
opinfo.pending_op[i] = 0;
*lock_count = pending_lock;
@@ -247,13 +247,13 @@ glusterd_xfer_commit_req (xlator_t *this, int32_t *lock_count)
//No pending ops, inject stage_acc
glusterd_op_sm_event_t *event = NULL;
-
- ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC,
+
+ ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC,
&event);
if (ret)
goto out;
-
+
ret = glusterd_op_sm_inject_event (event);
return ret;
@@ -273,12 +273,12 @@ glusterd_xfer_commit_req (xlator_t *this, int32_t *lock_count)
list_for_each_entry (peerinfo, &opinfo.op_peers, op_peers_list) {
GF_ASSERT (peerinfo);
- GF_ASSERT (peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED);
+ GF_ASSERT (peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED);
+
-
ret = glusterd_xfer (dummy_frame, this,
peerinfo->trans,
- GF_OP_TYPE_MOP_REQUEST,
+ GF_OP_TYPE_MOP_REQUEST,
GF_MOP_STAGE_OP,
hdr, hdrlen, NULL, 0, NULL);
if (!ret)
@@ -287,7 +287,7 @@ glusterd_xfer_commit_req (xlator_t *this, int32_t *lock_count)
gf_log ("glusterd", GF_LOG_NORMAL, "Sent op req to %d peers",
pending_lock);
- if (i < GD_OP_MAX)
+ if (i < GD_OP_MAX)
opinfo.pending_op[i] = 0;
*lock_count = pending_lock;
@@ -323,10 +323,10 @@ glusterd_op_stage_create_volume (gd1_mgmt_stage_op_req *req)
goto out;
}
- exists = glusterd_check_volume_exists (volname);
+ exists = glusterd_check_volume_exists (volname);
if (exists) {
- gf_log ("", GF_LOG_ERROR, "Volume with name: %s exists",
+ gf_log ("", GF_LOG_ERROR, "Volume with name: %s exists",
volname);
ret = -1;
} else {
@@ -394,7 +394,7 @@ glusterd_op_create_volume (gd1_mgmt_stage_op_req *req)
goto out;
}
- ret = dict_get_int32 (dict, "count", &volinfo->brick_count);
+ ret = dict_get_int32 (dict, "count", &volinfo->brick_count);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to get count");
@@ -756,8 +756,8 @@ glusterd_op_ac_commit_op (glusterd_op_sm_event_t *event, void *ctx)
static int
-glusterd_op_sm_transition_state (glusterd_op_info_t *opinfo,
- glusterd_op_sm_t *state,
+glusterd_op_sm_transition_state (glusterd_op_info_t *opinfo,
+ glusterd_op_sm_t *state,
glusterd_op_sm_event_type_t event_type)
{
@@ -766,7 +766,7 @@ glusterd_op_sm_transition_state (glusterd_op_info_t *opinfo,
gf_log ("", GF_LOG_NORMAL, "Transitioning from %d to %d",
opinfo->state.state, state[event_type].next_state);
- opinfo->state.state =
+ opinfo->state.state =
state[event_type].next_state;
return 0;
}
@@ -777,10 +777,10 @@ glusterd_op_sm_t glusterd_op_state_default [] = {
{GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_NONE
{GD_OP_STATE_LOCK_SENT, glusterd_op_ac_send_lock},//EVENT_START_LOCK
{GD_OP_STATE_LOCKED, glusterd_op_ac_lock}, //EVENT_LOCK
- {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_RCVD_ACC
- {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_ALL_ACC
- {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_STAGE_ACC
- {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
+ {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_RCVD_ACC
+ {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_ALL_ACC
+ {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_STAGE_ACC
+ {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
{GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_RCVD_RJT
{GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_STAGE_OP
{GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_COMMIT_OP
@@ -792,10 +792,10 @@ glusterd_op_sm_t glusterd_op_state_lock_sent [] = {
{GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_NONE
{GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none},//EVENT_START_LOCK
{GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_LOCK
- {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_rcvd_lock_acc}, //EVENT_RCVD_ACC
- {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_send_stage_op}, //EVENT_ALL_ACC
- {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC
- {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
+ {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_rcvd_lock_acc}, //EVENT_RCVD_ACC
+ {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_send_stage_op}, //EVENT_ALL_ACC
+ {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC
+ {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
{GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_send_unlock}, //EVENT_RCVD_RJT
{GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_OP
{GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_OP
@@ -807,10 +807,10 @@ glusterd_op_sm_t glusterd_op_state_locked [] = {
{GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_NONE
{GD_OP_STATE_LOCKED, glusterd_op_ac_none},//EVENT_START_LOCK
{GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_LOCK
- {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_RCVD_ACC
- {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_ALL_ACC
- {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_STAGE_ACC
- {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
+ {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_RCVD_ACC
+ {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_ALL_ACC
+ {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_STAGE_ACC
+ {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
{GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_RCVD_RJT
{GD_OP_STATE_STAGED, glusterd_op_ac_stage_op}, //EVENT_STAGE_OP
{GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_COMMIT_OP
@@ -822,10 +822,10 @@ glusterd_op_sm_t glusterd_op_state_stage_op_sent [] = {
{GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_NONE
{GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none},//EVENT_START_LOCK
{GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_LOCK
- {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_rcvd_stage_op_acc}, //EVENT_RCVD_ACC
- {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_send_stage_op}, //EVENT_ALL_ACC
- {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_send_commit_op}, //EVENT_STAGE_ACC
- {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
+ {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_rcvd_stage_op_acc}, //EVENT_RCVD_ACC
+ {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_send_stage_op}, //EVENT_ALL_ACC
+ {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_send_commit_op}, //EVENT_STAGE_ACC
+ {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
{GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_send_unlock}, //EVENT_RCVD_RJT
{GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_STAGE_OP
{GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_OP
@@ -837,10 +837,10 @@ glusterd_op_sm_t glusterd_op_state_staged [] = {
{GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_NONE
{GD_OP_STATE_STAGED, glusterd_op_ac_none},//EVENT_START_LOCK
{GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_LOCK
- {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_RCVD_ACC
- {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_ALL_ACC
- {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_STAGE_ACC
- {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
+ {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_RCVD_ACC
+ {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_ALL_ACC
+ {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_STAGE_ACC
+ {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
{GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_RCVD_RJT
{GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_STAGE_OP
{GD_OP_STATE_COMMITED, glusterd_op_ac_commit_op}, //EVENT_COMMIT_OP
@@ -852,10 +852,10 @@ glusterd_op_sm_t glusterd_op_state_commit_op_sent [] = {
{GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_NONE
{GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none},//EVENT_START_LOCK
{GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_LOCK
- {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_rcvd_commit_op_acc}, //EVENT_RCVD_ACC
- {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_commit_op}, //EVENT_ALL_ACC
- {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC
- {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_send_unlock}, //EVENT_COMMIT_ACC
+ {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_rcvd_commit_op_acc}, //EVENT_RCVD_ACC
+ {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_commit_op}, //EVENT_ALL_ACC
+ {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC
+ {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_send_unlock}, //EVENT_COMMIT_ACC
{GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_commit_error}, //EVENT_RCVD_RJT
{GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_STAGE_OP
{GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_OP
@@ -867,10 +867,10 @@ glusterd_op_sm_t glusterd_op_state_commited [] = {
{GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_NONE
{GD_OP_STATE_COMMITED, glusterd_op_ac_none},//EVENT_START_LOCK
{GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_LOCK
- {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_RCVD_ACC
- {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_ALL_ACC
- {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_STAGE_ACC
- {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
+ {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_RCVD_ACC
+ {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_ALL_ACC
+ {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_STAGE_ACC
+ {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
{GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_RCVD_RJT
{GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_STAGE_OP
{GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_COMMIT_OP
@@ -882,10 +882,10 @@ glusterd_op_sm_t glusterd_op_state_unlock_sent [] = {
{GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_NONE
{GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none},//EVENT_START_LOCK
{GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_LOCK
- {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_rcvd_unlock_acc}, //EVENT_RCVD_ACC
- {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_ALL_ACC
- {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC
- {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
+ {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_rcvd_unlock_acc}, //EVENT_RCVD_ACC
+ {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_ALL_ACC
+ {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC
+ {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC
{GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_RCVD_RJT
{GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_OP
{GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_OP
@@ -915,7 +915,7 @@ glusterd_op_sm_new_event (glusterd_op_sm_event_type_t event_type,
GF_ASSERT (GD_OP_EVENT_NONE <= event_type &&
GD_OP_EVENT_MAX > event_type);
- event = GF_CALLOC (1, sizeof (*event), gf_gld_mt_op_sm_event_t);
+ event = GF_CALLOC (1, sizeof (*event), gf_gld_mt_op_sm_event_t);
if (!event)
return -1;
@@ -949,11 +949,11 @@ glusterd_op_sm ()
glusterd_op_sm_t *state = NULL;
glusterd_op_sm_event_type_t event_type = 0;
-
+
while (!list_empty (&gd_op_sm_queue)) {
-
+
list_for_each_entry_safe (event, tmp, &gd_op_sm_queue, list) {
-
+
list_del_init (&event->list);
event_type = event->event;
@@ -963,22 +963,22 @@ glusterd_op_sm ()
handler = state[event_type].handler;
GF_ASSERT (handler);
-
+
ret = handler (event, event->ctx);
if (ret) {
- gf_log ("glusterd", GF_LOG_ERROR,
+ gf_log ("glusterd", GF_LOG_ERROR,
"handler returned: %d", ret);
return ret;
}
- ret = glusterd_op_sm_transition_state (&opinfo, state,
+ ret = glusterd_op_sm_transition_state (&opinfo, state,
event_type);
if (ret) {
- gf_log ("glusterd", GF_LOG_ERROR,
+ gf_log ("glusterd", GF_LOG_ERROR,
"Unable to transition"
- "state from %d to %d",
+ "state from %d to %d",
opinfo.state.state,
state[event_type].next_state);
return ret;
@@ -987,7 +987,7 @@ glusterd_op_sm ()
GF_FREE (event);
}
}
-
+
ret = 0;
@@ -997,7 +997,7 @@ glusterd_op_sm ()
int32_t
glusterd_op_set_op (glusterd_op_t op)
{
-
+
GF_ASSERT (op < GD_OP_MAX);
GF_ASSERT (op > GD_OP_NONE);
@@ -1012,7 +1012,7 @@ glusterd_op_set_op (glusterd_op_t op)
int32_t
glusterd_op_set_ctx (glusterd_op_t op, void *ctx)
{
-
+
GF_ASSERT (op < GD_OP_MAX);
GF_ASSERT (op > GD_OP_NONE);
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
index 53a0f5af8..b55fdd567 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.c
@@ -42,6 +42,7 @@
#include "compat-errno.h"
#include "statedump.h"
#include "glusterd-sm.h"
+#include "glusterd-utils.h"
static struct list_head gd_friend_sm_queue;
@@ -56,6 +57,16 @@ glusterd_ac_none (glusterd_friend_sm_event_t *event, void *ctx)
}
static int
+glusterd_ac_error (glusterd_friend_sm_event_t *event, void *ctx)
+{
+ int ret = 0;
+
+ gf_log ("", GF_LOG_ERROR, "Received event %d ", event->event);
+
+ return ret;
+}
+
+static int
glusterd_ac_friend_add (glusterd_friend_sm_event_t *event, void *ctx)
{
int ret = 0;
@@ -143,12 +154,95 @@ glusterd_ac_friend_probe (glusterd_friend_sm_event_t *event, void *ctx)
}
*/
-out:
+out:
gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
return ret;
}
+static int
+glusterd_ac_send_friend_remove_req (glusterd_friend_sm_event_t *event, void *ctx)
+{
+ int ret = 0;
+ glusterd_peerinfo_t *peerinfo = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ call_frame_t *frame = NULL;
+ glusterd_conf_t *conf = NULL;
+ xlator_t *this = NULL;
+
+
+ GF_ASSERT (event);
+ peerinfo = event->peerinfo;
+
+ this = THIS;
+ conf = this->private;
+
+ GF_ASSERT (conf);
+ GF_ASSERT (conf->mgmt);
+
+ proc = &conf->mgmt->proctable[GD_MGMT_FRIEND_REMOVE];
+ if (proc->fn) {
+ frame = create_frame (this, this->ctx->pool);
+ if (!frame) {
+ goto out;
+ }
+ frame->local = ctx;
+ ret = proc->fn (frame, this, event);
+ }
+
+/* ret = glusterd_xfer_friend_req_msg (peerinfo, THIS);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to probe: %s", hostname);
+ }
+*/
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+
+ return ret;
+}
+
+static int
+glusterd_ac_handle_friend_remove_req (glusterd_friend_sm_event_t *event,
+ void *ctx)
+{
+ int ret = 0;
+ glusterd_peerinfo_t *peerinfo = NULL;
+ glusterd_friend_req_ctx_t *ev_ctx = NULL;
+
+ GF_ASSERT (ctx);
+ ev_ctx = ctx;
+ peerinfo = event->peerinfo;
+ GF_ASSERT (peerinfo);
+
+ uuid_clear (peerinfo->uuid);
+
+ ret = glusterd_xfer_friend_remove_resp (ev_ctx->req, ev_ctx->hostname);
+
+ rpc_clnt_destroy (peerinfo->rpc);
+ peerinfo->rpc = NULL;
+
+ gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+
+ return ret;
+}
+
+static int
+glusterd_ac_friend_remove (glusterd_friend_sm_event_t *event, void *ctx)
+{
+ int ret = -1;
+
+ ret = glusterd_friend_cleanup (event->peerinfo);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Cleanup returned: %d", ret);
+ }
+
+
+ return 0;
+}
+
/*static int
glusterd_ac_none (void *ctx)
{
@@ -166,6 +260,9 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)
uuid_t uuid;
glusterd_peerinfo_t *peerinfo = NULL;
glusterd_friend_req_ctx_t *ev_ctx = NULL;
+ glusterd_friend_sm_event_t *new_event = NULL;
+ glusterd_friend_sm_event_type_t event_type = GD_FRIEND_EVENT_NONE;
+ int status = 0;
GF_ASSERT (ctx);
ev_ctx = ctx;
@@ -174,6 +271,22 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)
GF_ASSERT (peerinfo);
uuid_copy (peerinfo->uuid, ev_ctx->uuid);
+ //Build comparison logic here.
+
+ if (!status)
+ event_type = GD_FRIEND_EVENT_LOCAL_ACC;
+ else
+ event_type = GD_FRIEND_EVENT_LOCAL_RJT;
+
+ ret = glusterd_friend_sm_new_event (event_type, &new_event);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Out of Memory");
+ }
+
+ new_event->peerinfo = peerinfo;
+ glusterd_friend_sm_inject_event (new_event);
+
ret = glusterd_xfer_friend_add_resp (ev_ctx->req, ev_ctx->hostname);
gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
@@ -182,8 +295,8 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)
}
static int
-glusterd_friend_sm_transition_state (glusterd_peerinfo_t *peerinfo,
- glusterd_sm_t *state,
+glusterd_friend_sm_transition_state (glusterd_peerinfo_t *peerinfo,
+ glusterd_sm_t *state,
glusterd_friend_sm_event_type_t event_type)
{
@@ -203,9 +316,12 @@ glusterd_sm_t glusterd_state_default [] = {
{GD_FRIEND_STATE_DEFAULT, glusterd_ac_none},
{GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_probe},//EV_PROBE
{GD_FRIEND_STATE_REQ_SENT, glusterd_ac_friend_add}, //EV_INIT_FRIEND_REQ
- {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_ACC
+ {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_ACC
+ {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC
{GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_RJT
+ {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ
+ {GD_FRIEND_STATE_DEFAULT, glusterd_ac_error}, //EV_INIT_REMOVE_FRIEND
{GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND
{GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_MAX
};
@@ -215,9 +331,12 @@ glusterd_sm_t glusterd_state_req_sent [] = {
{GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_NONE,
{GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_PROBE,
{GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ,
- {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC
+ {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_RCVD_ACC
+ {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC
{GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT
+ {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT
{GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ
+ {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_INIT_REMOVE_FRIEND,
{GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND
{GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none},//EVENT_MAX
};
@@ -227,8 +346,11 @@ glusterd_sm_t glusterd_state_req_rcvd [] = {
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_friend_probe}, //EVENT_PROBE,
{GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_friend_add}, //EVENT_INIT_FRIEND_REQ,
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_ACC
+ {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_RJT
+ {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCV_FRIEND_REQ
+ {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_error}, //EVENT_INIT_REMOVE_FRIEND,
{GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none},//EVENT_MAX
};
@@ -238,9 +360,12 @@ glusterd_sm_t glusterd_state_befriended [] = {
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_PROBE,
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ,
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC
+ {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_RJT
+ {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCV_FRIEND_REQ
- {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_send_friend_remove_req}, //EVENT_INIT_REMOVE_FRIEND,
+ {GD_FRIEND_STATE_DEFAULT, glusterd_ac_handle_friend_remove_req}, //EVENT_REMOVE_FRIEND
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none},//EVENT_MAX
};
@@ -249,8 +374,11 @@ glusterd_sm_t glusterd_state_req_sent_rcvd [] = {
{GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_PROBE,
{GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ,
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC
+ {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC
{GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT
+ {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT
{GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_RCV_FRIEND_REQ
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_send_friend_remove_req}, //EVENT_INIT_REMOVE_FRIEND,
{GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND
{GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none},//EVENT_MAX
};
@@ -260,12 +388,43 @@ glusterd_sm_t glusterd_state_rejected [] = {
{GD_FRIEND_STATE_REJECTED, glusterd_ac_friend_probe}, //EVENT_PROBE,
{GD_FRIEND_STATE_REQ_SENT, glusterd_ac_friend_add}, //EVENT_INIT_FRIEND_REQ,
{GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_ACC
+ {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC
{GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT
+ {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ
+ {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_INIT_REMOVE_FRIEND
{GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none},//EVENT_MAX
};
+glusterd_sm_t glusterd_state_req_accepted [] = {
+ {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_NONE,
+ {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_PROBE,
+ {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ,
+ {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC
+ {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC
+ {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT
+ {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT
+ {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ
+ {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_INIT_REMOVE_FRIEND
+ {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND
+ {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none},//EVENT_MAX
+};
+
+glusterd_sm_t glusterd_state_unfriend_sent [] = {
+ {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_NONE,
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_PROBE,
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ,
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_RCVD_ACC
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_RCVD_RJT
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_RCVD_LOCAL_RJT
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_RCV_FRIEND_REQ
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_INIT_REMOVE_FRIEND
+ {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND
+ {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none},//EVENT_MAX
+};
+
glusterd_sm_t *glusterd_friend_state_table [] = {
glusterd_state_default,
glusterd_state_req_sent,
@@ -273,6 +432,8 @@ glusterd_sm_t *glusterd_friend_state_table [] = {
glusterd_state_befriended,
glusterd_state_req_sent_rcvd,
glusterd_state_rejected,
+ glusterd_state_req_accepted,
+ glusterd_state_unfriend_sent,
};
int
@@ -285,7 +446,7 @@ glusterd_friend_sm_new_event (glusterd_friend_sm_event_type_t event_type,
GF_ASSERT (GD_FRIEND_EVENT_NONE <= event_type &&
GD_FRIEND_EVENT_MAX > event_type);
- event = GF_CALLOC (1, sizeof (*event), gf_gld_mt_friend_sm_event_t);
+ event = GF_CALLOC (1, sizeof (*event), gf_gld_mt_friend_sm_event_t);
if (!event)
return -1;
@@ -321,21 +482,22 @@ glusterd_friend_sm ()
glusterd_friend_sm_event_type_t event_type = 0;
list_for_each_entry_safe (event, tmp, &gd_friend_sm_queue, list) {
-
+
list_del_init (&event->list);
peerinfo = event->peerinfo;
event_type = event->event;
- if (!peerinfo &&
+ if (!peerinfo &&
(GD_FRIEND_EVENT_PROBE == event_type ||
GD_FRIEND_EVENT_RCVD_FRIEND_REQ == event_type)) {
- ret = glusterd_friend_add (NULL, GD_PEER_STATE_NONE, NULL, NULL,
- &peerinfo);
+ ret = glusterd_friend_add (NULL,
+ GD_FRIEND_STATE_DEFAULT,
+ NULL, NULL, &peerinfo);
if (ret) {
gf_log ("glusterd", GF_LOG_ERROR, "Unable to add peer, "
"ret = %d", ret);
- continue;
+ continue;
}
GF_ASSERT (peerinfo);
event->peerinfo = peerinfo;
@@ -348,7 +510,7 @@ glusterd_friend_sm ()
handler = state[event_type].handler;
GF_ASSERT (handler);
-
+
ret = handler (event, event->ctx);
if (ret) {
@@ -368,7 +530,7 @@ glusterd_friend_sm ()
GF_FREE (event);
}
-
+
ret = 0;
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h
index 087a4c301..6f03a8497 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.h
@@ -28,6 +28,7 @@
#include <pthread.h>
#include <uuid/uuid.h>
+#include "rpc-clnt.h"
#include "glusterfs.h"
#include "xlator.h"
#include "logging.h"
@@ -35,27 +36,52 @@
#include "authenticate.h"
#include "fd.h"
#include "byte-order.h"
-#include "glusterd.h"
+//#include "glusterd.h"
#include "rpcsvc.h"
-
typedef enum glusterd_friend_sm_state_ {
GD_FRIEND_STATE_DEFAULT = 0,
GD_FRIEND_STATE_REQ_SENT,
GD_FRIEND_STATE_REQ_RCVD,
GD_FRIEND_STATE_BEFRIENDED,
+ GD_FRIEND_STATE_REQ_ACCEPTED,
GD_FRIEND_STATE_REQ_SENT_RCVD,
GD_FRIEND_STATE_REJECTED,
+ GD_FRIEND_STATE_UNFRIEND_SENT,
GD_FRIEND_STATE_MAX
} glusterd_friend_sm_state_t;
+typedef struct glusterd_peer_state_info_ {
+ glusterd_friend_sm_state_t state;
+ struct timeval transition_time;
+}glusterd_peer_state_info_t;
+
+
+struct glusterd_peerinfo_ {
+ uuid_t uuid;
+ char uuid_str[50];
+ glusterd_peer_state_info_t state;
+ char *hostname;
+ int port;
+ struct list_head uuid_list;
+ struct list_head op_peers_list;
+ struct rpc_clnt *rpc;
+};
+
+typedef struct glusterd_peerinfo_ glusterd_peerinfo_t;
+
+
+
typedef enum glusterd_friend_sm_event_type_ {
GD_FRIEND_EVENT_NONE = 0,
GD_FRIEND_EVENT_PROBE,
GD_FRIEND_EVENT_INIT_FRIEND_REQ,
GD_FRIEND_EVENT_RCVD_ACC,
+ GD_FRIEND_EVENT_LOCAL_ACC,
GD_FRIEND_EVENT_RCVD_RJT,
+ GD_FRIEND_EVENT_LOCAL_RJT,
GD_FRIEND_EVENT_RCVD_FRIEND_REQ,
+ GD_FRIEND_EVENT_INIT_REMOVE_FRIEND,
GD_FRIEND_EVENT_REMOVE_FRIEND,
GD_FRIEND_EVENT_MAX
} glusterd_friend_sm_event_type_t;
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 0e3168036..feb4919ee 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -106,7 +106,7 @@ out:
int32_t
glusterd_unlock (uuid_t uuid)
-{
+{
uuid_t owner;
char new_owner_str[50];
char owner_str[50];
@@ -162,8 +162,8 @@ glusterd_get_uuid (uuid_t *uuid)
int
glusterd_submit_request (glusterd_peerinfo_t *peerinfo, void *req,
- call_frame_t *frame, rpc_clnt_prog_t *prog,
- int procnum, struct iobref *iobref,
+ call_frame_t *frame, rpc_clnt_prog_t *prog,
+ int procnum, struct iobref *iobref,
gd_serialize_t sfunc, xlator_t *this,
fop_cbk_fn_t cbkfn)
{
@@ -205,8 +205,8 @@ glusterd_submit_request (glusterd_peerinfo_t *peerinfo, void *req,
count = 1;
}
/* Send the msg */
- ret = rpc_clnt_submit (peerinfo->rpc, prog, procnum, cbkfn,
- &iov, count,
+ ret = rpc_clnt_submit (peerinfo->rpc, prog, procnum, cbkfn,
+ &iov, count,
NULL, 0, iobref, frame);
if (ret == 0) {
@@ -235,7 +235,7 @@ out:
struct iobuf *
-glusterd_serialize_reply (rpcsvc_request_t *req, void *arg,
+glusterd_serialize_reply (rpcsvc_request_t *req, void *arg,
gd_serialize_t sfunc, struct iovec *outmsg)
{
struct iobuf *iob = NULL;
@@ -337,7 +337,7 @@ glusterd_check_volume_exists (char *volname)
struct stat stbuf = {0,};
int32_t ret = -1;
- snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,
+ snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,
volname);
ret = stat (pathname, &stbuf);
@@ -371,7 +371,7 @@ glusterd_volinfo_new (glusterd_volinfo_t **volinfo)
*volinfo = new_volinfo;
ret = 0;
-
+
out:
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
@@ -434,3 +434,17 @@ out:
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
+
+
+int32_t
+glusterd_friend_cleanup (glusterd_peerinfo_t *peerinfo)
+{
+ GF_ASSERT (peerinfo);
+ if (peerinfo->rpc) {
+ rpc_clnt_destroy (peerinfo->rpc);
+ peerinfo->rpc = NULL;
+ }
+ GF_FREE (peerinfo->hostname);
+
+ return 0;
+}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index 01c485b08..8007fa72d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -61,8 +61,8 @@ glusterd_submit_reply (rpcsvc_request_t *req, void *arg,
int
glusterd_submit_request (glusterd_peerinfo_t *peerinfo, void *req,
- call_frame_t *frame, struct rpc_clnt_program *prog,
- int procnum, struct iobref *iobref,
+ call_frame_t *frame, struct rpc_clnt_program *prog,
+ int procnum, struct iobref *iobref,
gd_serialize_t sfunc, xlator_t *this,
fop_cbk_fn_t cbkfn);
@@ -77,4 +77,7 @@ glusterd_brickinfo_new (glusterd_brickinfo_t **brickinfo);
int32_t
glusterd_brickinfo_from_brick (char *brick, glusterd_brickinfo_t **brickinfo);
+
+int32_t
+glusterd_friend_cleanup (glusterd_peerinfo_t *peerinfo);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index 9c688c136..7ce466a64 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -33,7 +33,6 @@
#include "rpcsvc.h"
#include "fnmatch.h"
#include "xlator.h"
-//#include "protocol.h"
#include "call-stub.h"
#include "defaults.h"
#include "list.h"
@@ -41,7 +40,6 @@
#include "compat.h"
#include "compat-errno.h"
#include "statedump.h"
-//#include "md5.h"
#include "glusterd-sm.h"
#include "glusterd-op-sm.h"
@@ -94,46 +92,6 @@ glusterd_uuid_init ()
}
-/* xxx_MOPS */
-
-#if 0
-
-#endif
-
-
-
-
-
-
-
-
-
-
-/*
- * glusterd_nop_cbk - nop callback for server protocol
- * @frame: call frame
- * @cookie:
- * @this:
- * @op_ret: return value
- * @op_errno: errno
- *
- * not for external reference
- */
-/*int
-glusterd_nop_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno)
-{
- glusterd_state_t *state = NULL;
-
- state = GLUSTERD_CALL_STATE(frame);
-
- if (state)
- free_state (state);
- STACK_DESTROY (frame->root);
- return 0;
-}
-*/
-
int
glusterd_priv (xlator_t *this)
@@ -152,7 +110,7 @@ mem_acct_init (xlator_t *this)
return ret;
ret = xlator_mem_acct_init (this, gf_gld_mt_end + 1);
-
+
if (ret != 0) {
gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
" failed");
@@ -181,23 +139,12 @@ glusterd_rpcsvc_notify (rpcsvc_t *rpc, void *xl, rpcsvc_event_t event,
switch (event) {
case RPCSVC_EVENT_ACCEPT:
{
- /* Have a structure per new connection */
- /* TODO: Should we create anything here at all ? * /
- conn = create_server_conn_state (this, xprt);
- if (!conn)
- goto out;
-
- xprt->protocol_private = conn;
- */
xprt->mydata = this;
break;
}
case RPCSVC_EVENT_DISCONNECT:
- /* conn = get_server_conn_state (this, xprt);
- if (conn)
- destroy_server_conn_state (conn);
- */
break;
+
default:
break;
}
@@ -263,7 +210,7 @@ init (xlator_t *this)
gf_log (this->name, GF_LOG_NORMAL, "Using %s as working directory",
dirname);
-
+
rpc = rpcsvc_init (this->ctx, this->options);
if (rpc == NULL) {
gf_log (this->name, GF_LOG_ERROR,
@@ -313,7 +260,7 @@ init (xlator_t *this)
ret = glusterd_uuid_init ();
- if (ret < 0)
+ if (ret < 0)
goto out;
glusterd_friend_sm_init ();
@@ -328,34 +275,10 @@ out:
-/*int
-glusterd_pollin (xlator_t *this, transport_t *trans)
-{
- char *hdr = NULL;
- size_t hdrlen = 0;
- int ret = -1;
- struct iobuf *iobuf = NULL;
-
-
- ret = transport_receive (trans, &hdr, &hdrlen, &iobuf);
-
- if (ret == 0)
- ret = glusterd_interpret (this, trans, hdr,
- hdrlen, iobuf);
-
- ret = glusterd_friend_sm ();
-
- glusterd_op_sm ();
-
- GF_FREE (hdr);
-
- return ret;
-}
-*/
/*
- * fini - finish function for server protocol, called before
- * unloading server protocol.
+ * fini - finish function for glusterd, called before
+ * unloading gluster.
*
* @this:
*
@@ -373,7 +296,7 @@ out:
}
/*
- * server_protocol_notify - notify function for server protocol
+ * notify - notify function for glusterd
* @this:
* @trans:
* @event:
@@ -393,12 +316,12 @@ notify (xlator_t *this, int32_t event, void *data, ...)
}
*/
switch (event) {
-
+
case GF_EVENT_POLLIN:
// ret = glusterd_pollin (this, trans);
break;
-
+
case GF_EVENT_POLLERR:
break;
@@ -408,49 +331,10 @@ notify (xlator_t *this, int32_t event, void *data, ...)
default:
default_notify (this, event, data);
break;
-
- }
-
- return ret;
-}
-
-
-void
-glusterd_init (int signum)
-{
- int ret = -1;
-
- glusterfs_this_set ((xlator_t *)CTX->active);
- ret = glusterd_probe_begin (NULL, "localhost");
-
- if (!ret) {
- ret = glusterd_friend_sm ();
-
- glusterd_op_sm ();
- }
-
- gf_log ("glusterd", GF_LOG_WARNING, "ret = %d", ret);
-
- //return 0;
-}
-
-void
-glusterd_op_init (int signum)
-{
- int ret = -1;
-
- glusterfs_this_set ((xlator_t *)CTX->active);
-
- //ret = glusterd_create_volume ("vol1");
-
-/* if (!ret) {
- glusterd_friend_sm ();
- glusterd_op_sm ();
}
-*/
- gf_log ("glusterd", GF_LOG_WARNING, "ret = %d", ret);
+ return ret;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index b3d53244e..48fe0fc66 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -36,38 +36,14 @@
#include "authenticate.h"
#include "fd.h"
#include "byte-order.h"
-//#include "protocol.h"
#include "glusterd-mem-types.h"
#include "rpcsvc.h"
+#include "glusterd-sm.h"
#include "glusterd1.h"
-
-
-/*struct _glusterd_connection {
- struct list_head list;
- char *id;
- int ref;
- int active_transports;
- pthread_mutex_t lock;
- char disconnected;
- xlator_t *bound_xl;
-};
-
-typedef struct _glusterd_connection glusterd_connection_t;
-*/
-
-
-typedef enum glusterd_peer_state_ {
- GD_PEER_STATE_NONE = 0,
- GD_PEER_STATE_INBOUND,
- GD_PEER_STATE_OUTBOUND,
- GD_PEER_STATE_FRIEND
-} glusterd_peer_state_t;
-
-
-typedef struct glusterd_peer_state_info_ {
- glusterd_peer_state_t state;
+/*typedef struct glusterd_peer_state_info_ {
+ glusterd_friend_sm_state_t state;
struct timeval transition_time;
}glusterd_peer_state_info_t;
@@ -79,11 +55,11 @@ struct glusterd_peerinfo_ {
int port;
struct list_head uuid_list;
struct list_head op_peers_list;
- // struct list_head pending_uuid;
struct rpc_clnt *rpc;
};
typedef struct glusterd_peerinfo_ glusterd_peerinfo_t;
+*/
typedef struct {
struct _volfile_ctx *volfile;
@@ -142,12 +118,12 @@ int
glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname);
int
-glusterd_friend_find (uuid_t uuid, char *hostname,
+glusterd_friend_find (uuid_t uuid, char *hostname,
glusterd_peerinfo_t **peerinfo);
int
glusterd_friend_add (const char *hoststr,
- glusterd_peer_state_t state,
+ glusterd_friend_sm_state_t state,
uuid_t *uuid, struct rpc_clnt *rpc,
glusterd_peerinfo_t **friend);
/*
@@ -169,18 +145,18 @@ int
glusterd_op_unlock_send_resp (rpcsvc_request_t *req, int32_t status);
int
-glusterd_op_stage_send_resp (rpcsvc_request_t *req,
+glusterd_op_stage_send_resp (rpcsvc_request_t *req,
int32_t op, int32_t status);
int
-glusterd_op_commmit_send_resp (rpcsvc_request_t *req,
+glusterd_op_commmit_send_resp (rpcsvc_request_t *req,
int32_t op, int32_t status);
int32_t
glusterd_create_volume (rpcsvc_request_t *req, dict_t *dict);
int
-glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata,
+glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata,
rpc_clnt_event_t event,
void *data);
int
@@ -211,8 +187,25 @@ int
glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret,
int32_t op_errno, char *hostname);
-
int
-glusterd_op_commit_send_resp (rpcsvc_request_t *req,
+glusterd_op_commit_send_resp (rpcsvc_request_t *req,
int32_t op, int32_t status);
+
+int
+glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname);
+
+int
+glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr);
+
+int
+glusterd_handle_cli_deprobe (rpcsvc_request_t *req);
+
+int
+glusterd_handle_incoming_unfriend_req (rpcsvc_request_t *req);
+
+int32_t
+glusterd_list_friends (rpcsvc_request_t *req, dict_t *dict, int32_t flags);
+
+int
+glusterd_handle_cli_list_friends (rpcsvc_request_t *req);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
index d377f09ac..1bd33ad1e 100644
--- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
+++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
@@ -43,26 +43,18 @@ extern glusterd_op_info_t opinfo;
int
glusterd_null (rpcsvc_request_t *req)
{
-/* gf_common_rsp rsp = {0,};
- rsp.gfs_id = req->gfs_id;
- //Accepted
- rsp.op_ret = 0;
-
- server_submit_reply (NULL, req, &rsp, NULL, 0, NULL,
- (gfs_serialize_t)xdr_serialize_common_rsp);
-*/
return 0;
}
int
-glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
+glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
{
gd1_mgmt_probe_rsp rsp = {{0},};
glusterd_conf_t *conf = NULL;
int ret = 0;
- char str[50];
+ char str[50] = {0,};
glusterd_peerinfo_t *peerinfo = NULL;
glusterd_peerinfo_t *dup_peerinfo = NULL;
glusterd_friend_sm_event_t *event = NULL;
@@ -82,8 +74,8 @@ glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
}
uuid_unparse (rsp.uuid, str);
- gf_log ("glusterd", GF_LOG_NORMAL,
- "Received probe resp from uuid: %s, host: %s",
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Received probe resp from uuid: %s, host: %s",
str, rsp.hostname);
ret = glusterd_friend_find (rsp.uuid, rsp.hostname, &peerinfo);
@@ -105,7 +97,7 @@ glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
GF_ASSERT (peerinfo->hostname);
uuid_copy (peerinfo->uuid, rsp.uuid);
- ret = glusterd_friend_sm_new_event
+ ret = glusterd_friend_sm_new_event
(GD_FRIEND_EVENT_INIT_FRIEND_REQ, &event);
if (ret) {
@@ -133,7 +125,7 @@ out:
}
int
-glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,
+glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,
int count, void *myframe)
{
gd1_mgmt_friend_rsp rsp = {{0},};
@@ -166,8 +158,8 @@ glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,
op_ret = rsp.op_ret;
op_errno = rsp.op_errno;
- gf_log ("glusterd", GF_LOG_NORMAL,
- "Received %s from uuid: %s, host: %s",
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Received %s from uuid: %s, host: %s",
(op_ret)?"RJT":"ACC", str, rsp.hostname);
ret = glusterd_friend_find (rsp.uuid, rsp.hostname, &peerinfo);
@@ -176,7 +168,7 @@ glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,
GF_ASSERT (0);
}
- if (op_ret)
+ if (op_ret)
event_type = GD_FRIEND_EVENT_RCVD_RJT;
else
event_type = GD_FRIEND_EVENT_RCVD_ACC;
@@ -199,7 +191,7 @@ glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,
GF_ASSERT (ctx);
- ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno,
+ ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno,
ctx->hostname);
if (!ret) {
glusterd_friend_sm ();
@@ -210,8 +202,93 @@ out:
return ret;
}
+int
+glusterd3_1_friend_remove_cbk (struct rpc_req * req, struct iovec *iov,
+ int count, void *myframe)
+{
+ gd1_mgmt_friend_rsp rsp = {{0},};
+ glusterd_conf_t *conf = NULL;
+ int ret = -1;
+ glusterd_friend_sm_event_t *event = NULL;
+ glusterd_friend_sm_event_type_t event_type = GD_FRIEND_EVENT_NONE;
+ glusterd_peerinfo_t *peerinfo = NULL;
+ char str[50] = {0,};
+ int32_t op_ret = -1;
+ int32_t op_errno = -1;
+ glusterd_probe_ctx_t *ctx = NULL;
+
+ conf = THIS->private;
+ GF_ASSERT (conf);
+
+ ctx = ((call_frame_t *)myframe)->local;
+ GF_ASSERT (ctx);
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto respond;
+ }
+
+ ret = gd_xdr_to_mgmt_friend_req (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto respond;
+ }
+ uuid_unparse (rsp.uuid, str);
+
+ op_ret = rsp.op_ret;
+ op_errno = rsp.op_errno;
+
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Received %s from uuid: %s, host: %s",
+ (op_ret)?"RJT":"ACC", str, rsp.hostname);
+
+ if (op_ret)
+ goto respond;
+
+ ret = glusterd_friend_find (rsp.uuid, rsp.hostname, &peerinfo);
+
+ if (ret) {
+ GF_ASSERT (0);
+ goto respond;
+ }
+
+ event_type = GD_FRIEND_EVENT_REMOVE_FRIEND;
+
+ ret = glusterd_friend_sm_new_event (event_type, &event);
+
+ if (ret) {
+ gf_log ("glusterd", GF_LOG_ERROR,
+ "Unable to get event");
+ goto respond;
+ }
+ event->peerinfo = peerinfo;
+
+ ret = glusterd_friend_sm_inject_event (event);
+
+ if (ret)
+ goto respond;
+
+ glusterd_friend_sm ();
+ glusterd_op_sm ();
+
+ return ret;
+
+respond:
+ ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno,
+ ctx->hostname);
+ if (!ret) {
+ glusterd_friend_sm ();
+ glusterd_op_sm ();
+ }
+
+ return ret;
+}
+
int32_t
-glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov,
+glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
{
gd1_mgmt_cluster_lock_rsp rsp = {{0},};
@@ -240,8 +317,8 @@ glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov,
op_ret = rsp.op_ret;
- gf_log ("glusterd", GF_LOG_NORMAL,
- "Received %s from uuid: %s",
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Received %s from uuid: %s",
(op_ret)?"RJT":"ACC", str);
ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo);
@@ -250,7 +327,7 @@ glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov,
GF_ASSERT (0);
}
- if (op_ret)
+ if (op_ret)
event_type = GD_OP_EVENT_RCVD_RJT;
else
event_type = GD_OP_EVENT_RCVD_ACC;
@@ -278,7 +355,7 @@ out:
}
int32_t
-glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov,
+glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
{
gd1_mgmt_cluster_lock_rsp rsp = {{0},};
@@ -308,8 +385,8 @@ glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov,
op_ret = rsp.op_ret;
- gf_log ("glusterd", GF_LOG_NORMAL,
- "Received %s from uuid: %s",
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Received %s from uuid: %s",
(op_ret)?"RJT":"ACC", str);
ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo);
@@ -318,7 +395,7 @@ glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov,
GF_ASSERT (0);
}
- if (op_ret)
+ if (op_ret)
event_type = GD_OP_EVENT_RCVD_RJT;
else
event_type = GD_OP_EVENT_RCVD_ACC;
@@ -346,7 +423,7 @@ out:
}
int32_t
-glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov,
+glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
{
gd1_mgmt_stage_op_rsp rsp = {{0},};
@@ -376,8 +453,8 @@ glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov,
op_ret = rsp.op_ret;
- gf_log ("glusterd", GF_LOG_NORMAL,
- "Received %s from uuid: %s",
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Received %s from uuid: %s",
(op_ret)?"RJT":"ACC", str);
ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo);
@@ -386,7 +463,7 @@ glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov,
GF_ASSERT (0);
}
- if (op_ret)
+ if (op_ret)
event_type = GD_OP_EVENT_RCVD_RJT;
else
event_type = GD_OP_EVENT_RCVD_ACC;
@@ -414,7 +491,7 @@ out:
}
int32_t
-glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov,
+glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
{
gd1_mgmt_commit_op_rsp rsp = {{0},};
@@ -444,8 +521,8 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov,
op_ret = rsp.op_ret;
- gf_log ("glusterd", GF_LOG_NORMAL,
- "Received %s from uuid: %s",
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Received %s from uuid: %s",
(op_ret)?"RJT":"ACC", str);
ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo);
@@ -454,7 +531,7 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov,
GF_ASSERT (0);
}
- if (op_ret)
+ if (op_ret)
event_type = GD_OP_EVENT_RCVD_RJT;
else
event_type = GD_OP_EVENT_RCVD_ACC;
@@ -484,7 +561,7 @@ out:
int32_t
-glusterd3_1_probe (call_frame_t *frame, xlator_t *this,
+glusterd3_1_probe (call_frame_t *frame, xlator_t *this,
void *data)
{
gd1_mgmt_probe_req req = {{0},};
@@ -508,7 +585,7 @@ glusterd3_1_probe (call_frame_t *frame, xlator_t *this,
if (ret) {
//We should not reach this state ideally
GF_ASSERT (0);
- goto out;
+ goto out;
}
uuid_copy (req.uuid, priv->uuid);
@@ -526,7 +603,7 @@ out:
int32_t
-glusterd3_1_friend_add (call_frame_t *frame, xlator_t *this,
+glusterd3_1_friend_add (call_frame_t *frame, xlator_t *this,
void *data)
{
gd1_mgmt_friend_req req = {{0},};
@@ -546,7 +623,7 @@ glusterd3_1_friend_add (call_frame_t *frame, xlator_t *this,
priv = this->private;
GF_ASSERT (priv);
-
+
ctx = event->ctx;
peerinfo = event->peerinfo;
@@ -565,7 +642,47 @@ out:
}
int32_t
-glusterd3_1_cluster_lock (call_frame_t *frame, xlator_t *this,
+glusterd3_1_friend_remove (call_frame_t *frame, xlator_t *this,
+ void *data)
+{
+ gd1_mgmt_friend_req req = {{0},};
+ int ret = 0;
+ glusterd_peerinfo_t *peerinfo = NULL;
+ glusterd_conf_t *priv = NULL;
+ glusterd_friend_sm_event_t *event = NULL;
+ glusterd_friend_req_ctx_t *ctx = NULL;
+
+
+ if (!frame || !this || !data) {
+ ret = -1;
+ goto out;
+ }
+
+ event = data;
+ priv = this->private;
+
+ GF_ASSERT (priv);
+
+ ctx = event->ctx;
+
+ peerinfo = event->peerinfo;
+
+ uuid_copy (req.uuid, priv->uuid);
+ req.hostname = peerinfo->hostname;
+
+ ret = glusterd_submit_request (peerinfo, &req, frame, priv->mgmt,
+ GD_MGMT_FRIEND_REMOVE,
+ NULL, gd_xdr_from_mgmt_friend_req,
+ this, glusterd3_1_friend_remove_cbk);
+
+out:
+ gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+
+int32_t
+glusterd3_1_cluster_lock (call_frame_t *frame, xlator_t *this,
void *data)
{
gd1_mgmt_cluster_lock_req req = {{0},};
@@ -587,7 +704,7 @@ glusterd3_1_cluster_lock (call_frame_t *frame, xlator_t *this,
list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
GF_ASSERT (peerinfo);
- if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
+ if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
continue;
dummy_frame = create_frame (this, this->ctx->pool);
@@ -595,9 +712,9 @@ glusterd3_1_cluster_lock (call_frame_t *frame, xlator_t *this,
if (!dummy_frame)
continue;
- ret = glusterd_submit_request (peerinfo, &req, dummy_frame,
+ ret = glusterd_submit_request (peerinfo, &req, dummy_frame,
priv->mgmt, GD_MGMT_CLUSTER_LOCK,
- NULL,
+ NULL,
gd_xdr_from_mgmt_cluster_lock_req,
this, glusterd3_1_cluster_lock_cbk);
if (!ret)
@@ -615,7 +732,7 @@ out:
}
int32_t
-glusterd3_1_cluster_unlock (call_frame_t *frame, xlator_t *this,
+glusterd3_1_cluster_unlock (call_frame_t *frame, xlator_t *this,
void *data)
{
gd1_mgmt_cluster_lock_req req = {{0},};
@@ -638,7 +755,7 @@ glusterd3_1_cluster_unlock (call_frame_t *frame, xlator_t *this,
list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
GF_ASSERT (peerinfo);
- if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
+ if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
continue;
dummy_frame = create_frame (this, this->ctx->pool);
@@ -646,9 +763,9 @@ glusterd3_1_cluster_unlock (call_frame_t *frame, xlator_t *this,
if (!dummy_frame)
continue;
- ret = glusterd_submit_request (peerinfo, &req, dummy_frame,
+ ret = glusterd_submit_request (peerinfo, &req, dummy_frame,
priv->mgmt, GD_MGMT_CLUSTER_UNLOCK,
- NULL,
+ NULL,
gd_xdr_from_mgmt_cluster_unlock_req,
this, glusterd3_1_cluster_unlock_cbk);
if (!ret)
@@ -667,7 +784,7 @@ out:
}
int32_t
-glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this,
+glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this,
void *data)
{
gd1_mgmt_stage_op_req *req = NULL;
@@ -697,13 +814,13 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this,
//No pending ops, inject stage_acc
glusterd_op_sm_event_t *event = NULL;
-
- ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC,
+
+ ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC,
&event);
if (ret)
goto out;
-
+
ret = glusterd_op_sm_inject_event (event);
return ret;
@@ -718,7 +835,7 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this,
list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
GF_ASSERT (peerinfo);
- if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
+ if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
continue;
dummy_frame = create_frame (this, this->ctx->pool);
@@ -726,14 +843,14 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this,
if (!dummy_frame)
continue;
- ret = glusterd_submit_request (peerinfo, req, dummy_frame,
+ ret = glusterd_submit_request (peerinfo, req, dummy_frame,
priv->mgmt, GD_MGMT_STAGE_OP,
- NULL,
+ NULL,
gd_xdr_from_mgmt_stage_op_req,
this, glusterd3_1_stage_op_cbk);
if (!ret)
pending_peer++;
- //TODO: Instead of keeping count, maintain a list of pending
+ //TODO: Instead of keeping count, maintain a list of pending
//UUIDs.
}
@@ -747,7 +864,7 @@ out:
}
int32_t
-glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this,
+glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this,
void *data)
{
gd1_mgmt_commit_op_req *req = NULL;
@@ -777,13 +894,13 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this,
//No pending ops, inject stage_acc
glusterd_op_sm_event_t *event = NULL;
-
- ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC,
+
+ ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC,
&event);
if (ret)
goto out;
-
+
ret = glusterd_op_sm_inject_event (event);
return ret;
@@ -798,7 +915,7 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this,
list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
GF_ASSERT (peerinfo);
- if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
+ if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)
continue;
dummy_frame = create_frame (this, this->ctx->pool);
@@ -806,14 +923,14 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this,
if (!dummy_frame)
continue;
- ret = glusterd_submit_request (peerinfo, req, dummy_frame,
+ ret = glusterd_submit_request (peerinfo, req, dummy_frame,
priv->mgmt, GD_MGMT_COMMIT_OP,
- NULL,
+ NULL,
gd_xdr_from_mgmt_commit_op_req,
this, glusterd3_1_commit_op_cbk);
if (!ret)
pending_peer++;
- //TODO: Instead of keeping count, maintain a list of pending
+ //TODO: Instead of keeping count, maintain a list of pending
//UUIDs.
}
@@ -869,6 +986,18 @@ glusterd_handle_rpc_msg (rpcsvc_request_t *req)
ret = glusterd_handle_create_volume (req);
break;
+ case GD_MGMT_CLI_DEPROBE:
+ ret = glusterd_handle_cli_deprobe (req);
+ break;
+
+ case GD_MGMT_FRIEND_REMOVE:
+ ret = glusterd_handle_incoming_unfriend_req (req);
+ break;
+
+ case GD_MGMT_CLI_LIST_FRIENDS:
+ ret = glusterd_handle_cli_list_friends (req);
+ break;
+
default:
GF_ASSERT (0);
}
@@ -884,20 +1013,23 @@ glusterd_handle_rpc_msg (rpcsvc_request_t *req)
rpcsvc_actor_t glusterd1_mgmt_actors[] = {
[GD_MGMT_NULL] = { "NULL", GD_MGMT_NULL, glusterd_null, NULL, NULL},
- [GD_MGMT_PROBE_QUERY] = { "PROBE_QUERY", GD_MGMT_PROBE_QUERY, glusterd_handle_rpc_msg, NULL, NULL},
- [GD_MGMT_FRIEND_ADD] = { "FRIEND_ADD", GD_MGMT_FRIEND_ADD, glusterd_handle_rpc_msg, NULL, NULL},
+ [GD_MGMT_PROBE_QUERY] = { "PROBE_QUERY", GD_MGMT_PROBE_QUERY, glusterd_handle_rpc_msg, NULL, NULL},
+ [GD_MGMT_FRIEND_ADD] = { "FRIEND_ADD", GD_MGMT_FRIEND_ADD, glusterd_handle_rpc_msg, NULL, NULL},
+ [GD_MGMT_FRIEND_REMOVE] = { "FRIEND_REMOVE", GD_MGMT_FRIEND_REMOVE, glusterd_handle_rpc_msg, NULL, NULL},
[GD_MGMT_CLUSTER_LOCK] = { "CLUSTER_LOCK", GD_MGMT_CLUSTER_LOCK, glusterd_handle_rpc_msg, NULL, NULL},
[GD_MGMT_CLUSTER_UNLOCK] = { "CLUSTER_UNLOCK", GD_MGMT_CLUSTER_UNLOCK, glusterd_handle_rpc_msg, NULL, NULL},
[GD_MGMT_STAGE_OP] = { "STAGE_OP", GD_MGMT_STAGE_OP, glusterd_handle_rpc_msg, NULL, NULL},
[GD_MGMT_COMMIT_OP] = { "COMMIT_OP", GD_MGMT_COMMIT_OP, glusterd_handle_rpc_msg, NULL, NULL},
[GD_MGMT_CLI_PROBE] = { "CLI_PROBE", GD_MGMT_CLI_PROBE, glusterd_handle_rpc_msg, NULL, NULL},
[GD_MGMT_CLI_CREATE_VOLUME] = { "CLI_CREATE_VOLUME", GD_MGMT_CLI_CREATE_VOLUME, glusterd_handle_rpc_msg, NULL, NULL},
+ [GD_MGMT_CLI_DEPROBE] = { "FRIEND_REMOVE", GD_MGMT_CLI_DEPROBE, glusterd_handle_rpc_msg, NULL, NULL},
+ [GD_MGMT_CLI_LIST_FRIENDS] = { "LIST_FRIENDS", GD_MGMT_CLI_LIST_FRIENDS, glusterd_handle_rpc_msg, NULL, NULL},
};
/*rpcsvc_actor_t glusterd1_mgmt_actors[] = {
[GD_MGMT_NULL] = { "NULL", GD_MGMT_NULL, glusterd_null, NULL, NULL},
- [GD_MGMT_PROBE_QUERY] = { "PROBE_QUERY", GD_MGMT_PROBE_QUERY, glusterd_handle_probe_query, NULL, NULL},
- [GD_MGMT_FRIEND_ADD] = { "FRIEND_ADD", GD_MGMT_FRIEND_ADD, glusterd_handle_incoming_friend_req, NULL, NULL},
+ [GD_MGMT_PROBE_QUERY] = { "PROBE_QUERY", GD_MGMT_PROBE_QUERY, glusterd_handle_probe_query, NULL, NULL},
+ [GD_MGMT_FRIEND_ADD] = { "FRIEND_ADD", GD_MGMT_FRIEND_ADD, glusterd_handle_incoming_friend_req, NULL, NULL},
[GD_MGMT_CLUSTER_LOCK] = { "CLUSTER_LOCK", GD_MGMT_CLUSTER_LOCK, glusterd_handle_cluster_lock, NULL, NULL},
[GD_MGMT_CLUSTER_UNLOCK] = { "CLUSTER_UNLOCK", GD_MGMT_CLUSTER_UNLOCK, glusterd_handle_cluster_unlock, NULL, NULL},
[GD_MGMT_STAGE_OP] = { "STAGE_OP", GD_MGMT_STAGE_OP, glusterd_handle_stage_op, NULL, NULL},
@@ -924,6 +1056,7 @@ struct rpc_clnt_procedure glusterd3_1_clnt_mgmt_actors[GD_MGMT_MAXVALUE] = {
[GD_MGMT_CLUSTER_UNLOCK] = {"CLUSTER_UNLOCK", glusterd3_1_cluster_unlock},
[GD_MGMT_STAGE_OP] = {"STAGE_OP", glusterd3_1_stage_op},
[GD_MGMT_COMMIT_OP] = {"COMMIT_OP", glusterd3_1_commit_op},
+ [GD_MGMT_FRIEND_REMOVE] = { "FRIEND_REMOVE", glusterd3_1_friend_remove},
// [GF_FOP_GETSPEC] = { "GETSPEC", client_getspec, client_getspec_cbk },
};