1/*- 2 * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ 3 * Authors: Doug Rabson <dfr@rabson.org> 4 * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> 29#ifndef lint 30/*static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";*/ 31/*static char sccsid[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";*/ 32__RCSID("$NetBSD: nlm_prot.x,v 1.6 2000/06/07 14:30:15 bouyer Exp $"); 33#endif /* not lint */ 34__FBSDID("$FreeBSD$"); 35 36#include <sys/param.h> 37#include <sys/malloc.h> 38#include <sys/systm.h> 39 40#include <nlm/nlm_prot.h> 41#include <nlm/nlm.h> 42 43/**********************************************************************/ 44 45/* 46 * Convert between various versions of the protocol structures. 47 */ 48 49static void 50nlm_convert_to_nlm4_lock(struct nlm4_lock *dst, struct nlm_lock *src) 51{ 52 53 dst->caller_name = src->caller_name; 54 dst->fh = src->fh; 55 dst->oh = src->oh; 56 dst->svid = src->svid; 57 dst->l_offset = src->l_offset; 58 dst->l_len = src->l_len; 59} 60 61static void 62nlm_convert_to_nlm4_share(struct nlm4_share *dst, struct nlm_share *src) 63{ 64 65 dst->caller_name = src->caller_name; 66 dst->fh = src->fh; 67 dst->oh = src->oh; 68 dst->mode = src->mode; 69 dst->access = src->access; 70} 71 72static void 73nlm_convert_to_nlm_holder(struct nlm_holder *dst, struct nlm4_holder *src) 74{ 75 76 dst->exclusive = src->exclusive; 77 dst->svid = src->svid; 78 dst->oh = src->oh; 79 dst->l_offset = src->l_offset; 80 dst->l_len = src->l_len; 81} 82 83static void 84nlm_convert_to_nlm4_holder(struct nlm4_holder *dst, struct nlm_holder *src) 85{ 86 87 dst->exclusive = src->exclusive; 88 dst->svid = src->svid; 89 dst->oh = src->oh; 90 dst->l_offset = src->l_offset; 91 dst->l_len = src->l_len; 92} 93 94static enum nlm_stats 95nlm_convert_to_nlm_stats(enum nlm4_stats src) 96{ 97 if (src > nlm4_deadlck) 98 return nlm_denied; 99 return (enum nlm_stats) src; 100} 101 102static void 103nlm_convert_to_nlm_res(struct nlm_res *dst, struct nlm4_res *src) 104{ 105 dst->cookie = src->cookie; 106 dst->stat.stat = nlm_convert_to_nlm_stats(src->stat.stat); 107} 108 109static void 110nlm_convert_to_nlm4_res(struct nlm4_res *dst, struct nlm_res *src) 111{ 112 dst->cookie = src->cookie; 113 dst->stat.stat = (enum nlm4_stats) src->stat.stat; 114} 115 116/**********************************************************************/ 117 118/* 119 * RPC server stubs. 120 */ 121 122bool_t 123nlm_sm_notify_0_svc(struct nlm_sm_status *argp, void *result, struct svc_req *rqstp) 124{ 125 nlm_sm_notify(argp); 126 127 return (TRUE); 128} 129 130bool_t 131nlm_test_1_svc(struct nlm_testargs *argp, nlm_testres *result, struct svc_req *rqstp) 132{ 133 bool_t retval; 134 nlm4_testargs args4; 135 nlm4_testres res4; 136 137 args4.cookie = argp->cookie; 138 args4.exclusive = argp->exclusive; 139 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 140 141 retval = nlm4_test_4_svc(&args4, &res4, rqstp); 142 if (retval) { 143 result->cookie = res4.cookie; 144 result->stat.stat = nlm_convert_to_nlm_stats(res4.stat.stat); 145 if (result->stat.stat == nlm_denied) 146 nlm_convert_to_nlm_holder( 147 &result->stat.nlm_testrply_u.holder, 148 &res4.stat.nlm4_testrply_u.holder); 149 } 150 151 return (retval); 152} 153 154bool_t 155nlm_lock_1_svc(struct nlm_lockargs *argp, nlm_res *result, struct svc_req *rqstp) 156{ 157 bool_t retval; 158 nlm4_lockargs args4; 159 nlm4_res res4; 160 161 args4.cookie = argp->cookie; 162 args4.block = argp->block; 163 args4.exclusive = argp->exclusive; 164 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 165 args4.reclaim = argp->reclaim; 166 args4.state = argp->state; 167 168 retval = nlm4_lock_4_svc(&args4, &res4, rqstp); 169 if (retval) 170 nlm_convert_to_nlm_res(result, &res4); 171 172 return (retval); 173} 174 175bool_t 176nlm_cancel_1_svc(struct nlm_cancargs *argp, nlm_res *result, struct svc_req *rqstp) 177{ 178 bool_t retval; 179 nlm4_cancargs args4; 180 nlm4_res res4; 181 182 args4.cookie = argp->cookie; 183 args4.block = argp->block; 184 args4.exclusive = argp->exclusive; 185 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 186 187 retval = nlm4_cancel_4_svc(&args4, &res4, rqstp); 188 if (retval) 189 nlm_convert_to_nlm_res(result, &res4); 190 191 return (retval); 192} 193 194bool_t 195nlm_unlock_1_svc(struct nlm_unlockargs *argp, nlm_res *result, struct svc_req *rqstp) 196{ 197 bool_t retval; 198 nlm4_unlockargs args4; 199 nlm4_res res4; 200 201 args4.cookie = argp->cookie; 202 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 203 204 retval = nlm4_unlock_4_svc(&args4, &res4, rqstp); 205 if (retval) 206 nlm_convert_to_nlm_res(result, &res4); 207 208 return (retval); 209} 210 211bool_t 212nlm_granted_1_svc(struct nlm_testargs *argp, nlm_res *result, struct svc_req *rqstp) 213{ 214 bool_t retval; 215 nlm4_testargs args4; 216 nlm4_res res4; 217 218 args4.cookie = argp->cookie; 219 args4.exclusive = argp->exclusive; 220 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 221 222 retval = nlm4_granted_4_svc(&args4, &res4, rqstp); 223 if (retval) 224 nlm_convert_to_nlm_res(result, &res4); 225 226 return (retval); 227} 228 229bool_t 230nlm_test_msg_1_svc(struct nlm_testargs *argp, void *result, struct svc_req *rqstp) 231{ 232 nlm4_testargs args4; 233 nlm4_testres res4; 234 nlm_testres res; 235 CLIENT *rpc; 236 char dummy; 237 238 args4.cookie = argp->cookie; 239 args4.exclusive = argp->exclusive; 240 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 241 242 if (nlm_do_test(&args4, &res4, rqstp, &rpc)) 243 return (FALSE); 244 245 res.cookie = res4.cookie; 246 res.stat.stat = nlm_convert_to_nlm_stats(res4.stat.stat); 247 if (res.stat.stat == nlm_denied) 248 nlm_convert_to_nlm_holder( 249 &res.stat.nlm_testrply_u.holder, 250 &res4.stat.nlm4_testrply_u.holder); 251 252 if (rpc) { 253 nlm_test_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv); 254 CLNT_RELEASE(rpc); 255 } 256 xdr_free((xdrproc_t) xdr_nlm_testres, &res); 257 258 return (FALSE); 259} 260 261bool_t 262nlm_lock_msg_1_svc(struct nlm_lockargs *argp, void *result, struct svc_req *rqstp) 263{ 264 nlm4_lockargs args4; 265 nlm4_res res4; 266 nlm_res res; 267 CLIENT *rpc; 268 char dummy; 269 270 args4.cookie = argp->cookie; 271 args4.block = argp->block; 272 args4.exclusive = argp->exclusive; 273 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 274 args4.reclaim = argp->reclaim; 275 args4.state = argp->state; 276 277 if (nlm_do_lock(&args4, &res4, rqstp, TRUE, &rpc)) 278 return (FALSE); 279 280 nlm_convert_to_nlm_res(&res, &res4); 281 282 if (rpc) { 283 nlm_lock_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv); 284 CLNT_RELEASE(rpc); 285 } 286 xdr_free((xdrproc_t) xdr_nlm_res, &res); 287 288 return (FALSE); 289} 290 291bool_t 292nlm_cancel_msg_1_svc(struct nlm_cancargs *argp, void *result, struct svc_req *rqstp) 293{ 294 nlm4_cancargs args4; 295 nlm4_res res4; 296 nlm_res res; 297 CLIENT *rpc; 298 char dummy; 299 300 args4.cookie = argp->cookie; 301 args4.block = argp->block; 302 args4.exclusive = argp->exclusive; 303 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 304 305 if (nlm_do_cancel(&args4, &res4, rqstp, &rpc)) 306 return (FALSE); 307 308 nlm_convert_to_nlm_res(&res, &res4); 309 310 if (rpc) { 311 nlm_cancel_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv); 312 CLNT_RELEASE(rpc); 313 } 314 xdr_free((xdrproc_t) xdr_nlm_res, &res); 315 316 return (FALSE); 317} 318 319bool_t 320nlm_unlock_msg_1_svc(struct nlm_unlockargs *argp, void *result, struct svc_req *rqstp) 321{ 322 nlm4_unlockargs args4; 323 nlm4_res res4; 324 nlm_res res; 325 CLIENT *rpc; 326 char dummy; 327 328 args4.cookie = argp->cookie; 329 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 330 331 if (nlm_do_unlock(&args4, &res4, rqstp, &rpc)) 332 return (FALSE); 333 334 nlm_convert_to_nlm_res(&res, &res4); 335 336 if (rpc) { 337 nlm_unlock_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv); 338 CLNT_RELEASE(rpc); 339 } 340 xdr_free((xdrproc_t) xdr_nlm_res, &res); 341 342 return (FALSE); 343} 344 345bool_t 346nlm_granted_msg_1_svc(struct nlm_testargs *argp, void *result, struct svc_req *rqstp) 347{ 348 nlm4_testargs args4; 349 nlm4_res res4; 350 nlm_res res; 351 CLIENT *rpc; 352 char dummy; 353 354 args4.cookie = argp->cookie; 355 args4.exclusive = argp->exclusive; 356 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 357 358 if (nlm_do_granted(&args4, &res4, rqstp, &rpc)) 359 return (FALSE); 360 361 nlm_convert_to_nlm_res(&res, &res4); 362 363 if (rpc) { 364 nlm_granted_res_1(&res, &dummy, rpc, NULL, nlm_zero_tv); 365 CLNT_RELEASE(rpc); 366 } 367 xdr_free((xdrproc_t) xdr_nlm_res, &res); 368 369 return (FALSE); 370} 371 372bool_t 373nlm_test_res_1_svc(nlm_testres *argp, void *result, struct svc_req *rqstp) 374{ 375 nlm4_testres args4; 376 377 args4.cookie = argp->cookie; 378 if (argp->stat.stat == nlm_denied) 379 nlm_convert_to_nlm4_holder( 380 &args4.stat.nlm4_testrply_u.holder, 381 &argp->stat.nlm_testrply_u.holder); 382 383 return (nlm4_test_res_4_svc(&args4, result, rqstp)); 384} 385 386bool_t 387nlm_lock_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp) 388{ 389 nlm4_res arg4; 390 391 nlm_convert_to_nlm4_res(&arg4, argp); 392 return (nlm4_lock_res_4_svc(&arg4, result, rqstp)); 393} 394 395bool_t 396nlm_cancel_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp) 397{ 398 nlm4_res arg4; 399 400 nlm_convert_to_nlm4_res(&arg4, argp); 401 return (nlm4_cancel_res_4_svc(&arg4, result, rqstp)); 402} 403 404bool_t 405nlm_unlock_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp) 406{ 407 nlm4_res arg4; 408 409 nlm_convert_to_nlm4_res(&arg4, argp); 410 return (nlm4_unlock_res_4_svc(&arg4, result, rqstp)); 411} 412 413bool_t 414nlm_granted_res_1_svc(nlm_res *argp, void *result, struct svc_req *rqstp) 415{ 416 nlm4_res arg4; 417 418 nlm_convert_to_nlm4_res(&arg4, argp); 419 return (nlm4_granted_res_4_svc(&arg4, result, rqstp)); 420} 421 422int 423nlm_prog_1_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result) 424{ 425 426 (void) xdr_free(xdr_result, result); 427 return (TRUE); 428} 429 430bool_t 431nlm_share_3_svc(nlm_shareargs *argp, nlm_shareres *result, struct svc_req *rqstp) 432{ 433 bool_t retval; 434 nlm4_shareargs args4; 435 nlm4_shareres res4; 436 437 args4.cookie = argp->cookie; 438 nlm_convert_to_nlm4_share(&args4.share, &argp->share); 439 args4.reclaim = argp->reclaim; 440 441 retval = nlm4_share_4_svc(&args4, &res4, rqstp); 442 if (retval) { 443 result->cookie = res4.cookie; 444 result->stat = nlm_convert_to_nlm_stats(res4.stat); 445 result->sequence = res4.sequence; 446 } 447 448 return (retval); 449} 450 451bool_t 452nlm_unshare_3_svc(nlm_shareargs *argp, nlm_shareres *result, struct svc_req *rqstp) 453{ 454 bool_t retval; 455 nlm4_shareargs args4; 456 nlm4_shareres res4; 457 458 args4.cookie = argp->cookie; 459 nlm_convert_to_nlm4_share(&args4.share, &argp->share); 460 args4.reclaim = argp->reclaim; 461 462 retval = nlm4_unshare_4_svc(&args4, &res4, rqstp); 463 if (retval) { 464 result->cookie = res4.cookie; 465 result->stat = nlm_convert_to_nlm_stats(res4.stat); 466 result->sequence = res4.sequence; 467 } 468 469 return (retval); 470} 471 472bool_t 473nlm_nm_lock_3_svc(nlm_lockargs *argp, nlm_res *result, struct svc_req *rqstp) 474{ 475 bool_t retval; 476 nlm4_lockargs args4; 477 nlm4_res res4; 478 479 args4.cookie = argp->cookie; 480 args4.block = argp->block; 481 args4.exclusive = argp->exclusive; 482 nlm_convert_to_nlm4_lock(&args4.alock, &argp->alock); 483 args4.reclaim = argp->reclaim; 484 args4.state = argp->state; 485 486 retval = nlm4_nm_lock_4_svc(&args4, &res4, rqstp); 487 if (retval) 488 nlm_convert_to_nlm_res(result, &res4); 489 490 return (retval); 491} 492 493bool_t 494nlm_free_all_3_svc(nlm_notify *argp, void *result, struct svc_req *rqstp) 495{ 496 struct nlm4_notify args4; 497 498 args4.name = argp->name; 499 args4.state = argp->state; 500 501 return (nlm4_free_all_4_svc(&args4, result, rqstp)); 502} 503 504int 505nlm_prog_3_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result) 506{ 507 508 (void) xdr_free(xdr_result, result); 509 return (TRUE); 510} 511 512bool_t 513nlm4_test_4_svc(nlm4_testargs *argp, nlm4_testres *result, struct svc_req *rqstp) 514{ 515 516 nlm_do_test(argp, result, rqstp, NULL); 517 return (TRUE); 518} 519 520bool_t 521nlm4_lock_4_svc(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp) 522{ 523 524 nlm_do_lock(argp, result, rqstp, TRUE, NULL); 525 return (TRUE); 526} 527 528bool_t 529nlm4_cancel_4_svc(nlm4_cancargs *argp, nlm4_res *result, struct svc_req *rqstp) 530{ 531 532 nlm_do_cancel(argp, result, rqstp, NULL); 533 return (TRUE); 534} 535 536bool_t 537nlm4_unlock_4_svc(nlm4_unlockargs *argp, nlm4_res *result, struct svc_req *rqstp) 538{ 539 540 nlm_do_unlock(argp, result, rqstp, NULL); 541 return (TRUE); 542} 543 544bool_t 545nlm4_granted_4_svc(nlm4_testargs *argp, nlm4_res *result, struct svc_req *rqstp) 546{ 547 548 nlm_do_granted(argp, result, rqstp, NULL); 549 return (TRUE); 550} 551 552bool_t 553nlm4_test_msg_4_svc(nlm4_testargs *argp, void *result, struct svc_req *rqstp) 554{ 555 nlm4_testres res4; 556 CLIENT *rpc; 557 char dummy; 558 559 if (nlm_do_test(argp, &res4, rqstp, &rpc)) 560 return (FALSE); 561 if (rpc) { 562 nlm4_test_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv); 563 CLNT_RELEASE(rpc); 564 } 565 xdr_free((xdrproc_t) xdr_nlm4_testres, &res4); 566 567 return (FALSE); 568} 569 570bool_t 571nlm4_lock_msg_4_svc(nlm4_lockargs *argp, void *result, struct svc_req *rqstp) 572{ 573 nlm4_res res4; 574 CLIENT *rpc; 575 char dummy; 576 577 if (nlm_do_lock(argp, &res4, rqstp, TRUE, &rpc)) 578 return (FALSE); 579 if (rpc) { 580 nlm4_lock_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv); 581 CLNT_RELEASE(rpc); 582 } 583 xdr_free((xdrproc_t) xdr_nlm4_res, &res4); 584 585 return (FALSE); 586} 587 588bool_t 589nlm4_cancel_msg_4_svc(nlm4_cancargs *argp, void *result, struct svc_req *rqstp) 590{ 591 nlm4_res res4; 592 CLIENT *rpc; 593 char dummy; 594 595 if (nlm_do_cancel(argp, &res4, rqstp, &rpc)) 596 return (FALSE); 597 if (rpc) { 598 nlm4_cancel_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv); 599 CLNT_RELEASE(rpc); 600 } 601 xdr_free((xdrproc_t) xdr_nlm4_res, &res4); 602 603 return (FALSE); 604} 605 606bool_t 607nlm4_unlock_msg_4_svc(nlm4_unlockargs *argp, void *result, struct svc_req *rqstp) 608{ 609 nlm4_res res4; 610 CLIENT *rpc; 611 char dummy; 612 613 if (nlm_do_unlock(argp, &res4, rqstp, &rpc)) 614 return (FALSE); 615 if (rpc) { 616 nlm4_unlock_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv); 617 CLNT_RELEASE(rpc); 618 } 619 xdr_free((xdrproc_t) xdr_nlm4_res, &res4); 620 621 return (FALSE); 622} 623 624bool_t 625nlm4_granted_msg_4_svc(nlm4_testargs *argp, void *result, struct svc_req *rqstp) 626{ 627 nlm4_res res4; 628 CLIENT *rpc; 629 char dummy; 630 631 if (nlm_do_granted(argp, &res4, rqstp, &rpc)) 632 return (FALSE); 633 if (rpc) { 634 nlm4_granted_res_4(&res4, &dummy, rpc, NULL, nlm_zero_tv); 635 CLNT_RELEASE(rpc); 636 } 637 xdr_free((xdrproc_t) xdr_nlm4_res, &res4); 638 639 return (FALSE); 640} 641 642bool_t 643nlm4_test_res_4_svc(nlm4_testres *argp, void *result, struct svc_req *rqstp) 644{ 645 646 return (FALSE); 647} 648 649bool_t 650nlm4_lock_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp) 651{ 652 653 return (FALSE); 654} 655 656bool_t 657nlm4_cancel_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp) 658{ 659 660 return (FALSE); 661} 662 663bool_t 664nlm4_unlock_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp) 665{ 666 667 return (FALSE); 668} 669 670bool_t 671nlm4_granted_res_4_svc(nlm4_res *argp, void *result, struct svc_req *rqstp) 672{ 673 674 nlm_do_granted_res(argp, rqstp); 675 return (FALSE); 676} 677 678bool_t 679nlm4_share_4_svc(nlm4_shareargs *argp, nlm4_shareres *result, struct svc_req *rqstp) 680{ 681 682 memset(result, 0, sizeof(*result)); 683 result->stat = nlm4_denied; 684 return (TRUE); 685} 686 687bool_t 688nlm4_unshare_4_svc(nlm4_shareargs *argp, nlm4_shareres *result, struct svc_req *rqstp) 689{ 690 691 memset(result, 0, sizeof(*result)); 692 result->stat = nlm4_denied; 693 return (TRUE); 694} 695 696bool_t 697nlm4_nm_lock_4_svc(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp) 698{ 699 700 nlm_do_lock(argp, result, rqstp, FALSE, NULL); 701 return (TRUE); 702} 703 704bool_t 705nlm4_free_all_4_svc(nlm4_notify *argp, void *result, struct svc_req *rqstp) 706{ 707 708 nlm_do_free_all(argp); 709 return (TRUE); 710} 711 712int 713nlm_prog_4_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result) 714{ 715 716 (void) xdr_free(xdr_result, result); 717 return (TRUE); 718} 719