Whamcloud - gitweb
LU-3319 procfs: move mdd/ofd proc handling to seq_files
[fs/lustre-release.git] / lustre / lfsck / lfsck_layout.c
index ced2e4d..cb39f8c 100644 (file)
@@ -492,7 +492,7 @@ static struct lfsck_rbtree_node *lfsck_rbtree_new(const struct lu_env *env,
                return ERR_PTR(-ENOMEM);
        }
 
-       rb_init_node(&lrn->lrn_node);
+       RB_CLEAR_NODE(&lrn->lrn_node);
        lrn->lrn_seq = fid_seq(fid);
        lrn->lrn_first_oid = fid_oid(fid) & ~LFSCK_RBTREE_BITMAP_MASK;
        atomic_set(&lrn->lrn_known_count, 0);
@@ -673,15 +673,6 @@ out:
        }
 }
 
-static inline bool is_dummy_lov_ost_data(struct lov_ost_data_v1 *obj)
-{
-       if (fid_is_zero(&obj->l_ost_oi.oi_fid) &&
-           obj->l_ost_gen == 0 && obj->l_ost_idx == 0)
-               return true;
-
-       return false;
-}
-
 static void lfsck_layout_le_to_cpu(struct lfsck_layout *des,
                                   const struct lfsck_layout *src)
 {
@@ -1469,6 +1460,7 @@ static int lfsck_layout_master_notify_others(const struct lu_env *env,
                        break;
 
                /* link other MDT targets locallly. */
+               ltds = &lfsck->li_mdt_descs;
                spin_lock(&ltds->ltd_lock);
                cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
                        ltd = LTD_TGT(ltds, idx);
@@ -1694,6 +1686,45 @@ static int lfsck_layout_trans_stop(const struct lu_env *env,
 }
 
 /**
+ * Get the system default stripe size.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] lfsck    pointer to the lfsck instance
+ * \param[out] size    pointer to the default stripe size
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
+static int lfsck_layout_get_def_stripesize(const struct lu_env *env,
+                                          struct lfsck_instance *lfsck,
+                                          __u32 *size)
+{
+       struct lov_user_md      *lum = &lfsck_env_info(env)->lti_lum;
+       struct dt_object        *root;
+       int                      rc;
+
+       root = dt_locate(env, lfsck->li_next, &lfsck->li_local_root_fid);
+       if (IS_ERR(root))
+               return PTR_ERR(root);
+
+       /* Get the default stripe size via xattr_get on the backend root. */
+       rc = dt_xattr_get(env, root, lfsck_buf_get(env, lum, sizeof(*lum)),
+                         XATTR_NAME_LOV, BYPASS_CAPA);
+       if (rc > 0) {
+               /* The lum->lmm_stripe_size is LE mode. The *size also
+                * should be LE mode. So it is unnecessary to convert. */
+               *size = lum->lmm_stripe_size;
+               rc = 0;
+       } else if (unlikely(rc == 0)) {
+               rc = -EINVAL;
+       }
+
+       lfsck_object_put(env, root);
+
+       return rc;
+}
+
+/**
  * \retval      +1: repaired
  * \retval       0: did nothing
  * \retval     -ve: on error
@@ -1706,13 +1737,36 @@ static int lfsck_layout_refill_lovea(const struct lu_env *env,
                                     struct lov_ost_data_v1 *slot,
                                     int fl, __u32 ost_idx)
 {
-       struct ost_id   *oi     = &lfsck_env_info(env)->lti_oi;
-       int              rc;
+       struct ost_id           *oi     = &lfsck_env_info(env)->lti_oi;
+       struct lov_mds_md_v1    *lmm    = buf->lb_buf;
+       int                      rc;
 
        fid_to_ostid(cfid, oi);
        ostid_cpu_to_le(oi, &slot->l_ost_oi);
        slot->l_ost_gen = cpu_to_le32(0);
        slot->l_ost_idx = cpu_to_le32(ost_idx);
+
+       if (le32_to_cpu(lmm->lmm_pattern) & LOV_PATTERN_F_HOLE) {
+               struct lov_ost_data_v1 *objs;
+               int                     i;
+               __u16                   count;
+
+               count = le16_to_cpu(lmm->lmm_stripe_count);
+               if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_V1)
+                       objs = &lmm->lmm_objects[0];
+               else
+                       objs = &((struct lov_mds_md_v3 *)lmm)->lmm_objects[0];
+               for (i = 0; i < count; i++, objs++) {
+                       if (objs != slot && lovea_slot_is_dummy(objs))
+                               break;
+               }
+
+               /* If the @slot is the last dummy slot to be refilled,
+                * then drop LOV_PATTERN_F_HOLE from lmm::lmm_pattern. */
+               if (i == count)
+                       lmm->lmm_pattern &= ~cpu_to_le32(LOV_PATTERN_F_HOLE);
+       }
+
        rc = dt_xattr_set(env, parent, buf, XATTR_NAME_LOV, fl, handle,
                          BYPASS_CAPA);
        if (rc == 0)
@@ -1727,6 +1781,7 @@ static int lfsck_layout_refill_lovea(const struct lu_env *env,
  * \retval     -ve: on error
  */
 static int lfsck_layout_extend_lovea(const struct lu_env *env,
+                                    struct lfsck_instance *lfsck,
                                     struct thandle *handle,
                                     struct dt_object *parent,
                                     struct lu_fid *cfid,
@@ -1736,50 +1791,57 @@ static int lfsck_layout_extend_lovea(const struct lu_env *env,
        struct lov_mds_md_v1    *lmm    = buf->lb_buf;
        struct lov_ost_data_v1  *objs;
        int                      rc;
+       __u16                    count;
        ENTRY;
 
        if (fl == LU_XATTR_CREATE || reset) {
-               LASSERT(buf->lb_len == lov_mds_md_size(ea_off + 1,
-                                                      LOV_MAGIC_V1));
+               __u32 pattern = LOV_PATTERN_RAID0;
+
+               count = ea_off + 1;
+               LASSERT(buf->lb_len == lov_mds_md_size(count, LOV_MAGIC_V1));
+
+               if (ea_off != 0 || reset)
+                       pattern |= LOV_PATTERN_F_HOLE;
 
                memset(lmm, 0, buf->lb_len);
                lmm->lmm_magic = cpu_to_le32(LOV_MAGIC_V1);
-               /* XXX: currently, we only support LOV_PATTERN_RAID0. */
-               lmm->lmm_pattern = cpu_to_le32(LOV_PATTERN_RAID0);
+               lmm->lmm_pattern = cpu_to_le32(pattern);
                fid_to_lmm_oi(lfsck_dto2fid(parent), &lmm->lmm_oi);
                lmm_oi_cpu_to_le(&lmm->lmm_oi, &lmm->lmm_oi);
-               /* XXX: We cannot know the stripe size,
-                *      then use the default value (1 MB). */
-               lmm->lmm_stripe_size =
-                       cpu_to_le32(LOV_DESC_STRIPE_SIZE_DEFAULT);
-               objs = &(lmm->lmm_objects[ea_off]);
+
+               rc = lfsck_layout_get_def_stripesize(env, lfsck,
+                                                    &lmm->lmm_stripe_size);
+               if (rc != 0)
+                       RETURN(rc);
+
+               objs = &lmm->lmm_objects[ea_off];
        } else {
-               __u16   count = le16_to_cpu(lmm->lmm_stripe_count);
-               int     gap   = ea_off - count;
                __u32   magic = le32_to_cpu(lmm->lmm_magic);
+               int     gap;
 
-               /* Currently, we only support LOV_MAGIC_V1/LOV_MAGIC_V3
-                * which has been verified in lfsck_layout_verify_header()
-                * already. If some new magic introduced in the future,
-                * then layout LFSCK needs to be updated also. */
-               if (magic == LOV_MAGIC_V1) {
-                       objs = &(lmm->lmm_objects[count]);
-               } else {
-                       LASSERT(magic == LOV_MAGIC_V3);
+               count = le16_to_cpu(lmm->lmm_stripe_count);
+               if (magic == LOV_MAGIC_V1)
+                       objs = &lmm->lmm_objects[count];
+               else
                        objs = &((struct lov_mds_md_v3 *)lmm)->
                                                        lmm_objects[count];
-               }
 
-               if (gap > 0)
+               gap = ea_off - count;
+               if (gap >= 0)
+                       count = ea_off + 1;
+               LASSERT(buf->lb_len == lov_mds_md_size(count, magic));
+
+               if (gap > 0) {
                        memset(objs, 0, gap * sizeof(*objs));
+                       lmm->lmm_pattern |= cpu_to_le32(LOV_PATTERN_F_HOLE);
+               }
+
                lmm->lmm_layout_gen =
                            cpu_to_le16(le16_to_cpu(lmm->lmm_layout_gen) + 1);
                objs += gap;
-
-               LASSERT(buf->lb_len == lov_mds_md_size(ea_off + 1, magic));
        }
 
-       lmm->lmm_stripe_count = cpu_to_le16(ea_off + 1);
+       lmm->lmm_stripe_count = cpu_to_le16(count);
        rc = lfsck_layout_refill_lovea(env, handle, parent, cfid, buf, objs,
                                       fl, ost_idx);
 
@@ -1844,17 +1906,57 @@ out:
 }
 
 /**
- * \retval      +1: repaired
- * \retval       0: did nothing
- * \retval     -ve: on error
+ * This function will create the MDT-object will the given (partial) LOV EA.
+ *
+ * Under some data corruption cases, the MDT-object of the file may be lost,
+ * but its OST-objects, or some of them are there. The layout LFSCK needs to
+ * re-create the MDT-object with the orphan OST-object(s) information.
+ *
+ * On the other hand, the LFSCK may has created some OST-object for repairing
+ * dangling LOV EA reference, but as the LFSCK processing, it may find that
+ * the old OST-object is there and should replace the former new created OST
+ * object. Unfortunately, some others have modified such newly created object.
+ * To keep the data (both new and old), the LFSCK will create MDT-object with
+ * new FID to reference the original OST-object.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] com      pointer to the lfsck component
+ * \param[in] ltd      pointer to target device descriptor
+ * \param[in] rec      pointer to the record for the orphan OST-object
+ * \param[in] cfid     pointer to FID for the orphan OST-object
+ * \param[in] infix    additional information, such as the FID for original
+ *                     MDT-object and the stripe offset in the LOV EA
+ * \param[in] type     the type for describing why the orphan MDT-object is
+ *                     created. The rules are as following:
+ *
+ *  type "C":          Multiple OST-objects claim the same MDT-object and the
+ *                     same slot in the layout EA. Then the LFSCK will create
+ *                     new MDT-object(s) to hold the conflict OST-object(s).
+ *
+ *  type "N":          The orphan OST-object does not know which one was the
+ *                     real parent MDT-object, so the LFSCK uses new FID for
+ *                     its parent MDT-object.
+ *
+ *  type "R":          The orphan OST-object knows its parent MDT-object FID,
+ *                     but does not know the position (the file name) in the
+ *                     namespace.
+ *
+ * The orphan name will be like:
+ * ${FID}-${infix}-${type}-${conflict_version}
+ *
+ * \param[in] ea_off   the stripe offset in the LOV EA
+ *
+ * \retval             positive on repaired something
+ * \retval             if needs to repair nothing
+ * \retval             negative error number on failure
  */
 static int lfsck_layout_recreate_parent(const struct lu_env *env,
                                        struct lfsck_component *com,
                                        struct lfsck_tgt_desc *ltd,
                                        struct lu_orphan_rec *rec,
                                        struct lu_fid *cfid,
-                                       const char *prefix,
-                                       const char *postfix,
+                                       const char *infix,
+                                       const char *type,
                                        __u32 ea_off)
 {
        struct lfsck_thread_info        *info   = lfsck_env_info(env);
@@ -1902,54 +2004,30 @@ static int lfsck_layout_recreate_parent(const struct lu_env *env,
                        RETURN(PTR_ERR(cobj));
        }
 
-       CDEBUG(D_LFSCK, "Re-create the lost MDT-object: parent "
-              DFID", child "DFID", OST-index %u, stripe-index %u, "
-              "prefix %s, postfix %s\n",
-              PFID(pfid), PFID(cfid), ltd->ltd_index, ea_off, prefix, postfix);
+       CDEBUG(D_LFSCK, "Re-create the lost MDT-object: parent "DFID", child "
+              DFID", OST-index %u, stripe-index %u, infix %s, type %s\n",
+              PFID(pfid), PFID(cfid), ltd->ltd_index, ea_off, infix, type);
 
        pobj = lfsck_object_find_by_dev(env, lfsck->li_bottom, pfid);
        if (IS_ERR(pobj))
                GOTO(put, rc = PTR_ERR(pobj));
 
-       LASSERT(prefix != NULL);
-       LASSERT(postfix != NULL);
+       LASSERT(infix != NULL);
+       LASSERT(type != NULL);
 
-       /** name rules:
-        *
-        *  1. Use the MDT-object's FID as the name with prefix and postfix.
-        *
-        *  1.1 prefix "C-":    More than one OST-objects claim the same
-        *                      MDT-object and the same slot in the layout EA.
-        *                      It may be created for dangling referenced MDT
-        *                      object or may be not.
-        *  1.2 prefix "N-":    The orphan OST-object does not know which one
-        *                      is the real parent, so the LFSCK assign a new
-        *                      FID as its parent.
-        *  1.3 prefix "R-":    The orphan OST-object know its parent FID but
-        *                      does not know the position in the namespace.
-        *
-        *  2. If there is name conflict, append more index for new name. */
-       sprintf(name, "%s"DFID"%s", prefix, PFID(pfid), postfix);
        do {
+               snprintf(name, NAME_MAX, DFID"%s-%s-%d", PFID(pfid), infix,
+                        type, idx++);
                rc = dt_lookup(env, lfsck->li_lpf_obj, (struct dt_rec *)tfid,
                               (const struct dt_key *)name, BYPASS_CAPA);
                if (rc != 0 && rc != -ENOENT)
                        GOTO(put, rc);
-
-               if (unlikely(rc == 0)) {
-                       CWARN("%s: The name %s under lost+found has been used "
-                             "by the "DFID". Try to increase the FID version "
-                             "for the new file name.\n",
-                             lfsck_lfsck2name(lfsck), name, PFID(tfid));
-                       sprintf(name, "%s"DFID"%s-%d", prefix, PFID(pfid),
-                               postfix, ++idx);
-               }
        } while (rc == 0);
 
        memset(la, 0, sizeof(*la));
        la->la_uid = rec->lor_uid;
        la->la_gid = rec->lor_gid;
-       la->la_mode = S_IFREG | S_IRUSR | S_IWUSR;
+       la->la_mode = S_IFREG | S_IRUSR;
        la->la_valid = LA_MODE | LA_UID | LA_GID;
 
        memset(dof, 0, sizeof(*dof));
@@ -2025,9 +2103,9 @@ static int lfsck_layout_recreate_parent(const struct lu_env *env,
        rc = dt_create(env, pobj, la, NULL, dof, th);
        if (rc == 0)
                /* 3b. Add layout EA for the MDT-object. */
-               rc = lfsck_layout_extend_lovea(env, th, pobj, cfid, ea_buf,
-                                              LU_XATTR_CREATE, ltd->ltd_index,
-                                              ea_off, false);
+               rc = lfsck_layout_extend_lovea(env, lfsck, th, pobj, cfid,
+                                              ea_buf, LU_XATTR_CREATE,
+                                              ltd->ltd_index, ea_off, false);
        dt_write_unlock(env, pobj);
        if (rc < 0)
                GOTO(stop, rc);
@@ -2237,7 +2315,7 @@ static int lfsck_layout_conflict_create(const struct lu_env *env,
        struct lfsck_thread_info *info          = lfsck_env_info(env);
        struct lu_fid            *cfid2         = &info->lti_fid2;
        struct ost_id            *oi            = &info->lti_oi;
-       char                     *postfix       = info->lti_tmpbuf;
+       char                     *infix         = info->lti_tmpbuf;
        struct lov_mds_md_v1     *lmm           = ea_buf->lb_buf;
        struct dt_device         *dev           = com->lc_lfsck->li_bottom;
        struct thandle           *th            = NULL;
@@ -2273,10 +2351,10 @@ static int lfsck_layout_conflict_create(const struct lu_env *env,
                ea_buf->lb_len = ori_len;
 
                fid_zero(&rec->lor_fid);
-               snprintf(postfix, LFSCK_TMPBUF_LEN, "-"DFID"-%x",
+               snprintf(infix, LFSCK_TMPBUF_LEN, "-"DFID"-%x",
                         PFID(lu_object_fid(&parent->do_lu)), ea_off);
                rc = lfsck_layout_recreate_parent(env, com, ltd, rec, cfid,
-                                                 "C-", postfix, ea_off);
+                                                 infix, "C", ea_off);
 
                RETURN(rc);
        }
@@ -2426,8 +2504,8 @@ again:
                LASSERT(buf->lb_len >= rc);
 
                buf->lb_len = rc;
-               rc = lfsck_layout_extend_lovea(env, handle, parent, cfid, buf,
-                                              fl, ost_idx, ea_off, false);
+               rc = lfsck_layout_extend_lovea(env, lfsck, handle, parent, cfid,
+                                              buf, fl, ost_idx, ea_off, false);
 
                GOTO(unlock_parent, rc);
        }
@@ -2444,8 +2522,8 @@ again:
 
                buf->lb_len = rc;
                memset(lmm, 0, buf->lb_len);
-               rc = lfsck_layout_extend_lovea(env, handle, parent, cfid, buf,
-                                              fl, ost_idx, ea_off, true);
+               rc = lfsck_layout_extend_lovea(env, lfsck, handle, parent, cfid,
+                                              buf, fl, ost_idx, ea_off, true);
 
                GOTO(unlock_parent, rc);
        }
@@ -2460,7 +2538,7 @@ again:
         * be updated also. */
        magic = le32_to_cpu(lmm->lmm_magic);
        if (magic == LOV_MAGIC_V1) {
-               objs = &(lmm->lmm_objects[0]);
+               objs = &lmm->lmm_objects[0];
        } else {
                LASSERT(magic == LOV_MAGIC_V3);
                objs = &((struct lov_mds_md_v3 *)lmm)->lmm_objects[0];
@@ -2482,8 +2560,9 @@ again:
                        goto again;
 
                buf->lb_len = rc;
-               rc = lfsck_layout_extend_lovea(env, handle, parent, cfid, buf,
-                                              fl, ost_idx, ea_off, false);
+               rc = lfsck_layout_extend_lovea(env, lfsck, handle, parent, cfid,
+                                              buf, fl, ost_idx, ea_off, false);
+
                GOTO(unlock_parent, rc);
        }
 
@@ -2493,7 +2572,7 @@ again:
        for (i = 0; i < count; i++, objs++) {
                /* The MDT-object was created via lfsck_layout_recover_create()
                 * by others before, and we fill the dummy layout EA. */
-               if (is_dummy_lov_ost_data(objs)) {
+               if (lovea_slot_is_dummy(objs)) {
                        if (i != ea_off)
                                continue;
 
@@ -2545,7 +2624,7 @@ again:
                dt_trans_stop(env, dt, handle);
        lfsck_layout_unlock(&lh);
        if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_V1)
-               objs = &(lmm->lmm_objects[ea_off]);
+               objs = &lmm->lmm_objects[ea_off];
        else
                objs = &((struct lov_mds_md_v3 *)lmm)->lmm_objects[ea_off];
        rc = lfsck_layout_conflict_create(env, com, ltd, rec, parent, cfid,
@@ -2586,7 +2665,7 @@ static int lfsck_layout_scan_orphan_one(const struct lu_env *env,
 
        if (fid_is_zero(pfid)) {
                rc = lfsck_layout_recreate_parent(env, com, ltd, rec, cfid,
-                                                 "N-", "", ea_off);
+                                                 "", "N", ea_off);
                GOTO(out, rc);
        }
 
@@ -2604,7 +2683,7 @@ static int lfsck_layout_scan_orphan_one(const struct lu_env *env,
        if (dt_object_exists(parent) == 0) {
                lu_object_put(env, &parent->do_lu);
                rc = lfsck_layout_recreate_parent(env, com, ltd, rec, cfid,
-                                                 "R-", "", ea_off);
+                                                 "", "R", ea_off);
                GOTO(out, rc);
        }
 
@@ -3025,7 +3104,7 @@ static int lfsck_layout_repair_multiple_references(const struct lu_env *env,
         * be updated also. */
        magic = le32_to_cpu(lmm->lmm_magic);
        if (magic == LOV_MAGIC_V1) {
-               objs = &(lmm->lmm_objects[0]);
+               objs = &lmm->lmm_objects[0];
        } else {
                LASSERT(magic == LOV_MAGIC_V3);
                objs = &((struct lov_mds_md_v3 *)lmm)->lmm_objects[0];
@@ -3199,7 +3278,7 @@ static int lfsck_layout_check_parent(const struct lu_env *env,
        lmm = buf->lb_buf;
        magic = le32_to_cpu(lmm->lmm_magic);
        if (magic == LOV_MAGIC_V1) {
-               objs = &(lmm->lmm_objects[0]);
+               objs = &lmm->lmm_objects[0];
        } else {
                LASSERT(magic == LOV_MAGIC_V3);
                objs = &((struct lov_mds_md_v3 *)lmm)->lmm_objects[0];
@@ -3210,7 +3289,7 @@ static int lfsck_layout_check_parent(const struct lu_env *env,
                struct lu_fid           *tfid   = &info->lti_fid2;
                struct ost_id           *oi     = &info->lti_oi;
 
-               if (is_dummy_lov_ost_data(objs))
+               if (lovea_slot_is_dummy(objs))
                        continue;
 
                ostid_le_to_cpu(&objs->l_ost_oi, oi);
@@ -3497,6 +3576,9 @@ static int lfsck_layout_assistant(void *args)
                                com->lc_time_last_checkpoint +
                                cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
 
+                       /* flush all async updating before handling orphan. */
+                       dt_sync(env, lfsck->li_next);
+
                        while (llmd->llmd_in_double_scan) {
                                struct lfsck_tgt_descs  *ltds =
                                                        &lfsck->li_ost_descs;
@@ -3934,7 +4016,7 @@ static int lfsck_layout_master_check_pairs(const struct lu_env *env,
         * be updated also. */
        magic = le32_to_cpu(lmm->lmm_magic);
        if (magic == LOV_MAGIC_V1) {
-               objs = &(lmm->lmm_objects[0]);
+               objs = &lmm->lmm_objects[0];
        } else {
                LASSERT(magic == LOV_MAGIC_V3);
                objs = &((struct lov_mds_md_v3 *)lmm)->lmm_objects[0];
@@ -4389,7 +4471,7 @@ static int lfsck_layout_scan_stripes(const struct lu_env *env,
         * be updated also. */
        magic = le32_to_cpu(lmm->lmm_magic);
        if (magic == LOV_MAGIC_V1) {
-               objs = &(lmm->lmm_objects[0]);
+               objs = &lmm->lmm_objects[0];
        } else {
                LASSERT(magic == LOV_MAGIC_V3);
                objs = &((struct lov_mds_md_v3 *)lmm)->lmm_objects[0];
@@ -4405,7 +4487,7 @@ static int lfsck_layout_scan_stripes(const struct lu_env *env,
                                        le32_to_cpu(objs->l_ost_idx);
                bool                     wakeup = false;
 
-               if (is_dummy_lov_ost_data(objs))
+               if (unlikely(lovea_slot_is_dummy(objs)))
                        continue;
 
                l_wait_event(mthread->t_ctl_waitq,
@@ -4654,6 +4736,17 @@ static int lfsck_layout_slave_exec_oit(const struct lu_env *env,
 
        LASSERT(llsd != NULL);
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DELAY5) &&
+           cfs_fail_val == lfsck_dev_idx(lfsck->li_bottom)) {
+               struct l_wait_info       lwi = LWI_TIMEOUT(cfs_time_seconds(1),
+                                                          NULL, NULL);
+               struct ptlrpc_thread    *thread = &lfsck->li_thread;
+
+               l_wait_event(thread->t_ctl_waitq,
+                            !thread_is_running(thread),
+                            &lwi);
+       }
+
        lfsck_rbtree_update_bitmap(env, com, fid, false);
 
        down_write(&com->lc_sem);
@@ -4873,69 +4966,53 @@ static int lfsck_layout_slave_post(const struct lu_env *env,
 }
 
 static int lfsck_layout_dump(const struct lu_env *env,
-                            struct lfsck_component *com, char *buf, int len)
+                            struct lfsck_component *com, struct seq_file *m)
 {
        struct lfsck_instance   *lfsck = com->lc_lfsck;
        struct lfsck_bookmark   *bk    = &lfsck->li_bookmark_ram;
        struct lfsck_layout     *lo    = com->lc_file_ram;
-       int                      save  = len;
-       int                      ret   = -ENOSPC;
        int                      rc;
 
        down_read(&com->lc_sem);
-       rc = snprintf(buf, len,
-                     "name: lfsck_layout\n"
+       seq_printf(m, "name: lfsck_layout\n"
                      "magic: %#x\n"
                      "version: %d\n"
                      "status: %s\n",
                      lo->ll_magic,
                      bk->lb_version,
                      lfsck_status2names(lo->ll_status));
-       if (rc <= 0)
-               goto out;
 
-       buf += rc;
-       len -= rc;
-       rc = lfsck_bits_dump(&buf, &len, lo->ll_flags, lfsck_flags_names,
-                            "flags");
+       rc = lfsck_bits_dump(m, lo->ll_flags, lfsck_flags_names, "flags");
        if (rc < 0)
                goto out;
 
-       rc = lfsck_bits_dump(&buf, &len, bk->lb_param, lfsck_param_names,
-                            "param");
+       rc = lfsck_bits_dump(m, bk->lb_param, lfsck_param_names, "param");
        if (rc < 0)
                goto out;
 
-       rc = lfsck_time_dump(&buf, &len, lo->ll_time_last_complete,
+       rc = lfsck_time_dump(m, lo->ll_time_last_complete,
                             "time_since_last_completed");
        if (rc < 0)
                goto out;
 
-       rc = lfsck_time_dump(&buf, &len, lo->ll_time_latest_start,
+       rc = lfsck_time_dump(m, lo->ll_time_latest_start,
                             "time_since_latest_start");
        if (rc < 0)
                goto out;
 
-       rc = lfsck_time_dump(&buf, &len, lo->ll_time_last_checkpoint,
+       rc = lfsck_time_dump(m, lo->ll_time_last_checkpoint,
                             "time_since_last_checkpoint");
        if (rc < 0)
                goto out;
 
-       rc = snprintf(buf, len,
-                     "latest_start_position: "LPU64"\n"
+       seq_printf(m, "latest_start_position: "LPU64"\n"
                      "last_checkpoint_position: "LPU64"\n"
                      "first_failure_position: "LPU64"\n",
                      lo->ll_pos_latest_start,
                      lo->ll_pos_last_checkpoint,
                      lo->ll_pos_first_inconsistent);
-       if (rc <= 0)
-               goto out;
-
-       buf += rc;
-       len -= rc;
 
-       rc = snprintf(buf, len,
-                     "success_count: %u\n"
+       seq_printf(m, "success_count: %u\n"
                      "repaired_dangling: "LPU64"\n"
                      "repaired_unmatched_pair: "LPU64"\n"
                      "repaired_multiple_referenced: "LPU64"\n"
@@ -4955,11 +5032,6 @@ static int lfsck_layout_dump(const struct lu_env *env,
                      lo->ll_objs_skipped,
                      lo->ll_objs_failed_phase1,
                      lo->ll_objs_failed_phase2);
-       if (rc <= 0)
-               goto out;
-
-       buf += rc;
-       len -= rc;
 
        if (lo->ll_status == LS_SCANNING_PHASE1) {
                __u64 pos;
@@ -4977,8 +5049,7 @@ static int lfsck_layout_dump(const struct lu_env *env,
                        do_div(new_checked, duration);
                if (rtime != 0)
                        do_div(speed, rtime);
-               rc = snprintf(buf, len,
-                             "checked_phase1: "LPU64"\n"
+               seq_printf(m, "checked_phase1: "LPU64"\n"
                              "checked_phase2: "LPU64"\n"
                              "run_time_phase1: %u seconds\n"
                              "run_time_phase2: %u seconds\n"
@@ -4992,11 +5063,6 @@ static int lfsck_layout_dump(const struct lu_env *env,
                              lo->ll_run_time_phase2,
                              speed,
                              new_checked);
-               if (rc <= 0)
-                       goto out;
-
-               buf += rc;
-               len -= rc;
 
                LASSERT(lfsck->li_di_oit != NULL);
 
@@ -5009,12 +5075,8 @@ static int lfsck_layout_dump(const struct lu_env *env,
                pos = iops->store(env, lfsck->li_di_oit);
                if (!lfsck->li_current_oit_processed)
                        pos--;
-               rc = snprintf(buf, len, "current_position: "LPU64"\n", pos);
-               if (rc <= 0)
-                       goto out;
+               seq_printf(m, "current_position: "LPU64"\n", pos);
 
-               buf += rc;
-               len -= rc;
        } else if (lo->ll_status == LS_SCANNING_PHASE2) {
                cfs_duration_t duration = cfs_time_current() -
                                          lfsck->li_time_last_checkpoint;
@@ -5032,29 +5094,26 @@ static int lfsck_layout_dump(const struct lu_env *env,
                        do_div(speed1, lo->ll_run_time_phase1);
                if (rtime != 0)
                        do_div(speed2, rtime);
-               rc = snprintf(buf, len,
-                             "checked_phase1: "LPU64"\n"
-                             "checked_phase2: "LPU64"\n"
-                             "run_time_phase1: %u seconds\n"
-                             "run_time_phase2: %u seconds\n"
-                             "average_speed_phase1: "LPU64" items/sec\n"
-                             "average_speed_phase2: "LPU64" items/sec\n"
-                             "real-time_speed_phase1: N/A\n"
-                             "real-time_speed_phase2: "LPU64" items/sec\n"
-                             "current_position: "DFID"\n",
-                             lo->ll_objs_checked_phase1,
-                             checked,
-                             lo->ll_run_time_phase1,
-                             rtime,
-                             speed1,
-                             speed2,
-                             new_checked,
-                             PFID(&com->lc_fid_latest_scanned_phase2));
+               rc = seq_printf(m, "checked_phase1: "LPU64"\n"
+                               "checked_phase2: "LPU64"\n"
+                               "run_time_phase1: %u seconds\n"
+                               "run_time_phase2: %u seconds\n"
+                               "average_speed_phase1: "LPU64" items/sec\n"
+                               "average_speed_phase2: "LPU64" items/sec\n"
+                               "real-time_speed_phase1: N/A\n"
+                               "real-time_speed_phase2: "LPU64" items/sec\n"
+                               "current_position: "DFID"\n",
+                               lo->ll_objs_checked_phase1,
+                               checked,
+                               lo->ll_run_time_phase1,
+                               rtime,
+                               speed1,
+                               speed2,
+                               new_checked,
+                               PFID(&com->lc_fid_latest_scanned_phase2));
                if (rc <= 0)
                        goto out;
 
-               buf += rc;
-               len -= rc;
        } else {
                __u64 speed1 = lo->ll_objs_checked_phase1;
                __u64 speed2 = lo->ll_objs_checked_phase2;
@@ -5063,34 +5122,26 @@ static int lfsck_layout_dump(const struct lu_env *env,
                        do_div(speed1, lo->ll_run_time_phase1);
                if (lo->ll_run_time_phase2 != 0)
                        do_div(speed2, lo->ll_run_time_phase2);
-               rc = snprintf(buf, len,
-                             "checked_phase1: "LPU64"\n"
-                             "checked_phase2: "LPU64"\n"
-                             "run_time_phase1: %u seconds\n"
-                             "run_time_phase2: %u seconds\n"
-                             "average_speed_phase1: "LPU64" items/sec\n"
-                             "average_speed_phase2: "LPU64" objs/sec\n"
-                             "real-time_speed_phase1: N/A\n"
-                             "real-time_speed_phase2: N/A\n"
-                             "current_position: N/A\n",
-                             lo->ll_objs_checked_phase1,
-                             lo->ll_objs_checked_phase2,
-                             lo->ll_run_time_phase1,
-                             lo->ll_run_time_phase2,
-                             speed1,
-                             speed2);
-               if (rc <= 0)
-                       goto out;
-
-               buf += rc;
-               len -= rc;
+               seq_printf(m, "checked_phase1: "LPU64"\n"
+                          "checked_phase2: "LPU64"\n"
+                          "run_time_phase1: %u seconds\n"
+                          "run_time_phase2: %u seconds\n"
+                          "average_speed_phase1: "LPU64" items/sec\n"
+                          "average_speed_phase2: "LPU64" objs/sec\n"
+                          "real-time_speed_phase1: N/A\n"
+                          "real-time_speed_phase2: N/A\n"
+                          "current_position: N/A\n",
+                          lo->ll_objs_checked_phase1,
+                          lo->ll_objs_checked_phase2,
+                          lo->ll_run_time_phase1,
+                          lo->ll_run_time_phase2,
+                          speed1,
+                          speed2);
        }
-       ret = save - len;
-
 out:
        up_read(&com->lc_sem);
 
-       return ret;
+       return rc;
 }
 
 static int lfsck_layout_master_double_scan(const struct lu_env *env,
@@ -5212,6 +5263,10 @@ static void lfsck_layout_master_data_release(const struct lu_env *env,
                                 ltd_layout_list) {
                list_del_init(&ltd->ltd_layout_list);
        }
+       spin_unlock(&ltds->ltd_lock);
+
+       ltds = &lfsck->li_mdt_descs;
+       spin_lock(&ltds->ltd_lock);
        list_for_each_entry_safe(ltd, next, &llmd->llmd_mdt_phase1_list,
                                 ltd_layout_phase_list) {
                list_del_init(&ltd->ltd_layout_phase_list);