From patchwork Tue Jan 4 05:40:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaohua Li X-Patchwork-Id: 449601 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p045fF27005214 for ; Tue, 4 Jan 2011 05:41:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751426Ab1ADFlJ (ORCPT ); Tue, 4 Jan 2011 00:41:09 -0500 Received: from mga11.intel.com ([192.55.52.93]:54900 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751226Ab1ADFlI (ORCPT ); Tue, 4 Jan 2011 00:41:08 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 03 Jan 2011 21:41:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.60,270,1291622400"; d="scan'208";a="874191593" Received: from unknown (HELO [10.239.36.124]) ([10.239.36.124]) by fmsmga001.fm.intel.com with ESMTP; 03 Jan 2011 21:41:06 -0800 Subject: [PATCH v2 4/5] implement metadata_ra in btrfs From: Shaohua Li To: "linux-btrfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" Cc: Chris Mason , Christoph Hellwig , Andrew Morton , Arjan van de Ven , "Yan, Zheng" , linux-api@vger.kernel.org, mtk.manpages@gmail.com Date: Tue, 04 Jan 2011 13:40:39 +0800 Message-ID: <1294119639.1949.369.camel@sli10-conroe> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 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.3 (demeter1.kernel.org [140.211.167.41]); Tue, 04 Jan 2011 05:41:15 +0000 (UTC) Index: linux/fs/btrfs/disk-io.c =================================================================== --- linux.orig/fs/btrfs/disk-io.c 2010-12-31 08:52:00.000000000 +0800 +++ linux/fs/btrfs/disk-io.c 2011-01-03 21:16:12.000000000 +0800 @@ -774,6 +774,15 @@ static int btree_readpage(struct file *f return extent_read_full_page(tree, page, btree_get_extent); } +static int btree_readpages(struct file *file, struct address_space *mapping, + struct list_head *pages, unsigned nr_pages) +{ + struct extent_io_tree *tree; + tree = &BTRFS_I(mapping->host)->io_tree; + return extent_readpages(tree, mapping, pages, nr_pages, + btree_get_extent); +} + static int btree_releasepage(struct page *page, gfp_t gfp_flags) { struct extent_io_tree *tree; @@ -817,6 +826,7 @@ static void btree_invalidatepage(struct static const struct address_space_operations btree_aops = { .readpage = btree_readpage, + .readpages = btree_readpages, .writepage = btree_writepage, .writepages = btree_writepages, .releasepage = btree_releasepage, Index: linux/fs/btrfs/super.c =================================================================== --- linux.orig/fs/btrfs/super.c 2011-01-03 21:16:00.000000000 +0800 +++ linux/fs/btrfs/super.c 2011-01-03 21:16:12.000000000 +0800 @@ -922,6 +922,7 @@ static const struct super_operations btr .freeze_fs = btrfs_freeze, .unfreeze_fs = btrfs_unfreeze, .metadata_incore = btrfs_metadata_incore, + .metadata_readahead = btrfs_metadata_readahead, }; static const struct file_operations btrfs_ctl_fops = { Index: linux/mm/readahead.c =================================================================== --- linux.orig/mm/readahead.c 2010-12-31 08:51:36.000000000 +0800 +++ linux/mm/readahead.c 2011-01-03 21:16:12.000000000 +0800 @@ -228,6 +228,7 @@ int force_page_cache_readahead(struct ad } return ret; } +EXPORT_SYMBOL_GPL(force_page_cache_readahead); /* * Given a desired number of PAGE_CACHE_SIZE readahead pages, return a Index: linux/fs/btrfs/volumes.c =================================================================== --- linux.orig/fs/btrfs/volumes.c 2010-12-31 08:52:00.000000000 +0800 +++ linux/fs/btrfs/volumes.c 2011-01-03 21:16:12.000000000 +0800 @@ -3448,3 +3448,41 @@ error: btrfs_free_path(path); return ret; } + +int btrfs_metadata_readahead(struct super_block *sb, loff_t offset, + ssize_t size) +{ + struct btrfs_root *tree_root = btrfs_sb(sb); + struct inode *btree_inode = tree_root->fs_info->btree_inode; + struct address_space *mapping = btree_inode->i_mapping; + struct btrfs_fs_info *info = tree_root->fs_info; + struct btrfs_block_group_cache *cache = NULL; + u64 bytenr = offset; + int retval = -EINVAL; + + lock_chunks(tree_root); + /* Make sure readahead range is in valid chunk */ + while (1) { + cache = btrfs_lookup_block_group(info, bytenr); + if (!cache) + break; + + if (cache->key.objectid + cache->key.offset >= + offset + size) { + retval = 0; + break; + } + bytenr = cache->key.objectid + cache->key.offset; + btrfs_put_block_group(cache); + cache = NULL; + } + if (cache) + btrfs_put_block_group(cache); + + if (!retval) + force_page_cache_readahead(mapping, NULL, + offset >> PAGE_CACHE_SHIFT, + size >> PAGE_CACHE_SHIFT); + unlock_chunks(tree_root); + return retval; +} Index: linux/fs/btrfs/volumes.h =================================================================== --- linux.orig/fs/btrfs/volumes.h 2010-12-31 08:52:00.000000000 +0800 +++ linux/fs/btrfs/volumes.h 2011-01-03 21:16:12.000000000 +0800 @@ -185,4 +185,6 @@ int btrfs_chunk_readonly(struct btrfs_ro int find_free_dev_extent(struct btrfs_trans_handle *trans, struct btrfs_device *device, u64 num_bytes, u64 *start, u64 *max_avail); +int btrfs_metadata_readahead(struct super_block *sb, loff_t offset, + ssize_t size); #endif