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, 2017, Intel Corporation.
26 * lustre/lfsck/lfsck_lib.c
28 * Author: Fan, Yong <fan.yong@intel.com>
31 #define DEBUG_SUBSYSTEM S_LFSCK
33 #include <linux/kthread.h>
34 #include <linux/sched.h>
35 #include <linux/list.h>
36 #include <lu_object.h>
37 #include <dt_object.h>
38 #include <md_object.h>
39 #include <lustre_fld.h>
40 #include <lustre_lib.h>
41 #include <lustre_net.h>
42 #include <lustre_lfsck.h>
44 #include "lfsck_internal.h"
46 #define LFSCK_CHECKPOINT_SKIP 1
48 /* define lfsck thread key */
49 LU_KEY_INIT(lfsck, struct lfsck_thread_info);
51 static void lfsck_key_fini(const struct lu_context *ctx,
52 struct lu_context_key *key, void *data)
54 struct lfsck_thread_info *info = data;
56 lu_buf_free(&info->lti_linkea_buf);
57 lu_buf_free(&info->lti_linkea_buf2);
58 lu_buf_free(&info->lti_big_buf);
62 LU_CONTEXT_KEY_DEFINE(lfsck, LCT_MD_THREAD | LCT_DT_THREAD);
63 LU_KEY_INIT_GENERIC(lfsck);
65 static struct list_head lfsck_instance_list;
66 static struct list_head lfsck_ost_orphan_list;
67 static struct list_head lfsck_mdt_orphan_list;
68 static DEFINE_SPINLOCK(lfsck_instance_lock);
70 const char *lfsck_flags_names[] = {
79 const char *lfsck_param_names[] = {
89 "delay_create_ostobj",
93 enum lfsck_verify_lpf_types {
95 LVLT_BY_NAMEENTRY = 1,
99 lfsck_reset_ltd_status(struct lfsck_tgt_desc *ltd, enum lfsck_type type)
101 if (type == LFSCK_TYPE_LAYOUT) {
102 ltd->ltd_layout_status = LS_MAX;
103 ltd->ltd_layout_repaired = 0;
105 ltd->ltd_namespace_status = LS_MAX;
106 ltd->ltd_namespace_repaired = 0;
110 static int lfsck_tgt_descs_init(struct lfsck_tgt_descs *ltds)
112 spin_lock_init(<ds->ltd_lock);
113 init_rwsem(<ds->ltd_rw_sem);
114 INIT_LIST_HEAD(<ds->ltd_orphan);
115 ltds->ltd_tgts_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
116 if (ltds->ltd_tgts_bitmap == NULL)
122 static void lfsck_tgt_descs_fini(struct lfsck_tgt_descs *ltds)
124 struct lfsck_tgt_desc *ltd;
125 struct lfsck_tgt_desc *next;
128 down_write(<ds->ltd_rw_sem);
130 list_for_each_entry_safe(ltd, next, <ds->ltd_orphan,
132 list_del_init(<d->ltd_orphan_list);
136 if (unlikely(ltds->ltd_tgts_bitmap == NULL)) {
137 up_write(<ds->ltd_rw_sem);
142 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
143 ltd = lfsck_ltd2tgt(ltds, idx);
144 if (likely(ltd != NULL)) {
145 LASSERT(list_empty(<d->ltd_layout_list));
146 LASSERT(list_empty(<d->ltd_layout_phase_list));
147 LASSERT(list_empty(<d->ltd_namespace_list));
148 LASSERT(list_empty(<d->ltd_namespace_phase_list));
151 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, idx);
152 lfsck_assign_tgt(ltds, NULL, idx);
157 LASSERTF(ltds->ltd_tgtnr == 0, "tgt count unmatched: %d\n",
160 for (idx = 0; idx < TGT_PTRS; idx++) {
161 if (ltds->ltd_tgts_idx[idx] != NULL) {
162 OBD_FREE_PTR(ltds->ltd_tgts_idx[idx]);
163 ltds->ltd_tgts_idx[idx] = NULL;
167 CFS_FREE_BITMAP(ltds->ltd_tgts_bitmap);
168 ltds->ltd_tgts_bitmap = NULL;
169 up_write(<ds->ltd_rw_sem);
172 static int __lfsck_add_target(const struct lu_env *env,
173 struct lfsck_instance *lfsck,
174 struct lfsck_tgt_desc *ltd,
175 bool for_ost, bool locked)
177 struct lfsck_tgt_descs *ltds;
178 __u32 index = ltd->ltd_index;
183 ltds = &lfsck->li_ost_descs;
185 ltds = &lfsck->li_mdt_descs;
188 down_write(<ds->ltd_rw_sem);
190 LASSERT(ltds->ltd_tgts_bitmap != NULL);
192 if (index >= ltds->ltd_tgts_bitmap->size) {
193 __u32 newsize = max((__u32)ltds->ltd_tgts_bitmap->size,
194 (__u32)BITS_PER_LONG);
195 struct cfs_bitmap *old_bitmap = ltds->ltd_tgts_bitmap;
196 struct cfs_bitmap *new_bitmap;
198 while (newsize < index + 1)
201 new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
202 if (new_bitmap == NULL)
203 GOTO(unlock, rc = -ENOMEM);
205 if (ltds->ltd_tgtnr > 0)
206 cfs_bitmap_copy(new_bitmap, old_bitmap);
207 ltds->ltd_tgts_bitmap = new_bitmap;
208 CFS_FREE_BITMAP(old_bitmap);
211 if (cfs_bitmap_check(ltds->ltd_tgts_bitmap, index)) {
212 CERROR("%s: the device %s (%u) is registered already\n",
213 lfsck_lfsck2name(lfsck),
214 ltd->ltd_tgt->dd_lu_dev.ld_obd->obd_name, index);
215 GOTO(unlock, rc = -EEXIST);
218 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
219 OBD_ALLOC_PTR(ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK]);
220 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL)
221 GOTO(unlock, rc = -ENOMEM);
224 lfsck_assign_tgt(ltds, ltd, index);
225 cfs_bitmap_set(ltds->ltd_tgts_bitmap, index);
228 GOTO(unlock, rc = 0);
232 up_write(<ds->ltd_rw_sem);
237 static int lfsck_add_target_from_orphan(const struct lu_env *env,
238 struct lfsck_instance *lfsck)
240 struct lfsck_tgt_descs *ltds = &lfsck->li_ost_descs;
241 struct lfsck_tgt_desc *ltd;
242 struct lfsck_tgt_desc *next;
243 struct list_head *head = &lfsck_ost_orphan_list;
248 spin_lock(&lfsck_instance_lock);
249 list_for_each_entry_safe(ltd, next, head, ltd_orphan_list) {
250 if (ltd->ltd_key == lfsck->li_bottom)
251 list_move_tail(<d->ltd_orphan_list,
254 spin_unlock(&lfsck_instance_lock);
256 down_write(<ds->ltd_rw_sem);
257 while (!list_empty(<ds->ltd_orphan)) {
258 ltd = list_entry(ltds->ltd_orphan.next,
259 struct lfsck_tgt_desc,
261 list_del_init(<d->ltd_orphan_list);
262 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, true);
263 /* Do not hold the semaphore for too long time. */
264 up_write(<ds->ltd_rw_sem);
268 down_write(<ds->ltd_rw_sem);
270 up_write(<ds->ltd_rw_sem);
273 ltds = &lfsck->li_mdt_descs;
274 head = &lfsck_mdt_orphan_list;
282 static inline struct lfsck_component *
283 __lfsck_component_find(struct lfsck_instance *lfsck, __u16 type,
284 struct list_head *list)
286 struct lfsck_component *com;
288 list_for_each_entry(com, list, lc_link) {
289 if (com->lc_type == type)
295 struct lfsck_component *
296 lfsck_component_find(struct lfsck_instance *lfsck, __u16 type)
298 struct lfsck_component *com;
300 spin_lock(&lfsck->li_lock);
301 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
305 com = __lfsck_component_find(lfsck, type,
306 &lfsck->li_list_double_scan);
310 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_idle);
314 lfsck_component_get(com);
315 spin_unlock(&lfsck->li_lock);
319 void lfsck_component_cleanup(const struct lu_env *env,
320 struct lfsck_component *com)
322 if (!list_empty(&com->lc_link))
323 list_del_init(&com->lc_link);
324 if (!list_empty(&com->lc_link_dir))
325 list_del_init(&com->lc_link_dir);
327 lfsck_component_put(env, com);
330 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
331 struct lu_fid *fid, bool locked)
333 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
338 mutex_lock(&lfsck->li_mutex);
340 rc = seq_client_alloc_fid(env, lfsck->li_seq, fid);
342 bk->lb_last_fid = *fid;
343 /* We do not care about whether the subsequent sub-operations
344 * failed or not. The worst case is that one FID is lost that
345 * is not a big issue for the LFSCK since it is relative rare
346 * for LFSCK create. */
347 rc = lfsck_bookmark_store(env, lfsck);
351 mutex_unlock(&lfsck->li_mutex);
356 static int __lfsck_ibits_lock(const struct lu_env *env,
357 struct lfsck_instance *lfsck,
358 struct dt_object *obj, struct ldlm_res_id *resid,
359 struct lustre_handle *lh, __u64 bits,
362 struct lfsck_thread_info *info = lfsck_env_info(env);
363 union ldlm_policy_data *policy = &info->lti_policy;
364 __u64 flags = LDLM_FL_ATOMIC_CB;
367 LASSERT(lfsck->li_namespace != NULL);
369 memset(policy, 0, sizeof(*policy));
370 policy->l_inodebits.bits = bits;
371 if (dt_object_remote(obj)) {
372 struct ldlm_enqueue_info *einfo = &info->lti_einfo;
374 memset(einfo, 0, sizeof(*einfo));
375 einfo->ei_type = LDLM_IBITS;
376 einfo->ei_mode = mode;
377 einfo->ei_cb_bl = ldlm_blocking_ast;
378 einfo->ei_cb_cp = ldlm_completion_ast;
379 einfo->ei_res_id = resid;
381 rc = dt_object_lock(env, obj, lh, einfo, policy);
382 /* for regular checks LFSCK doesn't use LDLM locking,
383 * so the state isn't coherent. here we just took LDLM
384 * lock for coherency and it's time to invalidate
387 dt_invalidate(env, obj);
389 rc = ldlm_cli_enqueue_local(env, lfsck->li_namespace, resid,
390 LDLM_IBITS, policy, mode,
391 &flags, ldlm_blocking_ast,
392 ldlm_completion_ast, NULL, NULL,
393 0, LVB_T_NONE, NULL, lh);
396 if (rc == ELDLM_OK) {
399 memset(lh, 0, sizeof(*lh));
407 * Request the specified ibits lock for the given object.
409 * Before the LFSCK modifying on the namespace visible object,
410 * it needs to acquire related ibits ldlm lock.
412 * \param[in] env pointer to the thread context
413 * \param[in] lfsck pointer to the lfsck instance
414 * \param[in] obj pointer to the dt_object to be locked
415 * \param[out] lh pointer to the lock handle
416 * \param[in] bits the bits for the ldlm lock to be acquired
417 * \param[in] mode the mode for the ldlm lock to be acquired
419 * \retval 0 for success
420 * \retval negative error number on failure
422 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
423 struct dt_object *obj, struct lustre_handle *lh,
424 __u64 bits, enum ldlm_mode mode)
426 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
428 LASSERT(!lustre_handle_is_used(lh));
430 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
431 return __lfsck_ibits_lock(env, lfsck, obj, resid, lh, bits, mode);
435 * Release the the specified ibits lock.
437 * If the lock has been acquired before, release it
438 * and cleanup the handle. Otherwise, do nothing.
440 * \param[in] lh pointer to the lock handle
441 * \param[in] mode the mode for the ldlm lock to be released
443 void lfsck_ibits_unlock(struct lustre_handle *lh, enum ldlm_mode mode)
445 if (lustre_handle_is_used(lh)) {
446 ldlm_lock_decref(lh, mode);
447 memset(lh, 0, sizeof(*lh));
452 * Request compound ibits locks for the given <obj, name> pairs.
454 * Before the LFSCK modifying on the namespace visible object, it needs to
455 * acquire related ibits ldlm lock. Usually, we can use lfsck_ibits_lock for
456 * the lock purpose. But the simple lfsck_ibits_lock for directory-based
457 * modificationis (such as insert name entry to the directory) may be too
458 * coarse-grained and not efficient.
460 * The lfsck_lock() will request compound ibits locks on the specified
461 * <obj, name> pairs: the PDO (Parallel Directory Operations) ibits (UPDATE)
462 * lock on the directory object, and the regular ibits lock on the name hash.
464 * \param[in] env pointer to the thread context
465 * \param[in] lfsck pointer to the lfsck instance
466 * \param[in] obj pointer to the dt_object to be locked
467 * \param[in] name used for building the PDO lock resource
468 * \param[out] llh pointer to the lfsck_lock_handle
469 * \param[in] bits the bits for the ldlm lock to be acquired
470 * \param[in] mode the mode for the ldlm lock to be acquired
472 * \retval 0 for success
473 * \retval negative error number on failure
475 int lfsck_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
476 struct dt_object *obj, const char *name,
477 struct lfsck_lock_handle *llh, __u64 bits, enum ldlm_mode mode)
479 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
482 LASSERT(S_ISDIR(lfsck_object_type(obj)));
483 LASSERT(name != NULL);
484 LASSERT(name[0] != 0);
485 LASSERT(!lustre_handle_is_used(&llh->llh_pdo_lh));
486 LASSERT(!lustre_handle_is_used(&llh->llh_reg_lh));
490 llh->llh_pdo_mode = LCK_EX;
493 llh->llh_pdo_mode = LCK_CW;
496 llh->llh_pdo_mode = LCK_CR;
499 CDEBUG(D_LFSCK, "%s: unexpected PDO lock mode %u on the obj "
500 DFID"\n", lfsck_lfsck2name(lfsck), mode,
501 PFID(lfsck_dto2fid(obj)));
505 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
506 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_pdo_lh,
507 MDS_INODELOCK_UPDATE, llh->llh_pdo_mode);
511 llh->llh_reg_mode = mode;
512 resid->name[LUSTRE_RES_ID_HSH_OFF] = ll_full_name_hash(NULL, name,
514 LASSERT(resid->name[LUSTRE_RES_ID_HSH_OFF] != 0);
515 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_reg_lh,
516 bits, llh->llh_reg_mode);
518 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
524 * Release the the compound ibits locks.
526 * \param[in] llh pointer to the lfsck_lock_handle to be released
528 void lfsck_unlock(struct lfsck_lock_handle *llh)
530 lfsck_ibits_unlock(&llh->llh_reg_lh, llh->llh_reg_mode);
531 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
534 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
535 struct lfsck_instance *lfsck,
536 const struct lu_fid *fid)
538 struct seq_server_site *ss = lfsck_dev_site(lfsck);
539 struct lu_seq_range *range = &lfsck_env_info(env)->lti_range;
542 if (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE)) {
543 /* "ROOT" is always on the MDT0. */
544 if (lu_fid_eq(fid, &lfsck->li_global_root_fid))
547 return lfsck_dev_idx(lfsck);
550 fld_range_set_mdt(range);
551 rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
553 rc = range->lsr_index;
558 const char dot[] = ".";
559 const char dotdot[] = "..";
560 static const char dotlustre[] = ".lustre";
561 static const char lostfound[] = "lost+found";
564 * Remove the name entry from the .lustre/lost+found directory.
566 * No need to care about the object referenced by the name entry,
567 * either the name entry is invalid or redundant, or the referenced
568 * object has been processed or will be handled by others.
570 * \param[in] env pointer to the thread context
571 * \param[in] lfsck pointer to the lfsck instance
572 * \param[in] name the name for the name entry to be removed
574 * \retval 0 for success
575 * \retval negative error number on failure
577 static int lfsck_lpf_remove_name_entry(const struct lu_env *env,
578 struct lfsck_instance *lfsck,
581 struct dt_object *parent = lfsck->li_lpf_root_obj;
582 struct dt_device *dev = lfsck_obj2dev(parent);
584 struct lfsck_lock_handle *llh = &lfsck_env_info(env)->lti_llh;
588 rc = lfsck_lock(env, lfsck, parent, name, llh,
589 MDS_INODELOCK_UPDATE, LCK_PW);
593 th = dt_trans_create(env, dev);
595 GOTO(unlock, rc = PTR_ERR(th));
597 rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
601 rc = dt_declare_ref_del(env, parent, th);
605 rc = dt_trans_start_local(env, dev, th);
609 rc = dt_delete(env, parent, (const struct dt_key *)name, th);
613 dt_write_lock(env, parent, 0);
614 rc = dt_ref_del(env, parent, th);
615 dt_write_unlock(env, parent);
620 dt_trans_stop(env, dev, th);
625 CDEBUG(D_LFSCK, "%s: remove name entry "DFID"/%s: rc = %d\n",
626 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(parent)), name, rc);
631 static int lfsck_create_lpf_local(const struct lu_env *env,
632 struct lfsck_instance *lfsck,
633 struct dt_object *child,
635 struct dt_object_format *dof,
638 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
639 struct dt_object *parent = lfsck->li_lpf_root_obj;
640 struct dt_device *dev = lfsck_obj2dev(child);
641 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
642 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
643 const struct lu_fid *cfid = lfsck_dto2fid(child);
644 struct thandle *th = NULL;
645 struct linkea_data ldata = { NULL };
646 struct lu_buf linkea_buf;
647 const struct lu_name *cname;
649 int len = sizeof(struct lfsck_bookmark);
653 cname = lfsck_name_get_const(env, name, strlen(name));
654 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
655 cname, lfsck_dto2fid(parent));
659 th = dt_trans_create(env, dev);
663 /* 1a. create child */
664 rc = dt_declare_create(env, child, la, NULL, dof, th);
668 if (!dt_try_as_dir(env, child))
669 GOTO(stop, rc = -ENOTDIR);
671 /* 2a. increase child nlink */
672 rc = dt_declare_ref_add(env, child, th);
676 /* 3a. insert dot into child dir */
677 rec->rec_type = S_IFDIR;
679 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
680 (const struct dt_key *)dot, th);
684 /* 4a. insert dotdot into child dir */
685 rec->rec_fid = &LU_LPF_FID;
686 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
687 (const struct dt_key *)dotdot, th);
691 /* 5a. insert linkEA for child */
692 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
693 ldata.ld_leh->leh_len);
694 rc = dt_declare_xattr_set(env, child, &linkea_buf,
695 XATTR_NAME_LINK, 0, th);
699 /* 6a. insert name into parent dir */
700 rec->rec_type = S_IFDIR;
702 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
703 (const struct dt_key *)name, th);
707 /* 7a. increase parent nlink */
708 rc = dt_declare_ref_add(env, parent, th);
712 /* 8a. update bookmark */
713 rc = dt_declare_record_write(env, bk_obj,
714 lfsck_buf_get(env, bk, len), 0, th);
718 rc = dt_trans_start_local(env, dev, th);
722 dt_write_lock(env, child, 0);
723 /* 1b. create child */
724 rc = dt_create(env, child, la, NULL, dof, th);
728 /* 2b. increase child nlink */
729 rc = dt_ref_add(env, child, th);
733 /* 3b. insert dot into child dir */
735 rc = dt_insert(env, child, (const struct dt_rec *)rec,
736 (const struct dt_key *)dot, th);
740 /* 4b. insert dotdot into child dir */
741 rec->rec_fid = &LU_LPF_FID;
742 rc = dt_insert(env, child, (const struct dt_rec *)rec,
743 (const struct dt_key *)dotdot, th);
747 /* 5b. insert linkEA for child. */
748 rc = dt_xattr_set(env, child, &linkea_buf,
749 XATTR_NAME_LINK, 0, th);
750 dt_write_unlock(env, child);
754 /* 6b. insert name into parent dir */
756 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
757 (const struct dt_key *)name, th);
761 dt_write_lock(env, parent, 0);
762 /* 7b. increase parent nlink */
763 rc = dt_ref_add(env, parent, th);
764 dt_write_unlock(env, parent);
768 bk->lb_lpf_fid = *cfid;
769 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
771 /* 8b. update bookmark */
772 rc = dt_record_write(env, bk_obj,
773 lfsck_buf_get(env, bk, len), &pos, th);
778 dt_write_unlock(env, child);
781 dt_trans_stop(env, dev, th);
786 static int lfsck_create_lpf_remote(const struct lu_env *env,
787 struct lfsck_instance *lfsck,
788 struct dt_object *child,
790 struct dt_object_format *dof,
793 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
794 struct dt_object *parent = lfsck->li_lpf_root_obj;
795 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
796 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
797 const struct lu_fid *cfid = lfsck_dto2fid(child);
798 struct thandle *th = NULL;
799 struct linkea_data ldata = { NULL };
800 struct lu_buf linkea_buf;
801 const struct lu_name *cname;
802 struct dt_device *dev;
804 int len = sizeof(struct lfsck_bookmark);
808 cname = lfsck_name_get_const(env, name, strlen(name));
809 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
810 cname, lfsck_dto2fid(parent));
814 /* Create .lustre/lost+found/MDTxxxx. */
816 /* XXX: Currently, cross-MDT create operation needs to create the child
817 * object firstly, then insert name into the parent directory. For
818 * this case, the child object resides on current MDT (local), but
819 * the parent ".lustre/lost+found" may be on remote MDT. It is not
820 * easy to contain all the sub-modifications orderly within single
823 * To avoid more inconsistency, we split the create operation into
826 * 1) create the child and update the lfsck_bookmark::lb_lpf_fid
828 * 2) insert the name "MDTXXXX" in the parent ".lustre/lost+found"
831 * If 1) done, but 2) failed, then go ahead, the LFSCK will try to
832 * repair such inconsistency when LFSCK run next time. */
834 /* Transaction I: locally */
836 dev = lfsck_obj2dev(child);
837 th = dt_trans_create(env, dev);
841 /* 1a. create child */
842 rc = dt_declare_create(env, child, la, NULL, dof, th);
846 if (!dt_try_as_dir(env, child))
847 GOTO(stop, rc = -ENOTDIR);
849 /* 2a. increase child nlink */
850 rc = dt_declare_ref_add(env, child, th);
854 /* 3a. insert dot into child dir */
855 rec->rec_type = S_IFDIR;
857 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
858 (const struct dt_key *)dot, th);
862 /* 4a. insert dotdot into child dir */
863 rec->rec_fid = &LU_LPF_FID;
864 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
865 (const struct dt_key *)dotdot, th);
869 /* 5a. insert linkEA for child */
870 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
871 ldata.ld_leh->leh_len);
872 rc = dt_declare_xattr_set(env, child, &linkea_buf,
873 XATTR_NAME_LINK, 0, th);
877 /* 6a. update bookmark */
878 rc = dt_declare_record_write(env, bk_obj,
879 lfsck_buf_get(env, bk, len), 0, th);
883 rc = dt_trans_start_local(env, dev, th);
887 dt_write_lock(env, child, 0);
888 /* 1b. create child */
889 rc = dt_create(env, child, la, NULL, dof, th);
893 /* 2b. increase child nlink */
894 rc = dt_ref_add(env, child, th);
898 /* 3b. insert dot into child dir */
899 rec->rec_type = S_IFDIR;
901 rc = dt_insert(env, child, (const struct dt_rec *)rec,
902 (const struct dt_key *)dot, th);
906 /* 4b. insert dotdot into child dir */
907 rec->rec_fid = &LU_LPF_FID;
908 rc = dt_insert(env, child, (const struct dt_rec *)rec,
909 (const struct dt_key *)dotdot, th);
913 /* 5b. insert linkEA for child */
914 rc = dt_xattr_set(env, child, &linkea_buf,
915 XATTR_NAME_LINK, 0, th);
919 bk->lb_lpf_fid = *cfid;
920 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
922 /* 6b. update bookmark */
923 rc = dt_record_write(env, bk_obj,
924 lfsck_buf_get(env, bk, len), &pos, th);
926 dt_write_unlock(env, child);
927 dt_trans_stop(env, dev, th);
931 /* Transaction II: remotely */
933 dev = lfsck_obj2dev(parent);
934 th = dt_trans_create(env, dev);
939 /* 5a. insert name into parent dir */
941 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
942 (const struct dt_key *)name, th);
946 /* 6a. increase parent nlink */
947 rc = dt_declare_ref_add(env, parent, th);
951 rc = dt_trans_start_local(env, dev, th);
955 /* 5b. insert name into parent dir */
956 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
957 (const struct dt_key *)name, th);
961 dt_write_lock(env, parent, 0);
962 /* 6b. increase parent nlink */
963 rc = dt_ref_add(env, parent, th);
964 dt_write_unlock(env, parent);
969 dt_write_unlock(env, child);
971 dt_trans_stop(env, dev, th);
973 if (rc != 0 && dev == lfsck_obj2dev(parent))
974 CDEBUG(D_LFSCK, "%s: partially created the object "DFID
975 "for orphans, but failed to insert the name %s "
976 "to the .lustre/lost+found/. Such inconsistency "
977 "will be repaired when LFSCK run next time: rc = %d\n",
978 lfsck_lfsck2name(lfsck), PFID(cfid), name, rc);
984 * Create the MDTxxxx directory under /ROOT/.lustre/lost+found/
986 * The /ROOT/.lustre/lost+found/MDTxxxx/ directory is used for holding
987 * orphans and other uncertain inconsistent objects found during the
988 * LFSCK. Such directory will be created by the LFSCK engine on the
989 * local MDT before the LFSCK scanning.
991 * \param[in] env pointer to the thread context
992 * \param[in] lfsck pointer to the lfsck instance
994 * \retval 0 for success
995 * \retval negative error number on failure
997 static int lfsck_create_lpf(const struct lu_env *env,
998 struct lfsck_instance *lfsck)
1000 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1001 struct lfsck_thread_info *info = lfsck_env_info(env);
1002 struct lu_fid *cfid = &info->lti_fid2;
1003 struct lu_attr *la = &info->lti_la;
1004 struct dt_object_format *dof = &info->lti_dof;
1005 struct dt_object *parent = lfsck->li_lpf_root_obj;
1006 struct dt_object *child = NULL;
1007 struct lfsck_lock_handle *llh = &info->lti_llh;
1009 int node = lfsck_dev_idx(lfsck);
1013 LASSERT(lfsck->li_master);
1014 LASSERT(parent != NULL);
1015 LASSERT(lfsck->li_lpf_obj == NULL);
1017 snprintf(name, 8, "MDT%04x", node);
1018 rc = lfsck_lock(env, lfsck, parent, name, llh,
1019 MDS_INODELOCK_UPDATE, LCK_PW);
1023 if (fid_is_zero(&bk->lb_lpf_fid)) {
1024 /* There is corner case that: in former LFSCK scanning we have
1025 * created the .lustre/lost+found/MDTxxxx but failed to update
1026 * the lfsck_bookmark::lb_lpf_fid successfully. So need lookup
1027 * it from MDT0 firstly. */
1028 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
1029 (const struct dt_key *)name);
1030 if (rc != 0 && rc != -ENOENT)
1034 bk->lb_lpf_fid = *cfid;
1035 rc = lfsck_bookmark_store(env, lfsck);
1037 rc = lfsck_fid_alloc(env, lfsck, cfid, true);
1042 *cfid = bk->lb_lpf_fid;
1045 child = lfsck_object_find_bottom_new(env, lfsck, cfid);
1047 GOTO(unlock, rc = PTR_ERR(child));
1049 if (dt_object_exists(child) != 0) {
1050 if (unlikely(!dt_try_as_dir(env, child)))
1053 lfsck->li_lpf_obj = child;
1058 memset(la, 0, sizeof(*la));
1059 la->la_atime = la->la_mtime = la->la_ctime = ktime_get_real_seconds();
1060 la->la_mode = S_IFDIR | S_IRWXU;
1061 la->la_valid = LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1063 memset(dof, 0, sizeof(*dof));
1064 dof->dof_type = dt_mode_to_dft(S_IFDIR);
1067 rc = lfsck_create_lpf_local(env, lfsck, child, la, dof, name);
1069 rc = lfsck_create_lpf_remote(env, lfsck, child, la, dof, name);
1071 lfsck->li_lpf_obj = child;
1077 if (rc != 0 && child != NULL && !IS_ERR(child))
1078 lfsck_object_put(env, child);
1084 * Scan .lustre/lost+found for bad name entries and remove them.
1086 * The valid name entry should be "MDTxxxx", the "xxxx" is the MDT device
1087 * index in the system. Any other formatted name is invalid and should be
1090 * \param[in] env pointer to the thread context
1091 * \param[in] lfsck pointer to the lfsck instance
1093 * \retval 0 for success
1094 * \retval negative error number on failure
1096 static int lfsck_scan_lpf_bad_entries(const struct lu_env *env,
1097 struct lfsck_instance *lfsck)
1099 struct dt_object *parent = lfsck->li_lpf_root_obj;
1100 struct lu_dirent *ent =
1101 (struct lu_dirent *)lfsck_env_info(env)->lti_key;
1102 const struct dt_it_ops *iops = &parent->do_index_ops->dio_it;
1107 it = iops->init(env, parent, LUDA_64BITHASH);
1109 RETURN(PTR_ERR(it));
1111 rc = iops->load(env, it, 0);
1113 rc = iops->next(env, it);
1120 rc = iops->rec(env, it, (struct dt_rec *)ent, LUDA_64BITHASH);
1124 ent->lde_namelen = le16_to_cpu(ent->lde_namelen);
1125 if (name_is_dot_or_dotdot(ent->lde_name, ent->lde_namelen))
1128 /* name length must be strlen("MDTxxxx") */
1129 if (ent->lde_namelen != 7)
1132 if (memcmp(ent->lde_name, "MDT", off) != 0)
1135 while (off < 7 && isxdigit(ent->lde_name[off]))
1141 rc = lfsck_lpf_remove_name_entry(env, lfsck,
1148 rc = iops->next(env, it);
1152 iops->fini(env, it);
1154 RETURN(rc > 0 ? 0 : rc);
1157 static int lfsck_update_lpf_entry(const struct lu_env *env,
1158 struct lfsck_instance *lfsck,
1159 struct dt_object *parent,
1160 struct dt_object *child,
1162 enum lfsck_verify_lpf_types type)
1166 if (type == LVLT_BY_BOOKMARK) {
1167 rc = lfsck_update_name_entry(env, lfsck, parent, name,
1168 lfsck_dto2fid(child), S_IFDIR);
1169 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1170 lfsck->li_bookmark_ram.lb_lpf_fid = *lfsck_dto2fid(child);
1171 rc = lfsck_bookmark_store(env, lfsck);
1173 CDEBUG(D_LFSCK, "%s: update LPF fid "DFID
1174 " in the bookmark file: rc = %d\n",
1175 lfsck_lfsck2name(lfsck),
1176 PFID(lfsck_dto2fid(child)), rc);
1183 * Check whether the @child back references the @parent.
1186 * 1) The child's FID is stored in the bookmark file. If the child back
1187 * references the parent (LU_LPF_FID object) via its ".." entry, then
1188 * insert the name (MDTxxxx) to the .lustre/lost+found; otherwise, if
1189 * the child back references another parent2, then:
1190 * 1.1) If the parent2 recognizes the child, then update the bookmark file;
1191 * 1.2) Otherwise, the LFSCK cannot know whether there will be parent3 that
1192 * references the child. So keep them there. As the LFSCK processing,
1193 * the parent3 may be found, then when the LFSCK run next time, the
1194 * inconsistency can be repaired.
1196 * 2) The child's FID is stored in the .lustre/lost+found/ sub-directory name
1197 * entry (MDTxxxx). If the child back references the parent (LU_LPF_FID obj)
1198 * via its ".." entry, then update the bookmark file, otherwise, if the child
1199 * back references another parent2, then:
1200 * 2.1) If the parent2 recognizes the child, then remove the sub-directory
1201 * from .lustre/lost+found/;
1202 * 2.2) Otherwise, if the parent2 does not recognizes the child, trust the
1203 * sub-directory name entry and update the child;
1204 * 2.3) Otherwise, if we do not know whether the parent2 recognizes the child
1205 * or not, then keep them there.
1207 * \param[in] env pointer to the thread context
1208 * \param[in] lfsck pointer to the lfsck instance
1209 * \param[in] child pointer to the lost+found sub-directory object
1210 * \param[in] name the name for lost+found sub-directory object
1211 * \param[out] fid pointer to the buffer to hold the FID of the object
1212 * (called it as parent2) that is referenced via the
1213 * child's dotdot entry; it also can be the FID that
1214 * is referenced by the name entry under the parent2.
1215 * \param[in] type to indicate where the child's FID is stored in
1217 * \retval positive number for uncertain inconsistency
1218 * \retval 0 for success
1219 * \retval negative error number on failure
1221 static int lfsck_verify_lpf_pairs(const struct lu_env *env,
1222 struct lfsck_instance *lfsck,
1223 struct dt_object *child, const char *name,
1225 enum lfsck_verify_lpf_types type)
1227 struct dt_object *parent = lfsck->li_lpf_root_obj;
1228 struct lfsck_thread_info *info = lfsck_env_info(env);
1229 char *name2 = info->lti_key;
1230 struct lu_fid *fid2 = &info->lti_fid3;
1231 struct dt_object *parent2 = NULL;
1232 struct lustre_handle lh = { 0 };
1237 rc = dt_lookup(env, child, (struct dt_rec *)fid,
1238 (const struct dt_key *)dotdot);
1242 if (!fid_is_sane(fid))
1243 GOTO(linkea, rc = -EINVAL);
1245 if (lu_fid_eq(fid, &LU_LPF_FID)) {
1246 const struct lu_name *cname;
1248 if (lfsck->li_lpf_obj == NULL) {
1249 lu_object_get(&child->do_lu);
1250 lfsck->li_lpf_obj = child;
1253 cname = lfsck_name_get_const(env, name, strlen(name));
1254 rc = lfsck_verify_linkea(env, child, cname, &LU_LPF_FID);
1256 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1262 parent2 = lfsck_object_find_bottom(env, lfsck, fid);
1263 if (IS_ERR(parent2))
1264 GOTO(linkea, parent2);
1266 if (!dt_object_exists(parent2)) {
1267 lfsck_object_put(env, parent2);
1269 GOTO(linkea, parent2 = ERR_PTR(-ENOENT));
1272 if (!dt_try_as_dir(env, parent2)) {
1273 lfsck_object_put(env, parent2);
1275 GOTO(linkea, parent2 = ERR_PTR(-ENOTDIR));
1279 /* To prevent rename/unlink race */
1280 rc = lfsck_ibits_lock(env, lfsck, child, &lh,
1281 MDS_INODELOCK_UPDATE, LCK_PR);
1285 dt_read_lock(env, child, 0);
1286 rc = lfsck_links_get_first(env, child, name2, fid2);
1288 dt_read_unlock(env, child);
1289 lfsck_ibits_unlock(&lh, LCK_PR);
1291 GOTO(out_put, rc = 1);
1294 /* It is almost impossible that the bookmark file (or the name entry)
1295 * and the linkEA hit the same data corruption. Trust the linkEA. */
1296 if (lu_fid_eq(fid2, &LU_LPF_FID) && strcmp(name, name2) == 0) {
1297 dt_read_unlock(env, child);
1298 lfsck_ibits_unlock(&lh, LCK_PR);
1301 if (lfsck->li_lpf_obj == NULL) {
1302 lu_object_get(&child->do_lu);
1303 lfsck->li_lpf_obj = child;
1306 /* Update the child's dotdot entry */
1307 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1308 &LU_LPF_FID, S_IFDIR);
1310 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1316 if (parent2 == NULL || IS_ERR(parent2)) {
1317 dt_read_unlock(env, child);
1318 lfsck_ibits_unlock(&lh, LCK_PR);
1320 GOTO(out_done, rc = 1);
1323 rc = dt_lookup(env, parent2, (struct dt_rec *)fid,
1324 (const struct dt_key *)name2);
1325 dt_read_unlock(env, child);
1326 lfsck_ibits_unlock(&lh, LCK_PR);
1327 if (rc != 0 && rc != -ENOENT)
1330 if (rc == -ENOENT || !lu_fid_eq(fid, lfsck_dto2fid(child))) {
1331 if (type == LVLT_BY_BOOKMARK)
1332 GOTO(out_put, rc = 1);
1334 /* Trust the name entry, update the child's dotdot entry. */
1335 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1336 &LU_LPF_FID, S_IFDIR);
1341 if (type == LVLT_BY_BOOKMARK) {
1342 /* Invalid FID record in the bookmark file, reset it. */
1343 fid_zero(&lfsck->li_bookmark_ram.lb_lpf_fid);
1344 rc = lfsck_bookmark_store(env, lfsck);
1346 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1347 " in the bookmark file: rc = %d\n",
1348 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(child)), rc);
1349 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1350 /* The name entry is wrong, remove it. */
1351 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1357 if (parent2 != NULL && !IS_ERR(parent2))
1358 lfsck_object_put(env, parent2);
1365 * Verify the /ROOT/.lustre/lost+found/ directory.
1367 * /ROOT/.lustre/lost+found/ is a special directory to hold the objects that
1368 * the LFSCK does not exactly know how to handle, such as orphans. So before
1369 * the LFSCK scanning the system, the consistency of such directory needs to
1370 * be verified firstly to allow the users to use it during the LFSCK.
1372 * \param[in] env pointer to the thread context
1373 * \param[in] lfsck pointer to the lfsck instance
1375 * \retval positive number for uncertain inconsistency
1376 * \retval 0 for success
1377 * \retval negative error number on failure
1379 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
1381 struct lfsck_thread_info *info = lfsck_env_info(env);
1382 struct lu_fid *pfid = &info->lti_fid;
1383 struct lu_fid *cfid = &info->lti_fid2;
1384 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1385 struct dt_object *parent;
1386 /* child1's FID is in the bookmark file. */
1387 struct dt_object *child1 = NULL;
1388 /* child2's FID is in the name entry MDTxxxx. */
1389 struct dt_object *child2 = NULL;
1390 const struct lu_name *cname;
1392 int node = lfsck_dev_idx(lfsck);
1396 LASSERT(lfsck->li_master);
1398 if (lfsck->li_lpf_root_obj != NULL)
1402 parent = lfsck_object_find_by_dev(env, lfsck->li_bottom,
1405 struct lfsck_tgt_desc *ltd;
1407 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
1408 if (unlikely(ltd == NULL))
1411 parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
1417 RETURN(PTR_ERR(parent));
1419 LASSERT(dt_object_exists(parent));
1421 if (unlikely(!dt_try_as_dir(env, parent))) {
1422 lfsck_object_put(env, parent);
1424 GOTO(put, rc = -ENOTDIR);
1427 lfsck->li_lpf_root_obj = parent;
1429 rc = lfsck_scan_lpf_bad_entries(env, lfsck);
1431 CDEBUG(D_LFSCK, "%s: scan .lustre/lost+found/ "
1432 "for bad sub-directories: rc = %d\n",
1433 lfsck_lfsck2name(lfsck), rc);
1437 snprintf(name, 8, "MDT%04x", node);
1438 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
1439 (const struct dt_key *)name);
1440 if (rc == -ENOENT) {
1448 /* Invalid FID in the name entry, remove the name entry. */
1449 if (!fid_is_norm(cfid)) {
1450 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1457 child2 = lfsck_object_find_bottom(env, lfsck, cfid);
1459 GOTO(put, rc = PTR_ERR(child2));
1461 if (unlikely(!dt_object_exists(child2) ||
1462 dt_object_remote(child2)) ||
1463 !S_ISDIR(lfsck_object_type(child2))) {
1464 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1471 if (unlikely(!dt_try_as_dir(env, child2))) {
1472 lfsck_object_put(env, child2);
1478 if (fid_is_zero(&bk->lb_lpf_fid))
1481 if (likely(lu_fid_eq(cfid, &bk->lb_lpf_fid))) {
1482 if (lfsck->li_lpf_obj == NULL) {
1483 lu_object_get(&child2->do_lu);
1484 lfsck->li_lpf_obj = child2;
1487 cname = lfsck_name_get_const(env, name, strlen(name));
1488 rc = lfsck_verify_linkea(env, child2, cname, &LU_LPF_FID);
1493 if (unlikely(!fid_is_norm(&bk->lb_lpf_fid))) {
1494 struct lu_fid tfid = bk->lb_lpf_fid;
1496 /* Invalid FID record in the bookmark file, reset it. */
1497 fid_zero(&bk->lb_lpf_fid);
1498 rc = lfsck_bookmark_store(env, lfsck);
1500 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1501 " in the bookmark file: rc = %d\n",
1502 lfsck_lfsck2name(lfsck), PFID(&tfid), rc);
1510 child1 = lfsck_object_find_bottom(env, lfsck, &bk->lb_lpf_fid);
1511 if (IS_ERR(child1)) {
1516 if (unlikely(!dt_object_exists(child1) ||
1517 dt_object_remote(child1)) ||
1518 !S_ISDIR(lfsck_object_type(child1))) {
1519 /* Invalid FID record in the bookmark file, reset it. */
1520 fid_zero(&bk->lb_lpf_fid);
1521 rc = lfsck_bookmark_store(env, lfsck);
1523 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1524 " in the bookmark file: rc = %d\n",
1525 lfsck_lfsck2name(lfsck),
1526 PFID(lfsck_dto2fid(child1)), rc);
1531 lfsck_object_put(env, child1);
1536 if (unlikely(!dt_try_as_dir(env, child1))) {
1537 lfsck_object_put(env, child1);
1543 rc = lfsck_verify_lpf_pairs(env, lfsck, child1, name, pfid,
1545 if (lu_fid_eq(pfid, &LU_LPF_FID))
1550 rc = lfsck_verify_lpf_pairs(env, lfsck, child2, name,
1551 pfid, LVLT_BY_NAMEENTRY);
1556 if (lfsck->li_lpf_obj != NULL) {
1557 if (unlikely(!dt_try_as_dir(env, lfsck->li_lpf_obj))) {
1558 lfsck_object_put(env, lfsck->li_lpf_obj);
1559 lfsck->li_lpf_obj = NULL;
1562 } else if (rc == 0) {
1563 rc = lfsck_create_lpf(env, lfsck);
1566 if (child2 != NULL && !IS_ERR(child2))
1567 lfsck_object_put(env, child2);
1568 if (child1 != NULL && !IS_ERR(child1))
1569 lfsck_object_put(env, child1);
1574 static int lfsck_fid_init(struct lfsck_instance *lfsck)
1576 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1577 struct seq_server_site *ss = lfsck_dev_site(lfsck);
1582 if (unlikely(ss == NULL))
1585 OBD_ALLOC_PTR(lfsck->li_seq);
1586 if (lfsck->li_seq == NULL)
1589 OBD_ALLOC(prefix, MAX_OBD_NAME + 7);
1591 GOTO(out, rc = -ENOMEM);
1593 snprintf(prefix, MAX_OBD_NAME + 7, "lfsck-%s", lfsck_lfsck2name(lfsck));
1594 rc = seq_client_init(lfsck->li_seq, NULL, LUSTRE_SEQ_METADATA, prefix,
1596 OBD_FREE(prefix, MAX_OBD_NAME + 7);
1600 if (fid_is_sane(&bk->lb_last_fid))
1601 lfsck->li_seq->lcs_fid = bk->lb_last_fid;
1606 OBD_FREE_PTR(lfsck->li_seq);
1607 lfsck->li_seq = NULL;
1612 static void lfsck_fid_fini(struct lfsck_instance *lfsck)
1614 if (lfsck->li_seq != NULL) {
1615 seq_client_fini(lfsck->li_seq);
1616 OBD_FREE_PTR(lfsck->li_seq);
1617 lfsck->li_seq = NULL;
1621 void lfsck_instance_cleanup(const struct lu_env *env,
1622 struct lfsck_instance *lfsck)
1624 struct ptlrpc_thread *thread = &lfsck->li_thread;
1625 struct lfsck_component *com;
1626 struct lfsck_component *next;
1627 struct lfsck_lmv_unit *llu;
1628 struct lfsck_lmv_unit *llu_next;
1629 struct lfsck_lmv *llmv;
1632 LASSERT(list_empty(&lfsck->li_link));
1633 LASSERT(thread_is_init(thread) || thread_is_stopped(thread));
1635 if (lfsck->li_obj_oit != NULL) {
1636 lfsck_object_put(env, lfsck->li_obj_oit);
1637 lfsck->li_obj_oit = NULL;
1640 LASSERT(lfsck->li_obj_dir == NULL);
1641 LASSERT(lfsck->li_lmv == NULL);
1643 list_for_each_entry_safe(llu, llu_next, &lfsck->li_list_lmv, llu_link) {
1644 llmv = &llu->llu_lmv;
1646 LASSERTF(atomic_read(&llmv->ll_ref) == 1,
1647 "still in using: %u\n",
1648 atomic_read(&llmv->ll_ref));
1650 lfsck_lmv_put(env, llmv);
1653 list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
1654 lfsck_component_cleanup(env, com);
1657 LASSERT(list_empty(&lfsck->li_list_dir));
1659 list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
1661 lfsck_component_cleanup(env, com);
1664 list_for_each_entry_safe(com, next, &lfsck->li_list_idle, lc_link) {
1665 lfsck_component_cleanup(env, com);
1668 lfsck_tgt_descs_fini(&lfsck->li_ost_descs);
1669 lfsck_tgt_descs_fini(&lfsck->li_mdt_descs);
1671 if (lfsck->li_lfsck_dir != NULL) {
1672 lfsck_object_put(env, lfsck->li_lfsck_dir);
1673 lfsck->li_lfsck_dir = NULL;
1676 if (lfsck->li_bookmark_obj != NULL) {
1677 lfsck_object_put(env, lfsck->li_bookmark_obj);
1678 lfsck->li_bookmark_obj = NULL;
1681 if (lfsck->li_lpf_obj != NULL) {
1682 lfsck_object_put(env, lfsck->li_lpf_obj);
1683 lfsck->li_lpf_obj = NULL;
1686 if (lfsck->li_lpf_root_obj != NULL) {
1687 lfsck_object_put(env, lfsck->li_lpf_root_obj);
1688 lfsck->li_lpf_root_obj = NULL;
1691 if (lfsck->li_los != NULL) {
1692 local_oid_storage_fini(env, lfsck->li_los);
1693 lfsck->li_los = NULL;
1696 lfsck_fid_fini(lfsck);
1698 OBD_FREE_PTR(lfsck);
1701 static inline struct lfsck_instance *
1702 __lfsck_instance_find(struct dt_device *key, bool ref, bool unlink)
1704 struct lfsck_instance *lfsck;
1706 list_for_each_entry(lfsck, &lfsck_instance_list, li_link) {
1707 if (lfsck->li_bottom == key) {
1709 lfsck_instance_get(lfsck);
1711 list_del_init(&lfsck->li_link);
1720 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
1723 struct lfsck_instance *lfsck;
1725 spin_lock(&lfsck_instance_lock);
1726 lfsck = __lfsck_instance_find(key, ref, unlink);
1727 spin_unlock(&lfsck_instance_lock);
1732 static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
1734 struct lfsck_instance *tmp;
1736 spin_lock(&lfsck_instance_lock);
1737 list_for_each_entry(tmp, &lfsck_instance_list, li_link) {
1738 if (lfsck->li_bottom == tmp->li_bottom) {
1739 spin_unlock(&lfsck_instance_lock);
1744 list_add_tail(&lfsck->li_link, &lfsck_instance_list);
1745 spin_unlock(&lfsck_instance_lock);
1749 void lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
1754 bool newline = (bits != 0 ? false : true);
1756 seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
1758 for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
1761 if (names[i] != NULL) {
1765 seq_printf(m, "%s%c", names[i],
1766 newline ? '\n' : ',');
1775 void lfsck_time_dump(struct seq_file *m, time64_t time, const char *name)
1778 seq_printf(m, "%s_time: N/A\n", name);
1779 seq_printf(m, "time_since_%s: N/A\n", name);
1781 seq_printf(m, "%s_time: %lld\n", name, time);
1782 seq_printf(m, "time_since_%s: %lld seconds\n",
1783 name, ktime_get_real_seconds() - time);
1787 void lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
1790 if (fid_is_zero(&pos->lp_dir_parent)) {
1791 if (pos->lp_oit_cookie == 0) {
1792 seq_printf(m, "%s: N/A, N/A, N/A\n", prefix);
1795 seq_printf(m, "%s: %llu, N/A, N/A\n",
1796 prefix, pos->lp_oit_cookie);
1798 seq_printf(m, "%s: %llu, "DFID", %#llx\n",
1799 prefix, pos->lp_oit_cookie,
1800 PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
1804 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
1805 struct lfsck_position *pos, bool init)
1807 const struct dt_it_ops *iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
1809 if (unlikely(lfsck->li_di_oit == NULL)) {
1810 memset(pos, 0, sizeof(*pos));
1814 pos->lp_oit_cookie = iops->store(env, lfsck->li_di_oit);
1815 if (!lfsck->li_current_oit_processed && !init)
1816 pos->lp_oit_cookie--;
1818 if (unlikely(pos->lp_oit_cookie == 0))
1819 pos->lp_oit_cookie = 1;
1821 if (lfsck->li_di_dir != NULL) {
1822 struct dt_object *dto = lfsck->li_obj_dir;
1824 pos->lp_dir_cookie = dto->do_index_ops->dio_it.store(env,
1827 if (pos->lp_dir_cookie >= MDS_DIR_END_OFF) {
1828 fid_zero(&pos->lp_dir_parent);
1829 pos->lp_dir_cookie = 0;
1831 pos->lp_dir_parent = *lfsck_dto2fid(dto);
1834 fid_zero(&pos->lp_dir_parent);
1835 pos->lp_dir_cookie = 0;
1839 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
1843 if (limit != LFSCK_SPEED_NO_LIMIT) {
1844 if (limit > cfs_time_seconds(1)) {
1845 lfsck->li_sleep_rate = limit / cfs_time_seconds(1);
1846 lfsck->li_sleep_jif = 1;
1848 lfsck->li_sleep_rate = 1;
1849 lfsck->li_sleep_jif = cfs_time_seconds(1) / limit;
1852 lfsck->li_sleep_jif = 0;
1853 lfsck->li_sleep_rate = 0;
1856 if (lfsck->li_bookmark_ram.lb_speed_limit != limit) {
1857 lfsck->li_bookmark_ram.lb_speed_limit = limit;
1864 void lfsck_control_speed(struct lfsck_instance *lfsck)
1866 struct ptlrpc_thread *thread = &lfsck->li_thread;
1867 struct l_wait_info lwi;
1869 if (lfsck->li_sleep_jif > 0 &&
1870 lfsck->li_new_scanned >= lfsck->li_sleep_rate) {
1871 lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
1872 LWI_ON_SIGNAL_NOOP, NULL);
1874 l_wait_event(thread->t_ctl_waitq,
1875 !thread_is_running(thread),
1877 lfsck->li_new_scanned = 0;
1881 void lfsck_control_speed_by_self(struct lfsck_component *com)
1883 struct lfsck_instance *lfsck = com->lc_lfsck;
1884 struct ptlrpc_thread *thread = &lfsck->li_thread;
1885 struct l_wait_info lwi;
1887 if (lfsck->li_sleep_jif > 0 &&
1888 com->lc_new_scanned >= lfsck->li_sleep_rate) {
1889 lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
1890 LWI_ON_SIGNAL_NOOP, NULL);
1892 l_wait_event(thread->t_ctl_waitq,
1893 !thread_is_running(thread),
1895 com->lc_new_scanned = 0;
1899 static struct lfsck_thread_args *
1900 lfsck_thread_args_init(struct lfsck_instance *lfsck,
1901 struct lfsck_component *com,
1902 struct lfsck_start_param *lsp)
1904 struct lfsck_thread_args *lta;
1909 return ERR_PTR(-ENOMEM);
1911 rc = lu_env_init(<a->lta_env, LCT_MD_THREAD | LCT_DT_THREAD);
1917 lta->lta_lfsck = lfsck_instance_get(lfsck);
1919 lta->lta_com = lfsck_component_get(com);
1926 void lfsck_thread_args_fini(struct lfsck_thread_args *lta)
1928 if (lta->lta_com != NULL)
1929 lfsck_component_put(<a->lta_env, lta->lta_com);
1930 lfsck_instance_put(<a->lta_env, lta->lta_lfsck);
1931 lu_env_fini(<a->lta_env);
1935 struct lfsck_assistant_data *
1936 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
1939 struct lfsck_assistant_data *lad;
1943 lad->lad_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
1944 if (lad->lad_bitmap == NULL) {
1949 INIT_LIST_HEAD(&lad->lad_req_list);
1950 spin_lock_init(&lad->lad_lock);
1951 INIT_LIST_HEAD(&lad->lad_ost_list);
1952 INIT_LIST_HEAD(&lad->lad_ost_phase1_list);
1953 INIT_LIST_HEAD(&lad->lad_ost_phase2_list);
1954 INIT_LIST_HEAD(&lad->lad_mdt_list);
1955 INIT_LIST_HEAD(&lad->lad_mdt_phase1_list);
1956 INIT_LIST_HEAD(&lad->lad_mdt_phase2_list);
1957 init_waitqueue_head(&lad->lad_thread.t_ctl_waitq);
1959 lad->lad_name = name;
1965 struct lfsck_assistant_object *
1966 lfsck_assistant_object_init(const struct lu_env *env, const struct lu_fid *fid,
1967 const struct lu_attr *attr, __u64 cookie,
1970 struct lfsck_assistant_object *lso;
1974 return ERR_PTR(-ENOMEM);
1976 lso->lso_fid = *fid;
1978 lso->lso_attr = *attr;
1980 atomic_set(&lso->lso_ref, 1);
1981 lso->lso_oit_cookie = cookie;
1983 lso->lso_is_dir = 1;
1989 lfsck_assistant_object_load(const struct lu_env *env,
1990 struct lfsck_instance *lfsck,
1991 struct lfsck_assistant_object *lso)
1993 struct dt_object *obj;
1995 obj = lfsck_object_find_bottom(env, lfsck, &lso->lso_fid);
1999 if (unlikely(!dt_object_exists(obj) || lfsck_is_dead_obj(obj))) {
2001 lfsck_object_put(env, obj);
2003 return ERR_PTR(-ENOENT);
2006 if (lso->lso_is_dir && unlikely(!dt_try_as_dir(env, obj))) {
2007 lfsck_object_put(env, obj);
2009 return ERR_PTR(-ENOTDIR);
2016 * Generic LFSCK asynchronous communication interpretor function.
2017 * The LFSCK RPC reply for both the event notification and status
2018 * querying will be handled here.
2020 * \param[in] env pointer to the thread context
2021 * \param[in] req pointer to the LFSCK request
2022 * \param[in] args pointer to the lfsck_async_interpret_args
2023 * \param[in] rc the result for handling the LFSCK request
2025 * \retval 0 for success
2026 * \retval negative error number on failure
2028 int lfsck_async_interpret_common(const struct lu_env *env,
2029 struct ptlrpc_request *req,
2032 struct lfsck_async_interpret_args *laia = args;
2033 struct lfsck_component *com = laia->laia_com;
2034 struct lfsck_assistant_data *lad = com->lc_data;
2035 struct lfsck_tgt_descs *ltds = laia->laia_ltds;
2036 struct lfsck_tgt_desc *ltd = laia->laia_ltd;
2037 struct lfsck_request *lr = laia->laia_lr;
2039 LASSERT(com->lc_lfsck->li_master);
2041 switch (lr->lr_event) {
2043 if (unlikely(rc == -EINPROGRESS)) {
2044 ltd->ltd_retry_start = 1;
2049 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s "
2051 lfsck_lfsck2name(com->lc_lfsck),
2052 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2053 ltd->ltd_index, lad->lad_name, rc);
2055 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2056 struct lfsck_layout *lo = com->lc_file_ram;
2058 if (lr->lr_flags & LEF_TO_OST)
2059 lfsck_lad_set_bitmap(env, com,
2062 lo->ll_flags |= LF_INCOMPLETE;
2064 struct lfsck_namespace *ns = com->lc_file_ram;
2066 /* If some MDT does not join the namespace
2067 * LFSCK, then we cannot know whether there
2068 * is some name entry on such MDT that with
2069 * the referenced MDT-object on this MDT or
2070 * not. So the namespace LFSCK on this MDT
2071 * cannot handle orphan MDT-objects properly.
2072 * So we mark the LFSCK as LF_INCOMPLETE and
2073 * skip orphan MDT-objects handling. */
2074 ns->ln_flags |= LF_INCOMPLETE;
2079 spin_lock(<ds->ltd_lock);
2080 if (ltd->ltd_dead) {
2081 spin_unlock(<ds->ltd_lock);
2085 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2086 struct list_head *list;
2087 struct list_head *phase_list;
2089 if (ltd->ltd_layout_done) {
2090 spin_unlock(<ds->ltd_lock);
2094 if (lr->lr_flags & LEF_TO_OST) {
2095 list = &lad->lad_ost_list;
2096 phase_list = &lad->lad_ost_phase1_list;
2098 list = &lad->lad_mdt_list;
2099 phase_list = &lad->lad_mdt_phase1_list;
2102 if (list_empty(<d->ltd_layout_list))
2103 list_add_tail(<d->ltd_layout_list, list);
2104 if (list_empty(<d->ltd_layout_phase_list))
2105 list_add_tail(<d->ltd_layout_phase_list,
2108 if (ltd->ltd_namespace_done) {
2109 spin_unlock(<ds->ltd_lock);
2113 if (list_empty(<d->ltd_namespace_list))
2114 list_add_tail(<d->ltd_namespace_list,
2115 &lad->lad_mdt_list);
2116 if (list_empty(<d->ltd_namespace_phase_list))
2117 list_add_tail(<d->ltd_namespace_phase_list,
2118 &lad->lad_mdt_phase1_list);
2120 spin_unlock(<ds->ltd_lock);
2123 case LE_PHASE1_DONE:
2124 case LE_PHASE2_DONE:
2126 if (rc != 0 && rc != -EALREADY)
2127 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s: "
2128 "event = %d, rc = %d\n",
2129 lfsck_lfsck2name(com->lc_lfsck),
2130 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2131 ltd->ltd_index, lad->lad_name, lr->lr_event, rc);
2134 struct lfsck_reply *reply;
2135 struct list_head *list;
2136 struct list_head *phase_list;
2138 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2139 list = <d->ltd_layout_list;
2140 phase_list = <d->ltd_layout_phase_list;
2142 list = <d->ltd_namespace_list;
2143 phase_list = <d->ltd_namespace_phase_list;
2147 if (lr->lr_flags & LEF_QUERY_ALL) {
2148 lfsck_reset_ltd_status(ltd, com->lc_type);
2152 spin_lock(<ds->ltd_lock);
2153 list_del_init(phase_list);
2154 list_del_init(list);
2155 spin_unlock(<ds->ltd_lock);
2159 reply = req_capsule_server_get(&req->rq_pill,
2161 if (reply == NULL) {
2163 CDEBUG(D_LFSCK, "%s: invalid query reply for %s: "
2164 "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck),
2167 if (lr->lr_flags & LEF_QUERY_ALL) {
2168 lfsck_reset_ltd_status(ltd, com->lc_type);
2172 spin_lock(<ds->ltd_lock);
2173 list_del_init(phase_list);
2174 list_del_init(list);
2175 spin_unlock(<ds->ltd_lock);
2179 if (lr->lr_flags & LEF_QUERY_ALL) {
2180 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2181 ltd->ltd_layout_status = reply->lr_status;
2182 ltd->ltd_layout_repaired = reply->lr_repaired;
2184 ltd->ltd_namespace_status = reply->lr_status;
2185 ltd->ltd_namespace_repaired =
2191 switch (reply->lr_status) {
2192 case LS_SCANNING_PHASE1:
2194 case LS_SCANNING_PHASE2:
2195 spin_lock(<ds->ltd_lock);
2196 list_del_init(phase_list);
2197 if (ltd->ltd_dead) {
2198 spin_unlock(<ds->ltd_lock);
2202 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2203 if (ltd->ltd_layout_done) {
2204 spin_unlock(<ds->ltd_lock);
2208 if (lr->lr_flags & LEF_TO_OST)
2209 list_add_tail(phase_list,
2210 &lad->lad_ost_phase2_list);
2212 list_add_tail(phase_list,
2213 &lad->lad_mdt_phase2_list);
2215 if (ltd->ltd_namespace_done) {
2216 spin_unlock(<ds->ltd_lock);
2220 list_add_tail(phase_list,
2221 &lad->lad_mdt_phase2_list);
2223 spin_unlock(<ds->ltd_lock);
2226 spin_lock(<ds->ltd_lock);
2227 list_del_init(phase_list);
2228 list_del_init(list);
2229 spin_unlock(<ds->ltd_lock);
2235 CDEBUG(D_LFSCK, "%s: unexpected event: rc = %d\n",
2236 lfsck_lfsck2name(com->lc_lfsck), lr->lr_event);
2240 if (!laia->laia_shared) {
2242 lfsck_component_put(env, com);
2248 static void lfsck_interpret(const struct lu_env *env,
2249 struct lfsck_instance *lfsck,
2250 struct ptlrpc_request *req, void *args, int result)
2252 struct lfsck_async_interpret_args *laia = args;
2253 struct lfsck_component *com;
2255 LASSERT(laia->laia_com == NULL);
2256 LASSERT(laia->laia_shared);
2258 spin_lock(&lfsck->li_lock);
2259 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
2260 laia->laia_com = com;
2261 lfsck_async_interpret_common(env, req, laia, result);
2264 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
2265 laia->laia_com = com;
2266 lfsck_async_interpret_common(env, req, laia, result);
2268 spin_unlock(&lfsck->li_lock);
2271 static int lfsck_stop_notify(const struct lu_env *env,
2272 struct lfsck_instance *lfsck,
2273 struct lfsck_tgt_descs *ltds,
2274 struct lfsck_tgt_desc *ltd, __u16 type)
2276 struct lfsck_component *com;
2280 LASSERT(lfsck->li_master);
2282 spin_lock(&lfsck->li_lock);
2283 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
2285 com = __lfsck_component_find(lfsck, type,
2286 &lfsck->li_list_double_scan);
2288 lfsck_component_get(com);
2289 spin_unlock(&lfsck->li_lock);
2292 struct lfsck_thread_info *info = lfsck_env_info(env);
2293 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2294 struct lfsck_request *lr = &info->lti_lr;
2295 struct lfsck_assistant_data *lad = com->lc_data;
2296 struct list_head *list;
2297 struct list_head *phase_list;
2298 struct ptlrpc_request_set *set;
2300 set = ptlrpc_prep_set();
2302 lfsck_component_put(env, com);
2307 if (type == LFSCK_TYPE_LAYOUT) {
2308 list = <d->ltd_layout_list;
2309 phase_list = <d->ltd_layout_phase_list;
2311 list = <d->ltd_namespace_list;
2312 phase_list = <d->ltd_namespace_phase_list;
2315 spin_lock(<ds->ltd_lock);
2316 if (list_empty(list)) {
2317 LASSERT(list_empty(phase_list));
2318 spin_unlock(<ds->ltd_lock);
2319 ptlrpc_set_destroy(set);
2324 list_del_init(phase_list);
2325 list_del_init(list);
2326 spin_unlock(<ds->ltd_lock);
2328 memset(lr, 0, sizeof(*lr));
2329 lr->lr_index = lfsck_dev_idx(lfsck);
2330 lr->lr_event = LE_PEER_EXIT;
2331 lr->lr_active = type;
2332 lr->lr_status = LS_CO_PAUSED;
2333 if (ltds == &lfsck->li_ost_descs)
2334 lr->lr_flags = LEF_TO_OST;
2336 memset(laia, 0, sizeof(*laia));
2337 laia->laia_com = com;
2338 laia->laia_ltds = ltds;
2339 atomic_inc(<d->ltd_ref);
2340 laia->laia_ltd = ltd;
2343 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2344 lfsck_async_interpret_common,
2345 laia, LFSCK_NOTIFY);
2347 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for "
2348 "co-stop for %s: rc = %d\n",
2349 lfsck_lfsck2name(lfsck),
2350 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2351 ltd->ltd_index, lad->lad_name, rc);
2354 rc = ptlrpc_set_wait(env, set);
2357 ptlrpc_set_destroy(set);
2358 lfsck_component_put(env, com);
2364 static int lfsck_async_interpret(const struct lu_env *env,
2365 struct ptlrpc_request *req,
2368 struct lfsck_async_interpret_args *laia = args;
2369 struct lfsck_instance *lfsck;
2371 lfsck = container_of0(laia->laia_ltds, struct lfsck_instance,
2373 lfsck_interpret(env, lfsck, req, laia, rc);
2374 lfsck_tgt_put(laia->laia_ltd);
2375 if (rc != 0 && laia->laia_result != -EALREADY)
2376 laia->laia_result = rc;
2381 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
2382 struct lfsck_request *lr,
2383 struct ptlrpc_request_set *set,
2384 ptlrpc_interpterer_t interpreter,
2385 void *args, int request)
2387 struct lfsck_async_interpret_args *laia;
2388 struct ptlrpc_request *req;
2389 struct lfsck_request *tmp;
2390 struct req_format *format;
2395 format = &RQF_LFSCK_NOTIFY;
2398 format = &RQF_LFSCK_QUERY;
2401 CDEBUG(D_LFSCK, "%s: unknown async request %d: rc = %d\n",
2402 exp->exp_obd->obd_name, request, -EINVAL);
2406 req = ptlrpc_request_alloc(class_exp2cliimp(exp), format);
2410 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, request);
2412 ptlrpc_request_free(req);
2417 tmp = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
2419 ptlrpc_request_set_replen(req);
2421 laia = ptlrpc_req_async_args(req);
2422 *laia = *(struct lfsck_async_interpret_args *)args;
2423 if (laia->laia_com != NULL)
2424 lfsck_component_get(laia->laia_com);
2425 req->rq_interpret_reply = interpreter;
2426 req->rq_allow_intr = 1;
2427 req->rq_no_delay = 1;
2428 ptlrpc_set_add_req(set, req);
2433 int lfsck_query_all(const struct lu_env *env, struct lfsck_component *com)
2435 struct lfsck_thread_info *info = lfsck_env_info(env);
2436 struct lfsck_request *lr = &info->lti_lr;
2437 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2438 struct lfsck_instance *lfsck = com->lc_lfsck;
2439 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2440 struct lfsck_tgt_desc *ltd;
2441 struct ptlrpc_request_set *set;
2446 memset(lr, 0, sizeof(*lr));
2447 lr->lr_event = LE_QUERY;
2448 lr->lr_active = com->lc_type;
2449 lr->lr_flags = LEF_QUERY_ALL;
2451 memset(laia, 0, sizeof(*laia));
2452 laia->laia_com = com;
2455 set = ptlrpc_prep_set();
2460 laia->laia_ltds = ltds;
2461 down_read(<ds->ltd_rw_sem);
2462 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2463 ltd = lfsck_tgt_get(ltds, idx);
2464 LASSERT(ltd != NULL);
2466 laia->laia_ltd = ltd;
2467 up_read(<ds->ltd_rw_sem);
2468 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2469 lfsck_async_interpret_common,
2472 struct lfsck_assistant_data *lad = com->lc_data;
2474 CDEBUG(D_LFSCK, "%s: Fail to query %s %x for stat %s: "
2475 "rc = %d\n", lfsck_lfsck2name(lfsck),
2476 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2477 ltd->ltd_index, lad->lad_name, rc);
2478 lfsck_reset_ltd_status(ltd, com->lc_type);
2481 down_read(<ds->ltd_rw_sem);
2483 up_read(<ds->ltd_rw_sem);
2485 if (com->lc_type == LFSCK_TYPE_LAYOUT && !(lr->lr_flags & LEF_TO_OST)) {
2486 ltds = &lfsck->li_ost_descs;
2487 lr->lr_flags |= LEF_TO_OST;
2491 rc = ptlrpc_set_wait(env, set);
2492 ptlrpc_set_destroy(set);
2497 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
2498 struct lfsck_start_param *lsp)
2500 struct lfsck_instance *lfsck = com->lc_lfsck;
2501 struct lfsck_assistant_data *lad = com->lc_data;
2502 struct ptlrpc_thread *mthread = &lfsck->li_thread;
2503 struct ptlrpc_thread *athread = &lad->lad_thread;
2504 struct lfsck_thread_args *lta;
2505 struct task_struct *task;
2509 lad->lad_assistant_status = 0;
2510 lad->lad_post_result = 0;
2512 lad->lad_advance_lock = false;
2513 thread_set_flags(athread, 0);
2515 lta = lfsck_thread_args_init(lfsck, com, lsp);
2517 RETURN(PTR_ERR(lta));
2519 task = kthread_run(lfsck_assistant_engine, lta, lad->lad_name);
2522 CERROR("%s: cannot start LFSCK assistant thread for %s: "
2523 "rc = %d\n", lfsck_lfsck2name(lfsck), lad->lad_name, rc);
2524 lfsck_thread_args_fini(lta);
2526 struct l_wait_info lwi = { 0 };
2528 l_wait_event(mthread->t_ctl_waitq,
2529 thread_is_running(athread) ||
2530 thread_is_stopped(athread) ||
2531 !thread_is_starting(mthread),
2533 if (unlikely(!thread_is_starting(mthread)))
2534 /* stopped by race */
2536 else if (unlikely(!thread_is_running(athread)))
2537 rc = lad->lad_assistant_status;
2545 int lfsck_checkpoint_generic(const struct lu_env *env,
2546 struct lfsck_component *com)
2548 struct lfsck_assistant_data *lad = com->lc_data;
2549 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2550 struct ptlrpc_thread *athread = &lad->lad_thread;
2551 struct l_wait_info lwi = { 0 };
2553 l_wait_event(mthread->t_ctl_waitq,
2554 list_empty(&lad->lad_req_list) ||
2555 !thread_is_running(mthread) ||
2556 thread_is_stopped(athread),
2559 if (!thread_is_running(mthread) || thread_is_stopped(athread))
2560 return LFSCK_CHECKPOINT_SKIP;
2565 void lfsck_post_generic(const struct lu_env *env,
2566 struct lfsck_component *com, int *result)
2568 struct lfsck_assistant_data *lad = com->lc_data;
2569 struct ptlrpc_thread *athread = &lad->lad_thread;
2570 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2571 struct l_wait_info lwi = { 0 };
2573 lad->lad_post_result = *result;
2575 set_bit(LAD_EXIT, &lad->lad_flags);
2576 set_bit(LAD_TO_POST, &lad->lad_flags);
2578 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s post, rc = %d\n",
2579 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2581 wake_up_all(&athread->t_ctl_waitq);
2582 l_wait_event(mthread->t_ctl_waitq,
2583 (*result > 0 && list_empty(&lad->lad_req_list)) ||
2584 thread_is_stopped(athread),
2587 if (lad->lad_assistant_status < 0)
2588 *result = lad->lad_assistant_status;
2590 CDEBUG(D_LFSCK, "%s: the assistant has done %s post, rc = %d\n",
2591 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2594 int lfsck_double_scan_generic(const struct lu_env *env,
2595 struct lfsck_component *com, int status)
2597 struct lfsck_assistant_data *lad = com->lc_data;
2598 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2599 struct ptlrpc_thread *athread = &lad->lad_thread;
2600 struct l_wait_info lwi = { 0 };
2602 if (status != LS_SCANNING_PHASE2)
2603 set_bit(LAD_EXIT, &lad->lad_flags);
2605 set_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags);
2607 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s double_scan, "
2609 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, status);
2611 wake_up_all(&athread->t_ctl_waitq);
2612 l_wait_event(mthread->t_ctl_waitq,
2613 test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags) ||
2614 thread_is_stopped(athread),
2617 CDEBUG(D_LFSCK, "%s: the assistant has done %s double_scan, "
2618 "status %d\n", lfsck_lfsck2name(com->lc_lfsck), lad->lad_name,
2619 lad->lad_assistant_status);
2621 if (lad->lad_assistant_status < 0)
2622 return lad->lad_assistant_status;
2627 void lfsck_quit_generic(const struct lu_env *env,
2628 struct lfsck_component *com)
2630 struct lfsck_assistant_data *lad = com->lc_data;
2631 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2632 struct ptlrpc_thread *athread = &lad->lad_thread;
2633 struct l_wait_info lwi = { 0 };
2635 set_bit(LAD_EXIT, &lad->lad_flags);
2636 wake_up_all(&athread->t_ctl_waitq);
2637 l_wait_event(mthread->t_ctl_waitq,
2638 thread_is_init(athread) ||
2639 thread_is_stopped(athread),
2643 int lfsck_load_one_trace_file(const struct lu_env *env,
2644 struct lfsck_component *com,
2645 struct dt_object *parent,
2646 struct dt_object **child,
2647 const struct dt_index_features *ft,
2648 const char *name, bool reset)
2650 struct lfsck_instance *lfsck = com->lc_lfsck;
2651 struct dt_object *obj;
2655 if (*child != NULL) {
2657 const struct dt_it_ops *iops;
2658 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid3;
2664 rc = obj->do_ops->do_index_try(env, obj, ft);
2666 /* unlink by force */
2669 iops = &obj->do_index_ops->dio_it;
2670 it = iops->init(env, obj, 0);
2672 /* unlink by force */
2676 rc = iops->get(env, it, (const struct dt_key *)fid);
2678 rc = iops->next(env, it);
2681 iops->fini(env, it);
2683 /* "rc > 0" means the index file is empty. */
2687 /* The old index is not empty, remove it firstly. */
2688 rc = local_object_unlink(env, lfsck->li_bottom, parent, name);
2689 CDEBUG_LIMIT(rc ? D_ERROR : D_LFSCK,
2690 "%s: unlink lfsck sub trace file %s: rc = %d\n",
2691 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2696 lfsck_object_put(env, *child);
2703 obj = local_index_find_or_create(env, lfsck->li_los, parent, name,
2704 S_IFREG | S_IRUGO | S_IWUSR, ft);
2706 RETURN(PTR_ERR(obj));
2708 rc = obj->do_ops->do_index_try(env, obj, ft);
2710 lfsck_object_put(env, obj);
2711 CDEBUG(D_LFSCK, "%s: LFSCK fail to load "
2712 "sub trace file %s: rc = %d\n",
2713 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2721 int lfsck_load_sub_trace_files(const struct lu_env *env,
2722 struct lfsck_component *com,
2723 const struct dt_index_features *ft,
2724 const char *prefix, bool reset)
2726 char *name = lfsck_env_info(env)->lti_key;
2727 struct lfsck_sub_trace_obj *lsto;
2731 for (i = 0, rc = 0, lsto = &com->lc_sub_trace_objs[0];
2732 i < LFSCK_STF_COUNT && rc == 0; i++, lsto++) {
2733 snprintf(name, NAME_MAX, "%s_%02d", prefix, i);
2734 rc = lfsck_load_one_trace_file(env, com,
2735 com->lc_lfsck->li_lfsck_dir,
2736 &lsto->lsto_obj, ft, name, reset);
2742 /* external interfaces */
2743 int lfsck_get_speed(char *buf, struct dt_device *key)
2746 struct lfsck_instance *lfsck;
2750 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2754 lfsck = lfsck_instance_find(key, true, false);
2756 rc = sprintf(buf, "%u\n",
2757 lfsck->li_bookmark_ram.lb_speed_limit);
2758 lfsck_instance_put(&env, lfsck);
2767 EXPORT_SYMBOL(lfsck_get_speed);
2769 int lfsck_set_speed(struct dt_device *key, __u32 val)
2772 struct lfsck_instance *lfsck;
2776 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2780 lfsck = lfsck_instance_find(key, true, false);
2781 if (likely(lfsck != NULL)) {
2782 mutex_lock(&lfsck->li_mutex);
2783 if (__lfsck_set_speed(lfsck, val))
2784 rc = lfsck_bookmark_store(&env, lfsck);
2785 mutex_unlock(&lfsck->li_mutex);
2786 lfsck_instance_put(&env, lfsck);
2795 EXPORT_SYMBOL(lfsck_set_speed);
2797 int lfsck_get_windows(char *buf, struct dt_device *key)
2800 struct lfsck_instance *lfsck;
2804 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2808 lfsck = lfsck_instance_find(key, true, false);
2809 if (likely(lfsck != NULL)) {
2810 rc = sprintf(buf, "%u\n",
2811 lfsck->li_bookmark_ram.lb_async_windows);
2812 lfsck_instance_put(&env, lfsck);
2821 EXPORT_SYMBOL(lfsck_get_windows);
2823 int lfsck_set_windows(struct dt_device *key, unsigned int val)
2826 struct lfsck_instance *lfsck;
2830 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2834 lfsck = lfsck_instance_find(key, true, false);
2835 if (likely(lfsck != NULL)) {
2836 if (val < 1 || val > LFSCK_ASYNC_WIN_MAX) {
2837 CWARN("%s: invalid async windows size that may "
2838 "cause memory issues. The valid range is "
2840 lfsck_lfsck2name(lfsck), LFSCK_ASYNC_WIN_MAX);
2842 } else if (lfsck->li_bookmark_ram.lb_async_windows != val) {
2843 mutex_lock(&lfsck->li_mutex);
2844 lfsck->li_bookmark_ram.lb_async_windows = val;
2845 rc = lfsck_bookmark_store(&env, lfsck);
2846 mutex_unlock(&lfsck->li_mutex);
2848 lfsck_instance_put(&env, lfsck);
2857 EXPORT_SYMBOL(lfsck_set_windows);
2859 int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
2862 struct lfsck_instance *lfsck;
2863 struct lfsck_component *com;
2867 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2871 lfsck = lfsck_instance_find(key, true, false);
2872 if (likely(lfsck != NULL)) {
2873 com = lfsck_component_find(lfsck, type);
2874 if (likely(com != NULL)) {
2875 com->lc_ops->lfsck_dump(&env, com, m);
2876 lfsck_component_put(&env, com);
2881 lfsck_instance_put(&env, lfsck);
2890 EXPORT_SYMBOL(lfsck_dump);
2892 static int lfsck_stop_all(const struct lu_env *env,
2893 struct lfsck_instance *lfsck,
2894 struct lfsck_stop *stop)
2896 struct lfsck_thread_info *info = lfsck_env_info(env);
2897 struct lfsck_request *lr = &info->lti_lr;
2898 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2899 struct ptlrpc_request_set *set;
2900 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2901 struct lfsck_tgt_desc *ltd;
2902 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2908 LASSERT(stop->ls_flags & LPF_BROADCAST);
2910 set = ptlrpc_prep_set();
2911 if (unlikely(set == NULL))
2914 memset(lr, 0, sizeof(*lr));
2915 lr->lr_event = LE_STOP;
2916 lr->lr_index = lfsck_dev_idx(lfsck);
2917 lr->lr_status = stop->ls_status;
2918 lr->lr_version = bk->lb_version;
2919 lr->lr_active = LFSCK_TYPES_ALL;
2920 lr->lr_param = stop->ls_flags;
2922 memset(laia, 0, sizeof(*laia));
2923 laia->laia_ltds = ltds;
2925 laia->laia_shared = 1;
2927 down_read(<ds->ltd_rw_sem);
2928 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2929 ltd = lfsck_tgt_get(ltds, idx);
2930 LASSERT(ltd != NULL);
2932 laia->laia_ltd = ltd;
2933 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2934 lfsck_async_interpret, laia,
2937 lfsck_interpret(env, lfsck, NULL, laia, rc);
2939 CERROR("%s: cannot notify MDT %x for LFSCK stop: "
2940 "rc = %d\n", lfsck_lfsck2name(lfsck), idx, rc);
2944 up_read(<ds->ltd_rw_sem);
2946 rc = ptlrpc_set_wait(env, set);
2947 ptlrpc_set_destroy(set);
2950 rc = laia->laia_result;
2952 if (rc == -EALREADY)
2956 CERROR("%s: fail to stop LFSCK on some MDTs: rc = %d\n",
2957 lfsck_lfsck2name(lfsck), rc);
2959 RETURN(rc != 0 ? rc : rc1);
2962 static int lfsck_start_all(const struct lu_env *env,
2963 struct lfsck_instance *lfsck,
2964 struct lfsck_start *start)
2966 struct lfsck_thread_info *info = lfsck_env_info(env);
2967 struct lfsck_request *lr = &info->lti_lr;
2968 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2969 struct ptlrpc_request_set *set;
2970 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2971 struct lfsck_tgt_desc *ltd;
2972 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2978 LASSERT(start->ls_flags & LPF_BROADCAST);
2980 memset(lr, 0, sizeof(*lr));
2981 lr->lr_event = LE_START;
2982 lr->lr_index = lfsck_dev_idx(lfsck);
2983 lr->lr_speed = bk->lb_speed_limit;
2984 lr->lr_version = bk->lb_version;
2985 lr->lr_active = start->ls_active;
2986 lr->lr_param = start->ls_flags;
2987 lr->lr_async_windows = bk->lb_async_windows;
2988 lr->lr_valid = LSV_SPEED_LIMIT | LSV_ERROR_HANDLE | LSV_DRYRUN |
2989 LSV_ASYNC_WINDOWS | LSV_CREATE_OSTOBJ |
2992 memset(laia, 0, sizeof(*laia));
2993 laia->laia_ltds = ltds;
2995 laia->laia_shared = 1;
2998 set = ptlrpc_prep_set();
3002 down_read(<ds->ltd_rw_sem);
3003 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3004 ltd = lfsck_tgt_get(ltds, idx);
3005 LASSERT(ltd != NULL);
3007 if (retry && !ltd->ltd_retry_start) {
3012 laia->laia_ltd = ltd;
3013 ltd->ltd_retry_start = 0;
3014 ltd->ltd_layout_done = 0;
3015 ltd->ltd_namespace_done = 0;
3016 ltd->ltd_synced_failures = 0;
3017 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
3018 lfsck_async_interpret, laia,
3021 lfsck_interpret(env, lfsck, NULL, laia, rc);
3023 CERROR("%s: cannot notify MDT %x for LFSCK "
3024 "start, failout: rc = %d\n",
3025 lfsck_lfsck2name(lfsck), idx, rc);
3029 up_read(<ds->ltd_rw_sem);
3032 ptlrpc_set_destroy(set);
3037 rc = ptlrpc_set_wait(env, set);
3038 ptlrpc_set_destroy(set);
3041 rc = laia->laia_result;
3043 if (unlikely(rc == -EINPROGRESS)) {
3045 set_current_state(TASK_INTERRUPTIBLE);
3046 schedule_timeout(cfs_time_seconds(1));
3047 set_current_state(TASK_RUNNING);
3048 if (!signal_pending(current) &&
3049 thread_is_running(&lfsck->li_thread))
3056 struct lfsck_stop *stop = &info->lti_stop;
3058 CERROR("%s: cannot start LFSCK on some MDTs, "
3059 "stop all: rc = %d\n",
3060 lfsck_lfsck2name(lfsck), rc);
3061 if (rc != -EALREADY) {
3062 stop->ls_status = LS_FAILED;
3063 stop->ls_flags = LPF_ALL_TGT | LPF_BROADCAST;
3064 lfsck_stop_all(env, lfsck, stop);
3071 int lfsck_start(const struct lu_env *env, struct dt_device *key,
3072 struct lfsck_start_param *lsp)
3074 struct lfsck_start *start = lsp->lsp_start;
3075 struct lfsck_instance *lfsck;
3076 struct lfsck_bookmark *bk;
3077 struct ptlrpc_thread *thread;
3078 struct lfsck_component *com;
3079 struct l_wait_info lwi = { 0 };
3080 struct lfsck_thread_args *lta;
3081 struct task_struct *task;
3082 struct lfsck_tgt_descs *ltds;
3083 struct lfsck_tgt_desc *ltd;
3094 lfsck = lfsck_instance_find(key, true, false);
3095 if (unlikely(lfsck == NULL))
3098 if (unlikely(lfsck->li_stopping))
3099 GOTO(put, rc = -ENXIO);
3101 /* System is not ready, try again later. */
3102 if (unlikely(lfsck->li_namespace == NULL ||
3103 lfsck_dev_site(lfsck)->ss_server_fld == NULL))
3104 GOTO(put, rc = -EINPROGRESS);
3106 /* start == NULL means auto trigger paused LFSCK. */
3108 if (list_empty(&lfsck->li_list_scan) ||
3109 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AUTO))
3111 } else if (start->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3112 CERROR("%s: only allow to specify '-A | -o' via MDS\n",
3113 lfsck_lfsck2name(lfsck));
3115 GOTO(put, rc = -EPERM);
3118 bk = &lfsck->li_bookmark_ram;
3119 thread = &lfsck->li_thread;
3120 mutex_lock(&lfsck->li_mutex);
3121 spin_lock(&lfsck->li_lock);
3122 if (unlikely(thread_is_stopping(thread))) {
3123 /* Someone is stopping the LFSCK. */
3124 spin_unlock(&lfsck->li_lock);
3125 GOTO(out, rc = -EBUSY);
3128 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
3130 if (unlikely(start == NULL)) {
3131 spin_unlock(&lfsck->li_lock);
3135 while (start->ls_active != 0) {
3136 if (!(type & start->ls_active)) {
3141 com = __lfsck_component_find(lfsck, type,
3142 &lfsck->li_list_scan);
3144 com = __lfsck_component_find(lfsck, type,
3145 &lfsck->li_list_double_scan);
3151 if (com->lc_ops->lfsck_join != NULL) {
3152 rc = com->lc_ops->lfsck_join( env, com, lsp);
3153 if (rc != 0 && rc != -EALREADY)
3156 start->ls_active &= ~type;
3159 spin_unlock(&lfsck->li_lock);
3162 spin_unlock(&lfsck->li_lock);
3164 lfsck->li_status = 0;
3165 lfsck->li_oit_over = 0;
3166 lfsck->li_start_unplug = 0;
3167 lfsck->li_drop_dryrun = 0;
3168 lfsck->li_new_scanned = 0;
3170 /* For auto trigger. */
3174 start->ls_version = bk->lb_version;
3176 if (start->ls_active != 0) {
3177 struct lfsck_component *next;
3179 if (start->ls_active == LFSCK_TYPES_ALL)
3180 start->ls_active = LFSCK_TYPES_SUPPORTED;
3182 if (start->ls_active & ~LFSCK_TYPES_SUPPORTED) {
3183 start->ls_active &= ~LFSCK_TYPES_SUPPORTED;
3184 GOTO(out, rc = -ENOTSUPP);
3187 list_for_each_entry_safe(com, next,
3188 &lfsck->li_list_scan, lc_link) {
3189 if (!(com->lc_type & start->ls_active)) {
3190 rc = com->lc_ops->lfsck_post(env, com, 0,
3197 while (start->ls_active != 0) {
3198 if (type & start->ls_active) {
3199 com = __lfsck_component_find(lfsck, type,
3200 &lfsck->li_list_idle);
3202 /* The component status will be updated
3203 * when its prep() is called later by
3204 * the LFSCK main engine. */
3205 list_move_tail(&com->lc_link,
3206 &lfsck->li_list_scan);
3207 start->ls_active &= ~type;
3213 if (list_empty(&lfsck->li_list_scan)) {
3214 /* The speed limit will be used to control both the LFSCK and
3215 * low layer scrub (if applied), need to be handled firstly. */
3216 if (start->ls_valid & LSV_SPEED_LIMIT) {
3217 if (__lfsck_set_speed(lfsck, start->ls_speed_limit)) {
3218 rc = lfsck_bookmark_store(env, lfsck);
3227 if (start->ls_flags & LPF_RESET)
3228 flags |= DOIF_RESET;
3230 rc = lfsck_set_param(env, lfsck, start, !!(flags & DOIF_RESET));
3234 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3235 start->ls_active |= com->lc_type;
3236 if (flags & DOIF_RESET) {
3237 rc = com->lc_ops->lfsck_reset(env, com, false);
3243 ltds = &lfsck->li_mdt_descs;
3244 down_read(<ds->ltd_rw_sem);
3245 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3246 ltd = lfsck_ltd2tgt(ltds, idx);
3247 LASSERT(ltd != NULL);
3249 ltd->ltd_layout_done = 0;
3250 ltd->ltd_namespace_done = 0;
3251 ltd->ltd_synced_failures = 0;
3252 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_NAMESPACE);
3253 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3254 list_del_init(<d->ltd_layout_phase_list);
3255 list_del_init(<d->ltd_layout_list);
3256 list_del_init(<d->ltd_namespace_phase_list);
3257 list_del_init(<d->ltd_namespace_list);
3259 up_read(<ds->ltd_rw_sem);
3261 ltds = &lfsck->li_ost_descs;
3262 down_read(<ds->ltd_rw_sem);
3263 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3264 ltd = lfsck_ltd2tgt(ltds, idx);
3265 LASSERT(ltd != NULL);
3267 ltd->ltd_layout_done = 0;
3268 ltd->ltd_synced_failures = 0;
3269 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3270 list_del_init(<d->ltd_layout_phase_list);
3271 list_del_init(<d->ltd_layout_list);
3273 up_read(<ds->ltd_rw_sem);
3276 lfsck->li_args_dir = LUDA_64BITHASH | LUDA_VERIFY | LUDA_TYPE;
3277 if (bk->lb_param & LPF_DRYRUN)
3278 lfsck->li_args_dir |= LUDA_VERIFY_DRYRUN;
3280 if (start != NULL && start->ls_valid & LSV_ERROR_HANDLE) {
3281 valid |= DOIV_ERROR_HANDLE;
3282 if (start->ls_flags & LPF_FAILOUT)
3283 flags |= DOIF_FAILOUT;
3286 if (start != NULL && start->ls_valid & LSV_DRYRUN) {
3287 valid |= DOIV_DRYRUN;
3288 if (start->ls_flags & LPF_DRYRUN)
3289 flags |= DOIF_DRYRUN;
3292 if (!list_empty(&lfsck->li_list_scan))
3293 flags |= DOIF_OUTUSED;
3295 lfsck->li_args_oit = (flags << DT_OTABLE_IT_FLAGS_SHIFT) | valid;
3296 lta = lfsck_thread_args_init(lfsck, NULL, lsp);
3298 GOTO(out, rc = PTR_ERR(lta));
3300 __lfsck_set_speed(lfsck, bk->lb_speed_limit);
3301 spin_lock(&lfsck->li_lock);
3302 thread_set_flags(thread, SVC_STARTING);
3303 spin_unlock(&lfsck->li_lock);
3304 task = kthread_run(lfsck_master_engine, lta, "lfsck");
3307 CERROR("%s: cannot start LFSCK thread: rc = %d\n",
3308 lfsck_lfsck2name(lfsck), rc);
3309 lfsck_thread_args_fini(lta);
3314 l_wait_event(thread->t_ctl_waitq,
3315 thread_is_running(thread) ||
3316 thread_is_stopped(thread),
3318 if (start == NULL || !(start->ls_flags & LPF_BROADCAST)) {
3319 lfsck->li_start_unplug = 1;
3320 wake_up_all(&thread->t_ctl_waitq);
3325 /* release lfsck::li_mutex to avoid deadlock. */
3326 mutex_unlock(&lfsck->li_mutex);
3327 rc = lfsck_start_all(env, lfsck, start);
3329 spin_lock(&lfsck->li_lock);
3330 if (thread_is_stopped(thread)) {
3331 spin_unlock(&lfsck->li_lock);
3333 lfsck->li_status = LS_FAILED;
3334 lfsck->li_flags = 0;
3335 thread_set_flags(thread, SVC_STOPPING);
3336 spin_unlock(&lfsck->li_lock);
3338 lfsck->li_start_unplug = 1;
3339 wake_up_all(&thread->t_ctl_waitq);
3340 l_wait_event(thread->t_ctl_waitq,
3341 thread_is_stopped(thread),
3345 lfsck->li_start_unplug = 1;
3346 wake_up_all(&thread->t_ctl_waitq);
3352 mutex_unlock(&lfsck->li_mutex);
3355 lfsck_instance_put(env, lfsck);
3357 return rc < 0 ? rc : 0;
3359 EXPORT_SYMBOL(lfsck_start);
3361 int lfsck_stop(const struct lu_env *env, struct dt_device *key,
3362 struct lfsck_stop *stop)
3364 struct lfsck_instance *lfsck;
3365 struct ptlrpc_thread *thread;
3366 struct l_wait_info lwi = { 0 };
3371 lfsck = lfsck_instance_find(key, true, false);
3372 if (unlikely(lfsck == NULL))
3375 thread = &lfsck->li_thread;
3376 if (stop && stop->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3377 CERROR("%s: only allow to specify '-A' via MDS\n",
3378 lfsck_lfsck2name(lfsck));
3379 GOTO(put, rc = -EPERM);
3382 spin_lock(&lfsck->li_lock);
3383 /* The target is umounted */
3384 if (stop && stop->ls_status == LS_PAUSED)
3385 lfsck->li_stopping = 1;
3387 if (thread_is_init(thread) || thread_is_stopped(thread))
3388 /* no error if LFSCK stopped already, or not started */
3389 GOTO(unlock, rc = 0);
3391 if (thread_is_stopping(thread))
3392 /* Someone is stopping LFSCK. */
3393 GOTO(unlock, rc = -EINPROGRESS);
3396 lfsck->li_status = stop->ls_status;
3397 lfsck->li_flags = stop->ls_flags;
3399 lfsck->li_status = LS_STOPPED;
3400 lfsck->li_flags = 0;
3403 thread_set_flags(thread, SVC_STOPPING);
3405 LASSERT(lfsck->li_task != NULL);
3406 force_sig(SIGINT, lfsck->li_task);
3408 if (lfsck->li_master) {
3409 struct lfsck_component *com;
3410 struct lfsck_assistant_data *lad;
3412 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3414 spin_lock(&lad->lad_lock);
3415 if (lad->lad_task != NULL)
3416 force_sig(SIGINT, lad->lad_task);
3417 spin_unlock(&lad->lad_lock);
3420 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
3422 spin_lock(&lad->lad_lock);
3423 if (lad->lad_task != NULL)
3424 force_sig(SIGINT, lad->lad_task);
3425 spin_unlock(&lad->lad_lock);
3429 wake_up_all(&thread->t_ctl_waitq);
3430 spin_unlock(&lfsck->li_lock);
3431 if (stop && stop->ls_flags & LPF_BROADCAST)
3432 rc1 = lfsck_stop_all(env, lfsck, stop);
3434 /* It was me set the status as 'stopping' just now, if it is not
3435 * 'stopping' now, then either stopped, or re-started by race. */
3436 l_wait_event(thread->t_ctl_waitq,
3437 !thread_is_stopping(thread),
3443 spin_unlock(&lfsck->li_lock);
3445 lfsck_instance_put(env, lfsck);
3447 return rc != 0 ? rc : rc1;
3449 EXPORT_SYMBOL(lfsck_stop);
3451 int lfsck_in_notify_local(const struct lu_env *env, struct dt_device *key,
3452 struct lfsck_req_local *lrl, struct thandle *th)
3454 struct lfsck_instance *lfsck;
3455 struct lfsck_component *com;
3456 int rc = -EOPNOTSUPP;
3459 lfsck = lfsck_instance_find(key, true, false);
3460 if (unlikely(!lfsck))
3463 com = lfsck_component_find(lfsck, lrl->lrl_active);
3464 if (likely(com && com->lc_ops->lfsck_in_notify_local)) {
3465 rc = com->lc_ops->lfsck_in_notify_local(env, com, lrl, th);
3466 lfsck_component_put(env, com);
3469 lfsck_instance_put(env, lfsck);
3473 EXPORT_SYMBOL(lfsck_in_notify_local);
3475 int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
3476 struct lfsck_request *lr)
3478 int rc = -EOPNOTSUPP;
3481 switch (lr->lr_event) {
3483 struct lfsck_start *start = &lfsck_env_info(env)->lti_start;
3484 struct lfsck_start_param lsp;
3486 memset(start, 0, sizeof(*start));
3487 start->ls_valid = lr->lr_valid;
3488 start->ls_speed_limit = lr->lr_speed;
3489 start->ls_version = lr->lr_version;
3490 start->ls_active = lr->lr_active;
3491 start->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3492 start->ls_async_windows = lr->lr_async_windows;
3494 lsp.lsp_start = start;
3495 lsp.lsp_index = lr->lr_index;
3496 lsp.lsp_index_valid = 1;
3497 rc = lfsck_start(env, key, &lsp);
3501 struct lfsck_stop *stop = &lfsck_env_info(env)->lti_stop;
3503 memset(stop, 0, sizeof(*stop));
3504 stop->ls_status = lr->lr_status;
3505 stop->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3506 rc = lfsck_stop(env, key, stop);
3509 case LE_PHASE1_DONE:
3510 case LE_PHASE2_DONE:
3512 case LE_CONDITIONAL_DESTROY:
3513 case LE_SET_LMV_MASTER:
3514 case LE_SET_LMV_SLAVE:
3515 case LE_PAIRS_VERIFY: {
3516 struct lfsck_instance *lfsck;
3517 struct lfsck_component *com;
3519 lfsck = lfsck_instance_find(key, true, false);
3520 if (unlikely(lfsck == NULL))
3523 com = lfsck_component_find(lfsck, lr->lr_active);
3525 rc = com->lc_ops->lfsck_in_notify(env, com, lr);
3526 lfsck_component_put(env, com);
3529 lfsck_instance_put(env, lfsck);
3538 EXPORT_SYMBOL(lfsck_in_notify);
3540 int lfsck_query(const struct lu_env *env, struct dt_device *key,
3541 struct lfsck_request *req, struct lfsck_reply *rep,
3542 struct lfsck_query *que)
3544 struct lfsck_instance *lfsck;
3545 struct lfsck_component *com;
3551 lfsck = lfsck_instance_find(key, true, false);
3552 if (unlikely(lfsck == NULL))
3556 if (que->lu_types == LFSCK_TYPES_ALL)
3558 LFSCK_TYPES_SUPPORTED & ~LFSCK_TYPE_SCRUB;
3560 if (que->lu_types & ~LFSCK_TYPES_SUPPORTED) {
3561 que->lu_types &= ~LFSCK_TYPES_SUPPORTED;
3563 GOTO(out, rc = -ENOTSUPP);
3566 for (i = 0, type = 1 << i; i < LFSCK_TYPE_BITS;
3567 i++, type = 1 << i) {
3568 if (!(que->lu_types & type))
3572 com = lfsck_component_find(lfsck, type);
3573 if (unlikely(com == NULL))
3574 GOTO(out, rc = -ENOTSUPP);
3576 memset(que->lu_mdts_count[i], 0,
3577 sizeof(__u32) * (LS_MAX + 1));
3578 memset(que->lu_osts_count[i], 0,
3579 sizeof(__u32) * (LS_MAX + 1));
3580 que->lu_repaired[i] = 0;
3581 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3583 lfsck_component_put(env, com);
3588 if (!(que->lu_flags & LPF_WAIT))
3591 for (i = 0, type = 1 << i; i < LFSCK_TYPE_BITS;
3592 i++, type = 1 << i) {
3593 if (!(que->lu_types & type))
3596 if (que->lu_mdts_count[i][LS_SCANNING_PHASE1] != 0 ||
3597 que->lu_mdts_count[i][LS_SCANNING_PHASE2] != 0 ||
3598 que->lu_osts_count[i][LS_SCANNING_PHASE1] != 0 ||
3599 que->lu_osts_count[i][LS_SCANNING_PHASE2] != 0) {
3600 struct l_wait_info lwi;
3602 /* If it is required to wait, then sleep
3603 * 3 seconds and try to query again. */
3604 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(3),
3608 rc = l_wait_event(lfsck->li_thread.t_ctl_waitq,
3610 if (rc == -ETIMEDOUT)
3615 com = lfsck_component_find(lfsck, req->lr_active);
3616 if (likely(com != NULL)) {
3617 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3619 lfsck_component_put(env, com);
3628 lfsck_instance_put(env, lfsck);
3631 EXPORT_SYMBOL(lfsck_query);
3633 int lfsck_register_namespace(const struct lu_env *env, struct dt_device *key,
3634 struct ldlm_namespace *ns)
3636 struct lfsck_instance *lfsck;
3639 lfsck = lfsck_instance_find(key, true, false);
3640 if (likely(lfsck != NULL)) {
3641 lfsck->li_namespace = ns;
3642 lfsck_instance_put(env, lfsck);
3648 EXPORT_SYMBOL(lfsck_register_namespace);
3650 int lfsck_register(const struct lu_env *env, struct dt_device *key,
3651 struct dt_device *next, struct obd_device *obd,
3652 lfsck_out_notify notify, void *notify_data, bool master)
3654 struct lfsck_instance *lfsck;
3655 struct dt_object *root = NULL;
3656 struct dt_object *obj = NULL;
3657 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
3661 lfsck = lfsck_instance_find(key, false, false);
3662 if (unlikely(lfsck != NULL))
3665 OBD_ALLOC_PTR(lfsck);
3669 mutex_init(&lfsck->li_mutex);
3670 spin_lock_init(&lfsck->li_lock);
3671 INIT_LIST_HEAD(&lfsck->li_link);
3672 INIT_LIST_HEAD(&lfsck->li_list_scan);
3673 INIT_LIST_HEAD(&lfsck->li_list_dir);
3674 INIT_LIST_HEAD(&lfsck->li_list_double_scan);
3675 INIT_LIST_HEAD(&lfsck->li_list_idle);
3676 INIT_LIST_HEAD(&lfsck->li_list_lmv);
3677 atomic_set(&lfsck->li_ref, 1);
3678 atomic_set(&lfsck->li_double_scan_count, 0);
3679 init_waitqueue_head(&lfsck->li_thread.t_ctl_waitq);
3680 lfsck->li_out_notify = notify;
3681 lfsck->li_out_notify_data = notify_data;
3682 lfsck->li_next = next;
3683 lfsck->li_bottom = key;
3684 lfsck->li_obd = obd;
3686 rc = lfsck_tgt_descs_init(&lfsck->li_ost_descs);
3690 rc = lfsck_tgt_descs_init(&lfsck->li_mdt_descs);
3694 fid->f_seq = FID_SEQ_LOCAL_NAME;
3697 rc = local_oid_storage_init(env, key, fid, &lfsck->li_los);
3701 rc = dt_root_get(env, key, fid);
3705 root = dt_locate(env, key, fid);
3707 GOTO(out, rc = PTR_ERR(root));
3709 if (unlikely(!dt_try_as_dir(env, root)))
3710 GOTO(out, rc = -ENOTDIR);
3712 lfsck->li_local_root_fid = *fid;
3714 lfsck->li_master = 1;
3715 if (lfsck_dev_idx(lfsck) == 0) {
3716 struct lu_fid *pfid = &lfsck_env_info(env)->lti_fid2;
3717 const struct lu_name *cname;
3719 rc = dt_lookup(env, root,
3720 (struct dt_rec *)(&lfsck->li_global_root_fid),
3721 (const struct dt_key *)"ROOT");
3725 obj = dt_locate(env, key, &lfsck->li_global_root_fid);
3727 GOTO(out, rc = PTR_ERR(obj));
3729 if (unlikely(!dt_try_as_dir(env, obj)))
3730 GOTO(out, rc = -ENOTDIR);
3732 rc = dt_lookup(env, obj, (struct dt_rec *)fid,
3733 (const struct dt_key *)dotlustre);
3737 lfsck_object_put(env, obj);
3738 obj = dt_locate(env, key, fid);
3740 GOTO(out, rc = PTR_ERR(obj));
3742 cname = lfsck_name_get_const(env, dotlustre,
3744 rc = lfsck_verify_linkea(env, obj, cname,
3745 &lfsck->li_global_root_fid);
3749 if (unlikely(!dt_try_as_dir(env, obj)))
3750 GOTO(out, rc = -ENOTDIR);
3753 rc = dt_lookup(env, obj, (struct dt_rec *)fid,
3754 (const struct dt_key *)lostfound);
3758 lfsck_object_put(env, obj);
3759 obj = dt_locate(env, key, fid);
3761 GOTO(out, rc = PTR_ERR(obj));
3763 cname = lfsck_name_get_const(env, lostfound,
3765 rc = lfsck_verify_linkea(env, obj, cname, pfid);
3769 lfsck_object_put(env, obj);
3774 fid->f_seq = FID_SEQ_LOCAL_FILE;
3775 fid->f_oid = OTABLE_IT_OID;
3777 obj = dt_locate(env, key, fid);
3779 GOTO(out, rc = PTR_ERR(obj));
3781 rc = obj->do_ops->do_index_try(env, obj, &dt_otable_features);
3785 lfsck->li_obj_oit = obj;
3786 obj = local_file_find_or_create(env, lfsck->li_los, root, LFSCK_DIR,
3787 S_IFDIR | S_IRUGO | S_IWUSR);
3789 GOTO(out, rc = PTR_ERR(obj));
3791 lu_object_get(&obj->do_lu);
3792 lfsck->li_lfsck_dir = obj;
3793 rc = lfsck_bookmark_setup(env, lfsck);
3798 rc = lfsck_fid_init(lfsck);
3802 rc = lfsck_namespace_setup(env, lfsck);
3807 rc = lfsck_layout_setup(env, lfsck);
3811 /* XXX: more LFSCK components initialization to be added here. */
3813 rc = lfsck_instance_add(lfsck);
3815 rc = lfsck_add_target_from_orphan(env, lfsck);
3817 if (obj != NULL && !IS_ERR(obj))
3818 lfsck_object_put(env, obj);
3819 if (root != NULL && !IS_ERR(root))
3820 lfsck_object_put(env, root);
3822 lfsck_instance_cleanup(env, lfsck);
3825 EXPORT_SYMBOL(lfsck_register);
3827 void lfsck_degister(const struct lu_env *env, struct dt_device *key)
3829 struct lfsck_instance *lfsck;
3831 lfsck = lfsck_instance_find(key, false, true);
3833 lfsck_instance_put(env, lfsck);
3835 EXPORT_SYMBOL(lfsck_degister);
3837 int lfsck_add_target(const struct lu_env *env, struct dt_device *key,
3838 struct dt_device *tgt, struct obd_export *exp,
3839 __u32 index, bool for_ost)
3841 struct lfsck_instance *lfsck;
3842 struct lfsck_tgt_desc *ltd;
3853 INIT_LIST_HEAD(<d->ltd_orphan_list);
3854 INIT_LIST_HEAD(<d->ltd_layout_list);
3855 INIT_LIST_HEAD(<d->ltd_layout_phase_list);
3856 INIT_LIST_HEAD(<d->ltd_namespace_list);
3857 INIT_LIST_HEAD(<d->ltd_namespace_phase_list);
3858 atomic_set(<d->ltd_ref, 1);
3859 ltd->ltd_index = index;
3861 spin_lock(&lfsck_instance_lock);
3862 lfsck = __lfsck_instance_find(key, true, false);
3863 if (lfsck == NULL) {
3865 list_add_tail(<d->ltd_orphan_list,
3866 &lfsck_ost_orphan_list);
3868 list_add_tail(<d->ltd_orphan_list,
3869 &lfsck_mdt_orphan_list);
3870 spin_unlock(&lfsck_instance_lock);
3874 spin_unlock(&lfsck_instance_lock);
3876 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, false);
3880 lfsck_instance_put(env, lfsck);
3884 EXPORT_SYMBOL(lfsck_add_target);
3886 void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
3887 struct dt_device *tgt, __u32 index, bool for_ost)
3889 struct lfsck_instance *lfsck;
3890 struct lfsck_tgt_descs *ltds;
3891 struct lfsck_tgt_desc *ltd;
3892 struct list_head *head;
3895 head = &lfsck_ost_orphan_list;
3897 head = &lfsck_mdt_orphan_list;
3899 spin_lock(&lfsck_instance_lock);
3900 list_for_each_entry(ltd, head, ltd_orphan_list) {
3901 if (ltd->ltd_tgt == tgt) {
3902 list_del_init(<d->ltd_orphan_list);
3903 spin_unlock(&lfsck_instance_lock);
3911 lfsck = __lfsck_instance_find(key, true, false);
3912 spin_unlock(&lfsck_instance_lock);
3913 if (unlikely(lfsck == NULL))
3917 ltds = &lfsck->li_ost_descs;
3919 ltds = &lfsck->li_mdt_descs;
3921 down_write(<ds->ltd_rw_sem);
3922 LASSERT(ltds->ltd_tgts_bitmap != NULL);
3924 if (unlikely(index >= ltds->ltd_tgts_bitmap->size))
3927 ltd = lfsck_ltd2tgt(ltds, index);
3928 if (unlikely(ltd == NULL))
3931 LASSERT(ltds->ltd_tgtnr > 0);
3934 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, index);
3935 lfsck_assign_tgt(ltds, NULL, index);
3940 head = &lfsck->li_ost_descs.ltd_orphan;
3942 head = &lfsck->li_mdt_descs.ltd_orphan;
3944 list_for_each_entry(ltd, head, ltd_orphan_list) {
3945 if (ltd->ltd_tgt == tgt) {
3946 list_del_init(<d->ltd_orphan_list);
3952 up_write(<ds->ltd_rw_sem);
3954 spin_lock(<ds->ltd_lock);
3956 spin_unlock(<ds->ltd_lock);
3957 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_NAMESPACE);
3958 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_LAYOUT);
3962 lfsck_instance_put(env, lfsck);
3964 EXPORT_SYMBOL(lfsck_del_target);
3966 static int __init lfsck_init(void)
3970 INIT_LIST_HEAD(&lfsck_instance_list);
3971 INIT_LIST_HEAD(&lfsck_ost_orphan_list);
3972 INIT_LIST_HEAD(&lfsck_mdt_orphan_list);
3973 lfsck_key_init_generic(&lfsck_thread_key, NULL);
3974 rc = lu_context_key_register(&lfsck_thread_key);
3976 tgt_register_lfsck_in_notify_local(lfsck_in_notify_local);
3977 tgt_register_lfsck_in_notify(lfsck_in_notify);
3978 tgt_register_lfsck_query(lfsck_query);
3984 static void __exit lfsck_exit(void)
3986 struct lfsck_tgt_desc *ltd;
3987 struct lfsck_tgt_desc *next;
3989 LASSERT(list_empty(&lfsck_instance_list));
3991 list_for_each_entry_safe(ltd, next, &lfsck_ost_orphan_list,
3993 list_del_init(<d->ltd_orphan_list);
3997 list_for_each_entry_safe(ltd, next, &lfsck_mdt_orphan_list,
3999 list_del_init(<d->ltd_orphan_list);
4003 lu_context_key_degister(&lfsck_thread_key);
4006 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
4007 MODULE_DESCRIPTION("Lustre File System Checker");
4008 MODULE_VERSION(LUSTRE_VERSION_STRING);
4009 MODULE_LICENSE("GPL");
4011 module_init(lfsck_init);
4012 module_exit(lfsck_exit);