From patchwork Tue Sep 11 17:57:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10596071 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C4FC14E5 for ; Tue, 11 Sep 2018 17:58:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58E1E29B9D for ; Tue, 11 Sep 2018 17:58:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D24029BA0; Tue, 11 Sep 2018 17:58:32 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 EA87829B9D for ; Tue, 11 Sep 2018 17:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728271AbeIKW6z (ORCPT ); Tue, 11 Sep 2018 18:58:55 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:37166 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbeIKW6z (ORCPT ); Tue, 11 Sep 2018 18:58:55 -0400 Received: by mail-qt0-f196.google.com with SMTP id n6-v6so29178164qtl.4 for ; Tue, 11 Sep 2018 10:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=+HzhX5veQVR7KYguCDJIe+MJkMCf434goypDockwhKY=; b=d6xnZgPEgRFACq/KgKcA3umAP3J3JSeCWlJac+nI1xEl2US91IgN6CUJhOuxDUW2C9 eM4ClWc9AjnPjdu4E2glRLUfhGfyplTFy4OVR6L8a5B377lHsqBNNryNUILDxOGgIIzA ayGL3gyVOKB9/wEOnrbOgAutJ1J44tEpY46gtetBUnk8iU03zvGdE76GG5EUo2oO5/8i 20+FyRcITFPGHePbvi0VUstZDuoczPZ0rAEV1fPRzbc8i4nSrsLi8dJTzU9p8dhrouof HIU7H3h72oe9ylD47XLBMcrFowGbYYUt4vTqaA082RlE2hRybMXAbLqGebWpiZRbATEU SDow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+HzhX5veQVR7KYguCDJIe+MJkMCf434goypDockwhKY=; b=Z86XQsEbk/HBvVefMVkftWpNAxrBcBfepuKD3bTv3OwXKyTAmnNYURn0j8WzMDec6A 1rwD92OiS7r6WqaQbQsPcZLfyTlIcyUkkcEW1IAaU8lI+Y7cfFwoTttX73U6k62G/J1x 1BuXLu3aIZ5Ht0jmihYe5zAShi3RknIyXg7P9v/3A1KzuRZLgkz4jj3+F16Fhh+adIzu Wdxc8qRcILb3QWddc4laXQZUCaMc4A155xV0NfT3OdQCZeUBlhGWj/R86n3KNsHUDRVu lUrCK5khEvz9FHEZtTXjZB9qwz0XcQggAvdQOHw2aHfbtju8h3BItbO+val/gJ7NlQ1S hBXA== X-Gm-Message-State: APzg51BnjYPbptnHlsf92Csg00n7LdlBvMvyn6vYXuyna0vhQeyXs56O 1BLfGTj8ncrkOyciRAtzZLSrAw== X-Google-Smtp-Source: ANB0VdbJt6tQ9+k8fQL0yD0NWJWEG4LYhq0/8PCMykkSlxI1gNm8BoKu3Z7asd2mEKps2PzK1MbBpQ== X-Received: by 2002:ac8:28bb:: with SMTP id i56-v6mr20779903qti.140.1536688709340; Tue, 11 Sep 2018 10:58:29 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id g39-v6sm13376709qtb.90.2018.09.11.10.58.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 10:58:28 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 10/36] btrfs: protect space cache inode alloc with nofs Date: Tue, 11 Sep 2018 13:57:41 -0400 Message-Id: <20180911175807.26181-11-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180911175807.26181-1-josef@toxicpanda.com> References: <20180911175807.26181-1-josef@toxicpanda.com> 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 If we're allocating a new space cache inode it's likely going to be under a transaction handle, so we need to use memalloc_nofs_save() in order to avoid deadlocks, and more importantly lockdep messages that make xfstests fail. Reviewed-by: Omar Sandoval Signed-off-by: Josef Bacik --- fs/btrfs/free-space-cache.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index c3888c113d81..e077ad3b4549 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "ctree.h" #include "free-space-cache.h" #include "transaction.h" @@ -47,6 +48,7 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root, struct btrfs_free_space_header *header; struct extent_buffer *leaf; struct inode *inode = NULL; + unsigned nofs_flag; int ret; key.objectid = BTRFS_FREE_SPACE_OBJECTID; @@ -68,7 +70,13 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root, btrfs_disk_key_to_cpu(&location, &disk_key); btrfs_release_path(path); + /* + * We are often under a trans handle at this point, so we need to make + * sure NOFS is set to keep us from deadlocking. + */ + nofs_flag = memalloc_nofs_save(); inode = btrfs_iget(fs_info->sb, &location, root, NULL); + memalloc_nofs_restore(nofs_flag); if (IS_ERR(inode)) return inode;