Whamcloud - gitweb
LU-5506 lfsck: skip orphan OST-object handling for failed OSTs
[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         /* The size of ll_ost_bitmap with nbits. */
258         __u32   ll_bitmap_size;
259
260         /* For further using. 256-bytes aligned now. */
261         __u32   ll_reserved_1;
262         __u64   ll_reserved_2[11];
263
264         /* The OST targets bitmap to record the OSTs that contain
265          * non-verified OST-objects. */
266         __u8    ll_ost_bitmap[0];
267 };
268
269 struct lfsck_component;
270 struct lfsck_tgt_descs;
271 struct lfsck_tgt_desc;
272
273 struct lfsck_operations {
274         int (*lfsck_reset)(const struct lu_env *env,
275                            struct lfsck_component *com,
276                            bool init);
277
278         void (*lfsck_fail)(const struct lu_env *env,
279                            struct lfsck_component *com,
280                            bool new_checked);
281
282         int (*lfsck_checkpoint)(const struct lu_env *env,
283                                 struct lfsck_component *com,
284                                 bool init);
285
286         int (*lfsck_prep)(const struct lu_env *env,
287                           struct lfsck_component *com,
288                           struct lfsck_start_param *lsp);
289
290         int (*lfsck_exec_oit)(const struct lu_env *env,
291                               struct lfsck_component *com,
292                               struct dt_object *obj);
293
294         int (*lfsck_exec_dir)(const struct lu_env *env,
295                               struct lfsck_component *com,
296                               struct lu_dirent *ent,
297                               __u16 type);
298
299         int (*lfsck_post)(const struct lu_env *env,
300                           struct lfsck_component *com,
301                           int result,
302                           bool init);
303
304         int (*lfsck_dump)(const struct lu_env *env,
305                           struct lfsck_component *com,
306                           struct seq_file *m);
307
308         int (*lfsck_double_scan)(const struct lu_env *env,
309                                  struct lfsck_component *com);
310
311         void (*lfsck_data_release)(const struct lu_env *env,
312                                    struct lfsck_component *com);
313
314         void (*lfsck_quit)(const struct lu_env *env,
315                            struct lfsck_component *com);
316
317         int (*lfsck_in_notify)(const struct lu_env *env,
318                                struct lfsck_component *com,
319                                struct lfsck_request *lr);
320
321         int (*lfsck_query)(const struct lu_env *env,
322                            struct lfsck_component *com);
323
324         int (*lfsck_join)(const struct lu_env *env,
325                           struct lfsck_component *com,
326                           struct lfsck_start_param *lsp);
327 };
328
329 #define TGT_PTRS                256     /* number of pointers at 1st level */
330 #define TGT_PTRS_PER_BLOCK      256     /* number of pointers at 2nd level */
331
332 struct lfsck_tgt_desc {
333         struct list_head   ltd_orphan_list;
334         struct dt_device  *ltd_tgt;
335         struct dt_device  *ltd_key;
336         struct obd_export *ltd_exp;
337         struct list_head   ltd_layout_list;
338         struct list_head   ltd_layout_phase_list;
339         struct list_head   ltd_namespace_list;
340         struct list_head   ltd_namespace_phase_list;
341         atomic_t           ltd_ref;
342         __u32              ltd_index;
343         __u32              ltd_layout_gen;
344         __u32              ltd_namespace_gen;
345         unsigned int       ltd_dead:1,
346                            ltd_layout_done:1,
347                            ltd_namespace_done:1;
348 };
349
350 struct lfsck_tgt_desc_idx {
351         struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
352 };
353
354 struct lfsck_tgt_descs {
355         /* list of known TGTs */
356         struct lfsck_tgt_desc_idx       *ltd_tgts_idx[TGT_PTRS];
357
358         /* bitmap of TGTs available */
359         cfs_bitmap_t                    *ltd_tgts_bitmap;
360
361         /* for lfsck_tgt_desc::ltd_xxx_list */
362         spinlock_t                       ltd_lock;
363
364         /* for tgts table accessing and changes */
365         struct rw_semaphore              ltd_rw_sem;
366
367         /* Temporary list for orphan targets. */
368         struct list_head                 ltd_orphan;
369
370         /* number of registered TGTs */
371         __u32                            ltd_tgtnr;
372 };
373
374 #define LTD_TGT(ltd, index)     \
375         ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
376          ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
377
378 #define OST_TGT(lfsck, index)   LTD_TGT(&lfsck->li_ost_descs, index)
379 #define MDT_TGT(lfsck, index)   LTD_TGT(&lfsck->li_mdt_descs, index)
380
381 struct lfsck_component {
382         /* into lfsck_instance::li_list_(scan,double_scan,idle} */
383         struct list_head         lc_link;
384
385         /* into lfsck_instance::li_list_dir */
386         struct list_head         lc_link_dir;
387
388         struct rw_semaphore      lc_sem;
389         atomic_t                 lc_ref;
390
391         struct lfsck_position    lc_pos_start;
392         struct lfsck_instance   *lc_lfsck;
393         struct dt_object        *lc_obj;
394         struct lfsck_operations *lc_ops;
395         void                    *lc_file_ram;
396         void                    *lc_file_disk;
397         void                    *lc_data;
398         struct lu_fid            lc_fid_latest_scanned_phase2;
399
400         /* The time for last checkpoint, jiffies */
401         cfs_time_t               lc_time_last_checkpoint;
402
403         /* The time for next checkpoint, jiffies */
404         cfs_time_t               lc_time_next_checkpoint;
405
406         __u32                    lc_file_size;
407
408         /* How many objects have been checked since last checkpoint. */
409         __u32                    lc_new_checked;
410
411         /* How many objects have been scanned since last sleep. */
412         __u32                    lc_new_scanned;
413
414         unsigned int             lc_journal:1;
415         __u16                    lc_type;
416 };
417
418 struct lfsck_instance {
419         struct mutex              li_mutex;
420         spinlock_t                li_lock;
421
422         /* Link into the lfsck_instance_list. */
423         struct list_head          li_link;
424
425         /* For the components in (first) scanning via otable-based iteration. */
426         struct list_head          li_list_scan;
427
428         /* For the components in scanning via directory traversal. Because
429          * directory traversal cannot guarantee all the object be scanned,
430          * so the component in the li_list_dir must be in li_list_scan. */
431         struct list_head          li_list_dir;
432
433         /* For the components in double scanning. */
434         struct list_head          li_list_double_scan;
435
436         /* For the components those are not scanning now. */
437         struct list_head          li_list_idle;
438
439         atomic_t                  li_ref;
440         atomic_t                  li_double_scan_count;
441         struct ptlrpc_thread      li_thread;
442
443         /* The time for last checkpoint, jiffies */
444         cfs_time_t                li_time_last_checkpoint;
445
446         /* The time for next checkpoint, jiffies */
447         cfs_time_t                li_time_next_checkpoint;
448
449         lfsck_out_notify          li_out_notify;
450         void                     *li_out_notify_data;
451         struct dt_device         *li_next;
452         struct dt_device         *li_bottom;
453         struct obd_device        *li_obd;
454         struct ldlm_namespace    *li_namespace;
455         struct local_oid_storage *li_los;
456         struct lu_fid             li_local_root_fid;  /* backend root "/" */
457         struct lu_fid             li_global_root_fid; /* /ROOT */
458         struct dt_object         *li_bookmark_obj;
459         struct dt_object         *li_lpf_obj;
460         struct lu_client_seq     *li_seq;
461         struct lfsck_bookmark     li_bookmark_ram;
462         struct lfsck_bookmark     li_bookmark_disk;
463         struct lfsck_position     li_pos_current;
464         struct lfsck_position     li_pos_checkpoint;
465
466         /* Obj for otable-based iteration */
467         struct dt_object         *li_obj_oit;
468
469         /* Obj for directory traversal */
470         struct dt_object         *li_obj_dir;
471
472         /* It for otable-based iteration */
473         struct dt_it             *li_di_oit;
474
475         /* It for directory traversal */
476         struct dt_it             *li_di_dir;
477
478         /* Description of OST */
479         struct lfsck_tgt_descs    li_ost_descs;
480
481         /* Description of MDT */
482         struct lfsck_tgt_descs    li_mdt_descs;
483
484         /* namespace-based directory traversal position. */
485         __u64                     li_cookie_dir;
486
487         /* Arguments for low layer otable-based iteration. */
488         __u32                     li_args_oit;
489
490         /* Arugments for namespace-based directory traversal. */
491         __u32                     li_args_dir;
492
493         /* Schedule for every N objects. */
494         __u32                     li_sleep_rate;
495
496         /* Sleep N jiffies for each schedule. */
497         __u32                     li_sleep_jif;
498
499         /* How many objects have been scanned since last sleep. */
500         __u32                     li_new_scanned;
501
502         /* The status when the LFSCK stopped or paused. */
503         __u32                     li_status;
504
505         /* The flags when the lFSCK stopped or paused. */
506         __u32                     li_flags;
507
508         unsigned int              li_oit_over:1, /* oit is finished. */
509                                   li_drop_dryrun:1, /* Ever dryrun, not now. */
510                                   li_master:1, /* Master instance or not. */
511                                   li_current_oit_processed:1,
512                                   li_start_unplug:1;
513 };
514
515 enum lfsck_linkea_flags {
516         /* The linkea entries does not match the object nlinks. */
517         LLF_UNMATCH_NLINKS      = 0x01,
518
519         /* Fail to repair the multiple-linked objects during the double scan. */
520         LLF_REPAIR_FAILED       = 0x02,
521 };
522
523 struct lfsck_async_interpret_args {
524         struct lfsck_component          *laia_com;
525         struct lfsck_tgt_descs          *laia_ltds;
526         struct lfsck_tgt_desc           *laia_ltd;
527         struct lfsck_request            *laia_lr;
528         atomic_t                        *laia_count;
529         int                              laia_result;
530         unsigned int                     laia_shared:1;
531 };
532
533 struct lfsck_thread_args {
534         struct lu_env                    lta_env;
535         struct lfsck_instance           *lta_lfsck;
536         struct lfsck_component          *lta_com;
537         struct lfsck_start_param        *lta_lsp;
538 };
539
540 struct lfsck_assistant_req {
541         struct list_head        lar_list;
542 };
543
544 struct lfsck_assistant_operations {
545         int (*la_handler_p1)(const struct lu_env *env,
546                              struct lfsck_component *com,
547                              struct lfsck_assistant_req *lar);
548
549         int (*la_handler_p2)(const struct lu_env *env,
550                              struct lfsck_component *com);
551
552         void (*la_fill_pos)(const struct lu_env *env,
553                             struct lfsck_component *com,
554                             struct lfsck_position *pos);
555
556         int (*la_double_scan_result)(const struct lu_env *env,
557                                      struct lfsck_component *com,
558                                      int rc);
559
560         void (*la_req_fini)(const struct lu_env *env,
561                             struct lfsck_assistant_req *lar);
562
563         void (*la_sync_failures)(const struct lu_env *env,
564                                  struct lfsck_component *com,
565                                  struct lfsck_request *lr);
566 };
567
568 struct lfsck_assistant_data {
569         spinlock_t                               lad_lock;
570         struct list_head                         lad_req_list;
571
572         /* list for the ost targets involve LFSCK. */
573         struct list_head                         lad_ost_list;
574
575         /* list for the ost targets in phase1 scanning. */
576         struct list_head                         lad_ost_phase1_list;
577
578         /* list for the ost targets in phase1 scanning. */
579         struct list_head                         lad_ost_phase2_list;
580
581         /* list for the mdt targets involve LFSCK. */
582         struct list_head                         lad_mdt_list;
583
584         /* list for the mdt targets in phase1 scanning. */
585         struct list_head                         lad_mdt_phase1_list;
586
587         /* list for the mdt targets in phase1 scanning. */
588         struct list_head                         lad_mdt_phase2_list;
589
590         const char                              *lad_name;
591         struct ptlrpc_thread                     lad_thread;
592
593         struct lfsck_assistant_operations       *lad_ops;
594
595         cfs_bitmap_t                            *lad_bitmap;
596
597         __u32                                    lad_touch_gen;
598         int                                      lad_prefetched;
599         int                                      lad_assistant_status;
600         int                                      lad_post_result;
601         unsigned int                             lad_to_post:1,
602                                                  lad_to_double_scan:1,
603                                                  lad_in_double_scan:1,
604                                                  lad_exit:1,
605                                                  lad_incomplete:1;
606 };
607
608 #define LFSCK_TMPBUF_LEN        64
609
610 struct lfsck_thread_info {
611         struct lu_name          lti_name;
612         struct lu_buf           lti_buf;
613         struct lu_buf           lti_linkea_buf;
614         struct lu_buf           lti_big_buf;
615         struct lu_fid           lti_fid;
616         struct lu_fid           lti_fid2;
617         struct lu_fid           lti_fid3;
618         struct lu_attr          lti_la;
619         struct lu_attr          lti_la2;
620         struct lu_attr          lti_la3;
621         struct ost_id           lti_oi;
622         union {
623                 struct lustre_mdt_attrs lti_lma;
624                 /* old LMA for compatibility */
625                 char                    lti_lma_old[LMA_OLD_SIZE];
626         };
627         struct dt_object_format lti_dof;
628         /* There will be '\0' at the end of the name. */
629         char            lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
630         char                    lti_tmpbuf[LFSCK_TMPBUF_LEN];
631         struct lfsck_request    lti_lr;
632         struct lfsck_async_interpret_args lti_laia;
633         struct lfsck_async_interpret_args lti_laia2;
634         struct lfsck_start      lti_start;
635         struct lfsck_stop       lti_stop;
636         ldlm_policy_data_t      lti_policy;
637         struct ldlm_res_id      lti_resid;
638         union {
639                 struct filter_fid_old   lti_old_pfid;
640                 struct filter_fid       lti_new_pfid;
641         };
642         struct dt_allocation_hint lti_hint;
643         struct lu_orphan_rec    lti_rec;
644         struct lov_user_md      lti_lum;
645         struct dt_insert_rec    lti_dt_rec;
646         struct lu_object_conf   lti_conf;
647 };
648
649 /* lfsck_lib.c */
650 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
651                     struct lu_fid *fid, bool locked);
652 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
653                      struct dt_object *obj, struct lustre_handle *lh,
654                      __u64 bits, ldlm_mode_t mode);
655 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
656 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
657 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
658 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
659                                            bool unlink);
660 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
661                                              __u16 type);
662 const char *lfsck_status2names(enum lfsck_status status);
663 void lfsck_component_cleanup(const struct lu_env *env,
664                              struct lfsck_component *com);
665 void lfsck_instance_cleanup(const struct lu_env *env,
666                             struct lfsck_instance *lfsck);
667 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
668                     const char *prefix);
669 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
670 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
671                    const char *prefix);
672 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
673                     struct lfsck_position *pos, bool init);
674 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
675 void lfsck_control_speed(struct lfsck_instance *lfsck);
676 void lfsck_control_speed_by_self(struct lfsck_component *com);
677 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
678 struct lfsck_assistant_data *
679 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
680                           const char *name);
681 int lfsck_async_interpret_common(const struct lu_env *env,
682                                  struct ptlrpc_request *req,
683                                  void *args, int rc);
684 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
685                         struct lfsck_request *lr,
686                         struct ptlrpc_request_set *set,
687                         ptlrpc_interpterer_t interpterer,
688                         void *args, int request);
689 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
690                           struct lfsck_start_param *lsp);
691 int lfsck_checkpoint_generic(const struct lu_env *env,
692                              struct lfsck_component *com);
693 void lfsck_post_generic(const struct lu_env *env,
694                         struct lfsck_component *com, int *result);
695 int lfsck_double_scan_generic(const struct lu_env *env,
696                               struct lfsck_component *com, int status);
697 void lfsck_quit_generic(const struct lu_env *env,
698                         struct lfsck_component *com);
699
700 /* lfsck_engine.c */
701 int lfsck_master_engine(void *args);
702 int lfsck_assistant_engine(void *args);
703
704 /* lfsck_bookmark.c */
705 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
706                               struct lfsck_bookmark *src);
707 int lfsck_bookmark_store(const struct lu_env *env,
708                          struct lfsck_instance *lfsck);
709 int lfsck_bookmark_setup(const struct lu_env *env,
710                          struct lfsck_instance *lfsck);
711 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
712                     struct lfsck_start *start, bool reset);
713
714 /* lfsck_namespace.c */
715 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
716                         struct dt_object *obj, const struct lu_name *cname,
717                         const struct lu_fid *pfid);
718 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
719                           char *name, struct lu_fid *pfid);
720 int lfsck_remove_name_entry(const struct lu_env *env,
721                             struct lfsck_instance *lfsck,
722                             struct dt_object *parent,
723                             const char *name, __u32 type);
724 int lfsck_update_name_entry(const struct lu_env *env,
725                             struct lfsck_instance *lfsck,
726                             struct dt_object *parent, const char *name,
727                             const struct lu_fid *pfid, __u32 type);
728 int lfsck_namespace_setup(const struct lu_env *env,
729                           struct lfsck_instance *lfsck);
730
731 /* lfsck_layout.c */
732 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
733
734 extern const char *lfsck_flags_names[];
735 extern const char *lfsck_param_names[];
736 extern struct lu_context_key lfsck_thread_key;
737
738 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
739 {
740         return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
741 }
742
743 static inline struct lfsck_thread_info *
744 lfsck_env_info(const struct lu_env *env)
745 {
746         struct lfsck_thread_info *info;
747
748         info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
749         LASSERT(info != NULL);
750         return info;
751 }
752
753 static inline const struct lu_name *
754 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
755 {
756         struct lu_name *lname;
757
758         lname = &lfsck_env_info(env)->lti_name;
759         lname->ln_name = area;
760         lname->ln_namelen = len;
761         return lname;
762 }
763
764 static inline void
765 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
766 {
767         buf->lb_buf = area;
768         buf->lb_len = len;
769 }
770
771 static inline struct lu_buf *
772 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
773 {
774         struct lu_buf *buf;
775
776         buf = &lfsck_env_info(env)->lti_buf;
777         buf->lb_buf = area;
778         buf->lb_len = len;
779         return buf;
780 }
781
782 static inline const struct lu_buf *
783 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
784 {
785         struct lu_buf *buf;
786
787         buf = &lfsck_env_info(env)->lti_buf;
788         buf->lb_buf = (void *)area;
789         buf->lb_len = len;
790         return buf;
791 }
792
793 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
794 {
795         return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
796 }
797
798 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
799 {
800         return lu_object_fid(&obj->do_lu);
801 }
802
803 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
804 {
805         memset(pos, 0, sizeof(*pos));
806 }
807
808 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
809 {
810         return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
811 }
812
813 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
814                                   const struct lfsck_position *pos2)
815 {
816         if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
817                 return -1;
818
819         if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
820                 return 1;
821
822         if (fid_is_zero(&pos1->lp_dir_parent) &&
823             !fid_is_zero(&pos2->lp_dir_parent))
824                 return -1;
825
826         if (!fid_is_zero(&pos1->lp_dir_parent) &&
827             fid_is_zero(&pos2->lp_dir_parent))
828                 return 1;
829
830         if (fid_is_zero(&pos1->lp_dir_parent) &&
831             fid_is_zero(&pos2->lp_dir_parent))
832                 return 0;
833
834         LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
835
836         if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
837                 return -1;
838
839         if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
840                 return 1;
841
842         return 0;
843 }
844
845 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
846                                             struct lfsck_position *src)
847 {
848         des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
849         fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
850         des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
851 }
852
853 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
854                                             struct lfsck_position *src)
855 {
856         des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
857         fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
858         des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
859 }
860
861 static inline umode_t lfsck_object_type(const struct dt_object *obj)
862 {
863         return lu_object_attr(&obj->do_lu);
864 }
865
866 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
867 {
868         struct lu_object_header *loh = obj->do_lu.lo_header;
869
870         return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
871 }
872
873 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
874 {
875         lu_object_get(&obj->do_lu);
876         return obj;
877 }
878
879 static inline void lfsck_object_put(const struct lu_env *env,
880                                     struct dt_object *obj)
881 {
882         lu_object_put(env, &obj->do_lu);
883 }
884
885 static inline struct dt_object *
886 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
887                                 const struct lu_fid *fid)
888 {
889         struct lu_object_conf   *conf = &lfsck_env_info(env)->lti_conf;
890         struct dt_object        *obj;
891
892         conf->loc_flags = LOC_F_NOWAIT;
893         obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
894         if (unlikely(obj == NULL))
895                 return ERR_PTR(-ENOENT);
896
897         return obj;
898 }
899
900 static inline struct dt_object *
901 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
902                          const struct lu_fid *fid)
903 {
904         struct dt_object *obj;
905
906         obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
907         if (unlikely(obj == NULL))
908                 return ERR_PTR(-ENOENT);
909
910         return obj;
911 }
912
913 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
914                                                   struct lfsck_instance *lfsck,
915                                                   const struct lu_fid *fid)
916 {
917         return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
918 }
919
920 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
921                                                    __u32 index)
922 {
923         struct lfsck_tgt_desc *ltd;
924
925         ltd = LTD_TGT(ltds, index);
926         if (ltd != NULL)
927                 atomic_inc(&ltd->ltd_ref);
928
929         return ltd;
930 }
931
932 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
933 {
934         if (atomic_dec_and_test(&ltd->ltd_ref))
935                 OBD_FREE_PTR(ltd);
936 }
937
938 static inline struct lfsck_component *
939 lfsck_component_get(struct lfsck_component *com)
940 {
941         atomic_inc(&com->lc_ref);
942
943         return com;
944 }
945
946 static inline void lfsck_component_put(const struct lu_env *env,
947                                        struct lfsck_component *com)
948 {
949         if (atomic_dec_and_test(&com->lc_ref)) {
950                 if (com->lc_obj != NULL)
951                         lu_object_put_nocache(env, &com->lc_obj->do_lu);
952                 if (com->lc_file_ram != NULL)
953                         OBD_FREE(com->lc_file_ram, com->lc_file_size);
954                 if (com->lc_file_disk != NULL)
955                         OBD_FREE(com->lc_file_disk, com->lc_file_size);
956                 if (com->lc_data != NULL) {
957                         LASSERT(com->lc_ops->lfsck_data_release != NULL);
958
959                         com->lc_ops->lfsck_data_release(env, com);
960                 }
961
962                 OBD_FREE_PTR(com);
963         }
964 }
965
966 static inline struct lfsck_instance *
967 lfsck_instance_get(struct lfsck_instance *lfsck)
968 {
969         atomic_inc(&lfsck->li_ref);
970
971         return lfsck;
972 }
973
974 static inline void lfsck_instance_put(const struct lu_env *env,
975                                       struct lfsck_instance *lfsck)
976 {
977         if (atomic_dec_and_test(&lfsck->li_ref))
978                 lfsck_instance_cleanup(env, lfsck);
979 }
980
981 static inline u32 lfsck_dev_idx(struct dt_device *dev)
982 {
983         return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
984 }
985
986 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
987 {
988         return list_empty(&lad->lad_mdt_phase1_list) &&
989                (!list_empty(&lad->lad_ost_phase2_list) ||
990                 list_empty(&lad->lad_ost_phase1_list));
991 }
992
993 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
994                                         struct lfsck_component *com,
995                                         __u32 index)
996 {
997         struct lfsck_assistant_data     *lad    = com->lc_data;
998         cfs_bitmap_t                    *bitmap = lad->lad_bitmap;
999
1000         LASSERT(com->lc_lfsck->li_master);
1001         LASSERT(bitmap != NULL);
1002         LASSERTF(bitmap->size > index, "invalid index: nbits %d, index %u\n",
1003                  bitmap->size, index);
1004
1005         cfs_bitmap_set(bitmap, index);
1006         lad->lad_incomplete = 1;
1007 }
1008
1009 #endif /* _LFSCK_INTERNAL_H */