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_engine.c
28 * Author: Fan, Yong <fan.yong@intel.com>
31 #define DEBUG_SUBSYSTEM S_LFSCK
33 #include <lu_object.h>
34 #include <dt_object.h>
35 #include <lustre_net.h>
36 #include <lustre_fid.h>
37 #include <obd_support.h>
38 #include <lustre_lib.h>
40 #include "lfsck_internal.h"
42 static int lfsck_unpack_ent(struct lu_dirent *ent, __u64 *cookie, __u16 *type)
45 int align = sizeof(*lt) - 1;
48 fid_le_to_cpu(&ent->lde_fid, &ent->lde_fid);
49 *cookie = le64_to_cpu(ent->lde_hash);
50 ent->lde_reclen = le16_to_cpu(ent->lde_reclen);
51 ent->lde_namelen = le16_to_cpu(ent->lde_namelen);
52 ent->lde_attrs = le32_to_cpu(ent->lde_attrs);
54 if (unlikely(!(ent->lde_attrs & LUDA_TYPE)))
57 len = (ent->lde_namelen + align) & ~align;
58 lt = (struct luda_type *)(ent->lde_name + len);
59 *type = le16_to_cpu(lt->lt_type);
61 /* Make sure the name is terminated with '\0'. The data (object type)
62 * after ent::lde_name maybe broken, but we have stored such data in
63 * the output parameter @type as above. */
64 ent->lde_name[ent->lde_namelen] = '\0';
69 static void lfsck_di_oit_put(const struct lu_env *env, struct lfsck_instance *lfsck)
71 const struct dt_it_ops *iops;
74 spin_lock(&lfsck->li_lock);
75 iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
76 di = lfsck->li_di_oit;
77 lfsck->li_di_oit = NULL;
78 spin_unlock(&lfsck->li_lock);
82 static void lfsck_di_dir_put(const struct lu_env *env, struct lfsck_instance *lfsck)
84 const struct dt_it_ops *iops;
87 spin_lock(&lfsck->li_lock);
88 iops = &lfsck->li_obj_dir->do_index_ops->dio_it;
89 di = lfsck->li_di_dir;
90 lfsck->li_di_dir = NULL;
91 lfsck->li_cookie_dir = 0;
92 spin_unlock(&lfsck->li_lock);
96 static void lfsck_close_dir(const struct lu_env *env,
97 struct lfsck_instance *lfsck)
99 struct dt_object *dir_obj = lfsck->li_obj_dir;
100 const struct dt_it_ops *dir_iops = &dir_obj->do_index_ops->dio_it;
101 struct dt_it *dir_di = lfsck->li_di_dir;
103 lfsck_di_dir_put(env, lfsck);
104 dir_iops->fini(env, dir_di);
105 lfsck->li_obj_dir = NULL;
106 lfsck_object_put(env, dir_obj);
109 static int lfsck_update_lma(const struct lu_env *env,
110 struct lfsck_instance *lfsck, struct dt_object *obj)
112 struct lfsck_thread_info *info = lfsck_env_info(env);
113 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
114 struct dt_device *dt = lfsck->li_bottom;
115 struct lustre_mdt_attrs *lma = &info->lti_lma;
122 if (bk->lb_param & LPF_DRYRUN)
125 buf = lfsck_buf_get(env, info->lti_lma_old, LMA_OLD_SIZE);
126 rc = dt_xattr_get(env, obj, buf, XATTR_NAME_LMA, BYPASS_CAPA);
131 fl = LU_XATTR_CREATE;
132 lustre_lma_init(lma, lfsck_dto2fid(obj), LMAC_FID_ON_OST, 0);
134 if (rc != LMA_OLD_SIZE && rc != sizeof(struct lustre_mdt_attrs))
137 fl = LU_XATTR_REPLACE;
138 lustre_lma_swab(lma);
139 lustre_lma_init(lma, lfsck_dto2fid(obj),
140 lma->lma_compat | LMAC_FID_ON_OST,
143 lustre_lma_swab(lma);
145 th = dt_trans_create(env, dt);
149 buf = lfsck_buf_get(env, lma, sizeof(*lma));
150 rc = dt_declare_xattr_set(env, obj, buf, XATTR_NAME_LMA, fl, th);
154 rc = dt_trans_start(env, dt, th);
158 rc = dt_xattr_set(env, obj, buf, XATTR_NAME_LMA, fl, th, BYPASS_CAPA);
163 dt_trans_stop(env, dt, th);
167 static int lfsck_parent_fid(const struct lu_env *env, struct dt_object *obj,
170 if (unlikely(!S_ISDIR(lfsck_object_type(obj)) ||
171 !dt_try_as_dir(env, obj)))
174 return dt_lookup(env, obj, (struct dt_rec *)fid,
175 (const struct dt_key *)"..", BYPASS_CAPA);
179 * Check whether needs to scan the directory or not.
181 * 1) If we are not doing namespace LFSCK, or the given @obj is not directory,
182 * then needs not to scan the @obj. Otherwise,
183 * 2) Global /ROOT needs to be scanned, backend root needs not to be scanned.
184 * 3) If the @obj is neither IGIF nor normal FID (including .lustre and its
185 * sub-directories that have been scanned when the LFSCK engine start),
186 * then needs not to be scanned.
187 * 4) If it is a remote object, then scanning the object will be done on the
188 * MDT on which the object really resides.
189 * 5) If the local object has normal FID, then needs to be scanned. Otherwise,
190 * 6) If the object has linkEA, then needs to be scanned. Otherwise,
191 * 7) If none of the previous conditions are true, we need to check the parent
192 * directories whether this subdirectory is in a tree that should be scanned.
193 * Set the parent as current @obj, repeat 2)-7).
195 * \param[in] env pointer to the thread context
196 * \param[in] lfsck pointer to the lfsck instance
197 * \param[in] obj pointer to the object to be checked
199 * \retval positive number if the directory needs to be scanned
200 * \retval 0 if the directory needs NOT to be scanned
201 * \retval negative error number on failure
203 static int lfsck_needs_scan_dir(const struct lu_env *env,
204 struct lfsck_instance *lfsck,
205 struct dt_object *obj)
207 struct lfsck_thread_info *info = lfsck_env_info(env);
208 struct lu_fid *fid = &info->lti_fid;
209 struct lu_seq_range *range = &info->lti_range;
210 struct dt_device *dev = lfsck->li_bottom;
211 struct seq_server_site *ss = lu_site2seq(dev->dd_lu_dev.ld_site);
212 __u32 idx = lfsck_dev_idx(dev);
216 if (list_empty(&lfsck->li_list_dir) || !S_ISDIR(lfsck_object_type(obj)))
221 *fid = *lfsck_dto2fid(obj);
223 /* Global /ROOT is visible. */
224 if (unlikely(lu_fid_eq(fid, &lfsck->li_global_root_fid)))
227 /* Backend root is invisible. */
228 if (unlikely(lu_fid_eq(fid, &lfsck->li_local_root_fid)))
231 if (!fid_is_norm(fid) && !fid_is_igif(fid))
234 fld_range_set_mdt(range);
235 rc = fld_local_lookup(env, ss->ss_server_fld,
236 fid_seq(fid), range);
237 if (rc != 0 || range->lsr_index != idx) {
238 /* Current FID should NOT be for the input parameter
239 * @obj, because the lfsck_master_oit_engine() has
240 * filtered out agent object. So current FID is for
241 * the ancestor of the original input parameter @obj.
242 * So he ancestor is a remote directory. The input
243 * parameter @obj is local directory, and should be
244 * scanned under such case. */
250 /* normal FID on this target (locally) must be for the
251 * client-side visiable object. */
252 if (fid_is_norm(fid))
256 obj = lfsck_object_find(env, lfsck, fid);
261 if (!dt_object_exists(obj))
265 dt_read_lock(env, obj, MOR_TGT_CHILD);
266 if (unlikely(lfsck_is_dead_obj(obj))) {
267 dt_read_unlock(env, obj);
272 rc = dt_xattr_get(env, obj,
273 lfsck_buf_get(env, NULL, 0), XATTR_NAME_LINK,
275 dt_read_unlock(env, obj);
279 if (rc < 0 && rc != -ENODATA)
282 rc = lfsck_parent_fid(env, obj, fid);
284 lfsck_object_put(env, obj);
290 if (!fid_is_sane(fid))
295 if (depth > 0 && obj != NULL)
296 lfsck_object_put(env, obj);
301 /* LFSCK wrap functions */
303 static void lfsck_fail(const struct lu_env *env, struct lfsck_instance *lfsck,
306 struct lfsck_component *com;
308 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
309 com->lc_ops->lfsck_fail(env, com, new_checked);
313 static int lfsck_checkpoint(const struct lu_env *env,
314 struct lfsck_instance *lfsck)
316 struct lfsck_component *com;
320 if (likely(cfs_time_beforeq(cfs_time_current(),
321 lfsck->li_time_next_checkpoint)))
324 lfsck_pos_fill(env, lfsck, &lfsck->li_pos_checkpoint, false);
325 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
326 rc = com->lc_ops->lfsck_checkpoint(env, com, false);
331 lfsck->li_time_last_checkpoint = cfs_time_current();
332 lfsck->li_time_next_checkpoint = lfsck->li_time_last_checkpoint +
333 cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
334 return rc1 != 0 ? rc1 : rc;
337 static int lfsck_prep(const struct lu_env *env, struct lfsck_instance *lfsck,
338 struct lfsck_start_param *lsp)
340 struct dt_object *obj = NULL;
341 struct lfsck_component *com;
342 struct lfsck_component *next;
343 struct lfsck_position *pos = NULL;
344 const struct dt_it_ops *iops =
345 &lfsck->li_obj_oit->do_index_ops->dio_it;
350 LASSERT(lfsck->li_obj_dir == NULL);
351 LASSERT(lfsck->li_di_dir == NULL);
353 lfsck->li_current_oit_processed = 0;
354 list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
355 com->lc_new_checked = 0;
356 rc = com->lc_ops->lfsck_prep(env, com, lsp);
361 (!lfsck_pos_is_zero(&com->lc_pos_start) &&
362 lfsck_pos_is_eq(pos, &com->lc_pos_start) > 0))
363 pos = &com->lc_pos_start;
366 /* Init otable-based iterator. */
368 rc = iops->load(env, lfsck->li_di_oit, 0);
370 lfsck->li_oit_over = 1;
377 rc = iops->load(env, lfsck->li_di_oit, pos->lp_oit_cookie);
381 lfsck->li_oit_over = 1;
383 if (!lfsck->li_master || fid_is_zero(&pos->lp_dir_parent))
386 /* Find the directory for namespace-based traverse. */
387 obj = lfsck_object_find(env, lfsck, &pos->lp_dir_parent);
389 RETURN(PTR_ERR(obj));
391 /* Remote directory will be scanned by the LFSCK instance
392 * on the MDT where the remote object really resides on. */
393 if (!dt_object_exists(obj) || dt_object_remote(obj) ||
394 unlikely(!S_ISDIR(lfsck_object_type(obj))))
397 if (unlikely(!dt_try_as_dir(env, obj)))
398 GOTO(out, rc = -ENOTDIR);
400 /* Init the namespace-based directory traverse. */
401 iops = &obj->do_index_ops->dio_it;
402 di = iops->init(env, obj, lfsck->li_args_dir, BYPASS_CAPA);
404 GOTO(out, rc = PTR_ERR(di));
406 LASSERT(pos->lp_dir_cookie < MDS_DIR_END_OFF);
408 rc = iops->load(env, di, pos->lp_dir_cookie);
409 if ((rc == 0) || (rc > 0 && pos->lp_dir_cookie > 0))
410 rc = iops->next(env, di);
420 lfsck->li_obj_dir = lfsck_object_get(obj);
421 lfsck->li_cookie_dir = iops->store(env, di);
422 spin_lock(&lfsck->li_lock);
423 lfsck->li_di_dir = di;
424 spin_unlock(&lfsck->li_lock);
430 lfsck_object_put(env, obj);
433 list_for_each_entry_safe(com, next, &lfsck->li_list_scan,
435 com->lc_ops->lfsck_post(env, com, rc, true);
441 lfsck_pos_fill(env, lfsck, &lfsck->li_pos_checkpoint, true);
442 lfsck->li_pos_current = lfsck->li_pos_checkpoint;
443 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
444 rc = com->lc_ops->lfsck_checkpoint(env, com, true);
449 lfsck->li_time_last_checkpoint = cfs_time_current();
450 lfsck->li_time_next_checkpoint = lfsck->li_time_last_checkpoint +
451 cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
455 static int lfsck_exec_oit(const struct lu_env *env,
456 struct lfsck_instance *lfsck, struct dt_object *obj)
458 struct lfsck_component *com;
459 const struct dt_it_ops *iops;
464 LASSERT(lfsck->li_obj_dir == NULL);
466 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
467 rc = com->lc_ops->lfsck_exec_oit(env, com, obj);
472 rc = lfsck_needs_scan_dir(env, lfsck, obj);
476 if (unlikely(!dt_try_as_dir(env, obj)))
477 GOTO(out, rc = -ENOTDIR);
479 iops = &obj->do_index_ops->dio_it;
480 di = iops->init(env, obj, lfsck->li_args_dir, BYPASS_CAPA);
482 GOTO(out, rc = PTR_ERR(di));
484 rc = iops->load(env, di, 0);
486 rc = iops->next(env, di);
496 lfsck->li_obj_dir = lfsck_object_get(obj);
497 lfsck->li_cookie_dir = iops->store(env, di);
498 spin_lock(&lfsck->li_lock);
499 lfsck->li_di_dir = di;
500 spin_unlock(&lfsck->li_lock);
506 lfsck_fail(env, lfsck, false);
507 return (rc > 0 ? 0 : rc);
510 static int lfsck_exec_dir(const struct lu_env *env,
511 struct lfsck_instance *lfsck,
512 struct lu_dirent *ent, __u16 type)
514 struct lfsck_component *com;
517 list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
518 rc = com->lc_ops->lfsck_exec_dir(env, com, ent, type);
525 static int lfsck_post(const struct lu_env *env, struct lfsck_instance *lfsck,
528 struct lfsck_component *com;
529 struct lfsck_component *next;
533 lfsck_pos_fill(env, lfsck, &lfsck->li_pos_checkpoint, false);
534 list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
535 rc = com->lc_ops->lfsck_post(env, com, result, false);
540 lfsck->li_time_last_checkpoint = cfs_time_current();
541 lfsck->li_time_next_checkpoint = lfsck->li_time_last_checkpoint +
542 cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
544 /* Ignore some component post failure to make other can go ahead. */
548 static int lfsck_double_scan(const struct lu_env *env,
549 struct lfsck_instance *lfsck)
551 struct lfsck_component *com;
552 struct lfsck_component *next;
553 struct l_wait_info lwi = { 0 };
557 list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
558 rc = com->lc_ops->lfsck_double_scan(env, com);
563 l_wait_event(lfsck->li_thread.t_ctl_waitq,
564 atomic_read(&lfsck->li_double_scan_count) == 0,
567 if (lfsck->li_status != LS_PAUSED &&
568 lfsck->li_status != LS_CO_PAUSED) {
569 list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
571 spin_lock(&lfsck->li_lock);
572 list_move_tail(&com->lc_link, &lfsck->li_list_idle);
573 spin_unlock(&lfsck->li_lock);
577 return rc1 != 0 ? rc1 : rc;
580 static void lfsck_quit(const struct lu_env *env, struct lfsck_instance *lfsck)
582 struct lfsck_component *com;
583 struct lfsck_component *next;
585 list_for_each_entry_safe(com, next, &lfsck->li_list_scan,
587 if (com->lc_ops->lfsck_quit != NULL)
588 com->lc_ops->lfsck_quit(env, com);
590 spin_lock(&lfsck->li_lock);
591 list_del_init(&com->lc_link_dir);
592 list_move_tail(&com->lc_link, &lfsck->li_list_idle);
593 spin_unlock(&lfsck->li_lock);
596 list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
598 if (com->lc_ops->lfsck_quit != NULL)
599 com->lc_ops->lfsck_quit(env, com);
601 spin_lock(&lfsck->li_lock);
602 list_move_tail(&com->lc_link, &lfsck->li_list_idle);
603 spin_unlock(&lfsck->li_lock);
609 static int lfsck_master_dir_engine(const struct lu_env *env,
610 struct lfsck_instance *lfsck)
612 struct lfsck_thread_info *info = lfsck_env_info(env);
613 struct dt_object *dir = lfsck->li_obj_dir;
614 const struct dt_it_ops *iops = &dir->do_index_ops->dio_it;
615 struct dt_it *di = lfsck->li_di_dir;
616 struct lu_dirent *ent =
617 (struct lu_dirent *)info->lti_key;
618 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
619 struct ptlrpc_thread *thread = &lfsck->li_thread;
625 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DELAY2) &&
627 struct l_wait_info lwi;
629 lwi = LWI_TIMEOUT(cfs_time_seconds(cfs_fail_val),
631 l_wait_event(thread->t_ctl_waitq,
632 !thread_is_running(thread),
635 if (unlikely(!thread_is_running(thread))) {
636 CDEBUG(D_LFSCK, "%s: scan dir exit for engine "
637 "stop, parent "DFID", cookie "LPX64"\n",
638 lfsck_lfsck2name(lfsck),
639 PFID(lfsck_dto2fid(dir)),
640 lfsck->li_cookie_dir);
645 lfsck->li_new_scanned++;
646 rc = iops->rec(env, di, (struct dt_rec *)ent,
649 rc = lfsck_unpack_ent(ent, &lfsck->li_cookie_dir,
653 CDEBUG(D_LFSCK, "%s: scan dir failed at rec(), "
654 "parent "DFID", cookie "LPX64": rc = %d\n",
655 lfsck_lfsck2name(lfsck),
656 PFID(lfsck_dto2fid(dir)),
657 lfsck->li_cookie_dir, rc);
658 lfsck_fail(env, lfsck, true);
659 if (bk->lb_param & LPF_FAILOUT)
665 if (ent->lde_attrs & LUDA_IGNORE)
668 /* The type in the @ent structure may has been overwritten,
669 * so we need to pass the @type parameter independently. */
670 rc = lfsck_exec_dir(env, lfsck, ent, type);
671 if (rc != 0 && bk->lb_param & LPF_FAILOUT)
675 rc = lfsck_checkpoint(env, lfsck);
676 if (rc != 0 && bk->lb_param & LPF_FAILOUT)
680 lfsck_control_speed(lfsck);
681 if (unlikely(!thread_is_running(thread))) {
682 CDEBUG(D_LFSCK, "%s: scan dir exit for engine stop, "
683 "parent "DFID", cookie "LPX64"\n",
684 lfsck_lfsck2name(lfsck),
685 PFID(lfsck_dto2fid(dir)),
686 lfsck->li_cookie_dir);
690 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_FATAL2)) {
691 spin_lock(&lfsck->li_lock);
692 thread_set_flags(thread, SVC_STOPPING);
693 spin_unlock(&lfsck->li_lock);
697 rc = iops->next(env, di);
700 if (rc > 0 && !lfsck->li_oit_over)
701 lfsck_close_dir(env, lfsck);
707 * Object-table based iteration engine.
709 * Object-table based iteration is the basic linear engine to scan all the
710 * objects on current device in turn. For each object, it calls all the
711 * registered LFSCK component(s)' API to perform related consistency
714 * It flushes related LFSCK tracing files to disk via making checkpoint
715 * periodically. Then if the server crashed or the LFSCK is paused, the
716 * LFSCK can resume from the latest checkpoint.
718 * It also controls the whole LFSCK speed via lfsck_control_speed() to
719 * avoid the server to become overload.
721 * \param[in] env pointer to the thread context
722 * \param[in] lfsck pointer to the lfsck instance
724 * \retval positive number if all objects have been scanned
725 * \retval 0 if the iteration is stopped or paused
726 * \retval negative error number on failure
728 static int lfsck_master_oit_engine(const struct lu_env *env,
729 struct lfsck_instance *lfsck)
731 struct lfsck_thread_info *info = lfsck_env_info(env);
732 const struct dt_it_ops *iops =
733 &lfsck->li_obj_oit->do_index_ops->dio_it;
734 struct dt_it *di = lfsck->li_di_oit;
735 struct lu_fid *fid = &info->lti_fid;
736 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
737 struct ptlrpc_thread *thread = &lfsck->li_thread;
738 struct dt_device *dev = lfsck->li_bottom;
739 struct seq_server_site *ss = lu_site2seq(dev->dd_lu_dev.ld_site);
740 __u32 idx = lfsck_dev_idx(dev);
744 if (unlikely(ss == NULL))
748 struct dt_object *target;
749 bool update_lma = false;
751 if (lfsck->li_di_dir != NULL) {
752 rc = lfsck_master_dir_engine(env, lfsck);
757 if (unlikely(lfsck->li_oit_over))
760 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DELAY1) &&
762 struct l_wait_info lwi;
764 lwi = LWI_TIMEOUT(cfs_time_seconds(cfs_fail_val),
766 l_wait_event(thread->t_ctl_waitq,
767 !thread_is_running(thread),
770 if (unlikely(!thread_is_running(thread))) {
771 CDEBUG(D_LFSCK, "%s: OIT scan exit for engine "
772 "stop, cookie "LPU64"\n",
773 lfsck_lfsck2name(lfsck),
774 iops->store(env, di));
779 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_CRASH))
782 lfsck->li_current_oit_processed = 1;
783 lfsck->li_new_scanned++;
784 lfsck->li_pos_current.lp_oit_cookie = iops->store(env, di);
785 rc = iops->rec(env, di, (struct dt_rec *)fid, 0);
787 CDEBUG(D_LFSCK, "%s: OIT scan failed at rec(): "
788 "rc = %d\n", lfsck_lfsck2name(lfsck), rc);
789 lfsck_fail(env, lfsck, true);
790 if (rc < 0 && bk->lb_param & LPF_FAILOUT)
796 if (fid_is_idif(fid)) {
797 __u32 idx1 = fid_idif_ost_idx(fid);
799 LASSERT(!lfsck->li_master);
801 /* It is an old format device, update the LMA. */
803 struct ost_id *oi = &info->lti_oi;
805 fid_to_ostid(fid, oi);
806 ostid_to_fid(fid, oi, idx);
809 } else if (!fid_is_norm(fid) && !fid_is_igif(fid) &&
810 !fid_is_last_id(fid) &&
811 !lu_fid_eq(fid, &lfsck->li_global_root_fid)) {
813 /* If the FID/object is only used locally and invisible
814 * to external nodes, then LFSCK will not handle it.
816 * dot_lustre sequence has been handled specially. */
819 struct lu_seq_range *range = &info->lti_range;
821 if (lfsck->li_master)
822 fld_range_set_mdt(range);
824 fld_range_set_ost(range);
825 rc = fld_local_lookup(env, ss->ss_server_fld,
826 fid_seq(fid), range);
827 if (rc != 0 || range->lsr_index != idx) {
828 /* Remote object will be handled by the LFSCK
829 * instance on the MDT where the remote object
830 * really resides on. */
836 target = lfsck_object_find(env, lfsck, fid);
837 if (IS_ERR(target)) {
838 CDEBUG(D_LFSCK, "%s: OIT scan failed at find target "
839 DFID", cookie "LPU64": rc = %d\n",
840 lfsck_lfsck2name(lfsck), PFID(fid),
841 iops->store(env, di), rc);
842 lfsck_fail(env, lfsck, true);
843 if (bk->lb_param & LPF_FAILOUT)
844 RETURN(PTR_ERR(target));
849 if (dt_object_exists(target)) {
851 rc = lfsck_update_lma(env, lfsck, target);
853 CDEBUG(D_LFSCK, "%s: fail to update "
854 "LMA for "DFID": rc = %d\n",
855 lfsck_lfsck2name(lfsck),
856 PFID(lfsck_dto2fid(target)), rc);
859 rc = lfsck_exec_oit(env, lfsck, target);
861 lfsck_object_put(env, target);
862 if (rc != 0 && bk->lb_param & LPF_FAILOUT)
866 rc = lfsck_checkpoint(env, lfsck);
867 if (rc != 0 && bk->lb_param & LPF_FAILOUT)
871 lfsck_control_speed(lfsck);
873 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_FATAL1)) {
874 spin_lock(&lfsck->li_lock);
875 thread_set_flags(thread, SVC_STOPPING);
876 spin_unlock(&lfsck->li_lock);
880 rc = iops->next(env, di);
881 if (unlikely(rc > 0))
882 lfsck->li_oit_over = 1;
883 else if (likely(rc == 0))
884 lfsck->li_current_oit_processed = 0;
886 if (unlikely(!thread_is_running(thread))) {
887 CDEBUG(D_LFSCK, "%s: OIT scan exit for engine stop, "
888 "cookie "LPU64"\n", lfsck_lfsck2name(lfsck),
889 iops->store(env, di));
892 } while (rc == 0 || lfsck->li_di_dir != NULL);
897 int lfsck_master_engine(void *args)
899 struct lfsck_thread_args *lta = args;
900 struct lu_env *env = <a->lta_env;
901 struct lfsck_instance *lfsck = lta->lta_lfsck;
902 struct ptlrpc_thread *thread = &lfsck->li_thread;
903 struct dt_object *oit_obj = lfsck->li_obj_oit;
904 const struct dt_it_ops *oit_iops = &oit_obj->do_index_ops->dio_it;
905 struct dt_it *oit_di;
906 struct l_wait_info lwi = { 0 };
910 if (lfsck->li_master &&
911 (!list_empty(&lfsck->li_list_scan) ||
912 !list_empty(&lfsck->li_list_double_scan))) {
913 rc = lfsck_verify_lpf(env, lfsck);
914 /* Fail to verify the .lustre/lost+found/MDTxxxx/ may be not
915 * fatal, because the .lustre/lost+found/ maybe not accessed
916 * by the LFSCK if it does not add orphans or others to such
917 * directory. So go ahead until hit failure when really uses
920 CDEBUG(D_LFSCK, "%s: master engine fail to verify the "
921 ".lustre/lost+found/, go ahead: rc = %d\n",
922 lfsck_lfsck2name(lfsck), rc);
925 oit_di = oit_iops->init(env, oit_obj, lfsck->li_args_oit, BYPASS_CAPA);
926 if (IS_ERR(oit_di)) {
927 rc = PTR_ERR(oit_di);
928 CDEBUG(D_LFSCK, "%s: master engine fail to init iteration: "
929 "rc = %d\n", lfsck_lfsck2name(lfsck), rc);
934 spin_lock(&lfsck->li_lock);
935 lfsck->li_di_oit = oit_di;
936 spin_unlock(&lfsck->li_lock);
937 rc = lfsck_prep(env, lfsck, lta->lta_lsp);
941 CDEBUG(D_LFSCK, "LFSCK entry: oit_flags = %#x, dir_flags = %#x, "
942 "oit_cookie = "LPU64", dir_cookie = "LPX64", parent = "DFID
943 ", pid = %d\n", lfsck->li_args_oit, lfsck->li_args_dir,
944 lfsck->li_pos_checkpoint.lp_oit_cookie,
945 lfsck->li_pos_checkpoint.lp_dir_cookie,
946 PFID(&lfsck->li_pos_checkpoint.lp_dir_parent),
949 spin_lock(&lfsck->li_lock);
950 thread_set_flags(thread, SVC_RUNNING);
951 spin_unlock(&lfsck->li_lock);
952 wake_up_all(&thread->t_ctl_waitq);
954 l_wait_event(thread->t_ctl_waitq,
955 lfsck->li_start_unplug ||
956 !thread_is_running(thread),
958 if (!thread_is_running(thread))
959 GOTO(fini_oit, rc = 0);
961 if (!list_empty(&lfsck->li_list_scan) ||
962 list_empty(&lfsck->li_list_double_scan))
963 rc = lfsck_master_oit_engine(env, lfsck);
967 CDEBUG(D_LFSCK, "LFSCK exit: oit_flags = %#x, dir_flags = %#x, "
968 "oit_cookie = "LPU64", dir_cookie = "LPX64", parent = "DFID
969 ", pid = %d, rc = %d\n", lfsck->li_args_oit, lfsck->li_args_dir,
970 lfsck->li_pos_checkpoint.lp_oit_cookie,
971 lfsck->li_pos_checkpoint.lp_dir_cookie,
972 PFID(&lfsck->li_pos_checkpoint.lp_dir_parent),
975 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_CRASH))
976 rc = lfsck_post(env, lfsck, rc);
978 if (lfsck->li_di_dir != NULL)
979 lfsck_close_dir(env, lfsck);
982 lfsck_di_oit_put(env, lfsck);
983 oit_iops->fini(env, oit_di);
985 if (!list_empty(&lfsck->li_list_double_scan))
986 rc = lfsck_double_scan(env, lfsck);
990 lfsck_quit(env, lfsck);
993 /* XXX: Purge the pinned objects in the future. */
996 spin_lock(&lfsck->li_lock);
997 thread_set_flags(thread, SVC_STOPPED);
998 spin_unlock(&lfsck->li_lock);
999 wake_up_all(&thread->t_ctl_waitq);
1000 lfsck_thread_args_fini(lta);
1004 static inline bool lfsck_assistant_req_empty(struct lfsck_assistant_data *lad)
1008 spin_lock(&lad->lad_lock);
1009 if (list_empty(&lad->lad_req_list))
1011 spin_unlock(&lad->lad_lock);
1017 * Query the LFSCK status from the instatnces on remote servers.
1019 * The LFSCK assistant thread queries the LFSCK instances on other
1020 * servers (MDT/OST) about their status, such as whether they have
1021 * finished the phase1/phase2 scanning or not, and so on.
1023 * \param[in] env pointer to the thread context
1024 * \param[in] com pointer to the lfsck component
1026 * \retval 0 for success
1027 * \retval negative error number on failure
1029 static int lfsck_assistant_query_others(const struct lu_env *env,
1030 struct lfsck_component *com)
1032 struct lfsck_thread_info *info = lfsck_env_info(env);
1033 struct lfsck_request *lr = &info->lti_lr;
1034 struct lfsck_async_interpret_args *laia = &info->lti_laia;
1035 struct lfsck_instance *lfsck = com->lc_lfsck;
1036 struct lfsck_assistant_data *lad = com->lc_data;
1037 struct ptlrpc_request_set *set;
1038 struct lfsck_tgt_descs *ltds;
1039 struct lfsck_tgt_desc *ltd;
1040 struct list_head *phase_head;
1045 set = ptlrpc_prep_set();
1049 lad->lad_touch_gen++;
1050 memset(lr, 0, sizeof(*lr));
1051 lr->lr_index = lfsck_dev_idx(lfsck->li_bottom);
1052 lr->lr_event = LE_QUERY;
1053 lr->lr_active = com->lc_type;
1054 laia->laia_com = com;
1056 laia->laia_shared = 0;
1058 if (!list_empty(&lad->lad_mdt_phase1_list)) {
1059 ltds = &lfsck->li_mdt_descs;
1061 phase_head = &lad->lad_mdt_phase1_list;
1062 } else if (com->lc_type != LFSCK_TYPE_LAYOUT) {
1067 ltds = &lfsck->li_ost_descs;
1068 lr->lr_flags = LEF_TO_OST;
1069 phase_head = &lad->lad_ost_phase1_list;
1072 laia->laia_ltds = ltds;
1073 spin_lock(<ds->ltd_lock);
1074 while (!list_empty(phase_head)) {
1075 struct list_head *phase_list;
1078 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1079 ltd = list_entry(phase_head->next,
1080 struct lfsck_tgt_desc,
1081 ltd_layout_phase_list);
1082 phase_list = <d->ltd_layout_phase_list;
1083 gen = <d->ltd_layout_gen;
1085 ltd = list_entry(phase_head->next,
1086 struct lfsck_tgt_desc,
1087 ltd_namespace_phase_list);
1088 phase_list = <d->ltd_namespace_phase_list;
1089 gen = <d->ltd_namespace_gen;
1092 if (*gen == lad->lad_touch_gen)
1095 *gen = lad->lad_touch_gen;
1096 list_move_tail(phase_list, phase_head);
1097 atomic_inc(<d->ltd_ref);
1098 laia->laia_ltd = ltd;
1099 spin_unlock(<ds->ltd_lock);
1100 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
1101 lfsck_async_interpret_common,
1104 CDEBUG(D_LFSCK, "%s: LFSCK assistant fail to query "
1105 "%s %x for %s: rc = %d\n",
1106 lfsck_lfsck2name(lfsck),
1107 (lr->lr_flags & LEF_TO_OST) ? "OST" : "MDT",
1108 ltd->ltd_index, lad->lad_name, rc);
1112 spin_lock(<ds->ltd_lock);
1114 spin_unlock(<ds->ltd_lock);
1116 rc = ptlrpc_set_wait(set);
1118 ptlrpc_set_destroy(set);
1122 if (com->lc_type == LFSCK_TYPE_LAYOUT && !(lr->lr_flags & LEF_TO_OST) &&
1123 list_empty(&lad->lad_mdt_phase1_list))
1127 ptlrpc_set_destroy(set);
1129 RETURN(rc1 != 0 ? rc1 : rc);
1133 * Notify the LFSCK event to the instatnces on remote servers.
1135 * The LFSCK assistant thread notifies the LFSCK instances on other
1136 * servers (MDT/OST) about some events, such as start new scanning,
1137 * stop the scanning, this LFSCK instance will exit, and so on.
1139 * \param[in] env pointer to the thread context
1140 * \param[in] com pointer to the lfsck component
1141 * \param[in] lr pointer to the LFSCK event request
1143 * \retval 0 for success
1144 * \retval negative error number on failure
1146 static int lfsck_assistant_notify_others(const struct lu_env *env,
1147 struct lfsck_component *com,
1148 struct lfsck_request *lr)
1150 struct lfsck_thread_info *info = lfsck_env_info(env);
1151 struct lfsck_async_interpret_args *laia = &info->lti_laia;
1152 struct lfsck_instance *lfsck = com->lc_lfsck;
1153 struct lfsck_assistant_data *lad = com->lc_data;
1154 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1155 struct ptlrpc_request_set *set;
1156 struct lfsck_tgt_descs *ltds;
1157 struct lfsck_tgt_desc *ltd;
1158 struct lfsck_tgt_desc *next;
1164 set = ptlrpc_prep_set();
1168 lr->lr_index = lfsck_dev_idx(lfsck->li_bottom);
1169 lr->lr_active = com->lc_type;
1170 laia->laia_com = com;
1172 laia->laia_shared = 0;
1174 switch (lr->lr_event) {
1176 if (com->lc_type != LFSCK_TYPE_LAYOUT)
1179 lr->lr_valid = LSV_SPEED_LIMIT | LSV_ERROR_HANDLE | LSV_DRYRUN |
1180 LSV_ASYNC_WINDOWS | LSV_CREATE_OSTOBJ;
1181 lr->lr_speed = bk->lb_speed_limit;
1182 lr->lr_version = bk->lb_version;
1183 lr->lr_param |= bk->lb_param;
1184 lr->lr_async_windows = bk->lb_async_windows;
1185 lr->lr_flags = LEF_TO_OST;
1187 /* Notify OSTs firstly, then handle other MDTs if needed. */
1188 ltds = &lfsck->li_ost_descs;
1189 laia->laia_ltds = ltds;
1190 down_read(<ds->ltd_rw_sem);
1191 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
1192 ltd = lfsck_tgt_get(ltds, idx);
1193 LASSERT(ltd != NULL);
1195 laia->laia_ltd = ltd;
1196 ltd->ltd_layout_done = 0;
1197 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
1198 lfsck_async_interpret_common,
1199 laia, LFSCK_NOTIFY);
1201 lfsck_lad_set_bitmap(env, com, idx);
1202 CDEBUG(D_LFSCK, "%s: LFSCK assistant fail to "
1203 "notify OST %x for %s start: rc = %d\n",
1204 lfsck_lfsck2name(lfsck), idx,
1209 up_read(<ds->ltd_rw_sem);
1212 rc = ptlrpc_set_wait(set);
1214 ptlrpc_set_destroy(set);
1219 if (!(bk->lb_param & LPF_ALL_TGT))
1222 /* link other MDT targets locallly. */
1223 ltds = &lfsck->li_mdt_descs;
1224 spin_lock(<ds->ltd_lock);
1225 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1226 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
1227 ltd = LTD_TGT(ltds, idx);
1228 LASSERT(ltd != NULL);
1230 if (!list_empty(<d->ltd_layout_list))
1233 list_add_tail(<d->ltd_layout_list,
1234 &lad->lad_mdt_list);
1235 list_add_tail(<d->ltd_layout_phase_list,
1236 &lad->lad_mdt_phase1_list);
1239 cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
1240 ltd = LTD_TGT(ltds, idx);
1241 LASSERT(ltd != NULL);
1243 if (!list_empty(<d->ltd_namespace_list))
1246 list_add_tail(<d->ltd_namespace_list,
1247 &lad->lad_mdt_list);
1248 list_add_tail(<d->ltd_namespace_phase_list,
1249 &lad->lad_mdt_phase1_list);
1252 spin_unlock(<ds->ltd_lock);
1255 case LE_PHASE2_DONE:
1256 case LE_PEER_EXIT: {
1257 struct list_head *phase_head;
1259 /* Handle other MDTs firstly if needed, then notify the OSTs. */
1260 if (bk->lb_param & LPF_ALL_TGT) {
1261 phase_head = &lad->lad_mdt_list;
1262 ltds = &lfsck->li_mdt_descs;
1263 if (lr->lr_event == LE_STOP) {
1264 /* unlink other MDT targets locallly. */
1265 spin_lock(<ds->ltd_lock);
1266 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1267 list_for_each_entry_safe(ltd, next,
1268 phase_head, ltd_layout_list) {
1270 <d->ltd_layout_phase_list);
1272 <d->ltd_layout_list);
1275 list_for_each_entry_safe(ltd, next,
1277 ltd_namespace_list) {
1279 <d->ltd_namespace_phase_list);
1281 <d->ltd_namespace_list);
1284 spin_unlock(<ds->ltd_lock);
1286 if (com->lc_type != LFSCK_TYPE_LAYOUT)
1289 lr->lr_flags |= LEF_TO_OST;
1290 phase_head = &lad->lad_ost_list;
1291 ltds = &lfsck->li_ost_descs;
1293 lr->lr_flags &= ~LEF_TO_OST;
1295 } else if (com->lc_type != LFSCK_TYPE_LAYOUT) {
1298 lr->lr_flags |= LEF_TO_OST;
1299 phase_head = &lad->lad_ost_list;
1300 ltds = &lfsck->li_ost_descs;
1304 laia->laia_ltds = ltds;
1305 spin_lock(<ds->ltd_lock);
1306 while (!list_empty(phase_head)) {
1307 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1308 ltd = list_entry(phase_head->next,
1309 struct lfsck_tgt_desc,
1311 if (!list_empty(<d->ltd_layout_phase_list))
1313 <d->ltd_layout_phase_list);
1314 list_del_init(<d->ltd_layout_list);
1316 ltd = list_entry(phase_head->next,
1317 struct lfsck_tgt_desc,
1318 ltd_namespace_list);
1319 if (!list_empty(<d->ltd_namespace_phase_list))
1321 <d->ltd_namespace_phase_list);
1322 list_del_init(<d->ltd_namespace_list);
1324 atomic_inc(<d->ltd_ref);
1325 laia->laia_ltd = ltd;
1326 spin_unlock(<ds->ltd_lock);
1327 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
1328 lfsck_async_interpret_common,
1329 laia, LFSCK_NOTIFY);
1331 CDEBUG(D_LFSCK, "%s: LFSCK assistant fail to "
1332 "notify %s %x for %s stop/phase2_done/"
1333 "peer_exit: rc = %d\n",
1334 lfsck_lfsck2name(lfsck),
1335 (lr->lr_flags & LEF_TO_OST) ?
1336 "OST" : "MDT", ltd->ltd_index,
1340 spin_lock(<ds->ltd_lock);
1342 spin_unlock(<ds->ltd_lock);
1344 rc = ptlrpc_set_wait(set);
1346 ptlrpc_set_destroy(set);
1350 if (com->lc_type == LFSCK_TYPE_LAYOUT &&
1351 !(lr->lr_flags & LEF_TO_OST)) {
1352 lr->lr_flags |= LEF_TO_OST;
1353 phase_head = &lad->lad_ost_list;
1354 ltds = &lfsck->li_ost_descs;
1359 case LE_PHASE1_DONE:
1360 lad->lad_ops->la_sync_failures(env, com, lr);
1361 lad->lad_touch_gen++;
1362 ltds = &lfsck->li_mdt_descs;
1363 laia->laia_ltds = ltds;
1364 spin_lock(<ds->ltd_lock);
1365 while (!list_empty(&lad->lad_mdt_list)) {
1366 struct list_head *list;
1369 if (com->lc_type == LFSCK_TYPE_LAYOUT) {
1370 ltd = list_entry(lad->lad_mdt_list.next,
1371 struct lfsck_tgt_desc,
1373 list = <d->ltd_layout_list;
1374 gen = <d->ltd_layout_gen;
1376 ltd = list_entry(lad->lad_mdt_list.next,
1377 struct lfsck_tgt_desc,
1378 ltd_namespace_list);
1379 list = <d->ltd_namespace_list;
1380 gen = <d->ltd_namespace_gen;
1383 if (*gen == lad->lad_touch_gen)
1386 *gen = lad->lad_touch_gen;
1387 list_move_tail(list, &lad->lad_mdt_list);
1388 atomic_inc(<d->ltd_ref);
1389 laia->laia_ltd = ltd;
1390 spin_unlock(<ds->ltd_lock);
1391 rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
1392 lfsck_async_interpret_common,
1393 laia, LFSCK_NOTIFY);
1395 CDEBUG(D_LFSCK, "%s: LFSCK assistant fail to "
1396 "notify MDT %x for %s phase1 done: "
1397 "rc = %d\n", lfsck_lfsck2name(lfsck),
1398 ltd->ltd_index, lad->lad_name, rc);
1401 spin_lock(<ds->ltd_lock);
1403 spin_unlock(<ds->ltd_lock);
1406 CDEBUG(D_LFSCK, "%s: LFSCK assistant unexpected LFSCK event: "
1407 "rc = %d\n", lfsck_lfsck2name(lfsck), lr->lr_event);
1412 rc1 = ptlrpc_set_wait(set);
1413 ptlrpc_set_destroy(set);
1415 RETURN(rc != 0 ? rc : rc1);
1419 * The LFSCK assistant thread is triggered by the LFSCK main engine.
1420 * They co-work together as an asynchronous pipeline: the LFSCK main
1421 * engine scans the system and pre-fetches the objects, attributes,
1422 * or name entries, etc, and pushes them into the pipeline as input
1423 * requests for the LFSCK assistant thread; on the other end of the
1424 * pipeline, the LFSCK assistant thread performs the real check and
1425 * repair for every request from the main engine.
1427 * Generally, the assistant engine may be blocked when check/repair
1428 * something, so the LFSCK main engine will run some faster. On the
1429 * other hand, the LFSCK main engine will drive multiple assistant
1430 * threads in parallel, means for each LFSCK component on the master
1431 * (such as layout LFSCK, namespace LFSCK), there is an independent
1432 * LFSCK assistant thread. So under such 1:N multiple asynchronous
1433 * pipelines mode, the whole LFSCK performance will be much better
1434 * than check/repair everything by the LFSCK main engine itself.
1436 int lfsck_assistant_engine(void *args)
1438 struct lfsck_thread_args *lta = args;
1439 struct lu_env *env = <a->lta_env;
1440 struct lfsck_component *com = lta->lta_com;
1441 struct lfsck_instance *lfsck = lta->lta_lfsck;
1442 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1443 struct lfsck_position *pos = &com->lc_pos_start;
1444 struct lfsck_thread_info *info = lfsck_env_info(env);
1445 struct lfsck_request *lr = &info->lti_lr;
1446 struct lfsck_assistant_data *lad = com->lc_data;
1447 struct ptlrpc_thread *mthread = &lfsck->li_thread;
1448 struct ptlrpc_thread *athread = &lad->lad_thread;
1449 struct lfsck_assistant_operations *lao = lad->lad_ops;
1450 struct lfsck_assistant_req *lar;
1451 struct l_wait_info lwi = { 0 };
1456 CDEBUG(D_LFSCK, "%s: %s LFSCK assistant thread start\n",
1457 lfsck_lfsck2name(lfsck), lad->lad_name);
1459 memset(lr, 0, sizeof(*lr));
1460 lr->lr_event = LE_START;
1461 if (pos->lp_oit_cookie <= 1)
1462 lr->lr_param = LPF_RESET;
1463 rc = lfsck_assistant_notify_others(env, com, lr);
1465 CDEBUG(D_LFSCK, "%s: LFSCK assistant fail to notify others "
1466 "to start %s: rc = %d\n",
1467 lfsck_lfsck2name(lfsck), lad->lad_name, rc);
1471 spin_lock(&lad->lad_lock);
1472 thread_set_flags(athread, SVC_RUNNING);
1473 spin_unlock(&lad->lad_lock);
1474 wake_up_all(&mthread->t_ctl_waitq);
1477 while (!list_empty(&lad->lad_req_list)) {
1478 bool wakeup = false;
1480 if (unlikely(lad->lad_exit ||
1481 !thread_is_running(mthread)))
1482 GOTO(cleanup1, rc = lad->lad_post_result);
1484 lar = list_entry(lad->lad_req_list.next,
1485 struct lfsck_assistant_req,
1487 /* Only the lfsck_assistant_engine thread itself can
1488 * remove the "lar" from the head of the list, LFSCK
1489 * engine thread only inserts other new "lar" at the
1490 * end of the list. So it is safe to handle current
1491 * "lar" without the spin_lock. */
1492 rc = lao->la_handler_p1(env, com, lar);
1493 spin_lock(&lad->lad_lock);
1494 list_del_init(&lar->lar_list);
1495 lad->lad_prefetched--;
1496 /* Wake up the main engine thread only when the list
1497 * is empty or half of the prefetched items have been
1498 * handled to avoid too frequent thread schedule. */
1499 if (lad->lad_prefetched == 0 ||
1500 (bk->lb_async_windows != 0 &&
1501 bk->lb_async_windows / 2 ==
1502 lad->lad_prefetched))
1504 spin_unlock(&lad->lad_lock);
1506 wake_up_all(&mthread->t_ctl_waitq);
1508 lao->la_req_fini(env, lar);
1509 if (rc < 0 && bk->lb_param & LPF_FAILOUT)
1513 l_wait_event(athread->t_ctl_waitq,
1514 !lfsck_assistant_req_empty(lad) ||
1517 lad->lad_to_double_scan,
1520 if (unlikely(lad->lad_exit))
1521 GOTO(cleanup1, rc = lad->lad_post_result);
1523 if (!list_empty(&lad->lad_req_list))
1526 if (lad->lad_to_post) {
1527 CDEBUG(D_LFSCK, "%s: %s LFSCK assistant thread post\n",
1528 lfsck_lfsck2name(lfsck), lad->lad_name);
1530 if (unlikely(lad->lad_exit))
1531 GOTO(cleanup1, rc = lad->lad_post_result);
1533 lad->lad_to_post = 0;
1534 LASSERT(lad->lad_post_result > 0);
1536 memset(lr, 0, sizeof(*lr));
1537 lr->lr_event = LE_PHASE1_DONE;
1538 lr->lr_status = lad->lad_post_result;
1539 rc = lfsck_assistant_notify_others(env, com, lr);
1541 CDEBUG(D_LFSCK, "%s: LFSCK assistant failed to "
1542 "notify others for %s post: rc = %d\n",
1543 lfsck_lfsck2name(lfsck),
1546 /* Wakeup the master engine to go ahead. */
1547 wake_up_all(&mthread->t_ctl_waitq);
1550 if (lad->lad_to_double_scan) {
1551 lad->lad_to_double_scan = 0;
1552 atomic_inc(&lfsck->li_double_scan_count);
1553 lad->lad_in_double_scan = 1;
1554 wake_up_all(&mthread->t_ctl_waitq);
1556 com->lc_new_checked = 0;
1557 com->lc_new_scanned = 0;
1558 com->lc_time_last_checkpoint = cfs_time_current();
1559 com->lc_time_next_checkpoint =
1560 com->lc_time_last_checkpoint +
1561 cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
1563 /* Flush async updates before handling orphan. */
1564 dt_sync(env, lfsck->li_next);
1566 CDEBUG(D_LFSCK, "%s: LFSCK assistant phase2 "
1567 "scan start\n", lfsck_lfsck2name(lfsck));
1569 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_DOUBLESCAN))
1570 GOTO(cleanup2, rc = 0);
1572 while (lad->lad_in_double_scan) {
1573 rc = lfsck_assistant_query_others(env, com);
1574 if (lfsck_phase2_next_ready(lad))
1580 /* Pull LFSCK status on related targets once
1581 * per 30 seconds if we are not notified. */
1582 lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(30),
1583 cfs_time_seconds(1),
1585 rc = l_wait_event(athread->t_ctl_waitq,
1586 lfsck_phase2_next_ready(lad) ||
1588 !thread_is_running(mthread),
1591 if (unlikely(lad->lad_exit ||
1592 !thread_is_running(mthread)))
1593 GOTO(cleanup2, rc = 0);
1595 if (rc == -ETIMEDOUT)
1602 rc = lao->la_handler_p2(env, com);
1606 if (unlikely(lad->lad_exit ||
1607 !thread_is_running(mthread)))
1608 GOTO(cleanup2, rc = 0);
1614 /* Cleanup the unfinished requests. */
1615 spin_lock(&lad->lad_lock);
1617 lad->lad_assistant_status = rc;
1619 if (lad->lad_exit && lad->lad_post_result <= 0)
1620 lao->la_fill_pos(env, com, &lfsck->li_pos_checkpoint);
1622 while (!list_empty(&lad->lad_req_list)) {
1623 lar = list_entry(lad->lad_req_list.next,
1624 struct lfsck_assistant_req,
1626 list_del_init(&lar->lar_list);
1627 lad->lad_prefetched--;
1628 spin_unlock(&lad->lad_lock);
1629 lao->la_req_fini(env, lar);
1630 spin_lock(&lad->lad_lock);
1632 spin_unlock(&lad->lad_lock);
1634 LASSERTF(lad->lad_prefetched == 0, "unmatched prefeteched objs %d\n",
1635 lad->lad_prefetched);
1638 memset(lr, 0, sizeof(*lr));
1640 lr->lr_event = LE_PHASE2_DONE;
1642 } else if (rc == 0) {
1643 if (lfsck->li_flags & LPF_ALL_TGT) {
1644 lr->lr_event = LE_STOP;
1645 lr->lr_status = LS_STOPPED;
1647 lr->lr_event = LE_PEER_EXIT;
1648 switch (lfsck->li_status) {
1651 lr->lr_status = LS_CO_PAUSED;
1655 lr->lr_status = LS_CO_STOPPED;
1658 CDEBUG(D_LFSCK, "%s: LFSCK assistant unknown "
1659 "status: rc = %d\n",
1660 lfsck_lfsck2name(lfsck),
1662 lr->lr_status = LS_CO_FAILED;
1667 if (lfsck->li_flags & LPF_ALL_TGT) {
1668 lr->lr_event = LE_STOP;
1669 lr->lr_status = LS_FAILED;
1671 lr->lr_event = LE_PEER_EXIT;
1672 lr->lr_status = LS_CO_FAILED;
1676 rc1 = lfsck_assistant_notify_others(env, com, lr);
1678 CDEBUG(D_LFSCK, "%s: LFSCK assistant failed to notify "
1679 "others for %s quit: rc = %d\n",
1680 lfsck_lfsck2name(lfsck), lad->lad_name, rc1);
1684 /* Flush async updates before exit. */
1685 dt_sync(env, lfsck->li_next);
1687 /* Under force exit case, some requests may be just freed without
1688 * verification, those objects should be re-handled when next run.
1689 * So not update the on-disk tracing file under such case. */
1690 if (lad->lad_in_double_scan) {
1692 rc1 = lao->la_double_scan_result(env, com, rc);
1694 CDEBUG(D_LFSCK, "%s: LFSCK assistant phase2 scan "
1695 "finished: rc = %d\n",
1696 lfsck_lfsck2name(lfsck), rc1 != 0 ? rc1 : rc);
1700 if (lad->lad_in_double_scan)
1701 atomic_dec(&lfsck->li_double_scan_count);
1703 spin_lock(&lad->lad_lock);
1704 lad->lad_assistant_status = (rc1 != 0 ? rc1 : rc);
1705 thread_set_flags(athread, SVC_STOPPED);
1706 wake_up_all(&mthread->t_ctl_waitq);
1707 spin_unlock(&lad->lad_lock);
1709 CDEBUG(D_LFSCK, "%s: %s LFSCK assistant thread exit: rc = %d\n",
1710 lfsck_lfsck2name(lfsck), lad->lad_name,
1711 lad->lad_assistant_status);
1713 lfsck_thread_args_fini(lta);