Blob Blame History Raw
From 941f841c8d396d957381fcd4de003d8f2201e741 Mon Sep 17 00:00:00 2001
From: David Disseldorp <ddiss@suse.de>
Date: Wed, 15 Jan 2020 13:33:50 +0100
Subject: [PATCH] rbd: add img_request done callback
References: fate#318836
Patch-mainline: Not yet, SES clustered LIO/RBD

This allows LIO to properly handle SCSI command completion.

Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 drivers/block/rbd.c         | 25 ++++++++++++++++++-------
 include/linux/ceph/librbd.h |  6 +++++-
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 2dc0d3244c80..6c887d3263cb 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1504,7 +1504,8 @@ static bool rbd_dev_parent_get(struct rbd_device *rbd_dev)
 struct rbd_img_request *rbd_img_request_create(
 					struct rbd_device *rbd_dev,
 					enum obj_operation_type op_type,
-					struct ceph_snap_context *snapc)
+					struct ceph_snap_context *snapc,
+					rbd_img_request_end_cb_t end_cb)
 {
 	struct rbd_img_request *img_request;
 
@@ -1526,6 +1527,7 @@ struct rbd_img_request *rbd_img_request_create(
 	INIT_LIST_HEAD(&img_request->object_extents);
 	mutex_init(&img_request->state_mutex);
 	kref_init(&img_request->kref);
+	img_request->callback = end_cb;
 
 	return img_request;
 }
@@ -2704,6 +2706,8 @@ static int rbd_obj_read_object(struct rbd_obj_request *obj_req)
 	return 0;
 }
 
+static void rbd_img_end_request(struct rbd_img_request *img_req, int result);
+
 static int rbd_obj_read_from_parent(struct rbd_obj_request *obj_req)
 {
 	struct rbd_img_request *img_req = obj_req->img_request;
@@ -2711,7 +2715,8 @@ static int rbd_obj_read_from_parent(struct rbd_obj_request *obj_req)
 	int ret;
 
 	child_img_req = rbd_img_request_create(img_req->rbd_dev->parent,
-					       OBJ_OP_READ, NULL);
+					       OBJ_OP_READ, NULL,
+					       rbd_img_end_request);
 	if (!child_img_req)
 		return -ENOMEM;
 
@@ -3496,6 +3501,14 @@ static bool __rbd_img_handle_request(struct rbd_img_request *img_req,
 	return done;
 }
 
+static void rbd_img_end_request(struct rbd_img_request *img_req, int result)
+{
+	struct request *rq = img_req->rq;
+
+	rbd_img_request_put(img_req);
+	blk_mq_end_request(rq, errno_to_blk_status(result));
+}
+
 void rbd_img_handle_request(struct rbd_img_request *img_req, int result)
 {
 again:
@@ -3511,10 +3524,7 @@ void rbd_img_handle_request(struct rbd_img_request *img_req, int result)
 			goto again;
 		}
 	} else {
-		struct request *rq = img_req->rq;
-
-		rbd_img_request_put(img_req);
-		blk_mq_end_request(rq, errno_to_blk_status(result));
+		img_req->callback(img_req, result);
 	}
 }
 EXPORT_SYMBOL(rbd_img_handle_request);
@@ -4647,7 +4657,8 @@ static void rbd_queue_workfn(struct work_struct *work)
 		goto err_rq;
 	}
 
-	img_request = rbd_img_request_create(rbd_dev, op_type, snapc);
+	img_request = rbd_img_request_create(rbd_dev, op_type, snapc,
+					     rbd_img_end_request);
 	if (!img_request) {
 		result = -ENOMEM;
 		goto err_rq;
diff --git a/include/linux/ceph/librbd.h b/include/linux/ceph/librbd.h
index 7cd6bbff754f..c8ca99095f26 100644
--- a/include/linux/ceph/librbd.h
+++ b/include/linux/ceph/librbd.h
@@ -99,6 +99,8 @@ enum rbd_img_state {
 };
 
 struct rbd_obj_request;
+typedef void (*rbd_img_request_end_cb_t)(struct rbd_img_request *img_request,
+					 int result);
 
 struct rbd_img_request {
 	struct rbd_device	*rbd_dev;
@@ -114,6 +116,7 @@ struct rbd_img_request {
 		struct request		*rq;		/* block request */
 		struct rbd_obj_request	*obj_request;	/* obj req initiator */
 	};
+	rbd_img_request_end_cb_t callback;
 
 	struct list_head	lock_item;
 	struct list_head	object_extents;	/* obj_req.ex structs */
@@ -237,7 +240,8 @@ enum rbd_dev_flags {
 extern struct rbd_img_request *rbd_img_request_create(
 					struct rbd_device *rbd_dev,
 					enum obj_operation_type op_type,
-					struct ceph_snap_context *snapc);
+					struct ceph_snap_context *snapc,
+					rbd_img_request_end_cb_t end_cb);
 extern int rbd_img_fill_nodata(struct rbd_img_request *img_req,
 			       u64 off, u64 len);
 extern int rbd_img_fill_from_bvecs(struct rbd_img_request *img_req,
-- 
2.16.4