From 8fe64f9db0e55eb4cfc9849c6ec6bb2c348b2932 Mon Sep 17 00:00:00 2001 From: pschwan Date: Sat, 19 Oct 2002 09:12:24 +0000 Subject: [PATCH] Fix the connection refcount leaks. There were actually 3 separate bugs. --- lustre/include/linux/obd_class.h | 6 ++++++ lustre/ldlm/ldlm_lock.c | 2 ++ lustre/ldlm/ldlm_lockd.c | 1 - lustre/lib/client.c | 9 +++++---- lustre/obdclass/class_obd.c | 1 + lustre/obdclass/genops.c | 6 +++++- lustre/ptlrpc/rpc.c | 1 + 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lustre/include/linux/obd_class.h b/lustre/include/linux/obd_class.h index 9e0e60b..f83acf7 100644 --- a/lustre/include/linux/obd_class.h +++ b/lustre/include/linux/obd_class.h @@ -753,6 +753,12 @@ static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src, #ifdef __KERNEL__ +/* I'm as embarrassed about this as you are. + * + * // XXX do not look into _superhack with remaining eye + * // XXX if this were any uglier, I'd get my own show on MTV */ +extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c); + int class_register_type(struct obd_ops *ops, char *nm); int class_unregister_type(char *nm); int class_name2dev(char *name); diff --git a/lustre/ldlm/ldlm_lock.c b/lustre/ldlm/ldlm_lock.c index 8673d6a..b6df7fe 100644 --- a/lustre/ldlm/ldlm_lock.c +++ b/lustre/ldlm/ldlm_lock.c @@ -211,6 +211,8 @@ void ldlm_lock_destroy(struct ldlm_lock *lock) lock->l_flags |= LDLM_FL_DESTROYED; /* Wake anyone waiting for this lock */ + /* FIXME: I should probably add yet another flag, instead of using + * l_export to only call this on clients */ if (lock->l_export && lock->l_completion_ast) lock->l_completion_ast(lock, 0); diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c index 9873e0e..1f7b0dd 100644 --- a/lustre/ldlm/ldlm_lockd.c +++ b/lustre/ldlm/ldlm_lockd.c @@ -273,7 +273,6 @@ int ldlm_handle_enqueue(struct ptlrpc_request *req) l_unlock(&lock->l_resource->lr_namespace->ns_lock); } - ptlrpc_connection_addref(req->rq_connection); EXIT; out: if (lock) diff --git a/lustre/lib/client.c b/lustre/lib/client.c index 59116eb..1f596e8 100644 --- a/lustre/lib/client.c +++ b/lustre/lib/client.c @@ -103,10 +103,10 @@ int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf) int client_obd_cleanup(struct obd_device * obddev) { - struct client_obd *mdc = &obddev->u.cli; + struct client_obd *obd = &obddev->u.cli; - ptlrpc_cleanup_client(&mdc->cl_import); - ptlrpc_put_connection(mdc->cl_import.imp_connection); + ptlrpc_cleanup_client(&obd->cl_import); + ptlrpc_put_connection(obd->cl_import.imp_connection); MOD_DEC_USE_COUNT; return 0; @@ -149,7 +149,8 @@ int client_obd_connect(struct lustre_handle *conn, struct obd_device *obd, request->rq_replen = lustre_msg_size(0, NULL); request->rq_reqmsg->addr = conn->addr; request->rq_reqmsg->cookie = conn->cookie; - c = class_conn2export(conn)->exp_connection = request->rq_connection; + c = class_conn2export(conn)->exp_connection = + ptlrpc_connection_addref(request->rq_connection); recovd_conn_manage(c, recovd, recover); rc = ptlrpc_queue_wait(request); diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index be7f50b..95a8f79 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -1041,6 +1041,7 @@ EXPORT_SYMBOL(obd_memory); EXPORT_SYMBOL(obd_fail_loc); EXPORT_SYMBOL(obd_timeout); EXPORT_SYMBOL(obd_recovery_upcall); +EXPORT_SYMBOL(ptlrpc_put_connection_superhack); EXPORT_SYMBOL(class_register_type); EXPORT_SYMBOL(class_unregister_type); diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 7bb7945..487c932 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -25,6 +25,8 @@ kmem_cache_t *import_cachep = NULL; kmem_cache_t *export_cachep = NULL; kmem_cache_t *handle_cachep = NULL; +int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c); + /* I would prefer if these next four functions were in ptlrpc, to be honest, * but obdclass uses them for the netregression ioctls. -phil */ static int sync_io_timeout(void *data) @@ -390,6 +392,8 @@ void class_destroy_export(struct obd_export *exp) { ENTRY; + LASSERT(exp->exp_cookie != DEAD_HANDLE_MAGIC); + spin_lock(&exp->exp_obd->obd_dev_lock); list_del(&exp->exp_obd_chain); spin_unlock(&exp->exp_obd->obd_dev_lock); @@ -400,7 +404,7 @@ void class_destroy_export(struct obd_export *exp) list_del(&exp->exp_conn_chain); if (exp->exp_connection) { spin_unlock(&exp->exp_connection->c_lock); - //ptlrpc_put_connection(exp->exp_connection); + ptlrpc_put_connection_superhack(exp->exp_connection); } exp->exp_cookie = DEAD_HANDLE_MAGIC; diff --git a/lustre/ptlrpc/rpc.c b/lustre/ptlrpc/rpc.c index 25d6449..98be8ca 100644 --- a/lustre/ptlrpc/rpc.c +++ b/lustre/ptlrpc/rpc.c @@ -178,6 +178,7 @@ static int __init ptlrpc_init(void) RETURN(rc); ptlrpc_init_connection(); class_register_type(&recovd_obd_ops, LUSTRE_HA_NAME); + ptlrpc_put_connection_superhack = ptlrpc_put_connection; return 0; } -- 1.8.3.1