2 Copyright (C) 2012 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
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.
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.
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/>.
19 #include "win32_compat.h"
27 #include "libnfs-raw.h"
28 #include "libnfs-private.h"
29 #include "libnfs-raw-nlm.h"
31 int rpc_nlm4_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
35 pdu
= rpc_allocate_pdu(rpc
, NLM_PROGRAM
, NLM_V4
, NLM4_NULL
, cb
, private_data
, (xdrproc_t
)xdr_void
, 0);
37 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nlm/null call");
41 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
42 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nlm/null call");
43 rpc_free_pdu(rpc
, pdu
);
50 int rpc_nlm4_test_async(struct rpc_context
*rpc
, rpc_cb cb
, struct NLM4_TESTargs
*args
, void *private_data
)
54 pdu
= rpc_allocate_pdu(rpc
, NLM_PROGRAM
, NLM_V4
, NLM4_TEST
, cb
, private_data
, (xdrproc_t
)xdr_NLM4_TESTres
, sizeof(NLM4_TESTres
));
56 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nlm/test call");
60 if (xdr_NLM4_TESTargs(&pdu
->xdr
, args
) == 0) {
61 rpc_set_error(rpc
, "XDR error: Failed to encode NLM4_TESTargs");
62 rpc_free_pdu(rpc
, pdu
);
66 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
67 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nlm/test call");
68 rpc_free_pdu(rpc
, pdu
);
75 int rpc_nlm4_lock_async(struct rpc_context
*rpc
, rpc_cb cb
, struct NLM4_LOCKargs
*args
, void *private_data
)
79 pdu
= rpc_allocate_pdu(rpc
, NLM_PROGRAM
, NLM_V4
, NLM4_LOCK
, cb
, private_data
, (xdrproc_t
)xdr_NLM4_LOCKres
, sizeof(NLM4_LOCKres
));
81 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nlm/lock call");
85 if (xdr_NLM4_LOCKargs(&pdu
->xdr
, args
) == 0) {
86 rpc_set_error(rpc
, "XDR error: Failed to encode NLM4_LOCKargs");
87 rpc_free_pdu(rpc
, pdu
);
91 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
92 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nlm/lock call");
93 rpc_free_pdu(rpc
, pdu
);
100 int rpc_nlm4_cancel_async(struct rpc_context
*rpc
, rpc_cb cb
, struct NLM4_CANCargs
*args
, void *private_data
)
104 pdu
= rpc_allocate_pdu(rpc
, NLM_PROGRAM
, NLM_V4
, NLM4_CANCEL
, cb
, private_data
, (xdrproc_t
)xdr_NLM4_CANCres
, sizeof(NLM4_CANCres
));
106 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nlm/cancel call");
110 if (xdr_NLM4_CANCargs(&pdu
->xdr
, args
) == 0) {
111 rpc_set_error(rpc
, "XDR error: Failed to encode NLM4_CANCargs");
112 rpc_free_pdu(rpc
, pdu
);
116 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
117 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nlm/cancel call");
118 rpc_free_pdu(rpc
, pdu
);
125 int rpc_nlm4_unlock_async(struct rpc_context
*rpc
, rpc_cb cb
, struct NLM4_UNLOCKargs
*args
, void *private_data
)
129 pdu
= rpc_allocate_pdu(rpc
, NLM_PROGRAM
, NLM_V4
, NLM4_UNLOCK
, cb
, private_data
, (xdrproc_t
)xdr_NLM4_UNLOCKres
, sizeof(NLM4_UNLOCKres
));
131 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nlm/unlock call");
135 if (xdr_NLM4_UNLOCKargs(&pdu
->xdr
, args
) == 0) {
136 rpc_set_error(rpc
, "XDR error: Failed to encode NLM4_UNLOCKargs");
137 rpc_free_pdu(rpc
, pdu
);
141 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
142 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nlm/unlock call");
143 rpc_free_pdu(rpc
, pdu
);
150 char *nlmstat4_to_str(int st
)
152 enum nlmstat4 stat
= st
;
154 char *str
= "unknown nlm stat";
156 case NLM4_GRANTED
: str
="NLM4_GRANTED";break;
157 case NLM4_DENIED
: str
="NLM4_DENIED";break;
158 case NLM4_DENIED_NOLOCKS
: str
="NLM4_DENIED_NOLOCKS";break;
159 case NLM4_BLOCKED
: str
="NLM4_BLOCKED";break;
160 case NLM4_DENIED_GRACE_PERIOD
: str
="NLM4_DENIED_GRACE_PERIOD";break;
161 case NLM4_DEADLCK
: str
="NLM4_DEADLCK";break;
162 case NLM4_ROFS
: str
="NLM4_ROFS";break;
163 case NLM4_STALE_FH
: str
="NLM4_STALE_FH";break;
164 case NLM4_FBIG
: str
="NLM4_FBIG";break;
165 case NLM4_FAILED
: str
="NLM4_FAILED";break;