Whamcloud - gitweb
LU-1866 lfsck: LFSCK for namespace consistency (3)
[fs/lustre-release.git] / lustre / mdd / mdd_dir.c
index de42a5c..5fb1cf8 100644 (file)
@@ -60,9 +60,6 @@ static struct lu_name lname_dotdot = {
 static int __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
                         const struct lu_name *lname, struct lu_fid* fid,
                         int mask);
-static int mdd_declare_links_add(const struct lu_env *env,
-                                 struct mdd_object *mdd_obj,
-                                 struct thandle *handle);
 static inline int mdd_links_add(const struct lu_env *env,
                                struct mdd_object *mdd_obj,
                                const struct lu_fid *pfid,
@@ -110,8 +107,8 @@ int mdd_lookup(const struct lu_env *env,
         RETURN(rc);
 }
 
-static int mdd_parent_fid(const struct lu_env *env, struct mdd_object *obj,
-                          struct lu_fid *fid)
+int mdd_parent_fid(const struct lu_env *env, struct mdd_object *obj,
+                  struct lu_fid *fid)
 {
         return __mdd_lookup_locked(env, &obj->mod_obj, &lname_dotdot, fid, 0);
 }
@@ -169,7 +166,7 @@ static int mdd_is_parent(const struct lu_env *env,
                parent = mdd_object_find(env, mdd, pfid);
                if (IS_ERR(parent)) {
                        GOTO(out, rc = PTR_ERR(parent));
-               } else if (mdd_object_exists(parent) < 0) {
+               } else if (mdd_object_remote(parent)) {
                        /*FIXME: Because of the restriction of rename in Phase I.
                         * If the parent is remote, we just assumed lf is not the
                         * parent of P1 for now */
@@ -297,7 +294,7 @@ int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
         int rc = 0;
         ENTRY;
 
-        if (cobj && mdd_object_exists(cobj))
+       if (cobj && mdd_object_exists(cobj))
                 RETURN(-EEXIST);
 
         if (mdd_is_dead_obj(pobj))
@@ -788,14 +785,10 @@ int mdd_changelog_ext_store(const struct lu_env *env, struct mdd_device *mdd,
  * \param tname - target name string
  * \param handle - transacion handle
  */
-static int mdd_changelog_ns_store(const struct lu_env  *env,
-                                 struct mdd_device    *mdd,
-                                 enum changelog_rec_type type,
-                                 unsigned flags,
-                                 struct mdd_object    *target,
-                                 struct mdd_object    *parent,
-                                 const struct lu_name *tname,
-                                 struct thandle *handle)
+int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
+                          enum changelog_rec_type type, unsigned flags,
+                          struct mdd_object *target, struct mdd_object *parent,
+                          const struct lu_name *tname, struct thandle *handle)
 {
        struct llog_changelog_rec *rec;
        struct lu_buf *buf;
@@ -1416,14 +1409,12 @@ __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
         if (unlikely(mdd_is_dead_obj(mdd_obj)))
                 RETURN(-ESTALE);
 
-        rc = mdd_object_exists(mdd_obj);
-        if (unlikely(rc == 0))
-                RETURN(-ESTALE);
-        else if (unlikely(rc < 0)) {
-                CERROR("Object "DFID" locates on remote server\n",
-                        PFID(mdo2fid(mdd_obj)));
-                RETURN(-EINVAL);
-        }
+       if (mdd_object_remote(mdd_obj)) {
+               CDEBUG(D_INFO, "%s: Object "DFID" locates on remote server\n",
+                      mdd2obd_dev(m)->obd_name, PFID(mdo2fid(mdd_obj)));
+       } else if (!mdd_object_exists(mdd_obj)) {
+               RETURN(-ESTALE);
+       }
 
         /* The common filename length check. */
         if (unlikely(lname->ln_namelen > m->mdd_dt_conf.ddp_max_name_len))
@@ -1450,12 +1441,14 @@ __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
         RETURN(rc);
 }
 
-int mdd_declare_object_initialize(const struct lu_env *env,
-                                 struct mdd_object *child,
-                                 struct lu_attr *attr,
-                                 struct thandle *handle)
+static int mdd_declare_object_initialize(const struct lu_env *env,
+                                        struct mdd_object *parent,
+                                        struct mdd_object *child,
+                                        struct lu_attr *attr,
+                                        struct thandle *handle)
 {
         int rc;
+       ENTRY;
 
        /*
         * inode mode has been set in creation time, and it's based on umask,
@@ -1472,12 +1465,16 @@ int mdd_declare_object_initialize(const struct lu_env *env,
                                              dot, handle);
                 if (rc == 0)
                         rc = mdo_declare_ref_add(env, child, handle);
+
+               rc = mdo_declare_index_insert(env, child, mdo2fid(parent),
+                                             dotdot, handle);
         }
 
-        if (rc == 0)
+       if (rc == 0 && (fid_is_norm(mdo2fid(child)) ||
+                       fid_is_dot_lustre(mdo2fid(child))))
                 mdd_declare_links_add(env, child, handle);
 
-        return rc;
+       RETURN(rc);
 }
 
 int mdd_object_initialize(const struct lu_env *env, const struct lu_fid *pfid,
@@ -1522,10 +1519,12 @@ int mdd_object_initialize(const struct lu_env *env, const struct lu_fid *pfid,
                 if (rc != 0)
                         mdo_ref_del(env, child, handle);
         }
-        if (rc == 0)
-                mdd_links_add(env, child, pfid, lname, handle, 1);
 
-        RETURN(rc);
+       if (rc == 0 && (fid_is_norm(mdo2fid(child)) ||
+                       fid_is_dot_lustre(mdo2fid(child))))
+               mdd_links_add(env, child, pfid, lname, handle, 1);
+
+       RETURN(rc);
 }
 
 /* has not lock on pobj yet */
@@ -1652,7 +1651,7 @@ static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd,
                        GOTO(out, rc);
         }
 
-       rc = mdd_declare_object_initialize(env, c, attr, handle);
+       rc = mdd_declare_object_initialize(env, p, c, attr, handle);
        if (rc)
                GOTO(out, rc);
 
@@ -2450,30 +2449,12 @@ cleanup_unlocked:
 
 stop:
         mdd_trans_stop(env, mdd, rc, handle);
-        if (mdd_sobj)
-                mdd_object_put(env, mdd_sobj);
 out_pending:
-        return rc;
+       mdd_object_put(env, mdd_sobj);
+       return rc;
 }
 
-/**
- * The data that link search is done on.
- */
-struct mdd_link_data {
-       /**
-        * Buffer to keep link EA body.
-        */
-       struct lu_buf           *ml_buf;
-       /**
-        * The matched header, entry and its lenght in the EA
-        */
-       struct link_ea_header   *ml_leh;
-       struct link_ea_entry    *ml_lee;
-       int                      ml_reclen;
-};
-
-static int mdd_links_new(const struct lu_env *env,
-                        struct mdd_link_data *ldata)
+int mdd_links_new(const struct lu_env *env, struct mdd_link_data *ldata)
 {
        ldata->ml_buf = mdd_buf_alloc(env, CFS_PAGE_SIZE);
        if (ldata->ml_buf->lb_buf == NULL)
@@ -2491,8 +2472,7 @@ static int mdd_links_new(const struct lu_env *env,
  *
  * \retval 0 or error
  */
-int mdd_links_read(const struct lu_env *env,
-                  struct mdd_object *mdd_obj,
+int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
                   struct mdd_link_data *ldata)
 {
        struct lustre_capa *capa;
@@ -2558,10 +2538,8 @@ struct lu_buf *mdd_links_get(const struct lu_env *env,
        return rc ? ERR_PTR(rc) : ldata.ml_buf;
 }
 
-static int mdd_links_write(const struct lu_env *env,
-                          struct mdd_object *mdd_obj,
-                          struct mdd_link_data *ldata,
-                          struct thandle *handle)
+int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
+                   struct mdd_link_data *ldata, struct thandle *handle)
 {
        const struct lu_buf *buf = mdd_buf_get_const(env, ldata->ml_buf->lb_buf,
                                                     ldata->ml_leh->leh_len);
@@ -2581,6 +2559,8 @@ static int mdd_lee_pack(struct link_ea_entry *lee, const struct lu_name *lname,
         int             reclen;
 
         fid_cpu_to_be(&tmpfid, pfid);
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_CRASH))
+               tmpfid.f_ver = ~0;
         memcpy(&lee->lee_parent_fid, &tmpfid, sizeof(tmpfid));
         memcpy(lee->lee_name, lname->ln_name, lname->ln_namelen);
         reclen = sizeof(struct link_ea_entry) + lname->ln_namelen;
@@ -2600,9 +2580,9 @@ void mdd_lee_unpack(const struct link_ea_entry *lee, int *reclen,
         lname->ln_namelen = *reclen - sizeof(struct link_ea_entry);
 }
 
-static int mdd_declare_links_add(const struct lu_env *env,
-                                 struct mdd_object *mdd_obj,
-                                 struct thandle *handle)
+int mdd_declare_links_add(const struct lu_env *env,
+                         struct mdd_object *mdd_obj,
+                         struct thandle *handle)
 {
         int rc;
 
@@ -2614,27 +2594,15 @@ static int mdd_declare_links_add(const struct lu_env *env,
         return rc;
 }
 
-/* For pathologic linkers, we don't want to spend lots of time scanning the
- * link ea.  Limit ourseleves to something reasonable; links not in the EA
- * can be looked up via (slower) parent lookup.
- */
-#define LINKEA_MAX_COUNT 128
-
 /** Add a record to the end of link ea buf */
-static int mdd_links_add_buf(const struct lu_env *env,
-                            struct mdd_link_data *ldata,
-                            const struct lu_name *lname,
-                            const struct lu_fid *pfid)
+int mdd_links_add_buf(const struct lu_env *env, struct mdd_link_data *ldata,
+                     const struct lu_name *lname, const struct lu_fid *pfid)
 {
        LASSERT(ldata->ml_leh != NULL);
 
        if (lname == NULL || pfid == NULL)
                return -EINVAL;
 
-       /* Make sure our buf is big enough for the new one */
-       if (ldata->ml_leh->leh_reccount > LINKEA_MAX_COUNT)
-               return -EOVERFLOW;
-
        ldata->ml_reclen = lname->ln_namelen + sizeof(struct link_ea_entry);
        if (ldata->ml_leh->leh_len + ldata->ml_reclen >
            ldata->ml_buf->lb_len) {
@@ -2654,9 +2622,8 @@ static int mdd_links_add_buf(const struct lu_env *env,
 }
 
 /** Del the current record from the link ea buf */
-static void mdd_links_del_buf(const struct lu_env *env,
-                             struct mdd_link_data *ldata,
-                             const struct lu_name *lname)
+void mdd_links_del_buf(const struct lu_env *env, struct mdd_link_data *ldata,
+                      const struct lu_name *lname)
 {
        LASSERT(ldata->ml_leh != NULL);
 
@@ -2682,11 +2649,9 @@ static void mdd_links_del_buf(const struct lu_env *env,
  * \retval -ENOENT link does not exist
  * \retval -ve on error
  */
-static int mdd_links_find(const struct lu_env  *env,
-                         struct mdd_object    *mdd_obj,
-                         struct mdd_link_data *ldata,
-                         const struct lu_name *lname,
-                         const struct lu_fid  *pfid)
+int mdd_links_find(const struct lu_env *env, struct mdd_object *mdd_obj,
+                  struct mdd_link_data *ldata, const struct lu_name *lname,
+                  const struct lu_fid  *pfid)
 {
        struct lu_name *tmpname = &mdd_env_info(env)->mti_name2;
        struct lu_fid  *tmpfid = &mdd_env_info(env)->mti_fid;
@@ -2745,6 +2710,14 @@ static int __mdd_links_add(const struct lu_env *env,
                        return -EEXIST;
        }
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_MORE)) {
+               struct lu_fid *tfid = &mdd_env_info(env)->mti_fid2;
+
+               *tfid = *pfid;
+               tfid->f_ver = ~0;
+               mdd_links_add_buf(env, ldata, lname, tfid);
+       }
+
        return mdd_links_add_buf(env, ldata, lname, pfid);
 }
 
@@ -2785,6 +2758,9 @@ static int mdd_links_rename(const struct lu_env *env,
        int rc = 0;
        ENTRY;
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF))
+               return 0;
+
        LASSERT(oldpfid != NULL || newpfid != NULL);
 
        if (mdd_obj->mod_flags & DEAD_OBJ)