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, 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/lustre_lfsck_user.h>
37 #include <lustre/lustre_user.h>
38 #include <lustre/lustre_idl.h>
39 #include <lustre_lfsck.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>
50 #define HALF_SEC (HZ >> 1)
51 #define LFSCK_CHECKPOINT_INTERVAL 60
54 /* Finish the first cycle scanning. */
55 LF_SCANNED_ONCE = 0x00000001ULL,
57 /* There is some namespace inconsistency. */
58 LF_INCONSISTENT = 0x00000002ULL,
60 /* The device is upgraded from 1.8 format. */
61 LF_UPGRADE = 0x00000004ULL,
63 /* The server ever restarted during the LFSCK, and may miss to process
64 * some objects check/repair. */
65 LF_INCOMPLETE = 0x00000008ULL,
67 /* The LAST_ID (file) crashed. */
68 LF_CRASHED_LASTID = 0x00000010ULL,
71 struct lfsck_position {
72 /* low layer object table-based iteration position. */
75 /* parent FID for directory traversal. */
76 struct lu_fid lp_dir_parent;
78 /* namespace-based directory traversal position. */
82 struct lfsck_bookmark {
83 /* Magic number to detect that this struct contains valid data. */
86 /* For compatible with old versions. */
89 /* See 'enum lfsck_param_flags' */
92 /* How many items can be scanned at most per second. */
95 /* The windows size for async requests pipeline. */
96 __u16 lb_async_windows;
98 /* For 64-bits aligned. */
101 /* The FID for .lustre/lost+found/MDTxxxx */
102 struct lu_fid lb_lpf_fid;
104 /* The FID for the last MDT-object created by the LFSCK repairing. */
105 struct lu_fid lb_last_fid;
107 /* For future using. */
108 __u64 lb_reserved[2];
111 enum lfsck_namespace_trace_flags {
112 LNTF_CHECK_LINKEA = 0x01,
113 LNTF_CHECK_PARENT = 0x02,
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 __u32 ln_run_time_phase1;
143 /* How long the LFSCK phase2 has run in seconds. */
144 __u32 ln_run_time_phase2;
146 /* Time for the last LFSCK completed in seconds since epoch. */
147 __u64 ln_time_last_complete;
149 /* Time for the latest LFSCK ran in seconds since epoch. */
150 __u64 ln_time_latest_start;
152 /* Time for the last LFSCK checkpoint in seconds since epoch. */
153 __u64 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 /* For further using. 256-bytes aligned now. */
223 __u64 ln_reserved[26];
226 enum lfsck_layout_inconsistency_type {
229 LLIT_UNMATCHED_PAIR = 2,
230 LLIT_MULTIPLE_REFERENCED = 3,
232 LLIT_INCONSISTENT_OWNER = 5,
234 LLIT_MAX = LLIT_OTHERS
237 struct lfsck_layout {
238 /* Magic number to detect that this struct contains valid data. */
241 /* See 'enum lfsck_status'. */
244 /* See 'enum lfsck_flags'. */
247 /* How many completed LFSCK runs on the device. */
248 __u32 ll_success_count;
250 /* How long the LFSCK phase1 has run in seconds. */
251 __u32 ll_run_time_phase1;
253 /* How long the LFSCK phase2 has run in seconds. */
254 __u32 ll_run_time_phase2;
256 /* Time for the last LFSCK completed in seconds since epoch. */
257 __u64 ll_time_last_complete;
259 /* Time for the latest LFSCK ran in seconds since epoch. */
260 __u64 ll_time_latest_start;
262 /* Time for the last LFSCK checkpoint in seconds since epoch. */
263 __u64 ll_time_last_checkpoint;
265 /* Position for the latest LFSCK started from. */
266 __u64 ll_pos_latest_start;
268 /* Position for the last LFSCK checkpoint. */
269 __u64 ll_pos_last_checkpoint;
271 /* Position for the first object to be fixed or
272 * failed to be checked in the phase1. */
273 __u64 ll_pos_first_inconsistent;
275 /* How many objects have been checked. */
276 __u64 ll_objs_checked_phase1;
278 /* How many objects failed to be processed. */
279 __u64 ll_objs_failed_phase1;
281 /* How many objects have been double scanned. */
282 __u64 ll_objs_checked_phase2;
284 /* How many objects failed to be processed during double scan. */
285 __u64 ll_objs_failed_phase2;
287 /* kinds of inconsistency have been or to be repaired.
288 * ll_objs_repaired[type - 1] is the count for the given @type. */
289 __u64 ll_objs_repaired[LLIT_MAX];
291 /* How many objects have been skipped because of related
292 * MDT(s)/OST(s) do not participate in the LFSCK */
293 __u64 ll_objs_skipped;
295 /* The size of ll_ost_bitmap with nbits. */
296 __u32 ll_bitmap_size;
298 /* For further using. 256-bytes aligned now. */
300 __u64 ll_reserved_2[11];
302 /* The OST targets bitmap to record the OSTs that contain
303 * non-verified OST-objects. */
304 __u8 ll_ost_bitmap[0];
307 struct lfsck_component;
308 struct lfsck_tgt_descs;
309 struct lfsck_tgt_desc;
311 struct lfsck_operations {
312 int (*lfsck_reset)(const struct lu_env *env,
313 struct lfsck_component *com,
316 void (*lfsck_fail)(const struct lu_env *env,
317 struct lfsck_component *com,
320 int (*lfsck_checkpoint)(const struct lu_env *env,
321 struct lfsck_component *com,
324 int (*lfsck_prep)(const struct lu_env *env,
325 struct lfsck_component *com,
326 struct lfsck_start_param *lsp);
328 int (*lfsck_exec_oit)(const struct lu_env *env,
329 struct lfsck_component *com,
330 struct dt_object *obj);
332 int (*lfsck_exec_dir)(const struct lu_env *env,
333 struct lfsck_component *com,
334 struct lu_dirent *ent,
337 int (*lfsck_post)(const struct lu_env *env,
338 struct lfsck_component *com,
342 int (*lfsck_dump)(const struct lu_env *env,
343 struct lfsck_component *com,
346 int (*lfsck_double_scan)(const struct lu_env *env,
347 struct lfsck_component *com);
349 void (*lfsck_data_release)(const struct lu_env *env,
350 struct lfsck_component *com);
352 void (*lfsck_quit)(const struct lu_env *env,
353 struct lfsck_component *com);
355 int (*lfsck_in_notify)(const struct lu_env *env,
356 struct lfsck_component *com,
357 struct lfsck_request *lr);
359 int (*lfsck_query)(const struct lu_env *env,
360 struct lfsck_component *com);
362 int (*lfsck_join)(const struct lu_env *env,
363 struct lfsck_component *com,
364 struct lfsck_start_param *lsp);
367 #define TGT_PTRS 256 /* number of pointers at 1st level */
368 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
370 struct lfsck_tgt_desc {
371 struct list_head ltd_orphan_list;
372 struct dt_device *ltd_tgt;
373 struct dt_device *ltd_key;
374 struct obd_export *ltd_exp;
375 struct list_head ltd_layout_list;
376 struct list_head ltd_layout_phase_list;
377 struct list_head ltd_namespace_list;
378 struct list_head ltd_namespace_phase_list;
381 __u32 ltd_layout_gen;
382 __u32 ltd_namespace_gen;
383 unsigned int ltd_dead:1,
385 ltd_namespace_done:1;
388 struct lfsck_tgt_desc_idx {
389 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
392 struct lfsck_tgt_descs {
393 /* list of known TGTs */
394 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
396 /* bitmap of TGTs available */
397 cfs_bitmap_t *ltd_tgts_bitmap;
399 /* for lfsck_tgt_desc::ltd_xxx_list */
402 /* for tgts table accessing and changes */
403 struct rw_semaphore ltd_rw_sem;
405 /* Temporary list for orphan targets. */
406 struct list_head ltd_orphan;
408 /* number of registered TGTs */
412 #define LTD_TGT(ltd, index) \
413 ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
414 ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
416 #define OST_TGT(lfsck, index) LTD_TGT(&lfsck->li_ost_descs, index)
417 #define MDT_TGT(lfsck, index) LTD_TGT(&lfsck->li_mdt_descs, index)
419 struct lfsck_component {
420 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
421 struct list_head lc_link;
423 /* into lfsck_instance::li_list_dir */
424 struct list_head lc_link_dir;
426 struct rw_semaphore lc_sem;
429 struct lfsck_position lc_pos_start;
430 struct lfsck_instance *lc_lfsck;
431 struct dt_object *lc_obj;
432 struct lfsck_operations *lc_ops;
436 struct lu_fid lc_fid_latest_scanned_phase2;
438 /* The time for last checkpoint, jiffies */
439 cfs_time_t lc_time_last_checkpoint;
441 /* The time for next checkpoint, jiffies */
442 cfs_time_t lc_time_next_checkpoint;
446 /* How many objects have been checked since last checkpoint. */
447 __u32 lc_new_checked;
449 /* How many objects have been scanned since last sleep. */
450 __u32 lc_new_scanned;
455 struct lfsck_instance {
456 struct mutex li_mutex;
459 /* Link into the lfsck_instance_list. */
460 struct list_head li_link;
462 /* For the components in (first) scanning via otable-based iteration. */
463 struct list_head li_list_scan;
465 /* For the components in scanning via directory traversal. Because
466 * directory traversal cannot guarantee all the object be scanned,
467 * so the component in the li_list_dir must be in li_list_scan. */
468 struct list_head li_list_dir;
470 /* For the components in double scanning. */
471 struct list_head li_list_double_scan;
473 /* For the components those are not scanning now. */
474 struct list_head li_list_idle;
477 atomic_t li_double_scan_count;
478 struct ptlrpc_thread li_thread;
480 /* The time for last checkpoint, jiffies */
481 cfs_time_t li_time_last_checkpoint;
483 /* The time for next checkpoint, jiffies */
484 cfs_time_t li_time_next_checkpoint;
486 lfsck_out_notify li_out_notify;
487 void *li_out_notify_data;
488 struct dt_device *li_next;
489 struct dt_device *li_bottom;
490 struct obd_device *li_obd;
491 struct ldlm_namespace *li_namespace;
492 struct local_oid_storage *li_los;
493 struct lu_fid li_local_root_fid; /* backend root "/" */
494 struct lu_fid li_global_root_fid; /* /ROOT */
495 struct dt_object *li_bookmark_obj;
496 struct dt_object *li_lpf_obj;
497 struct lu_client_seq *li_seq;
498 struct lfsck_bookmark li_bookmark_ram;
499 struct lfsck_bookmark li_bookmark_disk;
500 struct lfsck_position li_pos_current;
501 struct lfsck_position li_pos_checkpoint;
503 /* Obj for otable-based iteration */
504 struct dt_object *li_obj_oit;
506 /* Obj for directory traversal */
507 struct dt_object *li_obj_dir;
509 /* It for otable-based iteration */
510 struct dt_it *li_di_oit;
512 /* It for directory traversal */
513 struct dt_it *li_di_dir;
515 /* Description of OST */
516 struct lfsck_tgt_descs li_ost_descs;
518 /* Description of MDT */
519 struct lfsck_tgt_descs li_mdt_descs;
521 /* namespace-based directory traversal position. */
524 /* Arguments for low layer otable-based iteration. */
527 /* Arugments for namespace-based directory traversal. */
530 /* Schedule for every N objects. */
533 /* Sleep N jiffies for each schedule. */
536 /* How many objects have been scanned since last sleep. */
537 __u32 li_new_scanned;
539 /* The status when the LFSCK stopped or paused. */
542 /* The flags when the lFSCK stopped or paused. */
545 unsigned int li_oit_over:1, /* oit is finished. */
546 li_drop_dryrun:1, /* Ever dryrun, not now. */
547 li_master:1, /* Master instance or not. */
548 li_current_oit_processed:1,
552 struct lfsck_async_interpret_args {
553 struct lfsck_component *laia_com;
554 struct lfsck_tgt_descs *laia_ltds;
555 struct lfsck_tgt_desc *laia_ltd;
556 struct lfsck_request *laia_lr;
557 atomic_t *laia_count;
559 unsigned int laia_shared:1;
562 struct lfsck_thread_args {
563 struct lu_env lta_env;
564 struct lfsck_instance *lta_lfsck;
565 struct lfsck_component *lta_com;
566 struct lfsck_start_param *lta_lsp;
569 struct lfsck_assistant_req {
570 struct list_head lar_list;
573 struct lfsck_namespace_req {
574 struct lfsck_assistant_req lnr_lar;
575 struct dt_object *lnr_obj;
576 struct lu_fid lnr_fid;
577 __u64 lnr_oit_cookie;
578 __u64 lnr_dir_cookie;
586 struct lfsck_assistant_operations {
587 int (*la_handler_p1)(const struct lu_env *env,
588 struct lfsck_component *com,
589 struct lfsck_assistant_req *lar);
591 int (*la_handler_p2)(const struct lu_env *env,
592 struct lfsck_component *com);
594 void (*la_fill_pos)(const struct lu_env *env,
595 struct lfsck_component *com,
596 struct lfsck_position *pos);
598 int (*la_double_scan_result)(const struct lu_env *env,
599 struct lfsck_component *com,
602 void (*la_req_fini)(const struct lu_env *env,
603 struct lfsck_assistant_req *lar);
605 void (*la_sync_failures)(const struct lu_env *env,
606 struct lfsck_component *com,
607 struct lfsck_request *lr);
610 struct lfsck_assistant_data {
612 struct list_head lad_req_list;
614 /* list for the ost targets involve LFSCK. */
615 struct list_head lad_ost_list;
617 /* list for the ost targets in phase1 scanning. */
618 struct list_head lad_ost_phase1_list;
620 /* list for the ost targets in phase1 scanning. */
621 struct list_head lad_ost_phase2_list;
623 /* list for the mdt targets involve LFSCK. */
624 struct list_head lad_mdt_list;
626 /* list for the mdt targets in phase1 scanning. */
627 struct list_head lad_mdt_phase1_list;
629 /* list for the mdt targets in phase1 scanning. */
630 struct list_head lad_mdt_phase2_list;
632 const char *lad_name;
633 struct ptlrpc_thread lad_thread;
635 struct lfsck_assistant_operations *lad_ops;
637 cfs_bitmap_t *lad_bitmap;
641 int lad_assistant_status;
643 unsigned int lad_to_post:1,
644 lad_to_double_scan:1,
645 lad_in_double_scan:1,
650 #define LFSCK_TMPBUF_LEN 64
652 struct lfsck_thread_info {
653 struct lu_name lti_name_const;
654 struct lu_name lti_name;
655 struct lu_name lti_name2;
656 struct lu_buf lti_buf;
657 struct lu_buf lti_linkea_buf;
658 struct lu_buf lti_linkea_buf2;
659 struct lu_buf lti_big_buf;
660 struct lu_fid lti_fid;
661 struct lu_fid lti_fid2;
662 struct lu_fid lti_fid3;
663 struct lu_fid lti_fid4;
664 struct lu_fid lti_fid5;
665 struct lu_attr lti_la;
666 struct lu_attr lti_la2;
667 struct lu_attr lti_la3;
668 struct ost_id lti_oi;
670 struct lustre_mdt_attrs lti_lma;
671 /* old LMA for compatibility */
672 char lti_lma_old[LMA_OLD_SIZE];
674 struct dt_object_format lti_dof;
675 /* There will be '\0' at the end of the name. */
676 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
677 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
678 struct lfsck_request lti_lr;
679 struct lfsck_async_interpret_args lti_laia;
680 struct lfsck_async_interpret_args lti_laia2;
681 struct lfsck_start lti_start;
682 struct lfsck_stop lti_stop;
683 ldlm_policy_data_t lti_policy;
684 struct ldlm_res_id lti_resid;
686 struct filter_fid_old lti_old_pfid;
687 struct filter_fid lti_new_pfid;
689 struct dt_allocation_hint lti_hint;
690 struct lu_orphan_rec lti_rec;
691 struct lov_user_md lti_lum;
692 struct dt_insert_rec lti_dt_rec;
693 struct lu_object_conf lti_conf;
694 struct lu_seq_range lti_range;
698 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
699 struct lu_fid *fid, bool locked);
700 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
701 struct dt_object *obj, struct lustre_handle *lh,
702 __u64 bits, ldlm_mode_t mode);
703 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
704 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
705 struct lfsck_instance *lfsck,
706 const struct lu_fid *fid);
707 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
708 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
709 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
711 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
713 const char *lfsck_status2names(enum lfsck_status status);
714 void lfsck_component_cleanup(const struct lu_env *env,
715 struct lfsck_component *com);
716 void lfsck_instance_cleanup(const struct lu_env *env,
717 struct lfsck_instance *lfsck);
718 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
720 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
721 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
723 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
724 struct lfsck_position *pos, bool init);
725 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
726 void lfsck_control_speed(struct lfsck_instance *lfsck);
727 void lfsck_control_speed_by_self(struct lfsck_component *com);
728 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
729 struct lfsck_assistant_data *
730 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
732 int lfsck_async_interpret_common(const struct lu_env *env,
733 struct ptlrpc_request *req,
735 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
736 struct lfsck_request *lr,
737 struct ptlrpc_request_set *set,
738 ptlrpc_interpterer_t interpterer,
739 void *args, int request);
740 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
741 struct lfsck_start_param *lsp);
742 int lfsck_checkpoint_generic(const struct lu_env *env,
743 struct lfsck_component *com);
744 void lfsck_post_generic(const struct lu_env *env,
745 struct lfsck_component *com, int *result);
746 int lfsck_double_scan_generic(const struct lu_env *env,
747 struct lfsck_component *com, int status);
748 void lfsck_quit_generic(const struct lu_env *env,
749 struct lfsck_component *com);
752 int lfsck_master_engine(void *args);
753 int lfsck_assistant_engine(void *args);
755 /* lfsck_bookmark.c */
756 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
757 struct lfsck_bookmark *src);
758 int lfsck_bookmark_store(const struct lu_env *env,
759 struct lfsck_instance *lfsck);
760 int lfsck_bookmark_setup(const struct lu_env *env,
761 struct lfsck_instance *lfsck);
762 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
763 struct lfsck_start *start, bool reset);
765 /* lfsck_namespace.c */
766 int lfsck_namespace_trace_update(const struct lu_env *env,
767 struct lfsck_component *com,
768 const struct lu_fid *fid,
769 const __u8 flags, bool add);
770 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
771 struct linkea_data *ldata);
772 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
773 struct lfsck_component *com,
774 struct dt_object *obj,
775 struct linkea_data *ldata);
776 int lfsck_namespace_repair_dangling(const struct lu_env *env,
777 struct lfsck_component *com,
778 struct dt_object *child,
779 struct lfsck_namespace_req *lnr);
780 int lfsck_namespace_repair_dirent(const struct lu_env *env,
781 struct lfsck_component *com,
782 struct dt_object *parent,
783 struct dt_object *child,
784 const char *name, const char *name2,
785 __u16 type, bool update, bool dec);
786 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
787 struct dt_object *obj, const struct lu_name *cname,
788 const struct lu_fid *pfid);
789 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
790 char *name, struct lu_fid *pfid);
791 int lfsck_remove_name_entry(const struct lu_env *env,
792 struct lfsck_instance *lfsck,
793 struct dt_object *parent,
794 const char *name, __u32 type);
795 int lfsck_update_name_entry(const struct lu_env *env,
796 struct lfsck_instance *lfsck,
797 struct dt_object *parent, const char *name,
798 const struct lu_fid *pfid, __u32 type);
799 int lfsck_namespace_setup(const struct lu_env *env,
800 struct lfsck_instance *lfsck);
803 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
805 extern const char dot[];
806 extern const char dotdot[];
807 extern const char *lfsck_flags_names[];
808 extern const char *lfsck_param_names[];
809 extern struct lu_context_key lfsck_thread_key;
811 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
813 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
816 static inline struct lfsck_thread_info *
817 lfsck_env_info(const struct lu_env *env)
819 struct lfsck_thread_info *info;
821 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
822 LASSERT(info != NULL);
826 static inline const struct lu_name *
827 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
829 struct lu_name *lname;
831 lname = &lfsck_env_info(env)->lti_name_const;
832 lname->ln_name = area;
833 lname->ln_namelen = len;
838 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
844 static inline struct lu_buf *
845 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
849 buf = &lfsck_env_info(env)->lti_buf;
855 static inline const struct lu_buf *
856 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
860 buf = &lfsck_env_info(env)->lti_buf;
861 buf->lb_buf = (void *)area;
866 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
868 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
871 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
873 return lu_object_fid(&obj->do_lu);
876 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
878 memset(pos, 0, sizeof(*pos));
881 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
883 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
886 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
887 const struct lfsck_position *pos2)
889 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
892 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
895 if (fid_is_zero(&pos1->lp_dir_parent) &&
896 !fid_is_zero(&pos2->lp_dir_parent))
899 if (!fid_is_zero(&pos1->lp_dir_parent) &&
900 fid_is_zero(&pos2->lp_dir_parent))
903 if (fid_is_zero(&pos1->lp_dir_parent) &&
904 fid_is_zero(&pos2->lp_dir_parent))
907 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
909 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
912 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
918 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
919 struct lfsck_position *src)
921 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
922 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
923 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
926 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
927 struct lfsck_position *src)
929 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
930 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
931 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
934 static inline umode_t lfsck_object_type(const struct dt_object *obj)
936 return lu_object_attr(&obj->do_lu);
939 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
941 struct lu_object_header *loh = obj->do_lu.lo_header;
943 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
946 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
948 lu_object_get(&obj->do_lu);
952 static inline void lfsck_object_put(const struct lu_env *env,
953 struct dt_object *obj)
955 lu_object_put(env, &obj->do_lu);
958 static inline u32 lfsck_dev_idx(struct dt_device *dev)
960 return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
963 static inline struct dt_object *
964 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
965 const struct lu_fid *fid)
967 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
968 struct dt_object *obj;
970 conf->loc_flags = LOC_F_NOWAIT;
971 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
972 if (unlikely(obj == NULL))
973 return ERR_PTR(-ENOENT);
978 static inline struct dt_object *
979 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
980 const struct lu_fid *fid)
982 struct dt_object *obj;
984 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
985 if (unlikely(obj == NULL))
986 return ERR_PTR(-ENOENT);
991 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
992 struct lfsck_instance *lfsck,
993 const struct lu_fid *fid)
995 return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
998 static inline struct dt_object *
999 lfsck_object_find_bottom(const struct lu_env *env, struct lfsck_instance *lfsck,
1000 const struct lu_fid *fid)
1002 struct dt_device *dev;
1005 idx = lfsck_find_mdt_idx_by_fid(env, lfsck, fid);
1007 return ERR_PTR(idx);
1009 if (idx == lfsck_dev_idx(lfsck->li_bottom)) {
1010 dev = lfsck->li_bottom;
1012 struct lfsck_tgt_desc *ltd;
1014 ltd = LTD_TGT(&lfsck->li_mdt_descs, idx);
1015 if (unlikely(ltd == NULL))
1016 return ERR_PTR(-ENODEV);
1021 return lfsck_object_find_by_dev(env, dev, fid);
1024 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
1027 struct lfsck_tgt_desc *ltd;
1029 ltd = LTD_TGT(ltds, index);
1031 atomic_inc(<d->ltd_ref);
1036 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
1038 if (atomic_dec_and_test(<d->ltd_ref))
1042 static inline struct lfsck_component *
1043 lfsck_component_get(struct lfsck_component *com)
1045 atomic_inc(&com->lc_ref);
1050 static inline void lfsck_component_put(const struct lu_env *env,
1051 struct lfsck_component *com)
1053 if (atomic_dec_and_test(&com->lc_ref)) {
1054 if (com->lc_obj != NULL)
1055 lu_object_put_nocache(env, &com->lc_obj->do_lu);
1056 if (com->lc_file_ram != NULL)
1057 OBD_FREE(com->lc_file_ram, com->lc_file_size);
1058 if (com->lc_file_disk != NULL)
1059 OBD_FREE(com->lc_file_disk, com->lc_file_size);
1060 if (com->lc_data != NULL) {
1061 LASSERT(com->lc_ops->lfsck_data_release != NULL);
1063 com->lc_ops->lfsck_data_release(env, com);
1070 static inline struct lfsck_instance *
1071 lfsck_instance_get(struct lfsck_instance *lfsck)
1073 atomic_inc(&lfsck->li_ref);
1078 static inline void lfsck_instance_put(const struct lu_env *env,
1079 struct lfsck_instance *lfsck)
1081 if (atomic_dec_and_test(&lfsck->li_ref))
1082 lfsck_instance_cleanup(env, lfsck);
1085 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1087 return list_empty(&lad->lad_mdt_phase1_list) &&
1088 (!list_empty(&lad->lad_ost_phase2_list) ||
1089 list_empty(&lad->lad_ost_phase1_list));
1092 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1093 struct lfsck_component *com,
1096 struct lfsck_assistant_data *lad = com->lc_data;
1097 cfs_bitmap_t *bitmap = lad->lad_bitmap;
1099 LASSERT(com->lc_lfsck->li_master);
1100 LASSERT(bitmap != NULL);
1101 LASSERTF(bitmap->size > index, "invalid index: nbits %d, index %u\n",
1102 bitmap->size, index);
1104 cfs_bitmap_set(bitmap, index);
1105 lad->lad_incomplete = 1;
1108 static inline int lfsck_links_read(const struct lu_env *env,
1109 struct dt_object *obj,
1110 struct linkea_data *ldata)
1113 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1116 return __lfsck_links_read(env, obj, ldata);
1119 static inline int lfsck_links_read2(const struct lu_env *env,
1120 struct dt_object *obj,
1121 struct linkea_data *ldata)
1124 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1127 return __lfsck_links_read(env, obj, ldata);
1130 #endif /* _LFSCK_INTERNAL_H */