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