[PATCH 4/6] libceph: add helper that extends numner of operations in OSD request

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The helper function resizes the r_ops array and re-allocates request
message.

Signed-off-by: Yan, Zheng <zyan@xxxxxxxxxx>
---
 include/linux/ceph/osd_client.h |  3 ++
 net/ceph/osd_client.c           | 61 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index 9802df1..6430766 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -322,6 +322,9 @@ extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *
 					       unsigned int num_ops,
 					       bool use_mempool,
 					       gfp_t gfp_flags);
+extern int ceph_osdc_extend_request(struct ceph_osd_request *req,
+				    unsigned int num_ops, gfp_t gfp_flags);
+
 
 extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
 				    struct ceph_snap_context *snapc,
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 4a9d4e5..8349681 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -361,6 +361,67 @@ void ceph_osdc_put_request(struct ceph_osd_request *req)
 }
 EXPORT_SYMBOL(ceph_osdc_put_request);
 
+int ceph_osdc_extend_request(struct ceph_osd_request *req,
+			     unsigned int num_ops, gfp_t gfp_flags)
+{
+	struct ceph_osd_req_op *new_ops;
+	struct ceph_msg *request_msg;
+	struct ceph_msg *reply_msg = NULL;
+	size_t msg_size;
+
+	if (num_ops > CEPH_OSD_MAX_OP)
+		return -EINVAL;
+
+	if (num_ops <= req->r_max_ops)
+		return 0;
+
+	msg_size = req->r_request->front_alloc_len +
+		   (num_ops - req->r_max_ops) *
+		   sizeof(struct ceph_osd_op);
+	request_msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp_flags, true);
+	if (!request_msg)
+		return -ENOMEM;
+
+	if (num_ops > CEPH_OSD_INITIAL_OP &&
+	    req->r_max_ops <= CEPH_OSD_INITIAL_OP) {
+		msg_size = OSD_OPREPLY_FRONT_LEN +
+			   (CEPH_OSD_MAX_OP - CEPH_OSD_INITIAL_OP) *
+			   (sizeof(struct ceph_osd_op) + 4);
+		reply_msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, msg_size,
+					 gfp_flags, true);
+		if (!reply_msg)
+			goto out_enomem;
+	}
+
+	if (num_ops > CEPH_OSD_INITIAL_OP) {
+		new_ops = ceph_kvmalloc(sizeof(*req->r_ops) * num_ops,
+					gfp_flags | __GFP_ZERO);
+		if (!new_ops)
+			goto out_enomem;
+
+		memcpy(new_ops, req->r_ops,
+		       sizeof(*req->r_ops) * req->r_num_ops);
+		if (req->r_ops != req->r_inline_ops)
+			kvfree(req->r_ops);
+		req->r_ops = new_ops;
+	}
+
+	ceph_msg_put(req->r_request);
+	req->r_request = request_msg;
+	if (reply_msg) {
+		ceph_msg_put(req->r_reply);
+		req->r_reply = reply_msg;
+	}
+	req->r_max_ops = num_ops;
+	return 0;
+out_enomem:
+	ceph_msg_put(request_msg);
+	if (reply_msg)
+		ceph_msg_put(reply_msg);
+	return -ENOMEM;
+}
+EXPORT_SYMBOL(ceph_osdc_extend_request);
+
 struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
 					       struct ceph_snap_context *snapc,
 					       unsigned int num_ops,
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [CEPH Users]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux