Whamcloud - gitweb
LU-5519 lfsck: repair master LMV for striped directory
[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 enum lfsck_namespace_trace_flags {
112         LNTF_CHECK_LINKEA       = 0x01,
113         LNTF_CHECK_PARENT       = 0x02,
114         LNTF_SKIP_NLINK         = 0x04,
115         LNTF_CHECK_ORPHAN       = 0x08,
116         LNTF_UNCERTAIN_LMV      = 0x10,
117         LNTF_RECHECK_NAME_HASH  = 0x20,
118         LNTF_ALL                = 0xff
119 };
120
121 enum lfsck_namespace_inconsistency_type {
122         LNIT_NONE               = 0,
123         LNIT_BAD_LINKEA         = 1,
124         LNIT_UNMATCHED_PAIRS    = 2,
125         LNIT_DANGLING           = 3,
126         LNIT_MUL_REF            = 4,
127         LNIT_BAD_TYPE           = 5,
128         LNIT_BAD_DIRENT         = 6,
129 };
130
131 struct lfsck_namespace {
132         /* Magic number to detect that this struct contains valid data. */
133         __u32   ln_magic;
134
135         /* See 'enum lfsck_status'. */
136         __u32   ln_status;
137
138         /* See 'enum lfsck_flags'. */
139         __u32   ln_flags;
140
141         /* How many completed LFSCK runs on the device. */
142         __u32   ln_success_count;
143
144         /*  How long the LFSCK phase1 has run in seconds. */
145         __u32   ln_run_time_phase1;
146
147         /*  How long the LFSCK phase2 has run in seconds. */
148         __u32   ln_run_time_phase2;
149
150         /* Time for the last LFSCK completed in seconds since epoch. */
151         __u64   ln_time_last_complete;
152
153         /* Time for the latest LFSCK ran in seconds since epoch. */
154         __u64   ln_time_latest_start;
155
156         /* Time for the last LFSCK checkpoint in seconds since epoch. */
157         __u64   ln_time_last_checkpoint;
158
159         /* Position for the latest LFSCK started from. */
160         struct lfsck_position   ln_pos_latest_start;
161
162         /* Position for the last LFSCK checkpoint. */
163         struct lfsck_position   ln_pos_last_checkpoint;
164
165         /* Position for the first should be updated object. */
166         struct lfsck_position   ln_pos_first_inconsistent;
167
168         /* How many items (including dir) have been checked. */
169         __u64   ln_items_checked;
170
171         /* How many items have been repaired. */
172         __u64   ln_items_repaired;
173
174         /* How many items failed to be processed. */
175         __u64   ln_items_failed;
176
177         /* How many directories have been traversed. */
178         __u64   ln_dirs_checked;
179
180         /* How many objects have been double scanned. */
181         __u64   ln_objs_checked_phase2;
182
183         /* How many objects have been reparied during double scan. */
184         __u64   ln_objs_repaired_phase2;
185
186         /* How many objects failed to be processed during double scan. */
187         __u64   ln_objs_failed_phase2;
188
189         /* How many objects with nlink fixed. */
190         __u64   ln_objs_nlink_repaired;
191
192         /* The latest object has been processed (failed) during double scan. */
193         struct lu_fid   ln_fid_latest_scanned_phase2;
194
195         /* How many FID-in-dirent entries have been repaired. */
196         __u64   ln_dirent_repaired;
197
198         /* How many linkEA entries have been repaired. */
199         __u64   ln_linkea_repaired;
200
201         /* How many multiple-linked objects have been checked. */
202         __u64   ln_mul_linked_checked;
203
204         /* How many multiple-linked objects have been repaired. */
205         __u64   ln_mul_linked_repaired;
206
207         /* How many undefined inconsistency found in phase2. */
208         __u64   ln_unknown_inconsistency;
209
210         /* How many unmatched pairs have been repaired. */
211         __u64   ln_unmatched_pairs_repaired;
212
213         /* How many dangling name entries have been found/repaired. */
214         __u64   ln_dangling_repaired;
215
216         /* How many multiple referenced name entries have been
217          * found/repaired. */
218         __u64   ln_mul_ref_repaired;
219
220         /* How many name entries with bad file type have been repaired. */
221         __u64   ln_bad_type_repaired;
222
223         /* How many lost name entries have been re-inserted. */
224         __u64   ln_lost_dirent_repaired;
225
226         /* How many objects under /lost+found have been scanned. */
227         __u64   ln_local_lpf_scanned;
228
229         /* How many objects under /lost+found have been moved to
230          * namespace visible directory. */
231         __u64   ln_local_lpf_moved;
232
233         /* How many objects under /lost+found have been skipped. */
234         __u64   ln_local_lpf_skipped;
235
236         /* How many objects under /lost+found failed to be processed. */
237         __u64   ln_local_lpf_failed;
238
239         /* How many striped directories (master) have been scanned. */
240         __u64   ln_striped_dirs_scanned;
241
242         /* How many striped directories (master) have been repaired. */
243         __u64   ln_striped_dirs_repaired;
244
245         /* How many striped directories (master) failed verification. */
246         __u64   ln_striped_dirs_failed;
247
248         /* How many striped directories (master) has been disabled. */
249         __u64   ln_striped_dirs_disabled;
250
251         /* How many striped directory's (master) have been skipped
252          * (for shards verification) because of lost master LMV EA. */
253         __u64   ln_striped_dirs_skipped;
254
255         /* How many striped directory's shards (slave) have been scanned. */
256         __u64   ln_striped_shards_scanned;
257
258         /* How many striped directory's shards (slave) have been repaired. */
259         __u64   ln_striped_shards_repaired;
260
261         /* How many striped directory's shards (slave) failed verification. */
262         __u64   ln_striped_shards_failed;
263
264         /* How many striped directory's shards (slave) have been skipped
265          * (for name hash verification) because do not know whether the slave
266          * LMV EA is valid or not. */
267         __u64   ln_striped_shards_skipped;
268
269         /* How many name entries under striped directory with bad name
270          * hash have been repaired. */
271         __u64   ln_name_hash_repaired;
272
273         /* The size of MDT targets bitmap with nbits. Such bitmap records
274          * the MDTs that contain non-verified MDT-objects. */
275         __u32   ln_bitmap_size;
276
277         __u32   ln_reserved_1;
278         /* For further using. 256-bytes aligned now. */
279         __u64   ln_reserved[15];
280 };
281
282 enum lfsck_layout_inconsistency_type {
283         LLIT_NONE                       = 0,
284         LLIT_DANGLING                   = 1,
285         LLIT_UNMATCHED_PAIR             = 2,
286         LLIT_MULTIPLE_REFERENCED        = 3,
287         LLIT_ORPHAN                     = 4,
288         LLIT_INCONSISTENT_OWNER         = 5,
289         LLIT_OTHERS                     = 6,
290         LLIT_MAX                        = LLIT_OTHERS
291 };
292
293 struct lfsck_layout {
294         /* Magic number to detect that this struct contains valid data. */
295         __u32   ll_magic;
296
297         /* See 'enum lfsck_status'. */
298         __u32   ll_status;
299
300         /* See 'enum lfsck_flags'. */
301         __u32   ll_flags;
302
303         /* How many completed LFSCK runs on the device. */
304         __u32   ll_success_count;
305
306         /*  How long the LFSCK phase1 has run in seconds. */
307         __u32   ll_run_time_phase1;
308
309         /*  How long the LFSCK phase2 has run in seconds. */
310         __u32   ll_run_time_phase2;
311
312         /* Time for the last LFSCK completed in seconds since epoch. */
313         __u64   ll_time_last_complete;
314
315         /* Time for the latest LFSCK ran in seconds since epoch. */
316         __u64   ll_time_latest_start;
317
318         /* Time for the last LFSCK checkpoint in seconds since epoch. */
319         __u64   ll_time_last_checkpoint;
320
321         /* Position for the latest LFSCK started from. */
322         __u64   ll_pos_latest_start;
323
324         /* Position for the last LFSCK checkpoint. */
325         __u64   ll_pos_last_checkpoint;
326
327         /* Position for the first object to be fixed or
328          * failed to be checked in the phase1. */
329         __u64   ll_pos_first_inconsistent;
330
331         /* How many objects have been checked. */
332         __u64   ll_objs_checked_phase1;
333
334         /* How many objects failed to be processed. */
335         __u64   ll_objs_failed_phase1;
336
337         /* How many objects have been double scanned. */
338         __u64   ll_objs_checked_phase2;
339
340         /* How many objects failed to be processed during double scan. */
341         __u64   ll_objs_failed_phase2;
342
343         /* kinds of inconsistency have been or to be repaired.
344          * ll_objs_repaired[type - 1] is the count for the given @type. */
345         __u64   ll_objs_repaired[LLIT_MAX];
346
347         /* How many objects have been skipped because of related
348          * MDT(s)/OST(s) do not participate in the LFSCK */
349         __u64   ll_objs_skipped;
350
351         /* The size of ll_ost_bitmap with nbits. */
352         __u32   ll_bitmap_size;
353
354         /* For further using. 256-bytes aligned now. */
355         __u32   ll_reserved_1;
356         __u64   ll_reserved_2[11];
357
358         /* The OST targets bitmap to record the OSTs that contain
359          * non-verified OST-objects. */
360         __u8    ll_ost_bitmap[0];
361 };
362
363 struct lfsck_component;
364 struct lfsck_tgt_descs;
365 struct lfsck_tgt_desc;
366
367 struct lfsck_operations {
368         int (*lfsck_reset)(const struct lu_env *env,
369                            struct lfsck_component *com,
370                            bool init);
371
372         void (*lfsck_fail)(const struct lu_env *env,
373                            struct lfsck_component *com,
374                            bool new_checked);
375
376         void (*lfsck_close_dir)(const struct lu_env *env,
377                                 struct lfsck_component *com);
378
379         int (*lfsck_open_dir)(const struct lu_env *env,
380                               struct lfsck_component *com);
381
382         int (*lfsck_checkpoint)(const struct lu_env *env,
383                                 struct lfsck_component *com,
384                                 bool init);
385
386         int (*lfsck_prep)(const struct lu_env *env,
387                           struct lfsck_component *com,
388                           struct lfsck_start_param *lsp);
389
390         int (*lfsck_exec_oit)(const struct lu_env *env,
391                               struct lfsck_component *com,
392                               struct dt_object *obj);
393
394         int (*lfsck_exec_dir)(const struct lu_env *env,
395                               struct lfsck_component *com,
396                               struct lu_dirent *ent,
397                               __u16 type);
398
399         int (*lfsck_post)(const struct lu_env *env,
400                           struct lfsck_component *com,
401                           int result,
402                           bool init);
403
404         int (*lfsck_dump)(const struct lu_env *env,
405                           struct lfsck_component *com,
406                           struct seq_file *m);
407
408         int (*lfsck_double_scan)(const struct lu_env *env,
409                                  struct lfsck_component *com);
410
411         void (*lfsck_data_release)(const struct lu_env *env,
412                                    struct lfsck_component *com);
413
414         void (*lfsck_quit)(const struct lu_env *env,
415                            struct lfsck_component *com);
416
417         int (*lfsck_in_notify)(const struct lu_env *env,
418                                struct lfsck_component *com,
419                                struct lfsck_request *lr,
420                                struct thandle *th);
421
422         int (*lfsck_query)(const struct lu_env *env,
423                            struct lfsck_component *com);
424
425         int (*lfsck_join)(const struct lu_env *env,
426                           struct lfsck_component *com,
427                           struct lfsck_start_param *lsp);
428 };
429
430 #define TGT_PTRS                256     /* number of pointers at 1st level */
431 #define TGT_PTRS_PER_BLOCK      256     /* number of pointers at 2nd level */
432
433 struct lfsck_tgt_desc {
434         struct list_head   ltd_orphan_list;
435         struct dt_device  *ltd_tgt;
436         struct dt_device  *ltd_key;
437         struct obd_export *ltd_exp;
438         struct list_head   ltd_layout_list;
439         struct list_head   ltd_layout_phase_list;
440         struct list_head   ltd_namespace_list;
441         struct list_head   ltd_namespace_phase_list;
442         atomic_t           ltd_ref;
443         __u32              ltd_index;
444         __u32              ltd_layout_gen;
445         __u32              ltd_namespace_gen;
446         unsigned int       ltd_dead:1,
447                            ltd_layout_done:1,
448                            ltd_namespace_done:1,
449                            ltd_namespace_failed:1;
450 };
451
452 struct lfsck_tgt_desc_idx {
453         struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
454 };
455
456 struct lfsck_tgt_descs {
457         /* list of known TGTs */
458         struct lfsck_tgt_desc_idx       *ltd_tgts_idx[TGT_PTRS];
459
460         /* bitmap of TGTs available */
461         cfs_bitmap_t                    *ltd_tgts_bitmap;
462
463         /* for lfsck_tgt_desc::ltd_xxx_list */
464         spinlock_t                       ltd_lock;
465
466         /* for tgts table accessing and changes */
467         struct rw_semaphore              ltd_rw_sem;
468
469         /* Temporary list for orphan targets. */
470         struct list_head                 ltd_orphan;
471
472         /* number of registered TGTs */
473         __u32                            ltd_tgtnr;
474 };
475
476 #define LTD_TGT(ltd, index)     \
477         ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
478          ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
479
480 #define OST_TGT(lfsck, index)   LTD_TGT(&lfsck->li_ost_descs, index)
481 #define MDT_TGT(lfsck, index)   LTD_TGT(&lfsck->li_mdt_descs, index)
482
483 struct lfsck_component {
484         /* into lfsck_instance::li_list_(scan,double_scan,idle} */
485         struct list_head         lc_link;
486
487         /* into lfsck_instance::li_list_dir */
488         struct list_head         lc_link_dir;
489
490         struct rw_semaphore      lc_sem;
491         atomic_t                 lc_ref;
492
493         struct lfsck_position    lc_pos_start;
494         struct lfsck_instance   *lc_lfsck;
495         struct dt_object        *lc_obj;
496         struct lfsck_operations *lc_ops;
497         void                    *lc_file_ram;
498         void                    *lc_file_disk;
499         void                    *lc_data;
500         struct lu_fid            lc_fid_latest_scanned_phase2;
501
502         /* The time for last checkpoint, jiffies */
503         cfs_time_t               lc_time_last_checkpoint;
504
505         /* The time for next checkpoint, jiffies */
506         cfs_time_t               lc_time_next_checkpoint;
507
508         __u32                    lc_file_size;
509
510         /* How many objects have been checked since last checkpoint. */
511         __u32                    lc_new_checked;
512
513         /* How many objects have been scanned since last sleep. */
514         __u32                    lc_new_scanned;
515
516         __u16                    lc_type;
517 };
518
519 #define LFSCK_LMV_MAX_STRIPES   LMV_MAX_STRIPE_COUNT
520 #define LFSCK_LMV_DEF_STRIPES   4
521
522 /* When the namespace LFSCK scans a striped directory, it will record all
523  * the known shards' information in the structure "lfsck_slave_lmv_rec",
524  * including the shard's FID, index, slave LMV EA, and so on. Each shard
525  * will take one lfsck_slave_lmv_rec slot. After the 1st cycle scanning
526  * the striped directory, the LFSCK will get all the information about
527  * whether there are some inconsistency, and then it can repair them in
528  * the 2nd cycle scanning. */
529 struct lfsck_slave_lmv_rec {
530         struct lu_fid   lslr_fid;
531         __u32           lslr_stripe_count;
532         __u32           lslr_index; /* the index in name or in slave lmv */
533         __u32           lslr_hash_type;
534         __u32           lslr_flags;
535 };
536
537 struct lfsck_lmv {
538         struct lmv_mds_md_v1             ll_lmv;
539         atomic_t                         ll_ref;
540         int                              ll_stripes_allocated;
541         int                              ll_stripes_filled;
542         int                              ll_exit_value;
543         __u32                            ll_max_stripe_count;
544         __u32                            ll_max_filled_off;
545         __u32                            ll_hash_type;
546         unsigned int                     ll_lmv_master:1,
547                                          ll_lmv_slave:1,
548                                          ll_lmv_verified:1,
549                                          ll_lmv_updated:1,
550                                          ll_inline:1,
551                                          ll_failed:1,
552                                          ll_ignore:1;
553         struct lfsck_slave_lmv_rec      *ll_lslr;
554 };
555
556 /* If the namespace LFSCK finds that the master MDT-object of a striped
557  * directory lost its master LMV EA, it will re-generate the master LMV
558  * EA and notify the LFSCK instance on the MDT on which the striped dir
559  * master MDT-object resides to rescan the striped directory. To do that,
560  * the notify handler will insert a "lfsck_lmv_unit" structure into the
561  * lfsck::li_list_lmv. The LFSCK instance will scan such list from time
562  * to time to check whether needs to rescan some stirped directories. */
563 struct lfsck_lmv_unit {
564         struct list_head         llu_link;
565         struct lfsck_lmv         llu_lmv;
566         struct dt_object        *llu_obj;
567         struct lfsck_instance   *llu_lfsck;
568 };
569
570 struct lfsck_instance {
571         struct mutex              li_mutex;
572         spinlock_t                li_lock;
573
574         /* Link into the lfsck_instance_list. */
575         struct list_head          li_link;
576
577         /* For the components in (first) scanning via otable-based iteration. */
578         struct list_head          li_list_scan;
579
580         /* For the components in scanning via directory traversal. Because
581          * directory traversal cannot guarantee all the object be scanned,
582          * so the component in the li_list_dir must be in li_list_scan. */
583         struct list_head          li_list_dir;
584
585         /* For the components in double scanning. */
586         struct list_head          li_list_double_scan;
587
588         /* For the components those are not scanning now. */
589         struct list_head          li_list_idle;
590
591         /* For the lfsck_lmv_unit to be handled. */
592         struct list_head          li_list_lmv;
593
594         atomic_t                  li_ref;
595         atomic_t                  li_double_scan_count;
596         struct ptlrpc_thread      li_thread;
597
598         /* The time for last checkpoint, jiffies */
599         cfs_time_t                li_time_last_checkpoint;
600
601         /* The time for next checkpoint, jiffies */
602         cfs_time_t                li_time_next_checkpoint;
603
604         lfsck_out_notify          li_out_notify;
605         void                     *li_out_notify_data;
606         struct dt_device         *li_next;
607         struct dt_device         *li_bottom;
608         struct obd_device        *li_obd;
609         struct ldlm_namespace    *li_namespace;
610         struct local_oid_storage *li_los;
611         struct lu_fid             li_local_root_fid;  /* backend root "/" */
612         struct lu_fid             li_global_root_fid; /* /ROOT */
613         struct dt_object         *li_bookmark_obj;
614         struct dt_object         *li_lpf_obj;
615         struct lu_client_seq     *li_seq;
616         struct lfsck_bookmark     li_bookmark_ram;
617         struct lfsck_bookmark     li_bookmark_disk;
618         struct lfsck_position     li_pos_current;
619         struct lfsck_position     li_pos_checkpoint;
620
621         struct lfsck_lmv         *li_lmv;
622
623         /* Obj for otable-based iteration */
624         struct dt_object         *li_obj_oit;
625
626         /* Obj for directory traversal */
627         struct dt_object         *li_obj_dir;
628
629         /* It for otable-based iteration */
630         struct dt_it             *li_di_oit;
631
632         /* It for directory traversal */
633         struct dt_it             *li_di_dir;
634
635         /* Description of OST */
636         struct lfsck_tgt_descs    li_ost_descs;
637
638         /* Description of MDT */
639         struct lfsck_tgt_descs    li_mdt_descs;
640
641         /* namespace-based directory traversal position. */
642         __u64                     li_cookie_dir;
643
644         /* Arguments for low layer otable-based iteration. */
645         __u32                     li_args_oit;
646
647         /* Arugments for namespace-based directory traversal. */
648         __u32                     li_args_dir;
649
650         /* Schedule for every N objects. */
651         __u32                     li_sleep_rate;
652
653         /* Sleep N jiffies for each schedule. */
654         __u32                     li_sleep_jif;
655
656         /* How many objects have been scanned since last sleep. */
657         __u32                     li_new_scanned;
658
659         /* The status when the LFSCK stopped or paused. */
660         __u32                     li_status;
661
662         /* The flags when the lFSCK stopped or paused. */
663         __u32                     li_flags;
664
665         unsigned int              li_oit_over:1, /* oit is finished. */
666                                   li_drop_dryrun:1, /* Ever dryrun, not now. */
667                                   li_master:1, /* Master instance or not. */
668                                   li_current_oit_processed:1,
669                                   li_start_unplug:1;
670 };
671
672 struct lfsck_async_interpret_args {
673         struct lfsck_component          *laia_com;
674         struct lfsck_tgt_descs          *laia_ltds;
675         struct lfsck_tgt_desc           *laia_ltd;
676         struct lfsck_request            *laia_lr;
677         atomic_t                        *laia_count;
678         int                              laia_result;
679         unsigned int                     laia_shared:1;
680 };
681
682 struct lfsck_thread_args {
683         struct lu_env                    lta_env;
684         struct lfsck_instance           *lta_lfsck;
685         struct lfsck_component          *lta_com;
686         struct lfsck_start_param        *lta_lsp;
687 };
688
689 struct lfsck_assistant_req {
690         struct list_head        lar_list;
691 };
692
693 struct lfsck_namespace_req {
694         struct lfsck_assistant_req       lnr_lar;
695         struct dt_object                *lnr_obj;
696         struct lfsck_lmv                *lnr_lmv;
697         struct lu_fid                    lnr_fid;
698         __u64                            lnr_oit_cookie;
699         __u64                            lnr_dir_cookie;
700         __u32                            lnr_attr;
701         __u32                            lnr_size;
702         __u16                            lnr_type;
703         __u16                            lnr_namelen;
704         char                             lnr_name[0];
705 };
706
707 struct lfsck_assistant_operations {
708         int (*la_handler_p1)(const struct lu_env *env,
709                              struct lfsck_component *com,
710                              struct lfsck_assistant_req *lar);
711
712         int (*la_handler_p2)(const struct lu_env *env,
713                              struct lfsck_component *com);
714
715         void (*la_fill_pos)(const struct lu_env *env,
716                             struct lfsck_component *com,
717                             struct lfsck_position *pos);
718
719         int (*la_double_scan_result)(const struct lu_env *env,
720                                      struct lfsck_component *com,
721                                      int rc);
722
723         void (*la_req_fini)(const struct lu_env *env,
724                             struct lfsck_assistant_req *lar);
725
726         void (*la_sync_failures)(const struct lu_env *env,
727                                  struct lfsck_component *com,
728                                  struct lfsck_request *lr);
729 };
730
731 struct lfsck_assistant_data {
732         spinlock_t                               lad_lock;
733         struct list_head                         lad_req_list;
734
735         /* list for the ost targets involve LFSCK. */
736         struct list_head                         lad_ost_list;
737
738         /* list for the ost targets in phase1 scanning. */
739         struct list_head                         lad_ost_phase1_list;
740
741         /* list for the ost targets in phase1 scanning. */
742         struct list_head                         lad_ost_phase2_list;
743
744         /* list for the mdt targets involve LFSCK. */
745         struct list_head                         lad_mdt_list;
746
747         /* list for the mdt targets in phase1 scanning. */
748         struct list_head                         lad_mdt_phase1_list;
749
750         /* list for the mdt targets in phase1 scanning. */
751         struct list_head                         lad_mdt_phase2_list;
752
753         const char                              *lad_name;
754         struct ptlrpc_thread                     lad_thread;
755
756         struct lfsck_assistant_operations       *lad_ops;
757
758         cfs_bitmap_t                            *lad_bitmap;
759
760         __u32                                    lad_touch_gen;
761         int                                      lad_prefetched;
762         int                                      lad_assistant_status;
763         int                                      lad_post_result;
764         unsigned int                             lad_to_post:1,
765                                                  lad_to_double_scan:1,
766                                                  lad_in_double_scan:1,
767                                                  lad_exit:1,
768                                                  lad_incomplete:1;
769 };
770
771 #define LFSCK_TMPBUF_LEN        64
772
773 struct lfsck_thread_info {
774         struct lu_name          lti_name_const;
775         struct lu_name          lti_name;
776         struct lu_name          lti_name2;
777         struct lu_buf           lti_buf;
778         struct lu_buf           lti_linkea_buf;
779         struct lu_buf           lti_linkea_buf2;
780         struct lu_buf           lti_big_buf;
781         struct lu_fid           lti_fid;
782         struct lu_fid           lti_fid2;
783         struct lu_fid           lti_fid3;
784         struct lu_fid           lti_fid4;
785         struct lu_fid           lti_fid5;
786         struct lu_attr          lti_la;
787         struct lu_attr          lti_la2;
788         struct lu_attr          lti_la3;
789         struct ost_id           lti_oi;
790         union {
791                 struct lustre_mdt_attrs lti_lma;
792                 /* old LMA for compatibility */
793                 char                    lti_lma_old[LMA_OLD_SIZE];
794         };
795         struct dt_object_format lti_dof;
796         /* There will be '\0' at the end of the name. */
797         char            lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
798         char                    lti_tmpbuf[LFSCK_TMPBUF_LEN];
799         char                    lti_tmpbuf2[LFSCK_TMPBUF_LEN];
800         struct lfsck_request    lti_lr;
801         struct lfsck_async_interpret_args lti_laia;
802         struct lfsck_async_interpret_args lti_laia2;
803         struct lfsck_start      lti_start;
804         struct lfsck_stop       lti_stop;
805         ldlm_policy_data_t      lti_policy;
806         struct ldlm_enqueue_info lti_einfo;
807         struct ldlm_res_id      lti_resid;
808         union {
809                 struct filter_fid_old   lti_old_pfid;
810                 struct filter_fid       lti_new_pfid;
811         };
812         struct dt_allocation_hint lti_hint;
813         struct lu_orphan_rec    lti_rec;
814         struct lov_user_md      lti_lum;
815         struct dt_insert_rec    lti_dt_rec;
816         struct lu_object_conf   lti_conf;
817         struct lu_seq_range     lti_range;
818         struct lmv_mds_md_v1    lti_lmv;
819         struct lmv_mds_md_v1    lti_lmv2;
820         struct lmv_mds_md_v1    lti_lmv3;
821         struct lmv_mds_md_v1    lti_lmv4;
822 };
823
824 /* lfsck_lib.c */
825 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
826                     struct lu_fid *fid, bool locked);
827 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
828                      struct dt_object *obj, struct lustre_handle *lh,
829                      __u64 bits, ldlm_mode_t mode);
830 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
831 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
832                               struct lfsck_instance *lfsck,
833                               const struct lu_fid *fid);
834 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
835 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
836 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
837                                            bool unlink);
838 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
839                                              __u16 type);
840 const char *lfsck_status2names(enum lfsck_status status);
841 void lfsck_component_cleanup(const struct lu_env *env,
842                              struct lfsck_component *com);
843 void lfsck_instance_cleanup(const struct lu_env *env,
844                             struct lfsck_instance *lfsck);
845 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
846                     const char *prefix);
847 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
848 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
849                    const char *prefix);
850 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
851                     struct lfsck_position *pos, bool init);
852 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
853 void lfsck_control_speed(struct lfsck_instance *lfsck);
854 void lfsck_control_speed_by_self(struct lfsck_component *com);
855 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
856 struct lfsck_assistant_data *
857 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
858                           const char *name);
859 int lfsck_async_interpret_common(const struct lu_env *env,
860                                  struct ptlrpc_request *req,
861                                  void *args, int rc);
862 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
863                         struct lfsck_request *lr,
864                         struct ptlrpc_request_set *set,
865                         ptlrpc_interpterer_t interpterer,
866                         void *args, int request);
867 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
868                           struct lfsck_start_param *lsp);
869 int lfsck_checkpoint_generic(const struct lu_env *env,
870                              struct lfsck_component *com);
871 void lfsck_post_generic(const struct lu_env *env,
872                         struct lfsck_component *com, int *result);
873 int lfsck_double_scan_generic(const struct lu_env *env,
874                               struct lfsck_component *com, int status);
875 void lfsck_quit_generic(const struct lu_env *env,
876                         struct lfsck_component *com);
877
878 /* lfsck_engine.c */
879 int lfsck_unpack_ent(struct lu_dirent *ent, __u64 *cookie, __u16 *type);
880 void lfsck_close_dir(const struct lu_env *env,
881                      struct lfsck_instance *lfsck, int result);
882 int lfsck_open_dir(const struct lu_env *env,
883                    struct lfsck_instance *lfsck, __u64 cookie);
884 int lfsck_master_engine(void *args);
885 int lfsck_assistant_engine(void *args);
886
887 /* lfsck_bookmark.c */
888 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
889                               struct lfsck_bookmark *src);
890 int lfsck_bookmark_store(const struct lu_env *env,
891                          struct lfsck_instance *lfsck);
892 int lfsck_bookmark_setup(const struct lu_env *env,
893                          struct lfsck_instance *lfsck);
894 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
895                     struct lfsck_start *start, bool reset);
896
897 /* lfsck_namespace.c */
898 int lfsck_namespace_trace_update(const struct lu_env *env,
899                                  struct lfsck_component *com,
900                                  const struct lu_fid *fid,
901                                  const __u8 flags, bool add);
902 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
903                        struct linkea_data *ldata);
904 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
905                                    struct lfsck_component *com,
906                                    struct dt_object *obj,
907                                    struct linkea_data *ldata);
908 int lfsck_namespace_repair_dangling(const struct lu_env *env,
909                                     struct lfsck_component *com,
910                                     struct dt_object *child,
911                                     struct lfsck_namespace_req *lnr);
912 int lfsck_namespace_repair_dirent(const struct lu_env *env,
913                                   struct lfsck_component *com,
914                                   struct dt_object *parent,
915                                   struct dt_object *child,
916                                   const char *name, const char *name2,
917                                   __u16 type, bool update, bool dec);
918 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
919                         struct dt_object *obj, const struct lu_name *cname,
920                         const struct lu_fid *pfid);
921 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
922                           char *name, struct lu_fid *pfid);
923 int lfsck_remove_name_entry(const struct lu_env *env,
924                             struct lfsck_instance *lfsck,
925                             struct dt_object *parent,
926                             const char *name, __u32 type);
927 int lfsck_update_name_entry(const struct lu_env *env,
928                             struct lfsck_instance *lfsck,
929                             struct dt_object *parent, const char *name,
930                             const struct lu_fid *pfid, __u32 type);
931 int lfsck_namespace_setup(const struct lu_env *env,
932                           struct lfsck_instance *lfsck);
933
934 /* lfsck_striped_dir.c */
935 void lfsck_lmv_put(const struct lu_env *env, struct lfsck_lmv *llmv);
936 int lfsck_read_stripe_lmv(const struct lu_env *env, struct dt_object *obj,
937                           struct lmv_mds_md_v1 *lmv);
938 int lfsck_shard_name_to_index(const struct lu_env *env, const char *name,
939                               int namelen, __u16 type,
940                               const struct lu_fid *fid);
941 bool lfsck_is_valid_slave_name_entry(const struct lu_env *env,
942                                      struct lfsck_lmv *llmv,
943                                      const char *name, int namelen);
944 int lfsck_namespace_check_name(const struct lu_env *env,
945                                struct dt_object *parent,
946                                struct dt_object *child,
947                                const struct lu_name *cname);
948 int lfsck_namespace_update_lmv(const struct lu_env *env,
949                                struct lfsck_component *com,
950                                struct dt_object *obj,
951                                struct lmv_mds_md_v1 *lmv, bool locked);
952 int lfsck_namespace_verify_stripe_slave(const struct lu_env *env,
953                                         struct lfsck_component *com,
954                                         struct dt_object *obj,
955                                         struct lfsck_lmv *llmv);
956 int lfsck_namespace_scan_shard(const struct lu_env *env,
957                                struct lfsck_component *com,
958                                struct dt_object *child);
959 int lfsck_namespace_notify_lmv_master_local(const struct lu_env *env,
960                                             struct lfsck_component *com,
961                                             struct dt_object *obj);
962 int lfsck_namespace_repair_bad_name_hash(const struct lu_env *env,
963                                          struct lfsck_component *com,
964                                          struct dt_object *shard,
965                                          struct lfsck_lmv *llmv,
966                                          const char *name);
967 int lfsck_namespace_striped_dir_rescan(const struct lu_env *env,
968                                        struct lfsck_component *com,
969                                        struct lfsck_namespace_req *lnr);
970
971 /* lfsck_layout.c */
972 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
973
974 extern const char dot[];
975 extern const char dotdot[];
976 extern const char *lfsck_flags_names[];
977 extern const char *lfsck_param_names[];
978 extern struct lu_context_key lfsck_thread_key;
979
980 static inline bool name_is_dot_or_dotdot(const char *name, int namelen)
981 {
982         return name[0] == '.' &&
983                (namelen == 1 || (namelen == 2 && name[1] == '.'));
984 }
985
986 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
987 {
988         return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
989 }
990
991 static inline struct lfsck_thread_info *
992 lfsck_env_info(const struct lu_env *env)
993 {
994         struct lfsck_thread_info *info;
995
996         info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
997         LASSERT(info != NULL);
998         return info;
999 }
1000
1001 static inline const struct lu_name *
1002 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
1003 {
1004         struct lu_name *lname;
1005
1006         lname = &lfsck_env_info(env)->lti_name_const;
1007         lname->ln_name = area;
1008         lname->ln_namelen = len;
1009         return lname;
1010 }
1011
1012 static inline void
1013 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
1014 {
1015         buf->lb_buf = area;
1016         buf->lb_len = len;
1017 }
1018
1019 static inline struct lu_buf *
1020 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
1021 {
1022         struct lu_buf *buf;
1023
1024         buf = &lfsck_env_info(env)->lti_buf;
1025         buf->lb_buf = area;
1026         buf->lb_len = len;
1027         return buf;
1028 }
1029
1030 static inline const struct lu_buf *
1031 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
1032 {
1033         struct lu_buf *buf;
1034
1035         buf = &lfsck_env_info(env)->lti_buf;
1036         buf->lb_buf = (void *)area;
1037         buf->lb_len = len;
1038         return buf;
1039 }
1040
1041 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
1042 {
1043         return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
1044 }
1045
1046 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
1047 {
1048         return lu_object_fid(&obj->do_lu);
1049 }
1050
1051 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
1052 {
1053         memset(pos, 0, sizeof(*pos));
1054 }
1055
1056 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
1057 {
1058         return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
1059 }
1060
1061 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
1062                                   const struct lfsck_position *pos2)
1063 {
1064         if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
1065                 return -1;
1066
1067         if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
1068                 return 1;
1069
1070         if (fid_is_zero(&pos1->lp_dir_parent) &&
1071             !fid_is_zero(&pos2->lp_dir_parent))
1072                 return -1;
1073
1074         if (!fid_is_zero(&pos1->lp_dir_parent) &&
1075             fid_is_zero(&pos2->lp_dir_parent))
1076                 return 1;
1077
1078         if (fid_is_zero(&pos1->lp_dir_parent) &&
1079             fid_is_zero(&pos2->lp_dir_parent))
1080                 return 0;
1081
1082         LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
1083
1084         if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
1085                 return -1;
1086
1087         if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
1088                 return 1;
1089
1090         return 0;
1091 }
1092
1093 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
1094                                             struct lfsck_position *src)
1095 {
1096         des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
1097         fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
1098         des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
1099 }
1100
1101 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
1102                                             struct lfsck_position *src)
1103 {
1104         des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
1105         fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
1106         des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
1107 }
1108
1109 static inline umode_t lfsck_object_type(const struct dt_object *obj)
1110 {
1111         return lu_object_attr(&obj->do_lu);
1112 }
1113
1114 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
1115 {
1116         struct lu_object_header *loh = obj->do_lu.lo_header;
1117
1118         return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
1119 }
1120
1121 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
1122 {
1123         lu_object_get(&obj->do_lu);
1124         return obj;
1125 }
1126
1127 static inline void lfsck_object_put(const struct lu_env *env,
1128                                     struct dt_object *obj)
1129 {
1130         lu_object_put(env, &obj->do_lu);
1131 }
1132
1133 static inline u32 lfsck_dev_idx(struct dt_device *dev)
1134 {
1135         return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
1136 }
1137
1138 static inline struct dt_object *
1139 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
1140                                 const struct lu_fid *fid)
1141 {
1142         struct lu_object_conf   *conf = &lfsck_env_info(env)->lti_conf;
1143         struct dt_object        *obj;
1144
1145         conf->loc_flags = LOC_F_NOWAIT;
1146         obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
1147         if (unlikely(obj == NULL))
1148                 return ERR_PTR(-ENOENT);
1149
1150         return obj;
1151 }
1152
1153 static inline struct dt_object *
1154 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
1155                          const struct lu_fid *fid)
1156 {
1157         struct dt_object *obj;
1158
1159         obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
1160         if (unlikely(obj == NULL))
1161                 return ERR_PTR(-ENOENT);
1162
1163         return obj;
1164 }
1165
1166 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
1167                                                   struct lfsck_instance *lfsck,
1168                                                   const struct lu_fid *fid)
1169 {
1170         return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
1171 }
1172
1173 static inline struct dt_object *
1174 lfsck_object_find_bottom(const struct lu_env *env, struct lfsck_instance *lfsck,
1175                          const struct lu_fid *fid)
1176 {
1177         struct dt_device *dev;
1178         int               idx;
1179
1180         idx = lfsck_find_mdt_idx_by_fid(env, lfsck, fid);
1181         if (idx < 0)
1182                 return ERR_PTR(idx);
1183
1184         if (idx == lfsck_dev_idx(lfsck->li_bottom)) {
1185                 dev = lfsck->li_bottom;
1186         } else {
1187                 struct lfsck_tgt_desc *ltd;
1188
1189                 ltd = LTD_TGT(&lfsck->li_mdt_descs, idx);
1190                 if (unlikely(ltd == NULL))
1191                         return ERR_PTR(-ENODEV);
1192
1193                 dev = ltd->ltd_tgt;
1194         }
1195
1196         return lfsck_object_find_by_dev(env, dev, fid);
1197 }
1198
1199 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
1200                                                    __u32 index)
1201 {
1202         struct lfsck_tgt_desc *ltd;
1203
1204         ltd = LTD_TGT(ltds, index);
1205         if (ltd != NULL)
1206                 atomic_inc(&ltd->ltd_ref);
1207
1208         return ltd;
1209 }
1210
1211 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
1212 {
1213         if (atomic_dec_and_test(&ltd->ltd_ref))
1214                 OBD_FREE_PTR(ltd);
1215 }
1216
1217 static inline struct lfsck_component *
1218 lfsck_component_get(struct lfsck_component *com)
1219 {
1220         atomic_inc(&com->lc_ref);
1221
1222         return com;
1223 }
1224
1225 static inline void lfsck_component_put(const struct lu_env *env,
1226                                        struct lfsck_component *com)
1227 {
1228         if (atomic_dec_and_test(&com->lc_ref)) {
1229                 if (com->lc_obj != NULL)
1230                         lu_object_put_nocache(env, &com->lc_obj->do_lu);
1231                 if (com->lc_file_ram != NULL)
1232                         OBD_FREE(com->lc_file_ram, com->lc_file_size);
1233                 if (com->lc_file_disk != NULL)
1234                         OBD_FREE(com->lc_file_disk, com->lc_file_size);
1235                 if (com->lc_data != NULL) {
1236                         LASSERT(com->lc_ops->lfsck_data_release != NULL);
1237
1238                         com->lc_ops->lfsck_data_release(env, com);
1239                 }
1240
1241                 OBD_FREE_PTR(com);
1242         }
1243 }
1244
1245 static inline struct lfsck_instance *
1246 lfsck_instance_get(struct lfsck_instance *lfsck)
1247 {
1248         atomic_inc(&lfsck->li_ref);
1249
1250         return lfsck;
1251 }
1252
1253 static inline void lfsck_instance_put(const struct lu_env *env,
1254                                       struct lfsck_instance *lfsck)
1255 {
1256         if (atomic_dec_and_test(&lfsck->li_ref))
1257                 lfsck_instance_cleanup(env, lfsck);
1258 }
1259
1260 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1261 {
1262         return list_empty(&lad->lad_mdt_phase1_list) &&
1263                (!list_empty(&lad->lad_ost_phase2_list) ||
1264                 list_empty(&lad->lad_ost_phase1_list));
1265 }
1266
1267 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1268                                         struct lfsck_component *com,
1269                                         __u32 index)
1270 {
1271         struct lfsck_assistant_data     *lad    = com->lc_data;
1272         cfs_bitmap_t                    *bitmap = lad->lad_bitmap;
1273
1274         LASSERT(com->lc_lfsck->li_master);
1275         LASSERT(bitmap != NULL);
1276
1277         if (likely(bitmap->size > index)) {
1278                 cfs_bitmap_set(bitmap, index);
1279                 lad->lad_incomplete = 1;
1280         } else if (com->lc_type == LFSCK_TYPE_NAMESPACE) {
1281                 struct lfsck_namespace *ns = com->lc_file_ram;
1282
1283                 ns->ln_flags |= LF_INCOMPLETE;
1284         }
1285 }
1286
1287 static inline int lfsck_links_read(const struct lu_env *env,
1288                                    struct dt_object *obj,
1289                                    struct linkea_data *ldata)
1290 {
1291         ldata->ld_buf =
1292                 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1293                                        PAGE_CACHE_SIZE);
1294
1295         return __lfsck_links_read(env, obj, ldata);
1296 }
1297
1298 static inline int lfsck_links_read2(const struct lu_env *env,
1299                                     struct dt_object *obj,
1300                                     struct linkea_data *ldata)
1301 {
1302         ldata->ld_buf =
1303                 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1304                                        PAGE_CACHE_SIZE);
1305
1306         return __lfsck_links_read(env, obj, ldata);
1307 }
1308
1309 static inline struct lfsck_lmv *lfsck_lmv_get(struct lfsck_lmv *llmv)
1310 {
1311         if (llmv != NULL)
1312                 atomic_inc(&llmv->ll_ref);
1313
1314         return llmv;
1315 }
1316
1317 static inline void lfsck_lmv_header_le_to_cpu(struct lmv_mds_md_v1 *dst,
1318                                               const struct lmv_mds_md_v1 *src)
1319 {
1320         dst->lmv_magic = le32_to_cpu(src->lmv_magic);
1321         dst->lmv_stripe_count = le32_to_cpu(src->lmv_stripe_count);
1322         dst->lmv_master_mdt_index = le32_to_cpu(src->lmv_master_mdt_index);
1323         dst->lmv_hash_type = le32_to_cpu(src->lmv_hash_type);
1324         dst->lmv_layout_version = le32_to_cpu(src->lmv_layout_version);
1325 }
1326
1327 static inline void lfsck_lmv_header_cpu_to_le(struct lmv_mds_md_v1 *dst,
1328                                               const struct lmv_mds_md_v1 *src)
1329 {
1330         dst->lmv_magic = cpu_to_le32(src->lmv_magic);
1331         dst->lmv_stripe_count = cpu_to_le32(src->lmv_stripe_count);
1332         dst->lmv_master_mdt_index = cpu_to_le32(src->lmv_master_mdt_index);
1333         dst->lmv_hash_type = cpu_to_le32(src->lmv_hash_type);
1334         dst->lmv_layout_version = cpu_to_le32(src->lmv_layout_version);
1335 }
1336 #endif /* _LFSCK_INTERNAL_H */