Whamcloud - gitweb
LU-14119 lfsck: replace dt_lookup() with dt_lookup_dir()
[fs/lustre-release.git] / lustre / lfsck / lfsck_namespace.c
index 9606a11..ff660c4 100644 (file)
@@ -87,7 +87,7 @@ static void lfsck_namespace_assistant_req_fini(const struct lu_env *env,
                                               struct lfsck_assistant_req *lar)
 {
        struct lfsck_namespace_req *lnr =
-                       container_of0(lar, struct lfsck_namespace_req, lnr_lar);
+               container_of(lar, struct lfsck_namespace_req, lnr_lar);
 
        if (lnr->lnr_lmv != NULL)
                lfsck_lmv_put(env, lnr->lnr_lmv);
@@ -596,8 +596,7 @@ int lfsck_namespace_check_exist(const struct lu_env *env,
        if (unlikely(lfsck_is_dead_obj(obj)))
                RETURN(LFSCK_NAMEENTRY_DEAD);
 
-       rc = dt_lookup(env, dir, (struct dt_rec *)fid,
-                      (const struct dt_key *)name);
+       rc = dt_lookup_dir(env, dir, name, fid);
        if (rc == -ENOENT)
                RETURN(LFSCK_NAMEENTRY_REMOVED);
 
@@ -946,8 +945,7 @@ again:
        do {
                namelen = snprintf(info->lti_key, NAME_MAX, DFID"%s-%s-%d",
                                   PFID(cfid), infix, type, idx++);
-               rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
-                              (const struct dt_key *)info->lti_key);
+               rc = dt_lookup_dir(env, parent, info->lti_key, &tfid);
                if (rc != 0 && rc != -ENOENT)
                        GOTO(log, rc);
 
@@ -962,8 +960,7 @@ again:
 
        /* Re-check whether the name conflict with othrs after taken
         * the ldlm lock. */
-       rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
-                      (const struct dt_key *)info->lti_key);
+       rc = dt_lookup_dir(env, parent, info->lti_key, &tfid);
        if (rc == 0) {
                if (!lu_fid_eq(cfid, &tfid)) {
                        exist = false;
@@ -1129,7 +1126,7 @@ static int lfsck_lmv_set(const struct lu_env *env,
        if (IS_ERR(th))
                RETURN(PTR_ERR(th));
 
-       rc = dt_declare_xattr_set(env, obj, &buf, XATTR_NAME_LMV".set", 0, th);
+       rc = dt_declare_xattr_set(env, obj, &buf, XATTR_NAME_LMV, 0, th);
        if (rc)
                GOTO(stop, rc);
 
@@ -1137,7 +1134,7 @@ static int lfsck_lmv_set(const struct lu_env *env,
        if (rc != 0)
                GOTO(stop, rc);
 
-       rc = dt_xattr_set(env, obj, &buf, XATTR_NAME_LMV".set", 0, th);
+       rc = dt_xattr_set(env, obj, &buf, XATTR_NAME_LMV, 0, th);
        if (rc)
                GOTO(stop, rc);
 
@@ -1341,8 +1338,8 @@ static int lfsck_namespace_insert_normal(const struct lu_env *env,
        }
 
        if (parent_lmv_lost) {
-               rc = dt_declare_xattr_set(env, parent, &buf,
-                                         XATTR_NAME_LMV".set", 0, th);
+               rc = dt_declare_xattr_set(env, parent, &buf, XATTR_NAME_LMV,
+                                         0, th);
                if (rc)
                        GOTO(stop, rc);
        }
@@ -1375,8 +1372,7 @@ static int lfsck_namespace_insert_normal(const struct lu_env *env,
        }
 
        if (parent_lmv_lost) {
-               rc = dt_xattr_set(env, parent, &buf, XATTR_NAME_LMV".set", 0,
-                                 th);
+               rc = dt_xattr_set(env, parent, &buf, XATTR_NAME_LMV, 0, th);
                if (rc)
                        GOTO(stop, rc);
        }
@@ -1475,9 +1471,7 @@ static int lfsck_namespace_create_orphan_dir(const struct lu_env *env,
                        GOTO(log, rc = idx);
 
                snprintf(name, 8, "MDT%04x", idx);
-               rc = dt_lookup(env, lfsck->li_lpf_root_obj,
-                              (struct dt_rec *)&tfid,
-                              (const struct dt_key *)name);
+               rc = dt_lookup_dir(env, lfsck->li_lpf_root_obj, name, &tfid);
                if (rc != 0)
                        GOTO(log, rc = (rc == -ENOENT ? -ENXIO : rc));
 
@@ -1504,8 +1498,7 @@ again:
        do {
                namelen = snprintf(name, 31, DFID"-P-%d",
                                   PFID(cfid), idx++);
-               rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
-                              (const struct dt_key *)name);
+               rc = dt_lookup_dir(env, parent, name, &tfid);
                if (rc != 0 && rc != -ENOENT)
                        GOTO(log, rc);
        } while (rc == 0);
@@ -1517,8 +1510,7 @@ again:
 
        /* Re-check whether the name conflict with othrs after taken
         * the ldlm lock. */
-       rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
-                      (const struct dt_key *)name);
+       rc = dt_lookup_dir(env, parent, name, &tfid);
        if (unlikely(rc == 0)) {
                lfsck_unlock(llh);
                goto again;
@@ -1584,8 +1576,8 @@ again:
                lmv->lmv_master_mdt_index = lfsck_dev_idx(lfsck);
                lfsck_lmv_header_cpu_to_le(lmv2, lmv);
                lfsck_buf_init(&lmv_buf, lmv2, sizeof(*lmv2));
-               rc = dt_declare_xattr_set(env, orphan, &lmv_buf,
-                                         XATTR_NAME_LMV, 0, th);
+               rc = dt_declare_xattr_set(env, orphan, &lmv_buf, XATTR_NAME_LMV,
+                                         0, th);
                if (rc != 0)
                        GOTO(stop, rc);
        }
@@ -1990,8 +1982,7 @@ static int lfsck_namespace_replace_cond(const struct lu_env *env,
                goto replace;
        }
 
-       rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
-                      (const struct dt_key *)name);
+       rc = dt_lookup_dir(env, parent, name, &tfid);
        if (rc == -ENOENT) {
                exist = false;
                goto replace;
@@ -2277,8 +2268,7 @@ int lfsck_namespace_repair_dirent(const struct lu_env *env,
 
 
        dt_write_lock(env, parent, 0);
-       rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
-                      (const struct dt_key *)name);
+       rc = dt_lookup_dir(env, dt_object_child(parent), name, &tfid);
        /* Someone has removed the bad name entry by race. */
        if (rc == -ENOENT)
                GOTO(unlock2, rc = 0);
@@ -2676,8 +2666,7 @@ lost_parent:
                GOTO(out, rc);
        }
 
-       rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
-                      (const struct dt_key *)cname->ln_name);
+       rc = dt_lookup_dir(env, parent, cname->ln_name, &tfid);
        if (rc == -ENOENT) {
                /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT
                 * has ever tried to verify some remote MDT-object that resides
@@ -2917,8 +2906,7 @@ again:
                        continue;
                }
 
-               rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
-                              (const struct dt_key *)cname->ln_name);
+               rc = dt_lookup_dir(env, parent, cname->ln_name, &tfid);
                *pfid2 = *lfsck_dto2fid(parent);
                if (rc == -ENOENT) {
                        lfsck_object_put(env, parent);
@@ -3248,11 +3236,8 @@ static int lfsck_namespace_double_scan_dir(const struct lu_env *env,
 
        if (flags & (LNTF_CHECK_LINKEA | LNTF_CHECK_PARENT) &&
            !(lfsck->li_bookmark_ram.lb_param & LPF_ALL_TGT)) {
-               CDEBUG(D_LFSCK, "%s: some MDT(s) maybe NOT take part in the"
-                      "the namespace LFSCK, then the LFSCK cannot guarantee"
-                      "all the name entries have been verified in first-stage"
-                      "scanning. So have to skip orphan related handling for"
-                      "the directory object "DFID" with remote name entry\n",
+               CDEBUG(D_LFSCK,
+                      "%s: some MDT(s) maybe NOT take part in the the namespace LFSCK, then the LFSCK cannot guarantee all the name entries have been verified in first-stage scanning. So have to skip orphan related handling for the directory object "DFID" with remote name entry\n",
                       lfsck_lfsck2name(lfsck), PFID(cfid));
 
                RETURN(0);
@@ -3280,8 +3265,7 @@ lock:
                GOTO(out, rc = 0);
        }
 
-       rc = dt_lookup(env, child, (struct dt_rec *)pfid,
-                      (const struct dt_key *)dotdot);
+       rc = dt_lookup_dir(env, child, dotdot, pfid);
        if (rc != 0) {
                if (rc != -ENOENT && rc != -ENODATA && rc != -EINVAL) {
                        dt_read_unlock(env, child);
@@ -3871,8 +3855,7 @@ lost_parent:
                        continue;
                }
 
-               rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
-                              (const struct dt_key *)cname->ln_name);
+               rc = dt_lookup_dir(env, parent, cname->ln_name, cfid);
                if (rc != 0 && rc != -ENOENT) {
                        lfsck_object_put(env, parent);
 
@@ -4538,20 +4521,32 @@ static int lfsck_namespace_exec_oit(const struct lu_env *env,
                                    struct lfsck_component *com,
                                    struct dt_object *obj)
 {
-       struct lfsck_thread_info *info  = lfsck_env_info(env);
-       struct lfsck_namespace   *ns    = com->lc_file_ram;
-       struct lfsck_instance    *lfsck = com->lc_lfsck;
-       const struct lu_fid      *fid   = lfsck_dto2fid(obj);
-       struct lu_fid            *pfid  = &info->lti_fid2;
-       struct lu_name           *cname = &info->lti_name;
-       struct lu_seq_range      *range = &info->lti_range;
-       struct seq_server_site   *ss    = lfsck_dev_site(lfsck);
-       struct linkea_data        ldata = { NULL };
-       __u32                     idx   = lfsck_dev_idx(lfsck);
-       int                       rc;
+       struct lfsck_thread_info *info = lfsck_env_info(env);
+       struct lfsck_namespace *ns = com->lc_file_ram;
+       struct lfsck_instance *lfsck = com->lc_lfsck;
+       const struct lu_fid *fid = lfsck_dto2fid(obj);
+       struct lu_fid *pfid = &info->lti_fid2;
+       struct lu_name *cname = &info->lti_name;
+       struct lu_seq_range *range = &info->lti_range;
+       struct seq_server_site *ss = lfsck_dev_site(lfsck);
+       struct linkea_data ldata = { NULL };
+       __u32 idx = lfsck_dev_idx(lfsck);
+       struct lu_attr la = { .la_valid = 0 };
        bool remote = false;
+       int rc;
        ENTRY;
 
+       rc = dt_attr_get(env, obj, &la);
+       if (unlikely(rc || (la.la_valid & LA_FLAGS &&
+                           la.la_flags & LUSTRE_ORPHAN_FL))) {
+               CDEBUG(D_INFO,
+                      "%s: skip orphan "DFID", %llx/%x: rc = %d\n",
+                      lfsck_lfsck2name(lfsck), PFID(fid),
+                      la.la_valid, la.la_flags, rc);
+
+               return rc;
+       }
+
        rc = lfsck_links_read(env, obj, &ldata);
        if (rc == -ENOENT)
                GOTO(out, rc = 0);
@@ -4656,14 +4651,12 @@ static int lfsck_namespace_exec_dir(const struct lu_env *env,
        struct lfsck_bookmark           *bk      = &lfsck->li_bookmark_ram;
        struct ptlrpc_thread            *mthread = &lfsck->li_thread;
        struct ptlrpc_thread            *athread = &lad->lad_thread;
-       struct l_wait_info               lwi     = { 0 };
        bool                             wakeup  = false;
 
-       l_wait_event(mthread->t_ctl_waitq,
-                    lad->lad_prefetched < bk->lb_async_windows ||
-                    !thread_is_running(mthread) ||
-                    !thread_is_running(athread),
-                    &lwi);
+       wait_event_idle(mthread->t_ctl_waitq,
+                       lad->lad_prefetched < bk->lb_async_windows ||
+                       !thread_is_running(mthread) ||
+                       !thread_is_running(athread));
 
        if (unlikely(!thread_is_running(mthread) ||
                     !thread_is_running(athread)))
@@ -5221,7 +5214,7 @@ static int lfsck_namespace_query(const struct lu_env *env,
        return rc;
 }
 
-static struct lfsck_operations lfsck_namespace_ops = {
+static const struct lfsck_operations lfsck_namespace_ops = {
        .lfsck_reset            = lfsck_namespace_reset,
        .lfsck_fail             = lfsck_namespace_fail,
        .lfsck_close_dir        = lfsck_namespace_close_dir,
@@ -5364,6 +5357,8 @@ int lfsck_namespace_repair_dangling(const struct lu_env *env,
         */
        if (S_ISREG(type))
                child->do_ops->do_ah_init(env, hint,  parent, child, type);
+       else if (S_ISDIR(type))
+               child->do_ops->do_ah_init(env, hint,  NULL, child, type);
 
        memset(dof, 0, sizeof(*dof));
        dof->dof_type = dt_mode_to_dft(type);
@@ -5423,7 +5418,7 @@ int lfsck_namespace_repair_dangling(const struct lu_env *env,
                        lfsck_lmv_header_cpu_to_le(lmv2, lmv2);
                        lfsck_buf_init(&lmv_buf, lmv2, sizeof(*lmv2));
                        rc = dt_declare_xattr_set(env, child, &lmv_buf,
-                                                 XATTR_NAME_LMV".set", 0, th);
+                                                 XATTR_NAME_LMV, 0, th);
                        if (rc != 0)
                                GOTO(stop, rc);
                }
@@ -5485,8 +5480,8 @@ int lfsck_namespace_repair_dangling(const struct lu_env *env,
 
                /* 5b. generate slave LMV EA. */
                if (lnr->lnr_lmv != NULL && lnr->lnr_lmv->ll_lmv_master) {
-                       rc = dt_xattr_set(env, child, &lmv_buf,
-                                         XATTR_NAME_LMV".set", 0, th);
+                       rc = dt_xattr_set(env, child, &lmv_buf, XATTR_NAME_LMV,
+                                         0, th);
                        if (rc != 0)
                                GOTO(unlock, rc);
                }
@@ -5558,7 +5553,7 @@ static int lfsck_namespace_assistant_handler_p1(const struct lu_env *env,
        const struct lu_name       *cname;
        struct thandle             *handle   = NULL;
        struct lfsck_namespace_req *lnr      =
-                       container_of0(lar, struct lfsck_namespace_req, lnr_lar);
+               container_of(lar, struct lfsck_namespace_req, lnr_lar);
        struct dt_object           *dir      = NULL;
        struct dt_object           *obj      = NULL;
        struct lfsck_assistant_object *lso   = lar->lar_parent;
@@ -5592,11 +5587,9 @@ static int lfsck_namespace_assistant_handler_p1(const struct lu_env *env,
                repaired = true;
        }
 
-       if (unlikely(fid_is_zero(&lnr->lnr_fid))) {
-               if (strcmp(lnr->lnr_name, dotdot) != 0)
-                       LBUG();
-               else
-                       rc = lfsck_namespace_trace_update(env, com, pfid,
+       if (unlikely(fid_is_zero(&lnr->lnr_fid) &&
+                    strcmp(lnr->lnr_name, dotdot) == 0)) {
+               rc = lfsck_namespace_trace_update(env, com, pfid,
                                                LNTF_CHECK_PARENT, true);
 
                GOTO(out, rc);
@@ -6822,7 +6815,7 @@ out:
        EXIT;
 }
 
-struct lfsck_assistant_operations lfsck_namespace_assistant_ops = {
+const struct lfsck_assistant_operations lfsck_namespace_assistant_ops = {
        .la_handler_p1          = lfsck_namespace_assistant_handler_p1,
        .la_handler_p2          = lfsck_namespace_assistant_handler_p2,
        .la_fill_pos            = lfsck_namespace_assistant_fill_pos,