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, 2014, 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 msecs_to_jiffies(MSEC_PER_SEC >> 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_assistant_object {
364 struct lu_fid lso_fid;
365 __u64 lso_oit_cookie;
366 struct lu_attr lso_attr;
368 unsigned int lso_dead:1,
372 struct lfsck_component;
373 struct lfsck_tgt_descs;
374 struct lfsck_tgt_desc;
376 struct lfsck_operations {
377 int (*lfsck_reset)(const struct lu_env *env,
378 struct lfsck_component *com,
381 void (*lfsck_fail)(const struct lu_env *env,
382 struct lfsck_component *com,
385 void (*lfsck_close_dir)(const struct lu_env *env,
386 struct lfsck_component *com);
388 int (*lfsck_open_dir)(const struct lu_env *env,
389 struct lfsck_component *com);
391 int (*lfsck_checkpoint)(const struct lu_env *env,
392 struct lfsck_component *com,
395 int (*lfsck_prep)(const struct lu_env *env,
396 struct lfsck_component *com,
397 struct lfsck_start_param *lsp);
399 int (*lfsck_exec_oit)(const struct lu_env *env,
400 struct lfsck_component *com,
401 struct dt_object *obj);
403 int (*lfsck_exec_dir)(const struct lu_env *env,
404 struct lfsck_component *com,
405 struct lfsck_assistant_object *lso,
406 struct lu_dirent *ent,
409 int (*lfsck_post)(const struct lu_env *env,
410 struct lfsck_component *com,
414 int (*lfsck_dump)(const struct lu_env *env,
415 struct lfsck_component *com,
418 int (*lfsck_double_scan)(const struct lu_env *env,
419 struct lfsck_component *com);
421 void (*lfsck_data_release)(const struct lu_env *env,
422 struct lfsck_component *com);
424 void (*lfsck_quit)(const struct lu_env *env,
425 struct lfsck_component *com);
427 int (*lfsck_in_notify)(const struct lu_env *env,
428 struct lfsck_component *com,
429 struct lfsck_request *lr,
432 int (*lfsck_query)(const struct lu_env *env,
433 struct lfsck_component *com);
435 int (*lfsck_join)(const struct lu_env *env,
436 struct lfsck_component *com,
437 struct lfsck_start_param *lsp);
440 #define TGT_PTRS 256 /* number of pointers at 1st level */
441 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
443 struct lfsck_tgt_desc {
444 struct list_head ltd_orphan_list;
445 struct dt_device *ltd_tgt;
446 struct dt_device *ltd_key;
447 struct obd_export *ltd_exp;
448 struct list_head ltd_layout_list;
449 struct list_head ltd_layout_phase_list;
450 struct list_head ltd_namespace_list;
451 struct list_head ltd_namespace_phase_list;
454 __u32 ltd_layout_gen;
455 __u32 ltd_namespace_gen;
456 unsigned int ltd_dead:1,
458 ltd_namespace_done:1,
459 ltd_synced_failures:1;
462 struct lfsck_tgt_desc_idx {
463 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
466 struct lfsck_tgt_descs {
467 /* list of known TGTs */
468 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
470 /* bitmap of TGTs available */
471 cfs_bitmap_t *ltd_tgts_bitmap;
473 /* for lfsck_tgt_desc::ltd_xxx_list */
476 /* for tgts table accessing and changes */
477 struct rw_semaphore ltd_rw_sem;
479 /* Temporary list for orphan targets. */
480 struct list_head ltd_orphan;
482 /* number of registered TGTs */
486 static inline struct lfsck_tgt_desc *
487 lfsck_ltd2tgt(struct lfsck_tgt_descs *ltd, __u32 index)
489 __u32 idx1 = index / TGT_PTRS_PER_BLOCK;
490 __u32 idx2 = index % TGT_PTRS_PER_BLOCK;
491 struct lfsck_tgt_desc *__tgt = NULL;
493 if (unlikely(idx1 >= TGT_PTRS))
494 CDEBUG(D_LFSCK, "The target idx %u is invalid.\n", index);
495 else if (likely(ltd->ltd_tgts_idx[idx1] != NULL))
496 __tgt = ltd->ltd_tgts_idx[idx1]->ldi_tgts[idx2];
501 static inline void lfsck_assign_tgt(struct lfsck_tgt_descs *ltd,
502 struct lfsck_tgt_desc *tgt, __u32 index)
504 __u32 idx1 = index / TGT_PTRS_PER_BLOCK;
505 __u32 idx2 = index % TGT_PTRS_PER_BLOCK;
507 if (likely(idx1 < TGT_PTRS && ltd->ltd_tgts_idx[idx1] != NULL))
508 ltd->ltd_tgts_idx[idx1]->ldi_tgts[idx2] = tgt;
511 #define LFSCK_STF_BITS 4
512 /* If want to adjust the LFSCK_STF_COUNT, please change LFSCK_STF_BITS. */
513 #define LFSCK_STF_COUNT (1 << LFSCK_STF_BITS)
515 struct lfsck_sub_trace_obj {
516 struct dt_object *lsto_obj;
517 struct mutex lsto_mutex;
520 struct lfsck_component {
521 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
522 struct list_head lc_link;
524 /* into lfsck_instance::li_list_dir */
525 struct list_head lc_link_dir;
527 struct rw_semaphore lc_sem;
530 struct lfsck_position lc_pos_start;
531 struct lfsck_instance *lc_lfsck;
532 struct dt_object *lc_obj;
533 struct lfsck_sub_trace_obj lc_sub_trace_objs[LFSCK_STF_COUNT];
534 struct lfsck_operations *lc_ops;
538 struct lu_fid lc_fid_latest_scanned_phase2;
540 /* The time for last checkpoint, jiffies */
541 cfs_time_t lc_time_last_checkpoint;
543 /* The time for next checkpoint, jiffies */
544 cfs_time_t lc_time_next_checkpoint;
548 /* How many objects have been checked since last checkpoint. */
549 __u32 lc_new_checked;
551 /* How many objects have been scanned since last sleep. */
552 __u32 lc_new_scanned;
557 #define LFSCK_LMV_MAX_STRIPES LMV_MAX_STRIPE_COUNT
558 #define LFSCK_LMV_DEF_STRIPES 4
560 /* Warning: NOT change the lfsck_slave_lmv_flags members order,
561 * otherwise the lfsck_record_lmv() may be wrong. */
562 enum lfsck_slave_lmv_flags {
570 /* When the namespace LFSCK scans a striped directory, it will record all
571 * the known shards' information in the structure "lfsck_slave_lmv_rec",
572 * including the shard's FID, index, slave LMV EA, and so on. Each shard
573 * will take one lfsck_slave_lmv_rec slot. After the 1st cycle scanning
574 * the striped directory, the LFSCK will get all the information about
575 * whether there are some inconsistency, and then it can repair them in
576 * the 2nd cycle scanning. */
577 struct lfsck_slave_lmv_rec {
578 struct lu_fid lslr_fid;
579 __u32 lslr_stripe_count;
580 __u32 lslr_index; /* the index in name or in slave lmv */
581 __u32 lslr_hash_type;
586 struct lmv_mds_md_v1 ll_lmv;
588 int ll_stripes_allocated;
589 int ll_stripes_filled;
591 __u32 ll_max_stripe_count;
592 __u32 ll_max_filled_off;
594 unsigned int ll_lmv_master:1,
601 struct lfsck_slave_lmv_rec *ll_lslr;
604 /* If the namespace LFSCK finds that the master MDT-object of a striped
605 * directory lost its master LMV EA, it will re-generate the master LMV
606 * EA and notify the LFSCK instance on the MDT on which the striped dir
607 * master MDT-object resides to rescan the striped directory. To do that,
608 * the notify handler will insert a "lfsck_lmv_unit" structure into the
609 * lfsck::li_list_lmv. The LFSCK instance will scan such list from time
610 * to time to check whether needs to rescan some stirped directories. */
611 struct lfsck_lmv_unit {
612 struct list_head llu_link;
613 struct lfsck_lmv llu_lmv;
614 struct dt_object *llu_obj;
615 struct lfsck_instance *llu_lfsck;
618 struct lfsck_rec_lmv_save {
619 struct lu_fid lrls_fid;
620 struct lmv_mds_md_v1 lrls_lmv;
623 /* Allow lfsck_record_lmv() to be called recursively at most three times. */
624 #define LFSCK_REC_LMV_MAX_DEPTH 3
626 struct lfsck_instance {
627 struct mutex li_mutex;
630 /* Link into the lfsck_instance_list. */
631 struct list_head li_link;
633 /* For the components in (first) scanning via otable-based iteration. */
634 struct list_head li_list_scan;
636 /* For the components in scanning via directory traversal. Because
637 * directory traversal cannot guarantee all the object be scanned,
638 * so the component in the li_list_dir must be in li_list_scan. */
639 struct list_head li_list_dir;
641 /* For the components in double scanning. */
642 struct list_head li_list_double_scan;
644 /* For the components those are not scanning now. */
645 struct list_head li_list_idle;
647 /* For the lfsck_lmv_unit to be handled. */
648 struct list_head li_list_lmv;
651 atomic_t li_double_scan_count;
652 struct ptlrpc_thread li_thread;
654 /* The time for last checkpoint, jiffies */
655 cfs_time_t li_time_last_checkpoint;
657 /* The time for next checkpoint, jiffies */
658 cfs_time_t li_time_next_checkpoint;
660 lfsck_out_notify li_out_notify;
661 void *li_out_notify_data;
662 struct dt_device *li_next;
663 struct dt_device *li_bottom;
664 struct obd_device *li_obd;
665 struct ldlm_namespace *li_namespace;
666 struct local_oid_storage *li_los;
667 struct lu_fid li_local_root_fid; /* backend root "/" */
668 struct lu_fid li_global_root_fid; /* /ROOT */
669 struct dt_object *li_lfsck_dir;
670 struct dt_object *li_bookmark_obj;
671 struct dt_object *li_lpf_obj;
672 struct dt_object *li_lpf_root_obj;
673 struct lu_client_seq *li_seq;
674 struct lfsck_bookmark li_bookmark_ram;
675 struct lfsck_bookmark li_bookmark_disk;
676 struct lfsck_position li_pos_current;
677 struct lfsck_position li_pos_checkpoint;
679 struct lfsck_lmv *li_lmv;
681 /* Obj for otable-based iteration */
682 struct dt_object *li_obj_oit;
684 /* Obj for directory traversal */
685 struct dt_object *li_obj_dir;
687 /* It for otable-based iteration */
688 struct dt_it *li_di_oit;
690 /* It for directory traversal */
691 struct dt_it *li_di_dir;
693 /* Description of OST */
694 struct lfsck_tgt_descs li_ost_descs;
696 /* Description of MDT */
697 struct lfsck_tgt_descs li_mdt_descs;
699 /* namespace-based directory traversal position. */
702 /* Arguments for low layer otable-based iteration. */
705 /* Arugments for namespace-based directory traversal. */
708 /* Schedule for every N objects. */
711 /* Sleep N jiffies for each schedule. */
714 /* How many objects have been scanned since last sleep. */
715 __u32 li_new_scanned;
717 /* The status when the LFSCK stopped or paused. */
720 /* The flags when the lFSCK stopped or paused. */
723 unsigned int li_oit_over:1, /* oit is finished. */
724 li_drop_dryrun:1, /* Ever dryrun, not now. */
725 li_master:1, /* Master instance or not. */
726 li_current_oit_processed:1,
728 struct lfsck_rec_lmv_save li_rec_lmv_save[LFSCK_REC_LMV_MAX_DEPTH];
731 struct lfsck_async_interpret_args {
732 struct lfsck_component *laia_com;
733 struct lfsck_tgt_descs *laia_ltds;
734 struct lfsck_tgt_desc *laia_ltd;
735 struct lfsck_request *laia_lr;
736 atomic_t *laia_count;
738 unsigned int laia_shared:1;
741 struct lfsck_thread_args {
742 struct lu_env lta_env;
743 struct lfsck_instance *lta_lfsck;
744 struct lfsck_component *lta_com;
745 struct lfsck_start_param *lta_lsp;
748 struct lfsck_assistant_req {
749 struct list_head lar_list;
750 struct lfsck_assistant_object *lar_parent;
753 struct lfsck_namespace_req {
754 struct lfsck_assistant_req lnr_lar;
755 struct lfsck_lmv *lnr_lmv;
756 struct lu_fid lnr_fid;
757 __u64 lnr_dir_cookie;
765 struct lfsck_layout_req {
766 struct lfsck_assistant_req llr_lar;
767 struct dt_object *llr_child;
769 __u32 llr_lov_idx; /* offset in LOV EA */
772 struct lfsck_assistant_operations {
773 int (*la_handler_p1)(const struct lu_env *env,
774 struct lfsck_component *com,
775 struct lfsck_assistant_req *lar);
777 int (*la_handler_p2)(const struct lu_env *env,
778 struct lfsck_component *com);
780 void (*la_fill_pos)(const struct lu_env *env,
781 struct lfsck_component *com,
782 struct lfsck_position *pos);
784 int (*la_double_scan_result)(const struct lu_env *env,
785 struct lfsck_component *com,
788 void (*la_req_fini)(const struct lu_env *env,
789 struct lfsck_assistant_req *lar);
791 void (*la_sync_failures)(const struct lu_env *env,
792 struct lfsck_component *com,
793 struct lfsck_request *lr);
796 struct lfsck_assistant_data {
798 struct list_head lad_req_list;
800 /* list for the ost targets involve LFSCK. */
801 struct list_head lad_ost_list;
803 /* list for the ost targets in phase1 scanning. */
804 struct list_head lad_ost_phase1_list;
806 /* list for the ost targets in phase1 scanning. */
807 struct list_head lad_ost_phase2_list;
809 /* list for the mdt targets involve LFSCK. */
810 struct list_head lad_mdt_list;
812 /* list for the mdt targets in phase1 scanning. */
813 struct list_head lad_mdt_phase1_list;
815 /* list for the mdt targets in phase1 scanning. */
816 struct list_head lad_mdt_phase2_list;
818 const char *lad_name;
819 struct ptlrpc_thread lad_thread;
821 struct lfsck_assistant_operations *lad_ops;
823 cfs_bitmap_t *lad_bitmap;
827 int lad_assistant_status;
829 unsigned int lad_to_post:1,
830 lad_to_double_scan:1,
831 lad_in_double_scan:1,
834 bool lad_advance_lock;
837 #define LFSCK_TMPBUF_LEN 64
839 struct lfsck_lock_handle {
840 struct lustre_handle llh_pdo_lh;
841 struct lustre_handle llh_reg_lh;
842 enum ldlm_mode llh_pdo_mode;
843 enum ldlm_mode llh_reg_mode;
846 struct lfsck_thread_info {
847 struct lu_name lti_name_const;
848 struct lu_name lti_name;
849 struct lu_name lti_name2;
850 struct lu_buf lti_buf;
851 struct lu_buf lti_linkea_buf;
852 struct lu_buf lti_linkea_buf2;
853 struct lu_buf lti_big_buf;
854 struct lu_fid lti_fid;
855 struct lu_fid lti_fid2;
856 struct lu_fid lti_fid3;
857 struct lu_attr lti_la;
858 struct lu_attr lti_la2;
859 struct ost_id lti_oi;
861 struct lustre_mdt_attrs lti_lma;
862 /* old LMA for compatibility */
863 char lti_lma_old[LMA_OLD_SIZE];
865 struct dt_object_format lti_dof;
866 /* There will be '\0' at the end of the name. */
867 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
868 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
869 char lti_tmpbuf2[LFSCK_TMPBUF_LEN];
870 struct lfsck_request lti_lr;
871 struct lfsck_async_interpret_args lti_laia;
872 struct lfsck_async_interpret_args lti_laia2;
873 struct lfsck_start lti_start;
874 struct lfsck_stop lti_stop;
875 union ldlm_policy_data lti_policy;
876 struct ldlm_enqueue_info lti_einfo;
877 struct ldlm_res_id lti_resid;
879 struct filter_fid_old lti_old_pfid;
880 struct filter_fid lti_new_pfid;
882 struct dt_allocation_hint lti_hint;
883 struct lu_orphan_rec lti_rec;
884 struct lov_user_md lti_lum;
885 struct dt_insert_rec lti_dt_rec;
886 struct lu_object_conf lti_conf;
887 struct lu_seq_range lti_range;
888 struct lmv_mds_md_v1 lti_lmv;
889 struct lmv_mds_md_v1 lti_lmv2;
890 struct lmv_mds_md_v1 lti_lmv3;
891 struct lmv_mds_md_v1 lti_lmv4;
892 struct lfsck_lock_handle lti_llh;
896 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
897 struct lu_fid *fid, bool locked);
898 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
899 struct dt_object *obj, struct lustre_handle *lh,
900 __u64 bits, enum ldlm_mode mode);
901 void lfsck_ibits_unlock(struct lustre_handle *lh, enum ldlm_mode mode);
902 int lfsck_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
903 struct dt_object *obj, const char *name,
904 struct lfsck_lock_handle *llh, __u64 bits, enum ldlm_mode mode);
905 void lfsck_unlock(struct lfsck_lock_handle *llh);
906 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
907 struct lfsck_instance *lfsck,
908 const struct lu_fid *fid);
909 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
910 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
912 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
914 const char *lfsck_status2names(enum lfsck_status status);
915 void lfsck_component_cleanup(const struct lu_env *env,
916 struct lfsck_component *com);
917 void lfsck_instance_cleanup(const struct lu_env *env,
918 struct lfsck_instance *lfsck);
919 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
921 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *name);
922 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
924 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
925 struct lfsck_position *pos, bool init);
926 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
927 void lfsck_control_speed(struct lfsck_instance *lfsck);
928 void lfsck_control_speed_by_self(struct lfsck_component *com);
929 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
930 struct lfsck_assistant_data *
931 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
933 struct lfsck_assistant_object *
934 lfsck_assistant_object_init(const struct lu_env *env, const struct lu_fid *fid,
935 const struct lu_attr *attr, __u64 cookie,
938 lfsck_assistant_object_load(const struct lu_env *env,
939 struct lfsck_instance *lfsck,
940 struct lfsck_assistant_object *lso);
941 int lfsck_async_interpret_common(const struct lu_env *env,
942 struct ptlrpc_request *req,
944 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
945 struct lfsck_request *lr,
946 struct ptlrpc_request_set *set,
947 ptlrpc_interpterer_t interpterer,
948 void *args, int request);
949 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
950 struct lfsck_start_param *lsp);
951 int lfsck_checkpoint_generic(const struct lu_env *env,
952 struct lfsck_component *com);
953 void lfsck_post_generic(const struct lu_env *env,
954 struct lfsck_component *com, int *result);
955 int lfsck_double_scan_generic(const struct lu_env *env,
956 struct lfsck_component *com, int status);
957 void lfsck_quit_generic(const struct lu_env *env,
958 struct lfsck_component *com);
961 int lfsck_unpack_ent(struct lu_dirent *ent, __u64 *cookie, __u16 *type);
962 void lfsck_close_dir(const struct lu_env *env,
963 struct lfsck_instance *lfsck, int result);
964 int lfsck_open_dir(const struct lu_env *env,
965 struct lfsck_instance *lfsck, __u64 cookie);
966 int lfsck_master_engine(void *args);
967 int lfsck_assistant_engine(void *args);
969 /* lfsck_bookmark.c */
970 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
971 struct lfsck_bookmark *src);
972 int lfsck_bookmark_store(const struct lu_env *env,
973 struct lfsck_instance *lfsck);
974 int lfsck_bookmark_setup(const struct lu_env *env,
975 struct lfsck_instance *lfsck);
976 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
977 struct lfsck_start *start, bool reset);
979 /* lfsck_namespace.c */
980 int lfsck_namespace_trace_update(const struct lu_env *env,
981 struct lfsck_component *com,
982 const struct lu_fid *fid,
983 const __u8 flags, bool add);
984 int lfsck_namespace_check_exist(const struct lu_env *env,
985 struct dt_object *dir,
986 struct dt_object *obj, const char *name);
987 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
988 struct linkea_data *ldata);
989 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
990 struct lfsck_component *com,
991 struct dt_object *obj,
992 struct linkea_data *ldata);
993 int lfsck_namespace_repair_dangling(const struct lu_env *env,
994 struct lfsck_component *com,
995 struct dt_object *parent,
996 struct dt_object *child,
997 struct lfsck_namespace_req *lnr);
998 int lfsck_namespace_repair_dirent(const struct lu_env *env,
999 struct lfsck_component *com,
1000 struct dt_object *parent,
1001 struct dt_object *child,
1002 const char *name, const char *name2,
1003 __u16 type, bool update, bool dec);
1004 int lfsck_verify_linkea(const struct lu_env *env, struct dt_object *obj,
1005 const struct lu_name *cname, const struct lu_fid *pfid);
1006 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
1007 char *name, struct lu_fid *pfid);
1008 int lfsck_update_name_entry(const struct lu_env *env,
1009 struct lfsck_instance *lfsck,
1010 struct dt_object *dir, const char *name,
1011 const struct lu_fid *fid, __u32 type);
1012 int lfsck_namespace_setup(const struct lu_env *env,
1013 struct lfsck_instance *lfsck);
1015 /* lfsck_striped_dir.c */
1016 void lfsck_lmv_put(const struct lu_env *env, struct lfsck_lmv *llmv);
1017 int lfsck_read_stripe_lmv(const struct lu_env *env, struct dt_object *obj,
1018 struct lmv_mds_md_v1 *lmv);
1019 int lfsck_shard_name_to_index(const struct lu_env *env, const char *name,
1020 int namelen, __u16 type,
1021 const struct lu_fid *fid);
1022 bool lfsck_is_valid_slave_name_entry(const struct lu_env *env,
1023 struct lfsck_lmv *llmv,
1024 const char *name, int namelen);
1025 int lfsck_namespace_check_name(const struct lu_env *env,
1026 struct dt_object *parent,
1027 struct dt_object *child,
1028 const struct lu_name *cname);
1029 int lfsck_namespace_update_lmv(const struct lu_env *env,
1030 struct lfsck_component *com,
1031 struct dt_object *obj,
1032 struct lmv_mds_md_v1 *lmv, bool locked);
1033 int lfsck_namespace_verify_stripe_slave(const struct lu_env *env,
1034 struct lfsck_component *com,
1035 struct dt_object *obj,
1036 struct lfsck_lmv *llmv);
1037 int lfsck_namespace_scan_shard(const struct lu_env *env,
1038 struct lfsck_component *com,
1039 struct dt_object *child);
1040 int lfsck_namespace_notify_lmv_master_local(const struct lu_env *env,
1041 struct lfsck_component *com,
1042 struct dt_object *obj);
1043 int lfsck_namespace_repair_bad_name_hash(const struct lu_env *env,
1044 struct lfsck_component *com,
1045 struct dt_object *shard,
1046 struct lfsck_lmv *llmv,
1048 int lfsck_namespace_striped_dir_rescan(const struct lu_env *env,
1049 struct lfsck_component *com,
1050 struct lfsck_namespace_req *lnr);
1051 int lfsck_namespace_handle_striped_master(const struct lu_env *env,
1052 struct lfsck_component *com,
1053 struct lfsck_namespace_req *lnr);
1055 /* lfsck_layout.c */
1056 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
1058 extern const char dot[];
1059 extern const char dotdot[];
1060 extern const char *lfsck_flags_names[];
1061 extern const char *lfsck_param_names[];
1062 extern struct lu_context_key lfsck_thread_key;
1064 static inline bool name_is_dot_or_dotdot(const char *name, int namelen)
1066 return name[0] == '.' &&
1067 (namelen == 1 || (namelen == 2 && name[1] == '.'));
1070 static inline struct dt_device *lfsck_obj2dev(struct dt_object *obj)
1072 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
1075 static inline struct lfsck_thread_info *
1076 lfsck_env_info(const struct lu_env *env)
1078 struct lfsck_thread_info *info;
1080 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
1081 LASSERT(info != NULL);
1085 static inline const struct lu_name *
1086 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
1088 struct lu_name *lname;
1090 lname = &lfsck_env_info(env)->lti_name_const;
1091 lname->ln_name = area;
1092 lname->ln_namelen = len;
1097 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
1103 static inline struct lu_buf *
1104 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
1108 buf = &lfsck_env_info(env)->lti_buf;
1114 static inline const struct lu_buf *
1115 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
1119 buf = &lfsck_env_info(env)->lti_buf;
1120 buf->lb_buf = (void *)area;
1125 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
1127 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
1130 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
1132 return lu_object_fid(&obj->do_lu);
1135 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
1137 memset(pos, 0, sizeof(*pos));
1140 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
1142 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
1145 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
1146 const struct lfsck_position *pos2)
1148 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
1151 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
1154 if (fid_is_zero(&pos1->lp_dir_parent) &&
1155 !fid_is_zero(&pos2->lp_dir_parent))
1158 if (!fid_is_zero(&pos1->lp_dir_parent) &&
1159 fid_is_zero(&pos2->lp_dir_parent))
1162 if (fid_is_zero(&pos1->lp_dir_parent) &&
1163 fid_is_zero(&pos2->lp_dir_parent))
1166 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
1168 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
1171 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
1177 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
1178 struct lfsck_position *src)
1180 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
1181 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
1182 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
1185 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
1186 struct lfsck_position *src)
1188 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
1189 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
1190 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
1193 static inline umode_t lfsck_object_type(const struct dt_object *obj)
1195 return lu_object_attr(&obj->do_lu);
1198 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
1200 struct lu_object_header *loh = obj->do_lu.lo_header;
1202 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
1205 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
1207 lu_object_get(&obj->do_lu);
1211 static inline void lfsck_object_put(const struct lu_env *env,
1212 struct dt_object *obj)
1214 lu_object_put(env, &obj->do_lu);
1217 static inline struct seq_server_site
1218 *lfsck_dev_site(struct lfsck_instance *lfsck)
1220 return lu_site2seq(lfsck->li_bottom->dd_lu_dev.ld_site);
1223 static inline u32 lfsck_dev_idx(struct lfsck_instance *lfsck)
1225 return lfsck_dev_site(lfsck)->ss_node_id;
1228 static inline struct dt_object *
1229 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
1230 const struct lu_fid *fid)
1232 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
1234 conf->loc_flags = LOC_F_NOWAIT;
1235 return lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
1238 static inline struct dt_object *
1239 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
1240 const struct lu_fid *fid)
1242 return lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
1245 static inline struct dt_device *
1246 lfsck_find_dev_by_fid(const struct lu_env *env, struct lfsck_instance *lfsck,
1247 const struct lu_fid *fid)
1249 struct dt_device *dev;
1252 if (!lfsck->li_master)
1253 return lfsck->li_bottom;
1255 idx = lfsck_find_mdt_idx_by_fid(env, lfsck, fid);
1257 return ERR_PTR(idx);
1259 if (idx == lfsck_dev_idx(lfsck)) {
1260 dev = lfsck->li_bottom;
1262 struct lfsck_tgt_desc *ltd;
1264 ltd = lfsck_ltd2tgt(&lfsck->li_mdt_descs, idx);
1265 if (unlikely(ltd == NULL))
1266 return ERR_PTR(-ENODEV);
1274 static inline struct dt_object *
1275 lfsck_object_find_bottom(const struct lu_env *env, struct lfsck_instance *lfsck,
1276 const struct lu_fid *fid)
1278 struct dt_device *dev;
1280 dev = lfsck_find_dev_by_fid(env, lfsck, fid);
1282 return (struct dt_object *)dev;
1284 return lfsck_object_find_by_dev(env, dev, fid);
1287 static inline struct dt_object *
1288 lfsck_object_find_bottom_nowait(const struct lu_env *env,
1289 struct lfsck_instance *lfsck,
1290 const struct lu_fid *fid)
1292 struct dt_device *dev;
1294 dev = lfsck_find_dev_by_fid(env, lfsck, fid);
1296 return (struct dt_object *)dev;
1298 return lfsck_object_find_by_dev_nowait(env, dev, fid);
1301 static inline struct dt_object *
1302 lfsck_object_locate(struct dt_device *dev, struct dt_object *obj)
1304 if (lfsck_obj2dev(obj) == dev) {
1307 struct lu_object *lo;
1309 lo = lu_object_locate(obj->do_lu.lo_header,
1310 dev->dd_lu_dev.ld_type);
1311 if (unlikely(lo == NULL))
1312 return ERR_PTR(-ENOENT);
1318 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
1321 struct lfsck_tgt_desc *ltd;
1323 ltd = lfsck_ltd2tgt(ltds, index);
1325 atomic_inc(<d->ltd_ref);
1330 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
1332 if (atomic_dec_and_test(<d->ltd_ref))
1336 static inline struct lfsck_component *
1337 lfsck_component_get(struct lfsck_component *com)
1339 atomic_inc(&com->lc_ref);
1344 static inline void lfsck_component_put(const struct lu_env *env,
1345 struct lfsck_component *com)
1347 if (atomic_dec_and_test(&com->lc_ref)) {
1348 struct lfsck_sub_trace_obj *lsto;
1351 for (i = 0, lsto = &com->lc_sub_trace_objs[0];
1352 i < LFSCK_STF_COUNT; i++, lsto++) {
1353 if (lsto->lsto_obj != NULL)
1354 lfsck_object_put(env, lsto->lsto_obj);
1357 if (com->lc_obj != NULL)
1358 lfsck_object_put(env, com->lc_obj);
1359 if (com->lc_file_ram != NULL)
1360 OBD_FREE(com->lc_file_ram, com->lc_file_size);
1361 if (com->lc_file_disk != NULL)
1362 OBD_FREE(com->lc_file_disk, com->lc_file_size);
1363 if (com->lc_data != NULL) {
1364 LASSERT(com->lc_ops->lfsck_data_release != NULL);
1366 com->lc_ops->lfsck_data_release(env, com);
1373 static inline struct lfsck_instance *
1374 lfsck_instance_get(struct lfsck_instance *lfsck)
1376 atomic_inc(&lfsck->li_ref);
1381 static inline void lfsck_instance_put(const struct lu_env *env,
1382 struct lfsck_instance *lfsck)
1384 if (atomic_dec_and_test(&lfsck->li_ref))
1385 lfsck_instance_cleanup(env, lfsck);
1388 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1390 return list_empty(&lad->lad_mdt_phase1_list) &&
1391 (!list_empty(&lad->lad_ost_phase2_list) ||
1392 list_empty(&lad->lad_ost_phase1_list));
1395 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1396 struct lfsck_component *com,
1399 struct lfsck_assistant_data *lad = com->lc_data;
1400 cfs_bitmap_t *bitmap = lad->lad_bitmap;
1402 LASSERT(com->lc_lfsck->li_master);
1403 LASSERT(bitmap != NULL);
1405 if (likely(bitmap->size > index)) {
1406 cfs_bitmap_set(bitmap, index);
1407 lad->lad_incomplete = 1;
1408 } else if (com->lc_type == LFSCK_TYPE_NAMESPACE) {
1409 struct lfsck_namespace *ns = com->lc_file_ram;
1411 ns->ln_flags |= LF_INCOMPLETE;
1415 static inline int lfsck_links_read(const struct lu_env *env,
1416 struct dt_object *obj,
1417 struct linkea_data *ldata)
1420 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1423 return __lfsck_links_read(env, obj, ldata);
1426 static inline int lfsck_links_read2(const struct lu_env *env,
1427 struct dt_object *obj,
1428 struct linkea_data *ldata)
1431 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1434 return __lfsck_links_read(env, obj, ldata);
1437 static inline struct lfsck_lmv *lfsck_lmv_get(struct lfsck_lmv *llmv)
1440 atomic_inc(&llmv->ll_ref);
1445 static inline int lfsck_sub_trace_file_fid2idx(const struct lu_fid *fid)
1447 return fid->f_oid & (LFSCK_STF_COUNT - 1);
1450 static inline void lfsck_lmv_header_le_to_cpu(struct lmv_mds_md_v1 *dst,
1451 const struct lmv_mds_md_v1 *src)
1453 dst->lmv_magic = le32_to_cpu(src->lmv_magic);
1454 dst->lmv_stripe_count = le32_to_cpu(src->lmv_stripe_count);
1455 dst->lmv_master_mdt_index = le32_to_cpu(src->lmv_master_mdt_index);
1456 dst->lmv_hash_type = le32_to_cpu(src->lmv_hash_type);
1457 dst->lmv_layout_version = le32_to_cpu(src->lmv_layout_version);
1460 static inline void lfsck_lmv_header_cpu_to_le(struct lmv_mds_md_v1 *dst,
1461 const struct lmv_mds_md_v1 *src)
1463 dst->lmv_magic = cpu_to_le32(src->lmv_magic);
1464 dst->lmv_stripe_count = cpu_to_le32(src->lmv_stripe_count);
1465 dst->lmv_master_mdt_index = cpu_to_le32(src->lmv_master_mdt_index);
1466 dst->lmv_hash_type = cpu_to_le32(src->lmv_hash_type);
1467 dst->lmv_layout_version = cpu_to_le32(src->lmv_layout_version);
1470 static inline struct lfsck_assistant_object *
1471 lfsck_assistant_object_get(struct lfsck_assistant_object *lso)
1473 atomic_inc(&lso->lso_ref);
1479 lfsck_assistant_object_put(const struct lu_env *env,
1480 struct lfsck_assistant_object *lso)
1482 if (atomic_dec_and_test(&lso->lso_ref))
1485 #endif /* _LFSCK_INTERNAL_H */