From patchwork Thu Oct 19 18:16:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10018117 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 F058F60215 for ; Thu, 19 Oct 2017 18:16:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED1C228DCD for ; Thu, 19 Oct 2017 18:16:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E213428DEA; Thu, 19 Oct 2017 18:16:22 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 6BBFE28DCD for ; Thu, 19 Oct 2017 18:16:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753426AbdJSSQT (ORCPT ); Thu, 19 Oct 2017 14:16:19 -0400 Received: from mail-qt0-f169.google.com ([209.85.216.169]:45594 "EHLO mail-qt0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753988AbdJSSQR (ORCPT ); Thu, 19 Oct 2017 14:16:17 -0400 Received: by mail-qt0-f169.google.com with SMTP id p1so15577202qtg.2 for ; Thu, 19 Oct 2017 11:16:16 -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=WYoVMHLH6Qm+O1Vfv1qP5mNTnLdtLvn1XOyzCzJFnY4=; b=MWgyQHGfm+3lPCWXeJmGC2ZWFTvvajMEDtA6uJFKCbbAf4X0Bj4w6UwQTyOOHXxRDr GIecpIA0OAYu+jH1hvsqZm9V6oNAV/kTHy5mtIHuX211GuRNsvnujnzEaakR7dt5Vx3A wVXnzUDV3+Wg4mR+uCM1gC6BttN0NYU+nj46SEuzNcUoIB4PXJZYyvv/OS5HOW9vaO4r mbs4fzJqhF/+hZynA3QEbfHO+rKqFxEo++kP/JdBkrAKx5s6Wk45XA8/Kf/scYKbXUig 29kvVn4h1jysmlVl6HlCqmbCsVUQ79pWKZrC6rijVO+3bPeUqCOlRto2KLO/P0ARDhgo NPag== 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=WYoVMHLH6Qm+O1Vfv1qP5mNTnLdtLvn1XOyzCzJFnY4=; b=p7XTs/I4uyie9x8PAvrgEEtz4f73A5pxMpeG8/ootJywITHW+5x1sA+5bs3zw8Z2iy 8hj7Yk/pl5Gh8N1n1pIbTN/daN2DYgxBFASykaGym7FGfO3oUdF+Cc+rWmPImNIrCwRB 9XUe0FJrylJeJjbdGGU4NTas63pFJG9HzBzGAn9v6mU6E7UCGdUWLNtLbk92cJn6Fz1c mhucIZnXLaA1NvEs9eArFkyo+OuyTzLpeJql58gD2Rav9YPy+yyv/GdOaKkf75Z4cRSs W3YPiq6o36Pp2csLXIay04FQc7+w9seihtP1H2BK/VOe68+wNYl3QHLprzSd//z3xF0j iiNA== X-Gm-Message-State: AMCzsaUnIluYNxjKn96igh/z45cgG8eJng+8mjxGZ1DGNaQhjwUeIz/X O/Z4PXmNHUig6sOM+f2d9d4c+w== X-Google-Smtp-Source: ABhQp+Rr9xFe+euP5HoEbAHsrQUJeceQ2l97D5J3/B/oFBhZEs3RsuB1Dywj29e2rAPsmkfSXz/SWg== X-Received: by 10.200.34.239 with SMTP id g44mr3200539qta.111.1508436976555; Thu, 19 Oct 2017 11:16:16 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id q186sm9287437qkf.26.2017.10.19.11.16.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Oct 2017 11:16:15 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 7/8] btrfs: don't call btrfs_start_delalloc_roots in flushoncommit Date: Thu, 19 Oct 2017 14:16:01 -0400 Message-Id: <1508436962-6851-8-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1508436962-6851-1-git-send-email-josef@toxicpanda.com> References: <1508436962-6851-1-git-send-email-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 We're holding the sb_start_intwrite lock at this point, and doing async filemap_flush of the inodes will result in a deadlock if we freeze the fs during this operation. This is because we could do a btrfs_join_transaction() in the thread we are waiting on which would block at sb_start_intwrite, and thus deadlock. Using writeback_inodes_sb() side steps the problem by not introducing all of these extra locking dependencies. Signed-off-by: Josef Bacik --- fs/btrfs/transaction.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 68c3e1c04bca..5a8c2649af2f 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1916,8 +1916,17 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans, static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info) { + /* + * We use writeback_inodes_sb here because if we used + * btrfs_start_delalloc_roots we would deadlock with fs freeze. + * Currently are holding the fs freeze lock, if we do an async flush + * we'll do btrfs_join_transaction() and deadlock because we need to + * wait for the fs freeze lock. Using the direct flushing we benefit + * from already being in a transaction and our join_transaction doesn't + * have to re-take the fs freeze lock. + */ if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) - return btrfs_start_delalloc_roots(fs_info, 1, -1); + writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC); return 0; }