From b1a5fa55695f497952264e35a9c8eb2bbf1ec4c3 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Thu, 5 Jul 2012 08:45:52 +0530 Subject: 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: 817343 Signed-off-by: Amar Tumballi Reviewed-on: http://review.gluster.com/3631 Tested-by: Gluster Build System Reviewed-by: Jeff Darcy Reviewed-by: Raghavendra Bhat Reviewed-by: Anand Avati --- libglusterfs/src/iatt.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/iatt.h b/libglusterfs/src/iatt.h index eb916ad5e..60ae59047 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); -- cgit