Skip to content

Commit 7a971e2

Browse files
jtlaytonidryomov
authored andcommitted
ceph: fix error handling in ceph_atomic_open and ceph_lookup
Commit aa60cfc 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: aa60cfc ("ceph: don't use d_add in ceph_handle_snapdir") Signed-off-by: Jeff Layton <[email protected]> Reviewed-by: Ilya Dryomov <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 27171ae commit 7a971e2

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

fs/ceph/dir.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -668,14 +668,13 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int whence)
668668
* Handle lookups for the hidden .snap directory.
669669
*/
670670
struct dentry *ceph_handle_snapdir(struct ceph_mds_request *req,
671-
struct dentry *dentry, int err)
671+
struct dentry *dentry)
672672
{
673673
struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
674674
struct inode *parent = d_inode(dentry->d_parent); /* we hold i_mutex */
675675

676676
/* .snap dir? */
677-
if (err == -ENOENT &&
678-
ceph_snap(parent) == CEPH_NOSNAP &&
677+
if (ceph_snap(parent) == CEPH_NOSNAP &&
679678
strcmp(dentry->d_name.name, fsc->mount_options->snapdir_name) == 0) {
680679
struct dentry *res;
681680
struct inode *inode = ceph_get_snapdir(parent);
@@ -742,7 +741,6 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
742741
struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
743742
struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(dir->i_sb);
744743
struct ceph_mds_request *req;
745-
struct dentry *res;
746744
int op;
747745
int mask;
748746
int err;
@@ -793,12 +791,16 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
793791
req->r_parent = dir;
794792
set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
795793
err = ceph_mdsc_do_request(mdsc, NULL, req);
796-
res = ceph_handle_snapdir(req, dentry, err);
797-
if (IS_ERR(res)) {
798-
err = PTR_ERR(res);
799-
} else {
800-
dentry = res;
801-
err = 0;
794+
if (err == -ENOENT) {
795+
struct dentry *res;
796+
797+
res = ceph_handle_snapdir(req, dentry);
798+
if (IS_ERR(res)) {
799+
err = PTR_ERR(res);
800+
} else {
801+
dentry = res;
802+
err = 0;
803+
}
802804
}
803805
dentry = ceph_finish_lookup(req, dentry, err);
804806
ceph_mdsc_put_request(req); /* will dput(dentry) */

fs/ceph/file.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -742,14 +742,16 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
742742
err = ceph_mdsc_do_request(mdsc,
743743
(flags & (O_CREAT|O_TRUNC)) ? dir : NULL,
744744
req);
745-
dentry = ceph_handle_snapdir(req, dentry, err);
746-
if (IS_ERR(dentry)) {
747-
err = PTR_ERR(dentry);
748-
goto out_req;
745+
if (err == -ENOENT) {
746+
dentry = ceph_handle_snapdir(req, dentry);
747+
if (IS_ERR(dentry)) {
748+
err = PTR_ERR(dentry);
749+
goto out_req;
750+
}
751+
err = 0;
749752
}
750-
err = 0;
751753

752-
if ((flags & O_CREAT) && !req->r_reply_info.head->is_dentry)
754+
if (!err && (flags & O_CREAT) && !req->r_reply_info.head->is_dentry)
753755
err = ceph_handle_notrace_create(dir, dentry);
754756

755757
if (d_in_lookup(dentry)) {

fs/ceph/super.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ extern const struct dentry_operations ceph_dentry_ops;
12181218
extern loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order);
12191219
extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry);
12201220
extern struct dentry *ceph_handle_snapdir(struct ceph_mds_request *req,
1221-
struct dentry *dentry, int err);
1221+
struct dentry *dentry);
12221222
extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
12231223
struct dentry *dentry, int err);
12241224

0 commit comments

Comments
 (0)