Whamcloud - gitweb
Landing the mds_lock_devel branch on the trunk. Notables:
[fs/lustre-release.git] / lustre / ptlrpc / pack_generic.c
index ad66380..87f5e04 100644 (file)
  *
  */
 
-#define EXPORT_SYMTAB
-
 #define DEBUG_SUBSYSTEM S_CLASS
 
-#include <linux/obd_class.h>
 #include <linux/lustre_net.h>
 
-int lustre_pack_msg(int count, int *lens, char **bufs, int *len, char **buf)
+int lustre_pack_msg(int count, int *lens, char **bufs, int *len,
+                    struct lustre_msg **msg)
 {
         char *ptr;
         struct lustre_msg *m;
@@ -38,18 +36,18 @@ int lustre_pack_msg(int count, int *lens, char **bufs, int *len, char **buf)
         for (i = 0; i < count; i++)
                 size += size_round(lens[i]);
 
-        *len = sizeof(*m) + count * sizeof(__u32) + size;
+        *len = size_round(sizeof(*m) + count * sizeof(__u32)) + size;
 
-        OBD_ALLOC(*buf, *len);
-        if (!*buf)
+        OBD_ALLOC(*msg, *len);
+        if (!*msg)
                 RETURN(-ENOMEM);
 
-        m = (struct lustre_msg *)(*buf);
+        m = *msg;
         m->bufcount = HTON__u32(count);
         for (i = 0; i < count; i++)
                 m->buflens[i] = HTON__u32(lens[i]);
 
-        ptr = *buf + sizeof(*m) + sizeof(__u32) * count;
+        ptr = (char *)m + size_round(sizeof(*m) + count * sizeof(__u32));
         for (i = 0; i < count; i++) {
                 char *tmp = NULL;
                 if (bufs)
@@ -64,33 +62,33 @@ int lustre_pack_msg(int count, int *lens, char **bufs, int *len, char **buf)
  * with the given sub-buffer lengths. */
 int lustre_msg_size(int count, int *lengths)
 {
-        int size = sizeof(struct lustre_msg), i;
+        int size = 0, i;
 
         for (i = 0; i < count; i++)
                 size += size_round(lengths[i]);
 
-        size += count * sizeof(__u32);
+        size += size_round(sizeof(struct lustre_msg) + count * sizeof(__u32));
 
         return size;
 }
 
-int lustre_unpack_msg(char *buf, int len)
+int lustre_unpack_msg(struct lustre_msg *m, int len)
 {
-        struct lustre_msg *m = (struct lustre_msg *)buf;
         int required_len, i;
 
-        required_len = sizeof(*m);
+        required_len = size_round(sizeof(*m));
         if (len < required_len)
                 RETURN(-EINVAL);
 
         m->opc = NTOH__u32(m->opc);
-        m->xid = NTOH__u32(m->xid);
         m->status = NTOH__u32(m->status);
         m->type = NTOH__u32(m->type);
-        m->connid = NTOH__u32(m->connid);
         m->bufcount = NTOH__u32(m->bufcount);
+        m->last_rcvd = NTOH__u64(m->last_rcvd);
+        m->last_committed = NTOH__u64(m->last_committed);
+        m->target_id = NTOH__u32(m->target_id);
 
-        required_len += m->bufcount * sizeof(__u32);
+        required_len = size_round(sizeof(*m) + m->bufcount * sizeof(__u32));
         if (len < required_len)
                 RETURN(-EINVAL);
 
@@ -120,7 +118,7 @@ void *lustre_msg_buf(struct lustre_msg *m, int n)
         if (m->buflens[n] == 0)
                 return NULL;
 
-        offset = sizeof(*m) + m->bufcount * sizeof(__u32);
+        offset = size_round(sizeof(*m) + m->bufcount * sizeof(__u32));
 
         for (i = 0; i < n; i++)
                 offset += size_round(m->buflens[i]);