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) 2013, 2017, Intel Corporation.
26 * lustre/lfsck/lfsck_namespace.c
28 * Author: Fan, Yong <fan.yong@intel.com>
31 #define DEBUG_SUBSYSTEM S_LFSCK
33 #include <lu_object.h>
34 #include <dt_object.h>
35 #include <md_object.h>
36 #include <lustre_fid.h>
37 #include <lustre_lib.h>
38 #include <lustre_net.h>
40 #include "lfsck_internal.h"
42 #define LFSCK_NAMESPACE_MAGIC_V1 0xA0629D03
43 #define LFSCK_NAMESPACE_MAGIC_V2 0xA0621A0B
44 #define LFSCK_NAMESPACE_MAGIC_V3 0xA06249FF
46 /* For Lustre-2.x (x <= 6), the namespace LFSCK used LFSCK_NAMESPACE_MAGIC_V1
47 * as the trace file magic. When downgrade to such old release, the old LFSCK
48 * will not recognize the new LFSCK_NAMESPACE_MAGIC_V2 in the new trace file,
49 * then it will reset the whole LFSCK, and will not cause start failure. The
50 * similar case will happen when upgrade from such old release. */
51 #define LFSCK_NAMESPACE_MAGIC LFSCK_NAMESPACE_MAGIC_V3
53 enum lfsck_nameentry_check {
54 LFSCK_NAMEENTRY_DEAD = 1, /* The object has been unlinked. */
55 LFSCK_NAMEENTRY_REMOVED = 2, /* The entry has been removed. */
56 LFSCK_NAMEENTRY_RECREATED = 3, /* The entry has been recreated. */
59 static struct lfsck_namespace_req *
60 lfsck_namespace_assistant_req_init(struct lfsck_instance *lfsck,
61 struct lfsck_assistant_object *lso,
62 struct lu_dirent *ent, __u16 type)
64 struct lfsck_namespace_req *lnr;
67 size = sizeof(*lnr) + (ent->lde_namelen & ~3) + 4;
70 return ERR_PTR(-ENOMEM);
72 INIT_LIST_HEAD(&lnr->lnr_lar.lar_list);
73 lnr->lnr_lar.lar_parent = lfsck_assistant_object_get(lso);
74 lnr->lnr_lmv = lfsck_lmv_get(lfsck->li_lmv);
75 lnr->lnr_fid = ent->lde_fid;
76 lnr->lnr_dir_cookie = ent->lde_hash;
77 lnr->lnr_attr = ent->lde_attrs;
80 lnr->lnr_namelen = ent->lde_namelen;
81 memcpy(lnr->lnr_name, ent->lde_name, ent->lde_namelen);
86 static void lfsck_namespace_assistant_req_fini(const struct lu_env *env,
87 struct lfsck_assistant_req *lar)
89 struct lfsck_namespace_req *lnr =
90 container_of(lar, struct lfsck_namespace_req, lnr_lar);
92 if (lnr->lnr_lmv != NULL)
93 lfsck_lmv_put(env, lnr->lnr_lmv);
95 lfsck_assistant_object_put(env, lar->lar_parent);
96 OBD_FREE(lnr, lnr->lnr_size);
99 static void lfsck_namespace_le_to_cpu(struct lfsck_namespace *dst,
100 struct lfsck_namespace *src)
102 dst->ln_magic = le32_to_cpu(src->ln_magic);
103 dst->ln_status = le32_to_cpu(src->ln_status);
104 dst->ln_flags = le32_to_cpu(src->ln_flags);
105 dst->ln_success_count = le32_to_cpu(src->ln_success_count);
106 dst->ln_run_time_phase1 = le64_to_cpu(src->ln_run_time_phase1);
107 dst->ln_run_time_phase2 = le64_to_cpu(src->ln_run_time_phase2);
108 dst->ln_time_last_complete = le64_to_cpu(src->ln_time_last_complete);
109 dst->ln_time_latest_start = le64_to_cpu(src->ln_time_latest_start);
110 dst->ln_time_last_checkpoint =
111 le64_to_cpu(src->ln_time_last_checkpoint);
112 lfsck_position_le_to_cpu(&dst->ln_pos_latest_start,
113 &src->ln_pos_latest_start);
114 lfsck_position_le_to_cpu(&dst->ln_pos_last_checkpoint,
115 &src->ln_pos_last_checkpoint);
116 lfsck_position_le_to_cpu(&dst->ln_pos_first_inconsistent,
117 &src->ln_pos_first_inconsistent);
118 dst->ln_items_checked = le64_to_cpu(src->ln_items_checked);
119 dst->ln_items_repaired = le64_to_cpu(src->ln_items_repaired);
120 dst->ln_items_failed = le64_to_cpu(src->ln_items_failed);
121 dst->ln_dirs_checked = le64_to_cpu(src->ln_dirs_checked);
122 dst->ln_objs_checked_phase2 = le64_to_cpu(src->ln_objs_checked_phase2);
123 dst->ln_objs_repaired_phase2 =
124 le64_to_cpu(src->ln_objs_repaired_phase2);
125 dst->ln_objs_failed_phase2 = le64_to_cpu(src->ln_objs_failed_phase2);
126 dst->ln_objs_nlink_repaired = le64_to_cpu(src->ln_objs_nlink_repaired);
127 fid_le_to_cpu(&dst->ln_fid_latest_scanned_phase2,
128 &src->ln_fid_latest_scanned_phase2);
129 dst->ln_dirent_repaired = le64_to_cpu(src->ln_dirent_repaired);
130 dst->ln_linkea_repaired = le64_to_cpu(src->ln_linkea_repaired);
131 dst->ln_mul_linked_checked = le64_to_cpu(src->ln_mul_linked_checked);
132 dst->ln_mul_linked_repaired = le64_to_cpu(src->ln_mul_linked_repaired);
133 dst->ln_unknown_inconsistency =
134 le64_to_cpu(src->ln_unknown_inconsistency);
135 dst->ln_unmatched_pairs_repaired =
136 le64_to_cpu(src->ln_unmatched_pairs_repaired);
137 dst->ln_dangling_repaired = le64_to_cpu(src->ln_dangling_repaired);
138 dst->ln_mul_ref_repaired = le64_to_cpu(src->ln_mul_ref_repaired);
139 dst->ln_bad_type_repaired = le64_to_cpu(src->ln_bad_type_repaired);
140 dst->ln_lost_dirent_repaired =
141 le64_to_cpu(src->ln_lost_dirent_repaired);
142 dst->ln_striped_dirs_scanned =
143 le64_to_cpu(src->ln_striped_dirs_scanned);
144 dst->ln_striped_dirs_repaired =
145 le64_to_cpu(src->ln_striped_dirs_repaired);
146 dst->ln_striped_dirs_failed =
147 le64_to_cpu(src->ln_striped_dirs_failed);
148 dst->ln_striped_dirs_disabled =
149 le64_to_cpu(src->ln_striped_dirs_disabled);
150 dst->ln_striped_dirs_skipped =
151 le64_to_cpu(src->ln_striped_dirs_skipped);
152 dst->ln_striped_shards_scanned =
153 le64_to_cpu(src->ln_striped_shards_scanned);
154 dst->ln_striped_shards_repaired =
155 le64_to_cpu(src->ln_striped_shards_repaired);
156 dst->ln_striped_shards_failed =
157 le64_to_cpu(src->ln_striped_shards_failed);
158 dst->ln_striped_shards_skipped =
159 le64_to_cpu(src->ln_striped_shards_skipped);
160 dst->ln_name_hash_repaired = le64_to_cpu(src->ln_name_hash_repaired);
161 dst->ln_local_lpf_scanned = le64_to_cpu(src->ln_local_lpf_scanned);
162 dst->ln_local_lpf_moved = le64_to_cpu(src->ln_local_lpf_moved);
163 dst->ln_local_lpf_skipped = le64_to_cpu(src->ln_local_lpf_skipped);
164 dst->ln_local_lpf_failed = le64_to_cpu(src->ln_local_lpf_failed);
165 dst->ln_bitmap_size = le32_to_cpu(src->ln_bitmap_size);
166 dst->ln_time_latest_reset = le64_to_cpu(src->ln_time_latest_reset);
167 dst->ln_linkea_overflow_cleared =
168 le64_to_cpu(src->ln_linkea_overflow_cleared);
169 dst->ln_agent_entries_repaired =
170 le64_to_cpu(src->ln_agent_entries_repaired);
173 static void lfsck_namespace_cpu_to_le(struct lfsck_namespace *dst,
174 struct lfsck_namespace *src)
176 dst->ln_magic = cpu_to_le32(src->ln_magic);
177 dst->ln_status = cpu_to_le32(src->ln_status);
178 dst->ln_flags = cpu_to_le32(src->ln_flags);
179 dst->ln_success_count = cpu_to_le32(src->ln_success_count);
180 dst->ln_run_time_phase1 = cpu_to_le64(src->ln_run_time_phase1);
181 dst->ln_run_time_phase2 = cpu_to_le64(src->ln_run_time_phase2);
182 dst->ln_time_last_complete = cpu_to_le64(src->ln_time_last_complete);
183 dst->ln_time_latest_start = cpu_to_le64(src->ln_time_latest_start);
184 dst->ln_time_last_checkpoint =
185 cpu_to_le64(src->ln_time_last_checkpoint);
186 lfsck_position_cpu_to_le(&dst->ln_pos_latest_start,
187 &src->ln_pos_latest_start);
188 lfsck_position_cpu_to_le(&dst->ln_pos_last_checkpoint,
189 &src->ln_pos_last_checkpoint);
190 lfsck_position_cpu_to_le(&dst->ln_pos_first_inconsistent,
191 &src->ln_pos_first_inconsistent);
192 dst->ln_items_checked = cpu_to_le64(src->ln_items_checked);
193 dst->ln_items_repaired = cpu_to_le64(src->ln_items_repaired);
194 dst->ln_items_failed = cpu_to_le64(src->ln_items_failed);
195 dst->ln_dirs_checked = cpu_to_le64(src->ln_dirs_checked);
196 dst->ln_objs_checked_phase2 = cpu_to_le64(src->ln_objs_checked_phase2);
197 dst->ln_objs_repaired_phase2 =
198 cpu_to_le64(src->ln_objs_repaired_phase2);
199 dst->ln_objs_failed_phase2 = cpu_to_le64(src->ln_objs_failed_phase2);
200 dst->ln_objs_nlink_repaired = cpu_to_le64(src->ln_objs_nlink_repaired);
201 fid_cpu_to_le(&dst->ln_fid_latest_scanned_phase2,
202 &src->ln_fid_latest_scanned_phase2);
203 dst->ln_dirent_repaired = cpu_to_le64(src->ln_dirent_repaired);
204 dst->ln_linkea_repaired = cpu_to_le64(src->ln_linkea_repaired);
205 dst->ln_mul_linked_checked = cpu_to_le64(src->ln_mul_linked_checked);
206 dst->ln_mul_linked_repaired = cpu_to_le64(src->ln_mul_linked_repaired);
207 dst->ln_unknown_inconsistency =
208 cpu_to_le64(src->ln_unknown_inconsistency);
209 dst->ln_unmatched_pairs_repaired =
210 cpu_to_le64(src->ln_unmatched_pairs_repaired);
211 dst->ln_dangling_repaired = cpu_to_le64(src->ln_dangling_repaired);
212 dst->ln_mul_ref_repaired = cpu_to_le64(src->ln_mul_ref_repaired);
213 dst->ln_bad_type_repaired = cpu_to_le64(src->ln_bad_type_repaired);
214 dst->ln_lost_dirent_repaired =
215 cpu_to_le64(src->ln_lost_dirent_repaired);
216 dst->ln_striped_dirs_scanned =
217 cpu_to_le64(src->ln_striped_dirs_scanned);
218 dst->ln_striped_dirs_repaired =
219 cpu_to_le64(src->ln_striped_dirs_repaired);
220 dst->ln_striped_dirs_failed =
221 cpu_to_le64(src->ln_striped_dirs_failed);
222 dst->ln_striped_dirs_disabled =
223 cpu_to_le64(src->ln_striped_dirs_disabled);
224 dst->ln_striped_dirs_skipped =
225 cpu_to_le64(src->ln_striped_dirs_skipped);
226 dst->ln_striped_shards_scanned =
227 cpu_to_le64(src->ln_striped_shards_scanned);
228 dst->ln_striped_shards_repaired =
229 cpu_to_le64(src->ln_striped_shards_repaired);
230 dst->ln_striped_shards_failed =
231 cpu_to_le64(src->ln_striped_shards_failed);
232 dst->ln_striped_shards_skipped =
233 cpu_to_le64(src->ln_striped_shards_skipped);
234 dst->ln_name_hash_repaired = cpu_to_le64(src->ln_name_hash_repaired);
235 dst->ln_local_lpf_scanned = cpu_to_le64(src->ln_local_lpf_scanned);
236 dst->ln_local_lpf_moved = cpu_to_le64(src->ln_local_lpf_moved);
237 dst->ln_local_lpf_skipped = cpu_to_le64(src->ln_local_lpf_skipped);
238 dst->ln_local_lpf_failed = cpu_to_le64(src->ln_local_lpf_failed);
239 dst->ln_bitmap_size = cpu_to_le32(src->ln_bitmap_size);
240 dst->ln_time_latest_reset = cpu_to_le64(src->ln_time_latest_reset);
241 dst->ln_linkea_overflow_cleared =
242 cpu_to_le64(src->ln_linkea_overflow_cleared);
243 dst->ln_agent_entries_repaired =
244 cpu_to_le64(src->ln_agent_entries_repaired);
247 static void lfsck_namespace_record_failure(const struct lu_env *env,
248 struct lfsck_instance *lfsck,
249 struct lfsck_namespace *ns)
251 struct lfsck_position pos;
253 ns->ln_items_failed++;
254 lfsck_pos_fill(env, lfsck, &pos, false);
255 if (lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent) ||
256 lfsck_pos_is_eq(&pos, &ns->ln_pos_first_inconsistent) < 0) {
257 ns->ln_pos_first_inconsistent = pos;
259 CDEBUG(D_LFSCK, "%s: namespace LFSCK hit first non-repaired "
260 "inconsistency at the pos [%llu, "DFID", %#llx]\n",
261 lfsck_lfsck2name(lfsck),
262 ns->ln_pos_first_inconsistent.lp_oit_cookie,
263 PFID(&ns->ln_pos_first_inconsistent.lp_dir_parent),
264 ns->ln_pos_first_inconsistent.lp_dir_cookie);
269 * Load the MDT bitmap from the lfsck_namespace trace file.
271 * \param[in] env pointer to the thread context
272 * \param[in] com pointer to the lfsck component
274 * \retval 0 for success
275 * \retval negative error number on failure or data corruption
277 static int lfsck_namespace_load_bitmap(const struct lu_env *env,
278 struct lfsck_component *com)
280 struct dt_object *obj = com->lc_obj;
281 struct lfsck_assistant_data *lad = com->lc_data;
282 struct lfsck_namespace *ns = com->lc_file_ram;
283 struct cfs_bitmap *bitmap = lad->lad_bitmap;
289 if (com->lc_lfsck->li_mdt_descs.ltd_tgts_bitmap->size >
291 nbits = com->lc_lfsck->li_mdt_descs.ltd_tgts_bitmap->size;
293 nbits = ns->ln_bitmap_size;
295 if (unlikely(nbits < BITS_PER_LONG))
296 nbits = BITS_PER_LONG;
298 if (nbits > bitmap->size) {
299 __u32 new_bits = bitmap->size;
300 struct cfs_bitmap *new_bitmap;
302 while (new_bits < nbits)
305 new_bitmap = CFS_ALLOCATE_BITMAP(new_bits);
306 if (new_bitmap == NULL)
309 lad->lad_bitmap = new_bitmap;
310 CFS_FREE_BITMAP(bitmap);
314 if (ns->ln_bitmap_size == 0) {
315 clear_bit(LAD_INCOMPLETE, &lad->lad_flags);
316 CFS_RESET_BITMAP(bitmap);
321 size = (ns->ln_bitmap_size + 7) >> 3;
322 rc = dt_xattr_get(env, obj,
323 lfsck_buf_get(env, bitmap->data, size),
324 XATTR_NAME_LFSCK_BITMAP);
326 RETURN(rc >= 0 ? -EINVAL : rc);
328 if (cfs_bitmap_check_empty(bitmap))
329 clear_bit(LAD_INCOMPLETE, &lad->lad_flags);
331 set_bit(LAD_INCOMPLETE, &lad->lad_flags);
337 * Load namespace LFSCK statistics information from the trace file.
339 * \param[in] env pointer to the thread context
340 * \param[in] com pointer to the lfsck component
342 * \retval 0 for success
343 * \retval negative error number on failure
345 static int lfsck_namespace_load(const struct lu_env *env,
346 struct lfsck_component *com)
348 int len = com->lc_file_size;
351 rc = dt_xattr_get(env, com->lc_obj,
352 lfsck_buf_get(env, com->lc_file_disk, len),
353 XATTR_NAME_LFSCK_NAMESPACE);
355 struct lfsck_namespace *ns = com->lc_file_ram;
357 lfsck_namespace_le_to_cpu(ns,
358 (struct lfsck_namespace *)com->lc_file_disk);
359 if (ns->ln_magic != LFSCK_NAMESPACE_MAGIC) {
360 CDEBUG(D_LFSCK, "%s: invalid lfsck_namespace magic "
361 "%#x != %#x\n", lfsck_lfsck2name(com->lc_lfsck),
362 ns->ln_magic, LFSCK_NAMESPACE_MAGIC);
367 } else if (rc != -ENODATA) {
368 CDEBUG(D_LFSCK, "%s: fail to load lfsck_namespace, "
369 "expected = %d: rc = %d\n",
370 lfsck_lfsck2name(com->lc_lfsck), len, rc);
378 static int lfsck_namespace_store(const struct lu_env *env,
379 struct lfsck_component *com)
381 struct dt_object *obj = com->lc_obj;
382 struct lfsck_instance *lfsck = com->lc_lfsck;
383 struct lfsck_namespace *ns = com->lc_file_ram;
384 struct lfsck_assistant_data *lad = com->lc_data;
385 struct dt_device *dev = lfsck_obj2dev(obj);
386 struct cfs_bitmap *bitmap = NULL;
387 struct thandle *handle;
389 int len = com->lc_file_size;
394 bitmap = lad->lad_bitmap;
395 nbits = bitmap->size;
398 LASSERTF((nbits & 7) == 0, "Invalid nbits %u\n", nbits);
401 ns->ln_bitmap_size = nbits;
402 lfsck_namespace_cpu_to_le((struct lfsck_namespace *)com->lc_file_disk,
404 handle = dt_trans_create(env, dev);
406 GOTO(log, rc = PTR_ERR(handle));
408 rc = dt_declare_xattr_set(env, obj,
409 lfsck_buf_get(env, com->lc_file_disk, len),
410 XATTR_NAME_LFSCK_NAMESPACE, 0, handle);
414 if (bitmap != NULL) {
415 rc = dt_declare_xattr_set(env, obj,
416 lfsck_buf_get(env, bitmap->data, nbits >> 3),
417 XATTR_NAME_LFSCK_BITMAP, 0, handle);
422 rc = dt_trans_start_local(env, dev, handle);
426 rc = dt_xattr_set(env, obj,
427 lfsck_buf_get(env, com->lc_file_disk, len),
428 XATTR_NAME_LFSCK_NAMESPACE, 0, handle);
429 if (rc == 0 && bitmap != NULL)
430 rc = dt_xattr_set(env, obj,
431 lfsck_buf_get(env, bitmap->data, nbits >> 3),
432 XATTR_NAME_LFSCK_BITMAP, 0, handle);
437 dt_trans_stop(env, dev, handle);
441 CDEBUG(D_LFSCK, "%s: fail to store lfsck_namespace: rc = %d\n",
442 lfsck_lfsck2name(lfsck), rc);
446 static int lfsck_namespace_init(const struct lu_env *env,
447 struct lfsck_component *com)
449 struct lfsck_namespace *ns = com->lc_file_ram;
452 memset(ns, 0, sizeof(*ns));
453 ns->ln_magic = LFSCK_NAMESPACE_MAGIC;
454 ns->ln_status = LS_INIT;
455 ns->ln_time_latest_reset = ktime_get_real_seconds();
456 down_write(&com->lc_sem);
457 rc = lfsck_namespace_store(env, com);
459 rc = lfsck_load_sub_trace_files(env, com,
460 &dt_lfsck_namespace_features, LFSCK_NAMESPACE, true);
461 up_write(&com->lc_sem);
467 * Update the namespace LFSCK trace file for the given @fid
469 * \param[in] env pointer to the thread context
470 * \param[in] com pointer to the lfsck component
471 * \param[in] fid the fid which flags to be updated in the lfsck
473 * \param[in] add true if add new flags, otherwise remove flags
475 * \retval 0 for success or nothing to be done
476 * \retval negative error number on failure
478 int lfsck_namespace_trace_update(const struct lu_env *env,
479 struct lfsck_component *com,
480 const struct lu_fid *fid,
481 const __u8 flags, bool add)
483 struct lfsck_instance *lfsck = com->lc_lfsck;
484 struct dt_object *obj;
485 struct lu_fid *key = &lfsck_env_info(env)->lti_fid3;
486 struct dt_device *dev;
487 struct thandle *th = NULL;
496 if (unlikely(!fid_is_sane(fid)))
499 idx = lfsck_sub_trace_file_fid2idx(fid);
500 mutex_lock(&com->lc_sub_trace_objs[idx].lsto_mutex);
501 obj = com->lc_sub_trace_objs[idx].lsto_obj;
502 if (unlikely(obj == NULL)) {
503 mutex_unlock(&com->lc_sub_trace_objs[idx].lsto_mutex);
507 lfsck_object_get(obj);
508 dev = lfsck_obj2dev(obj);
509 fid_cpu_to_be(key, fid);
510 rc = dt_lookup(env, obj, (struct dt_rec *)&old,
511 (const struct dt_key *)key);
514 GOTO(unlock, rc = 0);
518 } else if (rc == 0) {
520 if ((old & flags) == flags)
521 GOTO(unlock, rc = 0);
525 if ((old & flags) == 0)
526 GOTO(unlock, rc = 0);
534 th = dt_trans_create(env, dev);
536 GOTO(log, rc = PTR_ERR(th));
539 rc = dt_declare_delete(env, obj,
540 (const struct dt_key *)key, th);
546 rc = dt_declare_insert(env, obj,
547 (const struct dt_rec *)&new,
548 (const struct dt_key *)key, th);
553 rc = dt_trans_start_local(env, dev, th);
558 rc = dt_delete(env, obj, (const struct dt_key *)key, th);
564 rc = dt_insert(env, obj, (const struct dt_rec *)&new,
565 (const struct dt_key *)key, th);
573 if (th != NULL && !IS_ERR(th))
574 dt_trans_stop(env, dev, th);
576 CDEBUG(D_LFSCK, "%s: namespace LFSCK %s flags for "DFID" in the "
577 "trace file, flags %x, old %x, new %x: rc = %d\n",
578 lfsck_lfsck2name(lfsck), add ? "add" : "del", PFID(fid),
579 (__u32)flags, (__u32)old, (__u32)new, rc);
582 mutex_unlock(&com->lc_sub_trace_objs[idx].lsto_mutex);
583 lfsck_object_put(env, obj);
588 int lfsck_namespace_check_exist(const struct lu_env *env,
589 struct dt_object *dir,
590 struct dt_object *obj, const char *name)
592 struct lu_fid *fid = &lfsck_env_info(env)->lti_fid;
596 if (unlikely(lfsck_is_dead_obj(obj)))
597 RETURN(LFSCK_NAMEENTRY_DEAD);
599 rc = dt_lookup(env, dir, (struct dt_rec *)fid,
600 (const struct dt_key *)name);
602 RETURN(LFSCK_NAMEENTRY_REMOVED);
607 if (!lu_fid_eq(fid, lfsck_dto2fid(obj)))
608 RETURN(LFSCK_NAMEENTRY_RECREATED);
613 static int lfsck_declare_namespace_exec_dir(const struct lu_env *env,
614 struct dt_object *obj,
615 struct thandle *handle)
619 /* For remote updating LINKEA, there may be further LFSCK action
620 * on remote MDT after the updating, so update the LINKEA ASAP. */
621 if (dt_object_remote(obj))
624 /* For destroying all invalid linkEA entries. */
625 rc = dt_declare_xattr_del(env, obj, XATTR_NAME_LINK, handle);
627 /* For insert new linkEA entry. */
628 rc = dt_declare_xattr_set(env, obj,
629 lfsck_buf_get_const(env, NULL, MAX_LINKEA_SIZE),
630 XATTR_NAME_LINK, 0, handle);
634 int __lfsck_links_read(const struct lu_env *env, struct dt_object *obj,
635 struct linkea_data *ldata, bool with_rec)
639 if (ldata->ld_buf->lb_buf == NULL)
642 if (!dt_object_exists(obj))
645 rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK);
647 /* Buf was too small, figure out what we need. */
648 rc = dt_xattr_get(env, obj, &LU_BUF_NULL, XATTR_NAME_LINK);
649 if (unlikely(rc == 0))
655 lu_buf_realloc(ldata->ld_buf, rc);
656 if (ldata->ld_buf->lb_buf == NULL)
659 rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK);
662 if (unlikely(rc == 0))
667 rc = linkea_init_with_rec(ldata);
669 rc = linkea_init(ldata);
676 * Remove linkEA for the given object.
678 * The caller should take the ldlm lock before the calling.
680 * \param[in] env pointer to the thread context
681 * \param[in] com pointer to the lfsck component
682 * \param[in] obj pointer to the dt_object to be handled
684 * \retval 0 for repaired cases
685 * \retval negative error number on failure
687 static int lfsck_namespace_links_remove(const struct lu_env *env,
688 struct lfsck_component *com,
689 struct dt_object *obj)
691 struct lfsck_instance *lfsck = com->lc_lfsck;
692 struct dt_device *dev = lfsck_obj2dev(obj);
693 struct thandle *th = NULL;
697 LASSERT(dt_object_remote(obj) == 0);
699 th = dt_trans_create(env, dev);
701 GOTO(log, rc = PTR_ERR(th));
703 rc = dt_declare_xattr_del(env, obj, XATTR_NAME_LINK, th);
707 rc = dt_trans_start_local(env, dev, th);
711 dt_write_lock(env, obj, 0);
712 if (unlikely(lfsck_is_dead_obj(obj)))
713 GOTO(unlock, rc = -ENOENT);
715 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
716 GOTO(unlock, rc = 0);
718 rc = dt_xattr_del(env, obj, XATTR_NAME_LINK, th);
723 dt_write_unlock(env, obj);
726 dt_trans_stop(env, dev, th);
729 CDEBUG(D_LFSCK, "%s: namespace LFSCK remove invalid linkEA "
730 "for the object "DFID": rc = %d\n",
731 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(obj)), rc);
734 struct lfsck_namespace *ns = com->lc_file_ram;
736 ns->ln_flags |= LF_INCONSISTENT;
742 static int lfsck_links_write(const struct lu_env *env, struct dt_object *obj,
743 struct linkea_data *ldata, struct thandle *handle)
748 lfsck_buf_init(&buf, ldata->ld_buf->lb_buf, ldata->ld_leh->leh_len);
751 rc = dt_xattr_set(env, obj, &buf, XATTR_NAME_LINK, 0, handle);
752 if (unlikely(rc == -ENOSPC)) {
753 rc = linkea_overflow_shrink(ldata);
754 if (likely(rc > 0)) {
763 static inline bool linkea_reclen_is_valid(const struct linkea_data *ldata)
765 if (ldata->ld_reclen <= 0)
768 if ((char *)ldata->ld_lee + ldata->ld_reclen >
769 (char *)ldata->ld_leh + ldata->ld_leh->leh_len)
775 static inline bool linkea_entry_is_valid(const struct linkea_data *ldata,
776 const struct lu_name *cname,
777 const struct lu_fid *pfid)
779 if (!linkea_reclen_is_valid(ldata))
782 if (cname->ln_namelen <= 0 || cname->ln_namelen > NAME_MAX)
785 if (!fid_is_sane(pfid))
791 static int lfsck_namespace_unpack_linkea_entry(struct linkea_data *ldata,
792 struct lu_name *cname,
794 char *buf, const int buflen)
796 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, cname, pfid);
797 if (unlikely(!linkea_entry_is_valid(ldata, cname, pfid)))
800 /* To guarantee the 'name' is terminated with '0'. */
801 memcpy(buf, cname->ln_name, cname->ln_namelen);
802 buf[cname->ln_namelen] = 0;
803 cname->ln_name = buf;
808 static void lfsck_linkea_del_buf(struct linkea_data *ldata,
809 const struct lu_name *lname)
811 LASSERT(ldata->ld_leh != NULL && ldata->ld_lee != NULL);
813 /* If current record is corrupted, all the subsequent
814 * records will be dropped. */
815 if (unlikely(!linkea_reclen_is_valid(ldata))) {
816 void *ptr = ldata->ld_lee;
818 ldata->ld_leh->leh_len = sizeof(struct link_ea_header);
819 ldata->ld_leh->leh_reccount = 0;
820 linkea_first_entry(ldata);
821 while (ldata->ld_lee != NULL &&
822 (char *)ldata->ld_lee < (char *)ptr) {
823 int reclen = (ldata->ld_lee->lee_reclen[0] << 8) |
824 ldata->ld_lee->lee_reclen[1];
826 ldata->ld_leh->leh_len += reclen;
827 ldata->ld_leh->leh_reccount++;
828 ldata->ld_lee = (struct link_ea_entry *)
829 ((char *)ldata->ld_lee + reclen);
832 ldata->ld_lee = NULL;
834 linkea_del_buf(ldata, lname);
838 static int lfsck_namespace_filter_linkea_entry(struct linkea_data *ldata,
839 struct lu_name *cname,
843 struct link_ea_entry *oldlee;
847 oldlee = ldata->ld_lee;
848 oldlen = ldata->ld_reclen;
849 linkea_next_entry(ldata);
850 while (ldata->ld_lee != NULL) {
851 ldata->ld_reclen = (ldata->ld_lee->lee_reclen[0] << 8) |
852 ldata->ld_lee->lee_reclen[1];
853 if (unlikely(!linkea_reclen_is_valid(ldata))) {
854 lfsck_linkea_del_buf(ldata, NULL);
855 LASSERT(ldata->ld_lee == NULL);
856 } else if (unlikely(ldata->ld_reclen == oldlen &&
857 memcmp(ldata->ld_lee, oldlee, oldlen) == 0)) {
862 lfsck_linkea_del_buf(ldata, cname);
864 linkea_next_entry(ldata);
867 ldata->ld_lee = oldlee;
868 ldata->ld_reclen = oldlen;
874 * Insert orphan into .lustre/lost+found/MDTxxxx/ locally.
876 * Add the specified orphan MDT-object to the .lustre/lost+found/MDTxxxx/
877 * with the given type to generate the name, the detailed rules for name
878 * have been described as following.
880 * The function also generates the linkEA corresponding to the name entry
881 * under the .lustre/lost+found/MDTxxxx/ for the orphan MDT-object.
883 * \param[in] env pointer to the thread context
884 * \param[in] com pointer to the lfsck component
885 * \param[in] orphan pointer to the orphan MDT-object
886 * \param[in] infix additional information for the orphan name, such as
887 * the FID for original
888 * \param[in] type the type for describing why the orphan MDT-object is
889 * created. The rules are as following:
891 * type "D": The MDT-object is a directory, it may knows its parent
892 * but because there is no valid linkEA, the LFSCK cannot
893 * know where to put it back to the namespace.
894 * type "O": The MDT-object has no linkEA, and there is no name
895 * entry that references the MDT-object.
897 * type "S": The orphan MDT-object is a shard of a striped directory
899 * \see lfsck_layout_recreate_parent() for more types.
901 * The orphan name will be like:
902 * ${FID}-${infix}-${type}-${conflict_version}
904 * \param[out] count if some others inserted some linkEA entries by race,
905 * then return the linkEA entries count.
907 * \retval positive number for repaired cases
908 * \retval 0 if needs to repair nothing
909 * \retval negative error number on failure
911 static int lfsck_namespace_insert_orphan(const struct lu_env *env,
912 struct lfsck_component *com,
913 struct dt_object *orphan,
914 const char *infix, const char *type,
917 struct lfsck_thread_info *info = lfsck_env_info(env);
918 struct lu_name *cname = &info->lti_name;
919 struct dt_insert_rec *rec = &info->lti_dt_rec;
920 struct lu_attr *la = &info->lti_la2;
921 const struct lu_fid *cfid = lfsck_dto2fid(orphan);
922 const struct lu_fid *pfid;
924 struct lfsck_instance *lfsck = com->lc_lfsck;
925 struct dt_device *dev = lfsck_obj2dev(orphan);
926 struct dt_object *parent;
927 struct thandle *th = NULL;
928 struct lfsck_lock_handle *pllh = &info->lti_llh;
929 struct lustre_handle clh = { 0 };
930 struct linkea_data ldata2 = { NULL };
931 struct lu_buf linkea_buf;
938 cname->ln_name = NULL;
939 if (unlikely(lfsck->li_lpf_obj == NULL))
940 GOTO(log, rc = -ENXIO);
942 parent = lfsck->li_lpf_obj;
943 pfid = lfsck_dto2fid(parent);
947 namelen = snprintf(info->lti_key, NAME_MAX, DFID"%s-%s-%d",
948 PFID(cfid), infix, type, idx++);
949 rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
950 (const struct dt_key *)info->lti_key);
951 if (rc != 0 && rc != -ENOENT)
954 if (unlikely(rc == 0 && lu_fid_eq(cfid, &tfid)))
956 } while (rc == 0 && !exist);
958 rc = lfsck_lock(env, lfsck, parent, info->lti_key, pllh,
959 MDS_INODELOCK_UPDATE, LCK_PW);
963 /* Re-check whether the name conflict with othrs after taken
965 rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
966 (const struct dt_key *)info->lti_key);
968 if (!lu_fid_eq(cfid, &tfid)) {
975 } else if (rc != -ENOENT) {
981 cname->ln_name = info->lti_key;
982 cname->ln_namelen = namelen;
983 rc = linkea_links_new(&ldata2, &info->lti_linkea_buf2,
988 rc = lfsck_ibits_lock(env, lfsck, orphan, &clh,
989 MDS_INODELOCK_UPDATE | MDS_INODELOCK_LOOKUP |
990 MDS_INODELOCK_XATTR, LCK_EX);
994 lfsck_buf_init(&linkea_buf, ldata2.ld_buf->lb_buf,
995 ldata2.ld_leh->leh_len);
996 th = dt_trans_create(env, dev);
998 GOTO(log, rc = PTR_ERR(th));
1000 if (S_ISDIR(lfsck_object_type(orphan))) {
1001 rc = dt_declare_delete(env, orphan,
1002 (const struct dt_key *)dotdot, th);
1006 rec->rec_type = S_IFDIR;
1007 rec->rec_fid = pfid;
1008 rc = dt_declare_insert(env, orphan, (const struct dt_rec *)rec,
1009 (const struct dt_key *)dotdot, th);
1014 rc = dt_declare_xattr_set(env, orphan, &linkea_buf,
1015 XATTR_NAME_LINK, 0, th);
1020 rec->rec_type = lfsck_object_type(orphan) & S_IFMT;
1021 rec->rec_fid = cfid;
1022 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
1023 (const struct dt_key *)cname->ln_name,
1028 if (S_ISDIR(rec->rec_type)) {
1029 rc = dt_declare_ref_add(env, parent, th);
1035 memset(la, 0, sizeof(*la));
1036 la->la_ctime = ktime_get_real_seconds();
1037 la->la_valid = LA_CTIME;
1038 rc = dt_declare_attr_set(env, orphan, la, th);
1042 rc = dt_trans_start_local(env, dev, th);
1046 dt_write_lock(env, orphan, 0);
1047 rc = lfsck_links_read2_with_rec(env, orphan, &ldata2);
1048 if (likely(rc == -ENODATA || rc == -EINVAL)) {
1049 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
1050 GOTO(unlock, rc = 1);
1052 if (S_ISDIR(lfsck_object_type(orphan))) {
1053 rc = dt_delete(env, orphan,
1054 (const struct dt_key *)dotdot, th);
1058 rec->rec_type = S_IFDIR;
1059 rec->rec_fid = pfid;
1060 rc = dt_insert(env, orphan, (const struct dt_rec *)rec,
1061 (const struct dt_key *)dotdot, th);
1066 rc = dt_xattr_set(env, orphan, &linkea_buf, XATTR_NAME_LINK, 0,
1069 if (rc == 0 && count != NULL)
1070 *count = ldata2.ld_leh->leh_reccount;
1074 dt_write_unlock(env, orphan);
1076 if (rc == 0 && !exist) {
1077 rec->rec_type = lfsck_object_type(orphan) & S_IFMT;
1078 rec->rec_fid = cfid;
1079 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
1080 (const struct dt_key *)cname->ln_name, th);
1081 if (rc == 0 && S_ISDIR(rec->rec_type)) {
1082 dt_write_lock(env, parent, 0);
1083 rc = dt_ref_add(env, parent, th);
1084 dt_write_unlock(env, parent);
1089 rc = dt_attr_set(env, orphan, la, th);
1091 GOTO(stop, rc = (rc == 0 ? 1 : rc));
1094 dt_write_unlock(env, orphan);
1097 dt_trans_stop(env, dev, th);
1100 lfsck_ibits_unlock(&clh, LCK_EX);
1102 CDEBUG(D_LFSCK, "%s: namespace LFSCK insert orphan for the "
1103 "object "DFID", name = %s: rc = %d\n",
1104 lfsck_lfsck2name(lfsck), PFID(cfid),
1105 cname->ln_name != NULL ? cname->ln_name : "<NULL>", rc);
1108 struct lfsck_namespace *ns = com->lc_file_ram;
1110 ns->ln_flags |= LF_INCONSISTENT;
1116 static int lfsck_lmv_set(const struct lu_env *env,
1117 struct lfsck_instance *lfsck,
1118 struct dt_object *obj,
1119 struct lmv_mds_md_v1 *lmv)
1121 struct dt_device *dev = lfsck->li_next;
1122 struct thandle *th = NULL;
1123 struct lu_buf buf = { lmv, sizeof(*lmv) };
1128 th = dt_trans_create(env, dev);
1130 RETURN(PTR_ERR(th));
1132 rc = dt_declare_xattr_set(env, obj, &buf, XATTR_NAME_LMV, 0, th);
1136 rc = dt_trans_start_local(env, dev, th);
1140 rc = dt_xattr_set(env, obj, &buf, XATTR_NAME_LMV, 0, th);
1146 dt_trans_stop(env, dev, th);
1151 static int lfsck_lmv_delete(const struct lu_env *env,
1152 struct lfsck_instance *lfsck,
1153 struct dt_object *obj)
1155 struct dt_device *dev = lfsck->li_next;
1156 struct thandle *th = NULL;
1161 th = dt_trans_create(env, dev);
1163 RETURN(PTR_ERR(th));
1165 rc = dt_declare_xattr_del(env, obj, XATTR_NAME_LMV, th);
1169 rc = dt_trans_start_local(env, dev, th);
1173 rc = dt_xattr_del(env, obj, XATTR_NAME_LMV, th);
1179 dt_trans_stop(env, dev, th);
1184 static inline int lfsck_object_is_shard(const struct lu_env *env,
1185 struct lfsck_instance *lfsck,
1186 struct dt_object *obj,
1187 const struct lu_name *lname)
1189 struct lfsck_thread_info *info = lfsck_env_info(env);
1190 struct lmv_mds_md_v1 *lmv = &info->lti_lmv;
1193 rc = lfsck_shard_name_to_index(env, lname->ln_name, lname->ln_namelen,
1194 lfsck_object_type(obj),
1195 lfsck_dto2fid(obj));
1199 rc = lfsck_read_stripe_lmv(env, lfsck, obj, lmv);
1203 if (!rc && lmv->lmv_magic == LMV_MAGIC_STRIPE)
1210 * Add the specified name entry back to namespace.
1212 * If there is a linkEA entry that back references a name entry under
1213 * some parent directory, but such parent directory does not have the
1214 * claimed name entry. On the other hand, the linkEA entries count is
1215 * not larger than the MDT-object's hard link count. Under such case,
1216 * it is quite possible that the name entry is lost. Then the LFSCK
1217 * should add the name entry back to the namespace.
1219 * If \a child is shard, which means \a parent is a striped directory,
1220 * if \a parent has LMV, we need to delete it before insertion because
1221 * now parent's striping is broken and can't be parsed correctly.
1223 * \param[in] env pointer to the thread context
1224 * \param[in] com pointer to the lfsck component
1225 * \param[in] parent pointer to the directory under which the name entry
1226 * will be inserted into
1227 * \param[in] child pointer to the object referenced by the name entry
1228 * that to be inserted into the parent
1229 * \param[in] lname the name for the child in the parent directory
1231 * \retval positive number for repaired cases
1232 * \retval 0 if nothing to be repaired
1233 * \retval negative error number on failure
1235 static int lfsck_namespace_insert_normal(const struct lu_env *env,
1236 struct lfsck_component *com,
1237 struct dt_object *parent,
1238 struct dt_object *child,
1239 const struct lu_name *lname)
1241 struct lfsck_thread_info *info = lfsck_env_info(env);
1242 struct lu_attr *la = &info->lti_la;
1243 struct dt_insert_rec *rec = &info->lti_dt_rec;
1244 struct lfsck_instance *lfsck = com->lc_lfsck;
1245 /* The child and its name may be on different MDTs. */
1246 const struct lu_fid *pfid = lfsck_dto2fid(parent);
1247 const struct lu_fid *cfid = lfsck_dto2fid(child);
1248 struct dt_device *dev = lfsck->li_next;
1249 struct thandle *th = NULL;
1250 struct lfsck_lock_handle *llh = &info->lti_llh;
1251 struct lmv_mds_md_v1 *lmv = &info->lti_lmv;
1252 struct lu_buf buf = { lmv, sizeof(*lmv) };
1253 /* whether parent's LMV is deleted before insertion */
1254 bool parent_lmv_deleted = false;
1255 /* whether parent's LMV is missing */
1256 bool parent_lmv_lost = false;
1261 /* @parent/@child may be based on lfsck->li_bottom,
1262 * but here we need the object based on the lfsck->li_next. */
1264 parent = lfsck_object_locate(dev, parent);
1266 GOTO(log, rc = PTR_ERR(parent));
1268 child = lfsck_object_locate(dev, child);
1270 GOTO(log, rc = PTR_ERR(child));
1272 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
1275 rc = lfsck_lock(env, lfsck, parent, lname->ln_name, llh,
1276 MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
1277 MDS_INODELOCK_XATTR, LCK_EX);
1281 rc = lfsck_object_is_shard(env, lfsck, child, lname);
1286 rc = lfsck_read_stripe_lmv(env, lfsck, parent, lmv);
1289 * To add a shard, we need to convert parent to a
1290 * plain directory by deleting its LMV, and after
1291 * insertion set it back.
1293 rc = lfsck_lmv_delete(env, lfsck, parent);
1296 parent_lmv_deleted = true;
1297 lmv->lmv_layout_version++;
1298 lfsck_lmv_header_cpu_to_le(lmv, lmv);
1299 } else if (rc == -ENODATA) {
1300 struct lu_seq_range *range = &info->lti_range;
1301 struct seq_server_site *ss = lfsck_dev_site(lfsck);
1303 rc = lfsck_read_stripe_lmv(env, lfsck, child, lmv);
1307 fld_range_set_mdt(range);
1308 rc = fld_server_lookup(env, ss->ss_server_fld,
1309 fid_seq(lfsck_dto2fid(parent)), range);
1313 parent_lmv_lost = true;
1314 lmv->lmv_magic = LMV_MAGIC;
1315 lmv->lmv_master_mdt_index = range->lsr_index;
1316 lmv->lmv_layout_version++;
1317 lfsck_lmv_header_cpu_to_le(lmv, lmv);
1323 if (unlikely(!dt_try_as_dir(env, parent)))
1324 GOTO(unlock, rc = -ENOTDIR);
1326 th = dt_trans_create(env, dev);
1328 GOTO(unlock, rc = PTR_ERR(th));
1330 rec->rec_type = lfsck_object_type(child) & S_IFMT;
1331 rec->rec_fid = cfid;
1332 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
1333 (const struct dt_key *)lname->ln_name, th);
1337 if (S_ISDIR(rec->rec_type)) {
1338 rc = dt_declare_ref_add(env, parent, th);
1343 if (parent_lmv_lost) {
1344 rc = dt_declare_xattr_set(env, parent, &buf, XATTR_NAME_LMV,
1350 la->la_ctime = ktime_get_real_seconds();
1351 la->la_valid = LA_CTIME;
1352 rc = dt_declare_attr_set(env, parent, la, th);
1356 rc = dt_declare_attr_set(env, child, la, th);
1360 rc = dt_trans_start_local(env, dev, th);
1364 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
1365 (const struct dt_key *)lname->ln_name, th);
1369 if (S_ISDIR(rec->rec_type)) {
1370 dt_write_lock(env, parent, 0);
1371 rc = dt_ref_add(env, parent, th);
1372 dt_write_unlock(env, parent);
1377 if (parent_lmv_lost) {
1378 rc = dt_xattr_set(env, parent, &buf, XATTR_NAME_LMV, 0, th);
1383 rc = dt_attr_set(env, parent, la, th);
1387 rc = dt_attr_set(env, child, la, th);
1389 GOTO(stop, rc = (rc == 0 ? 1 : rc));
1392 dt_trans_stop(env, dev, th);
1395 if (parent_lmv_deleted)
1396 lfsck_lmv_set(env, lfsck, parent, lmv);
1401 CDEBUG(D_LFSCK, "%s: namespace LFSCK insert object "DFID" with "
1402 "the name %s and type %o to the parent "DFID": rc = %d\n",
1403 lfsck_lfsck2name(lfsck), PFID(cfid), lname->ln_name,
1404 lfsck_object_type(child) & S_IFMT, PFID(pfid), rc);
1407 struct lfsck_namespace *ns = com->lc_file_ram;
1409 ns->ln_flags |= LF_INCONSISTENT;
1411 ns->ln_lost_dirent_repaired++;
1418 * Create the specified orphan directory.
1420 * For the case that the parent MDT-object stored in some MDT-object's
1421 * linkEA entry is lost, the LFSCK will re-create the parent object as
1422 * an orphan and insert it into .lustre/lost+found/MDTxxxx/ directory
1423 * with the name ${FID}-P-${conflict_version}.
1425 * \param[in] env pointer to the thread context
1426 * \param[in] com pointer to the lfsck component
1427 * \param[in] orphan pointer to the orphan MDT-object to be created
1428 * \param[in] lmv pointer to master LMV EA that will be set to the orphan
1430 * \retval positive number for repaired cases
1431 * \retval negative error number on failure
1433 static int lfsck_namespace_create_orphan_dir(const struct lu_env *env,
1434 struct lfsck_component *com,
1435 struct dt_object *orphan,
1436 struct lmv_mds_md_v1 *lmv)
1438 struct lfsck_thread_info *info = lfsck_env_info(env);
1439 struct lu_attr *la = &info->lti_la;
1440 struct dt_allocation_hint *hint = &info->lti_hint;
1441 struct dt_object_format *dof = &info->lti_dof;
1442 struct lu_name *cname = &info->lti_name2;
1443 struct dt_insert_rec *rec = &info->lti_dt_rec;
1444 struct lmv_mds_md_v1 *lmv2 = &info->lti_lmv2;
1445 const struct lu_fid *cfid = lfsck_dto2fid(orphan);
1447 struct lfsck_instance *lfsck = com->lc_lfsck;
1448 struct lfsck_namespace *ns = com->lc_file_ram;
1449 struct dt_device *dev = lfsck_obj2dev(orphan);
1450 struct dt_object *parent = NULL;
1451 struct thandle *th = NULL;
1452 struct lfsck_lock_handle *llh = &info->lti_llh;
1453 struct linkea_data ldata = { NULL };
1454 struct lu_buf linkea_buf;
1455 struct lu_buf lmv_buf;
1463 LASSERT(!dt_object_exists(orphan));
1465 cname->ln_name = NULL;
1466 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
1469 if (dt_object_remote(orphan)) {
1470 LASSERT(lfsck->li_lpf_root_obj != NULL);
1472 idx = lfsck_find_mdt_idx_by_fid(env, lfsck, cfid);
1474 GOTO(log, rc = idx);
1476 snprintf(name, 8, "MDT%04x", idx);
1477 rc = dt_lookup(env, lfsck->li_lpf_root_obj,
1478 (struct dt_rec *)&tfid,
1479 (const struct dt_key *)name);
1481 GOTO(log, rc = (rc == -ENOENT ? -ENXIO : rc));
1483 parent = lfsck_object_find_bottom(env, lfsck, &tfid);
1485 GOTO(log, rc = PTR_ERR(parent));
1487 if (unlikely(!dt_try_as_dir(env, parent)))
1488 GOTO(log, rc = -ENOTDIR);
1490 if (unlikely(lfsck->li_lpf_obj == NULL))
1491 GOTO(log, rc = -ENXIO);
1493 parent = lfsck->li_lpf_obj;
1496 dev = lfsck_find_dev_by_fid(env, lfsck, cfid);
1498 GOTO(log, rc = PTR_ERR(dev));
1504 namelen = snprintf(name, 31, DFID"-P-%d",
1506 rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
1507 (const struct dt_key *)name);
1508 if (rc != 0 && rc != -ENOENT)
1512 rc = lfsck_lock(env, lfsck, parent, name, llh,
1513 MDS_INODELOCK_UPDATE, LCK_PW);
1517 /* Re-check whether the name conflict with othrs after taken
1519 rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
1520 (const struct dt_key *)name);
1521 if (unlikely(rc == 0)) {
1529 cname->ln_name = name;
1530 cname->ln_namelen = namelen;
1532 memset(la, 0, sizeof(*la));
1533 la->la_mode = S_IFDIR | 0700;
1534 la->la_valid = LA_TYPE | LA_MODE | LA_UID | LA_GID |
1535 LA_ATIME | LA_MTIME | LA_CTIME;
1537 orphan->do_ops->do_ah_init(env, hint, parent, orphan,
1538 la->la_mode & S_IFMT);
1540 memset(dof, 0, sizeof(*dof));
1541 dof->dof_type = dt_mode_to_dft(S_IFDIR);
1543 rc = linkea_links_new(&ldata, &info->lti_linkea_buf2,
1544 cname, lfsck_dto2fid(parent));
1548 th = dt_trans_create(env, dev);
1550 GOTO(unlock1, rc = PTR_ERR(th));
1552 /* Sync the remote transaction to guarantee that the subsequent
1553 * lock against the @orphan can find the @orphan in time. */
1554 if (dt_object_remote(orphan))
1557 rc = dt_declare_create(env, orphan, la, hint, dof, th);
1561 if (unlikely(!dt_try_as_dir(env, orphan)))
1562 GOTO(stop, rc = -ENOTDIR);
1564 rc = dt_declare_ref_add(env, orphan, th);
1568 rec->rec_type = S_IFDIR;
1569 rec->rec_fid = cfid;
1570 rc = dt_declare_insert(env, orphan, (const struct dt_rec *)rec,
1571 (const struct dt_key *)dot, th);
1575 rec->rec_fid = lfsck_dto2fid(parent);
1576 rc = dt_declare_insert(env, orphan, (const struct dt_rec *)rec,
1577 (const struct dt_key *)dotdot, th);
1582 lmv->lmv_magic = LMV_MAGIC;
1583 lmv->lmv_master_mdt_index = lfsck_dev_idx(lfsck);
1584 lfsck_lmv_header_cpu_to_le(lmv2, lmv);
1585 lfsck_buf_init(&lmv_buf, lmv2, sizeof(*lmv2));
1586 rc = dt_declare_xattr_set(env, orphan, &lmv_buf, XATTR_NAME_LMV,
1592 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
1593 ldata.ld_leh->leh_len);
1594 rc = dt_declare_xattr_set(env, orphan, &linkea_buf,
1595 XATTR_NAME_LINK, 0, th);
1599 rec->rec_fid = cfid;
1600 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
1601 (const struct dt_key *)name, th);
1603 rc = dt_declare_ref_add(env, parent, th);
1608 rc = dt_trans_start_local(env, dev, th);
1612 dt_write_lock(env, orphan, 0);
1613 rc = dt_create(env, orphan, la, hint, dof, th);
1617 rc = dt_ref_add(env, orphan, th);
1621 rec->rec_fid = cfid;
1622 rc = dt_insert(env, orphan, (const struct dt_rec *)rec,
1623 (const struct dt_key *)dot, th);
1627 rec->rec_fid = lfsck_dto2fid(parent);
1628 rc = dt_insert(env, orphan, (const struct dt_rec *)rec,
1629 (const struct dt_key *)dotdot, th);
1634 rc = dt_xattr_set(env, orphan, &lmv_buf, XATTR_NAME_LMV, 0, th);
1639 rc = dt_xattr_set(env, orphan, &linkea_buf,
1640 XATTR_NAME_LINK, 0, th);
1641 dt_write_unlock(env, orphan);
1645 rec->rec_fid = cfid;
1646 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
1647 (const struct dt_key *)name, th);
1649 dt_write_lock(env, parent, 0);
1650 rc = dt_ref_add(env, parent, th);
1651 dt_write_unlock(env, parent);
1654 GOTO(stop, rc = (rc == 0 ? 1 : rc));
1657 dt_write_unlock(env, orphan);
1660 rc1 = dt_trans_stop(env, dev, th);
1661 if (rc1 != 0 && rc > 0)
1668 CDEBUG(D_LFSCK, "%s: namespace LFSCK create orphan dir for "
1669 "the object "DFID", name = %s: rc = %d\n",
1670 lfsck_lfsck2name(lfsck), PFID(cfid),
1671 cname->ln_name != NULL ? cname->ln_name : "<NULL>", rc);
1673 if (parent != NULL && !IS_ERR(parent) && parent != lfsck->li_lpf_obj)
1674 lfsck_object_put(env, parent);
1677 ns->ln_flags |= LF_INCONSISTENT;
1683 * Remove the specified entry from the linkEA.
1685 * Locate the linkEA entry with the given @cname and @pfid, then
1686 * remove this entry or the other entries those are repeated with
1689 * \param[in] env pointer to the thread context
1690 * \param[in] com pointer to the lfsck component
1691 * \param[in] obj pointer to the dt_object to be handled
1692 * \param[in,out]ldata pointer to the buffer that holds the linkEA
1693 * \param[in] cname the name for the child in the parent directory
1694 * \param[in] pfid the parent directory's FID for the linkEA
1695 * \param[in] next if true, then remove the first found linkEA
1696 * entry, and move the ldata->ld_lee to next entry
1698 * \retval positive number for repaired cases
1699 * \retval 0 if nothing to be repaired
1700 * \retval negative error number on failure
1702 static int lfsck_namespace_shrink_linkea(const struct lu_env *env,
1703 struct lfsck_component *com,
1704 struct dt_object *obj,
1705 struct linkea_data *ldata,
1706 struct lu_name *cname,
1707 struct lu_fid *pfid,
1710 struct lfsck_instance *lfsck = com->lc_lfsck;
1711 struct dt_device *dev = lfsck_obj2dev(obj);
1712 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
1713 struct thandle *th = NULL;
1714 struct lustre_handle lh = { 0 };
1715 struct linkea_data ldata_new = { NULL };
1716 struct lu_buf linkea_buf;
1721 rc = lfsck_ibits_lock(env, lfsck, obj, &lh,
1722 MDS_INODELOCK_UPDATE | MDS_INODELOCK_XATTR,
1728 lfsck_linkea_del_buf(ldata, cname);
1730 lfsck_namespace_filter_linkea_entry(ldata, cname, pfid,
1732 if (ldata->ld_leh->leh_reccount > 0 ||
1733 unlikely(ldata->ld_leh->leh_overflow_time)) {
1734 lfsck_buf_init(&linkea_buf, ldata->ld_buf->lb_buf,
1735 ldata->ld_leh->leh_len);
1736 buflen = linkea_buf.lb_len;
1740 th = dt_trans_create(env, dev);
1742 GOTO(unlock1, rc = PTR_ERR(th));
1745 rc = dt_declare_xattr_set(env, obj, &linkea_buf,
1746 XATTR_NAME_LINK, 0, th);
1748 rc = dt_declare_xattr_del(env, obj, XATTR_NAME_LINK, th);
1752 rc = dt_trans_start_local(env, dev, th);
1756 dt_write_lock(env, obj, 0);
1757 if (unlikely(lfsck_is_dead_obj(obj)))
1758 GOTO(unlock2, rc = -ENOENT);
1760 rc = lfsck_links_read2_with_rec(env, obj, &ldata_new);
1762 GOTO(unlock2, rc = (rc == -ENODATA ? 0 : rc));
1764 /* The specified linkEA entry has been removed by race. */
1765 rc = linkea_links_find(&ldata_new, cname, pfid);
1767 GOTO(unlock2, rc = 0);
1769 if (bk->lb_param & LPF_DRYRUN)
1770 GOTO(unlock2, rc = 1);
1773 lfsck_linkea_del_buf(&ldata_new, cname);
1775 lfsck_namespace_filter_linkea_entry(&ldata_new, cname, pfid,
1779 * linkea may change because it doesn't take lock in the first read, if
1780 * it becomes larger, restart from beginning.
1782 if ((ldata_new.ld_leh->leh_reccount > 0 ||
1783 unlikely(ldata_new.ld_leh->leh_overflow_time)) &&
1784 buflen < ldata_new.ld_leh->leh_len) {
1785 dt_write_unlock(env, obj);
1786 dt_trans_stop(env, dev, th);
1787 lfsck_buf_init(&linkea_buf, ldata_new.ld_buf->lb_buf,
1788 ldata_new.ld_leh->leh_len);
1789 buflen = linkea_buf.lb_len;
1794 rc = lfsck_links_write(env, obj, &ldata_new, th);
1796 rc = dt_xattr_del(env, obj, XATTR_NAME_LINK, th);
1798 GOTO(unlock2, rc = (rc == 0 ? 1 : rc));
1801 dt_write_unlock(env, obj);
1804 dt_trans_stop(env, dev, th);
1807 lfsck_ibits_unlock(&lh, LCK_EX);
1810 CDEBUG(D_LFSCK, "%s: namespace LFSCK remove %s linkEA entry "
1811 "for the object: "DFID", parent "DFID", name %.*s\n",
1812 lfsck_lfsck2name(lfsck), next ? "invalid" : "redundant",
1813 PFID(lfsck_dto2fid(obj)), PFID(pfid), cname->ln_namelen,
1817 struct lfsck_namespace *ns = com->lc_file_ram;
1819 ns->ln_flags |= LF_INCONSISTENT;
1826 * Conditionally remove the specified entry from the linkEA.
1828 * Take the parent lock firstly, then check whether the specified
1829 * name entry exists or not: if yes, do nothing; otherwise, call
1830 * lfsck_namespace_shrink_linkea() to remove the linkea entry.
1832 * \param[in] env pointer to the thread context
1833 * \param[in] com pointer to the lfsck component
1834 * \param[in] parent pointer to the parent directory
1835 * \param[in] child pointer to the child object that holds the linkEA
1836 * \param[in,out]ldata pointer to the buffer that holds the linkEA
1837 * \param[in] cname the name for the child in the parent directory
1838 * \param[in] pfid the parent directory's FID for the linkEA
1840 * \retval positive number for repaired cases
1841 * \retval 0 if nothing to be repaired
1842 * \retval negative error number on failure
1844 static int lfsck_namespace_shrink_linkea_cond(const struct lu_env *env,
1845 struct lfsck_component *com,
1846 struct dt_object *parent,
1847 struct dt_object *child,
1848 struct linkea_data *ldata,
1849 struct lu_name *cname,
1850 struct lu_fid *pfid)
1852 struct lfsck_thread_info *info = lfsck_env_info(env);
1853 struct lu_fid *cfid = &info->lti_fid3;
1854 struct lfsck_lock_handle *llh = &info->lti_llh;
1858 rc = lfsck_lock(env, com->lc_lfsck, parent, cname->ln_name, llh,
1859 MDS_INODELOCK_UPDATE, LCK_PR);
1863 dt_read_lock(env, parent, 0);
1864 if (unlikely(lfsck_is_dead_obj(parent))) {
1865 dt_read_unlock(env, parent);
1867 rc = lfsck_namespace_shrink_linkea(env, com, child, ldata,
1873 rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
1874 (const struct dt_key *)cname->ln_name);
1875 dt_read_unlock(env, parent);
1877 /* It is safe to release the ldlm lock, because when the logic come
1878 * here, we have got all the needed information above whether the
1879 * linkEA entry is valid or not. It is not important that others
1880 * may add new linkEA entry after the ldlm lock released. If other
1881 * has removed the specified linkEA entry by race, then it is OK,
1882 * because the subsequent lfsck_namespace_shrink_linkea() can handle
1885 if (rc == -ENOENT) {
1886 rc = lfsck_namespace_shrink_linkea(env, com, child, ldata,
1895 /* The LFSCK just found some internal status of cross-MDTs
1896 * create operation. That is normal. */
1897 if (lu_fid_eq(cfid, lfsck_dto2fid(child))) {
1898 linkea_next_entry(ldata);
1903 rc = lfsck_namespace_shrink_linkea(env, com, child, ldata, cname,
1910 * Conditionally replace name entry in the parent.
1912 * As required, the LFSCK may re-create the lost MDT-object for dangling
1913 * name entry, but such repairing may be wrong because of bad FID in the
1914 * name entry. As the LFSCK processing, the real MDT-object may be found,
1915 * then the LFSCK should check whether the former re-created MDT-object
1916 * has been modified or not, if not, then destroy it and update the name
1917 * entry in the parent to reference the real MDT-object.
1919 * \param[in] env pointer to the thread context
1920 * \param[in] com pointer to the lfsck component
1921 * \param[in] parent pointer to the parent directory
1922 * \param[in] child pointer to the MDT-object that may be the real
1923 * MDT-object corresponding to the name entry in parent
1924 * \param[in] cfid the current FID in the name entry
1925 * \param[in] cname contains the name of the child in the parent directory
1927 * \retval positive number for repaired cases
1928 * \retval 0 if nothing to be repaired
1929 * \retval negative error number on failure
1931 static int lfsck_namespace_replace_cond(const struct lu_env *env,
1932 struct lfsck_component *com,
1933 struct dt_object *parent,
1934 struct dt_object *child,
1935 const struct lu_fid *cfid,
1936 const struct lu_name *cname)
1938 struct lfsck_thread_info *info = lfsck_env_info(env);
1939 struct lu_attr *la = &info->lti_la;
1940 struct dt_insert_rec *rec = &info->lti_dt_rec;
1942 struct lfsck_instance *lfsck = com->lc_lfsck;
1943 /* The child and its name may be on different MDTs. */
1944 struct dt_device *dev = lfsck->li_next;
1945 const char *name = cname->ln_name;
1946 const struct lu_fid *pfid = lfsck_dto2fid(parent);
1947 struct dt_object *cobj = NULL;
1948 struct lfsck_lock_handle *pllh = &info->lti_llh;
1949 struct lustre_handle clh = { 0 };
1950 struct linkea_data ldata = { NULL };
1951 struct thandle *th = NULL;
1956 /* @parent/@child may be based on lfsck->li_bottom,
1957 * but here we need the object based on the lfsck->li_next. */
1959 parent = lfsck_object_locate(dev, parent);
1961 GOTO(log, rc = PTR_ERR(parent));
1963 if (unlikely(!dt_try_as_dir(env, parent)))
1964 GOTO(log, rc = -ENOTDIR);
1966 rc = lfsck_lock(env, lfsck, parent, name, pllh,
1967 MDS_INODELOCK_UPDATE, LCK_PW);
1971 if (!fid_is_sane(cfid)) {
1976 cobj = lfsck_object_find_by_dev(env, dev, cfid);
1979 if (rc == -ENOENT) {
1987 if (!dt_object_exists(cobj)) {
1992 rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
1993 (const struct dt_key *)name);
1994 if (rc == -ENOENT) {
2002 /* Someone changed the name entry, cannot replace it. */
2003 if (!lu_fid_eq(cfid, &tfid))
2006 /* lock the object to be destroyed. */
2007 rc = lfsck_ibits_lock(env, lfsck, cobj, &clh,
2008 MDS_INODELOCK_UPDATE |
2009 MDS_INODELOCK_UPDATE | MDS_INODELOCK_XATTR,
2014 if (unlikely(lfsck_is_dead_obj(cobj))) {
2019 rc = dt_attr_get(env, cobj, la);
2023 /* The object has been modified by other(s), or it is not created by
2024 * LFSCK, the two cases are indistinguishable. So cannot replace it. */
2025 if (la->la_ctime != 0)
2028 if (S_ISREG(la->la_mode)) {
2029 rc = dt_xattr_get(env, cobj, &LU_BUF_NULL, XATTR_NAME_LOV);
2030 /* If someone has created related OST-object(s),
2032 if ((rc > 0) || (rc < 0 && rc != -ENODATA))
2033 GOTO(log, rc = (rc > 0 ? 0 : rc));
2037 dt_read_lock(env, child, 0);
2038 rc = lfsck_links_read2_with_rec(env, child, &ldata);
2039 dt_read_unlock(env, child);
2041 /* Someone changed the child, no need to replace. */
2048 rc = linkea_links_find(&ldata, cname, pfid);
2049 /* Someone moved the child, no need to replace. */
2053 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
2056 th = dt_trans_create(env, dev);
2058 GOTO(log, rc = PTR_ERR(th));
2061 rc = dt_declare_destroy(env, cobj, th);
2066 rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
2070 rec->rec_type = S_IFDIR;
2071 rec->rec_fid = lfsck_dto2fid(child);
2072 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
2073 (const struct dt_key *)name, th);
2077 rc = dt_trans_start_local(env, dev, th);
2082 rc = dt_destroy(env, cobj, th);
2087 /* The old name entry maybe not exist. */
2088 rc = dt_delete(env, parent, (const struct dt_key *)name, th);
2089 if (rc != 0 && rc != -ENOENT)
2092 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
2093 (const struct dt_key *)name, th);
2095 GOTO(stop, rc = (rc == 0 ? 1 : rc));
2098 dt_trans_stop(env, dev, th);
2101 lfsck_ibits_unlock(&clh, LCK_EX);
2104 if (cobj != NULL && !IS_ERR(cobj))
2105 lfsck_object_put(env, cobj);
2107 CDEBUG(D_LFSCK, "%s: namespace LFSCK conditionally destroy the "
2108 "object "DFID" because of conflict with the object "DFID
2109 " under the parent "DFID" with name %s: rc = %d\n",
2110 lfsck_lfsck2name(lfsck), PFID(cfid),
2111 PFID(lfsck_dto2fid(child)), PFID(pfid), name, rc);
2117 * Overwrite the linkEA for the object with the given ldata.
2119 * The caller should take the ldlm lock before the calling.
2121 * \param[in] env pointer to the thread context
2122 * \param[in] com pointer to the lfsck component
2123 * \param[in] obj pointer to the dt_object to be handled
2124 * \param[in] ldata pointer to the new linkEA data
2126 * \retval positive number for repaired cases
2127 * \retval 0 if nothing to be repaired
2128 * \retval negative error number on failure
2130 int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
2131 struct lfsck_component *com,
2132 struct dt_object *obj,
2133 struct linkea_data *ldata)
2135 struct lfsck_instance *lfsck = com->lc_lfsck;
2136 struct dt_device *dev = lfsck_obj2dev(obj);
2137 struct thandle *th = NULL;
2138 struct lu_buf linkea_buf;
2142 th = dt_trans_create(env, dev);
2144 GOTO(log, rc = PTR_ERR(th));
2146 lfsck_buf_init(&linkea_buf, ldata->ld_buf->lb_buf,
2147 ldata->ld_leh->leh_len);
2148 rc = dt_declare_xattr_set(env, obj, &linkea_buf,
2149 XATTR_NAME_LINK, 0, th);
2153 rc = dt_trans_start_local(env, dev, th);
2157 dt_write_lock(env, obj, 0);
2158 if (unlikely(lfsck_is_dead_obj(obj)))
2159 GOTO(unlock, rc = 0);
2161 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
2162 GOTO(unlock, rc = 1);
2164 rc = dt_xattr_set(env, obj, &linkea_buf,
2165 XATTR_NAME_LINK, 0, th);
2167 GOTO(unlock, rc = (rc == 0 ? 1 : rc));
2170 dt_write_unlock(env, obj);
2173 dt_trans_stop(env, dev, th);
2176 CDEBUG(D_LFSCK, "%s: namespace LFSCK rebuild linkEA for the "
2177 "object "DFID": rc = %d\n",
2178 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(obj)), rc);
2181 struct lfsck_namespace *ns = com->lc_file_ram;
2183 ns->ln_flags |= LF_INCONSISTENT;
2190 * Repair invalid name entry.
2192 * If the name entry contains invalid information, such as bad file type
2193 * or (and) corrupted object FID, then either remove the name entry or
2194 * udpate the name entry with the given (right) information.
2196 * \param[in] env pointer to the thread context
2197 * \param[in] com pointer to the lfsck component
2198 * \param[in] parent pointer to the parent directory
2199 * \param[in] child pointer to the object referenced by the name entry
2200 * \param[in] name the old name of the child under the parent directory
2201 * \param[in] name2 the new name of the child under the parent directory
2202 * \param[in] type the type claimed by the name entry
2203 * \param[in] update update the name entry if true; otherwise, remove it
2204 * \param[in] dec decrease the parent nlink count if true
2206 * \retval positive number for repaired successfully
2207 * \retval 0 if nothing to be repaired
2208 * \retval negative error number on failure
2210 int lfsck_namespace_repair_dirent(const struct lu_env *env,
2211 struct lfsck_component *com,
2212 struct dt_object *parent,
2213 struct dt_object *child,
2214 const char *name, const char *name2,
2215 __u16 type, bool update, bool dec)
2217 struct lfsck_thread_info *info = lfsck_env_info(env);
2218 struct dt_insert_rec *rec = &info->lti_dt_rec;
2219 const struct lu_fid *pfid = lfsck_dto2fid(parent);
2220 struct lu_fid cfid = {0};
2222 struct lfsck_instance *lfsck = com->lc_lfsck;
2223 struct dt_device *dev = lfsck->li_next;
2224 struct thandle *th = NULL;
2225 struct lfsck_lock_handle *llh = &info->lti_llh;
2226 struct lustre_handle lh = { 0 };
2231 cfid = *lfsck_dto2fid(child);
2232 parent = lfsck_object_locate(dev, parent);
2234 GOTO(log, rc = PTR_ERR(parent));
2236 if (unlikely(!dt_try_as_dir(env, parent)))
2237 GOTO(log, rc = -ENOTDIR);
2239 if (!update || strcmp(name, name2) == 0)
2240 rc = lfsck_lock(env, lfsck, parent, name, llh,
2241 MDS_INODELOCK_UPDATE, LCK_PW);
2243 rc = lfsck_ibits_lock(env, lfsck, parent, &lh,
2244 MDS_INODELOCK_UPDATE, LCK_PW);
2248 th = dt_trans_create(env, dev);
2250 GOTO(unlock1, rc = PTR_ERR(th));
2252 rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
2257 rec->rec_type = lfsck_object_type(child) & S_IFMT;
2258 LASSERT(!fid_is_zero(&cfid));
2259 rec->rec_fid = &cfid;
2260 rc = dt_declare_insert(env, parent,
2261 (const struct dt_rec *)rec,
2262 (const struct dt_key *)name2, th);
2267 if (dec && S_ISDIR(type)) {
2268 rc = dt_declare_ref_del(env, parent, th);
2273 rc = dt_trans_start_local(env, dev, th);
2278 dt_write_lock(env, parent, 0);
2279 rc = dt_lookup(env, dt_object_child(parent), (struct dt_rec *)&tfid,
2280 (const struct dt_key *)name);
2281 /* Someone has removed the bad name entry by race. */
2283 GOTO(unlock2, rc = 0);
2288 /* Someone has removed the bad name entry and reused it for other
2289 * object by race. */
2290 if (!lu_fid_eq(&tfid, &cfid))
2291 GOTO(unlock2, rc = 0);
2293 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
2294 GOTO(unlock2, rc = 1);
2296 rc = dt_delete(env, parent, (const struct dt_key *)name, th);
2301 rc = dt_insert(env, parent,
2302 (const struct dt_rec *)rec,
2303 (const struct dt_key *)name2, th);
2308 if (dec && S_ISDIR(type)) {
2309 rc = dt_ref_del(env, parent, th);
2314 GOTO(unlock2, rc = (rc == 0 ? 1 : rc));
2317 dt_write_unlock(env, parent);
2320 dt_trans_stop(env, dev, th);
2322 /* We are not sure whether the child will become orphan or not.
2323 * Record it in the LFSCK trace file for further checking in
2324 * the second-stage scanning. */
2325 if (!update && !dec && child && rc == 0)
2326 lfsck_namespace_trace_update(env, com, &cfid,
2327 LNTF_CHECK_LINKEA, true);
2330 /* It is harmless even if unlock the unused lock_handle */
2331 lfsck_ibits_unlock(&lh, LCK_PW);
2335 CDEBUG(D_LFSCK, "%s: namespace LFSCK assistant found bad name "
2336 "entry for: parent "DFID", child "DFID", name %s, type "
2337 "in name entry %o, type claimed by child %o. repair it "
2338 "by %s with new name2 %s: rc = %d\n",
2339 lfsck_lfsck2name(lfsck), PFID(pfid), PFID(&cfid),
2340 name, type, update ? lfsck_object_type(child) : 0,
2341 update ? "updating" : "removing", name2, rc);
2344 struct lfsck_namespace *ns = com->lc_file_ram;
2346 ns->ln_flags |= LF_INCONSISTENT;
2353 * Update the ".." name entry for the given object.
2355 * The object's ".." is corrupted, this function will update the ".." name
2356 * entry with the given pfid, and the linkEA with the given ldata.
2358 * The caller should take the ldlm lock before the calling.
2360 * \param[in] env pointer to the thread context
2361 * \param[in] com pointer to the lfsck component
2362 * \param[in] obj pointer to the dt_object to be handled
2363 * \param[in] pfid the new fid for the object's ".." name entry
2364 * \param[in] cname the name for the @obj in the parent directory
2366 * \retval positive number for repaired cases
2367 * \retval 0 if nothing to be repaired
2368 * \retval negative error number on failure
2370 static int lfsck_namespace_repair_unmatched_pairs(const struct lu_env *env,
2371 struct lfsck_component *com,
2372 struct dt_object *obj,
2373 const struct lu_fid *pfid,
2374 struct lu_name *cname)
2376 struct lfsck_thread_info *info = lfsck_env_info(env);
2377 struct dt_insert_rec *rec = &info->lti_dt_rec;
2378 struct lfsck_instance *lfsck = com->lc_lfsck;
2379 struct dt_device *dev = lfsck_obj2dev(obj);
2380 struct thandle *th = NULL;
2381 struct linkea_data ldata = { NULL };
2382 struct lu_buf linkea_buf;
2386 LASSERT(!dt_object_remote(obj));
2387 LASSERT(S_ISDIR(lfsck_object_type(obj)));
2389 rc = linkea_links_new(&ldata, &info->lti_big_buf, cname, pfid);
2393 lfsck_buf_init(&linkea_buf, ldata.ld_buf->lb_buf,
2394 ldata.ld_leh->leh_len);
2396 th = dt_trans_create(env, dev);
2398 GOTO(log, rc = PTR_ERR(th));
2400 rc = dt_declare_delete(env, obj, (const struct dt_key *)dotdot, th);
2404 rec->rec_type = S_IFDIR;
2405 rec->rec_fid = pfid;
2406 rc = dt_declare_insert(env, obj, (const struct dt_rec *)rec,
2407 (const struct dt_key *)dotdot, th);
2411 rc = dt_declare_xattr_set(env, obj, &linkea_buf,
2412 XATTR_NAME_LINK, 0, th);
2416 rc = dt_trans_start_local(env, dev, th);
2420 dt_write_lock(env, obj, 0);
2421 if (unlikely(lfsck_is_dead_obj(obj)))
2422 GOTO(unlock, rc = 0);
2424 if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
2425 GOTO(unlock, rc = 1);
2427 /* The old ".." name entry maybe not exist. */
2428 dt_delete(env, obj, (const struct dt_key *)dotdot, th);
2430 rc = dt_insert(env, obj, (const struct dt_rec *)rec,
2431 (const struct dt_key *)dotdot, th);
2435 rc = lfsck_links_write(env, obj, &ldata, th);
2437 GOTO(unlock, rc = (rc == 0 ? 1 : rc));
2440 dt_write_unlock(env, obj);
2443 dt_trans_stop(env, dev, th);
2446 CDEBUG(D_LFSCK, "%s: namespace LFSCK rebuild dotdot name entry for "
2447 "the object "DFID", new parent "DFID": rc = %d\n",
2448 lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(obj)),
2452 struct lfsck_namespace *ns = com->lc_file_ram;
2454 ns->ln_flags |= LF_INCONSISTENT;
2461 * Handle orphan @obj during Double Scan Directory.
2463 * Remove the @obj's current (invalid) linkEA entries, and insert
2464 * it in the directory .lustre/lost+found/MDTxxxx/ with the name:
2465 * ${FID}-${PFID}-D-${conflict_version}
2467 * The caller should take the ldlm lock before the calling.
2469 * \param[in] env pointer to the thread context
2470 * \param[in] com pointer to the lfsck component
2471 * \param[in] obj pointer to the orphan object to be handled
2472 * \param[in] pfid the new fid for the object's ".." name entry
2473 * \param[in,out] lh ldlm lock handler for the given @obj
2474 * \param[out] type to tell the caller what the inconsistency is
2476 * \retval positive number for repaired cases
2477 * \retval 0 if nothing to be repaired
2478 * \retval negative error number on failure
2481 lfsck_namespace_dsd_orphan(const struct lu_env *env,
2482 struct lfsck_component *com,
2483 struct dt_object *obj,
2484 const struct lu_fid *pfid,
2485 struct lustre_handle *lh,
2486 enum lfsck_namespace_inconsistency_type *type)
2488 struct lfsck_thread_info *info = lfsck_env_info(env);
2489 struct lfsck_namespace *ns = com->lc_file_ram;
2493 /* Remove the unrecognized linkEA. */
2494 rc = lfsck_namespace_links_remove(env, com, obj);
2495 lfsck_ibits_unlock(lh, LCK_EX);
2496 if (rc < 0 && rc != -ENODATA)
2499 *type = LNIT_MUL_REF;
2501 /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT has
2502 * ever tried to verify some remote MDT-object that resides on this
2503 * MDT, but this MDT failed to respond such request. So means there
2504 * may be some remote name entry on other MDT that references this
2505 * object with another name, so we cannot know whether this linkEA
2506 * is valid or not. So keep it there and maybe resolved when next
2508 if (ns->ln_flags & LF_INCOMPLETE)
2511 /* The unique linkEA is invalid, even if the ".." name entry may be
2512 * valid, we still cannot know via which name entry this directory
2513 * will be referenced. Then handle it as pure orphan. */
2514 snprintf(info->lti_tmpbuf, sizeof(info->lti_tmpbuf),
2515 "-"DFID, PFID(pfid));
2516 rc = lfsck_namespace_insert_orphan(env, com, obj,
2517 info->lti_tmpbuf, "D", NULL);
2523 * Double Scan Directory object for single linkEA entry case.
2525 * The given @child has unique linkEA entry. If the linkEA entry is valid,
2526 * then check whether the name is in the namespace or not, if not, add the
2527 * missing name entry back to namespace. If the linkEA entry is invalid,
2528 * then remove it and insert the @child in the .lustre/lost+found/MDTxxxx/
2531 * \param[in] env pointer to the thread context
2532 * \param[in] com pointer to the lfsck component
2533 * \param[in] child pointer to the directory to be double scanned
2534 * \param[in] pfid the FID corresponding to the ".." entry
2535 * \param[in] ldata pointer to the linkEA data for the given @child
2536 * \param[in,out] lh ldlm lock handler for the given @child
2537 * \param[out] type to tell the caller what the inconsistency is
2538 * \param[in] retry if found inconsistency, but the caller does not hold
2539 * ldlm lock on the @child, then set @retry as true
2540 * \param[in] unknown set if does not know how to repair the inconsistency
2542 * \retval positive number for repaired cases
2543 * \retval 0 if nothing to be repaired
2544 * \retval negative error number on failure
2547 lfsck_namespace_dsd_single(const struct lu_env *env,
2548 struct lfsck_component *com,
2549 struct dt_object *child,
2550 const struct lu_fid *pfid,
2551 struct linkea_data *ldata,
2552 struct lustre_handle *lh,
2553 enum lfsck_namespace_inconsistency_type *type,
2554 bool *retry, bool *unknown)
2556 struct lfsck_thread_info *info = lfsck_env_info(env);
2557 struct lu_name *cname = &info->lti_name;
2558 const struct lu_fid *cfid = lfsck_dto2fid(child);
2560 struct lfsck_namespace *ns = com->lc_file_ram;
2561 struct lfsck_instance *lfsck = com->lc_lfsck;
2562 struct dt_object *parent = NULL;
2563 struct lmv_mds_md_v1 *lmv;
2567 rc = lfsck_namespace_unpack_linkea_entry(ldata, cname, &tfid,
2569 sizeof(info->lti_key));
2570 /* The unique linkEA entry with bad parent will be handled as orphan. */
2572 if (!lustre_handle_is_used(lh) && retry != NULL)
2575 rc = lfsck_namespace_dsd_orphan(env, com, child,
2581 parent = lfsck_object_find_bottom(env, lfsck, &tfid);
2583 GOTO(out, rc = PTR_ERR(parent));
2585 /* We trust the unique linkEA entry in spite of whether it matches the
2586 * ".." name entry or not. Because even if the linkEA entry is wrong
2587 * and the ".." name entry is right, we still cannot know via which
2588 * name entry the child will be referenced, since all known entries
2589 * have been verified during the first-stage scanning. */
2590 if (!dt_object_exists(parent)) {
2591 /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT
2592 * has ever tried to verify some remote MDT-object that resides
2593 * on this MDT, but this MDT failed to respond such request. So
2594 * means there may be some remote name entry on other MDT that
2595 * references this object with another name, so we cannot know
2596 * whether this linkEA is valid or not. So keep it there and
2597 * maybe resolved when next LFSCK run. */
2598 if (ns->ln_flags & LF_INCOMPLETE)
2601 if (!lustre_handle_is_used(lh) && retry != NULL) {
2607 lfsck_ibits_unlock(lh, LCK_EX);
2610 lmv = &info->lti_lmv;
2611 rc = lfsck_read_stripe_lmv(env, lfsck, child, lmv);
2612 if (rc != 0 && rc != -ENODATA)
2615 if (rc == -ENODATA || lmv->lmv_magic != LMV_MAGIC_STRIPE) {
2617 } else if (lfsck_shard_name_to_index(env,
2618 cname->ln_name, cname->ln_namelen,
2619 S_IFDIR, cfid) < 0) {
2620 /* It is an invalid name entry, we
2621 * cannot trust the parent also. */
2622 rc = lfsck_namespace_shrink_linkea(env, com, child,
2623 ldata, cname, &tfid, true);
2627 snprintf(info->lti_tmpbuf, sizeof(info->lti_tmpbuf),
2628 "-"DFID, PFID(pfid));
2629 rc = lfsck_namespace_insert_orphan(env, com, child,
2630 info->lti_tmpbuf, "S", NULL);
2635 /* Create the lost parent as an orphan. */
2636 rc = lfsck_namespace_create_orphan_dir(env, com, parent, lmv);
2638 /* Add the missing name entry to the parent. */
2639 rc = lfsck_namespace_insert_normal(env, com, parent,
2641 if (unlikely(rc == -EEXIST)) {
2642 /* Unfortunately, someone reused the name
2643 * under the parent by race. So we have
2644 * to remove the linkEA entry from
2645 * current child object. It means that the
2646 * LFSCK cannot recover the system
2647 * totally back to its original status,
2648 * but it is necessary to make the
2649 * current system to be consistent. */
2650 rc = lfsck_namespace_shrink_linkea(env,
2652 cname, &tfid, true);
2654 snprintf(info->lti_tmpbuf,
2655 sizeof(info->lti_tmpbuf),
2656 "-"DFID, PFID(pfid));
2657 rc = lfsck_namespace_insert_orphan(env,
2658 com, child, info->lti_tmpbuf,
2665 } /* !dt_object_exists(parent) */
2667 /* The unique linkEA entry with bad parent will be handled as orphan. */
2668 if (unlikely(!dt_try_as_dir(env, parent))) {
2669 if (!lustre_handle_is_used(lh) && retry != NULL)
2672 rc = lfsck_namespace_dsd_orphan(env, com, child,
2678 rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
2679 (const struct dt_key *)cname->ln_name);
2680 if (rc == -ENOENT) {
2681 /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT
2682 * has ever tried to verify some remote MDT-object that resides
2683 * on this MDT, but this MDT failed to respond such request. So
2684 * means there may be some remote name entry on other MDT that
2685 * references this object with another name, so we cannot know
2686 * whether this linkEA is valid or not. So keep it there and
2687 * maybe resolved when next LFSCK run. */
2688 if (ns->ln_flags & LF_INCOMPLETE)
2691 if (!lustre_handle_is_used(lh) && retry != NULL) {
2697 lfsck_ibits_unlock(lh, LCK_EX);
2698 rc = lfsck_namespace_check_name(env, lfsck, parent, child,
2706 /* It is an invalid name entry, drop it. */
2707 if (unlikely(rc > 0)) {
2708 rc = lfsck_namespace_shrink_linkea(env, com, child,
2709 ldata, cname, &tfid, true);
2711 snprintf(info->lti_tmpbuf,
2712 sizeof(info->lti_tmpbuf),
2713 "-"DFID, PFID(pfid));
2714 rc = lfsck_namespace_insert_orphan(env, com,
2715 child, info->lti_tmpbuf, "D", NULL);
2721 /* Add the missing name entry back to the namespace. */
2722 rc = lfsck_namespace_insert_normal(env, com, parent, child,
2724 if (unlikely(rc == -ESTALE))
2725 /* It may happen when the remote object has been
2726 * removed, but the local MDT is not aware of that. */
2729 if (unlikely(rc == -EEXIST)) {
2730 /* Unfortunately, someone reused the name under the
2731 * parent by race. So we have to remove the linkEA
2732 * entry from current child object. It means that the
2733 * LFSCK cannot recover the system totally back to
2734 * its original status, but it is necessary to make
2735 * the current system to be consistent.
2737 * It also may be because of the LFSCK found some
2738 * internal status of create operation. Under such
2739 * case, nothing to be done. */
2740 rc = lfsck_namespace_shrink_linkea_cond(env, com,
2741 parent, child, ldata, cname, &tfid);
2743 snprintf(info->lti_tmpbuf,
2744 sizeof(info->lti_tmpbuf),
2745 "-"DFID, PFID(pfid));
2746 rc = lfsck_namespace_insert_orphan(env, com,
2747 child, info->lti_tmpbuf, "D", NULL);
2752 } /* rc == -ENOENT */
2757 if (!lu_fid_eq(&tfid, cfid)) {
2758 if (!lustre_handle_is_used(lh) && retry != NULL) {
2764 lfsck_ibits_unlock(lh, LCK_EX);
2765 /* The name entry references another MDT-object that
2766 * may be created by the LFSCK for repairing dangling
2767 * name entry. Try to replace it. */
2768 rc = lfsck_namespace_replace_cond(env, com, parent, child,
2771 rc = lfsck_namespace_dsd_orphan(env, com, child,
2777 /* Zero FID may because the remote directroy object has invalid linkEA,
2778 * or lost linkEA. Under such case, the LFSCK on this MDT does not know
2779 * how to repair the inconsistency, but the namespace LFSCK on the MDT
2780 * where its name entry resides may has more information (name, FID) to
2781 * repair such inconsistency. So here, keep the inconsistency to avoid
2782 * some imporper repairing. */
2783 if (fid_is_zero(pfid)) {
2790 /* The ".." name entry is wrong, update it. */
2791 if (!lu_fid_eq(pfid, lfsck_dto2fid(parent))) {
2792 if (!lustre_handle_is_used(lh) && retry != NULL) {
2798 *type = LNIT_UNMATCHED_PAIRS;
2799 rc = lfsck_namespace_repair_unmatched_pairs(env, com, child,
2800 lfsck_dto2fid(parent), cname);
2806 if (parent != NULL && !IS_ERR(parent))
2807 lfsck_object_put(env, parent);
2813 * Double Scan Directory object for multiple linkEA entries case.
2815 * The given @child has multiple linkEA entries. There is at most one linkEA
2816 * entry will be valid, all the others will be removed. Firstly, the function
2817 * will try to find out the linkEA entry for which the name entry exists under
2818 * the given parent (@pfid). If there is no linkEA entry that matches the given
2819 * ".." name entry, then tries to find out the first linkEA entry that both the
2820 * parent and the name entry exist to rebuild a new ".." name entry.
2822 * \param[in] env pointer to the thread context
2823 * \param[in] com pointer to the lfsck component
2824 * \param[in] child pointer to the directory to be double scanned
2825 * \param[in] pfid the FID corresponding to the ".." entry
2826 * \param[in] ldata pointer to the linkEA data for the given @child
2827 * \param[in,out] lh ldlm lock handler for the given @child
2828 * \param[out] type to tell the caller what the inconsistency is
2829 * \param[in] lpf true if the ".." entry is under lost+found/MDTxxxx/
2830 * \param[in] unknown set if does not know how to repair the inconsistency
2832 * \retval positive number for repaired cases
2833 * \retval 0 if nothing to be repaired
2834 * \retval negative error number on failure
2837 lfsck_namespace_dsd_multiple(const struct lu_env *env,
2838 struct lfsck_component *com,
2839 struct dt_object *child,
2840 const struct lu_fid *pfid,
2841 struct linkea_data *ldata,
2842 struct lustre_handle *lh,
2843 enum lfsck_namespace_inconsistency_type *type,
2844 bool lpf, bool *unknown)
2846 struct lfsck_thread_info *info = lfsck_env_info(env);
2847 struct lu_name *cname = &info->lti_name;
2848 const struct lu_fid *cfid = lfsck_dto2fid(child);
2849 struct lu_fid *pfid2 = &info->lti_fid3;
2851 struct lfsck_namespace *ns = com->lc_file_ram;
2852 struct lfsck_instance *lfsck = com->lc_lfsck;
2853 struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
2854 struct dt_object *parent = NULL;
2855 struct linkea_data ldata_new = { NULL };
2856 int dirent_count = 0;
2862 while (ldata->ld_lee != NULL) {
2863 rc = lfsck_namespace_unpack_linkea_entry(ldata, cname, &tfid,
2865 sizeof(info->lti_key));
2866 /* Drop invalid linkEA entry. */
2868 lfsck_linkea_del_buf(ldata, cname);
2872 /* Drop repeated linkEA entries. */
2873 lfsck_namespace_filter_linkea_entry(ldata, cname, &tfid, true);
2875 /* If current dotdot is the .lustre/lost+found/MDTxxxx/,
2876 * then it is possible that: the directry object has ever
2877 * been lost, but its name entry was there. In the former
2878 * LFSCK run, during the first-stage scanning, the LFSCK
2879 * found the dangling name entry, but it did not recreate
2880 * the lost object, and when moved to the second-stage
2881 * scanning, some children objects of the lost directory
2882 * object were found, then the LFSCK recreated such lost
2883 * directory object as an orphan.
2885 * When the LFSCK runs again, if the dangling name is still
2886 * there, the LFSCK should move the orphan directory object
2887 * back to the normal namespace. */
2888 if (!lpf && !fid_is_zero(pfid) &&
2889 !lu_fid_eq(pfid, &tfid) && once) {
2890 linkea_next_entry(ldata);
2894 parent = lfsck_object_find_bottom(env, lfsck, &tfid);
2896 RETURN(PTR_ERR(parent));
2898 if (!dt_object_exists(parent)) {
2899 lfsck_object_put(env, parent);
2900 if (ldata->ld_leh->leh_reccount > 1) {
2901 /* If it is NOT the last linkEA entry, then
2902 * there is still other chance to make the
2903 * child to be visible via other parent, then
2904 * remove this linkEA entry. */
2905 lfsck_linkea_del_buf(ldata, cname);
2912 /* The linkEA entry with bad parent will be removed. */
2913 if (unlikely(!dt_try_as_dir(env, parent))) {
2914 lfsck_object_put(env, parent);
2915 lfsck_linkea_del_buf(ldata, cname);
2919 rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
2920 (const struct dt_key *)cname->ln_name);
2921 *pfid2 = *lfsck_dto2fid(parent);
2922 if (rc == -ENOENT) {
2923 lfsck_object_put(env, parent);
2924 linkea_next_entry(ldata);
2929 lfsck_object_put(env, parent);
2934 if (lu_fid_eq(&tfid, cfid)) {
2935 lfsck_object_put(env, parent);
2936 /* If the parent (that is declared via linkEA entry)
2937 * directory contains the specified child, but such
2938 * parent does not match the dotdot name entry, then
2939 * trust the linkEA. */
2940 if (!fid_is_zero(pfid) && !lu_fid_eq(pfid, pfid2)) {
2941 *type = LNIT_UNMATCHED_PAIRS;
2942 rc = lfsck_namespace_repair_unmatched_pairs(env,
2943 com, child, pfid2, cname);
2949 /* It is the most common case that we find the
2950 * name entry corresponding to the linkEA entry
2951 * that matches the ".." name entry. */
2952 rc = linkea_links_new(&ldata_new, &info->lti_big_buf,
2957 rc = lfsck_namespace_rebuild_linkea(env, com, child,
2962 lfsck_linkea_del_buf(ldata, cname);
2963 linkea_first_entry(ldata);
2964 /* There may be some invalid dangling name entries under
2965 * other parent directories, remove all of them. */
2966 while (ldata->ld_lee != NULL) {
2967 rc = lfsck_namespace_unpack_linkea_entry(ldata,
2968 cname, &tfid, info->lti_key,
2969 sizeof(info->lti_key));
2973 parent = lfsck_object_find_bottom(env, lfsck,
2975 if (IS_ERR(parent)) {
2976 rc = PTR_ERR(parent);
2977 if (rc != -ENOENT &&
2978 bk->lb_param & LPF_FAILOUT)
2984 if (!dt_object_exists(parent)) {
2985 lfsck_object_put(env, parent);
2989 rc = lfsck_namespace_repair_dirent(env, com,
2990 parent, child, cname->ln_name,
2991 cname->ln_name, S_IFDIR, false, true);
2992 lfsck_object_put(env, parent);
2994 if (bk->lb_param & LPF_FAILOUT)
3003 lfsck_linkea_del_buf(ldata, cname);
3006 ns->ln_dirent_repaired += dirent_count;
3009 } /* lu_fid_eq(&tfid, lfsck_dto2fid(child)) */
3011 lfsck_ibits_unlock(lh, LCK_EX);
3012 /* The name entry references another MDT-object that may be
3013 * created by the LFSCK for repairing dangling name entry.
3014 * Try to replace it. */
3015 rc = lfsck_namespace_replace_cond(env, com, parent, child,
3017 lfsck_object_put(env, parent);
3024 lfsck_linkea_del_buf(ldata, cname);
3025 } /* while (ldata->ld_lee != NULL) */
3027 /* If there is still linkEA overflow, return. */
3028 if (unlikely(ldata->ld_leh->leh_overflow_time))
3031 linkea_first_entry(ldata);
3032 if (ldata->ld_leh->leh_reccount == 1) {
3033 rc = lfsck_namespace_dsd_single(env, com, child, pfid, ldata,
3034 lh, type, NULL, unknown);
3039 /* All linkEA entries are invalid and removed, then handle the @child
3041 if (ldata->ld_leh->leh_reccount == 0) {
3042 rc = lfsck_namespace_dsd_orphan(env, com, child, pfid, lh,