1 /* AFS File Server client stubs
3 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
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>
20 #include "protocol_yfs.h"
22 static const struct afs_fid afs_zero_fid;
24 static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
26 call->cbi = afs_get_cb_interest(cbi);
30 * decode an AFSFid block
32 static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
34 const __be32 *bp = *_bp;
36 fid->vid = ntohl(*bp++);
37 fid->vnode = ntohl(*bp++);
38 fid->unique = ntohl(*bp++);
43 * Dump a bad file status record.
45 static void xdr_dump_bad(const __be32 *bp)
50 pr_notice("AFS XDR: Bad status record\n");
51 for (i = 0; i < 5 * 4 * 4; i += 16) {
54 pr_notice("%03x: %08x %08x %08x %08x\n",
55 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
59 pr_notice("0x50: %08x\n", ntohl(x[0]));
63 * decode an AFSFetchStatus block
65 static int xdr_decode_AFSFetchStatus(const __be32 **_bp,
66 struct afs_call *call,
67 struct afs_status_cb *scb)
69 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
70 struct afs_file_status *status = &scb->status;
71 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
72 u64 data_version, size;
75 abort_code = ntohl(xdr->abort_code);
77 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
78 if (xdr->if_version == htonl(0) &&
81 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
82 * whereby it doesn't set the interface version in the error
85 status->abort_code = abort_code;
89 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
93 if (abort_code != 0 && inline_error) {
94 status->abort_code = abort_code;
98 type = ntohl(xdr->type);
102 case AFS_FTYPE_SYMLINK:
109 status->nlink = ntohl(xdr->nlink);
110 status->author = ntohl(xdr->author);
111 status->owner = ntohl(xdr->owner);
112 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
113 status->anon_access = ntohl(xdr->anon_access);
114 status->mode = ntohl(xdr->mode) & S_IALLUGO;
115 status->group = ntohl(xdr->group);
116 status->lock_count = ntohl(xdr->lock_count);
118 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
119 status->mtime_client.tv_nsec = 0;
120 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
121 status->mtime_server.tv_nsec = 0;
123 size = (u64)ntohl(xdr->size_lo);
124 size |= (u64)ntohl(xdr->size_hi) << 32;
127 data_version = (u64)ntohl(xdr->data_version_lo);
128 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
129 status->data_version = data_version;
131 *_bp = (const void *)*_bp + sizeof(*xdr);
136 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
139 static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
141 return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
144 static void xdr_decode_AFSCallBack(const __be32 **_bp,
145 struct afs_call *call,
146 struct afs_status_cb *scb)
148 struct afs_callback *cb = &scb->callback;
149 const __be32 *bp = *_bp;
151 cb->version = ntohl(*bp++);
152 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
153 cb->type = ntohl(*bp++);
159 * decode an AFSVolSync block
161 static void xdr_decode_AFSVolSync(const __be32 **_bp,
162 struct afs_volsync *volsync)
164 const __be32 *bp = *_bp;
167 creation = ntohl(*bp++);
176 volsync->creation = creation;
180 * encode the requested attributes into an AFSStoreStatus block
182 static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
185 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
188 if (attr->ia_valid & ATTR_MTIME) {
189 mask |= AFS_SET_MTIME;
190 mtime = attr->ia_mtime.tv_sec;
193 if (attr->ia_valid & ATTR_UID) {
194 mask |= AFS_SET_OWNER;
195 owner = from_kuid(&init_user_ns, attr->ia_uid);
198 if (attr->ia_valid & ATTR_GID) {
199 mask |= AFS_SET_GROUP;
200 group = from_kgid(&init_user_ns, attr->ia_gid);
203 if (attr->ia_valid & ATTR_MODE) {
204 mask |= AFS_SET_MODE;
205 mode = attr->ia_mode & S_IALLUGO;
209 *bp++ = htonl(mtime);
210 *bp++ = htonl(owner);
211 *bp++ = htonl(group);
213 *bp++ = 0; /* segment size */
218 * decode an AFSFetchVolumeStatus block
220 static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
221 struct afs_volume_status *vs)
223 const __be32 *bp = *_bp;
225 vs->vid = ntohl(*bp++);
226 vs->parent_id = ntohl(*bp++);
227 vs->online = ntohl(*bp++);
228 vs->in_service = ntohl(*bp++);
229 vs->blessed = ntohl(*bp++);
230 vs->needs_salvage = ntohl(*bp++);
231 vs->type = ntohl(*bp++);
232 vs->min_quota = ntohl(*bp++);
233 vs->max_quota = ntohl(*bp++);
234 vs->blocks_in_use = ntohl(*bp++);
235 vs->part_blocks_avail = ntohl(*bp++);
236 vs->part_max_blocks = ntohl(*bp++);
237 vs->vol_copy_date = 0;
238 vs->vol_backup_date = 0;
243 * deliver reply data to an FS.FetchStatus
245 static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
250 ret = afs_transfer_reply(call);
254 /* unmarshall the reply once we've received all of it */
256 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
259 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
260 xdr_decode_AFSVolSync(&bp, call->out_volsync);
262 _leave(" = 0 [done]");
267 * FS.FetchStatus operation type
269 static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
270 .name = "FS.FetchStatus(vnode)",
271 .op = afs_FS_FetchStatus,
272 .deliver = afs_deliver_fs_fetch_status_vnode,
273 .destructor = afs_flat_call_destructor,
277 * fetch the status information for a file
279 int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_status_cb *scb,
280 struct afs_volsync *volsync)
282 struct afs_vnode *vnode = fc->vnode;
283 struct afs_call *call;
284 struct afs_net *net = afs_v2net(vnode);
287 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
288 return yfs_fs_fetch_file_status(fc, scb, volsync);
290 _enter(",%x,{%llx:%llu},,",
291 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
293 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
294 16, (21 + 3 + 6) * 4);
296 fc->ac.error = -ENOMEM;
302 call->out_volsync = volsync;
304 /* marshall the parameters */
306 bp[0] = htonl(FSFETCHSTATUS);
307 bp[1] = htonl(vnode->fid.vid);
308 bp[2] = htonl(vnode->fid.vnode);
309 bp[3] = htonl(vnode->fid.unique);
311 afs_use_fs_server(call, fc->cbi);
312 trace_afs_make_fs_call(call, &vnode->fid);
314 afs_set_fc_call(call, fc);
315 afs_make_call(&fc->ac, call, GFP_NOFS);
316 return afs_wait_for_call_to_complete(call, &fc->ac);
320 * deliver reply data to an FS.FetchData
322 static int afs_deliver_fs_fetch_data(struct afs_call *call)
324 struct afs_read *req = call->read_request;
329 _enter("{%u,%zu/%llu}",
330 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
332 switch (call->unmarshall) {
336 req->offset = req->pos & (PAGE_SIZE - 1);
338 if (call->operation_ID == FSFETCHDATA64) {
339 afs_extract_to_tmp64(call);
341 call->tmp_u = htonl(0);
342 afs_extract_to_tmp(call);
345 /* Fall through - and extract the returned data length */
347 _debug("extract data length");
348 ret = afs_extract_data(call, true);
352 req->actual_len = be64_to_cpu(call->tmp64);
353 _debug("DATA length: %llu", req->actual_len);
354 req->remain = min(req->len, req->actual_len);
355 if (req->remain == 0)
361 ASSERTCMP(req->index, <, req->nr_pages);
362 if (req->remain > PAGE_SIZE - req->offset)
363 size = PAGE_SIZE - req->offset;
366 call->bvec[0].bv_len = size;
367 call->bvec[0].bv_offset = req->offset;
368 call->bvec[0].bv_page = req->pages[req->index];
369 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
370 ASSERTCMP(size, <=, PAGE_SIZE);
372 /* Fall through - and extract the returned data */
374 _debug("extract data %zu/%llu",
375 iov_iter_count(&call->iter), req->remain);
377 ret = afs_extract_data(call, true);
380 req->remain -= call->bvec[0].bv_len;
381 req->offset += call->bvec[0].bv_len;
382 ASSERTCMP(req->offset, <=, PAGE_SIZE);
383 if (req->offset == PAGE_SIZE) {
392 ASSERTCMP(req->remain, ==, 0);
393 if (req->actual_len <= req->len)
396 /* Discard any excess data the server gave us */
397 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
398 call->unmarshall = 3;
402 _debug("extract discard %zu/%llu",
403 iov_iter_count(&call->iter), req->actual_len - req->len);
405 ret = afs_extract_data(call, true);
410 call->unmarshall = 4;
411 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
413 /* Fall through - and extract the metadata */
415 ret = afs_extract_data(call, false);
420 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
423 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
424 xdr_decode_AFSVolSync(&bp, call->out_volsync);
426 req->data_version = call->out_scb->status.data_version;
427 req->file_size = call->out_scb->status.size;
435 for (; req->index < req->nr_pages; req->index++) {
436 if (req->offset < PAGE_SIZE)
437 zero_user_segment(req->pages[req->index],
438 req->offset, PAGE_SIZE);
444 _leave(" = 0 [done]");
448 static void afs_fetch_data_destructor(struct afs_call *call)
450 struct afs_read *req = call->read_request;
453 afs_flat_call_destructor(call);
457 * FS.FetchData operation type
459 static const struct afs_call_type afs_RXFSFetchData = {
460 .name = "FS.FetchData",
461 .op = afs_FS_FetchData,
462 .deliver = afs_deliver_fs_fetch_data,
463 .destructor = afs_fetch_data_destructor,
466 static const struct afs_call_type afs_RXFSFetchData64 = {
467 .name = "FS.FetchData64",
468 .op = afs_FS_FetchData64,
469 .deliver = afs_deliver_fs_fetch_data,
470 .destructor = afs_fetch_data_destructor,
474 * fetch data from a very large file
476 static int afs_fs_fetch_data64(struct afs_fs_cursor *fc,
477 struct afs_status_cb *scb,
478 struct afs_read *req)
480 struct afs_vnode *vnode = fc->vnode;
481 struct afs_call *call;
482 struct afs_net *net = afs_v2net(vnode);
487 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
493 call->out_volsync = NULL;
494 call->read_request = req;
496 /* marshall the parameters */
498 bp[0] = htonl(FSFETCHDATA64);
499 bp[1] = htonl(vnode->fid.vid);
500 bp[2] = htonl(vnode->fid.vnode);
501 bp[3] = htonl(vnode->fid.unique);
502 bp[4] = htonl(upper_32_bits(req->pos));
503 bp[5] = htonl(lower_32_bits(req->pos));
505 bp[7] = htonl(lower_32_bits(req->len));
507 refcount_inc(&req->usage);
508 afs_use_fs_server(call, fc->cbi);
509 trace_afs_make_fs_call(call, &vnode->fid);
510 afs_set_fc_call(call, fc);
511 afs_make_call(&fc->ac, call, GFP_NOFS);
512 return afs_wait_for_call_to_complete(call, &fc->ac);
516 * fetch data from a file
518 int afs_fs_fetch_data(struct afs_fs_cursor *fc,
519 struct afs_status_cb *scb,
520 struct afs_read *req)
522 struct afs_vnode *vnode = fc->vnode;
523 struct afs_call *call;
524 struct afs_net *net = afs_v2net(vnode);
527 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
528 return yfs_fs_fetch_data(fc, scb, req);
530 if (upper_32_bits(req->pos) ||
531 upper_32_bits(req->len) ||
532 upper_32_bits(req->pos + req->len))
533 return afs_fs_fetch_data64(fc, scb, req);
537 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
543 call->out_volsync = NULL;
544 call->read_request = req;
546 /* marshall the parameters */
548 bp[0] = htonl(FSFETCHDATA);
549 bp[1] = htonl(vnode->fid.vid);
550 bp[2] = htonl(vnode->fid.vnode);
551 bp[3] = htonl(vnode->fid.unique);
552 bp[4] = htonl(lower_32_bits(req->pos));
553 bp[5] = htonl(lower_32_bits(req->len));
555 refcount_inc(&req->usage);
556 afs_use_fs_server(call, fc->cbi);
557 trace_afs_make_fs_call(call, &vnode->fid);
558 afs_set_fc_call(call, fc);
559 afs_make_call(&fc->ac, call, GFP_NOFS);
560 return afs_wait_for_call_to_complete(call, &fc->ac);
564 * deliver reply data to an FS.CreateFile or an FS.MakeDir
566 static int afs_deliver_fs_create_vnode(struct afs_call *call)
571 ret = afs_transfer_reply(call);
575 /* unmarshall the reply once we've received all of it */
577 xdr_decode_AFSFid(&bp, call->out_fid);
578 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
581 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
584 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
585 xdr_decode_AFSVolSync(&bp, call->out_volsync);
587 _leave(" = 0 [done]");
592 * FS.CreateFile and FS.MakeDir operation type
594 static const struct afs_call_type afs_RXFSCreateFile = {
595 .name = "FS.CreateFile",
596 .op = afs_FS_CreateFile,
597 .deliver = afs_deliver_fs_create_vnode,
598 .destructor = afs_flat_call_destructor,
601 static const struct afs_call_type afs_RXFSMakeDir = {
602 .name = "FS.MakeDir",
603 .op = afs_FS_MakeDir,
604 .deliver = afs_deliver_fs_create_vnode,
605 .destructor = afs_flat_call_destructor,
609 * create a file or make a directory
611 int afs_fs_create(struct afs_fs_cursor *fc,
614 struct afs_status_cb *dvnode_scb,
615 struct afs_fid *newfid,
616 struct afs_status_cb *new_scb)
618 struct afs_vnode *dvnode = fc->vnode;
619 struct afs_call *call;
620 struct afs_net *net = afs_v2net(dvnode);
621 size_t namesz, reqsz, padsz;
624 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
626 return yfs_fs_make_dir(fc, name, mode, dvnode_scb,
629 return yfs_fs_create_file(fc, name, mode, dvnode_scb,
635 namesz = strlen(name);
636 padsz = (4 - (namesz & 3)) & 3;
637 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
639 call = afs_alloc_flat_call(
640 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
641 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
646 call->out_dir_scb = dvnode_scb;
647 call->out_fid = newfid;
648 call->out_scb = new_scb;
650 /* marshall the parameters */
652 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
653 *bp++ = htonl(dvnode->fid.vid);
654 *bp++ = htonl(dvnode->fid.vnode);
655 *bp++ = htonl(dvnode->fid.unique);
656 *bp++ = htonl(namesz);
657 memcpy(bp, name, namesz);
658 bp = (void *) bp + namesz;
660 memset(bp, 0, padsz);
661 bp = (void *) bp + padsz;
663 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
664 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
665 *bp++ = 0; /* owner */
666 *bp++ = 0; /* group */
667 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
668 *bp++ = 0; /* segment size */
670 afs_use_fs_server(call, fc->cbi);
671 trace_afs_make_fs_call1(call, &dvnode->fid, name);
672 afs_set_fc_call(call, fc);
673 afs_make_call(&fc->ac, call, GFP_NOFS);
674 return afs_wait_for_call_to_complete(call, &fc->ac);
678 * Deliver reply data to any operation that returns directory status and volume
681 static int afs_deliver_fs_dir_status_and_vol(struct afs_call *call)
686 ret = afs_transfer_reply(call);
690 /* unmarshall the reply once we've received all of it */
692 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
695 xdr_decode_AFSVolSync(&bp, call->out_volsync);
697 _leave(" = 0 [done]");
702 * FS.RemoveDir/FS.RemoveFile operation type
704 static const struct afs_call_type afs_RXFSRemoveFile = {
705 .name = "FS.RemoveFile",
706 .op = afs_FS_RemoveFile,
707 .deliver = afs_deliver_fs_dir_status_and_vol,
708 .destructor = afs_flat_call_destructor,
711 static const struct afs_call_type afs_RXFSRemoveDir = {
712 .name = "FS.RemoveDir",
713 .op = afs_FS_RemoveDir,
714 .deliver = afs_deliver_fs_dir_status_and_vol,
715 .destructor = afs_flat_call_destructor,
719 * remove a file or directory
721 int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
722 const char *name, bool isdir, struct afs_status_cb *dvnode_scb)
724 struct afs_vnode *dvnode = fc->vnode;
725 struct afs_call *call;
726 struct afs_net *net = afs_v2net(dvnode);
727 size_t namesz, reqsz, padsz;
730 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
731 return yfs_fs_remove(fc, vnode, name, isdir, dvnode_scb);
735 namesz = strlen(name);
736 padsz = (4 - (namesz & 3)) & 3;
737 reqsz = (5 * 4) + namesz + padsz;
739 call = afs_alloc_flat_call(
740 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
741 reqsz, (21 + 6) * 4);
746 call->out_dir_scb = dvnode_scb;
748 /* marshall the parameters */
750 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
751 *bp++ = htonl(dvnode->fid.vid);
752 *bp++ = htonl(dvnode->fid.vnode);
753 *bp++ = htonl(dvnode->fid.unique);
754 *bp++ = htonl(namesz);
755 memcpy(bp, name, namesz);
756 bp = (void *) bp + namesz;
758 memset(bp, 0, padsz);
759 bp = (void *) bp + padsz;
762 afs_use_fs_server(call, fc->cbi);
763 trace_afs_make_fs_call1(call, &dvnode->fid, name);
764 afs_set_fc_call(call, fc);
765 afs_make_call(&fc->ac, call, GFP_NOFS);
766 return afs_wait_for_call_to_complete(call, &fc->ac);
770 * deliver reply data to an FS.Link
772 static int afs_deliver_fs_link(struct afs_call *call)
777 _enter("{%u}", call->unmarshall);
779 ret = afs_transfer_reply(call);
783 /* unmarshall the reply once we've received all of it */
785 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
788 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
791 xdr_decode_AFSVolSync(&bp, call->out_volsync);
793 _leave(" = 0 [done]");
798 * FS.Link operation type
800 static const struct afs_call_type afs_RXFSLink = {
803 .deliver = afs_deliver_fs_link,
804 .destructor = afs_flat_call_destructor,
810 int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
812 struct afs_status_cb *dvnode_scb,
813 struct afs_status_cb *vnode_scb)
815 struct afs_vnode *dvnode = fc->vnode;
816 struct afs_call *call;
817 struct afs_net *net = afs_v2net(vnode);
818 size_t namesz, reqsz, padsz;
821 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
822 return yfs_fs_link(fc, vnode, name, dvnode_scb, vnode_scb);
826 namesz = strlen(name);
827 padsz = (4 - (namesz & 3)) & 3;
828 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
830 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
835 call->out_dir_scb = dvnode_scb;
836 call->out_scb = vnode_scb;
838 /* marshall the parameters */
840 *bp++ = htonl(FSLINK);
841 *bp++ = htonl(dvnode->fid.vid);
842 *bp++ = htonl(dvnode->fid.vnode);
843 *bp++ = htonl(dvnode->fid.unique);
844 *bp++ = htonl(namesz);
845 memcpy(bp, name, namesz);
846 bp = (void *) bp + namesz;
848 memset(bp, 0, padsz);
849 bp = (void *) bp + padsz;
851 *bp++ = htonl(vnode->fid.vid);
852 *bp++ = htonl(vnode->fid.vnode);
853 *bp++ = htonl(vnode->fid.unique);
855 afs_use_fs_server(call, fc->cbi);
856 trace_afs_make_fs_call1(call, &vnode->fid, name);
857 afs_set_fc_call(call, fc);
858 afs_make_call(&fc->ac, call, GFP_NOFS);
859 return afs_wait_for_call_to_complete(call, &fc->ac);
863 * deliver reply data to an FS.Symlink
865 static int afs_deliver_fs_symlink(struct afs_call *call)
870 _enter("{%u}", call->unmarshall);
872 ret = afs_transfer_reply(call);
876 /* unmarshall the reply once we've received all of it */
878 xdr_decode_AFSFid(&bp, call->out_fid);
879 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
882 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
885 xdr_decode_AFSVolSync(&bp, call->out_volsync);
887 _leave(" = 0 [done]");
892 * FS.Symlink operation type
894 static const struct afs_call_type afs_RXFSSymlink = {
895 .name = "FS.Symlink",
896 .op = afs_FS_Symlink,
897 .deliver = afs_deliver_fs_symlink,
898 .destructor = afs_flat_call_destructor,
902 * create a symbolic link
904 int afs_fs_symlink(struct afs_fs_cursor *fc,
906 const char *contents,
907 struct afs_status_cb *dvnode_scb,
908 struct afs_fid *newfid,
909 struct afs_status_cb *new_scb)
911 struct afs_vnode *dvnode = fc->vnode;
912 struct afs_call *call;
913 struct afs_net *net = afs_v2net(dvnode);
914 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
917 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
918 return yfs_fs_symlink(fc, name, contents, dvnode_scb,
923 namesz = strlen(name);
924 padsz = (4 - (namesz & 3)) & 3;
926 c_namesz = strlen(contents);
927 c_padsz = (4 - (c_namesz & 3)) & 3;
929 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
931 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
932 (3 + 21 + 21 + 6) * 4);
937 call->out_dir_scb = dvnode_scb;
938 call->out_fid = newfid;
939 call->out_scb = new_scb;
941 /* marshall the parameters */
943 *bp++ = htonl(FSSYMLINK);
944 *bp++ = htonl(dvnode->fid.vid);
945 *bp++ = htonl(dvnode->fid.vnode);
946 *bp++ = htonl(dvnode->fid.unique);
947 *bp++ = htonl(namesz);
948 memcpy(bp, name, namesz);
949 bp = (void *) bp + namesz;
951 memset(bp, 0, padsz);
952 bp = (void *) bp + padsz;
954 *bp++ = htonl(c_namesz);
955 memcpy(bp, contents, c_namesz);
956 bp = (void *) bp + c_namesz;
958 memset(bp, 0, c_padsz);
959 bp = (void *) bp + c_padsz;
961 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
962 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
963 *bp++ = 0; /* owner */
964 *bp++ = 0; /* group */
965 *bp++ = htonl(S_IRWXUGO); /* unix mode */
966 *bp++ = 0; /* segment size */
968 afs_use_fs_server(call, fc->cbi);
969 trace_afs_make_fs_call1(call, &dvnode->fid, name);
970 afs_set_fc_call(call, fc);
971 afs_make_call(&fc->ac, call, GFP_NOFS);
972 return afs_wait_for_call_to_complete(call, &fc->ac);
976 * deliver reply data to an FS.Rename
978 static int afs_deliver_fs_rename(struct afs_call *call)
983 ret = afs_transfer_reply(call);
987 /* unmarshall the reply once we've received all of it */
989 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
992 if (call->out_dir_scb != call->out_scb) {
993 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
997 xdr_decode_AFSVolSync(&bp, call->out_volsync);
999 _leave(" = 0 [done]");
1004 * FS.Rename operation type
1006 static const struct afs_call_type afs_RXFSRename = {
1007 .name = "FS.Rename",
1008 .op = afs_FS_Rename,
1009 .deliver = afs_deliver_fs_rename,
1010 .destructor = afs_flat_call_destructor,
1014 * Rename/move a file or directory.
1016 int afs_fs_rename(struct afs_fs_cursor *fc,
1017 const char *orig_name,
1018 struct afs_vnode *new_dvnode,
1019 const char *new_name,
1020 struct afs_status_cb *orig_dvnode_scb,
1021 struct afs_status_cb *new_dvnode_scb)
1023 struct afs_vnode *orig_dvnode = fc->vnode;
1024 struct afs_call *call;
1025 struct afs_net *net = afs_v2net(orig_dvnode);
1026 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1029 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1030 return yfs_fs_rename(fc, orig_name,
1031 new_dvnode, new_name,
1037 o_namesz = strlen(orig_name);
1038 o_padsz = (4 - (o_namesz & 3)) & 3;
1040 n_namesz = strlen(new_name);
1041 n_padsz = (4 - (n_namesz & 3)) & 3;
1044 4 + o_namesz + o_padsz +
1046 4 + n_namesz + n_padsz;
1048 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1052 call->key = fc->key;
1053 call->out_dir_scb = orig_dvnode_scb;
1054 call->out_scb = new_dvnode_scb;
1056 /* marshall the parameters */
1058 *bp++ = htonl(FSRENAME);
1059 *bp++ = htonl(orig_dvnode->fid.vid);
1060 *bp++ = htonl(orig_dvnode->fid.vnode);
1061 *bp++ = htonl(orig_dvnode->fid.unique);
1062 *bp++ = htonl(o_namesz);
1063 memcpy(bp, orig_name, o_namesz);
1064 bp = (void *) bp + o_namesz;
1066 memset(bp, 0, o_padsz);
1067 bp = (void *) bp + o_padsz;
1070 *bp++ = htonl(new_dvnode->fid.vid);
1071 *bp++ = htonl(new_dvnode->fid.vnode);
1072 *bp++ = htonl(new_dvnode->fid.unique);
1073 *bp++ = htonl(n_namesz);
1074 memcpy(bp, new_name, n_namesz);
1075 bp = (void *) bp + n_namesz;
1077 memset(bp, 0, n_padsz);
1078 bp = (void *) bp + n_padsz;
1081 afs_use_fs_server(call, fc->cbi);
1082 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1083 afs_set_fc_call(call, fc);
1084 afs_make_call(&fc->ac, call, GFP_NOFS);
1085 return afs_wait_for_call_to_complete(call, &fc->ac);
1089 * deliver reply data to an FS.StoreData
1091 static int afs_deliver_fs_store_data(struct afs_call *call)
1098 ret = afs_transfer_reply(call);
1102 /* unmarshall the reply once we've received all of it */
1104 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1107 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1109 _leave(" = 0 [done]");
1114 * FS.StoreData operation type
1116 static const struct afs_call_type afs_RXFSStoreData = {
1117 .name = "FS.StoreData",
1118 .op = afs_FS_StoreData,
1119 .deliver = afs_deliver_fs_store_data,
1120 .destructor = afs_flat_call_destructor,
1123 static const struct afs_call_type afs_RXFSStoreData64 = {
1124 .name = "FS.StoreData64",
1125 .op = afs_FS_StoreData64,
1126 .deliver = afs_deliver_fs_store_data,
1127 .destructor = afs_flat_call_destructor,
1131 * store a set of pages to a very large file
1133 static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1134 struct address_space *mapping,
1135 pgoff_t first, pgoff_t last,
1136 unsigned offset, unsigned to,
1137 loff_t size, loff_t pos, loff_t i_size,
1138 struct afs_status_cb *scb)
1140 struct afs_vnode *vnode = fc->vnode;
1141 struct afs_call *call;
1142 struct afs_net *net = afs_v2net(vnode);
1145 _enter(",%x,{%llx:%llu},,",
1146 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1148 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
1149 (4 + 6 + 3 * 2) * 4,
1154 call->key = fc->key;
1155 call->mapping = mapping;
1156 call->first = first;
1158 call->first_offset = offset;
1160 call->send_pages = true;
1161 call->out_scb = scb;
1163 /* marshall the parameters */
1165 *bp++ = htonl(FSSTOREDATA64);
1166 *bp++ = htonl(vnode->fid.vid);
1167 *bp++ = htonl(vnode->fid.vnode);
1168 *bp++ = htonl(vnode->fid.unique);
1170 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1171 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1172 *bp++ = 0; /* owner */
1173 *bp++ = 0; /* group */
1174 *bp++ = 0; /* unix mode */
1175 *bp++ = 0; /* segment size */
1177 *bp++ = htonl(pos >> 32);
1178 *bp++ = htonl((u32) pos);
1179 *bp++ = htonl(size >> 32);
1180 *bp++ = htonl((u32) size);
1181 *bp++ = htonl(i_size >> 32);
1182 *bp++ = htonl((u32) i_size);
1184 trace_afs_make_fs_call(call, &vnode->fid);
1185 afs_set_fc_call(call, fc);
1186 afs_make_call(&fc->ac, call, GFP_NOFS);
1187 return afs_wait_for_call_to_complete(call, &fc->ac);
1191 * store a set of pages
1193 int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1194 pgoff_t first, pgoff_t last,
1195 unsigned offset, unsigned to,
1196 struct afs_status_cb *scb)
1198 struct afs_vnode *vnode = fc->vnode;
1199 struct afs_call *call;
1200 struct afs_net *net = afs_v2net(vnode);
1201 loff_t size, pos, i_size;
1204 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1205 return yfs_fs_store_data(fc, mapping, first, last, offset, to, scb);
1207 _enter(",%x,{%llx:%llu},,",
1208 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1210 size = (loff_t)to - (loff_t)offset;
1212 size += (loff_t)(last - first) << PAGE_SHIFT;
1213 pos = (loff_t)first << PAGE_SHIFT;
1216 i_size = i_size_read(&vnode->vfs_inode);
1217 if (pos + size > i_size)
1218 i_size = size + pos;
1220 _debug("size %llx, at %llx, i_size %llx",
1221 (unsigned long long) size, (unsigned long long) pos,
1222 (unsigned long long) i_size);
1224 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1225 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
1226 size, pos, i_size, scb);
1228 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1234 call->key = fc->key;
1235 call->mapping = mapping;
1236 call->first = first;
1238 call->first_offset = offset;
1240 call->send_pages = true;
1241 call->out_scb = scb;
1243 /* marshall the parameters */
1245 *bp++ = htonl(FSSTOREDATA);
1246 *bp++ = htonl(vnode->fid.vid);
1247 *bp++ = htonl(vnode->fid.vnode);
1248 *bp++ = htonl(vnode->fid.unique);
1250 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1251 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1252 *bp++ = 0; /* owner */
1253 *bp++ = 0; /* group */
1254 *bp++ = 0; /* unix mode */
1255 *bp++ = 0; /* segment size */
1258 *bp++ = htonl(size);
1259 *bp++ = htonl(i_size);
1261 afs_use_fs_server(call, fc->cbi);
1262 trace_afs_make_fs_call(call, &vnode->fid);
1263 afs_set_fc_call(call, fc);
1264 afs_make_call(&fc->ac, call, GFP_NOFS);
1265 return afs_wait_for_call_to_complete(call, &fc->ac);
1269 * deliver reply data to an FS.StoreStatus
1271 static int afs_deliver_fs_store_status(struct afs_call *call)
1278 ret = afs_transfer_reply(call);
1282 /* unmarshall the reply once we've received all of it */
1284 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1287 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1289 _leave(" = 0 [done]");
1294 * FS.StoreStatus operation type
1296 static const struct afs_call_type afs_RXFSStoreStatus = {
1297 .name = "FS.StoreStatus",
1298 .op = afs_FS_StoreStatus,
1299 .deliver = afs_deliver_fs_store_status,
1300 .destructor = afs_flat_call_destructor,
1303 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1304 .name = "FS.StoreData",
1305 .op = afs_FS_StoreData,
1306 .deliver = afs_deliver_fs_store_status,
1307 .destructor = afs_flat_call_destructor,
1310 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1311 .name = "FS.StoreData64",
1312 .op = afs_FS_StoreData64,
1313 .deliver = afs_deliver_fs_store_status,
1314 .destructor = afs_flat_call_destructor,
1318 * set the attributes on a very large file, using FS.StoreData rather than
1319 * FS.StoreStatus so as to alter the file size also
1321 static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr,
1322 struct afs_status_cb *scb)
1324 struct afs_vnode *vnode = fc->vnode;
1325 struct afs_call *call;
1326 struct afs_net *net = afs_v2net(vnode);
1329 _enter(",%x,{%llx:%llu},,",
1330 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1332 ASSERT(attr->ia_valid & ATTR_SIZE);
1334 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
1335 (4 + 6 + 3 * 2) * 4,
1340 call->key = fc->key;
1341 call->out_scb = scb;
1343 /* marshall the parameters */
1345 *bp++ = htonl(FSSTOREDATA64);
1346 *bp++ = htonl(vnode->fid.vid);
1347 *bp++ = htonl(vnode->fid.vnode);
1348 *bp++ = htonl(vnode->fid.unique);
1350 xdr_encode_AFS_StoreStatus(&bp, attr);
1352 *bp++ = htonl(attr->ia_size >> 32); /* position of start of write */
1353 *bp++ = htonl((u32) attr->ia_size);
1354 *bp++ = 0; /* size of write */
1356 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1357 *bp++ = htonl((u32) attr->ia_size);
1359 afs_use_fs_server(call, fc->cbi);
1360 trace_afs_make_fs_call(call, &vnode->fid);
1361 afs_set_fc_call(call, fc);
1362 afs_make_call(&fc->ac, call, GFP_NOFS);
1363 return afs_wait_for_call_to_complete(call, &fc->ac);
1367 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1368 * so as to alter the file size also
1370 static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr,
1371 struct afs_status_cb *scb)
1373 struct afs_vnode *vnode = fc->vnode;
1374 struct afs_call *call;
1375 struct afs_net *net = afs_v2net(vnode);
1378 _enter(",%x,{%llx:%llu},,",
1379 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1381 ASSERT(attr->ia_valid & ATTR_SIZE);
1382 if (attr->ia_size >> 32)
1383 return afs_fs_setattr_size64(fc, attr, scb);
1385 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1391 call->key = fc->key;
1392 call->out_scb = scb;
1394 /* marshall the parameters */
1396 *bp++ = htonl(FSSTOREDATA);
1397 *bp++ = htonl(vnode->fid.vid);
1398 *bp++ = htonl(vnode->fid.vnode);
1399 *bp++ = htonl(vnode->fid.unique);
1401 xdr_encode_AFS_StoreStatus(&bp, attr);
1403 *bp++ = htonl(attr->ia_size); /* position of start of write */
1404 *bp++ = 0; /* size of write */
1405 *bp++ = htonl(attr->ia_size); /* new file length */
1407 afs_use_fs_server(call, fc->cbi);
1408 trace_afs_make_fs_call(call, &vnode->fid);
1409 afs_set_fc_call(call, fc);
1410 afs_make_call(&fc->ac, call, GFP_NOFS);
1411 return afs_wait_for_call_to_complete(call, &fc->ac);
1415 * set the attributes on a file, using FS.StoreData if there's a change in file
1416 * size, and FS.StoreStatus otherwise
1418 int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr,
1419 struct afs_status_cb *scb)
1421 struct afs_vnode *vnode = fc->vnode;
1422 struct afs_call *call;
1423 struct afs_net *net = afs_v2net(vnode);
1426 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1427 return yfs_fs_setattr(fc, attr, scb);
1429 if (attr->ia_valid & ATTR_SIZE)
1430 return afs_fs_setattr_size(fc, attr, scb);
1432 _enter(",%x,{%llx:%llu},,",
1433 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1435 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1441 call->key = fc->key;
1442 call->out_scb = scb;
1444 /* marshall the parameters */
1446 *bp++ = htonl(FSSTORESTATUS);
1447 *bp++ = htonl(vnode->fid.vid);
1448 *bp++ = htonl(vnode->fid.vnode);
1449 *bp++ = htonl(vnode->fid.unique);
1451 xdr_encode_AFS_StoreStatus(&bp, attr);
1453 afs_use_fs_server(call, fc->cbi);
1454 trace_afs_make_fs_call(call, &vnode->fid);
1455 afs_set_fc_call(call, fc);
1456 afs_make_call(&fc->ac, call, GFP_NOFS);
1457 return afs_wait_for_call_to_complete(call, &fc->ac);
1461 * deliver reply data to an FS.GetVolumeStatus
1463 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1470 _enter("{%u}", call->unmarshall);
1472 switch (call->unmarshall) {
1475 afs_extract_to_buf(call, 12 * 4);
1477 /* Fall through - and extract the returned status record */
1479 _debug("extract status");
1480 ret = afs_extract_data(call, true);
1485 xdr_decode_AFSFetchVolumeStatus(&bp, call->out_volstatus);
1487 afs_extract_to_tmp(call);
1489 /* Fall through - and extract the volume name length */
1491 ret = afs_extract_data(call, true);
1495 call->count = ntohl(call->tmp);
1496 _debug("volname length: %u", call->count);
1497 if (call->count >= AFSNAMEMAX)
1498 return afs_protocol_error(call, -EBADMSG,
1499 afs_eproto_volname_len);
1500 size = (call->count + 3) & ~3; /* It's padded */
1501 afs_extract_to_buf(call, size);
1504 /* Fall through - and extract the volume name */
1506 _debug("extract volname");
1507 ret = afs_extract_data(call, true);
1513 _debug("volname '%s'", p);
1514 afs_extract_to_tmp(call);
1517 /* Fall through - and extract the offline message length */
1519 ret = afs_extract_data(call, true);
1523 call->count = ntohl(call->tmp);
1524 _debug("offline msg length: %u", call->count);
1525 if (call->count >= AFSNAMEMAX)
1526 return afs_protocol_error(call, -EBADMSG,
1527 afs_eproto_offline_msg_len);
1528 size = (call->count + 3) & ~3; /* It's padded */
1529 afs_extract_to_buf(call, size);
1532 /* Fall through - and extract the offline message */
1534 _debug("extract offline");
1535 ret = afs_extract_data(call, true);
1541 _debug("offline '%s'", p);
1543 afs_extract_to_tmp(call);
1546 /* Fall through - and extract the message of the day length */
1548 ret = afs_extract_data(call, true);
1552 call->count = ntohl(call->tmp);
1553 _debug("motd length: %u", call->count);
1554 if (call->count >= AFSNAMEMAX)
1555 return afs_protocol_error(call, -EBADMSG,
1556 afs_eproto_motd_len);
1557 size = (call->count + 3) & ~3; /* It's padded */
1558 afs_extract_to_buf(call, size);
1561 /* Fall through - and extract the message of the day */
1563 _debug("extract motd");
1564 ret = afs_extract_data(call, false);
1570 _debug("motd '%s'", p);
1578 _leave(" = 0 [done]");
1583 * FS.GetVolumeStatus operation type
1585 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1586 .name = "FS.GetVolumeStatus",
1587 .op = afs_FS_GetVolumeStatus,
1588 .deliver = afs_deliver_fs_get_volume_status,
1589 .destructor = afs_flat_call_destructor,
1593 * fetch the status of a volume
1595 int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1596 struct afs_volume_status *vs)
1598 struct afs_vnode *vnode = fc->vnode;
1599 struct afs_call *call;
1600 struct afs_net *net = afs_v2net(vnode);
1603 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1604 return yfs_fs_get_volume_status(fc, vs);
1608 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4,
1609 max(12 * 4, AFSOPAQUEMAX + 1));
1613 call->key = fc->key;
1614 call->out_volstatus = vs;
1616 /* marshall the parameters */
1618 bp[0] = htonl(FSGETVOLUMESTATUS);
1619 bp[1] = htonl(vnode->fid.vid);
1621 afs_use_fs_server(call, fc->cbi);
1622 trace_afs_make_fs_call(call, &vnode->fid);
1623 afs_set_fc_call(call, fc);
1624 afs_make_call(&fc->ac, call, GFP_NOFS);
1625 return afs_wait_for_call_to_complete(call, &fc->ac);
1629 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1631 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1636 _enter("{%u}", call->unmarshall);
1638 ret = afs_transfer_reply(call);
1642 /* unmarshall the reply once we've received all of it */
1644 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1646 _leave(" = 0 [done]");
1651 * FS.SetLock operation type
1653 static const struct afs_call_type afs_RXFSSetLock = {
1654 .name = "FS.SetLock",
1655 .op = afs_FS_SetLock,
1656 .deliver = afs_deliver_fs_xxxx_lock,
1657 .done = afs_lock_op_done,
1658 .destructor = afs_flat_call_destructor,
1662 * FS.ExtendLock operation type
1664 static const struct afs_call_type afs_RXFSExtendLock = {
1665 .name = "FS.ExtendLock",
1666 .op = afs_FS_ExtendLock,
1667 .deliver = afs_deliver_fs_xxxx_lock,
1668 .done = afs_lock_op_done,
1669 .destructor = afs_flat_call_destructor,
1673 * FS.ReleaseLock operation type
1675 static const struct afs_call_type afs_RXFSReleaseLock = {
1676 .name = "FS.ReleaseLock",
1677 .op = afs_FS_ReleaseLock,
1678 .deliver = afs_deliver_fs_xxxx_lock,
1679 .destructor = afs_flat_call_destructor,
1683 * Set a lock on a file
1685 int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type,
1686 struct afs_status_cb *scb)
1688 struct afs_vnode *vnode = fc->vnode;
1689 struct afs_call *call;
1690 struct afs_net *net = afs_v2net(vnode);
1693 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1694 return yfs_fs_set_lock(fc, type, scb);
1698 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1702 call->key = fc->key;
1703 call->lvnode = vnode;
1704 call->out_scb = scb;
1706 /* marshall the parameters */
1708 *bp++ = htonl(FSSETLOCK);
1709 *bp++ = htonl(vnode->fid.vid);
1710 *bp++ = htonl(vnode->fid.vnode);
1711 *bp++ = htonl(vnode->fid.unique);
1712 *bp++ = htonl(type);
1714 afs_use_fs_server(call, fc->cbi);
1715 trace_afs_make_fs_calli(call, &vnode->fid, type);
1716 afs_set_fc_call(call, fc);
1717 afs_make_call(&fc->ac, call, GFP_NOFS);
1718 return afs_wait_for_call_to_complete(call, &fc->ac);
1722 * extend a lock on a file
1724 int afs_fs_extend_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
1726 struct afs_vnode *vnode = fc->vnode;
1727 struct afs_call *call;
1728 struct afs_net *net = afs_v2net(vnode);
1731 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1732 return yfs_fs_extend_lock(fc, scb);
1736 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1740 call->key = fc->key;
1741 call->lvnode = vnode;
1742 call->out_scb = scb;
1744 /* marshall the parameters */
1746 *bp++ = htonl(FSEXTENDLOCK);
1747 *bp++ = htonl(vnode->fid.vid);
1748 *bp++ = htonl(vnode->fid.vnode);
1749 *bp++ = htonl(vnode->fid.unique);
1751 afs_use_fs_server(call, fc->cbi);
1752 trace_afs_make_fs_call(call, &vnode->fid);
1753 afs_set_fc_call(call, fc);
1754 afs_make_call(&fc->ac, call, GFP_NOFS);
1755 return afs_wait_for_call_to_complete(call, &fc->ac);
1759 * release a lock on a file
1761 int afs_fs_release_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
1763 struct afs_vnode *vnode = fc->vnode;
1764 struct afs_call *call;
1765 struct afs_net *net = afs_v2net(vnode);
1768 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1769 return yfs_fs_release_lock(fc, scb);
1773 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1777 call->key = fc->key;
1778 call->lvnode = vnode;
1779 call->out_scb = scb;
1781 /* marshall the parameters */
1783 *bp++ = htonl(FSRELEASELOCK);
1784 *bp++ = htonl(vnode->fid.vid);
1785 *bp++ = htonl(vnode->fid.vnode);
1786 *bp++ = htonl(vnode->fid.unique);
1788 afs_use_fs_server(call, fc->cbi);
1789 trace_afs_make_fs_call(call, &vnode->fid);
1790 afs_set_fc_call(call, fc);
1791 afs_make_call(&fc->ac, call, GFP_NOFS);
1792 return afs_wait_for_call_to_complete(call, &fc->ac);
1796 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1798 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1800 return afs_transfer_reply(call);
1804 * FS.GiveUpAllCallBacks operation type
1806 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1807 .name = "FS.GiveUpAllCallBacks",
1808 .op = afs_FS_GiveUpAllCallBacks,
1809 .deliver = afs_deliver_fs_give_up_all_callbacks,
1810 .destructor = afs_flat_call_destructor,
1814 * Flush all the callbacks we have on a server.
1816 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1817 struct afs_server *server,
1818 struct afs_addr_cursor *ac,
1821 struct afs_call *call;
1826 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1832 /* marshall the parameters */
1834 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1836 /* Can't take a ref on server */
1837 afs_make_call(ac, call, GFP_NOFS);
1838 return afs_wait_for_call_to_complete(call, ac);
1842 * Deliver reply data to an FS.GetCapabilities operation.
1844 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1849 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
1851 switch (call->unmarshall) {
1853 afs_extract_to_tmp(call);
1856 /* Fall through - and extract the capabilities word count */
1858 ret = afs_extract_data(call, true);
1862 count = ntohl(call->tmp);
1864 call->count = count;
1865 call->count2 = count;
1866 iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
1869 /* Fall through - and extract capabilities words */
1871 ret = afs_extract_data(call, false);
1875 /* TODO: Examine capabilities */
1881 _leave(" = 0 [done]");
1886 * FS.GetCapabilities operation type
1888 static const struct afs_call_type afs_RXFSGetCapabilities = {
1889 .name = "FS.GetCapabilities",
1890 .op = afs_FS_GetCapabilities,
1891 .deliver = afs_deliver_fs_get_capabilities,
1892 .done = afs_fileserver_probe_result,
1893 .destructor = afs_flat_call_destructor,
1897 * Probe a fileserver for the capabilities that it supports. This can
1898 * return up to 196 words.
1900 struct afs_call *afs_fs_get_capabilities(struct afs_net *net,
1901 struct afs_server *server,
1902 struct afs_addr_cursor *ac,
1904 unsigned int server_index)
1906 struct afs_call *call;
1911 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1913 return ERR_PTR(-ENOMEM);
1916 call->server = afs_get_server(server);
1917 call->server_index = server_index;
1918 call->upgrade = true;
1920 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
1922 /* marshall the parameters */
1924 *bp++ = htonl(FSGETCAPABILITIES);
1926 /* Can't take a ref on server */
1927 trace_afs_make_fs_call(call, NULL);
1928 afs_make_call(ac, call, GFP_NOFS);
1933 * Deliver reply data to an FS.FetchStatus with no vnode.
1935 static int afs_deliver_fs_fetch_status(struct afs_call *call)
1940 ret = afs_transfer_reply(call);
1944 /* unmarshall the reply once we've received all of it */
1946 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1949 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
1950 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1952 _leave(" = 0 [done]");
1957 * FS.FetchStatus operation type
1959 static const struct afs_call_type afs_RXFSFetchStatus = {
1960 .name = "FS.FetchStatus",
1961 .op = afs_FS_FetchStatus,
1962 .deliver = afs_deliver_fs_fetch_status,
1963 .destructor = afs_flat_call_destructor,
1967 * Fetch the status information for a fid without needing a vnode handle.
1969 int afs_fs_fetch_status(struct afs_fs_cursor *fc,
1970 struct afs_net *net,
1971 struct afs_fid *fid,
1972 struct afs_status_cb *scb,
1973 struct afs_volsync *volsync)
1975 struct afs_call *call;
1978 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1979 return yfs_fs_fetch_status(fc, net, fid, scb, volsync);
1981 _enter(",%x,{%llx:%llu},,",
1982 key_serial(fc->key), fid->vid, fid->vnode);
1984 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
1986 fc->ac.error = -ENOMEM;
1990 call->key = fc->key;
1991 call->out_fid = fid;
1992 call->out_scb = scb;
1993 call->out_volsync = volsync;
1995 /* marshall the parameters */
1997 bp[0] = htonl(FSFETCHSTATUS);
1998 bp[1] = htonl(fid->vid);
1999 bp[2] = htonl(fid->vnode);
2000 bp[3] = htonl(fid->unique);
2002 afs_use_fs_server(call, fc->cbi);
2003 trace_afs_make_fs_call(call, fid);
2004 afs_set_fc_call(call, fc);
2005 afs_make_call(&fc->ac, call, GFP_NOFS);
2006 return afs_wait_for_call_to_complete(call, &fc->ac);
2010 * Deliver reply data to an FS.InlineBulkStatus call
2012 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2014 struct afs_status_cb *scb;
2019 _enter("{%u}", call->unmarshall);
2021 switch (call->unmarshall) {
2023 afs_extract_to_tmp(call);
2026 /* Extract the file status count and array in two steps */
2029 _debug("extract status count");
2030 ret = afs_extract_data(call, true);
2034 tmp = ntohl(call->tmp);
2035 _debug("status count: %u/%u", tmp, call->count2);
2036 if (tmp != call->count2)
2037 return afs_protocol_error(call, -EBADMSG,
2038 afs_eproto_ibulkst_count);
2043 afs_extract_to_buf(call, 21 * sizeof(__be32));
2047 _debug("extract status array %u", call->count);
2048 ret = afs_extract_data(call, true);
2053 scb = &call->out_scb[call->count];
2054 ret = xdr_decode_AFSFetchStatus(&bp, call, scb);
2059 if (call->count < call->count2)
2064 afs_extract_to_tmp(call);
2066 /* Extract the callback count and array in two steps */
2069 _debug("extract CB count");
2070 ret = afs_extract_data(call, true);
2074 tmp = ntohl(call->tmp);
2075 _debug("CB count: %u", tmp);
2076 if (tmp != call->count2)
2077 return afs_protocol_error(call, -EBADMSG,
2078 afs_eproto_ibulkst_cb_count);
2082 afs_extract_to_buf(call, 3 * sizeof(__be32));
2086 _debug("extract CB array");
2087 ret = afs_extract_data(call, true);
2091 _debug("unmarshall CB array");
2093 scb = &call->out_scb[call->count];
2094 xdr_decode_AFSCallBack(&bp, call, scb);
2096 if (call->count < call->count2)
2099 afs_extract_to_buf(call, 6 * sizeof(__be32));
2104 ret = afs_extract_data(call, false);
2109 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2117 _leave(" = 0 [done]");
2122 * FS.InlineBulkStatus operation type
2124 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2125 .name = "FS.InlineBulkStatus",
2126 .op = afs_FS_InlineBulkStatus,
2127 .deliver = afs_deliver_fs_inline_bulk_status,
2128 .destructor = afs_flat_call_destructor,
2132 * Fetch the status information for up to 50 files
2134 int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2135 struct afs_net *net,
2136 struct afs_fid *fids,
2137 struct afs_status_cb *statuses,
2138 unsigned int nr_fids,
2139 struct afs_volsync *volsync)
2141 struct afs_call *call;
2145 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2146 return yfs_fs_inline_bulk_status(fc, net, fids, statuses,
2149 _enter(",%x,{%llx:%llu},%u",
2150 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2152 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2153 (2 + nr_fids * 3) * 4,
2156 fc->ac.error = -ENOMEM;
2160 call->key = fc->key;
2161 call->out_scb = statuses;
2162 call->out_volsync = volsync;
2163 call->count2 = nr_fids;
2165 /* marshall the parameters */
2167 *bp++ = htonl(FSINLINEBULKSTATUS);
2168 *bp++ = htonl(nr_fids);
2169 for (i = 0; i < nr_fids; i++) {
2170 *bp++ = htonl(fids[i].vid);
2171 *bp++ = htonl(fids[i].vnode);
2172 *bp++ = htonl(fids[i].unique);
2175 afs_use_fs_server(call, fc->cbi);
2176 trace_afs_make_fs_call(call, &fids[0]);
2177 afs_set_fc_call(call, fc);
2178 afs_make_call(&fc->ac, call, GFP_NOFS);
2179 return afs_wait_for_call_to_complete(call, &fc->ac);
2183 * deliver reply data to an FS.FetchACL
2185 static int afs_deliver_fs_fetch_acl(struct afs_call *call)
2187 struct afs_acl *acl;
2192 _enter("{%u}", call->unmarshall);
2194 switch (call->unmarshall) {
2196 afs_extract_to_tmp(call);
2199 /* extract the returned data length */
2201 ret = afs_extract_data(call, true);
2205 size = call->count2 = ntohl(call->tmp);
2206 size = round_up(size, 4);
2208 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2211 call->ret_acl = acl;
2212 acl->size = call->count2;
2213 afs_extract_begin(call, acl->data, size);
2216 /* extract the returned data */
2218 ret = afs_extract_data(call, true);
2222 afs_extract_to_buf(call, (21 + 6) * 4);
2225 /* extract the metadata */
2227 ret = afs_extract_data(call, false);
2232 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
2235 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2243 _leave(" = 0 [done]");
2247 static void afs_destroy_fs_fetch_acl(struct afs_call *call)
2249 kfree(call->ret_acl);
2250 afs_flat_call_destructor(call);
2254 * FS.FetchACL operation type
2256 static const struct afs_call_type afs_RXFSFetchACL = {
2257 .name = "FS.FetchACL",
2258 .op = afs_FS_FetchACL,
2259 .deliver = afs_deliver_fs_fetch_acl,
2260 .destructor = afs_destroy_fs_fetch_acl,
2264 * Fetch the ACL for a file.
2266 struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc,
2267 struct afs_status_cb *scb)
2269 struct afs_vnode *vnode = fc->vnode;
2270 struct afs_call *call;
2271 struct afs_net *net = afs_v2net(vnode);
2274 _enter(",%x,{%llx:%llu},,",
2275 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2277 call = afs_alloc_flat_call(net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2279 fc->ac.error = -ENOMEM;
2280 return ERR_PTR(-ENOMEM);
2283 call->key = fc->key;
2284 call->ret_acl = NULL;
2285 call->out_scb = scb;
2286 call->out_volsync = NULL;
2288 /* marshall the parameters */
2290 bp[0] = htonl(FSFETCHACL);
2291 bp[1] = htonl(vnode->fid.vid);
2292 bp[2] = htonl(vnode->fid.vnode);
2293 bp[3] = htonl(vnode->fid.unique);
2295 afs_use_fs_server(call, fc->cbi);
2296 trace_afs_make_fs_call(call, &vnode->fid);
2297 afs_make_call(&fc->ac, call, GFP_KERNEL);
2298 return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2302 * Deliver reply data to any operation that returns file status and volume
2305 static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
2310 ret = afs_transfer_reply(call);
2315 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
2318 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2320 _leave(" = 0 [done]");
2325 * FS.StoreACL operation type
2327 static const struct afs_call_type afs_RXFSStoreACL = {
2328 .name = "FS.StoreACL",
2329 .op = afs_FS_StoreACL,
2330 .deliver = afs_deliver_fs_file_status_and_vol,
2331 .destructor = afs_flat_call_destructor,
2335 * Fetch the ACL for a file.
2337 int afs_fs_store_acl(struct afs_fs_cursor *fc, const struct afs_acl *acl,
2338 struct afs_status_cb *scb)
2340 struct afs_vnode *vnode = fc->vnode;
2341 struct afs_call *call;
2342 struct afs_net *net = afs_v2net(vnode);
2346 _enter(",%x,{%llx:%llu},,",
2347 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2349 size = round_up(acl->size, 4);
2350 call = afs_alloc_flat_call(net, &afs_RXFSStoreACL,
2351 5 * 4 + size, (21 + 6) * 4);
2353 fc->ac.error = -ENOMEM;
2357 call->key = fc->key;
2358 call->out_scb = scb;
2359 call->out_volsync = NULL;
2361 /* marshall the parameters */
2363 bp[0] = htonl(FSSTOREACL);
2364 bp[1] = htonl(vnode->fid.vid);
2365 bp[2] = htonl(vnode->fid.vnode);
2366 bp[3] = htonl(vnode->fid.unique);
2367 bp[4] = htonl(acl->size);
2368 memcpy(&bp[5], acl->data, acl->size);
2369 if (acl->size != size)
2370 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2372 trace_afs_make_fs_call(call, &vnode->fid);
2373 afs_make_call(&fc->ac, call, GFP_KERNEL);
2374 return afs_wait_for_call_to_complete(call, &fc->ac);