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 struct lfsck_namespace {
112 /* Magic number to detect that this struct contains valid data. */
115 /* See 'enum lfsck_status'. */
118 /* See 'enum lfsck_flags'. */
121 /* How many completed LFSCK runs on the device. */
122 __u32 ln_success_count;
124 /* How long the LFSCK phase1 has run in seconds. */
125 __u32 ln_run_time_phase1;
127 /* How long the LFSCK phase2 has run in seconds. */
128 __u32 ln_run_time_phase2;
130 /* Time for the last LFSCK completed in seconds since epoch. */
131 __u64 ln_time_last_complete;
133 /* Time for the latest LFSCK ran in seconds since epoch. */
134 __u64 ln_time_latest_start;
136 /* Time for the last LFSCK checkpoint in seconds since epoch. */
137 __u64 ln_time_last_checkpoint;
139 /* Position for the latest LFSCK started from. */
140 struct lfsck_position ln_pos_latest_start;
142 /* Position for the last LFSCK checkpoint. */
143 struct lfsck_position ln_pos_last_checkpoint;
145 /* Position for the first should be updated object. */
146 struct lfsck_position ln_pos_first_inconsistent;
148 /* How many items (including dir) have been checked. */
149 __u64 ln_items_checked;
151 /* How many items have been repaired. */
152 __u64 ln_items_repaired;
154 /* How many items failed to be processed. */
155 __u64 ln_items_failed;
157 /* How many directories have been traversed. */
158 __u64 ln_dirs_checked;
160 /* How many multiple-linked objects have been checked. */
161 __u64 ln_mlinked_checked;
163 /* How many objects have been double scanned. */
164 __u64 ln_objs_checked_phase2;
166 /* How many objects have been reparied during double scan. */
167 __u64 ln_objs_repaired_phase2;
169 /* How many objects failed to be processed during double scan. */
170 __u64 ln_objs_failed_phase2;
172 /* How many objects with nlink fixed. */
173 __u64 ln_objs_nlink_repaired;
175 /* How many objects were lost before, but found back now. */
176 __u64 ln_objs_lost_found;
178 /* The latest object has been processed (failed) during double scan. */
179 struct lu_fid ln_fid_latest_scanned_phase2;
181 /* How many FID-in-dirent entries have been repaired. */
182 __u64 ln_dirent_repaired;
184 /* How many linkEA entries have been repaired. */
185 __u64 ln_linkea_repaired;
188 enum lfsck_layout_inconsistency_type {
191 LLIT_UNMATCHED_PAIR = 2,
192 LLIT_MULTIPLE_REFERENCED = 3,
194 LLIT_INCONSISTENT_OWNER = 5,
196 LLIT_MAX = LLIT_OTHERS
199 struct lfsck_layout {
200 /* Magic number to detect that this struct contains valid data. */
203 /* See 'enum lfsck_status'. */
206 /* See 'enum lfsck_flags'. */
209 /* How many completed LFSCK runs on the device. */
210 __u32 ll_success_count;
212 /* How long the LFSCK phase1 has run in seconds. */
213 __u32 ll_run_time_phase1;
215 /* How long the LFSCK phase2 has run in seconds. */
216 __u32 ll_run_time_phase2;
218 /* Time for the last LFSCK completed in seconds since epoch. */
219 __u64 ll_time_last_complete;
221 /* Time for the latest LFSCK ran in seconds since epoch. */
222 __u64 ll_time_latest_start;
224 /* Time for the last LFSCK checkpoint in seconds since epoch. */
225 __u64 ll_time_last_checkpoint;
227 /* Position for the latest LFSCK started from. */
228 __u64 ll_pos_latest_start;
230 /* Position for the last LFSCK checkpoint. */
231 __u64 ll_pos_last_checkpoint;
233 /* Position for the first object to be fixed or
234 * failed to be checked in the phase1. */
235 __u64 ll_pos_first_inconsistent;
237 /* How many objects have been checked. */
238 __u64 ll_objs_checked_phase1;
240 /* How many objects failed to be processed. */
241 __u64 ll_objs_failed_phase1;
243 /* How many objects have been double scanned. */
244 __u64 ll_objs_checked_phase2;
246 /* How many objects failed to be processed during double scan. */
247 __u64 ll_objs_failed_phase2;
249 /* kinds of inconsistency have been or to be repaired.
250 * ll_objs_repaired[type - 1] is the count for the given @type. */
251 __u64 ll_objs_repaired[LLIT_MAX];
253 /* How many objects have been skipped because of related
254 * MDT(s)/OST(s) do not participate in the LFSCK */
255 __u64 ll_objs_skipped;
257 /* The size of ll_ost_bitmap with nbits. */
258 __u32 ll_bitmap_size;
260 /* For further using. 256-bytes aligned now. */
262 __u64 ll_reserved_2[11];
264 /* The OST targets bitmap to record the OSTs that contain
265 * non-verified OST-objects. */
266 __u8 ll_ost_bitmap[0];
269 struct lfsck_component;
270 struct lfsck_tgt_descs;
271 struct lfsck_tgt_desc;
273 struct lfsck_operations {
274 int (*lfsck_reset)(const struct lu_env *env,
275 struct lfsck_component *com,
278 void (*lfsck_fail)(const struct lu_env *env,
279 struct lfsck_component *com,
282 int (*lfsck_checkpoint)(const struct lu_env *env,
283 struct lfsck_component *com,
286 int (*lfsck_prep)(const struct lu_env *env,
287 struct lfsck_component *com,
288 struct lfsck_start_param *lsp);
290 int (*lfsck_exec_oit)(const struct lu_env *env,
291 struct lfsck_component *com,
292 struct dt_object *obj);
294 int (*lfsck_exec_dir)(const struct lu_env *env,
295 struct lfsck_component *com,
296 struct lu_dirent *ent,
299 int (*lfsck_post)(const struct lu_env *env,
300 struct lfsck_component *com,
304 int (*lfsck_dump)(const struct lu_env *env,
305 struct lfsck_component *com,
308 int (*lfsck_double_scan)(const struct lu_env *env,
309 struct lfsck_component *com);
311 void (*lfsck_data_release)(const struct lu_env *env,
312 struct lfsck_component *com);
314 void (*lfsck_quit)(const struct lu_env *env,
315 struct lfsck_component *com);
317 int (*lfsck_in_notify)(const struct lu_env *env,
318 struct lfsck_component *com,
319 struct lfsck_request *lr);
321 int (*lfsck_query)(const struct lu_env *env,
322 struct lfsck_component *com);
324 int (*lfsck_join)(const struct lu_env *env,
325 struct lfsck_component *com,
326 struct lfsck_start_param *lsp);
329 #define TGT_PTRS 256 /* number of pointers at 1st level */
330 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
332 struct lfsck_tgt_desc {
333 struct list_head ltd_orphan_list;
334 struct dt_device *ltd_tgt;
335 struct dt_device *ltd_key;
336 struct obd_export *ltd_exp;
337 struct list_head ltd_layout_list;
338 struct list_head ltd_layout_phase_list;
339 struct list_head ltd_namespace_list;
340 struct list_head ltd_namespace_phase_list;
343 __u32 ltd_layout_gen;
344 __u32 ltd_namespace_gen;
345 unsigned int ltd_dead:1,
347 ltd_namespace_done:1;
350 struct lfsck_tgt_desc_idx {
351 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
354 struct lfsck_tgt_descs {
355 /* list of known TGTs */
356 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
358 /* bitmap of TGTs available */
359 cfs_bitmap_t *ltd_tgts_bitmap;
361 /* for lfsck_tgt_desc::ltd_xxx_list */
364 /* for tgts table accessing and changes */
365 struct rw_semaphore ltd_rw_sem;
367 /* Temporary list for orphan targets. */
368 struct list_head ltd_orphan;
370 /* number of registered TGTs */
374 #define LTD_TGT(ltd, index) \
375 ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
376 ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
378 #define OST_TGT(lfsck, index) LTD_TGT(&lfsck->li_ost_descs, index)
379 #define MDT_TGT(lfsck, index) LTD_TGT(&lfsck->li_mdt_descs, index)
381 struct lfsck_component {
382 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
383 struct list_head lc_link;
385 /* into lfsck_instance::li_list_dir */
386 struct list_head lc_link_dir;
388 struct rw_semaphore lc_sem;
391 struct lfsck_position lc_pos_start;
392 struct lfsck_instance *lc_lfsck;
393 struct dt_object *lc_obj;
394 struct lfsck_operations *lc_ops;
398 struct lu_fid lc_fid_latest_scanned_phase2;
400 /* The time for last checkpoint, jiffies */
401 cfs_time_t lc_time_last_checkpoint;
403 /* The time for next checkpoint, jiffies */
404 cfs_time_t lc_time_next_checkpoint;
408 /* How many objects have been checked since last checkpoint. */
409 __u32 lc_new_checked;
411 /* How many objects have been scanned since last sleep. */
412 __u32 lc_new_scanned;
414 unsigned int lc_journal:1;
418 struct lfsck_instance {
419 struct mutex li_mutex;
422 /* Link into the lfsck_instance_list. */
423 struct list_head li_link;
425 /* For the components in (first) scanning via otable-based iteration. */
426 struct list_head li_list_scan;
428 /* For the components in scanning via directory traversal. Because
429 * directory traversal cannot guarantee all the object be scanned,
430 * so the component in the li_list_dir must be in li_list_scan. */
431 struct list_head li_list_dir;
433 /* For the components in double scanning. */
434 struct list_head li_list_double_scan;
436 /* For the components those are not scanning now. */
437 struct list_head li_list_idle;
440 atomic_t li_double_scan_count;
441 struct ptlrpc_thread li_thread;
443 /* The time for last checkpoint, jiffies */
444 cfs_time_t li_time_last_checkpoint;
446 /* The time for next checkpoint, jiffies */
447 cfs_time_t li_time_next_checkpoint;
449 lfsck_out_notify li_out_notify;
450 void *li_out_notify_data;
451 struct dt_device *li_next;
452 struct dt_device *li_bottom;
453 struct obd_device *li_obd;
454 struct ldlm_namespace *li_namespace;
455 struct local_oid_storage *li_los;
456 struct lu_fid li_local_root_fid; /* backend root "/" */
457 struct lu_fid li_global_root_fid; /* /ROOT */
458 struct dt_object *li_bookmark_obj;
459 struct dt_object *li_lpf_obj;
460 struct lu_client_seq *li_seq;
461 struct lfsck_bookmark li_bookmark_ram;
462 struct lfsck_bookmark li_bookmark_disk;
463 struct lfsck_position li_pos_current;
464 struct lfsck_position li_pos_checkpoint;
466 /* Obj for otable-based iteration */
467 struct dt_object *li_obj_oit;
469 /* Obj for directory traversal */
470 struct dt_object *li_obj_dir;
472 /* It for otable-based iteration */
473 struct dt_it *li_di_oit;
475 /* It for directory traversal */
476 struct dt_it *li_di_dir;
478 /* Description of OST */
479 struct lfsck_tgt_descs li_ost_descs;
481 /* Description of MDT */
482 struct lfsck_tgt_descs li_mdt_descs;
484 /* namespace-based directory traversal position. */
487 /* Arguments for low layer otable-based iteration. */
490 /* Arugments for namespace-based directory traversal. */
493 /* Schedule for every N objects. */
496 /* Sleep N jiffies for each schedule. */
499 /* How many objects have been scanned since last sleep. */
500 __u32 li_new_scanned;
502 /* The status when the LFSCK stopped or paused. */
505 /* The flags when the lFSCK stopped or paused. */
508 unsigned int li_oit_over:1, /* oit is finished. */
509 li_drop_dryrun:1, /* Ever dryrun, not now. */
510 li_master:1, /* Master instance or not. */
511 li_current_oit_processed:1,
515 enum lfsck_linkea_flags {
516 /* The linkea entries does not match the object nlinks. */
517 LLF_UNMATCH_NLINKS = 0x01,
519 /* Fail to repair the multiple-linked objects during the double scan. */
520 LLF_REPAIR_FAILED = 0x02,
523 struct lfsck_async_interpret_args {
524 struct lfsck_component *laia_com;
525 struct lfsck_tgt_descs *laia_ltds;
526 struct lfsck_tgt_desc *laia_ltd;
527 struct lfsck_request *laia_lr;
528 atomic_t *laia_count;
530 unsigned int laia_shared:1;
533 struct lfsck_thread_args {
534 struct lu_env lta_env;
535 struct lfsck_instance *lta_lfsck;
536 struct lfsck_component *lta_com;
537 struct lfsck_start_param *lta_lsp;
540 struct lfsck_assistant_req {
541 struct list_head lar_list;
544 struct lfsck_assistant_operations {
545 int (*la_handler_p1)(const struct lu_env *env,
546 struct lfsck_component *com,
547 struct lfsck_assistant_req *lar);
549 int (*la_handler_p2)(const struct lu_env *env,
550 struct lfsck_component *com);
552 void (*la_fill_pos)(const struct lu_env *env,
553 struct lfsck_component *com,
554 struct lfsck_position *pos);
556 int (*la_double_scan_result)(const struct lu_env *env,
557 struct lfsck_component *com,
560 void (*la_req_fini)(const struct lu_env *env,
561 struct lfsck_assistant_req *lar);
563 void (*la_sync_failures)(const struct lu_env *env,
564 struct lfsck_component *com,
565 struct lfsck_request *lr);
568 struct lfsck_assistant_data {
570 struct list_head lad_req_list;
572 /* list for the ost targets involve LFSCK. */
573 struct list_head lad_ost_list;
575 /* list for the ost targets in phase1 scanning. */
576 struct list_head lad_ost_phase1_list;
578 /* list for the ost targets in phase1 scanning. */
579 struct list_head lad_ost_phase2_list;
581 /* list for the mdt targets involve LFSCK. */
582 struct list_head lad_mdt_list;
584 /* list for the mdt targets in phase1 scanning. */
585 struct list_head lad_mdt_phase1_list;
587 /* list for the mdt targets in phase1 scanning. */
588 struct list_head lad_mdt_phase2_list;
590 const char *lad_name;
591 struct ptlrpc_thread lad_thread;
593 struct lfsck_assistant_operations *lad_ops;
595 cfs_bitmap_t *lad_bitmap;
599 int lad_assistant_status;
601 unsigned int lad_to_post:1,
602 lad_to_double_scan:1,
603 lad_in_double_scan:1,
608 #define LFSCK_TMPBUF_LEN 64
610 struct lfsck_thread_info {
611 struct lu_name lti_name;
612 struct lu_buf lti_buf;
613 struct lu_buf lti_linkea_buf;
614 struct lu_buf lti_big_buf;
615 struct lu_fid lti_fid;
616 struct lu_fid lti_fid2;
617 struct lu_fid lti_fid3;
618 struct lu_attr lti_la;
619 struct lu_attr lti_la2;
620 struct lu_attr lti_la3;
621 struct ost_id lti_oi;
623 struct lustre_mdt_attrs lti_lma;
624 /* old LMA for compatibility */
625 char lti_lma_old[LMA_OLD_SIZE];
627 struct dt_object_format lti_dof;
628 /* There will be '\0' at the end of the name. */
629 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
630 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
631 struct lfsck_request lti_lr;
632 struct lfsck_async_interpret_args lti_laia;
633 struct lfsck_async_interpret_args lti_laia2;
634 struct lfsck_start lti_start;
635 struct lfsck_stop lti_stop;
636 ldlm_policy_data_t lti_policy;
637 struct ldlm_res_id lti_resid;
639 struct filter_fid_old lti_old_pfid;
640 struct filter_fid lti_new_pfid;
642 struct dt_allocation_hint lti_hint;
643 struct lu_orphan_rec lti_rec;
644 struct lov_user_md lti_lum;
645 struct dt_insert_rec lti_dt_rec;
646 struct lu_object_conf lti_conf;
650 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
651 struct lu_fid *fid, bool locked);
652 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
653 struct dt_object *obj, struct lustre_handle *lh,
654 __u64 bits, ldlm_mode_t mode);
655 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
656 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
657 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
658 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
660 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
662 const char *lfsck_status2names(enum lfsck_status status);
663 void lfsck_component_cleanup(const struct lu_env *env,
664 struct lfsck_component *com);
665 void lfsck_instance_cleanup(const struct lu_env *env,
666 struct lfsck_instance *lfsck);
667 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
669 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
670 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
672 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
673 struct lfsck_position *pos, bool init);
674 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
675 void lfsck_control_speed(struct lfsck_instance *lfsck);
676 void lfsck_control_speed_by_self(struct lfsck_component *com);
677 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
678 struct lfsck_assistant_data *
679 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
681 int lfsck_async_interpret_common(const struct lu_env *env,
682 struct ptlrpc_request *req,
684 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
685 struct lfsck_request *lr,
686 struct ptlrpc_request_set *set,
687 ptlrpc_interpterer_t interpterer,
688 void *args, int request);
689 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
690 struct lfsck_start_param *lsp);
691 int lfsck_checkpoint_generic(const struct lu_env *env,
692 struct lfsck_component *com);
693 void lfsck_post_generic(const struct lu_env *env,
694 struct lfsck_component *com, int *result);
695 int lfsck_double_scan_generic(const struct lu_env *env,
696 struct lfsck_component *com, int status);
697 void lfsck_quit_generic(const struct lu_env *env,
698 struct lfsck_component *com);
701 int lfsck_master_engine(void *args);
702 int lfsck_assistant_engine(void *args);
704 /* lfsck_bookmark.c */
705 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
706 struct lfsck_bookmark *src);
707 int lfsck_bookmark_store(const struct lu_env *env,
708 struct lfsck_instance *lfsck);
709 int lfsck_bookmark_setup(const struct lu_env *env,
710 struct lfsck_instance *lfsck);
711 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
712 struct lfsck_start *start, bool reset);
714 /* lfsck_namespace.c */
715 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
716 struct dt_object *obj, const struct lu_name *cname,
717 const struct lu_fid *pfid);
718 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
719 char *name, struct lu_fid *pfid);
720 int lfsck_remove_name_entry(const struct lu_env *env,
721 struct lfsck_instance *lfsck,
722 struct dt_object *parent,
723 const char *name, __u32 type);
724 int lfsck_update_name_entry(const struct lu_env *env,
725 struct lfsck_instance *lfsck,
726 struct dt_object *parent, const char *name,
727 const struct lu_fid *pfid, __u32 type);
728 int lfsck_namespace_setup(const struct lu_env *env,
729 struct lfsck_instance *lfsck);
732 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
734 extern const char *lfsck_flags_names[];
735 extern const char *lfsck_param_names[];
736 extern struct lu_context_key lfsck_thread_key;
738 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
740 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
743 static inline struct lfsck_thread_info *
744 lfsck_env_info(const struct lu_env *env)
746 struct lfsck_thread_info *info;
748 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
749 LASSERT(info != NULL);
753 static inline const struct lu_name *
754 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
756 struct lu_name *lname;
758 lname = &lfsck_env_info(env)->lti_name;
759 lname->ln_name = area;
760 lname->ln_namelen = len;
765 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
771 static inline struct lu_buf *
772 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
776 buf = &lfsck_env_info(env)->lti_buf;
782 static inline const struct lu_buf *
783 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
787 buf = &lfsck_env_info(env)->lti_buf;
788 buf->lb_buf = (void *)area;
793 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
795 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
798 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
800 return lu_object_fid(&obj->do_lu);
803 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
805 memset(pos, 0, sizeof(*pos));
808 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
810 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
813 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
814 const struct lfsck_position *pos2)
816 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
819 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
822 if (fid_is_zero(&pos1->lp_dir_parent) &&
823 !fid_is_zero(&pos2->lp_dir_parent))
826 if (!fid_is_zero(&pos1->lp_dir_parent) &&
827 fid_is_zero(&pos2->lp_dir_parent))
830 if (fid_is_zero(&pos1->lp_dir_parent) &&
831 fid_is_zero(&pos2->lp_dir_parent))
834 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
836 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
839 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
845 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
846 struct lfsck_position *src)
848 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
849 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
850 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
853 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
854 struct lfsck_position *src)
856 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
857 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
858 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
861 static inline umode_t lfsck_object_type(const struct dt_object *obj)
863 return lu_object_attr(&obj->do_lu);
866 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
868 struct lu_object_header *loh = obj->do_lu.lo_header;
870 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
873 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
875 lu_object_get(&obj->do_lu);
879 static inline void lfsck_object_put(const struct lu_env *env,
880 struct dt_object *obj)
882 lu_object_put(env, &obj->do_lu);
885 static inline struct dt_object *
886 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
887 const struct lu_fid *fid)
889 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
890 struct dt_object *obj;
892 conf->loc_flags = LOC_F_NOWAIT;
893 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
894 if (unlikely(obj == NULL))
895 return ERR_PTR(-ENOENT);
900 static inline struct dt_object *
901 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
902 const struct lu_fid *fid)
904 struct dt_object *obj;
906 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
907 if (unlikely(obj == NULL))
908 return ERR_PTR(-ENOENT);
913 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
914 struct lfsck_instance *lfsck,
915 const struct lu_fid *fid)
917 return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
920 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
923 struct lfsck_tgt_desc *ltd;
925 ltd = LTD_TGT(ltds, index);
927 atomic_inc(<d->ltd_ref);
932 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
934 if (atomic_dec_and_test(<d->ltd_ref))
938 static inline struct lfsck_component *
939 lfsck_component_get(struct lfsck_component *com)
941 atomic_inc(&com->lc_ref);
946 static inline void lfsck_component_put(const struct lu_env *env,
947 struct lfsck_component *com)
949 if (atomic_dec_and_test(&com->lc_ref)) {
950 if (com->lc_obj != NULL)
951 lu_object_put_nocache(env, &com->lc_obj->do_lu);
952 if (com->lc_file_ram != NULL)
953 OBD_FREE(com->lc_file_ram, com->lc_file_size);
954 if (com->lc_file_disk != NULL)
955 OBD_FREE(com->lc_file_disk, com->lc_file_size);
956 if (com->lc_data != NULL) {
957 LASSERT(com->lc_ops->lfsck_data_release != NULL);
959 com->lc_ops->lfsck_data_release(env, com);
966 static inline struct lfsck_instance *
967 lfsck_instance_get(struct lfsck_instance *lfsck)
969 atomic_inc(&lfsck->li_ref);
974 static inline void lfsck_instance_put(const struct lu_env *env,
975 struct lfsck_instance *lfsck)
977 if (atomic_dec_and_test(&lfsck->li_ref))
978 lfsck_instance_cleanup(env, lfsck);
981 static inline u32 lfsck_dev_idx(struct dt_device *dev)
983 return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
986 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
988 return list_empty(&lad->lad_mdt_phase1_list) &&
989 (!list_empty(&lad->lad_ost_phase2_list) ||
990 list_empty(&lad->lad_ost_phase1_list));
993 static inline void lfsck_lad_set_bitmap(const struct lu_env *env,
994 struct lfsck_component *com,
997 struct lfsck_assistant_data *lad = com->lc_data;
998 cfs_bitmap_t *bitmap = lad->lad_bitmap;
1000 LASSERT(com->lc_lfsck->li_master);
1001 LASSERT(bitmap != NULL);
1002 LASSERTF(bitmap->size > index, "invalid index: nbits %d, index %u\n",
1003 bitmap->size, index);
1005 cfs_bitmap_set(bitmap, index);
1006 lad->lad_incomplete = 1;
1009 #endif /* _LFSCK_INTERNAL_H */