From patchwork Wed Jun 22 12:25:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9193145 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 68FBD6075F for ; Wed, 22 Jun 2016 15:23:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5847428408 for ; Wed, 22 Jun 2016 15:23:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C6152840F; Wed, 22 Jun 2016 15:23:04 +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 lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 95A9128408 for ; Wed, 22 Jun 2016 15:23:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bFjzS-0002I9-6O; Wed, 22 Jun 2016 15:22:54 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bFjzR-0002Hz-33 for v9fs-developer@lists.sourceforge.net; Wed, 22 Jun 2016 15:22:53 +0000 Received-SPF: softfail (sog-mx-3.v43.ch3.sourceforge.com: transitioning domain of kaod.org does not designate 148.163.156.1 as permitted sender) client-ip=148.163.156.1; envelope-from=groug@kaod.org; helo=mx0a-001b2d01.pphosted.com; Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1bFjzP-0006c9-SP for v9fs-developer@lists.sourceforge.net; Wed, 22 Jun 2016 15:22:53 +0000 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5MCMPmT108884 for ; Wed, 22 Jun 2016 08:25:50 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 23qcxe8s3s-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Jun 2016 08:25:50 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Jun 2016 06:25:49 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Jun 2016 06:25:46 -0600 X-IBM-Helo: d03dlp02.boulder.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id D4BE33E40030; Wed, 22 Jun 2016 06:25:44 -0600 (MDT) Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5MCPkW443319526; Wed, 22 Jun 2016 12:25:46 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38911AC040; Wed, 22 Jun 2016 08:25:44 -0400 (EDT) Received: from bahia.lan (unknown [9.83.174.77]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id E126CAC03C; Wed, 22 Jun 2016 08:25:42 -0400 (EDT) From: Greg Kurz To: Eric Van Hensbergen Date: Wed, 22 Jun 2016 14:25:41 +0200 In-Reply-To: <146659832556.15781.17414806975641516683.stgit@bahia.lan> References: <146659832556.15781.17414806975641516683.stgit@bahia.lan> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16062212-0028-0000-0000-000005031D16 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062212-0029-0000-0000-00002CE29C01 Message-Id: <146659834177.15781.12052106001087696136.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-22_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606220132 X-Headers-End: 1bFjzP-0006c9-SP Cc: Latchesar Ionkov , linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, Ron Minnich , v9fs-developer@lists.sourceforge.net, "David S. Miller" Subject: [V9fs-developer] [PATCH 2/3] fs/9p: track open fids X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: v9fs-developer-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP From: Greg Kurz This patch adds accounting of open fids in a list hanging off the i_private field of the corresponding inode. This allows faster lookups compared to searching the full 9p client list. The lookup code is modified accordingly. Signed-off-by: Greg Kurz --- fs/9p/fid.c | 31 ++++++++++++++++++++++--------- fs/9p/fid.h | 1 + fs/9p/vfs_dir.c | 5 +++++ fs/9p/vfs_file.c | 1 + fs/9p/vfs_inode.c | 6 +++++- fs/9p/vfs_inode_dotl.c | 1 + include/net/9p/client.h | 3 +++ 7 files changed, 38 insertions(+), 10 deletions(-) ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape diff --git a/fs/9p/fid.c b/fs/9p/fid.c index e6f81f327407..6ac68df50dca 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -54,7 +54,7 @@ void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) } /** - * v9fs_fid_find_inode - search for a fid off of the client list + * v9fs_fid_find_inode - search for an open fid off of the inode list * @inode: return a fid pointing to a specific inode * @uid: return a fid belonging to the specified user * @@ -62,25 +62,38 @@ void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) static struct p9_fid *v9fs_fid_find_inode(struct inode *inode, kuid_t uid) { - struct p9_client *clnt = v9fs_inode2v9ses(inode)->clnt; - struct p9_fid *fid, *fidptr, *ret = NULL; - unsigned long flags; + struct hlist_head *h; + struct p9_fid *fid, *ret = NULL; p9_debug(P9_DEBUG_VFS, " inode: %p\n", inode); - spin_lock_irqsave(&clnt->lock, flags); - list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist) { - if (uid_eq(fid->uid, uid) && - (inode->i_ino == v9fs_qid2ino(&fid->qid))) { + spin_lock(&inode->i_lock); + h = (struct hlist_head *)&inode->i_private; + hlist_for_each_entry(fid, h, ilist) { + if (uid_eq(fid->uid, uid)) { ret = fid; break; } } - spin_unlock_irqrestore(&clnt->lock, flags); + spin_unlock(&inode->i_lock); return ret; } /** + * v9fs_open_fid_add - add an open fid to an inode + * @dentry: inode that the fid is being added to + * @fid: fid to add + * + */ + +void v9fs_open_fid_add(struct inode *inode, struct p9_fid *fid) +{ + spin_lock(&inode->i_lock); + hlist_add_head(&fid->ilist, (struct hlist_head *)&inode->i_private); + spin_unlock(&inode->i_lock); +} + +/** * v9fs_fid_find - retrieve a fid that belongs to the specified uid * @dentry: dentry to look for fid in * @uid: return fid that belongs to the specified user diff --git a/fs/9p/fid.h b/fs/9p/fid.h index 2b6787fcb626..1042bfa06332 100644 --- a/fs/9p/fid.h +++ b/fs/9p/fid.h @@ -27,4 +27,5 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry); struct p9_fid *v9fs_fid_clone(struct dentry *dentry); void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid); struct p9_fid *v9fs_writeback_fid(struct dentry *dentry); +void v9fs_open_fid_add(struct inode *inode, struct p9_fid *fid); #endif diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index b0405d6aac85..6de4f0734cc4 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -238,6 +238,11 @@ int v9fs_dir_release(struct inode *inode, struct file *filp) fid = filp->private_data; p9_debug(P9_DEBUG_VFS, "inode: %p filp: %p fid: %d\n", inode, filp, fid ? fid->fid : -1); + + spin_lock(&inode->i_lock); + hlist_del(&fid->ilist); + spin_unlock(&inode->i_lock); + if (fid) p9_client_clunk(fid); return 0; diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index b84c291ba1eb..db85afdc476a 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -111,6 +111,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) mutex_unlock(&v9inode->v_mutex); if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) v9fs_cache_inode_set_cookie(inode, file); + v9fs_open_fid_add(inode, fid); return 0; out_error: p9_client_clunk(file->private_data); diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 729144ad0c2c..2fb4e7a9d9bb 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -278,6 +278,7 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses, inode->i_rdev = rdev; inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_mapping->a_ops = &v9fs_addr_operations; + inode->i_private = NULL; switch (mode & S_IFMT) { case S_IFIFO: @@ -856,6 +857,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry, struct v9fs_session_info *v9ses; struct p9_fid *fid, *inode_fid; struct dentry *res = NULL; + struct inode *inode; if (d_unhashed(dentry)) { res = v9fs_vfs_lookup(dir, dentry, 0); @@ -884,7 +886,8 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry, } v9fs_invalidate_inode_attr(dir); - v9inode = V9FS_I(d_inode(dentry)); + inode = d_inode(dentry); + v9inode = V9FS_I(inode); mutex_lock(&v9inode->v_mutex); if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) && !v9inode->writeback_fid && @@ -912,6 +915,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry, file->private_data = fid; if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) v9fs_cache_inode_set_cookie(d_inode(dentry), file); + v9fs_open_fid_add(inode, fid); *opened |= FILE_CREATED; out: diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index a34702c998f5..2d7618b388db 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -355,6 +355,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, file->private_data = ofid; if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) v9fs_cache_inode_set_cookie(inode, file); + v9fs_open_fid_add(inode, ofid); *opened |= FILE_CREATED; out: v9fs_put_acl(dacl, pacl); diff --git a/include/net/9p/client.h b/include/net/9p/client.h index c6b97e58cf84..3ee46a6e32ba 100644 --- a/include/net/9p/client.h +++ b/include/net/9p/client.h @@ -194,6 +194,9 @@ struct p9_fid { struct list_head flist; struct hlist_node dlist; /* list of all fids attached to a dentry */ + struct hlist_node ilist; /* list of all open fids attached to an + * inode + */ }; /**