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 <linux/delay.h>
37 #include <lu_object.h>
38 #include <dt_object.h>
39 #include <md_object.h>
40 #include <lustre_fld.h>
41 #include <lustre_lib.h>
42 #include <lustre_net.h>
43 #include <lustre_lfsck.h>
45 #include "lfsck_internal.h"
47 #define LFSCK_CHECKPOINT_SKIP 1
49 /* define lfsck thread key */
50 LU_KEY_INIT(lfsck, struct lfsck_thread_info);
52 static void lfsck_key_fini(const struct lu_context *ctx,
53 struct lu_context_key *key, void *data)
55 struct lfsck_thread_info *info = data;
57 lu_buf_free(&info->lti_linkea_buf);
58 lu_buf_free(&info->lti_linkea_buf2);
59 lu_buf_free(&info->lti_big_buf);
63 LU_CONTEXT_KEY_DEFINE(lfsck, LCT_MD_THREAD | LCT_DT_THREAD);
64 LU_KEY_INIT_GENERIC(lfsck);
66 static struct list_head lfsck_instance_list;
67 static struct list_head lfsck_ost_orphan_list;
68 static struct list_head lfsck_mdt_orphan_list;
69 static DEFINE_SPINLOCK(lfsck_instance_lock);
71 const char *lfsck_flags_names[] = {
80 const char *lfsck_param_names[] = {
90 "delay_create_ostobj",
94 enum lfsck_verify_lpf_types {
96 LVLT_BY_NAMEENTRY = 1,
100 lfsck_reset_ltd_status(struct lfsck_tgt_desc *ltd, enum lfsck_type type)
102 if (type == LFSCK_TYPE_LAYOUT) {
103 ltd->ltd_layout_status = LS_MAX;
104 ltd->ltd_layout_repaired = 0;
106 ltd->ltd_namespace_status = LS_MAX;
107 ltd->ltd_namespace_repaired = 0;
111 static int lfsck_tgt_descs_init(struct lfsck_tgt_descs *ltds)
113 spin_lock_init(<ds->ltd_lock);
114 init_rwsem(<ds->ltd_rw_sem);
115 INIT_LIST_HEAD(<ds->ltd_orphan);
116 ltds->ltd_tgts_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
117 if (ltds->ltd_tgts_bitmap == NULL)
123 static void lfsck_tgt_descs_fini(struct lfsck_tgt_descs *ltds)
125 struct lfsck_tgt_desc *ltd;
126 struct lfsck_tgt_desc *next;
129 down_write(<ds->ltd_rw_sem);
131 list_for_each_entry_safe(ltd, next, <ds->ltd_orphan,
133 list_del_init(<d->ltd_orphan_list);
137 if (unlikely(ltds->ltd_tgts_bitmap == NULL)) {
138 up_write(<ds->ltd_rw_sem);
143 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
144 ltd = lfsck_ltd2tgt(ltds, idx);
145 if (likely(ltd != NULL)) {
146 LASSERT(list_empty(<d->ltd_layout_list));
147 LASSERT(list_empty(<d->ltd_layout_phase_list));
148 LASSERT(list_empty(<d->ltd_namespace_list));
149 LASSERT(list_empty(<d->ltd_namespace_phase_list));
152 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, idx);
153 lfsck_assign_tgt(ltds, NULL, idx);
158 LASSERTF(ltds->ltd_tgtnr == 0, "tgt count unmatched: %d\n",
161 for (idx = 0; idx < TGT_PTRS; idx++) {
162 if (ltds->ltd_tgts_idx[idx] != NULL) {
163 OBD_FREE_PTR(ltds->ltd_tgts_idx[idx]);
164 ltds->ltd_tgts_idx[idx] = NULL;
168 CFS_FREE_BITMAP(ltds->ltd_tgts_bitmap);
169 ltds->ltd_tgts_bitmap = NULL;
170 up_write(<ds->ltd_rw_sem);
173 static int __lfsck_add_target(const struct lu_env *env,
174 struct lfsck_instance *lfsck,
175 struct lfsck_tgt_desc *ltd,
176 bool for_ost, bool locked)
178 struct lfsck_tgt_descs *ltds;
179 __u32 index = ltd->ltd_index;
184 ltds = &lfsck->li_ost_descs;
186 ltds = &lfsck->li_mdt_descs;
189 down_write(<ds->ltd_rw_sem);
191 LASSERT(ltds->ltd_tgts_bitmap != NULL);
193 if (index >= ltds->ltd_tgts_bitmap->size) {
194 __u32 newsize = max((__u32)ltds->ltd_tgts_bitmap->size,
195 (__u32)BITS_PER_LONG);
196 struct cfs_bitmap *old_bitmap = ltds->ltd_tgts_bitmap;
197 struct cfs_bitmap *new_bitmap;
199 while (newsize < index + 1)
202 new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
203 if (new_bitmap == NULL)
204 GOTO(unlock, rc = -ENOMEM);
206 if (ltds->ltd_tgtnr > 0)
207 cfs_bitmap_copy(new_bitmap, old_bitmap);
208 ltds->ltd_tgts_bitmap = new_bitmap;
209 CFS_FREE_BITMAP(old_bitmap);
212 if (cfs_bitmap_check(ltds->ltd_tgts_bitmap, index)) {
213 CERROR("%s: the device %s (%u) is registered already\n",
214 lfsck_lfsck2name(lfsck),
215 ltd->ltd_tgt->dd_lu_dev.ld_obd->obd_name, index);
216 GOTO(unlock, rc = -EEXIST);
219 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
220 OBD_ALLOC_PTR(ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK]);
221 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL)
222 GOTO(unlock, rc = -ENOMEM);
225 lfsck_assign_tgt(ltds, ltd, index);
226 cfs_bitmap_set(ltds->ltd_tgts_bitmap, index);
229 GOTO(unlock, rc = 0);
233 up_write(<ds->ltd_rw_sem);
238 static int lfsck_add_target_from_orphan(const struct lu_env *env,
239 struct lfsck_instance *lfsck)
241 struct lfsck_tgt_descs *ltds = &lfsck->li_ost_descs;
242 struct lfsck_tgt_desc *ltd;
243 struct lfsck_tgt_desc *next;
244 struct list_head *head = &lfsck_ost_orphan_list;
249 spin_lock(&lfsck_instance_lock);
250 list_for_each_entry_safe(ltd, next, head, ltd_orphan_list) {
251 if (ltd->ltd_key == lfsck->li_bottom)
252 list_move_tail(<d->ltd_orphan_list,
255 spin_unlock(&lfsck_instance_lock);
257 down_write(<ds->ltd_rw_sem);
258 while (!list_empty(<ds->ltd_orphan)) {
259 ltd = list_entry(ltds->ltd_orphan.next,
260 struct lfsck_tgt_desc,
262 list_del_init(<d->ltd_orphan_list);
263 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, true);
264 /* Do not hold the semaphore for too long time. */
265 up_write(<ds->ltd_rw_sem);
269 down_write(<ds->ltd_rw_sem);
271 up_write(<ds->ltd_rw_sem);
274 ltds = &lfsck->li_mdt_descs;
275 head = &lfsck_mdt_orphan_list;
283 static inline struct lfsck_component *
284 __lfsck_component_find(struct lfsck_instance *lfsck, __u16 type,
285 struct list_head *list)
287 struct lfsck_component *com;
289 list_for_each_entry(com, list, lc_link) {
290 if (com->lc_type == type)
296 struct lfsck_component *
297 lfsck_component_find(struct lfsck_instance *lfsck, __u16 type)
299 struct lfsck_component *com;
301 spin_lock(&lfsck->li_lock);
302 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
306 com = __lfsck_component_find(lfsck, type,
307 &lfsck->li_list_double_scan);
311 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_idle);
315 lfsck_component_get(com);
316 spin_unlock(&lfsck->li_lock);
320 void lfsck_component_cleanup(const struct lu_env *env,
321 struct lfsck_component *com)
323 if (!list_empty(&com->lc_link))
324 list_del_init(&com->lc_link);
325 if (!list_empty(&com->lc_link_dir))
326 list_del_init(&com->lc_link_dir);
328 lfsck_component_put(env, com);
331 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
332 struct lu_fid *fid, bool locked)
334 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
339 mutex_lock(&lfsck->li_mutex);
341 rc = seq_client_alloc_fid(env, lfsck->li_seq, fid);
343 bk->lb_last_fid = *fid;
344 /* We do not care about whether the subsequent sub-operations
345 * failed or not. The worst case is that one FID is lost that
346 * is not a big issue for the LFSCK since it is relative rare
347 * for LFSCK create. */
348 rc = lfsck_bookmark_store(env, lfsck);
352 mutex_unlock(&lfsck->li_mutex);
357 static int __lfsck_ibits_lock(const struct lu_env *env,
358 struct lfsck_instance *lfsck,
359 struct dt_object *obj, struct ldlm_res_id *resid,
360 struct lustre_handle *lh, __u64 bits,
363 struct lfsck_thread_info *info = lfsck_env_info(env);
364 union ldlm_policy_data *policy = &info->lti_policy;
365 __u64 flags = LDLM_FL_ATOMIC_CB;
368 LASSERT(lfsck->li_namespace != NULL);
370 memset(policy, 0, sizeof(*policy));
371 policy->l_inodebits.bits = bits;
372 if (dt_object_remote(obj)) {
373 struct ldlm_enqueue_info *einfo = &info->lti_einfo;
375 memset(einfo, 0, sizeof(*einfo));
376 einfo->ei_type = LDLM_IBITS;
377 einfo->ei_mode = mode;
378 einfo->ei_cb_bl = ldlm_blocking_ast;
379 einfo->ei_cb_cp = ldlm_completion_ast;
380 einfo->ei_res_id = resid;
382 rc = dt_object_lock(env, obj, lh, einfo, policy);
383 /* for regular checks LFSCK doesn't use LDLM locking,
384 * so the state isn't coherent. here we just took LDLM
385 * lock for coherency and it's time to invalidate
388 dt_invalidate(env, obj);
390 rc = ldlm_cli_enqueue_local(env, lfsck->li_namespace, resid,
391 LDLM_IBITS, policy, mode,
392 &flags, ldlm_blocking_ast,
393 ldlm_completion_ast, NULL, NULL,
394 0, LVB_T_NONE, NULL, lh);
397 if (rc == ELDLM_OK) {
400 memset(lh, 0, sizeof(*lh));
408 * Request the specified ibits lock for the given object.
410 * Before the LFSCK modifying on the namespace visible object,
411 * it needs to acquire related ibits ldlm lock.
413 * \param[in] env pointer to the thread context
414 * \param[in] lfsck pointer to the lfsck instance
415 * \param[in] obj pointer to the dt_object to be locked
416 * \param[out] lh pointer to the lock handle
417 * \param[in] bits the bits for the ldlm lock to be acquired
418 * \param[in] mode the mode for the ldlm lock to be acquired
420 * \retval 0 for success
421 * \retval negative error number on failure
423 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
424 struct dt_object *obj, struct lustre_handle *lh,
425 __u64 bits, enum ldlm_mode mode)
427 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
429 LASSERT(!lustre_handle_is_used(lh));
431 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
432 return __lfsck_ibits_lock(env, lfsck, obj, resid, lh, bits, mode);
436 * Request the remote LOOKUP lock for the given object.
438 * If \a pobj is remote, the LOOKUP lock of \a obj is on the MDT where
439 * \a pobj is, acquire LOOKUP lock there.
441 * \param[in] env pointer to the thread context
442 * \param[in] lfsck pointer to the lfsck instance
443 * \param[in] pobj pointer to parent dt_object
444 * \param[in] obj pointer to the dt_object to be locked
445 * \param[out] lh pointer to the lock handle
446 * \param[in] mode the mode for the ldlm lock to be acquired
448 * \retval 0 for success
449 * \retval negative error number on failure
451 int lfsck_remote_lookup_lock(const struct lu_env *env,
452 struct lfsck_instance *lfsck,
453 struct dt_object *pobj, struct dt_object *obj,
454 struct lustre_handle *lh, enum ldlm_mode mode)
456 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
458 LASSERT(!lustre_handle_is_used(lh));
460 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
461 return __lfsck_ibits_lock(env, lfsck, pobj, resid, lh,
462 MDS_INODELOCK_LOOKUP, mode);
466 * Release the the specified ibits lock.
468 * If the lock has been acquired before, release it
469 * and cleanup the handle. Otherwise, do nothing.
471 * \param[in] lh pointer to the lock handle
472 * \param[in] mode the mode for the ldlm lock to be released
474 void lfsck_ibits_unlock(struct lustre_handle *lh, enum ldlm_mode mode)
476 if (lustre_handle_is_used(lh)) {
477 ldlm_lock_decref(lh, mode);
478 memset(lh, 0, sizeof(*lh));
483 * Request compound ibits locks for the given <obj, name> pairs.
485 * Before the LFSCK modifying on the namespace visible object, it needs to
486 * acquire related ibits ldlm lock. Usually, we can use lfsck_ibits_lock for
487 * the lock purpose. But the simple lfsck_ibits_lock for directory-based
488 * modificationis (such as insert name entry to the directory) may be too
489 * coarse-grained and not efficient.
491 * The lfsck_lock() will request compound ibits locks on the specified
492 * <obj, name> pairs: the PDO (Parallel Directory Operations) ibits (UPDATE)
493 * lock on the directory object, and the regular ibits lock on the name hash.
495 * \param[in] env pointer to the thread context
496 * \param[in] lfsck pointer to the lfsck instance
497 * \param[in] obj pointer to the dt_object to be locked
498 * \param[in] name used for building the PDO lock resource
499 * \param[out] llh pointer to the lfsck_lock_handle
500 * \param[in] bits the bits for the ldlm lock to be acquired
501 * \param[in] mode the mode for the ldlm lock to be acquired
503 * \retval 0 for success
504 * \retval negative error number on failure
506 int lfsck_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
507 struct dt_object *obj, const char *name,
508 struct lfsck_lock_handle *llh, __u64 bits, enum ldlm_mode mode)
510 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
513 LASSERT(S_ISDIR(lfsck_object_type(obj)));
514 LASSERT(name != NULL);
515 LASSERT(name[0] != 0);
516 LASSERT(!lustre_handle_is_used(&llh->llh_pdo_lh));
517 LASSERT(!lustre_handle_is_used(&llh->llh_reg_lh));
521 llh->llh_pdo_mode = LCK_EX;
524 llh->llh_pdo_mode = LCK_CW;
527 llh->llh_pdo_mode = LCK_CR;
530 CDEBUG(D_LFSCK, "%s: unexpected PDO lock mode %u on the obj "
531 DFID"\n", lfsck_lfsck2name(lfsck), mode,
532 PFID(lfsck_dto2fid(obj)));
536 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
537 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_pdo_lh,
538 MDS_INODELOCK_UPDATE, llh->llh_pdo_mode);
542 llh->llh_reg_mode = mode;
543 resid->name[LUSTRE_RES_ID_HSH_OFF] = ll_full_name_hash(NULL, name,
545 LASSERT(resid->name[LUSTRE_RES_ID_HSH_OFF] != 0);
546 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_reg_lh,
547 bits, llh->llh_reg_mode);
549 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
555 * Release the the compound ibits locks.
557 * \param[in] llh pointer to the lfsck_lock_handle to be released
559 void lfsck_unlock(struct lfsck_lock_handle *llh)
561 lfsck_ibits_unlock(&llh->llh_reg_lh, llh->llh_reg_mode);
562 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
565 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
566 struct lfsck_instance *lfsck,
567 const struct lu_fid *fid)
569 struct seq_server_site *ss = lfsck_dev_site(lfsck);
570 struct lu_seq_range *range = &lfsck_env_info(env)->lti_range;
573 if (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE)) {
574 /* "ROOT" is always on the MDT0. */
575 if (lu_fid_eq(fid, &lfsck->li_global_root_fid))
578 return lfsck_dev_idx(lfsck);
581 fld_range_set_mdt(range);
582 rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
584 rc = range->lsr_index;
589 const char dot[] = ".";
590 const char dotdot[] = "..";
591 static const char dotlustre[] = ".lustre";
592 static const char lostfound[] = "lost+found";
595 * Remove the name entry from the .lustre/lost+found directory.
597 * No need to care about the object referenced by the name entry,
598 * either the name entry is invalid or redundant, or the referenced
599 * object has been processed or will be handled by others.
601 * \param[in] env pointer to the thread context
602 * \param[in] lfsck pointer to the lfsck instance
603 * \param[in] name the name for the name entry to be removed
605 * \retval 0 for success
606 * \retval negative error number on failure
608 static int lfsck_lpf_remove_name_entry(const struct lu_env *env,
609 struct lfsck_instance *lfsck,
612 struct dt_object *parent = lfsck->li_lpf_root_obj;
613 struct dt_device *dev = lfsck_obj2dev(parent);
615 struct lfsck_lock_handle *llh = &lfsck_env_info(env)->lti_llh;
619 rc = lfsck_lock(env, lfsck, parent, name, llh,
620 MDS_INODELOCK_UPDATE, LCK_PW);
624 th = dt_trans_create(env, dev);
626 GOTO(unlock, rc = PTR_ERR(th));
628 rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
632 rc = dt_declare_ref_del(env, parent, th);
636 rc = dt_trans_start_local(env, dev, th);
640 rc = dt_delete(env, parent, (const struct dt_key *)name, th);
644 dt_write_lock(env, parent, 0);
645 rc = dt_ref_del(env, parent, th);
646 dt_write_unlock(env, parent);
651 dt_trans_stop(env, dev, th);
656 CDEBUG(D_LFSCK, "%s: remove name entry "DFID"/%s: rc = %d\n",
657 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(parent)), name, rc);
662 static int lfsck_create_lpf_local(const struct lu_env *env,
663 struct lfsck_instance *lfsck,
664 struct dt_object *child,
666 struct dt_object_format *dof,
669 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
670 struct dt_object *parent = lfsck->li_lpf_root_obj;
671 struct dt_device *dev = lfsck_obj2dev(child);
672 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
673 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
674 const struct lu_fid *cfid = lfsck_dto2fid(child);
675 struct thandle *th = NULL;
676 struct linkea_data ldata = { NULL };
677 struct lu_buf linkea_buf;
678 const struct lu_name *cname;
680 int len = sizeof(struct lfsck_bookmark);
684 cname = lfsck_name_get_const(env, name, strlen(name));
685 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
686 cname, lfsck_dto2fid(parent));
690 th = dt_trans_create(env, dev);
694 /* 1a. create child */
695 rc = dt_declare_create(env, child, la, NULL, dof, th);
699 if (!dt_try_as_dir(env, child))
700 GOTO(stop, rc = -ENOTDIR);
702 /* 2a. increase child nlink */
703 rc = dt_declare_ref_add(env, child, th);
707 /* 3a. insert dot into child dir */
708 rec->rec_type = S_IFDIR;
710 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
711 (const struct dt_key *)dot, th);
715 /* 4a. insert dotdot into child dir */
716 rec->rec_fid = &LU_LPF_FID;
717 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
718 (const struct dt_key *)dotdot, th);
722 /* 5a. insert linkEA for child */
723 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
724 ldata.ld_leh->leh_len);
725 rc = dt_declare_xattr_set(env, child, &linkea_buf,
726 XATTR_NAME_LINK, 0, th);
730 /* 6a. insert name into parent dir */
731 rec->rec_type = S_IFDIR;
733 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
734 (const struct dt_key *)name, th);
738 /* 7a. increase parent nlink */
739 rc = dt_declare_ref_add(env, parent, th);
743 /* 8a. update bookmark */
744 rc = dt_declare_record_write(env, bk_obj,
745 lfsck_buf_get(env, bk, len), 0, th);
749 rc = dt_trans_start_local(env, dev, th);
753 dt_write_lock(env, child, 0);
754 /* 1b. create child */
755 rc = dt_create(env, child, la, NULL, dof, th);
759 /* 2b. increase child nlink */
760 rc = dt_ref_add(env, child, th);
764 /* 3b. insert dot into child dir */
766 rc = dt_insert(env, child, (const struct dt_rec *)rec,
767 (const struct dt_key *)dot, th);
771 /* 4b. insert dotdot into child dir */
772 rec->rec_fid = &LU_LPF_FID;
773 rc = dt_insert(env, child, (const struct dt_rec *)rec,
774 (const struct dt_key *)dotdot, th);
778 /* 5b. insert linkEA for child. */
779 rc = dt_xattr_set(env, child, &linkea_buf,
780 XATTR_NAME_LINK, 0, th);
781 dt_write_unlock(env, child);
785 /* 6b. insert name into parent dir */
787 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
788 (const struct dt_key *)name, th);
792 dt_write_lock(env, parent, 0);
793 /* 7b. increase parent nlink */
794 rc = dt_ref_add(env, parent, th);
795 dt_write_unlock(env, parent);
799 bk->lb_lpf_fid = *cfid;
800 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
802 /* 8b. update bookmark */
803 rc = dt_record_write(env, bk_obj,
804 lfsck_buf_get(env, bk, len), &pos, th);
809 dt_write_unlock(env, child);
812 dt_trans_stop(env, dev, th);
817 static int lfsck_create_lpf_remote(const struct lu_env *env,
818 struct lfsck_instance *lfsck,
819 struct dt_object *child,
821 struct dt_object_format *dof,
824 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
825 struct dt_object *parent = lfsck->li_lpf_root_obj;
826 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
827 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
828 const struct lu_fid *cfid = lfsck_dto2fid(child);
829 struct thandle *th = NULL;
830 struct linkea_data ldata = { NULL };
831 struct lu_buf linkea_buf;
832 const struct lu_name *cname;
833 struct dt_device *dev;
835 int len = sizeof(struct lfsck_bookmark);
839 cname = lfsck_name_get_const(env, name, strlen(name));
840 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
841 cname, lfsck_dto2fid(parent));
845 /* Create .lustre/lost+found/MDTxxxx. */
847 /* XXX: Currently, cross-MDT create operation needs to create the child
848 * object firstly, then insert name into the parent directory. For
849 * this case, the child object resides on current MDT (local), but
850 * the parent ".lustre/lost+found" may be on remote MDT. It is not
851 * easy to contain all the sub-modifications orderly within single
854 * To avoid more inconsistency, we split the create operation into
857 * 1) create the child and update the lfsck_bookmark::lb_lpf_fid
859 * 2) insert the name "MDTXXXX" in the parent ".lustre/lost+found"
862 * If 1) done, but 2) failed, then go ahead, the LFSCK will try to
863 * repair such inconsistency when LFSCK run next time. */
865 /* Transaction I: locally */
867 dev = lfsck_obj2dev(child);
868 th = dt_trans_create(env, dev);
872 /* 1a. create child */
873 rc = dt_declare_create(env, child, la, NULL, dof, th);
877 if (!dt_try_as_dir(env, child))
878 GOTO(stop, rc = -ENOTDIR);
880 /* 2a. increase child nlink */
881 rc = dt_declare_ref_add(env, child, th);
885 /* 3a. insert dot into child dir */
886 rec->rec_type = S_IFDIR;
888 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
889 (const struct dt_key *)dot, th);
893 /* 4a. insert dotdot into child dir */
894 rec->rec_fid = &LU_LPF_FID;
895 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
896 (const struct dt_key *)dotdot, th);
900 /* 5a. insert linkEA for child */
901 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
902 ldata.ld_leh->leh_len);
903 rc = dt_declare_xattr_set(env, child, &linkea_buf,
904 XATTR_NAME_LINK, 0, th);
908 /* 6a. update bookmark */
909 rc = dt_declare_record_write(env, bk_obj,
910 lfsck_buf_get(env, bk, len), 0, th);
914 rc = dt_trans_start_local(env, dev, th);
918 dt_write_lock(env, child, 0);
919 /* 1b. create child */
920 rc = dt_create(env, child, la, NULL, dof, th);
924 /* 2b. increase child nlink */
925 rc = dt_ref_add(env, child, th);
929 /* 3b. insert dot into child dir */
930 rec->rec_type = S_IFDIR;
932 rc = dt_insert(env, child, (const struct dt_rec *)rec,
933 (const struct dt_key *)dot, th);
937 /* 4b. insert dotdot into child dir */
938 rec->rec_fid = &LU_LPF_FID;
939 rc = dt_insert(env, child, (const struct dt_rec *)rec,
940 (const struct dt_key *)dotdot, th);
944 /* 5b. insert linkEA for child */
945 rc = dt_xattr_set(env, child, &linkea_buf,
946 XATTR_NAME_LINK, 0, th);
950 bk->lb_lpf_fid = *cfid;
951 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
953 /* 6b. update bookmark */
954 rc = dt_record_write(env, bk_obj,
955 lfsck_buf_get(env, bk, len), &pos, th);
957 dt_write_unlock(env, child);
958 dt_trans_stop(env, dev, th);
962 /* Transaction II: remotely */
964 dev = lfsck_obj2dev(parent);
965 th = dt_trans_create(env, dev);
970 /* 5a. insert name into parent dir */
972 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
973 (const struct dt_key *)name, th);
977 /* 6a. increase parent nlink */
978 rc = dt_declare_ref_add(env, parent, th);
982 rc = dt_trans_start_local(env, dev, th);
986 /* 5b. insert name into parent dir */
987 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
988 (const struct dt_key *)name, th);
992 dt_write_lock(env, parent, 0);
993 /* 6b. increase parent nlink */
994 rc = dt_ref_add(env, parent, th);
995 dt_write_unlock(env, parent);
1000 dt_write_unlock(env, child);
1002 dt_trans_stop(env, dev, th);
1004 if (rc != 0 && dev == lfsck_obj2dev(parent))
1005 CDEBUG(D_LFSCK, "%s: partially created the object "DFID
1006 "for orphans, but failed to insert the name %s "
1007 "to the .lustre/lost+found/. Such inconsistency "
1008 "will be repaired when LFSCK run next time: rc = %d\n",
1009 lfsck_lfsck2name(lfsck), PFID(cfid), name, rc);
1015 * Create the MDTxxxx directory under /ROOT/.lustre/lost+found/
1017 * The /ROOT/.lustre/lost+found/MDTxxxx/ directory is used for holding
1018 * orphans and other uncertain inconsistent objects found during the
1019 * LFSCK. Such directory will be created by the LFSCK engine on the
1020 * local MDT before the LFSCK scanning.
1022 * \param[in] env pointer to the thread context
1023 * \param[in] lfsck pointer to the lfsck instance
1025 * \retval 0 for success
1026 * \retval negative error number on failure
1028 static int lfsck_create_lpf(const struct lu_env *env,
1029 struct lfsck_instance *lfsck)
1031 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1032 struct lfsck_thread_info *info = lfsck_env_info(env);
1033 struct lu_fid *cfid = &info->lti_fid2;
1034 struct lu_attr *la = &info->lti_la;
1035 struct dt_object_format *dof = &info->lti_dof;
1036 struct dt_object *parent = lfsck->li_lpf_root_obj;
1037 struct dt_object *child = NULL;
1038 struct lfsck_lock_handle *llh = &info->lti_llh;
1040 int node = lfsck_dev_idx(lfsck);
1044 LASSERT(lfsck->li_master);
1045 LASSERT(parent != NULL);
1046 LASSERT(lfsck->li_lpf_obj == NULL);
1048 snprintf(name, 8, "MDT%04x", node);
1049 rc = lfsck_lock(env, lfsck, parent, name, llh,
1050 MDS_INODELOCK_UPDATE, LCK_PW);
1054 if (fid_is_zero(&bk->lb_lpf_fid)) {
1055 /* There is corner case that: in former LFSCK scanning we have
1056 * created the .lustre/lost+found/MDTxxxx but failed to update
1057 * the lfsck_bookmark::lb_lpf_fid successfully. So need lookup
1058 * it from MDT0 firstly. */
1059 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
1060 (const struct dt_key *)name);
1061 if (rc != 0 && rc != -ENOENT)
1065 bk->lb_lpf_fid = *cfid;
1066 rc = lfsck_bookmark_store(env, lfsck);
1068 rc = lfsck_fid_alloc(env, lfsck, cfid, true);
1073 *cfid = bk->lb_lpf_fid;
1076 child = lfsck_object_find_bottom_new(env, lfsck, cfid);
1078 GOTO(unlock, rc = PTR_ERR(child));
1080 if (dt_object_exists(child) != 0) {
1081 if (unlikely(!dt_try_as_dir(env, child)))
1084 lfsck->li_lpf_obj = child;
1089 memset(la, 0, sizeof(*la));
1090 la->la_atime = la->la_mtime = la->la_ctime = ktime_get_real_seconds();
1091 la->la_mode = S_IFDIR | S_IRWXU;
1092 la->la_valid = LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1094 memset(dof, 0, sizeof(*dof));
1095 dof->dof_type = dt_mode_to_dft(S_IFDIR);
1098 rc = lfsck_create_lpf_local(env, lfsck, child, la, dof, name);
1100 rc = lfsck_create_lpf_remote(env, lfsck, child, la, dof, name);
1102 lfsck->li_lpf_obj = child;
1108 if (rc != 0 && child != NULL && !IS_ERR(child))
1109 lfsck_object_put(env, child);
1115 * Scan .lustre/lost+found for bad name entries and remove them.
1117 * The valid name entry should be "MDTxxxx", the "xxxx" is the MDT device
1118 * index in the system. Any other formatted name is invalid and should be
1121 * \param[in] env pointer to the thread context
1122 * \param[in] lfsck pointer to the lfsck instance
1124 * \retval 0 for success
1125 * \retval negative error number on failure
1127 static int lfsck_scan_lpf_bad_entries(const struct lu_env *env,
1128 struct lfsck_instance *lfsck)
1130 struct dt_object *parent = lfsck->li_lpf_root_obj;
1131 struct lu_dirent *ent =
1132 (struct lu_dirent *)lfsck_env_info(env)->lti_key;
1133 const struct dt_it_ops *iops = &parent->do_index_ops->dio_it;
1138 it = iops->init(env, parent, LUDA_64BITHASH);
1140 RETURN(PTR_ERR(it));
1142 rc = iops->load(env, it, 0);
1144 rc = iops->next(env, it);
1151 rc = iops->rec(env, it, (struct dt_rec *)ent, LUDA_64BITHASH);
1155 ent->lde_namelen = le16_to_cpu(ent->lde_namelen);
1156 if (name_is_dot_or_dotdot(ent->lde_name, ent->lde_namelen))
1159 /* name length must be strlen("MDTxxxx") */
1160 if (ent->lde_namelen != 7)
1163 if (memcmp(ent->lde_name, "MDT", off) != 0)
1166 while (off < 7 && isxdigit(ent->lde_name[off]))
1172 rc = lfsck_lpf_remove_name_entry(env, lfsck,
1179 rc = iops->next(env, it);
1183 iops->fini(env, it);
1185 RETURN(rc > 0 ? 0 : rc);
1188 static int lfsck_update_lpf_entry(const struct lu_env *env,
1189 struct lfsck_instance *lfsck,
1190 struct dt_object *parent,
1191 struct dt_object *child,
1193 enum lfsck_verify_lpf_types type)
1197 if (type == LVLT_BY_BOOKMARK) {
1198 rc = lfsck_update_name_entry(env, lfsck, parent, name,
1199 lfsck_dto2fid(child), S_IFDIR);
1200 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1201 lfsck->li_bookmark_ram.lb_lpf_fid = *lfsck_dto2fid(child);
1202 rc = lfsck_bookmark_store(env, lfsck);
1204 CDEBUG(D_LFSCK, "%s: update LPF fid "DFID
1205 " in the bookmark file: rc = %d\n",
1206 lfsck_lfsck2name(lfsck),
1207 PFID(lfsck_dto2fid(child)), rc);
1214 * Check whether the @child back references the @parent.
1217 * 1) The child's FID is stored in the bookmark file. If the child back
1218 * references the parent (LU_LPF_FID object) via its ".." entry, then
1219 * insert the name (MDTxxxx) to the .lustre/lost+found; otherwise, if
1220 * the child back references another parent2, then:
1221 * 1.1) If the parent2 recognizes the child, then update the bookmark file;
1222 * 1.2) Otherwise, the LFSCK cannot know whether there will be parent3 that
1223 * references the child. So keep them there. As the LFSCK processing,
1224 * the parent3 may be found, then when the LFSCK run next time, the
1225 * inconsistency can be repaired.
1227 * 2) The child's FID is stored in the .lustre/lost+found/ sub-directory name
1228 * entry (MDTxxxx). If the child back references the parent (LU_LPF_FID obj)
1229 * via its ".." entry, then update the bookmark file, otherwise, if the child
1230 * back references another parent2, then:
1231 * 2.1) If the parent2 recognizes the child, then remove the sub-directory
1232 * from .lustre/lost+found/;
1233 * 2.2) Otherwise, if the parent2 does not recognizes the child, trust the
1234 * sub-directory name entry and update the child;
1235 * 2.3) Otherwise, if we do not know whether the parent2 recognizes the child
1236 * or not, then keep them there.
1238 * \param[in] env pointer to the thread context
1239 * \param[in] lfsck pointer to the lfsck instance
1240 * \param[in] child pointer to the lost+found sub-directory object
1241 * \param[in] name the name for lost+found sub-directory object
1242 * \param[out] fid pointer to the buffer to hold the FID of the object
1243 * (called it as parent2) that is referenced via the
1244 * child's dotdot entry; it also can be the FID that
1245 * is referenced by the name entry under the parent2.
1246 * \param[in] type to indicate where the child's FID is stored in
1248 * \retval positive number for uncertain inconsistency
1249 * \retval 0 for success
1250 * \retval negative error number on failure
1252 static int lfsck_verify_lpf_pairs(const struct lu_env *env,
1253 struct lfsck_instance *lfsck,
1254 struct dt_object *child, const char *name,
1256 enum lfsck_verify_lpf_types type)
1258 struct dt_object *parent = lfsck->li_lpf_root_obj;
1259 struct lfsck_thread_info *info = lfsck_env_info(env);
1260 char *name2 = info->lti_key;
1261 struct lu_fid *fid2 = &info->lti_fid3;
1262 struct dt_object *parent2 = NULL;
1263 struct lustre_handle lh = { 0 };
1268 rc = dt_lookup(env, child, (struct dt_rec *)fid,
1269 (const struct dt_key *)dotdot);
1273 if (!fid_is_sane(fid))
1274 GOTO(linkea, rc = -EINVAL);
1276 if (lu_fid_eq(fid, &LU_LPF_FID)) {
1277 const struct lu_name *cname;
1279 if (lfsck->li_lpf_obj == NULL) {
1280 lu_object_get(&child->do_lu);
1281 lfsck->li_lpf_obj = child;
1284 cname = lfsck_name_get_const(env, name, strlen(name));
1285 rc = lfsck_verify_linkea(env, child, cname, &LU_LPF_FID);
1287 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1293 parent2 = lfsck_object_find_bottom(env, lfsck, fid);
1294 if (IS_ERR(parent2))
1295 GOTO(linkea, parent2);
1297 if (!dt_object_exists(parent2)) {
1298 lfsck_object_put(env, parent2);
1300 GOTO(linkea, parent2 = ERR_PTR(-ENOENT));
1303 if (!dt_try_as_dir(env, parent2)) {
1304 lfsck_object_put(env, parent2);
1306 GOTO(linkea, parent2 = ERR_PTR(-ENOTDIR));
1310 /* To prevent rename/unlink race */
1311 rc = lfsck_ibits_lock(env, lfsck, child, &lh,
1312 MDS_INODELOCK_UPDATE, LCK_PR);
1316 dt_read_lock(env, child, 0);
1317 rc = lfsck_links_get_first(env, child, name2, fid2);
1319 dt_read_unlock(env, child);
1320 lfsck_ibits_unlock(&lh, LCK_PR);
1322 GOTO(out_put, rc = 1);
1325 /* It is almost impossible that the bookmark file (or the name entry)
1326 * and the linkEA hit the same data corruption. Trust the linkEA. */
1327 if (lu_fid_eq(fid2, &LU_LPF_FID) && strcmp(name, name2) == 0) {
1328 dt_read_unlock(env, child);
1329 lfsck_ibits_unlock(&lh, LCK_PR);
1332 if (lfsck->li_lpf_obj == NULL) {
1333 lu_object_get(&child->do_lu);
1334 lfsck->li_lpf_obj = child;
1337 /* Update the child's dotdot entry */
1338 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1339 &LU_LPF_FID, S_IFDIR);
1341 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1347 if (parent2 == NULL || IS_ERR(parent2)) {
1348 dt_read_unlock(env, child);
1349 lfsck_ibits_unlock(&lh, LCK_PR);
1351 GOTO(out_done, rc = 1);
1354 rc = dt_lookup(env, parent2, (struct dt_rec *)fid,
1355 (const struct dt_key *)name2);
1356 dt_read_unlock(env, child);
1357 lfsck_ibits_unlock(&lh, LCK_PR);
1358 if (rc != 0 && rc != -ENOENT)
1361 if (rc == -ENOENT || !lu_fid_eq(fid, lfsck_dto2fid(child))) {
1362 if (type == LVLT_BY_BOOKMARK)
1363 GOTO(out_put, rc = 1);
1365 /* Trust the name entry, update the child's dotdot entry. */
1366 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1367 &LU_LPF_FID, S_IFDIR);
1372 if (type == LVLT_BY_BOOKMARK) {
1373 /* Invalid FID record in the bookmark file, reset it. */
1374 fid_zero(&lfsck->li_bookmark_ram.lb_lpf_fid);
1375 rc = lfsck_bookmark_store(env, lfsck);
1377 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1378 " in the bookmark file: rc = %d\n",
1379 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(child)), rc);
1380 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1381 /* The name entry is wrong, remove it. */
1382 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1388 if (parent2 != NULL && !IS_ERR(parent2))
1389 lfsck_object_put(env, parent2);
1396 * Verify the /ROOT/.lustre/lost+found/ directory.
1398 * /ROOT/.lustre/lost+found/ is a special directory to hold the objects that
1399 * the LFSCK does not exactly know how to handle, such as orphans. So before
1400 * the LFSCK scanning the system, the consistency of such directory needs to
1401 * be verified firstly to allow the users to use it during the LFSCK.
1403 * \param[in] env pointer to the thread context
1404 * \param[in] lfsck pointer to the lfsck instance
1406 * \retval positive number for uncertain inconsistency
1407 * \retval 0 for success
1408 * \retval negative error number on failure
1410 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
1412 struct lfsck_thread_info *info = lfsck_env_info(env);
1413 struct lu_fid *pfid = &info->lti_fid;
1414 struct lu_fid *cfid = &info->lti_fid2;
1415 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1416 struct dt_object *parent;
1417 /* child1's FID is in the bookmark file. */
1418 struct dt_object *child1 = NULL;
1419 /* child2's FID is in the name entry MDTxxxx. */
1420 struct dt_object *child2 = NULL;
1421 const struct lu_name *cname;
1423 int node = lfsck_dev_idx(lfsck);
1427 LASSERT(lfsck->li_master);
1429 if (lfsck->li_lpf_root_obj != NULL)
1433 parent = lfsck_object_find_by_dev(env, lfsck->li_bottom,
1436 struct lfsck_tgt_desc *ltd;
1438 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
1439 if (unlikely(ltd == NULL))
1442 parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
1448 RETURN(PTR_ERR(parent));
1450 LASSERT(dt_object_exists(parent));
1452 if (unlikely(!dt_try_as_dir(env, parent))) {
1453 lfsck_object_put(env, parent);
1455 GOTO(put, rc = -ENOTDIR);
1458 lfsck->li_lpf_root_obj = parent;
1460 rc = lfsck_scan_lpf_bad_entries(env, lfsck);
1462 CDEBUG(D_LFSCK, "%s: scan .lustre/lost+found/ "
1463 "for bad sub-directories: rc = %d\n",
1464 lfsck_lfsck2name(lfsck), rc);
1468 snprintf(name, 8, "MDT%04x", node);
1469 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
1470 (const struct dt_key *)name);
1471 if (rc == -ENOENT) {
1479 /* Invalid FID in the name entry, remove the name entry. */
1480 if (!fid_is_norm(cfid)) {
1481 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1488 child2 = lfsck_object_find_bottom(env, lfsck, cfid);
1490 GOTO(put, rc = PTR_ERR(child2));
1492 if (unlikely(!dt_object_exists(child2) ||
1493 dt_object_remote(child2)) ||
1494 !S_ISDIR(lfsck_object_type(child2))) {
1495 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1502 if (unlikely(!dt_try_as_dir(env, child2))) {
1503 lfsck_object_put(env, child2);
1509 if (fid_is_zero(&bk->lb_lpf_fid))
1512 if (likely(lu_fid_eq(cfid, &bk->lb_lpf_fid))) {
1513 if (lfsck->li_lpf_obj == NULL) {
1514 lu_object_get(&child2->do_lu);
1515 lfsck->li_lpf_obj = child2;
1518 cname = lfsck_name_get_const(env, name, strlen(name));
1519 rc = lfsck_verify_linkea(env, child2, cname, &LU_LPF_FID);
1524 if (unlikely(!fid_is_norm(&bk->lb_lpf_fid))) {
1525 struct lu_fid tfid = bk->lb_lpf_fid;
1527 /* Invalid FID record in the bookmark file, reset it. */
1528 fid_zero(&bk->lb_lpf_fid);
1529 rc = lfsck_bookmark_store(env, lfsck);
1531 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1532 " in the bookmark file: rc = %d\n",
1533 lfsck_lfsck2name(lfsck), PFID(&tfid), rc);
1541 child1 = lfsck_object_find_bottom(env, lfsck, &bk->lb_lpf_fid);
1542 if (IS_ERR(child1)) {
1547 if (unlikely(!dt_object_exists(child1) ||
1548 dt_object_remote(child1)) ||
1549 !S_ISDIR(lfsck_object_type(child1))) {
1550 /* Invalid FID record in the bookmark file, reset it. */
1551 fid_zero(&bk->lb_lpf_fid);
1552 rc = lfsck_bookmark_store(env, lfsck);
1554 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1555 " in the bookmark file: rc = %d\n",
1556 lfsck_lfsck2name(lfsck),
1557 PFID(lfsck_dto2fid(child1)), rc);
1562 lfsck_object_put(env, child1);
1567 if (unlikely(!dt_try_as_dir(env, child1))) {
1568 lfsck_object_put(env, child1);
1574 rc = lfsck_verify_lpf_pairs(env, lfsck, child1, name, pfid,
1576 if (lu_fid_eq(pfid, &LU_LPF_FID))
1581 rc = lfsck_verify_lpf_pairs(env, lfsck, child2, name,
1582 pfid, LVLT_BY_NAMEENTRY);
1587 if (lfsck->li_lpf_obj != NULL) {
1588 if (unlikely(!dt_try_as_dir(env, lfsck->li_lpf_obj))) {
1589 lfsck_object_put(env, lfsck->li_lpf_obj);
1590 lfsck->li_lpf_obj = NULL;
1593 } else if (rc == 0) {
1594 rc = lfsck_create_lpf(env, lfsck);
1597 if (child2 != NULL && !IS_ERR(child2))
1598 lfsck_object_put(env, child2);
1599 if (child1 != NULL && !IS_ERR(child1))
1600 lfsck_object_put(env, child1);
1605 static int lfsck_fid_init(struct lfsck_instance *lfsck)
1607 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1608 struct seq_server_site *ss = lfsck_dev_site(lfsck);
1613 if (unlikely(ss == NULL))
1616 OBD_ALLOC_PTR(lfsck->li_seq);
1617 if (lfsck->li_seq == NULL)
1620 OBD_ALLOC(prefix, MAX_OBD_NAME + 7);
1622 GOTO(out, rc = -ENOMEM);
1624 snprintf(prefix, MAX_OBD_NAME + 7, "lfsck-%s", lfsck_lfsck2name(lfsck));
1625 rc = seq_client_init(lfsck->li_seq, NULL, LUSTRE_SEQ_METADATA, prefix,
1627 OBD_FREE(prefix, MAX_OBD_NAME + 7);
1631 if (fid_is_sane(&bk->lb_last_fid))
1632 lfsck->li_seq->lcs_fid = bk->lb_last_fid;
1637 OBD_FREE_PTR(lfsck->li_seq);
1638 lfsck->li_seq = NULL;
1643 static void lfsck_fid_fini(struct lfsck_instance *lfsck)
1645 if (lfsck->li_seq != NULL) {
1646 seq_client_fini(lfsck->li_seq);
1647 OBD_FREE_PTR(lfsck->li_seq);
1648 lfsck->li_seq = NULL;
1652 void lfsck_instance_cleanup(const struct lu_env *env,
1653 struct lfsck_instance *lfsck)
1655 struct ptlrpc_thread *thread = &lfsck->li_thread;
1656 struct lfsck_component *com;
1657 struct lfsck_component *next;
1658 struct lfsck_lmv_unit *llu;
1659 struct lfsck_lmv_unit *llu_next;
1660 struct lfsck_lmv *llmv;
1663 LASSERT(list_empty(&lfsck->li_link));
1664 LASSERT(thread_is_init(thread) || thread_is_stopped(thread));
1666 if (lfsck->li_obj_oit != NULL) {
1667 lfsck_object_put(env, lfsck->li_obj_oit);
1668 lfsck->li_obj_oit = NULL;
1671 LASSERT(lfsck->li_obj_dir == NULL);
1672 LASSERT(lfsck->li_lmv == NULL);
1674 list_for_each_entry_safe(llu, llu_next, &lfsck->li_list_lmv, llu_link) {
1675 llmv = &llu->llu_lmv;
1677 LASSERTF(atomic_read(&llmv->ll_ref) == 1,
1678 "still in using: %u\n",
1679 atomic_read(&llmv->ll_ref));
1681 lfsck_lmv_put(env, llmv);
1684 list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
1685 lfsck_component_cleanup(env, com);
1688 LASSERT(list_empty(&lfsck->li_list_dir));
1690 list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
1692 lfsck_component_cleanup(env, com);
1695 list_for_each_entry_safe(com, next, &lfsck->li_list_idle, lc_link) {
1696 lfsck_component_cleanup(env, com);
1699 lfsck_tgt_descs_fini(&lfsck->li_ost_descs);
1700 lfsck_tgt_descs_fini(&lfsck->li_mdt_descs);
1702 if (lfsck->li_lfsck_dir != NULL) {
1703 lfsck_object_put(env, lfsck->li_lfsck_dir);
1704 lfsck->li_lfsck_dir = NULL;
1707 if (lfsck->li_bookmark_obj != NULL) {
1708 lfsck_object_put(env, lfsck->li_bookmark_obj);
1709 lfsck->li_bookmark_obj = NULL;
1712 if (lfsck->li_lpf_obj != NULL) {
1713 lfsck_object_put(env, lfsck->li_lpf_obj);
1714 lfsck->li_lpf_obj = NULL;
1717 if (lfsck->li_lpf_root_obj != NULL) {
1718 lfsck_object_put(env, lfsck->li_lpf_root_obj);
1719 lfsck->li_lpf_root_obj = NULL;
1722 if (lfsck->li_los != NULL) {
1723 local_oid_storage_fini(env, lfsck->li_los);
1724 lfsck->li_los = NULL;
1727 lfsck_fid_fini(lfsck);
1729 OBD_FREE_PTR(lfsck);
1732 static inline struct lfsck_instance *
1733 __lfsck_instance_find(struct dt_device *key, bool ref, bool unlink)
1735 struct lfsck_instance *lfsck;
1737 list_for_each_entry(lfsck, &lfsck_instance_list, li_link) {
1738 if (lfsck->li_bottom == key) {
1740 lfsck_instance_get(lfsck);
1742 list_del_init(&lfsck->li_link);
1751 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
1754 struct lfsck_instance *lfsck;
1756 spin_lock(&lfsck_instance_lock);
1757 lfsck = __lfsck_instance_find(key, ref, unlink);
1758 spin_unlock(&lfsck_instance_lock);
1763 static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
1765 struct lfsck_instance *tmp;
1767 spin_lock(&lfsck_instance_lock);
1768 list_for_each_entry(tmp, &lfsck_instance_list, li_link) {
1769 if (lfsck->li_bottom == tmp->li_bottom) {
1770 spin_unlock(&lfsck_instance_lock);
1775 list_add_tail(&lfsck->li_link, &lfsck_instance_list);
1776 spin_unlock(&lfsck_instance_lock);
1780 void lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
1785 bool newline = (bits != 0 ? false : true);
1787 seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
1789 for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
1792 if (names[i] != NULL) {
1796 seq_printf(m, "%s%c", names[i],
1797 newline ? '\n' : ',');
1806 void lfsck_time_dump(struct seq_file *m, time64_t time, const char *name)
1809 seq_printf(m, "%s_time: N/A\n", name);
1810 seq_printf(m, "time_since_%s: N/A\n", name);
1812 seq_printf(m, "%s_time: %lld\n", name, time);
1813 seq_printf(m, "time_since_%s: %lld seconds\n",
1814 name, ktime_get_real_seconds() - time);
1818 void lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
1821 if (fid_is_zero(&pos->lp_dir_parent)) {
1822 if (pos->lp_oit_cookie == 0) {
1823 seq_printf(m, "%s: N/A, N/A, N/A\n", prefix);
1826 seq_printf(m, "%s: %llu, N/A, N/A\n",
1827 prefix, pos->lp_oit_cookie);
1829 seq_printf(m, "%s: %llu, "DFID", %#llx\n",
1830 prefix, pos->lp_oit_cookie,
1831 PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
1835 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
1836 struct lfsck_position *pos, bool init)
1838 const struct dt_it_ops *iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
1840 if (unlikely(lfsck->li_di_oit == NULL)) {
1841 memset(pos, 0, sizeof(*pos));
1845 pos->lp_oit_cookie = iops->store(env, lfsck->li_di_oit);
1846 if (!lfsck->li_current_oit_processed && !init)
1847 pos->lp_oit_cookie--;
1849 if (unlikely(pos->lp_oit_cookie == 0))
1850 pos->lp_oit_cookie = 1;
1852 if (lfsck->li_di_dir != NULL) {
1853 struct dt_object *dto = lfsck->li_obj_dir;
1855 pos->lp_dir_cookie = dto->do_index_ops->dio_it.store(env,
1858 if (pos->lp_dir_cookie >= MDS_DIR_END_OFF) {
1859 fid_zero(&pos->lp_dir_parent);
1860 pos->lp_dir_cookie = 0;
1862 pos->lp_dir_parent = *lfsck_dto2fid(dto);
1865 fid_zero(&pos->lp_dir_parent);
1866 pos->lp_dir_cookie = 0;
1870 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
1874 if (limit != LFSCK_SPEED_NO_LIMIT) {
1875 if (limit > cfs_time_seconds(1)) {
1876 lfsck->li_sleep_rate = limit / cfs_time_seconds(1);
1877 lfsck->li_sleep_jif = 1;
1879 lfsck->li_sleep_rate = 1;
1880 lfsck->li_sleep_jif = cfs_time_seconds(1) / limit;
1883 lfsck->li_sleep_jif = 0;
1884 lfsck->li_sleep_rate = 0;
1887 if (lfsck->li_bookmark_ram.lb_speed_limit != limit) {
1888 lfsck->li_bookmark_ram.lb_speed_limit = limit;
1895 void lfsck_control_speed(struct lfsck_instance *lfsck)
1897 struct ptlrpc_thread *thread = &lfsck->li_thread;
1898 struct l_wait_info lwi;
1900 if (lfsck->li_sleep_jif > 0 &&
1901 lfsck->li_new_scanned >= lfsck->li_sleep_rate) {
1902 lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
1903 LWI_ON_SIGNAL_NOOP, NULL);
1905 l_wait_event(thread->t_ctl_waitq,
1906 !thread_is_running(thread),
1908 lfsck->li_new_scanned = 0;
1912 void lfsck_control_speed_by_self(struct lfsck_component *com)
1914 struct lfsck_instance *lfsck = com->lc_lfsck;
1915 struct ptlrpc_thread *thread = &lfsck->li_thread;
1916 struct l_wait_info lwi;
1918 if (lfsck->li_sleep_jif > 0 &&
1919 com->lc_new_scanned >= lfsck->li_sleep_rate) {
1920 lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
1921 LWI_ON_SIGNAL_NOOP, NULL);
1923 l_wait_event(thread->t_ctl_waitq,
1924 !thread_is_running(thread),
1926 com->lc_new_scanned = 0;
1930 static struct lfsck_thread_args *
1931 lfsck_thread_args_init(struct lfsck_instance *lfsck,
1932 struct lfsck_component *com,
1933 struct lfsck_start_param *lsp)
1935 struct lfsck_thread_args *lta;
1940 return ERR_PTR(-ENOMEM);
1942 rc = lu_env_init(<a->lta_env, LCT_MD_THREAD | LCT_DT_THREAD);
1948 lta->lta_lfsck = lfsck_instance_get(lfsck);
1950 lta->lta_com = lfsck_component_get(com);
1957 void lfsck_thread_args_fini(struct lfsck_thread_args *lta)
1959 if (lta->lta_com != NULL)
1960 lfsck_component_put(<a->lta_env, lta->lta_com);
1961 lfsck_instance_put(<a->lta_env, lta->lta_lfsck);
1962 lu_env_fini(<a->lta_env);
1966 struct lfsck_assistant_data *
1967 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
1970 struct lfsck_assistant_data *lad;
1974 lad->lad_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
1975 if (lad->lad_bitmap == NULL) {
1980 INIT_LIST_HEAD(&lad->lad_req_list);
1981 spin_lock_init(&lad->lad_lock);
1982 INIT_LIST_HEAD(&lad->lad_ost_list);
1983 INIT_LIST_HEAD(&lad->lad_ost_phase1_list);
1984 INIT_LIST_HEAD(&lad->lad_ost_phase2_list);
1985 INIT_LIST_HEAD(&lad->lad_mdt_list);
1986 INIT_LIST_HEAD(&lad->lad_mdt_phase1_list);
1987 INIT_LIST_HEAD(&lad->lad_mdt_phase2_list);
1988 init_waitqueue_head(&lad->lad_thread.t_ctl_waitq);
1990 lad->lad_name = name;
1996 struct lfsck_assistant_object *
1997 lfsck_assistant_object_init(const struct lu_env *env, const struct lu_fid *fid,
1998 const struct lu_attr *attr, __u64 cookie,
2001 struct lfsck_assistant_object *lso;
2005 return ERR_PTR(-ENOMEM);
2007 lso->lso_fid = *fid;
2009 lso->lso_attr = *attr;
2011 atomic_set(&lso->lso_ref, 1);
2012 lso->lso_oit_cookie = cookie;
2014 lso->lso_is_dir = 1;
2020 lfsck_assistant_object_load(const struct lu_env *env,
2021 struct lfsck_instance *lfsck,
2022 struct lfsck_assistant_object *lso)
2024 struct dt_object *obj;
2026 obj = lfsck_object_find_bottom(env, lfsck, &lso->lso_fid);
2030 if (unlikely(!dt_object_exists(obj) || lfsck_is_dead_obj(obj))) {
2032 lfsck_object_put(env, obj);
2034 return ERR_PTR(-ENOENT);
2037 if (lso->lso_is_dir && unlikely(!dt_try_as_dir(env, obj))) {
2038 lfsck_object_put(env, obj);
2040 return ERR_PTR(-ENOTDIR);
2047 * Generic LFSCK asynchronous communication interpretor function.
2048 * The LFSCK RPC reply for both the event notification and status
2049 * querying will be handled here.
2051 * \param[in] env pointer to the thread context
2052 * \param[in] req pointer to the LFSCK request
2053 * \param[in] args pointer to the lfsck_async_interpret_args
2054 * \param[in] rc the result for handling the LFSCK request
2056 * \retval 0 for success
2057 * \retval negative error number on failure
2059 int lfsck_async_interpret_common(const struct lu_env *env,
2060 struct ptlrpc_request *req,
2063 struct lfsck_async_interpret_args *laia = args;
2064 struct lfsck_component *com = laia->laia_com;
2065 struct lfsck_assistant_data *lad = com->lc_data;
2066 struct lfsck_tgt_descs *ltds = laia->laia_ltds;
2067 struct lfsck_tgt_desc *ltd = laia->laia_ltd;
2068 struct lfsck_request *lr = laia->laia_lr;
2070 LASSERT(com->lc_lfsck->li_master);
2072 switch (lr->lr_event) {
2074 if (unlikely(rc == -EINPROGRESS)) {
2075 ltd->ltd_retry_start = 1;
2080 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s "
2082 lfsck_lfsck2name(com->lc_lfsck),
2083 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2084 ltd->ltd_index, lad->lad_name, rc);
2086 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2087 struct lfsck_layout *lo = com->lc_file_ram;
2089 if (lr->lr_flags & LEF_TO_OST)
2090 lfsck_lad_set_bitmap(env, com,
2093 lo->ll_flags |= LF_INCOMPLETE;
2095 struct lfsck_namespace *ns = com->lc_file_ram;
2097 /* If some MDT does not join the namespace
2098 * LFSCK, then we cannot know whether there
2099 * is some name entry on such MDT that with
2100 * the referenced MDT-object on this MDT or
2101 * not. So the namespace LFSCK on this MDT
2102 * cannot handle orphan MDT-objects properly.
2103 * So we mark the LFSCK as LF_INCOMPLETE and
2104 * skip orphan MDT-objects handling. */
2105 ns->ln_flags |= LF_INCOMPLETE;
2110 spin_lock(<ds->ltd_lock);
2111 if (ltd->ltd_dead) {
2112 spin_unlock(<ds->ltd_lock);
2116 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2117 struct list_head *list;
2118 struct list_head *phase_list;
2120 if (ltd->ltd_layout_done) {
2121 spin_unlock(<ds->ltd_lock);
2125 if (lr->lr_flags & LEF_TO_OST) {
2126 list = &lad->lad_ost_list;
2127 phase_list = &lad->lad_ost_phase1_list;
2129 list = &lad->lad_mdt_list;
2130 phase_list = &lad->lad_mdt_phase1_list;
2133 if (list_empty(<d->ltd_layout_list))
2134 list_add_tail(<d->ltd_layout_list, list);
2135 if (list_empty(<d->ltd_layout_phase_list))
2136 list_add_tail(<d->ltd_layout_phase_list,
2139 if (ltd->ltd_namespace_done) {
2140 spin_unlock(<ds->ltd_lock);
2144 if (list_empty(<d->ltd_namespace_list))
2145 list_add_tail(<d->ltd_namespace_list,
2146 &lad->lad_mdt_list);
2147 if (list_empty(<d->ltd_namespace_phase_list))
2148 list_add_tail(<d->ltd_namespace_phase_list,
2149 &lad->lad_mdt_phase1_list);
2151 spin_unlock(<ds->ltd_lock);
2154 case LE_PHASE1_DONE:
2155 case LE_PHASE2_DONE:
2157 if (rc != 0 && rc != -EALREADY)
2158 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s: "
2159 "event = %d, rc = %d\n",
2160 lfsck_lfsck2name(com->lc_lfsck),
2161 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2162 ltd->ltd_index, lad->lad_name, lr->lr_event, rc);
2165 struct lfsck_reply *reply;
2166 struct list_head *list;
2167 struct list_head *phase_list;
2169 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2170 list = <d->ltd_layout_list;
2171 phase_list = <d->ltd_layout_phase_list;
2173 list = <d->ltd_namespace_list;
2174 phase_list = <d->ltd_namespace_phase_list;
2178 if (lr->lr_flags & LEF_QUERY_ALL) {
2179 lfsck_reset_ltd_status(ltd, com->lc_type);
2183 spin_lock(<ds->ltd_lock);
2184 list_del_init(phase_list);
2185 list_del_init(list);
2186 spin_unlock(<ds->ltd_lock);
2190 reply = req_capsule_server_get(&req->rq_pill,
2192 if (reply == NULL) {
2194 CDEBUG(D_LFSCK, "%s: invalid query reply for %s: "
2195 "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck),
2198 if (lr->lr_flags & LEF_QUERY_ALL) {
2199 lfsck_reset_ltd_status(ltd, com->lc_type);
2203 spin_lock(<ds->ltd_lock);
2204 list_del_init(phase_list);
2205 list_del_init(list);
2206 spin_unlock(<ds->ltd_lock);
2210 if (lr->lr_flags & LEF_QUERY_ALL) {
2211 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2212 ltd->ltd_layout_status = reply->lr_status;
2213 ltd->ltd_layout_repaired = reply->lr_repaired;
2215 ltd->ltd_namespace_status = reply->lr_status;
2216 ltd->ltd_namespace_repaired =
2222 switch (reply->lr_status) {
2223 case LS_SCANNING_PHASE1:
2225 case LS_SCANNING_PHASE2:
2226 spin_lock(<ds->ltd_lock);
2227 list_del_init(phase_list);
2228 if (ltd->ltd_dead) {
2229 spin_unlock(<ds->ltd_lock);
2233 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2234 if (ltd->ltd_layout_done) {
2235 spin_unlock(<ds->ltd_lock);
2239 if (lr->lr_flags & LEF_TO_OST)
2240 list_add_tail(phase_list,
2241 &lad->lad_ost_phase2_list);
2243 list_add_tail(phase_list,
2244 &lad->lad_mdt_phase2_list);
2246 if (ltd->ltd_namespace_done) {
2247 spin_unlock(<ds->ltd_lock);
2251 list_add_tail(phase_list,
2252 &lad->lad_mdt_phase2_list);
2254 spin_unlock(<ds->ltd_lock);
2257 spin_lock(<ds->ltd_lock);
2258 list_del_init(phase_list);
2259 list_del_init(list);
2260 spin_unlock(<ds->ltd_lock);
2266 CDEBUG(D_LFSCK, "%s: unexpected event: rc = %d\n",
2267 lfsck_lfsck2name(com->lc_lfsck), lr->lr_event);
2271 if (!laia->laia_shared) {
2273 lfsck_component_put(env, com);
2279 static void lfsck_interpret(const struct lu_env *env,
2280 struct lfsck_instance *lfsck,
2281 struct ptlrpc_request *req, void *args, int result)
2283 struct lfsck_async_interpret_args *laia = args;
2284 struct lfsck_component *com;
2286 LASSERT(laia->laia_com == NULL);
2287 LASSERT(laia->laia_shared);
2289 spin_lock(&lfsck->li_lock);
2290 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
2291 laia->laia_com = com;
2292 lfsck_async_interpret_common(env, req, laia, result);
2295 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
2296 laia->laia_com = com;
2297 lfsck_async_interpret_common(env, req, laia, result);
2299 spin_unlock(&lfsck->li_lock);
2302 static int lfsck_stop_notify(const struct lu_env *env,
2303 struct lfsck_instance *lfsck,
2304 struct lfsck_tgt_descs *ltds,
2305 struct lfsck_tgt_desc *ltd, __u16 type)
2307 struct lfsck_component *com;
2311 LASSERT(lfsck->li_master);
2313 spin_lock(&lfsck->li_lock);
2314 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
2316 com = __lfsck_component_find(lfsck, type,
2317 &lfsck->li_list_double_scan);
2319 lfsck_component_get(com);
2320 spin_unlock(&lfsck->li_lock);
2323 struct lfsck_thread_info *info = lfsck_env_info(env);
2324 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2325 struct lfsck_request *lr = &info->lti_lr;
2326 struct lfsck_assistant_data *lad = com->lc_data;
2327 struct list_head *list;
2328 struct list_head *phase_list;
2329 struct ptlrpc_request_set *set;
2331 set = ptlrpc_prep_set();
2333 lfsck_component_put(env, com);
2338 if (type == LFSCK_TYPE_LAYOUT) {
2339 list = <d->ltd_layout_list;
2340 phase_list = <d->ltd_layout_phase_list;
2342 list = <d->ltd_namespace_list;
2343 phase_list = <d->ltd_namespace_phase_list;
2346 spin_lock(<ds->ltd_lock);
2347 if (list_empty(list)) {
2348 LASSERT(list_empty(phase_list));
2349 spin_unlock(<ds->ltd_lock);
2350 ptlrpc_set_destroy(set);
2355 list_del_init(phase_list);
2356 list_del_init(list);
2357 spin_unlock(<ds->ltd_lock);
2359 memset(lr, 0, sizeof(*lr));
2360 lr->lr_index = lfsck_dev_idx(lfsck);
2361 lr->lr_event = LE_PEER_EXIT;
2362 lr->lr_active = type;
2363 lr->lr_status = LS_CO_PAUSED;
2364 if (ltds == &lfsck->li_ost_descs)
2365 lr->lr_flags = LEF_TO_OST;
2367 memset(laia, 0, sizeof(*laia));
2368 laia->laia_com = com;
2369 laia->laia_ltds = ltds;
2370 atomic_inc(<d->ltd_ref);
2371 laia->laia_ltd = ltd;
2374 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2375 lfsck_async_interpret_common,
2376 laia, LFSCK_NOTIFY);
2378 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for "
2379 "co-stop for %s: rc = %d\n",
2380 lfsck_lfsck2name(lfsck),
2381 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2382 ltd->ltd_index, lad->lad_name, rc);
2385 rc = ptlrpc_set_wait(env, set);
2388 ptlrpc_set_destroy(set);
2389 lfsck_component_put(env, com);
2395 static int lfsck_async_interpret(const struct lu_env *env,
2396 struct ptlrpc_request *req,
2399 struct lfsck_async_interpret_args *laia = args;
2400 struct lfsck_instance *lfsck;
2402 lfsck = container_of0(laia->laia_ltds, struct lfsck_instance,
2404 lfsck_interpret(env, lfsck, req, laia, rc);
2405 lfsck_tgt_put(laia->laia_ltd);
2406 if (rc != 0 && laia->laia_result != -EALREADY)
2407 laia->laia_result = rc;
2412 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
2413 struct lfsck_request *lr,
2414 struct ptlrpc_request_set *set,
2415 ptlrpc_interpterer_t interpreter,
2416 void *args, int request)
2418 struct lfsck_async_interpret_args *laia;
2419 struct ptlrpc_request *req;
2420 struct lfsck_request *tmp;
2421 struct req_format *format;
2426 format = &RQF_LFSCK_NOTIFY;
2429 format = &RQF_LFSCK_QUERY;
2432 CDEBUG(D_LFSCK, "%s: unknown async request %d: rc = %d\n",
2433 exp->exp_obd->obd_name, request, -EINVAL);
2437 req = ptlrpc_request_alloc(class_exp2cliimp(exp), format);
2441 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, request);
2443 ptlrpc_request_free(req);
2448 tmp = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
2450 ptlrpc_request_set_replen(req);
2452 laia = ptlrpc_req_async_args(laia, req);
2453 *laia = *(struct lfsck_async_interpret_args *)args;
2454 if (laia->laia_com != NULL)
2455 lfsck_component_get(laia->laia_com);
2456 req->rq_interpret_reply = interpreter;
2457 req->rq_allow_intr = 1;
2458 req->rq_no_delay = 1;
2459 ptlrpc_set_add_req(set, req);
2464 int lfsck_query_all(const struct lu_env *env, struct lfsck_component *com)
2466 struct lfsck_thread_info *info = lfsck_env_info(env);
2467 struct lfsck_request *lr = &info->lti_lr;
2468 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2469 struct lfsck_instance *lfsck = com->lc_lfsck;
2470 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2471 struct lfsck_tgt_desc *ltd;
2472 struct ptlrpc_request_set *set;
2477 memset(lr, 0, sizeof(*lr));
2478 lr->lr_event = LE_QUERY;
2479 lr->lr_active = com->lc_type;
2480 lr->lr_flags = LEF_QUERY_ALL;
2482 memset(laia, 0, sizeof(*laia));
2483 laia->laia_com = com;
2486 set = ptlrpc_prep_set();
2491 laia->laia_ltds = ltds;
2492 down_read(<ds->ltd_rw_sem);
2493 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2494 ltd = lfsck_tgt_get(ltds, idx);
2495 LASSERT(ltd != NULL);
2497 laia->laia_ltd = ltd;
2498 up_read(<ds->ltd_rw_sem);
2499 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2500 lfsck_async_interpret_common,
2503 struct lfsck_assistant_data *lad = com->lc_data;
2505 CDEBUG(D_LFSCK, "%s: Fail to query %s %x for stat %s: "
2506 "rc = %d\n", lfsck_lfsck2name(lfsck),
2507 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2508 ltd->ltd_index, lad->lad_name, rc);
2509 lfsck_reset_ltd_status(ltd, com->lc_type);
2512 down_read(<ds->ltd_rw_sem);
2514 up_read(<ds->ltd_rw_sem);
2516 if (com->lc_type == LFSCK_TYPE_LAYOUT && !(lr->lr_flags & LEF_TO_OST)) {
2517 ltds = &lfsck->li_ost_descs;
2518 lr->lr_flags |= LEF_TO_OST;
2522 rc = ptlrpc_set_wait(env, set);
2523 ptlrpc_set_destroy(set);
2528 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
2529 struct lfsck_start_param *lsp)
2531 struct lfsck_instance *lfsck = com->lc_lfsck;
2532 struct lfsck_assistant_data *lad = com->lc_data;
2533 struct ptlrpc_thread *mthread = &lfsck->li_thread;
2534 struct ptlrpc_thread *athread = &lad->lad_thread;
2535 struct lfsck_thread_args *lta;
2536 struct task_struct *task;
2540 lad->lad_assistant_status = 0;
2541 lad->lad_post_result = 0;
2543 lad->lad_advance_lock = false;
2544 thread_set_flags(athread, 0);
2546 lta = lfsck_thread_args_init(lfsck, com, lsp);
2548 RETURN(PTR_ERR(lta));
2550 task = kthread_run(lfsck_assistant_engine, lta, lad->lad_name);
2553 CERROR("%s: cannot start LFSCK assistant thread for %s: "
2554 "rc = %d\n", lfsck_lfsck2name(lfsck), lad->lad_name, rc);
2555 lfsck_thread_args_fini(lta);
2557 wait_event_idle(mthread->t_ctl_waitq,
2558 thread_is_running(athread) ||
2559 thread_is_stopped(athread) ||
2560 !thread_is_starting(mthread));
2561 if (unlikely(!thread_is_starting(mthread)))
2562 /* stopped by race */
2564 else if (unlikely(!thread_is_running(athread)))
2565 rc = lad->lad_assistant_status;
2573 int lfsck_checkpoint_generic(const struct lu_env *env,
2574 struct lfsck_component *com)
2576 struct lfsck_assistant_data *lad = com->lc_data;
2577 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2578 struct ptlrpc_thread *athread = &lad->lad_thread;
2580 wait_event_idle(mthread->t_ctl_waitq,
2581 list_empty(&lad->lad_req_list) ||
2582 !thread_is_running(mthread) ||
2583 thread_is_stopped(athread));
2585 if (!thread_is_running(mthread) || thread_is_stopped(athread))
2586 return LFSCK_CHECKPOINT_SKIP;
2591 void lfsck_post_generic(const struct lu_env *env,
2592 struct lfsck_component *com, int *result)
2594 struct lfsck_assistant_data *lad = com->lc_data;
2595 struct ptlrpc_thread *athread = &lad->lad_thread;
2596 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2598 lad->lad_post_result = *result;
2600 set_bit(LAD_EXIT, &lad->lad_flags);
2601 set_bit(LAD_TO_POST, &lad->lad_flags);
2603 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s post, rc = %d\n",
2604 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2606 wake_up_all(&athread->t_ctl_waitq);
2607 wait_event_idle(mthread->t_ctl_waitq,
2608 (*result > 0 && list_empty(&lad->lad_req_list)) ||
2609 thread_is_stopped(athread));
2611 if (lad->lad_assistant_status < 0)
2612 *result = lad->lad_assistant_status;
2614 CDEBUG(D_LFSCK, "%s: the assistant has done %s post, rc = %d\n",
2615 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2618 int lfsck_double_scan_generic(const struct lu_env *env,
2619 struct lfsck_component *com, int status)
2621 struct lfsck_assistant_data *lad = com->lc_data;
2622 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2623 struct ptlrpc_thread *athread = &lad->lad_thread;
2625 if (status != LS_SCANNING_PHASE2)
2626 set_bit(LAD_EXIT, &lad->lad_flags);
2628 set_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags);
2630 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s double_scan, "
2632 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, status);
2634 wake_up_all(&athread->t_ctl_waitq);
2635 wait_event_idle(mthread->t_ctl_waitq,
2636 test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags) ||
2637 thread_is_stopped(athread));
2639 CDEBUG(D_LFSCK, "%s: the assistant has done %s double_scan, "
2640 "status %d\n", lfsck_lfsck2name(com->lc_lfsck), lad->lad_name,
2641 lad->lad_assistant_status);
2643 if (lad->lad_assistant_status < 0)
2644 return lad->lad_assistant_status;
2649 void lfsck_quit_generic(const struct lu_env *env,
2650 struct lfsck_component *com)
2652 struct lfsck_assistant_data *lad = com->lc_data;
2653 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2654 struct ptlrpc_thread *athread = &lad->lad_thread;
2656 set_bit(LAD_EXIT, &lad->lad_flags);
2657 wake_up_all(&athread->t_ctl_waitq);
2658 wait_event_idle(mthread->t_ctl_waitq,
2659 thread_is_init(athread) ||
2660 thread_is_stopped(athread));
2663 int lfsck_load_one_trace_file(const struct lu_env *env,
2664 struct lfsck_component *com,
2665 struct dt_object *parent,
2666 struct dt_object **child,
2667 const struct dt_index_features *ft,
2668 const char *name, bool reset)
2670 struct lfsck_instance *lfsck = com->lc_lfsck;
2671 struct dt_object *obj;
2675 if (*child != NULL) {
2677 const struct dt_it_ops *iops;
2678 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid3;
2684 rc = obj->do_ops->do_index_try(env, obj, ft);
2686 /* unlink by force */
2689 iops = &obj->do_index_ops->dio_it;
2690 it = iops->init(env, obj, 0);
2692 /* unlink by force */
2696 rc = iops->get(env, it, (const struct dt_key *)fid);
2698 rc = iops->next(env, it);
2701 iops->fini(env, it);
2703 /* "rc > 0" means the index file is empty. */
2707 /* The old index is not empty, remove it firstly. */
2708 rc = local_object_unlink(env, lfsck->li_bottom, parent, name);
2709 CDEBUG_LIMIT(rc ? D_ERROR : D_LFSCK,
2710 "%s: unlink lfsck sub trace file %s: rc = %d\n",
2711 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2716 lfsck_object_put(env, *child);
2723 obj = local_index_find_or_create(env, lfsck->li_los, parent, name,
2724 S_IFREG | S_IRUGO | S_IWUSR, ft);
2726 RETURN(PTR_ERR(obj));
2728 rc = obj->do_ops->do_index_try(env, obj, ft);
2730 lfsck_object_put(env, obj);
2731 CDEBUG(D_LFSCK, "%s: LFSCK fail to load "
2732 "sub trace file %s: rc = %d\n",
2733 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2741 int lfsck_load_sub_trace_files(const struct lu_env *env,
2742 struct lfsck_component *com,
2743 const struct dt_index_features *ft,
2744 const char *prefix, bool reset)
2746 char *name = lfsck_env_info(env)->lti_key;
2747 struct lfsck_sub_trace_obj *lsto;
2751 for (i = 0, rc = 0, lsto = &com->lc_sub_trace_objs[0];
2752 i < LFSCK_STF_COUNT && rc == 0; i++, lsto++) {
2753 snprintf(name, NAME_MAX, "%s_%02d", prefix, i);
2754 rc = lfsck_load_one_trace_file(env, com,
2755 com->lc_lfsck->li_lfsck_dir,
2756 &lsto->lsto_obj, ft, name, reset);
2762 /* external interfaces */
2763 int lfsck_get_speed(char *buf, struct dt_device *key)
2766 struct lfsck_instance *lfsck;
2770 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2774 lfsck = lfsck_instance_find(key, true, false);
2776 rc = sprintf(buf, "%u\n",
2777 lfsck->li_bookmark_ram.lb_speed_limit);
2778 lfsck_instance_put(&env, lfsck);
2787 EXPORT_SYMBOL(lfsck_get_speed);
2789 int lfsck_set_speed(struct dt_device *key, __u32 val)
2792 struct lfsck_instance *lfsck;
2796 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2800 lfsck = lfsck_instance_find(key, true, false);
2801 if (likely(lfsck != NULL)) {
2802 mutex_lock(&lfsck->li_mutex);
2803 if (__lfsck_set_speed(lfsck, val))
2804 rc = lfsck_bookmark_store(&env, lfsck);
2805 mutex_unlock(&lfsck->li_mutex);
2806 lfsck_instance_put(&env, lfsck);
2815 EXPORT_SYMBOL(lfsck_set_speed);
2817 int lfsck_get_windows(char *buf, struct dt_device *key)
2820 struct lfsck_instance *lfsck;
2824 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2828 lfsck = lfsck_instance_find(key, true, false);
2829 if (likely(lfsck != NULL)) {
2830 rc = sprintf(buf, "%u\n",
2831 lfsck->li_bookmark_ram.lb_async_windows);
2832 lfsck_instance_put(&env, lfsck);
2841 EXPORT_SYMBOL(lfsck_get_windows);
2843 int lfsck_set_windows(struct dt_device *key, unsigned int val)
2846 struct lfsck_instance *lfsck;
2850 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2854 lfsck = lfsck_instance_find(key, true, false);
2855 if (likely(lfsck != NULL)) {
2856 if (val < 1 || val > LFSCK_ASYNC_WIN_MAX) {
2857 CWARN("%s: invalid async windows size that may "
2858 "cause memory issues. The valid range is "
2860 lfsck_lfsck2name(lfsck), LFSCK_ASYNC_WIN_MAX);
2862 } else if (lfsck->li_bookmark_ram.lb_async_windows != val) {
2863 mutex_lock(&lfsck->li_mutex);
2864 lfsck->li_bookmark_ram.lb_async_windows = val;
2865 rc = lfsck_bookmark_store(&env, lfsck);
2866 mutex_unlock(&lfsck->li_mutex);
2868 lfsck_instance_put(&env, lfsck);
2877 EXPORT_SYMBOL(lfsck_set_windows);
2879 int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
2882 struct lfsck_instance *lfsck;
2883 struct lfsck_component *com;
2887 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2891 lfsck = lfsck_instance_find(key, true, false);
2892 if (likely(lfsck != NULL)) {
2893 com = lfsck_component_find(lfsck, type);
2894 if (likely(com != NULL)) {
2895 com->lc_ops->lfsck_dump(&env, com, m);
2896 lfsck_component_put(&env, com);
2901 lfsck_instance_put(&env, lfsck);
2910 EXPORT_SYMBOL(lfsck_dump);
2912 static int lfsck_stop_all(const struct lu_env *env,
2913 struct lfsck_instance *lfsck,
2914 struct lfsck_stop *stop)
2916 struct lfsck_thread_info *info = lfsck_env_info(env);
2917 struct lfsck_request *lr = &info->lti_lr;
2918 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2919 struct ptlrpc_request_set *set;
2920 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2921 struct lfsck_tgt_desc *ltd;
2922 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2928 LASSERT(stop->ls_flags & LPF_BROADCAST);
2930 set = ptlrpc_prep_set();
2931 if (unlikely(set == NULL))
2934 memset(lr, 0, sizeof(*lr));
2935 lr->lr_event = LE_STOP;
2936 lr->lr_index = lfsck_dev_idx(lfsck);
2937 lr->lr_status = stop->ls_status;
2938 lr->lr_version = bk->lb_version;
2939 lr->lr_active = LFSCK_TYPES_ALL;
2940 lr->lr_param = stop->ls_flags;
2942 memset(laia, 0, sizeof(*laia));
2943 laia->laia_ltds = ltds;
2945 laia->laia_shared = 1;
2947 down_read(<ds->ltd_rw_sem);
2948 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2949 ltd = lfsck_tgt_get(ltds, idx);
2950 LASSERT(ltd != NULL);
2952 laia->laia_ltd = ltd;
2953 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2954 lfsck_async_interpret, laia,
2957 lfsck_interpret(env, lfsck, NULL, laia, rc);
2959 CERROR("%s: cannot notify MDT %x for LFSCK stop: "
2960 "rc = %d\n", lfsck_lfsck2name(lfsck), idx, rc);
2964 up_read(<ds->ltd_rw_sem);
2966 rc = ptlrpc_set_wait(env, set);
2967 ptlrpc_set_destroy(set);
2970 rc = laia->laia_result;
2972 if (rc == -EALREADY)
2976 CERROR("%s: fail to stop LFSCK on some MDTs: rc = %d\n",
2977 lfsck_lfsck2name(lfsck), rc);
2979 RETURN(rc != 0 ? rc : rc1);
2982 static int lfsck_start_all(const struct lu_env *env,
2983 struct lfsck_instance *lfsck,
2984 struct lfsck_start *start)
2986 struct lfsck_thread_info *info = lfsck_env_info(env);
2987 struct lfsck_request *lr = &info->lti_lr;
2988 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2989 struct ptlrpc_request_set *set;
2990 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2991 struct lfsck_tgt_desc *ltd;
2992 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2998 LASSERT(start->ls_flags & LPF_BROADCAST);
3000 memset(lr, 0, sizeof(*lr));
3001 lr->lr_event = LE_START;
3002 lr->lr_index = lfsck_dev_idx(lfsck);
3003 lr->lr_speed = bk->lb_speed_limit;
3004 lr->lr_version = bk->lb_version;
3005 lr->lr_active = start->ls_active;
3006 lr->lr_param = start->ls_flags;
3007 lr->lr_async_windows = bk->lb_async_windows;
3008 lr->lr_valid = LSV_SPEED_LIMIT | LSV_ERROR_HANDLE | LSV_DRYRUN |
3009 LSV_ASYNC_WINDOWS | LSV_CREATE_OSTOBJ |
3012 memset(laia, 0, sizeof(*laia));
3013 laia->laia_ltds = ltds;
3015 laia->laia_shared = 1;
3018 set = ptlrpc_prep_set();
3022 down_read(<ds->ltd_rw_sem);
3023 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3024 ltd = lfsck_tgt_get(ltds, idx);
3025 LASSERT(ltd != NULL);
3027 if (retry && !ltd->ltd_retry_start) {
3032 laia->laia_ltd = ltd;
3033 ltd->ltd_retry_start = 0;
3034 ltd->ltd_layout_done = 0;
3035 ltd->ltd_namespace_done = 0;
3036 ltd->ltd_synced_failures = 0;
3037 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
3038 lfsck_async_interpret, laia,
3041 lfsck_interpret(env, lfsck, NULL, laia, rc);
3043 CERROR("%s: cannot notify MDT %x for LFSCK "
3044 "start, failout: rc = %d\n",
3045 lfsck_lfsck2name(lfsck), idx, rc);
3049 up_read(<ds->ltd_rw_sem);
3052 ptlrpc_set_destroy(set);
3057 rc = ptlrpc_set_wait(env, set);
3058 ptlrpc_set_destroy(set);
3061 rc = laia->laia_result;
3063 if (unlikely(rc == -EINPROGRESS)) {
3065 set_current_state(TASK_INTERRUPTIBLE);
3066 schedule_timeout(cfs_time_seconds(1));
3067 set_current_state(TASK_RUNNING);
3068 if (!signal_pending(current) &&
3069 thread_is_running(&lfsck->li_thread))
3076 struct lfsck_stop *stop = &info->lti_stop;
3078 CERROR("%s: cannot start LFSCK on some MDTs, "
3079 "stop all: rc = %d\n",
3080 lfsck_lfsck2name(lfsck), rc);
3081 if (rc != -EALREADY) {
3082 stop->ls_status = LS_FAILED;
3083 stop->ls_flags = LPF_ALL_TGT | LPF_BROADCAST;
3084 lfsck_stop_all(env, lfsck, stop);
3091 int lfsck_start(const struct lu_env *env, struct dt_device *key,
3092 struct lfsck_start_param *lsp)
3094 struct lfsck_start *start = lsp->lsp_start;
3095 struct lfsck_instance *lfsck;
3096 struct lfsck_bookmark *bk;
3097 struct ptlrpc_thread *thread;
3098 struct lfsck_component *com;
3099 struct lfsck_thread_args *lta;
3100 struct task_struct *task;
3101 struct lfsck_tgt_descs *ltds;
3102 struct lfsck_tgt_desc *ltd;
3113 lfsck = lfsck_instance_find(key, true, false);
3114 if (unlikely(lfsck == NULL))
3117 if (unlikely(lfsck->li_stopping))
3118 GOTO(put, rc = -ENXIO);
3120 /* System is not ready, try again later. */
3121 if (unlikely(lfsck->li_namespace == NULL ||
3122 lfsck_dev_site(lfsck)->ss_server_fld == NULL))
3123 GOTO(put, rc = -EINPROGRESS);
3125 /* start == NULL means auto trigger paused LFSCK. */
3127 if (list_empty(&lfsck->li_list_scan) ||
3128 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AUTO))
3130 } else if (start->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3131 CERROR("%s: only allow to specify '-A | -o' via MDS\n",
3132 lfsck_lfsck2name(lfsck));
3134 GOTO(put, rc = -EPERM);
3137 bk = &lfsck->li_bookmark_ram;
3138 thread = &lfsck->li_thread;
3139 mutex_lock(&lfsck->li_mutex);
3140 spin_lock(&lfsck->li_lock);
3141 if (unlikely(thread_is_stopping(thread))) {
3142 /* Someone is stopping the LFSCK. */
3143 spin_unlock(&lfsck->li_lock);
3144 GOTO(out, rc = -EBUSY);
3147 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
3149 if (unlikely(start == NULL)) {
3150 spin_unlock(&lfsck->li_lock);
3154 while (start->ls_active != 0) {
3155 if (!(type & start->ls_active)) {
3160 com = __lfsck_component_find(lfsck, type,
3161 &lfsck->li_list_scan);
3163 com = __lfsck_component_find(lfsck, type,
3164 &lfsck->li_list_double_scan);
3170 if (com->lc_ops->lfsck_join != NULL) {
3171 rc = com->lc_ops->lfsck_join( env, com, lsp);
3172 if (rc != 0 && rc != -EALREADY)
3175 start->ls_active &= ~type;
3178 spin_unlock(&lfsck->li_lock);
3181 spin_unlock(&lfsck->li_lock);
3183 lfsck->li_status = 0;
3184 lfsck->li_oit_over = 0;
3185 lfsck->li_start_unplug = 0;
3186 lfsck->li_drop_dryrun = 0;
3187 lfsck->li_new_scanned = 0;
3189 /* For auto trigger. */
3193 start->ls_version = bk->lb_version;
3195 if (start->ls_active != 0) {
3196 struct lfsck_component *next;
3198 if (start->ls_active == LFSCK_TYPES_ALL)
3199 start->ls_active = LFSCK_TYPES_SUPPORTED;
3201 if (start->ls_active & ~LFSCK_TYPES_SUPPORTED) {
3202 start->ls_active &= ~LFSCK_TYPES_SUPPORTED;
3203 GOTO(out, rc = -ENOTSUPP);
3206 list_for_each_entry_safe(com, next,
3207 &lfsck->li_list_scan, lc_link) {
3208 if (!(com->lc_type & start->ls_active)) {
3209 rc = com->lc_ops->lfsck_post(env, com, 0,
3216 while (start->ls_active != 0) {
3217 if (type & start->ls_active) {
3218 com = __lfsck_component_find(lfsck, type,
3219 &lfsck->li_list_idle);
3221 /* The component status will be updated
3222 * when its prep() is called later by
3223 * the LFSCK main engine. */
3224 list_move_tail(&com->lc_link,
3225 &lfsck->li_list_scan);
3226 start->ls_active &= ~type;
3232 if (list_empty(&lfsck->li_list_scan)) {
3233 /* The speed limit will be used to control both the LFSCK and
3234 * low layer scrub (if applied), need to be handled firstly. */
3235 if (start->ls_valid & LSV_SPEED_LIMIT) {
3236 if (__lfsck_set_speed(lfsck, start->ls_speed_limit)) {
3237 rc = lfsck_bookmark_store(env, lfsck);
3246 if (start->ls_flags & LPF_RESET)
3247 flags |= DOIF_RESET;
3249 rc = lfsck_set_param(env, lfsck, start, !!(flags & DOIF_RESET));
3253 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3254 start->ls_active |= com->lc_type;
3255 if (flags & DOIF_RESET) {
3256 rc = com->lc_ops->lfsck_reset(env, com, false);
3262 ltds = &lfsck->li_mdt_descs;
3263 down_read(<ds->ltd_rw_sem);
3264 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3265 ltd = lfsck_ltd2tgt(ltds, idx);
3266 LASSERT(ltd != NULL);
3268 ltd->ltd_layout_done = 0;
3269 ltd->ltd_namespace_done = 0;
3270 ltd->ltd_synced_failures = 0;
3271 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_NAMESPACE);
3272 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3273 list_del_init(<d->ltd_layout_phase_list);
3274 list_del_init(<d->ltd_layout_list);
3275 list_del_init(<d->ltd_namespace_phase_list);
3276 list_del_init(<d->ltd_namespace_list);
3278 up_read(<ds->ltd_rw_sem);
3280 ltds = &lfsck->li_ost_descs;
3281 down_read(<ds->ltd_rw_sem);
3282 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3283 ltd = lfsck_ltd2tgt(ltds, idx);
3284 LASSERT(ltd != NULL);
3286 ltd->ltd_layout_done = 0;
3287 ltd->ltd_synced_failures = 0;
3288 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3289 list_del_init(<d->ltd_layout_phase_list);
3290 list_del_init(<d->ltd_layout_list);
3292 up_read(<ds->ltd_rw_sem);
3295 lfsck->li_args_dir = LUDA_64BITHASH | LUDA_VERIFY | LUDA_TYPE;
3296 if (bk->lb_param & LPF_DRYRUN)
3297 lfsck->li_args_dir |= LUDA_VERIFY_DRYRUN;
3299 if (start != NULL && start->ls_valid & LSV_ERROR_HANDLE) {
3300 valid |= DOIV_ERROR_HANDLE;
3301 if (start->ls_flags & LPF_FAILOUT)
3302 flags |= DOIF_FAILOUT;
3305 if (start != NULL && start->ls_valid & LSV_DRYRUN) {
3306 valid |= DOIV_DRYRUN;
3307 if (start->ls_flags & LPF_DRYRUN)
3308 flags |= DOIF_DRYRUN;
3311 if (!list_empty(&lfsck->li_list_scan))
3312 flags |= DOIF_OUTUSED;
3314 lfsck->li_args_oit = (flags << DT_OTABLE_IT_FLAGS_SHIFT) | valid;
3315 lta = lfsck_thread_args_init(lfsck, NULL, lsp);
3317 GOTO(out, rc = PTR_ERR(lta));
3319 __lfsck_set_speed(lfsck, bk->lb_speed_limit);
3320 spin_lock(&lfsck->li_lock);
3321 thread_set_flags(thread, SVC_STARTING);
3322 spin_unlock(&lfsck->li_lock);
3323 task = kthread_run(lfsck_master_engine, lta, "lfsck");
3326 CERROR("%s: cannot start LFSCK thread: rc = %d\n",
3327 lfsck_lfsck2name(lfsck), rc);
3328 lfsck_thread_args_fini(lta);
3333 wait_event_idle(thread->t_ctl_waitq,
3334 thread_is_running(thread) ||
3335 thread_is_stopped(thread));
3336 if (start == NULL || !(start->ls_flags & LPF_BROADCAST)) {
3337 lfsck->li_start_unplug = 1;
3338 wake_up_all(&thread->t_ctl_waitq);
3343 /* release lfsck::li_mutex to avoid deadlock. */
3344 mutex_unlock(&lfsck->li_mutex);
3345 rc = lfsck_start_all(env, lfsck, start);
3347 spin_lock(&lfsck->li_lock);
3348 if (thread_is_stopped(thread)) {
3349 spin_unlock(&lfsck->li_lock);
3351 lfsck->li_status = LS_FAILED;
3352 lfsck->li_flags = 0;
3353 thread_set_flags(thread, SVC_STOPPING);
3354 spin_unlock(&lfsck->li_lock);
3356 lfsck->li_start_unplug = 1;
3357 wake_up_all(&thread->t_ctl_waitq);
3358 wait_event_idle(thread->t_ctl_waitq,
3359 thread_is_stopped(thread));
3362 lfsck->li_start_unplug = 1;
3363 wake_up_all(&thread->t_ctl_waitq);
3369 mutex_unlock(&lfsck->li_mutex);
3372 lfsck_instance_put(env, lfsck);
3374 return rc < 0 ? rc : 0;
3376 EXPORT_SYMBOL(lfsck_start);
3378 int lfsck_stop(const struct lu_env *env, struct dt_device *key,
3379 struct lfsck_stop *stop)
3381 struct lfsck_instance *lfsck;
3382 struct ptlrpc_thread *thread;
3387 lfsck = lfsck_instance_find(key, true, false);
3388 if (unlikely(lfsck == NULL))
3391 thread = &lfsck->li_thread;
3392 if (stop && stop->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3393 CERROR("%s: only allow to specify '-A' via MDS\n",
3394 lfsck_lfsck2name(lfsck));
3395 GOTO(put, rc = -EPERM);
3398 spin_lock(&lfsck->li_lock);
3399 /* The target is umounted */
3400 if (stop && stop->ls_status == LS_PAUSED)
3401 lfsck->li_stopping = 1;
3403 if (thread_is_init(thread) || thread_is_stopped(thread))
3404 /* no error if LFSCK stopped already, or not started */
3405 GOTO(unlock, rc = 0);
3407 if (thread_is_stopping(thread))
3408 /* Someone is stopping LFSCK. */
3409 GOTO(unlock, rc = -EINPROGRESS);
3412 lfsck->li_status = stop->ls_status;
3413 lfsck->li_flags = stop->ls_flags;
3415 lfsck->li_status = LS_STOPPED;
3416 lfsck->li_flags = 0;
3419 thread_set_flags(thread, SVC_STOPPING);
3421 LASSERT(lfsck->li_task != NULL);
3422 cfs_force_sig(SIGINT, lfsck->li_task);
3424 if (lfsck->li_master) {
3425 struct lfsck_component *com;
3426 struct lfsck_assistant_data *lad;
3428 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3430 spin_lock(&lad->lad_lock);
3431 if (lad->lad_task != NULL)
3432 cfs_force_sig(SIGINT, lad->lad_task);
3433 spin_unlock(&lad->lad_lock);
3436 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
3438 spin_lock(&lad->lad_lock);
3439 if (lad->lad_task != NULL)
3440 cfs_force_sig(SIGINT, lad->lad_task);
3441 spin_unlock(&lad->lad_lock);
3445 wake_up_all(&thread->t_ctl_waitq);
3446 spin_unlock(&lfsck->li_lock);
3447 if (stop && stop->ls_flags & LPF_BROADCAST)
3448 rc1 = lfsck_stop_all(env, lfsck, stop);
3450 /* It was me set the status as 'stopping' just now, if it is not
3451 * 'stopping' now, then either stopped, or re-started by race. */
3452 wait_event_idle(thread->t_ctl_waitq,
3453 !thread_is_stopping(thread));
3458 spin_unlock(&lfsck->li_lock);
3460 lfsck_instance_put(env, lfsck);
3462 return rc != 0 ? rc : rc1;
3464 EXPORT_SYMBOL(lfsck_stop);
3466 int lfsck_in_notify_local(const struct lu_env *env, struct dt_device *key,
3467 struct lfsck_req_local *lrl, struct thandle *th)
3469 struct lfsck_instance *lfsck;
3470 struct lfsck_component *com;
3471 int rc = -EOPNOTSUPP;
3474 lfsck = lfsck_instance_find(key, true, false);
3475 if (unlikely(!lfsck))
3478 com = lfsck_component_find(lfsck, lrl->lrl_active);
3479 if (likely(com && com->lc_ops->lfsck_in_notify_local)) {
3480 rc = com->lc_ops->lfsck_in_notify_local(env, com, lrl, th);
3481 lfsck_component_put(env, com);
3484 lfsck_instance_put(env, lfsck);
3488 EXPORT_SYMBOL(lfsck_in_notify_local);
3490 int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
3491 struct lfsck_request *lr)
3493 int rc = -EOPNOTSUPP;
3496 switch (lr->lr_event) {
3498 struct lfsck_start *start = &lfsck_env_info(env)->lti_start;
3499 struct lfsck_start_param lsp;
3501 memset(start, 0, sizeof(*start));
3502 start->ls_valid = lr->lr_valid;
3503 start->ls_speed_limit = lr->lr_speed;
3504 start->ls_version = lr->lr_version;
3505 start->ls_active = lr->lr_active;
3506 start->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3507 start->ls_async_windows = lr->lr_async_windows;
3509 lsp.lsp_start = start;
3510 lsp.lsp_index = lr->lr_index;
3511 lsp.lsp_index_valid = 1;
3512 rc = lfsck_start(env, key, &lsp);
3516 struct lfsck_stop *stop = &lfsck_env_info(env)->lti_stop;
3518 memset(stop, 0, sizeof(*stop));
3519 stop->ls_status = lr->lr_status;
3520 stop->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3521 rc = lfsck_stop(env, key, stop);
3524 case LE_PHASE1_DONE:
3525 case LE_PHASE2_DONE:
3527 case LE_CONDITIONAL_DESTROY:
3528 case LE_SET_LMV_MASTER:
3529 case LE_SET_LMV_SLAVE:
3530 case LE_PAIRS_VERIFY: {
3531 struct lfsck_instance *lfsck;
3532 struct lfsck_component *com;
3534 lfsck = lfsck_instance_find(key, true, false);
3535 if (unlikely(lfsck == NULL))
3538 com = lfsck_component_find(lfsck, lr->lr_active);
3540 rc = com->lc_ops->lfsck_in_notify(env, com, lr);
3541 lfsck_component_put(env, com);
3544 lfsck_instance_put(env, lfsck);
3553 EXPORT_SYMBOL(lfsck_in_notify);
3555 int lfsck_query(const struct lu_env *env, struct dt_device *key,
3556 struct lfsck_request *req, struct lfsck_reply *rep,
3557 struct lfsck_query *que)
3559 struct lfsck_instance *lfsck;
3560 struct lfsck_component *com;
3566 lfsck = lfsck_instance_find(key, true, false);
3567 if (unlikely(lfsck == NULL))
3571 if (que->lu_types == LFSCK_TYPES_ALL)
3573 LFSCK_TYPES_SUPPORTED & ~LFSCK_TYPE_SCRUB;
3575 if (que->lu_types & ~LFSCK_TYPES_SUPPORTED) {
3576 que->lu_types &= ~LFSCK_TYPES_SUPPORTED;
3578 GOTO(out, rc = -ENOTSUPP);
3581 for (i = 0, type = 1 << i; i < LFSCK_TYPE_BITS;
3582 i++, type = 1 << i) {
3583 if (!(que->lu_types & type))
3587 com = lfsck_component_find(lfsck, type);
3588 if (unlikely(com == NULL))
3589 GOTO(out, rc = -ENOTSUPP);
3591 memset(que->lu_mdts_count[i], 0,
3592 sizeof(__u32) * (LS_MAX + 1));
3593 memset(que->lu_osts_count[i], 0,
3594 sizeof(__u32) * (LS_MAX + 1));
3595 que->lu_repaired[i] = 0;
3596 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3598 lfsck_component_put(env, com);
3603 if (!(que->lu_flags & LPF_WAIT))
3606 for (i = 0, type = 1 << i; i < LFSCK_TYPE_BITS;
3607 i++, type = 1 << i) {
3608 if (!(que->lu_types & type))
3611 if (que->lu_mdts_count[i][LS_SCANNING_PHASE1] != 0 ||
3612 que->lu_mdts_count[i][LS_SCANNING_PHASE2] != 0 ||
3613 que->lu_osts_count[i][LS_SCANNING_PHASE1] != 0 ||
3614 que->lu_osts_count[i][LS_SCANNING_PHASE2] != 0) {
3615 /* If it is required to wait, then sleep
3616 * 3 seconds and try to query again.
3618 unsigned long timeout =
3619 msecs_to_jiffies(3000) + 1;
3621 !fatal_signal_pending(current))
3622 timeout = schedule_timeout_killable(
3629 com = lfsck_component_find(lfsck, req->lr_active);
3630 if (likely(com != NULL)) {
3631 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3633 lfsck_component_put(env, com);
3642 lfsck_instance_put(env, lfsck);
3645 EXPORT_SYMBOL(lfsck_query);
3647 int lfsck_register_namespace(const struct lu_env *env, struct dt_device *key,
3648 struct ldlm_namespace *ns)
3650 struct lfsck_instance *lfsck;
3653 lfsck = lfsck_instance_find(key, true, false);
3654 if (likely(lfsck != NULL)) {
3655 lfsck->li_namespace = ns;
3656 lfsck_instance_put(env, lfsck);
3662 EXPORT_SYMBOL(lfsck_register_namespace);
3664 int lfsck_register(const struct lu_env *env, struct dt_device *key,
3665 struct dt_device *next, struct obd_device *obd,
3666 lfsck_out_notify notify, void *notify_data, bool master)
3668 struct lfsck_instance *lfsck;
3669 struct dt_object *root = NULL;
3670 struct dt_object *obj = NULL;
3671 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
3675 lfsck = lfsck_instance_find(key, false, false);
3676 if (unlikely(lfsck != NULL))
3679 OBD_ALLOC_PTR(lfsck);
3683 mutex_init(&lfsck->li_mutex);
3684 spin_lock_init(&lfsck->li_lock);
3685 INIT_LIST_HEAD(&lfsck->li_link);
3686 INIT_LIST_HEAD(&lfsck->li_list_scan);
3687 INIT_LIST_HEAD(&lfsck->li_list_dir);
3688 INIT_LIST_HEAD(&lfsck->li_list_double_scan);
3689 INIT_LIST_HEAD(&lfsck->li_list_idle);
3690 INIT_LIST_HEAD(&lfsck->li_list_lmv);
3691 atomic_set(&lfsck->li_ref, 1);
3692 atomic_set(&lfsck->li_double_scan_count, 0);
3693 init_waitqueue_head(&lfsck->li_thread.t_ctl_waitq);
3694 lfsck->li_out_notify = notify;
3695 lfsck->li_out_notify_data = notify_data;
3696 lfsck->li_next = next;
3697 lfsck->li_bottom = key;
3698 lfsck->li_obd = obd;
3700 rc = lfsck_tgt_descs_init(&lfsck->li_ost_descs);
3704 rc = lfsck_tgt_descs_init(&lfsck->li_mdt_descs);
3708 fid->f_seq = FID_SEQ_LOCAL_NAME;
3711 rc = local_oid_storage_init(env, key, fid, &lfsck->li_los);
3715 rc = dt_root_get(env, key, fid);
3719 root = dt_locate(env, key, fid);
3721 GOTO(out, rc = PTR_ERR(root));
3723 if (unlikely(!dt_try_as_dir(env, root)))
3724 GOTO(out, rc = -ENOTDIR);
3726 lfsck->li_local_root_fid = *fid;
3728 lfsck->li_master = 1;
3729 if (lfsck_dev_idx(lfsck) == 0) {
3730 struct lu_fid *pfid = &lfsck_env_info(env)->lti_fid2;
3731 const struct lu_name *cname;
3733 rc = dt_lookup(env, root,
3734 (struct dt_rec *)(&lfsck->li_global_root_fid),
3735 (const struct dt_key *)"ROOT");
3739 obj = dt_locate(env, key, &lfsck->li_global_root_fid);
3741 GOTO(out, rc = PTR_ERR(obj));
3743 if (unlikely(!dt_try_as_dir(env, obj)))
3744 GOTO(out, rc = -ENOTDIR);
3746 rc = dt_lookup(env, obj, (struct dt_rec *)fid,
3747 (const struct dt_key *)dotlustre);
3751 lfsck_object_put(env, obj);
3752 obj = dt_locate(env, key, fid);
3754 GOTO(out, rc = PTR_ERR(obj));
3756 cname = lfsck_name_get_const(env, dotlustre,
3758 rc = lfsck_verify_linkea(env, obj, cname,
3759 &lfsck->li_global_root_fid);
3763 if (unlikely(!dt_try_as_dir(env, obj)))
3764 GOTO(out, rc = -ENOTDIR);
3767 rc = dt_lookup(env, obj, (struct dt_rec *)fid,
3768 (const struct dt_key *)lostfound);
3772 lfsck_object_put(env, obj);
3773 obj = dt_locate(env, key, fid);
3775 GOTO(out, rc = PTR_ERR(obj));
3777 cname = lfsck_name_get_const(env, lostfound,
3779 rc = lfsck_verify_linkea(env, obj, cname, pfid);
3783 lfsck_object_put(env, obj);
3788 fid->f_seq = FID_SEQ_LOCAL_FILE;
3789 fid->f_oid = OTABLE_IT_OID;
3791 obj = dt_locate(env, key, fid);
3793 GOTO(out, rc = PTR_ERR(obj));
3795 rc = obj->do_ops->do_index_try(env, obj, &dt_otable_features);
3799 lfsck->li_obj_oit = obj;
3800 obj = local_file_find_or_create(env, lfsck->li_los, root, LFSCK_DIR,
3801 S_IFDIR | S_IRUGO | S_IWUSR);
3803 GOTO(out, rc = PTR_ERR(obj));
3805 lu_object_get(&obj->do_lu);
3806 lfsck->li_lfsck_dir = obj;
3807 rc = lfsck_bookmark_setup(env, lfsck);
3812 rc = lfsck_fid_init(lfsck);
3816 rc = lfsck_namespace_setup(env, lfsck);
3821 rc = lfsck_layout_setup(env, lfsck);
3825 /* XXX: more LFSCK components initialization to be added here. */
3827 rc = lfsck_instance_add(lfsck);
3829 rc = lfsck_add_target_from_orphan(env, lfsck);
3831 if (obj != NULL && !IS_ERR(obj))
3832 lfsck_object_put(env, obj);
3833 if (root != NULL && !IS_ERR(root))
3834 lfsck_object_put(env, root);
3836 lfsck_instance_cleanup(env, lfsck);
3839 EXPORT_SYMBOL(lfsck_register);
3841 void lfsck_degister(const struct lu_env *env, struct dt_device *key)
3843 struct lfsck_instance *lfsck;
3845 lfsck = lfsck_instance_find(key, false, true);
3847 lfsck_instance_put(env, lfsck);
3849 EXPORT_SYMBOL(lfsck_degister);
3851 int lfsck_add_target(const struct lu_env *env, struct dt_device *key,
3852 struct dt_device *tgt, struct obd_export *exp,
3853 __u32 index, bool for_ost)
3855 struct lfsck_instance *lfsck;
3856 struct lfsck_tgt_desc *ltd;
3867 INIT_LIST_HEAD(<d->ltd_orphan_list);
3868 INIT_LIST_HEAD(<d->ltd_layout_list);
3869 INIT_LIST_HEAD(<d->ltd_layout_phase_list);
3870 INIT_LIST_HEAD(<d->ltd_namespace_list);
3871 INIT_LIST_HEAD(<d->ltd_namespace_phase_list);
3872 atomic_set(<d->ltd_ref, 1);
3873 ltd->ltd_index = index;
3875 spin_lock(&lfsck_instance_lock);
3876 lfsck = __lfsck_instance_find(key, true, false);
3877 if (lfsck == NULL) {
3879 list_add_tail(<d->ltd_orphan_list,
3880 &lfsck_ost_orphan_list);
3882 list_add_tail(<d->ltd_orphan_list,
3883 &lfsck_mdt_orphan_list);
3884 spin_unlock(&lfsck_instance_lock);
3888 spin_unlock(&lfsck_instance_lock);
3890 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, false);
3894 lfsck_instance_put(env, lfsck);
3898 EXPORT_SYMBOL(lfsck_add_target);
3900 void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
3901 struct dt_device *tgt, __u32 index, bool for_ost)
3903 struct lfsck_instance *lfsck;
3904 struct lfsck_tgt_descs *ltds;
3905 struct lfsck_tgt_desc *ltd;
3906 struct list_head *head;
3909 head = &lfsck_ost_orphan_list;
3911 head = &lfsck_mdt_orphan_list;
3913 spin_lock(&lfsck_instance_lock);
3914 list_for_each_entry(ltd, head, ltd_orphan_list) {
3915 if (ltd->ltd_tgt == tgt) {
3916 list_del_init(<d->ltd_orphan_list);
3917 spin_unlock(&lfsck_instance_lock);
3925 lfsck = __lfsck_instance_find(key, true, false);
3926 spin_unlock(&lfsck_instance_lock);
3927 if (unlikely(lfsck == NULL))
3931 ltds = &lfsck->li_ost_descs;
3933 ltds = &lfsck->li_mdt_descs;
3935 down_write(<ds->ltd_rw_sem);
3936 LASSERT(ltds->ltd_tgts_bitmap != NULL);
3938 if (unlikely(index >= ltds->ltd_tgts_bitmap->size))
3941 ltd = lfsck_ltd2tgt(ltds, index);
3942 if (unlikely(ltd == NULL))
3945 LASSERT(ltds->ltd_tgtnr > 0);
3948 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, index);
3949 lfsck_assign_tgt(ltds, NULL, index);
3954 head = &lfsck->li_ost_descs.ltd_orphan;
3956 head = &lfsck->li_mdt_descs.ltd_orphan;
3958 list_for_each_entry(ltd, head, ltd_orphan_list) {
3959 if (ltd->ltd_tgt == tgt) {
3960 list_del_init(<d->ltd_orphan_list);
3966 up_write(<ds->ltd_rw_sem);
3968 spin_lock(<ds->ltd_lock);
3970 spin_unlock(<ds->ltd_lock);
3971 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_NAMESPACE);
3972 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_LAYOUT);
3976 lfsck_instance_put(env, lfsck);
3978 EXPORT_SYMBOL(lfsck_del_target);
3980 static int __init lfsck_init(void)
3984 INIT_LIST_HEAD(&lfsck_instance_list);
3985 INIT_LIST_HEAD(&lfsck_ost_orphan_list);
3986 INIT_LIST_HEAD(&lfsck_mdt_orphan_list);
3987 lfsck_key_init_generic(&lfsck_thread_key, NULL);
3988 rc = lu_context_key_register(&lfsck_thread_key);
3990 tgt_register_lfsck_in_notify_local(lfsck_in_notify_local);
3991 tgt_register_lfsck_in_notify(lfsck_in_notify);
3992 tgt_register_lfsck_query(lfsck_query);
3998 static void __exit lfsck_exit(void)
4000 struct lfsck_tgt_desc *ltd;
4001 struct lfsck_tgt_desc *next;
4003 LASSERT(list_empty(&lfsck_instance_list));
4005 list_for_each_entry_safe(ltd, next, &lfsck_ost_orphan_list,
4007 list_del_init(<d->ltd_orphan_list);
4011 list_for_each_entry_safe(ltd, next, &lfsck_mdt_orphan_list,
4013 list_del_init(<d->ltd_orphan_list);
4017 lu_context_key_degister(&lfsck_thread_key);
4020 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
4021 MODULE_DESCRIPTION("Lustre File System Checker");
4022 MODULE_VERSION(LUSTRE_VERSION_STRING);
4023 MODULE_LICENSE("GPL");
4025 module_init(lfsck_init);
4026 module_exit(lfsck_exit);