sunrpc: get rid of rpc_rqst.rq_bufsize
[safe/jmp/linux-2.6] / fs / dlm / midcomms.c
index c9b1c3d..07ac709 100644 (file)
@@ -2,7 +2,7 @@
 *******************************************************************************
 **
 **  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
-**  Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
+**  Copyright (C) 2004-2008 Red Hat, Inc.  All rights reserved.
 **
 **  This copyrighted material is made available to anyone wishing to use,
 **  modify, copy, or redistribute it subject to the terms and conditions
@@ -27,7 +27,6 @@
 #include "dlm_internal.h"
 #include "lowcomms.h"
 #include "config.h"
-#include "rcom.h"
 #include "lock.h"
 #include "midcomms.h"
 
@@ -59,8 +58,12 @@ static void copy_from_cb(void *dst, const void *base, unsigned offset,
 int dlm_process_incoming_buffer(int nodeid, const void *base,
                                unsigned offset, unsigned len, unsigned limit)
 {
-       unsigned char __tmp[DLM_INBUF_LEN];
-       struct dlm_header *msg = (struct dlm_header *) __tmp;
+       union {
+               unsigned char __buf[DLM_INBUF_LEN];
+               /* this is to force proper alignment on some arches */
+               union dlm_packet p;
+       } __tmp;
+       union dlm_packet *p = &__tmp.p;
        int ret = 0;
        int err = 0;
        uint16_t msglen;
@@ -72,17 +75,24 @@ int dlm_process_incoming_buffer(int nodeid, const void *base,
                   message may wrap around the end of the buffer back to the
                   start, so we need to use a temp buffer and copy_from_cb. */
 
-               copy_from_cb(msg, base, offset, sizeof(struct dlm_header),
+               copy_from_cb(p, base, offset, sizeof(struct dlm_header),
                             limit);
 
-               msglen = le16_to_cpu(msg->h_length);
-               lockspace = msg->h_lockspace;
+               msglen = le16_to_cpu(p->header.h_length);
+               lockspace = p->header.h_lockspace;
 
                err = -EINVAL;
                if (msglen < sizeof(struct dlm_header))
                        break;
+               if (p->header.h_cmd == DLM_MSG) {
+                       if (msglen < sizeof(struct dlm_message))
+                               break;
+               } else {
+                       if (msglen < sizeof(struct dlm_rcom))
+                               break;
+               }
                err = -E2BIG;
-               if (msglen > dlm_config.buffer_size) {
+               if (msglen > dlm_config.ci_buffer_size) {
                        log_print("message size %d from %d too big, buf len %d",
                                  msglen, nodeid, len);
                        break;
@@ -101,39 +111,26 @@ int dlm_process_incoming_buffer(int nodeid, const void *base,
                   in the buffer on the stack (which should work for most
                   ordinary messages). */
 
-               if (msglen > sizeof(__tmp) &&
-                   msg == (struct dlm_header *) __tmp) {
-                       msg = kmalloc(dlm_config.buffer_size, GFP_KERNEL);
-                       if (msg == NULL)
+               if (msglen > sizeof(__tmp) && p == &__tmp.p) {
+                       p = kmalloc(dlm_config.ci_buffer_size, GFP_KERNEL);
+                       if (p == NULL)
                                return ret;
                }
 
-               copy_from_cb(msg, base, offset, msglen, limit);
+               copy_from_cb(p, base, offset, msglen, limit);
 
-               BUG_ON(lockspace != msg->h_lockspace);
+               BUG_ON(lockspace != p->header.h_lockspace);
 
                ret += msglen;
                offset += msglen;
                offset &= (limit - 1);
                len -= msglen;
 
-               switch (msg->h_cmd) {
-               case DLM_MSG:
-                       dlm_receive_message(msg, nodeid, 0);
-                       break;
-
-               case DLM_RCOM:
-                       dlm_receive_rcom(msg, nodeid);
-                       break;
-
-               default:
-                       log_print("unknown msg type %x from %u: %u %u %u %u",
-                                 msg->h_cmd, nodeid, msglen, len, offset, ret);
-               }
+               dlm_receive_buffer(p, nodeid);
        }
 
-       if (msg != (struct dlm_header *) __tmp)
-               kfree(msg);
+       if (p != &__tmp.p)
+               kfree(p);
 
        return err ? err : ret;
 }