From patchwork Mon Jan 19 23:44:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Tao X-Patchwork-Id: 5661601 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A2AED9F333 for ; Tue, 20 Jan 2015 00:45:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CB6E920351 for ; Tue, 20 Jan 2015 00:45:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0DB520353 for ; Tue, 20 Jan 2015 00:45:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752258AbbATApp (ORCPT ); Mon, 19 Jan 2015 19:45:45 -0500 Received: from mail-pd0-f174.google.com ([209.85.192.174]:33930 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752241AbbATApo (ORCPT ); Mon, 19 Jan 2015 19:45:44 -0500 Received: by mail-pd0-f174.google.com with SMTP id ft15so10270898pdb.5 for ; Mon, 19 Jan 2015 16:45:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3opzjV0OVIBKXf8RCw7tVIywU7Sa8iTB8SNbCIAqtNg=; b=QXraUFj6NMyTJ/2G1q+T/wN3q0zAJ5rQLQkAigY7Xft0sxd+KH8XX7Vd8wFoXVQtaR ELjIDYqt7zlxgzkzrWbA7rDCNLGHeix1d+OggkPHq/gbjbvXdo9FKo6UifyTo2LiicIQ 1U6c9bjZZPuSEHLae6JcsXixwwdeYxJHegQbuowpoGR7uQ/ULNc3iYqTrk5lBtuIkJ4I 4FA5buGYNyTzquuJJguAEBHH+Fivs9qmvetdRQtSJ7sAftfnv7c0OZkqhNBwyztEjwVW gdfb47s6bLLgR+pgzsx4rdTpK4CULGFgYPBb4F3kLRFy6KYxPszpDtLPNbregMjSTF2s ICXQ== X-Gm-Message-State: ALoCoQk76C+NEASQCqtb84cYr5SEtWEtLPbZsCCpi1DQT0Bk4nsy++acvZ70qN1O16KRQoWunQHt X-Received: by 10.70.61.130 with SMTP id p2mr49746944pdr.0.1421714744138; Mon, 19 Jan 2015 16:45:44 -0800 (PST) Received: from localhost.localdomain (ec2-54-65-164-9.ap-northeast-1.compute.amazonaws.com. [54.65.164.9]) by mx.google.com with ESMTPSA id qm7sm1155271pbc.46.2015.01.19.16.45.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Jan 2015 16:45:43 -0800 (PST) From: Peng Tao To: linux-nfs@vger.kernel.org Cc: Trond Myklebust , Christoph Hellwig , Peng Tao Subject: [PATCH v3] nfs: fix dio deadlock when O_DIRECT flag is flipped Date: Tue, 20 Jan 2015 07:44:29 +0800 Message-Id: <1421711069-21378-1-git-send-email-tao.peng@primarydata.com> X-Mailer: git-send-email 1.9.1 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@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=ham 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 only support swap file calling nfs_direct_IO. However, application might be able to get to nfs_direct_IO if it toggles O_DIRECT flag during IO and it can deadlock because we grab inode->i_mutex in nfs_file_direct_write(). So return 0 for such case. Then the generic layer will fall back to buffer IO. Signed-off-by: Peng Tao --- fs/nfs/direct.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index fafeb07..1184118 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -253,6 +253,12 @@ static int nfs_direct_cmp_commit_data_verf(struct nfs_direct_req *dreq, */ ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, loff_t pos) { + struct inode *inode = iocb->ki_filp->f_mapping->host; + + /* we only support swap file calling nfs_direct_IO */ + if (!IS_SWAPFILE(inode)) + return 0; + #ifndef CONFIG_NFS_SWAP dprintk("NFS: nfs_direct_IO (%pD) off/no(%Ld/%lu) EINVAL\n", iocb->ki_filp, (long long) pos, iter->nr_segs);