9p: add write-cache support to loose cache mode
Subsystems (2)
PATCH RESEND 1/1 9p: add write-cache support to loose cache mode
Loose cache mode was added primarily to asssist exclusive, read-only mounts (like venti) -- however, there is also a case for using loose write cacheing in support of read/write exclusive mounts. This feature is linked to the loose cache option and is disabled by default.
This code adds the necessary code to support writes through the page cache. Write caches are not used for synthetic files or for files opened in APPEND mode.
--- Documentation/filesystems/9p.txt | 2 fs/9p/9p.h | 2 fs/9p/conv.c | 19 ++++ fs/9p/conv.h | 2 fs/9p/fcall.c | 6 + fs/9p/fid.c | 17 ++-- fs/9p/fid.h | 2 fs/9p/v9fs_vfs.h | 2 fs/9p/vfs_addr.c | 180 ++++++++++++++++++++++++++++++++++++-- fs/9p/vfs_dir.c | 2 fs/9p/vfs_file.c | 58 ++++++++++-- fs/9p/vfs_inode.c | 13 ++- fs/9p/vfs_super.c | 3 - 13 files changed, 264 insertions(+), 44 deletions(-)
Documentation/filesystems/9p.txt +1 -1
@@ -42,7 +42,7 @@ OPTIONS cache=mode specifies a cacheing policy. By default, no caches are used. loose = no attempts are made at consistency, - intended for exclusive, read-only mounts + intended for exclusive mounts debug=n specifies debug level. The debug level is a bitmask. 0x01 = display verbose error messages
fs/9p/9p.h +1 -1
@@ -370,6 +370,6 @@ int v9fs_t_read(struct v9fs_session_info u64 offset, u32 count, struct v9fs_fcall **rcall);int v9fs_t_write (struct v9fs_session_info *v9ses,u32 fid,u64 offset, -u32 count,const char __user * data, +u32 count,const char __user * data,char * kdata,struct v9fs_fcall **rcall);int v9fs_printfcall (char *,int ,struct v9fs_fcall *,int );
fs/9p/conv.c +17 -2
@@ -458,6 +458,15 @@ v9fs_put_user_data(struct cbuf *bufp, coreturn copy_from_user (*pdata, data, count); } +static int +v9fs_put_kernel_data (struct cbuf *bufp,char * kdata,int count, +unsigned char **pdata) +{ + *pdata =buf_alloc (bufp, count); +memcpy (*pdata, kdata, count); +return 0 ; +} +static void v9fs_put_wstat (struct cbuf *bufp,struct v9fs_wstat *wstat,struct v9fs_stat *stat,int statsz,int extended)
@@ -723,7 +732,7 @@ struct v9fs_fcall *v9fs_create_tread(u32 }struct v9fs_fcall *v9fs_create_twrite (u32 fid,u64 offset,u32 count, -const char __user * data) +const char __user * data,char * kdata) {int size, err;struct v9fs_fcall *fc;
@@ -738,7 +747,13 @@ struct v9fs_fcall *v9fs_create_twrite(u3v9fs_put_int32 (bufp, fid, &fc->params.twrite.fid);v9fs_put_int64 (bufp, offset, &fc->params.twrite.offset);v9fs_put_int32 (bufp, count, &fc->params.twrite.count); - err =v9fs_put_user_data (bufp, data, count, &fc->params.twrite.data); +if (data) { + err =v9fs_put_user_data (bufp, data, count, + &fc->params.twrite.data); + }else { + err =v9fs_put_kernel_data (bufp, kdata, count, + &fc->params.twrite.data); + }if (err) {kfree (fc); fc =ERR_PTR (err);
fs/9p/conv.h +1 -1
@@ -42,7 +42,7 @@ struct v9fs_fcall *v9fs_create_tcreate(u char *extension, int extended);struct v9fs_fcall *v9fs_create_tread (u32 fid,u64 offset,u32 count);struct v9fs_fcall *v9fs_create_twrite (u32 fid,u64 offset,u32 count, -const char __user *data); +const char __user *data,char *kdata);struct v9fs_fcall *v9fs_create_tclunk (u32 fid);struct v9fs_fcall *v9fs_create_tremove (u32 fid);struct v9fs_fcall *v9fs_create_tstat (u32 fid);
fs/9p/fcall.c +4 -2
@@ -393,13 +393,15 @@ v9fs_t_read(struct v9fs_session_info *v9* @fid: fid to write to * @offset: offset to start write at * @count: how many bytes to write +* @data: userspace data +* @kdata: kernelspace data * @fcall: pointer to response fcall * */ int v9fs_t_write (struct v9fs_session_info *v9ses,u32 fid,u64 offset,u32 count, -const char __user *data,struct v9fs_fcall **rcp) +const char __user *data,char *kdata,struct v9fs_fcall **rcp) {int ret;struct v9fs_fcall *tc, *rc;
@@ -407,7 +409,7 @@ v9fs_t_write(struct v9fs_session_info *vdprintk (DEBUG_9P ,"fid %d offset 0x%llux count 0x%x\n" , fid, (long long unsigned ) offset, count); - tc =v9fs_create_twrite (fid, offset, count, data); + tc =v9fs_create_twrite (fid, offset, count, data, kdata);if (!IS_ERR (tc)) { ret =v9fs_mux_rpc (v9ses->mux, tc, &rc);
fs/9p/fid.c +9 -8
@@ -40,19 +40,18 @@ #include "fid.h"* */ -int v9fs_fid_insert (struct v9fs_fid *fid,struct dentry *dentry) +int v9fs_fid_insert (struct v9fs_fid *fid,void **priv) { -struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; -dprintk (DEBUG_9P ,"fid %d (%p) dentry %s (%p)\n" , fid->fid, fid, - dentry->d_iname, dentry); -if (dentry->d_fsdata ==NULL ) { - dentry->d_fsdata = +struct list_head *fid_list= (struct list_head *) *priv; + +if (fid_list ==NULL ) { + *priv =kmalloc (sizeof (struct list_head ),GFP_KERNEL ); -if (dentry->d_fsdata ==NULL ) { +if (*priv ==NULL ) {dprintk (DEBUG_ERROR ,"Out of memory\n" );return -ENOMEM ; } - fid_list = (struct list_head *)dentry->d_fsdata; + fid_list = (struct list_head *)*priv;INIT_LIST_HEAD (fid_list);/* Initialize list head */ }
@@ -80,6 +79,7 @@ struct v9fs_fid *v9fs_fid_create(struct new->fid = fid; new->v9ses = v9ses; + new->filp =NULL ; new->fidopen =0 ; new->fidclunked =0 ; new->iounit =0 ;
@@ -192,3 +192,4 @@ void v9fs_fid_clunk(struct v9fs_session_v9fs_t_clunk (v9ses, fid->fid);v9fs_fid_destroy (fid); } +
fs/9p/fid.h +1 -1
@@ -56,7 +56,7 @@ struct v9fs_fid *v9fs_fid_lookup(structstruct v9fs_fid *v9fs_fid_get_created (struct dentry *);void v9fs_fid_destroy (struct v9fs_fid *fid);struct v9fs_fid *v9fs_fid_create (struct v9fs_session_info *,int fid); -int v9fs_fid_insert (struct v9fs_fid *fid,struct dentry *dentry); +int v9fs_fid_insert (struct v9fs_fid *fid,void **priv);struct v9fs_fid *v9fs_fid_clone (struct dentry *dentry);void v9fs_fid_clunk (struct v9fs_session_info *v9ses,struct v9fs_fid *fid);
fs/9p/v9fs_vfs.h +2 -0
@@ -53,3 +53,5 @@ int v9fs_file_open(struct inode *inode,void v9fs_inode2stat (struct inode *inode,struct v9fs_stat *stat);void v9fs_dentry_release (struct dentry *);int v9fs_uflags2omode (int uflags); +ssize_t v9fs_write (struct file *filp,const char __user * data,char * kdata,size_t count,loff_t * offset); +
fs/9p/vfs_addr.c +170 -10
223 lines not on this page · raw message
fs/9p/vfs_dir.c +1 -1
@@ -197,7 +197,7 @@ int v9fs_dir_release(struct inode *inodedprintk (DEBUG_ERROR ,"clunk failed\n" );kfree (fid->rdir_fcall); -kfree (fid); +v9fs_fid_destroy (fid); filp->private_data =NULL ; }
fs/9p/vfs_file.c +45 -13
109 lines not on this page · raw message
fs/9p/vfs_inode.c +10 -3
@@ -208,6 +208,7 @@ struct inode *v9fs_get_inode(struct supe inode->i_rdev =0 ; 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 :
@@ -340,7 +341,7 @@ v9fs_clone_walk(struct v9fs_session_info goto clunk_fid; } - err =v9fs_fid_insert (ret, dentry); + err =v9fs_fid_insert (ret, &dentry->d_fsdata);if (err <0 ) {v9fs_fid_destroy (ret); goto clunk_fid;
@@ -520,13 +521,19 @@ v9fs_vfs_create(struct inode *dir, strucv9fs_fid_destroy (ffid);return PTR_ERR (filp); } - ffid->rdir_pos =0 ; ffid->rdir_fcall =NULL ; ffid->fidopen =1 ; ffid->iounit = iounit; ffid->filp = filp; filp->private_data = ffid; +if ((vfid->qid.version) && (v9ses->cache) && + !(flags &O_APPEND )) { +/* enable cached file options */ +if (filp->f_op == &v9fs_file_operations) + filp->f_op = &v9fs_cached_file_operations; + } +v9fs_fid_insert (ffid, &inode->i_private); }return 0 ;
@@ -696,7 +703,7 @@ static struct dentry *v9fs_vfs_lookup(st goto FreeFcall; } - result =v9fs_fid_insert (fid, dentry); + result =v9fs_fid_insert (fid, &dentry->d_fsdata);if (result <0 ) goto FreeFcall;
fs/9p/vfs_super.c +2 -1
@@ -56,6 +56,7 @@ static const struct super_operations v9fstatic void v9fs_clear_inode (struct inode *inode) {filemap_fdatawrite (inode->i_mapping); +kfree (inode->i_private); }/**
@@ -167,7 +168,7 @@ static int v9fs_get_sb(struct file_syste goto put_back_sb; } - retval =v9fs_fid_insert (root_fid, root); + retval =v9fs_fid_insert (root_fid, &root->d_fsdata);if (retval <0 ) {kfree (fcall); goto put_back_sb;
Signature · 1 line
1.4.1
Quoted 4 lines · On Tue, 13 Feb 2007 17:55:31 -0600 Eric Van Hensbergen <[email protected]> wrote:
fs/9p/vfs_addr.c +3
-0+int v9fs_prepare_write (struct file *file,struct page *page, +unsigned from,unsigned to) +{
fs/9p/vfs_addr.c static int v9fs_vfs_readpage(struct file · line 133
Quoted 10 lines
fs/9p/vfs_addr.c +10
-0+if (!PageUptodate (page)) { +if (to - from !=PAGE_CACHE_SIZE ) { +void *kaddr =kmap_atomic (page,KM_USER0 ); +memset (kaddr,0 , from); +memset (kaddr + to,0 ,PAGE_CACHE_SIZE - to); +flush_dcache_page (page); +kunmap_atomic (kaddr,KM_USER0 ); + } +SetPageUptodate (page); + }
This will mark the page uptodate while the piece between to' and from' is uninitialised. A concurrent pagefault can come in and permit a read of that uninitialised data. Because filemap_nopage() doesn't lock the page if it is uptodate.
Quoted 11 lines · Andrew Morton
Quoted 11 lines · On Tue, 13 Feb 2007 17:55:31 -0600 Eric Van Hensbergen <[email protected]> wrote:
fs/9p/vfs_addr.c +10
-0+int v9fs_prepare_write (struct file *file,struct page *page, +unsigned from,unsigned to) +{ +if (!PageUptodate (page)) { +if (to - from !=PAGE_CACHE_SIZE ) { +void *kaddr =kmap_atomic (page,KM_USER0 ); +memset (kaddr,0 , from); +memset (kaddr + to,0 ,PAGE_CACHE_SIZE - to); +flush_dcache_page (page); +kunmap_atomic (kaddr,KM_USER0 );
Quoted 9 lines
fs/9p/vfs_addr.c static int v9fs_vfs_readpage(struct file · line 133
Quoted 3 lines
fs/9p/vfs_addr.c +3
-0+ } +SetPageUptodate (page); + }This will mark the page uptodate while the piece between
to' andfrom' is uninitialised. A concurrent pagefault can come in and permit a read of that uninitialised data. Becausefilemap_nopage()doesn't lock the page if it is uptodate.
Okay - I snagged this code from fs/libfs.c (simple_prepare_write) -- is that code also not correct, or am I just using it in the wrong context?
-eric
Quoted 23 lines · On Tue, 13 Feb 2007 20:07:44 -0600 "Eric Van Hensbergen" <[email protected]>…
Quoted 11 lines · Andrew Morton
Quoted 11 lines · On Tue, 13 Feb 2007 17:55:31 -0600 Eric Van Hensbergen <[email protected]> wrote:
fs/9p/vfs_addr.c +10
-0+int v9fs_prepare_write (struct file *file,struct page *page, +unsigned from,unsigned to) +{ +if (!PageUptodate (page)) { +if (to - from !=PAGE_CACHE_SIZE ) { +void *kaddr =kmap_atomic (page,KM_USER0 ); +memset (kaddr,0 , from); +memset (kaddr + to,0 ,PAGE_CACHE_SIZE - to); +flush_dcache_page (page); +kunmap_atomic (kaddr,KM_USER0 );Quoted 9 lines
fs/9p/vfs_addr.c static int v9fs_vfs_readpage(struct file · line 133
Quoted 3 lines
fs/9p/vfs_addr.c +3
-0+ } +SetPageUptodate (page); + }This will mark the page uptodate while the piece between
to' andfrom' is uninitialised. A concurrent pagefault can come in and permit a read of that uninitialised data. Becausefilemap_nopage()doesn't lock the page if it is uptodate.
Quoted 4 lines
Okay - I snagged this code from
fs/libfs.c(simple_prepare_write) -- is that code also not correct, or am I just using it in the wrong context?
libfs.c is wrong. Nick has fixes, but they got tangled up in other stuff.
Quoted 24 lines · Andrew Morton
Quoted 24 lines · On Tue, 13 Feb 2007 20:07:44 -0600 "Eric Van Hensbergen" <[email protected]>…
Quoted 20 lines · Andrew Morton
Quoted 4 lines · On Tue, 13 Feb 2007 17:55:31 -0600 Eric Van Hensbergen <[email protected]> wrote:
fs/9p/vfs_addr.c +3
-0+int v9fs_prepare_write (struct file *file,struct page *page, +unsigned from,unsigned to) +{fs/9p/vfs_addr.c static int v9fs_vfs_readpage(struct file · line 133
Quoted 10 lines
fs/9p/vfs_addr.c +10
-0+if (!PageUptodate (page)) { +if (to - from !=PAGE_CACHE_SIZE ) { +void *kaddr =kmap_atomic (page,KM_USER0 ); +memset (kaddr,0 , from); +memset (kaddr + to,0 ,PAGE_CACHE_SIZE - to); +flush_dcache_page (page); +kunmap_atomic (kaddr,KM_USER0 ); + } +SetPageUptodate (page); + }This will mark the page uptodate while the piece between
to' andfrom' is uninitialised. A concurrent pagefault can come in and permit a read of that uninitialised data. Becausefilemap_nopage()doesn't lock the page if it is uptodate.
Quoted 7 lines
Quoted 4 lines
Okay - I snagged this code from
fs/libfs.c(simple_prepare_write) -- is that code also not correct, or am I just using it in the wrong context?
libfs.cis wrong. Nick has fixes, but they got tangled up in other stuff.
Yeah. 1/9 in that series should be applied on its own and sent upstream.
Need me to resend?
Signature · 2 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 6 lines · On Wed, 14 Feb 2007 14:05:44 +1100 Nick Piggin <[email protected]> wrote:
Quoted 1 line
libfs.cis wrong. Nick has fixes, but they got tangled up in other stuff.Yeah. 1/9 in that series should be applied on its own and sent upstream.
Need me to resend?
Yes please.
fs/9p/vfs_addr.c static int v9fs_vfs_readpage(struct file · line 207
Quoted 9 lines · On Tue, 13 Feb 2007 17:55:31 -0600 Eric Van Hensbergen <[email protected]> wrote:
fs/9p/vfs_addr.c +8
-0+static int v9fs_vfs_writepage (struct page *page,struct writeback_control *wbc) +{ +char *buffer =NULL ; +struct address_space *mapping = page->mapping; +int retval = -EIO ; +loff_t offset =0 ; +loff_t pageoffset =0 ; +unsigned long end_index;
Cosmetic detail: pgoff_t here.
Quoted 11 lines
fs/9p/vfs_addr.c +11
-0+int count =PAGE_CACHE_SIZE ; +struct file *filp =v9fs_find_file (page); +struct inode *inode = mapping->host; + +dprintk (DEBUG_VFS ,"page: %p\n" , page); + +if ((!inode) || (!filp)) + goto UnlockPage; + + end_index = inode->i_size >>PAGE_CACHE_SHIFT ; +
fs/9p/vfs_addr.c static int v9fs_vfs_readpage(struct file · line 228
Quoted 10 lines
fs/9p/vfs_addr.c +10
-0+/* complicated case at end of file */ +if (page->index >= end_index) { +/* things got complicated... */ + count = inode->i_size & (PAGE_CACHE_SIZE -1 ); +if (page->index >= end_index +1 || !count) +return 0 ;/* truncated - don't care */ + } + +/* get buffer */ + buffer =kmap (page) + pageoffset;
kmap_atomic() is faster and less deadlocky. But presumably v9fs_write() prevents that.
fs/9p/vfs_addr.c static int v9fs_vfs_readpage(struct file · line 239
Quoted 11 lines
fs/9p/vfs_addr.c +11
-0+ offset = ((loff_t ) page->index <<PAGE_CACHE_SHIFT ) + pageoffset; + +page_cache_get (page); + + retval =v9fs_write (filp,NULL , buffer, count, &offset); + +if (retval <0 ) { +dprintk (DEBUG_ERROR ,"error: %d\n" , retval); +ClearPageUptodate (page); + goto UnmapPage; + }
I think you'll find that the ->writepage() caller handles all this. The callers also set AS_EIO, which this code forgot.
fs/9p/vfs_addr.c static int v9fs_vfs_readpage(struct file · line 247
Quoted 7 lines
fs/9p/vfs_addr.c +7
-0+if (retval < count) { +dprintk (DEBUG_ERROR ,"Short write\n" ); + } + +if (offset > inode->i_size) { + inode->i_size = offset; + }
Can this happen??
If so, mark_inode_dirty() seems to be missing.
fs/9p/vfs_addr.c static int v9fs_vfs_readpage(struct file · line 250
Quoted 2 lines
fs/9p/vfs_addr.c +2
-0+if (PageError (page)) +ClearPageError (page);
Is this needed?
Review
Quoted 1 line
(quoted diff) +1
-0+ SetPageUptodate(page);
I'd expect that v9fs_writepage() is only ever called against uptodate pages?
Quoted 10 lines
fs/9p/vfs_addr.c +6
-0+ retval =0 ; + + UnmapPage:kunmap (page); + UnlockPage:unlock_page (page); +page_cache_release (page); +return retval; }
Quoted 6 lines · On Tue, 13 Feb 2007 17:55:31 -0600 Eric Van Hensbergen <[email protected]> wrote:
fs/9p/vfs_file.c +5
-0+static ssize_t +v9fs_file_write (struct file *filp,const char __user * data, +size_t count,loff_t * offset) +{ +struct inode *inode = filp->f_path.dentry->d_inode;
fs/9p/vfs_file.c v9fs_file_write(struct file *filp, const · line 277
Quoted 10 lines
fs/9p/vfs_file.c +10
-0+ +ssize_t ret; + +dprintk (DEBUG_VFS ,"count %d offset %x\n" , + (int )count, (int )*offset); + ret =v9fs_write (filp, data,NULL , count, offset); +invalidate_inode_pages2 (inode->i_mapping); +return ret; +} +
invalidate_inode_pages2() can fail. It might be worth at least warning here if it does.