Blob Blame History Raw
From 69a3c28f156a59018670c93a07883bb5ea366476 Mon Sep 17 00:00:00 2001
From: Manikandan Selvaganesh <mselvaga@redhat.com>
Date: Tue, 30 Aug 2016 17:53:09 +0530
Subject: [PATCH 156/157] glusterd/quota: upgrade quota.conf file during an upgrade

Problem
=======
When quota is enabled on 3.6, it will have quota conf version in quota.conf
as v1.1. This node gets upgraded to 3.7 but it will still have quota conf
version as v1.1 until a quota enable/disable/set limit is initiated. When
this is not initiated and when this node tries to peer probe a node which
is a fresh install of 3.7 (which will have quota conf version as v1.2), then this
will result in "Peer rejected" state. This patch fixes the issue.

Solution
========
When an upgrade happens from 3.6 to 3.7, quota.conf file needs
to be modified as well. With 3.6, in quota.conf the version will be
v1.1 and it needs to be changed to v1.2 from 3.7. This is because in
3.7, inode quota feature is introduced. So when an op-version bumpup
happens quota.conf needs to be upgraded with quota conf version v1.2
and all the 16 byte uuid needs to be changed to 17 bytes uuid as well.

Previously, when the cluster version is upgraded to 3.7, the quota.conf
got upgraded as well. But, the upgradation was done only when quota
enable/disable/set limit is done. With this patch, the upgradation is done
during a cluster op version bump up as well.

> Reviewed-on: http://review.gluster.org/15352
> Tested-by: Atin Mukherjee <amukherj@redhat.com>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
(cherry picked from commit 4b2cff614462508eef529c5d128e0974720e3f50)

>Reviewed-on: http://review.gluster.org/15791
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>Reviewed-by: Manikandan Selvaganesh <manikandancs333@gmail.com>
>Tested-by: Manikandan Selvaganesh <manikandancs333@gmail.com>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>

Change-Id: Idb5ba29d3e1ea0e45c85d87c952c75da9e0f99f0
BUG: 1367472
Signed-off-by: Manikandan Selvaganesh <mselvaga@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/89554
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 rpc/xdr/src/cli1-xdr.x                     |    1 +
 xlators/mgmt/glusterd/src/Makefile.am      |    2 +-
 xlators/mgmt/glusterd/src/glusterd-op-sm.c |   44 +++++++++++++++++++++-------
 xlators/mgmt/glusterd/src/glusterd-quota.c |   13 ++++++--
 xlators/mgmt/glusterd/src/glusterd-quota.h |   17 +++++++++++
 5 files changed, 61 insertions(+), 16 deletions(-)
 create mode 100644 xlators/mgmt/glusterd/src/glusterd-quota.h

diff --git a/rpc/xdr/src/cli1-xdr.x b/rpc/xdr/src/cli1-xdr.x
index 80151d4..78b54ce 100644
--- a/rpc/xdr/src/cli1-xdr.x
+++ b/rpc/xdr/src/cli1-xdr.x
@@ -79,6 +79,7 @@ enum gf_quota_type {
         GF_QUOTA_OPTION_TYPE_LIST_OBJECTS,
         GF_QUOTA_OPTION_TYPE_REMOVE_OBJECTS,
         GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS,
+        GF_QUOTA_OPTION_TYPE_UPGRADE,
         GF_QUOTA_OPTION_TYPE_MAX
 };
 
diff --git a/xlators/mgmt/glusterd/src/Makefile.am b/xlators/mgmt/glusterd/src/Makefile.am
index 33a1fc4..1b90e5a 100644
--- a/xlators/mgmt/glusterd/src/Makefile.am
+++ b/xlators/mgmt/glusterd/src/Makefile.am
@@ -31,7 +31,7 @@ endif
 noinst_HEADERS = glusterd.h glusterd-utils.h glusterd-op-sm.h \
 	glusterd-sm.h glusterd-store.h glusterd-mem-types.h \
 	glusterd-pmap.h glusterd-volgen.h glusterd-mountbroker.h \
-	glusterd-syncop.h glusterd-hooks.h glusterd-locks.h \
+	glusterd-syncop.h glusterd-hooks.h glusterd-locks.h glusterd-quota.h \
 	glusterd-mgmt.h glusterd-messages.h glusterd-peer-utils.h \
 	glusterd-statedump.h glusterd-snapshot-utils.h glusterd-geo-rep.h \
 	glusterd-conn-mgmt.h glusterd-conn-helper.h glusterd-proc-mgmt.h \
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index fcad97c..52ef08c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -36,6 +36,7 @@
 #include "glusterd-locks.h"
 #include "glusterd-messages.h"
 #include "glusterd-utils.h"
+#include "glusterd-quota.h"
 #include "syscall.h"
 #include "cli1-xdr.h"
 #include "common-utils.h"
@@ -2335,17 +2336,19 @@ static int
 glusterd_op_set_all_volume_options (xlator_t *this, dict_t *dict,
                                     char **op_errstr)
 {
-        char            *key            = NULL;
-        char            *key_fixed      = NULL;
-        char            *value          = NULL;
-        char            *dup_value      = NULL;
-        int             ret             = -1;
-        glusterd_conf_t *conf           = NULL;
-        dict_t          *dup_opt        = NULL;
-        char            *next_version   = NULL;
-        gf_boolean_t    quorum_action   = _gf_false;
-        uint32_t        op_version      = 0;
-        glusterd_volinfo_t  *volinfo    = NULL;
+        char            *key                    = NULL;
+        char            *key_fixed              = NULL;
+        char            *value                  = NULL;
+        char            *dup_value              = NULL;
+        int             ret                     = -1;
+        glusterd_conf_t *conf                   = NULL;
+        dict_t          *dup_opt                = NULL;
+        char            *next_version           = NULL;
+        gf_boolean_t    quorum_action           = _gf_false;
+        uint32_t        op_version              = 0;
+        glusterd_volinfo_t  *volinfo            = NULL;
+        glusterd_volinfo_t  *tmp_volinfo        = NULL;
+        glusterd_volinfo_t  *voliter            = NULL;
 
         conf = this->private;
         ret = dict_get_str (dict, "key1", &key);
@@ -2391,6 +2394,25 @@ glusterd_op_set_all_volume_options (xlator_t *this, dict_t *dict,
 
                 if (op_version >= conf->op_version) {
                         conf->op_version = op_version;
+
+                        /* When a bump up happens, update the quota.conf file
+                         * as well. This is because, till 3.7 we had a quota
+                         * conf version v1.1 in quota.conf. When inode-quota
+                         * feature is introduced, this needs to be changed to
+                         * v1.2 in quota.conf and 16 bytes uuid in quota.conf
+                         * needs to be changed to 17 bytes. Look
+                         * glusterd_store_quota_config for more details.
+                         */
+                        cds_list_for_each_entry (voliter, &conf->volumes, vol_list) {
+                                tmp_volinfo = voliter;
+                                ret = glusterd_store_quota_config (tmp_volinfo,
+                                                                   NULL, NULL,
+                                                                   GF_QUOTA_OPTION_TYPE_UPGRADE,
+                                                                   NULL);
+                                if (ret)
+                                        goto out;
+                        }
+
                         ret = glusterd_store_global_info (this);
                         if (ret) {
                                 gf_msg (this->name, GF_LOG_ERROR, 0,
diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c
index 55699cc..08fc74f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-quota.c
+++ b/xlators/mgmt/glusterd/src/glusterd-quota.c
@@ -23,6 +23,7 @@
 #include "byte-order.h"
 #include "compat-errno.h"
 #include "quota-common-utils.h"
+#include "glusterd-quota.h"
 
 #include <sys/wait.h>
 #include <dlfcn.h>
@@ -55,12 +56,10 @@ const char *gd_quota_op_list[GF_QUOTA_OPTION_TYPE_MAX + 1] = {
         [GF_QUOTA_OPTION_TYPE_LIST_OBJECTS]       = "list-objects",
         [GF_QUOTA_OPTION_TYPE_REMOVE_OBJECTS]     = "remove-objects",
         [GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS]     = "enable-objects",
+        [GF_QUOTA_OPTION_TYPE_UPGRADE]            = "upgrade",
         [GF_QUOTA_OPTION_TYPE_MAX]                = NULL
 };
 
-int
-glusterd_store_quota_config (glusterd_volinfo_t *volinfo, char *path,
-                             char *gfid_str, int opcode, char **op_errstr);
 
 gf_boolean_t
 glusterd_is_quota_supported (int32_t type, char **op_errstr)
@@ -1097,9 +1096,15 @@ glusterd_store_quota_config (glusterd_volinfo_t *volinfo, char *path,
         if (ret)
                 goto out;
 
+
         /* Just create empty quota.conf file if create */
         if (GF_QUOTA_OPTION_TYPE_ENABLE == opcode ||
-            GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS == opcode) {
+            GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS == opcode ||
+            GF_QUOTA_OPTION_TYPE_UPGRADE == opcode) {
+                /* Opcode will be GF_QUOTA_OPTION_TYPE_UPGRADE when there is
+                 * an upgrade from 3.6 to 3.7. Just upgrade the quota.conf
+                 * file even during an op-version bumpup and exit.
+                 */
                 modified = _gf_true;
                 goto out;
         }
diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.h b/xlators/mgmt/glusterd/src/glusterd-quota.h
new file mode 100644
index 0000000..9efff41
--- /dev/null
+++ b/xlators/mgmt/glusterd/src/glusterd-quota.h
@@ -0,0 +1,17 @@
+/*
+   Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
+   This file is part of GlusterFS.
+
+   This file is licensed to you under your choice of the GNU Lesser
+   General Public License, version 3 or any later version (LGPLv3 or
+   later), or the GNU General Public License, version 2 (GPLv2), in all
+   cases as published by the Free Software Foundation.
+*/
+#ifndef _GLUSTERD_QUOTA_
+#define _GLUSTERD_QUOTA_
+
+int
+glusterd_store_quota_config (glusterd_volinfo_t *volinfo, char *path,
+                             char *gfid_str, int opcode, char **op_errstr);
+
+#endif
-- 
1.7.1