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/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
rpc_nsm1_null_async(struct rpc_context * rpc,rpc_cb cb,void * private_data)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 return -1;
43 }
44
45 return 0;
46 }
47
rpc_nsm1_stat_async(struct rpc_context * rpc,rpc_cb cb,struct NSM1_STATargs * args,void * private_data)48 int rpc_nsm1_stat_async(struct rpc_context *rpc, rpc_cb cb, struct NSM1_STATargs *args, void *private_data)
49 {
50 struct rpc_pdu *pdu;
51
52 pdu = rpc_allocate_pdu(rpc, NSM_PROGRAM, NSM_V1, NSM1_STAT, cb, private_data, (zdrproc_t)zdr_NSM1_STATres, sizeof(NSM1_STATres));
53 if (pdu == NULL) {
54 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nsm/stat call");
55 return -1;
56 }
57
58 if (zdr_NSM1_STATargs(&pdu->zdr, args) == 0) {
59 rpc_set_error(rpc, "ZDR error: Failed to encode NSM1_STATargs");
60 rpc_free_pdu(rpc, pdu);
61 return -2;
62 }
63
64 if (rpc_queue_pdu(rpc, pdu) != 0) {
65 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nsm/stat call");
66 return -1;
67 }
68
69 return 0;
70 }
71
rpc_nsm1_mon_async(struct rpc_context * rpc,rpc_cb cb,struct NSM1_MONargs * args,void * private_data)72 int rpc_nsm1_mon_async(struct rpc_context *rpc, rpc_cb cb, struct NSM1_MONargs *args, void *private_data)
73 {
74 struct rpc_pdu *pdu;
75
76 pdu = rpc_allocate_pdu(rpc, NSM_PROGRAM, NSM_V1, NSM1_MON, cb, private_data, (zdrproc_t)zdr_NSM1_MONres, sizeof(NSM1_MONres));
77 if (pdu == NULL) {
78 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nsm/mon call");
79 return -1;
80 }
81
82 if (zdr_NSM1_MONargs(&pdu->zdr, args) == 0) {
83 rpc_set_error(rpc, "ZDR error: Failed to encode NSM1_MONargs");
84 rpc_free_pdu(rpc, pdu);
85 return -2;
86 }
87
88 if (rpc_queue_pdu(rpc, pdu) != 0) {
89 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nsm/mon call");
90 return -1;
91 }
92
93 return 0;
94 }
95
rpc_nsm1_unmon_async(struct rpc_context * rpc,rpc_cb cb,struct NSM1_UNMONargs * args,void * private_data)96 int rpc_nsm1_unmon_async(struct rpc_context *rpc, rpc_cb cb, struct NSM1_UNMONargs *args, void *private_data)
97 {
98 struct rpc_pdu *pdu;
99
100 pdu = rpc_allocate_pdu(rpc, NSM_PROGRAM, NSM_V1, NSM1_UNMON, cb, private_data, (zdrproc_t)zdr_NSM1_UNMONres, sizeof(NSM1_UNMONres));
101 if (pdu == NULL) {
102 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nsm/unmon call");
103 return -1;
104 }
105
106 if (zdr_NSM1_UNMONargs(&pdu->zdr, args) == 0) {
107 rpc_set_error(rpc, "ZDR error: Failed to encode NSM1_UNMONargs");
108 rpc_free_pdu(rpc, pdu);
109 return -2;
110 }
111
112 if (rpc_queue_pdu(rpc, pdu) != 0) {
113 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nsm/unmon call");
114 return -1;
115 }
116
117 return 0;
118 }
119
rpc_nsm1_unmonall_async(struct rpc_context * rpc,rpc_cb cb,struct NSM1_UNMONALLargs * args,void * private_data)120 int rpc_nsm1_unmonall_async(struct rpc_context *rpc, rpc_cb cb, struct NSM1_UNMONALLargs *args, void *private_data)
121 {
122 struct rpc_pdu *pdu;
123
124 pdu = rpc_allocate_pdu(rpc, NSM_PROGRAM, NSM_V1, NSM1_UNMON_ALL, cb, private_data, (zdrproc_t)zdr_NSM1_UNMONALLres, sizeof(NSM1_UNMONALLres));
125 if (pdu == NULL) {
126 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nsm/unmonall call");
127 return -1;
128 }
129
130 if (zdr_NSM1_UNMONALLargs(&pdu->zdr, args) == 0) {
131 rpc_set_error(rpc, "ZDR error: Failed to encode NSM1_UNMONALLargs");
132 rpc_free_pdu(rpc, pdu);
133 return -2;
134 }
135
136 if (rpc_queue_pdu(rpc, pdu) != 0) {
137 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nsm/unmonall call");
138 return -1;
139 }
140
141 return 0;
142 }
143
rpc_nsm1_simucrash_async(struct rpc_context * rpc,rpc_cb cb,void * private_data)144 int rpc_nsm1_simucrash_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
145 {
146 struct rpc_pdu *pdu;
147
148 pdu = rpc_allocate_pdu(rpc, NSM_PROGRAM, NSM_V1, NSM1_SIMU_CRASH, cb, private_data, (zdrproc_t)zdr_void, 0);
149 if (pdu == NULL) {
150 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nsm/simucrash call");
151 return -1;
152 }
153
154 if (rpc_queue_pdu(rpc, pdu) != 0) {
155 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nsm/simucrash call");
156 return -1;
157 }
158
159 return 0;
160 }
161
rpc_nsm1_notify_async(struct rpc_context * rpc,rpc_cb cb,struct NSM1_NOTIFYargs * args,void * private_data)162 int rpc_nsm1_notify_async(struct rpc_context *rpc, rpc_cb cb, struct NSM1_NOTIFYargs *args, void *private_data)
163 {
164 struct rpc_pdu *pdu;
165
166 pdu = rpc_allocate_pdu(rpc, NSM_PROGRAM, NSM_V1, NSM1_NOTIFY, cb, private_data, (zdrproc_t)zdr_void, 0);
167 if (pdu == NULL) {
168 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nsm/notify call");
169 return -1;
170 }
171
172 if (zdr_NSM1_NOTIFYargs(&pdu->zdr, args) == 0) {
173 rpc_set_error(rpc, "ZDR error: Failed to encode NSM1_NOTIFYargs");
174 rpc_free_pdu(rpc, pdu);
175 return -2;
176 }
177
178 if (rpc_queue_pdu(rpc, pdu) != 0) {
179 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nsm/notify call");
180 return -1;
181 }
182
183 return 0;
184 }
185
nsmstat1_to_str(int st)186 char *nsmstat1_to_str(int st)
187 {
188 enum nsmstat1 stat = st;
189
190 char *str = "unknown n1m stat";
191 switch (stat) {
192 case NSM_STAT_SUCC: str="NSM_STAT_SUCC";break;
193 case NSM_STAT_FAIL: str="NSM_STAT_FAIL";break;
194 }
195 return str;
196 }
197