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 struct lfsck_namespace {
118 /* Magic number to detect that this struct contains valid data. */
121 /* See 'enum lfsck_status'. */
124 /* See 'enum lfsck_flags'. */
127 /* How many completed LFSCK runs on the device. */
128 __u32 ln_success_count;
130 /* How long the LFSCK phase1 has run in seconds. */
131 __u32 ln_run_time_phase1;
133 /* How long the LFSCK phase2 has run in seconds. */
134 __u32 ln_run_time_phase2;
136 /* Time for the last LFSCK completed in seconds since epoch. */
137 __u64 ln_time_last_complete;
139 /* Time for the latest LFSCK ran in seconds since epoch. */
140 __u64 ln_time_latest_start;
142 /* Time for the last LFSCK checkpoint in seconds since epoch. */
143 __u64 ln_time_last_checkpoint;
145 /* Position for the latest LFSCK started from. */
146 struct lfsck_position ln_pos_latest_start;
148 /* Position for the last LFSCK checkpoint. */
149 struct lfsck_position ln_pos_last_checkpoint;
151 /* Position for the first should be updated object. */
152 struct lfsck_position ln_pos_first_inconsistent;
154 /* How many items (including dir) have been checked. */
155 __u64 ln_items_checked;
157 /* How many items have been repaired. */
158 __u64 ln_items_repaired;
160 /* How many items failed to be processed. */
161 __u64 ln_items_failed;
163 /* How many directories have been traversed. */
164 __u64 ln_dirs_checked;
166 /* How many objects have been double scanned. */
167 __u64 ln_objs_checked_phase2;
169 /* How many objects have been reparied during double scan. */
170 __u64 ln_objs_repaired_phase2;
172 /* How many objects failed to be processed during double scan. */
173 __u64 ln_objs_failed_phase2;
175 /* How many objects with nlink fixed. */
176 __u64 ln_objs_nlink_repaired;
178 /* How many objects were lost before, but found back now. */
179 __u64 ln_objs_lost_found;
181 /* The latest object has been processed (failed) during double scan. */
182 struct lu_fid ln_fid_latest_scanned_phase2;
184 /* How many FID-in-dirent entries have been repaired. */
185 __u64 ln_dirent_repaired;
187 /* How many linkEA entries have been repaired. */
188 __u64 ln_linkea_repaired;
190 /* How many multiple-linked objects have been checked. */
191 __u64 ln_mul_linked_checked;
193 /* How many multiple-linked objects have been repaired. */
194 __u64 ln_mul_linked_repaired;
196 /* For further using. 256-bytes aligned now. */
197 __u64 ln_reserved[31];
200 enum lfsck_layout_inconsistency_type {
203 LLIT_UNMATCHED_PAIR = 2,
204 LLIT_MULTIPLE_REFERENCED = 3,
206 LLIT_INCONSISTENT_OWNER = 5,
208 LLIT_MAX = LLIT_OTHERS
211 struct lfsck_layout {
212 /* Magic number to detect that this struct contains valid data. */
215 /* See 'enum lfsck_status'. */
218 /* See 'enum lfsck_flags'. */
221 /* How many completed LFSCK runs on the device. */
222 __u32 ll_success_count;
224 /* How long the LFSCK phase1 has run in seconds. */
225 __u32 ll_run_time_phase1;
227 /* How long the LFSCK phase2 has run in seconds. */
228 __u32 ll_run_time_phase2;
230 /* Time for the last LFSCK completed in seconds since epoch. */
231 __u64 ll_time_last_complete;
233 /* Time for the latest LFSCK ran in seconds since epoch. */
234 __u64 ll_time_latest_start;
236 /* Time for the last LFSCK checkpoint in seconds since epoch. */
237 __u64 ll_time_last_checkpoint;
239 /* Position for the latest LFSCK started from. */
240 __u64 ll_pos_latest_start;
242 /* Position for the last LFSCK checkpoint. */
243 __u64 ll_pos_last_checkpoint;
245 /* Position for the first object to be fixed or
246 * failed to be checked in the phase1. */
247 __u64 ll_pos_first_inconsistent;
249 /* How many objects have been checked. */
250 __u64 ll_objs_checked_phase1;
252 /* How many objects failed to be processed. */
253 __u64 ll_objs_failed_phase1;
255 /* How many objects have been double scanned. */
256 __u64 ll_objs_checked_phase2;
258 /* How many objects failed to be processed during double scan. */
259 __u64 ll_objs_failed_phase2;
261 /* kinds of inconsistency have been or to be repaired.
262 * ll_objs_repaired[type - 1] is the count for the given @type. */
263 __u64 ll_objs_repaired[LLIT_MAX];
265 /* How many objects have been skipped because of related
266 * MDT(s)/OST(s) do not participate in the LFSCK */
267 __u64 ll_objs_skipped;
269 /* The size of ll_ost_bitmap with nbits. */
270 __u32 ll_bitmap_size;
272 /* For further using. 256-bytes aligned now. */
274 __u64 ll_reserved_2[11];
276 /* The OST targets bitmap to record the OSTs that contain
277 * non-verified OST-objects. */
278 __u8 ll_ost_bitmap[0];
281 struct lfsck_component;
282 struct lfsck_tgt_descs;
283 struct lfsck_tgt_desc;
285 struct lfsck_operations {
286 int (*lfsck_reset)(const struct lu_env *env,
287 struct lfsck_component *com,
290 void (*lfsck_fail)(const struct lu_env *env,
291 struct lfsck_component *com,
294 int (*lfsck_checkpoint)(const struct lu_env *env,
295 struct lfsck_component *com,
298 int (*lfsck_prep)(const struct lu_env *env,
299 struct lfsck_component *com,
300 struct lfsck_start_param *lsp);
302 int (*lfsck_exec_oit)(const struct lu_env *env,
303 struct lfsck_component *com,
304 struct dt_object *obj);
306 int (*lfsck_exec_dir)(const struct lu_env *env,
307 struct lfsck_component *com,
308 struct lu_dirent *ent,
311 int (*lfsck_post)(const struct lu_env *env,
312 struct lfsck_component *com,
316 int (*lfsck_dump)(const struct lu_env *env,
317 struct lfsck_component *com,
320 int (*lfsck_double_scan)(const struct lu_env *env,
321 struct lfsck_component *com);
323 void (*lfsck_data_release)(const struct lu_env *env,
324 struct lfsck_component *com);
326 void (*lfsck_quit)(const struct lu_env *env,
327 struct lfsck_component *com);
329 int (*lfsck_in_notify)(const struct lu_env *env,
330 struct lfsck_component *com,
331 struct lfsck_request *lr);
333 int (*lfsck_query)(const struct lu_env *env,
334 struct lfsck_component *com);
336 int (*lfsck_join)(const struct lu_env *env,
337 struct lfsck_component *com,
338 struct lfsck_start_param *lsp);
341 #define TGT_PTRS 256 /* number of pointers at 1st level */
342 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
344 struct lfsck_tgt_desc {
345 struct list_head ltd_orphan_list;
346 struct dt_device *ltd_tgt;
347 struct dt_device *ltd_key;
348 struct obd_export *ltd_exp;
349 struct list_head ltd_layout_list;
350 struct list_head ltd_layout_phase_list;
351 struct list_head ltd_namespace_list;
352 struct list_head ltd_namespace_phase_list;
355 __u32 ltd_layout_gen;
356 __u32 ltd_namespace_gen;
357 unsigned int ltd_dead:1,
359 ltd_namespace_done:1;
362 struct lfsck_tgt_desc_idx {
363 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
366 struct lfsck_tgt_descs {
367 /* list of known TGTs */
368 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
370 /* bitmap of TGTs available */
371 cfs_bitmap_t *ltd_tgts_bitmap;
373 /* for lfsck_tgt_desc::ltd_xxx_list */
376 /* for tgts table accessing and changes */
377 struct rw_semaphore ltd_rw_sem;
379 /* Temporary list for orphan targets. */
380 struct list_head ltd_orphan;
382 /* number of registered TGTs */
386 #define LTD_TGT(ltd, index) \
387 ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
388 ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
390 #define OST_TGT(lfsck, index) LTD_TGT(&lfsck->li_ost_descs, index)
391 #define MDT_TGT(lfsck, index) LTD_TGT(&lfsck->li_mdt_descs, index)
393 struct lfsck_component {
394 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
395 struct list_head lc_link;
397 /* into lfsck_instance::li_list_dir */
398 struct list_head lc_link_dir;
400 struct rw_semaphore lc_sem;
403 struct lfsck_position lc_pos_start;
404 struct lfsck_instance *lc_lfsck;
405 struct dt_object *lc_obj;
406 struct lfsck_operations *lc_ops;
410 struct lu_fid lc_fid_latest_scanned_phase2;
412 /* The time for last checkpoint, jiffies */
413 cfs_time_t lc_time_last_checkpoint;
415 /* The time for next checkpoint, jiffies */
416 cfs_time_t lc_time_next_checkpoint;
420 /* How many objects have been checked since last checkpoint. */
421 __u32 lc_new_checked;
423 /* How many objects have been scanned since last sleep. */
424 __u32 lc_new_scanned;
429 struct lfsck_instance {
430 struct mutex li_mutex;
433 /* Link into the lfsck_instance_list. */
434 struct list_head li_link;
436 /* For the components in (first) scanning via otable-based iteration. */
437 struct list_head li_list_scan;
439 /* For the components in scanning via directory traversal. Because
440 * directory traversal cannot guarantee all the object be scanned,
441 * so the component in the li_list_dir must be in li_list_scan. */
442 struct list_head li_list_dir;
444 /* For the components in double scanning. */
445 struct list_head li_list_double_scan;
447 /* For the components those are not scanning now. */
448 struct list_head li_list_idle;
451 atomic_t li_double_scan_count;
452 struct ptlrpc_thread li_thread;
454 /* The time for last checkpoint, jiffies */
455 cfs_time_t li_time_last_checkpoint;
457 /* The time for next checkpoint, jiffies */
458 cfs_time_t li_time_next_checkpoint;
460 lfsck_out_notify li_out_notify;
461 void *li_out_notify_data;
462 struct dt_device *li_next;
463 struct dt_device *li_bottom;
464 struct obd_device *li_obd;
465 struct ldlm_namespace *li_namespace;
466 struct local_oid_storage *li_los;
467 struct lu_fid li_local_root_fid; /* backend root "/" */
468 struct lu_fid li_global_root_fid; /* /ROOT */
469 struct dt_object *li_bookmark_obj;
470 struct dt_object *li_lpf_obj;
471 struct lu_client_seq *li_seq;
472 struct lfsck_bookmark li_bookmark_ram;
473 struct lfsck_bookmark li_bookmark_disk;
474 struct lfsck_position li_pos_current;
475 struct lfsck_position li_pos_checkpoint;
477 /* Obj for otable-based iteration */
478 struct dt_object *li_obj_oit;
480 /* Obj for directory traversal */
481 struct dt_object *li_obj_dir;
483 /* It for otable-based iteration */
484 struct dt_it *li_di_oit;
486 /* It for directory traversal */
487 struct dt_it *li_di_dir;
489 /* Description of OST */
490 struct lfsck_tgt_descs li_ost_descs;
492 /* Description of MDT */
493 struct lfsck_tgt_descs li_mdt_descs;
495 /* namespace-based directory traversal position. */
498 /* Arguments for low layer otable-based iteration. */
501 /* Arugments for namespace-based directory traversal. */
504 /* Schedule for every N objects. */
507 /* Sleep N jiffies for each schedule. */
510 /* How many objects have been scanned since last sleep. */
511 __u32 li_new_scanned;
513 /* The status when the LFSCK stopped or paused. */
516 /* The flags when the lFSCK stopped or paused. */
519 unsigned int li_oit_over:1, /* oit is finished. */
520 li_drop_dryrun:1, /* Ever dryrun, not now. */
521 li_master:1, /* Master instance or not. */
522 li_current_oit_processed:1,
526 struct lfsck_async_interpret_args {
527 struct lfsck_component *laia_com;
528 struct lfsck_tgt_descs *laia_ltds;
529 struct lfsck_tgt_desc *laia_ltd;
530 struct lfsck_request *laia_lr;
531 atomic_t *laia_count;
533 unsigned int laia_shared:1;
536 struct lfsck_thread_args {
537 struct lu_env lta_env;
538 struct lfsck_instance *lta_lfsck;
539 struct lfsck_component *lta_com;
540 struct lfsck_start_param *lta_lsp;
543 struct lfsck_assistant_req {
544 struct list_head lar_list;
547 struct lfsck_assistant_operations {
548 int (*la_handler_p1)(const struct lu_env *env,
549 struct lfsck_component *com,
550 struct lfsck_assistant_req *lar);
552 int (*la_handler_p2)(const struct lu_env *env,
553 struct lfsck_component *com);
555 void (*la_fill_pos)(const struct lu_env *env,
556 struct lfsck_component *com,
557 struct lfsck_position *pos);
559 int (*la_double_scan_result)(const struct lu_env *env,
560 struct lfsck_component *com,
563 void (*la_req_fini)(const struct lu_env *env,
564 struct lfsck_assistant_req *lar);
566 void (*la_sync_failures)(const struct lu_env *env,
567 struct lfsck_component *com,
568 struct lfsck_request *lr);
571 struct lfsck_assistant_data {
573 struct list_head lad_req_list;
575 /* list for the ost targets involve LFSCK. */
576 struct list_head lad_ost_list;
578 /* list for the ost targets in phase1 scanning. */
579 struct list_head lad_ost_phase1_list;
581 /* list for the ost targets in phase1 scanning. */
582 struct list_head lad_ost_phase2_list;
584 /* list for the mdt targets involve LFSCK. */
585 struct list_head lad_mdt_list;
587 /* list for the mdt targets in phase1 scanning. */
588 struct list_head lad_mdt_phase1_list;
590 /* list for the mdt targets in phase1 scanning. */
591 struct list_head lad_mdt_phase2_list;
593 const char *lad_name;
594 struct ptlrpc_thread lad_thread;
596 struct lfsck_assistant_operations *lad_ops;
598 cfs_bitmap_t *lad_bitmap;
602 int lad_assistant_status;
604 unsigned int lad_to_post:1,
605 lad_to_double_scan:1,
606 lad_in_double_scan:1,
611 #define LFSCK_TMPBUF_LEN 64
613 struct lfsck_thread_info {
614 struct lu_name lti_name_const;
615 struct lu_name lti_name;
616 struct lu_buf lti_buf;
617 struct lu_buf lti_linkea_buf;
618 struct lu_buf lti_linkea_buf2;
619 struct lu_buf lti_big_buf;
620 struct lu_fid lti_fid;
621 struct lu_fid lti_fid2;
622 struct lu_fid lti_fid3;
623 struct lu_attr lti_la;
624 struct lu_attr lti_la2;
625 struct lu_attr lti_la3;
626 struct ost_id lti_oi;
628 struct lustre_mdt_attrs lti_lma;
629 /* old LMA for compatibility */
630 char lti_lma_old[LMA_OLD_SIZE];
632 struct dt_object_format lti_dof;
633 /* There will be '\0' at the end of the name. */
634 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
635 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
636 struct lfsck_request lti_lr;
637 struct lfsck_async_interpret_args lti_laia;
638 struct lfsck_async_interpret_args lti_laia2;
639 struct lfsck_start lti_start;
640 struct lfsck_stop lti_stop;
641 ldlm_policy_data_t lti_policy;
642 struct ldlm_res_id lti_resid;
644 struct filter_fid_old lti_old_pfid;
645 struct filter_fid lti_new_pfid;
647 struct dt_allocation_hint lti_hint;
648 struct lu_orphan_rec lti_rec;
649 struct lov_user_md lti_lum;
650 struct dt_insert_rec lti_dt_rec;
651 struct lu_object_conf lti_conf;
652 struct lu_seq_range lti_range;
656 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
657 struct lu_fid *fid, bool locked);
658 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
659 struct dt_object *obj, struct lustre_handle *lh,
660 __u64 bits, ldlm_mode_t mode);
661 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
662 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
663 struct lfsck_instance *lfsck,
664 const struct lu_fid *fid);
665 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
666 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
667 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
669 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
671 const char *lfsck_status2names(enum lfsck_status status);
672 void lfsck_component_cleanup(const struct lu_env *env,
673 struct lfsck_component *com);
674 void lfsck_instance_cleanup(const struct lu_env *env,
675 struct lfsck_instance *lfsck);
676 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
678 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
679 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
681 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
682 struct lfsck_position *pos, bool init);
683 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
684 void lfsck_control_speed(struct lfsck_instance *lfsck);
685 void lfsck_control_speed_by_self(struct lfsck_component *com);
686 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
687 struct lfsck_assistant_data *
688 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
690 int lfsck_async_interpret_common(const struct lu_env *env,
691 struct ptlrpc_request *req,
693 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
694 struct lfsck_request *lr,
695 struct ptlrpc_request_set *set,
696 ptlrpc_interpterer_t interpterer,
697 void *args, int request);
698 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
699 struct lfsck_start_param *lsp);
700 int lfsck_checkpoint_generic(const struct lu_env *env,
701 struct lfsck_component *com);
702 void lfsck_post_generic(const struct lu_env *env,
703 struct lfsck_component *com, int *result);
704 int lfsck_double_scan_generic(const struct lu_env *env,
705 struct lfsck_component *com, int status);
706 void lfsck_quit_generic(const struct lu_env *env,
707 struct lfsck_component *com);
710 int lfsck_master_engine(void *args);
711 int lfsck_assistant_engine(void *args);
713 /* lfsck_bookmark.c */
714 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
715 struct lfsck_bookmark *src);
716 int lfsck_bookmark_store(const struct lu_env *env,
717 struct lfsck_instance *lfsck);
718 int lfsck_bookmark_setup(const struct lu_env *env,
719 struct lfsck_instance *lfsck);
720 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
721 struct lfsck_start *start, bool reset);
723 /* lfsck_namespace.c */
724 int lfsck_namespace_trace_update(const struct lu_env *env,
725 struct lfsck_component *com,
726 const struct lu_fid *fid,
727 const __u8 flags, bool add);
728 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
729 struct linkea_data *ldata);
730 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
731 struct dt_object *obj, const struct lu_name *cname,
732 const struct lu_fid *pfid);
733 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
734 char *name, struct lu_fid *pfid);
735 int lfsck_remove_name_entry(const struct lu_env *env,
736 struct lfsck_instance *lfsck,
737 struct dt_object *parent,
738 const char *name, __u32 type);
739 int lfsck_update_name_entry(const struct lu_env *env,
740 struct lfsck_instance *lfsck,
741 struct dt_object *parent, const char *name,
742 const struct lu_fid *pfid, __u32 type);
743 int lfsck_namespace_setup(const struct lu_env *env,
744 struct lfsck_instance *lfsck);
747 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
749 extern const char *lfsck_flags_names[];
750 extern const char *lfsck_param_names[];
751 extern struct lu_context_key lfsck_thread_key;
753 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
755 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
758 static inline struct lfsck_thread_info *
759 lfsck_env_info(const struct lu_env *env)
761 struct lfsck_thread_info *info;
763 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
764 LASSERT(info != NULL);
768 static inline const struct lu_name *
769 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
771 struct lu_name *lname;
773 lname = &lfsck_env_info(env)->lti_name_const;
774 lname->ln_name = area;
775 lname->ln_namelen = len;
780 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
786 static inline struct lu_buf *
787 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
791 buf = &lfsck_env_info(env)->lti_buf;
797 static inline const struct lu_buf *
798 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
802 buf = &lfsck_env_info(env)->lti_buf;
803 buf->lb_buf = (void *)area;
808 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
810 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
813 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
815 return lu_object_fid(&obj->do_lu);
818 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
820 memset(pos, 0, sizeof(*pos));
823 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
825 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
828 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
829 const struct lfsck_position *pos2)
831 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
834 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
837 if (fid_is_zero(&pos1->lp_dir_parent) &&
838 !fid_is_zero(&pos2->lp_dir_parent))
841 if (!fid_is_zero(&pos1->lp_dir_parent) &&
842 fid_is_zero(&pos2->lp_dir_parent))
845 if (fid_is_zero(&pos1->lp_dir_parent) &&
846 fid_is_zero(&pos2->lp_dir_parent))
849 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
851 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
854 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
860 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
861 struct lfsck_position *src)
863 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
864 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
865 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
868 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
869 struct lfsck_position *src)
871 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
872 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
873 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
876 static inline umode_t lfsck_object_type(const struct dt_object *obj)
878 return lu_object_attr(&obj->do_lu);
881 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
883 struct lu_object_header *loh = obj->do_lu.lo_header;
885 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
888 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
890 lu_object_get(&obj->do_lu);
894 static inline void lfsck_object_put(const struct lu_env *env,
895 struct dt_object *obj)
897 lu_object_put(env, &obj->do_lu);
900 static inline struct dt_object *
901 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
902 const struct lu_fid *fid)
904 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
905 struct dt_object *obj;
907 conf->loc_flags = LOC_F_NOWAIT;
908 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
909 if (unlikely(obj == NULL))
910 return ERR_PTR(-ENOENT);
915 static inline struct dt_object *
916 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
917 const struct lu_fid *fid)
919 struct dt_object *obj;
921 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
922 if (unlikely(obj == NULL))
923 return ERR_PTR(-ENOENT);
928 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
929 struct lfsck_instance *lfsck,
930 const struct lu_fid *fid)
932 return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
935 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
938 struct lfsck_tgt_desc *ltd;
940 ltd = LTD_TGT(ltds, index);
942 atomic_inc(<d->ltd_ref);
947 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
949 if (atomic_dec_and_test(<d->ltd_ref))
953 static inline struct lfsck_component *
954 lfsck_component_get(struct lfsck_component *com)
956 atomic_inc(&com->lc_ref);
961 static inline void lfsck_component_put(const struct lu_env *env,
962 struct lfsck_component *com)
964 if (atomic_dec_and_test(&com->lc_ref)) {
965 if (com->lc_obj != NULL)
966 lu_object_put_nocache(env, &com->lc_obj->do_lu);
967 if (com->lc_file_ram != NULL)
968 OBD_FREE(com->lc_file_ram, com->lc_file_size);
969 if (com->lc_file_disk != NULL)
970 OBD_FREE(com->lc_file_disk, com->lc_file_size);
971 if (com->lc_data != NULL) {
972 LASSERT(com->lc_ops->lfsck_data_release != NULL);
974 com->lc_ops->lfsck_data_release(env, com);
981 static inline struct lfsck_instance *
982 lfsck_instance_get(struct lfsck_instance *lfsck)
984 atomic_inc(&lfsck->li_ref);
989 static inline void lfsck_instance_put(const struct lu_env *env,
990 struct lfsck_instance *lfsck)
992 if (atomic_dec_and_test(&lfsck->li_ref))
993 lfsck_instance_cleanup(env, lfsck);
996 static inline u32 lfsck_dev_idx(struct dt_device *dev)
998 return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
1001 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
1003 return list_empty(&lad->lad_mdt_phase1_list) &&
1004 (!list_empty(&lad->lad_ost_phase2_list) ||
1005 list_empty(&lad->lad_ost_phase1_list));
1008 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
1009 struct lfsck_component *com,
1012 struct lfsck_assistant_data *lad = com->lc_data;
1013 cfs_bitmap_t *bitmap = lad->lad_bitmap;
1015 LASSERT(com->lc_lfsck->li_master);
1016 LASSERT(bitmap != NULL);
1017 LASSERTF(bitmap->size > index, "invalid index: nbits %d, index %u\n",
1018 bitmap->size, index);
1020 cfs_bitmap_set(bitmap, index);
1021 lad->lad_incomplete = 1;
1024 static inline int lfsck_links_read(const struct lu_env *env,
1025 struct dt_object *obj,
1026 struct linkea_data *ldata)
1029 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
1032 return __lfsck_links_read(env, obj, ldata);
1035 static inline int lfsck_links_read2(const struct lu_env *env,
1036 struct dt_object *obj,
1037 struct linkea_data *ldata)
1040 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf2,
1043 return __lfsck_links_read(env, obj, ldata);
1046 #endif /* _LFSCK_INTERNAL_H */