Commit 8f3bc053 authored by Sage Weil's avatar Sage Weil

ceph: warn on allocation from msgpool with larger front_len

Pass the front_len we need when pulling a message off a msgpool,
and WARN if it is greater than the pool's size.  Then try to
allocate a new message (to continue without failing).
Signed-off-by: default avatarSage Weil <sage@newdream.net>
parent 07bd10fb
...@@ -639,14 +639,15 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con, ...@@ -639,14 +639,15 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
{ {
struct ceph_mon_client *monc = con->private; struct ceph_mon_client *monc = con->private;
int type = le16_to_cpu(hdr->type); int type = le16_to_cpu(hdr->type);
int front = le32_to_cpu(hdr->front_len);
switch (type) { switch (type) {
case CEPH_MSG_CLIENT_MOUNT_ACK: case CEPH_MSG_CLIENT_MOUNT_ACK:
return ceph_msgpool_get(&monc->msgpool_mount_ack); return ceph_msgpool_get(&monc->msgpool_mount_ack, front);
case CEPH_MSG_MON_SUBSCRIBE_ACK: case CEPH_MSG_MON_SUBSCRIBE_ACK:
return ceph_msgpool_get(&monc->msgpool_subscribe_ack); return ceph_msgpool_get(&monc->msgpool_subscribe_ack, front);
case CEPH_MSG_STATFS_REPLY: case CEPH_MSG_STATFS_REPLY:
return ceph_msgpool_get(&monc->msgpool_statfs_reply); return ceph_msgpool_get(&monc->msgpool_statfs_reply, front);
} }
return ceph_alloc_msg(con, hdr); return ceph_alloc_msg(con, hdr);
} }
......
...@@ -101,14 +101,28 @@ int ceph_msgpool_resv(struct ceph_msgpool *pool, int delta) ...@@ -101,14 +101,28 @@ int ceph_msgpool_resv(struct ceph_msgpool *pool, int delta)
return ret; return ret;
} }
struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *pool) struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *pool, int front_len)
{ {
wait_queue_t wait; wait_queue_t wait;
struct ceph_msg *msg; struct ceph_msg *msg;
if (front_len && front_len > pool->front_len) {
pr_err("msgpool_get pool %p need front %d, pool size is %d\n",
pool, front_len, pool->front_len);
WARN_ON(1);
/* try to alloc a fresh message */
msg = ceph_msg_new(0, front_len, 0, 0, NULL);
if (!IS_ERR(msg))
return msg;
}
if (!front_len)
front_len = pool->front_len;
if (pool->blocking) { if (pool->blocking) {
/* mempool_t behavior; first try to alloc */ /* mempool_t behavior; first try to alloc */
msg = ceph_msg_new(0, pool->front_len, 0, 0, NULL); msg = ceph_msg_new(0, front_len, 0, 0, NULL);
if (!IS_ERR(msg)) if (!IS_ERR(msg))
return msg; return msg;
} }
...@@ -133,7 +147,7 @@ struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *pool) ...@@ -133,7 +147,7 @@ struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *pool)
WARN_ON(1); WARN_ON(1);
/* maybe we can allocate it now? */ /* maybe we can allocate it now? */
msg = ceph_msg_new(0, pool->front_len, 0, 0, NULL); msg = ceph_msg_new(0, front_len, 0, 0, NULL);
if (!IS_ERR(msg)) if (!IS_ERR(msg))
return msg; return msg;
......
...@@ -20,7 +20,8 @@ extern int ceph_msgpool_init(struct ceph_msgpool *pool, ...@@ -20,7 +20,8 @@ extern int ceph_msgpool_init(struct ceph_msgpool *pool,
int front_len, int size, bool blocking); int front_len, int size, bool blocking);
extern void ceph_msgpool_destroy(struct ceph_msgpool *pool); extern void ceph_msgpool_destroy(struct ceph_msgpool *pool);
extern int ceph_msgpool_resv(struct ceph_msgpool *, int delta); extern int ceph_msgpool_resv(struct ceph_msgpool *, int delta);
extern struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *); extern struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *,
int front_len);
extern void ceph_msgpool_put(struct ceph_msgpool *, struct ceph_msg *); extern void ceph_msgpool_put(struct ceph_msgpool *, struct ceph_msg *);
#endif #endif
...@@ -161,7 +161,7 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, ...@@ -161,7 +161,7 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
if (snapc) if (snapc)
msg_size += sizeof(u64) * snapc->num_snaps; msg_size += sizeof(u64) * snapc->num_snaps;
if (use_mempool) if (use_mempool)
msg = ceph_msgpool_get(&osdc->msgpool_op); msg = ceph_msgpool_get(&osdc->msgpool_op, 0);
else else
msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, 0, 0, NULL); msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, 0, 0, NULL);
if (IS_ERR(msg)) { if (IS_ERR(msg)) {
...@@ -1271,10 +1271,11 @@ static struct ceph_msg *alloc_msg(struct ceph_connection *con, ...@@ -1271,10 +1271,11 @@ static struct ceph_msg *alloc_msg(struct ceph_connection *con,
struct ceph_osd *osd = con->private; struct ceph_osd *osd = con->private;
struct ceph_osd_client *osdc = osd->o_osdc; struct ceph_osd_client *osdc = osd->o_osdc;
int type = le16_to_cpu(hdr->type); int type = le16_to_cpu(hdr->type);
int front = le32_to_cpu(hdr->front_len);
switch (type) { switch (type) {
case CEPH_MSG_OSD_OPREPLY: case CEPH_MSG_OSD_OPREPLY:
return ceph_msgpool_get(&osdc->msgpool_op_reply); return ceph_msgpool_get(&osdc->msgpool_op_reply, front);
} }
return ceph_alloc_msg(con, hdr); return ceph_alloc_msg(con, hdr);
} }
......
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