Coverage Report

Created: 2026-12-01 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libnfs/nfs/nfs.c
Line
Count
Source
1
/* -*-  mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil;  -*- */
2
/*
3
   Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
4
5
   This program is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU Lesser General Public License as published by
7
   the Free Software Foundation; either version 2.1 of the License, or
8
   (at your option) any later version.
9
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU Lesser General Public License for more details.
14
15
   You should have received a copy of the GNU Lesser General Public License
16
   along with this program; if not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifdef HAVE_CONFIG_H
20
#include "config.h"
21
#endif
22
23
#ifdef PS2_EE
24
#include "ps2_compat.h"
25
#endif
26
27
#ifdef WIN32
28
#include <win32/win32_compat.h>
29
#else
30
#include <sys/stat.h>
31
#endif/*WIN32*/
32
33
#include <stdio.h>
34
#include <errno.h>
35
#include <string.h>
36
#include <stdlib.h>
37
#include "libnfs-zdr.h"
38
#include "libnfs.h"
39
#include "libnfs-raw.h"
40
#include "libnfs-private.h"
41
#include "libnfs-raw-nfs.h"
42
43
char *nfsstat3_to_str(int error)
44
0
{
45
0
  switch (error) {
46
0
  case NFS3_OK: return "NFS3_OK"; break;
47
0
  case NFS3ERR_PERM: return "NFS3ERR_PERM"; break;
48
0
  case NFS3ERR_NOENT: return "NFS3ERR_NOENT"; break;
49
0
  case NFS3ERR_IO: return "NFS3ERR_IO"; break;
50
0
  case NFS3ERR_NXIO: return "NFS3ERR_NXIO"; break;
51
0
  case NFS3ERR_ACCES: return "NFS3ERR_ACCES"; break;
52
0
  case NFS3ERR_EXIST: return "NFS3ERR_EXIST"; break;
53
0
  case NFS3ERR_XDEV: return "NFS3ERR_XDEV"; break;
54
0
  case NFS3ERR_NODEV: return "NFS3ERR_NODEV"; break;
55
0
  case NFS3ERR_NOTDIR: return "NFS3ERR_NOTDIR"; break;
56
0
  case NFS3ERR_ISDIR: return "NFS3ERR_ISDIR"; break;
57
0
  case NFS3ERR_INVAL: return "NFS3ERR_INVAL"; break;
58
0
  case NFS3ERR_FBIG: return "NFS3ERR_FBIG"; break;
59
0
  case NFS3ERR_NOSPC: return "NFS3ERR_NOSPC"; break;
60
0
  case NFS3ERR_ROFS: return "NFS3ERR_ROFS"; break;
61
0
  case NFS3ERR_MLINK: return "NFS3ERR_MLINK"; break;
62
0
  case NFS3ERR_NAMETOOLONG: return "NFS3ERR_NAMETOOLONG"; break;
63
0
  case NFS3ERR_NOTEMPTY: return "NFS3ERR_NOTEMPTY"; break;
64
0
  case NFS3ERR_DQUOT: return "NFS3ERR_DQUOT"; break;
65
0
  case NFS3ERR_STALE: return "NFS3ERR_STALE"; break;
66
0
  case NFS3ERR_REMOTE: return "NFS3ERR_REMOTE"; break;
67
0
  case NFS3ERR_BADHANDLE: return "NFS3ERR_BADHANDLE"; break;
68
0
  case NFS3ERR_NOT_SYNC: return "NFS3ERR_NOT_SYNC"; break;
69
0
  case NFS3ERR_BAD_COOKIE: return "NFS3ERR_BAD_COOKIE"; break;
70
0
  case NFS3ERR_NOTSUPP: return "NFS3ERR_NOTSUPP"; break;
71
0
  case NFS3ERR_TOOSMALL: return "NFS3ERR_TOOSMALL"; break;
72
0
  case NFS3ERR_SERVERFAULT: return "NFS3ERR_SERVERFAULT"; break;
73
0
  case NFS3ERR_BADTYPE: return "NFS3ERR_BADTYPE"; break;
74
0
  case NFS3ERR_JUKEBOX: return "NFS3ERR_JUKEBOX"; break;
75
0
  };
76
0
  return "unknown nfs error";
77
0
}
78
79
int nfsstat3_to_errno(int error)
80
0
{
81
0
  switch (error) {
82
0
  case NFS3_OK:             return 0; break;
83
0
  case NFS3ERR_PERM:        return -EPERM; break;
84
0
  case NFS3ERR_NOENT:       return -ENOENT; break;
85
0
  case NFS3ERR_IO:          return -EIO; break;
86
0
  case NFS3ERR_NXIO:        return -ENXIO; break;
87
0
  case NFS3ERR_ACCES:       return -EACCES; break;
88
0
  case NFS3ERR_EXIST:       return -EEXIST; break;
89
0
  case NFS3ERR_XDEV:        return -EXDEV; break;
90
0
  case NFS3ERR_NODEV:       return -ENODEV; break;
91
0
  case NFS3ERR_NOTDIR:      return -ENOTDIR; break;
92
0
  case NFS3ERR_ISDIR:       return -EISDIR; break;
93
0
  case NFS3ERR_INVAL:       return -EINVAL; break;
94
0
  case NFS3ERR_FBIG:        return -EFBIG; break;
95
0
  case NFS3ERR_NOSPC:       return -ENOSPC; break;
96
0
  case NFS3ERR_ROFS:        return -EROFS; break;
97
0
  case NFS3ERR_MLINK:       return -EMLINK; break;
98
0
  case NFS3ERR_NAMETOOLONG: return -ENAMETOOLONG; break;
99
0
  case NFS3ERR_NOTEMPTY:    return -ENOTEMPTY; break;
100
0
  case NFS3ERR_DQUOT:       return -ERANGE; break;
101
0
  case NFS3ERR_STALE:       return -ESTALE; break;
102
0
  case NFS3ERR_REMOTE:      return -EIO; break;
103
0
  case NFS3ERR_BADHANDLE:   return -EIO; break;
104
0
  case NFS3ERR_NOT_SYNC:    return -EIO; break;
105
0
  case NFS3ERR_BAD_COOKIE:  return -EIO; break;
106
0
  case NFS3ERR_NOTSUPP:     return -EINVAL; break;
107
0
  case NFS3ERR_TOOSMALL:    return -EIO; break;
108
0
  case NFS3ERR_SERVERFAULT: return -EIO; break;
109
0
  case NFS3ERR_BADTYPE:     return -EINVAL; break;
110
0
  case NFS3ERR_JUKEBOX:     return -EAGAIN; break;
111
0
  };
112
0
  return -ERANGE;
113
0
}
114
115
116
/*
117
 * NFSv3
118
 */
119
struct rpc_pdu *rpc_nfs3_null_task(struct rpc_context *rpc, rpc_cb cb,
120
                                   void *private_data)
121
0
{
122
0
  struct rpc_pdu *pdu;
123
124
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_NULL, cb, private_data, (zdrproc_t)zdr_void, 0);
125
0
  if (pdu == NULL) {
126
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/NULL call");
127
0
    return NULL;
128
0
  }
129
130
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
131
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/NULL call");
132
0
    return NULL;
133
0
  }
134
135
0
  return pdu;
136
0
}
137
138
struct rpc_pdu *rpc_nfs3_getattr_task(struct rpc_context *rpc, rpc_cb cb,
139
                                      struct GETATTR3args *args,
140
                                      void *private_data)
141
0
{
142
0
  struct rpc_pdu *pdu;
143
144
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_GETATTR, cb, private_data, (zdrproc_t)zdr_GETATTR3res, sizeof(GETATTR3res));
145
0
  if (pdu == NULL) {
146
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/GETATTR call");
147
0
    return NULL;
148
0
  }
149
150
0
  if (zdr_GETATTR3args(&pdu->zdr, args) == 0) {
151
0
    rpc_set_error(rpc, "ZDR error: Failed to encode GETATTR3args");
152
0
    rpc_free_pdu(rpc, pdu);
153
0
    return NULL;
154
0
  }
155
156
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
157
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/GETATTR call");
158
0
    return NULL;
159
0
  }
160
161
0
  return pdu;
162
0
}
163
164
struct rpc_pdu *rpc_nfs3_pathconf_task(struct rpc_context *rpc, rpc_cb cb,
165
                                       struct PATHCONF3args *args,
166
                                       void *private_data)
167
0
{
168
0
  struct rpc_pdu *pdu;
169
170
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_PATHCONF, cb, private_data, (zdrproc_t)zdr_PATHCONF3res, sizeof(PATHCONF3res));
171
0
  if (pdu == NULL) {
172
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/PATHCONF call");
173
0
    return NULL;
174
0
  }
175
176
0
  if (zdr_PATHCONF3args(&pdu->zdr, args) == 0) {
177
0
    rpc_set_error(rpc, "ZDR error: Failed to encode PATHCONF3args");
178
0
    rpc_free_pdu(rpc, pdu);
179
0
    return NULL;
180
0
  }
181
182
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
183
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/PATHCONF call");
184
0
    return NULL;
185
0
  }
186
187
0
  return pdu;
188
0
}
189
190
struct rpc_pdu *rpc_nfs3_lookup_task(struct rpc_context *rpc, rpc_cb cb,
191
                                     struct LOOKUP3args *args,
192
                                     void *private_data)
193
0
{
194
0
  struct rpc_pdu *pdu;
195
196
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_LOOKUP, cb, private_data, (zdrproc_t)zdr_LOOKUP3res, sizeof(LOOKUP3res));
197
0
  if (pdu == NULL) {
198
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/LOOKUP call");
199
0
    return NULL;
200
0
  }
201
202
0
  if (zdr_LOOKUP3args(&pdu->zdr, args) == 0) {
203
0
    rpc_set_error(rpc, "ZDR error: Failed to encode LOOKUP3args");
204
0
    rpc_free_pdu(rpc, pdu);
205
0
    return NULL;
206
0
  }
207
208
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
209
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/LOOKUP call");
210
0
    return NULL;
211
0
  }
212
213
0
  return pdu;
214
0
}
215
216
struct rpc_pdu *rpc_nfs3_access_task(struct rpc_context *rpc, rpc_cb cb,
217
                                     struct ACCESS3args *args,
218
                                     void *private_data)
219
0
{
220
0
  struct rpc_pdu *pdu;
221
222
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_ACCESS, cb, private_data, (zdrproc_t)zdr_ACCESS3res, sizeof(ACCESS3res));
223
0
  if (pdu == NULL) {
224
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/ACCESS call");
225
0
    return NULL;
226
0
  }
227
228
0
  if (zdr_ACCESS3args(&pdu->zdr, args) == 0) {
229
0
    rpc_set_error(rpc, "ZDR error: Failed to encode ACCESS3args");
230
0
    rpc_free_pdu(rpc, pdu);
231
0
    return NULL;
232
0
  }
233
234
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
235
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/ACCESS call");
236
0
    return NULL;
237
0
  }
238
239
0
  return pdu;
240
0
}
241
242
uint32_t
243
zdr_READ3resok_zero_copy (ZDR *zdrs, READ3resok *objp)
244
0
{
245
0
        uint32_t pos;
246
247
0
        if (!zdr_post_op_attr (zdrs, &objp->file_attributes))
248
0
                return FALSE;
249
0
        if (!zdr_count3 (zdrs, &objp->count))
250
0
                return FALSE;
251
0
        if (!zdr_bool (zdrs, &objp->eof))
252
0
                return FALSE;
253
        /* Peek at the data length, the data itself goes to the caller's buffers */
254
0
        pos = zdr_getpos(zdrs);
255
0
        if (!zdr_uint32_t (zdrs, &objp->data.data_len))
256
0
                return FALSE;
257
0
        zdr_setpos(zdrs, pos);
258
0
  return TRUE;
259
0
}
260
261
uint32_t
262
zdr_READ3res_zero_copy (ZDR *zdrs, READ3res *objp)
263
0
{
264
0
        if (!zdr_nfsstat3 (zdrs, &objp->status))
265
0
                return FALSE;
266
0
  switch (objp->status) {
267
0
  case NFS3_OK:
268
0
     if (!zdr_READ3resok_zero_copy (zdrs, &objp->READ3res_u.resok))
269
0
       return FALSE;
270
0
    break;
271
0
  default:
272
0
     if (!zdr_READ3resfail (zdrs, &objp->READ3res_u.resfail))
273
0
       return FALSE;
274
0
    break;
275
0
  }
276
0
  return TRUE;
277
0
}
278
279
struct rpc_pdu *
280
rpc_nfs3_readv_task(struct rpc_context *rpc, rpc_cb cb,
281
                    const struct iovec *iov, int iovcnt,
282
                    struct READ3args *args, void *private_data)
283
0
{
284
0
  struct rpc_pdu *pdu;
285
0
  int i;
286
287
0
        if (iovcnt == 0 || iov == NULL) {
288
0
    rpc_set_error(rpc, "Invalid arguments: iov and iovcnt must be specified");
289
0
    return NULL;
290
0
        }
291
292
        /*
293
         * It's disallowed since it's not tested. It may work.
294
         */
295
0
        if (iovcnt > 1 && rpc->is_udp) {
296
0
    rpc_set_error(rpc, "Invalid arguments: Vectored read not supported for UDP transport");
297
0
    return NULL;
298
0
        }
299
300
        /*
301
         * Don't accept more iovecs than what readv() can handle.
302
         */
303
0
        if (iovcnt > RPC_MAX_VECTORS) {
304
0
    rpc_set_error(rpc, "Invalid arguments: iovcnt must be <= %d", RPC_MAX_VECTORS);
305
0
    return NULL;
306
0
        }
307
308
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READ, cb, private_data, (zdrproc_t)zdr_READ3res_zero_copy, sizeof(READ3res));
309
0
  if (pdu == NULL) {
310
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/READ call");
311
0
    return NULL;
312
0
  }
313
0
  if (zdr_READ3args(&pdu->zdr, args) == 0) {
314
0
    rpc_set_error(rpc, "ZDR error: Failed to encode READ3args");
315
0
    rpc_free_pdu(rpc, pdu);
316
0
    return NULL;
317
0
  }
318
319
        /*
320
         * Allocate twice the iovec space, first half will be used for iov[].
321
         * This will be updated as data is read into user buffers.
322
         * Second half is for iov_ref[]. This is not used in happy path. Only
323
         * if we need to resend the request we need it to reset the cursor to
324
         * the original iovec.
325
         * See rpc_reset_cursor().
326
         */
327
0
  pdu->in.base = (struct iovec *) malloc(sizeof(struct iovec) * iovcnt * 2);
328
0
  if (!pdu->in.base) {
329
0
    rpc_set_error(rpc, "error: Failed to allocate memory");
330
0
    rpc_free_pdu(rpc, pdu);
331
0
    return NULL;
332
0
  }
333
334
0
        pdu->in.iov = pdu->in.base;
335
0
        pdu->in.iov_ref = pdu->in.base + iovcnt;
336
0
  pdu->in.iovcnt = pdu->in.iovcnt_ref = iovcnt;
337
338
0
        for (i = 0; i < iovcnt; i++) {
339
0
                pdu->in.iov[i] = pdu->in.iov_ref[i] = iov[i];
340
0
                pdu->in.remaining_size += iov[i].iov_len;
341
0
        }
342
343
0
        pdu->requested_read_count = pdu->in.remaining_size;
344
0
        pdu->zero_copy_iov = 1;
345
346
        /*
347
         * Queue READs as high priority so they can be dispatched ahead of
348
         * WRITEs. WRITEs carry a full data payload and a deep backlog of them
349
         * can delay a READ for a long time even though the READ itself is
350
         * cheap to put on the wire. Getting READs to the server sooner lets
351
         * the server start work on them earlier.
352
         *
353
         * Note that WRITE and COMMIT both stay low priority, so their relative
354
         * order, and therefore write-then-commit semantics, is unchanged.
355
         */
356
0
        if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
357
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/READ call");
358
0
    return NULL;
359
0
  }
360
361
0
  return pdu;
362
0
}
363
364
struct rpc_pdu *
365
rpc_nfs3_read_task(struct rpc_context *rpc, rpc_cb cb,
366
                   void *buf, size_t count,
367
                   struct READ3args *args, void *private_data)
368
0
{
369
0
  struct iovec iov;
370
371
0
  iov.iov_base = buf;
372
0
  iov.iov_len = count;
373
374
0
  return rpc_nfs3_readv_task(rpc, cb, &iov, 1, args, private_data);
375
0
}
376
377
/*
378
 * Replacement WRITE3args so that we can add the data as an iovector
379
 * instead of marshalling it in the out buffer.
380
 * This will marshall the WRITE3args structure except for the final
381
 * byte/array for the actual data.
382
 */
383
uint32_t
384
zdr_WRITE3args_zerocopy(ZDR *zdrs, WRITE3args *objp)
385
0
{
386
0
  if (!zdr_nfs_fh3 (zdrs, &objp->file))
387
0
                return FALSE;
388
0
        if (!zdr_offset3 (zdrs, &objp->offset))
389
0
                return FALSE;
390
0
        if (!zdr_count3 (zdrs, &objp->count))
391
0
                return FALSE;
392
0
        if (!zdr_stable_how (zdrs, &objp->stable))
393
0
                return FALSE;
394
0
  return TRUE;
395
0
}
396
397
struct rpc_pdu *rpc_nfs3_writev_task(struct rpc_context *rpc, rpc_cb cb,
398
                                     struct WRITE3args *args,
399
                                     const struct iovec *iov,
400
                                     int iovcnt,
401
                                     void *private_data)
402
0
{
403
0
  struct rpc_pdu *pdu;
404
0
        int start;
405
0
        static uint32_t zero_padding;
406
0
        uint32_t data_len;
407
0
        int copy_payload;
408
409
        /*
410
         * If caller has a single contiguous buffer they can convey it
411
         * using args.data, and if they have an io vector they can convey
412
         * that using iov.
413
         */
414
0
        if ((iovcnt == 0) != (iov == NULL)) {
415
0
    rpc_set_error(rpc, "Invalid arguments: iov and iovcnt must both be specified together");
416
0
    return NULL;
417
0
        }
418
419
0
        if (iovcnt && args->data.data_len) {
420
                /* Warn bad callers */
421
0
    rpc_set_error(rpc, "Invalid arguments: args->data.data_len not 0 when iovcnt is non-zero");
422
0
    return NULL;
423
0
        }
424
425
0
        if (iov && rpc->is_udp) {
426
0
    rpc_set_error(rpc, "Invalid arguments: Vectored write not supported for UDP transport");
427
0
    return NULL;
428
0
        }
429
430
        /*
431
         * We add 5 to the user provided iovcnt to account for one each for
432
         * the following:
433
         * - Record marker
434
         * - RPC header
435
         * - NFS header
436
         * - Write length
437
         * - Padding (optional)
438
         */
439
        /* Calculate data length to encode in the RPC request */
440
0
        if (iov) {
441
0
                int i;
442
0
                data_len = 0;
443
0
                for (i = 0; i < iovcnt; i++) {
444
0
                        data_len += iov[i].iov_len;
445
0
                }
446
0
        } else {
447
0
                data_len = args->data.data_len;
448
0
        }
449
0
        copy_payload = rpc_sec_covers_payload(rpc);
450
451
0
  pdu = rpc_allocate_pdu2(rpc, NFS_PROGRAM, NFS_V3, NFS3_WRITE, cb, private_data, (zdrproc_t)zdr_WRITE3res, sizeof(WRITE3res), copy_payload ? data_len + 8 : 0, iovcnt + 5);
452
0
  if (pdu == NULL) {
453
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/WRITE call");
454
0
    return NULL;
455
0
  }
456
457
0
        start = zdr_getpos(&pdu->zdr);
458
459
0
  if (zdr_WRITE3args_zerocopy(&pdu->zdr, args) == 0) {
460
0
    rpc_set_error(rpc, "ZDR error: Failed to encode WRITE3args");
461
0
    rpc_free_pdu(rpc, pdu);
462
0
    return NULL;
463
0
  }
464
465
0
        if (copy_payload) {
466
0
                struct iovec data;
467
468
0
                if (!iov) {
469
0
                        data.iov_base = args->data.data_val;
470
0
                        data.iov_len = data_len;
471
0
                }
472
0
                if (rpc_zdr_put_payload(&pdu->zdr, iov ? iov : &data,
473
0
                                        iov ? iovcnt : 1, data_len) < 0) {
474
0
                        rpc_set_error(rpc, "ZDR error: Failed to encode WRITE3 data");
475
0
                        rpc_free_pdu(rpc, pdu);
476
0
                        return NULL;
477
0
                }
478
0
                goto queue;
479
0
        }
480
481
        /* Add an iovector for the WRITE3 header */
482
0
        if (rpc_add_iovector(rpc, &pdu->out, &pdu->outdata.data[start + 4],
483
0
                             zdr_getpos(&pdu->zdr) - start, NULL) < 0) {
484
0
    rpc_free_pdu(rpc, pdu);
485
0
    return NULL;
486
0
        }
487
488
        /* Add an iovector for the length of the byte/array blob */
489
0
        start = zdr_getpos(&pdu->zdr);
490
0
        zdr_u_int(&pdu->zdr, &data_len);
491
0
        if (rpc_add_iovector(rpc, &pdu->out, &pdu->outdata.data[start + 4],
492
0
                             4, NULL) < 0) {
493
0
    rpc_free_pdu(rpc, pdu);
494
0
    return NULL;
495
0
        }
496
497
        /* Add an iovector for the data itself */
498
0
        if (!iov) {
499
0
                if (rpc_add_iovector(rpc, &pdu->out, args->data.data_val,
500
0
                                     args->data.data_len, NULL) < 0) {
501
0
                        rpc_free_pdu(rpc, pdu);
502
0
                        return NULL;
503
0
                }
504
0
        } else {
505
0
                int i;
506
0
                for (i = 0; i < iovcnt; i++) {
507
0
                        if (rpc_add_iovector(rpc, &pdu->out,
508
0
                                             iov[i].iov_base,
509
0
                                             iov[i].iov_len, NULL) < 0) {
510
0
                                rpc_free_pdu(rpc, pdu);
511
0
                                return NULL;
512
0
                        }
513
0
                }
514
0
        }
515
516
        /* We may need to pad this to 4 byte boundary */
517
0
        if (data_len & 0x03) {
518
0
                if (rpc_add_iovector(rpc, &pdu->out, (char *)&zero_padding,
519
0
                                     4 - (data_len & 0x03), NULL) < 0) {
520
0
                        rpc_free_pdu(rpc, pdu);
521
0
                        return NULL;
522
0
                }
523
0
        }
524
525
0
 queue:
526
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
527
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/WRITE call");
528
0
    return NULL;
529
0
  }
530
531
0
  return pdu;
532
0
}
533
534
struct rpc_pdu *rpc_nfs3_write_task(struct rpc_context *rpc, rpc_cb cb,
535
                                    struct WRITE3args *args,
536
                                    void *private_data)
537
0
{
538
0
        return rpc_nfs3_writev_task(rpc, cb, args, NULL, 0, private_data);
539
0
}
540
541
struct rpc_pdu *rpc_nfs3_commit_task(struct rpc_context *rpc, rpc_cb cb,
542
                                     struct COMMIT3args *args,
543
                                     void *private_data)
544
0
{
545
0
  struct rpc_pdu *pdu;
546
547
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_COMMIT, cb, private_data, (zdrproc_t)zdr_COMMIT3res, sizeof(COMMIT3res));
548
0
  if (pdu == NULL) {
549
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/COMMIT call");
550
0
    return NULL;
551
0
  }
552
553
0
  if (zdr_COMMIT3args(&pdu->zdr, args) == 0) {
554
0
    rpc_set_error(rpc, "ZDR error: Failed to encode COMMIT3args");
555
0
    rpc_free_pdu(rpc, pdu);
556
0
    return NULL;
557
0
  }
558
559
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
560
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/COMMIT call");
561
0
    return NULL;
562
0
  }
563
564
0
  return pdu;
565
0
}
566
567
struct rpc_pdu *
568
rpc_nfs3_setattr_task(struct rpc_context *rpc, rpc_cb cb, SETATTR3args *args,
569
                      void *private_data)
570
0
{
571
0
  struct rpc_pdu *pdu;
572
573
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_SETATTR, cb, private_data, (zdrproc_t)zdr_SETATTR3res, sizeof(SETATTR3res));
574
0
  if (pdu == NULL) {
575
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/SETATTR call");
576
0
    return NULL;
577
0
  }
578
579
0
  if (zdr_SETATTR3args(&pdu->zdr, args) == 0) {
580
0
    rpc_set_error(rpc, "ZDR error: Failed to encode SETATTR3args");
581
0
    rpc_free_pdu(rpc, pdu);
582
0
    return NULL;
583
0
  }
584
585
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
586
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/SETATTR call");
587
0
    return NULL;
588
0
  }
589
590
0
  return pdu;
591
0
}
592
593
struct rpc_pdu *rpc_nfs3_mkdir_task(struct rpc_context *rpc, rpc_cb cb,
594
                                    MKDIR3args *args, void *private_data)
595
0
{
596
0
  struct rpc_pdu *pdu;
597
598
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_MKDIR, cb, private_data, (zdrproc_t)zdr_MKDIR3res, sizeof(MKDIR3res));
599
0
  if (pdu == NULL) {
600
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/MKDIR call");
601
0
    return NULL;
602
0
  }
603
604
0
  if (zdr_MKDIR3args(&pdu->zdr, args) == 0) {
605
0
    rpc_set_error(rpc, "ZDR error: Failed to encode MKDIR3args");
606
0
    rpc_free_pdu(rpc, pdu);
607
0
    return NULL;
608
0
  }
609
610
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
611
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/MKDIR call");
612
0
    return NULL;
613
0
  }
614
615
0
  return pdu;
616
0
}
617
618
struct rpc_pdu *rpc_nfs3_rmdir_task(struct rpc_context *rpc, rpc_cb cb,
619
                                    struct RMDIR3args *args,
620
                                    void *private_data)
621
0
{
622
0
  struct rpc_pdu *pdu;
623
624
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_RMDIR, cb, private_data, (zdrproc_t)zdr_RMDIR3res, sizeof(RMDIR3res));
625
0
  if (pdu == NULL) {
626
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/RMDIR call");
627
0
    return NULL;
628
0
  }
629
630
0
  if (zdr_RMDIR3args(&pdu->zdr, args) == 0) {
631
0
    rpc_set_error(rpc, "ZDR error: Failed to encode RMDIR3args");
632
0
    rpc_free_pdu(rpc, pdu);
633
0
    return NULL;
634
0
  }
635
636
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
637
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/RMDIR call");
638
0
    return NULL;
639
0
  }
640
641
0
  return pdu;
642
0
}
643
644
struct rpc_pdu *rpc_nfs3_create_task(struct rpc_context *rpc, rpc_cb cb,
645
                                     CREATE3args *args, void *private_data)
646
0
{
647
0
  struct rpc_pdu *pdu;
648
649
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_CREATE, cb, private_data, (zdrproc_t)zdr_CREATE3res, sizeof(CREATE3res));
650
0
  if (pdu == NULL) {
651
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/CREATE call");
652
0
    return NULL;
653
0
  }
654
655
0
  if (zdr_CREATE3args(&pdu->zdr, args) == 0) {
656
0
    rpc_set_error(rpc, "ZDR error: Failed to encode CREATE3args");
657
0
    rpc_free_pdu(rpc, pdu);
658
0
    return NULL;
659
0
  }
660
661
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
662
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/CREATE call");
663
0
    return NULL;
664
0
  }
665
666
0
  return pdu;
667
0
}
668
669
struct rpc_pdu *rpc_nfs3_mknod_task(struct rpc_context *rpc, rpc_cb cb,
670
                                    struct MKNOD3args *args,
671
                                    void *private_data)
672
0
{
673
0
  struct rpc_pdu *pdu;
674
675
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_MKNOD, cb, private_data, (zdrproc_t)zdr_MKNOD3res, sizeof(MKNOD3res));
676
0
  if (pdu == NULL) {
677
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/MKNOD call");
678
0
    return NULL;
679
0
  }
680
681
0
  if (zdr_MKNOD3args(&pdu->zdr, args) == 0) {
682
0
    rpc_set_error(rpc, "ZDR error: Failed to encode MKNOD3args");
683
0
    rpc_free_pdu(rpc, pdu);
684
0
    return NULL;
685
0
  }
686
687
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
688
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/MKNOD call");
689
0
    return NULL;
690
0
  }
691
692
0
  return pdu;
693
0
}
694
695
struct rpc_pdu *rpc_nfs3_remove_task(struct rpc_context *rpc, rpc_cb cb,
696
                                     struct REMOVE3args *args,
697
                                     void *private_data)
698
0
{
699
0
  struct rpc_pdu *pdu;
700
701
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_REMOVE, cb, private_data, (zdrproc_t)zdr_REMOVE3res, sizeof(REMOVE3res));
702
0
  if (pdu == NULL) {
703
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/REMOVE call");
704
0
    return NULL;
705
0
  }
706
707
0
  if (zdr_REMOVE3args(&pdu->zdr, args) == 0) {
708
0
    rpc_set_error(rpc, "ZDR error: Failed to encode REMOVE3args");
709
0
    rpc_free_pdu(rpc, pdu);
710
0
    return NULL;
711
0
  }
712
713
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
714
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/REMOVE call");
715
0
    return NULL;
716
0
  }
717
718
0
  return pdu;
719
0
}
720
721
struct rpc_pdu *rpc_nfs3_readdir_task(struct rpc_context *rpc, rpc_cb cb,
722
                                      struct READDIR3args *args,
723
                                      void *private_data)
724
0
{
725
0
  struct rpc_pdu *pdu;
726
727
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READDIR, cb, private_data, (zdrproc_t)zdr_READDIR3res, sizeof(READDIR3res));
728
0
  if (pdu == NULL) {
729
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/READDIR call");
730
0
    return NULL;
731
0
  }
732
733
0
  if (zdr_READDIR3args(&pdu->zdr, args) == 0) {
734
0
    rpc_set_error(rpc, "ZDR error: Failed to encode READDIR3args");
735
0
    rpc_free_pdu(rpc, pdu);
736
0
    return NULL;
737
0
  }
738
739
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
740
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/READDIR call");
741
0
    return NULL;
742
0
  }
743
744
0
  return pdu;
745
0
}
746
747
struct rpc_pdu *rpc_nfs3_readdirplus_task(struct rpc_context *rpc, rpc_cb cb,
748
                                          struct READDIRPLUS3args *args,
749
                                          void *private_data)
750
0
{
751
0
  struct rpc_pdu *pdu;
752
753
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READDIRPLUS, cb, private_data, (zdrproc_t)zdr_READDIRPLUS3res, sizeof(READDIRPLUS3res));
754
0
  if (pdu == NULL) {
755
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/READDIRPLUS call");
756
0
    return NULL;
757
0
  }
758
759
0
  if (zdr_READDIRPLUS3args(&pdu->zdr, args) == 0) {
760
0
    rpc_set_error(rpc, "ZDR error: Failed to encode READDIRPLUS3args");
761
0
    rpc_free_pdu(rpc, pdu);
762
0
    return NULL;
763
0
  }
764
765
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
766
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/READDIRPLUS call");
767
0
    return NULL;
768
0
  }
769
770
0
  return pdu;
771
0
}
772
773
struct rpc_pdu *rpc_nfs3_fsstat_task(struct rpc_context *rpc, rpc_cb cb,
774
                                     struct FSSTAT3args *args,
775
                                     void *private_data)
776
0
{
777
0
  struct rpc_pdu *pdu;
778
779
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_FSSTAT, cb, private_data, (zdrproc_t)zdr_FSSTAT3res, sizeof(FSSTAT3res));
780
0
  if (pdu == NULL) {
781
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/FSSTAT call");
782
0
    return NULL;
783
0
  }
784
785
0
  if (zdr_FSSTAT3args(&pdu->zdr, args) == 0) {
786
0
    rpc_set_error(rpc, "ZDR error: Failed to encode FSSTAT3args");
787
0
    rpc_free_pdu(rpc, pdu);
788
0
    return NULL;
789
0
  }
790
791
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
792
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/FSSTAT call");
793
0
    return NULL;
794
0
  }
795
796
0
  return pdu;
797
0
}
798
799
struct rpc_pdu *rpc_nfs3_fsinfo_task(struct rpc_context *rpc, rpc_cb cb,
800
                                     struct FSINFO3args *args,
801
                                     void *private_data)
802
0
{
803
0
  struct rpc_pdu *pdu;
804
805
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_FSINFO, cb, private_data, (zdrproc_t)zdr_FSINFO3res, sizeof(FSINFO3res));
806
0
  if (pdu == NULL) {
807
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/FSINFO call");
808
0
    return NULL;
809
0
  }
810
811
0
  if (zdr_FSINFO3args(&pdu->zdr, args) == 0) {
812
0
    rpc_set_error(rpc, "ZDR error: Failed to encode FSINFO3args");
813
0
    rpc_free_pdu(rpc, pdu);
814
0
    return NULL;
815
0
  }
816
817
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
818
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/FSINFO call");
819
0
    return NULL;
820
0
  }
821
822
0
  return pdu;
823
0
}
824
825
struct rpc_pdu *
826
rpc_nfs3_readlink_task(struct rpc_context *rpc, rpc_cb cb,
827
                       READLINK3args *args, void *private_data)
828
0
{
829
0
  struct rpc_pdu *pdu;
830
831
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READLINK, cb, private_data, (zdrproc_t)zdr_READLINK3res, sizeof(READLINK3res));
832
0
  if (pdu == NULL) {
833
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/READLINK call");
834
0
    return NULL;
835
0
  }
836
837
0
  if (zdr_READLINK3args(&pdu->zdr, args) == 0) {
838
0
    rpc_set_error(rpc, "ZDR error: Failed to encode READLINK3args");
839
0
    rpc_free_pdu(rpc, pdu);
840
0
    return NULL;
841
0
  }
842
843
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
844
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/READLINK call");
845
0
    return NULL;
846
0
  }
847
848
0
  return pdu;
849
0
}
850
851
struct rpc_pdu *rpc_nfs3_symlink_task(struct rpc_context *rpc, rpc_cb cb,
852
                                       SYMLINK3args *args, void *private_data)
853
0
{
854
0
  struct rpc_pdu *pdu;
855
856
  /*
857
   * symlink target max length is 4096 bytes and we need space to encode
858
   * symlink attributes too, so we use additional 512 bytes for request
859
   * encoding.
860
   */
861
0
  pdu = rpc_allocate_pdu2(rpc, NFS_PROGRAM, NFS_V3, NFS3_SYMLINK, cb, private_data, (zdrproc_t)zdr_SYMLINK3res, sizeof(SYMLINK3res), 512, 0);
862
0
  if (pdu == NULL) {
863
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/SYMLINK call");
864
0
    return NULL;
865
0
  }
866
867
0
  if (zdr_SYMLINK3args(&pdu->zdr, args) == 0) {
868
0
    rpc_set_error(rpc, "ZDR error: Failed to encode SYMLINK3args");
869
0
    rpc_free_pdu(rpc, pdu);
870
0
    return NULL;
871
0
  }
872
873
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
874
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/SYMLINK call");
875
0
    return NULL;
876
0
  }
877
878
0
  return pdu;
879
0
}
880
881
struct rpc_pdu *rpc_nfs3_rename_task(struct rpc_context *rpc, rpc_cb cb,
882
                                     struct RENAME3args *args,
883
                                     void *private_data)
884
0
{
885
0
  struct rpc_pdu *pdu;
886
887
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_RENAME, cb, private_data, (zdrproc_t)zdr_RENAME3res, sizeof(RENAME3res));
888
0
  if (pdu == NULL) {
889
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/RENAME call");
890
0
    return NULL;
891
0
  }
892
893
0
  if (zdr_RENAME3args(&pdu->zdr, args) == 0) {
894
0
    rpc_set_error(rpc, "ZDR error: Failed to encode RENAME3args");
895
0
    rpc_free_pdu(rpc, pdu);
896
0
    return NULL;
897
0
  }
898
899
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
900
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/RENAME call");
901
0
    return NULL;
902
0
  }
903
904
0
  return pdu;
905
0
}
906
907
struct rpc_pdu *rpc_nfs3_link_task(struct rpc_context *rpc, rpc_cb cb,
908
                                   struct LINK3args *args, void *private_data)
909
0
{
910
0
  struct rpc_pdu *pdu;
911
912
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_LINK, cb, private_data, (zdrproc_t)zdr_LINK3res, sizeof(LINK3res));
913
0
  if (pdu == NULL) {
914
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/LINK call");
915
0
    return NULL;
916
0
  }
917
918
0
  if (zdr_LINK3args(&pdu->zdr, args) == 0) {
919
0
    rpc_set_error(rpc, "ZDR error: Failed to encode LINK3args");
920
0
    rpc_free_pdu(rpc, pdu);
921
0
    return NULL;
922
0
  }
923
924
0
  if (rpc_queue_pdu2(rpc, pdu, PDU_Q_PRIO_HI) != 0) {
925
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS3/LINK call");
926
0
    return NULL;
927
0
  }
928
929
0
  return pdu;
930
0
}
931
932
/*
933
 * NFSv2
934
 */
935
struct rpc_pdu *rpc_nfs2_null_task(struct rpc_context *rpc, rpc_cb cb,
936
                                   void *private_data)
937
0
{
938
0
  struct rpc_pdu *pdu;
939
940
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_NULL, cb, private_data, (zdrproc_t)zdr_void, 0);
941
0
  if (pdu == NULL) {
942
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/NULL call");
943
0
    return NULL;
944
0
  }
945
946
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
947
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/NULL call");
948
0
    return NULL;
949
0
  }
950
951
0
  return pdu;
952
0
}
953
954
struct rpc_pdu *rpc_nfs2_getattr_task(struct rpc_context *rpc, rpc_cb cb,
955
                                      struct GETATTR2args *args,
956
                                      void *private_data)
957
0
{
958
0
  struct rpc_pdu *pdu;
959
960
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_GETATTR, cb, private_data, (zdrproc_t)zdr_GETATTR2res, sizeof(GETATTR2res));
961
0
  if (pdu == NULL) {
962
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/GETATTR call");
963
0
    return NULL;
964
0
  }
965
966
0
  if (zdr_GETATTR2args(&pdu->zdr, args) == 0) {
967
0
    rpc_set_error(rpc, "ZDR error: Failed to encode GETATTR2args");
968
0
    rpc_free_pdu(rpc, pdu);
969
0
    return NULL;
970
0
  }
971
972
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
973
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/GETATTR call");
974
0
    return NULL;
975
0
  }
976
977
0
  return pdu;
978
0
}
979
980
struct rpc_pdu *rpc_nfs2_setattr_task(struct rpc_context *rpc, rpc_cb cb,
981
                                      SETATTR2args *args, void *private_data)
982
0
{
983
0
  struct rpc_pdu *pdu;
984
985
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_SETATTR, cb, private_data, (zdrproc_t)zdr_SETATTR2res, sizeof(SETATTR2res));
986
0
  if (pdu == NULL) {
987
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/SETATTR call");
988
0
    return NULL;
989
0
  }
990
991
0
  if (zdr_SETATTR2args(&pdu->zdr, args) == 0) {
992
0
    rpc_set_error(rpc, "ZDR error: Failed to encode SETATTR2args");
993
0
    rpc_free_pdu(rpc, pdu);
994
0
    return NULL;
995
0
  }
996
997
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
998
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/SETATTR call");
999
0
    return NULL;
1000
0
  }
1001
1002
0
  return pdu;
1003
0
}
1004
1005
struct rpc_pdu *rpc_nfs2_lookup_task(struct rpc_context *rpc, rpc_cb cb,
1006
                                     struct LOOKUP2args *args,
1007
                                     void *private_data)
1008
0
{
1009
0
  struct rpc_pdu *pdu;
1010
1011
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_LOOKUP, cb, private_data, (zdrproc_t)zdr_LOOKUP2res, sizeof(LOOKUP2res));
1012
0
  if (pdu == NULL) {
1013
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/LOOKUP call");
1014
0
    return NULL;
1015
0
  }
1016
1017
0
  if (zdr_LOOKUP2args(&pdu->zdr, args) == 0) {
1018
0
    rpc_set_error(rpc, "ZDR error: Failed to encode LOOKUP2args");
1019
0
    rpc_free_pdu(rpc, pdu);
1020
0
    return NULL;
1021
0
  }
1022
1023
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1024
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/LOOKUP call");
1025
0
    return NULL;
1026
0
  }
1027
1028
0
  return pdu;
1029
0
}
1030
1031
struct rpc_pdu *rpc_nfs2_readlink_task(struct rpc_context *rpc, rpc_cb cb,
1032
                                       READLINK2args *args, void *private_data)
1033
0
{
1034
0
  struct rpc_pdu *pdu;
1035
1036
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_READLINK, cb, private_data, (zdrproc_t)zdr_READLINK2res, sizeof(READLINK2res));
1037
0
  if (pdu == NULL) {
1038
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/READLINK call");
1039
0
    return NULL;
1040
0
  }
1041
1042
0
  if (zdr_READLINK2args(&pdu->zdr, args) == 0) {
1043
0
    rpc_set_error(rpc, "ZDR error: Failed to encode READLINK2args");
1044
0
    rpc_free_pdu(rpc, pdu);
1045
0
    return NULL;
1046
0
  }
1047
1048
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1049
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/READLINK call");
1050
0
    return NULL;
1051
0
  }
1052
1053
0
  return pdu;
1054
0
}
1055
1056
struct rpc_pdu *rpc_nfs2_read_task(struct rpc_context *rpc, rpc_cb cb,
1057
                                   struct READ2args *args, void *private_data)
1058
0
{
1059
0
  struct rpc_pdu *pdu;
1060
1061
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_READ, cb, private_data, (zdrproc_t)zdr_READ2res, sizeof(READ2res));
1062
0
  if (pdu == NULL) {
1063
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/READ call");
1064
0
    return NULL;
1065
0
  }
1066
1067
0
  if (zdr_READ2args(&pdu->zdr, args) == 0) {
1068
0
    rpc_set_error(rpc, "ZDR error: Failed to encode READ2args");
1069
0
    rpc_free_pdu(rpc, pdu);
1070
0
    return NULL;
1071
0
  }
1072
1073
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1074
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/READ call");
1075
0
    return NULL;
1076
0
  }
1077
1078
0
  return pdu;
1079
0
}
1080
1081
struct rpc_pdu *rpc_nfs2_write_task(struct rpc_context *rpc, rpc_cb cb,
1082
                                    struct WRITE2args *args,
1083
                                    void *private_data)
1084
0
{
1085
0
  struct rpc_pdu *pdu;
1086
1087
0
  pdu = rpc_allocate_pdu2(rpc, NFS_PROGRAM, NFS_V2, NFS2_WRITE, cb, private_data, (zdrproc_t)zdr_WRITE2res, sizeof(WRITE2res), args->totalcount, 0);
1088
0
  if (pdu == NULL) {
1089
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/WRITE call");
1090
0
    return NULL;
1091
0
  }
1092
1093
0
  if (zdr_WRITE2args(&pdu->zdr, args) == 0) {
1094
0
    rpc_set_error(rpc, "ZDR error: Failed to encode WRITE2args");
1095
0
    rpc_free_pdu(rpc, pdu);
1096
0
    return NULL;
1097
0
  }
1098
1099
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1100
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/WRITE call");
1101
0
    return NULL;
1102
0
  }
1103
1104
0
  return pdu;
1105
0
}
1106
1107
struct rpc_pdu *rpc_nfs2_create_task(struct rpc_context *rpc, rpc_cb cb,
1108
                                     CREATE2args *args, void *private_data)
1109
0
{
1110
0
  struct rpc_pdu *pdu;
1111
1112
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_CREATE, cb, private_data, (zdrproc_t)zdr_CREATE2res, sizeof(CREATE2res));
1113
0
  if (pdu == NULL) {
1114
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/CREATE call");
1115
0
    return NULL;
1116
0
  }
1117
1118
0
  if (zdr_CREATE2args(&pdu->zdr, args) == 0) {
1119
0
    rpc_set_error(rpc, "ZDR error: Failed to encode CREATE2args");
1120
0
    rpc_free_pdu(rpc, pdu);
1121
0
    return NULL;
1122
0
  }
1123
1124
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1125
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/CREATE call");
1126
0
    return NULL;
1127
0
  }
1128
1129
0
  return pdu;
1130
0
}
1131
1132
struct rpc_pdu *rpc_nfs2_remove_task(struct rpc_context *rpc, rpc_cb cb,
1133
                                     struct REMOVE2args *args,
1134
                                     void *private_data)
1135
0
{
1136
0
  struct rpc_pdu *pdu;
1137
1138
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_REMOVE, cb, private_data, (zdrproc_t)zdr_REMOVE2res, sizeof(REMOVE2res));
1139
0
  if (pdu == NULL) {
1140
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/REMOVE call");
1141
0
    return NULL;
1142
0
  }
1143
1144
0
  if (zdr_REMOVE2args(&pdu->zdr, args) == 0) {
1145
0
    rpc_set_error(rpc, "ZDR error: Failed to encode REMOVE2args");
1146
0
    rpc_free_pdu(rpc, pdu);
1147
0
    return NULL;
1148
0
  }
1149
1150
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1151
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/REMOVE call");
1152
0
    return NULL;
1153
0
  }
1154
1155
0
  return pdu;
1156
0
}
1157
1158
struct rpc_pdu *rpc_nfs2_rename_task(struct rpc_context *rpc, rpc_cb cb,
1159
                                     struct RENAME2args *args,
1160
                                     void *private_data)
1161
0
{
1162
0
  struct rpc_pdu *pdu;
1163
1164
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_RENAME, cb, private_data, (zdrproc_t)zdr_RENAME2res, sizeof(RENAME2res));
1165
0
  if (pdu == NULL) {
1166
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/RENAME call");
1167
0
    return NULL;
1168
0
  }
1169
1170
0
  if (zdr_RENAME2args(&pdu->zdr, args) == 0) {
1171
0
    rpc_set_error(rpc, "ZDR error: Failed to encode RENAME2args");
1172
0
    rpc_free_pdu(rpc, pdu);
1173
0
    return NULL;
1174
0
  }
1175
1176
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1177
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/RENAME call");
1178
0
    return NULL;
1179
0
  }
1180
1181
0
  return pdu;
1182
0
}
1183
1184
struct rpc_pdu *rpc_nfs2_link_task(struct rpc_context *rpc, rpc_cb cb,
1185
                                   LINK2args *args, void *private_data)
1186
0
{
1187
0
  struct rpc_pdu *pdu;
1188
1189
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_LINK, cb, private_data, (zdrproc_t)zdr_LINK2res, sizeof(LINK2res));
1190
0
  if (pdu == NULL) {
1191
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/LINK call");
1192
0
    return NULL;
1193
0
  }
1194
1195
0
  if (zdr_LINK2args(&pdu->zdr, args) == 0) {
1196
0
    rpc_set_error(rpc, "ZDR error: Failed to encode LINK2args");
1197
0
    rpc_free_pdu(rpc, pdu);
1198
0
    return NULL;
1199
0
  }
1200
1201
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1202
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/LINK call");
1203
0
    return NULL;
1204
0
  }
1205
1206
0
  return pdu;
1207
0
}
1208
1209
struct rpc_pdu *rpc_nfs2_symlink_task(struct rpc_context *rpc, rpc_cb cb,
1210
                                      SYMLINK2args *args, void *private_data)
1211
0
{
1212
0
  struct rpc_pdu *pdu;
1213
1214
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_SYMLINK, cb, private_data, (zdrproc_t)zdr_SYMLINK2res, sizeof(SYMLINK2res));
1215
0
  if (pdu == NULL) {
1216
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/SYMLINK call");
1217
0
    return NULL;
1218
0
  }
1219
1220
0
  if (zdr_SYMLINK2args(&pdu->zdr, args) == 0) {
1221
0
    rpc_set_error(rpc, "ZDR error: Failed to encode SYMLINK2args");
1222
0
    rpc_free_pdu(rpc, pdu);
1223
0
    return NULL;
1224
0
  }
1225
1226
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1227
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/SYMLINK call");
1228
0
    return NULL;
1229
0
  }
1230
1231
0
  return pdu;
1232
0
}
1233
1234
struct rpc_pdu *rpc_nfs2_mkdir_task(struct rpc_context *rpc, rpc_cb cb,
1235
                                    MKDIR2args *args, void *private_data)
1236
0
{
1237
0
  struct rpc_pdu *pdu;
1238
1239
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_MKDIR, cb, private_data, (zdrproc_t)zdr_MKDIR2res, sizeof(MKDIR2res));
1240
0
  if (pdu == NULL) {
1241
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/MKDIR call");
1242
0
    return NULL;
1243
0
  }
1244
1245
0
  if (zdr_MKDIR2args(&pdu->zdr, args) == 0) {
1246
0
    rpc_set_error(rpc, "ZDR error: Failed to encode MKDIR2args");
1247
0
    rpc_free_pdu(rpc, pdu);
1248
0
    return NULL;
1249
0
  }
1250
1251
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1252
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/MKDIR call");
1253
0
    return NULL;
1254
0
  }
1255
1256
0
  return pdu;
1257
0
}
1258
1259
struct rpc_pdu *rpc_nfs2_rmdir_task(struct rpc_context *rpc, rpc_cb cb,
1260
                                    struct RMDIR2args *args,
1261
                                    void *private_data)
1262
0
{
1263
0
  struct rpc_pdu *pdu;
1264
1265
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_RMDIR, cb, private_data, (zdrproc_t)zdr_RMDIR2res, sizeof(RMDIR2res));
1266
0
  if (pdu == NULL) {
1267
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/RMDIR call");
1268
0
    return NULL;
1269
0
  }
1270
1271
0
  if (zdr_RMDIR2args(&pdu->zdr, args) == 0) {
1272
0
    rpc_set_error(rpc, "ZDR error: Failed to encode RMDIR2args");
1273
0
    rpc_free_pdu(rpc, pdu);
1274
0
    return NULL;
1275
0
  }
1276
1277
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1278
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/RMDIR call");
1279
0
    return NULL;
1280
0
  }
1281
1282
0
  return pdu;
1283
0
}
1284
1285
struct rpc_pdu *rpc_nfs2_readdir_task(struct rpc_context *rpc, rpc_cb cb,
1286
                                      struct READDIR2args *args,
1287
                                      void *private_data)
1288
0
{
1289
0
  struct rpc_pdu *pdu;
1290
1291
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_READDIR, cb, private_data, (zdrproc_t)zdr_READDIR2res, sizeof(READDIR2res));
1292
0
  if (pdu == NULL) {
1293
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/READDIR call");
1294
0
    return NULL;
1295
0
  }
1296
1297
0
  if (zdr_READDIR2args(&pdu->zdr,  args) == 0) {
1298
0
    rpc_set_error(rpc, "ZDR error: Failed to encode READDIR2args");
1299
0
    rpc_free_pdu(rpc, pdu);
1300
0
    return NULL;
1301
0
  }
1302
1303
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1304
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/READDIR call");
1305
0
    return NULL;
1306
0
  }
1307
1308
0
  return pdu;
1309
0
}
1310
1311
struct rpc_pdu *rpc_nfs2_statfs_task(struct rpc_context *rpc, rpc_cb cb,
1312
                                     struct STATFS2args *args,
1313
                                     void *private_data)
1314
0
{
1315
0
  struct rpc_pdu *pdu;
1316
1317
0
  pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V2, NFS2_STATFS, cb, private_data, (zdrproc_t)zdr_STATFS2res, sizeof(STATFS2res));
1318
0
  if (pdu == NULL) {
1319
0
    rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/STATFS call");
1320
0
    return NULL;
1321
0
  }
1322
1323
0
  if (zdr_STATFS2args(&pdu->zdr,  args) == 0) {
1324
0
    rpc_set_error(rpc, "ZDR error: Failed to encode STATFS2args");
1325
0
    rpc_free_pdu(rpc, pdu);
1326
0
    return NULL;
1327
0
  }
1328
1329
0
  if (rpc_queue_pdu(rpc, pdu) != 0) {
1330
0
    rpc_set_error(rpc, "Out of memory. Failed to queue pdu for NFS2/STATFS call");
1331
0
    return NULL;
1332
0
  }
1333
1334
0
  return pdu;
1335
0
}