From patchwork Mon Mar 16 18:27:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milosz Tanski X-Patchwork-Id: 6023571 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 74DAABF90F for ; Mon, 16 Mar 2015 18:27:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 928E120439 for ; Mon, 16 Mar 2015 18:27:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BBA9D20453 for ; Mon, 16 Mar 2015 18:27:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933685AbbCPS1e (ORCPT ); Mon, 16 Mar 2015 14:27:34 -0400 Received: from mail-ie0-f181.google.com ([209.85.223.181]:33738 "EHLO mail-ie0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964974AbbCPS13 (ORCPT ); Mon, 16 Mar 2015 14:27:29 -0400 Received: by iecvj10 with SMTP id vj10so174421130iec.0 for ; Mon, 16 Mar 2015 11:27:28 -0700 (PDT) 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:in-reply-to :references:in-reply-to:references; bh=M+ckHuXMNn8ZXOoS5Rvp0NHReGvVlXUAk/2U16geOb0=; b=JznuEYT1Lbb71kVjC5qPZVMth/LYD/V+Yexw9XjHFHiRtEwLZuBz/96IqTfY2SdLFh hARGcvV86ES6LevHBC+K+3aYQUJLeBD2iyFSdZ+Fs5KmIxAZlW3dWfZu9FFYJckE0aP5 t3SaxvkSloqg7jmmYaHnpRlSMYgBxEWUL6fMhszaCu/XiQKMM4HNPk8rM7feeqIROFLj SILm+hrX2oSe0COBt8kNArpJyHUbTkn29USy0ejgXREHeuyGws2f4R5pKfuOuq4az0X5 1n1UGeq9frkxBOd0GTN9vjIK0JvEH94CF2h7L/Opf912vR8fb/A+i0NE8SDWwD41TyqQ Z22Q== X-Gm-Message-State: ALoCoQmPeUwMQer+83fqCeLanukqRU/nJf9Pz1bD0EO8LtfllRdF0lNRl8pBzcMMuEedFA0RJJbN X-Received: by 10.50.254.99 with SMTP id ah3mr27789050igd.12.1426530448451; Mon, 16 Mar 2015 11:27:28 -0700 (PDT) Received: from adfin.com ([65.244.82.98]) by mx.google.com with ESMTPSA id i20sm7210027igh.16.2015.03.16.11.27.26 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Mar 2015 11:27:27 -0700 (PDT) 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, Dave Chinner , Andrew Morton Subject: [PATCH v7 5/5] xfs: add RWF_NONBLOCK support Date: Mon, 16 Mar 2015 14:27:15 -0400 Message-Id: <0a6f2c2297bfbfd7220e3c4d6bce34fc42bc22fb.1426528417.git.milosz@adfin.com> X-Mailer: git-send-email 1.9.3 (Apple Git-50) In-Reply-To: References: In-Reply-To: References: Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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=unavailable 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 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 Acked-by: Dave Chinner --- 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 a38ddc1..69333a7 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -59,6 +59,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, @@ -280,10 +299,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) @@ -321,7 +336,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);