3604df
From 69a3c28f156a59018670c93a07883bb5ea366476 Mon Sep 17 00:00:00 2001
3604df
From: Manikandan Selvaganesh <mselvaga@redhat.com>
3604df
Date: Tue, 30 Aug 2016 17:53:09 +0530
3604df
Subject: [PATCH 156/157] glusterd/quota: upgrade quota.conf file during an upgrade
3604df
3604df
Problem
3604df
=======
3604df
When quota is enabled on 3.6, it will have quota conf version in quota.conf
3604df
as v1.1. This node gets upgraded to 3.7 but it will still have quota conf
3604df
version as v1.1 until a quota enable/disable/set limit is initiated. When
3604df
this is not initiated and when this node tries to peer probe a node which
3604df
is a fresh install of 3.7 (which will have quota conf version as v1.2), then this
3604df
will result in "Peer rejected" state. This patch fixes the issue.
3604df
3604df
Solution
3604df
========
3604df
When an upgrade happens from 3.6 to 3.7, quota.conf file needs
3604df
to be modified as well. With 3.6, in quota.conf the version will be
3604df
v1.1 and it needs to be changed to v1.2 from 3.7. This is because in
3604df
3.7, inode quota feature is introduced. So when an op-version bumpup
3604df
happens quota.conf needs to be upgraded with quota conf version v1.2
3604df
and all the 16 byte uuid needs to be changed to 17 bytes uuid as well.
3604df
3604df
Previously, when the cluster version is upgraded to 3.7, the quota.conf
3604df
got upgraded as well. But, the upgradation was done only when quota
3604df
enable/disable/set limit is done. With this patch, the upgradation is done
3604df
during a cluster op version bump up as well.
3604df
3604df
> Reviewed-on: http://review.gluster.org/15352
3604df
> Tested-by: Atin Mukherjee <amukherj@redhat.com>
3604df
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
3604df
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
> Smoke: Gluster Build System <jenkins@build.gluster.org>
3604df
> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
(cherry picked from commit 4b2cff614462508eef529c5d128e0974720e3f50)
3604df
3604df
>Reviewed-on: http://review.gluster.org/15791
3604df
>Smoke: Gluster Build System <jenkins@build.gluster.org>
3604df
>Reviewed-by: Manikandan Selvaganesh <manikandancs333@gmail.com>
3604df
>Tested-by: Manikandan Selvaganesh <manikandancs333@gmail.com>
3604df
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
3604df
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
3604df
Change-Id: Idb5ba29d3e1ea0e45c85d87c952c75da9e0f99f0
3604df
BUG: 1367472
3604df
Signed-off-by: Manikandan Selvaganesh <mselvaga@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/89554
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
Tested-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 rpc/xdr/src/cli1-xdr.x                     |    1 +
3604df
 xlators/mgmt/glusterd/src/Makefile.am      |    2 +-
3604df
 xlators/mgmt/glusterd/src/glusterd-op-sm.c |   44 +++++++++++++++++++++-------
3604df
 xlators/mgmt/glusterd/src/glusterd-quota.c |   13 ++++++--
3604df
 xlators/mgmt/glusterd/src/glusterd-quota.h |   17 +++++++++++
3604df
 5 files changed, 61 insertions(+), 16 deletions(-)
3604df
 create mode 100644 xlators/mgmt/glusterd/src/glusterd-quota.h
3604df
3604df
diff --git a/rpc/xdr/src/cli1-xdr.x b/rpc/xdr/src/cli1-xdr.x
3604df
index 80151d4..78b54ce 100644
3604df
--- a/rpc/xdr/src/cli1-xdr.x
3604df
+++ b/rpc/xdr/src/cli1-xdr.x
3604df
@@ -79,6 +79,7 @@ enum gf_quota_type {
3604df
         GF_QUOTA_OPTION_TYPE_LIST_OBJECTS,
3604df
         GF_QUOTA_OPTION_TYPE_REMOVE_OBJECTS,
3604df
         GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS,
3604df
+        GF_QUOTA_OPTION_TYPE_UPGRADE,
3604df
         GF_QUOTA_OPTION_TYPE_MAX
3604df
 };
3604df
 
3604df
diff --git a/xlators/mgmt/glusterd/src/Makefile.am b/xlators/mgmt/glusterd/src/Makefile.am
3604df
index 33a1fc4..1b90e5a 100644
3604df
--- a/xlators/mgmt/glusterd/src/Makefile.am
3604df
+++ b/xlators/mgmt/glusterd/src/Makefile.am
3604df
@@ -31,7 +31,7 @@ endif
3604df
 noinst_HEADERS = glusterd.h glusterd-utils.h glusterd-op-sm.h \
3604df
 	glusterd-sm.h glusterd-store.h glusterd-mem-types.h \
3604df
 	glusterd-pmap.h glusterd-volgen.h glusterd-mountbroker.h \
3604df
-	glusterd-syncop.h glusterd-hooks.h glusterd-locks.h \
3604df
+	glusterd-syncop.h glusterd-hooks.h glusterd-locks.h glusterd-quota.h \
3604df
 	glusterd-mgmt.h glusterd-messages.h glusterd-peer-utils.h \
3604df
 	glusterd-statedump.h glusterd-snapshot-utils.h glusterd-geo-rep.h \
3604df
 	glusterd-conn-mgmt.h glusterd-conn-helper.h glusterd-proc-mgmt.h \
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
index fcad97c..52ef08c 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
@@ -36,6 +36,7 @@
3604df
 #include "glusterd-locks.h"
3604df
 #include "glusterd-messages.h"
3604df
 #include "glusterd-utils.h"
3604df
+#include "glusterd-quota.h"
3604df
 #include "syscall.h"
3604df
 #include "cli1-xdr.h"
3604df
 #include "common-utils.h"
3604df
@@ -2335,17 +2336,19 @@ static int
3604df
 glusterd_op_set_all_volume_options (xlator_t *this, dict_t *dict,
3604df
                                     char **op_errstr)
3604df
 {
3604df
-        char            *key            = NULL;
3604df
-        char            *key_fixed      = NULL;
3604df
-        char            *value          = NULL;
3604df
-        char            *dup_value      = NULL;
3604df
-        int             ret             = -1;
3604df
-        glusterd_conf_t *conf           = NULL;
3604df
-        dict_t          *dup_opt        = NULL;
3604df
-        char            *next_version   = NULL;
3604df
-        gf_boolean_t    quorum_action   = _gf_false;
3604df
-        uint32_t        op_version      = 0;
3604df
-        glusterd_volinfo_t  *volinfo    = NULL;
3604df
+        char            *key                    = NULL;
3604df
+        char            *key_fixed              = NULL;
3604df
+        char            *value                  = NULL;
3604df
+        char            *dup_value              = NULL;
3604df
+        int             ret                     = -1;
3604df
+        glusterd_conf_t *conf                   = NULL;
3604df
+        dict_t          *dup_opt                = NULL;
3604df
+        char            *next_version           = NULL;
3604df
+        gf_boolean_t    quorum_action           = _gf_false;
3604df
+        uint32_t        op_version              = 0;
3604df
+        glusterd_volinfo_t  *volinfo            = NULL;
3604df
+        glusterd_volinfo_t  *tmp_volinfo        = NULL;
3604df
+        glusterd_volinfo_t  *voliter            = NULL;
3604df
 
3604df
         conf = this->private;
3604df
         ret = dict_get_str (dict, "key1", &key);
3604df
@@ -2391,6 +2394,25 @@ glusterd_op_set_all_volume_options (xlator_t *this, dict_t *dict,
3604df
 
3604df
                 if (op_version >= conf->op_version) {
3604df
                         conf->op_version = op_version;
3604df
+
3604df
+                        /* When a bump up happens, update the quota.conf file
3604df
+                         * as well. This is because, till 3.7 we had a quota
3604df
+                         * conf version v1.1 in quota.conf. When inode-quota
3604df
+                         * feature is introduced, this needs to be changed to
3604df
+                         * v1.2 in quota.conf and 16 bytes uuid in quota.conf
3604df
+                         * needs to be changed to 17 bytes. Look
3604df
+                         * glusterd_store_quota_config for more details.
3604df
+                         */
3604df
+                        cds_list_for_each_entry (voliter, &conf->volumes, vol_list) {
3604df
+                                tmp_volinfo = voliter;
3604df
+                                ret = glusterd_store_quota_config (tmp_volinfo,
3604df
+                                                                   NULL, NULL,
3604df
+                                                                   GF_QUOTA_OPTION_TYPE_UPGRADE,
3604df
+                                                                   NULL);
3604df
+                                if (ret)
3604df
+                                        goto out;
3604df
+                        }
3604df
+
3604df
                         ret = glusterd_store_global_info (this);
3604df
                         if (ret) {
3604df
                                 gf_msg (this->name, GF_LOG_ERROR, 0,
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c
3604df
index 55699cc..08fc74f 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd-quota.c
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd-quota.c
3604df
@@ -23,6 +23,7 @@
3604df
 #include "byte-order.h"
3604df
 #include "compat-errno.h"
3604df
 #include "quota-common-utils.h"
3604df
+#include "glusterd-quota.h"
3604df
 
3604df
 #include <sys/wait.h>
3604df
 #include <dlfcn.h>
3604df
@@ -55,12 +56,10 @@ const char *gd_quota_op_list[GF_QUOTA_OPTION_TYPE_MAX + 1] = {
3604df
         [GF_QUOTA_OPTION_TYPE_LIST_OBJECTS]       = "list-objects",
3604df
         [GF_QUOTA_OPTION_TYPE_REMOVE_OBJECTS]     = "remove-objects",
3604df
         [GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS]     = "enable-objects",
3604df
+        [GF_QUOTA_OPTION_TYPE_UPGRADE]            = "upgrade",
3604df
         [GF_QUOTA_OPTION_TYPE_MAX]                = NULL
3604df
 };
3604df
 
3604df
-int
3604df
-glusterd_store_quota_config (glusterd_volinfo_t *volinfo, char *path,
3604df
-                             char *gfid_str, int opcode, char **op_errstr);
3604df
 
3604df
 gf_boolean_t
3604df
 glusterd_is_quota_supported (int32_t type, char **op_errstr)
3604df
@@ -1097,9 +1096,15 @@ glusterd_store_quota_config (glusterd_volinfo_t *volinfo, char *path,
3604df
         if (ret)
3604df
                 goto out;
3604df
 
3604df
+
3604df
         /* Just create empty quota.conf file if create */
3604df
         if (GF_QUOTA_OPTION_TYPE_ENABLE == opcode ||
3604df
-            GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS == opcode) {
3604df
+            GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS == opcode ||
3604df
+            GF_QUOTA_OPTION_TYPE_UPGRADE == opcode) {
3604df
+                /* Opcode will be GF_QUOTA_OPTION_TYPE_UPGRADE when there is
3604df
+                 * an upgrade from 3.6 to 3.7. Just upgrade the quota.conf
3604df
+                 * file even during an op-version bumpup and exit.
3604df
+                 */
3604df
                 modified = _gf_true;
3604df
                 goto out;
3604df
         }
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.h b/xlators/mgmt/glusterd/src/glusterd-quota.h
3604df
new file mode 100644
3604df
index 0000000..9efff41
3604df
--- /dev/null
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd-quota.h
3604df
@@ -0,0 +1,17 @@
3604df
+/*
3604df
+   Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
3604df
+   This file is part of GlusterFS.
3604df
+
3604df
+   This file is licensed to you under your choice of the GNU Lesser
3604df
+   General Public License, version 3 or any later version (LGPLv3 or
3604df
+   later), or the GNU General Public License, version 2 (GPLv2), in all
3604df
+   cases as published by the Free Software Foundation.
3604df
+*/
3604df
+#ifndef _GLUSTERD_QUOTA_
3604df
+#define _GLUSTERD_QUOTA_
3604df
+
3604df
+int
3604df
+glusterd_store_quota_config (glusterd_volinfo_t *volinfo, char *path,
3604df
+                             char *gfid_str, int opcode, char **op_errstr);
3604df
+
3604df
+#endif
3604df
-- 
3604df
1.7.1
3604df