From patchwork Mon Apr 3 18:53:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 9660259 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 E2ABD6032D for ; Mon, 3 Apr 2017 18:54:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5538284C2 for ; Mon, 3 Apr 2017 18:54:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA156284F0; Mon, 3 Apr 2017 18:54:44 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 90BB0284C2 for ; Mon, 3 Apr 2017 18:54:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752522AbdDCSyh (ORCPT ); Mon, 3 Apr 2017 14:54:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:45919 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752288AbdDCSxn (ORCPT ); Mon, 3 Apr 2017 14:53:43 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 17A2FAB5F; Mon, 3 Apr 2017 18:53:41 +0000 (UTC) From: Goldwyn Rodrigues To: linux-fsdevel@vger.kernel.org Cc: jack@suse.com, hch@infradead.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, sagi@grimberg.me, avi@scylladb.com, axboe@kernel.dk, linux-api@vger.kernel.org, willy@infradead.org, tom.leiming@gmail.com, Goldwyn Rodrigues Subject: [PATCH 2/8] nowait aio: Return if cannot get hold of i_rwsem Date: Mon, 3 Apr 2017 13:53:01 -0500 Message-Id: <20170403185307.6243-3-rgoldwyn@suse.de> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170403185307.6243-1-rgoldwyn@suse.de> References: <20170403185307.6243-1-rgoldwyn@suse.de> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Goldwyn Rodrigues A failure to lock i_rwsem would mean there is I/O being performed by another thread. So, let's bail. Reviewed-by: Christoph Hellwig --- mm/filemap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 1694623..e08f3b9 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2982,7 +2982,12 @@ ssize_t generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) struct inode *inode = file->f_mapping->host; ssize_t ret; - inode_lock(inode); + if (!inode_trylock(inode)) { + /* Don't sleep on inode rwsem */ + if (iocb->ki_flags & IOCB_NOWAIT) + return -EAGAIN; + inode_lock(inode); + } ret = generic_write_checks(iocb, from); if (ret > 0) ret = __generic_file_write_iter(iocb, from);