Skip to content

Commit d6fd6f8

Browse files
MaxKellermannidryomov
authored andcommitted
ceph: fix memory leaks in __ceph_sync_read()
In two `break` statements, the call to ceph_release_page_vector() was missing, leaking the allocation from ceph_alloc_page_vector(). Instead of adding the missing ceph_release_page_vector() calls, the Ceph maintainers preferred to transfer page ownership to the `ceph_osd_request` by passing `own_pages=true` to osd_req_op_extent_osd_data_pages(). This requires postponing the ceph_osdc_put_request() call until after the block that accesses the `pages`. Cc: [email protected] Fixes: 03bc06c ("ceph: add new mount option to enable sparse reads") Fixes: f0fe1e5 ("ceph: plumb in decryption during reads") Signed-off-by: Max Kellermann <[email protected]> Reviewed-by: Ilya Dryomov <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 78d4f34 commit d6fd6f8

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

fs/ceph/file.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,
11271127

11281128
osd_req_op_extent_osd_data_pages(req, 0, pages, read_len,
11291129
offset_in_page(read_off),
1130-
false, false);
1130+
false, true);
11311131

11321132
op = &req->r_ops[0];
11331133
if (sparse) {
@@ -1186,8 +1186,6 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,
11861186
ret = min_t(ssize_t, fret, len);
11871187
}
11881188

1189-
ceph_osdc_put_request(req);
1190-
11911189
/* Short read but not EOF? Zero out the remainder. */
11921190
if (ret >= 0 && ret < len && (off + ret < i_size)) {
11931191
int zlen = min(len - ret, i_size - off - ret);
@@ -1221,7 +1219,8 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,
12211219
break;
12221220
}
12231221
}
1224-
ceph_release_page_vector(pages, num_pages);
1222+
1223+
ceph_osdc_put_request(req);
12251224

12261225
if (ret < 0) {
12271226
if (ret == -EBLOCKLISTED)

0 commit comments

Comments
 (0)