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