Whamcloud - gitweb
b=16551
[fs/lustre-release.git] / lustre / cmm / cmm_device.c
index aef1da6..4308533 100644 (file)
@@ -58,7 +58,7 @@ static struct obd_ops cmm_obd_device_ops = {
         .o_owner           = THIS_MODULE
 };
 
-static struct lu_device_operations cmm_lu_ops;
+static const struct lu_device_operations cmm_lu_ops;
 
 static inline int lu_device_is_cmm(struct lu_device *d)
 {
@@ -127,7 +127,7 @@ static int cmm_update_capa_key(const struct lu_env *env,
         RETURN(rc);
 }
 
-static struct md_device_operations cmm_md_ops = {
+static const struct md_device_operations cmm_md_ops = {
         .mdo_statfs          = cmm_statfs,
         .mdo_root_get        = cmm_root_get,
         .mdo_maxsize_get     = cmm_maxsize_get,
@@ -168,6 +168,7 @@ static int cmm_add_mdc(const struct lu_env *env,
         struct mdc_device *mc, *tmp;
         struct lu_fld_target target;
         struct lu_device *ld;
+        struct lu_device *cmm_lu = cmm2lu_dev(cm);
         mdsno_t mdc_num;
         int rc;
         ENTRY;
@@ -223,7 +224,8 @@ static int cmm_add_mdc(const struct lu_env *env,
         cm->cmm_tgt_count++;
         spin_unlock(&cm->cmm_tgt_guard);
 
-        lu_device_get(cmm2lu_dev(cm));
+        lu_device_get(cmm_lu);
+        lu_ref_add(&cmm_lu->ld_reference, "mdc-child", ld);
 
         target.ft_srv = NULL;
         target.ft_idx = mc->mc_num;
@@ -292,7 +294,7 @@ static int cmm_process_config(const struct lu_env *env,
                         struct lu_site *ls = cmm2lu_dev(m)->ld_site;
                         struct lu_fld_target target;
 
-                        target.ft_srv = ls->ls_server_fld;
+                        target.ft_srv = lu_site2md(ls)->ms_server_fld;
                         target.ft_idx = m->cmm_local_num;
                         target.ft_exp = NULL;
 
@@ -334,7 +336,7 @@ static int cmm_recovery_complete(const struct lu_env *env,
         RETURN(rc);
 }
 
-static struct lu_device_operations cmm_lu_ops = {
+static const struct lu_device_operations cmm_lu_ops = {
        .ldo_object_alloc      = cmm_object_alloc,
         .ldo_process_config    = cmm_process_config,
         .ldo_recovery_complete = cmm_recovery_complete
@@ -359,6 +361,24 @@ int cmm_upcall(const struct lu_env *env, struct md_device *md,
         RETURN(rc);
 }
 
+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));
+        if (m->cmm_fld != NULL) {
+                OBD_FREE_PTR(m->cmm_fld);
+                m->cmm_fld = NULL;
+        }
+        md_device_fini(&m->cmm_md_dev);
+        OBD_FREE_PTR(m);
+        RETURN(next);
+}
+
 static struct lu_device *cmm_device_alloc(const struct lu_env *env,
                                           struct lu_device_type *t,
                                           struct lustre_cfg *cfg)
@@ -378,32 +398,12 @@ static struct lu_device *cmm_device_alloc(const struct lu_env *env,
                 l->ld_ops = &cmm_lu_ops;
 
                 OBD_ALLOC_PTR(m->cmm_fld);
-                if (!m->cmm_fld)
-                        GOTO(out_free_cmm, l = ERR_PTR(-ENOMEM));
+                if (!m->cmm_fld) {
+                        cmm_device_free(env, l);
+                        l = ERR_PTR(-ENOMEM);
         }
-
-        RETURN(l);
-out_free_cmm:
-        OBD_FREE_PTR(m);
-        return l;
-}
-
-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));
-        if (m->cmm_fld != NULL) {
-                OBD_FREE_PTR(m->cmm_fld);
-                m->cmm_fld = NULL;
         }
-        md_device_fini(&m->cmm_md_dev);
-        OBD_FREE_PTR(m);
-        RETURN(next);
+        RETURN(l);
 }
 
 /* context key constructor/destructor: cmm_key_init, cmm_key_fini */
@@ -446,7 +446,7 @@ static int cmm_device_init(const struct lu_env *env, struct lu_device *d,
 
         /* Assign site's fld client ref, needed for asserts in osd. */
         ls = cmm2lu_dev(m)->ld_site;
-        ls->ls_client_fld = m->cmm_fld;
+        lu_site2md(ls)->ms_client_fld = m->cmm_fld;
         err = cmm_procfs_init(m, name);
         
         RETURN(err);
@@ -464,9 +464,11 @@ static struct lu_device *cmm_device_fini(const struct lu_env *env,
         spin_lock(&cm->cmm_tgt_guard);
         list_for_each_entry_safe(mc, tmp, &cm->cmm_targets, mc_linkage) {
                 struct lu_device *ld_m = mdc2lu_dev(mc);
+                struct lu_device *ld_c = cmm2lu_dev(cm);
 
                 list_del_init(&mc->mc_linkage);
-                lu_device_put(cmm2lu_dev(cm));
+                lu_ref_del(&ld_c->ld_reference, "mdc-child", ld_m);
+                lu_device_put(ld_c);
                 ld_m->ld_type->ldt_ops->ldto_device_fini(env, ld_m);
                 ld_m->ld_type->ldt_ops->ldto_device_free(env, ld_m);
                 cm->cmm_tgt_count--;
@@ -475,7 +477,7 @@ static struct lu_device *cmm_device_fini(const struct lu_env *env,
 
         fld_client_fini(cm->cmm_fld);
         ls = cmm2lu_dev(cm)->ld_site;
-        ls->ls_client_fld = NULL;
+        lu_site2md(ls)->ms_client_fld = NULL;
         cmm_procfs_fini(cm);
 
         RETURN (md2lu_dev(cm->cmm_child));
@@ -485,6 +487,9 @@ static struct lu_device_type_operations cmm_device_type_ops = {
         .ldto_init = cmm_type_init,
         .ldto_fini = cmm_type_fini,
 
+        .ldto_start = cmm_type_start,
+        .ldto_stop  = cmm_type_stop,
+
         .ldto_device_alloc = cmm_device_alloc,
         .ldto_device_free  = cmm_device_free,