Whamcloud - gitweb
git://git.whamcloud.com
/
fs
/
lustre-release.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
LU-15880 quota: fix issues in reserving quota
[fs/lustre-release.git]
/
lustre
/
mdd
/
mdd_object.c
diff --git
a/lustre/mdd/mdd_object.c
b/lustre/mdd/mdd_object.c
index
1553946
..
7de1017
100644
(file)
--- a/
lustre/mdd/mdd_object.c
+++ b/
lustre/mdd/mdd_object.c
@@
-250,7
+250,7
@@
struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len)
{
struct lu_buf *buf;
- buf = &mdd_env_info(env)->m
t
i_buf[0];
+ buf = &mdd_env_info(env)->m
d
i_buf[0];
buf->lb_buf = area;
buf->lb_len = len;
return buf;
@@
-261,7
+261,7
@@
const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
{
struct lu_buf *buf;
- buf = &mdd_env_info(env)->m
t
i_buf[0];
+ buf = &mdd_env_info(env)->m
d
i_buf[0];
buf->lb_buf = (void *)area;
buf->lb_len = len;
return buf;
@@
-550,7
+550,7
@@
int mdd_declare_create_object_internal(const struct lu_env *env,
const struct md_op_spec *spec,
struct dt_allocation_hint *hint)
{
- struct dt_object_format *dof = &mdd_env_info(env)->m
t
i_dof;
+ struct dt_object_format *dof = &mdd_env_info(env)->m
d
i_dof;
const struct dt_index_features *feat = spec->sp_feat;
int rc;
ENTRY;
@@
-582,7
+582,7
@@
int mdd_create_object_internal(const struct lu_env *env, struct mdd_object *p,
const struct md_op_spec *spec,
struct dt_allocation_hint *hint)
{
- struct dt_object_format *dof = &mdd_env_info(env)->m
t
i_dof;
+ struct dt_object_format *dof = &mdd_env_info(env)->m
d
i_dof;
int rc;
ENTRY;
@@
-684,7
+684,7
@@
static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
RETURN(0);
if (is_project_state_change(oattr, la)) {
- if (!
md_capable(uc
, CAP_SYS_RESOURCE) &&
+ if (!
cap_raised(uc->uc_cap
, CAP_SYS_RESOURCE) &&
!lustre_in_group_p(uc, ma->ma_enable_chprojid_gid) &&
!(ma->ma_enable_chprojid_gid == -1 &&
mdd_permission_internal(env, obj, oattr, MAY_WRITE)))
@@
-726,13
+726,13
@@
static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
(LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL);
if ((uc->uc_fsuid != oattr->la_uid) &&
- !
md_capable(uc
, CAP_FOWNER))
+ !
cap_raised(uc->uc_cap
, CAP_FOWNER))
RETURN(-EPERM);
/* The IMMUTABLE and APPEND_ONLY flags can
* only be changed by the relevant capability. */
if ((oldflags ^ newflags) &&
- !
md_capable(uc
, CAP_LINUX_IMMUTABLE))
+ !
cap_raised(uc->uc_cap
, CAP_LINUX_IMMUTABLE))
RETURN(-EPERM);
if (!S_ISDIR(oattr->la_mode)) {
@@
-757,7
+757,7
@@
static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
if ((la->la_valid & (LA_MTIME | LA_ATIME | LA_CTIME)) &&
!(la->la_valid & ~(LA_MTIME | LA_ATIME | LA_CTIME))) {
if ((uc->uc_fsuid != oattr->la_uid) &&
- !
md_capable(uc
, CAP_FOWNER)) {
+ !
cap_raised(uc->uc_cap
, CAP_FOWNER)) {
rc = mdd_permission_internal(env, obj, oattr,
MAY_WRITE);
if (rc)
@@
-790,7
+790,7
@@
static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
if (la->la_valid & LA_MODE) {
if (!(flags & MDS_PERM_BYPASS) &&
(uc->uc_fsuid != oattr->la_uid) &&
- !
md_capable(uc
, CAP_FOWNER))
+ !
cap_raised(uc->uc_cap
, CAP_FOWNER))
RETURN(-EPERM);
if (la->la_mode == (umode_t) -1)
@@
-802,7
+802,7
@@
static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
/* Also check the setgid bit! */
if (!lustre_in_group_p(uc, (la->la_valid & LA_GID) ?
la->la_gid : oattr->la_gid) &&
- !
md_capable(uc
, CAP_FSETID))
+ !
cap_raised(uc->uc_cap
, CAP_FSETID))
la->la_mode &= ~S_ISGID;
} else {
la->la_mode = oattr->la_mode;
@@
-814,7
+814,7
@@
static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
la->la_uid = oattr->la_uid;
if (((uc->uc_fsuid != oattr->la_uid) ||
(la->la_uid != oattr->la_uid)) &&
- !
md_capable(uc
, CAP_CHOWN))
+ !
cap_raised(uc->uc_cap
, CAP_CHOWN))
RETURN(-EPERM);
/* If the user or group of a non-directory has been
@@
-840,7
+840,7
@@
static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
if (((uc->uc_fsuid != oattr->la_uid) ||
((la->la_gid != oattr->la_gid) &&
!lustre_in_group_p(uc, la->la_gid))) &&
- !
md_capable(uc
, CAP_CHOWN))
+ !
cap_raised(uc->uc_cap
, CAP_CHOWN))
RETURN(-EPERM);
/* Likewise, if the user or group of a non-directory
@@
-870,8
+870,10
@@
static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
}
if (la->la_valid & LA_CTIME) {
- /* The pure setattr, it has the priority over what is
- * already set, do not drop it if ctime is equal. */
+ /**
+ * The pure setattr, it has the priority over what is
+ * already set, do not drop it if ctime is equal.
+ */
if (la->la_ctime < oattr->la_ctime)
la->la_valid &= ~(LA_ATIME | LA_MTIME | LA_CTIME);
}
@@
-911,7
+913,7
@@
static int mdd_changelog_data_store_by_fid(const struct lu_env *env,
reclen = llog_data_len(LLOG_CHANGELOG_HDR_SZ +
changelog_rec_offset(clf_flags & CLF_SUPPORTED,
xflags & CLFE_SUPPORTED));
- buf = lu_buf_check_and_alloc(&mdd_env_info(env)->m
ti_bi
g_buf, reclen);
+ buf = lu_buf_check_and_alloc(&mdd_env_info(env)->m
di_chl
g_buf, reclen);
if (buf->lb_buf == NULL)
RETURN(-ENOMEM);
rec = buf->lb_buf;
@@
-1088,7
+1090,7
@@
static int mdd_attr_set_changelog(const struct lu_env *env,
bits |= (valid & LA_MTIME) ? BIT(CL_MTIME) : 0;
bits |= (valid & LA_CTIME) ? BIT(CL_CTIME) : 0;
bits |= (valid & LA_ATIME) ? BIT(CL_ATIME) : 0;
- bits = bits & mdd->mdd_cl.mc_mask;
+ bits = bits & mdd->mdd_cl.mc_
current_
mask;
/* This is an implementation limit rather than a protocol limit */
BUILD_BUG_ON(CL_LAST > sizeof(int) * 8);
if (bits == 0)
@@
-1211,10
+1213,12
@@
int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
struct mdd_object *mdd_obj = md2mdd_obj(obj);
struct mdd_device *mdd = mdo2mdd(obj);
struct thandle *handle = NULL;
- struct lu_attr *la_copy = &mdd_env_info(env)->m
t
i_la_for_fix;
+ struct lu_attr *la_copy = &mdd_env_info(env)->m
d
i_la_for_fix;
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;
int rc;
ENTRY;
@@
-1246,13
+1250,42
@@
int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
* 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) {
- /* LU-10048: disable synchronous chgrp operation for it will
- * cause deadlock between MDT and OST.
- la_copy->la_valid |= LA_FLAGS;
- la_copy->la_flags |= LUSTRE_SET_SYNC_FL;
- */
+ 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)
+ qi.lqi_space = la->la_blocks << 9;
+ else if (la->la_valid & LA_SIZE)
+ qi.lqi_space = la->la_size;
+ /* use local attr gotten above */
+ else if (attr->la_valid & LA_BLOCKS)
+ qi.lqi_space = attr->la_blocks << 9;
+ else if (attr->la_valid & LA_SIZE)
+ qi.lqi_space = attr->la_size;
+
+ 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,
+ &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, qi.lqi_space);
+
+ GOTO(out, rc);
+ }
+
+ quota_reserved = true;
+ la_copy->la_valid |= LA_FLAGS;
+ }
+
chrgrp_by_unprivileged_user = true;
/* Flush the possible existing client setattr requests to OSTs
@@
-1328,6
+1361,21
@@
out:
rc = mdd_attr_set_changelog(env, obj, handle, &ma->ma_pfid,
la_copy->la_valid);
+ if (rc == 0 && quota_reserved) {
+ struct thandle *sub_th;
+
+ sub_th = thandle_get_sub_by_dt(env, handle, mdd->mdd_bottom);
+ if (unlikely(IS_ERR(sub_th))) {
+ qi.lqi_space *= -1;
+ dt_reserve_or_free_quota(env, mdd->mdd_bottom, &qi);
+ } else {
+ 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)
rc = mdd_trans_stop(env, mdd, rc, handle);
@@
-1351,11
+1399,11
@@
static int mdd_xattr_sanity_check(const struct lu_env *env,
* can write attributes. */
if (S_ISDIR(attr->la_mode) && (attr->la_mode & S_ISVTX) &&
(uc->uc_fsuid != attr->la_uid) &&
- !
md_capable(uc
, CAP_FOWNER))
+ !
cap_raised(uc->uc_cap
, CAP_FOWNER))
RETURN(-EPERM);
} else if (strcmp(name, XATTR_NAME_SOM) != 0 &&
(uc->uc_fsuid != attr->la_uid) &&
- !
md_capable(uc
, CAP_FOWNER)) {
+ !
cap_raised(uc->uc_cap
, CAP_FOWNER)) {
RETURN(-EPERM);
}
@@
-1458,7
+1506,7
@@
static int mdd_hsm_update_locked(const struct lu_env *env,
RETURN(-ENOMEM);
/* Read HSM attrs from disk */
- current_buf = lu_buf_check_and_alloc(&info->m
t
i_xattr_buf,
+ current_buf = lu_buf_check_and_alloc(&info->m
d
i_xattr_buf,
min_t(unsigned int,
mdd_obj2mdd_dev(mdd_obj)->mdd_dt_conf.ddp_max_ea_size,
XATTR_SIZE_MAX));
@@
-1540,64
+1588,64
@@
static int mdd_xattr_merge(const struct lu_env *env, struct md_object *md_obj,
struct mdd_device *mdd = mdo2mdd(md_obj);
struct mdd_object *obj = md2mdd_obj(md_obj);
struct mdd_object *vic = md2mdd_obj(md_vic);
- struct lu_buf *buf = &mdd_env_info(env)->m
t
i_buf[0];
- struct lu_buf *buf_vic = &mdd_env_info(env)->m
t
i_buf[1];
+ struct lu_buf *buf = &mdd_env_info(env)->m
d
i_buf[0];
+ struct lu_buf *buf_vic = &mdd_env_info(env)->m
d
i_buf[1];
struct lov_mds_md *lmm;
struct thandle *handle;
- int rc;
+ int rc
, lock_order
;
ENTRY;
-
rc
= lu_fid_cmp(mdd_object_fid(obj), mdd_object_fid(vic));
- if (
rc
== 0) /* same fid */
+
lock_order
= lu_fid_cmp(mdd_object_fid(obj), mdd_object_fid(vic));
+ if (
lock_order
== 0) /* same fid */
RETURN(-EPERM);
handle = mdd_trans_create(env, mdd);
if (IS_ERR(handle))
RETURN(PTR_ERR(handle));
- if (rc > 0) {
- mdd_write_lock(env, obj, DT_TGT_CHILD);
- mdd_write_lock(env, vic, DT_TGT_CHILD);
- } else {
- mdd_write_lock(env, vic, DT_TGT_CHILD);
- mdd_write_lock(env, obj, DT_TGT_CHILD);
- }
-
/* get EA of victim file */
memset(buf_vic, 0, sizeof(*buf_vic));
rc = mdd_stripe_get(env, vic, buf_vic, XATTR_NAME_LOV);
if (rc < 0) {
if (rc == -ENODATA)
rc = 0;
- GOTO(
out
, rc);
+ GOTO(
stop
, rc);
}
/* parse the layout of victim file */
lmm = buf_vic->lb_buf;
if (le32_to_cpu(lmm->lmm_magic) != LOV_MAGIC_COMP_V1)
- GOTO(
out
, rc = -EINVAL);
+ GOTO(
stop
, rc = -EINVAL);
/* save EA of target file for restore */
memset(buf, 0, sizeof(*buf));
rc = mdd_stripe_get(env, obj, buf, XATTR_NAME_LOV);
if (rc < 0)
- GOTO(
out
, rc);
+ GOTO(
stop
, rc);
/* Get rid of the layout from victim object */
rc = mdd_declare_xattr_del(env, mdd, vic, XATTR_NAME_LOV, handle);
if (rc)
- GOTO(
out
, rc);
+ GOTO(
stop
, rc);
- rc = mdd_declare_xattr_set(env, mdd, obj, buf_vic, XATTR_
LUSTR
E_LOV,
+ rc = mdd_declare_xattr_set(env, mdd, obj, buf_vic, XATTR_
NAM
E_LOV,
LU_XATTR_MERGE, handle);
if (rc)
- GOTO(
out
, rc);
+ GOTO(
stop
, rc);
rc = mdd_trans_start(env, mdd, handle);
if (rc != 0)
- GOTO(
out
, rc);
+ GOTO(
stop
, rc);
- rc = mdo_xattr_set(env, obj, buf_vic, XATTR_LUSTRE_LOV, LU_XATTR_MERGE,
+ if (lock_order > 0) {
+ mdd_write_lock(env, obj, DT_TGT_CHILD);
+ mdd_write_lock(env, vic, DT_TGT_CHILD);
+ } else {
+ mdd_write_lock(env, vic, DT_TGT_CHILD);
+ mdd_write_lock(env, obj, DT_TGT_CHILD);
+ }
+
+ rc = mdo_xattr_set(env, obj, buf_vic, XATTR_NAME_LOV, LU_XATTR_MERGE,
handle);
if (rc)
GOTO(out, rc);
@@
-1623,9
+1671,10
@@
out_restore:
}
out:
- mdd_trans_stop(env, mdd, rc, handle);
mdd_write_unlock(env, obj);
mdd_write_unlock(env, vic);
+stop:
+ mdd_trans_stop(env, mdd, rc, handle);
lu_buf_free(buf);
lu_buf_free(buf_vic);
@@
-1770,9
+1819,9
@@
static int mdd_xattr_split(const struct lu_env *env, struct md_object *md_obj,
struct mdd_device *mdd = mdo2mdd(md_obj);
struct mdd_object *obj = md2mdd_obj(md_obj);
struct mdd_object *vic = NULL;
- struct lu_buf *buf = &mdd_env_info(env)->m
t
i_buf[0];
- struct lu_buf *buf_save = &mdd_env_info(env)->m
t
i_buf[1];
- struct lu_buf *buf_vic = &mdd_env_info(env)->m
t
i_buf[2];
+ struct lu_buf *buf = &mdd_env_info(env)->m
d
i_buf[0];
+ struct lu_buf *buf_save = &mdd_env_info(env)->m
d
i_buf[1];
+ struct lu_buf *buf_vic = &mdd_env_info(env)->m
d
i_buf[2];
struct lov_comp_md_v1 *lcm;
struct thandle *handle;
int rc;
@@
-1876,7
+1925,7
@@
static int mdd_xattr_split(const struct lu_env *env, struct md_object *md_obj,
}
/* set obj's layout in @buf */
- rc = mdo_xattr_set(env, obj, buf, XATTR_NAME_LOV, LU_XATTR_
REPLACE
,
+ rc = mdo_xattr_set(env, obj, buf, XATTR_NAME_LOV, LU_XATTR_
SPLIT
,
handle);
if (rc)
GOTO(unlock, rc);
@@
-2141,7
+2190,7
@@
stop:
int mdd_stripe_get(const struct lu_env *env, struct mdd_object *obj,
struct lu_buf *lmm_buf, const char *name)
{
- struct lu_buf *buf = &mdd_env_info(env)->m
t
i_big_buf;
+ struct lu_buf *buf = &mdd_env_info(env)->m
d
i_big_buf;
int rc;
ENTRY;
@@
-2155,9
+2204,9
@@
int mdd_stripe_get(const struct lu_env *env, struct mdd_object *obj,
repeat:
rc = mdo_xattr_get(env, obj, buf, name);
if (rc == -ERANGE) {
- /* m
t
i_big_buf is allocated but is too small
+ /* m
d
i_big_buf is allocated but is too small
* we need to increase it */
- buf = lu_buf_check_and_alloc(&mdd_env_info(env)->m
t
i_big_buf,
+ buf = lu_buf_check_and_alloc(&mdd_env_info(env)->m
d
i_big_buf,
buf->lb_len * 2);
if (buf->lb_buf == NULL)
RETURN(-ENOMEM);
@@
-2174,7
+2223,7
@@
repeat:
/*
* we don't use lmm_buf directly, because we don't know xattr size, so
- * by using m
t
i_big_buf we can avoid calling mdo_xattr_get() twice.
+ * by using m
d
i_big_buf we can avoid calling mdo_xattr_get() twice.
*/
memcpy(lmm_buf->lb_buf, buf->lb_buf, rc);
@@
-2386,10
+2435,10
@@
static int mdd_swap_layouts(const struct lu_env *env, struct md_object *obj1,
struct lu_attr *snd_la = MDD_ENV_VAR(env, tattr);
struct mdd_device *mdd = mdo2mdd(obj1);
struct lov_mds_md *fst_lmm, *snd_lmm;
- struct lu_buf *fst_buf = &info->m
t
i_buf[0];
- struct lu_buf *snd_buf = &info->m
t
i_buf[1];
- struct lu_buf *fst_hsm_buf = &info->m
t
i_buf[2];
- struct lu_buf *snd_hsm_buf = &info->m
t
i_buf[3];
+ struct lu_buf *fst_buf = &info->m
d
i_buf[0];
+ struct lu_buf *snd_buf = &info->m
d
i_buf[1];
+ struct lu_buf *fst_hsm_buf = &info->m
d
i_buf[2];
+ struct lu_buf *snd_hsm_buf = &info->m
d
i_buf[3];
struct ost_id *saved_oi = NULL;
struct thandle *handle;
struct mdd_object *dom_o = NULL;
@@
-2400,8
+2449,8
@@
static int mdd_swap_layouts(const struct lu_env *env, struct md_object *obj1,
ENTRY;
- BUILD_BUG_ON(ARRAY_SIZE(info->m
t
i_buf) < 4);
- memset(info->m
ti_buf, 0, sizeof(info->mt
i_buf));
+ BUILD_BUG_ON(ARRAY_SIZE(info->m
d
i_buf) < 4);
+ memset(info->m
di_buf, 0, sizeof(info->md
i_buf));
/* we have to sort the 2 obj, so locking will always
* be in the same order, even in case of 2 concurrent swaps */
@@
-2540,7
+2589,7
@@
static int mdd_swap_layouts(const struct lu_env *env, struct md_object *obj1,
if (fst_lmm != NULL) {
struct ost_id temp_oi;
- saved_oi = &info->m
t
i_oa.o_oi;
+ saved_oi = &info->m
d
i_oa.o_oi;
mdd_get_lmm_oi(fst_lmm, saved_oi);
mdd_get_lmm_oi(snd_lmm, &temp_oi);
mdd_set_lmm_gen(fst_lmm, &snd_gen);
@@
-2668,13
+2717,17
@@
out_restore:
if (rc2 < 0)
goto do_lbug;
- ++steps;
- rc2 = mdd_xattr_hsm_replace(env, fst_o, fst_hsm_buf, handle);
- if (rc2 < 0)
- goto do_lbug;
+ if (flags & SWAP_LAYOUTS_MDS_HSM) {
+ ++steps;
+ rc2 = mdd_xattr_hsm_replace(env, fst_o, fst_hsm_buf,
+ handle);
+ if (rc2 < 0)
+ goto do_lbug;
- ++steps;
- rc2 = mdd_xattr_hsm_replace(env, snd_o, snd_hsm_buf, handle);
+ ++steps;
+ rc2 = mdd_xattr_hsm_replace(env, snd_o, snd_hsm_buf,
+ handle);
+ }
do_lbug:
if (rc2 < 0) {
@@
-2781,7
+2834,7
@@
mdd_layout_update_rdonly(const struct lu_env *env, struct mdd_object *obj,
struct md_layout_change *mlc, struct thandle *handle)
{
struct mdd_device *mdd = mdd_obj2mdd_dev(obj);
- struct lu_buf *som_buf = &mdd_env_info(env)->m
t
i_buf[1];
+ struct lu_buf *som_buf = &mdd_env_info(env)->m
d
i_buf[1];
struct lustre_som_attrs *som = &mlc->mlc_som;
int fl = 0;
int rc;
@@
-2809,6
+2862,12
@@
mdd_layout_update_rdonly(const struct lu_env *env, struct mdd_object *obj,
lustre_som_swab(som);
if (som->lsa_valid & SOM_FL_STRICT)
fl = LU_XATTR_REPLACE;
+
+ if (mlc->mlc_opc == MD_LAYOUT_WRITE &&
+ mlc->mlc_intent->li_extent.e_end > som->lsa_size) {
+ som->lsa_size = mlc->mlc_intent->li_extent.e_end + 1;
+ fl = LU_XATTR_REPLACE;
+ }
}
rc = mdd_declare_layout_change(env, mdd, obj, mlc, handle);
@@
-2871,6
+2930,9
@@
mdd_layout_update_write_pending(const struct lu_env *env,
struct thandle *handle)
{
struct mdd_device *mdd = mdd_obj2mdd_dev(obj);
+ struct lu_buf *som_buf = &mdd_env_info(env)->mdi_buf[1];
+ struct lustre_som_attrs *som = &mlc->mlc_som;
+ int fl = 0;
int rc;
ENTRY;
@@
-2883,8
+2945,25
@@
mdd_layout_update_write_pending(const struct lu_env *env,
* resync state. */
break;
case MD_LAYOUT_WRITE:
- /* legal race for concurrent write, the file state has been
- * changed by another client. */
+ /**
+ * legal race for concurrent write, the file state has been
+ * changed by another client. Or a jump over file size and
+ * write.
+ */
+ som_buf->lb_buf = som;
+ som_buf->lb_len = sizeof(*som);
+ rc = mdo_xattr_get(env, obj, som_buf, XATTR_NAME_SOM);
+ if (rc < 0 && rc != -ENODATA)
+ RETURN(rc);
+
+ if (rc > 0) {
+ lustre_som_swab(som);
+ if (mlc->mlc_intent->li_extent.e_end > som->lsa_size) {
+ som->lsa_size =
+ mlc->mlc_intent->li_extent.e_end + 1;
+ fl = LU_XATTR_REPLACE;
+ }
+ }
break;
default:
RETURN(-EBUSY);
@@
-2894,6
+2973,13
@@
mdd_layout_update_write_pending(const struct lu_env *env,
if (rc)
GOTO(out, rc);
+ if (fl) {
+ rc = mdd_declare_xattr_set(env, mdd, obj, som_buf,
+ XATTR_NAME_SOM, fl, handle);
+ if (rc)
+ GOTO(out, rc);
+ }
+
rc = mdd_trans_start(env, mdd, handle);
if (rc)
GOTO(out, rc);
@@
-2903,6
+2989,12
@@
mdd_layout_update_write_pending(const struct lu_env *env,
mdd_write_lock(env, obj, DT_TGT_CHILD);
rc = mdo_layout_change(env, obj, mlc, handle);
+ if (!rc && fl) {
+ som->lsa_valid = SOM_FL_STALE;
+ lustre_som_swab(som);
+ rc = mdo_xattr_set(env, obj, som_buf, XATTR_NAME_SOM,
+ fl, handle);
+ }
mdd_write_unlock(env, obj);
if (rc)
GOTO(out, rc);
@@
-2930,7
+3022,7
@@
mdd_object_update_sync_pending(const struct lu_env *env, struct mdd_object *obj,
struct md_layout_change *mlc, struct thandle *handle)
{
struct mdd_device *mdd = mdd_obj2mdd_dev(obj);
- struct lu_buf *som_buf = &mdd_env_info(env)->m
t
i_buf[1];
+ struct lu_buf *som_buf = &mdd_env_info(env)->m
d
i_buf[1];
int fl = 0;
int rc;
ENTRY;
@@
-3112,22
+3204,10
@@
void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
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)),
@@
-3221,7
+3301,7
@@
static int mdd_open(const struct lu_env *env, struct md_object *obj,
rc = mdd_open_sanity_check(env, mdd_obj, attr, open_flags,
spec->no_create);
- if ((rc == -EACCES) && (mdd->mdd_cl.mc_mask & BIT(CL_DN_OPEN)))
+ if ((rc == -EACCES) && (mdd->mdd_cl.mc_
current_
mask & BIT(CL_DN_OPEN)))
type = CL_DN_OPEN;
else if (rc != 0)
GOTO(out, rc);
@@
-3459,10
+3539,11
@@
out:
* this is not a big deal if we have a CL_CLOSE entry with no matching
* CL_OPEN. Plus Changelogs mask may not change often.
*/
- if (((!(mdd->mdd_cl.mc_mask & BIT(CL_OPEN)) &&
+ if (((!(mdd->mdd_cl.mc_
current_
mask & BIT(CL_OPEN)) &&
(open_flags & (MDS_FMODE_WRITE | MDS_OPEN_APPEND |
MDS_OPEN_TRUNC))) ||
- ((mdd->mdd_cl.mc_mask & BIT(CL_OPEN)) && last_close_by_uid)) &&
+ ((mdd->mdd_cl.mc_current_mask & BIT(CL_OPEN)) &&
+ last_close_by_uid)) &&
!(ma->ma_valid & MA_FLAGS && ma->ma_attr_flags & MDS_RECOV_OPEN)) {
if (handle == NULL) {
handle = mdd_trans_create(env, mdo2mdd(obj));
@@
-3510,89
+3591,96
@@
static int mdd_readpage_sanity_check(const struct lu_env *env,
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,