diff options
Diffstat (limited to 'drivers/staging/lustre/lustre/osc/osc_lock.c')
-rw-r--r-- | drivers/staging/lustre/lustre/osc/osc_lock.c | 146 |
1 files changed, 49 insertions, 97 deletions
diff --git a/drivers/staging/lustre/lustre/osc/osc_lock.c b/drivers/staging/lustre/lustre/osc/osc_lock.c index 640bc3d34709..5d7bdbfc871a 100644 --- a/drivers/staging/lustre/lustre/osc/osc_lock.c +++ b/drivers/staging/lustre/lustre/osc/osc_lock.c @@ -89,35 +89,49 @@ static struct ldlm_lock *osc_handle_ptr(struct lustre_handle *handle) */ static int osc_lock_invariant(struct osc_lock *ols) { - struct ldlm_lock *lock = osc_handle_ptr(&ols->ols_handle); - struct ldlm_lock *olock = ols->ols_lock; - int handle_used = lustre_handle_is_used(&ols->ols_handle); - - return - ergo(osc_lock_is_lockless(ols), - ols->ols_locklessable && ols->ols_lock == NULL) || - (ergo(olock != NULL, handle_used) && - ergo(olock != NULL, - olock->l_handle.h_cookie == ols->ols_handle.cookie) && - /* - * Check that ->ols_handle and ->ols_lock are consistent, but - * take into account that they are set at the different time. - */ - ergo(handle_used, - ergo(lock != NULL && olock != NULL, lock == olock) && - ergo(lock == NULL, olock == NULL)) && - ergo(ols->ols_state == OLS_CANCELLED, - olock == NULL && !handle_used) && - /* - * DLM lock is destroyed only after we have seen cancellation - * ast. - */ - ergo(olock != NULL && ols->ols_state < OLS_CANCELLED, - !olock->l_destroyed) && - ergo(ols->ols_state == OLS_GRANTED, - olock != NULL && - olock->l_req_mode == olock->l_granted_mode && - ols->ols_hold)); + struct ldlm_lock *lock = osc_handle_ptr(&ols->ols_handle); + struct ldlm_lock *olock = ols->ols_lock; + int handle_used = lustre_handle_is_used(&ols->ols_handle); + + if (ergo(osc_lock_is_lockless(ols), + ols->ols_locklessable && ols->ols_lock == NULL)) + return 1; + + /* + * If all the following "ergo"s are true, return 1, otherwise 0 + */ + if (! ergo(olock != NULL, handle_used)) + return 0; + + if (! ergo(olock != NULL, + olock->l_handle.h_cookie == ols->ols_handle.cookie)) + return 0; + + if (! ergo(handle_used, + ergo(lock != NULL && olock != NULL, lock == olock) && + ergo(lock == NULL, olock == NULL))) + return 0; + /* + * Check that ->ols_handle and ->ols_lock are consistent, but + * take into account that they are set at the different time. + */ + if (! ergo(ols->ols_state == OLS_CANCELLED, + olock == NULL && !handle_used)) + return 0; + /* + * DLM lock is destroyed only after we have seen cancellation + * ast. + */ + if (! ergo(olock != NULL && ols->ols_state < OLS_CANCELLED, + ((olock->l_flags & LDLM_FL_DESTROYED) == 0))) + return 0; + + if (! ergo(ols->ols_state == OLS_GRANTED, + olock != NULL && + olock->l_req_mode == olock->l_granted_mode && + ols->ols_hold)) + return 0; + return 1; } /***************************************************************************** @@ -261,7 +275,7 @@ static __u64 osc_enq2ldlm_flags(__u32 enqflags) if (enqflags & CEF_ASYNC) result |= LDLM_FL_HAS_INTENT; if (enqflags & CEF_DISCARD_DATA) - result |= LDLM_AST_DISCARD_DATA; + result |= LDLM_FL_AST_DISCARD_DATA; return result; } @@ -329,10 +343,8 @@ static void osc_lock_lvb_update(const struct lu_env *env, struct osc_lock *olck, struct cl_attr *attr; unsigned valid; - ENTRY; - if (!(olck->ols_flags & LDLM_FL_LVB_READY)) - RETURN_EXIT; + return; lvb = &olck->ols_lvb; obj = olck->ols_cl.cls_obj; @@ -378,8 +390,6 @@ static void osc_lock_lvb_update(const struct lu_env *env, struct osc_lock *olck, cl_object_attr_set(env, obj, attr, valid); cl_object_attr_unlock(obj); - - EXIT; } /** @@ -398,7 +408,6 @@ static void osc_lock_granted(const struct lu_env *env, struct osc_lock *olck, LASSERT(dlmlock->l_granted_mode == dlmlock->l_req_mode); - ENTRY; if (olck->ols_state < OLS_GRANTED) { lock = olck->ols_cl.cls_lock; ext = &dlmlock->l_policy_data.l_extent; @@ -428,7 +437,6 @@ static void osc_lock_granted(const struct lu_env *env, struct osc_lock *olck, LINVRNT(osc_lock_invariant(olck)); lock_res_and_lock(dlmlock); } - EXIT; } static void osc_lock_upcall0(const struct lu_env *env, struct osc_lock *olck) @@ -436,8 +444,6 @@ static void osc_lock_upcall0(const struct lu_env *env, struct osc_lock *olck) { struct ldlm_lock *dlmlock; - ENTRY; - dlmlock = ldlm_handle2lock_long(&olck->ols_handle, 0); LASSERT(dlmlock != NULL); @@ -483,7 +489,6 @@ static int osc_lock_upcall(void *cookie, int errcode) struct lu_env *env; struct cl_env_nest nest; - ENTRY; env = cl_env_nested_get(&nest); if (!IS_ERR(env)) { int rc; @@ -575,7 +580,7 @@ static int osc_lock_upcall(void *cookie, int errcode) /* should never happen, similar to osc_ldlm_blocking_ast(). */ LBUG(); } - RETURN(errcode); + return errcode; } /** @@ -896,55 +901,6 @@ static unsigned long osc_lock_weigh(const struct lu_env *env, return cl_object_header(slice->cls_obj)->coh_pages; } -/** - * Get the weight of dlm lock for early cancellation. - * - * XXX: it should return the pages covered by this \a dlmlock. - */ -static unsigned long osc_ldlm_weigh_ast(struct ldlm_lock *dlmlock) -{ - struct cl_env_nest nest; - struct lu_env *env; - struct osc_lock *lock; - struct cl_lock *cll; - unsigned long weight; - ENTRY; - - might_sleep(); - /* - * osc_ldlm_weigh_ast has a complex context since it might be called - * because of lock canceling, or from user's input. We have to make - * a new environment for it. Probably it is implementation safe to use - * the upper context because cl_lock_put don't modify environment - * variables. But in case of .. - */ - env = cl_env_nested_get(&nest); - if (IS_ERR(env)) - /* Mostly because lack of memory, tend to eliminate this lock*/ - RETURN(0); - - LASSERT(dlmlock->l_resource->lr_type == LDLM_EXTENT); - lock = osc_ast_data_get(dlmlock); - if (lock == NULL) { - /* cl_lock was destroyed because of memory pressure. - * It is much reasonable to assign this type of lock - * a lower cost. - */ - GOTO(out, weight = 0); - } - - cll = lock->ols_cl.cls_lock; - cl_lock_mutex_get(env, cll); - weight = cl_lock_weigh(env, cll); - cl_lock_mutex_put(env, cll); - osc_ast_data_put(env, lock); - EXIT; - -out: - cl_env_nested_put(&nest, env); - return weight; -} - static void osc_lock_build_einfo(const struct lu_env *env, const struct cl_lock *clock, struct osc_lock *lock, @@ -966,7 +922,6 @@ static void osc_lock_build_einfo(const struct lu_env *env, einfo->ei_cb_bl = osc_ldlm_blocking_ast; einfo->ei_cb_cp = osc_ldlm_completion_ast; einfo->ei_cb_gl = osc_ldlm_glimpse_ast; - einfo->ei_cb_wg = osc_ldlm_weigh_ast; einfo->ei_cbdata = lock; /* value to be put into ->l_ast_data */ } @@ -1059,7 +1014,6 @@ static int osc_lock_enqueue_wait(const struct lu_env *env, struct cl_lock *conflict= NULL; int lockless = osc_lock_is_lockless(olck); int rc = 0; - ENTRY; LASSERT(cl_lock_is_mutexed(lock)); @@ -1130,7 +1084,7 @@ static int osc_lock_enqueue_wait(const struct lu_env *env, rc = CLO_WAIT; } } - RETURN(rc); + return rc; } /** @@ -1154,7 +1108,6 @@ static int osc_lock_enqueue(const struct lu_env *env, struct osc_lock *ols = cl2osc_lock(slice); struct cl_lock *lock = ols->ols_cl.cls_lock; int result; - ENTRY; LASSERT(cl_lock_is_mutexed(lock)); LASSERTF(ols->ols_state == OLS_NEW, @@ -1207,7 +1160,7 @@ static int osc_lock_enqueue(const struct lu_env *env, } } LASSERT(ergo(ols->ols_glimpse, !osc_lock_is_lockless(ols))); - RETURN(result); + return result; } static int osc_lock_wait(const struct lu_env *env, @@ -1298,7 +1251,6 @@ static int osc_lock_flush(struct osc_lock *ols, int discard) struct cl_env_nest nest; struct lu_env *env; int result = 0; - ENTRY; env = cl_env_nested_get(&nest); if (!IS_ERR(env)) { @@ -1328,7 +1280,7 @@ static int osc_lock_flush(struct osc_lock *ols, int discard) ols->ols_flush = 1; LINVRNT(!osc_lock_has_pages(ols)); } - RETURN(result); + return result; } /** |