From patchwork Fri Jun 15 11:05:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 10466195 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 4E3CB600F4 for ; Fri, 15 Jun 2018 11:06:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F1CC28D33 for ; Fri, 15 Jun 2018 11:06:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33E4128D3F; Fri, 15 Jun 2018 11:06:17 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 87E2128D33 for ; Fri, 15 Jun 2018 11:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965703AbeFOLGM (ORCPT ); Fri, 15 Jun 2018 07:06:12 -0400 Received: from mx2.suse.de ([195.135.220.15]:54707 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965627AbeFOLGL (ORCPT ); Fri, 15 Jun 2018 07:06:11 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 99E86AEB5; Fri, 15 Jun 2018 11:06:10 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: osandov@osandov.com, Nikolay Borisov Subject: [PATCH 2/6] btrfs-progs: Add extent buffer bitmap manipulation infrastructure Date: Fri, 15 Jun 2018 14:05:58 +0300 Message-Id: <1529060762-4372-3-git-send-email-nborisov@suse.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529060762-4372-1-git-send-email-nborisov@suse.com> References: <1529060762-4372-1-git-send-email-nborisov@suse.com> 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 Those functions are in preparation for adding the freespace tree repair code since it needs to be able to deal with bitmap based fsts. This patch adds extent_buffer_bitmap_set and extent_buffer_bitmap_clear functions. Since in userspace we don't have to deal with page mappings their implementation is vastly simplified by simply setting each bit in the passed range. Signed-off-by: Nikolay Borisov --- extent_io.c | 39 +++++++++++++++++++++++++++++++++++++++ extent_io.h | 15 +++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/extent_io.c b/extent_io.c index 198492699438..568a12f7084b 100644 --- a/extent_io.c +++ b/extent_io.c @@ -204,6 +204,45 @@ static int clear_state_bit(struct extent_io_tree *tree, return ret; } +/** + * extent_buffer_bitmap_set - set an area of a bitmap + * @eb: the extent buffer + * @start: offset of the bitmap item in the extent buffer + * @pos: bit number of the first bit + * @len: number of bits to set + */ +void extent_buffer_bitmap_set(struct extent_buffer *eb, unsigned long start, + unsigned long pos, unsigned long len) +{ + u8 *kaddr = (u8 *)eb->data + start; + + while (len) { + le_set_bit(pos, kaddr); + pos++; + len--; + } +} + + +/** + * extent_buffer_bitmap_clear - clear an area of a bitmap + * @eb: the extent buffer + * @start: offset of the bitmap item in the extent buffer + * @pos: bit number of the first bit + * @len: number of bits to clear + */ +void extent_buffer_bitmap_clear(struct extent_buffer *eb, unsigned long start, + unsigned long pos, unsigned long len) +{ + u8 *kaddr = (u8 *)eb->data + start; + + while (len) { + le_clear_bit(pos, kaddr); + pos++; + len--; + } +} + /* * clear some bits on a range in the tree. */ diff --git a/extent_io.h b/extent_io.h index d407d93d617e..f9097911f5ef 100644 --- a/extent_io.h +++ b/extent_io.h @@ -68,6 +68,17 @@ static inline int le_test_bit(int nr, const u8 *addr) return 1U & (addr[BIT_BYTE(nr)] >> (nr & (BITS_PER_BYTE-1))); } + +static inline void le_set_bit(int nr, u8 *addr) +{ + addr[BIT_BYTE(nr)] |= (1U << (nr & (BITS_PER_BYTE-1))); +} + +static inline void le_clear_bit(int nr, u8 *addr) +{ + addr[BIT_BYTE(nr)] &= ~(1U << (nr & (BITS_PER_BYTE-1))); +} + struct btrfs_fs_info; struct extent_io_tree { @@ -175,4 +186,8 @@ int read_data_from_disk(struct btrfs_fs_info *info, void *buf, u64 offset, u64 bytes, int mirror); int write_data_to_disk(struct btrfs_fs_info *info, void *buf, u64 offset, u64 bytes, int mirror); +void extent_buffer_bitmap_clear(struct extent_buffer *eb, unsigned long start, + unsigned long pos, unsigned long len); +void extent_buffer_bitmap_set(struct extent_buffer *eb, unsigned long start, + unsigned long pos, unsigned long len); #endif