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 /* For further using. 256-bytes aligned now. */
258 __u64 ll_reserved[12];
261 struct lfsck_component;
262 struct lfsck_tgt_descs;
263 struct lfsck_tgt_desc;
265 struct lfsck_operations {
266 int (*lfsck_reset)(const struct lu_env *env,
267 struct lfsck_component *com,
270 void (*lfsck_fail)(const struct lu_env *env,
271 struct lfsck_component *com,
274 int (*lfsck_checkpoint)(const struct lu_env *env,
275 struct lfsck_component *com,
278 int (*lfsck_prep)(const struct lu_env *env,
279 struct lfsck_component *com,
280 struct lfsck_start_param *lsp);
282 int (*lfsck_exec_oit)(const struct lu_env *env,
283 struct lfsck_component *com,
284 struct dt_object *obj);
286 int (*lfsck_exec_dir)(const struct lu_env *env,
287 struct lfsck_component *com,
288 struct lu_dirent *ent,
291 int (*lfsck_post)(const struct lu_env *env,
292 struct lfsck_component *com,
296 int (*lfsck_dump)(const struct lu_env *env,
297 struct lfsck_component *com,
300 int (*lfsck_double_scan)(const struct lu_env *env,
301 struct lfsck_component *com);
303 void (*lfsck_data_release)(const struct lu_env *env,
304 struct lfsck_component *com);
306 void (*lfsck_quit)(const struct lu_env *env,
307 struct lfsck_component *com);
309 int (*lfsck_in_notify)(const struct lu_env *env,
310 struct lfsck_component *com,
311 struct lfsck_request *lr);
313 int (*lfsck_query)(const struct lu_env *env,
314 struct lfsck_component *com);
316 int (*lfsck_join)(const struct lu_env *env,
317 struct lfsck_component *com,
318 struct lfsck_start_param *lsp);
321 #define TGT_PTRS 256 /* number of pointers at 1st level */
322 #define TGT_PTRS_PER_BLOCK 256 /* number of pointers at 2nd level */
324 struct lfsck_tgt_desc {
325 struct list_head ltd_orphan_list;
326 struct dt_device *ltd_tgt;
327 struct dt_device *ltd_key;
328 struct obd_export *ltd_exp;
329 struct list_head ltd_layout_list;
330 struct list_head ltd_layout_phase_list;
331 struct list_head ltd_namespace_list;
332 struct list_head ltd_namespace_phase_list;
335 __u32 ltd_layout_gen;
336 __u32 ltd_namespace_gen;
337 unsigned int ltd_dead:1,
339 ltd_namespace_done:1;
342 struct lfsck_tgt_desc_idx {
343 struct lfsck_tgt_desc *ldi_tgts[TGT_PTRS_PER_BLOCK];
346 struct lfsck_tgt_descs {
347 /* list of known TGTs */
348 struct lfsck_tgt_desc_idx *ltd_tgts_idx[TGT_PTRS];
350 /* bitmap of TGTs available */
351 cfs_bitmap_t *ltd_tgts_bitmap;
353 /* for lfsck_tgt_desc::ltd_xxx_list */
356 /* for tgts table accessing and changes */
357 struct rw_semaphore ltd_rw_sem;
359 /* Temporary list for orphan targets. */
360 struct list_head ltd_orphan;
362 /* number of registered TGTs */
366 #define LTD_TGT(ltd, index) \
367 ((ltd)->ltd_tgts_idx[(index) / TGT_PTRS_PER_BLOCK]->\
368 ldi_tgts[(index) % TGT_PTRS_PER_BLOCK])
370 #define OST_TGT(lfsck, index) LTD_TGT(&lfsck->li_ost_descs, index)
371 #define MDT_TGT(lfsck, index) LTD_TGT(&lfsck->li_mdt_descs, index)
373 struct lfsck_component {
374 /* into lfsck_instance::li_list_(scan,double_scan,idle} */
375 struct list_head lc_link;
377 /* into lfsck_instance::li_list_dir */
378 struct list_head lc_link_dir;
380 struct rw_semaphore lc_sem;
383 struct lfsck_position lc_pos_start;
384 struct lfsck_instance *lc_lfsck;
385 struct dt_object *lc_obj;
386 struct lfsck_operations *lc_ops;
390 struct lu_fid lc_fid_latest_scanned_phase2;
392 /* The time for last checkpoint, jiffies */
393 cfs_time_t lc_time_last_checkpoint;
395 /* The time for next checkpoint, jiffies */
396 cfs_time_t lc_time_next_checkpoint;
400 /* How many objects have been checked since last checkpoint. */
401 __u32 lc_new_checked;
403 /* How many objects have been scanned since last sleep. */
404 __u32 lc_new_scanned;
406 unsigned int lc_journal:1;
410 struct lfsck_instance {
411 struct mutex li_mutex;
414 /* Link into the lfsck_instance_list. */
415 struct list_head li_link;
417 /* For the components in (first) scanning via otable-based iteration. */
418 struct list_head li_list_scan;
420 /* For the components in scanning via directory traversal. Because
421 * directory traversal cannot guarantee all the object be scanned,
422 * so the component in the li_list_dir must be in li_list_scan. */
423 struct list_head li_list_dir;
425 /* For the components in double scanning. */
426 struct list_head li_list_double_scan;
428 /* For the components those are not scanning now. */
429 struct list_head li_list_idle;
432 atomic_t li_double_scan_count;
433 struct ptlrpc_thread li_thread;
435 /* The time for last checkpoint, jiffies */
436 cfs_time_t li_time_last_checkpoint;
438 /* The time for next checkpoint, jiffies */
439 cfs_time_t li_time_next_checkpoint;
441 lfsck_out_notify li_out_notify;
442 void *li_out_notify_data;
443 struct dt_device *li_next;
444 struct dt_device *li_bottom;
445 struct obd_device *li_obd;
446 struct ldlm_namespace *li_namespace;
447 struct local_oid_storage *li_los;
448 struct lu_fid li_local_root_fid; /* backend root "/" */
449 struct lu_fid li_global_root_fid; /* /ROOT */
450 struct dt_object *li_bookmark_obj;
451 struct dt_object *li_lpf_obj;
452 struct lu_client_seq *li_seq;
453 struct lfsck_bookmark li_bookmark_ram;
454 struct lfsck_bookmark li_bookmark_disk;
455 struct lfsck_position li_pos_current;
456 struct lfsck_position li_pos_checkpoint;
458 /* Obj for otable-based iteration */
459 struct dt_object *li_obj_oit;
461 /* Obj for directory traversal */
462 struct dt_object *li_obj_dir;
464 /* It for otable-based iteration */
465 struct dt_it *li_di_oit;
467 /* It for directory traversal */
468 struct dt_it *li_di_dir;
470 /* Description of OST */
471 struct lfsck_tgt_descs li_ost_descs;
473 /* Description of MDT */
474 struct lfsck_tgt_descs li_mdt_descs;
476 /* namespace-based directory traversal position. */
479 /* Arguments for low layer otable-based iteration. */
482 /* Arugments for namespace-based directory traversal. */
485 /* Schedule for every N objects. */
488 /* Sleep N jiffies for each schedule. */
491 /* How many objects have been scanned since last sleep. */
492 __u32 li_new_scanned;
494 /* The status when the LFSCK stopped or paused. */
497 /* The flags when the lFSCK stopped or paused. */
500 unsigned int li_oit_over:1, /* oit is finished. */
501 li_drop_dryrun:1, /* Ever dryrun, not now. */
502 li_master:1, /* Master instance or not. */
503 li_current_oit_processed:1,
507 enum lfsck_linkea_flags {
508 /* The linkea entries does not match the object nlinks. */
509 LLF_UNMATCH_NLINKS = 0x01,
511 /* Fail to repair the multiple-linked objects during the double scan. */
512 LLF_REPAIR_FAILED = 0x02,
515 struct lfsck_async_interpret_args {
516 struct lfsck_component *laia_com;
517 struct lfsck_tgt_descs *laia_ltds;
518 struct lfsck_tgt_desc *laia_ltd;
519 struct lfsck_request *laia_lr;
521 unsigned int laia_shared:1;
524 struct lfsck_thread_args {
525 struct lu_env lta_env;
526 struct lfsck_instance *lta_lfsck;
527 struct lfsck_component *lta_com;
528 struct lfsck_start_param *lta_lsp;
531 struct lfsck_assistant_req {
532 struct list_head lar_list;
535 struct lfsck_assistant_operations {
536 int (*la_handler_p1)(const struct lu_env *env,
537 struct lfsck_component *com,
538 struct lfsck_assistant_req *lar);
540 int (*la_handler_p2)(const struct lu_env *env,
541 struct lfsck_component *com);
543 void (*la_fill_pos)(const struct lu_env *env,
544 struct lfsck_component *com,
545 struct lfsck_position *pos);
547 int (*la_double_scan_result)(const struct lu_env *env,
548 struct lfsck_component *com,
551 void (*la_req_fini)(const struct lu_env *env,
552 struct lfsck_assistant_req *lar);
555 struct lfsck_assistant_data {
557 struct list_head lad_req_list;
559 /* list for the ost targets involve LFSCK. */
560 struct list_head lad_ost_list;
562 /* list for the ost targets in phase1 scanning. */
563 struct list_head lad_ost_phase1_list;
565 /* list for the ost targets in phase1 scanning. */
566 struct list_head lad_ost_phase2_list;
568 /* list for the mdt targets involve LFSCK. */
569 struct list_head lad_mdt_list;
571 /* list for the mdt targets in phase1 scanning. */
572 struct list_head lad_mdt_phase1_list;
574 /* list for the mdt targets in phase1 scanning. */
575 struct list_head lad_mdt_phase2_list;
577 const char *lad_name;
578 struct ptlrpc_thread lad_thread;
580 struct lfsck_assistant_operations *lad_ops;
584 int lad_assistant_status;
586 unsigned int lad_to_post:1,
587 lad_to_double_scan:1,
588 lad_in_double_scan:1,
592 #define LFSCK_TMPBUF_LEN 64
594 struct lfsck_thread_info {
595 struct lu_name lti_name;
596 struct lu_buf lti_buf;
597 struct lu_buf lti_linkea_buf;
598 struct lu_buf lti_big_buf;
599 struct lu_fid lti_fid;
600 struct lu_fid lti_fid2;
601 struct lu_fid lti_fid3;
602 struct lu_attr lti_la;
603 struct lu_attr lti_la2;
604 struct lu_attr lti_la3;
605 struct ost_id lti_oi;
607 struct lustre_mdt_attrs lti_lma;
608 /* old LMA for compatibility */
609 char lti_lma_old[LMA_OLD_SIZE];
611 struct dt_object_format lti_dof;
612 /* There will be '\0' at the end of the name. */
613 char lti_key[sizeof(struct lu_dirent) + NAME_MAX + 1];
614 char lti_tmpbuf[LFSCK_TMPBUF_LEN];
615 struct lfsck_request lti_lr;
616 struct lfsck_async_interpret_args lti_laia;
617 struct lfsck_start lti_start;
618 struct lfsck_stop lti_stop;
619 ldlm_policy_data_t lti_policy;
620 struct ldlm_res_id lti_resid;
622 struct filter_fid_old lti_old_pfid;
623 struct filter_fid lti_new_pfid;
625 struct dt_allocation_hint lti_hint;
626 struct lu_orphan_rec lti_rec;
627 struct lov_user_md lti_lum;
628 struct dt_insert_rec lti_dt_rec;
629 struct lu_object_conf lti_conf;
633 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
634 struct lu_fid *fid, bool locked);
635 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
636 struct dt_object *obj, struct lustre_handle *lh,
637 __u64 bits, ldlm_mode_t mode);
638 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode);
639 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
640 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck);
641 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
643 struct lfsck_component *lfsck_component_find(struct lfsck_instance *lfsck,
645 const char *lfsck_status2names(enum lfsck_status status);
646 void lfsck_component_cleanup(const struct lu_env *env,
647 struct lfsck_component *com);
648 void lfsck_instance_cleanup(const struct lu_env *env,
649 struct lfsck_instance *lfsck);
650 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
652 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix);
653 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
655 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
656 struct lfsck_position *pos, bool init);
657 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit);
658 void lfsck_control_speed(struct lfsck_instance *lfsck);
659 void lfsck_control_speed_by_self(struct lfsck_component *com);
660 void lfsck_thread_args_fini(struct lfsck_thread_args *lta);
661 struct lfsck_assistant_data *
662 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
664 int lfsck_async_interpret_common(const struct lu_env *env,
665 struct ptlrpc_request *req,
667 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
668 struct lfsck_request *lr,
669 struct ptlrpc_request_set *set,
670 ptlrpc_interpterer_t interpterer,
671 void *args, int request);
672 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
673 struct lfsck_start_param *lsp);
674 int lfsck_checkpoint_generic(const struct lu_env *env,
675 struct lfsck_component *com);
676 void lfsck_post_generic(const struct lu_env *env,
677 struct lfsck_component *com, int *result);
678 int lfsck_double_scan_generic(const struct lu_env *env,
679 struct lfsck_component *com, int status);
680 void lfsck_quit_generic(const struct lu_env *env,
681 struct lfsck_component *com);
684 int lfsck_master_engine(void *args);
685 int lfsck_assistant_engine(void *args);
687 /* lfsck_bookmark.c */
688 void lfsck_bookmark_cpu_to_le(struct lfsck_bookmark *des,
689 struct lfsck_bookmark *src);
690 int lfsck_bookmark_store(const struct lu_env *env,
691 struct lfsck_instance *lfsck);
692 int lfsck_bookmark_setup(const struct lu_env *env,
693 struct lfsck_instance *lfsck);
694 int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
695 struct lfsck_start *start, bool reset);
697 /* lfsck_namespace.c */
698 int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
699 struct dt_object *obj, const struct lu_name *cname,
700 const struct lu_fid *pfid);
701 int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
702 char *name, struct lu_fid *pfid);
703 int lfsck_remove_name_entry(const struct lu_env *env,
704 struct lfsck_instance *lfsck,
705 struct dt_object *parent,
706 const char *name, __u32 type);
707 int lfsck_update_name_entry(const struct lu_env *env,
708 struct lfsck_instance *lfsck,
709 struct dt_object *parent, const char *name,
710 const struct lu_fid *pfid, __u32 type);
711 int lfsck_namespace_setup(const struct lu_env *env,
712 struct lfsck_instance *lfsck);
715 int lfsck_layout_setup(const struct lu_env *env, struct lfsck_instance *lfsck);
717 extern const char *lfsck_flags_names[];
718 extern const char *lfsck_param_names[];
719 extern struct lu_context_key lfsck_thread_key;
721 static inline struct dt_device *lfsck_obj2dt_dev(struct dt_object *obj)
723 return container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
726 static inline struct lfsck_thread_info *
727 lfsck_env_info(const struct lu_env *env)
729 struct lfsck_thread_info *info;
731 info = lu_context_key_get(&env->le_ctx, &lfsck_thread_key);
732 LASSERT(info != NULL);
736 static inline const struct lu_name *
737 lfsck_name_get_const(const struct lu_env *env, const void *area, ssize_t len)
739 struct lu_name *lname;
741 lname = &lfsck_env_info(env)->lti_name;
742 lname->ln_name = area;
743 lname->ln_namelen = len;
748 lfsck_buf_init(struct lu_buf *buf, void *area, ssize_t len)
754 static inline struct lu_buf *
755 lfsck_buf_get(const struct lu_env *env, void *area, ssize_t len)
759 buf = &lfsck_env_info(env)->lti_buf;
765 static inline const struct lu_buf *
766 lfsck_buf_get_const(const struct lu_env *env, const void *area, ssize_t len)
770 buf = &lfsck_env_info(env)->lti_buf;
771 buf->lb_buf = (void *)area;
776 static inline char *lfsck_lfsck2name(struct lfsck_instance *lfsck)
778 return lfsck->li_bottom->dd_lu_dev.ld_obd->obd_name;
781 static inline const struct lu_fid *lfsck_dto2fid(const struct dt_object *obj)
783 return lu_object_fid(&obj->do_lu);
786 static inline void lfsck_pos_set_zero(struct lfsck_position *pos)
788 memset(pos, 0, sizeof(*pos));
791 static inline int lfsck_pos_is_zero(const struct lfsck_position *pos)
793 return pos->lp_oit_cookie == 0 && fid_is_zero(&pos->lp_dir_parent);
796 static inline int lfsck_pos_is_eq(const struct lfsck_position *pos1,
797 const struct lfsck_position *pos2)
799 if (pos1->lp_oit_cookie < pos2->lp_oit_cookie)
802 if (pos1->lp_oit_cookie > pos2->lp_oit_cookie)
805 if (fid_is_zero(&pos1->lp_dir_parent) &&
806 !fid_is_zero(&pos2->lp_dir_parent))
809 if (!fid_is_zero(&pos1->lp_dir_parent) &&
810 fid_is_zero(&pos2->lp_dir_parent))
813 if (fid_is_zero(&pos1->lp_dir_parent) &&
814 fid_is_zero(&pos2->lp_dir_parent))
817 LASSERT(lu_fid_eq(&pos1->lp_dir_parent, &pos2->lp_dir_parent));
819 if (pos1->lp_dir_cookie < pos2->lp_dir_cookie)
822 if (pos1->lp_dir_cookie > pos2->lp_dir_cookie)
828 static void inline lfsck_position_le_to_cpu(struct lfsck_position *des,
829 struct lfsck_position *src)
831 des->lp_oit_cookie = le64_to_cpu(src->lp_oit_cookie);
832 fid_le_to_cpu(&des->lp_dir_parent, &src->lp_dir_parent);
833 des->lp_dir_cookie = le64_to_cpu(src->lp_dir_cookie);
836 static void inline lfsck_position_cpu_to_le(struct lfsck_position *des,
837 struct lfsck_position *src)
839 des->lp_oit_cookie = cpu_to_le64(src->lp_oit_cookie);
840 fid_cpu_to_le(&des->lp_dir_parent, &src->lp_dir_parent);
841 des->lp_dir_cookie = cpu_to_le64(src->lp_dir_cookie);
844 static inline umode_t lfsck_object_type(const struct dt_object *obj)
846 return lu_object_attr(&obj->do_lu);
849 static inline int lfsck_is_dead_obj(const struct dt_object *obj)
851 struct lu_object_header *loh = obj->do_lu.lo_header;
853 return !!test_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
856 static inline struct dt_object *lfsck_object_get(struct dt_object *obj)
858 lu_object_get(&obj->do_lu);
862 static inline void lfsck_object_put(const struct lu_env *env,
863 struct dt_object *obj)
865 lu_object_put(env, &obj->do_lu);
868 static inline struct dt_object *
869 lfsck_object_find_by_dev_nowait(const struct lu_env *env, struct dt_device *dev,
870 const struct lu_fid *fid)
872 struct lu_object_conf *conf = &lfsck_env_info(env)->lti_conf;
873 struct dt_object *obj;
875 conf->loc_flags = LOC_F_NOWAIT;
876 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, conf));
877 if (unlikely(obj == NULL))
878 return ERR_PTR(-ENOENT);
883 static inline struct dt_object *
884 lfsck_object_find_by_dev(const struct lu_env *env, struct dt_device *dev,
885 const struct lu_fid *fid)
887 struct dt_object *obj;
889 obj = lu2dt(lu_object_find_slice(env, dt2lu_dev(dev), fid, NULL));
890 if (unlikely(obj == NULL))
891 return ERR_PTR(-ENOENT);
896 static inline struct dt_object *lfsck_object_find(const struct lu_env *env,
897 struct lfsck_instance *lfsck,
898 const struct lu_fid *fid)
900 return lfsck_object_find_by_dev(env, lfsck->li_next, fid);
903 static inline struct lfsck_tgt_desc *lfsck_tgt_get(struct lfsck_tgt_descs *ltds,
906 struct lfsck_tgt_desc *ltd;
908 ltd = LTD_TGT(ltds, index);
910 atomic_inc(<d->ltd_ref);
915 static inline void lfsck_tgt_put(struct lfsck_tgt_desc *ltd)
917 if (atomic_dec_and_test(<d->ltd_ref))
921 static inline struct lfsck_component *
922 lfsck_component_get(struct lfsck_component *com)
924 atomic_inc(&com->lc_ref);
929 static inline void lfsck_component_put(const struct lu_env *env,
930 struct lfsck_component *com)
932 if (atomic_dec_and_test(&com->lc_ref)) {
933 if (com->lc_obj != NULL)
934 lu_object_put_nocache(env, &com->lc_obj->do_lu);
935 if (com->lc_file_ram != NULL)
936 OBD_FREE(com->lc_file_ram, com->lc_file_size);
937 if (com->lc_file_disk != NULL)
938 OBD_FREE(com->lc_file_disk, com->lc_file_size);
939 if (com->lc_data != NULL) {
940 LASSERT(com->lc_ops->lfsck_data_release != NULL);
942 com->lc_ops->lfsck_data_release(env, com);
949 static inline struct lfsck_instance *
950 lfsck_instance_get(struct lfsck_instance *lfsck)
952 atomic_inc(&lfsck->li_ref);
957 static inline void lfsck_instance_put(const struct lu_env *env,
958 struct lfsck_instance *lfsck)
960 if (atomic_dec_and_test(&lfsck->li_ref))
961 lfsck_instance_cleanup(env, lfsck);
964 static inline u32 lfsck_dev_idx(struct dt_device *dev)
966 return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
969 static inline bool lfsck_phase2_next_ready(struct lfsck_assistant_data *lad)
971 return list_empty(&lad->lad_mdt_phase1_list) &&
972 (!list_empty(&lad->lad_ost_phase2_list) ||
973 list_empty(&lad->lad_ost_phase1_list));
976 #endif /* _LFSCK_INTERNAL_H */