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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <sys/param.h>
34 #include <rpcsvc/mount.h>
36 #include "rpcsvc/nfs_prot.h"
38 char sharedpath[MAXPATHLEN];
42 * The waiting() function returns the value passed in, until something
43 * external modifies it. In this case, the D script tst.call.d will
44 * modify the value of *a, and thus break the while loop in dotest().
46 * This serves the purpose of not making the RPC calls until tst.call.d
47 * is active. Thus, the probes in tst.call.d can fire as a result of
48 * the RPC call in dotest().
52 waiting(volatile int *a)
58 getattr_arginit(void *argp)
60 GETATTR3args *args = argp;
62 args->object.data.data_len = rootfh->fhandle3_len;
63 args->object.data.data_val = rootfh->fhandle3_val;
67 setattr_arginit(void *argp)
69 SETATTR3args *args = argp;
71 bzero(args, sizeof (*args));
72 args->object.data.data_len = rootfh->fhandle3_len;
73 args->object.data.data_val = rootfh->fhandle3_val;
77 lookup_arginit(void *argp)
79 LOOKUP3args *args = argp;
81 args->what.name = "giant-skunk";
82 args->what.dir.data.data_len = rootfh->fhandle3_len;
83 args->what.dir.data.data_val = rootfh->fhandle3_val;
87 access_arginit(void *argp)
89 ACCESS3args *args = argp;
91 args->object.data.data_len = rootfh->fhandle3_len;
92 args->object.data.data_val = rootfh->fhandle3_val;
96 commit_arginit(void *argp)
98 COMMIT3args *args = argp;
100 bzero(args, sizeof (*args));
101 args->file.data.data_len = rootfh->fhandle3_len;
102 args->file.data.data_val = rootfh->fhandle3_val;
106 create_arginit(void *argp)
108 CREATE3args *args = argp;
110 bzero(args, sizeof (*args));
111 args->where.name = "pinky-blue";
112 args->where.dir.data.data_len = rootfh->fhandle3_len;
113 args->where.dir.data.data_val = rootfh->fhandle3_val;
117 fsinfo_arginit(void *argp)
119 FSINFO3args *args = argp;
121 args->fsroot.data.data_len = rootfh->fhandle3_len;
122 args->fsroot.data.data_val = rootfh->fhandle3_val;
126 fsstat_arginit(void *argp)
128 FSSTAT3args *args = argp;
130 args->fsroot.data.data_len = rootfh->fhandle3_len;
131 args->fsroot.data.data_val = rootfh->fhandle3_val;
135 link_arginit(void *argp)
137 LINK3args *args = argp;
139 args->file.data.data_len = rootfh->fhandle3_len;
140 args->file.data.data_val = rootfh->fhandle3_val;
141 args->link.dir.data.data_len = rootfh->fhandle3_len;
142 args->link.dir.data.data_val = rootfh->fhandle3_val;
143 args->link.name = "samf";
147 mkdir_arginit(void *argp)
149 MKDIR3args *args = argp;
151 bzero(args, sizeof (*args));
152 args->where.dir.data.data_len = rootfh->fhandle3_len;
153 args->where.dir.data.data_val = rootfh->fhandle3_val;
154 args->where.name = "cookie";
158 mknod_arginit(void *argp)
160 MKNOD3args *args = argp;
162 bzero(args, sizeof (*args));
163 args->where.dir.data.data_len = rootfh->fhandle3_len;
164 args->where.dir.data.data_val = rootfh->fhandle3_val;
165 args->where.name = "pookie";
169 null_arginit(void *argp)
174 pathconf_arginit(void *argp)
176 PATHCONF3args *args = argp;
178 args->object.data.data_len = rootfh->fhandle3_len;
179 args->object.data.data_val = rootfh->fhandle3_val;
183 read_arginit(void *argp)
185 READ3args *args = argp;
187 bzero(args, sizeof (*args));
188 args->file.data.data_len = rootfh->fhandle3_len;
189 args->file.data.data_val = rootfh->fhandle3_val;
193 readdir_arginit(void *argp)
195 READDIR3args *args = argp;
197 bzero(args, sizeof (*args));
198 args->dir.data.data_len = rootfh->fhandle3_len;
199 args->dir.data.data_val = rootfh->fhandle3_val;
204 readdirplus_arginit(void *argp)
206 READDIRPLUS3args *args = argp;
208 bzero(args, sizeof (*args));
209 args->dir.data.data_len = rootfh->fhandle3_len;
210 args->dir.data.data_val = rootfh->fhandle3_val;
211 args->dircount = 1024;
212 args->maxcount = 1024;
216 readlink_arginit(void *argp)
218 READLINK3args *args = argp;
220 args->symlink.data.data_len = rootfh->fhandle3_len;
221 args->symlink.data.data_val = rootfh->fhandle3_val;
225 remove_arginit(void *argp)
227 REMOVE3args *args = argp;
229 args->object.dir.data.data_len = rootfh->fhandle3_len;
230 args->object.dir.data.data_val = rootfh->fhandle3_val;
231 args->object.name = "antelope";
235 rename_arginit(void *argp)
237 RENAME3args *args = argp;
239 args->from.dir.data.data_len = rootfh->fhandle3_len;
240 args->from.dir.data.data_val = rootfh->fhandle3_val;
241 args->from.name = "walter";
242 args->to.dir.data.data_len = rootfh->fhandle3_len;
243 args->to.dir.data.data_val = rootfh->fhandle3_val;
244 args->to.name = "wendy";
248 rmdir_arginit(void *argp)
250 RMDIR3args *args = argp;
252 args->object.dir.data.data_len = rootfh->fhandle3_len;
253 args->object.dir.data.data_val = rootfh->fhandle3_val;
254 args->object.name = "bunny";
258 symlink_arginit(void *argp)
260 SYMLINK3args *args = argp;
262 bzero(args, sizeof (*args));
263 args->where.dir.data.data_len = rootfh->fhandle3_len;
264 args->where.dir.data.data_val = rootfh->fhandle3_val;
265 args->where.name = "parlor";
266 args->symlink.symlink_data = "interior";
270 write_arginit(void *argp)
272 WRITE3args *args = argp;
274 bzero(args, sizeof (*args));
275 args->file.data.data_len = rootfh->fhandle3_len;
276 args->file.data.data_val = rootfh->fhandle3_val;
279 typedef void (*call3_arginit_t)(void *);
282 call3_arginit_t arginit;
289 call3_test_t call3_tests[] = {
290 {getattr_arginit, NFSPROC3_GETATTR, xdr_GETATTR3args,
291 sizeof (GETATTR3args), xdr_GETATTR3res, sizeof (GETATTR3res)},
292 {setattr_arginit, NFSPROC3_SETATTR, xdr_SETATTR3args,
293 sizeof (SETATTR3args), xdr_SETATTR3res, sizeof (SETATTR3res)},
294 {lookup_arginit, NFSPROC3_LOOKUP, xdr_LOOKUP3args,
295 sizeof (LOOKUP3args), xdr_LOOKUP3res, sizeof (LOOKUP3res)},
296 {access_arginit, NFSPROC3_ACCESS, xdr_ACCESS3args,
297 sizeof (ACCESS3args), xdr_ACCESS3res, sizeof (ACCESS3res)},
298 {commit_arginit, NFSPROC3_COMMIT, xdr_COMMIT3args,
299 sizeof (COMMIT3args), xdr_COMMIT3res, sizeof (COMMIT3res)},
300 {create_arginit, NFSPROC3_CREATE, xdr_CREATE3args,
301 sizeof (CREATE3args), xdr_CREATE3res, sizeof (CREATE3res)},
302 {fsinfo_arginit, NFSPROC3_FSINFO, xdr_FSINFO3args,
303 sizeof (FSINFO3args), xdr_FSINFO3res, sizeof (FSINFO3res)},
304 {fsstat_arginit, NFSPROC3_FSSTAT, xdr_FSSTAT3args,
305 sizeof (FSSTAT3args), xdr_FSSTAT3res, sizeof (FSSTAT3res)},
306 {link_arginit, NFSPROC3_LINK, xdr_LINK3args,
307 sizeof (LINK3args), xdr_LINK3res, sizeof (LINK3res)},
308 {mkdir_arginit, NFSPROC3_MKDIR, xdr_MKDIR3args,
309 sizeof (MKDIR3args), xdr_MKDIR3res, sizeof (MKDIR3res)},
310 {mknod_arginit, NFSPROC3_MKNOD, xdr_MKNOD3args,
311 sizeof (MKNOD3args), xdr_MKNOD3res, sizeof (MKNOD3res)},
313 * NULL proc is special. Rather than special case its zero-sized
314 * args/results, we give it a small nonzero size, so as to not
315 * make realloc() do the wrong thing.
317 {null_arginit, NFSPROC3_NULL, xdr_void, sizeof (int), xdr_void,
319 {pathconf_arginit, NFSPROC3_PATHCONF, xdr_PATHCONF3args,
320 sizeof (PATHCONF3args), xdr_PATHCONF3res, sizeof (PATHCONF3res)},
321 {read_arginit, NFSPROC3_READ, xdr_READ3args,
322 sizeof (READ3args), xdr_READ3res, sizeof (READ3res)},
323 {readdir_arginit, NFSPROC3_READDIR, xdr_READDIR3args,
324 sizeof (READDIR3args), xdr_READDIR3res, sizeof (READDIR3res)},
325 {readdirplus_arginit, NFSPROC3_READDIRPLUS, xdr_READDIRPLUS3args,
326 sizeof (READDIRPLUS3args), xdr_READDIRPLUS3res,
327 sizeof (READDIRPLUS3res)},
328 {readlink_arginit, NFSPROC3_READLINK, xdr_READLINK3args,
329 sizeof (READLINK3args), xdr_READLINK3res, sizeof (READLINK3res)},
330 {remove_arginit, NFSPROC3_REMOVE, xdr_REMOVE3args,
331 sizeof (REMOVE3args), xdr_REMOVE3res, sizeof (REMOVE3res)},
332 {rename_arginit, NFSPROC3_RENAME, xdr_RENAME3args,
333 sizeof (RENAME3args), xdr_RENAME3res, sizeof (RENAME3res)},
334 {rmdir_arginit, NFSPROC3_RMDIR, xdr_RMDIR3args,
335 sizeof (RMDIR3args), xdr_RMDIR3res, sizeof (RMDIR3res)},
336 {symlink_arginit, NFSPROC3_SYMLINK, xdr_SYMLINK3args,
337 sizeof (SYMLINK3args), xdr_SYMLINK3res, sizeof (SYMLINK3res)},
338 {write_arginit, NFSPROC3_WRITE, xdr_WRITE3args,
339 sizeof (WRITE3args), xdr_WRITE3res, sizeof (WRITE3res)},
346 CLIENT *client, *mountclient;
348 struct timeval timeout;
350 enum clnt_stat status;
355 struct mountres3 mountres3;
359 while (waiting(&a) == 0)
365 mountclient = clnt_create("localhost", MOUNTPROG, MOUNTVERS3, "tcp");
366 if (mountclient == NULL) {
367 clnt_pcreateerror("clnt_create mount");
370 auth = authsys_create_default();
371 mountclient->cl_auth = auth;
373 bzero(&mountres3, sizeof (mountres3));
374 status = clnt_call(mountclient, MOUNTPROC_MNT,
375 xdr_dirpath, (char *)&sp,
376 xdr_mountres3, (char *)&mountres3,
378 if (status != RPC_SUCCESS) {
379 clnt_perror(mountclient, "mnt");
382 if (mountres3.fhs_status != 0) {
383 fprintf(stderr, "MOUNTPROG/MOUNTVERS3 failed %d\n",
384 mountres3.fhs_status);
387 rootfh = &mountres3.mountres3_u.mountinfo.fhandle;
389 client = clnt_create("localhost", NFS3_PROGRAM, NFS_V3, "tcp");
390 if (client == NULL) {
391 clnt_pcreateerror("clnt_create");
394 client->cl_auth = auth;
396 for (test = call3_tests; test->arginit; ++test) {
397 argbuf = realloc(argbuf, test->argsize);
398 resbuf = realloc(resbuf, test->ressize);
399 if ((argbuf == NULL) || (resbuf == NULL)) {
400 perror("realloc() failed");
403 (test->arginit)(argbuf);
404 bzero(resbuf, test->ressize);
405 status = clnt_call(client, test->proc,
406 test->xdrargs, argbuf,
407 test->xdrres, resbuf,
409 if (status != RPC_SUCCESS)
410 clnt_perror(client, "call");
413 status = clnt_call(mountclient, MOUNTPROC_UMNT,
414 xdr_dirpath, (char *)&sp,
417 if (status != RPC_SUCCESS)
418 clnt_perror(mountclient, "umnt");
425 main(int argc, char **argv)
427 char shareline[BUFSIZ], unshareline[BUFSIZ];
430 (void) snprintf(sharedpath, sizeof (sharedpath),
431 "/tmp/nfsv3test.%d", getpid());
432 (void) snprintf(shareline, sizeof (shareline),
433 "mkdir %s ; share %s", sharedpath, sharedpath);
434 (void) snprintf(unshareline, sizeof (unshareline),
435 "unshare %s ; rmdir %s", sharedpath, sharedpath);
437 (void) system(shareline);
439 (void) system(unshareline);