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>
32 # define EXPORT_SYMTAB
34 #define DEBUG_SUBSYSTEM S_LFSCK
36 #include <lustre/lustre_idl.h>
37 #include <lu_object.h>
38 #include <dt_object.h>
39 #include <md_object.h>
40 #include <lustre_linkea.h>
41 #include <lustre_fid.h>
42 #include <lustre_lib.h>
43 #include <lustre_net.h>
44 #include <lustre/lustre_user.h>
46 #include "lfsck_internal.h"
48 #define LFSCK_NAMESPACE_MAGIC 0xA0629D03
50 static const char lfsck_namespace_name[] = "lfsck_namespace";
52 static void lfsck_namespace_le_to_cpu(struct lfsck_namespace *des,
53 struct lfsck_namespace *src)
55 des->ln_magic = le32_to_cpu(src->ln_magic);
56 des->ln_status = le32_to_cpu(src->ln_status);
57 des->ln_flags = le32_to_cpu(src->ln_flags);
58 des->ln_success_count = le32_to_cpu(src->ln_success_count);
59 des->ln_run_time_phase1 = le32_to_cpu(src->ln_run_time_phase1);
60 des->ln_run_time_phase2 = le32_to_cpu(src->ln_run_time_phase2);
61 des->ln_time_last_complete = le64_to_cpu(src->ln_time_last_complete);
62 des->ln_time_latest_start = le64_to_cpu(src->ln_time_latest_start);
63 des->ln_time_last_checkpoint =
64 le64_to_cpu(src->ln_time_last_checkpoint);
65 lfsck_position_le_to_cpu(&des->ln_pos_latest_start,
66 &src->ln_pos_latest_start);
67 lfsck_position_le_to_cpu(&des->ln_pos_last_checkpoint,
68 &src->ln_pos_last_checkpoint);
69 lfsck_position_le_to_cpu(&des->ln_pos_first_inconsistent,
70 &src->ln_pos_first_inconsistent);
71 des->ln_items_checked = le64_to_cpu(src->ln_items_checked);
72 des->ln_items_repaired = le64_to_cpu(src->ln_items_repaired);
73 des->ln_items_failed = le64_to_cpu(src->ln_items_failed);
74 des->ln_dirs_checked = le64_to_cpu(src->ln_dirs_checked);
75 des->ln_mlinked_checked = le64_to_cpu(src->ln_mlinked_checked);
76 des->ln_objs_checked_phase2 = le64_to_cpu(src->ln_objs_checked_phase2);
77 des->ln_objs_repaired_phase2 =
78 le64_to_cpu(src->ln_objs_repaired_phase2);
79 des->ln_objs_failed_phase2 = le64_to_cpu(src->ln_objs_failed_phase2);
80 des->ln_objs_nlink_repaired = le64_to_cpu(src->ln_objs_nlink_repaired);
81 des->ln_objs_lost_found = le64_to_cpu(src->ln_objs_lost_found);
82 fid_le_to_cpu(&des->ln_fid_latest_scanned_phase2,
83 &src->ln_fid_latest_scanned_phase2);
86 static void lfsck_namespace_cpu_to_le(struct lfsck_namespace *des,
87 struct lfsck_namespace *src)
89 des->ln_magic = cpu_to_le32(src->ln_magic);
90 des->ln_status = cpu_to_le32(src->ln_status);
91 des->ln_flags = cpu_to_le32(src->ln_flags);
92 des->ln_success_count = cpu_to_le32(src->ln_success_count);
93 des->ln_run_time_phase1 = cpu_to_le32(src->ln_run_time_phase1);
94 des->ln_run_time_phase2 = cpu_to_le32(src->ln_run_time_phase2);
95 des->ln_time_last_complete = cpu_to_le64(src->ln_time_last_complete);
96 des->ln_time_latest_start = cpu_to_le64(src->ln_time_latest_start);
97 des->ln_time_last_checkpoint =
98 cpu_to_le64(src->ln_time_last_checkpoint);
99 lfsck_position_cpu_to_le(&des->ln_pos_latest_start,
100 &src->ln_pos_latest_start);
101 lfsck_position_cpu_to_le(&des->ln_pos_last_checkpoint,
102 &src->ln_pos_last_checkpoint);
103 lfsck_position_cpu_to_le(&des->ln_pos_first_inconsistent,
104 &src->ln_pos_first_inconsistent);
105 des->ln_items_checked = cpu_to_le64(src->ln_items_checked);
106 des->ln_items_repaired = cpu_to_le64(src->ln_items_repaired);
107 des->ln_items_failed = cpu_to_le64(src->ln_items_failed);
108 des->ln_dirs_checked = cpu_to_le64(src->ln_dirs_checked);
109 des->ln_mlinked_checked = cpu_to_le64(src->ln_mlinked_checked);
110 des->ln_objs_checked_phase2 = cpu_to_le64(src->ln_objs_checked_phase2);
111 des->ln_objs_repaired_phase2 =
112 cpu_to_le64(src->ln_objs_repaired_phase2);
113 des->ln_objs_failed_phase2 = cpu_to_le64(src->ln_objs_failed_phase2);
114 des->ln_objs_nlink_repaired = cpu_to_le64(src->ln_objs_nlink_repaired);
115 des->ln_objs_lost_found = cpu_to_le64(src->ln_objs_lost_found);
116 fid_cpu_to_le(&des->ln_fid_latest_scanned_phase2,
117 &src->ln_fid_latest_scanned_phase2);
121 * \retval +ve: the lfsck_namespace is broken, the caller should reset it.
122 * \retval 0: succeed.
123 * \retval -ve: failed cases.
125 static int lfsck_namespace_load(const struct lu_env *env,
126 struct lfsck_component *com)
128 int len = com->lc_file_size;
131 rc = dt_xattr_get(env, com->lc_obj,
132 lfsck_buf_get(env, com->lc_file_disk, len),
133 XATTR_NAME_LFSCK_NAMESPACE, BYPASS_CAPA);
135 struct lfsck_namespace *ns = com->lc_file_ram;
137 lfsck_namespace_le_to_cpu(ns,
138 (struct lfsck_namespace *)com->lc_file_disk);
139 if (ns->ln_magic != LFSCK_NAMESPACE_MAGIC) {
140 CWARN("%.16s: invalid lfsck_namespace magic "
142 lfsck_lfsck2name(com->lc_lfsck),
143 ns->ln_magic, LFSCK_NAMESPACE_MAGIC);
148 } else if (rc != -ENODATA) {
149 CERROR("%.16s: fail to load lfsck_namespace, expected = %d, "
150 "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck), len, rc);
157 static int lfsck_namespace_store(const struct lu_env *env,
158 struct lfsck_component *com, bool init)
160 struct dt_object *obj = com->lc_obj;
161 struct lfsck_instance *lfsck = com->lc_lfsck;
162 struct thandle *handle;
163 int len = com->lc_file_size;
167 lfsck_namespace_cpu_to_le((struct lfsck_namespace *)com->lc_file_disk,
168 (struct lfsck_namespace *)com->lc_file_ram);
169 handle = dt_trans_create(env, lfsck->li_bottom);
170 if (IS_ERR(handle)) {
171 rc = PTR_ERR(handle);
172 CERROR("%.16s: fail to create trans for storing "
173 "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
177 rc = dt_declare_xattr_set(env, obj,
178 lfsck_buf_get(env, com->lc_file_disk, len),
179 XATTR_NAME_LFSCK_NAMESPACE, 0, handle);
181 CERROR("%.16s: fail to declare trans for storing "
182 "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
186 rc = dt_trans_start_local(env, lfsck->li_bottom, handle);
188 CERROR("%.16s: fail to start trans for storing "
189 "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
193 rc = dt_xattr_set(env, obj,
194 lfsck_buf_get(env, com->lc_file_disk, len),
195 XATTR_NAME_LFSCK_NAMESPACE,
196 init ? LU_XATTR_CREATE : LU_XATTR_REPLACE,
197 handle, BYPASS_CAPA);
199 CERROR("%.16s: fail to store lfsck_namespace, len = %d, "
200 "rc = %d\n", lfsck_lfsck2name(lfsck), len, rc);
205 dt_trans_stop(env, lfsck->li_bottom, handle);
209 static int lfsck_namespace_init(const struct lu_env *env,
210 struct lfsck_component *com)
212 struct lfsck_namespace *ns = (struct lfsck_namespace *)com->lc_file_ram;
215 memset(ns, 0, sizeof(*ns));
216 ns->ln_magic = LFSCK_NAMESPACE_MAGIC;
217 ns->ln_status = LS_INIT;
218 down_write(&com->lc_sem);
219 rc = lfsck_namespace_store(env, com, true);
220 up_write(&com->lc_sem);
224 static int lfsck_namespace_lookup(const struct lu_env *env,
225 struct lfsck_component *com,
226 const struct lu_fid *fid, __u8 *flags)
228 struct lu_fid *key = &lfsck_env_info(env)->lti_fid;
231 fid_cpu_to_be(key, fid);
232 rc = dt_lookup(env, com->lc_obj, (struct dt_rec *)flags,
233 (const struct dt_key *)key, BYPASS_CAPA);
237 static int lfsck_namespace_delete(const struct lu_env *env,
238 struct lfsck_component *com,
239 const struct lu_fid *fid)
241 struct lfsck_instance *lfsck = com->lc_lfsck;
242 struct lu_fid *key = &lfsck_env_info(env)->lti_fid;
243 struct thandle *handle;
244 struct dt_object *obj = com->lc_obj;
248 handle = dt_trans_create(env, lfsck->li_bottom);
250 RETURN(PTR_ERR(handle));
252 rc = dt_declare_delete(env, obj, (const struct dt_key *)fid, handle);
256 rc = dt_trans_start_local(env, lfsck->li_bottom, handle);
260 fid_cpu_to_be(key, fid);
261 rc = dt_delete(env, obj, (const struct dt_key *)key, handle,
267 dt_trans_stop(env, lfsck->li_bottom, handle);
271 static int lfsck_namespace_update(const struct lu_env *env,
272 struct lfsck_component *com,
273 const struct lu_fid *fid,
274 __u8 flags, bool force)
276 struct lfsck_instance *lfsck = com->lc_lfsck;
277 struct lu_fid *key = &lfsck_env_info(env)->lti_fid;
278 struct thandle *handle;
279 struct dt_object *obj = com->lc_obj;
285 rc = lfsck_namespace_lookup(env, com, fid, &tf);
286 if (rc != 0 && rc != -ENOENT)
290 if (!force || flags == tf)
294 handle = dt_trans_create(env, lfsck->li_bottom);
296 RETURN(PTR_ERR(handle));
298 rc = dt_declare_delete(env, obj, (const struct dt_key *)fid,
303 handle = dt_trans_create(env, lfsck->li_bottom);
305 RETURN(PTR_ERR(handle));
308 rc = dt_declare_insert(env, obj, (const struct dt_rec *)&flags,
309 (const struct dt_key *)fid, handle);
313 rc = dt_trans_start_local(env, lfsck->li_bottom, handle);
317 fid_cpu_to_be(key, fid);
319 rc = dt_delete(env, obj, (const struct dt_key *)key, handle,
322 CERROR("%s: fail to insert "DFID", rc = %d\n",
323 lfsck_lfsck2name(com->lc_lfsck), PFID(fid), rc);
328 rc = dt_insert(env, obj, (const struct dt_rec *)&flags,
329 (const struct dt_key *)key, handle, BYPASS_CAPA, 1);
334 dt_trans_stop(env, lfsck->li_bottom, handle);
338 static int lfsck_namespace_check_exist(const struct lu_env *env,
339 struct lfsck_instance *lfsck,
340 struct dt_object *obj, const char *name)
342 struct dt_object *dir = lfsck->li_obj_dir;
343 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
347 if (unlikely(lfsck_is_dead_obj(obj)))
348 RETURN(LFSCK_NAMEENTRY_DEAD);
350 rc = dt_lookup(env, dir, (struct dt_rec *)fid,
351 (const struct dt_key *)name, BYPASS_CAPA);
353 RETURN(LFSCK_NAMEENTRY_REMOVED);
358 if (!lu_fid_eq(fid, lfsck_dto2fid(obj)))
359 RETURN(LFSCK_NAMEENTRY_RECREATED);
364 static int lfsck_declare_namespace_exec_dir(const struct lu_env *env,
365 struct dt_object *obj,
366 struct thandle *handle)
370 /* For destroying all invalid linkEA entries. */
371 rc = dt_declare_xattr_del(env, obj, XATTR_NAME_LINK, handle);
375 /* For insert new linkEA entry. */
376 rc = dt_declare_xattr_set(env, obj,
377 lfsck_buf_get_const(env, NULL, DEFAULT_LINKEA_SIZE),
378 XATTR_NAME_LINK, 0, handle);
382 static int lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
383 struct linkea_data *ldata)
388 lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
390 if (ldata->ld_buf->lb_buf == NULL)
393 if (!dt_object_exists(obj))
396 rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK, BYPASS_CAPA);
398 /* Buf was too small, figure out what we need. */
399 lu_buf_free(ldata->ld_buf);
400 rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK,
405 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
406 if (ldata->ld_buf->lb_buf == NULL)
409 rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK,
420 static int lfsck_links_write(const struct lu_env *env, struct dt_object *obj,
421 struct linkea_data *ldata, struct thandle *handle)
423 const struct lu_buf *buf = lfsck_buf_get_const(env,
424 ldata->ld_buf->lb_buf,
425 ldata->ld_leh->leh_len);
427 return dt_xattr_set(env, obj, buf, XATTR_NAME_LINK, 0, handle,
432 * \retval ve: removed entries
434 static int lfsck_linkea_entry_unpack(struct lfsck_instance *lfsck,
435 struct linkea_data *ldata,
436 struct lu_name *cname,
439 struct link_ea_entry *oldlee;
443 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, cname, pfid);
444 oldlee = ldata->ld_lee;
445 oldlen = ldata->ld_reclen;
446 linkea_next_entry(ldata);
447 while (ldata->ld_lee != NULL) {
448 ldata->ld_reclen = (ldata->ld_lee->lee_reclen[0] << 8) |
449 ldata->ld_lee->lee_reclen[1];
450 if (unlikely(ldata->ld_reclen == oldlen &&
451 memcmp(ldata->ld_lee, oldlee, oldlen) == 0)) {
452 linkea_del_buf(ldata, cname);
455 linkea_next_entry(ldata);
458 ldata->ld_lee = oldlee;
459 ldata->ld_reclen = oldlen;
464 * \retval +ve repaired
465 * \retval 0 no need to repair
466 * \retval -ve error cases
468 static int lfsck_namespace_double_scan_one(const struct lu_env *env,
469 struct lfsck_component *com,
470 struct dt_object *child, __u8 flags)
472 struct lfsck_thread_info *info = lfsck_env_info(env);
473 struct lu_attr *la = &info->lti_la;
474 struct lu_name *cname = &info->lti_name;
475 struct lu_fid *pfid = &info->lti_fid;
476 struct lu_fid *cfid = &info->lti_fid2;
477 struct lfsck_instance *lfsck = com->lc_lfsck;
478 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
479 struct lfsck_namespace *ns =
480 (struct lfsck_namespace *)com->lc_file_ram;
481 struct linkea_data ldata = { 0 };
482 struct thandle *handle = NULL;
488 if (com->lc_journal) {
495 handle = dt_trans_create(env, lfsck->li_next);
497 RETURN(rc = PTR_ERR(handle));
499 rc = dt_declare_xattr_set(env, child,
500 lfsck_buf_get_const(env, NULL, DEFAULT_LINKEA_SIZE),
501 XATTR_NAME_LINK, 0, handle);
505 rc = dt_trans_start(env, lfsck->li_next, handle);
509 dt_write_lock(env, child, MOR_TGT_CHILD);
513 if (unlikely(lfsck_is_dead_obj(child)))
516 rc = dt_attr_get(env, child, la, BYPASS_CAPA);
518 rc = lfsck_links_read(env, child, &ldata);
520 if ((bk->lb_param & LPF_DRYRUN) &&
521 (rc == -EINVAL || rc == -ENODATA))
527 linkea_first_entry(&ldata);
528 while (ldata.ld_lee != NULL) {
529 struct dt_object *parent = NULL;
531 rc = lfsck_linkea_entry_unpack(lfsck, &ldata, cname, pfid);
535 if (!fid_is_sane(pfid))
538 parent = lfsck_object_find(env, lfsck, pfid);
541 else if (IS_ERR(parent))
542 GOTO(stop, rc = PTR_ERR(parent));
544 if (!dt_object_exists(parent))
547 /* XXX: Currently, skip remote object, the consistency for
548 * remote object will be processed in LFSCK phase III. */
549 if (dt_object_remote(parent)) {
550 lfsck_object_put(env, parent);
551 linkea_next_entry(&ldata);
555 if (unlikely(!dt_try_as_dir(env, parent)))
558 /* To guarantee the 'name' is terminated with '0'. */
559 memcpy(info->lti_key, cname->ln_name, cname->ln_namelen);
560 info->lti_key[cname->ln_namelen] = 0;
561 cname->ln_name = info->lti_key;
562 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
563 (const struct dt_key *)cname->ln_name,
565 if (rc != 0 && rc != -ENOENT) {
566 lfsck_object_put(env, parent);
571 if (lu_fid_eq(cfid, lfsck_dto2fid(child))) {
572 lfsck_object_put(env, parent);
573 linkea_next_entry(&ldata);
580 /* If there is no name entry in the parent dir and the object
581 * link count is less than the linkea entries count, then the
582 * linkea entry should be removed. */
583 if (ldata.ld_leh->leh_reccount > la->la_nlink)
586 /* XXX: For the case of there is a linkea entry, but without
587 * name entry pointing to the object and its hard links
588 * count is not less than the object name entries count,
589 * then seems we should add the 'missed' name entry back
590 * to namespace, but before LFSCK phase III finished, we
591 * do not know whether the object has some inconsistency
592 * on other MDTs. So now, do NOT add the name entry back
593 * to the namespace, but keep the linkEA entry. LU-2914 */
594 lfsck_object_put(env, parent);
595 linkea_next_entry(&ldata);
600 lfsck_object_put(env, parent);
601 if (bk->lb_param & LPF_DRYRUN)
604 CDEBUG(D_LFSCK, "Remove linkEA: "DFID"[%.*s], "DFID"\n",
605 PFID(lfsck_dto2fid(child)), cname->ln_namelen, cname->ln_name,
607 linkea_del_buf(&ldata, cname);
612 if (!com->lc_journal) {
617 rc = lfsck_links_write(env, child, &ldata, handle);
624 /* XXX: For the case linkea entries count does not match the object hard
625 * links count, we cannot update the later one simply. Before LFSCK
626 * phase III finished, we cannot know whether there are some remote
627 * name entries to be repaired or not. LU-2914 */
628 if (rc == 0 && !lfsck_is_dead_obj(child) &&
629 ldata.ld_leh != NULL &&
630 ldata.ld_leh->leh_reccount != la->la_nlink)
631 CWARN("%.16s: the object "DFID" linkEA entry count %u "
632 "may not match its hardlink count %u\n",
633 lfsck_lfsck2name(lfsck), PFID(cfid),
634 ldata.ld_leh->leh_reccount, la->la_nlink);
636 dt_write_unlock(env, child);
640 dt_trans_stop(env, lfsck->li_next, handle);
642 if (rc == 0 && update) {
643 ns->ln_objs_nlink_repaired++;
652 static int lfsck_namespace_reset(const struct lu_env *env,
653 struct lfsck_component *com, bool init)
655 struct lfsck_instance *lfsck = com->lc_lfsck;
656 struct lfsck_namespace *ns =
657 (struct lfsck_namespace *)com->lc_file_ram;
658 struct dt_object *dto;
662 down_write(&com->lc_sem);
664 memset(ns, 0, sizeof(*ns));
666 __u32 count = ns->ln_success_count;
667 __u64 last_time = ns->ln_time_last_complete;
669 memset(ns, 0, sizeof(*ns));
670 ns->ln_success_count = count;
671 ns->ln_time_last_complete = last_time;
673 ns->ln_magic = LFSCK_NAMESPACE_MAGIC;
674 ns->ln_status = LS_INIT;
676 rc = local_object_unlink(env, lfsck->li_bottom, lfsck->li_local_root,
677 lfsck_namespace_name);
681 dto = local_index_find_or_create(env, lfsck->li_los, lfsck->li_local_root,
682 lfsck_namespace_name,
683 S_IFREG | S_IRUGO | S_IWUSR,
686 GOTO(out, rc = PTR_ERR(dto));
689 rc = dto->do_ops->do_index_try(env, dto, &dt_lfsck_features);
693 rc = lfsck_namespace_store(env, com, true);
698 up_write(&com->lc_sem);
703 lfsck_namespace_fail(const struct lu_env *env, struct lfsck_component *com,
706 struct lfsck_namespace *ns = (struct lfsck_namespace *)com->lc_file_ram;
708 down_write(&com->lc_sem);
710 com->lc_new_checked++;
711 ns->ln_items_failed++;
712 if (lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent))
713 lfsck_pos_fill(env, com->lc_lfsck,
714 &ns->ln_pos_first_inconsistent, false);
715 up_write(&com->lc_sem);
718 static int lfsck_namespace_checkpoint(const struct lu_env *env,
719 struct lfsck_component *com, bool init)
721 struct lfsck_instance *lfsck = com->lc_lfsck;
722 struct lfsck_namespace *ns =
723 (struct lfsck_namespace *)com->lc_file_ram;
726 if (com->lc_new_checked == 0 && !init)
729 down_write(&com->lc_sem);
732 ns->ln_pos_latest_start = lfsck->li_pos_current;
734 ns->ln_pos_last_checkpoint = lfsck->li_pos_current;
735 ns->ln_run_time_phase1 += cfs_duration_sec(cfs_time_current() +
736 HALF_SEC - lfsck->li_time_last_checkpoint);
737 ns->ln_time_last_checkpoint = cfs_time_current_sec();
738 ns->ln_items_checked += com->lc_new_checked;
739 com->lc_new_checked = 0;
742 rc = lfsck_namespace_store(env, com, false);
744 up_write(&com->lc_sem);
748 static int lfsck_namespace_prep(const struct lu_env *env,
749 struct lfsck_component *com)
751 struct lfsck_instance *lfsck = com->lc_lfsck;
752 struct lfsck_namespace *ns =
753 (struct lfsck_namespace *)com->lc_file_ram;
754 struct lfsck_position *pos = &com->lc_pos_start;
756 if (ns->ln_status == LS_COMPLETED) {
759 rc = lfsck_namespace_reset(env, com, false);
764 down_write(&com->lc_sem);
766 ns->ln_time_latest_start = cfs_time_current_sec();
768 spin_lock(&lfsck->li_lock);
769 if (ns->ln_flags & LF_SCANNED_ONCE) {
770 if (!lfsck->li_drop_dryrun ||
771 lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent)) {
772 ns->ln_status = LS_SCANNING_PHASE2;
773 cfs_list_del_init(&com->lc_link);
774 cfs_list_add_tail(&com->lc_link,
775 &lfsck->li_list_double_scan);
776 if (!cfs_list_empty(&com->lc_link_dir))
777 cfs_list_del_init(&com->lc_link_dir);
778 lfsck_pos_set_zero(pos);
780 ns->ln_status = LS_SCANNING_PHASE1;
781 ns->ln_run_time_phase1 = 0;
782 ns->ln_run_time_phase2 = 0;
783 ns->ln_items_checked = 0;
784 ns->ln_items_repaired = 0;
785 ns->ln_items_failed = 0;
786 ns->ln_dirs_checked = 0;
787 ns->ln_mlinked_checked = 0;
788 ns->ln_objs_checked_phase2 = 0;
789 ns->ln_objs_repaired_phase2 = 0;
790 ns->ln_objs_failed_phase2 = 0;
791 ns->ln_objs_nlink_repaired = 0;
792 ns->ln_objs_lost_found = 0;
793 fid_zero(&ns->ln_fid_latest_scanned_phase2);
794 if (cfs_list_empty(&com->lc_link_dir))
795 cfs_list_add_tail(&com->lc_link_dir,
796 &lfsck->li_list_dir);
797 *pos = ns->ln_pos_first_inconsistent;
800 ns->ln_status = LS_SCANNING_PHASE1;
801 if (cfs_list_empty(&com->lc_link_dir))
802 cfs_list_add_tail(&com->lc_link_dir,
803 &lfsck->li_list_dir);
804 if (!lfsck->li_drop_dryrun ||
805 lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent)) {
806 *pos = ns->ln_pos_last_checkpoint;
807 pos->lp_oit_cookie++;
809 *pos = ns->ln_pos_first_inconsistent;
812 spin_unlock(&lfsck->li_lock);
814 up_write(&com->lc_sem);
818 static int lfsck_namespace_exec_oit(const struct lu_env *env,
819 struct lfsck_component *com,
820 struct dt_object *obj)
822 down_write(&com->lc_sem);
823 com->lc_new_checked++;
824 if (S_ISDIR(lfsck_object_type(obj)))
825 ((struct lfsck_namespace *)com->lc_file_ram)->ln_dirs_checked++;
826 up_write(&com->lc_sem);
830 static int lfsck_namespace_exec_dir(const struct lu_env *env,
831 struct lfsck_component *com,
832 struct dt_object *obj,
833 struct lu_dirent *ent)
835 struct lfsck_thread_info *info = lfsck_env_info(env);
836 struct lu_attr *la = &info->lti_la;
837 struct lfsck_instance *lfsck = com->lc_lfsck;
838 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
839 struct lfsck_namespace *ns =
840 (struct lfsck_namespace *)com->lc_file_ram;
841 struct linkea_data ldata = { 0 };
842 const struct lu_fid *pfid =
843 lu_object_fid(&lfsck->li_obj_dir->do_lu);
844 const struct lu_fid *cfid = lfsck_dto2fid(obj);
845 const struct lu_name *cname;
846 struct thandle *handle = NULL;
847 bool repaired = false;
855 cname = lfsck_name_get_const(env, ent->lde_name, ent->lde_namelen);
856 down_write(&com->lc_sem);
857 com->lc_new_checked++;
859 if (ent->lde_attrs & LUDA_UPGRADE) {
860 ns->ln_flags |= LF_UPGRADE;
862 } else if (ent->lde_attrs & LUDA_REPAIR) {
863 ns->ln_flags |= LF_INCONSISTENT;
867 if (ent->lde_name[0] == '.' &&
868 (ent->lde_namelen == 1 ||
869 (ent->lde_namelen == 2 && ent->lde_name[1] == '.') ||
870 fid_is_dot_lustre(&ent->lde_fid)))
873 if (!(bk->lb_param & LPF_DRYRUN) &&
874 (com->lc_journal || repaired)) {
880 handle = dt_trans_create(env, lfsck->li_next);
882 GOTO(out, rc = PTR_ERR(handle));
884 rc = lfsck_declare_namespace_exec_dir(env, obj, handle);
888 rc = dt_trans_start(env, lfsck->li_next, handle);
892 dt_write_lock(env, obj, MOR_TGT_CHILD);
896 rc = lfsck_namespace_check_exist(env, lfsck, obj, ent->lde_name);
900 rc = lfsck_links_read(env, obj, &ldata);
902 count = ldata.ld_leh->leh_reccount;
903 rc = linkea_links_find(&ldata, cname, pfid);
905 (count == 1 || !S_ISDIR(lfsck_object_type(obj))))
908 ns->ln_flags |= LF_INCONSISTENT;
909 /* For dir, if there are more than one linkea entries, or the
910 * linkea entry does not match the name entry, then remove all
911 * and add the correct one. */
912 if (S_ISDIR(lfsck_object_type(obj))) {
920 } else if (unlikely(rc == -EINVAL)) {
922 ns->ln_flags |= LF_INCONSISTENT;
923 /* The magic crashed, we are not sure whether there are more
924 * corrupt data in the linkea, so remove all linkea entries. */
928 } else if (rc == -ENODATA) {
930 ns->ln_flags |= LF_UPGRADE;
935 if (bk->lb_param & LPF_DRYRUN) {
940 if (!com->lc_journal)
946 rc = dt_xattr_del(env, obj, XATTR_NAME_LINK, handle,
953 rc = linkea_data_new(&ldata,
954 &lfsck_env_info(env)->lti_linkea_buf);
959 rc = linkea_add_buf(&ldata, cname, pfid);
963 rc = lfsck_links_write(env, obj, &ldata, handle);
967 count = ldata.ld_leh->leh_reccount;
976 rc = dt_attr_get(env, obj, la, BYPASS_CAPA);
981 (la->la_nlink == 1 || S_ISDIR(lfsck_object_type(obj))))
982 /* Usually, it is for single linked object or dir, do nothing.*/
985 /* Following modification will be in another transaction. */
986 if (handle != NULL) {
987 LASSERT(dt_write_locked(env, obj));
989 dt_write_unlock(env, obj);
992 dt_trans_stop(env, lfsck->li_next, handle);
996 ns->ln_mlinked_checked++;
997 rc = lfsck_namespace_update(env, com, cfid,
998 count != la->la_nlink ? LLF_UNMATCH_NLINKS : 0, false);
1004 dt_write_unlock(env, obj);
1007 dt_trans_stop(env, lfsck->li_next, handle);
1011 ns->ln_items_failed++;
1012 if (lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent))
1013 lfsck_pos_fill(env, lfsck,
1014 &ns->ln_pos_first_inconsistent, false);
1015 if (!(bk->lb_param & LPF_FAILOUT))
1019 ns->ln_items_repaired++;
1021 com->lc_journal = 0;
1024 up_write(&com->lc_sem);
1028 static int lfsck_namespace_post(const struct lu_env *env,
1029 struct lfsck_component *com,
1030 int result, bool init)
1032 struct lfsck_instance *lfsck = com->lc_lfsck;
1033 struct lfsck_namespace *ns =
1034 (struct lfsck_namespace *)com->lc_file_ram;
1037 down_write(&com->lc_sem);
1039 spin_lock(&lfsck->li_lock);
1041 ns->ln_pos_last_checkpoint = lfsck->li_pos_current;
1043 ns->ln_status = LS_SCANNING_PHASE2;
1044 ns->ln_flags |= LF_SCANNED_ONCE;
1045 ns->ln_flags &= ~LF_UPGRADE;
1046 cfs_list_del_init(&com->lc_link);
1047 cfs_list_del_init(&com->lc_link_dir);
1048 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_double_scan);
1049 } else if (result == 0) {
1050 if (lfsck->li_paused) {
1051 ns->ln_status = LS_PAUSED;
1053 ns->ln_status = LS_STOPPED;
1054 cfs_list_del_init(&com->lc_link);
1055 cfs_list_del_init(&com->lc_link_dir);
1056 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
1059 ns->ln_status = LS_FAILED;
1060 cfs_list_del_init(&com->lc_link);
1061 cfs_list_del_init(&com->lc_link_dir);
1062 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
1064 spin_unlock(&lfsck->li_lock);
1067 ns->ln_run_time_phase1 += cfs_duration_sec(cfs_time_current() +
1068 HALF_SEC - lfsck->li_time_last_checkpoint);
1069 ns->ln_time_last_checkpoint = cfs_time_current_sec();
1070 ns->ln_items_checked += com->lc_new_checked;
1071 com->lc_new_checked = 0;
1074 rc = lfsck_namespace_store(env, com, false);
1076 up_write(&com->lc_sem);
1081 lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
1084 struct lfsck_instance *lfsck = com->lc_lfsck;
1085 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1086 struct lfsck_namespace *ns =
1087 (struct lfsck_namespace *)com->lc_file_ram;
1092 down_read(&com->lc_sem);
1093 rc = snprintf(buf, len,
1094 "name: lfsck_namespace\n"
1100 lfsck_status_names[ns->ln_status]);
1106 rc = lfsck_bits_dump(&buf, &len, ns->ln_flags, lfsck_flags_names,
1111 rc = lfsck_bits_dump(&buf, &len, bk->lb_param, lfsck_param_names,
1116 rc = lfsck_time_dump(&buf, &len, ns->ln_time_last_complete,
1117 "time_since_last_completed");
1121 rc = lfsck_time_dump(&buf, &len, ns->ln_time_latest_start,
1122 "time_since_latest_start");
1126 rc = lfsck_time_dump(&buf, &len, ns->ln_time_last_checkpoint,
1127 "time_since_last_checkpoint");
1131 rc = lfsck_pos_dump(&buf, &len, &ns->ln_pos_latest_start,
1132 "latest_start_position");
1136 rc = lfsck_pos_dump(&buf, &len, &ns->ln_pos_last_checkpoint,
1137 "last_checkpoint_position");
1141 rc = lfsck_pos_dump(&buf, &len, &ns->ln_pos_first_inconsistent,
1142 "first_failure_position");
1146 if (ns->ln_status == LS_SCANNING_PHASE1) {
1147 struct lfsck_position pos;
1148 const struct dt_it_ops *iops;
1149 cfs_duration_t duration = cfs_time_current() -
1150 lfsck->li_time_last_checkpoint;
1151 __u64 checked = ns->ln_items_checked + com->lc_new_checked;
1152 __u64 speed = checked;
1153 __u64 new_checked = com->lc_new_checked * CFS_HZ;
1154 __u32 rtime = ns->ln_run_time_phase1 +
1155 cfs_duration_sec(duration + HALF_SEC);
1158 do_div(new_checked, duration);
1160 do_div(speed, rtime);
1161 rc = snprintf(buf, len,
1162 "checked_phase1: "LPU64"\n"
1163 "checked_phase2: "LPU64"\n"
1164 "updated_phase1: "LPU64"\n"
1165 "updated_phase2: "LPU64"\n"
1166 "failed_phase1: "LPU64"\n"
1167 "failed_phase2: "LPU64"\n"
1169 "M-linked: "LPU64"\n"
1170 "nlinks_repaired: "LPU64"\n"
1171 "lost_found: "LPU64"\n"
1172 "success_count: %u\n"
1173 "run_time_phase1: %u seconds\n"
1174 "run_time_phase2: %u seconds\n"
1175 "average_speed_phase1: "LPU64" items/sec\n"
1176 "average_speed_phase2: N/A\n"
1177 "real-time_speed_phase1: "LPU64" items/sec\n"
1178 "real-time_speed_phase2: N/A\n",
1180 ns->ln_objs_checked_phase2,
1181 ns->ln_items_repaired,
1182 ns->ln_objs_repaired_phase2,
1183 ns->ln_items_failed,
1184 ns->ln_objs_failed_phase2,
1185 ns->ln_dirs_checked,
1186 ns->ln_mlinked_checked,
1187 ns->ln_objs_nlink_repaired,
1188 ns->ln_objs_lost_found,
1189 ns->ln_success_count,
1191 ns->ln_run_time_phase2,
1200 LASSERT(lfsck->li_di_oit != NULL);
1202 iops = &lfsck->li_obj_oit->do_index_ops->dio_it;
1204 /* The low layer otable-based iteration position may NOT
1205 * exactly match the namespace-based directory traversal
1206 * cookie. Generally, it is not a serious issue. But the
1207 * caller should NOT make assumption on that. */
1208 pos.lp_oit_cookie = iops->store(env, lfsck->li_di_oit);
1209 if (!lfsck->li_current_oit_processed)
1210 pos.lp_oit_cookie--;
1212 spin_lock(&lfsck->li_lock);
1213 if (lfsck->li_di_dir != NULL) {
1214 pos.lp_dir_cookie = lfsck->li_cookie_dir;
1215 if (pos.lp_dir_cookie >= MDS_DIR_END_OFF) {
1216 fid_zero(&pos.lp_dir_parent);
1217 pos.lp_dir_cookie = 0;
1220 *lu_object_fid(&lfsck->li_obj_dir->do_lu);
1223 fid_zero(&pos.lp_dir_parent);
1224 pos.lp_dir_cookie = 0;
1226 spin_unlock(&lfsck->li_lock);
1227 rc = lfsck_pos_dump(&buf, &len, &pos, "current_position");
1230 } else if (ns->ln_status == LS_SCANNING_PHASE2) {
1231 cfs_duration_t duration = cfs_time_current() -
1232 lfsck->li_time_last_checkpoint;
1233 __u64 checked = ns->ln_objs_checked_phase2 +
1234 com->lc_new_checked;
1235 __u64 speed1 = ns->ln_items_checked;
1236 __u64 speed2 = checked;
1237 __u64 new_checked = com->lc_new_checked * CFS_HZ;
1238 __u32 rtime = ns->ln_run_time_phase2 +
1239 cfs_duration_sec(duration + HALF_SEC);
1242 do_div(new_checked, duration);
1243 if (ns->ln_run_time_phase1 != 0)
1244 do_div(speed1, ns->ln_run_time_phase1);
1246 do_div(speed2, rtime);
1247 rc = snprintf(buf, len,
1248 "checked_phase1: "LPU64"\n"
1249 "checked_phase2: "LPU64"\n"
1250 "updated_phase1: "LPU64"\n"
1251 "updated_phase2: "LPU64"\n"
1252 "failed_phase1: "LPU64"\n"
1253 "failed_phase2: "LPU64"\n"
1255 "M-linked: "LPU64"\n"
1256 "nlinks_repaired: "LPU64"\n"
1257 "lost_found: "LPU64"\n"
1258 "success_count: %u\n"
1259 "run_time_phase1: %u seconds\n"
1260 "run_time_phase2: %u seconds\n"
1261 "average_speed_phase1: "LPU64" items/sec\n"
1262 "average_speed_phase2: "LPU64" objs/sec\n"
1263 "real-time_speed_phase1: N/A\n"
1264 "real-time_speed_phase2: "LPU64" objs/sec\n"
1265 "current_position: "DFID"\n",
1266 ns->ln_items_checked,
1268 ns->ln_items_repaired,
1269 ns->ln_objs_repaired_phase2,
1270 ns->ln_items_failed,
1271 ns->ln_objs_failed_phase2,
1272 ns->ln_dirs_checked,
1273 ns->ln_mlinked_checked,
1274 ns->ln_objs_nlink_repaired,
1275 ns->ln_objs_lost_found,
1276 ns->ln_success_count,
1277 ns->ln_run_time_phase1,
1282 PFID(&ns->ln_fid_latest_scanned_phase2));
1289 __u64 speed1 = ns->ln_items_checked;
1290 __u64 speed2 = ns->ln_objs_checked_phase2;
1292 if (ns->ln_run_time_phase1 != 0)
1293 do_div(speed1, ns->ln_run_time_phase1);
1294 if (ns->ln_run_time_phase2 != 0)
1295 do_div(speed2, ns->ln_run_time_phase2);
1296 rc = snprintf(buf, len,
1297 "checked_phase1: "LPU64"\n"
1298 "checked_phase2: "LPU64"\n"
1299 "updated_phase1: "LPU64"\n"
1300 "updated_phase2: "LPU64"\n"
1301 "failed_phase1: "LPU64"\n"
1302 "failed_phase2: "LPU64"\n"
1304 "M-linked: "LPU64"\n"
1305 "nlinks_repaired: "LPU64"\n"
1306 "lost_found: "LPU64"\n"
1307 "success_count: %u\n"
1308 "run_time_phase1: %u seconds\n"
1309 "run_time_phase2: %u seconds\n"
1310 "average_speed_phase1: "LPU64" items/sec\n"
1311 "average_speed_phase2: "LPU64" objs/sec\n"
1312 "real-time_speed_phase1: N/A\n"
1313 "real-time_speed_phase2: N/A\n"
1314 "current_position: N/A\n",
1315 ns->ln_items_checked,
1316 ns->ln_objs_checked_phase2,
1317 ns->ln_items_repaired,
1318 ns->ln_objs_repaired_phase2,
1319 ns->ln_items_failed,
1320 ns->ln_objs_failed_phase2,
1321 ns->ln_dirs_checked,
1322 ns->ln_mlinked_checked,
1323 ns->ln_objs_nlink_repaired,
1324 ns->ln_objs_lost_found,
1325 ns->ln_success_count,
1326 ns->ln_run_time_phase1,
1327 ns->ln_run_time_phase2,
1339 up_read(&com->lc_sem);
1343 static int lfsck_namespace_double_scan(const struct lu_env *env,
1344 struct lfsck_component *com)
1346 struct lfsck_instance *lfsck = com->lc_lfsck;
1347 struct ptlrpc_thread *thread = &lfsck->li_thread;
1348 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1349 struct lfsck_namespace *ns =
1350 (struct lfsck_namespace *)com->lc_file_ram;
1351 struct dt_object *obj = com->lc_obj;
1352 const struct dt_it_ops *iops = &obj->do_index_ops->dio_it;
1353 struct dt_object *target;
1361 lfsck->li_new_scanned = 0;
1362 lfsck->li_time_last_checkpoint = cfs_time_current();
1363 lfsck->li_time_next_checkpoint = lfsck->li_time_last_checkpoint +
1364 cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
1366 di = iops->init(env, obj, 0, BYPASS_CAPA);
1368 RETURN(PTR_ERR(di));
1370 fid_cpu_to_be(&fid, &ns->ln_fid_latest_scanned_phase2);
1371 rc = iops->get(env, di, (const struct dt_key *)&fid);
1375 /* Skip the start one, which either has been processed or non-exist. */
1376 rc = iops->next(env, di);
1380 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_DOUBLESCAN))
1384 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DELAY3) &&
1386 struct l_wait_info lwi;
1388 lwi = LWI_TIMEOUT(cfs_time_seconds(cfs_fail_val),
1390 l_wait_event(thread->t_ctl_waitq,
1391 !thread_is_running(thread),
1395 key = iops->key(env, di);
1396 fid_be_to_cpu(&fid, (const struct lu_fid *)key);
1397 target = lfsck_object_find(env, lfsck, &fid);
1398 down_write(&com->lc_sem);
1399 if (target == NULL) {
1402 } else if (IS_ERR(target)) {
1403 rc = PTR_ERR(target);
1407 /* XXX: Currently, skip remote object, the consistency for
1408 * remote object will be processed in LFSCK phase III. */
1409 if (dt_object_exists(target) && !dt_object_remote(target)) {
1410 rc = iops->rec(env, di, (struct dt_rec *)&flags, 0);
1412 rc = lfsck_namespace_double_scan_one(env, com,
1416 lfsck_object_put(env, target);
1419 lfsck->li_new_scanned++;
1420 com->lc_new_checked++;
1421 ns->ln_fid_latest_scanned_phase2 = fid;
1423 ns->ln_objs_repaired_phase2++;
1425 ns->ln_objs_failed_phase2++;
1426 up_write(&com->lc_sem);
1428 if ((rc == 0) || ((rc > 0) && !(bk->lb_param & LPF_DRYRUN))) {
1429 lfsck_namespace_delete(env, com, &fid);
1430 } else if (rc < 0) {
1431 flags |= LLF_REPAIR_FAILED;
1432 lfsck_namespace_update(env, com, &fid, flags, true);
1435 if (rc < 0 && bk->lb_param & LPF_FAILOUT)
1438 if (unlikely(cfs_time_beforeq(lfsck->li_time_next_checkpoint,
1439 cfs_time_current())) &&
1440 com->lc_new_checked != 0) {
1441 down_write(&com->lc_sem);
1442 ns->ln_run_time_phase2 +=
1443 cfs_duration_sec(cfs_time_current() +
1444 HALF_SEC - lfsck->li_time_last_checkpoint);
1445 ns->ln_time_last_checkpoint = cfs_time_current_sec();
1446 ns->ln_objs_checked_phase2 += com->lc_new_checked;
1447 com->lc_new_checked = 0;
1448 rc = lfsck_namespace_store(env, com, false);
1449 up_write(&com->lc_sem);
1453 lfsck->li_time_last_checkpoint = cfs_time_current();
1454 lfsck->li_time_next_checkpoint =
1455 lfsck->li_time_last_checkpoint +
1456 cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
1459 lfsck_control_speed(lfsck);
1460 if (unlikely(!thread_is_running(thread)))
1463 rc = iops->next(env, di);
1472 iops->fini(env, di);
1473 down_write(&com->lc_sem);
1475 ns->ln_run_time_phase2 += cfs_duration_sec(cfs_time_current() +
1476 HALF_SEC - lfsck->li_time_last_checkpoint);
1477 ns->ln_time_last_checkpoint = cfs_time_current_sec();
1478 ns->ln_objs_checked_phase2 += com->lc_new_checked;
1479 com->lc_new_checked = 0;
1482 com->lc_journal = 0;
1483 ns->ln_status = LS_COMPLETED;
1484 if (!(bk->lb_param & LPF_DRYRUN))
1486 ~(LF_SCANNED_ONCE | LF_INCONSISTENT | LF_UPGRADE);
1487 ns->ln_time_last_complete = ns->ln_time_last_checkpoint;
1488 ns->ln_success_count++;
1489 } else if (rc == 0) {
1490 if (lfsck->li_paused)
1491 ns->ln_status = LS_PAUSED;
1493 ns->ln_status = LS_STOPPED;
1495 ns->ln_status = LS_FAILED;
1498 if (ns->ln_status != LS_PAUSED) {
1499 spin_lock(&lfsck->li_lock);
1500 cfs_list_del_init(&com->lc_link);
1501 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
1502 spin_unlock(&lfsck->li_lock);
1505 rc = lfsck_namespace_store(env, com, false);
1507 up_write(&com->lc_sem);
1511 static struct lfsck_operations lfsck_namespace_ops = {
1512 .lfsck_reset = lfsck_namespace_reset,
1513 .lfsck_fail = lfsck_namespace_fail,
1514 .lfsck_checkpoint = lfsck_namespace_checkpoint,
1515 .lfsck_prep = lfsck_namespace_prep,
1516 .lfsck_exec_oit = lfsck_namespace_exec_oit,
1517 .lfsck_exec_dir = lfsck_namespace_exec_dir,
1518 .lfsck_post = lfsck_namespace_post,
1519 .lfsck_dump = lfsck_namespace_dump,
1520 .lfsck_double_scan = lfsck_namespace_double_scan,
1523 int lfsck_namespace_setup(const struct lu_env *env,
1524 struct lfsck_instance *lfsck)
1526 struct lfsck_component *com;
1527 struct lfsck_namespace *ns;
1528 struct dt_object *obj;
1532 LASSERT(lfsck->li_master);
1538 CFS_INIT_LIST_HEAD(&com->lc_link);
1539 CFS_INIT_LIST_HEAD(&com->lc_link_dir);
1540 init_rwsem(&com->lc_sem);
1541 atomic_set(&com->lc_ref, 1);
1542 com->lc_lfsck = lfsck;
1543 com->lc_type = LT_NAMESPACE;
1544 com->lc_ops = &lfsck_namespace_ops;
1545 com->lc_file_size = sizeof(struct lfsck_namespace);
1546 OBD_ALLOC(com->lc_file_ram, com->lc_file_size);
1547 if (com->lc_file_ram == NULL)
1548 GOTO(out, rc = -ENOMEM);
1550 OBD_ALLOC(com->lc_file_disk, com->lc_file_size);
1551 if (com->lc_file_disk == NULL)
1552 GOTO(out, rc = -ENOMEM);
1554 obj = local_index_find_or_create(env, lfsck->li_los,
1555 lfsck->li_local_root,
1556 lfsck_namespace_name,
1557 S_IFREG | S_IRUGO | S_IWUSR,
1558 &dt_lfsck_features);
1560 GOTO(out, rc = PTR_ERR(obj));
1563 rc = obj->do_ops->do_index_try(env, obj, &dt_lfsck_features);
1567 rc = lfsck_namespace_load(env, com);
1569 rc = lfsck_namespace_reset(env, com, true);
1570 else if (rc == -ENODATA)
1571 rc = lfsck_namespace_init(env, com);
1575 ns = (struct lfsck_namespace *)com->lc_file_ram;
1576 switch (ns->ln_status) {
1581 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
1584 CERROR("%s: unknown lfsck_namespace status: %u\n",
1585 lfsck_lfsck2name(lfsck), ns->ln_status);
1587 case LS_SCANNING_PHASE1:
1588 case LS_SCANNING_PHASE2:
1589 /* No need to store the status to disk right now.
1590 * If the system crashed before the status stored,
1591 * it will be loaded back when next time. */
1592 ns->ln_status = LS_CRASHED;
1596 cfs_list_add_tail(&com->lc_link, &lfsck->li_list_scan);
1597 cfs_list_add_tail(&com->lc_link_dir, &lfsck->li_list_dir);
1605 lfsck_component_cleanup(env, com);