f3b585ce799a83688c5532c430f6133f098431c2samf/*
f3b585ce799a83688c5532c430f6133f098431c2samf * CDDL HEADER START
f3b585ce799a83688c5532c430f6133f098431c2samf *
f3b585ce799a83688c5532c430f6133f098431c2samf * The contents of this file are subject to the terms of the
f3b585ce799a83688c5532c430f6133f098431c2samf * Common Development and Distribution License (the "License").
f3b585ce799a83688c5532c430f6133f098431c2samf * You may not use this file except in compliance with the License.
f3b585ce799a83688c5532c430f6133f098431c2samf *
f3b585ce799a83688c5532c430f6133f098431c2samf * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f3b585ce799a83688c5532c430f6133f098431c2samf * or http://www.opensolaris.org/os/licensing.
f3b585ce799a83688c5532c430f6133f098431c2samf * See the License for the specific language governing permissions
f3b585ce799a83688c5532c430f6133f098431c2samf * and limitations under the License.
f3b585ce799a83688c5532c430f6133f098431c2samf *
f3b585ce799a83688c5532c430f6133f098431c2samf * When distributing Covered Code, include this CDDL HEADER in each
f3b585ce799a83688c5532c430f6133f098431c2samf * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f3b585ce799a83688c5532c430f6133f098431c2samf * If applicable, add the following below this CDDL HEADER, with the
f3b585ce799a83688c5532c430f6133f098431c2samf * fields enclosed by brackets "[]" replaced with your own identifying
f3b585ce799a83688c5532c430f6133f098431c2samf * information: Portions Copyright [yyyy] [name of copyright owner]
f3b585ce799a83688c5532c430f6133f098431c2samf *
f3b585ce799a83688c5532c430f6133f098431c2samf * CDDL HEADER END
f3b585ce799a83688c5532c430f6133f098431c2samf */
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf/*
f3b585ce799a83688c5532c430f6133f098431c2samf * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
f3b585ce799a83688c5532c430f6133f098431c2samf * Use is subject to license terms.
f3b585ce799a83688c5532c430f6133f098431c2samf */
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf#pragma ident "%Z%%M% %I% %E% SMI"
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf#include <strings.h>
f3b585ce799a83688c5532c430f6133f098431c2samf#include <rpc/rpc.h>
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf#include "rpcsvc/nfs4_prot.h"
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samfint nfs4_skip_bytes;
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf/*
f3b585ce799a83688c5532c430f6133f098431c2samf * The waiting() function returns the value passed in, until something
f3b585ce799a83688c5532c430f6133f098431c2samf * external modifies it. In this case, the D script tst.call.d will
f3b585ce799a83688c5532c430f6133f098431c2samf * modify the value of *a, and thus break the while loop in dotest().
f3b585ce799a83688c5532c430f6133f098431c2samf *
f3b585ce799a83688c5532c430f6133f098431c2samf * This serves the purpose of not making the RPC calls until tst.call.d
f3b585ce799a83688c5532c430f6133f098431c2samf * is active. Thus, the probes in tst.call.d can fire as a result of
f3b585ce799a83688c5532c430f6133f098431c2samf * the RPC call in dotest().
f3b585ce799a83688c5532c430f6133f098431c2samf */
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samfint
f3b585ce799a83688c5532c430f6133f098431c2samfwaiting(volatile int *a)
f3b585ce799a83688c5532c430f6133f098431c2samf{
f3b585ce799a83688c5532c430f6133f098431c2samf return (*a);
f3b585ce799a83688c5532c430f6133f098431c2samf}
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samfint
f3b585ce799a83688c5532c430f6133f098431c2samfdotest(void)
f3b585ce799a83688c5532c430f6133f098431c2samf{
f3b585ce799a83688c5532c430f6133f098431c2samf CLIENT *client;
f3b585ce799a83688c5532c430f6133f098431c2samf AUTH *auth;
f3b585ce799a83688c5532c430f6133f098431c2samf COMPOUND4args args;
f3b585ce799a83688c5532c430f6133f098431c2samf COMPOUND4res res;
f3b585ce799a83688c5532c430f6133f098431c2samf enum clnt_stat status;
f3b585ce799a83688c5532c430f6133f098431c2samf struct timeval timeout;
f3b585ce799a83688c5532c430f6133f098431c2samf nfs_argop4 arg[1];
f3b585ce799a83688c5532c430f6133f098431c2samf char *tag = "dtrace test";
f3b585ce799a83688c5532c430f6133f098431c2samf volatile int a = 0;
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf while (waiting(&a) == 0)
f3b585ce799a83688c5532c430f6133f098431c2samf continue;
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf timeout.tv_sec = 30;
f3b585ce799a83688c5532c430f6133f098431c2samf timeout.tv_usec = 0;
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf client = clnt_create("localhost", NFS4_PROGRAM, NFS_V4, "tcp");
f3b585ce799a83688c5532c430f6133f098431c2samf if (client == NULL) {
f3b585ce799a83688c5532c430f6133f098431c2samf clnt_pcreateerror("test");
f3b585ce799a83688c5532c430f6133f098431c2samf return (1);
f3b585ce799a83688c5532c430f6133f098431c2samf }
f3b585ce799a83688c5532c430f6133f098431c2samf auth = authsys_create_default();
f3b585ce799a83688c5532c430f6133f098431c2samf client->cl_auth = auth;
f3b585ce799a83688c5532c430f6133f098431c2samf args.minorversion = 0;
f3b585ce799a83688c5532c430f6133f098431c2samf args.tag.utf8string_len = strlen(tag);
f3b585ce799a83688c5532c430f6133f098431c2samf args.tag.utf8string_val = tag;
f3b585ce799a83688c5532c430f6133f098431c2samf args.argarray.argarray_len = sizeof (arg) / sizeof (nfs_argop4);
f3b585ce799a83688c5532c430f6133f098431c2samf args.argarray.argarray_val = arg;
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf arg[0].argop = OP_PUTROOTFH;
f3b585ce799a83688c5532c430f6133f098431c2samf /* no need to manipulate nfs_argop4_u */
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf bzero(&res, sizeof (res));
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf status = clnt_call(client, NFSPROC4_COMPOUND,
f3b585ce799a83688c5532c430f6133f098431c2samf xdr_COMPOUND4args, (caddr_t)&args,
f3b585ce799a83688c5532c430f6133f098431c2samf xdr_COMPOUND4res, (caddr_t)&res,
f3b585ce799a83688c5532c430f6133f098431c2samf timeout);
f3b585ce799a83688c5532c430f6133f098431c2samf if (status != RPC_SUCCESS) {
f3b585ce799a83688c5532c430f6133f098431c2samf clnt_perror(client, "test");
f3b585ce799a83688c5532c430f6133f098431c2samf return (2);
f3b585ce799a83688c5532c430f6133f098431c2samf }
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf return (0);
f3b585ce799a83688c5532c430f6133f098431c2samf}
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf/*ARGSUSED*/
f3b585ce799a83688c5532c430f6133f098431c2samfint
f3b585ce799a83688c5532c430f6133f098431c2samfmain(int argc, char **argv)
f3b585ce799a83688c5532c430f6133f098431c2samf{
f3b585ce799a83688c5532c430f6133f098431c2samf char shareline[BUFSIZ], unshareline[BUFSIZ];
f3b585ce799a83688c5532c430f6133f098431c2samf int rc;
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf (void) snprintf(shareline, sizeof (shareline),
f3b585ce799a83688c5532c430f6133f098431c2samf "mkdir /tmp/nfsv4test.%d ; share /tmp/nfsv4test.%d", getpid(),
f3b585ce799a83688c5532c430f6133f098431c2samf getpid());
f3b585ce799a83688c5532c430f6133f098431c2samf (void) snprintf(unshareline, sizeof (unshareline),
f3b585ce799a83688c5532c430f6133f098431c2samf "unshare /tmp/nfsv4test.%d ; rmdir /tmp/nfsv4test.%d", getpid(),
f3b585ce799a83688c5532c430f6133f098431c2samf getpid());
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf (void) system(shareline);
f3b585ce799a83688c5532c430f6133f098431c2samf rc = dotest();
f3b585ce799a83688c5532c430f6133f098431c2samf (void) system(unshareline);
f3b585ce799a83688c5532c430f6133f098431c2samf
f3b585ce799a83688c5532c430f6133f098431c2samf return (rc);
f3b585ce799a83688c5532c430f6133f098431c2samf}