From patchwork Wed Nov 15 21:20:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10060283 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 3B73C6023A for ; Wed, 15 Nov 2017 21:21:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EA262A121 for ; Wed, 15 Nov 2017 21:21:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 120D72A311; Wed, 15 Nov 2017 21:21: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 82BCE2A121 for ; Wed, 15 Nov 2017 21:20:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935059AbdKOVU4 (ORCPT ); Wed, 15 Nov 2017 16:20:56 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:52218 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935054AbdKOVUy (ORCPT ); Wed, 15 Nov 2017 16:20:54 -0500 Received: by mail-qt0-f195.google.com with SMTP id e19so32908667qte.8 for ; Wed, 15 Nov 2017 13:20:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=Dt3lYM4nimnTatbJq6TnmzoiViHkioKS9obKjxArtao=; b=atXuoq2UUD5T0vO0Z4an7OgBEsmuJQ4+2InM2DMCg9mjcL6D9rHobdKrV0q24rDAZE m31nAEldiajCDRtSbQwrYIl2UpdMmAqzcaE64cmxXakiKZMY2syY9QMt3Gmstuym6bNb 0h3Ck43B8AwLcTQVJrRGyJpmOr+C/d9zsEBsOiwoRqP1bAQEw2+feHhVimBbM06yzyev McqL4wI6x4RkoMMew35eZ9TaZajhxe75KJ+X0rGadeWn/S54pVCfRej56J+uSmC8edtn r0DRBGzF4KYYmrBVYC8dS/YAnB5t6GUZljPEQTcLlJvktO4AIBH1VwGpcF0K03x9nXjb PAqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Dt3lYM4nimnTatbJq6TnmzoiViHkioKS9obKjxArtao=; b=fCflLLo24XC4m9KLmuQhLJ07YZb9uT3LKs6lgLl5fkxzqatsZH6tWAMDxIIYRewm4p zJMO2BSdO/jEJeJ1AwYzAo/qIxoZsJkO6oDkpmlJAV6GmZY0DrjAUX7D16vCzj/jQln/ Gy51dtwXIf1TDWTBPZ0BmI3HVAlzMvZjU3Su+Q5SMRFwx+PfDfE/TOWZG6t3pXd5Iv+N tGSp2IaBgdExc9ShhMPH0yDEjknydgw0GXs/oWKRUhRveKa/ZXbgcoBwHVK/UUgWGQr2 naeaLRbNOVvTAVAL1yIzWSJk/aXe8rFV2NTgEcLg3mXBfuoUpQKpbRPgNPYv1oVrapfd dpSA== X-Gm-Message-State: AJaThX5K9A6HVWvJd67ybpaxqiXU28srRegSs8NtLp6rCNdruo9A0QEK YcYYkHEzF3CA7c94/yZ1sSv6iQt0 X-Google-Smtp-Source: AGs4zMa0ctBQRfoHIpZzS7o4KkhsZla/XJgrOJ/tg9l5yd7stFkJYYAzryNJmNhcngLfpnpHR6DHew== X-Received: by 10.200.41.145 with SMTP id 17mr8419807qts.239.1510780853999; Wed, 15 Nov 2017 13:20:53 -0800 (PST) Received: from localhost (cpe-2606-A000-4381-1201-225-22FF-FEB3-E51A.dyn6.twc.com. [2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id k10sm11183364qke.75.2017.11.15.13.20.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Nov 2017 13:20:53 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik Subject: [PATCH] btrfs: fix deadlock when writing out space cache Date: Wed, 15 Nov 2017 16:20:52 -0500 Message-Id: <1510780852-8862-1-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 2.7.5 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 If we fail to prepare our pages for whatever reason (out of memory in our case) we need to make sure to drop the block_group->data_rwsem, otherwise hilarity ensues. Signed-off-by: Josef Bacik Reviewed-by: Omar Sandoval Reviewed-by: Liu Bo --- fs/btrfs/free-space-cache.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index cdc9f4015ec3..a6c643275210 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -1263,8 +1263,12 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, /* Lock all pages first so we can lock the extent safely. */ ret = io_ctl_prepare_pages(io_ctl, inode, 0); - if (ret) + if (ret) { + if (block_group && + (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) + up_write(&block_group->data_rwsem); goto out; + } lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, &cached_state);