From 290ec05f6a5e3737ab22b1228763cf1d5d5852a6 Mon Sep 17 00:00:00 2001 From: huanghua <huanghua> Date: Thu, 20 Mar 2008 03:04:28 +0000 Subject: [PATCH] Branch HEAD b=13943 i=yong.fan i=nikita.danilov fini devices one by one, and then free them one by one. --- lustre/cmm/cmm_device.c | 8 +++++-- lustre/cmm/mdc_device.c | 13 +++++++----- lustre/include/lu_object.h | 7 ++++--- lustre/mdd/mdd_device.c | 7 +++++-- lustre/mdt/mdt_handler.c | 43 ++++++++++++++++++++++++++------------ lustre/osd/osd_handler.c | 7 +++++-- 6 files changed, 58 insertions(+), 27 deletions(-) diff --git a/lustre/cmm/cmm_device.c b/lustre/cmm/cmm_device.c index b4e03d2669..886dfbc48c 100644 --- a/lustre/cmm/cmm_device.c +++ b/lustre/cmm/cmm_device.c @@ -368,9 +368,12 @@ out_free_cmm: return l; } -static void cmm_device_free(const struct lu_env *env, struct lu_device *d) +static struct lu_device *cmm_device_free(const struct lu_env *env, + struct lu_device *d) { struct cmm_device *m = lu2cmm_dev(d); + struct lu_device *next = md2lu_dev(m->cmm_child); + ENTRY; LASSERT(m->cmm_tgt_count == 0); LASSERT(list_empty(&m->cmm_targets)); @@ -378,8 +381,9 @@ static void cmm_device_free(const struct lu_env *env, struct lu_device *d) OBD_FREE_PTR(m->cmm_fld); m->cmm_fld = NULL; } - md_device_fini(&m->cmm_md_dev); + md_device_fini(&m->cmm_md_dev); OBD_FREE_PTR(m); + RETURN(next); } /* context key constructor/destructor: cmm_key_init, cmm_key_fini */ diff --git a/lustre/cmm/mdc_device.c b/lustre/cmm/mdc_device.c index 9ecc428f6c..c81a6e7e6e 100644 --- a/lustre/cmm/mdc_device.c +++ b/lustre/cmm/mdc_device.c @@ -257,9 +257,9 @@ static struct lu_device *mdc_device_fini(const struct lu_env *env, RETURN (NULL); } -struct lu_device *mdc_device_alloc(const struct lu_env *env, - struct lu_device_type *ldt, - struct lustre_cfg *cfg) +static struct lu_device *mdc_device_alloc(const struct lu_env *env, + struct lu_device_type *ldt, + struct lustre_cfg *cfg) { struct lu_device *ld; struct mdc_device *mc; @@ -279,15 +279,18 @@ struct lu_device *mdc_device_alloc(const struct lu_env *env, RETURN (ld); } -void mdc_device_free(const struct lu_env *env, struct lu_device *ld) + +static struct lu_device *mdc_device_free(const struct lu_env *env, + struct lu_device *ld) { struct mdc_device *mc = lu2mdc_dev(ld); LASSERTF(atomic_read(&ld->ld_ref) == 0, "Refcount = %i\n", atomic_read(&ld->ld_ref)); LASSERT(list_empty(&mc->mc_linkage)); - md_device_fini(&mc->mc_md_dev); + md_device_fini(&mc->mc_md_dev); OBD_FREE_PTR(mc); + return NULL; } /* context key constructor/destructor: mdc_key_init, mdc_key_fini */ diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index fd26c3d19a..5c64d90595 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -297,10 +297,11 @@ struct lu_device_type_operations { struct lu_device_type *t, struct lustre_cfg *lcfg); /* - * Free device. Dual to ->ldto_device_alloc(). + * Free device. Dual to ->ldto_device_alloc(). Returns pointer to + * the next device in the stack. */ - void (*ldto_device_free)(const struct lu_env *, - struct lu_device *); + struct lu_device *(*ldto_device_free)(const struct lu_env *, + struct lu_device *); /* * Initialize the devices after allocation diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 9222e7eec0..a1a69f57d7 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -317,14 +317,17 @@ static struct lu_device *mdd_device_alloc(const struct lu_env *env, return l; } -static void mdd_device_free(const struct lu_env *env, - struct lu_device *lu) +static struct lu_device *mdd_device_free(const struct lu_env *env, + struct lu_device *lu) { struct mdd_device *m = lu2mdd_dev(lu); + struct lu_device *next = &m->mdd_child->dd_lu_dev; + ENTRY; LASSERT(atomic_read(&lu->ld_ref) == 0); md_device_fini(&m->mdd_md_dev); OBD_FREE_PTR(m); + RETURN(next); } static struct obd_ops mdd_obd_device_ops = { diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index fdb9f4597e..6f2f0353d4 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -3520,14 +3520,37 @@ static void mdt_stack_fini(const struct lu_env *env, lu_site_purge(env, top->ld_site, ~0); while (d != NULL) { - struct obd_type *type; struct lu_device_type *ldt = d->ld_type; /* each fini() returns next device in stack of layers - * * so we can avoid the recursion */ + * so we can avoid the recursion */ n = ldt->ldt_ops->ldto_device_fini(env, d); lu_device_put(d); - ldt->ldt_ops->ldto_device_free(env, d); + + /* switch to the next device in the layer */ + d = n; + } + + /* purge again. */ + lu_site_purge(env, top->ld_site, ~0); + + if (!list_empty(&top->ld_site->ls_lru) || top->ld_site->ls_total != 0) { + /* + * Uh-oh, objects still exist. + */ + static DECLARE_LU_CDEBUG_PRINT_INFO(cookie, D_ERROR); + + lu_site_print(env, top->ld_site, &cookie, lu_cdebug_printer); + } + + d = top; + while (d != NULL) { + struct obd_type *type; + struct lu_device_type *ldt = d->ld_type; + + /* each free() returns next device in stack of layers + * so we can avoid the recursion */ + n = ldt->ldt_ops->ldto_device_free(env, d); type = ldt->ldt_obd_type; type->typ_refcnt--; class_put_type(type); @@ -3696,15 +3719,6 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m) mdt_stack_fini(env, m, md2lu_dev(m->mdt_child)); if (ls) { - if (!list_empty(&ls->ls_lru) || ls->ls_total != 0) { - /* - * Uh-oh, objects still exist. - */ - static DECLARE_LU_CDEBUG_PRINT_INFO(cookie, D_ERROR); - - lu_site_print(env, ls, &cookie, lu_cdebug_printer); - } - lu_site_fini(ls); OBD_FREE_PTR(ls); d->ld_site = NULL; @@ -4596,11 +4610,14 @@ static struct lu_device* mdt_device_fini(const struct lu_env *env, RETURN(NULL); } -static void mdt_device_free(const struct lu_env *env, struct lu_device *d) +static struct lu_device *mdt_device_free(const struct lu_env *env, + struct lu_device *d) { struct mdt_device *m = mdt_dev(d); + ENTRY; OBD_FREE_PTR(m); + RETURN(NULL); } static struct lu_device *mdt_device_alloc(const struct lu_env *env, diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index 750de0c0ec..3c59117646 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -107,7 +107,7 @@ static void osd_object_release(const struct lu_env *env, struct lu_object *l); static int osd_object_print (const struct lu_env *env, void *cookie, lu_printer_t p, const struct lu_object *o); -static void osd_device_free (const struct lu_env *env, +static struct lu_device *osd_device_free (const struct lu_env *env, struct lu_device *m); static void *osd_key_init (const struct lu_context *ctx, struct lu_context_key *key); @@ -2315,13 +2315,16 @@ static struct lu_device *osd_device_alloc(const struct lu_env *env, return l; } -static void osd_device_free(const struct lu_env *env, struct lu_device *d) +static struct lu_device *osd_device_free(const struct lu_env *env, + struct lu_device *d) { struct osd_device *o = osd_dev(d); + ENTRY; cleanup_capa_hash(o->od_capa_hash); dt_device_fini(&o->od_dt_dev); OBD_FREE_PTR(o); + RETURN(NULL); } static int osd_process_config(const struct lu_env *env, -- GitLab