+static int lfsck_layout_ins_dangling_rec(const struct lu_env *env,
+ struct lfsck_component *com,
+ const struct lu_fid *pfid,
+ const struct lu_fid *cfid,
+ __u32 ea_off, __u32 ost_idx)
+{
+ struct lu_fid *key = &lfsck_env_info(env)->lti_fid3;
+ struct lu_fid *rec = &lfsck_env_info(env)->lti_fid4;
+ struct dt_device *dev;
+ struct dt_object *obj;
+ struct thandle *th = NULL;
+ int idx;
+ int rc = 0;
+ ENTRY;
+
+ idx = lfsck_sub_trace_file_fid2idx(pfid);
+ obj = com->lc_sub_trace_objs[idx].lsto_obj;
+ dev = lfsck_obj2dev(obj);
+ fid_cpu_to_be(key, pfid);
+ key->f_ver = cpu_to_be32(ea_off);
+ fid_cpu_to_be(rec, cfid);
+ rec->f_ver = cpu_to_be32(ost_idx);
+
+ mutex_lock(&com->lc_sub_trace_objs[idx].lsto_mutex);
+
+ th = dt_trans_create(env, dev);
+ if (IS_ERR(th))
+ GOTO(unlock, rc = PTR_ERR(th));
+
+ rc = dt_declare_insert(env, obj,
+ (const struct dt_rec *)rec,
+ (const struct dt_key *)key, th);
+ if (rc)
+ GOTO(unlock, rc);
+
+ rc = dt_trans_start_local(env, dev, th);
+ if (rc)
+ GOTO(unlock, rc);
+
+ rc = dt_insert(env, obj, (const struct dt_rec *)rec,
+ (const struct dt_key *)key, th, 1);
+
+ GOTO(unlock, rc);
+
+unlock:
+ if (th != NULL && !IS_ERR(th))
+ dt_trans_stop(env, dev, th);
+
+ mutex_unlock(&com->lc_sub_trace_objs[idx].lsto_mutex);
+
+ CDEBUG(D_LFSCK, "%s: insert the paris "DFID" => "DFID", ea_off = %u, "
+ "ost_idx = %u, into the trace file for further dangling check: "
+ "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck),
+ PFID(pfid), PFID(cfid), ea_off, ost_idx, rc);
+
+ return rc;
+}
+
+static int lfsck_layout_del_dangling_rec(const struct lu_env *env,
+ struct lfsck_component *com,
+ const struct lu_fid *fid,
+ __u32 ea_off)
+{
+ struct lu_fid *key = &lfsck_env_info(env)->lti_fid3;
+ struct dt_device *dev;
+ struct dt_object *obj;
+ struct thandle *th = NULL;
+ int idx;
+ int rc = 0;
+ ENTRY;
+
+ idx = lfsck_sub_trace_file_fid2idx(fid);
+ obj = com->lc_sub_trace_objs[idx].lsto_obj;
+ dev = lfsck_obj2dev(obj);
+ fid_cpu_to_be(key, fid);
+ key->f_ver = cpu_to_be32(ea_off);
+
+ mutex_lock(&com->lc_sub_trace_objs[idx].lsto_mutex);
+
+ th = dt_trans_create(env, dev);
+ if (IS_ERR(th))
+ GOTO(unlock, rc = PTR_ERR(th));
+
+ rc = dt_declare_delete(env, obj, (const struct dt_key *)key, th);
+ if (rc)
+ GOTO(unlock, rc);
+
+ rc = dt_trans_start_local(env, dev, th);
+ if (rc)
+ GOTO(unlock, rc);
+
+ rc = dt_delete(env, obj, (const struct dt_key *)key, th);
+
+ GOTO(unlock, rc);
+
+unlock:
+ if (th != NULL && !IS_ERR(th))
+ dt_trans_stop(env, dev, th);
+
+ mutex_unlock(&com->lc_sub_trace_objs[idx].lsto_mutex);
+
+ CDEBUG(D_LFSCK, "%s: delete the dangling record for "DFID
+ ", ea_off = %u from the trace file: rc = %d\n",
+ lfsck_lfsck2name(com->lc_lfsck), PFID(fid), ea_off, rc);
+
+ return rc;
+}
+