Initial support for NSM
[deb_libnfs.git] / nsm / nsm.c
1 /*
2 Copyright (C) 2013 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-nsm.h"
29
30 int rpc_nsm1_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, NSM_PROGRAM, NSM_V1, NSM1_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 nsm/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 nsm/null call");
42 rpc_free_pdu(rpc, pdu);
43 return -1;
44 }
45
46 return 0;
47 }
48
49 #if 0
50 int 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, (zdrproc_t)zdr_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 (zdr_NLM4_TESTargs(&pdu->zdr, args) == 0) {
61 rpc_set_error(rpc, "ZDR 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
75 int rpc_nlm4_lock_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_LOCKargs *args, void *private_data)
76 {
77 struct rpc_pdu *pdu;
78
79 pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_LOCK, cb, private_data, (zdrproc_t)zdr_NLM4_LOCKres, sizeof(NLM4_LOCKres));
80 if (pdu == NULL) {
81 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/lock call");
82 return -1;
83 }
84
85 if (zdr_NLM4_LOCKargs(&pdu->zdr, args) == 0) {
86 rpc_set_error(rpc, "ZDR error: Failed to encode NLM4_LOCKargs");
87 rpc_free_pdu(rpc, pdu);
88 return -2;
89 }
90
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);
94 return -1;
95 }
96
97 return 0;
98 }
99
100 int rpc_nlm4_cancel_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_CANCargs *args, void *private_data)
101 {
102 struct rpc_pdu *pdu;
103
104 pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_CANCEL, cb, private_data, (zdrproc_t)zdr_NLM4_CANCres, sizeof(NLM4_CANCres));
105 if (pdu == NULL) {
106 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/cancel call");
107 return -1;
108 }
109
110 if (zdr_NLM4_CANCargs(&pdu->zdr, args) == 0) {
111 rpc_set_error(rpc, "ZDR error: Failed to encode NLM4_CANCargs");
112 rpc_free_pdu(rpc, pdu);
113 return -2;
114 }
115
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);
119 return -1;
120 }
121
122 return 0;
123 }
124
125 int rpc_nlm4_unlock_async(struct rpc_context *rpc, rpc_cb cb, struct NLM4_UNLOCKargs *args, void *private_data)
126 {
127 struct rpc_pdu *pdu;
128
129 pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_UNLOCK, cb, private_data, (zdrproc_t)zdr_NLM4_UNLOCKres, sizeof(NLM4_UNLOCKres));
130 if (pdu == NULL) {
131 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/unlock call");
132 return -1;
133 }
134
135 if (zdr_NLM4_UNLOCKargs(&pdu->zdr, args) == 0) {
136 rpc_set_error(rpc, "ZDR error: Failed to encode NLM4_UNLOCKargs");
137 rpc_free_pdu(rpc, pdu);
138 return -2;
139 }
140
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);
144 return -1;
145 }
146
147 return 0;
148 }
149 #endif
150
151 char *nsmstat1_to_str(int st)
152 {
153 enum nsmstat1 stat = st;
154
155 char *str = "unknown n1m stat";
156 switch (stat) {
157 case NSM_STAT_SUCC: str="NSM_STAT_SUCC";break;
158 case NSM_STAT_FAIL: str="NSM_STAT_FAIL";break;
159 }
160 return str;
161 }