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) 2012, 2013, Intel Corporation.
26 * lustre/lfsck/lfsck_lib.c
28 * Author: Fan, Yong <fan.yong@intel.com>
31 #define DEBUG_SUBSYSTEM S_LFSCK
33 #include <libcfs/list.h>
34 #include <lu_object.h>
35 #include <dt_object.h>
36 #include <md_object.h>
37 #include <lustre_fld.h>
38 #include <lustre_lib.h>
39 #include <lustre_net.h>
40 #include <lustre_lfsck.h>
41 #include <lustre/lustre_lfsck_user.h>
43 #include "lfsck_internal.h"
45 #define LFSCK_CHECKPOINT_SKIP 1
47 /* define lfsck thread key */
48 LU_KEY_INIT(lfsck, struct lfsck_thread_info);
50 static void lfsck_key_fini(const struct lu_context *ctx,
51 struct lu_context_key *key, void *data)
53 struct lfsck_thread_info *info = data;
55 lu_buf_free(&info->lti_linkea_buf);
56 lu_buf_free(&info->lti_big_buf);
60 LU_CONTEXT_KEY_DEFINE(lfsck, LCT_MD_THREAD | LCT_DT_THREAD);
61 LU_KEY_INIT_GENERIC(lfsck);
63 static struct list_head lfsck_instance_list;
64 static struct list_head lfsck_ost_orphan_list;
65 static struct list_head lfsck_mdt_orphan_list;
66 static DEFINE_SPINLOCK(lfsck_instance_lock);
68 static const char *lfsck_status_names[] = {
70 [LS_SCANNING_PHASE1] = "scanning-phase1",
71 [LS_SCANNING_PHASE2] = "scanning-phase2",
72 [LS_COMPLETED] = "completed",
73 [LS_FAILED] = "failed",
74 [LS_STOPPED] = "stopped",
75 [LS_PAUSED] = "paused",
76 [LS_CRASHED] = "crashed",
77 [LS_PARTIAL] = "partial",
78 [LS_CO_FAILED] = "co-failed",
79 [LS_CO_STOPPED] = "co-stopped",
80 [LS_CO_PAUSED] = "co-paused"
83 const char *lfsck_flags_names[] = {
92 const char *lfsck_param_names[] = {
103 enum lfsck_verify_lpf_types {
104 LVLT_BY_BOOKMARK = 0,
105 LVLT_BY_NAMEENTRY = 1,
108 const char *lfsck_status2names(enum lfsck_status status)
110 if (unlikely(status < 0 || status >= LS_MAX))
113 return lfsck_status_names[status];
116 static int lfsck_tgt_descs_init(struct lfsck_tgt_descs *ltds)
118 spin_lock_init(<ds->ltd_lock);
119 init_rwsem(<ds->ltd_rw_sem);
120 INIT_LIST_HEAD(<ds->ltd_orphan);
121 ltds->ltd_tgts_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
122 if (ltds->ltd_tgts_bitmap == NULL)
128 static void lfsck_tgt_descs_fini(struct lfsck_tgt_descs *ltds)
130 struct lfsck_tgt_desc *ltd;
131 struct lfsck_tgt_desc *next;
134 down_write(<ds->ltd_rw_sem);
136 list_for_each_entry_safe(ltd, next, <ds->ltd_orphan,
138 list_del_init(<d->ltd_orphan_list);
142 if (unlikely(ltds->ltd_tgts_bitmap == NULL)) {
143 up_write(<ds->ltd_rw_sem);
148 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
149 ltd = LTD_TGT(ltds, idx);
150 if (likely(ltd != NULL)) {
151 LASSERT(list_empty(<d->ltd_layout_list));
152 LASSERT(list_empty(<d->ltd_layout_phase_list));
153 LASSERT(list_empty(<d->ltd_namespace_list));
154 LASSERT(list_empty(<d->ltd_namespace_phase_list));
157 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, idx);
158 LTD_TGT(ltds, idx) = NULL;
163 LASSERTF(ltds->ltd_tgtnr == 0, "tgt count unmatched: %d\n",
166 for (idx = 0; idx < TGT_PTRS; idx++) {
167 if (ltds->ltd_tgts_idx[idx] != NULL) {
168 OBD_FREE_PTR(ltds->ltd_tgts_idx[idx]);
169 ltds->ltd_tgts_idx[idx] = NULL;
173 CFS_FREE_BITMAP(ltds->ltd_tgts_bitmap);
174 ltds->ltd_tgts_bitmap = NULL;
175 up_write(<ds->ltd_rw_sem);
178 static int __lfsck_add_target(const struct lu_env *env,
179 struct lfsck_instance *lfsck,
180 struct lfsck_tgt_desc *ltd,
181 bool for_ost, bool locked)
183 struct lfsck_tgt_descs *ltds;
184 __u32 index = ltd->ltd_index;
189 ltds = &lfsck->li_ost_descs;
191 ltds = &lfsck->li_mdt_descs;
194 down_write(<ds->ltd_rw_sem);
196 LASSERT(ltds->ltd_tgts_bitmap != NULL);
198 if (index >= ltds->ltd_tgts_bitmap->size) {
199 __u32 newsize = max((__u32)ltds->ltd_tgts_bitmap->size,
200 (__u32)BITS_PER_LONG);
201 cfs_bitmap_t *old_bitmap = ltds->ltd_tgts_bitmap;
202 cfs_bitmap_t *new_bitmap;
204 while (newsize < index + 1)
207 new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
208 if (new_bitmap == NULL)
209 GOTO(unlock, rc = -ENOMEM);
211 if (ltds->ltd_tgtnr > 0)
212 cfs_bitmap_copy(new_bitmap, old_bitmap);
213 ltds->ltd_tgts_bitmap = new_bitmap;
214 CFS_FREE_BITMAP(old_bitmap);
217 if (cfs_bitmap_check(ltds->ltd_tgts_bitmap, index)) {
218 CERROR("%s: the device %s (%u) is registered already\n",
219 lfsck_lfsck2name(lfsck),
220 ltd->ltd_tgt->dd_lu_dev.ld_obd->obd_name, index);
221 GOTO(unlock, rc = -EEXIST);
224 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
225 OBD_ALLOC_PTR(ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK]);
226 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL)
227 GOTO(unlock, rc = -ENOMEM);
230 LTD_TGT(ltds, index) = ltd;
231 cfs_bitmap_set(ltds->ltd_tgts_bitmap, index);
234 GOTO(unlock, rc = 0);
238 up_write(<ds->ltd_rw_sem);
243 static int lfsck_add_target_from_orphan(const struct lu_env *env,
244 struct lfsck_instance *lfsck)
246 struct lfsck_tgt_descs *ltds = &lfsck->li_ost_descs;
247 struct lfsck_tgt_desc *ltd;
248 struct lfsck_tgt_desc *next;
249 struct list_head *head = &lfsck_ost_orphan_list;
254 spin_lock(&lfsck_instance_lock);
255 list_for_each_entry_safe(ltd, next, head, ltd_orphan_list) {
256 if (ltd->ltd_key == lfsck->li_bottom)
257 list_move_tail(<d->ltd_orphan_list,
260 spin_unlock(&lfsck_instance_lock);
262 down_write(<ds->ltd_rw_sem);
263 while (!list_empty(<ds->ltd_orphan)) {
264 ltd = list_entry(ltds->ltd_orphan.next,
265 struct lfsck_tgt_desc,
267 list_del_init(<d->ltd_orphan_list);
268 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, true);
269 /* Do not hold the semaphore for too long time. */
270 up_write(<ds->ltd_rw_sem);
274 down_write(<ds->ltd_rw_sem);
276 up_write(<ds->ltd_rw_sem);
279 ltds = &lfsck->li_mdt_descs;
280 head = &lfsck_mdt_orphan_list;
288 static inline struct lfsck_component *
289 __lfsck_component_find(struct lfsck_instance *lfsck, __u16 type,
290 struct list_head *list)
292 struct lfsck_component *com;
294 list_for_each_entry(com, list, lc_link) {
295 if (com->lc_type == type)
301 struct lfsck_component *
302 lfsck_component_find(struct lfsck_instance *lfsck, __u16 type)
304 struct lfsck_component *com;
306 spin_lock(&lfsck->li_lock);
307 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
311 com = __lfsck_component_find(lfsck, type,
312 &lfsck->li_list_double_scan);
316 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_idle);
320 lfsck_component_get(com);
321 spin_unlock(&lfsck->li_lock);
325 void lfsck_component_cleanup(const struct lu_env *env,
326 struct lfsck_component *com)
328 if (!list_empty(&com->lc_link))
329 list_del_init(&com->lc_link);
330 if (!list_empty(&com->lc_link_dir))
331 list_del_init(&com->lc_link_dir);
333 lfsck_component_put(env, com);
336 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
337 struct lu_fid *fid, bool locked)
339 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
344 mutex_lock(&lfsck->li_mutex);
346 rc = seq_client_alloc_fid(env, lfsck->li_seq, fid);
348 bk->lb_last_fid = *fid;
349 /* We do not care about whether the subsequent sub-operations
350 * failed or not. The worst case is that one FID is lost that
351 * is not a big issue for the LFSCK since it is relative rare
352 * for LFSCK create. */
353 rc = lfsck_bookmark_store(env, lfsck);
357 mutex_unlock(&lfsck->li_mutex);
363 * Request the specified ibits lock for the given object.
365 * Before the LFSCK modifying on the namespace visible object,
366 * it needs to acquire related ibits ldlm lock.
368 * \param[in] env pointer to the thread context
369 * \param[in] lfsck pointer to the lfsck instance
370 * \param[in] obj pointer to the dt_object to be locked
371 * \param[out] lh pointer to the lock handle
372 * \param[in] ibits the bits for the ldlm lock to be acquired
373 * \param[in] mode the mode for the ldlm lock to be acquired
375 * \retval 0 for success
376 * \retval negative error number on failure
378 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
379 struct dt_object *obj, struct lustre_handle *lh,
380 __u64 bits, ldlm_mode_t mode)
382 struct lfsck_thread_info *info = lfsck_env_info(env);
383 ldlm_policy_data_t *policy = &info->lti_policy;
384 struct ldlm_res_id *resid = &info->lti_resid;
385 __u64 flags = LDLM_FL_ATOMIC_CB;
388 LASSERT(lfsck->li_namespace != NULL);
390 memset(policy, 0, sizeof(*policy));
391 policy->l_inodebits.bits = bits;
392 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
393 rc = ldlm_cli_enqueue_local(lfsck->li_namespace, resid, LDLM_IBITS,
394 policy, mode, &flags, ldlm_blocking_ast,
395 ldlm_completion_ast, NULL, NULL, 0,
396 LVB_T_NONE, NULL, lh);
397 if (rc == ELDLM_OK) {
400 memset(lh, 0, sizeof(*lh));
408 * Release the the specified ibits lock.
410 * If the lock has been acquired before, release it
411 * and cleanup the handle. Otherwise, do nothing.
413 * \param[in] lh pointer to the lock handle
414 * \param[in] mode the mode for the ldlm lock to be released
416 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode)
418 if (lustre_handle_is_used(lh)) {
419 ldlm_lock_decref(lh, mode);
420 memset(lh, 0, sizeof(*lh));
424 static const char dot[] = ".";
425 static const char dotdot[] = "..";
426 static const char dotlustre[] = ".lustre";
427 static const char lostfound[] = "lost+found";
429 static int lfsck_create_lpf_local(const struct lu_env *env,
430 struct lfsck_instance *lfsck,
431 struct dt_object *parent,
432 struct dt_object *child,
434 struct dt_object_format *dof,
437 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
438 struct dt_device *dev = lfsck->li_bottom;
439 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
440 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
441 const struct lu_fid *cfid = lfsck_dto2fid(child);
442 struct thandle *th = NULL;
443 struct linkea_data ldata = { 0 };
444 struct lu_buf linkea_buf;
445 const struct lu_name *cname;
447 int len = sizeof(struct lfsck_bookmark);
451 rc = linkea_data_new(&ldata,
452 &lfsck_env_info(env)->lti_linkea_buf);
456 cname = lfsck_name_get_const(env, name, strlen(name));
457 rc = linkea_add_buf(&ldata, cname, lfsck_dto2fid(parent));
461 th = dt_trans_create(env, dev);
465 /* 1a. create child */
466 rc = dt_declare_create(env, child, la, NULL, dof, th);
470 /* 2a. increase child nlink */
471 rc = dt_declare_ref_add(env, child, th);
475 /* 3a. insert linkEA for child */
476 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
477 ldata.ld_leh->leh_len);
478 rc = dt_declare_xattr_set(env, child, &linkea_buf,
479 XATTR_NAME_LINK, 0, th);
483 /* 4a. insert name into parent dir */
484 rec->rec_type = S_IFDIR;
486 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
487 (const struct dt_key *)name, th);
491 /* 5a. increase parent nlink */
492 rc = dt_declare_ref_add(env, parent, th);
496 /* 6a. update bookmark */
497 rc = dt_declare_record_write(env, bk_obj,
498 lfsck_buf_get(env, bk, len), 0, th);
502 rc = dt_trans_start_local(env, dev, th);
506 dt_write_lock(env, child, 0);
507 /* 1b.1. create child */
508 rc = dt_create(env, child, la, NULL, dof, th);
512 if (unlikely(!dt_try_as_dir(env, child)))
513 GOTO(unlock, rc = -ENOTDIR);
515 /* 1b.2. insert dot into child dir */
517 rc = dt_insert(env, child, (const struct dt_rec *)rec,
518 (const struct dt_key *)dot, th, BYPASS_CAPA, 1);
522 /* 1b.3. insert dotdot into child dir */
523 rec->rec_fid = &LU_LPF_FID;
524 rc = dt_insert(env, child, (const struct dt_rec *)rec,
525 (const struct dt_key *)dotdot, th, BYPASS_CAPA, 1);
529 /* 2b. increase child nlink */
530 rc = dt_ref_add(env, child, th);
534 /* 3b. insert linkEA for child. */
535 rc = dt_xattr_set(env, child, &linkea_buf,
536 XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
537 dt_write_unlock(env, child);
541 /* 4b. insert name into parent dir */
543 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
544 (const struct dt_key *)name, th, BYPASS_CAPA, 1);
548 dt_write_lock(env, parent, 0);
549 /* 5b. increase parent nlink */
550 rc = dt_ref_add(env, parent, th);
551 dt_write_unlock(env, parent);
555 bk->lb_lpf_fid = *cfid;
556 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
558 /* 6b. update bookmark */
559 rc = dt_record_write(env, bk_obj,
560 lfsck_buf_get(env, bk, len), &pos, th);
565 dt_write_unlock(env, child);
568 dt_trans_stop(env, dev, th);
573 static int lfsck_create_lpf_remote(const struct lu_env *env,
574 struct lfsck_instance *lfsck,
575 struct dt_object *parent,
576 struct dt_object *child,
578 struct dt_object_format *dof,
581 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
582 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
583 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
584 const struct lu_fid *cfid = lfsck_dto2fid(child);
585 struct thandle *th = NULL;
586 struct linkea_data ldata = { 0 };
587 struct lu_buf linkea_buf;
588 const struct lu_name *cname;
589 struct dt_device *dev;
591 int len = sizeof(struct lfsck_bookmark);
595 rc = linkea_data_new(&ldata,
596 &lfsck_env_info(env)->lti_linkea_buf);
600 cname = lfsck_name_get_const(env, name, strlen(name));
601 rc = linkea_add_buf(&ldata, cname, lfsck_dto2fid(parent));
605 /* Create .lustre/lost+found/MDTxxxx. */
607 /* XXX: Currently, cross-MDT create operation needs to create the child
608 * object firstly, then insert name into the parent directory. For
609 * this case, the child object resides on current MDT (local), but
610 * the parent ".lustre/lost+found" may be on remote MDT. It is not
611 * easy to contain all the sub-modifications orderly within single
614 * To avoid more inconsistency, we split the create operation into
617 * 1) create the child and update the lfsck_bookmark::lb_lpf_fid
619 * 2) insert the name "MDTXXXX" in the parent ".lustre/lost+found"
622 * If 1) done, but 2) failed, then go ahead, the LFSCK will try to
623 * repair such inconsistency when LFSCK run next time. */
625 /* Transaction I: locally */
627 dev = lfsck->li_bottom;
628 th = dt_trans_create(env, dev);
632 /* 1a. create child */
633 rc = dt_declare_create(env, child, la, NULL, dof, th);
637 /* 2a. increase child nlink */
638 rc = dt_declare_ref_add(env, child, th);
642 /* 3a. insert linkEA for child */
643 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
644 ldata.ld_leh->leh_len);
645 rc = dt_declare_xattr_set(env, child, &linkea_buf,
646 XATTR_NAME_LINK, 0, th);
650 /* 4a. update bookmark */
651 rc = dt_declare_record_write(env, bk_obj,
652 lfsck_buf_get(env, bk, len), 0, th);
656 rc = dt_trans_start_local(env, dev, th);
660 dt_write_lock(env, child, 0);
661 /* 1b.1. create child */
662 rc = dt_create(env, child, la, NULL, dof, th);
666 if (unlikely(!dt_try_as_dir(env, child)))
667 GOTO(unlock, rc = -ENOTDIR);
669 /* 1b.2. insert dot into child dir */
670 rec->rec_type = S_IFDIR;
672 rc = dt_insert(env, child, (const struct dt_rec *)rec,
673 (const struct dt_key *)dot, th, BYPASS_CAPA, 1);
677 /* 1b.3. insert dotdot into child dir */
678 rec->rec_fid = &LU_LPF_FID;
679 rc = dt_insert(env, child, (const struct dt_rec *)rec,
680 (const struct dt_key *)dotdot, th, BYPASS_CAPA, 1);
684 /* 2b. increase child nlink */
685 rc = dt_ref_add(env, child, th);
689 /* 3b. insert linkEA for child */
690 rc = dt_xattr_set(env, child, &linkea_buf,
691 XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
695 bk->lb_lpf_fid = *cfid;
696 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
698 /* 4b. update bookmark */
699 rc = dt_record_write(env, bk_obj,
700 lfsck_buf_get(env, bk, len), &pos, th);
702 dt_write_unlock(env, child);
703 dt_trans_stop(env, dev, th);
707 /* Transaction II: remotely */
709 dev = lfsck->li_next;
710 th = dt_trans_create(env, dev);
714 /* 5a. insert name into parent dir */
716 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
717 (const struct dt_key *)name, th);
721 /* 6a. increase parent nlink */
722 rc = dt_declare_ref_add(env, parent, th);
726 rc = dt_trans_start(env, dev, th);
730 /* 5b. insert name into parent dir */
731 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
732 (const struct dt_key *)name, th, BYPASS_CAPA, 1);
736 dt_write_lock(env, parent, 0);
737 /* 6b. increase parent nlink */
738 rc = dt_ref_add(env, parent, th);
739 dt_write_unlock(env, parent);
744 dt_write_unlock(env, child);
746 dt_trans_stop(env, dev, th);
748 if (rc != 0 && dev == lfsck->li_next)
749 CDEBUG(D_LFSCK, "%s: partially created the object "DFID
750 "for orphans, but failed to insert the name %s "
751 "to the .lustre/lost+found/. Such inconsistency "
752 "will be repaired when LFSCK run next time: rc = %d\n",
753 lfsck_lfsck2name(lfsck), PFID(cfid), name, rc);
758 /* Do NOT create .lustre/lost+found/MDTxxxx when register the lfsck instance,
759 * because the MDT0 maybe not reaady for sequence allocation yet. We do that
760 * only when it is required, such as orphan OST-objects repairing. */
761 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
763 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
764 struct lfsck_thread_info *info = lfsck_env_info(env);
765 struct lu_fid *cfid = &info->lti_fid2;
766 struct lu_attr *la = &info->lti_la;
767 struct dt_object_format *dof = &info->lti_dof;
768 struct dt_object *parent = NULL;
769 struct dt_object *child = NULL;
770 struct lustre_handle lh = { 0 };
772 int node = lfsck_dev_idx(lfsck->li_bottom);
776 LASSERT(lfsck->li_master);
778 sprintf(name, "MDT%04x", node);
780 parent = lfsck_object_find_by_dev(env, lfsck->li_bottom,
783 struct lfsck_tgt_desc *ltd;
785 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
786 if (unlikely(ltd == NULL))
789 parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
794 RETURN(PTR_ERR(parent));
796 if (lfsck->li_lpf_obj != NULL)
799 if (unlikely(!dt_try_as_dir(env, parent)))
800 GOTO(out, rc = -ENOTDIR);
802 rc = lfsck_ibits_lock(env, lfsck, parent, &lh,
803 MDS_INODELOCK_UPDATE, LCK_EX);
807 mutex_lock(&lfsck->li_mutex);
808 if (lfsck->li_lpf_obj != NULL)
809 GOTO(unlock, rc = 0);
811 if (fid_is_zero(&bk->lb_lpf_fid)) {
812 /* There is corner case that: in former LFSCK scanning we have
813 * created the .lustre/lost+found/MDTxxxx but failed to update
814 * the lfsck_bookmark::lb_lpf_fid successfully. So need lookup
815 * it from MDT0 firstly. */
816 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
817 (const struct dt_key *)name, BYPASS_CAPA);
818 if (rc != 0 && rc != -ENOENT)
822 bk->lb_lpf_fid = *cfid;
823 rc = lfsck_bookmark_store(env, lfsck);
825 rc = lfsck_fid_alloc(env, lfsck, cfid, true);
830 *cfid = bk->lb_lpf_fid;
833 child = lfsck_object_find_by_dev(env, lfsck->li_bottom, cfid);
835 GOTO(unlock, rc = PTR_ERR(child));
837 if (dt_object_exists(child) != 0) {
838 if (unlikely(!dt_try_as_dir(env, child)))
841 lfsck->li_lpf_obj = child;
846 memset(la, 0, sizeof(*la));
847 la->la_atime = la->la_mtime = la->la_ctime = cfs_time_current_sec();
848 la->la_mode = S_IFDIR | S_IRWXU;
849 la->la_valid = LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
851 memset(dof, 0, sizeof(*dof));
852 dof->dof_type = dt_mode_to_dft(S_IFDIR);
855 rc = lfsck_create_lpf_local(env, lfsck, parent, child, la,
858 rc = lfsck_create_lpf_remote(env, lfsck, parent, child, la,
861 lfsck->li_lpf_obj = child;
866 mutex_unlock(&lfsck->li_mutex);
867 lfsck_ibits_unlock(&lh, LCK_EX);
868 if (rc != 0 && child != NULL && !IS_ERR(child))
869 lu_object_put(env, &child->do_lu);
871 if (parent != NULL && !IS_ERR(parent))
872 lu_object_put(env, &parent->do_lu);
878 * Scan .lustre/lost+found for bad name entries and remove them.
880 * The valid name entry should be "MDTxxxx", the "xxxx" is the MDT device
881 * index in the system. Any other formatted name is invalid and should be
884 * \param[in] env pointer to the thread context
885 * \param[in] lfsck pointer to the lfsck instance
886 * \param[in] parent pointer to the lost+found object
888 * \retval 0 for success
889 * \retval negative error number on failure
891 static int lfsck_scan_lpf_bad_entries(const struct lu_env *env,
892 struct lfsck_instance *lfsck,
893 struct dt_object *parent)
895 struct lu_dirent *ent =
896 (struct lu_dirent *)lfsck_env_info(env)->lti_key;
897 const struct dt_it_ops *iops = &parent->do_index_ops->dio_it;
902 it = iops->init(env, parent, LUDA_64BITHASH, BYPASS_CAPA);
906 rc = iops->load(env, it, 0);
908 rc = iops->next(env, it);
915 rc = iops->rec(env, it, (struct dt_rec *)ent, LUDA_64BITHASH);
919 ent->lde_namelen = le16_to_cpu(ent->lde_namelen);
920 if (ent->lde_name[0] == '.') {
921 if (ent->lde_namelen == 1)
924 if (ent->lde_namelen == 2 && ent->lde_name[1] == '.')
928 /* name length must be strlen("MDTxxxx") */
929 if (ent->lde_namelen != 7)
932 if (memcmp(ent->lde_name, "MDT", off) != 0)
935 while (off < 7 && isxdigit(ent->lde_name[off]))
941 rc = lfsck_remove_name_entry(env, lfsck, parent,
942 ent->lde_name, S_IFDIR);
948 rc = iops->next(env, it);
954 RETURN(rc > 0 ? 0 : rc);
957 static int lfsck_update_lpf_entry(const struct lu_env *env,
958 struct lfsck_instance *lfsck,
959 struct dt_object *parent,
960 struct dt_object *child,
962 enum lfsck_verify_lpf_types type)
966 if (type == LVLT_BY_BOOKMARK) {
967 rc = lfsck_update_name_entry(env, lfsck, parent, name,
968 lfsck_dto2fid(child), S_IFDIR);
969 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
970 lfsck->li_bookmark_ram.lb_lpf_fid = *lfsck_dto2fid(child);
971 rc = lfsck_bookmark_store(env, lfsck);
973 CDEBUG(D_LFSCK, "%s: update LPF fid "DFID
974 " in the bookmark file: rc = %d\n",
975 lfsck_lfsck2name(lfsck),
976 PFID(lfsck_dto2fid(child)), rc);
983 * Check whether the @child back references the @parent.
986 * 1) The child's FID is stored in the bookmark file. If the child back
987 * references the parent (LU_LPF_FID object) via its ".." entry, then
988 * insert the name (MDTxxxx) to the .lustre/lost+found; otherwise, if
989 * the child back references another parent2, then:
990 * 1.1) If the parent2 recognizes the child, then update the bookmark file;
991 * 1.2) Otherwise, the LFSCK cannot know whether there will be parent3 that
992 * references the child. So keep them there. As the LFSCK processing,
993 * the parent3 may be found, then when the LFSCK run next time, the
994 * inconsistency can be repaired.
996 * 2) The child's FID is stored in the .lustre/lost+found/ sub-directory name
997 * entry (MDTxxxx). If the child back references the parent (LU_LPF_FID obj)
998 * via its ".." entry, then update the bookmark file, otherwise, if the child
999 * back references another parent2, then:
1000 * 2.1) If the parent2 recognizes the child, then remove the sub-directory
1001 * from .lustre/lost+found/;
1002 * 2.2) Otherwise, if the parent2 does not recognizes the child, trust the
1003 * sub-directory name entry and update the child;
1004 * 2.3) Otherwise, if we do not know whether the parent2 recognizes the child
1005 * or not, then keep them there.
1007 * \param[in] env pointer to the thread context
1008 * \param[in] lfsck pointer to the lfsck instance
1009 * \param[in] parent pointer to the lost+found object
1010 * \param[in] child pointer to the lost+found sub-directory object
1011 * \param[in] name the name for lost+found sub-directory object
1012 * \param[out] fid pointer to the buffer to hold the FID of the object
1013 * (called it as parent2) that is referenced via the
1014 * child's dotdot entry; it also can be the FID that
1015 * is referenced by the name entry under the parent2.
1016 * \param[in] type to indicate where the child's FID is stored in
1018 * \retval positive number for uncertain inconsistency
1019 * \retval 0 for success
1020 * \retval negative error number on failure
1022 static int lfsck_verify_lpf_pairs(const struct lu_env *env,
1023 struct lfsck_instance *lfsck,
1024 struct dt_object *parent,
1025 struct dt_object *child, const char *name,
1027 enum lfsck_verify_lpf_types type)
1029 struct lfsck_thread_info *info = lfsck_env_info(env);
1030 char *name2 = info->lti_key;
1031 struct lu_fid *fid2 = &info->lti_fid3;
1032 struct dt_object *parent2 = NULL;
1033 struct lustre_handle lh = { 0 };
1038 rc = dt_lookup(env, child, (struct dt_rec *)fid,
1039 (const struct dt_key *)dotdot, BYPASS_CAPA);
1043 if (!fid_is_sane(fid))
1044 GOTO(linkea, rc = -EINVAL);
1046 if (lu_fid_eq(fid, &LU_LPF_FID)) {
1047 const struct lu_name *cname;
1049 if (lfsck->li_lpf_obj == NULL) {
1050 lu_object_get(&child->do_lu);
1051 lfsck->li_lpf_obj = child;
1054 cname = lfsck_name_get_const(env, name, strlen(name));
1055 rc = lfsck_verify_linkea(env, lfsck->li_bottom, child, cname,
1058 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1064 parent2 = lfsck_object_find_by_dev(env, lfsck->li_next, fid);
1065 if (IS_ERR(parent2))
1066 GOTO(linkea, parent2);
1068 if (!dt_object_exists(parent2)) {
1069 lu_object_put(env, &parent2->do_lu);
1071 GOTO(linkea, parent2 = ERR_PTR(-ENOENT));
1074 if (!dt_try_as_dir(env, parent2)) {
1075 lu_object_put(env, &parent2->do_lu);
1077 GOTO(linkea, parent2 = ERR_PTR(-ENOTDIR));
1081 /* To prevent rename/unlink race */
1082 rc = lfsck_ibits_lock(env, lfsck, child, &lh,
1083 MDS_INODELOCK_UPDATE, LCK_PR);
1087 dt_read_lock(env, child, 0);
1088 rc = lfsck_links_get_first(env, child, name2, fid2);
1090 dt_read_unlock(env, child);
1091 lfsck_ibits_unlock(&lh, LCK_PR);
1093 GOTO(out_put, rc = 1);
1096 /* It is almost impossible that the bookmark file (or the name entry)
1097 * and the linkEA hit the same data corruption. Trust the linkEA. */
1098 if (lu_fid_eq(fid2, &LU_LPF_FID) && strcmp(name, name2) == 0) {
1099 dt_read_unlock(env, child);
1100 lfsck_ibits_unlock(&lh, LCK_PR);
1103 if (lfsck->li_lpf_obj == NULL) {
1104 lu_object_get(&child->do_lu);
1105 lfsck->li_lpf_obj = child;
1108 /* Update the child's dotdot entry */
1109 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1110 &LU_LPF_FID, S_IFDIR);
1112 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1118 if (parent2 == NULL || IS_ERR(parent2)) {
1119 dt_read_unlock(env, child);
1120 lfsck_ibits_unlock(&lh, LCK_PR);
1122 GOTO(out_done, rc = 1);
1125 rc = dt_lookup(env, parent2, (struct dt_rec *)fid,
1126 (const struct dt_key *)name2, BYPASS_CAPA);
1127 dt_read_unlock(env, child);
1128 lfsck_ibits_unlock(&lh, LCK_PR);
1129 if (rc != 0 && rc != -ENOENT)
1132 if (rc == -ENOENT || !lu_fid_eq(fid, lfsck_dto2fid(child))) {
1133 if (type == LVLT_BY_BOOKMARK)
1134 GOTO(out_put, rc = 1);
1136 /* Trust the name entry, update the child's dotdot entry. */
1137 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1138 &LU_LPF_FID, S_IFDIR);
1143 if (type == LVLT_BY_BOOKMARK) {
1144 /* Invalid FID record in the bookmark file, reset it. */
1145 fid_zero(&lfsck->li_bookmark_ram.lb_lpf_fid);
1146 rc = lfsck_bookmark_store(env, lfsck);
1148 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1149 " in the bookmark file: rc = %d\n",
1150 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(child)), rc);
1151 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1152 /* The name entry is wrong, remove it. */
1153 rc = lfsck_remove_name_entry(env, lfsck, parent, name, S_IFDIR);
1159 if (parent2 != NULL && !IS_ERR(parent2))
1160 lu_object_put(env, &parent2->do_lu);
1167 * Verify the /ROOT/.lustre/lost+found/ directory.
1169 * /ROOT/.lustre/lost+found/ is a special directory to hold the objects that
1170 * the LFSCK does not exactly know how to handle, such as orphans. So before
1171 * the LFSCK scanning the system, the consistency of such directory needs to
1172 * be verified firstly to allow the users to use it during the LFSCK.
1174 * \param[in] env pointer to the thread context
1175 * \param[in] lfsck pointer to the lfsck instance
1177 * \retval positive number for uncertain inconsistency
1178 * \retval 0 for success
1179 * \retval negative error number on failure
1181 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
1183 struct lfsck_thread_info *info = lfsck_env_info(env);
1184 struct lu_fid *pfid = &info->lti_fid;
1185 struct lu_fid *cfid = &info->lti_fid2;
1186 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1187 struct dt_object *parent = NULL;
1188 /* child1's FID is in the bookmark file. */
1189 struct dt_object *child1 = NULL;
1190 /* child2's FID is in the name entry MDTxxxx. */
1191 struct dt_object *child2 = NULL;
1192 struct dt_device *dev = lfsck->li_bottom;
1193 const struct lu_name *cname;
1195 int node = lfsck_dev_idx(dev);
1199 LASSERT(lfsck->li_master);
1202 parent = lfsck_object_find_by_dev(env, dev, &LU_LPF_FID);
1204 struct lfsck_tgt_desc *ltd;
1206 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
1207 if (unlikely(ltd == NULL))
1210 parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
1216 RETURN(PTR_ERR(parent));
1218 LASSERT(dt_object_exists(parent));
1220 if (unlikely(!dt_try_as_dir(env, parent)))
1221 GOTO(put, rc = -ENOTDIR);
1224 rc = lfsck_scan_lpf_bad_entries(env, lfsck, parent);
1226 CDEBUG(D_LFSCK, "%s: scan .lustre/lost+found/ "
1227 "for bad sub-directories: rc = %d\n",
1228 lfsck_lfsck2name(lfsck), rc);
1231 if (!fid_is_zero(&bk->lb_lpf_fid)) {
1232 if (unlikely(!fid_is_norm(&bk->lb_lpf_fid))) {
1233 struct lu_fid tfid = bk->lb_lpf_fid;
1235 /* Invalid FID record in the bookmark file, reset it. */
1236 fid_zero(&bk->lb_lpf_fid);
1237 rc = lfsck_bookmark_store(env, lfsck);
1239 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1240 " in the bookmark file: rc = %d\n",
1241 lfsck_lfsck2name(lfsck), PFID(&tfid), rc);
1246 child1 = lfsck_object_find_by_dev(env, dev,
1249 GOTO(put, rc = PTR_ERR(child1));
1251 if (unlikely(!dt_object_exists(child1) ||
1252 dt_object_remote(child1)) ||
1253 !S_ISDIR(lfsck_object_type(child1))) {
1254 /* Invalid FID record in the bookmark file,
1256 fid_zero(&bk->lb_lpf_fid);
1257 rc = lfsck_bookmark_store(env, lfsck);
1259 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1260 " in the bookmark file: rc = %d\n",
1261 lfsck_lfsck2name(lfsck),
1262 PFID(lfsck_dto2fid(child1)), rc);
1267 lu_object_put(env, &child1->do_lu);
1269 } else if (unlikely(!dt_try_as_dir(env, child1))) {
1270 GOTO(put, rc = -ENOTDIR);
1275 snprintf(name, 8, "MDT%04x", node);
1276 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
1277 (const struct dt_key *)name, BYPASS_CAPA);
1278 if (rc == -ENOENT) {
1279 if (!fid_is_zero(&bk->lb_lpf_fid))
1288 /* Invalid FID in the name entry, remove the name entry. */
1289 if (!fid_is_norm(cfid)) {
1290 rc = lfsck_remove_name_entry(env, lfsck, parent, name, S_IFDIR);
1297 child2 = lfsck_object_find_by_dev(env, dev, cfid);
1299 GOTO(put, rc = PTR_ERR(child2));
1301 if (unlikely(!dt_object_exists(child2) ||
1302 dt_object_remote(child2)) ||
1303 !S_ISDIR(lfsck_object_type(child2))) {
1304 rc = lfsck_remove_name_entry(env, lfsck, parent, name,
1312 if (unlikely(!dt_try_as_dir(env, child2)))
1313 GOTO(put, rc = -ENOTDIR);
1315 if (child1 == NULL) {
1316 rc = lfsck_verify_lpf_pairs(env, lfsck, parent, child2, name,
1317 pfid, LVLT_BY_NAMEENTRY);
1318 } else if (!lu_fid_eq(cfid, &bk->lb_lpf_fid)) {
1319 rc = lfsck_verify_lpf_pairs(env, lfsck, parent, child1, name,
1320 pfid, LVLT_BY_BOOKMARK);
1321 if (!lu_fid_eq(pfid, &LU_LPF_FID))
1322 rc = lfsck_verify_lpf_pairs(env, lfsck, parent, child2,
1326 if (lfsck->li_lpf_obj == NULL) {
1327 lu_object_get(&child2->do_lu);
1328 lfsck->li_lpf_obj = child2;
1331 cname = lfsck_name_get_const(env, name, strlen(name));
1332 rc = lfsck_verify_linkea(env, dev, child2, cname, &LU_LPF_FID);
1339 rc = lfsck_verify_lpf_pairs(env, lfsck, parent, child1, name,
1340 pfid, LVLT_BY_BOOKMARK);
1345 if (lfsck->li_lpf_obj != NULL &&
1346 unlikely(!dt_try_as_dir(env, lfsck->li_lpf_obj)))
1349 if (child2 != NULL && !IS_ERR(child2))
1350 lu_object_put(env, &child2->do_lu);
1351 if (child1 != NULL && !IS_ERR(child1))
1352 lu_object_put(env, &child1->do_lu);
1353 if (parent != NULL && !IS_ERR(parent))
1354 lu_object_put(env, &parent->do_lu);
1359 static int lfsck_fid_init(struct lfsck_instance *lfsck)
1361 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1362 struct seq_server_site *ss;
1367 ss = lu_site2seq(lfsck->li_bottom->dd_lu_dev.ld_site);
1368 if (unlikely(ss == NULL))
1371 OBD_ALLOC_PTR(lfsck->li_seq);
1372 if (lfsck->li_seq == NULL)
1375 OBD_ALLOC(prefix, MAX_OBD_NAME + 7);
1377 GOTO(out, rc = -ENOMEM);
1379 snprintf(prefix, MAX_OBD_NAME + 7, "lfsck-%s", lfsck_lfsck2name(lfsck));
1380 rc = seq_client_init(lfsck->li_seq, NULL, LUSTRE_SEQ_METADATA, prefix,
1382 OBD_FREE(prefix, MAX_OBD_NAME + 7);
1386 if (fid_is_sane(&bk->lb_last_fid))
1387 lfsck->li_seq->lcs_fid = bk->lb_last_fid;
1392 OBD_FREE_PTR(lfsck->li_seq);
1393 lfsck->li_seq = NULL;
1398 static void lfsck_fid_fini(struct lfsck_instance *lfsck)
1400 if (lfsck->li_seq != NULL) {
1401 seq_client_fini(lfsck->li_seq);
1402 OBD_FREE_PTR(lfsck->li_seq);
1403 lfsck->li_seq = NULL;
1407 void lfsck_instance_cleanup(const struct lu_env *env,
1408 struct lfsck_instance *lfsck)
1410 struct ptlrpc_thread *thread = &lfsck->li_thread;
1411 struct lfsck_component *com;
1412 struct lfsck_component *next;
1415 LASSERT(list_empty(&lfsck->li_link));
1416 LASSERT(thread_is_init(thread) || thread_is_stopped(thread));
1418 if (lfsck->li_obj_oit != NULL) {
1419 lu_object_put_nocache(env, &lfsck->li_obj_oit->do_lu);
1420 lfsck->li_obj_oit = NULL;
1423 LASSERT(lfsck->li_obj_dir == NULL);
1425 list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
1426 lfsck_component_cleanup(env, com);
1429 LASSERT(list_empty(&lfsck->li_list_dir));
1431 list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
1433 lfsck_component_cleanup(env, com);
1436 list_for_each_entry_safe(com, next, &lfsck->li_list_idle, lc_link) {
1437 lfsck_component_cleanup(env, com);
1440 lfsck_tgt_descs_fini(&lfsck->li_ost_descs);
1441 lfsck_tgt_descs_fini(&lfsck->li_mdt_descs);
1443 if (lfsck->li_bookmark_obj != NULL) {
1444 lu_object_put_nocache(env, &lfsck->li_bookmark_obj->do_lu);
1445 lfsck->li_bookmark_obj = NULL;
1448 if (lfsck->li_lpf_obj != NULL) {
1449 lu_object_put(env, &lfsck->li_lpf_obj->do_lu);
1450 lfsck->li_lpf_obj = NULL;
1453 if (lfsck->li_los != NULL) {
1454 local_oid_storage_fini(env, lfsck->li_los);
1455 lfsck->li_los = NULL;
1458 lfsck_fid_fini(lfsck);
1460 OBD_FREE_PTR(lfsck);
1463 static inline struct lfsck_instance *
1464 __lfsck_instance_find(struct dt_device *key, bool ref, bool unlink)
1466 struct lfsck_instance *lfsck;
1468 list_for_each_entry(lfsck, &lfsck_instance_list, li_link) {
1469 if (lfsck->li_bottom == key) {
1471 lfsck_instance_get(lfsck);
1473 list_del_init(&lfsck->li_link);
1482 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
1485 struct lfsck_instance *lfsck;
1487 spin_lock(&lfsck_instance_lock);
1488 lfsck = __lfsck_instance_find(key, ref, unlink);
1489 spin_unlock(&lfsck_instance_lock);
1494 static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
1496 struct lfsck_instance *tmp;
1498 spin_lock(&lfsck_instance_lock);
1499 list_for_each_entry(tmp, &lfsck_instance_list, li_link) {
1500 if (lfsck->li_bottom == tmp->li_bottom) {
1501 spin_unlock(&lfsck_instance_lock);
1506 list_add_tail(&lfsck->li_link, &lfsck_instance_list);
1507 spin_unlock(&lfsck_instance_lock);
1511 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
1516 bool newline = (bits != 0 ? false : true);
1518 seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
1520 for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
1523 if (names[i] != NULL) {
1527 seq_printf(m, "%s%c", names[i],
1528 newline ? '\n' : ',');
1534 seq_printf(m, "\n");
1538 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix)
1541 seq_printf(m, "%s: "LPU64" seconds\n", prefix,
1542 cfs_time_current_sec() - time);
1544 seq_printf(m, "%s: N/A\n", prefix);
1548 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
1551 if (fid_is_zero(&pos->lp_dir_parent)) {
1552 if (pos->lp_oit_cookie == 0)
1553 seq_printf(m, "%s: N/A, N/A, N/A\n",
1556 seq_printf(m, "%s: "LPU64", N/A, N/A\n",
1557 prefix, pos->lp_oit_cookie);
1559 seq_printf(m, "%s: "LPU64", "DFID", "LPX64"\n",
1560 prefix, pos->lp_oit_cookie,
1561 PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
1566 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
1567 struct lfsck_position *pos, bool init)
1569 const struct dt_it_ops *iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
1571 if (unlikely(lfsck->li_di_oit == NULL)) {
1572 memset(pos, 0, sizeof(*pos));
1576 pos->lp_oit_cookie = iops->store(env, lfsck->li_di_oit);
1577 if (!lfsck->li_current_oit_processed && !init)
1578 pos->lp_oit_cookie--;
1580 LASSERT(pos->lp_oit_cookie > 0);
1582 if (lfsck->li_di_dir != NULL) {
1583 struct dt_object *dto = lfsck->li_obj_dir;
1585 pos->lp_dir_cookie = dto->do_index_ops->dio_it.store(env,
1588 if (pos->lp_dir_cookie >= MDS_DIR_END_OFF) {
1589 fid_zero(&pos->lp_dir_parent);
1590 pos->lp_dir_cookie = 0;
1592 pos->lp_dir_parent = *lfsck_dto2fid(dto);
1595 fid_zero(&pos->lp_dir_parent);
1596 pos->lp_dir_cookie = 0;
1600 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
1604 if (limit != LFSCK_SPEED_NO_LIMIT) {
1606 lfsck->li_sleep_rate = limit / HZ;
1607 lfsck->li_sleep_jif = 1;
1609 lfsck->li_sleep_rate = 1;
1610 lfsck->li_sleep_jif = HZ / limit;
1613 lfsck->li_sleep_jif = 0;
1614 lfsck->li_sleep_rate = 0;
1617 if (lfsck->li_bookmark_ram.lb_speed_limit != limit) {
1618 lfsck->li_bookmark_ram.lb_speed_limit = limit;
1625 void lfsck_control_speed(struct lfsck_instance *lfsck)
1627 struct ptlrpc_thread *thread = &lfsck->li_thread;
1628 struct l_wait_info lwi;
1630 if (lfsck->li_sleep_jif > 0 &&
1631 lfsck->li_new_scanned >= lfsck->li_sleep_rate) {
1632 lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
1633 LWI_ON_SIGNAL_NOOP, NULL);
1635 l_wait_event(thread->t_ctl_waitq,
1636 !thread_is_running(thread),
1638 lfsck->li_new_scanned = 0;
1642 void lfsck_control_speed_by_self(struct lfsck_component *com)
1644 struct lfsck_instance *lfsck = com->lc_lfsck;
1645 struct ptlrpc_thread *thread = &lfsck->li_thread;
1646 struct l_wait_info lwi;
1648 if (lfsck->li_sleep_jif > 0 &&
1649 com->lc_new_scanned >= lfsck->li_sleep_rate) {
1650 lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
1651 LWI_ON_SIGNAL_NOOP, NULL);
1653 l_wait_event(thread->t_ctl_waitq,
1654 !thread_is_running(thread),
1656 com->lc_new_scanned = 0;
1660 static struct lfsck_thread_args *
1661 lfsck_thread_args_init(struct lfsck_instance *lfsck,
1662 struct lfsck_component *com,
1663 struct lfsck_start_param *lsp)
1665 struct lfsck_thread_args *lta;
1670 return ERR_PTR(-ENOMEM);
1672 rc = lu_env_init(<a->lta_env, LCT_MD_THREAD | LCT_DT_THREAD);
1678 lta->lta_lfsck = lfsck_instance_get(lfsck);
1680 lta->lta_com = lfsck_component_get(com);
1687 void lfsck_thread_args_fini(struct lfsck_thread_args *lta)
1689 if (lta->lta_com != NULL)
1690 lfsck_component_put(<a->lta_env, lta->lta_com);
1691 lfsck_instance_put(<a->lta_env, lta->lta_lfsck);
1692 lu_env_fini(<a->lta_env);
1696 struct lfsck_assistant_data *
1697 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
1700 struct lfsck_assistant_data *lad;
1704 lad->lad_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
1705 if (lad->lad_bitmap == NULL) {
1710 INIT_LIST_HEAD(&lad->lad_req_list);
1711 spin_lock_init(&lad->lad_lock);
1712 INIT_LIST_HEAD(&lad->lad_ost_list);
1713 INIT_LIST_HEAD(&lad->lad_ost_phase1_list);
1714 INIT_LIST_HEAD(&lad->lad_ost_phase2_list);
1715 INIT_LIST_HEAD(&lad->lad_mdt_list);
1716 INIT_LIST_HEAD(&lad->lad_mdt_phase1_list);
1717 INIT_LIST_HEAD(&lad->lad_mdt_phase2_list);
1718 init_waitqueue_head(&lad->lad_thread.t_ctl_waitq);
1720 lad->lad_name = name;
1727 * Generic LFSCK asynchronous communication interpretor function.
1728 * The LFSCK RPC reply for both the event notification and status
1729 * querying will be handled here.
1731 * \param[in] env pointer to the thread context
1732 * \param[in] req pointer to the LFSCK request
1733 * \param[in] args pointer to the lfsck_async_interpret_args
1734 * \param[in] rc the result for handling the LFSCK request
1736 * \retval 0 for success
1737 * \retval negative error number on failure
1739 int lfsck_async_interpret_common(const struct lu_env *env,
1740 struct ptlrpc_request *req,
1743 struct lfsck_async_interpret_args *laia = args;
1744 struct lfsck_component *com = laia->laia_com;
1745 struct lfsck_assistant_data *lad = com->lc_data;
1746 struct lfsck_tgt_descs *ltds = laia->laia_ltds;
1747 struct lfsck_tgt_desc *ltd = laia->laia_ltd;
1748 struct lfsck_request *lr = laia->laia_lr;
1750 LASSERT(com->lc_lfsck->li_master);
1752 switch (lr->lr_event) {
1755 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s "
1757 lfsck_lfsck2name(com->lc_lfsck),
1758 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
1759 ltd->ltd_index, lad->lad_name, rc);
1761 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1762 struct lfsck_layout *lo = com->lc_file_ram;
1764 if (lr->lr_flags & LEF_TO_OST)
1765 lfsck_lad_set_bitmap(env, com,
1768 lo->ll_flags |= LF_INCOMPLETE;
1770 struct lfsck_namespace *ns = com->lc_file_ram;
1772 /* If some MDT does not join the namespace
1773 * LFSCK, then we cannot know whether there
1774 * is some name entry on such MDT that with
1775 * the referenced MDT-object on this MDT or
1776 * not. So the namespace LFSCK on this MDT
1777 * cannot handle orphan MDT-objects properly.
1778 * So we mark the LFSCK as LF_INCOMPLETE and
1779 * skip orphan MDT-objects handling. */
1780 ns->ln_flags |= LF_INCOMPLETE;
1785 spin_lock(<ds->ltd_lock);
1786 if (ltd->ltd_dead) {
1787 spin_unlock(<ds->ltd_lock);
1791 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1792 struct list_head *list;
1793 struct list_head *phase_list;
1795 if (ltd->ltd_layout_done) {
1796 spin_unlock(<ds->ltd_lock);
1800 if (lr->lr_flags & LEF_TO_OST) {
1801 list = &lad->lad_ost_list;
1802 phase_list = &lad->lad_ost_phase1_list;
1804 list = &lad->lad_mdt_list;
1805 phase_list = &lad->lad_mdt_phase1_list;
1808 if (list_empty(<d->ltd_layout_list))
1809 list_add_tail(<d->ltd_layout_list, list);
1810 if (list_empty(<d->ltd_layout_phase_list))
1811 list_add_tail(<d->ltd_layout_phase_list,
1814 if (ltd->ltd_namespace_done) {
1815 spin_unlock(<ds->ltd_lock);
1819 if (list_empty(<d->ltd_namespace_list))
1820 list_add_tail(<d->ltd_namespace_list,
1821 &lad->lad_mdt_list);
1822 if (list_empty(<d->ltd_namespace_phase_list))
1823 list_add_tail(<d->ltd_namespace_phase_list,
1824 &lad->lad_mdt_phase1_list);
1826 spin_unlock(<ds->ltd_lock);
1829 case LE_PHASE1_DONE:
1830 case LE_PHASE2_DONE:
1832 if (rc != 0 && rc != -EALREADY)
1833 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s: "
1834 "event = %d, rc = %d\n",
1835 lfsck_lfsck2name(com->lc_lfsck),
1836 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
1837 ltd->ltd_index, lad->lad_name, lr->lr_event, rc);
1840 struct lfsck_reply *reply;
1841 struct list_head *list;
1842 struct list_head *phase_list;
1844 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1845 list = <d->ltd_layout_list;
1846 phase_list = <d->ltd_layout_phase_list;
1848 list = <d->ltd_namespace_list;
1849 phase_list = <d->ltd_namespace_phase_list;
1853 spin_lock(<ds->ltd_lock);
1854 list_del_init(phase_list);
1855 list_del_init(list);
1856 spin_unlock(<ds->ltd_lock);
1860 reply = req_capsule_server_get(&req->rq_pill,
1862 if (reply == NULL) {
1864 CDEBUG(D_LFSCK, "%s: invalid query reply for %s: "
1865 "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck),
1867 spin_lock(<ds->ltd_lock);
1868 list_del_init(phase_list);
1869 list_del_init(list);
1870 spin_unlock(<ds->ltd_lock);
1874 switch (reply->lr_status) {
1875 case LS_SCANNING_PHASE1:
1877 case LS_SCANNING_PHASE2:
1878 spin_lock(<ds->ltd_lock);
1879 list_del_init(phase_list);
1880 if (ltd->ltd_dead) {
1881 spin_unlock(<ds->ltd_lock);
1885 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1886 if (ltd->ltd_layout_done) {
1887 spin_unlock(<ds->ltd_lock);
1891 if (lr->lr_flags & LEF_TO_OST)
1892 list_add_tail(phase_list,
1893 &lad->lad_ost_phase2_list);
1895 list_add_tail(phase_list,
1896 &lad->lad_mdt_phase2_list);
1898 if (ltd->ltd_namespace_done) {
1899 spin_unlock(<ds->ltd_lock);
1903 list_add_tail(phase_list,
1904 &lad->lad_mdt_phase2_list);
1906 spin_unlock(<ds->ltd_lock);
1909 spin_lock(<ds->ltd_lock);
1910 list_del_init(phase_list);
1911 list_del_init(list);
1912 spin_unlock(<ds->ltd_lock);
1918 CDEBUG(D_LFSCK, "%s: unexpected event: rc = %d\n",
1919 lfsck_lfsck2name(com->lc_lfsck), lr->lr_event);
1923 if (!laia->laia_shared) {
1925 lfsck_component_put(env, com);
1931 static void lfsck_interpret(const struct lu_env *env,
1932 struct lfsck_instance *lfsck,
1933 struct ptlrpc_request *req, void *args, int result)
1935 struct lfsck_async_interpret_args *laia = args;
1936 struct lfsck_component *com;
1938 LASSERT(laia->laia_com == NULL);
1939 LASSERT(laia->laia_shared);
1941 spin_lock(&lfsck->li_lock);
1942 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
1943 laia->laia_com = com;
1944 lfsck_async_interpret_common(env, req, laia, result);
1947 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
1948 laia->laia_com = com;
1949 lfsck_async_interpret_common(env, req, laia, result);
1951 spin_unlock(&lfsck->li_lock);
1954 static int lfsck_stop_notify(const struct lu_env *env,
1955 struct lfsck_instance *lfsck,
1956 struct lfsck_tgt_descs *ltds,
1957 struct lfsck_tgt_desc *ltd, __u16 type)
1959 struct lfsck_component *com;
1963 LASSERT(lfsck->li_master);
1965 spin_lock(&lfsck->li_lock);
1966 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
1968 com = __lfsck_component_find(lfsck, type,
1969 &lfsck->li_list_double_scan);
1971 lfsck_component_get(com);
1972 spin_unlock(&lfsck->li_lock);
1975 struct lfsck_thread_info *info = lfsck_env_info(env);
1976 struct lfsck_async_interpret_args *laia = &info->lti_laia;
1977 struct lfsck_request *lr = &info->lti_lr;
1978 struct lfsck_assistant_data *lad = com->lc_data;
1979 struct list_head *list;
1980 struct list_head *phase_list;
1981 struct ptlrpc_request_set *set;
1983 set = ptlrpc_prep_set();
1985 lfsck_component_put(env, com);
1990 if (type == LFSCK_TYPE_LAYOUT) {
1991 list = <d->ltd_layout_list;
1992 phase_list = <d->ltd_layout_phase_list;
1994 list = <d->ltd_namespace_list;
1995 phase_list = <d->ltd_namespace_phase_list;
1998 spin_lock(<ds->ltd_lock);
1999 if (list_empty(list)) {
2000 LASSERT(list_empty(phase_list));
2001 spin_unlock(<ds->ltd_lock);
2002 ptlrpc_set_destroy(set);
2007 list_del_init(phase_list);
2008 list_del_init(list);
2009 spin_unlock(<ds->ltd_lock);
2011 memset(lr, 0, sizeof(*lr));
2012 lr->lr_index = lfsck_dev_idx(lfsck->li_bottom);
2013 lr->lr_event = LE_PEER_EXIT;
2014 lr->lr_active = type;
2015 lr->lr_status = LS_CO_PAUSED;
2016 if (ltds == &lfsck->li_ost_descs)
2017 lr->lr_flags = LEF_TO_OST;
2019 laia->laia_com = com;
2020 laia->laia_ltds = ltds;
2021 atomic_inc(<d->ltd_ref);
2022 laia->laia_ltd = ltd;
2024 laia->laia_shared = 0;
2026 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2027 lfsck_async_interpret_common,
2028 laia, LFSCK_NOTIFY);
2030 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for "
2031 "co-stop for %s: rc = %d\n",
2032 lfsck_lfsck2name(lfsck),
2033 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2034 ltd->ltd_index, lad->lad_name, rc);
2037 rc = ptlrpc_set_wait(set);
2040 ptlrpc_set_destroy(set);
2041 lfsck_component_put(env, com);
2047 static int lfsck_async_interpret(const struct lu_env *env,
2048 struct ptlrpc_request *req,
2051 struct lfsck_async_interpret_args *laia = args;
2052 struct lfsck_instance *lfsck;
2054 lfsck = container_of0(laia->laia_ltds, struct lfsck_instance,
2056 lfsck_interpret(env, lfsck, req, laia, rc);
2057 lfsck_tgt_put(laia->laia_ltd);
2058 if (rc != 0 && laia->laia_result != -EALREADY)
2059 laia->laia_result = rc;
2064 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
2065 struct lfsck_request *lr,
2066 struct ptlrpc_request_set *set,
2067 ptlrpc_interpterer_t interpreter,
2068 void *args, int request)
2070 struct lfsck_async_interpret_args *laia;
2071 struct ptlrpc_request *req;
2072 struct lfsck_request *tmp;
2073 struct req_format *format;
2078 format = &RQF_LFSCK_NOTIFY;
2081 format = &RQF_LFSCK_QUERY;
2084 CDEBUG(D_LFSCK, "%s: unknown async request %d: rc = %d\n",
2085 exp->exp_obd->obd_name, request, -EINVAL);
2089 req = ptlrpc_request_alloc(class_exp2cliimp(exp), format);
2093 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, request);
2095 ptlrpc_request_free(req);
2100 tmp = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
2102 ptlrpc_request_set_replen(req);
2104 laia = ptlrpc_req_async_args(req);
2105 *laia = *(struct lfsck_async_interpret_args *)args;
2106 if (laia->laia_com != NULL)
2107 lfsck_component_get(laia->laia_com);
2108 req->rq_interpret_reply = interpreter;
2109 ptlrpc_set_add_req(set, req);
2114 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
2115 struct lfsck_start_param *lsp)
2117 struct lfsck_instance *lfsck = com->lc_lfsck;
2118 struct lfsck_assistant_data *lad = com->lc_data;
2119 struct ptlrpc_thread *mthread = &lfsck->li_thread;
2120 struct ptlrpc_thread *athread = &lad->lad_thread;
2121 struct lfsck_thread_args *lta;
2122 struct task_struct *task;
2126 lad->lad_assistant_status = 0;
2127 lad->lad_post_result = 0;
2128 lad->lad_to_post = 0;
2129 lad->lad_to_double_scan = 0;
2130 lad->lad_in_double_scan = 0;
2132 thread_set_flags(athread, 0);
2134 lta = lfsck_thread_args_init(lfsck, com, lsp);
2136 RETURN(PTR_ERR(lta));
2138 task = kthread_run(lfsck_assistant_engine, lta, lad->lad_name);
2141 CERROR("%s: cannot start LFSCK assistant thread for %s: "
2142 "rc = %d\n", lfsck_lfsck2name(lfsck), lad->lad_name, rc);
2143 lfsck_thread_args_fini(lta);
2145 struct l_wait_info lwi = { 0 };
2147 l_wait_event(mthread->t_ctl_waitq,
2148 thread_is_running(athread) ||
2149 thread_is_stopped(athread),
2151 if (unlikely(!thread_is_running(athread)))
2152 rc = lad->lad_assistant_status;
2160 int lfsck_checkpoint_generic(const struct lu_env *env,
2161 struct lfsck_component *com)
2163 struct lfsck_assistant_data *lad = com->lc_data;
2164 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2165 struct ptlrpc_thread *athread = &lad->lad_thread;
2166 struct l_wait_info lwi = { 0 };
2168 if (com->lc_new_checked == 0)
2169 return LFSCK_CHECKPOINT_SKIP;
2171 l_wait_event(mthread->t_ctl_waitq,
2172 list_empty(&lad->lad_req_list) ||
2173 !thread_is_running(mthread) ||
2174 thread_is_stopped(athread),
2177 if (!thread_is_running(mthread) || thread_is_stopped(athread))
2178 return LFSCK_CHECKPOINT_SKIP;
2183 void lfsck_post_generic(const struct lu_env *env,
2184 struct lfsck_component *com, int *result)
2186 struct lfsck_assistant_data *lad = com->lc_data;
2187 struct ptlrpc_thread *athread = &lad->lad_thread;
2188 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2189 struct l_wait_info lwi = { 0 };
2191 lad->lad_post_result = *result;
2194 lad->lad_to_post = 1;
2196 wake_up_all(&athread->t_ctl_waitq);
2197 l_wait_event(mthread->t_ctl_waitq,
2198 (*result > 0 && list_empty(&lad->lad_req_list)) ||
2199 thread_is_stopped(athread),
2202 if (lad->lad_assistant_status < 0)
2203 *result = lad->lad_assistant_status;
2206 int lfsck_double_scan_generic(const struct lu_env *env,
2207 struct lfsck_component *com, int status)
2209 struct lfsck_assistant_data *lad = com->lc_data;
2210 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2211 struct ptlrpc_thread *athread = &lad->lad_thread;
2212 struct l_wait_info lwi = { 0 };
2214 if (status != LS_SCANNING_PHASE2)
2217 lad->lad_to_double_scan = 1;
2219 wake_up_all(&athread->t_ctl_waitq);
2220 l_wait_event(mthread->t_ctl_waitq,
2221 lad->lad_in_double_scan ||
2222 thread_is_stopped(athread),
2225 if (lad->lad_assistant_status < 0)
2226 return lad->lad_assistant_status;
2231 void lfsck_quit_generic(const struct lu_env *env,
2232 struct lfsck_component *com)
2234 struct lfsck_assistant_data *lad = com->lc_data;
2235 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2236 struct ptlrpc_thread *athread = &lad->lad_thread;
2237 struct l_wait_info lwi = { 0 };
2240 wake_up_all(&athread->t_ctl_waitq);
2241 l_wait_event(mthread->t_ctl_waitq,
2242 thread_is_init(athread) ||
2243 thread_is_stopped(athread),
2247 /* external interfaces */
2249 int lfsck_get_speed(struct seq_file *m, struct dt_device *key)
2252 struct lfsck_instance *lfsck;
2256 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2260 lfsck = lfsck_instance_find(key, true, false);
2261 if (likely(lfsck != NULL)) {
2262 seq_printf(m, "%u\n", lfsck->li_bookmark_ram.lb_speed_limit);
2263 lfsck_instance_put(&env, lfsck);
2272 EXPORT_SYMBOL(lfsck_get_speed);
2274 int lfsck_set_speed(struct dt_device *key, int val)
2277 struct lfsck_instance *lfsck;
2281 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2285 lfsck = lfsck_instance_find(key, true, false);
2286 if (likely(lfsck != NULL)) {
2287 mutex_lock(&lfsck->li_mutex);
2288 if (__lfsck_set_speed(lfsck, val))
2289 rc = lfsck_bookmark_store(&env, lfsck);
2290 mutex_unlock(&lfsck->li_mutex);
2291 lfsck_instance_put(&env, lfsck);
2300 EXPORT_SYMBOL(lfsck_set_speed);
2302 int lfsck_get_windows(struct seq_file *m, struct dt_device *key)
2305 struct lfsck_instance *lfsck;
2309 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2313 lfsck = lfsck_instance_find(key, true, false);
2314 if (likely(lfsck != NULL)) {
2315 seq_printf(m, "%u\n", lfsck->li_bookmark_ram.lb_async_windows);
2316 lfsck_instance_put(&env, lfsck);
2325 EXPORT_SYMBOL(lfsck_get_windows);
2327 int lfsck_set_windows(struct dt_device *key, int val)
2330 struct lfsck_instance *lfsck;
2334 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2338 lfsck = lfsck_instance_find(key, true, false);
2339 if (likely(lfsck != NULL)) {
2340 if (val > LFSCK_ASYNC_WIN_MAX) {
2341 CWARN("%s: Too large async window size, which "
2342 "may cause memory issues. The valid range "
2343 "is [0 - %u]. If you do not want to restrict "
2344 "the window size for async requests pipeline, "
2345 "just set it as 0.\n",
2346 lfsck_lfsck2name(lfsck), LFSCK_ASYNC_WIN_MAX);
2348 } else if (lfsck->li_bookmark_ram.lb_async_windows != val) {
2349 mutex_lock(&lfsck->li_mutex);
2350 lfsck->li_bookmark_ram.lb_async_windows = val;
2351 rc = lfsck_bookmark_store(&env, lfsck);
2352 mutex_unlock(&lfsck->li_mutex);
2354 lfsck_instance_put(&env, lfsck);
2363 EXPORT_SYMBOL(lfsck_set_windows);
2365 int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
2368 struct lfsck_instance *lfsck;
2369 struct lfsck_component *com;
2373 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2377 lfsck = lfsck_instance_find(key, true, false);
2378 if (likely(lfsck != NULL)) {
2379 com = lfsck_component_find(lfsck, type);
2380 if (likely(com != NULL)) {
2381 rc = com->lc_ops->lfsck_dump(&env, com, m);
2382 lfsck_component_put(&env, com);
2387 lfsck_instance_put(&env, lfsck);
2396 EXPORT_SYMBOL(lfsck_dump);
2398 static int lfsck_stop_all(const struct lu_env *env,
2399 struct lfsck_instance *lfsck,
2400 struct lfsck_stop *stop)
2402 struct lfsck_thread_info *info = lfsck_env_info(env);
2403 struct lfsck_request *lr = &info->lti_lr;
2404 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2405 struct ptlrpc_request_set *set;
2406 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2407 struct lfsck_tgt_desc *ltd;
2408 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2414 LASSERT(stop->ls_flags & LPF_BROADCAST);
2416 set = ptlrpc_prep_set();
2417 if (unlikely(set == NULL))
2420 memset(lr, 0, sizeof(*lr));
2421 lr->lr_event = LE_STOP;
2422 lr->lr_index = lfsck_dev_idx(lfsck->li_bottom);
2423 lr->lr_status = stop->ls_status;
2424 lr->lr_version = bk->lb_version;
2425 lr->lr_active = LFSCK_TYPES_ALL;
2426 lr->lr_param = stop->ls_flags;
2428 laia->laia_com = NULL;
2429 laia->laia_ltds = ltds;
2431 laia->laia_result = 0;
2432 laia->laia_shared = 1;
2434 down_read(<ds->ltd_rw_sem);
2435 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2436 ltd = lfsck_tgt_get(ltds, idx);
2437 LASSERT(ltd != NULL);
2439 laia->laia_ltd = ltd;
2440 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2441 lfsck_async_interpret, laia,
2444 lfsck_interpret(env, lfsck, NULL, laia, rc);
2446 CERROR("%s: cannot notify MDT %x for LFSCK stop: "
2447 "rc = %d\n", lfsck_lfsck2name(lfsck), idx, rc);
2451 up_read(<ds->ltd_rw_sem);
2453 rc = ptlrpc_set_wait(set);
2454 ptlrpc_set_destroy(set);
2457 rc = laia->laia_result;
2459 if (rc == -EALREADY)
2463 CERROR("%s: fail to stop LFSCK on some MDTs: rc = %d\n",
2464 lfsck_lfsck2name(lfsck), rc);
2466 RETURN(rc != 0 ? rc : rc1);
2469 static int lfsck_start_all(const struct lu_env *env,
2470 struct lfsck_instance *lfsck,
2471 struct lfsck_start *start)
2473 struct lfsck_thread_info *info = lfsck_env_info(env);
2474 struct lfsck_request *lr = &info->lti_lr;
2475 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2476 struct ptlrpc_request_set *set;
2477 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2478 struct lfsck_tgt_desc *ltd;
2479 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2484 LASSERT(start->ls_flags & LPF_BROADCAST);
2486 set = ptlrpc_prep_set();
2487 if (unlikely(set == NULL))
2490 memset(lr, 0, sizeof(*lr));
2491 lr->lr_event = LE_START;
2492 lr->lr_index = lfsck_dev_idx(lfsck->li_bottom);
2493 lr->lr_speed = bk->lb_speed_limit;
2494 lr->lr_version = bk->lb_version;
2495 lr->lr_active = start->ls_active;
2496 lr->lr_param = start->ls_flags;
2497 lr->lr_async_windows = bk->lb_async_windows;
2498 lr->lr_valid = LSV_SPEED_LIMIT | LSV_ERROR_HANDLE | LSV_DRYRUN |
2501 laia->laia_com = NULL;
2502 laia->laia_ltds = ltds;
2504 laia->laia_result = 0;
2505 laia->laia_shared = 1;
2507 down_read(<ds->ltd_rw_sem);
2508 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2509 ltd = lfsck_tgt_get(ltds, idx);
2510 LASSERT(ltd != NULL);
2512 laia->laia_ltd = ltd;
2513 ltd->ltd_layout_done = 0;
2514 ltd->ltd_namespace_done = 0;
2515 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2516 lfsck_async_interpret, laia,
2519 lfsck_interpret(env, lfsck, NULL, laia, rc);
2521 CERROR("%s: cannot notify MDT %x for LFSCK "
2522 "start, failout: rc = %d\n",
2523 lfsck_lfsck2name(lfsck), idx, rc);
2527 up_read(<ds->ltd_rw_sem);
2530 ptlrpc_set_destroy(set);
2535 rc = ptlrpc_set_wait(set);
2536 ptlrpc_set_destroy(set);
2539 rc = laia->laia_result;
2542 struct lfsck_stop *stop = &info->lti_stop;
2544 CERROR("%s: cannot start LFSCK on some MDTs, "
2545 "stop all: rc = %d\n",
2546 lfsck_lfsck2name(lfsck), rc);
2547 if (rc != -EALREADY) {
2548 stop->ls_status = LS_FAILED;
2549 stop->ls_flags = LPF_ALL_TGT | LPF_BROADCAST;
2550 lfsck_stop_all(env, lfsck, stop);
2557 int lfsck_start(const struct lu_env *env, struct dt_device *key,
2558 struct lfsck_start_param *lsp)
2560 struct lfsck_start *start = lsp->lsp_start;
2561 struct lfsck_instance *lfsck;
2562 struct lfsck_bookmark *bk;
2563 struct ptlrpc_thread *thread;
2564 struct lfsck_component *com;
2565 struct l_wait_info lwi = { 0 };
2566 struct lfsck_thread_args *lta;
2567 struct task_struct *task;
2574 lfsck = lfsck_instance_find(key, true, false);
2575 if (unlikely(lfsck == NULL))
2578 /* System is not ready, try again later. */
2579 if (unlikely(lfsck->li_namespace == NULL))
2580 GOTO(put, rc = -EAGAIN);
2582 /* start == NULL means auto trigger paused LFSCK. */
2583 if ((start == NULL) &&
2584 (list_empty(&lfsck->li_list_scan) ||
2585 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AUTO)))
2588 bk = &lfsck->li_bookmark_ram;
2589 thread = &lfsck->li_thread;
2590 mutex_lock(&lfsck->li_mutex);
2591 spin_lock(&lfsck->li_lock);
2592 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
2594 if (unlikely(start == NULL)) {
2595 spin_unlock(&lfsck->li_lock);
2599 while (start->ls_active != 0) {
2600 if (!(type & start->ls_active)) {
2605 com = __lfsck_component_find(lfsck, type,
2606 &lfsck->li_list_scan);
2608 com = __lfsck_component_find(lfsck, type,
2609 &lfsck->li_list_double_scan);
2615 if (com->lc_ops->lfsck_join != NULL) {
2616 rc = com->lc_ops->lfsck_join( env, com, lsp);
2617 if (rc != 0 && rc != -EALREADY)
2620 start->ls_active &= ~type;
2623 spin_unlock(&lfsck->li_lock);
2626 spin_unlock(&lfsck->li_lock);
2628 lfsck->li_status = 0;
2629 lfsck->li_oit_over = 0;
2630 lfsck->li_start_unplug = 0;
2631 lfsck->li_drop_dryrun = 0;
2632 lfsck->li_new_scanned = 0;
2634 /* For auto trigger. */
2638 if (start->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
2639 CERROR("%s: only allow to specify '-A | -o' via MDS\n",
2640 lfsck_lfsck2name(lfsck));
2642 GOTO(out, rc = -EPERM);
2645 start->ls_version = bk->lb_version;
2647 if (start->ls_active != 0) {
2648 struct lfsck_component *next;
2650 if (start->ls_active == LFSCK_TYPES_ALL)
2651 start->ls_active = LFSCK_TYPES_SUPPORTED;
2653 if (start->ls_active & ~LFSCK_TYPES_SUPPORTED) {
2654 start->ls_active &= ~LFSCK_TYPES_SUPPORTED;
2655 GOTO(out, rc = -ENOTSUPP);
2658 list_for_each_entry_safe(com, next,
2659 &lfsck->li_list_scan, lc_link) {
2660 if (!(com->lc_type & start->ls_active)) {
2661 rc = com->lc_ops->lfsck_post(env, com, 0,
2668 while (start->ls_active != 0) {
2669 if (type & start->ls_active) {
2670 com = __lfsck_component_find(lfsck, type,
2671 &lfsck->li_list_idle);
2673 /* The component status will be updated
2674 * when its prep() is called later by
2675 * the LFSCK main engine. */
2676 list_move_tail(&com->lc_link,
2677 &lfsck->li_list_scan);
2678 start->ls_active &= ~type;
2684 if (list_empty(&lfsck->li_list_scan)) {
2685 /* The speed limit will be used to control both the LFSCK and
2686 * low layer scrub (if applied), need to be handled firstly. */
2687 if (start->ls_valid & LSV_SPEED_LIMIT) {
2688 if (__lfsck_set_speed(lfsck, start->ls_speed_limit)) {
2689 rc = lfsck_bookmark_store(env, lfsck);
2698 if (start->ls_flags & LPF_RESET)
2699 flags |= DOIF_RESET;
2701 rc = lfsck_set_param(env, lfsck, start, !!(flags & DOIF_RESET));
2705 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
2706 start->ls_active |= com->lc_type;
2707 if (flags & DOIF_RESET) {
2708 rc = com->lc_ops->lfsck_reset(env, com, false);
2715 lfsck->li_args_dir = LUDA_64BITHASH | LUDA_VERIFY | LUDA_TYPE;
2716 if (bk->lb_param & LPF_DRYRUN)
2717 lfsck->li_args_dir |= LUDA_VERIFY_DRYRUN;
2719 if (start != NULL && start->ls_valid & LSV_ERROR_HANDLE) {
2720 valid |= DOIV_ERROR_HANDLE;
2721 if (start->ls_flags & LPF_FAILOUT)
2722 flags |= DOIF_FAILOUT;
2725 if (start != NULL && start->ls_valid & LSV_DRYRUN) {
2726 valid |= DOIV_DRYRUN;
2727 if (start->ls_flags & LPF_DRYRUN)
2728 flags |= DOIF_DRYRUN;
2731 if (!list_empty(&lfsck->li_list_scan))
2732 flags |= DOIF_OUTUSED;
2734 lfsck->li_args_oit = (flags << DT_OTABLE_IT_FLAGS_SHIFT) | valid;
2735 thread_set_flags(thread, 0);
2736 lta = lfsck_thread_args_init(lfsck, NULL, lsp);
2738 GOTO(out, rc = PTR_ERR(lta));
2740 __lfsck_set_speed(lfsck, bk->lb_speed_limit);
2741 task = kthread_run(lfsck_master_engine, lta, "lfsck");
2744 CERROR("%s: cannot start LFSCK thread: rc = %d\n",
2745 lfsck_lfsck2name(lfsck), rc);
2746 lfsck_thread_args_fini(lta);
2751 l_wait_event(thread->t_ctl_waitq,
2752 thread_is_running(thread) ||
2753 thread_is_stopped(thread),
2755 if (start == NULL || !(start->ls_flags & LPF_BROADCAST)) {
2756 lfsck->li_start_unplug = 1;
2757 wake_up_all(&thread->t_ctl_waitq);
2762 /* release lfsck::li_mutex to avoid deadlock. */
2763 mutex_unlock(&lfsck->li_mutex);
2764 rc = lfsck_start_all(env, lfsck, start);
2766 spin_lock(&lfsck->li_lock);
2767 if (thread_is_stopped(thread)) {
2768 spin_unlock(&lfsck->li_lock);
2770 lfsck->li_status = LS_FAILED;
2771 lfsck->li_flags = 0;
2772 thread_set_flags(thread, SVC_STOPPING);
2773 spin_unlock(&lfsck->li_lock);
2775 lfsck->li_start_unplug = 1;
2776 wake_up_all(&thread->t_ctl_waitq);
2777 l_wait_event(thread->t_ctl_waitq,
2778 thread_is_stopped(thread),
2782 lfsck->li_start_unplug = 1;
2783 wake_up_all(&thread->t_ctl_waitq);
2789 mutex_unlock(&lfsck->li_mutex);
2792 lfsck_instance_put(env, lfsck);
2794 return rc < 0 ? rc : 0;
2796 EXPORT_SYMBOL(lfsck_start);
2798 int lfsck_stop(const struct lu_env *env, struct dt_device *key,
2799 struct lfsck_stop *stop)
2801 struct lfsck_instance *lfsck;
2802 struct ptlrpc_thread *thread;
2803 struct l_wait_info lwi = { 0 };
2808 lfsck = lfsck_instance_find(key, true, false);
2809 if (unlikely(lfsck == NULL))
2812 thread = &lfsck->li_thread;
2813 /* release lfsck::li_mutex to avoid deadlock. */
2814 if (stop != NULL && stop->ls_flags & LPF_BROADCAST) {
2815 if (!lfsck->li_master) {
2816 CERROR("%s: only allow to specify '-A' via MDS\n",
2817 lfsck_lfsck2name(lfsck));
2819 GOTO(out, rc = -EPERM);
2822 rc1 = lfsck_stop_all(env, lfsck, stop);
2825 mutex_lock(&lfsck->li_mutex);
2826 spin_lock(&lfsck->li_lock);
2827 /* no error if LFSCK is already stopped, or was never started */
2828 if (thread_is_init(thread) || thread_is_stopped(thread)) {
2829 spin_unlock(&lfsck->li_lock);
2834 lfsck->li_status = stop->ls_status;
2835 lfsck->li_flags = stop->ls_flags;
2837 lfsck->li_status = LS_STOPPED;
2838 lfsck->li_flags = 0;
2841 thread_set_flags(thread, SVC_STOPPING);
2842 spin_unlock(&lfsck->li_lock);
2844 wake_up_all(&thread->t_ctl_waitq);
2845 l_wait_event(thread->t_ctl_waitq,
2846 thread_is_stopped(thread),
2852 mutex_unlock(&lfsck->li_mutex);
2853 lfsck_instance_put(env, lfsck);
2855 return rc != 0 ? rc : rc1;
2857 EXPORT_SYMBOL(lfsck_stop);
2859 int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
2860 struct lfsck_request *lr)
2862 int rc = -EOPNOTSUPP;
2865 switch (lr->lr_event) {
2867 struct lfsck_start *start = &lfsck_env_info(env)->lti_start;
2868 struct lfsck_start_param lsp;
2870 memset(start, 0, sizeof(*start));
2871 start->ls_valid = lr->lr_valid;
2872 start->ls_speed_limit = lr->lr_speed;
2873 start->ls_version = lr->lr_version;
2874 start->ls_active = lr->lr_active;
2875 start->ls_flags = lr->lr_param & ~LPF_BROADCAST;
2876 start->ls_async_windows = lr->lr_async_windows;
2878 lsp.lsp_start = start;
2879 lsp.lsp_index = lr->lr_index;
2880 lsp.lsp_index_valid = 1;
2881 rc = lfsck_start(env, key, &lsp);
2885 struct lfsck_stop *stop = &lfsck_env_info(env)->lti_stop;
2887 memset(stop, 0, sizeof(*stop));
2888 stop->ls_status = lr->lr_status;
2889 stop->ls_flags = lr->lr_param & ~LPF_BROADCAST;
2890 rc = lfsck_stop(env, key, stop);
2893 case LE_PHASE1_DONE:
2894 case LE_PHASE2_DONE:
2895 case LE_FID_ACCESSED:
2897 case LE_CONDITIONAL_DESTROY:
2898 case LE_PAIRS_VERIFY: {
2899 struct lfsck_instance *lfsck;
2900 struct lfsck_component *com;
2902 lfsck = lfsck_instance_find(key, true, false);
2903 if (unlikely(lfsck == NULL))
2906 com = lfsck_component_find(lfsck, lr->lr_active);
2907 if (likely(com != NULL)) {
2908 rc = com->lc_ops->lfsck_in_notify(env, com, lr);
2909 lfsck_component_put(env, com);
2912 lfsck_instance_put(env, lfsck);
2921 EXPORT_SYMBOL(lfsck_in_notify);
2923 int lfsck_query(const struct lu_env *env, struct dt_device *key,
2924 struct lfsck_request *lr)
2926 struct lfsck_instance *lfsck;
2927 struct lfsck_component *com;
2931 lfsck = lfsck_instance_find(key, true, false);
2932 if (unlikely(lfsck == NULL))
2935 com = lfsck_component_find(lfsck, lr->lr_active);
2936 if (likely(com != NULL)) {
2937 rc = com->lc_ops->lfsck_query(env, com);
2938 lfsck_component_put(env, com);
2943 lfsck_instance_put(env, lfsck);
2947 EXPORT_SYMBOL(lfsck_query);
2949 int lfsck_register_namespace(const struct lu_env *env, struct dt_device *key,
2950 struct ldlm_namespace *ns)
2952 struct lfsck_instance *lfsck;
2955 lfsck = lfsck_instance_find(key, true, false);
2956 if (likely(lfsck != NULL)) {
2957 lfsck->li_namespace = ns;
2958 lfsck_instance_put(env, lfsck);
2964 EXPORT_SYMBOL(lfsck_register_namespace);
2966 int lfsck_register(const struct lu_env *env, struct dt_device *key,
2967 struct dt_device *next, struct obd_device *obd,
2968 lfsck_out_notify notify, void *notify_data, bool master)
2970 struct lfsck_instance *lfsck;
2971 struct dt_object *root = NULL;
2972 struct dt_object *obj = NULL;
2973 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
2977 lfsck = lfsck_instance_find(key, false, false);
2978 if (unlikely(lfsck != NULL))
2981 OBD_ALLOC_PTR(lfsck);
2985 mutex_init(&lfsck->li_mutex);
2986 spin_lock_init(&lfsck->li_lock);
2987 INIT_LIST_HEAD(&lfsck->li_link);
2988 INIT_LIST_HEAD(&lfsck->li_list_scan);
2989 INIT_LIST_HEAD(&lfsck->li_list_dir);
2990 INIT_LIST_HEAD(&lfsck->li_list_double_scan);
2991 INIT_LIST_HEAD(&lfsck->li_list_idle);
2992 atomic_set(&lfsck->li_ref, 1);
2993 atomic_set(&lfsck->li_double_scan_count, 0);
2994 init_waitqueue_head(&lfsck->li_thread.t_ctl_waitq);
2995 lfsck->li_out_notify = notify;
2996 lfsck->li_out_notify_data = notify_data;
2997 lfsck->li_next = next;
2998 lfsck->li_bottom = key;
2999 lfsck->li_obd = obd;
3001 rc = lfsck_tgt_descs_init(&lfsck->li_ost_descs);
3005 rc = lfsck_tgt_descs_init(&lfsck->li_mdt_descs);
3009 fid->f_seq = FID_SEQ_LOCAL_NAME;
3012 rc = local_oid_storage_init(env, key, fid, &lfsck->li_los);
3016 rc = dt_root_get(env, key, fid);
3020 root = dt_locate(env, key, fid);
3022 GOTO(out, rc = PTR_ERR(root));
3024 if (unlikely(!dt_try_as_dir(env, root)))
3025 GOTO(out, rc = -ENOTDIR);
3027 lfsck->li_local_root_fid = *fid;
3029 lfsck->li_master = 1;
3030 if (lfsck_dev_idx(key) == 0) {
3031 struct lu_fid *pfid = &lfsck_env_info(env)->lti_fid2;
3032 const struct lu_name *cname;
3034 rc = dt_lookup(env, root,
3035 (struct dt_rec *)(&lfsck->li_global_root_fid),
3036 (const struct dt_key *)"ROOT", BYPASS_CAPA);
3040 obj = dt_locate(env, key, &lfsck->li_global_root_fid);
3042 GOTO(out, rc = PTR_ERR(obj));
3044 rc = dt_lookup(env, obj, (struct dt_rec *)fid,
3045 (const struct dt_key *)dotlustre, BYPASS_CAPA);
3049 lu_object_put(env, &obj->do_lu);
3050 obj = dt_locate(env, key, fid);
3052 GOTO(out, rc = PTR_ERR(obj));
3054 cname = lfsck_name_get_const(env, dotlustre,
3056 rc = lfsck_verify_linkea(env, key, obj, cname,
3057 &lfsck->li_global_root_fid);
3062 rc = dt_lookup(env, obj, (struct dt_rec *)fid,
3063 (const struct dt_key *)lostfound,
3068 lu_object_put(env, &obj->do_lu);
3069 obj = dt_locate(env, key, fid);
3071 GOTO(out, rc = PTR_ERR(obj));
3073 cname = lfsck_name_get_const(env, lostfound,
3075 rc = lfsck_verify_linkea(env, key, obj, cname, pfid);
3079 lu_object_put(env, &obj->do_lu);
3084 fid->f_seq = FID_SEQ_LOCAL_FILE;
3085 fid->f_oid = OTABLE_IT_OID;
3087 obj = dt_locate(env, key, fid);
3089 GOTO(out, rc = PTR_ERR(obj));
3091 lu_object_get(&obj->do_lu);
3092 lfsck->li_obj_oit = obj;
3093 rc = obj->do_ops->do_index_try(env, obj, &dt_otable_features);
3097 rc = lfsck_bookmark_setup(env, lfsck);
3102 rc = lfsck_fid_init(lfsck);
3106 rc = lfsck_namespace_setup(env, lfsck);
3111 rc = lfsck_layout_setup(env, lfsck);
3115 /* XXX: more LFSCK components initialization to be added here. */
3117 rc = lfsck_instance_add(lfsck);
3119 rc = lfsck_add_target_from_orphan(env, lfsck);
3121 if (obj != NULL && !IS_ERR(obj))
3122 lu_object_put(env, &obj->do_lu);
3123 if (root != NULL && !IS_ERR(root))
3124 lu_object_put(env, &root->do_lu);
3126 lfsck_instance_cleanup(env, lfsck);
3129 EXPORT_SYMBOL(lfsck_register);
3131 void lfsck_degister(const struct lu_env *env, struct dt_device *key)
3133 struct lfsck_instance *lfsck;
3135 lfsck = lfsck_instance_find(key, false, true);
3137 lfsck_instance_put(env, lfsck);
3139 EXPORT_SYMBOL(lfsck_degister);
3141 int lfsck_add_target(const struct lu_env *env, struct dt_device *key,
3142 struct dt_device *tgt, struct obd_export *exp,
3143 __u32 index, bool for_ost)
3145 struct lfsck_instance *lfsck;
3146 struct lfsck_tgt_desc *ltd;
3157 INIT_LIST_HEAD(<d->ltd_orphan_list);
3158 INIT_LIST_HEAD(<d->ltd_layout_list);
3159 INIT_LIST_HEAD(<d->ltd_layout_phase_list);
3160 INIT_LIST_HEAD(<d->ltd_namespace_list);
3161 INIT_LIST_HEAD(<d->ltd_namespace_phase_list);
3162 atomic_set(<d->ltd_ref, 1);
3163 ltd->ltd_index = index;
3165 spin_lock(&lfsck_instance_lock);
3166 lfsck = __lfsck_instance_find(key, true, false);
3167 if (lfsck == NULL) {
3169 list_add_tail(<d->ltd_orphan_list,
3170 &lfsck_ost_orphan_list);
3172 list_add_tail(<d->ltd_orphan_list,
3173 &lfsck_mdt_orphan_list);
3174 spin_unlock(&lfsck_instance_lock);
3178 spin_unlock(&lfsck_instance_lock);
3180 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, false);
3184 lfsck_instance_put(env, lfsck);
3188 EXPORT_SYMBOL(lfsck_add_target);
3190 void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
3191 struct dt_device *tgt, __u32 index, bool for_ost)
3193 struct lfsck_instance *lfsck;
3194 struct lfsck_tgt_descs *ltds;
3195 struct lfsck_tgt_desc *ltd;
3196 struct list_head *head;
3199 head = &lfsck_ost_orphan_list;
3201 head = &lfsck_mdt_orphan_list;
3203 spin_lock(&lfsck_instance_lock);
3204 list_for_each_entry(ltd, head, ltd_orphan_list) {
3205 if (ltd->ltd_tgt == tgt) {
3206 list_del_init(<d->ltd_orphan_list);
3207 spin_unlock(&lfsck_instance_lock);
3215 lfsck = __lfsck_instance_find(key, true, false);
3216 spin_unlock(&lfsck_instance_lock);
3217 if (unlikely(lfsck == NULL))
3221 ltds = &lfsck->li_ost_descs;
3223 ltds = &lfsck->li_mdt_descs;
3225 down_write(<ds->ltd_rw_sem);
3226 LASSERT(ltds->ltd_tgts_bitmap != NULL);
3228 if (unlikely(index >= ltds->ltd_tgts_bitmap->size))
3231 ltd = LTD_TGT(ltds, index);
3232 if (unlikely(ltd == NULL))
3235 LASSERT(ltds->ltd_tgtnr > 0);
3238 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, index);
3239 LTD_TGT(ltds, index) = NULL;
3244 head = &lfsck->li_ost_descs.ltd_orphan;
3246 head = &lfsck->li_mdt_descs.ltd_orphan;
3248 list_for_each_entry(ltd, head, ltd_orphan_list) {
3249 if (ltd->ltd_tgt == tgt) {
3250 list_del_init(<d->ltd_orphan_list);
3256 up_write(<ds->ltd_rw_sem);
3258 spin_lock(<ds->ltd_lock);
3260 spin_unlock(<ds->ltd_lock);
3261 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_NAMESPACE);
3262 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_LAYOUT);
3266 lfsck_instance_put(env, lfsck);
3268 EXPORT_SYMBOL(lfsck_del_target);
3270 static int __init lfsck_init(void)
3274 INIT_LIST_HEAD(&lfsck_instance_list);
3275 INIT_LIST_HEAD(&lfsck_ost_orphan_list);
3276 INIT_LIST_HEAD(&lfsck_mdt_orphan_list);
3277 lfsck_key_init_generic(&lfsck_thread_key, NULL);
3278 rc = lu_context_key_register(&lfsck_thread_key);
3280 tgt_register_lfsck_in_notify(lfsck_in_notify);
3281 tgt_register_lfsck_query(lfsck_query);
3287 static void __exit lfsck_exit(void)
3289 struct lfsck_tgt_desc *ltd;
3290 struct lfsck_tgt_desc *next;
3292 LASSERT(list_empty(&lfsck_instance_list));
3294 list_for_each_entry_safe(ltd, next, &lfsck_ost_orphan_list,
3296 list_del_init(<d->ltd_orphan_list);
3300 list_for_each_entry_safe(ltd, next, &lfsck_mdt_orphan_list,
3302 list_del_init(<d->ltd_orphan_list);
3306 lu_context_key_degister(&lfsck_thread_key);
3309 MODULE_AUTHOR("Intel Corporation <http://www.intel.com/>");
3310 MODULE_DESCRIPTION("LFSCK");
3311 MODULE_LICENSE("GPL");
3313 cfs_module(lfsck, LUSTRE_VERSION_STRING, lfsck_init, lfsck_exit);