Add myself for packaging copyright and some minor tweaks
[deb_libnfs.git] / nlm / nlm.c
... / ...
CommitLineData
1/*
2 Copyright (C) 2012 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifdef WIN32
19#include "win32_compat.h"
20#endif/*WIN32*/
21
22#include <stdio.h>
23#include <errno.h>
24#include "libnfs-zdr.h"
25#include "libnfs.h"
26#include "libnfs-raw.h"
27#include "libnfs-private.h"
28#include "libnfs-raw-nlm.h"
29
30int rpc_nlm4_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
31{
32 struct rpc_pdu *pdu;
33
34 pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_NULL, cb, private_data, (zdrproc_t)zdr_void, 0);
35 if (pdu == NULL) {
36 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/null call");
37 return -1;
38 }
39
40 if (rpc_queue_pdu(rpc, pdu) != 0) {
41 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nlm/null call");
42 rpc_free_pdu(rpc, pdu);
43 return -1;
44 }
45
46 return 0;
47}
48
49int rpc_nlm4_test_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_TESTargs *args, void *private_data)
50{
51 struct rpc_pdu *pdu;
52
53 pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_TEST, cb, private_data, (zdrproc_t)zdr_NLM4_TESTres, sizeof(NLM4_TESTres));
54 if (pdu == NULL) {
55 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/test call");
56 return -1;
57 }
58
59 if (zdr_NLM4_TESTargs(&pdu->zdr, args) == 0) {
60 rpc_set_error(rpc, "ZDR error: Failed to encode NLM4_TESTargs");
61 rpc_free_pdu(rpc, pdu);
62 return -2;
63 }
64
65 if (rpc_queue_pdu(rpc, pdu) != 0) {
66 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nlm/test call");
67 rpc_free_pdu(rpc, pdu);
68 return -1;
69 }
70
71 return 0;
72}
73
74int rpc_nlm4_lock_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_LOCKargs *args, void *private_data)
75{
76 struct rpc_pdu *pdu;
77
78 pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_LOCK, cb, private_data, (zdrproc_t)zdr_NLM4_LOCKres, sizeof(NLM4_LOCKres));
79 if (pdu == NULL) {
80 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/lock call");
81 return -1;
82 }
83
84 if (zdr_NLM4_LOCKargs(&pdu->zdr, args) == 0) {
85 rpc_set_error(rpc, "ZDR error: Failed to encode NLM4_LOCKargs");
86 rpc_free_pdu(rpc, pdu);
87 return -2;
88 }
89
90 if (rpc_queue_pdu(rpc, pdu) != 0) {
91 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nlm/lock call");
92 rpc_free_pdu(rpc, pdu);
93 return -1;
94 }
95
96 return 0;
97}
98
99int rpc_nlm4_cancel_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_CANCargs *args, void *private_data)
100{
101 struct rpc_pdu *pdu;
102
103 pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_CANCEL, cb, private_data, (zdrproc_t)zdr_NLM4_CANCres, sizeof(NLM4_CANCres));
104 if (pdu == NULL) {
105 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/cancel call");
106 return -1;
107 }
108
109 if (zdr_NLM4_CANCargs(&pdu->zdr, args) == 0) {
110 rpc_set_error(rpc, "ZDR error: Failed to encode NLM4_CANCargs");
111 rpc_free_pdu(rpc, pdu);
112 return -2;
113 }
114
115 if (rpc_queue_pdu(rpc, pdu) != 0) {
116 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nlm/cancel call");
117 rpc_free_pdu(rpc, pdu);
118 return -1;
119 }
120
121 return 0;
122}
123
124int rpc_nlm4_unlock_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_UNLOCKargs *args, void *private_data)
125{
126 struct rpc_pdu *pdu;
127
128 pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_UNLOCK, cb, private_data, (zdrproc_t)zdr_NLM4_UNLOCKres, sizeof(NLM4_UNLOCKres));
129 if (pdu == NULL) {
130 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/unlock call");
131 return -1;
132 }
133
134 if (zdr_NLM4_UNLOCKargs(&pdu->zdr, args) == 0) {
135 rpc_set_error(rpc, "ZDR error: Failed to encode NLM4_UNLOCKargs");
136 rpc_free_pdu(rpc, pdu);
137 return -2;
138 }
139
140 if (rpc_queue_pdu(rpc, pdu) != 0) {
141 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nlm/unlock call");
142 rpc_free_pdu(rpc, pdu);
143 return -1;
144 }
145
146 return 0;
147}
148
149char *nlmstat4_to_str(int st)
150{
151 enum nlmstat4 stat = st;
152
153 char *str = "unknown nlm stat";
154 switch (stat) {
155 case NLM4_GRANTED: str="NLM4_GRANTED";break;
156 case NLM4_DENIED: str="NLM4_DENIED";break;
157 case NLM4_DENIED_NOLOCKS: str="NLM4_DENIED_NOLOCKS";break;
158 case NLM4_BLOCKED: str="NLM4_BLOCKED";break;
159 case NLM4_DENIED_GRACE_PERIOD: str="NLM4_DENIED_GRACE_PERIOD";break;
160 case NLM4_DEADLCK: str="NLM4_DEADLCK";break;
161 case NLM4_ROFS: str="NLM4_ROFS";break;
162 case NLM4_STALE_FH: str="NLM4_STALE_FH";break;
163 case NLM4_FBIG: str="NLM4_FBIG";break;
164 case NLM4_FAILED: str="NLM4_FAILED";break;
165 }
166 return str;
167}
168
169
170
171