+static int lod_xattr_set_default_lmv_on_dir(const struct lu_env *env,
+ struct dt_object *dt,
+ const struct lu_buf *buf,
+ const char *name, int fl,
+ struct thandle *th,
+ struct lustre_capa *capa)
+{
+ struct dt_object *next = dt_object_child(dt);
+ struct lod_object *l = lod_dt_obj(dt);
+ struct lmv_user_md_v1 *lum;
+ int rc;
+ ENTRY;
+
+ LASSERT(buf != NULL && buf->lb_buf != NULL);
+ lum = buf->lb_buf;
+
+ CDEBUG(D_OTHER, "set default stripe_count # %u stripe_offset %d\n",
+ le32_to_cpu(lum->lum_stripe_count),
+ (int)le32_to_cpu(lum->lum_stripe_offset));
+
+ if (LMVEA_DELETE_VALUES((le32_to_cpu(lum->lum_stripe_count)),
+ le32_to_cpu(lum->lum_stripe_offset)) &&
+ le32_to_cpu(lum->lum_magic) == LMV_USER_MAGIC) {
+ rc = dt_xattr_del(env, next, name, th, capa);
+ if (rc == -ENODATA)
+ rc = 0;
+ } else {
+ rc = dt_xattr_set(env, next, buf, name, fl, th, capa);
+ if (rc != 0)
+ RETURN(rc);
+
+ /* Update default stripe cache */
+ if (l->ldo_dir_stripe == NULL) {
+ OBD_ALLOC_PTR(l->ldo_dir_stripe);
+ if (l->ldo_dir_stripe == NULL)
+ RETURN(-ENOMEM);
+ }
+
+ l->ldo_dir_striping_cached = 0;
+ l->ldo_dir_def_striping_set = 1;
+ l->ldo_dir_def_stripenr =
+ le32_to_cpu(lum->lum_stripe_count) - 1;
+ }
+
+ RETURN(rc);
+}
+