Skip to content

Commit fadc0d8

Browse files
kdavechrismason-xx
authored andcommitted
btrfs: fix stat blocks accounting
Round inode bytes and delalloc bytes up to real blocksize before converting to sector size. Otherwise eg. files smaller than 512 are reported with zero blocks due to incorrect rounding. Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 52621cb commit fadc0d8

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎fs/btrfs/inode.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6794,11 +6794,13 @@ static int btrfs_getattr(struct vfsmount *mnt,
67946794
struct dentry *dentry, struct kstat *stat)
67956795
{
67966796
struct inode *inode = dentry->d_inode;
6797+
u32 blocksize = inode->i_sb->s_blocksize;
6798+
67976799
generic_fillattr(inode, stat);
67986800
stat->dev = BTRFS_I(inode)->root->anon_dev;
67996801
stat->blksize = PAGE_CACHE_SIZE;
6800-
stat->blocks = (inode_get_bytes(inode) +
6801-
BTRFS_I(inode)->delalloc_bytes) >> 9;
6802+
stat->blocks = (ALIGN(inode_get_bytes(inode), blocksize) +
6803+
ALIGN(BTRFS_I(inode)->delalloc_bytes, blocksize)) >> 9;
68026804
return 0;
68036805
}
68046806

0 commit comments

Comments
 (0)