Reviewed-by: Alex Markuze <amarkuze@xxxxxxxxxx> On Sat, Dec 7, 2024 at 8:26 PM Ilya Dryomov <idryomov@xxxxxxxxx> wrote: > > 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@xxxxxxxxx> > --- > fs/ceph/file.c | 2 +- > net/ceph/osd_client.c | 2 ++ > 2 files changed, 3 insertions(+), 1 deletion(-) > > diff --git a/fs/ceph/file.c b/fs/ceph/file.c > index 0df2ffc69e92..f17bc4dc629c 100644 > --- a/fs/ceph/file.c > +++ b/fs/ceph/file.c > @@ -1558,7 +1558,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) { > diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c > index 9b1168eb77ab..b24afec24138 100644 > --- a/net/ceph/osd_client.c > +++ b/net/ceph/osd_client.c > @@ -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), > -- > 2.46.1 >