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