[RFC PATCH 15/35] libceph: Make osd_req_op_cls_init() use a ceph_databuf and map it

David Howells
2025-03-13T23:34:53Z

Make osd_req_op_cls_init() use a ceph_databuf to hold the request_info data
and then map it and write directly into it rather than using the databuf
encode functions.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Viacheslav Dubeyko <slava@dubeyko.com>
cc: Alex Markuze <amarkuze@redhat.com>
cc: Ilya Dryomov <idryomov@gmail.com>
cc: ceph-devel@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
---
net/ceph/osd_client.c | 55 +++++++++++++++++--------------------------
1 file changed, 22 insertions(+), 33 deletions(-)

diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 10f65e9b1906..405ccf7e7a91 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -245,14 +245,14 @@ void osd_req_op_extent_osd_iter(struct ceph_osd_request *osd_req,
}
EXPORT_SYMBOL(osd_req_op_extent_osd_iter);

-static void osd_req_op_cls_request_info_pagelist(
- struct ceph_osd_request *osd_req,
- unsigned int which, struct ceph_pagelist *pagelist)
+static void osd_req_op_cls_request_info_databuf(struct ceph_osd_request *osd_req,
+ unsigned int which,
+ struct ceph_databuf *dbuf)
{
struct ceph_osd_data *osd_data;

osd_data = osd_req_op_data(osd_req, which, cls, request_info);
- ceph_osd_data_pagelist_init(osd_data, pagelist);
+ ceph_osd_databuf_init(osd_data, dbuf);
}

void osd_req_op_cls_request_databuf(struct ceph_osd_request *osd_req,
@@ -778,42 +778,31 @@ int osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
const char *class, const char *method)
{
struct ceph_osd_req_op *op;
- struct ceph_pagelist *pagelist;
- size_t payload_len = 0;
- size_t size;
- int ret;
+ struct ceph_databuf *dbuf;
+ size_t csize = strlen(class), msize = strlen(method);
+ void *p;
+
+ BUG_ON(csize > (size_t) U8_MAX);
+ BUG_ON(msize > (size_t) U8_MAX);

op = osd_req_op_init(osd_req, which, CEPH_OSD_OP_CALL, 0);
+ op->cls.class_name = class;
+ op->cls.class_len = csize;
+ op->cls.method_name = method;
+ op->cls.method_len = msize;

- pagelist = ceph_pagelist_alloc(GFP_NOFS);
- if (!pagelist)
+ dbuf = ceph_databuf_req_alloc(1, PAGE_SIZE, GFP_NOFS);
+ if (!dbuf)
return -ENOMEM;

- op->cls.class_name = class;
- size = strlen(class);
- BUG_ON(size > (size_t) U8_MAX);
- op->cls.class_len = size;
- ret = ceph_pagelist_append(pagelist, class, size);
- if (ret)
- goto err_pagelist_free;
- payload_len += size;
-
- op->cls.method_name = method;
- size = strlen(method);
- BUG_ON(size > (size_t) U8_MAX);
- op->cls.method_len = size;
- ret = ceph_pagelist_append(pagelist, method, size);
- if (ret)
- goto err_pagelist_free;
- payload_len += size;
+ p = ceph_databuf_enc_start(dbuf);
+ ceph_encode_copy(&p, class, csize);
+ ceph_encode_copy(&p, method, msize);
+ ceph_databuf_enc_stop(dbuf, p);

- osd_req_op_cls_request_info_pagelist(osd_req, which, pagelist);
- op->indata_len = payload_len;
+ osd_req_op_cls_request_info_databuf(osd_req, which, dbuf);
+ op->indata_len = ceph_databuf_len(dbuf);
return 0;
-
-err_pagelist_free:
- ceph_pagelist_release(pagelist);
- return ret;
}
EXPORT_SYMBOL(osd_req_op_cls_init);