Skip to content

Commit db27571

Browse files
jtlaytongregkh
authored andcommitted
ceph: don't clobber i_snap_caps on non-I_NEW inode
[ Upstream commit d3c51ae ] We want the snapdir to mirror the non-snapped directory's attributes for most things, but i_snap_caps represents the caps granted on the snapshot directory by the MDS itself. A misbehaving MDS could issue different caps for the snapdir and we lose them here. Only reset i_snap_caps when the inode is I_NEW. Also, move the setting of i_op and i_fop inside the if block since they should never change anyway. Reported-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 2783c34 commit db27571

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

fs/ceph/inode.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ struct inode *ceph_get_snapdir(struct inode *parent)
8787
inode->i_mtime = parent->i_mtime;
8888
inode->i_ctime = parent->i_ctime;
8989
inode->i_atime = parent->i_atime;
90-
inode->i_op = &ceph_snapdir_iops;
91-
inode->i_fop = &ceph_snapdir_fops;
92-
ci->i_snap_caps = CEPH_CAP_PIN; /* so we can open */
9390
ci->i_rbytes = 0;
9491
ci->i_btime = ceph_inode(parent)->i_btime;
9592

96-
if (inode->i_state & I_NEW)
93+
if (inode->i_state & I_NEW) {
94+
inode->i_op = &ceph_snapdir_iops;
95+
inode->i_fop = &ceph_snapdir_fops;
96+
ci->i_snap_caps = CEPH_CAP_PIN; /* so we can open */
9797
unlock_new_inode(inode);
98+
}
9899

99100
return inode;
100101
}

0 commit comments

Comments
 (0)