xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/nfs/tst.call.c (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
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 #include <strings.h>
28 #include <rpc/rpc.h>
29 
30 #include "rpcsvc/nfs4_prot.h"
31 
32 int nfs4_skip_bytes;
33 
34 /*
35  * The waiting() function returns the value passed in, until something
36  * external modifies it.  In this case, the D script tst.call.d will
37  * modify the value of *a, and thus break the while loop in dotest().
38  *
39  * This serves the purpose of not making the RPC calls until tst.call.d
40  * is active.  Thus, the probes in tst.call.d can fire as a result of
41  * the RPC call in dotest().
42  */
43 
44 int
45 waiting(volatile int *a)
46 {
47 	return (*a);
48 }
49 
50 int
51 dotest(void)
52 {
53 	CLIENT *client;
54 	AUTH *auth;
55 	COMPOUND4args args;
56 	COMPOUND4res res;
57 	enum clnt_stat status;
58 	struct timeval timeout;
59 	nfs_argop4 arg[1];
60 	char *tag = "dtrace test";
61 	volatile int a = 0;
62 
63 	while (waiting(&a) == 0)
64 		continue;
65 
66 	timeout.tv_sec = 30;
67 	timeout.tv_usec = 0;
68 
69 	client = clnt_create("localhost", NFS4_PROGRAM, NFS_V4, "tcp");
70 	if (client == NULL) {
71 		clnt_pcreateerror("test");
72 		return (1);
73 	}
74 	auth = authsys_create_default();
75 	client->cl_auth = auth;
76 	args.minorversion = 0;
77 	args.tag.utf8string_len = strlen(tag);
78 	args.tag.utf8string_val = tag;
79 	args.argarray.argarray_len = sizeof (arg) / sizeof (nfs_argop4);
80 	args.argarray.argarray_val = arg;
81 
82 	arg[0].argop = OP_PUTROOTFH;
83 	/* no need to manipulate nfs_argop4_u */
84 
85 	bzero(&res, sizeof (res));
86 
87 	status = clnt_call(client, NFSPROC4_COMPOUND,
88 	    xdr_COMPOUND4args, (caddr_t)&args,
89 	    xdr_COMPOUND4res, (caddr_t)&res,
90 	    timeout);
91 	if (status != RPC_SUCCESS) {
92 		clnt_perror(client, "test");
93 		return (2);
94 	}
95 
96 	return (0);
97 }
98 
99 /*ARGSUSED*/
100 int
101 main(int argc, char **argv)
102 {
103 	char shareline[BUFSIZ], unshareline[BUFSIZ];
104 	int rc;
105 
106 	(void) snprintf(shareline, sizeof (shareline),
107 	    "mkdir /tmp/nfsv4test.%d ; share /tmp/nfsv4test.%d", getpid(),
108 	    getpid());
109 	(void) snprintf(unshareline, sizeof (unshareline),
110 	    "unshare /tmp/nfsv4test.%d ; rmdir /tmp/nfsv4test.%d", getpid(),
111 	    getpid());
112 
113 	(void) system(shareline);
114 	rc = dotest();
115 	(void) system(unshareline);
116 
117 	return (rc);
118 }
119