Whamcloud - gitweb
LU-3474 mdt: mdt_links_read() to return linkea_init() errors
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index f7ed271..c4ce385 100644 (file)
@@ -69,6 +69,7 @@
 #include <lustre_param.h>
 #include <lustre_quota.h>
 #include <lustre_linkea.h>
+#include <lustre_lfsck.h>
 
 mdl_mode_t mdt_mdl_lock_modes[] = {
         [LCK_MINMODE] = MDL_MINMODE,
@@ -98,7 +99,7 @@ static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
 static const struct lu_object_operations mdt_obj_ops;
 
 /* Slab for MDT object allocation */
-static cfs_mem_cache_t *mdt_object_kmem;
+static struct kmem_cache *mdt_object_kmem;
 
 static struct lu_kmem_descr mdt_caches[] = {
        {
@@ -154,6 +155,13 @@ void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
         if (name != NULL && (name[0] != '\0')) {
                 LASSERT(namelen > 0);
                 lh->mlh_pdo_hash = full_name_hash(name, namelen);
+               /* XXX Workaround for LU-2856
+                * Zero is a valid return value of full_name_hash, but several
+                * users of mlh_pdo_hash assume a non-zero hash value. We
+                * therefore map zero onto an arbitrary, but consistent
+                * value (1) to avoid problems further down the road. */
+               if (unlikely(!lh->mlh_pdo_hash))
+                       lh->mlh_pdo_hash = 1;
         } else {
                 LASSERT(namelen == 0);
                 lh->mlh_pdo_hash = 0ull;
@@ -719,11 +727,12 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                 ma->ma_som = &info->mti_u.som.data;
 
        rc = mdt_attr_get_complex(info, o, ma);
-        if (unlikely(rc)) {
-                CERROR("getattr error for "DFID": %d\n",
-                        PFID(mdt_object_fid(o)), rc);
-                RETURN(rc);
-        }
+       if (unlikely(rc)) {
+               CERROR("%s: getattr error for "DFID": rc = %d\n",
+                      mdt_obd_name(info->mti_mdt),
+                      PFID(mdt_object_fid(o)), rc);
+               RETURN(rc);
+       }
 
        is_root = lu_fid_eq(mdt_object_fid(o), &info->mti_mdt->mdt_md_root_fid);
 
@@ -744,8 +753,9 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                rc = mdt_attr_get_lov(info, root, ma);
                mdt_object_put(info->mti_env, root);
                if (unlikely(rc)) {
-                       CERROR("getattr error for "DFID": %d\n",
-                                       PFID(mdt_object_fid(o)), rc);
+                       CERROR("%s: getattr error for "DFID": rc = %d\n",
+                              mdt_obd_name(info->mti_mdt),
+                              PFID(mdt_object_fid(o)), rc);
                        RETURN(rc);
                }
        }
@@ -770,18 +780,20 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                         repbody->eadatasize = ma->ma_lmv_size;
                         repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
                 }
-        } else if (S_ISLNK(la->la_mode) &&
-                   reqbody->valid & OBD_MD_LINKNAME) {
-                buffer->lb_buf = ma->ma_lmm;
-                /* eadatasize from client includes NULL-terminator, so
-                 * there is no need to read it */
-                buffer->lb_len = reqbody->eadatasize - 1;
-                rc = mo_readlink(env, next, buffer);
-                if (unlikely(rc <= 0)) {
-                        CERROR("readlink failed: %d\n", rc);
-                        rc = -EFAULT;
-                } else {
-                       int print_limit = min_t(int, CFS_PAGE_SIZE - 128, rc);
+       } else if (S_ISLNK(la->la_mode) &&
+                  reqbody->valid & OBD_MD_LINKNAME) {
+               buffer->lb_buf = ma->ma_lmm;
+               /* eadatasize from client includes NULL-terminator, so
+                * there is no need to read it */
+               buffer->lb_len = reqbody->eadatasize - 1;
+               rc = mo_readlink(env, next, buffer);
+               if (unlikely(rc <= 0)) {
+                       CERROR("%s: readlink failed for "DFID": rc = %d\n",
+                              mdt_obd_name(info->mti_mdt),
+                              PFID(mdt_object_fid(o)), rc);
+                       rc = -EFAULT;
+               } else {
+                       int print_limit = min_t(int, PAGE_CACHE_SIZE - 128, rc);
 
                        if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
                                rc -= 2;
@@ -790,8 +802,11 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                         * because client expects that */
                        repbody->eadatasize = rc + 1;
                        if (repbody->eadatasize != reqbody->eadatasize)
-                               CERROR("Read shorter symlink %d, expected %d\n",
-                                      rc, reqbody->eadatasize - 1);
+                               CDEBUG(D_INODE, "%s: Read shorter symlink %d "
+                                      "on "DFID ", expected %d\n",
+                                      mdt_obd_name(info->mti_mdt),
+                                      rc, PFID(mdt_object_fid(o)),
+                                      reqbody->eadatasize - 1);
                        /* NULL terminate */
                        ((char *)ma->ma_lmm)[rc] = 0;
 
@@ -845,9 +860,12 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                                         rc = 0;
                                 } else if (rc == -EOPNOTSUPP) {
                                         rc = 0;
-                                } else {
-                                        CERROR("got acl size: %d\n", rc);
-                                }
+                               } else {
+                                       CERROR("%s: unable to read "DFID
+                                              " ACL: rc = %d\n",
+                                              mdt_obd_name(info->mti_mdt),
+                                              PFID(mdt_object_fid(o)), rc);
+                               }
                         } else {
                                 repbody->aclsize = rc;
                                 repbody->valid |= OBD_MD_FLACL;
@@ -1063,7 +1081,8 @@ int mdt_swap_layouts(struct mdt_thread_info *info)
                GOTO(put, rc);
 
        msl = req_capsule_client_get(info->mti_pill, &RMF_SWAP_LAYOUTS);
-       LASSERT(msl != NULL);
+       if (msl == NULL)
+               GOTO(put, rc = -EPROTO);
 
        lh1 = &info->mti_lh[MDT_LH_NEW];
        mdt_lock_reg_init(lh1, LCK_EX);
@@ -1615,7 +1634,7 @@ static int mdt_sendpage(struct mdt_thread_info *info,
 
        for (i = 0, tmpcount = nob; i < rdpg->rp_npages && tmpcount > 0;
             i++, tmpcount -= tmpsize) {
-                tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
+               tmpsize = min_t(int, tmpcount, PAGE_CACHE_SIZE);
                ptlrpc_prep_bulk_page_pin(desc, rdpg->rp_pages[i], 0, tmpsize);
         }
 
@@ -1660,14 +1679,14 @@ int mdt_readpage(struct mdt_thread_info *info)
                rdpg->rp_attrs |= LUDA_64BITHASH;
        rdpg->rp_count  = min_t(unsigned int, reqbody->nlink,
                                exp_max_brw_size(info->mti_exp));
-        rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
-                          CFS_PAGE_SHIFT;
+       rdpg->rp_npages = (rdpg->rp_count + PAGE_CACHE_SIZE - 1) >>
+                         PAGE_CACHE_SHIFT;
         OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
         if (rdpg->rp_pages == NULL)
                 RETURN(-ENOMEM);
 
         for (i = 0; i < rdpg->rp_npages; ++i) {
-                rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
+               rdpg->rp_pages[i] = alloc_page(GFP_IOFS);
                 if (rdpg->rp_pages[i] == NULL)
                         GOTO(free_rdpg, rc = -ENOMEM);
         }
@@ -1685,7 +1704,7 @@ free_rdpg:
 
         for (i = 0; i < rdpg->rp_npages; i++)
                 if (rdpg->rp_pages[i] != NULL)
-                        cfs_free_page(rdpg->rp_pages[i]);
+                       __free_page(rdpg->rp_pages[i]);
         OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
 
         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
@@ -2098,14 +2117,15 @@ int mdt_obd_idx_read(struct mdt_thread_info *info)
                GOTO(out, rc = -EFAULT);
        rdpg->rp_count = min_t(unsigned int, req_ii->ii_count << LU_PAGE_SHIFT,
                               exp_max_brw_size(info->mti_exp));
-       rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE -1) >> CFS_PAGE_SHIFT;
+       rdpg->rp_npages = (rdpg->rp_count + PAGE_CACHE_SIZE - 1) >>
+                               PAGE_CACHE_SHIFT;
 
        /* allocate pages to store the containers */
        OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
        if (rdpg->rp_pages == NULL)
                GOTO(out, rc = -ENOMEM);
        for (i = 0; i < rdpg->rp_npages; i++) {
-               rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
+               rdpg->rp_pages[i] = alloc_page(GFP_IOFS);
                if (rdpg->rp_pages[i] == NULL)
                        GOTO(out, rc = -ENOMEM);
        }
@@ -2126,7 +2146,7 @@ out:
        if (rdpg->rp_pages) {
                for (i = 0; i < rdpg->rp_npages; i++)
                        if (rdpg->rp_pages[i])
-                               cfs_free_page(rdpg->rp_pages[i]);
+                               __free_page(rdpg->rp_pages[i]);
                OBD_FREE(rdpg->rp_pages,
                         rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
        }
@@ -3690,8 +3710,8 @@ static int mdt_intent_getattr(enum mdt_it_code opcode,
         /* Get lock from request for possible resent case. */
         mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
 
-        ldlm_rep->lock_policy_res2 =
-                mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
+       rc = mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
+       ldlm_rep->lock_policy_res2 = clear_serious(rc);
 
         if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
                 ldlm_rep->lock_policy_res2 = 0;
@@ -3719,15 +3739,38 @@ static int mdt_intent_layout(enum mdt_it_code opcode,
                             __u64 flags)
 {
        struct layout_intent *layout;
+       struct lu_fid *fid;
+       struct mdt_object *obj = NULL;
+       struct md_object *child = NULL;
        int rc;
        ENTRY;
 
        if (opcode != MDT_IT_LAYOUT) {
-               CERROR("%s: Unknown intent (%d)\n",
-                       info->mti_exp->exp_obd->obd_name, opcode);
+               CERROR("%s: Unknown intent (%d)\n", mdt_obd_name(info->mti_mdt),
+                       opcode);
                RETURN(-EINVAL);
        }
 
+       fid = &info->mti_tmp_fid2;
+       fid_extract_from_res_name(fid, &(*lockp)->l_resource->lr_name);
+
+       obj = mdt_object_find(info->mti_env, info->mti_mdt, fid);
+       if (IS_ERR(obj))
+               RETURN(PTR_ERR(obj));
+
+       if (mdt_object_exists(obj) && !mdt_object_remote(obj)) {
+               child = mdt_object_child(obj);
+
+               /* get the length of lsm */
+               rc = mo_xattr_get(info->mti_env, child, &LU_BUF_NULL,
+                                 XATTR_NAME_LOV);
+
+               if (rc > info->mti_mdt->mdt_max_mdsize)
+                       info->mti_mdt->mdt_max_mdsize = rc;
+       }
+
+       mdt_object_put(info->mti_env, obj);
+
        (*lockp)->l_lvb_type = LVB_T_LAYOUT;
        req_capsule_set_size(info->mti_pill, &RMF_DLM_LVB, RCL_SERVER,
                        ldlm_lvbo_size(*lockp));
@@ -3742,7 +3785,7 @@ static int mdt_intent_layout(enum mdt_it_code opcode,
                RETURN(0);
 
        CERROR("%s: Unsupported layout intent (%d)\n",
-               info->mti_exp->exp_obd->obd_name, layout->li_opc);
+               mdt_obd_name(info->mti_mdt), layout->li_opc);
        RETURN(-EINVAL);
 }
 
@@ -3788,14 +3831,16 @@ static int mdt_intent_reint(enum mdt_it_code opcode,
         if (rc != 0)
                 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
 
-        /* Cross-ref case, the lock should be returned to the client */
-        if (rc == -EREMOTE) {
-                LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
-                rep->lock_policy_res2 = 0;
-                rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
-                RETURN(rc);
-        }
-        rep->lock_policy_res2 = clear_serious(rc);
+       /* the open lock or the lock for cross-ref object should be
+        * returned to the client */
+       if (rc == -EREMOTE || mdt_get_disposition(rep, DISP_OPEN_LOCK)) {
+               LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
+               rep->lock_policy_res2 = 0;
+               rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
+               RETURN(rc);
+       }
+
+       rep->lock_policy_res2 = clear_serious(rc);
 
         if (rep->lock_policy_res2 == -ENOENT &&
             mdt_get_disposition(rep, DISP_LOOKUP_NEG))
@@ -3921,8 +3966,18 @@ static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
                        RETURN(-EROFS);
         }
         if (rc == 0 && flv->it_act != NULL) {
-                /* execute policy */
-                rc = flv->it_act(opc, info, lockp, flags);
+               struct ldlm_reply *rep;
+
+               /* execute policy */
+               rc = flv->it_act(opc, info, lockp, flags);
+
+               /* Check whether the reply has been packed successfully. */
+               if (mdt_info_req(info)->rq_repmsg != NULL) {
+                       rep = req_capsule_server_get(info->mti_pill,
+                                                    &RMF_DLM_REP);
+                       rep->lock_policy_res2 =
+                               ptlrpc_status_hton(rep->lock_policy_res2);
+               }
         } else {
                 rc = -EOPNOTSUPP;
         }
@@ -4120,7 +4175,7 @@ static int mdt_fld_init(const struct lu_env *env,
 static void mdt_stack_pre_fini(const struct lu_env *env,
                           struct mdt_device *m, struct lu_device *top)
 {
-       struct obd_device       *obd = mdt2obd_dev(m);
+       struct obd_device       *obd;
        struct lustre_cfg_bufs  *bufs;
        struct lustre_cfg       *lcfg;
        struct mdt_thread_info  *info;
@@ -4142,7 +4197,7 @@ static void mdt_stack_pre_fini(const struct lu_env *env,
         * objects (some of them are pinned by osd, for example *
         * the proper solution should be a model where object used
         * by osd only doesn't have mdt/mdd slices -bzzz */
-       lustre_cfg_bufs_reset(bufs, obd->obd_name);
+       lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
        lustre_cfg_bufs_set_string(bufs, 1, NULL);
        lcfg = lustre_cfg_new(LCFG_PRE_CLEANUP, bufs);
        if (!lcfg) {
@@ -4155,44 +4210,44 @@ static void mdt_stack_pre_fini(const struct lu_env *env,
 }
 
 static void mdt_stack_fini(const struct lu_env *env,
-                           struct mdt_device *m, struct lu_device *top)
+                          struct mdt_device *m, struct lu_device *top)
 {
-        struct obd_device       *obd = mdt2obd_dev(m);
-        struct lustre_cfg_bufs  *bufs;
-        struct lustre_cfg       *lcfg;
-        struct mdt_thread_info  *info;
-        char flags[3]="";
-        ENTRY;
+       struct obd_device       *obd = mdt2obd_dev(m);
+       struct lustre_cfg_bufs  *bufs;
+       struct lustre_cfg       *lcfg;
+       struct mdt_thread_info  *info;
+       char                     flags[3] = "";
+       ENTRY;
 
-        info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
-        LASSERT(info != NULL);
+       info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
+       LASSERT(info != NULL);
 
        lu_dev_del_linkage(top->ld_site, top);
 
        lu_site_purge(env, top->ld_site, -1);
 
-        bufs = &info->mti_u.bufs;
-        /* process cleanup, pass mdt obd name to get obd umount flags */
+       bufs = &info->mti_u.bufs;
+       /* process cleanup, pass mdt obd name to get obd umount flags */
        /* another purpose is to let all layers to release their objects */
-        lustre_cfg_bufs_reset(bufs, obd->obd_name);
-        if (obd->obd_force)
-                strcat(flags, "F");
-        if (obd->obd_fail)
-                strcat(flags, "A");
-        lustre_cfg_bufs_set_string(bufs, 1, flags);
-        lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
-        if (!lcfg) {
-                CERROR("Cannot alloc lcfg!\n");
-                return;
-        }
-        LASSERT(top);
-        top->ld_ops->ldo_process_config(env, top, lcfg);
-        lustre_cfg_free(lcfg);
+       lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
+       if (obd->obd_force)
+               strcat(flags, "F");
+       if (obd->obd_fail)
+               strcat(flags, "A");
+       lustre_cfg_bufs_set_string(bufs, 1, flags);
+       lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
+       if (!lcfg) {
+               CERROR("Cannot alloc lcfg!\n");
+               return;
+       }
+       LASSERT(top);
+       top->ld_ops->ldo_process_config(env, top, lcfg);
+       lustre_cfg_free(lcfg);
 
        lu_site_purge(env, top->ld_site, -1);
 
-        m->mdt_child = NULL;
-        m->mdt_bottom = NULL;
+       m->mdt_child = NULL;
+       m->mdt_bottom = NULL;
 
        obd_disconnect(m->mdt_child_exp);
        m->mdt_child_exp = NULL;
@@ -4216,7 +4271,7 @@ static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
        obd = class_name2obd(next);
        if (obd == NULL) {
                CERROR("%s: can't locate next device: %s\n",
-                      m->mdt_md_dev.md_lu_dev.ld_obd->obd_name, next);
+                      mdt_obd_name(m), next);
                GOTO(out, rc = -ENOTCONN);
        }
 
@@ -4226,7 +4281,7 @@ static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
        rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
        if (rc) {
                CERROR("%s: cannot connect to next dev %s (%d)\n",
-                      m->mdt_md_dev.md_lu_dev.ld_obd->obd_name, next, rc);
+                      mdt_obd_name(m), next, rc);
                GOTO(out, rc);
        }
 
@@ -4342,7 +4397,7 @@ static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt,
 
        site = mdt->mdt_child_exp->exp_obd->obd_lu_dev->ld_site;
        LASSERT(site);
-       LASSERT(mdt->mdt_md_dev.md_lu_dev.ld_site == NULL);
+       LASSERT(mdt_lu_site(mdt) == NULL);
        mdt->mdt_md_dev.md_lu_dev.ld_site = site;
        site->ls_top_dev = &mdt->mdt_md_dev.md_lu_dev;
        mdt->mdt_child = lu2md_dev(mdt->mdt_child_exp->exp_obd->obd_lu_dev);
@@ -4566,8 +4621,8 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
                 m->mdt_nosquash_strlen = 0;
         }
 
-       next->md_ops->mdo_iocontrol(env, next, OBD_IOC_PAUSE_LFSCK,
-                                   0, NULL);
+       next->md_ops->mdo_iocontrol(env, next, OBD_IOC_PAUSE_LFSCK, 0, NULL);
+
         mdt_seq_fini(env, m);
         mdt_fld_fini(env, m);
         sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
@@ -4576,40 +4631,40 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
         cfs_timer_disarm(&m->mdt_ck_timer);
         mdt_ck_thread_stop(m);
 
-        /*
-         * Finish the stack
-         */
-        mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
+       /*
+        * Finish the stack
+        */
+       mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
 
-        LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
+       LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
 
-       server_put_mount(mdt2obd_dev(m)->obd_name, NULL);
+       server_put_mount(mdt_obd_name(m), NULL);
 
-        EXIT;
+       EXIT;
 }
 
 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
 {
-        struct mdt_device       *m = mdt_dev(obd->obd_lu_dev);
-        struct sptlrpc_rule_set  tmp_rset;
-        int                      rc;
+       struct mdt_device       *m = mdt_dev(obd->obd_lu_dev);
+       struct sptlrpc_rule_set  tmp_rset;
+       int                      rc;
 
-        sptlrpc_rule_set_init(&tmp_rset);
-        rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
-        if (rc) {
-                CERROR("mdt %s: failed get sptlrpc rules: %d\n",
-                       obd->obd_name, rc);
-                return rc;
-        }
+       sptlrpc_rule_set_init(&tmp_rset);
+       rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
+       if (rc) {
+               CERROR("mdt %s: failed get sptlrpc rules: %d\n",
+                      mdt_obd_name(m), rc);
+               return rc;
+       }
 
-        sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
+       sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
 
        write_lock(&m->mdt_sptlrpc_lock);
-        sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
-        m->mdt_sptlrpc_rset = tmp_rset;
+       sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
+       m->mdt_sptlrpc_rset = tmp_rset;
        write_unlock(&m->mdt_sptlrpc_lock);
 
-        return 0;
+       return 0;
 }
 
 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
@@ -4697,12 +4752,13 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
        /* init the stack */
        rc = mdt_stack_init((struct lu_env *)env, m, cfg);
        if (rc) {
-               CERROR("Can't init device stack, rc %d\n", rc);
+               CERROR("%s: Can't init device stack, rc %d\n",
+                      mdt_obd_name(m), rc);
                GOTO(err_lmi, rc);
        }
 
-       s = m->mdt_md_dev.md_lu_dev.ld_site;
-       ss_site = &m->mdt_seq_site;
+       s = mdt_lu_site(m);
+       ss_site = mdt_seq_site(m);
        s->ld_seq_site = ss_site;
        ss_site->ss_lu = s;
 
@@ -4717,28 +4773,28 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
         /* No connection accepted until configurations will finish */
         obd->obd_no_conn = 1;
 
-        if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
-                char *str = lustre_cfg_string(cfg, 4);
-                if (strchr(str, 'n')) {
-                        CWARN("%s: recovery disabled\n", obd->obd_name);
-                        obd->obd_replayable = 0;
-                }
-        }
+       if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
+               char *str = lustre_cfg_string(cfg, 4);
+               if (strchr(str, 'n')) {
+                       CWARN("%s: recovery disabled\n", mdt_obd_name(m));
+                       obd->obd_replayable = 0;
+               }
+       }
 
         rc = tgt_init(env, &m->mdt_lut, obd, m->mdt_bottom);
         if (rc)
                 GOTO(err_fini_stack, rc);
 
-       rc = mdt_fld_init(env, obd->obd_name, m);
+       rc = mdt_fld_init(env, mdt_obd_name(m), m);
        if (rc)
                GOTO(err_lut, rc);
 
-       rc = mdt_seq_init(env, obd->obd_name, m);
+       rc = mdt_seq_init(env, mdt_obd_name(m), m);
        if (rc)
                GOTO(err_fini_fld, rc);
 
-        snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
-                 LUSTRE_MDT_NAME"-%p", m);
+       snprintf(info->mti_u.ns_name, sizeof(info->mti_u.ns_name), "%s-%s",
+                LUSTRE_MDT_NAME, obd->obd_uuid.uuid);
         m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
                                               LDLM_NAMESPACE_SERVER,
                                               LDLM_NAMESPACE_GREEDY,
@@ -4781,18 +4837,19 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
         else
                 m->mdt_opts.mo_acl = 0;
 
-        /* XXX: to support suppgid for ACL, we enable identity_upcall
-         * by default, otherwise, maybe got unexpected -EACCESS. */
-        if (m->mdt_opts.mo_acl)
-                identity_upcall = MDT_IDENTITY_UPCALL_PATH;
-
-        m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
-                                                &mdt_identity_upcall_cache_ops);
-        if (IS_ERR(m->mdt_identity_cache)) {
-                rc = PTR_ERR(m->mdt_identity_cache);
-                m->mdt_identity_cache = NULL;
+       /* XXX: to support suppgid for ACL, we enable identity_upcall
+        * by default, otherwise, maybe got unexpected -EACCESS. */
+       if (m->mdt_opts.mo_acl)
+               identity_upcall = MDT_IDENTITY_UPCALL_PATH;
+
+       m->mdt_identity_cache = upcall_cache_init(mdt_obd_name(m),
+                                               identity_upcall,
+                                               &mdt_identity_upcall_cache_ops);
+       if (IS_ERR(m->mdt_identity_cache)) {
+               rc = PTR_ERR(m->mdt_identity_cache);
+               m->mdt_identity_cache = NULL;
                GOTO(err_llog_cleanup, rc);
-        }
+       }
 
         rc = mdt_procfs_init(m, dev);
         if (rc) {
@@ -4940,7 +4997,7 @@ static struct lu_object *mdt_object_alloc(const struct lu_env *env,
 
         ENTRY;
 
-       OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, CFS_ALLOC_IO);
+       OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, __GFP_IO);
         if (mo != NULL) {
                 struct lu_object *o;
                 struct lu_object_header *h;
@@ -5014,6 +5071,7 @@ static int mdt_prepare(const struct lu_env *env,
        struct mdt_device *mdt = mdt_dev(cdev);
        struct lu_device *next = &mdt->mdt_child->md_lu_dev;
        struct obd_device *obd = cdev->ld_obd;
+       struct lfsck_start_param lsp;
        int rc;
 
        ENTRY;
@@ -5028,11 +5086,16 @@ static int mdt_prepare(const struct lu_env *env,
        if (rc)
                RETURN(rc);
 
+       lsp.lsp_start = NULL;
+       lsp.lsp_namespace = mdt->mdt_namespace;
        rc = mdt->mdt_child->md_ops->mdo_iocontrol(env, mdt->mdt_child,
                                                   OBD_IOC_START_LFSCK,
-                                                  0, NULL);
-       if (rc != 0)
-               CWARN("Fail to auto trigger paused LFSCK.\n");
+                                                  0, &lsp);
+       if (rc != 0) {
+               CWARN("%s: auto trigger paused LFSCK failed: rc = %d\n",
+                     mdt_obd_name(mdt), rc);
+               rc = 0;
+       }
 
        if (mdt->mdt_seq_site.ss_node_id == 0) {
                rc = mdt->mdt_child->md_ops->mdo_root_get(env, mdt->mdt_child,
@@ -5142,7 +5205,7 @@ static int mdt_connect_internal(struct obd_export *exp,
                               "unexpectedly zero, network data "
                               "corruption? Refusing connection of this"
                               " client\n",
-                              exp->exp_obd->obd_name,
+                              mdt_obd_name(mdt),
                               exp->exp_client_uuid.uuid,
                               exp, data->ocd_connect_flags, data->ocd_version,
                               data->ocd_grant, data->ocd_index);
@@ -5167,7 +5230,7 @@ static int mdt_connect_internal(struct obd_export *exp,
 
        if ((data->ocd_connect_flags & OBD_CONNECT_FID) == 0) {
                CWARN("%s: MDS requires FID support, but client not\n",
-                     mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
+                     mdt_obd_name(mdt));
                return -EBADE;
        }
 
@@ -5176,12 +5239,12 @@ static int mdt_connect_internal(struct obd_export *exp,
                                         OBD_CONNECT_MDS_MDS |
                                         OBD_CONNECT_SOM))) {
                CWARN("%s: MDS has SOM enabled, but client does not support "
-                     "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
+                     "it\n", mdt_obd_name(mdt));
                return -EBADE;
        }
 
-       if (data->ocd_connect_flags & OBD_CONNECT_PINGLESS) {
-               if (suppress_pings) {
+       if (OCD_HAS_FLAG(data, PINGLESS)) {
+               if (ptlrpc_pinger_suppress_pings()) {
                        spin_lock(&exp->exp_obd->obd_dev_lock);
                        list_del_init(&exp->exp_obd_chain_timed);
                        spin_unlock(&exp->exp_obd->obd_dev_lock);
@@ -5527,9 +5590,7 @@ static int mdt_links_read(struct mdt_thread_info *info,
        if (rc < 0)
                return rc;
 
-       linkea_init(ldata);
-
-       return 0;
+       return linkea_init(ldata);
 }
 
 static int mdt_path_current(struct mdt_thread_info *info,
@@ -5545,7 +5606,7 @@ static int mdt_path_current(struct mdt_thread_info *info,
        char                    *ptr;
        int                     reclen;
        struct linkea_data      ldata = { 0 };
-       int                     rc;
+       int                     rc = 0;
        ENTRY;
 
        /* temp buffer for path element, the buffer will be finally freed
@@ -5581,7 +5642,7 @@ static int mdt_path_current(struct mdt_thread_info *info,
                rc = mdt_links_read(info, mdt_obj, &ldata);
                mdt_object_put(info->mti_env, mdt_obj);
                if (rc != 0)
-                       GOTO(out, rc = PTR_ERR(buf));
+                       GOTO(out, rc);
 
                leh = buf->lb_buf;
                lee = (struct link_ea_entry *)(leh + 1); /* link #0 */
@@ -5674,7 +5735,6 @@ static int mdt_fid2path(struct mdt_thread_info *info,
                        struct getinfo_fid2path *fp)
 {
        struct mdt_device *mdt = info->mti_mdt;
-       struct obd_device *obd = mdt2obd_dev(mdt);
        struct mdt_object *obj;
        int    rc;
        ENTRY;
@@ -5685,17 +5745,17 @@ static int mdt_fid2path(struct mdt_thread_info *info,
        if (!fid_is_sane(&fp->gf_fid))
                RETURN(-EINVAL);
 
-       if (!fid_is_client_mdt_visible(&fp->gf_fid)) {
+       if (!fid_is_namespace_visible(&fp->gf_fid)) {
                CWARN("%s: "DFID" is invalid, sequence should be "
-                       ">= "LPX64"\n", obd->obd_name,
-                       PFID(&fp->gf_fid), (__u64)FID_SEQ_NORMAL);
+                     ">= "LPX64"\n", mdt_obd_name(mdt),
+                     PFID(&fp->gf_fid), (__u64)FID_SEQ_NORMAL);
                RETURN(-EINVAL);
        }
 
        obj = mdt_object_find(info->mti_env, mdt, &fp->gf_fid);
        if (obj == NULL || IS_ERR(obj)) {
                CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
-                       PTR_ERR(obj));
+                      PTR_ERR(obj));
                RETURN(-EINVAL);
        }
 
@@ -5709,7 +5769,7 @@ static int mdt_fid2path(struct mdt_thread_info *info,
        if (rc < 0) {
                mdt_object_put(info->mti_env, obj);
                CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
-                       PFID(&fp->gf_fid), rc);
+                      PFID(&fp->gf_fid), rc);
                RETURN(rc);
        }
 
@@ -5813,17 +5873,24 @@ static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
 
 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
 {
-        struct obd_ioctl_data *data = karg;
-        struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
-        __u64 version;
-        struct mdt_object *obj;
-        struct mdt_lock_handle  *lh;
-        int rc;
-        ENTRY;
+       struct obd_ioctl_data *data = karg;
+       struct lu_fid *fid;
+       __u64 version;
+       struct mdt_object *obj;
+       struct mdt_lock_handle  *lh;
+       int rc;
+       ENTRY;
 
-        CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
-        if (!fid_is_sane(fid))
-                RETURN(-EINVAL);
+       if (data->ioc_inlbuf1 == NULL || data->ioc_inllen1 != sizeof(*fid) ||
+           data->ioc_inlbuf2 == NULL || data->ioc_inllen2 != sizeof(version))
+               RETURN(-EINVAL);
+
+       fid = (struct lu_fid *)data->ioc_inlbuf1;
+
+       if (!fid_is_sane(fid))
+               RETURN(-EINVAL);
+
+       CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
 
         lh = &mti->mti_lh[MDT_LH_PARENT];
         mdt_lock_reg_init(lh, LCK_CR);
@@ -5874,29 +5941,35 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
         case OBD_IOC_SET_READONLY:
                 rc = dt->dd_ops->dt_ro(&env, dt);
                 break;
-        case OBD_IOC_ABORT_RECOVERY:
-                CERROR("Aborting recovery for device %s\n", obd->obd_name);
-                target_stop_recovery_thread(obd);
-                rc = 0;
-                break;
+       case OBD_IOC_ABORT_RECOVERY:
+               CERROR("%s: Aborting recovery for device\n", mdt_obd_name(mdt));
+               target_stop_recovery_thread(obd);
+               rc = 0;
+               break;
         case OBD_IOC_CHANGELOG_REG:
         case OBD_IOC_CHANGELOG_DEREG:
         case OBD_IOC_CHANGELOG_CLEAR:
                 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
                 break;
-       case OBD_IOC_START_LFSCK:
-       case OBD_IOC_STOP_LFSCK: {
+       case OBD_IOC_START_LFSCK: {
                struct md_device *next = mdt->mdt_child;
                struct obd_ioctl_data *data = karg;
+               struct lfsck_start_param lsp;
 
                if (unlikely(data == NULL)) {
                        rc = -EINVAL;
                        break;
                }
 
-               rc = next->md_ops->mdo_iocontrol(&env, next, cmd,
-                                                data->ioc_inllen1,
-                                                data->ioc_inlbuf1);
+               lsp.lsp_start = (struct lfsck_start *)(data->ioc_inlbuf1);
+               lsp.lsp_namespace = mdt->mdt_namespace;
+               rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0, &lsp);
+               break;
+       }
+       case OBD_IOC_STOP_LFSCK: {
+               struct md_device *next = mdt->mdt_child;
+
+               rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0, NULL);
                break;
        }
         case OBD_IOC_GET_OBJ_VERSION: {
@@ -5910,11 +5983,11 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 rc = mdt_ioc_version_get(mti, karg);
                 break;
         }
-        default:
-                CERROR("Not supported cmd = %d for device %s\n",
-                       cmd, obd->obd_name);
-                rc = -EOPNOTSUPP;
-        }
+       default:
+               rc = -EOPNOTSUPP;
+               CERROR("%s: Not supported cmd = %d, rc = %d\n",
+                       mdt_obd_name(mdt), cmd, rc);
+       }
 
         lu_env_fini(&env);
         RETURN(rc);
@@ -6082,6 +6155,10 @@ static int __init mdt_mod_init(void)
        struct lprocfs_static_vars lvars;
        int rc;
 
+       CLASSERT(sizeof("0x0123456789ABCDEF:0x01234567:0x01234567") ==
+                FID_NOBRACE_LEN + 1);
+       CLASSERT(sizeof("[0x0123456789ABCDEF:0x01234567:0x01234567]") ==
+                FID_LEN + 1);
        rc = lu_kmem_init(mdt_caches);
        if (rc)
                return rc;