Commit 45089142 authored by Aneesh Kumar K.V's avatar Aneesh Kumar K.V Committed by Eric Van Hensbergen

fs/9p: Don't update file type when updating file attributes

We should only update attributes that we can change on stat2inode.
Also do file type initialization in v9fs_init_inode.
Signed-off-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: default avatarEric Van Hensbergen <ericvh@gmail.com>
parent 5441ae5e
...@@ -54,9 +54,9 @@ extern struct kmem_cache *v9fs_inode_cache; ...@@ -54,9 +54,9 @@ extern struct kmem_cache *v9fs_inode_cache;
struct inode *v9fs_alloc_inode(struct super_block *sb); struct inode *v9fs_alloc_inode(struct super_block *sb);
void v9fs_destroy_inode(struct inode *inode); void v9fs_destroy_inode(struct inode *inode);
struct inode *v9fs_get_inode(struct super_block *sb, int mode); struct inode *v9fs_get_inode(struct super_block *sb, int mode, dev_t);
int v9fs_init_inode(struct v9fs_session_info *v9ses, int v9fs_init_inode(struct v9fs_session_info *v9ses,
struct inode *inode, int mode); struct inode *inode, int mode, dev_t);
void v9fs_evict_inode(struct inode *inode); void v9fs_evict_inode(struct inode *inode);
ino_t v9fs_qid2ino(struct p9_qid *qid); ino_t v9fs_qid2ino(struct p9_qid *qid);
void v9fs_stat2inode(struct p9_wstat *, struct inode *, struct super_block *); void v9fs_stat2inode(struct p9_wstat *, struct inode *, struct super_block *);
......
...@@ -95,15 +95,18 @@ static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode) ...@@ -95,15 +95,18 @@ static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
/** /**
* p9mode2unixmode- convert plan9 mode bits to unix mode bits * p9mode2unixmode- convert plan9 mode bits to unix mode bits
* @v9ses: v9fs session information * @v9ses: v9fs session information
* @mode: mode to convert * @stat: p9_wstat from which mode need to be derived
* @rdev: major number, minor number in case of device files.
* *
*/ */
static int p9mode2unixmode(struct v9fs_session_info *v9ses,
static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) struct p9_wstat *stat, dev_t *rdev)
{ {
int res; int res;
int mode = stat->mode;
res = mode & 0777; res = mode & S_IALLUGO;
*rdev = 0;
if ((mode & P9_DMDIR) == P9_DMDIR) if ((mode & P9_DMDIR) == P9_DMDIR)
res |= S_IFDIR; res |= S_IFDIR;
...@@ -116,9 +119,26 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) ...@@ -116,9 +119,26 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
&& (v9ses->nodev == 0)) && (v9ses->nodev == 0))
res |= S_IFIFO; res |= S_IFIFO;
else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses)) else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses))
&& (v9ses->nodev == 0)) && (v9ses->nodev == 0)) {
char type = 0, ext[32];
int major = -1, minor = -1;
strncpy(ext, stat->extension, sizeof(ext));
sscanf(ext, "%c %u %u", &type, &major, &minor);
switch (type) {
case 'c':
res |= S_IFCHR;
break;
case 'b':
res |= S_IFBLK; res |= S_IFBLK;
else break;
default:
P9_DPRINTK(P9_DEBUG_ERROR,
"Unknown special type %c %s\n", type,
stat->extension);
};
*rdev = MKDEV(major, minor);
} else
res |= S_IFREG; res |= S_IFREG;
if (v9fs_proto_dotu(v9ses)) { if (v9fs_proto_dotu(v9ses)) {
...@@ -131,7 +151,6 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) ...@@ -131,7 +151,6 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
if ((mode & P9_DMSETVTX) == P9_DMSETVTX) if ((mode & P9_DMSETVTX) == P9_DMSETVTX)
res |= S_ISVTX; res |= S_ISVTX;
} }
return res; return res;
} }
...@@ -242,13 +261,13 @@ void v9fs_destroy_inode(struct inode *inode) ...@@ -242,13 +261,13 @@ void v9fs_destroy_inode(struct inode *inode)
} }
int v9fs_init_inode(struct v9fs_session_info *v9ses, int v9fs_init_inode(struct v9fs_session_info *v9ses,
struct inode *inode, int mode) struct inode *inode, int mode, dev_t rdev)
{ {
int err = 0; int err = 0;
inode_init_owner(inode, NULL, mode); inode_init_owner(inode, NULL, mode);
inode->i_blocks = 0; inode->i_blocks = 0;
inode->i_rdev = 0; inode->i_rdev = rdev;
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
inode->i_mapping->a_ops = &v9fs_addr_operations; inode->i_mapping->a_ops = &v9fs_addr_operations;
...@@ -335,7 +354,7 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses, ...@@ -335,7 +354,7 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses,
* *
*/ */
struct inode *v9fs_get_inode(struct super_block *sb, int mode) struct inode *v9fs_get_inode(struct super_block *sb, int mode, dev_t rdev)
{ {
int err; int err;
struct inode *inode; struct inode *inode;
...@@ -348,7 +367,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) ...@@ -348,7 +367,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n"); P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
err = v9fs_init_inode(v9ses, inode, mode); err = v9fs_init_inode(v9ses, inode, mode, rdev);
if (err) { if (err) {
iput(inode); iput(inode);
return ERR_PTR(err); return ERR_PTR(err);
...@@ -435,11 +454,12 @@ void v9fs_evict_inode(struct inode *inode) ...@@ -435,11 +454,12 @@ void v9fs_evict_inode(struct inode *inode)
static int v9fs_test_inode(struct inode *inode, void *data) static int v9fs_test_inode(struct inode *inode, void *data)
{ {
int umode; int umode;
dev_t rdev;
struct v9fs_inode *v9inode = V9FS_I(inode); struct v9fs_inode *v9inode = V9FS_I(inode);
struct p9_wstat *st = (struct p9_wstat *)data; struct p9_wstat *st = (struct p9_wstat *)data;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
umode = p9mode2unixmode(v9ses, st->mode); umode = p9mode2unixmode(v9ses, st, &rdev);
/* don't match inode of different type */ /* don't match inode of different type */
if ((inode->i_mode & S_IFMT) != (umode & S_IFMT)) if ((inode->i_mode & S_IFMT) != (umode & S_IFMT))
return 0; return 0;
...@@ -473,6 +493,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb, ...@@ -473,6 +493,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
struct p9_wstat *st, struct p9_wstat *st,
int new) int new)
{ {
dev_t rdev;
int retval, umode; int retval, umode;
unsigned long i_ino; unsigned long i_ino;
struct inode *inode; struct inode *inode;
...@@ -496,8 +517,8 @@ static struct inode *v9fs_qid_iget(struct super_block *sb, ...@@ -496,8 +517,8 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
* later. * later.
*/ */
inode->i_ino = i_ino; inode->i_ino = i_ino;
umode = p9mode2unixmode(v9ses, st->mode); umode = p9mode2unixmode(v9ses, st, &rdev);
retval = v9fs_init_inode(v9ses, inode, umode); retval = v9fs_init_inode(v9ses, inode, umode, rdev);
if (retval) if (retval)
goto error; goto error;
...@@ -1084,6 +1105,7 @@ void ...@@ -1084,6 +1105,7 @@ void
v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode, v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
struct super_block *sb) struct super_block *sb)
{ {
mode_t mode;
char ext[32]; char ext[32];
char tag_name[14]; char tag_name[14];
unsigned int i_nlink; unsigned int i_nlink;
...@@ -1119,31 +1141,9 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode, ...@@ -1119,31 +1141,9 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
inode->i_nlink = i_nlink; inode->i_nlink = i_nlink;
} }
} }
inode->i_mode = p9mode2unixmode(v9ses, stat->mode); mode = stat->mode & S_IALLUGO;
if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) { mode |= inode->i_mode & ~S_IALLUGO;
char type = 0; inode->i_mode = mode;
int major = -1;
int minor = -1;
strncpy(ext, stat->extension, sizeof(ext));
sscanf(ext, "%c %u %u", &type, &major, &minor);
switch (type) {
case 'c':
inode->i_mode &= ~S_IFBLK;
inode->i_mode |= S_IFCHR;
break;
case 'b':
break;
default:
P9_DPRINTK(P9_DEBUG_ERROR,
"Unknown special type %c %s\n", type,
stat->extension);
};
inode->i_rdev = MKDEV(major, minor);
init_special_inode(inode, inode->i_mode, inode->i_rdev);
} else
inode->i_rdev = 0;
i_size_write(inode, stat->length); i_size_write(inode, stat->length);
/* not real number of blocks, but 512 byte ones ... */ /* not real number of blocks, but 512 byte ones ... */
...@@ -1409,6 +1409,8 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) ...@@ -1409,6 +1409,8 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode) int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
{ {
int umode;
dev_t rdev;
loff_t i_size; loff_t i_size;
struct p9_wstat *st; struct p9_wstat *st;
struct v9fs_session_info *v9ses; struct v9fs_session_info *v9ses;
...@@ -1417,6 +1419,12 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode) ...@@ -1417,6 +1419,12 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
st = p9_client_stat(fid); st = p9_client_stat(fid);
if (IS_ERR(st)) if (IS_ERR(st))
return PTR_ERR(st); return PTR_ERR(st);
/*
* Don't update inode if the file type is different
*/
umode = p9mode2unixmode(v9ses, st, &rdev);
if ((inode->i_mode & S_IFMT) != (umode & S_IFMT))
goto out;
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
/* /*
...@@ -1428,6 +1436,7 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode) ...@@ -1428,6 +1436,7 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
if (v9ses->cache) if (v9ses->cache)
inode->i_size = i_size; inode->i_size = i_size;
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
out:
p9stat_free(st); p9stat_free(st);
kfree(st); kfree(st);
return 0; return 0;
......
...@@ -153,7 +153,8 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb, ...@@ -153,7 +153,8 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
* later. * later.
*/ */
inode->i_ino = i_ino; inode->i_ino = i_ino;
retval = v9fs_init_inode(v9ses, inode, st->st_mode); retval = v9fs_init_inode(v9ses, inode,
st->st_mode, new_decode_dev(st->st_rdev));
if (retval) if (retval)
goto error; goto error;
...@@ -414,7 +415,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir, ...@@ -414,7 +415,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
* inode with stat. We need to get an inode * inode with stat. We need to get an inode
* so that we can set the acl with dentry * so that we can set the acl with dentry
*/ */
inode = v9fs_get_inode(dir->i_sb, mode); inode = v9fs_get_inode(dir->i_sb, mode, 0);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
err = PTR_ERR(inode); err = PTR_ERR(inode);
goto error; goto error;
...@@ -540,6 +541,7 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr) ...@@ -540,6 +541,7 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
void void
v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode) v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
{ {
mode_t mode;
struct v9fs_inode *v9inode = V9FS_I(inode); struct v9fs_inode *v9inode = V9FS_I(inode);
if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) { if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
...@@ -552,11 +554,10 @@ v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode) ...@@ -552,11 +554,10 @@ v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
inode->i_uid = stat->st_uid; inode->i_uid = stat->st_uid;
inode->i_gid = stat->st_gid; inode->i_gid = stat->st_gid;
inode->i_nlink = stat->st_nlink; inode->i_nlink = stat->st_nlink;
inode->i_mode = stat->st_mode;
inode->i_rdev = new_decode_dev(stat->st_rdev);
if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) mode = stat->st_mode & S_IALLUGO;
init_special_inode(inode, inode->i_mode, inode->i_rdev); mode |= inode->i_mode & ~S_IALLUGO;
inode->i_mode = mode;
i_size_write(inode, stat->st_size); i_size_write(inode, stat->st_size);
inode->i_blocks = stat->st_blocks; inode->i_blocks = stat->st_blocks;
...@@ -664,7 +665,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, ...@@ -664,7 +665,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
fid = NULL; fid = NULL;
} else { } else {
/* Not in cached mode. No need to populate inode with stat */ /* Not in cached mode. No need to populate inode with stat */
inode = v9fs_get_inode(dir->i_sb, S_IFLNK); inode = v9fs_get_inode(dir->i_sb, S_IFLNK, 0);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
err = PTR_ERR(inode); err = PTR_ERR(inode);
goto error; goto error;
...@@ -820,7 +821,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode, ...@@ -820,7 +821,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
* Not in cached mode. No need to populate inode with stat. * Not in cached mode. No need to populate inode with stat.
* socket syscall returns a fd, so we need instantiate * socket syscall returns a fd, so we need instantiate
*/ */
inode = v9fs_get_inode(dir->i_sb, mode); inode = v9fs_get_inode(dir->i_sb, mode, rdev);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
err = PTR_ERR(inode); err = PTR_ERR(inode);
goto error; goto error;
...@@ -886,6 +887,11 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode) ...@@ -886,6 +887,11 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
st = p9_client_getattr_dotl(fid, P9_STATS_ALL); st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
if (IS_ERR(st)) if (IS_ERR(st))
return PTR_ERR(st); return PTR_ERR(st);
/*
* Don't update inode if the file type is different
*/
if ((inode->i_mode & S_IFMT) != (st->st_mode & S_IFMT))
goto out;
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
/* /*
...@@ -897,6 +903,7 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode) ...@@ -897,6 +903,7 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
if (v9ses->cache) if (v9ses->cache)
inode->i_size = i_size; inode->i_size = i_size;
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
out:
kfree(st); kfree(st);
return 0; return 0;
} }
......
...@@ -149,7 +149,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags, ...@@ -149,7 +149,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
else else
sb->s_d_op = &v9fs_dentry_operations; sb->s_d_op = &v9fs_dentry_operations;
inode = v9fs_get_inode(sb, S_IFDIR | mode); inode = v9fs_get_inode(sb, S_IFDIR | mode, 0);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
retval = PTR_ERR(inode); retval = PTR_ERR(inode);
goto release_sb; goto release_sb;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment