Whamcloud - gitweb
LU-12707 obdecho: avoid panic with partially object init
[fs/lustre-release.git] / lustre / obdecho / echo_client.c
index ed6fd8c..2acc4a0 100644 (file)
@@ -524,23 +524,37 @@ static int echo_object_init(const struct lu_env *env, struct lu_object *obj,
        RETURN(0);
 }
 
        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_object *eco    = cl2echo_obj(lu2cl(obj));
-       struct echo_client_obd *ec = eco->eo_dev->ed_ec;
+       struct echo_client_obd *ec;
 
        ENTRY;
 
        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);
 
        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);
        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;
 
        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,
 
 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,
        .loo_object_release   = NULL,
        .loo_object_free      = echo_object_free,
        .loo_object_print     = echo_object_print,