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