diff options
author | Amar Tumballi <amar@gluster.com> | 2011-03-03 05:47:33 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2011-03-04 00:41:00 -0800 |
commit | 8f132b363d41e7fe94a8712ed297a5f810e8ed56 (patch) | |
tree | 18cd6c294c0eb585ca1ac4da479f79f2926b162c | |
parent | 568d4027033a5cb89d6aaee757d4c71e5369fe25 (diff) |
glusterd: check for the variable before dereferencing it
check if 'peerinfo->mgmt' is set (ie, handshake is completed), before
sending any request to that peer.
Signed-off-by: Amar Tumballi <amar@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 2486 ([glusterfs-3.1.3qa2]: Core generated due to SegFault in glusterd_sm.c)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2486
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handshake.c | 25 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 8 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-sm.c | 21 |
3 files changed, 32 insertions, 22 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c index c3af04b2a78..d364339a671 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handshake.c +++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c @@ -292,10 +292,6 @@ glusterd_set_clnt_mgmt_program (glusterd_peerinfo_t *peerinfo, if ((gd_clnt_mgmt_prog.prognum == trav->prognum) && (gd_clnt_mgmt_prog.progver == trav->progver)) { peerinfo->mgmt = &gd_clnt_mgmt_prog; - gf_log ("", GF_LOG_INFO, - "Using Program %s, Num (%"PRId64"), " - "Version (%"PRId64")", - trav->progname, trav->prognum, trav->progver); ret = 0; /* Break here, as this gets higher priority */ break; @@ -303,20 +299,24 @@ glusterd_set_clnt_mgmt_program (glusterd_peerinfo_t *peerinfo, if ((glusterd3_1_mgmt_prog.prognum == trav->prognum) && (glusterd3_1_mgmt_prog.progver == trav->progver)) { peerinfo->mgmt = &glusterd3_1_mgmt_prog; - gf_log ("", GF_LOG_INFO, - "Using Program %s, Num (%"PRId64"), " - "Version (%"PRId64")", - trav->progname, trav->prognum, trav->progver); ret = 0; } if (ret) { - gf_log ("", GF_LOG_TRACE, - "%s (%"PRId64") not supported", trav->progname, + gf_log ("", GF_LOG_DEBUG, + "%s (%"PRId64":%"PRId64") not supported", + trav->progname, trav->prognum, trav->progver); } trav = trav->next; } + if (!ret && peerinfo->mgmt) { + gf_log ("", GF_LOG_INFO, + "Using Program %s, Num (%d), Version (%d)", + peerinfo->mgmt->progname, peerinfo->mgmt->prognum, + peerinfo->mgmt->progver); + } + out: return ret; } @@ -370,6 +370,9 @@ glusterd_peer_dump_version_cbk (struct rpc_req *req, struct iovec *iov, peerctx->args.req = NULL; } else if (GD_MODE_SWITCH_ON == peerctx->args.mode) { peerctx->args.mode = GD_MODE_ON; + } else { + gf_log ("", GF_LOG_WARNING, "unknown mode %d", + peerctx->args.mode); } glusterd_friend_sm (); @@ -405,7 +408,7 @@ glusterd_peer_handshake (xlator_t *this, struct rpc_clnt *rpc, { call_frame_t *frame = NULL; gf_dump_req req = {0,}; - int ret = 0; + int ret = -1; frame = create_frame (this, this->ctx->pool); if (!frame) diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index fc8f86ac8a3..c994db40c12 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -4609,7 +4609,7 @@ glusterd_op_ac_send_lock (glusterd_op_sm_event_t *event, void *ctx) (glusterd_op_get_op() != GD_OP_SYNC_VOLUME)) continue; - proc = &peerinfo->mgmt->proctable[GD_MGMT_CLUSTER_LOCK]; + proc = &peerinfo->mgmt->proctable[GLUSTERD_MGMT_CLUSTER_LOCK]; if (proc->fn) { ret = proc->fn (NULL, this, peerinfo); if (ret) @@ -4654,7 +4654,7 @@ glusterd_op_ac_send_unlock (glusterd_op_sm_event_t *event, void *ctx) (glusterd_op_get_op() != GD_OP_SYNC_VOLUME)) continue; - proc = &peerinfo->mgmt->proctable[GD_MGMT_CLUSTER_UNLOCK]; + proc = &peerinfo->mgmt->proctable[GLUSTERD_MGMT_CLUSTER_UNLOCK]; if (proc->fn) { ret = proc->fn (NULL, this, peerinfo); if (ret) @@ -4868,7 +4868,7 @@ glusterd_op_ac_send_stage_op (glusterd_op_sm_event_t *event, void *ctx) (glusterd_op_get_op() != GD_OP_SYNC_VOLUME)) continue; - proc = &peerinfo->mgmt->proctable[GD_MGMT_STAGE_OP]; + proc = &peerinfo->mgmt->proctable[GLUSTERD_MGMT_STAGE_OP]; GF_ASSERT (proc); if (proc->fn) { ret = dict_set_static_ptr (dict, "peerinfo", peerinfo); @@ -4989,7 +4989,7 @@ glusterd_op_ac_send_commit_op (glusterd_op_sm_event_t *event, void *ctx) (glusterd_op_get_op() != GD_OP_SYNC_VOLUME)) continue; - proc = &peerinfo->mgmt->proctable[GD_MGMT_COMMIT_OP]; + proc = &peerinfo->mgmt->proctable[GLUSTERD_MGMT_COMMIT_OP]; GF_ASSERT (proc); if (proc->fn) { ret = dict_set_static_ptr (dict, "peerinfo", peerinfo); diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c index bcab9291127..d245e0f2e04 100644 --- a/xlators/mgmt/glusterd/src/glusterd-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-sm.c @@ -165,7 +165,7 @@ glusterd_broadcast_friend_delete (char *hostname, uuid_t uuid) goto out; list_for_each_entry (peerinfo, &priv->peers, uuid_list) { - if (!peerinfo->connected) + if (!peerinfo->connected || !peerinfo->mgmt) continue; ret = dict_set_static_ptr (friends, "peerinfo", peerinfo); @@ -173,7 +173,8 @@ glusterd_broadcast_friend_delete (char *hostname, uuid_t uuid) gf_log ("", GF_LOG_ERROR, "failed to set peerinfo"); goto out; } - proc = &peerinfo->mgmt->proctable[GD_MGMT_FRIEND_UPDATE]; + + proc = &peerinfo->mgmt->proctable[GLUSTERD_MGMT_FRIEND_UPDATE]; if (proc->fn) { ret = proc->fn (NULL, this, friends); } @@ -282,7 +283,9 @@ glusterd_ac_friend_add (glusterd_friend_sm_event_t *event, void *ctx) GF_ASSERT (conf); - proc = &peerinfo->mgmt->proctable[GD_MGMT_FRIEND_ADD]; + if (!peerinfo->mgmt) + goto out; + proc = &peerinfo->mgmt->proctable[GLUSTERD_MGMT_FRIEND_ADD]; if (proc->fn) { frame = create_frame (this, this->ctx->pool); if (!frame) { @@ -329,7 +332,9 @@ glusterd_ac_friend_probe (glusterd_friend_sm_event_t *event, void *ctx) goto out; } - proc = &peerinfo->mgmt->proctable[GD_MGMT_PROBE_QUERY]; + if (!peerinfo->mgmt) + goto out; + proc = &peerinfo->mgmt->proctable[GLUSTERD_MGMT_PROBE_QUERY]; if (proc->fn) { frame = create_frame (this, this->ctx->pool); if (!frame) { @@ -418,7 +423,9 @@ glusterd_ac_send_friend_remove_req (glusterd_friend_sm_event_t *event, goto out; } - proc = &peerinfo->mgmt->proctable[GD_MGMT_FRIEND_REMOVE]; + if (!peerinfo->mgmt) + goto out; + proc = &peerinfo->mgmt->proctable[GLUSTERD_MGMT_FRIEND_REMOVE]; if (proc->fn) { frame = create_frame (this, this->ctx->pool); if (!frame) { @@ -487,7 +494,7 @@ glusterd_ac_send_friend_update (glusterd_friend_sm_event_t *event, void *ctx) goto out; list_for_each_entry (peerinfo, &priv->peers, uuid_list) { - if (!peerinfo->connected) + if (!peerinfo->connected || !peerinfo->mgmt) continue; ret = dict_set_static_ptr (friends, "peerinfo", peerinfo); @@ -496,7 +503,7 @@ glusterd_ac_send_friend_update (glusterd_friend_sm_event_t *event, void *ctx) goto out; } - proc = &peerinfo->mgmt->proctable[GD_MGMT_FRIEND_UPDATE]; + proc = &peerinfo->mgmt->proctable[GLUSTERD_MGMT_FRIEND_UPDATE]; if (proc->fn) { ret = proc->fn (NULL, this, friends); } |