From patchwork Thu Mar 13 05:19:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 3821971 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 762E6BF540 for ; Thu, 13 Mar 2014 05:21:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 77C5A201F0 for ; Thu, 13 Mar 2014 05:21:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 67E6C201E9 for ; Thu, 13 Mar 2014 05:21:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751310AbaCMFVy (ORCPT ); Thu, 13 Mar 2014 01:21:54 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:23285 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751034AbaCMFVx (ORCPT ); Thu, 13 Mar 2014 01:21:53 -0400 X-IronPort-AV: E=Sophos;i="4.97,644,1389715200"; d="scan'208";a="9688127" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 13 Mar 2014 13:17:59 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s2D5LnNX004923 for ; Thu, 13 Mar 2014 13:21:49 +0800 Received: from wangs.fnst.cn.fujitsu.com ([10.167.226.104]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2014031313190363-604174 ; Thu, 13 Mar 2014 13:19:03 +0800 From: Wang Shilong To: linux-btrfs@vger.kernel.org Subject: [PATCH] Btrfs: fix joining same transaction handle more than twice Date: Thu, 13 Mar 2014 13:19:47 +0800 Message-Id: <1394687987-22715-1-git-send-email-wangsl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.0 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/03/13 13:19:03, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/03/13 13:19:04, Serialize complete at 2014/03/13 13:19:04 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We hit something like the following function call flows: |->run_delalloc_range() |->btrfs_join_transaction() |->cow_file_range() |->btrfs_join_transaction() |->find_free_extent() |->btrfs_join_transaction() Trace infomation can be seen as: [ 7411.127040] ------------[ cut here ]------------ [ 7411.127060] WARNING: CPU: 0 PID: 11557 at fs/btrfs/transaction.c:383 start_transaction+0x561/0x580 [btrfs]() [ 7411.127079] CPU: 0 PID: 11557 Comm: kworker/u8:9 Tainted: G O 3.13.0+ #4 [ 7411.127080] Hardware name: LENOVO QiTianM4350/ , BIOS F1KT52AUS 05/24/2013 [ 7411.127085] Workqueue: writeback bdi_writeback_workfn (flush-btrfs-5) [ 7411.127092] Call Trace: [ 7411.127097] [] dump_stack+0x45/0x56 [ 7411.127101] [] warn_slowpath_common+0x7d/0xa0 [ 7411.127102] [] warn_slowpath_null+0x1a/0x20 [ 7411.127109] [] start_transaction+0x561/0x580 [btrfs] [ 7411.127115] [] btrfs_join_transaction+0x17/0x20 [btrfs] [ 7411.127120] [] find_free_extent+0xa21/0xb50 [btrfs] [ 7411.127126] [] btrfs_reserve_extent+0xa8/0x1a0 [btrfs] [ 7411.127131] [] btrfs_alloc_free_block+0xee/0x440 [btrfs] [ 7411.127137] [] ? btree_set_page_dirty+0xe/0x10 [btrfs] [ 7411.127142] [] __btrfs_cow_block+0x121/0x530 [btrfs] [ 7411.127146] [] btrfs_cow_block+0x11f/0x1c0 [btrfs] [ 7411.127151] [] btrfs_search_slot+0x1d4/0x9c0 [btrfs] [ 7411.127157] [] btrfs_lookup_file_extent+0x37/0x40 [btrfs] [ 7411.127163] [] __btrfs_drop_extents+0x16c/0xd90 [btrfs] [ 7411.127169] [] ? start_transaction+0x93/0x580 [btrfs] [ 7411.127171] [] ? kmem_cache_alloc+0x132/0x140 [ 7411.127176] [] ? btrfs_alloc_path+0x1a/0x20 [btrfs] [ 7411.127182] [] cow_file_range_inline+0x181/0x2e0 [btrfs] [ 7411.127187] [] cow_file_range+0x2ed/0x440 [btrfs] [ 7411.127194] [] ? free_extent_buffer+0x4f/0xb0 [btrfs] [ 7411.127200] [] run_delalloc_nocow+0x38f/0xa60 [btrfs] [ 7411.127207] [] ? test_range_bit+0x30/0x180 [btrfs] [ 7411.127212] [] run_delalloc_range+0x2e8/0x350 [btrfs] [ 7411.127219] [] ? find_lock_delalloc_range+0x1a9/0x1e0 [btrfs] [ 7411.127222] [] ? blk_queue_bio+0x2c1/0x330 [ 7411.127228] [] __extent_writepage+0x2f4/0x760 [btrfs] Here we fix it by avoiding joining transaction again if we have held a transaction handle when allocating chunk in find_free_extent(). Signed-off-by: Wang Shilong --- fs/btrfs/extent-tree.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index da8031b..06066d5 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -6604,8 +6604,14 @@ loop: loop++; if (loop == LOOP_ALLOC_CHUNK) { struct btrfs_trans_handle *trans; + int exist = 0; + + trans = current->journal_info; + if (trans) + exist = 1; + else + trans = btrfs_join_transaction(root); - trans = btrfs_join_transaction(root); if (IS_ERR(trans)) { ret = PTR_ERR(trans); goto out; @@ -6622,7 +6628,8 @@ loop: root, ret); else ret = 0; - btrfs_end_transaction(trans, root); + if (!exist) + btrfs_end_transaction(trans, root); if (ret) goto out; }