Whamcloud - gitweb
LU-5781 ldlm: Solve a race for LRU lock cancel
[fs/lustre-release.git] / lustre / ldlm / ldlm_lock.c
index d6b7de5..7c47ca6 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2010, 2013, Intel Corporation.
+ * Copyright (c) 2010, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #define DEBUG_SUBSYSTEM S_LDLM
 
-#ifdef __KERNEL__
-# include <libcfs/libcfs.h>
-# include <linux/lustre_intent.h>
-#else
-# include <liblustre.h>
-#endif
-
+#include <libcfs/libcfs.h>
 #include <obd_class.h>
 #include "ldlm_internal.h"
 
@@ -71,19 +65,11 @@ char *ldlm_typename[] = {
        [LDLM_FLOCK] = "FLK",
        [LDLM_IBITS] = "IBT",
 };
-EXPORT_SYMBOL(ldlm_typename);
 
-static ldlm_policy_wire_to_local_t ldlm_policy_wire18_to_local[] = {
+static ldlm_policy_wire_to_local_t ldlm_policy_wire_to_local[] = {
        [LDLM_PLAIN - LDLM_MIN_TYPE]  = ldlm_plain_policy_wire_to_local,
        [LDLM_EXTENT - LDLM_MIN_TYPE] = ldlm_extent_policy_wire_to_local,
-       [LDLM_FLOCK - LDLM_MIN_TYPE]  = ldlm_flock_policy_wire18_to_local,
-       [LDLM_IBITS - LDLM_MIN_TYPE]  = ldlm_ibits_policy_wire_to_local,
-};
-
-static ldlm_policy_wire_to_local_t ldlm_policy_wire21_to_local[] = {
-       [LDLM_PLAIN - LDLM_MIN_TYPE]  = ldlm_plain_policy_wire_to_local,
-       [LDLM_EXTENT - LDLM_MIN_TYPE] = ldlm_extent_policy_wire_to_local,
-       [LDLM_FLOCK - LDLM_MIN_TYPE]  = ldlm_flock_policy_wire21_to_local,
+       [LDLM_FLOCK - LDLM_MIN_TYPE]  = ldlm_flock_policy_wire_to_local,
        [LDLM_IBITS - LDLM_MIN_TYPE]  = ldlm_ibits_policy_wire_to_local,
 };
 
@@ -116,14 +102,8 @@ void ldlm_convert_policy_to_local(struct obd_export *exp, ldlm_type_t type,
                                  ldlm_policy_data_t *lpolicy)
 {
        ldlm_policy_wire_to_local_t convert;
-       int new_client;
 
-       /** some badness for 2.0.0 clients, but 2.0.0 isn't supported */
-       new_client = (exp_connect_flags(exp) & OBD_CONNECT_FULL20) != 0;
-       if (new_client)
-               convert = ldlm_policy_wire21_to_local[type - LDLM_MIN_TYPE];
-       else
-               convert = ldlm_policy_wire18_to_local[type - LDLM_MIN_TYPE];
+       convert = ldlm_policy_wire_to_local[type - LDLM_MIN_TYPE];
 
        convert(wpolicy, lpolicy);
 }
@@ -162,9 +142,7 @@ extern struct kmem_cache *ldlm_lock_slab;
 static ldlm_processing_policy ldlm_processing_policy_table[] = {
        [LDLM_PLAIN]    = ldlm_process_plain_lock,
        [LDLM_EXTENT]   = ldlm_process_extent_lock,
-# ifdef __KERNEL__
        [LDLM_FLOCK]    = ldlm_process_flock_lock,
-# endif
        [LDLM_IBITS]    = ldlm_process_inodebits_lock,
 };
 
@@ -220,8 +198,8 @@ void ldlm_lock_put(struct ldlm_lock *lock)
 
                 res = lock->l_resource;
                LASSERT(ldlm_is_destroyed(lock));
-                LASSERT(cfs_list_empty(&lock->l_res_link));
-                LASSERT(cfs_list_empty(&lock->l_pending_chain));
+               LASSERT(list_empty(&lock->l_res_link));
+               LASSERT(list_empty(&lock->l_pending_chain));
 
                 lprocfs_counter_decr(ldlm_res_to_ns(res)->ns_stats,
                                      LDLM_NSS_LOCKS);
@@ -251,11 +229,11 @@ EXPORT_SYMBOL(ldlm_lock_put);
 int ldlm_lock_remove_from_lru_nolock(struct ldlm_lock *lock)
 {
        int rc = 0;
-       if (!cfs_list_empty(&lock->l_lru)) {
+       if (!list_empty(&lock->l_lru)) {
                struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
 
                LASSERT(lock->l_resource->lr_type != LDLM_FLOCK);
-               cfs_list_del_init(&lock->l_lru);
+               list_del_init(&lock->l_lru);
                LASSERT(ns->ns_nr_unused > 0);
                ns->ns_nr_unused--;
                rc = 1;
@@ -265,23 +243,32 @@ int ldlm_lock_remove_from_lru_nolock(struct ldlm_lock *lock)
 
 /**
  * Removes LDLM lock \a lock from LRU. Obtains the LRU lock first.
+ *
+ * If \a last_use is non-zero, it will remove the lock from LRU only if
+ * it matches lock's l_last_used.
+ *
+ * \retval 0 if \a last_use is set, the lock is not in LRU list or \a last_use
+ *           doesn't match lock's l_last_used;
+ *           otherwise, the lock hasn't been in the LRU list.
+ * \retval 1 the lock was in LRU list and removed.
  */
-int ldlm_lock_remove_from_lru(struct ldlm_lock *lock)
+int ldlm_lock_remove_from_lru_check(struct ldlm_lock *lock, cfs_time_t last_use)
 {
        struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
-       int rc;
+       int rc = 0;
 
        ENTRY;
        if (ldlm_is_ns_srv(lock)) {
-               LASSERT(cfs_list_empty(&lock->l_lru));
+               LASSERT(list_empty(&lock->l_lru));
                RETURN(0);
        }
 
        spin_lock(&ns->ns_lock);
-       rc = ldlm_lock_remove_from_lru_nolock(lock);
+       if (last_use == 0 || last_use == lock->l_last_used)
+               rc = ldlm_lock_remove_from_lru_nolock(lock);
        spin_unlock(&ns->ns_lock);
-       EXIT;
-       return rc;
+
+       RETURN(rc);
 }
 
 /**
@@ -292,9 +279,9 @@ void ldlm_lock_add_to_lru_nolock(struct ldlm_lock *lock)
        struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
 
        lock->l_last_used = cfs_time_current();
-       LASSERT(cfs_list_empty(&lock->l_lru));
+       LASSERT(list_empty(&lock->l_lru));
        LASSERT(lock->l_resource->lr_type != LDLM_FLOCK);
-       cfs_list_add_tail(&lock->l_lru, &ns->ns_unused_list);
+       list_add_tail(&lock->l_lru, &ns->ns_unused_list);
        ldlm_clear_skipped(lock);
        LASSERT(ns->ns_nr_unused >= 0);
        ns->ns_nr_unused++;
@@ -325,13 +312,13 @@ void ldlm_lock_touch_in_lru(struct ldlm_lock *lock)
 
        ENTRY;
        if (ldlm_is_ns_srv(lock)) {
-               LASSERT(cfs_list_empty(&lock->l_lru));
+               LASSERT(list_empty(&lock->l_lru));
                EXIT;
                return;
        }
 
        spin_lock(&ns->ns_lock);
-       if (!cfs_list_empty(&lock->l_lru)) {
+       if (!list_empty(&lock->l_lru)) {
                ldlm_lock_remove_from_lru_nolock(lock);
                ldlm_lock_add_to_lru_nolock(lock);
        }
@@ -358,7 +345,7 @@ void ldlm_lock_touch_in_lru(struct ldlm_lock *lock)
  * ldlm_lock_destroy, you can never drop your final references on this lock.
  * Because it's not in the hash table anymore.  -phil
  */
-int ldlm_lock_destroy_internal(struct ldlm_lock *lock)
+static int ldlm_lock_destroy_internal(struct ldlm_lock *lock)
 {
         ENTRY;
 
@@ -367,13 +354,13 @@ int ldlm_lock_destroy_internal(struct ldlm_lock *lock)
                 LBUG();
         }
 
-        if (!cfs_list_empty(&lock->l_res_link)) {
+       if (!list_empty(&lock->l_res_link)) {
                 LDLM_ERROR(lock, "lock still on resource");
                 LBUG();
         }
 
        if (ldlm_is_destroyed(lock)) {
-               LASSERT(cfs_list_empty(&lock->l_lru));
+               LASSERT(list_empty(&lock->l_lru));
                EXIT;
                return 0;
        }
@@ -453,7 +440,7 @@ static void lock_handle_free(void *lock, int size)
        OBD_SLAB_FREE(lock, ldlm_lock_slab, size);
 }
 
-struct portals_handle_ops lock_handle_ops = {
+static struct portals_handle_ops lock_handle_ops = {
        .hop_addref = lock_handle_addref,
        .hop_free   = lock_handle_free,
 };
@@ -483,22 +470,22 @@ static struct ldlm_lock *ldlm_lock_new(struct ldlm_resource *resource)
        lu_ref_add(&resource->lr_reference, "lock", lock);
 
        atomic_set(&lock->l_refc, 2);
-       CFS_INIT_LIST_HEAD(&lock->l_res_link);
-       CFS_INIT_LIST_HEAD(&lock->l_lru);
-       CFS_INIT_LIST_HEAD(&lock->l_pending_chain);
-       CFS_INIT_LIST_HEAD(&lock->l_bl_ast);
-       CFS_INIT_LIST_HEAD(&lock->l_cp_ast);
-       CFS_INIT_LIST_HEAD(&lock->l_rk_ast);
+       INIT_LIST_HEAD(&lock->l_res_link);
+       INIT_LIST_HEAD(&lock->l_lru);
+       INIT_LIST_HEAD(&lock->l_pending_chain);
+       INIT_LIST_HEAD(&lock->l_bl_ast);
+       INIT_LIST_HEAD(&lock->l_cp_ast);
+       INIT_LIST_HEAD(&lock->l_rk_ast);
        init_waitqueue_head(&lock->l_waitq);
        lock->l_blocking_lock = NULL;
-       CFS_INIT_LIST_HEAD(&lock->l_sl_mode);
-       CFS_INIT_LIST_HEAD(&lock->l_sl_policy);
-       CFS_INIT_HLIST_NODE(&lock->l_exp_hash);
-       CFS_INIT_HLIST_NODE(&lock->l_exp_flock_hash);
+       INIT_LIST_HEAD(&lock->l_sl_mode);
+       INIT_LIST_HEAD(&lock->l_sl_policy);
+       INIT_HLIST_NODE(&lock->l_exp_hash);
+       INIT_HLIST_NODE(&lock->l_exp_flock_hash);
 
         lprocfs_counter_incr(ldlm_res_to_ns(resource)->ns_stats,
                              LDLM_NSS_LOCKS);
-        CFS_INIT_LIST_HEAD(&lock->l_handle.h_link);
+       INIT_LIST_HEAD(&lock->l_handle.h_link);
        class_handle_hash(&lock->l_handle, &lock_handle_ops);
 
         lu_ref_init(&lock->l_reference);
@@ -506,11 +493,11 @@ static struct ldlm_lock *ldlm_lock_new(struct ldlm_resource *resource)
         lock->l_callback_timeout = 0;
 
 #if LUSTRE_TRACKS_LOCK_EXP_REFS
-        CFS_INIT_LIST_HEAD(&lock->l_exp_refs_link);
+       INIT_LIST_HEAD(&lock->l_exp_refs_link);
         lock->l_exp_refs_nr = 0;
         lock->l_exp_refs_target = NULL;
 #endif
-        CFS_INIT_LIST_HEAD(&lock->l_exp_list);
+       INIT_LIST_HEAD(&lock->l_exp_list);
 
         RETURN(lock);
 }
@@ -541,7 +528,7 @@ int ldlm_lock_change_resource(struct ldlm_namespace *ns, struct ldlm_lock *lock,
         LASSERT(new_resid->name[0] != 0);
 
         /* This function assumes that the lock isn't on any lists */
-        LASSERT(cfs_list_empty(&lock->l_res_link));
+       LASSERT(list_empty(&lock->l_res_link));
 
         type = oldres->lr_type;
         unlock_res_and_lock(lock);
@@ -578,7 +565,6 @@ int ldlm_lock_change_resource(struct ldlm_namespace *ns, struct ldlm_lock *lock,
 
         RETURN(0);
 }
-EXPORT_SYMBOL(ldlm_lock_change_resource);
 
 /** \defgroup ldlm_handles LDLM HANDLES
  * Ways to get hold of locks without any addresses.
@@ -655,61 +641,21 @@ EXPORT_SYMBOL(__ldlm_handle2lock);
  */
 void ldlm_lock2desc(struct ldlm_lock *lock, struct ldlm_lock_desc *desc)
 {
-       struct obd_export *exp = lock->l_export ?: lock->l_conn_export;
-
-       /* INODEBITS_INTEROP: If the other side does not support
-        * inodebits, reply with a plain lock descriptor. */
-       if ((lock->l_resource->lr_type == LDLM_IBITS) &&
-           (exp && !(exp_connect_flags(exp) & OBD_CONNECT_IBITS))) {
-                /* Make sure all the right bits are set in this lock we
-                   are going to pass to client */
-                LASSERTF(lock->l_policy_data.l_inodebits.bits ==
-                         (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
-                          MDS_INODELOCK_LAYOUT),
-                         "Inappropriate inode lock bits during "
-                         "conversion " LPU64 "\n",
-                         lock->l_policy_data.l_inodebits.bits);
-
-                ldlm_res2desc(lock->l_resource, &desc->l_resource);
-                desc->l_resource.lr_type = LDLM_PLAIN;
-
-                /* Convert "new" lock mode to something old client can
-                   understand */
-                if ((lock->l_req_mode == LCK_CR) ||
-                    (lock->l_req_mode == LCK_CW))
-                        desc->l_req_mode = LCK_PR;
-                else
-                        desc->l_req_mode = lock->l_req_mode;
-                if ((lock->l_granted_mode == LCK_CR) ||
-                    (lock->l_granted_mode == LCK_CW)) {
-                        desc->l_granted_mode = LCK_PR;
-                } else {
-                        /* We never grant PW/EX locks to clients */
-                        LASSERT((lock->l_granted_mode != LCK_PW) &&
-                                (lock->l_granted_mode != LCK_EX));
-                        desc->l_granted_mode = lock->l_granted_mode;
-                }
-
-                /* We do not copy policy here, because there is no
-                   policy for plain locks */
-        } else {
-                ldlm_res2desc(lock->l_resource, &desc->l_resource);
-                desc->l_req_mode = lock->l_req_mode;
-                desc->l_granted_mode = lock->l_granted_mode;
-                ldlm_convert_policy_to_wire(lock->l_resource->lr_type,
-                                            &lock->l_policy_data,
-                                            &desc->l_policy_data);
-        }
+       ldlm_res2desc(lock->l_resource, &desc->l_resource);
+       desc->l_req_mode = lock->l_req_mode;
+       desc->l_granted_mode = lock->l_granted_mode;
+       ldlm_convert_policy_to_wire(lock->l_resource->lr_type,
+                                   &lock->l_policy_data,
+                                   &desc->l_policy_data);
 }
-EXPORT_SYMBOL(ldlm_lock2desc);
 
 /**
  * Add a lock to list of conflicting locks to send AST to.
  *
  * Only add if we have not sent a blocking AST to the lock yet.
  */
-void ldlm_add_bl_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
-                           cfs_list_t *work_list)
+static void ldlm_add_bl_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
+                                 struct list_head *work_list)
 {
        if (!ldlm_is_ast_sent(lock)) {
                LDLM_DEBUG(lock, "lock incompatible; sending blocking AST.");
@@ -718,8 +664,8 @@ void ldlm_add_bl_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
                 * discard dirty data, rather than writing back. */
                if (ldlm_is_ast_discard_data(new))
                        ldlm_set_discard_data(lock);
-                LASSERT(cfs_list_empty(&lock->l_bl_ast));
-                cfs_list_add(&lock->l_bl_ast, work_list);
+               LASSERT(list_empty(&lock->l_bl_ast));
+               list_add(&lock->l_bl_ast, work_list);
                 LDLM_LOCK_GET(lock);
                 LASSERT(lock->l_blocking_lock == NULL);
                 lock->l_blocking_lock = LDLM_LOCK_GET(new);
@@ -729,13 +675,14 @@ void ldlm_add_bl_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
 /**
  * Add a lock to list of just granted locks to send completion AST to.
  */
-void ldlm_add_cp_work_item(struct ldlm_lock *lock, cfs_list_t *work_list)
+static void ldlm_add_cp_work_item(struct ldlm_lock *lock,
+                                 struct list_head *work_list)
 {
        if (!ldlm_is_cp_reqd(lock)) {
                ldlm_set_cp_reqd(lock);
                 LDLM_DEBUG(lock, "lock granted; sending completion AST.");
-                LASSERT(cfs_list_empty(&lock->l_cp_ast));
-                cfs_list_add(&lock->l_cp_ast, work_list);
+               LASSERT(list_empty(&lock->l_cp_ast));
+               list_add(&lock->l_cp_ast, work_list);
                 LDLM_LOCK_GET(lock);
         }
 }
@@ -747,7 +694,7 @@ void ldlm_add_cp_work_item(struct ldlm_lock *lock, cfs_list_t *work_list)
  * Must be called with lr_lock held.
  */
 void ldlm_add_ast_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
-                            cfs_list_t *work_list)
+                           struct list_head *work_list)
 {
         ENTRY;
         check_res_locked(lock->l_resource);
@@ -765,12 +712,12 @@ void ldlm_add_ast_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
  */
 void ldlm_lock_addref(struct lustre_handle *lockh, __u32 mode)
 {
-        struct ldlm_lock *lock;
+       struct ldlm_lock *lock;
 
-        lock = ldlm_handle2lock(lockh);
-        LASSERT(lock != NULL);
-        ldlm_lock_addref_internal(lock, mode);
-        LDLM_LOCK_PUT(lock);
+       lock = ldlm_handle2lock(lockh);
+       LASSERTF(lock != NULL, "Non-existing lock: "LPX64"\n", lockh->cookie);
+       ldlm_lock_addref_internal(lock, mode);
+       LDLM_LOCK_PUT(lock);
 }
 EXPORT_SYMBOL(ldlm_lock_addref);
 
@@ -890,10 +837,16 @@ void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
                ldlm_set_cbpending(lock);
         }
 
-        if (!lock->l_readers && !lock->l_writers &&
-           ldlm_is_cbpending(lock)) {
-                /* If we received a blocked AST and this was the last reference,
-                 * run the callback. */
+       if (!lock->l_readers && !lock->l_writers &&
+           (ldlm_is_cbpending(lock) || lock->l_req_mode == LCK_GROUP)) {
+               /* If we received a blocked AST and this was the last reference,
+                * run the callback.
+                * Group locks are special:
+                * They must not go in LRU, but they are not called back
+                * like non-group locks, instead they are manually released.
+                * They have an l_writers reference which they keep until
+                * they are manually released, so we remove them when they have
+                * no more reader or writer references. - LU-6368 */
                if (ldlm_is_ns_srv(lock) && lock->l_export)
                         CERROR("FL_CBPENDING set on non-local lock--just a "
                                "warning\n");
@@ -956,7 +909,6 @@ EXPORT_SYMBOL(ldlm_lock_decref);
  * \a lockh and mark it for subsequent cancellation once r/w refcount
  * drops to zero instead of putting into LRU.
  *
- * Typical usage is for GROUP locks which we cannot allow to be cached.
  */
 void ldlm_lock_decref_and_cancel(struct lustre_handle *lockh, __u32 mode)
 {
@@ -975,9 +927,9 @@ void ldlm_lock_decref_and_cancel(struct lustre_handle *lockh, __u32 mode)
 EXPORT_SYMBOL(ldlm_lock_decref_and_cancel);
 
 struct sl_insert_point {
-        cfs_list_t *res_link;
-        cfs_list_t *mode_link;
-        cfs_list_t *policy_link;
+       struct list_head *res_link;
+       struct list_head *mode_link;
+       struct list_head *policy_link;
 };
 
 /**
@@ -994,18 +946,18 @@ struct sl_insert_point {
  * NOTE: called by
  *  - ldlm_grant_lock_with_skiplist
  */
-static void search_granted_lock(cfs_list_t *queue,
+static void search_granted_lock(struct list_head *queue,
                                 struct ldlm_lock *req,
                                 struct sl_insert_point *prev)
 {
-        cfs_list_t *tmp;
+       struct list_head *tmp;
         struct ldlm_lock *lock, *mode_end, *policy_end;
         ENTRY;
 
-        cfs_list_for_each(tmp, queue) {
-                lock = cfs_list_entry(tmp, struct ldlm_lock, l_res_link);
+       list_for_each(tmp, queue) {
+               lock = list_entry(tmp, struct ldlm_lock, l_res_link);
 
-                mode_end = cfs_list_entry(lock->l_sl_mode.prev,
+               mode_end = list_entry(lock->l_sl_mode.prev,
                                           struct ldlm_lock, l_sl_mode);
 
                 if (lock->l_req_mode != req->l_req_mode) {
@@ -1025,7 +977,7 @@ static void search_granted_lock(cfs_list_t *queue,
                 } else if (lock->l_resource->lr_type == LDLM_IBITS) {
                         for (;;) {
                                 policy_end =
-                                        cfs_list_entry(lock->l_sl_policy.prev,
+                                       list_entry(lock->l_sl_policy.prev,
                                                        struct ldlm_lock,
                                                        l_sl_policy);
 
@@ -1049,7 +1001,7 @@ static void search_granted_lock(cfs_list_t *queue,
 
                                 /* go to next policy group within mode group */
                                 tmp = policy_end->l_res_link.next;
-                                lock = cfs_list_entry(tmp, struct ldlm_lock,
+                               lock = list_entry(tmp, struct ldlm_lock,
                                                       l_res_link);
                         }  /* loop over policy groups within the mode group */
 
@@ -1095,20 +1047,20 @@ static void ldlm_granted_list_add_lock(struct ldlm_lock *lock,
                 return;
         }
 
-        LASSERT(cfs_list_empty(&lock->l_res_link));
-        LASSERT(cfs_list_empty(&lock->l_sl_mode));
-        LASSERT(cfs_list_empty(&lock->l_sl_policy));
+       LASSERT(list_empty(&lock->l_res_link));
+       LASSERT(list_empty(&lock->l_sl_mode));
+       LASSERT(list_empty(&lock->l_sl_policy));
 
        /*
         * lock->link == prev->link means lock is first starting the group.
         * Don't re-add to itself to suppress kernel warnings.
         */
        if (&lock->l_res_link != prev->res_link)
-               cfs_list_add(&lock->l_res_link, prev->res_link);
+               list_add(&lock->l_res_link, prev->res_link);
        if (&lock->l_sl_mode != prev->mode_link)
-               cfs_list_add(&lock->l_sl_mode, prev->mode_link);
+               list_add(&lock->l_sl_mode, prev->mode_link);
        if (&lock->l_sl_policy != prev->policy_link)
-               cfs_list_add(&lock->l_sl_policy, prev->policy_link);
+               list_add(&lock->l_sl_policy, prev->policy_link);
 
         EXIT;
 }
@@ -1140,7 +1092,7 @@ static void ldlm_grant_lock_with_skiplist(struct ldlm_lock *lock)
  *
  * must be called with lr_lock held
  */
-void ldlm_grant_lock(struct ldlm_lock *lock, cfs_list_t *work_list)
+void ldlm_grant_lock(struct ldlm_lock *lock, struct list_head *work_list)
 {
         struct ldlm_resource *res = lock->l_resource;
         ENTRY;
@@ -1178,87 +1130,167 @@ void ldlm_grant_lock(struct ldlm_lock *lock, cfs_list_t *work_list)
 }
 
 /**
- * Search for a lock with given properties in a queue.
+ * Describe the overlap between two locks.  itree_overlap_cb data.
+ */
+struct lock_match_data {
+       struct ldlm_lock    *lmd_old;
+       struct ldlm_lock    *lmd_lock;
+       ldlm_mode_t         *lmd_mode;
+       ldlm_policy_data_t  *lmd_policy;
+       __u64                lmd_flags;
+       int                  lmd_unref;
+};
+
+/**
+ * Check if the given @lock meets the criteria for a match.
+ * A reference on the lock is taken if matched.
  *
- * \retval a referenced lock or NULL.  See the flag descriptions below, in the
- * comment above ldlm_lock_match
+ * \param lock     test-against this lock
+ * \param data    parameters
  */
-static struct ldlm_lock *search_queue(cfs_list_t *queue,
-                                      ldlm_mode_t *mode,
-                                      ldlm_policy_data_t *policy,
-                                      struct ldlm_lock *old_lock,
-                                     __u64 flags, int unref)
-{
-        struct ldlm_lock *lock;
-        cfs_list_t       *tmp;
+static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
+{
+       ldlm_policy_data_t *lpol = &lock->l_policy_data;
+       ldlm_mode_t match;
+
+       if (lock == data->lmd_old)
+               return INTERVAL_ITER_STOP;
+
+       /* Check if this lock can be matched.
+        * Used by LU-2919(exclusive open) for open lease lock */
+       if (ldlm_is_excl(lock))
+               return INTERVAL_ITER_CONT;
+
+       /* llite sometimes wants to match locks that will be
+        * canceled when their users drop, but we allow it to match
+        * if it passes in CBPENDING and the lock still has users.
+        * this is generally only going to be used by children
+        * whose parents already hold a lock so forward progress
+        * can still happen. */
+       if (ldlm_is_cbpending(lock) &&
+           !(data->lmd_flags & LDLM_FL_CBPENDING))
+               return INTERVAL_ITER_CONT;
+       if (!data->lmd_unref && ldlm_is_cbpending(lock) &&
+           lock->l_readers == 0 && lock->l_writers == 0)
+               return INTERVAL_ITER_CONT;
+
+       if (!(lock->l_req_mode & *data->lmd_mode))
+               return INTERVAL_ITER_CONT;
+       match = lock->l_req_mode;
+
+       switch (lock->l_resource->lr_type) {
+       case LDLM_EXTENT:
+               if (lpol->l_extent.start > data->lmd_policy->l_extent.start ||
+                   lpol->l_extent.end < data->lmd_policy->l_extent.end)
+                       return INTERVAL_ITER_CONT;
+
+               if (unlikely(match == LCK_GROUP) &&
+                   data->lmd_policy->l_extent.gid != LDLM_GID_ANY &&
+                   lpol->l_extent.gid != data->lmd_policy->l_extent.gid)
+                       return INTERVAL_ITER_CONT;
+               break;
+       case LDLM_IBITS:
+               /* We match if we have existing lock with same or wider set
+                  of bits. */
+               if ((lpol->l_inodebits.bits &
+                    data->lmd_policy->l_inodebits.bits) !=
+                   data->lmd_policy->l_inodebits.bits)
+                       return INTERVAL_ITER_CONT;
+               break;
+       default:
+               ;
+       }
 
-        cfs_list_for_each(tmp, queue) {
-                ldlm_mode_t match;
+       /* We match if we have existing lock with same or wider set
+          of bits. */
+       if (!data->lmd_unref && LDLM_HAVE_MASK(lock, GONE))
+               return INTERVAL_ITER_CONT;
 
-                lock = cfs_list_entry(tmp, struct ldlm_lock, l_res_link);
+       if ((data->lmd_flags & LDLM_FL_LOCAL_ONLY) &&
+           !ldlm_is_local(lock))
+               return INTERVAL_ITER_CONT;
 
-                if (lock == old_lock)
-                        break;
+       if (data->lmd_flags & LDLM_FL_TEST_LOCK) {
+               LDLM_LOCK_GET(lock);
+               ldlm_lock_touch_in_lru(lock);
+       } else {
+               ldlm_lock_addref_internal_nolock(lock, match);
+       }
 
-               /* Check if this lock can be matched.
-                * Used by LU-2919(exclusive open) for open lease lock */
-               if (ldlm_is_excl(lock))
-                       continue;
+       *data->lmd_mode = match;
+       data->lmd_lock = lock;
 
-                /* llite sometimes wants to match locks that will be
-                 * canceled when their users drop, but we allow it to match
-                 * if it passes in CBPENDING and the lock still has users.
-                 * this is generally only going to be used by children
-                 * whose parents already hold a lock so forward progress
-                 * can still happen. */
-               if (ldlm_is_cbpending(lock) &&
-                    !(flags & LDLM_FL_CBPENDING))
-                        continue;
-               if (!unref && ldlm_is_cbpending(lock) &&
-                    lock->l_readers == 0 && lock->l_writers == 0)
-                        continue;
+       return INTERVAL_ITER_STOP;
+}
 
-                if (!(lock->l_req_mode & *mode))
-                        continue;
-                match = lock->l_req_mode;
+static unsigned int itree_overlap_cb(struct interval_node *in, void *args)
+{
+       struct ldlm_interval *node = to_ldlm_interval(in);
+       struct lock_match_data *data = args;
+       struct ldlm_lock *lock;
+       int rc;
 
-                if (lock->l_resource->lr_type == LDLM_EXTENT &&
-                    (lock->l_policy_data.l_extent.start >
-                     policy->l_extent.start ||
-                     lock->l_policy_data.l_extent.end < policy->l_extent.end))
-                        continue;
+       list_for_each_entry(lock, &node->li_group, l_sl_policy) {
+               rc = lock_matches(lock, data);
+               if (rc == INTERVAL_ITER_STOP)
+                       return INTERVAL_ITER_STOP;
+       }
+       return INTERVAL_ITER_CONT;
+}
 
-                if (unlikely(match == LCK_GROUP) &&
-                    lock->l_resource->lr_type == LDLM_EXTENT &&
-                    lock->l_policy_data.l_extent.gid != policy->l_extent.gid)
-                        continue;
+/**
+ * Search for a lock with given parameters in interval trees.
+ *
+ * \param res      search for a lock in this resource
+ * \param data    parameters
+ *
+ * \retval a referenced lock or NULL.
+ */
+static struct ldlm_lock *search_itree(struct ldlm_resource *res,
+                                     struct lock_match_data *data)
+{
+       struct interval_node_extent ext = {
+               .start     = data->lmd_policy->l_extent.start,
+               .end       = data->lmd_policy->l_extent.end
+       };
+       int idx;
 
-                /* We match if we have existing lock with same or wider set
-                   of bits. */
-                if (lock->l_resource->lr_type == LDLM_IBITS &&
-                     ((lock->l_policy_data.l_inodebits.bits &
-                      policy->l_inodebits.bits) !=
-                      policy->l_inodebits.bits))
-                        continue;
+       for (idx = 0; idx < LCK_MODE_NUM; idx++) {
+               struct ldlm_interval_tree *tree = &res->lr_itree[idx];
 
-               if (!unref && LDLM_HAVE_MASK(lock, GONE))
-                        continue;
+               if (tree->lit_root == NULL)
+                       continue;
 
-                if ((flags & LDLM_FL_LOCAL_ONLY) &&
-                   !ldlm_is_local(lock))
-                        continue;
+               if (!(tree->lit_mode & *data->lmd_mode))
+                       continue;
 
-                if (flags & LDLM_FL_TEST_LOCK) {
-                        LDLM_LOCK_GET(lock);
-                        ldlm_lock_touch_in_lru(lock);
-                } else {
-                        ldlm_lock_addref_internal_nolock(lock, match);
-                }
-                *mode = match;
-                return lock;
-        }
+               interval_search(tree->lit_root, &ext,
+                               itree_overlap_cb, data);
+       }
+       return data->lmd_lock;
+}
+
+
+/**
+ * Search for a lock with given properties in a queue.
+ *
+ * \param queue    search for a lock in this queue
+ * \param data    parameters
+ *
+ * \retval a referenced lock or NULL.
+ */
+static struct ldlm_lock *search_queue(struct list_head *queue,
+                                     struct lock_match_data *data)
+{
+       struct ldlm_lock *lock;
+       int rc;
 
-        return NULL;
+       list_for_each_entry(lock, queue, l_res_link) {
+               rc = lock_matches(lock, data);
+               if (rc == INTERVAL_ITER_STOP)
+                       return data->lmd_lock;
+       }
+       return NULL;
 }
 
 void ldlm_lock_fail_match_locked(struct ldlm_lock *lock)
@@ -1276,7 +1308,6 @@ void ldlm_lock_fail_match(struct ldlm_lock *lock)
         ldlm_lock_fail_match_locked(lock);
         unlock_res_and_lock(lock);
 }
-EXPORT_SYMBOL(ldlm_lock_fail_match);
 
 /**
  * Mark lock as "matchable" by OST.
@@ -1336,47 +1367,55 @@ EXPORT_SYMBOL(ldlm_lock_allow_match);
  */
 ldlm_mode_t ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags,
                             const struct ldlm_res_id *res_id, ldlm_type_t type,
-                            ldlm_policy_data_t *policy, ldlm_mode_t mode,
-                            struct lustre_handle *lockh, int unref)
-{
-        struct ldlm_resource *res;
-        struct ldlm_lock *lock, *old_lock = NULL;
-        int rc = 0;
-        ENTRY;
+                           ldlm_policy_data_t *policy, ldlm_mode_t mode,
+                           struct lustre_handle *lockh, int unref)
+{
+       struct lock_match_data data = {
+               .lmd_old        = NULL,
+               .lmd_lock       = NULL,
+               .lmd_mode       = &mode,
+               .lmd_policy     = policy,
+               .lmd_flags      = flags,
+               .lmd_unref      = unref,
+       };
+       struct ldlm_resource *res;
+       struct ldlm_lock *lock;
+       int rc = 0;
+       ENTRY;
 
-        if (ns == NULL) {
-                old_lock = ldlm_handle2lock(lockh);
-                LASSERT(old_lock);
+       if (ns == NULL) {
+               data.lmd_old = ldlm_handle2lock(lockh);
+               LASSERT(data.lmd_old != NULL);
 
-                ns = ldlm_lock_to_ns(old_lock);
-                res_id = &old_lock->l_resource->lr_name;
-                type = old_lock->l_resource->lr_type;
-                mode = old_lock->l_req_mode;
-        }
+               ns = ldlm_lock_to_ns(data.lmd_old);
+               res_id = &data.lmd_old->l_resource->lr_name;
+               type = data.lmd_old->l_resource->lr_type;
+               *data.lmd_mode = data.lmd_old->l_req_mode;
+       }
 
        res = ldlm_resource_get(ns, NULL, res_id, type, 0);
        if (IS_ERR(res)) {
-               LASSERT(old_lock == NULL);
+               LASSERT(data.lmd_old == NULL);
                RETURN(0);
        }
 
-        LDLM_RESOURCE_ADDREF(res);
-        lock_res(res);
+       LDLM_RESOURCE_ADDREF(res);
+       lock_res(res);
 
-        lock = search_queue(&res->lr_granted, &mode, policy, old_lock,
-                            flags, unref);
-        if (lock != NULL)
-                GOTO(out, rc = 1);
-        if (flags & LDLM_FL_BLOCK_GRANTED)
-                GOTO(out, rc = 0);
-        lock = search_queue(&res->lr_converting, &mode, policy, old_lock,
-                            flags, unref);
-        if (lock != NULL)
-                GOTO(out, rc = 1);
-        lock = search_queue(&res->lr_waiting, &mode, policy, old_lock,
-                            flags, unref);
-        if (lock != NULL)
-                GOTO(out, rc = 1);
+       if (res->lr_type == LDLM_EXTENT)
+               lock = search_itree(res, &data);
+       else
+               lock = search_queue(&res->lr_granted, &data);
+       if (lock != NULL)
+               GOTO(out, rc = 1);
+       if (flags & LDLM_FL_BLOCK_GRANTED)
+               GOTO(out, rc = 0);
+       lock = search_queue(&res->lr_converting, &data);
+       if (lock != NULL)
+               GOTO(out, rc = 1);
+       lock = search_queue(&res->lr_waiting, &data);
+       if (lock != NULL)
+               GOTO(out, rc = 1);
 
         EXIT;
  out:
@@ -1451,10 +1490,10 @@ ldlm_mode_t ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags,
                                   (type == LDLM_PLAIN || type == LDLM_IBITS) ?
                                         res_id->name[3] : policy->l_extent.end);
         }
-        if (old_lock)
-                LDLM_LOCK_PUT(old_lock);
+       if (data.lmd_old != NULL)
+               LDLM_LOCK_PUT(data.lmd_old);
 
-        return rc ? mode : 0;
+       return rc ? mode : 0;
 }
 EXPORT_SYMBOL(ldlm_lock_match);
 
@@ -1676,7 +1715,6 @@ ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
         struct ldlm_interval *node = NULL;
         ENTRY;
 
-        lock->l_last_activity = cfs_time_current_sec();
         /* policies are not executed on the client or during replay */
         if ((*flags & (LDLM_FL_HAS_INTENT|LDLM_FL_REPLAY)) == LDLM_FL_HAS_INTENT
             && !local && ns->ns_policy) {
@@ -1700,6 +1738,19 @@ ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
                 }
         }
 
+       if (*flags & LDLM_FL_RESENT) {
+               /* Reconstruct LDLM_FL_SRV_ENQ_MASK @flags for reply.
+                * Set LOCK_CHANGED always.
+                * Check if the lock is granted for BLOCK_GRANTED.
+                * Take NO_TIMEOUT from the lock as it is inherited through
+                * LDLM_FL_INHERIT_MASK */
+               *flags |= LDLM_FL_LOCK_CHANGED;
+               if (lock->l_req_mode != lock->l_granted_mode)
+                       *flags |= LDLM_FL_BLOCK_GRANTED;
+               *flags |= lock->l_flags & LDLM_FL_NO_TIMEOUT;
+               RETURN(ELDLM_OK);
+       }
+
        /* For a replaying lock, it might be already in granted list. So
         * unlinking the lock will cause the interval node to be freed, we
         * have to allocate the interval node early otherwise we can't regrant
@@ -1712,8 +1763,7 @@ ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
                 /* The server returned a blocked lock, but it was granted
                  * before we got a chance to actually enqueue it.  We don't
                  * need to do anything else. */
-                *flags &= ~(LDLM_FL_BLOCK_GRANTED |
-                            LDLM_FL_BLOCK_CONV | LDLM_FL_BLOCK_WAIT);
+                *flags &= ~LDLM_FL_BLOCKED_MASK;
                GOTO(out, rc = ELDLM_OK);
         }
 
@@ -1724,7 +1774,7 @@ ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
                         GOTO(out, rc = -ENOMEM);
                 }
 
-                CFS_INIT_LIST_HEAD(&node->li_group);
+               INIT_LIST_HEAD(&node->li_group);
                 ldlm_interval_attach(node, lock);
                 node = NULL;
         }
@@ -1795,10 +1845,10 @@ out:
  *
  * Must be called with resource lock held.
  */
-int ldlm_reprocess_queue(struct ldlm_resource *res, cfs_list_t *queue,
-                         cfs_list_t *work_list)
+int ldlm_reprocess_queue(struct ldlm_resource *res, struct list_head *queue,
+                        struct list_head *work_list)
 {
-        cfs_list_t *tmp, *pos;
+       struct list_head *tmp, *pos;
         ldlm_processing_policy policy;
        __u64 flags;
         int rc = LDLM_ITER_CONTINUE;
@@ -1810,9 +1860,9 @@ int ldlm_reprocess_queue(struct ldlm_resource *res, cfs_list_t *queue,
         policy = ldlm_processing_policy_table[res->lr_type];
         LASSERT(policy);
 
-        cfs_list_for_each_safe(tmp, pos, queue) {
+       list_for_each_safe(tmp, pos, queue) {
                 struct ldlm_lock *pending;
-                pending = cfs_list_entry(tmp, struct ldlm_lock, l_res_link);
+               pending = list_entry(tmp, struct ldlm_lock, l_res_link);
 
                 CDEBUG(D_INFO, "Reprocessing lock %p\n", pending);
 
@@ -1838,14 +1888,14 @@ ldlm_work_bl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
        struct ldlm_lock       *lock;
        ENTRY;
 
-       if (cfs_list_empty(arg->list))
+       if (list_empty(arg->list))
                RETURN(-ENOENT);
 
-       lock = cfs_list_entry(arg->list->next, struct ldlm_lock, l_bl_ast);
+       lock = list_entry(arg->list->next, struct ldlm_lock, l_bl_ast);
 
        /* nobody should touch l_bl_ast */
        lock_res_and_lock(lock);
-       cfs_list_del_init(&lock->l_bl_ast);
+       list_del_init(&lock->l_bl_ast);
 
        LASSERT(ldlm_is_ast_sent(lock));
        LASSERT(lock->l_bl_ast_run == 0);
@@ -1875,10 +1925,10 @@ ldlm_work_cp_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
        ldlm_completion_callback completion_callback;
        ENTRY;
 
-       if (cfs_list_empty(arg->list))
+       if (list_empty(arg->list))
                RETURN(-ENOENT);
 
-       lock = cfs_list_entry(arg->list->next, struct ldlm_lock, l_cp_ast);
+       lock = list_entry(arg->list->next, struct ldlm_lock, l_cp_ast);
 
        /* It's possible to receive a completion AST before we've set
         * the l_completion_ast pointer: either because the AST arrived
@@ -1893,7 +1943,7 @@ ldlm_work_cp_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
 
        /* nobody should touch l_cp_ast */
        lock_res_and_lock(lock);
-       cfs_list_del_init(&lock->l_cp_ast);
+       list_del_init(&lock->l_cp_ast);
        LASSERT(ldlm_is_cp_reqd(lock));
        /* save l_completion_ast since it can be changed by
         * mds_intent_policy(), see bug 14225 */
@@ -1920,11 +1970,11 @@ ldlm_work_revoke_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
        struct ldlm_lock       *lock;
        ENTRY;
 
-       if (cfs_list_empty(arg->list))
+       if (list_empty(arg->list))
                RETURN(-ENOENT);
 
-       lock = cfs_list_entry(arg->list->next, struct ldlm_lock, l_rk_ast);
-       cfs_list_del_init(&lock->l_rk_ast);
+       lock = list_entry(arg->list->next, struct ldlm_lock, l_rk_ast);
+       list_del_init(&lock->l_rk_ast);
 
        /* the desc just pretend to exclusive */
        ldlm_lock2desc(lock, &desc);
@@ -1948,12 +1998,12 @@ int ldlm_work_gl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
        int                              rc = 0;
        ENTRY;
 
-       if (cfs_list_empty(arg->list))
+       if (list_empty(arg->list))
                RETURN(-ENOENT);
 
-       gl_work = cfs_list_entry(arg->list->next, struct ldlm_glimpse_work,
+       gl_work = list_entry(arg->list->next, struct ldlm_glimpse_work,
                                 gl_list);
-       cfs_list_del_init(&gl_work->gl_list);
+       list_del_init(&gl_work->gl_list);
 
        lock = gl_work->gl_lock;
 
@@ -1978,14 +2028,14 @@ int ldlm_work_gl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
  * Used on server to send multiple ASTs together instead of sending one by
  * one.
  */
-int ldlm_run_ast_work(struct ldlm_namespace *ns, cfs_list_t *rpc_list,
+int ldlm_run_ast_work(struct ldlm_namespace *ns, struct list_head *rpc_list,
                       ldlm_desc_ast_t ast_type)
 {
        struct ldlm_cb_set_arg *arg;
        set_producer_func       work_ast_lock;
        int                     rc;
 
-       if (cfs_list_empty(rpc_list))
+       if (list_empty(rpc_list))
                RETURN(0);
 
        OBD_ALLOC_PTR(arg);
@@ -2041,8 +2091,8 @@ static int reprocess_one_queue(struct ldlm_resource *res, void *closure)
         return LDLM_ITER_CONTINUE;
 }
 
-static int ldlm_reprocess_res(cfs_hash_t *hs, cfs_hash_bd_t *bd,
-                              cfs_hlist_node_t *hnode, void *arg)
+static int ldlm_reprocess_res(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                             struct hlist_node *hnode, void *arg)
 {
         struct ldlm_resource *res = cfs_hash_object(hs, hnode);
         int    rc;
@@ -2066,7 +2116,6 @@ void ldlm_reprocess_all_ns(struct ldlm_namespace *ns)
         }
         EXIT;
 }
-EXPORT_SYMBOL(ldlm_reprocess_all_ns);
 
 /**
  * Try to grant all waiting locks on a resource.
@@ -2078,11 +2127,12 @@ EXPORT_SYMBOL(ldlm_reprocess_all_ns);
  */
 void ldlm_reprocess_all(struct ldlm_resource *res)
 {
-        CFS_LIST_HEAD(rpc_list);
-
+       struct list_head rpc_list;
 #ifdef HAVE_SERVER_SUPPORT
         int rc;
         ENTRY;
+
+       INIT_LIST_HEAD(&rpc_list);
         /* Local lock trees don't get reprocessed. */
         if (ns_is_client(ldlm_res_to_ns(res))) {
                 EXIT;
@@ -2099,11 +2149,13 @@ restart:
         rc = ldlm_run_ast_work(ldlm_res_to_ns(res), &rpc_list,
                                LDLM_WORK_CP_AST);
         if (rc == -ERESTART) {
-                LASSERT(cfs_list_empty(&rpc_list));
+               LASSERT(list_empty(&rpc_list));
                 goto restart;
         }
 #else
         ENTRY;
+
+       INIT_LIST_HEAD(&rpc_list);
         if (!ns_is_client(ldlm_res_to_ns(res))) {
                 CERROR("This is client-side-only module, cannot handle "
                        "LDLM_NAMESPACE_SERVER resource type lock.\n");
@@ -2144,8 +2196,8 @@ void ldlm_unlink_lock_skiplist(struct ldlm_lock *req)
             req->l_resource->lr_type != LDLM_IBITS)
                 return;
 
-        cfs_list_del_init(&req->l_sl_policy);
-        cfs_list_del_init(&req->l_sl_mode);
+       list_del_init(&req->l_sl_policy);
+       list_del_init(&req->l_sl_mode);
 }
 
 /**
@@ -2175,10 +2227,7 @@ void ldlm_lock_cancel(struct ldlm_lock *lock)
         /* Releases cancel callback. */
         ldlm_cancel_callback(lock);
 
-       /* Yes, second time, just in case it was added again while we were
-        * running with no res lock in ldlm_cancel_callback */
-       if (ldlm_is_waited(lock))
-               ldlm_del_waiting_lock(lock);
+       LASSERT(!ldlm_is_waited(lock));
 
         ldlm_resource_unlink_lock(lock);
         ldlm_lock_destroy_nolock(lock);
@@ -2224,8 +2273,9 @@ struct export_cl_data {
  * Iterator function for ldlm_cancel_locks_for_export.
  * Cancels passed locks.
  */
-int ldlm_cancel_locks_for_export_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd,
-                                    cfs_hlist_node_t *hnode, void *data)
+static int
+ldlm_cancel_locks_for_export_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                               struct hlist_node *hnode, void *data)
 
 {
        struct export_cl_data   *ecl = (struct export_cl_data *)data;
@@ -2315,7 +2365,7 @@ EXPORT_SYMBOL(ldlm_lock_downgrade);
 struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
                                        __u32 *flags)
 {
-       CFS_LIST_HEAD(rpc_list);
+       struct list_head rpc_list;
        struct ldlm_resource *res;
        struct ldlm_namespace *ns;
        int granted = 0;
@@ -2326,6 +2376,7 @@ struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
        struct ldlm_interval *node;
        ENTRY;
 
+       INIT_LIST_HEAD(&rpc_list);
        /* Just return if mode is unchanged. */
        if (new_mode == lock->l_granted_mode) {
                *flags |= LDLM_FL_BLOCK_GRANTED;
@@ -2366,7 +2417,7 @@ struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
                         /* FIXME: ugly code, I have to attach the lock to a
                          * interval node again since perhaps it will be granted
                          * soon */
-                        CFS_INIT_LIST_HEAD(&node->li_group);
+                       INIT_LIST_HEAD(&node->li_group);
                         ldlm_interval_attach(node, lock);
                         node = NULL;
                 }
@@ -2431,7 +2482,6 @@ struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
                 OBD_SLAB_FREE(node, ldlm_interval_slab, sizeof(*node));
         RETURN(res);
 }
-EXPORT_SYMBOL(ldlm_lock_convert);
 
 /**
  * Print lock with lock handle \a lockh description into debug log.