From patchwork Fri Jan 5 19:51:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Bo X-Patchwork-Id: 10147049 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D1A4260153 for ; Fri, 5 Jan 2018 20:54:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BBC128926 for ; Fri, 5 Jan 2018 20:54:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EE0228929; Fri, 5 Jan 2018 20:54:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA13428926 for ; Fri, 5 Jan 2018 20:54:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752955AbeAEUyM (ORCPT ); Fri, 5 Jan 2018 15:54:12 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:52852 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752913AbeAEUyK (ORCPT ); Fri, 5 Jan 2018 15:54:10 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.21/8.16.0.21) with SMTP id w05Kqdpe146657 for ; Fri, 5 Jan 2018 20:54:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=AEBBxDRs+btP0Z2TUwBaRSRd287OtxS6TkV1loZZDGU=; b=WrpA15bIOiT4q/JzlJyrJS/GZl6rpcEIHpHrqgl9VNPbE4Zk8FGa6vj2mavFpKqHf8I+ Yfv8rtIT1VVruTMMuZ5CYDJPpNxpJhfEwz0LAz48fWhNw90qaR0Y5W/a+thbkawHADiY zBS/6gC8JzU97n23UrUl4jz2K5L4BvWqTNrYclTA9G6bHwG8TD/j7JR17pW8uOz+0hd7 jYZ2wFRYUNAuiqbju6/ZZvdi9UYqP7dqOYXIXGLdltojUTtgTyrcsDkIp9yEvoveIBku uiYFSu2hGw5JvAQgawiE8s4+ittFk3BW0V8GaEPwMDY4l/32aq4EdDBKNsNyZ1nZ2LNw Mg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2fag5k06ee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 05 Jan 2018 20:54:09 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w05Ks9sx000454 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 5 Jan 2018 20:54:09 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w05Ks8R8027708 for ; Fri, 5 Jan 2018 20:54:09 GMT Received: from dhcp-10-211-47-181.usdhcp.oraclecorp.com.com (/10.211.47.181) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 05 Jan 2018 12:54:08 -0800 From: Liu Bo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 03/10] Btrfs: add helper for em merge logic Date: Fri, 5 Jan 2018 12:51:10 -0700 Message-Id: <20180105195117.5131-4-bo.li.liu@oracle.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20180105195117.5131-1-bo.li.liu@oracle.com> References: <20180105195117.5131-1-bo.li.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8765 signatures=668651 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=18 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=742 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801050287 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a prepare work for the following extent map selftest, which runs tests against em merge logic. Signed-off-by: Liu Bo Reviewed-by: Josef Bacik --- fs/btrfs/ctree.h | 2 ++ fs/btrfs/inode.c | 80 ++++++++++++++++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index b2e09fe..328f40f 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3148,6 +3148,8 @@ struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode, int delay_iput); void btrfs_wait_and_free_delalloc_work(struct btrfs_delalloc_work *work); +int btrfs_add_extent_mapping(struct extent_map_tree *em_tree, + struct extent_map **em_in, u64 start, u64 len); struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode, struct page *page, size_t pg_offset, u64 start, u64 len, int create); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a270fe2..876118c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -6911,6 +6911,51 @@ static noinline int uncompress_inline(struct btrfs_path *path, return ret; } +int btrfs_add_extent_mapping(struct extent_map_tree *em_tree, + struct extent_map **em_in, u64 start, u64 len) +{ + int ret; + struct extent_map *em = *em_in; + + ret = add_extent_mapping(em_tree, em, 0); + /* it is possible that someone inserted the extent into the tree + * while we had the lock dropped. It is also possible that + * an overlapping map exists in the tree + */ + if (ret == -EEXIST) { + struct extent_map *existing; + + ret = 0; + + existing = search_extent_mapping(em_tree, start, len); + /* + * existing will always be non-NULL, since there must be + * extent causing the -EEXIST. + */ + if (start >= existing->start && + start < extent_map_end(existing)) { + free_extent_map(em); + *em_in = existing; + ret = 0; + } else { + /* + * The existing extent map is the one nearest to + * the [start, start + len) range which overlaps + */ + ret = merge_extent_mapping(em_tree, existing, + em, start); + free_extent_map(existing); + if (ret) { + free_extent_map(em); + *em_in = NULL; + } + } + } + + ASSERT(ret == 0 || ret == -EEXIST); + return ret; +} + /* * a bit scary, this does extent mapping from logical file offset to the disk. * the ugly parts come from merging extents from the disk with the in-ram @@ -7147,40 +7192,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, err = 0; write_lock(&em_tree->lock); - ret = add_extent_mapping(em_tree, em, 0); - /* it is possible that someone inserted the extent into the tree - * while we had the lock dropped. It is also possible that - * an overlapping map exists in the tree - */ - if (ret == -EEXIST) { - struct extent_map *existing; - - ret = 0; - - existing = search_extent_mapping(em_tree, start, len); - /* - * existing will always be non-NULL, since there must be - * extent causing the -EEXIST. - */ - if (start >= existing->start && - start < extent_map_end(existing)) { - free_extent_map(em); - em = existing; - err = 0; - } else { - /* - * The existing extent map is the one nearest to - * the [start, start + len) range which overlaps - */ - err = merge_extent_mapping(em_tree, existing, - em, start); - free_extent_map(existing); - if (err) { - free_extent_map(em); - em = NULL; - } - } - } + err = btrfs_add_extent_mapping(em_tree, &em, start, len); write_unlock(&em_tree->lock); out: