+ return stripe_idx;
+
+error:
+ for (j = 1; j < stripe_idx; j++) {
+ LASSERT(stripes[j] != NULL);
+ dt_object_put(env, stripes[j]);
+ stripes[j] = NULL;
+ }
+ return rc;
+}
+
+static int lod_prep_md_striped_create(const struct lu_env *env,
+ struct dt_object *dt,
+ struct lu_attr *attr,
+ const struct lmv_user_md_v1 *lum,
+ struct dt_object_format *dof,
+ struct thandle *th)
+{
+ struct lod_device *lod = lu2lod_dev(dt->do_lu.lo_dev);
+ struct lod_object *lo = lod_dt_obj(dt);
+ struct dt_object **stripes;
+ struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
+ struct lu_fid fid = { 0 };
+ __u32 stripe_count;
+ int i;
+ int rc = 0;
+
+ ENTRY;
+
+ /* 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);
+
+ stripe_count = lo->ldo_dir_stripe_count;
+
+ OBD_ALLOC(stripes, sizeof(stripes[0]) * stripe_count);
+ if (!stripes)
+ RETURN(-ENOMEM);
+
+ /* Allocate the first stripe locally */
+ rc = obd_fid_alloc(env, lod->lod_child_exp, &fid, NULL);
+ if (rc < 0)
+ GOTO(out, rc);
+
+ stripes[0] = dt_locate_at(env, lod->lod_child, &fid,
+ dt->do_lu.lo_dev->ld_site->ls_top_dev, &conf);
+ if (IS_ERR(stripes[0]))
+ GOTO(out, rc = PTR_ERR(stripes[0]));
+
+ if (lo->ldo_dir_stripe_offset == LMV_OFFSET_DEFAULT) {
+ lod_qos_statfs_update(env, lod, &lod->lod_mdt_descs);
+ rc = lod_mdt_alloc_qos(env, lo, stripes);
+ if (rc == -EAGAIN)
+ rc = lod_mdt_alloc_rr(env, lo, stripes);
+ } else {
+ int *idx_array;
+ bool is_specific = false;
+
+ OBD_ALLOC(idx_array, sizeof(idx_array[0]) * stripe_count);
+ if (!idx_array)
+ GOTO(out, rc = -ENOMEM);
+
+ if (le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC_SPECIFIC) {
+ is_specific = true;
+ for (i = 0; i < stripe_count; i++)
+ idx_array[i] =
+ le32_to_cpu(lum->lum_objects[i].lum_mds);
+ }
+
+ /* stripe 0 is local */
+ idx_array[0] =
+ lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
+ rc = lod_mdt_alloc_specific(env, lo, stripes, idx_array,
+ is_specific);
+ OBD_FREE(idx_array, sizeof(idx_array[0]) * stripe_count);
+ }
+
+ if (rc < 0)
+ GOTO(out, rc);
+
+ LASSERT(rc > 0);
+