Commit 6e3e2c43 authored by Al Viro's avatar Al Viro
Browse files

new helper: inode_wrong_type()



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: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent a38fd874
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -399,7 +399,7 @@ static int v9fs_test_inode(struct inode *inode, void *data)

	umode = p9mode2unixmode(v9ses, st, &rdev);
	/* don't match inode of different type */
	if ((inode->i_mode & S_IFMT) != (umode & S_IFMT))
	if (inode_wrong_type(inode, umode))
		return 0;

	/* compare qid details */
@@ -1390,7 +1390,7 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
	 * Don't update inode if the file type is different
	 */
	umode = p9mode2unixmode(v9ses, st, &rdev);
	if ((inode->i_mode & S_IFMT) != (umode & S_IFMT))
	if (inode_wrong_type(inode, umode))
		goto out;

	/*
+2 −2
Original line number Diff line number Diff line
@@ -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;

	/* 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;

	if (inode->i_generation != st->st_gen)
@@ -959,7 +959,7 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
	/*
	 * 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;

	/*
+2 −3
Original line number Diff line number Diff line
@@ -426,8 +426,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
		}

		/* if filetype is different, return error */
		if (unlikely(((*pinode)->i_mode & S_IFMT) !=
		    (fattr.cf_mode & S_IFMT))) {
		if (unlikely(inode_wrong_type(*pinode, fattr.cf_mode))) {
			CIFS_I(*pinode)->time = 0; /* force reval */
			rc = -ESTALE;
			goto cgiiu_exit;
@@ -1249,7 +1248,7 @@ cifs_find_inode(struct inode *inode, void *opaque)
		return 0;

	/* 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;

	/* if it's not a directory or has no dentries, then flag it */
+3 −3
Original line number Diff line number Diff line
@@ -252,7 +252,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
		if (ret == -ENOMEM)
			goto out;
		if (ret || fuse_invalid_attr(&outarg.attr) ||
		    (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
		    inode_wrong_type(inode, outarg.attr.mode))
			goto invalid;

		forget_all_cached_acls(inode);
@@ -1054,7 +1054,7 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
	err = fuse_simple_request(fm, &args);
	if (!err) {
		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);
			err = -EIO;
		} else {
@@ -1703,7 +1703,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *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);
		err = -EIO;
		goto error;
+1 −1
Original line number Diff line number Diff line
@@ -350,7 +350,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
		inode->i_generation = generation;
		fuse_init_inode(inode, attr);
		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 */
		fuse_make_bad(inode);
		iput(inode);
Loading