Skip to content

Commit d9ae977

Browse files
Luís Henriquesidryomov
authored andcommitted
ceph: switch ceph_lookup/atomic_open() to use new fscrypt helper
Instead of setting the no-key dentry, use the new fscrypt_prepare_lookup_partial() helper. We still need to mark the directory as incomplete if the directory was just unlocked. In ceph_atomic_open() this fixes a bug where a dentry is incorrectly set with DCACHE_NOKEY_NAME when 'dir' has been evicted but the key is still available (for example, where there's a drop_caches). Signed-off-by: Luís Henriques <[email protected]> Reviewed-by: Xiubo Li <[email protected]> Reviewed-by: Milind Changire <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 295fc4a commit d9ae977

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

fs/ceph/dir.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -785,14 +785,15 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
785785
return ERR_PTR(-ENAMETOOLONG);
786786

787787
if (IS_ENCRYPTED(dir)) {
788-
err = ceph_fscrypt_prepare_readdir(dir);
788+
bool had_key = fscrypt_has_encryption_key(dir);
789+
790+
err = fscrypt_prepare_lookup_partial(dir, dentry);
789791
if (err < 0)
790792
return ERR_PTR(err);
791-
if (!fscrypt_has_encryption_key(dir)) {
792-
spin_lock(&dentry->d_lock);
793-
dentry->d_flags |= DCACHE_NOKEY_NAME;
794-
spin_unlock(&dentry->d_lock);
795-
}
793+
794+
/* mark directory as incomplete if it has been unlocked */
795+
if (!had_key && fscrypt_has_encryption_key(dir))
796+
ceph_dir_clear_complete(dir);
796797
}
797798

798799
/* can we conclude ENOENT locally? */

fs/ceph/file.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,9 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
791791
ihold(dir);
792792
if (IS_ENCRYPTED(dir)) {
793793
set_bit(CEPH_MDS_R_FSCRYPT_FILE, &req->r_req_flags);
794-
if (!fscrypt_has_encryption_key(dir)) {
795-
spin_lock(&dentry->d_lock);
796-
dentry->d_flags |= DCACHE_NOKEY_NAME;
797-
spin_unlock(&dentry->d_lock);
798-
}
794+
err = fscrypt_prepare_lookup_partial(dir, dentry);
795+
if (err < 0)
796+
goto out_req;
799797
}
800798

801799
if (flags & O_CREAT) {

0 commit comments

Comments
 (0)