]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ceph: allocate sparse_ext map only for sparse reads
authorIlya Dryomov <idryomov@gmail.com>
Sat, 7 Dec 2024 16:33:25 +0000 (17:33 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 16 Dec 2024 22:25:44 +0000 (23:25 +0100)
If mounted with sparseread option, ceph_direct_read_write() ends up
making an unnecessarily allocation for O_DIRECT writes.

Fixes: 03bc06c7b0bd ("ceph: add new mount option to enable sparse reads")
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Alex Markuze <amarkuze@redhat.com>
fs/ceph/file.c
net/ceph/osd_client.c

index 67468d88f139086e73c96c5e4df7c4abd2d80388..851d70200c6b8f5746fe02fc667a802f70336a71 100644 (file)
@@ -1552,7 +1552,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
                }
 
                op = &req->r_ops[0];
-               if (sparse) {
+               if (!write && sparse) {
                        extent_cnt = __ceph_sparse_read_ext_count(inode, size);
                        ret = ceph_alloc_sparse_ext_map(op, extent_cnt);
                        if (ret) {
index 9b1168eb77abb3707ab162953fa9cf380ec1795f..b24afec241382b60d775dd12a6561fa23a7eca45 100644 (file)
@@ -1173,6 +1173,8 @@ EXPORT_SYMBOL(ceph_osdc_new_request);
 
 int __ceph_alloc_sparse_ext_map(struct ceph_osd_req_op *op, int cnt)
 {
+       WARN_ON(op->op != CEPH_OSD_OP_SPARSE_READ);
+
        op->extent.sparse_ext_cnt = cnt;
        op->extent.sparse_ext = kmalloc_array(cnt,
                                              sizeof(*op->extent.sparse_ext),