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