1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Network lock manager protocol definition
  24  * Copyright (C) 1986, 1992, 1993, 1997, 1999 by Sun Microsystems, Inc.
  25  * All rights reserved.
  26  *
  27  * Protocol used between local lock manager and remote lock manager.
  28  *
  29  * There are currently 3 versions of the protocol in use.  Versions 1
  30  * and 3 are used with NFS version 2.  Version 4 is used with NFS
  31  * version 3.
  32  *
  33  * (Note: there is also a version 2, but it defines an orthogonal set of
  34  * procedures that the status monitor uses to notify the lock manager of
  35  * changes in monitored systems.)
  36  */
  37 
  38 %#pragma ident  "%Z%%M% %I%     %E% SMI"
  39 
  40 #if RPC_HDR
  41 %
  42 %#include <rpc/rpc_sztypes.h>
  43 %
  44 #endif
  45 
  46 #ifdef RPC_HDR
  47 %#define LM_MAXSTRLEN   1024
  48 %#define LM_MAXNAMELEN  (LM_MAXSTRLEN + 1)
  49 #endif
  50 
  51 /*
  52  * Types for versions 1 and 3.
  53  */
  54 
  55 /*
  56  * Status of a call to the lock manager.  The lower case enums violate the
  57  * current style guide, but we're stuck with 'em.
  58  */
  59 
  60 enum nlm_stats {
  61         nlm_granted = 0,
  62         nlm_denied = 1,
  63         nlm_denied_nolocks = 2,
  64         nlm_blocked = 3,
  65         nlm_denied_grace_period = 4,
  66         nlm_deadlck = 5
  67 };
  68 
  69 /*
  70  * The holder of a conflicting lock.
  71  */
  72 
  73 struct nlm_holder {
  74         bool exclusive;
  75         int svid;
  76         netobj oh;
  77         unsigned l_offset;
  78         unsigned l_len;
  79 };
  80 
  81 union nlm_testrply switch (nlm_stats stat) {
  82         case nlm_denied:
  83                 struct nlm_holder holder;
  84         default:
  85                 void;
  86 };
  87 
  88 struct nlm_stat {
  89         nlm_stats stat;
  90 };
  91 
  92 struct nlm_res {
  93         netobj cookie;
  94         nlm_stat stat;
  95 };
  96 
  97 struct nlm_testres {
  98         netobj cookie;
  99         nlm_testrply stat;
 100 };
 101 
 102 struct nlm_lock {
 103         string caller_name<LM_MAXSTRLEN>;
 104         netobj fh;              /* identify a file */
 105         netobj oh;              /* identify owner of a lock */
 106         int svid;               /* generated from pid for svid */
 107         unsigned l_offset;
 108         unsigned l_len;
 109 };
 110 
 111 struct nlm_lockargs {
 112         netobj cookie;
 113         bool block;
 114         bool exclusive;
 115         struct nlm_lock alock;
 116         bool reclaim;           /* used for recovering locks */
 117         int state;              /* specify local status monitor state */
 118 };
 119 
 120 struct nlm_cancargs {
 121         netobj cookie;
 122         bool block;
 123         bool exclusive;
 124         struct nlm_lock alock;
 125 };
 126 
 127 struct nlm_testargs {
 128         netobj cookie;
 129         bool exclusive;
 130         struct nlm_lock alock;
 131 };
 132 
 133 struct nlm_unlockargs {
 134         netobj cookie;
 135         struct nlm_lock alock;
 136 };
 137 
 138 #ifdef RPC_HDR
 139 %/*
 140 % * The following enums are actually bit encoded for efficient
 141 % * boolean algebra.... DON'T change them.....
 142 % * The mixed-case enums violate the present style guide, but we're
 143 % * stuck with 'em.
 144 % */
 145 #endif
 146 
 147 enum    fsh_mode {
 148         fsm_DN  = 0,    /* deny none */
 149         fsm_DR  = 1,    /* deny read */
 150         fsm_DW  = 2,    /* deny write */
 151         fsm_DRW = 3     /* deny read/write */
 152 };
 153 
 154 enum    fsh_access {
 155         fsa_NONE = 0,   /* for completeness */
 156         fsa_R    = 1,   /* read only */
 157         fsa_W    = 2,   /* write only */
 158         fsa_RW   = 3    /* read/write */
 159 };
 160 
 161 struct  nlm_share {
 162         string caller_name<LM_MAXSTRLEN>;
 163         netobj  fh;
 164         netobj  oh;
 165         fsh_mode        mode;
 166         fsh_access      access;
 167 };
 168 
 169 struct  nlm_shareargs {
 170         netobj  cookie;
 171         nlm_share       share;
 172         bool    reclaim;
 173 };
 174 
 175 struct  nlm_shareres {
 176         netobj  cookie;
 177         nlm_stats       stat;
 178         int     sequence;
 179 };
 180 
 181 struct  nlm_notify {
 182         string name<LM_MAXNAMELEN>;
 183         int state;
 184 };
 185 
 186 /*
 187  * Types for version 4.
 188  *
 189  * This revision is designed to work with NFS V3.  The main changes from
 190  * NFS V2 to V3 that affect the NLM protocol are that all file offsets
 191  * and sizes are now unsigned 64-bit ints, and file handles are now
 192  * variable length.  In NLM V1 and V3, the fixed-length V2 file handle
 193  * was encoded as a 'netobj', which is a count followed by the data
 194  * bytes.  For NLM 4, the file handle is already a count followed by
 195  * data bytes, so the handle is copied directly into the netobj, rather
 196  * than being encoded with an additional byte count.
 197  */
 198 
 199 /*
 200  * Status of a call to the lock manager.
 201  */
 202 
 203 enum nlm4_stats {
 204         NLM4_GRANTED = 0,               /* lock was granted */
 205         NLM4_DENIED = 1,                /* lock was not granted, usually */
 206                                         /* due to conflicting lock */
 207         NLM4_DENIED_NOLOCKS = 2,        /* not granted: out of resources */
 208         NLM4_BLOCKED = 3,               /* not granted: expect callback */
 209                                         /* when granted */
 210         NLM4_DENIED_GRACE_PERIOD = 4,   /* not granted: server is */
 211                                         /* reestablishing old locks */
 212         NLM4_DEADLCK = 5,               /* not granted: deadlock detected */
 213         NLM4_ROFS = 6,                  /* not granted: read-only filesystem */
 214         NLM4_STALE_FH = 7,              /* not granted: stale file handle */
 215         NLM4_FBIG = 8,                  /* not granted: offset or length */
 216                                         /* too big */
 217         NLM4_FAILED = 9                 /* not granted: some other error */
 218 };
 219 
 220 /*
 221  * The holder of a conflicting lock.
 222  */
 223 
 224 struct nlm4_holder {
 225         bool exclusive;
 226         int32 svid;
 227         netobj oh;
 228         uint64 l_offset;
 229         uint64 l_len;
 230 };
 231 
 232 union nlm4_testrply switch (nlm4_stats stat) {
 233         case NLM4_DENIED:
 234                 struct nlm4_holder holder;
 235         default:
 236                 void;
 237 };
 238 
 239 struct nlm4_stat {
 240         nlm4_stats stat;
 241 };
 242 
 243 struct nlm4_res {
 244         netobj cookie;
 245         nlm4_stat stat;
 246 };
 247 
 248 struct nlm4_testres {
 249         netobj cookie;
 250         nlm4_testrply stat;
 251 };
 252 
 253 struct nlm4_lock {
 254         string caller_name<LM_MAXSTRLEN>;
 255         netobj fh;              /* identify a file */
 256         netobj oh;              /* identify owner of a lock */
 257         int32 svid;             /* generated from pid for svid */
 258         uint64 l_offset;
 259         uint64 l_len;
 260 };
 261 
 262 struct nlm4_lockargs {
 263         netobj cookie;
 264         bool block;
 265         bool exclusive;
 266         struct nlm4_lock alock;
 267         bool reclaim;           /* used for recovering locks */
 268         int32 state;            /* specify local status monitor state */
 269 };
 270 
 271 struct nlm4_cancargs {
 272         netobj cookie;
 273         bool block;
 274         bool exclusive;
 275         struct nlm4_lock alock;
 276 };
 277 
 278 struct nlm4_testargs {
 279         netobj cookie;
 280         bool exclusive;
 281         struct nlm4_lock alock;
 282 };
 283 
 284 struct nlm4_unlockargs {
 285         netobj cookie;
 286         struct nlm4_lock alock;
 287 };
 288 
 289 #ifdef RPC_HDR
 290 %/*
 291 % * The following enums are actually bit encoded for efficient
 292 % * boolean algebra.... DON'T change them.....
 293 % */
 294 #endif
 295 
 296 enum    fsh4_mode {
 297         FSM_DN  = 0,    /* deny none */
 298         FSM_DR  = 1,    /* deny read */
 299         FSM_DW  = 2,    /* deny write */
 300         FSM_DRW = 3     /* deny read/write */
 301 };
 302 
 303 enum    fsh4_access {
 304         FSA_NONE = 0,   /* for completeness */
 305         FSA_R    = 1,   /* read only */
 306         FSA_W    = 2,   /* write only */
 307         FSA_RW   = 3    /* read/write */
 308 };
 309 
 310 struct  nlm4_share {
 311         string caller_name<LM_MAXSTRLEN>;
 312         netobj  fh;
 313         netobj  oh;
 314         fsh4_mode       mode;
 315         fsh4_access     access;
 316 };
 317 
 318 struct  nlm4_shareargs {
 319         netobj  cookie;
 320         nlm4_share      share;
 321         bool    reclaim;
 322 };
 323 
 324 struct  nlm4_shareres {
 325         netobj  cookie;
 326         nlm4_stats      stat;
 327         int32   sequence;
 328 };
 329 
 330 struct  nlm4_notify {
 331         string name<LM_MAXNAMELEN>;
 332         int32 state;
 333 };
 334 
 335 /*
 336  * Over-the-wire protocol used between the network lock managers
 337  */
 338 
 339 program NLM_PROG {
 340         version NLM_VERS {
 341 
 342                 nlm_testres
 343                         NLM_TEST(nlm_testargs) =                1;
 344 
 345                 nlm_res
 346                         NLM_LOCK(nlm_lockargs) =                2;
 347 
 348                 nlm_res
 349                         NLM_CANCEL(nlm_cancargs) =              3;
 350 
 351                 nlm_res
 352                         NLM_UNLOCK(nlm_unlockargs) =            4;
 353                 /*
 354                  * remote lock manager call-back to grant lock
 355                  */
 356                 nlm_res
 357                         NLM_GRANTED(nlm_testargs) =             5;
 358 
 359                 /*
 360                  * message passing style of requesting lock
 361                  */
 362 
 363                 void
 364                         NLM_TEST_MSG(nlm_testargs) =            6;
 365                 void
 366                         NLM_LOCK_MSG(nlm_lockargs) =            7;
 367                 void
 368                         NLM_CANCEL_MSG(nlm_cancargs) =          8;
 369                 void
 370                         NLM_UNLOCK_MSG(nlm_unlockargs) =        9;
 371                 void
 372                         NLM_GRANTED_MSG(nlm_testargs) =         10;
 373                 void
 374                         NLM_TEST_RES(nlm_testres) =             11;
 375                 void
 376                         NLM_LOCK_RES(nlm_res) =                 12;
 377                 void
 378                         NLM_CANCEL_RES(nlm_res) =               13;
 379                 void
 380                         NLM_UNLOCK_RES(nlm_res) =               14;
 381                 void
 382                         NLM_GRANTED_RES(nlm_res) =              15;
 383         } = 1;
 384 
 385         version NLM_VERSX {
 386                 nlm_shareres
 387                         NLM_SHARE(nlm_shareargs) =              20;
 388                 nlm_shareres
 389                         NLM_UNSHARE(nlm_shareargs) =            21;
 390                 nlm_res
 391                         NLM_NM_LOCK(nlm_lockargs) =             22;
 392                 void
 393                         NLM_FREE_ALL(nlm_notify) =              23;
 394         } = 3;
 395 
 396         version NLM4_VERS {
 397                 void
 398                         NLMPROC4_NULL(void) =                   0;
 399                 nlm4_testres
 400                         NLMPROC4_TEST(nlm4_testargs) =          1;
 401                 nlm4_res
 402                         NLMPROC4_LOCK(nlm4_lockargs) =          2;
 403                 nlm4_res
 404                         NLMPROC4_CANCEL(nlm4_cancargs) =        3;
 405                 nlm4_res
 406                         NLMPROC4_UNLOCK(nlm4_unlockargs) =      4;
 407                 /*
 408                  * remote lock manager call-back to grant lock
 409                  */
 410                 nlm4_res
 411                         NLMPROC4_GRANTED(nlm4_testargs) =       5;
 412 
 413                 /*
 414                  * message passing style of requesting lock
 415                  */
 416 
 417                 void
 418                         NLMPROC4_TEST_MSG(nlm4_testargs) =      6;
 419                 void
 420                         NLMPROC4_LOCK_MSG(nlm4_lockargs) =      7;
 421                 void
 422                         NLMPROC4_CANCEL_MSG(nlm4_cancargs) =    8;
 423                 void
 424                         NLMPROC4_UNLOCK_MSG(nlm4_unlockargs) =  9;
 425                 void
 426                         NLMPROC4_GRANTED_MSG(nlm4_testargs) =   10;
 427                 void
 428                         NLMPROC4_TEST_RES(nlm4_testres) =       11;
 429                 void
 430                         NLMPROC4_LOCK_RES(nlm4_res) =           12;
 431                 void
 432                         NLMPROC4_CANCEL_RES(nlm4_res) =         13;
 433                 void
 434                         NLMPROC4_UNLOCK_RES(nlm4_res) =         14;
 435                 void
 436                         NLMPROC4_GRANTED_RES(nlm4_res) =        15;
 437 
 438                 /*
 439                  * DOS-style file sharing
 440                  */
 441 
 442                 nlm4_shareres
 443                         NLMPROC4_SHARE(nlm4_shareargs) =        20;
 444                 nlm4_shareres
 445                         NLMPROC4_UNSHARE(nlm4_shareargs) =      21;
 446                 nlm4_res
 447                         NLMPROC4_NM_LOCK(nlm4_lockargs) =       22;
 448                 void
 449                         NLMPROC4_FREE_ALL(nlm4_notify) =        23;
 450         } = 4;
 451 
 452 } = 100021;