Blob Blame History Raw
From ea8c08c0da93e71cca3d90849c0aa4f9c7eace95 Mon Sep 17 00:00:00 2001
From: Kotresh HR <khiremat@redhat.com>
Date: Tue, 9 Jun 2015 10:44:44 +0530
Subject: [PATCH 67/73] features/changelog: Do htime setxattr without XATTR_REPLACE flag

HTIME_KEY marks the last changelog rolled over. The xattr is
maintained on .glusterfs/changelog/htime/HTIME.TSTAMP file.
On every rollover of the changelog file, the xattr is updated.
It is being updated with XATTR_REPLACE flag as xattr gets
created during changelog enable. But it is once found that
the xattrs on the file is cleared and is not reproduced later
on. This patch protects that case, if it happens by setting
xattr without XATTR_REPLACE flag in failure case.

The reason behind doing this in failure case is not to mask
the actual cause of xattrs getting cleared. This provides
the log message if the original issue still exists but the
consequential effects are fixed.

Also changed the log messages to depict the events happened
during changelog enable.

Change-Id: I699ed09a03667fd823d01d65c9c360fa7bc0e455
BUG: 1228495
Reviewed-On: http://review.gluster.org/#/c/11150/
Reviewed-On: http://review.gluster.org/#/c/11181/
Signed-off-by: Kotresh HR <khiremat@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/50530
Reviewed-by: Saravanakumar Arumugam <sarumuga@redhat.com>
Reviewed-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
Tested-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
---
 xlators/features/changelog/src/changelog-helpers.c |   33 +++++++++++++++-----
 xlators/features/changelog/src/changelog.c         |    3 +-
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c
index 7e518f1..2c0a645 100644
--- a/xlators/features/changelog/src/changelog-helpers.c
+++ b/xlators/features/changelog/src/changelog-helpers.c
@@ -327,11 +327,21 @@ htime_update (xlator_t *this,
         sprintf (x_value,"%lu:%d",ts, priv->rollover_count);
 
         if (sys_fsetxattr (priv->htime_fd, HTIME_KEY, x_value,
-                       strlen (x_value),  XATTR_REPLACE)) {
+                           strlen (x_value), XATTR_REPLACE)) {
                 gf_log (this->name, GF_LOG_ERROR,
-                        "Htime xattr updation failed, "
-                        "reason (%s)",strerror (errno));
-                goto out;
+                        "Htime xattr updation failed with XATTR_REPLACE "
+                        "Changelog: %s Reason (%s)", changelog_path,
+                        strerror (errno));
+
+                if (sys_fsetxattr (priv->htime_fd, HTIME_KEY, x_value,
+                                   strlen (x_value), 0)) {
+                        gf_log (this->name, GF_LOG_ERROR,
+                                "Htime xattr updation failed "
+                                "Changelog: %s Reason (%s)", changelog_path,
+                                strerror (errno));
+                        ret = -1;
+                        goto out;
+                }
         }
 
         priv->rollover_count +=1;
@@ -633,17 +643,21 @@ htime_open (xlator_t *this,
         size = sys_fgetxattr (ht_dir_fd, HTIME_CURRENT, ht_file_bname,
                              sizeof (ht_file_bname));
         if (size < 0) {
-                gf_log (this->name, GF_LOG_ERROR, "Error extracting"
-                        " HTIME_CURRENT: %s.", strerror (errno));
-
                 /* If upgrade scenario, find the latest HTIME.TSTAMP file
                  * and use the same. If error, create a new HTIME.TSTAMP
                  * file.
                  */
                 cnt = find_current_htime (ht_dir_fd, ht_dir_path,
                                            ht_file_bname);
-                if (cnt <= 0)
+                if (cnt <= 0) {
+                        gf_log (this->name, GF_LOG_INFO,
+                                "HTIME_CURRENT not found: %s. Changelog enabled"
+                                " before init", strerror (errno));
                         return htime_create (this, priv, ts);
+                }
+
+                gf_log (this->name, GF_LOG_ERROR, "Error extracting"
+                        " HTIME_CURRENT: %s.", strerror (errno));
         }
 
         gf_log (this->name, GF_LOG_INFO, "HTIME_CURRENT: %s", ht_file_bname);
@@ -701,6 +715,9 @@ htime_create (xlator_t *this,
         char ht_file_bname[NAME_MAX + 1]    = {0,};
         int flags                           = 0;
 
+        gf_log (this->name, GF_LOG_INFO, "Changelog enable: Creating new "
+                "HTIME.%lu file", ts);
+
         CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path);
 
         /* get the htime file name in ht_file_path */
diff --git a/xlators/features/changelog/src/changelog.c b/xlators/features/changelog/src/changelog.c
index bea7334..47696f4 100644
--- a/xlators/features/changelog/src/changelog.c
+++ b/xlators/features/changelog/src/changelog.c
@@ -2423,8 +2423,7 @@ reconfigure (xlator_t *this, dict_t *options)
                 if (active_now) {
                         if (!active_earlier) {
                                 gf_log (this->name, GF_LOG_INFO,
-                                        "Changelog enable: Creating new "
-                                        "HTIME.TSTAMP file");
+                                        "Reconfigure: Changelog Enable");
                                 if (gettimeofday(&tv, NULL) ) {
                                         gf_log (this->name, GF_LOG_ERROR,
                                                  "unable to fetch htime");
-- 
1.7.1