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 /* How many striped directories (master) have been scanned. */
238 __u64 ln_striped_dirs_scanned;
240 /* How many striped directories (master) have been repaired. */
241 __u64 ln_striped_dirs_repaired;
243 /* How many striped directories (master) failed verification. */
244 __u64 ln_striped_dirs_failed;
246 /* How many striped directories (master) has been disabled. */
247 __u64 ln_striped_dirs_disabled;
249 /* How many striped directory's (master) have been skipped
250 * (for shards verification) because of lost master LMV EA. */
251 __u64 ln_striped_dirs_skipped;
253 /* How many striped directory's shards (slave) have been scanned. */
254 __u64 ln_striped_shards_scanned;
256 /* How many striped directory's shards (slave) have been repaired. */
257 __u64 ln_striped_shards_repaired;
259 /* How many striped directory's shards (slave) failed verification. */
260 __u64 ln_striped_shards_failed;
262 /* How many striped directory's shards (slave) have been skipped
263 * (for name hash verification) because do not know whether the slave
264 * LMV EA is valid or not. */
265 __u64 ln_striped_shards_skipped;
267 /* How many name entries under striped directory with bad name
268 * hash have been repaired. */
269 __u64 ln_name_hash_repaired;
271 /* The size of MDT targets bitmap with nbits. Such bitmap records
272 * the MDTs that contain non-verified MDT-objects. */
273 __u32 ln_bitmap_size;
276 /* For further using. 256-bytes aligned now. */
277 __u64 ln_reserved[15];
280 enum lfsck_layout_inconsistency_type {
283 LLIT_UNMATCHED_PAIR = 2,
284 LLIT_MULTIPLE_REFERENCED = 3,
286 LLIT_INCONSISTENT_OWNER = 5,
288 LLIT_MAX = LLIT_OTHERS
291 struct lfsck_layout {
292 /* Magic number to detect that this struct contains valid data. */
295 /* See 'enum lfsck_status'. */
298 /* See 'enum lfsck_flags'. */
301 /* How many completed LFSCK runs on the device. */
302 __u32 ll_success_count;
304 /* How long the LFSCK phase1 has run in seconds. */
305 __u32 ll_run_time_phase1;
307 /* How long the LFSCK phase2 has run in seconds. */
308 __u32 ll_run_time_phase2;
310 /* Time for the last LFSCK completed in seconds since epoch. */
311 __u64 ll_time_last_complete;
313 /* Time for the latest LFSCK ran in seconds since epoch. */
314 __u64 ll_time_latest_start;
316 /* Time for the last LFSCK checkpoint in seconds since epoch. */
317 __u64 ll_time_last_checkpoint;
319 /* Position for the latest LFSCK started from. */
320 __u64 ll_pos_latest_start;
322 /* Position for the last LFSCK checkpoint. */
323 __u64 ll_pos_last_checkpoint;
325 /* Position for the first object to be fixed or
326 * failed to be checked in the phase1. */
327 __u64 ll_pos_first_inconsistent;
329 /* How many objects have been checked. */
330 __u64 ll_objs_checked_phase1;
332 /* How many objects failed to be processed. */
333 __u64 ll_objs_failed_phase1;
335 /* How many objects have been double scanned. */
336 __u64 ll_objs_checked_phase2;
338 /* How many objects failed to be processed during double scan. */
339 __u64 ll_objs_failed_phase2;
341 /* kinds of inconsistency have been or to be repaired.
342 * ll_objs_repaired[type - 1] is the count for the given @type. */
343 __u64 ll_objs_repaired[LLIT_MAX];
345 /* How many objects have been skipped because of related
346 * MDT(s)/OST(s) do not participate in the LFSCK */
347 __u64 ll_objs_skipped;
349 /* The size of ll_ost_bitmap with nbits. */
350 __u32 ll_bitmap_size;
352 /* For further using. 256-bytes aligned now. */
354 __u64 ll_reserved_2[11];
356 /* The OST targets bitmap to record the OSTs that contain
357 * non-verified OST-objects. */
358 __u8 ll_ost_bitmap[0];
361 struct lfsck_component;
362 struct lfsck_tgt_descs;
363 struct lfsck_tgt_desc;
365 struct lfsck_operations {
366 int (*lfsck_reset)(const struct lu_env *env,
367 struct lfsck_component *com,
370 void (*lfsck_fail)(const struct lu_env *env,
371 struct lfsck_component *com,
374 void (*lfsck_close_dir)(const struct lu_env *env,
375 struct lfsck_component *com);
377 int (*lfsck_open_dir)(const struct lu_env *env,
378 struct lfsck_component *com);
380 int (*lfsck_checkpoint)(const struct lu_env *env,
381 struct lfsck_component *com,
384 int (*lfsck_prep)(const struct lu_env *env,
385 struct lfsck_component *com,
386 struct lfsck_start_param *lsp);
388 int (*lfsck_exec_oit)(const struct lu_env *env,
389 struct lfsck_component *com,
390 struct dt_object *obj);
392 int (*lfsck_exec_dir)(const struct lu_env *env,
393 struct lfsck_component *com,
394 struct lu_dirent *ent,
397 int (*lfsck_post)(const struct lu_env *env,
398 struct lfsck_component *com,
402 int (*lfsck_dump)(const struct lu_env *env,
403 struct lfsck_component *com,
406 int (*lfsck_double_scan)(const struct lu_env *env,
407 struct lfsck_component *com);
409 void (*lfsck_data_release)(const struct lu_env *env,
410 struct lfsck_component *com);
412 void (*lfsck_quit)(const struct lu_env *env,
413 struct lfsck_component *com);
415 int (*lfsck_in_notify)(const struct lu_env *env,
416 struct lfsck_component *com,
417 struct lfsck_request *lr,
420 int (*lfsck_query)(const struct lu_env *env,
421 struct lfsck_component *com);
423 int (*lfsck_join)(const struct lu_env *env,
424 struct lfsck_component *com,
425 struct lfsck_start_param *lsp);
428 #define TGT_PTRS 256 /* number of pointers at 1st level */
429 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
431 struct lfsck_tgt_desc {
432 struct list_head ltd_orphan_list;
433 struct dt_device *ltd_tgt;
434 struct dt_device *ltd_key;
435 struct obd_export *ltd_exp;
436 struct list_head ltd_layout_list;
437 struct list_head ltd_layout_phase_list;
438 struct list_head ltd_namespace_list;
439 struct list_head ltd_namespace_phase_list;
442 __u32 ltd_layout_gen;
443 __u32 ltd_namespace_gen;
444 unsigned int ltd_dead:1,
446 ltd_namespace_done:1,
447 ltd_namespace_failed:1;
450 struct lfsck_tgt_desc_idx {
451 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
454 struct lfsck_tgt_descs {
455 /* list of known TGTs */
456 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
458 /* bitmap of TGTs available */
459 cfs_bitmap_t *ltd_tgts_bitmap;
461 /* for lfsck_tgt_desc::ltd_xxx_list */
464 /* for tgts table accessing and changes */
465 struct rw_semaphore ltd_rw_sem;
467 /* Temporary list for orphan targets. */
468 struct list_head ltd_orphan;
470 /* number of registered TGTs */
474 #define LTD_TGT(ltd, index) \
475 ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
476 ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
478 #define OST_TGT(lfsck, index) LTD_TGT(&lfsck->li_ost_descs, index)
479 #define MDT_TGT(lfsck, index) LTD_TGT(&lfsck->li_mdt_descs, index)
481 struct lfsck_component {
482 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
483 struct list_head lc_link;
485 /* into lfsck_instance::li_list_dir */
486 struct list_head lc_link_dir;
488 struct rw_semaphore lc_sem;
491 struct lfsck_position lc_pos_start;
492 struct lfsck_instance *lc_lfsck;
493 struct dt_object *lc_obj;
494 struct lfsck_operations *lc_ops;
498 struct lu_fid lc_fid_latest_scanned_phase2;
500 /* The time for last checkpoint, jiffies */
501 cfs_time_t lc_time_last_checkpoint;
503 /* The time for next checkpoint, jiffies */
504 cfs_time_t lc_time_next_checkpoint;
508 /* How many objects have been checked since last checkpoint. */
509 __u32 lc_new_checked;
511 /* How many objects have been scanned since last sleep. */
512 __u32 lc_new_scanned;
517 #define LFSCK_LMV_MAX_STRIPES LMV_MAX_STRIPE_COUNT
518 #define LFSCK_LMV_DEF_STRIPES 4
520 struct lfsck_slave_lmv_rec {
521 struct lu_fid lslr_fid;
522 __u32 lslr_stripe_count;
523 __u32 lslr_index; /* the index in name or in slave lmv */
524 __u32 lslr_hash_type;
529 struct lmv_mds_md_v1 ll_lmv;
531 int ll_stripes_allocated;
532 int ll_stripes_filled;
534 __u32 ll_max_stripe_count;
535 __u32 ll_max_filled_off;
537 unsigned int ll_lmv_master:1,
544 struct lfsck_slave_lmv_rec *ll_lslr;
547 struct lfsck_instance {
548 struct mutex li_mutex;
551 /* Link into the lfsck_instance_list. */
552 struct list_head li_link;
554 /* For the components in (first) scanning via otable-based iteration. */
555 struct list_head li_list_scan;
557 /* For the components in scanning via directory traversal. Because
558 * directory traversal cannot guarantee all the object be scanned,
559 * so the component in the li_list_dir must be in li_list_scan. */
560 struct list_head li_list_dir;
562 /* For the components in double scanning. */
563 struct list_head li_list_double_scan;
565 /* For the components those are not scanning now. */
566 struct list_head li_list_idle;
569 atomic_t li_double_scan_count;
570 struct ptlrpc_thread li_thread;
572 /* The time for last checkpoint, jiffies */
573 cfs_time_t li_time_last_checkpoint;
575 /* The time for next checkpoint, jiffies */
576 cfs_time_t li_time_next_checkpoint;
578 lfsck_out_notify li_out_notify;
579 void *li_out_notify_data;
580 struct dt_device *li_next;
581 struct dt_device *li_bottom;
582 struct obd_device *li_obd;
583 struct ldlm_namespace *li_namespace;
584 struct local_oid_storage *li_los;
585 struct lu_fid li_local_root_fid; /* backend root "/" */
586 struct lu_fid li_global_root_fid; /* /ROOT */
587 struct dt_object *li_bookmark_obj;
588 struct dt_object *li_lpf_obj;
589 struct lu_client_seq *li_seq;
590 struct lfsck_bookmark li_bookmark_ram;
591 struct lfsck_bookmark li_bookmark_disk;
592 struct lfsck_position li_pos_current;
593 struct lfsck_position li_pos_checkpoint;
595 struct lfsck_lmv *li_lmv;
597 /* Obj for otable-based iteration */
598 struct dt_object *li_obj_oit;
600 /* Obj for directory traversal */
601 struct dt_object *li_obj_dir;
603 /* It for otable-based iteration */
604 struct dt_it *li_di_oit;
606 /* It for directory traversal */
607 struct dt_it *li_di_dir;
609 /* Description of OST */
610 struct lfsck_tgt_descs li_ost_descs;
612 /* Description of MDT */
613 struct lfsck_tgt_descs li_mdt_descs;
615 /* namespace-based directory traversal position. */
618 /* Arguments for low layer otable-based iteration. */
621 /* Arugments for namespace-based directory traversal. */
624 /* Schedule for every N objects. */
627 /* Sleep N jiffies for each schedule. */
630 /* How many objects have been scanned since last sleep. */
631 __u32 li_new_scanned;
633 /* The status when the LFSCK stopped or paused. */
636 /* The flags when the lFSCK stopped or paused. */
639 unsigned int li_oit_over:1, /* oit is finished. */
640 li_drop_dryrun:1, /* Ever dryrun, not now. */
641 li_master:1, /* Master instance or not. */
642 li_current_oit_processed:1,
646 struct lfsck_async_interpret_args {
647 struct lfsck_component *laia_com;
648 struct lfsck_tgt_descs *laia_ltds;
649 struct lfsck_tgt_desc *laia_ltd;
650 struct lfsck_request *laia_lr;
651 atomic_t *laia_count;
653 unsigned int laia_shared:1;
656 struct lfsck_thread_args {
657 struct lu_env lta_env;
658 struct lfsck_instance *lta_lfsck;
659 struct lfsck_component *lta_com;
660 struct lfsck_start_param *lta_lsp;
663 struct lfsck_assistant_req {
664 struct list_head lar_list;
667 struct lfsck_namespace_req {
668 struct lfsck_assistant_req lnr_lar;
669 struct dt_object *lnr_obj;
670 struct lfsck_lmv *lnr_lmv;
671 struct lu_fid lnr_fid;
672 __u64 lnr_oit_cookie;
673 __u64 lnr_dir_cookie;
681 struct lfsck_assistant_operations {
682 int (*la_handler_p1)(const struct lu_env *env,
683 struct lfsck_component *com,
684 struct lfsck_assistant_req *lar);
686 int (*la_handler_p2)(const struct lu_env *env,
687 struct lfsck_component *com);
689 void (*la_fill_pos)(const struct lu_env *env,
690 struct lfsck_component *com,
691 struct lfsck_position *pos);
693 int (*la_double_scan_result)(const struct lu_env *env,
694 struct lfsck_component *com,
697 void (*la_req_fini)(const struct lu_env *env,
698 struct lfsck_assistant_req *lar);
700 void (*la_sync_failures)(const struct lu_env *env,
701 struct lfsck_component *com,
702 struct lfsck_request *lr);
705 struct lfsck_assistant_data {
707 struct list_head lad_req_list;
709 /* list for the ost targets involve LFSCK. */
710 struct list_head lad_ost_list;
712 /* list for the ost targets in phase1 scanning. */
713 struct list_head lad_ost_phase1_list;
715 /* list for the ost targets in phase1 scanning. */
716 struct list_head lad_ost_phase2_list;
718 /* list for the mdt targets involve LFSCK. */
719 struct list_head lad_mdt_list;
721 /* list for the mdt targets in phase1 scanning. */
722 struct list_head lad_mdt_phase1_list;
724 /* list for the mdt targets in phase1 scanning. */
725 struct list_head lad_mdt_phase2_list;
727 const char *lad_name;
728 struct ptlrpc_thread lad_thread;
730 struct lfsck_assistant_operations *lad_ops;
732 cfs_bitmap_t *lad_bitmap;
736 int lad_assistant_status;
738 unsigned int lad_to_post:1,
739 lad_to_double_scan:1,
740 lad_in_double_scan:1,
745 #define LFSCK_TMPBUF_LEN 64
747 struct lfsck_thread_info {
748 struct lu_name lti_name_const;
749 struct lu_name lti_name;
750 struct lu_name lti_name2;
751 struct lu_buf lti_buf;
752 struct lu_buf lti_linkea_buf;
753 struct lu_buf lti_linkea_buf2;
754 struct lu_buf lti_big_buf;
755 struct lu_fid lti_fid;
756 struct lu_fid lti_fid2;
757 struct lu_fid lti_fid3;
758 struct lu_fid lti_fid4;
759 struct lu_fid lti_fid5;
760 struct lu_attr lti_la;
761 struct lu_attr lti_la2;
762 struct lu_attr lti_la3;
763 struct ost_id lti_oi;
765 struct lustre_mdt_attrs lti_lma;
766 /* old LMA for compatibility */
767 char lti_lma_old[LMA_OLD_SIZE];
769 struct dt_object_format lti_dof;
770 /* There will be '\0' at the end of the name. */
771 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
772 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
773 char lti_tmpbuf2[LFSCK_TMPBUF_LEN];
774 struct lfsck_request lti_lr;
775 struct lfsck_async_interpret_args lti_laia;
776 struct lfsck_async_interpret_args lti_laia2;
777 struct lfsck_start lti_start;
778 struct lfsck_stop lti_stop;
779 ldlm_policy_data_t lti_policy;
780 struct ldlm_res_id lti_resid;
782 struct filter_fid_old lti_old_pfid;
783 struct filter_fid lti_new_pfid;
785 struct dt_allocation_hint lti_hint;
786 struct lu_orphan_rec lti_rec;
787 struct lov_user_md lti_lum;
788 struct dt_insert_rec lti_dt_rec;
789 struct lu_object_conf lti_conf;
790 struct lu_seq_range lti_range;
791 struct lmv_mds_md_v1 lti_lmv;
792 struct lmv_mds_md_v1 lti_lmv2;
793 struct lmv_mds_md_v1 lti_lmv3;
794 struct lmv_mds_md_v1 lti_lmv4;
798 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
799 struct lu_fid *fid, bool locked);
800 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
801 struct dt_object *obj, struct lustre_handle *lh,
802 __u64 bits, ldlm_mode_t mode);
803 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
804 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
805 struct lfsck_instance *lfsck,
806 const struct lu_fid *fid);
807 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
808 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
809 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
811 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
813 const char *lfsck_status2names(enum lfsck_status status);
814 void lfsck_component_cleanup(const struct lu_env *env,
815 struct lfsck_component *com);
816 void lfsck_instance_cleanup(const struct lu_env *env,
817 struct lfsck_instance *lfsck);
818 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
820 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
821 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
823 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
824 struct lfsck_position *pos, bool init);
825 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
826 void lfsck_control_speed(struct lfsck_instance *lfsck);
827 void lfsck_control_speed_by_self(struct lfsck_component *com);
828 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
829 struct lfsck_assistant_data *
830 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
832 int lfsck_async_interpret_common(const struct lu_env *env,
833 struct ptlrpc_request *req,
835 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
836 struct lfsck_request *lr,
837 struct ptlrpc_request_set *set,
838 ptlrpc_interpterer_t interpterer,
839 void *args, int request);
840 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
841 struct lfsck_start_param *lsp);
842 int lfsck_checkpoint_generic(const struct lu_env *env,
843 struct lfsck_component *com);
844 void lfsck_post_generic(const struct lu_env *env,
845 struct lfsck_component *com, int *result);
846 int lfsck_double_scan_generic(const struct lu_env *env,
847 struct lfsck_component *com, int status);
848 void lfsck_quit_generic(const struct lu_env *env,
849 struct lfsck_component *com);
852 int lfsck_unpack_ent(struct lu_dirent *ent, __u64 *cookie, __u16 *type);
853 int lfsck_master_engine(void *args);
854 int lfsck_assistant_engine(void *args);
856 /* lfsck_bookmark.c */
857 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
858 struct lfsck_bookmark *src);
859 int lfsck_bookmark_store(const struct lu_env *env,
860 struct lfsck_instance *lfsck);
861 int lfsck_bookmark_setup(const struct lu_env *env,
862 struct lfsck_instance *lfsck);
863 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
864 struct lfsck_start *start, bool reset);
866 /* lfsck_namespace.c */
867 int lfsck_namespace_trace_update(const struct lu_env *env,
868 struct lfsck_component *com,
869 const struct lu_fid *fid,
870 const __u8 flags, bool add);
871 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
872 struct linkea_data *ldata);
873 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
874 struct lfsck_component *com,
875 struct dt_object *obj,
876 struct linkea_data *ldata);
877 int lfsck_namespace_repair_dangling(const struct lu_env *env,
878 struct lfsck_component *com,
879 struct dt_object *child,
880 struct lfsck_namespace_req *lnr);
881 int lfsck_namespace_repair_dirent(const struct lu_env *env,
882 struct lfsck_component *com,
883 struct dt_object *parent,
884 struct dt_object *child,
885 const char *name, const char *name2,
886 __u16 type, bool update, bool dec);
887 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
888 struct dt_object *obj, const struct lu_name *cname,
889 const struct lu_fid *pfid);
890 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
891 char *name, struct lu_fid *pfid);
892 int lfsck_remove_name_entry(const struct lu_env *env,
893 struct lfsck_instance *lfsck,
894 struct dt_object *parent,
895 const char *name, __u32 type);
896 int lfsck_update_name_entry(const struct lu_env *env,
897 struct lfsck_instance *lfsck,
898 struct dt_object *parent, const char *name,
899 const struct lu_fid *pfid, __u32 type);
900 int lfsck_namespace_setup(const struct lu_env *env,
901 struct lfsck_instance *lfsck);
903 /* lfsck_striped_dir.c */
904 void lfsck_lmv_put(const struct lu_env *env, struct lfsck_lmv *llmv);
905 int lfsck_read_stripe_lmv(const struct lu_env *env, struct dt_object *obj,
906 struct lmv_mds_md_v1 *lmv);
907 int lfsck_shard_name_to_index(const struct lu_env *env, const char *name,
908 int namelen, __u16 type,
909 const struct lu_fid *fid);
910 bool lfsck_is_valid_slave_name_entry(const struct lu_env *env,
911 struct lfsck_lmv *llmv,
912 const char *name, int namelen);
913 int lfsck_namespace_check_name(const struct lu_env *env,
914 struct dt_object *parent,
915 struct dt_object *child,
916 const struct lu_name *cname);
917 int lfsck_namespace_verify_stripe_slave(const struct lu_env *env,
918 struct lfsck_component *com,
919 struct dt_object *obj,
920 struct lfsck_lmv *llmv);
923 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
925 extern const char dot[];
926 extern const char dotdot[];
927 extern const char *lfsck_flags_names[];
928 extern const char *lfsck_param_names[];
929 extern struct lu_context_key lfsck_thread_key;
931 static inline bool name_is_dot_or_dotdot(const char *name, int namelen)
933 return name[0] == '.' &&
934 (namelen == 1 || (namelen == 2 && name[1] == '.'));
937 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
939 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
942 static inline struct lfsck_thread_info *
943 lfsck_env_info(const struct lu_env *env)
945 struct lfsck_thread_info *info;
947 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
948 LASSERT(info != NULL);
952 static inline const struct lu_name *
953 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
955 struct lu_name *lname;
957 lname = &lfsck_env_info(env)->lti_name_const;
958 lname->ln_name = area;
959 lname->ln_namelen = len;
964 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
970 static inline struct lu_buf *
971 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
975 buf = &lfsck_env_info(env)->lti_buf;
981 static inline const struct lu_buf *
982 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
986 buf = &lfsck_env_info(env)->lti_buf;
987 buf->lb_buf = (void *)area;
992 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
994 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
997 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
999 return lu_object_fid(&obj->do_lu);
1002 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
1004 memset(pos, 0, sizeof(*pos));
1007 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
1009 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
1012 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
1013 const struct lfsck_position *pos2)
1015 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
1018 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
1021 if (fid_is_zero(&pos1->lp_dir_parent) &&
1022 !fid_is_zero(&pos2->lp_dir_parent))
1025 if (!fid_is_zero(&pos1->lp_dir_parent) &&
1026 fid_is_zero(&pos2->lp_dir_parent))
1029 if (fid_is_zero(&pos1->lp_dir_parent) &&
1030 fid_is_zero(&pos2->lp_dir_parent))
1033 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
1035 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
1038 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
1044 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
1045 struct lfsck_position *src)
1047 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
1048 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
1049 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
1052 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
1053 struct lfsck_position *src)
1055 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
1056 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
1057 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
1060 static inline umode_t lfsck_object_type(const struct dt_object *obj)
1062 return lu_object_attr(&obj->do_lu);
1065 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
1067 struct lu_object_header *loh = obj->do_lu.lo_header;
1069 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
1072 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
1074 lu_object_get(&obj->do_lu);
1078 static inline void lfsck_object_put(const struct lu_env *env,
1079 struct dt_object *obj)
1081 lu_object_put(env, &obj->do_lu);
1084 static inline u32 lfsck_dev_idx(struct dt_device *dev)
1086 return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
1089 static inline struct dt_object *
1090 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
1091 const struct lu_fid *fid)
1093 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
1094 struct dt_object *obj;
1096 conf->loc_flags = LOC_F_NOWAIT;
1097 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
1098 if (unlikely(obj == NULL))
1099 return ERR_PTR(-ENOENT);
1104 static inline struct dt_object *
1105 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
1106 const struct lu_fid *fid)
1108 struct dt_object *obj;
1110 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
1111 if (unlikely(obj == NULL))
1112 return ERR_PTR(-ENOENT);
1117 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
1118 struct lfsck_instance *lfsck,
1119 const struct lu_fid *fid)
1121 return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
1124 static inline struct dt_object *
1125 lfsck_object_find_bottom(const struct lu_env *env, struct lfsck_instance *lfsck,
1126 const struct lu_fid *fid)
1128 struct dt_device *dev;
1131 idx = lfsck_find_mdt_idx_by_fid(env, lfsck, fid);
1133 return ERR_PTR(idx);
1135 if (idx == lfsck_dev_idx(lfsck->li_bottom)) {
1136 dev = lfsck->li_bottom;
1138 struct lfsck_tgt_desc *ltd;
1140 ltd = LTD_TGT(&lfsck->li_mdt_descs, idx);
1141 if (unlikely(ltd == NULL))
1142 return ERR_PTR(-ENODEV);
1147 return lfsck_object_find_by_dev(env, dev, fid);
1150 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
1153 struct lfsck_tgt_desc *ltd;
1155 ltd = LTD_TGT(ltds, index);
1157 atomic_inc(<d->ltd_ref);
1162 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
1164 if (atomic_dec_and_test(<d->ltd_ref))
1168 static inline struct lfsck_component *
1169 lfsck_component_get(struct lfsck_component *com)
1171 atomic_inc(&com->lc_ref);
1176 static inline void lfsck_component_put(const struct lu_env *env,
1177 struct lfsck_component *com)
1179 if (atomic_dec_and_test(&com->lc_ref)) {
1180 if (com->lc_obj != NULL)
1181 lu_object_put_nocache(env, &com->lc_obj->do_lu);
1182 if (com->lc_file_ram != NULL)
1183 OBD_FREE(com->lc_file_ram, com->lc_file_size);
1184 if (com->lc_file_disk != NULL)
1185 OBD_FREE(com->lc_file_disk, com->lc_file_size);
1186 if (com->lc_data != NULL) {
1187 LASSERT(com->lc_ops->lfsck_data_release != NULL);
1189 com->lc_ops->lfsck_data_release(env, com);
1196 static inline struct lfsck_instance *
1197 lfsck_instance_get(struct lfsck_instance *lfsck)
1199 atomic_inc(&lfsck->li_ref);
1204 static inline void lfsck_instance_put(const struct lu_env *env,
1205 struct lfsck_instance *lfsck)
1207 if (atomic_dec_and_test(&lfsck->li_ref))
1208 lfsck_instance_cleanup(env, lfsck);
1211 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1213 return list_empty(&lad->lad_mdt_phase1_list) &&
1214 (!list_empty(&lad->lad_ost_phase2_list) ||
1215 list_empty(&lad->lad_ost_phase1_list));
1218 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1219 struct lfsck_component *com,
1222 struct lfsck_assistant_data *lad = com->lc_data;
1223 cfs_bitmap_t *bitmap = lad->lad_bitmap;
1225 LASSERT(com->lc_lfsck->li_master);
1226 LASSERT(bitmap != NULL);
1228 if (likely(bitmap->size > index)) {
1229 cfs_bitmap_set(bitmap, index);
1230 lad->lad_incomplete = 1;
1231 } else if (com->lc_type == LFSCK_TYPE_NAMESPACE) {
1232 struct lfsck_namespace *ns = com->lc_file_ram;
1234 ns->ln_flags |= LF_INCOMPLETE;
1238 static inline int lfsck_links_read(const struct lu_env *env,
1239 struct dt_object *obj,
1240 struct linkea_data *ldata)
1243 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1246 return __lfsck_links_read(env, obj, ldata);
1249 static inline int lfsck_links_read2(const struct lu_env *env,
1250 struct dt_object *obj,
1251 struct linkea_data *ldata)
1254 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1257 return __lfsck_links_read(env, obj, ldata);
1260 static inline struct lfsck_lmv *lfsck_lmv_get(struct lfsck_lmv *llmv)
1263 atomic_inc(&llmv->ll_ref);
1268 static inline void lfsck_lmv_header_le_to_cpu(struct lmv_mds_md_v1 *dst,
1269 const struct lmv_mds_md_v1 *src)
1271 dst->lmv_magic = le32_to_cpu(src->lmv_magic);
1272 dst->lmv_stripe_count = le32_to_cpu(src->lmv_stripe_count);
1273 dst->lmv_master_mdt_index = le32_to_cpu(src->lmv_master_mdt_index);
1274 dst->lmv_hash_type = le32_to_cpu(src->lmv_hash_type);
1275 dst->lmv_layout_version = le32_to_cpu(src->lmv_layout_version);
1278 static inline void lfsck_lmv_header_cpu_to_le(struct lmv_mds_md_v1 *dst,
1279 const struct lmv_mds_md_v1 *src)
1281 dst->lmv_magic = cpu_to_le32(src->lmv_magic);
1282 dst->lmv_stripe_count = cpu_to_le32(src->lmv_stripe_count);
1283 dst->lmv_master_mdt_index = cpu_to_le32(src->lmv_master_mdt_index);
1284 dst->lmv_hash_type = cpu_to_le32(src->lmv_hash_type);
1285 dst->lmv_layout_version = cpu_to_le32(src->lmv_layout_version);
1287 #endif /* _LFSCK_INTERNAL_H */