struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
const struct lu_attr *la = &ma->ma_attr;
struct lu_ucred *uc;
+ struct lquota_id_info qi;
bool quota_reserved = false;
bool chrgrp_by_unprivileged_user = false;
- __s64 quota_size = 0;
int rc;
ENTRY;
* the setattr operation will be processed synchronously to
* honor the quota limit of the corresponding group. see LU-5152 */
uc = lu_ucred_check(env);
+ memset(&qi, 0, sizeof(qi));
if (S_ISREG(attr->la_mode) && la->la_valid & LA_GID &&
la->la_gid != attr->la_gid && uc != NULL && uc->uc_fsuid != 0) {
CDEBUG(D_QUOTA, "%s: reserve quota for changing group: gid=%u size=%llu\n",
mdd2obd_dev(mdd)->obd_name, la->la_gid, la->la_size);
if (la->la_valid & LA_BLOCKS)
- quota_size = la->la_blocks << 9;
+ qi.lqi_space = la->la_blocks << 9;
else if (la->la_valid & LA_SIZE)
- quota_size = la->la_size;
+ qi.lqi_space = la->la_size;
/* use local attr gotten above */
else if (attr->la_valid & LA_BLOCKS)
- quota_size = attr->la_blocks << 9;
+ qi.lqi_space = attr->la_blocks << 9;
else if (attr->la_valid & LA_SIZE)
- quota_size = attr->la_size;
+ qi.lqi_space = attr->la_size;
- if (quota_size > 0) {
+ if (qi.lqi_space > 0) {
+ qi.lqi_id.qid_gid = la->la_gid;
+ qi.lqi_type = GRPQUOTA;
+ qi.lqi_space = toqb(qi.lqi_space);
+ qi.lqi_is_blk = true;
rc = dt_reserve_or_free_quota(env, mdd->mdd_bottom,
- GRPQUOTA, attr->la_uid,
- la->la_gid, quota_size,
- false);
+ &qi);
if (rc) {
CDEBUG(D_QUOTA, "%s: failed to reserve quota for gid %d size %llu\n",
mdd2obd_dev(mdd)->obd_name,
- la->la_gid, quota_size);
+ la->la_gid, qi.lqi_space);
GOTO(out, rc);
}
sub_th = thandle_get_sub_by_dt(env, handle, mdd->mdd_bottom);
if (unlikely(IS_ERR(sub_th))) {
- dt_reserve_or_free_quota(env, mdd->mdd_bottom, GRPQUOTA,
- attr->la_uid, la->la_gid,
- -quota_size, false);
+ qi.lqi_space *= -1;
+ dt_reserve_or_free_quota(env, mdd->mdd_bottom, &qi);
} else {
- sub_th->th_reserved_quota.qrr_type = GRPQUOTA;
- sub_th->th_reserved_quota.qrr_id.qid_gid = la->la_gid;
- sub_th->th_reserved_quota.qrr_count = quota_size;
+ sub_th->th_reserved_quota = qi;
}
+ } else if (quota_reserved) {
+ qi.lqi_space *= -1;
+ dt_reserve_or_free_quota(env, mdd->mdd_bottom, &qi);
}
if (handle != NULL)
unlikely(spec != NULL && spec->sp_cr_flags & MDS_OPEN_HAS_EA)) {
hint->dah_eadata = spec->u.sp_ea.eadata;
hint->dah_eadata_len = spec->u.sp_ea.eadatalen;
- } else {
- hint->dah_eadata = NULL;
- hint->dah_eadata_len = 0;
- if (spec->sp_cr_flags & MDS_OPEN_APPEND) {
- if (mdd->mdd_append_stripe_count != 0 ||
- mdd->mdd_append_pool[0])
- CDEBUG(D_INFO,
- "using O_APPEND file striping\n");
- if (mdd->mdd_append_stripe_count)
- hint->dah_append_stripes =
- mdd->mdd_append_stripe_count;
- if (mdd->mdd_append_pool[0])
- hint->dah_append_pool = mdd->mdd_append_pool;
- } else {
- hint->dah_append_stripes = 0;
- }
+ } else if (S_ISREG(attr->la_mode) &&
+ spec->sp_cr_flags & MDS_OPEN_APPEND) {
+ hint->dah_append_stripe_count = mdd->mdd_append_stripe_count;
+ hint->dah_append_pool = mdd->mdd_append_pool;
}
CDEBUG(D_INFO, DFID" eadata %p len %d\n", PFID(mdd_object_fid(child)),
RETURN(rc);
}
-static int mdd_dir_page_build(const struct lu_env *env, union lu_page *lp,
- size_t nob, const struct dt_it_ops *iops,
+static int mdd_dir_page_build(const struct lu_env *env, struct dt_object *obj,
+ union lu_page *lp, size_t bytes,
+ const struct dt_it_ops *iops,
struct dt_it *it, __u32 attr, void *arg)
{
- struct lu_dirpage *dp = &lp->lp_dir;
- void *area = dp;
- int result;
- __u64 hash = 0;
- struct lu_dirent *ent;
- struct lu_dirent *last = NULL;
- struct lu_fid fid;
- int first = 1;
-
- if (nob < sizeof(*dp))
- return -EINVAL;
-
- memset(area, 0, sizeof (*dp));
- area += sizeof (*dp);
- nob -= sizeof (*dp);
-
- ent = area;
- do {
- int len;
+ struct lu_dirpage *dp = &lp->lp_dir;
+ void *area = dp;
+ __u64 hash = 0;
+ struct lu_dirent *ent;
+ struct lu_dirent *last = NULL;
+ struct lu_fid fid;
+ int first = 1;
+ int result;
+
+ if (bytes < sizeof(*dp))
+ GOTO(out_err, result = -EOVERFLOW);
+
+ memset(area, 0, sizeof(*dp));
+ area += sizeof(*dp);
+ bytes -= sizeof(*dp);
+
+ ent = area;
+ do {
+ int len;
size_t recsize;
- len = iops->key_size(env, it);
+ len = iops->key_size(env, it);
- /* IAM iterator can return record with zero len. */
- if (len == 0)
- goto next;
+ /* IAM iterator can return record with zero len. */
+ if (len == 0)
+ GOTO(next, 0);
- hash = iops->store(env, it);
- if (unlikely(first)) {
- first = 0;
- dp->ldp_hash_start = cpu_to_le64(hash);
- }
+ hash = iops->store(env, it);
+ if (unlikely(first)) {
+ first = 0;
+ dp->ldp_hash_start = cpu_to_le64(hash);
+ }
- /* calculate max space required for lu_dirent */
- recsize = lu_dirent_calc_size(len, attr);
+ /* calculate max space required for lu_dirent */
+ recsize = lu_dirent_calc_size(len, attr);
- if (nob >= recsize) {
- result = iops->rec(env, it, (struct dt_rec *)ent, attr);
- if (result == -ESTALE)
- goto next;
- if (result != 0)
- goto out;
+ if (bytes >= recsize &&
+ !OBD_FAIL_CHECK(OBD_FAIL_MDS_DIR_PAGE_WALK)) {
+ result = iops->rec(env, it, (struct dt_rec *)ent, attr);
+ if (result == -ESTALE)
+ GOTO(next, result);
+ if (result != 0)
+ GOTO(out, result);
- /* osd might not able to pack all attributes,
- * so recheck rec length */
- recsize = le16_to_cpu(ent->lde_reclen);
+ /* OSD might not able to pack all attributes, so
+ * recheck record length had room to store FID
+ */
+ recsize = le16_to_cpu(ent->lde_reclen);
if (le32_to_cpu(ent->lde_attrs) & LUDA_FID) {
fid_le_to_cpu(&fid, &ent->lde_fid);
if (fid_is_dot_lustre(&fid))
- goto next;
+ GOTO(next, recsize);
}
- } else {
- result = (last != NULL) ? 0 :-EINVAL;
- goto out;
- }
- last = ent;
- ent = (void *)ent + recsize;
- nob -= recsize;
+ } else {
+ result = (last != NULL) ? 0 : -EBADSLT;
+ GOTO(out, result);
+ }
+ last = ent;
+ ent = (void *)ent + recsize;
+ bytes -= recsize;
next:
- result = iops->next(env, it);
- if (result == -ESTALE)
- goto next;
- } while (result == 0);
+ result = iops->next(env, it);
+ if (result == -ESTALE)
+ GOTO(next, result);
+ } while (result == 0);
out:
- dp->ldp_hash_end = cpu_to_le64(hash);
- if (last != NULL) {
- if (last->lde_hash == dp->ldp_hash_end)
- dp->ldp_flags |= cpu_to_le32(LDF_COLLIDE);
- last->lde_reclen = 0; /* end mark */
- }
+ dp->ldp_hash_end = cpu_to_le64(hash);
+ if (last != NULL) {
+ if (last->lde_hash == dp->ldp_hash_end)
+ dp->ldp_flags |= cpu_to_le32(LDF_COLLIDE);
+ last->lde_reclen = 0; /* end mark */
+ }
+out_err:
if (result > 0)
/* end of directory */
dp->ldp_hash_end = cpu_to_le64(MDS_DIR_END_OFF);
else if (result < 0)
- CWARN("build page failed: %d!\n", result);
- return result;
+ CWARN("%s: build page failed for "DFID": rc = %d\n",
+ lu_dev_name(obj->do_lu.lo_dev),
+ PFID(lu_object_fid(&obj->do_lu)), result);
+
+ return result;
}
int mdd_readpage(const struct lu_env *env, struct md_object *obj,