From patchwork Mon May 23 12:59:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Jansen X-Patchwork-Id: 808612 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4NCxJok017713 for ; Mon, 23 May 2011 12:59:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753610Ab1EWM7O (ORCPT ); Mon, 23 May 2011 08:59:14 -0400 Received: from mort.rzone.de ([81.169.144.234]:33082 "EHLO mort.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753301Ab1EWM7M (ORCPT ); Mon, 23 May 2011 08:59:12 -0400 Received: from gargravarr.store (gargravarr.store [192.168.42.236]) by mort.rzone.de (Postfix) with ESMTP id 13FB1630; Mon, 23 May 2011 14:59:10 +0200 (MEST) Received: by gargravarr.store (Postfix, from userid 32466) id AC67CC075; Mon, 23 May 2011 14:59:08 +0200 (CEST) From: Arne Jansen To: chris.mason@oracle.com, linux-btrfs@vger.kernel.org Subject: [PATCH v1 1/5] btrfs: add READAHEAD extent state Date: Mon, 23 May 2011 14:59:04 +0200 Message-Id: X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 23 May 2011 12:59:20 +0000 (UTC) Add a READAHEAD extent state flag. Add a function to trigger a read with this flag set. Reset the flag in the end_io hook Signed-off-by: Arne Jansen --- fs/btrfs/disk-io.c | 36 ++++++++++++++++++++++++++++++++++++ fs/btrfs/disk-io.h | 2 ++ fs/btrfs/extent_io.c | 10 +++++++++- fs/btrfs/extent_io.h | 1 + 4 files changed, 48 insertions(+), 1 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index fe5aec9..7753eb9 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -958,6 +958,42 @@ int readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize, return ret; } +int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, u32 blocksize, + int mirror_num, struct extent_buffer **eb) +{ + struct extent_buffer *buf = NULL; + struct inode *btree_inode = root->fs_info->btree_inode; + int ret; + + buf = btrfs_find_create_tree_block(root, bytenr, blocksize); + if (!buf) + return 0; + + ret = set_extent_bits(&BTRFS_I(btree_inode)->io_tree, + bytenr, bytenr+blocksize-1, + EXTENT_READAHEAD, GFP_NOFS); + if (ret) { + printk(KERN_ERR "set_extent_bits failed with %d\n", ret); + free_extent_buffer(buf); + return ret; + } + + read_extent_buffer_pages(&BTRFS_I(btree_inode)->io_tree, + buf, 0, 0, btree_get_extent, mirror_num); + + if (test_bit(EXTENT_BUFFER_CORRUPT, &buf->bflags)) { + *eb = buf; + ret = -EIO; + } else if (extent_buffer_uptodate( + &BTRFS_I(buf->first_page->mapping->host)->io_tree, + buf, NULL)) { + *eb = buf; + } else { + free_extent_buffer(buf); + } + return ret; +} + struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize) { diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 07b20dc..0c47d57 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -40,6 +40,8 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize, u64 parent_transid); int readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize, u64 parent_transid); +int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, u32 blocksize, + int mirror_num, struct extent_buffer **eb); struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize); int clean_tree_block(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 0d1196d..df0bc46 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1021,6 +1021,14 @@ int unlock_extent_cached(struct extent_io_tree *tree, u64 start, u64 end, mask); } +int unlock_ra_extent_cached(struct extent_io_tree *tree, u64 start, u64 end, + struct extent_state **cached, gfp_t mask) +{ + return clear_extent_bit(tree, start, end, + EXTENT_READAHEAD | EXTENT_LOCKED, 1, 0, cached, + mask); +} + int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask) { return clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, NULL, @@ -1795,7 +1803,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err) set_extent_uptodate(tree, start, end, &cached, GFP_ATOMIC); } - unlock_extent_cached(tree, start, end, &cached, GFP_ATOMIC); + unlock_ra_extent_cached(tree, start, end, &cached, GFP_ATOMIC); if (whole_page) { if (uptodate) { diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index af2d717..6317c78 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -17,6 +17,7 @@ #define EXTENT_NODATASUM (1 << 10) #define EXTENT_DO_ACCOUNTING (1 << 11) #define EXTENT_FIRST_DELALLOC (1 << 12) +#define EXTENT_READAHEAD (1 << 13) #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK) #define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC)