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