From patchwork Mon Mar 23 02:37:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 6068801 Return-Path: X-Original-To: patchwork-linux-fsdevel@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 751429F2A9 for ; Mon, 23 Mar 2015 02:40:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 85B16201FE for ; Mon, 23 Mar 2015 02:40:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7374820219 for ; Mon, 23 Mar 2015 02:40:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752239AbbCWCj5 (ORCPT ); Sun, 22 Mar 2015 22:39:57 -0400 Received: from cantor2.suse.de ([195.135.220.15]:34559 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752530AbbCWCjz (ORCPT ); Sun, 22 Mar 2015 22:39:55 -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 985ADAC77; Mon, 23 Mar 2015 02:39:53 +0000 (UTC) From: NeilBrown To: Al Viro Date: Mon, 23 Mar 2015 13:37:40 +1100 Subject: [PATCH 19/20] XFS: allow follow_link to often succeed in RCU-walk. Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <20150323023740.8161.44210.stgit@notabene.brown> In-Reply-To: <20150323023258.8161.32467.stgit@notabene.brown> References: <20150323023258.8161.32467.stgit@notabene.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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 If LOOKUP_RCU is set, use GFP_ATOMIC rather than GFP_KERNEL, and try to get the ilock without blocking. When these succeed, follow_link() can succeed without dropping out of RCU-walk. As xfs_readlink can now races with xfs_fs_evict_inode: - xfs_readlink must check if the inode is being evicted after getting the lock - xfs_fs_evict_inode cannot assert that the lock is not held. Signed-off-by: NeilBrown --- fs/xfs/xfs_ioctl.c | 2 +- fs/xfs/xfs_iops.c | 15 ++++++++++----- fs/xfs/xfs_super.c | 2 -- fs/xfs/xfs_symlink.c | 15 +++++++++++++-- fs/xfs/xfs_symlink.h | 2 +- 5 files changed, 25 insertions(+), 11 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index ac4feae45eb3..29d95a1b76c0 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -303,7 +303,7 @@ xfs_readlink_by_handle( goto out_dput; } - error = xfs_readlink(XFS_I(dentry->d_inode), link); + error = xfs_readlink(XFS_I(dentry->d_inode), link, 0); if (error) goto out_kfree; error = readlink_copy(hreq->ohandle, olen, link); diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index c2c136ef3a50..631b1ec2e650 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -416,15 +416,20 @@ xfs_vn_follow_link( int flags) { char *link; - int error = -ENOMEM; + int error; - if (flags & LOOKUP_RCU) - return ERR_PTR(-ECHILD); - link = kmalloc(MAXPATHLEN+1, GFP_KERNEL); + if (flags & LOOKUP_RCU) { + error = -ECHILD; + link = kmalloc(MAXPATHLEN+1, GFP_ATOMIC); + } else { + error = -ENOMEM; + link = kmalloc(MAXPATHLEN+1, GFP_KERNEL); + } if (!link) goto out_err; - error = xfs_readlink(XFS_I(inode), link); + error = xfs_readlink(XFS_I(inode), link, + flags & LOOKUP_RCU); if (unlikely(error)) goto out_kfree; diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 3827be14383c..e041fa55912b 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -996,8 +996,6 @@ xfs_fs_evict_inode( { xfs_inode_t *ip = XFS_I(inode); - ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock)); - trace_xfs_evict_inode(ip); truncate_inode_pages_final(&inode->i_data); diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 25791df6f638..228987b8e758 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -123,7 +123,8 @@ xfs_readlink_bmap( int xfs_readlink( struct xfs_inode *ip, - char *link) + char *link, + int rcu) { struct xfs_mount *mp = ip->i_mount; xfs_fsize_t pathlen; @@ -134,7 +135,15 @@ xfs_readlink( if (XFS_FORCED_SHUTDOWN(mp)) return -EIO; - xfs_ilock(ip, XFS_ILOCK_SHARED); + if (rcu) { + if (xfs_ilock_nowait(ip, XFS_ILOCK_SHARED) == 0) + return -ECHILD; + if (ip->i_vnode.i_state & (I_FREEING | I_CLEAR)) { + xfs_iunlock(ip, XFS_ILOCK_EXCL); + return -ECHILD; + } + } else + xfs_ilock(ip, XFS_ILOCK_SHARED); pathlen = ip->i_d.di_size; if (!pathlen) @@ -153,6 +162,8 @@ xfs_readlink( if (ip->i_df.if_flags & XFS_IFINLINE) { memcpy(link, ip->i_df.if_u1.if_data, pathlen); link[pathlen] = '\0'; + } else if (rcu) { + error = -ECHILD; } else { error = xfs_readlink_bmap(ip, link); } diff --git a/fs/xfs/xfs_symlink.h b/fs/xfs/xfs_symlink.h index e75245d09116..a71d26643e20 100644 --- a/fs/xfs/xfs_symlink.h +++ b/fs/xfs/xfs_symlink.h @@ -21,7 +21,7 @@ int xfs_symlink(struct xfs_inode *dp, struct xfs_name *link_name, const char *target_path, umode_t mode, struct xfs_inode **ipp); -int xfs_readlink(struct xfs_inode *ip, char *link); +int xfs_readlink(struct xfs_inode *ip, char *link, int rcu); int xfs_inactive_symlink(struct xfs_inode *ip); #endif /* __XFS_SYMLINK_H */