[PATCH] Fix hugetlbfs_statfs() reporting of block limits

Currently, if a hugetlbfs is mounted without limits (the default), statfs()
will return -1 for max/free/used blocks. This does not appear to be in
line with normal convention: simple_statfs() and shmem_statfs() both return
0 in similar cases. Worse, it confuses the translation logic in
put_compat_statfs(), causing it to return -EOVERFLOW on such a mount.

This patch alters hugetlbfs_statfs() to return 0 for max/free/used blocks
on a mount without limits. Note that we need the test in the patch below,
rather than just using 0 in the sbinfo structure, because the -1 marked in
the free blocks field is used internally to tell the

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by David Gibson and committed by Linus Torvalds 74a8a65c 86e07ce7

+8 -4
+8 -4
fs/hugetlbfs/inode.c
··· 512 buf->f_bsize = HPAGE_SIZE; 513 if (sbinfo) { 514 spin_lock(&sbinfo->stat_lock); 515 - buf->f_blocks = sbinfo->max_blocks; 516 - buf->f_bavail = buf->f_bfree = sbinfo->free_blocks; 517 - buf->f_files = sbinfo->max_inodes; 518 - buf->f_ffree = sbinfo->free_inodes; 519 spin_unlock(&sbinfo->stat_lock); 520 } 521 buf->f_namelen = NAME_MAX;
··· 512 buf->f_bsize = HPAGE_SIZE; 513 if (sbinfo) { 514 spin_lock(&sbinfo->stat_lock); 515 + /* If no limits set, just report 0 for max/free/used 516 + * blocks, like simple_statfs() */ 517 + if (sbinfo->max_blocks >= 0) { 518 + buf->f_blocks = sbinfo->max_blocks; 519 + buf->f_bavail = buf->f_bfree = sbinfo->free_blocks; 520 + buf->f_files = sbinfo->max_inodes; 521 + buf->f_ffree = sbinfo->free_inodes; 522 + } 523 spin_unlock(&sbinfo->stat_lock); 524 } 525 buf->f_namelen = NAME_MAX;