Skip to content

Commit 8e55ba8

Browse files
kotreshhridryomov
authored andcommitted
ceph: Fix incorrect statfs report for small quota
Problem: The statfs reports incorrect free/available space for quota less then CEPH_BLOCK size (4M). Solution: For quota less than CEPH_BLOCK size, smaller block size of 4K is used. But if quota is less than 4K, it is decided to go with binary use/free of 4K block. For quota size less than 4K size, report the total=used=4K,free=0 when quota is full and total=free=4K,used=0 otherwise. Signed-off-by: Kotresh HR <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent adbed05 commit 8e55ba8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

fs/ceph/quota.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,24 @@ bool ceph_quota_update_statfs(struct ceph_fs_client *fsc, struct kstatfs *buf)
494494
if (ci->i_max_bytes) {
495495
total = ci->i_max_bytes >> CEPH_BLOCK_SHIFT;
496496
used = ci->i_rbytes >> CEPH_BLOCK_SHIFT;
497+
/* For quota size less than 4MB, use 4KB block size */
498+
if (!total) {
499+
total = ci->i_max_bytes >> CEPH_4K_BLOCK_SHIFT;
500+
used = ci->i_rbytes >> CEPH_4K_BLOCK_SHIFT;
501+
buf->f_frsize = 1 << CEPH_4K_BLOCK_SHIFT;
502+
}
497503
/* It is possible for a quota to be exceeded.
498504
* Report 'zero' in that case
499505
*/
500506
free = total > used ? total - used : 0;
507+
/* For quota size less than 4KB, report the
508+
* total=used=4KB,free=0 when quota is full
509+
* and total=free=4KB, used=0 otherwise */
510+
if (!total) {
511+
total = 1;
512+
free = ci->i_max_bytes > ci->i_rbytes ? 1 : 0;
513+
buf->f_frsize = 1 << CEPH_4K_BLOCK_SHIFT;
514+
}
501515
}
502516
spin_unlock(&ci->i_ceph_lock);
503517
if (total) {

fs/ceph/super.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* large volume sizes on 32-bit machines. */
3333
#define CEPH_BLOCK_SHIFT 22 /* 4 MB */
3434
#define CEPH_BLOCK (1 << CEPH_BLOCK_SHIFT)
35+
#define CEPH_4K_BLOCK_SHIFT 12 /* 4 KB */
3536

3637
#define CEPH_MOUNT_OPT_CLEANRECOVER (1<<1) /* auto reonnect (clean mode) after blocklisted */
3738
#define CEPH_MOUNT_OPT_DIRSTAT (1<<4) /* `cat dirname` for stats */

0 commit comments

Comments
 (0)