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_fid.h>
38 #include <lustre_lib.h>
39 #include <lustre_net.h>
40 #include <lustre/lustre_user.h>
42 #include "lfsck_internal.h"
44 #define LFSCK_NAMESPACE_MAGIC 0xA0629D03
46 enum lfsck_nameentry_check {
47 LFSCK_NAMEENTRY_DEAD = 1, /* The object has been unlinked. */
48 LFSCK_NAMEENTRY_REMOVED = 2, /* The entry has been removed. */
49 LFSCK_NAMEENTRY_RECREATED = 3, /* The entry has been recreated. */
52 static const char lfsck_namespace_name[] = "lfsck_namespace";
54 static struct lfsck_namespace_req *
55 lfsck_namespace_assistant_req_init(struct lfsck_instance *lfsck,
56 struct lu_dirent *ent, __u16 type)
58 struct lfsck_namespace_req *lnr;
61 size = sizeof(*lnr) + (ent->lde_namelen & ~3) + 4;
64 return ERR_PTR(-ENOMEM);
66 INIT_LIST_HEAD(&lnr->lnr_lar.lar_list);
67 lu_object_get(&lfsck->li_obj_dir->do_lu);
68 lnr->lnr_obj = lfsck->li_obj_dir;
69 lnr->lnr_fid = ent->lde_fid;
70 lnr->lnr_oit_cookie = lfsck->li_pos_current.lp_oit_cookie;
71 lnr->lnr_dir_cookie = ent->lde_hash;
72 lnr->lnr_attr = ent->lde_attrs;
75 lnr->lnr_namelen = ent->lde_namelen;
76 memcpy(lnr->lnr_name, ent->lde_name, ent->lde_namelen);
81 static void lfsck_namespace_assistant_req_fini(const struct lu_env *env,
82 struct lfsck_assistant_req *lar)
84 struct lfsck_namespace_req *lnr =
85 container_of0(lar, struct lfsck_namespace_req, lnr_lar);
87 lu_object_put(env, &lnr->lnr_obj->do_lu);
88 OBD_FREE(lnr, lnr->lnr_size);
91 static void lfsck_namespace_le_to_cpu(struct lfsck_namespace *dst,
92 struct lfsck_namespace *src)
94 dst->ln_magic = le32_to_cpu(src->ln_magic);
95 dst->ln_status = le32_to_cpu(src->ln_status);
96 dst->ln_flags = le32_to_cpu(src->ln_flags);
97 dst->ln_success_count = le32_to_cpu(src->ln_success_count);
98 dst->ln_run_time_phase1 = le32_to_cpu(src->ln_run_time_phase1);
99 dst->ln_run_time_phase2 = le32_to_cpu(src->ln_run_time_phase2);
100 dst->ln_time_last_complete = le64_to_cpu(src->ln_time_last_complete);
101 dst->ln_time_latest_start = le64_to_cpu(src->ln_time_latest_start);
102 dst->ln_time_last_checkpoint =
103 le64_to_cpu(src->ln_time_last_checkpoint);
104 lfsck_position_le_to_cpu(&dst->ln_pos_latest_start,
105 &src->ln_pos_latest_start);
106 lfsck_position_le_to_cpu(&dst->ln_pos_last_checkpoint,
107 &src->ln_pos_last_checkpoint);
108 lfsck_position_le_to_cpu(&dst->ln_pos_first_inconsistent,
109 &src->ln_pos_first_inconsistent);
110 dst->ln_items_checked = le64_to_cpu(src->ln_items_checked);
111 dst->ln_items_repaired = le64_to_cpu(src->ln_items_repaired);
112 dst->ln_items_failed = le64_to_cpu(src->ln_items_failed);
113 dst->ln_dirs_checked = le64_to_cpu(src->ln_dirs_checked);
114 dst->ln_objs_checked_phase2 = le64_to_cpu(src->ln_objs_checked_phase2);
115 dst->ln_objs_repaired_phase2 =
116 le64_to_cpu(src->ln_objs_repaired_phase2);
117 dst->ln_objs_failed_phase2 = le64_to_cpu(src->ln_objs_failed_phase2);
118 dst->ln_objs_nlink_repaired = le64_to_cpu(src->ln_objs_nlink_repaired);
119 fid_le_to_cpu(&dst->ln_fid_latest_scanned_phase2,
120 &src->ln_fid_latest_scanned_phase2);
121 dst->ln_dirent_repaired = le64_to_cpu(src->ln_dirent_repaired);
122 dst->ln_linkea_repaired = le64_to_cpu(src->ln_linkea_repaired);
123 dst->ln_mul_linked_checked = le64_to_cpu(src->ln_mul_linked_checked);
124 dst->ln_mul_linked_repaired = le64_to_cpu(src->ln_mul_linked_repaired);
125 dst->ln_unknown_inconsistency =
126 le64_to_cpu(src->ln_unknown_inconsistency);
127 dst->ln_unmatched_pairs_repaired =
128 le64_to_cpu(src->ln_unmatched_pairs_repaired);
129 dst->ln_dangling_repaired = le64_to_cpu(src->ln_dangling_repaired);
130 dst->ln_mul_ref_repaired = le64_to_cpu(src->ln_mul_ref_repaired);
131 dst->ln_bad_type_repaired = le64_to_cpu(src->ln_bad_type_repaired);
132 dst->ln_lost_dirent_repaired =
133 le64_to_cpu(src->ln_lost_dirent_repaired);
134 dst->ln_local_lpf_scanned = le64_to_cpu(src->ln_local_lpf_scanned);
135 dst->ln_local_lpf_moved = le64_to_cpu(src->ln_local_lpf_moved);
136 dst->ln_local_lpf_skipped = le64_to_cpu(src->ln_local_lpf_skipped);
137 dst->ln_local_lpf_failed = le64_to_cpu(src->ln_local_lpf_failed);
138 dst->ln_bitmap_size = le32_to_cpu(src->ln_bitmap_size);
141 static void lfsck_namespace_cpu_to_le(struct lfsck_namespace *dst,
142 struct lfsck_namespace *src)
144 dst->ln_magic = cpu_to_le32(src->ln_magic);
145 dst->ln_status = cpu_to_le32(src->ln_status);
146 dst->ln_flags = cpu_to_le32(src->ln_flags);
147 dst->ln_success_count = cpu_to_le32(src->ln_success_count);
148 dst->ln_run_time_phase1 = cpu_to_le32(src->ln_run_time_phase1);
149 dst->ln_run_time_phase2 = cpu_to_le32(src->ln_run_time_phase2);
150 dst->ln_time_last_complete = cpu_to_le64(src->ln_time_last_complete);
151 dst->ln_time_latest_start = cpu_to_le64(src->ln_time_latest_start);
152 dst->ln_time_last_checkpoint =
153 cpu_to_le64(src->ln_time_last_checkpoint);
154 lfsck_position_cpu_to_le(&dst->ln_pos_latest_start,
155 &src->ln_pos_latest_start);
156 lfsck_position_cpu_to_le(&dst->ln_pos_last_checkpoint,
157 &src->ln_pos_last_checkpoint);
158 lfsck_position_cpu_to_le(&dst->ln_pos_first_inconsistent,
159 &src->ln_pos_first_inconsistent);
160 dst->ln_items_checked = cpu_to_le64(src->ln_items_checked);
161 dst->ln_items_repaired = cpu_to_le64(src->ln_items_repaired);
162 dst->ln_items_failed = cpu_to_le64(src->ln_items_failed);
163 dst->ln_dirs_checked = cpu_to_le64(src->ln_dirs_checked);
164 dst->ln_objs_checked_phase2 = cpu_to_le64(src->ln_objs_checked_phase2);
165 dst->ln_objs_repaired_phase2 =
166 cpu_to_le64(src->ln_objs_repaired_phase2);
167 dst->ln_objs_failed_phase2 = cpu_to_le64(src->ln_objs_failed_phase2);
168 dst->ln_objs_nlink_repaired = cpu_to_le64(src->ln_objs_nlink_repaired);
169 fid_cpu_to_le(&dst->ln_fid_latest_scanned_phase2,
170 &src->ln_fid_latest_scanned_phase2);
171 dst->ln_dirent_repaired = cpu_to_le64(src->ln_dirent_repaired);
172 dst->ln_linkea_repaired = cpu_to_le64(src->ln_linkea_repaired);
173 dst->ln_mul_linked_checked = cpu_to_le64(src->ln_mul_linked_checked);
174 dst->ln_mul_linked_repaired = cpu_to_le64(src->ln_mul_linked_repaired);
175 dst->ln_unknown_inconsistency =
176 cpu_to_le64(src->ln_unknown_inconsistency);
177 dst->ln_unmatched_pairs_repaired =
178 cpu_to_le64(src->ln_unmatched_pairs_repaired);
179 dst->ln_dangling_repaired = cpu_to_le64(src->ln_dangling_repaired);
180 dst->ln_mul_ref_repaired = cpu_to_le64(src->ln_mul_ref_repaired);
181 dst->ln_bad_type_repaired = cpu_to_le64(src->ln_bad_type_repaired);
182 dst->ln_lost_dirent_repaired =
183 cpu_to_le64(src->ln_lost_dirent_repaired);
184 dst->ln_local_lpf_scanned = cpu_to_le64(src->ln_local_lpf_scanned);
185 dst->ln_local_lpf_moved = cpu_to_le64(src->ln_local_lpf_moved);
186 dst->ln_local_lpf_skipped = cpu_to_le64(src->ln_local_lpf_skipped);
187 dst->ln_local_lpf_failed = cpu_to_le64(src->ln_local_lpf_failed);
188 dst->ln_bitmap_size = cpu_to_le32(src->ln_bitmap_size);
191 static void lfsck_namespace_record_failure(const struct lu_env *env,
192 struct lfsck_instance *lfsck,
193 struct lfsck_namespace *ns)
195 struct lfsck_position pos;
197 ns->ln_items_failed++;
198 lfsck_pos_fill(env, lfsck, &pos, false);
199 if (lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent) ||
200 lfsck_pos_is_eq(&pos, &ns->ln_pos_first_inconsistent) < 0) {
201 ns->ln_pos_first_inconsistent = pos;
203 CDEBUG(D_LFSCK, "%s: namespace LFSCK hit first non-repaired "
204 "inconsistency at the pos ["LPU64", "DFID", "LPX64"]\n",
205 lfsck_lfsck2name(lfsck),
206 ns->ln_pos_first_inconsistent.lp_oit_cookie,
207 PFID(&ns->ln_pos_first_inconsistent.lp_dir_parent),
208 ns->ln_pos_first_inconsistent.lp_dir_cookie);
213 * Load the MDT bitmap from the lfsck_namespace trace file.
215 * \param[in] env pointer to the thread context
216 * \param[in] com pointer to the lfsck component
218 * \retval 0 for success
219 * \retval negative error number on failure or data corruption
221 static int lfsck_namespace_load_bitmap(const struct lu_env *env,
222 struct lfsck_component *com)
224 struct dt_object *obj = com->lc_obj;
225 struct lfsck_assistant_data *lad = com->lc_data;
226 struct lfsck_namespace *ns = com->lc_file_ram;
227 cfs_bitmap_t *bitmap = lad->lad_bitmap;
233 if (com->lc_lfsck->li_mdt_descs.ltd_tgts_bitmap->size >
235 nbits = com->lc_lfsck->li_mdt_descs.ltd_tgts_bitmap->size;
237 nbits = ns->ln_bitmap_size;
239 if (unlikely(nbits < BITS_PER_LONG))
240 nbits = BITS_PER_LONG;
242 if (nbits > bitmap->size) {
243 __u32 new_bits = bitmap->size;
244 cfs_bitmap_t *new_bitmap;
246 while (new_bits < nbits)
249 new_bitmap = CFS_ALLOCATE_BITMAP(new_bits);
250 if (new_bitmap == NULL)
253 lad->lad_bitmap = new_bitmap;
254 CFS_FREE_BITMAP(bitmap);
258 if (ns->ln_bitmap_size == 0) {
259 lad->lad_incomplete = 0;
260 CFS_RESET_BITMAP(bitmap);
265 size = (ns->ln_bitmap_size + 7) >> 3;
266 rc = dt_xattr_get(env, obj,
267 lfsck_buf_get(env, bitmap->data, size),
268 XATTR_NAME_LFSCK_BITMAP, BYPASS_CAPA);
270 RETURN(rc >= 0 ? -EINVAL : rc);
272 if (cfs_bitmap_check_empty(bitmap))
273 lad->lad_incomplete = 0;
275 lad->lad_incomplete = 1;
281 * \retval +ve: the lfsck_namespace is broken, the caller should reset it.
282 * \retval 0: succeed.
283 * \retval -ve: failed cases.
285 static int lfsck_namespace_load(const struct lu_env *env,
286 struct lfsck_component *com)
288 int len = com->lc_file_size;
291 rc = dt_xattr_get(env, com->lc_obj,
292 lfsck_buf_get(env, com->lc_file_disk, len),
293 XATTR_NAME_LFSCK_NAMESPACE, BYPASS_CAPA);
295 struct lfsck_namespace *ns = com->lc_file_ram;
297 lfsck_namespace_le_to_cpu(ns,
298 (struct lfsck_namespace *)com->lc_file_disk);
299 if (ns->ln_magic != LFSCK_NAMESPACE_MAGIC) {
300 CDEBUG(D_LFSCK, "%s: invalid lfsck_namespace magic "
301 "%#x != %#x\n", lfsck_lfsck2name(com->lc_lfsck),
302 ns->ln_magic, LFSCK_NAMESPACE_MAGIC);
307 } else if (rc != -ENODATA) {
308 CDEBUG(D_LFSCK, "%s: fail to load lfsck_namespace, "
309 "expected = %d: rc = %d\n",
310 lfsck_lfsck2name(com->lc_lfsck), len, rc);
317 static int lfsck_namespace_store(const struct lu_env *env,
318 struct lfsck_component *com)
320 struct dt_object *obj = com->lc_obj;
321 struct lfsck_instance *lfsck = com->lc_lfsck;
322 struct lfsck_namespace *ns = com->lc_file_ram;
323 struct lfsck_assistant_data *lad = com->lc_data;
324 cfs_bitmap_t *bitmap = NULL;
325 struct thandle *handle;
327 int len = com->lc_file_size;
332 bitmap = lad->lad_bitmap;
333 nbits = bitmap->size;
336 LASSERTF((nbits & 7) == 0, "Invalid nbits %u\n", nbits);
339 ns->ln_bitmap_size = nbits;
340 lfsck_namespace_cpu_to_le((struct lfsck_namespace *)com->lc_file_disk,
342 handle = dt_trans_create(env, lfsck->li_bottom);
344 GOTO(log, rc = PTR_ERR(handle));
346 rc = dt_declare_xattr_set(env, obj,
347 lfsck_buf_get(env, com->lc_file_disk, len),
348 XATTR_NAME_LFSCK_NAMESPACE, 0, handle);
352 if (bitmap != NULL) {
353 rc = dt_declare_xattr_set(env, obj,
354 lfsck_buf_get(env, bitmap->data, nbits >> 3),
355 XATTR_NAME_LFSCK_BITMAP, 0, handle);
360 rc = dt_trans_start_local(env, lfsck->li_bottom, handle);
364 rc = dt_xattr_set(env, obj,
365 lfsck_buf_get(env, com->lc_file_disk, len),
366 XATTR_NAME_LFSCK_NAMESPACE, 0, handle, BYPASS_CAPA);
367 if (rc == 0 && bitmap != NULL)
368 rc = dt_xattr_set(env, obj,
369 lfsck_buf_get(env, bitmap->data, nbits >> 3),
370 XATTR_NAME_LFSCK_BITMAP, 0, handle,
376 dt_trans_stop(env, lfsck->li_bottom, handle);
380 CDEBUG(D_LFSCK, "%s: fail to store lfsck_namespace: rc = %d\n",
381 lfsck_lfsck2name(lfsck), rc);
385 static int lfsck_namespace_init(const struct lu_env *env,
386 struct lfsck_component *com)
388 struct lfsck_namespace *ns = com->lc_file_ram;
391 memset(ns, 0, sizeof(*ns));
392 ns->ln_magic = LFSCK_NAMESPACE_MAGIC;
393 ns->ln_status = LS_INIT;
394 down_write(&com->lc_sem);
395 rc = lfsck_namespace_store(env, com);
396 up_write(&com->lc_sem);
401 * Update the namespace LFSCK trace file for the given @fid
403 * \param[in] env pointer to the thread context
404 * \param[in] com pointer to the lfsck component
405 * \param[in] fid the fid which flags to be updated in the lfsck
407 * \param[in] add true if add new flags, otherwise remove flags
409 * \retval 0 for succeed or nothing to be done
410 * \retval negative error number on failure
412 int lfsck_namespace_trace_update(const struct lu_env *env,
413 struct lfsck_component *com,
414 const struct lu_fid *fid,
415 const __u8 flags, bool add)
417 struct lfsck_instance *lfsck = com->lc_lfsck;
418 struct dt_object *obj = com->lc_obj;
419 struct lu_fid *key = &lfsck_env_info(env)->lti_fid3;
420 struct dt_device *dev = lfsck->li_bottom;
421 struct thandle *th = NULL;
429 down_write(&com->lc_sem);
430 fid_cpu_to_be(key, fid);
431 rc = dt_lookup(env, obj, (struct dt_rec *)&old,
432 (const struct dt_key *)key, BYPASS_CAPA);
435 GOTO(unlock, rc = 0);
439 } else if (rc == 0) {
441 if ((old & flags) == flags)
442 GOTO(unlock, rc = 0);
446 if ((old & flags) == 0)
447 GOTO(unlock, rc = 0);
455 th = dt_trans_create(env, dev);
457 GOTO(log, rc = PTR_ERR(th));
460 rc = dt_declare_delete(env, obj,
461 (const struct dt_key *)key, th);
467 rc = dt_declare_insert(env, obj,
468 (const struct dt_rec *)&new,
469 (const struct dt_key *)key, th);
474 rc = dt_trans_start_local(env, dev, th);
479 rc = dt_delete(env, obj, (const struct dt_key *)key,
486 rc = dt_insert(env, obj, (const struct dt_rec *)&new,
487 (const struct dt_key *)key, th, BYPASS_CAPA, 1);
495 if (th != NULL && !IS_ERR(th))
496 dt_trans_stop(env, dev, th);
498 CDEBUG(D_LFSCK, "%s: namespace LFSCK %s flags for "DFID" in the "
499 "trace file, flags %x, old %x, new %x: rc = %d\n",
500 lfsck_lfsck2name(lfsck), add ? "add" : "del", PFID(fid),
501 (__u32)flags, (__u32)old, (__u32)new, rc);
504 up_write(&com->lc_sem);
509 static int lfsck_namespace_check_exist(const struct lu_env *env,
510 struct dt_object *dir,
511 struct dt_object *obj, const char *name)
513 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
517 if (unlikely(lfsck_is_dead_obj(obj)))
518 RETURN(LFSCK_NAMEENTRY_DEAD);
520 rc = dt_lookup(env, dir, (struct dt_rec *)fid,
521 (const struct dt_key *)name, BYPASS_CAPA);
523 RETURN(LFSCK_NAMEENTRY_REMOVED);
528 if (!lu_fid_eq(fid, lfsck_dto2fid(obj)))
529 RETURN(LFSCK_NAMEENTRY_RECREATED);
534 static int lfsck_declare_namespace_exec_dir(const struct lu_env *env,
535 struct dt_object *obj,
536 struct thandle *handle)
540 /* For destroying all invalid linkEA entries. */
541 rc = dt_declare_xattr_del(env, obj, XATTR_NAME_LINK, handle);
545 /* For insert new linkEA entry. */
546 rc = dt_declare_xattr_set(env, obj,
547 lfsck_buf_get_const(env, NULL, DEFAULT_LINKEA_SIZE),
548 XATTR_NAME_LINK, 0, handle);
552 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
553 struct linkea_data *ldata)
557 if (ldata->ld_buf->lb_buf == NULL)
560 if (!dt_object_exists(obj))
563 rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK, BYPASS_CAPA);
565 /* Buf was too small, figure out what we need. */
566 rc = dt_xattr_get(env, obj, &LU_BUF_NULL, XATTR_NAME_LINK,
571 lu_buf_realloc(ldata->ld_buf, rc);
572 if (ldata->ld_buf->lb_buf == NULL)
575 rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK,
580 rc = linkea_init(ldata);
586 * Remove linkEA for the given object.
588 * The caller should take the ldlm lock before the calling.
590 * \param[in] env pointer to the thread context
591 * \param[in] com pointer to the lfsck component
592 * \param[in] obj pointer to the dt_object to be handled
594 * \retval 0 for repaired cases
595 * \retval negative error number on failure
597 static int lfsck_namespace_links_remove(const struct lu_env *env,
598 struct lfsck_component *com,
599 struct dt_object *obj)
601 struct lfsck_instance *lfsck = com->lc_lfsck;
602 struct dt_device *dev = lfsck->li_bottom;
603 struct thandle *th = NULL;
607 LASSERT(dt_object_remote(obj) == 0);
609 th = dt_trans_create(env, dev);
611 GOTO(log, rc = PTR_ERR(th));
613 rc = dt_declare_xattr_del(env, obj, XATTR_NAME_LINK, th);
617 rc = dt_trans_start_local(env, dev, th);
621 dt_write_lock(env, obj, 0);
622 if (unlikely(lfsck_is_dead_obj(obj)))
623 GOTO(unlock, rc = -ENOENT);
625 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
626 GOTO(unlock, rc = 0);
628 rc = dt_xattr_del(env, obj, XATTR_NAME_LINK, th, BYPASS_CAPA);
633 dt_write_unlock(env, obj);
636 dt_trans_stop(env, dev, th);
639 CDEBUG(D_LFSCK, "%s: namespace LFSCK remove invalid linkEA "
640 "for the object "DFID": rc = %d\n",
641 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(obj)), rc);
644 struct lfsck_namespace *ns = com->lc_file_ram;
646 ns->ln_flags |= LF_INCONSISTENT;
652 static int lfsck_links_write(const struct lu_env *env, struct dt_object *obj,
653 struct linkea_data *ldata, struct thandle *handle)
655 const struct lu_buf *buf = lfsck_buf_get_const(env,
656 ldata->ld_buf->lb_buf,
657 ldata->ld_leh->leh_len);
659 return dt_xattr_set(env, obj, buf, XATTR_NAME_LINK, 0, handle,
663 static void lfsck_namespace_unpack_linkea_entry(struct linkea_data *ldata,
664 struct lu_name *cname,
668 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, cname, pfid);
669 /* To guarantee the 'name' is terminated with '0'. */
670 memcpy(buf, cname->ln_name, cname->ln_namelen);
671 buf[cname->ln_namelen] = 0;
672 cname->ln_name = buf;
675 static int lfsck_namespace_filter_linkea_entry(struct linkea_data *ldata,
676 struct lu_name *cname,
680 struct link_ea_entry *oldlee;
684 oldlee = ldata->ld_lee;
685 oldlen = ldata->ld_reclen;
686 linkea_next_entry(ldata);
687 while (ldata->ld_lee != NULL) {
688 ldata->ld_reclen = (ldata->ld_lee->lee_reclen[0] << 8) |
689 ldata->ld_lee->lee_reclen[1];
690 if (unlikely(ldata->ld_reclen == oldlen &&
691 memcmp(ldata->ld_lee, oldlee, oldlen) == 0)) {
696 linkea_del_buf(ldata, cname);
698 linkea_next_entry(ldata);
701 ldata->ld_lee = oldlee;
702 ldata->ld_reclen = oldlen;
708 * Insert orphan into .lustre/lost+found/MDTxxxx/ locally.
710 * Add the specified orphan MDT-object to the .lustre/lost+found/MDTxxxx/
711 * with the given type to generate the name, the detailed rules for name
712 * have been described as following.
714 * The function also generates the linkEA corresponding to the name entry
715 * under the .lustre/lost+found/MDTxxxx/ for the orphan MDT-object.
717 * \param[in] env pointer to the thread context
718 * \param[in] com pointer to the lfsck component
719 * \param[in] orphan pointer to the orphan MDT-object
720 * \param[in] infix additional information for the orphan name, such as
721 * the FID for original
722 * \param[in] type the type for describing why the orphan MDT-object is
723 * created. The rules are as following:
725 * type "D": The MDT-object is a directory, it may knows its parent
726 * but because there is no valid linkEA, the LFSCK cannot
727 * know where to put it back to the namespace.
728 * type "O": The MDT-object has no linkEA, and there is no name
729 * entry that references the MDT-object.
731 * \see lfsck_layout_recreate_parent() for more types.
733 * The orphan name will be like:
734 * ${FID}-${infix}-${type}-${conflict_version}
736 * \param[out] count if some others inserted some linkEA entries by race,
737 * then return the linkEA entries count.
739 * \retval positive number for repaired cases
740 * \retval 0 if needs to repair nothing
741 * \retval negative error number on failure
743 static int lfsck_namespace_insert_orphan(const struct lu_env *env,
744 struct lfsck_component *com,
745 struct dt_object *orphan,
746 const char *infix, const char *type,
749 struct lfsck_thread_info *info = lfsck_env_info(env);
750 struct lu_name *cname = &info->lti_name;
751 struct dt_insert_rec *rec = &info->lti_dt_rec;
752 struct lu_fid *tfid = &info->lti_fid5;
753 struct lu_attr *la = &info->lti_la3;
754 const struct lu_fid *cfid = lfsck_dto2fid(orphan);
755 const struct lu_fid *pfid;
756 struct lfsck_instance *lfsck = com->lc_lfsck;
757 struct dt_device *dev = lfsck->li_bottom;
758 struct dt_object *parent;
759 struct thandle *th = NULL;
760 struct lustre_handle plh = { 0 };
761 struct lustre_handle clh = { 0 };
762 struct linkea_data ldata = { 0 };
763 struct lu_buf linkea_buf;
770 cname->ln_name = NULL;
771 /* Create .lustre/lost+found/MDTxxxx when needed. */
772 if (unlikely(lfsck->li_lpf_obj == NULL)) {
773 rc = lfsck_create_lpf(env, lfsck);
778 parent = lfsck->li_lpf_obj;
779 pfid = lfsck_dto2fid(parent);
781 /* Hold update lock on the parent to prevent others to access. */
782 rc = lfsck_ibits_lock(env, lfsck, parent, &plh,
783 MDS_INODELOCK_UPDATE, LCK_EX);
788 namelen = snprintf(info->lti_key, NAME_MAX, DFID"%s-%s-%d",
789 PFID(cfid), infix, type, idx++);
790 rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
791 (const struct dt_key *)info->lti_key,
793 if (rc != 0 && rc != -ENOENT)
796 if (unlikely(rc == 0 && lu_fid_eq(cfid, tfid)))
798 } while (rc == 0 && !exist);
800 cname->ln_name = info->lti_key;
801 cname->ln_namelen = namelen;
802 rc = linkea_data_new(&ldata, &info->lti_linkea_buf2);
806 rc = linkea_add_buf(&ldata, cname, pfid);
810 rc = lfsck_ibits_lock(env, lfsck, orphan, &clh,
811 MDS_INODELOCK_UPDATE | MDS_INODELOCK_LOOKUP,
816 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
817 ldata.ld_leh->leh_len);
818 th = dt_trans_create(env, dev);
820 GOTO(log, rc = PTR_ERR(th));
822 if (S_ISDIR(lfsck_object_type(orphan))) {
823 rc = dt_declare_delete(env, orphan,
824 (const struct dt_key *)dotdot, th);
828 rec->rec_type = S_IFDIR;
830 rc = dt_declare_insert(env, orphan, (const struct dt_rec *)rec,
831 (const struct dt_key *)dotdot, th);
836 rc = dt_declare_xattr_set(env, orphan, &linkea_buf,
837 XATTR_NAME_LINK, 0, th);
842 rec->rec_type = lfsck_object_type(orphan) & S_IFMT;
844 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
845 (const struct dt_key *)cname->ln_name,
850 if (S_ISDIR(rec->rec_type)) {
851 rc = dt_declare_ref_add(env, parent, th);
857 memset(la, 0, sizeof(*la));
858 la->la_ctime = cfs_time_current_sec();
859 la->la_valid = LA_CTIME;
860 rc = dt_declare_attr_set(env, orphan, la, th);
864 rc = dt_trans_start_local(env, dev, th);
868 dt_write_lock(env, orphan, 0);
869 rc = lfsck_links_read(env, orphan, &ldata);
870 if (likely((rc == -ENODATA) || (rc == -EINVAL) ||
871 (rc == 0 && ldata.ld_leh->leh_reccount == 0))) {
872 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
873 GOTO(unlock, rc = 1);
875 if (S_ISDIR(lfsck_object_type(orphan))) {
876 rc = dt_delete(env, orphan,
877 (const struct dt_key *)dotdot, th,
882 rec->rec_type = S_IFDIR;
884 rc = dt_insert(env, orphan, (const struct dt_rec *)rec,
885 (const struct dt_key *)dotdot, th,
891 rc = dt_xattr_set(env, orphan, &linkea_buf, XATTR_NAME_LINK, 0,
894 if (rc == 0 && count != NULL)
895 *count = ldata.ld_leh->leh_reccount;
899 dt_write_unlock(env, orphan);
901 if (rc == 0 && !exist) {
902 rec->rec_type = lfsck_object_type(orphan) & S_IFMT;
904 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
905 (const struct dt_key *)cname->ln_name,
907 if (rc == 0 && S_ISDIR(rec->rec_type)) {
908 dt_write_lock(env, parent, 0);
909 rc = dt_ref_add(env, parent, th);
910 dt_write_unlock(env, parent);
917 rc = dt_attr_set(env, orphan, la, th, BYPASS_CAPA);
919 GOTO(stop, rc = (rc == 0 ? 1 : rc));
922 dt_write_unlock(env, orphan);
925 dt_trans_stop(env, dev, th);
928 lfsck_ibits_unlock(&clh, LCK_EX);
929 lfsck_ibits_unlock(&plh, LCK_EX);
930 CDEBUG(D_LFSCK, "%s: namespace LFSCK insert orphan for the "
931 "object "DFID", name = %s: rc = %d\n",
932 lfsck_lfsck2name(lfsck), PFID(cfid),
933 cname->ln_name != NULL ? cname->ln_name : "<NULL>", rc);
936 struct lfsck_namespace *ns = com->lc_file_ram;
938 ns->ln_flags |= LF_INCONSISTENT;
945 * Add the specified name entry back to namespace.
947 * If there is a linkEA entry that back references a name entry under
948 * some parent directory, but such parent directory does not have the
949 * claimed name entry. On the other hand, the linkEA entries count is
950 * not larger than the MDT-object's hard link count. Under such case,
951 * it is quite possible that the name entry is lost. Then the LFSCK
952 * should add the name entry back to the namespace.
954 * \param[in] env pointer to the thread context
955 * \param[in] com pointer to the lfsck component
956 * \param[in] parent pointer to the directory under which the name entry
957 * will be inserted into
958 * \param[in] child pointer to the object referenced by the name entry
959 * that to be inserted into the parent
960 * \param[in] name the name for the child in the parent directory
962 * \retval positive number for repaired cases
963 * \retval 0 if nothing to be repaired
964 * \retval negative error number on failure
966 static int lfsck_namespace_insert_normal(const struct lu_env *env,
967 struct lfsck_component *com,
968 struct dt_object *parent,
969 struct dt_object *child,
972 struct lfsck_thread_info *info = lfsck_env_info(env);
973 struct lu_attr *la = &info->lti_la;
974 struct dt_insert_rec *rec = &info->lti_dt_rec;
975 struct lfsck_instance *lfsck = com->lc_lfsck;
976 struct dt_device *dev = lfsck->li_next;
977 struct thandle *th = NULL;
978 struct lustre_handle lh = { 0 };
982 if (unlikely(!dt_try_as_dir(env, parent)))
983 GOTO(log, rc = -ENOTDIR);
985 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
988 /* Hold update lock on the parent to prevent others to access. */
989 rc = lfsck_ibits_lock(env, lfsck, parent, &lh,
990 MDS_INODELOCK_UPDATE, LCK_EX);
994 th = dt_trans_create(env, dev);
996 GOTO(unlock, rc = PTR_ERR(th));
998 rec->rec_type = lfsck_object_type(child) & S_IFMT;
999 rec->rec_fid = lfsck_dto2fid(child);
1000 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
1001 (const struct dt_key *)name, th);
1005 if (S_ISDIR(rec->rec_type)) {
1006 rc = dt_declare_ref_add(env, parent, th);
1011 memset(la, 0, sizeof(*la));
1012 la->la_ctime = cfs_time_current_sec();
1013 la->la_valid = LA_CTIME;
1014 rc = dt_declare_attr_set(env, parent, la, th);
1018 rc = dt_declare_attr_set(env, child, la, th);
1022 rc = dt_trans_start_local(env, dev, th);
1026 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
1027 (const struct dt_key *)name, th, BYPASS_CAPA, 1);
1031 if (S_ISDIR(rec->rec_type)) {
1032 dt_write_lock(env, parent, 0);
1033 rc = dt_ref_add(env, parent, th);
1034 dt_write_unlock(env, parent);
1039 la->la_ctime = cfs_time_current_sec();
1040 rc = dt_attr_set(env, parent, la, th, BYPASS_CAPA);
1044 rc = dt_attr_set(env, child, la, th, BYPASS_CAPA);
1046 GOTO(stop, rc = (rc == 0 ? 1 : rc));
1049 dt_trans_stop(env, dev, th);
1052 lfsck_ibits_unlock(&lh, LCK_EX);
1055 CDEBUG(D_LFSCK, "%s: namespace LFSCK insert object "DFID" with "
1056 "the name %s and type %o to the parent "DFID": rc = %d\n",
1057 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(child)), name,
1058 lfsck_object_type(child) & S_IFMT,
1059 PFID(lfsck_dto2fid(parent)), rc);
1062 struct lfsck_namespace *ns = com->lc_file_ram;
1064 ns->ln_flags |= LF_INCONSISTENT;
1066 ns->ln_lost_dirent_repaired++;
1073 * Create the specified orphan MDT-object on remote MDT.
1075 * The LFSCK instance on this MDT will send LFSCK RPC to remote MDT to
1076 * ask the remote LFSCK instance to create the specified orphan object
1077 * under .lustre/lost+found/MDTxxxx/ directory with the name:
1078 * ${FID}-P-${conflict_version}.
1080 * \param[in] env pointer to the thread context
1081 * \param[in] com pointer to the lfsck component
1082 * \param[in] orphan pointer to the orphan MDT-object
1083 * \param[in] type the orphan's type to be created
1085 * type "P": The orphan object to be created was a parent directory
1086 * of some MDT-object which linkEA shows that the @orphan
1087 * object is missing.
1089 * \see lfsck_layout_recreate_parent() for more types.
1091 * \retval positive number for repaired cases
1092 * \retval 0 if needs to repair nothing
1093 * \retval negative error number on failure
1095 static int lfsck_namespace_create_orphan_remote(const struct lu_env *env,
1096 struct lfsck_component *com,
1097 struct dt_object *orphan,
1100 struct lfsck_thread_info *info = lfsck_env_info(env);
1101 struct lfsck_request *lr = &info->lti_lr;
1102 struct lu_seq_range *range = &info->lti_range;
1103 const struct lu_fid *fid = lfsck_dto2fid(orphan);
1104 struct lfsck_namespace *ns = com->lc_file_ram;
1105 struct lfsck_instance *lfsck = com->lc_lfsck;
1106 struct seq_server_site *ss =
1107 lu_site2seq(lfsck->li_bottom->dd_lu_dev.ld_site);
1108 struct lfsck_tgt_desc *ltd = NULL;
1109 struct ptlrpc_request *req = NULL;
1113 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
1116 fld_range_set_mdt(range);
1117 rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
1121 ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, range->lsr_index);
1123 ns->ln_flags |= LF_INCOMPLETE;
1125 GOTO(out, rc = -ENODEV);
1128 req = ptlrpc_request_alloc(class_exp2cliimp(ltd->ltd_exp),
1131 GOTO(out, rc = -ENOMEM);
1133 rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, LFSCK_NOTIFY);
1135 ptlrpc_request_free(req);
1140 lr = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
1141 memset(lr, 0, sizeof(*lr));
1142 lr->lr_event = LE_CREATE_ORPHAN;
1143 lr->lr_index = lfsck_dev_idx(lfsck->li_bottom);
1144 lr->lr_active = LFSCK_TYPE_NAMESPACE;
1148 ptlrpc_request_set_replen(req);
1149 rc = ptlrpc_queue_wait(req);
1150 ptlrpc_req_finished(req);
1154 else if (rc == -EEXIST)
1160 CDEBUG(D_LFSCK, "%s: namespace LFSCK create object "
1161 DFID" on the MDT %x remotely: rc = %d\n",
1162 lfsck_lfsck2name(lfsck), PFID(fid),
1163 ltd != NULL ? ltd->ltd_index : -1, rc);
1172 * Create the specified orphan MDT-object locally.
1174 * For the case that the parent MDT-object stored in some MDT-object's
1175 * linkEA entry is lost, the LFSCK will re-create the parent object as
1176 * an orphan and insert it into .lustre/lost+found/MDTxxxx/ directory
1177 * with the name ${FID}-P-${conflict_version}.
1179 * \param[in] env pointer to the thread context
1180 * \param[in] com pointer to the lfsck component
1181 * \param[in] orphan pointer to the orphan MDT-object to be created
1182 * \param[in] type the orphan's type to be created
1184 * type "P": The orphan object to be created was a parent directory
1185 * of some MDT-object which linkEA shows that the @orphan
1186 * object is missing.
1188 * \see lfsck_layout_recreate_parent() for more types.
1190 * \retval positive number for repaired cases
1191 * \retval negative error number on failure
1193 static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
1194 struct lfsck_component *com,
1195 struct dt_object *orphan,
1198 struct lfsck_thread_info *info = lfsck_env_info(env);
1199 struct lu_attr *la = &info->lti_la;
1200 struct dt_allocation_hint *hint = &info->lti_hint;
1201 struct dt_object_format *dof = &info->lti_dof;
1202 struct lu_name *cname = &info->lti_name2;
1203 struct dt_insert_rec *rec = &info->lti_dt_rec;
1204 struct lu_fid *tfid = &info->lti_fid;
1205 const struct lu_fid *cfid = lfsck_dto2fid(orphan);
1206 const struct lu_fid *pfid;
1207 struct lfsck_instance *lfsck = com->lc_lfsck;
1208 struct dt_device *dev = lfsck->li_bottom;
1209 struct dt_object *parent = NULL;
1210 struct dt_object *child = NULL;
1211 struct thandle *th = NULL;
1212 struct lustre_handle lh = { 0 };
1213 struct linkea_data ldata = { 0 };
1214 struct lu_buf linkea_buf;
1221 LASSERT(!dt_object_exists(orphan));
1222 LASSERT(!dt_object_remote(orphan));
1224 /* @orphan maybe not attached to lfsck->li_bottom */
1225 child = lfsck_object_find_by_dev(env, dev, cfid);
1227 GOTO(log, rc = PTR_ERR(child));
1229 cname->ln_name = NULL;
1230 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
1233 /* Create .lustre/lost+found/MDTxxxx when needed. */
1234 if (unlikely(lfsck->li_lpf_obj == NULL)) {
1235 rc = lfsck_create_lpf(env, lfsck);
1240 parent = lfsck->li_lpf_obj;
1241 pfid = lfsck_dto2fid(parent);
1243 /* Hold update lock on the parent to prevent others to access. */
1244 rc = lfsck_ibits_lock(env, lfsck, parent, &lh,
1245 MDS_INODELOCK_UPDATE, LCK_EX);
1250 namelen = snprintf(name, 31, DFID"-P-%d",
1252 rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
1253 (const struct dt_key *)name, BYPASS_CAPA);
1254 if (rc != 0 && rc != -ENOENT)
1258 cname->ln_name = name;
1259 cname->ln_namelen = namelen;
1261 memset(la, 0, sizeof(*la));
1262 la->la_mode = type | (S_ISDIR(type) ? 0700 : 0600);
1263 la->la_valid = LA_TYPE | LA_MODE | LA_UID | LA_GID |
1264 LA_ATIME | LA_MTIME | LA_CTIME;
1266 child->do_ops->do_ah_init(env, hint, parent, child,
1267 la->la_mode & S_IFMT);
1269 memset(dof, 0, sizeof(*dof));
1270 dof->dof_type = dt_mode_to_dft(type);
1272 rc = linkea_data_new(&ldata, &info->lti_linkea_buf2);
1276 rc = linkea_add_buf(&ldata, cname, pfid);
1280 th = dt_trans_create(env, dev);
1282 GOTO(unlock1, rc = PTR_ERR(th));
1284 rc = dt_declare_create(env, child, la, hint, dof, th);
1285 if (rc == 0 && S_ISDIR(type))
1286 rc = dt_declare_ref_add(env, child, th);
1291 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
1292 ldata.ld_leh->leh_len);
1293 rc = dt_declare_xattr_set(env, child, &linkea_buf,
1294 XATTR_NAME_LINK, 0, th);
1298 rec->rec_type = type;
1299 rec->rec_fid = cfid;
1300 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
1301 (const struct dt_key *)name, th);
1302 if (rc == 0 && S_ISDIR(type))
1303 rc = dt_declare_ref_add(env, parent, th);
1308 rc = dt_trans_start_local(env, dev, th);
1312 dt_write_lock(env, child, 0);
1313 rc = dt_create(env, child, la, hint, dof, th);
1317 if (S_ISDIR(type)) {
1318 if (unlikely(!dt_try_as_dir(env, child)))
1319 GOTO(unlock2, rc = -ENOTDIR);
1321 rec->rec_type = S_IFDIR;
1322 rec->rec_fid = cfid;
1323 rc = dt_insert(env, child, (const struct dt_rec *)rec,
1324 (const struct dt_key *)dot, th, BYPASS_CAPA, 1);
1328 rec->rec_fid = pfid;
1329 rc = dt_insert(env, child, (const struct dt_rec *)rec,
1330 (const struct dt_key *)dotdot, th,
1335 rc = dt_ref_add(env, child, th);
1340 rc = dt_xattr_set(env, child, &linkea_buf,
1341 XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
1342 dt_write_unlock(env, child);
1346 rec->rec_type = type;
1347 rec->rec_fid = cfid;
1348 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
1349 (const struct dt_key *)name, th, BYPASS_CAPA, 1);
1350 if (rc == 0 && S_ISDIR(type)) {
1351 dt_write_lock(env, parent, 0);
1352 rc = dt_ref_add(env, parent, th);
1353 dt_write_unlock(env, parent);
1356 GOTO(stop, rc = (rc == 0 ? 1 : rc));
1359 dt_write_unlock(env, child);
1362 dt_trans_stop(env, dev, th);
1365 lfsck_ibits_unlock(&lh, LCK_EX);
1368 CDEBUG(D_LFSCK, "%s: namespace LFSCK create orphan locally for "
1369 "the object "DFID", name = %s, type %o: rc = %d\n",
1370 lfsck_lfsck2name(lfsck), PFID(cfid),
1371 cname->ln_name != NULL ? cname->ln_name : "<NULL>", type, rc);
1373 if (child != NULL && !IS_ERR(child))
1374 lfsck_object_put(env, child);
1380 * Create the specified orphan MDT-object.
1382 * For the case that the parent MDT-object stored in some MDT-object's
1383 * linkEA entry is lost, the LFSCK will re-create the parent object as
1384 * an orphan and insert it into .lustre/lost+found/MDTxxxx/ directory
1385 * with the name: ${FID}-P-${conflict_version}.
1387 * \param[in] env pointer to the thread context
1388 * \param[in] com pointer to the lfsck component
1389 * \param[in] orphan pointer to the orphan MDT-object
1391 * type "P": The orphan object to be created was a parent directory
1392 * of some MDT-object which linkEA shows that the @orphan
1393 * object is missing.
1395 * \see lfsck_layout_recreate_parent() for more types.
1397 * \retval positive number for repaired cases
1398 * \retval 0 if needs to repair nothing
1399 * \retval negative error number on failure
1401 static int lfsck_namespace_create_orphan(const struct lu_env *env,
1402 struct lfsck_component *com,
1403 struct dt_object *orphan)
1405 struct lfsck_namespace *ns = com->lc_file_ram;
1408 if (dt_object_remote(orphan))
1409 rc = lfsck_namespace_create_orphan_remote(env, com, orphan,
1412 rc = lfsck_namespace_create_orphan_local(env, com, orphan,
1416 ns->ln_flags |= LF_INCONSISTENT;
1422 * Remove the specified entry from the linkEA.
1424 * Locate the linkEA entry with the given @cname and @pfid, then
1425 * remove this entry or the other entries those are repeated with
1428 * \param[in] env pointer to the thread context
1429 * \param[in] com pointer to the lfsck component
1430 * \param[in] obj pointer to the dt_object to be handled
1431 * \param[in,out]ldata pointer to the buffer that holds the linkEA
1432 * \param[in] cname the name for the child in the parent directory
1433 * \param[in] pfid the parent directory's FID for the linkEA
1434 * \param[in] next if true, then remove the first found linkEA
1435 * entry, and move the ldata->ld_lee to next entry
1437 * \retval positive number for repaired cases
1438 * \retval 0 if nothing to be repaired
1439 * \retval negative error number on failure
1441 static int lfsck_namespace_shrink_linkea(const struct lu_env *env,
1442 struct lfsck_component *com,
1443 struct dt_object *obj,
1444 struct linkea_data *ldata,
1445 struct lu_name *cname,
1446 struct lu_fid *pfid,
1449 struct lfsck_instance *lfsck = com->lc_lfsck;
1450 struct dt_device *dev = lfsck->li_bottom;
1451 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1452 struct thandle *th = NULL;
1453 struct lustre_handle lh = { 0 };
1454 struct linkea_data ldata_new = { 0 };
1455 struct lu_buf linkea_buf;
1459 rc = lfsck_ibits_lock(env, lfsck, obj, &lh,
1460 MDS_INODELOCK_UPDATE |
1461 MDS_INODELOCK_XATTR, LCK_EX);
1466 linkea_del_buf(ldata, cname);
1468 lfsck_namespace_filter_linkea_entry(ldata, cname, pfid,
1470 lfsck_buf_init(&linkea_buf, ldata->ld_buf->lb_buf,
1471 ldata->ld_leh->leh_len);
1474 th = dt_trans_create(env, dev);
1476 GOTO(unlock1, rc = PTR_ERR(th));
1478 rc = dt_declare_xattr_set(env, obj, &linkea_buf,
1479 XATTR_NAME_LINK, 0, th);
1483 rc = dt_trans_start_local(env, dev, th);
1487 dt_write_lock(env, obj, 0);
1488 if (unlikely(lfsck_is_dead_obj(obj)))
1489 GOTO(unlock2, rc = -ENOENT);
1491 rc = lfsck_links_read2(env, obj, &ldata_new);
1495 /* The specified linkEA entry has been removed by race. */
1496 rc = linkea_links_find(&ldata_new, cname, pfid);
1498 GOTO(unlock2, rc = 0);
1500 if (bk->lb_param & LPF_DRYRUN)
1501 GOTO(unlock2, rc = 1);
1504 linkea_del_buf(&ldata_new, cname);
1506 lfsck_namespace_filter_linkea_entry(&ldata_new, cname, pfid,
1509 if (linkea_buf.lb_len < ldata_new.ld_leh->leh_len) {
1510 dt_write_unlock(env, obj);
1511 dt_trans_stop(env, dev, th);
1512 lfsck_buf_init(&linkea_buf, ldata_new.ld_buf->lb_buf,
1513 ldata_new.ld_leh->leh_len);
1517 lfsck_buf_init(&linkea_buf, ldata_new.ld_buf->lb_buf,
1518 ldata_new.ld_leh->leh_len);
1519 rc = dt_xattr_set(env, obj, &linkea_buf,
1520 XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
1522 GOTO(unlock2, rc = (rc == 0 ? 1 : rc));
1525 dt_write_unlock(env, obj);
1528 dt_trans_stop(env, dev, th);
1531 lfsck_ibits_unlock(&lh, LCK_EX);
1534 CDEBUG(D_LFSCK, "%s: namespace LFSCK remove %s linkEA entry "
1535 "for the object: "DFID", parent "DFID", name %.*s\n",
1536 lfsck_lfsck2name(lfsck), next ? "invalid" : "redundant",
1537 PFID(lfsck_dto2fid(obj)), PFID(pfid), cname->ln_namelen,
1541 struct lfsck_namespace *ns = com->lc_file_ram;
1543 ns->ln_flags |= LF_INCONSISTENT;
1550 * Conditionally remove the specified entry from the linkEA.
1552 * Take the parent lock firstly, then check whether the specified
1553 * name entry exists or not: if yes, do nothing; otherwise, call
1554 * lfsck_namespace_shrink_linkea() to remove the linkea entry.
1556 * \param[in] env pointer to the thread context
1557 * \param[in] com pointer to the lfsck component
1558 * \param[in] parent pointer to the parent directory
1559 * \param[in] child pointer to the child object that holds the linkEA
1560 * \param[in,out]ldata pointer to the buffer that holds the linkEA
1561 * \param[in] cname the name for the child in the parent directory
1562 * \param[in] pfid the parent directory's FID for the linkEA
1564 * \retval positive number for repaired cases
1565 * \retval 0 if nothing to be repaired
1566 * \retval negative error number on failure
1568 static int lfsck_namespace_shrink_linkea_cond(const struct lu_env *env,
1569 struct lfsck_component *com,
1570 struct dt_object *parent,
1571 struct dt_object *child,
1572 struct linkea_data *ldata,
1573 struct lu_name *cname,
1574 struct lu_fid *pfid)
1576 struct lu_fid *cfid = &lfsck_env_info(env)->lti_fid3;
1577 struct lustre_handle lh = { 0 };
1581 rc = lfsck_ibits_lock(env, com->lc_lfsck, parent, &lh,
1582 MDS_INODELOCK_UPDATE, LCK_EX);
1586 dt_read_lock(env, parent, 0);
1587 if (unlikely(lfsck_is_dead_obj(parent))) {
1588 dt_read_unlock(env, parent);
1589 lfsck_ibits_unlock(&lh, LCK_EX);
1590 rc = lfsck_namespace_shrink_linkea(env, com, child, ldata,
1596 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
1597 (const struct dt_key *)cname->ln_name,
1599 dt_read_unlock(env, parent);
1601 /* It is safe to release the ldlm lock, because when the logic come
1602 * here, we have got all the needed information above whether the
1603 * linkEA entry is valid or not. It is not important that others
1604 * may add new linkEA entry after the ldlm lock released. If other
1605 * has removed the specified linkEA entry by race, then it is OK,
1606 * because the subsequent lfsck_namespace_shrink_linkea() can handle
1608 lfsck_ibits_unlock(&lh, LCK_EX);
1609 if (rc == -ENOENT) {
1610 rc = lfsck_namespace_shrink_linkea(env, com, child, ldata,
1619 /* The LFSCK just found some internal status of cross-MDTs
1620 * create operation. That is normal. */
1621 if (lu_fid_eq(cfid, lfsck_dto2fid(child))) {
1622 linkea_next_entry(ldata);
1627 rc = lfsck_namespace_shrink_linkea(env, com, child, ldata, cname,
1634 * Conditionally replace name entry in the parent.
1636 * As required, the LFSCK may re-create the lost MDT-object for dangling
1637 * name entry, but such repairing may be wrong because of bad FID in the
1638 * name entry. As the LFSCK processing, the real MDT-object may be found,
1639 * then the LFSCK should check whether the former re-created MDT-object
1640 * has been modified or not, if not, then destroy it and update the name
1641 * entry in the parent to reference the real MDT-object.
1643 * \param[in] env pointer to the thread context
1644 * \param[in] com pointer to the lfsck component
1645 * \param[in] parent pointer to the parent directory
1646 * \param[in] child pointer to the MDT-object that may be the real
1647 * MDT-object corresponding to the name entry in parent
1648 * \param[in] cfid the current FID in the name entry
1649 * \param[in] cname contains the name of the child in the parent directory
1651 * \retval positive number for repaired cases
1652 * \retval 0 if nothing to be repaired
1653 * \retval negative error number on failure
1655 static int lfsck_namespace_replace_cond(const struct lu_env *env,
1656 struct lfsck_component *com,
1657 struct dt_object *parent,
1658 struct dt_object *child,
1659 const struct lu_fid *cfid,
1660 const struct lu_name *cname)
1662 struct lfsck_thread_info *info = lfsck_env_info(env);
1663 struct lu_fid *tfid = &info->lti_fid5;
1664 struct lu_attr *la = &info->lti_la;
1665 struct dt_insert_rec *rec = &info->lti_dt_rec;
1666 struct lfsck_instance *lfsck = com->lc_lfsck;
1667 struct dt_device *dev = lfsck->li_next;
1668 const char *name = cname->ln_name;
1669 struct dt_object *obj = NULL;
1670 struct lustre_handle plh = { 0 };
1671 struct lustre_handle clh = { 0 };
1672 struct linkea_data ldata = { 0 };
1673 struct thandle *th = NULL;
1678 rc = lfsck_ibits_lock(env, lfsck, parent, &plh,
1679 MDS_INODELOCK_UPDATE, LCK_EX);
1683 if (!fid_is_sane(cfid)) {
1688 obj = lfsck_object_find(env, lfsck, cfid);
1691 if (rc == -ENOENT) {
1699 if (!dt_object_exists(obj)) {
1704 rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
1705 (const struct dt_key *)name, BYPASS_CAPA);
1706 if (rc == -ENOENT) {
1714 /* Someone changed the name entry, cannot replace it. */
1715 if (!lu_fid_eq(cfid, tfid))
1718 /* lock the object to be destroyed. */
1719 rc = lfsck_ibits_lock(env, lfsck, obj, &clh,
1720 MDS_INODELOCK_UPDATE |
1721 MDS_INODELOCK_XATTR, LCK_EX);
1725 if (unlikely(lfsck_is_dead_obj(obj))) {
1730 rc = dt_attr_get(env, obj, la, BYPASS_CAPA);
1734 /* The object has been modified by other(s), or it is not created by
1735 * LFSCK, the two cases are indistinguishable. So cannot replace it. */
1736 if (la->la_ctime != 0)
1739 if (S_ISREG(la->la_mode)) {
1740 rc = dt_xattr_get(env, obj, &LU_BUF_NULL, XATTR_NAME_LOV,
1742 /* If someone has created related OST-object(s),
1744 if ((rc > 0) || (rc < 0 && rc != -ENODATA))
1745 GOTO(log, rc = (rc > 0 ? 0 : rc));
1749 dt_read_lock(env, child, 0);
1750 rc = lfsck_links_read2(env, child, &ldata);
1751 dt_read_unlock(env, child);
1753 /* Someone changed the child, no need to replace. */
1760 rc = linkea_links_find(&ldata, cname, lfsck_dto2fid(parent));
1761 /* Someone moved the child, no need to replace. */
1765 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
1768 th = dt_trans_create(env, dev);
1770 GOTO(log, rc = PTR_ERR(th));
1773 rc = dt_declare_destroy(env, obj, th);
1778 rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
1782 rec->rec_type = S_IFDIR;
1783 rec->rec_fid = lfsck_dto2fid(child);
1784 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
1785 (const struct dt_key *)name, th);
1789 rc = dt_trans_start(env, dev, th);
1794 rc = dt_destroy(env, obj, th);
1799 /* The old name entry maybe not exist. */
1800 dt_delete(env, parent, (const struct dt_key *)name, th,
1803 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
1804 (const struct dt_key *)name, th, BYPASS_CAPA, 1);
1806 GOTO(stop, rc = (rc == 0 ? 1 : rc));
1809 dt_trans_stop(env, dev, th);
1812 lfsck_ibits_unlock(&clh, LCK_EX);
1813 lfsck_ibits_unlock(&plh, LCK_EX);
1814 if (obj != NULL && !IS_ERR(obj))
1815 lfsck_object_put(env, obj);
1817 CDEBUG(D_LFSCK, "%s: namespace LFSCK conditionally destroy the "
1818 "object "DFID" because of conflict with the object "DFID
1819 " under the parent "DFID" with name %s: rc = %d\n",
1820 lfsck_lfsck2name(lfsck), PFID(cfid),
1821 PFID(lfsck_dto2fid(child)), PFID(lfsck_dto2fid(parent)),
1828 * Overwrite the linkEA for the object with the given ldata.
1830 * The caller should take the ldlm lock before the calling.
1832 * \param[in] env pointer to the thread context
1833 * \param[in] com pointer to the lfsck component
1834 * \param[in] obj pointer to the dt_object to be handled
1835 * \param[in] ldata pointer to the new linkEA data
1837 * \retval positive number for repaired cases
1838 * \retval 0 if nothing to be repaired
1839 * \retval negative error number on failure
1841 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
1842 struct lfsck_component *com,
1843 struct dt_object *obj,
1844 struct linkea_data *ldata)
1846 struct lfsck_instance *lfsck = com->lc_lfsck;
1847 struct dt_device *dev = lfsck->li_bottom;
1848 struct thandle *th = NULL;
1849 struct lu_buf linkea_buf;
1853 LASSERT(!dt_object_remote(obj));
1855 th = dt_trans_create(env, dev);
1857 GOTO(log, rc = PTR_ERR(th));
1859 lfsck_buf_init(&linkea_buf, ldata->ld_buf->lb_buf,
1860 ldata->ld_leh->leh_len);
1861 rc = dt_declare_xattr_set(env, obj, &linkea_buf,
1862 XATTR_NAME_LINK, 0, th);
1866 rc = dt_trans_start_local(env, dev, th);
1870 dt_write_lock(env, obj, 0);
1871 if (unlikely(lfsck_is_dead_obj(obj)))
1872 GOTO(unlock, rc = 0);
1874 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
1875 GOTO(unlock, rc = 1);
1877 rc = dt_xattr_set(env, obj, &linkea_buf,
1878 XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
1880 GOTO(unlock, rc = (rc == 0 ? 1 : rc));
1883 dt_write_unlock(env, obj);
1886 dt_trans_stop(env, dev, th);
1889 CDEBUG(D_LFSCK, "%s: namespace LFSCK rebuild linkEA for the "
1890 "object "DFID": rc = %d\n",
1891 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(obj)), rc);
1894 struct lfsck_namespace *ns = com->lc_file_ram;
1896 ns->ln_flags |= LF_INCONSISTENT;
1903 * Repair invalid name entry.
1905 * If the name entry contains invalid information, such as bad file type
1906 * or (and) corrupted object FID, then either remove the name entry or
1907 * udpate the name entry with the given (right) information.
1909 * \param[in] env pointer to the thread context
1910 * \param[in] com pointer to the lfsck component
1911 * \param[in] parent pointer to the parent directory
1912 * \param[in] child pointer to the object referenced by the name entry
1913 * \param[in] name the old name of the child under the parent directory
1914 * \param[in] name2 the new name of the child under the parent directory
1915 * \param[in] type the type claimed by the name entry
1916 * \param[in] update update the name entry if true; otherwise, remove it
1917 * \param[in] dec decrease the parent nlink count if true
1919 * \retval positive number for repaired successfully
1920 * \retval 0 if nothing to be repaired
1921 * \retval negative error number on failure
1923 int lfsck_namespace_repair_dirent(const struct lu_env *env,
1924 struct lfsck_component *com,
1925 struct dt_object *parent,
1926 struct dt_object *child,
1927 const char *name, const char *name2,
1928 __u16 type, bool update, bool dec)
1930 struct lfsck_thread_info *info = lfsck_env_info(env);
1931 struct dt_insert_rec *rec = &info->lti_dt_rec;
1932 const struct lu_fid *cfid = lfsck_dto2fid(child);
1933 struct lu_fid *tfid = &info->lti_fid5;
1934 struct lfsck_instance *lfsck = com->lc_lfsck;
1935 struct dt_device *dev = lfsck->li_next;
1936 struct thandle *th = NULL;
1937 struct lustre_handle lh = { 0 };
1941 if (unlikely(!dt_try_as_dir(env, parent)))
1942 GOTO(log, rc = -ENOTDIR);
1944 rc = lfsck_ibits_lock(env, lfsck, parent, &lh,
1945 MDS_INODELOCK_UPDATE, LCK_EX);
1949 th = dt_trans_create(env, dev);
1951 GOTO(unlock1, rc = PTR_ERR(th));
1953 rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
1958 rec->rec_type = lfsck_object_type(child) & S_IFMT;
1959 rec->rec_fid = cfid;
1960 rc = dt_declare_insert(env, parent,
1961 (const struct dt_rec *)rec,
1962 (const struct dt_key *)name2, th);
1968 rc = dt_declare_ref_del(env, parent, th);
1973 rc = dt_trans_start(env, dev, th);
1977 dt_write_lock(env, parent, 0);
1978 rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
1979 (const struct dt_key *)name, BYPASS_CAPA);
1980 /* Someone has removed the bad name entry by race. */
1982 GOTO(unlock2, rc = 0);
1987 /* Someone has removed the bad name entry and reused it for other
1988 * object by race. */
1989 if (!lu_fid_eq(tfid, cfid))
1990 GOTO(unlock2, rc = 0);
1992 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
1993 GOTO(unlock2, rc = 1);
1995 rc = dt_delete(env, parent, (const struct dt_key *)name, th,
2001 rc = dt_insert(env, parent,
2002 (const struct dt_rec *)rec,
2003 (const struct dt_key *)name2, th,
2010 rc = dt_ref_del(env, parent, th);
2015 GOTO(unlock2, rc = (rc == 0 ? 1 : rc));
2018 dt_write_unlock(env, parent);
2021 dt_trans_stop(env, dev, th);
2023 /* We are not sure whether the child will become orphan or not.
2024 * Record it in the LFSCK trace file for further checking in
2025 * the second-stage scanning. */
2026 if (!update && !dec && rc == 0)
2027 lfsck_namespace_trace_update(env, com, cfid,
2028 LNTF_CHECK_LINKEA, true);
2031 lfsck_ibits_unlock(&lh, LCK_EX);
2034 CDEBUG(D_LFSCK, "%s: namespace LFSCK assistant found bad name "
2035 "entry for: parent "DFID", child "DFID", name %s, type "
2036 "in name entry %o, type claimed by child %o. repair it "
2037 "by %s with new name2 %s: rc = %d\n", lfsck_lfsck2name(lfsck),
2038 PFID(lfsck_dto2fid(parent)), PFID(lfsck_dto2fid(child)),
2039 name, type, update ? lfsck_object_type(child) : 0,
2040 update ? "updating" : "removing", name2, rc);
2043 struct lfsck_namespace *ns = com->lc_file_ram;
2045 ns->ln_flags |= LF_INCONSISTENT;
2052 * Update the ".." name entry for the given object.
2054 * The object's ".." is corrupted, this function will update the ".." name
2055 * entry with the given pfid, and the linkEA with the given ldata.
2057 * The caller should take the ldlm lock before the calling.
2059 * \param[in] env pointer to the thread context
2060 * \param[in] com pointer to the lfsck component
2061 * \param[in] obj pointer to the dt_object to be handled
2062 * \param[in] pfid the new fid for the object's ".." name entry
2063 * \param[in] cname the name for the @obj in the parent directory
2065 * \retval positive number for repaired cases
2066 * \retval 0 if nothing to be repaired
2067 * \retval negative error number on failure
2069 static int lfsck_namespace_repair_unmatched_pairs(const struct lu_env *env,
2070 struct lfsck_component *com,
2071 struct dt_object *obj,
2072 const struct lu_fid *pfid,
2073 struct lu_name *cname)
2075 struct lfsck_thread_info *info = lfsck_env_info(env);
2076 struct dt_insert_rec *rec = &info->lti_dt_rec;
2077 struct lfsck_instance *lfsck = com->lc_lfsck;
2078 struct dt_device *dev = lfsck->li_bottom;
2079 struct thandle *th = NULL;
2080 struct linkea_data ldata = { 0 };
2081 struct lu_buf linkea_buf;
2085 LASSERT(!dt_object_remote(obj));
2086 LASSERT(S_ISDIR(lfsck_object_type(obj)));
2088 rc = linkea_data_new(&ldata, &info->lti_big_buf);
2092 rc = linkea_add_buf(&ldata, cname, pfid);
2096 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
2097 ldata.ld_leh->leh_len);
2099 th = dt_trans_create(env, dev);
2101 GOTO(log, rc = PTR_ERR(th));
2103 rc = dt_declare_delete(env, obj, (const struct dt_key *)dotdot, th);
2107 rec->rec_type = S_IFDIR;
2108 rec->rec_fid = pfid;
2109 rc = dt_declare_insert(env, obj, (const struct dt_rec *)rec,
2110 (const struct dt_key *)dotdot, th);
2114 rc = dt_declare_xattr_set(env, obj, &linkea_buf,
2115 XATTR_NAME_LINK, 0, th);
2119 rc = dt_trans_start_local(env, dev, th);
2123 dt_write_lock(env, obj, 0);
2124 if (unlikely(lfsck_is_dead_obj(obj)))
2125 GOTO(unlock, rc = 0);
2127 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
2128 GOTO(unlock, rc = 1);
2130 /* The old ".." name entry maybe not exist. */
2131 dt_delete(env, obj, (const struct dt_key *)dotdot, th,
2134 rc = dt_insert(env, obj, (const struct dt_rec *)rec,
2135 (const struct dt_key *)dotdot, th, BYPASS_CAPA, 1);
2139 rc = dt_xattr_set(env, obj, &linkea_buf,
2140 XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
2142 GOTO(unlock, rc = (rc == 0 ? 1 : rc));
2145 dt_write_unlock(env, obj);
2148 dt_trans_stop(env, dev, th);
2151 CDEBUG(D_LFSCK, "%s: namespace LFSCK rebuild dotdot name entry for "
2152 "the object "DFID", new parent "DFID": rc = %d\n",
2153 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(obj)),
2157 struct lfsck_namespace *ns = com->lc_file_ram;
2159 ns->ln_flags |= LF_INCONSISTENT;
2166 * Handle orphan @obj during Double Scan Directory.
2168 * Remove the @obj's current (invalid) linkEA entries, and insert
2169 * it in the directory .lustre/lost+found/MDTxxxx/ with the name:
2170 * ${FID}-${PFID}-D-${conflict_version}
2172 * The caller should take the ldlm lock before the calling.
2174 * \param[in] env pointer to the thread context
2175 * \param[in] com pointer to the lfsck component
2176 * \param[in] obj pointer to the orphan object to be handled
2177 * \param[in] pfid the new fid for the object's ".." name entry
2178 * \param[in,out] lh ldlm lock handler for the given @obj
2179 * \param[out] type to tell the caller what the inconsistency is
2181 * \retval positive number for repaired cases
2182 * \retval 0 if nothing to be repaired
2183 * \retval negative error number on failure
2186 lfsck_namespace_dsd_orphan(const struct lu_env *env,
2187 struct lfsck_component *com,
2188 struct dt_object *obj,
2189 const struct lu_fid *pfid,
2190 struct lustre_handle *lh,
2191 enum lfsck_namespace_inconsistency_type *type)
2193 struct lfsck_thread_info *info = lfsck_env_info(env);
2194 struct lfsck_namespace *ns = com->lc_file_ram;
2198 /* Remove the unrecognized linkEA. */
2199 rc = lfsck_namespace_links_remove(env, com, obj);
2200 lfsck_ibits_unlock(lh, LCK_EX);
2201 if (rc < 0 && rc != -ENODATA)
2204 *type = LNIT_MUL_REF;
2206 /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT has
2207 * ever tried to verify some remote MDT-object that resides on this
2208 * MDT, but this MDT failed to respond such request. So means there
2209 * may be some remote name entry on other MDT that references this
2210 * object with another name, so we cannot know whether this linkEA
2211 * is valid or not. So keep it there and maybe resolved when next
2213 if (ns->ln_flags & LF_INCOMPLETE)
2216 /* The unique linkEA is invalid, even if the ".." name entry may be
2217 * valid, we still cannot know via which name entry this directory
2218 * will be referenced. Then handle it as pure orphan. */
2219 snprintf(info->lti_tmpbuf, sizeof(info->lti_tmpbuf),
2220 "-"DFID, PFID(pfid));
2221 rc = lfsck_namespace_insert_orphan(env, com, obj,
2222 info->lti_tmpbuf, "D", NULL);
2228 * Double Scan Directory object for single linkEA entry case.
2230 * The given @child has unique linkEA entry. If the linkEA entry is valid,
2231 * then check whether the name is in the namespace or not, if not, add the
2232 * missing name entry back to namespace. If the linkEA entry is invalid,
2233 * then remove it and insert the @child in the .lustre/lost+found/MDTxxxx/
2236 * \param[in] env pointer to the thread context
2237 * \param[in] com pointer to the lfsck component
2238 * \param[in] child pointer to the directory to be double scanned
2239 * \param[in] pfid the FID corresponding to the ".." entry
2240 * \param[in] ldata pointer to the linkEA data for the given @child
2241 * \param[in,out] lh ldlm lock handler for the given @child
2242 * \param[out] type to tell the caller what the inconsistency is
2243 * \param[in] retry if found inconsistency, but the caller does not hold
2244 * ldlm lock on the @child, then set @retry as true
2246 * \retval positive number for repaired cases
2247 * \retval 0 if nothing to be repaired
2248 * \retval negative error number on failure
2251 lfsck_namespace_dsd_single(const struct lu_env *env,
2252 struct lfsck_component *com,
2253 struct dt_object *child,
2254 const struct lu_fid *pfid,
2255 struct linkea_data *ldata,
2256 struct lustre_handle *lh,
2257 enum lfsck_namespace_inconsistency_type *type,
2260 struct lfsck_thread_info *info = lfsck_env_info(env);
2261 struct lu_name *cname = &info->lti_name;
2262 const struct lu_fid *cfid = lfsck_dto2fid(child);
2263 struct lu_fid *tfid = &info->lti_fid3;
2264 struct lfsck_namespace *ns = com->lc_file_ram;
2265 struct lfsck_instance *lfsck = com->lc_lfsck;
2266 struct dt_object *parent = NULL;
2270 lfsck_namespace_unpack_linkea_entry(ldata, cname, tfid, info->lti_key);
2271 /* The unique linkEA entry with bad parent will be handled as orphan. */
2272 if (!fid_is_sane(tfid)) {
2273 if (!lustre_handle_is_used(lh) && retry != NULL)
2276 rc = lfsck_namespace_dsd_orphan(env, com, child,
2282 parent = lfsck_object_find_bottom(env, lfsck, tfid);
2284 GOTO(out, rc = PTR_ERR(parent));
2286 /* We trust the unique linkEA entry in spite of whether it matches the
2287 * ".." name entry or not. Because even if the linkEA entry is wrong
2288 * and the ".." name entry is right, we still cannot know via which
2289 * name entry the child will be referenced, since all known entries
2290 * have been verified during the first-stage scanning. */
2291 if (!dt_object_exists(parent)) {
2292 /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT
2293 * has ever tried to verify some remote MDT-object that resides
2294 * on this MDT, but this MDT failed to respond such request. So
2295 * means there may be some remote name entry on other MDT that
2296 * references this object with another name, so we cannot know
2297 * whether this linkEA is valid or not. So keep it there and
2298 * maybe resolved when next LFSCK run. */
2299 if (ns->ln_flags & LF_INCOMPLETE)
2302 if (!lustre_handle_is_used(lh) && retry != NULL) {
2308 lfsck_ibits_unlock(lh, LCK_EX);
2311 /* Create the lost parent as an orphan. */
2312 rc = lfsck_namespace_create_orphan(env, com, parent);
2314 /* Add the missing name entry to the parent. */
2315 rc = lfsck_namespace_insert_normal(env, com, parent,
2316 child, cname->ln_name);
2317 if (unlikely(rc == -EEXIST)) {
2318 /* Unfortunately, someone reused the name
2319 * under the parent by race. So we have
2320 * to remove the linkEA entry from
2321 * current child object. It means that the
2322 * LFSCK cannot recover the system
2323 * totally back to its original status,
2324 * but it is necessary to make the
2325 * current system to be consistent. */
2326 rc = lfsck_namespace_shrink_linkea(env,
2330 snprintf(info->lti_tmpbuf,
2331 sizeof(info->lti_tmpbuf),
2332 "-"DFID, PFID(pfid));
2333 rc = lfsck_namespace_insert_orphan(env,
2334 com, child, info->lti_tmpbuf,
2343 /* The unique linkEA entry with bad parent will be handled as orphan. */
2344 if (unlikely(!dt_try_as_dir(env, parent))) {
2345 if (!lustre_handle_is_used(lh) && retry != NULL)
2348 rc = lfsck_namespace_dsd_orphan(env, com, child,
2354 rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
2355 (const struct dt_key *)cname->ln_name, BYPASS_CAPA);
2356 if (rc == -ENOENT) {
2357 /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT
2358 * has ever tried to verify some remote MDT-object that resides
2359 * on this MDT, but this MDT failed to respond such request. So
2360 * means there may be some remote name entry on other MDT that
2361 * references this object with another name, so we cannot know
2362 * whether this linkEA is valid or not. So keep it there and
2363 * maybe resolved when next LFSCK run. */
2364 if (ns->ln_flags & LF_INCOMPLETE)
2367 if (!lustre_handle_is_used(lh) && retry != NULL) {
2373 lfsck_ibits_unlock(lh, LCK_EX);
2374 /* Add the missing name entry back to the namespace. */
2375 rc = lfsck_namespace_insert_normal(env, com, parent, child,
2377 if (unlikely(rc == -ESTALE))
2378 /* It may happen when the remote object has been
2379 * removed, but the local MDT is not aware of that. */
2382 if (unlikely(rc == -EEXIST)) {
2383 /* Unfortunately, someone reused the name under the
2384 * parent by race. So we have to remove the linkEA
2385 * entry from current child object. It means that the
2386 * LFSCK cannot recover the system totally back to
2387 * its original status, but it is necessary to make
2388 * the current system to be consistent.
2390 * It also may be because of the LFSCK found some
2391 * internal status of create operation. Under such
2392 * case, nothing to be done. */
2393 rc = lfsck_namespace_shrink_linkea_cond(env, com,
2394 parent, child, ldata, cname, tfid);
2396 snprintf(info->lti_tmpbuf,
2397 sizeof(info->lti_tmpbuf),
2398 "-"DFID, PFID(pfid));
2399 rc = lfsck_namespace_insert_orphan(env, com,
2400 child, info->lti_tmpbuf, "D", NULL);
2410 if (!lu_fid_eq(tfid, cfid)) {
2411 if (!lustre_handle_is_used(lh) && retry != NULL) {
2417 lfsck_ibits_unlock(lh, LCK_EX);
2418 /* The name entry references another MDT-object that
2419 * may be created by the LFSCK for repairing dangling
2420 * name entry. Try to replace it. */
2421 rc = lfsck_namespace_replace_cond(env, com, parent, child,
2424 rc = lfsck_namespace_dsd_orphan(env, com, child,
2430 /* The ".." name entry is wrong, update it. */
2431 if (!lu_fid_eq(pfid, lfsck_dto2fid(parent))) {
2432 if (!lustre_handle_is_used(lh) && retry != NULL) {
2438 *type = LNIT_UNMATCHED_PAIRS;
2439 rc = lfsck_namespace_repair_unmatched_pairs(env, com, child,
2440 lfsck_dto2fid(parent), cname);
2446 if (parent != NULL && !IS_ERR(parent))
2447 lfsck_object_put(env, parent);
2453 * Double Scan Directory object for multiple linkEA entries case.
2455 * The given @child has multiple linkEA entries. There is at most one linkEA
2456 * entry will be valid, all the others will be removed. Firstly, the function
2457 * will try to find out the linkEA entry for which the name entry exists under
2458 * the given parent (@pfid). If there is no linkEA entry that matches the given
2459 * ".." name entry, then tries to find out the first linkEA entry that both the
2460 * parent and the name entry exist to rebuild a new ".." name entry.
2462 * \param[in] env pointer to the thread context
2463 * \param[in] com pointer to the lfsck component
2464 * \param[in] child pointer to the directory to be double scanned
2465 * \param[in] pfid the FID corresponding to the ".." entry
2466 * \param[in] ldata pointer to the linkEA data for the given @child
2467 * \param[in,out] lh ldlm lock handler for the given @child
2468 * \param[out] type to tell the caller what the inconsistency is
2469 * \param[in] lpf true if the ".." entry is under lost+found/MDTxxxx/
2471 * \retval positive number for repaired cases
2472 * \retval 0 if nothing to be repaired
2473 * \retval negative error number on failure
2476 lfsck_namespace_dsd_multiple(const struct lu_env *env,
2477 struct lfsck_component *com,
2478 struct dt_object *child,
2479 const struct lu_fid *pfid,
2480 struct linkea_data *ldata,
2481 struct lustre_handle *lh,
2482 enum lfsck_namespace_inconsistency_type *type,
2485 struct lfsck_thread_info *info = lfsck_env_info(env);
2486 struct lu_name *cname = &info->lti_name;
2487 const struct lu_fid *cfid = lfsck_dto2fid(child);
2488 struct lu_fid *tfid = &info->lti_fid3;
2489 struct lu_fid *pfid2 = &info->lti_fid4;
2490 struct lfsck_namespace *ns = com->lc_file_ram;
2491 struct lfsck_instance *lfsck = com->lc_lfsck;
2492 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2493 struct dt_object *parent = NULL;
2494 struct linkea_data ldata_new = { 0 };
2501 while (ldata->ld_lee != NULL) {
2502 lfsck_namespace_unpack_linkea_entry(ldata, cname, tfid,
2504 /* Drop repeated linkEA entries. */
2505 lfsck_namespace_filter_linkea_entry(ldata, cname, tfid, true);
2506 /* Drop invalid linkEA entry. */
2507 if (!fid_is_sane(tfid)) {
2508 linkea_del_buf(ldata, cname);
2512 /* If current dotdot is the .lustre/lost+found/MDTxxxx/,
2513 * then it is possible that: the directry object has ever
2514 * been lost, but its name entry was there. In the former
2515 * LFSCK run, during the first-stage scanning, the LFSCK
2516 * found the dangling name entry, but it did not recreate
2517 * the lost object, and when moved to the second-stage
2518 * scanning, some children objects of the lost directory
2519 * object were found, then the LFSCK recreated such lost
2520 * directory object as an orphan.
2522 * When the LFSCK runs again, if the dangling name is still
2523 * there, the LFSCK should move the orphan directory object
2524 * back to the normal namespace. */
2525 if (!lpf && !lu_fid_eq(pfid, tfid) && once) {
2526 linkea_next_entry(ldata);
2530 parent = lfsck_object_find_bottom(env, lfsck, tfid);
2532 RETURN(PTR_ERR(parent));
2534 if (!dt_object_exists(parent)) {
2535 lfsck_object_put(env, parent);
2536 if (ldata->ld_leh->leh_reccount > 1) {
2537 /* If it is NOT the last linkEA entry, then
2538 * there is still other chance to make the
2539 * child to be visible via other parent, then
2540 * remove this linkEA entry. */
2541 linkea_del_buf(ldata, cname);
2548 /* The linkEA entry with bad parent will be removed. */
2549 if (unlikely(!dt_try_as_dir(env, parent))) {
2550 lfsck_object_put(env, parent);
2551 linkea_del_buf(ldata, cname);
2555 rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
2556 (const struct dt_key *)cname->ln_name,
2558 *pfid2 = *lfsck_dto2fid(parent);
2559 if (rc == -ENOENT) {
2560 lfsck_object_put(env, parent);
2561 linkea_next_entry(ldata);
2566 lfsck_object_put(env, parent);
2571 if (lu_fid_eq(tfid, cfid)) {
2572 lfsck_object_put(env, parent);
2573 if (!lu_fid_eq(pfid, pfid2)) {
2574 *type = LNIT_UNMATCHED_PAIRS;
2575 rc = lfsck_namespace_repair_unmatched_pairs(env,
2576 com, child, pfid2, cname);
2582 /* It is the most common case that we find the
2583 * name entry corresponding to the linkEA entry
2584 * that matches the ".." name entry. */
2585 rc = linkea_data_new(&ldata_new, &info->lti_big_buf);
2589 rc = linkea_add_buf(&ldata_new, cname, pfid2);
2593 rc = lfsck_namespace_rebuild_linkea(env, com, child,
2598 linkea_del_buf(ldata, cname);
2599 linkea_first_entry(ldata);
2600 /* There may be some invalid dangling name entries under
2601 * other parent directories, remove all of them. */
2602 while (ldata->ld_lee != NULL) {
2603 lfsck_namespace_unpack_linkea_entry(ldata,
2604 cname, tfid, info->lti_key);
2605 if (!fid_is_sane(tfid))
2608 parent = lfsck_object_find_bottom(env, lfsck,
2610 if (IS_ERR(parent)) {
2611 rc = PTR_ERR(parent);
2612 if (rc != -ENOENT &&
2613 bk->lb_param & LPF_FAILOUT)
2619 if (!dt_object_exists(parent)) {
2620 lfsck_object_put(env, parent);
2624 rc = lfsck_namespace_repair_dirent(env, com,
2625 parent, child, cname->ln_name,
2626 cname->ln_name, S_IFDIR, false, true);
2627 lfsck_object_put(env, parent);
2629 if (bk->lb_param & LPF_FAILOUT)
2638 linkea_del_buf(ldata, cname);
2641 ns->ln_dirent_repaired += count;
2646 lfsck_ibits_unlock(lh, LCK_EX);
2647 /* The name entry references another MDT-object that may be
2648 * created by the LFSCK for repairing dangling name entry.
2649 * Try to replace it. */
2650 rc = lfsck_namespace_replace_cond(env, com, parent, child,
2652 lfsck_object_put(env, parent);
2659 linkea_del_buf(ldata, cname);
2662 if (ldata->ld_leh->leh_reccount == 1) {
2663 rc = lfsck_namespace_dsd_single(env, com, child, pfid, ldata,
2669 /* All linkEA entries are invalid and removed, then handle the @child
2671 if (ldata->ld_leh->leh_reccount == 0) {
2672 rc = lfsck_namespace_dsd_orphan(env, com, child, pfid, lh,
2678 linkea_first_entry(ldata);
2679 /* If the dangling name entry for the orphan directory object has
2680 * been remvoed, then just check whether the directory object is
2681 * still under the .lustre/lost+found/MDTxxxx/ or not. */
2687 /* There is no linkEA entry that matches the ".." name entry. Find
2688 * the first linkEA entry that both parent and name entry exist to
2689 * rebuild a new ".." name entry. */
2699 * Repair the object's nlink attribute.
2701 * If all the known name entries have been verified, then the object's hard
2702 * link attribute should match the object's linkEA entries count unless the
2703 * object's has too much hard link to be recorded in the linkEA. Such cases
2704 * should have been marked in the LFSCK trace file. Otherwise, trust the
2705 * linkEA to update the object's nlink attribute.
2707 * \param[in] env pointer to the thread context
2708 * \param[in] com pointer to the lfsck component
2709 * \param[in] obj pointer to the dt_object to be handled
2710 * \param[in,out] nlink pointer to buffer to object's hard lock count before
2711 * and after the repairing
2713 * \retval positive number for repaired cases
2714 * \retval 0 if nothing to be repaired
2715 * \retval negative error number on failure
2717 static int lfsck_namespace_repair_nlink(const struct lu_env *env,
2718 struct lfsck_component *com,
2719 struct dt_object *obj, __u32 *nlink)
2721 struct lfsck_thread_info *info = lfsck_env_info(env);
2722 struct lu_attr *la = &info->lti_la3;
2723 struct lu_fid *tfid = &info->lti_fid3;
2724 struct lfsck_namespace *ns = com->lc_file_ram;
2725 struct lfsck_instance *lfsck = com->lc_lfsck;
2726 struct dt_device *dev = lfsck->li_bottom;
2727 const struct lu_fid *cfid = lfsck_dto2fid(obj);
2728 struct dt_object *child = NULL;
2729 struct thandle *th = NULL;
2730 struct linkea_data ldata = { 0 };
2731 struct lustre_handle lh = { 0 };
2737 LASSERT(!dt_object_remote(obj));
2738 LASSERT(S_ISREG(lfsck_object_type(obj)));
2740 child = lfsck_object_find_by_dev(env, dev, cfid);
2742 GOTO(log, rc = PTR_ERR(child));
2744 rc = lfsck_ibits_lock(env, lfsck, child, &lh,
2745 MDS_INODELOCK_UPDATE |
2746 MDS_INODELOCK_XATTR, LCK_EX);
2750 th = dt_trans_create(env, dev);
2752 GOTO(log, rc = PTR_ERR(th));
2754 la->la_valid = LA_NLINK;
2755 rc = dt_declare_attr_set(env, child, la, th);
2759 rc = dt_trans_start_local(env, dev, th);
2763 dt_write_lock(env, child, 0);
2764 /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT has
2765 * ever tried to verify some remote MDT-object that resides on this
2766 * MDT, but this MDT failed to respond such request. So means there
2767 * may be some remote name entry on other MDT that references this
2768 * object with another name, so we cannot know whether this linkEA
2769 * is valid or not. So keep it there and maybe resolved when next
2771 if (ns->ln_flags & LF_INCOMPLETE)
2772 GOTO(unlock, rc = 0);
2774 fid_cpu_to_be(tfid, cfid);
2775 rc = dt_lookup(env, com->lc_obj, (struct dt_rec *)&flags,
2776 (const struct dt_key *)tfid, BYPASS_CAPA);
2780 if (flags & LNTF_SKIP_NLINK)
2781 GOTO(unlock, rc = 0);
2783 rc = lfsck_links_read2(env, child, &ldata);
2785 GOTO(unlock, rc = 0);
2790 if (*nlink == ldata.ld_leh->leh_reccount)
2791 GOTO(unlock, rc = 0);
2793 la->la_nlink = *nlink = ldata.ld_leh->leh_reccount;
2794 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
2795 GOTO(unlock, rc = 1);
2797 rc = dt_attr_set(env, child, la, th, BYPASS_CAPA);
2799 GOTO(unlock, rc = (rc == 0 ? 1 : rc));
2802 dt_write_unlock(env, child);
2805 dt_trans_stop(env, dev, th);
2808 lfsck_ibits_unlock(&lh, LCK_EX);
2809 if (child != NULL && !IS_ERR(child))
2810 lfsck_object_put(env, child);
2812 CDEBUG(D_LFSCK, "%s: namespace LFSCK repaired the object "DFID"'s "
2813 "nlink count from %u to %u: rc = %d\n",
2814 lfsck_lfsck2name(lfsck), PFID(cfid), old, *nlink, rc);
2817 ns->ln_flags |= LF_INCONSISTENT;
2823 * Double scan the directory object for namespace LFSCK.
2825 * This function will verify the <parent, child> pairs in the namespace tree:
2826 * the parent references the child via some name entry that should be in the
2827 * child's linkEA entry, the child should back references the parent via its
2830 * The LFSCK will scan every linkEA entry in turn until find out the first
2831 * matched pairs. If found, then all other linkEA entries will be dropped.
2832 * If all the linkEA entries cannot match the ".." name entry, then there
2833 * are serveral possible cases:
2835 * 1) If there is only one linkEA entry, then trust it as long as the PFID
2836 * in the linkEA entry is valid.
2838 * 2) If there are multiple linkEA entries, then try to find the linkEA
2839 * that matches the ".." name entry. If found, then all other entries
2840 * are invalid; otherwise, it is quite possible that the ".." name entry
2841 * is corrupted. Under such case, the LFSCK will rebuild the ".." name
2842 * entry according to the first valid linkEA entry (both the parent and
2843 * the name entry should exist).
2845 * 3) If the directory object has no (valid) linkEA entry, then the
2846 * directory object will be handled as pure orphan and inserted
2847 * in the .lustre/lost+found/MDTxxxx/ with the name:
2848 * ${self_FID}-${PFID}-D-${conflict_version}
2850 * \param[in] env pointer to the thread context
2851 * \param[in] com pointer to the lfsck component
2852 * \param[in] child pointer to the directory object to be handled
2853 * \param[in] flags to indicate the specical checking on the @child
2855 * \retval positive number for repaired cases
2856 * \retval 0 if nothing to be repaired
2857 * \retval negative error number on failure
2859 static int lfsck_namespace_double_scan_dir(const struct lu_env *env,
2860 struct lfsck_component *com,
2861 struct dt_object *child, __u8 flags)
2863 struct lfsck_thread_info *info = lfsck_env_info(env);
2864 const struct lu_fid *cfid = lfsck_dto2fid(child);
2865 struct lu_fid *pfid = &info->lti_fid2;
2866 struct lfsck_namespace *ns = com->lc_file_ram;
2867 struct lfsck_instance *lfsck = com->lc_lfsck;
2868 struct lustre_handle lh = { 0 };
2869 struct linkea_data ldata = { 0 };
2870 bool unknown = false;
2873 enum lfsck_namespace_inconsistency_type type = LNIT_BAD_LINKEA;
2877 LASSERT(!dt_object_remote(child));
2879 if (flags & (LNTF_CHECK_LINKEA | LNTF_CHECK_PARENT) &&
2880 !(lfsck->li_bookmark_ram.lb_param & LPF_ALL_TGT)) {
2881 CDEBUG(D_LFSCK, "%s: some MDT(s) maybe NOT take part in the"
2882 "the namespace LFSCK, then the LFSCK cannot guarantee"
2883 "all the name entries have been verified in first-stage"
2884 "scanning. So have to skip orphan related handling for"
2885 "the directory object "DFID" with remote name entry\n",
2886 lfsck_lfsck2name(lfsck), PFID(cfid));
2891 if (unlikely(!dt_try_as_dir(env, child)))
2892 GOTO(out, rc = -ENOTDIR);
2894 /* We only take ldlm lock on the @child when required. When the
2895 * logic comes here for the first time, it is always false. */
2899 rc = lfsck_ibits_lock(env, lfsck, child, &lh,
2900 MDS_INODELOCK_UPDATE |
2901 MDS_INODELOCK_XATTR, LCK_EX);
2906 dt_read_lock(env, child, 0);
2907 if (unlikely(lfsck_is_dead_obj(child))) {
2908 dt_read_unlock(env, child);
2913 rc = dt_lookup(env, child, (struct dt_rec *)pfid,
2914 (const struct dt_key *)dotdot, BYPASS_CAPA);
2916 if (rc != -ENOENT && rc != -ENODATA && rc != -EINVAL) {
2917 dt_read_unlock(env, child);
2922 if (!lustre_handle_is_used(&lh)) {
2923 dt_read_unlock(env, child);
2928 } else if (lfsck->li_lpf_obj != NULL &&
2929 lu_fid_eq(pfid, lfsck_dto2fid(lfsck->li_lpf_obj))) {
2933 rc = lfsck_links_read(env, child, &ldata);
2934 dt_read_unlock(env, child);
2936 if (rc != -ENODATA && rc != -EINVAL)
2939 if (!lustre_handle_is_used(&lh))
2942 if (rc == -EINVAL && !fid_is_zero(pfid)) {
2943 /* Remove the corrupted linkEA. */
2944 rc = lfsck_namespace_links_remove(env, com, child);
2946 /* Here, because of the crashed linkEA, we
2947 * cannot know whether there is some parent
2948 * that references the child directory via
2949 * some name entry or not. So keep it there,
2950 * when the LFSCK run next time, if there is
2951 * some parent that references this object,
2952 * then the LFSCK can rebuild the linkEA;
2953 * otherwise, this object will be handled
2954 * as orphan as above. */
2957 /* 1. If we have neither ".." nor linkEA,
2958 * then it is an orphan.
2960 * 2. If we only have the ".." name entry,
2961 * but no parent references this child
2962 * directory, then handle it as orphan. */
2963 lfsck_ibits_unlock(&lh, LCK_EX);
2964 type = LNIT_MUL_REF;
2966 /* If the LFSCK is marked as LF_INCOMPLETE,
2967 * then means some MDT has ever tried to
2968 * verify some remote MDT-object that resides
2969 * on this MDT, but this MDT failed to respond
2970 * such request. So means there may be some
2971 * remote name entry on other MDT that
2972 * references this object with another name,
2973 * so we cannot know whether this linkEA is
2974 * valid or not. So keep it there and maybe
2975 * resolved when next LFSCK run. */
2976 if (ns->ln_flags & LF_INCOMPLETE)
2979 snprintf(info->lti_tmpbuf, sizeof(info->lti_tmpbuf),
2980 "-"DFID, PFID(pfid));
2981 rc = lfsck_namespace_insert_orphan(env, com, child,
2982 info->lti_tmpbuf, "D", NULL);
2988 linkea_first_entry(&ldata);
2989 /* This is the most common case: the object has unique linkEA entry. */
2990 if (ldata.ld_leh->leh_reccount == 1) {
2991 rc = lfsck_namespace_dsd_single(env, com, child, pfid, &ldata,
2992 &lh, &type, &retry);
2994 LASSERT(!lustre_handle_is_used(&lh));
3003 if (!lustre_handle_is_used(&lh))
3006 if (unlikely(ldata.ld_leh->leh_reccount == 0)) {
3007 rc = lfsck_namespace_dsd_orphan(env, com, child, pfid, &lh,
3013 /* When we come here, the cases usually like that:
3014 * 1) The directory object has a corrupted linkEA entry. During the
3015 * first-stage scanning, the LFSCK cannot know such corruption,
3016 * then it appends the right linkEA entry according to the found
3017 * name entry after the bad one.
3019 * 2) The directory object has a right linkEA entry. During the
3020 * first-stage scanning, the LFSCK finds some bad name entry,
3021 * but the LFSCK cannot aware that at that time, then it adds
3022 * the bad linkEA entry for further processing. */
3023 rc = lfsck_namespace_dsd_multiple(env, com, child, pfid, &ldata,
3029 lfsck_ibits_unlock(&lh, LCK_EX);
3032 case LNIT_BAD_LINKEA:
3033 ns->ln_linkea_repaired++;
3035 case LNIT_UNMATCHED_PAIRS:
3036 ns->ln_unmatched_pairs_repaired++;