Whamcloud - gitweb
Branch b1_6
authorbwzhou <bwzhou>
Fri, 11 Jan 2008 10:29:10 +0000 (10:29 +0000)
committerbwzhou <bwzhou>
Fri, 11 Jan 2008 10:29:10 +0000 (10:29 +0000)
b=14043
r=johann, bobijam

This is used to determine the size of a buffer that was already packed and
will correctly handle the different message formats.

lustre/include/lustre_net.h
lustre/mdc/mdc_locks.c
lustre/ptlrpc/pack_generic.c
lustre/ptlrpc/ptlrpc_module.c

index aa167ca..7883923 100644 (file)
@@ -772,6 +772,7 @@ void lustre_shrink_reply(struct ptlrpc_request *req, int segment,
                          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);
index 36539f0..e171802 100644 (file)
@@ -190,16 +190,11 @@ static void mdc_realloc_openmsg(struct ptlrpc_request *req,
         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",
index 83f3e75..b9da95b 100644 (file)
@@ -118,7 +118,11 @@ static inline int lustre_msg_size_v2(int count, int *lengths)
 }
 
 /* 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) };
@@ -142,6 +146,24 @@ int lustre_msg_size(__u32 magic, int count, int *lens)
         }
 }
 
+/* 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)
 {
@@ -820,16 +842,18 @@ static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
 {
         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;
 }
index 56e7228..5ecfdee 100644 (file)
@@ -193,6 +193,7 @@ EXPORT_SYMBOL(lustre_pack_reply_flags);
 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);