From 1a9ca8417c60f04a9aa719b7254372e2d18a6b0a Mon Sep 17 00:00:00 2001 From: Alexey Lyashkov Date: Wed, 28 Aug 2019 18:06:43 +0300 Subject: [PATCH 1/1] LU-12707 obdecho: avoid panic with partially object init in some cases (like ENOMEM) init function can't called, so any init related code should placed in the object delete handler, not in the object free. Signed-off-by: Alexey Lyashkov Change-Id: I1fca56423de9a045aac2c495fbc45069c3bbc97c Reviewed-on: https://review.whamcloud.com/35950 Reviewed-by: Andreas Dilger Reviewed-by: Alex Zhuravlev Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/obdecho/echo_client.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index ed6fd8c..2acc4a0 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -524,23 +524,37 @@ static int echo_object_init(const struct lu_env *env, struct lu_object *obj, RETURN(0); } -static void echo_object_free(const struct lu_env *env, struct lu_object *obj) +static void echo_object_delete(const struct lu_env *env, struct lu_object *obj) { struct echo_object *eco = cl2echo_obj(lu2cl(obj)); - struct echo_client_obd *ec = eco->eo_dev->ed_ec; + struct echo_client_obd *ec; ENTRY; + + /* object delete called unconditolally - layer init or not */ + if (eco->eo_dev == NULL) + return; + + ec = eco->eo_dev->ed_ec; + LASSERT(atomic_read(&eco->eo_npages) == 0); spin_lock(&ec->ec_lock); list_del_init(&eco->eo_obj_chain); spin_unlock(&ec->ec_lock); - lu_object_fini(obj); - lu_object_header_fini(obj->lo_header); - if (eco->eo_oinfo) OBD_FREE_PTR(eco->eo_oinfo); +} + +static void echo_object_free(const struct lu_env *env, struct lu_object *obj) +{ + struct echo_object *eco = cl2echo_obj(lu2cl(obj)); + + ENTRY; + + lu_object_fini(obj); + lu_object_header_fini(obj->lo_header); OBD_SLAB_FREE_PTR(eco, echo_object_kmem); EXIT; @@ -556,7 +570,7 @@ static int echo_object_print(const struct lu_env *env, void *cookie, static const struct lu_object_operations echo_lu_obj_ops = { .loo_object_init = echo_object_init, - .loo_object_delete = NULL, + .loo_object_delete = echo_object_delete, .loo_object_release = NULL, .loo_object_free = echo_object_free, .loo_object_print = echo_object_print, -- 1.8.3.1