midcomms.c (c1f3ee120bb61045b1c0a3ead620d1d65af47130) midcomms.c (eef7d739c218cb2546cf95686db77de0d76e4122)
1/******************************************************************************
2*******************************************************************************
3**
4** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5** Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
6**
7** This copyrighted material is made available to anyone wishing to use,
8** modify, copy, or redistribute it subject to the terms and conditions

--- 47 unchanged lines hidden (view full) ---

56 */
57
58int dlm_process_incoming_buffer(int nodeid, const void *base,
59 unsigned offset, unsigned len, unsigned limit)
60{
61 union {
62 unsigned char __buf[DLM_INBUF_LEN];
63 /* this is to force proper alignment on some arches */
1/******************************************************************************
2*******************************************************************************
3**
4** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5** Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
6**
7** This copyrighted material is made available to anyone wishing to use,
8** modify, copy, or redistribute it subject to the terms and conditions

--- 47 unchanged lines hidden (view full) ---

56 */
57
58int dlm_process_incoming_buffer(int nodeid, const void *base,
59 unsigned offset, unsigned len, unsigned limit)
60{
61 union {
62 unsigned char __buf[DLM_INBUF_LEN];
63 /* this is to force proper alignment on some arches */
64 struct dlm_header dlm;
64 union dlm_packet p;
65 } __tmp;
65 } __tmp;
66 struct dlm_header *msg = &__tmp.dlm;
66 union dlm_packet *p = &__tmp.p;
67 int ret = 0;
68 int err = 0;
69 uint16_t msglen;
70 uint32_t lockspace;
71
72 while (len > sizeof(struct dlm_header)) {
73
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. */
77
67 int ret = 0;
68 int err = 0;
69 uint16_t msglen;
70 uint32_t lockspace;
71
72 while (len > sizeof(struct dlm_header)) {
73
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. */
77
78 copy_from_cb(msg, base, offset, sizeof(struct dlm_header),
78 copy_from_cb(p, base, offset, sizeof(struct dlm_header),
79 limit);
80
79 limit);
80
81 msglen = le16_to_cpu(msg->h_length);
82 lockspace = msg->h_lockspace;
81 msglen = le16_to_cpu(p->header.h_length);
82 lockspace = p->header.h_lockspace;
83
84 err = -EINVAL;
85 if (msglen < sizeof(struct dlm_header))
86 break;
83
84 err = -EINVAL;
85 if (msglen < sizeof(struct dlm_header))
86 break;
87 if (p->header.h_cmd == DLM_MSG) {
88 if (msglen < sizeof(struct dlm_message))
89 break;
90 } else {
91 if (msglen < sizeof(struct dlm_rcom))
92 break;
93 }
87 err = -E2BIG;
88 if (msglen > dlm_config.ci_buffer_size) {
89 log_print("message size %d from %d too big, buf len %d",
90 msglen, nodeid, len);
91 break;
92 }
93 err = 0;
94

--- 4 unchanged lines hidden (view full) ---

99
100 if (msglen > len)
101 break;
102
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). */
106
94 err = -E2BIG;
95 if (msglen > dlm_config.ci_buffer_size) {
96 log_print("message size %d from %d too big, buf len %d",
97 msglen, nodeid, len);
98 break;
99 }
100 err = 0;
101

--- 4 unchanged lines hidden (view full) ---

106
107 if (msglen > len)
108 break;
109
110 /* Allocate a larger temp buffer if the full message won't fit
111 in the buffer on the stack (which should work for most
112 ordinary messages). */
113
107 if (msglen > DLM_INBUF_LEN && msg == &__tmp.dlm) {
108 msg = kmalloc(dlm_config.ci_buffer_size, GFP_KERNEL);
109 if (msg == NULL)
114 if (msglen > sizeof(__tmp) && p == &__tmp.p) {
115 p = kmalloc(dlm_config.ci_buffer_size, GFP_KERNEL);
116 if (p == NULL)
110 return ret;
111 }
112
117 return ret;
118 }
119
113 copy_from_cb(msg, base, offset, msglen, limit);
120 copy_from_cb(p, base, offset, msglen, limit);
114
121
115 BUG_ON(lockspace != msg->h_lockspace);
122 BUG_ON(lockspace != p->header.h_lockspace);
116
117 ret += msglen;
118 offset += msglen;
119 offset &= (limit - 1);
120 len -= msglen;
121
123
124 ret += msglen;
125 offset += msglen;
126 offset &= (limit - 1);
127 len -= msglen;
128
122 dlm_receive_buffer(msg, nodeid);
129 dlm_receive_buffer(p, nodeid);
123 }
124
130 }
131
125 if (msg != &__tmp.dlm)
126 kfree(msg);
132 if (p != &__tmp.p)
133 kfree(p);
127
128 return err ? err : ret;
129}
130
134
135 return err ? err : ret;
136}
137