From patchwork Fri Jul 15 19:12:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9232475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9855260868 for ; Fri, 15 Jul 2016 19:13:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88D6527D5D for ; Fri, 15 Jul 2016 19:13:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DCEE27F86; Fri, 15 Jul 2016 19:13:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D99A227D5D for ; Fri, 15 Jul 2016 19:13:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751379AbcGOTNA (ORCPT ); Fri, 15 Jul 2016 15:13:00 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:35836 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751234AbcGOTM7 (ORCPT ); Fri, 15 Jul 2016 15:12:59 -0400 Received: by mail-pf0-f176.google.com with SMTP id c2so44061976pfa.2 for ; Fri, 15 Jul 2016 12:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=Bd8S3BEwXdSlOI8YcbvgOS2CPbAIDh1JjiBO6LcZbGU=; b=v+/E1XxA2bNxzHbBYWf7TuSuZMOKouJgf9IFWDh53efut995W62aXoO3BTVz6elet1 63rLPtmFATB3lMc659KBl9BWKicw/rIL2sxE6V948nnlxGo4FDRUip/XOwjMOpLy3Piv qz8GRenlb8PLW2+cukD1DdFZ+AkYbUqZRBgqxWVONzh016GI/0UQzCzSGbfM8kZB1iPn 6s1xzEKvvlMbganZEqB68VUc4onkcAs7dJWqdbrSzpBmz5SJSJTBDeShMdBj/Gqrk3He 3h+PnyGAD/JCiqcBurnmSeOuzdc5uaibXnUUSm9Qc3KRItHBcFHyWFlep7WfqwTDv5tH DH7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Bd8S3BEwXdSlOI8YcbvgOS2CPbAIDh1JjiBO6LcZbGU=; b=mKroKddjck4kyrER35kVTl/u4n2nIhWBhhDF7Pgy3Yr1JF03XVzYobxyDumPhQrCjV 41t062UCArCCLuvEFfPq1TBrjQK5Or8gKDy5wZiEwo6Agh25cpEqHRrAYB2mKbCwIsG3 fM03L1c4mA5SVAliuRy7KOEQZcWFoU/Z+g+gD47URG91e3vG8OgRKPgLUIkoada+yxMc gVJu3M+p3E1lc2wxGLaEzR8L1pR7FPdNVO+rXLc/ZwmgZqTObJWXVXb6GMmowPkDejqf 8ZpWmB71/Ln4+7FBUqEOCRiA36xhACpFVqE2r1dnRG9wzboMHipbvkHZlvI15Wp2GpbM RWGg== X-Gm-Message-State: ALyK8tLnn2yDpgzgGpYcTIdBcohnCENbEu3mPMywo3uZ3ZiHpLDi4b1RmK28B11T1nrCxxdJ X-Received: by 10.98.103.214 with SMTP id t83mr24253764pfj.158.1468609978420; Fri, 15 Jul 2016 12:12:58 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::2:8652]) by smtp.gmail.com with ESMTPSA id f2sm4875602pfb.76.2016.07.15.12.12.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Jul 2016 12:12:57 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH] btrfs-progs: fix btrfsck of space_cache=v2 bitmaps on big-endian Date: Fri, 15 Jul 2016 12:12:48 -0700 Message-Id: <17d32b3a20611fe19ab62726bf8626563ff3ec19.1468609012.git.osandov@fb.com> X-Mailer: git-send-email 2.9.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval Copy le_test_bit() from the kernel and use that for the free space tree bitmaps. Signed-off-by: Omar Sandoval --- Same sort of mistake as in the kernel. Applies to v4.6.1. extent_io.c | 2 +- extent_io.h | 19 +++++++++++++++++++ kerncompat.h | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/extent_io.c b/extent_io.c index c99d3627e370..d956c5731332 100644 --- a/extent_io.c +++ b/extent_io.c @@ -889,5 +889,5 @@ void memset_extent_buffer(struct extent_buffer *eb, char c, int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start, unsigned long nr) { - return test_bit(nr, (unsigned long *)(eb->data + start)); + return le_test_bit(nr, (u8 *)eb->data + start); } diff --git a/extent_io.h b/extent_io.h index a9a7353556a7..94a42bf5e180 100644 --- a/extent_io.h +++ b/extent_io.h @@ -49,6 +49,25 @@ #define BLOCK_GROUP_DIRTY EXTENT_DIRTY +/* + * The extent buffer bitmap operations are done with byte granularity instead of + * word granularity for two reasons: + * 1. The bitmaps must be little-endian on disk. + * 2. Bitmap items are not guaranteed to be aligned to a word and therefore a + * single word in a bitmap may straddle two pages in the extent buffer. + */ +#define BIT_BYTE(nr) ((nr) / BITS_PER_BYTE) +#define BYTE_MASK ((1 << BITS_PER_BYTE) - 1) +#define BITMAP_FIRST_BYTE_MASK(start) \ + ((BYTE_MASK << ((start) & (BITS_PER_BYTE - 1))) & BYTE_MASK) +#define BITMAP_LAST_BYTE_MASK(nbits) \ + (BYTE_MASK >> (-(nbits) & (BITS_PER_BYTE - 1))) + +static inline int le_test_bit(int nr, const u8 *addr) +{ + return 1U & (addr[BIT_BYTE(nr)] >> (nr & (BITS_PER_BYTE-1))); +} + struct btrfs_fs_info; struct extent_io_tree { diff --git a/kerncompat.h b/kerncompat.h index 378f0552edd2..c9b9b79782b9 100644 --- a/kerncompat.h +++ b/kerncompat.h @@ -55,7 +55,8 @@ #define gfp_t int #define get_cpu_var(p) (p) #define __get_cpu_var(p) (p) -#define BITS_PER_LONG (__SIZEOF_LONG__ * 8) +#define BITS_PER_BYTE 8 +#define BITS_PER_LONG (__SIZEOF_LONG__ * BITS_PER_BYTE) #define __GFP_BITS_SHIFT 20 #define __GFP_BITS_MASK ((int)((1 << __GFP_BITS_SHIFT) - 1)) #define GFP_KERNEL 0