xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/nfs/tst.call.c (revision f3b585ce799a83688c5532c430f6133f098431c2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <strings.h>
30 #include <rpc/rpc.h>
31 
32 #include "rpcsvc/nfs4_prot.h"
33 
34 int nfs4_skip_bytes;
35 
36 /*
37  * The waiting() function returns the value passed in, until something
38  * external modifies it.  In this case, the D script tst.call.d will
39  * modify the value of *a, and thus break the while loop in dotest().
40  *
41  * This serves the purpose of not making the RPC calls until tst.call.d
42  * is active.  Thus, the probes in tst.call.d can fire as a result of
43  * the RPC call in dotest().
44  */
45 
46 int
47 waiting(volatile int *a)
48 {
49 	return (*a);
50 }
51 
52 int
53 dotest(void)
54 {
55 	CLIENT *client;
56 	AUTH *auth;
57 	COMPOUND4args args;
58 	COMPOUND4res res;
59 	enum clnt_stat status;
60 	struct timeval timeout;
61 	nfs_argop4 arg[1];
62 	char *tag = "dtrace test";
63 	volatile int a = 0;
64 
65 	while (waiting(&a) == 0)
66 		continue;
67 
68 	timeout.tv_sec = 30;
69 	timeout.tv_usec = 0;
70 
71 	client = clnt_create("localhost", NFS4_PROGRAM, NFS_V4, "tcp");
72 	if (client == NULL) {
73 		clnt_pcreateerror("test");
74 		return (1);
75 	}
76 	auth = authsys_create_default();
77 	client->cl_auth = auth;
78 	args.minorversion = 0;
79 	args.tag.utf8string_len = strlen(tag);
80 	args.tag.utf8string_val = tag;
81 	args.argarray.argarray_len = sizeof (arg) / sizeof (nfs_argop4);
82 	args.argarray.argarray_val = arg;
83 
84 	arg[0].argop = OP_PUTROOTFH;
85 	/* no need to manipulate nfs_argop4_u */
86 
87 	bzero(&res, sizeof (res));
88 
89 	status = clnt_call(client, NFSPROC4_COMPOUND,
90 	    xdr_COMPOUND4args, (caddr_t)&args,
91 	    xdr_COMPOUND4res, (caddr_t)&res,
92 	    timeout);
93 	if (status != RPC_SUCCESS) {
94 		clnt_perror(client, "test");
95 		return (2);
96 	}
97 
98 	return (0);
99 }
100 
101 /*ARGSUSED*/
102 int
103 main(int argc, char **argv)
104 {
105 	char shareline[BUFSIZ], unshareline[BUFSIZ];
106 	int rc;
107 
108 	(void) snprintf(shareline, sizeof (shareline),
109 	    "mkdir /tmp/nfsv4test.%d ; share /tmp/nfsv4test.%d", getpid(),
110 	    getpid());
111 	(void) snprintf(unshareline, sizeof (unshareline),
112 	    "unshare /tmp/nfsv4test.%d ; rmdir /tmp/nfsv4test.%d", getpid(),
113 	    getpid());
114 
115 	(void) system(shareline);
116 	rc = dotest();
117 	(void) system(unshareline);
118 
119 	return (rc);
120 }
121