From c8dc7456ed67a17aaaaba129089928b9f4b73225 Mon Sep 17 00:00:00 2001
From: Jeff Darcy <jdarcy@redhat.com>
Date: Thu, 9 Mar 2017 12:49:27 -0500
Subject: [PATCH 352/361] glusterfsd+libglusterfs: add null checks during
attach
It's possible (though unlikely) that we could get a brick-attach
request while we're not ready to process it (ctx->active not set yet).
Add code to guard against this possibility, and return appropriate
error indicators.
mainline:
> BUG: 1430860
> Reviewed-on: https://review.gluster.org/16883
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
(cherry picked from commit bd690f084bdf93393bb47b09e9b333244b5602e8)
BUG: 1417815
Change-Id: Icb3bc52ce749258a3f03cbbbdf4c2320c5c541a0
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/101328
Tested-by: Milind Changire <mchangir@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
glusterfsd/src/glusterfsd-mgmt.c | 27 ++++++++++++++++++---------
libglusterfs/src/graph.c | 4 ++++
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
index 0dfa505..9a7ed0d 100644
--- a/glusterfsd/src/glusterfsd-mgmt.c
+++ b/glusterfsd/src/glusterfsd-mgmt.c
@@ -817,9 +817,9 @@ out:
int
glusterfs_handle_attach (rpcsvc_request_t *req)
{
- int32_t ret = -1;
- gd1_mgmt_brick_op_req xlator_req = {0,};
- xlator_t *this = NULL;
+ int32_t ret = -1;
+ gd1_mgmt_brick_op_req xlator_req = {0,};
+ xlator_t *this = NULL;
GF_ASSERT (req);
this = THIS;
@@ -831,15 +831,24 @@ glusterfs_handle_attach (rpcsvc_request_t *req)
if (ret < 0) {
/*failed to decode msg;*/
req->rpc_err = GARBAGE_ARGS;
- goto out;
+ return -1;
}
- gf_log (this->name, GF_LOG_INFO, "got attach for %s", xlator_req.name);
- glusterfs_graph_attach (this->ctx->active, xlator_req.name);
- glusterfs_autoscale_threads (this->ctx, 1);
+ if (this->ctx->active) {
+ gf_log (this->name, GF_LOG_INFO,
+ "got attach for %s", xlator_req.name);
+ ret = glusterfs_graph_attach (this->ctx->active,
+ xlator_req.name);
+ if (ret == 0) {
+ glusterfs_autoscale_threads (this->ctx, 1);
+ }
+ } else {
+ gf_log (this->name, GF_LOG_WARNING,
+ "got attach for %s but no active graph",
+ xlator_req.name);
+ }
-out:
- glusterfs_translator_info_response_send (req, 0, NULL, NULL);
+ glusterfs_translator_info_response_send (req, ret, NULL, NULL);
free (xlator_req.input.input_val);
free (xlator_req.name);
diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c
index b090f8a..254eb0c 100644
--- a/libglusterfs/src/graph.c
+++ b/libglusterfs/src/graph.c
@@ -1039,6 +1039,10 @@ glusterfs_graph_attach (glusterfs_graph_t *orig_graph, char *path)
xlator_t *xl;
char *volfile_id;
+ if (!orig_graph) {
+ return -EINVAL;
+ }
+
fp = fopen (path, "r");
if (!fp) {
gf_log (THIS->name, GF_LOG_WARNING,
--
1.8.3.1