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 = bitmap_zalloc(BITS_PER_LONG, GFP_KERNEL);
117 if (!ltds->ltd_tgts_bitmap)
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)) {
138 up_write(<ds->ltd_rw_sem);
143 for_each_set_bit(idx, ltds->ltd_tgts_bitmap, ltds->ltd_tgts_mask_len) {
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 clear_bit(idx, ltds->ltd_tgts_bitmap);
153 lfsck_assign_tgt(ltds, NULL, idx);
158 LASSERTF(ltds->ltd_tgtnr == 0, "tgt count unmatched: %d\n",
161 for (idx = 0; idx < ARRAY_SIZE(ltds->ltd_tgts_idx); idx++) {
162 if (ltds->ltd_tgts_idx[idx] != NULL) {
163 OBD_FREE_PTR(ltds->ltd_tgts_idx[idx]);
164 ltds->ltd_tgts_idx[idx] = NULL;
168 bitmap_free(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);
193 if (index >= ltds->ltd_tgts_mask_len) {
194 u32 newsize = max_t(u32, ltds->ltd_tgts_mask_len,
196 unsigned long *old_bitmap = ltds->ltd_tgts_bitmap;
197 unsigned long *new_bitmap;
199 while (newsize < index + 1)
202 new_bitmap = bitmap_zalloc(newsize, GFP_KERNEL);
204 GOTO(unlock, rc = -ENOMEM);
206 if (ltds->ltd_tgtnr > 0) {
207 bitmap_copy(new_bitmap, old_bitmap,
208 ltds->ltd_tgts_mask_len);
210 ltds->ltd_tgts_bitmap = new_bitmap;
211 ltds->ltd_tgts_mask_len = newsize;
212 bitmap_free(old_bitmap);
215 if (test_bit(index, ltds->ltd_tgts_bitmap)) {
216 CERROR("%s: the device %s (%u) is registered already\n",
217 lfsck_lfsck2name(lfsck),
218 ltd->ltd_tgt->dd_lu_dev.ld_obd->obd_name, index);
219 GOTO(unlock, rc = -EEXIST);
222 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
223 OBD_ALLOC_PTR(ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK]);
224 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL)
225 GOTO(unlock, rc = -ENOMEM);
228 lfsck_assign_tgt(ltds, ltd, index);
229 set_bit(index, ltds->ltd_tgts_bitmap);
232 GOTO(unlock, rc = 0);
236 up_write(<ds->ltd_rw_sem);
241 static int lfsck_add_target_from_orphan(const struct lu_env *env,
242 struct lfsck_instance *lfsck)
244 struct lfsck_tgt_descs *ltds = &lfsck->li_ost_descs;
245 struct lfsck_tgt_desc *ltd;
246 struct lfsck_tgt_desc *next;
247 struct list_head *head = &lfsck_ost_orphan_list;
252 spin_lock(&lfsck_instance_lock);
253 list_for_each_entry_safe(ltd, next, head, ltd_orphan_list) {
254 if (ltd->ltd_key == lfsck->li_bottom)
255 list_move_tail(<d->ltd_orphan_list,
258 spin_unlock(&lfsck_instance_lock);
260 down_write(<ds->ltd_rw_sem);
261 while (!list_empty(<ds->ltd_orphan)) {
262 ltd = list_entry(ltds->ltd_orphan.next,
263 struct lfsck_tgt_desc,
265 list_del_init(<d->ltd_orphan_list);
266 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, true);
267 /* Do not hold the semaphore for too long time. */
268 up_write(<ds->ltd_rw_sem);
272 down_write(<ds->ltd_rw_sem);
274 up_write(<ds->ltd_rw_sem);
277 ltds = &lfsck->li_mdt_descs;
278 head = &lfsck_mdt_orphan_list;
286 static inline struct lfsck_component *
287 __lfsck_component_find(struct lfsck_instance *lfsck, __u16 type,
288 struct list_head *list)
290 struct lfsck_component *com;
292 list_for_each_entry(com, list, lc_link) {
293 if (com->lc_type == type)
299 struct lfsck_component *
300 lfsck_component_find(struct lfsck_instance *lfsck, __u16 type)
302 struct lfsck_component *com;
304 spin_lock(&lfsck->li_lock);
305 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
309 com = __lfsck_component_find(lfsck, type,
310 &lfsck->li_list_double_scan);
314 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_idle);
318 lfsck_component_get(com);
319 spin_unlock(&lfsck->li_lock);
323 void lfsck_component_cleanup(const struct lu_env *env,
324 struct lfsck_component *com)
326 if (!list_empty(&com->lc_link))
327 list_del_init(&com->lc_link);
328 if (!list_empty(&com->lc_link_dir))
329 list_del_init(&com->lc_link_dir);
331 lfsck_component_put(env, com);
334 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
335 struct lu_fid *fid, bool locked)
337 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
342 mutex_lock(&lfsck->li_mutex);
344 rc = seq_client_alloc_fid(env, lfsck->li_seq, fid);
346 bk->lb_last_fid = *fid;
347 /* We do not care about whether the subsequent sub-operations
348 * failed or not. The worst case is that one FID is lost that
349 * is not a big issue for the LFSCK since it is relative rare
350 * for LFSCK create. */
351 rc = lfsck_bookmark_store(env, lfsck);
355 mutex_unlock(&lfsck->li_mutex);
360 static int __lfsck_ibits_lock(const struct lu_env *env,
361 struct lfsck_instance *lfsck,
362 struct dt_object *obj, struct ldlm_res_id *resid,
363 struct lustre_handle *lh, __u64 bits,
366 struct lfsck_thread_info *info = lfsck_env_info(env);
367 union ldlm_policy_data *policy = &info->lti_policy;
368 __u64 flags = LDLM_FL_ATOMIC_CB;
371 LASSERT(lfsck->li_namespace != NULL);
373 memset(policy, 0, sizeof(*policy));
374 policy->l_inodebits.bits = bits;
375 if (dt_object_remote(obj)) {
376 struct ldlm_enqueue_info *einfo = &info->lti_einfo;
378 memset(einfo, 0, sizeof(*einfo));
379 einfo->ei_type = LDLM_IBITS;
380 einfo->ei_mode = mode;
381 einfo->ei_cb_bl = ldlm_blocking_ast;
382 einfo->ei_cb_cp = ldlm_completion_ast;
383 einfo->ei_res_id = resid;
384 einfo->ei_req_slot = 1;
386 rc = dt_object_lock(env, obj, lh, einfo, policy);
387 /* for regular checks LFSCK doesn't use LDLM locking,
388 * so the state isn't coherent. here we just took LDLM
389 * lock for coherency and it's time to invalidate
392 dt_invalidate(env, obj);
394 rc = ldlm_cli_enqueue_local(env, lfsck->li_namespace, resid,
395 LDLM_IBITS, policy, mode,
396 &flags, ldlm_blocking_ast,
397 ldlm_completion_ast, NULL, NULL,
398 0, LVB_T_NONE, NULL, lh);
401 if (rc == ELDLM_OK) {
404 memset(lh, 0, sizeof(*lh));
412 * Request the specified ibits lock for the given object.
414 * Before the LFSCK modifying on the namespace visible object,
415 * it needs to acquire related ibits ldlm lock.
417 * \param[in] env pointer to the thread context
418 * \param[in] lfsck pointer to the lfsck instance
419 * \param[in] obj pointer to the dt_object to be locked
420 * \param[out] lh pointer to the lock handle
421 * \param[in] bits the bits for the ldlm lock to be acquired
422 * \param[in] mode the mode for the ldlm lock to be acquired
424 * \retval 0 for success
425 * \retval negative error number on failure
427 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
428 struct dt_object *obj, struct lustre_handle *lh,
429 __u64 bits, enum ldlm_mode mode)
431 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
433 LASSERT(!lustre_handle_is_used(lh));
435 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
436 return __lfsck_ibits_lock(env, lfsck, obj, resid, lh, bits, mode);
440 * Request the remote LOOKUP lock for the given object.
442 * If \a pobj is remote, the LOOKUP lock of \a obj is on the MDT where
443 * \a pobj is, acquire LOOKUP lock there.
445 * \param[in] env pointer to the thread context
446 * \param[in] lfsck pointer to the lfsck instance
447 * \param[in] pobj pointer to parent dt_object
448 * \param[in] obj pointer to the dt_object to be locked
449 * \param[out] lh pointer to the lock handle
450 * \param[in] mode the mode for the ldlm lock to be acquired
452 * \retval 0 for success
453 * \retval negative error number on failure
455 int lfsck_remote_lookup_lock(const struct lu_env *env,
456 struct lfsck_instance *lfsck,
457 struct dt_object *pobj, struct dt_object *obj,
458 struct lustre_handle *lh, enum ldlm_mode mode)
460 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
462 LASSERT(!lustre_handle_is_used(lh));
464 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
465 return __lfsck_ibits_lock(env, lfsck, pobj, resid, lh,
466 MDS_INODELOCK_LOOKUP, mode);
470 * Release the the specified ibits lock.
472 * If the lock has been acquired before, release it
473 * and cleanup the handle. Otherwise, do nothing.
475 * \param[in] lh pointer to the lock handle
476 * \param[in] mode the mode for the ldlm lock to be released
478 void lfsck_ibits_unlock(struct lustre_handle *lh, enum ldlm_mode mode)
480 if (lustre_handle_is_used(lh)) {
481 ldlm_lock_decref(lh, mode);
482 memset(lh, 0, sizeof(*lh));
487 * Request compound ibits locks for the given <obj, name> pairs.
489 * Before the LFSCK modifying on the namespace visible object, it needs to
490 * acquire related ibits ldlm lock. Usually, we can use lfsck_ibits_lock for
491 * the lock purpose. But the simple lfsck_ibits_lock for directory-based
492 * modificationis (such as insert name entry to the directory) may be too
493 * coarse-grained and not efficient.
495 * The lfsck_lock() will request compound ibits locks on the specified
496 * <obj, name> pairs: the PDO (Parallel Directory Operations) ibits (UPDATE)
497 * lock on the directory object, and the regular ibits lock on the name hash.
499 * \param[in] env pointer to the thread context
500 * \param[in] lfsck pointer to the lfsck instance
501 * \param[in] obj pointer to the dt_object to be locked
502 * \param[in] name used for building the PDO lock resource
503 * \param[out] llh pointer to the lfsck_lock_handle
504 * \param[in] bits the bits for the ldlm lock to be acquired
505 * \param[in] mode the mode for the ldlm lock to be acquired
507 * \retval 0 for success
508 * \retval negative error number on failure
510 int lfsck_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
511 struct dt_object *obj, const char *name,
512 struct lfsck_lock_handle *llh, __u64 bits, enum ldlm_mode mode)
514 struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
517 LASSERT(S_ISDIR(lfsck_object_type(obj)));
518 LASSERT(name != NULL);
519 LASSERT(name[0] != 0);
520 LASSERT(!lustre_handle_is_used(&llh->llh_pdo_lh));
521 LASSERT(!lustre_handle_is_used(&llh->llh_reg_lh));
525 llh->llh_pdo_mode = LCK_EX;
528 llh->llh_pdo_mode = LCK_CW;
531 llh->llh_pdo_mode = LCK_CR;
534 CDEBUG(D_LFSCK, "%s: unexpected PDO lock mode %u on the obj "
535 DFID"\n", lfsck_lfsck2name(lfsck), mode,
536 PFID(lfsck_dto2fid(obj)));
540 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
541 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_pdo_lh,
542 MDS_INODELOCK_UPDATE, llh->llh_pdo_mode);
546 llh->llh_reg_mode = mode;
547 resid->name[LUSTRE_RES_ID_HSH_OFF] = ll_full_name_hash(NULL, name,
549 LASSERT(resid->name[LUSTRE_RES_ID_HSH_OFF] != 0);
550 rc = __lfsck_ibits_lock(env, lfsck, obj, resid, &llh->llh_reg_lh,
551 bits, llh->llh_reg_mode);
553 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
559 * Release the the compound ibits locks.
561 * \param[in] llh pointer to the lfsck_lock_handle to be released
563 void lfsck_unlock(struct lfsck_lock_handle *llh)
565 lfsck_ibits_unlock(&llh->llh_reg_lh, llh->llh_reg_mode);
566 lfsck_ibits_unlock(&llh->llh_pdo_lh, llh->llh_pdo_mode);
569 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
570 struct lfsck_instance *lfsck,
571 const struct lu_fid *fid)
573 struct seq_server_site *ss = lfsck_dev_site(lfsck);
574 struct lu_seq_range *range = &lfsck_env_info(env)->lti_range;
577 if (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE)) {
578 /* "ROOT" is always on the MDT0. */
579 if (lu_fid_eq(fid, &lfsck->li_global_root_fid))
582 return lfsck_dev_idx(lfsck);
585 fld_range_set_mdt(range);
586 rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
588 rc = range->lsr_index;
593 const char dot[] = ".";
594 const char dotdot[] = "..";
595 static const char dotlustre[] = ".lustre";
596 static const char lostfound[] = "lost+found";
599 * Remove the name entry from the .lustre/lost+found directory.
601 * No need to care about the object referenced by the name entry,
602 * either the name entry is invalid or redundant, or the referenced
603 * object has been processed or will be handled by others.
605 * \param[in] env pointer to the thread context
606 * \param[in] lfsck pointer to the lfsck instance
607 * \param[in] name the name for the name entry to be removed
609 * \retval 0 for success
610 * \retval negative error number on failure
612 static int lfsck_lpf_remove_name_entry(const struct lu_env *env,
613 struct lfsck_instance *lfsck,
616 struct dt_object *parent = lfsck->li_lpf_root_obj;
617 struct dt_device *dev = lfsck_obj2dev(parent);
619 struct lfsck_lock_handle *llh = &lfsck_env_info(env)->lti_llh;
623 rc = lfsck_lock(env, lfsck, parent, name, llh,
624 MDS_INODELOCK_UPDATE, LCK_PW);
628 th = lfsck_trans_create(env, dev, lfsck);
630 GOTO(unlock, rc = PTR_ERR(th));
632 rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
636 rc = dt_declare_ref_del(env, parent, th);
640 rc = dt_trans_start_local(env, dev, th);
644 rc = dt_delete(env, parent, (const struct dt_key *)name, th);
648 dt_write_lock(env, parent, 0);
649 rc = dt_ref_del(env, parent, th);
650 dt_write_unlock(env, parent);
655 dt_trans_stop(env, dev, th);
660 CDEBUG(D_LFSCK, "%s: remove name entry "DFID"/%s: rc = %d\n",
661 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(parent)), name, rc);
666 static int lfsck_create_lpf_local(const struct lu_env *env,
667 struct lfsck_instance *lfsck,
668 struct dt_object *child,
670 struct dt_object_format *dof,
673 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
674 struct dt_object *parent = lfsck->li_lpf_root_obj;
675 struct dt_device *dev = lfsck_obj2dev(child);
676 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
677 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
678 const struct lu_fid *cfid = lfsck_dto2fid(child);
679 struct thandle *th = NULL;
680 struct linkea_data ldata = { NULL };
681 struct lu_buf linkea_buf;
682 const struct lu_name *cname;
684 int len = sizeof(struct lfsck_bookmark);
688 cname = lfsck_name_get_const(env, name, strlen(name));
689 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
690 cname, lfsck_dto2fid(parent));
694 th = lfsck_trans_create(env, dev, lfsck);
698 /* 1a. create child */
699 rc = dt_declare_create(env, child, la, NULL, dof, th);
703 if (!dt_try_as_dir(env, child, false))
704 GOTO(stop, rc = -ENOTDIR);
706 /* 2a. increase child nlink */
707 rc = dt_declare_ref_add(env, child, th);
711 /* 3a. insert dot into child dir */
712 rec->rec_type = S_IFDIR;
714 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
715 (const struct dt_key *)dot, th);
719 /* 4a. insert dotdot into child dir */
720 rec->rec_fid = &LU_LPF_FID;
721 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
722 (const struct dt_key *)dotdot, th);
726 /* 5a. insert linkEA for child */
727 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
728 ldata.ld_leh->leh_len);
729 rc = dt_declare_xattr_set(env, child, &linkea_buf,
730 XATTR_NAME_LINK, 0, th);
734 /* 6a. insert name into parent dir */
735 rec->rec_type = S_IFDIR;
737 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
738 (const struct dt_key *)name, th);
742 /* 7a. increase parent nlink */
743 rc = dt_declare_ref_add(env, parent, th);
747 /* 8a. update bookmark */
748 rc = dt_declare_record_write(env, bk_obj,
749 lfsck_buf_get(env, bk, len), 0, th);
753 rc = dt_trans_start_local(env, dev, th);
757 dt_write_lock(env, child, 0);
758 /* 1b. create child */
759 rc = dt_create(env, child, la, NULL, dof, th);
763 /* 2b. increase child nlink */
764 rc = dt_ref_add(env, child, th);
768 /* 3b. insert dot into child dir */
770 rc = dt_insert(env, child, (const struct dt_rec *)rec,
771 (const struct dt_key *)dot, th);
775 /* 4b. insert dotdot into child dir */
776 rec->rec_fid = &LU_LPF_FID;
777 rc = dt_insert(env, child, (const struct dt_rec *)rec,
778 (const struct dt_key *)dotdot, th);
782 /* 5b. insert linkEA for child. */
783 rc = dt_xattr_set(env, child, &linkea_buf,
784 XATTR_NAME_LINK, 0, th);
785 dt_write_unlock(env, child);
789 /* 6b. insert name into parent dir */
791 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
792 (const struct dt_key *)name, th);
796 dt_write_lock(env, parent, 0);
797 /* 7b. increase parent nlink */
798 rc = dt_ref_add(env, parent, th);
799 dt_write_unlock(env, parent);
803 bk->lb_lpf_fid = *cfid;
804 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
806 /* 8b. update bookmark */
807 rc = dt_record_write(env, bk_obj,
808 lfsck_buf_get(env, bk, len), &pos, th);
813 dt_write_unlock(env, child);
816 dt_trans_stop(env, dev, th);
821 static int lfsck_create_lpf_remote(const struct lu_env *env,
822 struct lfsck_instance *lfsck,
823 struct dt_object *child,
825 struct dt_object_format *dof,
828 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
829 struct dt_object *parent = lfsck->li_lpf_root_obj;
830 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
831 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
832 const struct lu_fid *cfid = lfsck_dto2fid(child);
833 struct thandle *th = NULL;
834 struct linkea_data ldata = { NULL };
835 struct lu_buf linkea_buf;
836 const struct lu_name *cname;
837 struct dt_device *dev;
839 int len = sizeof(struct lfsck_bookmark);
843 cname = lfsck_name_get_const(env, name, strlen(name));
844 rc = linkea_links_new(&ldata, &lfsck_env_info(env)->lti_linkea_buf2,
845 cname, lfsck_dto2fid(parent));
849 /* Create .lustre/lost+found/MDTxxxx. */
851 /* XXX: Currently, cross-MDT create operation needs to create the child
852 * object firstly, then insert name into the parent directory. For
853 * this case, the child object resides on current MDT (local), but
854 * the parent ".lustre/lost+found" may be on remote MDT. It is not
855 * easy to contain all the sub-modifications orderly within single
858 * To avoid more inconsistency, we split the create operation into
861 * 1) create the child and update the lfsck_bookmark::lb_lpf_fid
863 * 2) insert the name "MDTXXXX" in the parent ".lustre/lost+found"
866 * If 1) done, but 2) failed, then go ahead, the LFSCK will try to
867 * repair such inconsistency when LFSCK run next time. */
869 /* Transaction I: locally */
871 dev = lfsck_obj2dev(child);
872 th = lfsck_trans_create(env, dev, lfsck);
876 /* 1a. create child */
877 rc = dt_declare_create(env, child, la, NULL, dof, th);
881 if (!dt_try_as_dir(env, child, false))
882 GOTO(stop, rc = -ENOTDIR);
884 /* 2a. increase child nlink */
885 rc = dt_declare_ref_add(env, child, th);
889 /* 3a. insert dot into child dir */
890 rec->rec_type = S_IFDIR;
892 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
893 (const struct dt_key *)dot, th);
897 /* 4a. insert dotdot into child dir */
898 rec->rec_fid = &LU_LPF_FID;
899 rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
900 (const struct dt_key *)dotdot, th);
904 /* 5a. insert linkEA for child */
905 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
906 ldata.ld_leh->leh_len);
907 rc = dt_declare_xattr_set(env, child, &linkea_buf,
908 XATTR_NAME_LINK, 0, th);
912 /* 6a. update bookmark */
913 rc = dt_declare_record_write(env, bk_obj,
914 lfsck_buf_get(env, bk, len), 0, th);
918 rc = dt_trans_start_local(env, dev, th);
922 dt_write_lock(env, child, 0);
923 /* 1b. create child */
924 rc = dt_create(env, child, la, NULL, dof, th);
928 /* 2b. increase child nlink */
929 rc = dt_ref_add(env, child, th);
933 /* 3b. insert dot into child dir */
934 rec->rec_type = S_IFDIR;
936 rc = dt_insert(env, child, (const struct dt_rec *)rec,
937 (const struct dt_key *)dot, th);
941 /* 4b. insert dotdot into child dir */
942 rec->rec_fid = &LU_LPF_FID;
943 rc = dt_insert(env, child, (const struct dt_rec *)rec,
944 (const struct dt_key *)dotdot, th);
948 /* 5b. insert linkEA for child */
949 rc = dt_xattr_set(env, child, &linkea_buf,
950 XATTR_NAME_LINK, 0, th);
954 bk->lb_lpf_fid = *cfid;
955 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
957 /* 6b. update bookmark */
958 rc = dt_record_write(env, bk_obj,
959 lfsck_buf_get(env, bk, len), &pos, th);
961 dt_write_unlock(env, child);
962 dt_trans_stop(env, dev, th);
966 /* Transaction II: remotely */
968 dev = lfsck_obj2dev(parent);
969 th = lfsck_trans_create(env, dev, lfsck);
974 /* 5a. insert name into parent dir */
976 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
977 (const struct dt_key *)name, th);
981 /* 6a. increase parent nlink */
982 rc = dt_declare_ref_add(env, parent, th);
986 rc = dt_trans_start_local(env, dev, th);
990 /* 5b. insert name into parent dir */
991 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
992 (const struct dt_key *)name, th);
996 dt_write_lock(env, parent, 0);
997 /* 6b. increase parent nlink */
998 rc = dt_ref_add(env, parent, th);
999 dt_write_unlock(env, parent);
1004 dt_write_unlock(env, child);
1006 dt_trans_stop(env, dev, th);
1008 if (rc != 0 && dev == lfsck_obj2dev(parent))
1009 CDEBUG(D_LFSCK, "%s: partially created the object "DFID
1010 "for orphans, but failed to insert the name %s "
1011 "to the .lustre/lost+found/. Such inconsistency "
1012 "will be repaired when LFSCK run next time: rc = %d\n",
1013 lfsck_lfsck2name(lfsck), PFID(cfid), name, rc);
1019 * Create the MDTxxxx directory under /ROOT/.lustre/lost+found/
1021 * The /ROOT/.lustre/lost+found/MDTxxxx/ directory is used for holding
1022 * orphans and other uncertain inconsistent objects found during the
1023 * LFSCK. Such directory will be created by the LFSCK engine on the
1024 * local MDT before the LFSCK scanning.
1026 * \param[in] env pointer to the thread context
1027 * \param[in] lfsck pointer to the lfsck instance
1029 * \retval 0 for success
1030 * \retval negative error number on failure
1032 static int lfsck_create_lpf(const struct lu_env *env,
1033 struct lfsck_instance *lfsck)
1035 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1036 struct lfsck_thread_info *info = lfsck_env_info(env);
1037 struct lu_fid *cfid = &info->lti_fid2;
1038 struct lu_attr *la = &info->lti_la;
1039 struct dt_object_format *dof = &info->lti_dof;
1040 struct dt_object *parent = lfsck->li_lpf_root_obj;
1041 struct dt_object *child = NULL;
1042 struct lfsck_lock_handle *llh = &info->lti_llh;
1044 int node = lfsck_dev_idx(lfsck);
1048 LASSERT(lfsck->li_master);
1049 LASSERT(parent != NULL);
1050 LASSERT(lfsck->li_lpf_obj == NULL);
1052 snprintf(name, 8, "MDT%04x", node);
1053 rc = lfsck_lock(env, lfsck, parent, name, llh,
1054 MDS_INODELOCK_UPDATE, LCK_PW);
1058 if (fid_is_zero(&bk->lb_lpf_fid)) {
1059 /* There is corner case that: in former LFSCK scanning we have
1060 * created the .lustre/lost+found/MDTxxxx but failed to update
1061 * the lfsck_bookmark::lb_lpf_fid successfully. So need lookup
1062 * it from MDT0 firstly. */
1063 rc = dt_lookup_dir(env, parent, name, cfid);
1064 if (rc != 0 && rc != -ENOENT)
1068 bk->lb_lpf_fid = *cfid;
1069 rc = lfsck_bookmark_store(env, lfsck);
1071 rc = lfsck_fid_alloc(env, lfsck, cfid, true);
1076 *cfid = bk->lb_lpf_fid;
1079 child = lfsck_object_find_bottom_new(env, lfsck, cfid);
1081 GOTO(unlock, rc = PTR_ERR(child));
1083 if (dt_object_exists(child)) {
1084 if (unlikely(!dt_try_as_dir(env, child, true)))
1087 lfsck->li_lpf_obj = child;
1092 memset(la, 0, sizeof(*la));
1093 la->la_atime = la->la_mtime = la->la_ctime = ktime_get_real_seconds();
1094 la->la_mode = S_IFDIR | S_IRWXU;
1095 la->la_valid = LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1096 LA_UID | LA_GID | LA_TYPE;
1097 memset(dof, 0, sizeof(*dof));
1098 dof->dof_type = dt_mode_to_dft(S_IFDIR);
1101 rc = lfsck_create_lpf_local(env, lfsck, child, la, dof, name);
1103 rc = lfsck_create_lpf_remote(env, lfsck, child, la, dof, name);
1105 lfsck->li_lpf_obj = child;
1111 if (rc != 0 && child != NULL && !IS_ERR(child))
1112 lfsck_object_put(env, child);
1118 * Scan .lustre/lost+found for bad name entries and remove them.
1120 * The valid name entry should be "MDTxxxx", the "xxxx" is the MDT device
1121 * index in the system. Any other formatted name is invalid and should be
1124 * \param[in] env pointer to the thread context
1125 * \param[in] lfsck pointer to the lfsck instance
1127 * \retval 0 for success
1128 * \retval negative error number on failure
1130 static int lfsck_scan_lpf_bad_entries(const struct lu_env *env,
1131 struct lfsck_instance *lfsck)
1133 struct dt_object *parent = lfsck->li_lpf_root_obj;
1134 struct lu_dirent *ent =
1135 (struct lu_dirent *)lfsck_env_info(env)->lti_key;
1136 const struct dt_it_ops *iops = &parent->do_index_ops->dio_it;
1141 it = iops->init(env, parent, LUDA_64BITHASH);
1143 RETURN(PTR_ERR(it));
1145 rc = iops->load(env, it, 0);
1147 rc = iops->next(env, it);
1154 rc = iops->rec(env, it, (struct dt_rec *)ent, LUDA_64BITHASH);
1158 ent->lde_namelen = le16_to_cpu(ent->lde_namelen);
1159 if (name_is_dot_or_dotdot(ent->lde_name, ent->lde_namelen))
1162 /* name length must be strlen("MDTxxxx") */
1163 if (ent->lde_namelen != 7)
1166 if (memcmp(ent->lde_name, "MDT", off) != 0)
1169 while (off < 7 && isxdigit(ent->lde_name[off]))
1175 rc = lfsck_lpf_remove_name_entry(env, lfsck,
1182 rc = iops->next(env, it);
1186 iops->fini(env, it);
1188 RETURN(rc > 0 ? 0 : rc);
1191 static int lfsck_update_lpf_entry(const struct lu_env *env,
1192 struct lfsck_instance *lfsck,
1193 struct dt_object *parent,
1194 struct dt_object *child,
1196 enum lfsck_verify_lpf_types type)
1200 if (type == LVLT_BY_BOOKMARK) {
1201 rc = lfsck_update_name_entry(env, lfsck, parent, name,
1202 lfsck_dto2fid(child), S_IFDIR);
1203 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1204 lfsck->li_bookmark_ram.lb_lpf_fid = *lfsck_dto2fid(child);
1205 rc = lfsck_bookmark_store(env, lfsck);
1207 CDEBUG(D_LFSCK, "%s: update LPF fid "DFID
1208 " in the bookmark file: rc = %d\n",
1209 lfsck_lfsck2name(lfsck),
1210 PFID(lfsck_dto2fid(child)), rc);
1217 * Check whether the @child back references the @parent.
1220 * 1) The child's FID is stored in the bookmark file. If the child back
1221 * references the parent (LU_LPF_FID object) via its ".." entry, then
1222 * insert the name (MDTxxxx) to the .lustre/lost+found; otherwise, if
1223 * the child back references another parent2, then:
1224 * 1.1) If the parent2 recognizes the child, then update the bookmark file;
1225 * 1.2) Otherwise, the LFSCK cannot know whether there will be parent3 that
1226 * references the child. So keep them there. As the LFSCK processing,
1227 * the parent3 may be found, then when the LFSCK run next time, the
1228 * inconsistency can be repaired.
1230 * 2) The child's FID is stored in the .lustre/lost+found/ sub-directory name
1231 * entry (MDTxxxx). If the child back references the parent (LU_LPF_FID obj)
1232 * via its ".." entry, then update the bookmark file, otherwise, if the child
1233 * back references another parent2, then:
1234 * 2.1) If the parent2 recognizes the child, then remove the sub-directory
1235 * from .lustre/lost+found/;
1236 * 2.2) Otherwise, if the parent2 does not recognizes the child, trust the
1237 * sub-directory name entry and update the child;
1238 * 2.3) Otherwise, if we do not know whether the parent2 recognizes the child
1239 * or not, then keep them there.
1241 * \param[in] env pointer to the thread context
1242 * \param[in] lfsck pointer to the lfsck instance
1243 * \param[in] child pointer to the lost+found sub-directory object
1244 * \param[in] name the name for lost+found sub-directory object
1245 * \param[out] fid pointer to the buffer to hold the FID of the object
1246 * (called it as parent2) that is referenced via the
1247 * child's dotdot entry; it also can be the FID that
1248 * is referenced by the name entry under the parent2.
1249 * \param[in] type to indicate where the child's FID is stored in
1251 * \retval positive number for uncertain inconsistency
1252 * \retval 0 for success
1253 * \retval negative error number on failure
1255 static int lfsck_verify_lpf_pairs(const struct lu_env *env,
1256 struct lfsck_instance *lfsck,
1257 struct dt_object *child, const char *name,
1259 enum lfsck_verify_lpf_types type)
1261 struct dt_object *parent = lfsck->li_lpf_root_obj;
1262 struct lfsck_thread_info *info = lfsck_env_info(env);
1263 char *name2 = info->lti_key;
1264 struct lu_fid *fid2 = &info->lti_fid3;
1265 struct dt_object *parent2 = NULL;
1266 struct lustre_handle lh = { 0 };
1271 rc = dt_lookup_dir(env, child, dotdot, fid);
1275 if (!fid_is_sane(fid))
1276 GOTO(linkea, rc = -EINVAL);
1278 if (lu_fid_eq(fid, &LU_LPF_FID)) {
1279 const struct lu_name *cname;
1281 if (lfsck->li_lpf_obj == NULL) {
1282 lu_object_get(&child->do_lu);
1283 lfsck->li_lpf_obj = child;
1286 cname = lfsck_name_get_const(env, name, strlen(name));
1287 rc = lfsck_verify_linkea(env, lfsck, child, cname, &LU_LPF_FID);
1289 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1295 parent2 = lfsck_object_find_bottom(env, lfsck, fid);
1296 if (IS_ERR(parent2))
1297 GOTO(linkea, parent2);
1299 if (!dt_try_as_dir(env, parent2, true)) {
1300 lfsck_object_put(env, parent2);
1302 GOTO(linkea, parent2 = ERR_PTR(-ENOTDIR));
1306 /* To prevent rename/unlink race */
1307 rc = lfsck_ibits_lock(env, lfsck, child, &lh,
1308 MDS_INODELOCK_UPDATE, LCK_PR);
1312 dt_read_lock(env, child, 0);
1313 rc = lfsck_links_get_first(env, child, name2, fid2);
1315 dt_read_unlock(env, child);
1316 lfsck_ibits_unlock(&lh, LCK_PR);
1318 GOTO(out_put, rc = 1);
1321 /* It is almost impossible that the bookmark file (or the name entry)
1322 * and the linkEA hit the same data corruption. Trust the linkEA. */
1323 if (lu_fid_eq(fid2, &LU_LPF_FID) && strcmp(name, name2) == 0) {
1324 dt_read_unlock(env, child);
1325 lfsck_ibits_unlock(&lh, LCK_PR);
1328 if (lfsck->li_lpf_obj == NULL) {
1329 lu_object_get(&child->do_lu);
1330 lfsck->li_lpf_obj = child;
1333 /* Update the child's dotdot entry */
1334 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1335 &LU_LPF_FID, S_IFDIR);
1337 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1343 if (parent2 == NULL || IS_ERR(parent2)) {
1344 dt_read_unlock(env, child);
1345 lfsck_ibits_unlock(&lh, LCK_PR);
1347 GOTO(out_done, rc = 1);
1350 rc = dt_lookup_dir(env, parent2, name2, fid);
1351 dt_read_unlock(env, child);
1352 lfsck_ibits_unlock(&lh, LCK_PR);
1353 if (rc != 0 && rc != -ENOENT)
1356 if (rc == -ENOENT || !lu_fid_eq(fid, lfsck_dto2fid(child))) {
1357 if (type == LVLT_BY_BOOKMARK)
1358 GOTO(out_put, rc = 1);
1360 /* Trust the name entry, update the child's dotdot entry. */
1361 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1362 &LU_LPF_FID, S_IFDIR);
1367 if (type == LVLT_BY_BOOKMARK) {
1368 /* Invalid FID record in the bookmark file, reset it. */
1369 fid_zero(&lfsck->li_bookmark_ram.lb_lpf_fid);
1370 rc = lfsck_bookmark_store(env, lfsck);
1372 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1373 " in the bookmark file: rc = %d\n",
1374 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(child)), rc);
1375 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1376 /* The name entry is wrong, remove it. */
1377 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1383 if (parent2 != NULL && !IS_ERR(parent2))
1384 lfsck_object_put(env, parent2);
1391 * Verify the /ROOT/.lustre/lost+found/ directory.
1393 * /ROOT/.lustre/lost+found/ is a special directory to hold the objects that
1394 * the LFSCK does not exactly know how to handle, such as orphans. So before
1395 * the LFSCK scanning the system, the consistency of such directory needs to
1396 * be verified firstly to allow the users to use it during the LFSCK.
1398 * \param[in] env pointer to the thread context
1399 * \param[in] lfsck pointer to the lfsck instance
1401 * \retval positive number for uncertain inconsistency
1402 * \retval 0 for success
1403 * \retval negative error number on failure
1405 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
1407 struct lfsck_thread_info *info = lfsck_env_info(env);
1408 struct lu_fid *pfid = &info->lti_fid;
1409 struct lu_fid *cfid = &info->lti_fid2;
1410 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1411 struct dt_object *parent;
1412 /* child1's FID is in the bookmark file. */
1413 struct dt_object *child1 = NULL;
1414 /* child2's FID is in the name entry MDTxxxx. */
1415 struct dt_object *child2 = NULL;
1416 const struct lu_name *cname;
1418 int node = lfsck_dev_idx(lfsck);
1422 LASSERT(lfsck->li_master);
1424 if (lfsck_is_dryrun(lfsck))
1427 if (lfsck->li_lpf_root_obj != NULL)
1431 parent = lfsck_object_find_by_dev(env, lfsck->li_bottom,
1434 struct lfsck_tgt_desc *ltd;
1436 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
1437 if (unlikely(ltd == NULL))
1440 parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
1446 RETURN(PTR_ERR(parent));
1448 LASSERT(dt_object_exists(parent));
1450 if (unlikely(!dt_try_as_dir(env, parent, true))) {
1451 lfsck_object_put(env, parent);
1453 GOTO(put, rc = -ENOTDIR);
1456 lfsck->li_lpf_root_obj = parent;
1458 rc = lfsck_scan_lpf_bad_entries(env, lfsck);
1460 CDEBUG(D_LFSCK, "%s: scan .lustre/lost+found/ "
1461 "for bad sub-directories: rc = %d\n",
1462 lfsck_lfsck2name(lfsck), rc);
1466 snprintf(name, 8, "MDT%04x", node);
1467 rc = dt_lookup_dir(env, parent, name, cfid);
1468 if (rc == -ENOENT) {
1476 /* Invalid FID in the name entry, remove the name entry. */
1477 if (!fid_is_norm(cfid)) {
1478 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1485 child2 = lfsck_object_find_bottom(env, lfsck, cfid);
1487 GOTO(put, rc = PTR_ERR(child2));
1489 if (unlikely(!dt_object_exists(child2) ||
1490 dt_object_remote(child2)) ||
1491 !S_ISDIR(lfsck_object_type(child2))) {
1492 rc = lfsck_lpf_remove_name_entry(env, lfsck, name);
1499 if (unlikely(!dt_try_as_dir(env, child2, true)))
1500 GOTO(put, rc = -ENOTDIR);
1503 if (fid_is_zero(&bk->lb_lpf_fid))
1506 if (likely(lu_fid_eq(cfid, &bk->lb_lpf_fid))) {
1507 if (lfsck->li_lpf_obj == NULL) {
1508 lu_object_get(&child2->do_lu);
1509 lfsck->li_lpf_obj = child2;
1512 cname = lfsck_name_get_const(env, name, strlen(name));
1513 rc = lfsck_verify_linkea(env, lfsck, child2, cname,
1519 if (unlikely(!fid_is_norm(&bk->lb_lpf_fid))) {
1520 struct lu_fid tfid = bk->lb_lpf_fid;
1522 /* Invalid FID record in the bookmark file, reset it. */
1523 fid_zero(&bk->lb_lpf_fid);
1524 rc = lfsck_bookmark_store(env, lfsck);
1526 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1527 " in the bookmark file: rc = %d\n",
1528 lfsck_lfsck2name(lfsck), PFID(&tfid), rc);
1536 child1 = lfsck_object_find_bottom(env, lfsck, &bk->lb_lpf_fid);
1537 if (IS_ERR(child1)) {
1542 if (unlikely(!dt_object_exists(child1) ||
1543 dt_object_remote(child1)) ||
1544 !S_ISDIR(lfsck_object_type(child1))) {
1545 /* Invalid FID record in the bookmark file, reset it. */
1546 fid_zero(&bk->lb_lpf_fid);
1547 rc = lfsck_bookmark_store(env, lfsck);
1549 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1550 " in the bookmark file: rc = %d\n",
1551 lfsck_lfsck2name(lfsck),
1552 PFID(lfsck_dto2fid(child1)), rc);
1557 lfsck_object_put(env, child1);
1562 if (unlikely(!dt_try_as_dir(env, child1, true))) {
1563 lfsck_object_put(env, child1);
1569 rc = lfsck_verify_lpf_pairs(env, lfsck, child1, name, pfid,
1571 if (lu_fid_eq(pfid, &LU_LPF_FID))
1576 rc = lfsck_verify_lpf_pairs(env, lfsck, child2, name,
1577 pfid, LVLT_BY_NAMEENTRY);
1582 if (lfsck->li_lpf_obj != NULL) {
1583 if (unlikely(!dt_try_as_dir(env, lfsck->li_lpf_obj, true))) {
1584 lfsck_object_put(env, lfsck->li_lpf_obj);
1585 lfsck->li_lpf_obj = NULL;
1588 } else if (rc == 0) {
1589 rc = lfsck_create_lpf(env, lfsck);
1592 if (child2 != NULL && !IS_ERR(child2))
1593 lfsck_object_put(env, child2);
1594 if (child1 != NULL && !IS_ERR(child1))
1595 lfsck_object_put(env, child1);
1600 static int lfsck_fid_init(struct lfsck_instance *lfsck)
1602 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1603 struct seq_server_site *ss = lfsck_dev_site(lfsck);
1608 if (unlikely(ss == NULL))
1611 OBD_ALLOC_PTR(lfsck->li_seq);
1612 if (lfsck->li_seq == NULL)
1615 OBD_ALLOC(prefix, MAX_OBD_NAME + 7);
1617 GOTO(out, rc = -ENOMEM);
1619 snprintf(prefix, MAX_OBD_NAME + 7, "lfsck-%s", lfsck_lfsck2name(lfsck));
1620 seq_client_init(lfsck->li_seq, NULL, LUSTRE_SEQ_METADATA, prefix,
1622 OBD_FREE(prefix, MAX_OBD_NAME + 7);
1624 if (fid_is_sane(&bk->lb_last_fid))
1625 lfsck->li_seq->lcs_fid = bk->lb_last_fid;
1630 OBD_FREE_PTR(lfsck->li_seq);
1631 lfsck->li_seq = NULL;
1636 static void lfsck_fid_fini(struct lfsck_instance *lfsck)
1638 if (lfsck->li_seq != NULL) {
1639 seq_client_fini(lfsck->li_seq);
1640 OBD_FREE_PTR(lfsck->li_seq);
1641 lfsck->li_seq = NULL;
1645 void lfsck_instance_cleanup(const struct lu_env *env,
1646 struct lfsck_instance *lfsck)
1648 struct ptlrpc_thread *thread = &lfsck->li_thread;
1649 struct lfsck_component *com;
1650 struct lfsck_component *next;
1651 struct lfsck_lmv_unit *llu;
1652 struct lfsck_lmv_unit *llu_next;
1653 struct lfsck_lmv *llmv;
1656 LASSERT(list_empty(&lfsck->li_link));
1657 LASSERT(thread_is_init(thread) || thread_is_stopped(thread));
1659 if (lfsck->li_obj_oit != NULL) {
1660 lfsck_object_put(env, lfsck->li_obj_oit);
1661 lfsck->li_obj_oit = NULL;
1664 list_for_each_entry_safe(llu, llu_next, &lfsck->li_list_lmv, llu_link) {
1665 llmv = &llu->llu_lmv;
1667 LASSERTF(atomic_read(&llmv->ll_ref) == 1,
1668 "still in using: %u\n",
1669 atomic_read(&llmv->ll_ref));
1671 lfsck_lmv_put(env, llmv);
1674 list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
1675 lfsck_component_cleanup(env, com);
1678 LASSERT(list_empty(&lfsck->li_list_dir));
1680 list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
1682 lfsck_component_cleanup(env, com);
1685 list_for_each_entry_safe(com, next, &lfsck->li_list_idle, lc_link) {
1686 lfsck_component_cleanup(env, com);
1689 lfsck_tgt_descs_fini(&lfsck->li_ost_descs);
1690 lfsck_tgt_descs_fini(&lfsck->li_mdt_descs);
1692 if (lfsck->li_lfsck_dir != NULL) {
1693 lfsck_object_put(env, lfsck->li_lfsck_dir);
1694 lfsck->li_lfsck_dir = NULL;
1697 if (lfsck->li_bookmark_obj != NULL) {
1698 lfsck_object_put(env, lfsck->li_bookmark_obj);
1699 lfsck->li_bookmark_obj = NULL;
1702 if (lfsck->li_lpf_obj != NULL) {
1703 lfsck_object_put(env, lfsck->li_lpf_obj);
1704 lfsck->li_lpf_obj = NULL;
1707 if (lfsck->li_lpf_root_obj != NULL) {
1708 lfsck_object_put(env, lfsck->li_lpf_root_obj);
1709 lfsck->li_lpf_root_obj = NULL;
1712 if (lfsck->li_los != NULL) {
1713 local_oid_storage_fini(env, lfsck->li_los);
1714 lfsck->li_los = NULL;
1717 lfsck_fid_fini(lfsck);
1719 OBD_FREE_PTR(lfsck);
1722 static inline struct lfsck_instance *
1723 __lfsck_instance_find(struct dt_device *key, bool ref, bool unlink)
1725 struct lfsck_instance *lfsck;
1727 list_for_each_entry(lfsck, &lfsck_instance_list, li_link) {
1728 if (lfsck->li_bottom == key) {
1730 lfsck_instance_get(lfsck);
1732 list_del_init(&lfsck->li_link);
1741 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
1744 struct lfsck_instance *lfsck;
1746 spin_lock(&lfsck_instance_lock);
1747 lfsck = __lfsck_instance_find(key, ref, unlink);
1748 spin_unlock(&lfsck_instance_lock);
1753 static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
1755 struct lfsck_instance *tmp;
1757 spin_lock(&lfsck_instance_lock);
1758 list_for_each_entry(tmp, &lfsck_instance_list, li_link) {
1759 if (lfsck->li_bottom == tmp->li_bottom) {
1760 spin_unlock(&lfsck_instance_lock);
1765 list_add_tail(&lfsck->li_link, &lfsck_instance_list);
1766 spin_unlock(&lfsck_instance_lock);
1770 void lfsck_bits_dump(struct seq_file *m, int bits, const char *const names[],
1775 bool newline = (bits != 0 ? false : true);
1777 seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
1779 for (i = 0, flag = 1; bits != 0; i++, flag = BIT(i)) {
1782 if (names[i] != NULL) {
1786 seq_printf(m, "%s%c", names[i],
1787 newline ? '\n' : ',');
1796 void lfsck_time_dump(struct seq_file *m, time64_t time, const char *name)
1799 seq_printf(m, "%s_time: N/A\n", name);
1800 seq_printf(m, "time_since_%s: N/A\n", name);
1802 seq_printf(m, "%s_time: %lld\n", name, time);
1803 seq_printf(m, "time_since_%s: %lld seconds\n",
1804 name, ktime_get_real_seconds() - time);
1808 void lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
1811 if (fid_is_zero(&pos->lp_dir_parent)) {
1812 if (pos->lp_oit_cookie == 0) {
1813 seq_printf(m, "%s: N/A, N/A, N/A\n", prefix);
1816 seq_printf(m, "%s: %llu, N/A, N/A\n",
1817 prefix, pos->lp_oit_cookie);
1819 seq_printf(m, "%s: %llu, "DFID", %#llx\n",
1820 prefix, pos->lp_oit_cookie,
1821 PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
1825 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
1826 struct lfsck_position *pos, bool init)
1828 const struct dt_it_ops *iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
1830 if (unlikely(lfsck->li_di_oit == NULL)) {
1831 memset(pos, 0, sizeof(*pos));
1835 pos->lp_oit_cookie = iops->store(env, lfsck->li_di_oit);
1836 if (!lfsck->li_current_oit_processed && !init)
1837 pos->lp_oit_cookie--;
1839 if (unlikely(pos->lp_oit_cookie == 0))
1840 pos->lp_oit_cookie = 1;
1842 spin_lock(&lfsck->li_lock);
1843 if (lfsck->li_di_dir != NULL) {
1844 struct dt_object *dto = lfsck->li_obj_dir;
1846 pos->lp_dir_cookie = dto->do_index_ops->dio_it.store(env,
1849 if (pos->lp_dir_cookie >= MDS_DIR_END_OFF) {
1850 fid_zero(&pos->lp_dir_parent);
1851 pos->lp_dir_cookie = 0;
1853 pos->lp_dir_parent = *lfsck_dto2fid(dto);
1856 fid_zero(&pos->lp_dir_parent);
1857 pos->lp_dir_cookie = 0;
1859 spin_unlock(&lfsck->li_lock);
1862 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
1866 if (limit != LFSCK_SPEED_NO_LIMIT) {
1867 if (limit > cfs_time_seconds(1)) {
1868 lfsck->li_sleep_rate = limit / cfs_time_seconds(1);
1869 lfsck->li_sleep_jif = 1;
1871 lfsck->li_sleep_rate = 1;
1872 lfsck->li_sleep_jif = cfs_time_seconds(1) / limit;
1875 lfsck->li_sleep_jif = 0;
1876 lfsck->li_sleep_rate = 0;
1879 if (lfsck->li_bookmark_ram.lb_speed_limit != limit) {
1880 lfsck->li_bookmark_ram.lb_speed_limit = limit;
1887 void lfsck_control_speed(struct lfsck_instance *lfsck)
1889 struct ptlrpc_thread *thread = &lfsck->li_thread;
1891 if (lfsck->li_sleep_jif > 0 &&
1892 lfsck->li_new_scanned >= lfsck->li_sleep_rate) {
1893 wait_event_idle_timeout(thread->t_ctl_waitq,
1894 !thread_is_running(thread),
1895 lfsck->li_sleep_jif);
1896 lfsck->li_new_scanned = 0;
1900 void lfsck_control_speed_by_self(struct lfsck_component *com)
1902 struct lfsck_instance *lfsck = com->lc_lfsck;
1903 struct ptlrpc_thread *thread = &lfsck->li_thread;
1905 if (lfsck->li_sleep_jif > 0 &&
1906 com->lc_new_scanned >= lfsck->li_sleep_rate) {
1907 wait_event_idle_timeout(thread->t_ctl_waitq,
1908 !thread_is_running(thread),
1909 lfsck->li_sleep_jif);
1910 com->lc_new_scanned = 0;
1914 static struct lfsck_thread_args *
1915 lfsck_thread_args_init(struct lfsck_instance *lfsck,
1916 struct lfsck_component *com,
1917 struct lfsck_start_param *lsp)
1919 struct lfsck_thread_args *lta;
1924 return ERR_PTR(-ENOMEM);
1926 rc = lu_env_init(<a->lta_env, LCT_MD_THREAD | LCT_DT_THREAD);
1932 lta->lta_lfsck = lfsck_instance_get(lfsck);
1934 lta->lta_com = lfsck_component_get(com);
1941 void lfsck_thread_args_fini(struct lfsck_thread_args *lta)
1943 if (lta->lta_com != NULL)
1944 lfsck_component_put(<a->lta_env, lta->lta_com);
1945 lfsck_instance_put(<a->lta_env, lta->lta_lfsck);
1946 lu_env_fini(<a->lta_env);
1950 struct lfsck_assistant_data *
1951 lfsck_assistant_data_init(const struct lfsck_assistant_operations *lao,
1954 struct lfsck_assistant_data *lad;
1958 lad->lad_bitmap = bitmap_zalloc(BITS_PER_LONG, GFP_KERNEL);
1959 if (lad->lad_bitmap == NULL) {
1963 lad->lad_bitmap_count = BITS_PER_LONG;
1965 INIT_LIST_HEAD(&lad->lad_req_list);
1966 spin_lock_init(&lad->lad_lock);
1967 INIT_LIST_HEAD(&lad->lad_ost_list);
1968 INIT_LIST_HEAD(&lad->lad_ost_phase1_list);
1969 INIT_LIST_HEAD(&lad->lad_ost_phase2_list);
1970 INIT_LIST_HEAD(&lad->lad_mdt_list);
1971 INIT_LIST_HEAD(&lad->lad_mdt_phase1_list);
1972 INIT_LIST_HEAD(&lad->lad_mdt_phase2_list);
1973 init_waitqueue_head(&lad->lad_thread.t_ctl_waitq);
1975 lad->lad_name = name;
1981 struct lfsck_assistant_object *
1982 lfsck_assistant_object_init(const struct lu_env *env, const struct lu_fid *fid,
1983 const struct lu_attr *attr, __u64 cookie,
1986 struct lfsck_assistant_object *lso;
1990 return ERR_PTR(-ENOMEM);
1992 lso->lso_fid = *fid;
1994 lso->lso_attr = *attr;
1996 atomic_set(&lso->lso_ref, 1);
1997 lso->lso_oit_cookie = cookie;
1999 lso->lso_is_dir = 1;
2005 lfsck_assistant_object_load(const struct lu_env *env,
2006 struct lfsck_instance *lfsck,
2007 struct lfsck_assistant_object *lso)
2009 struct dt_object *obj;
2011 obj = lfsck_object_find_bottom(env, lfsck, &lso->lso_fid);
2015 if (unlikely(!dt_object_exists(obj) || lfsck_is_dead_obj(obj))) {
2017 lfsck_object_put(env, obj);
2019 return ERR_PTR(-ENOENT);
2022 if (lso->lso_is_dir && unlikely(!dt_try_as_dir(env, obj, true))) {
2023 lfsck_object_put(env, obj);
2025 return ERR_PTR(-ENOTDIR);
2032 * Generic LFSCK asynchronous communication interpretor function.
2033 * The LFSCK RPC reply for both the event notification and status
2034 * querying will be handled here.
2036 * \param[in] env pointer to the thread context
2037 * \param[in] req pointer to the LFSCK request
2038 * \param[in] args pointer to the lfsck_async_interpret_args
2039 * \param[in] rc the result for handling the LFSCK request
2041 * \retval 0 for success
2042 * \retval negative error number on failure
2044 int lfsck_async_interpret_common(const struct lu_env *env,
2045 struct ptlrpc_request *req,
2048 struct lfsck_async_interpret_args *laia = args;
2049 struct lfsck_component *com = laia->laia_com;
2050 struct lfsck_assistant_data *lad = com->lc_data;
2051 struct lfsck_tgt_descs *ltds = laia->laia_ltds;
2052 struct lfsck_tgt_desc *ltd = laia->laia_ltd;
2053 struct lfsck_request *lr = laia->laia_lr;
2055 LASSERT(com->lc_lfsck->li_master);
2057 switch (lr->lr_event) {
2059 if (unlikely(rc == -EINPROGRESS)) {
2060 ltd->ltd_retry_start = 1;
2065 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s "
2067 lfsck_lfsck2name(com->lc_lfsck),
2068 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2069 ltd->ltd_index, lad->lad_name, rc);
2071 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2072 struct lfsck_layout *lo = com->lc_file_ram;
2074 if (lr->lr_flags & LEF_TO_OST)
2075 lfsck_lad_set_bitmap(env, com,
2078 lo->ll_flags |= LF_INCOMPLETE;
2080 struct lfsck_namespace *ns = com->lc_file_ram;
2082 /* If some MDT does not join the namespace
2083 * LFSCK, then we cannot know whether there
2084 * is some name entry on such MDT that with
2085 * the referenced MDT-object on this MDT or
2086 * not. So the namespace LFSCK on this MDT
2087 * cannot handle orphan MDT-objects properly.
2088 * So we mark the LFSCK as LF_INCOMPLETE and
2089 * skip orphan MDT-objects handling. */
2090 ns->ln_flags |= LF_INCOMPLETE;
2095 spin_lock(<ds->ltd_lock);
2096 if (ltd->ltd_dead) {
2097 spin_unlock(<ds->ltd_lock);
2101 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2102 struct list_head *list;
2103 struct list_head *phase_list;
2105 if (ltd->ltd_layout_done) {
2106 spin_unlock(<ds->ltd_lock);
2110 if (lr->lr_flags & LEF_TO_OST) {
2111 list = &lad->lad_ost_list;
2112 phase_list = &lad->lad_ost_phase1_list;
2114 list = &lad->lad_mdt_list;
2115 phase_list = &lad->lad_mdt_phase1_list;
2118 if (list_empty(<d->ltd_layout_list))
2119 list_add_tail(<d->ltd_layout_list, list);
2120 if (list_empty(<d->ltd_layout_phase_list))
2121 list_add_tail(<d->ltd_layout_phase_list,
2124 if (ltd->ltd_namespace_done) {
2125 spin_unlock(<ds->ltd_lock);
2129 if (list_empty(<d->ltd_namespace_list))
2130 list_add_tail(<d->ltd_namespace_list,
2131 &lad->lad_mdt_list);
2132 if (list_empty(<d->ltd_namespace_phase_list))
2133 list_add_tail(<d->ltd_namespace_phase_list,
2134 &lad->lad_mdt_phase1_list);
2136 spin_unlock(<ds->ltd_lock);
2139 case LE_PHASE1_DONE:
2140 case LE_PHASE2_DONE:
2142 if (rc != 0 && rc != -EALREADY)
2143 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s: "
2144 "event = %d, rc = %d\n",
2145 lfsck_lfsck2name(com->lc_lfsck),
2146 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2147 ltd->ltd_index, lad->lad_name, lr->lr_event, rc);
2150 struct lfsck_reply *reply;
2151 struct list_head *list;
2152 struct list_head *phase_list;
2154 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2155 list = <d->ltd_layout_list;
2156 phase_list = <d->ltd_layout_phase_list;
2158 list = <d->ltd_namespace_list;
2159 phase_list = <d->ltd_namespace_phase_list;
2163 if (lr->lr_flags & LEF_QUERY_ALL) {
2164 lfsck_reset_ltd_status(ltd, com->lc_type);
2168 spin_lock(<ds->ltd_lock);
2169 list_del_init(phase_list);
2170 list_del_init(list);
2171 spin_unlock(<ds->ltd_lock);
2175 reply = req_capsule_server_get(&req->rq_pill,
2177 if (reply == NULL) {
2179 CDEBUG(D_LFSCK, "%s: invalid query reply for %s: "
2180 "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck),
2183 if (lr->lr_flags & LEF_QUERY_ALL) {
2184 lfsck_reset_ltd_status(ltd, com->lc_type);
2188 spin_lock(<ds->ltd_lock);
2189 list_del_init(phase_list);
2190 list_del_init(list);
2191 spin_unlock(<ds->ltd_lock);
2195 if (lr->lr_flags & LEF_QUERY_ALL) {
2196 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2197 ltd->ltd_layout_status = reply->lr_status;
2198 ltd->ltd_layout_repaired = reply->lr_repaired;
2200 ltd->ltd_namespace_status = reply->lr_status;
2201 ltd->ltd_namespace_repaired =
2207 switch (reply->lr_status) {
2208 case LS_SCANNING_PHASE1:
2210 case LS_SCANNING_PHASE2:
2211 spin_lock(<ds->ltd_lock);
2212 list_del_init(phase_list);
2213 if (ltd->ltd_dead) {
2214 spin_unlock(<ds->ltd_lock);
2218 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
2219 if (ltd->ltd_layout_done) {
2220 spin_unlock(<ds->ltd_lock);
2224 if (lr->lr_flags & LEF_TO_OST)
2225 list_add_tail(phase_list,
2226 &lad->lad_ost_phase2_list);
2228 list_add_tail(phase_list,
2229 &lad->lad_mdt_phase2_list);
2231 if (ltd->ltd_namespace_done) {
2232 spin_unlock(<ds->ltd_lock);
2236 list_add_tail(phase_list,
2237 &lad->lad_mdt_phase2_list);
2239 spin_unlock(<ds->ltd_lock);
2242 spin_lock(<ds->ltd_lock);
2243 list_del_init(phase_list);
2244 list_del_init(list);
2245 spin_unlock(<ds->ltd_lock);
2251 CDEBUG(D_LFSCK, "%s: unexpected event: rc = %d\n",
2252 lfsck_lfsck2name(com->lc_lfsck), lr->lr_event);
2256 if (!laia->laia_shared) {
2258 lfsck_component_put(env, com);
2264 static void lfsck_interpret(const struct lu_env *env,
2265 struct lfsck_instance *lfsck,
2266 struct ptlrpc_request *req, void *args, int result)
2268 struct lfsck_async_interpret_args *laia = args;
2269 struct lfsck_component *com;
2271 LASSERT(laia->laia_com == NULL);
2272 LASSERT(laia->laia_shared);
2274 spin_lock(&lfsck->li_lock);
2275 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
2276 laia->laia_com = com;
2277 lfsck_async_interpret_common(env, req, laia, result);
2280 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
2281 laia->laia_com = com;
2282 lfsck_async_interpret_common(env, req, laia, result);
2284 spin_unlock(&lfsck->li_lock);
2287 static int lfsck_stop_notify(const struct lu_env *env,
2288 struct lfsck_instance *lfsck,
2289 struct lfsck_tgt_descs *ltds,
2290 struct lfsck_tgt_desc *ltd, __u16 type)
2292 struct lfsck_component *com;
2296 LASSERT(lfsck->li_master);
2298 spin_lock(&lfsck->li_lock);
2299 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
2301 com = __lfsck_component_find(lfsck, type,
2302 &lfsck->li_list_double_scan);
2304 lfsck_component_get(com);
2305 spin_unlock(&lfsck->li_lock);
2308 struct lfsck_thread_info *info = lfsck_env_info(env);
2309 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2310 struct lfsck_request *lr = &info->lti_lr;
2311 struct lfsck_assistant_data *lad = com->lc_data;
2312 struct list_head *list;
2313 struct list_head *phase_list;
2314 struct ptlrpc_request_set *set;
2316 set = ptlrpc_prep_set();
2318 lfsck_component_put(env, com);
2323 if (type == LFSCK_TYPE_LAYOUT) {
2324 list = <d->ltd_layout_list;
2325 phase_list = <d->ltd_layout_phase_list;
2327 list = <d->ltd_namespace_list;
2328 phase_list = <d->ltd_namespace_phase_list;
2331 spin_lock(<ds->ltd_lock);
2332 if (list_empty(list)) {
2333 LASSERT(list_empty(phase_list));
2334 spin_unlock(<ds->ltd_lock);
2335 ptlrpc_set_destroy(set);
2340 list_del_init(phase_list);
2341 list_del_init(list);
2342 spin_unlock(<ds->ltd_lock);
2344 memset(lr, 0, sizeof(*lr));
2345 lr->lr_index = lfsck_dev_idx(lfsck);
2346 lr->lr_event = LE_PEER_EXIT;
2347 lr->lr_active = type;
2348 lr->lr_status = LS_CO_PAUSED;
2349 if (ltds == &lfsck->li_ost_descs)
2350 lr->lr_flags = LEF_TO_OST;
2352 memset(laia, 0, sizeof(*laia));
2353 laia->laia_com = com;
2354 laia->laia_ltds = ltds;
2355 atomic_inc(<d->ltd_ref);
2356 laia->laia_ltd = ltd;
2359 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2360 lfsck_async_interpret_common,
2361 laia, LFSCK_NOTIFY);
2363 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for "
2364 "co-stop for %s: rc = %d\n",
2365 lfsck_lfsck2name(lfsck),
2366 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2367 ltd->ltd_index, lad->lad_name, rc);
2370 rc = ptlrpc_set_wait(env, set);
2373 ptlrpc_set_destroy(set);
2374 lfsck_component_put(env, com);
2380 static int lfsck_async_interpret(const struct lu_env *env,
2381 struct ptlrpc_request *req,
2384 struct lfsck_async_interpret_args *laia = args;
2385 struct lfsck_instance *lfsck;
2387 lfsck = container_of(laia->laia_ltds, struct lfsck_instance,
2389 lfsck_interpret(env, lfsck, req, laia, rc);
2390 lfsck_tgt_put(laia->laia_ltd);
2391 if (rc != 0 && laia->laia_result != -EALREADY)
2392 laia->laia_result = rc;
2397 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
2398 struct lfsck_request *lr,
2399 struct ptlrpc_request_set *set,
2400 ptlrpc_interpterer_t interpreter,
2401 void *args, int request)
2403 struct lfsck_async_interpret_args *laia;
2404 struct ptlrpc_request *req;
2405 struct lfsck_request *tmp;
2406 struct req_format *format;
2411 format = &RQF_LFSCK_NOTIFY;
2414 format = &RQF_LFSCK_QUERY;
2417 CDEBUG(D_LFSCK, "%s: unknown async request %d: rc = %d\n",
2418 exp->exp_obd->obd_name, request, -EINVAL);
2422 req = ptlrpc_request_alloc(class_exp2cliimp(exp), format);
2426 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, request);
2428 ptlrpc_request_free(req);
2433 tmp = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
2435 ptlrpc_request_set_replen(req);
2437 laia = ptlrpc_req_async_args(laia, req);
2438 *laia = *(struct lfsck_async_interpret_args *)args;
2439 if (laia->laia_com != NULL)
2440 lfsck_component_get(laia->laia_com);
2441 req->rq_interpret_reply = interpreter;
2442 req->rq_allow_intr = 1;
2443 req->rq_no_delay = 1;
2444 ptlrpc_set_add_req(set, req);
2449 int lfsck_query_all(const struct lu_env *env, struct lfsck_component *com)
2451 struct lfsck_thread_info *info = lfsck_env_info(env);
2452 struct lfsck_request *lr = &info->lti_lr;
2453 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2454 struct lfsck_instance *lfsck = com->lc_lfsck;
2455 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2456 struct lfsck_tgt_desc *ltd;
2457 struct ptlrpc_request_set *set;
2462 memset(lr, 0, sizeof(*lr));
2463 lr->lr_event = LE_QUERY;
2464 lr->lr_active = com->lc_type;
2465 lr->lr_flags = LEF_QUERY_ALL;
2467 memset(laia, 0, sizeof(*laia));
2468 laia->laia_com = com;
2471 set = ptlrpc_prep_set();
2476 laia->laia_ltds = ltds;
2477 down_read(<ds->ltd_rw_sem);
2478 for_each_set_bit(idx, ltds->ltd_tgts_bitmap, ltds->ltd_tgts_mask_len) {
2479 ltd = lfsck_tgt_get(ltds, idx);
2480 LASSERT(ltd != NULL);
2482 laia->laia_ltd = ltd;
2483 up_read(<ds->ltd_rw_sem);
2484 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2485 lfsck_async_interpret_common,
2488 struct lfsck_assistant_data *lad = com->lc_data;
2490 CDEBUG(D_LFSCK, "%s: Fail to query %s %x for stat %s: "
2491 "rc = %d\n", lfsck_lfsck2name(lfsck),
2492 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2493 ltd->ltd_index, lad->lad_name, rc);
2494 lfsck_reset_ltd_status(ltd, com->lc_type);
2497 down_read(<ds->ltd_rw_sem);
2499 up_read(<ds->ltd_rw_sem);
2501 if (com->lc_type == LFSCK_TYPE_LAYOUT && !(lr->lr_flags & LEF_TO_OST)) {
2502 ltds = &lfsck->li_ost_descs;
2503 lr->lr_flags |= LEF_TO_OST;
2507 rc = ptlrpc_set_wait(env, set);
2508 ptlrpc_set_destroy(set);
2513 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
2514 struct lfsck_start_param *lsp)
2516 struct lfsck_instance *lfsck = com->lc_lfsck;
2517 struct lfsck_assistant_data *lad = com->lc_data;
2518 struct ptlrpc_thread *mthread = &lfsck->li_thread;
2519 struct ptlrpc_thread *athread = &lad->lad_thread;
2520 struct lfsck_thread_args *lta;
2521 struct task_struct *task;
2525 lad->lad_assistant_status = 0;
2526 lad->lad_post_result = 0;
2528 lad->lad_advance_lock = false;
2529 thread_set_flags(athread, 0);
2531 lta = lfsck_thread_args_init(lfsck, com, lsp);
2533 RETURN(PTR_ERR(lta));
2535 task = kthread_run(lfsck_assistant_engine, lta, lad->lad_name);
2538 CERROR("%s: cannot start LFSCK assistant thread for %s: "
2539 "rc = %d\n", lfsck_lfsck2name(lfsck), lad->lad_name, rc);
2540 lfsck_thread_args_fini(lta);
2542 wait_event_idle(mthread->t_ctl_waitq,
2543 thread_is_running(athread) ||
2544 thread_is_stopped(athread) ||
2545 !thread_is_starting(mthread));
2546 if (unlikely(!thread_is_starting(mthread)))
2547 /* stopped by race */
2549 else if (unlikely(!thread_is_running(athread)))
2550 rc = lad->lad_assistant_status;
2558 int lfsck_checkpoint_generic(const struct lu_env *env,
2559 struct lfsck_component *com)
2561 struct lfsck_assistant_data *lad = com->lc_data;
2562 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2563 struct ptlrpc_thread *athread = &lad->lad_thread;
2565 wait_event_idle(mthread->t_ctl_waitq,
2566 list_empty(&lad->lad_req_list) ||
2567 !thread_is_running(mthread) ||
2568 thread_is_stopped(athread));
2570 if (!thread_is_running(mthread) || thread_is_stopped(athread))
2571 return LFSCK_CHECKPOINT_SKIP;
2576 void lfsck_post_generic(const struct lu_env *env,
2577 struct lfsck_component *com, int *result)
2579 struct lfsck_assistant_data *lad = com->lc_data;
2580 struct ptlrpc_thread *athread = &lad->lad_thread;
2581 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2583 lad->lad_post_result = *result;
2585 set_bit(LAD_EXIT, &lad->lad_flags);
2586 set_bit(LAD_TO_POST, &lad->lad_flags);
2588 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s post, rc = %d\n",
2589 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2591 wake_up(&athread->t_ctl_waitq);
2592 wait_event_idle(mthread->t_ctl_waitq,
2593 (*result > 0 && list_empty(&lad->lad_req_list)) ||
2594 thread_is_stopped(athread));
2596 if (lad->lad_assistant_status < 0)
2597 *result = lad->lad_assistant_status;
2599 CDEBUG(D_LFSCK, "%s: the assistant has done %s post, rc = %d\n",
2600 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
2603 int lfsck_double_scan_generic(const struct lu_env *env,
2604 struct lfsck_component *com, int status)
2606 struct lfsck_assistant_data *lad = com->lc_data;
2607 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2608 struct ptlrpc_thread *athread = &lad->lad_thread;
2610 if (status != LS_SCANNING_PHASE2)
2611 set_bit(LAD_EXIT, &lad->lad_flags);
2613 set_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags);
2615 CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s double_scan, "
2617 lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, status);
2619 wake_up(&athread->t_ctl_waitq);
2620 wait_event_idle(mthread->t_ctl_waitq,
2621 test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags) ||
2622 thread_is_stopped(athread));
2624 CDEBUG(D_LFSCK, "%s: the assistant has done %s double_scan, "
2625 "status %d\n", lfsck_lfsck2name(com->lc_lfsck), lad->lad_name,
2626 lad->lad_assistant_status);
2628 if (lad->lad_assistant_status < 0)
2629 return lad->lad_assistant_status;
2634 void lfsck_quit_generic(const struct lu_env *env,
2635 struct lfsck_component *com)
2637 struct lfsck_assistant_data *lad = com->lc_data;
2638 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2639 struct ptlrpc_thread *athread = &lad->lad_thread;
2641 set_bit(LAD_EXIT, &lad->lad_flags);
2642 wake_up(&athread->t_ctl_waitq);
2643 wait_event_idle(mthread->t_ctl_waitq,
2644 thread_is_init(athread) ||
2645 thread_is_stopped(athread));
2648 int lfsck_load_one_trace_file(const struct lu_env *env,
2649 struct lfsck_component *com,
2650 struct dt_object *parent,
2651 struct dt_object **child,
2652 const struct dt_index_features *ft,
2653 const char *name, bool reset)
2655 struct lfsck_instance *lfsck = com->lc_lfsck;
2656 struct dt_object *obj;
2660 if (*child != NULL) {
2662 const struct dt_it_ops *iops;
2663 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid3;
2669 rc = obj->do_ops->do_index_try(env, obj, ft);
2671 /* unlink by force */
2674 iops = &obj->do_index_ops->dio_it;
2675 it = iops->init(env, obj, 0);
2677 /* unlink by force */
2681 rc = iops->get(env, it, (const struct dt_key *)fid);
2683 rc = iops->next(env, it);
2686 iops->fini(env, it);
2688 /* "rc > 0" means the index file is empty. */
2692 /* The old index is not empty, remove it firstly. */
2693 rc = local_object_unlink(env, lfsck->li_bottom, parent, name);
2694 CDEBUG_LIMIT(rc ? D_ERROR : D_LFSCK,
2695 "%s: unlink lfsck sub trace file %s: rc = %d\n",
2696 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2701 lfsck_object_put(env, *child);
2708 obj = local_index_find_or_create(env, lfsck->li_los, parent, name,
2709 S_IFREG | S_IRUGO | S_IWUSR, ft);
2711 RETURN(PTR_ERR(obj));
2713 rc = obj->do_ops->do_index_try(env, obj, ft);
2715 lfsck_object_put(env, obj);
2716 CDEBUG(D_LFSCK, "%s: LFSCK fail to load "
2717 "sub trace file %s: rc = %d\n",
2718 lfsck_lfsck2name(com->lc_lfsck), name, rc);
2726 int lfsck_load_sub_trace_files(const struct lu_env *env,
2727 struct lfsck_component *com,
2728 const struct dt_index_features *ft,
2729 const char *prefix, bool reset)
2731 char *name = lfsck_env_info(env)->lti_key;
2732 struct lfsck_sub_trace_obj *lsto;
2736 for (i = 0, rc = 0, lsto = &com->lc_sub_trace_objs[0];
2737 i < LFSCK_STF_COUNT && rc == 0; i++, lsto++) {
2738 snprintf(name, NAME_MAX, "%s_%02d", prefix, i);
2739 rc = lfsck_load_one_trace_file(env, com,
2740 com->lc_lfsck->li_lfsck_dir,
2741 &lsto->lsto_obj, ft, name, reset);
2747 /* external interfaces */
2748 int lfsck_get_speed(char *buf, struct dt_device *key)
2751 struct lfsck_instance *lfsck;
2755 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2759 lfsck = lfsck_instance_find(key, true, false);
2761 rc = sprintf(buf, "%u\n",
2762 lfsck->li_bookmark_ram.lb_speed_limit);
2763 lfsck_instance_put(&env, lfsck);
2772 EXPORT_SYMBOL(lfsck_get_speed);
2774 int lfsck_set_speed(struct dt_device *key, __u32 val)
2777 struct lfsck_instance *lfsck;
2781 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2785 lfsck = lfsck_instance_find(key, true, false);
2786 if (likely(lfsck != NULL)) {
2787 mutex_lock(&lfsck->li_mutex);
2788 if (__lfsck_set_speed(lfsck, val))
2789 rc = lfsck_bookmark_store(&env, lfsck);
2790 mutex_unlock(&lfsck->li_mutex);
2791 lfsck_instance_put(&env, lfsck);
2800 EXPORT_SYMBOL(lfsck_set_speed);
2802 int lfsck_get_windows(char *buf, struct dt_device *key)
2805 struct lfsck_instance *lfsck;
2809 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2813 lfsck = lfsck_instance_find(key, true, false);
2814 if (likely(lfsck != NULL)) {
2815 rc = sprintf(buf, "%u\n",
2816 lfsck->li_bookmark_ram.lb_async_windows);
2817 lfsck_instance_put(&env, lfsck);
2826 EXPORT_SYMBOL(lfsck_get_windows);
2828 int lfsck_set_windows(struct dt_device *key, unsigned int val)
2831 struct lfsck_instance *lfsck;
2835 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2839 lfsck = lfsck_instance_find(key, true, false);
2840 if (likely(lfsck != NULL)) {
2841 if (val < 1 || val > LFSCK_ASYNC_WIN_MAX) {
2842 CWARN("%s: invalid async windows size that may "
2843 "cause memory issues. The valid range is "
2845 lfsck_lfsck2name(lfsck), LFSCK_ASYNC_WIN_MAX);
2847 } else if (lfsck->li_bookmark_ram.lb_async_windows != val) {
2848 mutex_lock(&lfsck->li_mutex);
2849 lfsck->li_bookmark_ram.lb_async_windows = val;
2850 rc = lfsck_bookmark_store(&env, lfsck);
2851 mutex_unlock(&lfsck->li_mutex);
2853 lfsck_instance_put(&env, lfsck);
2862 EXPORT_SYMBOL(lfsck_set_windows);
2864 int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
2867 struct lfsck_instance *lfsck;
2868 struct lfsck_component *com;
2872 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2876 lfsck = lfsck_instance_find(key, true, false);
2877 if (likely(lfsck != NULL)) {
2878 com = lfsck_component_find(lfsck, type);
2879 if (likely(com != NULL)) {
2880 com->lc_ops->lfsck_dump(&env, com, m);
2881 lfsck_component_put(&env, com);
2886 lfsck_instance_put(&env, lfsck);
2895 EXPORT_SYMBOL(lfsck_dump);
2897 static int lfsck_stop_all(const struct lu_env *env,
2898 struct lfsck_instance *lfsck,
2899 struct lfsck_stop *stop)
2901 struct lfsck_thread_info *info = lfsck_env_info(env);
2902 struct lfsck_request *lr = &info->lti_lr;
2903 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2904 struct ptlrpc_request_set *set;
2905 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2906 struct lfsck_tgt_desc *ltd;
2907 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2913 LASSERT(stop->ls_flags & LPF_BROADCAST);
2915 set = ptlrpc_prep_set();
2916 if (unlikely(set == NULL))
2919 memset(lr, 0, sizeof(*lr));
2920 lr->lr_event = LE_STOP;
2921 lr->lr_index = lfsck_dev_idx(lfsck);
2922 lr->lr_status = stop->ls_status;
2923 lr->lr_version = bk->lb_version;
2924 lr->lr_active = LFSCK_TYPES_ALL;
2925 lr->lr_param = stop->ls_flags;
2927 memset(laia, 0, sizeof(*laia));
2928 laia->laia_ltds = ltds;
2930 laia->laia_shared = 1;
2932 down_read(<ds->ltd_rw_sem);
2933 for_each_set_bit(idx, ltds->ltd_tgts_bitmap, ltds->ltd_tgts_mask_len) {
2934 ltd = lfsck_tgt_get(ltds, idx);
2935 LASSERT(ltd != NULL);
2937 laia->laia_ltd = ltd;
2938 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2939 lfsck_async_interpret, laia,
2942 lfsck_interpret(env, lfsck, NULL, laia, rc);
2944 CERROR("%s: cannot notify MDT %x for LFSCK stop: "
2945 "rc = %d\n", lfsck_lfsck2name(lfsck), idx, rc);
2949 up_read(<ds->ltd_rw_sem);
2951 rc = ptlrpc_set_wait(env, set);
2952 ptlrpc_set_destroy(set);
2955 rc = laia->laia_result;
2957 if (rc == -EALREADY)
2961 CERROR("%s: fail to stop LFSCK on some MDTs: rc = %d\n",
2962 lfsck_lfsck2name(lfsck), rc);
2964 RETURN(rc != 0 ? rc : rc1);
2967 static int lfsck_start_all(const struct lu_env *env,
2968 struct lfsck_instance *lfsck,
2969 struct lfsck_start *start)
2971 struct lfsck_thread_info *info = lfsck_env_info(env);
2972 struct lfsck_request *lr = &info->lti_lr;
2973 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2974 struct ptlrpc_request_set *set;
2975 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2976 struct lfsck_tgt_desc *ltd;
2977 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2983 LASSERT(start->ls_flags & LPF_BROADCAST);
2985 memset(lr, 0, sizeof(*lr));
2986 lr->lr_event = LE_START;
2987 lr->lr_index = lfsck_dev_idx(lfsck);
2988 lr->lr_speed = bk->lb_speed_limit;
2989 lr->lr_version = bk->lb_version;
2990 lr->lr_active = start->ls_active;
2991 lr->lr_param = start->ls_flags;
2992 lr->lr_async_windows = bk->lb_async_windows;
2993 lr->lr_valid = LSV_SPEED_LIMIT | LSV_ERROR_HANDLE | LSV_DRYRUN |
2994 LSV_ASYNC_WINDOWS | LSV_CREATE_OSTOBJ |
2997 memset(laia, 0, sizeof(*laia));
2998 laia->laia_ltds = ltds;
3000 laia->laia_shared = 1;
3003 set = ptlrpc_prep_set();
3007 down_read(<ds->ltd_rw_sem);
3008 for_each_set_bit(idx, ltds->ltd_tgts_bitmap, ltds->ltd_tgts_mask_len) {
3009 ltd = lfsck_tgt_get(ltds, idx);
3010 LASSERT(ltd != NULL);
3012 if (retry && !ltd->ltd_retry_start) {
3017 laia->laia_ltd = ltd;
3018 ltd->ltd_retry_start = 0;
3019 ltd->ltd_layout_done = 0;
3020 ltd->ltd_namespace_done = 0;
3021 ltd->ltd_synced_failures = 0;
3022 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
3023 lfsck_async_interpret, laia,
3026 lfsck_interpret(env, lfsck, NULL, laia, rc);
3028 CERROR("%s: cannot notify MDT %x for LFSCK "
3029 "start, failout: rc = %d\n",
3030 lfsck_lfsck2name(lfsck), idx, rc);
3034 up_read(<ds->ltd_rw_sem);
3037 ptlrpc_set_destroy(set);
3042 rc = ptlrpc_set_wait(env, set);
3043 ptlrpc_set_destroy(set);
3046 rc = laia->laia_result;
3048 if (unlikely(rc == -EINPROGRESS)) {
3050 schedule_timeout_interruptible(cfs_time_seconds(1));
3051 set_current_state(TASK_RUNNING);
3052 if (!signal_pending(current) &&
3053 thread_is_running(&lfsck->li_thread))
3060 struct lfsck_stop *stop = &info->lti_stop;
3062 CERROR("%s: cannot start LFSCK on some MDTs, "
3063 "stop all: rc = %d\n",
3064 lfsck_lfsck2name(lfsck), rc);
3065 if (rc != -EALREADY) {
3066 stop->ls_status = LS_FAILED;
3067 stop->ls_flags = LPF_ALL_TGT | LPF_BROADCAST;
3068 lfsck_stop_all(env, lfsck, stop);
3075 int lfsck_start(const struct lu_env *env, struct dt_device *key,
3076 struct lfsck_start_param *lsp)
3078 struct lfsck_start *start = lsp->lsp_start;
3079 struct lfsck_instance *lfsck;
3080 struct lfsck_bookmark *bk;
3081 struct ptlrpc_thread *thread;
3082 struct lfsck_component *com;
3083 struct lfsck_thread_args *lta;
3084 struct task_struct *task;
3085 struct lfsck_tgt_descs *ltds;
3086 struct lfsck_tgt_desc *ltd;
3097 lfsck = lfsck_instance_find(key, true, false);
3098 if (unlikely(lfsck == NULL))
3101 if (unlikely(lfsck->li_stopping))
3102 GOTO(put, rc = -ENXIO);
3104 /* System is not ready, try again later. */
3105 if (unlikely(lfsck->li_namespace == NULL ||
3106 lfsck_dev_site(lfsck)->ss_server_fld == NULL))
3107 GOTO(put, rc = -EINPROGRESS);
3109 /* start == NULL means auto trigger paused LFSCK. */
3111 if (list_empty(&lfsck->li_list_scan) ||
3112 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AUTO))
3114 } else if (start->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3115 CERROR("%s: only allow to specify '-A | -o' via MDS\n",
3116 lfsck_lfsck2name(lfsck));
3118 GOTO(put, rc = -EPERM);
3121 bk = &lfsck->li_bookmark_ram;
3122 thread = &lfsck->li_thread;
3123 mutex_lock(&lfsck->li_mutex);
3124 spin_lock(&lfsck->li_lock);
3125 if (unlikely(thread_is_stopping(thread))) {
3126 /* Someone is stopping the LFSCK. */
3127 spin_unlock(&lfsck->li_lock);
3128 GOTO(out, rc = -EBUSY);
3131 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
3133 if (unlikely(start == NULL)) {
3134 spin_unlock(&lfsck->li_lock);
3138 while (start->ls_active != 0) {
3139 if (!(type & start->ls_active)) {
3144 com = __lfsck_component_find(lfsck, type,
3145 &lfsck->li_list_scan);
3147 com = __lfsck_component_find(lfsck, type,
3148 &lfsck->li_list_double_scan);
3154 if (com->lc_ops->lfsck_join != NULL) {
3155 rc = com->lc_ops->lfsck_join( env, com, lsp);
3156 if (rc != 0 && rc != -EALREADY)
3159 start->ls_active &= ~type;
3162 spin_unlock(&lfsck->li_lock);
3165 spin_unlock(&lfsck->li_lock);
3167 lfsck->li_status = 0;
3168 lfsck->li_oit_over = 0;
3169 lfsck->li_start_unplug = 0;
3170 lfsck->li_drop_dryrun = 0;
3171 lfsck->li_new_scanned = 0;
3173 /* For auto trigger. */
3177 start->ls_version = bk->lb_version;
3179 if (start->ls_active != 0) {
3180 struct lfsck_component *next;
3182 if (start->ls_active == LFSCK_TYPES_ALL)
3183 start->ls_active = LFSCK_TYPES_SUPPORTED;
3185 if (start->ls_active & ~LFSCK_TYPES_SUPPORTED) {
3186 start->ls_active &= ~LFSCK_TYPES_SUPPORTED;
3187 GOTO(out, rc = -ENOTSUPP);
3190 list_for_each_entry_safe(com, next,
3191 &lfsck->li_list_scan, lc_link) {
3192 if (!(com->lc_type & start->ls_active)) {
3193 rc = com->lc_ops->lfsck_post(env, com, 0,
3200 while (start->ls_active != 0) {
3201 if (type & start->ls_active) {
3202 com = __lfsck_component_find(lfsck, type,
3203 &lfsck->li_list_idle);
3205 /* The component status will be updated
3206 * when its prep() is called later by
3207 * the LFSCK main engine. */
3208 list_move_tail(&com->lc_link,
3209 &lfsck->li_list_scan);
3210 start->ls_active &= ~type;
3216 if (list_empty(&lfsck->li_list_scan)) {
3217 /* The speed limit will be used to control both the LFSCK and
3218 * low layer scrub (if applied), need to be handled firstly. */
3219 if (start->ls_valid & LSV_SPEED_LIMIT) {
3220 if (__lfsck_set_speed(lfsck, start->ls_speed_limit)) {
3221 rc = lfsck_bookmark_store(env, lfsck);
3230 if (start->ls_flags & LPF_RESET)
3231 flags |= DOIF_RESET;
3233 rc = lfsck_set_param(env, lfsck, start, !!(flags & DOIF_RESET));
3237 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3238 start->ls_active |= com->lc_type;
3239 if (flags & DOIF_RESET) {
3240 rc = com->lc_ops->lfsck_reset(env, com, false);
3246 ltds = &lfsck->li_mdt_descs;
3247 down_read(<ds->ltd_rw_sem);
3248 for_each_set_bit(idx, ltds->ltd_tgts_bitmap, ltds->ltd_tgts_mask_len) {
3249 ltd = lfsck_ltd2tgt(ltds, idx);
3250 LASSERT(ltd != NULL);
3252 ltd->ltd_layout_done = 0;
3253 ltd->ltd_namespace_done = 0;
3254 ltd->ltd_synced_failures = 0;
3255 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_NAMESPACE);
3256 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3257 list_del_init(<d->ltd_layout_phase_list);
3258 list_del_init(<d->ltd_layout_list);
3259 list_del_init(<d->ltd_namespace_phase_list);
3260 list_del_init(<d->ltd_namespace_list);
3262 up_read(<ds->ltd_rw_sem);
3264 ltds = &lfsck->li_ost_descs;
3265 down_read(<ds->ltd_rw_sem);
3266 for_each_set_bit(idx, ltds->ltd_tgts_bitmap, ltds->ltd_tgts_mask_len) {
3267 ltd = lfsck_ltd2tgt(ltds, idx);
3268 LASSERT(ltd != NULL);
3270 ltd->ltd_layout_done = 0;
3271 ltd->ltd_synced_failures = 0;
3272 lfsck_reset_ltd_status(ltd, LFSCK_TYPE_LAYOUT);
3273 list_del_init(<d->ltd_layout_phase_list);
3274 list_del_init(<d->ltd_layout_list);
3276 up_read(<ds->ltd_rw_sem);
3279 lfsck->li_args_dir = LUDA_64BITHASH | LUDA_VERIFY | LUDA_TYPE;
3280 if (bk->lb_param & LPF_DRYRUN)
3281 lfsck->li_args_dir |= LUDA_VERIFY_DRYRUN;
3283 if (start != NULL && start->ls_valid & LSV_ERROR_HANDLE) {
3284 valid |= DOIV_ERROR_HANDLE;
3285 if (start->ls_flags & LPF_FAILOUT)
3286 flags |= DOIF_FAILOUT;
3289 if (start != NULL && start->ls_valid & LSV_DRYRUN) {
3290 valid |= DOIV_DRYRUN;
3291 if (start->ls_flags & LPF_DRYRUN)
3292 flags |= DOIF_DRYRUN;
3295 if (!list_empty(&lfsck->li_list_scan))
3296 flags |= DOIF_OUTUSED;
3298 lfsck->li_args_oit = (flags << DT_OTABLE_IT_FLAGS_SHIFT) | valid;
3299 lta = lfsck_thread_args_init(lfsck, NULL, lsp);
3301 GOTO(out, rc = PTR_ERR(lta));
3303 __lfsck_set_speed(lfsck, bk->lb_speed_limit);
3304 spin_lock(&lfsck->li_lock);
3305 thread_set_flags(thread, SVC_STARTING);
3306 spin_unlock(&lfsck->li_lock);
3307 task = kthread_run(lfsck_master_engine, lta, "lfsck");
3310 CERROR("%s: cannot start LFSCK thread: rc = %d\n",
3311 lfsck_lfsck2name(lfsck), rc);
3312 lfsck_thread_args_fini(lta);
3317 wait_event_idle(thread->t_ctl_waitq,
3318 thread_is_running(thread) ||
3319 thread_is_stopped(thread));
3320 if (start == NULL || !(start->ls_flags & LPF_BROADCAST)) {
3321 lfsck->li_start_unplug = 1;
3322 wake_up(&thread->t_ctl_waitq);
3327 /* release lfsck::li_mutex to avoid deadlock. */
3328 mutex_unlock(&lfsck->li_mutex);
3329 rc = lfsck_start_all(env, lfsck, start);
3331 spin_lock(&lfsck->li_lock);
3332 if (thread_is_stopped(thread)) {
3333 spin_unlock(&lfsck->li_lock);
3335 lfsck->li_status = LS_FAILED;
3336 lfsck->li_flags = 0;
3337 thread_set_flags(thread, SVC_STOPPING);
3338 spin_unlock(&lfsck->li_lock);
3340 lfsck->li_start_unplug = 1;
3341 wake_up(&thread->t_ctl_waitq);
3342 wait_event_idle(thread->t_ctl_waitq,
3343 thread_is_stopped(thread));
3346 lfsck->li_start_unplug = 1;
3347 wake_up(&thread->t_ctl_waitq);
3353 mutex_unlock(&lfsck->li_mutex);
3356 lfsck_instance_put(env, lfsck);
3358 return rc < 0 ? rc : 0;
3360 EXPORT_SYMBOL(lfsck_start);
3362 int lfsck_stop(const struct lu_env *env, struct dt_device *key,
3363 struct lfsck_stop *stop)
3365 struct lfsck_instance *lfsck;
3366 struct ptlrpc_thread *thread;
3371 lfsck = lfsck_instance_find(key, true, false);
3372 if (unlikely(lfsck == NULL))
3375 thread = &lfsck->li_thread;
3376 if (stop && stop->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
3377 CERROR("%s: only allow to specify '-A' via MDS\n",
3378 lfsck_lfsck2name(lfsck));
3379 GOTO(put, rc = -EPERM);
3382 spin_lock(&lfsck->li_lock);
3383 /* The target is umounted */
3384 if (stop && stop->ls_status == LS_PAUSED)
3385 lfsck->li_stopping = 1;
3387 if (thread_is_init(thread) || thread_is_stopped(thread))
3388 /* no error if LFSCK stopped already, or not started */
3389 GOTO(unlock, rc = 0);
3391 if (thread_is_stopping(thread))
3392 /* Someone is stopping LFSCK. */
3393 GOTO(unlock, rc = -EINPROGRESS);
3396 lfsck->li_status = stop->ls_status;
3397 lfsck->li_flags = stop->ls_flags;
3399 lfsck->li_status = LS_STOPPED;
3400 lfsck->li_flags = 0;
3403 thread_set_flags(thread, SVC_STOPPING);
3405 LASSERT(lfsck->li_task != NULL);
3406 cfs_force_sig(SIGINT, lfsck->li_task);
3408 if (lfsck->li_master) {
3409 struct lfsck_component *com;
3410 struct lfsck_assistant_data *lad;
3412 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
3414 spin_lock(&lad->lad_lock);
3415 if (lad->lad_task != NULL)
3416 cfs_force_sig(SIGINT, lad->lad_task);
3417 spin_unlock(&lad->lad_lock);
3420 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
3422 spin_lock(&lad->lad_lock);
3423 if (lad->lad_task != NULL)
3424 cfs_force_sig(SIGINT, lad->lad_task);
3425 spin_unlock(&lad->lad_lock);
3429 wake_up(&thread->t_ctl_waitq);
3430 spin_unlock(&lfsck->li_lock);
3431 if (stop && stop->ls_flags & LPF_BROADCAST)
3432 rc1 = lfsck_stop_all(env, lfsck, stop);
3434 /* It was me set the status as 'stopping' just now, if it is not
3435 * 'stopping' now, then either stopped, or re-started by race. */
3436 wait_event_idle(thread->t_ctl_waitq,
3437 !thread_is_stopping(thread));
3442 spin_unlock(&lfsck->li_lock);
3444 lfsck_instance_put(env, lfsck);
3446 return rc != 0 ? rc : rc1;
3448 EXPORT_SYMBOL(lfsck_stop);
3450 int lfsck_in_notify_local(const struct lu_env *env, struct dt_device *key,
3451 struct lfsck_req_local *lrl, struct thandle *th)
3453 struct lfsck_instance *lfsck;
3454 struct lfsck_component *com;
3455 int rc = -EOPNOTSUPP;
3458 lfsck = lfsck_instance_find(key, true, false);
3459 if (unlikely(!lfsck))
3462 com = lfsck_component_find(lfsck, lrl->lrl_active);
3463 if (likely(com && com->lc_ops->lfsck_in_notify_local)) {
3464 rc = com->lc_ops->lfsck_in_notify_local(env, com, lrl, th);
3465 lfsck_component_put(env, com);
3468 lfsck_instance_put(env, lfsck);
3472 EXPORT_SYMBOL(lfsck_in_notify_local);
3474 int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
3475 struct lfsck_request *lr)
3477 int rc = -EOPNOTSUPP;
3480 switch (lr->lr_event) {
3482 struct lfsck_start *start = &lfsck_env_info(env)->lti_start;
3483 struct lfsck_start_param lsp;
3485 memset(start, 0, sizeof(*start));
3486 start->ls_valid = lr->lr_valid;
3487 start->ls_speed_limit = lr->lr_speed;
3488 start->ls_version = lr->lr_version;
3489 start->ls_active = lr->lr_active;
3490 start->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3491 start->ls_async_windows = lr->lr_async_windows;
3493 lsp.lsp_start = start;
3494 lsp.lsp_index = lr->lr_index;
3495 lsp.lsp_index_valid = 1;
3496 rc = lfsck_start(env, key, &lsp);
3500 struct lfsck_stop *stop = &lfsck_env_info(env)->lti_stop;
3502 memset(stop, 0, sizeof(*stop));
3503 stop->ls_status = lr->lr_status;
3504 stop->ls_flags = lr->lr_param & ~LPF_BROADCAST;
3505 rc = lfsck_stop(env, key, stop);
3508 case LE_PHASE1_DONE:
3509 case LE_PHASE2_DONE:
3511 case LE_CONDITIONAL_DESTROY:
3512 case LE_SET_LMV_MASTER:
3513 case LE_SET_LMV_SLAVE:
3514 case LE_PAIRS_VERIFY: {
3515 struct lfsck_instance *lfsck;
3516 struct lfsck_component *com;
3518 lfsck = lfsck_instance_find(key, true, false);
3519 if (unlikely(lfsck == NULL))
3522 com = lfsck_component_find(lfsck, lr->lr_active);
3524 rc = com->lc_ops->lfsck_in_notify(env, com, lr);
3525 lfsck_component_put(env, com);
3528 lfsck_instance_put(env, lfsck);
3537 EXPORT_SYMBOL(lfsck_in_notify);
3539 int lfsck_query(const struct lu_env *env, struct dt_device *key,
3540 struct lfsck_request *req, struct lfsck_reply *rep,
3541 struct lfsck_query *que)
3543 struct lfsck_instance *lfsck;
3544 struct lfsck_component *com;
3550 lfsck = lfsck_instance_find(key, true, false);
3551 if (unlikely(lfsck == NULL))
3555 if (que->lu_types == LFSCK_TYPES_ALL)
3557 LFSCK_TYPES_SUPPORTED & ~LFSCK_TYPE_SCRUB;
3559 if (que->lu_types & ~LFSCK_TYPES_SUPPORTED) {
3560 que->lu_types &= ~LFSCK_TYPES_SUPPORTED;
3562 GOTO(out, rc = -ENOTSUPP);
3565 for (i = 0, type = BIT(i); i < LFSCK_TYPE_BITS;
3566 i++, type = BIT(i)) {
3567 if (!(que->lu_types & type))
3571 com = lfsck_component_find(lfsck, type);
3572 if (unlikely(com == NULL))
3573 GOTO(out, rc = -ENOTSUPP);
3575 memset(que->lu_mdts_count[i], 0,
3576 sizeof(__u32) * (LS_MAX + 1));
3577 memset(que->lu_osts_count[i], 0,
3578 sizeof(__u32) * (LS_MAX + 1));
3579 que->lu_repaired[i] = 0;
3580 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3582 lfsck_component_put(env, com);
3587 if (!(que->lu_flags & LPF_WAIT))
3590 for (i = 0, type = BIT(i); i < LFSCK_TYPE_BITS;
3591 i++, type = BIT(i)) {
3592 if (!(que->lu_types & type))
3595 if (que->lu_mdts_count[i][LS_SCANNING_PHASE1] != 0 ||
3596 que->lu_mdts_count[i][LS_SCANNING_PHASE2] != 0 ||
3597 que->lu_osts_count[i][LS_SCANNING_PHASE1] != 0 ||
3598 que->lu_osts_count[i][LS_SCANNING_PHASE2] != 0) {
3599 /* If it is required to wait, then sleep
3600 * 3 seconds and try to query again.
3602 unsigned long timeout =
3603 msecs_to_jiffies(3000) + 1;
3605 !fatal_signal_pending(current))
3606 timeout = schedule_timeout_killable(
3613 com = lfsck_component_find(lfsck, req->lr_active);
3614 if (likely(com != NULL)) {
3615 rc = com->lc_ops->lfsck_query(env, com, req, rep,
3617 lfsck_component_put(env, com);
3626 lfsck_instance_put(env, lfsck);
3629 EXPORT_SYMBOL(lfsck_query);
3631 int lfsck_register_namespace(const struct lu_env *env, struct dt_device *key,
3632 struct ldlm_namespace *ns)
3634 struct lfsck_instance *lfsck;
3637 lfsck = lfsck_instance_find(key, true, false);
3638 if (likely(lfsck != NULL)) {
3639 lfsck->li_namespace = ns;
3640 lfsck_instance_put(env, lfsck);
3646 EXPORT_SYMBOL(lfsck_register_namespace);
3648 int lfsck_register(const struct lu_env *env, struct dt_device *key,
3649 struct dt_device *next, struct obd_device *obd,
3650 lfsck_out_notify notify, void *notify_data, bool master)
3652 struct lfsck_instance *lfsck;
3653 struct dt_object *root = NULL;
3654 struct dt_object *obj = NULL;
3655 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
3659 lfsck = lfsck_instance_find(key, false, false);
3660 if (unlikely(lfsck != NULL))
3663 OBD_ALLOC_PTR(lfsck);
3667 mutex_init(&lfsck->li_mutex);
3668 spin_lock_init(&lfsck->li_lock);
3669 INIT_LIST_HEAD(&lfsck->li_link);
3670 INIT_LIST_HEAD(&lfsck->li_list_scan);
3671 INIT_LIST_HEAD(&lfsck->li_list_dir);
3672 INIT_LIST_HEAD(&lfsck->li_list_double_scan);
3673 INIT_LIST_HEAD(&lfsck->li_list_idle);
3674 INIT_LIST_HEAD(&lfsck->li_list_lmv);
3675 atomic_set(&lfsck->li_ref, 1);
3676 atomic_set(&lfsck->li_double_scan_count, 0);
3677 init_waitqueue_head(&lfsck->li_thread.t_ctl_waitq);
3678 lfsck->li_out_notify = notify;
3679 lfsck->li_out_notify_data = notify_data;
3680 lfsck->li_next = next;
3681 lfsck->li_bottom = key;
3682 lfsck->li_obd = obd;
3684 rc = lfsck_tgt_descs_init(&lfsck->li_ost_descs);
3688 rc = lfsck_tgt_descs_init(&lfsck->li_mdt_descs);
3692 fid->f_seq = FID_SEQ_LOCAL_NAME;
3695 rc = local_oid_storage_init(env, key, fid, &lfsck->li_los);
3699 rc = dt_root_get(env, key, fid);
3703 root = dt_locate(env, key, fid);
3705 GOTO(out, rc = PTR_ERR(root));
3707 lfsck->li_local_root_fid = *fid;
3709 lfsck->li_master = 1;
3710 if (lfsck_dev_idx(lfsck) == 0) {
3711 struct lu_fid *pfid = &lfsck_env_info(env)->lti_fid2;
3712 const struct lu_name *cname;
3714 rc = dt_lookup_dir(env, root, "ROOT",
3715 &lfsck->li_global_root_fid);
3719 obj = dt_locate(env, key, &lfsck->li_global_root_fid);
3721 GOTO(out, rc = PTR_ERR(obj));
3723 rc = dt_lookup_dir(env, obj, dotlustre, fid);
3727 lfsck_object_put(env, obj);
3728 obj = dt_locate(env, key, fid);
3730 GOTO(out, rc = PTR_ERR(obj));
3732 cname = lfsck_name_get_const(env, dotlustre,
3734 rc = lfsck_verify_linkea(env, lfsck, obj, cname,
3735 &lfsck->li_global_root_fid);
3740 rc = dt_lookup_dir(env, obj, lostfound, fid);
3744 lfsck_object_put(env, obj);
3745 obj = dt_locate(env, key, fid);
3747 GOTO(out, rc = PTR_ERR(obj));
3749 cname = lfsck_name_get_const(env, lostfound,
3751 rc = lfsck_verify_linkea(env, lfsck, obj, cname, pfid);
3755 lfsck_object_put(env, obj);
3760 fid->f_seq = FID_SEQ_LOCAL_FILE;
3761 fid->f_oid = OTABLE_IT_OID;
3763 obj = dt_locate(env, key, fid);
3765 GOTO(out, rc = PTR_ERR(obj));
3767 rc = obj->do_ops->do_index_try(env, obj, &dt_otable_features);
3771 lfsck->li_obj_oit = obj;
3772 obj = local_file_find_or_create(env, lfsck->li_los, root, LFSCK_DIR,
3773 S_IFDIR | S_IRUGO | S_IWUSR);
3775 GOTO(out, rc = PTR_ERR(obj));
3777 lu_object_get(&obj->do_lu);
3778 lfsck->li_lfsck_dir = obj;
3779 rc = lfsck_bookmark_setup(env, lfsck);
3784 rc = lfsck_fid_init(lfsck);
3788 rc = lfsck_namespace_setup(env, lfsck);
3793 rc = lfsck_layout_setup(env, lfsck);
3797 /* XXX: more LFSCK components initialization to be added here. */
3799 rc = lfsck_instance_add(lfsck);
3801 rc = lfsck_add_target_from_orphan(env, lfsck);
3803 if (obj != NULL && !IS_ERR(obj))
3804 lfsck_object_put(env, obj);
3805 if (root != NULL && !IS_ERR(root))
3806 lfsck_object_put(env, root);
3808 lfsck_instance_cleanup(env, lfsck);
3811 EXPORT_SYMBOL(lfsck_register);
3813 void lfsck_degister(const struct lu_env *env, struct dt_device *key)
3815 struct lfsck_instance *lfsck;
3817 lfsck = lfsck_instance_find(key, false, true);
3819 lfsck_instance_put(env, lfsck);
3821 EXPORT_SYMBOL(lfsck_degister);
3823 int lfsck_add_target(const struct lu_env *env, struct dt_device *key,
3824 struct dt_device *tgt, struct obd_export *exp,
3825 __u32 index, bool for_ost)
3827 struct lfsck_instance *lfsck;
3828 struct lfsck_tgt_desc *ltd;
3839 INIT_LIST_HEAD(<d->ltd_orphan_list);
3840 INIT_LIST_HEAD(<d->ltd_layout_list);
3841 INIT_LIST_HEAD(<d->ltd_layout_phase_list);
3842 INIT_LIST_HEAD(<d->ltd_namespace_list);
3843 INIT_LIST_HEAD(<d->ltd_namespace_phase_list);
3844 atomic_set(<d->ltd_ref, 1);
3845 ltd->ltd_index = index;
3847 spin_lock(&lfsck_instance_lock);
3848 lfsck = __lfsck_instance_find(key, true, false);
3849 if (lfsck == NULL) {
3851 list_add_tail(<d->ltd_orphan_list,
3852 &lfsck_ost_orphan_list);
3854 list_add_tail(<d->ltd_orphan_list,
3855 &lfsck_mdt_orphan_list);
3856 spin_unlock(&lfsck_instance_lock);
3860 spin_unlock(&lfsck_instance_lock);
3862 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, false);
3866 lfsck_instance_put(env, lfsck);
3870 EXPORT_SYMBOL(lfsck_add_target);
3872 void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
3873 struct dt_device *tgt, __u32 index, bool for_ost)
3875 struct lfsck_instance *lfsck;
3876 struct lfsck_tgt_descs *ltds;
3877 struct lfsck_tgt_desc *ltd;
3878 struct list_head *head;
3881 head = &lfsck_ost_orphan_list;
3883 head = &lfsck_mdt_orphan_list;
3885 spin_lock(&lfsck_instance_lock);
3886 list_for_each_entry(ltd, head, ltd_orphan_list) {
3887 if (ltd->ltd_tgt == tgt) {
3888 list_del_init(<d->ltd_orphan_list);
3889 spin_unlock(&lfsck_instance_lock);
3897 lfsck = __lfsck_instance_find(key, true, false);
3898 spin_unlock(&lfsck_instance_lock);
3899 if (unlikely(lfsck == NULL))
3903 ltds = &lfsck->li_ost_descs;
3905 ltds = &lfsck->li_mdt_descs;
3907 down_write(<ds->ltd_rw_sem);
3908 LASSERT(ltds->ltd_tgts_bitmap);
3910 if (unlikely(index >= ltds->ltd_tgts_mask_len))
3913 ltd = lfsck_ltd2tgt(ltds, index);
3914 if (unlikely(ltd == NULL))
3917 LASSERT(ltds->ltd_tgtnr > 0);
3920 set_bit(index, ltds->ltd_tgts_bitmap);
3921 lfsck_assign_tgt(ltds, NULL, index);
3926 head = &lfsck->li_ost_descs.ltd_orphan;
3928 head = &lfsck->li_mdt_descs.ltd_orphan;
3930 list_for_each_entry(ltd, head, ltd_orphan_list) {
3931 if (ltd->ltd_tgt == tgt) {
3932 list_del_init(<d->ltd_orphan_list);
3938 up_write(<ds->ltd_rw_sem);
3940 spin_lock(<ds->ltd_lock);
3942 spin_unlock(<ds->ltd_lock);
3943 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_NAMESPACE);
3944 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_LAYOUT);
3948 lfsck_instance_put(env, lfsck);
3950 EXPORT_SYMBOL(lfsck_del_target);
3952 static int __init lfsck_init(void)
3956 lfsck_key_init_generic(&lfsck_thread_key, NULL);
3957 rc = lu_context_key_register(&lfsck_thread_key);
3959 tgt_register_lfsck_in_notify_local(lfsck_in_notify_local);
3960 tgt_register_lfsck_in_notify(lfsck_in_notify);
3961 tgt_register_lfsck_query(lfsck_query);
3967 static void __exit lfsck_exit(void)
3969 struct lfsck_tgt_desc *ltd;
3970 struct lfsck_tgt_desc *next;
3972 LASSERT(list_empty(&lfsck_instance_list));
3974 list_for_each_entry_safe(ltd, next, &lfsck_ost_orphan_list,
3976 list_del_init(<d->ltd_orphan_list);
3980 list_for_each_entry_safe(ltd, next, &lfsck_mdt_orphan_list,
3982 list_del_init(<d->ltd_orphan_list);
3986 lu_context_key_degister(&lfsck_thread_key);
3989 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3990 MODULE_DESCRIPTION("Lustre File System Checker");
3991 MODULE_VERSION(LUSTRE_VERSION_STRING);
3992 MODULE_LICENSE("GPL");
3994 module_init(lfsck_init);
3995 module_exit(lfsck_exit);