ceph: fix error handling in ceph_atomic_open and ceph_lookup
PATCH 1/1 ceph: fix error handling in ceph_atomic_open and ceph_lookup
Commit aa60cfc3f7ee 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.
--- fs/ceph/dir.c | 17 ++++++----------- fs/ceph/file.c | 6 +++--- fs/ceph/super.h | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-)
fs/ceph/dir.c +6 -11
@@ -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. */ 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 inode *parent =d_inode (dentry->d_parent);/* we hold i_mutex */ /* .snap dir? */ -if (err == -ENOENT && -ceph_snap (parent) ==CEPH_NOSNAP && +if (ceph_snap (parent) ==CEPH_NOSNAP &&strcmp (dentry->d_name.name, fsc->mount_options->snapdir_name) ==0 ) {struct dentry *res;struct inode *inode =ceph_get_snapdir (parent);
@@ -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_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);struct ceph_mds_request *req; -struct dentry *res;int op;int mask;int err;
@@ -793,13 +791,10 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, req->r_parent = dir;set_bit (CEPH_MDS_R_PARENT_LOCKED , &req->r_req_flags); err =ceph_mdsc_do_request (mdsc,NULL , req); - res =ceph_handle_snapdir (req, dentry, err); -if (IS_ERR (res)) { - err =PTR_ERR (res); - }else { - dentry = res; - err =0 ; - } +if (err == -ENOENT ) + dentry =ceph_handle_snapdir (req, dentry); +if (IS_ERR (dentry)) + err =PTR_ERR (dentry); dentry =ceph_finish_lookup (req, dentry, err);ceph_mdsc_put_request (req);/* will dput(dentry) */ dout ("lookup result=%p\n" , dentry);
fs/ceph/file.c +3 -3
@@ -739,14 +739,14 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, err =ceph_mdsc_do_request (mdsc, (flags & (O_CREAT |O_TRUNC )) ? dir :NULL , req); - dentry =ceph_handle_snapdir (req, dentry, err); +if (err == -ENOENT ) + dentry =ceph_handle_snapdir (req, dentry);if (IS_ERR (dentry)) { err =PTR_ERR (dentry); goto out_req; } - 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);if (d_in_lookup (dentry)) {
fs/ceph/super.h +1 -1
@@ -1217,7 +1217,7 @@ extern const struct dentry_operations ceph_dentry_ops;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 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,struct dentry *dentry,int err);
Signature · 1 line
2.31.1
Ilya Dryomov
maintainerQuoted 68 lines · Jeff Layton
Commit
aa60cfc3f7eebroke the error handling in these functions such that they don't handle non-ENOENT errors fromceph_mdsc_do_requestproperly.Move the checking of
-ENOENTout ofceph_handle_snapdirand into the callers, and if we get a different error, return it immediately.Fixes aa60cfc3f7ee ("ceph: don't use d_add in ceph_handle_snapdir")Signed-off-by Jeff Layton <[email protected]>--- fs/ceph/dir.c | 17 ++++++----------- fs/ceph/file.c | 6 +++--- fs/ceph/super.h | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-)fs/ceph/dir.c +6
-11@@ -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. */ 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 inode *parent =d_inode (dentry->d_parent);/* we hold i_mutex */ /* .snap dir? */ -if (err == -ENOENT && -ceph_snap (parent) ==CEPH_NOSNAP && +if (ceph_snap (parent) ==CEPH_NOSNAP &&strcmp (dentry->d_name.name, fsc->mount_options->snapdir_name) ==0 ) {struct dentry *res;struct inode *inode =ceph_get_snapdir (parent);@@ -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_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);struct ceph_mds_request *req; -struct dentry *res;int op;int mask;int err;@@ -793,13 +791,10 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, req->r_parent = dir;set_bit (CEPH_MDS_R_PARENT_LOCKED , &req->r_req_flags); err =ceph_mdsc_do_request (mdsc,NULL , req); - res =ceph_handle_snapdir (req, dentry, err); -if (IS_ERR (res)) { - err =PTR_ERR (res); - }else { - dentry = res; - err =0 ; - } +if (err == -ENOENT ) + dentry =ceph_handle_snapdir (req, dentry); +if (IS_ERR (dentry)) + err =PTR_ERR (dentry); dentry =ceph_finish_lookup (req, dentry, err);ceph_mdsc_put_request (req);/* will dput(dentry) */ dout ("lookup result=%p\n" , dentry);fs/ceph/file.c +0
-0
fs/ceph/file.c int ceph_atomic_open(struct inode *dir, struct dentry *dentry, · line 747
Quoted 10 lines
fs/ceph/file.c +2
-1@@ -739,14 +739,14 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, err =ceph_mdsc_do_request (mdsc, (flags & (O_CREAT |O_TRUNC )) ? dir :NULL , req); - dentry =ceph_handle_snapdir (req, dentry, err); +if (err == -ENOENT ) + dentry =ceph_handle_snapdir (req, dentry);if (IS_ERR (dentry)) { err =PTR_ERR (dentry); goto out_req; }
Hi Jeff,
This doesn't seem right to me. Looking at 5.12, ENOENT from ceph_mdsc_do_request() could be resolved by ceph_handle_snapdir() meaning that ceph_handle_notrace_create() could be called and ceph_finish_lookup() could be passed err == 0.
With this patch err would remain ENOENT, resulting in skipping the potential ceph_handle_notrace_create() call and passing that ENOENT to ceph_finish_lookup().
Thanks,
Ilya
Quoted 82 lines · Ilya Dryomov
Quoted 68 lines · Jeff Layton
Commit
aa60cfc3f7eebroke the error handling in these functions such that they don't handle non-ENOENT errors fromceph_mdsc_do_requestproperly.Move the checking of
-ENOENTout ofceph_handle_snapdirand into the callers, and if we get a different error, return it immediately.Fixes aa60cfc3f7ee ("ceph: don't use d_add in ceph_handle_snapdir")Signed-off-by Jeff Layton <[email protected]>--- fs/ceph/dir.c | 17 ++++++----------- fs/ceph/file.c | 6 +++--- fs/ceph/super.h | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-)fs/ceph/dir.c +6
-11@@ -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. */ 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 inode *parent =d_inode (dentry->d_parent);/* we hold i_mutex */ /* .snap dir? */ -if (err == -ENOENT && -ceph_snap (parent) ==CEPH_NOSNAP && +if (ceph_snap (parent) ==CEPH_NOSNAP &&strcmp (dentry->d_name.name, fsc->mount_options->snapdir_name) ==0 ) {struct dentry *res;struct inode *inode =ceph_get_snapdir (parent);@@ -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_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);struct ceph_mds_request *req; -struct dentry *res;int op;int mask;int err;@@ -793,13 +791,10 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, req->r_parent = dir;set_bit (CEPH_MDS_R_PARENT_LOCKED , &req->r_req_flags); err =ceph_mdsc_do_request (mdsc,NULL , req); - res =ceph_handle_snapdir (req, dentry, err); -if (IS_ERR (res)) { - err =PTR_ERR (res); - }else { - dentry = res; - err =0 ; - } +if (err == -ENOENT ) + dentry =ceph_handle_snapdir (req, dentry); +if (IS_ERR (dentry)) + err =PTR_ERR (dentry); dentry =ceph_finish_lookup (req, dentry, err);ceph_mdsc_put_request (req);/* will dput(dentry) */ dout ("lookup result=%p\n" , dentry);fs/ceph/file.c +0
-0fs/ceph/file.c int ceph_atomic_open(struct inode *dir, struct dentry *dentry, · line 747
Quoted 10 lines
fs/ceph/file.c +2
-1@@ -739,14 +739,14 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, err =ceph_mdsc_do_request (mdsc, (flags & (O_CREAT |O_TRUNC )) ? dir :NULL , req); - dentry =ceph_handle_snapdir (req, dentry, err); +if (err == -ENOENT ) + dentry =ceph_handle_snapdir (req, dentry);if (IS_ERR (dentry)) { err =PTR_ERR (dentry); goto out_req; }Hi Jeff,
Quoted 9 lines
This doesn't seem right to me. Looking at 5.12, ENOENT from
ceph_mdsc_do_request()could be resolved byceph_handle_snapdir()meaning thatceph_handle_notrace_create()could be called andceph_finish_lookup()could be passed err == 0.With this patch err would remain ENOENT, resulting in skipping the potential
ceph_handle_notrace_create()call and passing that ENOENT toceph_finish_lookup().
Well spotted! I have a v2 version that I'm running through xfstests now. I'll send it along in a bit.
Thanks!
Signature · 1 line
Jeff Layton <[email protected]>
PATCH v2 1/1 ceph: fix error handling in ceph_atomic_open and ceph_lookup
In reply to Jeff LaytonCommit aa60cfc3f7ee 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.
--- fs/ceph/dir.c | 22 ++++++++++++---------- fs/ceph/file.c | 14 ++++++++------ fs/ceph/super.h | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-)
This one fixes the bug that Ilya spotted in ceph_atomic_open. Also, there is no need to test IS_ERR(dentry) unless we called ceph_handle_snapdir. Finally, it's probably best not to pass ceph_finish_lookup an ERR_PTR as a dentry. Reinstate the res pointer and only reset the dentry pointer if it's valid.
fs/ceph/dir.c +12 -10
@@ -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. */ 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 inode *parent =d_inode (dentry->d_parent);/* we hold i_mutex */ /* .snap dir? */ -if (err == -ENOENT && -ceph_snap (parent) ==CEPH_NOSNAP && +if (ceph_snap (parent) ==CEPH_NOSNAP &&strcmp (dentry->d_name.name, fsc->mount_options->snapdir_name) ==0 ) {struct dentry *res;struct inode *inode =ceph_get_snapdir (parent);
@@ -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_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);struct ceph_mds_request *req; -struct dentry *res;int op;int mask;int err;
@@ -793,12 +791,16 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, req->r_parent = dir;set_bit (CEPH_MDS_R_PARENT_LOCKED , &req->r_req_flags); err =ceph_mdsc_do_request (mdsc,NULL , req); - res =ceph_handle_snapdir (req, dentry, err); -if (IS_ERR (res)) { - err =PTR_ERR (res); - }else { - dentry = res; - err =0 ; +if (err == -ENOENT ) { +struct dentry *res; + + res =ceph_handle_snapdir (req, dentry); +if (IS_ERR (res)) { + err =PTR_ERR (res); + }else { + dentry = res; + err =0 ; + } } dentry =ceph_finish_lookup (req, dentry, err);ceph_mdsc_put_request (req);/* will dput(dentry) */
fs/ceph/file.c +8 -6
@@ -739,14 +739,16 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, err =ceph_mdsc_do_request (mdsc, (flags & (O_CREAT |O_TRUNC )) ? dir :NULL , req); - dentry =ceph_handle_snapdir (req, dentry, err); -if (IS_ERR (dentry)) { - err =PTR_ERR (dentry); - goto out_req; +if (err == -ENOENT ) { + dentry =ceph_handle_snapdir (req, dentry); +if (IS_ERR (dentry)) { + 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);if (d_in_lookup (dentry)) {
fs/ceph/super.h +1 -1
@@ -1217,7 +1217,7 @@ extern const struct dentry_operations ceph_dentry_ops;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 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,struct dentry *dentry,int err);
Signature · 1 line
2.31.1
Quoted 55 lines · Jeff Layton
Commit
aa60cfc3f7eebroke the error handling in these functions such that they don't handle non-ENOENT errors fromceph_mdsc_do_requestproperly.Move the checking of
-ENOENTout ofceph_handle_snapdirand into the callers, and if we get a different error, return it immediately.Fixes aa60cfc3f7ee ("ceph: don't use d_add in ceph_handle_snapdir")Signed-off-by Jeff Layton <[email protected]>--- fs/ceph/dir.c | 22 ++++++++++++---------- fs/ceph/file.c | 14 ++++++++------ fs/ceph/super.h | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-)This one fixes the bug that Ilya spotted in
ceph_atomic_open. Also, there is no need to testIS_ERR(dentry)unless we calledceph_handle_snapdir. Finally, it's probably best not to passceph_finish_lookupanERR_PTRas a dentry. Reinstate the res pointer and only reset the dentry pointer if it's valid.fs/ceph/dir.c +2
-4@@ -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. */ 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 inode *parent =d_inode (dentry->d_parent);/* we hold i_mutex */ /* .snap dir? */ -if (err == -ENOENT && -ceph_snap (parent) ==CEPH_NOSNAP && +if (ceph_snap (parent) ==CEPH_NOSNAP &&strcmp (dentry->d_name.name, fsc->mount_options->snapdir_name) ==0 ) {struct dentry *res;struct inode *inode =ceph_get_snapdir (parent);@@ -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_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);struct ceph_mds_request *req; -struct dentry *res;int op;int mask;int err;@@ -793,12 +791,16 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, req->r_parent = dir;set_bit (CEPH_MDS_R_PARENT_LOCKED , &req->r_req_flags); err =ceph_mdsc_do_request (mdsc,NULL , req);
fs/ceph/dir.c static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, · line 797
Quoted 10 lines
fs/ceph/dir.c +4
-6- res =ceph_handle_snapdir (req, dentry, err); -if (IS_ERR (res)) { - err =PTR_ERR (res); - }else { - dentry = res; - err =0 ; +if (err == -ENOENT ) { +struct dentry *res; + + res =ceph_handle_snapdir (req, dentry);
Stray space here, fixed in the branch.
Quoted 26 lines
fs/ceph/dir.c +6
-0+if (IS_ERR (res)) { + err =PTR_ERR (res); + }else { + dentry = res; + err =0 ; + } } dentry =ceph_finish_lookup (req, dentry, err);ceph_mdsc_put_request (req);/* will dput(dentry) */ fs/ceph/file.c +5
-4@@ -739,14 +739,16 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, err =ceph_mdsc_do_request (mdsc, (flags & (O_CREAT |O_TRUNC )) ? dir :NULL , req); - dentry =ceph_handle_snapdir (req, dentry, err); -if (IS_ERR (dentry)) { - err =PTR_ERR (dentry); - goto out_req; +if (err == -ENOENT ) { + dentry =ceph_handle_snapdir (req, dentry); +if (IS_ERR (dentry)) { + err =PTR_ERR (dentry); + goto out_req;
fs/ceph/file.c int ceph_atomic_open(struct inode *dir, struct dentry *dentry, · line 754
Quoted 10 lines
fs/ceph/file.c +3
-2+ } + 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);if (d_in_lookup (dentry)) {
I must admit that I don't understand the code that follows. For example, if ceph_handle_notrace_create() returns ENOENT, is it supposed to be resolved by ceph_finish_lookup()? Because if it gets resolved, err is not reset and we still jump to out_req, possibly leaving some dentry references behind. It appears to be an older bug though.
This fix for dealing with ceph_mdsc_do_request() errors seems correct, but I really think this code needs massaging to disentangle handling of special cases from actual errors.
Thanks,
Ilya
Quoted 60 lines · Ilya Dryomov
Quoted 59 lines · Jeff Layton
Commit
aa60cfc3f7eebroke the error handling in these functions such that they don't handle non-ENOENT errors fromceph_mdsc_do_requestproperly.Move the checking of
-ENOENTout ofceph_handle_snapdirand into the callers, and if we get a different error, return it immediately.Fixes aa60cfc3f7ee ("ceph: don't use d_add in ceph_handle_snapdir")Signed-off-by Jeff Layton <[email protected]>--- fs/ceph/dir.c | 22 ++++++++++++---------- fs/ceph/file.c | 14 ++++++++------ fs/ceph/super.h | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-)This one fixes the bug that Ilya spotted in
ceph_atomic_open. Also, there is no need to testIS_ERR(dentry)unless we calledceph_handle_snapdir. Finally, it's probably best not to passceph_finish_lookupanERR_PTRas a dentry. Reinstate the res pointer and only reset the dentry pointer if it's valid.fs/ceph/dir.c +2
-8@@ -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. */ 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 inode *parent =d_inode (dentry->d_parent);/* we hold i_mutex */ /* .snap dir? */ -if (err == -ENOENT && -ceph_snap (parent) ==CEPH_NOSNAP && +if (ceph_snap (parent) ==CEPH_NOSNAP &&strcmp (dentry->d_name.name, fsc->mount_options->snapdir_name) ==0 ) {struct dentry *res;struct inode *inode =ceph_get_snapdir (parent);@@ -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_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);struct ceph_mds_request *req; -struct dentry *res;int op;int mask;int err;@@ -793,12 +791,16 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, req->r_parent = dir;set_bit (CEPH_MDS_R_PARENT_LOCKED , &req->r_req_flags); err =ceph_mdsc_do_request (mdsc,NULL , req); - res =ceph_handle_snapdir (req, dentry, err); -if (IS_ERR (res)) { - err =PTR_ERR (res); - }else {
Quoted 9 lines
fs/ceph/dir.c static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, · line 797
Quoted 6 lines
fs/ceph/dir.c +4
-2- dentry = res; - err =0 ; +if (err == -ENOENT ) { +struct dentry *res; + + res =ceph_handle_snapdir (req, dentry);Stray space here, fixed in the branch.
Thanks!
Quoted 35 lines
Quoted 35 lines
fs/ceph/dir.c +6
-0+if (IS_ERR (res)) { + err =PTR_ERR (res); + }else { + dentry = res; + err =0 ; + } } dentry =ceph_finish_lookup (req, dentry, err);ceph_mdsc_put_request (req);/* will dput(dentry) */ fs/ceph/file.c +8
-6@@ -739,14 +739,16 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, err =ceph_mdsc_do_request (mdsc, (flags & (O_CREAT |O_TRUNC )) ? dir :NULL , req); - dentry =ceph_handle_snapdir (req, dentry, err); -if (IS_ERR (dentry)) { - err =PTR_ERR (dentry); - goto out_req; +if (err == -ENOENT ) { + dentry =ceph_handle_snapdir (req, dentry); +if (IS_ERR (dentry)) { + 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);
Quoted 8 lines
fs/ceph/file.c int ceph_atomic_open(struct inode *dir, struct dentry *dentry, · line 754
Quoted 1 line
fs/ceph/file.c +0
-0if (d_in_lookup (dentry)) {I must admit that I don't understand the code that follows. For example, if
ceph_handle_notrace_create()returns ENOENT, is it supposed to be resolved byceph_finish_lookup()? Because if it gets resolved, err is not reset and we still jump toout_req, possibly leaving some dentry references behind. It appears to be an older bug though.
Yes. A lot of this code is unclear.
Quoted 6 lines
This fix for dealing with
ceph_mdsc_do_request()errors seems correct, but I really think this code needs massaging to disentangle handling of special cases from actual errors.Reviewed-by Ilya Dryomov <[email protected]>
Thanks and I agree. This code really is a giant hairball. I really hate the way it weaves "err" through several functions and lets them deal with it. That alone makes this so very difficult to follow.
I intend to follow up with some more cleanup in this area, but I haven't had the time to spend on it yet. In the meantime, if anyone else wants to submit patches to do this cleanup, I'm happy to review them...
Signature · 1 line
Jeff Layton <[email protected]>