NLM: add UNLOCK call
[deb_libnfs.git] / nlm / nlm.c
CommitLineData
6916a665
RS
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 <rpc/rpc.h>
25#include <rpc/xdr.h>
26#include "libnfs.h"
27#include "libnfs-raw.h"
28#include "libnfs-private.h"
29#include "libnfs-raw-nlm.h"
30
e01ed6a2 31int rpc_nlm4_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
6916a665
RS
32{
33 struct rpc_pdu *pdu;
34
35 pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
36 if (pdu == NULL) {
37 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/null call");
38 return -1;
39 }
40
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);
44 return -1;
45 }
46
47 return 0;
48}
49
e01ed6a2
RS
50int rpc_nlm4_test_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_TESTargs *args, void *private_data)
51{
52 struct rpc_pdu *pdu;
53
54 pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_TEST, cb, private_data, (xdrproc_t)xdr_NLM4_TESTres, sizeof(NLM4_TESTres));
55 if (pdu == NULL) {
56 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/test call");
57 return -1;
58 }
59
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);
63 return -2;
64 }
65
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);
69 return -1;
70 }
71
72 return 0;
73}
74
6916a665
RS
75char *nlmstat4_to_str(int st)
76{
77 enum nlmstat4 stat = st;
78
79 char *str = "unknown nlm stat";
80 switch (stat) {
81 case NLM4_GRANTED: str="NLM4_GRANTED";break;
82 case NLM4_DENIED: str="NLM4_DENIED";break;
83 case NLM4_DENIED_NOLOCKS: str="NLM4_DENIED_NOLOCKS";break;
84 case NLM4_BLOCKED: str="NLM4_BLOCKED";break;
85 case NLM4_DENIED_GRACE_PERIOD: str="NLM4_DENIED_GRACE_PERIOD";break;
86 case NLM4_DEADLCK: str="NLM4_DEADLCK";break;
87 case NLM4_ROFS: str="NLM4_ROFS";break;
88 case NLM4_STALE_FH: str="NLM4_STALE_FH";break;
89 case NLM4_FBIG: str="NLM4_FBIG";break;
90 case NLM4_FAILED: str="NLM4_FAILED";break;
91 }
92 return str;
93}
94
95
96
97