From patchwork Mon Dec 13 07:22:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaohua Li X-Patchwork-Id: 405022 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 oBD7MNKu028559 for ; Mon, 13 Dec 2010 07:22:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932273Ab0LMHWR (ORCPT ); Mon, 13 Dec 2010 02:22:17 -0500 Received: from mga02.intel.com ([134.134.136.20]:30789 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932206Ab0LMHWQ (ORCPT ); Mon, 13 Dec 2010 02:22:16 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 12 Dec 2010 23:22:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.59,335,1288594800"; d="scan'208";a="583119475" Received: from sli10-conroe.sh.intel.com (HELO [10.239.36.47]) ([10.239.36.47]) by orsmga002.jf.intel.com with ESMTP; 12 Dec 2010 23:22:14 -0800 Subject: [RFC 2/5] implement metadata_incore in btrfs From: Shaohua Li To: "linux-btrfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" Cc: Chris Mason , Christoph Hellwig , Arjan van de Ven , Andrew Morton Date: Mon, 13 Dec 2010 15:22:11 +0800 Message-ID: <1292224931.2323.451.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]); Mon, 13 Dec 2010 07:22:24 +0000 (UTC) Index: linux/fs/btrfs/super.c =================================================================== --- linux.orig/fs/btrfs/super.c 2010-12-07 10:10:20.000000000 +0800 +++ linux/fs/btrfs/super.c 2010-12-07 13:25:20.000000000 +0800 @@ -39,6 +39,7 @@ #include #include #include +#include #include "compat.h" #include "ctree.h" #include "disk-io.h" @@ -845,6 +846,52 @@ static int btrfs_unfreeze(struct super_b return 0; } +static int btrfs_metadata_incore(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 pagevec pvec; + loff_t index = (*offset) >> PAGE_CACHE_SHIFT; + int i, nr_pages; + + *size = 0; +retry: + pagevec_init(&pvec, 0); + nr_pages = pagevec_lookup(&pvec, btree_inode->i_mapping, index, + PAGEVEC_SIZE); + if (nr_pages == 0) + goto out; + for (i = 0; i < nr_pages; i++) { + struct page *page = pvec.pages[i]; + + /* Only take pages with 'referenced' bit set */ + if (PageUptodate(page) && PageReferenced(page)) { + if (*size == 0) { + *size += PAGE_CACHE_SIZE; + *offset = page->index << PAGE_CACHE_SHIFT; + continue; + } + if (page->index != + (*offset + *size) >> PAGE_CACHE_SHIFT) + break; + *size += PAGE_CACHE_SIZE; + } else if (*size > 0) + break; + else + index = page->index + 1; + } + pagevec_release(&pvec); + + if (nr_pages > 0 && *size == 0) + goto retry; +out: + if (*size > 0) + return 0; + else + return -ENOENT; +} + static const struct super_operations btrfs_super_ops = { .drop_inode = btrfs_drop_inode, .evict_inode = btrfs_evict_inode, @@ -859,6 +906,7 @@ static const struct super_operations btr .remount_fs = btrfs_remount, .freeze_fs = btrfs_freeze, .unfreeze_fs = btrfs_unfreeze, + .metadata_incore = btrfs_metadata_incore, }; static const struct file_operations btrfs_ctl_fops = {