From patchwork Mon Mar 22 03:20:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jim owens X-Patchwork-Id: 87335 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2M3KsdC017099 for ; Mon, 22 Mar 2010 03:20:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753917Ab0CVDUx (ORCPT ); Sun, 21 Mar 2010 23:20:53 -0400 Received: from qw-out-2122.google.com ([74.125.92.26]:28656 "EHLO qw-out-2122.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753726Ab0CVDUw (ORCPT ); Sun, 21 Mar 2010 23:20:52 -0400 Received: by qw-out-2122.google.com with SMTP id 8so1062175qwh.37 for ; Sun, 21 Mar 2010 20:20:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=mNDBV0g7omupftFPQAIngS7zzCqSdInria6P9nBlymk=; b=rmUqmrZUyIjvUGxMMRUlVfQ/4mX7dkhueT+WmME7ImEilpGwWqsV4VNR2DJzuryDy9 1kAno3gHVad8pDk7r1FsEahJepy1iMvOOH87TTH00gbUahLnSNbuHtxQB2CyqOTris8S JviPk4ugHd+PjflccDRYMZQpG0KYcdH+FExYw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=i/MpZZMbH8zlQ8xd2qagG2YrxYlauE8S1qTMskBj9WVYViIqY3ul2H5S3D4Tjw21D4 RWzWiKV/+Bcg5iBWAaUccODuhcQC1nw9oBqOxLjCrs12VXwfL3xgcD/YywLVtxNSTVAb gPmWuxz0XhaBFT6I3AnnWp1iZl/2yxWaju3VE= Received: by 10.224.123.103 with SMTP id o39mr503360qar.296.1269228051568; Sun, 21 Mar 2010 20:20:51 -0700 (PDT) Received: from [192.168.0.97] (c-24-147-40-65.hsd1.nh.comcast.net [24.147.40.65]) by mx.google.com with ESMTPS id 6sm6025025qwk.42.2010.03.21.20.20.50 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 21 Mar 2010 20:20:51 -0700 (PDT) Message-ID: <4BA6E212.6090501@gmail.com> Date: Sun, 21 Mar 2010 23:20:50 -0400 From: jim owens User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: linux-btrfs Subject: [PATCH V3 03/18] Btrfs: __btrfs_map_block should not set length more than input 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 (demeter.kernel.org [140.211.167.41]); Mon, 22 Mar 2010 03:20:54 +0000 (UTC) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 1727b26..f01e41a 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -1608,9 +1608,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 2a337a0..c917545 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1402,20 +1402,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 8c8908c..0e6c173 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2711,14 +2711,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)