Whamcloud - gitweb
Branch HEAD
authorbwzhou <bwzhou>
Fri, 9 May 2008 17:29:26 +0000 (17:29 +0000)
committerbwzhou <bwzhou>
Fri, 9 May 2008 17:29:26 +0000 (17:29 +0000)
b=14219
r=adilger, shadow

use obd_punch_rqset() instead of obd_setattr() to change size

lustre/mdd/mdd_lov.c
lustre/obdfilter/filter.c

index b3ecae2..cb7a68b 100644 (file)
@@ -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",
index 59e533e..44addac 100644 (file)
@@ -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))