887953
From 647b4d4e8edefd256de2a9f3916763b8cfa8429b Mon Sep 17 00:00:00 2001
887953
From: Atin Mukherjee <amukherj@redhat.com>
887953
Date: Tue, 20 Nov 2018 12:32:32 +0530
887953
Subject: [PATCH 467/493] glusterd: glusterd to regenerate volfiles when
887953
 GD_OP_VERSION_MAX changes
887953
887953
While glusterd has an infra to allow post install of spec to bring it up
887953
in the interim upgrade mode to allow all the volfiles to be regenerated
887953
with the latest executable, in container world the same methodology is
887953
not followed as container image always point to the specific gluster rpm
887953
and gluster rpm doesn't go through an upgrade process.
887953
887953
This fix does the following:
887953
1. If glusterd.upgrade file doesn't exist, regenerate the volfiles
887953
2. If maximum-operating-version read from glusterd.upgrade doesn't match
887953
with GD_OP_VERSION_MAX, glusterd detects it to be a version where new
887953
options are introduced and regenerate the volfiles.
887953
887953
Tests done:
887953
887953
1. Bring up glusterd, check if glusterd.upgrade file has been created
887953
with GD_OP_VERSION_MAX value.
887953
2. Post 1, restart glusterd and check glusterd hasn't regenerated the
887953
volfiles as there's is no change in the GD_OP_VERSION_MAX vs the
887953
op_version read from the file.
887953
3. Bump up the GD_OP_VERSION_MAX in the code by 1 and post compilation
887953
restart glusterd where the volfiles should be again regenerated.
887953
887953
Note: The old way of having volfiles regenerated during an rpm upgrade
887953
is kept as it is for now but eventually this can be sunset later.
887953
887953
> Change-Id: I75b49a1601c71e99f6a6bc360dd12dd03a96414b
887953
> Fixes: bz#1651463
887953
> Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
887953
887953
upstream patch: https://review.gluster.org/#/c/glusterfs/+/21687/
887953
887953
Change-Id: I75b49a1601c71e99f6a6bc360dd12dd03a96414b
887953
BUG: 1651460
887953
Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
887953
Reviewed-on: https://code.engineering.redhat.com/gerrit/158645
887953
Tested-by: RHGS Build Bot <nigelb@redhat.com>
887953
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
887953
---
887953
 xlators/mgmt/glusterd/src/glusterd-store.c | 126 +++++++++++++++++++++++++++--
887953
 xlators/mgmt/glusterd/src/glusterd-store.h |   6 ++
887953
 xlators/mgmt/glusterd/src/glusterd.c       |  27 +++++--
887953
 xlators/mgmt/glusterd/src/glusterd.h       |   7 ++
887953
 4 files changed, 154 insertions(+), 12 deletions(-)
887953
887953
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
887953
index 37542e7..f276fef 100644
887953
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
887953
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
887953
@@ -2063,7 +2063,7 @@ glusterd_store_global_info (xlator_t *this)
887953
         }
887953
 
887953
         handle->fd = gf_store_mkstemp (handle);
887953
-        if (handle->fd <= 0) {
887953
+        if (handle->fd < 0) {
887953
                 ret = -1;
887953
                 goto out;
887953
         }
887953
@@ -2081,7 +2081,7 @@ glusterd_store_global_info (xlator_t *this)
887953
                 goto out;
887953
         }
887953
 
887953
-        snprintf (op_version_str, 15, "%d", conf->op_version);
887953
+        snprintf (op_version_str, sizeof(op_version_str), "%d", conf->op_version);
887953
         ret = gf_store_save_value (handle->fd, GD_OP_VERSION_KEY,
887953
                                    op_version_str);
887953
         if (ret) {
887953
@@ -2094,12 +2094,8 @@ glusterd_store_global_info (xlator_t *this)
887953
         ret = gf_store_rename_tmppath (handle);
887953
 out:
887953
         if (handle) {
887953
-                if (ret && (handle->fd > 0))
887953
+                if (ret && (handle->fd >= 0))
887953
                         gf_store_unlink_tmppath (handle);
887953
-
887953
-                if (handle->fd > 0) {
887953
-                        handle->fd = 0;
887953
-                }
887953
         }
887953
 
887953
         if (uuid_str)
887953
@@ -2114,6 +2110,122 @@ out:
887953
 }
887953
 
887953
 int
887953
+glusterd_store_max_op_version(xlator_t *this)
887953
+{
887953
+        int ret = -1;
887953
+        glusterd_conf_t *conf = NULL;
887953
+        char op_version_str[15] = {0,};
887953
+        char path[PATH_MAX] = {0,};
887953
+        gf_store_handle_t *handle = NULL;
887953
+        int32_t len = 0;
887953
+
887953
+        conf = this->private;
887953
+
887953
+        len = snprintf(path, PATH_MAX, "%s/%s", conf->workdir,
887953
+                       GLUSTERD_UPGRADE_FILE);
887953
+        if ((len < 0) || (len >= PATH_MAX)) {
887953
+                goto out;
887953
+        }
887953
+        ret = gf_store_handle_new(path, &handle);
887953
+        if (ret) {
887953
+                gf_msg(this->name, GF_LOG_ERROR, 0,
887953
+                       GD_MSG_STORE_HANDLE_GET_FAIL, "Unable to get store "
887953
+                       "handle");
887953
+                goto out;
887953
+        }
887953
+
887953
+        /* These options need to be available for all users */
887953
+        ret = sys_chmod(handle->path, 0644);
887953
+        if (ret) {
887953
+                gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
887953
+                       "chmod error for %s", GLUSTERD_UPGRADE_FILE);
887953
+                goto out;
887953
+        }
887953
+
887953
+        handle->fd = gf_store_mkstemp(handle);
887953
+        if (handle->fd < 0) {
887953
+                ret = -1;
887953
+                goto out;
887953
+        }
887953
+
887953
+        snprintf(op_version_str, sizeof(op_version_str), "%d",
887953
+                 GD_OP_VERSION_MAX);
887953
+        ret = gf_store_save_value(handle->fd, GD_MAX_OP_VERSION_KEY,
887953
+                                  op_version_str);
887953
+        if (ret) {
887953
+                gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_OP_VERS_STORE_FAIL,
887953
+                       "Storing op-version failed ret = %d", ret);
887953
+                goto out;
887953
+        }
887953
+
887953
+        ret = gf_store_rename_tmppath(handle);
887953
+out:
887953
+        if (handle) {
887953
+                if (ret && (handle->fd >= 0))
887953
+                        gf_store_unlink_tmppath(handle);
887953
+        }
887953
+
887953
+        if (ret)
887953
+                gf_msg(this->name, GF_LOG_ERROR, 0,
887953
+                       GD_MSG_GLUSTERD_GLOBAL_INFO_STORE_FAIL,
887953
+                       "Failed to store max op-version");
887953
+        if (handle)
887953
+                gf_store_handle_destroy(handle);
887953
+        return ret;
887953
+}
887953
+
887953
+int
887953
+glusterd_retrieve_max_op_version(xlator_t *this, int *op_version)
887953
+{
887953
+        char *op_version_str = NULL;
887953
+        glusterd_conf_t *priv = NULL;
887953
+        int ret = -1;
887953
+        int tmp_version = 0;
887953
+        char *tmp = NULL;
887953
+        char path[PATH_MAX] = {0,};
887953
+        gf_store_handle_t *handle = NULL;
887953
+        int32_t len = 0;
887953
+
887953
+        priv = this->private;
887953
+
887953
+        len = snprintf(path, PATH_MAX, "%s/%s", priv->workdir,
887953
+                       GLUSTERD_UPGRADE_FILE);
887953
+        if ((len < 0) || (len >= PATH_MAX)) {
887953
+                goto out;
887953
+        }
887953
+        ret = gf_store_handle_retrieve(path, &handle);
887953
+
887953
+        if (ret) {
887953
+                gf_msg_debug(this->name, 0, "Unable to get store handle!");
887953
+                goto out;
887953
+        }
887953
+
887953
+        ret = gf_store_retrieve_value(handle, GD_MAX_OP_VERSION_KEY,
887953
+                                      &op_version_str);
887953
+        if (ret) {
887953
+                gf_msg_debug(this->name, 0, "No previous op_version present");
887953
+                goto out;
887953
+        }
887953
+
887953
+        tmp_version = strtol(op_version_str, &tmp, 10);
887953
+        if ((tmp_version <= 0) || (tmp && strlen(tmp) > 1)) {
887953
+                gf_msg(this->name, GF_LOG_WARNING, EINVAL,
887953
+                       GD_MSG_UNSUPPORTED_VERSION, "invalid version number");
887953
+                goto out;
887953
+        }
887953
+
887953
+        *op_version = tmp_version;
887953
+
887953
+        ret = 0;
887953
+out:
887953
+        if (op_version_str)
887953
+                GF_FREE(op_version_str);
887953
+        if (handle)
887953
+                gf_store_handle_destroy(handle);
887953
+        return ret;
887953
+}
887953
+
887953
+int
887953
 glusterd_retrieve_op_version (xlator_t *this, int *op_version)
887953
 {
887953
         char                    *op_version_str = NULL;
887953
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h
887953
index 383a475..76c5500 100644
887953
--- a/xlators/mgmt/glusterd/src/glusterd-store.h
887953
+++ b/xlators/mgmt/glusterd/src/glusterd-store.h
887953
@@ -161,6 +161,12 @@ glusterd_retrieve_op_version (xlator_t *this, int *op_version);
887953
 int
887953
 glusterd_store_global_info (xlator_t *this);
887953
 
887953
+int
887953
+glusterd_retrieve_max_op_version(xlator_t *this, int *op_version);
887953
+
887953
+int
887953
+glusterd_store_max_op_version(xlator_t *this);
887953
+
887953
 int32_t
887953
 glusterd_store_retrieve_options (xlator_t *this);
887953
 
887953
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
887953
index ca17526..29d5de1 100644
887953
--- a/xlators/mgmt/glusterd/src/glusterd.c
887953
+++ b/xlators/mgmt/glusterd/src/glusterd.c
887953
@@ -1428,6 +1428,7 @@ init (xlator_t *this)
887953
         gf_boolean_t       upgrade                    = _gf_false;
887953
         gf_boolean_t       downgrade                  = _gf_false;
887953
         char              *localtime_logging          = NULL;
887953
+        int                op_version                 = 0;
887953
 
887953
 #ifndef GF_DARWIN_HOST_OS
887953
         {
887953
@@ -1976,6 +1977,27 @@ init (xlator_t *this)
887953
         }
887953
 
887953
         GF_ATOMIC_INIT(conf->blockers, 0);
887953
+        ret = glusterd_handle_upgrade_downgrade(this->options, conf, upgrade,
887953
+                                                downgrade);
887953
+        if (ret)
887953
+                goto out;
887953
+
887953
+        ret = glusterd_retrieve_max_op_version(this, &op_version);
887953
+        /* first condition indicates file isn't present which means this code
887953
+         * change is hitting for the first time or someone has deleted it from
887953
+         * the backend.second condition is when max op_version differs, in both
887953
+         * cases volfiles should be regenerated
887953
+         */
887953
+        if (op_version == 0 || op_version != GD_OP_VERSION_MAX) {
887953
+                gf_log(this->name, GF_LOG_INFO,
887953
+                       "Regenerating volfiles due to a max op-version mismatch "
887953
+                       "or glusterd.upgrade file not being present, op_version "
887953
+                       "retrieved: %d, max op_version: %d", op_version,
887953
+                       GD_OP_VERSION_MAX);
887953
+                glusterd_recreate_volfiles(conf);
887953
+                ret = glusterd_store_max_op_version(this);
887953
+        }
887953
+
887953
         /* If the peer count is less than 2 then this would be the best time to
887953
          * spawn process/bricks that may need (re)starting since last time
887953
          * (this) glusterd was up. */
887953
@@ -1983,11 +2005,6 @@ init (xlator_t *this)
887953
                 glusterd_launch_synctask (glusterd_spawn_daemons, NULL);
887953
 
887953
 
887953
-        ret = glusterd_handle_upgrade_downgrade (this->options, conf, upgrade,
887953
-                                                 downgrade);
887953
-        if (ret)
887953
-                goto out;
887953
-
887953
         ret = glusterd_hooks_spawn_worker (this);
887953
         if (ret)
887953
                 goto out;
887953
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
887953
index bfa8310..cbdca52 100644
887953
--- a/xlators/mgmt/glusterd/src/glusterd.h
887953
+++ b/xlators/mgmt/glusterd/src/glusterd.h
887953
@@ -582,6 +582,9 @@ typedef enum {
887953
 
887953
 #define GLUSTERD_DEFAULT_PORT    GF_DEFAULT_BASE_PORT
887953
 #define GLUSTERD_INFO_FILE      "glusterd.info"
887953
+#define GLUSTERD_UPGRADE_FILE                                                  \
887953
+    "glusterd.upgrade" /* zero byte file to detect a need for regenerating     \
887953
+                          volfiles in container mode */
887953
 #define GLUSTERD_VOLUME_QUOTA_CONFIG "quota.conf"
887953
 #define GLUSTERD_VOLUME_DIR_PREFIX "vols"
887953
 #define GLUSTERD_PEER_DIR_PREFIX "peers"
887953
@@ -1333,4 +1336,8 @@ glusterd_tier_prevalidate (dict_t *dict, char **op_errstr,
887953
 
887953
 int
887953
 glusterd_options_init (xlator_t *this);
887953
+
887953
+int32_t
887953
+glusterd_recreate_volfiles(glusterd_conf_t *conf);
887953
+
887953
 #endif
887953
-- 
887953
1.8.3.1
887953