All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@inktank.com>
To: "ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>
Subject: [PATCH REPOST 4/6] rbd: define generalized osd request op routines
Date: Fri, 04 Jan 2013 09:06:45 -0600	[thread overview]
Message-ID: <50E6F005.10909@inktank.com> (raw)
In-Reply-To: <50E6EF5F.9080200@inktank.com>

Create a baseline function to encapsulate the creation of osd
requests, along with a matching function to destroy them.  For now
this just duplicates what rbd_create_rw_op() does for read and write
operations, but the next patches will expand on this.

Since rbd_create_rw_op() is no longer used for read or write
requests, the special handling in that function for those types can
be removed.

Signed-off-by: Alex Elder <elder@inktank.com>
---
 drivers/block/rbd.c |   52
+++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 40 insertions(+), 12 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 685d049..6fa6ba7 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1034,14 +1034,6 @@ static struct ceph_osd_req_op
*rbd_create_rw_op(int opcode, u64 ofs, u64 len)
 		return NULL;

 	op->op = opcode;
-	if (opcode == CEPH_OSD_OP_READ || opcode == CEPH_OSD_OP_WRITE) {
-		op->extent.offset = ofs;
-		op->extent.length = len;
-		if (opcode == CEPH_OSD_OP_WRITE) {
-			rbd_assert(len <= (u64) U32_MAX);
-			op->payload_len = len;
-		}
-	}

 	return op;
 }
@@ -1051,6 +1043,42 @@ static void rbd_destroy_op(struct ceph_osd_req_op
*op)
 	kfree(op);
 }

+struct ceph_osd_req_op *rbd_osd_req_op_create(u16 opcode, ...)
+{
+	struct ceph_osd_req_op *op;
+	va_list args;
+
+	op = kzalloc(sizeof (*op), GFP_NOIO);
+	if (!op)
+		return NULL;
+	op->op = opcode;
+	va_start(args, opcode);
+	switch (opcode) {
+	case CEPH_OSD_OP_READ:
+	case CEPH_OSD_OP_WRITE:
+		/* rbd_osd_req_op_create(READ, offset, length) */
+		/* rbd_osd_req_op_create(WRITE, offset, length) */
+		op->extent.offset = va_arg(args, u64);
+		op->extent.length = va_arg(args, u64);
+		if (opcode == CEPH_OSD_OP_WRITE)
+			op->payload_len = op->extent.length;
+		break;
+	default:
+		rbd_warn(NULL, "unsupported opcode %hu\n", opcode);
+		kfree(op);
+		op = NULL;
+		break;
+	}
+	va_end(args);
+
+	return op;
+}
+
+static void rbd_osd_req_op_destroy(struct ceph_osd_req_op *op)
+{
+	kfree(op);
+}
+
 static void rbd_coll_end_req_index(struct request *rq,
 				   struct rbd_req_coll *coll,
 				   int index,
@@ -1323,7 +1351,7 @@ static int rbd_do_op(struct request *rq,
 	}

 	ret = -ENOMEM;
-	op = rbd_create_rw_op(opcode, seg_ofs, seg_len);
+	op = rbd_osd_req_op_create(opcode, seg_ofs, seg_len);
 	if (!op)
 		goto done;

@@ -1343,7 +1371,7 @@ static int rbd_do_op(struct request *rq,
 	if (ret < 0)
 		rbd_coll_end_req_index(rq, coll, coll_index,
 					(s32) ret, seg_len);
-	rbd_destroy_op(op);
+	rbd_osd_req_op_destroy(op);
 done:
 	kfree(seg_name);
 	return ret;
@@ -1361,13 +1389,13 @@ static int rbd_req_sync_read(struct rbd_device
*rbd_dev,
 	struct ceph_osd_req_op *op;
 	int ret;

-	op = rbd_create_rw_op(CEPH_OSD_OP_READ, ofs, len);
+	op = rbd_osd_req_op_create(CEPH_OSD_OP_READ, ofs, len);
 	if (!op)
 		return -ENOMEM;

 	ret = rbd_req_sync_op(rbd_dev, CEPH_OSD_FLAG_READ,
 			       op, object_name, ofs, len, buf, NULL, ver);
-	rbd_destroy_op(op);
+	rbd_osd_req_op_destroy(op);

 	return ret;
 }
-- 
1.7.9.5


  parent reply	other threads:[~2013-01-04 15:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-04 15:03 [PATCH REPOST 0/6] rbd: consolidate osd request setup Alex Elder
2013-01-04 15:05 ` [PATCH REPOST 1/6] rbd: don't assign extent info in rbd_do_request() Alex Elder
2013-01-04 15:06 ` [PATCH REPOST 2/6] rbd: don't assign extent info in rbd_req_sync_op() Alex Elder
2013-01-04 15:06 ` [PATCH REPOST 3/6] rbd: initialize off and len in rbd_create_rw_op() Alex Elder
2013-01-04 15:06 ` Alex Elder [this message]
2013-01-04 15:06 ` [PATCH REPOST 5/6] rbd: move call osd op setup into rbd_osd_req_op_create() Alex Elder
2013-01-04 15:07 ` [PATCH REPOST 6/6] rbd: move remaining " Alex Elder
2013-01-17  4:23   ` Josh Durgin
2013-01-17  4:37     ` Alex Elder
2013-01-17 22:25       ` Alex Elder
2013-01-17  4:25 ` [PATCH REPOST 0/6] rbd: consolidate osd request setup Josh Durgin
2013-01-17 22:19   ` Alex Elder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50E6F005.10909@inktank.com \
    --to=elder@inktank.com \
    --cc=ceph-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.