From patchwork Mon Jan 4 21:14:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jim owens X-Patchwork-Id: 70751 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o04LOD2G026391 for ; Mon, 4 Jan 2010 21:24:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753221Ab0ADVYM (ORCPT ); Mon, 4 Jan 2010 16:24:12 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753157Ab0ADVYM (ORCPT ); Mon, 4 Jan 2010 16:24:12 -0500 Received: from g6t0185.atlanta.hp.com ([15.193.32.62]:22974 "EHLO g6t0185.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753083Ab0ADVYL (ORCPT ); Mon, 4 Jan 2010 16:24:11 -0500 Received: from g5t0030.atlanta.hp.com (g5t0030.atlanta.hp.com [16.228.8.142]) by g6t0185.atlanta.hp.com (Postfix) with ESMTP id BD1C4240B0 for ; Mon, 4 Jan 2010 21:14:23 +0000 (UTC) Received: from ldl (ldl.fc.hp.com [15.11.146.30]) by g5t0030.atlanta.hp.com (Postfix) with ESMTP id AA11C1402C for ; Mon, 4 Jan 2010 21:14:23 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl (Postfix) with ESMTP id 7DF17CF0011; Mon, 4 Jan 2010 14:14:23 -0700 (MST) Received: from ldl ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9JpToA2K08i8; Mon, 4 Jan 2010 14:14:23 -0700 (MST) Received: from [192.168.0.99] (squirrel.fc.hp.com [15.11.146.57]) (Authenticated sender: owens@fc.hp.com) by ldl (Postfix) with ESMTPA id 0462ECF000E; Mon, 4 Jan 2010 14:14:22 -0700 (MST) Message-ID: <4B425A2D.5030207@hp.com> Date: Mon, 04 Jan 2010 16:14:21 -0500 From: jim owens User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: linux-btrfs Subject: [RFC 11/12 PATCH] Btrfs: add direct I/O helper btrfs_lookup_one_csum(). Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index bf04876..e5926c6 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2281,6 +2281,8 @@ int btrfs_csum_truncate(struct btrfs_trans_handle *trans, u64 isize); int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, struct list_head *list, u32 *csums); +int btrfs_lookup_one_csum(struct btrfs_root *root, struct inode *inode, + u64 disk_bytenr, u64 fpos, u32 *csum); /* inode.c */ /* RHEL and EL kernels have a patch that renames PG_checked to FsMisc */ diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 72c76bd..8482a56 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -244,6 +244,51 @@ found: return 0; } +int btrfs_lookup_one_csum(struct btrfs_root *root, struct inode *inode, + u64 disk_bytenr, u64 fpos, u32 *csum) +{ + u32 diff; + u16 csum_size; + int ret; + struct btrfs_path *path; + struct btrfs_csum_item *item; + struct btrfs_key found_key; + + if (!btrfs_find_ordered_sum(inode, fpos, disk_bytenr, csum)) + return 0; + + *csum = 0; + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + item = btrfs_lookup_csum(NULL, root->fs_info->csum_root, + path, disk_bytenr, 0); + if (IS_ERR(item)) { + ret = PTR_ERR(item); + printk(KERN_INFO "btrfs no csum found " + "for inode %lu start %llu err %d\n", + inode->i_ino, (unsigned long long)fpos, ret); + goto notfound; + } + + btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); + item = btrfs_item_ptr(path->nodes[0], path->slots[0], + struct btrfs_csum_item); + csum_size = btrfs_super_csum_size(&root->fs_info->super_copy); + + diff = disk_bytenr - found_key.offset; + diff = diff / root->sectorsize * csum_size; + + read_extent_buffer(path->nodes[0], csum, + ((unsigned long)item) + diff, csum_size); + ret = 0; + +notfound: + btrfs_free_path(path); + return ret; +} + int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, struct list_head *list, u32 *csums) {