Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753826AbaKJQl7 (ORCPT ); Mon, 10 Nov 2014 11:41:59 -0500 Received: from mail-qg0-f51.google.com ([209.85.192.51]:46876 "EHLO mail-qg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753682AbaKJQko (ORCPT ); Mon, 10 Nov 2014 11:40:44 -0500 From: Milosz Tanski To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Christoph Hellwig , linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, Mel Gorman , Volker Lendecke , Tejun Heo , Jeff Moyer , "Theodore Ts'o" , Al Viro , linux-api@vger.kernel.org, Michael Kerrisk , linux-arch@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH v6 5/7] xfs: add RWF_NONBLOCK support Date: Mon, 10 Nov 2014 11:40:28 -0500 Message-Id: X-Mailer: git-send-email 2.0.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig Add support for non-blocking reads. The guts are handled by the generic code, the only addition is a non-blocking variant of xfs_rw_ilock. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_file.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index b1f6334..0655915 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -61,6 +61,25 @@ xfs_rw_ilock( xfs_ilock(ip, type); } +static inline bool +xfs_rw_ilock_nowait( + struct xfs_inode *ip, + int type) +{ + if (type & XFS_IOLOCK_EXCL) { + if (!mutex_trylock(&VFS_I(ip)->i_mutex)) + return false; + if (!xfs_ilock_nowait(ip, type)) { + mutex_unlock(&VFS_I(ip)->i_mutex); + return false; + } + } else { + if (!xfs_ilock_nowait(ip, type)) + return false; + } + return true; +} + static inline void xfs_rw_iunlock( struct xfs_inode *ip, @@ -246,10 +265,6 @@ xfs_file_read_iter( XFS_STATS_INC(xs_read_calls); - /* XXX: need a non-blocking iolock helper, shouldn't be too hard */ - if (iocb->ki_rwflags & RWF_NONBLOCK) - return -EAGAIN; - if (unlikely(file->f_flags & O_DIRECT)) ioflags |= XFS_IO_ISDIRECT; if (file->f_mode & FMODE_NOCMTIME) @@ -287,7 +302,14 @@ xfs_file_read_iter( * This allows the normal direct IO case of no page cache pages to * proceeed concurrently without serialisation. */ - xfs_rw_ilock(ip, XFS_IOLOCK_SHARED); + if (iocb->ki_rwflags & RWF_NONBLOCK) { + if (ioflags & XFS_IO_ISDIRECT) + return -EAGAIN; + if (!xfs_rw_ilock_nowait(ip, XFS_IOLOCK_SHARED)) + return -EAGAIN; + } else { + xfs_rw_ilock(ip, XFS_IOLOCK_SHARED); + } if ((ioflags & XFS_IO_ISDIRECT) && inode->i_mapping->nrpages) { xfs_rw_iunlock(ip, XFS_IOLOCK_SHARED); xfs_rw_ilock(ip, XFS_IOLOCK_EXCL); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/