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,
114 LNTF_SKIP_NLINK = 0x04,
115 LNTF_CHECK_ORPHAN = 0x08,
119 enum lfsck_namespace_inconsistency_type {
122 LNIT_UNMATCHED_PAIRS = 2,
129 struct lfsck_namespace {
130 /* Magic number to detect that this struct contains valid data. */
133 /* See 'enum lfsck_status'. */
136 /* See 'enum lfsck_flags'. */
139 /* How many completed LFSCK runs on the device. */
140 __u32 ln_success_count;
142 /* How long the LFSCK phase1 has run in seconds. */
143 __u32 ln_run_time_phase1;
145 /* How long the LFSCK phase2 has run in seconds. */
146 __u32 ln_run_time_phase2;
148 /* Time for the last LFSCK completed in seconds since epoch. */
149 __u64 ln_time_last_complete;
151 /* Time for the latest LFSCK ran in seconds since epoch. */
152 __u64 ln_time_latest_start;
154 /* Time for the last LFSCK checkpoint in seconds since epoch. */
155 __u64 ln_time_last_checkpoint;
157 /* Position for the latest LFSCK started from. */
158 struct lfsck_position ln_pos_latest_start;
160 /* Position for the last LFSCK checkpoint. */
161 struct lfsck_position ln_pos_last_checkpoint;
163 /* Position for the first should be updated object. */
164 struct lfsck_position ln_pos_first_inconsistent;
166 /* How many items (including dir) have been checked. */
167 __u64 ln_items_checked;
169 /* How many items have been repaired. */
170 __u64 ln_items_repaired;
172 /* How many items failed to be processed. */
173 __u64 ln_items_failed;
175 /* How many directories have been traversed. */
176 __u64 ln_dirs_checked;
178 /* How many objects have been double scanned. */
179 __u64 ln_objs_checked_phase2;
181 /* How many objects have been reparied during double scan. */
182 __u64 ln_objs_repaired_phase2;
184 /* How many objects failed to be processed during double scan. */
185 __u64 ln_objs_failed_phase2;
187 /* How many objects with nlink fixed. */
188 __u64 ln_objs_nlink_repaired;
190 /* The latest object has been processed (failed) during double scan. */
191 struct lu_fid ln_fid_latest_scanned_phase2;
193 /* How many FID-in-dirent entries have been repaired. */
194 __u64 ln_dirent_repaired;
196 /* How many linkEA entries have been repaired. */
197 __u64 ln_linkea_repaired;
199 /* How many multiple-linked objects have been checked. */
200 __u64 ln_mul_linked_checked;
202 /* How many multiple-linked objects have been repaired. */
203 __u64 ln_mul_linked_repaired;
205 /* How many undefined inconsistency found in phase2. */
206 __u64 ln_unknown_inconsistency;
208 /* How many unmatched pairs have been repaired. */
209 __u64 ln_unmatched_pairs_repaired;
211 /* How many dangling name entries have been found/repaired. */
212 __u64 ln_dangling_repaired;
214 /* How many multiple referenced name entries have been
216 __u64 ln_mul_ref_repaired;
218 /* How many name entries with bad file type have been repaired. */
219 __u64 ln_bad_type_repaired;
221 /* How many lost name entries have been re-inserted. */
222 __u64 ln_lost_dirent_repaired;
224 /* How many objects under /lost+found have been scanned. */
225 __u64 ln_local_lpf_scanned;
227 /* How many objects under /lost+found have been moved to
228 * namespace visible directory. */
229 __u64 ln_local_lpf_moved;
231 /* How many objects under /lost+found have been skipped. */
232 __u64 ln_local_lpf_skipped;
234 /* How many objects under /lost+found failed to be processed. */
235 __u64 ln_local_lpf_failed;
237 /* The size of MDT targets bitmap with nbits. Such bitmap records
238 * the MDTs that contain non-verified MDT-objects. */
239 __u32 ln_bitmap_size;
242 /* For further using. 256-bytes aligned now. */
243 __u64 ln_reserved[25];
246 enum lfsck_layout_inconsistency_type {
249 LLIT_UNMATCHED_PAIR = 2,
250 LLIT_MULTIPLE_REFERENCED = 3,
252 LLIT_INCONSISTENT_OWNER = 5,
254 LLIT_MAX = LLIT_OTHERS
257 struct lfsck_layout {
258 /* Magic number to detect that this struct contains valid data. */
261 /* See 'enum lfsck_status'. */
264 /* See 'enum lfsck_flags'. */
267 /* How many completed LFSCK runs on the device. */
268 __u32 ll_success_count;
270 /* How long the LFSCK phase1 has run in seconds. */
271 __u32 ll_run_time_phase1;
273 /* How long the LFSCK phase2 has run in seconds. */
274 __u32 ll_run_time_phase2;
276 /* Time for the last LFSCK completed in seconds since epoch. */
277 __u64 ll_time_last_complete;
279 /* Time for the latest LFSCK ran in seconds since epoch. */
280 __u64 ll_time_latest_start;
282 /* Time for the last LFSCK checkpoint in seconds since epoch. */
283 __u64 ll_time_last_checkpoint;
285 /* Position for the latest LFSCK started from. */
286 __u64 ll_pos_latest_start;
288 /* Position for the last LFSCK checkpoint. */
289 __u64 ll_pos_last_checkpoint;
291 /* Position for the first object to be fixed or
292 * failed to be checked in the phase1. */
293 __u64 ll_pos_first_inconsistent;
295 /* How many objects have been checked. */
296 __u64 ll_objs_checked_phase1;
298 /* How many objects failed to be processed. */
299 __u64 ll_objs_failed_phase1;
301 /* How many objects have been double scanned. */
302 __u64 ll_objs_checked_phase2;
304 /* How many objects failed to be processed during double scan. */
305 __u64 ll_objs_failed_phase2;
307 /* kinds of inconsistency have been or to be repaired.
308 * ll_objs_repaired[type - 1] is the count for the given @type. */
309 __u64 ll_objs_repaired[LLIT_MAX];
311 /* How many objects have been skipped because of related
312 * MDT(s)/OST(s) do not participate in the LFSCK */
313 __u64 ll_objs_skipped;
315 /* The size of ll_ost_bitmap with nbits. */
316 __u32 ll_bitmap_size;
318 /* For further using. 256-bytes aligned now. */
320 __u64 ll_reserved_2[11];
322 /* The OST targets bitmap to record the OSTs that contain
323 * non-verified OST-objects. */
324 __u8 ll_ost_bitmap[0];
327 struct lfsck_component;
328 struct lfsck_tgt_descs;
329 struct lfsck_tgt_desc;
331 struct lfsck_operations {
332 int (*lfsck_reset)(const struct lu_env *env,
333 struct lfsck_component *com,
336 void (*lfsck_fail)(const struct lu_env *env,
337 struct lfsck_component *com,
340 int (*lfsck_checkpoint)(const struct lu_env *env,
341 struct lfsck_component *com,
344 int (*lfsck_prep)(const struct lu_env *env,
345 struct lfsck_component *com,
346 struct lfsck_start_param *lsp);
348 int (*lfsck_exec_oit)(const struct lu_env *env,
349 struct lfsck_component *com,
350 struct dt_object *obj);
352 int (*lfsck_exec_dir)(const struct lu_env *env,
353 struct lfsck_component *com,
354 struct lu_dirent *ent,
357 int (*lfsck_post)(const struct lu_env *env,
358 struct lfsck_component *com,
362 int (*lfsck_dump)(const struct lu_env *env,
363 struct lfsck_component *com,
366 int (*lfsck_double_scan)(const struct lu_env *env,
367 struct lfsck_component *com);
369 void (*lfsck_data_release)(const struct lu_env *env,
370 struct lfsck_component *com);
372 void (*lfsck_quit)(const struct lu_env *env,
373 struct lfsck_component *com);
375 int (*lfsck_in_notify)(const struct lu_env *env,
376 struct lfsck_component *com,
377 struct lfsck_request *lr,
380 int (*lfsck_query)(const struct lu_env *env,
381 struct lfsck_component *com);
383 int (*lfsck_join)(const struct lu_env *env,
384 struct lfsck_component *com,
385 struct lfsck_start_param *lsp);
388 #define TGT_PTRS 256 /* number of pointers at 1st level */
389 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
391 struct lfsck_tgt_desc {
392 struct list_head ltd_orphan_list;
393 struct dt_device *ltd_tgt;
394 struct dt_device *ltd_key;
395 struct obd_export *ltd_exp;
396 struct list_head ltd_layout_list;
397 struct list_head ltd_layout_phase_list;
398 struct list_head ltd_namespace_list;
399 struct list_head ltd_namespace_phase_list;
402 __u32 ltd_layout_gen;
403 __u32 ltd_namespace_gen;
404 unsigned int ltd_dead:1,
406 ltd_namespace_done:1,
407 ltd_namespace_failed:1;
410 struct lfsck_tgt_desc_idx {
411 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
414 struct lfsck_tgt_descs {
415 /* list of known TGTs */
416 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
418 /* bitmap of TGTs available */
419 cfs_bitmap_t *ltd_tgts_bitmap;
421 /* for lfsck_tgt_desc::ltd_xxx_list */
424 /* for tgts table accessing and changes */
425 struct rw_semaphore ltd_rw_sem;
427 /* Temporary list for orphan targets. */
428 struct list_head ltd_orphan;
430 /* number of registered TGTs */
434 #define LTD_TGT(ltd, index) \
435 ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
436 ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
438 #define OST_TGT(lfsck, index) LTD_TGT(&lfsck->li_ost_descs, index)
439 #define MDT_TGT(lfsck, index) LTD_TGT(&lfsck->li_mdt_descs, index)
441 struct lfsck_component {
442 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
443 struct list_head lc_link;
445 /* into lfsck_instance::li_list_dir */
446 struct list_head lc_link_dir;
448 struct rw_semaphore lc_sem;
451 struct lfsck_position lc_pos_start;
452 struct lfsck_instance *lc_lfsck;
453 struct dt_object *lc_obj;
454 struct lfsck_operations *lc_ops;
458 struct lu_fid lc_fid_latest_scanned_phase2;
460 /* The time for last checkpoint, jiffies */
461 cfs_time_t lc_time_last_checkpoint;
463 /* The time for next checkpoint, jiffies */
464 cfs_time_t lc_time_next_checkpoint;
468 /* How many objects have been checked since last checkpoint. */
469 __u32 lc_new_checked;
471 /* How many objects have been scanned since last sleep. */
472 __u32 lc_new_scanned;
477 struct lfsck_instance {
478 struct mutex li_mutex;
481 /* Link into the lfsck_instance_list. */
482 struct list_head li_link;
484 /* For the components in (first) scanning via otable-based iteration. */
485 struct list_head li_list_scan;
487 /* For the components in scanning via directory traversal. Because
488 * directory traversal cannot guarantee all the object be scanned,
489 * so the component in the li_list_dir must be in li_list_scan. */
490 struct list_head li_list_dir;
492 /* For the components in double scanning. */
493 struct list_head li_list_double_scan;
495 /* For the components those are not scanning now. */
496 struct list_head li_list_idle;
499 atomic_t li_double_scan_count;
500 struct ptlrpc_thread li_thread;
502 /* The time for last checkpoint, jiffies */
503 cfs_time_t li_time_last_checkpoint;
505 /* The time for next checkpoint, jiffies */
506 cfs_time_t li_time_next_checkpoint;
508 lfsck_out_notify li_out_notify;
509 void *li_out_notify_data;
510 struct dt_device *li_next;
511 struct dt_device *li_bottom;
512 struct obd_device *li_obd;
513 struct ldlm_namespace *li_namespace;
514 struct local_oid_storage *li_los;
515 struct lu_fid li_local_root_fid; /* backend root "/" */
516 struct lu_fid li_global_root_fid; /* /ROOT */
517 struct dt_object *li_bookmark_obj;
518 struct dt_object *li_lpf_obj;
519 struct lu_client_seq *li_seq;
520 struct lfsck_bookmark li_bookmark_ram;
521 struct lfsck_bookmark li_bookmark_disk;
522 struct lfsck_position li_pos_current;
523 struct lfsck_position li_pos_checkpoint;
525 /* Obj for otable-based iteration */
526 struct dt_object *li_obj_oit;
528 /* Obj for directory traversal */
529 struct dt_object *li_obj_dir;
531 /* It for otable-based iteration */
532 struct dt_it *li_di_oit;
534 /* It for directory traversal */
535 struct dt_it *li_di_dir;
537 /* Description of OST */
538 struct lfsck_tgt_descs li_ost_descs;
540 /* Description of MDT */
541 struct lfsck_tgt_descs li_mdt_descs;
543 /* namespace-based directory traversal position. */
546 /* Arguments for low layer otable-based iteration. */
549 /* Arugments for namespace-based directory traversal. */
552 /* Schedule for every N objects. */
555 /* Sleep N jiffies for each schedule. */
558 /* How many objects have been scanned since last sleep. */
559 __u32 li_new_scanned;
561 /* The status when the LFSCK stopped or paused. */
564 /* The flags when the lFSCK stopped or paused. */
567 unsigned int li_oit_over:1, /* oit is finished. */
568 li_drop_dryrun:1, /* Ever dryrun, not now. */
569 li_master:1, /* Master instance or not. */
570 li_current_oit_processed:1,
574 struct lfsck_async_interpret_args {
575 struct lfsck_component *laia_com;
576 struct lfsck_tgt_descs *laia_ltds;
577 struct lfsck_tgt_desc *laia_ltd;
578 struct lfsck_request *laia_lr;
579 atomic_t *laia_count;
581 unsigned int laia_shared:1;
584 struct lfsck_thread_args {
585 struct lu_env lta_env;
586 struct lfsck_instance *lta_lfsck;
587 struct lfsck_component *lta_com;
588 struct lfsck_start_param *lta_lsp;
591 struct lfsck_assistant_req {
592 struct list_head lar_list;
595 struct lfsck_namespace_req {
596 struct lfsck_assistant_req lnr_lar;
597 struct dt_object *lnr_obj;
598 struct lu_fid lnr_fid;
599 __u64 lnr_oit_cookie;
600 __u64 lnr_dir_cookie;
608 struct lfsck_assistant_operations {
609 int (*la_handler_p1)(const struct lu_env *env,
610 struct lfsck_component *com,
611 struct lfsck_assistant_req *lar);
613 int (*la_handler_p2)(const struct lu_env *env,
614 struct lfsck_component *com);
616 void (*la_fill_pos)(const struct lu_env *env,
617 struct lfsck_component *com,
618 struct lfsck_position *pos);
620 int (*la_double_scan_result)(const struct lu_env *env,
621 struct lfsck_component *com,
624 void (*la_req_fini)(const struct lu_env *env,
625 struct lfsck_assistant_req *lar);
627 void (*la_sync_failures)(const struct lu_env *env,
628 struct lfsck_component *com,
629 struct lfsck_request *lr);
632 struct lfsck_assistant_data {
634 struct list_head lad_req_list;
636 /* list for the ost targets involve LFSCK. */
637 struct list_head lad_ost_list;
639 /* list for the ost targets in phase1 scanning. */
640 struct list_head lad_ost_phase1_list;
642 /* list for the ost targets in phase1 scanning. */
643 struct list_head lad_ost_phase2_list;
645 /* list for the mdt targets involve LFSCK. */
646 struct list_head lad_mdt_list;
648 /* list for the mdt targets in phase1 scanning. */
649 struct list_head lad_mdt_phase1_list;
651 /* list for the mdt targets in phase1 scanning. */
652 struct list_head lad_mdt_phase2_list;
654 const char *lad_name;
655 struct ptlrpc_thread lad_thread;
657 struct lfsck_assistant_operations *lad_ops;
659 cfs_bitmap_t *lad_bitmap;
663 int lad_assistant_status;
665 unsigned int lad_to_post:1,
666 lad_to_double_scan:1,
667 lad_in_double_scan:1,
672 #define LFSCK_TMPBUF_LEN 64
674 struct lfsck_thread_info {
675 struct lu_name lti_name_const;
676 struct lu_name lti_name;
677 struct lu_name lti_name2;
678 struct lu_buf lti_buf;
679 struct lu_buf lti_linkea_buf;
680 struct lu_buf lti_linkea_buf2;
681 struct lu_buf lti_big_buf;
682 struct lu_fid lti_fid;
683 struct lu_fid lti_fid2;
684 struct lu_fid lti_fid3;
685 struct lu_fid lti_fid4;
686 struct lu_fid lti_fid5;
687 struct lu_attr lti_la;
688 struct lu_attr lti_la2;
689 struct lu_attr lti_la3;
690 struct ost_id lti_oi;
692 struct lustre_mdt_attrs lti_lma;
693 /* old LMA for compatibility */
694 char lti_lma_old[LMA_OLD_SIZE];
696 struct dt_object_format lti_dof;
697 /* There will be '\0' at the end of the name. */
698 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
699 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
700 struct lfsck_request lti_lr;
701 struct lfsck_async_interpret_args lti_laia;
702 struct lfsck_async_interpret_args lti_laia2;
703 struct lfsck_start lti_start;
704 struct lfsck_stop lti_stop;
705 ldlm_policy_data_t lti_policy;
706 struct ldlm_res_id lti_resid;
708 struct filter_fid_old lti_old_pfid;
709 struct filter_fid lti_new_pfid;
711 struct dt_allocation_hint lti_hint;
712 struct lu_orphan_rec lti_rec;
713 struct lov_user_md lti_lum;
714 struct dt_insert_rec lti_dt_rec;
715 struct lu_object_conf lti_conf;
716 struct lu_seq_range lti_range;
720 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
721 struct lu_fid *fid, bool locked);
722 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
723 struct dt_object *obj, struct lustre_handle *lh,
724 __u64 bits, ldlm_mode_t mode);
725 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
726 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
727 struct lfsck_instance *lfsck,
728 const struct lu_fid *fid);
729 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
730 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
731 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
733 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
735 const char *lfsck_status2names(enum lfsck_status status);
736 void lfsck_component_cleanup(const struct lu_env *env,
737 struct lfsck_component *com);
738 void lfsck_instance_cleanup(const struct lu_env *env,
739 struct lfsck_instance *lfsck);
740 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
742 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
743 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
745 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
746 struct lfsck_position *pos, bool init);
747 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
748 void lfsck_control_speed(struct lfsck_instance *lfsck);
749 void lfsck_control_speed_by_self(struct lfsck_component *com);
750 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
751 struct lfsck_assistant_data *
752 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
754 int lfsck_async_interpret_common(const struct lu_env *env,
755 struct ptlrpc_request *req,
757 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
758 struct lfsck_request *lr,
759 struct ptlrpc_request_set *set,
760 ptlrpc_interpterer_t interpterer,
761 void *args, int request);
762 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
763 struct lfsck_start_param *lsp);
764 int lfsck_checkpoint_generic(const struct lu_env *env,
765 struct lfsck_component *com);
766 void lfsck_post_generic(const struct lu_env *env,
767 struct lfsck_component *com, int *result);
768 int lfsck_double_scan_generic(const struct lu_env *env,
769 struct lfsck_component *com, int status);
770 void lfsck_quit_generic(const struct lu_env *env,
771 struct lfsck_component *com);
774 int lfsck_unpack_ent(struct lu_dirent *ent, __u64 *cookie, __u16 *type);
775 int lfsck_master_engine(void *args);
776 int lfsck_assistant_engine(void *args);
778 /* lfsck_bookmark.c */
779 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
780 struct lfsck_bookmark *src);
781 int lfsck_bookmark_store(const struct lu_env *env,
782 struct lfsck_instance *lfsck);
783 int lfsck_bookmark_setup(const struct lu_env *env,
784 struct lfsck_instance *lfsck);
785 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
786 struct lfsck_start *start, bool reset);
788 /* lfsck_namespace.c */
789 int lfsck_namespace_trace_update(const struct lu_env *env,
790 struct lfsck_component *com,
791 const struct lu_fid *fid,
792 const __u8 flags, bool add);
793 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
794 struct linkea_data *ldata);
795 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
796 struct lfsck_component *com,
797 struct dt_object *obj,
798 struct linkea_data *ldata);
799 int lfsck_namespace_repair_dangling(const struct lu_env *env,
800 struct lfsck_component *com,
801 struct dt_object *child,
802 struct lfsck_namespace_req *lnr);
803 int lfsck_namespace_repair_dirent(const struct lu_env *env,
804 struct lfsck_component *com,
805 struct dt_object *parent,
806 struct dt_object *child,
807 const char *name, const char *name2,
808 __u16 type, bool update, bool dec);
809 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
810 struct dt_object *obj, const struct lu_name *cname,
811 const struct lu_fid *pfid);
812 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
813 char *name, struct lu_fid *pfid);
814 int lfsck_remove_name_entry(const struct lu_env *env,
815 struct lfsck_instance *lfsck,
816 struct dt_object *parent,
817 const char *name, __u32 type);
818 int lfsck_update_name_entry(const struct lu_env *env,
819 struct lfsck_instance *lfsck,
820 struct dt_object *parent, const char *name,
821 const struct lu_fid *pfid, __u32 type);
822 int lfsck_namespace_setup(const struct lu_env *env,
823 struct lfsck_instance *lfsck);
826 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
828 extern const char dot[];
829 extern const char dotdot[];
830 extern const char *lfsck_flags_names[];
831 extern const char *lfsck_param_names[];
832 extern struct lu_context_key lfsck_thread_key;
834 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
836 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
839 static inline struct lfsck_thread_info *
840 lfsck_env_info(const struct lu_env *env)
842 struct lfsck_thread_info *info;
844 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
845 LASSERT(info != NULL);
849 static inline const struct lu_name *
850 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
852 struct lu_name *lname;
854 lname = &lfsck_env_info(env)->lti_name_const;
855 lname->ln_name = area;
856 lname->ln_namelen = len;
861 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
867 static inline struct lu_buf *
868 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
872 buf = &lfsck_env_info(env)->lti_buf;
878 static inline const struct lu_buf *
879 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
883 buf = &lfsck_env_info(env)->lti_buf;
884 buf->lb_buf = (void *)area;
889 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
891 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
894 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
896 return lu_object_fid(&obj->do_lu);
899 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
901 memset(pos, 0, sizeof(*pos));
904 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
906 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
909 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
910 const struct lfsck_position *pos2)
912 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
915 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
918 if (fid_is_zero(&pos1->lp_dir_parent) &&
919 !fid_is_zero(&pos2->lp_dir_parent))
922 if (!fid_is_zero(&pos1->lp_dir_parent) &&
923 fid_is_zero(&pos2->lp_dir_parent))
926 if (fid_is_zero(&pos1->lp_dir_parent) &&
927 fid_is_zero(&pos2->lp_dir_parent))
930 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
932 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
935 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
941 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
942 struct lfsck_position *src)
944 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
945 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
946 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
949 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
950 struct lfsck_position *src)
952 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
953 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
954 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
957 static inline umode_t lfsck_object_type(const struct dt_object *obj)
959 return lu_object_attr(&obj->do_lu);
962 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
964 struct lu_object_header *loh = obj->do_lu.lo_header;
966 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
969 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
971 lu_object_get(&obj->do_lu);
975 static inline void lfsck_object_put(const struct lu_env *env,
976 struct dt_object *obj)
978 lu_object_put(env, &obj->do_lu);
981 static inline u32 lfsck_dev_idx(struct dt_device *dev)
983 return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
986 static inline struct dt_object *
987 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
988 const struct lu_fid *fid)
990 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
991 struct dt_object *obj;
993 conf->loc_flags = LOC_F_NOWAIT;
994 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
995 if (unlikely(obj == NULL))
996 return ERR_PTR(-ENOENT);
1001 static inline struct dt_object *
1002 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
1003 const struct lu_fid *fid)
1005 struct dt_object *obj;
1007 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
1008 if (unlikely(obj == NULL))
1009 return ERR_PTR(-ENOENT);
1014 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
1015 struct lfsck_instance *lfsck,
1016 const struct lu_fid *fid)
1018 return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
1021 static inline struct dt_object *
1022 lfsck_object_find_bottom(const struct lu_env *env, struct lfsck_instance *lfsck,
1023 const struct lu_fid *fid)
1025 struct dt_device *dev;
1028 idx = lfsck_find_mdt_idx_by_fid(env, lfsck, fid);
1030 return ERR_PTR(idx);
1032 if (idx == lfsck_dev_idx(lfsck->li_bottom)) {
1033 dev = lfsck->li_bottom;
1035 struct lfsck_tgt_desc *ltd;
1037 ltd = LTD_TGT(&lfsck->li_mdt_descs, idx);
1038 if (unlikely(ltd == NULL))
1039 return ERR_PTR(-ENODEV);
1044 return lfsck_object_find_by_dev(env, dev, fid);
1047 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
1050 struct lfsck_tgt_desc *ltd;
1052 ltd = LTD_TGT(ltds, index);
1054 atomic_inc(<d->ltd_ref);
1059 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
1061 if (atomic_dec_and_test(<d->ltd_ref))
1065 static inline struct lfsck_component *
1066 lfsck_component_get(struct lfsck_component *com)
1068 atomic_inc(&com->lc_ref);
1073 static inline void lfsck_component_put(const struct lu_env *env,
1074 struct lfsck_component *com)
1076 if (atomic_dec_and_test(&com->lc_ref)) {
1077 if (com->lc_obj != NULL)
1078 lu_object_put_nocache(env, &com->lc_obj->do_lu);
1079 if (com->lc_file_ram != NULL)
1080 OBD_FREE(com->lc_file_ram, com->lc_file_size);
1081 if (com->lc_file_disk != NULL)
1082 OBD_FREE(com->lc_file_disk, com->lc_file_size);
1083 if (com->lc_data != NULL) {
1084 LASSERT(com->lc_ops->lfsck_data_release != NULL);
1086 com->lc_ops->lfsck_data_release(env, com);
1093 static inline struct lfsck_instance *
1094 lfsck_instance_get(struct lfsck_instance *lfsck)
1096 atomic_inc(&lfsck->li_ref);
1101 static inline void lfsck_instance_put(const struct lu_env *env,
1102 struct lfsck_instance *lfsck)
1104 if (atomic_dec_and_test(&lfsck->li_ref))
1105 lfsck_instance_cleanup(env, lfsck);
1108 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1110 return list_empty(&lad->lad_mdt_phase1_list) &&
1111 (!list_empty(&lad->lad_ost_phase2_list) ||
1112 list_empty(&lad->lad_ost_phase1_list));
1115 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1116 struct lfsck_component *com,
1119 struct lfsck_assistant_data *lad = com->lc_data;
1120 cfs_bitmap_t *bitmap = lad->lad_bitmap;
1122 LASSERT(com->lc_lfsck->li_master);
1123 LASSERT(bitmap != NULL);
1125 if (likely(bitmap->size > index)) {
1126 cfs_bitmap_set(bitmap, index);
1127 lad->lad_incomplete = 1;
1128 } else if (com->lc_type == LFSCK_TYPE_NAMESPACE) {
1129 struct lfsck_namespace *ns = com->lc_file_ram;
1131 ns->ln_flags |= LF_INCOMPLETE;
1135 static inline int lfsck_links_read(const struct lu_env *env,
1136 struct dt_object *obj,
1137 struct linkea_data *ldata)
1140 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1143 return __lfsck_links_read(env, obj, ldata);
1146 static inline int lfsck_links_read2(const struct lu_env *env,
1147 struct dt_object *obj,
1148 struct linkea_data *ldata)
1151 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1154 return __lfsck_links_read(env, obj, ldata);
1157 #endif /* _LFSCK_INTERNAL_H */