[PATCH 29/32] libxfs: work around do_div() not handling 32 bit numerators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Dave Chinner <dchinner@xxxxxxxxxx>

The libxfs dquot buffer code uses do_div() with a 32 bit numerator.
This gives incorrect results as do_div() passes the numerator by
reference as a pointer to a 64 bit value. Hence it does the division
using 32 bits of garbage gives the wrong result. The kernel code
handles 32 bit numerators just fine, so this patch is a temporary
workaround in the dquot buffer code until we fix do_div() to handle
32 bit numerators correctly.

Signed-off-by: Dave Chinner <dchinner@xxxxxxxxxx>
---
 libxfs/xfs_dquot_buf.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/libxfs/xfs_dquot_buf.c b/libxfs/xfs_dquot_buf.c
index 620d9d3..ce6b09c 100644
--- a/libxfs/xfs_dquot_buf.c
+++ b/libxfs/xfs_dquot_buf.c
@@ -18,18 +18,28 @@
  */
 #include "xfs.h"
 
+/*
+ * XXX: the userspace implementation of the do_div() macro does not handle 32
+ * bit numerators properly as it passes it by reference as a pointer to a 64 bit
+ * variable and dereferences it as such. Hence the result is way, way off
+ * because it uses 32 bits of garbage for the upper 32 bits of the numerator.
+ *
+ * This is being left here as a reminder that we need to fix do_div() in
+ * userspace as every time we do a libxfs kernel/userspace diff we'll see this
+ * comment.
+ */
 int
 xfs_calc_dquots_per_chunk(
 	struct xfs_mount	*mp,
 	unsigned int		nbblks)	/* basic block units */
 {
-	unsigned int	ndquots;
+	uint64_t	ndquots;
 
 	ASSERT(nbblks > 0);
 	ndquots = BBTOB(nbblks);
 	do_div(ndquots, sizeof(xfs_dqblk_t));
 
-	return ndquots;
+	return (int)ndquots;
 }
 
 /*
-- 
1.8.3.2

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




[Index of Archives]     [Linux XFS Devel]     [Linux Filesystem Development]     [Filesystem Testing]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux