From patchwork Thu Jul 21 11:02:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mason X-Patchwork-Id: 9241473 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 B4C9560574 for ; Thu, 21 Jul 2016 11:03:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A478727DE0 for ; Thu, 21 Jul 2016 11:03:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9870A27E5A; Thu, 21 Jul 2016 11:03:00 +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 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 6C4B627DE0 for ; Thu, 21 Jul 2016 11:02:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752174AbcGULC5 (ORCPT ); Thu, 21 Jul 2016 07:02:57 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:47058 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752006AbcGULCz (ORCPT ); Thu, 21 Jul 2016 07:02:55 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.11/8.16.0.11) with SMTP id u6LAwaKQ010344 for ; Thu, 21 Jul 2016 04:02:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=FYA7MCXYL7nvT2L4upo8X5JiaLHWlQHLDLMbdDEfA5s=; b=IvteYAYuDjeQBUSQQ7l0ma3h8JVGshX9ACfjSoJVOmHhNVIRNg8a2G4tXlEe3Ka5XD62 ExUOyhf1BGts8hAHacSf42E1BYVQPyrGtwZNZdUtij8lpnM3FokEBP15Rsg1X/RmBxFN WPJIbYR0DrPTo45cHrOJ/xFgdJ1ozJh7r1Y= Received: from maileast.thefacebook.com ([199.201.65.23]) by m0001303.ppops.net with ESMTP id 24a8ghy6my-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 21 Jul 2016 04:02:54 -0700 Received: from mx-out.facebook.com (192.168.182.6) by FRC-CHUB12.TheFacebook.com (192.168.177.32) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 21 Jul 2016 07:02:53 -0400 Received: from facebook.com (2401:db00:2040:5012:face:0:1:0) by mx-out.facebook.com (10.212.232.63) with ESMTP id ac07fc364f3211e69dd20002c992ebde-d67f8af0 for ; Thu, 21 Jul 2016 04:02:53 -0700 Received: by devbig616.ash4.facebook.com (Postfix, from userid 8731) id 4DE72B20767; Thu, 21 Jul 2016 04:02:53 -0700 (PDT) From: Chris Mason To: CC: Josef Bacik , Chris Mason Subject: [PATCH] Btrfs: avoid deadlocks during reservations in btrfs_truncate_block Date: Thu, 21 Jul 2016 04:02:33 -0700 Message-ID: <1469098953-2500150-1-git-send-email-clm@fb.com> X-Mailer: git-send-email 2.8.0.rc2 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-07-21_04:, , signatures=0 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 From: Josef Bacik The new enospc code makes it possible to deadlock if we don't use FLUSH_LIMIT during reservations inside a transaction. This enforces the correct flush type to avoid both deadlocks and assertions Signed-off-by: Chris Mason Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 3a129c4..9fcb8c9 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5939,10 +5939,15 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) * the middle of a transaction commit. We also don't need the delalloc * mutex since we won't race with anybody. We need this mostly to make * lockdep shut its filthy mouth. + * + * If we have a transaction open (can happen if we call truncate_block + * from truncate), then we need FLUSH_LIMIT so we don't deadlock. */ if (btrfs_is_free_space_inode(inode)) { flush = BTRFS_RESERVE_NO_FLUSH; delalloc_lock = false; + } else if (current->journal_info) { + flush = BTRFS_RESERVE_FLUSH_LIMIT; } if (flush != BTRFS_RESERVE_NO_FLUSH &&