]> asedeno.scripts.mit.edu Git - linux.git/blob - fs/afs/fsclient.c
afs: Mark expected switch fall-throughs
[linux.git] / fs / afs / fsclient.c
1 /* AFS File Server client stubs
2  *
3  * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/sched.h>
15 #include <linux/circ_buf.h>
16 #include <linux/iversion.h>
17 #include "internal.h"
18 #include "afs_fs.h"
19 #include "xdr_fs.h"
20 #include "protocol_yfs.h"
21
22 static const struct afs_fid afs_zero_fid;
23
24 static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
25 {
26         call->cbi = afs_get_cb_interest(cbi);
27 }
28
29 /*
30  * decode an AFSFid block
31  */
32 static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
33 {
34         const __be32 *bp = *_bp;
35
36         fid->vid                = ntohl(*bp++);
37         fid->vnode              = ntohl(*bp++);
38         fid->unique             = ntohl(*bp++);
39         *_bp = bp;
40 }
41
42 /*
43  * Dump a bad file status record.
44  */
45 static void xdr_dump_bad(const __be32 *bp)
46 {
47         __be32 x[4];
48         int i;
49
50         pr_notice("AFS XDR: Bad status record\n");
51         for (i = 0; i < 5 * 4 * 4; i += 16) {
52                 memcpy(x, bp, 16);
53                 bp += 4;
54                 pr_notice("%03x: %08x %08x %08x %08x\n",
55                           i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
56         }
57
58         memcpy(x, bp, 4);
59         pr_notice("0x50: %08x\n", ntohl(x[0]));
60 }
61
62 /*
63  * Update the core inode struct from a returned status record.
64  */
65 void afs_update_inode_from_status(struct afs_vnode *vnode,
66                                   struct afs_file_status *status,
67                                   const afs_dataversion_t *expected_version,
68                                   u8 flags)
69 {
70         struct timespec64 t;
71         umode_t mode;
72
73         t = status->mtime_client;
74         vnode->vfs_inode.i_ctime = t;
75         vnode->vfs_inode.i_mtime = t;
76         vnode->vfs_inode.i_atime = t;
77
78         if (flags & (AFS_VNODE_META_CHANGED | AFS_VNODE_NOT_YET_SET)) {
79                 vnode->vfs_inode.i_uid = make_kuid(&init_user_ns, status->owner);
80                 vnode->vfs_inode.i_gid = make_kgid(&init_user_ns, status->group);
81                 set_nlink(&vnode->vfs_inode, status->nlink);
82
83                 mode = vnode->vfs_inode.i_mode;
84                 mode &= ~S_IALLUGO;
85                 mode |= status->mode;
86                 barrier();
87                 vnode->vfs_inode.i_mode = mode;
88         }
89
90         if (!(flags & AFS_VNODE_NOT_YET_SET)) {
91                 if (expected_version &&
92                     *expected_version != status->data_version) {
93                         _debug("vnode modified %llx on {%llx:%llu} [exp %llx]",
94                                (unsigned long long) status->data_version,
95                                vnode->fid.vid, vnode->fid.vnode,
96                                (unsigned long long) *expected_version);
97                         vnode->invalid_before = status->data_version;
98                         if (vnode->status.type == AFS_FTYPE_DIR) {
99                                 if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
100                                         afs_stat_v(vnode, n_inval);
101                         } else {
102                                 set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags);
103                         }
104                 } else if (vnode->status.type == AFS_FTYPE_DIR) {
105                         /* Expected directory change is handled elsewhere so
106                          * that we can locally edit the directory and save on a
107                          * download.
108                          */
109                         if (test_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
110                                 flags &= ~AFS_VNODE_DATA_CHANGED;
111                 }
112         }
113
114         if (flags & (AFS_VNODE_DATA_CHANGED | AFS_VNODE_NOT_YET_SET)) {
115                 inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
116                 i_size_write(&vnode->vfs_inode, status->size);
117         }
118 }
119
120 /*
121  * decode an AFSFetchStatus block
122  */
123 static int xdr_decode_AFSFetchStatus(struct afs_call *call,
124                                      const __be32 **_bp,
125                                      struct afs_file_status *status,
126                                      struct afs_vnode *vnode,
127                                      const afs_dataversion_t *expected_version,
128                                      struct afs_read *read_req)
129 {
130         const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
131         bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
132         u64 data_version, size;
133         u32 type, abort_code;
134         u8 flags = 0;
135
136         abort_code = ntohl(xdr->abort_code);
137
138         if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
139                 if (xdr->if_version == htonl(0) &&
140                     abort_code != 0 &&
141                     inline_error) {
142                         /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
143                          * whereby it doesn't set the interface version in the error
144                          * case.
145                          */
146                         status->abort_code = abort_code;
147                         return 0;
148                 }
149
150                 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
151                 goto bad;
152         }
153
154         if (abort_code != 0 && inline_error) {
155                 status->abort_code = abort_code;
156                 return 0;
157         }
158
159         type = ntohl(xdr->type);
160         switch (type) {
161         case AFS_FTYPE_FILE:
162         case AFS_FTYPE_DIR:
163         case AFS_FTYPE_SYMLINK:
164                 if (type != status->type &&
165                     vnode &&
166                     !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
167                         pr_warning("Vnode %llx:%llx:%x changed type %u to %u\n",
168                                    vnode->fid.vid,
169                                    vnode->fid.vnode,
170                                    vnode->fid.unique,
171                                    status->type, type);
172                         goto bad;
173                 }
174                 status->type = type;
175                 break;
176         default:
177                 goto bad;
178         }
179
180 #define EXTRACT_M(FIELD)                                        \
181         do {                                                    \
182                 u32 x = ntohl(xdr->FIELD);                      \
183                 if (status->FIELD != x) {                       \
184                         flags |= AFS_VNODE_META_CHANGED;        \
185                         status->FIELD = x;                      \
186                 }                                               \
187         } while (0)
188
189         EXTRACT_M(nlink);
190         EXTRACT_M(author);
191         EXTRACT_M(owner);
192         EXTRACT_M(caller_access); /* call ticket dependent */
193         EXTRACT_M(anon_access);
194         EXTRACT_M(mode);
195         EXTRACT_M(group);
196
197         status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
198         status->mtime_client.tv_nsec = 0;
199         status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
200         status->mtime_server.tv_nsec = 0;
201         status->lock_count   = ntohl(xdr->lock_count);
202
203         size  = (u64)ntohl(xdr->size_lo);
204         size |= (u64)ntohl(xdr->size_hi) << 32;
205         status->size = size;
206
207         data_version  = (u64)ntohl(xdr->data_version_lo);
208         data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
209         if (data_version != status->data_version) {
210                 status->data_version = data_version;
211                 flags |= AFS_VNODE_DATA_CHANGED;
212         }
213
214         if (read_req) {
215                 read_req->data_version = data_version;
216                 read_req->file_size = size;
217         }
218
219         *_bp = (const void *)*_bp + sizeof(*xdr);
220
221         if (vnode) {
222                 if (test_bit(AFS_VNODE_UNSET, &vnode->flags))
223                         flags |= AFS_VNODE_NOT_YET_SET;
224                 afs_update_inode_from_status(vnode, status, expected_version,
225                                              flags);
226         }
227
228         return 0;
229
230 bad:
231         xdr_dump_bad(*_bp);
232         return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
233 }
234
235 /*
236  * Decode the file status.  We need to lock the target vnode if we're going to
237  * update its status so that stat() sees the attributes update atomically.
238  */
239 static int afs_decode_status(struct afs_call *call,
240                              const __be32 **_bp,
241                              struct afs_file_status *status,
242                              struct afs_vnode *vnode,
243                              const afs_dataversion_t *expected_version,
244                              struct afs_read *read_req)
245 {
246         int ret;
247
248         if (!vnode)
249                 return xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
250                                                  expected_version, read_req);
251
252         write_seqlock(&vnode->cb_lock);
253         ret = xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
254                                         expected_version, read_req);
255         write_sequnlock(&vnode->cb_lock);
256         return ret;
257 }
258
259 /*
260  * decode an AFSCallBack block
261  */
262 static void xdr_decode_AFSCallBack(struct afs_call *call,
263                                    struct afs_vnode *vnode,
264                                    const __be32 **_bp)
265 {
266         struct afs_cb_interest *old, *cbi = call->cbi;
267         const __be32 *bp = *_bp;
268         u32 cb_expiry;
269
270         write_seqlock(&vnode->cb_lock);
271
272         if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
273                 vnode->cb_version       = ntohl(*bp++);
274                 cb_expiry               = ntohl(*bp++);
275                 vnode->cb_type          = ntohl(*bp++);
276                 vnode->cb_expires_at    = cb_expiry + ktime_get_real_seconds();
277                 old = vnode->cb_interest;
278                 if (old != call->cbi) {
279                         vnode->cb_interest = cbi;
280                         cbi = old;
281                 }
282                 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
283         } else {
284                 bp += 3;
285         }
286
287         write_sequnlock(&vnode->cb_lock);
288         call->cbi = cbi;
289         *_bp = bp;
290 }
291
292 static ktime_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
293 {
294         return ktime_add_ns(call->reply_time, expiry * NSEC_PER_SEC);
295 }
296
297 static void xdr_decode_AFSCallBack_raw(struct afs_call *call,
298                                        const __be32 **_bp,
299                                        struct afs_callback *cb)
300 {
301         const __be32 *bp = *_bp;
302
303         cb->version     = ntohl(*bp++);
304         cb->expires_at  = xdr_decode_expiry(call, ntohl(*bp++));
305         cb->type        = ntohl(*bp++);
306         *_bp = bp;
307 }
308
309 /*
310  * decode an AFSVolSync block
311  */
312 static void xdr_decode_AFSVolSync(const __be32 **_bp,
313                                   struct afs_volsync *volsync)
314 {
315         const __be32 *bp = *_bp;
316         u32 creation;
317
318         creation = ntohl(*bp++);
319         bp++; /* spare2 */
320         bp++; /* spare3 */
321         bp++; /* spare4 */
322         bp++; /* spare5 */
323         bp++; /* spare6 */
324         *_bp = bp;
325
326         if (volsync)
327                 volsync->creation = creation;
328 }
329
330 /*
331  * encode the requested attributes into an AFSStoreStatus block
332  */
333 static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
334 {
335         __be32 *bp = *_bp;
336         u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
337
338         mask = 0;
339         if (attr->ia_valid & ATTR_MTIME) {
340                 mask |= AFS_SET_MTIME;
341                 mtime = attr->ia_mtime.tv_sec;
342         }
343
344         if (attr->ia_valid & ATTR_UID) {
345                 mask |= AFS_SET_OWNER;
346                 owner = from_kuid(&init_user_ns, attr->ia_uid);
347         }
348
349         if (attr->ia_valid & ATTR_GID) {
350                 mask |= AFS_SET_GROUP;
351                 group = from_kgid(&init_user_ns, attr->ia_gid);
352         }
353
354         if (attr->ia_valid & ATTR_MODE) {
355                 mask |= AFS_SET_MODE;
356                 mode = attr->ia_mode & S_IALLUGO;
357         }
358
359         *bp++ = htonl(mask);
360         *bp++ = htonl(mtime);
361         *bp++ = htonl(owner);
362         *bp++ = htonl(group);
363         *bp++ = htonl(mode);
364         *bp++ = 0;              /* segment size */
365         *_bp = bp;
366 }
367
368 /*
369  * decode an AFSFetchVolumeStatus block
370  */
371 static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
372                                             struct afs_volume_status *vs)
373 {
374         const __be32 *bp = *_bp;
375
376         vs->vid                 = ntohl(*bp++);
377         vs->parent_id           = ntohl(*bp++);
378         vs->online              = ntohl(*bp++);
379         vs->in_service          = ntohl(*bp++);
380         vs->blessed             = ntohl(*bp++);
381         vs->needs_salvage       = ntohl(*bp++);
382         vs->type                = ntohl(*bp++);
383         vs->min_quota           = ntohl(*bp++);
384         vs->max_quota           = ntohl(*bp++);
385         vs->blocks_in_use       = ntohl(*bp++);
386         vs->part_blocks_avail   = ntohl(*bp++);
387         vs->part_max_blocks     = ntohl(*bp++);
388         vs->vol_copy_date       = 0;
389         vs->vol_backup_date     = 0;
390         *_bp = bp;
391 }
392
393 /*
394  * deliver reply data to an FS.FetchStatus
395  */
396 static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
397 {
398         struct afs_vnode *vnode = call->reply[0];
399         const __be32 *bp;
400         int ret;
401
402         ret = afs_transfer_reply(call);
403         if (ret < 0)
404                 return ret;
405
406         _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
407
408         /* unmarshall the reply once we've received all of it */
409         bp = call->buffer;
410         ret = afs_decode_status(call, &bp, &vnode->status, vnode,
411                                 &call->expected_version, NULL);
412         if (ret < 0)
413                 return ret;
414         xdr_decode_AFSCallBack(call, vnode, &bp);
415         xdr_decode_AFSVolSync(&bp, call->reply[1]);
416
417         _leave(" = 0 [done]");
418         return 0;
419 }
420
421 /*
422  * FS.FetchStatus operation type
423  */
424 static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
425         .name           = "FS.FetchStatus(vnode)",
426         .op             = afs_FS_FetchStatus,
427         .deliver        = afs_deliver_fs_fetch_status_vnode,
428         .destructor     = afs_flat_call_destructor,
429 };
430
431 /*
432  * fetch the status information for a file
433  */
434 int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_volsync *volsync,
435                              bool new_inode)
436 {
437         struct afs_vnode *vnode = fc->vnode;
438         struct afs_call *call;
439         struct afs_net *net = afs_v2net(vnode);
440         __be32 *bp;
441
442         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
443                 return yfs_fs_fetch_file_status(fc, volsync, new_inode);
444
445         _enter(",%x,{%llx:%llu},,",
446                key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
447
448         call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
449                                    16, (21 + 3 + 6) * 4);
450         if (!call) {
451                 fc->ac.error = -ENOMEM;
452                 return -ENOMEM;
453         }
454
455         call->key = fc->key;
456         call->reply[0] = vnode;
457         call->reply[1] = volsync;
458         call->expected_version = new_inode ? 1 : vnode->status.data_version;
459         call->want_reply_time = true;
460
461         /* marshall the parameters */
462         bp = call->request;
463         bp[0] = htonl(FSFETCHSTATUS);
464         bp[1] = htonl(vnode->fid.vid);
465         bp[2] = htonl(vnode->fid.vnode);
466         bp[3] = htonl(vnode->fid.unique);
467
468         call->cb_break = fc->cb_break;
469         afs_use_fs_server(call, fc->cbi);
470         trace_afs_make_fs_call(call, &vnode->fid);
471         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
472 }
473
474 /*
475  * deliver reply data to an FS.FetchData
476  */
477 static int afs_deliver_fs_fetch_data(struct afs_call *call)
478 {
479         struct afs_vnode *vnode = call->reply[0];
480         struct afs_read *req = call->reply[2];
481         const __be32 *bp;
482         unsigned int size;
483         int ret;
484
485         _enter("{%u,%zu/%llu}",
486                call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
487
488         switch (call->unmarshall) {
489         case 0:
490                 req->actual_len = 0;
491                 req->index = 0;
492                 req->offset = req->pos & (PAGE_SIZE - 1);
493                 call->unmarshall++;
494                 if (call->operation_ID == FSFETCHDATA64) {
495                         afs_extract_to_tmp64(call);
496                 } else {
497                         call->tmp_u = htonl(0);
498                         afs_extract_to_tmp(call);
499                 }
500
501                 /* Fall through - and extract the returned data length */
502         case 1:
503                 _debug("extract data length");
504                 ret = afs_extract_data(call, true);
505                 if (ret < 0)
506                         return ret;
507
508                 req->actual_len = be64_to_cpu(call->tmp64);
509                 _debug("DATA length: %llu", req->actual_len);
510                 req->remain = min(req->len, req->actual_len);
511                 if (req->remain == 0)
512                         goto no_more_data;
513
514                 call->unmarshall++;
515
516         begin_page:
517                 ASSERTCMP(req->index, <, req->nr_pages);
518                 if (req->remain > PAGE_SIZE - req->offset)
519                         size = PAGE_SIZE - req->offset;
520                 else
521                         size = req->remain;
522                 call->bvec[0].bv_len = size;
523                 call->bvec[0].bv_offset = req->offset;
524                 call->bvec[0].bv_page = req->pages[req->index];
525                 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
526                 ASSERTCMP(size, <=, PAGE_SIZE);
527
528                 /* Fall through - and extract the returned data */
529         case 2:
530                 _debug("extract data %zu/%llu",
531                        iov_iter_count(&call->iter), req->remain);
532
533                 ret = afs_extract_data(call, true);
534                 if (ret < 0)
535                         return ret;
536                 req->remain -= call->bvec[0].bv_len;
537                 req->offset += call->bvec[0].bv_len;
538                 ASSERTCMP(req->offset, <=, PAGE_SIZE);
539                 if (req->offset == PAGE_SIZE) {
540                         req->offset = 0;
541                         if (req->page_done)
542                                 req->page_done(call, req);
543                         req->index++;
544                         if (req->remain > 0)
545                                 goto begin_page;
546                 }
547
548                 ASSERTCMP(req->remain, ==, 0);
549                 if (req->actual_len <= req->len)
550                         goto no_more_data;
551
552                 /* Discard any excess data the server gave us */
553                 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
554                 call->unmarshall = 3;
555
556                 /* Fall through */
557         case 3:
558                 _debug("extract discard %zu/%llu",
559                        iov_iter_count(&call->iter), req->actual_len - req->len);
560
561                 ret = afs_extract_data(call, true);
562                 if (ret < 0)
563                         return ret;
564
565         no_more_data:
566                 call->unmarshall = 4;
567                 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
568
569                 /* Fall through - and extract the metadata */
570         case 4:
571                 ret = afs_extract_data(call, false);
572                 if (ret < 0)
573                         return ret;
574
575                 bp = call->buffer;
576                 ret = afs_decode_status(call, &bp, &vnode->status, vnode,
577                                         &vnode->status.data_version, req);
578                 if (ret < 0)
579                         return ret;
580                 xdr_decode_AFSCallBack(call, vnode, &bp);
581                 xdr_decode_AFSVolSync(&bp, call->reply[1]);
582
583                 call->unmarshall++;
584
585         case 5:
586                 break;
587         }
588
589         for (; req->index < req->nr_pages; req->index++) {
590                 if (req->offset < PAGE_SIZE)
591                         zero_user_segment(req->pages[req->index],
592                                           req->offset, PAGE_SIZE);
593                 if (req->page_done)
594                         req->page_done(call, req);
595                 req->offset = 0;
596         }
597
598         _leave(" = 0 [done]");
599         return 0;
600 }
601
602 static void afs_fetch_data_destructor(struct afs_call *call)
603 {
604         struct afs_read *req = call->reply[2];
605
606         afs_put_read(req);
607         afs_flat_call_destructor(call);
608 }
609
610 /*
611  * FS.FetchData operation type
612  */
613 static const struct afs_call_type afs_RXFSFetchData = {
614         .name           = "FS.FetchData",
615         .op             = afs_FS_FetchData,
616         .deliver        = afs_deliver_fs_fetch_data,
617         .destructor     = afs_fetch_data_destructor,
618 };
619
620 static const struct afs_call_type afs_RXFSFetchData64 = {
621         .name           = "FS.FetchData64",
622         .op             = afs_FS_FetchData64,
623         .deliver        = afs_deliver_fs_fetch_data,
624         .destructor     = afs_fetch_data_destructor,
625 };
626
627 /*
628  * fetch data from a very large file
629  */
630 static int afs_fs_fetch_data64(struct afs_fs_cursor *fc, struct afs_read *req)
631 {
632         struct afs_vnode *vnode = fc->vnode;
633         struct afs_call *call;
634         struct afs_net *net = afs_v2net(vnode);
635         __be32 *bp;
636
637         _enter("");
638
639         call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
640         if (!call)
641                 return -ENOMEM;
642
643         call->key = fc->key;
644         call->reply[0] = vnode;
645         call->reply[1] = NULL; /* volsync */
646         call->reply[2] = req;
647         call->expected_version = vnode->status.data_version;
648         call->want_reply_time = true;
649
650         /* marshall the parameters */
651         bp = call->request;
652         bp[0] = htonl(FSFETCHDATA64);
653         bp[1] = htonl(vnode->fid.vid);
654         bp[2] = htonl(vnode->fid.vnode);
655         bp[3] = htonl(vnode->fid.unique);
656         bp[4] = htonl(upper_32_bits(req->pos));
657         bp[5] = htonl(lower_32_bits(req->pos));
658         bp[6] = 0;
659         bp[7] = htonl(lower_32_bits(req->len));
660
661         refcount_inc(&req->usage);
662         call->cb_break = fc->cb_break;
663         afs_use_fs_server(call, fc->cbi);
664         trace_afs_make_fs_call(call, &vnode->fid);
665         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
666 }
667
668 /*
669  * fetch data from a file
670  */
671 int afs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
672 {
673         struct afs_vnode *vnode = fc->vnode;
674         struct afs_call *call;
675         struct afs_net *net = afs_v2net(vnode);
676         __be32 *bp;
677
678         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
679                 return yfs_fs_fetch_data(fc, req);
680
681         if (upper_32_bits(req->pos) ||
682             upper_32_bits(req->len) ||
683             upper_32_bits(req->pos + req->len))
684                 return afs_fs_fetch_data64(fc, req);
685
686         _enter("");
687
688         call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
689         if (!call)
690                 return -ENOMEM;
691
692         call->key = fc->key;
693         call->reply[0] = vnode;
694         call->reply[1] = NULL; /* volsync */
695         call->reply[2] = req;
696         call->expected_version = vnode->status.data_version;
697         call->want_reply_time = true;
698
699         /* marshall the parameters */
700         bp = call->request;
701         bp[0] = htonl(FSFETCHDATA);
702         bp[1] = htonl(vnode->fid.vid);
703         bp[2] = htonl(vnode->fid.vnode);
704         bp[3] = htonl(vnode->fid.unique);
705         bp[4] = htonl(lower_32_bits(req->pos));
706         bp[5] = htonl(lower_32_bits(req->len));
707
708         refcount_inc(&req->usage);
709         call->cb_break = fc->cb_break;
710         afs_use_fs_server(call, fc->cbi);
711         trace_afs_make_fs_call(call, &vnode->fid);
712         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
713 }
714
715 /*
716  * deliver reply data to an FS.CreateFile or an FS.MakeDir
717  */
718 static int afs_deliver_fs_create_vnode(struct afs_call *call)
719 {
720         struct afs_vnode *vnode = call->reply[0];
721         const __be32 *bp;
722         int ret;
723
724         _enter("{%u}", call->unmarshall);
725
726         ret = afs_transfer_reply(call);
727         if (ret < 0)
728                 return ret;
729
730         /* unmarshall the reply once we've received all of it */
731         bp = call->buffer;
732         xdr_decode_AFSFid(&bp, call->reply[1]);
733         ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
734         if (ret < 0)
735                 return ret;
736         ret = afs_decode_status(call, &bp, &vnode->status, vnode,
737                                 &call->expected_version, NULL);
738         if (ret < 0)
739                 return ret;
740         xdr_decode_AFSCallBack_raw(call, &bp, call->reply[3]);
741         /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
742
743         _leave(" = 0 [done]");
744         return 0;
745 }
746
747 /*
748  * FS.CreateFile and FS.MakeDir operation type
749  */
750 static const struct afs_call_type afs_RXFSCreateFile = {
751         .name           = "FS.CreateFile",
752         .op             = afs_FS_CreateFile,
753         .deliver        = afs_deliver_fs_create_vnode,
754         .destructor     = afs_flat_call_destructor,
755 };
756
757 static const struct afs_call_type afs_RXFSMakeDir = {
758         .name           = "FS.MakeDir",
759         .op             = afs_FS_MakeDir,
760         .deliver        = afs_deliver_fs_create_vnode,
761         .destructor     = afs_flat_call_destructor,
762 };
763
764 /*
765  * create a file or make a directory
766  */
767 int afs_fs_create(struct afs_fs_cursor *fc,
768                   const char *name,
769                   umode_t mode,
770                   u64 current_data_version,
771                   struct afs_fid *newfid,
772                   struct afs_file_status *newstatus,
773                   struct afs_callback *newcb)
774 {
775         struct afs_vnode *vnode = fc->vnode;
776         struct afs_call *call;
777         struct afs_net *net = afs_v2net(vnode);
778         size_t namesz, reqsz, padsz;
779         __be32 *bp;
780
781         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
782                 if (S_ISDIR(mode))
783                         return yfs_fs_make_dir(fc, name, mode, current_data_version,
784                                                newfid, newstatus, newcb);
785                 else
786                         return yfs_fs_create_file(fc, name, mode, current_data_version,
787                                                   newfid, newstatus, newcb);
788         }
789
790         _enter("");
791
792         namesz = strlen(name);
793         padsz = (4 - (namesz & 3)) & 3;
794         reqsz = (5 * 4) + namesz + padsz + (6 * 4);
795
796         call = afs_alloc_flat_call(
797                 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
798                 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
799         if (!call)
800                 return -ENOMEM;
801
802         call->key = fc->key;
803         call->reply[0] = vnode;
804         call->reply[1] = newfid;
805         call->reply[2] = newstatus;
806         call->reply[3] = newcb;
807         call->expected_version = current_data_version + 1;
808         call->want_reply_time = true;
809
810         /* marshall the parameters */
811         bp = call->request;
812         *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
813         *bp++ = htonl(vnode->fid.vid);
814         *bp++ = htonl(vnode->fid.vnode);
815         *bp++ = htonl(vnode->fid.unique);
816         *bp++ = htonl(namesz);
817         memcpy(bp, name, namesz);
818         bp = (void *) bp + namesz;
819         if (padsz > 0) {
820                 memset(bp, 0, padsz);
821                 bp = (void *) bp + padsz;
822         }
823         *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
824         *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
825         *bp++ = 0; /* owner */
826         *bp++ = 0; /* group */
827         *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
828         *bp++ = 0; /* segment size */
829
830         afs_use_fs_server(call, fc->cbi);
831         trace_afs_make_fs_call(call, &vnode->fid);
832         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
833 }
834
835 /*
836  * deliver reply data to an FS.RemoveFile or FS.RemoveDir
837  */
838 static int afs_deliver_fs_remove(struct afs_call *call)
839 {
840         struct afs_vnode *vnode = call->reply[0];
841         const __be32 *bp;
842         int ret;
843
844         _enter("{%u}", call->unmarshall);
845
846         ret = afs_transfer_reply(call);
847         if (ret < 0)
848                 return ret;
849
850         /* unmarshall the reply once we've received all of it */
851         bp = call->buffer;
852         ret = afs_decode_status(call, &bp, &vnode->status, vnode,
853                                 &call->expected_version, NULL);
854         if (ret < 0)
855                 return ret;
856         /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
857
858         _leave(" = 0 [done]");
859         return 0;
860 }
861
862 /*
863  * FS.RemoveDir/FS.RemoveFile operation type
864  */
865 static const struct afs_call_type afs_RXFSRemoveFile = {
866         .name           = "FS.RemoveFile",
867         .op             = afs_FS_RemoveFile,
868         .deliver        = afs_deliver_fs_remove,
869         .destructor     = afs_flat_call_destructor,
870 };
871
872 static const struct afs_call_type afs_RXFSRemoveDir = {
873         .name           = "FS.RemoveDir",
874         .op             = afs_FS_RemoveDir,
875         .deliver        = afs_deliver_fs_remove,
876         .destructor     = afs_flat_call_destructor,
877 };
878
879 /*
880  * remove a file or directory
881  */
882 int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
883                   const char *name, bool isdir, u64 current_data_version)
884 {
885         struct afs_vnode *dvnode = fc->vnode;
886         struct afs_call *call;
887         struct afs_net *net = afs_v2net(dvnode);
888         size_t namesz, reqsz, padsz;
889         __be32 *bp;
890
891         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
892                 return yfs_fs_remove(fc, vnode, name, isdir, current_data_version);
893
894         _enter("");
895
896         namesz = strlen(name);
897         padsz = (4 - (namesz & 3)) & 3;
898         reqsz = (5 * 4) + namesz + padsz;
899
900         call = afs_alloc_flat_call(
901                 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
902                 reqsz, (21 + 6) * 4);
903         if (!call)
904                 return -ENOMEM;
905
906         call->key = fc->key;
907         call->reply[0] = dvnode;
908         call->reply[1] = vnode;
909         call->expected_version = current_data_version + 1;
910
911         /* marshall the parameters */
912         bp = call->request;
913         *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
914         *bp++ = htonl(dvnode->fid.vid);
915         *bp++ = htonl(dvnode->fid.vnode);
916         *bp++ = htonl(dvnode->fid.unique);
917         *bp++ = htonl(namesz);
918         memcpy(bp, name, namesz);
919         bp = (void *) bp + namesz;
920         if (padsz > 0) {
921                 memset(bp, 0, padsz);
922                 bp = (void *) bp + padsz;
923         }
924
925         afs_use_fs_server(call, fc->cbi);
926         trace_afs_make_fs_call(call, &dvnode->fid);
927         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
928 }
929
930 /*
931  * deliver reply data to an FS.Link
932  */
933 static int afs_deliver_fs_link(struct afs_call *call)
934 {
935         struct afs_vnode *dvnode = call->reply[0], *vnode = call->reply[1];
936         const __be32 *bp;
937         int ret;
938
939         _enter("{%u}", call->unmarshall);
940
941         ret = afs_transfer_reply(call);
942         if (ret < 0)
943                 return ret;
944
945         /* unmarshall the reply once we've received all of it */
946         bp = call->buffer;
947         ret = afs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
948         if (ret < 0)
949                 return ret;
950         ret = afs_decode_status(call, &bp, &dvnode->status, dvnode,
951                                 &call->expected_version, NULL);
952         if (ret < 0)
953                 return ret;
954         /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
955
956         _leave(" = 0 [done]");
957         return 0;
958 }
959
960 /*
961  * FS.Link operation type
962  */
963 static const struct afs_call_type afs_RXFSLink = {
964         .name           = "FS.Link",
965         .op             = afs_FS_Link,
966         .deliver        = afs_deliver_fs_link,
967         .destructor     = afs_flat_call_destructor,
968 };
969
970 /*
971  * make a hard link
972  */
973 int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
974                 const char *name, u64 current_data_version)
975 {
976         struct afs_vnode *dvnode = fc->vnode;
977         struct afs_call *call;
978         struct afs_net *net = afs_v2net(vnode);
979         size_t namesz, reqsz, padsz;
980         __be32 *bp;
981
982         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
983                 return yfs_fs_link(fc, vnode, name, current_data_version);
984
985         _enter("");
986
987         namesz = strlen(name);
988         padsz = (4 - (namesz & 3)) & 3;
989         reqsz = (5 * 4) + namesz + padsz + (3 * 4);
990
991         call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
992         if (!call)
993                 return -ENOMEM;
994
995         call->key = fc->key;
996         call->reply[0] = dvnode;
997         call->reply[1] = vnode;
998         call->expected_version = current_data_version + 1;
999
1000         /* marshall the parameters */
1001         bp = call->request;
1002         *bp++ = htonl(FSLINK);
1003         *bp++ = htonl(dvnode->fid.vid);
1004         *bp++ = htonl(dvnode->fid.vnode);
1005         *bp++ = htonl(dvnode->fid.unique);
1006         *bp++ = htonl(namesz);
1007         memcpy(bp, name, namesz);
1008         bp = (void *) bp + namesz;
1009         if (padsz > 0) {
1010                 memset(bp, 0, padsz);
1011                 bp = (void *) bp + padsz;
1012         }
1013         *bp++ = htonl(vnode->fid.vid);
1014         *bp++ = htonl(vnode->fid.vnode);
1015         *bp++ = htonl(vnode->fid.unique);
1016
1017         afs_use_fs_server(call, fc->cbi);
1018         trace_afs_make_fs_call(call, &vnode->fid);
1019         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1020 }
1021
1022 /*
1023  * deliver reply data to an FS.Symlink
1024  */
1025 static int afs_deliver_fs_symlink(struct afs_call *call)
1026 {
1027         struct afs_vnode *vnode = call->reply[0];
1028         const __be32 *bp;
1029         int ret;
1030
1031         _enter("{%u}", call->unmarshall);
1032
1033         ret = afs_transfer_reply(call);
1034         if (ret < 0)
1035                 return ret;
1036
1037         /* unmarshall the reply once we've received all of it */
1038         bp = call->buffer;
1039         xdr_decode_AFSFid(&bp, call->reply[1]);
1040         ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
1041         if (ret < 0)
1042                 return ret;
1043         ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1044                                 &call->expected_version, NULL);
1045         if (ret < 0)
1046                 return ret;
1047         /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1048
1049         _leave(" = 0 [done]");
1050         return 0;
1051 }
1052
1053 /*
1054  * FS.Symlink operation type
1055  */
1056 static const struct afs_call_type afs_RXFSSymlink = {
1057         .name           = "FS.Symlink",
1058         .op             = afs_FS_Symlink,
1059         .deliver        = afs_deliver_fs_symlink,
1060         .destructor     = afs_flat_call_destructor,
1061 };
1062
1063 /*
1064  * create a symbolic link
1065  */
1066 int afs_fs_symlink(struct afs_fs_cursor *fc,
1067                    const char *name,
1068                    const char *contents,
1069                    u64 current_data_version,
1070                    struct afs_fid *newfid,
1071                    struct afs_file_status *newstatus)
1072 {
1073         struct afs_vnode *vnode = fc->vnode;
1074         struct afs_call *call;
1075         struct afs_net *net = afs_v2net(vnode);
1076         size_t namesz, reqsz, padsz, c_namesz, c_padsz;
1077         __be32 *bp;
1078
1079         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1080                 return yfs_fs_symlink(fc, name, contents, current_data_version,
1081                                       newfid, newstatus);
1082
1083         _enter("");
1084
1085         namesz = strlen(name);
1086         padsz = (4 - (namesz & 3)) & 3;
1087
1088         c_namesz = strlen(contents);
1089         c_padsz = (4 - (c_namesz & 3)) & 3;
1090
1091         reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
1092
1093         call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
1094                                    (3 + 21 + 21 + 6) * 4);
1095         if (!call)
1096                 return -ENOMEM;
1097
1098         call->key = fc->key;
1099         call->reply[0] = vnode;
1100         call->reply[1] = newfid;
1101         call->reply[2] = newstatus;
1102         call->expected_version = current_data_version + 1;
1103
1104         /* marshall the parameters */
1105         bp = call->request;
1106         *bp++ = htonl(FSSYMLINK);
1107         *bp++ = htonl(vnode->fid.vid);
1108         *bp++ = htonl(vnode->fid.vnode);
1109         *bp++ = htonl(vnode->fid.unique);
1110         *bp++ = htonl(namesz);
1111         memcpy(bp, name, namesz);
1112         bp = (void *) bp + namesz;
1113         if (padsz > 0) {
1114                 memset(bp, 0, padsz);
1115                 bp = (void *) bp + padsz;
1116         }
1117         *bp++ = htonl(c_namesz);
1118         memcpy(bp, contents, c_namesz);
1119         bp = (void *) bp + c_namesz;
1120         if (c_padsz > 0) {
1121                 memset(bp, 0, c_padsz);
1122                 bp = (void *) bp + c_padsz;
1123         }
1124         *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
1125         *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1126         *bp++ = 0; /* owner */
1127         *bp++ = 0; /* group */
1128         *bp++ = htonl(S_IRWXUGO); /* unix mode */
1129         *bp++ = 0; /* segment size */
1130
1131         afs_use_fs_server(call, fc->cbi);
1132         trace_afs_make_fs_call(call, &vnode->fid);
1133         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1134 }
1135
1136 /*
1137  * deliver reply data to an FS.Rename
1138  */
1139 static int afs_deliver_fs_rename(struct afs_call *call)
1140 {
1141         struct afs_vnode *orig_dvnode = call->reply[0], *new_dvnode = call->reply[1];
1142         const __be32 *bp;
1143         int ret;
1144
1145         _enter("{%u}", call->unmarshall);
1146
1147         ret = afs_transfer_reply(call);
1148         if (ret < 0)
1149                 return ret;
1150
1151         /* unmarshall the reply once we've received all of it */
1152         bp = call->buffer;
1153         ret = afs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1154                                 &call->expected_version, NULL);
1155         if (ret < 0)
1156                 return ret;
1157         if (new_dvnode != orig_dvnode) {
1158                 ret = afs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1159                                         &call->expected_version_2, NULL);
1160                 if (ret < 0)
1161                         return ret;
1162         }
1163         /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1164
1165         _leave(" = 0 [done]");
1166         return 0;
1167 }
1168
1169 /*
1170  * FS.Rename operation type
1171  */
1172 static const struct afs_call_type afs_RXFSRename = {
1173         .name           = "FS.Rename",
1174         .op             = afs_FS_Rename,
1175         .deliver        = afs_deliver_fs_rename,
1176         .destructor     = afs_flat_call_destructor,
1177 };
1178
1179 /*
1180  * create a symbolic link
1181  */
1182 int afs_fs_rename(struct afs_fs_cursor *fc,
1183                   const char *orig_name,
1184                   struct afs_vnode *new_dvnode,
1185                   const char *new_name,
1186                   u64 current_orig_data_version,
1187                   u64 current_new_data_version)
1188 {
1189         struct afs_vnode *orig_dvnode = fc->vnode;
1190         struct afs_call *call;
1191         struct afs_net *net = afs_v2net(orig_dvnode);
1192         size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1193         __be32 *bp;
1194
1195         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1196                 return yfs_fs_rename(fc, orig_name,
1197                                      new_dvnode, new_name,
1198                                      current_orig_data_version,
1199                                      current_new_data_version);
1200
1201         _enter("");
1202
1203         o_namesz = strlen(orig_name);
1204         o_padsz = (4 - (o_namesz & 3)) & 3;
1205
1206         n_namesz = strlen(new_name);
1207         n_padsz = (4 - (n_namesz & 3)) & 3;
1208
1209         reqsz = (4 * 4) +
1210                 4 + o_namesz + o_padsz +
1211                 (3 * 4) +
1212                 4 + n_namesz + n_padsz;
1213
1214         call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1215         if (!call)
1216                 return -ENOMEM;
1217
1218         call->key = fc->key;
1219         call->reply[0] = orig_dvnode;
1220         call->reply[1] = new_dvnode;
1221         call->expected_version = current_orig_data_version + 1;
1222         call->expected_version_2 = current_new_data_version + 1;
1223
1224         /* marshall the parameters */
1225         bp = call->request;
1226         *bp++ = htonl(FSRENAME);
1227         *bp++ = htonl(orig_dvnode->fid.vid);
1228         *bp++ = htonl(orig_dvnode->fid.vnode);
1229         *bp++ = htonl(orig_dvnode->fid.unique);
1230         *bp++ = htonl(o_namesz);
1231         memcpy(bp, orig_name, o_namesz);
1232         bp = (void *) bp + o_namesz;
1233         if (o_padsz > 0) {
1234                 memset(bp, 0, o_padsz);
1235                 bp = (void *) bp + o_padsz;
1236         }
1237
1238         *bp++ = htonl(new_dvnode->fid.vid);
1239         *bp++ = htonl(new_dvnode->fid.vnode);
1240         *bp++ = htonl(new_dvnode->fid.unique);
1241         *bp++ = htonl(n_namesz);
1242         memcpy(bp, new_name, n_namesz);
1243         bp = (void *) bp + n_namesz;
1244         if (n_padsz > 0) {
1245                 memset(bp, 0, n_padsz);
1246                 bp = (void *) bp + n_padsz;
1247         }
1248
1249         afs_use_fs_server(call, fc->cbi);
1250         trace_afs_make_fs_call(call, &orig_dvnode->fid);
1251         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1252 }
1253
1254 /*
1255  * deliver reply data to an FS.StoreData
1256  */
1257 static int afs_deliver_fs_store_data(struct afs_call *call)
1258 {
1259         struct afs_vnode *vnode = call->reply[0];
1260         const __be32 *bp;
1261         int ret;
1262
1263         _enter("");
1264
1265         ret = afs_transfer_reply(call);
1266         if (ret < 0)
1267                 return ret;
1268
1269         /* unmarshall the reply once we've received all of it */
1270         bp = call->buffer;
1271         ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1272                                 &call->expected_version, NULL);
1273         if (ret < 0)
1274                 return ret;
1275         /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1276
1277         afs_pages_written_back(vnode, call);
1278
1279         _leave(" = 0 [done]");
1280         return 0;
1281 }
1282
1283 /*
1284  * FS.StoreData operation type
1285  */
1286 static const struct afs_call_type afs_RXFSStoreData = {
1287         .name           = "FS.StoreData",
1288         .op             = afs_FS_StoreData,
1289         .deliver        = afs_deliver_fs_store_data,
1290         .destructor     = afs_flat_call_destructor,
1291 };
1292
1293 static const struct afs_call_type afs_RXFSStoreData64 = {
1294         .name           = "FS.StoreData64",
1295         .op             = afs_FS_StoreData64,
1296         .deliver        = afs_deliver_fs_store_data,
1297         .destructor     = afs_flat_call_destructor,
1298 };
1299
1300 /*
1301  * store a set of pages to a very large file
1302  */
1303 static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1304                                struct address_space *mapping,
1305                                pgoff_t first, pgoff_t last,
1306                                unsigned offset, unsigned to,
1307                                loff_t size, loff_t pos, loff_t i_size)
1308 {
1309         struct afs_vnode *vnode = fc->vnode;
1310         struct afs_call *call;
1311         struct afs_net *net = afs_v2net(vnode);
1312         __be32 *bp;
1313
1314         _enter(",%x,{%llx:%llu},,",
1315                key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1316
1317         call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
1318                                    (4 + 6 + 3 * 2) * 4,
1319                                    (21 + 6) * 4);
1320         if (!call)
1321                 return -ENOMEM;
1322
1323         call->key = fc->key;
1324         call->mapping = mapping;
1325         call->reply[0] = vnode;
1326         call->first = first;
1327         call->last = last;
1328         call->first_offset = offset;
1329         call->last_to = to;
1330         call->send_pages = true;
1331         call->expected_version = vnode->status.data_version + 1;
1332
1333         /* marshall the parameters */
1334         bp = call->request;
1335         *bp++ = htonl(FSSTOREDATA64);
1336         *bp++ = htonl(vnode->fid.vid);
1337         *bp++ = htonl(vnode->fid.vnode);
1338         *bp++ = htonl(vnode->fid.unique);
1339
1340         *bp++ = htonl(AFS_SET_MTIME); /* mask */
1341         *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1342         *bp++ = 0; /* owner */
1343         *bp++ = 0; /* group */
1344         *bp++ = 0; /* unix mode */
1345         *bp++ = 0; /* segment size */
1346
1347         *bp++ = htonl(pos >> 32);
1348         *bp++ = htonl((u32) pos);
1349         *bp++ = htonl(size >> 32);
1350         *bp++ = htonl((u32) size);
1351         *bp++ = htonl(i_size >> 32);
1352         *bp++ = htonl((u32) i_size);
1353
1354         trace_afs_make_fs_call(call, &vnode->fid);
1355         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1356 }
1357
1358 /*
1359  * store a set of pages
1360  */
1361 int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1362                       pgoff_t first, pgoff_t last,
1363                       unsigned offset, unsigned to)
1364 {
1365         struct afs_vnode *vnode = fc->vnode;
1366         struct afs_call *call;
1367         struct afs_net *net = afs_v2net(vnode);
1368         loff_t size, pos, i_size;
1369         __be32 *bp;
1370
1371         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1372                 return yfs_fs_store_data(fc, mapping, first, last, offset, to);
1373
1374         _enter(",%x,{%llx:%llu},,",
1375                key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1376
1377         size = (loff_t)to - (loff_t)offset;
1378         if (first != last)
1379                 size += (loff_t)(last - first) << PAGE_SHIFT;
1380         pos = (loff_t)first << PAGE_SHIFT;
1381         pos += offset;
1382
1383         i_size = i_size_read(&vnode->vfs_inode);
1384         if (pos + size > i_size)
1385                 i_size = size + pos;
1386
1387         _debug("size %llx, at %llx, i_size %llx",
1388                (unsigned long long) size, (unsigned long long) pos,
1389                (unsigned long long) i_size);
1390
1391         if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1392                 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
1393                                            size, pos, i_size);
1394
1395         call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1396                                    (4 + 6 + 3) * 4,
1397                                    (21 + 6) * 4);
1398         if (!call)
1399                 return -ENOMEM;
1400
1401         call->key = fc->key;
1402         call->mapping = mapping;
1403         call->reply[0] = vnode;
1404         call->first = first;
1405         call->last = last;
1406         call->first_offset = offset;
1407         call->last_to = to;
1408         call->send_pages = true;
1409         call->expected_version = vnode->status.data_version + 1;
1410
1411         /* marshall the parameters */
1412         bp = call->request;
1413         *bp++ = htonl(FSSTOREDATA);
1414         *bp++ = htonl(vnode->fid.vid);
1415         *bp++ = htonl(vnode->fid.vnode);
1416         *bp++ = htonl(vnode->fid.unique);
1417
1418         *bp++ = htonl(AFS_SET_MTIME); /* mask */
1419         *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1420         *bp++ = 0; /* owner */
1421         *bp++ = 0; /* group */
1422         *bp++ = 0; /* unix mode */
1423         *bp++ = 0; /* segment size */
1424
1425         *bp++ = htonl(pos);
1426         *bp++ = htonl(size);
1427         *bp++ = htonl(i_size);
1428
1429         afs_use_fs_server(call, fc->cbi);
1430         trace_afs_make_fs_call(call, &vnode->fid);
1431         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1432 }
1433
1434 /*
1435  * deliver reply data to an FS.StoreStatus
1436  */
1437 static int afs_deliver_fs_store_status(struct afs_call *call)
1438 {
1439         struct afs_vnode *vnode = call->reply[0];
1440         const __be32 *bp;
1441         int ret;
1442
1443         _enter("");
1444
1445         ret = afs_transfer_reply(call);
1446         if (ret < 0)
1447                 return ret;
1448
1449         /* unmarshall the reply once we've received all of it */
1450         bp = call->buffer;
1451         ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1452                                 &call->expected_version, NULL);
1453         if (ret < 0)
1454                 return ret;
1455         /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1456
1457         _leave(" = 0 [done]");
1458         return 0;
1459 }
1460
1461 /*
1462  * FS.StoreStatus operation type
1463  */
1464 static const struct afs_call_type afs_RXFSStoreStatus = {
1465         .name           = "FS.StoreStatus",
1466         .op             = afs_FS_StoreStatus,
1467         .deliver        = afs_deliver_fs_store_status,
1468         .destructor     = afs_flat_call_destructor,
1469 };
1470
1471 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1472         .name           = "FS.StoreData",
1473         .op             = afs_FS_StoreData,
1474         .deliver        = afs_deliver_fs_store_status,
1475         .destructor     = afs_flat_call_destructor,
1476 };
1477
1478 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1479         .name           = "FS.StoreData64",
1480         .op             = afs_FS_StoreData64,
1481         .deliver        = afs_deliver_fs_store_status,
1482         .destructor     = afs_flat_call_destructor,
1483 };
1484
1485 /*
1486  * set the attributes on a very large file, using FS.StoreData rather than
1487  * FS.StoreStatus so as to alter the file size also
1488  */
1489 static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr)
1490 {
1491         struct afs_vnode *vnode = fc->vnode;
1492         struct afs_call *call;
1493         struct afs_net *net = afs_v2net(vnode);
1494         __be32 *bp;
1495
1496         _enter(",%x,{%llx:%llu},,",
1497                key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1498
1499         ASSERT(attr->ia_valid & ATTR_SIZE);
1500
1501         call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
1502                                    (4 + 6 + 3 * 2) * 4,
1503                                    (21 + 6) * 4);
1504         if (!call)
1505                 return -ENOMEM;
1506
1507         call->key = fc->key;
1508         call->reply[0] = vnode;
1509         call->expected_version = vnode->status.data_version + 1;
1510
1511         /* marshall the parameters */
1512         bp = call->request;
1513         *bp++ = htonl(FSSTOREDATA64);
1514         *bp++ = htonl(vnode->fid.vid);
1515         *bp++ = htonl(vnode->fid.vnode);
1516         *bp++ = htonl(vnode->fid.unique);
1517
1518         xdr_encode_AFS_StoreStatus(&bp, attr);
1519
1520         *bp++ = 0;                              /* position of start of write */
1521         *bp++ = 0;
1522         *bp++ = 0;                              /* size of write */
1523         *bp++ = 0;
1524         *bp++ = htonl(attr->ia_size >> 32);     /* new file length */
1525         *bp++ = htonl((u32) attr->ia_size);
1526
1527         afs_use_fs_server(call, fc->cbi);
1528         trace_afs_make_fs_call(call, &vnode->fid);
1529         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1530 }
1531
1532 /*
1533  * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1534  * so as to alter the file size also
1535  */
1536 static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
1537 {
1538         struct afs_vnode *vnode = fc->vnode;
1539         struct afs_call *call;
1540         struct afs_net *net = afs_v2net(vnode);
1541         __be32 *bp;
1542
1543         _enter(",%x,{%llx:%llu},,",
1544                key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1545
1546         ASSERT(attr->ia_valid & ATTR_SIZE);
1547         if (attr->ia_size >> 32)
1548                 return afs_fs_setattr_size64(fc, attr);
1549
1550         call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1551                                    (4 + 6 + 3) * 4,
1552                                    (21 + 6) * 4);
1553         if (!call)
1554                 return -ENOMEM;
1555
1556         call->key = fc->key;
1557         call->reply[0] = vnode;
1558         call->expected_version = vnode->status.data_version + 1;
1559
1560         /* marshall the parameters */
1561         bp = call->request;
1562         *bp++ = htonl(FSSTOREDATA);
1563         *bp++ = htonl(vnode->fid.vid);
1564         *bp++ = htonl(vnode->fid.vnode);
1565         *bp++ = htonl(vnode->fid.unique);
1566
1567         xdr_encode_AFS_StoreStatus(&bp, attr);
1568
1569         *bp++ = 0;                              /* position of start of write */
1570         *bp++ = 0;                              /* size of write */
1571         *bp++ = htonl(attr->ia_size);           /* new file length */
1572
1573         afs_use_fs_server(call, fc->cbi);
1574         trace_afs_make_fs_call(call, &vnode->fid);
1575         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1576 }
1577
1578 /*
1579  * set the attributes on a file, using FS.StoreData if there's a change in file
1580  * size, and FS.StoreStatus otherwise
1581  */
1582 int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
1583 {
1584         struct afs_vnode *vnode = fc->vnode;
1585         struct afs_call *call;
1586         struct afs_net *net = afs_v2net(vnode);
1587         __be32 *bp;
1588
1589         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1590                 return yfs_fs_setattr(fc, attr);
1591
1592         if (attr->ia_valid & ATTR_SIZE)
1593                 return afs_fs_setattr_size(fc, attr);
1594
1595         _enter(",%x,{%llx:%llu},,",
1596                key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1597
1598         call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1599                                    (4 + 6) * 4,
1600                                    (21 + 6) * 4);
1601         if (!call)
1602                 return -ENOMEM;
1603
1604         call->key = fc->key;
1605         call->reply[0] = vnode;
1606         call->expected_version = vnode->status.data_version;
1607
1608         /* marshall the parameters */
1609         bp = call->request;
1610         *bp++ = htonl(FSSTORESTATUS);
1611         *bp++ = htonl(vnode->fid.vid);
1612         *bp++ = htonl(vnode->fid.vnode);
1613         *bp++ = htonl(vnode->fid.unique);
1614
1615         xdr_encode_AFS_StoreStatus(&bp, attr);
1616
1617         afs_use_fs_server(call, fc->cbi);
1618         trace_afs_make_fs_call(call, &vnode->fid);
1619         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1620 }
1621
1622 /*
1623  * deliver reply data to an FS.GetVolumeStatus
1624  */
1625 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1626 {
1627         const __be32 *bp;
1628         char *p;
1629         u32 size;
1630         int ret;
1631
1632         _enter("{%u}", call->unmarshall);
1633
1634         switch (call->unmarshall) {
1635         case 0:
1636                 call->unmarshall++;
1637                 afs_extract_to_buf(call, 12 * 4);
1638
1639                 /* Fall through - and extract the returned status record */
1640         case 1:
1641                 _debug("extract status");
1642                 ret = afs_extract_data(call, true);
1643                 if (ret < 0)
1644                         return ret;
1645
1646                 bp = call->buffer;
1647                 xdr_decode_AFSFetchVolumeStatus(&bp, call->reply[1]);
1648                 call->unmarshall++;
1649                 afs_extract_to_tmp(call);
1650
1651                 /* Fall through - and extract the volume name length */
1652         case 2:
1653                 ret = afs_extract_data(call, true);
1654                 if (ret < 0)
1655                         return ret;
1656
1657                 call->count = ntohl(call->tmp);
1658                 _debug("volname length: %u", call->count);
1659                 if (call->count >= AFSNAMEMAX)
1660                         return afs_protocol_error(call, -EBADMSG,
1661                                                   afs_eproto_volname_len);
1662                 size = (call->count + 3) & ~3; /* It's padded */
1663                 afs_extract_begin(call, call->reply[2], size);
1664                 call->unmarshall++;
1665
1666                 /* Fall through - and extract the volume name */
1667         case 3:
1668                 _debug("extract volname");
1669                 ret = afs_extract_data(call, true);
1670                 if (ret < 0)
1671                         return ret;
1672
1673                 p = call->reply[2];
1674                 p[call->count] = 0;
1675                 _debug("volname '%s'", p);
1676                 afs_extract_to_tmp(call);
1677                 call->unmarshall++;
1678
1679                 /* Fall through - and extract the offline message length */
1680         case 4:
1681                 ret = afs_extract_data(call, true);
1682                 if (ret < 0)
1683                         return ret;
1684
1685                 call->count = ntohl(call->tmp);
1686                 _debug("offline msg length: %u", call->count);
1687                 if (call->count >= AFSNAMEMAX)
1688                         return afs_protocol_error(call, -EBADMSG,
1689                                                   afs_eproto_offline_msg_len);
1690                 size = (call->count + 3) & ~3; /* It's padded */
1691                 afs_extract_begin(call, call->reply[2], size);
1692                 call->unmarshall++;
1693
1694                 /* Fall through - and extract the offline message */
1695         case 5:
1696                 _debug("extract offline");
1697                 ret = afs_extract_data(call, true);
1698                 if (ret < 0)
1699                         return ret;
1700
1701                 p = call->reply[2];
1702                 p[call->count] = 0;
1703                 _debug("offline '%s'", p);
1704
1705                 afs_extract_to_tmp(call);
1706                 call->unmarshall++;
1707
1708                 /* Fall through - and extract the message of the day length */
1709         case 6:
1710                 ret = afs_extract_data(call, true);
1711                 if (ret < 0)
1712                         return ret;
1713
1714                 call->count = ntohl(call->tmp);
1715                 _debug("motd length: %u", call->count);
1716                 if (call->count >= AFSNAMEMAX)
1717                         return afs_protocol_error(call, -EBADMSG,
1718                                                   afs_eproto_motd_len);
1719                 size = (call->count + 3) & ~3; /* It's padded */
1720                 afs_extract_begin(call, call->reply[2], size);
1721                 call->unmarshall++;
1722
1723                 /* Fall through - and extract the message of the day */
1724         case 7:
1725                 _debug("extract motd");
1726                 ret = afs_extract_data(call, false);
1727                 if (ret < 0)
1728                         return ret;
1729
1730                 p = call->reply[2];
1731                 p[call->count] = 0;
1732                 _debug("motd '%s'", p);
1733
1734                 call->unmarshall++;
1735
1736         case 8:
1737                 break;
1738         }
1739
1740         _leave(" = 0 [done]");
1741         return 0;
1742 }
1743
1744 /*
1745  * destroy an FS.GetVolumeStatus call
1746  */
1747 static void afs_get_volume_status_call_destructor(struct afs_call *call)
1748 {
1749         kfree(call->reply[2]);
1750         call->reply[2] = NULL;
1751         afs_flat_call_destructor(call);
1752 }
1753
1754 /*
1755  * FS.GetVolumeStatus operation type
1756  */
1757 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1758         .name           = "FS.GetVolumeStatus",
1759         .op             = afs_FS_GetVolumeStatus,
1760         .deliver        = afs_deliver_fs_get_volume_status,
1761         .destructor     = afs_get_volume_status_call_destructor,
1762 };
1763
1764 /*
1765  * fetch the status of a volume
1766  */
1767 int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1768                              struct afs_volume_status *vs)
1769 {
1770         struct afs_vnode *vnode = fc->vnode;
1771         struct afs_call *call;
1772         struct afs_net *net = afs_v2net(vnode);
1773         __be32 *bp;
1774         void *tmpbuf;
1775
1776         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1777                 return yfs_fs_get_volume_status(fc, vs);
1778
1779         _enter("");
1780
1781         tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
1782         if (!tmpbuf)
1783                 return -ENOMEM;
1784
1785         call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
1786         if (!call) {
1787                 kfree(tmpbuf);
1788                 return -ENOMEM;
1789         }
1790
1791         call->key = fc->key;
1792         call->reply[0] = vnode;
1793         call->reply[1] = vs;
1794         call->reply[2] = tmpbuf;
1795
1796         /* marshall the parameters */
1797         bp = call->request;
1798         bp[0] = htonl(FSGETVOLUMESTATUS);
1799         bp[1] = htonl(vnode->fid.vid);
1800
1801         afs_use_fs_server(call, fc->cbi);
1802         trace_afs_make_fs_call(call, &vnode->fid);
1803         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1804 }
1805
1806 /*
1807  * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1808  */
1809 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1810 {
1811         const __be32 *bp;
1812         int ret;
1813
1814         _enter("{%u}", call->unmarshall);
1815
1816         ret = afs_transfer_reply(call);
1817         if (ret < 0)
1818                 return ret;
1819
1820         /* unmarshall the reply once we've received all of it */
1821         bp = call->buffer;
1822         /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1823
1824         _leave(" = 0 [done]");
1825         return 0;
1826 }
1827
1828 /*
1829  * FS.SetLock operation type
1830  */
1831 static const struct afs_call_type afs_RXFSSetLock = {
1832         .name           = "FS.SetLock",
1833         .op             = afs_FS_SetLock,
1834         .deliver        = afs_deliver_fs_xxxx_lock,
1835         .destructor     = afs_flat_call_destructor,
1836 };
1837
1838 /*
1839  * FS.ExtendLock operation type
1840  */
1841 static const struct afs_call_type afs_RXFSExtendLock = {
1842         .name           = "FS.ExtendLock",
1843         .op             = afs_FS_ExtendLock,
1844         .deliver        = afs_deliver_fs_xxxx_lock,
1845         .destructor     = afs_flat_call_destructor,
1846 };
1847
1848 /*
1849  * FS.ReleaseLock operation type
1850  */
1851 static const struct afs_call_type afs_RXFSReleaseLock = {
1852         .name           = "FS.ReleaseLock",
1853         .op             = afs_FS_ReleaseLock,
1854         .deliver        = afs_deliver_fs_xxxx_lock,
1855         .destructor     = afs_flat_call_destructor,
1856 };
1857
1858 /*
1859  * Set a lock on a file
1860  */
1861 int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
1862 {
1863         struct afs_vnode *vnode = fc->vnode;
1864         struct afs_call *call;
1865         struct afs_net *net = afs_v2net(vnode);
1866         __be32 *bp;
1867
1868         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1869                 return yfs_fs_set_lock(fc, type);
1870
1871         _enter("");
1872
1873         call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1874         if (!call)
1875                 return -ENOMEM;
1876
1877         call->key = fc->key;
1878         call->reply[0] = vnode;
1879
1880         /* marshall the parameters */
1881         bp = call->request;
1882         *bp++ = htonl(FSSETLOCK);
1883         *bp++ = htonl(vnode->fid.vid);
1884         *bp++ = htonl(vnode->fid.vnode);
1885         *bp++ = htonl(vnode->fid.unique);
1886         *bp++ = htonl(type);
1887
1888         afs_use_fs_server(call, fc->cbi);
1889         trace_afs_make_fs_call(call, &vnode->fid);
1890         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1891 }
1892
1893 /*
1894  * extend a lock on a file
1895  */
1896 int afs_fs_extend_lock(struct afs_fs_cursor *fc)
1897 {
1898         struct afs_vnode *vnode = fc->vnode;
1899         struct afs_call *call;
1900         struct afs_net *net = afs_v2net(vnode);
1901         __be32 *bp;
1902
1903         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1904                 return yfs_fs_extend_lock(fc);
1905
1906         _enter("");
1907
1908         call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1909         if (!call)
1910                 return -ENOMEM;
1911
1912         call->key = fc->key;
1913         call->reply[0] = vnode;
1914
1915         /* marshall the parameters */
1916         bp = call->request;
1917         *bp++ = htonl(FSEXTENDLOCK);
1918         *bp++ = htonl(vnode->fid.vid);
1919         *bp++ = htonl(vnode->fid.vnode);
1920         *bp++ = htonl(vnode->fid.unique);
1921
1922         afs_use_fs_server(call, fc->cbi);
1923         trace_afs_make_fs_call(call, &vnode->fid);
1924         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1925 }
1926
1927 /*
1928  * release a lock on a file
1929  */
1930 int afs_fs_release_lock(struct afs_fs_cursor *fc)
1931 {
1932         struct afs_vnode *vnode = fc->vnode;
1933         struct afs_call *call;
1934         struct afs_net *net = afs_v2net(vnode);
1935         __be32 *bp;
1936
1937         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1938                 return yfs_fs_release_lock(fc);
1939
1940         _enter("");
1941
1942         call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1943         if (!call)
1944                 return -ENOMEM;
1945
1946         call->key = fc->key;
1947         call->reply[0] = vnode;
1948
1949         /* marshall the parameters */
1950         bp = call->request;
1951         *bp++ = htonl(FSRELEASELOCK);
1952         *bp++ = htonl(vnode->fid.vid);
1953         *bp++ = htonl(vnode->fid.vnode);
1954         *bp++ = htonl(vnode->fid.unique);
1955
1956         afs_use_fs_server(call, fc->cbi);
1957         trace_afs_make_fs_call(call, &vnode->fid);
1958         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
1959 }
1960
1961 /*
1962  * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1963  */
1964 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1965 {
1966         return afs_transfer_reply(call);
1967 }
1968
1969 /*
1970  * FS.GiveUpAllCallBacks operation type
1971  */
1972 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1973         .name           = "FS.GiveUpAllCallBacks",
1974         .op             = afs_FS_GiveUpAllCallBacks,
1975         .deliver        = afs_deliver_fs_give_up_all_callbacks,
1976         .destructor     = afs_flat_call_destructor,
1977 };
1978
1979 /*
1980  * Flush all the callbacks we have on a server.
1981  */
1982 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1983                                  struct afs_server *server,
1984                                  struct afs_addr_cursor *ac,
1985                                  struct key *key)
1986 {
1987         struct afs_call *call;
1988         __be32 *bp;
1989
1990         _enter("");
1991
1992         call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1993         if (!call)
1994                 return -ENOMEM;
1995
1996         call->key = key;
1997
1998         /* marshall the parameters */
1999         bp = call->request;
2000         *bp++ = htonl(FSGIVEUPALLCALLBACKS);
2001
2002         /* Can't take a ref on server */
2003         return afs_make_call(ac, call, GFP_NOFS, false);
2004 }
2005
2006 /*
2007  * Deliver reply data to an FS.GetCapabilities operation.
2008  */
2009 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
2010 {
2011         u32 count;
2012         int ret;
2013
2014         _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
2015
2016         switch (call->unmarshall) {
2017         case 0:
2018                 afs_extract_to_tmp(call);
2019                 call->unmarshall++;
2020
2021                 /* Fall through - and extract the capabilities word count */
2022         case 1:
2023                 ret = afs_extract_data(call, true);
2024                 if (ret < 0)
2025                         return ret;
2026
2027                 count = ntohl(call->tmp);
2028
2029                 call->count = count;
2030                 call->count2 = count;
2031                 iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
2032                 call->unmarshall++;
2033
2034                 /* Fall through - and extract capabilities words */
2035         case 2:
2036                 ret = afs_extract_data(call, false);
2037                 if (ret < 0)
2038                         return ret;
2039
2040                 /* TODO: Examine capabilities */
2041
2042                 call->unmarshall++;
2043                 break;
2044         }
2045
2046         _leave(" = 0 [done]");
2047         return 0;
2048 }
2049
2050 static void afs_destroy_fs_get_capabilities(struct afs_call *call)
2051 {
2052         struct afs_server *server = call->reply[0];
2053
2054         afs_put_server(call->net, server);
2055         afs_flat_call_destructor(call);
2056 }
2057
2058 /*
2059  * FS.GetCapabilities operation type
2060  */
2061 static const struct afs_call_type afs_RXFSGetCapabilities = {
2062         .name           = "FS.GetCapabilities",
2063         .op             = afs_FS_GetCapabilities,
2064         .deliver        = afs_deliver_fs_get_capabilities,
2065         .done           = afs_fileserver_probe_result,
2066         .destructor     = afs_destroy_fs_get_capabilities,
2067 };
2068
2069 /*
2070  * Probe a fileserver for the capabilities that it supports.  This can
2071  * return up to 196 words.
2072  */
2073 int afs_fs_get_capabilities(struct afs_net *net,
2074                             struct afs_server *server,
2075                             struct afs_addr_cursor *ac,
2076                             struct key *key,
2077                             unsigned int server_index,
2078                             bool async)
2079 {
2080         struct afs_call *call;
2081         __be32 *bp;
2082
2083         _enter("");
2084
2085         call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
2086         if (!call)
2087                 return -ENOMEM;
2088
2089         call->key = key;
2090         call->reply[0] = afs_get_server(server);
2091         call->reply[1] = (void *)(long)server_index;
2092         call->upgrade = true;
2093         call->want_reply_time = true;
2094
2095         /* marshall the parameters */
2096         bp = call->request;
2097         *bp++ = htonl(FSGETCAPABILITIES);
2098
2099         /* Can't take a ref on server */
2100         trace_afs_make_fs_call(call, NULL);
2101         return afs_make_call(ac, call, GFP_NOFS, async);
2102 }
2103
2104 /*
2105  * Deliver reply data to an FS.FetchStatus with no vnode.
2106  */
2107 static int afs_deliver_fs_fetch_status(struct afs_call *call)
2108 {
2109         struct afs_file_status *status = call->reply[1];
2110         struct afs_callback *callback = call->reply[2];
2111         struct afs_volsync *volsync = call->reply[3];
2112         struct afs_fid *fid = call->reply[0];
2113         const __be32 *bp;
2114         int ret;
2115
2116         ret = afs_transfer_reply(call);
2117         if (ret < 0)
2118                 return ret;
2119
2120         _enter("{%llx:%llu}", fid->vid, fid->vnode);
2121
2122         /* unmarshall the reply once we've received all of it */
2123         bp = call->buffer;
2124         ret = afs_decode_status(call, &bp, status, NULL,
2125                                 &call->expected_version, NULL);
2126         if (ret < 0)
2127                 return ret;
2128         xdr_decode_AFSCallBack_raw(call, &bp, callback);
2129         xdr_decode_AFSVolSync(&bp, volsync);
2130
2131         _leave(" = 0 [done]");
2132         return 0;
2133 }
2134
2135 /*
2136  * FS.FetchStatus operation type
2137  */
2138 static const struct afs_call_type afs_RXFSFetchStatus = {
2139         .name           = "FS.FetchStatus",
2140         .op             = afs_FS_FetchStatus,
2141         .deliver        = afs_deliver_fs_fetch_status,
2142         .destructor     = afs_flat_call_destructor,
2143 };
2144
2145 /*
2146  * Fetch the status information for a fid without needing a vnode handle.
2147  */
2148 int afs_fs_fetch_status(struct afs_fs_cursor *fc,
2149                         struct afs_net *net,
2150                         struct afs_fid *fid,
2151                         struct afs_file_status *status,
2152                         struct afs_callback *callback,
2153                         struct afs_volsync *volsync)
2154 {
2155         struct afs_call *call;
2156         __be32 *bp;
2157
2158         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2159                 return yfs_fs_fetch_status(fc, net, fid, status, callback, volsync);
2160
2161         _enter(",%x,{%llx:%llu},,",
2162                key_serial(fc->key), fid->vid, fid->vnode);
2163
2164         call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
2165         if (!call) {
2166                 fc->ac.error = -ENOMEM;
2167                 return -ENOMEM;
2168         }
2169
2170         call->key = fc->key;
2171         call->reply[0] = fid;
2172         call->reply[1] = status;
2173         call->reply[2] = callback;
2174         call->reply[3] = volsync;
2175         call->expected_version = 1; /* vnode->status.data_version */
2176         call->want_reply_time = true;
2177
2178         /* marshall the parameters */
2179         bp = call->request;
2180         bp[0] = htonl(FSFETCHSTATUS);
2181         bp[1] = htonl(fid->vid);
2182         bp[2] = htonl(fid->vnode);
2183         bp[3] = htonl(fid->unique);
2184
2185         call->cb_break = fc->cb_break;
2186         afs_use_fs_server(call, fc->cbi);
2187         trace_afs_make_fs_call(call, fid);
2188         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
2189 }
2190
2191 /*
2192  * Deliver reply data to an FS.InlineBulkStatus call
2193  */
2194 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2195 {
2196         struct afs_file_status *statuses;
2197         struct afs_callback *callbacks;
2198         struct afs_vnode *vnode = call->reply[0];
2199         const __be32 *bp;
2200         u32 tmp;
2201         int ret;
2202
2203         _enter("{%u}", call->unmarshall);
2204
2205         switch (call->unmarshall) {
2206         case 0:
2207                 afs_extract_to_tmp(call);
2208                 call->unmarshall++;
2209
2210                 /* Extract the file status count and array in two steps */
2211                 /* Fall through */
2212         case 1:
2213                 _debug("extract status count");
2214                 ret = afs_extract_data(call, true);
2215                 if (ret < 0)
2216                         return ret;
2217
2218                 tmp = ntohl(call->tmp);
2219                 _debug("status count: %u/%u", tmp, call->count2);
2220                 if (tmp != call->count2)
2221                         return afs_protocol_error(call, -EBADMSG,
2222                                                   afs_eproto_ibulkst_count);
2223
2224                 call->count = 0;
2225                 call->unmarshall++;
2226         more_counts:
2227                 afs_extract_to_buf(call, 21 * sizeof(__be32));
2228
2229                 /* Fall through */
2230         case 2:
2231                 _debug("extract status array %u", call->count);
2232                 ret = afs_extract_data(call, true);
2233                 if (ret < 0)
2234                         return ret;
2235
2236                 bp = call->buffer;
2237                 statuses = call->reply[1];
2238                 ret = afs_decode_status(call, &bp, &statuses[call->count],
2239                                         call->count == 0 ? vnode : NULL,
2240                                         NULL, NULL);
2241                 if (ret < 0)
2242                         return ret;
2243
2244                 call->count++;
2245                 if (call->count < call->count2)
2246                         goto more_counts;
2247
2248                 call->count = 0;
2249                 call->unmarshall++;
2250                 afs_extract_to_tmp(call);
2251
2252                 /* Extract the callback count and array in two steps */
2253                 /* Fall through */
2254         case 3:
2255                 _debug("extract CB count");
2256                 ret = afs_extract_data(call, true);
2257                 if (ret < 0)
2258                         return ret;
2259
2260                 tmp = ntohl(call->tmp);
2261                 _debug("CB count: %u", tmp);
2262                 if (tmp != call->count2)
2263                         return afs_protocol_error(call, -EBADMSG,
2264                                                   afs_eproto_ibulkst_cb_count);
2265                 call->count = 0;
2266                 call->unmarshall++;
2267         more_cbs:
2268                 afs_extract_to_buf(call, 3 * sizeof(__be32));
2269
2270                 /* Fall through */
2271         case 4:
2272                 _debug("extract CB array");
2273                 ret = afs_extract_data(call, true);
2274                 if (ret < 0)
2275                         return ret;
2276
2277                 _debug("unmarshall CB array");
2278                 bp = call->buffer;
2279                 callbacks = call->reply[2];
2280                 callbacks[call->count].version  = ntohl(bp[0]);
2281                 callbacks[call->count].expires_at = xdr_decode_expiry(call, ntohl(bp[1]));
2282                 callbacks[call->count].type     = ntohl(bp[2]);
2283                 statuses = call->reply[1];
2284                 if (call->count == 0 && vnode && statuses[0].abort_code == 0)
2285                         xdr_decode_AFSCallBack(call, vnode, &bp);
2286                 call->count++;
2287                 if (call->count < call->count2)
2288                         goto more_cbs;
2289
2290                 afs_extract_to_buf(call, 6 * sizeof(__be32));
2291                 call->unmarshall++;
2292
2293                 /* Fall through */
2294         case 5:
2295                 ret = afs_extract_data(call, false);
2296                 if (ret < 0)
2297                         return ret;
2298
2299                 bp = call->buffer;
2300                 xdr_decode_AFSVolSync(&bp, call->reply[3]);
2301
2302                 call->unmarshall++;
2303
2304         case 6:
2305                 break;
2306         }
2307
2308         _leave(" = 0 [done]");
2309         return 0;
2310 }
2311
2312 /*
2313  * FS.InlineBulkStatus operation type
2314  */
2315 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2316         .name           = "FS.InlineBulkStatus",
2317         .op             = afs_FS_InlineBulkStatus,
2318         .deliver        = afs_deliver_fs_inline_bulk_status,
2319         .destructor     = afs_flat_call_destructor,
2320 };
2321
2322 /*
2323  * Fetch the status information for up to 50 files
2324  */
2325 int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2326                               struct afs_net *net,
2327                               struct afs_fid *fids,
2328                               struct afs_file_status *statuses,
2329                               struct afs_callback *callbacks,
2330                               unsigned int nr_fids,
2331                               struct afs_volsync *volsync)
2332 {
2333         struct afs_call *call;
2334         __be32 *bp;
2335         int i;
2336
2337         if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2338                 return yfs_fs_inline_bulk_status(fc, net, fids, statuses, callbacks,
2339                                                  nr_fids, volsync);
2340
2341         _enter(",%x,{%llx:%llu},%u",
2342                key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2343
2344         call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2345                                    (2 + nr_fids * 3) * 4,
2346                                    21 * 4);
2347         if (!call) {
2348                 fc->ac.error = -ENOMEM;
2349                 return -ENOMEM;
2350         }
2351
2352         call->key = fc->key;
2353         call->reply[0] = NULL; /* vnode for fid[0] */
2354         call->reply[1] = statuses;
2355         call->reply[2] = callbacks;
2356         call->reply[3] = volsync;
2357         call->count2 = nr_fids;
2358         call->want_reply_time = true;
2359
2360         /* marshall the parameters */
2361         bp = call->request;
2362         *bp++ = htonl(FSINLINEBULKSTATUS);
2363         *bp++ = htonl(nr_fids);
2364         for (i = 0; i < nr_fids; i++) {
2365                 *bp++ = htonl(fids[i].vid);
2366                 *bp++ = htonl(fids[i].vnode);
2367                 *bp++ = htonl(fids[i].unique);
2368         }
2369
2370         call->cb_break = fc->cb_break;
2371         afs_use_fs_server(call, fc->cbi);
2372         trace_afs_make_fs_call(call, &fids[0]);
2373         return afs_make_call(&fc->ac, call, GFP_NOFS, false);
2374 }