Commit 195d3ce2 authored by Sage Weil's avatar Sage Weil

ceph: return EBADF if waiting for caps on closed file

Verify the file is actually open for the given caps when we are
waiting for caps.  This ensures we will wake up and return EBADF
if another thread closes the file out from under us.

Note that EBADF is also the correct return code from write(2)
when called on a file handle opened for reading (although the
vfs should catch that).
Signed-off-by: default avatarSage Weil <sage@newdream.net>
parent 6f863e71
...@@ -1923,14 +1923,17 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, ...@@ -1923,14 +1923,17 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
struct inode *inode = &ci->vfs_inode; struct inode *inode = &ci->vfs_inode;
int ret = 0; int ret = 0;
int have, implemented; int have, implemented;
int file_wanted;
dout("get_cap_refs %p need %s want %s\n", inode, dout("get_cap_refs %p need %s want %s\n", inode,
ceph_cap_string(need), ceph_cap_string(want)); ceph_cap_string(need), ceph_cap_string(want));
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
/* make sure we _have_ some caps! */ /* make sure file is actually open */
if (!__ceph_is_any_caps(ci)) { file_wanted = __ceph_caps_file_wanted(ci);
dout("get_cap_refs %p no real caps\n", inode); if ((file_wanted & need) == 0) {
dout("try_get_cap_refs need %s file_wanted %s, EBADF\n",
ceph_cap_string(need), ceph_cap_string(file_wanted));
*err = -EBADF; *err = -EBADF;
ret = 1; ret = 1;
goto out; goto out;
......
...@@ -262,6 +262,9 @@ int ceph_release(struct inode *inode, struct file *file) ...@@ -262,6 +262,9 @@ int ceph_release(struct inode *inode, struct file *file)
kfree(cf->dir_info); kfree(cf->dir_info);
dput(cf->dentry); dput(cf->dentry);
kmem_cache_free(ceph_file_cachep, cf); kmem_cache_free(ceph_file_cachep, cf);
/* wake up anyone waiting for caps on this inode */
wake_up(&ci->i_cap_wq);
return 0; return 0;
} }
......
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