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