From patchwork Mon Mar 22 03:32:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jim owens X-Patchwork-Id: 87347 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 o2M3X5nN019857 for ; Mon, 22 Mar 2010 03:33:06 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754023Ab0CVDdE (ORCPT ); Sun, 21 Mar 2010 23:33:04 -0400 Received: from mail-qy0-f179.google.com ([209.85.221.179]:39016 "EHLO mail-qy0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753711Ab0CVDdC (ORCPT ); Sun, 21 Mar 2010 23:33:02 -0400 Received: by qyk9 with SMTP id 9so2972550qyk.1 for ; Sun, 21 Mar 2010 20:33:00 -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=6rjiMzSiPip4AyZDg++klYSRcCVPD3zAT5tGF+TBs54=; b=Fiy3iLfjpDZ67hgtO0HKNbcf95KCaS5g5kj440RFwj2cn1lKRTmw1nD8zoJPqiI/nC RUrXHBHOSVvQ56jQGjWr4TpvgA/FefwNkmHgujQGyZ/uaXZWyYq3fQv1Xo9LQ+EpJvH6 xeFHAQxojoOXtJPRq8SsktJ0W+MDvbcOeXCRY= 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=nq6uNtl4wNV+BD7e61i5eXUwi0xelWGKUeOWfzpxyxb6YZrq/6gU/gIvMmWhA41L5V vx54+XSM3u2Ep/HKQhvN44PY8zeLkceSTsRMkcY2NKgiY0JacFrHjjfVN4X5Gz2xIRAf hzft5CAnHz0jqBoWk6yNGWFnAA7dTG4CSFlbo= Received: by 10.224.83.80 with SMTP id e16mr2070943qal.231.1269228780713; Sun, 21 Mar 2010 20:33:00 -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 6sm8040631qwd.27.2010.03.21.20.32.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 21 Mar 2010 20:33:00 -0700 (PDT) Message-ID: <4BA6E4EB.70001@gmail.com> Date: Sun, 21 Mar 2010 23:32:59 -0400 From: jim owens User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: linux-btrfs Subject: [PATCH V3 15/18] Btrfs: change btrfs_get_extent for direct I/O merges. 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:33:06 +0000 (UTC) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index aad29fe..49dfc1a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4573,29 +4573,6 @@ out_unlock: return err; } -/* helper for btfs_get_extent. Given an existing extent in the tree, - * and an extent that you want to insert, deal with overlap and insert - * the new extent into the tree. - */ -static int merge_extent_mapping(struct extent_map_tree *em_tree, - struct extent_map *existing, - struct extent_map *em, - u64 map_start, u64 map_len) -{ - u64 start_diff; - - BUG_ON(map_start < em->start || map_start >= extent_map_end(em)); - start_diff = map_start - em->start; - em->start = map_start; - em->len = map_len; - if (em->block_start < EXTENT_MAP_LAST_BYTE && - !test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) { - em->block_start += start_diff; - em->block_len -= start_diff; - } - return add_extent_mapping(em_tree, em); -} - static noinline int uncompress_inline(struct btrfs_path *path, struct inode *inode, struct page *page, size_t pg_offset, u64 extent_offset, @@ -4873,35 +4850,28 @@ insert: if (ret == -EEXIST) { struct extent_map *existing; - ret = 0; + /* start and len might not be block aligned, but extents are */ + u64 lb_start = start & ~(root->sectorsize - 1); + u64 em_tail = em->len - (lb_start - em->start); - existing = lookup_extent_mapping(em_tree, start, len); - if (existing && (existing->start > start || - existing->start + existing->len <= start)) { + existing = lookup_extent_mapping(em_tree, lb_start, em_tail); + if (existing && lb_start < existing->start) { + em_tail = existing->start - lb_start; free_extent_map(existing); existing = NULL; } if (!existing) { - existing = lookup_extent_mapping(em_tree, em->start, - em->len); - if (existing) { - err = merge_extent_mapping(em_tree, existing, - em, start, - root->sectorsize); - free_extent_map(existing); - if (err) { - free_extent_map(em); - em = NULL; - } - } else { - err = -EIO; - free_extent_map(em); - em = NULL; + if (!test_bit(EXTENT_FLAG_COMPRESSED, &em->flags) && + em->block_start < EXTENT_MAP_LAST_BYTE) { + em->block_start += lb_start - em->start; + em->block_len -= lb_start - em->start; } + em->start = lb_start; + em->len = em_tail; + err = add_extent_mapping(em_tree, em); } else { free_extent_map(em); em = existing; - err = 0; } } write_unlock(&em_tree->lock);