1 5982 ahl /* 2 5982 ahl * CDDL HEADER START 3 5982 ahl * 4 5982 ahl * The contents of this file are subject to the terms of the 5 5982 ahl * Common Development and Distribution License (the "License"). 6 5982 ahl * You may not use this file except in compliance with the License. 7 5982 ahl * 8 5982 ahl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 5982 ahl * or http://www.opensolaris.org/os/licensing. 10 5982 ahl * See the License for the specific language governing permissions 11 5982 ahl * and limitations under the License. 12 5982 ahl * 13 5982 ahl * When distributing Covered Code, include this CDDL HEADER in each 14 5982 ahl * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 5982 ahl * If applicable, add the following below this CDDL HEADER, with the 16 5982 ahl * fields enclosed by brackets "[]" replaced with your own identifying 17 5982 ahl * information: Portions Copyright [yyyy] [name of copyright owner] 18 5982 ahl * 19 5982 ahl * CDDL HEADER END 20 5982 ahl */ 21 5982 ahl 22 5982 ahl /* 23 5982 ahl * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 5982 ahl * Use is subject to license terms. 25 5982 ahl */ 26 5982 ahl 27 5982 ahl #pragma ident "%Z%%M% %I% %E% SMI" 28 5982 ahl 29 5982 ahl #include <strings.h> 30 5982 ahl #include <rpc/rpc.h> 31 5982 ahl #include <stdlib.h> 32 5982 ahl #include <sys/param.h> 33 5982 ahl #include <rpcsvc/mount.h> 34 5982 ahl 35 5982 ahl #include "rpcsvc/nfs_prot.h" 36 5982 ahl 37 5982 ahl char sharedpath[MAXPATHLEN]; 38 5982 ahl fhandle3 *rootfh; 39 5982 ahl 40 5982 ahl /* 41 5982 ahl * The waiting() function returns the value passed in, until something 42 5982 ahl * external modifies it. In this case, the D script tst.call.d will 43 5982 ahl * modify the value of *a, and thus break the while loop in dotest(). 44 5982 ahl * 45 5982 ahl * This serves the purpose of not making the RPC calls until tst.call.d 46 5982 ahl * is active. Thus, the probes in tst.call.d can fire as a result of 47 5982 ahl * the RPC call in dotest(). 48 5982 ahl */ 49 5982 ahl 50 5982 ahl int 51 5982 ahl waiting(volatile int *a) 52 5982 ahl { 53 5982 ahl return (*a); 54 5982 ahl } 55 5982 ahl 56 5982 ahl static void 57 5982 ahl getattr_arginit(void *argp) 58 5982 ahl { 59 5982 ahl GETATTR3args *args = argp; 60 5982 ahl 61 5982 ahl args->object.data.data_len = rootfh->fhandle3_len; 62 5982 ahl args->object.data.data_val = rootfh->fhandle3_val; 63 5982 ahl } 64 5982 ahl 65 5982 ahl static void 66 5982 ahl setattr_arginit(void *argp) 67 5982 ahl { 68 5982 ahl SETATTR3args *args = argp; 69 5982 ahl 70 5982 ahl bzero(args, sizeof (*args)); 71 5982 ahl args->object.data.data_len = rootfh->fhandle3_len; 72 5982 ahl args->object.data.data_val = rootfh->fhandle3_val; 73 5982 ahl } 74 5982 ahl 75 5982 ahl static void 76 5982 ahl lookup_arginit(void *argp) 77 5982 ahl { 78 5982 ahl LOOKUP3args *args = argp; 79 5982 ahl 80 5982 ahl args->what.name = "giant-skunk"; 81 5982 ahl args->what.dir.data.data_len = rootfh->fhandle3_len; 82 5982 ahl args->what.dir.data.data_val = rootfh->fhandle3_val; 83 5982 ahl } 84 5982 ahl 85 5982 ahl static void 86 5982 ahl access_arginit(void *argp) 87 5982 ahl { 88 5982 ahl ACCESS3args *args = argp; 89 5982 ahl 90 5982 ahl args->object.data.data_len = rootfh->fhandle3_len; 91 5982 ahl args->object.data.data_val = rootfh->fhandle3_val; 92 5982 ahl } 93 5982 ahl 94 5982 ahl static void 95 5982 ahl commit_arginit(void *argp) 96 5982 ahl { 97 5982 ahl COMMIT3args *args = argp; 98 5982 ahl 99 5982 ahl bzero(args, sizeof (*args)); 100 5982 ahl args->file.data.data_len = rootfh->fhandle3_len; 101 5982 ahl args->file.data.data_val = rootfh->fhandle3_val; 102 5982 ahl } 103 5982 ahl 104 5982 ahl static void 105 5982 ahl create_arginit(void *argp) 106 5982 ahl { 107 5982 ahl CREATE3args *args = argp; 108 5982 ahl 109 5982 ahl bzero(args, sizeof (*args)); 110 5982 ahl args->where.name = "pinky-blue"; 111 5982 ahl args->where.dir.data.data_len = rootfh->fhandle3_len; 112 5982 ahl args->where.dir.data.data_val = rootfh->fhandle3_val; 113 5982 ahl } 114 5982 ahl 115 5982 ahl static void 116 5982 ahl fsinfo_arginit(void *argp) 117 5982 ahl { 118 5982 ahl FSINFO3args *args = argp; 119 5982 ahl 120 5982 ahl args->fsroot.data.data_len = rootfh->fhandle3_len; 121 5982 ahl args->fsroot.data.data_val = rootfh->fhandle3_val; 122 5982 ahl } 123 5982 ahl 124 5982 ahl static void 125 5982 ahl fsstat_arginit(void *argp) 126 5982 ahl { 127 5982 ahl FSSTAT3args *args = argp; 128 5982 ahl 129 5982 ahl args->fsroot.data.data_len = rootfh->fhandle3_len; 130 5982 ahl args->fsroot.data.data_val = rootfh->fhandle3_val; 131 5982 ahl } 132 5982 ahl 133 5982 ahl static void 134 5982 ahl link_arginit(void *argp) 135 5982 ahl { 136 5982 ahl LINK3args *args = argp; 137 5982 ahl 138 5982 ahl args->file.data.data_len = rootfh->fhandle3_len; 139 5982 ahl args->file.data.data_val = rootfh->fhandle3_val; 140 5982 ahl args->link.dir.data.data_len = rootfh->fhandle3_len; 141 5982 ahl args->link.dir.data.data_val = rootfh->fhandle3_val; 142 5982 ahl args->link.name = "samf"; 143 5982 ahl } 144 5982 ahl 145 5982 ahl static void 146 5982 ahl mkdir_arginit(void *argp) 147 5982 ahl { 148 5982 ahl MKDIR3args *args = argp; 149 5982 ahl 150 5982 ahl bzero(args, sizeof (*args)); 151 5982 ahl args->where.dir.data.data_len = rootfh->fhandle3_len; 152 5982 ahl args->where.dir.data.data_val = rootfh->fhandle3_val; 153 5982 ahl args->where.name = "cookie"; 154 5982 ahl } 155 5982 ahl 156 5982 ahl static void 157 5982 ahl mknod_arginit(void *argp) 158 5982 ahl { 159 5982 ahl MKNOD3args *args = argp; 160 5982 ahl 161 5982 ahl bzero(args, sizeof (*args)); 162 5982 ahl args->where.dir.data.data_len = rootfh->fhandle3_len; 163 5982 ahl args->where.dir.data.data_val = rootfh->fhandle3_val; 164 5982 ahl args->where.name = "pookie"; 165 5982 ahl } 166 5982 ahl 167 5982 ahl static void 168 5982 ahl null_arginit(void *argp) 169 5982 ahl { 170 5982 ahl } 171 5982 ahl 172 5982 ahl static void 173 5982 ahl pathconf_arginit(void *argp) 174 5982 ahl { 175 5982 ahl PATHCONF3args *args = argp; 176 5982 ahl 177 5982 ahl args->object.data.data_len = rootfh->fhandle3_len; 178 5982 ahl args->object.data.data_val = rootfh->fhandle3_val; 179 5982 ahl } 180 5982 ahl 181 5982 ahl static void 182 5982 ahl read_arginit(void *argp) 183 5982 ahl { 184 5982 ahl READ3args *args = argp; 185 5982 ahl 186 5982 ahl bzero(args, sizeof (*args)); 187 5982 ahl args->file.data.data_len = rootfh->fhandle3_len; 188 5982 ahl args->file.data.data_val = rootfh->fhandle3_val; 189 5982 ahl } 190 5982 ahl 191 5982 ahl static void 192 5982 ahl readdir_arginit(void *argp) 193 5982 ahl { 194 5982 ahl READDIR3args *args = argp; 195 5982 ahl 196 5982 ahl bzero(args, sizeof (*args)); 197 5982 ahl args->dir.data.data_len = rootfh->fhandle3_len; 198 5982 ahl args->dir.data.data_val = rootfh->fhandle3_val; 199 5982 ahl args->count = 1024; 200 5982 ahl } 201 5982 ahl 202 5982 ahl static void 203 5982 ahl readdirplus_arginit(void *argp) 204 5982 ahl { 205 5982 ahl READDIRPLUS3args *args = argp; 206 5982 ahl 207 5982 ahl bzero(args, sizeof (*args)); 208 5982 ahl args->dir.data.data_len = rootfh->fhandle3_len; 209 5982 ahl args->dir.data.data_val = rootfh->fhandle3_val; 210 5982 ahl args->dircount = 1024; 211 5982 ahl args->maxcount = 1024; 212 5982 ahl } 213 5982 ahl 214 5982 ahl static void 215 5982 ahl readlink_arginit(void *argp) 216 5982 ahl { 217 5982 ahl READLINK3args *args = argp; 218 5982 ahl 219 5982 ahl args->symlink.data.data_len = rootfh->fhandle3_len; 220 5982 ahl args->symlink.data.data_val = rootfh->fhandle3_val; 221 5982 ahl } 222 5982 ahl 223 5982 ahl static void 224 5982 ahl remove_arginit(void *argp) 225 5982 ahl { 226 5982 ahl REMOVE3args *args = argp; 227 5982 ahl 228 5982 ahl args->object.dir.data.data_len = rootfh->fhandle3_len; 229 5982 ahl args->object.dir.data.data_val = rootfh->fhandle3_val; 230 5982 ahl args->object.name = "antelope"; 231 5982 ahl } 232 5982 ahl 233 5982 ahl static void 234 5982 ahl rename_arginit(void *argp) 235 5982 ahl { 236 5982 ahl RENAME3args *args = argp; 237 5982 ahl 238 5982 ahl args->from.dir.data.data_len = rootfh->fhandle3_len; 239 5982 ahl args->from.dir.data.data_val = rootfh->fhandle3_val; 240 5982 ahl args->from.name = "walter"; 241 5982 ahl args->to.dir.data.data_len = rootfh->fhandle3_len; 242 5982 ahl args->to.dir.data.data_val = rootfh->fhandle3_val; 243 5982 ahl args->to.name = "wendy"; 244 5982 ahl } 245 5982 ahl 246 5982 ahl static void 247 5982 ahl rmdir_arginit(void *argp) 248 5982 ahl { 249 5982 ahl RMDIR3args *args = argp; 250 5982 ahl 251 5982 ahl args->object.dir.data.data_len = rootfh->fhandle3_len; 252 5982 ahl args->object.dir.data.data_val = rootfh->fhandle3_val; 253 5982 ahl args->object.name = "bunny"; 254 5982 ahl } 255 5982 ahl 256 5982 ahl static void 257 5982 ahl symlink_arginit(void *argp) 258 5982 ahl { 259 5982 ahl SYMLINK3args *args = argp; 260 5982 ahl 261 5982 ahl bzero(args, sizeof (*args)); 262 5982 ahl args->where.dir.data.data_len = rootfh->fhandle3_len; 263 5982 ahl args->where.dir.data.data_val = rootfh->fhandle3_val; 264 5982 ahl args->where.name = "parlor"; 265 5982 ahl args->symlink.symlink_data = "interior"; 266 5982 ahl } 267 5982 ahl 268 5982 ahl static void 269 5982 ahl write_arginit(void *argp) 270 5982 ahl { 271 5982 ahl WRITE3args *args = argp; 272 5982 ahl 273 5982 ahl bzero(args, sizeof (*args)); 274 5982 ahl args->file.data.data_len = rootfh->fhandle3_len; 275 5982 ahl args->file.data.data_val = rootfh->fhandle3_val; 276 5982 ahl } 277 5982 ahl 278 5982 ahl typedef void (*call3_arginit_t)(void *); 279 5982 ahl 280 5982 ahl typedef struct { 281 5982 ahl call3_arginit_t arginit; 282 5982 ahl rpcproc_t proc; 283 5982 ahl xdrproc_t xdrargs; 284 5982 ahl size_t argsize; 285 5982 ahl xdrproc_t xdrres; 286 5982 ahl size_t ressize; 287 5982 ahl } call3_test_t; 288 5982 ahl call3_test_t call3_tests[] = { 289 5982 ahl {getattr_arginit, NFSPROC3_GETATTR, xdr_GETATTR3args, 290 5982 ahl sizeof (GETATTR3args), xdr_GETATTR3res, sizeof (GETATTR3res)}, 291 5982 ahl {setattr_arginit, NFSPROC3_SETATTR, xdr_SETATTR3args, 292 5982 ahl sizeof (SETATTR3args), xdr_SETATTR3res, sizeof (SETATTR3res)}, 293 5982 ahl {lookup_arginit, NFSPROC3_LOOKUP, xdr_LOOKUP3args, 294 5982 ahl sizeof (LOOKUP3args), xdr_LOOKUP3res, sizeof (LOOKUP3res)}, 295 5982 ahl {access_arginit, NFSPROC3_ACCESS, xdr_ACCESS3args, 296 5982 ahl sizeof (ACCESS3args), xdr_ACCESS3res, sizeof (ACCESS3res)}, 297 5982 ahl {commit_arginit, NFSPROC3_COMMIT, xdr_COMMIT3args, 298 5982 ahl sizeof (COMMIT3args), xdr_COMMIT3res, sizeof (COMMIT3res)}, 299 5982 ahl {create_arginit, NFSPROC3_CREATE, xdr_CREATE3args, 300 5982 ahl sizeof (CREATE3args), xdr_CREATE3res, sizeof (CREATE3res)}, 301 5982 ahl {fsinfo_arginit, NFSPROC3_FSINFO, xdr_FSINFO3args, 302 5982 ahl sizeof (FSINFO3args), xdr_FSINFO3res, sizeof (FSINFO3res)}, 303 5982 ahl {fsstat_arginit, NFSPROC3_FSSTAT, xdr_FSSTAT3args, 304 5982 ahl sizeof (FSSTAT3args), xdr_FSSTAT3res, sizeof (FSSTAT3res)}, 305 5982 ahl {link_arginit, NFSPROC3_LINK, xdr_LINK3args, 306 5982 ahl sizeof (LINK3args), xdr_LINK3res, sizeof (LINK3res)}, 307 5982 ahl {mkdir_arginit, NFSPROC3_MKDIR, xdr_MKDIR3args, 308 5982 ahl sizeof (MKDIR3args), xdr_MKDIR3res, sizeof (MKDIR3res)}, 309 5982 ahl {mknod_arginit, NFSPROC3_MKNOD, xdr_MKNOD3args, 310 5982 ahl sizeof (MKNOD3args), xdr_MKNOD3res, sizeof (MKNOD3res)}, 311 5982 ahl /* 312 5982 ahl * NULL proc is special. Rather than special case its zero-sized 313 5982 ahl * args/results, we give it a small nonzero size, so as to not 314 5982 ahl * make realloc() do the wrong thing. 315 5982 ahl */ 316 5982 ahl {null_arginit, NFSPROC3_NULL, xdr_void, sizeof (int), xdr_void, 317 5982 ahl sizeof (int)}, 318 5982 ahl {pathconf_arginit, NFSPROC3_PATHCONF, xdr_PATHCONF3args, 319 5982 ahl sizeof (PATHCONF3args), xdr_PATHCONF3res, sizeof (PATHCONF3res)}, 320 5982 ahl {read_arginit, NFSPROC3_READ, xdr_READ3args, 321 5982 ahl sizeof (READ3args), xdr_READ3res, sizeof (READ3res)}, 322 5982 ahl {readdir_arginit, NFSPROC3_READDIR, xdr_READDIR3args, 323 5982 ahl sizeof (READDIR3args), xdr_READDIR3res, sizeof (READDIR3res)}, 324 5982 ahl {readdirplus_arginit, NFSPROC3_READDIRPLUS, xdr_READDIRPLUS3args, 325 5982 ahl sizeof (READDIRPLUS3args), xdr_READDIRPLUS3res, 326 5982 ahl sizeof (READDIRPLUS3res)}, 327 5982 ahl {readlink_arginit, NFSPROC3_READLINK, xdr_READLINK3args, 328 5982 ahl sizeof (READLINK3args), xdr_READLINK3res, sizeof (READLINK3res)}, 329 5982 ahl {remove_arginit, NFSPROC3_REMOVE, xdr_REMOVE3args, 330 5982 ahl sizeof (REMOVE3args), xdr_REMOVE3res, sizeof (REMOVE3res)}, 331 5982 ahl {rename_arginit, NFSPROC3_RENAME, xdr_RENAME3args, 332 5982 ahl sizeof (RENAME3args), xdr_RENAME3res, sizeof (RENAME3res)}, 333 5982 ahl {rmdir_arginit, NFSPROC3_RMDIR, xdr_RMDIR3args, 334 5982 ahl sizeof (RMDIR3args), xdr_RMDIR3res, sizeof (RMDIR3res)}, 335 5982 ahl {symlink_arginit, NFSPROC3_SYMLINK, xdr_SYMLINK3args, 336 5982 ahl sizeof (SYMLINK3args), xdr_SYMLINK3res, sizeof (SYMLINK3res)}, 337 5982 ahl {write_arginit, NFSPROC3_WRITE, xdr_WRITE3args, 338 5982 ahl sizeof (WRITE3args), xdr_WRITE3res, sizeof (WRITE3res)}, 339 5982 ahl {NULL} 340 5982 ahl }; 341 5982 ahl 342 5982 ahl int 343 5982 ahl dotest(void) 344 5982 ahl { 345 5982 ahl CLIENT *client, *mountclient; 346 5982 ahl AUTH *auth; 347 5982 ahl struct timeval timeout; 348 5982 ahl caddr_t args, res; 349 5982 ahl enum clnt_stat status; 350 5982 ahl rpcproc_t proc; 351 5982 ahl call3_test_t *test; 352 5982 ahl void *argbuf = NULL; 353 5982 ahl void *resbuf = NULL; 354 5982 ahl struct mountres3 mountres3; 355 5982 ahl char *sp; 356 5982 ahl volatile int a = 0; 357 5982 ahl 358 5982 ahl while (waiting(&a) == 0) 359 5982 ahl continue; 360 5982 ahl 361 5982 ahl timeout.tv_sec = 30; 362 5982 ahl timeout.tv_usec = 0; 363 5982 ahl 364 5982 ahl mountclient = clnt_create("localhost", MOUNTPROG, MOUNTVERS3, "tcp"); 365 5982 ahl if (mountclient == NULL) { 366 5982 ahl clnt_pcreateerror("clnt_create mount"); 367 5982 ahl return (1); 368 5982 ahl } 369 5982 ahl auth = authsys_create_default(); 370 5982 ahl mountclient->cl_auth = auth; 371 5982 ahl sp = sharedpath; 372 5982 ahl bzero(&mountres3, sizeof (mountres3)); 373 5982 ahl status = clnt_call(mountclient, MOUNTPROC_MNT, 374 5982 ahl xdr_dirpath, (char *)&sp, 375 5982 ahl xdr_mountres3, (char *)&mountres3, 376 5982 ahl timeout); 377 5982 ahl if (status != RPC_SUCCESS) { 378 5982 ahl clnt_perror(mountclient, "mnt"); 379 5982 ahl return (1); 380 5982 ahl } 381 5982 ahl if (mountres3.fhs_status != 0) { 382 5982 ahl fprintf(stderr, "MOUNTPROG/MOUNTVERS3 failed %d\n", 383 5982 ahl mountres3.fhs_status); 384 5982 ahl return (1); 385 5982 ahl } 386 5982 ahl rootfh = &mountres3.mountres3_u.mountinfo.fhandle; 387 5982 ahl 388 5982 ahl client = clnt_create("localhost", NFS3_PROGRAM, NFS_V3, "tcp"); 389 5982 ahl if (client == NULL) { 390 5982 ahl clnt_pcreateerror("clnt_create"); 391 5982 ahl return (1); 392 5982 ahl } 393 5982 ahl client->cl_auth = auth; 394 5982 ahl 395 5982 ahl for (test = call3_tests; test->arginit; ++test) { 396 5982 ahl argbuf = realloc(argbuf, test->argsize); 397 5982 ahl resbuf = realloc(resbuf, test->ressize); 398 5982 ahl if ((argbuf == NULL) || (resbuf == NULL)) { 399 5982 ahl perror("realloc() failed"); 400 5982 ahl return (1); 401 5982 ahl } 402 5982 ahl (test->arginit)(argbuf); 403 5982 ahl bzero(resbuf, test->ressize); 404 5982 ahl status = clnt_call(client, test->proc, 405 5982 ahl test->xdrargs, argbuf, 406 5982 ahl test->xdrres, resbuf, 407 5982 ahl timeout); 408 5982 ahl if (status != RPC_SUCCESS) 409 5982 ahl clnt_perror(client, "call"); 410 5982 ahl } 411 5982 ahl 412 5982 ahl status = clnt_call(mountclient, MOUNTPROC_UMNT, 413 5982 ahl xdr_dirpath, (char *)&sp, 414 5982 ahl xdr_void, NULL, 415 5982 ahl timeout); 416 5982 ahl if (status != RPC_SUCCESS) 417 5982 ahl clnt_perror(mountclient, "umnt"); 418 5982 ahl 419 5982 ahl return (0); 420 5982 ahl } 421 5982 ahl 422 5982 ahl /*ARGSUSED*/ 423 5982 ahl int 424 5982 ahl main(int argc, char **argv) 425 5982 ahl { 426 5982 ahl char shareline[BUFSIZ], unshareline[BUFSIZ]; 427 5982 ahl int rc; 428 5982 ahl 429 5982 ahl (void) snprintf(sharedpath, sizeof (sharedpath), 430 5982 ahl "/tmp/nfsv3test.%d", getpid()); 431 5982 ahl (void) snprintf(shareline, sizeof (shareline), 432 5982 ahl "mkdir %s ; share %s", sharedpath, sharedpath); 433 5982 ahl (void) snprintf(unshareline, sizeof (unshareline), 434 5982 ahl "unshare %s ; rmdir %s", sharedpath, sharedpath); 435 5982 ahl 436 5982 ahl (void) system(shareline); 437 5982 ahl rc = dotest(); 438 5982 ahl (void) system(unshareline); 439 5982 ahl 440 5982 ahl return (rc); 441 5982 ahl } 442