From patchwork Mon Jan 4 21:12:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jim owens X-Patchwork-Id: 70739 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 o04LDM6J024937 for ; Mon, 4 Jan 2010 21:13:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754132Ab0ADVMs (ORCPT ); Mon, 4 Jan 2010 16:12:48 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754120Ab0ADVMs (ORCPT ); Mon, 4 Jan 2010 16:12:48 -0500 Received: from g1t0026.austin.hp.com ([15.216.28.33]:5808 "EHLO g1t0026.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754132Ab0ADVMr (ORCPT ); Mon, 4 Jan 2010 16:12:47 -0500 Received: from g1t0038.austin.hp.com (g1t0038.austin.hp.com [16.236.32.44]) by g1t0026.austin.hp.com (Postfix) with ESMTP id 5E899C313 for ; Mon, 4 Jan 2010 21:12:47 +0000 (UTC) Received: from ldl (ldl.fc.hp.com [15.11.146.30]) by g1t0038.austin.hp.com (Postfix) with ESMTP id 5071B30094 for ; Mon, 4 Jan 2010 21:12:47 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl (Postfix) with ESMTP id 1F579CF0011; Mon, 4 Jan 2010 14:12:47 -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 jydXDugc7+af; Mon, 4 Jan 2010 14:12:47 -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 7D317CF000E; Mon, 4 Jan 2010 14:12:46 -0700 (MST) Message-ID: <4B4259CD.4010104@hp.com> Date: Mon, 04 Jan 2010 16:12:45 -0500 From: jim owens User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: linux-btrfs Subject: [RFC 02/12 RESEND PATCH] Btrfs: __btrfs_map_block should not set length more than input length. Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 56e5013..b610557 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -1600,9 +1600,6 @@ static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, struct btrfs_bio_stripe *stripe = multi->stripes; int i; - if (map_length > num_bytes) - map_length = num_bytes; - for (i = 0; i < multi->num_stripes; i++, stripe++) { btrfs_issue_discard(stripe->dev->bdev, stripe->physical, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5440bab..152015c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1397,20 +1397,19 @@ int btrfs_merge_bio_hook(struct page *page, unsigned long offset, struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; struct btrfs_mapping_tree *map_tree; u64 logical = (u64)bio->bi_sector << 9; - u64 length = 0; + u64 length = bio->bi_size + size; u64 map_length; int ret; if (bio_flags & EXTENT_BIO_COMPRESSED) return 0; - length = bio->bi_size; map_tree = &root->fs_info->mapping_tree; map_length = length; ret = btrfs_map_block(map_tree, READ, logical, &map_length, NULL, 0); - if (map_length < length + size) + if (ret || map_length < length) return 1; return 0; } diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index f4b5666..5af76fc 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2697,14 +2697,15 @@ again: /* stripe_offset is the offset of this block in its stripe*/ stripe_offset = offset - stripe_offset; + /* return smaller of input length or remaining contiguous length */ if (map->type & (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID10)) { - /* we limit the length of each bio to what fits in a stripe */ - *length = min_t(u64, em->len - offset, - map->stripe_len - stripe_offset); + /* only the length that fits in one stripe is contiguous */ + *length = min(*length, min_t(u64, em->len - offset, + map->stripe_len - stripe_offset)); } else { /* RAID1, DUP, and simple disk stripes are all contiguous */ - *length = em->len - offset; + *length = min(*length, em->len - offset); } if (!multi_ret && !unplug_page)