12a457
From 47e8d4ab112e58db1736f30f6a1aff6954be660f Mon Sep 17 00:00:00 2001
12a457
From: Avra Sengupta <asengupt@redhat.com>
12a457
Date: Fri, 11 Mar 2016 15:27:30 +0530
12a457
Subject: [PATCH 092/104] snapshot/quota: Copy quota.cksum during snapshot operations
12a457
12a457
    Backport of http://review.gluster.org/#/c/13760/
12a457
12a457
A volume having a quota.conf file, should always have
12a457
a quota.cksum file too. Based on this above assumption
12a457
modifying glusterd_copy_quota_files() to always copy
12a457
quota.cksum, if quota.conf is present.
12a457
12a457
This change will be reflected when a snapshot is created,
12a457
restored and cloned.
12a457
12a457
Backport of upstream master:
12a457
> Change-Id: Ia49dc26eacef32eeb8f7d7d9553c80e304b08779
12a457
> BUG: 1316848
12a457
> Signed-off-by: Avra Sengupta <asengupt@redhat.com>
12a457
> Reviewed-on: http://review.gluster.org/13760
12a457
> Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
> CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
> Reviewed-by: Vijaikumar Mallikarjuna <vmallika@redhat.com>
12a457
> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
12a457
12a457
Backport of upstream release-3.7
12a457
> Change-Id: Ia49dc26eacef32eeb8f7d7d9553c80e304b08779
12a457
> BUG: 1329492
12a457
> Signed-off-by: Avra Sengupta <asengupt@redhat.com>
12a457
> Reviewed-on: http://review.gluster.org/14047
12a457
> Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
> CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
> Reviewed-by: Vijaikumar Mallikarjuna <vmallika@redhat.com>
12a457
> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
12a457
12a457
BUG: 1308837
12a457
Change-Id: I2979c34efb2020d1e027cfc2883519b96a4e15f1
12a457
Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/73092
12a457
Reviewed-by: Rafi Kavungal Chundattu Parambil <rkavunga@redhat.com>
12a457
---
12a457
 xlators/mgmt/glusterd/src/glusterd-messages.h      |    8 +++++
12a457
 .../mgmt/glusterd/src/glusterd-snapshot-utils.c    |   28 ++++++++++++++++++++
12a457
 xlators/mgmt/glusterd/src/glusterd-snapshot.c      |   24 ++---------------
12a457
 xlators/mgmt/glusterd/src/glusterd-utils.c         |    1 +
12a457
 4 files changed, 40 insertions(+), 21 deletions(-)
12a457
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h
12a457
index 8dcbcdb..cfcd114 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-messages.h
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-messages.h
12a457
@@ -4638,6 +4638,14 @@
12a457
  */
12a457
 #define GD_MSG_SNAP_RESUME_TIER_FAIL                (GLUSTERD_COMP_BASE + 573)
12a457
 
12a457
+/*!
12a457
+ * @messageid
12a457
+ * @diagnosis
12a457
+ * @recommendedaction
12a457
+ *
12a457
+ */
12a457
+#define GD_MSG_FILE_NOT_FOUND                       (GLUSTERD_COMP_BASE + 574)
12a457
+
12a457
 /*------------*/
12a457
 #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
12a457
 #endif /* !_GLUSTERD_MESSAGES_H_ */
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
12a457
index e95d6ab..7c1b1f0 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
12a457
@@ -3652,6 +3652,34 @@ glusterd_copy_quota_files (glusterd_volinfo_t *src_vol,
12a457
                 goto out;
12a457
         }
12a457
 
12a457
+        ret = snprintf (src_path, sizeof (src_path), "%s/quota.cksum",
12a457
+                        src_dir);
12a457
+        if (ret < 0)
12a457
+                goto out;
12a457
+
12a457
+        /* if quota.conf is present, quota.cksum has to be present. *
12a457
+         * Fail snapshot operation if file is absent                *
12a457
+         */
12a457
+        ret = sys_lstat (src_path, &stbuf);
12a457
+        if (ret) {
12a457
+                gf_msg (this->name, GF_LOG_ERROR, 0,
12a457
+                        GD_MSG_FILE_NOT_FOUND, "%s not found", src_path);
12a457
+                goto out;
12a457
+        }
12a457
+
12a457
+        ret = snprintf (dest_path, sizeof (dest_path), "%s/quota.cksum",
12a457
+                       dest_dir);
12a457
+        if (ret < 0)
12a457
+                goto out;
12a457
+
12a457
+        ret = glusterd_copy_file (src_path, dest_path);
12a457
+        if (ret) {
12a457
+                gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
12a457
+                        GD_MSG_NO_MEMORY, "Failed to copy %s in %s",
12a457
+                        src_path, dest_path);
12a457
+                goto out;
12a457
+        }
12a457
+
12a457
         *conf_present = _gf_true;
12a457
 out:
12a457
         return ret;
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
12a457
index da6c301..072e22f 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
12a457
@@ -9731,6 +9731,9 @@ gd_restore_snap_volume (dict_t *dict, dict_t *rsp_dict,
12a457
                 goto out;
12a457
         }
12a457
 
12a457
+        /* Need not save cksum, as we will copy cksum file in *
12a457
+         * this function                                           *
12a457
+         */
12a457
         ret = glusterd_copy_quota_files (snap_vol, orig_vol, &conf_present);
12a457
         if (ret) {
12a457
                 gf_msg (this->name, GF_LOG_ERROR, 0,
12a457
@@ -9740,27 +9743,6 @@ gd_restore_snap_volume (dict_t *dict, dict_t *rsp_dict,
12a457
                 goto out;
12a457
         }
12a457
 
12a457
-        if (conf_present) {
12a457
-                /* TO calculate checksum of quota conf we need to send
12a457
-                 * second argument as _gf_true
12a457
-                 */
12a457
-                ret = glusterd_compute_cksum (new_volinfo, _gf_true);
12a457
-                if (ret) {
12a457
-                        gf_msg (this->name, GF_LOG_ERROR, 0,
12a457
-                                GD_MSG_CKSUM_COMPUTE_FAIL, "Failed to compute "
12a457
-                                "checksum for quota conf file");
12a457
-                        goto out;
12a457
-                }
12a457
-
12a457
-                ret = glusterd_store_save_quota_version_and_cksum (new_volinfo);
12a457
-                if (ret) {
12a457
-                        gf_msg (this->name, GF_LOG_ERROR, 0,
12a457
-                                GD_MSG_QUOTA_CKSUM_VER_STORE_FAIL, "Failed to "
12a457
-                                "store quota version and cksum");
12a457
-                        goto out;
12a457
-                }
12a457
-        }
12a457
-
12a457
         /* New volinfo always shows the status as created. Therefore
12a457
          * set the status to the original volume's status. */
12a457
         glusterd_set_volume_status (new_volinfo, orig_vol->status);
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
12a457
index bb4868b..d100ec3 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
12a457
@@ -634,6 +634,7 @@ glusterd_volinfo_dup (glusterd_volinfo_t *volinfo,
12a457
         new_volinfo->quota_conf_version = volinfo->quota_conf_version;
12a457
         new_volinfo->quota_xattr_version = volinfo->quota_xattr_version;
12a457
         new_volinfo->snap_max_hard_limit = volinfo->snap_max_hard_limit;
12a457
+        new_volinfo->quota_conf_cksum = volinfo->quota_conf_cksum;
12a457
 
12a457
         dict_copy (volinfo->dict, new_volinfo->dict);
12a457
         dict_copy (volinfo->gsync_slaves, new_volinfo->gsync_slaves);
12a457
-- 
12a457
1.7.1
12a457