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_namespace.c
28 * Author: Fan, Yong <fan.yong@intel.com>
31 #define DEBUG_SUBSYSTEM S_LFSCK
33 #include <lustre/lustre_idl.h>
34 #include <lu_object.h>
35 #include <dt_object.h>
36 #include <md_object.h>
37 #include <lustre_linkea.h>
38 #include <lustre_fid.h>
39 #include <lustre_lib.h>
40 #include <lustre_net.h>
41 #include <lustre/lustre_user.h>
43 #include "lfsck_internal.h"
45 #define LFSCK_NAMESPACE_MAGIC 0xA0629D03
47 static const char lfsck_namespace_name[] = "lfsck_namespace";
49 static void lfsck_namespace_le_to_cpu(struct lfsck_namespace *des,
50 struct lfsck_namespace *src)
52 des->ln_magic = le32_to_cpu(src->ln_magic);
53 des->ln_status = le32_to_cpu(src->ln_status);
54 des->ln_flags = le32_to_cpu(src->ln_flags);
55 des->ln_success_count = le32_to_cpu(src->ln_success_count);
56 des->ln_run_time_phase1 = le32_to_cpu(src->ln_run_time_phase1);
57 des->ln_run_time_phase2 = le32_to_cpu(src->ln_run_time_phase2);
58 des->ln_time_last_complete = le64_to_cpu(src->ln_time_last_complete);
59 des->ln_time_latest_start = le64_to_cpu(src->ln_time_latest_start);
60 des->ln_time_last_checkpoint =
61 le64_to_cpu(src->ln_time_last_checkpoint);
62 lfsck_position_le_to_cpu(&des->ln_pos_latest_start,
63 &src->ln_pos_latest_start);
64 lfsck_position_le_to_cpu(&des->ln_pos_last_checkpoint,
65 &src->ln_pos_last_checkpoint);
66 lfsck_position_le_to_cpu(&des->ln_pos_first_inconsistent,
67 &src->ln_pos_first_inconsistent);
68 des->ln_items_checked = le64_to_cpu(src->ln_items_checked);
69 des->ln_items_repaired = le64_to_cpu(src->ln_items_repaired);
70 des->ln_items_failed = le64_to_cpu(src->ln_items_failed);
71 des->ln_dirs_checked = le64_to_cpu(src->ln_dirs_checked);
72 des->ln_mlinked_checked = le64_to_cpu(src->ln_mlinked_checked);
73 des->ln_objs_checked_phase2 = le64_to_cpu(src->ln_objs_checked_phase2);
74 des->ln_objs_repaired_phase2 =
75 le64_to_cpu(src->ln_objs_repaired_phase2);
76 des->ln_objs_failed_phase2 = le64_to_cpu(src->ln_objs_failed_phase2);
77 des->ln_objs_nlink_repaired = le64_to_cpu(src->ln_objs_nlink_repaired);
78 des->ln_objs_lost_found = le64_to_cpu(src->ln_objs_lost_found);
79 fid_le_to_cpu(&des->ln_fid_latest_scanned_phase2,
80 &src->ln_fid_latest_scanned_phase2);
83 static void lfsck_namespace_cpu_to_le(struct lfsck_namespace *des,
84 struct lfsck_namespace *src)
86 des->ln_magic = cpu_to_le32(src->ln_magic);
87 des->ln_status = cpu_to_le32(src->ln_status);
88 des->ln_flags = cpu_to_le32(src->ln_flags);
89 des->ln_success_count = cpu_to_le32(src->ln_success_count);
90 des->ln_run_time_phase1 = cpu_to_le32(src->ln_run_time_phase1);
91 des->ln_run_time_phase2 = cpu_to_le32(src->ln_run_time_phase2);
92 des->ln_time_last_complete = cpu_to_le64(src->ln_time_last_complete);
93 des->ln_time_latest_start = cpu_to_le64(src->ln_time_latest_start);
94 des->ln_time_last_checkpoint =
95 cpu_to_le64(src->ln_time_last_checkpoint);
96 lfsck_position_cpu_to_le(&des->ln_pos_latest_start,
97 &src->ln_pos_latest_start);
98 lfsck_position_cpu_to_le(&des->ln_pos_last_checkpoint,
99 &src->ln_pos_last_checkpoint);
100 lfsck_position_cpu_to_le(&des->ln_pos_first_inconsistent,
101 &src->ln_pos_first_inconsistent);
102 des->ln_items_checked = cpu_to_le64(src->ln_items_checked);
103 des->ln_items_repaired = cpu_to_le64(src->ln_items_repaired);
104 des->ln_items_failed = cpu_to_le64(src->ln_items_failed);
105 des->ln_dirs_checked = cpu_to_le64(src->ln_dirs_checked);
106 des->ln_mlinked_checked = cpu_to_le64(src->ln_mlinked_checked);
107 des->ln_objs_checked_phase2 = cpu_to_le64(src->ln_objs_checked_phase2);
108 des->ln_objs_repaired_phase2 =
109 cpu_to_le64(src->ln_objs_repaired_phase2);
110 des->ln_objs_failed_phase2 = cpu_to_le64(src->ln_objs_failed_phase2);
111 des->ln_objs_nlink_repaired = cpu_to_le64(src->ln_objs_nlink_repaired);
112 des->ln_objs_lost_found = cpu_to_le64(src->ln_objs_lost_found);
113 fid_cpu_to_le(&des->ln_fid_latest_scanned_phase2,
114 &src->ln_fid_latest_scanned_phase2);
118 * \retval +ve: the lfsck_namespace is broken, the caller should reset it.
119 * \retval 0: succeed.
120 * \retval -ve: failed cases.
122 static int lfsck_namespace_load(const struct lu_env *env,
123 struct lfsck_component *com)
125 int len = com->lc_file_size;
128 rc = dt_xattr_get(env, com->lc_obj,
129 lfsck_buf_get(env, com->lc_file_disk, len),
130 XATTR_NAME_LFSCK_NAMESPACE, BYPASS_CAPA);
132 struct lfsck_namespace *ns = com->lc_file_ram;
134 lfsck_namespace_le_to_cpu(ns,
135 (struct lfsck_namespace *)com->lc_file_disk);
136 if (ns->ln_magic != LFSCK_NAMESPACE_MAGIC) {
137 CWARN("%.16s: invalid lfsck_namespace magic "
139 lfsck_lfsck2name(com->lc_lfsck),
140 ns->ln_magic, LFSCK_NAMESPACE_MAGIC);
145 } else if (rc != -ENODATA) {
146 CERROR("%.16s: fail to load lfsck_namespace, expected = %d, "
147 "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck), len, rc);
154 static int lfsck_namespace_store(const struct lu_env *env,
155 struct lfsck_component *com, bool init)
157 struct dt_object *obj = com->lc_obj;
158 struct lfsck_instance *lfsck = com->lc_lfsck;
159 struct thandle *handle;
160 int len = com->lc_file_size;
164 lfsck_namespace_cpu_to_le((struct lfsck_namespace *)com->lc_file_disk,
165 (struct lfsck_namespace *)com->lc_file_ram);
166 handle = dt_trans_create(env, lfsck->li_bottom);
167 if (IS_ERR(handle)) {
168 rc = PTR_ERR(handle);
169 CERROR("%.16s: fail to create trans for storing "
170 "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
174 rc = dt_declare_xattr_set(env, obj,
175 lfsck_buf_get(env, com->lc_file_disk, len),
176 XATTR_NAME_LFSCK_NAMESPACE, 0, handle);
178 CERROR("%.16s: fail to declare trans for storing "
179 "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
183 rc = dt_trans_start_local(env, lfsck->li_bottom, handle);
185 CERROR("%.16s: fail to start trans for storing "
186 "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
190 rc = dt_xattr_set(env, obj,
191 lfsck_buf_get(env, com->lc_file_disk, len),
192 XATTR_NAME_LFSCK_NAMESPACE,
193 init ? LU_XATTR_CREATE : LU_XATTR_REPLACE,
194 handle, BYPASS_CAPA);
196 CERROR("%.16s: fail to store lfsck_namespace, len = %d, "
197 "rc = %d\n", lfsck_lfsck2name(lfsck), len, rc);
202 dt_trans_stop(env, lfsck->li_bottom, handle);
206 static int lfsck_namespace_init(const struct lu_env *env,
207 struct lfsck_component *com)
209 struct lfsck_namespace *ns = (struct lfsck_namespace *)com->lc_file_ram;
212 memset(ns, 0, sizeof(*ns));
213 ns->ln_magic = LFSCK_NAMESPACE_MAGIC;
214 ns->ln_status = LS_INIT;
215 down_write(&com->lc_sem);
216 rc = lfsck_namespace_store(env, com, true);
217 up_write(&com->lc_sem);
221 static int lfsck_namespace_lookup(const struct lu_env *env,
222 struct lfsck_component *com,
223 const struct lu_fid *fid, __u8 *flags)
225 struct lu_fid *key = &lfsck_env_info(env)->lti_fid;
228 fid_cpu_to_be(key, fid);
229 rc = dt_lookup(env, com->lc_obj, (struct dt_rec *)flags,
230 (const struct dt_key *)key, BYPASS_CAPA);
234 static int lfsck_namespace_delete(const struct lu_env *env,
235 struct lfsck_component *com,
236 const struct lu_fid *fid)
238 struct lfsck_instance *lfsck = com->lc_lfsck;
239 struct lu_fid *key = &lfsck_env_info(env)->lti_fid;
240 struct thandle *handle;
241 struct dt_object *obj = com->lc_obj;
245 handle = dt_trans_create(env, lfsck->li_bottom);
247 RETURN(PTR_ERR(handle));
249 rc = dt_declare_delete(env, obj, (const struct dt_key *)fid, handle);
253 rc = dt_trans_start_local(env, lfsck->li_bottom, handle);
257 fid_cpu_to_be(key, fid);
258 rc = dt_delete(env, obj, (const struct dt_key *)key, handle,
264 dt_trans_stop(env, lfsck->li_bottom, handle);
268 static int lfsck_namespace_update(const struct lu_env *env,
269 struct lfsck_component *com,
270 const struct lu_fid *fid,
271 __u8 flags, bool force)
273 struct lfsck_instance *lfsck = com->lc_lfsck;
274 struct lu_fid *key = &lfsck_env_info(env)->lti_fid;
275 struct thandle *handle;
276 struct dt_object *obj = com->lc_obj;
282 rc = lfsck_namespace_lookup(env, com, fid, &tf);
283 if (rc != 0 && rc != -ENOENT)
287 if (!force || flags == tf)
291 handle = dt_trans_create(env, lfsck->li_bottom);
293 RETURN(PTR_ERR(handle));
295 rc = dt_declare_delete(env, obj, (const struct dt_key *)fid,
300 handle = dt_trans_create(env, lfsck->li_bottom);
302 RETURN(PTR_ERR(handle));
305 rc = dt_declare_insert(env, obj, (const struct dt_rec *)&flags,
306 (const struct dt_key *)fid, handle);
310 rc = dt_trans_start_local(env, lfsck->li_bottom, handle);
314 fid_cpu_to_be(key, fid);
316 rc = dt_delete(env, obj, (const struct dt_key *)key, handle,
319 CERROR("%s: fail to insert "DFID", rc = %d\n",
320 lfsck_lfsck2name(com->lc_lfsck), PFID(fid), rc);
325 rc = dt_insert(env, obj, (const struct dt_rec *)&flags,
326 (const struct dt_key *)key, handle, BYPASS_CAPA, 1);
331 dt_trans_stop(env, lfsck->li_bottom, handle);
335 static int lfsck_namespace_check_exist(const struct lu_env *env,
336 struct lfsck_instance *lfsck,
337 struct dt_object *obj, const char *name)
339 struct dt_object *dir = lfsck->li_obj_dir;
340 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
344 if (unlikely(lfsck_is_dead_obj(obj)))
345 RETURN(LFSCK_NAMEENTRY_DEAD);
347 rc = dt_lookup(env, dir, (struct dt_rec *)fid,
348 (const struct dt_key *)name, BYPASS_CAPA);
350 RETURN(LFSCK_NAMEENTRY_REMOVED);
355 if (!lu_fid_eq(fid, lfsck_dto2fid(obj)))
356 RETURN(LFSCK_NAMEENTRY_RECREATED);
361 static int lfsck_declare_namespace_exec_dir(const struct lu_env *env,
362 struct dt_object *obj,
363 struct thandle *handle)
367 /* For destroying all invalid linkEA entries. */
368 rc = dt_declare_xattr_del(env, obj, XATTR_NAME_LINK, handle);
372 /* For insert new linkEA entry. */
373 rc = dt_declare_xattr_set(env, obj,
374 lfsck_buf_get_const(env, NULL, DEFAULT_LINKEA_SIZE),
375 XATTR_NAME_LINK, 0, handle);
379 static int lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
380 struct linkea_data *ldata)
385 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
387 if (ldata->ld_buf->lb_buf == NULL)
390 if (!dt_object_exists(obj))
393 rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK, BYPASS_CAPA);
395 /* Buf was too small, figure out what we need. */
396 lu_buf_free(ldata->ld_buf);
397 rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK,
402 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
403 if (ldata->ld_buf->lb_buf == NULL)
406 rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK,
417 static int lfsck_links_write(const struct lu_env *env, struct dt_object *obj,
418 struct linkea_data *ldata, struct thandle *handle)
420 const struct lu_buf *buf = lfsck_buf_get_const(env,
421 ldata->ld_buf->lb_buf,
422 ldata->ld_leh->leh_len);
424 return dt_xattr_set(env, obj, buf, XATTR_NAME_LINK, 0, handle,
429 * \retval ve: removed entries
431 static int lfsck_linkea_entry_unpack(struct lfsck_instance *lfsck,
432 struct linkea_data *ldata,
433 struct lu_name *cname,
436 struct link_ea_entry *oldlee;
440 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, cname, pfid);
441 oldlee = ldata->ld_lee;
442 oldlen = ldata->ld_reclen;
443 linkea_next_entry(ldata);
444 while (ldata->ld_lee != NULL) {
445 ldata->ld_reclen = (ldata->ld_lee->lee_reclen[0] << 8) |
446 ldata->ld_lee->lee_reclen[1];
447 if (unlikely(ldata->ld_reclen == oldlen &&
448 memcmp(ldata->ld_lee, oldlee, oldlen) == 0)) {
449 linkea_del_buf(ldata, cname);
452 linkea_next_entry(ldata);
455 ldata->ld_lee = oldlee;
456 ldata->ld_reclen = oldlen;
461 * \retval +ve repaired
462 * \retval 0 no need to repair
463 * \retval -ve error cases
465 static int lfsck_namespace_double_scan_one(const struct lu_env *env,
466 struct lfsck_component *com,
467 struct dt_object *child, __u8 flags)
469 struct lfsck_thread_info *info = lfsck_env_info(env);
470 struct lu_attr *la = &info->lti_la;
471 struct lu_name *cname = &info->lti_name;
472 struct lu_fid *pfid = &info->lti_fid;
473 struct lu_fid *cfid = &info->lti_fid2;
474 struct lfsck_instance *lfsck = com->lc_lfsck;
475 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
476 struct lfsck_namespace *ns =
477 (struct lfsck_namespace *)com->lc_file_ram;
478 struct linkea_data ldata = { 0 };
479 struct thandle *handle = NULL;
485 if (com->lc_journal) {
492 handle = dt_trans_create(env, lfsck->li_next);
494 RETURN(rc = PTR_ERR(handle));
496 rc = dt_declare_xattr_set(env, child,
497 lfsck_buf_get_const(env, NULL, DEFAULT_LINKEA_SIZE),
498 XATTR_NAME_LINK, 0, handle);
502 rc = dt_trans_start(env, lfsck->li_next, handle);
506 dt_write_lock(env, child, MOR_TGT_CHILD);
510 if (unlikely(lfsck_is_dead_obj(child)))
513 rc = dt_attr_get(env, child, la, BYPASS_CAPA);
515 rc = lfsck_links_read(env, child, &ldata);
517 if ((bk->lb_param & LPF_DRYRUN) &&
518 (rc == -EINVAL || rc == -ENODATA))
524 linkea_first_entry(&ldata);
525 while (ldata.ld_lee != NULL) {
526 struct dt_object *parent = NULL;
528 rc = lfsck_linkea_entry_unpack(lfsck, &ldata, cname, pfid);
532 if (!fid_is_sane(pfid))
535 parent = lfsck_object_find(env, lfsck, pfid);
538 else if (IS_ERR(parent))
539 GOTO(stop, rc = PTR_ERR(parent));
541 if (!dt_object_exists(parent))
544 /* XXX: Currently, skip remote object, the consistency for
545 * remote object will be processed in LFSCK phase III. */
546 if (dt_object_remote(parent)) {
547 lfsck_object_put(env, parent);
548 linkea_next_entry(&ldata);
552 if (unlikely(!dt_try_as_dir(env, parent)))
555 /* To guarantee the 'name' is terminated with '0'. */
556 memcpy(info->lti_key, cname->ln_name, cname->ln_namelen);
557 info->lti_key[cname->ln_namelen] = 0;
558 cname->ln_name = info->lti_key;
559 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
560 (const struct dt_key *)cname->ln_name,
562 if (rc != 0 && rc != -ENOENT) {
563 lfsck_object_put(env, parent);
568 if (lu_fid_eq(cfid, lfsck_dto2fid(child))) {
569 lfsck_object_put(env, parent);
570 linkea_next_entry(&ldata);
577 /* If there is no name entry in the parent dir and the object
578 * link count is less than the linkea entries count, then the
579 * linkea entry should be removed. */
580 if (ldata.ld_leh->leh_reccount > la->la_nlink)
583 /* XXX: For the case of there is a linkea entry, but without
584 * name entry pointing to the object and its hard links
585 * count is not less than the object name entries count,
586 * then seems we should add the 'missed' name entry back
587 * to namespace, but before LFSCK phase III finished, we
588 * do not know whether the object has some inconsistency
589 * on other MDTs. So now, do NOT add the name entry back
590 * to the namespace, but keep the linkEA entry. LU-2914 */
591 lfsck_object_put(env, parent);
592 linkea_next_entry(&ldata);
597 lfsck_object_put(env, parent);
598 if (bk->lb_param & LPF_DRYRUN)
601 CDEBUG(D_LFSCK, "Remove linkEA: "DFID"[%.*s], "DFID"\n",
602 PFID(lfsck_dto2fid(child)), cname->ln_namelen, cname->ln_name,
604 linkea_del_buf(&ldata, cname);
609 if (!com->lc_journal) {
614 rc = lfsck_links_write(env, child, &ldata, handle);
621 /* XXX: For the case linkea entries count does not match the object hard
622 * links count, we cannot update the later one simply. Before LFSCK
623 * phase III finished, we cannot know whether there are some remote
624 * name entries to be repaired or not. LU-2914 */
625 if (rc == 0 && !lfsck_is_dead_obj(child) &&
626 ldata.ld_leh != NULL &&
627 ldata.ld_leh->leh_reccount != la->la_nlink)
628 CWARN("%.16s: the object "DFID" linkEA entry count %u "
629 "may not match its hardlink count %u\n",
630 lfsck_lfsck2name(lfsck), PFID(cfid),
631 ldata.ld_leh->leh_reccount, la->la_nlink);
633 dt_write_unlock(env, child);
637 dt_trans_stop(env, lfsck->li_next, handle);
639 if (rc == 0 && update) {
640 ns->ln_objs_nlink_repaired++;
649 static int lfsck_namespace_reset(const struct lu_env *env,
650 struct lfsck_component *com, bool init)
652 struct lfsck_instance *lfsck = com->lc_lfsck;
653 struct lfsck_namespace *ns =
654 (struct lfsck_namespace *)com->lc_file_ram;
655 struct dt_object *dto;
659 down_write(&com->lc_sem);
661 memset(ns, 0, sizeof(*ns));
663 __u32 count = ns->ln_success_count;
664 __u64 last_time = ns->ln_time_last_complete;
666 memset(ns, 0, sizeof(*ns));
667 ns->ln_success_count = count;
668 ns->ln_time_last_complete = last_time;
670 ns->ln_magic = LFSCK_NAMESPACE_MAGIC;
671 ns->ln_status = LS_INIT;
673 rc = local_object_unlink(env, lfsck->li_bottom, lfsck->li_local_root,
674 lfsck_namespace_name);
678 dto = local_index_find_or_create(env, lfsck->li_los, lfsck->li_local_root,
679 lfsck_namespace_name,
680 S_IFREG | S_IRUGO | S_IWUSR,
683 GOTO(out, rc = PTR_ERR(dto));
686 rc = dto->do_ops->do_index_try(env, dto, &dt_lfsck_features);
690 rc = lfsck_namespace_store(env, com, true);
695 up_write(&com->lc_sem);
700 lfsck_namespace_fail(const struct lu_env *env, struct lfsck_component *com,
703 struct lfsck_namespace *ns = (struct lfsck_namespace *)com->lc_file_ram;
705 down_write(&com->lc_sem);
707 com->lc_new_checked++;
708 ns->ln_items_failed++;
709 if (lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent))
710 lfsck_pos_fill(env, com->lc_lfsck,
711 &ns->ln_pos_first_inconsistent, false);
712 up_write(&com->lc_sem);
715 static int lfsck_namespace_checkpoint(const struct lu_env *env,
716 struct lfsck_component *com, bool init)
718 struct lfsck_instance *lfsck = com->lc_lfsck;
719 struct lfsck_namespace *ns =
720 (struct lfsck_namespace *)com->lc_file_ram;
723 if (com->lc_new_checked == 0 && !init)
726 down_write(&com->lc_sem);
729 ns->ln_pos_latest_start = lfsck->li_pos_current;
731 ns->ln_pos_last_checkpoint = lfsck->li_pos_current;
732 ns->ln_run_time_phase1 += cfs_duration_sec(cfs_time_current() +
733 HALF_SEC - lfsck->li_time_last_checkpoint);
734 ns->ln_time_last_checkpoint = cfs_time_current_sec();
735 ns->ln_items_checked += com->lc_new_checked;
736 com->lc_new_checked = 0;
739 rc = lfsck_namespace_store(env, com, false);
741 up_write(&com->lc_sem);
745 static int lfsck_namespace_prep(const struct lu_env *env,
746 struct lfsck_component *com)
748 struct lfsck_instance *lfsck = com->lc_lfsck;
749 struct lfsck_namespace *ns =
750 (struct lfsck_namespace *)com->lc_file_ram;
751 struct lfsck_position *pos = &com->lc_pos_start;
753 if (ns->ln_status == LS_COMPLETED) {
756 rc = lfsck_namespace_reset(env, com, false);
761 down_write(&com->lc_sem);
763 ns->ln_time_latest_start = cfs_time_current_sec();
765 spin_lock(&lfsck->li_lock);
766 if (ns->ln_flags & LF_SCANNED_ONCE) {
767 if (!lfsck->li_drop_dryrun ||
768 lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent)) {
769 ns->ln_status = LS_SCANNING_PHASE2;
770 cfs_list_del_init(&com->lc_link);
771 cfs_list_add_tail(&com->lc_link,
772 &lfsck->li_list_double_scan);
773 if (!cfs_list_empty(&com->lc_link_dir))
774 cfs_list_del_init(&com->lc_link_dir);
775 lfsck_pos_set_zero(pos);
777 ns->ln_status = LS_SCANNING_PHASE1;
778 ns->ln_run_time_phase1 = 0;
779 ns->ln_run_time_phase2 = 0;
780 ns->ln_items_checked = 0;
781 ns->ln_items_repaired = 0;
782 ns->ln_items_failed = 0;
783 ns->ln_dirs_checked = 0;
784 ns->ln_mlinked_checked = 0;
785 ns->ln_objs_checked_phase2 = 0;
786 ns->ln_objs_repaired_phase2 = 0;
787 ns->ln_objs_failed_phase2 = 0;
788 ns->ln_objs_nlink_repaired = 0;
789 ns->ln_objs_lost_found = 0;
790 fid_zero(&ns->ln_fid_latest_scanned_phase2);
791 if (cfs_list_empty(&com->lc_link_dir))
792 cfs_list_add_tail(&com->lc_link_dir,
793 &lfsck->li_list_dir);
794 *pos = ns->ln_pos_first_inconsistent;
797 ns->ln_status = LS_SCANNING_PHASE1;
798 if (cfs_list_empty(&com->lc_link_dir))
799 cfs_list_add_tail(&com->lc_link_dir,
800 &lfsck->li_list_dir);
801 if (!lfsck->li_drop_dryrun ||
802 lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent)) {
803 *pos = ns->ln_pos_last_checkpoint;
804 pos->lp_oit_cookie++;
806 *pos = ns->ln_pos_first_inconsistent;
809 spin_unlock(&lfsck->li_lock);
811 up_write(&com->lc_sem);
815 static int lfsck_namespace_exec_oit(const struct lu_env *env,
816 struct lfsck_component *com,
817 struct dt_object *obj)
819 down_write(&com->lc_sem);
820 com->lc_new_checked++;
821 if (S_ISDIR(lfsck_object_type(obj)))
822 ((struct lfsck_namespace *)com->lc_file_ram)->ln_dirs_checked++;
823 up_write(&com->lc_sem);
827 static int lfsck_namespace_exec_dir(const struct lu_env *env,
828 struct lfsck_component *com,
829 struct dt_object *obj,
830 struct lu_dirent *ent)
832 struct lfsck_thread_info *info = lfsck_env_info(env);
833 struct lu_attr *la = &info->lti_la;
834 struct lfsck_instance *lfsck = com->lc_lfsck;
835 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
836 struct lfsck_namespace *ns =
837 (struct lfsck_namespace *)com->lc_file_ram;
838 struct linkea_data ldata = { 0 };
839 const struct lu_fid *pfid =
840 lu_object_fid(&lfsck->li_obj_dir->do_lu);
841 const struct lu_fid *cfid = lfsck_dto2fid(obj);
842 const struct lu_name *cname;
843 struct thandle *handle = NULL;
844 bool repaired = false;
852 cname = lfsck_name_get_const(env, ent->lde_name, ent->lde_namelen);
853 down_write(&com->lc_sem);
854 com->lc_new_checked++;
856 if (ent->lde_attrs & LUDA_UPGRADE) {
857 ns->ln_flags |= LF_UPGRADE;
859 } else if (ent->lde_attrs & LUDA_REPAIR) {
860 ns->ln_flags |= LF_INCONSISTENT;
864 if (ent->lde_name[0] == '.' &&
865 (ent->lde_namelen == 1 ||
866 (ent->lde_namelen == 2 && ent->lde_name[1] == '.') ||
867 fid_is_dot_lustre(&ent->lde_fid)))
870 if (!(bk->lb_param & LPF_DRYRUN) &&
871 (com->lc_journal || repaired)) {
877 handle = dt_trans_create(env, lfsck->li_next);
879 GOTO(out, rc = PTR_ERR(handle));
881 rc = lfsck_declare_namespace_exec_dir(env, obj, handle);
885 rc = dt_trans_start(env, lfsck->li_next, handle);
889 dt_write_lock(env, obj, MOR_TGT_CHILD);
893 rc = lfsck_namespace_check_exist(env, lfsck, obj, ent->lde_name);
897 rc = lfsck_links_read(env, obj, &ldata);
899 count = ldata.ld_leh->leh_reccount;
900 rc = linkea_links_find(&ldata, cname, pfid);
902 (count == 1 || !S_ISDIR(lfsck_object_type(obj))))
905 ns->ln_flags |= LF_INCONSISTENT;
906 /* For dir, if there are more than one linkea entries, or the
907 * linkea entry does not match the name entry, then remove all
908 * and add the correct one. */
909 if (S_ISDIR(lfsck_object_type(obj))) {
917 } else if (unlikely(rc == -EINVAL)) {
919 ns->ln_flags |= LF_INCONSISTENT;
920 /* The magic crashed, we are not sure whether there are more
921 * corrupt data in the linkea, so remove all linkea entries. */
925 } else if (rc == -ENODATA) {
927 ns->ln_flags |= LF_UPGRADE;
932 if (bk->lb_param & LPF_DRYRUN) {
937 if (!com->lc_journal)
943 rc = dt_xattr_del(env, obj, XATTR_NAME_LINK, handle,
950 rc = linkea_data_new(&ldata,
951 &lfsck_env_info(env)->lti_linkea_buf);
956 rc = linkea_add_buf(&ldata, cname, pfid);
960 rc = lfsck_links_write(env, obj, &ldata, handle);
964 count = ldata.ld_leh->leh_reccount;
973 rc = dt_attr_get(env, obj, la, BYPASS_CAPA);
978 (la->la_nlink == 1 || S_ISDIR(lfsck_object_type(obj))))
979 /* Usually, it is for single linked object or dir, do nothing.*/
982 /* Following modification will be in another transaction. */
983 if (handle != NULL) {
984 LASSERT(dt_write_locked(env, obj));
986 dt_write_unlock(env, obj);
989 dt_trans_stop(env, lfsck->li_next, handle);
993 ns->ln_mlinked_checked++;
994 rc = lfsck_namespace_update(env, com, cfid,
995 count != la->la_nlink ? LLF_UNMATCH_NLINKS : 0, false);
1001 dt_write_unlock(env, obj);
1004 dt_trans_stop(env, lfsck->li_next, handle);
1008 ns->ln_items_failed++;
1009 if (lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent))
1010 lfsck_pos_fill(env, lfsck,
1011 &ns->ln_pos_first_inconsistent, false);
1012 if (!(bk->lb_param & LPF_FAILOUT))
1016 ns->ln_items_repaired++;
1018 com->lc_journal = 0;
1021 up_write(&com->lc_sem);
1025 static int lfsck_namespace_post(const struct lu_env *env,
1026 struct lfsck_component *com,
1027 int result, bool init)
1029 struct lfsck_instance *lfsck = com->lc_lfsck;
1030 struct lfsck_namespace *ns =
1031 (struct lfsck_namespace *)com->lc_file_ram;
1034 down_write(&com->lc_sem);
1036 spin_lock(&lfsck->li_lock);
1038 ns->ln_pos_last_checkpoint = lfsck->li_pos_current;
1040 ns->ln_status = LS_SCANNING_PHASE2;
1041 ns->ln_flags |= LF_SCANNED_ONCE;
1042 ns->ln_flags &= ~LF_UPGRADE;
1043 cfs_list_del_init(&com->lc_link);
1044 cfs_list_del_init(&com->lc_link_dir);
1045 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_double_scan);
1046 } else if (result == 0) {
1047 if (lfsck->li_paused) {
1048 ns->ln_status = LS_PAUSED;
1050 ns->ln_status = LS_STOPPED;
1051 cfs_list_del_init(&com->lc_link);
1052 cfs_list_del_init(&com->lc_link_dir);
1053 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
1056 ns->ln_status = LS_FAILED;
1057 cfs_list_del_init(&com->lc_link);
1058 cfs_list_del_init(&com->lc_link_dir);
1059 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
1061 spin_unlock(&lfsck->li_lock);
1064 ns->ln_run_time_phase1 += cfs_duration_sec(cfs_time_current() +
1065 HALF_SEC - lfsck->li_time_last_checkpoint);
1066 ns->ln_time_last_checkpoint = cfs_time_current_sec();
1067 ns->ln_items_checked += com->lc_new_checked;
1068 com->lc_new_checked = 0;
1071 rc = lfsck_namespace_store(env, com, false);
1073 up_write(&com->lc_sem);
1078 lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
1081 struct lfsck_instance *lfsck = com->lc_lfsck;
1082 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1083 struct lfsck_namespace *ns =
1084 (struct lfsck_namespace *)com->lc_file_ram;
1089 down_read(&com->lc_sem);
1090 rc = snprintf(buf, len,
1091 "name: lfsck_namespace\n"
1097 lfsck_status_names[ns->ln_status]);
1103 rc = lfsck_bits_dump(&buf, &len, ns->ln_flags, lfsck_flags_names,
1108 rc = lfsck_bits_dump(&buf, &len, bk->lb_param, lfsck_param_names,
1113 rc = lfsck_time_dump(&buf, &len, ns->ln_time_last_complete,
1114 "time_since_last_completed");
1118 rc = lfsck_time_dump(&buf, &len, ns->ln_time_latest_start,
1119 "time_since_latest_start");
1123 rc = lfsck_time_dump(&buf, &len, ns->ln_time_last_checkpoint,
1124 "time_since_last_checkpoint");
1128 rc = lfsck_pos_dump(&buf, &len, &ns->ln_pos_latest_start,
1129 "latest_start_position");
1133 rc = lfsck_pos_dump(&buf, &len, &ns->ln_pos_last_checkpoint,
1134 "last_checkpoint_position");
1138 rc = lfsck_pos_dump(&buf, &len, &ns->ln_pos_first_inconsistent,
1139 "first_failure_position");
1143 if (ns->ln_status == LS_SCANNING_PHASE1) {
1144 struct lfsck_position pos;
1145 const struct dt_it_ops *iops;
1146 cfs_duration_t duration = cfs_time_current() -
1147 lfsck->li_time_last_checkpoint;
1148 __u64 checked = ns->ln_items_checked + com->lc_new_checked;
1149 __u64 speed = checked;
1150 __u64 new_checked = com->lc_new_checked * CFS_HZ;
1151 __u32 rtime = ns->ln_run_time_phase1 +
1152 cfs_duration_sec(duration + HALF_SEC);
1155 do_div(new_checked, duration);
1157 do_div(speed, rtime);
1158 rc = snprintf(buf, len,
1159 "checked_phase1: "LPU64"\n"
1160 "checked_phase2: "LPU64"\n"
1161 "updated_phase1: "LPU64"\n"
1162 "updated_phase2: "LPU64"\n"
1163 "failed_phase1: "LPU64"\n"
1164 "failed_phase2: "LPU64"\n"
1166 "M-linked: "LPU64"\n"
1167 "nlinks_repaired: "LPU64"\n"
1168 "lost_found: "LPU64"\n"
1169 "success_count: %u\n"
1170 "run_time_phase1: %u seconds\n"
1171 "run_time_phase2: %u seconds\n"
1172 "average_speed_phase1: "LPU64" items/sec\n"
1173 "average_speed_phase2: N/A\n"
1174 "real-time_speed_phase1: "LPU64" items/sec\n"
1175 "real-time_speed_phase2: N/A\n",
1177 ns->ln_objs_checked_phase2,
1178 ns->ln_items_repaired,
1179 ns->ln_objs_repaired_phase2,
1180 ns->ln_items_failed,
1181 ns->ln_objs_failed_phase2,
1182 ns->ln_dirs_checked,
1183 ns->ln_mlinked_checked,
1184 ns->ln_objs_nlink_repaired,
1185 ns->ln_objs_lost_found,
1186 ns->ln_success_count,
1188 ns->ln_run_time_phase2,
1197 LASSERT(lfsck->li_di_oit != NULL);
1199 iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
1201 /* The low layer otable-based iteration position may NOT
1202 * exactly match the namespace-based directory traversal
1203 * cookie. Generally, it is not a serious issue. But the
1204 * caller should NOT make assumption on that. */
1205 pos.lp_oit_cookie = iops->store(env, lfsck->li_di_oit);
1206 if (!lfsck->li_current_oit_processed)
1207 pos.lp_oit_cookie--;
1209 spin_lock(&lfsck->li_lock);
1210 if (lfsck->li_di_dir != NULL) {
1211 pos.lp_dir_cookie = lfsck->li_cookie_dir;
1212 if (pos.lp_dir_cookie >= MDS_DIR_END_OFF) {
1213 fid_zero(&pos.lp_dir_parent);
1214 pos.lp_dir_cookie = 0;
1217 *lu_object_fid(&lfsck->li_obj_dir->do_lu);
1220 fid_zero(&pos.lp_dir_parent);
1221 pos.lp_dir_cookie = 0;
1223 spin_unlock(&lfsck->li_lock);
1224 rc = lfsck_pos_dump(&buf, &len, &pos, "current_position");
1227 } else if (ns->ln_status == LS_SCANNING_PHASE2) {
1228 cfs_duration_t duration = cfs_time_current() -
1229 lfsck->li_time_last_checkpoint;
1230 __u64 checked = ns->ln_objs_checked_phase2 +
1231 com->lc_new_checked;
1232 __u64 speed1 = ns->ln_items_checked;
1233 __u64 speed2 = checked;
1234 __u64 new_checked = com->lc_new_checked * CFS_HZ;
1235 __u32 rtime = ns->ln_run_time_phase2 +
1236 cfs_duration_sec(duration + HALF_SEC);
1239 do_div(new_checked, duration);
1240 if (ns->ln_run_time_phase1 != 0)
1241 do_div(speed1, ns->ln_run_time_phase1);
1243 do_div(speed2, rtime);
1244 rc = snprintf(buf, len,
1245 "checked_phase1: "LPU64"\n"
1246 "checked_phase2: "LPU64"\n"
1247 "updated_phase1: "LPU64"\n"
1248 "updated_phase2: "LPU64"\n"
1249 "failed_phase1: "LPU64"\n"
1250 "failed_phase2: "LPU64"\n"
1252 "M-linked: "LPU64"\n"
1253 "nlinks_repaired: "LPU64"\n"
1254 "lost_found: "LPU64"\n"
1255 "success_count: %u\n"
1256 "run_time_phase1: %u seconds\n"
1257 "run_time_phase2: %u seconds\n"
1258 "average_speed_phase1: "LPU64" items/sec\n"
1259 "average_speed_phase2: "LPU64" objs/sec\n"
1260 "real-time_speed_phase1: N/A\n"
1261 "real-time_speed_phase2: "LPU64" objs/sec\n"
1262 "current_position: "DFID"\n",
1263 ns->ln_items_checked,
1265 ns->ln_items_repaired,
1266 ns->ln_objs_repaired_phase2,
1267 ns->ln_items_failed,
1268 ns->ln_objs_failed_phase2,
1269 ns->ln_dirs_checked,
1270 ns->ln_mlinked_checked,
1271 ns->ln_objs_nlink_repaired,
1272 ns->ln_objs_lost_found,
1273 ns->ln_success_count,
1274 ns->ln_run_time_phase1,
1279 PFID(&ns->ln_fid_latest_scanned_phase2));
1286 __u64 speed1 = ns->ln_items_checked;
1287 __u64 speed2 = ns->ln_objs_checked_phase2;
1289 if (ns->ln_run_time_phase1 != 0)
1290 do_div(speed1, ns->ln_run_time_phase1);
1291 if (ns->ln_run_time_phase2 != 0)
1292 do_div(speed2, ns->ln_run_time_phase2);
1293 rc = snprintf(buf, len,
1294 "checked_phase1: "LPU64"\n"
1295 "checked_phase2: "LPU64"\n"
1296 "updated_phase1: "LPU64"\n"
1297 "updated_phase2: "LPU64"\n"
1298 "failed_phase1: "LPU64"\n"
1299 "failed_phase2: "LPU64"\n"
1301 "M-linked: "LPU64"\n"
1302 "nlinks_repaired: "LPU64"\n"
1303 "lost_found: "LPU64"\n"
1304 "success_count: %u\n"
1305 "run_time_phase1: %u seconds\n"
1306 "run_time_phase2: %u seconds\n"
1307 "average_speed_phase1: "LPU64" items/sec\n"
1308 "average_speed_phase2: "LPU64" objs/sec\n"
1309 "real-time_speed_phase1: N/A\n"
1310 "real-time_speed_phase2: N/A\n"
1311 "current_position: N/A\n",
1312 ns->ln_items_checked,
1313 ns->ln_objs_checked_phase2,
1314 ns->ln_items_repaired,
1315 ns->ln_objs_repaired_phase2,
1316 ns->ln_items_failed,
1317 ns->ln_objs_failed_phase2,
1318 ns->ln_dirs_checked,
1319 ns->ln_mlinked_checked,
1320 ns->ln_objs_nlink_repaired,
1321 ns->ln_objs_lost_found,
1322 ns->ln_success_count,
1323 ns->ln_run_time_phase1,
1324 ns->ln_run_time_phase2,
1336 up_read(&com->lc_sem);
1340 static int lfsck_namespace_double_scan(const struct lu_env *env,
1341 struct lfsck_component *com)
1343 struct lfsck_instance *lfsck = com->lc_lfsck;
1344 struct ptlrpc_thread *thread = &lfsck->li_thread;
1345 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1346 struct lfsck_namespace *ns =
1347 (struct lfsck_namespace *)com->lc_file_ram;
1348 struct dt_object *obj = com->lc_obj;
1349 const struct dt_it_ops *iops = &obj->do_index_ops->dio_it;
1350 struct dt_object *target;
1358 lfsck->li_new_scanned = 0;
1359 lfsck->li_time_last_checkpoint = cfs_time_current();
1360 lfsck->li_time_next_checkpoint = lfsck->li_time_last_checkpoint +
1361 cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
1363 di = iops->init(env, obj, 0, BYPASS_CAPA);
1365 RETURN(PTR_ERR(di));
1367 fid_cpu_to_be(&fid, &ns->ln_fid_latest_scanned_phase2);
1368 rc = iops->get(env, di, (const struct dt_key *)&fid);
1372 /* Skip the start one, which either has been processed or non-exist. */
1373 rc = iops->next(env, di);
1377 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_DOUBLESCAN))
1381 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DELAY3) &&
1383 struct l_wait_info lwi;
1385 lwi = LWI_TIMEOUT(cfs_time_seconds(cfs_fail_val),
1387 l_wait_event(thread->t_ctl_waitq,
1388 !thread_is_running(thread),
1392 key = iops->key(env, di);
1393 fid_be_to_cpu(&fid, (const struct lu_fid *)key);
1394 target = lfsck_object_find(env, lfsck, &fid);
1395 down_write(&com->lc_sem);
1396 if (target == NULL) {
1399 } else if (IS_ERR(target)) {
1400 rc = PTR_ERR(target);
1404 /* XXX: Currently, skip remote object, the consistency for
1405 * remote object will be processed in LFSCK phase III. */
1406 if (dt_object_exists(target) && !dt_object_remote(target)) {
1407 rc = iops->rec(env, di, (struct dt_rec *)&flags, 0);
1409 rc = lfsck_namespace_double_scan_one(env, com,
1413 lfsck_object_put(env, target);
1416 lfsck->li_new_scanned++;
1417 com->lc_new_checked++;
1418 ns->ln_fid_latest_scanned_phase2 = fid;
1420 ns->ln_objs_repaired_phase2++;
1422 ns->ln_objs_failed_phase2++;
1423 up_write(&com->lc_sem);
1425 if ((rc == 0) || ((rc > 0) && !(bk->lb_param & LPF_DRYRUN))) {
1426 lfsck_namespace_delete(env, com, &fid);
1427 } else if (rc < 0) {
1428 flags |= LLF_REPAIR_FAILED;
1429 lfsck_namespace_update(env, com, &fid, flags, true);
1432 if (rc < 0 && bk->lb_param & LPF_FAILOUT)
1435 if (unlikely(cfs_time_beforeq(lfsck->li_time_next_checkpoint,
1436 cfs_time_current())) &&
1437 com->lc_new_checked != 0) {
1438 down_write(&com->lc_sem);
1439 ns->ln_run_time_phase2 +=
1440 cfs_duration_sec(cfs_time_current() +
1441 HALF_SEC - lfsck->li_time_last_checkpoint);
1442 ns->ln_time_last_checkpoint = cfs_time_current_sec();
1443 ns->ln_objs_checked_phase2 += com->lc_new_checked;
1444 com->lc_new_checked = 0;
1445 rc = lfsck_namespace_store(env, com, false);
1446 up_write(&com->lc_sem);
1450 lfsck->li_time_last_checkpoint = cfs_time_current();
1451 lfsck->li_time_next_checkpoint =
1452 lfsck->li_time_last_checkpoint +
1453 cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
1456 lfsck_control_speed(lfsck);
1457 if (unlikely(!thread_is_running(thread)))
1460 rc = iops->next(env, di);
1469 iops->fini(env, di);
1470 down_write(&com->lc_sem);
1472 ns->ln_run_time_phase2 += cfs_duration_sec(cfs_time_current() +
1473 HALF_SEC - lfsck->li_time_last_checkpoint);
1474 ns->ln_time_last_checkpoint = cfs_time_current_sec();
1475 ns->ln_objs_checked_phase2 += com->lc_new_checked;
1476 com->lc_new_checked = 0;
1479 com->lc_journal = 0;
1480 ns->ln_status = LS_COMPLETED;
1481 if (!(bk->lb_param & LPF_DRYRUN))
1483 ~(LF_SCANNED_ONCE | LF_INCONSISTENT | LF_UPGRADE);
1484 ns->ln_time_last_complete = ns->ln_time_last_checkpoint;
1485 ns->ln_success_count++;
1486 } else if (rc == 0) {
1487 if (lfsck->li_paused)
1488 ns->ln_status = LS_PAUSED;
1490 ns->ln_status = LS_STOPPED;
1492 ns->ln_status = LS_FAILED;
1495 if (ns->ln_status != LS_PAUSED) {
1496 spin_lock(&lfsck->li_lock);
1497 cfs_list_del_init(&com->lc_link);
1498 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
1499 spin_unlock(&lfsck->li_lock);
1502 rc = lfsck_namespace_store(env, com, false);
1504 up_write(&com->lc_sem);
1508 static struct lfsck_operations lfsck_namespace_ops = {
1509 .lfsck_reset = lfsck_namespace_reset,
1510 .lfsck_fail = lfsck_namespace_fail,
1511 .lfsck_checkpoint = lfsck_namespace_checkpoint,
1512 .lfsck_prep = lfsck_namespace_prep,
1513 .lfsck_exec_oit = lfsck_namespace_exec_oit,
1514 .lfsck_exec_dir = lfsck_namespace_exec_dir,
1515 .lfsck_post = lfsck_namespace_post,
1516 .lfsck_dump = lfsck_namespace_dump,
1517 .lfsck_double_scan = lfsck_namespace_double_scan,
1520 int lfsck_namespace_setup(const struct lu_env *env,
1521 struct lfsck_instance *lfsck)
1523 struct lfsck_component *com;
1524 struct lfsck_namespace *ns;
1525 struct dt_object *obj;
1529 LASSERT(lfsck->li_master);
1535 CFS_INIT_LIST_HEAD(&com->lc_link);
1536 CFS_INIT_LIST_HEAD(&com->lc_link_dir);
1537 init_rwsem(&com->lc_sem);
1538 atomic_set(&com->lc_ref, 1);
1539 com->lc_lfsck = lfsck;
1540 com->lc_type = LT_NAMESPACE;
1541 com->lc_ops = &lfsck_namespace_ops;
1542 com->lc_file_size = sizeof(struct lfsck_namespace);
1543 OBD_ALLOC(com->lc_file_ram, com->lc_file_size);
1544 if (com->lc_file_ram == NULL)
1545 GOTO(out, rc = -ENOMEM);
1547 OBD_ALLOC(com->lc_file_disk, com->lc_file_size);
1548 if (com->lc_file_disk == NULL)
1549 GOTO(out, rc = -ENOMEM);
1551 obj = local_index_find_or_create(env, lfsck->li_los,
1552 lfsck->li_local_root,
1553 lfsck_namespace_name,
1554 S_IFREG | S_IRUGO | S_IWUSR,
1555 &dt_lfsck_features);
1557 GOTO(out, rc = PTR_ERR(obj));
1560 rc = obj->do_ops->do_index_try(env, obj, &dt_lfsck_features);
1564 rc = lfsck_namespace_load(env, com);
1566 rc = lfsck_namespace_reset(env, com, true);
1567 else if (rc == -ENODATA)
1568 rc = lfsck_namespace_init(env, com);
1572 ns = (struct lfsck_namespace *)com->lc_file_ram;
1573 switch (ns->ln_status) {
1578 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
1581 CERROR("%s: unknown lfsck_namespace status: %u\n",
1582 lfsck_lfsck2name(lfsck), ns->ln_status);
1584 case LS_SCANNING_PHASE1:
1585 case LS_SCANNING_PHASE2:
1586 /* No need to store the status to disk right now.
1587 * If the system crashed before the status stored,
1588 * it will be loaded back when next time. */
1589 ns->ln_status = LS_CRASHED;
1593 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_scan);
1594 cfs_list_add_tail(&com->lc_link_dir, &lfsck->li_list_dir);
1602 lfsck_component_cleanup(env, com);