Whamcloud - gitweb
b=20748
[fs/lustre-release.git] / lustre / cmm / cmm_device.c
index 839322a..deda49e 100644 (file)
@@ -57,7 +57,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 +65,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,
@@ -84,7 +84,7 @@ static int cmm_statfs(const struct lu_env *env, struct md_device *md,
                       struct kstatfs *sfs)
 {
         struct cmm_device *cmm_dev = md2cmm_dev(md);
-       int rc;
+        int rc;
 
         ENTRY;
         rc = cmm_child_ops(cmm_dev)->mdo_statfs(env,
@@ -130,6 +130,18 @@ 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
 static int cmm_quota_notify(const struct lu_env *env, struct md_device *m)
 {
@@ -137,10 +149,6 @@ static int cmm_quota_notify(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_notify(env,
                                                           cmm_dev->cmm_child);
         RETURN(rc);
@@ -153,10 +161,6 @@ static int cmm_quota_setup(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_setup(env,
                                                          cmm_dev->cmm_child,
                                                          data);
@@ -169,10 +173,6 @@ static int cmm_quota_cleanup(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_cleanup(env,
                                                            cmm_dev->cmm_child);
         RETURN(rc);
@@ -184,10 +184,6 @@ static int cmm_quota_recovery(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_recovery(env,
                                                             cmm_dev->cmm_child);
         RETURN(rc);
@@ -211,7 +207,7 @@ static int cmm_quota_check(const struct lu_env *env, struct md_device *m,
 }
 
 static int cmm_quota_on(const struct lu_env *env, struct md_device *m,
-                        __u32 type, __u32 id)
+                        __u32 type)
 {
         struct cmm_device *cmm_dev = md2cmm_dev(m);
         int rc;
@@ -223,24 +219,20 @@ static int cmm_quota_on(const struct lu_env *env, struct md_device *m,
 
         rc = cmm_child_ops(cmm_dev)->mdo_quota.mqo_on(env,
                                                       cmm_dev->cmm_child,
-                                                      type, id);
+                                                      type);
         RETURN(rc);
 }
 
 static int cmm_quota_off(const struct lu_env *env, struct md_device *m,
-                         __u32 type, __u32 id)
+                         __u32 type)
 {
         struct cmm_device *cmm_dev = md2cmm_dev(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, id);
+                                                       type);
         RETURN(rc);
 }
 
@@ -385,12 +377,26 @@ static int cmm_quota_finvalidate(const struct lu_env *env, struct md_device *m,
 }
 #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,
@@ -447,7 +453,11 @@ static int cmm_add_mdc(const struct lu_env *env,
         struct lu_device *ld;
         struct lu_device *cmm_lu = cmm2lu_dev(cm);
         mdsno_t mdc_num;
+        struct lu_site *site = cmm2lu_dev(cm)->ld_site;
         int rc;
+#ifdef HAVE_QUOTA_SUPPORT
+        int first;
+#endif
         ENTRY;
 
         /* find out that there is no such mdc */
@@ -471,7 +481,7 @@ static int cmm_add_mdc(const struct lu_env *env,
         if (IS_ERR(ld))
                 RETURN(PTR_ERR(ld));
 
-        ld->ld_site = cmm2lu_dev(cm)->ld_site;
+        ld->ld_site = site;
 
         rc = ldt->ldt_ops->ldto_device_init(env, ld, NULL, NULL);
         if (rc) {
@@ -499,6 +509,9 @@ static int cmm_add_mdc(const struct lu_env *env,
         mc = lu2mdc_dev(ld);
         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);
 
         lu_device_get(cmm_lu);
@@ -509,6 +522,20 @@ static int cmm_add_mdc(const struct lu_env *env,
         target.ft_exp = mc->mc_desc.cl_exp;
         fld_client_add_target(cm->cmm_fld, &target);
 
+        if (mc->mc_num == 0) {
+                /* this is mdt0 -> mc export, fld lookup need this export
+                   to forward fld lookup request. */
+                LASSERT(!lu_site2md(site)->ms_server_fld->lsf_control_exp);
+                lu_site2md(site)->ms_server_fld->lsf_control_exp =
+                                          mc->mc_desc.cl_exp;
+        }
+#ifdef HAVE_QUOTA_SUPPORT
+        /* XXX: Disable quota for CMD case temporary. */
+        if (first == 1) {
+                CWARN("Disable quota for CMD case temporary!\n");
+                cmm_child_ops(cm)->mdo_quota.mqo_off(env, cm->cmm_child, UGQUOTA);
+        }
+#endif
         /* Set max md size for the mdc. */
         rc = cmm_post_init_mdc(env, cm);
         RETURN(rc);
@@ -613,15 +640,29 @@ static int cmm_recovery_complete(const struct lu_env *env,
         RETURN(rc);
 }
 
+static int cmm_prepare(const struct lu_env *env,
+                       struct lu_device *pdev,
+                       struct lu_device *dev)
+{
+        struct cmm_device *cmm = lu2cmm_dev(dev);
+        struct lu_device *next = md2lu_dev(cmm->cmm_child);
+        int rc;
+
+        ENTRY;
+        rc = next->ld_ops->ldo_prepare(env, dev, next);
+        RETURN(rc);
+}
+
 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_recovery_complete = cmm_recovery_complete,
+        .ldo_prepare           = cmm_prepare,
 };
 
 /* --- 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;
@@ -633,7 +674,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);
 }
@@ -701,6 +742,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)
 {
@@ -761,11 +836,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,