ceph: fix memory leakage in ceph_readdir
PATCH v3 1/1 ceph: fix memory leakage in ceph_readdir
From: Xiubo Li <[email protected]>
Reset the last_readdir at the same time.
--- fs/ceph/dir.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/ceph/dir.c +10 -1
@@ -498,8 +498,11 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx) 2 : (fpos_off(rde->offset) + 1); err =note_last_dentry (dfi, rde->name, rde->name_len, next_offset); -if (err) +if (err) { +ceph_mdsc_put_request (dfi->last_readdir); + dfi->last_readdir =NULL ; goto out; + } }else if (req->r_reply_info.dir_end) { dfi->next_offset =2 ;/* keep last name */
@@ -552,6 +555,12 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)if (!dir_emit (ctx, oname.name, oname.len,ceph_present_ino (inode->i_sb,le64_to_cpu (rde->inode.in->ino)),le32_to_cpu (rde->inode.in->mode) >>12 )) { +/* +* NOTE: Here no need to put the 'dfi->last_readdir', +* because when dir_emit stops us it's most likely +* doesn't have enough memory, etc. So for next readdir +* it will continue. +*/ dout ("filldir stopping us...\n" ); err =0 ; goto out;
Signature · 1 line
2.27.0
Quoted 14 lines · On Sat, 2022-03-05 at 19:52 +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
Reset the
last_readdirat the same time.Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/dir.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)fs/ceph/dir.c +0
-0
fs/ceph/dir.c static int ceph_readdir(struct file *file, struct dir_context *ctx) · line 505
Quoted 9 lines
fs/ceph/dir.c +4
-1@@ -498,8 +498,11 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx) 2 : (fpos_off(rde->offset) + 1); err =note_last_dentry (dfi, rde->name, rde->name_len, next_offset); -if (err) +if (err) { +ceph_mdsc_put_request (dfi->last_readdir); + dfi->last_readdir =NULL ; goto out; + }
Looks good, but this doesn't apply cleanly to the testing branch since it still does a "return 0" there instead of "goto out". I adapted it to work with testing branch and will do some testing with it today.
Quoted 16 lines
fs/ceph/dir.c +6
-0}else if (req->r_reply_info.dir_end) { dfi->next_offset =2 ;/* keep last name */ @@ -552,6 +555,12 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)if (!dir_emit (ctx, oname.name, oname.len,ceph_present_ino (inode->i_sb,le64_to_cpu (rde->inode.in->ino)),le32_to_cpu (rde->inode.in->mode) >>12 )) { +/* +* NOTE: Here no need to put the 'dfi->last_readdir', +* because when dir_emit stops us it's most likely +* doesn't have enough memory, etc. So for next readdir +* it will continue. +*/ dout ("filldir stopping us...\n" ); err =0 ; goto out;
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 19 lines · Jeff Layton
Quoted 18 lines · On Sat, 2022-03-05 at 19:52 +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
Reset the
last_readdirat the same time.Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/dir.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)fs/ceph/dir.c +0
-1@@ -498,8 +498,11 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx) 2 : (fpos_off(rde->offset) + 1); err =note_last_dentry (dfi, rde->name, rde->name_len, next_offset); -if (err)
Quoted 9 lines
fs/ceph/dir.c static int ceph_readdir(struct file *file, struct dir_context *ctx) · line 505
Quoted 5 lines
fs/ceph/dir.c +4
-0+if (err) { +ceph_mdsc_put_request (dfi->last_readdir); + dfi->last_readdir =NULL ; goto out; + }Looks good, but this doesn't apply cleanly to the testing branch since it still does a "return 0" there instead of "goto out". I adapted it to work with testing branch and will do some testing with it today.
I think I was working on the wip-fscrypt branch. Thanks Jeff.
- Xiubo
Quoted 16 lines
Quoted 16 lines
fs/ceph/dir.c +6
-0}else if (req->r_reply_info.dir_end) { dfi->next_offset =2 ;/* keep last name */ @@ -552,6 +555,12 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)if (!dir_emit (ctx, oname.name, oname.len,ceph_present_ino (inode->i_sb,le64_to_cpu (rde->inode.in->ino)),le32_to_cpu (rde->inode.in->mode) >>12 )) { +/* +* NOTE: Here no need to put the 'dfi->last_readdir', +* because when dir_emit stops us it's most likely +* doesn't have enough memory, etc. So for next readdir +* it will continue. +*/ dout ("filldir stopping us...\n" ); err =0 ; goto out;