public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: xfs@oss.sgi.com
Subject: [PATCH 5/8] xfs: ensure f_ffree returned by statfs() is non-negative
Date: Wed, 18 Aug 2010 21:36:16 +1000	[thread overview]
Message-ID: <1282131379-29932-6-git-send-email-david@fromorbit.com> (raw)
In-Reply-To: <1282131379-29932-1-git-send-email-david@fromorbit.com>

From: Stuart Brodsky <sbrodsky@sgi.com>

Because of delayed updates to sb_icount field in the super block, it
is possible to allocate over maxicount number of inodes.  This
causes the arithmetic to calculate a negative number of free inodes
in user commands like df or stat -f.

Since maxicount is a somewhat arbitrary number, a slight over
allocation is not critical but user commands should be displayed as
0 or greater and never go negative.  To do this the value in the
stats buffer f_ffree is capped to never go negative.

[ Modified to use max_t as per Christoph's comment. ]

Signed-off-by: Stu Brodsky <sbrodsky@sgi.com>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 fs/xfs/linux-2.6/xfs_super.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index d09cd14..a4e0797 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -1226,6 +1226,7 @@ xfs_fs_statfs(
 	struct xfs_inode	*ip = XFS_I(dentry->d_inode);
 	__uint64_t		fakeinos, id;
 	xfs_extlen_t		lsize;
+	__int64_t		ffree;
 
 	statp->f_type = XFS_SB_MAGIC;
 	statp->f_namelen = MAXNAMELEN - 1;
@@ -1249,7 +1250,11 @@ xfs_fs_statfs(
 		statp->f_files = min_t(typeof(statp->f_files),
 					statp->f_files,
 					mp->m_maxicount);
-	statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
+
+	/* make sure statp->f_ffree does not underflow */
+	ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
+	statp->f_ffree = max_t(__int64_t, ffree, 0);
+
 	spin_unlock(&mp->m_sb_lock);
 
 	if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) ||
-- 
1.7.1

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  parent reply	other threads:[~2010-08-18 11:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-18 11:36 [PATCH 0/8] xfs: current pending patches Dave Chinner
2010-08-18 11:36 ` [PATCH 1/8] xfs: unlock items before allowing the CIL to commit Dave Chinner
2010-08-18 11:36 ` [PATCH 2/8] xfs: ensure we mark all inodes in a freed cluster XFS_ISTALE Dave Chinner
2010-08-19 12:06   ` Christoph Hellwig
2010-08-18 11:36 ` [PATCH 3/8] xfs: Reduce log force overhead for delayed logging Dave Chinner
2010-08-18 11:36 ` [PATCH 4/8] xfs: dummy transactions should not dirty VFS state Dave Chinner
2010-08-18 12:04   ` Christoph Hellwig
2010-08-18 11:36 ` Dave Chinner [this message]
2010-08-18 12:05   ` [PATCH 5/8] xfs: ensure f_ffree returned by statfs() is non-negative Christoph Hellwig
2010-08-18 11:36 ` [PATCH 6/8] xfs: fix untrusted inode number lookup Dave Chinner
2010-08-18 11:36 ` [PATCH 7/8] xfs: use range primitives for xfs page cache operations Dave Chinner
2010-08-18 11:36 ` [PATCH 8/8] xfs: Introduce XFS_IOC_ZERO_RANGE Dave Chinner

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=1282131379-29932-6-git-send-email-david@fromorbit.com \
    --to=david@fromorbit.com \
    --cc=xfs@oss.sgi.com \
    /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