Whamcloud - gitweb
LU-354 test: Change dev_set_rdonly() check to warning
[fs/lustre-release.git] / lustre / cmm / cmm_device.c
index 681e2db..3aa8b87 100644 (file)
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  *
  * Author: Mike Pershin <tappro@clusterfs.com>
  */
-
+/**
+ * \addtogroup cmm
+ * @{
+ */
 #ifndef EXPORT_SYMTAB
 # define EXPORT_SYMTAB
 #endif
@@ -57,7 +62,7 @@
 # include <lustre_quota.h>
 #endif
 
-static struct obd_ops cmm_obd_device_ops = {
+struct obd_ops cmm_obd_device_ops = {
         .o_owner           = THIS_MODULE
 };
 
@@ -65,7 +70,7 @@ static const struct lu_device_operations cmm_lu_ops;
 
 static inline int lu_device_is_cmm(struct lu_device *d)
 {
-       return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &cmm_lu_ops);
+        return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &cmm_lu_ops);
 }
 
 int cmm_root_get(const struct lu_env *env, struct md_device *md,
@@ -81,10 +86,10 @@ int cmm_root_get(const struct lu_env *env, struct md_device *md,
 }
 
 static int cmm_statfs(const struct lu_env *env, struct md_device *md,
-                      struct kstatfs *sfs)
+                      cfs_kstatfs_t *sfs)
 {
         struct cmm_device *cmm_dev = md2cmm_dev(md);
-       int rc;
+        int rc;
 
         ENTRY;
         rc = cmm_child_ops(cmm_dev)->mdo_statfs(env,
@@ -130,7 +135,23 @@ static int cmm_update_capa_key(const struct lu_env *env,
         RETURN(rc);
 }
 
+static int cmm_llog_ctxt_get(const struct lu_env *env, struct md_device *m,
+                             int idx, void **h)
+{
+        struct cmm_device *cmm_dev = md2cmm_dev(m);
+        int rc;
+        ENTRY;
+
+        rc = cmm_child_ops(cmm_dev)->mdo_llog_ctxt_get(env, cmm_dev->cmm_child,
+                                                       idx, h);
+        RETURN(rc);
+}
+
 #ifdef HAVE_QUOTA_SUPPORT
+/**
+ * \name Quota functions
+ * @{
+ */
 static int cmm_quota_notify(const struct lu_env *env, struct md_device *m)
 {
         struct cmm_device *cmm_dev = md2cmm_dev(m);
@@ -178,7 +199,7 @@ static int cmm_quota_recovery(const struct lu_env *env, struct md_device *m)
 }
 
 static int cmm_quota_check(const struct lu_env *env, struct md_device *m,
-                           struct obd_export *exp, __u32 type)
+                           __u32 type)
 {
         struct cmm_device *cmm_dev = md2cmm_dev(m);
         int rc;
@@ -190,7 +211,7 @@ static int cmm_quota_check(const struct lu_env *env, struct md_device *m,
 
         rc = cmm_child_ops(cmm_dev)->mdo_quota.mqo_check(env,
                                                          cmm_dev->cmm_child,
-                                                         exp, type);
+                                                         type);
         RETURN(rc);
 }
 
@@ -218,10 +239,6 @@ static int cmm_quota_off(const struct lu_env *env, struct md_device *m,
         int rc;
         ENTRY;
 
-        /* disable quota for CMD case temporary. */
-        if (cmm_dev->cmm_tgt_count)
-                RETURN(-EOPNOTSUPP);
-
         rc = cmm_child_ops(cmm_dev)->mdo_quota.mqo_off(env,
                                                        cmm_dev->cmm_child,
                                                        type);
@@ -367,14 +384,29 @@ static int cmm_quota_finvalidate(const struct lu_env *env, struct md_device *m,
                                                                type);
         RETURN(rc);
 }
+/** @} */
 #endif
 
+int cmm_iocontrol(const struct lu_env *env, struct md_device *m,
+                  unsigned int cmd, int len, void *data)
+{
+        struct md_device *next = md2cmm_dev(m)->cmm_child;
+        int rc;
+
+        ENTRY;
+        rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
+        RETURN(rc);
+}
+
+
 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,
         .mdo_init_capa_ctxt  = cmm_init_capa_ctxt,
         .mdo_update_capa_key = cmm_update_capa_key,
+        .mdo_llog_ctxt_get   = cmm_llog_ctxt_get,
+        .mdo_iocontrol       = cmm_iocontrol,
 #ifdef HAVE_QUOTA_SUPPORT
         .mdo_quota           = {
                 .mqo_notify      = cmm_quota_notify,
@@ -397,7 +429,9 @@ static const struct md_device_operations cmm_md_ops = {
 };
 
 extern struct lu_device_type mdc_device_type;
-
+/**
+ * Init MDC.
+ */
 static int cmm_post_init_mdc(const struct lu_env *env,
                              struct cmm_device *cmm)
 {
@@ -406,16 +440,16 @@ static int cmm_post_init_mdc(const struct lu_env *env,
 
         /* get the max mdsize and cookiesize from lower layer */
         rc = cmm_maxsize_get(env, &cmm->cmm_md_dev, &max_mdsize,
-                                                &max_cookiesize);
+                             &max_cookiesize);
         if (rc)
                 RETURN(rc);
 
-        spin_lock(&cmm->cmm_tgt_guard);
-        list_for_each_entry_safe(mc, tmp, &cmm->cmm_targets,
-                                 mc_linkage) {
+        cfs_spin_lock(&cmm->cmm_tgt_guard);
+        cfs_list_for_each_entry_safe(mc, tmp, &cmm->cmm_targets,
+                                     mc_linkage) {
                 cmm_mdc_init_ea_size(env, mc, max_mdsize, max_cookiesize);
         }
-        spin_unlock(&cmm->cmm_tgt_guard);
+        cfs_spin_unlock(&cmm->cmm_tgt_guard);
         RETURN(rc);
 }
 
@@ -446,15 +480,15 @@ static int cmm_add_mdc(const struct lu_env *env,
                 RETURN(-EINVAL);
         }
 
-        spin_lock(&cm->cmm_tgt_guard);
-        list_for_each_entry_safe(mc, tmp, &cm->cmm_targets,
-                                 mc_linkage) {
+        cfs_spin_lock(&cm->cmm_tgt_guard);
+        cfs_list_for_each_entry_safe(mc, tmp, &cm->cmm_targets,
+                                     mc_linkage) {
                 if (mc->mc_num == mdc_num) {
-                        spin_unlock(&cm->cmm_tgt_guard);
+                        cfs_spin_unlock(&cm->cmm_tgt_guard);
                         RETURN(-EEXIST);
                 }
         }
-        spin_unlock(&cm->cmm_tgt_guard);
+        cfs_spin_unlock(&cm->cmm_tgt_guard);
         ld = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
         if (IS_ERR(ld))
                 RETURN(PTR_ERR(ld));
@@ -474,23 +508,23 @@ static int cmm_add_mdc(const struct lu_env *env,
                 RETURN(rc);
         }
 
-        spin_lock(&cm->cmm_tgt_guard);
-        list_for_each_entry_safe(mc, tmp, &cm->cmm_targets,
-                                 mc_linkage) {
+        cfs_spin_lock(&cm->cmm_tgt_guard);
+        cfs_list_for_each_entry_safe(mc, tmp, &cm->cmm_targets,
+                                     mc_linkage) {
                 if (mc->mc_num == mdc_num) {
-                        spin_unlock(&cm->cmm_tgt_guard);
+                        cfs_spin_unlock(&cm->cmm_tgt_guard);
                         ldt->ldt_ops->ldto_device_fini(env, ld);
                         ldt->ldt_ops->ldto_device_free(env, ld);
                         RETURN(-EEXIST);
                 }
         }
         mc = lu2mdc_dev(ld);
-        list_add_tail(&mc->mc_linkage, &cm->cmm_targets);
+        cfs_list_add_tail(&mc->mc_linkage, &cm->cmm_targets);
         cm->cmm_tgt_count++;
 #ifdef HAVE_QUOTA_SUPPORT
         first = cm->cmm_tgt_count;
 #endif
-        spin_unlock(&cm->cmm_tgt_guard);
+        cfs_spin_unlock(&cm->cmm_tgt_guard);
 
         lu_device_get(cmm_lu);
         lu_ref_add(&cmm_lu->ld_reference, "mdc-child", ld);
@@ -530,13 +564,13 @@ static void cmm_device_shutdown(const struct lu_env *env,
         fld_client_del_target(cm->cmm_fld, cm->cmm_local_num);
 
         /* Finish all mdc devices. */
-        spin_lock(&cm->cmm_tgt_guard);
-        list_for_each_entry_safe(mc, tmp, &cm->cmm_targets, mc_linkage) {
+        cfs_spin_lock(&cm->cmm_tgt_guard);
+        cfs_list_for_each_entry_safe(mc, tmp, &cm->cmm_targets, mc_linkage) {
                 struct lu_device *ld_m = mdc2lu_dev(mc);
                 fld_client_del_target(cm->cmm_fld, mc->mc_num);
                 ld_m->ld_ops->ldo_process_config(env, ld_m, cfg);
         }
-        spin_unlock(&cm->cmm_tgt_guard);
+        cfs_spin_unlock(&cm->cmm_tgt_guard);
 
         /* remove upcall device*/
         md_upcall_fini(&cm->cmm_md_dev);
@@ -632,7 +666,7 @@ static int cmm_prepare(const struct lu_env *env,
 }
 
 static const struct lu_device_operations cmm_lu_ops = {
-       .ldo_object_alloc      = cmm_object_alloc,
+        .ldo_object_alloc      = cmm_object_alloc,
         .ldo_process_config    = cmm_process_config,
         .ldo_recovery_complete = cmm_recovery_complete,
         .ldo_prepare           = cmm_prepare,
@@ -640,7 +674,7 @@ static const struct lu_device_operations cmm_lu_ops = {
 
 /* --- lu_device_type operations --- */
 int cmm_upcall(const struct lu_env *env, struct md_device *md,
-               enum md_upcall_event ev)
+               enum md_upcall_event ev, void *data)
 {
         int rc;
         ENTRY;
@@ -652,7 +686,7 @@ int cmm_upcall(const struct lu_env *env, struct md_device *md,
                                 CERROR("can not init md size %d\n", rc);
                         /* fall through */
                 default:
-                        rc = md_do_upcall(env, md, ev);
+                        rc = md_do_upcall(env, md, ev, data);
         }
         RETURN(rc);
 }
@@ -665,7 +699,7 @@ static struct lu_device *cmm_device_free(const struct lu_env *env,
         ENTRY;
 
         LASSERT(m->cmm_tgt_count == 0);
-        LASSERT(list_empty(&m->cmm_targets));
+        LASSERT(cfs_list_empty(&m->cmm_targets));
         if (m->cmm_fld != NULL) {
                 OBD_FREE_PTR(m->cmm_fld);
                 m->cmm_fld = NULL;
@@ -720,6 +754,40 @@ struct cmm_thread_info *cmm_env_info(const struct lu_env *env)
 /* type constructor/destructor: cmm_type_init/cmm_type_fini */
 LU_TYPE_INIT_FINI(cmm, &cmm_thread_key);
 
+/* 
+ * Kludge code : it should be moved mdc_device.c if mdc_(mds)_device
+ * is really stacked.
+ */
+static int __cmm_type_init(struct lu_device_type *t)
+{
+        int rc;
+        rc = lu_device_type_init(&mdc_device_type);
+        if (rc == 0) {
+                rc = cmm_type_init(t);
+                if (rc)
+                        lu_device_type_fini(&mdc_device_type);
+        }
+        return rc;
+}
+
+static void __cmm_type_fini(struct lu_device_type *t)
+{
+        lu_device_type_fini(&mdc_device_type);
+        cmm_type_fini(t);
+}
+
+static void __cmm_type_start(struct lu_device_type *t)
+{
+        mdc_device_type.ldt_ops->ldto_start(&mdc_device_type);
+        cmm_type_start(t);
+}
+
+static void __cmm_type_stop(struct lu_device_type *t)
+{
+        mdc_device_type.ldt_ops->ldto_stop(&mdc_device_type);
+        cmm_type_stop(t);
+}
+
 static int cmm_device_init(const struct lu_env *env, struct lu_device *d,
                            const char *name, struct lu_device *next)
 {
@@ -728,7 +796,7 @@ static int cmm_device_init(const struct lu_env *env, struct lu_device *d,
         int err = 0;
         ENTRY;
 
-        spin_lock_init(&m->cmm_tgt_guard);
+        cfs_spin_lock_init(&m->cmm_tgt_guard);
         CFS_INIT_LIST_HEAD(&m->cmm_targets);
         m->cmm_tgt_count = 0;
         m->cmm_child = lu2md_dev(next);
@@ -757,20 +825,21 @@ static struct lu_device *cmm_device_fini(const struct lu_env *env,
         ENTRY;
 
         /* Finish all mdc devices */
-        spin_lock(&cm->cmm_tgt_guard);
-        list_for_each_entry_safe(mc, tmp, &cm->cmm_targets, mc_linkage) {
+        cfs_spin_lock(&cm->cmm_tgt_guard);
+        cfs_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);
+                cfs_list_del_init(&mc->mc_linkage);
                 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--;
         }
-        spin_unlock(&cm->cmm_tgt_guard);
+        cfs_spin_unlock(&cm->cmm_tgt_guard);
 
+        fld_client_proc_fini(cm->cmm_fld);
         fld_client_fini(cm->cmm_fld);
         ls = cmm2lu_dev(cm)->ld_site;
         lu_site2md(ls)->ms_client_fld = NULL;
@@ -780,11 +849,11 @@ static struct lu_device *cmm_device_fini(const struct lu_env *env,
 }
 
 static struct lu_device_type_operations cmm_device_type_ops = {
-        .ldto_init = cmm_type_init,
-        .ldto_fini = cmm_type_fini,
+        .ldto_init = __cmm_type_init,
+        .ldto_fini = __cmm_type_fini,
 
-        .ldto_start = cmm_type_start,
-        .ldto_stop  = cmm_type_stop,
+        .ldto_start = __cmm_type_start,
+        .ldto_stop  = __cmm_type_stop,
 
         .ldto_device_alloc = cmm_device_alloc,
         .ldto_device_free  = cmm_device_free,
@@ -813,33 +882,20 @@ 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;
-        int rc;
-
-        /* 
-         * Kludge code : it should be moved mdc_device.c if mdc_(mds)_device
-         * is really stacked.
-         */
-        rc = lu_device_type_init(&mdc_device_type);
-        if (rc)
-                return rc;
 
         lprocfs_cmm_init_vars(&lvars);
-        rc = class_register_type(&cmm_obd_device_ops, NULL, lvars.module_vars,
-                                 LUSTRE_CMM_NAME, &cmm_device_type);
-        if (rc)
-                lu_device_type_fini(&mdc_device_type);
-
-        return rc;
+        return class_register_type(&cmm_obd_device_ops, NULL, lvars.module_vars,
+                                   LUSTRE_CMM_NAME, &cmm_device_type);
 }
 
 static void __exit cmm_mod_exit(void)
 {
         class_unregister_type(LUSTRE_CMM_NAME);
-        lu_device_type_fini(&mdc_device_type);
 }
 
 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");