Whamcloud - gitweb
LU-6529 ldlm: cancel aged locks for LRUR
[fs/lustre-release.git] / lustre / ldlm / ldlm_request.c
index defd2ac..684062f 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/
@@ -131,7 +131,6 @@ int ldlm_expired_completion_wait(void *data)
 
         RETURN(0);
 }
-EXPORT_SYMBOL(ldlm_expired_completion_wait);
 
 /**
  * Calculate the Completion timeout (covering enqueue, BL AST, data flush,
@@ -414,7 +413,6 @@ int ldlm_glimpse_ast(struct ldlm_lock *lock, void *reqp)
 {
         return -ELDLM_NO_LOCK_DATA;
 }
-EXPORT_SYMBOL(ldlm_glimpse_ast);
 
 /**
  * Enqueue a local lock (typically on a server).
@@ -555,7 +553,6 @@ int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
         struct ldlm_lock *lock;
         struct ldlm_reply *reply;
         int cleanup_phase = 1;
-       int size = 0;
         ENTRY;
 
         lock = ldlm_handle2lock(lockh);
@@ -582,8 +579,8 @@ int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
        if (reply == NULL)
                GOTO(cleanup, rc = -EPROTO);
 
-       if (lvb_len != 0) {
-               LASSERT(lvb != NULL);
+       if (lvb_len > 0) {
+               int size = 0;
 
                size = req_capsule_get_size(&req->rq_pill, &RMF_DLM_LVB,
                                            RCL_SERVER);
@@ -596,13 +593,14 @@ int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
                                   lvb_len, size);
                        GOTO(cleanup, rc = -EINVAL);
                }
+               lvb_len = size;
        }
 
        if (rc == ELDLM_LOCK_ABORTED) {
-               if (lvb_len != 0)
+               if (lvb_len > 0 && lvb != NULL)
                        rc = ldlm_fill_lvb(lock, &req->rq_pill, RCL_SERVER,
-                                          lvb, size);
-               GOTO(cleanup, rc = (rc != 0 ? rc : ELDLM_LOCK_ABORTED));
+                                          lvb, lvb_len);
+               GOTO(cleanup, rc = rc ? : ELDLM_LOCK_ABORTED);
        }
 
         /* lock enqueued on the server */
@@ -676,7 +674,7 @@ int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
 
         /* If the lock has already been granted by a completion AST, don't
          * clobber the LVB with an older one. */
-       if (lvb_len != 0) {
+       if (lvb_len > 0) {
                /* We must lock or a racing completion might update lvb without
                 * letting us know and we'll clobber the correct value.
                 * Cannot unlock after the check either, a that still leaves
@@ -684,7 +682,7 @@ int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
                lock_res_and_lock(lock);
                if (lock->l_req_mode != lock->l_granted_mode)
                        rc = ldlm_fill_lvb(lock, &req->rq_pill, RCL_SERVER,
-                                          lock->l_lvb_data, size);
+                                          lock->l_lvb_data, lvb_len);
                unlock_res_and_lock(lock);
                if (rc < 0) {
                        cleanup_phase = 1;
@@ -703,11 +701,11 @@ int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
                 }
         }
 
-        if (lvb_len && lvb != NULL) {
-                /* Copy the LVB here, and not earlier, because the completion
-                 * AST (if any) can override what we got in the reply */
-                memcpy(lvb, lock->l_lvb_data, lvb_len);
-        }
+       if (lvb_len > 0 && lvb != NULL) {
+               /* Copy the LVB here, and not earlier, because the completion
+                * AST (if any) can override what we got in the reply */
+               memcpy(lvb, lock->l_lvb_data, lvb_len);
+       }
 
         LDLM_DEBUG(lock, "client-side enqueue END");
         EXIT;
@@ -745,16 +743,16 @@ static inline int ldlm_capsule_handles_avail(struct req_capsule *pill,
                                              enum req_location loc,
                                              int off)
 {
-        int size = req_capsule_msg_size(pill, loc);
-        return ldlm_req_handles_avail(size, off);
+       __u32 size = req_capsule_msg_size(pill, loc);
+       return ldlm_req_handles_avail(size, off);
 }
 
 static inline int ldlm_format_handles_avail(struct obd_import *imp,
                                             const struct req_format *fmt,
                                             enum req_location loc, int off)
 {
-        int size = req_capsule_fmt_size(imp->imp_msg_magic, fmt, loc);
-        return ldlm_req_handles_avail(size, off);
+       __u32 size = req_capsule_fmt_size(imp->imp_msg_magic, fmt, loc);
+       return ldlm_req_handles_avail(size, off);
 }
 
 /**
@@ -814,7 +812,7 @@ int ldlm_prep_elc_req(struct obd_export *exp, struct ptlrpc_request *req,
                         dlm = req_capsule_client_get(pill, &RMF_DLM_REQ);
                         LASSERT(dlm);
                         /* Skip first lock handler in ldlm_request_pack(),
-                         * this method will incrment @lock_count according
+                        * this method will increment @lock_count according
                          * to the lock handle amount actually written to
                          * the buffer. */
                         dlm->lock_count = canceloff;
@@ -1099,7 +1097,6 @@ int ldlm_cli_convert(struct lustre_handle *lockh, int new_mode, __u32 *flags)
         ptlrpc_req_finished(req);
         return rc;
 }
-EXPORT_SYMBOL(ldlm_cli_convert);
 
 /**
  * Cancel locks locally.
@@ -1270,7 +1267,6 @@ int ldlm_cli_cancel_req(struct obd_export *exp, struct list_head *cancels,
 out:
         return sent ? sent : rc;
 }
-EXPORT_SYMBOL(ldlm_cli_cancel_req);
 
 static inline struct ldlm_pool *ldlm_imp2pl(struct obd_import *imp)
 {
@@ -1326,7 +1322,6 @@ int ldlm_cli_update_pool(struct ptlrpc_request *req)
 
         RETURN(0);
 }
-EXPORT_SYMBOL(ldlm_cli_update_pool);
 
 /**
  * Client side lock cancel.
@@ -1428,7 +1423,6 @@ int ldlm_cli_cancel_list_local(struct list_head *cancels, int count,
 
         RETURN(count);
 }
-EXPORT_SYMBOL(ldlm_cli_cancel_list_local);
 
 /**
  * Cancel as many locks as possible w/o sending any RPCs (e.g. to write back
@@ -1486,6 +1480,12 @@ static ldlm_policy_res_t ldlm_cancel_lrur_policy(struct ldlm_namespace *ns,
        if (count && added >= count)
                return LDLM_POLICY_KEEP_LOCK;
 
+       /* Despite of the LV, It doesn't make sense to keep the lock which
+        * is unused for ns_max_age time. */
+       if (cfs_time_after(cfs_time_current(),
+                          cfs_time_add(lock->l_last_used, ns->ns_max_age)))
+               return LDLM_POLICY_CANCEL_LOCK;
+
        slv = ldlm_pool_get_slv(pl);
        lvf = ldlm_pool_get_lvf(pl);
        la = cfs_duration_sec(cfs_time_sub(cur,
@@ -1500,9 +1500,6 @@ static ldlm_policy_res_t ldlm_cancel_lrur_policy(struct ldlm_namespace *ns,
        if (slv == 0 || lv < slv)
                return LDLM_POLICY_KEEP_LOCK;
 
-       if (ns->ns_cancel != NULL && ns->ns_cancel(lock) == 0)
-               return LDLM_POLICY_KEEP_LOCK;
-
        return LDLM_POLICY_CANCEL_LOCK;
 }
 
@@ -1545,9 +1542,6 @@ static ldlm_policy_res_t ldlm_cancel_aged_policy(struct ldlm_namespace *ns,
                            cfs_time_add(lock->l_last_used, ns->ns_max_age)))
                return LDLM_POLICY_KEEP_LOCK;
 
-       if (ns->ns_cancel != NULL && ns->ns_cancel(lock) == 0)
-               return LDLM_POLICY_KEEP_LOCK;
-
        return LDLM_POLICY_CANCEL_LOCK;
 }
 
@@ -2001,7 +1995,6 @@ int ldlm_cli_cancel_unused(struct ldlm_namespace *ns,
                 RETURN(ELDLM_OK);
         }
 }
-EXPORT_SYMBOL(ldlm_cli_cancel_unused);
 
 /* Lock iterators. */
 
@@ -2042,7 +2035,6 @@ int ldlm_resource_foreach(struct ldlm_resource *res, ldlm_iterator_t iter,
         unlock_res(res);
         RETURN(rc);
 }
-EXPORT_SYMBOL(ldlm_resource_foreach);
 
 struct iter_helper_data {
         ldlm_iterator_t iter;
@@ -2075,7 +2067,6 @@ void ldlm_namespace_foreach(struct ldlm_namespace *ns,
                                  ldlm_res_iter_helper, &helper);
 
 }
-EXPORT_SYMBOL(ldlm_namespace_foreach);
 
 /* non-blocking function to manipulate a lock whose cb_data is being put away.
  * return  0:  find no resource
@@ -2326,4 +2317,3 @@ int ldlm_replay_locks(struct obd_import *imp)
 
        RETURN(rc);
 }
-EXPORT_SYMBOL(ldlm_replay_locks);