4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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.
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
23 * Copyright (c) 2013, 2017, Intel Corporation.
26 * lustre/lfsck/lfsck_internal.h
28 * Shared definitions and declarations for the LFSCK.
30 * Author: Fan, Yong <fan.yong@intel.com>
33 #ifndef _LFSCK_INTERNAL_H
34 # define _LFSCK_INTERNAL_H
36 #include <lustre_lfsck.h>
38 #include <lu_object.h>
39 #include <dt_object.h>
40 #include <md_object.h>
41 #include <lustre_net.h>
42 #include <lustre_dlm.h>
43 #include <lustre_fid.h>
44 #include <md_object.h>
45 #include <lustre_linkea.h>
47 #define LFSCK_CHECKPOINT_INTERVAL 60
50 /* Finish the first cycle scanning. */
51 LF_SCANNED_ONCE = 0x00000001ULL,
53 /* There is some namespace inconsistency. */
54 LF_INCONSISTENT = 0x00000002ULL,
56 /* The device is upgraded from 1.8 format. */
57 LF_UPGRADE = 0x00000004ULL,
59 /* The server ever restarted during the LFSCK, and may miss to process
60 * some objects check/repair. */
61 LF_INCOMPLETE = 0x00000008ULL,
63 /* The LAST_ID (file) crashed. */
64 LF_CRASHED_LASTID = 0x00000010ULL,
67 struct lfsck_position {
68 /* low layer object table-based iteration position. */
71 /* parent FID for directory traversal. */
72 struct lu_fid lp_dir_parent;
74 /* namespace-based directory traversal position. */
78 struct lfsck_bookmark {
79 /* Magic number to detect that this struct contains valid data. */
82 /* For compatible with old versions. */
85 /* See 'enum lfsck_param_flags' */
88 /* How many items can be scanned at most per second. */
91 /* The windows size for async requests pipeline. */
92 __u16 lb_async_windows;
94 /* For 64-bits aligned. */
97 /* The FID for .lustre/lost+found/MDTxxxx */
98 struct lu_fid lb_lpf_fid;
100 /* The FID for the last MDT-object created by the LFSCK repairing. */
101 struct lu_fid lb_last_fid;
103 /* For future using. */
104 __u64 lb_reserved[2];
107 enum lfsck_namespace_trace_flags {
108 LNTF_CHECK_LINKEA = 0x01,
109 LNTF_CHECK_PARENT = 0x02,
110 LNTF_CHECK_ORPHAN = 0x08,
111 LNTF_UNCERTAIN_LMV = 0x10,
112 LNTF_RECHECK_NAME_HASH = 0x20,
113 LNTF_CHECK_AGENT_ENTRY = 0x40,
117 enum lfsck_namespace_inconsistency_type {
120 LNIT_UNMATCHED_PAIRS = 2,
127 struct lfsck_namespace {
128 /* Magic number to detect that this struct contains valid data. */
131 /* See 'enum lfsck_status'. */
134 /* See 'enum lfsck_flags'. */
137 /* How many completed LFSCK runs on the device. */
138 __u32 ln_success_count;
140 /* How long the LFSCK phase1 has run in seconds. */
141 time64_t ln_run_time_phase1;
143 /* How long the LFSCK phase2 has run in seconds. */
144 time64_t ln_run_time_phase2;
146 /* Time for the last LFSCK completed in seconds since epoch. */
147 time64_t ln_time_last_complete;
149 /* Time for the latest LFSCK ran in seconds since epoch. */
150 time64_t ln_time_latest_start;
152 /* Time for the last LFSCK checkpoint in seconds since epoch. */
153 time64_t ln_time_last_checkpoint;
155 /* Position for the latest LFSCK started from. */
156 struct lfsck_position ln_pos_latest_start;
158 /* Position for the last LFSCK checkpoint. */
159 struct lfsck_position ln_pos_last_checkpoint;
161 /* Position for the first should be updated object. */
162 struct lfsck_position ln_pos_first_inconsistent;
164 /* How many items (including dir) have been checked. */
165 __u64 ln_items_checked;
167 /* How many items have been repaired. */
168 __u64 ln_items_repaired;
170 /* How many items failed to be processed. */
171 __u64 ln_items_failed;
173 /* How many directories have been traversed. */
174 __u64 ln_dirs_checked;
176 /* How many objects have been double scanned. */
177 __u64 ln_objs_checked_phase2;
179 /* How many objects have been reparied during double scan. */
180 __u64 ln_objs_repaired_phase2;
182 /* How many objects failed to be processed during double scan. */
183 __u64 ln_objs_failed_phase2;
185 /* How many objects with nlink fixed. */
186 __u64 ln_objs_nlink_repaired;
188 /* The latest object has been processed (failed) during double scan. */
189 struct lu_fid ln_fid_latest_scanned_phase2;
191 /* How many FID-in-dirent entries have been repaired. */
192 __u64 ln_dirent_repaired;
194 /* How many linkEA entries have been repaired. */
195 __u64 ln_linkea_repaired;
197 /* How many multiple-linked objects have been checked. */
198 __u64 ln_mul_linked_checked;
200 /* How many multiple-linked objects have been repaired. */
201 __u64 ln_mul_linked_repaired;
203 /* How many undefined inconsistency found in phase2. */
204 __u64 ln_unknown_inconsistency;
206 /* How many unmatched pairs have been repaired. */
207 __u64 ln_unmatched_pairs_repaired;
209 /* How many dangling name entries have been found/repaired. */
210 __u64 ln_dangling_repaired;
212 /* How many multiple referenced name entries have been
214 __u64 ln_mul_ref_repaired;
216 /* How many name entries with bad file type have been repaired. */
217 __u64 ln_bad_type_repaired;
219 /* How many lost name entries have been re-inserted. */
220 __u64 ln_lost_dirent_repaired;
222 /* How many objects under /lost+found have been scanned. */
223 __u64 ln_local_lpf_scanned;
225 /* How many objects under /lost+found have been moved to
226 * namespace visible directory. */
227 __u64 ln_local_lpf_moved;
229 /* How many objects under /lost+found have been skipped. */
230 __u64 ln_local_lpf_skipped;
232 /* How many objects under /lost+found failed to be processed. */
233 __u64 ln_local_lpf_failed;
235 /* How many striped directories (master) have been scanned. */
236 __u64 ln_striped_dirs_scanned;
238 /* How many striped directories (master) have been repaired. */
239 __u64 ln_striped_dirs_repaired;
241 /* How many striped directories (master) failed verification. */
242 __u64 ln_striped_dirs_failed;
244 /* How many striped directories (master) has been disabled. */
245 __u64 ln_striped_dirs_disabled;
247 /* How many striped directory's (master) have been skipped
248 * (for shards verification) because of lost master LMV EA. */
249 __u64 ln_striped_dirs_skipped;
251 /* How many striped directory's shards (slave) have been scanned. */
252 __u64 ln_striped_shards_scanned;
254 /* How many striped directory's shards (slave) have been repaired. */
255 __u64 ln_striped_shards_repaired;
257 /* How many striped directory's shards (slave) failed verification. */
258 __u64 ln_striped_shards_failed;
260 /* How many striped directory's shards (slave) have been skipped
261 * (for name hash verification) because do not know whether the slave
262 * LMV EA is valid or not. */
263 __u64 ln_striped_shards_skipped;
265 /* How many name entries under striped directory with bad name
266 * hash have been repaired. */
267 __u64 ln_name_hash_repaired;
269 /* The size of MDT targets bitmap with nbits. Such bitmap records
270 * the MDTs that contain non-verified MDT-objects. */
271 __u32 ln_bitmap_size;
273 /* For further using. 256-bytes aligned now. */
276 /* Time for the latest LFSCK scan in seconds from the beginning. */
277 time64_t ln_time_latest_reset;
279 /* How many linkEA overflow timestamp have been cleared. */
280 __u64 ln_linkea_overflow_cleared;
282 /* How many agent entries have been repaired. */
283 __u64 ln_agent_entries_repaired;
285 /* For further using. 256-bytes aligned now. */
286 __u64 ln_reserved[11];
289 enum lfsck_layout_inconsistency_type {
292 LLIT_UNMATCHED_PAIR = 2,
293 LLIT_MULTIPLE_REFERENCED = 3,
295 LLIT_INCONSISTENT_OWNER = 5,
297 LLIT_MAX = LLIT_OTHERS
300 struct lfsck_layout {
301 /* Magic number to detect that this struct contains valid data. */
304 /* See 'enum lfsck_status'. */
307 /* See 'enum lfsck_flags'. */
310 /* How many completed LFSCK runs on the device. */
311 __u32 ll_success_count;
313 /* How long the LFSCK phase1 has run in seconds. */
314 time64_t ll_run_time_phase1;
316 /* How long the LFSCK phase2 has run in seconds. */
317 time64_t ll_run_time_phase2;
319 /* Time for the last LFSCK completed in seconds since epoch. */
320 time64_t ll_time_last_complete;
322 /* Time for the latest LFSCK ran in seconds since epoch. */
323 time64_t ll_time_latest_start;
325 /* Time for the last LFSCK checkpoint in seconds since epoch. */
326 time64_t ll_time_last_checkpoint;
328 /* Position for the latest LFSCK started from. */
329 __u64 ll_pos_latest_start;
331 /* Position for the last LFSCK checkpoint. */
332 __u64 ll_pos_last_checkpoint;
334 /* Position for the first object to be fixed or
335 * failed to be checked in the phase1. */
336 __u64 ll_pos_first_inconsistent;
338 /* How many objects have been checked. */
339 __u64 ll_objs_checked_phase1;
341 /* How many objects failed to be processed. */
342 __u64 ll_objs_failed_phase1;
344 /* How many objects have been double scanned. */
345 __u64 ll_objs_checked_phase2;
347 /* How many objects failed to be processed during double scan. */
348 __u64 ll_objs_failed_phase2;
350 /* kinds of inconsistency have been or to be repaired.
351 * ll_objs_repaired[type - 1] is the count for the given @type. */
352 __u64 ll_objs_repaired[LLIT_MAX];
354 /* How many objects have been skipped because of related
355 * MDT(s)/OST(s) do not participate in the LFSCK */
356 __u64 ll_objs_skipped;
358 /* The size of ll_ost_bitmap with nbits. */
359 __u32 ll_bitmap_size;
361 /* For further using. 256-bytes aligned now. */
364 /* The latest object has been processed (failed) during double scan. */
365 struct lfsck_layout_dangling_key ll_lldk_latest_scanned_phase2;
367 /* For further using */
368 u64 ll_reserved_2[7];
370 /* The OST targets bitmap to record the OSTs that contain
371 * non-verified OST-objects. */
372 __u8 ll_ost_bitmap[0];
375 struct lfsck_assistant_object {
376 struct lu_fid lso_fid;
377 __u64 lso_oit_cookie;
378 struct lu_attr lso_attr;
380 unsigned int lso_dead:1,
384 struct lfsck_component;
385 struct lfsck_tgt_descs;
386 struct lfsck_tgt_desc;
388 struct lfsck_operations {
389 int (*lfsck_reset)(const struct lu_env *env,
390 struct lfsck_component *com,
393 void (*lfsck_fail)(const struct lu_env *env,
394 struct lfsck_component *com,
397 void (*lfsck_close_dir)(const struct lu_env *env,
398 struct lfsck_component *com);
400 int (*lfsck_open_dir)(const struct lu_env *env,
401 struct lfsck_component *com);
403 int (*lfsck_checkpoint)(const struct lu_env *env,
404 struct lfsck_component *com,
407 int (*lfsck_prep)(const struct lu_env *env,
408 struct lfsck_component *com,
409 struct lfsck_start_param *lsp);
411 int (*lfsck_exec_oit)(const struct lu_env *env,
412 struct lfsck_component *com,
413 struct dt_object *obj);
415 int (*lfsck_exec_dir)(const struct lu_env *env,
416 struct lfsck_component *com,
417 struct lfsck_assistant_object *lso,
418 struct lu_dirent *ent,
421 int (*lfsck_post)(const struct lu_env *env,
422 struct lfsck_component *com,
426 void (*lfsck_dump)(const struct lu_env *env,
427 struct lfsck_component *com,
430 int (*lfsck_double_scan)(const struct lu_env *env,
431 struct lfsck_component *com);
433 void (*lfsck_data_release)(const struct lu_env *env,
434 struct lfsck_component *com);
436 void (*lfsck_quit)(const struct lu_env *env,
437 struct lfsck_component *com);
439 int (*lfsck_in_notify_local)(const struct lu_env *env,
440 struct lfsck_component *com,
441 struct lfsck_req_local *lrl,
444 int (*lfsck_in_notify)(const struct lu_env *env,
445 struct lfsck_component *com,
446 struct lfsck_request *lr);
448 int (*lfsck_query)(const struct lu_env *env,
449 struct lfsck_component *com,
450 struct lfsck_request *req,
451 struct lfsck_reply *rep,
452 struct lfsck_query *que, int idx);
454 int (*lfsck_join)(const struct lu_env *env,
455 struct lfsck_component *com,
456 struct lfsck_start_param *lsp);
459 struct lfsck_tgt_desc {
460 struct list_head ltd_orphan_list;
461 struct dt_device *ltd_tgt;
462 struct dt_device *ltd_key;
463 struct obd_export *ltd_exp;
464 struct list_head ltd_layout_list;
465 struct list_head ltd_layout_phase_list;
466 struct list_head ltd_namespace_list;
467 struct list_head ltd_namespace_phase_list;
468 __u32 ltd_layout_status;
469 __u32 ltd_namespace_status;
470 __u64 ltd_layout_repaired;
471 __u64 ltd_namespace_repaired;
474 __u32 ltd_layout_gen;
475 __u32 ltd_namespace_gen;
476 unsigned int ltd_dead:1,
479 ltd_namespace_done:1,
480 ltd_synced_failures:1;
483 struct lfsck_tgt_desc_idx {
484 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
487 struct lfsck_tgt_descs {
488 /* list of known TGTs */
489 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
491 /* bitmap of TGTs available */
492 unsigned long *ltd_tgts_bitmap;
493 u32 ltd_tgts_mask_len;
495 /* for lfsck_tgt_desc::ltd_xxx_list */
498 /* for tgts table accessing and changes */
499 struct rw_semaphore ltd_rw_sem;
501 /* Temporary list for orphan targets. */
502 struct list_head ltd_orphan;
504 /* number of registered TGTs */
508 static inline struct lfsck_tgt_desc *
509 lfsck_ltd2tgt(struct lfsck_tgt_descs *ltd, __u32 index)
511 __u32 idx1 = index / TGT_PTRS_PER_BLOCK;
512 __u32 idx2 = index % TGT_PTRS_PER_BLOCK;
513 struct lfsck_tgt_desc *__tgt = NULL;
515 if (unlikely(idx1 >= TGT_PTRS))
516 CDEBUG(D_LFSCK, "The target idx %u is invalid.\n", index);
517 else if (likely(ltd->ltd_tgts_idx[idx1] != NULL))
518 __tgt = ltd->ltd_tgts_idx[idx1]->ldi_tgts[idx2];
523 static inline void lfsck_assign_tgt(struct lfsck_tgt_descs *ltd,
524 struct lfsck_tgt_desc *tgt, __u32 index)
526 __u32 idx1 = index / TGT_PTRS_PER_BLOCK;
527 __u32 idx2 = index % TGT_PTRS_PER_BLOCK;
529 if (likely(idx1 < TGT_PTRS && ltd->ltd_tgts_idx[idx1] != NULL))
530 ltd->ltd_tgts_idx[idx1]->ldi_tgts[idx2] = tgt;
533 #define LFSCK_STF_BITS 4
534 /* If want to adjust the LFSCK_STF_COUNT, please change LFSCK_STF_BITS. */
535 #define LFSCK_STF_COUNT (1 << LFSCK_STF_BITS)
537 struct lfsck_sub_trace_obj {
538 struct dt_object *lsto_obj;
539 struct mutex lsto_mutex;
542 struct lfsck_component {
543 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
544 struct list_head lc_link;
546 /* into lfsck_instance::li_list_dir */
547 struct list_head lc_link_dir;
549 struct rw_semaphore lc_sem;
552 struct lfsck_position lc_pos_start;
553 struct lfsck_instance *lc_lfsck;
554 struct dt_object *lc_obj;
555 struct lfsck_sub_trace_obj lc_sub_trace_objs[LFSCK_STF_COUNT];
556 const struct lfsck_operations *lc_ops;
560 struct lu_fid lc_fid_latest_scanned_phase2;
562 /* The time for last checkpoint, seconds */
563 time64_t lc_time_last_checkpoint;
565 /* The time for next checkpoint, seconds */
566 time64_t lc_time_next_checkpoint;
570 /* How many objects have been checked since last checkpoint. */
571 __u32 lc_new_checked;
573 /* How many objects have been scanned since last sleep. */
574 __u32 lc_new_scanned;
579 #define LFSCK_LMV_MAX_STRIPES LMV_MAX_STRIPE_COUNT
580 #define LFSCK_LMV_DEF_STRIPES 4
582 /* Warning: NOT change the lfsck_slave_lmv_flags members order,
583 * otherwise the lfsck_record_lmv() may be wrong. */
584 enum lfsck_slave_lmv_flags {
592 /* When the namespace LFSCK scans a striped directory, it will record all
593 * the known shards' information in the structure "lfsck_slave_lmv_rec",
594 * including the shard's FID, index, slave LMV EA, and so on. Each shard
595 * will take one lfsck_slave_lmv_rec slot. After the 1st cycle scanning
596 * the striped directory, the LFSCK will get all the information about
597 * whether there are some inconsistency, and then it can repair them in
598 * the 2nd cycle scanning. */
599 struct lfsck_slave_lmv_rec {
600 struct lu_fid lslr_fid;
601 __u32 lslr_stripe_count;
602 __u32 lslr_index; /* the index in name or in slave lmv */
603 __u32 lslr_hash_type;
608 struct lmv_mds_md_v1 ll_lmv;
610 int ll_stripes_allocated;
611 int ll_stripes_filled;
613 __u32 ll_max_stripe_count;
614 __u32 ll_max_filled_off;
616 unsigned int ll_lmv_master:1,
624 struct lfsck_slave_lmv_rec *ll_lslr; /* may be vmalloc'd */
627 /* If the namespace LFSCK finds that the master MDT-object of a striped
628 * directory lost its master LMV EA, it will re-generate the master LMV
629 * EA and notify the LFSCK instance on the MDT on which the striped dir
630 * master MDT-object resides to rescan the striped directory. To do that,
631 * the notify handler will insert a "lfsck_lmv_unit" structure into the
632 * lfsck::li_list_lmv. The LFSCK instance will scan such list from time
633 * to time to check whether needs to rescan some stirped directories. */
634 struct lfsck_lmv_unit {
635 struct list_head llu_link;
636 struct lfsck_lmv llu_lmv;
637 struct dt_object *llu_obj;
638 struct lfsck_instance *llu_lfsck;
641 struct lfsck_rec_lmv_save {
642 struct lu_fid lrls_fid;
643 struct lmv_mds_md_v1 lrls_lmv;
646 /* Allow lfsck_record_lmv() to be called recursively at most three times. */
647 #define LFSCK_REC_LMV_MAX_DEPTH 3
649 struct lfsck_instance {
650 struct mutex li_mutex;
653 /* Link into the lfsck_instance_list. */
654 struct list_head li_link;
656 /* For the components in (first) scanning via otable-based iteration. */
657 struct list_head li_list_scan;
659 /* For the components in scanning via directory traversal. Because
660 * directory traversal cannot guarantee all the object be scanned,
661 * so the component in the li_list_dir must be in li_list_scan. */
662 struct list_head li_list_dir;
664 /* For the components in double scanning. */
665 struct list_head li_list_double_scan;
667 /* For the components those are not scanning now. */
668 struct list_head li_list_idle;
670 /* For the lfsck_lmv_unit to be handled. */
671 struct list_head li_list_lmv;
674 atomic_t li_double_scan_count;
675 struct ptlrpc_thread li_thread;
676 struct task_struct *li_task;
678 /* The time for last checkpoint, seconds */
679 time64_t li_time_last_checkpoint;
681 /* The time for next checkpoint, seconds */
682 time64_t li_time_next_checkpoint;
684 lfsck_out_notify li_out_notify;
685 void *li_out_notify_data;
686 struct dt_device *li_next;
687 struct dt_device *li_bottom;
688 struct obd_device *li_obd;
689 struct ldlm_namespace *li_namespace;
690 struct local_oid_storage *li_los;
691 struct lu_fid li_local_root_fid; /* backend root "/" */
692 struct lu_fid li_global_root_fid; /* /ROOT */
693 struct dt_object *li_lfsck_dir;
694 struct dt_object *li_bookmark_obj;
695 struct dt_object *li_lpf_obj;
696 struct dt_object *li_lpf_root_obj;
697 struct lu_client_seq *li_seq;
698 struct lfsck_bookmark li_bookmark_ram;
699 struct lfsck_bookmark li_bookmark_disk;
700 struct lfsck_position li_pos_current;
701 struct lfsck_position li_pos_checkpoint;
703 struct lfsck_lmv *li_lmv;
705 /* Obj for otable-based iteration */
706 struct dt_object *li_obj_oit;
708 /* Obj for directory traversal */
709 struct dt_object *li_obj_dir;
711 /* It for otable-based iteration */
712 struct dt_it *li_di_oit;
714 /* It for directory traversal */
715 struct dt_it *li_di_dir;
717 /* Description of OST */
718 struct lfsck_tgt_descs li_ost_descs;
720 /* Description of MDT */
721 struct lfsck_tgt_descs li_mdt_descs;
723 /* namespace-based directory traversal position. */
726 /* Arguments for low layer otable-based iteration. */
729 /* Arugments for namespace-based directory traversal. */
732 /* Schedule for every N objects. */
735 /* Sleep N jiffies for each schedule. */
738 /* How many objects have been scanned since last sleep. */
739 __u32 li_new_scanned;
741 /* The status when the LFSCK stopped or paused. */
744 /* The flags when the lFSCK stopped or paused. */
747 unsigned int li_oit_over:1, /* oit is finished. */
748 li_drop_dryrun:1, /* Ever dryrun, not now. */
749 li_master:1, /* Master instance or not. */
750 li_current_oit_processed:1,
753 struct lfsck_rec_lmv_save li_rec_lmv_save[LFSCK_REC_LMV_MAX_DEPTH];
756 static inline bool lfsck_is_dryrun(struct lfsck_instance *lfsck)
758 return lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN;
761 struct lfsck_async_interpret_args {
762 struct lfsck_component *laia_com;
763 struct lfsck_tgt_descs *laia_ltds;
764 struct lfsck_tgt_desc *laia_ltd;
765 struct lfsck_request *laia_lr;
766 atomic_t *laia_count;
768 unsigned int laia_shared:1;
771 struct lfsck_thread_args {
772 struct lu_env lta_env;
773 struct lfsck_instance *lta_lfsck;
774 struct lfsck_component *lta_com;
775 struct lfsck_start_param *lta_lsp;
778 struct lfsck_assistant_req {
779 struct list_head lar_list;
780 struct lfsck_assistant_object *lar_parent;
783 struct lfsck_namespace_req {
784 struct lfsck_assistant_req lnr_lar;
785 struct lfsck_lmv *lnr_lmv;
786 struct lu_fid lnr_fid;
787 __u64 lnr_dir_cookie;
795 struct lfsck_layout_req {
796 struct lfsck_assistant_req llr_lar;
797 struct dt_object *llr_child;
800 __u32 llr_lov_idx; /* offset in LOV EA */
803 struct lfsck_assistant_operations {
804 int (*la_handler_p1)(const struct lu_env *env,
805 struct lfsck_component *com,
806 struct lfsck_assistant_req *lar);
808 int (*la_handler_p2)(const struct lu_env *env,
809 struct lfsck_component *com);
811 void (*la_fill_pos)(const struct lu_env *env,
812 struct lfsck_component *com,
813 struct lfsck_position *pos);
815 int (*la_double_scan_result)(const struct lu_env *env,
816 struct lfsck_component *com,
819 void (*la_req_fini)(const struct lu_env *env,
820 struct lfsck_assistant_req *lar);
822 void (*la_sync_failures)(const struct lu_env *env,
823 struct lfsck_component *com,
824 struct lfsck_request *lr);
827 struct lfsck_assistant_data {
829 struct list_head lad_req_list;
831 /* list for the ost targets involve LFSCK. */
832 struct list_head lad_ost_list;
834 /* list for the ost targets in phase1 scanning. */
835 struct list_head lad_ost_phase1_list;
837 /* list for the ost targets in phase2 scanning. */
838 struct list_head lad_ost_phase2_list;
840 /* list for the mdt targets involve LFSCK. */
841 struct list_head lad_mdt_list;
843 /* list for the mdt targets in phase1 scanning. */
844 struct list_head lad_mdt_phase1_list;
846 /* list for the mdt targets in phase2 scanning. */
847 struct list_head lad_mdt_phase2_list;
849 const char *lad_name;
850 struct ptlrpc_thread lad_thread;
851 struct task_struct *lad_task;
853 const struct lfsck_assistant_operations *lad_ops;
855 unsigned long *lad_bitmap;
856 unsigned int lad_bitmap_count;
860 int lad_assistant_status;
862 unsigned long lad_flags;
863 bool lad_advance_lock;
867 LAD_TO_DOUBLE_SCAN = 1,
868 LAD_IN_DOUBLE_SCAN = 2,
873 #define LFSCK_TMPBUF_LEN 64
875 struct lfsck_lock_handle {
876 struct lustre_handle llh_pdo_lh;
877 struct lustre_handle llh_reg_lh;
878 enum ldlm_mode llh_pdo_mode;
879 enum ldlm_mode llh_reg_mode;
882 struct lfsck_thread_info {
883 struct lu_name lti_name_const;
884 struct lu_name lti_name;
885 struct lu_name lti_name2;
886 struct lu_buf lti_buf;
887 struct lu_buf lti_linkea_buf;
888 struct lu_buf lti_linkea_buf2;
889 struct lu_buf lti_big_buf;
890 struct lu_fid lti_fid;
891 struct lu_fid lti_fid2;
892 struct lu_fid lti_fid3;
893 struct lu_fid lti_fid4;
894 struct lu_attr lti_la;
895 struct lu_attr lti_la2;
896 struct ost_id lti_oi;
897 struct lustre_ost_attrs lti_loa;
898 struct dt_object_format lti_dof;
899 /* There will be '\0' at the end of the name. */
900 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
901 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
902 char lti_tmpbuf2[LFSCK_TMPBUF_LEN];
903 struct lfsck_request lti_lr;
904 struct lfsck_async_interpret_args lti_laia;
905 struct lfsck_async_interpret_args lti_laia2;
906 struct lfsck_start lti_start;
907 struct lfsck_stop lti_stop;
908 union ldlm_policy_data lti_policy;
909 struct ldlm_enqueue_info lti_einfo;
910 struct ldlm_res_id lti_resid;
911 struct filter_fid lti_ff;
912 struct dt_allocation_hint lti_hint;
913 struct lu_orphan_rec_v3 lti_rec;
914 struct lov_user_md lti_lum;
915 struct dt_insert_rec lti_dt_rec;
916 struct lu_object_conf lti_conf;
917 struct lu_seq_range lti_range;
918 struct lmv_mds_md_v1 lti_lmv;
919 struct lmv_mds_md_v1 lti_lmv2;
920 struct lmv_mds_md_v1 lti_lmv3;
921 struct lmv_mds_md_v1 lti_lmv4;
922 struct lfsck_lock_handle lti_llh;
923 struct lfsck_layout_dangling_key lti_lldk;
927 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
928 struct lu_fid *fid, bool locked);
929 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
930 struct dt_object *obj, struct lustre_handle *lh,
931 __u64 bits, enum ldlm_mode mode);
932 void lfsck_ibits_unlock(struct lustre_handle *lh, enum ldlm_mode mode);
933 int lfsck_remote_lookup_lock(const struct lu_env *env,
934 struct lfsck_instance *lfsck,
935 struct dt_object *pobj, struct dt_object *obj,
936 struct lustre_handle *lh, enum ldlm_mode mode);
937 int lfsck_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
938 struct dt_object *obj, const char *name,
939 struct lfsck_lock_handle *llh, __u64 bits, enum ldlm_mode mode);
940 void lfsck_unlock(struct lfsck_lock_handle *llh);
941 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
942 struct lfsck_instance *lfsck,
943 const struct lu_fid *fid);
944 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
945 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
947 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
949 void lfsck_component_cleanup(const struct lu_env *env,
950 struct lfsck_component *com);
951 void lfsck_instance_cleanup(const struct lu_env *env,
952 struct lfsck_instance *lfsck);
953 void lfsck_bits_dump(struct seq_file *m, int bits, const char *const names[],
955 void lfsck_time_dump(struct seq_file *m, time64_t time, const char *name);
956 void lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
958 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
959 struct lfsck_position *pos, bool init);
960 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
961 void lfsck_control_speed(struct lfsck_instance *lfsck);
962 void lfsck_control_speed_by_self(struct lfsck_component *com);
963 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
964 struct lfsck_assistant_data *
965 lfsck_assistant_data_init(const struct lfsck_assistant_operations *lao,
967 struct lfsck_assistant_object *
968 lfsck_assistant_object_init(const struct lu_env *env, const struct lu_fid *fid,
969 const struct lu_attr *attr, __u64 cookie,
972 lfsck_assistant_object_load(const struct lu_env *env,
973 struct lfsck_instance *lfsck,
974 struct lfsck_assistant_object *lso);
975 int lfsck_async_interpret_common(const struct lu_env *env,
976 struct ptlrpc_request *req,
978 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
979 struct lfsck_request *lr,
980 struct ptlrpc_request_set *set,
981 ptlrpc_interpterer_t interpterer,
982 void *args, int request);
983 int lfsck_query_all(const struct lu_env *env, struct lfsck_component *com);
984 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
985 struct lfsck_start_param *lsp);
986 int lfsck_checkpoint_generic(const struct lu_env *env,
987 struct lfsck_component *com);
988 void lfsck_post_generic(const struct lu_env *env,
989 struct lfsck_component *com, int *result);
990 int lfsck_double_scan_generic(const struct lu_env *env,
991 struct lfsck_component *com, int status);
992 void lfsck_quit_generic(const struct lu_env *env,
993 struct lfsck_component *com);
994 int lfsck_load_one_trace_file(const struct lu_env *env,
995 struct lfsck_component *com,
996 struct dt_object *parent,
997 struct dt_object **child,
998 const struct dt_index_features *ft,
999 const char *name, bool reset);
1000 int lfsck_load_sub_trace_files(const struct lu_env *env,
1001 struct lfsck_component *com,
1002 const struct dt_index_features *ft,
1003 const char *prefix, bool reset);
1005 /* lfsck_engine.c */
1006 int lfsck_unpack_ent(struct lu_dirent *ent, __u64 *cookie, __u16 *type);
1007 void lfsck_close_dir(const struct lu_env *env,
1008 struct lfsck_instance *lfsck, int result);
1009 int lfsck_open_dir(const struct lu_env *env,
1010 struct lfsck_instance *lfsck, __u64 cookie);
1011 int lfsck_master_engine(void *args);
1012 int lfsck_assistant_engine(void *args);
1014 /* lfsck_bookmark.c */
1015 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
1016 struct lfsck_bookmark *src);
1017 int lfsck_bookmark_store(const struct lu_env *env,
1018 struct lfsck_instance *lfsck);
1019 int lfsck_bookmark_setup(const struct lu_env *env,
1020 struct lfsck_instance *lfsck);
1021 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
1022 struct lfsck_start *start, bool reset);
1024 /* lfsck_namespace.c */
1025 int lfsck_namespace_trace_update(const struct lu_env *env,
1026 struct lfsck_component *com,
1027 const struct lu_fid *fid,
1028 const __u8 flags, bool add);
1029 int lfsck_namespace_check_exist(const struct lu_env *env,
1030 struct dt_object *dir,
1031 struct dt_object *obj, const char *name);
1032 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
1033 struct linkea_data *ldata, bool with_rec);
1034 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
1035 struct lfsck_component *com,
1036 struct dt_object *obj,
1037 struct linkea_data *ldata);
1038 int lfsck_namespace_repair_dangling(const struct lu_env *env,
1039 struct lfsck_component *com,
1040 struct dt_object *parent,
1041 struct dt_object *child,
1042 struct lfsck_namespace_req *lnr);
1043 int lfsck_namespace_repair_dirent(const struct lu_env *env,
1044 struct lfsck_component *com,
1045 struct dt_object *parent,
1046 struct dt_object *child,
1047 const char *name, const char *name2,
1048 __u16 type, bool update, bool dec);
1049 int lfsck_verify_linkea(const struct lu_env *env, struct lfsck_instance *lfsck,
1050 struct dt_object *obj, const struct lu_name *cname,
1051 const struct lu_fid *pfid);
1052 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
1053 char *name, struct lu_fid *pfid);
1054 int lfsck_update_name_entry(const struct lu_env *env,
1055 struct lfsck_instance *lfsck,
1056 struct dt_object *dir, const char *name,
1057 const struct lu_fid *fid, __u32 type);
1058 int lfsck_namespace_setup(const struct lu_env *env,
1059 struct lfsck_instance *lfsck);
1061 /* lfsck_striped_dir.c */
1062 void lfsck_lmv_put(const struct lu_env *env, struct lfsck_lmv *llmv);
1063 int lfsck_read_stripe_lmv(const struct lu_env *env,
1064 struct lfsck_instance *lfsck,
1065 struct dt_object *obj,
1066 struct lmv_mds_md_v1 *lmv);
1067 int lfsck_shard_name_to_index(const struct lu_env *env, const char *name,
1068 int namelen, __u16 type,
1069 const struct lu_fid *fid);
1070 bool lfsck_is_valid_slave_name_entry(const struct lu_env *env,
1071 struct lfsck_lmv *llmv,
1072 const char *name, int namelen);
1073 int lfsck_namespace_check_name(const struct lu_env *env,
1074 struct lfsck_instance *lfsck,
1075 struct dt_object *parent,
1076 struct dt_object *child,
1077 const struct lu_name *cname);
1078 int lfsck_namespace_update_lmv(const struct lu_env *env,
1079 struct lfsck_component *com,
1080 struct dt_object *obj,
1081 struct lmv_mds_md_v1 *lmv, bool locked);
1082 int lfsck_namespace_verify_stripe_slave(const struct lu_env *env,
1083 struct lfsck_component *com,
1084 struct dt_object *obj,
1085 struct lfsck_lmv *llmv);
1086 int lfsck_namespace_scan_shard(const struct lu_env *env,
1087 struct lfsck_component *com,
1088 struct dt_object *child);
1089 int lfsck_namespace_notify_lmv_master_local(const struct lu_env *env,
1090 struct lfsck_component *com,
1091 struct dt_object *obj);
1092 int lfsck_namespace_repair_bad_name_hash(const struct lu_env *env,
1093 struct lfsck_component *com,
1094 struct dt_object *shard,
1095 struct lfsck_lmv *llmv,
1097 int lfsck_namespace_striped_dir_rescan(const struct lu_env *env,
1098 struct lfsck_component *com,
1099 struct lfsck_namespace_req *lnr);
1100 int lfsck_namespace_handle_striped_master(const struct lu_env *env,
1101 struct lfsck_component *com,
1102 struct lfsck_namespace_req *lnr);
1104 /* lfsck_layout.c */
1105 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
1107 extern const char dot[];
1108 extern const char dotdot[];
1109 extern const char *const lfsck_flags_names[];
1110 extern const char *const lfsck_param_names[];
1111 extern struct lu_context_key lfsck_thread_key;
1113 static inline struct dt_device *lfsck_obj2dev(struct dt_object *obj)
1115 return container_of_safe(obj->do_lu.lo_dev, struct dt_device,
1119 static inline struct lfsck_thread_info *
1120 lfsck_env_info(const struct lu_env *env)
1122 struct lfsck_thread_info *info;
1124 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
1125 LASSERT(info != NULL);
1129 static inline const struct lu_name *
1130 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
1132 struct lu_name *lname;
1134 lname = &lfsck_env_info(env)->lti_name_const;
1135 lname->ln_name = area;
1136 lname->ln_namelen = len;
1141 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
1147 static inline struct lu_buf *
1148 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
1152 buf = &lfsck_env_info(env)->lti_buf;
1158 static inline const struct lu_buf *
1159 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
1163 buf = &lfsck_env_info(env)->lti_buf;
1164 buf->lb_buf = (void *)area;
1169 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
1171 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
1174 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
1176 return lu_object_fid(&obj->do_lu);
1179 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
1181 memset(pos, 0, sizeof(*pos));
1184 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
1186 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
1189 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
1190 const struct lfsck_position *pos2)
1192 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
1195 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
1198 if (fid_is_zero(&pos1->lp_dir_parent) &&
1199 !fid_is_zero(&pos2->lp_dir_parent))
1202 if (!fid_is_zero(&pos1->lp_dir_parent) &&
1203 fid_is_zero(&pos2->lp_dir_parent))
1206 if (fid_is_zero(&pos1->lp_dir_parent) &&
1207 fid_is_zero(&pos2->lp_dir_parent))
1210 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
1212 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
1215 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
1221 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
1222 struct lfsck_position *src)
1224 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
1225 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
1226 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
1229 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
1230 struct lfsck_position *src)
1232 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
1233 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
1234 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
1237 static inline umode_t lfsck_object_type(const struct dt_object *obj)
1239 return lu_object_attr(&obj->do_lu);
1242 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
1244 return lu_object_is_dying(obj->do_lu.lo_header);
1247 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
1249 lu_object_get(&obj->do_lu);
1253 static inline void lfsck_object_put(const struct lu_env *env,
1254 struct dt_object *obj)
1256 dt_object_put(env, obj);
1259 static inline struct seq_server_site
1260 *lfsck_dev_site(struct lfsck_instance *lfsck)
1262 return lu_site2seq(lfsck->li_bottom->dd_lu_dev.ld_site);
1265 static inline u32 lfsck_dev_idx(struct lfsck_instance *lfsck)
1267 return lfsck_dev_site(lfsck)->ss_node_id;
1270 static inline struct dt_object *
1271 lfsck_object_find_by_dev_new(const struct lu_env *env, struct dt_device *dev,
1272 const struct lu_fid *fid)
1274 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
1276 conf->loc_flags = LOC_F_NEW;
1277 return lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
1280 static inline struct dt_object *
1281 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
1282 const struct lu_fid *fid)
1284 return lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
1287 static inline struct dt_device *
1288 lfsck_find_dev_by_fid(const struct lu_env *env, struct lfsck_instance *lfsck,
1289 const struct lu_fid *fid)
1291 struct dt_device *dev;
1294 if (!lfsck->li_master)
1295 return lfsck->li_bottom;
1297 idx = lfsck_find_mdt_idx_by_fid(env, lfsck, fid);
1299 return ERR_PTR(idx);
1301 if (idx == lfsck_dev_idx(lfsck)) {
1302 dev = lfsck->li_bottom;
1304 struct lfsck_tgt_desc *ltd;
1306 ltd = lfsck_ltd2tgt(&lfsck->li_mdt_descs, idx);
1307 if (unlikely(ltd == NULL))
1308 return ERR_PTR(-ENODEV);
1316 static inline struct dt_object *
1317 lfsck_object_find_bottom(const struct lu_env *env, struct lfsck_instance *lfsck,
1318 const struct lu_fid *fid)
1320 struct dt_device *dev;
1322 dev = lfsck_find_dev_by_fid(env, lfsck, fid);
1324 return (struct dt_object *)dev;
1326 return lfsck_object_find_by_dev(env, dev, fid);
1329 static inline struct dt_object *
1330 lfsck_object_find_bottom_new(const struct lu_env *env,
1331 struct lfsck_instance *lfsck,
1332 const struct lu_fid *fid)
1334 struct dt_device *dev;
1336 dev = lfsck_find_dev_by_fid(env, lfsck, fid);
1338 return (struct dt_object *)dev;
1340 return lfsck_object_find_by_dev_new(env, dev, fid);
1343 static inline struct dt_object *
1344 lfsck_object_locate(struct dt_device *dev, struct dt_object *obj)
1346 if (lfsck_obj2dev(obj) == dev) {
1349 struct lu_object *lo;
1351 lo = lu_object_locate(obj->do_lu.lo_header,
1352 dev->dd_lu_dev.ld_type);
1353 if (unlikely(lo == NULL))
1354 return ERR_PTR(-ENOENT);
1360 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
1363 struct lfsck_tgt_desc *ltd;
1365 ltd = lfsck_ltd2tgt(ltds, index);
1367 atomic_inc(<d->ltd_ref);
1372 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
1374 if (atomic_dec_and_test(<d->ltd_ref))
1378 static inline struct lfsck_component *
1379 lfsck_component_get(struct lfsck_component *com)
1381 atomic_inc(&com->lc_ref);
1386 static inline void lfsck_component_put(const struct lu_env *env,
1387 struct lfsck_component *com)
1389 if (atomic_dec_and_test(&com->lc_ref)) {
1390 struct lfsck_sub_trace_obj *lsto;
1393 for (i = 0, lsto = &com->lc_sub_trace_objs[0];
1394 i < LFSCK_STF_COUNT; i++, lsto++) {
1395 if (lsto->lsto_obj != NULL)
1396 lfsck_object_put(env, lsto->lsto_obj);
1399 if (com->lc_obj != NULL)
1400 lfsck_object_put(env, com->lc_obj);
1401 if (com->lc_file_ram != NULL)
1402 OBD_FREE(com->lc_file_ram, com->lc_file_size);
1403 if (com->lc_file_disk != NULL)
1404 OBD_FREE(com->lc_file_disk, com->lc_file_size);
1405 if (com->lc_data != NULL) {
1406 LASSERT(com->lc_ops->lfsck_data_release != NULL);
1408 com->lc_ops->lfsck_data_release(env, com);
1415 static inline struct lfsck_instance *
1416 lfsck_instance_get(struct lfsck_instance *lfsck)
1418 atomic_inc(&lfsck->li_ref);
1423 static inline void lfsck_instance_put(const struct lu_env *env,
1424 struct lfsck_instance *lfsck)
1426 if (atomic_dec_and_test(&lfsck->li_ref))
1427 lfsck_instance_cleanup(env, lfsck);
1430 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1432 return list_empty(&lad->lad_mdt_phase1_list) &&
1433 (!list_empty(&lad->lad_ost_phase2_list) ||
1434 list_empty(&lad->lad_ost_phase1_list));
1437 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1438 struct lfsck_component *com,
1441 struct lfsck_assistant_data *lad = com->lc_data;
1442 unsigned long *bitmap = lad->lad_bitmap;
1444 LASSERT(com->lc_lfsck->li_master);
1447 if (likely(lad->lad_bitmap_count > index)) {
1448 set_bit(index, bitmap);
1449 set_bit(LAD_INCOMPLETE, &lad->lad_flags);
1450 } else if (com->lc_type == LFSCK_TYPE_NAMESPACE) {
1451 struct lfsck_namespace *ns = com->lc_file_ram;
1453 ns->ln_flags |= LF_INCOMPLETE;
1456 CDEBUG(D_LFSCK, "%s: %s LFSCK set bitmap (%p/%u) for idx %u\n",
1457 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, bitmap,
1458 lad->lad_bitmap_count, index);
1461 static inline int lfsck_links_read(const struct lu_env *env,
1462 struct dt_object *obj,
1463 struct linkea_data *ldata)
1466 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1469 return __lfsck_links_read(env, obj, ldata, false);
1472 /* Read linkEA for the given object, the linkEA should contain
1473 * at least one entry, otherwise, -ENODATA will be returned. */
1474 static inline int lfsck_links_read_with_rec(const struct lu_env *env,
1475 struct dt_object *obj,
1476 struct linkea_data *ldata)
1479 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1482 return __lfsck_links_read(env, obj, ldata, true);
1485 static inline int lfsck_links_read2_with_rec(const struct lu_env *env,
1486 struct dt_object *obj,
1487 struct linkea_data *ldata)
1490 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1493 return __lfsck_links_read(env, obj, ldata, true);
1496 static inline struct lfsck_lmv *lfsck_lmv_get(struct lfsck_lmv *llmv)
1499 atomic_inc(&llmv->ll_ref);
1504 static inline int lfsck_sub_trace_file_fid2idx(const struct lu_fid *fid)
1506 return fid->f_oid & (LFSCK_STF_COUNT - 1);
1509 static inline void lfsck_lmv_header_le_to_cpu(struct lmv_mds_md_v1 *dst,
1510 const struct lmv_mds_md_v1 *src)
1512 dst->lmv_magic = le32_to_cpu(src->lmv_magic);
1513 dst->lmv_stripe_count = le32_to_cpu(src->lmv_stripe_count);
1514 dst->lmv_master_mdt_index = le32_to_cpu(src->lmv_master_mdt_index);
1515 dst->lmv_hash_type = le32_to_cpu(src->lmv_hash_type);
1516 dst->lmv_layout_version = le32_to_cpu(src->lmv_layout_version);
1517 dst->lmv_migrate_offset = le32_to_cpu(src->lmv_migrate_offset);
1518 dst->lmv_migrate_hash = le32_to_cpu(src->lmv_migrate_hash);
1521 static inline void lfsck_lmv_header_cpu_to_le(struct lmv_mds_md_v1 *dst,
1522 const struct lmv_mds_md_v1 *src)
1524 dst->lmv_magic = cpu_to_le32(src->lmv_magic);
1525 dst->lmv_stripe_count = cpu_to_le32(src->lmv_stripe_count);
1526 dst->lmv_master_mdt_index = cpu_to_le32(src->lmv_master_mdt_index);
1527 dst->lmv_hash_type = cpu_to_le32(src->lmv_hash_type);
1528 dst->lmv_layout_version = cpu_to_le32(src->lmv_layout_version);
1529 dst->lmv_migrate_offset = cpu_to_le32(src->lmv_migrate_offset);
1530 dst->lmv_migrate_hash = cpu_to_le32(src->lmv_migrate_hash);
1533 static inline struct lfsck_assistant_object *
1534 lfsck_assistant_object_get(struct lfsck_assistant_object *lso)
1536 atomic_inc(&lso->lso_ref);
1542 lfsck_assistant_object_put(const struct lu_env *env,
1543 struct lfsck_assistant_object *lso)
1545 if (atomic_dec_and_test(&lso->lso_ref))
1549 static inline struct thandle*
1550 lfsck_trans_create(const struct lu_env *env, struct dt_device *dev,
1551 struct lfsck_instance *lfsck)
1553 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN) {
1554 CERROR("%s: transaction is being created in DRYRUN mode!\n",
1555 lfsck_lfsck2name(lfsck));
1558 return ERR_PTR(-EINVAL);
1561 return dt_trans_create(env, dev);
1563 #endif /* _LFSCK_INTERNAL_H */