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,
123 struct lfsck_namespace {
124 /* Magic number to detect that this struct contains valid data. */
127 /* See 'enum lfsck_status'. */
130 /* See 'enum lfsck_flags'. */
133 /* How many completed LFSCK runs on the device. */
134 __u32 ln_success_count;
136 /* How long the LFSCK phase1 has run in seconds. */
137 __u32 ln_run_time_phase1;
139 /* How long the LFSCK phase2 has run in seconds. */
140 __u32 ln_run_time_phase2;
142 /* Time for the last LFSCK completed in seconds since epoch. */
143 __u64 ln_time_last_complete;
145 /* Time for the latest LFSCK ran in seconds since epoch. */
146 __u64 ln_time_latest_start;
148 /* Time for the last LFSCK checkpoint in seconds since epoch. */
149 __u64 ln_time_last_checkpoint;
151 /* Position for the latest LFSCK started from. */
152 struct lfsck_position ln_pos_latest_start;
154 /* Position for the last LFSCK checkpoint. */
155 struct lfsck_position ln_pos_last_checkpoint;
157 /* Position for the first should be updated object. */
158 struct lfsck_position ln_pos_first_inconsistent;
160 /* How many items (including dir) have been checked. */
161 __u64 ln_items_checked;
163 /* How many items have been repaired. */
164 __u64 ln_items_repaired;
166 /* How many items failed to be processed. */
167 __u64 ln_items_failed;
169 /* How many directories have been traversed. */
170 __u64 ln_dirs_checked;
172 /* How many objects have been double scanned. */
173 __u64 ln_objs_checked_phase2;
175 /* How many objects have been reparied during double scan. */
176 __u64 ln_objs_repaired_phase2;
178 /* How many objects failed to be processed during double scan. */
179 __u64 ln_objs_failed_phase2;
181 /* How many objects with nlink fixed. */
182 __u64 ln_objs_nlink_repaired;
184 /* How many objects were lost before, but found back now. */
185 __u64 ln_objs_lost_found;
187 /* The latest object has been processed (failed) during double scan. */
188 struct lu_fid ln_fid_latest_scanned_phase2;
190 /* How many FID-in-dirent entries have been repaired. */
191 __u64 ln_dirent_repaired;
193 /* How many linkEA entries have been repaired. */
194 __u64 ln_linkea_repaired;
196 /* How many multiple-linked objects have been checked. */
197 __u64 ln_mul_linked_checked;
199 /* How many multiple-linked objects have been repaired. */
200 __u64 ln_mul_linked_repaired;
202 /* How many undefined inconsistency found in phase2. */
203 __u64 ln_unknown_inconsistency;
205 /* How many unmatched pairs have been repaired. */
206 __u64 ln_unmatched_pairs_repaired;
208 /* For further using. 256-bytes aligned now. */
209 __u64 ln_reserved[29];
212 enum lfsck_layout_inconsistency_type {
215 LLIT_UNMATCHED_PAIR = 2,
216 LLIT_MULTIPLE_REFERENCED = 3,
218 LLIT_INCONSISTENT_OWNER = 5,
220 LLIT_MAX = LLIT_OTHERS
223 struct lfsck_layout {
224 /* Magic number to detect that this struct contains valid data. */
227 /* See 'enum lfsck_status'. */
230 /* See 'enum lfsck_flags'. */
233 /* How many completed LFSCK runs on the device. */
234 __u32 ll_success_count;
236 /* How long the LFSCK phase1 has run in seconds. */
237 __u32 ll_run_time_phase1;
239 /* How long the LFSCK phase2 has run in seconds. */
240 __u32 ll_run_time_phase2;
242 /* Time for the last LFSCK completed in seconds since epoch. */
243 __u64 ll_time_last_complete;
245 /* Time for the latest LFSCK ran in seconds since epoch. */
246 __u64 ll_time_latest_start;
248 /* Time for the last LFSCK checkpoint in seconds since epoch. */
249 __u64 ll_time_last_checkpoint;
251 /* Position for the latest LFSCK started from. */
252 __u64 ll_pos_latest_start;
254 /* Position for the last LFSCK checkpoint. */
255 __u64 ll_pos_last_checkpoint;
257 /* Position for the first object to be fixed or
258 * failed to be checked in the phase1. */
259 __u64 ll_pos_first_inconsistent;
261 /* How many objects have been checked. */
262 __u64 ll_objs_checked_phase1;
264 /* How many objects failed to be processed. */
265 __u64 ll_objs_failed_phase1;
267 /* How many objects have been double scanned. */
268 __u64 ll_objs_checked_phase2;
270 /* How many objects failed to be processed during double scan. */
271 __u64 ll_objs_failed_phase2;
273 /* kinds of inconsistency have been or to be repaired.
274 * ll_objs_repaired[type - 1] is the count for the given @type. */
275 __u64 ll_objs_repaired[LLIT_MAX];
277 /* How many objects have been skipped because of related
278 * MDT(s)/OST(s) do not participate in the LFSCK */
279 __u64 ll_objs_skipped;
281 /* The size of ll_ost_bitmap with nbits. */
282 __u32 ll_bitmap_size;
284 /* For further using. 256-bytes aligned now. */
286 __u64 ll_reserved_2[11];
288 /* The OST targets bitmap to record the OSTs that contain
289 * non-verified OST-objects. */
290 __u8 ll_ost_bitmap[0];
293 struct lfsck_component;
294 struct lfsck_tgt_descs;
295 struct lfsck_tgt_desc;
297 struct lfsck_operations {
298 int (*lfsck_reset)(const struct lu_env *env,
299 struct lfsck_component *com,
302 void (*lfsck_fail)(const struct lu_env *env,
303 struct lfsck_component *com,
306 int (*lfsck_checkpoint)(const struct lu_env *env,
307 struct lfsck_component *com,
310 int (*lfsck_prep)(const struct lu_env *env,
311 struct lfsck_component *com,
312 struct lfsck_start_param *lsp);
314 int (*lfsck_exec_oit)(const struct lu_env *env,
315 struct lfsck_component *com,
316 struct dt_object *obj);
318 int (*lfsck_exec_dir)(const struct lu_env *env,
319 struct lfsck_component *com,
320 struct lu_dirent *ent,
323 int (*lfsck_post)(const struct lu_env *env,
324 struct lfsck_component *com,
328 int (*lfsck_dump)(const struct lu_env *env,
329 struct lfsck_component *com,
332 int (*lfsck_double_scan)(const struct lu_env *env,
333 struct lfsck_component *com);
335 void (*lfsck_data_release)(const struct lu_env *env,
336 struct lfsck_component *com);
338 void (*lfsck_quit)(const struct lu_env *env,
339 struct lfsck_component *com);
341 int (*lfsck_in_notify)(const struct lu_env *env,
342 struct lfsck_component *com,
343 struct lfsck_request *lr);
345 int (*lfsck_query)(const struct lu_env *env,
346 struct lfsck_component *com);
348 int (*lfsck_join)(const struct lu_env *env,
349 struct lfsck_component *com,
350 struct lfsck_start_param *lsp);
353 #define TGT_PTRS 256 /* number of pointers at 1st level */
354 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
356 struct lfsck_tgt_desc {
357 struct list_head ltd_orphan_list;
358 struct dt_device *ltd_tgt;
359 struct dt_device *ltd_key;
360 struct obd_export *ltd_exp;
361 struct list_head ltd_layout_list;
362 struct list_head ltd_layout_phase_list;
363 struct list_head ltd_namespace_list;
364 struct list_head ltd_namespace_phase_list;
367 __u32 ltd_layout_gen;
368 __u32 ltd_namespace_gen;
369 unsigned int ltd_dead:1,
371 ltd_namespace_done:1;
374 struct lfsck_tgt_desc_idx {
375 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
378 struct lfsck_tgt_descs {
379 /* list of known TGTs */
380 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
382 /* bitmap of TGTs available */
383 cfs_bitmap_t *ltd_tgts_bitmap;
385 /* for lfsck_tgt_desc::ltd_xxx_list */
388 /* for tgts table accessing and changes */
389 struct rw_semaphore ltd_rw_sem;
391 /* Temporary list for orphan targets. */
392 struct list_head ltd_orphan;
394 /* number of registered TGTs */
398 #define LTD_TGT(ltd, index) \
399 ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
400 ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
402 #define OST_TGT(lfsck, index) LTD_TGT(&lfsck->li_ost_descs, index)
403 #define MDT_TGT(lfsck, index) LTD_TGT(&lfsck->li_mdt_descs, index)
405 struct lfsck_component {
406 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
407 struct list_head lc_link;
409 /* into lfsck_instance::li_list_dir */
410 struct list_head lc_link_dir;
412 struct rw_semaphore lc_sem;
415 struct lfsck_position lc_pos_start;
416 struct lfsck_instance *lc_lfsck;
417 struct dt_object *lc_obj;
418 struct lfsck_operations *lc_ops;
422 struct lu_fid lc_fid_latest_scanned_phase2;
424 /* The time for last checkpoint, jiffies */
425 cfs_time_t lc_time_last_checkpoint;
427 /* The time for next checkpoint, jiffies */
428 cfs_time_t lc_time_next_checkpoint;
432 /* How many objects have been checked since last checkpoint. */
433 __u32 lc_new_checked;
435 /* How many objects have been scanned since last sleep. */
436 __u32 lc_new_scanned;
441 struct lfsck_instance {
442 struct mutex li_mutex;
445 /* Link into the lfsck_instance_list. */
446 struct list_head li_link;
448 /* For the components in (first) scanning via otable-based iteration. */
449 struct list_head li_list_scan;
451 /* For the components in scanning via directory traversal. Because
452 * directory traversal cannot guarantee all the object be scanned,
453 * so the component in the li_list_dir must be in li_list_scan. */
454 struct list_head li_list_dir;
456 /* For the components in double scanning. */
457 struct list_head li_list_double_scan;
459 /* For the components those are not scanning now. */
460 struct list_head li_list_idle;
463 atomic_t li_double_scan_count;
464 struct ptlrpc_thread li_thread;
466 /* The time for last checkpoint, jiffies */
467 cfs_time_t li_time_last_checkpoint;
469 /* The time for next checkpoint, jiffies */
470 cfs_time_t li_time_next_checkpoint;
472 lfsck_out_notify li_out_notify;
473 void *li_out_notify_data;
474 struct dt_device *li_next;
475 struct dt_device *li_bottom;
476 struct obd_device *li_obd;
477 struct ldlm_namespace *li_namespace;
478 struct local_oid_storage *li_los;
479 struct lu_fid li_local_root_fid; /* backend root "/" */
480 struct lu_fid li_global_root_fid; /* /ROOT */
481 struct dt_object *li_bookmark_obj;
482 struct dt_object *li_lpf_obj;
483 struct lu_client_seq *li_seq;
484 struct lfsck_bookmark li_bookmark_ram;
485 struct lfsck_bookmark li_bookmark_disk;
486 struct lfsck_position li_pos_current;
487 struct lfsck_position li_pos_checkpoint;
489 /* Obj for otable-based iteration */
490 struct dt_object *li_obj_oit;
492 /* Obj for directory traversal */
493 struct dt_object *li_obj_dir;
495 /* It for otable-based iteration */
496 struct dt_it *li_di_oit;
498 /* It for directory traversal */
499 struct dt_it *li_di_dir;
501 /* Description of OST */
502 struct lfsck_tgt_descs li_ost_descs;
504 /* Description of MDT */
505 struct lfsck_tgt_descs li_mdt_descs;
507 /* namespace-based directory traversal position. */
510 /* Arguments for low layer otable-based iteration. */
513 /* Arugments for namespace-based directory traversal. */
516 /* Schedule for every N objects. */
519 /* Sleep N jiffies for each schedule. */
522 /* How many objects have been scanned since last sleep. */
523 __u32 li_new_scanned;
525 /* The status when the LFSCK stopped or paused. */
528 /* The flags when the lFSCK stopped or paused. */
531 unsigned int li_oit_over:1, /* oit is finished. */
532 li_drop_dryrun:1, /* Ever dryrun, not now. */
533 li_master:1, /* Master instance or not. */
534 li_current_oit_processed:1,
538 struct lfsck_async_interpret_args {
539 struct lfsck_component *laia_com;
540 struct lfsck_tgt_descs *laia_ltds;
541 struct lfsck_tgt_desc *laia_ltd;
542 struct lfsck_request *laia_lr;
543 atomic_t *laia_count;
545 unsigned int laia_shared:1;
548 struct lfsck_thread_args {
549 struct lu_env lta_env;
550 struct lfsck_instance *lta_lfsck;
551 struct lfsck_component *lta_com;
552 struct lfsck_start_param *lta_lsp;
555 struct lfsck_assistant_req {
556 struct list_head lar_list;
559 struct lfsck_assistant_operations {
560 int (*la_handler_p1)(const struct lu_env *env,
561 struct lfsck_component *com,
562 struct lfsck_assistant_req *lar);
564 int (*la_handler_p2)(const struct lu_env *env,
565 struct lfsck_component *com);
567 void (*la_fill_pos)(const struct lu_env *env,
568 struct lfsck_component *com,
569 struct lfsck_position *pos);
571 int (*la_double_scan_result)(const struct lu_env *env,
572 struct lfsck_component *com,
575 void (*la_req_fini)(const struct lu_env *env,
576 struct lfsck_assistant_req *lar);
578 void (*la_sync_failures)(const struct lu_env *env,
579 struct lfsck_component *com,
580 struct lfsck_request *lr);
583 struct lfsck_assistant_data {
585 struct list_head lad_req_list;
587 /* list for the ost targets involve LFSCK. */
588 struct list_head lad_ost_list;
590 /* list for the ost targets in phase1 scanning. */
591 struct list_head lad_ost_phase1_list;
593 /* list for the ost targets in phase1 scanning. */
594 struct list_head lad_ost_phase2_list;
596 /* list for the mdt targets involve LFSCK. */
597 struct list_head lad_mdt_list;
599 /* list for the mdt targets in phase1 scanning. */
600 struct list_head lad_mdt_phase1_list;
602 /* list for the mdt targets in phase1 scanning. */
603 struct list_head lad_mdt_phase2_list;
605 const char *lad_name;
606 struct ptlrpc_thread lad_thread;
608 struct lfsck_assistant_operations *lad_ops;
610 cfs_bitmap_t *lad_bitmap;
614 int lad_assistant_status;
616 unsigned int lad_to_post:1,
617 lad_to_double_scan:1,
618 lad_in_double_scan:1,
623 #define LFSCK_TMPBUF_LEN 64
625 struct lfsck_thread_info {
626 struct lu_name lti_name_const;
627 struct lu_name lti_name;
628 struct lu_buf lti_buf;
629 struct lu_buf lti_linkea_buf;
630 struct lu_buf lti_linkea_buf2;
631 struct lu_buf lti_big_buf;
632 struct lu_fid lti_fid;
633 struct lu_fid lti_fid2;
634 struct lu_fid lti_fid3;
635 struct lu_fid lti_fid4;
636 struct lu_attr lti_la;
637 struct lu_attr lti_la2;
638 struct lu_attr lti_la3;
639 struct ost_id lti_oi;
641 struct lustre_mdt_attrs lti_lma;
642 /* old LMA for compatibility */
643 char lti_lma_old[LMA_OLD_SIZE];
645 struct dt_object_format lti_dof;
646 /* There will be '\0' at the end of the name. */
647 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
648 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
649 struct lfsck_request lti_lr;
650 struct lfsck_async_interpret_args lti_laia;
651 struct lfsck_async_interpret_args lti_laia2;
652 struct lfsck_start lti_start;
653 struct lfsck_stop lti_stop;
654 ldlm_policy_data_t lti_policy;
655 struct ldlm_res_id lti_resid;
657 struct filter_fid_old lti_old_pfid;
658 struct filter_fid lti_new_pfid;
660 struct dt_allocation_hint lti_hint;
661 struct lu_orphan_rec lti_rec;
662 struct lov_user_md lti_lum;
663 struct dt_insert_rec lti_dt_rec;
664 struct lu_object_conf lti_conf;
665 struct lu_seq_range lti_range;
669 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
670 struct lu_fid *fid, bool locked);
671 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
672 struct dt_object *obj, struct lustre_handle *lh,
673 __u64 bits, ldlm_mode_t mode);
674 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
675 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
676 struct lfsck_instance *lfsck,
677 const struct lu_fid *fid);
678 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
679 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
680 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
682 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
684 const char *lfsck_status2names(enum lfsck_status status);
685 void lfsck_component_cleanup(const struct lu_env *env,
686 struct lfsck_component *com);
687 void lfsck_instance_cleanup(const struct lu_env *env,
688 struct lfsck_instance *lfsck);
689 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
691 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
692 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
694 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
695 struct lfsck_position *pos, bool init);
696 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
697 void lfsck_control_speed(struct lfsck_instance *lfsck);
698 void lfsck_control_speed_by_self(struct lfsck_component *com);
699 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
700 struct lfsck_assistant_data *
701 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
703 int lfsck_async_interpret_common(const struct lu_env *env,
704 struct ptlrpc_request *req,
706 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
707 struct lfsck_request *lr,
708 struct ptlrpc_request_set *set,
709 ptlrpc_interpterer_t interpterer,
710 void *args, int request);
711 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
712 struct lfsck_start_param *lsp);
713 int lfsck_checkpoint_generic(const struct lu_env *env,
714 struct lfsck_component *com);
715 void lfsck_post_generic(const struct lu_env *env,
716 struct lfsck_component *com, int *result);
717 int lfsck_double_scan_generic(const struct lu_env *env,
718 struct lfsck_component *com, int status);
719 void lfsck_quit_generic(const struct lu_env *env,
720 struct lfsck_component *com);
723 int lfsck_master_engine(void *args);
724 int lfsck_assistant_engine(void *args);
726 /* lfsck_bookmark.c */
727 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
728 struct lfsck_bookmark *src);
729 int lfsck_bookmark_store(const struct lu_env *env,
730 struct lfsck_instance *lfsck);
731 int lfsck_bookmark_setup(const struct lu_env *env,
732 struct lfsck_instance *lfsck);
733 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
734 struct lfsck_start *start, bool reset);
736 /* lfsck_namespace.c */
737 int lfsck_namespace_trace_update(const struct lu_env *env,
738 struct lfsck_component *com,
739 const struct lu_fid *fid,
740 const __u8 flags, bool add);
741 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
742 struct linkea_data *ldata);
743 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
744 struct lfsck_component *com,
745 struct dt_object *obj,
746 struct linkea_data *ldata);
747 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
748 struct dt_object *obj, const struct lu_name *cname,
749 const struct lu_fid *pfid);
750 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
751 char *name, struct lu_fid *pfid);
752 int lfsck_remove_name_entry(const struct lu_env *env,
753 struct lfsck_instance *lfsck,
754 struct dt_object *parent,
755 const char *name, __u32 type);
756 int lfsck_update_name_entry(const struct lu_env *env,
757 struct lfsck_instance *lfsck,
758 struct dt_object *parent, const char *name,
759 const struct lu_fid *pfid, __u32 type);
760 int lfsck_namespace_setup(const struct lu_env *env,
761 struct lfsck_instance *lfsck);
764 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
766 extern const char dot[];
767 extern const char dotdot[];
768 extern const char *lfsck_flags_names[];
769 extern const char *lfsck_param_names[];
770 extern struct lu_context_key lfsck_thread_key;
772 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
774 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
777 static inline struct lfsck_thread_info *
778 lfsck_env_info(const struct lu_env *env)
780 struct lfsck_thread_info *info;
782 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
783 LASSERT(info != NULL);
787 static inline const struct lu_name *
788 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
790 struct lu_name *lname;
792 lname = &lfsck_env_info(env)->lti_name_const;
793 lname->ln_name = area;
794 lname->ln_namelen = len;
799 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
805 static inline struct lu_buf *
806 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
810 buf = &lfsck_env_info(env)->lti_buf;
816 static inline const struct lu_buf *
817 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
821 buf = &lfsck_env_info(env)->lti_buf;
822 buf->lb_buf = (void *)area;
827 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
829 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
832 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
834 return lu_object_fid(&obj->do_lu);
837 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
839 memset(pos, 0, sizeof(*pos));
842 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
844 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
847 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
848 const struct lfsck_position *pos2)
850 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
853 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
856 if (fid_is_zero(&pos1->lp_dir_parent) &&
857 !fid_is_zero(&pos2->lp_dir_parent))
860 if (!fid_is_zero(&pos1->lp_dir_parent) &&
861 fid_is_zero(&pos2->lp_dir_parent))
864 if (fid_is_zero(&pos1->lp_dir_parent) &&
865 fid_is_zero(&pos2->lp_dir_parent))
868 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
870 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
873 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
879 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
880 struct lfsck_position *src)
882 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
883 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
884 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
887 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
888 struct lfsck_position *src)
890 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
891 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
892 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
895 static inline umode_t lfsck_object_type(const struct dt_object *obj)
897 return lu_object_attr(&obj->do_lu);
900 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
902 struct lu_object_header *loh = obj->do_lu.lo_header;
904 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
907 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
909 lu_object_get(&obj->do_lu);
913 static inline void lfsck_object_put(const struct lu_env *env,
914 struct dt_object *obj)
916 lu_object_put(env, &obj->do_lu);
919 static inline u32 lfsck_dev_idx(struct dt_device *dev)
921 return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
924 static inline struct dt_object *
925 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
926 const struct lu_fid *fid)
928 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
929 struct dt_object *obj;
931 conf->loc_flags = LOC_F_NOWAIT;
932 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
933 if (unlikely(obj == NULL))
934 return ERR_PTR(-ENOENT);
939 static inline struct dt_object *
940 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
941 const struct lu_fid *fid)
943 struct dt_object *obj;
945 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
946 if (unlikely(obj == NULL))
947 return ERR_PTR(-ENOENT);
952 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
953 struct lfsck_instance *lfsck,
954 const struct lu_fid *fid)
956 return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
959 static inline struct dt_object *
960 lfsck_object_find_bottom(const struct lu_env *env, struct lfsck_instance *lfsck,
961 const struct lu_fid *fid)
963 struct dt_device *dev;
966 idx = lfsck_find_mdt_idx_by_fid(env, lfsck, fid);
970 if (idx == lfsck_dev_idx(lfsck->li_bottom)) {
971 dev = lfsck->li_bottom;
973 struct lfsck_tgt_desc *ltd;
975 ltd = LTD_TGT(&lfsck->li_mdt_descs, idx);
976 if (unlikely(ltd == NULL))
977 return ERR_PTR(-ENODEV);
982 return lfsck_object_find_by_dev(env, dev, fid);
985 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
988 struct lfsck_tgt_desc *ltd;
990 ltd = LTD_TGT(ltds, index);
992 atomic_inc(<d->ltd_ref);
997 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
999 if (atomic_dec_and_test(<d->ltd_ref))
1003 static inline struct lfsck_component *
1004 lfsck_component_get(struct lfsck_component *com)
1006 atomic_inc(&com->lc_ref);
1011 static inline void lfsck_component_put(const struct lu_env *env,
1012 struct lfsck_component *com)
1014 if (atomic_dec_and_test(&com->lc_ref)) {
1015 if (com->lc_obj != NULL)
1016 lu_object_put_nocache(env, &com->lc_obj->do_lu);
1017 if (com->lc_file_ram != NULL)
1018 OBD_FREE(com->lc_file_ram, com->lc_file_size);
1019 if (com->lc_file_disk != NULL)
1020 OBD_FREE(com->lc_file_disk, com->lc_file_size);
1021 if (com->lc_data != NULL) {
1022 LASSERT(com->lc_ops->lfsck_data_release != NULL);
1024 com->lc_ops->lfsck_data_release(env, com);
1031 static inline struct lfsck_instance *
1032 lfsck_instance_get(struct lfsck_instance *lfsck)
1034 atomic_inc(&lfsck->li_ref);
1039 static inline void lfsck_instance_put(const struct lu_env *env,
1040 struct lfsck_instance *lfsck)
1042 if (atomic_dec_and_test(&lfsck->li_ref))
1043 lfsck_instance_cleanup(env, lfsck);
1046 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1048 return list_empty(&lad->lad_mdt_phase1_list) &&
1049 (!list_empty(&lad->lad_ost_phase2_list) ||
1050 list_empty(&lad->lad_ost_phase1_list));
1053 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1054 struct lfsck_component *com,
1057 struct lfsck_assistant_data *lad = com->lc_data;
1058 cfs_bitmap_t *bitmap = lad->lad_bitmap;
1060 LASSERT(com->lc_lfsck->li_master);
1061 LASSERT(bitmap != NULL);
1062 LASSERTF(bitmap->size > index, "invalid index: nbits %d, index %u\n",
1063 bitmap->size, index);
1065 cfs_bitmap_set(bitmap, index);
1066 lad->lad_incomplete = 1;
1069 static inline int lfsck_links_read(const struct lu_env *env,
1070 struct dt_object *obj,
1071 struct linkea_data *ldata)
1074 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1077 return __lfsck_links_read(env, obj, ldata);
1080 static inline int lfsck_links_read2(const struct lu_env *env,
1081 struct dt_object *obj,
1082 struct linkea_data *ldata)
1085 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1088 return __lfsck_links_read(env, obj, ldata);
1091 #endif /* _LFSCK_INTERNAL_H */