1 /******************************************************************************
2 *******************************************************************************
4 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5 ** Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
7 ** This copyrighted material is made available to anyone wishing to use,
8 ** modify, copy, or redistribute it subject to the terms and conditions
9 ** of the GNU General Public License v.2.
11 *******************************************************************************
12 ******************************************************************************/
17 * This is the appallingly named "mid-level" comms layer.
19 * Its purpose is to take packets from the "real" comms layer,
20 * split them up into packets and pass them to the interested
21 * part of the locking mechanism.
23 * It also takes messages from the locking layer, formats them
24 * into packets and sends them to the comms layer.
27 #include "dlm_internal.h"
34 static void copy_from_cb(void *dst
, const void *base
, unsigned offset
,
35 unsigned len
, unsigned limit
)
39 if ((copy
+ offset
) > limit
)
40 copy
= limit
- offset
;
41 memcpy(dst
, base
+ offset
, copy
);
44 memcpy(dst
+ copy
, base
, len
);
48 * Called from the low-level comms layer to process a buffer of
51 * Only complete messages are processed here, any "spare" bytes from
52 * the end of a buffer are saved and tacked onto the front of the next
53 * message that comes in. I doubt this will happen very often but we
54 * need to be able to cope with it and I don't want the task to be waiting
55 * for packets to come in when there is useful work to be done.
58 int dlm_process_incoming_buffer(int nodeid
, const void *base
,
59 unsigned offset
, unsigned len
, unsigned limit
)
62 unsigned char __buf
[DLM_INBUF_LEN
];
63 /* this is to force proper alignment on some arches */
64 struct dlm_header dlm
;
66 struct dlm_header
*msg
= &__tmp
.dlm
;
72 while (len
> sizeof(struct dlm_header
)) {
74 /* Copy just the header to check the total length. The
75 message may wrap around the end of the buffer back to the
76 start, so we need to use a temp buffer and copy_from_cb. */
78 copy_from_cb(msg
, base
, offset
, sizeof(struct dlm_header
),
81 msglen
= le16_to_cpu(msg
->h_length
);
82 lockspace
= msg
->h_lockspace
;
85 if (msglen
< sizeof(struct dlm_header
))
88 if (msglen
> dlm_config
.ci_buffer_size
) {
89 log_print("message size %d from %d too big, buf len %d",
95 /* If only part of the full message is contained in this
96 buffer, then do nothing and wait for lowcomms to call
97 us again later with more data. We return 0 meaning
98 we've consumed none of the input buffer. */
103 /* Allocate a larger temp buffer if the full message won't fit
104 in the buffer on the stack (which should work for most
105 ordinary messages). */
107 if (msglen
> DLM_INBUF_LEN
&& msg
== &__tmp
.dlm
) {
108 msg
= kmalloc(dlm_config
.ci_buffer_size
, GFP_KERNEL
);
113 copy_from_cb(msg
, base
, offset
, msglen
, limit
);
115 BUG_ON(lockspace
!= msg
->h_lockspace
);
119 offset
&= (limit
- 1);
122 dlm_receive_buffer(msg
, nodeid
);
125 if (msg
!= &__tmp
.dlm
)
128 return err
? err
: ret
;
This page took 0.039678 seconds and 6 git commands to generate.