4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (c) 2013, 2017, Intel Corporation.
26 * lustre/lfsck/lfsck_lib.c
28 * Author: Fan, Yong <fan.yong@intel.com>
31 #define DEBUG_SUBSYSTEM S_LFSCK
33 #include <linux/kthread.h>
34 #include <linux/sched.h>
35 #include <linux/list.h>
36 #include <lu_object.h>
37 #include <dt_object.h>
38 #include <md_object.h>
39 #include <lustre_fld.h>
40 #include <lustre_lib.h>
41 #include <lustre_net.h>
42 #include <lustre_lfsck.h>
44 #include "lfsck_internal.h"
46 #define LFSCK_CHECKPOINT_SKIP 1
48 /* define lfsck thread key */
49 LU_KEY_INIT(lfsck, struct lfsck_thread_info);
51 static void lfsck_key_fini(const struct lu_context *ctx,
52 struct lu_context_key *key, void *data)
54 struct lfsck_thread_info *info = data;
56 lu_buf_free(&info->lti_linkea_buf);
57 lu_buf_free(&info->lti_linkea_buf2);
58 lu_buf_free(&info->lti_big_buf);
62 LU_CONTEXT_KEY_DEFINE(lfsck, LCT_MD_THREAD | LCT_DT_THREAD);
63 LU_KEY_INIT_GENERIC(lfsck);
65 static struct list_head lfsck_instance_list;
66 static struct list_head lfsck_ost_orphan_list;
67 static struct list_head lfsck_mdt_orphan_list;
68 static DEFINE_SPINLOCK(lfsck_instance_lock);
70 const char *lfsck_flags_names[] = {
79 const char *lfsck_param_names[] = {
89 "delay_create_ostobj",
93 enum lfsck_verify_lpf_types {
95 LVLT_BY_NAMEENTRY = 1,
99 lfsck_reset_ltd_status(struct lfsck_tgt_desc *ltd, enum lfsck_type type)
101 if (type == LFSCK_TYPE_LAYOUT) {
102 ltd->ltd_layout_status = LS_MAX;
103 ltd->ltd_layout_repaired = 0;
105 ltd->ltd_namespace_status = LS_MAX;
106 ltd->ltd_namespace_repaired = 0;
110 static int lfsck_tgt_descs_init(struct lfsck_tgt_descs *ltds)
112 spin_lock_init(<ds->ltd_lock);
113 init_rwsem(<ds->ltd_rw_sem);
114 INIT_LIST_HEAD(<ds->ltd_orphan);
115 ltds->ltd_tgts_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
116 if (ltds->ltd_tgts_bitmap == NULL)
122 static void lfsck_tgt_descs_fini(struct lfsck_tgt_descs *ltds)
124 struct lfsck_tgt_desc *ltd;
125 struct lfsck_tgt_desc *next;
128 down_write(<ds->ltd_rw_sem);
130 list_for_each_entry_safe(ltd, next, <ds->ltd_orphan,
132 list_del_init(<d->ltd_orphan_list);
136 if (unlikely(ltds->ltd_tgts_bitmap == NULL)) {
137 up_write(<ds->ltd_rw_sem);
142 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
143 ltd = lfsck_ltd2tgt(ltds, idx);
144 if (likely(ltd != NULL)) {
145 LASSERT(list_empty(<d->ltd_layout_list));
146 LASSERT(list_empty(<d->ltd_layout_phase_list));
147 LASSERT(list_empty(<d->ltd_namespace_list));
148 LASSERT(list_empty(<d->ltd_namespace_phase_list));
151 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, idx);
152 lfsck_assign_tgt(ltds, NULL, idx);
157 LASSERTF(ltds->ltd_tgtnr == 0, "tgt count unmatched: %d\n",
160 for (idx = 0; idx < TGT_PTRS; idx++) {
161 if (ltds->ltd_tgts_idx[idx] != NULL) {
162 OBD_FREE_PTR(ltds->ltd_tgts_idx[idx]);
163 ltds->ltd_tgts_idx[idx] = NULL;
167 CFS_FREE_BITMAP(ltds->ltd_tgts_bitmap);
168 ltds->ltd_tgts_bitmap = NULL;
169 up_write(<ds->ltd_rw_sem);
172 static int __lfsck_add_target(const struct lu_env *env,
173 struct lfsck_instance *lfsck,
174 struct lfsck_tgt_desc *ltd,
175 bool for_ost, bool locked)
177 struct lfsck_tgt_descs *ltds;
178 __u32 index = ltd->ltd_index;
183 ltds = &lfsck->li_ost_descs;
185 ltds = &lfsck->li_mdt_descs;
188 down_write(<ds->ltd_rw_sem);
190 LASSERT(ltds->ltd_tgts_bitmap != NULL);
192 if (index >= ltds->ltd_tgts_bitmap->size) {
193 __u32 newsize = max((__u32)ltds->ltd_tgts_bitmap->size,
194 (__u32)BITS_PER_LONG);
195 struct cfs_bitmap *old_bitmap = ltds->ltd_tgts_bitmap;
196 struct cfs_bitmap *new_bitmap;
198 while (newsize < index + 1)
201 new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
202 if (new_bitmap == NULL)
203 GOTO(unlock, rc = -ENOMEM);
205 if (ltds->ltd_tgtnr > 0)
206 cfs_bitmap_copy(new_bitmap, old_bitmap);
207 ltds->ltd_tgts_bitmap = new_bitmap;
208 CFS_FREE_BITMAP(old_bitmap);
211 if (cfs_bitmap_check(ltds->ltd_tgts_bitmap, index)) {
212 CERROR("%s: the device %s (%u) is registered already\n",
213 lfsck_lfsck2name(lfsck),
214 ltd->ltd_tgt->dd_lu_dev.ld_obd->obd_name, index);
215 GOTO(unlock, rc = -EEXIST);
218 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
219 OBD_ALLOC_PTR(ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK]);
220 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL)
221 GOTO(unlock, rc = -ENOMEM);
224 lfsck_assign_tgt(ltds, ltd, index);
225 cfs_bitmap_set(ltds->ltd_tgts_bitmap, index);
228 GOTO(unlock, rc = 0);
232 up_write(<ds->ltd_rw_sem);
237 static int lfsck_add_target_from_orphan(const struct lu_env *env,
238 struct lfsck_instance *lfsck)
240 struct lfsck_tgt_descs *ltds = &lfsck->li_ost_descs;
241 struct lfsck_tgt_desc *ltd;
242 struct lfsck_tgt_desc *next;
243 struct list_head *head = &lfsck_ost_orphan_list;
248 spin_lock(&lfsck_instance_lock);
249 list_for_each_entry_safe(ltd, next, head, ltd_orphan_list) {
250 if (ltd->ltd_key == lfsck->li_bottom)
251 list_move_tail(<d->ltd_orphan_list,
254 spin_unlock(&lfsck_instance_lock);
256 down_write(<ds->ltd_rw_sem);
257 while (!list_empty(<ds->ltd_orphan)) {
258 ltd = list_entry(ltds->ltd_orphan.next,
259 struct lfsck_tgt_desc,
261 list_del_init(<d->ltd_orphan_list);
262 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, true);
263 /* Do not hold the semaphore for too long time. */
264 up_write(<ds->ltd_rw_sem);
268 down_write(<ds->ltd_rw_sem);
270 up_write(<ds->ltd_rw_sem);
273 ltds = &lfsck->li_mdt_descs;
274 head = &lfsck_mdt_orphan_list;
282 static inline struct lfsck_component *
283 __lfsck_component_find(struct lfsck_instance *lfsck, __u16 type,
284 struct list_head *list)
286 struct lfsck_component *com;
288 list_for_each_entry(com, list, lc_link) {
289 if (com->lc_type == type)
295 struct lfsck_component *
296 lfsck_component_find(struct lfsck_instance *lfsck, __u16 type)
298 struct lfsck_component *com;
300 spin_lock(&lfsck->li_lock);
301 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
305 com = __lfsck_component_find(lfsck, type,
306 &lfsck->li_list_double_scan);
310 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_idle);
314 lfsck_component_get(com);
315 spin_unlock(&lfsck->li_lock);
319 void lfsck_component_cleanup(const struct lu_env *env,
320 struct lfsck_component *com)
322 if (!list_empty(&com->lc_link))
323 list_del_init(&com->lc_link);
324 if (!list_empty(&com->lc_link_dir))
325 list_del_init(&com->lc_link_dir);
327 lfsck_component_put(env, com);
330 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
331 struct lu_fid *fid, bool locked)
333 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
338 mutex_lock(&lfsck->li_mutex);
340 rc = seq_client_alloc_fid(env, lfsck->li_seq, fid);
342 bk->lb_last_fid = *fid;
343 /* We do not care about whether the subsequent sub-operations
344 * failed or not. The worst case is that one FID is lost that
345 * is not a big issue for the LFSCK since it is relative rare
346 * for LFSCK create. */
347 rc = lfsck_bookmark_store(env, lfsck);
351 mutex_unlock(&lfsck->li_mutex);
356 static int __lfsck_ibits_lock(const struct lu_env *env,
357 struct lfsck_instance *lfsck,
358 struct dt_object *obj, struct ldlm_res_id *resid,
359 struct lustre_handle *lh, __u64 bits,
362 struct lfsck_thread_info *info = lfsck_env_info(env);
363 union ldlm_policy_data *policy = &info->lti_policy;
364 __u64 flags = LDLM_FL_ATOMIC_CB;
367 LASSERT(lfsck->li_namespace != NULL);
369 memset(policy, 0, sizeof(*policy));
370 policy->l_inodebits.bits = bits;
371 if (dt_object_remote(obj)) {
372 struct ldlm_enqueue_info *einfo = &info->lti_einfo;
374 memset(einfo, 0, sizeof(*einfo));
375 einfo->ei_type = LDLM_IBITS;
376 einfo->ei_mode = mode;
377 einfo->ei_cb_bl = ldlm_blocking_ast;
378 einfo->ei_cb_cp = ldlm_completion_ast;
379 einfo->ei_res_id = resid;
381 rc = dt_object_lock(env, obj, lh, einfo, policy);
382 /* for regular checks LFSCK doesn't use LDLM locking,
383 * so the state isn't coherent. here we just took LDLM
384 * lock for coherency and it's time to invalidate
387 dt_invalidate(env, obj);
389 rc = ldlm_cli_enqueue_local(env, lfsck->li_namespace, resid,
390 LDLM_IBITS, policy, mode,
391 &flags, ldlm_blocking_ast,
392 ldlm_completion_ast, NULL, NULL,
393 0, LVB_T_NONE, NULL, lh);
396 if (rc == ELDLM_OK) {
399 memset(lh, 0, sizeof(*lh));
407 * Request the specified ibits lock for the given object.
409 * Before the LFSCK modifying on the namespace visible object,
410 * it needs to acquire related ibits ldlm lock.
412 * \param[in] env pointer to the thread context
413 * \param[in] lfsck pointer to the lfsck instance
414 * \param[in] obj pointer to the dt_object to be locked
415 * \param[out] lh pointer to the lock handle
416 * \param[in] bits the bits for the ldlm lock to be acquired
417 * \param[in] mode the mode for the ldlm lock to be acquired
419 * \retval 0 for success
420 * \retval negative error number on failure
422 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
423 struct dt_object *obj, struct lustre_handle *lh,
424 __u64 bits, enum ldlm_mode mode)
426 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
428 LASSERT(!lustre_handle_is_used(lh));
430 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
431 return __lfsck_ibits_lock(env, lfsck, obj, resid, lh, bits, mode);
435 * Request the remote LOOKUP lock for the given object.
437 * If \a pobj is remote, the LOOKUP lock of \a obj is on the MDT where
438 * \a pobj is, acquire LOOKUP lock there.
440 * \param[in] env pointer to the thread context
441 * \param[in] lfsck pointer to the lfsck instance
442 * \param[in] pobj pointer to parent dt_object
443 * \param[in] obj pointer to the dt_object to be locked
444 * \param[out] lh pointer to the lock handle
445 * \param[in] mode the mode for the ldlm lock to be acquired
447 * \retval 0 for success
448 * \retval negative error number on failure
450 int lfsck_remote_lookup_lock(const struct lu_env *env,
451 struct lfsck_instance *lfsck,
452 struct dt_object *pobj, struct dt_object *obj,
453 struct lustre_handle *lh, enum ldlm_mode mode)
455 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
457 LASSERT(!lustre_handle_is_used(lh));
459 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
460 return __lfsck_ibits_lock(env, lfsck, pobj, resid, lh,
461 MDS_INODELOCK_LOOKUP, mode);
465 * Release the the specified ibits lock.
467 * If the lock has been acquired before, release it
468 * and cleanup the handle. Otherwise, do nothing.
470 * \param[in] lh pointer to the lock handle
471 * \param[in] mode the mode for the ldlm lock to be released
473 void lfsck_ibits_unlock(struct lustre_handle *lh, enum ldlm_mode mode)
475 if (lustre_handle_is_used(lh)) {
476 ldlm_lock_decref(lh, mode);
477 memset(lh, 0, sizeof(*lh));
482 * Request compound ibits locks for the given <obj, name> pairs.
484 * Before the LFSCK modifying on the namespace visible object, it needs to
485 * acquire related ibits ldlm lock. Usually, we can use lfsck_ibits_lock for
486 * the lock purpose. But the simple lfsck_ibits_lock for directory-based
487 * modificationis (such as insert name entry to the directory) may be too
488 * coarse-grained and not efficient.
490 * The lfsck_lock() will request compound ibits locks on the specified
491 * <obj, name> pairs: the PDO (Parallel Directory Operations) ibits (UPDATE)
492 * lock on the directory object, and the regular ibits lock on the name hash.
494 * \param[in] env pointer to the thread context
495 * \param[in] lfsck pointer to the lfsck instance
496 * \param[in] obj pointer to the dt_object to be locked
497 * \param[in] name used for building the PDO lock resource
498 * \param[out] llh pointer to the lfsck_lock_handle
499 * \param[in] bits the bits for the ldlm lock to be acquired
500 * \param[in] mode the mode for the ldlm lock to be acquired
502 * \retval 0 for success
503 * \retval negative error number on failure
505 int lfsck_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
506 struct dt_object *obj, const char *name,
507 struct lfsck_lock_handle *llh, __u64 bits, enum ldlm_mode mode)
509 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
512 LASSERT(S_ISDIR(lfsck_object_type(obj)));
513 LASSERT(name != NULL);
514 LASSERT(name[0] != 0);
515 LASSERT(!lustre_handle_is_used(&llh->llh_pdo_lh));
516 LASSERT(!lustre_handle_is_used(&llh->llh_reg_lh));
520 llh->llh_pdo_mode = LCK_EX;
523 llh->llh_pdo_mode = LCK_CW;
526 llh->llh_pdo_mode = LCK_CR;
529 CDEBUG(D_LFSCK, "%s: unexpected PDO lock mode %u on the obj "
530 DFID"\n", lfsck_lfsck2name(lfsck), mode,
531 PFID(lfsck_dto2fid(obj)));
535 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
536 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_pdo_lh,
537 MDS_INODELOCK_UPDATE, llh->llh_pdo_mode);
541 llh->llh_reg_mode = mode;
542 resid->name[LUSTRE_RES_ID_HSH_OFF] = ll_full_name_hash(NULL, name,
544 LASSERT(resid->name[LUSTRE_RES_ID_HSH_OFF] != 0);
545 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_reg_lh,
546 bits, llh->llh_reg_mode);
548 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
554 * Release the the compound ibits locks.
556 * \param[in] llh pointer to the lfsck_lock_handle to be released
558 void lfsck_unlock(struct lfsck_lock_handle *llh)
560 lfsck_ibits_unlock(&llh->llh_reg_lh, llh->llh_reg_mode);
561 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
564 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
565 struct lfsck_instance *lfsck,
566 const struct lu_fid *fid)
568 struct seq_server_site *ss = lfsck_dev_site(lfsck);
569 struct lu_seq_range *range = &lfsck_env_info(env)->lti_range;
572 if (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE)) {
573 /* "ROOT" is always on the MDT0. */
574 if (lu_fid_eq(fid, &lfsck->li_global_root_fid))
577 return lfsck_dev_idx(lfsck);
580 fld_range_set_mdt(range);
581 rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
583 rc = range->lsr_index;
588 const char dot[] = ".";
589 const char dotdot[] = "..";
590 static const char dotlustre[] = ".lustre";
591 static const char lostfound[] = "lost+found";
594 * Remove the name entry from the .lustre/lost+found directory.
596 * No need to care about the object referenced by the name entry,
597 * either the name entry is invalid or redundant, or the referenced
598 * object has been processed or will be handled by others.
600 * \param[in] env pointer to the thread context
601 * \param[in] lfsck pointer to the lfsck instance
602 * \param[in] name the name for the name entry to be removed
604 * \retval 0 for success
605 * \retval negative error number on failure
607 static int lfsck_lpf_remove_name_entry(const struct lu_env *env,
608 struct lfsck_instance *lfsck,
611 struct dt_object *parent = lfsck->li_lpf_root_obj;
612 struct dt_device *dev = lfsck_obj2dev(parent);
614 struct lfsck_lock_handle *llh = &lfsck_env_info(env)->lti_llh;
618 rc = lfsck_lock(env, lfsck, parent, name, llh,
619 MDS_INODELOCK_UPDATE, LCK_PW);
623 th = dt_trans_create(env, dev);
625 GOTO(unlock, rc = PTR_ERR(th));
627 rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
631 rc = dt_declare_ref_del(env, parent, th);
635 rc = dt_trans_start_local(env, dev, th);
639 rc = dt_delete(env, parent, (const struct dt_key *)name, th);
643 dt_write_lock(env, parent, 0);
644 rc = dt_ref_del(env, parent, th);
645 dt_write_unlock(env, parent);
650 dt_trans_stop(env, dev, th);
655 CDEBUG(D_LFSCK, "%s: remove name entry "DFID"/%s: rc = %d\n",
656 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(parent)), name, rc);
661 static int lfsck_create_lpf_local(const struct lu_env *env,
662 struct lfsck_instance *lfsck,
663 struct dt_object *child,
665 struct dt_object_format *dof,
668 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
669 struct dt_object *parent = lfsck->li_lpf_root_obj;
670 struct dt_device *dev = lfsck_obj2dev(child);
671 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
672 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
673 const struct lu_fid *cfid = lfsck_dto2fid(child);
674 struct thandle *th = NULL;
675 struct linkea_data ldata = { NULL };
676 struct lu_buf linkea_buf;
677 const struct lu_name *cname;
679 int len = sizeof(struct lfsck_bookmark);
683 cname = lfsck_name_get_const(env, name, strlen(name));
684 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
685 cname, lfsck_dto2fid(parent));
689 th = dt_trans_create(env, dev);
693 /* 1a. create child */
694 rc = dt_declare_create(env, child, la, NULL, dof, th);
698 if (!dt_try_as_dir(env, child))
699 GOTO(stop, rc = -ENOTDIR);
701 /* 2a. increase child nlink */
702 rc = dt_declare_ref_add(env, child, th);
706 /* 3a. insert dot into child dir */
707 rec->rec_type = S_IFDIR;
709 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
710 (const struct dt_key *)dot, th);
714 /* 4a. insert dotdot into child dir */
715 rec->rec_fid = &LU_LPF_FID;
716 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
717 (const struct dt_key *)dotdot, th);
721 /* 5a. insert linkEA for child */
722 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
723 ldata.ld_leh->leh_len);
724 rc = dt_declare_xattr_set(env, child, &linkea_buf,
725 XATTR_NAME_LINK, 0, th);
729 /* 6a. insert name into parent dir */
730 rec->rec_type = S_IFDIR;
732 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
733 (const struct dt_key *)name, th);
737 /* 7a. increase parent nlink */
738 rc = dt_declare_ref_add(env, parent, th);
742 /* 8a. update bookmark */
743 rc = dt_declare_record_write(env, bk_obj,
744 lfsck_buf_get(env, bk, len), 0, th);
748 rc = dt_trans_start_local(env, dev, th);
752 dt_write_lock(env, child, 0);
753 /* 1b. create child */
754 rc = dt_create(env, child, la, NULL, dof, th);
758 /* 2b. increase child nlink */
759 rc = dt_ref_add(env, child, th);
763 /* 3b. insert dot into child dir */
765 rc = dt_insert(env, child, (const struct dt_rec *)rec,
766 (const struct dt_key *)dot, th);
770 /* 4b. insert dotdot into child dir */
771 rec->rec_fid = &LU_LPF_FID;
772 rc = dt_insert(env, child, (const struct dt_rec *)rec,
773 (const struct dt_key *)dotdot, th);
777 /* 5b. insert linkEA for child. */
778 rc = dt_xattr_set(env, child, &linkea_buf,
779 XATTR_NAME_LINK, 0, th);
780 dt_write_unlock(env, child);
784 /* 6b. insert name into parent dir */
786 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
787 (const struct dt_key *)name, th);
791 dt_write_lock(env, parent, 0);
792 /* 7b. increase parent nlink */
793 rc = dt_ref_add(env, parent, th);
794 dt_write_unlock(env, parent);
798 bk->lb_lpf_fid = *cfid;
799 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
801 /* 8b. update bookmark */
802 rc = dt_record_write(env, bk_obj,
803 lfsck_buf_get(env, bk, len), &pos, th);
808 dt_write_unlock(env, child);
811 dt_trans_stop(env, dev, th);
816 static int lfsck_create_lpf_remote(const struct lu_env *env,
817 struct lfsck_instance *lfsck,
818 struct dt_object *child,
820 struct dt_object_format *dof,
823 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
824 struct dt_object *parent = lfsck->li_lpf_root_obj;
825 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
826 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
827 const struct lu_fid *cfid = lfsck_dto2fid(child);
828 struct thandle *th = NULL;
829 struct linkea_data ldata = { NULL };
830 struct lu_buf linkea_buf;
831 const struct lu_name *cname;
832 struct dt_device *dev;
834 int len = sizeof(struct lfsck_bookmark);
838 cname = lfsck_name_get_const(env, name, strlen(name));
839 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
840 cname, lfsck_dto2fid(parent));
844 /* Create .lustre/lost+found/MDTxxxx. */
846 /* XXX: Currently, cross-MDT create operation needs to create the child
847 * object firstly, then insert name into the parent directory. For
848 * this case, the child object resides on current MDT (local), but
849 * the parent ".lustre/lost+found" may be on remote MDT. It is not
850 * easy to contain all the sub-modifications orderly within single
853 * To avoid more inconsistency, we split the create operation into
856 * 1) create the child and update the lfsck_bookmark::lb_lpf_fid
858 * 2) insert the name "MDTXXXX" in the parent ".lustre/lost+found"
861 * If 1) done, but 2) failed, then go ahead, the LFSCK will try to
862 * repair such inconsistency when LFSCK run next time. */
864 /* Transaction I: locally */
866 dev = lfsck_obj2dev(child);
867 th = dt_trans_create(env, dev);
871 /* 1a. create child */
872 rc = dt_declare_create(env, child, la, NULL, dof, th);
876 if (!dt_try_as_dir(env, child))
877 GOTO(stop, rc = -ENOTDIR);
879 /* 2a. increase child nlink */
880 rc = dt_declare_ref_add(env, child, th);
884 /* 3a. insert dot into child dir */
885 rec->rec_type = S_IFDIR;
887 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
888 (const struct dt_key *)dot, th);
892 /* 4a. insert dotdot into child dir */
893 rec->rec_fid = &LU_LPF_FID;
894 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
895 (const struct dt_key *)dotdot, th);
899 /* 5a. insert linkEA for child */
900 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
901 ldata.ld_leh->leh_len);
902 rc = dt_declare_xattr_set(env, child, &linkea_buf,
903 XATTR_NAME_LINK, 0, th);
907 /* 6a. update bookmark */
908 rc = dt_declare_record_write(env, bk_obj,
909 lfsck_buf_get(env, bk, len), 0, th);
913 rc = dt_trans_start_local(env, dev, th);
917 dt_write_lock(env, child, 0);
918 /* 1b. create child */
919 rc = dt_create(env, child, la, NULL, dof, th);
923 /* 2b. increase child nlink */
924 rc = dt_ref_add(env, child, th);
928 /* 3b. insert dot into child dir */
929 rec->rec_type = S_IFDIR;
931 rc = dt_insert(env, child, (const struct dt_rec *)rec,
932 (const struct dt_key *)dot, th);
936 /* 4b. insert dotdot into child dir */
937 rec->rec_fid = &LU_LPF_FID;
938 rc = dt_insert(env, child, (const struct dt_rec *)rec,
939 (const struct dt_key *)dotdot, th);
943 /* 5b. insert linkEA for child */
944 rc = dt_xattr_set(env, child, &linkea_buf,
945 XATTR_NAME_LINK, 0, th);
949 bk->lb_lpf_fid = *cfid;
950 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
952 /* 6b. update bookmark */
953 rc = dt_record_write(env, bk_obj,
954 lfsck_buf_get(env, bk, len), &pos, th);
956 dt_write_unlock(env, child);
957 dt_trans_stop(env, dev, th);
961 /* Transaction II: remotely */
963 dev = lfsck_obj2dev(parent);
964 th = dt_trans_create(env, dev);
969 /* 5a. insert name into parent dir */
971 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
972 (const struct dt_key *)name, th);
976 /* 6a. increase parent nlink */
977 rc = dt_declare_ref_add(env, parent, th);
981 rc = dt_trans_start_local(env, dev, th);
985 /* 5b. insert name into parent dir */
986 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
987 (const struct dt_key *)name, th);
991 dt_write_lock(env, parent, 0);
992 /* 6b. increase parent nlink */
993 rc = dt_ref_add(env, parent, th);
994 dt_write_unlock(env, parent);
999 dt_write_unlock(env, child);
1001 dt_trans_stop(env, dev, th);
1003 if (rc != 0 && dev == lfsck_obj2dev(parent))
1004 CDEBUG(D_LFSCK, "%s: partially created the object "DFID
1005 "for orphans, but failed to insert the name %s "
1006 "to the .lustre/lost+found/. Such inconsistency "
1007 "will be repaired when LFSCK run next time: rc = %d\n",
1008 lfsck_lfsck2name(lfsck), PFID(cfid), name, rc);
1014 * Create the MDTxxxx directory under /ROOT/.lustre/lost+found/
1016 * The /ROOT/.lustre/lost+found/MDTxxxx/ directory is used for holding
1017 * orphans and other uncertain inconsistent objects found during the
1018 * LFSCK. Such directory will be created by the LFSCK engine on the
1019 * local MDT before the LFSCK scanning.
1021 * \param[in] env pointer to the thread context
1022 * \param[in] lfsck pointer to the lfsck instance
1024 * \retval 0 for success
1025 * \retval negative error number on failure
1027 static int lfsck_create_lpf(const struct lu_env *env,
1028 struct lfsck_instance *lfsck)
1030 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1031 struct lfsck_thread_info *info = lfsck_env_info(env);
1032 struct lu_fid *cfid = &info->lti_fid2;
1033 struct lu_attr *la = &info->lti_la;
1034 struct dt_object_format *dof = &info->lti_dof;
1035 struct dt_object *parent = lfsck->li_lpf_root_obj;
1036 struct dt_object *child = NULL;
1037 struct lfsck_lock_handle *llh = &info->lti_llh;
1039 int node = lfsck_dev_idx(lfsck);
1043 LASSERT(lfsck->li_master);
1044 LASSERT(parent != NULL);
1045 LASSERT(lfsck->li_lpf_obj == NULL);
1047 snprintf(name, 8, "MDT%04x", node);
1048 rc = lfsck_lock(env, lfsck, parent, name, llh,
1049 MDS_INODELOCK_UPDATE, LCK_PW);
1053 if (fid_is_zero(&bk->lb_lpf_fid)) {
1054 /* There is corner case that: in former LFSCK scanning we have
1055 * created the .lustre/lost+found/MDTxxxx but failed to update
1056 * the lfsck_bookmark::lb_lpf_fid successfully. So need lookup
1057 * it from MDT0 firstly. */
1058 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
1059 (const struct dt_key *)name);
1060 if (rc != 0 && rc != -ENOENT)
1064 bk->lb_lpf_fid = *cfid;
1065 rc = lfsck_bookmark_store(env, lfsck);
1067 rc = lfsck_fid_alloc(env, lfsck, cfid, true);
1072 *cfid = bk->lb_lpf_fid;
1075 child = lfsck_object_find_bottom_new(env, lfsck, cfid);
1077 GOTO(unlock, rc = PTR_ERR(child));
1079 if (dt_object_exists(child) != 0) {
1080 if (unlikely(!dt_try_as_dir(env, child)))
1083 lfsck->li_lpf_obj = child;
1088 memset(la, 0, sizeof(*la));
1089 la->la_atime = la->la_mtime = la->la_ctime = ktime_get_real_seconds();
1090 la->la_mode = S_IFDIR | S_IRWXU;
1091 la->la_valid = LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1093 memset(dof, 0, sizeof(*dof));
1094 dof->dof_type = dt_mode_to_dft(S_IFDIR);
1097 rc = lfsck_create_lpf_local(env, lfsck, child, la, dof, name);
1099 rc = lfsck_create_lpf_remote(env, lfsck, child, la, dof, name);
1101 lfsck->li_lpf_obj = child;
1107 if (rc != 0 && child != NULL && !IS_ERR(child))
1108 lfsck_object_put(env, child);
1114 * Scan .lustre/lost+found for bad name entries and remove them.
1116 * The valid name entry should be "MDTxxxx", the "xxxx" is the MDT device
1117 * index in the system. Any other formatted name is invalid and should be
1120 * \param[in] env pointer to the thread context
1121 * \param[in] lfsck pointer to the lfsck instance
1123 * \retval 0 for success
1124 * \retval negative error number on failure
1126 static int lfsck_scan_lpf_bad_entries(const struct lu_env *env,
1127 struct lfsck_instance *lfsck)
1129 struct dt_object *parent = lfsck->li_lpf_root_obj;
1130 struct lu_dirent *ent =
1131 (struct lu_dirent *)lfsck_env_info(env)->lti_key;
1132 const struct dt_it_ops *iops = &parent->do_index_ops->dio_it;
1137 it = iops->init(env, parent, LUDA_64BITHASH);
1139 RETURN(PTR_ERR(it));
1141 rc = iops->load(env, it, 0);
1143 rc = iops->next(env, it);
1150 rc = iops->rec(env, it, (struct dt_rec *)ent, LUDA_64BITHASH);
1154 ent->lde_namelen = le16_to_cpu(ent->lde_namelen);
1155 if (name_is_dot_or_dotdot(ent->lde_name, ent->lde_namelen))
1158 /* name length must be strlen("MDTxxxx") */
1159 if (ent->lde_namelen != 7)
1162 if (memcmp(ent->lde_name, "MDT", off) != 0)
1165 while (off < 7 && isxdigit(ent->lde_name[off]))
1171 rc = lfsck_lpf_remove_name_entry(env, lfsck,
1178 rc = iops->next(env, it);
1182 iops->fini(env, it);
1184 RETURN(rc > 0 ? 0 : rc);
1187 static int lfsck_update_lpf_entry(const struct lu_env *env,
1188 struct lfsck_instance *lfsck,
1189 struct dt_object *parent,
1190 struct dt_object *child,
1192 enum lfsck_verify_lpf_types type)
1196 if (type == LVLT_BY_BOOKMARK) {
1197 rc = lfsck_update_name_entry(env, lfsck, parent, name,
1198 lfsck_dto2fid(child), S_IFDIR);
1199 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1200 lfsck->li_bookmark_ram.lb_lpf_fid = *lfsck_dto2fid(child);
1201 rc = lfsck_bookmark_store(env, lfsck);
1203 CDEBUG(D_LFSCK, "%s: update LPF fid "DFID
1204 " in the bookmark file: rc = %d\n",
1205 lfsck_lfsck2name(lfsck),
1206 PFID(lfsck_dto2fid(child)), rc);
1213 * Check whether the @child back references the @parent.
1216 * 1) The child's FID is stored in the bookmark file. If the child back
1217 * references the parent (LU_LPF_FID object) via its ".." entry, then
1218 * insert the name (MDTxxxx) to the .lustre/lost+found; otherwise, if
1219 * the child back references another parent2, then:
1220 * 1.1) If the parent2 recognizes the child, then update the bookmark file;
1221 * 1.2) Otherwise, the LFSCK cannot know whether there will be parent3 that
1222 * references the child. So keep them there. As the LFSCK processing,
1223 * the parent3 may be found, then when the LFSCK run next time, the
1224 * inconsistency can be repaired.
1226 * 2) The child's FID is stored in the .lustre/lost+found/ sub-directory name
1227 * entry (MDTxxxx). If the child back references the parent (LU_LPF_FID obj)
1228 * via its ".." entry, then update the bookmark file, otherwise, if the child
1229 * back references another parent2, then:
1230 * 2.1) If the parent2 recognizes the child, then remove the sub-directory
1231 * from .lustre/lost+found/;
1232 * 2.2) Otherwise, if the parent2 does not recognizes the child, trust the
1233 * sub-directory name entry and update the child;
1234 * 2.3) Otherwise, if we do not know whether the parent2 recognizes the child
1235 * or not, then keep them there.
1237 * \param[in] env pointer to the thread context
1238 * \param[in] lfsck pointer to the lfsck instance
1239 * \param[in] child pointer to the lost+found sub-directory object
1240 * \param[in] name the name for lost+found sub-directory object
1241 * \param[out] fid pointer to the buffer to hold the FID of the object
1242 * (called it as parent2) that is referenced via the
1243 * child's dotdot entry; it also can be the FID that
1244 * is referenced by the name entry under the parent2.
1245 * \param[in] type to indicate where the child's FID is stored in
1247 * \retval positive number for uncertain inconsistency
1248 * \retval 0 for success
1249 * \retval negative error number on failure
1251 static int lfsck_verify_lpf_pairs(const struct lu_env *env,
1252 struct lfsck_instance *lfsck,
1253 struct dt_object *child, const char *name,
1255 enum lfsck_verify_lpf_types type)
1257 struct dt_object *parent = lfsck->li_lpf_root_obj;
1258 struct lfsck_thread_info *info = lfsck_env_info(env);
1259 char *name2 = info->lti_key;
1260 struct lu_fid *fid2 = &info->lti_fid3;
1261 struct dt_object *parent2 = NULL;
1262 struct lustre_handle lh = { 0 };
1267 rc = dt_lookup(env, child, (struct dt_rec *)fid,
1268 (const struct dt_key *)dotdot);
1272 if (!fid_is_sane(fid))
1273 GOTO(linkea, rc = -EINVAL);
1275 if (lu_fid_eq(fid, &LU_LPF_FID)) {
1276 const struct lu_name *cname;
1278 if (lfsck->li_lpf_obj == NULL) {
1279 lu_object_get(&child->do_lu);
1280 lfsck->li_lpf_obj = child;
1283 cname = lfsck_name_get_const(env, name, strlen(name));
1284 rc = lfsck_verify_linkea(env, child, cname, &LU_LPF_FID);
1286 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1292 parent2 = lfsck_object_find_bottom(env, lfsck, fid);
1293 if (IS_ERR(parent2))
1294 GOTO(linkea, parent2);
1296 if (!dt_object_exists(parent2)) {
1297 lfsck_object_put(env, parent2);
1299 GOTO(linkea, parent2 = ERR_PTR(-ENOENT));
1302 if (!dt_try_as_dir(env, parent2)) {
1303 lfsck_object_put(env, parent2);
1305 GOTO(linkea, parent2 = ERR_PTR(-ENOTDIR));
1309 /* To prevent rename/unlink race */
1310 rc = lfsck_ibits_lock(env, lfsck, child, &lh,
1311 MDS_INODELOCK_UPDATE, LCK_PR);
1315 dt_read_lock(env, child, 0);
1316 rc = lfsck_links_get_first(env, child, name2, fid2);
1318 dt_read_unlock(env, child);
1319 lfsck_ibits_unlock(&lh, LCK_PR);
1321 GOTO(out_put, rc = 1);
1324 /* It is almost impossible that the bookmark file (or the name entry)
1325 * and the linkEA hit the same data corruption. Trust the linkEA. */
1326 if (lu_fid_eq(fid2, &LU_LPF_FID) && strcmp(name, name2) == 0) {
1327 dt_read_unlock(env, child);
1328 lfsck_ibits_unlock(&lh, LCK_PR);
1331 if (lfsck->li_lpf_obj == NULL) {
1332 lu_object_get(&child->do_lu);
1333 lfsck->li_lpf_obj = child;
1336 /* Update the child's dotdot entry */
1337 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1338 &LU_LPF_FID, S_IFDIR);
1340 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1346 if (parent2 == NULL || IS_ERR(parent2)) {
1347 dt_read_unlock(env, child);
1348 lfsck_ibits_unlock(&lh, LCK_PR);
1350 GOTO(out_done, rc = 1);
1353 rc = dt_lookup(env, parent2, (struct dt_rec *)fid,
1354 (const struct dt_key *)name2);
1355 dt_read_unlock(env, child);
1356 lfsck_ibits_unlock(&lh, LCK_PR);
1357 if (rc != 0 && rc != -ENOENT)
1360 if (rc == -ENOENT || !lu_fid_eq(fid, lfsck_dto2fid(child))) {
1361 if (type == LVLT_BY_BOOKMARK)
1362 GOTO(out_put, rc = 1);
1364 /* Trust the name entry, update the child's dotdot entry. */
1365 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1366 &LU_LPF_FID, S_IFDIR);
1371 if (type == LVLT_BY_BOOKMARK) {
1372 /* Invalid FID record in the bookmark file, reset it. */
1373 fid_zero(&lfsck->li_bookmark_ram.lb_lpf_fid);
1374 rc = lfsck_bookmark_store(env, lfsck);
1376 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1377 " in the bookmark file: rc = %d\n",
1378 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(child)), rc);
1379 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1380 /* The name entry is wrong, remove it. */
1381 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1387 if (parent2 != NULL && !IS_ERR(parent2))
1388 lfsck_object_put(env, parent2);
1395 * Verify the /ROOT/.lustre/lost+found/ directory.
1397 * /ROOT/.lustre/lost+found/ is a special directory to hold the objects that
1398 * the LFSCK does not exactly know how to handle, such as orphans. So before
1399 * the LFSCK scanning the system, the consistency of such directory needs to
1400 * be verified firstly to allow the users to use it during the LFSCK.
1402 * \param[in] env pointer to the thread context
1403 * \param[in] lfsck pointer to the lfsck instance
1405 * \retval positive number for uncertain inconsistency
1406 * \retval 0 for success
1407 * \retval negative error number on failure
1409 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
1411 struct lfsck_thread_info *info = lfsck_env_info(env);
1412 struct lu_fid *pfid = &info->lti_fid;
1413 struct lu_fid *cfid = &info->lti_fid2;
1414 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1415 struct dt_object *parent;
1416 /* child1's FID is in the bookmark file. */
1417 struct dt_object *child1 = NULL;
1418 /* child2's FID is in the name entry MDTxxxx. */
1419 struct dt_object *child2 = NULL;
1420 const struct lu_name *cname;
1422 int node = lfsck_dev_idx(lfsck);
1426 LASSERT(lfsck->li_master);
1428 if (lfsck->li_lpf_root_obj != NULL)
1432 parent = lfsck_object_find_by_dev(env, lfsck->li_bottom,
1435 struct lfsck_tgt_desc *ltd;
1437 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
1438 if (unlikely(ltd == NULL))
1441 parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
1447 RETURN(PTR_ERR(parent));
1449 LASSERT(dt_object_exists(parent));
1451 if (unlikely(!dt_try_as_dir(env, parent))) {
1452 lfsck_object_put(env, parent);
1454 GOTO(put, rc = -ENOTDIR);
1457 lfsck->li_lpf_root_obj = parent;
1459 rc = lfsck_scan_lpf_bad_entries(env, lfsck);
1461 CDEBUG(D_LFSCK, "%s: scan .lustre/lost+found/ "
1462 "for bad sub-directories: rc = %d\n",
1463 lfsck_lfsck2name(lfsck), rc);
1467 snprintf(name, 8, "MDT%04x", node);
1468 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
1469 (const struct dt_key *)name);
1470 if (rc == -ENOENT) {
1478 /* Invalid FID in the name entry, remove the name entry. */
1479 if (!fid_is_norm(cfid)) {
1480 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1487 child2 = lfsck_object_find_bottom(env, lfsck, cfid);
1489 GOTO(put, rc = PTR_ERR(child2));
1491 if (unlikely(!dt_object_exists(child2) ||
1492 dt_object_remote(child2)) ||
1493 !S_ISDIR(lfsck_object_type(child2))) {
1494 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1501 if (unlikely(!dt_try_as_dir(env, child2))) {
1502 lfsck_object_put(env, child2);
1508 if (fid_is_zero(&bk->lb_lpf_fid))
1511 if (likely(lu_fid_eq(cfid, &bk->lb_lpf_fid))) {
1512 if (lfsck->li_lpf_obj == NULL) {
1513 lu_object_get(&child2->do_lu);
1514 lfsck->li_lpf_obj = child2;
1517 cname = lfsck_name_get_const(env, name, strlen(name));
1518 rc = lfsck_verify_linkea(env, child2, cname, &LU_LPF_FID);
1523 if (unlikely(!fid_is_norm(&bk->lb_lpf_fid))) {
1524 struct lu_fid tfid = bk->lb_lpf_fid;
1526 /* Invalid FID record in the bookmark file, reset it. */
1527 fid_zero(&bk->lb_lpf_fid);
1528 rc = lfsck_bookmark_store(env, lfsck);
1530 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1531 " in the bookmark file: rc = %d\n",
1532 lfsck_lfsck2name(lfsck), PFID(&tfid), rc);
1540 child1 = lfsck_object_find_bottom(env, lfsck, &bk->lb_lpf_fid);
1541 if (IS_ERR(child1)) {
1546 if (unlikely(!dt_object_exists(child1) ||
1547 dt_object_remote(child1)) ||
1548 !S_ISDIR(lfsck_object_type(child1))) {
1549 /* Invalid FID record in the bookmark file, reset it. */
1550 fid_zero(&bk->lb_lpf_fid);
1551 rc = lfsck_bookmark_store(env, lfsck);
1553 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1554 " in the bookmark file: rc = %d\n",
1555 lfsck_lfsck2name(lfsck),
1556 PFID(lfsck_dto2fid(child1)), rc);
1561 lfsck_object_put(env, child1);
1566 if (unlikely(!dt_try_as_dir(env, child1))) {
1567 lfsck_object_put(env, child1);
1573 rc = lfsck_verify_lpf_pairs(env, lfsck, child1, name, pfid,
1575 if (lu_fid_eq(pfid, &LU_LPF_FID))
1580 rc = lfsck_verify_lpf_pairs(env, lfsck, child2, name,
1581 pfid, LVLT_BY_NAMEENTRY);
1586 if (lfsck->li_lpf_obj != NULL) {
1587 if (unlikely(!dt_try_as_dir(env, lfsck->li_lpf_obj))) {
1588 lfsck_object_put(env, lfsck->li_lpf_obj);
1589 lfsck->li_lpf_obj = NULL;
1592 } else if (rc == 0) {
1593 rc = lfsck_create_lpf(env, lfsck);
1596 if (child2 != NULL && !IS_ERR(child2))
1597 lfsck_object_put(env, child2);
1598 if (child1 != NULL && !IS_ERR(child1))
1599 lfsck_object_put(env, child1);
1604 static int lfsck_fid_init(struct lfsck_instance *lfsck)
1606 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1607 struct seq_server_site *ss = lfsck_dev_site(lfsck);
1612 if (unlikely(ss == NULL))
1615 OBD_ALLOC_PTR(lfsck->li_seq);
1616 if (lfsck->li_seq == NULL)
1619 OBD_ALLOC(prefix, MAX_OBD_NAME + 7);
1621 GOTO(out, rc = -ENOMEM);
1623 snprintf(prefix, MAX_OBD_NAME + 7, "lfsck-%s", lfsck_lfsck2name(lfsck));
1624 rc = seq_client_init(lfsck->li_seq, NULL, LUSTRE_SEQ_METADATA, prefix,
1626 OBD_FREE(prefix, MAX_OBD_NAME + 7);
1630 if (fid_is_sane(&bk->lb_last_fid))
1631 lfsck->li_seq->lcs_fid = bk->lb_last_fid;
1636 OBD_FREE_PTR(lfsck->li_seq);
1637 lfsck->li_seq = NULL;
1642 static void lfsck_fid_fini(struct lfsck_instance *lfsck)
1644 if (lfsck->li_seq != NULL) {
1645 seq_client_fini(lfsck->li_seq);
1646 OBD_FREE_PTR(lfsck->li_seq);
1647 lfsck->li_seq = NULL;
1651 void lfsck_instance_cleanup(const struct lu_env *env,
1652 struct lfsck_instance *lfsck)
1654 struct ptlrpc_thread *thread = &lfsck->li_thread;
1655 struct lfsck_component *com;
1656 struct lfsck_component *next;
1657 struct lfsck_lmv_unit *llu;
1658 struct lfsck_lmv_unit *llu_next;
1659 struct lfsck_lmv *llmv;
1662 LASSERT(list_empty(&lfsck->li_link));
1663 LASSERT(thread_is_init(thread) || thread_is_stopped(thread));
1665 if (lfsck->li_obj_oit != NULL) {
1666 lfsck_object_put(env, lfsck->li_obj_oit);
1667 lfsck->li_obj_oit = NULL;
1670 LASSERT(lfsck->li_obj_dir == NULL);
1671 LASSERT(lfsck->li_lmv == NULL);
1673 list_for_each_entry_safe(llu, llu_next, &lfsck->li_list_lmv, llu_link) {
1674 llmv = &llu->llu_lmv;
1676 LASSERTF(atomic_read(&llmv->ll_ref) == 1,
1677 "still in using: %u\n",
1678 atomic_read(&llmv->ll_ref));
1680 lfsck_lmv_put(env, llmv);
1683 list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
1684 lfsck_component_cleanup(env, com);
1687 LASSERT(list_empty(&lfsck->li_list_dir));
1689 list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
1691 lfsck_component_cleanup(env, com);
1694 list_for_each_entry_safe(com, next, &lfsck->li_list_idle, lc_link) {
1695 lfsck_component_cleanup(env, com);
1698 lfsck_tgt_descs_fini(&lfsck->li_ost_descs);
1699 lfsck_tgt_descs_fini(&lfsck->li_mdt_descs);
1701 if (lfsck->li_lfsck_dir != NULL) {
1702 lfsck_object_put(env, lfsck->li_lfsck_dir);
1703 lfsck->li_lfsck_dir = NULL;
1706 if (lfsck->li_bookmark_obj != NULL) {
1707 lfsck_object_put(env, lfsck->li_bookmark_obj);
1708 lfsck->li_bookmark_obj = NULL;
1711 if (lfsck->li_lpf_obj != NULL) {
1712 lfsck_object_put(env, lfsck->li_lpf_obj);
1713 lfsck->li_lpf_obj = NULL;
1716 if (lfsck->li_lpf_root_obj != NULL) {
1717 lfsck_object_put(env, lfsck->li_lpf_root_obj);
1718 lfsck->li_lpf_root_obj = NULL;
1721 if (lfsck->li_los != NULL) {
1722 local_oid_storage_fini(env, lfsck->li_los);
1723 lfsck->li_los = NULL;
1726 lfsck_fid_fini(lfsck);
1728 OBD_FREE_PTR(lfsck);
1731 static inline struct lfsck_instance *
1732 __lfsck_instance_find(struct dt_device *key, bool ref, bool unlink)
1734 struct lfsck_instance *lfsck;
1736 list_for_each_entry(lfsck, &lfsck_instance_list, li_link) {
1737 if (lfsck->li_bottom == key) {
1739 lfsck_instance_get(lfsck);
1741 list_del_init(&lfsck->li_link);
1750 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
1753 struct lfsck_instance *lfsck;
1755 spin_lock(&lfsck_instance_lock);
1756 lfsck = __lfsck_instance_find(key, ref, unlink);
1757 spin_unlock(&lfsck_instance_lock);
1762 static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
1764 struct lfsck_instance *tmp;
1766 spin_lock(&lfsck_instance_lock);
1767 list_for_each_entry(tmp, &lfsck_instance_list, li_link) {
1768 if (lfsck->li_bottom == tmp->li_bottom) {
1769 spin_unlock(&lfsck_instance_lock);
1774 list_add_tail(&lfsck->li_link, &lfsck_instance_list);
1775 spin_unlock(&lfsck_instance_lock);
1779 void lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
1784 bool newline = (bits != 0 ? false : true);
1786 seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
1788 for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
1791 if (names[i] != NULL) {
1795 seq_printf(m, "%s%c", names[i],
1796 newline ? '\n' : ',');
1805 void lfsck_time_dump(struct seq_file *m, time64_t time, const char *name)
1808 seq_printf(m, "%s_time: N/A\n", name);
1809 seq_printf(m, "time_since_%s: N/A\n", name);
1811 seq_printf(m, "%s_time: %lld\n", name, time);
1812 seq_printf(m, "time_since_%s: %lld seconds\n",
1813 name, ktime_get_real_seconds() - time);
1817 void lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
1820 if (fid_is_zero(&pos->lp_dir_parent)) {
1821 if (pos->lp_oit_cookie == 0) {
1822 seq_printf(m, "%s: N/A, N/A, N/A\n", prefix);
1825 seq_printf(m, "%s: %llu, N/A, N/A\n",
1826 prefix, pos->lp_oit_cookie);
1828 seq_printf(m, "%s: %llu, "DFID", %#llx\n",
1829 prefix, pos->lp_oit_cookie,
1830 PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
1834 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
1835 struct lfsck_position *pos, bool init)
1837 const struct dt_it_ops *iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
1839 if (unlikely(lfsck->li_di_oit == NULL)) {
1840 memset(pos, 0, sizeof(*pos));
1844 pos->lp_oit_cookie = iops->store(env, lfsck->li_di_oit);
1845 if (!lfsck->li_current_oit_processed && !init)
1846 pos->lp_oit_cookie--;
1848 if (unlikely(pos->lp_oit_cookie == 0))
1849 pos->lp_oit_cookie = 1;
1851 if (lfsck->li_di_dir != NULL) {
1852 struct dt_object *dto = lfsck->li_obj_dir;
1854 pos->lp_dir_cookie = dto->do_index_ops->dio_it.store(env,
1857 if (pos->lp_dir_cookie >= MDS_DIR_END_OFF) {
1858 fid_zero(&pos->lp_dir_parent);
1859 pos->lp_dir_cookie = 0;
1861 pos->lp_dir_parent = *lfsck_dto2fid(dto);
1864 fid_zero(&pos->lp_dir_parent);
1865 pos->lp_dir_cookie = 0;
1869 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
1873 if (limit != LFSCK_SPEED_NO_LIMIT) {
1874 if (limit > cfs_time_seconds(1)) {
1875 lfsck->li_sleep_rate = limit / cfs_time_seconds(1);
1876 lfsck->li_sleep_jif = 1;
1878 lfsck->li_sleep_rate = 1;
1879 lfsck->li_sleep_jif = cfs_time_seconds(1) / limit;
1882 lfsck->li_sleep_jif = 0;
1883 lfsck->li_sleep_rate = 0;
1886 if (lfsck->li_bookmark_ram.lb_speed_limit != limit) {
1887 lfsck->li_bookmark_ram.lb_speed_limit = limit;
1894 void lfsck_control_speed(struct lfsck_instance *lfsck)
1896 struct ptlrpc_thread *thread = &lfsck->li_thread;
1897 struct l_wait_info lwi;
1899 if (lfsck->li_sleep_jif > 0 &&
1900 lfsck->li_new_scanned >= lfsck->li_sleep_rate) {
1901 lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
1902 LWI_ON_SIGNAL_NOOP, NULL);
1904 l_wait_event(thread->t_ctl_waitq,
1905 !thread_is_running(thread),
1907 lfsck->li_new_scanned = 0;
1911 void lfsck_control_speed_by_self(struct lfsck_component *com)
1913 struct lfsck_instance *lfsck = com->lc_lfsck;
1914 struct ptlrpc_thread *thread = &lfsck->li_thread;
1915 struct l_wait_info lwi;
1917 if (lfsck->li_sleep_jif > 0 &&
1918 com->lc_new_scanned >= lfsck->li_sleep_rate) {
1919 lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
1920 LWI_ON_SIGNAL_NOOP, NULL);
1922 l_wait_event(thread->t_ctl_waitq,
1923 !thread_is_running(thread),
1925 com->lc_new_scanned = 0;
1929 static struct lfsck_thread_args *
1930 lfsck_thread_args_init(struct lfsck_instance *lfsck,
1931 struct lfsck_component *com,
1932 struct lfsck_start_param *lsp)
1934 struct lfsck_thread_args *lta;
1939 return ERR_PTR(-ENOMEM);
1941 rc = lu_env_init(<a->lta_env, LCT_MD_THREAD | LCT_DT_THREAD);
1947 lta->lta_lfsck = lfsck_instance_get(lfsck);
1949 lta->lta_com = lfsck_component_get(com);
1956 void lfsck_thread_args_fini(struct lfsck_thread_args *lta)
1958 if (lta->lta_com != NULL)
1959 lfsck_component_put(<a->lta_env, lta->lta_com);
1960 lfsck_instance_put(<a->lta_env, lta->lta_lfsck);
1961 lu_env_fini(<a->lta_env);
1965 struct lfsck_assistant_data *
1966 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
1969 struct lfsck_assistant_data *lad;
1973 lad->lad_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
1974 if (lad->lad_bitmap == NULL) {
1979 INIT_LIST_HEAD(&lad->lad_req_list);
1980 spin_lock_init(&lad->lad_lock);
1981 INIT_LIST_HEAD(&lad->lad_ost_list);
1982 INIT_LIST_HEAD(&lad->lad_ost_phase1_list);
1983 INIT_LIST_HEAD(&lad->lad_ost_phase2_list);
1984 INIT_LIST_HEAD(&lad->lad_mdt_list);
1985 INIT_LIST_HEAD(&lad->lad_mdt_phase1_list);
1986 INIT_LIST_HEAD(&lad->lad_mdt_phase2_list);
1987 init_waitqueue_head(&lad->lad_thread.t_ctl_waitq);
1989 lad->lad_name = name;
1995 struct lfsck_assistant_object *
1996 lfsck_assistant_object_init(const struct lu_env *env, const struct lu_fid *fid,
1997 const struct lu_attr *attr, __u64 cookie,
2000 struct lfsck_assistant_object *lso;
2004 return ERR_PTR(-ENOMEM);
2006 lso->lso_fid = *fid;
2008 lso->lso_attr = *attr;
2010 atomic_set(&lso->lso_ref, 1);
2011 lso->lso_oit_cookie = cookie;
2013 lso->lso_is_dir = 1;
2019 lfsck_assistant_object_load(const struct lu_env *env,
2020 struct lfsck_instance *lfsck,
2021 struct lfsck_assistant_object *lso)
2023 struct dt_object *obj;
2025 obj = lfsck_object_find_bottom(env, lfsck, &lso->lso_fid);
2029 if (unlikely(!dt_object_exists(obj) || lfsck_is_dead_obj(obj))) {
2031 lfsck_object_put(env, obj);
2033 return ERR_PTR(-ENOENT);
2036 if (lso->lso_is_dir && unlikely(!dt_try_as_dir(env, obj))) {
2037 lfsck_object_put(env, obj);
2039 return ERR_PTR(-ENOTDIR);
2046 * Generic LFSCK asynchronous communication interpretor function.
2047 * The LFSCK RPC reply for both the event notification and status
2048 * querying will be handled here.
2050 * \param[in] env pointer to the thread context
2051 * \param[in] req pointer to the LFSCK request
2052 * \param[in] args pointer to the lfsck_async_interpret_args
2053 * \param[in] rc the result for handling the LFSCK request
2055 * \retval 0 for success
2056 * \retval negative error number on failure
2058 int lfsck_async_interpret_common(const struct lu_env *env,
2059 struct ptlrpc_request *req,
2062 struct lfsck_async_interpret_args *laia = args;
2063 struct lfsck_component *com = laia->laia_com;
2064 struct lfsck_assistant_data *lad = com->lc_data;
2065 struct lfsck_tgt_descs *ltds = laia->laia_ltds;
2066 struct lfsck_tgt_desc *ltd = laia->laia_ltd;
2067 struct lfsck_request *lr = laia->laia_lr;
2069 LASSERT(com->lc_lfsck->li_master);
2071 switch (lr->lr_event) {
2073 if (unlikely(rc == -EINPROGRESS)) {
2074 ltd->ltd_retry_start = 1;
2079 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s "
2081 lfsck_lfsck2name(com->lc_lfsck),
2082 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2083 ltd->ltd_index, lad->lad_name, rc);
2085 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2086 struct lfsck_layout *lo = com->lc_file_ram;
2088 if (lr->lr_flags & LEF_TO_OST)
2089 lfsck_lad_set_bitmap(env, com,
2092 lo->ll_flags |= LF_INCOMPLETE;
2094 struct lfsck_namespace *ns = com->lc_file_ram;
2096 /* If some MDT does not join the namespace
2097 * LFSCK, then we cannot know whether there
2098 * is some name entry on such MDT that with
2099 * the referenced MDT-object on this MDT or
2100 * not. So the namespace LFSCK on this MDT
2101 * cannot handle orphan MDT-objects properly.
2102 * So we mark the LFSCK as LF_INCOMPLETE and
2103 * skip orphan MDT-objects handling. */
2104 ns->ln_flags |= LF_INCOMPLETE;
2109 spin_lock(<ds->ltd_lock);
2110 if (ltd->ltd_dead) {
2111 spin_unlock(<ds->ltd_lock);
2115 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2116 struct list_head *list;
2117 struct list_head *phase_list;
2119 if (ltd->ltd_layout_done) {
2120 spin_unlock(<ds->ltd_lock);
2124 if (lr->lr_flags & LEF_TO_OST) {
2125 list = &lad->lad_ost_list;
2126 phase_list = &lad->lad_ost_phase1_list;
2128 list = &lad->lad_mdt_list;
2129 phase_list = &lad->lad_mdt_phase1_list;
2132 if (list_empty(<d->ltd_layout_list))
2133 list_add_tail(<d->ltd_layout_list, list);
2134 if (list_empty(<d->ltd_layout_phase_list))
2135 list_add_tail(<d->ltd_layout_phase_list,
2138 if (ltd->ltd_namespace_done) {
2139 spin_unlock(<ds->ltd_lock);
2143 if (list_empty(<d->ltd_namespace_list))
2144 list_add_tail(<d->ltd_namespace_list,
2145 &lad->lad_mdt_list);
2146 if (list_empty(<d->ltd_namespace_phase_list))
2147 list_add_tail(<d->ltd_namespace_phase_list,
2148 &lad->lad_mdt_phase1_list);
2150 spin_unlock(<ds->ltd_lock);
2153 case LE_PHASE1_DONE:
2154 case LE_PHASE2_DONE:
2156 if (rc != 0 && rc != -EALREADY)
2157 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s: "
2158 "event = %d, rc = %d\n",
2159 lfsck_lfsck2name(com->lc_lfsck),
2160 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2161 ltd->ltd_index, lad->lad_name, lr->lr_event, rc);
2164 struct lfsck_reply *reply;
2165 struct list_head *list;
2166 struct list_head *phase_list;
2168 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2169 list = <d->ltd_layout_list;
2170 phase_list = <d->ltd_layout_phase_list;
2172 list = <d->ltd_namespace_list;
2173 phase_list = <d->ltd_namespace_phase_list;
2177 if (lr->lr_flags & LEF_QUERY_ALL) {
2178 lfsck_reset_ltd_status(ltd, com->lc_type);
2182 spin_lock(<ds->ltd_lock);
2183 list_del_init(phase_list);
2184 list_del_init(list);
2185 spin_unlock(<ds->ltd_lock);
2189 reply = req_capsule_server_get(&req->rq_pill,
2191 if (reply == NULL) {
2193 CDEBUG(D_LFSCK, "%s: invalid query reply for %s: "
2194 "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck),
2197 if (lr->lr_flags & LEF_QUERY_ALL) {
2198 lfsck_reset_ltd_status(ltd, com->lc_type);
2202 spin_lock(<ds->ltd_lock);
2203 list_del_init(phase_list);
2204 list_del_init(list);
2205 spin_unlock(<ds->ltd_lock);
2209 if (lr->lr_flags & LEF_QUERY_ALL) {
2210 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2211 ltd->ltd_layout_status = reply->lr_status;
2212 ltd->ltd_layout_repaired = reply->lr_repaired;
2214 ltd->ltd_namespace_status = reply->lr_status;
2215 ltd->ltd_namespace_repaired =
2221 switch (reply->lr_status) {
2222 case LS_SCANNING_PHASE1:
2224 case LS_SCANNING_PHASE2:
2225 spin_lock(<ds->ltd_lock);
2226 list_del_init(phase_list);
2227 if (ltd->ltd_dead) {
2228 spin_unlock(<ds->ltd_lock);
2232 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2233 if (ltd->ltd_layout_done) {
2234 spin_unlock(<ds->ltd_lock);
2238 if (lr->lr_flags & LEF_TO_OST)
2239 list_add_tail(phase_list,
2240 &lad->lad_ost_phase2_list);
2242 list_add_tail(phase_list,
2243 &lad->lad_mdt_phase2_list);
2245 if (ltd->ltd_namespace_done) {
2246 spin_unlock(<ds->ltd_lock);
2250 list_add_tail(phase_list,
2251 &lad->lad_mdt_phase2_list);
2253 spin_unlock(<ds->ltd_lock);
2256 spin_lock(<ds->ltd_lock);
2257 list_del_init(phase_list);
2258 list_del_init(list);
2259 spin_unlock(<ds->ltd_lock);
2265 CDEBUG(D_LFSCK, "%s: unexpected event: rc = %d\n",
2266 lfsck_lfsck2name(com->lc_lfsck), lr->lr_event);
2270 if (!laia->laia_shared) {
2272 lfsck_component_put(env, com);
2278 static void lfsck_interpret(const struct lu_env *env,
2279 struct lfsck_instance *lfsck,
2280 struct ptlrpc_request *req, void *args, int result)
2282 struct lfsck_async_interpret_args *laia = args;
2283 struct lfsck_component *com;
2285 LASSERT(laia->laia_com == NULL);
2286 LASSERT(laia->laia_shared);
2288 spin_lock(&lfsck->li_lock);
2289 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
2290 laia->laia_com = com;
2291 lfsck_async_interpret_common(env, req, laia, result);
2294 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
2295 laia->laia_com = com;
2296 lfsck_async_interpret_common(env, req, laia, result);
2298 spin_unlock(&lfsck->li_lock);
2301 static int lfsck_stop_notify(const struct lu_env *env,
2302 struct lfsck_instance *lfsck,
2303 struct lfsck_tgt_descs *ltds,
2304 struct lfsck_tgt_desc *ltd, __u16 type)
2306 struct lfsck_component *com;
2310 LASSERT(lfsck->li_master);
2312 spin_lock(&lfsck->li_lock);
2313 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
2315 com = __lfsck_component_find(lfsck, type,
2316 &lfsck->li_list_double_scan);
2318 lfsck_component_get(com);
2319 spin_unlock(&lfsck->li_lock);
2322 struct lfsck_thread_info *info = lfsck_env_info(env);
2323 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2324 struct lfsck_request *lr = &info->lti_lr;
2325 struct lfsck_assistant_data *lad = com->lc_data;
2326 struct list_head *list;
2327 struct list_head *phase_list;
2328 struct ptlrpc_request_set *set;
2330 set = ptlrpc_prep_set();
2332 lfsck_component_put(env, com);
2337 if (type == LFSCK_TYPE_LAYOUT) {
2338 list = <d->ltd_layout_list;
2339 phase_list = <d->ltd_layout_phase_list;
2341 list = <d->ltd_namespace_list;
2342 phase_list = <d->ltd_namespace_phase_list;
2345 spin_lock(<ds->ltd_lock);
2346 if (list_empty(list)) {
2347 LASSERT(list_empty(phase_list));
2348 spin_unlock(<ds->ltd_lock);
2349 ptlrpc_set_destroy(set);
2354 list_del_init(phase_list);
2355 list_del_init(list);
2356 spin_unlock(<ds->ltd_lock);
2358 memset(lr, 0, sizeof(*lr));
2359 lr->lr_index = lfsck_dev_idx(lfsck);
2360 lr->lr_event = LE_PEER_EXIT;
2361 lr->lr_active = type;
2362 lr->lr_status = LS_CO_PAUSED;
2363 if (ltds == &lfsck->li_ost_descs)
2364 lr->lr_flags = LEF_TO_OST;
2366 memset(laia, 0, sizeof(*laia));
2367 laia->laia_com = com;
2368 laia->laia_ltds = ltds;
2369 atomic_inc(<d->ltd_ref);
2370 laia->laia_ltd = ltd;
2373 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2374 lfsck_async_interpret_common,
2375 laia, LFSCK_NOTIFY);
2377 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for "
2378 "co-stop for %s: rc = %d\n",
2379 lfsck_lfsck2name(lfsck),
2380 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2381 ltd->ltd_index, lad->lad_name, rc);
2384 rc = ptlrpc_set_wait(env, set);
2387 ptlrpc_set_destroy(set);
2388 lfsck_component_put(env, com);
2394 static int lfsck_async_interpret(const struct lu_env *env,
2395 struct ptlrpc_request *req,
2398 struct lfsck_async_interpret_args *laia = args;
2399 struct lfsck_instance *lfsck;
2401 lfsck = container_of0(laia->laia_ltds, struct lfsck_instance,
2403 lfsck_interpret(env, lfsck, req, laia, rc);
2404 lfsck_tgt_put(laia->laia_ltd);
2405 if (rc != 0 && laia->laia_result != -EALREADY)
2406 laia->laia_result = rc;
2411 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
2412 struct lfsck_request *lr,
2413 struct ptlrpc_request_set *set,
2414 ptlrpc_interpterer_t interpreter,
2415 void *args, int request)
2417 struct lfsck_async_interpret_args *laia;
2418 struct ptlrpc_request *req;
2419 struct lfsck_request *tmp;
2420 struct req_format *format;
2425 format = &RQF_LFSCK_NOTIFY;
2428 format = &RQF_LFSCK_QUERY;
2431 CDEBUG(D_LFSCK, "%s: unknown async request %d: rc = %d\n",
2432 exp->exp_obd->obd_name, request, -EINVAL);
2436 req = ptlrpc_request_alloc(class_exp2cliimp(exp), format);
2440 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, request);
2442 ptlrpc_request_free(req);
2447 tmp = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
2449 ptlrpc_request_set_replen(req);
2451 laia = ptlrpc_req_async_args(laia, req);
2452 *laia = *(struct lfsck_async_interpret_args *)args;
2453 if (laia->laia_com != NULL)
2454 lfsck_component_get(laia->laia_com);
2455 req->rq_interpret_reply = interpreter;
2456 req->rq_allow_intr = 1;
2457 req->rq_no_delay = 1;
2458 ptlrpc_set_add_req(set, req);
2463 int lfsck_query_all(const struct lu_env *env, struct lfsck_component *com)
2465 struct lfsck_thread_info *info = lfsck_env_info(env);
2466 struct lfsck_request *lr = &info->lti_lr;
2467 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2468 struct lfsck_instance *lfsck = com->lc_lfsck;
2469 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2470 struct lfsck_tgt_desc *ltd;
2471 struct ptlrpc_request_set *set;
2476 memset(lr, 0, sizeof(*lr));
2477 lr->lr_event = LE_QUERY;
2478 lr->lr_active = com->lc_type;
2479 lr->lr_flags = LEF_QUERY_ALL;
2481 memset(laia, 0, sizeof(*laia));
2482 laia->laia_com = com;
2485 set = ptlrpc_prep_set();
2490 laia->laia_ltds = ltds;
2491 down_read(<ds->ltd_rw_sem);
2492 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2493 ltd = lfsck_tgt_get(ltds, idx);
2494 LASSERT(ltd != NULL);
2496 laia->laia_ltd = ltd;
2497 up_read(<ds->ltd_rw_sem);
2498 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2499 lfsck_async_interpret_common,
2502 struct lfsck_assistant_data *lad = com->lc_data;
2504 CDEBUG(D_LFSCK, "%s: Fail to query %s %x for stat %s: "
2505 "rc = %d\n", lfsck_lfsck2name(lfsck),
2506 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2507 ltd->ltd_index, lad->lad_name, rc);
2508 lfsck_reset_ltd_status(ltd, com->lc_type);
2511 down_read(<ds->ltd_rw_sem);
2513 up_read(<ds->ltd_rw_sem);
2515 if (com->lc_type == LFSCK_TYPE_LAYOUT && !(lr->lr_flags & LEF_TO_OST)) {
2516 ltds = &lfsck->li_ost_descs;
2517 lr->lr_flags |= LEF_TO_OST;
2521 rc = ptlrpc_set_wait(env, set);
2522 ptlrpc_set_destroy(set);
2527 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
2528 struct lfsck_start_param *lsp)
2530 struct lfsck_instance *lfsck = com->lc_lfsck;
2531 struct lfsck_assistant_data *lad = com->lc_data;
2532 struct ptlrpc_thread *mthread = &lfsck->li_thread;
2533 struct ptlrpc_thread *athread = &lad->lad_thread;
2534 struct lfsck_thread_args *lta;
2535 struct task_struct *task;
2539 lad->lad_assistant_status = 0;
2540 lad->lad_post_result = 0;
2542 lad->lad_advance_lock = false;
2543 thread_set_flags(athread, 0);
2545 lta = lfsck_thread_args_init(lfsck, com, lsp);
2547 RETURN(PTR_ERR(lta));
2549 task = kthread_run(lfsck_assistant_engine, lta, lad->lad_name);
2552 CERROR("%s: cannot start LFSCK assistant thread for %s: "
2553 "rc = %d\n", lfsck_lfsck2name(lfsck), lad->lad_name, rc);
2554 lfsck_thread_args_fini(lta);
2556 struct l_wait_info lwi = { 0 };
2558 l_wait_event(mthread->t_ctl_waitq,
2559 thread_is_running(athread) ||
2560 thread_is_stopped(athread) ||
2561 !thread_is_starting(mthread),
2563 if (unlikely(!thread_is_starting(mthread)))
2564 /* stopped by race */
2566 else if (unlikely(!thread_is_running(athread)))
2567 rc = lad->lad_assistant_status;
2575 int lfsck_checkpoint_generic(const struct lu_env *env,
2576 struct lfsck_component *com)
2578 struct lfsck_assistant_data *lad = com->lc_data;
2579 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2580 struct ptlrpc_thread *athread = &lad->lad_thread;
2581 struct l_wait_info lwi = { 0 };
2583 l_wait_event(mthread->t_ctl_waitq,
2584 list_empty(&lad->lad_req_list) ||
2585 !thread_is_running(mthread) ||
2586 thread_is_stopped(athread),
2589 if (!thread_is_running(mthread) || thread_is_stopped(athread))
2590 return LFSCK_CHECKPOINT_SKIP;
2595 void lfsck_post_generic(const struct lu_env *env,
2596 struct lfsck_component *com, int *result)
2598 struct lfsck_assistant_data *lad = com->lc_data;
2599 struct ptlrpc_thread *athread = &lad->lad_thread;
2600 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2601 struct l_wait_info lwi = { 0 };
2603 lad->lad_post_result = *result;
2605 set_bit(LAD_EXIT, &lad->lad_flags);
2606 set_bit(LAD_TO_POST, &lad->lad_flags);
2608 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s post, rc = %d\n",
2609 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2611 wake_up_all(&athread->t_ctl_waitq);
2612 l_wait_event(mthread->t_ctl_waitq,
2613 (*result > 0 && list_empty(&lad->lad_req_list)) ||
2614 thread_is_stopped(athread),
2617 if (lad->lad_assistant_status < 0)
2618 *result = lad->lad_assistant_status;
2620 CDEBUG(D_LFSCK, "%s: the assistant has done %s post, rc = %d\n",
2621 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2624 int lfsck_double_scan_generic(const struct lu_env *env,
2625 struct lfsck_component *com, int status)
2627 struct lfsck_assistant_data *lad = com->lc_data;
2628 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2629 struct ptlrpc_thread *athread = &lad->lad_thread;
2630 struct l_wait_info lwi = { 0 };
2632 if (status != LS_SCANNING_PHASE2)
2633 set_bit(LAD_EXIT, &lad->lad_flags);
2635 set_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags);
2637 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s double_scan, "
2639 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, status);
2641 wake_up_all(&athread->t_ctl_waitq);
2642 l_wait_event(mthread->t_ctl_waitq,
2643 test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags) ||
2644 thread_is_stopped(athread),
2647 CDEBUG(D_LFSCK, "%s: the assistant has done %s double_scan, "
2648 "status %d\n", lfsck_lfsck2name(com->lc_lfsck), lad->lad_name,
2649 lad->lad_assistant_status);
2651 if (lad->lad_assistant_status < 0)
2652 return lad->lad_assistant_status;
2657 void lfsck_quit_generic(const struct lu_env *env,
2658 struct lfsck_component *com)
2660 struct lfsck_assistant_data *lad = com->lc_data;
2661 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2662 struct ptlrpc_thread *athread = &lad->lad_thread;
2663 struct l_wait_info lwi = { 0 };
2665 set_bit(LAD_EXIT, &lad->lad_flags);
2666 wake_up_all(&athread->t_ctl_waitq);
2667 l_wait_event(mthread->t_ctl_waitq,
2668 thread_is_init(athread) ||
2669 thread_is_stopped(athread),
2673 int lfsck_load_one_trace_file(const struct lu_env *env,
2674 struct lfsck_component *com,
2675 struct dt_object *parent,
2676 struct dt_object **child,
2677 const struct dt_index_features *ft,
2678 const char *name, bool reset)
2680 struct lfsck_instance *lfsck = com->lc_lfsck;
2681 struct dt_object *obj;
2685 if (*child != NULL) {
2687 const struct dt_it_ops *iops;
2688 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid3;
2694 rc = obj->do_ops->do_index_try(env, obj, ft);
2696 /* unlink by force */
2699 iops = &obj->do_index_ops->dio_it;
2700 it = iops->init(env, obj, 0);
2702 /* unlink by force */
2706 rc = iops->get(env, it, (const struct dt_key *)fid);
2708 rc = iops->next(env, it);
2711 iops->fini(env, it);
2713 /* "rc > 0" means the index file is empty. */
2717 /* The old index is not empty, remove it firstly. */
2718 rc = local_object_unlink(env, lfsck->li_bottom, parent, name);
2719 CDEBUG_LIMIT(rc ? D_ERROR : D_LFSCK,
2720 "%s: unlink lfsck sub trace file %s: rc = %d\n",
2721 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2726 lfsck_object_put(env, *child);
2733 obj = local_index_find_or_create(env, lfsck->li_los, parent, name,
2734 S_IFREG | S_IRUGO | S_IWUSR, ft);
2736 RETURN(PTR_ERR(obj));
2738 rc = obj->do_ops->do_index_try(env, obj, ft);
2740 lfsck_object_put(env, obj);
2741 CDEBUG(D_LFSCK, "%s: LFSCK fail to load "
2742 "sub trace file %s: rc = %d\n",
2743 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2751 int lfsck_load_sub_trace_files(const struct lu_env *env,
2752 struct lfsck_component *com,
2753 const struct dt_index_features *ft,
2754 const char *prefix, bool reset)
2756 char *name = lfsck_env_info(env)->lti_key;
2757 struct lfsck_sub_trace_obj *lsto;
2761 for (i = 0, rc = 0, lsto = &com->lc_sub_trace_objs[0];
2762 i < LFSCK_STF_COUNT && rc == 0; i++, lsto++) {
2763 snprintf(name, NAME_MAX, "%s_%02d", prefix, i);
2764 rc = lfsck_load_one_trace_file(env, com,
2765 com->lc_lfsck->li_lfsck_dir,
2766 &lsto->lsto_obj, ft, name, reset);
2772 /* external interfaces */
2773 int lfsck_get_speed(char *buf, struct dt_device *key)
2776 struct lfsck_instance *lfsck;
2780 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2784 lfsck = lfsck_instance_find(key, true, false);
2786 rc = sprintf(buf, "%u\n",
2787 lfsck->li_bookmark_ram.lb_speed_limit);
2788 lfsck_instance_put(&env, lfsck);
2797 EXPORT_SYMBOL(lfsck_get_speed);
2799 int lfsck_set_speed(struct dt_device *key, __u32 val)
2802 struct lfsck_instance *lfsck;
2806 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2810 lfsck = lfsck_instance_find(key, true, false);
2811 if (likely(lfsck != NULL)) {
2812 mutex_lock(&lfsck->li_mutex);
2813 if (__lfsck_set_speed(lfsck, val))
2814 rc = lfsck_bookmark_store(&env, lfsck);
2815 mutex_unlock(&lfsck->li_mutex);
2816 lfsck_instance_put(&env, lfsck);
2825 EXPORT_SYMBOL(lfsck_set_speed);
2827 int lfsck_get_windows(char *buf, struct dt_device *key)
2830 struct lfsck_instance *lfsck;
2834 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2838 lfsck = lfsck_instance_find(key, true, false);
2839 if (likely(lfsck != NULL)) {
2840 rc = sprintf(buf, "%u\n",
2841 lfsck->li_bookmark_ram.lb_async_windows);
2842 lfsck_instance_put(&env, lfsck);
2851 EXPORT_SYMBOL(lfsck_get_windows);
2853 int lfsck_set_windows(struct dt_device *key, unsigned int val)
2856 struct lfsck_instance *lfsck;
2860 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2864 lfsck = lfsck_instance_find(key, true, false);
2865 if (likely(lfsck != NULL)) {
2866 if (val < 1 || val > LFSCK_ASYNC_WIN_MAX) {
2867 CWARN("%s: invalid async windows size that may "
2868 "cause memory issues. The valid range is "
2870 lfsck_lfsck2name(lfsck), LFSCK_ASYNC_WIN_MAX);
2872 } else if (lfsck->li_bookmark_ram.lb_async_windows != val) {
2873 mutex_lock(&lfsck->li_mutex);
2874 lfsck->li_bookmark_ram.lb_async_windows = val;
2875 rc = lfsck_bookmark_store(&env, lfsck);
2876 mutex_unlock(&lfsck->li_mutex);
2878 lfsck_instance_put(&env, lfsck);
2887 EXPORT_SYMBOL(lfsck_set_windows);
2889 int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
2892 struct lfsck_instance *lfsck;
2893 struct lfsck_component *com;
2897 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2901 lfsck = lfsck_instance_find(key, true, false);
2902 if (likely(lfsck != NULL)) {
2903 com = lfsck_component_find(lfsck, type);
2904 if (likely(com != NULL)) {
2905 com->lc_ops->lfsck_dump(&env, com, m);
2906 lfsck_component_put(&env, com);
2911 lfsck_instance_put(&env, lfsck);
2920 EXPORT_SYMBOL(lfsck_dump);
2922 static int lfsck_stop_all(const struct lu_env *env,
2923 struct lfsck_instance *lfsck,
2924 struct lfsck_stop *stop)
2926 struct lfsck_thread_info *info = lfsck_env_info(env);
2927 struct lfsck_request *lr = &info->lti_lr;
2928 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2929 struct ptlrpc_request_set *set;
2930 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2931 struct lfsck_tgt_desc *ltd;
2932 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2938 LASSERT(stop->ls_flags & LPF_BROADCAST);
2940 set = ptlrpc_prep_set();
2941 if (unlikely(set == NULL))
2944 memset(lr, 0, sizeof(*lr));
2945 lr->lr_event = LE_STOP;
2946 lr->lr_index = lfsck_dev_idx(lfsck);
2947 lr->lr_status = stop->ls_status;
2948 lr->lr_version = bk->lb_version;
2949 lr->lr_active = LFSCK_TYPES_ALL;
2950 lr->lr_param = stop->ls_flags;
2952 memset(laia, 0, sizeof(*laia));
2953 laia->laia_ltds = ltds;
2955 laia->laia_shared = 1;
2957 down_read(<ds->ltd_rw_sem);
2958 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2959 ltd = lfsck_tgt_get(ltds, idx);
2960 LASSERT(ltd != NULL);
2962 laia->laia_ltd = ltd;
2963 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2964 lfsck_async_interpret, laia,
2967 lfsck_interpret(env, lfsck, NULL, laia, rc);
2969 CERROR("%s: cannot notify MDT %x for LFSCK stop: "
2970 "rc = %d\n", lfsck_lfsck2name(lfsck), idx, rc);
2974 up_read(<ds->ltd_rw_sem);
2976 rc = ptlrpc_set_wait(env, set);
2977 ptlrpc_set_destroy(set);
2980 rc = laia->laia_result;
2982 if (rc == -EALREADY)
2986 CERROR("%s: fail to stop LFSCK on some MDTs: rc = %d\n",
2987 lfsck_lfsck2name(lfsck), rc);
2989 RETURN(rc != 0 ? rc : rc1);
2992 static int lfsck_start_all(const struct lu_env *env,
2993 struct lfsck_instance *lfsck,
2994 struct lfsck_start *start)
2996 struct lfsck_thread_info *info = lfsck_env_info(env);
2997 struct lfsck_request *lr = &info->lti_lr;
2998 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2999 struct ptlrpc_request_set *set;
3000 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
3001 struct lfsck_tgt_desc *ltd;
3002 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
3008 LASSERT(start->ls_flags & LPF_BROADCAST);
3010 memset(lr, 0, sizeof(*lr));
3011 lr->lr_event = LE_START;
3012 lr->lr_index = lfsck_dev_idx(lfsck);
3013 lr->lr_speed = bk->lb_speed_limit;
3014 lr->lr_version = bk->lb_version;
3015 lr->lr_active = start->ls_active;
3016 lr->lr_param = start->ls_flags;
3017 lr->lr_async_windows = bk->lb_async_windows;
3018 lr->lr_valid = LSV_SPEED_LIMIT | LSV_ERROR_HANDLE | LSV_DRYRUN |
3019 LSV_ASYNC_WINDOWS | LSV_CREATE_OSTOBJ |
3022 memset(laia, 0, sizeof(*laia));
3023 laia->laia_ltds = ltds;
3025 laia->laia_shared = 1;
3028 set = ptlrpc_prep_set();
3032 down_read(<ds->ltd_rw_sem);
3033 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3034 ltd = lfsck_tgt_get(ltds, idx);
3035 LASSERT(ltd != NULL);
3037 if (retry && !ltd->ltd_retry_start) {
3042 laia->laia_ltd = ltd;
3043 ltd->ltd_retry_start = 0;
3044 ltd->ltd_layout_done = 0;
3045 ltd->ltd_namespace_done = 0;
3046 ltd->ltd_synced_failures = 0;
3047 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
3048 lfsck_async_interpret, laia,
3051 lfsck_interpret(env, lfsck, NULL, laia, rc);
3053 CERROR("%s: cannot notify MDT %x for LFSCK "
3054 "start, failout: rc = %d\n",
3055 lfsck_lfsck2name(lfsck), idx, rc);
3059 up_read(<ds->ltd_rw_sem);
3062 ptlrpc_set_destroy(set);
3067 rc = ptlrpc_set_wait(env, set);
3068 ptlrpc_set_destroy(set);
3071 rc = laia->laia_result;
3073 if (unlikely(rc == -EINPROGRESS)) {
3075 set_current_state(TASK_INTERRUPTIBLE);
3076 schedule_timeout(cfs_time_seconds(1));
3077 set_current_state(TASK_RUNNING);
3078 if (!signal_pending(current) &&
3079 thread_is_running(&lfsck->li_thread))
3086 struct lfsck_stop *stop = &info->lti_stop;
3088 CERROR("%s: cannot start LFSCK on some MDTs, "
3089 "stop all: rc = %d\n",
3090 lfsck_lfsck2name(lfsck), rc);
3091 if (rc != -EALREADY) {
3092 stop->ls_status = LS_FAILED;
3093 stop->ls_flags = LPF_ALL_TGT | LPF_BROADCAST;
3094 lfsck_stop_all(env, lfsck, stop);
3101 int lfsck_start(const struct lu_env *env, struct dt_device *key,
3102 struct lfsck_start_param *lsp)
3104 struct lfsck_start *start = lsp->lsp_start;
3105 struct lfsck_instance *lfsck;
3106 struct lfsck_bookmark *bk;
3107 struct ptlrpc_thread *thread;
3108 struct lfsck_component *com;
3109 struct l_wait_info lwi = { 0 };
3110 struct lfsck_thread_args *lta;
3111 struct task_struct *task;
3112 struct lfsck_tgt_descs *ltds;
3113 struct lfsck_tgt_desc *ltd;
3124 lfsck = lfsck_instance_find(key, true, false);
3125 if (unlikely(lfsck == NULL))
3128 if (unlikely(lfsck->li_stopping))
3129 GOTO(put, rc = -ENXIO);
3131 /* System is not ready, try again later. */
3132 if (unlikely(lfsck->li_namespace == NULL ||
3133 lfsck_dev_site(lfsck)->ss_server_fld == NULL))
3134 GOTO(put, rc = -EINPROGRESS);
3136 /* start == NULL means auto trigger paused LFSCK. */
3138 if (list_empty(&lfsck->li_list_scan) ||
3139 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AUTO))
3141 } else if (start->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3142 CERROR("%s: only allow to specify '-A | -o' via MDS\n",
3143 lfsck_lfsck2name(lfsck));
3145 GOTO(put, rc = -EPERM);
3148 bk = &lfsck->li_bookmark_ram;
3149 thread = &lfsck->li_thread;
3150 mutex_lock(&lfsck->li_mutex);
3151 spin_lock(&lfsck->li_lock);
3152 if (unlikely(thread_is_stopping(thread))) {
3153 /* Someone is stopping the LFSCK. */
3154 spin_unlock(&lfsck->li_lock);
3155 GOTO(out, rc = -EBUSY);
3158 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
3160 if (unlikely(start == NULL)) {
3161 spin_unlock(&lfsck->li_lock);
3165 while (start->ls_active != 0) {
3166 if (!(type & start->ls_active)) {
3171 com = __lfsck_component_find(lfsck, type,
3172 &lfsck->li_list_scan);
3174 com = __lfsck_component_find(lfsck, type,
3175 &lfsck->li_list_double_scan);
3181 if (com->lc_ops->lfsck_join != NULL) {
3182 rc = com->lc_ops->lfsck_join( env, com, lsp);
3183 if (rc != 0 && rc != -EALREADY)
3186 start->ls_active &= ~type;
3189 spin_unlock(&lfsck->li_lock);
3192 spin_unlock(&lfsck->li_lock);
3194 lfsck->li_status = 0;
3195 lfsck->li_oit_over = 0;
3196 lfsck->li_start_unplug = 0;
3197 lfsck->li_drop_dryrun = 0;
3198 lfsck->li_new_scanned = 0;
3200 /* For auto trigger. */
3204 start->ls_version = bk->lb_version;
3206 if (start->ls_active != 0) {
3207 struct lfsck_component *next;
3209 if (start->ls_active == LFSCK_TYPES_ALL)
3210 start->ls_active = LFSCK_TYPES_SUPPORTED;
3212 if (start->ls_active & ~LFSCK_TYPES_SUPPORTED) {
3213 start->ls_active &= ~LFSCK_TYPES_SUPPORTED;
3214 GOTO(out, rc = -ENOTSUPP);
3217 list_for_each_entry_safe(com, next,
3218 &lfsck->li_list_scan, lc_link) {
3219 if (!(com->lc_type & start->ls_active)) {
3220 rc = com->lc_ops->lfsck_post(env, com, 0,
3227 while (start->ls_active != 0) {
3228 if (type & start->ls_active) {
3229 com = __lfsck_component_find(lfsck, type,
3230 &lfsck->li_list_idle);
3232 /* The component status will be updated
3233 * when its prep() is called later by
3234 * the LFSCK main engine. */
3235 list_move_tail(&com->lc_link,
3236 &lfsck->li_list_scan);
3237 start->ls_active &= ~type;
3243 if (list_empty(&lfsck->li_list_scan)) {
3244 /* The speed limit will be used to control both the LFSCK and
3245 * low layer scrub (if applied), need to be handled firstly. */
3246 if (start->ls_valid & LSV_SPEED_LIMIT) {
3247 if (__lfsck_set_speed(lfsck, start->ls_speed_limit)) {
3248 rc = lfsck_bookmark_store(env, lfsck);
3257 if (start->ls_flags & LPF_RESET)
3258 flags |= DOIF_RESET;
3260 rc = lfsck_set_param(env, lfsck, start, !!(flags & DOIF_RESET));
3264 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3265 start->ls_active |= com->lc_type;
3266 if (flags & DOIF_RESET) {
3267 rc = com->lc_ops->lfsck_reset(env, com, false);
3273 ltds = &lfsck->li_mdt_descs;
3274 down_read(<ds->ltd_rw_sem);
3275 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3276 ltd = lfsck_ltd2tgt(ltds, idx);
3277 LASSERT(ltd != NULL);
3279 ltd->ltd_layout_done = 0;
3280 ltd->ltd_namespace_done = 0;
3281 ltd->ltd_synced_failures = 0;
3282 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_NAMESPACE);
3283 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3284 list_del_init(<d->ltd_layout_phase_list);
3285 list_del_init(<d->ltd_layout_list);
3286 list_del_init(<d->ltd_namespace_phase_list);
3287 list_del_init(<d->ltd_namespace_list);
3289 up_read(<ds->ltd_rw_sem);
3291 ltds = &lfsck->li_ost_descs;
3292 down_read(<ds->ltd_rw_sem);
3293 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3294 ltd = lfsck_ltd2tgt(ltds, idx);
3295 LASSERT(ltd != NULL);
3297 ltd->ltd_layout_done = 0;
3298 ltd->ltd_synced_failures = 0;
3299 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3300 list_del_init(<d->ltd_layout_phase_list);
3301 list_del_init(<d->ltd_layout_list);
3303 up_read(<ds->ltd_rw_sem);
3306 lfsck->li_args_dir = LUDA_64BITHASH | LUDA_VERIFY | LUDA_TYPE;
3307 if (bk->lb_param & LPF_DRYRUN)
3308 lfsck->li_args_dir |= LUDA_VERIFY_DRYRUN;
3310 if (start != NULL && start->ls_valid & LSV_ERROR_HANDLE) {
3311 valid |= DOIV_ERROR_HANDLE;
3312 if (start->ls_flags & LPF_FAILOUT)
3313 flags |= DOIF_FAILOUT;
3316 if (start != NULL && start->ls_valid & LSV_DRYRUN) {
3317 valid |= DOIV_DRYRUN;
3318 if (start->ls_flags & LPF_DRYRUN)
3319 flags |= DOIF_DRYRUN;
3322 if (!list_empty(&lfsck->li_list_scan))
3323 flags |= DOIF_OUTUSED;
3325 lfsck->li_args_oit = (flags << DT_OTABLE_IT_FLAGS_SHIFT) | valid;
3326 lta = lfsck_thread_args_init(lfsck, NULL, lsp);
3328 GOTO(out, rc = PTR_ERR(lta));
3330 __lfsck_set_speed(lfsck, bk->lb_speed_limit);
3331 spin_lock(&lfsck->li_lock);
3332 thread_set_flags(thread, SVC_STARTING);
3333 spin_unlock(&lfsck->li_lock);
3334 task = kthread_run(lfsck_master_engine, lta, "lfsck");
3337 CERROR("%s: cannot start LFSCK thread: rc = %d\n",
3338 lfsck_lfsck2name(lfsck), rc);
3339 lfsck_thread_args_fini(lta);
3344 l_wait_event(thread->t_ctl_waitq,
3345 thread_is_running(thread) ||
3346 thread_is_stopped(thread),
3348 if (start == NULL || !(start->ls_flags & LPF_BROADCAST)) {
3349 lfsck->li_start_unplug = 1;
3350 wake_up_all(&thread->t_ctl_waitq);
3355 /* release lfsck::li_mutex to avoid deadlock. */
3356 mutex_unlock(&lfsck->li_mutex);
3357 rc = lfsck_start_all(env, lfsck, start);
3359 spin_lock(&lfsck->li_lock);
3360 if (thread_is_stopped(thread)) {
3361 spin_unlock(&lfsck->li_lock);
3363 lfsck->li_status = LS_FAILED;
3364 lfsck->li_flags = 0;
3365 thread_set_flags(thread, SVC_STOPPING);
3366 spin_unlock(&lfsck->li_lock);
3368 lfsck->li_start_unplug = 1;
3369 wake_up_all(&thread->t_ctl_waitq);
3370 l_wait_event(thread->t_ctl_waitq,
3371 thread_is_stopped(thread),
3375 lfsck->li_start_unplug = 1;
3376 wake_up_all(&thread->t_ctl_waitq);
3382 mutex_unlock(&lfsck->li_mutex);
3385 lfsck_instance_put(env, lfsck);
3387 return rc < 0 ? rc : 0;
3389 EXPORT_SYMBOL(lfsck_start);
3391 int lfsck_stop(const struct lu_env *env, struct dt_device *key,
3392 struct lfsck_stop *stop)
3394 struct lfsck_instance *lfsck;
3395 struct ptlrpc_thread *thread;
3396 struct l_wait_info lwi = { 0 };
3401 lfsck = lfsck_instance_find(key, true, false);
3402 if (unlikely(lfsck == NULL))
3405 thread = &lfsck->li_thread;
3406 if (stop && stop->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3407 CERROR("%s: only allow to specify '-A' via MDS\n",
3408 lfsck_lfsck2name(lfsck));
3409 GOTO(put, rc = -EPERM);
3412 spin_lock(&lfsck->li_lock);
3413 /* The target is umounted */
3414 if (stop && stop->ls_status == LS_PAUSED)
3415 lfsck->li_stopping = 1;
3417 if (thread_is_init(thread) || thread_is_stopped(thread))
3418 /* no error if LFSCK stopped already, or not started */
3419 GOTO(unlock, rc = 0);
3421 if (thread_is_stopping(thread))
3422 /* Someone is stopping LFSCK. */
3423 GOTO(unlock, rc = -EINPROGRESS);
3426 lfsck->li_status = stop->ls_status;
3427 lfsck->li_flags = stop->ls_flags;
3429 lfsck->li_status = LS_STOPPED;
3430 lfsck->li_flags = 0;
3433 thread_set_flags(thread, SVC_STOPPING);
3435 LASSERT(lfsck->li_task != NULL);
3436 force_sig(SIGINT, lfsck->li_task);
3438 if (lfsck->li_master) {
3439 struct lfsck_component *com;
3440 struct lfsck_assistant_data *lad;
3442 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3444 spin_lock(&lad->lad_lock);
3445 if (lad->lad_task != NULL)
3446 force_sig(SIGINT, lad->lad_task);
3447 spin_unlock(&lad->lad_lock);
3450 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
3452 spin_lock(&lad->lad_lock);
3453 if (lad->lad_task != NULL)
3454 force_sig(SIGINT, lad->lad_task);
3455 spin_unlock(&lad->lad_lock);
3459 wake_up_all(&thread->t_ctl_waitq);
3460 spin_unlock(&lfsck->li_lock);
3461 if (stop && stop->ls_flags & LPF_BROADCAST)
3462 rc1 = lfsck_stop_all(env, lfsck, stop);
3464 /* It was me set the status as 'stopping' just now, if it is not
3465 * 'stopping' now, then either stopped, or re-started by race. */
3466 l_wait_event(thread->t_ctl_waitq,
3467 !thread_is_stopping(thread),
3473 spin_unlock(&lfsck->li_lock);
3475 lfsck_instance_put(env, lfsck);
3477 return rc != 0 ? rc : rc1;
3479 EXPORT_SYMBOL(lfsck_stop);
3481 int lfsck_in_notify_local(const struct lu_env *env, struct dt_device *key,
3482 struct lfsck_req_local *lrl, struct thandle *th)
3484 struct lfsck_instance *lfsck;
3485 struct lfsck_component *com;
3486 int rc = -EOPNOTSUPP;
3489 lfsck = lfsck_instance_find(key, true, false);
3490 if (unlikely(!lfsck))
3493 com = lfsck_component_find(lfsck, lrl->lrl_active);
3494 if (likely(com && com->lc_ops->lfsck_in_notify_local)) {
3495 rc = com->lc_ops->lfsck_in_notify_local(env, com, lrl, th);
3496 lfsck_component_put(env, com);
3499 lfsck_instance_put(env, lfsck);
3503 EXPORT_SYMBOL(lfsck_in_notify_local);
3505 int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
3506 struct lfsck_request *lr)
3508 int rc = -EOPNOTSUPP;
3511 switch (lr->lr_event) {
3513 struct lfsck_start *start = &lfsck_env_info(env)->lti_start;
3514 struct lfsck_start_param lsp;
3516 memset(start, 0, sizeof(*start));
3517 start->ls_valid = lr->lr_valid;
3518 start->ls_speed_limit = lr->lr_speed;
3519 start->ls_version = lr->lr_version;
3520 start->ls_active = lr->lr_active;
3521 start->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3522 start->ls_async_windows = lr->lr_async_windows;
3524 lsp.lsp_start = start;
3525 lsp.lsp_index = lr->lr_index;
3526 lsp.lsp_index_valid = 1;
3527 rc = lfsck_start(env, key, &lsp);
3531 struct lfsck_stop *stop = &lfsck_env_info(env)->lti_stop;
3533 memset(stop, 0, sizeof(*stop));
3534 stop->ls_status = lr->lr_status;
3535 stop->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3536 rc = lfsck_stop(env, key, stop);
3539 case LE_PHASE1_DONE:
3540 case LE_PHASE2_DONE:
3542 case LE_CONDITIONAL_DESTROY:
3543 case LE_SET_LMV_MASTER:
3544 case LE_SET_LMV_SLAVE:
3545 case LE_PAIRS_VERIFY: {
3546 struct lfsck_instance *lfsck;
3547 struct lfsck_component *com;
3549 lfsck = lfsck_instance_find(key, true, false);
3550 if (unlikely(lfsck == NULL))
3553 com = lfsck_component_find(lfsck, lr->lr_active);
3555 rc = com->lc_ops->lfsck_in_notify(env, com, lr);
3556 lfsck_component_put(env, com);
3559 lfsck_instance_put(env, lfsck);
3568 EXPORT_SYMBOL(lfsck_in_notify);
3570 int lfsck_query(const struct lu_env *env, struct dt_device *key,
3571 struct lfsck_request *req, struct lfsck_reply *rep,
3572 struct lfsck_query *que)
3574 struct lfsck_instance *lfsck;
3575 struct lfsck_component *com;
3581 lfsck = lfsck_instance_find(key, true, false);
3582 if (unlikely(lfsck == NULL))
3586 if (que->lu_types == LFSCK_TYPES_ALL)
3588 LFSCK_TYPES_SUPPORTED & ~LFSCK_TYPE_SCRUB;
3590 if (que->lu_types & ~LFSCK_TYPES_SUPPORTED) {
3591 que->lu_types &= ~LFSCK_TYPES_SUPPORTED;
3593 GOTO(out, rc = -ENOTSUPP);
3596 for (i = 0, type = 1 << i; i < LFSCK_TYPE_BITS;
3597 i++, type = 1 << i) {
3598 if (!(que->lu_types & type))
3602 com = lfsck_component_find(lfsck, type);
3603 if (unlikely(com == NULL))
3604 GOTO(out, rc = -ENOTSUPP);
3606 memset(que->lu_mdts_count[i], 0,
3607 sizeof(__u32) * (LS_MAX + 1));
3608 memset(que->lu_osts_count[i], 0,
3609 sizeof(__u32) * (LS_MAX + 1));
3610 que->lu_repaired[i] = 0;
3611 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3613 lfsck_component_put(env, com);
3618 if (!(que->lu_flags & LPF_WAIT))
3621 for (i = 0, type = 1 << i; i < LFSCK_TYPE_BITS;
3622 i++, type = 1 << i) {
3623 if (!(que->lu_types & type))
3626 if (que->lu_mdts_count[i][LS_SCANNING_PHASE1] != 0 ||
3627 que->lu_mdts_count[i][LS_SCANNING_PHASE2] != 0 ||
3628 que->lu_osts_count[i][LS_SCANNING_PHASE1] != 0 ||
3629 que->lu_osts_count[i][LS_SCANNING_PHASE2] != 0) {
3630 struct l_wait_info lwi;
3632 /* If it is required to wait, then sleep
3633 * 3 seconds and try to query again. */
3634 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(3),
3638 rc = l_wait_event(lfsck->li_thread.t_ctl_waitq,
3640 if (rc == -ETIMEDOUT)
3645 com = lfsck_component_find(lfsck, req->lr_active);
3646 if (likely(com != NULL)) {
3647 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3649 lfsck_component_put(env, com);
3658 lfsck_instance_put(env, lfsck);
3661 EXPORT_SYMBOL(lfsck_query);
3663 int lfsck_register_namespace(const struct lu_env *env, struct dt_device *key,
3664 struct ldlm_namespace *ns)
3666 struct lfsck_instance *lfsck;
3669 lfsck = lfsck_instance_find(key, true, false);
3670 if (likely(lfsck != NULL)) {
3671 lfsck->li_namespace = ns;
3672 lfsck_instance_put(env, lfsck);
3678 EXPORT_SYMBOL(lfsck_register_namespace);
3680 int lfsck_register(const struct lu_env *env, struct dt_device *key,
3681 struct dt_device *next, struct obd_device *obd,
3682 lfsck_out_notify notify, void *notify_data, bool master)
3684 struct lfsck_instance *lfsck;
3685 struct dt_object *root = NULL;
3686 struct dt_object *obj = NULL;
3687 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
3691 lfsck = lfsck_instance_find(key, false, false);
3692 if (unlikely(lfsck != NULL))
3695 OBD_ALLOC_PTR(lfsck);
3699 mutex_init(&lfsck->li_mutex);
3700 spin_lock_init(&lfsck->li_lock);
3701 INIT_LIST_HEAD(&lfsck->li_link);
3702 INIT_LIST_HEAD(&lfsck->li_list_scan);
3703 INIT_LIST_HEAD(&lfsck->li_list_dir);
3704 INIT_LIST_HEAD(&lfsck->li_list_double_scan);
3705 INIT_LIST_HEAD(&lfsck->li_list_idle);
3706 INIT_LIST_HEAD(&lfsck->li_list_lmv);
3707 atomic_set(&lfsck->li_ref, 1);
3708 atomic_set(&lfsck->li_double_scan_count, 0);
3709 init_waitqueue_head(&lfsck->li_thread.t_ctl_waitq);
3710 lfsck->li_out_notify = notify;
3711 lfsck->li_out_notify_data = notify_data;
3712 lfsck->li_next = next;
3713 lfsck->li_bottom = key;
3714 lfsck->li_obd = obd;
3716 rc = lfsck_tgt_descs_init(&lfsck->li_ost_descs);
3720 rc = lfsck_tgt_descs_init(&lfsck->li_mdt_descs);
3724 fid->f_seq = FID_SEQ_LOCAL_NAME;
3727 rc = local_oid_storage_init(env, key, fid, &lfsck->li_los);
3731 rc = dt_root_get(env, key, fid);
3735 root = dt_locate(env, key, fid);
3737 GOTO(out, rc = PTR_ERR(root));
3739 if (unlikely(!dt_try_as_dir(env, root)))
3740 GOTO(out, rc = -ENOTDIR);
3742 lfsck->li_local_root_fid = *fid;
3744 lfsck->li_master = 1;
3745 if (lfsck_dev_idx(lfsck) == 0) {
3746 struct lu_fid *pfid = &lfsck_env_info(env)->lti_fid2;
3747 const struct lu_name *cname;
3749 rc = dt_lookup(env, root,
3750 (struct dt_rec *)(&lfsck->li_global_root_fid),
3751 (const struct dt_key *)"ROOT");
3755 obj = dt_locate(env, key, &lfsck->li_global_root_fid);
3757 GOTO(out, rc = PTR_ERR(obj));
3759 if (unlikely(!dt_try_as_dir(env, obj)))
3760 GOTO(out, rc = -ENOTDIR);
3762 rc = dt_lookup(env, obj, (struct dt_rec *)fid,
3763 (const struct dt_key *)dotlustre);
3767 lfsck_object_put(env, obj);
3768 obj = dt_locate(env, key, fid);
3770 GOTO(out, rc = PTR_ERR(obj));
3772 cname = lfsck_name_get_const(env, dotlustre,
3774 rc = lfsck_verify_linkea(env, obj, cname,
3775 &lfsck->li_global_root_fid);
3779 if (unlikely(!dt_try_as_dir(env, obj)))
3780 GOTO(out, rc = -ENOTDIR);
3783 rc = dt_lookup(env, obj, (struct dt_rec *)fid,
3784 (const struct dt_key *)lostfound);
3788 lfsck_object_put(env, obj);
3789 obj = dt_locate(env, key, fid);
3791 GOTO(out, rc = PTR_ERR(obj));
3793 cname = lfsck_name_get_const(env, lostfound,
3795 rc = lfsck_verify_linkea(env, obj, cname, pfid);
3799 lfsck_object_put(env, obj);
3804 fid->f_seq = FID_SEQ_LOCAL_FILE;
3805 fid->f_oid = OTABLE_IT_OID;
3807 obj = dt_locate(env, key, fid);
3809 GOTO(out, rc = PTR_ERR(obj));
3811 rc = obj->do_ops->do_index_try(env, obj, &dt_otable_features);
3815 lfsck->li_obj_oit = obj;
3816 obj = local_file_find_or_create(env, lfsck->li_los, root, LFSCK_DIR,
3817 S_IFDIR | S_IRUGO | S_IWUSR);
3819 GOTO(out, rc = PTR_ERR(obj));
3821 lu_object_get(&obj->do_lu);
3822 lfsck->li_lfsck_dir = obj;
3823 rc = lfsck_bookmark_setup(env, lfsck);
3828 rc = lfsck_fid_init(lfsck);
3832 rc = lfsck_namespace_setup(env, lfsck);
3837 rc = lfsck_layout_setup(env, lfsck);
3841 /* XXX: more LFSCK components initialization to be added here. */
3843 rc = lfsck_instance_add(lfsck);
3845 rc = lfsck_add_target_from_orphan(env, lfsck);
3847 if (obj != NULL && !IS_ERR(obj))
3848 lfsck_object_put(env, obj);
3849 if (root != NULL && !IS_ERR(root))
3850 lfsck_object_put(env, root);
3852 lfsck_instance_cleanup(env, lfsck);
3855 EXPORT_SYMBOL(lfsck_register);
3857 void lfsck_degister(const struct lu_env *env, struct dt_device *key)
3859 struct lfsck_instance *lfsck;
3861 lfsck = lfsck_instance_find(key, false, true);
3863 lfsck_instance_put(env, lfsck);
3865 EXPORT_SYMBOL(lfsck_degister);
3867 int lfsck_add_target(const struct lu_env *env, struct dt_device *key,
3868 struct dt_device *tgt, struct obd_export *exp,
3869 __u32 index, bool for_ost)
3871 struct lfsck_instance *lfsck;
3872 struct lfsck_tgt_desc *ltd;
3883 INIT_LIST_HEAD(<d->ltd_orphan_list);
3884 INIT_LIST_HEAD(<d->ltd_layout_list);
3885 INIT_LIST_HEAD(<d->ltd_layout_phase_list);
3886 INIT_LIST_HEAD(<d->ltd_namespace_list);
3887 INIT_LIST_HEAD(<d->ltd_namespace_phase_list);
3888 atomic_set(<d->ltd_ref, 1);
3889 ltd->ltd_index = index;
3891 spin_lock(&lfsck_instance_lock);
3892 lfsck = __lfsck_instance_find(key, true, false);
3893 if (lfsck == NULL) {
3895 list_add_tail(<d->ltd_orphan_list,
3896 &lfsck_ost_orphan_list);
3898 list_add_tail(<d->ltd_orphan_list,
3899 &lfsck_mdt_orphan_list);
3900 spin_unlock(&lfsck_instance_lock);
3904 spin_unlock(&lfsck_instance_lock);
3906 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, false);
3910 lfsck_instance_put(env, lfsck);
3914 EXPORT_SYMBOL(lfsck_add_target);
3916 void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
3917 struct dt_device *tgt, __u32 index, bool for_ost)
3919 struct lfsck_instance *lfsck;
3920 struct lfsck_tgt_descs *ltds;
3921 struct lfsck_tgt_desc *ltd;
3922 struct list_head *head;
3925 head = &lfsck_ost_orphan_list;
3927 head = &lfsck_mdt_orphan_list;
3929 spin_lock(&lfsck_instance_lock);
3930 list_for_each_entry(ltd, head, ltd_orphan_list) {
3931 if (ltd->ltd_tgt == tgt) {
3932 list_del_init(<d->ltd_orphan_list);
3933 spin_unlock(&lfsck_instance_lock);
3941 lfsck = __lfsck_instance_find(key, true, false);
3942 spin_unlock(&lfsck_instance_lock);
3943 if (unlikely(lfsck == NULL))
3947 ltds = &lfsck->li_ost_descs;
3949 ltds = &lfsck->li_mdt_descs;
3951 down_write(<ds->ltd_rw_sem);
3952 LASSERT(ltds->ltd_tgts_bitmap != NULL);
3954 if (unlikely(index >= ltds->ltd_tgts_bitmap->size))
3957 ltd = lfsck_ltd2tgt(ltds, index);
3958 if (unlikely(ltd == NULL))
3961 LASSERT(ltds->ltd_tgtnr > 0);
3964 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, index);
3965 lfsck_assign_tgt(ltds, NULL, index);
3970 head = &lfsck->li_ost_descs.ltd_orphan;
3972 head = &lfsck->li_mdt_descs.ltd_orphan;
3974 list_for_each_entry(ltd, head, ltd_orphan_list) {
3975 if (ltd->ltd_tgt == tgt) {
3976 list_del_init(<d->ltd_orphan_list);
3982 up_write(<ds->ltd_rw_sem);
3984 spin_lock(<ds->ltd_lock);
3986 spin_unlock(<ds->ltd_lock);
3987 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_NAMESPACE);
3988 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_LAYOUT);
3992 lfsck_instance_put(env, lfsck);
3994 EXPORT_SYMBOL(lfsck_del_target);
3996 static int __init lfsck_init(void)
4000 INIT_LIST_HEAD(&lfsck_instance_list);
4001 INIT_LIST_HEAD(&lfsck_ost_orphan_list);
4002 INIT_LIST_HEAD(&lfsck_mdt_orphan_list);
4003 lfsck_key_init_generic(&lfsck_thread_key, NULL);
4004 rc = lu_context_key_register(&lfsck_thread_key);
4006 tgt_register_lfsck_in_notify_local(lfsck_in_notify_local);
4007 tgt_register_lfsck_in_notify(lfsck_in_notify);
4008 tgt_register_lfsck_query(lfsck_query);
4014 static void __exit lfsck_exit(void)
4016 struct lfsck_tgt_desc *ltd;
4017 struct lfsck_tgt_desc *next;
4019 LASSERT(list_empty(&lfsck_instance_list));
4021 list_for_each_entry_safe(ltd, next, &lfsck_ost_orphan_list,
4023 list_del_init(<d->ltd_orphan_list);
4027 list_for_each_entry_safe(ltd, next, &lfsck_mdt_orphan_list,
4029 list_del_init(<d->ltd_orphan_list);
4033 lu_context_key_degister(&lfsck_thread_key);
4036 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
4037 MODULE_DESCRIPTION("Lustre File System Checker");
4038 MODULE_VERSION(LUSTRE_VERSION_STRING);
4039 MODULE_LICENSE("GPL");
4041 module_init(lfsck_init);
4042 module_exit(lfsck_exit);