Whamcloud - gitweb
Branch HEAD
authorhuanghua <huanghua>
Thu, 20 Mar 2008 03:04:28 +0000 (03:04 +0000)
committerhuanghua <huanghua>
Thu, 20 Mar 2008 03:04:28 +0000 (03:04 +0000)
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
lustre/cmm/mdc_device.c
lustre/include/lu_object.h
lustre/mdd/mdd_device.c
lustre/mdt/mdt_handler.c
lustre/osd/osd_handler.c

index b4e03d2..886dfbc 100644 (file)
@@ -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 */
index 9ecc428..c81a6e7 100644 (file)
@@ -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 */
index fd26c3d..5c64d90 100644 (file)
@@ -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
index 9222e7e..a1a69f5 100644 (file)
@@ -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 = {
index fdb9f45..6f2f035 100644 (file)
@@ -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,
index 750de0c..3c59117 100644 (file)
@@ -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,