]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nfs: fix dio deadlock when O_DIRECT flag is flipped
authorPeng Tao <tao.peng@primarydata.com>
Mon, 19 Jan 2015 23:44:29 +0000 (07:44 +0800)
committerLuis Henriques <luis.henriques@canonical.com>
Wed, 4 Feb 2015 10:58:07 +0000 (10:58 +0000)
commit ee8a1a8b160a87dc3a9c81a86796aa4db85ea815 upstream.

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 <tao.peng@primarydata.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
fs/nfs/direct.c

index 73a3023e270286c3c75cff678391e1ce3a192968..ac8e19995f56c5f0268588cf60f1cb8187d8955b 100644 (file)
@@ -214,6 +214,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);