Commit 1c20f2d2 authored by Alex Elder's avatar Alex Elder Committed by Alex Elder

libceph: tweak ceph_alloc_msg()

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.

Make sure the result of an ->alloc_msg method call always sets the
value of *skip properly.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarSage Weil <sage@inktank.com>
parent 1bfd89f4
...@@ -1655,9 +1655,8 @@ static int read_partial_message_section(struct ceph_connection *con, ...@@ -1655,9 +1655,8 @@ static int read_partial_message_section(struct ceph_connection *con,
return 1; return 1;
} }
static struct ceph_msg *ceph_alloc_msg(struct ceph_connection *con, static bool ceph_con_in_msg_alloc(struct ceph_connection *con,
struct ceph_msg_header *hdr, struct ceph_msg_header *hdr);
int *skip);
static int read_partial_message_pages(struct ceph_connection *con, static int read_partial_message_pages(struct ceph_connection *con,
...@@ -1740,7 +1739,6 @@ static int read_partial_message(struct ceph_connection *con) ...@@ -1740,7 +1739,6 @@ static int read_partial_message(struct ceph_connection *con)
int ret; int ret;
unsigned front_len, middle_len, data_len; unsigned front_len, middle_len, data_len;
bool do_datacrc = !con->msgr->nocrc; bool do_datacrc = !con->msgr->nocrc;
int skip;
u64 seq; u64 seq;
u32 crc; u32 crc;
...@@ -1793,9 +1791,7 @@ static int read_partial_message(struct ceph_connection *con) ...@@ -1793,9 +1791,7 @@ static int read_partial_message(struct ceph_connection *con)
if (!con->in_msg) { if (!con->in_msg) {
dout("got hdr type %d front %d data %d\n", con->in_hdr.type, dout("got hdr type %d front %d data %d\n", con->in_hdr.type,
con->in_hdr.front_len, con->in_hdr.data_len); con->in_hdr.front_len, con->in_hdr.data_len);
skip = 0; if (ceph_con_in_msg_alloc(con, &con->in_hdr)) {
con->in_msg = ceph_alloc_msg(con, &con->in_hdr, &skip);
if (skip) {
/* skip this message */ /* skip this message */
dout("alloc_msg said skip message\n"); dout("alloc_msg said skip message\n");
BUG_ON(con->in_msg); BUG_ON(con->in_msg);
...@@ -2577,46 +2573,57 @@ static int ceph_alloc_middle(struct ceph_connection *con, struct ceph_msg *msg) ...@@ -2577,46 +2573,57 @@ 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.
* If true is returned (skip message), con->in_msg will be NULL.
* If false is returned, con->in_msg will contain a pointer to the
* newly-allocated message, or NULL in case of memory exhaustion.
*/ */
static struct ceph_msg *ceph_alloc_msg(struct ceph_connection *con, static bool ceph_con_in_msg_alloc(struct ceph_connection *con,
struct ceph_msg_header *hdr, struct ceph_msg_header *hdr)
int *skip)
{ {
int type = le16_to_cpu(hdr->type); int type = le16_to_cpu(hdr->type);
int front_len = le32_to_cpu(hdr->front_len); int front_len = le32_to_cpu(hdr->front_len);
int middle_len = le32_to_cpu(hdr->middle_len); int middle_len = le32_to_cpu(hdr->middle_len);
struct ceph_msg *msg = NULL;
int ret; int ret;
BUG_ON(con->in_msg != NULL);
if (con->ops->alloc_msg) { if (con->ops->alloc_msg) {
int skip = 0;
mutex_unlock(&con->mutex); 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); mutex_lock(&con->mutex);
if (!msg || *skip) if (skip)
return NULL; con->in_msg = NULL;
if (!con->in_msg)
return skip != 0;
} }
if (!msg) { if (!con->in_msg) {
*skip = 0; con->in_msg = ceph_msg_new(type, front_len, GFP_NOFS, false);
msg = ceph_msg_new(type, front_len, GFP_NOFS, false); if (!con->in_msg) {
if (!msg) {
pr_err("unable to allocate msg type %d len %d\n", pr_err("unable to allocate msg type %d len %d\n",
type, front_len); 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) { if (middle_len && !con->in_msg->middle) {
ret = ceph_alloc_middle(con, msg); ret = ceph_alloc_middle(con, con->in_msg);
if (ret < 0) { if (ret < 0) {
ceph_msg_put(msg); ceph_msg_put(con->in_msg);
return NULL; con->in_msg = NULL;
} }
} }
return msg; return false;
} }
......
...@@ -442,6 +442,7 @@ static struct ceph_msg *get_generic_reply(struct ceph_connection *con, ...@@ -442,6 +442,7 @@ static struct ceph_msg *get_generic_reply(struct ceph_connection *con,
m = NULL; m = NULL;
} else { } else {
dout("get_generic_reply %lld got %p\n", tid, req->reply); dout("get_generic_reply %lld got %p\n", tid, req->reply);
*skip = 0;
m = ceph_msg_get(req->reply); m = ceph_msg_get(req->reply);
/* /*
* we don't need to track the connection reading into * we don't need to track the connection reading into
...@@ -982,6 +983,8 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con, ...@@ -982,6 +983,8 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
case CEPH_MSG_MDS_MAP: case CEPH_MSG_MDS_MAP:
case CEPH_MSG_OSD_MAP: case CEPH_MSG_OSD_MAP:
m = ceph_msg_new(type, front_len, GFP_NOFS, false); m = ceph_msg_new(type, front_len, GFP_NOFS, false);
if (!m)
return NULL; /* ENOMEM--return skip == 0 */
break; break;
} }
......
...@@ -2077,6 +2077,7 @@ static struct ceph_msg *alloc_msg(struct ceph_connection *con, ...@@ -2077,6 +2077,7 @@ static struct ceph_msg *alloc_msg(struct ceph_connection *con,
int type = le16_to_cpu(hdr->type); int type = le16_to_cpu(hdr->type);
int front = le32_to_cpu(hdr->front_len); int front = le32_to_cpu(hdr->front_len);
*skip = 0;
switch (type) { switch (type) {
case CEPH_MSG_OSD_MAP: case CEPH_MSG_OSD_MAP:
case CEPH_MSG_WATCH_NOTIFY: case CEPH_MSG_WATCH_NOTIFY:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment