From: Alex Elder <elder@inktank.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH] libceph: tweak ceph_alloc_msg()
Date: Tue, 05 Jun 2012 22:31:30 -0500 [thread overview]
Message-ID: <4FCECF12.4050601@inktank.com> (raw)
In-Reply-To: <4FCECD7F.9030002@inktank.com>
The function ceph_alloc_msg() is only used to allocate a message
that will be assigned to a connection's in_msg pointer. Rename the
function so this implied usage is more clear.
In addition, make that assignment inside the function (again, since
that's precisely what it's intended to be used for). This allows us
to return what is now provided via the passed-in address of a "skip"
variable. The return type is now Boolean to be explicit that there
are only two possible outcomes.
Signed-off-by: Alex Elder <elder@inktank.com>
---
net/ceph/messenger.c | 58
++++++++++++++++++++++++++-----------------------
1 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 3b65f6e..f7c9061 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -1655,9 +1655,8 @@ static int read_partial_message_section(struct
ceph_connection *con,
return 1;
}
-static struct ceph_msg *ceph_alloc_msg(struct ceph_connection *con,
- struct ceph_msg_header *hdr,
- int *skip);
+static bool ceph_con_in_msg_alloc(struct ceph_connection *con,
+ struct ceph_msg_header *hdr);
static int read_partial_message_pages(struct ceph_connection *con,
@@ -1740,7 +1739,6 @@ static int read_partial_message(struct
ceph_connection *con)
int ret;
unsigned front_len, middle_len, data_len;
bool do_datacrc = !con->msgr->nocrc;
- int skip;
u64 seq;
u32 crc;
@@ -1793,9 +1791,7 @@ static int read_partial_message(struct
ceph_connection *con)
if (!con->in_msg) {
dout("got hdr type %d front %d data %d\n", con->in_hdr.type,
con->in_hdr.front_len, con->in_hdr.data_len);
- skip = 0;
- con->in_msg = ceph_alloc_msg(con, &con->in_hdr, &skip);
- if (skip) {
+ if (ceph_con_in_msg_alloc(con, &con->in_hdr)) {
/* skip this message */
dout("alloc_msg said skip message\n");
BUG_ON(con->in_msg);
@@ -2577,46 +2573,54 @@ static int ceph_alloc_middle(struct
ceph_connection *con, struct ceph_msg *msg)
}
/*
- * Generic message allocator, for incoming messages.
+ * Allocate a message for receiving an incoming message on a
+ * connection, and save the result in con->in_msg. Uses the
+ * connection's private alloc_msg op if available.
+ *
+ * Returns true if the message should be skipped, false otherwise.
*/
-static struct ceph_msg *ceph_alloc_msg(struct ceph_connection *con,
- struct ceph_msg_header *hdr,
- int *skip)
+static bool ceph_con_in_msg_alloc(struct ceph_connection *con,
+ struct ceph_msg_header *hdr)
{
int type = le16_to_cpu(hdr->type);
int front_len = le32_to_cpu(hdr->front_len);
int middle_len = le32_to_cpu(hdr->middle_len);
- struct ceph_msg *msg = NULL;
int ret;
+ BUG_ON(con->in_msg != NULL);
+
if (con->ops->alloc_msg) {
+ int skip = 0;
+
mutex_unlock(&con->mutex);
- msg = con->ops->alloc_msg(con, hdr, skip);
+ con->in_msg = con->ops->alloc_msg(con, hdr, &skip);
mutex_lock(&con->mutex);
- if (!msg || *skip)
- return NULL;
+ if (skip)
+ con->in_msg = NULL;
+
+ if (!con->in_msg)
+ return skip != 0;
}
- if (!msg) {
- *skip = 0;
- msg = ceph_msg_new(type, front_len, GFP_NOFS, false);
- if (!msg) {
+ if (!con->in_msg) {
+ con->in_msg = ceph_msg_new(type, front_len, GFP_NOFS, false);
+ if (!con->in_msg) {
pr_err("unable to allocate msg type %d len %d\n",
type, front_len);
- return NULL;
+ return false;
}
- msg->page_alignment = le16_to_cpu(hdr->data_off);
+ con->in_msg->page_alignment = le16_to_cpu(hdr->data_off);
}
- memcpy(&msg->hdr, &con->in_hdr, sizeof(con->in_hdr));
+ memcpy(&con->in_msg->hdr, &con->in_hdr, sizeof(con->in_hdr));
- if (middle_len && !msg->middle) {
- ret = ceph_alloc_middle(con, msg);
+ if (middle_len && !con->in_msg->middle) {
+ ret = ceph_alloc_middle(con, con->in_msg);
if (ret < 0) {
- ceph_msg_put(msg);
- return NULL;
+ ceph_msg_put(con->in_msg);
+ con->in_msg = NULL;
}
}
- return msg;
+ return false;
}
--
1.7.5.4
next prev parent reply other threads:[~2012-06-06 3:31 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-06 3:24 [PATCH 00/11] continued messenger-related changes Alex Elder
2012-06-06 3:30 ` [PATCH] libceph: osd_client: don't drop reply reference too early Alex Elder
2012-06-06 16:18 ` Sage Weil
2012-06-06 3:30 ` [PATCH] libceph: use con get/put ops from osd_client Alex Elder
2012-06-06 3:30 ` [PATCH 1/2] libceph: embed ceph connection structure in mon_client Alex Elder
2012-06-06 5:22 ` Sage Weil
2012-06-06 16:19 ` Sage Weil
2012-06-06 3:31 ` [PATCH 2/2] libceph: drop connection refcounting for mon_client Alex Elder
2012-06-06 3:31 ` [PATCH 1/2] libceph: init monitor connection when opening Alex Elder
2012-06-06 3:31 ` [PATCH 2/2] libceph: fully initialize connection in con_init() Alex Elder
2012-06-06 3:31 ` Alex Elder [this message]
2012-06-06 5:14 ` [PATCH] libceph: tweak ceph_alloc_msg() Sage Weil
2012-06-06 3:31 ` [PATCH 1/4] libceph: have messages point to their connection Alex Elder
2012-06-06 5:16 ` Sage Weil
2012-06-06 3:31 ` [PATCH 2/4] libceph: have messages take a connection reference Alex Elder
2012-06-06 17:06 ` Sage Weil
2012-06-06 17:34 ` Alex Elder
2012-06-06 3:31 ` [PATCH 3/4] libceph: make ceph_con_revoke() a msg operation Alex Elder
2012-06-06 5:18 ` Sage Weil
2012-06-06 11:51 ` Alex Elder
2012-06-06 3:31 ` [PATCH 4/4] libceph: make ceph_con_revoke_message() a msg op Alex Elder
2012-06-06 5:22 ` Sage Weil
2012-06-06 11:40 ` 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=4FCECF12.4050601@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.