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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright 2017 RackTop Systems.
*/
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <sys/types.h>
#include <sys/sdt.h>
#include <rpc/auth.h>
#include <rpc/rpc_rdma.h>
struct private {
int min_chunk;
uint_t flags; /* controls setting for rdma xdr */
int num_chunk;
caddr_t inline_buf; /* temporary buffer for xdr inlining */
int inline_len; /* inline buffer length */
uint_t xp_reply_chunk_len;
uint_t xp_reply_chunk_len_alt;
};
/* ARGSUSED */
static bool_t
x_putint32_t(XDR *xdrs, int32_t *ip)
{
xdrs->x_handy += BYTES_PER_XDR_UNIT;
return (TRUE);
}
/* ARGSUSED */
static bool_t
x_putbytes(XDR *xdrs, char *bp, int len)
{
struct private *xdrp = (struct private *)xdrs->x_private;
/*
* min_chunk = 0, means that the stream of bytes, to estimate size of,
* contains no chunks to seperate out. See xdrrdma_putbytes()
*/
if (len < xdrp->min_chunk || !(xdrp->flags & XDR_RDMA_CHUNK)) {
xdrs->x_handy += len;
return (TRUE);
}
/*
* Chunk item. No impact on xdr size.
*/
xdrp->num_chunk++;
return (TRUE);
}
static uint_t
x_getpostn(XDR *xdrs)
{
return (xdrs->x_handy);
}
/* ARGSUSED */
static bool_t
x_setpostn(XDR *xdrs, uint_t pos)
{
/* This is not allowed */
return (FALSE);
}
/* ARGSUSED */
static bool_t
x_control(XDR *xdrs, int request, void *info)
{
int32_t *int32p;
uint_t in_flags;
rdma_chunkinfo_t *rcip = NULL;
rdma_chunkinfo_lengths_t *rcilp = NULL;
struct private *xdrp = (struct private *)xdrs->x_private;
switch (request) {
case XDR_RDMA_SET_FLAGS:
/*
* Set the flags provided in the *info in xp_flags for rdma xdr
* stream control.
*/
int32p = (int32_t *)info;
in_flags = (uint_t)(*int32p);
xdrp->flags = in_flags;
return (TRUE);
case XDR_RDMA_GET_FLAGS:
/*
* Get the flags provided in xp_flags return through *info
*/
int32p = (int32_t *)info;
*int32p = (int32_t)xdrp->flags;
return (TRUE);
case XDR_RDMA_GET_CHUNK_LEN:
rcilp = (rdma_chunkinfo_lengths_t *)info;
rcilp->rcil_len = xdrp->xp_reply_chunk_len;
rcilp->rcil_len_alt = xdrp->xp_reply_chunk_len_alt;
return (TRUE);
case XDR_RDMA_ADD_CHUNK:
rcip = (rdma_chunkinfo_t *)info;
switch (rcip->rci_type) {
case RCI_WRITE_UIO_CHUNK:
xdrp->xp_reply_chunk_len_alt += rcip->rci_len;
break;
case RCI_WRITE_ADDR_CHUNK:
xdrp->xp_reply_chunk_len_alt += rcip->rci_len;
break;
case RCI_REPLY_CHUNK:
xdrp->xp_reply_chunk_len += rcip->rci_len;
break;
}
return (TRUE);
default:
return (FALSE);
}
}
/* ARGSUSED */
static rpc_inline_t *
x_inline(XDR *xdrs, int len)
{
struct private *xdrp = (struct private *)xdrs->x_private;
if (len == 0) {
return (NULL);
}
if (xdrs->x_op != XDR_ENCODE) {
return (NULL);
}
if (len >= xdrp->min_chunk) {
return (NULL);
}
if (len <= xdrp->inline_len) {
/* inline_buf was already allocated, just reuse it */
xdrs->x_handy += len;
return ((rpc_inline_t *)xdrp->inline_buf);
} else {
/* Free the earlier space and allocate new area */
if (xdrp->inline_buf)
mem_free(xdrp->inline_buf, xdrp->inline_len);
if ((xdrp->inline_buf = (caddr_t)mem_alloc(len)) == NULL) {
xdrp->inline_len = 0;
return (NULL);
}
xdrp->inline_len = len;
xdrs->x_handy += len;
return ((rpc_inline_t *)xdrp->inline_buf);
}
}
static int
harmless()
{
/* Always return FALSE/NULL, as the case may be */
return (0);
}
static void
x_destroy(XDR *xdrs)
{
struct private *xdrp = (struct private *)xdrs->x_private;
xdrs->x_handy = 0;
if (xdrp) {
if (xdrp->inline_buf)
mem_free(xdrp->inline_buf, xdrp->inline_len);
mem_free(xdrp, sizeof (struct private));
xdrs->x_private = NULL;
}
xdrs->x_base = 0;
}
static bool_t
xdrrdma_common(XDR *xdrs, int min_chunk)
{
struct private *xdrp;
xdrs->x_ops = xdrrdma_xops();
xdrs->x_op = XDR_ENCODE;
xdrs->x_handy = 0;
xdrs->x_base = NULL;
xdrs->x_private = kmem_zalloc(sizeof (struct private), KM_SLEEP);
xdrp = (struct private *)xdrs->x_private;
xdrp->min_chunk = min_chunk;
xdrp->flags = 0;
if (xdrp->min_chunk != 0)
xdrp->flags |= XDR_RDMA_CHUNK;
xdrp->xp_reply_chunk_len = 0;
xdrp->xp_reply_chunk_len_alt = 0;
return (TRUE);
}
unsigned int
xdrrdma_sizeof(xdrproc_t func, void *data, int min_chunk,
uint_t *reply_size, uint_t *reply_size_alt)
{
XDR x;
struct xdr_ops ops;
bool_t stat;
struct private *xdrp;
x.x_ops = &ops;
(void) xdrrdma_common(&x, min_chunk);
stat = func(&x, data);
xdrp = (struct private *)x.x_private;
if (xdrp) {
if (reply_size != NULL)
*reply_size = xdrp->xp_reply_chunk_len;
if (reply_size_alt != NULL)
*reply_size_alt = xdrp->xp_reply_chunk_len_alt;
if (xdrp->inline_buf)
mem_free(xdrp->inline_buf, xdrp->inline_len);
mem_free(xdrp, sizeof (struct private));
}
return (stat == TRUE ? (unsigned int)x.x_handy: 0);
}
unsigned int
xdrrdma_authsize(AUTH *auth, struct cred *cred, int min_chunk)
{
XDR x;
struct xdr_ops ops;
bool_t stat;
struct private *xdrp;
x.x_ops = &ops;
(void) xdrrdma_common(&x, min_chunk);
stat = AUTH_MARSHALL(auth, &x, cred);
xdrp = (struct private *)x.x_private;
if (xdrp) {
if (xdrp->inline_buf)
mem_free(xdrp->inline_buf, xdrp->inline_len);
mem_free(xdrp, sizeof (struct private));
}
return (stat == TRUE ? (unsigned int)x.x_handy: 0);
}
struct xdr_ops *
xdrrdma_xops(void)
{
static struct xdr_ops ops;
/* to stop ANSI-C compiler from complaining */
typedef bool_t (* dummyfunc1)(XDR *, caddr_t, int);
#if defined(_LP64) || defined(_KERNEL)
typedef bool_t (* dummyfunc2)(XDR *, int32_t *);
#endif
ops.x_putbytes = x_putbytes;
ops.x_inline = x_inline;
ops.x_getpostn = x_getpostn;
ops.x_setpostn = x_setpostn;
ops.x_destroy = x_destroy;
ops.x_control = x_control;
#if defined(_LP64) || defined(_KERNEL)
ops.x_getint32 = (dummyfunc2)harmless;
ops.x_putint32 = x_putint32_t;
#endif
/* the other harmless ones */
ops.x_getbytes = (dummyfunc1)harmless;
return (&ops);
}
|