From 11de14b33b4ea17591c6e67a9c782de545262a1f Mon Sep 17 00:00:00 2001 From: yury Date: Fri, 30 May 2008 09:24:33 +0000 Subject: [PATCH] b=15440 r=shadow, nikita - fixes missed list init in CFS_LIST_INIT_HEAD(&ns->ns_list_chain); - cleanups about registering/unregistering @ns in its list. --- lustre/include/lustre_dlm.h | 10 +++++--- lustre/ldlm/ldlm_pool.c | 12 ++++----- lustre/ldlm/ldlm_resource.c | 60 ++++++++++++++++++++++++++++----------------- 3 files changed, 49 insertions(+), 33 deletions(-) diff --git a/lustre/include/lustre_dlm.h b/lustre/include/lustre_dlm.h index 9ddb35b..b59c05a 100644 --- a/lustre/include/lustre_dlm.h +++ b/lustre/include/lustre_dlm.h @@ -700,12 +700,14 @@ struct ldlm_namespace *ldlm_namespace_new(char *name, ldlm_side_t client, int ldlm_namespace_cleanup(struct ldlm_namespace *ns, int flags); void ldlm_namespace_free(struct ldlm_namespace *ns, struct obd_import *imp, int force); -void ldlm_namespace_move(struct ldlm_namespace *ns, ldlm_side_t client); -struct ldlm_namespace *ldlm_namespace_first(ldlm_side_t client); +void ldlm_namespace_register(struct ldlm_namespace *ns, ldlm_side_t client); +void ldlm_namespace_unregister(struct ldlm_namespace *ns, ldlm_side_t client); +void ldlm_namespace_move_locked(struct ldlm_namespace *ns, ldlm_side_t client); +struct ldlm_namespace *ldlm_namespace_first_locked(ldlm_side_t client); +void ldlm_namespace_get_locked(struct ldlm_namespace *ns); +void ldlm_namespace_put_locked(struct ldlm_namespace *ns, int wakeup); void ldlm_namespace_get(struct ldlm_namespace *ns); void ldlm_namespace_put(struct ldlm_namespace *ns, int wakeup); -void ldlm_namespace_get_nolock(struct ldlm_namespace *ns); -void ldlm_namespace_put_nolock(struct ldlm_namespace *ns, int wakeup); int ldlm_proc_setup(void); #ifdef LPROCFS void ldlm_proc_cleanup(void); diff --git a/lustre/ldlm/ldlm_pool.c b/lustre/ldlm/ldlm_pool.c index fb9a508..cb96c8a 100644 --- a/lustre/ldlm/ldlm_pool.c +++ b/lustre/ldlm/ldlm_pool.c @@ -783,9 +783,9 @@ static int ldlm_pools_shrink(ldlm_side_t client, int nr, mutex_up(ldlm_namespace_lock(client)); return 0; } - ns = ldlm_namespace_first(client); + ns = ldlm_namespace_first_locked(client); ldlm_namespace_get(ns); - ldlm_namespace_move(ns, client); + ldlm_namespace_move_locked(ns, client); mutex_up(ldlm_namespace_lock(client)); total += ldlm_pool_shrink(&ns->ns_pool, 0, gfp_mask); ldlm_namespace_put(ns, 1); @@ -810,9 +810,9 @@ static int ldlm_pools_shrink(ldlm_side_t client, int nr, cached = 0; break; } - ns = ldlm_namespace_first(client); + ns = ldlm_namespace_first_locked(client); ldlm_namespace_get(ns); - ldlm_namespace_move(ns, client); + ldlm_namespace_move_locked(ns, client); mutex_up(ldlm_namespace_lock(client)); nr_locks = ldlm_pool_granted(&ns->ns_pool); @@ -909,9 +909,9 @@ void ldlm_pools_recalc(ldlm_side_t client) mutex_up(ldlm_namespace_lock(client)); break; } - ns = ldlm_namespace_first(client); + ns = ldlm_namespace_first_locked(client); ldlm_namespace_get(ns); - ldlm_namespace_move(ns, client); + ldlm_namespace_move_locked(ns, client); mutex_up(ldlm_namespace_lock(client)); /* After setup is done - recalc the pool. */ diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 2c93142..a2a7a3b 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -327,6 +327,7 @@ struct ldlm_namespace *ldlm_namespace_new(char *name, ldlm_side_t client, strcpy(ns->ns_name, name); CFS_INIT_LIST_HEAD(&ns->ns_root_list); + CFS_INIT_LIST_HEAD(&ns->ns_list_chain); ns->ns_refcount = 0; ns->ns_client = client; spin_lock_init(&ns->ns_hash_lock); @@ -358,11 +359,7 @@ struct ldlm_namespace *ldlm_namespace_new(char *name, ldlm_side_t client, GOTO(out_proc, rc); } - mutex_down(ldlm_namespace_lock(client)); - list_add(&ns->ns_list_chain, ldlm_namespace_list(client)); - atomic_inc(ldlm_namespace_nr(client)); - mutex_up(ldlm_namespace_lock(client)); - + ldlm_namespace_register(ns, client); RETURN(ns); out_proc: ldlm_namespace_cleanup(ns, 0); @@ -580,16 +577,8 @@ void ldlm_namespace_free_post(struct ldlm_namespace *ns) return; } - mutex_down(ldlm_namespace_lock(ns->ns_client)); - /* - * Some asserts and possibly other parts of code still using - * list_empty(&ns->ns_list_chain). This is why it is important - * to use list_del_init() here. - */ - list_del_init(&ns->ns_list_chain); - atomic_dec(ldlm_namespace_nr(ns->ns_client)); - ldlm_pool_fini(&ns->ns_pool); - mutex_up(ldlm_namespace_lock(ns->ns_client)); + /* Remove @ns from list. */ + ldlm_namespace_unregister(ns, ns->ns_client); #ifdef LPROCFS { struct proc_dir_entry *dir; @@ -642,7 +631,7 @@ void ldlm_namespace_free(struct ldlm_namespace *ns, } -void ldlm_namespace_get_nolock(struct ldlm_namespace *ns) +void ldlm_namespace_get_locked(struct ldlm_namespace *ns) { LASSERT(ns->ns_refcount >= 0); ns->ns_refcount++; @@ -651,11 +640,11 @@ void ldlm_namespace_get_nolock(struct ldlm_namespace *ns) void ldlm_namespace_get(struct ldlm_namespace *ns) { spin_lock(&ns->ns_hash_lock); - ldlm_namespace_get_nolock(ns); + ldlm_namespace_get_locked(ns); spin_unlock(&ns->ns_hash_lock); } -void ldlm_namespace_put_nolock(struct ldlm_namespace *ns, int wakeup) +void ldlm_namespace_put_locked(struct ldlm_namespace *ns, int wakeup) { LASSERT(ns->ns_refcount > 0); ns->ns_refcount--; @@ -666,12 +655,37 @@ void ldlm_namespace_put_nolock(struct ldlm_namespace *ns, int wakeup) void ldlm_namespace_put(struct ldlm_namespace *ns, int wakeup) { spin_lock(&ns->ns_hash_lock); - ldlm_namespace_put_nolock(ns, wakeup); + ldlm_namespace_put_locked(ns, wakeup); spin_unlock(&ns->ns_hash_lock); } +/* Register @ns in the list of namespaces */ +void ldlm_namespace_register(struct ldlm_namespace *ns, ldlm_side_t client) +{ + mutex_down(ldlm_namespace_lock(client)); + LASSERT(list_empty(&ns->ns_list_chain)); + list_add(&ns->ns_list_chain, ldlm_namespace_list(client)); + atomic_inc(ldlm_namespace_nr(client)); + mutex_up(ldlm_namespace_lock(client)); +} + +/* Unregister @ns from the list of namespaces */ +void ldlm_namespace_unregister(struct ldlm_namespace *ns, ldlm_side_t client) +{ + mutex_down(ldlm_namespace_lock(client)); + LASSERT(!list_empty(&ns->ns_list_chain)); + /* + * Some asserts and possibly other parts of code still using + * list_empty(&ns->ns_list_chain). This is why it is important + * to use list_del_init() here. + */ + list_del_init(&ns->ns_list_chain); + atomic_dec(ldlm_namespace_nr(client)); + mutex_up(ldlm_namespace_lock(client)); +} + /* Should be called under ldlm_namespace_lock(client) taken */ -void ldlm_namespace_move(struct ldlm_namespace *ns, ldlm_side_t client) +void ldlm_namespace_move_locked(struct ldlm_namespace *ns, ldlm_side_t client) { LASSERT(!list_empty(&ns->ns_list_chain)); LASSERT_SEM_LOCKED(ldlm_namespace_lock(client)); @@ -679,7 +693,7 @@ void ldlm_namespace_move(struct ldlm_namespace *ns, ldlm_side_t client) } /* Should be called under ldlm_namespace_lock(client) taken */ -struct ldlm_namespace *ldlm_namespace_first(ldlm_side_t client) +struct ldlm_namespace *ldlm_namespace_first_locked(ldlm_side_t client) { LASSERT_SEM_LOCKED(ldlm_namespace_lock(client)); LASSERT(!list_empty(ldlm_namespace_list(client))); @@ -795,7 +809,7 @@ ldlm_resource_add(struct ldlm_namespace *ns, struct ldlm_resource *parent, bucket = ns->ns_hash + hash; list_add(&res->lr_hash, bucket); ns->ns_resources++; - ldlm_namespace_get_nolock(ns); + ldlm_namespace_get_locked(ns); if (parent == NULL) { list_add(&res->lr_childof, &ns->ns_root_list); @@ -894,7 +908,7 @@ void __ldlm_resource_putref_final(struct ldlm_resource *res) /* Pass 0 here to not wake ->ns_waitq up yet, we will do it few * lines below when all children are freed. */ - ldlm_namespace_put_nolock(ns, 0); + ldlm_namespace_put_locked(ns, 0); list_del_init(&res->lr_hash); list_del_init(&res->lr_childof); -- 1.8.3.1