Whamcloud - gitweb
LU-11757 lod: use calculated stripe count
[fs/lustre-release.git] / lustre / lod / lod_object.c
index dc896ef..d7fdad2 100644 (file)
@@ -98,9 +98,9 @@ static int lod_declare_insert(const struct lu_env *env, struct dt_object *dt,
  */
 static int lod_insert(const struct lu_env *env, struct dt_object *dt,
                      const struct dt_rec *rec, const struct dt_key *key,
-                     struct thandle *th, int ign)
+                     struct thandle *th)
 {
-       return lod_sub_insert(env, dt_object_child(dt), rec, key, th, ign);
+       return lod_sub_insert(env, dt_object_child(dt), rec, key, th);
 }
 
 /**
@@ -1662,9 +1662,6 @@ int lod_parse_dir_striping(const struct lu_env *env, struct lod_object *lo,
 
        LASSERT(mutex_is_locked(&lo->ldo_layout_mutex));
 
-       if (le32_to_cpu(lmv1->lmv_hash_type) & LMV_HASH_FLAG_MIGRATION)
-               RETURN(0);
-
        if (le32_to_cpu(lmv1->lmv_magic) == LMV_MAGIC_STRIPE) {
                lo->ldo_dir_slave_stripe = 1;
                RETURN(0);
@@ -1895,9 +1892,8 @@ static int lod_prep_md_striped_create(const struct lu_env *env,
        /* The lum has been verifed in lod_verify_md_striping */
        LASSERT(le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC ||
                le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC_SPECIFIC);
-       LASSERT(le32_to_cpu(lum->lum_stripe_count) > 0);
 
-       stripe_count = le32_to_cpu(lum->lum_stripe_count);
+       stripe_count = lo->ldo_dir_stripe_count;
 
        OBD_ALLOC(idx_array, sizeof(idx_array[0]) * stripe_count);
        if (idx_array == NULL)
@@ -2473,20 +2469,25 @@ lod_obj_stripe_replace_parent_fid_cb(const struct lu_env *env,
                return rc;
        }
 
-       filter_fid_le_to_cpu(ff, ff, sizeof(*ff));
-
        /*
-        * mdd_declare_migrate_create() declares this via source object because
-        * target is not ready yet, so declare anyway.
+        * locd_buf is set if it's called by dir migration, which doesn't check
+        * pfid and comp id.
         */
-       if (!data->locd_declare &&
-           lu_fid_eq(lu_object_fid(&lo->ldo_obj.do_lu), &ff->ff_parent) &&
-           ff->ff_layout.ol_comp_id == comp->llc_id)
-               return 0;
+       if (data->locd_buf) {
+               memset(ff, 0, sizeof(*ff));
+               ff->ff_parent = *(struct lu_fid *)data->locd_buf->lb_buf;
+       } else {
+               filter_fid_le_to_cpu(ff, ff, sizeof(*ff));
+
+               if (lu_fid_eq(lod_object_fid(lo), &ff->ff_parent) &&
+                   ff->ff_layout.ol_comp_id == comp->llc_id)
+                       return 0;
+
+               memset(ff, 0, sizeof(*ff));
+               ff->ff_parent = *lu_object_fid(&lo->ldo_obj.do_lu);
+       }
 
        /* rewrite filter_fid */
-       memset(ff, 0, sizeof(*ff));
-       ff->ff_parent = *lu_object_fid(&lo->ldo_obj.do_lu);
        ff->ff_parent.f_ver = stripe_idx;
        ff->ff_layout.ol_stripe_size = comp->llc_stripe_size;
        ff->ff_layout.ol_stripe_count = comp->llc_stripe_count;
@@ -2522,11 +2523,11 @@ lod_obj_stripe_replace_parent_fid_cb(const struct lu_env *env,
  */
 static int lod_replace_parent_fid(const struct lu_env *env,
                                  struct dt_object *dt,
+                                 const struct lu_buf *buf,
                                  struct thandle *th, bool declare)
 {
        struct lod_object *lo = lod_dt_obj(dt);
        struct lod_thread_info  *info = lod_env_info(env);
-       struct lu_buf *buf = &info->lti_buf;
        struct filter_fid *ff;
        struct lod_obj_stripe_cb_data data = { { 0 } };
        int rc;
@@ -2548,11 +2549,9 @@ static int lod_replace_parent_fid(const struct lu_env *env,
                        RETURN(rc);
        }
 
-       buf->lb_buf = info->lti_ea_store;
-       buf->lb_len = info->lti_ea_store_size;
-
        data.locd_declare = declare;
        data.locd_stripe_cb = lod_obj_stripe_replace_parent_fid_cb;
+       data.locd_buf = buf;
        rc = lod_obj_for_each_stripe(env, lo, th, &data);
 
        RETURN(rc);
@@ -2793,6 +2792,8 @@ static int lod_declare_layout_set(const struct lu_env *env,
        for (i = 0; i < comp_v1->lcm_entry_count; i++) {
                __u32 id = comp_v1->lcm_entries[i].lcme_id;
                __u32 flags = comp_v1->lcm_entries[i].lcme_flags;
+               __u32 mirror_flag = flags & LCME_MIRROR_FLAGS;
+               bool neg = flags & LCME_FL_NEG;
 
                if (flags & LCME_FL_INIT) {
                        if (changed)
@@ -2800,16 +2801,30 @@ static int lod_declare_layout_set(const struct lu_env *env,
                        RETURN(-EINVAL);
                }
 
+               flags &= ~(LCME_MIRROR_FLAGS | LCME_FL_NEG);
                for (j = 0; j < lo->ldo_comp_cnt; j++) {
                        lod_comp = &lo->ldo_comp_entries[j];
-                       if (id != lod_comp->llc_id)
+
+                       /* lfs only put one flag in each entry */
+                       if ((flags && id != lod_comp->llc_id) ||
+                           (mirror_flag && mirror_id_of(id) !=
+                                           mirror_id_of(lod_comp->llc_id)))
                                continue;
 
-                       if (flags & LCME_FL_NEG) {
-                               flags &= ~LCME_FL_NEG;
-                               lod_comp->llc_flags &= ~flags;
+                       if (neg) {
+                               if (flags)
+                                       lod_comp->llc_flags &= ~flags;
+                               if (mirror_flag)
+                                       lod_comp->llc_flags &= ~mirror_flag;
                        } else {
-                               lod_comp->llc_flags |= flags;
+                               if (flags)
+                                       lod_comp->llc_flags |= flags;
+                               if (mirror_flag) {
+                                       lod_comp->llc_flags |= mirror_flag;
+                                       if (mirror_flag & LCME_FL_NOSYNC)
+                                               lod_comp->llc_timestamp =
+                                                      ktime_get_real_seconds();
+                               }
                        }
                        changed = true;
                }
@@ -3345,7 +3360,7 @@ static int lod_declare_xattr_set(const struct lu_env *env,
        } else if (S_ISDIR(mode)) {
                rc = lod_dir_declare_xattr_set(env, dt, buf, name, fl, th);
        } else if (strcmp(name, XATTR_NAME_FID) == 0) {
-               rc = lod_replace_parent_fid(env, dt, th, true);
+               rc = lod_replace_parent_fid(env, dt, buf, th, true);
        } else {
                rc = lod_sub_declare_xattr_set(env, next, buf, name, fl, th);
        }
@@ -3661,14 +3676,14 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
                        rec->rec_fid = lu_object_fid(&dto->do_lu);
                        rc = lod_sub_insert(env, dto,
                                            (const struct dt_rec *)rec,
-                                           (const struct dt_key *)dot, th, 0);
+                                           (const struct dt_key *)dot, th);
                        if (rc != 0)
                                GOTO(out, rc);
                }
 
                rec->rec_fid = lu_object_fid(&dt->do_lu);
                rc = lod_sub_insert(env, dto, (struct dt_rec *)rec,
-                                   (const struct dt_key *)dotdot, th, 0);
+                                   (const struct dt_key *)dotdot, th);
                if (rc != 0)
                        GOTO(out, rc);
 
@@ -3712,7 +3727,7 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
                rec->rec_fid = lu_object_fid(&dto->do_lu);
                rc = lod_sub_insert(env, dt_object_child(dt),
                                    (const struct dt_rec *)rec,
-                                   (const struct dt_key *)stripe_name, th, 0);
+                                   (const struct dt_key *)stripe_name, th);
                if (rc != 0)
                        GOTO(out, rc);
 
@@ -4214,7 +4229,7 @@ static int lod_xattr_set(const struct lu_env *env,
                }
                RETURN(rc);
        } else if (strcmp(name, XATTR_NAME_FID) == 0) {
-               rc = lod_replace_parent_fid(env, dt, th, false);
+               rc = lod_replace_parent_fid(env, dt, buf, th, false);
 
                RETURN(rc);
        }
@@ -4450,7 +4465,6 @@ static int lod_get_default_lov_striping(const struct lu_env *env,
 
        for (i = 0; i < comp_cnt; i++) {
                struct lod_layout_component *lod_comp;
-               struct lu_extent *ext;
                char *pool;
 
                lod_comp = &lds->lds_def_comp_entries[i];
@@ -4464,8 +4478,12 @@ static int lod_get_default_lov_striping(const struct lu_env *env,
                if (composite) {
                        v1 = (struct lov_user_md *)((char *)comp_v1 +
                                        comp_v1->lcm_entries[i].lcme_offset);
-                       ext = &comp_v1->lcm_entries[i].lcme_extent;
-                       lod_comp->llc_extent = *ext;
+                       lod_comp->llc_extent =
+                                       comp_v1->lcm_entries[i].lcme_extent;
+                       /* We only inherit certain flags from the layout */
+                       lod_comp->llc_flags =
+                                       comp_v1->lcm_entries[i].lcme_flags &
+                                       LCME_TEMPLATE_FLAGS;
                }
 
                if (v1->lmm_pattern != LOV_PATTERN_RAID0 &&
@@ -4608,8 +4626,9 @@ static void lod_striping_from_default(struct lod_object *lo,
                        struct lod_layout_component *def_comp =
                                                &lds->lds_def_comp_entries[i];
 
-                       CDEBUG(D_LAYOUT, "Inherite from default: size:%hu "
-                              "nr:%u offset:%u pattern %#x %s\n",
+                       CDEBUG(D_LAYOUT, "Inherit from default: flags=%#x "
+                              "size=%hu nr=%u offset=%u pattern=%#x pool=%s\n",
+                              def_comp->llc_flags,
                               def_comp->llc_stripe_size,
                               def_comp->llc_stripe_count,
                               def_comp->llc_stripe_offset,
@@ -5303,6 +5322,23 @@ out:
        RETURN(rc);
 }
 
+static inline bool lod_obj_is_dom(struct dt_object *dt)
+{
+       struct lod_object *lo = lod_dt_obj(dt);
+
+       if (!dt_object_exists(dt_object_child(dt)))
+               return false;
+
+       if (S_ISDIR(dt->do_lu.lo_header->loh_attr))
+               return false;
+
+       if (!lo->ldo_comp_cnt)
+               return false;
+
+       return (lov_pattern(lo->ldo_comp_entries[0].llc_pattern) ==
+               LOV_PATTERN_MDT);
+}
+
 /**
  * Implementation of dt_object_operations::do_create.
  *
@@ -5325,7 +5361,8 @@ static int lod_create(const struct lu_env *env, struct dt_object *dt,
                RETURN(rc);
 
        if (S_ISREG(dt->do_lu.lo_header->loh_attr) &&
-           lod_obj_is_striped(dt) && dof->u.dof_reg.striped != 0) {
+           (lod_obj_is_striped(dt) || lod_obj_is_dom(dt)) &&
+           dof->u.dof_reg.striped != 0) {
                LASSERT(lod_dt_obj(dt)->ldo_comp_cached == 0);
                rc = lod_striped_create(env, dt, attr, dof, th);
        }
@@ -5705,7 +5742,7 @@ static int lod_object_lock(const struct lu_env *env,
                                dlmflags |= LDLM_FL_COS_INCOMPAT;
 
                        LASSERT(ns != NULL);
-                       rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS,
+                       rc = ldlm_cli_enqueue_local(env, ns, res_id, LDLM_IBITS,
                                                    policy, einfo->ei_mode,
                                                    &dlmflags, blocking,
                                                    completion, NULL,
@@ -6098,6 +6135,30 @@ static int lod_primary_pick(const struct lu_env *env, struct lod_object *lo,
        RETURN(picked);
 }
 
+static int lod_prepare_resync_mirror(const struct lu_env *env,
+                                    struct lod_object *lo,
+                                    __u16 mirror_id)
+{
+       struct lod_thread_info *info = lod_env_info(env);
+       struct lod_layout_component *lod_comp;
+       int i;
+
+       for (i = 0; i < lo->ldo_mirror_count; i++) {
+               if (lo->ldo_mirrors[i].lme_id != mirror_id)
+                       continue;
+
+               lod_foreach_mirror_comp(lod_comp, lo, i) {
+                       if (lod_comp_inited(lod_comp))
+                               continue;
+
+                       info->lti_comp_idx[info->lti_count++] =
+                               lod_comp_index(lo, lod_comp);
+               }
+       }
+
+       return 0;
+}
+
 /**
  * figure out the components should be instantiated for resync.
  */
@@ -6213,23 +6274,33 @@ static int lod_declare_update_rdonly(const struct lu_env *env,
                 * prep uninited all components assuming any non-stale mirror
                 * could be picked as the primary mirror.
                 */
-               for (i = 0; i < lo->ldo_mirror_count; i++) {
-                       if (lo->ldo_mirrors[i].lme_stale)
-                               continue;
+               if (mlc->mlc_mirror_id == 0) {
+                       /* normal resync */
+                       for (i = 0; i < lo->ldo_mirror_count; i++) {
+                               if (lo->ldo_mirrors[i].lme_stale)
+                                       continue;
 
-                       lod_foreach_mirror_comp(lod_comp, lo, i) {
-                               if (!lod_comp_inited(lod_comp))
-                                       break;
+                               lod_foreach_mirror_comp(lod_comp, lo, i) {
+                                       if (!lod_comp_inited(lod_comp))
+                                               break;
 
-                               if (extent.e_end < lod_comp->llc_extent.e_end)
-                                       extent.e_end =
-                                               lod_comp->llc_extent.e_end;
+                                       if (extent.e_end <
+                                               lod_comp->llc_extent.e_end)
+                                               extent.e_end =
+                                                    lod_comp->llc_extent.e_end;
+                               }
                        }
+                       rc = lod_prepare_resync(env, lo, &extent);
+                       if (rc)
+                               GOTO(out, rc);
+               } else {
+                       /* mirror write, try to init its all components */
+                       rc = lod_prepare_resync_mirror(env, lo,
+                                                      mlc->mlc_mirror_id);
+                       if (rc)
+                               GOTO(out, rc);
                }
 
-               rc = lod_prepare_resync(env, lo, &extent);
-               if (rc)
-                       GOTO(out, rc);
                /* change the file state to SYNC_PENDING */
                lo->ldo_flr_state = LCM_FL_SYNC_PENDING;
        }
@@ -6353,16 +6424,26 @@ static int lod_declare_update_write_pending(const struct lu_env *env,
                                                lod_comp_index(lo, lod_comp);
                }
        } else { /* MD_LAYOUT_RESYNC */
-               lod_foreach_mirror_comp(lod_comp, lo, primary) {
-                       if (!lod_comp_inited(lod_comp))
-                               break;
+               if (mlc->mlc_mirror_id == 0) {
+                       /* normal resync */
+                       lod_foreach_mirror_comp(lod_comp, lo, primary) {
+                               if (!lod_comp_inited(lod_comp))
+                                       break;
 
-                       extent.e_end = lod_comp->llc_extent.e_end;
+                               extent.e_end = lod_comp->llc_extent.e_end;
+                       }
+
+                       rc = lod_prepare_resync(env, lo, &extent);
+                       if (rc)
+                               GOTO(out, rc);
+               } else {
+                       /* mirror write, try to init its all components */
+                       rc = lod_prepare_resync_mirror(env, lo,
+                                                      mlc->mlc_mirror_id);
+                       if (rc)
+                               GOTO(out, rc);
                }
 
-               rc = lod_prepare_resync(env, lo, &extent);
-               if (rc)
-                       GOTO(out, rc);
                /* change the file state to SYNC_PENDING */
                lo->ldo_flr_state = LCM_FL_SYNC_PENDING;
        }
@@ -6613,11 +6694,11 @@ static ssize_t lod_declare_write(const struct lu_env *env,
  */
 static ssize_t lod_write(const struct lu_env *env, struct dt_object *dt,
                         const struct lu_buf *buf, loff_t *pos,
-                        struct thandle *th, int iq)
+                        struct thandle *th)
 {
        LASSERT(S_ISREG(dt->do_lu.lo_header->loh_attr) ||
                S_ISLNK(dt->do_lu.lo_header->loh_attr));
-       return lod_sub_write(env, dt_object_child(dt), buf, pos, th, iq);
+       return lod_sub_write(env, dt_object_child(dt), buf, pos, th);
 }
 
 static int lod_declare_punch(const struct lu_env *env, struct dt_object *dt,