xfs: clean up xfs_set_maxicount & use in growfs
PATCH 1/1 xfs: clean up xfs_set_maxicount & use in growfs
xfs_set_maxicount() overflowed fairly easily for large filesystems and large maxicount; we started out by multiplying dblocks by the percentage, *then* dividing by 100, and never checked for an overflow. The calculations were also, IMHO, a little hard to follow.
I rewrote it using mult_frac (so handy!) and rounddown, to do a nice no-overflow, no-precision-loss multiplication by (%/100), then round down to the inode allocation unit. Then check to see if we've overflowed the u64, and set to XFS_MAXINUMBER if so.
Also, growfs open-coded the setting of maxicount; call the handy helper instead.
This slightly changes growfs behavior, because we weren't rounding to the allocation multiple in that code. I checked that we get the same answers for non-growfs cases by running 100 mkfs.xfs's with imaxpct from 1 to 100, and it gives the same inode count in all cases.
Thanks to dchinner for pointing out that this could use fixing.
---
Ok Brian, have at it. ;)
fs/xfs/xfs_fsops.c +1 -6
@@ -471,12 +471,7 @@ xfs_growfs_data_private(/* New allocation groups fully initialized, so update mount struct */ if (nagimax) mp->m_maxagi = nagimax; -if (mp->m_sb.sb_imax_pct) { -__uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct; -do_div (icount,100 ); - mp->m_maxicount = icount << mp->m_sb.sb_inopblog; - }else - mp->m_maxicount =0 ; +xfs_set_maxicount (mp);xfs_set_low_space_thresholds (mp);/* update secondary superblocks. */
fs/xfs/xfs_mount.c +8 -8
@@ -419,24 +419,24 @@ xfs_update_alignment(xfs_mount_t *mp) }/* -* Set the maximum inode count for this filesystem +* Set the maximum inode count for this filesystem based on sb_imax_pct */ -STATIC void +void xfs_set_maxicount (xfs_mount_t *mp) {xfs_sb_t *sbp = &(mp->m_sb); -__uint64_t icount; +__uint64_t iblocks;if (sbp->sb_imax_pct) {/* * Make sure the maximum inode count is a multiple * of the units we allocate inodes in. */ - icount = sbp->sb_dblocks * sbp->sb_imax_pct; -do_div (icount,100 ); -do_div (icount, mp->m_ialloc_blks); - mp->m_maxicount = (icount * mp->m_ialloc_blks) << - sbp->sb_inopblog; + iblocks =mult_frac (sbp->sb_dblocks, sbp->sb_imax_pct,100 ); + iblocks =rounddown (iblocks, mp->m_ialloc_blks); + mp->m_maxicount = iblocks << sbp->sb_inopblog; +if (mp->m_maxicount < iblocks) + mp->m_maxicount =XFS_MAXINUMBER ; }else { mp->m_maxicount =0 ; }
fs/xfs/xfs_mount.h +1 -0
@@ -388,6 +388,7 @@ extern int xfs_mod_incore_sb_batch(xfs_mount_t *, xfs_mod_sb_t *,extern int xfs_mount_log_sb (xfs_mount_t *,__int64_t );extern struct xfs_buf *xfs_getsb (xfs_mount_t *,int );extern int xfs_readsb (xfs_mount_t *,int ); +void xfs_set_maxicount (xfs_mount_t *mp);extern void xfs_freesb (xfs_mount_t *);extern int xfs_fs_writable (xfs_mount_t *);extern int xfs_sb_validate_fsb_count (struct xfs_sb *,__uint64_t );
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 5 lines · Eric Sandeen
xfs_set_maxicount()overflowed fairly easily for large filesystems and large maxicount; we started out by multiplying dblocks by the percentage, *then* dividing by 100, and never checked for an overflow. The calculations were also, IMHO, a little hard to follow.
Would be useful to get this test case into xfstests..
fs/xfs/xfs_mount.c xfs_update_alignment(xfs_mount_t *mp) · line 428
Quoted 7 lines
fs/xfs/xfs_mount.c +2
-2-STATIC void +void xfs_set_maxicount (xfs_mount_t *mp) {xfs_sb_t *sbp = &(mp->m_sb); -__uint64_t icount; +__uint64_t iblocks;
Seems like this could move into the if clause below.
fs/xfs/xfs_mount.h extern int xfs_mod_incore_sb_batch(xfs_mount_t *, xfs_mod_sb_t *, · line 394
Quoted 8 lines
fs/xfs/xfs_mount.h +1
-0@@ -388,6 +388,7 @@ extern int xfs_mod_incore_sb_batch(xfs_mount_t *, xfs_mod_sb_t *,extern int xfs_mount_log_sb (xfs_mount_t *,__int64_t );extern struct xfs_buf *xfs_getsb (xfs_mount_t *,int );extern int xfs_readsb (xfs_mount_t *,int ); +void xfs_set_maxicount (xfs_mount_t *mp);extern void xfs_freesb (xfs_mount_t *);extern int xfs_fs_writable (xfs_mount_t *);extern int xfs_sb_validate_fsb_count (struct xfs_sb *,__uint64_t );
A missing extern while all other prototypes around it have one seems rather odd.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Eric Sandeen
xfs_set_maxicount()overflowed fairly easily for large filesystems and large maxicount; we started out by multiplying dblocks by the percentage, *then* dividing by 100, and never checked for an overflow. The calculations were also, IMHO, a little hard to follow.Would be useful to get this test case into xfstests..
Your'e bot, aren't you. ;)
yeah you're right. I went down this path by starting a testcase for 3-patches-ago, and got here. That one can be sent soon, and sure, it'd be worth doing this too.
Quoted 10 lines
fs/xfs/xfs_mount.c xfs_update_alignment(xfs_mount_t *mp) · line 428
Quoted 7 lines
fs/xfs/xfs_mount.c +2
-2-STATIC void +void xfs_set_maxicount (xfs_mount_t *mp) {xfs_sb_t *sbp = &(mp->m_sb); -__uint64_t icount; +__uint64_t iblocks;Seems like this could move into the if clause below.
Quoted 11 lines
fs/xfs/xfs_mount.h extern int xfs_mod_incore_sb_batch(xfs_mount_t *, xfs_mod_sb_t *, · line 394
Quoted 8 lines
fs/xfs/xfs_mount.h +1
-0@@ -388,6 +388,7 @@ extern int xfs_mod_incore_sb_batch(xfs_mount_t *, xfs_mod_sb_t *,extern int xfs_mount_log_sb (xfs_mount_t *,__int64_t );extern struct xfs_buf *xfs_getsb (xfs_mount_t *,int );extern int xfs_readsb (xfs_mount_t *,int ); +void xfs_set_maxicount (xfs_mount_t *mp);extern void xfs_freesb (xfs_mount_t *);extern int xfs_fs_writable (xfs_mount_t *);extern int xfs_sb_validate_fsb_count (struct xfs_sb *,__uint64_t );A missing extern while all other prototypes around it have one seems rather odd.
Sure does!
-Eric
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Eric Sandeen
xfs_set_maxicount()overflowed fairly easily for large filesystems and large maxicount; we started out by multiplying dblocks by the percentage, *then* dividing by 100, and never checked for an overflow. The calculations were also, IMHO, a little hard to follow.Would be useful to get this test case into xfstests..
Ok so I was going on Dave's assertion about that. ;)
To overflow, we'd need dblocks * 100 to be > 2^64-1:
so dblocks would need to be > (2^64-1)/100
for 4k blocks that's 655 exabytes. Maybe not so possible after all ;)
Dave, maybe just removing the open-code is enough here.
-Eric
Quoted 22 lines
fs/xfs/xfs_mount.c xfs_update_alignment(xfs_mount_t *mp) · line 428
Quoted 7 lines
fs/xfs/xfs_mount.c +2
-2-STATIC void +void xfs_set_maxicount (xfs_mount_t *mp) {xfs_sb_t *sbp = &(mp->m_sb); -__uint64_t icount; +__uint64_t iblocks;Seems like this could move into the if clause below.
fs/xfs/xfs_mount.h extern int xfs_mod_incore_sb_batch(xfs_mount_t *, xfs_mod_sb_t *, · line 394
Quoted 8 lines
fs/xfs/xfs_mount.h +1
-0@@ -388,6 +388,7 @@ extern int xfs_mod_incore_sb_batch(xfs_mount_t *, xfs_mod_sb_t *,extern int xfs_mount_log_sb (xfs_mount_t *,__int64_t );extern struct xfs_buf *xfs_getsb (xfs_mount_t *,int );extern int xfs_readsb (xfs_mount_t *,int ); +void xfs_set_maxicount (xfs_mount_t *mp);extern void xfs_freesb (xfs_mount_t *);extern int xfs_fs_writable (xfs_mount_t *);extern int xfs_sb_validate_fsb_count (struct xfs_sb *,__uint64_t );A missing extern while all other prototypes around it have one seems rather odd.
Quoted 5 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 10 lines · Eric Sandeen
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Eric Sandeen
xfs_set_maxicount()overflowed fairly easily for large filesystems and large maxicount; we started out by multiplying dblocks by the percentage, *then* dividing by 100, and never checked for an overflow. The calculations were also, IMHO, a little hard to follow.Would be useful to get this test case into xfstests..
Quoted 7 lines
Ok so I was going on Dave's assertion about that. ;)
To overflow, we'd need dblocks * 100 to be > 2^64-1:
so dblocks would need to be > (2^64-1)/100
for 4k blocks that's 655 exabytes. Maybe not so possible after all ;)
Until the block count is corrupted by fsfuzzer? ;)
Quoted 1 line
Dave, maybe just removing the open-code is enough here.
Sure, but I still like the conversion to use mult_frac....
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 17 lines · Dave Chinner
Quoted 16 lines · Eric Sandeen
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Eric Sandeen
xfs_set_maxicount()overflowed fairly easily for large filesystems and large maxicount; we started out by multiplying dblocks by the percentage, *then* dividing by 100, and never checked for an overflow. The calculations were also, IMHO, a little hard to follow.Would be useful to get this test case into xfstests..
Ok so I was going on Dave's assertion about that. ;)
To overflow, we'd need dblocks * 100 to be > 2^64-1:
so dblocks would need to be > (2^64-1)/100
Quoted 7 lines
Quoted 1 line
for 4k blocks that's 655 exabytes. Maybe not so possible after all ;)
Until the block count is corrupted by fsfuzzer? ;)
Quoted 1 line
Dave, maybe just removing the open-code is enough here.
Sure, but I still like the conversion to use
mult_frac....
Ok, I do too. Just a bit resistant to fixing what ain't broke. I'll see if I can write up a test to be sure we're doing sane things statfs/growfs with the change.
-Eric
Quoted 4 lines
Cheers,
Dave.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs