Whamcloud - gitweb
LU-1267 lfsck: enhance RPCs (1) for MDT-OST consistency
[fs/lustre-release.git] / lustre / lfsck / lfsck_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License version 2 for more details.  A copy is
14  * included in the COPYING file that accompanied this code.
15
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2013, Intel Corporation.
24  */
25 /*
26  * lustre/lfsck/lfsck_internal.h
27  *
28  * Shared definitions and declarations for the LFSCK.
29  *
30  * Author: Fan, Yong <fan.yong@intel.com>
31  */
32
33 #ifndef _LFSCK_INTERNAL_H
34 # define _LFSCK_INTERNAL_H
35
36 #include <lustre/lustre_lfsck_user.h>
37 #include <lustre/lustre_user.h>
38 #include <lustre/lustre_idl.h>
39 #include <lustre_lfsck.h>
40 #include <obd.h>
41 #include <lu_object.h>
42 #include <dt_object.h>
43 #include <md_object.h>
44 #include <lustre_net.h>
45 #include <lustre_dlm.h>
46 #include <lustre_fid.h>
47 #include <md_object.h>
48
49 #define HALF_SEC                        (HZ >> 1)
50 #define LFSCK_CHECKPOINT_INTERVAL       60
51
52 #define LFSCK_NAMEENTRY_DEAD            1 /* The object has been unlinked. */
53 #define LFSCK_NAMEENTRY_REMOVED         2 /* The entry has been removed. */
54 #define LFSCK_NAMEENTRY_RECREATED       3 /* The entry has been recreated. */
55
56 enum lfsck_flags {
57         /* Finish the first cycle scanning. */
58         LF_SCANNED_ONCE         = 0x00000001ULL,
59
60         /* There is some namespace inconsistency. */
61         LF_INCONSISTENT         = 0x00000002ULL,
62
63         /* The device is upgraded from 1.8 format. */
64         LF_UPGRADE              = 0x00000004ULL,
65
66         /* The server ever restarted during the LFSCK, and may miss to process
67          * some objects check/repair. */
68         LF_INCOMPLETE           = 0x00000008ULL,
69
70         /* The LAST_ID (file) crashed. */
71         LF_CRASHED_LASTID       = 0x00000010ULL,
72 };
73
74 struct lfsck_position {
75         /* low layer object table-based iteration position. */
76         __u64   lp_oit_cookie;
77
78         /* parent FID for directory traversal. */
79         struct lu_fid lp_dir_parent;
80
81         /* namespace-based directory traversal position. */
82         __u64   lp_dir_cookie;
83 };
84
85 struct lfsck_bookmark {
86         /* Magic number to detect that this struct contains valid data. */
87         __u32   lb_magic;
88
89         /* For compatible with old versions. */
90         __u16   lb_version;
91
92         /* See 'enum lfsck_param_flags' */
93         __u16   lb_param;
94
95         /* How many items can be scanned at most per second. */
96         __u32   lb_speed_limit;
97
98         /* The windows size for async requests pipeline. */
99         __u16   lb_async_windows;
100
101         /* For 64-bits aligned. */
102         __u16   lb_padding;
103
104         /* For future using. */
105         __u64   lb_reserved[6];
106 };
107
108 struct lfsck_namespace {
109         /* Magic number to detect that this struct contains valid data. */
110         __u32   ln_magic;
111
112         /* See 'enum lfsck_status'. */
113         __u32   ln_status;
114
115         /* See 'enum lfsck_flags'. */
116         __u32   ln_flags;
117
118         /* How many completed LFSCK runs on the device. */
119         __u32   ln_success_count;
120
121         /*  How long the LFSCK phase1 has run in seconds. */
122         __u32   ln_run_time_phase1;
123
124         /*  How long the LFSCK phase2 has run in seconds. */
125         __u32   ln_run_time_phase2;
126
127         /* Time for the last LFSCK completed in seconds since epoch. */
128         __u64   ln_time_last_complete;
129
130         /* Time for the latest LFSCK ran in seconds since epoch. */
131         __u64   ln_time_latest_start;
132
133         /* Time for the last LFSCK checkpoint in seconds since epoch. */
134         __u64   ln_time_last_checkpoint;
135
136         /* Position for the latest LFSCK started from. */
137         struct lfsck_position   ln_pos_latest_start;
138
139         /* Position for the last LFSCK checkpoint. */
140         struct lfsck_position   ln_pos_last_checkpoint;
141
142         /* Position for the first should be updated object. */
143         struct lfsck_position   ln_pos_first_inconsistent;
144
145         /* How many items (including dir) have been checked. */
146         __u64   ln_items_checked;
147
148         /* How many items have been repaired. */
149         __u64   ln_items_repaired;
150
151         /* How many items failed to be processed. */
152         __u64   ln_items_failed;
153
154         /* How many directories have been traversed. */
155         __u64   ln_dirs_checked;
156
157         /* How many multiple-linked objects have been checked. */
158         __u64   ln_mlinked_checked;
159
160         /* How many objects have been double scanned. */
161         __u64   ln_objs_checked_phase2;
162
163         /* How many objects have been reparied during double scan. */
164         __u64   ln_objs_repaired_phase2;
165
166         /* How many objects failed to be processed during double scan. */
167         __u64   ln_objs_failed_phase2;
168
169         /* How many objects with nlink fixed. */
170         __u64   ln_objs_nlink_repaired;
171
172         /* How many objects were lost before, but found back now. */
173         __u64   ln_objs_lost_found;
174
175         /* The latest object has been processed (failed) during double scan. */
176         struct lu_fid   ln_fid_latest_scanned_phase2;
177
178         /* For further using. 256-bytes aligned now. */
179         __u64   ln_reserved[2];
180 };
181
182 enum lfsck_layout_inconsistency_type {
183         LLIT_NONE                       = 0,
184         LLIT_DANGLING                   = 1,
185         LLIT_UNMATCHED_PAIR             = 2,
186         LLIT_MULTIPLE_REFERENCED        = 3,
187         LLIT_ORPHAN                     = 4,
188         LLIT_INCONSISTENT_OWNER         = 5,
189         LLIT_OTHERS                     = 6,
190         LLIT_MAX                        = LLIT_OTHERS
191 };
192
193 struct lfsck_layout {
194         /* Magic number to detect that this struct contains valid data. */
195         __u32   ll_magic;
196
197         /* See 'enum lfsck_status'. */
198         __u32   ll_status;
199
200         /* See 'enum lfsck_flags'. */
201         __u32   ll_flags;
202
203         /* How many completed LFSCK runs on the device. */
204         __u32   ll_success_count;
205
206         /*  How long the LFSCK phase1 has run in seconds. */
207         __u32   ll_run_time_phase1;
208
209         /*  How long the LFSCK phase2 has run in seconds. */
210         __u32   ll_run_time_phase2;
211
212         /* Time for the last LFSCK completed in seconds since epoch. */
213         __u64   ll_time_last_complete;
214
215         /* Time for the latest LFSCK ran in seconds since epoch. */
216         __u64   ll_time_latest_start;
217
218         /* Time for the last LFSCK checkpoint in seconds since epoch. */
219         __u64   ll_time_last_checkpoint;
220
221         /* Position for the latest LFSCK started from. */
222         __u64   ll_pos_latest_start;
223
224         /* Position for the last LFSCK checkpoint. */
225         __u64   ll_pos_last_checkpoint;
226
227         /* Position for the first should be updated object. */
228         __u64   ll_pos_first_inconsistent;
229
230         /* How many objects have been checked. */
231         __u64   ll_objs_checked_phase1;
232
233         /* How many objects failed to be processed. */
234         __u64   ll_objs_failed_phase1;
235
236         /* How many objects have been double scanned. */
237         __u64   ll_objs_checked_phase2;
238
239         /* How many objects failed to be processed during double scan. */
240         __u64   ll_objs_failed_phase2;
241
242         /* kinds of inconsistency have been repaired.
243          * ll_objs_repaired[type - 1] is the count for the given @type. */
244         __u64   ll_objs_repaired[LLIT_MAX];
245
246         /* How many objects have been skipped because of related
247          * MDT(s)/OST(s) do not participate in the LFSCK */
248         __u64   ll_objs_skipped;
249
250         /* For further using. 256-bytes aligned now. */
251         __u64   ll_reserved[12];
252 };
253
254 struct lfsck_component;
255
256 struct lfsck_operations {
257         int (*lfsck_reset)(const struct lu_env *env,
258                            struct lfsck_component *com,
259                            bool init);
260
261         void (*lfsck_fail)(const struct lu_env *env,
262                            struct lfsck_component *com,
263                            bool new_checked);
264
265         int (*lfsck_checkpoint)(const struct lu_env *env,
266                                 struct lfsck_component *com,
267                                 bool init);
268
269         int (*lfsck_prep)(const struct lu_env *env,
270                           struct lfsck_component *com);
271
272         int (*lfsck_exec_oit)(const struct lu_env *env,
273                               struct lfsck_component *com,
274                               struct dt_object *obj);
275
276         int (*lfsck_exec_dir)(const struct lu_env *env,
277                               struct lfsck_component *com,
278                               struct dt_object *obj,
279                               struct lu_dirent *ent);
280
281         int (*lfsck_post)(const struct lu_env *env,
282                           struct lfsck_component *com,
283                           int result,
284                           bool init);
285
286         int (*lfsck_dump)(const struct lu_env *env,
287                           struct lfsck_component *com,
288                           char *buf,
289                           int len);
290
291         int (*lfsck_double_scan)(const struct lu_env *env,
292                                  struct lfsck_component *com);
293
294         void (*lfsck_data_release)(const struct lu_env *env,
295                                    struct lfsck_component *com);
296
297         void (*lfsck_quit)(const struct lu_env *env,
298                            struct lfsck_component *com);
299
300         int (*lfsck_in_notify)(const struct lu_env *env,
301                                struct lfsck_component *com,
302                                struct lfsck_request *lr);
303
304         int (*lfsck_query)(const struct lu_env *env,
305                            struct lfsck_component *com);
306 };
307
308 #define TGT_PTRS                256     /* number of pointers at 1st level */
309 #define TGT_PTRS_PER_BLOCK      256     /* number of pointers at 2nd level */
310
311 struct lfsck_tgt_desc {
312         struct list_head   ltd_orphan_list;
313         struct dt_device  *ltd_tgt;
314         struct dt_device  *ltd_key;
315         struct obd_export *ltd_exp;
316         struct list_head   ltd_layout_list;
317         atomic_t           ltd_ref;
318         __u32              ltd_index;
319 };
320
321 struct lfsck_tgt_desc_idx {
322         struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
323 };
324
325 struct lfsck_tgt_descs {
326         /* list of known TGTs */
327         struct lfsck_tgt_desc_idx       *ltd_tgts_idx[TGT_PTRS];
328
329         /* bitmap of TGTs available */
330         cfs_bitmap_t                    *ltd_tgts_bitmap;
331
332         /* for lfsck_tgt_desc::ltd_xxx_list */
333         spinlock_t                       ltd_lock;
334
335         /* for tgts table accessing and changes */
336         struct rw_semaphore              ltd_rw_sem;
337
338         /* Temporary list for orphan targets. */
339         struct list_head                 ltd_orphan;
340
341         /* number of registered TGTs */
342         int                              ltd_tgtnr;
343 };
344
345 #define LTD_TGT(ltd, index)     \
346         ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
347          ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
348
349 #define OST_TGT(lfsck, index)   LTD_TGT(&lfsck->li_ost_descs, index)
350 #define MDT_TGT(lfsck, index)   LTD_TGT(&lfsck->li_mdt_descs, index)
351
352 struct lfsck_component {
353         /* into lfsck_instance::li_list_(scan,double_scan,idle} */
354         cfs_list_t               lc_link;
355
356         /* into lfsck_instance::li_list_dir */
357         cfs_list_t               lc_link_dir;
358
359         struct rw_semaphore      lc_sem;
360         atomic_t                 lc_ref;
361
362         struct lfsck_position    lc_pos_start;
363         struct lfsck_instance   *lc_lfsck;
364         struct dt_object        *lc_obj;
365         struct lfsck_operations *lc_ops;
366         void                    *lc_file_ram;
367         void                    *lc_file_disk;
368         void                    *lc_data;
369
370         /* The time for last checkpoint, jiffies */
371         cfs_time_t               lc_time_last_checkpoint;
372
373         /* The time for next checkpoint, jiffies */
374         cfs_time_t               lc_time_next_checkpoint;
375
376         __u32                    lc_file_size;
377
378         /* How many objects have been checked since last checkpoint. */
379         __u32                    lc_new_checked;
380
381         /* How many objects have been scanned since last sleep. */
382         __u32                    lc_new_scanned;
383
384         unsigned int             lc_journal:1;
385         __u16                    lc_type;
386 };
387
388 struct lfsck_instance {
389         struct mutex              li_mutex;
390         spinlock_t                li_lock;
391
392         /* Link into the lfsck_instance_list. */
393         cfs_list_t                li_link;
394
395         /* For the components in (first) scanning via otable-based iteration. */
396         cfs_list_t                li_list_scan;
397
398         /* For the components in scanning via directory traversal. Because
399          * directory traversal cannot guarantee all the object be scanned,
400          * so the component in the li_list_dir must be in li_list_scan. */
401         cfs_list_t                li_list_dir;
402
403         /* For the components in double scanning. */
404         cfs_list_t                li_list_double_scan;
405
406         /* For the components those are not scanning now. */
407         cfs_list_t                li_list_idle;
408
409         atomic_t                  li_ref;
410         atomic_t                  li_double_scan_count;
411         struct ptlrpc_thread      li_thread;
412
413         /* The time for last checkpoint, jiffies */
414         cfs_time_t                li_time_last_checkpoint;
415
416         /* The time for next checkpoint, jiffies */
417         cfs_time_t                li_time_next_checkpoint;
418
419         lfsck_out_notify          li_out_notify;
420         void                     *li_out_notify_data;
421         struct dt_device         *li_next;
422         struct dt_device         *li_bottom;
423         struct ldlm_namespace    *li_namespace;
424         struct local_oid_storage *li_los;
425         struct lu_fid             li_local_root_fid;  /* backend root "/" */
426         struct lu_fid             li_global_root_fid; /* /ROOT */
427         struct dt_object         *li_bookmark_obj;
428         struct lfsck_bookmark     li_bookmark_ram;
429         struct lfsck_bookmark     li_bookmark_disk;
430         struct lfsck_position     li_pos_current;
431
432         /* Obj for otable-based iteration */
433         struct dt_object         *li_obj_oit;
434
435         /* Obj for directory traversal */
436         struct dt_object         *li_obj_dir;
437
438         /* It for otable-based iteration */
439         struct dt_it             *li_di_oit;
440
441         /* It for directory traversal */
442         struct dt_it             *li_di_dir;
443
444         /* Description of OST */
445         struct lfsck_tgt_descs    li_ost_descs;
446
447         /* Description of MDT */
448         struct lfsck_tgt_descs    li_mdt_descs;
449
450         /* namespace-based directory traversal position. */
451         __u64                     li_cookie_dir;
452
453         /* Arguments for low layer otable-based iteration. */
454         __u32                     li_args_oit;
455
456         /* Arugments for namespace-based directory traversal. */
457         __u32                     li_args_dir;
458
459         /* Schedule for every N objects. */
460         __u32                     li_sleep_rate;
461
462         /* Sleep N jiffies for each schedule. */
463         __u32                     li_sleep_jif;
464
465         /* How many objects have been scanned since last sleep. */
466         __u32                     li_new_scanned;
467
468         /* The status when the LFSCK stopped or paused. */
469         __u32                     li_status;
470
471         unsigned int              li_oit_over:1, /* oit is finished. */
472                                   li_drop_dryrun:1, /* Ever dryrun, not now. */
473                                   li_master:1, /* Master instance or not. */
474                                   li_current_oit_processed:1;
475 };
476
477 enum lfsck_linkea_flags {
478         /* The linkea entries does not match the object nlinks. */
479         LLF_UNMATCH_NLINKS      = 0x01,
480
481         /* Fail to repair the multiple-linked objects during the double scan. */
482         LLF_REPAIR_FAILED       = 0x02,
483 };
484
485 struct lfsck_thread_args {
486         struct lu_env            lta_env;
487         struct lfsck_instance   *lta_lfsck;
488         struct lfsck_component  *lta_com;
489 };
490
491 struct lfsck_thread_info {
492         struct lu_name          lti_name;
493         struct lu_buf           lti_buf;
494         struct lu_buf           lti_linkea_buf;
495         struct lu_fid           lti_fid;
496         struct lu_fid           lti_fid2;
497         struct lu_attr          lti_la;
498         struct ost_id           lti_oi;
499         union {
500                 struct lustre_mdt_attrs lti_lma;
501                 /* old LMA for compatibility */
502                 char                    lti_lma_old[LMA_OLD_SIZE];
503         };
504         struct dt_object_format lti_dof;
505         /* lti_ent and lti_key must be conjoint,
506          * then lti_ent::lde_name will be lti_key. */
507         struct lu_dirent        lti_ent;
508         char                    lti_key[NAME_MAX + 16];
509         struct lfsck_request    lti_lr;
510 };
511
512 /* lfsck_lib.c */
513 const char *lfsck_status2names(enum lfsck_status status);
514 void lfsck_component_cleanup(const struct lu_env *env,
515                              struct lfsck_component *com);
516 void lfsck_instance_cleanup(const struct lu_env *env,
517                             struct lfsck_instance *lfsck);
518 int lfsck_bits_dump(char **buf, int *len, int bits, const char *names[],
519                     const char *prefix);
520 int lfsck_time_dump(char **buf, int *len, __u64 time, const char *prefix);
521 int lfsck_pos_dump(char **buf, int *len, struct lfsck_position *pos,
522                    const char *prefix);
523 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
524                     struct lfsck_position *pos, bool init);
525 void lfsck_control_speed(struct lfsck_instance *lfsck);
526 void lfsck_control_speed_by_self(struct lfsck_component *com);
527 int lfsck_reset(const struct lu_env *env, struct lfsck_instance *lfsck,
528                 bool init);
529 struct lfsck_thread_args *lfsck_thread_args_init(struct lfsck_instance *lfsck,
530                                                  struct lfsck_component *com);
531 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
532 void lfsck_fail(const struct lu_env *env, struct lfsck_instance *lfsck,
533                 bool new_checked);
534 int lfsck_checkpoint(const struct lu_env *env, struct lfsck_instance *lfsck);
535 int lfsck_prep(const struct lu_env *env, struct lfsck_instance *lfsck);
536 int lfsck_exec_oit(const struct lu_env *env, struct lfsck_instance *lfsck,
537                    struct dt_object *obj);
538 int lfsck_exec_dir(const struct lu_env *env, struct lfsck_instance *lfsck,
539                    struct dt_object *obj, struct lu_dirent *ent);
540 int lfsck_post(const struct lu_env *env, struct lfsck_instance *lfsck,
541                int result);
542 int lfsck_double_scan(const struct lu_env *env, struct lfsck_instance *lfsck);
543 void lfsck_quit(const struct lu_env *env, struct lfsck_instance *lfsck);
544
545 /* lfsck_engine.c */
546 int lfsck_master_engine(void *args);
547
548 /* lfsck_bookmark.c */
549 int lfsck_bookmark_store(const struct lu_env *env,
550                          struct lfsck_instance *lfsck);
551 int lfsck_bookmark_setup(const struct lu_env *env,
552                          struct lfsck_instance *lfsck);
553
554 /* lfsck_namespace.c */
555 int lfsck_namespace_setup(const struct lu_env *env,
556                           struct lfsck_instance *lfsck);
557
558 /* lfsck_layout.c */
559 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
560
561 extern const char *lfsck_flags_names[];
562 extern const char *lfsck_param_names[];
563 extern struct lu_context_key lfsck_thread_key;
564
565 static inline struct lfsck_thread_info *
566 lfsck_env_info(const struct lu_env *env)
567 {
568         struct lfsck_thread_info *info;
569
570         info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
571         LASSERT(info != NULL);
572         return info;
573 }
574
575 static inline const struct lu_name *
576 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
577 {
578         struct lu_name *lname;
579
580         lname = &lfsck_env_info(env)->lti_name;
581         lname->ln_name = area;
582         lname->ln_namelen = len;
583         return lname;
584 }
585
586 static inline struct lu_buf *
587 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
588 {
589         struct lu_buf *buf;
590
591         buf = &lfsck_env_info(env)->lti_buf;
592         buf->lb_buf = area;
593         buf->lb_len = len;
594         return buf;
595 }
596
597 static inline const struct lu_buf *
598 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
599 {
600         struct lu_buf *buf;
601
602         buf = &lfsck_env_info(env)->lti_buf;
603         buf->lb_buf = (void *)area;
604         buf->lb_len = len;
605         return buf;
606 }
607
608 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
609 {
610         return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
611 }
612
613 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
614 {
615         return lu_object_fid(&obj->do_lu);
616 }
617
618 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
619 {
620         memset(pos, 0, sizeof(*pos));
621 }
622
623 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
624 {
625         return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
626 }
627
628 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
629                                   const struct lfsck_position *pos2)
630 {
631         if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
632                 return -1;
633
634         if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
635                 return 1;
636
637         if (fid_is_zero(&pos1->lp_dir_parent) &&
638             !fid_is_zero(&pos2->lp_dir_parent))
639                 return -1;
640
641         if (!fid_is_zero(&pos1->lp_dir_parent) &&
642             fid_is_zero(&pos2->lp_dir_parent))
643                 return 1;
644
645         if (fid_is_zero(&pos1->lp_dir_parent) &&
646             fid_is_zero(&pos2->lp_dir_parent))
647                 return 0;
648
649         LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
650
651         if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
652                 return -1;
653
654         if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
655                 return 1;
656
657         return 0;
658 }
659
660 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
661                                             struct lfsck_position *src)
662 {
663         des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
664         fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
665         des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
666 }
667
668 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
669                                             struct lfsck_position *src)
670 {
671         des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
672         fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
673         des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
674 }
675
676 static inline umode_t lfsck_object_type(const struct dt_object *obj)
677 {
678         return lu_object_attr(&obj->do_lu);
679 }
680
681 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
682 {
683         struct lu_object_header *loh = obj->do_lu.lo_header;
684
685         return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
686 }
687
688 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
689                                                   struct lfsck_instance *lfsck,
690                                                   const struct lu_fid *fid)
691 {
692         return lu2dt(lu_object_find_slice(env, dt2lu_dev(lfsck->li_next),
693                      fid, NULL));
694 }
695
696 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
697 {
698         lu_object_get(&obj->do_lu);
699         return obj;
700 }
701
702 static inline void lfsck_object_put(const struct lu_env *env,
703                                     struct dt_object *obj)
704 {
705         lu_object_put(env, &obj->do_lu);
706 }
707
708 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
709                                                    __u32 index)
710 {
711         struct lfsck_tgt_desc *ltd;
712
713         ltd = LTD_TGT(ltds, index);
714         if (ltd != NULL)
715                 atomic_inc(&ltd->ltd_ref);
716
717         return ltd;
718 }
719
720 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
721 {
722         if (atomic_dec_and_test(&ltd->ltd_ref))
723                 OBD_FREE_PTR(ltd);
724 }
725
726 static inline struct lfsck_component *
727 lfsck_component_get(struct lfsck_component *com)
728 {
729         atomic_inc(&com->lc_ref);
730
731         return com;
732 }
733
734 static inline void lfsck_component_put(const struct lu_env *env,
735                                        struct lfsck_component *com)
736 {
737         if (atomic_dec_and_test(&com->lc_ref)) {
738                 if (com->lc_obj != NULL)
739                         lu_object_put_nocache(env, &com->lc_obj->do_lu);
740                 if (com->lc_file_ram != NULL)
741                         OBD_FREE(com->lc_file_ram, com->lc_file_size);
742                 if (com->lc_file_disk != NULL)
743                         OBD_FREE(com->lc_file_disk, com->lc_file_size);
744                 if (com->lc_data != NULL) {
745                         LASSERT(com->lc_ops->lfsck_data_release != NULL);
746
747                         com->lc_ops->lfsck_data_release(env, com);
748                 }
749
750                 OBD_FREE_PTR(com);
751         }
752 }
753
754 static inline struct lfsck_instance *
755 lfsck_instance_get(struct lfsck_instance *lfsck)
756 {
757         atomic_inc(&lfsck->li_ref);
758
759         return lfsck;
760 }
761
762 static inline void lfsck_instance_put(const struct lu_env *env,
763                                       struct lfsck_instance *lfsck)
764 {
765         if (atomic_dec_and_test(&lfsck->li_ref))
766                 lfsck_instance_cleanup(env, lfsck);
767 }
768
769 static inline mdsno_t lfsck_dev_idx(struct dt_device *dev)
770 {
771         return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
772 }
773
774 #endif /* _LFSCK_INTERNAL_H */