7f4c2a
From c5ec2f7b76ce128c93413ab260c7bb7b59027219 Mon Sep 17 00:00:00 2001
7f4c2a
From: Venky Shankar <vshankar@redhat.com>
7f4c2a
Date: Tue, 30 Jun 2015 13:10:46 +0530
7f4c2a
Subject: [PATCH 240/244] features/bitrot: move inode state just at the last moment
7f4c2a
7f4c2a
    Backport of http://review.gluster.org/11461
7f4c2a
7f4c2a
Which was done at half the set expiry time resulting in actual
7f4c2a
IOs incrementing the object version. Now this is done just at
7f4c2a
the last moment with re-notification now cut-shorting into
7f4c2a
checksum calculation without waiting in the timer-wheel.
7f4c2a
7f4c2a
BUG: 1242585
7f4c2a
Change-Id: If655b77d822ebf7b2a4f65e1b5583dd3609306e7
7f4c2a
Signed-off-by: Venky Shankar <vshankar@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/52926
7f4c2a
Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com>
7f4c2a
Tested-by: Raghavendra Bhat <raghavendra@redhat.com>
7f4c2a
---
7f4c2a
 xlators/features/bit-rot/src/bitd/bit-rot.c |   61 ++++++++++++++++++--------
7f4c2a
 1 files changed, 42 insertions(+), 19 deletions(-)
7f4c2a
7f4c2a
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot.c b/xlators/features/bit-rot/src/bitd/bit-rot.c
7f4c2a
index 94063cb..4a050c8 100644
7f4c2a
--- a/xlators/features/bit-rot/src/bitd/bit-rot.c
7f4c2a
+++ b/xlators/features/bit-rot/src/bitd/bit-rot.c
7f4c2a
@@ -594,15 +594,12 @@ static inline int32_t br_sign_object (br_object_t *object)
7f4c2a
                 goto out;
7f4c2a
         }
7f4c2a
 
7f4c2a
-        /* sanity check */
7f4c2a
-        sign_info = ntohl (object->sign_info);
7f4c2a
-        GF_ASSERT (sign_info != BR_SIGN_NORMAL);
7f4c2a
-
7f4c2a
         /**
7f4c2a
          * For fd's that have notified for reopening, we send an explicit
7f4c2a
          * open() followed by a dummy write() call. This triggers the
7f4c2a
          * actual signing of the object.
7f4c2a
          */
7f4c2a
+        sign_info = ntohl (object->sign_info);
7f4c2a
         if (sign_info == BR_SIGN_REOPEN_WAIT) {
7f4c2a
                 br_object_resign (this, object, linked_inode);
7f4c2a
                 goto unref_inode;
7f4c2a
@@ -722,7 +719,8 @@ br_add_object_to_queue (struct gf_tw_timer_list *timer,
7f4c2a
         }
7f4c2a
         pthread_mutex_unlock (&priv->lock);
7f4c2a
 
7f4c2a
-        mem_put (timer);
7f4c2a
+        if (timer)
7f4c2a
+                mem_put (timer);
7f4c2a
         return;
7f4c2a
 }
7f4c2a
 
7f4c2a
@@ -762,7 +760,7 @@ br_initialize_timer (xlator_t *this, br_object_t *object, br_child_t *child,
7f4c2a
                 goto out;
7f4c2a
         INIT_LIST_HEAD (&timer->entry);
7f4c2a
 
7f4c2a
-        timer->expires  = (priv->expiry_time >> 1);
7f4c2a
+        timer->expires = priv->expiry_time;
7f4c2a
         if (!timer->expires)
7f4c2a
                 timer->expires = 1;
7f4c2a
 
7f4c2a
@@ -774,6 +772,27 @@ out:
7f4c2a
         return timer;
7f4c2a
 }
7f4c2a
 
7f4c2a
+static int32_t
7f4c2a
+br_schedule_object_reopen (xlator_t *this, br_object_t *object,
7f4c2a
+                           br_child_t *child, changelog_event_t *ev)
7f4c2a
+{
7f4c2a
+        struct gf_tw_timer_list *timer = NULL;
7f4c2a
+
7f4c2a
+        timer = br_initialize_timer (this, object, child, ev);
7f4c2a
+        if (!timer)
7f4c2a
+                gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_SET_TIMER_FAILED,
7f4c2a
+                        "Failed to allocate object expiry timer [GFID: %s]",
7f4c2a
+                        uuid_utoa (object->gfid));
7f4c2a
+        return timer ? 0 : -1;
7f4c2a
+}
7f4c2a
+
7f4c2a
+static int32_t
7f4c2a
+br_object_quicksign (xlator_t *this, br_object_t *object)
7f4c2a
+{
7f4c2a
+        br_add_object_to_queue (NULL, object, 0ULL);
7f4c2a
+        return 0;
7f4c2a
+}
7f4c2a
+
7f4c2a
 /**
7f4c2a
  * This callback function registered with the changelog is executed
7f4c2a
  * whenever a notification from the changelog is received. This should
7f4c2a
@@ -787,11 +806,12 @@ void
7f4c2a
 br_brick_callback (void *xl, char *brick,
7f4c2a
                    void *data, changelog_event_t *ev)
7f4c2a
 {
7f4c2a
-        uuid_t gfid = {0,};
7f4c2a
-        xlator_t                *this   = NULL;
7f4c2a
-        br_object_t             *object = NULL;
7f4c2a
-        br_child_t              *child  = NULL;
7f4c2a
-        struct gf_tw_timer_list *timer  = NULL;
7f4c2a
+        int32_t          ret       = 0;
7f4c2a
+        uuid_t           gfid      = {0,};
7f4c2a
+        xlator_t        *this      = NULL;
7f4c2a
+        br_object_t     *object    = NULL;
7f4c2a
+        br_child_t      *child     = NULL;
7f4c2a
+        br_sign_state_t  sign_info = BR_SIGN_INVALID;
7f4c2a
 
7f4c2a
         this = xl;
7f4c2a
 
7f4c2a
@@ -822,22 +842,25 @@ br_brick_callback (void *xl, char *brick,
7f4c2a
                 goto out;
7f4c2a
         }
7f4c2a
 
7f4c2a
-        timer = br_initialize_timer (this, object, child, ev);
7f4c2a
-        if (!timer) {
7f4c2a
-                gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_SET_TIMER_FAILED,
7f4c2a
-                        "failed to allocate object expiry timer [GFID: %s]",
7f4c2a
-                        uuid_utoa (gfid));
7f4c2a
+        /* sanity check */
7f4c2a
+        sign_info = ntohl (object->sign_info);
7f4c2a
+        GF_ASSERT (sign_info != BR_SIGN_NORMAL);
7f4c2a
+
7f4c2a
+        if (sign_info == BR_SIGN_REOPEN_WAIT)
7f4c2a
+                ret = br_schedule_object_reopen (this, object, child, ev);
7f4c2a
+        else
7f4c2a
+                ret = br_object_quicksign (this, object);
7f4c2a
+
7f4c2a
+        if (ret)
7f4c2a
                 goto free_object;
7f4c2a
-        }
7f4c2a
 
7f4c2a
         gf_msg_debug (this->name, 0, "->callback: brick [%s], type [%d]\n",
7f4c2a
                       brick, ev->ev_type);
7f4c2a
-
7f4c2a
         return;
7f4c2a
 
7f4c2a
  free_object:
7f4c2a
         GF_FREE (object);
7f4c2a
-out:
7f4c2a
+ out:
7f4c2a
         return;
7f4c2a
 }
7f4c2a
 
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a