Whamcloud - gitweb
LU-1538 tests: unmount /sbin/mount.lustre bind mount
[fs/lustre-release.git] / lustre / lod / lod_object.c
index e4583d8..acdd4d0 100644 (file)
@@ -43,7 +43,6 @@
 #include <lustre_param.h>
 #include <lustre_fid.h>
 #include <lustre_lmv.h>
-#include <obd_lov.h>
 #include <md_object.h>
 
 #include "lod_internal.h"
@@ -364,6 +363,18 @@ static int lod_declare_attr_set(const struct lu_env *env,
            dt_object_remote(next) == 0)
                dt_declare_xattr_del(env, next, XATTR_NAME_LOV, handle);
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_CHANGE_STRIPE) &&
+           dt_object_exists(next) &&
+           dt_object_remote(next) == 0 && S_ISREG(attr->la_mode)) {
+               struct lod_thread_info *info = lod_env_info(env);
+               struct lu_buf *buf = &info->lti_buf;
+
+               buf->lb_buf = info->lti_ea_store;
+               buf->lb_len = info->lti_ea_store_size;
+               dt_declare_xattr_set(env, next, buf, XATTR_NAME_LOV,
+                                    LU_XATTR_REPLACE, handle);
+       }
+
        RETURN(rc);
 }
 
@@ -441,6 +452,39 @@ static int lod_attr_set(const struct lu_env *env,
            dt_object_remote(next) == 0)
                dt_xattr_del(env, next, XATTR_NAME_LOV, handle, BYPASS_CAPA);
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_CHANGE_STRIPE) &&
+           dt_object_exists(next) &&
+           dt_object_remote(next) == 0 && S_ISREG(attr->la_mode)) {
+               struct lod_thread_info *info = lod_env_info(env);
+               struct lu_buf *buf = &info->lti_buf;
+               struct ost_id *oi = &info->lti_ostid;
+               struct lu_fid *fid = &info->lti_fid;
+               struct lov_mds_md_v1 *lmm;
+               struct lov_ost_data_v1 *objs;
+               __u32 magic;
+               int rc1;
+
+               rc1 = lod_get_lov_ea(env, lo);
+               if (rc1  <= 0)
+                       RETURN(rc);
+
+               buf->lb_buf = info->lti_ea_store;
+               buf->lb_len = info->lti_ea_store_size;
+               lmm = info->lti_ea_store;
+               magic = le32_to_cpu(lmm->lmm_magic);
+               if (magic == LOV_MAGIC_V1)
+                       objs = &(lmm->lmm_objects[0]);
+               else
+                       objs = &((struct lov_mds_md_v3 *)lmm)->lmm_objects[0];
+               ostid_le_to_cpu(&objs->l_ost_oi, oi);
+               ostid_to_fid(fid, oi, le32_to_cpu(objs->l_ost_idx));
+               fid->f_oid--;
+               fid_to_ostid(fid, oi);
+               ostid_cpu_to_le(oi, &objs->l_ost_oi);
+               dt_xattr_set(env, next, buf, XATTR_NAME_LOV,
+                            LU_XATTR_REPLACE, handle, BYPASS_CAPA);
+       }
+
        RETURN(rc);
 }
 
@@ -584,6 +628,9 @@ int lod_parse_dir_striping(const struct lu_env *env, struct lod_object *lo,
        int                     rc = 0;
        ENTRY;
 
+       if (le32_to_cpu(lmv1->lmv_magic) == LMV_MAGIC_MIGRATE)
+               RETURN(0);
+
        if (le32_to_cpu(lmv1->lmv_magic) != LMV_MAGIC_V1)
                RETURN(-EINVAL);
 
@@ -790,9 +837,9 @@ static int lod_prep_md_striped_create(const struct lu_env *env,
                        memset(v3, 0, sizeof(*v3));
                        v3->lmm_magic = cpu_to_le32(LOV_USER_MAGIC_V3);
                        v3->lmm_stripe_count =
-                               cpu_to_le32(lo->ldo_def_stripenr);
+                               cpu_to_le16(lo->ldo_def_stripenr);
                        v3->lmm_stripe_offset =
-                               cpu_to_le32(lo->ldo_def_stripe_offset);
+                               cpu_to_le16(lo->ldo_def_stripe_offset);
                        v3->lmm_stripe_size =
                                cpu_to_le32(lo->ldo_def_stripe_size);
                        if (lo->ldo_pool)
@@ -816,7 +863,8 @@ static int lod_prep_md_striped_create(const struct lu_env *env,
                        GOTO(out_put, rc);
        }
 
-       rc = dt_declare_xattr_set(env, dt, &lmv_buf, XATTR_NAME_LMV, 0, th);
+       rc = dt_declare_xattr_set(env, dt_object_child(dt), &lmv_buf,
+                                 XATTR_NAME_LMV, 0, th);
        if (rc != 0)
                GOTO(out_put, rc);
 
@@ -1135,9 +1183,9 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
                        memset(v3, 0, sizeof(*v3));
                        v3->lmm_magic = cpu_to_le32(LOV_USER_MAGIC_V3);
                        v3->lmm_stripe_count =
-                               cpu_to_le32(lo->ldo_def_stripenr);
+                               cpu_to_le16(lo->ldo_def_stripenr);
                        v3->lmm_stripe_offset =
-                               cpu_to_le32(lo->ldo_def_stripe_offset);
+                               cpu_to_le16(lo->ldo_def_stripe_offset);
                        v3->lmm_stripe_size =
                                cpu_to_le32(lo->ldo_def_stripe_size);
                        if (lo->ldo_pool)
@@ -1158,7 +1206,8 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
                                  capa);
        }
 
-       rc = dt_xattr_set(env, dt, &lmv_buf, XATTR_NAME_LMV, fl, th, capa);
+       rc = dt_xattr_set(env, dt_object_child(dt), &lmv_buf, XATTR_NAME_LMV,
+                         fl, th, capa);
 
        RETURN(rc);
 }
@@ -1307,6 +1356,11 @@ static int lod_cache_parent_lov_striping(const struct lu_env *env,
        if (v1->lmm_pattern != LOV_PATTERN_RAID0 && v1->lmm_pattern != 0)
                GOTO(unlock, rc = 0);
 
+       CDEBUG(D_INFO, DFID" stripe_count=%d stripe_size=%d stripe_offset=%d\n",
+              PFID(lu_object_fid(&lp->ldo_obj.do_lu)),
+              (int)v1->lmm_stripe_count,
+              (int)v1->lmm_stripe_size, (int)v1->lmm_stripe_offset);
+
        lp->ldo_def_stripenr = v1->lmm_stripe_count;
        lp->ldo_def_stripe_size = v1->lmm_stripe_size;
        lp->ldo_def_stripe_offset = v1->lmm_stripe_offset;
@@ -1636,22 +1690,33 @@ int lod_declare_striped_object(const struct lu_env *env, struct dt_object *dt,
                GOTO(out, rc = -ENOMEM);
        }
 
-       /* choose OST and generate appropriate objects */
-       rc = lod_qos_prep_create(env, lo, attr, lovea, th);
-       if (rc) {
-               /* failed to create striping, let's reset
-                * config so that others don't get confused */
-               lod_object_free_striping(env, lo);
-               GOTO(out, rc);
-       }
+       if (!dt_object_remote(next)) {
+               /* choose OST and generate appropriate objects */
+               rc = lod_qos_prep_create(env, lo, attr, lovea, th);
+               if (rc) {
+                       /* failed to create striping, let's reset
+                        * config so that others don't get confused */
+                       lod_object_free_striping(env, lo);
+                       GOTO(out, rc);
+               }
 
-       /*
-        * declare storage for striping data
-        */
-       info->lti_buf.lb_len = lov_mds_md_size(lo->ldo_stripenr,
+               /*
+                * declare storage for striping data
+                */
+               info->lti_buf.lb_len = lov_mds_md_size(lo->ldo_stripenr,
                                lo->ldo_pool ?  LOV_MAGIC_V3 : LOV_MAGIC_V1);
-       rc = dt_declare_xattr_set(env, next, &info->lti_buf, XATTR_NAME_LOV,
-                                 0, th);
+       } else {
+               /* LOD can not choose OST objects for remote objects, i.e.
+                * stripes must be ready before that. Right now, it can only
+                * happen during migrate, i.e. migrate process needs to create
+                * remote regular file (mdd_migrate_create), then the migrate
+                * process will provide stripeEA. */
+               LASSERT(lovea != NULL);
+               info->lti_buf = *lovea;
+       }
+
+       rc = dt_declare_xattr_set(env, next, &info->lti_buf,
+                                 XATTR_NAME_LOV, 0, th);
        if (rc)
                GOTO(out, rc);
 
@@ -1847,7 +1912,11 @@ static int lod_declare_object_create(const struct lu_env *env,
                        rc = lod_declare_striped_object(env, dt, attr,
                                                        NULL, th);
        } else if (dof->dof_type == DFT_DIR) {
-               rc = lod_declare_dir_striping_create(env, dt, attr, dof, th);
+               /* Orphan object (like migrating object) does not have
+                * lod_dir_stripe, see lod_ah_init */
+               if (lo->ldo_dir_stripe != NULL)
+                       rc = lod_declare_dir_striping_create(env, dt, attr,
+                                                            dof, th);
        }
 out:
        RETURN(rc);
@@ -1891,7 +1960,8 @@ static int lod_object_create(const struct lu_env *env, struct dt_object *dt,
        rc = dt_create(env, next, attr, hint, dof, th);
 
        if (rc == 0) {
-               if (S_ISDIR(dt->do_lu.lo_header->loh_attr))
+               if (S_ISDIR(dt->do_lu.lo_header->loh_attr) &&
+                   lo->ldo_dir_stripe != NULL)
                        rc = lod_dir_striping_create(env, dt, attr, dof, th);
                else if (lo->ldo_stripe && dof->u.dof_reg.striped != 0)
                        rc = lod_striping_create(env, dt, attr, dof, th);
@@ -1916,6 +1986,9 @@ static int lod_declare_object_destroy(const struct lu_env *env,
        if (rc)
                RETURN(rc);
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ))
+               RETURN(0);
+
        /*
         * load striping information, notice we don't do this when object
         * is being initialized as we don't need this information till
@@ -1950,6 +2023,9 @@ static int lod_object_destroy(const struct lu_env *env,
        if (rc)
                RETURN(rc);
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ))
+               RETURN(0);
+
        /* destroy all underlying objects */
        for (i = 0; i < lo->ldo_stripenr; i++) {
                LASSERT(lo->ldo_stripe[i]);
@@ -2129,6 +2205,12 @@ static int lod_object_lock(const struct lu_env *env,
        /* striped directory lock */
        for (i = 0; i < lo->ldo_stripenr; i++) {
                struct lustre_handle    lockh;
+               struct ldlm_res_id      *res_id;
+
+               res_id = &lod_env_info(env)->lti_res_id;
+               fid_build_reg_res_name(lu_object_fid(&lo->ldo_stripe[i]->do_lu),
+                                      res_id);
+               einfo->ei_res_id = res_id;
 
                LASSERT(lo->ldo_stripe[i]);
                rc = dt_object_lock(env, lo->ldo_stripe[i], &lockh, einfo,
@@ -2193,11 +2275,11 @@ static ssize_t lod_read(const struct lu_env *env, struct dt_object *dt,
 
 static ssize_t lod_declare_write(const struct lu_env *env,
                                 struct dt_object *dt,
-                                const loff_t size, loff_t pos,
+                                const struct lu_buf *buf, loff_t pos,
                                 struct thandle *th)
 {
        return dt_declare_record_write(env, dt_object_child(dt),
-                                      size, pos, th);
+                                      buf, pos, th);
 }
 
 static ssize_t lod_write(const struct lu_env *env, struct dt_object *dt,