]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/nfs/nfs4session.c
Merge tag 'for-v3.9' of git://git.infradead.org/battery-2.6
[karo-tx-linux.git] / fs / nfs / nfs4session.c
index 066cfa101b4133517e324a7305d6917338da0a93..ebda5f4a031b74d2c890d4c1e6cf932d869e8f2b 100644 (file)
@@ -143,7 +143,6 @@ struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl)
        if (slotid > tbl->highest_used_slotid ||
                        tbl->highest_used_slotid == NFS4_NO_SLOT)
                tbl->highest_used_slotid = slotid;
-       ret->renewal_time = jiffies;
        ret->generation = tbl->generation;
 
 out:
@@ -173,11 +172,14 @@ static void nfs4_reset_slot_table(struct nfs4_slot_table *tbl,
        p = &tbl->slots;
        while (*p) {
                (*p)->seq_nr = ivalue;
+               (*p)->interrupted = 0;
                p = &(*p)->next;
        }
        tbl->highest_used_slotid = NFS4_NO_SLOT;
        tbl->target_highest_slotid = server_highest_slotid;
        tbl->server_highest_slotid = server_highest_slotid;
+       tbl->d_target_highest_slotid = 0;
+       tbl->d2_target_highest_slotid = 0;
        tbl->max_slotid = server_highest_slotid;
 }
 
@@ -226,9 +228,9 @@ static bool nfs41_assign_slot(struct rpc_task *task, void *pslot)
 
        if (nfs4_session_draining(tbl->session) && !args->sa_privileged)
                return false;
-       slot->renewal_time = jiffies;
        slot->generation = tbl->generation;
        args->sa_slot = slot;
+       res->sr_timestamp = jiffies;
        res->sr_slot = slot;
        res->sr_status_flags = 0;
        res->sr_status = 1;
@@ -271,20 +273,28 @@ void nfs41_wake_slot_table(struct nfs4_slot_table *tbl)
        }
 }
 
+static void nfs41_set_max_slotid_locked(struct nfs4_slot_table *tbl,
+               u32 target_highest_slotid)
+{
+       u32 max_slotid;
+
+       max_slotid = min(NFS4_MAX_SLOT_TABLE - 1, target_highest_slotid);
+       if (max_slotid > tbl->server_highest_slotid)
+               max_slotid = tbl->server_highest_slotid;
+       if (max_slotid > tbl->target_highest_slotid)
+               max_slotid = tbl->target_highest_slotid;
+       tbl->max_slotid = max_slotid;
+       nfs41_wake_slot_table(tbl);
+}
+
 /* Update the client's idea of target_highest_slotid */
 static void nfs41_set_target_slotid_locked(struct nfs4_slot_table *tbl,
                u32 target_highest_slotid)
 {
-       unsigned int max_slotid;
-
        if (tbl->target_highest_slotid == target_highest_slotid)
                return;
        tbl->target_highest_slotid = target_highest_slotid;
        tbl->generation++;
-
-       max_slotid = min(NFS4_MAX_SLOT_TABLE - 1, tbl->target_highest_slotid);
-       tbl->max_slotid = max_slotid;
-       nfs41_wake_slot_table(tbl);
 }
 
 void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
@@ -292,6 +302,9 @@ void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
 {
        spin_lock(&tbl->slot_tbl_lock);
        nfs41_set_target_slotid_locked(tbl, target_highest_slotid);
+       tbl->d_target_highest_slotid = 0;
+       tbl->d2_target_highest_slotid = 0;
+       nfs41_set_max_slotid_locked(tbl, target_highest_slotid);
        spin_unlock(&tbl->slot_tbl_lock);
 }
 
@@ -307,16 +320,66 @@ static void nfs41_set_server_slotid_locked(struct nfs4_slot_table *tbl,
        tbl->server_highest_slotid = highest_slotid;
 }
 
+static s32 nfs41_derivative_target_slotid(s32 s1, s32 s2)
+{
+       s1 -= s2;
+       if (s1 == 0)
+               return 0;
+       if (s1 < 0)
+               return (s1 - 1) >> 1;
+       return (s1 + 1) >> 1;
+}
+
+static int nfs41_sign_s32(s32 s1)
+{
+       if (s1 > 0)
+               return 1;
+       if (s1 < 0)
+               return -1;
+       return 0;
+}
+
+static bool nfs41_same_sign_or_zero_s32(s32 s1, s32 s2)
+{
+       if (!s1 || !s2)
+               return true;
+       return nfs41_sign_s32(s1) == nfs41_sign_s32(s2);
+}
+
+/* Try to eliminate outliers by checking for sharp changes in the
+ * derivatives and second derivatives
+ */
+static bool nfs41_is_outlier_target_slotid(struct nfs4_slot_table *tbl,
+               u32 new_target)
+{
+       s32 d_target, d2_target;
+       bool ret = true;
+
+       d_target = nfs41_derivative_target_slotid(new_target,
+                       tbl->target_highest_slotid);
+       d2_target = nfs41_derivative_target_slotid(d_target,
+                       tbl->d_target_highest_slotid);
+       /* Is first derivative same sign? */
+       if (nfs41_same_sign_or_zero_s32(d_target, tbl->d_target_highest_slotid))
+               ret = false;
+       /* Is second derivative same sign? */
+       if (nfs41_same_sign_or_zero_s32(d2_target, tbl->d2_target_highest_slotid))
+               ret = false;
+       tbl->d_target_highest_slotid = d_target;
+       tbl->d2_target_highest_slotid = d2_target;
+       return ret;
+}
+
 void nfs41_update_target_slotid(struct nfs4_slot_table *tbl,
                struct nfs4_slot *slot,
                struct nfs4_sequence_res *res)
 {
        spin_lock(&tbl->slot_tbl_lock);
-       if (tbl->generation != slot->generation)
-               goto out;
-       nfs41_set_server_slotid_locked(tbl, res->sr_highest_slotid);
-       nfs41_set_target_slotid_locked(tbl, res->sr_target_highest_slotid);
-out:
+       if (!nfs41_is_outlier_target_slotid(tbl, res->sr_target_highest_slotid))
+               nfs41_set_target_slotid_locked(tbl, res->sr_target_highest_slotid);
+       if (tbl->generation == slot->generation)
+               nfs41_set_server_slotid_locked(tbl, res->sr_highest_slotid);
+       nfs41_set_max_slotid_locked(tbl, res->sr_target_highest_slotid);
        spin_unlock(&tbl->slot_tbl_lock);
 }