diff mbox

[5/5] Btrfs: self-test: fix extent buffer bitmap test fail on BE system

Message ID 201605270701.u4R6xUai016007@mx0a-001b2d01.pphosted.com (mailing list archive)
State New, archived
Headers show

Commit Message

Feifei Xu May 27, 2016, 7 a.m. UTC
In __test_eb_bitmaps(), we write random data to a bitmap. Then copy
the bitmap to another bitmap that resides inside an extent buffer.
Later we verify the values of corresponding bits in the bitmap and the
bitmap inside the extent buffer. However, extent_buffer_test_bit()
reads in byte granularity while test_bit() reads in unsigned long
granularity. Hence we end up comparing wrong bits on big-endian
systems such as ppc64. This commit fixes the issue by reading the
bitmap in byte granularity.

Reviewed-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: Feifei Xu <xufeifei@linux.vnet.ibm.com>
---
 fs/btrfs/tests/extent-io-tests.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

David Sterba May 27, 2016, 6:55 p.m. UTC | #1
On Fri, May 27, 2016 at 03:00:38PM +0800, Feifei Xu wrote:
> In __test_eb_bitmaps(), we write random data to a bitmap. Then copy
> the bitmap to another bitmap that resides inside an extent buffer.
> Later we verify the values of corresponding bits in the bitmap and the
> bitmap inside the extent buffer. However, extent_buffer_test_bit()
> reads in byte granularity while test_bit() reads in unsigned long
> granularity. Hence we end up comparing wrong bits on big-endian
> systems such as ppc64. This commit fixes the issue by reading the
> bitmap in byte granularity.
> 
> Reviewed-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
> Signed-off-by: Feifei Xu <xufeifei@linux.vnet.ibm.com>
> ---
>  fs/btrfs/tests/extent-io-tests.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c
> index b06b13a..d33f28f 100644
> --- a/fs/btrfs/tests/extent-io-tests.c
> +++ b/fs/btrfs/tests/extent-io-tests.c
> @@ -275,6 +275,16 @@ out:
>  	return ret;
>  }
>  
> +/**
> + * test_bit_in_byte - Determine whether a bit is set in a byte
> + * @nr: bit number to test
> + * @addr: Address to start counting from
> + */
> +static inline int test_bit_in_byte(int nr, const u8 *addr)
> +{
> +	return 1UL & (addr[nr/BITS_PER_BYTE] >> (nr & (BITS_PER_BYTE-1)));

minor nit:

	return 1UL & (addr[nr / BITS_PER_BYTE] >> (nr & (BITS_PER_BYTE - 1)));

otherwise looks ok.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c
index b06b13a..d33f28f 100644
--- a/fs/btrfs/tests/extent-io-tests.c
+++ b/fs/btrfs/tests/extent-io-tests.c
@@ -275,6 +275,16 @@  out:
 	return ret;
 }
 
+/**
+ * test_bit_in_byte - Determine whether a bit is set in a byte
+ * @nr: bit number to test
+ * @addr: Address to start counting from
+ */
+static inline int test_bit_in_byte(int nr, const u8 *addr)
+{
+	return 1UL & (addr[nr/BITS_PER_BYTE] >> (nr & (BITS_PER_BYTE-1)));
+}
+
 static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb,
 			     unsigned long len)
 {
@@ -339,7 +349,7 @@  static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb,
 	for (i = 0; i < len * BITS_PER_BYTE; i++) {
 		int bit, bit1;
 
-		bit = !!test_bit(i, bitmap);
+		bit = !!test_bit_in_byte(i, (u8 *)bitmap);
 		bit1 = !!extent_buffer_test_bit(eb, 0, i);
 		if (bit1 != bit) {
 			test_msg("Testing bit pattern failed\n");