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,
116 LNTF_UNCERTAIN_LMV = 0x10,
117 LNTF_RECHECK_NAME_HASH = 0x20,
121 enum lfsck_namespace_inconsistency_type {
124 LNIT_UNMATCHED_PAIRS = 2,
131 struct lfsck_namespace {
132 /* Magic number to detect that this struct contains valid data. */
135 /* See 'enum lfsck_status'. */
138 /* See 'enum lfsck_flags'. */
141 /* How many completed LFSCK runs on the device. */
142 __u32 ln_success_count;
144 /* How long the LFSCK phase1 has run in seconds. */
145 __u32 ln_run_time_phase1;
147 /* How long the LFSCK phase2 has run in seconds. */
148 __u32 ln_run_time_phase2;
150 /* Time for the last LFSCK completed in seconds since epoch. */
151 __u64 ln_time_last_complete;
153 /* Time for the latest LFSCK ran in seconds since epoch. */
154 __u64 ln_time_latest_start;
156 /* Time for the last LFSCK checkpoint in seconds since epoch. */
157 __u64 ln_time_last_checkpoint;
159 /* Position for the latest LFSCK started from. */
160 struct lfsck_position ln_pos_latest_start;
162 /* Position for the last LFSCK checkpoint. */
163 struct lfsck_position ln_pos_last_checkpoint;
165 /* Position for the first should be updated object. */
166 struct lfsck_position ln_pos_first_inconsistent;
168 /* How many items (including dir) have been checked. */
169 __u64 ln_items_checked;
171 /* How many items have been repaired. */
172 __u64 ln_items_repaired;
174 /* How many items failed to be processed. */
175 __u64 ln_items_failed;
177 /* How many directories have been traversed. */
178 __u64 ln_dirs_checked;
180 /* How many objects have been double scanned. */
181 __u64 ln_objs_checked_phase2;
183 /* How many objects have been reparied during double scan. */
184 __u64 ln_objs_repaired_phase2;
186 /* How many objects failed to be processed during double scan. */
187 __u64 ln_objs_failed_phase2;
189 /* How many objects with nlink fixed. */
190 __u64 ln_objs_nlink_repaired;
192 /* The latest object has been processed (failed) during double scan. */
193 struct lu_fid ln_fid_latest_scanned_phase2;
195 /* How many FID-in-dirent entries have been repaired. */
196 __u64 ln_dirent_repaired;
198 /* How many linkEA entries have been repaired. */
199 __u64 ln_linkea_repaired;
201 /* How many multiple-linked objects have been checked. */
202 __u64 ln_mul_linked_checked;
204 /* How many multiple-linked objects have been repaired. */
205 __u64 ln_mul_linked_repaired;
207 /* How many undefined inconsistency found in phase2. */
208 __u64 ln_unknown_inconsistency;
210 /* How many unmatched pairs have been repaired. */
211 __u64 ln_unmatched_pairs_repaired;
213 /* How many dangling name entries have been found/repaired. */
214 __u64 ln_dangling_repaired;
216 /* How many multiple referenced name entries have been
218 __u64 ln_mul_ref_repaired;
220 /* How many name entries with bad file type have been repaired. */
221 __u64 ln_bad_type_repaired;
223 /* How many lost name entries have been re-inserted. */
224 __u64 ln_lost_dirent_repaired;
226 /* How many objects under /lost+found have been scanned. */
227 __u64 ln_local_lpf_scanned;
229 /* How many objects under /lost+found have been moved to
230 * namespace visible directory. */
231 __u64 ln_local_lpf_moved;
233 /* How many objects under /lost+found have been skipped. */
234 __u64 ln_local_lpf_skipped;
236 /* How many objects under /lost+found failed to be processed. */
237 __u64 ln_local_lpf_failed;
239 /* How many striped directories (master) have been scanned. */
240 __u64 ln_striped_dirs_scanned;
242 /* How many striped directories (master) have been repaired. */
243 __u64 ln_striped_dirs_repaired;
245 /* How many striped directories (master) failed verification. */
246 __u64 ln_striped_dirs_failed;
248 /* How many striped directories (master) has been disabled. */
249 __u64 ln_striped_dirs_disabled;
251 /* How many striped directory's (master) have been skipped
252 * (for shards verification) because of lost master LMV EA. */
253 __u64 ln_striped_dirs_skipped;
255 /* How many striped directory's shards (slave) have been scanned. */
256 __u64 ln_striped_shards_scanned;
258 /* How many striped directory's shards (slave) have been repaired. */
259 __u64 ln_striped_shards_repaired;
261 /* How many striped directory's shards (slave) failed verification. */
262 __u64 ln_striped_shards_failed;
264 /* How many striped directory's shards (slave) have been skipped
265 * (for name hash verification) because do not know whether the slave
266 * LMV EA is valid or not. */
267 __u64 ln_striped_shards_skipped;
269 /* How many name entries under striped directory with bad name
270 * hash have been repaired. */
271 __u64 ln_name_hash_repaired;
273 /* The size of MDT targets bitmap with nbits. Such bitmap records
274 * the MDTs that contain non-verified MDT-objects. */
275 __u32 ln_bitmap_size;
278 /* For further using. 256-bytes aligned now. */
279 __u64 ln_reserved[15];
282 enum lfsck_layout_inconsistency_type {
285 LLIT_UNMATCHED_PAIR = 2,
286 LLIT_MULTIPLE_REFERENCED = 3,
288 LLIT_INCONSISTENT_OWNER = 5,
290 LLIT_MAX = LLIT_OTHERS
293 struct lfsck_layout {
294 /* Magic number to detect that this struct contains valid data. */
297 /* See 'enum lfsck_status'. */
300 /* See 'enum lfsck_flags'. */
303 /* How many completed LFSCK runs on the device. */
304 __u32 ll_success_count;
306 /* How long the LFSCK phase1 has run in seconds. */
307 __u32 ll_run_time_phase1;
309 /* How long the LFSCK phase2 has run in seconds. */
310 __u32 ll_run_time_phase2;
312 /* Time for the last LFSCK completed in seconds since epoch. */
313 __u64 ll_time_last_complete;
315 /* Time for the latest LFSCK ran in seconds since epoch. */
316 __u64 ll_time_latest_start;
318 /* Time for the last LFSCK checkpoint in seconds since epoch. */
319 __u64 ll_time_last_checkpoint;
321 /* Position for the latest LFSCK started from. */
322 __u64 ll_pos_latest_start;
324 /* Position for the last LFSCK checkpoint. */
325 __u64 ll_pos_last_checkpoint;
327 /* Position for the first object to be fixed or
328 * failed to be checked in the phase1. */
329 __u64 ll_pos_first_inconsistent;
331 /* How many objects have been checked. */
332 __u64 ll_objs_checked_phase1;
334 /* How many objects failed to be processed. */
335 __u64 ll_objs_failed_phase1;
337 /* How many objects have been double scanned. */
338 __u64 ll_objs_checked_phase2;
340 /* How many objects failed to be processed during double scan. */
341 __u64 ll_objs_failed_phase2;
343 /* kinds of inconsistency have been or to be repaired.
344 * ll_objs_repaired[type - 1] is the count for the given @type. */
345 __u64 ll_objs_repaired[LLIT_MAX];
347 /* How many objects have been skipped because of related
348 * MDT(s)/OST(s) do not participate in the LFSCK */
349 __u64 ll_objs_skipped;
351 /* The size of ll_ost_bitmap with nbits. */
352 __u32 ll_bitmap_size;
354 /* For further using. 256-bytes aligned now. */
356 __u64 ll_reserved_2[11];
358 /* The OST targets bitmap to record the OSTs that contain
359 * non-verified OST-objects. */
360 __u8 ll_ost_bitmap[0];
363 struct lfsck_component;
364 struct lfsck_tgt_descs;
365 struct lfsck_tgt_desc;
367 struct lfsck_operations {
368 int (*lfsck_reset)(const struct lu_env *env,
369 struct lfsck_component *com,
372 void (*lfsck_fail)(const struct lu_env *env,
373 struct lfsck_component *com,
376 void (*lfsck_close_dir)(const struct lu_env *env,
377 struct lfsck_component *com);
379 int (*lfsck_open_dir)(const struct lu_env *env,
380 struct lfsck_component *com);
382 int (*lfsck_checkpoint)(const struct lu_env *env,
383 struct lfsck_component *com,
386 int (*lfsck_prep)(const struct lu_env *env,
387 struct lfsck_component *com,
388 struct lfsck_start_param *lsp);
390 int (*lfsck_exec_oit)(const struct lu_env *env,
391 struct lfsck_component *com,
392 struct dt_object *obj);
394 int (*lfsck_exec_dir)(const struct lu_env *env,
395 struct lfsck_component *com,
396 struct lu_dirent *ent,
399 int (*lfsck_post)(const struct lu_env *env,
400 struct lfsck_component *com,
404 int (*lfsck_dump)(const struct lu_env *env,
405 struct lfsck_component *com,
408 int (*lfsck_double_scan)(const struct lu_env *env,
409 struct lfsck_component *com);
411 void (*lfsck_data_release)(const struct lu_env *env,
412 struct lfsck_component *com);
414 void (*lfsck_quit)(const struct lu_env *env,
415 struct lfsck_component *com);
417 int (*lfsck_in_notify)(const struct lu_env *env,
418 struct lfsck_component *com,
419 struct lfsck_request *lr,
422 int (*lfsck_query)(const struct lu_env *env,
423 struct lfsck_component *com);
425 int (*lfsck_join)(const struct lu_env *env,
426 struct lfsck_component *com,
427 struct lfsck_start_param *lsp);
430 #define TGT_PTRS 256 /* number of pointers at 1st level */
431 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
433 struct lfsck_tgt_desc {
434 struct list_head ltd_orphan_list;
435 struct dt_device *ltd_tgt;
436 struct dt_device *ltd_key;
437 struct obd_export *ltd_exp;
438 struct list_head ltd_layout_list;
439 struct list_head ltd_layout_phase_list;
440 struct list_head ltd_namespace_list;
441 struct list_head ltd_namespace_phase_list;
444 __u32 ltd_layout_gen;
445 __u32 ltd_namespace_gen;
446 unsigned int ltd_dead:1,
448 ltd_namespace_done:1,
449 ltd_namespace_failed:1;
452 struct lfsck_tgt_desc_idx {
453 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
456 struct lfsck_tgt_descs {
457 /* list of known TGTs */
458 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
460 /* bitmap of TGTs available */
461 cfs_bitmap_t *ltd_tgts_bitmap;
463 /* for lfsck_tgt_desc::ltd_xxx_list */
466 /* for tgts table accessing and changes */
467 struct rw_semaphore ltd_rw_sem;
469 /* Temporary list for orphan targets. */
470 struct list_head ltd_orphan;
472 /* number of registered TGTs */
476 #define LTD_TGT(ltd, index) \
477 ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
478 ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
480 #define OST_TGT(lfsck, index) LTD_TGT(&lfsck->li_ost_descs, index)
481 #define MDT_TGT(lfsck, index) LTD_TGT(&lfsck->li_mdt_descs, index)
483 struct lfsck_component {
484 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
485 struct list_head lc_link;
487 /* into lfsck_instance::li_list_dir */
488 struct list_head lc_link_dir;
490 struct rw_semaphore lc_sem;
493 struct lfsck_position lc_pos_start;
494 struct lfsck_instance *lc_lfsck;
495 struct dt_object *lc_obj;
496 struct lfsck_operations *lc_ops;
500 struct lu_fid lc_fid_latest_scanned_phase2;
502 /* The time for last checkpoint, jiffies */
503 cfs_time_t lc_time_last_checkpoint;
505 /* The time for next checkpoint, jiffies */
506 cfs_time_t lc_time_next_checkpoint;
510 /* How many objects have been checked since last checkpoint. */
511 __u32 lc_new_checked;
513 /* How many objects have been scanned since last sleep. */
514 __u32 lc_new_scanned;
519 #define LFSCK_LMV_MAX_STRIPES LMV_MAX_STRIPE_COUNT
520 #define LFSCK_LMV_DEF_STRIPES 4
522 struct lfsck_slave_lmv_rec {
523 struct lu_fid lslr_fid;
524 __u32 lslr_stripe_count;
525 __u32 lslr_index; /* the index in name or in slave lmv */
526 __u32 lslr_hash_type;
531 struct lmv_mds_md_v1 ll_lmv;
533 int ll_stripes_allocated;
534 int ll_stripes_filled;
536 __u32 ll_max_stripe_count;
537 __u32 ll_max_filled_off;
539 unsigned int ll_lmv_master:1,
546 struct lfsck_slave_lmv_rec *ll_lslr;
549 struct lfsck_instance {
550 struct mutex li_mutex;
553 /* Link into the lfsck_instance_list. */
554 struct list_head li_link;
556 /* For the components in (first) scanning via otable-based iteration. */
557 struct list_head li_list_scan;
559 /* For the components in scanning via directory traversal. Because
560 * directory traversal cannot guarantee all the object be scanned,
561 * so the component in the li_list_dir must be in li_list_scan. */
562 struct list_head li_list_dir;
564 /* For the components in double scanning. */
565 struct list_head li_list_double_scan;
567 /* For the components those are not scanning now. */
568 struct list_head li_list_idle;
571 atomic_t li_double_scan_count;
572 struct ptlrpc_thread li_thread;
574 /* The time for last checkpoint, jiffies */
575 cfs_time_t li_time_last_checkpoint;
577 /* The time for next checkpoint, jiffies */
578 cfs_time_t li_time_next_checkpoint;
580 lfsck_out_notify li_out_notify;
581 void *li_out_notify_data;
582 struct dt_device *li_next;
583 struct dt_device *li_bottom;
584 struct obd_device *li_obd;
585 struct ldlm_namespace *li_namespace;
586 struct local_oid_storage *li_los;
587 struct lu_fid li_local_root_fid; /* backend root "/" */
588 struct lu_fid li_global_root_fid; /* /ROOT */
589 struct dt_object *li_bookmark_obj;
590 struct dt_object *li_lpf_obj;
591 struct lu_client_seq *li_seq;
592 struct lfsck_bookmark li_bookmark_ram;
593 struct lfsck_bookmark li_bookmark_disk;
594 struct lfsck_position li_pos_current;
595 struct lfsck_position li_pos_checkpoint;
597 struct lfsck_lmv *li_lmv;
599 /* Obj for otable-based iteration */
600 struct dt_object *li_obj_oit;
602 /* Obj for directory traversal */
603 struct dt_object *li_obj_dir;
605 /* It for otable-based iteration */
606 struct dt_it *li_di_oit;
608 /* It for directory traversal */
609 struct dt_it *li_di_dir;
611 /* Description of OST */
612 struct lfsck_tgt_descs li_ost_descs;
614 /* Description of MDT */
615 struct lfsck_tgt_descs li_mdt_descs;
617 /* namespace-based directory traversal position. */
620 /* Arguments for low layer otable-based iteration. */
623 /* Arugments for namespace-based directory traversal. */
626 /* Schedule for every N objects. */
629 /* Sleep N jiffies for each schedule. */
632 /* How many objects have been scanned since last sleep. */
633 __u32 li_new_scanned;
635 /* The status when the LFSCK stopped or paused. */
638 /* The flags when the lFSCK stopped or paused. */
641 unsigned int li_oit_over:1, /* oit is finished. */
642 li_drop_dryrun:1, /* Ever dryrun, not now. */
643 li_master:1, /* Master instance or not. */
644 li_current_oit_processed:1,
648 struct lfsck_async_interpret_args {
649 struct lfsck_component *laia_com;
650 struct lfsck_tgt_descs *laia_ltds;
651 struct lfsck_tgt_desc *laia_ltd;
652 struct lfsck_request *laia_lr;
653 atomic_t *laia_count;
655 unsigned int laia_shared:1;
658 struct lfsck_thread_args {
659 struct lu_env lta_env;
660 struct lfsck_instance *lta_lfsck;
661 struct lfsck_component *lta_com;
662 struct lfsck_start_param *lta_lsp;
665 struct lfsck_assistant_req {
666 struct list_head lar_list;
669 struct lfsck_namespace_req {
670 struct lfsck_assistant_req lnr_lar;
671 struct dt_object *lnr_obj;
672 struct lfsck_lmv *lnr_lmv;
673 struct lu_fid lnr_fid;
674 __u64 lnr_oit_cookie;
675 __u64 lnr_dir_cookie;
683 struct lfsck_assistant_operations {
684 int (*la_handler_p1)(const struct lu_env *env,
685 struct lfsck_component *com,
686 struct lfsck_assistant_req *lar);
688 int (*la_handler_p2)(const struct lu_env *env,
689 struct lfsck_component *com);
691 void (*la_fill_pos)(const struct lu_env *env,
692 struct lfsck_component *com,
693 struct lfsck_position *pos);
695 int (*la_double_scan_result)(const struct lu_env *env,
696 struct lfsck_component *com,
699 void (*la_req_fini)(const struct lu_env *env,
700 struct lfsck_assistant_req *lar);
702 void (*la_sync_failures)(const struct lu_env *env,
703 struct lfsck_component *com,
704 struct lfsck_request *lr);
707 struct lfsck_assistant_data {
709 struct list_head lad_req_list;
711 /* list for the ost targets involve LFSCK. */
712 struct list_head lad_ost_list;
714 /* list for the ost targets in phase1 scanning. */
715 struct list_head lad_ost_phase1_list;
717 /* list for the ost targets in phase1 scanning. */
718 struct list_head lad_ost_phase2_list;
720 /* list for the mdt targets involve LFSCK. */
721 struct list_head lad_mdt_list;
723 /* list for the mdt targets in phase1 scanning. */
724 struct list_head lad_mdt_phase1_list;
726 /* list for the mdt targets in phase1 scanning. */
727 struct list_head lad_mdt_phase2_list;
729 const char *lad_name;
730 struct ptlrpc_thread lad_thread;
732 struct lfsck_assistant_operations *lad_ops;
734 cfs_bitmap_t *lad_bitmap;
738 int lad_assistant_status;
740 unsigned int lad_to_post:1,
741 lad_to_double_scan:1,
742 lad_in_double_scan:1,
747 #define LFSCK_TMPBUF_LEN 64
749 struct lfsck_thread_info {
750 struct lu_name lti_name_const;
751 struct lu_name lti_name;
752 struct lu_name lti_name2;
753 struct lu_buf lti_buf;
754 struct lu_buf lti_linkea_buf;
755 struct lu_buf lti_linkea_buf2;
756 struct lu_buf lti_big_buf;
757 struct lu_fid lti_fid;
758 struct lu_fid lti_fid2;
759 struct lu_fid lti_fid3;
760 struct lu_fid lti_fid4;
761 struct lu_fid lti_fid5;
762 struct lu_attr lti_la;
763 struct lu_attr lti_la2;
764 struct lu_attr lti_la3;
765 struct ost_id lti_oi;
767 struct lustre_mdt_attrs lti_lma;
768 /* old LMA for compatibility */
769 char lti_lma_old[LMA_OLD_SIZE];
771 struct dt_object_format lti_dof;
772 /* There will be '\0' at the end of the name. */
773 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
774 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
775 char lti_tmpbuf2[LFSCK_TMPBUF_LEN];
776 struct lfsck_request lti_lr;
777 struct lfsck_async_interpret_args lti_laia;
778 struct lfsck_async_interpret_args lti_laia2;
779 struct lfsck_start lti_start;
780 struct lfsck_stop lti_stop;
781 ldlm_policy_data_t lti_policy;
782 struct ldlm_res_id lti_resid;
784 struct filter_fid_old lti_old_pfid;
785 struct filter_fid lti_new_pfid;
787 struct dt_allocation_hint lti_hint;
788 struct lu_orphan_rec lti_rec;
789 struct lov_user_md lti_lum;
790 struct dt_insert_rec lti_dt_rec;
791 struct lu_object_conf lti_conf;
792 struct lu_seq_range lti_range;
793 struct lmv_mds_md_v1 lti_lmv;
794 struct lmv_mds_md_v1 lti_lmv2;
795 struct lmv_mds_md_v1 lti_lmv3;
796 struct lmv_mds_md_v1 lti_lmv4;
800 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
801 struct lu_fid *fid, bool locked);
802 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
803 struct dt_object *obj, struct lustre_handle *lh,
804 __u64 bits, ldlm_mode_t mode);
805 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
806 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
807 struct lfsck_instance *lfsck,
808 const struct lu_fid *fid);
809 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
810 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
811 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
813 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
815 const char *lfsck_status2names(enum lfsck_status status);
816 void lfsck_component_cleanup(const struct lu_env *env,
817 struct lfsck_component *com);
818 void lfsck_instance_cleanup(const struct lu_env *env,
819 struct lfsck_instance *lfsck);
820 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
822 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
823 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
825 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
826 struct lfsck_position *pos, bool init);
827 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
828 void lfsck_control_speed(struct lfsck_instance *lfsck);
829 void lfsck_control_speed_by_self(struct lfsck_component *com);
830 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
831 struct lfsck_assistant_data *
832 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
834 int lfsck_async_interpret_common(const struct lu_env *env,
835 struct ptlrpc_request *req,
837 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
838 struct lfsck_request *lr,
839 struct ptlrpc_request_set *set,
840 ptlrpc_interpterer_t interpterer,
841 void *args, int request);
842 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
843 struct lfsck_start_param *lsp);
844 int lfsck_checkpoint_generic(const struct lu_env *env,
845 struct lfsck_component *com);
846 void lfsck_post_generic(const struct lu_env *env,
847 struct lfsck_component *com, int *result);
848 int lfsck_double_scan_generic(const struct lu_env *env,
849 struct lfsck_component *com, int status);
850 void lfsck_quit_generic(const struct lu_env *env,
851 struct lfsck_component *com);
854 int lfsck_unpack_ent(struct lu_dirent *ent, __u64 *cookie, __u16 *type);
855 int lfsck_master_engine(void *args);
856 int lfsck_assistant_engine(void *args);
858 /* lfsck_bookmark.c */
859 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
860 struct lfsck_bookmark *src);
861 int lfsck_bookmark_store(const struct lu_env *env,
862 struct lfsck_instance *lfsck);
863 int lfsck_bookmark_setup(const struct lu_env *env,
864 struct lfsck_instance *lfsck);
865 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
866 struct lfsck_start *start, bool reset);
868 /* lfsck_namespace.c */
869 int lfsck_namespace_trace_update(const struct lu_env *env,
870 struct lfsck_component *com,
871 const struct lu_fid *fid,
872 const __u8 flags, bool add);
873 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
874 struct linkea_data *ldata);
875 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
876 struct lfsck_component *com,
877 struct dt_object *obj,
878 struct linkea_data *ldata);
879 int lfsck_namespace_repair_dangling(const struct lu_env *env,
880 struct lfsck_component *com,
881 struct dt_object *child,
882 struct lfsck_namespace_req *lnr);
883 int lfsck_namespace_repair_dirent(const struct lu_env *env,
884 struct lfsck_component *com,
885 struct dt_object *parent,
886 struct dt_object *child,
887 const char *name, const char *name2,
888 __u16 type, bool update, bool dec);
889 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
890 struct dt_object *obj, const struct lu_name *cname,
891 const struct lu_fid *pfid);
892 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
893 char *name, struct lu_fid *pfid);
894 int lfsck_remove_name_entry(const struct lu_env *env,
895 struct lfsck_instance *lfsck,
896 struct dt_object *parent,
897 const char *name, __u32 type);
898 int lfsck_update_name_entry(const struct lu_env *env,
899 struct lfsck_instance *lfsck,
900 struct dt_object *parent, const char *name,
901 const struct lu_fid *pfid, __u32 type);
902 int lfsck_namespace_setup(const struct lu_env *env,
903 struct lfsck_instance *lfsck);
905 /* lfsck_striped_dir.c */
906 void lfsck_lmv_put(const struct lu_env *env, struct lfsck_lmv *llmv);
907 int lfsck_read_stripe_lmv(const struct lu_env *env, struct dt_object *obj,
908 struct lmv_mds_md_v1 *lmv);
909 int lfsck_shard_name_to_index(const struct lu_env *env, const char *name,
910 int namelen, __u16 type,
911 const struct lu_fid *fid);
912 bool lfsck_is_valid_slave_name_entry(const struct lu_env *env,
913 struct lfsck_lmv *llmv,
914 const char *name, int namelen);
915 int lfsck_namespace_check_name(const struct lu_env *env,
916 struct dt_object *parent,
917 struct dt_object *child,
918 const struct lu_name *cname);
919 int lfsck_namespace_update_lmv(const struct lu_env *env,
920 struct lfsck_component *com,
921 struct dt_object *obj,
922 struct lmv_mds_md_v1 *lmv, bool locked);
923 int lfsck_namespace_verify_stripe_slave(const struct lu_env *env,
924 struct lfsck_component *com,
925 struct dt_object *obj,
926 struct lfsck_lmv *llmv);
927 int lfsck_namespace_repair_bad_name_hash(const struct lu_env *env,
928 struct lfsck_component *com,
929 struct dt_object *shard,
930 struct lfsck_lmv *llmv,
932 int lfsck_namespace_striped_dir_rescan(const struct lu_env *env,
933 struct lfsck_component *com,
934 struct lfsck_namespace_req *lnr);
937 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
939 extern const char dot[];
940 extern const char dotdot[];
941 extern const char *lfsck_flags_names[];
942 extern const char *lfsck_param_names[];
943 extern struct lu_context_key lfsck_thread_key;
945 static inline bool name_is_dot_or_dotdot(const char *name, int namelen)
947 return name[0] == '.' &&
948 (namelen == 1 || (namelen == 2 && name[1] == '.'));
951 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
953 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
956 static inline struct lfsck_thread_info *
957 lfsck_env_info(const struct lu_env *env)
959 struct lfsck_thread_info *info;
961 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
962 LASSERT(info != NULL);
966 static inline const struct lu_name *
967 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
969 struct lu_name *lname;
971 lname = &lfsck_env_info(env)->lti_name_const;
972 lname->ln_name = area;
973 lname->ln_namelen = len;
978 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
984 static inline struct lu_buf *
985 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
989 buf = &lfsck_env_info(env)->lti_buf;
995 static inline const struct lu_buf *
996 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
1000 buf = &lfsck_env_info(env)->lti_buf;
1001 buf->lb_buf = (void *)area;
1006 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
1008 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
1011 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
1013 return lu_object_fid(&obj->do_lu);
1016 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
1018 memset(pos, 0, sizeof(*pos));
1021 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
1023 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
1026 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
1027 const struct lfsck_position *pos2)
1029 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
1032 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
1035 if (fid_is_zero(&pos1->lp_dir_parent) &&
1036 !fid_is_zero(&pos2->lp_dir_parent))
1039 if (!fid_is_zero(&pos1->lp_dir_parent) &&
1040 fid_is_zero(&pos2->lp_dir_parent))
1043 if (fid_is_zero(&pos1->lp_dir_parent) &&
1044 fid_is_zero(&pos2->lp_dir_parent))
1047 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
1049 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
1052 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
1058 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
1059 struct lfsck_position *src)
1061 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
1062 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
1063 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
1066 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
1067 struct lfsck_position *src)
1069 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
1070 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
1071 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
1074 static inline umode_t lfsck_object_type(const struct dt_object *obj)
1076 return lu_object_attr(&obj->do_lu);
1079 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
1081 struct lu_object_header *loh = obj->do_lu.lo_header;
1083 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
1086 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
1088 lu_object_get(&obj->do_lu);
1092 static inline void lfsck_object_put(const struct lu_env *env,
1093 struct dt_object *obj)
1095 lu_object_put(env, &obj->do_lu);
1098 static inline u32 lfsck_dev_idx(struct dt_device *dev)
1100 return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
1103 static inline struct dt_object *
1104 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
1105 const struct lu_fid *fid)
1107 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
1108 struct dt_object *obj;
1110 conf->loc_flags = LOC_F_NOWAIT;
1111 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
1112 if (unlikely(obj == NULL))
1113 return ERR_PTR(-ENOENT);
1118 static inline struct dt_object *
1119 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
1120 const struct lu_fid *fid)
1122 struct dt_object *obj;
1124 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
1125 if (unlikely(obj == NULL))
1126 return ERR_PTR(-ENOENT);
1131 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
1132 struct lfsck_instance *lfsck,
1133 const struct lu_fid *fid)
1135 return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
1138 static inline struct dt_object *
1139 lfsck_object_find_bottom(const struct lu_env *env, struct lfsck_instance *lfsck,
1140 const struct lu_fid *fid)
1142 struct dt_device *dev;
1145 idx = lfsck_find_mdt_idx_by_fid(env, lfsck, fid);
1147 return ERR_PTR(idx);
1149 if (idx == lfsck_dev_idx(lfsck->li_bottom)) {
1150 dev = lfsck->li_bottom;
1152 struct lfsck_tgt_desc *ltd;
1154 ltd = LTD_TGT(&lfsck->li_mdt_descs, idx);
1155 if (unlikely(ltd == NULL))
1156 return ERR_PTR(-ENODEV);
1161 return lfsck_object_find_by_dev(env, dev, fid);
1164 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
1167 struct lfsck_tgt_desc *ltd;
1169 ltd = LTD_TGT(ltds, index);
1171 atomic_inc(<d->ltd_ref);
1176 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
1178 if (atomic_dec_and_test(<d->ltd_ref))
1182 static inline struct lfsck_component *
1183 lfsck_component_get(struct lfsck_component *com)
1185 atomic_inc(&com->lc_ref);
1190 static inline void lfsck_component_put(const struct lu_env *env,
1191 struct lfsck_component *com)
1193 if (atomic_dec_and_test(&com->lc_ref)) {
1194 if (com->lc_obj != NULL)
1195 lu_object_put_nocache(env, &com->lc_obj->do_lu);
1196 if (com->lc_file_ram != NULL)
1197 OBD_FREE(com->lc_file_ram, com->lc_file_size);
1198 if (com->lc_file_disk != NULL)
1199 OBD_FREE(com->lc_file_disk, com->lc_file_size);
1200 if (com->lc_data != NULL) {
1201 LASSERT(com->lc_ops->lfsck_data_release != NULL);
1203 com->lc_ops->lfsck_data_release(env, com);
1210 static inline struct lfsck_instance *
1211 lfsck_instance_get(struct lfsck_instance *lfsck)
1213 atomic_inc(&lfsck->li_ref);
1218 static inline void lfsck_instance_put(const struct lu_env *env,
1219 struct lfsck_instance *lfsck)
1221 if (atomic_dec_and_test(&lfsck->li_ref))
1222 lfsck_instance_cleanup(env, lfsck);
1225 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1227 return list_empty(&lad->lad_mdt_phase1_list) &&
1228 (!list_empty(&lad->lad_ost_phase2_list) ||
1229 list_empty(&lad->lad_ost_phase1_list));
1232 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1233 struct lfsck_component *com,
1236 struct lfsck_assistant_data *lad = com->lc_data;
1237 cfs_bitmap_t *bitmap = lad->lad_bitmap;
1239 LASSERT(com->lc_lfsck->li_master);
1240 LASSERT(bitmap != NULL);
1242 if (likely(bitmap->size > index)) {
1243 cfs_bitmap_set(bitmap, index);
1244 lad->lad_incomplete = 1;
1245 } else if (com->lc_type == LFSCK_TYPE_NAMESPACE) {
1246 struct lfsck_namespace *ns = com->lc_file_ram;
1248 ns->ln_flags |= LF_INCOMPLETE;
1252 static inline int lfsck_links_read(const struct lu_env *env,
1253 struct dt_object *obj,
1254 struct linkea_data *ldata)
1257 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1260 return __lfsck_links_read(env, obj, ldata);
1263 static inline int lfsck_links_read2(const struct lu_env *env,
1264 struct dt_object *obj,
1265 struct linkea_data *ldata)
1268 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1271 return __lfsck_links_read(env, obj, ldata);
1274 static inline struct lfsck_lmv *lfsck_lmv_get(struct lfsck_lmv *llmv)
1277 atomic_inc(&llmv->ll_ref);
1282 static inline void lfsck_lmv_header_le_to_cpu(struct lmv_mds_md_v1 *dst,
1283 const struct lmv_mds_md_v1 *src)
1285 dst->lmv_magic = le32_to_cpu(src->lmv_magic);
1286 dst->lmv_stripe_count = le32_to_cpu(src->lmv_stripe_count);
1287 dst->lmv_master_mdt_index = le32_to_cpu(src->lmv_master_mdt_index);
1288 dst->lmv_hash_type = le32_to_cpu(src->lmv_hash_type);
1289 dst->lmv_layout_version = le32_to_cpu(src->lmv_layout_version);
1292 static inline void lfsck_lmv_header_cpu_to_le(struct lmv_mds_md_v1 *dst,
1293 const struct lmv_mds_md_v1 *src)
1295 dst->lmv_magic = cpu_to_le32(src->lmv_magic);
1296 dst->lmv_stripe_count = cpu_to_le32(src->lmv_stripe_count);
1297 dst->lmv_master_mdt_index = cpu_to_le32(src->lmv_master_mdt_index);
1298 dst->lmv_hash_type = cpu_to_le32(src->lmv_hash_type);
1299 dst->lmv_layout_version = cpu_to_le32(src->lmv_layout_version);
1301 #endif /* _LFSCK_INTERNAL_H */