4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (c) 2013, 2017, Intel Corporation.
26 * lustre/lfsck/lfsck_lib.c
28 * Author: Fan, Yong <fan.yong@intel.com>
31 #define DEBUG_SUBSYSTEM S_LFSCK
33 #include <linux/kthread.h>
34 #include <linux/sched.h>
35 #include <linux/list.h>
36 #include <linux/delay.h>
37 #include <lu_object.h>
38 #include <dt_object.h>
39 #include <md_object.h>
40 #include <lustre_fld.h>
41 #include <lustre_lib.h>
42 #include <lustre_net.h>
43 #include <lustre_lfsck.h>
45 #include "lfsck_internal.h"
47 #define LFSCK_CHECKPOINT_SKIP 1
49 /* define lfsck thread key */
50 LU_KEY_INIT(lfsck, struct lfsck_thread_info);
52 static void lfsck_key_fini(const struct lu_context *ctx,
53 struct lu_context_key *key, void *data)
55 struct lfsck_thread_info *info = data;
57 lu_buf_free(&info->lti_linkea_buf);
58 lu_buf_free(&info->lti_linkea_buf2);
59 lu_buf_free(&info->lti_big_buf);
63 LU_CONTEXT_KEY_DEFINE(lfsck, LCT_MD_THREAD | LCT_DT_THREAD);
64 LU_KEY_INIT_GENERIC(lfsck);
66 static LIST_HEAD(lfsck_instance_list);
67 static LIST_HEAD(lfsck_ost_orphan_list);
68 static LIST_HEAD(lfsck_mdt_orphan_list);
69 static DEFINE_SPINLOCK(lfsck_instance_lock);
71 const char *const lfsck_flags_names[] = {
80 const char *const lfsck_param_names[] = {
90 "delay_create_ostobj",
94 enum lfsck_verify_lpf_types {
96 LVLT_BY_NAMEENTRY = 1,
100 lfsck_reset_ltd_status(struct lfsck_tgt_desc *ltd, enum lfsck_type type)
102 if (type == LFSCK_TYPE_LAYOUT) {
103 ltd->ltd_layout_status = LS_MAX;
104 ltd->ltd_layout_repaired = 0;
106 ltd->ltd_namespace_status = LS_MAX;
107 ltd->ltd_namespace_repaired = 0;
111 static int lfsck_tgt_descs_init(struct lfsck_tgt_descs *ltds)
113 spin_lock_init(<ds->ltd_lock);
114 init_rwsem(<ds->ltd_rw_sem);
115 INIT_LIST_HEAD(<ds->ltd_orphan);
116 ltds->ltd_tgts_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
117 if (ltds->ltd_tgts_bitmap == NULL)
123 static void lfsck_tgt_descs_fini(struct lfsck_tgt_descs *ltds)
125 struct lfsck_tgt_desc *ltd;
126 struct lfsck_tgt_desc *next;
129 down_write(<ds->ltd_rw_sem);
131 list_for_each_entry_safe(ltd, next, <ds->ltd_orphan,
133 list_del_init(<d->ltd_orphan_list);
137 if (unlikely(ltds->ltd_tgts_bitmap == NULL)) {
138 up_write(<ds->ltd_rw_sem);
143 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
144 ltd = lfsck_ltd2tgt(ltds, idx);
145 if (likely(ltd != NULL)) {
146 LASSERT(list_empty(<d->ltd_layout_list));
147 LASSERT(list_empty(<d->ltd_layout_phase_list));
148 LASSERT(list_empty(<d->ltd_namespace_list));
149 LASSERT(list_empty(<d->ltd_namespace_phase_list));
152 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, idx);
153 lfsck_assign_tgt(ltds, NULL, idx);
158 LASSERTF(ltds->ltd_tgtnr == 0, "tgt count unmatched: %d\n",
161 for (idx = 0; idx < ARRAY_SIZE(ltds->ltd_tgts_idx); idx++) {
162 if (ltds->ltd_tgts_idx[idx] != NULL) {
163 OBD_FREE_PTR(ltds->ltd_tgts_idx[idx]);
164 ltds->ltd_tgts_idx[idx] = NULL;
168 CFS_FREE_BITMAP(ltds->ltd_tgts_bitmap);
169 ltds->ltd_tgts_bitmap = NULL;
170 up_write(<ds->ltd_rw_sem);
173 static int __lfsck_add_target(const struct lu_env *env,
174 struct lfsck_instance *lfsck,
175 struct lfsck_tgt_desc *ltd,
176 bool for_ost, bool locked)
178 struct lfsck_tgt_descs *ltds;
179 __u32 index = ltd->ltd_index;
184 ltds = &lfsck->li_ost_descs;
186 ltds = &lfsck->li_mdt_descs;
189 down_write(<ds->ltd_rw_sem);
191 LASSERT(ltds->ltd_tgts_bitmap != NULL);
193 if (index >= ltds->ltd_tgts_bitmap->size) {
194 __u32 newsize = max((__u32)ltds->ltd_tgts_bitmap->size,
195 (__u32)BITS_PER_LONG);
196 struct cfs_bitmap *old_bitmap = ltds->ltd_tgts_bitmap;
197 struct cfs_bitmap *new_bitmap;
199 while (newsize < index + 1)
202 new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
203 if (new_bitmap == NULL)
204 GOTO(unlock, rc = -ENOMEM);
206 if (ltds->ltd_tgtnr > 0)
207 cfs_bitmap_copy(new_bitmap, old_bitmap);
208 ltds->ltd_tgts_bitmap = new_bitmap;
209 CFS_FREE_BITMAP(old_bitmap);
212 if (cfs_bitmap_check(ltds->ltd_tgts_bitmap, index)) {
213 CERROR("%s: the device %s (%u) is registered already\n",
214 lfsck_lfsck2name(lfsck),
215 ltd->ltd_tgt->dd_lu_dev.ld_obd->obd_name, index);
216 GOTO(unlock, rc = -EEXIST);
219 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
220 OBD_ALLOC_PTR(ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK]);
221 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL)
222 GOTO(unlock, rc = -ENOMEM);
225 lfsck_assign_tgt(ltds, ltd, index);
226 cfs_bitmap_set(ltds->ltd_tgts_bitmap, index);
229 GOTO(unlock, rc = 0);
233 up_write(<ds->ltd_rw_sem);
238 static int lfsck_add_target_from_orphan(const struct lu_env *env,
239 struct lfsck_instance *lfsck)
241 struct lfsck_tgt_descs *ltds = &lfsck->li_ost_descs;
242 struct lfsck_tgt_desc *ltd;
243 struct lfsck_tgt_desc *next;
244 struct list_head *head = &lfsck_ost_orphan_list;
249 spin_lock(&lfsck_instance_lock);
250 list_for_each_entry_safe(ltd, next, head, ltd_orphan_list) {
251 if (ltd->ltd_key == lfsck->li_bottom)
252 list_move_tail(<d->ltd_orphan_list,
255 spin_unlock(&lfsck_instance_lock);
257 down_write(<ds->ltd_rw_sem);
258 while (!list_empty(<ds->ltd_orphan)) {
259 ltd = list_entry(ltds->ltd_orphan.next,
260 struct lfsck_tgt_desc,
262 list_del_init(<d->ltd_orphan_list);
263 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, true);
264 /* Do not hold the semaphore for too long time. */
265 up_write(<ds->ltd_rw_sem);
269 down_write(<ds->ltd_rw_sem);
271 up_write(<ds->ltd_rw_sem);
274 ltds = &lfsck->li_mdt_descs;
275 head = &lfsck_mdt_orphan_list;
283 static inline struct lfsck_component *
284 __lfsck_component_find(struct lfsck_instance *lfsck, __u16 type,
285 struct list_head *list)
287 struct lfsck_component *com;
289 list_for_each_entry(com, list, lc_link) {
290 if (com->lc_type == type)
296 struct lfsck_component *
297 lfsck_component_find(struct lfsck_instance *lfsck, __u16 type)
299 struct lfsck_component *com;
301 spin_lock(&lfsck->li_lock);
302 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
306 com = __lfsck_component_find(lfsck, type,
307 &lfsck->li_list_double_scan);
311 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_idle);
315 lfsck_component_get(com);
316 spin_unlock(&lfsck->li_lock);
320 void lfsck_component_cleanup(const struct lu_env *env,
321 struct lfsck_component *com)
323 if (!list_empty(&com->lc_link))
324 list_del_init(&com->lc_link);
325 if (!list_empty(&com->lc_link_dir))
326 list_del_init(&com->lc_link_dir);
328 lfsck_component_put(env, com);
331 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
332 struct lu_fid *fid, bool locked)
334 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
339 mutex_lock(&lfsck->li_mutex);
341 rc = seq_client_alloc_fid(env, lfsck->li_seq, fid);
343 bk->lb_last_fid = *fid;
344 /* We do not care about whether the subsequent sub-operations
345 * failed or not. The worst case is that one FID is lost that
346 * is not a big issue for the LFSCK since it is relative rare
347 * for LFSCK create. */
348 rc = lfsck_bookmark_store(env, lfsck);
352 mutex_unlock(&lfsck->li_mutex);
357 static int __lfsck_ibits_lock(const struct lu_env *env,
358 struct lfsck_instance *lfsck,
359 struct dt_object *obj, struct ldlm_res_id *resid,
360 struct lustre_handle *lh, __u64 bits,
363 struct lfsck_thread_info *info = lfsck_env_info(env);
364 union ldlm_policy_data *policy = &info->lti_policy;
365 __u64 flags = LDLM_FL_ATOMIC_CB;
368 LASSERT(lfsck->li_namespace != NULL);
370 memset(policy, 0, sizeof(*policy));
371 policy->l_inodebits.bits = bits;
372 if (dt_object_remote(obj)) {
373 struct ldlm_enqueue_info *einfo = &info->lti_einfo;
375 memset(einfo, 0, sizeof(*einfo));
376 einfo->ei_type = LDLM_IBITS;
377 einfo->ei_mode = mode;
378 einfo->ei_cb_bl = ldlm_blocking_ast;
379 einfo->ei_cb_cp = ldlm_completion_ast;
380 einfo->ei_res_id = resid;
381 einfo->ei_req_slot = 1;
383 rc = dt_object_lock(env, obj, lh, einfo, policy);
384 /* for regular checks LFSCK doesn't use LDLM locking,
385 * so the state isn't coherent. here we just took LDLM
386 * lock for coherency and it's time to invalidate
389 dt_invalidate(env, obj);
391 rc = ldlm_cli_enqueue_local(env, lfsck->li_namespace, resid,
392 LDLM_IBITS, policy, mode,
393 &flags, ldlm_blocking_ast,
394 ldlm_completion_ast, NULL, NULL,
395 0, LVB_T_NONE, NULL, lh);
398 if (rc == ELDLM_OK) {
401 memset(lh, 0, sizeof(*lh));
409 * Request the specified ibits lock for the given object.
411 * Before the LFSCK modifying on the namespace visible object,
412 * it needs to acquire related ibits ldlm lock.
414 * \param[in] env pointer to the thread context
415 * \param[in] lfsck pointer to the lfsck instance
416 * \param[in] obj pointer to the dt_object to be locked
417 * \param[out] lh pointer to the lock handle
418 * \param[in] bits the bits for the ldlm lock to be acquired
419 * \param[in] mode the mode for the ldlm lock to be acquired
421 * \retval 0 for success
422 * \retval negative error number on failure
424 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
425 struct dt_object *obj, struct lustre_handle *lh,
426 __u64 bits, enum ldlm_mode mode)
428 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
430 LASSERT(!lustre_handle_is_used(lh));
432 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
433 return __lfsck_ibits_lock(env, lfsck, obj, resid, lh, bits, mode);
437 * Request the remote LOOKUP lock for the given object.
439 * If \a pobj is remote, the LOOKUP lock of \a obj is on the MDT where
440 * \a pobj is, acquire LOOKUP lock there.
442 * \param[in] env pointer to the thread context
443 * \param[in] lfsck pointer to the lfsck instance
444 * \param[in] pobj pointer to parent dt_object
445 * \param[in] obj pointer to the dt_object to be locked
446 * \param[out] lh pointer to the lock handle
447 * \param[in] mode the mode for the ldlm lock to be acquired
449 * \retval 0 for success
450 * \retval negative error number on failure
452 int lfsck_remote_lookup_lock(const struct lu_env *env,
453 struct lfsck_instance *lfsck,
454 struct dt_object *pobj, struct dt_object *obj,
455 struct lustre_handle *lh, enum ldlm_mode mode)
457 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
459 LASSERT(!lustre_handle_is_used(lh));
461 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
462 return __lfsck_ibits_lock(env, lfsck, pobj, resid, lh,
463 MDS_INODELOCK_LOOKUP, mode);
467 * Release the the specified ibits lock.
469 * If the lock has been acquired before, release it
470 * and cleanup the handle. Otherwise, do nothing.
472 * \param[in] lh pointer to the lock handle
473 * \param[in] mode the mode for the ldlm lock to be released
475 void lfsck_ibits_unlock(struct lustre_handle *lh, enum ldlm_mode mode)
477 if (lustre_handle_is_used(lh)) {
478 ldlm_lock_decref(lh, mode);
479 memset(lh, 0, sizeof(*lh));
484 * Request compound ibits locks for the given <obj, name> pairs.
486 * Before the LFSCK modifying on the namespace visible object, it needs to
487 * acquire related ibits ldlm lock. Usually, we can use lfsck_ibits_lock for
488 * the lock purpose. But the simple lfsck_ibits_lock for directory-based
489 * modificationis (such as insert name entry to the directory) may be too
490 * coarse-grained and not efficient.
492 * The lfsck_lock() will request compound ibits locks on the specified
493 * <obj, name> pairs: the PDO (Parallel Directory Operations) ibits (UPDATE)
494 * lock on the directory object, and the regular ibits lock on the name hash.
496 * \param[in] env pointer to the thread context
497 * \param[in] lfsck pointer to the lfsck instance
498 * \param[in] obj pointer to the dt_object to be locked
499 * \param[in] name used for building the PDO lock resource
500 * \param[out] llh pointer to the lfsck_lock_handle
501 * \param[in] bits the bits for the ldlm lock to be acquired
502 * \param[in] mode the mode for the ldlm lock to be acquired
504 * \retval 0 for success
505 * \retval negative error number on failure
507 int lfsck_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
508 struct dt_object *obj, const char *name,
509 struct lfsck_lock_handle *llh, __u64 bits, enum ldlm_mode mode)
511 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
514 LASSERT(S_ISDIR(lfsck_object_type(obj)));
515 LASSERT(name != NULL);
516 LASSERT(name[0] != 0);
517 LASSERT(!lustre_handle_is_used(&llh->llh_pdo_lh));
518 LASSERT(!lustre_handle_is_used(&llh->llh_reg_lh));
522 llh->llh_pdo_mode = LCK_EX;
525 llh->llh_pdo_mode = LCK_CW;
528 llh->llh_pdo_mode = LCK_CR;
531 CDEBUG(D_LFSCK, "%s: unexpected PDO lock mode %u on the obj "
532 DFID"\n", lfsck_lfsck2name(lfsck), mode,
533 PFID(lfsck_dto2fid(obj)));
537 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
538 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_pdo_lh,
539 MDS_INODELOCK_UPDATE, llh->llh_pdo_mode);
543 llh->llh_reg_mode = mode;
544 resid->name[LUSTRE_RES_ID_HSH_OFF] = ll_full_name_hash(NULL, name,
546 LASSERT(resid->name[LUSTRE_RES_ID_HSH_OFF] != 0);
547 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_reg_lh,
548 bits, llh->llh_reg_mode);
550 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
556 * Release the the compound ibits locks.
558 * \param[in] llh pointer to the lfsck_lock_handle to be released
560 void lfsck_unlock(struct lfsck_lock_handle *llh)
562 lfsck_ibits_unlock(&llh->llh_reg_lh, llh->llh_reg_mode);
563 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
566 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
567 struct lfsck_instance *lfsck,
568 const struct lu_fid *fid)
570 struct seq_server_site *ss = lfsck_dev_site(lfsck);
571 struct lu_seq_range *range = &lfsck_env_info(env)->lti_range;
574 if (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE)) {
575 /* "ROOT" is always on the MDT0. */
576 if (lu_fid_eq(fid, &lfsck->li_global_root_fid))
579 return lfsck_dev_idx(lfsck);
582 fld_range_set_mdt(range);
583 rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
585 rc = range->lsr_index;
590 const char dot[] = ".";
591 const char dotdot[] = "..";
592 static const char dotlustre[] = ".lustre";
593 static const char lostfound[] = "lost+found";
596 * Remove the name entry from the .lustre/lost+found directory.
598 * No need to care about the object referenced by the name entry,
599 * either the name entry is invalid or redundant, or the referenced
600 * object has been processed or will be handled by others.
602 * \param[in] env pointer to the thread context
603 * \param[in] lfsck pointer to the lfsck instance
604 * \param[in] name the name for the name entry to be removed
606 * \retval 0 for success
607 * \retval negative error number on failure
609 static int lfsck_lpf_remove_name_entry(const struct lu_env *env,
610 struct lfsck_instance *lfsck,
613 struct dt_object *parent = lfsck->li_lpf_root_obj;
614 struct dt_device *dev = lfsck_obj2dev(parent);
616 struct lfsck_lock_handle *llh = &lfsck_env_info(env)->lti_llh;
620 rc = lfsck_lock(env, lfsck, parent, name, llh,
621 MDS_INODELOCK_UPDATE, LCK_PW);
625 th = lfsck_trans_create(env, dev, lfsck);
627 GOTO(unlock, rc = PTR_ERR(th));
629 rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
633 rc = dt_declare_ref_del(env, parent, th);
637 rc = dt_trans_start_local(env, dev, th);
641 rc = dt_delete(env, parent, (const struct dt_key *)name, th);
645 dt_write_lock(env, parent, 0);
646 rc = dt_ref_del(env, parent, th);
647 dt_write_unlock(env, parent);
652 dt_trans_stop(env, dev, th);
657 CDEBUG(D_LFSCK, "%s: remove name entry "DFID"/%s: rc = %d\n",
658 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(parent)), name, rc);
663 static int lfsck_create_lpf_local(const struct lu_env *env,
664 struct lfsck_instance *lfsck,
665 struct dt_object *child,
667 struct dt_object_format *dof,
670 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
671 struct dt_object *parent = lfsck->li_lpf_root_obj;
672 struct dt_device *dev = lfsck_obj2dev(child);
673 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
674 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
675 const struct lu_fid *cfid = lfsck_dto2fid(child);
676 struct thandle *th = NULL;
677 struct linkea_data ldata = { NULL };
678 struct lu_buf linkea_buf;
679 const struct lu_name *cname;
681 int len = sizeof(struct lfsck_bookmark);
685 cname = lfsck_name_get_const(env, name, strlen(name));
686 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
687 cname, lfsck_dto2fid(parent));
691 th = lfsck_trans_create(env, dev, lfsck);
695 /* 1a. create child */
696 rc = dt_declare_create(env, child, la, NULL, dof, th);
700 if (!dt_try_as_dir(env, child))
701 GOTO(stop, rc = -ENOTDIR);
703 /* 2a. increase child nlink */
704 rc = dt_declare_ref_add(env, child, th);
708 /* 3a. insert dot into child dir */
709 rec->rec_type = S_IFDIR;
711 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
712 (const struct dt_key *)dot, th);
716 /* 4a. insert dotdot into child dir */
717 rec->rec_fid = &LU_LPF_FID;
718 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
719 (const struct dt_key *)dotdot, th);
723 /* 5a. insert linkEA for child */
724 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
725 ldata.ld_leh->leh_len);
726 rc = dt_declare_xattr_set(env, child, &linkea_buf,
727 XATTR_NAME_LINK, 0, th);
731 /* 6a. insert name into parent dir */
732 rec->rec_type = S_IFDIR;
734 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
735 (const struct dt_key *)name, th);
739 /* 7a. increase parent nlink */
740 rc = dt_declare_ref_add(env, parent, th);
744 /* 8a. update bookmark */
745 rc = dt_declare_record_write(env, bk_obj,
746 lfsck_buf_get(env, bk, len), 0, th);
750 rc = dt_trans_start_local(env, dev, th);
754 dt_write_lock(env, child, 0);
755 /* 1b. create child */
756 rc = dt_create(env, child, la, NULL, dof, th);
760 /* 2b. increase child nlink */
761 rc = dt_ref_add(env, child, th);
765 /* 3b. insert dot into child dir */
767 rc = dt_insert(env, child, (const struct dt_rec *)rec,
768 (const struct dt_key *)dot, th);
772 /* 4b. insert dotdot into child dir */
773 rec->rec_fid = &LU_LPF_FID;
774 rc = dt_insert(env, child, (const struct dt_rec *)rec,
775 (const struct dt_key *)dotdot, th);
779 /* 5b. insert linkEA for child. */
780 rc = dt_xattr_set(env, child, &linkea_buf,
781 XATTR_NAME_LINK, 0, th);
782 dt_write_unlock(env, child);
786 /* 6b. insert name into parent dir */
788 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
789 (const struct dt_key *)name, th);
793 dt_write_lock(env, parent, 0);
794 /* 7b. increase parent nlink */
795 rc = dt_ref_add(env, parent, th);
796 dt_write_unlock(env, parent);
800 bk->lb_lpf_fid = *cfid;
801 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
803 /* 8b. update bookmark */
804 rc = dt_record_write(env, bk_obj,
805 lfsck_buf_get(env, bk, len), &pos, th);
810 dt_write_unlock(env, child);
813 dt_trans_stop(env, dev, th);
818 static int lfsck_create_lpf_remote(const struct lu_env *env,
819 struct lfsck_instance *lfsck,
820 struct dt_object *child,
822 struct dt_object_format *dof,
825 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
826 struct dt_object *parent = lfsck->li_lpf_root_obj;
827 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
828 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
829 const struct lu_fid *cfid = lfsck_dto2fid(child);
830 struct thandle *th = NULL;
831 struct linkea_data ldata = { NULL };
832 struct lu_buf linkea_buf;
833 const struct lu_name *cname;
834 struct dt_device *dev;
836 int len = sizeof(struct lfsck_bookmark);
840 cname = lfsck_name_get_const(env, name, strlen(name));
841 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
842 cname, lfsck_dto2fid(parent));
846 /* Create .lustre/lost+found/MDTxxxx. */
848 /* XXX: Currently, cross-MDT create operation needs to create the child
849 * object firstly, then insert name into the parent directory. For
850 * this case, the child object resides on current MDT (local), but
851 * the parent ".lustre/lost+found" may be on remote MDT. It is not
852 * easy to contain all the sub-modifications orderly within single
855 * To avoid more inconsistency, we split the create operation into
858 * 1) create the child and update the lfsck_bookmark::lb_lpf_fid
860 * 2) insert the name "MDTXXXX" in the parent ".lustre/lost+found"
863 * If 1) done, but 2) failed, then go ahead, the LFSCK will try to
864 * repair such inconsistency when LFSCK run next time. */
866 /* Transaction I: locally */
868 dev = lfsck_obj2dev(child);
869 th = lfsck_trans_create(env, dev, lfsck);
873 /* 1a. create child */
874 rc = dt_declare_create(env, child, la, NULL, dof, th);
878 if (!dt_try_as_dir(env, child))
879 GOTO(stop, rc = -ENOTDIR);
881 /* 2a. increase child nlink */
882 rc = dt_declare_ref_add(env, child, th);
886 /* 3a. insert dot into child dir */
887 rec->rec_type = S_IFDIR;
889 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
890 (const struct dt_key *)dot, th);
894 /* 4a. insert dotdot into child dir */
895 rec->rec_fid = &LU_LPF_FID;
896 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
897 (const struct dt_key *)dotdot, th);
901 /* 5a. insert linkEA for child */
902 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
903 ldata.ld_leh->leh_len);
904 rc = dt_declare_xattr_set(env, child, &linkea_buf,
905 XATTR_NAME_LINK, 0, th);
909 /* 6a. update bookmark */
910 rc = dt_declare_record_write(env, bk_obj,
911 lfsck_buf_get(env, bk, len), 0, th);
915 rc = dt_trans_start_local(env, dev, th);
919 dt_write_lock(env, child, 0);
920 /* 1b. create child */
921 rc = dt_create(env, child, la, NULL, dof, th);
925 /* 2b. increase child nlink */
926 rc = dt_ref_add(env, child, th);
930 /* 3b. insert dot into child dir */
931 rec->rec_type = S_IFDIR;
933 rc = dt_insert(env, child, (const struct dt_rec *)rec,
934 (const struct dt_key *)dot, th);
938 /* 4b. insert dotdot into child dir */
939 rec->rec_fid = &LU_LPF_FID;
940 rc = dt_insert(env, child, (const struct dt_rec *)rec,
941 (const struct dt_key *)dotdot, th);
945 /* 5b. insert linkEA for child */
946 rc = dt_xattr_set(env, child, &linkea_buf,
947 XATTR_NAME_LINK, 0, th);
951 bk->lb_lpf_fid = *cfid;
952 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
954 /* 6b. update bookmark */
955 rc = dt_record_write(env, bk_obj,
956 lfsck_buf_get(env, bk, len), &pos, th);
958 dt_write_unlock(env, child);
959 dt_trans_stop(env, dev, th);
963 /* Transaction II: remotely */
965 dev = lfsck_obj2dev(parent);
966 th = lfsck_trans_create(env, dev, lfsck);
971 /* 5a. insert name into parent dir */
973 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
974 (const struct dt_key *)name, th);
978 /* 6a. increase parent nlink */
979 rc = dt_declare_ref_add(env, parent, th);
983 rc = dt_trans_start_local(env, dev, th);
987 /* 5b. insert name into parent dir */
988 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
989 (const struct dt_key *)name, th);
993 dt_write_lock(env, parent, 0);
994 /* 6b. increase parent nlink */
995 rc = dt_ref_add(env, parent, th);
996 dt_write_unlock(env, parent);
1001 dt_write_unlock(env, child);
1003 dt_trans_stop(env, dev, th);
1005 if (rc != 0 && dev == lfsck_obj2dev(parent))
1006 CDEBUG(D_LFSCK, "%s: partially created the object "DFID
1007 "for orphans, but failed to insert the name %s "
1008 "to the .lustre/lost+found/. Such inconsistency "
1009 "will be repaired when LFSCK run next time: rc = %d\n",
1010 lfsck_lfsck2name(lfsck), PFID(cfid), name, rc);
1016 * Create the MDTxxxx directory under /ROOT/.lustre/lost+found/
1018 * The /ROOT/.lustre/lost+found/MDTxxxx/ directory is used for holding
1019 * orphans and other uncertain inconsistent objects found during the
1020 * LFSCK. Such directory will be created by the LFSCK engine on the
1021 * local MDT before the LFSCK scanning.
1023 * \param[in] env pointer to the thread context
1024 * \param[in] lfsck pointer to the lfsck instance
1026 * \retval 0 for success
1027 * \retval negative error number on failure
1029 static int lfsck_create_lpf(const struct lu_env *env,
1030 struct lfsck_instance *lfsck)
1032 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1033 struct lfsck_thread_info *info = lfsck_env_info(env);
1034 struct lu_fid *cfid = &info->lti_fid2;
1035 struct lu_attr *la = &info->lti_la;
1036 struct dt_object_format *dof = &info->lti_dof;
1037 struct dt_object *parent = lfsck->li_lpf_root_obj;
1038 struct dt_object *child = NULL;
1039 struct lfsck_lock_handle *llh = &info->lti_llh;
1041 int node = lfsck_dev_idx(lfsck);
1045 LASSERT(lfsck->li_master);
1046 LASSERT(parent != NULL);
1047 LASSERT(lfsck->li_lpf_obj == NULL);
1049 snprintf(name, 8, "MDT%04x", node);
1050 rc = lfsck_lock(env, lfsck, parent, name, llh,
1051 MDS_INODELOCK_UPDATE, LCK_PW);
1055 if (fid_is_zero(&bk->lb_lpf_fid)) {
1056 /* There is corner case that: in former LFSCK scanning we have
1057 * created the .lustre/lost+found/MDTxxxx but failed to update
1058 * the lfsck_bookmark::lb_lpf_fid successfully. So need lookup
1059 * it from MDT0 firstly. */
1060 rc = dt_lookup_dir(env, parent, name, cfid);
1061 if (rc != 0 && rc != -ENOENT)
1065 bk->lb_lpf_fid = *cfid;
1066 rc = lfsck_bookmark_store(env, lfsck);
1068 rc = lfsck_fid_alloc(env, lfsck, cfid, true);
1073 *cfid = bk->lb_lpf_fid;
1076 child = lfsck_object_find_bottom_new(env, lfsck, cfid);
1078 GOTO(unlock, rc = PTR_ERR(child));
1080 if (dt_object_exists(child) != 0) {
1081 if (unlikely(!dt_try_as_dir(env, child)))
1084 lfsck->li_lpf_obj = child;
1089 memset(la, 0, sizeof(*la));
1090 la->la_atime = la->la_mtime = la->la_ctime = ktime_get_real_seconds();
1091 la->la_mode = S_IFDIR | S_IRWXU;
1092 la->la_valid = LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1093 LA_UID | LA_GID | LA_TYPE;
1094 memset(dof, 0, sizeof(*dof));
1095 dof->dof_type = dt_mode_to_dft(S_IFDIR);
1098 rc = lfsck_create_lpf_local(env, lfsck, child, la, dof, name);
1100 rc = lfsck_create_lpf_remote(env, lfsck, child, la, dof, name);
1102 lfsck->li_lpf_obj = child;
1108 if (rc != 0 && child != NULL && !IS_ERR(child))
1109 lfsck_object_put(env, child);
1115 * Scan .lustre/lost+found for bad name entries and remove them.
1117 * The valid name entry should be "MDTxxxx", the "xxxx" is the MDT device
1118 * index in the system. Any other formatted name is invalid and should be
1121 * \param[in] env pointer to the thread context
1122 * \param[in] lfsck pointer to the lfsck instance
1124 * \retval 0 for success
1125 * \retval negative error number on failure
1127 static int lfsck_scan_lpf_bad_entries(const struct lu_env *env,
1128 struct lfsck_instance *lfsck)
1130 struct dt_object *parent = lfsck->li_lpf_root_obj;
1131 struct lu_dirent *ent =
1132 (struct lu_dirent *)lfsck_env_info(env)->lti_key;
1133 const struct dt_it_ops *iops = &parent->do_index_ops->dio_it;
1138 it = iops->init(env, parent, LUDA_64BITHASH);
1140 RETURN(PTR_ERR(it));
1142 rc = iops->load(env, it, 0);
1144 rc = iops->next(env, it);
1151 rc = iops->rec(env, it, (struct dt_rec *)ent, LUDA_64BITHASH);
1155 ent->lde_namelen = le16_to_cpu(ent->lde_namelen);
1156 if (name_is_dot_or_dotdot(ent->lde_name, ent->lde_namelen))
1159 /* name length must be strlen("MDTxxxx") */
1160 if (ent->lde_namelen != 7)
1163 if (memcmp(ent->lde_name, "MDT", off) != 0)
1166 while (off < 7 && isxdigit(ent->lde_name[off]))
1172 rc = lfsck_lpf_remove_name_entry(env, lfsck,
1179 rc = iops->next(env, it);
1183 iops->fini(env, it);
1185 RETURN(rc > 0 ? 0 : rc);
1188 static int lfsck_update_lpf_entry(const struct lu_env *env,
1189 struct lfsck_instance *lfsck,
1190 struct dt_object *parent,
1191 struct dt_object *child,
1193 enum lfsck_verify_lpf_types type)
1197 if (type == LVLT_BY_BOOKMARK) {
1198 rc = lfsck_update_name_entry(env, lfsck, parent, name,
1199 lfsck_dto2fid(child), S_IFDIR);
1200 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1201 lfsck->li_bookmark_ram.lb_lpf_fid = *lfsck_dto2fid(child);
1202 rc = lfsck_bookmark_store(env, lfsck);
1204 CDEBUG(D_LFSCK, "%s: update LPF fid "DFID
1205 " in the bookmark file: rc = %d\n",
1206 lfsck_lfsck2name(lfsck),
1207 PFID(lfsck_dto2fid(child)), rc);
1214 * Check whether the @child back references the @parent.
1217 * 1) The child's FID is stored in the bookmark file. If the child back
1218 * references the parent (LU_LPF_FID object) via its ".." entry, then
1219 * insert the name (MDTxxxx) to the .lustre/lost+found; otherwise, if
1220 * the child back references another parent2, then:
1221 * 1.1) If the parent2 recognizes the child, then update the bookmark file;
1222 * 1.2) Otherwise, the LFSCK cannot know whether there will be parent3 that
1223 * references the child. So keep them there. As the LFSCK processing,
1224 * the parent3 may be found, then when the LFSCK run next time, the
1225 * inconsistency can be repaired.
1227 * 2) The child's FID is stored in the .lustre/lost+found/ sub-directory name
1228 * entry (MDTxxxx). If the child back references the parent (LU_LPF_FID obj)
1229 * via its ".." entry, then update the bookmark file, otherwise, if the child
1230 * back references another parent2, then:
1231 * 2.1) If the parent2 recognizes the child, then remove the sub-directory
1232 * from .lustre/lost+found/;
1233 * 2.2) Otherwise, if the parent2 does not recognizes the child, trust the
1234 * sub-directory name entry and update the child;
1235 * 2.3) Otherwise, if we do not know whether the parent2 recognizes the child
1236 * or not, then keep them there.
1238 * \param[in] env pointer to the thread context
1239 * \param[in] lfsck pointer to the lfsck instance
1240 * \param[in] child pointer to the lost+found sub-directory object
1241 * \param[in] name the name for lost+found sub-directory object
1242 * \param[out] fid pointer to the buffer to hold the FID of the object
1243 * (called it as parent2) that is referenced via the
1244 * child's dotdot entry; it also can be the FID that
1245 * is referenced by the name entry under the parent2.
1246 * \param[in] type to indicate where the child's FID is stored in
1248 * \retval positive number for uncertain inconsistency
1249 * \retval 0 for success
1250 * \retval negative error number on failure
1252 static int lfsck_verify_lpf_pairs(const struct lu_env *env,
1253 struct lfsck_instance *lfsck,
1254 struct dt_object *child, const char *name,
1256 enum lfsck_verify_lpf_types type)
1258 struct dt_object *parent = lfsck->li_lpf_root_obj;
1259 struct lfsck_thread_info *info = lfsck_env_info(env);
1260 char *name2 = info->lti_key;
1261 struct lu_fid *fid2 = &info->lti_fid3;
1262 struct dt_object *parent2 = NULL;
1263 struct lustre_handle lh = { 0 };
1268 rc = dt_lookup_dir(env, child, dotdot, fid);
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, lfsck, 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_dir(env, parent2, name2, fid);
1354 dt_read_unlock(env, child);
1355 lfsck_ibits_unlock(&lh, LCK_PR);
1356 if (rc != 0 && rc != -ENOENT)
1359 if (rc == -ENOENT || !lu_fid_eq(fid, lfsck_dto2fid(child))) {
1360 if (type == LVLT_BY_BOOKMARK)
1361 GOTO(out_put, rc = 1);
1363 /* Trust the name entry, update the child's dotdot entry. */
1364 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1365 &LU_LPF_FID, S_IFDIR);
1370 if (type == LVLT_BY_BOOKMARK) {
1371 /* Invalid FID record in the bookmark file, reset it. */
1372 fid_zero(&lfsck->li_bookmark_ram.lb_lpf_fid);
1373 rc = lfsck_bookmark_store(env, lfsck);
1375 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1376 " in the bookmark file: rc = %d\n",
1377 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(child)), rc);
1378 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1379 /* The name entry is wrong, remove it. */
1380 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1386 if (parent2 != NULL && !IS_ERR(parent2))
1387 lfsck_object_put(env, parent2);
1394 * Verify the /ROOT/.lustre/lost+found/ directory.
1396 * /ROOT/.lustre/lost+found/ is a special directory to hold the objects that
1397 * the LFSCK does not exactly know how to handle, such as orphans. So before
1398 * the LFSCK scanning the system, the consistency of such directory needs to
1399 * be verified firstly to allow the users to use it during the LFSCK.
1401 * \param[in] env pointer to the thread context
1402 * \param[in] lfsck pointer to the lfsck instance
1404 * \retval positive number for uncertain inconsistency
1405 * \retval 0 for success
1406 * \retval negative error number on failure
1408 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
1410 struct lfsck_thread_info *info = lfsck_env_info(env);
1411 struct lu_fid *pfid = &info->lti_fid;
1412 struct lu_fid *cfid = &info->lti_fid2;
1413 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1414 struct dt_object *parent;
1415 /* child1's FID is in the bookmark file. */
1416 struct dt_object *child1 = NULL;
1417 /* child2's FID is in the name entry MDTxxxx. */
1418 struct dt_object *child2 = NULL;
1419 const struct lu_name *cname;
1421 int node = lfsck_dev_idx(lfsck);
1425 LASSERT(lfsck->li_master);
1427 if (lfsck_is_dryrun(lfsck))
1430 if (lfsck->li_lpf_root_obj != NULL)
1434 parent = lfsck_object_find_by_dev(env, lfsck->li_bottom,
1437 struct lfsck_tgt_desc *ltd;
1439 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
1440 if (unlikely(ltd == NULL))
1443 parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
1449 RETURN(PTR_ERR(parent));
1451 LASSERT(dt_object_exists(parent));
1453 if (unlikely(!dt_try_as_dir(env, parent))) {
1454 lfsck_object_put(env, parent);
1456 GOTO(put, rc = -ENOTDIR);
1459 lfsck->li_lpf_root_obj = parent;
1461 rc = lfsck_scan_lpf_bad_entries(env, lfsck);
1463 CDEBUG(D_LFSCK, "%s: scan .lustre/lost+found/ "
1464 "for bad sub-directories: rc = %d\n",
1465 lfsck_lfsck2name(lfsck), rc);
1469 snprintf(name, 8, "MDT%04x", node);
1470 rc = dt_lookup_dir(env, parent, name, cfid);
1471 if (rc == -ENOENT) {
1479 /* Invalid FID in the name entry, remove the name entry. */
1480 if (!fid_is_norm(cfid)) {
1481 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1488 child2 = lfsck_object_find_bottom(env, lfsck, cfid);
1490 GOTO(put, rc = PTR_ERR(child2));
1492 if (unlikely(!dt_object_exists(child2) ||
1493 dt_object_remote(child2)) ||
1494 !S_ISDIR(lfsck_object_type(child2))) {
1495 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1502 if (unlikely(!dt_try_as_dir(env, child2)))
1503 GOTO(put, rc = -ENOTDIR);
1506 if (fid_is_zero(&bk->lb_lpf_fid))
1509 if (likely(lu_fid_eq(cfid, &bk->lb_lpf_fid))) {
1510 if (lfsck->li_lpf_obj == NULL) {
1511 lu_object_get(&child2->do_lu);
1512 lfsck->li_lpf_obj = child2;
1515 cname = lfsck_name_get_const(env, name, strlen(name));
1516 rc = lfsck_verify_linkea(env, lfsck, child2, cname,
1522 if (unlikely(!fid_is_norm(&bk->lb_lpf_fid))) {
1523 struct lu_fid tfid = bk->lb_lpf_fid;
1525 /* Invalid FID record in the bookmark file, reset it. */
1526 fid_zero(&bk->lb_lpf_fid);
1527 rc = lfsck_bookmark_store(env, lfsck);
1529 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1530 " in the bookmark file: rc = %d\n",
1531 lfsck_lfsck2name(lfsck), PFID(&tfid), rc);
1539 child1 = lfsck_object_find_bottom(env, lfsck, &bk->lb_lpf_fid);
1540 if (IS_ERR(child1)) {
1545 if (unlikely(!dt_object_exists(child1) ||
1546 dt_object_remote(child1)) ||
1547 !S_ISDIR(lfsck_object_type(child1))) {
1548 /* Invalid FID record in the bookmark file, reset it. */
1549 fid_zero(&bk->lb_lpf_fid);
1550 rc = lfsck_bookmark_store(env, lfsck);
1552 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1553 " in the bookmark file: rc = %d\n",
1554 lfsck_lfsck2name(lfsck),
1555 PFID(lfsck_dto2fid(child1)), rc);
1560 lfsck_object_put(env, child1);
1565 if (unlikely(!dt_try_as_dir(env, child1))) {
1566 lfsck_object_put(env, child1);
1572 rc = lfsck_verify_lpf_pairs(env, lfsck, child1, name, pfid,
1574 if (lu_fid_eq(pfid, &LU_LPF_FID))
1579 rc = lfsck_verify_lpf_pairs(env, lfsck, child2, name,
1580 pfid, LVLT_BY_NAMEENTRY);
1585 if (lfsck->li_lpf_obj != NULL) {
1586 if (unlikely(!dt_try_as_dir(env, lfsck->li_lpf_obj))) {
1587 lfsck_object_put(env, lfsck->li_lpf_obj);
1588 lfsck->li_lpf_obj = NULL;
1591 } else if (rc == 0) {
1592 rc = lfsck_create_lpf(env, lfsck);
1595 if (child2 != NULL && !IS_ERR(child2))
1596 lfsck_object_put(env, child2);
1597 if (child1 != NULL && !IS_ERR(child1))
1598 lfsck_object_put(env, child1);
1603 static int lfsck_fid_init(struct lfsck_instance *lfsck)
1605 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1606 struct seq_server_site *ss = lfsck_dev_site(lfsck);
1611 if (unlikely(ss == NULL))
1614 OBD_ALLOC_PTR(lfsck->li_seq);
1615 if (lfsck->li_seq == NULL)
1618 OBD_ALLOC(prefix, MAX_OBD_NAME + 7);
1620 GOTO(out, rc = -ENOMEM);
1622 snprintf(prefix, MAX_OBD_NAME + 7, "lfsck-%s", lfsck_lfsck2name(lfsck));
1623 seq_client_init(lfsck->li_seq, NULL, LUSTRE_SEQ_METADATA, prefix,
1625 OBD_FREE(prefix, MAX_OBD_NAME + 7);
1627 if (fid_is_sane(&bk->lb_last_fid))
1628 lfsck->li_seq->lcs_fid = bk->lb_last_fid;
1633 OBD_FREE_PTR(lfsck->li_seq);
1634 lfsck->li_seq = NULL;
1639 static void lfsck_fid_fini(struct lfsck_instance *lfsck)
1641 if (lfsck->li_seq != NULL) {
1642 seq_client_fini(lfsck->li_seq);
1643 OBD_FREE_PTR(lfsck->li_seq);
1644 lfsck->li_seq = NULL;
1648 void lfsck_instance_cleanup(const struct lu_env *env,
1649 struct lfsck_instance *lfsck)
1651 struct ptlrpc_thread *thread = &lfsck->li_thread;
1652 struct lfsck_component *com;
1653 struct lfsck_component *next;
1654 struct lfsck_lmv_unit *llu;
1655 struct lfsck_lmv_unit *llu_next;
1656 struct lfsck_lmv *llmv;
1659 LASSERT(list_empty(&lfsck->li_link));
1660 LASSERT(thread_is_init(thread) || thread_is_stopped(thread));
1662 if (lfsck->li_obj_oit != NULL) {
1663 lfsck_object_put(env, lfsck->li_obj_oit);
1664 lfsck->li_obj_oit = NULL;
1667 LASSERT(lfsck->li_obj_dir == NULL);
1668 LASSERT(lfsck->li_lmv == NULL);
1670 list_for_each_entry_safe(llu, llu_next, &lfsck->li_list_lmv, llu_link) {
1671 llmv = &llu->llu_lmv;
1673 LASSERTF(atomic_read(&llmv->ll_ref) == 1,
1674 "still in using: %u\n",
1675 atomic_read(&llmv->ll_ref));
1677 lfsck_lmv_put(env, llmv);
1680 list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
1681 lfsck_component_cleanup(env, com);
1684 LASSERT(list_empty(&lfsck->li_list_dir));
1686 list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
1688 lfsck_component_cleanup(env, com);
1691 list_for_each_entry_safe(com, next, &lfsck->li_list_idle, lc_link) {
1692 lfsck_component_cleanup(env, com);
1695 lfsck_tgt_descs_fini(&lfsck->li_ost_descs);
1696 lfsck_tgt_descs_fini(&lfsck->li_mdt_descs);
1698 if (lfsck->li_lfsck_dir != NULL) {
1699 lfsck_object_put(env, lfsck->li_lfsck_dir);
1700 lfsck->li_lfsck_dir = NULL;
1703 if (lfsck->li_bookmark_obj != NULL) {
1704 lfsck_object_put(env, lfsck->li_bookmark_obj);
1705 lfsck->li_bookmark_obj = NULL;
1708 if (lfsck->li_lpf_obj != NULL) {
1709 lfsck_object_put(env, lfsck->li_lpf_obj);
1710 lfsck->li_lpf_obj = NULL;
1713 if (lfsck->li_lpf_root_obj != NULL) {
1714 lfsck_object_put(env, lfsck->li_lpf_root_obj);
1715 lfsck->li_lpf_root_obj = NULL;
1718 if (lfsck->li_los != NULL) {
1719 local_oid_storage_fini(env, lfsck->li_los);
1720 lfsck->li_los = NULL;
1723 lfsck_fid_fini(lfsck);
1725 OBD_FREE_PTR(lfsck);
1728 static inline struct lfsck_instance *
1729 __lfsck_instance_find(struct dt_device *key, bool ref, bool unlink)
1731 struct lfsck_instance *lfsck;
1733 list_for_each_entry(lfsck, &lfsck_instance_list, li_link) {
1734 if (lfsck->li_bottom == key) {
1736 lfsck_instance_get(lfsck);
1738 list_del_init(&lfsck->li_link);
1747 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
1750 struct lfsck_instance *lfsck;
1752 spin_lock(&lfsck_instance_lock);
1753 lfsck = __lfsck_instance_find(key, ref, unlink);
1754 spin_unlock(&lfsck_instance_lock);
1759 static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
1761 struct lfsck_instance *tmp;
1763 spin_lock(&lfsck_instance_lock);
1764 list_for_each_entry(tmp, &lfsck_instance_list, li_link) {
1765 if (lfsck->li_bottom == tmp->li_bottom) {
1766 spin_unlock(&lfsck_instance_lock);
1771 list_add_tail(&lfsck->li_link, &lfsck_instance_list);
1772 spin_unlock(&lfsck_instance_lock);
1776 void lfsck_bits_dump(struct seq_file *m, int bits, const char *const names[],
1781 bool newline = (bits != 0 ? false : true);
1783 seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
1785 for (i = 0, flag = 1; bits != 0; i++, flag = BIT(i)) {
1788 if (names[i] != NULL) {
1792 seq_printf(m, "%s%c", names[i],
1793 newline ? '\n' : ',');
1802 void lfsck_time_dump(struct seq_file *m, time64_t time, const char *name)
1805 seq_printf(m, "%s_time: N/A\n", name);
1806 seq_printf(m, "time_since_%s: N/A\n", name);
1808 seq_printf(m, "%s_time: %lld\n", name, time);
1809 seq_printf(m, "time_since_%s: %lld seconds\n",
1810 name, ktime_get_real_seconds() - time);
1814 void lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
1817 if (fid_is_zero(&pos->lp_dir_parent)) {
1818 if (pos->lp_oit_cookie == 0) {
1819 seq_printf(m, "%s: N/A, N/A, N/A\n", prefix);
1822 seq_printf(m, "%s: %llu, N/A, N/A\n",
1823 prefix, pos->lp_oit_cookie);
1825 seq_printf(m, "%s: %llu, "DFID", %#llx\n",
1826 prefix, pos->lp_oit_cookie,
1827 PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
1831 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
1832 struct lfsck_position *pos, bool init)
1834 const struct dt_it_ops *iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
1836 if (unlikely(lfsck->li_di_oit == NULL)) {
1837 memset(pos, 0, sizeof(*pos));
1841 pos->lp_oit_cookie = iops->store(env, lfsck->li_di_oit);
1842 if (!lfsck->li_current_oit_processed && !init)
1843 pos->lp_oit_cookie--;
1845 if (unlikely(pos->lp_oit_cookie == 0))
1846 pos->lp_oit_cookie = 1;
1848 spin_lock(&lfsck->li_lock);
1849 if (lfsck->li_di_dir != NULL) {
1850 struct dt_object *dto = lfsck->li_obj_dir;
1852 pos->lp_dir_cookie = dto->do_index_ops->dio_it.store(env,
1855 if (pos->lp_dir_cookie >= MDS_DIR_END_OFF) {
1856 fid_zero(&pos->lp_dir_parent);
1857 pos->lp_dir_cookie = 0;
1859 pos->lp_dir_parent = *lfsck_dto2fid(dto);
1862 fid_zero(&pos->lp_dir_parent);
1863 pos->lp_dir_cookie = 0;
1865 spin_unlock(&lfsck->li_lock);
1868 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
1872 if (limit != LFSCK_SPEED_NO_LIMIT) {
1873 if (limit > cfs_time_seconds(1)) {
1874 lfsck->li_sleep_rate = limit / cfs_time_seconds(1);
1875 lfsck->li_sleep_jif = 1;
1877 lfsck->li_sleep_rate = 1;
1878 lfsck->li_sleep_jif = cfs_time_seconds(1) / limit;
1881 lfsck->li_sleep_jif = 0;
1882 lfsck->li_sleep_rate = 0;
1885 if (lfsck->li_bookmark_ram.lb_speed_limit != limit) {
1886 lfsck->li_bookmark_ram.lb_speed_limit = limit;
1893 void lfsck_control_speed(struct lfsck_instance *lfsck)
1895 struct ptlrpc_thread *thread = &lfsck->li_thread;
1897 if (lfsck->li_sleep_jif > 0 &&
1898 lfsck->li_new_scanned >= lfsck->li_sleep_rate) {
1899 wait_event_idle_timeout(thread->t_ctl_waitq,
1900 !thread_is_running(thread),
1901 lfsck->li_sleep_jif);
1902 lfsck->li_new_scanned = 0;
1906 void lfsck_control_speed_by_self(struct lfsck_component *com)
1908 struct lfsck_instance *lfsck = com->lc_lfsck;
1909 struct ptlrpc_thread *thread = &lfsck->li_thread;
1911 if (lfsck->li_sleep_jif > 0 &&
1912 com->lc_new_scanned >= lfsck->li_sleep_rate) {
1913 wait_event_idle_timeout(thread->t_ctl_waitq,
1914 !thread_is_running(thread),
1915 lfsck->li_sleep_jif);
1916 com->lc_new_scanned = 0;
1920 static struct lfsck_thread_args *
1921 lfsck_thread_args_init(struct lfsck_instance *lfsck,
1922 struct lfsck_component *com,
1923 struct lfsck_start_param *lsp)
1925 struct lfsck_thread_args *lta;
1930 return ERR_PTR(-ENOMEM);
1932 rc = lu_env_init(<a->lta_env, LCT_MD_THREAD | LCT_DT_THREAD);
1938 lta->lta_lfsck = lfsck_instance_get(lfsck);
1940 lta->lta_com = lfsck_component_get(com);
1947 void lfsck_thread_args_fini(struct lfsck_thread_args *lta)
1949 if (lta->lta_com != NULL)
1950 lfsck_component_put(<a->lta_env, lta->lta_com);
1951 lfsck_instance_put(<a->lta_env, lta->lta_lfsck);
1952 lu_env_fini(<a->lta_env);
1956 struct lfsck_assistant_data *
1957 lfsck_assistant_data_init(const struct lfsck_assistant_operations *lao,
1960 struct lfsck_assistant_data *lad;
1964 lad->lad_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
1965 if (lad->lad_bitmap == NULL) {
1970 INIT_LIST_HEAD(&lad->lad_req_list);
1971 spin_lock_init(&lad->lad_lock);
1972 INIT_LIST_HEAD(&lad->lad_ost_list);
1973 INIT_LIST_HEAD(&lad->lad_ost_phase1_list);
1974 INIT_LIST_HEAD(&lad->lad_ost_phase2_list);
1975 INIT_LIST_HEAD(&lad->lad_mdt_list);
1976 INIT_LIST_HEAD(&lad->lad_mdt_phase1_list);
1977 INIT_LIST_HEAD(&lad->lad_mdt_phase2_list);
1978 init_waitqueue_head(&lad->lad_thread.t_ctl_waitq);
1980 lad->lad_name = name;
1986 struct lfsck_assistant_object *
1987 lfsck_assistant_object_init(const struct lu_env *env, const struct lu_fid *fid,
1988 const struct lu_attr *attr, __u64 cookie,
1991 struct lfsck_assistant_object *lso;
1995 return ERR_PTR(-ENOMEM);
1997 lso->lso_fid = *fid;
1999 lso->lso_attr = *attr;
2001 atomic_set(&lso->lso_ref, 1);
2002 lso->lso_oit_cookie = cookie;
2004 lso->lso_is_dir = 1;
2010 lfsck_assistant_object_load(const struct lu_env *env,
2011 struct lfsck_instance *lfsck,
2012 struct lfsck_assistant_object *lso)
2014 struct dt_object *obj;
2016 obj = lfsck_object_find_bottom(env, lfsck, &lso->lso_fid);
2020 if (unlikely(!dt_object_exists(obj) || lfsck_is_dead_obj(obj))) {
2022 lfsck_object_put(env, obj);
2024 return ERR_PTR(-ENOENT);
2027 if (lso->lso_is_dir && unlikely(!dt_try_as_dir(env, obj))) {
2028 lfsck_object_put(env, obj);
2030 return ERR_PTR(-ENOTDIR);
2037 * Generic LFSCK asynchronous communication interpretor function.
2038 * The LFSCK RPC reply for both the event notification and status
2039 * querying will be handled here.
2041 * \param[in] env pointer to the thread context
2042 * \param[in] req pointer to the LFSCK request
2043 * \param[in] args pointer to the lfsck_async_interpret_args
2044 * \param[in] rc the result for handling the LFSCK request
2046 * \retval 0 for success
2047 * \retval negative error number on failure
2049 int lfsck_async_interpret_common(const struct lu_env *env,
2050 struct ptlrpc_request *req,
2053 struct lfsck_async_interpret_args *laia = args;
2054 struct lfsck_component *com = laia->laia_com;
2055 struct lfsck_assistant_data *lad = com->lc_data;
2056 struct lfsck_tgt_descs *ltds = laia->laia_ltds;
2057 struct lfsck_tgt_desc *ltd = laia->laia_ltd;
2058 struct lfsck_request *lr = laia->laia_lr;
2060 LASSERT(com->lc_lfsck->li_master);
2062 switch (lr->lr_event) {
2064 if (unlikely(rc == -EINPROGRESS)) {
2065 ltd->ltd_retry_start = 1;
2070 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s "
2072 lfsck_lfsck2name(com->lc_lfsck),
2073 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2074 ltd->ltd_index, lad->lad_name, rc);
2076 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2077 struct lfsck_layout *lo = com->lc_file_ram;
2079 if (lr->lr_flags & LEF_TO_OST)
2080 lfsck_lad_set_bitmap(env, com,
2083 lo->ll_flags |= LF_INCOMPLETE;
2085 struct lfsck_namespace *ns = com->lc_file_ram;
2087 /* If some MDT does not join the namespace
2088 * LFSCK, then we cannot know whether there
2089 * is some name entry on such MDT that with
2090 * the referenced MDT-object on this MDT or
2091 * not. So the namespace LFSCK on this MDT
2092 * cannot handle orphan MDT-objects properly.
2093 * So we mark the LFSCK as LF_INCOMPLETE and
2094 * skip orphan MDT-objects handling. */
2095 ns->ln_flags |= LF_INCOMPLETE;
2100 spin_lock(<ds->ltd_lock);
2101 if (ltd->ltd_dead) {
2102 spin_unlock(<ds->ltd_lock);
2106 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2107 struct list_head *list;
2108 struct list_head *phase_list;
2110 if (ltd->ltd_layout_done) {
2111 spin_unlock(<ds->ltd_lock);
2115 if (lr->lr_flags & LEF_TO_OST) {
2116 list = &lad->lad_ost_list;
2117 phase_list = &lad->lad_ost_phase1_list;
2119 list = &lad->lad_mdt_list;
2120 phase_list = &lad->lad_mdt_phase1_list;
2123 if (list_empty(<d->ltd_layout_list))
2124 list_add_tail(<d->ltd_layout_list, list);
2125 if (list_empty(<d->ltd_layout_phase_list))
2126 list_add_tail(<d->ltd_layout_phase_list,
2129 if (ltd->ltd_namespace_done) {
2130 spin_unlock(<ds->ltd_lock);
2134 if (list_empty(<d->ltd_namespace_list))
2135 list_add_tail(<d->ltd_namespace_list,
2136 &lad->lad_mdt_list);
2137 if (list_empty(<d->ltd_namespace_phase_list))
2138 list_add_tail(<d->ltd_namespace_phase_list,
2139 &lad->lad_mdt_phase1_list);
2141 spin_unlock(<ds->ltd_lock);
2144 case LE_PHASE1_DONE:
2145 case LE_PHASE2_DONE:
2147 if (rc != 0 && rc != -EALREADY)
2148 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s: "
2149 "event = %d, rc = %d\n",
2150 lfsck_lfsck2name(com->lc_lfsck),
2151 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2152 ltd->ltd_index, lad->lad_name, lr->lr_event, rc);
2155 struct lfsck_reply *reply;
2156 struct list_head *list;
2157 struct list_head *phase_list;
2159 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2160 list = <d->ltd_layout_list;
2161 phase_list = <d->ltd_layout_phase_list;
2163 list = <d->ltd_namespace_list;
2164 phase_list = <d->ltd_namespace_phase_list;
2168 if (lr->lr_flags & LEF_QUERY_ALL) {
2169 lfsck_reset_ltd_status(ltd, com->lc_type);
2173 spin_lock(<ds->ltd_lock);
2174 list_del_init(phase_list);
2175 list_del_init(list);
2176 spin_unlock(<ds->ltd_lock);
2180 reply = req_capsule_server_get(&req->rq_pill,
2182 if (reply == NULL) {
2184 CDEBUG(D_LFSCK, "%s: invalid query reply for %s: "
2185 "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck),
2188 if (lr->lr_flags & LEF_QUERY_ALL) {
2189 lfsck_reset_ltd_status(ltd, com->lc_type);
2193 spin_lock(<ds->ltd_lock);
2194 list_del_init(phase_list);
2195 list_del_init(list);
2196 spin_unlock(<ds->ltd_lock);
2200 if (lr->lr_flags & LEF_QUERY_ALL) {
2201 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2202 ltd->ltd_layout_status = reply->lr_status;
2203 ltd->ltd_layout_repaired = reply->lr_repaired;
2205 ltd->ltd_namespace_status = reply->lr_status;
2206 ltd->ltd_namespace_repaired =
2212 switch (reply->lr_status) {
2213 case LS_SCANNING_PHASE1:
2215 case LS_SCANNING_PHASE2:
2216 spin_lock(<ds->ltd_lock);
2217 list_del_init(phase_list);
2218 if (ltd->ltd_dead) {
2219 spin_unlock(<ds->ltd_lock);
2223 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2224 if (ltd->ltd_layout_done) {
2225 spin_unlock(<ds->ltd_lock);
2229 if (lr->lr_flags & LEF_TO_OST)
2230 list_add_tail(phase_list,
2231 &lad->lad_ost_phase2_list);
2233 list_add_tail(phase_list,
2234 &lad->lad_mdt_phase2_list);
2236 if (ltd->ltd_namespace_done) {
2237 spin_unlock(<ds->ltd_lock);
2241 list_add_tail(phase_list,
2242 &lad->lad_mdt_phase2_list);
2244 spin_unlock(<ds->ltd_lock);
2247 spin_lock(<ds->ltd_lock);
2248 list_del_init(phase_list);
2249 list_del_init(list);
2250 spin_unlock(<ds->ltd_lock);
2256 CDEBUG(D_LFSCK, "%s: unexpected event: rc = %d\n",
2257 lfsck_lfsck2name(com->lc_lfsck), lr->lr_event);
2261 if (!laia->laia_shared) {
2263 lfsck_component_put(env, com);
2269 static void lfsck_interpret(const struct lu_env *env,
2270 struct lfsck_instance *lfsck,
2271 struct ptlrpc_request *req, void *args, int result)
2273 struct lfsck_async_interpret_args *laia = args;
2274 struct lfsck_component *com;
2276 LASSERT(laia->laia_com == NULL);
2277 LASSERT(laia->laia_shared);
2279 spin_lock(&lfsck->li_lock);
2280 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
2281 laia->laia_com = com;
2282 lfsck_async_interpret_common(env, req, laia, result);
2285 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
2286 laia->laia_com = com;
2287 lfsck_async_interpret_common(env, req, laia, result);
2289 spin_unlock(&lfsck->li_lock);
2292 static int lfsck_stop_notify(const struct lu_env *env,
2293 struct lfsck_instance *lfsck,
2294 struct lfsck_tgt_descs *ltds,
2295 struct lfsck_tgt_desc *ltd, __u16 type)
2297 struct lfsck_component *com;
2301 LASSERT(lfsck->li_master);
2303 spin_lock(&lfsck->li_lock);
2304 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
2306 com = __lfsck_component_find(lfsck, type,
2307 &lfsck->li_list_double_scan);
2309 lfsck_component_get(com);
2310 spin_unlock(&lfsck->li_lock);
2313 struct lfsck_thread_info *info = lfsck_env_info(env);
2314 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2315 struct lfsck_request *lr = &info->lti_lr;
2316 struct lfsck_assistant_data *lad = com->lc_data;
2317 struct list_head *list;
2318 struct list_head *phase_list;
2319 struct ptlrpc_request_set *set;
2321 set = ptlrpc_prep_set();
2323 lfsck_component_put(env, com);
2328 if (type == LFSCK_TYPE_LAYOUT) {
2329 list = <d->ltd_layout_list;
2330 phase_list = <d->ltd_layout_phase_list;
2332 list = <d->ltd_namespace_list;
2333 phase_list = <d->ltd_namespace_phase_list;
2336 spin_lock(<ds->ltd_lock);
2337 if (list_empty(list)) {
2338 LASSERT(list_empty(phase_list));
2339 spin_unlock(<ds->ltd_lock);
2340 ptlrpc_set_destroy(set);
2345 list_del_init(phase_list);
2346 list_del_init(list);
2347 spin_unlock(<ds->ltd_lock);
2349 memset(lr, 0, sizeof(*lr));
2350 lr->lr_index = lfsck_dev_idx(lfsck);
2351 lr->lr_event = LE_PEER_EXIT;
2352 lr->lr_active = type;
2353 lr->lr_status = LS_CO_PAUSED;
2354 if (ltds == &lfsck->li_ost_descs)
2355 lr->lr_flags = LEF_TO_OST;
2357 memset(laia, 0, sizeof(*laia));
2358 laia->laia_com = com;
2359 laia->laia_ltds = ltds;
2360 atomic_inc(<d->ltd_ref);
2361 laia->laia_ltd = ltd;
2364 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2365 lfsck_async_interpret_common,
2366 laia, LFSCK_NOTIFY);
2368 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for "
2369 "co-stop for %s: rc = %d\n",
2370 lfsck_lfsck2name(lfsck),
2371 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2372 ltd->ltd_index, lad->lad_name, rc);
2375 rc = ptlrpc_set_wait(env, set);
2378 ptlrpc_set_destroy(set);
2379 lfsck_component_put(env, com);
2385 static int lfsck_async_interpret(const struct lu_env *env,
2386 struct ptlrpc_request *req,
2389 struct lfsck_async_interpret_args *laia = args;
2390 struct lfsck_instance *lfsck;
2392 lfsck = container_of(laia->laia_ltds, struct lfsck_instance,
2394 lfsck_interpret(env, lfsck, req, laia, rc);
2395 lfsck_tgt_put(laia->laia_ltd);
2396 if (rc != 0 && laia->laia_result != -EALREADY)
2397 laia->laia_result = rc;
2402 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
2403 struct lfsck_request *lr,
2404 struct ptlrpc_request_set *set,
2405 ptlrpc_interpterer_t interpreter,
2406 void *args, int request)
2408 struct lfsck_async_interpret_args *laia;
2409 struct ptlrpc_request *req;
2410 struct lfsck_request *tmp;
2411 struct req_format *format;
2416 format = &RQF_LFSCK_NOTIFY;
2419 format = &RQF_LFSCK_QUERY;
2422 CDEBUG(D_LFSCK, "%s: unknown async request %d: rc = %d\n",
2423 exp->exp_obd->obd_name, request, -EINVAL);
2427 req = ptlrpc_request_alloc(class_exp2cliimp(exp), format);
2431 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, request);
2433 ptlrpc_request_free(req);
2438 tmp = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
2440 ptlrpc_request_set_replen(req);
2442 laia = ptlrpc_req_async_args(laia, req);
2443 *laia = *(struct lfsck_async_interpret_args *)args;
2444 if (laia->laia_com != NULL)
2445 lfsck_component_get(laia->laia_com);
2446 req->rq_interpret_reply = interpreter;
2447 req->rq_allow_intr = 1;
2448 req->rq_no_delay = 1;
2449 ptlrpc_set_add_req(set, req);
2454 int lfsck_query_all(const struct lu_env *env, struct lfsck_component *com)
2456 struct lfsck_thread_info *info = lfsck_env_info(env);
2457 struct lfsck_request *lr = &info->lti_lr;
2458 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2459 struct lfsck_instance *lfsck = com->lc_lfsck;
2460 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2461 struct lfsck_tgt_desc *ltd;
2462 struct ptlrpc_request_set *set;
2467 memset(lr, 0, sizeof(*lr));
2468 lr->lr_event = LE_QUERY;
2469 lr->lr_active = com->lc_type;
2470 lr->lr_flags = LEF_QUERY_ALL;
2472 memset(laia, 0, sizeof(*laia));
2473 laia->laia_com = com;
2476 set = ptlrpc_prep_set();
2481 laia->laia_ltds = ltds;
2482 down_read(<ds->ltd_rw_sem);
2483 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2484 ltd = lfsck_tgt_get(ltds, idx);
2485 LASSERT(ltd != NULL);
2487 laia->laia_ltd = ltd;
2488 up_read(<ds->ltd_rw_sem);
2489 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2490 lfsck_async_interpret_common,
2493 struct lfsck_assistant_data *lad = com->lc_data;
2495 CDEBUG(D_LFSCK, "%s: Fail to query %s %x for stat %s: "
2496 "rc = %d\n", lfsck_lfsck2name(lfsck),
2497 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2498 ltd->ltd_index, lad->lad_name, rc);
2499 lfsck_reset_ltd_status(ltd, com->lc_type);
2502 down_read(<ds->ltd_rw_sem);
2504 up_read(<ds->ltd_rw_sem);
2506 if (com->lc_type == LFSCK_TYPE_LAYOUT && !(lr->lr_flags & LEF_TO_OST)) {
2507 ltds = &lfsck->li_ost_descs;
2508 lr->lr_flags |= LEF_TO_OST;
2512 rc = ptlrpc_set_wait(env, set);
2513 ptlrpc_set_destroy(set);
2518 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
2519 struct lfsck_start_param *lsp)
2521 struct lfsck_instance *lfsck = com->lc_lfsck;
2522 struct lfsck_assistant_data *lad = com->lc_data;
2523 struct ptlrpc_thread *mthread = &lfsck->li_thread;
2524 struct ptlrpc_thread *athread = &lad->lad_thread;
2525 struct lfsck_thread_args *lta;
2526 struct task_struct *task;
2530 lad->lad_assistant_status = 0;
2531 lad->lad_post_result = 0;
2533 lad->lad_advance_lock = false;
2534 thread_set_flags(athread, 0);
2536 lta = lfsck_thread_args_init(lfsck, com, lsp);
2538 RETURN(PTR_ERR(lta));
2540 task = kthread_run(lfsck_assistant_engine, lta, lad->lad_name);
2543 CERROR("%s: cannot start LFSCK assistant thread for %s: "
2544 "rc = %d\n", lfsck_lfsck2name(lfsck), lad->lad_name, rc);
2545 lfsck_thread_args_fini(lta);
2547 wait_event_idle(mthread->t_ctl_waitq,
2548 thread_is_running(athread) ||
2549 thread_is_stopped(athread) ||
2550 !thread_is_starting(mthread));
2551 if (unlikely(!thread_is_starting(mthread)))
2552 /* stopped by race */
2554 else if (unlikely(!thread_is_running(athread)))
2555 rc = lad->lad_assistant_status;
2563 int lfsck_checkpoint_generic(const struct lu_env *env,
2564 struct lfsck_component *com)
2566 struct lfsck_assistant_data *lad = com->lc_data;
2567 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2568 struct ptlrpc_thread *athread = &lad->lad_thread;
2570 wait_event_idle(mthread->t_ctl_waitq,
2571 list_empty(&lad->lad_req_list) ||
2572 !thread_is_running(mthread) ||
2573 thread_is_stopped(athread));
2575 if (!thread_is_running(mthread) || thread_is_stopped(athread))
2576 return LFSCK_CHECKPOINT_SKIP;
2581 void lfsck_post_generic(const struct lu_env *env,
2582 struct lfsck_component *com, int *result)
2584 struct lfsck_assistant_data *lad = com->lc_data;
2585 struct ptlrpc_thread *athread = &lad->lad_thread;
2586 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2588 lad->lad_post_result = *result;
2590 set_bit(LAD_EXIT, &lad->lad_flags);
2591 set_bit(LAD_TO_POST, &lad->lad_flags);
2593 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s post, rc = %d\n",
2594 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2596 wake_up(&athread->t_ctl_waitq);
2597 wait_event_idle(mthread->t_ctl_waitq,
2598 (*result > 0 && list_empty(&lad->lad_req_list)) ||
2599 thread_is_stopped(athread));
2601 if (lad->lad_assistant_status < 0)
2602 *result = lad->lad_assistant_status;
2604 CDEBUG(D_LFSCK, "%s: the assistant has done %s post, rc = %d\n",
2605 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2608 int lfsck_double_scan_generic(const struct lu_env *env,
2609 struct lfsck_component *com, int status)
2611 struct lfsck_assistant_data *lad = com->lc_data;
2612 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2613 struct ptlrpc_thread *athread = &lad->lad_thread;
2615 if (status != LS_SCANNING_PHASE2)
2616 set_bit(LAD_EXIT, &lad->lad_flags);
2618 set_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags);
2620 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s double_scan, "
2622 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, status);
2624 wake_up(&athread->t_ctl_waitq);
2625 wait_event_idle(mthread->t_ctl_waitq,
2626 test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags) ||
2627 thread_is_stopped(athread));
2629 CDEBUG(D_LFSCK, "%s: the assistant has done %s double_scan, "
2630 "status %d\n", lfsck_lfsck2name(com->lc_lfsck), lad->lad_name,
2631 lad->lad_assistant_status);
2633 if (lad->lad_assistant_status < 0)
2634 return lad->lad_assistant_status;
2639 void lfsck_quit_generic(const struct lu_env *env,
2640 struct lfsck_component *com)
2642 struct lfsck_assistant_data *lad = com->lc_data;
2643 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2644 struct ptlrpc_thread *athread = &lad->lad_thread;
2646 set_bit(LAD_EXIT, &lad->lad_flags);
2647 wake_up(&athread->t_ctl_waitq);
2648 wait_event_idle(mthread->t_ctl_waitq,
2649 thread_is_init(athread) ||
2650 thread_is_stopped(athread));
2653 int lfsck_load_one_trace_file(const struct lu_env *env,
2654 struct lfsck_component *com,
2655 struct dt_object *parent,
2656 struct dt_object **child,
2657 const struct dt_index_features *ft,
2658 const char *name, bool reset)
2660 struct lfsck_instance *lfsck = com->lc_lfsck;
2661 struct dt_object *obj;
2665 if (*child != NULL) {
2667 const struct dt_it_ops *iops;
2668 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid3;
2674 rc = obj->do_ops->do_index_try(env, obj, ft);
2676 /* unlink by force */
2679 iops = &obj->do_index_ops->dio_it;
2680 it = iops->init(env, obj, 0);
2682 /* unlink by force */
2686 rc = iops->get(env, it, (const struct dt_key *)fid);
2688 rc = iops->next(env, it);
2691 iops->fini(env, it);
2693 /* "rc > 0" means the index file is empty. */
2697 /* The old index is not empty, remove it firstly. */
2698 rc = local_object_unlink(env, lfsck->li_bottom, parent, name);
2699 CDEBUG_LIMIT(rc ? D_ERROR : D_LFSCK,
2700 "%s: unlink lfsck sub trace file %s: rc = %d\n",
2701 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2706 lfsck_object_put(env, *child);
2713 obj = local_index_find_or_create(env, lfsck->li_los, parent, name,
2714 S_IFREG | S_IRUGO | S_IWUSR, ft);
2716 RETURN(PTR_ERR(obj));
2718 rc = obj->do_ops->do_index_try(env, obj, ft);
2720 lfsck_object_put(env, obj);
2721 CDEBUG(D_LFSCK, "%s: LFSCK fail to load "
2722 "sub trace file %s: rc = %d\n",
2723 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2731 int lfsck_load_sub_trace_files(const struct lu_env *env,
2732 struct lfsck_component *com,
2733 const struct dt_index_features *ft,
2734 const char *prefix, bool reset)
2736 char *name = lfsck_env_info(env)->lti_key;
2737 struct lfsck_sub_trace_obj *lsto;
2741 for (i = 0, rc = 0, lsto = &com->lc_sub_trace_objs[0];
2742 i < LFSCK_STF_COUNT && rc == 0; i++, lsto++) {
2743 snprintf(name, NAME_MAX, "%s_%02d", prefix, i);
2744 rc = lfsck_load_one_trace_file(env, com,
2745 com->lc_lfsck->li_lfsck_dir,
2746 &lsto->lsto_obj, ft, name, reset);
2752 /* external interfaces */
2753 int lfsck_get_speed(char *buf, struct dt_device *key)
2756 struct lfsck_instance *lfsck;
2760 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2764 lfsck = lfsck_instance_find(key, true, false);
2766 rc = sprintf(buf, "%u\n",
2767 lfsck->li_bookmark_ram.lb_speed_limit);
2768 lfsck_instance_put(&env, lfsck);
2777 EXPORT_SYMBOL(lfsck_get_speed);
2779 int lfsck_set_speed(struct dt_device *key, __u32 val)
2782 struct lfsck_instance *lfsck;
2786 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2790 lfsck = lfsck_instance_find(key, true, false);
2791 if (likely(lfsck != NULL)) {
2792 mutex_lock(&lfsck->li_mutex);
2793 if (__lfsck_set_speed(lfsck, val))
2794 rc = lfsck_bookmark_store(&env, lfsck);
2795 mutex_unlock(&lfsck->li_mutex);
2796 lfsck_instance_put(&env, lfsck);
2805 EXPORT_SYMBOL(lfsck_set_speed);
2807 int lfsck_get_windows(char *buf, struct dt_device *key)
2810 struct lfsck_instance *lfsck;
2814 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2818 lfsck = lfsck_instance_find(key, true, false);
2819 if (likely(lfsck != NULL)) {
2820 rc = sprintf(buf, "%u\n",
2821 lfsck->li_bookmark_ram.lb_async_windows);
2822 lfsck_instance_put(&env, lfsck);
2831 EXPORT_SYMBOL(lfsck_get_windows);
2833 int lfsck_set_windows(struct dt_device *key, unsigned int val)
2836 struct lfsck_instance *lfsck;
2840 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2844 lfsck = lfsck_instance_find(key, true, false);
2845 if (likely(lfsck != NULL)) {
2846 if (val < 1 || val > LFSCK_ASYNC_WIN_MAX) {
2847 CWARN("%s: invalid async windows size that may "
2848 "cause memory issues. The valid range is "
2850 lfsck_lfsck2name(lfsck), LFSCK_ASYNC_WIN_MAX);
2852 } else if (lfsck->li_bookmark_ram.lb_async_windows != val) {
2853 mutex_lock(&lfsck->li_mutex);
2854 lfsck->li_bookmark_ram.lb_async_windows = val;
2855 rc = lfsck_bookmark_store(&env, lfsck);
2856 mutex_unlock(&lfsck->li_mutex);
2858 lfsck_instance_put(&env, lfsck);
2867 EXPORT_SYMBOL(lfsck_set_windows);
2869 int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
2872 struct lfsck_instance *lfsck;
2873 struct lfsck_component *com;
2877 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2881 lfsck = lfsck_instance_find(key, true, false);
2882 if (likely(lfsck != NULL)) {
2883 com = lfsck_component_find(lfsck, type);
2884 if (likely(com != NULL)) {
2885 com->lc_ops->lfsck_dump(&env, com, m);
2886 lfsck_component_put(&env, com);
2891 lfsck_instance_put(&env, lfsck);
2900 EXPORT_SYMBOL(lfsck_dump);
2902 static int lfsck_stop_all(const struct lu_env *env,
2903 struct lfsck_instance *lfsck,
2904 struct lfsck_stop *stop)
2906 struct lfsck_thread_info *info = lfsck_env_info(env);
2907 struct lfsck_request *lr = &info->lti_lr;
2908 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2909 struct ptlrpc_request_set *set;
2910 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2911 struct lfsck_tgt_desc *ltd;
2912 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2918 LASSERT(stop->ls_flags & LPF_BROADCAST);
2920 set = ptlrpc_prep_set();
2921 if (unlikely(set == NULL))
2924 memset(lr, 0, sizeof(*lr));
2925 lr->lr_event = LE_STOP;
2926 lr->lr_index = lfsck_dev_idx(lfsck);
2927 lr->lr_status = stop->ls_status;
2928 lr->lr_version = bk->lb_version;
2929 lr->lr_active = LFSCK_TYPES_ALL;
2930 lr->lr_param = stop->ls_flags;
2932 memset(laia, 0, sizeof(*laia));
2933 laia->laia_ltds = ltds;
2935 laia->laia_shared = 1;
2937 down_read(<ds->ltd_rw_sem);
2938 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2939 ltd = lfsck_tgt_get(ltds, idx);
2940 LASSERT(ltd != NULL);
2942 laia->laia_ltd = ltd;
2943 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2944 lfsck_async_interpret, laia,
2947 lfsck_interpret(env, lfsck, NULL, laia, rc);
2949 CERROR("%s: cannot notify MDT %x for LFSCK stop: "
2950 "rc = %d\n", lfsck_lfsck2name(lfsck), idx, rc);
2954 up_read(<ds->ltd_rw_sem);
2956 rc = ptlrpc_set_wait(env, set);
2957 ptlrpc_set_destroy(set);
2960 rc = laia->laia_result;
2962 if (rc == -EALREADY)
2966 CERROR("%s: fail to stop LFSCK on some MDTs: rc = %d\n",
2967 lfsck_lfsck2name(lfsck), rc);
2969 RETURN(rc != 0 ? rc : rc1);
2972 static int lfsck_start_all(const struct lu_env *env,
2973 struct lfsck_instance *lfsck,
2974 struct lfsck_start *start)
2976 struct lfsck_thread_info *info = lfsck_env_info(env);
2977 struct lfsck_request *lr = &info->lti_lr;
2978 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2979 struct ptlrpc_request_set *set;
2980 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2981 struct lfsck_tgt_desc *ltd;
2982 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2988 LASSERT(start->ls_flags & LPF_BROADCAST);
2990 memset(lr, 0, sizeof(*lr));
2991 lr->lr_event = LE_START;
2992 lr->lr_index = lfsck_dev_idx(lfsck);
2993 lr->lr_speed = bk->lb_speed_limit;
2994 lr->lr_version = bk->lb_version;
2995 lr->lr_active = start->ls_active;
2996 lr->lr_param = start->ls_flags;
2997 lr->lr_async_windows = bk->lb_async_windows;
2998 lr->lr_valid = LSV_SPEED_LIMIT | LSV_ERROR_HANDLE | LSV_DRYRUN |
2999 LSV_ASYNC_WINDOWS | LSV_CREATE_OSTOBJ |
3002 memset(laia, 0, sizeof(*laia));
3003 laia->laia_ltds = ltds;
3005 laia->laia_shared = 1;
3008 set = ptlrpc_prep_set();
3012 down_read(<ds->ltd_rw_sem);
3013 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3014 ltd = lfsck_tgt_get(ltds, idx);
3015 LASSERT(ltd != NULL);
3017 if (retry && !ltd->ltd_retry_start) {
3022 laia->laia_ltd = ltd;
3023 ltd->ltd_retry_start = 0;
3024 ltd->ltd_layout_done = 0;
3025 ltd->ltd_namespace_done = 0;
3026 ltd->ltd_synced_failures = 0;
3027 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
3028 lfsck_async_interpret, laia,
3031 lfsck_interpret(env, lfsck, NULL, laia, rc);
3033 CERROR("%s: cannot notify MDT %x for LFSCK "
3034 "start, failout: rc = %d\n",
3035 lfsck_lfsck2name(lfsck), idx, rc);
3039 up_read(<ds->ltd_rw_sem);
3042 ptlrpc_set_destroy(set);
3047 rc = ptlrpc_set_wait(env, set);
3048 ptlrpc_set_destroy(set);
3051 rc = laia->laia_result;
3053 if (unlikely(rc == -EINPROGRESS)) {
3055 schedule_timeout_interruptible(cfs_time_seconds(1));
3056 set_current_state(TASK_RUNNING);
3057 if (!signal_pending(current) &&
3058 thread_is_running(&lfsck->li_thread))
3065 struct lfsck_stop *stop = &info->lti_stop;
3067 CERROR("%s: cannot start LFSCK on some MDTs, "
3068 "stop all: rc = %d\n",
3069 lfsck_lfsck2name(lfsck), rc);
3070 if (rc != -EALREADY) {
3071 stop->ls_status = LS_FAILED;
3072 stop->ls_flags = LPF_ALL_TGT | LPF_BROADCAST;
3073 lfsck_stop_all(env, lfsck, stop);
3080 int lfsck_start(const struct lu_env *env, struct dt_device *key,
3081 struct lfsck_start_param *lsp)
3083 struct lfsck_start *start = lsp->lsp_start;
3084 struct lfsck_instance *lfsck;
3085 struct lfsck_bookmark *bk;
3086 struct ptlrpc_thread *thread;
3087 struct lfsck_component *com;
3088 struct lfsck_thread_args *lta;
3089 struct task_struct *task;
3090 struct lfsck_tgt_descs *ltds;
3091 struct lfsck_tgt_desc *ltd;
3102 lfsck = lfsck_instance_find(key, true, false);
3103 if (unlikely(lfsck == NULL))
3106 if (unlikely(lfsck->li_stopping))
3107 GOTO(put, rc = -ENXIO);
3109 /* System is not ready, try again later. */
3110 if (unlikely(lfsck->li_namespace == NULL ||
3111 lfsck_dev_site(lfsck)->ss_server_fld == NULL))
3112 GOTO(put, rc = -EINPROGRESS);
3114 /* start == NULL means auto trigger paused LFSCK. */
3116 if (list_empty(&lfsck->li_list_scan) ||
3117 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AUTO))
3119 } else if (start->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3120 CERROR("%s: only allow to specify '-A | -o' via MDS\n",
3121 lfsck_lfsck2name(lfsck));
3123 GOTO(put, rc = -EPERM);
3126 bk = &lfsck->li_bookmark_ram;
3127 thread = &lfsck->li_thread;
3128 mutex_lock(&lfsck->li_mutex);
3129 spin_lock(&lfsck->li_lock);
3130 if (unlikely(thread_is_stopping(thread))) {
3131 /* Someone is stopping the LFSCK. */
3132 spin_unlock(&lfsck->li_lock);
3133 GOTO(out, rc = -EBUSY);
3136 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
3138 if (unlikely(start == NULL)) {
3139 spin_unlock(&lfsck->li_lock);
3143 while (start->ls_active != 0) {
3144 if (!(type & start->ls_active)) {
3149 com = __lfsck_component_find(lfsck, type,
3150 &lfsck->li_list_scan);
3152 com = __lfsck_component_find(lfsck, type,
3153 &lfsck->li_list_double_scan);
3159 if (com->lc_ops->lfsck_join != NULL) {
3160 rc = com->lc_ops->lfsck_join( env, com, lsp);
3161 if (rc != 0 && rc != -EALREADY)
3164 start->ls_active &= ~type;
3167 spin_unlock(&lfsck->li_lock);
3170 spin_unlock(&lfsck->li_lock);
3172 lfsck->li_status = 0;
3173 lfsck->li_oit_over = 0;
3174 lfsck->li_start_unplug = 0;
3175 lfsck->li_drop_dryrun = 0;
3176 lfsck->li_new_scanned = 0;
3178 /* For auto trigger. */
3182 start->ls_version = bk->lb_version;
3184 if (start->ls_active != 0) {
3185 struct lfsck_component *next;
3187 if (start->ls_active == LFSCK_TYPES_ALL)
3188 start->ls_active = LFSCK_TYPES_SUPPORTED;
3190 if (start->ls_active & ~LFSCK_TYPES_SUPPORTED) {
3191 start->ls_active &= ~LFSCK_TYPES_SUPPORTED;
3192 GOTO(out, rc = -ENOTSUPP);
3195 list_for_each_entry_safe(com, next,
3196 &lfsck->li_list_scan, lc_link) {
3197 if (!(com->lc_type & start->ls_active)) {
3198 rc = com->lc_ops->lfsck_post(env, com, 0,
3205 while (start->ls_active != 0) {
3206 if (type & start->ls_active) {
3207 com = __lfsck_component_find(lfsck, type,
3208 &lfsck->li_list_idle);
3210 /* The component status will be updated
3211 * when its prep() is called later by
3212 * the LFSCK main engine. */
3213 list_move_tail(&com->lc_link,
3214 &lfsck->li_list_scan);
3215 start->ls_active &= ~type;
3221 if (list_empty(&lfsck->li_list_scan)) {
3222 /* The speed limit will be used to control both the LFSCK and
3223 * low layer scrub (if applied), need to be handled firstly. */
3224 if (start->ls_valid & LSV_SPEED_LIMIT) {
3225 if (__lfsck_set_speed(lfsck, start->ls_speed_limit)) {
3226 rc = lfsck_bookmark_store(env, lfsck);
3235 if (start->ls_flags & LPF_RESET)
3236 flags |= DOIF_RESET;
3238 rc = lfsck_set_param(env, lfsck, start, !!(flags & DOIF_RESET));
3242 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3243 start->ls_active |= com->lc_type;
3244 if (flags & DOIF_RESET) {
3245 rc = com->lc_ops->lfsck_reset(env, com, false);
3251 ltds = &lfsck->li_mdt_descs;
3252 down_read(<ds->ltd_rw_sem);
3253 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3254 ltd = lfsck_ltd2tgt(ltds, idx);
3255 LASSERT(ltd != NULL);
3257 ltd->ltd_layout_done = 0;
3258 ltd->ltd_namespace_done = 0;
3259 ltd->ltd_synced_failures = 0;
3260 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_NAMESPACE);
3261 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3262 list_del_init(<d->ltd_layout_phase_list);
3263 list_del_init(<d->ltd_layout_list);
3264 list_del_init(<d->ltd_namespace_phase_list);
3265 list_del_init(<d->ltd_namespace_list);
3267 up_read(<ds->ltd_rw_sem);
3269 ltds = &lfsck->li_ost_descs;
3270 down_read(<ds->ltd_rw_sem);
3271 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3272 ltd = lfsck_ltd2tgt(ltds, idx);
3273 LASSERT(ltd != NULL);
3275 ltd->ltd_layout_done = 0;
3276 ltd->ltd_synced_failures = 0;
3277 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3278 list_del_init(<d->ltd_layout_phase_list);
3279 list_del_init(<d->ltd_layout_list);
3281 up_read(<ds->ltd_rw_sem);
3284 lfsck->li_args_dir = LUDA_64BITHASH | LUDA_VERIFY | LUDA_TYPE;
3285 if (bk->lb_param & LPF_DRYRUN)
3286 lfsck->li_args_dir |= LUDA_VERIFY_DRYRUN;
3288 if (start != NULL && start->ls_valid & LSV_ERROR_HANDLE) {
3289 valid |= DOIV_ERROR_HANDLE;
3290 if (start->ls_flags & LPF_FAILOUT)
3291 flags |= DOIF_FAILOUT;
3294 if (start != NULL && start->ls_valid & LSV_DRYRUN) {
3295 valid |= DOIV_DRYRUN;
3296 if (start->ls_flags & LPF_DRYRUN)
3297 flags |= DOIF_DRYRUN;
3300 if (!list_empty(&lfsck->li_list_scan))
3301 flags |= DOIF_OUTUSED;
3303 lfsck->li_args_oit = (flags << DT_OTABLE_IT_FLAGS_SHIFT) | valid;
3304 lta = lfsck_thread_args_init(lfsck, NULL, lsp);
3306 GOTO(out, rc = PTR_ERR(lta));
3308 __lfsck_set_speed(lfsck, bk->lb_speed_limit);
3309 spin_lock(&lfsck->li_lock);
3310 thread_set_flags(thread, SVC_STARTING);
3311 spin_unlock(&lfsck->li_lock);
3312 task = kthread_run(lfsck_master_engine, lta, "lfsck");
3315 CERROR("%s: cannot start LFSCK thread: rc = %d\n",
3316 lfsck_lfsck2name(lfsck), rc);
3317 lfsck_thread_args_fini(lta);
3322 wait_event_idle(thread->t_ctl_waitq,
3323 thread_is_running(thread) ||
3324 thread_is_stopped(thread));
3325 if (start == NULL || !(start->ls_flags & LPF_BROADCAST)) {
3326 lfsck->li_start_unplug = 1;
3327 wake_up(&thread->t_ctl_waitq);
3332 /* release lfsck::li_mutex to avoid deadlock. */
3333 mutex_unlock(&lfsck->li_mutex);
3334 rc = lfsck_start_all(env, lfsck, start);
3336 spin_lock(&lfsck->li_lock);
3337 if (thread_is_stopped(thread)) {
3338 spin_unlock(&lfsck->li_lock);
3340 lfsck->li_status = LS_FAILED;
3341 lfsck->li_flags = 0;
3342 thread_set_flags(thread, SVC_STOPPING);
3343 spin_unlock(&lfsck->li_lock);
3345 lfsck->li_start_unplug = 1;
3346 wake_up(&thread->t_ctl_waitq);
3347 wait_event_idle(thread->t_ctl_waitq,
3348 thread_is_stopped(thread));
3351 lfsck->li_start_unplug = 1;
3352 wake_up(&thread->t_ctl_waitq);
3358 mutex_unlock(&lfsck->li_mutex);
3361 lfsck_instance_put(env, lfsck);
3363 return rc < 0 ? rc : 0;
3365 EXPORT_SYMBOL(lfsck_start);
3367 int lfsck_stop(const struct lu_env *env, struct dt_device *key,
3368 struct lfsck_stop *stop)
3370 struct lfsck_instance *lfsck;
3371 struct ptlrpc_thread *thread;
3376 lfsck = lfsck_instance_find(key, true, false);
3377 if (unlikely(lfsck == NULL))
3380 thread = &lfsck->li_thread;
3381 if (stop && stop->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3382 CERROR("%s: only allow to specify '-A' via MDS\n",
3383 lfsck_lfsck2name(lfsck));
3384 GOTO(put, rc = -EPERM);
3387 spin_lock(&lfsck->li_lock);
3388 /* The target is umounted */
3389 if (stop && stop->ls_status == LS_PAUSED)
3390 lfsck->li_stopping = 1;
3392 if (thread_is_init(thread) || thread_is_stopped(thread))
3393 /* no error if LFSCK stopped already, or not started */
3394 GOTO(unlock, rc = 0);
3396 if (thread_is_stopping(thread))
3397 /* Someone is stopping LFSCK. */
3398 GOTO(unlock, rc = -EINPROGRESS);
3401 lfsck->li_status = stop->ls_status;
3402 lfsck->li_flags = stop->ls_flags;
3404 lfsck->li_status = LS_STOPPED;
3405 lfsck->li_flags = 0;
3408 thread_set_flags(thread, SVC_STOPPING);
3410 LASSERT(lfsck->li_task != NULL);
3411 cfs_force_sig(SIGINT, lfsck->li_task);
3413 if (lfsck->li_master) {
3414 struct lfsck_component *com;
3415 struct lfsck_assistant_data *lad;
3417 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3419 spin_lock(&lad->lad_lock);
3420 if (lad->lad_task != NULL)
3421 cfs_force_sig(SIGINT, lad->lad_task);
3422 spin_unlock(&lad->lad_lock);
3425 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
3427 spin_lock(&lad->lad_lock);
3428 if (lad->lad_task != NULL)
3429 cfs_force_sig(SIGINT, lad->lad_task);
3430 spin_unlock(&lad->lad_lock);
3434 wake_up(&thread->t_ctl_waitq);
3435 spin_unlock(&lfsck->li_lock);
3436 if (stop && stop->ls_flags & LPF_BROADCAST)
3437 rc1 = lfsck_stop_all(env, lfsck, stop);
3439 /* It was me set the status as 'stopping' just now, if it is not
3440 * 'stopping' now, then either stopped, or re-started by race. */
3441 wait_event_idle(thread->t_ctl_waitq,
3442 !thread_is_stopping(thread));
3447 spin_unlock(&lfsck->li_lock);
3449 lfsck_instance_put(env, lfsck);
3451 return rc != 0 ? rc : rc1;
3453 EXPORT_SYMBOL(lfsck_stop);
3455 int lfsck_in_notify_local(const struct lu_env *env, struct dt_device *key,
3456 struct lfsck_req_local *lrl, struct thandle *th)
3458 struct lfsck_instance *lfsck;
3459 struct lfsck_component *com;
3460 int rc = -EOPNOTSUPP;
3463 lfsck = lfsck_instance_find(key, true, false);
3464 if (unlikely(!lfsck))
3467 com = lfsck_component_find(lfsck, lrl->lrl_active);
3468 if (likely(com && com->lc_ops->lfsck_in_notify_local)) {
3469 rc = com->lc_ops->lfsck_in_notify_local(env, com, lrl, th);
3470 lfsck_component_put(env, com);
3473 lfsck_instance_put(env, lfsck);
3477 EXPORT_SYMBOL(lfsck_in_notify_local);
3479 int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
3480 struct lfsck_request *lr)
3482 int rc = -EOPNOTSUPP;
3485 switch (lr->lr_event) {
3487 struct lfsck_start *start = &lfsck_env_info(env)->lti_start;
3488 struct lfsck_start_param lsp;
3490 memset(start, 0, sizeof(*start));
3491 start->ls_valid = lr->lr_valid;
3492 start->ls_speed_limit = lr->lr_speed;
3493 start->ls_version = lr->lr_version;
3494 start->ls_active = lr->lr_active;
3495 start->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3496 start->ls_async_windows = lr->lr_async_windows;
3498 lsp.lsp_start = start;
3499 lsp.lsp_index = lr->lr_index;
3500 lsp.lsp_index_valid = 1;
3501 rc = lfsck_start(env, key, &lsp);
3505 struct lfsck_stop *stop = &lfsck_env_info(env)->lti_stop;
3507 memset(stop, 0, sizeof(*stop));
3508 stop->ls_status = lr->lr_status;
3509 stop->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3510 rc = lfsck_stop(env, key, stop);
3513 case LE_PHASE1_DONE:
3514 case LE_PHASE2_DONE:
3516 case LE_CONDITIONAL_DESTROY:
3517 case LE_SET_LMV_MASTER:
3518 case LE_SET_LMV_SLAVE:
3519 case LE_PAIRS_VERIFY: {
3520 struct lfsck_instance *lfsck;
3521 struct lfsck_component *com;
3523 lfsck = lfsck_instance_find(key, true, false);
3524 if (unlikely(lfsck == NULL))
3527 com = lfsck_component_find(lfsck, lr->lr_active);
3529 rc = com->lc_ops->lfsck_in_notify(env, com, lr);
3530 lfsck_component_put(env, com);
3533 lfsck_instance_put(env, lfsck);
3542 EXPORT_SYMBOL(lfsck_in_notify);
3544 int lfsck_query(const struct lu_env *env, struct dt_device *key,
3545 struct lfsck_request *req, struct lfsck_reply *rep,
3546 struct lfsck_query *que)
3548 struct lfsck_instance *lfsck;
3549 struct lfsck_component *com;
3555 lfsck = lfsck_instance_find(key, true, false);
3556 if (unlikely(lfsck == NULL))
3560 if (que->lu_types == LFSCK_TYPES_ALL)
3562 LFSCK_TYPES_SUPPORTED & ~LFSCK_TYPE_SCRUB;
3564 if (que->lu_types & ~LFSCK_TYPES_SUPPORTED) {
3565 que->lu_types &= ~LFSCK_TYPES_SUPPORTED;
3567 GOTO(out, rc = -ENOTSUPP);
3570 for (i = 0, type = BIT(i); i < LFSCK_TYPE_BITS;
3571 i++, type = BIT(i)) {
3572 if (!(que->lu_types & type))
3576 com = lfsck_component_find(lfsck, type);
3577 if (unlikely(com == NULL))
3578 GOTO(out, rc = -ENOTSUPP);
3580 memset(que->lu_mdts_count[i], 0,
3581 sizeof(__u32) * (LS_MAX + 1));
3582 memset(que->lu_osts_count[i], 0,
3583 sizeof(__u32) * (LS_MAX + 1));
3584 que->lu_repaired[i] = 0;
3585 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3587 lfsck_component_put(env, com);
3592 if (!(que->lu_flags & LPF_WAIT))
3595 for (i = 0, type = BIT(i); i < LFSCK_TYPE_BITS;
3596 i++, type = BIT(i)) {
3597 if (!(que->lu_types & type))
3600 if (que->lu_mdts_count[i][LS_SCANNING_PHASE1] != 0 ||
3601 que->lu_mdts_count[i][LS_SCANNING_PHASE2] != 0 ||
3602 que->lu_osts_count[i][LS_SCANNING_PHASE1] != 0 ||
3603 que->lu_osts_count[i][LS_SCANNING_PHASE2] != 0) {
3604 /* If it is required to wait, then sleep
3605 * 3 seconds and try to query again.
3607 unsigned long timeout =
3608 msecs_to_jiffies(3000) + 1;
3610 !fatal_signal_pending(current))
3611 timeout = schedule_timeout_killable(
3618 com = lfsck_component_find(lfsck, req->lr_active);
3619 if (likely(com != NULL)) {
3620 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3622 lfsck_component_put(env, com);
3631 lfsck_instance_put(env, lfsck);
3634 EXPORT_SYMBOL(lfsck_query);
3636 int lfsck_register_namespace(const struct lu_env *env, struct dt_device *key,
3637 struct ldlm_namespace *ns)
3639 struct lfsck_instance *lfsck;
3642 lfsck = lfsck_instance_find(key, true, false);
3643 if (likely(lfsck != NULL)) {
3644 lfsck->li_namespace = ns;
3645 lfsck_instance_put(env, lfsck);
3651 EXPORT_SYMBOL(lfsck_register_namespace);
3653 int lfsck_register(const struct lu_env *env, struct dt_device *key,
3654 struct dt_device *next, struct obd_device *obd,
3655 lfsck_out_notify notify, void *notify_data, bool master)
3657 struct lfsck_instance *lfsck;
3658 struct dt_object *root = NULL;
3659 struct dt_object *obj = NULL;
3660 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
3664 lfsck = lfsck_instance_find(key, false, false);
3665 if (unlikely(lfsck != NULL))
3668 OBD_ALLOC_PTR(lfsck);
3672 mutex_init(&lfsck->li_mutex);
3673 spin_lock_init(&lfsck->li_lock);
3674 INIT_LIST_HEAD(&lfsck->li_link);
3675 INIT_LIST_HEAD(&lfsck->li_list_scan);
3676 INIT_LIST_HEAD(&lfsck->li_list_dir);
3677 INIT_LIST_HEAD(&lfsck->li_list_double_scan);
3678 INIT_LIST_HEAD(&lfsck->li_list_idle);
3679 INIT_LIST_HEAD(&lfsck->li_list_lmv);
3680 atomic_set(&lfsck->li_ref, 1);
3681 atomic_set(&lfsck->li_double_scan_count, 0);
3682 init_waitqueue_head(&lfsck->li_thread.t_ctl_waitq);
3683 lfsck->li_out_notify = notify;
3684 lfsck->li_out_notify_data = notify_data;
3685 lfsck->li_next = next;
3686 lfsck->li_bottom = key;
3687 lfsck->li_obd = obd;
3689 rc = lfsck_tgt_descs_init(&lfsck->li_ost_descs);
3693 rc = lfsck_tgt_descs_init(&lfsck->li_mdt_descs);
3697 fid->f_seq = FID_SEQ_LOCAL_NAME;
3700 rc = local_oid_storage_init(env, key, fid, &lfsck->li_los);
3704 rc = dt_root_get(env, key, fid);
3708 root = dt_locate(env, key, fid);
3710 GOTO(out, rc = PTR_ERR(root));
3712 lfsck->li_local_root_fid = *fid;
3714 lfsck->li_master = 1;
3715 if (lfsck_dev_idx(lfsck) == 0) {
3716 struct lu_fid *pfid = &lfsck_env_info(env)->lti_fid2;
3717 const struct lu_name *cname;
3719 rc = dt_lookup_dir(env, root, "ROOT",
3720 &lfsck->li_global_root_fid);
3724 obj = dt_locate(env, key, &lfsck->li_global_root_fid);
3726 GOTO(out, rc = PTR_ERR(obj));
3728 rc = dt_lookup_dir(env, obj, dotlustre, fid);
3732 lfsck_object_put(env, obj);
3733 obj = dt_locate(env, key, fid);
3735 GOTO(out, rc = PTR_ERR(obj));
3737 cname = lfsck_name_get_const(env, dotlustre,
3739 rc = lfsck_verify_linkea(env, lfsck, obj, cname,
3740 &lfsck->li_global_root_fid);
3744 if (unlikely(!dt_try_as_dir(env, obj)))
3745 GOTO(out, rc = -ENOTDIR);
3748 rc = dt_lookup_dir(env, obj, lostfound, fid);
3752 lfsck_object_put(env, obj);
3753 obj = dt_locate(env, key, fid);
3755 GOTO(out, rc = PTR_ERR(obj));
3757 cname = lfsck_name_get_const(env, lostfound,
3759 rc = lfsck_verify_linkea(env, lfsck, obj, cname, pfid);
3763 lfsck_object_put(env, obj);
3768 fid->f_seq = FID_SEQ_LOCAL_FILE;
3769 fid->f_oid = OTABLE_IT_OID;
3771 obj = dt_locate(env, key, fid);
3773 GOTO(out, rc = PTR_ERR(obj));
3775 rc = obj->do_ops->do_index_try(env, obj, &dt_otable_features);
3779 lfsck->li_obj_oit = obj;
3780 obj = local_file_find_or_create(env, lfsck->li_los, root, LFSCK_DIR,
3781 S_IFDIR | S_IRUGO | S_IWUSR);
3783 GOTO(out, rc = PTR_ERR(obj));
3785 lu_object_get(&obj->do_lu);
3786 lfsck->li_lfsck_dir = obj;
3787 rc = lfsck_bookmark_setup(env, lfsck);
3792 rc = lfsck_fid_init(lfsck);
3796 rc = lfsck_namespace_setup(env, lfsck);
3801 rc = lfsck_layout_setup(env, lfsck);
3805 /* XXX: more LFSCK components initialization to be added here. */
3807 rc = lfsck_instance_add(lfsck);
3809 rc = lfsck_add_target_from_orphan(env, lfsck);
3811 if (obj != NULL && !IS_ERR(obj))
3812 lfsck_object_put(env, obj);
3813 if (root != NULL && !IS_ERR(root))
3814 lfsck_object_put(env, root);
3816 lfsck_instance_cleanup(env, lfsck);
3819 EXPORT_SYMBOL(lfsck_register);
3821 void lfsck_degister(const struct lu_env *env, struct dt_device *key)
3823 struct lfsck_instance *lfsck;
3825 lfsck = lfsck_instance_find(key, false, true);
3827 lfsck_instance_put(env, lfsck);
3829 EXPORT_SYMBOL(lfsck_degister);
3831 int lfsck_add_target(const struct lu_env *env, struct dt_device *key,
3832 struct dt_device *tgt, struct obd_export *exp,
3833 __u32 index, bool for_ost)
3835 struct lfsck_instance *lfsck;
3836 struct lfsck_tgt_desc *ltd;
3847 INIT_LIST_HEAD(<d->ltd_orphan_list);
3848 INIT_LIST_HEAD(<d->ltd_layout_list);
3849 INIT_LIST_HEAD(<d->ltd_layout_phase_list);
3850 INIT_LIST_HEAD(<d->ltd_namespace_list);
3851 INIT_LIST_HEAD(<d->ltd_namespace_phase_list);
3852 atomic_set(<d->ltd_ref, 1);
3853 ltd->ltd_index = index;
3855 spin_lock(&lfsck_instance_lock);
3856 lfsck = __lfsck_instance_find(key, true, false);
3857 if (lfsck == NULL) {
3859 list_add_tail(<d->ltd_orphan_list,
3860 &lfsck_ost_orphan_list);
3862 list_add_tail(<d->ltd_orphan_list,
3863 &lfsck_mdt_orphan_list);
3864 spin_unlock(&lfsck_instance_lock);
3868 spin_unlock(&lfsck_instance_lock);
3870 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, false);
3874 lfsck_instance_put(env, lfsck);
3878 EXPORT_SYMBOL(lfsck_add_target);
3880 void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
3881 struct dt_device *tgt, __u32 index, bool for_ost)
3883 struct lfsck_instance *lfsck;
3884 struct lfsck_tgt_descs *ltds;
3885 struct lfsck_tgt_desc *ltd;
3886 struct list_head *head;
3889 head = &lfsck_ost_orphan_list;
3891 head = &lfsck_mdt_orphan_list;
3893 spin_lock(&lfsck_instance_lock);
3894 list_for_each_entry(ltd, head, ltd_orphan_list) {
3895 if (ltd->ltd_tgt == tgt) {
3896 list_del_init(<d->ltd_orphan_list);
3897 spin_unlock(&lfsck_instance_lock);
3905 lfsck = __lfsck_instance_find(key, true, false);
3906 spin_unlock(&lfsck_instance_lock);
3907 if (unlikely(lfsck == NULL))
3911 ltds = &lfsck->li_ost_descs;
3913 ltds = &lfsck->li_mdt_descs;
3915 down_write(<ds->ltd_rw_sem);
3916 LASSERT(ltds->ltd_tgts_bitmap != NULL);
3918 if (unlikely(index >= ltds->ltd_tgts_bitmap->size))
3921 ltd = lfsck_ltd2tgt(ltds, index);
3922 if (unlikely(ltd == NULL))
3925 LASSERT(ltds->ltd_tgtnr > 0);
3928 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, index);
3929 lfsck_assign_tgt(ltds, NULL, index);
3934 head = &lfsck->li_ost_descs.ltd_orphan;
3936 head = &lfsck->li_mdt_descs.ltd_orphan;
3938 list_for_each_entry(ltd, head, ltd_orphan_list) {
3939 if (ltd->ltd_tgt == tgt) {
3940 list_del_init(<d->ltd_orphan_list);
3946 up_write(<ds->ltd_rw_sem);
3948 spin_lock(<ds->ltd_lock);
3950 spin_unlock(<ds->ltd_lock);
3951 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_NAMESPACE);
3952 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_LAYOUT);
3956 lfsck_instance_put(env, lfsck);
3958 EXPORT_SYMBOL(lfsck_del_target);
3960 static int __init lfsck_init(void)
3964 lfsck_key_init_generic(&lfsck_thread_key, NULL);
3965 rc = lu_context_key_register(&lfsck_thread_key);
3967 tgt_register_lfsck_in_notify_local(lfsck_in_notify_local);
3968 tgt_register_lfsck_in_notify(lfsck_in_notify);
3969 tgt_register_lfsck_query(lfsck_query);
3975 static void __exit lfsck_exit(void)
3977 struct lfsck_tgt_desc *ltd;
3978 struct lfsck_tgt_desc *next;
3980 LASSERT(list_empty(&lfsck_instance_list));
3982 list_for_each_entry_safe(ltd, next, &lfsck_ost_orphan_list,
3984 list_del_init(<d->ltd_orphan_list);
3988 list_for_each_entry_safe(ltd, next, &lfsck_mdt_orphan_list,
3990 list_del_init(<d->ltd_orphan_list);
3994 lu_context_key_degister(&lfsck_thread_key);
3997 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3998 MODULE_DESCRIPTION("Lustre File System Checker");
3999 MODULE_VERSION(LUSTRE_VERSION_STRING);
4000 MODULE_LICENSE("GPL");
4002 module_init(lfsck_init);
4003 module_exit(lfsck_exit);