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 < TGT_PTRS; idx++) {
162 if (ltds->ltd_tgts_idx[idx] != NULL) {
163 OBD_FREE_PTR(ltds->ltd_tgts_idx[idx]);
164 ltds->ltd_tgts_idx[idx] = NULL;
168 CFS_FREE_BITMAP(ltds->ltd_tgts_bitmap);
169 ltds->ltd_tgts_bitmap = NULL;
170 up_write(<ds->ltd_rw_sem);
173 static int __lfsck_add_target(const struct lu_env *env,
174 struct lfsck_instance *lfsck,
175 struct lfsck_tgt_desc *ltd,
176 bool for_ost, bool locked)
178 struct lfsck_tgt_descs *ltds;
179 __u32 index = ltd->ltd_index;
184 ltds = &lfsck->li_ost_descs;
186 ltds = &lfsck->li_mdt_descs;
189 down_write(<ds->ltd_rw_sem);
191 LASSERT(ltds->ltd_tgts_bitmap != NULL);
193 if (index >= ltds->ltd_tgts_bitmap->size) {
194 __u32 newsize = max((__u32)ltds->ltd_tgts_bitmap->size,
195 (__u32)BITS_PER_LONG);
196 struct cfs_bitmap *old_bitmap = ltds->ltd_tgts_bitmap;
197 struct cfs_bitmap *new_bitmap;
199 while (newsize < index + 1)
202 new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
203 if (new_bitmap == NULL)
204 GOTO(unlock, rc = -ENOMEM);
206 if (ltds->ltd_tgtnr > 0)
207 cfs_bitmap_copy(new_bitmap, old_bitmap);
208 ltds->ltd_tgts_bitmap = new_bitmap;
209 CFS_FREE_BITMAP(old_bitmap);
212 if (cfs_bitmap_check(ltds->ltd_tgts_bitmap, index)) {
213 CERROR("%s: the device %s (%u) is registered already\n",
214 lfsck_lfsck2name(lfsck),
215 ltd->ltd_tgt->dd_lu_dev.ld_obd->obd_name, index);
216 GOTO(unlock, rc = -EEXIST);
219 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
220 OBD_ALLOC_PTR(ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK]);
221 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL)
222 GOTO(unlock, rc = -ENOMEM);
225 lfsck_assign_tgt(ltds, ltd, index);
226 cfs_bitmap_set(ltds->ltd_tgts_bitmap, index);
229 GOTO(unlock, rc = 0);
233 up_write(<ds->ltd_rw_sem);
238 static int lfsck_add_target_from_orphan(const struct lu_env *env,
239 struct lfsck_instance *lfsck)
241 struct lfsck_tgt_descs *ltds = &lfsck->li_ost_descs;
242 struct lfsck_tgt_desc *ltd;
243 struct lfsck_tgt_desc *next;
244 struct list_head *head = &lfsck_ost_orphan_list;
249 spin_lock(&lfsck_instance_lock);
250 list_for_each_entry_safe(ltd, next, head, ltd_orphan_list) {
251 if (ltd->ltd_key == lfsck->li_bottom)
252 list_move_tail(<d->ltd_orphan_list,
255 spin_unlock(&lfsck_instance_lock);
257 down_write(<ds->ltd_rw_sem);
258 while (!list_empty(<ds->ltd_orphan)) {
259 ltd = list_entry(ltds->ltd_orphan.next,
260 struct lfsck_tgt_desc,
262 list_del_init(<d->ltd_orphan_list);
263 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, true);
264 /* Do not hold the semaphore for too long time. */
265 up_write(<ds->ltd_rw_sem);
269 down_write(<ds->ltd_rw_sem);
271 up_write(<ds->ltd_rw_sem);
274 ltds = &lfsck->li_mdt_descs;
275 head = &lfsck_mdt_orphan_list;
283 static inline struct lfsck_component *
284 __lfsck_component_find(struct lfsck_instance *lfsck, __u16 type,
285 struct list_head *list)
287 struct lfsck_component *com;
289 list_for_each_entry(com, list, lc_link) {
290 if (com->lc_type == type)
296 struct lfsck_component *
297 lfsck_component_find(struct lfsck_instance *lfsck, __u16 type)
299 struct lfsck_component *com;
301 spin_lock(&lfsck->li_lock);
302 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
306 com = __lfsck_component_find(lfsck, type,
307 &lfsck->li_list_double_scan);
311 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_idle);
315 lfsck_component_get(com);
316 spin_unlock(&lfsck->li_lock);
320 void lfsck_component_cleanup(const struct lu_env *env,
321 struct lfsck_component *com)
323 if (!list_empty(&com->lc_link))
324 list_del_init(&com->lc_link);
325 if (!list_empty(&com->lc_link_dir))
326 list_del_init(&com->lc_link_dir);
328 lfsck_component_put(env, com);
331 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
332 struct lu_fid *fid, bool locked)
334 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
339 mutex_lock(&lfsck->li_mutex);
341 rc = seq_client_alloc_fid(env, lfsck->li_seq, fid);
343 bk->lb_last_fid = *fid;
344 /* We do not care about whether the subsequent sub-operations
345 * failed or not. The worst case is that one FID is lost that
346 * is not a big issue for the LFSCK since it is relative rare
347 * for LFSCK create. */
348 rc = lfsck_bookmark_store(env, lfsck);
352 mutex_unlock(&lfsck->li_mutex);
357 static int __lfsck_ibits_lock(const struct lu_env *env,
358 struct lfsck_instance *lfsck,
359 struct dt_object *obj, struct ldlm_res_id *resid,
360 struct lustre_handle *lh, __u64 bits,
363 struct lfsck_thread_info *info = lfsck_env_info(env);
364 union ldlm_policy_data *policy = &info->lti_policy;
365 __u64 flags = LDLM_FL_ATOMIC_CB;
368 LASSERT(lfsck->li_namespace != NULL);
370 memset(policy, 0, sizeof(*policy));
371 policy->l_inodebits.bits = bits;
372 if (dt_object_remote(obj)) {
373 struct ldlm_enqueue_info *einfo = &info->lti_einfo;
375 memset(einfo, 0, sizeof(*einfo));
376 einfo->ei_type = LDLM_IBITS;
377 einfo->ei_mode = mode;
378 einfo->ei_cb_bl = ldlm_blocking_ast;
379 einfo->ei_cb_cp = ldlm_completion_ast;
380 einfo->ei_res_id = resid;
382 rc = dt_object_lock(env, obj, lh, einfo, policy);
383 /* for regular checks LFSCK doesn't use LDLM locking,
384 * so the state isn't coherent. here we just took LDLM
385 * lock for coherency and it's time to invalidate
388 dt_invalidate(env, obj);
390 rc = ldlm_cli_enqueue_local(env, lfsck->li_namespace, resid,
391 LDLM_IBITS, policy, mode,
392 &flags, ldlm_blocking_ast,
393 ldlm_completion_ast, NULL, NULL,
394 0, LVB_T_NONE, NULL, lh);
397 if (rc == ELDLM_OK) {
400 memset(lh, 0, sizeof(*lh));
408 * Request the specified ibits lock for the given object.
410 * Before the LFSCK modifying on the namespace visible object,
411 * it needs to acquire related ibits ldlm lock.
413 * \param[in] env pointer to the thread context
414 * \param[in] lfsck pointer to the lfsck instance
415 * \param[in] obj pointer to the dt_object to be locked
416 * \param[out] lh pointer to the lock handle
417 * \param[in] bits the bits for the ldlm lock to be acquired
418 * \param[in] mode the mode for the ldlm lock to be acquired
420 * \retval 0 for success
421 * \retval negative error number on failure
423 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
424 struct dt_object *obj, struct lustre_handle *lh,
425 __u64 bits, enum ldlm_mode mode)
427 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
429 LASSERT(!lustre_handle_is_used(lh));
431 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
432 return __lfsck_ibits_lock(env, lfsck, obj, resid, lh, bits, mode);
436 * Request the remote LOOKUP lock for the given object.
438 * If \a pobj is remote, the LOOKUP lock of \a obj is on the MDT where
439 * \a pobj is, acquire LOOKUP lock there.
441 * \param[in] env pointer to the thread context
442 * \param[in] lfsck pointer to the lfsck instance
443 * \param[in] pobj pointer to parent dt_object
444 * \param[in] obj pointer to the dt_object to be locked
445 * \param[out] lh pointer to the lock handle
446 * \param[in] mode the mode for the ldlm lock to be acquired
448 * \retval 0 for success
449 * \retval negative error number on failure
451 int lfsck_remote_lookup_lock(const struct lu_env *env,
452 struct lfsck_instance *lfsck,
453 struct dt_object *pobj, struct dt_object *obj,
454 struct lustre_handle *lh, enum ldlm_mode mode)
456 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
458 LASSERT(!lustre_handle_is_used(lh));
460 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
461 return __lfsck_ibits_lock(env, lfsck, pobj, resid, lh,
462 MDS_INODELOCK_LOOKUP, mode);
466 * Release the the specified ibits lock.
468 * If the lock has been acquired before, release it
469 * and cleanup the handle. Otherwise, do nothing.
471 * \param[in] lh pointer to the lock handle
472 * \param[in] mode the mode for the ldlm lock to be released
474 void lfsck_ibits_unlock(struct lustre_handle *lh, enum ldlm_mode mode)
476 if (lustre_handle_is_used(lh)) {
477 ldlm_lock_decref(lh, mode);
478 memset(lh, 0, sizeof(*lh));
483 * Request compound ibits locks for the given <obj, name> pairs.
485 * Before the LFSCK modifying on the namespace visible object, it needs to
486 * acquire related ibits ldlm lock. Usually, we can use lfsck_ibits_lock for
487 * the lock purpose. But the simple lfsck_ibits_lock for directory-based
488 * modificationis (such as insert name entry to the directory) may be too
489 * coarse-grained and not efficient.
491 * The lfsck_lock() will request compound ibits locks on the specified
492 * <obj, name> pairs: the PDO (Parallel Directory Operations) ibits (UPDATE)
493 * lock on the directory object, and the regular ibits lock on the name hash.
495 * \param[in] env pointer to the thread context
496 * \param[in] lfsck pointer to the lfsck instance
497 * \param[in] obj pointer to the dt_object to be locked
498 * \param[in] name used for building the PDO lock resource
499 * \param[out] llh pointer to the lfsck_lock_handle
500 * \param[in] bits the bits for the ldlm lock to be acquired
501 * \param[in] mode the mode for the ldlm lock to be acquired
503 * \retval 0 for success
504 * \retval negative error number on failure
506 int lfsck_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
507 struct dt_object *obj, const char *name,
508 struct lfsck_lock_handle *llh, __u64 bits, enum ldlm_mode mode)
510 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
513 LASSERT(S_ISDIR(lfsck_object_type(obj)));
514 LASSERT(name != NULL);
515 LASSERT(name[0] != 0);
516 LASSERT(!lustre_handle_is_used(&llh->llh_pdo_lh));
517 LASSERT(!lustre_handle_is_used(&llh->llh_reg_lh));
521 llh->llh_pdo_mode = LCK_EX;
524 llh->llh_pdo_mode = LCK_CW;
527 llh->llh_pdo_mode = LCK_CR;
530 CDEBUG(D_LFSCK, "%s: unexpected PDO lock mode %u on the obj "
531 DFID"\n", lfsck_lfsck2name(lfsck), mode,
532 PFID(lfsck_dto2fid(obj)));
536 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
537 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_pdo_lh,
538 MDS_INODELOCK_UPDATE, llh->llh_pdo_mode);
542 llh->llh_reg_mode = mode;
543 resid->name[LUSTRE_RES_ID_HSH_OFF] = ll_full_name_hash(NULL, name,
545 LASSERT(resid->name[LUSTRE_RES_ID_HSH_OFF] != 0);
546 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_reg_lh,
547 bits, llh->llh_reg_mode);
549 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
555 * Release the the compound ibits locks.
557 * \param[in] llh pointer to the lfsck_lock_handle to be released
559 void lfsck_unlock(struct lfsck_lock_handle *llh)
561 lfsck_ibits_unlock(&llh->llh_reg_lh, llh->llh_reg_mode);
562 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
565 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
566 struct lfsck_instance *lfsck,
567 const struct lu_fid *fid)
569 struct seq_server_site *ss = lfsck_dev_site(lfsck);
570 struct lu_seq_range *range = &lfsck_env_info(env)->lti_range;
573 if (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE)) {
574 /* "ROOT" is always on the MDT0. */
575 if (lu_fid_eq(fid, &lfsck->li_global_root_fid))
578 return lfsck_dev_idx(lfsck);
581 fld_range_set_mdt(range);
582 rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
584 rc = range->lsr_index;
589 const char dot[] = ".";
590 const char dotdot[] = "..";
591 static const char dotlustre[] = ".lustre";
592 static const char lostfound[] = "lost+found";
595 * Remove the name entry from the .lustre/lost+found directory.
597 * No need to care about the object referenced by the name entry,
598 * either the name entry is invalid or redundant, or the referenced
599 * object has been processed or will be handled by others.
601 * \param[in] env pointer to the thread context
602 * \param[in] lfsck pointer to the lfsck instance
603 * \param[in] name the name for the name entry to be removed
605 * \retval 0 for success
606 * \retval negative error number on failure
608 static int lfsck_lpf_remove_name_entry(const struct lu_env *env,
609 struct lfsck_instance *lfsck,
612 struct dt_object *parent = lfsck->li_lpf_root_obj;
613 struct dt_device *dev = lfsck_obj2dev(parent);
615 struct lfsck_lock_handle *llh = &lfsck_env_info(env)->lti_llh;
619 rc = lfsck_lock(env, lfsck, parent, name, llh,
620 MDS_INODELOCK_UPDATE, LCK_PW);
624 th = dt_trans_create(env, dev);
626 GOTO(unlock, rc = PTR_ERR(th));
628 rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
632 rc = dt_declare_ref_del(env, parent, th);
636 rc = dt_trans_start_local(env, dev, th);
640 rc = dt_delete(env, parent, (const struct dt_key *)name, th);
644 dt_write_lock(env, parent, 0);
645 rc = dt_ref_del(env, parent, th);
646 dt_write_unlock(env, parent);
651 dt_trans_stop(env, dev, th);
656 CDEBUG(D_LFSCK, "%s: remove name entry "DFID"/%s: rc = %d\n",
657 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(parent)), name, rc);
662 static int lfsck_create_lpf_local(const struct lu_env *env,
663 struct lfsck_instance *lfsck,
664 struct dt_object *child,
666 struct dt_object_format *dof,
669 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
670 struct dt_object *parent = lfsck->li_lpf_root_obj;
671 struct dt_device *dev = lfsck_obj2dev(child);
672 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
673 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
674 const struct lu_fid *cfid = lfsck_dto2fid(child);
675 struct thandle *th = NULL;
676 struct linkea_data ldata = { NULL };
677 struct lu_buf linkea_buf;
678 const struct lu_name *cname;
680 int len = sizeof(struct lfsck_bookmark);
684 cname = lfsck_name_get_const(env, name, strlen(name));
685 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
686 cname, lfsck_dto2fid(parent));
690 th = dt_trans_create(env, dev);
694 /* 1a. create child */
695 rc = dt_declare_create(env, child, la, NULL, dof, th);
699 if (!dt_try_as_dir(env, child))
700 GOTO(stop, rc = -ENOTDIR);
702 /* 2a. increase child nlink */
703 rc = dt_declare_ref_add(env, child, th);
707 /* 3a. insert dot into child dir */
708 rec->rec_type = S_IFDIR;
710 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
711 (const struct dt_key *)dot, th);
715 /* 4a. insert dotdot into child dir */
716 rec->rec_fid = &LU_LPF_FID;
717 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
718 (const struct dt_key *)dotdot, th);
722 /* 5a. insert linkEA for child */
723 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
724 ldata.ld_leh->leh_len);
725 rc = dt_declare_xattr_set(env, child, &linkea_buf,
726 XATTR_NAME_LINK, 0, th);
730 /* 6a. insert name into parent dir */
731 rec->rec_type = S_IFDIR;
733 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
734 (const struct dt_key *)name, th);
738 /* 7a. increase parent nlink */
739 rc = dt_declare_ref_add(env, parent, th);
743 /* 8a. update bookmark */
744 rc = dt_declare_record_write(env, bk_obj,
745 lfsck_buf_get(env, bk, len), 0, th);
749 rc = dt_trans_start_local(env, dev, th);
753 dt_write_lock(env, child, 0);
754 /* 1b. create child */
755 rc = dt_create(env, child, la, NULL, dof, th);
759 /* 2b. increase child nlink */
760 rc = dt_ref_add(env, child, th);
764 /* 3b. insert dot into child dir */
766 rc = dt_insert(env, child, (const struct dt_rec *)rec,
767 (const struct dt_key *)dot, th);
771 /* 4b. insert dotdot into child dir */
772 rec->rec_fid = &LU_LPF_FID;
773 rc = dt_insert(env, child, (const struct dt_rec *)rec,
774 (const struct dt_key *)dotdot, th);
778 /* 5b. insert linkEA for child. */
779 rc = dt_xattr_set(env, child, &linkea_buf,
780 XATTR_NAME_LINK, 0, th);
781 dt_write_unlock(env, child);
785 /* 6b. insert name into parent dir */
787 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
788 (const struct dt_key *)name, th);
792 dt_write_lock(env, parent, 0);
793 /* 7b. increase parent nlink */
794 rc = dt_ref_add(env, parent, th);
795 dt_write_unlock(env, parent);
799 bk->lb_lpf_fid = *cfid;
800 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
802 /* 8b. update bookmark */
803 rc = dt_record_write(env, bk_obj,
804 lfsck_buf_get(env, bk, len), &pos, th);
809 dt_write_unlock(env, child);
812 dt_trans_stop(env, dev, th);
817 static int lfsck_create_lpf_remote(const struct lu_env *env,
818 struct lfsck_instance *lfsck,
819 struct dt_object *child,
821 struct dt_object_format *dof,
824 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
825 struct dt_object *parent = lfsck->li_lpf_root_obj;
826 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
827 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
828 const struct lu_fid *cfid = lfsck_dto2fid(child);
829 struct thandle *th = NULL;
830 struct linkea_data ldata = { NULL };
831 struct lu_buf linkea_buf;
832 const struct lu_name *cname;
833 struct dt_device *dev;
835 int len = sizeof(struct lfsck_bookmark);
839 cname = lfsck_name_get_const(env, name, strlen(name));
840 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
841 cname, lfsck_dto2fid(parent));
845 /* Create .lustre/lost+found/MDTxxxx. */
847 /* XXX: Currently, cross-MDT create operation needs to create the child
848 * object firstly, then insert name into the parent directory. For
849 * this case, the child object resides on current MDT (local), but
850 * the parent ".lustre/lost+found" may be on remote MDT. It is not
851 * easy to contain all the sub-modifications orderly within single
854 * To avoid more inconsistency, we split the create operation into
857 * 1) create the child and update the lfsck_bookmark::lb_lpf_fid
859 * 2) insert the name "MDTXXXX" in the parent ".lustre/lost+found"
862 * If 1) done, but 2) failed, then go ahead, the LFSCK will try to
863 * repair such inconsistency when LFSCK run next time. */
865 /* Transaction I: locally */
867 dev = lfsck_obj2dev(child);
868 th = dt_trans_create(env, dev);
872 /* 1a. create child */
873 rc = dt_declare_create(env, child, la, NULL, dof, th);
877 if (!dt_try_as_dir(env, child))
878 GOTO(stop, rc = -ENOTDIR);
880 /* 2a. increase child nlink */
881 rc = dt_declare_ref_add(env, child, th);
885 /* 3a. insert dot into child dir */
886 rec->rec_type = S_IFDIR;
888 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
889 (const struct dt_key *)dot, th);
893 /* 4a. insert dotdot into child dir */
894 rec->rec_fid = &LU_LPF_FID;
895 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
896 (const struct dt_key *)dotdot, th);
900 /* 5a. insert linkEA for child */
901 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
902 ldata.ld_leh->leh_len);
903 rc = dt_declare_xattr_set(env, child, &linkea_buf,
904 XATTR_NAME_LINK, 0, th);
908 /* 6a. update bookmark */
909 rc = dt_declare_record_write(env, bk_obj,
910 lfsck_buf_get(env, bk, len), 0, th);
914 rc = dt_trans_start_local(env, dev, th);
918 dt_write_lock(env, child, 0);
919 /* 1b. create child */
920 rc = dt_create(env, child, la, NULL, dof, th);
924 /* 2b. increase child nlink */
925 rc = dt_ref_add(env, child, th);
929 /* 3b. insert dot into child dir */
930 rec->rec_type = S_IFDIR;
932 rc = dt_insert(env, child, (const struct dt_rec *)rec,
933 (const struct dt_key *)dot, th);
937 /* 4b. insert dotdot into child dir */
938 rec->rec_fid = &LU_LPF_FID;
939 rc = dt_insert(env, child, (const struct dt_rec *)rec,
940 (const struct dt_key *)dotdot, th);
944 /* 5b. insert linkEA for child */
945 rc = dt_xattr_set(env, child, &linkea_buf,
946 XATTR_NAME_LINK, 0, th);
950 bk->lb_lpf_fid = *cfid;
951 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
953 /* 6b. update bookmark */
954 rc = dt_record_write(env, bk_obj,
955 lfsck_buf_get(env, bk, len), &pos, th);
957 dt_write_unlock(env, child);
958 dt_trans_stop(env, dev, th);
962 /* Transaction II: remotely */
964 dev = lfsck_obj2dev(parent);
965 th = dt_trans_create(env, dev);
970 /* 5a. insert name into parent dir */
972 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
973 (const struct dt_key *)name, th);
977 /* 6a. increase parent nlink */
978 rc = dt_declare_ref_add(env, parent, th);
982 rc = dt_trans_start_local(env, dev, th);
986 /* 5b. insert name into parent dir */
987 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
988 (const struct dt_key *)name, th);
992 dt_write_lock(env, parent, 0);
993 /* 6b. increase parent nlink */
994 rc = dt_ref_add(env, parent, th);
995 dt_write_unlock(env, parent);
1000 dt_write_unlock(env, child);
1002 dt_trans_stop(env, dev, th);
1004 if (rc != 0 && dev == lfsck_obj2dev(parent))
1005 CDEBUG(D_LFSCK, "%s: partially created the object "DFID
1006 "for orphans, but failed to insert the name %s "
1007 "to the .lustre/lost+found/. Such inconsistency "
1008 "will be repaired when LFSCK run next time: rc = %d\n",
1009 lfsck_lfsck2name(lfsck), PFID(cfid), name, rc);
1015 * Create the MDTxxxx directory under /ROOT/.lustre/lost+found/
1017 * The /ROOT/.lustre/lost+found/MDTxxxx/ directory is used for holding
1018 * orphans and other uncertain inconsistent objects found during the
1019 * LFSCK. Such directory will be created by the LFSCK engine on the
1020 * local MDT before the LFSCK scanning.
1022 * \param[in] env pointer to the thread context
1023 * \param[in] lfsck pointer to the lfsck instance
1025 * \retval 0 for success
1026 * \retval negative error number on failure
1028 static int lfsck_create_lpf(const struct lu_env *env,
1029 struct lfsck_instance *lfsck)
1031 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1032 struct lfsck_thread_info *info = lfsck_env_info(env);
1033 struct lu_fid *cfid = &info->lti_fid2;
1034 struct lu_attr *la = &info->lti_la;
1035 struct dt_object_format *dof = &info->lti_dof;
1036 struct dt_object *parent = lfsck->li_lpf_root_obj;
1037 struct dt_object *child = NULL;
1038 struct lfsck_lock_handle *llh = &info->lti_llh;
1040 int node = lfsck_dev_idx(lfsck);
1044 LASSERT(lfsck->li_master);
1045 LASSERT(parent != NULL);
1046 LASSERT(lfsck->li_lpf_obj == NULL);
1048 snprintf(name, 8, "MDT%04x", node);
1049 rc = lfsck_lock(env, lfsck, parent, name, llh,
1050 MDS_INODELOCK_UPDATE, LCK_PW);
1054 if (fid_is_zero(&bk->lb_lpf_fid)) {
1055 /* There is corner case that: in former LFSCK scanning we have
1056 * created the .lustre/lost+found/MDTxxxx but failed to update
1057 * the lfsck_bookmark::lb_lpf_fid successfully. So need lookup
1058 * it from MDT0 firstly. */
1059 rc = dt_lookup_dir(env, parent, name, cfid);
1060 if (rc != 0 && rc != -ENOENT)
1064 bk->lb_lpf_fid = *cfid;
1065 rc = lfsck_bookmark_store(env, lfsck);
1067 rc = lfsck_fid_alloc(env, lfsck, cfid, true);
1072 *cfid = bk->lb_lpf_fid;
1075 child = lfsck_object_find_bottom_new(env, lfsck, cfid);
1077 GOTO(unlock, rc = PTR_ERR(child));
1079 if (dt_object_exists(child) != 0) {
1080 if (unlikely(!dt_try_as_dir(env, child)))
1083 lfsck->li_lpf_obj = child;
1088 memset(la, 0, sizeof(*la));
1089 la->la_atime = la->la_mtime = la->la_ctime = ktime_get_real_seconds();
1090 la->la_mode = S_IFDIR | S_IRWXU;
1091 la->la_valid = LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1092 LA_UID | LA_GID | LA_TYPE;
1093 memset(dof, 0, sizeof(*dof));
1094 dof->dof_type = dt_mode_to_dft(S_IFDIR);
1097 rc = lfsck_create_lpf_local(env, lfsck, child, la, dof, name);
1099 rc = lfsck_create_lpf_remote(env, lfsck, child, la, dof, name);
1101 lfsck->li_lpf_obj = child;
1107 if (rc != 0 && child != NULL && !IS_ERR(child))
1108 lfsck_object_put(env, child);
1114 * Scan .lustre/lost+found for bad name entries and remove them.
1116 * The valid name entry should be "MDTxxxx", the "xxxx" is the MDT device
1117 * index in the system. Any other formatted name is invalid and should be
1120 * \param[in] env pointer to the thread context
1121 * \param[in] lfsck pointer to the lfsck instance
1123 * \retval 0 for success
1124 * \retval negative error number on failure
1126 static int lfsck_scan_lpf_bad_entries(const struct lu_env *env,
1127 struct lfsck_instance *lfsck)
1129 struct dt_object *parent = lfsck->li_lpf_root_obj;
1130 struct lu_dirent *ent =
1131 (struct lu_dirent *)lfsck_env_info(env)->lti_key;
1132 const struct dt_it_ops *iops = &parent->do_index_ops->dio_it;
1137 it = iops->init(env, parent, LUDA_64BITHASH);
1139 RETURN(PTR_ERR(it));
1141 rc = iops->load(env, it, 0);
1143 rc = iops->next(env, it);
1150 rc = iops->rec(env, it, (struct dt_rec *)ent, LUDA_64BITHASH);
1154 ent->lde_namelen = le16_to_cpu(ent->lde_namelen);
1155 if (name_is_dot_or_dotdot(ent->lde_name, ent->lde_namelen))
1158 /* name length must be strlen("MDTxxxx") */
1159 if (ent->lde_namelen != 7)
1162 if (memcmp(ent->lde_name, "MDT", off) != 0)
1165 while (off < 7 && isxdigit(ent->lde_name[off]))
1171 rc = lfsck_lpf_remove_name_entry(env, lfsck,
1178 rc = iops->next(env, it);
1182 iops->fini(env, it);
1184 RETURN(rc > 0 ? 0 : rc);
1187 static int lfsck_update_lpf_entry(const struct lu_env *env,
1188 struct lfsck_instance *lfsck,
1189 struct dt_object *parent,
1190 struct dt_object *child,
1192 enum lfsck_verify_lpf_types type)
1196 if (type == LVLT_BY_BOOKMARK) {
1197 rc = lfsck_update_name_entry(env, lfsck, parent, name,
1198 lfsck_dto2fid(child), S_IFDIR);
1199 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1200 lfsck->li_bookmark_ram.lb_lpf_fid = *lfsck_dto2fid(child);
1201 rc = lfsck_bookmark_store(env, lfsck);
1203 CDEBUG(D_LFSCK, "%s: update LPF fid "DFID
1204 " in the bookmark file: rc = %d\n",
1205 lfsck_lfsck2name(lfsck),
1206 PFID(lfsck_dto2fid(child)), rc);
1213 * Check whether the @child back references the @parent.
1216 * 1) The child's FID is stored in the bookmark file. If the child back
1217 * references the parent (LU_LPF_FID object) via its ".." entry, then
1218 * insert the name (MDTxxxx) to the .lustre/lost+found; otherwise, if
1219 * the child back references another parent2, then:
1220 * 1.1) If the parent2 recognizes the child, then update the bookmark file;
1221 * 1.2) Otherwise, the LFSCK cannot know whether there will be parent3 that
1222 * references the child. So keep them there. As the LFSCK processing,
1223 * the parent3 may be found, then when the LFSCK run next time, the
1224 * inconsistency can be repaired.
1226 * 2) The child's FID is stored in the .lustre/lost+found/ sub-directory name
1227 * entry (MDTxxxx). If the child back references the parent (LU_LPF_FID obj)
1228 * via its ".." entry, then update the bookmark file, otherwise, if the child
1229 * back references another parent2, then:
1230 * 2.1) If the parent2 recognizes the child, then remove the sub-directory
1231 * from .lustre/lost+found/;
1232 * 2.2) Otherwise, if the parent2 does not recognizes the child, trust the
1233 * sub-directory name entry and update the child;
1234 * 2.3) Otherwise, if we do not know whether the parent2 recognizes the child
1235 * or not, then keep them there.
1237 * \param[in] env pointer to the thread context
1238 * \param[in] lfsck pointer to the lfsck instance
1239 * \param[in] child pointer to the lost+found sub-directory object
1240 * \param[in] name the name for lost+found sub-directory object
1241 * \param[out] fid pointer to the buffer to hold the FID of the object
1242 * (called it as parent2) that is referenced via the
1243 * child's dotdot entry; it also can be the FID that
1244 * is referenced by the name entry under the parent2.
1245 * \param[in] type to indicate where the child's FID is stored in
1247 * \retval positive number for uncertain inconsistency
1248 * \retval 0 for success
1249 * \retval negative error number on failure
1251 static int lfsck_verify_lpf_pairs(const struct lu_env *env,
1252 struct lfsck_instance *lfsck,
1253 struct dt_object *child, const char *name,
1255 enum lfsck_verify_lpf_types type)
1257 struct dt_object *parent = lfsck->li_lpf_root_obj;
1258 struct lfsck_thread_info *info = lfsck_env_info(env);
1259 char *name2 = info->lti_key;
1260 struct lu_fid *fid2 = &info->lti_fid3;
1261 struct dt_object *parent2 = NULL;
1262 struct lustre_handle lh = { 0 };
1267 rc = dt_lookup_dir(env, child, dotdot, fid);
1271 if (!fid_is_sane(fid))
1272 GOTO(linkea, rc = -EINVAL);
1274 if (lu_fid_eq(fid, &LU_LPF_FID)) {
1275 const struct lu_name *cname;
1277 if (lfsck->li_lpf_obj == NULL) {
1278 lu_object_get(&child->do_lu);
1279 lfsck->li_lpf_obj = child;
1282 cname = lfsck_name_get_const(env, name, strlen(name));
1283 rc = lfsck_verify_linkea(env, child, cname, &LU_LPF_FID);
1285 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1291 parent2 = lfsck_object_find_bottom(env, lfsck, fid);
1292 if (IS_ERR(parent2))
1293 GOTO(linkea, parent2);
1295 if (!dt_object_exists(parent2)) {
1296 lfsck_object_put(env, parent2);
1298 GOTO(linkea, parent2 = ERR_PTR(-ENOENT));
1301 if (!dt_try_as_dir(env, parent2)) {
1302 lfsck_object_put(env, parent2);
1304 GOTO(linkea, parent2 = ERR_PTR(-ENOTDIR));
1308 /* To prevent rename/unlink race */
1309 rc = lfsck_ibits_lock(env, lfsck, child, &lh,
1310 MDS_INODELOCK_UPDATE, LCK_PR);
1314 dt_read_lock(env, child, 0);
1315 rc = lfsck_links_get_first(env, child, name2, fid2);
1317 dt_read_unlock(env, child);
1318 lfsck_ibits_unlock(&lh, LCK_PR);
1320 GOTO(out_put, rc = 1);
1323 /* It is almost impossible that the bookmark file (or the name entry)
1324 * and the linkEA hit the same data corruption. Trust the linkEA. */
1325 if (lu_fid_eq(fid2, &LU_LPF_FID) && strcmp(name, name2) == 0) {
1326 dt_read_unlock(env, child);
1327 lfsck_ibits_unlock(&lh, LCK_PR);
1330 if (lfsck->li_lpf_obj == NULL) {
1331 lu_object_get(&child->do_lu);
1332 lfsck->li_lpf_obj = child;
1335 /* Update the child's dotdot entry */
1336 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1337 &LU_LPF_FID, S_IFDIR);
1339 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1345 if (parent2 == NULL || IS_ERR(parent2)) {
1346 dt_read_unlock(env, child);
1347 lfsck_ibits_unlock(&lh, LCK_PR);
1349 GOTO(out_done, rc = 1);
1352 rc = dt_lookup_dir(env, parent2, name2, fid);
1353 dt_read_unlock(env, child);
1354 lfsck_ibits_unlock(&lh, LCK_PR);
1355 if (rc != 0 && rc != -ENOENT)
1358 if (rc == -ENOENT || !lu_fid_eq(fid, lfsck_dto2fid(child))) {
1359 if (type == LVLT_BY_BOOKMARK)
1360 GOTO(out_put, rc = 1);
1362 /* Trust the name entry, update the child's dotdot entry. */
1363 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1364 &LU_LPF_FID, S_IFDIR);
1369 if (type == LVLT_BY_BOOKMARK) {
1370 /* Invalid FID record in the bookmark file, reset it. */
1371 fid_zero(&lfsck->li_bookmark_ram.lb_lpf_fid);
1372 rc = lfsck_bookmark_store(env, lfsck);
1374 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1375 " in the bookmark file: rc = %d\n",
1376 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(child)), rc);
1377 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1378 /* The name entry is wrong, remove it. */
1379 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1385 if (parent2 != NULL && !IS_ERR(parent2))
1386 lfsck_object_put(env, parent2);
1393 * Verify the /ROOT/.lustre/lost+found/ directory.
1395 * /ROOT/.lustre/lost+found/ is a special directory to hold the objects that
1396 * the LFSCK does not exactly know how to handle, such as orphans. So before
1397 * the LFSCK scanning the system, the consistency of such directory needs to
1398 * be verified firstly to allow the users to use it during the LFSCK.
1400 * \param[in] env pointer to the thread context
1401 * \param[in] lfsck pointer to the lfsck instance
1403 * \retval positive number for uncertain inconsistency
1404 * \retval 0 for success
1405 * \retval negative error number on failure
1407 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
1409 struct lfsck_thread_info *info = lfsck_env_info(env);
1410 struct lu_fid *pfid = &info->lti_fid;
1411 struct lu_fid *cfid = &info->lti_fid2;
1412 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1413 struct dt_object *parent;
1414 /* child1's FID is in the bookmark file. */
1415 struct dt_object *child1 = NULL;
1416 /* child2's FID is in the name entry MDTxxxx. */
1417 struct dt_object *child2 = NULL;
1418 const struct lu_name *cname;
1420 int node = lfsck_dev_idx(lfsck);
1424 LASSERT(lfsck->li_master);
1426 if (lfsck_is_dryrun(lfsck))
1429 if (lfsck->li_lpf_root_obj != NULL)
1433 parent = lfsck_object_find_by_dev(env, lfsck->li_bottom,
1436 struct lfsck_tgt_desc *ltd;
1438 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
1439 if (unlikely(ltd == NULL))
1442 parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
1448 RETURN(PTR_ERR(parent));
1450 LASSERT(dt_object_exists(parent));
1452 if (unlikely(!dt_try_as_dir(env, parent))) {
1453 lfsck_object_put(env, parent);
1455 GOTO(put, rc = -ENOTDIR);
1458 lfsck->li_lpf_root_obj = parent;
1460 rc = lfsck_scan_lpf_bad_entries(env, lfsck);
1462 CDEBUG(D_LFSCK, "%s: scan .lustre/lost+found/ "
1463 "for bad sub-directories: rc = %d\n",
1464 lfsck_lfsck2name(lfsck), rc);
1468 snprintf(name, 8, "MDT%04x", node);
1469 rc = dt_lookup_dir(env, parent, name, cfid);
1470 if (rc == -ENOENT) {
1478 /* Invalid FID in the name entry, remove the name entry. */
1479 if (!fid_is_norm(cfid)) {
1480 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1487 child2 = lfsck_object_find_bottom(env, lfsck, cfid);
1489 GOTO(put, rc = PTR_ERR(child2));
1491 if (unlikely(!dt_object_exists(child2) ||
1492 dt_object_remote(child2)) ||
1493 !S_ISDIR(lfsck_object_type(child2))) {
1494 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1501 if (unlikely(!dt_try_as_dir(env, child2))) {
1502 lfsck_object_put(env, child2);
1508 if (fid_is_zero(&bk->lb_lpf_fid))
1511 if (likely(lu_fid_eq(cfid, &bk->lb_lpf_fid))) {
1512 if (lfsck->li_lpf_obj == NULL) {
1513 lu_object_get(&child2->do_lu);
1514 lfsck->li_lpf_obj = child2;
1517 cname = lfsck_name_get_const(env, name, strlen(name));
1518 rc = lfsck_verify_linkea(env, child2, cname, &LU_LPF_FID);
1523 if (unlikely(!fid_is_norm(&bk->lb_lpf_fid))) {
1524 struct lu_fid tfid = bk->lb_lpf_fid;
1526 /* Invalid FID record in the bookmark file, reset it. */
1527 fid_zero(&bk->lb_lpf_fid);
1528 rc = lfsck_bookmark_store(env, lfsck);
1530 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1531 " in the bookmark file: rc = %d\n",
1532 lfsck_lfsck2name(lfsck), PFID(&tfid), rc);
1540 child1 = lfsck_object_find_bottom(env, lfsck, &bk->lb_lpf_fid);
1541 if (IS_ERR(child1)) {
1546 if (unlikely(!dt_object_exists(child1) ||
1547 dt_object_remote(child1)) ||
1548 !S_ISDIR(lfsck_object_type(child1))) {
1549 /* Invalid FID record in the bookmark file, reset it. */
1550 fid_zero(&bk->lb_lpf_fid);
1551 rc = lfsck_bookmark_store(env, lfsck);
1553 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1554 " in the bookmark file: rc = %d\n",
1555 lfsck_lfsck2name(lfsck),
1556 PFID(lfsck_dto2fid(child1)), rc);
1561 lfsck_object_put(env, child1);
1566 if (unlikely(!dt_try_as_dir(env, child1))) {
1567 lfsck_object_put(env, child1);
1573 rc = lfsck_verify_lpf_pairs(env, lfsck, child1, name, pfid,
1575 if (lu_fid_eq(pfid, &LU_LPF_FID))
1580 rc = lfsck_verify_lpf_pairs(env, lfsck, child2, name,
1581 pfid, LVLT_BY_NAMEENTRY);
1586 if (lfsck->li_lpf_obj != NULL) {
1587 if (unlikely(!dt_try_as_dir(env, lfsck->li_lpf_obj))) {
1588 lfsck_object_put(env, lfsck->li_lpf_obj);
1589 lfsck->li_lpf_obj = NULL;
1592 } else if (rc == 0) {
1593 rc = lfsck_create_lpf(env, lfsck);
1596 if (child2 != NULL && !IS_ERR(child2))
1597 lfsck_object_put(env, child2);
1598 if (child1 != NULL && !IS_ERR(child1))
1599 lfsck_object_put(env, child1);
1604 static int lfsck_fid_init(struct lfsck_instance *lfsck)
1606 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1607 struct seq_server_site *ss = lfsck_dev_site(lfsck);
1612 if (unlikely(ss == NULL))
1615 OBD_ALLOC_PTR(lfsck->li_seq);
1616 if (lfsck->li_seq == NULL)
1619 OBD_ALLOC(prefix, MAX_OBD_NAME + 7);
1621 GOTO(out, rc = -ENOMEM);
1623 snprintf(prefix, MAX_OBD_NAME + 7, "lfsck-%s", lfsck_lfsck2name(lfsck));
1624 seq_client_init(lfsck->li_seq, NULL, LUSTRE_SEQ_METADATA, prefix,
1626 OBD_FREE(prefix, MAX_OBD_NAME + 7);
1628 if (fid_is_sane(&bk->lb_last_fid))
1629 lfsck->li_seq->lcs_fid = bk->lb_last_fid;
1634 OBD_FREE_PTR(lfsck->li_seq);
1635 lfsck->li_seq = NULL;
1640 static void lfsck_fid_fini(struct lfsck_instance *lfsck)
1642 if (lfsck->li_seq != NULL) {
1643 seq_client_fini(lfsck->li_seq);
1644 OBD_FREE_PTR(lfsck->li_seq);
1645 lfsck->li_seq = NULL;
1649 void lfsck_instance_cleanup(const struct lu_env *env,
1650 struct lfsck_instance *lfsck)
1652 struct ptlrpc_thread *thread = &lfsck->li_thread;
1653 struct lfsck_component *com;
1654 struct lfsck_component *next;
1655 struct lfsck_lmv_unit *llu;
1656 struct lfsck_lmv_unit *llu_next;
1657 struct lfsck_lmv *llmv;
1660 LASSERT(list_empty(&lfsck->li_link));
1661 LASSERT(thread_is_init(thread) || thread_is_stopped(thread));
1663 if (lfsck->li_obj_oit != NULL) {
1664 lfsck_object_put(env, lfsck->li_obj_oit);
1665 lfsck->li_obj_oit = NULL;
1668 LASSERT(lfsck->li_obj_dir == NULL);
1669 LASSERT(lfsck->li_lmv == NULL);
1671 list_for_each_entry_safe(llu, llu_next, &lfsck->li_list_lmv, llu_link) {
1672 llmv = &llu->llu_lmv;
1674 LASSERTF(atomic_read(&llmv->ll_ref) == 1,
1675 "still in using: %u\n",
1676 atomic_read(&llmv->ll_ref));
1678 lfsck_lmv_put(env, llmv);
1681 list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
1682 lfsck_component_cleanup(env, com);
1685 LASSERT(list_empty(&lfsck->li_list_dir));
1687 list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
1689 lfsck_component_cleanup(env, com);
1692 list_for_each_entry_safe(com, next, &lfsck->li_list_idle, lc_link) {
1693 lfsck_component_cleanup(env, com);
1696 lfsck_tgt_descs_fini(&lfsck->li_ost_descs);
1697 lfsck_tgt_descs_fini(&lfsck->li_mdt_descs);
1699 if (lfsck->li_lfsck_dir != NULL) {
1700 lfsck_object_put(env, lfsck->li_lfsck_dir);
1701 lfsck->li_lfsck_dir = NULL;
1704 if (lfsck->li_bookmark_obj != NULL) {
1705 lfsck_object_put(env, lfsck->li_bookmark_obj);
1706 lfsck->li_bookmark_obj = NULL;
1709 if (lfsck->li_lpf_obj != NULL) {
1710 lfsck_object_put(env, lfsck->li_lpf_obj);
1711 lfsck->li_lpf_obj = NULL;
1714 if (lfsck->li_lpf_root_obj != NULL) {
1715 lfsck_object_put(env, lfsck->li_lpf_root_obj);
1716 lfsck->li_lpf_root_obj = NULL;
1719 if (lfsck->li_los != NULL) {
1720 local_oid_storage_fini(env, lfsck->li_los);
1721 lfsck->li_los = NULL;
1724 lfsck_fid_fini(lfsck);
1726 OBD_FREE_PTR(lfsck);
1729 static inline struct lfsck_instance *
1730 __lfsck_instance_find(struct dt_device *key, bool ref, bool unlink)
1732 struct lfsck_instance *lfsck;
1734 list_for_each_entry(lfsck, &lfsck_instance_list, li_link) {
1735 if (lfsck->li_bottom == key) {
1737 lfsck_instance_get(lfsck);
1739 list_del_init(&lfsck->li_link);
1748 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
1751 struct lfsck_instance *lfsck;
1753 spin_lock(&lfsck_instance_lock);
1754 lfsck = __lfsck_instance_find(key, ref, unlink);
1755 spin_unlock(&lfsck_instance_lock);
1760 static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
1762 struct lfsck_instance *tmp;
1764 spin_lock(&lfsck_instance_lock);
1765 list_for_each_entry(tmp, &lfsck_instance_list, li_link) {
1766 if (lfsck->li_bottom == tmp->li_bottom) {
1767 spin_unlock(&lfsck_instance_lock);
1772 list_add_tail(&lfsck->li_link, &lfsck_instance_list);
1773 spin_unlock(&lfsck_instance_lock);
1777 void lfsck_bits_dump(struct seq_file *m, int bits, const char *const names[],
1782 bool newline = (bits != 0 ? false : true);
1784 seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
1786 for (i = 0, flag = 1; bits != 0; i++, flag = BIT(i)) {
1789 if (names[i] != NULL) {
1793 seq_printf(m, "%s%c", names[i],
1794 newline ? '\n' : ',');
1803 void lfsck_time_dump(struct seq_file *m, time64_t time, const char *name)
1806 seq_printf(m, "%s_time: N/A\n", name);
1807 seq_printf(m, "time_since_%s: N/A\n", name);
1809 seq_printf(m, "%s_time: %lld\n", name, time);
1810 seq_printf(m, "time_since_%s: %lld seconds\n",
1811 name, ktime_get_real_seconds() - time);
1815 void lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
1818 if (fid_is_zero(&pos->lp_dir_parent)) {
1819 if (pos->lp_oit_cookie == 0) {
1820 seq_printf(m, "%s: N/A, N/A, N/A\n", prefix);
1823 seq_printf(m, "%s: %llu, N/A, N/A\n",
1824 prefix, pos->lp_oit_cookie);
1826 seq_printf(m, "%s: %llu, "DFID", %#llx\n",
1827 prefix, pos->lp_oit_cookie,
1828 PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
1832 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
1833 struct lfsck_position *pos, bool init)
1835 const struct dt_it_ops *iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
1837 if (unlikely(lfsck->li_di_oit == NULL)) {
1838 memset(pos, 0, sizeof(*pos));
1842 pos->lp_oit_cookie = iops->store(env, lfsck->li_di_oit);
1843 if (!lfsck->li_current_oit_processed && !init)
1844 pos->lp_oit_cookie--;
1846 if (unlikely(pos->lp_oit_cookie == 0))
1847 pos->lp_oit_cookie = 1;
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;
1867 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
1871 if (limit != LFSCK_SPEED_NO_LIMIT) {
1872 if (limit > cfs_time_seconds(1)) {
1873 lfsck->li_sleep_rate = limit / cfs_time_seconds(1);
1874 lfsck->li_sleep_jif = 1;
1876 lfsck->li_sleep_rate = 1;
1877 lfsck->li_sleep_jif = cfs_time_seconds(1) / limit;
1880 lfsck->li_sleep_jif = 0;
1881 lfsck->li_sleep_rate = 0;
1884 if (lfsck->li_bookmark_ram.lb_speed_limit != limit) {
1885 lfsck->li_bookmark_ram.lb_speed_limit = limit;
1892 void lfsck_control_speed(struct lfsck_instance *lfsck)
1894 struct ptlrpc_thread *thread = &lfsck->li_thread;
1896 if (lfsck->li_sleep_jif > 0 &&
1897 lfsck->li_new_scanned >= lfsck->li_sleep_rate) {
1898 wait_event_idle_timeout(thread->t_ctl_waitq,
1899 !thread_is_running(thread),
1900 lfsck->li_sleep_jif);
1901 lfsck->li_new_scanned = 0;
1905 void lfsck_control_speed_by_self(struct lfsck_component *com)
1907 struct lfsck_instance *lfsck = com->lc_lfsck;
1908 struct ptlrpc_thread *thread = &lfsck->li_thread;
1910 if (lfsck->li_sleep_jif > 0 &&
1911 com->lc_new_scanned >= lfsck->li_sleep_rate) {
1912 wait_event_idle_timeout(thread->t_ctl_waitq,
1913 !thread_is_running(thread),
1914 lfsck->li_sleep_jif);
1915 com->lc_new_scanned = 0;
1919 static struct lfsck_thread_args *
1920 lfsck_thread_args_init(struct lfsck_instance *lfsck,
1921 struct lfsck_component *com,
1922 struct lfsck_start_param *lsp)
1924 struct lfsck_thread_args *lta;
1929 return ERR_PTR(-ENOMEM);
1931 rc = lu_env_init(<a->lta_env, LCT_MD_THREAD | LCT_DT_THREAD);
1937 lta->lta_lfsck = lfsck_instance_get(lfsck);
1939 lta->lta_com = lfsck_component_get(com);
1946 void lfsck_thread_args_fini(struct lfsck_thread_args *lta)
1948 if (lta->lta_com != NULL)
1949 lfsck_component_put(<a->lta_env, lta->lta_com);
1950 lfsck_instance_put(<a->lta_env, lta->lta_lfsck);
1951 lu_env_fini(<a->lta_env);
1955 struct lfsck_assistant_data *
1956 lfsck_assistant_data_init(const struct lfsck_assistant_operations *lao,
1959 struct lfsck_assistant_data *lad;
1963 lad->lad_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
1964 if (lad->lad_bitmap == NULL) {
1969 INIT_LIST_HEAD(&lad->lad_req_list);
1970 spin_lock_init(&lad->lad_lock);
1971 INIT_LIST_HEAD(&lad->lad_ost_list);
1972 INIT_LIST_HEAD(&lad->lad_ost_phase1_list);
1973 INIT_LIST_HEAD(&lad->lad_ost_phase2_list);
1974 INIT_LIST_HEAD(&lad->lad_mdt_list);
1975 INIT_LIST_HEAD(&lad->lad_mdt_phase1_list);
1976 INIT_LIST_HEAD(&lad->lad_mdt_phase2_list);
1977 init_waitqueue_head(&lad->lad_thread.t_ctl_waitq);
1979 lad->lad_name = name;
1985 struct lfsck_assistant_object *
1986 lfsck_assistant_object_init(const struct lu_env *env, const struct lu_fid *fid,
1987 const struct lu_attr *attr, __u64 cookie,
1990 struct lfsck_assistant_object *lso;
1994 return ERR_PTR(-ENOMEM);
1996 lso->lso_fid = *fid;
1998 lso->lso_attr = *attr;
2000 atomic_set(&lso->lso_ref, 1);
2001 lso->lso_oit_cookie = cookie;
2003 lso->lso_is_dir = 1;
2009 lfsck_assistant_object_load(const struct lu_env *env,
2010 struct lfsck_instance *lfsck,
2011 struct lfsck_assistant_object *lso)
2013 struct dt_object *obj;
2015 obj = lfsck_object_find_bottom(env, lfsck, &lso->lso_fid);
2019 if (unlikely(!dt_object_exists(obj) || lfsck_is_dead_obj(obj))) {
2021 lfsck_object_put(env, obj);
2023 return ERR_PTR(-ENOENT);
2026 if (lso->lso_is_dir && unlikely(!dt_try_as_dir(env, obj))) {
2027 lfsck_object_put(env, obj);
2029 return ERR_PTR(-ENOTDIR);
2036 * Generic LFSCK asynchronous communication interpretor function.
2037 * The LFSCK RPC reply for both the event notification and status
2038 * querying will be handled here.
2040 * \param[in] env pointer to the thread context
2041 * \param[in] req pointer to the LFSCK request
2042 * \param[in] args pointer to the lfsck_async_interpret_args
2043 * \param[in] rc the result for handling the LFSCK request
2045 * \retval 0 for success
2046 * \retval negative error number on failure
2048 int lfsck_async_interpret_common(const struct lu_env *env,
2049 struct ptlrpc_request *req,
2052 struct lfsck_async_interpret_args *laia = args;
2053 struct lfsck_component *com = laia->laia_com;
2054 struct lfsck_assistant_data *lad = com->lc_data;
2055 struct lfsck_tgt_descs *ltds = laia->laia_ltds;
2056 struct lfsck_tgt_desc *ltd = laia->laia_ltd;
2057 struct lfsck_request *lr = laia->laia_lr;
2059 LASSERT(com->lc_lfsck->li_master);
2061 switch (lr->lr_event) {
2063 if (unlikely(rc == -EINPROGRESS)) {
2064 ltd->ltd_retry_start = 1;
2069 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s "
2071 lfsck_lfsck2name(com->lc_lfsck),
2072 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2073 ltd->ltd_index, lad->lad_name, rc);
2075 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2076 struct lfsck_layout *lo = com->lc_file_ram;
2078 if (lr->lr_flags & LEF_TO_OST)
2079 lfsck_lad_set_bitmap(env, com,
2082 lo->ll_flags |= LF_INCOMPLETE;
2084 struct lfsck_namespace *ns = com->lc_file_ram;
2086 /* If some MDT does not join the namespace
2087 * LFSCK, then we cannot know whether there
2088 * is some name entry on such MDT that with
2089 * the referenced MDT-object on this MDT or
2090 * not. So the namespace LFSCK on this MDT
2091 * cannot handle orphan MDT-objects properly.
2092 * So we mark the LFSCK as LF_INCOMPLETE and
2093 * skip orphan MDT-objects handling. */
2094 ns->ln_flags |= LF_INCOMPLETE;
2099 spin_lock(<ds->ltd_lock);
2100 if (ltd->ltd_dead) {
2101 spin_unlock(<ds->ltd_lock);
2105 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2106 struct list_head *list;
2107 struct list_head *phase_list;
2109 if (ltd->ltd_layout_done) {
2110 spin_unlock(<ds->ltd_lock);
2114 if (lr->lr_flags & LEF_TO_OST) {
2115 list = &lad->lad_ost_list;
2116 phase_list = &lad->lad_ost_phase1_list;
2118 list = &lad->lad_mdt_list;
2119 phase_list = &lad->lad_mdt_phase1_list;
2122 if (list_empty(<d->ltd_layout_list))
2123 list_add_tail(<d->ltd_layout_list, list);
2124 if (list_empty(<d->ltd_layout_phase_list))
2125 list_add_tail(<d->ltd_layout_phase_list,
2128 if (ltd->ltd_namespace_done) {
2129 spin_unlock(<ds->ltd_lock);
2133 if (list_empty(<d->ltd_namespace_list))
2134 list_add_tail(<d->ltd_namespace_list,
2135 &lad->lad_mdt_list);
2136 if (list_empty(<d->ltd_namespace_phase_list))
2137 list_add_tail(<d->ltd_namespace_phase_list,
2138 &lad->lad_mdt_phase1_list);
2140 spin_unlock(<ds->ltd_lock);
2143 case LE_PHASE1_DONE:
2144 case LE_PHASE2_DONE:
2146 if (rc != 0 && rc != -EALREADY)
2147 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s: "
2148 "event = %d, rc = %d\n",
2149 lfsck_lfsck2name(com->lc_lfsck),
2150 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2151 ltd->ltd_index, lad->lad_name, lr->lr_event, rc);
2154 struct lfsck_reply *reply;
2155 struct list_head *list;
2156 struct list_head *phase_list;
2158 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2159 list = <d->ltd_layout_list;
2160 phase_list = <d->ltd_layout_phase_list;
2162 list = <d->ltd_namespace_list;
2163 phase_list = <d->ltd_namespace_phase_list;
2167 if (lr->lr_flags & LEF_QUERY_ALL) {
2168 lfsck_reset_ltd_status(ltd, com->lc_type);
2172 spin_lock(<ds->ltd_lock);
2173 list_del_init(phase_list);
2174 list_del_init(list);
2175 spin_unlock(<ds->ltd_lock);
2179 reply = req_capsule_server_get(&req->rq_pill,
2181 if (reply == NULL) {
2183 CDEBUG(D_LFSCK, "%s: invalid query reply for %s: "
2184 "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck),
2187 if (lr->lr_flags & LEF_QUERY_ALL) {
2188 lfsck_reset_ltd_status(ltd, com->lc_type);
2192 spin_lock(<ds->ltd_lock);
2193 list_del_init(phase_list);
2194 list_del_init(list);
2195 spin_unlock(<ds->ltd_lock);
2199 if (lr->lr_flags & LEF_QUERY_ALL) {
2200 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2201 ltd->ltd_layout_status = reply->lr_status;
2202 ltd->ltd_layout_repaired = reply->lr_repaired;
2204 ltd->ltd_namespace_status = reply->lr_status;
2205 ltd->ltd_namespace_repaired =
2211 switch (reply->lr_status) {
2212 case LS_SCANNING_PHASE1:
2214 case LS_SCANNING_PHASE2:
2215 spin_lock(<ds->ltd_lock);
2216 list_del_init(phase_list);
2217 if (ltd->ltd_dead) {
2218 spin_unlock(<ds->ltd_lock);
2222 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2223 if (ltd->ltd_layout_done) {
2224 spin_unlock(<ds->ltd_lock);
2228 if (lr->lr_flags & LEF_TO_OST)
2229 list_add_tail(phase_list,
2230 &lad->lad_ost_phase2_list);
2232 list_add_tail(phase_list,
2233 &lad->lad_mdt_phase2_list);
2235 if (ltd->ltd_namespace_done) {
2236 spin_unlock(<ds->ltd_lock);
2240 list_add_tail(phase_list,
2241 &lad->lad_mdt_phase2_list);
2243 spin_unlock(<ds->ltd_lock);
2246 spin_lock(<ds->ltd_lock);
2247 list_del_init(phase_list);
2248 list_del_init(list);
2249 spin_unlock(<ds->ltd_lock);
2255 CDEBUG(D_LFSCK, "%s: unexpected event: rc = %d\n",
2256 lfsck_lfsck2name(com->lc_lfsck), lr->lr_event);
2260 if (!laia->laia_shared) {
2262 lfsck_component_put(env, com);
2268 static void lfsck_interpret(const struct lu_env *env,
2269 struct lfsck_instance *lfsck,
2270 struct ptlrpc_request *req, void *args, int result)
2272 struct lfsck_async_interpret_args *laia = args;
2273 struct lfsck_component *com;
2275 LASSERT(laia->laia_com == NULL);
2276 LASSERT(laia->laia_shared);
2278 spin_lock(&lfsck->li_lock);
2279 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
2280 laia->laia_com = com;
2281 lfsck_async_interpret_common(env, req, laia, result);
2284 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
2285 laia->laia_com = com;
2286 lfsck_async_interpret_common(env, req, laia, result);
2288 spin_unlock(&lfsck->li_lock);
2291 static int lfsck_stop_notify(const struct lu_env *env,
2292 struct lfsck_instance *lfsck,
2293 struct lfsck_tgt_descs *ltds,
2294 struct lfsck_tgt_desc *ltd, __u16 type)
2296 struct lfsck_component *com;
2300 LASSERT(lfsck->li_master);
2302 spin_lock(&lfsck->li_lock);
2303 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
2305 com = __lfsck_component_find(lfsck, type,
2306 &lfsck->li_list_double_scan);
2308 lfsck_component_get(com);
2309 spin_unlock(&lfsck->li_lock);
2312 struct lfsck_thread_info *info = lfsck_env_info(env);
2313 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2314 struct lfsck_request *lr = &info->lti_lr;
2315 struct lfsck_assistant_data *lad = com->lc_data;
2316 struct list_head *list;
2317 struct list_head *phase_list;
2318 struct ptlrpc_request_set *set;
2320 set = ptlrpc_prep_set();
2322 lfsck_component_put(env, com);
2327 if (type == LFSCK_TYPE_LAYOUT) {
2328 list = <d->ltd_layout_list;
2329 phase_list = <d->ltd_layout_phase_list;
2331 list = <d->ltd_namespace_list;
2332 phase_list = <d->ltd_namespace_phase_list;
2335 spin_lock(<ds->ltd_lock);
2336 if (list_empty(list)) {
2337 LASSERT(list_empty(phase_list));
2338 spin_unlock(<ds->ltd_lock);
2339 ptlrpc_set_destroy(set);
2344 list_del_init(phase_list);
2345 list_del_init(list);
2346 spin_unlock(<ds->ltd_lock);
2348 memset(lr, 0, sizeof(*lr));
2349 lr->lr_index = lfsck_dev_idx(lfsck);
2350 lr->lr_event = LE_PEER_EXIT;
2351 lr->lr_active = type;
2352 lr->lr_status = LS_CO_PAUSED;
2353 if (ltds == &lfsck->li_ost_descs)
2354 lr->lr_flags = LEF_TO_OST;
2356 memset(laia, 0, sizeof(*laia));
2357 laia->laia_com = com;
2358 laia->laia_ltds = ltds;
2359 atomic_inc(<d->ltd_ref);
2360 laia->laia_ltd = ltd;
2363 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2364 lfsck_async_interpret_common,
2365 laia, LFSCK_NOTIFY);
2367 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for "
2368 "co-stop for %s: rc = %d\n",
2369 lfsck_lfsck2name(lfsck),
2370 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2371 ltd->ltd_index, lad->lad_name, rc);
2374 rc = ptlrpc_set_wait(env, set);
2377 ptlrpc_set_destroy(set);
2378 lfsck_component_put(env, com);
2384 static int lfsck_async_interpret(const struct lu_env *env,
2385 struct ptlrpc_request *req,
2388 struct lfsck_async_interpret_args *laia = args;
2389 struct lfsck_instance *lfsck;
2391 lfsck = container_of(laia->laia_ltds, struct lfsck_instance,
2393 lfsck_interpret(env, lfsck, req, laia, rc);
2394 lfsck_tgt_put(laia->laia_ltd);
2395 if (rc != 0 && laia->laia_result != -EALREADY)
2396 laia->laia_result = rc;
2401 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
2402 struct lfsck_request *lr,
2403 struct ptlrpc_request_set *set,
2404 ptlrpc_interpterer_t interpreter,
2405 void *args, int request)
2407 struct lfsck_async_interpret_args *laia;
2408 struct ptlrpc_request *req;
2409 struct lfsck_request *tmp;
2410 struct req_format *format;
2415 format = &RQF_LFSCK_NOTIFY;
2418 format = &RQF_LFSCK_QUERY;
2421 CDEBUG(D_LFSCK, "%s: unknown async request %d: rc = %d\n",
2422 exp->exp_obd->obd_name, request, -EINVAL);
2426 req = ptlrpc_request_alloc(class_exp2cliimp(exp), format);
2430 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, request);
2432 ptlrpc_request_free(req);
2437 tmp = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
2439 ptlrpc_request_set_replen(req);
2441 laia = ptlrpc_req_async_args(laia, req);
2442 *laia = *(struct lfsck_async_interpret_args *)args;
2443 if (laia->laia_com != NULL)
2444 lfsck_component_get(laia->laia_com);
2445 req->rq_interpret_reply = interpreter;
2446 req->rq_allow_intr = 1;
2447 req->rq_no_delay = 1;
2448 ptlrpc_set_add_req(set, req);
2453 int lfsck_query_all(const struct lu_env *env, struct lfsck_component *com)
2455 struct lfsck_thread_info *info = lfsck_env_info(env);
2456 struct lfsck_request *lr = &info->lti_lr;
2457 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2458 struct lfsck_instance *lfsck = com->lc_lfsck;
2459 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2460 struct lfsck_tgt_desc *ltd;
2461 struct ptlrpc_request_set *set;
2466 memset(lr, 0, sizeof(*lr));
2467 lr->lr_event = LE_QUERY;
2468 lr->lr_active = com->lc_type;
2469 lr->lr_flags = LEF_QUERY_ALL;
2471 memset(laia, 0, sizeof(*laia));
2472 laia->laia_com = com;
2475 set = ptlrpc_prep_set();
2480 laia->laia_ltds = ltds;
2481 down_read(<ds->ltd_rw_sem);
2482 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2483 ltd = lfsck_tgt_get(ltds, idx);
2484 LASSERT(ltd != NULL);
2486 laia->laia_ltd = ltd;
2487 up_read(<ds->ltd_rw_sem);
2488 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2489 lfsck_async_interpret_common,
2492 struct lfsck_assistant_data *lad = com->lc_data;
2494 CDEBUG(D_LFSCK, "%s: Fail to query %s %x for stat %s: "
2495 "rc = %d\n", lfsck_lfsck2name(lfsck),
2496 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2497 ltd->ltd_index, lad->lad_name, rc);
2498 lfsck_reset_ltd_status(ltd, com->lc_type);
2501 down_read(<ds->ltd_rw_sem);
2503 up_read(<ds->ltd_rw_sem);
2505 if (com->lc_type == LFSCK_TYPE_LAYOUT && !(lr->lr_flags & LEF_TO_OST)) {
2506 ltds = &lfsck->li_ost_descs;
2507 lr->lr_flags |= LEF_TO_OST;
2511 rc = ptlrpc_set_wait(env, set);
2512 ptlrpc_set_destroy(set);
2517 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
2518 struct lfsck_start_param *lsp)
2520 struct lfsck_instance *lfsck = com->lc_lfsck;
2521 struct lfsck_assistant_data *lad = com->lc_data;
2522 struct ptlrpc_thread *mthread = &lfsck->li_thread;
2523 struct ptlrpc_thread *athread = &lad->lad_thread;
2524 struct lfsck_thread_args *lta;
2525 struct task_struct *task;
2529 lad->lad_assistant_status = 0;
2530 lad->lad_post_result = 0;
2532 lad->lad_advance_lock = false;
2533 thread_set_flags(athread, 0);
2535 lta = lfsck_thread_args_init(lfsck, com, lsp);
2537 RETURN(PTR_ERR(lta));
2539 task = kthread_run(lfsck_assistant_engine, lta, lad->lad_name);
2542 CERROR("%s: cannot start LFSCK assistant thread for %s: "
2543 "rc = %d\n", lfsck_lfsck2name(lfsck), lad->lad_name, rc);
2544 lfsck_thread_args_fini(lta);
2546 wait_event_idle(mthread->t_ctl_waitq,
2547 thread_is_running(athread) ||
2548 thread_is_stopped(athread) ||
2549 !thread_is_starting(mthread));
2550 if (unlikely(!thread_is_starting(mthread)))
2551 /* stopped by race */
2553 else if (unlikely(!thread_is_running(athread)))
2554 rc = lad->lad_assistant_status;
2562 int lfsck_checkpoint_generic(const struct lu_env *env,
2563 struct lfsck_component *com)
2565 struct lfsck_assistant_data *lad = com->lc_data;
2566 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2567 struct ptlrpc_thread *athread = &lad->lad_thread;
2569 wait_event_idle(mthread->t_ctl_waitq,
2570 list_empty(&lad->lad_req_list) ||
2571 !thread_is_running(mthread) ||
2572 thread_is_stopped(athread));
2574 if (!thread_is_running(mthread) || thread_is_stopped(athread))
2575 return LFSCK_CHECKPOINT_SKIP;
2580 void lfsck_post_generic(const struct lu_env *env,
2581 struct lfsck_component *com, int *result)
2583 struct lfsck_assistant_data *lad = com->lc_data;
2584 struct ptlrpc_thread *athread = &lad->lad_thread;
2585 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2587 lad->lad_post_result = *result;
2589 set_bit(LAD_EXIT, &lad->lad_flags);
2590 set_bit(LAD_TO_POST, &lad->lad_flags);
2592 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s post, rc = %d\n",
2593 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2595 wake_up_all(&athread->t_ctl_waitq);
2596 wait_event_idle(mthread->t_ctl_waitq,
2597 (*result > 0 && list_empty(&lad->lad_req_list)) ||
2598 thread_is_stopped(athread));
2600 if (lad->lad_assistant_status < 0)
2601 *result = lad->lad_assistant_status;
2603 CDEBUG(D_LFSCK, "%s: the assistant has done %s post, rc = %d\n",
2604 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2607 int lfsck_double_scan_generic(const struct lu_env *env,
2608 struct lfsck_component *com, int status)
2610 struct lfsck_assistant_data *lad = com->lc_data;
2611 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2612 struct ptlrpc_thread *athread = &lad->lad_thread;
2614 if (status != LS_SCANNING_PHASE2)
2615 set_bit(LAD_EXIT, &lad->lad_flags);
2617 set_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags);
2619 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s double_scan, "
2621 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, status);
2623 wake_up_all(&athread->t_ctl_waitq);
2624 wait_event_idle(mthread->t_ctl_waitq,
2625 test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags) ||
2626 thread_is_stopped(athread));
2628 CDEBUG(D_LFSCK, "%s: the assistant has done %s double_scan, "
2629 "status %d\n", lfsck_lfsck2name(com->lc_lfsck), lad->lad_name,
2630 lad->lad_assistant_status);
2632 if (lad->lad_assistant_status < 0)
2633 return lad->lad_assistant_status;
2638 void lfsck_quit_generic(const struct lu_env *env,
2639 struct lfsck_component *com)
2641 struct lfsck_assistant_data *lad = com->lc_data;
2642 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2643 struct ptlrpc_thread *athread = &lad->lad_thread;
2645 set_bit(LAD_EXIT, &lad->lad_flags);
2646 wake_up_all(&athread->t_ctl_waitq);
2647 wait_event_idle(mthread->t_ctl_waitq,
2648 thread_is_init(athread) ||
2649 thread_is_stopped(athread));
2652 int lfsck_load_one_trace_file(const struct lu_env *env,
2653 struct lfsck_component *com,
2654 struct dt_object *parent,
2655 struct dt_object **child,
2656 const struct dt_index_features *ft,
2657 const char *name, bool reset)
2659 struct lfsck_instance *lfsck = com->lc_lfsck;
2660 struct dt_object *obj;
2664 if (*child != NULL) {
2666 const struct dt_it_ops *iops;
2667 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid3;
2673 rc = obj->do_ops->do_index_try(env, obj, ft);
2675 /* unlink by force */
2678 iops = &obj->do_index_ops->dio_it;
2679 it = iops->init(env, obj, 0);
2681 /* unlink by force */
2685 rc = iops->get(env, it, (const struct dt_key *)fid);
2687 rc = iops->next(env, it);
2690 iops->fini(env, it);
2692 /* "rc > 0" means the index file is empty. */
2696 /* The old index is not empty, remove it firstly. */
2697 rc = local_object_unlink(env, lfsck->li_bottom, parent, name);
2698 CDEBUG_LIMIT(rc ? D_ERROR : D_LFSCK,
2699 "%s: unlink lfsck sub trace file %s: rc = %d\n",
2700 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2705 lfsck_object_put(env, *child);
2712 obj = local_index_find_or_create(env, lfsck->li_los, parent, name,
2713 S_IFREG | S_IRUGO | S_IWUSR, ft);
2715 RETURN(PTR_ERR(obj));
2717 rc = obj->do_ops->do_index_try(env, obj, ft);
2719 lfsck_object_put(env, obj);
2720 CDEBUG(D_LFSCK, "%s: LFSCK fail to load "
2721 "sub trace file %s: rc = %d\n",
2722 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2730 int lfsck_load_sub_trace_files(const struct lu_env *env,
2731 struct lfsck_component *com,
2732 const struct dt_index_features *ft,
2733 const char *prefix, bool reset)
2735 char *name = lfsck_env_info(env)->lti_key;
2736 struct lfsck_sub_trace_obj *lsto;
2740 for (i = 0, rc = 0, lsto = &com->lc_sub_trace_objs[0];
2741 i < LFSCK_STF_COUNT && rc == 0; i++, lsto++) {
2742 snprintf(name, NAME_MAX, "%s_%02d", prefix, i);
2743 rc = lfsck_load_one_trace_file(env, com,
2744 com->lc_lfsck->li_lfsck_dir,
2745 &lsto->lsto_obj, ft, name, reset);
2751 /* external interfaces */
2752 int lfsck_get_speed(char *buf, struct dt_device *key)
2755 struct lfsck_instance *lfsck;
2759 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2763 lfsck = lfsck_instance_find(key, true, false);
2765 rc = sprintf(buf, "%u\n",
2766 lfsck->li_bookmark_ram.lb_speed_limit);
2767 lfsck_instance_put(&env, lfsck);
2776 EXPORT_SYMBOL(lfsck_get_speed);
2778 int lfsck_set_speed(struct dt_device *key, __u32 val)
2781 struct lfsck_instance *lfsck;
2785 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2789 lfsck = lfsck_instance_find(key, true, false);
2790 if (likely(lfsck != NULL)) {
2791 mutex_lock(&lfsck->li_mutex);
2792 if (__lfsck_set_speed(lfsck, val))
2793 rc = lfsck_bookmark_store(&env, lfsck);
2794 mutex_unlock(&lfsck->li_mutex);
2795 lfsck_instance_put(&env, lfsck);
2804 EXPORT_SYMBOL(lfsck_set_speed);
2806 int lfsck_get_windows(char *buf, struct dt_device *key)
2809 struct lfsck_instance *lfsck;
2813 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2817 lfsck = lfsck_instance_find(key, true, false);
2818 if (likely(lfsck != NULL)) {
2819 rc = sprintf(buf, "%u\n",
2820 lfsck->li_bookmark_ram.lb_async_windows);
2821 lfsck_instance_put(&env, lfsck);
2830 EXPORT_SYMBOL(lfsck_get_windows);
2832 int lfsck_set_windows(struct dt_device *key, unsigned int val)
2835 struct lfsck_instance *lfsck;
2839 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2843 lfsck = lfsck_instance_find(key, true, false);
2844 if (likely(lfsck != NULL)) {
2845 if (val < 1 || val > LFSCK_ASYNC_WIN_MAX) {
2846 CWARN("%s: invalid async windows size that may "
2847 "cause memory issues. The valid range is "
2849 lfsck_lfsck2name(lfsck), LFSCK_ASYNC_WIN_MAX);
2851 } else if (lfsck->li_bookmark_ram.lb_async_windows != val) {
2852 mutex_lock(&lfsck->li_mutex);
2853 lfsck->li_bookmark_ram.lb_async_windows = val;
2854 rc = lfsck_bookmark_store(&env, lfsck);
2855 mutex_unlock(&lfsck->li_mutex);
2857 lfsck_instance_put(&env, lfsck);
2866 EXPORT_SYMBOL(lfsck_set_windows);
2868 int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
2871 struct lfsck_instance *lfsck;
2872 struct lfsck_component *com;
2876 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2880 lfsck = lfsck_instance_find(key, true, false);
2881 if (likely(lfsck != NULL)) {
2882 com = lfsck_component_find(lfsck, type);
2883 if (likely(com != NULL)) {
2884 com->lc_ops->lfsck_dump(&env, com, m);
2885 lfsck_component_put(&env, com);
2890 lfsck_instance_put(&env, lfsck);
2899 EXPORT_SYMBOL(lfsck_dump);
2901 static int lfsck_stop_all(const struct lu_env *env,
2902 struct lfsck_instance *lfsck,
2903 struct lfsck_stop *stop)
2905 struct lfsck_thread_info *info = lfsck_env_info(env);
2906 struct lfsck_request *lr = &info->lti_lr;
2907 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2908 struct ptlrpc_request_set *set;
2909 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2910 struct lfsck_tgt_desc *ltd;
2911 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2917 LASSERT(stop->ls_flags & LPF_BROADCAST);
2919 set = ptlrpc_prep_set();
2920 if (unlikely(set == NULL))
2923 memset(lr, 0, sizeof(*lr));
2924 lr->lr_event = LE_STOP;
2925 lr->lr_index = lfsck_dev_idx(lfsck);
2926 lr->lr_status = stop->ls_status;
2927 lr->lr_version = bk->lb_version;
2928 lr->lr_active = LFSCK_TYPES_ALL;
2929 lr->lr_param = stop->ls_flags;
2931 memset(laia, 0, sizeof(*laia));
2932 laia->laia_ltds = ltds;
2934 laia->laia_shared = 1;
2936 down_read(<ds->ltd_rw_sem);
2937 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2938 ltd = lfsck_tgt_get(ltds, idx);
2939 LASSERT(ltd != NULL);
2941 laia->laia_ltd = ltd;
2942 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2943 lfsck_async_interpret, laia,
2946 lfsck_interpret(env, lfsck, NULL, laia, rc);
2948 CERROR("%s: cannot notify MDT %x for LFSCK stop: "
2949 "rc = %d\n", lfsck_lfsck2name(lfsck), idx, rc);
2953 up_read(<ds->ltd_rw_sem);
2955 rc = ptlrpc_set_wait(env, set);
2956 ptlrpc_set_destroy(set);
2959 rc = laia->laia_result;
2961 if (rc == -EALREADY)
2965 CERROR("%s: fail to stop LFSCK on some MDTs: rc = %d\n",
2966 lfsck_lfsck2name(lfsck), rc);
2968 RETURN(rc != 0 ? rc : rc1);
2971 static int lfsck_start_all(const struct lu_env *env,
2972 struct lfsck_instance *lfsck,
2973 struct lfsck_start *start)
2975 struct lfsck_thread_info *info = lfsck_env_info(env);
2976 struct lfsck_request *lr = &info->lti_lr;
2977 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2978 struct ptlrpc_request_set *set;
2979 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2980 struct lfsck_tgt_desc *ltd;
2981 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2987 LASSERT(start->ls_flags & LPF_BROADCAST);
2989 memset(lr, 0, sizeof(*lr));
2990 lr->lr_event = LE_START;
2991 lr->lr_index = lfsck_dev_idx(lfsck);
2992 lr->lr_speed = bk->lb_speed_limit;
2993 lr->lr_version = bk->lb_version;
2994 lr->lr_active = start->ls_active;
2995 lr->lr_param = start->ls_flags;
2996 lr->lr_async_windows = bk->lb_async_windows;
2997 lr->lr_valid = LSV_SPEED_LIMIT | LSV_ERROR_HANDLE | LSV_DRYRUN |
2998 LSV_ASYNC_WINDOWS | LSV_CREATE_OSTOBJ |
3001 memset(laia, 0, sizeof(*laia));
3002 laia->laia_ltds = ltds;
3004 laia->laia_shared = 1;
3007 set = ptlrpc_prep_set();
3011 down_read(<ds->ltd_rw_sem);
3012 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3013 ltd = lfsck_tgt_get(ltds, idx);
3014 LASSERT(ltd != NULL);
3016 if (retry && !ltd->ltd_retry_start) {
3021 laia->laia_ltd = ltd;
3022 ltd->ltd_retry_start = 0;
3023 ltd->ltd_layout_done = 0;
3024 ltd->ltd_namespace_done = 0;
3025 ltd->ltd_synced_failures = 0;
3026 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
3027 lfsck_async_interpret, laia,
3030 lfsck_interpret(env, lfsck, NULL, laia, rc);
3032 CERROR("%s: cannot notify MDT %x for LFSCK "
3033 "start, failout: rc = %d\n",
3034 lfsck_lfsck2name(lfsck), idx, rc);
3038 up_read(<ds->ltd_rw_sem);
3041 ptlrpc_set_destroy(set);
3046 rc = ptlrpc_set_wait(env, set);
3047 ptlrpc_set_destroy(set);
3050 rc = laia->laia_result;
3052 if (unlikely(rc == -EINPROGRESS)) {
3054 schedule_timeout_interruptible(cfs_time_seconds(1));
3055 set_current_state(TASK_RUNNING);
3056 if (!signal_pending(current) &&
3057 thread_is_running(&lfsck->li_thread))
3064 struct lfsck_stop *stop = &info->lti_stop;
3066 CERROR("%s: cannot start LFSCK on some MDTs, "
3067 "stop all: rc = %d\n",
3068 lfsck_lfsck2name(lfsck), rc);
3069 if (rc != -EALREADY) {
3070 stop->ls_status = LS_FAILED;
3071 stop->ls_flags = LPF_ALL_TGT | LPF_BROADCAST;
3072 lfsck_stop_all(env, lfsck, stop);
3079 int lfsck_start(const struct lu_env *env, struct dt_device *key,
3080 struct lfsck_start_param *lsp)
3082 struct lfsck_start *start = lsp->lsp_start;
3083 struct lfsck_instance *lfsck;
3084 struct lfsck_bookmark *bk;
3085 struct ptlrpc_thread *thread;
3086 struct lfsck_component *com;
3087 struct lfsck_thread_args *lta;
3088 struct task_struct *task;
3089 struct lfsck_tgt_descs *ltds;
3090 struct lfsck_tgt_desc *ltd;
3101 lfsck = lfsck_instance_find(key, true, false);
3102 if (unlikely(lfsck == NULL))
3105 if (unlikely(lfsck->li_stopping))
3106 GOTO(put, rc = -ENXIO);
3108 /* System is not ready, try again later. */
3109 if (unlikely(lfsck->li_namespace == NULL ||
3110 lfsck_dev_site(lfsck)->ss_server_fld == NULL))
3111 GOTO(put, rc = -EINPROGRESS);
3113 /* start == NULL means auto trigger paused LFSCK. */
3115 if (list_empty(&lfsck->li_list_scan) ||
3116 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AUTO))
3118 } else if (start->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3119 CERROR("%s: only allow to specify '-A | -o' via MDS\n",
3120 lfsck_lfsck2name(lfsck));
3122 GOTO(put, rc = -EPERM);
3125 bk = &lfsck->li_bookmark_ram;
3126 thread = &lfsck->li_thread;
3127 mutex_lock(&lfsck->li_mutex);
3128 spin_lock(&lfsck->li_lock);
3129 if (unlikely(thread_is_stopping(thread))) {
3130 /* Someone is stopping the LFSCK. */
3131 spin_unlock(&lfsck->li_lock);
3132 GOTO(out, rc = -EBUSY);
3135 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
3137 if (unlikely(start == NULL)) {
3138 spin_unlock(&lfsck->li_lock);
3142 while (start->ls_active != 0) {
3143 if (!(type & start->ls_active)) {
3148 com = __lfsck_component_find(lfsck, type,
3149 &lfsck->li_list_scan);
3151 com = __lfsck_component_find(lfsck, type,
3152 &lfsck->li_list_double_scan);
3158 if (com->lc_ops->lfsck_join != NULL) {
3159 rc = com->lc_ops->lfsck_join( env, com, lsp);
3160 if (rc != 0 && rc != -EALREADY)
3163 start->ls_active &= ~type;
3166 spin_unlock(&lfsck->li_lock);
3169 spin_unlock(&lfsck->li_lock);
3171 lfsck->li_status = 0;
3172 lfsck->li_oit_over = 0;
3173 lfsck->li_start_unplug = 0;
3174 lfsck->li_drop_dryrun = 0;
3175 lfsck->li_new_scanned = 0;
3177 /* For auto trigger. */
3181 start->ls_version = bk->lb_version;
3183 if (start->ls_active != 0) {
3184 struct lfsck_component *next;
3186 if (start->ls_active == LFSCK_TYPES_ALL)
3187 start->ls_active = LFSCK_TYPES_SUPPORTED;
3189 if (start->ls_active & ~LFSCK_TYPES_SUPPORTED) {
3190 start->ls_active &= ~LFSCK_TYPES_SUPPORTED;
3191 GOTO(out, rc = -ENOTSUPP);
3194 list_for_each_entry_safe(com, next,
3195 &lfsck->li_list_scan, lc_link) {
3196 if (!(com->lc_type & start->ls_active)) {
3197 rc = com->lc_ops->lfsck_post(env, com, 0,
3204 while (start->ls_active != 0) {
3205 if (type & start->ls_active) {
3206 com = __lfsck_component_find(lfsck, type,
3207 &lfsck->li_list_idle);
3209 /* The component status will be updated
3210 * when its prep() is called later by
3211 * the LFSCK main engine. */
3212 list_move_tail(&com->lc_link,
3213 &lfsck->li_list_scan);
3214 start->ls_active &= ~type;
3220 if (list_empty(&lfsck->li_list_scan)) {
3221 /* The speed limit will be used to control both the LFSCK and
3222 * low layer scrub (if applied), need to be handled firstly. */
3223 if (start->ls_valid & LSV_SPEED_LIMIT) {
3224 if (__lfsck_set_speed(lfsck, start->ls_speed_limit)) {
3225 rc = lfsck_bookmark_store(env, lfsck);
3234 if (start->ls_flags & LPF_RESET)
3235 flags |= DOIF_RESET;
3237 rc = lfsck_set_param(env, lfsck, start, !!(flags & DOIF_RESET));
3241 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3242 start->ls_active |= com->lc_type;
3243 if (flags & DOIF_RESET) {
3244 rc = com->lc_ops->lfsck_reset(env, com, false);
3250 ltds = &lfsck->li_mdt_descs;
3251 down_read(<ds->ltd_rw_sem);
3252 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3253 ltd = lfsck_ltd2tgt(ltds, idx);
3254 LASSERT(ltd != NULL);
3256 ltd->ltd_layout_done = 0;
3257 ltd->ltd_namespace_done = 0;
3258 ltd->ltd_synced_failures = 0;
3259 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_NAMESPACE);
3260 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3261 list_del_init(<d->ltd_layout_phase_list);
3262 list_del_init(<d->ltd_layout_list);
3263 list_del_init(<d->ltd_namespace_phase_list);
3264 list_del_init(<d->ltd_namespace_list);
3266 up_read(<ds->ltd_rw_sem);
3268 ltds = &lfsck->li_ost_descs;
3269 down_read(<ds->ltd_rw_sem);
3270 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
3271 ltd = lfsck_ltd2tgt(ltds, idx);
3272 LASSERT(ltd != NULL);
3274 ltd->ltd_layout_done = 0;
3275 ltd->ltd_synced_failures = 0;
3276 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3277 list_del_init(<d->ltd_layout_phase_list);
3278 list_del_init(<d->ltd_layout_list);
3280 up_read(<ds->ltd_rw_sem);
3283 lfsck->li_args_dir = LUDA_64BITHASH | LUDA_VERIFY | LUDA_TYPE;
3284 if (bk->lb_param & LPF_DRYRUN)
3285 lfsck->li_args_dir |= LUDA_VERIFY_DRYRUN;
3287 if (start != NULL && start->ls_valid & LSV_ERROR_HANDLE) {
3288 valid |= DOIV_ERROR_HANDLE;
3289 if (start->ls_flags & LPF_FAILOUT)
3290 flags |= DOIF_FAILOUT;
3293 if (start != NULL && start->ls_valid & LSV_DRYRUN) {
3294 valid |= DOIV_DRYRUN;
3295 if (start->ls_flags & LPF_DRYRUN)
3296 flags |= DOIF_DRYRUN;
3299 if (!list_empty(&lfsck->li_list_scan))
3300 flags |= DOIF_OUTUSED;
3302 lfsck->li_args_oit = (flags << DT_OTABLE_IT_FLAGS_SHIFT) | valid;
3303 lta = lfsck_thread_args_init(lfsck, NULL, lsp);
3305 GOTO(out, rc = PTR_ERR(lta));
3307 __lfsck_set_speed(lfsck, bk->lb_speed_limit);
3308 spin_lock(&lfsck->li_lock);
3309 thread_set_flags(thread, SVC_STARTING);
3310 spin_unlock(&lfsck->li_lock);
3311 task = kthread_run(lfsck_master_engine, lta, "lfsck");
3314 CERROR("%s: cannot start LFSCK thread: rc = %d\n",
3315 lfsck_lfsck2name(lfsck), rc);
3316 lfsck_thread_args_fini(lta);
3321 wait_event_idle(thread->t_ctl_waitq,
3322 thread_is_running(thread) ||
3323 thread_is_stopped(thread));
3324 if (start == NULL || !(start->ls_flags & LPF_BROADCAST)) {
3325 lfsck->li_start_unplug = 1;
3326 wake_up_all(&thread->t_ctl_waitq);
3331 /* release lfsck::li_mutex to avoid deadlock. */
3332 mutex_unlock(&lfsck->li_mutex);
3333 rc = lfsck_start_all(env, lfsck, start);
3335 spin_lock(&lfsck->li_lock);
3336 if (thread_is_stopped(thread)) {
3337 spin_unlock(&lfsck->li_lock);
3339 lfsck->li_status = LS_FAILED;
3340 lfsck->li_flags = 0;
3341 thread_set_flags(thread, SVC_STOPPING);
3342 spin_unlock(&lfsck->li_lock);
3344 lfsck->li_start_unplug = 1;
3345 wake_up_all(&thread->t_ctl_waitq);
3346 wait_event_idle(thread->t_ctl_waitq,
3347 thread_is_stopped(thread));
3350 lfsck->li_start_unplug = 1;
3351 wake_up_all(&thread->t_ctl_waitq);
3357 mutex_unlock(&lfsck->li_mutex);
3360 lfsck_instance_put(env, lfsck);
3362 return rc < 0 ? rc : 0;
3364 EXPORT_SYMBOL(lfsck_start);
3366 int lfsck_stop(const struct lu_env *env, struct dt_device *key,
3367 struct lfsck_stop *stop)
3369 struct lfsck_instance *lfsck;
3370 struct ptlrpc_thread *thread;
3375 lfsck = lfsck_instance_find(key, true, false);
3376 if (unlikely(lfsck == NULL))
3379 thread = &lfsck->li_thread;
3380 if (stop && stop->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3381 CERROR("%s: only allow to specify '-A' via MDS\n",
3382 lfsck_lfsck2name(lfsck));
3383 GOTO(put, rc = -EPERM);
3386 spin_lock(&lfsck->li_lock);
3387 /* The target is umounted */
3388 if (stop && stop->ls_status == LS_PAUSED)
3389 lfsck->li_stopping = 1;
3391 if (thread_is_init(thread) || thread_is_stopped(thread))
3392 /* no error if LFSCK stopped already, or not started */
3393 GOTO(unlock, rc = 0);
3395 if (thread_is_stopping(thread))
3396 /* Someone is stopping LFSCK. */
3397 GOTO(unlock, rc = -EINPROGRESS);
3400 lfsck->li_status = stop->ls_status;
3401 lfsck->li_flags = stop->ls_flags;
3403 lfsck->li_status = LS_STOPPED;
3404 lfsck->li_flags = 0;
3407 thread_set_flags(thread, SVC_STOPPING);
3409 LASSERT(lfsck->li_task != NULL);
3410 cfs_force_sig(SIGINT, lfsck->li_task);
3412 if (lfsck->li_master) {
3413 struct lfsck_component *com;
3414 struct lfsck_assistant_data *lad;
3416 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3418 spin_lock(&lad->lad_lock);
3419 if (lad->lad_task != NULL)
3420 cfs_force_sig(SIGINT, lad->lad_task);
3421 spin_unlock(&lad->lad_lock);
3424 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
3426 spin_lock(&lad->lad_lock);
3427 if (lad->lad_task != NULL)
3428 cfs_force_sig(SIGINT, lad->lad_task);
3429 spin_unlock(&lad->lad_lock);
3433 wake_up_all(&thread->t_ctl_waitq);
3434 spin_unlock(&lfsck->li_lock);
3435 if (stop && stop->ls_flags & LPF_BROADCAST)
3436 rc1 = lfsck_stop_all(env, lfsck, stop);
3438 /* It was me set the status as 'stopping' just now, if it is not
3439 * 'stopping' now, then either stopped, or re-started by race. */
3440 wait_event_idle(thread->t_ctl_waitq,
3441 !thread_is_stopping(thread));
3446 spin_unlock(&lfsck->li_lock);
3448 lfsck_instance_put(env, lfsck);
3450 return rc != 0 ? rc : rc1;
3452 EXPORT_SYMBOL(lfsck_stop);
3454 int lfsck_in_notify_local(const struct lu_env *env, struct dt_device *key,
3455 struct lfsck_req_local *lrl, struct thandle *th)
3457 struct lfsck_instance *lfsck;
3458 struct lfsck_component *com;
3459 int rc = -EOPNOTSUPP;
3462 lfsck = lfsck_instance_find(key, true, false);
3463 if (unlikely(!lfsck))
3466 com = lfsck_component_find(lfsck, lrl->lrl_active);
3467 if (likely(com && com->lc_ops->lfsck_in_notify_local)) {
3468 rc = com->lc_ops->lfsck_in_notify_local(env, com, lrl, th);
3469 lfsck_component_put(env, com);
3472 lfsck_instance_put(env, lfsck);
3476 EXPORT_SYMBOL(lfsck_in_notify_local);
3478 int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
3479 struct lfsck_request *lr)
3481 int rc = -EOPNOTSUPP;
3484 switch (lr->lr_event) {
3486 struct lfsck_start *start = &lfsck_env_info(env)->lti_start;
3487 struct lfsck_start_param lsp;
3489 memset(start, 0, sizeof(*start));
3490 start->ls_valid = lr->lr_valid;
3491 start->ls_speed_limit = lr->lr_speed;
3492 start->ls_version = lr->lr_version;
3493 start->ls_active = lr->lr_active;
3494 start->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3495 start->ls_async_windows = lr->lr_async_windows;
3497 lsp.lsp_start = start;
3498 lsp.lsp_index = lr->lr_index;
3499 lsp.lsp_index_valid = 1;
3500 rc = lfsck_start(env, key, &lsp);
3504 struct lfsck_stop *stop = &lfsck_env_info(env)->lti_stop;
3506 memset(stop, 0, sizeof(*stop));
3507 stop->ls_status = lr->lr_status;
3508 stop->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3509 rc = lfsck_stop(env, key, stop);
3512 case LE_PHASE1_DONE:
3513 case LE_PHASE2_DONE:
3515 case LE_CONDITIONAL_DESTROY:
3516 case LE_SET_LMV_MASTER:
3517 case LE_SET_LMV_SLAVE:
3518 case LE_PAIRS_VERIFY: {
3519 struct lfsck_instance *lfsck;
3520 struct lfsck_component *com;
3522 lfsck = lfsck_instance_find(key, true, false);
3523 if (unlikely(lfsck == NULL))
3526 com = lfsck_component_find(lfsck, lr->lr_active);
3528 rc = com->lc_ops->lfsck_in_notify(env, com, lr);
3529 lfsck_component_put(env, com);
3532 lfsck_instance_put(env, lfsck);
3541 EXPORT_SYMBOL(lfsck_in_notify);
3543 int lfsck_query(const struct lu_env *env, struct dt_device *key,
3544 struct lfsck_request *req, struct lfsck_reply *rep,
3545 struct lfsck_query *que)
3547 struct lfsck_instance *lfsck;
3548 struct lfsck_component *com;
3554 lfsck = lfsck_instance_find(key, true, false);
3555 if (unlikely(lfsck == NULL))
3559 if (que->lu_types == LFSCK_TYPES_ALL)
3561 LFSCK_TYPES_SUPPORTED & ~LFSCK_TYPE_SCRUB;
3563 if (que->lu_types & ~LFSCK_TYPES_SUPPORTED) {
3564 que->lu_types &= ~LFSCK_TYPES_SUPPORTED;
3566 GOTO(out, rc = -ENOTSUPP);
3569 for (i = 0, type = BIT(i); i < LFSCK_TYPE_BITS;
3570 i++, type = BIT(i)) {
3571 if (!(que->lu_types & type))
3575 com = lfsck_component_find(lfsck, type);
3576 if (unlikely(com == NULL))
3577 GOTO(out, rc = -ENOTSUPP);
3579 memset(que->lu_mdts_count[i], 0,
3580 sizeof(__u32) * (LS_MAX + 1));
3581 memset(que->lu_osts_count[i], 0,
3582 sizeof(__u32) * (LS_MAX + 1));
3583 que->lu_repaired[i] = 0;
3584 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3586 lfsck_component_put(env, com);
3591 if (!(que->lu_flags & LPF_WAIT))
3594 for (i = 0, type = BIT(i); i < LFSCK_TYPE_BITS;
3595 i++, type = BIT(i)) {
3596 if (!(que->lu_types & type))
3599 if (que->lu_mdts_count[i][LS_SCANNING_PHASE1] != 0 ||
3600 que->lu_mdts_count[i][LS_SCANNING_PHASE2] != 0 ||
3601 que->lu_osts_count[i][LS_SCANNING_PHASE1] != 0 ||
3602 que->lu_osts_count[i][LS_SCANNING_PHASE2] != 0) {
3603 /* If it is required to wait, then sleep
3604 * 3 seconds and try to query again.
3606 unsigned long timeout =
3607 msecs_to_jiffies(3000) + 1;
3609 !fatal_signal_pending(current))
3610 timeout = schedule_timeout_killable(
3617 com = lfsck_component_find(lfsck, req->lr_active);
3618 if (likely(com != NULL)) {
3619 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3621 lfsck_component_put(env, com);
3630 lfsck_instance_put(env, lfsck);
3633 EXPORT_SYMBOL(lfsck_query);
3635 int lfsck_register_namespace(const struct lu_env *env, struct dt_device *key,
3636 struct ldlm_namespace *ns)
3638 struct lfsck_instance *lfsck;
3641 lfsck = lfsck_instance_find(key, true, false);
3642 if (likely(lfsck != NULL)) {
3643 lfsck->li_namespace = ns;
3644 lfsck_instance_put(env, lfsck);
3650 EXPORT_SYMBOL(lfsck_register_namespace);
3652 int lfsck_register(const struct lu_env *env, struct dt_device *key,
3653 struct dt_device *next, struct obd_device *obd,
3654 lfsck_out_notify notify, void *notify_data, bool master)
3656 struct lfsck_instance *lfsck;
3657 struct dt_object *root = NULL;
3658 struct dt_object *obj = NULL;
3659 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
3663 lfsck = lfsck_instance_find(key, false, false);
3664 if (unlikely(lfsck != NULL))
3667 OBD_ALLOC_PTR(lfsck);
3671 mutex_init(&lfsck->li_mutex);
3672 spin_lock_init(&lfsck->li_lock);
3673 INIT_LIST_HEAD(&lfsck->li_link);
3674 INIT_LIST_HEAD(&lfsck->li_list_scan);
3675 INIT_LIST_HEAD(&lfsck->li_list_dir);
3676 INIT_LIST_HEAD(&lfsck->li_list_double_scan);
3677 INIT_LIST_HEAD(&lfsck->li_list_idle);
3678 INIT_LIST_HEAD(&lfsck->li_list_lmv);
3679 atomic_set(&lfsck->li_ref, 1);
3680 atomic_set(&lfsck->li_double_scan_count, 0);
3681 init_waitqueue_head(&lfsck->li_thread.t_ctl_waitq);
3682 lfsck->li_out_notify = notify;
3683 lfsck->li_out_notify_data = notify_data;
3684 lfsck->li_next = next;
3685 lfsck->li_bottom = key;
3686 lfsck->li_obd = obd;
3688 rc = lfsck_tgt_descs_init(&lfsck->li_ost_descs);
3692 rc = lfsck_tgt_descs_init(&lfsck->li_mdt_descs);
3696 fid->f_seq = FID_SEQ_LOCAL_NAME;
3699 rc = local_oid_storage_init(env, key, fid, &lfsck->li_los);
3703 rc = dt_root_get(env, key, fid);
3707 root = dt_locate(env, key, fid);
3709 GOTO(out, rc = PTR_ERR(root));
3711 lfsck->li_local_root_fid = *fid;
3713 lfsck->li_master = 1;
3714 if (lfsck_dev_idx(lfsck) == 0) {
3715 struct lu_fid *pfid = &lfsck_env_info(env)->lti_fid2;
3716 const struct lu_name *cname;
3718 rc = dt_lookup_dir(env, root, "ROOT",
3719 &lfsck->li_global_root_fid);
3723 obj = dt_locate(env, key, &lfsck->li_global_root_fid);
3725 GOTO(out, rc = PTR_ERR(obj));
3727 rc = dt_lookup_dir(env, obj, dotlustre, fid);
3731 lfsck_object_put(env, obj);
3732 obj = dt_locate(env, key, fid);
3734 GOTO(out, rc = PTR_ERR(obj));
3736 cname = lfsck_name_get_const(env, dotlustre,
3738 rc = lfsck_verify_linkea(env, obj, cname,
3739 &lfsck->li_global_root_fid);
3743 if (unlikely(!dt_try_as_dir(env, obj)))
3744 GOTO(out, rc = -ENOTDIR);
3747 rc = dt_lookup_dir(env, obj, lostfound, fid);
3751 lfsck_object_put(env, obj);
3752 obj = dt_locate(env, key, fid);
3754 GOTO(out, rc = PTR_ERR(obj));
3756 cname = lfsck_name_get_const(env, lostfound,
3758 rc = lfsck_verify_linkea(env, obj, cname, pfid);
3762 lfsck_object_put(env, obj);
3767 fid->f_seq = FID_SEQ_LOCAL_FILE;
3768 fid->f_oid = OTABLE_IT_OID;
3770 obj = dt_locate(env, key, fid);
3772 GOTO(out, rc = PTR_ERR(obj));
3774 rc = obj->do_ops->do_index_try(env, obj, &dt_otable_features);
3778 lfsck->li_obj_oit = obj;
3779 obj = local_file_find_or_create(env, lfsck->li_los, root, LFSCK_DIR,
3780 S_IFDIR | S_IRUGO | S_IWUSR);
3782 GOTO(out, rc = PTR_ERR(obj));
3784 lu_object_get(&obj->do_lu);
3785 lfsck->li_lfsck_dir = obj;
3786 rc = lfsck_bookmark_setup(env, lfsck);
3791 rc = lfsck_fid_init(lfsck);
3795 rc = lfsck_namespace_setup(env, lfsck);
3800 rc = lfsck_layout_setup(env, lfsck);
3804 /* XXX: more LFSCK components initialization to be added here. */
3806 rc = lfsck_instance_add(lfsck);
3808 rc = lfsck_add_target_from_orphan(env, lfsck);
3810 if (obj != NULL && !IS_ERR(obj))
3811 lfsck_object_put(env, obj);
3812 if (root != NULL && !IS_ERR(root))
3813 lfsck_object_put(env, root);
3815 lfsck_instance_cleanup(env, lfsck);
3818 EXPORT_SYMBOL(lfsck_register);
3820 void lfsck_degister(const struct lu_env *env, struct dt_device *key)
3822 struct lfsck_instance *lfsck;
3824 lfsck = lfsck_instance_find(key, false, true);
3826 lfsck_instance_put(env, lfsck);
3828 EXPORT_SYMBOL(lfsck_degister);
3830 int lfsck_add_target(const struct lu_env *env, struct dt_device *key,
3831 struct dt_device *tgt, struct obd_export *exp,
3832 __u32 index, bool for_ost)
3834 struct lfsck_instance *lfsck;
3835 struct lfsck_tgt_desc *ltd;
3846 INIT_LIST_HEAD(<d->ltd_orphan_list);
3847 INIT_LIST_HEAD(<d->ltd_layout_list);
3848 INIT_LIST_HEAD(<d->ltd_layout_phase_list);
3849 INIT_LIST_HEAD(<d->ltd_namespace_list);
3850 INIT_LIST_HEAD(<d->ltd_namespace_phase_list);
3851 atomic_set(<d->ltd_ref, 1);
3852 ltd->ltd_index = index;
3854 spin_lock(&lfsck_instance_lock);
3855 lfsck = __lfsck_instance_find(key, true, false);
3856 if (lfsck == NULL) {
3858 list_add_tail(<d->ltd_orphan_list,
3859 &lfsck_ost_orphan_list);
3861 list_add_tail(<d->ltd_orphan_list,
3862 &lfsck_mdt_orphan_list);
3863 spin_unlock(&lfsck_instance_lock);
3867 spin_unlock(&lfsck_instance_lock);
3869 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, false);
3873 lfsck_instance_put(env, lfsck);
3877 EXPORT_SYMBOL(lfsck_add_target);
3879 void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
3880 struct dt_device *tgt, __u32 index, bool for_ost)
3882 struct lfsck_instance *lfsck;
3883 struct lfsck_tgt_descs *ltds;
3884 struct lfsck_tgt_desc *ltd;
3885 struct list_head *head;
3888 head = &lfsck_ost_orphan_list;
3890 head = &lfsck_mdt_orphan_list;
3892 spin_lock(&lfsck_instance_lock);
3893 list_for_each_entry(ltd, head, ltd_orphan_list) {
3894 if (ltd->ltd_tgt == tgt) {
3895 list_del_init(<d->ltd_orphan_list);
3896 spin_unlock(&lfsck_instance_lock);
3904 lfsck = __lfsck_instance_find(key, true, false);
3905 spin_unlock(&lfsck_instance_lock);
3906 if (unlikely(lfsck == NULL))
3910 ltds = &lfsck->li_ost_descs;
3912 ltds = &lfsck->li_mdt_descs;
3914 down_write(<ds->ltd_rw_sem);
3915 LASSERT(ltds->ltd_tgts_bitmap != NULL);
3917 if (unlikely(index >= ltds->ltd_tgts_bitmap->size))
3920 ltd = lfsck_ltd2tgt(ltds, index);
3921 if (unlikely(ltd == NULL))
3924 LASSERT(ltds->ltd_tgtnr > 0);
3927 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, index);
3928 lfsck_assign_tgt(ltds, NULL, index);
3933 head = &lfsck->li_ost_descs.ltd_orphan;
3935 head = &lfsck->li_mdt_descs.ltd_orphan;
3937 list_for_each_entry(ltd, head, ltd_orphan_list) {
3938 if (ltd->ltd_tgt == tgt) {
3939 list_del_init(<d->ltd_orphan_list);
3945 up_write(<ds->ltd_rw_sem);
3947 spin_lock(<ds->ltd_lock);
3949 spin_unlock(<ds->ltd_lock);
3950 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_NAMESPACE);
3951 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_LAYOUT);
3955 lfsck_instance_put(env, lfsck);
3957 EXPORT_SYMBOL(lfsck_del_target);
3959 static int __init lfsck_init(void)
3963 lfsck_key_init_generic(&lfsck_thread_key, NULL);
3964 rc = lu_context_key_register(&lfsck_thread_key);
3966 tgt_register_lfsck_in_notify_local(lfsck_in_notify_local);
3967 tgt_register_lfsck_in_notify(lfsck_in_notify);
3968 tgt_register_lfsck_query(lfsck_query);
3974 static void __exit lfsck_exit(void)
3976 struct lfsck_tgt_desc *ltd;
3977 struct lfsck_tgt_desc *next;
3979 LASSERT(list_empty(&lfsck_instance_list));
3981 list_for_each_entry_safe(ltd, next, &lfsck_ost_orphan_list,
3983 list_del_init(<d->ltd_orphan_list);
3987 list_for_each_entry_safe(ltd, next, &lfsck_mdt_orphan_list,
3989 list_del_init(<d->ltd_orphan_list);
3993 lu_context_key_degister(&lfsck_thread_key);
3996 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3997 MODULE_DESCRIPTION("Lustre File System Checker");
3998 MODULE_VERSION(LUSTRE_VERSION_STRING);
3999 MODULE_LICENSE("GPL");
4001 module_init(lfsck_init);
4002 module_exit(lfsck_exit);