linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chengguang Xu <cgxu519@gmx.com>
To: linux-xfs@vger.kernel.org
Cc: darrick.wong@oracle.com, Chengguang Xu <cgxu519@gmx.com>
Subject: [RFC][PATCH] xfs: adjust size/used/avail information for quota-df
Date: Fri,  9 Mar 2018 21:15:55 +0800	[thread overview]
Message-ID: <1520601355-180600-1-git-send-email-cgxu519@gmx.com> (raw)

In order to more accurately reflect size/used/avail information
for quota-df, slightly adjust related counting logic.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---

Hello folks,

Recently I’m testing  project quota  for our container users and found
sometimes the result of df command could not exactly represent
block/inode usage amount. So I checked  the logic in function xfs_qm_statvfs()
and I think it might be better if slightly adjusting the counting logic.
What do you think?

Terms:
# Size(F)   - The size field  in df result of filesystem
# Size(Q) - The size field of in df result of pquota-dir
# Used(F) - The used field  in df result of filesystem
# Used(Q) - The used field  in df result of pquota-dir
# Avail(F)  - The avail field  in df result of filesystem
# Avail(Q)  - The avail field  in df result of pquota-dir
# Used(A) - Actual used

Problems that I found.
1) Avail(Q) can be higher than Avail(F)
2) Used(A) can be higher than Used(Q)


 fs/xfs/xfs_qm_bhv.c | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/fs/xfs/xfs_qm_bhv.c b/fs/xfs/xfs_qm_bhv.c
index 2be6d27..cb2e6c9 100644
--- a/fs/xfs/xfs_qm_bhv.c
+++ b/fs/xfs/xfs_qm_bhv.c
@@ -38,21 +38,41 @@
 	limit = dqp->q_core.d_blk_softlimit ?
 		be64_to_cpu(dqp->q_core.d_blk_softlimit) :
 		be64_to_cpu(dqp->q_core.d_blk_hardlimit);
-	if (limit && statp->f_blocks > limit) {
-		statp->f_blocks = limit;
-		statp->f_bfree = statp->f_bavail =
-			(statp->f_blocks > dqp->q_res_bcount) ?
-			 (statp->f_blocks - dqp->q_res_bcount) : 0;
+
+	if (limit) {
+		if (limit > dqp->q_res_bcount + statp->f_bavail)
+			statp->f_blocks = dqp->q_res_bcount + statp->f_bavail;
+		else
+			statp->f_blocks = limit;
+	} else {
+		statp->f_blocks = dqp->q_res_bcount + statp->f_bavail;
+	}
+
+	if (dqp->q_res_bcount >= statp->f_blocks) {
+		statp->f_blocks = dqp->q_res_bcount;
+		statp->f_bfree = statp->f_bavail = 0;
+	} else {
+		statp->f_bfree = statp->f_bavail = statp->f_blocks - dqp->q_res_bcount;
 	}
 
 	limit = dqp->q_core.d_ino_softlimit ?
 		be64_to_cpu(dqp->q_core.d_ino_softlimit) :
 		be64_to_cpu(dqp->q_core.d_ino_hardlimit);
-	if (limit && statp->f_files > limit) {
-		statp->f_files = limit;
-		statp->f_ffree =
-			(statp->f_files > dqp->q_res_icount) ?
-			 (statp->f_ffree - dqp->q_res_icount) : 0;
+
+	if (limit) {
+		if (limit > dqp->q_res_icount + statp->f_ffree)
+			statp->f_files = dqp->q_res_icount + statp->f_ffree;
+		else
+			statp->f_files = limit;
+	} else {
+		statp->f_files = dqp->q_res_icount + statp->f_ffree;
+	}
+
+	if (dqp->q_res_icount >= statp->f_files) {
+		statp->f_files = dqp->q_res_icount;
+		statp->f_ffree = 0;
+	} else {
+		statp->f_ffree = statp->f_files - dqp->q_res_icount;
 	}
 }
 
-- 
1.8.3.1


             reply	other threads:[~2018-03-09 13:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09 13:15 Chengguang Xu [this message]
2018-03-15 14:25 ` [RFC][PATCH] xfs: adjust size/used/avail information for quota-df Brian Foster
2018-03-20 14:49   ` cgxu519
2018-03-20 17:41     ` Eric Sandeen
2018-03-20 19:18       ` Brian Foster
2018-03-21  3:36         ` cgxu519
2018-03-21 11:51           ` Brian Foster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1520601355-180600-1-git-send-email-cgxu519@gmx.com \
    --to=cgxu519@gmx.com \
    --cc=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).