From d387061f1d9a4c169b67567d51b6ac42a82de490 Mon Sep 17 00:00:00 2001 From: bwzhou <bwzhou> Date: Fri, 9 May 2008 17:29:26 +0000 Subject: [PATCH] Branch HEAD b=14219 r=adilger, shadow use obd_punch_rqset() instead of obd_setattr() to change size --- lustre/mdd/mdd_lov.c | 7 ++++--- lustre/obdfilter/filter.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lustre/mdd/mdd_lov.c b/lustre/mdd/mdd_lov.c index b3ecae21f7..cb7a68bbc6 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 59e533e380..44addacb58 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)) -- GitLab