Whamcloud - gitweb
add process_config, fix issue with stack_init/fini (thx Huang Hua) and remove
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index 70ebd3c..b4df1e2 100644 (file)
@@ -1004,7 +1004,7 @@ static int mdt_fld(struct mdt_thread_info *info,
         struct lu_site *ls  = info->mti_mdt->mdt_md_dev.md_lu_dev.ld_site;
         struct md_fld mf, *p, *reply;
         int size = sizeof(*reply);
-        __u32 *opt; 
+        __u32 *opt;
         int rc;
         ENTRY;
 
@@ -1015,10 +1015,10 @@ static int mdt_fld(struct mdt_thread_info *info,
         opt = lustre_swab_reqbuf(req, 0, sizeof(*opt), lustre_swab_generic_32s);
         p = lustre_swab_reqbuf(req, 1, sizeof(mf), lustre_swab_md_fld);
         mf = *p;
-        
+
         rc = fld_handle(ls->ls_fld, *opt, &mf);
         if (rc)
-                RETURN(rc);        
+                RETURN(rc);
 
         reply = lustre_msg_buf(req->rq_repmsg, 0, size);
         *reply = mf;
@@ -1039,16 +1039,16 @@ static int mdt_fld_init(struct mdt_device *m)
         ENTRY;
 
         dt = md2_bottom_dev(m);
-       
+
         ls = m->mdt_md_dev.md_lu_dev.ld_site;
-        
+
         OBD_ALLOC_PTR(ls->ls_fld);
-        
+
         if (!ls->ls_fld)
              RETURN(-ENOMEM);
-        
+
         rc = fld_server_init(ls->ls_fld, dt);
-        
+
         RETURN(rc);
 }
 
@@ -1056,7 +1056,7 @@ static int mdt_fld_fini(struct mdt_device *m)
 {
         struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
         int rc = 0;
+
         if (ls && ls->ls_fld) {
                 fld_server_fini(ls->ls_fld);
                 OBD_FREE_PTR(ls->ls_fld);
@@ -1140,29 +1140,26 @@ err_mdt_svc:
 
 static void mdt_stack_fini(struct mdt_device *m)
 {
-        if (m->mdt_child) {
-                struct lu_device *d = md2lu_dev(m->mdt_child);
-                /* goes through all stack */
-                while (d != NULL) {
-                        struct lu_device *n;
-                        struct obd_type *type;
-                        struct lu_device_type *ldt = d->ld_type;
-
-                        lu_device_put(d);
-                        
-                        /* each fini() returns next device in stack of layers 
-                         * so we can avoid the recursion */
-                        n = d->ld_type->ldt_ops->ldto_device_fini(d);
-                        d->ld_type->ldt_ops->ldto_device_free(d);
-
-                        type = ldt->obd_type;
-                        type->typ_refcnt--;
-                        class_put_type(type);
-                        /* switch to the next device in the layer */
-                        d = n;
-                }
+        struct lu_device *d = md2lu_dev(m->mdt_child);
+        /* goes through all stack */
+        while (d != NULL) {
+                struct lu_device *n;
+                struct obd_type *type;
+                struct lu_device_type *ldt = d->ld_type;
+                
+                lu_device_put(d);
+                
+                /* each fini() returns next device in stack of layers
+                 * * so we can avoid the recursion */
+                n = ldt->ldt_ops->ldto_device_fini(d);
+                ldt->ldt_ops->ldto_device_free(d);
+                
+                type = ldt->obd_type;
+                type->typ_refcnt--;
+                class_put_type(type);
+                /* switch to the next device in the layer */
+                d = n;
         }
-        return;
 }
 
 static struct lu_device *mdt_layer_setup(const char *typename,
@@ -1187,13 +1184,13 @@ static struct lu_device *mdt_layer_setup(const char *typename,
                 CERROR("type: '%s'\n", typename);
                 GOTO(out_type, rc = -EINVAL);
         }
-                
+
         d = ldt->ldt_ops->ldto_device_alloc(ldt, cfg);
         if (IS_ERR(d)) {
                 CERROR("Cannot allocate device: '%s'\n", typename);
                 GOTO(out_type, rc = -ENODEV);
         }
-        
+
         LASSERT(child->ld_site);
         d->ld_site = child->ld_site;
 
@@ -1215,32 +1212,39 @@ out:
         RETURN(ERR_PTR(rc));
 }
 
-static int mdt_stack_init(struct mdt_device *m, struct lustre_cfg *cfg) 
+static int mdt_stack_init(struct mdt_device *m, struct lustre_cfg *cfg)
 {
         struct lu_device  *d = &m->mdt_md_dev.md_lu_dev;
+        struct lu_device  *tmp;
         int rc;
-        
+
         /* init the stack */
-        d = mdt_layer_setup(LUSTRE_OSD0_NAME, d, cfg);
-        if (IS_ERR(d)) {
-                GOTO(out, rc = PTR_ERR(d));
+        tmp = mdt_layer_setup(LUSTRE_OSD0_NAME, d, cfg);
+        if (IS_ERR(tmp)) {
+                RETURN (PTR_ERR(tmp));
         }
-
-        d = mdt_layer_setup(LUSTRE_MDD0_NAME, d, cfg);
-        if (IS_ERR(d)) {
-                GOTO(out, rc = PTR_ERR(d));
+        d = tmp;
+        tmp = mdt_layer_setup(LUSTRE_MDD0_NAME, d, cfg);
+        if (IS_ERR(tmp)) {
+                GOTO(out, rc = PTR_ERR(tmp));
         }
-
-        d = mdt_layer_setup(LUSTRE_CMM0_NAME, d, cfg);
-        if (IS_ERR(d)) {
-                GOTO(out, rc = PTR_ERR(d));
+        d = tmp;
+        tmp = mdt_layer_setup(LUSTRE_CMM0_NAME, d, cfg);
+        if (IS_ERR(tmp)) {
+                GOTO(out, rc = PTR_ERR(tmp));
         }
-
+        d = tmp;
         m->mdt_child = lu2md_dev(d);
 
-        RETURN(0);
+        /* process setup config */
+        tmp = &m->mdt_md_dev.md_lu_dev;
+        rc = tmp->ld_ops->ldo_process_config(tmp, cfg);
+        
 out:
-        mdt_stack_fini(m);
+        /* fini from last known good lu_device */
+        if (rc)
+                mdt_stack_fini(d);
+        
         return rc;
 }
 
@@ -1248,7 +1252,13 @@ static void mdt_fini(struct mdt_device *m)
 {
         struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
 
+        ENTRY;
+
         mdt_stop_ptlrpc_service(m);
+
+        /* finish the stack */
+        mdt_stack_fini(m);
+
         if (d->ld_site != NULL) {
                 lu_site_fini(d->ld_site);
                 OBD_FREE_PTR(d->ld_site);
@@ -1259,9 +1269,6 @@ static void mdt_fini(struct mdt_device *m)
                 m->mdt_namespace = NULL;
         }
 
-        /* finish the stack */
-        mdt_stack_fini(m);
-
         if (m->mdt_seq_mgr) {
                 seq_mgr_fini(m->mdt_seq_mgr);
                 m->mdt_seq_mgr = NULL;
@@ -1269,6 +1276,7 @@ static void mdt_fini(struct mdt_device *m)
 
         LASSERT(atomic_read(&d->ld_ref) == 0);
         md_device_fini(&m->mdt_md_dev);
+        EXIT;
 }
 
 static int mdt_init0(struct mdt_device *m,
@@ -1278,6 +1286,7 @@ static int mdt_init0(struct mdt_device *m,
         struct lu_site *s;
         char   ns_name[48];
         struct lu_context ctx;
+
         ENTRY;
 
         OBD_ALLOC_PTR(s);
@@ -1286,12 +1295,13 @@ static int mdt_init0(struct mdt_device *m,
 
         md_device_init(&m->mdt_md_dev, t);
         m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
-        
-        rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev, cfg);
+
+        rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
         if (rc) {
                 CERROR("can't init lu_site, rc %d\n", rc);
                 GOTO(err_fini_site, rc);
         }
+
         /* init the stack */
         rc = mdt_stack_init(m, cfg);
         if (rc) {
@@ -1346,12 +1356,26 @@ err_fini_mgr:
         m->mdt_seq_mgr = NULL;
 err_fini_stack:
         mdt_stack_fini(m);
-
 err_fini_site:
         lu_site_fini(s);
         OBD_FREE_PTR(s);
         RETURN(rc);
 }
+/* used by MGS to process specific configurations */
+static int mdt_process_config(struct lu_device *d, struct lustre_cfg *cfg)
+{
+        struct lu_device *next = md2lu_dev(mdt_dev(d)->mdt_child);
+        int err;
+        ENTRY;
+        switch(cfg->lcfg_command) {
+                /* all MDT specific commands should be here */
+        default:
+                /* others are passed further */
+                err = next->ld_ops->ldo_process_config(next, cfg);
+        }
+out:
+        RETURN(err);
+}
 
 static struct lu_object *mdt_object_alloc(struct lu_context *ctxt,
                                           struct lu_device *d)
@@ -1390,7 +1414,7 @@ static int mdt_object_init(struct lu_context *ctxt, struct lu_object *o)
 
 static void mdt_object_free(struct lu_context *ctxt, struct lu_object *o)
 {
-        struct mdt_object *mo = lu2mdt_obj(o);
+        struct mdt_object *mo = mdt_obj(o);
         struct lu_object_header *h;
 
         h = o->lo_header;
@@ -1414,7 +1438,8 @@ static struct lu_device_operations mdt_lu_ops = {
         .ldo_object_init    = mdt_object_init,
         .ldo_object_free    = mdt_object_free,
         .ldo_object_release = mdt_object_release,
-        .ldo_object_print   = mdt_object_print
+        .ldo_object_print   = mdt_object_print,
+        .ldo_process_config = mdt_process_config
 };
 
 /* mds_connect copy */
@@ -1441,7 +1466,7 @@ static int mdt_obd_connect(struct lustre_handle *conn, struct obd_device *obd,
         exp = class_conn2export(conn);
         LASSERT(exp);
         med = &exp->exp_mds_data;
-        
+
         OBD_ALLOC_PTR(mcd);
         if (!mcd)
                 GOTO(out, rc = -ENOMEM);
@@ -1487,7 +1512,7 @@ static int mdt_obd_disconnect(struct obd_export *exp)
                 spin_unlock(&svc->srv_lock);
         }
         spin_unlock_irqrestore(&exp->exp_lock, irqflags);
-        
+
         OBD_FREE_PTR(med->med_mcd);
 
         class_export_put(exp);