Whamcloud - gitweb
LU-1866 lfsck: ancillary work for namespace LFSCK
authorFan Yong <yong.fan@whamcloud.com>
Tue, 15 Jan 2013 07:05:35 +0000 (15:05 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 6 Feb 2013 05:12:15 +0000 (00:12 -0500)
1) Share related linkEA functions with LFSCK.

2) Multiple linked objects are rare, and the objects with
   a lot of linkea entries are more rare. It is unnecessary
   to worry about performance under such cases. So drop the
   linkea entries count limitation: LINKEA_MAX_COUNT.

Signed-off-by: Fan Yong <fan.yong@intel.com>
Change-Id: I75f90c9619c56f2f62063435aea26ed01337d6dd
Reviewed-on: http://review.whamcloud.com/4907
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
lustre/mdd/mdd_device.c
lustre/mdd/mdd_dir.c
lustre/mdd/mdd_internal.h
lustre/mdd/mdd_object.c
lustre/mdd/mdd_orphans.c

index 2a76656..8a2aef8 100644 (file)
@@ -291,15 +291,10 @@ static int mdd_changelog_llog_init(const struct lu_env *env,
 {
        struct obd_device       *obd = mdd2obd_dev(mdd);
        struct llog_ctxt        *ctxt = NULL, *uctxt = NULL;
-       struct lu_fid            rfid;
        int                      rc;
 
        OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
        obd->obd_lvfs_ctxt.dt = mdd->mdd_bottom;
-       rc = dt_root_get(env, mdd->mdd_bottom, &rfid);
-       if (rc)
-               RETURN(-ENODEV);
-
        rc = llog_setup(env, obd, &obd->obd_olg, LLOG_CHANGELOG_ORIG_CTXT,
                        obd, &changelog_orig_logops);
        if (rc) {
@@ -877,7 +872,6 @@ static int obf_xattr_get(const struct lu_env *env,
 {
        struct mdd_device *mdd = mdo2mdd(obj);
        struct mdd_object *root;
-       struct lu_fid      rootfid;
        int rc = 0;
 
        /*
@@ -885,10 +879,7 @@ static int obf_xattr_get(const struct lu_env *env,
         * in the root
         */
        if (strcmp(name, XATTR_NAME_LOV) == 0) {
-               rc = dt_root_get(env, mdd->mdd_child, &rootfid);
-               if (rc)
-                       return rc;
-               root = mdd_object_find(env, mdd, &rootfid);
+               root = mdd_object_find(env, mdd, &mdd->mdd_local_root_fid);
                if (IS_ERR(root))
                        return PTR_ERR(root);
                rc = mdo_xattr_get(env, root, buf, name,
@@ -1185,6 +1176,10 @@ static int mdd_prepare(const struct lu_env *env,
         if (rc)
                 GOTO(out, rc);
 
+       rc = dt_root_get(env, mdd->mdd_child, &mdd->mdd_local_root_fid);
+       if (rc != 0)
+               GOTO(out, rc);
+
         root = dt_store_open(env, mdd->mdd_child, "", mdd_root_dir_name,
                              &mdd->mdd_root_fid);
         if (!IS_ERR(root)) {
@@ -1634,13 +1629,8 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m,
                 RETURN(0);
         }
        case OBD_IOC_START_LFSCK: {
-               struct lfsck_start *start = karg;
-               struct md_lfsck *lfsck = &mdd->mdd_lfsck;
-
-               /* Return the kernel service version. */
-               /* XXX: version can be used for compatibility in the future. */
-               start->ls_version = lfsck->ml_version;
-               rc = mdd_lfsck_start(env, lfsck, start);
+               rc = mdd_lfsck_start(env, &mdd->mdd_lfsck,
+                                    (struct lfsck_start *)karg);
                RETURN(rc);
        }
        case OBD_IOC_STOP_LFSCK: {
index ab7f9be..0fa00ba 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);
 }
@@ -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;
@@ -1477,7 +1470,8 @@ static int mdd_declare_object_initialize(const struct lu_env *env,
                                              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);
@@ -1525,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 */
@@ -2453,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)
@@ -2494,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;
@@ -2561,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);
@@ -2603,9 +2578,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;
 
@@ -2617,27 +2592,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) {
@@ -2657,9 +2620,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);
 
@@ -2685,11 +2647,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;
index cb512de..d4ab715 100644 (file)
@@ -121,6 +121,7 @@ struct mdd_device {
         struct dt_device                *mdd_child;
        struct dt_device                *mdd_bottom;
         struct lu_fid                    mdd_root_fid;
+       struct lu_fid                    mdd_local_root_fid;
         struct dt_device_param           mdd_dt_conf;
         struct dt_object                *mdd_orphans; /* PENDING directory */
         struct dt_object                *mdd_capa;
@@ -167,10 +168,10 @@ struct mdd_thread_info {
        struct lu_attr            mti_cattr;
         struct md_attr            mti_ma;
         struct obd_info           mti_oi;
-       /* mti_orph_ent and mti_orph_key must be conjoint,
-        * then mti_orph_ent::lde_name will be mti_orph_key. */
-       struct lu_dirent          mti_orph_ent;
-        char                      mti_orph_key[NAME_MAX + 1];
+       /* mti_ent and mti_key must be conjoint,
+        * then mti_ent::lde_name will be mti_key. */
+       struct lu_dirent          mti_ent;
+       char                      mti_key[NAME_MAX + 16];
         struct obd_trans_info     mti_oti;
         struct lu_buf             mti_buf;
         struct lu_buf             mti_big_buf; /* biggish persistent buf */
@@ -187,6 +188,22 @@ struct mdd_thread_info {
         struct obd_quotactl       mti_oqctl;
 };
 
+/**
+ * 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;
+};
+
 extern const char orph_index_name[];
 
 extern const struct dt_index_features orph_index_features;
@@ -289,6 +306,8 @@ void mdd_pdo_write_unlock(const struct lu_env *env, struct mdd_object *obj,
 void mdd_pdo_read_unlock(const struct lu_env *env, struct mdd_object *obj,
                          void *dlh);
 /* mdd_dir.c */
+int mdd_parent_fid(const struct lu_env *env, struct mdd_object *obj,
+                  struct lu_fid *fid);
 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
                   const struct lu_fid *fid, struct lu_fid *sfid);
 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
@@ -312,6 +331,21 @@ int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
 int mdd_lookup(const struct lu_env *env,
                struct md_object *pobj, const struct lu_name *lname,
                struct lu_fid* fid, struct md_op_spec *spec);
+int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
+                  struct mdd_link_data *ldata);
+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_new(const struct lu_env *env, struct mdd_link_data *ldata);
+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);
+void mdd_links_del_buf(const struct lu_env *env, struct mdd_link_data *ldata,
+                      const struct lu_name *lname);
+int mdd_declare_links_add(const struct lu_env *env,
+                         struct mdd_object *mdd_obj,
+                         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);
 struct lu_buf *mdd_links_get(const struct lu_env *env,
                              struct mdd_object *mdd_obj);
 void mdd_lee_unpack(const struct link_ea_entry *lee, int *reclen,
@@ -341,6 +375,8 @@ int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd,
 
 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
 
+const struct lu_name *mdd_name_get_const(const struct lu_env *env,
+                                        const void *area, ssize_t len);
 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
                                        const void *area, ssize_t len);
@@ -389,6 +425,10 @@ int mdd_declare_changelog_store(const struct lu_env *env,
                                struct thandle *handle);
 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
                        struct llog_changelog_rec *rec, struct thandle *th);
+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_declare_object_create_internal(const struct lu_env *env,
                                       struct mdd_object *p,
                                       struct mdd_object *c,
@@ -403,6 +443,11 @@ int mdd_lov_destroy(const struct lu_env *env, struct mdd_device *mdd,
 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
                          struct mdd_object *child, struct lu_attr *attr);
 
+static inline void mdd_object_get(struct mdd_object *o)
+{
+       lu_object_get(&o->mod_obj.mo_lu);
+}
+
 static inline void mdd_object_put(const struct lu_env *env,
                                   struct mdd_object *o)
 {
@@ -838,12 +883,14 @@ int mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
         *  LU-974 enforce client umask in creation.
         * TODO: CMD needs to handle this for remote object.
         */
-       saved = xchg(&current->fs->umask, uc->uc_umask & S_IRWXUGO);
+       if (likely(uc != NULL))
+               saved = xchg(&current->fs->umask, uc->uc_umask & S_IRWXUGO);
 
        rc = next->do_ops->do_create(env, next, attr, hint, dof, handle);
 
        /* restore previous umask value */
-       current->fs->umask = saved;
+       if (likely(uc != NULL))
+               current->fs->umask = saved;
 
        return rc;
 }
index 6248eec..5dbb9ef 100644 (file)
@@ -107,6 +107,17 @@ struct mdd_thread_info *mdd_env_info(const struct lu_env *env)
         return info;
 }
 
+const struct lu_name *mdd_name_get_const(const struct lu_env *env,
+                                        const void *area, ssize_t len)
+{
+       struct lu_name *lname;
+
+       lname = &mdd_env_info(env)->mti_name;
+       lname->ln_name = area;
+       lname->ln_namelen = len;
+       return lname;
+}
+
 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len)
 {
         struct lu_buf *buf;
index 6a741a3..e364903 100644 (file)
@@ -64,7 +64,7 @@ enum {
 static struct dt_key* orph_key_fill(const struct lu_env *env,
                                     const struct lu_fid *lf, __u32 op)
 {
-        char *key = mdd_env_info(env)->mti_orph_key;
+       char *key = mdd_env_info(env)->mti_key;
         int rc;
 
         LASSERT(key);
@@ -80,7 +80,7 @@ static struct dt_key* orph_key_fill(const struct lu_env *env,
 static struct dt_key* orph_key_fill_18(const struct lu_env *env,
                                        const struct lu_fid *lf)
 {
-        char *key = mdd_env_info(env)->mti_orph_key;
+       char *key = mdd_env_info(env)->mti_key;
         int rc;
 
         LASSERT(key);
@@ -427,7 +427,7 @@ static int orph_index_iterate(const struct lu_env *env,
                              struct mdd_device *mdd)
 {
        struct dt_object *dor = mdd->mdd_orphans;
-       struct lu_dirent *ent = &mdd_env_info(env)->mti_orph_ent;
+       struct lu_dirent *ent = &mdd_env_info(env)->mti_ent;
        const struct dt_it_ops *iops;
        struct dt_it     *it;
        struct lu_fid     fid;