Whamcloud - gitweb
5a801cf51cc659b193798bef10a4073fae48493e
[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 #include <lustre_linkea.h>
49
50 #define HALF_SEC                        (HZ >> 1)
51 #define LFSCK_CHECKPOINT_INTERVAL       60
52
53 enum lfsck_flags {
54         /* Finish the first cycle scanning. */
55         LF_SCANNED_ONCE         = 0x00000001ULL,
56
57         /* There is some namespace inconsistency. */
58         LF_INCONSISTENT         = 0x00000002ULL,
59
60         /* The device is upgraded from 1.8 format. */
61         LF_UPGRADE              = 0x00000004ULL,
62
63         /* The server ever restarted during the LFSCK, and may miss to process
64          * some objects check/repair. */
65         LF_INCOMPLETE           = 0x00000008ULL,
66
67         /* The LAST_ID (file) crashed. */
68         LF_CRASHED_LASTID       = 0x00000010ULL,
69 };
70
71 struct lfsck_position {
72         /* low layer object table-based iteration position. */
73         __u64   lp_oit_cookie;
74
75         /* parent FID for directory traversal. */
76         struct lu_fid lp_dir_parent;
77
78         /* namespace-based directory traversal position. */
79         __u64   lp_dir_cookie;
80 };
81
82 struct lfsck_bookmark {
83         /* Magic number to detect that this struct contains valid data. */
84         __u32   lb_magic;
85
86         /* For compatible with old versions. */
87         __u16   lb_version;
88
89         /* See 'enum lfsck_param_flags' */
90         __u16   lb_param;
91
92         /* How many items can be scanned at most per second. */
93         __u32   lb_speed_limit;
94
95         /* The windows size for async requests pipeline. */
96         __u16   lb_async_windows;
97
98         /* For 64-bits aligned. */
99         __u16   lb_padding;
100
101         /* The FID for .lustre/lost+found/MDTxxxx */
102         struct lu_fid   lb_lpf_fid;
103
104         /* The FID for the last MDT-object created by the LFSCK repairing. */
105         struct lu_fid   lb_last_fid;
106
107         /* For future using. */
108         __u64   lb_reserved[2];
109 };
110
111 struct lfsck_namespace {
112         /* Magic number to detect that this struct contains valid data. */
113         __u32   ln_magic;
114
115         /* See 'enum lfsck_status'. */
116         __u32   ln_status;
117
118         /* See 'enum lfsck_flags'. */
119         __u32   ln_flags;
120
121         /* How many completed LFSCK runs on the device. */
122         __u32   ln_success_count;
123
124         /*  How long the LFSCK phase1 has run in seconds. */
125         __u32   ln_run_time_phase1;
126
127         /*  How long the LFSCK phase2 has run in seconds. */
128         __u32   ln_run_time_phase2;
129
130         /* Time for the last LFSCK completed in seconds since epoch. */
131         __u64   ln_time_last_complete;
132
133         /* Time for the latest LFSCK ran in seconds since epoch. */
134         __u64   ln_time_latest_start;
135
136         /* Time for the last LFSCK checkpoint in seconds since epoch. */
137         __u64   ln_time_last_checkpoint;
138
139         /* Position for the latest LFSCK started from. */
140         struct lfsck_position   ln_pos_latest_start;
141
142         /* Position for the last LFSCK checkpoint. */
143         struct lfsck_position   ln_pos_last_checkpoint;
144
145         /* Position for the first should be updated object. */
146         struct lfsck_position   ln_pos_first_inconsistent;
147
148         /* How many items (including dir) have been checked. */
149         __u64   ln_items_checked;
150
151         /* How many items have been repaired. */
152         __u64   ln_items_repaired;
153
154         /* How many items failed to be processed. */
155         __u64   ln_items_failed;
156
157         /* How many directories have been traversed. */
158         __u64   ln_dirs_checked;
159
160         /* How many multiple-linked objects have been checked. */
161         __u64   ln_mlinked_checked;
162
163         /* How many objects have been double scanned. */
164         __u64   ln_objs_checked_phase2;
165
166         /* How many objects have been reparied during double scan. */
167         __u64   ln_objs_repaired_phase2;
168
169         /* How many objects failed to be processed during double scan. */
170         __u64   ln_objs_failed_phase2;
171
172         /* How many objects with nlink fixed. */
173         __u64   ln_objs_nlink_repaired;
174
175         /* How many objects were lost before, but found back now. */
176         __u64   ln_objs_lost_found;
177
178         /* The latest object has been processed (failed) during double scan. */
179         struct lu_fid   ln_fid_latest_scanned_phase2;
180
181         /* How many FID-in-dirent entries have been repaired. */
182         __u64   ln_dirent_repaired;
183
184         /* How many linkEA entries have been repaired. */
185         __u64   ln_linkea_repaired;
186 };
187
188 enum lfsck_layout_inconsistency_type {
189         LLIT_NONE                       = 0,
190         LLIT_DANGLING                   = 1,
191         LLIT_UNMATCHED_PAIR             = 2,
192         LLIT_MULTIPLE_REFERENCED        = 3,
193         LLIT_ORPHAN                     = 4,
194         LLIT_INCONSISTENT_OWNER         = 5,
195         LLIT_OTHERS                     = 6,
196         LLIT_MAX                        = LLIT_OTHERS
197 };
198
199 struct lfsck_layout {
200         /* Magic number to detect that this struct contains valid data. */
201         __u32   ll_magic;
202
203         /* See 'enum lfsck_status'. */
204         __u32   ll_status;
205
206         /* See 'enum lfsck_flags'. */
207         __u32   ll_flags;
208
209         /* How many completed LFSCK runs on the device. */
210         __u32   ll_success_count;
211
212         /*  How long the LFSCK phase1 has run in seconds. */
213         __u32   ll_run_time_phase1;
214
215         /*  How long the LFSCK phase2 has run in seconds. */
216         __u32   ll_run_time_phase2;
217
218         /* Time for the last LFSCK completed in seconds since epoch. */
219         __u64   ll_time_last_complete;
220
221         /* Time for the latest LFSCK ran in seconds since epoch. */
222         __u64   ll_time_latest_start;
223
224         /* Time for the last LFSCK checkpoint in seconds since epoch. */
225         __u64   ll_time_last_checkpoint;
226
227         /* Position for the latest LFSCK started from. */
228         __u64   ll_pos_latest_start;
229
230         /* Position for the last LFSCK checkpoint. */
231         __u64   ll_pos_last_checkpoint;
232
233         /* Position for the first object to be fixed or
234          * failed to be checked in the phase1. */
235         __u64   ll_pos_first_inconsistent;
236
237         /* How many objects have been checked. */
238         __u64   ll_objs_checked_phase1;
239
240         /* How many objects failed to be processed. */
241         __u64   ll_objs_failed_phase1;
242
243         /* How many objects have been double scanned. */
244         __u64   ll_objs_checked_phase2;
245
246         /* How many objects failed to be processed during double scan. */
247         __u64   ll_objs_failed_phase2;
248
249         /* kinds of inconsistency have been or to be repaired.
250          * ll_objs_repaired[type - 1] is the count for the given @type. */
251         __u64   ll_objs_repaired[LLIT_MAX];
252
253         /* How many objects have been skipped because of related
254          * MDT(s)/OST(s) do not participate in the LFSCK */
255         __u64   ll_objs_skipped;
256
257         /* For further using. 256-bytes aligned now. */
258         __u64   ll_reserved[12];
259 };
260
261 struct lfsck_component;
262 struct lfsck_tgt_descs;
263 struct lfsck_tgt_desc;
264
265 struct lfsck_operations {
266         int (*lfsck_reset)(const struct lu_env *env,
267                            struct lfsck_component *com,
268                            bool init);
269
270         void (*lfsck_fail)(const struct lu_env *env,
271                            struct lfsck_component *com,
272                            bool new_checked);
273
274         int (*lfsck_checkpoint)(const struct lu_env *env,
275                                 struct lfsck_component *com,
276                                 bool init);
277
278         int (*lfsck_prep)(const struct lu_env *env,
279                           struct lfsck_component *com,
280                           struct lfsck_start_param *lsp);
281
282         int (*lfsck_exec_oit)(const struct lu_env *env,
283                               struct lfsck_component *com,
284                               struct dt_object *obj);
285
286         int (*lfsck_exec_dir)(const struct lu_env *env,
287                               struct lfsck_component *com,
288                               struct lu_dirent *ent,
289                               __u16 type);
290
291         int (*lfsck_post)(const struct lu_env *env,
292                           struct lfsck_component *com,
293                           int result,
294                           bool init);
295
296         int (*lfsck_dump)(const struct lu_env *env,
297                           struct lfsck_component *com,
298                           struct seq_file *m);
299
300         int (*lfsck_double_scan)(const struct lu_env *env,
301                                  struct lfsck_component *com);
302
303         void (*lfsck_data_release)(const struct lu_env *env,
304                                    struct lfsck_component *com);
305
306         void (*lfsck_quit)(const struct lu_env *env,
307                            struct lfsck_component *com);
308
309         int (*lfsck_in_notify)(const struct lu_env *env,
310                                struct lfsck_component *com,
311                                struct lfsck_request *lr);
312
313         int (*lfsck_query)(const struct lu_env *env,
314                            struct lfsck_component *com);
315
316         int (*lfsck_join)(const struct lu_env *env,
317                           struct lfsck_component *com,
318                           struct lfsck_start_param *lsp);
319 };
320
321 #define TGT_PTRS                256     /* number of pointers at 1st level */
322 #define TGT_PTRS_PER_BLOCK      256     /* number of pointers at 2nd level */
323
324 struct lfsck_tgt_desc {
325         struct list_head   ltd_orphan_list;
326         struct dt_device  *ltd_tgt;
327         struct dt_device  *ltd_key;
328         struct obd_export *ltd_exp;
329         struct list_head   ltd_layout_list;
330         struct list_head   ltd_layout_phase_list;
331         struct list_head   ltd_namespace_list;
332         struct list_head   ltd_namespace_phase_list;
333         atomic_t           ltd_ref;
334         __u32              ltd_index;
335         __u32              ltd_layout_gen;
336         __u32              ltd_namespace_gen;
337         unsigned int       ltd_dead:1,
338                            ltd_layout_done:1,
339                            ltd_namespace_done:1;
340 };
341
342 struct lfsck_tgt_desc_idx {
343         struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
344 };
345
346 struct lfsck_tgt_descs {
347         /* list of known TGTs */
348         struct lfsck_tgt_desc_idx       *ltd_tgts_idx[TGT_PTRS];
349
350         /* bitmap of TGTs available */
351         cfs_bitmap_t                    *ltd_tgts_bitmap;
352
353         /* for lfsck_tgt_desc::ltd_xxx_list */
354         spinlock_t                       ltd_lock;
355
356         /* for tgts table accessing and changes */
357         struct rw_semaphore              ltd_rw_sem;
358
359         /* Temporary list for orphan targets. */
360         struct list_head                 ltd_orphan;
361
362         /* number of registered TGTs */
363         __u32                            ltd_tgtnr;
364 };
365
366 #define LTD_TGT(ltd, index)     \
367         ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
368          ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
369
370 #define OST_TGT(lfsck, index)   LTD_TGT(&lfsck->li_ost_descs, index)
371 #define MDT_TGT(lfsck, index)   LTD_TGT(&lfsck->li_mdt_descs, index)
372
373 struct lfsck_component {
374         /* into lfsck_instance::li_list_(scan,double_scan,idle} */
375         struct list_head         lc_link;
376
377         /* into lfsck_instance::li_list_dir */
378         struct list_head         lc_link_dir;
379
380         struct rw_semaphore      lc_sem;
381         atomic_t                 lc_ref;
382
383         struct lfsck_position    lc_pos_start;
384         struct lfsck_instance   *lc_lfsck;
385         struct dt_object        *lc_obj;
386         struct lfsck_operations *lc_ops;
387         void                    *lc_file_ram;
388         void                    *lc_file_disk;
389         void                    *lc_data;
390         struct lu_fid            lc_fid_latest_scanned_phase2;
391
392         /* The time for last checkpoint, jiffies */
393         cfs_time_t               lc_time_last_checkpoint;
394
395         /* The time for next checkpoint, jiffies */
396         cfs_time_t               lc_time_next_checkpoint;
397
398         __u32                    lc_file_size;
399
400         /* How many objects have been checked since last checkpoint. */
401         __u32                    lc_new_checked;
402
403         /* How many objects have been scanned since last sleep. */
404         __u32                    lc_new_scanned;
405
406         unsigned int             lc_journal:1;
407         __u16                    lc_type;
408 };
409
410 struct lfsck_instance {
411         struct mutex              li_mutex;
412         spinlock_t                li_lock;
413
414         /* Link into the lfsck_instance_list. */
415         struct list_head          li_link;
416
417         /* For the components in (first) scanning via otable-based iteration. */
418         struct list_head          li_list_scan;
419
420         /* For the components in scanning via directory traversal. Because
421          * directory traversal cannot guarantee all the object be scanned,
422          * so the component in the li_list_dir must be in li_list_scan. */
423         struct list_head          li_list_dir;
424
425         /* For the components in double scanning. */
426         struct list_head          li_list_double_scan;
427
428         /* For the components those are not scanning now. */
429         struct list_head          li_list_idle;
430
431         atomic_t                  li_ref;
432         atomic_t                  li_double_scan_count;
433         struct ptlrpc_thread      li_thread;
434
435         /* The time for last checkpoint, jiffies */
436         cfs_time_t                li_time_last_checkpoint;
437
438         /* The time for next checkpoint, jiffies */
439         cfs_time_t                li_time_next_checkpoint;
440
441         lfsck_out_notify          li_out_notify;
442         void                     *li_out_notify_data;
443         struct dt_device         *li_next;
444         struct dt_device         *li_bottom;
445         struct obd_device        *li_obd;
446         struct ldlm_namespace    *li_namespace;
447         struct local_oid_storage *li_los;
448         struct lu_fid             li_local_root_fid;  /* backend root "/" */
449         struct lu_fid             li_global_root_fid; /* /ROOT */
450         struct dt_object         *li_bookmark_obj;
451         struct dt_object         *li_lpf_obj;
452         struct lu_client_seq     *li_seq;
453         struct lfsck_bookmark     li_bookmark_ram;
454         struct lfsck_bookmark     li_bookmark_disk;
455         struct lfsck_position     li_pos_current;
456         struct lfsck_position     li_pos_checkpoint;
457
458         /* Obj for otable-based iteration */
459         struct dt_object         *li_obj_oit;
460
461         /* Obj for directory traversal */
462         struct dt_object         *li_obj_dir;
463
464         /* It for otable-based iteration */
465         struct dt_it             *li_di_oit;
466
467         /* It for directory traversal */
468         struct dt_it             *li_di_dir;
469
470         /* Description of OST */
471         struct lfsck_tgt_descs    li_ost_descs;
472
473         /* Description of MDT */
474         struct lfsck_tgt_descs    li_mdt_descs;
475
476         /* namespace-based directory traversal position. */
477         __u64                     li_cookie_dir;
478
479         /* Arguments for low layer otable-based iteration. */
480         __u32                     li_args_oit;
481
482         /* Arugments for namespace-based directory traversal. */
483         __u32                     li_args_dir;
484
485         /* Schedule for every N objects. */
486         __u32                     li_sleep_rate;
487
488         /* Sleep N jiffies for each schedule. */
489         __u32                     li_sleep_jif;
490
491         /* How many objects have been scanned since last sleep. */
492         __u32                     li_new_scanned;
493
494         /* The status when the LFSCK stopped or paused. */
495         __u32                     li_status;
496
497         /* The flags when the lFSCK stopped or paused. */
498         __u32                     li_flags;
499
500         unsigned int              li_oit_over:1, /* oit is finished. */
501                                   li_drop_dryrun:1, /* Ever dryrun, not now. */
502                                   li_master:1, /* Master instance or not. */
503                                   li_current_oit_processed:1,
504                                   li_start_unplug:1;
505 };
506
507 enum lfsck_linkea_flags {
508         /* The linkea entries does not match the object nlinks. */
509         LLF_UNMATCH_NLINKS      = 0x01,
510
511         /* Fail to repair the multiple-linked objects during the double scan. */
512         LLF_REPAIR_FAILED       = 0x02,
513 };
514
515 struct lfsck_async_interpret_args {
516         struct lfsck_component          *laia_com;
517         struct lfsck_tgt_descs          *laia_ltds;
518         struct lfsck_tgt_desc           *laia_ltd;
519         struct lfsck_request            *laia_lr;
520         int                              laia_result;
521         unsigned int                     laia_shared:1;
522 };
523
524 struct lfsck_thread_args {
525         struct lu_env                    lta_env;
526         struct lfsck_instance           *lta_lfsck;
527         struct lfsck_component          *lta_com;
528         struct lfsck_start_param        *lta_lsp;
529 };
530
531 struct lfsck_assistant_req {
532         struct list_head        lar_list;
533 };
534
535 struct lfsck_assistant_operations {
536         int (*la_handler_p1)(const struct lu_env *env,
537                              struct lfsck_component *com,
538                              struct lfsck_assistant_req *lar);
539
540         int (*la_handler_p2)(const struct lu_env *env,
541                              struct lfsck_component *com);
542
543         void (*la_fill_pos)(const struct lu_env *env,
544                             struct lfsck_component *com,
545                             struct lfsck_position *pos);
546
547         int (*la_double_scan_result)(const struct lu_env *env,
548                                      struct lfsck_component *com,
549                                      int rc);
550
551         void (*la_req_fini)(const struct lu_env *env,
552                             struct lfsck_assistant_req *lar);
553 };
554
555 struct lfsck_assistant_data {
556         spinlock_t                               lad_lock;
557         struct list_head                         lad_req_list;
558
559         /* list for the ost targets involve LFSCK. */
560         struct list_head                         lad_ost_list;
561
562         /* list for the ost targets in phase1 scanning. */
563         struct list_head                         lad_ost_phase1_list;
564
565         /* list for the ost targets in phase1 scanning. */
566         struct list_head                         lad_ost_phase2_list;
567
568         /* list for the mdt targets involve LFSCK. */
569         struct list_head                         lad_mdt_list;
570
571         /* list for the mdt targets in phase1 scanning. */
572         struct list_head                         lad_mdt_phase1_list;
573
574         /* list for the mdt targets in phase1 scanning. */
575         struct list_head                         lad_mdt_phase2_list;
576
577         const char                              *lad_name;
578         struct ptlrpc_thread                     lad_thread;
579
580         struct lfsck_assistant_operations       *lad_ops;
581
582         __u32                                    lad_touch_gen;
583         int                                      lad_prefetched;
584         int                                      lad_assistant_status;
585         int                                      lad_post_result;
586         unsigned int                             lad_to_post:1,
587                                                  lad_to_double_scan:1,
588                                                  lad_in_double_scan:1,
589                                                  lad_exit:1;
590 };
591
592 #define LFSCK_TMPBUF_LEN        64
593
594 struct lfsck_thread_info {
595         struct lu_name          lti_name;
596         struct lu_buf           lti_buf;
597         struct lu_buf           lti_linkea_buf;
598         struct lu_buf           lti_big_buf;
599         struct lu_fid           lti_fid;
600         struct lu_fid           lti_fid2;
601         struct lu_fid           lti_fid3;
602         struct lu_attr          lti_la;
603         struct lu_attr          lti_la2;
604         struct lu_attr          lti_la3;
605         struct ost_id           lti_oi;
606         union {
607                 struct lustre_mdt_attrs lti_lma;
608                 /* old LMA for compatibility */
609                 char                    lti_lma_old[LMA_OLD_SIZE];
610         };
611         struct dt_object_format lti_dof;
612         /* There will be '\0' at the end of the name. */
613         char            lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
614         char                    lti_tmpbuf[LFSCK_TMPBUF_LEN];
615         struct lfsck_request    lti_lr;
616         struct lfsck_async_interpret_args lti_laia;
617         struct lfsck_start      lti_start;
618         struct lfsck_stop       lti_stop;
619         ldlm_policy_data_t      lti_policy;
620         struct ldlm_res_id      lti_resid;
621         union {
622                 struct filter_fid_old   lti_old_pfid;
623                 struct filter_fid       lti_new_pfid;
624         };
625         struct dt_allocation_hint lti_hint;
626         struct lu_orphan_rec    lti_rec;
627         struct lov_user_md      lti_lum;
628         struct dt_insert_rec    lti_dt_rec;
629         struct lu_object_conf   lti_conf;
630 };
631
632 /* lfsck_lib.c */
633 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
634                     struct lu_fid *fid, bool locked);
635 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
636                      struct dt_object *obj, struct lustre_handle *lh,
637                      __u64 bits, ldlm_mode_t mode);
638 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
639 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
640 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
641 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
642                                            bool unlink);
643 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
644                                              __u16 type);
645 const char *lfsck_status2names(enum lfsck_status status);
646 void lfsck_component_cleanup(const struct lu_env *env,
647                              struct lfsck_component *com);
648 void lfsck_instance_cleanup(const struct lu_env *env,
649                             struct lfsck_instance *lfsck);
650 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
651                     const char *prefix);
652 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
653 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
654                    const char *prefix);
655 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
656                     struct lfsck_position *pos, bool init);
657 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
658 void lfsck_control_speed(struct lfsck_instance *lfsck);
659 void lfsck_control_speed_by_self(struct lfsck_component *com);
660 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
661 struct lfsck_assistant_data *
662 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
663                           const char *name);
664 int lfsck_async_interpret_common(const struct lu_env *env,
665                                  struct ptlrpc_request *req,
666                                  void *args, int rc);
667 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
668                         struct lfsck_request *lr,
669                         struct ptlrpc_request_set *set,
670                         ptlrpc_interpterer_t interpterer,
671                         void *args, int request);
672 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
673                           struct lfsck_start_param *lsp);
674 int lfsck_checkpoint_generic(const struct lu_env *env,
675                              struct lfsck_component *com);
676 void lfsck_post_generic(const struct lu_env *env,
677                         struct lfsck_component *com, int *result);
678 int lfsck_double_scan_generic(const struct lu_env *env,
679                               struct lfsck_component *com, int status);
680 void lfsck_quit_generic(const struct lu_env *env,
681                         struct lfsck_component *com);
682
683 /* lfsck_engine.c */
684 int lfsck_master_engine(void *args);
685 int lfsck_assistant_engine(void *args);
686
687 /* lfsck_bookmark.c */
688 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
689                               struct lfsck_bookmark *src);
690 int lfsck_bookmark_store(const struct lu_env *env,
691                          struct lfsck_instance *lfsck);
692 int lfsck_bookmark_setup(const struct lu_env *env,
693                          struct lfsck_instance *lfsck);
694 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
695                     struct lfsck_start *start, bool reset);
696
697 /* lfsck_namespace.c */
698 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
699                         struct dt_object *obj, const struct lu_name *cname,
700                         const struct lu_fid *pfid);
701 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
702                           char *name, struct lu_fid *pfid);
703 int lfsck_remove_name_entry(const struct lu_env *env,
704                             struct lfsck_instance *lfsck,
705                             struct dt_object *parent,
706                             const char *name, __u32 type);
707 int lfsck_update_name_entry(const struct lu_env *env,
708                             struct lfsck_instance *lfsck,
709                             struct dt_object *parent, const char *name,
710                             const struct lu_fid *pfid, __u32 type);
711 int lfsck_namespace_setup(const struct lu_env *env,
712                           struct lfsck_instance *lfsck);
713
714 /* lfsck_layout.c */
715 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
716
717 extern const char *lfsck_flags_names[];
718 extern const char *lfsck_param_names[];
719 extern struct lu_context_key lfsck_thread_key;
720
721 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
722 {
723         return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
724 }
725
726 static inline struct lfsck_thread_info *
727 lfsck_env_info(const struct lu_env *env)
728 {
729         struct lfsck_thread_info *info;
730
731         info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
732         LASSERT(info != NULL);
733         return info;
734 }
735
736 static inline const struct lu_name *
737 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
738 {
739         struct lu_name *lname;
740
741         lname = &lfsck_env_info(env)->lti_name;
742         lname->ln_name = area;
743         lname->ln_namelen = len;
744         return lname;
745 }
746
747 static inline void
748 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
749 {
750         buf->lb_buf = area;
751         buf->lb_len = len;
752 }
753
754 static inline struct lu_buf *
755 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
756 {
757         struct lu_buf *buf;
758
759         buf = &lfsck_env_info(env)->lti_buf;
760         buf->lb_buf = area;
761         buf->lb_len = len;
762         return buf;
763 }
764
765 static inline const struct lu_buf *
766 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
767 {
768         struct lu_buf *buf;
769
770         buf = &lfsck_env_info(env)->lti_buf;
771         buf->lb_buf = (void *)area;
772         buf->lb_len = len;
773         return buf;
774 }
775
776 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
777 {
778         return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
779 }
780
781 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
782 {
783         return lu_object_fid(&obj->do_lu);
784 }
785
786 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
787 {
788         memset(pos, 0, sizeof(*pos));
789 }
790
791 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
792 {
793         return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
794 }
795
796 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
797                                   const struct lfsck_position *pos2)
798 {
799         if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
800                 return -1;
801
802         if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
803                 return 1;
804
805         if (fid_is_zero(&pos1->lp_dir_parent) &&
806             !fid_is_zero(&pos2->lp_dir_parent))
807                 return -1;
808
809         if (!fid_is_zero(&pos1->lp_dir_parent) &&
810             fid_is_zero(&pos2->lp_dir_parent))
811                 return 1;
812
813         if (fid_is_zero(&pos1->lp_dir_parent) &&
814             fid_is_zero(&pos2->lp_dir_parent))
815                 return 0;
816
817         LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
818
819         if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
820                 return -1;
821
822         if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
823                 return 1;
824
825         return 0;
826 }
827
828 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
829                                             struct lfsck_position *src)
830 {
831         des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
832         fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
833         des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
834 }
835
836 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
837                                             struct lfsck_position *src)
838 {
839         des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
840         fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
841         des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
842 }
843
844 static inline umode_t lfsck_object_type(const struct dt_object *obj)
845 {
846         return lu_object_attr(&obj->do_lu);
847 }
848
849 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
850 {
851         struct lu_object_header *loh = obj->do_lu.lo_header;
852
853         return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
854 }
855
856 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
857 {
858         lu_object_get(&obj->do_lu);
859         return obj;
860 }
861
862 static inline void lfsck_object_put(const struct lu_env *env,
863                                     struct dt_object *obj)
864 {
865         lu_object_put(env, &obj->do_lu);
866 }
867
868 static inline struct dt_object *
869 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
870                                 const struct lu_fid *fid)
871 {
872         struct lu_object_conf   *conf = &lfsck_env_info(env)->lti_conf;
873         struct dt_object        *obj;
874
875         conf->loc_flags = LOC_F_NOWAIT;
876         obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
877         if (unlikely(obj == NULL))
878                 return ERR_PTR(-ENOENT);
879
880         return obj;
881 }
882
883 static inline struct dt_object *
884 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
885                          const struct lu_fid *fid)
886 {
887         struct dt_object *obj;
888
889         obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
890         if (unlikely(obj == NULL))
891                 return ERR_PTR(-ENOENT);
892
893         return obj;
894 }
895
896 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
897                                                   struct lfsck_instance *lfsck,
898                                                   const struct lu_fid *fid)
899 {
900         return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
901 }
902
903 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
904                                                    __u32 index)
905 {
906         struct lfsck_tgt_desc *ltd;
907
908         ltd = LTD_TGT(ltds, index);
909         if (ltd != NULL)
910                 atomic_inc(&ltd->ltd_ref);
911
912         return ltd;
913 }
914
915 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
916 {
917         if (atomic_dec_and_test(&ltd->ltd_ref))
918                 OBD_FREE_PTR(ltd);
919 }
920
921 static inline struct lfsck_component *
922 lfsck_component_get(struct lfsck_component *com)
923 {
924         atomic_inc(&com->lc_ref);
925
926         return com;
927 }
928
929 static inline void lfsck_component_put(const struct lu_env *env,
930                                        struct lfsck_component *com)
931 {
932         if (atomic_dec_and_test(&com->lc_ref)) {
933                 if (com->lc_obj != NULL)
934                         lu_object_put_nocache(env, &com->lc_obj->do_lu);
935                 if (com->lc_file_ram != NULL)
936                         OBD_FREE(com->lc_file_ram, com->lc_file_size);
937                 if (com->lc_file_disk != NULL)
938                         OBD_FREE(com->lc_file_disk, com->lc_file_size);
939                 if (com->lc_data != NULL) {
940                         LASSERT(com->lc_ops->lfsck_data_release != NULL);
941
942                         com->lc_ops->lfsck_data_release(env, com);
943                 }
944
945                 OBD_FREE_PTR(com);
946         }
947 }
948
949 static inline struct lfsck_instance *
950 lfsck_instance_get(struct lfsck_instance *lfsck)
951 {
952         atomic_inc(&lfsck->li_ref);
953
954         return lfsck;
955 }
956
957 static inline void lfsck_instance_put(const struct lu_env *env,
958                                       struct lfsck_instance *lfsck)
959 {
960         if (atomic_dec_and_test(&lfsck->li_ref))
961                 lfsck_instance_cleanup(env, lfsck);
962 }
963
964 static inline u32 lfsck_dev_idx(struct dt_device *dev)
965 {
966         return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
967 }
968
969 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
970 {
971         return list_empty(&lad->lad_mdt_phase1_list) &&
972                (!list_empty(&lad->lad_ost_phase2_list) ||
973                 list_empty(&lad->lad_ost_phase1_list));
974 }
975
976 #endif /* _LFSCK_INTERNAL_H */