From patchwork Sat Jan 29 19:26:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 516891 X-Patchwork-Delegate: ericvh@gmail.com Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p0TJREJC020213 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 29 Jan 2011 19:27:34 GMT 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.74) (envelope-from ) id 1PjGRl-0002Ir-2H; Sat, 29 Jan 2011 19:26:57 +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.74) (envelope-from ) id 1PjGRj-0002Im-6E for v9fs-developer@lists.sourceforge.net; Sat, 29 Jan 2011 19:26:55 +0000 X-ACL-Warn: Received: from e23smtp06.au.ibm.com ([202.81.31.148]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.74) id 1PjGRh-0007Or-Of for v9fs-developer@lists.sourceforge.net; Sat, 29 Jan 2011 19:26:55 +0000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp06.au.ibm.com (8.14.4/8.13.1) with ESMTP id p0TJQirC023219 for ; Sun, 30 Jan 2011 06:26:44 +1100 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0TJQkr42289810 for ; Sun, 30 Jan 2011 06:26:46 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0TJQktp004907 for ; Sun, 30 Jan 2011 06:26:46 +1100 Received: from skywalker.in.ibm.com ([9.77.192.95]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p0TJQWTE004824; Sun, 30 Jan 2011 06:26:44 +1100 From: "Aneesh Kumar K.V" To: v9fs-developer@lists.sourceforge.net Date: Sun, 30 Jan 2011 00:56:25 +0530 Message-Id: <1296329186-23807-7-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1296329186-23807-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1296329186-23807-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Spam-Score: -0.0 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1PjGRh-0007Or-Of Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [V9fs-developer] [RFC PATCH -V1 6/7] fs/9p: Add fid to inode in cached mode 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: , MIME-Version: 1.0 Errors-To: v9fs-developer-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 29 Jan 2011 19:27:34 +0000 (UTC) diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index ecdd512..0f62b26 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -86,11 +86,42 @@ int v9fs_file_open(struct inode *inode, struct file *file) } file->private_data = fid; + /* + * In cached mode we need to attach a fid to inode. The fid + * attached to inode will only be used to write back the + * dirty pages. We always request for the open fid in read-write + * mode so that a partial page write which result in page + * read can work. + */ + if (v9ses->cache && !inode->i_private) { + /* + * clone a fid and add it to inode->i_private + * we do it during open time instead of + * page dirty time via write_begin/page_mkwrite + * because we want write after unlink usecase + * to work. + */ + fid = v9fs_fid_clone(file->f_path.dentry); + if (IS_ERR(fid)) { + err = PTR_ERR(fid); + goto out_error; + } + err = p9_client_open(fid, O_RDWR); + if (err < 0) { + p9_client_clunk(fid); + goto out_error; + } + inode->i_private = (void *) fid; + } #ifdef CONFIG_9P_FSCACHE if (v9ses->cache) v9fs_cache_inode_set_cookie(inode, file); #endif return 0; +out_error: + p9_client_clunk(file->private_data); + file->private_data = 0; + return err; } /** diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index b6b939b..908fa08 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -416,6 +416,11 @@ void v9fs_evict_inode(struct inode *inode) #ifdef CONFIG_9P_FSCACHE v9fs_cache_inode_put_cookie(inode); #endif + /* clunk the fid stashed in inode->i_private */ + if (inode->i_private) { + p9_client_clunk((struct p9_fid *)inode->i_private); + inode->i_private = 0; + } } struct inode * @@ -577,7 +582,7 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, u32 perm; int flags; struct v9fs_session_info *v9ses; - struct p9_fid *fid; + struct p9_fid *fid, *inode_fid; struct file *filp; err = 0; @@ -600,6 +605,33 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, /* if we are opening a file, assign the open fid to the file */ if (nd && nd->flags & LOOKUP_OPEN) { + /* + * In cached mode we need to attach a fid to inode. The fid + * attached to inode will only be used to write back the + * dirty pages. We always request for the open fid in read-write + * mode so that a partial page write which result in page + * read can work. + */ + if (v9ses->cache && !dentry->d_inode->i_private) { + /* + * clone a fid and add it to inode->i_private + * we do it during open time instead of + * page dirty time via write_begin/page_mkwrite + * because we want write after unlink usecase + * to work. + */ + inode_fid = v9fs_fid_clone(dentry); + if (IS_ERR(inode_fid)) { + err = PTR_ERR(inode_fid); + goto error; + } + err = p9_client_open(inode_fid, O_RDWR); + if (err < 0) { + p9_client_clunk(inode_fid); + goto error; + } + dentry->d_inode->i_private = (void *) inode_fid; + } filp = lookup_instantiate_filp(nd, dentry, generic_file_open); if (IS_ERR(filp)) { err = PTR_ERR(filp); diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index 265f583..d5aa986 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -142,7 +142,7 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode, mode_t mode; struct v9fs_session_info *v9ses; struct p9_fid *fid = NULL; - struct p9_fid *dfid, *ofid; + struct p9_fid *dfid, *ofid, *inode_fid; struct file *filp; struct p9_qid qid; struct inode *inode; @@ -218,7 +218,33 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode, /* Now set the ACL based on the default value */ v9fs_set_create_acl(dentry, dacl, pacl); - + /* + * In cached mode we need to attach a fid to inode. The fid + * attached to inode will only be used to write back the + * dirty pages. We always request for the open fid in read-write + * mode so that a partial page write which result in page + * read can work. + */ + if (v9ses->cache && !inode->i_private) { + /* + * clone a fid and add it to inode->i_private + * we do it during open time instead of + * page dirty time via write_begin/page_mkwrite + * because we want write after unlink usecase + * to work. + */ + inode_fid = v9fs_fid_clone(dentry); + if (IS_ERR(inode_fid)) { + err = PTR_ERR(inode_fid); + goto error; + } + err = p9_client_open(inode_fid, O_RDWR); + if (err < 0) { + p9_client_clunk(inode_fid); + goto error; + } + inode->i_private = (void *) inode_fid; + } /* Since we are opening a file, assign the open fid to the file */ filp = lookup_instantiate_filp(nd, dentry, generic_file_open); if (IS_ERR(filp)) {