+static inline struct dt_object *
+lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
+ const struct lu_fid *fid)
+{
+ struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
+ struct dt_object *obj;
+
+ conf->loc_flags = LOC_F_NOWAIT;
+ obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
+ if (unlikely(obj == NULL))
+ return ERR_PTR(-ENOENT);
+
+ return obj;
+}
+
+static inline struct dt_object *
+lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
+ const struct lu_fid *fid)
+{
+ struct dt_object *obj;
+
+ obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
+ if (unlikely(obj == NULL))
+ return ERR_PTR(-ENOENT);
+
+ return obj;
+}
+
+static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
+ struct lfsck_instance *lfsck,
+ const struct lu_fid *fid)
+{
+ return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
+}
+
+static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
+ __u32 index)
+{
+ struct lfsck_tgt_desc *ltd;
+
+ ltd = LTD_TGT(ltds, index);
+ if (ltd != NULL)
+ atomic_inc(<d->ltd_ref);
+
+ return ltd;
+}
+
+static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
+{
+ if (atomic_dec_and_test(<d->ltd_ref))
+ OBD_FREE_PTR(ltd);
+}
+
+static inline struct lfsck_component *
+lfsck_component_get(struct lfsck_component *com)
+{
+ atomic_inc(&com->lc_ref);
+
+ return com;
+}
+
+static inline void lfsck_component_put(const struct lu_env *env,
+ struct lfsck_component *com)
+{
+ if (atomic_dec_and_test(&com->lc_ref)) {
+ if (com->lc_obj != NULL)
+ lu_object_put_nocache(env, &com->lc_obj->do_lu);
+ if (com->lc_file_ram != NULL)
+ OBD_FREE(com->lc_file_ram, com->lc_file_size);
+ if (com->lc_file_disk != NULL)
+ OBD_FREE(com->lc_file_disk, com->lc_file_size);
+ if (com->lc_data != NULL) {
+ LASSERT(com->lc_ops->lfsck_data_release != NULL);
+
+ com->lc_ops->lfsck_data_release(env, com);
+ }
+
+ OBD_FREE_PTR(com);
+ }
+}
+
+static inline struct lfsck_instance *
+lfsck_instance_get(struct lfsck_instance *lfsck)
+{
+ atomic_inc(&lfsck->li_ref);
+
+ return lfsck;
+}
+
+static inline void lfsck_instance_put(const struct lu_env *env,
+ struct lfsck_instance *lfsck)
+{
+ if (atomic_dec_and_test(&lfsck->li_ref))
+ lfsck_instance_cleanup(env, lfsck);
+}
+
+static inline u32 lfsck_dev_idx(struct dt_device *dev)