diff --git a/lustre/mdd/mdd_lov.c b/lustre/mdd/mdd_lov.c index b3ecae21f7c6dae6e142b289086a5399f5ded166..cb7a68bbc6de89d65ed8440c76787e9a70a79234 100644 --- a/lustre/mdd/mdd_lov.c +++ b/lustre/mdd/mdd_lov.c @@ -457,8 +457,6 @@ int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd, memset(oinfo, 0, sizeof(*oinfo)); - oa->o_size = la->la_size; - /* When setting attr to ost, FLBKSZ is not needed. */ oa->o_valid &= ~OBD_MD_FLBLKSZ; obdo_from_la(oa, la, OBD_MD_FLTYPE | OBD_MD_FLATIME | @@ -476,10 +474,13 @@ int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd, oinfo->oi_md = lsm; oinfo->oi_capa = mdo_capa_get(env, child, NULL, CAPA_OPC_MDS_DEFAULT); + oinfo->oi_policy.l_extent.start = la->la_size; + oinfo->oi_policy.l_extent.end = OBD_OBJECT_EOF; + if (IS_ERR(oinfo->oi_capa)) oinfo->oi_capa = NULL; - rc = obd_setattr(lov_exp, oinfo, oti); + rc = obd_punch_rqset(lov_exp, oinfo, oti); capa_put(oinfo->oi_capa); if (rc) { CERROR("Error setting attrs for "DFID": rc %d\n", diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index 59e533e3801e4345527953e668e7e0750f795776..44addacb589e9bf1621f88c470eaa8e547871a7f 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -3134,6 +3134,26 @@ int filter_setattr(struct obd_export *exp, struct obd_info *oinfo, if (rc) RETURN(rc); + /* This would be very bad - accidentally truncating a file when + * changing the time or similar - bug 12203. */ + if (oinfo->oi_oa->o_valid & OBD_MD_FLSIZE && + oinfo->oi_policy.l_extent.end != OBD_OBJECT_EOF) { + static char mdsinum[48]; + + if (oinfo->oi_oa->o_valid & OBD_MD_FLFID) + snprintf(mdsinum, sizeof(mdsinum) - 1, + " of inode "LPU64"/%u", oinfo->oi_oa->o_fid, + oinfo->oi_oa->o_generation); + else + mdsinum[0] = '\0'; + + CERROR("%s: setattr from %s trying to truncate objid "LPU64 + " %s\n", + exp->exp_obd->obd_name, obd_export_nid2str(exp), + oinfo->oi_oa->o_id, mdsinum); + RETURN(-EPERM); + } + dentry = __filter_oa2dentry(exp->exp_obd, oinfo->oi_oa, __FUNCTION__, 1); if (IS_ERR(dentry))