summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorAmar Tumballi <amarts@redhat.com>2012-07-14 08:25:56 +0530
committerVijay Bellur <vbellur@redhat.com>2012-08-16 23:58:13 -0700
commitb96e499e9e290547a655072fede969f51854e2d8 (patch)
tree6954cbeb26cd9dfdba2660d965efc707f2f93eec /libglusterfs/src
parent502c95bdfb35640fb424b37b080664e9c1639a86 (diff)
core: check for pre-allocated blocks in backend fs, fix it.
There is a possibility that the backend FS (like XFS) can allocate blocks beyond EOF for better performance reasons, which results in 'st_blocks' with higher values than what is consumed by the file descriptor. This would break few logic inside GlusterFS, like quota behavior etc, thus we need the exact number of blocks which are consumed by the file to the higher layers inside GlusterFS. Currently, this logic won't work for sparse files (ie, file with holes) Change-Id: Ied216733a8862e84f7da8386ae0a144f3f5cd5f2 BUG: 839589 Signed-off-by: Amar Tumballi <amarts@redhat.com> Reviewed-on: http://review.gluster.com/3671 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/iatt.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/libglusterfs/src/iatt.h b/libglusterfs/src/iatt.h
index eb916ad5edc..60ae5904703 100644
--- a/libglusterfs/src/iatt.h
+++ b/libglusterfs/src/iatt.h
@@ -265,6 +265,24 @@ iatt_from_stat (struct iatt *iatt, struct stat *stat)
iatt->ia_blksize = stat->st_blksize;
iatt->ia_blocks = stat->st_blocks;
+ /* There is a possibility that the backend FS (like XFS) can
+ allocate blocks beyond EOF for better performance reasons, which
+ results in 'st_blocks' with higher values than what is consumed by
+ the file descriptor. This would break few logic inside GlusterFS,
+ like quota behavior etc, thus we need the exact number of blocks
+ which are consumed by the file to the higher layers inside GlusterFS.
+ Currently, this logic won't work for sparse files (ie, file with
+ holes)
+ */
+ {
+ uint64_t maxblocks;
+
+ maxblocks = (iatt->ia_size + 511) / 512;
+
+ if (iatt->ia_blocks > maxblocks)
+ iatt->ia_blocks = maxblocks;
+ }
+
iatt->ia_atime = stat->st_atime;
iatt->ia_atime_nsec = ST_ATIM_NSEC (stat);