This source file includes following definitions.
- copy_from_cb
- dlm_process_incoming_buffer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include "dlm_internal.h"
26 #include "lowcomms.h"
27 #include "config.h"
28 #include "lock.h"
29 #include "midcomms.h"
30
31
32 static void copy_from_cb(void *dst, const void *base, unsigned offset,
33 unsigned len, unsigned limit)
34 {
35 unsigned copy = len;
36
37 if ((copy + offset) > limit)
38 copy = limit - offset;
39 memcpy(dst, base + offset, copy);
40 len -= copy;
41 if (len)
42 memcpy(dst + copy, base, len);
43 }
44
45
46
47
48
49
50
51
52
53
54
55
56 int dlm_process_incoming_buffer(int nodeid, const void *base,
57 unsigned offset, unsigned len, unsigned limit)
58 {
59 union {
60 unsigned char __buf[DLM_INBUF_LEN];
61
62 union dlm_packet p;
63 } __tmp;
64 union dlm_packet *p = &__tmp.p;
65 int ret = 0;
66 int err = 0;
67 uint16_t msglen;
68 uint32_t lockspace;
69
70 while (len > sizeof(struct dlm_header)) {
71
72
73
74
75
76 copy_from_cb(p, base, offset, sizeof(struct dlm_header),
77 limit);
78
79 msglen = le16_to_cpu(p->header.h_length);
80 lockspace = p->header.h_lockspace;
81
82 err = -EINVAL;
83 if (msglen < sizeof(struct dlm_header))
84 break;
85 if (p->header.h_cmd == DLM_MSG) {
86 if (msglen < sizeof(struct dlm_message))
87 break;
88 } else {
89 if (msglen < sizeof(struct dlm_rcom))
90 break;
91 }
92 err = -E2BIG;
93 if (msglen > dlm_config.ci_buffer_size) {
94 log_print("message size %d from %d too big, buf len %d",
95 msglen, nodeid, len);
96 break;
97 }
98 err = 0;
99
100
101
102
103
104
105 if (msglen > len)
106 break;
107
108
109
110
111
112 if (msglen > sizeof(__tmp) && p == &__tmp.p) {
113 p = kmalloc(dlm_config.ci_buffer_size, GFP_NOFS);
114 if (p == NULL)
115 return ret;
116 }
117
118 copy_from_cb(p, base, offset, msglen, limit);
119
120 BUG_ON(lockspace != p->header.h_lockspace);
121
122 ret += msglen;
123 offset += msglen;
124 offset &= (limit - 1);
125 len -= msglen;
126
127 dlm_receive_buffer(p, nodeid);
128 }
129
130 if (p != &__tmp.p)
131 kfree(p);
132
133 return err ? err : ret;
134 }
135