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 /* The size of MDT targets bitmap with nbits. Such bitmap records
223 * the MDTs that contain non-verified MDT-objects. */
224 __u32 ln_bitmap_size;
227 /* For further using. 256-bytes aligned now. */
228 __u64 ln_reserved[25];
231 enum lfsck_layout_inconsistency_type {
234 LLIT_UNMATCHED_PAIR = 2,
235 LLIT_MULTIPLE_REFERENCED = 3,
237 LLIT_INCONSISTENT_OWNER = 5,
239 LLIT_MAX = LLIT_OTHERS
242 struct lfsck_layout {
243 /* Magic number to detect that this struct contains valid data. */
246 /* See 'enum lfsck_status'. */
249 /* See 'enum lfsck_flags'. */
252 /* How many completed LFSCK runs on the device. */
253 __u32 ll_success_count;
255 /* How long the LFSCK phase1 has run in seconds. */
256 __u32 ll_run_time_phase1;
258 /* How long the LFSCK phase2 has run in seconds. */
259 __u32 ll_run_time_phase2;
261 /* Time for the last LFSCK completed in seconds since epoch. */
262 __u64 ll_time_last_complete;
264 /* Time for the latest LFSCK ran in seconds since epoch. */
265 __u64 ll_time_latest_start;
267 /* Time for the last LFSCK checkpoint in seconds since epoch. */
268 __u64 ll_time_last_checkpoint;
270 /* Position for the latest LFSCK started from. */
271 __u64 ll_pos_latest_start;
273 /* Position for the last LFSCK checkpoint. */
274 __u64 ll_pos_last_checkpoint;
276 /* Position for the first object to be fixed or
277 * failed to be checked in the phase1. */
278 __u64 ll_pos_first_inconsistent;
280 /* How many objects have been checked. */
281 __u64 ll_objs_checked_phase1;
283 /* How many objects failed to be processed. */
284 __u64 ll_objs_failed_phase1;
286 /* How many objects have been double scanned. */
287 __u64 ll_objs_checked_phase2;
289 /* How many objects failed to be processed during double scan. */
290 __u64 ll_objs_failed_phase2;
292 /* kinds of inconsistency have been or to be repaired.
293 * ll_objs_repaired[type - 1] is the count for the given @type. */
294 __u64 ll_objs_repaired[LLIT_MAX];
296 /* How many objects have been skipped because of related
297 * MDT(s)/OST(s) do not participate in the LFSCK */
298 __u64 ll_objs_skipped;
300 /* The size of ll_ost_bitmap with nbits. */
301 __u32 ll_bitmap_size;
303 /* For further using. 256-bytes aligned now. */
305 __u64 ll_reserved_2[11];
307 /* The OST targets bitmap to record the OSTs that contain
308 * non-verified OST-objects. */
309 __u8 ll_ost_bitmap[0];
312 struct lfsck_component;
313 struct lfsck_tgt_descs;
314 struct lfsck_tgt_desc;
316 struct lfsck_operations {
317 int (*lfsck_reset)(const struct lu_env *env,
318 struct lfsck_component *com,
321 void (*lfsck_fail)(const struct lu_env *env,
322 struct lfsck_component *com,
325 int (*lfsck_checkpoint)(const struct lu_env *env,
326 struct lfsck_component *com,
329 int (*lfsck_prep)(const struct lu_env *env,
330 struct lfsck_component *com,
331 struct lfsck_start_param *lsp);
333 int (*lfsck_exec_oit)(const struct lu_env *env,
334 struct lfsck_component *com,
335 struct dt_object *obj);
337 int (*lfsck_exec_dir)(const struct lu_env *env,
338 struct lfsck_component *com,
339 struct lu_dirent *ent,
342 int (*lfsck_post)(const struct lu_env *env,
343 struct lfsck_component *com,
347 int (*lfsck_dump)(const struct lu_env *env,
348 struct lfsck_component *com,
351 int (*lfsck_double_scan)(const struct lu_env *env,
352 struct lfsck_component *com);
354 void (*lfsck_data_release)(const struct lu_env *env,
355 struct lfsck_component *com);
357 void (*lfsck_quit)(const struct lu_env *env,
358 struct lfsck_component *com);
360 int (*lfsck_in_notify)(const struct lu_env *env,
361 struct lfsck_component *com,
362 struct lfsck_request *lr);
364 int (*lfsck_query)(const struct lu_env *env,
365 struct lfsck_component *com);
367 int (*lfsck_join)(const struct lu_env *env,
368 struct lfsck_component *com,
369 struct lfsck_start_param *lsp);
372 #define TGT_PTRS 256 /* number of pointers at 1st level */
373 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
375 struct lfsck_tgt_desc {
376 struct list_head ltd_orphan_list;
377 struct dt_device *ltd_tgt;
378 struct dt_device *ltd_key;
379 struct obd_export *ltd_exp;
380 struct list_head ltd_layout_list;
381 struct list_head ltd_layout_phase_list;
382 struct list_head ltd_namespace_list;
383 struct list_head ltd_namespace_phase_list;
386 __u32 ltd_layout_gen;
387 __u32 ltd_namespace_gen;
388 unsigned int ltd_dead:1,
390 ltd_namespace_done:1,
391 ltd_namespace_failed:1;
394 struct lfsck_tgt_desc_idx {
395 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
398 struct lfsck_tgt_descs {
399 /* list of known TGTs */
400 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
402 /* bitmap of TGTs available */
403 cfs_bitmap_t *ltd_tgts_bitmap;
405 /* for lfsck_tgt_desc::ltd_xxx_list */
408 /* for tgts table accessing and changes */
409 struct rw_semaphore ltd_rw_sem;
411 /* Temporary list for orphan targets. */
412 struct list_head ltd_orphan;
414 /* number of registered TGTs */
418 #define LTD_TGT(ltd, index) \
419 ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
420 ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
422 #define OST_TGT(lfsck, index) LTD_TGT(&lfsck->li_ost_descs, index)
423 #define MDT_TGT(lfsck, index) LTD_TGT(&lfsck->li_mdt_descs, index)
425 struct lfsck_component {
426 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
427 struct list_head lc_link;
429 /* into lfsck_instance::li_list_dir */
430 struct list_head lc_link_dir;
432 struct rw_semaphore lc_sem;
435 struct lfsck_position lc_pos_start;
436 struct lfsck_instance *lc_lfsck;
437 struct dt_object *lc_obj;
438 struct lfsck_operations *lc_ops;
442 struct lu_fid lc_fid_latest_scanned_phase2;
444 /* The time for last checkpoint, jiffies */
445 cfs_time_t lc_time_last_checkpoint;
447 /* The time for next checkpoint, jiffies */
448 cfs_time_t lc_time_next_checkpoint;
452 /* How many objects have been checked since last checkpoint. */
453 __u32 lc_new_checked;
455 /* How many objects have been scanned since last sleep. */
456 __u32 lc_new_scanned;
461 struct lfsck_instance {
462 struct mutex li_mutex;
465 /* Link into the lfsck_instance_list. */
466 struct list_head li_link;
468 /* For the components in (first) scanning via otable-based iteration. */
469 struct list_head li_list_scan;
471 /* For the components in scanning via directory traversal. Because
472 * directory traversal cannot guarantee all the object be scanned,
473 * so the component in the li_list_dir must be in li_list_scan. */
474 struct list_head li_list_dir;
476 /* For the components in double scanning. */
477 struct list_head li_list_double_scan;
479 /* For the components those are not scanning now. */
480 struct list_head li_list_idle;
483 atomic_t li_double_scan_count;
484 struct ptlrpc_thread li_thread;
486 /* The time for last checkpoint, jiffies */
487 cfs_time_t li_time_last_checkpoint;
489 /* The time for next checkpoint, jiffies */
490 cfs_time_t li_time_next_checkpoint;
492 lfsck_out_notify li_out_notify;
493 void *li_out_notify_data;
494 struct dt_device *li_next;
495 struct dt_device *li_bottom;
496 struct obd_device *li_obd;
497 struct ldlm_namespace *li_namespace;
498 struct local_oid_storage *li_los;
499 struct lu_fid li_local_root_fid; /* backend root "/" */
500 struct lu_fid li_global_root_fid; /* /ROOT */
501 struct dt_object *li_bookmark_obj;
502 struct dt_object *li_lpf_obj;
503 struct lu_client_seq *li_seq;
504 struct lfsck_bookmark li_bookmark_ram;
505 struct lfsck_bookmark li_bookmark_disk;
506 struct lfsck_position li_pos_current;
507 struct lfsck_position li_pos_checkpoint;
509 /* Obj for otable-based iteration */
510 struct dt_object *li_obj_oit;
512 /* Obj for directory traversal */
513 struct dt_object *li_obj_dir;
515 /* It for otable-based iteration */
516 struct dt_it *li_di_oit;
518 /* It for directory traversal */
519 struct dt_it *li_di_dir;
521 /* Description of OST */
522 struct lfsck_tgt_descs li_ost_descs;
524 /* Description of MDT */
525 struct lfsck_tgt_descs li_mdt_descs;
527 /* namespace-based directory traversal position. */
530 /* Arguments for low layer otable-based iteration. */
533 /* Arugments for namespace-based directory traversal. */
536 /* Schedule for every N objects. */
539 /* Sleep N jiffies for each schedule. */
542 /* How many objects have been scanned since last sleep. */
543 __u32 li_new_scanned;
545 /* The status when the LFSCK stopped or paused. */
548 /* The flags when the lFSCK stopped or paused. */
551 unsigned int li_oit_over:1, /* oit is finished. */
552 li_drop_dryrun:1, /* Ever dryrun, not now. */
553 li_master:1, /* Master instance or not. */
554 li_current_oit_processed:1,
558 struct lfsck_async_interpret_args {
559 struct lfsck_component *laia_com;
560 struct lfsck_tgt_descs *laia_ltds;
561 struct lfsck_tgt_desc *laia_ltd;
562 struct lfsck_request *laia_lr;
563 atomic_t *laia_count;
565 unsigned int laia_shared:1;
568 struct lfsck_thread_args {
569 struct lu_env lta_env;
570 struct lfsck_instance *lta_lfsck;
571 struct lfsck_component *lta_com;
572 struct lfsck_start_param *lta_lsp;
575 struct lfsck_assistant_req {
576 struct list_head lar_list;
579 struct lfsck_namespace_req {
580 struct lfsck_assistant_req lnr_lar;
581 struct dt_object *lnr_obj;
582 struct lu_fid lnr_fid;
583 __u64 lnr_oit_cookie;
584 __u64 lnr_dir_cookie;
592 struct lfsck_assistant_operations {
593 int (*la_handler_p1)(const struct lu_env *env,
594 struct lfsck_component *com,
595 struct lfsck_assistant_req *lar);
597 int (*la_handler_p2)(const struct lu_env *env,
598 struct lfsck_component *com);
600 void (*la_fill_pos)(const struct lu_env *env,
601 struct lfsck_component *com,
602 struct lfsck_position *pos);
604 int (*la_double_scan_result)(const struct lu_env *env,
605 struct lfsck_component *com,
608 void (*la_req_fini)(const struct lu_env *env,
609 struct lfsck_assistant_req *lar);
611 void (*la_sync_failures)(const struct lu_env *env,
612 struct lfsck_component *com,
613 struct lfsck_request *lr);
616 struct lfsck_assistant_data {
618 struct list_head lad_req_list;
620 /* list for the ost targets involve LFSCK. */
621 struct list_head lad_ost_list;
623 /* list for the ost targets in phase1 scanning. */
624 struct list_head lad_ost_phase1_list;
626 /* list for the ost targets in phase1 scanning. */
627 struct list_head lad_ost_phase2_list;
629 /* list for the mdt targets involve LFSCK. */
630 struct list_head lad_mdt_list;
632 /* list for the mdt targets in phase1 scanning. */
633 struct list_head lad_mdt_phase1_list;
635 /* list for the mdt targets in phase1 scanning. */
636 struct list_head lad_mdt_phase2_list;
638 const char *lad_name;
639 struct ptlrpc_thread lad_thread;
641 struct lfsck_assistant_operations *lad_ops;
643 cfs_bitmap_t *lad_bitmap;
647 int lad_assistant_status;
649 unsigned int lad_to_post:1,
650 lad_to_double_scan:1,
651 lad_in_double_scan:1,
656 #define LFSCK_TMPBUF_LEN 64
658 struct lfsck_thread_info {
659 struct lu_name lti_name_const;
660 struct lu_name lti_name;
661 struct lu_name lti_name2;
662 struct lu_buf lti_buf;
663 struct lu_buf lti_linkea_buf;
664 struct lu_buf lti_linkea_buf2;
665 struct lu_buf lti_big_buf;
666 struct lu_fid lti_fid;
667 struct lu_fid lti_fid2;
668 struct lu_fid lti_fid3;
669 struct lu_fid lti_fid4;
670 struct lu_fid lti_fid5;
671 struct lu_attr lti_la;
672 struct lu_attr lti_la2;
673 struct lu_attr lti_la3;
674 struct ost_id lti_oi;
676 struct lustre_mdt_attrs lti_lma;
677 /* old LMA for compatibility */
678 char lti_lma_old[LMA_OLD_SIZE];
680 struct dt_object_format lti_dof;
681 /* There will be '\0' at the end of the name. */
682 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
683 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
684 struct lfsck_request lti_lr;
685 struct lfsck_async_interpret_args lti_laia;
686 struct lfsck_async_interpret_args lti_laia2;
687 struct lfsck_start lti_start;
688 struct lfsck_stop lti_stop;
689 ldlm_policy_data_t lti_policy;
690 struct ldlm_res_id lti_resid;
692 struct filter_fid_old lti_old_pfid;
693 struct filter_fid lti_new_pfid;
695 struct dt_allocation_hint lti_hint;
696 struct lu_orphan_rec lti_rec;
697 struct lov_user_md lti_lum;
698 struct dt_insert_rec lti_dt_rec;
699 struct lu_object_conf lti_conf;
700 struct lu_seq_range lti_range;
704 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
705 struct lu_fid *fid, bool locked);
706 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
707 struct dt_object *obj, struct lustre_handle *lh,
708 __u64 bits, ldlm_mode_t mode);
709 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
710 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
711 struct lfsck_instance *lfsck,
712 const struct lu_fid *fid);
713 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
714 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
715 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
717 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
719 const char *lfsck_status2names(enum lfsck_status status);
720 void lfsck_component_cleanup(const struct lu_env *env,
721 struct lfsck_component *com);
722 void lfsck_instance_cleanup(const struct lu_env *env,
723 struct lfsck_instance *lfsck);
724 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
726 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
727 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
729 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
730 struct lfsck_position *pos, bool init);
731 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
732 void lfsck_control_speed(struct lfsck_instance *lfsck);
733 void lfsck_control_speed_by_self(struct lfsck_component *com);
734 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
735 struct lfsck_assistant_data *
736 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
738 int lfsck_async_interpret_common(const struct lu_env *env,
739 struct ptlrpc_request *req,
741 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
742 struct lfsck_request *lr,
743 struct ptlrpc_request_set *set,
744 ptlrpc_interpterer_t interpterer,
745 void *args, int request);
746 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
747 struct lfsck_start_param *lsp);
748 int lfsck_checkpoint_generic(const struct lu_env *env,
749 struct lfsck_component *com);
750 void lfsck_post_generic(const struct lu_env *env,
751 struct lfsck_component *com, int *result);
752 int lfsck_double_scan_generic(const struct lu_env *env,
753 struct lfsck_component *com, int status);
754 void lfsck_quit_generic(const struct lu_env *env,
755 struct lfsck_component *com);
758 int lfsck_master_engine(void *args);
759 int lfsck_assistant_engine(void *args);
761 /* lfsck_bookmark.c */
762 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
763 struct lfsck_bookmark *src);
764 int lfsck_bookmark_store(const struct lu_env *env,
765 struct lfsck_instance *lfsck);
766 int lfsck_bookmark_setup(const struct lu_env *env,
767 struct lfsck_instance *lfsck);
768 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
769 struct lfsck_start *start, bool reset);
771 /* lfsck_namespace.c */
772 int lfsck_namespace_trace_update(const struct lu_env *env,
773 struct lfsck_component *com,
774 const struct lu_fid *fid,
775 const __u8 flags, bool add);
776 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
777 struct linkea_data *ldata);
778 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
779 struct lfsck_component *com,
780 struct dt_object *obj,
781 struct linkea_data *ldata);
782 int lfsck_namespace_repair_dangling(const struct lu_env *env,
783 struct lfsck_component *com,
784 struct dt_object *child,
785 struct lfsck_namespace_req *lnr);
786 int lfsck_namespace_repair_dirent(const struct lu_env *env,
787 struct lfsck_component *com,
788 struct dt_object *parent,
789 struct dt_object *child,
790 const char *name, const char *name2,
791 __u16 type, bool update, bool dec);
792 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
793 struct dt_object *obj, const struct lu_name *cname,
794 const struct lu_fid *pfid);
795 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
796 char *name, struct lu_fid *pfid);
797 int lfsck_remove_name_entry(const struct lu_env *env,
798 struct lfsck_instance *lfsck,
799 struct dt_object *parent,
800 const char *name, __u32 type);
801 int lfsck_update_name_entry(const struct lu_env *env,
802 struct lfsck_instance *lfsck,
803 struct dt_object *parent, const char *name,
804 const struct lu_fid *pfid, __u32 type);
805 int lfsck_namespace_setup(const struct lu_env *env,
806 struct lfsck_instance *lfsck);
809 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
811 extern const char dot[];
812 extern const char dotdot[];
813 extern const char *lfsck_flags_names[];
814 extern const char *lfsck_param_names[];
815 extern struct lu_context_key lfsck_thread_key;
817 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
819 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
822 static inline struct lfsck_thread_info *
823 lfsck_env_info(const struct lu_env *env)
825 struct lfsck_thread_info *info;
827 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
828 LASSERT(info != NULL);
832 static inline const struct lu_name *
833 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
835 struct lu_name *lname;
837 lname = &lfsck_env_info(env)->lti_name_const;
838 lname->ln_name = area;
839 lname->ln_namelen = len;
844 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
850 static inline struct lu_buf *
851 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
855 buf = &lfsck_env_info(env)->lti_buf;
861 static inline const struct lu_buf *
862 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
866 buf = &lfsck_env_info(env)->lti_buf;
867 buf->lb_buf = (void *)area;
872 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
874 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
877 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
879 return lu_object_fid(&obj->do_lu);
882 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
884 memset(pos, 0, sizeof(*pos));
887 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
889 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
892 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
893 const struct lfsck_position *pos2)
895 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
898 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
901 if (fid_is_zero(&pos1->lp_dir_parent) &&
902 !fid_is_zero(&pos2->lp_dir_parent))
905 if (!fid_is_zero(&pos1->lp_dir_parent) &&
906 fid_is_zero(&pos2->lp_dir_parent))
909 if (fid_is_zero(&pos1->lp_dir_parent) &&
910 fid_is_zero(&pos2->lp_dir_parent))
913 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
915 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
918 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
924 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
925 struct lfsck_position *src)
927 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
928 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
929 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
932 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
933 struct lfsck_position *src)
935 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
936 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
937 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
940 static inline umode_t lfsck_object_type(const struct dt_object *obj)
942 return lu_object_attr(&obj->do_lu);
945 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
947 struct lu_object_header *loh = obj->do_lu.lo_header;
949 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
952 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
954 lu_object_get(&obj->do_lu);
958 static inline void lfsck_object_put(const struct lu_env *env,
959 struct dt_object *obj)
961 lu_object_put(env, &obj->do_lu);
964 static inline u32 lfsck_dev_idx(struct dt_device *dev)
966 return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
969 static inline struct dt_object *
970 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
971 const struct lu_fid *fid)
973 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
974 struct dt_object *obj;
976 conf->loc_flags = LOC_F_NOWAIT;
977 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
978 if (unlikely(obj == NULL))
979 return ERR_PTR(-ENOENT);
984 static inline struct dt_object *
985 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
986 const struct lu_fid *fid)
988 struct dt_object *obj;
990 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
991 if (unlikely(obj == NULL))
992 return ERR_PTR(-ENOENT);
997 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
998 struct lfsck_instance *lfsck,
999 const struct lu_fid *fid)
1001 return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
1004 static inline struct dt_object *
1005 lfsck_object_find_bottom(const struct lu_env *env, struct lfsck_instance *lfsck,
1006 const struct lu_fid *fid)
1008 struct dt_device *dev;
1011 idx = lfsck_find_mdt_idx_by_fid(env, lfsck, fid);
1013 return ERR_PTR(idx);
1015 if (idx == lfsck_dev_idx(lfsck->li_bottom)) {
1016 dev = lfsck->li_bottom;
1018 struct lfsck_tgt_desc *ltd;
1020 ltd = LTD_TGT(&lfsck->li_mdt_descs, idx);
1021 if (unlikely(ltd == NULL))
1022 return ERR_PTR(-ENODEV);
1027 return lfsck_object_find_by_dev(env, dev, fid);
1030 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
1033 struct lfsck_tgt_desc *ltd;
1035 ltd = LTD_TGT(ltds, index);
1037 atomic_inc(<d->ltd_ref);
1042 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
1044 if (atomic_dec_and_test(<d->ltd_ref))
1048 static inline struct lfsck_component *
1049 lfsck_component_get(struct lfsck_component *com)
1051 atomic_inc(&com->lc_ref);
1056 static inline void lfsck_component_put(const struct lu_env *env,
1057 struct lfsck_component *com)
1059 if (atomic_dec_and_test(&com->lc_ref)) {
1060 if (com->lc_obj != NULL)
1061 lu_object_put_nocache(env, &com->lc_obj->do_lu);
1062 if (com->lc_file_ram != NULL)
1063 OBD_FREE(com->lc_file_ram, com->lc_file_size);
1064 if (com->lc_file_disk != NULL)
1065 OBD_FREE(com->lc_file_disk, com->lc_file_size);
1066 if (com->lc_data != NULL) {
1067 LASSERT(com->lc_ops->lfsck_data_release != NULL);
1069 com->lc_ops->lfsck_data_release(env, com);
1076 static inline struct lfsck_instance *
1077 lfsck_instance_get(struct lfsck_instance *lfsck)
1079 atomic_inc(&lfsck->li_ref);
1084 static inline void lfsck_instance_put(const struct lu_env *env,
1085 struct lfsck_instance *lfsck)
1087 if (atomic_dec_and_test(&lfsck->li_ref))
1088 lfsck_instance_cleanup(env, lfsck);
1091 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1093 return list_empty(&lad->lad_mdt_phase1_list) &&
1094 (!list_empty(&lad->lad_ost_phase2_list) ||
1095 list_empty(&lad->lad_ost_phase1_list));
1098 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1099 struct lfsck_component *com,
1102 struct lfsck_assistant_data *lad = com->lc_data;
1103 cfs_bitmap_t *bitmap = lad->lad_bitmap;
1105 LASSERT(com->lc_lfsck->li_master);
1106 LASSERT(bitmap != NULL);
1107 LASSERTF(bitmap->size > index, "invalid index: nbits %d, index %u\n",
1108 bitmap->size, index);
1110 cfs_bitmap_set(bitmap, index);
1111 lad->lad_incomplete = 1;
1114 static inline int lfsck_links_read(const struct lu_env *env,
1115 struct dt_object *obj,
1116 struct linkea_data *ldata)
1119 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1122 return __lfsck_links_read(env, obj, ldata);
1125 static inline int lfsck_links_read2(const struct lu_env *env,
1126 struct dt_object *obj,
1127 struct linkea_data *ldata)
1130 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1133 return __lfsck_links_read(env, obj, ldata);
1136 #endif /* _LFSCK_INTERNAL_H */