提交 356b720e 编写于 作者: A Al Viro 提交者: Zheng Zengkai

new helper: inode_wrong_type()

stable inclusion
from stable-5.10.63
commit 40ba433a85dbbf5b2e58f2ac6b161ce37ac872fc
bugzilla: 182231 https://gitee.com/openeuler/kernel/issues/I4EFS1

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=40ba433a85dbbf5b2e58f2ac6b161ce37ac872fc

--------------------------------

commit 6e3e2c43 upstream.

inode_wrong_type(inode, mode) returns true if setting inode->i_mode
to given value would've changed the inode type.  We have enough of
those checks open-coded to make a helper worthwhile.
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 b444181f
...@@ -398,7 +398,7 @@ static int v9fs_test_inode(struct inode *inode, void *data) ...@@ -398,7 +398,7 @@ static int v9fs_test_inode(struct inode *inode, void *data)
umode = p9mode2unixmode(v9ses, st, &rdev); 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_wrong_type(inode, umode))
return 0; return 0;
/* compare qid details */ /* compare qid details */
...@@ -1360,7 +1360,7 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode) ...@@ -1360,7 +1360,7 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
* Don't update inode if the file type is different * Don't update inode if the file type is different
*/ */
umode = p9mode2unixmode(v9ses, st, &rdev); umode = p9mode2unixmode(v9ses, st, &rdev);
if ((inode->i_mode & S_IFMT) != (umode & S_IFMT)) if (inode_wrong_type(inode, umode))
goto out; goto out;
/* /*
......
...@@ -59,7 +59,7 @@ static int v9fs_test_inode_dotl(struct inode *inode, void *data) ...@@ -59,7 +59,7 @@ static int v9fs_test_inode_dotl(struct inode *inode, void *data)
struct p9_stat_dotl *st = (struct p9_stat_dotl *)data; struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
/* don't match inode of different type */ /* don't match inode of different type */
if ((inode->i_mode & S_IFMT) != (st->st_mode & S_IFMT)) if (inode_wrong_type(inode, st->st_mode))
return 0; return 0;
if (inode->i_generation != st->st_gen) if (inode->i_generation != st->st_gen)
...@@ -933,7 +933,7 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode) ...@@ -933,7 +933,7 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
/* /*
* Don't update inode if the file type is different * Don't update inode if the file type is different
*/ */
if ((inode->i_mode & S_IFMT) != (st->st_mode & S_IFMT)) if (inode_wrong_type(inode, st->st_mode))
goto out; goto out;
/* /*
......
...@@ -425,8 +425,7 @@ int cifs_get_inode_info_unix(struct inode **pinode, ...@@ -425,8 +425,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
} }
/* if filetype is different, return error */ /* if filetype is different, return error */
if (unlikely(((*pinode)->i_mode & S_IFMT) != if (unlikely(inode_wrong_type(*pinode, fattr.cf_mode))) {
(fattr.cf_mode & S_IFMT))) {
CIFS_I(*pinode)->time = 0; /* force reval */ CIFS_I(*pinode)->time = 0; /* force reval */
rc = -ESTALE; rc = -ESTALE;
goto cgiiu_exit; goto cgiiu_exit;
...@@ -1243,7 +1242,7 @@ cifs_find_inode(struct inode *inode, void *opaque) ...@@ -1243,7 +1242,7 @@ cifs_find_inode(struct inode *inode, void *opaque)
return 0; return 0;
/* don't match inode of different type */ /* don't match inode of different type */
if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT)) if (inode_wrong_type(inode, fattr->cf_mode))
return 0; return 0;
/* if it's not a directory or has no dentries, then flag it */ /* if it's not a directory or has no dentries, then flag it */
......
...@@ -252,7 +252,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) ...@@ -252,7 +252,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
if (ret == -ENOMEM) if (ret == -ENOMEM)
goto out; goto out;
if (ret || fuse_invalid_attr(&outarg.attr) || if (ret || fuse_invalid_attr(&outarg.attr) ||
(outarg.attr.mode ^ inode->i_mode) & S_IFMT) inode_wrong_type(inode, outarg.attr.mode))
goto invalid; goto invalid;
forget_all_cached_acls(inode); forget_all_cached_acls(inode);
...@@ -1062,7 +1062,7 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat, ...@@ -1062,7 +1062,7 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
err = fuse_simple_request(fm, &args); err = fuse_simple_request(fm, &args);
if (!err) { if (!err) {
if (fuse_invalid_attr(&outarg.attr) || if (fuse_invalid_attr(&outarg.attr) ||
(inode->i_mode ^ outarg.attr.mode) & S_IFMT) { inode_wrong_type(inode, outarg.attr.mode)) {
fuse_make_bad(inode); fuse_make_bad(inode);
err = -EIO; err = -EIO;
} else { } else {
...@@ -1699,7 +1699,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, ...@@ -1699,7 +1699,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
} }
if (fuse_invalid_attr(&outarg.attr) || if (fuse_invalid_attr(&outarg.attr) ||
(inode->i_mode ^ outarg.attr.mode) & S_IFMT) { inode_wrong_type(inode, outarg.attr.mode)) {
fuse_make_bad(inode); fuse_make_bad(inode);
err = -EIO; err = -EIO;
goto error; goto error;
......
...@@ -340,7 +340,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid, ...@@ -340,7 +340,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
inode->i_generation = generation; inode->i_generation = generation;
fuse_init_inode(inode, attr); fuse_init_inode(inode, attr);
unlock_new_inode(inode); unlock_new_inode(inode);
} else if ((inode->i_mode ^ attr->mode) & S_IFMT) { } else if (inode_wrong_type(inode, attr->mode)) {
/* Inode has changed type, any I/O on the old should fail */ /* Inode has changed type, any I/O on the old should fail */
fuse_make_bad(inode); fuse_make_bad(inode);
iput(inode); iput(inode);
......
...@@ -202,7 +202,7 @@ static int fuse_direntplus_link(struct file *file, ...@@ -202,7 +202,7 @@ static int fuse_direntplus_link(struct file *file,
inode = d_inode(dentry); inode = d_inode(dentry);
if (!inode || if (!inode ||
get_node_id(inode) != o->nodeid || get_node_id(inode) != o->nodeid ||
((o->attr.mode ^ inode->i_mode) & S_IFMT)) { inode_wrong_type(inode, o->attr.mode)) {
d_invalidate(dentry); d_invalidate(dentry);
dput(dentry); dput(dentry);
goto retry; goto retry;
......
...@@ -322,7 +322,7 @@ nfs_find_actor(struct inode *inode, void *opaque) ...@@ -322,7 +322,7 @@ nfs_find_actor(struct inode *inode, void *opaque)
if (NFS_FILEID(inode) != fattr->fileid) if (NFS_FILEID(inode) != fattr->fileid)
return 0; return 0;
if ((S_IFMT & inode->i_mode) != (S_IFMT & fattr->mode)) if (inode_wrong_type(inode, fattr->mode))
return 0; return 0;
if (nfs_compare_fh(NFS_FH(inode), fh)) if (nfs_compare_fh(NFS_FH(inode), fh))
return 0; return 0;
...@@ -1446,7 +1446,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat ...@@ -1446,7 +1446,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
return 0; return 0;
return -ESTALE; return -ESTALE;
} }
if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && inode_wrong_type(inode, fattr->mode))
return -ESTALE; return -ESTALE;
...@@ -1861,7 +1861,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) ...@@ -1861,7 +1861,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
/* /*
* Make sure the inode's type hasn't changed. * Make sure the inode's type hasn't changed.
*/ */
if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) { if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && inode_wrong_type(inode, fattr->mode)) {
/* /*
* Big trouble! The inode has become a different object. * Big trouble! The inode has become a different object.
*/ */
......
...@@ -376,7 +376,7 @@ nfsd_proc_create(struct svc_rqst *rqstp) ...@@ -376,7 +376,7 @@ nfsd_proc_create(struct svc_rqst *rqstp)
/* Make sure the type and device matches */ /* Make sure the type and device matches */
resp->status = nfserr_exist; resp->status = nfserr_exist;
if (inode && type != (inode->i_mode & S_IFMT)) if (inode && inode_wrong_type(inode, type))
goto out_unlock; goto out_unlock;
} }
......
...@@ -366,7 +366,7 @@ int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected, ...@@ -366,7 +366,7 @@ int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected,
return PTR_ERR(origin); return PTR_ERR(origin);
if (upperdentry && !ovl_is_whiteout(upperdentry) && if (upperdentry && !ovl_is_whiteout(upperdentry) &&
((d_inode(origin)->i_mode ^ d_inode(upperdentry)->i_mode) & S_IFMT)) inode_wrong_type(d_inode(upperdentry), d_inode(origin)->i_mode))
goto invalid; goto invalid;
if (!*stackp) if (!*stackp)
...@@ -724,7 +724,7 @@ struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, ...@@ -724,7 +724,7 @@ struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper,
index = ERR_PTR(-ESTALE); index = ERR_PTR(-ESTALE);
goto out; goto out;
} else if (ovl_dentry_weird(index) || ovl_is_whiteout(index) || } else if (ovl_dentry_weird(index) || ovl_is_whiteout(index) ||
((inode->i_mode ^ d_inode(origin)->i_mode) & S_IFMT)) { inode_wrong_type(inode, d_inode(origin)->i_mode)) {
/* /*
* Index should always be of the same file type as origin * Index should always be of the same file type as origin
* except for the case of a whiteout index. A whiteout * except for the case of a whiteout index. A whiteout
......
...@@ -2775,6 +2775,11 @@ static inline bool execute_ok(struct inode *inode) ...@@ -2775,6 +2775,11 @@ static inline bool execute_ok(struct inode *inode)
return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode); return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode);
} }
static inline bool inode_wrong_type(const struct inode *inode, umode_t mode)
{
return (inode->i_mode ^ mode) & S_IFMT;
}
static inline void file_start_write(struct file *file) static inline void file_start_write(struct file *file)
{ {
if (!S_ISREG(file_inode(file)->i_mode)) if (!S_ISREG(file_inode(file)->i_mode))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册