Commit | Line | Data |
---|---|---|
84004dbf RS |
1 | /* |
2 | Copyright (C) 2010 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 | * High level api to nfs filesystems | |
19 | */ | |
20 | ||
7f0242ca | 21 | #define _GNU_SOURCE |
84004dbf | 22 | #include <stdio.h> |
1896d37b | 23 | #include <stdarg.h> |
84004dbf RS |
24 | #include <stdlib.h> |
25 | #include <string.h> | |
26 | #include <strings.h> | |
27 | #include <errno.h> | |
28 | #include <sys/types.h> | |
29 | #include <sys/stat.h> | |
30 | #include <sys/statvfs.h> | |
31 | #include <utime.h> | |
32 | #include <unistd.h> | |
33 | #include <fcntl.h> | |
34 | #include "libnfs.h" | |
35 | #include "libnfs-raw.h" | |
36 | #include "libnfs-raw-mount.h" | |
37 | #include "libnfs-raw-nfs.h" | |
1896d37b RS |
38 | #include "libnfs-private.h" |
39 | ||
40 | struct nfsdir { | |
41 | struct nfsdirent *entries; | |
42 | struct nfsdirent *current; | |
43 | }; | |
84004dbf RS |
44 | |
45 | struct nfsfh { | |
46 | struct nfs_fh3 fh; | |
47 | int is_sync; | |
48 | off_t offset; | |
49 | }; | |
50 | ||
1896d37b RS |
51 | struct nfs_context { |
52 | struct rpc_context *rpc; | |
53 | char *server; | |
54 | char *export; | |
55 | struct nfs_fh3 rootfh; | |
56 | size_t readmax; | |
57 | size_t writemax; | |
84004dbf RS |
58 | }; |
59 | ||
60 | void nfs_free_nfsdir(struct nfsdir *nfsdir) | |
61 | { | |
62 | while (nfsdir->entries) { | |
63 | struct nfsdirent *dirent = nfsdir->entries->next; | |
64 | if (nfsdir->entries->name != NULL) { | |
65 | free(nfsdir->entries->name); | |
66 | } | |
67 | free(nfsdir->entries); | |
68 | nfsdir->entries = dirent; | |
69 | } | |
70 | free(nfsdir); | |
71 | } | |
72 | ||
84004dbf RS |
73 | struct nfs_cb_data; |
74 | typedef int (*continue_func)(struct nfs_context *nfs, struct nfs_cb_data *data); | |
75 | ||
76 | struct nfs_cb_data { | |
77 | struct nfs_context *nfs; | |
78 | struct nfsfh *nfsfh; | |
79 | char *saved_path, *path; | |
80 | ||
81 | nfs_cb cb; | |
82 | void *private_data; | |
83 | ||
84 | continue_func continue_cb; | |
85 | void *continue_data; | |
86 | void (*free_continue_data)(void *); | |
87 | int continue_int; | |
88 | ||
89 | struct nfs_fh3 fh; | |
921f877b RS |
90 | |
91 | /* for multi-read/write calls. */ | |
92 | int error; | |
93 | int cancel; | |
94 | int num_calls; | |
95 | off_t start_offset, max_offset; | |
96 | char *buffer; | |
97 | }; | |
98 | ||
99 | struct nfs_mcb_data { | |
100 | struct nfs_cb_data *data; | |
101 | off_t offset; | |
102 | size_t count; | |
84004dbf RS |
103 | }; |
104 | ||
105 | static int nfs_lookup_path_async_internal(struct nfs_context *nfs, struct nfs_cb_data *data, struct nfs_fh3 *fh); | |
106 | ||
107 | ||
108 | void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth) | |
109 | { | |
be337389 | 110 | rpc_set_auth(nfs->rpc, auth); |
84004dbf RS |
111 | } |
112 | ||
113 | int nfs_get_fd(struct nfs_context *nfs) | |
114 | { | |
115 | return rpc_get_fd(nfs->rpc); | |
116 | } | |
117 | ||
118 | int nfs_which_events(struct nfs_context *nfs) | |
119 | { | |
120 | return rpc_which_events(nfs->rpc); | |
121 | } | |
122 | ||
123 | int nfs_service(struct nfs_context *nfs, int revents) | |
124 | { | |
125 | return rpc_service(nfs->rpc, revents); | |
126 | } | |
127 | ||
128 | char *nfs_get_error(struct nfs_context *nfs) | |
129 | { | |
130 | return rpc_get_error(nfs->rpc); | |
131 | }; | |
132 | ||
133 | struct nfs_context *nfs_init_context(void) | |
134 | { | |
135 | struct nfs_context *nfs; | |
136 | ||
137 | nfs = malloc(sizeof(struct nfs_context)); | |
138 | if (nfs == NULL) { | |
84004dbf RS |
139 | return NULL; |
140 | } | |
141 | nfs->rpc = rpc_init_context(); | |
142 | if (nfs->rpc == NULL) { | |
84004dbf RS |
143 | free(nfs); |
144 | return NULL; | |
145 | } | |
146 | ||
b077fdeb RS |
147 | nfs->server = NULL; |
148 | nfs->export = NULL; | |
149 | ||
963c2f83 RS |
150 | nfs->rootfh.data.data_len = 0; |
151 | nfs->rootfh.data.data_val = NULL; | |
152 | ||
84004dbf RS |
153 | return nfs; |
154 | } | |
155 | ||
156 | void nfs_destroy_context(struct nfs_context *nfs) | |
157 | { | |
158 | rpc_destroy_context(nfs->rpc); | |
159 | nfs->rpc = NULL; | |
160 | ||
161 | if (nfs->server) { | |
162 | free(nfs->server); | |
163 | nfs->server = NULL; | |
164 | } | |
165 | ||
166 | if (nfs->export) { | |
167 | free(nfs->export); | |
168 | nfs->export = NULL; | |
169 | } | |
170 | ||
171 | if (nfs->rootfh.data.data_val != NULL) { | |
172 | free(nfs->rootfh.data.data_val); | |
173 | nfs->rootfh.data.data_val = NULL; | |
174 | } | |
175 | ||
176 | free(nfs); | |
177 | } | |
178 | ||
179 | void free_nfs_cb_data(struct nfs_cb_data *data) | |
180 | { | |
181 | if (data->saved_path != NULL) { | |
182 | free(data->saved_path); | |
183 | data->saved_path = NULL; | |
184 | } | |
185 | ||
186 | if (data->continue_data != NULL) { | |
187 | data->free_continue_data(data->continue_data); | |
188 | data->continue_data = NULL; | |
189 | } | |
190 | ||
191 | if (data->fh.data.data_val != NULL) { | |
192 | free(data->fh.data.data_val); | |
193 | data->fh.data.data_val = NULL; | |
194 | } | |
195 | ||
921f877b RS |
196 | if (data->buffer != NULL) { |
197 | free(data->buffer); | |
198 | data->buffer = NULL; | |
199 | } | |
200 | ||
84004dbf RS |
201 | free(data); |
202 | } | |
203 | ||
204 | ||
205 | ||
206 | ||
207 | ||
17ef62fa | 208 | static void nfs_mount_10_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) |
84004dbf RS |
209 | { |
210 | struct nfs_cb_data *data = private_data; | |
211 | struct nfs_context *nfs = data->nfs; | |
212 | ||
213 | if (status == RPC_STATUS_ERROR) { | |
214 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
215 | free_nfs_cb_data(data); | |
216 | return; | |
217 | } | |
218 | if (status == RPC_STATUS_CANCEL) { | |
219 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
220 | free_nfs_cb_data(data); | |
221 | return; | |
222 | } | |
223 | ||
224 | data->cb(0, nfs, NULL, data->private_data); | |
225 | free_nfs_cb_data(data); | |
226 | } | |
227 | ||
17ef62fa | 228 | static void nfs_mount_9_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) |
84004dbf RS |
229 | { |
230 | struct nfs_cb_data *data = private_data; | |
231 | struct nfs_context *nfs = data->nfs; | |
17ef62fa | 232 | FSINFO3res *res = command_data; |
84004dbf RS |
233 | |
234 | if (status == RPC_STATUS_ERROR) { | |
235 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
236 | free_nfs_cb_data(data); | |
237 | return; | |
238 | } | |
239 | if (status == RPC_STATUS_CANCEL) { | |
240 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
241 | free_nfs_cb_data(data); | |
242 | return; | |
243 | } | |
244 | ||
17ef62fa RS |
245 | nfs->readmax = res->FSINFO3res_u.resok.rtmax; |
246 | nfs->writemax = res->FSINFO3res_u.resok.wtmax; | |
84004dbf | 247 | |
17ef62fa | 248 | if (rpc_nfs_getattr_async(rpc, nfs_mount_10_cb, &nfs->rootfh, data) != 0) { |
84004dbf RS |
249 | data->cb(-ENOMEM, nfs, command_data, data->private_data); |
250 | free_nfs_cb_data(data); | |
251 | return; | |
252 | } | |
253 | } | |
254 | ||
17ef62fa RS |
255 | static void nfs_mount_8_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) |
256 | { | |
257 | struct nfs_cb_data *data = private_data; | |
258 | struct nfs_context *nfs = data->nfs; | |
259 | ||
260 | if (status == RPC_STATUS_ERROR) { | |
261 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
262 | free_nfs_cb_data(data); | |
263 | return; | |
264 | } | |
265 | if (status == RPC_STATUS_CANCEL) { | |
266 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
267 | free_nfs_cb_data(data); | |
268 | return; | |
269 | } | |
270 | ||
271 | if (rpc_nfs_fsinfo_async(rpc, nfs_mount_9_cb, &nfs->rootfh, data) != 0) { | |
272 | data->cb(-ENOMEM, nfs, command_data, data->private_data); | |
273 | free_nfs_cb_data(data); | |
274 | return; | |
275 | } | |
276 | } | |
277 | ||
278 | ||
84004dbf RS |
279 | static void nfs_mount_7_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) |
280 | { | |
281 | struct nfs_cb_data *data = private_data; | |
282 | struct nfs_context *nfs = data->nfs; | |
283 | ||
284 | if (status == RPC_STATUS_ERROR) { | |
285 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
286 | free_nfs_cb_data(data); | |
287 | return; | |
288 | } | |
289 | if (status == RPC_STATUS_CANCEL) { | |
290 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
291 | free_nfs_cb_data(data); | |
292 | return; | |
293 | } | |
294 | ||
295 | if (rpc_nfs_null_async(rpc, nfs_mount_8_cb, data) != 0) { | |
296 | data->cb(-ENOMEM, nfs, command_data, data->private_data); | |
297 | free_nfs_cb_data(data); | |
298 | return; | |
299 | } | |
300 | } | |
301 | ||
302 | ||
303 | static void nfs_mount_6_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
304 | { | |
305 | struct nfs_cb_data *data = private_data; | |
306 | struct nfs_context *nfs = data->nfs; | |
307 | mountres3 *res; | |
308 | ||
309 | if (status == RPC_STATUS_ERROR) { | |
310 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
311 | free_nfs_cb_data(data); | |
312 | return; | |
313 | } | |
314 | if (status == RPC_STATUS_CANCEL) { | |
315 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
316 | free_nfs_cb_data(data); | |
317 | return; | |
318 | } | |
319 | ||
320 | res = command_data; | |
321 | if (res->fhs_status != MNT3_OK) { | |
322 | rpc_set_error(rpc, "RPC error: Mount failed with error %s(%d) %s(%d)", mountstat3_to_str(res->fhs_status), res->fhs_status, strerror(-mountstat3_to_errno(res->fhs_status)), -mountstat3_to_errno(res->fhs_status)); | |
323 | data->cb(mountstat3_to_errno(res->fhs_status), nfs, rpc_get_error(rpc), data->private_data); | |
324 | free_nfs_cb_data(data); | |
325 | return; | |
326 | } | |
327 | ||
328 | nfs->rootfh.data.data_len = res->mountres3_u.mountinfo.fhandle.fhandle3_len; | |
329 | nfs->rootfh.data.data_val = malloc(nfs->rootfh.data.data_len); | |
330 | if (nfs->rootfh.data.data_val == NULL) { | |
331 | rpc_set_error(rpc, "Out of memory. Could not allocate memory to store root filehandle"); | |
332 | data->cb(-ENOMEM, nfs, rpc_get_error(rpc), data->private_data); | |
333 | free_nfs_cb_data(data); | |
334 | return; | |
335 | } | |
336 | memcpy(nfs->rootfh.data.data_val, res->mountres3_u.mountinfo.fhandle.fhandle3_val, nfs->rootfh.data.data_len); | |
337 | ||
338 | rpc_disconnect(rpc, "normal disconnect"); | |
339 | if (rpc_connect_async(rpc, nfs->server, 2049, nfs_mount_7_cb, data) != 0) { | |
340 | data->cb(-ENOMEM, nfs, command_data, data->private_data); | |
341 | free_nfs_cb_data(data); | |
342 | return; | |
343 | } | |
344 | } | |
345 | ||
346 | ||
347 | static void nfs_mount_5_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
348 | { | |
349 | struct nfs_cb_data *data = private_data; | |
350 | struct nfs_context *nfs = data->nfs; | |
351 | ||
352 | if (status == RPC_STATUS_ERROR) { | |
353 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
354 | free_nfs_cb_data(data); | |
355 | return; | |
356 | } | |
357 | if (status == RPC_STATUS_CANCEL) { | |
358 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
359 | free_nfs_cb_data(data); | |
360 | return; | |
361 | } | |
362 | ||
363 | if (rpc_mount_mnt_async(rpc, nfs_mount_6_cb, nfs->export, data) != 0) { | |
364 | data->cb(-ENOMEM, nfs, command_data, data->private_data); | |
365 | free_nfs_cb_data(data); | |
366 | return; | |
367 | } | |
368 | } | |
369 | ||
370 | static void nfs_mount_4_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
371 | { | |
372 | struct nfs_cb_data *data = private_data; | |
373 | struct nfs_context *nfs = data->nfs; | |
374 | ||
375 | if (status == RPC_STATUS_ERROR) { | |
376 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
377 | free_nfs_cb_data(data); | |
378 | return; | |
379 | } | |
380 | if (status == RPC_STATUS_CANCEL) { | |
381 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
382 | free_nfs_cb_data(data); | |
383 | return; | |
384 | } | |
385 | ||
386 | if (rpc_mount_null_async(rpc, nfs_mount_5_cb, data) != 0) { | |
387 | data->cb(-ENOMEM, nfs, command_data, data->private_data); | |
388 | free_nfs_cb_data(data); | |
389 | return; | |
390 | } | |
391 | } | |
392 | ||
393 | static void nfs_mount_3_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
394 | { | |
395 | struct nfs_cb_data *data = private_data; | |
396 | struct nfs_context *nfs = data->nfs; | |
397 | uint32_t mount_port; | |
398 | ||
399 | if (status == RPC_STATUS_ERROR) { | |
400 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
401 | free_nfs_cb_data(data); | |
402 | return; | |
403 | } | |
404 | if (status == RPC_STATUS_CANCEL) { | |
405 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
406 | free_nfs_cb_data(data); | |
407 | return; | |
408 | } | |
409 | ||
410 | mount_port = *(uint32_t *)command_data; | |
411 | if (mount_port == 0) { | |
412 | rpc_set_error(rpc, "RPC error. Mount program is not available on %s", nfs->server); | |
413 | data->cb(-ENOENT, nfs, command_data, data->private_data); | |
414 | free_nfs_cb_data(data); | |
415 | return; | |
416 | } | |
417 | ||
418 | rpc_disconnect(rpc, "normal disconnect"); | |
419 | if (rpc_connect_async(rpc, nfs->server, mount_port, nfs_mount_4_cb, data) != 0) { | |
420 | data->cb(-ENOMEM, nfs, command_data, data->private_data); | |
421 | free_nfs_cb_data(data); | |
422 | return; | |
423 | } | |
424 | } | |
425 | ||
426 | ||
427 | static void nfs_mount_2_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
428 | { | |
429 | struct nfs_cb_data *data = private_data; | |
430 | struct nfs_context *nfs = data->nfs; | |
431 | ||
432 | if (status == RPC_STATUS_ERROR) { | |
433 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
434 | free_nfs_cb_data(data); | |
435 | return; | |
436 | } | |
437 | if (status == RPC_STATUS_CANCEL) { | |
438 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
439 | free_nfs_cb_data(data); | |
440 | return; | |
441 | } | |
442 | ||
443 | if (rpc_pmap_getport_async(rpc, MOUNT_PROGRAM, MOUNT_V3, nfs_mount_3_cb, private_data) != 0) { | |
444 | data->cb(-ENOMEM, nfs, command_data, data->private_data); | |
445 | free_nfs_cb_data(data); | |
446 | return; | |
447 | } | |
448 | } | |
449 | ||
450 | static void nfs_mount_1_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
451 | { | |
452 | struct nfs_cb_data *data = private_data; | |
453 | struct nfs_context *nfs = data->nfs; | |
454 | ||
455 | if (status == RPC_STATUS_ERROR) { | |
456 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
457 | free_nfs_cb_data(data); | |
458 | return; | |
459 | } | |
460 | if (status == RPC_STATUS_CANCEL) { | |
461 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
462 | free_nfs_cb_data(data); | |
463 | return; | |
464 | } | |
465 | ||
466 | if (rpc_pmap_null_async(rpc, nfs_mount_2_cb, data) != 0) { | |
467 | data->cb(-ENOMEM, nfs, command_data, data->private_data); | |
468 | free_nfs_cb_data(data); | |
469 | return; | |
470 | } | |
471 | } | |
472 | ||
473 | /* | |
474 | * Async call for mounting an nfs share and geting the root filehandle | |
475 | */ | |
476 | int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *export, nfs_cb cb, void *private_data) | |
477 | { | |
478 | struct nfs_cb_data *data; | |
b077fdeb | 479 | char *new_server, *new_export; |
84004dbf RS |
480 | |
481 | data = malloc(sizeof(struct nfs_cb_data)); | |
482 | if (data == NULL) { | |
cbbf9d3e | 483 | rpc_set_error(nfs->rpc, "out of memory. failed to allocate memory for nfs mount data"); |
84004dbf RS |
484 | return -1; |
485 | } | |
486 | bzero(data, sizeof(struct nfs_cb_data)); | |
b077fdeb RS |
487 | new_server = strdup(server); |
488 | new_export = strdup(export); | |
489 | if (nfs->server != NULL) { | |
490 | free(nfs->server); | |
491 | nfs->server = NULL; | |
492 | } | |
493 | nfs->server = new_server; | |
494 | if (nfs->export != NULL) { | |
495 | free(nfs->export); | |
496 | nfs->export = NULL; | |
497 | } | |
498 | nfs->export = new_export; | |
84004dbf RS |
499 | data->nfs = nfs; |
500 | data->cb = cb; | |
501 | data->private_data = private_data; | |
502 | ||
503 | if (rpc_connect_async(nfs->rpc, server, 111, nfs_mount_1_cb, data) != 0) { | |
cbbf9d3e | 504 | rpc_set_error(nfs->rpc, "Failed to start connection"); |
84004dbf | 505 | free_nfs_cb_data(data); |
cbbf9d3e | 506 | return -1; |
84004dbf RS |
507 | } |
508 | ||
509 | return 0; | |
510 | } | |
511 | ||
512 | ||
513 | ||
514 | /* | |
515 | * Functions to first look up a path, component by component, and then finally call a specific function once | |
516 | * the filehandle for the final component is found. | |
517 | */ | |
518 | static void nfs_lookup_path_1_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
519 | { | |
520 | struct nfs_cb_data *data = private_data; | |
521 | struct nfs_context *nfs = data->nfs; | |
522 | LOOKUP3res *res; | |
523 | ||
524 | if (status == RPC_STATUS_ERROR) { | |
525 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
526 | free_nfs_cb_data(data); | |
527 | return; | |
528 | } | |
529 | if (status == RPC_STATUS_CANCEL) { | |
530 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
531 | free_nfs_cb_data(data); | |
532 | return; | |
533 | } | |
534 | ||
535 | res = command_data; | |
536 | if (res->status != NFS3_OK) { | |
537 | rpc_set_error(nfs->rpc, "NFS: Lookup of %s failed with %s(%d)", data->saved_path, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
538 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
539 | free_nfs_cb_data(data); | |
540 | return; | |
541 | } | |
542 | ||
543 | if (nfs_lookup_path_async_internal(nfs, data, &res->LOOKUP3res_u.resok.object) != 0) { | |
544 | rpc_set_error(nfs->rpc, "Failed to create lookup pdu"); | |
545 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
546 | free_nfs_cb_data(data); | |
547 | return; | |
548 | } | |
549 | } | |
550 | ||
551 | static int nfs_lookup_path_async_internal(struct nfs_context *nfs, struct nfs_cb_data *data, struct nfs_fh3 *fh) | |
552 | { | |
553 | char *path, *str; | |
554 | ||
555 | while (*data->path == '/') { | |
556 | data->path++; | |
557 | } | |
558 | ||
559 | path = data->path; | |
a671a465 | 560 | str = strchr(path, '/'); |
84004dbf RS |
561 | if (str != NULL) { |
562 | *str = 0; | |
563 | data->path = str+1; | |
564 | } else { | |
565 | while (*data->path != 0) { | |
566 | data->path++; | |
567 | } | |
568 | } | |
569 | ||
570 | if (*path == 0) { | |
571 | data->fh.data.data_len = fh->data.data_len; | |
572 | data->fh.data.data_val = malloc(data->fh.data.data_len); | |
573 | if (data->fh.data.data_val == NULL) { | |
574 | rpc_set_error(nfs->rpc, "Out of memory: Failed to allocate fh for %s", data->path); | |
575 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
576 | free_nfs_cb_data(data); | |
577 | return -1; | |
578 | } | |
579 | memcpy(data->fh.data.data_val, fh->data.data_val, data->fh.data.data_len); | |
580 | data->continue_cb(nfs, data); | |
581 | return 0; | |
582 | } | |
583 | ||
584 | if (rpc_nfs_lookup_async(nfs->rpc, nfs_lookup_path_1_cb, fh, path, data) != 0) { | |
585 | rpc_set_error(nfs->rpc, "RPC error: Failed to send lookup call for %s", data->path); | |
586 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
587 | free_nfs_cb_data(data); | |
588 | return -1; | |
589 | } | |
590 | return 0; | |
591 | } | |
592 | ||
593 | static int nfs_lookuppath_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data, continue_func continue_cb, void *continue_data, void (*free_continue_data)(void *), int continue_int) | |
594 | { | |
595 | struct nfs_cb_data *data; | |
596 | ||
597 | if (path[0] != '/') { | |
598 | rpc_set_error(nfs->rpc, "Pathname is not absulute %s", path); | |
599 | return -1; | |
600 | } | |
601 | ||
602 | data = malloc(sizeof(struct nfs_cb_data)); | |
603 | if (data == NULL) { | |
604 | rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); | |
cbbf9d3e | 605 | return -1; |
84004dbf RS |
606 | } |
607 | bzero(data, sizeof(struct nfs_cb_data)); | |
608 | data->nfs = nfs; | |
609 | data->cb = cb; | |
610 | data->continue_cb = continue_cb; | |
611 | data->continue_data = continue_data; | |
612 | data->free_continue_data = free_continue_data; | |
613 | data->continue_int = continue_int; | |
614 | data->private_data = private_data; | |
615 | data->saved_path = strdup(path); | |
616 | if (data->saved_path == NULL) { | |
617 | rpc_set_error(nfs->rpc, "out of memory: failed to copy path string"); | |
84004dbf | 618 | free_nfs_cb_data(data); |
cbbf9d3e | 619 | return -1; |
84004dbf RS |
620 | } |
621 | data->path = data->saved_path; | |
622 | ||
623 | if (nfs_lookup_path_async_internal(nfs, data, &nfs->rootfh) != 0) { | |
84004dbf RS |
624 | /* return 0 here since the callback will be invoked if there is a failure */ |
625 | return 0; | |
626 | } | |
627 | return 0; | |
628 | } | |
629 | ||
630 | ||
631 | ||
632 | ||
633 | ||
634 | /* | |
635 | * Async stat() | |
636 | */ | |
637 | static void nfs_stat_1_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
638 | { | |
639 | GETATTR3res *res; | |
640 | struct nfs_cb_data *data = private_data; | |
641 | struct nfs_context *nfs = data->nfs; | |
642 | struct stat st; | |
643 | ||
644 | if (status == RPC_STATUS_ERROR) { | |
645 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
646 | free_nfs_cb_data(data); | |
647 | return; | |
648 | } | |
649 | if (status == RPC_STATUS_CANCEL) { | |
650 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
651 | free_nfs_cb_data(data); | |
652 | return; | |
653 | } | |
654 | ||
655 | res = command_data; | |
656 | if (res->status != NFS3_OK) { | |
657 | rpc_set_error(nfs->rpc, "NFS: GETATTR of %s failed with %s(%d)", data->saved_path, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
658 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
659 | free_nfs_cb_data(data); | |
660 | return; | |
661 | } | |
662 | ||
663 | st.st_dev = -1; | |
664 | st.st_ino = res->GETATTR3res_u.resok.obj_attributes.fileid; | |
665 | st.st_mode = res->GETATTR3res_u.resok.obj_attributes.mode; | |
e8cab72a RS |
666 | if (res->GETATTR3res_u.resok.obj_attributes.type == NF3DIR) { |
667 | st.st_mode |= S_IFDIR ; | |
668 | } | |
84004dbf RS |
669 | st.st_nlink = res->GETATTR3res_u.resok.obj_attributes.nlink; |
670 | st.st_uid = res->GETATTR3res_u.resok.obj_attributes.uid; | |
671 | st.st_gid = res->GETATTR3res_u.resok.obj_attributes.gid; | |
672 | st.st_rdev = 0; | |
673 | st.st_size = res->GETATTR3res_u.resok.obj_attributes.size; | |
d8143ff7 | 674 | #if !defined(WIN32) |
84004dbf RS |
675 | st.st_blksize = 4096; |
676 | st.st_blocks = res->GETATTR3res_u.resok.obj_attributes.size / 4096; | |
d8143ff7 | 677 | #endif |
84004dbf RS |
678 | st.st_atime = res->GETATTR3res_u.resok.obj_attributes.atime.seconds; |
679 | st.st_mtime = res->GETATTR3res_u.resok.obj_attributes.mtime.seconds; | |
680 | st.st_ctime = res->GETATTR3res_u.resok.obj_attributes.ctime.seconds; | |
681 | ||
682 | data->cb(0, nfs, &st, data->private_data); | |
683 | free_nfs_cb_data(data); | |
684 | } | |
685 | ||
686 | static int nfs_stat_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
687 | { | |
688 | if (rpc_nfs_getattr_async(nfs->rpc, nfs_stat_1_cb, &data->fh, data) != 0) { | |
689 | rpc_set_error(nfs->rpc, "RPC error: Failed to send STAT GETATTR call for %s", data->path); | |
690 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
691 | free_nfs_cb_data(data); | |
692 | return -1; | |
693 | } | |
694 | return 0; | |
695 | } | |
696 | ||
697 | int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data) | |
698 | { | |
699 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_stat_continue_internal, NULL, NULL, 0) != 0) { | |
cbbf9d3e | 700 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
84004dbf RS |
701 | return -1; |
702 | } | |
703 | ||
704 | return 0; | |
705 | } | |
706 | ||
707 | ||
708 | ||
709 | ||
710 | ||
711 | /* | |
712 | * Async open() | |
713 | */ | |
714 | static void nfs_open_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
715 | { | |
716 | ACCESS3res *res; | |
717 | struct nfs_cb_data *data = private_data; | |
718 | struct nfs_context *nfs = data->nfs; | |
719 | struct nfsfh *nfsfh; | |
720 | unsigned int nfsmode = 0; | |
721 | ||
722 | if (status == RPC_STATUS_ERROR) { | |
723 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
724 | free_nfs_cb_data(data); | |
725 | return; | |
726 | } | |
727 | if (status == RPC_STATUS_CANCEL) { | |
728 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
729 | free_nfs_cb_data(data); | |
730 | return; | |
731 | } | |
732 | ||
733 | res = command_data; | |
734 | if (res->status != NFS3_OK) { | |
735 | rpc_set_error(nfs->rpc, "NFS: ACCESS of %s failed with %s(%d)", data->saved_path, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
736 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
737 | free_nfs_cb_data(data); | |
738 | return; | |
739 | } | |
740 | ||
741 | if (data->continue_int & O_WRONLY) { | |
742 | nfsmode |= ACCESS3_MODIFY; | |
743 | } | |
744 | if (data->continue_int & O_RDWR) { | |
745 | nfsmode |= ACCESS3_READ|ACCESS3_MODIFY; | |
746 | } | |
747 | if (!(data->continue_int & (O_WRONLY|O_RDWR))) { | |
748 | nfsmode |= ACCESS3_READ; | |
749 | } | |
750 | ||
751 | ||
752 | if (res->ACCESS3res_u.resok.access != nfsmode) { | |
753 | rpc_set_error(nfs->rpc, "NFS: ACCESS denied. Required access %c%c%c. Allowed access %c%c%c", | |
754 | nfsmode&ACCESS3_READ?'r':'-', | |
755 | nfsmode&ACCESS3_MODIFY?'w':'-', | |
756 | nfsmode&ACCESS3_EXECUTE?'x':'-', | |
757 | res->ACCESS3res_u.resok.access&ACCESS3_READ?'r':'-', | |
758 | res->ACCESS3res_u.resok.access&ACCESS3_MODIFY?'w':'-', | |
759 | res->ACCESS3res_u.resok.access&ACCESS3_EXECUTE?'x':'-'); | |
760 | data->cb(-EACCES, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
761 | free_nfs_cb_data(data); | |
762 | return; | |
763 | } | |
764 | ||
765 | nfsfh = malloc(sizeof(struct nfsfh)); | |
766 | if (nfsfh == NULL) { | |
767 | rpc_set_error(nfs->rpc, "NFS: Failed to allocate nfsfh structure"); | |
768 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
769 | free_nfs_cb_data(data); | |
770 | return; | |
771 | } | |
772 | bzero(nfsfh, sizeof(struct nfsfh)); | |
773 | ||
774 | if (data->continue_int & O_SYNC) { | |
775 | nfsfh->is_sync = 1; | |
776 | } | |
777 | ||
778 | /* steal the filehandle */ | |
779 | nfsfh->fh.data.data_len = data->fh.data.data_len; | |
780 | nfsfh->fh.data.data_val = data->fh.data.data_val; | |
781 | data->fh.data.data_val = NULL; | |
782 | ||
783 | data->cb(0, nfs, nfsfh, data->private_data); | |
784 | free_nfs_cb_data(data); | |
785 | } | |
786 | ||
787 | static int nfs_open_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
788 | { | |
789 | int nfsmode = 0; | |
790 | ||
791 | if (data->continue_int & O_WRONLY) { | |
792 | nfsmode |= ACCESS3_MODIFY; | |
793 | } | |
794 | if (data->continue_int & O_RDWR) { | |
795 | nfsmode |= ACCESS3_READ|ACCESS3_MODIFY; | |
796 | } | |
797 | if (!(data->continue_int & (O_WRONLY|O_RDWR))) { | |
798 | nfsmode |= ACCESS3_READ; | |
799 | } | |
800 | ||
801 | if (rpc_nfs_access_async(nfs->rpc, nfs_open_cb, &data->fh, nfsmode, data) != 0) { | |
802 | rpc_set_error(nfs->rpc, "RPC error: Failed to send OPEN ACCESS call for %s", data->path); | |
803 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
804 | free_nfs_cb_data(data); | |
805 | return -1; | |
806 | } | |
807 | return 0; | |
808 | } | |
809 | ||
810 | int nfs_open_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data) | |
811 | { | |
812 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_open_continue_internal, NULL, NULL, mode) != 0) { | |
cbbf9d3e RS |
813 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
814 | return -1; | |
84004dbf RS |
815 | } |
816 | ||
817 | return 0; | |
818 | } | |
819 | ||
820 | ||
821 | ||
822 | ||
823 | ||
824 | /* | |
825 | * Async pread() | |
826 | */ | |
827 | static void nfs_pread_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
828 | { | |
829 | struct nfs_cb_data *data = private_data; | |
830 | struct nfs_context *nfs = data->nfs; | |
831 | READ3res *res; | |
832 | ||
833 | if (status == RPC_STATUS_ERROR) { | |
834 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
835 | free_nfs_cb_data(data); | |
836 | return; | |
837 | } | |
838 | if (status == RPC_STATUS_CANCEL) { | |
839 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
840 | free_nfs_cb_data(data); | |
841 | return; | |
842 | } | |
843 | ||
844 | res = command_data; | |
845 | if (res->status != NFS3_OK) { | |
846 | rpc_set_error(nfs->rpc, "NFS: Read failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
847 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
848 | free_nfs_cb_data(data); | |
849 | return; | |
850 | } | |
851 | ||
852 | data->nfsfh->offset += res->READ3res_u.resok.count; | |
853 | data->cb(res->READ3res_u.resok.count, nfs, res->READ3res_u.resok.data.data_val, data->private_data); | |
854 | free_nfs_cb_data(data); | |
855 | } | |
856 | ||
921f877b RS |
857 | static void nfs_pread_mcb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) |
858 | { | |
859 | struct nfs_mcb_data *mdata = private_data; | |
860 | struct nfs_cb_data *data = mdata->data; | |
861 | struct nfs_context *nfs = data->nfs; | |
862 | READ3res *res; | |
863 | ||
864 | data->num_calls--; | |
865 | ||
866 | if (status == RPC_STATUS_ERROR) { | |
867 | /* flag the failure but do not invoke callback until we have received all responses */ | |
868 | data->error = 1; | |
869 | } | |
870 | if (status == RPC_STATUS_CANCEL) { | |
871 | /* flag the cancellation but do not invoke callback until we have received all responses */ | |
872 | data->cancel = 1; | |
873 | } | |
874 | ||
875 | /* reassemble the data into the buffer */ | |
876 | if (status == RPC_STATUS_SUCCESS) { | |
877 | res = command_data; | |
878 | if (res->status != NFS3_OK) { | |
879 | rpc_set_error(nfs->rpc, "NFS: Read failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
880 | data->error = 1; | |
e4a5ba42 RS |
881 | } else { |
882 | if (res->READ3res_u.resok.count > 0) { | |
883 | memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count); | |
884 | if ((unsigned)data->max_offset < mdata->offset + res->READ3res_u.resok.count) { | |
885 | data->max_offset = mdata->offset + res->READ3res_u.resok.count; | |
886 | } | |
921f877b RS |
887 | } |
888 | } | |
889 | } | |
890 | ||
891 | if (data->num_calls > 0) { | |
892 | /* still waiting for more replies */ | |
893 | free(mdata); | |
894 | return; | |
895 | } | |
896 | ||
921f877b RS |
897 | if (data->error != 0) { |
898 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
899 | free_nfs_cb_data(data); | |
900 | free(mdata); | |
901 | return; | |
902 | } | |
903 | if (data->cancel != 0) { | |
904 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
905 | free_nfs_cb_data(data); | |
906 | free(mdata); | |
907 | return; | |
908 | } | |
909 | ||
910 | data->nfsfh->offset = data->max_offset; | |
7ed9d87a RS |
911 | data->cb(data->max_offset - data->start_offset, nfs, data->buffer, data->private_data); |
912 | ||
921f877b RS |
913 | free_nfs_cb_data(data); |
914 | free(mdata); | |
915 | } | |
916 | ||
84004dbf RS |
917 | int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, nfs_cb cb, void *private_data) |
918 | { | |
919 | struct nfs_cb_data *data; | |
920 | ||
921 | data = malloc(sizeof(struct nfs_cb_data)); | |
922 | if (data == NULL) { | |
923 | rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); | |
84004dbf RS |
924 | return -1; |
925 | } | |
926 | bzero(data, sizeof(struct nfs_cb_data)); | |
927 | data->nfs = nfs; | |
928 | data->cb = cb; | |
929 | data->private_data = private_data; | |
930 | data->nfsfh = nfsfh; | |
931 | ||
932 | nfsfh->offset = offset; | |
921f877b RS |
933 | |
934 | if (count <= nfs_get_readmax(nfs)) { | |
935 | if (rpc_nfs_read_async(nfs->rpc, nfs_pread_cb, &nfsfh->fh, offset, count, data) != 0) { | |
936 | rpc_set_error(nfs->rpc, "RPC error: Failed to send READ call for %s", data->path); | |
937 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
938 | free_nfs_cb_data(data); | |
939 | return -1; | |
940 | } | |
941 | return 0; | |
942 | } | |
943 | ||
944 | /* trying to read more than maximum server read size, we has to chop it up into smaller | |
945 | * reads and collect into a reassembly buffer. | |
946 | * we send all reads in parallell so that performance is still good. | |
947 | */ | |
7ed9d87a | 948 | data->max_offset = offset; |
921f877b RS |
949 | data->start_offset = offset; |
950 | ||
951 | data->buffer = malloc(count); | |
952 | if (data->buffer == NULL) { | |
953 | rpc_set_error(nfs->rpc, "Out-Of-Memory: Failed to allocate reassembly buffer for %d bytes", (int)count); | |
84004dbf RS |
954 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); |
955 | free_nfs_cb_data(data); | |
956 | return -1; | |
957 | } | |
921f877b RS |
958 | |
959 | while (count > 0) { | |
960 | size_t readcount = count; | |
961 | struct nfs_mcb_data *mdata; | |
962 | ||
963 | if (readcount > nfs_get_readmax(nfs)) { | |
964 | readcount = nfs_get_readmax(nfs); | |
965 | } | |
966 | ||
967 | mdata = malloc(sizeof(struct nfs_mcb_data)); | |
968 | if (mdata == NULL) { | |
969 | rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_mcb_data structure"); | |
921f877b RS |
970 | return -1; |
971 | } | |
972 | bzero(mdata, sizeof(struct nfs_mcb_data)); | |
973 | mdata->data = data; | |
974 | mdata->offset = offset; | |
975 | mdata->count = readcount; | |
921f877b RS |
976 | if (rpc_nfs_read_async(nfs->rpc, nfs_pread_mcb, &nfsfh->fh, offset, readcount, mdata) != 0) { |
977 | rpc_set_error(nfs->rpc, "RPC error: Failed to send READ call for %s", data->path); | |
978 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
979 | free(mdata); | |
980 | return -1; | |
981 | } | |
982 | ||
983 | count -= readcount; | |
984 | offset += readcount; | |
985 | data->num_calls++; | |
986 | } | |
987 | ||
988 | return 0; | |
84004dbf RS |
989 | } |
990 | ||
991 | /* | |
992 | * Async read() | |
993 | */ | |
994 | int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, nfs_cb cb, void *private_data) | |
995 | { | |
996 | return nfs_pread_async(nfs, nfsfh, nfsfh->offset, count, cb, private_data); | |
997 | } | |
998 | ||
999 | ||
1000 | ||
1001 | /* | |
1002 | * Async pwrite() | |
1003 | */ | |
1004 | static void nfs_pwrite_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1005 | { | |
1006 | struct nfs_cb_data *data = private_data; | |
1007 | struct nfs_context *nfs = data->nfs; | |
1008 | WRITE3res *res; | |
1009 | ||
1010 | if (status == RPC_STATUS_ERROR) { | |
1011 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1012 | free_nfs_cb_data(data); | |
1013 | return; | |
1014 | } | |
1015 | if (status == RPC_STATUS_CANCEL) { | |
1016 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1017 | free_nfs_cb_data(data); | |
1018 | return; | |
1019 | } | |
1020 | ||
1021 | res = command_data; | |
1022 | if (res->status != NFS3_OK) { | |
1023 | rpc_set_error(nfs->rpc, "NFS: Write failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1024 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1025 | free_nfs_cb_data(data); | |
1026 | return; | |
1027 | } | |
1028 | ||
1029 | data->nfsfh->offset += res->WRITE3res_u.resok.count; | |
1030 | data->cb(res->WRITE3res_u.resok.count, nfs, NULL, data->private_data); | |
1031 | free_nfs_cb_data(data); | |
1032 | } | |
1033 | ||
1034 | int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data) | |
1035 | { | |
1036 | struct nfs_cb_data *data; | |
1037 | ||
1038 | data = malloc(sizeof(struct nfs_cb_data)); | |
1039 | if (data == NULL) { | |
1040 | rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); | |
84004dbf RS |
1041 | return -1; |
1042 | } | |
1043 | bzero(data, sizeof(struct nfs_cb_data)); | |
1044 | data->nfs = nfs; | |
1045 | data->cb = cb; | |
1046 | data->private_data = private_data; | |
1047 | data->nfsfh = nfsfh; | |
1048 | ||
1049 | nfsfh->offset = offset; | |
1050 | if (rpc_nfs_write_async(nfs->rpc, nfs_pwrite_cb, &nfsfh->fh, buf, offset, count, nfsfh->is_sync?FILE_SYNC:UNSTABLE, data) != 0) { | |
1051 | rpc_set_error(nfs->rpc, "RPC error: Failed to send WRITE call for %s", data->path); | |
1052 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1053 | free_nfs_cb_data(data); | |
1054 | return -1; | |
1055 | } | |
1056 | return 0; | |
1057 | } | |
1058 | ||
1059 | /* | |
1060 | * Async write() | |
1061 | */ | |
1062 | int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf, nfs_cb cb, void *private_data) | |
1063 | { | |
1064 | return nfs_pwrite_async(nfs, nfsfh, nfsfh->offset, count, buf, cb, private_data); | |
1065 | } | |
1066 | ||
1067 | ||
1068 | ||
1069 | ||
1070 | /* | |
1071 | * close | |
1072 | */ | |
1073 | ||
1074 | int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data) | |
1075 | { | |
1076 | if (nfsfh->fh.data.data_val != NULL){ | |
1077 | free(nfsfh->fh.data.data_val); | |
1078 | nfsfh->fh.data.data_val = NULL; | |
1079 | } | |
1080 | free(nfsfh); | |
1081 | ||
1082 | cb(0, nfs, NULL, private_data); | |
1083 | return 0; | |
1084 | }; | |
1085 | ||
1086 | ||
1087 | ||
1088 | ||
1089 | ||
1090 | /* | |
1091 | * Async fstat() | |
1092 | */ | |
1093 | int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data) | |
1094 | { | |
1095 | struct nfs_cb_data *data; | |
1096 | ||
1097 | data = malloc(sizeof(struct nfs_cb_data)); | |
1098 | if (data == NULL) { | |
1099 | rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); | |
84004dbf RS |
1100 | return -1; |
1101 | } | |
1102 | bzero(data, sizeof(struct nfs_cb_data)); | |
1103 | data->nfs = nfs; | |
1104 | data->cb = cb; | |
1105 | data->private_data = private_data; | |
1106 | ||
1107 | if (rpc_nfs_getattr_async(nfs->rpc, nfs_stat_1_cb, &nfsfh->fh, data) != 0) { | |
1108 | rpc_set_error(nfs->rpc, "RPC error: Failed to send STAT GETATTR call for %s", data->path); | |
1109 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1110 | free_nfs_cb_data(data); | |
1111 | return -1; | |
1112 | } | |
1113 | return 0; | |
1114 | } | |
1115 | ||
1116 | ||
1117 | ||
1118 | /* | |
1119 | * Async fsync() | |
1120 | */ | |
1121 | static void nfs_fsync_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1122 | { | |
1123 | struct nfs_cb_data *data = private_data; | |
1124 | struct nfs_context *nfs = data->nfs; | |
1125 | COMMIT3res *res; | |
1126 | ||
1127 | if (status == RPC_STATUS_ERROR) { | |
1128 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1129 | free_nfs_cb_data(data); | |
1130 | return; | |
1131 | } | |
1132 | if (status == RPC_STATUS_CANCEL) { | |
1133 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1134 | free_nfs_cb_data(data); | |
1135 | return; | |
1136 | } | |
1137 | ||
1138 | res = command_data; | |
1139 | if (res->status != NFS3_OK) { | |
1140 | rpc_set_error(nfs->rpc, "NFS: Commit failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1141 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1142 | free_nfs_cb_data(data); | |
1143 | return; | |
1144 | } | |
1145 | ||
1146 | data->cb(0, nfs, NULL, data->private_data); | |
1147 | free_nfs_cb_data(data); | |
1148 | } | |
1149 | ||
1150 | int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data) | |
1151 | { | |
1152 | struct nfs_cb_data *data; | |
1153 | ||
1154 | data = malloc(sizeof(struct nfs_cb_data)); | |
1155 | if (data == NULL) { | |
1156 | rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); | |
84004dbf RS |
1157 | return -1; |
1158 | } | |
1159 | bzero(data, sizeof(struct nfs_cb_data)); | |
1160 | data->nfs = nfs; | |
1161 | data->cb = cb; | |
1162 | data->private_data = private_data; | |
1163 | ||
1164 | if (rpc_nfs_commit_async(nfs->rpc, nfs_fsync_cb, &nfsfh->fh, data) != 0) { | |
1165 | rpc_set_error(nfs->rpc, "RPC error: Failed to send COMMIT call for %s", data->path); | |
1166 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1167 | free_nfs_cb_data(data); | |
1168 | return -1; | |
1169 | } | |
1170 | return 0; | |
1171 | } | |
1172 | ||
1173 | ||
1174 | ||
1175 | ||
1176 | /* | |
1177 | * Async ftruncate() | |
1178 | */ | |
1179 | static void nfs_ftruncate_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1180 | { | |
1181 | struct nfs_cb_data *data = private_data; | |
1182 | struct nfs_context *nfs = data->nfs; | |
1183 | SETATTR3res *res; | |
1184 | ||
1185 | if (status == RPC_STATUS_ERROR) { | |
1186 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1187 | free_nfs_cb_data(data); | |
1188 | return; | |
1189 | } | |
1190 | if (status == RPC_STATUS_CANCEL) { | |
1191 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1192 | free_nfs_cb_data(data); | |
1193 | return; | |
1194 | } | |
1195 | ||
1196 | res = command_data; | |
1197 | if (res->status != NFS3_OK) { | |
1198 | rpc_set_error(nfs->rpc, "NFS: Setattr failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1199 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1200 | free_nfs_cb_data(data); | |
1201 | return; | |
1202 | } | |
1203 | ||
1204 | data->cb(0, nfs, NULL, data->private_data); | |
1205 | free_nfs_cb_data(data); | |
1206 | } | |
1207 | ||
1208 | int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length, nfs_cb cb, void *private_data) | |
1209 | { | |
1210 | struct nfs_cb_data *data; | |
1211 | SETATTR3args args; | |
1212 | ||
1213 | data = malloc(sizeof(struct nfs_cb_data)); | |
1214 | if (data == NULL) { | |
1215 | rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); | |
84004dbf RS |
1216 | return -1; |
1217 | } | |
1218 | bzero(data, sizeof(struct nfs_cb_data)); | |
1219 | data->nfs = nfs; | |
1220 | data->cb = cb; | |
1221 | data->private_data = private_data; | |
1222 | ||
1223 | bzero(&args, sizeof(SETATTR3args)); | |
1224 | args.object.data.data_len = nfsfh->fh.data.data_len; | |
1225 | args.object.data.data_val = nfsfh->fh.data.data_val; | |
1226 | args.new_attributes.size.set_it = 1; | |
1227 | args.new_attributes.size.set_size3_u.size = length; | |
1228 | ||
1229 | if (rpc_nfs_setattr_async(nfs->rpc, nfs_ftruncate_cb, &args, data) != 0) { | |
1230 | rpc_set_error(nfs->rpc, "RPC error: Failed to send SETATTR call for %s", data->path); | |
1231 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1232 | free_nfs_cb_data(data); | |
1233 | return -1; | |
1234 | } | |
1235 | return 0; | |
1236 | } | |
1237 | ||
1238 | ||
1239 | /* | |
1240 | * Async truncate() | |
1241 | */ | |
1242 | static int nfs_truncate_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
1243 | { | |
1244 | off_t offset = data->continue_int; | |
1245 | struct nfsfh nfsfh; | |
1246 | ||
1247 | nfsfh.fh.data.data_val = data->fh.data.data_val; | |
1248 | nfsfh.fh.data.data_len = data->fh.data.data_len; | |
1249 | ||
1250 | if (nfs_ftruncate_async(nfs, &nfsfh, offset, data->cb, data->private_data) != 0) { | |
1251 | rpc_set_error(nfs->rpc, "RPC error: Failed to send SETATTR call for %s", data->path); | |
1252 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1253 | free_nfs_cb_data(data); | |
1254 | return -1; | |
1255 | } | |
1256 | free_nfs_cb_data(data); | |
1257 | return 0; | |
1258 | } | |
1259 | ||
1260 | int nfs_truncate_async(struct nfs_context *nfs, const char *path, off_t length, nfs_cb cb, void *private_data) | |
1261 | { | |
1262 | off_t offset; | |
1263 | ||
1264 | offset = length; | |
1265 | ||
1266 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_truncate_continue_internal, NULL, NULL, offset) != 0) { | |
cbbf9d3e RS |
1267 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
1268 | return -1; | |
84004dbf RS |
1269 | } |
1270 | ||
1271 | return 0; | |
1272 | } | |
1273 | ||
1274 | ||
1275 | ||
1276 | ||
1277 | /* | |
1278 | * Async mkdir() | |
1279 | */ | |
1280 | static void nfs_mkdir_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1281 | { | |
1282 | MKDIR3res *res; | |
1283 | struct nfs_cb_data *data = private_data; | |
1284 | struct nfs_context *nfs = data->nfs; | |
1285 | char *str = data->continue_data; | |
1286 | ||
1287 | str = &str[strlen(str) + 1]; | |
1288 | ||
1289 | if (status == RPC_STATUS_ERROR) { | |
1290 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1291 | free_nfs_cb_data(data); | |
1292 | return; | |
1293 | } | |
1294 | if (status == RPC_STATUS_CANCEL) { | |
1295 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1296 | free_nfs_cb_data(data); | |
1297 | return; | |
1298 | } | |
1299 | ||
1300 | res = command_data; | |
1301 | if (res->status != NFS3_OK) { | |
1302 | rpc_set_error(nfs->rpc, "NFS: MKDIR of %s/%s failed with %s(%d)", data->saved_path, str, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1303 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1304 | free_nfs_cb_data(data); | |
1305 | return; | |
1306 | } | |
1307 | ||
1308 | data->cb(0, nfs, NULL, data->private_data); | |
1309 | free_nfs_cb_data(data); | |
1310 | } | |
1311 | ||
1312 | static int nfs_mkdir_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
1313 | { | |
1314 | char *str = data->continue_data; | |
1315 | ||
1316 | str = &str[strlen(str) + 1]; | |
1317 | ||
1318 | if (rpc_nfs_mkdir_async(nfs->rpc, nfs_mkdir_cb, &data->fh, str, data) != 0) { | |
1319 | rpc_set_error(nfs->rpc, "RPC error: Failed to send MKDIR call for %s", data->path); | |
1320 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1321 | free_nfs_cb_data(data); | |
1322 | return -1; | |
1323 | } | |
1324 | return 0; | |
1325 | } | |
1326 | ||
1327 | int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data) | |
1328 | { | |
1329 | char *new_path; | |
1330 | char *ptr; | |
1331 | ||
1332 | new_path = strdup(path); | |
1333 | if (new_path == NULL) { | |
cbbf9d3e | 1334 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate mode buffer for path"); |
84004dbf RS |
1335 | return -1; |
1336 | } | |
1337 | ||
a671a465 | 1338 | ptr = strrchr(new_path, '/'); |
84004dbf | 1339 | if (ptr == NULL) { |
cbbf9d3e RS |
1340 | rpc_set_error(nfs->rpc, "Invalid path %s", path); |
1341 | return -1; | |
84004dbf RS |
1342 | } |
1343 | *ptr = 0; | |
1344 | ||
1345 | /* new_path now points to the parent directory, and beyond the nul terminateor is the new directory to create */ | |
1346 | if (nfs_lookuppath_async(nfs, new_path, cb, private_data, nfs_mkdir_continue_internal, new_path, free, 0) != 0) { | |
cbbf9d3e RS |
1347 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path component"); |
1348 | return -1; | |
84004dbf RS |
1349 | } |
1350 | ||
1351 | return 0; | |
1352 | } | |
1353 | ||
1354 | ||
1355 | ||
1356 | ||
1357 | ||
1358 | /* | |
1359 | * Async rmdir() | |
1360 | */ | |
1361 | static void nfs_rmdir_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1362 | { | |
1363 | RMDIR3res *res; | |
1364 | struct nfs_cb_data *data = private_data; | |
1365 | struct nfs_context *nfs = data->nfs; | |
1366 | char *str = data->continue_data; | |
1367 | ||
1368 | str = &str[strlen(str) + 1]; | |
1369 | ||
1370 | if (status == RPC_STATUS_ERROR) { | |
1371 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1372 | free_nfs_cb_data(data); | |
1373 | return; | |
1374 | } | |
1375 | if (status == RPC_STATUS_CANCEL) { | |
1376 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1377 | free_nfs_cb_data(data); | |
1378 | return; | |
1379 | } | |
1380 | ||
1381 | res = command_data; | |
1382 | if (res->status != NFS3_OK) { | |
1383 | rpc_set_error(nfs->rpc, "NFS: RMDIR of %s/%s failed with %s(%d)", data->saved_path, str, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1384 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1385 | free_nfs_cb_data(data); | |
1386 | return; | |
1387 | } | |
1388 | ||
1389 | data->cb(0, nfs, NULL, data->private_data); | |
1390 | free_nfs_cb_data(data); | |
1391 | } | |
1392 | ||
1393 | static int nfs_rmdir_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
1394 | { | |
1395 | char *str = data->continue_data; | |
1396 | ||
1397 | str = &str[strlen(str) + 1]; | |
1398 | ||
1399 | if (rpc_nfs_rmdir_async(nfs->rpc, nfs_rmdir_cb, &data->fh, str, data) != 0) { | |
1400 | rpc_set_error(nfs->rpc, "RPC error: Failed to send RMDIR call for %s", data->path); | |
1401 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1402 | free_nfs_cb_data(data); | |
1403 | return -1; | |
1404 | } | |
1405 | return 0; | |
1406 | } | |
1407 | ||
1408 | int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data) | |
1409 | { | |
1410 | char *new_path; | |
1411 | char *ptr; | |
1412 | ||
1413 | new_path = strdup(path); | |
1414 | if (new_path == NULL) { | |
cbbf9d3e | 1415 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate mode buffer for path"); |
84004dbf RS |
1416 | return -1; |
1417 | } | |
1418 | ||
a671a465 | 1419 | ptr = strrchr(new_path, '/'); |
84004dbf | 1420 | if (ptr == NULL) { |
cbbf9d3e RS |
1421 | rpc_set_error(nfs->rpc, "Invalid path %s", path); |
1422 | return -1; | |
84004dbf RS |
1423 | } |
1424 | *ptr = 0; | |
1425 | ||
1426 | /* new_path now points to the parent directory, and beyond the nul terminateor is the new directory to create */ | |
1427 | if (nfs_lookuppath_async(nfs, new_path, cb, private_data, nfs_rmdir_continue_internal, new_path, free, 0) != 0) { | |
cbbf9d3e RS |
1428 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
1429 | return -1; | |
84004dbf RS |
1430 | } |
1431 | ||
1432 | return 0; | |
1433 | } | |
1434 | ||
1435 | ||
1436 | ||
1437 | ||
1438 | /* | |
1439 | * Async creat() | |
1440 | */ | |
1441 | static void nfs_create_2_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1442 | { | |
1443 | LOOKUP3res *res; | |
1444 | struct nfs_cb_data *data = private_data; | |
1445 | struct nfs_context *nfs = data->nfs; | |
1446 | struct nfsfh *nfsfh; | |
1447 | char *str = data->continue_data; | |
1448 | ||
1449 | if (status == RPC_STATUS_ERROR) { | |
1450 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1451 | free_nfs_cb_data(data); | |
1452 | return; | |
1453 | } | |
1454 | if (status == RPC_STATUS_CANCEL) { | |
1455 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1456 | free_nfs_cb_data(data); | |
1457 | return; | |
1458 | } | |
1459 | ||
1460 | str = &str[strlen(str) + 1]; | |
1461 | res = command_data; | |
1462 | if (res->status != NFS3_OK) { | |
1463 | rpc_set_error(nfs->rpc, "NFS: CREATE of %s/%s failed with %s(%d)", data->saved_path, str, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1464 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1465 | ||
1466 | return; | |
1467 | } | |
1468 | ||
1469 | nfsfh = malloc(sizeof(struct nfsfh)); | |
1470 | if (nfsfh == NULL) { | |
1471 | rpc_set_error(nfs->rpc, "NFS: Failed to allocate nfsfh structure"); | |
1472 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1473 | free_nfs_cb_data(data); | |
1474 | return; | |
1475 | } | |
1476 | bzero(nfsfh, sizeof(struct nfsfh)); | |
1477 | ||
1478 | /* steal the filehandle */ | |
1479 | nfsfh->fh.data.data_len = data->fh.data.data_len; | |
1480 | nfsfh->fh.data.data_val = data->fh.data.data_val; | |
1481 | data->fh.data.data_val = NULL; | |
1482 | ||
1483 | data->cb(0, nfs, nfsfh, data->private_data); | |
1484 | free_nfs_cb_data(data); | |
1485 | } | |
1486 | ||
1487 | ||
1488 | ||
1489 | static void nfs_creat_1_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1490 | { | |
1491 | CREATE3res *res; | |
1492 | struct nfs_cb_data *data = private_data; | |
1493 | struct nfs_context *nfs = data->nfs; | |
1494 | char *str = data->continue_data; | |
1495 | ||
1496 | if (status == RPC_STATUS_ERROR) { | |
1497 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1498 | free_nfs_cb_data(data); | |
1499 | return; | |
1500 | } | |
1501 | if (status == RPC_STATUS_CANCEL) { | |
1502 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1503 | free_nfs_cb_data(data); | |
1504 | return; | |
1505 | } | |
1506 | ||
1507 | str = &str[strlen(str) + 1]; | |
1508 | res = command_data; | |
1509 | if (res->status != NFS3_OK) { | |
1510 | rpc_set_error(nfs->rpc, "NFS: CREATE of %s/%s failed with %s(%d)", data->saved_path, str, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1511 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1512 | ||
1513 | return; | |
1514 | } | |
1515 | ||
1516 | if (rpc_nfs_lookup_async(nfs->rpc, nfs_create_2_cb, &data->fh, str, data) != 0) { | |
1517 | rpc_set_error(nfs->rpc, "RPC error: Failed to send lookup call for %s/%s", data->saved_path, str); | |
1518 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1519 | free_nfs_cb_data(data); | |
1520 | return; | |
1521 | } | |
1522 | return; | |
1523 | } | |
1524 | ||
1525 | static int nfs_creat_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
1526 | { | |
1527 | char *str = data->continue_data; | |
1528 | ||
1529 | str = &str[strlen(str) + 1]; | |
1530 | ||
1531 | if (rpc_nfs_create_async(nfs->rpc, nfs_creat_1_cb, &data->fh, str, data->continue_int, data) != 0) { | |
1532 | rpc_set_error(nfs->rpc, "RPC error: Failed to send CREATE call for %s/%s", data->path, str); | |
1533 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1534 | free_nfs_cb_data(data); | |
1535 | return -1; | |
1536 | } | |
1537 | return 0; | |
1538 | } | |
1539 | ||
1540 | int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data) | |
1541 | { | |
1542 | char *new_path; | |
1543 | char *ptr; | |
1544 | ||
1545 | new_path = strdup(path); | |
1546 | if (new_path == NULL) { | |
cbbf9d3e | 1547 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate mode buffer for path"); |
84004dbf RS |
1548 | return -1; |
1549 | } | |
1550 | ||
a671a465 | 1551 | ptr = strrchr(new_path, '/'); |
84004dbf | 1552 | if (ptr == NULL) { |
cbbf9d3e RS |
1553 | rpc_set_error(nfs->rpc, "Invalid path %s", path); |
1554 | return -1; | |
84004dbf RS |
1555 | } |
1556 | *ptr = 0; | |
1557 | ||
1558 | /* new_path now points to the parent directory, and beyond the nul terminateor is the new directory to create */ | |
1559 | if (nfs_lookuppath_async(nfs, new_path, cb, private_data, nfs_creat_continue_internal, new_path, free, mode) != 0) { | |
cbbf9d3e RS |
1560 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
1561 | return -1; | |
84004dbf RS |
1562 | } |
1563 | ||
1564 | return 0; | |
1565 | } | |
1566 | ||
1567 | ||
1568 | ||
1569 | ||
1570 | /* | |
1571 | * Async unlink() | |
1572 | */ | |
1573 | static void nfs_unlink_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1574 | { | |
1575 | REMOVE3res *res; | |
1576 | struct nfs_cb_data *data = private_data; | |
1577 | struct nfs_context *nfs = data->nfs; | |
1578 | char *str = data->continue_data; | |
1579 | ||
1580 | str = &str[strlen(str) + 1]; | |
1581 | ||
1582 | if (status == RPC_STATUS_ERROR) { | |
1583 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1584 | free_nfs_cb_data(data); | |
1585 | return; | |
1586 | } | |
1587 | if (status == RPC_STATUS_CANCEL) { | |
1588 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1589 | free_nfs_cb_data(data); | |
1590 | return; | |
1591 | } | |
1592 | ||
1593 | res = command_data; | |
1594 | if (res->status != NFS3_OK) { | |
1595 | rpc_set_error(nfs->rpc, "NFS: REMOVE of %s/%s failed with %s(%d)", data->saved_path, str, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1596 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1597 | free_nfs_cb_data(data); | |
1598 | return; | |
1599 | } | |
1600 | ||
1601 | data->cb(0, nfs, NULL, data->private_data); | |
1602 | free_nfs_cb_data(data); | |
1603 | } | |
1604 | ||
1605 | static int nfs_unlink_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
1606 | { | |
1607 | char *str = data->continue_data; | |
1608 | ||
1609 | str = &str[strlen(str) + 1]; | |
1610 | ||
1611 | if (rpc_nfs_remove_async(nfs->rpc, nfs_unlink_cb, &data->fh, str, data) != 0) { | |
1612 | rpc_set_error(nfs->rpc, "RPC error: Failed to send REMOVE call for %s", data->path); | |
1613 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1614 | free_nfs_cb_data(data); | |
1615 | return -1; | |
1616 | } | |
1617 | return 0; | |
1618 | } | |
1619 | ||
1620 | int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data) | |
1621 | { | |
1622 | char *new_path; | |
1623 | char *ptr; | |
1624 | ||
1625 | new_path = strdup(path); | |
1626 | if (new_path == NULL) { | |
cbbf9d3e | 1627 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate mode buffer for path"); |
84004dbf RS |
1628 | return -1; |
1629 | } | |
1630 | ||
a671a465 | 1631 | ptr = strrchr(new_path, '/'); |
84004dbf | 1632 | if (ptr == NULL) { |
cbbf9d3e RS |
1633 | rpc_set_error(nfs->rpc, "Invalid path %s", path); |
1634 | return -1; | |
84004dbf RS |
1635 | } |
1636 | *ptr = 0; | |
1637 | ||
1638 | /* new_path now points to the parent directory, and beyond the nul terminateor is the new directory to create */ | |
1639 | if (nfs_lookuppath_async(nfs, new_path, cb, private_data, nfs_unlink_continue_internal, new_path, free, 0) != 0) { | |
cbbf9d3e RS |
1640 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
1641 | return -1; | |
84004dbf RS |
1642 | } |
1643 | ||
1644 | return 0; | |
1645 | } | |
1646 | ||
1647 | ||
1648 | ||
1649 | ||
1650 | ||
1651 | /* | |
1652 | * Async opendir() | |
1653 | */ | |
1654 | static void nfs_opendir_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1655 | { | |
1656 | READDIR3res *res; | |
1657 | struct nfs_cb_data *data = private_data; | |
1658 | struct nfs_context *nfs = data->nfs; | |
1659 | struct nfsdir *nfsdir = data->continue_data;; | |
1660 | struct entry3 *entry; | |
1661 | uint64_t cookie; | |
1662 | ||
1663 | if (status == RPC_STATUS_ERROR) { | |
1664 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1665 | nfs_free_nfsdir(nfsdir); | |
1666 | data->continue_data = NULL; | |
1667 | free_nfs_cb_data(data); | |
1668 | return; | |
1669 | } | |
1670 | if (status == RPC_STATUS_CANCEL) { | |
1671 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1672 | nfs_free_nfsdir(nfsdir); | |
1673 | data->continue_data = NULL; | |
1674 | free_nfs_cb_data(data); | |
1675 | return; | |
1676 | } | |
1677 | ||
1678 | res = command_data; | |
1679 | if (res->status != NFS3_OK) { | |
1680 | rpc_set_error(nfs->rpc, "NFS: READDIR of %s failed with %s(%d)", data->saved_path, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1681 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1682 | nfs_free_nfsdir(nfsdir); | |
1683 | data->continue_data = NULL; | |
1684 | free_nfs_cb_data(data); | |
1685 | return; | |
1686 | } | |
1687 | ||
1688 | entry =res->READDIR3res_u.resok.reply.entries; | |
1689 | while (entry != NULL) { | |
1690 | struct nfsdirent *nfsdirent; | |
1691 | ||
1692 | nfsdirent = malloc(sizeof(struct nfsdirent)); | |
1693 | if (nfsdirent == NULL) { | |
1694 | data->cb(-ENOMEM, nfs, "Failed to allocate dirent", data->private_data); | |
1695 | nfs_free_nfsdir(nfsdir); | |
1696 | data->continue_data = NULL; | |
1697 | free_nfs_cb_data(data); | |
1698 | return; | |
1699 | } | |
1700 | bzero(nfsdirent, sizeof(struct nfsdirent)); | |
1701 | nfsdirent->name = strdup(entry->name); | |
1702 | if (nfsdirent->name == NULL) { | |
1703 | data->cb(-ENOMEM, nfs, "Failed to allocate dirent->name", data->private_data); | |
1704 | nfs_free_nfsdir(nfsdir); | |
1705 | data->continue_data = NULL; | |
1706 | free_nfs_cb_data(data); | |
1707 | return; | |
1708 | } | |
1709 | nfsdirent->inode = entry->fileid; | |
1710 | nfsdirent->next = nfsdir->entries; | |
1711 | nfsdir->entries = nfsdirent; | |
1712 | ||
1713 | cookie = entry->cookie; | |
1714 | entry = entry->nextentry; | |
1715 | } | |
1716 | ||
1717 | if (res->READDIR3res_u.resok.reply.eof == 0) { | |
1718 | if (rpc_nfs_readdir_async(nfs->rpc, nfs_opendir_cb, &data->fh, cookie, res->READDIR3res_u.resok.cookieverf, 20000, data) != 0) { | |
1719 | rpc_set_error(nfs->rpc, "RPC error: Failed to send READDIR call for %s", data->path); | |
1720 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1721 | nfs_free_nfsdir(nfsdir); | |
1722 | data->continue_data = NULL; | |
1723 | free_nfs_cb_data(data); | |
1724 | return; | |
1725 | } | |
1726 | return; | |
1727 | } | |
1728 | ||
1729 | /* steal the dirhandle */ | |
1730 | data->continue_data = NULL; | |
1731 | nfsdir->current = nfsdir->entries; | |
1732 | ||
1733 | data->cb(0, nfs, nfsdir, data->private_data); | |
1734 | free_nfs_cb_data(data); | |
1735 | } | |
1736 | ||
1737 | static int nfs_opendir_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
1738 | { | |
1739 | cookieverf3 cv; | |
1740 | ||
1741 | bzero(cv, sizeof(cookieverf3)); | |
1742 | if (rpc_nfs_readdir_async(nfs->rpc, nfs_opendir_cb, &data->fh, 0, (char *)&cv, 20000, data) != 0) { | |
1743 | rpc_set_error(nfs->rpc, "RPC error: Failed to send READDIR call for %s", data->path); | |
1744 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1745 | free_nfs_cb_data(data); | |
1746 | return -1; | |
1747 | } | |
1748 | return 0; | |
1749 | } | |
1750 | ||
1751 | int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data) | |
1752 | { | |
1753 | struct nfsdir *nfsdir; | |
1754 | ||
1755 | nfsdir = malloc(sizeof(struct nfsdir)); | |
1756 | if (nfsdir == NULL) { | |
cbbf9d3e | 1757 | rpc_set_error(nfs->rpc, "failed to allocate buffer for nfsdir"); |
84004dbf RS |
1758 | return -1; |
1759 | } | |
1760 | bzero(nfsdir, sizeof(struct nfsdir)); | |
1761 | ||
1762 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_opendir_continue_internal, nfsdir, free, 0) != 0) { | |
cbbf9d3e RS |
1763 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
1764 | return -1; | |
84004dbf RS |
1765 | } |
1766 | ||
1767 | return 0; | |
1768 | } | |
1769 | ||
1770 | ||
1771 | struct nfsdirent *nfs_readdir(struct nfs_context *nfs _U_, struct nfsdir *nfsdir) | |
1772 | { | |
1773 | struct nfsdirent *nfsdirent = nfsdir->current; | |
1774 | ||
1775 | if (nfsdir->current != NULL) { | |
1776 | nfsdir->current = nfsdir->current->next; | |
1777 | } | |
1778 | return nfsdirent; | |
1779 | } | |
1780 | ||
1781 | ||
1782 | void nfs_closedir(struct nfs_context *nfs _U_, struct nfsdir *nfsdir) | |
1783 | { | |
1784 | nfs_free_nfsdir(nfsdir); | |
1785 | } | |
1786 | ||
1787 | ||
1788 | ||
1789 | ||
1790 | ||
1791 | ||
1792 | ||
1793 | /* | |
1794 | * Async lseek() | |
1795 | */ | |
1796 | struct lseek_cb_data { | |
1797 | struct nfs_context *nfs; | |
1798 | struct nfsfh *nfsfh; | |
1799 | off_t offset; | |
1800 | nfs_cb cb; | |
1801 | void *private_data; | |
1802 | }; | |
1803 | ||
1804 | static void nfs_lseek_1_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1805 | { | |
1806 | GETATTR3res *res; | |
1807 | struct lseek_cb_data *data = private_data; | |
1808 | struct nfs_context *nfs = data->nfs; | |
1809 | ||
1810 | if (status == RPC_STATUS_ERROR) { | |
1811 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1812 | free(data); | |
1813 | return; | |
1814 | } | |
1815 | if (status == RPC_STATUS_CANCEL) { | |
1816 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1817 | free(data); | |
1818 | return; | |
1819 | } | |
1820 | ||
1821 | res = command_data; | |
1822 | if (res->status != NFS3_OK) { | |
1823 | rpc_set_error(nfs->rpc, "NFS: GETATTR failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1824 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1825 | free(data); | |
1826 | return; | |
1827 | } | |
1828 | ||
1829 | data->nfsfh->offset = data->offset + res->GETATTR3res_u.resok.obj_attributes.size; | |
1830 | data->cb(0, nfs, &data->nfsfh->offset, data->private_data); | |
1831 | free(data); | |
1832 | } | |
1833 | ||
1834 | int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, nfs_cb cb, void *private_data) | |
1835 | { | |
1836 | struct lseek_cb_data *data; | |
1837 | ||
1838 | if (whence == SEEK_SET) { | |
1839 | nfsfh->offset = offset; | |
1840 | cb(0, nfs, &nfsfh->offset, private_data); | |
1841 | return 0; | |
1842 | } | |
1843 | if (whence == SEEK_CUR) { | |
1844 | nfsfh->offset += offset; | |
1845 | cb(0, nfs, &nfsfh->offset, private_data); | |
1846 | return 0; | |
1847 | } | |
1848 | ||
1849 | data = malloc(sizeof(struct lseek_cb_data)); | |
1850 | if (data == NULL) { | |
1851 | rpc_set_error(nfs->rpc, "Out Of Memory: Failed to malloc lseek cb data"); | |
1852 | return -1; | |
1853 | } | |
1854 | ||
1855 | data->nfs = nfs; | |
1856 | data->nfsfh = nfsfh; | |
1857 | data->offset = offset; | |
1858 | data->cb = cb; | |
1859 | data->private_data = private_data; | |
1860 | ||
1861 | if (rpc_nfs_getattr_async(nfs->rpc, nfs_lseek_1_cb, &nfsfh->fh, data) != 0) { | |
1862 | rpc_set_error(nfs->rpc, "RPC error: Failed to send LSEEK GETATTR call"); | |
1863 | free(data); | |
cbbf9d3e | 1864 | return -1; |
84004dbf RS |
1865 | } |
1866 | return 0; | |
1867 | } | |
1868 | ||
1869 | ||
1870 | ||
1871 | ||
1872 | /* | |
1873 | * Async statvfs() | |
1874 | */ | |
1875 | static void nfs_statvfs_1_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1876 | { | |
1877 | FSSTAT3res *res; | |
1878 | struct nfs_cb_data *data = private_data; | |
1879 | struct nfs_context *nfs = data->nfs; | |
1880 | struct statvfs svfs; | |
1881 | ||
1882 | if (status == RPC_STATUS_ERROR) { | |
1883 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1884 | free_nfs_cb_data(data); | |
1885 | return; | |
1886 | } | |
1887 | if (status == RPC_STATUS_CANCEL) { | |
1888 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1889 | free_nfs_cb_data(data); | |
1890 | return; | |
1891 | } | |
1892 | ||
1893 | res = command_data; | |
1894 | if (res->status != NFS3_OK) { | |
1895 | rpc_set_error(nfs->rpc, "NFS: FSSTAT of %s failed with %s(%d)", data->saved_path, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1896 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1897 | free_nfs_cb_data(data); | |
1898 | return; | |
1899 | } | |
1900 | ||
1901 | svfs.f_bsize = 4096; | |
1902 | svfs.f_frsize = 4096; | |
1903 | svfs.f_blocks = res->FSSTAT3res_u.resok.tbytes/4096; | |
1904 | svfs.f_bfree = res->FSSTAT3res_u.resok.fbytes/4096; | |
1905 | svfs.f_bavail = res->FSSTAT3res_u.resok.abytes/4096; | |
1906 | svfs.f_files = res->FSSTAT3res_u.resok.tfiles; | |
1907 | svfs.f_ffree = res->FSSTAT3res_u.resok.ffiles; | |
1908 | svfs.f_favail = res->FSSTAT3res_u.resok.afiles; | |
1909 | svfs.f_fsid = 0; | |
1910 | svfs.f_flag = 0; | |
1911 | svfs.f_namemax = 256; | |
1912 | ||
1913 | data->cb(0, nfs, &svfs, data->private_data); | |
1914 | free_nfs_cb_data(data); | |
1915 | } | |
1916 | ||
1917 | static int nfs_statvfs_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
1918 | { | |
1919 | if (rpc_nfs_fsstat_async(nfs->rpc, nfs_statvfs_1_cb, &data->fh, data) != 0) { | |
1920 | rpc_set_error(nfs->rpc, "RPC error: Failed to send FSSTAT call for %s", data->path); | |
1921 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1922 | free_nfs_cb_data(data); | |
1923 | return -1; | |
1924 | } | |
1925 | return 0; | |
1926 | } | |
1927 | ||
1928 | int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data) | |
1929 | { | |
1930 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_statvfs_continue_internal, NULL, NULL, 0) != 0) { | |
cbbf9d3e | 1931 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
84004dbf RS |
1932 | return -1; |
1933 | } | |
1934 | ||
1935 | return 0; | |
1936 | } | |
1937 | ||
1938 | ||
1939 | ||
1940 | ||
1941 | /* | |
1942 | * Async readlink() | |
1943 | */ | |
1944 | static void nfs_readlink_1_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
1945 | { | |
1946 | READLINK3res *res; | |
1947 | struct nfs_cb_data *data = private_data; | |
1948 | struct nfs_context *nfs = data->nfs; | |
1949 | ||
1950 | if (status == RPC_STATUS_ERROR) { | |
1951 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
1952 | free_nfs_cb_data(data); | |
1953 | return; | |
1954 | } | |
1955 | if (status == RPC_STATUS_CANCEL) { | |
1956 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
1957 | free_nfs_cb_data(data); | |
1958 | return; | |
1959 | } | |
1960 | ||
1961 | res = command_data; | |
1962 | if (res->status != NFS3_OK) { | |
1963 | rpc_set_error(nfs->rpc, "NFS: READLINK of %s failed with %s(%d)", data->saved_path, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
1964 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1965 | free_nfs_cb_data(data); | |
1966 | return; | |
1967 | } | |
1968 | ||
1969 | ||
1970 | data->cb(0, nfs, res->READLINK3res_u.resok.data, data->private_data); | |
1971 | free_nfs_cb_data(data); | |
1972 | } | |
1973 | ||
1974 | static int nfs_readlink_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
1975 | { | |
1976 | if (rpc_nfs_readlink_async(nfs->rpc, nfs_readlink_1_cb, &data->fh, data) != 0) { | |
1977 | rpc_set_error(nfs->rpc, "RPC error: Failed to send READLINK call for %s", data->path); | |
1978 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
1979 | free_nfs_cb_data(data); | |
1980 | return -1; | |
1981 | } | |
1982 | return 0; | |
1983 | } | |
1984 | ||
1985 | int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data) | |
1986 | { | |
1987 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_readlink_continue_internal, NULL, NULL, 0) != 0) { | |
cbbf9d3e | 1988 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
84004dbf RS |
1989 | return -1; |
1990 | } | |
1991 | ||
1992 | return 0; | |
1993 | } | |
1994 | ||
1995 | ||
1996 | ||
1997 | ||
1998 | /* | |
1999 | * Async chmod() | |
2000 | */ | |
2001 | static void nfs_chmod_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
2002 | { | |
2003 | struct nfs_cb_data *data = private_data; | |
2004 | struct nfs_context *nfs = data->nfs; | |
2005 | SETATTR3res *res; | |
2006 | ||
2007 | if (status == RPC_STATUS_ERROR) { | |
2008 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
2009 | free_nfs_cb_data(data); | |
2010 | return; | |
2011 | } | |
2012 | if (status == RPC_STATUS_CANCEL) { | |
2013 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
2014 | free_nfs_cb_data(data); | |
2015 | return; | |
2016 | } | |
2017 | ||
2018 | res = command_data; | |
2019 | if (res->status != NFS3_OK) { | |
2020 | rpc_set_error(nfs->rpc, "NFS: SETATTR failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
2021 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2022 | free_nfs_cb_data(data); | |
2023 | return; | |
2024 | } | |
2025 | ||
2026 | data->cb(0, nfs, NULL, data->private_data); | |
2027 | free_nfs_cb_data(data); | |
2028 | } | |
2029 | ||
2030 | static int nfs_chmod_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
2031 | { | |
2032 | SETATTR3args args; | |
2033 | ||
2034 | bzero(&args, sizeof(SETATTR3args)); | |
2035 | args.object.data.data_len = data->fh.data.data_len; | |
2036 | args.object.data.data_val = data->fh.data.data_val; | |
2037 | args.new_attributes.mode.set_it = 1; | |
2038 | args.new_attributes.mode.set_mode3_u.mode = data->continue_int; | |
2039 | ||
2040 | if (rpc_nfs_setattr_async(nfs->rpc, nfs_chmod_cb, &args, data) != 0) { | |
2041 | rpc_set_error(nfs->rpc, "RPC error: Failed to send SETATTR call for %s", data->path); | |
2042 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2043 | free_nfs_cb_data(data); | |
2044 | return -1; | |
2045 | } | |
2046 | return 0; | |
2047 | } | |
2048 | ||
2049 | ||
2050 | int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data) | |
2051 | { | |
2052 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_chmod_continue_internal, NULL, NULL, mode) != 0) { | |
cbbf9d3e | 2053 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
84004dbf RS |
2054 | return -1; |
2055 | } | |
2056 | ||
2057 | return 0; | |
2058 | } | |
2059 | ||
2060 | /* | |
2061 | * Async fchmod() | |
2062 | */ | |
2063 | int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data) | |
2064 | { | |
2065 | struct nfs_cb_data *data; | |
2066 | ||
2067 | data = malloc(sizeof(struct nfs_cb_data)); | |
2068 | if (data == NULL) { | |
cbbf9d3e | 2069 | rpc_set_error(nfs->rpc, "out of memory. failed to allocate memory for nfs mount data"); |
84004dbf RS |
2070 | return -1; |
2071 | } | |
2072 | bzero(data, sizeof(struct nfs_cb_data)); | |
2073 | data->nfs = nfs; | |
2074 | data->cb = cb; | |
2075 | data->private_data = private_data; | |
2076 | data->continue_int = mode; | |
2077 | data->fh.data.data_len = nfsfh->fh.data.data_len; | |
2078 | data->fh.data.data_val = malloc(data->fh.data.data_len); | |
2079 | if (data->fh.data.data_val == NULL) { | |
2080 | rpc_set_error(nfs->rpc, "Out of memory: Failed to allocate fh"); | |
2081 | free_nfs_cb_data(data); | |
2082 | return -1; | |
2083 | } | |
2084 | memcpy(data->fh.data.data_val, nfsfh->fh.data.data_val, data->fh.data.data_len); | |
2085 | ||
2086 | if (nfs_chmod_continue_internal(nfs, data) != 0) { | |
2087 | free_nfs_cb_data(data); | |
2088 | return -1; | |
2089 | } | |
2090 | ||
2091 | return 0; | |
2092 | } | |
2093 | ||
2094 | ||
2095 | ||
2096 | /* | |
2097 | * Async chown() | |
2098 | */ | |
2099 | static void nfs_chown_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
2100 | { | |
2101 | struct nfs_cb_data *data = private_data; | |
2102 | struct nfs_context *nfs = data->nfs; | |
2103 | SETATTR3res *res; | |
2104 | ||
2105 | if (status == RPC_STATUS_ERROR) { | |
2106 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
2107 | free_nfs_cb_data(data); | |
2108 | return; | |
2109 | } | |
2110 | if (status == RPC_STATUS_CANCEL) { | |
2111 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
2112 | free_nfs_cb_data(data); | |
2113 | return; | |
2114 | } | |
2115 | ||
2116 | res = command_data; | |
2117 | if (res->status != NFS3_OK) { | |
2118 | rpc_set_error(nfs->rpc, "NFS: SETATTR failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
2119 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2120 | free_nfs_cb_data(data); | |
2121 | return; | |
2122 | } | |
2123 | ||
2124 | data->cb(0, nfs, NULL, data->private_data); | |
2125 | free_nfs_cb_data(data); | |
2126 | } | |
2127 | ||
2128 | struct nfs_chown_data { | |
2129 | uid_t uid; | |
2130 | gid_t gid; | |
2131 | }; | |
2132 | ||
2133 | static int nfs_chown_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
2134 | { | |
2135 | SETATTR3args args; | |
2136 | struct nfs_chown_data *chown_data = data->continue_data; | |
2137 | ||
2138 | bzero(&args, sizeof(SETATTR3args)); | |
2139 | args.object.data.data_len = data->fh.data.data_len; | |
2140 | args.object.data.data_val = data->fh.data.data_val; | |
2141 | if (chown_data->uid != (uid_t)-1) { | |
2142 | args.new_attributes.uid.set_it = 1; | |
2143 | args.new_attributes.uid.set_uid3_u.uid = chown_data->uid; | |
2144 | } | |
2145 | if (chown_data->gid != (gid_t)-1) { | |
2146 | args.new_attributes.gid.set_it = 1; | |
2147 | args.new_attributes.gid.set_gid3_u.gid = chown_data->gid; | |
2148 | } | |
2149 | ||
2150 | if (rpc_nfs_setattr_async(nfs->rpc, nfs_chown_cb, &args, data) != 0) { | |
2151 | rpc_set_error(nfs->rpc, "RPC error: Failed to send SETATTR call for %s", data->path); | |
2152 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2153 | free_nfs_cb_data(data); | |
2154 | return -1; | |
2155 | } | |
2156 | return 0; | |
2157 | } | |
2158 | ||
2159 | ||
2160 | int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data) | |
2161 | { | |
2162 | struct nfs_chown_data *chown_data; | |
2163 | ||
2164 | chown_data = malloc(sizeof(struct nfs_chown_data)); | |
2165 | if (chown_data == NULL) { | |
cbbf9d3e | 2166 | rpc_set_error(nfs->rpc, "Failed to allocate memory for chown data structure"); |
84004dbf RS |
2167 | return -1; |
2168 | } | |
2169 | ||
2170 | chown_data->uid = uid; | |
2171 | chown_data->gid = gid; | |
2172 | ||
2173 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_chown_continue_internal, chown_data, free, 0) != 0) { | |
cbbf9d3e | 2174 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
84004dbf RS |
2175 | return -1; |
2176 | } | |
2177 | ||
2178 | return 0; | |
2179 | } | |
2180 | ||
2181 | ||
2182 | /* | |
2183 | * Async fchown() | |
2184 | */ | |
2185 | int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data) | |
2186 | { | |
2187 | struct nfs_cb_data *data; | |
2188 | struct nfs_chown_data *chown_data; | |
2189 | ||
2190 | chown_data = malloc(sizeof(struct nfs_chown_data)); | |
2191 | if (chown_data == NULL) { | |
cbbf9d3e | 2192 | rpc_set_error(nfs->rpc, "Failed to allocate memory for chown data structure"); |
84004dbf RS |
2193 | return -1; |
2194 | } | |
2195 | ||
2196 | chown_data->uid = uid; | |
2197 | chown_data->gid = gid; | |
2198 | ||
2199 | ||
2200 | data = malloc(sizeof(struct nfs_cb_data)); | |
2201 | if (data == NULL) { | |
cbbf9d3e | 2202 | rpc_set_error(nfs->rpc, "out of memory. failed to allocate memory for fchown data"); |
84004dbf RS |
2203 | return -1; |
2204 | } | |
2205 | bzero(data, sizeof(struct nfs_cb_data)); | |
2206 | data->nfs = nfs; | |
2207 | data->cb = cb; | |
2208 | data->private_data = private_data; | |
2209 | data->continue_data = chown_data; | |
2210 | data->fh.data.data_len = nfsfh->fh.data.data_len; | |
2211 | data->fh.data.data_val = malloc(data->fh.data.data_len); | |
2212 | if (data->fh.data.data_val == NULL) { | |
2213 | rpc_set_error(nfs->rpc, "Out of memory: Failed to allocate fh"); | |
2214 | free_nfs_cb_data(data); | |
2215 | return -1; | |
2216 | } | |
2217 | memcpy(data->fh.data.data_val, nfsfh->fh.data.data_val, data->fh.data.data_len); | |
2218 | ||
2219 | ||
2220 | if (nfs_chown_continue_internal(nfs, data) != 0) { | |
2221 | free_nfs_cb_data(data); | |
2222 | return -1; | |
2223 | } | |
2224 | ||
2225 | return 0; | |
2226 | } | |
2227 | ||
2228 | ||
2229 | ||
2230 | ||
2231 | ||
2232 | /* | |
2233 | * Async utimes() | |
2234 | */ | |
2235 | static void nfs_utimes_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
2236 | { | |
2237 | struct nfs_cb_data *data = private_data; | |
2238 | struct nfs_context *nfs = data->nfs; | |
2239 | SETATTR3res *res; | |
2240 | ||
2241 | if (status == RPC_STATUS_ERROR) { | |
2242 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
2243 | free_nfs_cb_data(data); | |
2244 | return; | |
2245 | } | |
2246 | if (status == RPC_STATUS_CANCEL) { | |
2247 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
2248 | free_nfs_cb_data(data); | |
2249 | return; | |
2250 | } | |
2251 | ||
2252 | res = command_data; | |
2253 | if (res->status != NFS3_OK) { | |
2254 | rpc_set_error(nfs->rpc, "NFS: SETATTR failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
2255 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2256 | free_nfs_cb_data(data); | |
2257 | return; | |
2258 | } | |
2259 | ||
2260 | data->cb(0, nfs, NULL, data->private_data); | |
2261 | free_nfs_cb_data(data); | |
2262 | } | |
2263 | ||
2264 | static int nfs_utimes_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
2265 | { | |
2266 | SETATTR3args args; | |
2267 | struct timeval *utimes_data = data->continue_data; | |
2268 | ||
2269 | bzero(&args, sizeof(SETATTR3args)); | |
2270 | args.object.data.data_len = data->fh.data.data_len; | |
2271 | args.object.data.data_val = data->fh.data.data_val; | |
2272 | if (utimes_data != NULL) { | |
2273 | args.new_attributes.atime.set_it = SET_TO_CLIENT_TIME; | |
2274 | args.new_attributes.atime.set_atime_u.atime.seconds = utimes_data[0].tv_sec; | |
2275 | args.new_attributes.atime.set_atime_u.atime.nseconds = utimes_data[0].tv_usec * 1000; | |
2276 | args.new_attributes.mtime.set_it = SET_TO_CLIENT_TIME; | |
2277 | args.new_attributes.mtime.set_mtime_u.mtime.seconds = utimes_data[1].tv_sec; | |
2278 | args.new_attributes.mtime.set_mtime_u.mtime.nseconds = utimes_data[1].tv_usec * 1000; | |
2279 | } else { | |
2280 | args.new_attributes.atime.set_it = SET_TO_SERVER_TIME; | |
2281 | args.new_attributes.mtime.set_it = SET_TO_SERVER_TIME; | |
2282 | } | |
2283 | ||
2284 | if (rpc_nfs_setattr_async(nfs->rpc, nfs_utimes_cb, &args, data) != 0) { | |
2285 | rpc_set_error(nfs->rpc, "RPC error: Failed to send SETATTR call for %s", data->path); | |
2286 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2287 | free_nfs_cb_data(data); | |
2288 | return -1; | |
2289 | } | |
2290 | return 0; | |
2291 | } | |
2292 | ||
2293 | ||
2294 | int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data) | |
2295 | { | |
2296 | struct timeval *new_times = NULL; | |
2297 | ||
2298 | if (times != NULL) { | |
2299 | new_times = malloc(sizeof(struct timeval)*2); | |
2300 | if (new_times == NULL) { | |
cbbf9d3e | 2301 | rpc_set_error(nfs->rpc, "Failed to allocate memory for timeval structure"); |
84004dbf RS |
2302 | return -1; |
2303 | } | |
2304 | ||
2305 | memcpy(new_times, times, sizeof(struct timeval)*2); | |
2306 | } | |
2307 | ||
2308 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_utimes_continue_internal, new_times, free, 0) != 0) { | |
cbbf9d3e | 2309 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
84004dbf RS |
2310 | return -1; |
2311 | } | |
2312 | ||
2313 | return 0; | |
2314 | } | |
2315 | ||
2316 | /* | |
2317 | * Async utime() | |
2318 | */ | |
2319 | int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data) | |
2320 | { | |
2321 | struct timeval *new_times = NULL; | |
2322 | ||
2323 | if (times != NULL) { | |
2324 | new_times = malloc(sizeof(struct timeval)*2); | |
2325 | if (new_times == NULL) { | |
cbbf9d3e | 2326 | rpc_set_error(nfs->rpc, "Failed to allocate memory for timeval structure"); |
84004dbf RS |
2327 | return -1; |
2328 | } | |
2329 | ||
2330 | new_times[0].tv_sec = times->actime; | |
2331 | new_times[0].tv_usec = 0; | |
2332 | new_times[1].tv_sec = times->modtime; | |
2333 | new_times[1].tv_usec = 0; | |
2334 | } | |
2335 | ||
2336 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_utimes_continue_internal, new_times, free, 0) != 0) { | |
cbbf9d3e | 2337 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
84004dbf RS |
2338 | return -1; |
2339 | } | |
2340 | ||
2341 | return 0; | |
2342 | } | |
2343 | ||
2344 | ||
2345 | ||
2346 | ||
2347 | ||
2348 | /* | |
2349 | * Async access() | |
2350 | */ | |
2351 | static void nfs_access_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
2352 | { | |
2353 | ACCESS3res *res; | |
2354 | struct nfs_cb_data *data = private_data; | |
2355 | struct nfs_context *nfs = data->nfs; | |
2356 | unsigned int nfsmode = 0; | |
2357 | ||
2358 | if (status == RPC_STATUS_ERROR) { | |
2359 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
2360 | free_nfs_cb_data(data); | |
2361 | return; | |
2362 | } | |
2363 | if (status == RPC_STATUS_CANCEL) { | |
2364 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
2365 | free_nfs_cb_data(data); | |
2366 | return; | |
2367 | } | |
2368 | ||
2369 | res = command_data; | |
2370 | if (res->status != NFS3_OK) { | |
2371 | rpc_set_error(nfs->rpc, "NFS: ACCESS of %s failed with %s(%d)", data->saved_path, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
2372 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2373 | free_nfs_cb_data(data); | |
2374 | return; | |
2375 | } | |
2376 | ||
2377 | if (data->continue_int & R_OK) { | |
2378 | nfsmode |= ACCESS3_READ; | |
2379 | } | |
2380 | if (data->continue_int & W_OK) { | |
2381 | nfsmode |= ACCESS3_MODIFY; | |
2382 | } | |
2383 | if (data->continue_int & X_OK) { | |
2384 | nfsmode |= ACCESS3_EXECUTE; | |
2385 | } | |
2386 | ||
2387 | if (res->ACCESS3res_u.resok.access != nfsmode) { | |
2388 | rpc_set_error(nfs->rpc, "NFS: ACCESS denied. Required access %c%c%c. Allowed access %c%c%c", | |
2389 | nfsmode&ACCESS3_READ?'r':'-', | |
2390 | nfsmode&ACCESS3_MODIFY?'w':'-', | |
2391 | nfsmode&ACCESS3_EXECUTE?'x':'-', | |
2392 | res->ACCESS3res_u.resok.access&ACCESS3_READ?'r':'-', | |
2393 | res->ACCESS3res_u.resok.access&ACCESS3_MODIFY?'w':'-', | |
2394 | res->ACCESS3res_u.resok.access&ACCESS3_EXECUTE?'x':'-'); | |
2395 | data->cb(-EACCES, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2396 | free_nfs_cb_data(data); | |
2397 | return; | |
2398 | } | |
2399 | ||
2400 | data->cb(0, nfs, NULL, data->private_data); | |
2401 | free_nfs_cb_data(data); | |
2402 | } | |
2403 | ||
2404 | static int nfs_access_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
2405 | { | |
2406 | int nfsmode = 0; | |
2407 | ||
2408 | if (data->continue_int & R_OK) { | |
2409 | nfsmode |= ACCESS3_READ; | |
2410 | } | |
2411 | if (data->continue_int & W_OK) { | |
2412 | nfsmode |= ACCESS3_MODIFY; | |
2413 | } | |
2414 | if (data->continue_int & X_OK) { | |
2415 | nfsmode |= ACCESS3_EXECUTE; | |
2416 | } | |
2417 | ||
2418 | if (rpc_nfs_access_async(nfs->rpc, nfs_access_cb, &data->fh, nfsmode, data) != 0) { | |
2419 | rpc_set_error(nfs->rpc, "RPC error: Failed to send OPEN ACCESS call for %s", data->path); | |
2420 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2421 | free_nfs_cb_data(data); | |
2422 | return -1; | |
2423 | } | |
2424 | return 0; | |
2425 | } | |
2426 | ||
2427 | int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data) | |
2428 | { | |
2429 | if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_access_continue_internal, NULL, NULL, mode) != 0) { | |
cbbf9d3e RS |
2430 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
2431 | return -1; | |
84004dbf RS |
2432 | } |
2433 | ||
2434 | return 0; | |
2435 | } | |
2436 | ||
2437 | ||
2438 | ||
2439 | /* | |
2440 | * Async symlink() | |
2441 | */ | |
2442 | struct nfs_symlink_data { | |
2443 | char *oldpath; | |
2444 | char *newpathparent; | |
2445 | char *newpathobject; | |
2446 | }; | |
2447 | ||
2448 | static void free_nfs_symlink_data(void *mem) | |
2449 | { | |
2450 | struct nfs_symlink_data *data = mem; | |
2451 | ||
2452 | if (data->oldpath != NULL) { | |
2453 | free(data->oldpath); | |
2454 | } | |
2455 | if (data->newpathparent != NULL) { | |
2456 | free(data->newpathparent); | |
2457 | } | |
2458 | if (data->newpathobject != NULL) { | |
2459 | free(data->newpathobject); | |
2460 | } | |
2461 | free(data); | |
2462 | } | |
2463 | ||
2464 | static void nfs_symlink_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
2465 | { | |
2466 | SYMLINK3res *res; | |
2467 | struct nfs_cb_data *data = private_data; | |
2468 | struct nfs_context *nfs = data->nfs; | |
2469 | struct nfs_symlink_data *symlink_data = data->continue_data; | |
2470 | ||
2471 | if (status == RPC_STATUS_ERROR) { | |
2472 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
2473 | free_nfs_cb_data(data); | |
2474 | return; | |
2475 | } | |
2476 | if (status == RPC_STATUS_CANCEL) { | |
2477 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
2478 | free_nfs_cb_data(data); | |
2479 | return; | |
2480 | } | |
2481 | ||
2482 | res = command_data; | |
2483 | if (res->status != NFS3_OK) { | |
2484 | rpc_set_error(nfs->rpc, "NFS: SYMLINK %s/%s -> %s failed with %s(%d)", symlink_data->newpathparent, symlink_data->newpathobject, symlink_data->oldpath, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
2485 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2486 | free_nfs_cb_data(data); | |
2487 | return; | |
2488 | } | |
2489 | ||
2490 | data->cb(0, nfs, NULL, data->private_data); | |
2491 | free_nfs_cb_data(data); | |
2492 | } | |
2493 | ||
2494 | static int nfs_symlink_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
2495 | { | |
2496 | struct nfs_symlink_data *symlink_data = data->continue_data; | |
2497 | ||
2498 | if (rpc_nfs_symlink_async(nfs->rpc, nfs_symlink_cb, &data->fh, symlink_data->newpathobject, symlink_data->oldpath, data) != 0) { | |
2499 | rpc_set_error(nfs->rpc, "RPC error: Failed to send SYMLINK call for %s", data->path); | |
2500 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2501 | free_nfs_cb_data(data); | |
2502 | return -1; | |
2503 | } | |
2504 | return 0; | |
2505 | } | |
2506 | ||
2507 | int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data) | |
2508 | { | |
2509 | char *ptr; | |
2510 | struct nfs_symlink_data *symlink_data; | |
2511 | ||
2512 | symlink_data = malloc(sizeof(struct nfs_symlink_data)); | |
2513 | if (symlink_data == NULL) { | |
cbbf9d3e | 2514 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for symlink data"); |
84004dbf RS |
2515 | return -1; |
2516 | } | |
2517 | bzero(symlink_data, sizeof(struct nfs_symlink_data)); | |
2518 | ||
2519 | symlink_data->oldpath = strdup(oldpath); | |
2520 | if (symlink_data->oldpath == NULL) { | |
cbbf9d3e | 2521 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for oldpath"); |
84004dbf | 2522 | free_nfs_symlink_data(symlink_data); |
cbbf9d3e | 2523 | return -1; |
84004dbf RS |
2524 | } |
2525 | ||
2526 | symlink_data->newpathparent = strdup(newpath); | |
2527 | if (symlink_data->newpathparent == NULL) { | |
cbbf9d3e | 2528 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate mode buffer for new path"); |
84004dbf | 2529 | free_nfs_symlink_data(symlink_data); |
cbbf9d3e | 2530 | return -1; |
84004dbf RS |
2531 | } |
2532 | ||
a671a465 | 2533 | ptr = strrchr(symlink_data->newpathparent, '/'); |
84004dbf | 2534 | if (ptr == NULL) { |
cbbf9d3e | 2535 | rpc_set_error(nfs->rpc, "Invalid path %s", oldpath); |
84004dbf | 2536 | free_nfs_symlink_data(symlink_data); |
cbbf9d3e | 2537 | return -1; |
84004dbf RS |
2538 | } |
2539 | *ptr = 0; | |
2540 | ptr++; | |
2541 | ||
2542 | symlink_data->newpathobject = strdup(ptr); | |
2543 | if (symlink_data->newpathobject == NULL) { | |
cbbf9d3e | 2544 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate mode buffer for new path"); |
84004dbf | 2545 | free_nfs_symlink_data(symlink_data); |
cbbf9d3e | 2546 | return -1; |
84004dbf RS |
2547 | } |
2548 | ||
2549 | if (nfs_lookuppath_async(nfs, symlink_data->newpathparent, cb, private_data, nfs_symlink_continue_internal, symlink_data, free_nfs_symlink_data, 0) != 0) { | |
cbbf9d3e RS |
2550 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
2551 | return -1; | |
84004dbf RS |
2552 | } |
2553 | ||
2554 | return 0; | |
2555 | } | |
2556 | ||
2557 | ||
2558 | ||
2559 | /* | |
2560 | * Async rename() | |
2561 | */ | |
2562 | struct nfs_rename_data { | |
2563 | char *oldpath; | |
2564 | char *oldobject; | |
2565 | struct nfs_fh3 olddir; | |
2566 | char *newpath; | |
2567 | char *newobject; | |
2568 | struct nfs_fh3 newdir; | |
2569 | }; | |
2570 | ||
2571 | static void free_nfs_rename_data(void *mem) | |
2572 | { | |
2573 | struct nfs_rename_data *data = mem; | |
2574 | ||
2575 | if (data->oldpath != NULL) { | |
2576 | free(data->oldpath); | |
2577 | } | |
2578 | if (data->olddir.data.data_val != NULL) { | |
2579 | free(data->olddir.data.data_val); | |
2580 | } | |
2581 | if (data->newpath != NULL) { | |
2582 | free(data->newpath); | |
2583 | } | |
2584 | if (data->newdir.data.data_val != NULL) { | |
2585 | free(data->newdir.data.data_val); | |
2586 | } | |
2587 | free(data); | |
2588 | } | |
2589 | ||
2590 | static void nfs_rename_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
2591 | { | |
2592 | RENAME3res *res; | |
2593 | struct nfs_cb_data *data = private_data; | |
2594 | struct nfs_context *nfs = data->nfs; | |
2595 | struct nfs_rename_data *rename_data = data->continue_data; | |
2596 | ||
2597 | if (status == RPC_STATUS_ERROR) { | |
2598 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
2599 | free_nfs_cb_data(data); | |
2600 | return; | |
2601 | } | |
2602 | if (status == RPC_STATUS_CANCEL) { | |
2603 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
2604 | free_nfs_cb_data(data); | |
2605 | return; | |
2606 | } | |
2607 | ||
2608 | res = command_data; | |
2609 | if (res->status != NFS3_OK) { | |
2610 | rpc_set_error(nfs->rpc, "NFS: RENAME %s/%s -> %s/%s failed with %s(%d)", rename_data->oldpath, rename_data->oldobject, rename_data->newpath, rename_data->newobject, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
2611 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2612 | free_nfs_cb_data(data); | |
2613 | return; | |
2614 | } | |
2615 | ||
2616 | data->cb(0, nfs, NULL, data->private_data); | |
2617 | free_nfs_cb_data(data); | |
2618 | } | |
2619 | ||
2620 | static int nfs_rename_continue_2_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
2621 | { | |
2622 | struct nfs_rename_data *rename_data = data->continue_data; | |
2623 | ||
2624 | /* steal the filehandle */ | |
2625 | rename_data->newdir.data.data_len = data->fh.data.data_len; | |
2626 | rename_data->newdir.data.data_val = data->fh.data.data_val; | |
2627 | data->fh.data.data_val = NULL; | |
2628 | ||
2629 | if (rpc_nfs_rename_async(nfs->rpc, nfs_rename_cb, &rename_data->olddir, rename_data->oldobject, &rename_data->newdir, rename_data->newobject, data) != 0) { | |
2630 | rpc_set_error(nfs->rpc, "RPC error: Failed to send RENAME call for %s", data->path); | |
2631 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2632 | free_nfs_cb_data(data); | |
2633 | return -1; | |
2634 | } | |
2635 | return 0; | |
2636 | } | |
2637 | ||
2638 | ||
2639 | static int nfs_rename_continue_1_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
2640 | { | |
2641 | struct nfs_rename_data *rename_data = data->continue_data; | |
2642 | ||
2643 | /* steal the filehandle */ | |
2644 | rename_data->olddir.data.data_len = data->fh.data.data_len; | |
2645 | rename_data->olddir.data.data_val = data->fh.data.data_val; | |
2646 | data->fh.data.data_val = NULL; | |
2647 | ||
2648 | if (nfs_lookuppath_async(nfs, rename_data->newpath, data->cb, data->private_data, nfs_rename_continue_2_internal, rename_data, free_nfs_rename_data, 0) != 0) { | |
2649 | rpc_set_error(nfs->rpc, "RPC error: Failed to send LOOKUP call for %s", rename_data->newpath); | |
2650 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2651 | free_nfs_cb_data(data); | |
2652 | return -1; | |
2653 | } | |
2654 | data->continue_data = NULL; | |
2655 | free_nfs_cb_data(data); | |
2656 | ||
2657 | return 0; | |
2658 | } | |
2659 | ||
2660 | ||
2661 | int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data) | |
2662 | { | |
2663 | char *ptr; | |
2664 | struct nfs_rename_data *rename_data; | |
2665 | ||
2666 | rename_data = malloc(sizeof(struct nfs_rename_data)); | |
2667 | if (rename_data == NULL) { | |
cbbf9d3e | 2668 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for rename data"); |
84004dbf RS |
2669 | return -1; |
2670 | } | |
2671 | bzero(rename_data, sizeof(struct nfs_rename_data)); | |
2672 | ||
2673 | rename_data->oldpath = strdup(oldpath); | |
2674 | if (rename_data->oldpath == NULL) { | |
cbbf9d3e | 2675 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for oldpath"); |
84004dbf | 2676 | free_nfs_rename_data(rename_data); |
cbbf9d3e | 2677 | return -1; |
84004dbf | 2678 | } |
a671a465 | 2679 | ptr = strrchr(rename_data->oldpath, '/'); |
84004dbf | 2680 | if (ptr == NULL) { |
cbbf9d3e | 2681 | rpc_set_error(nfs->rpc, "Invalid path %s", oldpath); |
84004dbf | 2682 | free_nfs_rename_data(rename_data); |
cbbf9d3e | 2683 | return -1; |
84004dbf RS |
2684 | } |
2685 | *ptr = 0; | |
2686 | ptr++; | |
2687 | rename_data->oldobject = ptr; | |
2688 | ||
2689 | ||
2690 | rename_data->newpath = strdup(newpath); | |
2691 | if (rename_data->newpath == NULL) { | |
cbbf9d3e | 2692 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for newpath"); |
84004dbf | 2693 | free_nfs_rename_data(rename_data); |
cbbf9d3e | 2694 | return -1; |
84004dbf | 2695 | } |
a671a465 | 2696 | ptr = strrchr(rename_data->newpath, '/'); |
84004dbf | 2697 | if (ptr == NULL) { |
cbbf9d3e | 2698 | rpc_set_error(nfs->rpc, "Invalid path %s", newpath); |
84004dbf | 2699 | free_nfs_rename_data(rename_data); |
cbbf9d3e | 2700 | return -1; |
84004dbf RS |
2701 | } |
2702 | *ptr = 0; | |
2703 | ptr++; | |
2704 | rename_data->newobject = ptr; | |
2705 | ||
2706 | ||
2707 | if (nfs_lookuppath_async(nfs, rename_data->oldpath, cb, private_data, nfs_rename_continue_1_internal, rename_data, free_nfs_rename_data, 0) != 0) { | |
cbbf9d3e RS |
2708 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
2709 | return -1; | |
84004dbf RS |
2710 | } |
2711 | ||
2712 | return 0; | |
2713 | } | |
2714 | ||
2715 | ||
2716 | /* | |
2717 | * Async link() | |
2718 | */ | |
2719 | struct nfs_link_data { | |
2720 | char *oldpath; | |
2721 | struct nfs_fh3 oldfh; | |
2722 | char *newpath; | |
2723 | char *newobject; | |
2724 | struct nfs_fh3 newdir; | |
2725 | }; | |
2726 | ||
2727 | static void free_nfs_link_data(void *mem) | |
2728 | { | |
2729 | struct nfs_link_data *data = mem; | |
2730 | ||
2731 | if (data->oldpath != NULL) { | |
2732 | free(data->oldpath); | |
2733 | } | |
2734 | if (data->oldfh.data.data_val != NULL) { | |
2735 | free(data->oldfh.data.data_val); | |
2736 | } | |
2737 | if (data->newpath != NULL) { | |
2738 | free(data->newpath); | |
2739 | } | |
2740 | if (data->newdir.data.data_val != NULL) { | |
2741 | free(data->newdir.data.data_val); | |
2742 | } | |
2743 | free(data); | |
2744 | } | |
2745 | ||
2746 | static void nfs_link_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data) | |
2747 | { | |
2748 | LINK3res *res; | |
2749 | struct nfs_cb_data *data = private_data; | |
2750 | struct nfs_context *nfs = data->nfs; | |
2751 | struct nfs_link_data *link_data = data->continue_data; | |
2752 | ||
2753 | if (status == RPC_STATUS_ERROR) { | |
2754 | data->cb(-EFAULT, nfs, command_data, data->private_data); | |
2755 | free_nfs_cb_data(data); | |
2756 | return; | |
2757 | } | |
2758 | if (status == RPC_STATUS_CANCEL) { | |
2759 | data->cb(-EINTR, nfs, "Command was cancelled", data->private_data); | |
2760 | free_nfs_cb_data(data); | |
2761 | return; | |
2762 | } | |
2763 | ||
2764 | res = command_data; | |
2765 | if (res->status != NFS3_OK) { | |
2766 | rpc_set_error(nfs->rpc, "NFS: LINK %s -> %s/%s failed with %s(%d)", link_data->oldpath, link_data->newpath, link_data->newobject, nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); | |
2767 | data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2768 | free_nfs_cb_data(data); | |
2769 | return; | |
2770 | } | |
2771 | ||
2772 | data->cb(0, nfs, NULL, data->private_data); | |
2773 | free_nfs_cb_data(data); | |
2774 | } | |
2775 | ||
2776 | static int nfs_link_continue_2_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
2777 | { | |
2778 | struct nfs_link_data *link_data = data->continue_data; | |
2779 | ||
2780 | /* steal the filehandle */ | |
2781 | link_data->newdir.data.data_len = data->fh.data.data_len; | |
2782 | link_data->newdir.data.data_val = data->fh.data.data_val; | |
2783 | data->fh.data.data_val = NULL; | |
2784 | ||
2785 | if (rpc_nfs_link_async(nfs->rpc, nfs_link_cb, &link_data->oldfh, &link_data->newdir, link_data->newobject, data) != 0) { | |
2786 | rpc_set_error(nfs->rpc, "RPC error: Failed to send LINK call for %s", data->path); | |
2787 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2788 | free_nfs_cb_data(data); | |
2789 | return -1; | |
2790 | } | |
2791 | return 0; | |
2792 | } | |
2793 | ||
2794 | ||
2795 | static int nfs_link_continue_1_internal(struct nfs_context *nfs, struct nfs_cb_data *data) | |
2796 | { | |
2797 | struct nfs_link_data *link_data = data->continue_data; | |
2798 | ||
2799 | /* steal the filehandle */ | |
2800 | link_data->oldfh.data.data_len = data->fh.data.data_len; | |
2801 | link_data->oldfh.data.data_val = data->fh.data.data_val; | |
2802 | data->fh.data.data_val = NULL; | |
2803 | ||
2804 | if (nfs_lookuppath_async(nfs, link_data->newpath, data->cb, data->private_data, nfs_link_continue_2_internal, link_data, free_nfs_link_data, 0) != 0) { | |
2805 | rpc_set_error(nfs->rpc, "RPC error: Failed to send LOOKUP call for %s", link_data->newpath); | |
2806 | data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data); | |
2807 | free_nfs_cb_data(data); | |
2808 | return -1; | |
2809 | } | |
2810 | data->continue_data = NULL; | |
2811 | free_nfs_cb_data(data); | |
2812 | ||
2813 | return 0; | |
2814 | } | |
2815 | ||
2816 | ||
2817 | int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data) | |
2818 | { | |
2819 | char *ptr; | |
2820 | struct nfs_link_data *link_data; | |
2821 | ||
2822 | link_data = malloc(sizeof(struct nfs_link_data)); | |
2823 | if (link_data == NULL) { | |
cbbf9d3e | 2824 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for link data"); |
84004dbf RS |
2825 | return -1; |
2826 | } | |
2827 | bzero(link_data, sizeof(struct nfs_link_data)); | |
2828 | ||
2829 | link_data->oldpath = strdup(oldpath); | |
2830 | if (link_data->oldpath == NULL) { | |
cbbf9d3e | 2831 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for oldpath"); |
84004dbf | 2832 | free_nfs_link_data(link_data); |
cbbf9d3e | 2833 | return -1; |
84004dbf RS |
2834 | } |
2835 | ||
2836 | link_data->newpath = strdup(newpath); | |
2837 | if (link_data->newpath == NULL) { | |
cbbf9d3e | 2838 | rpc_set_error(nfs->rpc, "Out of memory, failed to allocate buffer for newpath"); |
84004dbf | 2839 | free_nfs_link_data(link_data); |
cbbf9d3e | 2840 | return -1; |
84004dbf | 2841 | } |
a671a465 | 2842 | ptr = strrchr(link_data->newpath, '/'); |
84004dbf | 2843 | if (ptr == NULL) { |
cbbf9d3e | 2844 | rpc_set_error(nfs->rpc, "Invalid path %s", newpath); |
84004dbf | 2845 | free_nfs_link_data(link_data); |
cbbf9d3e | 2846 | return -1; |
84004dbf RS |
2847 | } |
2848 | *ptr = 0; | |
2849 | ptr++; | |
2850 | link_data->newobject = ptr; | |
2851 | ||
2852 | ||
2853 | if (nfs_lookuppath_async(nfs, link_data->oldpath, cb, private_data, nfs_link_continue_1_internal, link_data, free_nfs_link_data, 0) != 0) { | |
cbbf9d3e RS |
2854 | rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); |
2855 | return -1; | |
84004dbf RS |
2856 | } |
2857 | ||
2858 | return 0; | |
2859 | } | |
2860 | ||
2861 | ||
2862 | //qqq replace later with lseek() | |
2863 | off_t nfs_get_current_offset(struct nfsfh *nfsfh) | |
2864 | { | |
2865 | return nfsfh->offset; | |
2866 | } | |
2867 | ||
17ef62fa RS |
2868 | |
2869 | ||
2870 | /* | |
2871 | * Get the maximum supported READ3 size by the server | |
2872 | */ | |
2873 | size_t nfs_get_readmax(struct nfs_context *nfs) | |
2874 | { | |
2875 | return nfs->readmax; | |
2876 | } | |
2877 | ||
2878 | /* | |
2879 | * Get the maximum supported WRITE3 size by the server | |
2880 | */ | |
2881 | size_t nfs_get_writemax(struct nfs_context *nfs) | |
2882 | { | |
2883 | return nfs->writemax; | |
2884 | } | |
1896d37b RS |
2885 | |
2886 | void nfs_set_error(struct nfs_context *nfs, char *error_string, ...) | |
2887 | { | |
2888 | va_list ap; | |
1e8994af | 2889 | char *str = NULL; |
1896d37b | 2890 | |
1e8994af RS |
2891 | va_start(ap, error_string); |
2892 | vasprintf(&str, error_string, ap); | |
1896d37b RS |
2893 | if (nfs->rpc->error_string != NULL) { |
2894 | free(nfs->rpc->error_string); | |
2895 | } | |
1896d37b RS |
2896 | nfs->rpc->error_string = str; |
2897 | va_end(ap); | |
2898 | } | |
7f0242ca RS |
2899 | |
2900 | ||
2901 | ||
2902 | struct mount_cb_data { | |
2903 | rpc_cb cb; | |
2904 | void *private_data; | |
2905 | char *server; | |
2906 | }; | |
2907 | ||
2908 | static void free_mount_cb_data(struct mount_cb_data *data) | |
2909 | { | |
2910 | if (data->server != NULL) { | |
2911 | free(data->server); | |
2912 | data->server = NULL; | |
2913 | } | |
2914 | ||
2915 | free(data); | |
2916 | } | |
2917 | ||
2918 | static void mount_export_5_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
2919 | { | |
2920 | struct mount_cb_data *data = private_data; | |
2921 | ||
2922 | if (status == RPC_STATUS_ERROR) { | |
2923 | data->cb(rpc, -EFAULT, command_data, data->private_data); | |
2924 | free_mount_cb_data(data); | |
2925 | return; | |
2926 | } | |
2927 | if (status == RPC_STATUS_CANCEL) { | |
2928 | data->cb(rpc, -EINTR, "Command was cancelled", data->private_data); | |
2929 | free_mount_cb_data(data); | |
2930 | return; | |
2931 | } | |
2932 | ||
2933 | data->cb(rpc, 0, command_data, data->private_data); | |
2934 | if (rpc_disconnect(rpc, "normal disconnect") != 0) { | |
2935 | rpc_set_error(rpc, "Failed to disconnect\n"); | |
2936 | } | |
2937 | free_mount_cb_data(data); | |
2938 | } | |
2939 | ||
2940 | static void mount_export_4_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
2941 | { | |
2942 | struct mount_cb_data *data = private_data; | |
2943 | ||
2944 | if (status == RPC_STATUS_ERROR) { | |
2945 | data->cb(rpc, -EFAULT, command_data, data->private_data); | |
2946 | free_mount_cb_data(data); | |
2947 | return; | |
2948 | } | |
2949 | if (status == RPC_STATUS_CANCEL) { | |
2950 | data->cb(rpc, -EINTR, "Command was cancelled", data->private_data); | |
2951 | free_mount_cb_data(data); | |
2952 | return; | |
2953 | } | |
2954 | ||
2955 | if (rpc_mount_export_async(rpc, mount_export_5_cb, data) != 0) { | |
2956 | data->cb(rpc, -ENOMEM, command_data, data->private_data); | |
2957 | free_mount_cb_data(data); | |
2958 | return; | |
2959 | } | |
2960 | } | |
2961 | ||
2962 | static void mount_export_3_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
2963 | { | |
2964 | struct mount_cb_data *data = private_data; | |
2965 | uint32_t mount_port; | |
2966 | ||
2967 | if (status == RPC_STATUS_ERROR) { | |
2968 | data->cb(rpc, -EFAULT, command_data, data->private_data); | |
2969 | free_mount_cb_data(data); | |
2970 | return; | |
2971 | } | |
2972 | if (status == RPC_STATUS_CANCEL) { | |
2973 | data->cb(rpc, -EINTR, "Command was cancelled", data->private_data); | |
2974 | free_mount_cb_data(data); | |
2975 | return; | |
2976 | } | |
2977 | ||
2978 | mount_port = *(uint32_t *)command_data; | |
2979 | if (mount_port == 0) { | |
2980 | rpc_set_error(rpc, "RPC error. Mount program is not available"); | |
2981 | data->cb(rpc, -ENOENT, command_data, data->private_data); | |
2982 | free_mount_cb_data(data); | |
2983 | return; | |
2984 | } | |
2985 | ||
2986 | rpc_disconnect(rpc, "normal disconnect"); | |
2987 | if (rpc_connect_async(rpc, data->server, mount_port, mount_export_4_cb, data) != 0) { | |
2988 | data->cb(rpc, -ENOMEM, command_data, data->private_data); | |
2989 | free_mount_cb_data(data); | |
2990 | return; | |
2991 | } | |
2992 | } | |
2993 | ||
2994 | static void mount_export_2_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
2995 | { | |
2996 | struct mount_cb_data *data = private_data; | |
2997 | ||
2998 | if (status == RPC_STATUS_ERROR) { | |
2999 | data->cb(rpc, -EFAULT, command_data, data->private_data); | |
3000 | free_mount_cb_data(data); | |
3001 | return; | |
3002 | } | |
3003 | if (status == RPC_STATUS_CANCEL) { | |
3004 | data->cb(rpc, -EINTR, "Command was cancelled", data->private_data); | |
3005 | free_mount_cb_data(data); | |
3006 | return; | |
3007 | } | |
3008 | ||
3009 | if (rpc_pmap_getport_async(rpc, MOUNT_PROGRAM, MOUNT_V3, mount_export_3_cb, private_data) != 0) { | |
3010 | data->cb(rpc, -ENOMEM, command_data, data->private_data); | |
3011 | free_mount_cb_data(data); | |
3012 | return; | |
3013 | } | |
3014 | } | |
3015 | ||
3016 | static void mount_export_1_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data) | |
3017 | { | |
3018 | struct mount_cb_data *data = private_data; | |
3019 | ||
3020 | if (status == RPC_STATUS_ERROR) { | |
3021 | data->cb(rpc, -EFAULT, command_data, data->private_data); | |
3022 | free_mount_cb_data(data); | |
3023 | return; | |
3024 | } | |
3025 | if (status == RPC_STATUS_CANCEL) { | |
3026 | data->cb(rpc, -EINTR, "Command was cancelled", data->private_data); | |
3027 | free_mount_cb_data(data); | |
3028 | return; | |
3029 | } | |
3030 | ||
3031 | if (rpc_pmap_null_async(rpc, mount_export_2_cb, data) != 0) { | |
3032 | data->cb(rpc, -ENOMEM, command_data, data->private_data); | |
3033 | free_mount_cb_data(data); | |
3034 | return; | |
3035 | } | |
3036 | } | |
3037 | ||
3038 | int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data) | |
3039 | { | |
3040 | struct mount_cb_data *data; | |
3041 | ||
3042 | data = malloc(sizeof(struct mount_cb_data)); | |
3043 | if (data == NULL) { | |
3044 | return -1; | |
3045 | } | |
3046 | bzero(data, sizeof(struct mount_cb_data)); | |
3047 | data->cb = cb; | |
3048 | data->private_data = private_data; | |
3049 | data->server = strdup(server); | |
3050 | if (data->server == NULL) { | |
3051 | free_mount_cb_data(data); | |
3052 | return -1; | |
3053 | } | |
3054 | if (rpc_connect_async(rpc, data->server, 111, mount_export_1_cb, data) != 0) { | |
3055 | free_mount_cb_data(data); | |
3056 | return -1; | |
3057 | } | |
3058 | ||
3059 | return 0; | |
3060 | } | |
3061 | ||
df5af25f RS |
3062 | struct rpc_context *nfs_get_rpc_context(struct nfs_context *nfs) |
3063 | { | |
3064 | return nfs->rpc; | |
3065 | } | |
3066 | ||
b077fdeb RS |
3067 | const char *nfs_get_server(struct nfs_context *nfs) { |
3068 | return nfs->server; | |
3069 | } | |
3070 | ||
3071 | const char *nfs_get_export(struct nfs_context *nfs) { | |
3072 | return nfs->export; | |
3073 | } |