xref: /openbsd/lib/librpcsvc/klm_prot.x (revision cb7760d1)
1 /*	$OpenBSD: klm_prot.x,v 1.6 2010/09/01 14:43:34 millert Exp $	*/
2 
3 /*
4  * Copyright (c) 2010, Oracle America, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above
13  *       copyright notice, this list of conditions and the following
14  *       disclaimer in the documentation and/or other materials
15  *       provided with the distribution.
16  *     * Neither the name of the "Oracle America, Inc." nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Kernel/lock manager protocol definition
36  *
37  * protocol used between the UNIX kernel (the "client") and the
38  * local lock manager.  The local lock manager is a daemon running
39  * above the kernel.
40  */
41 
42 #ifndef RPC_HDR
43 #endif
44 
45 const	LM_MAXSTRLEN = 1024;
46 
47 /*
48  * lock manager status returns
49  */
50 enum klm_stats {
51 	klm_granted = 0,	/* lock is granted */
52 	klm_denied = 1,		/* lock is denied */
53 	klm_denied_nolocks = 2, /* no lock entry available */
54 	klm_working = 3	/* lock is being processed */
55 };
56 
57 /*
58  * lock manager lock identifier
59  */
60 struct klm_lock {
61 	string server_name<LM_MAXSTRLEN>;
62 	netobj fh;		/* a counted file handle */
63 	int pid;		/* holder of the lock */
64 	unsigned l_offset;	/* beginning offset of the lock */
65 	unsigned l_len;		/* byte length of the lock;
66 				 * zero means through end of file */
67 };
68 
69 /*
70  * lock holder identifier
71  */
72 struct klm_holder {
73 	bool exclusive;		/* FALSE if shared lock */
74 	int svid;		/* holder of the lock (pid) */
75 	unsigned l_offset;	/* beginning offset of the lock */
76 	unsigned l_len;		/* byte length of the lock;
77 				 * zero means through end of file */
78 };
79 
80 /*
81  * reply to KLM_LOCK / KLM_UNLOCK / KLM_CANCEL
82  */
83 struct klm_stat {
84 	klm_stats stat;
85 };
86 
87 /*
88  * reply to a KLM_TEST call
89  */
90 union klm_testrply switch (klm_stats stat) {
91 	case klm_denied:
92 		struct klm_holder holder;
93 	default: /* All other cases return no arguments */
94 		void;
95 };
96 
97 
98 /*
99  * arguments to KLM_LOCK
100  */
101 struct klm_lockargs {
102 	bool block;
103 	bool exclusive;
104 	struct klm_lock alock;
105 };
106 
107 /*
108  * arguments to KLM_TEST
109  */
110 struct klm_testargs {
111 	bool exclusive;
112 	struct klm_lock alock;
113 };
114 
115 /*
116  * arguments to KLM_UNLOCK
117  */
118 struct klm_unlockargs {
119 	struct klm_lock alock;
120 };
121 
122 program KLM_PROG {
123 	version KLM_VERS {
124 
125 		klm_testrply	KLM_TEST (struct klm_testargs) =	1;
126 
127 		klm_stat	KLM_LOCK (struct klm_lockargs) =	2;
128 
129 		klm_stat	KLM_CANCEL (struct klm_lockargs) =	3;
130 		/* klm_granted=> the cancel request fails due to lock is already granted */
131 		/* klm_denied=> the cancel request successfully aborts
132 lock request  */
133 
134 		klm_stat	KLM_UNLOCK (struct klm_unlockargs) =	4;
135 	} = 1;
136 } = 100020;
137