fs/9p: Use truncate_setsize instead of vmtruncate
Subsystems (2)
PATCH 1/4 fs/9p: Use truncate_setsize instead of vmtruncate
convert vmtruncate usage to truncate_setsize. We also writeback
all dirty pages before doing 9p operations and on success call truncate_setsize. This ensure that we continue sanely on failed truncate on the server. The disadvantage is that we are now going to write back the content that get thrown away later as a part of truncate.
--- fs/9p/vfs_inode.c | 16 ++++++++++------ fs/9p/vfs_inode_dotl.c | 12 +++++------- 2 files changed, 15 insertions(+), 13 deletions(-)
fs/9p/vfs_inode.c +10 -6
@@ -971,6 +971,10 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)struct p9_wstat wstat;P9_DPRINTK (P9_DEBUG_VFS ,"\n" ); + retval =inode_change_ok (dentry->d_inode, iattr); +if (retval) +return retval; + retval = -EPERM ; v9ses =v9fs_inode2v9ses (dentry->d_inode); fid =v9fs_fid_lookup (dentry);
@@ -997,12 +1001,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)if (iattr->ia_valid &ATTR_GID ) wstat.n_gid = iattr->ia_gid; } -if ((iattr->ia_valid &ATTR_SIZE ) && - iattr->ia_size !=i_size_read (dentry->d_inode)) { - retval =vmtruncate (dentry->d_inode, iattr->ia_size); -if (retval) -return retval; - } +/* Write all dirty data */ if (S_ISREG (dentry->d_inode->i_mode))filemap_write_and_wait (dentry->d_inode->i_mapping);
@@ -1010,6 +1009,11 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) retval =p9_client_wstat (fid, &wstat);if (retval <0 )return retval; + +if ((iattr->ia_valid &ATTR_SIZE ) && + iattr->ia_size !=i_size_read (dentry->d_inode)) +truncate_setsize (dentry->d_inode, iattr->ia_size); +v9fs_invalidate_inode_attr (dentry->d_inode);setattr_copy (dentry->d_inode, iattr);
fs/9p/vfs_inode_dotl.c +5 -7
@@ -456,12 +456,6 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)if (IS_ERR (fid))return PTR_ERR (fid); -if ((iattr->ia_valid &ATTR_SIZE ) && - iattr->ia_size !=i_size_read (dentry->d_inode)) { - retval =vmtruncate (dentry->d_inode, iattr->ia_size); -if (retval) -return retval; - }/* Write all dirty data */ if (S_ISREG (dentry->d_inode->i_mode))filemap_write_and_wait (dentry->d_inode->i_mapping);
@@ -469,8 +463,12 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr) retval =p9_client_setattr (fid, &p9attr);if (retval <0 )return retval; -v9fs_invalidate_inode_attr (dentry->d_inode); +if ((iattr->ia_valid &ATTR_SIZE ) && + iattr->ia_size !=i_size_read (dentry->d_inode)) +truncate_setsize (dentry->d_inode, iattr->ia_size); + +v9fs_invalidate_inode_attr (dentry->d_inode);setattr_copy (dentry->d_inode, iattr);mark_inode_dirty (dentry->d_inode);if (iattr->ia_valid &ATTR_MODE ) {
Signature · 1 line
1.7.1
PATCH 2/4 fs/9p: Open writeback fid in O_SYNC mode
Older version of protocol don't support tsyncfs operation. So for them force a O_SYNC flag on the server
--- fs/9p/fid.c | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-)
fs/9p/fid.c +13 -2
@@ -286,9 +286,11 @@ static struct p9_fid *v9fs_fid_clone_with_uid(struct dentry *dentry, uid_t uid)struct p9_fid *v9fs_writeback_fid (struct dentry *dentry) { -int err; +int err, flags;struct p9_fid *fid; +struct v9fs_session_info *v9ses; + v9ses =v9fs_inode2v9ses (dentry->d_inode); fid =v9fs_fid_clone_with_uid (dentry,0 );if (IS_ERR (fid)) goto error_out;
@@ -297,8 +299,17 @@ struct p9_fid *v9fs_writeback_fid(struct dentry *dentry)* 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. +* +* we don't have a tsyncfs operation for older version +* of protocol. So make sure the write back fid is +* opened in O_SYNC mode. */ - err =p9_client_open (fid,O_RDWR ); +if (!v9fs_proto_dotl (v9ses)) + flags =O_RDWR |O_SYNC ; +else + flags =O_RDWR ; + + err =p9_client_open (fid, flags);if (err <0 ) {p9_client_clunk (fid); fid =ERR_PTR (err);
Signature · 1 line
1.7.1
PATCH 3/4 fs/9p: Attach writeback_fid on first open with WR flag
In reply to Aneesh Kumar K.VWe don't need writeback fid if we are only doing O_RDONLY open
--- fs/9p/vfs_file.c | 3 ++- fs/9p/vfs_inode.c | 3 ++- fs/9p/vfs_inode_dotl.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-)
fs/9p/vfs_file.c +2 -1
@@ -91,7 +91,8 @@ int v9fs_file_open(struct inode *inode, struct file *file) file->private_data = fid;mutex_lock (&v9inode->v_mutex); -if (v9ses->cache && !v9inode->writeback_fid) { +if (v9ses->cache && !v9inode->writeback_fid && + ((file->f_flags &O_ACCMODE ) !=O_RDONLY )) {/* * clone a fid and add it to writeback_fid * we do it during open time instead of
fs/9p/vfs_inode.c +2 -1
@@ -652,7 +652,8 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,if (nd && nd->flags &LOOKUP_OPEN ) { v9inode =V9FS_I (dentry->d_inode);mutex_lock (&v9inode->v_mutex); -if (v9ses->cache && !v9inode->writeback_fid) { +if (v9ses->cache && !v9inode->writeback_fid && + ((flags &O_ACCMODE ) !=O_RDONLY )) {/* * clone a fid and add it to writeback_fid * we do it during open time instead of
fs/9p/vfs_inode_dotl.c +2 -1
@@ -246,7 +246,8 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode, v9inode =V9FS_I (inode);mutex_lock (&v9inode->v_mutex); -if (v9ses->cache && !v9inode->writeback_fid) { +if (v9ses->cache && !v9inode->writeback_fid && + ((flags &O_ACCMODE ) !=O_RDONLY )) {/* * clone a fid and add it to writeback_fid * we do it during open time instead of
Signature · 1 line
1.7.1
PATCH 4/4 fs/9p: Add v9fs_dentry2v9ses
In reply to Aneesh Kumar K.VAdd the new static inline and use the same
--- fs/9p/acl.c | 4 ++-- fs/9p/fid.c | 6 +++--- fs/9p/v9fs.h | 5 +++++ fs/9p/vfs_inode.c | 6 +++--- fs/9p/vfs_inode_dotl.c | 4 ++-- fs/9p/vfs_super.c | 2 +- 6 files changed, 16 insertions(+), 11 deletions(-)
fs/9p/acl.c +2 -2
@@ -262,7 +262,7 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name,if (strcmp (name,"" ) !=0 )return -EINVAL ; - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry);/* * We allow set/get/list of acl when access=client is not specified */
@@ -312,7 +312,7 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,if (strcmp (name,"" ) !=0 )return -EINVAL ; - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry);/* * set the attribute on the remote. Without even looking at the * xattr value. We leave it to the server to validate
fs/9p/fid.c +3 -3
@@ -134,7 +134,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,struct v9fs_session_info *v9ses;struct p9_fid *fid, *old_fid =NULL ; - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry); access = v9ses->flags &V9FS_ACCESS_MASK ; fid =v9fs_fid_find (dentry, uid, any);if (fid)
@@ -237,7 +237,7 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)int any, access;struct v9fs_session_info *v9ses; - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry); access = v9ses->flags &V9FS_ACCESS_MASK ;switch (access) {case V9FS_ACCESS_SINGLE :
@@ -290,7 +290,7 @@ struct p9_fid *v9fs_writeback_fid(struct dentry *dentry)struct p9_fid *fid;struct v9fs_session_info *v9ses; - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry); fid =v9fs_fid_clone_with_uid (dentry,0 );if (IS_ERR (fid)) goto error_out;
fs/9p/v9fs.h +5 -0
@@ -174,6 +174,11 @@ static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)return (inode->i_sb->s_fs_info); } +static inline struct v9fs_session_info *v9fs_dentry2v9ses (struct dentry *dentry) +{ +return dentry->d_sb->s_fs_info; +} +static inline int v9fs_proto_dotu (struct v9fs_session_info *v9ses) {return v9ses->flags &V9FS_PROTO_2000U ;
fs/9p/vfs_inode.c +3 -3
@@ -936,7 +936,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,P9_DPRINTK (P9_DEBUG_VFS ,"dentry: %p\n" , dentry); err = -EPERM ; - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry);if (v9ses->cache ==CACHE_LOOSE || v9ses->cache ==CACHE_FSCACHE ) {generic_fillattr (dentry->d_inode, stat);return 0 ;
@@ -977,7 +977,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)return retval; retval = -EPERM ; - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry); fid =v9fs_fid_lookup (dentry);if (IS_ERR (fid))return PTR_ERR (fid);
@@ -1139,7 +1139,7 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)P9_DPRINTK (P9_DEBUG_VFS ," %s\n" , dentry->d_name.name); retval = -EPERM ; - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry); fid =v9fs_fid_lookup (dentry);if (IS_ERR (fid))return PTR_ERR (fid);
fs/9p/vfs_inode_dotl.c +2 -2
@@ -395,7 +395,7 @@ v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,P9_DPRINTK (P9_DEBUG_VFS ,"dentry: %p\n" , dentry); err = -EPERM ; - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry);if (v9ses->cache ==CACHE_LOOSE || v9ses->cache ==CACHE_FSCACHE ) {generic_fillattr (dentry->d_inode, stat);return 0 ;
@@ -452,7 +452,7 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr) p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec; retval = -EPERM ; - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry); fid =v9fs_fid_lookup (dentry);if (IS_ERR (fid))return PTR_ERR (fid);
fs/9p/vfs_super.c +1 -1
@@ -262,7 +262,7 @@ static int v9fs_statfs(struct dentry *dentry, struct kstatfs *buf) goto done; } - v9ses =v9fs_inode2v9ses (dentry->d_inode); + v9ses =v9fs_dentry2v9ses (dentry);if (v9fs_proto_dotl (v9ses)) { res =p9_client_statfs (fid, &rs);if (res ==0 ) {
Signature · 1 line
1.7.1