Whamcloud - gitweb
Move md-specific fields out of struct lu_site into special struct md_site, so
[fs/lustre-release.git] / lustre / cmm / cmm_device.c
index 38054f4..4308533 100644 (file)
@@ -1,29 +1,43 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  lustre/cmm/cmm_device.c
- *  Lustre Cluster Metadata Manager (cmm)
+ * GPL HEADER START
  *
- *  Copyright (c) 2006 Cluster File Systems, Inc.
- *   Author: Mike Pershin <tappro@clusterfs.com>
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   This file is part of the Lustre file system, http://www.lustre.org
- *   Lustre is a trademark of Cluster File Systems, Inc.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   You may have signed or agreed to another license before downloading
- *   this software.  If so, you are bound by the terms and conditions
- *   of that agreement, and the following does not apply to you.  See the
- *   LICENSE file included with this distribution for more information.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   If you did not agree to a different license, then this copy of Lustre
- *   is open source software; you can redistribute it and/or modify it
- *   under the terms of version 2 of the GNU General Public License as
- *   published by the Free Software Foundation.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
- *   In either case, Lustre is distributed in the hope that it will be
- *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   license text for more details.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/cmm/cmm_device.c
+ *
+ * Lustre Cluster Metadata Manager (cmm)
+ *
+ * Author: Mike Pershin <tappro@clusterfs.com>
  */
 
 #ifndef EXPORT_SYMTAB
@@ -44,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)
 {
@@ -113,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,
@@ -138,7 +152,7 @@ static int cmm_post_init_mdc(const struct lu_env *env,
         spin_lock(&cmm->cmm_tgt_guard);
         list_for_each_entry_safe(mc, tmp, &cmm->cmm_targets,
                                  mc_linkage) {
-                mdc_init_ea_size(env, mc, max_mdsize, max_cookiesize);
+                cmm_mdc_init_ea_size(env, mc, max_mdsize, max_cookiesize);
         }
         spin_unlock(&cmm->cmm_tgt_guard);
         RETURN(rc);
@@ -154,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;
@@ -176,17 +191,23 @@ static int cmm_add_mdc(const struct lu_env *env,
         }
         spin_unlock(&cm->cmm_tgt_guard);
         ld = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
+        if (IS_ERR(ld))
+                RETURN(PTR_ERR(ld));
+
         ld->ld_site = cmm2lu_dev(cm)->ld_site;
 
         rc = ldt->ldt_ops->ldto_device_init(env, ld, NULL, NULL);
         if (rc) {
                 ldt->ldt_ops->ldto_device_free(env, ld);
-                RETURN (rc);
+                RETURN(rc);
         }
         /* pass config to the just created MDC */
         rc = ld->ld_ops->ldo_process_config(env, ld, cfg);
-        if (rc)
+        if (rc) {
+                ldt->ldt_ops->ldto_device_fini(env, ld);
+                ldt->ldt_ops->ldto_device_free(env, ld);
                 RETURN(rc);
+        }
 
         spin_lock(&cm->cmm_tgt_guard);
         list_for_each_entry_safe(mc, tmp, &cm->cmm_targets,
@@ -203,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;
@@ -272,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;
 
@@ -314,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
@@ -339,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)
@@ -358,28 +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 void cmm_device_free(const struct lu_env *env, struct lu_device *d)
-{
-        struct cmm_device *m = lu2cmm_dev(d);
-
-        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(l);
 }
 
 /* context key constructor/destructor: cmm_key_init, cmm_key_fini */
@@ -409,7 +433,7 @@ static int cmm_device_init(const struct lu_env *env, struct lu_device *d,
         ENTRY;
 
         spin_lock_init(&m->cmm_tgt_guard);
-        INIT_LIST_HEAD(&m->cmm_targets);
+        CFS_INIT_LIST_HEAD(&m->cmm_targets);
         m->cmm_tgt_count = 0;
         m->cmm_child = lu2md_dev(next);
 
@@ -422,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);
@@ -440,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--;
@@ -451,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));
@@ -461,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,
 
@@ -483,13 +512,17 @@ struct lprocfs_vars lprocfs_cmm_module_vars[] = {
         { 0 }
 };
 
-LPROCFS_INIT_VARS(cmm, lprocfs_cmm_module_vars, lprocfs_cmm_obd_vars);
+static void lprocfs_cmm_init_vars(struct lprocfs_static_vars *lvars)
+{
+    lvars->module_vars  = lprocfs_cmm_module_vars;
+    lvars->obd_vars     = lprocfs_cmm_obd_vars;
+}
 
 static int __init cmm_mod_init(void)
 {
         struct lprocfs_static_vars lvars;
 
-        lprocfs_init_vars(cmm, &lvars);
+        lprocfs_cmm_init_vars(&lvars);
         return class_register_type(&cmm_obd_device_ops, NULL, lvars.module_vars,
                                    LUSTRE_CMM_NAME, &cmm_device_type);
 }
@@ -499,7 +532,7 @@ static void __exit cmm_mod_exit(void)
         class_unregister_type(LUSTRE_CMM_NAME);
 }
 
-MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
+MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
 MODULE_DESCRIPTION("Lustre Clustered Metadata Manager ("LUSTRE_CMM_NAME")");
 MODULE_LICENSE("GPL");