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_linkea_buf2);
57 lu_buf_free(&info->lti_big_buf);
61 LU_CONTEXT_KEY_DEFINE(lfsck, LCT_MD_THREAD | LCT_DT_THREAD);
62 LU_KEY_INIT_GENERIC(lfsck);
64 static struct list_head lfsck_instance_list;
65 static struct list_head lfsck_ost_orphan_list;
66 static struct list_head lfsck_mdt_orphan_list;
67 static DEFINE_SPINLOCK(lfsck_instance_lock);
69 static const char *lfsck_status_names[] = {
71 [LS_SCANNING_PHASE1] = "scanning-phase1",
72 [LS_SCANNING_PHASE2] = "scanning-phase2",
73 [LS_COMPLETED] = "completed",
74 [LS_FAILED] = "failed",
75 [LS_STOPPED] = "stopped",
76 [LS_PAUSED] = "paused",
77 [LS_CRASHED] = "crashed",
78 [LS_PARTIAL] = "partial",
79 [LS_CO_FAILED] = "co-failed",
80 [LS_CO_STOPPED] = "co-stopped",
81 [LS_CO_PAUSED] = "co-paused"
84 const char *lfsck_flags_names[] = {
93 const char *lfsck_param_names[] = {
104 enum lfsck_verify_lpf_types {
105 LVLT_BY_BOOKMARK = 0,
106 LVLT_BY_NAMEENTRY = 1,
109 const char *lfsck_status2names(enum lfsck_status status)
111 if (unlikely(status < 0 || status >= LS_MAX))
114 return lfsck_status_names[status];
117 static int lfsck_tgt_descs_init(struct lfsck_tgt_descs *ltds)
119 spin_lock_init(<ds->ltd_lock);
120 init_rwsem(<ds->ltd_rw_sem);
121 INIT_LIST_HEAD(<ds->ltd_orphan);
122 ltds->ltd_tgts_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
123 if (ltds->ltd_tgts_bitmap == NULL)
129 static void lfsck_tgt_descs_fini(struct lfsck_tgt_descs *ltds)
131 struct lfsck_tgt_desc *ltd;
132 struct lfsck_tgt_desc *next;
135 down_write(<ds->ltd_rw_sem);
137 list_for_each_entry_safe(ltd, next, <ds->ltd_orphan,
139 list_del_init(<d->ltd_orphan_list);
143 if (unlikely(ltds->ltd_tgts_bitmap == NULL)) {
144 up_write(<ds->ltd_rw_sem);
149 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
150 ltd = LTD_TGT(ltds, idx);
151 if (likely(ltd != NULL)) {
152 LASSERT(list_empty(<d->ltd_layout_list));
153 LASSERT(list_empty(<d->ltd_layout_phase_list));
154 LASSERT(list_empty(<d->ltd_namespace_list));
155 LASSERT(list_empty(<d->ltd_namespace_phase_list));
158 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, idx);
159 LTD_TGT(ltds, idx) = NULL;
164 LASSERTF(ltds->ltd_tgtnr == 0, "tgt count unmatched: %d\n",
167 for (idx = 0; idx < TGT_PTRS; idx++) {
168 if (ltds->ltd_tgts_idx[idx] != NULL) {
169 OBD_FREE_PTR(ltds->ltd_tgts_idx[idx]);
170 ltds->ltd_tgts_idx[idx] = NULL;
174 CFS_FREE_BITMAP(ltds->ltd_tgts_bitmap);
175 ltds->ltd_tgts_bitmap = NULL;
176 up_write(<ds->ltd_rw_sem);
179 static int __lfsck_add_target(const struct lu_env *env,
180 struct lfsck_instance *lfsck,
181 struct lfsck_tgt_desc *ltd,
182 bool for_ost, bool locked)
184 struct lfsck_tgt_descs *ltds;
185 __u32 index = ltd->ltd_index;
190 ltds = &lfsck->li_ost_descs;
192 ltds = &lfsck->li_mdt_descs;
195 down_write(<ds->ltd_rw_sem);
197 LASSERT(ltds->ltd_tgts_bitmap != NULL);
199 if (index >= ltds->ltd_tgts_bitmap->size) {
200 __u32 newsize = max((__u32)ltds->ltd_tgts_bitmap->size,
201 (__u32)BITS_PER_LONG);
202 cfs_bitmap_t *old_bitmap = ltds->ltd_tgts_bitmap;
203 cfs_bitmap_t *new_bitmap;
205 while (newsize < index + 1)
208 new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
209 if (new_bitmap == NULL)
210 GOTO(unlock, rc = -ENOMEM);
212 if (ltds->ltd_tgtnr > 0)
213 cfs_bitmap_copy(new_bitmap, old_bitmap);
214 ltds->ltd_tgts_bitmap = new_bitmap;
215 CFS_FREE_BITMAP(old_bitmap);
218 if (cfs_bitmap_check(ltds->ltd_tgts_bitmap, index)) {
219 CERROR("%s: the device %s (%u) is registered already\n",
220 lfsck_lfsck2name(lfsck),
221 ltd->ltd_tgt->dd_lu_dev.ld_obd->obd_name, index);
222 GOTO(unlock, rc = -EEXIST);
225 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
226 OBD_ALLOC_PTR(ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK]);
227 if (ltds->ltd_tgts_idx[index / TGT_PTRS_PER_BLOCK] == NULL)
228 GOTO(unlock, rc = -ENOMEM);
231 LTD_TGT(ltds, index) = ltd;
232 cfs_bitmap_set(ltds->ltd_tgts_bitmap, index);
235 GOTO(unlock, rc = 0);
239 up_write(<ds->ltd_rw_sem);
244 static int lfsck_add_target_from_orphan(const struct lu_env *env,
245 struct lfsck_instance *lfsck)
247 struct lfsck_tgt_descs *ltds = &lfsck->li_ost_descs;
248 struct lfsck_tgt_desc *ltd;
249 struct lfsck_tgt_desc *next;
250 struct list_head *head = &lfsck_ost_orphan_list;
255 spin_lock(&lfsck_instance_lock);
256 list_for_each_entry_safe(ltd, next, head, ltd_orphan_list) {
257 if (ltd->ltd_key == lfsck->li_bottom)
258 list_move_tail(<d->ltd_orphan_list,
261 spin_unlock(&lfsck_instance_lock);
263 down_write(<ds->ltd_rw_sem);
264 while (!list_empty(<ds->ltd_orphan)) {
265 ltd = list_entry(ltds->ltd_orphan.next,
266 struct lfsck_tgt_desc,
268 list_del_init(<d->ltd_orphan_list);
269 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, true);
270 /* Do not hold the semaphore for too long time. */
271 up_write(<ds->ltd_rw_sem);
275 down_write(<ds->ltd_rw_sem);
277 up_write(<ds->ltd_rw_sem);
280 ltds = &lfsck->li_mdt_descs;
281 head = &lfsck_mdt_orphan_list;
289 static inline struct lfsck_component *
290 __lfsck_component_find(struct lfsck_instance *lfsck, __u16 type,
291 struct list_head *list)
293 struct lfsck_component *com;
295 list_for_each_entry(com, list, lc_link) {
296 if (com->lc_type == type)
302 struct lfsck_component *
303 lfsck_component_find(struct lfsck_instance *lfsck, __u16 type)
305 struct lfsck_component *com;
307 spin_lock(&lfsck->li_lock);
308 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
312 com = __lfsck_component_find(lfsck, type,
313 &lfsck->li_list_double_scan);
317 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_idle);
321 lfsck_component_get(com);
322 spin_unlock(&lfsck->li_lock);
326 void lfsck_component_cleanup(const struct lu_env *env,
327 struct lfsck_component *com)
329 if (!list_empty(&com->lc_link))
330 list_del_init(&com->lc_link);
331 if (!list_empty(&com->lc_link_dir))
332 list_del_init(&com->lc_link_dir);
334 lfsck_component_put(env, com);
337 int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
338 struct lu_fid *fid, bool locked)
340 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
345 mutex_lock(&lfsck->li_mutex);
347 rc = seq_client_alloc_fid(env, lfsck->li_seq, fid);
349 bk->lb_last_fid = *fid;
350 /* We do not care about whether the subsequent sub-operations
351 * failed or not. The worst case is that one FID is lost that
352 * is not a big issue for the LFSCK since it is relative rare
353 * for LFSCK create. */
354 rc = lfsck_bookmark_store(env, lfsck);
358 mutex_unlock(&lfsck->li_mutex);
364 * Request the specified ibits lock for the given object.
366 * Before the LFSCK modifying on the namespace visible object,
367 * it needs to acquire related ibits ldlm lock.
369 * \param[in] env pointer to the thread context
370 * \param[in] lfsck pointer to the lfsck instance
371 * \param[in] obj pointer to the dt_object to be locked
372 * \param[out] lh pointer to the lock handle
373 * \param[in] ibits the bits for the ldlm lock to be acquired
374 * \param[in] mode the mode for the ldlm lock to be acquired
376 * \retval 0 for success
377 * \retval negative error number on failure
379 int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
380 struct dt_object *obj, struct lustre_handle *lh,
381 __u64 bits, ldlm_mode_t mode)
383 struct lfsck_thread_info *info = lfsck_env_info(env);
384 ldlm_policy_data_t *policy = &info->lti_policy;
385 struct ldlm_res_id *resid = &info->lti_resid;
386 __u64 flags = LDLM_FL_ATOMIC_CB;
389 LASSERT(lfsck->li_namespace != NULL);
391 memset(policy, 0, sizeof(*policy));
392 policy->l_inodebits.bits = bits;
393 fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
394 rc = ldlm_cli_enqueue_local(lfsck->li_namespace, resid, LDLM_IBITS,
395 policy, mode, &flags, ldlm_blocking_ast,
396 ldlm_completion_ast, NULL, NULL, 0,
397 LVB_T_NONE, NULL, lh);
398 if (rc == ELDLM_OK) {
401 memset(lh, 0, sizeof(*lh));
409 * Release the the specified ibits lock.
411 * If the lock has been acquired before, release it
412 * and cleanup the handle. Otherwise, do nothing.
414 * \param[in] lh pointer to the lock handle
415 * \param[in] mode the mode for the ldlm lock to be released
417 void lfsck_ibits_unlock(struct lustre_handle *lh, ldlm_mode_t mode)
419 if (lustre_handle_is_used(lh)) {
420 ldlm_lock_decref(lh, mode);
421 memset(lh, 0, sizeof(*lh));
425 int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
426 struct lfsck_instance *lfsck,
427 const struct lu_fid *fid)
429 struct seq_server_site *ss =
430 lu_site2seq(lfsck->li_bottom->dd_lu_dev.ld_site);
431 struct lu_seq_range *range = &lfsck_env_info(env)->lti_range;
434 fld_range_set_mdt(range);
435 rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
437 rc = range->lsr_index;
442 static const char dot[] = ".";
443 static const char dotdot[] = "..";
444 static const char dotlustre[] = ".lustre";
445 static const char lostfound[] = "lost+found";
447 static int lfsck_create_lpf_local(const struct lu_env *env,
448 struct lfsck_instance *lfsck,
449 struct dt_object *parent,
450 struct dt_object *child,
452 struct dt_object_format *dof,
455 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
456 struct dt_device *dev = lfsck->li_bottom;
457 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
458 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
459 const struct lu_fid *cfid = lfsck_dto2fid(child);
460 struct thandle *th = NULL;
461 struct linkea_data ldata = { 0 };
462 struct lu_buf linkea_buf;
463 const struct lu_name *cname;
465 int len = sizeof(struct lfsck_bookmark);
469 rc = linkea_data_new(&ldata,
470 &lfsck_env_info(env)->lti_linkea_buf2);
474 cname = lfsck_name_get_const(env, name, strlen(name));
475 rc = linkea_add_buf(&ldata, cname, lfsck_dto2fid(parent));
479 th = dt_trans_create(env, dev);
483 /* 1a. create child */
484 rc = dt_declare_create(env, child, la, NULL, dof, th);
488 /* 2a. increase child nlink */
489 rc = dt_declare_ref_add(env, child, th);
493 /* 3a. insert linkEA for child */
494 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
495 ldata.ld_leh->leh_len);
496 rc = dt_declare_xattr_set(env, child, &linkea_buf,
497 XATTR_NAME_LINK, 0, th);
501 /* 4a. insert name into parent dir */
502 rec->rec_type = S_IFDIR;
504 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
505 (const struct dt_key *)name, th);
509 /* 5a. increase parent nlink */
510 rc = dt_declare_ref_add(env, parent, th);
514 /* 6a. update bookmark */
515 rc = dt_declare_record_write(env, bk_obj,
516 lfsck_buf_get(env, bk, len), 0, th);
520 rc = dt_trans_start_local(env, dev, th);
524 dt_write_lock(env, child, 0);
525 /* 1b.1. create child */
526 rc = dt_create(env, child, la, NULL, dof, th);
530 if (unlikely(!dt_try_as_dir(env, child)))
531 GOTO(unlock, rc = -ENOTDIR);
533 /* 1b.2. insert dot into child dir */
535 rc = dt_insert(env, child, (const struct dt_rec *)rec,
536 (const struct dt_key *)dot, th, BYPASS_CAPA, 1);
540 /* 1b.3. insert dotdot into child dir */
541 rec->rec_fid = &LU_LPF_FID;
542 rc = dt_insert(env, child, (const struct dt_rec *)rec,
543 (const struct dt_key *)dotdot, th, BYPASS_CAPA, 1);
547 /* 2b. increase child nlink */
548 rc = dt_ref_add(env, child, th);
552 /* 3b. insert linkEA for child. */
553 rc = dt_xattr_set(env, child, &linkea_buf,
554 XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
555 dt_write_unlock(env, child);
559 /* 4b. insert name into parent dir */
561 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
562 (const struct dt_key *)name, th, BYPASS_CAPA, 1);
566 dt_write_lock(env, parent, 0);
567 /* 5b. increase parent nlink */
568 rc = dt_ref_add(env, parent, th);
569 dt_write_unlock(env, parent);
573 bk->lb_lpf_fid = *cfid;
574 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
576 /* 6b. update bookmark */
577 rc = dt_record_write(env, bk_obj,
578 lfsck_buf_get(env, bk, len), &pos, th);
583 dt_write_unlock(env, child);
586 dt_trans_stop(env, dev, th);
591 static int lfsck_create_lpf_remote(const struct lu_env *env,
592 struct lfsck_instance *lfsck,
593 struct dt_object *parent,
594 struct dt_object *child,
596 struct dt_object_format *dof,
599 struct dt_insert_rec *rec = &lfsck_env_info(env)->lti_dt_rec;
600 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
601 struct dt_object *bk_obj = lfsck->li_bookmark_obj;
602 const struct lu_fid *cfid = lfsck_dto2fid(child);
603 struct thandle *th = NULL;
604 struct linkea_data ldata = { 0 };
605 struct lu_buf linkea_buf;
606 const struct lu_name *cname;
607 struct dt_device *dev;
609 int len = sizeof(struct lfsck_bookmark);
613 rc = linkea_data_new(&ldata,
614 &lfsck_env_info(env)->lti_linkea_buf2);
618 cname = lfsck_name_get_const(env, name, strlen(name));
619 rc = linkea_add_buf(&ldata, cname, lfsck_dto2fid(parent));
623 /* Create .lustre/lost+found/MDTxxxx. */
625 /* XXX: Currently, cross-MDT create operation needs to create the child
626 * object firstly, then insert name into the parent directory. For
627 * this case, the child object resides on current MDT (local), but
628 * the parent ".lustre/lost+found" may be on remote MDT. It is not
629 * easy to contain all the sub-modifications orderly within single
632 * To avoid more inconsistency, we split the create operation into
635 * 1) create the child and update the lfsck_bookmark::lb_lpf_fid
637 * 2) insert the name "MDTXXXX" in the parent ".lustre/lost+found"
640 * If 1) done, but 2) failed, then go ahead, the LFSCK will try to
641 * repair such inconsistency when LFSCK run next time. */
643 /* Transaction I: locally */
645 dev = lfsck->li_bottom;
646 th = dt_trans_create(env, dev);
650 /* 1a. create child */
651 rc = dt_declare_create(env, child, la, NULL, dof, th);
655 /* 2a. increase child nlink */
656 rc = dt_declare_ref_add(env, child, th);
660 /* 3a. insert linkEA for child */
661 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
662 ldata.ld_leh->leh_len);
663 rc = dt_declare_xattr_set(env, child, &linkea_buf,
664 XATTR_NAME_LINK, 0, th);
668 /* 4a. update bookmark */
669 rc = dt_declare_record_write(env, bk_obj,
670 lfsck_buf_get(env, bk, len), 0, th);
674 rc = dt_trans_start_local(env, dev, th);
678 dt_write_lock(env, child, 0);
679 /* 1b.1. create child */
680 rc = dt_create(env, child, la, NULL, dof, th);
684 if (unlikely(!dt_try_as_dir(env, child)))
685 GOTO(unlock, rc = -ENOTDIR);
687 /* 1b.2. insert dot into child dir */
688 rec->rec_type = S_IFDIR;
690 rc = dt_insert(env, child, (const struct dt_rec *)rec,
691 (const struct dt_key *)dot, th, BYPASS_CAPA, 1);
695 /* 1b.3. insert dotdot into child dir */
696 rec->rec_fid = &LU_LPF_FID;
697 rc = dt_insert(env, child, (const struct dt_rec *)rec,
698 (const struct dt_key *)dotdot, th, BYPASS_CAPA, 1);
702 /* 2b. increase child nlink */
703 rc = dt_ref_add(env, child, th);
707 /* 3b. insert linkEA for child */
708 rc = dt_xattr_set(env, child, &linkea_buf,
709 XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
713 bk->lb_lpf_fid = *cfid;
714 lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
716 /* 4b. update bookmark */
717 rc = dt_record_write(env, bk_obj,
718 lfsck_buf_get(env, bk, len), &pos, th);
720 dt_write_unlock(env, child);
721 dt_trans_stop(env, dev, th);
725 /* Transaction II: remotely */
727 dev = lfsck->li_next;
728 th = dt_trans_create(env, dev);
732 /* 5a. insert name into parent dir */
734 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
735 (const struct dt_key *)name, th);
739 /* 6a. increase parent nlink */
740 rc = dt_declare_ref_add(env, parent, th);
744 rc = dt_trans_start(env, dev, th);
748 /* 5b. insert name into parent dir */
749 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
750 (const struct dt_key *)name, th, BYPASS_CAPA, 1);
754 dt_write_lock(env, parent, 0);
755 /* 6b. increase parent nlink */
756 rc = dt_ref_add(env, parent, th);
757 dt_write_unlock(env, parent);
762 dt_write_unlock(env, child);
764 dt_trans_stop(env, dev, th);
766 if (rc != 0 && dev == lfsck->li_next)
767 CDEBUG(D_LFSCK, "%s: partially created the object "DFID
768 "for orphans, but failed to insert the name %s "
769 "to the .lustre/lost+found/. Such inconsistency "
770 "will be repaired when LFSCK run next time: rc = %d\n",
771 lfsck_lfsck2name(lfsck), PFID(cfid), name, rc);
776 /* Do NOT create .lustre/lost+found/MDTxxxx when register the lfsck instance,
777 * because the MDT0 maybe not reaady for sequence allocation yet. We do that
778 * only when it is required, such as orphan OST-objects repairing. */
779 int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
781 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
782 struct lfsck_thread_info *info = lfsck_env_info(env);
783 struct lu_fid *cfid = &info->lti_fid2;
784 struct lu_attr *la = &info->lti_la;
785 struct dt_object_format *dof = &info->lti_dof;
786 struct dt_object *parent = NULL;
787 struct dt_object *child = NULL;
788 struct lustre_handle lh = { 0 };
790 int node = lfsck_dev_idx(lfsck->li_bottom);
794 LASSERT(lfsck->li_master);
796 sprintf(name, "MDT%04x", node);
798 parent = lfsck_object_find_by_dev(env, lfsck->li_bottom,
801 struct lfsck_tgt_desc *ltd;
803 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
804 if (unlikely(ltd == NULL))
807 parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
812 RETURN(PTR_ERR(parent));
814 if (lfsck->li_lpf_obj != NULL)
817 if (unlikely(!dt_try_as_dir(env, parent)))
818 GOTO(out, rc = -ENOTDIR);
820 rc = lfsck_ibits_lock(env, lfsck, parent, &lh,
821 MDS_INODELOCK_UPDATE, LCK_EX);
825 mutex_lock(&lfsck->li_mutex);
826 if (lfsck->li_lpf_obj != NULL)
827 GOTO(unlock, rc = 0);
829 if (fid_is_zero(&bk->lb_lpf_fid)) {
830 /* There is corner case that: in former LFSCK scanning we have
831 * created the .lustre/lost+found/MDTxxxx but failed to update
832 * the lfsck_bookmark::lb_lpf_fid successfully. So need lookup
833 * it from MDT0 firstly. */
834 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
835 (const struct dt_key *)name, BYPASS_CAPA);
836 if (rc != 0 && rc != -ENOENT)
840 bk->lb_lpf_fid = *cfid;
841 rc = lfsck_bookmark_store(env, lfsck);
843 rc = lfsck_fid_alloc(env, lfsck, cfid, true);
848 *cfid = bk->lb_lpf_fid;
851 child = lfsck_object_find_by_dev(env, lfsck->li_bottom, cfid);
853 GOTO(unlock, rc = PTR_ERR(child));
855 if (dt_object_exists(child) != 0) {
856 if (unlikely(!dt_try_as_dir(env, child)))
859 lfsck->li_lpf_obj = child;
864 memset(la, 0, sizeof(*la));
865 la->la_atime = la->la_mtime = la->la_ctime = cfs_time_current_sec();
866 la->la_mode = S_IFDIR | S_IRWXU;
867 la->la_valid = LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
869 memset(dof, 0, sizeof(*dof));
870 dof->dof_type = dt_mode_to_dft(S_IFDIR);
873 rc = lfsck_create_lpf_local(env, lfsck, parent, child, la,
876 rc = lfsck_create_lpf_remote(env, lfsck, parent, child, la,
879 lfsck->li_lpf_obj = child;
884 mutex_unlock(&lfsck->li_mutex);
885 lfsck_ibits_unlock(&lh, LCK_EX);
886 if (rc != 0 && child != NULL && !IS_ERR(child))
887 lu_object_put(env, &child->do_lu);
889 if (parent != NULL && !IS_ERR(parent))
890 lu_object_put(env, &parent->do_lu);
896 * Scan .lustre/lost+found for bad name entries and remove them.
898 * The valid name entry should be "MDTxxxx", the "xxxx" is the MDT device
899 * index in the system. Any other formatted name is invalid and should be
902 * \param[in] env pointer to the thread context
903 * \param[in] lfsck pointer to the lfsck instance
904 * \param[in] parent pointer to the lost+found object
906 * \retval 0 for success
907 * \retval negative error number on failure
909 static int lfsck_scan_lpf_bad_entries(const struct lu_env *env,
910 struct lfsck_instance *lfsck,
911 struct dt_object *parent)
913 struct lu_dirent *ent =
914 (struct lu_dirent *)lfsck_env_info(env)->lti_key;
915 const struct dt_it_ops *iops = &parent->do_index_ops->dio_it;
920 it = iops->init(env, parent, LUDA_64BITHASH, BYPASS_CAPA);
924 rc = iops->load(env, it, 0);
926 rc = iops->next(env, it);
933 rc = iops->rec(env, it, (struct dt_rec *)ent, LUDA_64BITHASH);
937 ent->lde_namelen = le16_to_cpu(ent->lde_namelen);
938 if (ent->lde_name[0] == '.') {
939 if (ent->lde_namelen == 1)
942 if (ent->lde_namelen == 2 && ent->lde_name[1] == '.')
946 /* name length must be strlen("MDTxxxx") */
947 if (ent->lde_namelen != 7)
950 if (memcmp(ent->lde_name, "MDT", off) != 0)
953 while (off < 7 && isxdigit(ent->lde_name[off]))
959 rc = lfsck_remove_name_entry(env, lfsck, parent,
960 ent->lde_name, S_IFDIR);
966 rc = iops->next(env, it);
972 RETURN(rc > 0 ? 0 : rc);
975 static int lfsck_update_lpf_entry(const struct lu_env *env,
976 struct lfsck_instance *lfsck,
977 struct dt_object *parent,
978 struct dt_object *child,
980 enum lfsck_verify_lpf_types type)
984 if (type == LVLT_BY_BOOKMARK) {
985 rc = lfsck_update_name_entry(env, lfsck, parent, name,
986 lfsck_dto2fid(child), S_IFDIR);
987 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
988 lfsck->li_bookmark_ram.lb_lpf_fid = *lfsck_dto2fid(child);
989 rc = lfsck_bookmark_store(env, lfsck);
991 CDEBUG(D_LFSCK, "%s: update LPF fid "DFID
992 " in the bookmark file: rc = %d\n",
993 lfsck_lfsck2name(lfsck),
994 PFID(lfsck_dto2fid(child)), rc);
1001 * Check whether the @child back references the @parent.
1004 * 1) The child's FID is stored in the bookmark file. If the child back
1005 * references the parent (LU_LPF_FID object) via its ".." entry, then
1006 * insert the name (MDTxxxx) to the .lustre/lost+found; otherwise, if
1007 * the child back references another parent2, then:
1008 * 1.1) If the parent2 recognizes the child, then update the bookmark file;
1009 * 1.2) Otherwise, the LFSCK cannot know whether there will be parent3 that
1010 * references the child. So keep them there. As the LFSCK processing,
1011 * the parent3 may be found, then when the LFSCK run next time, the
1012 * inconsistency can be repaired.
1014 * 2) The child's FID is stored in the .lustre/lost+found/ sub-directory name
1015 * entry (MDTxxxx). If the child back references the parent (LU_LPF_FID obj)
1016 * via its ".." entry, then update the bookmark file, otherwise, if the child
1017 * back references another parent2, then:
1018 * 2.1) If the parent2 recognizes the child, then remove the sub-directory
1019 * from .lustre/lost+found/;
1020 * 2.2) Otherwise, if the parent2 does not recognizes the child, trust the
1021 * sub-directory name entry and update the child;
1022 * 2.3) Otherwise, if we do not know whether the parent2 recognizes the child
1023 * or not, then keep them there.
1025 * \param[in] env pointer to the thread context
1026 * \param[in] lfsck pointer to the lfsck instance
1027 * \param[in] parent pointer to the lost+found object
1028 * \param[in] child pointer to the lost+found sub-directory object
1029 * \param[in] name the name for lost+found sub-directory object
1030 * \param[out] fid pointer to the buffer to hold the FID of the object
1031 * (called it as parent2) that is referenced via the
1032 * child's dotdot entry; it also can be the FID that
1033 * is referenced by the name entry under the parent2.
1034 * \param[in] type to indicate where the child's FID is stored in
1036 * \retval positive number for uncertain inconsistency
1037 * \retval 0 for success
1038 * \retval negative error number on failure
1040 static int lfsck_verify_lpf_pairs(const struct lu_env *env,
1041 struct lfsck_instance *lfsck,
1042 struct dt_object *parent,
1043 struct dt_object *child, const char *name,
1045 enum lfsck_verify_lpf_types type)
1047 struct lfsck_thread_info *info = lfsck_env_info(env);
1048 char *name2 = info->lti_key;
1049 struct lu_fid *fid2 = &info->lti_fid3;
1050 struct dt_object *parent2 = NULL;
1051 struct lustre_handle lh = { 0 };
1056 rc = dt_lookup(env, child, (struct dt_rec *)fid,
1057 (const struct dt_key *)dotdot, BYPASS_CAPA);
1061 if (!fid_is_sane(fid))
1062 GOTO(linkea, rc = -EINVAL);
1064 if (lu_fid_eq(fid, &LU_LPF_FID)) {
1065 const struct lu_name *cname;
1067 if (lfsck->li_lpf_obj == NULL) {
1068 lu_object_get(&child->do_lu);
1069 lfsck->li_lpf_obj = child;
1072 cname = lfsck_name_get_const(env, name, strlen(name));
1073 rc = lfsck_verify_linkea(env, lfsck->li_bottom, child, cname,
1076 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1082 parent2 = lfsck_object_find_by_dev(env, lfsck->li_next, fid);
1083 if (IS_ERR(parent2))
1084 GOTO(linkea, parent2);
1086 if (!dt_object_exists(parent2)) {
1087 lu_object_put(env, &parent2->do_lu);
1089 GOTO(linkea, parent2 = ERR_PTR(-ENOENT));
1092 if (!dt_try_as_dir(env, parent2)) {
1093 lu_object_put(env, &parent2->do_lu);
1095 GOTO(linkea, parent2 = ERR_PTR(-ENOTDIR));
1099 /* To prevent rename/unlink race */
1100 rc = lfsck_ibits_lock(env, lfsck, child, &lh,
1101 MDS_INODELOCK_UPDATE, LCK_PR);
1105 dt_read_lock(env, child, 0);
1106 rc = lfsck_links_get_first(env, child, name2, fid2);
1108 dt_read_unlock(env, child);
1109 lfsck_ibits_unlock(&lh, LCK_PR);
1111 GOTO(out_put, rc = 1);
1114 /* It is almost impossible that the bookmark file (or the name entry)
1115 * and the linkEA hit the same data corruption. Trust the linkEA. */
1116 if (lu_fid_eq(fid2, &LU_LPF_FID) && strcmp(name, name2) == 0) {
1117 dt_read_unlock(env, child);
1118 lfsck_ibits_unlock(&lh, LCK_PR);
1121 if (lfsck->li_lpf_obj == NULL) {
1122 lu_object_get(&child->do_lu);
1123 lfsck->li_lpf_obj = child;
1126 /* Update the child's dotdot entry */
1127 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1128 &LU_LPF_FID, S_IFDIR);
1130 rc = lfsck_update_lpf_entry(env, lfsck, parent, child,
1136 if (parent2 == NULL || IS_ERR(parent2)) {
1137 dt_read_unlock(env, child);
1138 lfsck_ibits_unlock(&lh, LCK_PR);
1140 GOTO(out_done, rc = 1);
1143 rc = dt_lookup(env, parent2, (struct dt_rec *)fid,
1144 (const struct dt_key *)name2, BYPASS_CAPA);
1145 dt_read_unlock(env, child);
1146 lfsck_ibits_unlock(&lh, LCK_PR);
1147 if (rc != 0 && rc != -ENOENT)
1150 if (rc == -ENOENT || !lu_fid_eq(fid, lfsck_dto2fid(child))) {
1151 if (type == LVLT_BY_BOOKMARK)
1152 GOTO(out_put, rc = 1);
1154 /* Trust the name entry, update the child's dotdot entry. */
1155 rc = lfsck_update_name_entry(env, lfsck, child, dotdot,
1156 &LU_LPF_FID, S_IFDIR);
1161 if (type == LVLT_BY_BOOKMARK) {
1162 /* Invalid FID record in the bookmark file, reset it. */
1163 fid_zero(&lfsck->li_bookmark_ram.lb_lpf_fid);
1164 rc = lfsck_bookmark_store(env, lfsck);
1166 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1167 " in the bookmark file: rc = %d\n",
1168 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(child)), rc);
1169 } else /* if (type == LVLT_BY_NAMEENTRY) */ {
1170 /* The name entry is wrong, remove it. */
1171 rc = lfsck_remove_name_entry(env, lfsck, parent, name, S_IFDIR);
1177 if (parent2 != NULL && !IS_ERR(parent2))
1178 lu_object_put(env, &parent2->do_lu);
1185 * Verify the /ROOT/.lustre/lost+found/ directory.
1187 * /ROOT/.lustre/lost+found/ is a special directory to hold the objects that
1188 * the LFSCK does not exactly know how to handle, such as orphans. So before
1189 * the LFSCK scanning the system, the consistency of such directory needs to
1190 * be verified firstly to allow the users to use it during the LFSCK.
1192 * \param[in] env pointer to the thread context
1193 * \param[in] lfsck pointer to the lfsck instance
1195 * \retval positive number for uncertain inconsistency
1196 * \retval 0 for success
1197 * \retval negative error number on failure
1199 int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
1201 struct lfsck_thread_info *info = lfsck_env_info(env);
1202 struct lu_fid *pfid = &info->lti_fid;
1203 struct lu_fid *cfid = &info->lti_fid2;
1204 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1205 struct dt_object *parent = NULL;
1206 /* child1's FID is in the bookmark file. */
1207 struct dt_object *child1 = NULL;
1208 /* child2's FID is in the name entry MDTxxxx. */
1209 struct dt_object *child2 = NULL;
1210 struct dt_device *dev = lfsck->li_bottom;
1211 const struct lu_name *cname;
1213 int node = lfsck_dev_idx(dev);
1217 LASSERT(lfsck->li_master);
1220 parent = lfsck_object_find_by_dev(env, dev, &LU_LPF_FID);
1222 struct lfsck_tgt_desc *ltd;
1224 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
1225 if (unlikely(ltd == NULL))
1228 parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
1234 RETURN(PTR_ERR(parent));
1236 LASSERT(dt_object_exists(parent));
1238 if (unlikely(!dt_try_as_dir(env, parent)))
1239 GOTO(put, rc = -ENOTDIR);
1242 rc = lfsck_scan_lpf_bad_entries(env, lfsck, parent);
1244 CDEBUG(D_LFSCK, "%s: scan .lustre/lost+found/ "
1245 "for bad sub-directories: rc = %d\n",
1246 lfsck_lfsck2name(lfsck), rc);
1249 if (!fid_is_zero(&bk->lb_lpf_fid)) {
1250 if (unlikely(!fid_is_norm(&bk->lb_lpf_fid))) {
1251 struct lu_fid tfid = bk->lb_lpf_fid;
1253 /* Invalid FID record in the bookmark file, reset it. */
1254 fid_zero(&bk->lb_lpf_fid);
1255 rc = lfsck_bookmark_store(env, lfsck);
1257 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1258 " in the bookmark file: rc = %d\n",
1259 lfsck_lfsck2name(lfsck), PFID(&tfid), rc);
1264 child1 = lfsck_object_find_by_dev(env, dev,
1267 GOTO(put, rc = PTR_ERR(child1));
1269 if (unlikely(!dt_object_exists(child1) ||
1270 dt_object_remote(child1)) ||
1271 !S_ISDIR(lfsck_object_type(child1))) {
1272 /* Invalid FID record in the bookmark file,
1274 fid_zero(&bk->lb_lpf_fid);
1275 rc = lfsck_bookmark_store(env, lfsck);
1277 CDEBUG(D_LFSCK, "%s: reset invalid LPF fid "DFID
1278 " in the bookmark file: rc = %d\n",
1279 lfsck_lfsck2name(lfsck),
1280 PFID(lfsck_dto2fid(child1)), rc);
1285 lu_object_put(env, &child1->do_lu);
1287 } else if (unlikely(!dt_try_as_dir(env, child1))) {
1288 GOTO(put, rc = -ENOTDIR);
1293 snprintf(name, 8, "MDT%04x", node);
1294 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
1295 (const struct dt_key *)name, BYPASS_CAPA);
1296 if (rc == -ENOENT) {
1297 if (!fid_is_zero(&bk->lb_lpf_fid))
1306 /* Invalid FID in the name entry, remove the name entry. */
1307 if (!fid_is_norm(cfid)) {
1308 rc = lfsck_remove_name_entry(env, lfsck, parent, name, S_IFDIR);
1315 child2 = lfsck_object_find_by_dev(env, dev, cfid);
1317 GOTO(put, rc = PTR_ERR(child2));
1319 if (unlikely(!dt_object_exists(child2) ||
1320 dt_object_remote(child2)) ||
1321 !S_ISDIR(lfsck_object_type(child2))) {
1322 rc = lfsck_remove_name_entry(env, lfsck, parent, name,
1330 if (unlikely(!dt_try_as_dir(env, child2)))
1331 GOTO(put, rc = -ENOTDIR);
1333 if (child1 == NULL) {
1334 rc = lfsck_verify_lpf_pairs(env, lfsck, parent, child2, name,
1335 pfid, LVLT_BY_NAMEENTRY);
1336 } else if (!lu_fid_eq(cfid, &bk->lb_lpf_fid)) {
1337 rc = lfsck_verify_lpf_pairs(env, lfsck, parent, child1, name,
1338 pfid, LVLT_BY_BOOKMARK);
1339 if (!lu_fid_eq(pfid, &LU_LPF_FID))
1340 rc = lfsck_verify_lpf_pairs(env, lfsck, parent, child2,
1344 if (lfsck->li_lpf_obj == NULL) {
1345 lu_object_get(&child2->do_lu);
1346 lfsck->li_lpf_obj = child2;
1349 cname = lfsck_name_get_const(env, name, strlen(name));
1350 rc = lfsck_verify_linkea(env, dev, child2, cname, &LU_LPF_FID);
1357 rc = lfsck_verify_lpf_pairs(env, lfsck, parent, child1, name,
1358 pfid, LVLT_BY_BOOKMARK);
1363 if (lfsck->li_lpf_obj != NULL &&
1364 unlikely(!dt_try_as_dir(env, lfsck->li_lpf_obj)))
1367 if (child2 != NULL && !IS_ERR(child2))
1368 lu_object_put(env, &child2->do_lu);
1369 if (child1 != NULL && !IS_ERR(child1))
1370 lu_object_put(env, &child1->do_lu);
1371 if (parent != NULL && !IS_ERR(parent))
1372 lu_object_put(env, &parent->do_lu);
1377 static int lfsck_fid_init(struct lfsck_instance *lfsck)
1379 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1380 struct seq_server_site *ss;
1385 ss = lu_site2seq(lfsck->li_bottom->dd_lu_dev.ld_site);
1386 if (unlikely(ss == NULL))
1389 OBD_ALLOC_PTR(lfsck->li_seq);
1390 if (lfsck->li_seq == NULL)
1393 OBD_ALLOC(prefix, MAX_OBD_NAME + 7);
1395 GOTO(out, rc = -ENOMEM);
1397 snprintf(prefix, MAX_OBD_NAME + 7, "lfsck-%s", lfsck_lfsck2name(lfsck));
1398 rc = seq_client_init(lfsck->li_seq, NULL, LUSTRE_SEQ_METADATA, prefix,
1400 OBD_FREE(prefix, MAX_OBD_NAME + 7);
1404 if (fid_is_sane(&bk->lb_last_fid))
1405 lfsck->li_seq->lcs_fid = bk->lb_last_fid;
1410 OBD_FREE_PTR(lfsck->li_seq);
1411 lfsck->li_seq = NULL;
1416 static void lfsck_fid_fini(struct lfsck_instance *lfsck)
1418 if (lfsck->li_seq != NULL) {
1419 seq_client_fini(lfsck->li_seq);
1420 OBD_FREE_PTR(lfsck->li_seq);
1421 lfsck->li_seq = NULL;
1425 void lfsck_instance_cleanup(const struct lu_env *env,
1426 struct lfsck_instance *lfsck)
1428 struct ptlrpc_thread *thread = &lfsck->li_thread;
1429 struct lfsck_component *com;
1430 struct lfsck_component *next;
1433 LASSERT(list_empty(&lfsck->li_link));
1434 LASSERT(thread_is_init(thread) || thread_is_stopped(thread));
1436 if (lfsck->li_obj_oit != NULL) {
1437 lu_object_put_nocache(env, &lfsck->li_obj_oit->do_lu);
1438 lfsck->li_obj_oit = NULL;
1441 LASSERT(lfsck->li_obj_dir == NULL);
1443 list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
1444 lfsck_component_cleanup(env, com);
1447 LASSERT(list_empty(&lfsck->li_list_dir));
1449 list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
1451 lfsck_component_cleanup(env, com);
1454 list_for_each_entry_safe(com, next, &lfsck->li_list_idle, lc_link) {
1455 lfsck_component_cleanup(env, com);
1458 lfsck_tgt_descs_fini(&lfsck->li_ost_descs);
1459 lfsck_tgt_descs_fini(&lfsck->li_mdt_descs);
1461 if (lfsck->li_bookmark_obj != NULL) {
1462 lu_object_put_nocache(env, &lfsck->li_bookmark_obj->do_lu);
1463 lfsck->li_bookmark_obj = NULL;
1466 if (lfsck->li_lpf_obj != NULL) {
1467 lu_object_put(env, &lfsck->li_lpf_obj->do_lu);
1468 lfsck->li_lpf_obj = NULL;
1471 if (lfsck->li_los != NULL) {
1472 local_oid_storage_fini(env, lfsck->li_los);
1473 lfsck->li_los = NULL;
1476 lfsck_fid_fini(lfsck);
1478 OBD_FREE_PTR(lfsck);
1481 static inline struct lfsck_instance *
1482 __lfsck_instance_find(struct dt_device *key, bool ref, bool unlink)
1484 struct lfsck_instance *lfsck;
1486 list_for_each_entry(lfsck, &lfsck_instance_list, li_link) {
1487 if (lfsck->li_bottom == key) {
1489 lfsck_instance_get(lfsck);
1491 list_del_init(&lfsck->li_link);
1500 struct lfsck_instance *lfsck_instance_find(struct dt_device *key, bool ref,
1503 struct lfsck_instance *lfsck;
1505 spin_lock(&lfsck_instance_lock);
1506 lfsck = __lfsck_instance_find(key, ref, unlink);
1507 spin_unlock(&lfsck_instance_lock);
1512 static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
1514 struct lfsck_instance *tmp;
1516 spin_lock(&lfsck_instance_lock);
1517 list_for_each_entry(tmp, &lfsck_instance_list, li_link) {
1518 if (lfsck->li_bottom == tmp->li_bottom) {
1519 spin_unlock(&lfsck_instance_lock);
1524 list_add_tail(&lfsck->li_link, &lfsck_instance_list);
1525 spin_unlock(&lfsck_instance_lock);
1529 int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
1534 bool newline = (bits != 0 ? false : true);
1536 seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
1538 for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
1541 if (names[i] != NULL) {
1545 seq_printf(m, "%s%c", names[i],
1546 newline ? '\n' : ',');
1552 seq_printf(m, "\n");
1556 int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix)
1559 seq_printf(m, "%s: "LPU64" seconds\n", prefix,
1560 cfs_time_current_sec() - time);
1562 seq_printf(m, "%s: N/A\n", prefix);
1566 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
1569 if (fid_is_zero(&pos->lp_dir_parent)) {
1570 if (pos->lp_oit_cookie == 0)
1571 seq_printf(m, "%s: N/A, N/A, N/A\n",
1574 seq_printf(m, "%s: "LPU64", N/A, N/A\n",
1575 prefix, pos->lp_oit_cookie);
1577 seq_printf(m, "%s: "LPU64", "DFID", "LPX64"\n",
1578 prefix, pos->lp_oit_cookie,
1579 PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
1584 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
1585 struct lfsck_position *pos, bool init)
1587 const struct dt_it_ops *iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
1589 if (unlikely(lfsck->li_di_oit == NULL)) {
1590 memset(pos, 0, sizeof(*pos));
1594 pos->lp_oit_cookie = iops->store(env, lfsck->li_di_oit);
1595 if (!lfsck->li_current_oit_processed && !init)
1596 pos->lp_oit_cookie--;
1598 LASSERT(pos->lp_oit_cookie > 0);
1600 if (lfsck->li_di_dir != NULL) {
1601 struct dt_object *dto = lfsck->li_obj_dir;
1603 pos->lp_dir_cookie = dto->do_index_ops->dio_it.store(env,
1606 if (pos->lp_dir_cookie >= MDS_DIR_END_OFF) {
1607 fid_zero(&pos->lp_dir_parent);
1608 pos->lp_dir_cookie = 0;
1610 pos->lp_dir_parent = *lfsck_dto2fid(dto);
1613 fid_zero(&pos->lp_dir_parent);
1614 pos->lp_dir_cookie = 0;
1618 bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
1622 if (limit != LFSCK_SPEED_NO_LIMIT) {
1624 lfsck->li_sleep_rate = limit / HZ;
1625 lfsck->li_sleep_jif = 1;
1627 lfsck->li_sleep_rate = 1;
1628 lfsck->li_sleep_jif = HZ / limit;
1631 lfsck->li_sleep_jif = 0;
1632 lfsck->li_sleep_rate = 0;
1635 if (lfsck->li_bookmark_ram.lb_speed_limit != limit) {
1636 lfsck->li_bookmark_ram.lb_speed_limit = limit;
1643 void lfsck_control_speed(struct lfsck_instance *lfsck)
1645 struct ptlrpc_thread *thread = &lfsck->li_thread;
1646 struct l_wait_info lwi;
1648 if (lfsck->li_sleep_jif > 0 &&
1649 lfsck->li_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 lfsck->li_new_scanned = 0;
1660 void lfsck_control_speed_by_self(struct lfsck_component *com)
1662 struct lfsck_instance *lfsck = com->lc_lfsck;
1663 struct ptlrpc_thread *thread = &lfsck->li_thread;
1664 struct l_wait_info lwi;
1666 if (lfsck->li_sleep_jif > 0 &&
1667 com->lc_new_scanned >= lfsck->li_sleep_rate) {
1668 lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
1669 LWI_ON_SIGNAL_NOOP, NULL);
1671 l_wait_event(thread->t_ctl_waitq,
1672 !thread_is_running(thread),
1674 com->lc_new_scanned = 0;
1678 static struct lfsck_thread_args *
1679 lfsck_thread_args_init(struct lfsck_instance *lfsck,
1680 struct lfsck_component *com,
1681 struct lfsck_start_param *lsp)
1683 struct lfsck_thread_args *lta;
1688 return ERR_PTR(-ENOMEM);
1690 rc = lu_env_init(<a->lta_env, LCT_MD_THREAD | LCT_DT_THREAD);
1696 lta->lta_lfsck = lfsck_instance_get(lfsck);
1698 lta->lta_com = lfsck_component_get(com);
1705 void lfsck_thread_args_fini(struct lfsck_thread_args *lta)
1707 if (lta->lta_com != NULL)
1708 lfsck_component_put(<a->lta_env, lta->lta_com);
1709 lfsck_instance_put(<a->lta_env, lta->lta_lfsck);
1710 lu_env_fini(<a->lta_env);
1714 struct lfsck_assistant_data *
1715 lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
1718 struct lfsck_assistant_data *lad;
1722 lad->lad_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
1723 if (lad->lad_bitmap == NULL) {
1728 INIT_LIST_HEAD(&lad->lad_req_list);
1729 spin_lock_init(&lad->lad_lock);
1730 INIT_LIST_HEAD(&lad->lad_ost_list);
1731 INIT_LIST_HEAD(&lad->lad_ost_phase1_list);
1732 INIT_LIST_HEAD(&lad->lad_ost_phase2_list);
1733 INIT_LIST_HEAD(&lad->lad_mdt_list);
1734 INIT_LIST_HEAD(&lad->lad_mdt_phase1_list);
1735 INIT_LIST_HEAD(&lad->lad_mdt_phase2_list);
1736 init_waitqueue_head(&lad->lad_thread.t_ctl_waitq);
1738 lad->lad_name = name;
1745 * Generic LFSCK asynchronous communication interpretor function.
1746 * The LFSCK RPC reply for both the event notification and status
1747 * querying will be handled here.
1749 * \param[in] env pointer to the thread context
1750 * \param[in] req pointer to the LFSCK request
1751 * \param[in] args pointer to the lfsck_async_interpret_args
1752 * \param[in] rc the result for handling the LFSCK request
1754 * \retval 0 for success
1755 * \retval negative error number on failure
1757 int lfsck_async_interpret_common(const struct lu_env *env,
1758 struct ptlrpc_request *req,
1761 struct lfsck_async_interpret_args *laia = args;
1762 struct lfsck_component *com = laia->laia_com;
1763 struct lfsck_assistant_data *lad = com->lc_data;
1764 struct lfsck_tgt_descs *ltds = laia->laia_ltds;
1765 struct lfsck_tgt_desc *ltd = laia->laia_ltd;
1766 struct lfsck_request *lr = laia->laia_lr;
1768 LASSERT(com->lc_lfsck->li_master);
1770 switch (lr->lr_event) {
1773 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s "
1775 lfsck_lfsck2name(com->lc_lfsck),
1776 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
1777 ltd->ltd_index, lad->lad_name, rc);
1779 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1780 struct lfsck_layout *lo = com->lc_file_ram;
1782 if (lr->lr_flags & LEF_TO_OST)
1783 lfsck_lad_set_bitmap(env, com,
1786 lo->ll_flags |= LF_INCOMPLETE;
1788 struct lfsck_namespace *ns = com->lc_file_ram;
1790 /* If some MDT does not join the namespace
1791 * LFSCK, then we cannot know whether there
1792 * is some name entry on such MDT that with
1793 * the referenced MDT-object on this MDT or
1794 * not. So the namespace LFSCK on this MDT
1795 * cannot handle orphan MDT-objects properly.
1796 * So we mark the LFSCK as LF_INCOMPLETE and
1797 * skip orphan MDT-objects handling. */
1798 ns->ln_flags |= LF_INCOMPLETE;
1803 spin_lock(<ds->ltd_lock);
1804 if (ltd->ltd_dead) {
1805 spin_unlock(<ds->ltd_lock);
1809 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1810 struct list_head *list;
1811 struct list_head *phase_list;
1813 if (ltd->ltd_layout_done) {
1814 spin_unlock(<ds->ltd_lock);
1818 if (lr->lr_flags & LEF_TO_OST) {
1819 list = &lad->lad_ost_list;
1820 phase_list = &lad->lad_ost_phase1_list;
1822 list = &lad->lad_mdt_list;
1823 phase_list = &lad->lad_mdt_phase1_list;
1826 if (list_empty(<d->ltd_layout_list))
1827 list_add_tail(<d->ltd_layout_list, list);
1828 if (list_empty(<d->ltd_layout_phase_list))
1829 list_add_tail(<d->ltd_layout_phase_list,
1832 if (ltd->ltd_namespace_done) {
1833 spin_unlock(<ds->ltd_lock);
1837 if (list_empty(<d->ltd_namespace_list))
1838 list_add_tail(<d->ltd_namespace_list,
1839 &lad->lad_mdt_list);
1840 if (list_empty(<d->ltd_namespace_phase_list))
1841 list_add_tail(<d->ltd_namespace_phase_list,
1842 &lad->lad_mdt_phase1_list);
1844 spin_unlock(<ds->ltd_lock);
1847 case LE_PHASE1_DONE:
1848 case LE_PHASE2_DONE:
1850 if (rc != 0 && rc != -EALREADY)
1851 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for %s: "
1852 "event = %d, rc = %d\n",
1853 lfsck_lfsck2name(com->lc_lfsck),
1854 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
1855 ltd->ltd_index, lad->lad_name, lr->lr_event, rc);
1858 struct lfsck_reply *reply;
1859 struct list_head *list;
1860 struct list_head *phase_list;
1862 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1863 list = <d->ltd_layout_list;
1864 phase_list = <d->ltd_layout_phase_list;
1866 list = <d->ltd_namespace_list;
1867 phase_list = <d->ltd_namespace_phase_list;
1871 spin_lock(<ds->ltd_lock);
1872 list_del_init(phase_list);
1873 list_del_init(list);
1874 spin_unlock(<ds->ltd_lock);
1878 reply = req_capsule_server_get(&req->rq_pill,
1880 if (reply == NULL) {
1882 CDEBUG(D_LFSCK, "%s: invalid query reply for %s: "
1883 "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck),
1885 spin_lock(<ds->ltd_lock);
1886 list_del_init(phase_list);
1887 list_del_init(list);
1888 spin_unlock(<ds->ltd_lock);
1892 switch (reply->lr_status) {
1893 case LS_SCANNING_PHASE1:
1895 case LS_SCANNING_PHASE2:
1896 spin_lock(<ds->ltd_lock);
1897 list_del_init(phase_list);
1898 if (ltd->ltd_dead) {
1899 spin_unlock(<ds->ltd_lock);
1903 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1904 if (ltd->ltd_layout_done) {
1905 spin_unlock(<ds->ltd_lock);
1909 if (lr->lr_flags & LEF_TO_OST)
1910 list_add_tail(phase_list,
1911 &lad->lad_ost_phase2_list);
1913 list_add_tail(phase_list,
1914 &lad->lad_mdt_phase2_list);
1916 if (ltd->ltd_namespace_done) {
1917 spin_unlock(<ds->ltd_lock);
1921 list_add_tail(phase_list,
1922 &lad->lad_mdt_phase2_list);
1924 spin_unlock(<ds->ltd_lock);
1927 spin_lock(<ds->ltd_lock);
1928 list_del_init(phase_list);
1929 list_del_init(list);
1930 spin_unlock(<ds->ltd_lock);
1936 CDEBUG(D_LFSCK, "%s: unexpected event: rc = %d\n",
1937 lfsck_lfsck2name(com->lc_lfsck), lr->lr_event);
1941 if (!laia->laia_shared) {
1943 lfsck_component_put(env, com);
1949 static void lfsck_interpret(const struct lu_env *env,
1950 struct lfsck_instance *lfsck,
1951 struct ptlrpc_request *req, void *args, int result)
1953 struct lfsck_async_interpret_args *laia = args;
1954 struct lfsck_component *com;
1956 LASSERT(laia->laia_com == NULL);
1957 LASSERT(laia->laia_shared);
1959 spin_lock(&lfsck->li_lock);
1960 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
1961 laia->laia_com = com;
1962 lfsck_async_interpret_common(env, req, laia, result);
1965 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
1966 laia->laia_com = com;
1967 lfsck_async_interpret_common(env, req, laia, result);
1969 spin_unlock(&lfsck->li_lock);
1972 static int lfsck_stop_notify(const struct lu_env *env,
1973 struct lfsck_instance *lfsck,
1974 struct lfsck_tgt_descs *ltds,
1975 struct lfsck_tgt_desc *ltd, __u16 type)
1977 struct lfsck_component *com;
1981 LASSERT(lfsck->li_master);
1983 spin_lock(&lfsck->li_lock);
1984 com = __lfsck_component_find(lfsck, type, &lfsck->li_list_scan);
1986 com = __lfsck_component_find(lfsck, type,
1987 &lfsck->li_list_double_scan);
1989 lfsck_component_get(com);
1990 spin_unlock(&lfsck->li_lock);
1993 struct lfsck_thread_info *info = lfsck_env_info(env);
1994 struct lfsck_async_interpret_args *laia = &info->lti_laia;
1995 struct lfsck_request *lr = &info->lti_lr;
1996 struct lfsck_assistant_data *lad = com->lc_data;
1997 struct list_head *list;
1998 struct list_head *phase_list;
1999 struct ptlrpc_request_set *set;
2001 set = ptlrpc_prep_set();
2003 lfsck_component_put(env, com);
2008 if (type == LFSCK_TYPE_LAYOUT) {
2009 list = <d->ltd_layout_list;
2010 phase_list = <d->ltd_layout_phase_list;
2012 list = <d->ltd_namespace_list;
2013 phase_list = <d->ltd_namespace_phase_list;
2016 spin_lock(<ds->ltd_lock);
2017 if (list_empty(list)) {
2018 LASSERT(list_empty(phase_list));
2019 spin_unlock(<ds->ltd_lock);
2020 ptlrpc_set_destroy(set);
2025 list_del_init(phase_list);
2026 list_del_init(list);
2027 spin_unlock(<ds->ltd_lock);
2029 memset(lr, 0, sizeof(*lr));
2030 lr->lr_index = lfsck_dev_idx(lfsck->li_bottom);
2031 lr->lr_event = LE_PEER_EXIT;
2032 lr->lr_active = type;
2033 lr->lr_status = LS_CO_PAUSED;
2034 if (ltds == &lfsck->li_ost_descs)
2035 lr->lr_flags = LEF_TO_OST;
2037 laia->laia_com = com;
2038 laia->laia_ltds = ltds;
2039 atomic_inc(<d->ltd_ref);
2040 laia->laia_ltd = ltd;
2042 laia->laia_shared = 0;
2044 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2045 lfsck_async_interpret_common,
2046 laia, LFSCK_NOTIFY);
2048 CDEBUG(D_LFSCK, "%s: fail to notify %s %x for "
2049 "co-stop for %s: rc = %d\n",
2050 lfsck_lfsck2name(lfsck),
2051 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
2052 ltd->ltd_index, lad->lad_name, rc);
2055 rc = ptlrpc_set_wait(set);
2058 ptlrpc_set_destroy(set);
2059 lfsck_component_put(env, com);
2065 static int lfsck_async_interpret(const struct lu_env *env,
2066 struct ptlrpc_request *req,
2069 struct lfsck_async_interpret_args *laia = args;
2070 struct lfsck_instance *lfsck;
2072 lfsck = container_of0(laia->laia_ltds, struct lfsck_instance,
2074 lfsck_interpret(env, lfsck, req, laia, rc);
2075 lfsck_tgt_put(laia->laia_ltd);
2076 if (rc != 0 && laia->laia_result != -EALREADY)
2077 laia->laia_result = rc;
2082 int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
2083 struct lfsck_request *lr,
2084 struct ptlrpc_request_set *set,
2085 ptlrpc_interpterer_t interpreter,
2086 void *args, int request)
2088 struct lfsck_async_interpret_args *laia;
2089 struct ptlrpc_request *req;
2090 struct lfsck_request *tmp;
2091 struct req_format *format;
2096 format = &RQF_LFSCK_NOTIFY;
2099 format = &RQF_LFSCK_QUERY;
2102 CDEBUG(D_LFSCK, "%s: unknown async request %d: rc = %d\n",
2103 exp->exp_obd->obd_name, request, -EINVAL);
2107 req = ptlrpc_request_alloc(class_exp2cliimp(exp), format);
2111 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, request);
2113 ptlrpc_request_free(req);
2118 tmp = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
2120 ptlrpc_request_set_replen(req);
2122 laia = ptlrpc_req_async_args(req);
2123 *laia = *(struct lfsck_async_interpret_args *)args;
2124 if (laia->laia_com != NULL)
2125 lfsck_component_get(laia->laia_com);
2126 req->rq_interpret_reply = interpreter;
2127 ptlrpc_set_add_req(set, req);
2132 int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
2133 struct lfsck_start_param *lsp)
2135 struct lfsck_instance *lfsck = com->lc_lfsck;
2136 struct lfsck_assistant_data *lad = com->lc_data;
2137 struct ptlrpc_thread *mthread = &lfsck->li_thread;
2138 struct ptlrpc_thread *athread = &lad->lad_thread;
2139 struct lfsck_thread_args *lta;
2140 struct task_struct *task;
2144 lad->lad_assistant_status = 0;
2145 lad->lad_post_result = 0;
2146 lad->lad_to_post = 0;
2147 lad->lad_to_double_scan = 0;
2148 lad->lad_in_double_scan = 0;
2150 thread_set_flags(athread, 0);
2152 lta = lfsck_thread_args_init(lfsck, com, lsp);
2154 RETURN(PTR_ERR(lta));
2156 task = kthread_run(lfsck_assistant_engine, lta, lad->lad_name);
2159 CERROR("%s: cannot start LFSCK assistant thread for %s: "
2160 "rc = %d\n", lfsck_lfsck2name(lfsck), lad->lad_name, rc);
2161 lfsck_thread_args_fini(lta);
2163 struct l_wait_info lwi = { 0 };
2165 l_wait_event(mthread->t_ctl_waitq,
2166 thread_is_running(athread) ||
2167 thread_is_stopped(athread),
2169 if (unlikely(!thread_is_running(athread)))
2170 rc = lad->lad_assistant_status;
2178 int lfsck_checkpoint_generic(const struct lu_env *env,
2179 struct lfsck_component *com)
2181 struct lfsck_assistant_data *lad = com->lc_data;
2182 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2183 struct ptlrpc_thread *athread = &lad->lad_thread;
2184 struct l_wait_info lwi = { 0 };
2186 if (com->lc_new_checked == 0)
2187 return LFSCK_CHECKPOINT_SKIP;
2189 l_wait_event(mthread->t_ctl_waitq,
2190 list_empty(&lad->lad_req_list) ||
2191 !thread_is_running(mthread) ||
2192 thread_is_stopped(athread),
2195 if (!thread_is_running(mthread) || thread_is_stopped(athread))
2196 return LFSCK_CHECKPOINT_SKIP;
2201 void lfsck_post_generic(const struct lu_env *env,
2202 struct lfsck_component *com, int *result)
2204 struct lfsck_assistant_data *lad = com->lc_data;
2205 struct ptlrpc_thread *athread = &lad->lad_thread;
2206 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2207 struct l_wait_info lwi = { 0 };
2209 lad->lad_post_result = *result;
2212 lad->lad_to_post = 1;
2214 wake_up_all(&athread->t_ctl_waitq);
2215 l_wait_event(mthread->t_ctl_waitq,
2216 (*result > 0 && list_empty(&lad->lad_req_list)) ||
2217 thread_is_stopped(athread),
2220 if (lad->lad_assistant_status < 0)
2221 *result = lad->lad_assistant_status;
2224 int lfsck_double_scan_generic(const struct lu_env *env,
2225 struct lfsck_component *com, int status)
2227 struct lfsck_assistant_data *lad = com->lc_data;
2228 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2229 struct ptlrpc_thread *athread = &lad->lad_thread;
2230 struct l_wait_info lwi = { 0 };
2232 if (status != LS_SCANNING_PHASE2)
2235 lad->lad_to_double_scan = 1;
2237 wake_up_all(&athread->t_ctl_waitq);
2238 l_wait_event(mthread->t_ctl_waitq,
2239 lad->lad_in_double_scan ||
2240 thread_is_stopped(athread),
2243 if (lad->lad_assistant_status < 0)
2244 return lad->lad_assistant_status;
2249 void lfsck_quit_generic(const struct lu_env *env,
2250 struct lfsck_component *com)
2252 struct lfsck_assistant_data *lad = com->lc_data;
2253 struct ptlrpc_thread *mthread = &com->lc_lfsck->li_thread;
2254 struct ptlrpc_thread *athread = &lad->lad_thread;
2255 struct l_wait_info lwi = { 0 };
2258 wake_up_all(&athread->t_ctl_waitq);
2259 l_wait_event(mthread->t_ctl_waitq,
2260 thread_is_init(athread) ||
2261 thread_is_stopped(athread),
2265 /* external interfaces */
2267 int lfsck_get_speed(struct seq_file *m, struct dt_device *key)
2270 struct lfsck_instance *lfsck;
2274 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2278 lfsck = lfsck_instance_find(key, true, false);
2279 if (likely(lfsck != NULL)) {
2280 seq_printf(m, "%u\n", lfsck->li_bookmark_ram.lb_speed_limit);
2281 lfsck_instance_put(&env, lfsck);
2290 EXPORT_SYMBOL(lfsck_get_speed);
2292 int lfsck_set_speed(struct dt_device *key, int val)
2295 struct lfsck_instance *lfsck;
2299 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2303 lfsck = lfsck_instance_find(key, true, false);
2304 if (likely(lfsck != NULL)) {
2305 mutex_lock(&lfsck->li_mutex);
2306 if (__lfsck_set_speed(lfsck, val))
2307 rc = lfsck_bookmark_store(&env, lfsck);
2308 mutex_unlock(&lfsck->li_mutex);
2309 lfsck_instance_put(&env, lfsck);
2318 EXPORT_SYMBOL(lfsck_set_speed);
2320 int lfsck_get_windows(struct seq_file *m, struct dt_device *key)
2323 struct lfsck_instance *lfsck;
2327 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2331 lfsck = lfsck_instance_find(key, true, false);
2332 if (likely(lfsck != NULL)) {
2333 seq_printf(m, "%u\n", lfsck->li_bookmark_ram.lb_async_windows);
2334 lfsck_instance_put(&env, lfsck);
2343 EXPORT_SYMBOL(lfsck_get_windows);
2345 int lfsck_set_windows(struct dt_device *key, int val)
2348 struct lfsck_instance *lfsck;
2352 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2356 lfsck = lfsck_instance_find(key, true, false);
2357 if (likely(lfsck != NULL)) {
2358 if (val > LFSCK_ASYNC_WIN_MAX) {
2359 CWARN("%s: Too large async window size, which "
2360 "may cause memory issues. The valid range "
2361 "is [0 - %u]. If you do not want to restrict "
2362 "the window size for async requests pipeline, "
2363 "just set it as 0.\n",
2364 lfsck_lfsck2name(lfsck), LFSCK_ASYNC_WIN_MAX);
2366 } else if (lfsck->li_bookmark_ram.lb_async_windows != val) {
2367 mutex_lock(&lfsck->li_mutex);
2368 lfsck->li_bookmark_ram.lb_async_windows = val;
2369 rc = lfsck_bookmark_store(&env, lfsck);
2370 mutex_unlock(&lfsck->li_mutex);
2372 lfsck_instance_put(&env, lfsck);
2381 EXPORT_SYMBOL(lfsck_set_windows);
2383 int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
2386 struct lfsck_instance *lfsck;
2387 struct lfsck_component *com;
2391 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
2395 lfsck = lfsck_instance_find(key, true, false);
2396 if (likely(lfsck != NULL)) {
2397 com = lfsck_component_find(lfsck, type);
2398 if (likely(com != NULL)) {
2399 rc = com->lc_ops->lfsck_dump(&env, com, m);
2400 lfsck_component_put(&env, com);
2405 lfsck_instance_put(&env, lfsck);
2414 EXPORT_SYMBOL(lfsck_dump);
2416 static int lfsck_stop_all(const struct lu_env *env,
2417 struct lfsck_instance *lfsck,
2418 struct lfsck_stop *stop)
2420 struct lfsck_thread_info *info = lfsck_env_info(env);
2421 struct lfsck_request *lr = &info->lti_lr;
2422 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2423 struct ptlrpc_request_set *set;
2424 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2425 struct lfsck_tgt_desc *ltd;
2426 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2432 LASSERT(stop->ls_flags & LPF_BROADCAST);
2434 set = ptlrpc_prep_set();
2435 if (unlikely(set == NULL))
2438 memset(lr, 0, sizeof(*lr));
2439 lr->lr_event = LE_STOP;
2440 lr->lr_index = lfsck_dev_idx(lfsck->li_bottom);
2441 lr->lr_status = stop->ls_status;
2442 lr->lr_version = bk->lb_version;
2443 lr->lr_active = LFSCK_TYPES_ALL;
2444 lr->lr_param = stop->ls_flags;
2446 laia->laia_com = NULL;
2447 laia->laia_ltds = ltds;
2449 laia->laia_result = 0;
2450 laia->laia_shared = 1;
2452 down_read(<ds->ltd_rw_sem);
2453 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2454 ltd = lfsck_tgt_get(ltds, idx);
2455 LASSERT(ltd != NULL);
2457 laia->laia_ltd = ltd;
2458 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2459 lfsck_async_interpret, laia,
2462 lfsck_interpret(env, lfsck, NULL, laia, rc);
2464 CERROR("%s: cannot notify MDT %x for LFSCK stop: "
2465 "rc = %d\n", lfsck_lfsck2name(lfsck), idx, rc);
2469 up_read(<ds->ltd_rw_sem);
2471 rc = ptlrpc_set_wait(set);
2472 ptlrpc_set_destroy(set);
2475 rc = laia->laia_result;
2477 if (rc == -EALREADY)
2481 CERROR("%s: fail to stop LFSCK on some MDTs: rc = %d\n",
2482 lfsck_lfsck2name(lfsck), rc);
2484 RETURN(rc != 0 ? rc : rc1);
2487 static int lfsck_start_all(const struct lu_env *env,
2488 struct lfsck_instance *lfsck,
2489 struct lfsck_start *start)
2491 struct lfsck_thread_info *info = lfsck_env_info(env);
2492 struct lfsck_request *lr = &info->lti_lr;
2493 struct lfsck_async_interpret_args *laia = &info->lti_laia;
2494 struct ptlrpc_request_set *set;
2495 struct lfsck_tgt_descs *ltds = &lfsck->li_mdt_descs;
2496 struct lfsck_tgt_desc *ltd;
2497 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2502 LASSERT(start->ls_flags & LPF_BROADCAST);
2504 set = ptlrpc_prep_set();
2505 if (unlikely(set == NULL))
2508 memset(lr, 0, sizeof(*lr));
2509 lr->lr_event = LE_START;
2510 lr->lr_index = lfsck_dev_idx(lfsck->li_bottom);
2511 lr->lr_speed = bk->lb_speed_limit;
2512 lr->lr_version = bk->lb_version;
2513 lr->lr_active = start->ls_active;
2514 lr->lr_param = start->ls_flags;
2515 lr->lr_async_windows = bk->lb_async_windows;
2516 lr->lr_valid = LSV_SPEED_LIMIT | LSV_ERROR_HANDLE | LSV_DRYRUN |
2519 laia->laia_com = NULL;
2520 laia->laia_ltds = ltds;
2522 laia->laia_result = 0;
2523 laia->laia_shared = 1;
2525 down_read(<ds->ltd_rw_sem);
2526 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
2527 ltd = lfsck_tgt_get(ltds, idx);
2528 LASSERT(ltd != NULL);
2530 laia->laia_ltd = ltd;
2531 ltd->ltd_layout_done = 0;
2532 ltd->ltd_namespace_done = 0;
2533 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
2534 lfsck_async_interpret, laia,
2537 lfsck_interpret(env, lfsck, NULL, laia, rc);
2539 CERROR("%s: cannot notify MDT %x for LFSCK "
2540 "start, failout: rc = %d\n",
2541 lfsck_lfsck2name(lfsck), idx, rc);
2545 up_read(<ds->ltd_rw_sem);
2548 ptlrpc_set_destroy(set);
2553 rc = ptlrpc_set_wait(set);
2554 ptlrpc_set_destroy(set);
2557 rc = laia->laia_result;
2560 struct lfsck_stop *stop = &info->lti_stop;
2562 CERROR("%s: cannot start LFSCK on some MDTs, "
2563 "stop all: rc = %d\n",
2564 lfsck_lfsck2name(lfsck), rc);
2565 if (rc != -EALREADY) {
2566 stop->ls_status = LS_FAILED;
2567 stop->ls_flags = LPF_ALL_TGT | LPF_BROADCAST;
2568 lfsck_stop_all(env, lfsck, stop);
2575 int lfsck_start(const struct lu_env *env, struct dt_device *key,
2576 struct lfsck_start_param *lsp)
2578 struct lfsck_start *start = lsp->lsp_start;
2579 struct lfsck_instance *lfsck;
2580 struct lfsck_bookmark *bk;
2581 struct ptlrpc_thread *thread;
2582 struct lfsck_component *com;
2583 struct l_wait_info lwi = { 0 };
2584 struct lfsck_thread_args *lta;
2585 struct task_struct *task;
2592 lfsck = lfsck_instance_find(key, true, false);
2593 if (unlikely(lfsck == NULL))
2596 /* System is not ready, try again later. */
2597 if (unlikely(lfsck->li_namespace == NULL))
2598 GOTO(put, rc = -EAGAIN);
2600 /* start == NULL means auto trigger paused LFSCK. */
2601 if ((start == NULL) &&
2602 (list_empty(&lfsck->li_list_scan) ||
2603 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AUTO)))
2606 bk = &lfsck->li_bookmark_ram;
2607 thread = &lfsck->li_thread;
2608 mutex_lock(&lfsck->li_mutex);
2609 spin_lock(&lfsck->li_lock);
2610 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
2612 if (unlikely(start == NULL)) {
2613 spin_unlock(&lfsck->li_lock);
2617 while (start->ls_active != 0) {
2618 if (!(type & start->ls_active)) {
2623 com = __lfsck_component_find(lfsck, type,
2624 &lfsck->li_list_scan);
2626 com = __lfsck_component_find(lfsck, type,
2627 &lfsck->li_list_double_scan);
2633 if (com->lc_ops->lfsck_join != NULL) {
2634 rc = com->lc_ops->lfsck_join( env, com, lsp);
2635 if (rc != 0 && rc != -EALREADY)
2638 start->ls_active &= ~type;
2641 spin_unlock(&lfsck->li_lock);
2644 spin_unlock(&lfsck->li_lock);
2646 lfsck->li_status = 0;
2647 lfsck->li_oit_over = 0;
2648 lfsck->li_start_unplug = 0;
2649 lfsck->li_drop_dryrun = 0;
2650 lfsck->li_new_scanned = 0;
2652 /* For auto trigger. */
2656 if (start->ls_flags & LPF_BROADCAST && !lfsck->li_master) {
2657 CERROR("%s: only allow to specify '-A | -o' via MDS\n",
2658 lfsck_lfsck2name(lfsck));
2660 GOTO(out, rc = -EPERM);
2663 start->ls_version = bk->lb_version;
2665 if (start->ls_active != 0) {
2666 struct lfsck_component *next;
2668 if (start->ls_active == LFSCK_TYPES_ALL)
2669 start->ls_active = LFSCK_TYPES_SUPPORTED;
2671 if (start->ls_active & ~LFSCK_TYPES_SUPPORTED) {
2672 start->ls_active &= ~LFSCK_TYPES_SUPPORTED;
2673 GOTO(out, rc = -ENOTSUPP);
2676 list_for_each_entry_safe(com, next,
2677 &lfsck->li_list_scan, lc_link) {
2678 if (!(com->lc_type & start->ls_active)) {
2679 rc = com->lc_ops->lfsck_post(env, com, 0,
2686 while (start->ls_active != 0) {
2687 if (type & start->ls_active) {
2688 com = __lfsck_component_find(lfsck, type,
2689 &lfsck->li_list_idle);
2691 /* The component status will be updated
2692 * when its prep() is called later by
2693 * the LFSCK main engine. */
2694 list_move_tail(&com->lc_link,
2695 &lfsck->li_list_scan);
2696 start->ls_active &= ~type;
2702 if (list_empty(&lfsck->li_list_scan)) {
2703 /* The speed limit will be used to control both the LFSCK and
2704 * low layer scrub (if applied), need to be handled firstly. */
2705 if (start->ls_valid & LSV_SPEED_LIMIT) {
2706 if (__lfsck_set_speed(lfsck, start->ls_speed_limit)) {
2707 rc = lfsck_bookmark_store(env, lfsck);
2716 if (start->ls_flags & LPF_RESET)
2717 flags |= DOIF_RESET;
2719 rc = lfsck_set_param(env, lfsck, start, !!(flags & DOIF_RESET));
2723 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
2724 start->ls_active |= com->lc_type;
2725 if (flags & DOIF_RESET) {
2726 rc = com->lc_ops->lfsck_reset(env, com, false);
2733 lfsck->li_args_dir = LUDA_64BITHASH | LUDA_VERIFY | LUDA_TYPE;
2734 if (bk->lb_param & LPF_DRYRUN)
2735 lfsck->li_args_dir |= LUDA_VERIFY_DRYRUN;
2737 if (start != NULL && start->ls_valid & LSV_ERROR_HANDLE) {
2738 valid |= DOIV_ERROR_HANDLE;
2739 if (start->ls_flags & LPF_FAILOUT)
2740 flags |= DOIF_FAILOUT;
2743 if (start != NULL && start->ls_valid & LSV_DRYRUN) {
2744 valid |= DOIV_DRYRUN;
2745 if (start->ls_flags & LPF_DRYRUN)
2746 flags |= DOIF_DRYRUN;
2749 if (!list_empty(&lfsck->li_list_scan))
2750 flags |= DOIF_OUTUSED;
2752 lfsck->li_args_oit = (flags << DT_OTABLE_IT_FLAGS_SHIFT) | valid;
2753 thread_set_flags(thread, 0);
2754 lta = lfsck_thread_args_init(lfsck, NULL, lsp);
2756 GOTO(out, rc = PTR_ERR(lta));
2758 __lfsck_set_speed(lfsck, bk->lb_speed_limit);
2759 task = kthread_run(lfsck_master_engine, lta, "lfsck");
2762 CERROR("%s: cannot start LFSCK thread: rc = %d\n",
2763 lfsck_lfsck2name(lfsck), rc);
2764 lfsck_thread_args_fini(lta);
2769 l_wait_event(thread->t_ctl_waitq,
2770 thread_is_running(thread) ||
2771 thread_is_stopped(thread),
2773 if (start == NULL || !(start->ls_flags & LPF_BROADCAST)) {
2774 lfsck->li_start_unplug = 1;
2775 wake_up_all(&thread->t_ctl_waitq);
2780 /* release lfsck::li_mutex to avoid deadlock. */
2781 mutex_unlock(&lfsck->li_mutex);
2782 rc = lfsck_start_all(env, lfsck, start);
2784 spin_lock(&lfsck->li_lock);
2785 if (thread_is_stopped(thread)) {
2786 spin_unlock(&lfsck->li_lock);
2788 lfsck->li_status = LS_FAILED;
2789 lfsck->li_flags = 0;
2790 thread_set_flags(thread, SVC_STOPPING);
2791 spin_unlock(&lfsck->li_lock);
2793 lfsck->li_start_unplug = 1;
2794 wake_up_all(&thread->t_ctl_waitq);
2795 l_wait_event(thread->t_ctl_waitq,
2796 thread_is_stopped(thread),
2800 lfsck->li_start_unplug = 1;
2801 wake_up_all(&thread->t_ctl_waitq);
2807 mutex_unlock(&lfsck->li_mutex);
2810 lfsck_instance_put(env, lfsck);
2812 return rc < 0 ? rc : 0;
2814 EXPORT_SYMBOL(lfsck_start);
2816 int lfsck_stop(const struct lu_env *env, struct dt_device *key,
2817 struct lfsck_stop *stop)
2819 struct lfsck_instance *lfsck;
2820 struct ptlrpc_thread *thread;
2821 struct l_wait_info lwi = { 0 };
2826 lfsck = lfsck_instance_find(key, true, false);
2827 if (unlikely(lfsck == NULL))
2830 thread = &lfsck->li_thread;
2831 /* release lfsck::li_mutex to avoid deadlock. */
2832 if (stop != NULL && stop->ls_flags & LPF_BROADCAST) {
2833 if (!lfsck->li_master) {
2834 CERROR("%s: only allow to specify '-A' via MDS\n",
2835 lfsck_lfsck2name(lfsck));
2837 GOTO(out, rc = -EPERM);
2840 rc1 = lfsck_stop_all(env, lfsck, stop);
2843 mutex_lock(&lfsck->li_mutex);
2844 spin_lock(&lfsck->li_lock);
2845 /* no error if LFSCK is already stopped, or was never started */
2846 if (thread_is_init(thread) || thread_is_stopped(thread)) {
2847 spin_unlock(&lfsck->li_lock);
2852 lfsck->li_status = stop->ls_status;
2853 lfsck->li_flags = stop->ls_flags;
2855 lfsck->li_status = LS_STOPPED;
2856 lfsck->li_flags = 0;
2859 thread_set_flags(thread, SVC_STOPPING);
2860 spin_unlock(&lfsck->li_lock);
2862 wake_up_all(&thread->t_ctl_waitq);
2863 l_wait_event(thread->t_ctl_waitq,
2864 thread_is_stopped(thread),
2870 mutex_unlock(&lfsck->li_mutex);
2871 lfsck_instance_put(env, lfsck);
2873 return rc != 0 ? rc : rc1;
2875 EXPORT_SYMBOL(lfsck_stop);
2877 int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
2878 struct lfsck_request *lr)
2880 int rc = -EOPNOTSUPP;
2883 switch (lr->lr_event) {
2885 struct lfsck_start *start = &lfsck_env_info(env)->lti_start;
2886 struct lfsck_start_param lsp;
2888 memset(start, 0, sizeof(*start));
2889 start->ls_valid = lr->lr_valid;
2890 start->ls_speed_limit = lr->lr_speed;
2891 start->ls_version = lr->lr_version;
2892 start->ls_active = lr->lr_active;
2893 start->ls_flags = lr->lr_param & ~LPF_BROADCAST;
2894 start->ls_async_windows = lr->lr_async_windows;
2896 lsp.lsp_start = start;
2897 lsp.lsp_index = lr->lr_index;
2898 lsp.lsp_index_valid = 1;
2899 rc = lfsck_start(env, key, &lsp);
2903 struct lfsck_stop *stop = &lfsck_env_info(env)->lti_stop;
2905 memset(stop, 0, sizeof(*stop));
2906 stop->ls_status = lr->lr_status;
2907 stop->ls_flags = lr->lr_param & ~LPF_BROADCAST;
2908 rc = lfsck_stop(env, key, stop);
2911 case LE_PHASE1_DONE:
2912 case LE_PHASE2_DONE:
2913 case LE_FID_ACCESSED:
2915 case LE_CONDITIONAL_DESTROY:
2916 case LE_PAIRS_VERIFY: {
2917 struct lfsck_instance *lfsck;
2918 struct lfsck_component *com;
2920 lfsck = lfsck_instance_find(key, true, false);
2921 if (unlikely(lfsck == NULL))
2924 com = lfsck_component_find(lfsck, lr->lr_active);
2925 if (likely(com != NULL)) {
2926 rc = com->lc_ops->lfsck_in_notify(env, com, lr);
2927 lfsck_component_put(env, com);
2930 lfsck_instance_put(env, lfsck);
2939 EXPORT_SYMBOL(lfsck_in_notify);
2941 int lfsck_query(const struct lu_env *env, struct dt_device *key,
2942 struct lfsck_request *lr)
2944 struct lfsck_instance *lfsck;
2945 struct lfsck_component *com;
2949 lfsck = lfsck_instance_find(key, true, false);
2950 if (unlikely(lfsck == NULL))
2953 com = lfsck_component_find(lfsck, lr->lr_active);
2954 if (likely(com != NULL)) {
2955 rc = com->lc_ops->lfsck_query(env, com);
2956 lfsck_component_put(env, com);
2961 lfsck_instance_put(env, lfsck);
2965 EXPORT_SYMBOL(lfsck_query);
2967 int lfsck_register_namespace(const struct lu_env *env, struct dt_device *key,
2968 struct ldlm_namespace *ns)
2970 struct lfsck_instance *lfsck;
2973 lfsck = lfsck_instance_find(key, true, false);
2974 if (likely(lfsck != NULL)) {
2975 lfsck->li_namespace = ns;
2976 lfsck_instance_put(env, lfsck);
2982 EXPORT_SYMBOL(lfsck_register_namespace);
2984 int lfsck_register(const struct lu_env *env, struct dt_device *key,
2985 struct dt_device *next, struct obd_device *obd,
2986 lfsck_out_notify notify, void *notify_data, bool master)
2988 struct lfsck_instance *lfsck;
2989 struct dt_object *root = NULL;
2990 struct dt_object *obj = NULL;
2991 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
2995 lfsck = lfsck_instance_find(key, false, false);
2996 if (unlikely(lfsck != NULL))
2999 OBD_ALLOC_PTR(lfsck);
3003 mutex_init(&lfsck->li_mutex);
3004 spin_lock_init(&lfsck->li_lock);
3005 INIT_LIST_HEAD(&lfsck->li_link);
3006 INIT_LIST_HEAD(&lfsck->li_list_scan);
3007 INIT_LIST_HEAD(&lfsck->li_list_dir);
3008 INIT_LIST_HEAD(&lfsck->li_list_double_scan);
3009 INIT_LIST_HEAD(&lfsck->li_list_idle);
3010 atomic_set(&lfsck->li_ref, 1);
3011 atomic_set(&lfsck->li_double_scan_count, 0);
3012 init_waitqueue_head(&lfsck->li_thread.t_ctl_waitq);
3013 lfsck->li_out_notify = notify;
3014 lfsck->li_out_notify_data = notify_data;
3015 lfsck->li_next = next;
3016 lfsck->li_bottom = key;
3017 lfsck->li_obd = obd;
3019 rc = lfsck_tgt_descs_init(&lfsck->li_ost_descs);
3023 rc = lfsck_tgt_descs_init(&lfsck->li_mdt_descs);
3027 fid->f_seq = FID_SEQ_LOCAL_NAME;
3030 rc = local_oid_storage_init(env, key, fid, &lfsck->li_los);
3034 rc = dt_root_get(env, key, fid);
3038 root = dt_locate(env, key, fid);
3040 GOTO(out, rc = PTR_ERR(root));
3042 if (unlikely(!dt_try_as_dir(env, root)))
3043 GOTO(out, rc = -ENOTDIR);
3045 lfsck->li_local_root_fid = *fid;
3047 lfsck->li_master = 1;
3048 if (lfsck_dev_idx(key) == 0) {
3049 struct lu_fid *pfid = &lfsck_env_info(env)->lti_fid2;
3050 const struct lu_name *cname;
3052 rc = dt_lookup(env, root,
3053 (struct dt_rec *)(&lfsck->li_global_root_fid),
3054 (const struct dt_key *)"ROOT", BYPASS_CAPA);
3058 obj = dt_locate(env, key, &lfsck->li_global_root_fid);
3060 GOTO(out, rc = PTR_ERR(obj));
3062 rc = dt_lookup(env, obj, (struct dt_rec *)fid,
3063 (const struct dt_key *)dotlustre, BYPASS_CAPA);
3067 lu_object_put(env, &obj->do_lu);
3068 obj = dt_locate(env, key, fid);
3070 GOTO(out, rc = PTR_ERR(obj));
3072 cname = lfsck_name_get_const(env, dotlustre,
3074 rc = lfsck_verify_linkea(env, key, obj, cname,
3075 &lfsck->li_global_root_fid);
3080 rc = dt_lookup(env, obj, (struct dt_rec *)fid,
3081 (const struct dt_key *)lostfound,
3086 lu_object_put(env, &obj->do_lu);
3087 obj = dt_locate(env, key, fid);
3089 GOTO(out, rc = PTR_ERR(obj));
3091 cname = lfsck_name_get_const(env, lostfound,
3093 rc = lfsck_verify_linkea(env, key, obj, cname, pfid);
3097 lu_object_put(env, &obj->do_lu);
3102 fid->f_seq = FID_SEQ_LOCAL_FILE;
3103 fid->f_oid = OTABLE_IT_OID;
3105 obj = dt_locate(env, key, fid);
3107 GOTO(out, rc = PTR_ERR(obj));
3109 lu_object_get(&obj->do_lu);
3110 lfsck->li_obj_oit = obj;
3111 rc = obj->do_ops->do_index_try(env, obj, &dt_otable_features);
3115 rc = lfsck_bookmark_setup(env, lfsck);
3120 rc = lfsck_fid_init(lfsck);
3124 rc = lfsck_namespace_setup(env, lfsck);
3129 rc = lfsck_layout_setup(env, lfsck);
3133 /* XXX: more LFSCK components initialization to be added here. */
3135 rc = lfsck_instance_add(lfsck);
3137 rc = lfsck_add_target_from_orphan(env, lfsck);
3139 if (obj != NULL && !IS_ERR(obj))
3140 lu_object_put(env, &obj->do_lu);
3141 if (root != NULL && !IS_ERR(root))
3142 lu_object_put(env, &root->do_lu);
3144 lfsck_instance_cleanup(env, lfsck);
3147 EXPORT_SYMBOL(lfsck_register);
3149 void lfsck_degister(const struct lu_env *env, struct dt_device *key)
3151 struct lfsck_instance *lfsck;
3153 lfsck = lfsck_instance_find(key, false, true);
3155 lfsck_instance_put(env, lfsck);
3157 EXPORT_SYMBOL(lfsck_degister);
3159 int lfsck_add_target(const struct lu_env *env, struct dt_device *key,
3160 struct dt_device *tgt, struct obd_export *exp,
3161 __u32 index, bool for_ost)
3163 struct lfsck_instance *lfsck;
3164 struct lfsck_tgt_desc *ltd;
3175 INIT_LIST_HEAD(<d->ltd_orphan_list);
3176 INIT_LIST_HEAD(<d->ltd_layout_list);
3177 INIT_LIST_HEAD(<d->ltd_layout_phase_list);
3178 INIT_LIST_HEAD(<d->ltd_namespace_list);
3179 INIT_LIST_HEAD(<d->ltd_namespace_phase_list);
3180 atomic_set(<d->ltd_ref, 1);
3181 ltd->ltd_index = index;
3183 spin_lock(&lfsck_instance_lock);
3184 lfsck = __lfsck_instance_find(key, true, false);
3185 if (lfsck == NULL) {
3187 list_add_tail(<d->ltd_orphan_list,
3188 &lfsck_ost_orphan_list);
3190 list_add_tail(<d->ltd_orphan_list,
3191 &lfsck_mdt_orphan_list);
3192 spin_unlock(&lfsck_instance_lock);
3196 spin_unlock(&lfsck_instance_lock);
3198 rc = __lfsck_add_target(env, lfsck, ltd, for_ost, false);
3202 lfsck_instance_put(env, lfsck);
3206 EXPORT_SYMBOL(lfsck_add_target);
3208 void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
3209 struct dt_device *tgt, __u32 index, bool for_ost)
3211 struct lfsck_instance *lfsck;
3212 struct lfsck_tgt_descs *ltds;
3213 struct lfsck_tgt_desc *ltd;
3214 struct list_head *head;
3217 head = &lfsck_ost_orphan_list;
3219 head = &lfsck_mdt_orphan_list;
3221 spin_lock(&lfsck_instance_lock);
3222 list_for_each_entry(ltd, head, ltd_orphan_list) {
3223 if (ltd->ltd_tgt == tgt) {
3224 list_del_init(<d->ltd_orphan_list);
3225 spin_unlock(&lfsck_instance_lock);
3233 lfsck = __lfsck_instance_find(key, true, false);
3234 spin_unlock(&lfsck_instance_lock);
3235 if (unlikely(lfsck == NULL))
3239 ltds = &lfsck->li_ost_descs;
3241 ltds = &lfsck->li_mdt_descs;
3243 down_write(<ds->ltd_rw_sem);
3244 LASSERT(ltds->ltd_tgts_bitmap != NULL);
3246 if (unlikely(index >= ltds->ltd_tgts_bitmap->size))
3249 ltd = LTD_TGT(ltds, index);
3250 if (unlikely(ltd == NULL))
3253 LASSERT(ltds->ltd_tgtnr > 0);
3256 cfs_bitmap_clear(ltds->ltd_tgts_bitmap, index);
3257 LTD_TGT(ltds, index) = NULL;
3262 head = &lfsck->li_ost_descs.ltd_orphan;
3264 head = &lfsck->li_mdt_descs.ltd_orphan;
3266 list_for_each_entry(ltd, head, ltd_orphan_list) {
3267 if (ltd->ltd_tgt == tgt) {
3268 list_del_init(<d->ltd_orphan_list);
3274 up_write(<ds->ltd_rw_sem);
3276 spin_lock(<ds->ltd_lock);
3278 spin_unlock(<ds->ltd_lock);
3279 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_NAMESPACE);
3280 lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_LAYOUT);
3284 lfsck_instance_put(env, lfsck);
3286 EXPORT_SYMBOL(lfsck_del_target);
3288 static int __init lfsck_init(void)
3292 INIT_LIST_HEAD(&lfsck_instance_list);
3293 INIT_LIST_HEAD(&lfsck_ost_orphan_list);
3294 INIT_LIST_HEAD(&lfsck_mdt_orphan_list);
3295 lfsck_key_init_generic(&lfsck_thread_key, NULL);
3296 rc = lu_context_key_register(&lfsck_thread_key);
3298 tgt_register_lfsck_in_notify(lfsck_in_notify);
3299 tgt_register_lfsck_query(lfsck_query);
3305 static void __exit lfsck_exit(void)
3307 struct lfsck_tgt_desc *ltd;
3308 struct lfsck_tgt_desc *next;
3310 LASSERT(list_empty(&lfsck_instance_list));
3312 list_for_each_entry_safe(ltd, next, &lfsck_ost_orphan_list,
3314 list_del_init(<d->ltd_orphan_list);
3318 list_for_each_entry_safe(ltd, next, &lfsck_mdt_orphan_list,
3320 list_del_init(<d->ltd_orphan_list);
3324 lu_context_key_degister(&lfsck_thread_key);
3327 MODULE_AUTHOR("Intel Corporation <http://www.intel.com/>");
3328 MODULE_DESCRIPTION("LFSCK");
3329 MODULE_LICENSE("GPL");
3331 cfs_module(lfsck, LUSTRE_VERSION_STRING, lfsck_init, lfsck_exit);