unsigned int newlen, int move_data);
void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
int lustre_msg_size(__u32 magic, int count, int *lengths);
+int lustre_packed_msg_size(struct lustre_msg *msg);
int lustre_msg_early_size(void);
int lustre_unpack_msg(struct lustre_msg *m, int len);
void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
struct lustre_msg *new_msg;
old_len = lustre_msg_buflen(old_msg, DLM_INTENT_REC_OFF + 2);
- /* save old size */
- old_size = lustre_msg_size(lustre_request_magic(req),
- req->rq_reqmsg->lm_bufcount,
- req->rq_reqmsg->lm_buflens);
-
+ old_size = lustre_packed_msg_size(old_msg);
lustre_msg_set_buflen(old_msg, DLM_INTENT_REC_OFF + 2,
body->eadatasize);
- new_size = lustre_msg_size(lustre_request_magic(req),
- req->rq_reqmsg->lm_bufcount,
- req->rq_reqmsg->lm_buflens);
+ new_size = lustre_packed_msg_size(old_msg);
+
OBD_ALLOC(new_msg, new_size);
if (new_msg != NULL) {
DEBUG_REQ(D_INFO, req, "replace reqmsg for larger EA %u\n",
}
/* 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_reply);
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);