Commit bb257664 authored by Sage Weil's avatar Sage Weil

ceph: simplify ceph_msg_new

We only need to pass in front_len.  Callers can attach any other payload
pieces (middle, data) as they see fit.
Signed-off-by: default avatarSage Weil <sage@newdream.net>
parent a79832f2
......@@ -938,7 +938,7 @@ static int send_cap_msg(struct ceph_mds_session *session,
seq, issue_seq, mseq, follows, size, max_size,
xattr_version, xattrs_buf ? (int)xattrs_buf->vec.iov_len : 0);
msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, sizeof(*fc), 0, 0, NULL);
msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPS, sizeof(*fc));
if (!msg)
return -ENOMEM;
......
......@@ -665,7 +665,7 @@ static struct ceph_msg *create_session_msg(u32 op, u64 seq)
struct ceph_msg *msg;
struct ceph_mds_session_head *h;
msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h), 0, 0, NULL);
msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h));
if (!msg) {
pr_err("create_session_msg ENOMEM creating msg\n");
return NULL;
......@@ -1051,8 +1051,7 @@ static int add_cap_releases(struct ceph_mds_client *mdsc,
while (session->s_num_cap_releases < session->s_nr_caps + extra) {
spin_unlock(&session->s_cap_lock);
msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPRELEASE, PAGE_CACHE_SIZE,
0, 0, NULL);
msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPRELEASE, PAGE_CACHE_SIZE);
if (!msg)
goto out_unlocked;
dout("add_cap_releases %p msg %p now %d\n", session, msg,
......@@ -1418,7 +1417,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc,
if (req->r_old_dentry_drop)
len += req->r_old_dentry->d_name.len;
msg = ceph_msg_new(CEPH_MSG_CLIENT_REQUEST, len, 0, 0, NULL);
msg = ceph_msg_new(CEPH_MSG_CLIENT_REQUEST, len);
if (!msg) {
msg = ERR_PTR(-ENOMEM);
goto out_free2;
......@@ -2154,7 +2153,7 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc, int mds)
ceph_pagelist_init(pagelist);
err = -ENOMEM;
reply = ceph_msg_new(CEPH_MSG_CLIENT_RECONNECT, 0, 0, 0, NULL);
reply = ceph_msg_new(CEPH_MSG_CLIENT_RECONNECT, 0);
if (!reply)
goto fail_nomsg;
......@@ -2462,7 +2461,7 @@ void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session,
dnamelen = dentry->d_name.len;
len += dnamelen;
msg = ceph_msg_new(CEPH_MSG_CLIENT_LEASE, len, 0, 0, NULL);
msg = ceph_msg_new(CEPH_MSG_CLIENT_LEASE, len);
if (!msg)
return;
lease = msg->front.iov_base;
......
......@@ -2081,8 +2081,7 @@ void ceph_con_keepalive(struct ceph_connection *con)
* construct a new message with given type, size
* the new msg has a ref count of 1.
*/
struct ceph_msg *ceph_msg_new(int type, int front_len,
int page_len, int page_off, struct page **pages)
struct ceph_msg *ceph_msg_new(int type, int front_len)
{
struct ceph_msg *m;
......@@ -2098,8 +2097,8 @@ struct ceph_msg *ceph_msg_new(int type, int front_len,
m->hdr.version = 0;
m->hdr.front_len = cpu_to_le32(front_len);
m->hdr.middle_len = 0;
m->hdr.data_len = cpu_to_le32(page_len);
m->hdr.data_off = cpu_to_le16(page_off);
m->hdr.data_len = 0;
m->hdr.data_off = 0;
m->hdr.reserved = 0;
m->footer.front_crc = 0;
m->footer.middle_crc = 0;
......@@ -2133,18 +2132,17 @@ struct ceph_msg *ceph_msg_new(int type, int front_len,
m->middle = NULL;
/* data */
m->nr_pages = calc_pages_for(page_off, page_len);
m->pages = pages;
m->nr_pages = 0;
m->pages = NULL;
m->pagelist = NULL;
dout("ceph_msg_new %p page %d~%d -> %d\n", m, page_off, page_len,
m->nr_pages);
dout("ceph_msg_new %p front %d\n", m, front_len);
return m;
out2:
ceph_msg_put(m);
out:
pr_err("msg_new can't create type %d len %d\n", type, front_len);
pr_err("msg_new can't create type %d front %d\n", type, front_len);
return NULL;
}
......@@ -2193,7 +2191,7 @@ static struct ceph_msg *ceph_alloc_msg(struct ceph_connection *con,
}
if (!msg) {
*skip = 0;
msg = ceph_msg_new(type, front_len, 0, 0, NULL);
msg = ceph_msg_new(type, front_len);
if (!msg) {
pr_err("unable to allocate msg type %d len %d\n",
type, front_len);
......@@ -2202,7 +2200,7 @@ static struct ceph_msg *ceph_alloc_msg(struct ceph_connection *con,
}
memcpy(&msg->hdr, &con->in_hdr, sizeof(con->in_hdr));
if (middle_len) {
if (middle_len && !msg->middle) {
ret = ceph_alloc_middle(con, msg);
if (ret < 0) {
ceph_msg_put(msg);
......
......@@ -234,9 +234,7 @@ extern void ceph_con_keepalive(struct ceph_connection *con);
extern struct ceph_connection *ceph_con_get(struct ceph_connection *con);
extern void ceph_con_put(struct ceph_connection *con);
extern struct ceph_msg *ceph_msg_new(int type, int front_len,
int page_len, int page_off,
struct page **pages);
extern struct ceph_msg *ceph_msg_new(int type, int front_len);
extern void ceph_msg_kfree(struct ceph_msg *m);
......
......@@ -191,7 +191,7 @@ static void __send_subscribe(struct ceph_mon_client *monc)
struct ceph_mon_subscribe_item *i;
void *p, *end;
msg = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, 0, 0, NULL);
msg = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96);
if (!msg)
return;
......@@ -491,10 +491,10 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
init_completion(&req->completion);
err = -ENOMEM;
req->request = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), 0, 0, NULL);
req->request = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h));
if (!req->request)
goto out;
req->reply = ceph_msg_new(CEPH_MSG_STATFS_REPLY, 1024, 0, 0, NULL);
req->reply = ceph_msg_new(CEPH_MSG_STATFS_REPLY, 1024);
if (!req->reply)
goto out;
......@@ -633,17 +633,15 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
/* msg pools */
err = -ENOMEM;
monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK,
sizeof(struct ceph_mon_subscribe_ack),
0, 0, NULL);
sizeof(struct ceph_mon_subscribe_ack));
if (!monc->m_subscribe_ack)
goto out_monmap;
monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096, 0, 0,
NULL);
monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096);
if (!monc->m_auth_reply)
goto out_subscribe_ack;
monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, 0, 0, NULL);
monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096);
monc->pending_auth = 0;
if (!monc->m_auth)
goto out_auth_reply;
......@@ -818,7 +816,7 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
case CEPH_MSG_MON_MAP:
case CEPH_MSG_MDS_MAP:
case CEPH_MSG_OSD_MAP:
m = ceph_msg_new(type, front_len, 0, 0, NULL);
m = ceph_msg_new(type, front_len);
break;
}
......
......@@ -11,7 +11,7 @@ static void *alloc_fn(gfp_t gfp_mask, void *arg)
{
struct ceph_msgpool *pool = arg;
return ceph_msg_new(0, pool->front_len, 0, 0, NULL);
return ceph_msg_new(0, pool->front_len);
}
static void free_fn(void *element, void *arg)
......@@ -43,7 +43,7 @@ struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *pool,
WARN_ON(1);
/* try to alloc a fresh message */
return ceph_msg_new(0, front_len, 0, 0, NULL);
return ceph_msg_new(0, front_len);
}
return mempool_alloc(pool->pool, GFP_NOFS);
......
......@@ -164,7 +164,7 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0);
else
msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY,
OSD_OPREPLY_FRONT_LEN, 0, 0, NULL);
OSD_OPREPLY_FRONT_LEN);
if (!msg) {
ceph_osdc_put_request(req);
return NULL;
......@@ -178,7 +178,7 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
if (use_mempool)
msg = ceph_msgpool_get(&osdc->msgpool_op, 0);
else
msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, 0, 0, NULL);
msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size);
if (!msg) {
ceph_osdc_put_request(req);
return NULL;
......@@ -1392,7 +1392,7 @@ static struct ceph_msg *get_reply(struct ceph_connection *con,
if (front > req->r_reply->front.iov_len) {
pr_warning("get_reply front %d > preallocated %d\n",
front, (int)req->r_reply->front.iov_len);
m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front, 0, 0, NULL);
m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front);
if (!m)
goto out;
ceph_msg_put(req->r_reply);
......@@ -1435,7 +1435,7 @@ static struct ceph_msg *alloc_msg(struct ceph_connection *con,
switch (type) {
case CEPH_MSG_OSD_MAP:
return ceph_msg_new(type, front, 0, 0, NULL);
return ceph_msg_new(type, front);
case CEPH_MSG_OSD_OPREPLY:
return get_reply(con, hdr, skip);
default:
......
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