Whamcloud - gitweb
b=1021,2720
[fs/lustre-release.git] / lustre / ptlrpc / pack_generic.c
index e0e725a..c735d01 100644 (file)
@@ -31,6 +31,7 @@
 #endif
 
 #include <linux/obd_support.h>
+#include <linux/obd_class.h>
 #include <linux/lustre_net.h>
 
 
@@ -42,54 +43,114 @@ int lustre_msg_swabbed(struct lustre_msg *msg)
         return (msg->magic == __swab32(PTLRPC_MSG_MAGIC));
 }
 
-static int lustre_pack_msg(int count, int *lens, char **bufs, int *len,
-                           struct lustre_msg **msg)
+static void
+lustre_init_msg (struct lustre_msg *msg, int count, int *lens, char **bufs)
 {
         char *ptr;
-        struct lustre_msg *m;
-        int size = 0, i;
-
-        size = HDR_SIZE (count);
+        int   i;
+        
+        msg->magic = PTLRPC_MSG_MAGIC;
+        msg->version = PTLRPC_MSG_VERSION;
+        msg->bufcount = count;
         for (i = 0; i < count; i++)
-                size += size_round(lens[i]);
-
-        *len = size;
-
-        OBD_ALLOC(*msg, *len);
-        if (!*msg)
-                RETURN(-ENOMEM);
+                msg->buflens[i] = lens[i];
 
-        m = *msg;
-        m->magic = PTLRPC_MSG_MAGIC;
-        m->version = PTLRPC_MSG_VERSION;
-        m->bufcount = count;
-        for (i = 0; i < count; i++)
-                m->buflens[i] = lens[i];
+        if (bufs == NULL)
+                return;
 
-        ptr = (char *)m + HDR_SIZE(count);
+        ptr = (char *)msg + HDR_SIZE(count);
         for (i = 0; i < count; i++) {
-                char *tmp = NULL;
-                if (bufs)
-                        tmp = bufs[i];
+                char *tmp = bufs[i];
                 LOGL(tmp, lens[i], ptr);
-
         }
+}
 
-        return 0;
+int lustre_pack_request (struct ptlrpc_request *req, 
+                         int count, int *lens, char **bufs)
+{
+        ENTRY;
+        
+        req->rq_reqlen = lustre_msg_size (count, lens);
+        OBD_ALLOC(req->rq_reqmsg, req->rq_reqlen);
+        if (req->rq_reqmsg == NULL)
+                RETURN(-ENOMEM);
+
+        lustre_init_msg (req->rq_reqmsg, count, lens, bufs);
+        RETURN (0);
 }
 
-int lustre_pack_request(struct ptlrpc_request *req, int count, int *lens,
-                        char **bufs)
+#if RS_DEBUG
+LIST_HEAD(ptlrpc_rs_debug_lru);
+spinlock_t ptlrpc_rs_debug_lock = SPIN_LOCK_UNLOCKED;
+
+#define PTLRPC_RS_DEBUG_LRU_ADD(rs)                                     \
+do {                                                                    \
+        unsigned long __flags;                                          \
+                                                                        \
+        spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags);              \
+        list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru);      \
+        spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags);         \
+} while (0)
+
+#define PTLRPC_RS_DEBUG_LRU_DEL(rs)                                     \
+do {                                                                    \
+        unsigned long __flags;                                          \
+                                                                        \
+        spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags);              \
+        list_del(&(rs)->rs_debug_list);                                 \
+        spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags);         \
+} while (0)
+#else
+# define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
+# define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
+#endif
+
+int lustre_pack_reply (struct ptlrpc_request *req,
+                       int count, int *lens, char **bufs)
 {
-        return lustre_pack_msg(count, lens, bufs, &req->rq_reqlen,
-                               &req->rq_reqmsg);
+        struct ptlrpc_reply_state *rs;
+        int                        msg_len;
+        int                        size;
+        ENTRY;
+
+        LASSERT (req->rq_reply_state == NULL);
+
+        msg_len = lustre_msg_size (count, lens);
+        size = offsetof (struct ptlrpc_reply_state, rs_msg) + msg_len;
+        OBD_ALLOC (rs, size);
+        if (rs == NULL)
+                RETURN (-ENOMEM);
+
+        rs->rs_cb_id.cbid_fn = reply_out_callback;
+        rs->rs_cb_id.cbid_arg = rs;
+        rs->rs_srv_ni = req->rq_rqbd->rqbd_srv_ni;
+        rs->rs_size = size;
+        INIT_LIST_HEAD(&rs->rs_exp_list);
+        INIT_LIST_HEAD(&rs->rs_obd_list);
+
+        req->rq_replen = msg_len;
+        req->rq_reply_state = rs;
+        req->rq_repmsg = &rs->rs_msg;
+        lustre_init_msg (&rs->rs_msg, count, lens, bufs);
+
+        PTLRPC_RS_DEBUG_LRU_ADD(rs);
+
+        RETURN (0);
 }
 
-int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens,
-                      char **bufs)
+void lustre_free_reply_state (struct ptlrpc_reply_state *rs)
 {
-        return lustre_pack_msg(count, lens, bufs, &req->rq_replen,
-                               &req->rq_repmsg);
+        PTLRPC_RS_DEBUG_LRU_DEL(rs);
+
+        LASSERT (!rs->rs_difficult || rs->rs_handled);
+        LASSERT (!rs->rs_on_net);
+        LASSERT (!rs->rs_scheduled);
+        LASSERT (rs->rs_export == NULL);
+        LASSERT (rs->rs_nlocks == 0);
+        LASSERT (list_empty(&rs->rs_exp_list));
+        LASSERT (list_empty(&rs->rs_obd_list));
+
+        OBD_FREE (rs, rs->rs_size);
 }
 
 /* This returns the size of the buffer that is required to hold a lustre_msg
@@ -257,40 +318,34 @@ char *lustre_msg_string (struct lustre_msg *m, int index, int max_len)
         return (str);
 }
 
-/* Wrap up the normal fixed length case */
-void *lustre_swab_reqbuf (struct ptlrpc_request *req, int index, int min_size,
-                          void *swabber)
+/* Wrap up the normal fixed length cases */
+void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
+                      void *swabber)
 {
         void *ptr;
 
-        LASSERT_REQSWAB(req, index);
-
-        ptr = lustre_msg_buf(req->rq_reqmsg, index, min_size);
+        ptr = lustre_msg_buf(msg, index, min_size);
         if (ptr == NULL)
                 return NULL;
 
-        if (swabber != NULL && lustre_msg_swabbed(req->rq_reqmsg))
+        if (swabber != NULL && lustre_msg_swabbed(msg))
                 ((void (*)(void *))swabber)(ptr);
 
         return ptr;
 }
 
-/* Wrap up the normal fixed length case */
-void *lustre_swab_repbuf (struct ptlrpc_request *req, int index, int min_size,
-                          void *swabber)
+void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
+                         void *swabber)
 {
-        void *ptr;
+        LASSERT_REQSWAB(req, index);
+        return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
+}
 
+void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
+                         void *swabber)
+{
         LASSERT_REPSWAB(req, index);
-
-        ptr = lustre_msg_buf(req->rq_repmsg, index, min_size);
-        if (ptr == NULL)
-                return NULL;
-
-        if (swabber != NULL && lustre_msg_swabbed(req->rq_repmsg))
-                ((void (*)(void *))swabber)(ptr);
-
-        return ptr;
+        return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
 }
 
 /* byte flipping routines for all wire types declared in
@@ -306,7 +361,7 @@ void lustre_swab_obdo (struct obdo  *o)
         __swab64s (&o->o_ctime);
         __swab64s (&o->o_size);
         __swab64s (&o->o_blocks);
-        __swab64s (&o->o_rdev);
+        __swab64s (&o->o_grant);
         __swab32s (&o->o_blksize);
         __swab32s (&o->o_mode);
         __swab32s (&o->o_uid);
@@ -315,7 +370,7 @@ void lustre_swab_obdo (struct obdo  *o)
         __swab32s (&o->o_nlink);
         __swab32s (&o->o_generation);
         __swab32s (&o->o_valid);
-        __swab32s (&o->o_obdflags);
+        __swab32s (&o->o_misc);
         __swab32s (&o->o_easize);
         /* o_inline is opaque */
 }
@@ -358,6 +413,12 @@ void lustre_swab_ost_last_id(obd_id *id)
         __swab64s(id);
 }
 
+void lustre_swab_ost_lvb(struct ost_lvb *lvb)
+{
+        __swab64s(&lvb->lvb_size);
+        __swab64s(&lvb->lvb_time);
+}
+
 void lustre_swab_ll_fid (struct ll_fid *fid)
 {
         __swab64s (&fid->id);
@@ -503,24 +564,16 @@ void lustre_swab_ldlm_intent (struct ldlm_intent *i)
 
 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
 {
-        int   i;
-
         __swab32s (&r->lr_type);
         lustre_swab_ldlm_res_id (&r->lr_name);
-        for (i = 0; i < RES_VERSION_SIZE; i++)
-                __swab32s (&r->lr_version[i]);
 }
 
 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
 {
-        int   i;
-
         lustre_swab_ldlm_resource_desc (&l->l_resource);
         __swab32s (&l->l_req_mode);
         __swab32s (&l->l_granted_mode);
         lustre_swab_ldlm_policy_data (&l->l_policy_data);
-        for (i = 0; i < RES_VERSION_SIZE; i++)
-                __swab32s (&l->l_version[i]);
 }
 
 void lustre_swab_ldlm_request (struct ldlm_request *rq)
@@ -534,10 +587,8 @@ void lustre_swab_ldlm_request (struct ldlm_request *rq)
 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
 {
         __swab32s (&r->lock_flags);
-        __swab32s (&r->lock_mode);
-        lustre_swab_ldlm_res_id (&r->lock_resource_name);
+        lustre_swab_ldlm_lock_desc (&r->lock_desc);
         /* lock_handle opaque */
-        lustre_swab_ldlm_policy_data (&r->lock_policy_data);
         __swab64s (&r->lock_policy_res1);
         __swab64s (&r->lock_policy_res2);
 }
@@ -615,7 +666,7 @@ void lustre_swab_llogd_conn_body (struct llogd_conn_body *d)
 void lustre_assert_wire_constants(void)
 {
         /* Wire protocol assertions generated by 'wirecheck'
-         * running on Linux schnapps.adilger.int 2.4.22-l32 #4 Thu Jan 8 14:32:57 MST 2004 i686 i686
+         * running on Linux schnapps.adilger.int 2.4.22-l32 #4 Thu Jan 8 14:32:57 MST 2004 i686 i686 
          * with gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) */
 
 
@@ -756,8 +807,8 @@ void lustre_assert_wire_constants(void)
         LASSERT((int)sizeof(((struct obdo *)0)->o_size) == 8);
         LASSERT(offsetof(struct obdo, o_blocks) == 48);
         LASSERT((int)sizeof(((struct obdo *)0)->o_blocks) == 8);
-        LASSERT(offsetof(struct obdo, o_rdev) == 56);
-        LASSERT((int)sizeof(((struct obdo *)0)->o_rdev) == 8);
+        LASSERT(offsetof(struct obdo, o_grant) == 56);
+        LASSERT((int)sizeof(((struct obdo *)0)->o_grant) == 8);
         LASSERT(offsetof(struct obdo, o_blksize) == 64);
         LASSERT((int)sizeof(((struct obdo *)0)->o_blksize) == 4);
         LASSERT(offsetof(struct obdo, o_mode) == 68);
@@ -774,8 +825,8 @@ void lustre_assert_wire_constants(void)
         LASSERT((int)sizeof(((struct obdo *)0)->o_generation) == 4);
         LASSERT(offsetof(struct obdo, o_valid) == 92);
         LASSERT((int)sizeof(((struct obdo *)0)->o_valid) == 4);
-        LASSERT(offsetof(struct obdo, o_obdflags) == 96);
-        LASSERT((int)sizeof(((struct obdo *)0)->o_obdflags) == 4);
+        LASSERT(offsetof(struct obdo, o_misc) == 96);
+        LASSERT((int)sizeof(((struct obdo *)0)->o_misc) == 4);
         LASSERT(offsetof(struct obdo, o_easize) == 100);
         LASSERT((int)sizeof(((struct obdo *)0)->o_easize) == 4);
         LASSERT(offsetof(struct obdo, o_inline) == 104);
@@ -792,7 +843,6 @@ void lustre_assert_wire_constants(void)
         LASSERT(OBD_MD_FLUID == 512);
         LASSERT(OBD_MD_FLGID == 1024);
         LASSERT(OBD_MD_FLFLAGS == 2048);
-        LASSERT(OBD_MD_FLOBDFLG == 4096);
         LASSERT(OBD_MD_FLNLINK == 8192);
         LASSERT(OBD_MD_FLGENER == 16384);
         LASSERT(OBD_MD_FLINLINE == 32768);
@@ -810,6 +860,7 @@ void lustre_assert_wire_constants(void)
         LASSERT(OBD_FL_DELORPHAN == 4);
         LASSERT(OBD_FL_NORPC == 8);
         LASSERT(OBD_FL_IDONLY == 16);
+        LASSERT(OBD_FL_RECREATE_OBJS == 32);
 
         /* Checks for struct lov_mds_md_v1 */
         LASSERT((int)sizeof(struct lov_mds_md_v1) == 32);
@@ -885,7 +936,6 @@ void lustre_assert_wire_constants(void)
         LASSERT((int)sizeof(((struct niobuf_remote *)0)->flags) == 4);
         LASSERT(OBD_BRW_READ == 1);
         LASSERT(OBD_BRW_WRITE == 2);
-        LASSERT(OBD_BRW_CREATE == 4);
         LASSERT(OBD_BRW_SYNC == 8);
         LASSERT(OBD_BRW_FROM_GRANT == 32);
 
@@ -1139,13 +1189,11 @@ void lustre_assert_wire_constants(void)
         LASSERT((int)sizeof(((struct ldlm_intent *)0)->opc) == 8);
 
         /* Checks for struct ldlm_resource_desc */
-        LASSERT((int)sizeof(struct ldlm_resource_desc) == 52);
+        LASSERT((int)sizeof(struct ldlm_resource_desc) == 40);
         LASSERT(offsetof(struct ldlm_resource_desc, lr_type) == 0);
         LASSERT((int)sizeof(((struct ldlm_resource_desc *)0)->lr_type) == 4);
-        LASSERT(offsetof(struct ldlm_resource_desc, lr_name) == 4);
+        LASSERT(offsetof(struct ldlm_resource_desc, lr_name) == 8);
         LASSERT((int)sizeof(((struct ldlm_resource_desc *)0)->lr_name) == 32);
-        LASSERT(offsetof(struct ldlm_resource_desc, lr_version[4]) == 52);
-        LASSERT((int)sizeof(((struct ldlm_resource_desc *)0)->lr_version[4]) == 4);
 
         /* Checks for struct ldlm_lock_desc */
         LASSERT((int)sizeof(struct ldlm_lock_desc) == 108);