+ /* store a default directory layout on the root directory if
+ * it doesn't already exist to improve MDT space balance.
+ */
+ root = dt_locate(env, mdd->mdd_bottom, &fid);
+ if (unlikely(IS_ERR(root)))
+ GOTO(out_los, rc = PTR_ERR(root));
+
+ rc = dt_xattr_get(env, root, &LU_BUF_NULL,
+ XATTR_NAME_DEFAULT_LMV);
+ if (rc == -ENODATA) {
+ struct lu_buf buf;
+ struct lmv_user_md lmv_default = {
+ .lum_magic = LMV_USER_MAGIC,
+ .lum_stripe_count = 1,
+ .lum_stripe_offset = LMV_OFFSET_DEFAULT,
+ .lum_max_inherit = LMV_INHERIT_UNLIMITED,
+ .lum_max_inherit_rr = LMV_INHERIT_RR_ROOT,
+ };
+
+ th = dt_trans_create(env, mdd->mdd_bottom);
+ if (IS_ERR(th))
+ GOTO(out_root_put, rc = PTR_ERR(th));
+
+ buf.lb_buf = &lmv_default;
+ buf.lb_len = sizeof(lmv_default);
+ rc = dt_declare_xattr_set(env, root, &buf,
+ XATTR_NAME_DEFAULT_LMV, 0,
+ th);
+ if (rc)
+ GOTO(out_trans_stop, rc);
+
+ rc = dt_trans_start_local(env, mdd->mdd_bottom, th);
+ if (rc)
+ GOTO(out_trans_stop, rc);
+
+ rc = dt_xattr_set(env, root, &buf,
+ XATTR_NAME_DEFAULT_LMV, 0, th);
+ if (rc)
+ GOTO(out_trans_stop, rc);
+
+ dt_trans_stop(env, mdd->mdd_bottom, th);
+ th = NULL;
+ } else if (rc < 0 && rc != -ERANGE) {
+ CERROR("%s: get default LMV of root failed: rc = %d\n",
+ mdd2obd_dev(mdd)->obd_name, rc);
+
+ GOTO(out_root_put, rc);
+ }
+
+ dt_object_put(env, root);
+ root = NULL;
+
+ mdd->mdd_root_fid = fid;