Whamcloud - gitweb
LU-5396 lod: (and mdt, mgs) make some symbols static
[fs/lustre-release.git] / lustre / lod / lod_object.c
index 5e535f0..450e7f7 100644 (file)
@@ -6,13 +6,13 @@
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 only,
  * as published by the Free Software Foundation.
-
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License version 2 for more details.  A copy is
  * included in the COPYING file that accompanied this code.
-
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -23,7 +23,7 @@
  * Copyright  2009 Sun Microsystems, Inc. All rights reserved
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * lustre/lod/lod_object.c
@@ -58,7 +58,6 @@
 static const char dot[] = ".";
 static const char dotdot[] = "..";
 
-extern struct kmem_cache *lod_object_kmem;
 static const struct dt_body_operations lod_body_lnk_ops;
 
 /**
@@ -188,7 +187,7 @@ do {                                                                \
  *
  * \see dt_index_operations::dio_it.fini() in the API description for details.
  */
-void lod_it_fini(const struct lu_env *env, struct dt_it *di)
+static void lod_it_fini(const struct lu_env *env, struct dt_it *di)
 {
        struct lod_it *it = (struct lod_it *)di;
 
@@ -207,8 +206,8 @@ void lod_it_fini(const struct lu_env *env, struct dt_it *di)
  *
  * \see dt_it_ops::get() in the API description for details.
  */
-int lod_it_get(const struct lu_env *env, struct dt_it *di,
-              const struct dt_key *key)
+static int lod_it_get(const struct lu_env *env, struct dt_it *di,
+                     const struct dt_key *key)
 {
        const struct lod_it *it = (const struct lod_it *)di;
 
@@ -223,7 +222,7 @@ int lod_it_get(const struct lu_env *env, struct dt_it *di,
  *
  * \see dt_it_ops::put() in the API description for details.
  */
-void lod_it_put(const struct lu_env *env, struct dt_it *di)
+static void lod_it_put(const struct lu_env *env, struct dt_it *di)
 {
        struct lod_it *it = (struct lod_it *)di;
 
@@ -238,7 +237,7 @@ void lod_it_put(const struct lu_env *env, struct dt_it *di)
  *
  * \see dt_it_ops::next() in the API description for details.
  */
-int lod_it_next(const struct lu_env *env, struct dt_it *di)
+static int lod_it_next(const struct lu_env *env, struct dt_it *di)
 {
        struct lod_it *it = (struct lod_it *)di;
 
@@ -253,7 +252,8 @@ int lod_it_next(const struct lu_env *env, struct dt_it *di)
  *
  * \see dt_it_ops::key() in the API description for details.
  */
-struct dt_key *lod_it_key(const struct lu_env *env, const struct dt_it *di)
+static struct dt_key *lod_it_key(const struct lu_env *env,
+                                const struct dt_it *di)
 {
        const struct lod_it *it = (const struct lod_it *)di;
 
@@ -268,7 +268,7 @@ struct dt_key *lod_it_key(const struct lu_env *env, const struct dt_it *di)
  *
  * \see dt_it_ops::key_size() in the API description for details.
  */
-int lod_it_key_size(const struct lu_env *env, const struct dt_it *di)
+static int lod_it_key_size(const struct lu_env *env, const struct dt_it *di)
 {
        struct lod_it *it = (struct lod_it *)di;
 
@@ -283,8 +283,8 @@ int lod_it_key_size(const struct lu_env *env, const struct dt_it *di)
  *
  * \see dt_it_ops::rec() in the API description for details.
  */
-int lod_it_rec(const struct lu_env *env, const struct dt_it *di,
-              struct dt_rec *rec, __u32 attr)
+static int lod_it_rec(const struct lu_env *env, const struct dt_it *di,
+                     struct dt_rec *rec, __u32 attr)
 {
        const struct lod_it *it = (const struct lod_it *)di;
 
@@ -300,8 +300,8 @@ int lod_it_rec(const struct lu_env *env, const struct dt_it *di,
  *
  * \see dt_it_ops::rec_size() in the API description for details.
  */
-int lod_it_rec_size(const struct lu_env *env, const struct dt_it *di,
-                   __u32 attr)
+static int lod_it_rec_size(const struct lu_env *env, const struct dt_it *di,
+                          __u32 attr)
 {
        const struct lod_it *it = (const struct lod_it *)di;
 
@@ -317,7 +317,7 @@ int lod_it_rec_size(const struct lu_env *env, const struct dt_it *di,
  *
  * \see dt_it_ops::store() in the API description for details.
  */
-__u64 lod_it_store(const struct lu_env *env, const struct dt_it *di)
+static __u64 lod_it_store(const struct lu_env *env, const struct dt_it *di)
 {
        const struct lod_it *it = (const struct lod_it *)di;
 
@@ -332,7 +332,8 @@ __u64 lod_it_store(const struct lu_env *env, const struct dt_it *di)
  *
  * \see dt_it_ops::load() in the API description for details.
  */
-int lod_it_load(const struct lu_env *env, const struct dt_it *di, __u64 hash)
+static int lod_it_load(const struct lu_env *env, const struct dt_it *di,
+                      __u64 hash)
 {
        const struct lod_it *it = (const struct lod_it *)di;
 
@@ -347,8 +348,8 @@ int lod_it_load(const struct lu_env *env, const struct dt_it *di, __u64 hash)
  *
  * \see dt_it_ops::rec() in the API description for details.
  */
-int lod_it_key_rec(const struct lu_env *env, const struct dt_it *di,
-                  void *key_rec)
+static int lod_it_key_rec(const struct lu_env *env, const struct dt_it *di,
+                         void *key_rec)
 {
        const struct lod_it *it = (const struct lod_it *)di;
 
@@ -1490,8 +1491,8 @@ static void lod_prep_slave_lmv_md(struct lmv_mds_md_v1 *slave_lmv,
  * \retval             0 on success
  * \retval             negative if failed
  */
-int lod_prep_lmv_md(const struct lu_env *env, struct dt_object *dt,
-                   struct lu_buf *lmv_buf)
+static int lod_prep_lmv_md(const struct lu_env *env, struct dt_object *dt,
+                          struct lu_buf *lmv_buf)
 {
        struct lod_thread_info  *info = lod_env_info(env);
        struct lod_device       *lod = lu2lod_dev(dt->do_lu.lo_dev);
@@ -1837,7 +1838,8 @@ next:
                if (lo->ldo_striping_cached &&
                    !LOVEA_DELETE_VALUES(lo->ldo_def_stripe_size,
                                         lo->ldo_def_stripenr,
-                                        lo->ldo_def_stripe_offset)) {
+                                        lo->ldo_def_stripe_offset,
+                                        lo->ldo_pool)) {
                        struct lov_user_md_v3   *v3;
 
                        /* sigh, lti_ea_store has been used for lmv_buf,
@@ -1870,14 +1872,28 @@ next:
                                GOTO(out_put, rc);
                }
 
-               slave_lmm->lmv_master_mdt_index = cpu_to_le32(i);
-               rc = dt_declare_xattr_set(env, dto, &slave_lmv_buf,
-                                         XATTR_NAME_LMV, 0, th);
-               if (rc != 0)
-                       GOTO(out_put, rc);
+               if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_SLAVE_LMV) ||
+                   cfs_fail_val != i) {
+                       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_SLAVE_LMV) &&
+                           cfs_fail_val == i)
+                               slave_lmm->lmv_master_mdt_index =
+                                                       cpu_to_le32(i + 1);
+                       else
+                               slave_lmm->lmv_master_mdt_index =
+                                                       cpu_to_le32(i);
+                       rc = dt_declare_xattr_set(env, dto, &slave_lmv_buf,
+                                                 XATTR_NAME_LMV, 0, th);
+                       if (rc != 0)
+                               GOTO(out_put, rc);
+               }
 
-               snprintf(stripe_name, sizeof(info->lti_key), DFID":%u",
-                       PFID(lu_object_fid(&dto->do_lu)), i);
+               if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_SLAVE_NAME) &&
+                   cfs_fail_val == i)
+                       snprintf(stripe_name, sizeof(info->lti_key), DFID":%u",
+                               PFID(lu_object_fid(&dto->do_lu)), i + 1);
+               else
+                       snprintf(stripe_name, sizeof(info->lti_key), DFID":%u",
+                               PFID(lu_object_fid(&dto->do_lu)), i);
 
                sname = lod_name_get(env, stripe_name, strlen(stripe_name));
                rc = linkea_data_new(&ldata, &info->lti_linkea_buf);
@@ -2243,6 +2259,7 @@ static int lod_xattr_set_lov_on_dir(const struct lu_env *env,
        struct lod_object       *l = lod_dt_obj(dt);
        struct lov_user_md_v1   *lum;
        struct lov_user_md_v3   *v3 = NULL;
+       const char              *pool_name = NULL;
        int                      rc;
        ENTRY;
 
@@ -2258,8 +2275,11 @@ static int lod_xattr_set_lov_on_dir(const struct lu_env *env,
        if (rc)
                RETURN(rc);
 
-       if (lum->lmm_magic == LOV_USER_MAGIC_V3)
+       if (lum->lmm_magic == LOV_USER_MAGIC_V3) {
                v3 = buf->lb_buf;
+               if (v3->lmm_pool_name[0] != '\0')
+                       pool_name = v3->lmm_pool_name;
+       }
 
        /* if { size, offset, count } = { 0, -1, 0 } and no pool
         * (i.e. all default values specified) then delete default
@@ -2271,10 +2291,8 @@ static int lod_xattr_set_lov_on_dir(const struct lu_env *env,
                (int)lum->lmm_stripe_offset,
                v3 ? "from" : "", v3 ? v3->lmm_pool_name : "");
 
-       if (LOVEA_DELETE_VALUES((lum->lmm_stripe_size),
-                               (lum->lmm_stripe_count),
-                               (lum->lmm_stripe_offset)) &&
-                       lum->lmm_magic == LOV_USER_MAGIC_V1) {
+       if (LOVEA_DELETE_VALUES(lum->lmm_stripe_size, lum->lmm_stripe_count,
+                               lum->lmm_stripe_offset, pool_name)) {
                rc = lod_xattr_del_internal(env, dt, name, th, capa);
                if (rc == -ENODATA)
                        rc = 0;
@@ -2445,7 +2463,8 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
                if (lo->ldo_striping_cached &&
                    !LOVEA_DELETE_VALUES(lo->ldo_def_stripe_size,
                                         lo->ldo_def_stripenr,
-                                        lo->ldo_def_stripe_offset)) {
+                                        lo->ldo_def_stripe_offset,
+                                        lo->ldo_pool)) {
                        struct lov_user_md_v3   *v3;
 
                        /* sigh, lti_ea_store has been used for lmv_buf,
@@ -2476,14 +2495,28 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
                                GOTO(out, rc);
                }
 
-               slave_lmm->lmv_master_mdt_index = cpu_to_le32(i);
-               rc = dt_xattr_set(env, dto, &slave_lmv_buf, XATTR_NAME_LMV,
-                                 fl, th, capa);
-               if (rc != 0)
-                       GOTO(out, rc);
+               if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_SLAVE_LMV) ||
+                   cfs_fail_val != i) {
+                       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_SLAVE_LMV) &&
+                           cfs_fail_val == i)
+                               slave_lmm->lmv_master_mdt_index =
+                                                       cpu_to_le32(i + 1);
+                       else
+                               slave_lmm->lmv_master_mdt_index =
+                                                       cpu_to_le32(i);
+                       rc = dt_xattr_set(env, dto, &slave_lmv_buf,
+                                         XATTR_NAME_LMV, fl, th, capa);
+                       if (rc != 0)
+                               GOTO(out, rc);
+               }
 
-               snprintf(stripe_name, sizeof(info->lti_key), DFID":%d",
-                        PFID(lu_object_fid(&dto->do_lu)), i);
+               if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_SLAVE_NAME) &&
+                   cfs_fail_val == i)
+                       snprintf(stripe_name, sizeof(info->lti_key), DFID":%d",
+                                PFID(lu_object_fid(&dto->do_lu)), i + 1);
+               else
+                       snprintf(stripe_name, sizeof(info->lti_key), DFID":%d",
+                                PFID(lu_object_fid(&dto->do_lu)), i);
 
                sname = lod_name_get(env, stripe_name, strlen(stripe_name));
                rc = linkea_data_new(&ldata, &info->lti_linkea_buf);
@@ -2546,12 +2579,12 @@ out:
  * \retval             0 on success
  * \retval             negative if failed
  */
-int lod_dir_striping_create_internal(const struct lu_env *env,
-                                    struct dt_object *dt,
-                                    struct lu_attr *attr,
-                                    struct dt_object_format *dof,
-                                    struct thandle *th,
-                                    bool declare)
+static int lod_dir_striping_create_internal(const struct lu_env *env,
+                                           struct dt_object *dt,
+                                           struct lu_attr *attr,
+                                           struct dt_object_format *dof,
+                                           struct thandle *th,
+                                           bool declare)
 {
        struct lod_thread_info  *info = lod_env_info(env);
        struct lod_object       *lo = lod_dt_obj(dt);
@@ -2631,7 +2664,8 @@ int lod_dir_striping_create_internal(const struct lu_env *env,
        if (lo->ldo_striping_cached &&
            !LOVEA_DELETE_VALUES(lo->ldo_def_stripe_size,
                                 lo->ldo_def_stripenr,
-                                lo->ldo_def_stripe_offset)) {
+                                lo->ldo_def_stripe_offset,
+                                lo->ldo_pool)) {
                struct lov_user_md_v3 *v3 = info->lti_ea_store;
 
                if (info->lti_ea_store_size < sizeof(*v3)) {
@@ -2796,7 +2830,7 @@ static int lod_xattr_del(const struct lu_env *env, struct dt_object *dt,
  * for details.
  */
 static int lod_xattr_list(const struct lu_env *env,
-                         struct dt_object *dt, struct lu_buf *buf,
+                         struct dt_object *dt, const struct lu_buf *buf,
                          struct lustre_capa *capa)
 {
        return dt_xattr_list(env, dt_object_child(dt), buf, capa);
@@ -3057,9 +3091,12 @@ static void lod_ah_init(const struct lu_env *env,
         * in case of late striping creation, ->ah_init()
         * can be called with local object existing
         */
-       if (!dt_object_exists(nextc) || dt_object_remote(nextc))
-               nextc->do_ops->do_ah_init(env, ah, dt_object_remote(nextp) ?
-                                         NULL : nextp, nextc, child_mode);
+       if (!dt_object_exists(nextc) || dt_object_remote(nextc)) {
+               struct dt_object *obj;
+
+               obj = (nextp != NULL && dt_object_remote(nextp)) ? NULL : nextp;
+               nextc->do_ops->do_ah_init(env, ah, obj, nextc, child_mode);
+       }
 
        if (S_ISDIR(child_mode)) {
                if (lc->ldo_dir_stripe == NULL) {
@@ -3164,7 +3201,7 @@ static void lod_ah_init(const struct lu_env *env,
        if (likely(parent)) {
                lod_cache_parent_striping(env, lp, child_mode);
 
-               lc->ldo_def_stripe_offset = (__u16) -1;
+               lc->ldo_def_stripe_offset = LOV_OFFSET_DEFAULT;
 
                if (lp->ldo_def_striping_set) {
                        if (lp->ldo_pool)
@@ -3953,8 +3990,16 @@ static int lod_object_init(const struct lu_env *env, struct lu_object *lo,
        ENTRY;
 
        rc = lod_fld_lookup(env, lod, lu_object_fid(lo), &idx, &type);
-       if (rc != 0)
+       if (rc != 0) {
+               /* Note: Sometimes, it will Return EAGAIN here, see
+                * ptrlpc_import_delay_req(), which might confuse
+                * lu_object_find_at() and make it wait there incorrectly.
+                * so we convert it to EIO here.*/
+               if (rc == -EAGAIN)
+                       rc = -EIO;
+
                RETURN(rc);
+       }
 
        if (type == LU_SEQ_RANGE_MDT &&
            idx == lu_site2seq(lo->lo_dev->ld_site)->ss_node_id) {