aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/nfs/tst.call3.c
blob: bd89fffca676d37b1f3654ca0297464d76864450 (plain) (blame)
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/*
 * 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.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <strings.h>
#include <rpc/rpc.h>
#include <stdlib.h>
#include <sys/param.h>
#include <rpcsvc/mount.h>

#include "rpcsvc/nfs_prot.h"

char sharedpath[MAXPATHLEN];
fhandle3 *rootfh;

/*
 * The waiting() function returns the value passed in, until something
 * external modifies it.  In this case, the D script tst.call.d will
 * modify the value of *a, and thus break the while loop in dotest().
 *
 * This serves the purpose of not making the RPC calls until tst.call.d
 * is active.  Thus, the probes in tst.call.d can fire as a result of
 * the RPC call in dotest().
 */

int
waiting(volatile int *a)
{
	return (*a);
}

static void
getattr_arginit(void *argp)
{
	GETATTR3args *args = argp;

	args->object.data.data_len = rootfh->fhandle3_len;
	args->object.data.data_val = rootfh->fhandle3_val;
}

static void
setattr_arginit(void *argp)
{
	SETATTR3args *args = argp;

	bzero(args, sizeof (*args));
	args->object.data.data_len = rootfh->fhandle3_len;
	args->object.data.data_val = rootfh->fhandle3_val;
}

static void
lookup_arginit(void *argp)
{
	LOOKUP3args *args = argp;

	args->what.name = "giant-skunk";
	args->what.dir.data.data_len = rootfh->fhandle3_len;
	args->what.dir.data.data_val = rootfh->fhandle3_val;
}

static void
access_arginit(void *argp)
{
	ACCESS3args *args = argp;

	args->object.data.data_len = rootfh->fhandle3_len;
	args->object.data.data_val = rootfh->fhandle3_val;
}

static void
commit_arginit(void *argp)
{
	COMMIT3args *args = argp;

	bzero(args, sizeof (*args));
	args->file.data.data_len = rootfh->fhandle3_len;
	args->file.data.data_val = rootfh->fhandle3_val;
}

static void
create_arginit(void *argp)
{
	CREATE3args *args = argp;

	bzero(args, sizeof (*args));
	args->where.name = "pinky-blue";
	args->where.dir.data.data_len = rootfh->fhandle3_len;
	args->where.dir.data.data_val = rootfh->fhandle3_val;
}

static void
fsinfo_arginit(void *argp)
{
	FSINFO3args *args = argp;

	args->fsroot.data.data_len = rootfh->fhandle3_len;
	args->fsroot.data.data_val = rootfh->fhandle3_val;
}

static void
fsstat_arginit(void *argp)
{
	FSSTAT3args *args = argp;

	args->fsroot.data.data_len = rootfh->fhandle3_len;
	args->fsroot.data.data_val = rootfh->fhandle3_val;
}

static void
link_arginit(void *argp)
{
	LINK3args *args = argp;

	args->file.data.data_len = rootfh->fhandle3_len;
	args->file.data.data_val = rootfh->fhandle3_val;
	args->link.dir.data.data_len = rootfh->fhandle3_len;
	args->link.dir.data.data_val = rootfh->fhandle3_val;
	args->link.name = "samf";
}

static void
mkdir_arginit(void *argp)
{
	MKDIR3args *args = argp;

	bzero(args, sizeof (*args));
	args->where.dir.data.data_len = rootfh->fhandle3_len;
	args->where.dir.data.data_val = rootfh->fhandle3_val;
	args->where.name = "cookie";
}

static void
mknod_arginit(void *argp)
{
	MKNOD3args *args = argp;

	bzero(args, sizeof (*args));
	args->where.dir.data.data_len = rootfh->fhandle3_len;
	args->where.dir.data.data_val = rootfh->fhandle3_val;
	args->where.name = "pookie";
}

static void
null_arginit(void *argp)
{
}

static void
pathconf_arginit(void *argp)
{
	PATHCONF3args *args = argp;

	args->object.data.data_len = rootfh->fhandle3_len;
	args->object.data.data_val = rootfh->fhandle3_val;
}

static void
read_arginit(void *argp)
{
	READ3args *args = argp;

	bzero(args, sizeof (*args));
	args->file.data.data_len = rootfh->fhandle3_len;
	args->file.data.data_val = rootfh->fhandle3_val;
}

static void
readdir_arginit(void *argp)
{
	READDIR3args *args = argp;

	bzero(args, sizeof (*args));
	args->dir.data.data_len = rootfh->fhandle3_len;
	args->dir.data.data_val = rootfh->fhandle3_val;
	args->count = 1024;
}

static void
readdirplus_arginit(void *argp)
{
	READDIRPLUS3args *args = argp;

	bzero(args, sizeof (*args));
	args->dir.data.data_len = rootfh->fhandle3_len;
	args->dir.data.data_val = rootfh->fhandle3_val;
	args->dircount = 1024;
	args->maxcount = 1024;
}

static void
readlink_arginit(void *argp)
{
	READLINK3args *args = argp;

	args->symlink.data.data_len = rootfh->fhandle3_len;
	args->symlink.data.data_val = rootfh->fhandle3_val;
}

static void
remove_arginit(void *argp)
{
	REMOVE3args *args = argp;

	args->object.dir.data.data_len = rootfh->fhandle3_len;
	args->object.dir.data.data_val = rootfh->fhandle3_val;
	args->object.name = "antelope";
}

static void
rename_arginit(void *argp)
{
	RENAME3args *args = argp;

	args->from.dir.data.data_len = rootfh->fhandle3_len;
	args->from.dir.data.data_val = rootfh->fhandle3_val;
	args->from.name = "walter";
	args->to.dir.data.data_len = rootfh->fhandle3_len;
	args->to.dir.data.data_val = rootfh->fhandle3_val;
	args->to.name = "wendy";
}

static void
rmdir_arginit(void *argp)
{
	RMDIR3args *args = argp;

	args->object.dir.data.data_len = rootfh->fhandle3_len;
	args->object.dir.data.data_val = rootfh->fhandle3_val;
	args->object.name = "bunny";
}

static void
symlink_arginit(void *argp)
{
	SYMLINK3args *args = argp;

	bzero(args, sizeof (*args));
	args->where.dir.data.data_len = rootfh->fhandle3_len;
	args->where.dir.data.data_val = rootfh->fhandle3_val;
	args->where.name = "parlor";
	args->symlink.symlink_data = "interior";
}

static void
write_arginit(void *argp)
{
	WRITE3args *args = argp;

	bzero(args, sizeof (*args));
	args->file.data.data_len = rootfh->fhandle3_len;
	args->file.data.data_val = rootfh->fhandle3_val;
}

typedef void (*call3_arginit_t)(void *);

typedef struct {
	call3_arginit_t arginit;
	rpcproc_t proc;
	xdrproc_t xdrargs;
	size_t argsize;
	xdrproc_t xdrres;
	size_t ressize;
} call3_test_t;
call3_test_t call3_tests[] = {
	{getattr_arginit, NFSPROC3_GETATTR, xdr_GETATTR3args,
	    sizeof (GETATTR3args), xdr_GETATTR3res, sizeof (GETATTR3res)},
	{setattr_arginit, NFSPROC3_SETATTR, xdr_SETATTR3args,
	    sizeof (SETATTR3args), xdr_SETATTR3res, sizeof (SETATTR3res)},
	{lookup_arginit, NFSPROC3_LOOKUP, xdr_LOOKUP3args,
	    sizeof (LOOKUP3args), xdr_LOOKUP3res, sizeof (LOOKUP3res)},
	{access_arginit, NFSPROC3_ACCESS, xdr_ACCESS3args,
	    sizeof (ACCESS3args), xdr_ACCESS3res, sizeof (ACCESS3res)},
	{commit_arginit, NFSPROC3_COMMIT, xdr_COMMIT3args,
	    sizeof (COMMIT3args), xdr_COMMIT3res, sizeof (COMMIT3res)},
	{create_arginit, NFSPROC3_CREATE, xdr_CREATE3args,
	    sizeof (CREATE3args), xdr_CREATE3res, sizeof (CREATE3res)},
	{fsinfo_arginit, NFSPROC3_FSINFO, xdr_FSINFO3args,
	    sizeof (FSINFO3args), xdr_FSINFO3res, sizeof (FSINFO3res)},
	{fsstat_arginit, NFSPROC3_FSSTAT, xdr_FSSTAT3args,
	    sizeof (FSSTAT3args), xdr_FSSTAT3res, sizeof (FSSTAT3res)},
	{link_arginit, NFSPROC3_LINK, xdr_LINK3args,
	    sizeof (LINK3args), xdr_LINK3res, sizeof (LINK3res)},
	{mkdir_arginit, NFSPROC3_MKDIR, xdr_MKDIR3args,
	    sizeof (MKDIR3args), xdr_MKDIR3res, sizeof (MKDIR3res)},
	{mknod_arginit, NFSPROC3_MKNOD, xdr_MKNOD3args,
	    sizeof (MKNOD3args), xdr_MKNOD3res, sizeof (MKNOD3res)},
	/*
	 * NULL proc is special.  Rather than special case its zero-sized
	 * args/results, we give it a small nonzero size, so as to not
	 * make realloc() do the wrong thing.
	 */
	{null_arginit, NFSPROC3_NULL, xdr_void, sizeof (int), xdr_void,
	    sizeof (int)},
	{pathconf_arginit, NFSPROC3_PATHCONF, xdr_PATHCONF3args,
	    sizeof (PATHCONF3args), xdr_PATHCONF3res, sizeof (PATHCONF3res)},
	{read_arginit, NFSPROC3_READ, xdr_READ3args,
	    sizeof (READ3args), xdr_READ3res, sizeof (READ3res)},
	{readdir_arginit, NFSPROC3_READDIR, xdr_READDIR3args,
	    sizeof (READDIR3args), xdr_READDIR3res, sizeof (READDIR3res)},
	{readdirplus_arginit, NFSPROC3_READDIRPLUS, xdr_READDIRPLUS3args,
	    sizeof (READDIRPLUS3args), xdr_READDIRPLUS3res,
	    sizeof (READDIRPLUS3res)},
	{readlink_arginit, NFSPROC3_READLINK, xdr_READLINK3args,
	    sizeof (READLINK3args), xdr_READLINK3res, sizeof (READLINK3res)},
	{remove_arginit, NFSPROC3_REMOVE, xdr_REMOVE3args,
	    sizeof (REMOVE3args), xdr_REMOVE3res, sizeof (REMOVE3res)},
	{rename_arginit, NFSPROC3_RENAME, xdr_RENAME3args,
	    sizeof (RENAME3args), xdr_RENAME3res, sizeof (RENAME3res)},
	{rmdir_arginit, NFSPROC3_RMDIR, xdr_RMDIR3args,
	    sizeof (RMDIR3args), xdr_RMDIR3res, sizeof (RMDIR3res)},
	{symlink_arginit, NFSPROC3_SYMLINK, xdr_SYMLINK3args,
	    sizeof (SYMLINK3args), xdr_SYMLINK3res, sizeof (SYMLINK3res)},
	{write_arginit, NFSPROC3_WRITE, xdr_WRITE3args,
	    sizeof (WRITE3args), xdr_WRITE3res, sizeof (WRITE3res)},
	{NULL}
};

int
dotest(void)
{
	CLIENT *client, *mountclient;
	AUTH *auth;
	struct timeval timeout;
	caddr_t args, res;
	enum clnt_stat status;
	rpcproc_t proc;
	call3_test_t *test;
	void *argbuf = NULL;
	void *resbuf = NULL;
	struct mountres3 mountres3;
	char *sp;
	volatile int a = 0;

	while (waiting(&a) == 0)
		continue;

	timeout.tv_sec = 30;
	timeout.tv_usec = 0;

	mountclient = clnt_create("localhost", MOUNTPROG, MOUNTVERS3, "tcp");
	if (mountclient == NULL) {
		clnt_pcreateerror("clnt_create mount");
		return (1);
	}
	auth = authsys_create_default();
	mountclient->cl_auth = auth;
	sp = sharedpath;
	bzero(&mountres3, sizeof (mountres3));
	status = clnt_call(mountclient, MOUNTPROC_MNT,
	    xdr_dirpath, (char *)&sp,
	    xdr_mountres3, (char *)&mountres3,
	    timeout);
	if (status != RPC_SUCCESS) {
		clnt_perror(mountclient, "mnt");
		return (1);
	}
	if (mountres3.fhs_status != 0) {
		fprintf(stderr, "MOUNTPROG/MOUNTVERS3 failed %d\n",
		    mountres3.fhs_status);
		return (1);
	}
	rootfh = &mountres3.mountres3_u.mountinfo.fhandle;

	client = clnt_create("localhost", NFS3_PROGRAM, NFS_V3, "tcp");
	if (client == NULL) {
		clnt_pcreateerror("clnt_create");
		return (1);
	}
	client->cl_auth = auth;

	for (test = call3_tests; test->arginit; ++test) {
		argbuf = realloc(argbuf, test->argsize);
		resbuf = realloc(resbuf, test->ressize);
		if ((argbuf == NULL) || (resbuf == NULL)) {
			perror("realloc() failed");
			return (1);
		}
		(test->arginit)(argbuf);
		bzero(resbuf, test->ressize);
		status = clnt_call(client, test->proc,
		    test->xdrargs, argbuf,
		    test->xdrres, resbuf,
		    timeout);
		if (status != RPC_SUCCESS)
			clnt_perror(client, "call");
	}

	status = clnt_call(mountclient, MOUNTPROC_UMNT,
	    xdr_dirpath, (char *)&sp,
	    xdr_void, NULL,
	    timeout);
	if (status != RPC_SUCCESS)
		clnt_perror(mountclient, "umnt");

	return (0);
}

/*ARGSUSED*/
int
main(int argc, char **argv)
{
	char shareline[BUFSIZ], unshareline[BUFSIZ];
	int rc;

	(void) snprintf(sharedpath, sizeof (sharedpath),
	    "/tmp/nfsv3test.%d", getpid());
	(void) snprintf(shareline, sizeof (shareline),
	    "mkdir %s ; share %s", sharedpath, sharedpath);
	(void) snprintf(unshareline, sizeof (unshareline),
	    "unshare %s ; rmdir %s", sharedpath, sharedpath);

	(void) system(shareline);
	rc = dotest();
	(void) system(unshareline);

	return (rc);
}