void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
int lustre_msg_size(__u32 magic, int count, int *lengths);
int lustre_msg_size_v2(int count, int *lengths);
+int lustre_packed_msg_size(struct lustre_msg *msg);
int lustre_unpack_msg(struct lustre_msg *m, int len);
void *lustre_msg_buf_v1(void *msg, int n, int min_size);
void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
EXPORT_SYMBOL(lustre_msg_size_v2);
/* This returns the size of the buffer that is required to hold a lustre_msg
- * with the given sub-buffer lengths. */
+ * with the given sub-buffer lengths.
+ * NOTE: this should only be used for NEW requests, and should always be
+ * in the form of a v2 request. If this is a connection to a v1
+ * target then the first buffer will be stripped because the ptlrpc
+ * data is part of the lustre_msg_v1 header. b=14043 */
int lustre_msg_size(__u32 magic, int count, int *lens)
{
int size[] = { sizeof(struct ptlrpc_body) };
}
}
+/* This is used to determine the size of a buffer that was already packed
+ * and will correctly handle the different message formats. */
+int lustre_packed_msg_size(struct lustre_msg *msg)
+{
+ switch (msg->lm_magic) {
+ case LUSTRE_MSG_MAGIC_V1: {
+ struct lustre_msg_v1 *v1_msg = (struct lustre_msg_v1 *)msg;
+ return lustre_msg_size_v1(v1_msg->lm_bufcount,
+ v1_msg->lm_buflens);
+ }
+ case LUSTRE_MSG_MAGIC_V2:
+ return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
+ default:
+ CERROR("incorrect message magic: %08x\n", msg->lm_magic);
+ return 0;
+ }
+}
+
static
void lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
{
{
struct ptlrpc_body *pb;
- pb = lustre_swab_buf(m, offset, sizeof(*pb), lustre_swab_ptlrpc_body);
+ pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
if (!pb) {
CERROR("error unpacking ptlrpc body");
return -EFAULT;
}
+ if (lustre_msg_swabbed(m))
+ lustre_swab_ptlrpc_body(pb);
if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
return -EINVAL;
- }
+ }
return 0;
}
EXPORT_SYMBOL(lustre_shrink_msg);
EXPORT_SYMBOL(lustre_free_reply_state);
EXPORT_SYMBOL(lustre_msg_size);
+EXPORT_SYMBOL(lustre_packed_msg_size);
EXPORT_SYMBOL(lustre_unpack_msg);
EXPORT_SYMBOL(lustre_msg_buf);
EXPORT_SYMBOL(lustre_msg_string);
int segment, int newsize)
{
struct lustre_msg *newbuf;
+ struct lustre_msg *oldbuf = req->rq_reqmsg;
int oldsize, newmsg_size, alloc_size;
LASSERT(req->rq_reqbuf);
LASSERT(req->rq_reqbuf == req->rq_reqmsg);
LASSERT(req->rq_reqbuf_len >= req->rq_reqlen);
- LASSERT(req->rq_reqlen == lustre_msg_size(req->rq_reqmsg->lm_magic,
- req->rq_reqmsg->lm_bufcount,
- req->rq_reqmsg->lm_buflens));
+ LASSERT(req->rq_reqlen == lustre_packed_msg_size(oldbuf));
/* compute new message size */
oldsize = req->rq_reqbuf->lm_buflens[segment];
req->rq_reqbuf->lm_buflens[segment] = newsize;
- newmsg_size = lustre_msg_size(req->rq_reqbuf->lm_magic,
- req->rq_reqbuf->lm_bufcount,
- req->rq_reqbuf->lm_buflens);
+ newmsg_size = lustre_packed_msg_size(oldbuf);
req->rq_reqbuf->lm_buflens[segment] = oldsize;
/* request from pool should always have enough buffer */