Whamcloud - gitweb
LU-6109 lfsck: check FID validity before locating object
[fs/lustre-release.git] / lustre / lfsck / lfsck_namespace.c
index af77f24..6e29717 100644 (file)
@@ -584,6 +584,9 @@ int lfsck_namespace_trace_update(const struct lu_env *env,
 
        LASSERT(flags != 0);
 
+       if (unlikely(!fid_is_sane(fid)))
+               RETURN(0);
+
        idx = lfsck_sub_trace_file_fid2idx(fid);
        obj = com->lc_sub_trace_objs[idx].lsto_obj;
        mutex_lock(&com->lc_sub_trace_objs[idx].lsto_mutex);
@@ -4947,7 +4950,7 @@ static int lfsck_namespace_assistant_handler_p1(const struct lu_env *env,
        bool                        bad_hash = false;
        int                         idx      = 0;
        int                         count    = 0;
-       int                         rc;
+       int                         rc       = 0;
        enum lfsck_namespace_inconsistency_type type = LNIT_NONE;
        ENTRY;
 
@@ -4972,6 +4975,24 @@ static int lfsck_namespace_assistant_handler_p1(const struct lu_env *env,
                GOTO(out, rc);
        }
 
+       if (unlikely(!fid_is_sane(&lnr->lnr_fid))) {
+               CDEBUG(D_LFSCK, "%s: dir scan find invalid FID "DFID
+                      " for the name entry %.*s under "DFID"\n",
+                      lfsck_lfsck2name(lfsck), PFID(&lnr->lnr_fid),
+                      lnr->lnr_namelen, lnr->lnr_name, PFID(pfid));
+
+               if (strcmp(lnr->lnr_name, dotdot) != 0)
+                       /* invalid FID means bad name entry, remove it. */
+                       type = LNIT_BAD_DIRENT;
+               else
+                       /* If the parent FID is invalid, we cannot remove
+                        * the ".." entry directly. */
+                       rc = lfsck_namespace_trace_update(env, com, pfid,
+                                               LNTF_CHECK_PARENT, true);
+
+               GOTO(out, rc);
+       }
+
        if (unlikely(lnr->lnr_dir_cookie == MDS_DIR_END_OFF)) {
                rc = lfsck_namespace_striped_dir_rescan(env, com, lnr);