74b1de
From f90df1167bc70c634ba33c181232321da6770709 Mon Sep 17 00:00:00 2001
74b1de
From: Raghavendra Bhat <raghavendra@redhat.com>
74b1de
Date: Tue, 25 Jun 2019 10:51:33 -0400
74b1de
Subject: [PATCH 256/261] features/snapview-server: use the same volfile server
74b1de
 for gfapi options
74b1de
74b1de
snapview server xlator makes use of "localhost" as the volfile server while
74b1de
initing the new glfs instance to talk to a snapshot. While localhost is fine,
74b1de
better use the same volfile server that was used to start the snapshot
74b1de
daemon containing the snapview-server xlator.
74b1de
74b1de
Upstream Patch:
74b1de
>Change-Id: I4485d39b0e3d066f481adc6958ace53ea33237f7
74b1de
>fixes: bz#1725211
74b1de
>Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
74b1de
> patch: https://review.gluster.org/#/c/glusterfs/+/22974/
74b1de
74b1de
BUG: 1722757
74b1de
Change-Id: I4485d39b0e3d066f481adc6958ace53ea33237f7
74b1de
Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
74b1de
Reviewed-on: https://code.engineering.redhat.com/gerrit/175984
74b1de
Tested-by: RHGS Build Bot <nigelb@redhat.com>
74b1de
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
74b1de
---
74b1de
 .../snapview-server/src/snapview-server-helpers.c  | 44 ++++++++++++++++++++--
74b1de
 .../snapview-server/src/snapview-server-messages.h |  2 +-
74b1de
 2 files changed, 42 insertions(+), 4 deletions(-)
74b1de
74b1de
diff --git a/xlators/features/snapview-server/src/snapview-server-helpers.c b/xlators/features/snapview-server/src/snapview-server-helpers.c
74b1de
index 5514a54..62c1dda 100644
74b1de
--- a/xlators/features/snapview-server/src/snapview-server-helpers.c
74b1de
+++ b/xlators/features/snapview-server/src/snapview-server-helpers.c
74b1de
@@ -476,6 +476,7 @@ __svs_initialise_snapshot_volume(xlator_t *this, const char *name,
74b1de
     char logfile[PATH_MAX] = {
74b1de
         0,
74b1de
     };
74b1de
+    char *volfile_server = NULL;
74b1de
 
74b1de
     GF_VALIDATE_OR_GOTO("snapview-server", this, out);
74b1de
     GF_VALIDATE_OR_GOTO(this->name, this->private, out);
74b1de
@@ -512,14 +513,50 @@ __svs_initialise_snapshot_volume(xlator_t *this, const char *name,
74b1de
         goto out;
74b1de
     }
74b1de
 
74b1de
-    ret = glfs_set_volfile_server(fs, "tcp", "localhost", 24007);
74b1de
+    /*
74b1de
+     * Before, localhost was used as the volfile server. But, with that
74b1de
+     * method, accessing snapshots started giving ENOENT error if a
74b1de
+     * specific bind address is mentioned in the glusterd volume file.
74b1de
+     * Check the bug https://bugzilla.redhat.com/show_bug.cgi?id=1725211.
74b1de
+     * So, the new method is tried below, where, snapview-server first
74b1de
+     * uses the volfile server used by the snapd (obtained from the
74b1de
+     * command line arguments saved in the global context of the process).
74b1de
+     * If the volfile server in global context is NULL, then localhost
74b1de
+     * is tried (like before).
74b1de
+     */
74b1de
+    if (this->ctx->cmd_args.volfile_server) {
74b1de
+        volfile_server = gf_strdup(this->ctx->cmd_args.volfile_server);
74b1de
+        if (!volfile_server) {
74b1de
+            gf_msg(this->name, GF_LOG_WARNING, ENOMEM,
74b1de
+                   SVS_MSG_VOLFILE_SERVER_GET_FAIL,
74b1de
+                   "failed to copy volfile server %s. ",
74b1de
+                   this->ctx->cmd_args.volfile_server);
74b1de
+            ret = -1;
74b1de
+            goto out;
74b1de
+        }
74b1de
+    } else {
74b1de
+        gf_msg(this->name, GF_LOG_WARNING, ENOMEM,
74b1de
+               SVS_MSG_VOLFILE_SERVER_GET_FAIL,
74b1de
+               "volfile server is NULL in cmd args. "
74b1de
+               "Trying with localhost");
74b1de
+        volfile_server = gf_strdup("localhost");
74b1de
+        if (!volfile_server) {
74b1de
+            gf_msg(this->name, GF_LOG_WARNING, ENOMEM,
74b1de
+                   SVS_MSG_VOLFILE_SERVER_GET_FAIL,
74b1de
+                   "failed to copy volfile server localhost.");
74b1de
+            ret = -1;
74b1de
+            goto out;
74b1de
+        }
74b1de
+    }
74b1de
+
74b1de
+    ret = glfs_set_volfile_server(fs, "tcp", volfile_server, 24007);
74b1de
     if (ret) {
74b1de
         gf_msg(this->name, GF_LOG_ERROR, local_errno,
74b1de
                SVS_MSG_SET_VOLFILE_SERVR_FAILED,
74b1de
                "setting the "
74b1de
-               "volfile server for snap volume %s "
74b1de
+               "volfile server %s for snap volume %s "
74b1de
                "failed",
74b1de
-               dirent->name);
74b1de
+               volfile_server, dirent->name);
74b1de
         goto out;
74b1de
     }
74b1de
 
74b1de
@@ -561,6 +598,7 @@ out:
74b1de
         dirent->fs = fs;
74b1de
     }
74b1de
 
74b1de
+    GF_FREE(volfile_server);
74b1de
     return fs;
74b1de
 }
74b1de
 
74b1de
diff --git a/xlators/features/snapview-server/src/snapview-server-messages.h b/xlators/features/snapview-server/src/snapview-server-messages.h
74b1de
index 8548015..f634ab5 100644
74b1de
--- a/xlators/features/snapview-server/src/snapview-server-messages.h
74b1de
+++ b/xlators/features/snapview-server/src/snapview-server-messages.h
74b1de
@@ -49,6 +49,6 @@ GLFS_MSGID(SNAPVIEW_SERVER, SVS_MSG_NO_MEMORY, SVS_MSG_MEM_ACNT_FAILED,
74b1de
            SVS_MSG_CLOSEDIR_FAILED, SVS_MSG_CLOSE_FAILED,
74b1de
            SVS_MSG_GFID_GEN_FAILED, SVS_MSG_GLFS_NEW_FAILED,
74b1de
            SVS_MSG_SET_VOLFILE_SERVR_FAILED, SVS_MSG_SET_LOGGING_FAILED,
74b1de
-           SVS_MSG_GLFS_INIT_FAILED);
74b1de
+           SVS_MSG_VOLFILE_SERVER_GET_FAIL, SVS_MSG_GLFS_INIT_FAILED);
74b1de
 
74b1de
 #endif /* !_SNAPVIEW_CLIENT_MESSAGES_H_ */
74b1de
-- 
74b1de
1.8.3.1
74b1de