Commit 7a971e2c authored by Jeff Layton's avatar Jeff Layton Committed by Ilya Dryomov

ceph: fix error handling in ceph_atomic_open and ceph_lookup

Commit aa60cfc3 broke the error handling in these functions such
that they don't handle non-ENOENT errors from ceph_mdsc_do_request
properly.

Move the checking of -ENOENT out of ceph_handle_snapdir and into the
callers, and if we get a different error, return it immediately.

Fixes: aa60cfc3 ("ceph: don't use d_add in ceph_handle_snapdir")
Signed-off-by: default avatarJeff Layton <jlayton@kernel.org>
Reviewed-by: default avatarIlya Dryomov <idryomov@gmail.com>
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent 27171ae6
...@@ -668,14 +668,13 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int whence) ...@@ -668,14 +668,13 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int whence)
* Handle lookups for the hidden .snap directory. * Handle lookups for the hidden .snap directory.
*/ */
struct dentry *ceph_handle_snapdir(struct ceph_mds_request *req, struct dentry *ceph_handle_snapdir(struct ceph_mds_request *req,
struct dentry *dentry, int err) struct dentry *dentry)
{ {
struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb); struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
struct inode *parent = d_inode(dentry->d_parent); /* we hold i_mutex */ struct inode *parent = d_inode(dentry->d_parent); /* we hold i_mutex */
/* .snap dir? */ /* .snap dir? */
if (err == -ENOENT && if (ceph_snap(parent) == CEPH_NOSNAP &&
ceph_snap(parent) == CEPH_NOSNAP &&
strcmp(dentry->d_name.name, fsc->mount_options->snapdir_name) == 0) { strcmp(dentry->d_name.name, fsc->mount_options->snapdir_name) == 0) {
struct dentry *res; struct dentry *res;
struct inode *inode = ceph_get_snapdir(parent); struct inode *inode = ceph_get_snapdir(parent);
...@@ -742,7 +741,6 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, ...@@ -742,7 +741,6 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(dir->i_sb); struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(dir->i_sb);
struct ceph_mds_request *req; struct ceph_mds_request *req;
struct dentry *res;
int op; int op;
int mask; int mask;
int err; int err;
...@@ -793,12 +791,16 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, ...@@ -793,12 +791,16 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
req->r_parent = dir; req->r_parent = dir;
set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
err = ceph_mdsc_do_request(mdsc, NULL, req); err = ceph_mdsc_do_request(mdsc, NULL, req);
res = ceph_handle_snapdir(req, dentry, err); if (err == -ENOENT) {
if (IS_ERR(res)) { struct dentry *res;
err = PTR_ERR(res);
} else { res = ceph_handle_snapdir(req, dentry);
dentry = res; if (IS_ERR(res)) {
err = 0; err = PTR_ERR(res);
} else {
dentry = res;
err = 0;
}
} }
dentry = ceph_finish_lookup(req, dentry, err); dentry = ceph_finish_lookup(req, dentry, err);
ceph_mdsc_put_request(req); /* will dput(dentry) */ ceph_mdsc_put_request(req); /* will dput(dentry) */
......
...@@ -742,14 +742,16 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, ...@@ -742,14 +742,16 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
err = ceph_mdsc_do_request(mdsc, err = ceph_mdsc_do_request(mdsc,
(flags & (O_CREAT|O_TRUNC)) ? dir : NULL, (flags & (O_CREAT|O_TRUNC)) ? dir : NULL,
req); req);
dentry = ceph_handle_snapdir(req, dentry, err); if (err == -ENOENT) {
if (IS_ERR(dentry)) { dentry = ceph_handle_snapdir(req, dentry);
err = PTR_ERR(dentry); if (IS_ERR(dentry)) {
goto out_req; err = PTR_ERR(dentry);
goto out_req;
}
err = 0;
} }
err = 0;
if ((flags & O_CREAT) && !req->r_reply_info.head->is_dentry) if (!err && (flags & O_CREAT) && !req->r_reply_info.head->is_dentry)
err = ceph_handle_notrace_create(dir, dentry); err = ceph_handle_notrace_create(dir, dentry);
if (d_in_lookup(dentry)) { if (d_in_lookup(dentry)) {
......
...@@ -1218,7 +1218,7 @@ extern const struct dentry_operations ceph_dentry_ops; ...@@ -1218,7 +1218,7 @@ extern const struct dentry_operations ceph_dentry_ops;
extern loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order); extern loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order);
extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry); extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry);
extern struct dentry *ceph_handle_snapdir(struct ceph_mds_request *req, extern struct dentry *ceph_handle_snapdir(struct ceph_mds_request *req,
struct dentry *dentry, int err); struct dentry *dentry);
extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req, extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
struct dentry *dentry, int err); struct dentry *dentry, int err);
......
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