All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@inktank.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 2/3] libceph: distinguish page and bio requests
Date: Mon, 04 Mar 2013 12:18:08 -0600	[thread overview]
Message-ID: <5134E560.4020204@inktank.com> (raw)
In-Reply-To: <5134E515.6010006@inktank.com>

An osd request uses either pages or a bio list for its data.  Use a
union to record information about the two, and add a data type
tag to select between them.

Signed-off-by: Alex Elder <elder@inktank.com>
---
 drivers/block/rbd.c             |    4 +++
 fs/ceph/file.c                  |    1 +
 include/linux/ceph/osd_client.h |   11 +++++++-
 net/ceph/osd_client.c           |   56
+++++++++++++++++++++++++--------------
 4 files changed, 51 insertions(+), 21 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index dcf08f2..70c3b39 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1412,12 +1412,16 @@ static struct ceph_osd_request *rbd_osd_req_create(
 		break;		/* Nothing to do */
 	case OBJ_REQUEST_BIO:
 		rbd_assert(obj_request->bio_list != NULL);
+		osd_req->r_data.type = CEPH_OSD_DATA_TYPE_BIO;
 		osd_req->r_data.bio = obj_request->bio_list;
 		break;
 	case OBJ_REQUEST_PAGES:
+		osd_req->r_data.type = CEPH_OSD_DATA_TYPE_PAGES;
 		osd_req->r_data.pages = obj_request->pages;
 		osd_req->r_data.num_pages = obj_request->page_count;
 		osd_req->r_data.alignment = offset & ~PAGE_MASK;
+		osd_req->r_data.pages_from_pool = false;
+		osd_req->r_data.own_pages = false;
 		break;
 	}

diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 76739049..0f7b3f4 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -571,6 +571,7 @@ more:
 			req->r_data.own_pages = 1;
 		}
 	}
+	req->r_data.type = CEPH_OSD_DATA_TYPE_PAGES;
 	req->r_data.pages = pages;
 	req->r_data.num_pages = num_pages;
 	req->r_data.alignment = page_align;
diff --git a/include/linux/ceph/osd_client.h
b/include/linux/ceph/osd_client.h
index 600b827..56604b3 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -50,8 +50,17 @@ struct ceph_osd {

 #define CEPH_OSD_MAX_OP 10

+enum ceph_osd_data_type {
+	CEPH_OSD_DATA_TYPE_NONE,
+	CEPH_OSD_DATA_TYPE_PAGES,
+#ifdef CONFIG_BLOCK
+	CEPH_OSD_DATA_TYPE_BIO,
+#endif /* CONFIG_BLOCK */
+};
+
 struct ceph_osd_data {
-	struct {
+	enum ceph_osd_data_type	type;
+	union {
 		struct {
 			struct page	**pages;
 			u32		num_pages;
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 1f8c7a7..591e1b0 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -122,7 +122,8 @@ void ceph_osdc_release_request(struct kref *kref)
 	}
 	if (req->r_reply)
 		ceph_msg_put(req->r_reply);
-	if (req->r_data.own_pages)
+	if (req->r_data.type == CEPH_OSD_DATA_TYPE_PAGES &&
+			req->r_data.own_pages)
 		ceph_release_page_vector(req->r_data.pages,
 					 req->r_data.num_pages);
 	ceph_put_snap_context(req->r_snapc);
@@ -188,6 +189,7 @@ struct ceph_osd_request
*ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
 	}
 	req->r_reply = msg;

+	req->r_data.type = CEPH_OSD_DATA_TYPE_NONE;
 	ceph_pagelist_init(&req->r_trail);

 	/* create request message; allow space for oid */
@@ -1739,12 +1741,17 @@ int ceph_osdc_start_request(struct
ceph_osd_client *osdc,
 {
 	int rc = 0;

-	req->r_request->pages = req->r_data.pages;
-	req->r_request->page_count = req->r_data.num_pages;
-	req->r_request->page_alignment = req->r_data.alignment;
+	if (req->r_data.type == CEPH_OSD_DATA_TYPE_PAGES) {
+		req->r_request->pages = req->r_data.pages;
+		req->r_request->page_count = req->r_data.num_pages;
+		req->r_request->page_alignment = req->r_data.alignment;
 #ifdef CONFIG_BLOCK
-	req->r_request->bio = req->r_data.bio;
+	} else if (req->r_data.type == CEPH_OSD_DATA_TYPE_BIO) {
+		req->r_request->bio = req->r_data.bio;
 #endif
+	} else {
+		pr_err("unknown request data type %d\n", req->r_data.type);
+	}
 	req->r_request->trail = &req->r_trail;

 	register_request(osdc, req);
@@ -1944,6 +1951,7 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc,
 		return PTR_ERR(req);

 	/* it may be a short read due to an object boundary */
+	req->r_data.type = CEPH_OSD_DATA_TYPE_PAGES;
 	req->r_data.pages = pages;
 	req->r_data.num_pages = calc_pages_for(page_align, *plen);
 	req->r_data.alignment = page_align;
@@ -1987,6 +1995,7 @@ int ceph_osdc_writepages(struct ceph_osd_client
*osdc, struct ceph_vino vino,
 		return PTR_ERR(req);

 	/* it may be a short write due to an object boundary */
+	req->r_data.type = CEPH_OSD_DATA_TYPE_PAGES;
 	req->r_data.pages = pages;
 	req->r_data.num_pages = calc_pages_for(page_align, len);
 	req->r_data.alignment = page_align;
@@ -2083,23 +2092,30 @@ static struct ceph_msg *get_reply(struct
ceph_connection *con,
 	m = ceph_msg_get(req->r_reply);

 	if (data_len > 0) {
-		int want = calc_pages_for(req->r_data.alignment, data_len);
-
-		if (req->r_data.pages && unlikely(req->r_data.num_pages < want)) {
-			pr_warning("tid %lld reply has %d bytes %d pages, we"
-				   " had only %d pages ready\n", tid, data_len,
-				   want, req->r_data.num_pages);
-			*skip = 1;
-			ceph_msg_put(m);
-			m = NULL;
-			goto out;
-		}
-		m->pages = req->r_data.pages;
-		m->page_count = req->r_data.num_pages;
-		m->page_alignment = req->r_data.alignment;
+		if (req->r_data.type == CEPH_OSD_DATA_TYPE_PAGES) {
+			int want;
+
+			want = calc_pages_for(req->r_data.alignment, data_len);
+			if (req->r_data.pages &&
+				unlikely(req->r_data.num_pages < want)) {
+
+				pr_warning("tid %lld reply has %d bytes %d "
+					"pages, we had only %d pages ready\n",
+					tid, data_len, want,
+					req->r_data.num_pages);
+				*skip = 1;
+				ceph_msg_put(m);
+				m = NULL;
+				goto out;
+			}
+			m->pages = req->r_data.pages;
+			m->page_count = req->r_data.num_pages;
+			m->page_alignment = req->r_data.alignment;
 #ifdef CONFIG_BLOCK
-		m->bio = req->r_data.bio;
+		} else if (req->r_data.type == CEPH_OSD_DATA_TYPE_BIO) {
+			m->bio = req->r_data.bio;
 #endif
+		}
 	}
 	*skip = 0;
 	req->r_con_filling_msg = con->ops->get(con);
-- 
1.7.9.5


  parent reply	other threads:[~2013-03-04 18:18 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-04 18:05 OSD Data Read/Write Separation Patches Alex Elder
2013-03-04 18:08 ` [PATCH 0/3] libceph: a few cleanups Alex Elder
2013-03-04 18:09   ` [PATCH 1/3] libceph: use (void *) for untyped data in osd ops Alex Elder
2013-03-04 18:09   ` [PATCH 2/3] libceph: kill ceph_msg->pagelist_count Alex Elder
2013-03-04 18:09   ` [PATCH 3/3] libceph: rename ceph_calc_object_layout() Alex Elder
2013-03-05  1:49   ` [PATCH 0/3] libceph: a few cleanups Josh Durgin
2013-03-04 18:10 ` [PATCH 0/3] libceph: simplify incoming message allocation Alex Elder
2013-03-04 18:12   ` [PATCH 1/3] libceph: drop mutex while allocating a message Alex Elder
2013-03-04 19:07     ` Gregory Farnum
2013-03-04 19:25       ` Alex Elder
2013-03-04 19:39         ` Gregory Farnum
2013-03-04 19:52           ` Alex Elder
2013-03-04 18:12   ` [PATCH 2/3] libceph: define mds_alloc_msg() method Alex Elder
2013-03-04 19:05     ` Gregory Farnum
2013-03-04 19:37       ` Alex Elder
2013-03-04 18:12   ` [PATCH 3/3] libceph: no need for alignment for mds message Alex Elder
2013-03-04 19:09     ` Gregory Farnum
2013-03-04 18:14 ` [PATCH 0/3] ceph: assign message data fields consistently Alex Elder
2013-03-04 18:15   ` [PATCH 1/3] ceph: use calc_pages_for() in start_read() Alex Elder
2013-03-04 18:15   ` [PATCH 2/3] ceph: simplify ceph_sync_write() page_align calculation Alex Elder
2013-03-04 18:15   ` [PATCH 3/3] libceph: don't assign page info in ceph_osdc_new_request() Alex Elder
2013-03-05  1:55   ` [PATCH 0/3] ceph: assign message data fields consistently Josh Durgin
2013-03-04 18:16 ` [PATCH 0/3] libceph: distinguish osd request read and write data Alex Elder
2013-03-04 18:17   ` [PATCH 1/3] libceph: separate osd request data info Alex Elder
2013-03-05  2:13     ` Josh Durgin
2013-03-04 18:18   ` Alex Elder [this message]
2013-03-05  2:14     ` [PATCH 2/3] libceph: distinguish page and bio requests Josh Durgin
2013-03-04 18:18   ` [PATCH 3/3] libceph: separate read and write data Alex Elder
2013-03-05  2:15     ` Josh Durgin

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=5134E560.4020204@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.