diff options
Diffstat (limited to 'libglusterfs/src/iatt.h')
| -rw-r--r-- | libglusterfs/src/iatt.h | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/libglusterfs/src/iatt.h b/libglusterfs/src/iatt.h index e67d714c2..60ae59047 100644 --- a/libglusterfs/src/iatt.h +++ b/libglusterfs/src/iatt.h @@ -1,20 +1,11 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ @@ -59,7 +50,6 @@ typedef struct { struct iatt { uint64_t ia_ino; /* inode number */ - uint64_t ia_gen; /* generation number */ uuid_t ia_gfid; uint64_t ia_dev; /* backing device ID */ ia_type_t ia_type; /* type of file */ @@ -104,6 +94,8 @@ struct iatt { #define IA_PROT_SGID(prot) ((prot).sgid == 1) #define IA_PROT_STCKY(prot) ((prot).sticky == 1) +#define IA_FILE_OR_DIR(t) (IA_ISREG(t) || IA_ISDIR(t)) + static inline uint32_t ia_major (uint64_t ia_dev) { @@ -121,7 +113,7 @@ ia_minor (uint64_t ia_dev) static inline uint64_t ia_makedev (uint32_t ia_maj, uint32_t ia_min) { - return ((((uint64_t) ia_maj) << 32) & ia_min); + return ((((uint64_t) ia_maj) << 32) | ia_min); } @@ -259,8 +251,6 @@ iatt_from_stat (struct iatt *iatt, struct stat *stat) iatt->ia_dev = stat->st_dev; iatt->ia_ino = stat->st_ino; - (void) iatt->ia_gen; - iatt->ia_type = ia_type_from_st_mode (stat->st_mode); iatt->ia_prot = ia_prot_from_st_mode (stat->st_mode); @@ -275,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); @@ -294,8 +302,6 @@ iatt_to_stat (struct iatt *iatt, struct stat *stat) stat->st_dev = iatt->ia_dev; stat->st_ino = iatt->ia_ino; - (void) iatt->ia_gen; - stat->st_mode = st_mode_from_ia (iatt->ia_prot, iatt->ia_type); stat->st_nlink = iatt->ia_nlink; |
