4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (c) 2013, Intel Corporation.
26 * lustre/lfsck/lfsck_internal.h
28 * Shared definitions and declarations for the LFSCK.
30 * Author: Fan, Yong <fan.yong@intel.com>
33 #ifndef _LFSCK_INTERNAL_H
34 # define _LFSCK_INTERNAL_H
36 #include <lustre/lustre_lfsck_user.h>
37 #include <lustre/lustre_user.h>
38 #include <lustre/lustre_idl.h>
39 #include <lustre_lfsck.h>
41 #include <lu_object.h>
42 #include <dt_object.h>
43 #include <md_object.h>
44 #include <lustre_net.h>
45 #include <lustre_dlm.h>
46 #include <lustre_fid.h>
47 #include <md_object.h>
48 #include <lustre_linkea.h>
50 #define HALF_SEC (HZ >> 1)
51 #define LFSCK_CHECKPOINT_INTERVAL 60
54 /* Finish the first cycle scanning. */
55 LF_SCANNED_ONCE = 0x00000001ULL,
57 /* There is some namespace inconsistency. */
58 LF_INCONSISTENT = 0x00000002ULL,
60 /* The device is upgraded from 1.8 format. */
61 LF_UPGRADE = 0x00000004ULL,
63 /* The server ever restarted during the LFSCK, and may miss to process
64 * some objects check/repair. */
65 LF_INCOMPLETE = 0x00000008ULL,
67 /* The LAST_ID (file) crashed. */
68 LF_CRASHED_LASTID = 0x00000010ULL,
71 struct lfsck_position {
72 /* low layer object table-based iteration position. */
75 /* parent FID for directory traversal. */
76 struct lu_fid lp_dir_parent;
78 /* namespace-based directory traversal position. */
82 struct lfsck_bookmark {
83 /* Magic number to detect that this struct contains valid data. */
86 /* For compatible with old versions. */
89 /* See 'enum lfsck_param_flags' */
92 /* How many items can be scanned at most per second. */
95 /* The windows size for async requests pipeline. */
96 __u16 lb_async_windows;
98 /* For 64-bits aligned. */
101 /* The FID for .lustre/lost+found/MDTxxxx */
102 struct lu_fid lb_lpf_fid;
104 /* The FID for the last MDT-object created by the LFSCK repairing. */
105 struct lu_fid lb_last_fid;
107 /* For future using. */
108 __u64 lb_reserved[2];
111 enum lfsck_namespace_trace_flags {
112 LNTF_CHECK_LINKEA = 0x01,
113 LNTF_CHECK_PARENT = 0x02,
117 enum lfsck_namespace_inconsistency_type {
120 LNIT_UNMATCHED_PAIRS = 2,
125 struct lfsck_namespace {
126 /* Magic number to detect that this struct contains valid data. */
129 /* See 'enum lfsck_status'. */
132 /* See 'enum lfsck_flags'. */
135 /* How many completed LFSCK runs on the device. */
136 __u32 ln_success_count;
138 /* How long the LFSCK phase1 has run in seconds. */
139 __u32 ln_run_time_phase1;
141 /* How long the LFSCK phase2 has run in seconds. */
142 __u32 ln_run_time_phase2;
144 /* Time for the last LFSCK completed in seconds since epoch. */
145 __u64 ln_time_last_complete;
147 /* Time for the latest LFSCK ran in seconds since epoch. */
148 __u64 ln_time_latest_start;
150 /* Time for the last LFSCK checkpoint in seconds since epoch. */
151 __u64 ln_time_last_checkpoint;
153 /* Position for the latest LFSCK started from. */
154 struct lfsck_position ln_pos_latest_start;
156 /* Position for the last LFSCK checkpoint. */
157 struct lfsck_position ln_pos_last_checkpoint;
159 /* Position for the first should be updated object. */
160 struct lfsck_position ln_pos_first_inconsistent;
162 /* How many items (including dir) have been checked. */
163 __u64 ln_items_checked;
165 /* How many items have been repaired. */
166 __u64 ln_items_repaired;
168 /* How many items failed to be processed. */
169 __u64 ln_items_failed;
171 /* How many directories have been traversed. */
172 __u64 ln_dirs_checked;
174 /* How many objects have been double scanned. */
175 __u64 ln_objs_checked_phase2;
177 /* How many objects have been reparied during double scan. */
178 __u64 ln_objs_repaired_phase2;
180 /* How many objects failed to be processed during double scan. */
181 __u64 ln_objs_failed_phase2;
183 /* How many objects with nlink fixed. */
184 __u64 ln_objs_nlink_repaired;
186 /* How many objects were lost before, but found back now. */
187 __u64 ln_objs_lost_found;
189 /* The latest object has been processed (failed) during double scan. */
190 struct lu_fid ln_fid_latest_scanned_phase2;
192 /* How many FID-in-dirent entries have been repaired. */
193 __u64 ln_dirent_repaired;
195 /* How many linkEA entries have been repaired. */
196 __u64 ln_linkea_repaired;
198 /* How many multiple-linked objects have been checked. */
199 __u64 ln_mul_linked_checked;
201 /* How many multiple-linked objects have been repaired. */
202 __u64 ln_mul_linked_repaired;
204 /* How many undefined inconsistency found in phase2. */
205 __u64 ln_unknown_inconsistency;
207 /* How many unmatched pairs have been repaired. */
208 __u64 ln_unmatched_pairs_repaired;
210 /* How many dangling name entries have been found/repaired. */
211 __u64 ln_dangling_repaired;
213 /* How many multiple referenced name entries have been
215 __u64 ln_mul_ref_repaired;
217 /* For further using. 256-bytes aligned now. */
218 __u64 ln_reserved[27];
221 enum lfsck_layout_inconsistency_type {
224 LLIT_UNMATCHED_PAIR = 2,
225 LLIT_MULTIPLE_REFERENCED = 3,
227 LLIT_INCONSISTENT_OWNER = 5,
229 LLIT_MAX = LLIT_OTHERS
232 struct lfsck_layout {
233 /* Magic number to detect that this struct contains valid data. */
236 /* See 'enum lfsck_status'. */
239 /* See 'enum lfsck_flags'. */
242 /* How many completed LFSCK runs on the device. */
243 __u32 ll_success_count;
245 /* How long the LFSCK phase1 has run in seconds. */
246 __u32 ll_run_time_phase1;
248 /* How long the LFSCK phase2 has run in seconds. */
249 __u32 ll_run_time_phase2;
251 /* Time for the last LFSCK completed in seconds since epoch. */
252 __u64 ll_time_last_complete;
254 /* Time for the latest LFSCK ran in seconds since epoch. */
255 __u64 ll_time_latest_start;
257 /* Time for the last LFSCK checkpoint in seconds since epoch. */
258 __u64 ll_time_last_checkpoint;
260 /* Position for the latest LFSCK started from. */
261 __u64 ll_pos_latest_start;
263 /* Position for the last LFSCK checkpoint. */
264 __u64 ll_pos_last_checkpoint;
266 /* Position for the first object to be fixed or
267 * failed to be checked in the phase1. */
268 __u64 ll_pos_first_inconsistent;
270 /* How many objects have been checked. */
271 __u64 ll_objs_checked_phase1;
273 /* How many objects failed to be processed. */
274 __u64 ll_objs_failed_phase1;
276 /* How many objects have been double scanned. */
277 __u64 ll_objs_checked_phase2;
279 /* How many objects failed to be processed during double scan. */
280 __u64 ll_objs_failed_phase2;
282 /* kinds of inconsistency have been or to be repaired.
283 * ll_objs_repaired[type - 1] is the count for the given @type. */
284 __u64 ll_objs_repaired[LLIT_MAX];
286 /* How many objects have been skipped because of related
287 * MDT(s)/OST(s) do not participate in the LFSCK */
288 __u64 ll_objs_skipped;
290 /* The size of ll_ost_bitmap with nbits. */
291 __u32 ll_bitmap_size;
293 /* For further using. 256-bytes aligned now. */
295 __u64 ll_reserved_2[11];
297 /* The OST targets bitmap to record the OSTs that contain
298 * non-verified OST-objects. */
299 __u8 ll_ost_bitmap[0];
302 struct lfsck_component;
303 struct lfsck_tgt_descs;
304 struct lfsck_tgt_desc;
306 struct lfsck_operations {
307 int (*lfsck_reset)(const struct lu_env *env,
308 struct lfsck_component *com,
311 void (*lfsck_fail)(const struct lu_env *env,
312 struct lfsck_component *com,
315 int (*lfsck_checkpoint)(const struct lu_env *env,
316 struct lfsck_component *com,
319 int (*lfsck_prep)(const struct lu_env *env,
320 struct lfsck_component *com,
321 struct lfsck_start_param *lsp);
323 int (*lfsck_exec_oit)(const struct lu_env *env,
324 struct lfsck_component *com,
325 struct dt_object *obj);
327 int (*lfsck_exec_dir)(const struct lu_env *env,
328 struct lfsck_component *com,
329 struct lu_dirent *ent,
332 int (*lfsck_post)(const struct lu_env *env,
333 struct lfsck_component *com,
337 int (*lfsck_dump)(const struct lu_env *env,
338 struct lfsck_component *com,
341 int (*lfsck_double_scan)(const struct lu_env *env,
342 struct lfsck_component *com);
344 void (*lfsck_data_release)(const struct lu_env *env,
345 struct lfsck_component *com);
347 void (*lfsck_quit)(const struct lu_env *env,
348 struct lfsck_component *com);
350 int (*lfsck_in_notify)(const struct lu_env *env,
351 struct lfsck_component *com,
352 struct lfsck_request *lr);
354 int (*lfsck_query)(const struct lu_env *env,
355 struct lfsck_component *com);
357 int (*lfsck_join)(const struct lu_env *env,
358 struct lfsck_component *com,
359 struct lfsck_start_param *lsp);
362 #define TGT_PTRS 256 /* number of pointers at 1st level */
363 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
365 struct lfsck_tgt_desc {
366 struct list_head ltd_orphan_list;
367 struct dt_device *ltd_tgt;
368 struct dt_device *ltd_key;
369 struct obd_export *ltd_exp;
370 struct list_head ltd_layout_list;
371 struct list_head ltd_layout_phase_list;
372 struct list_head ltd_namespace_list;
373 struct list_head ltd_namespace_phase_list;
376 __u32 ltd_layout_gen;
377 __u32 ltd_namespace_gen;
378 unsigned int ltd_dead:1,
380 ltd_namespace_done:1;
383 struct lfsck_tgt_desc_idx {
384 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
387 struct lfsck_tgt_descs {
388 /* list of known TGTs */
389 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
391 /* bitmap of TGTs available */
392 cfs_bitmap_t *ltd_tgts_bitmap;
394 /* for lfsck_tgt_desc::ltd_xxx_list */
397 /* for tgts table accessing and changes */
398 struct rw_semaphore ltd_rw_sem;
400 /* Temporary list for orphan targets. */
401 struct list_head ltd_orphan;
403 /* number of registered TGTs */
407 #define LTD_TGT(ltd, index) \
408 ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
409 ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
411 #define OST_TGT(lfsck, index) LTD_TGT(&lfsck->li_ost_descs, index)
412 #define MDT_TGT(lfsck, index) LTD_TGT(&lfsck->li_mdt_descs, index)
414 struct lfsck_component {
415 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
416 struct list_head lc_link;
418 /* into lfsck_instance::li_list_dir */
419 struct list_head lc_link_dir;
421 struct rw_semaphore lc_sem;
424 struct lfsck_position lc_pos_start;
425 struct lfsck_instance *lc_lfsck;
426 struct dt_object *lc_obj;
427 struct lfsck_operations *lc_ops;
431 struct lu_fid lc_fid_latest_scanned_phase2;
433 /* The time for last checkpoint, jiffies */
434 cfs_time_t lc_time_last_checkpoint;
436 /* The time for next checkpoint, jiffies */
437 cfs_time_t lc_time_next_checkpoint;
441 /* How many objects have been checked since last checkpoint. */
442 __u32 lc_new_checked;
444 /* How many objects have been scanned since last sleep. */
445 __u32 lc_new_scanned;
450 struct lfsck_instance {
451 struct mutex li_mutex;
454 /* Link into the lfsck_instance_list. */
455 struct list_head li_link;
457 /* For the components in (first) scanning via otable-based iteration. */
458 struct list_head li_list_scan;
460 /* For the components in scanning via directory traversal. Because
461 * directory traversal cannot guarantee all the object be scanned,
462 * so the component in the li_list_dir must be in li_list_scan. */
463 struct list_head li_list_dir;
465 /* For the components in double scanning. */
466 struct list_head li_list_double_scan;
468 /* For the components those are not scanning now. */
469 struct list_head li_list_idle;
472 atomic_t li_double_scan_count;
473 struct ptlrpc_thread li_thread;
475 /* The time for last checkpoint, jiffies */
476 cfs_time_t li_time_last_checkpoint;
478 /* The time for next checkpoint, jiffies */
479 cfs_time_t li_time_next_checkpoint;
481 lfsck_out_notify li_out_notify;
482 void *li_out_notify_data;
483 struct dt_device *li_next;
484 struct dt_device *li_bottom;
485 struct obd_device *li_obd;
486 struct ldlm_namespace *li_namespace;
487 struct local_oid_storage *li_los;
488 struct lu_fid li_local_root_fid; /* backend root "/" */
489 struct lu_fid li_global_root_fid; /* /ROOT */
490 struct dt_object *li_bookmark_obj;
491 struct dt_object *li_lpf_obj;
492 struct lu_client_seq *li_seq;
493 struct lfsck_bookmark li_bookmark_ram;
494 struct lfsck_bookmark li_bookmark_disk;
495 struct lfsck_position li_pos_current;
496 struct lfsck_position li_pos_checkpoint;
498 /* Obj for otable-based iteration */
499 struct dt_object *li_obj_oit;
501 /* Obj for directory traversal */
502 struct dt_object *li_obj_dir;
504 /* It for otable-based iteration */
505 struct dt_it *li_di_oit;
507 /* It for directory traversal */
508 struct dt_it *li_di_dir;
510 /* Description of OST */
511 struct lfsck_tgt_descs li_ost_descs;
513 /* Description of MDT */
514 struct lfsck_tgt_descs li_mdt_descs;
516 /* namespace-based directory traversal position. */
519 /* Arguments for low layer otable-based iteration. */
522 /* Arugments for namespace-based directory traversal. */
525 /* Schedule for every N objects. */
528 /* Sleep N jiffies for each schedule. */
531 /* How many objects have been scanned since last sleep. */
532 __u32 li_new_scanned;
534 /* The status when the LFSCK stopped or paused. */
537 /* The flags when the lFSCK stopped or paused. */
540 unsigned int li_oit_over:1, /* oit is finished. */
541 li_drop_dryrun:1, /* Ever dryrun, not now. */
542 li_master:1, /* Master instance or not. */
543 li_current_oit_processed:1,
547 struct lfsck_async_interpret_args {
548 struct lfsck_component *laia_com;
549 struct lfsck_tgt_descs *laia_ltds;
550 struct lfsck_tgt_desc *laia_ltd;
551 struct lfsck_request *laia_lr;
552 atomic_t *laia_count;
554 unsigned int laia_shared:1;
557 struct lfsck_thread_args {
558 struct lu_env lta_env;
559 struct lfsck_instance *lta_lfsck;
560 struct lfsck_component *lta_com;
561 struct lfsck_start_param *lta_lsp;
564 struct lfsck_assistant_req {
565 struct list_head lar_list;
568 struct lfsck_namespace_req {
569 struct lfsck_assistant_req lnr_lar;
570 struct dt_object *lnr_obj;
571 struct lu_fid lnr_fid;
572 __u64 lnr_oit_cookie;
573 __u64 lnr_dir_cookie;
581 struct lfsck_assistant_operations {
582 int (*la_handler_p1)(const struct lu_env *env,
583 struct lfsck_component *com,
584 struct lfsck_assistant_req *lar);
586 int (*la_handler_p2)(const struct lu_env *env,
587 struct lfsck_component *com);
589 void (*la_fill_pos)(const struct lu_env *env,
590 struct lfsck_component *com,
591 struct lfsck_position *pos);
593 int (*la_double_scan_result)(const struct lu_env *env,
594 struct lfsck_component *com,
597 void (*la_req_fini)(const struct lu_env *env,
598 struct lfsck_assistant_req *lar);
600 void (*la_sync_failures)(const struct lu_env *env,
601 struct lfsck_component *com,
602 struct lfsck_request *lr);
605 struct lfsck_assistant_data {
607 struct list_head lad_req_list;
609 /* list for the ost targets involve LFSCK. */
610 struct list_head lad_ost_list;
612 /* list for the ost targets in phase1 scanning. */
613 struct list_head lad_ost_phase1_list;
615 /* list for the ost targets in phase1 scanning. */
616 struct list_head lad_ost_phase2_list;
618 /* list for the mdt targets involve LFSCK. */
619 struct list_head lad_mdt_list;
621 /* list for the mdt targets in phase1 scanning. */
622 struct list_head lad_mdt_phase1_list;
624 /* list for the mdt targets in phase1 scanning. */
625 struct list_head lad_mdt_phase2_list;
627 const char *lad_name;
628 struct ptlrpc_thread lad_thread;
630 struct lfsck_assistant_operations *lad_ops;
632 cfs_bitmap_t *lad_bitmap;
636 int lad_assistant_status;
638 unsigned int lad_to_post:1,
639 lad_to_double_scan:1,
640 lad_in_double_scan:1,
645 #define LFSCK_TMPBUF_LEN 64
647 struct lfsck_thread_info {
648 struct lu_name lti_name_const;
649 struct lu_name lti_name;
650 struct lu_buf lti_buf;
651 struct lu_buf lti_linkea_buf;
652 struct lu_buf lti_linkea_buf2;
653 struct lu_buf lti_big_buf;
654 struct lu_fid lti_fid;
655 struct lu_fid lti_fid2;
656 struct lu_fid lti_fid3;
657 struct lu_fid lti_fid4;
658 struct lu_fid lti_fid5;
659 struct lu_attr lti_la;
660 struct lu_attr lti_la2;
661 struct lu_attr lti_la3;
662 struct ost_id lti_oi;
664 struct lustre_mdt_attrs lti_lma;
665 /* old LMA for compatibility */
666 char lti_lma_old[LMA_OLD_SIZE];
668 struct dt_object_format lti_dof;
669 /* There will be '\0' at the end of the name. */
670 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
671 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
672 struct lfsck_request lti_lr;
673 struct lfsck_async_interpret_args lti_laia;
674 struct lfsck_async_interpret_args lti_laia2;
675 struct lfsck_start lti_start;
676 struct lfsck_stop lti_stop;
677 ldlm_policy_data_t lti_policy;
678 struct ldlm_res_id lti_resid;
680 struct filter_fid_old lti_old_pfid;
681 struct filter_fid lti_new_pfid;
683 struct dt_allocation_hint lti_hint;
684 struct lu_orphan_rec lti_rec;
685 struct lov_user_md lti_lum;
686 struct dt_insert_rec lti_dt_rec;
687 struct lu_object_conf lti_conf;
688 struct lu_seq_range lti_range;
692 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
693 struct lu_fid *fid, bool locked);
694 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
695 struct dt_object *obj, struct lustre_handle *lh,
696 __u64 bits, ldlm_mode_t mode);
697 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
698 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
699 struct lfsck_instance *lfsck,
700 const struct lu_fid *fid);
701 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
702 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
703 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
705 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
707 const char *lfsck_status2names(enum lfsck_status status);
708 void lfsck_component_cleanup(const struct lu_env *env,
709 struct lfsck_component *com);
710 void lfsck_instance_cleanup(const struct lu_env *env,
711 struct lfsck_instance *lfsck);
712 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
714 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
715 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
717 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
718 struct lfsck_position *pos, bool init);
719 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
720 void lfsck_control_speed(struct lfsck_instance *lfsck);
721 void lfsck_control_speed_by_self(struct lfsck_component *com);
722 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
723 struct lfsck_assistant_data *
724 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
726 int lfsck_async_interpret_common(const struct lu_env *env,
727 struct ptlrpc_request *req,
729 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
730 struct lfsck_request *lr,
731 struct ptlrpc_request_set *set,
732 ptlrpc_interpterer_t interpterer,
733 void *args, int request);
734 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
735 struct lfsck_start_param *lsp);
736 int lfsck_checkpoint_generic(const struct lu_env *env,
737 struct lfsck_component *com);
738 void lfsck_post_generic(const struct lu_env *env,
739 struct lfsck_component *com, int *result);
740 int lfsck_double_scan_generic(const struct lu_env *env,
741 struct lfsck_component *com, int status);
742 void lfsck_quit_generic(const struct lu_env *env,
743 struct lfsck_component *com);
746 int lfsck_master_engine(void *args);
747 int lfsck_assistant_engine(void *args);
749 /* lfsck_bookmark.c */
750 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
751 struct lfsck_bookmark *src);
752 int lfsck_bookmark_store(const struct lu_env *env,
753 struct lfsck_instance *lfsck);
754 int lfsck_bookmark_setup(const struct lu_env *env,
755 struct lfsck_instance *lfsck);
756 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
757 struct lfsck_start *start, bool reset);
759 /* lfsck_namespace.c */
760 int lfsck_namespace_trace_update(const struct lu_env *env,
761 struct lfsck_component *com,
762 const struct lu_fid *fid,
763 const __u8 flags, bool add);
764 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
765 struct linkea_data *ldata);
766 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
767 struct lfsck_component *com,
768 struct dt_object *obj,
769 struct linkea_data *ldata);
770 int lfsck_namespace_repair_dangling(const struct lu_env *env,
771 struct lfsck_component *com,
772 struct dt_object *child,
773 struct lfsck_namespace_req *lnr);
774 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
775 struct dt_object *obj, const struct lu_name *cname,
776 const struct lu_fid *pfid);
777 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
778 char *name, struct lu_fid *pfid);
779 int lfsck_remove_name_entry(const struct lu_env *env,
780 struct lfsck_instance *lfsck,
781 struct dt_object *parent,
782 const char *name, __u32 type);
783 int lfsck_update_name_entry(const struct lu_env *env,
784 struct lfsck_instance *lfsck,
785 struct dt_object *parent, const char *name,
786 const struct lu_fid *pfid, __u32 type);
787 int lfsck_namespace_setup(const struct lu_env *env,
788 struct lfsck_instance *lfsck);
791 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
793 extern const char dot[];
794 extern const char dotdot[];
795 extern const char *lfsck_flags_names[];
796 extern const char *lfsck_param_names[];
797 extern struct lu_context_key lfsck_thread_key;
799 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
801 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
804 static inline struct lfsck_thread_info *
805 lfsck_env_info(const struct lu_env *env)
807 struct lfsck_thread_info *info;
809 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
810 LASSERT(info != NULL);
814 static inline const struct lu_name *
815 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
817 struct lu_name *lname;
819 lname = &lfsck_env_info(env)->lti_name_const;
820 lname->ln_name = area;
821 lname->ln_namelen = len;
826 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
832 static inline struct lu_buf *
833 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
837 buf = &lfsck_env_info(env)->lti_buf;
843 static inline const struct lu_buf *
844 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
848 buf = &lfsck_env_info(env)->lti_buf;
849 buf->lb_buf = (void *)area;
854 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
856 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
859 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
861 return lu_object_fid(&obj->do_lu);
864 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
866 memset(pos, 0, sizeof(*pos));
869 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
871 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
874 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
875 const struct lfsck_position *pos2)
877 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
880 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
883 if (fid_is_zero(&pos1->lp_dir_parent) &&
884 !fid_is_zero(&pos2->lp_dir_parent))
887 if (!fid_is_zero(&pos1->lp_dir_parent) &&
888 fid_is_zero(&pos2->lp_dir_parent))
891 if (fid_is_zero(&pos1->lp_dir_parent) &&
892 fid_is_zero(&pos2->lp_dir_parent))
895 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
897 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
900 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
906 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
907 struct lfsck_position *src)
909 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
910 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
911 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
914 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
915 struct lfsck_position *src)
917 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
918 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
919 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
922 static inline umode_t lfsck_object_type(const struct dt_object *obj)
924 return lu_object_attr(&obj->do_lu);
927 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
929 struct lu_object_header *loh = obj->do_lu.lo_header;
931 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
934 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
936 lu_object_get(&obj->do_lu);
940 static inline void lfsck_object_put(const struct lu_env *env,
941 struct dt_object *obj)
943 lu_object_put(env, &obj->do_lu);
946 static inline u32 lfsck_dev_idx(struct dt_device *dev)
948 return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
951 static inline struct dt_object *
952 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
953 const struct lu_fid *fid)
955 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
956 struct dt_object *obj;
958 conf->loc_flags = LOC_F_NOWAIT;
959 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
960 if (unlikely(obj == NULL))
961 return ERR_PTR(-ENOENT);
966 static inline struct dt_object *
967 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
968 const struct lu_fid *fid)
970 struct dt_object *obj;
972 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
973 if (unlikely(obj == NULL))
974 return ERR_PTR(-ENOENT);
979 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
980 struct lfsck_instance *lfsck,
981 const struct lu_fid *fid)
983 return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
986 static inline struct dt_object *
987 lfsck_object_find_bottom(const struct lu_env *env, struct lfsck_instance *lfsck,
988 const struct lu_fid *fid)
990 struct dt_device *dev;
993 idx = lfsck_find_mdt_idx_by_fid(env, lfsck, fid);
997 if (idx == lfsck_dev_idx(lfsck->li_bottom)) {
998 dev = lfsck->li_bottom;
1000 struct lfsck_tgt_desc *ltd;
1002 ltd = LTD_TGT(&lfsck->li_mdt_descs, idx);
1003 if (unlikely(ltd == NULL))
1004 return ERR_PTR(-ENODEV);
1009 return lfsck_object_find_by_dev(env, dev, fid);
1012 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
1015 struct lfsck_tgt_desc *ltd;
1017 ltd = LTD_TGT(ltds, index);
1019 atomic_inc(<d->ltd_ref);
1024 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
1026 if (atomic_dec_and_test(<d->ltd_ref))
1030 static inline struct lfsck_component *
1031 lfsck_component_get(struct lfsck_component *com)
1033 atomic_inc(&com->lc_ref);
1038 static inline void lfsck_component_put(const struct lu_env *env,
1039 struct lfsck_component *com)
1041 if (atomic_dec_and_test(&com->lc_ref)) {
1042 if (com->lc_obj != NULL)
1043 lu_object_put_nocache(env, &com->lc_obj->do_lu);
1044 if (com->lc_file_ram != NULL)
1045 OBD_FREE(com->lc_file_ram, com->lc_file_size);
1046 if (com->lc_file_disk != NULL)
1047 OBD_FREE(com->lc_file_disk, com->lc_file_size);
1048 if (com->lc_data != NULL) {
1049 LASSERT(com->lc_ops->lfsck_data_release != NULL);
1051 com->lc_ops->lfsck_data_release(env, com);
1058 static inline struct lfsck_instance *
1059 lfsck_instance_get(struct lfsck_instance *lfsck)
1061 atomic_inc(&lfsck->li_ref);
1066 static inline void lfsck_instance_put(const struct lu_env *env,
1067 struct lfsck_instance *lfsck)
1069 if (atomic_dec_and_test(&lfsck->li_ref))
1070 lfsck_instance_cleanup(env, lfsck);
1073 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1075 return list_empty(&lad->lad_mdt_phase1_list) &&
1076 (!list_empty(&lad->lad_ost_phase2_list) ||
1077 list_empty(&lad->lad_ost_phase1_list));
1080 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1081 struct lfsck_component *com,
1084 struct lfsck_assistant_data *lad = com->lc_data;
1085 cfs_bitmap_t *bitmap = lad->lad_bitmap;
1087 LASSERT(com->lc_lfsck->li_master);
1088 LASSERT(bitmap != NULL);
1089 LASSERTF(bitmap->size > index, "invalid index: nbits %d, index %u\n",
1090 bitmap->size, index);
1092 cfs_bitmap_set(bitmap, index);
1093 lad->lad_incomplete = 1;
1096 static inline int lfsck_links_read(const struct lu_env *env,
1097 struct dt_object *obj,
1098 struct linkea_data *ldata)
1101 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1104 return __lfsck_links_read(env, obj, ldata);
1107 static inline int lfsck_links_read2(const struct lu_env *env,
1108 struct dt_object *obj,
1109 struct linkea_data *ldata)
1112 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1115 return __lfsck_links_read(env, obj, ldata);
1118 #endif /* _LFSCK_INTERNAL_H */