1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* AFS File Server client stubs
4 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #include <linux/init.h>
9 #include <linux/slab.h>
10 #include <linux/sched.h>
11 #include <linux/circ_buf.h>
12 #include <linux/iversion.h>
16 #include "protocol_yfs.h"
18 static const struct afs_fid afs_zero_fid;
20 static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
22 call->cbi = afs_get_cb_interest(cbi);
26 * decode an AFSFid block
28 static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
30 const __be32 *bp = *_bp;
32 fid->vid = ntohl(*bp++);
33 fid->vnode = ntohl(*bp++);
34 fid->unique = ntohl(*bp++);
39 * Dump a bad file status record.
41 static void xdr_dump_bad(const __be32 *bp)
46 pr_notice("AFS XDR: Bad status record\n");
47 for (i = 0; i < 5 * 4 * 4; i += 16) {
50 pr_notice("%03x: %08x %08x %08x %08x\n",
51 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
55 pr_notice("0x50: %08x\n", ntohl(x[0]));
59 * decode an AFSFetchStatus block
61 static int xdr_decode_AFSFetchStatus(const __be32 **_bp,
62 struct afs_call *call,
63 struct afs_status_cb *scb)
65 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
66 struct afs_file_status *status = &scb->status;
67 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
68 u64 data_version, size;
71 abort_code = ntohl(xdr->abort_code);
73 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
74 if (xdr->if_version == htonl(0) &&
77 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
78 * whereby it doesn't set the interface version in the error
81 status->abort_code = abort_code;
82 scb->have_error = true;
86 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
90 if (abort_code != 0 && inline_error) {
91 status->abort_code = abort_code;
95 type = ntohl(xdr->type);
99 case AFS_FTYPE_SYMLINK:
106 status->nlink = ntohl(xdr->nlink);
107 status->author = ntohl(xdr->author);
108 status->owner = ntohl(xdr->owner);
109 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
110 status->anon_access = ntohl(xdr->anon_access);
111 status->mode = ntohl(xdr->mode) & S_IALLUGO;
112 status->group = ntohl(xdr->group);
113 status->lock_count = ntohl(xdr->lock_count);
115 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
116 status->mtime_client.tv_nsec = 0;
117 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
118 status->mtime_server.tv_nsec = 0;
120 size = (u64)ntohl(xdr->size_lo);
121 size |= (u64)ntohl(xdr->size_hi) << 32;
124 data_version = (u64)ntohl(xdr->data_version_lo);
125 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
126 status->data_version = data_version;
127 scb->have_status = true;
129 *_bp = (const void *)*_bp + sizeof(*xdr);
134 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
137 static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
139 return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
142 static void xdr_decode_AFSCallBack(const __be32 **_bp,
143 struct afs_call *call,
144 struct afs_status_cb *scb)
146 struct afs_callback *cb = &scb->callback;
147 const __be32 *bp = *_bp;
150 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
157 * decode an AFSVolSync block
159 static void xdr_decode_AFSVolSync(const __be32 **_bp,
160 struct afs_volsync *volsync)
162 const __be32 *bp = *_bp;
165 creation = ntohl(*bp++);
174 volsync->creation = creation;
178 * encode the requested attributes into an AFSStoreStatus block
180 static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
183 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
186 if (attr->ia_valid & ATTR_MTIME) {
187 mask |= AFS_SET_MTIME;
188 mtime = attr->ia_mtime.tv_sec;
191 if (attr->ia_valid & ATTR_UID) {
192 mask |= AFS_SET_OWNER;
193 owner = from_kuid(&init_user_ns, attr->ia_uid);
196 if (attr->ia_valid & ATTR_GID) {
197 mask |= AFS_SET_GROUP;
198 group = from_kgid(&init_user_ns, attr->ia_gid);
201 if (attr->ia_valid & ATTR_MODE) {
202 mask |= AFS_SET_MODE;
203 mode = attr->ia_mode & S_IALLUGO;
207 *bp++ = htonl(mtime);
208 *bp++ = htonl(owner);
209 *bp++ = htonl(group);
211 *bp++ = 0; /* segment size */
216 * decode an AFSFetchVolumeStatus block
218 static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
219 struct afs_volume_status *vs)
221 const __be32 *bp = *_bp;
223 vs->vid = ntohl(*bp++);
224 vs->parent_id = ntohl(*bp++);
225 vs->online = ntohl(*bp++);
226 vs->in_service = ntohl(*bp++);
227 vs->blessed = ntohl(*bp++);
228 vs->needs_salvage = ntohl(*bp++);
229 vs->type = ntohl(*bp++);
230 vs->min_quota = ntohl(*bp++);
231 vs->max_quota = ntohl(*bp++);
232 vs->blocks_in_use = ntohl(*bp++);
233 vs->part_blocks_avail = ntohl(*bp++);
234 vs->part_max_blocks = ntohl(*bp++);
235 vs->vol_copy_date = 0;
236 vs->vol_backup_date = 0;
241 * deliver reply data to an FS.FetchStatus
243 static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
248 ret = afs_transfer_reply(call);
252 /* unmarshall the reply once we've received all of it */
254 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
257 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
258 xdr_decode_AFSVolSync(&bp, call->out_volsync);
260 _leave(" = 0 [done]");
265 * FS.FetchStatus operation type
267 static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
268 .name = "FS.FetchStatus(vnode)",
269 .op = afs_FS_FetchStatus,
270 .deliver = afs_deliver_fs_fetch_status_vnode,
271 .destructor = afs_flat_call_destructor,
275 * fetch the status information for a file
277 int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_status_cb *scb,
278 struct afs_volsync *volsync)
280 struct afs_vnode *vnode = fc->vnode;
281 struct afs_call *call;
282 struct afs_net *net = afs_v2net(vnode);
285 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
286 return yfs_fs_fetch_file_status(fc, scb, volsync);
288 _enter(",%x,{%llx:%llu},,",
289 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
291 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
292 16, (21 + 3 + 6) * 4);
294 fc->ac.error = -ENOMEM;
300 call->out_volsync = volsync;
302 /* marshall the parameters */
304 bp[0] = htonl(FSFETCHSTATUS);
305 bp[1] = htonl(vnode->fid.vid);
306 bp[2] = htonl(vnode->fid.vnode);
307 bp[3] = htonl(vnode->fid.unique);
309 afs_use_fs_server(call, fc->cbi);
310 trace_afs_make_fs_call(call, &vnode->fid);
312 afs_set_fc_call(call, fc);
313 afs_make_call(&fc->ac, call, GFP_NOFS);
314 return afs_wait_for_call_to_complete(call, &fc->ac);
318 * deliver reply data to an FS.FetchData
320 static int afs_deliver_fs_fetch_data(struct afs_call *call)
322 struct afs_read *req = call->read_request;
327 _enter("{%u,%zu/%llu}",
328 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
330 switch (call->unmarshall) {
334 req->offset = req->pos & (PAGE_SIZE - 1);
336 if (call->operation_ID == FSFETCHDATA64) {
337 afs_extract_to_tmp64(call);
339 call->tmp_u = htonl(0);
340 afs_extract_to_tmp(call);
344 /* extract the returned data length */
346 _debug("extract data length");
347 ret = afs_extract_data(call, true);
351 req->actual_len = be64_to_cpu(call->tmp64);
352 _debug("DATA length: %llu", req->actual_len);
353 req->remain = min(req->len, req->actual_len);
354 if (req->remain == 0)
360 ASSERTCMP(req->index, <, req->nr_pages);
361 if (req->remain > PAGE_SIZE - req->offset)
362 size = PAGE_SIZE - req->offset;
365 call->bvec[0].bv_len = size;
366 call->bvec[0].bv_offset = req->offset;
367 call->bvec[0].bv_page = req->pages[req->index];
368 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
369 ASSERTCMP(size, <=, PAGE_SIZE);
372 /* 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);
414 /* extract the metadata */
416 ret = afs_extract_data(call, false);
421 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
424 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
425 xdr_decode_AFSVolSync(&bp, call->out_volsync);
427 req->data_version = call->out_scb->status.data_version;
428 req->file_size = call->out_scb->status.size;
436 for (; req->index < req->nr_pages; req->index++) {
437 if (req->offset < PAGE_SIZE)
438 zero_user_segment(req->pages[req->index],
439 req->offset, PAGE_SIZE);
445 _leave(" = 0 [done]");
449 static void afs_fetch_data_destructor(struct afs_call *call)
451 struct afs_read *req = call->read_request;
454 afs_flat_call_destructor(call);
458 * FS.FetchData operation type
460 static const struct afs_call_type afs_RXFSFetchData = {
461 .name = "FS.FetchData",
462 .op = afs_FS_FetchData,
463 .deliver = afs_deliver_fs_fetch_data,
464 .destructor = afs_fetch_data_destructor,
467 static const struct afs_call_type afs_RXFSFetchData64 = {
468 .name = "FS.FetchData64",
469 .op = afs_FS_FetchData64,
470 .deliver = afs_deliver_fs_fetch_data,
471 .destructor = afs_fetch_data_destructor,
475 * fetch data from a very large file
477 static int afs_fs_fetch_data64(struct afs_fs_cursor *fc,
478 struct afs_status_cb *scb,
479 struct afs_read *req)
481 struct afs_vnode *vnode = fc->vnode;
482 struct afs_call *call;
483 struct afs_net *net = afs_v2net(vnode);
488 call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
494 call->out_volsync = NULL;
495 call->read_request = req;
497 /* marshall the parameters */
499 bp[0] = htonl(FSFETCHDATA64);
500 bp[1] = htonl(vnode->fid.vid);
501 bp[2] = htonl(vnode->fid.vnode);
502 bp[3] = htonl(vnode->fid.unique);
503 bp[4] = htonl(upper_32_bits(req->pos));
504 bp[5] = htonl(lower_32_bits(req->pos));
506 bp[7] = htonl(lower_32_bits(req->len));
508 refcount_inc(&req->usage);
509 afs_use_fs_server(call, fc->cbi);
510 trace_afs_make_fs_call(call, &vnode->fid);
511 afs_set_fc_call(call, fc);
512 afs_make_call(&fc->ac, call, GFP_NOFS);
513 return afs_wait_for_call_to_complete(call, &fc->ac);
517 * fetch data from a file
519 int afs_fs_fetch_data(struct afs_fs_cursor *fc,
520 struct afs_status_cb *scb,
521 struct afs_read *req)
523 struct afs_vnode *vnode = fc->vnode;
524 struct afs_call *call;
525 struct afs_net *net = afs_v2net(vnode);
528 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
529 return yfs_fs_fetch_data(fc, scb, req);
531 if (upper_32_bits(req->pos) ||
532 upper_32_bits(req->len) ||
533 upper_32_bits(req->pos + req->len))
534 return afs_fs_fetch_data64(fc, scb, req);
538 call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
544 call->out_volsync = NULL;
545 call->read_request = req;
547 /* marshall the parameters */
549 bp[0] = htonl(FSFETCHDATA);
550 bp[1] = htonl(vnode->fid.vid);
551 bp[2] = htonl(vnode->fid.vnode);
552 bp[3] = htonl(vnode->fid.unique);
553 bp[4] = htonl(lower_32_bits(req->pos));
554 bp[5] = htonl(lower_32_bits(req->len));
556 refcount_inc(&req->usage);
557 afs_use_fs_server(call, fc->cbi);
558 trace_afs_make_fs_call(call, &vnode->fid);
559 afs_set_fc_call(call, fc);
560 afs_make_call(&fc->ac, call, GFP_NOFS);
561 return afs_wait_for_call_to_complete(call, &fc->ac);
565 * deliver reply data to an FS.CreateFile or an FS.MakeDir
567 static int afs_deliver_fs_create_vnode(struct afs_call *call)
572 ret = afs_transfer_reply(call);
576 /* unmarshall the reply once we've received all of it */
578 xdr_decode_AFSFid(&bp, call->out_fid);
579 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
582 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
585 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
586 xdr_decode_AFSVolSync(&bp, call->out_volsync);
588 _leave(" = 0 [done]");
593 * FS.CreateFile and FS.MakeDir operation type
595 static const struct afs_call_type afs_RXFSCreateFile = {
596 .name = "FS.CreateFile",
597 .op = afs_FS_CreateFile,
598 .deliver = afs_deliver_fs_create_vnode,
599 .destructor = afs_flat_call_destructor,
602 static const struct afs_call_type afs_RXFSMakeDir = {
603 .name = "FS.MakeDir",
604 .op = afs_FS_MakeDir,
605 .deliver = afs_deliver_fs_create_vnode,
606 .destructor = afs_flat_call_destructor,
610 * create a file or make a directory
612 int afs_fs_create(struct afs_fs_cursor *fc,
615 struct afs_status_cb *dvnode_scb,
616 struct afs_fid *newfid,
617 struct afs_status_cb *new_scb)
619 struct afs_vnode *dvnode = fc->vnode;
620 struct afs_call *call;
621 struct afs_net *net = afs_v2net(dvnode);
622 size_t namesz, reqsz, padsz;
625 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
627 return yfs_fs_make_dir(fc, name, mode, dvnode_scb,
630 return yfs_fs_create_file(fc, name, mode, dvnode_scb,
636 namesz = strlen(name);
637 padsz = (4 - (namesz & 3)) & 3;
638 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
640 call = afs_alloc_flat_call(
641 net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
642 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
647 call->out_dir_scb = dvnode_scb;
648 call->out_fid = newfid;
649 call->out_scb = new_scb;
651 /* marshall the parameters */
653 *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
654 *bp++ = htonl(dvnode->fid.vid);
655 *bp++ = htonl(dvnode->fid.vnode);
656 *bp++ = htonl(dvnode->fid.unique);
657 *bp++ = htonl(namesz);
658 memcpy(bp, name, namesz);
659 bp = (void *) bp + namesz;
661 memset(bp, 0, padsz);
662 bp = (void *) bp + padsz;
664 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
665 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
666 *bp++ = 0; /* owner */
667 *bp++ = 0; /* group */
668 *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
669 *bp++ = 0; /* segment size */
671 afs_use_fs_server(call, fc->cbi);
672 trace_afs_make_fs_call1(call, &dvnode->fid, name);
673 afs_set_fc_call(call, fc);
674 afs_make_call(&fc->ac, call, GFP_NOFS);
675 return afs_wait_for_call_to_complete(call, &fc->ac);
679 * Deliver reply data to any operation that returns directory status and volume
682 static int afs_deliver_fs_dir_status_and_vol(struct afs_call *call)
687 ret = afs_transfer_reply(call);
691 /* unmarshall the reply once we've received all of it */
693 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
696 xdr_decode_AFSVolSync(&bp, call->out_volsync);
698 _leave(" = 0 [done]");
703 * FS.RemoveDir/FS.RemoveFile operation type
705 static const struct afs_call_type afs_RXFSRemoveFile = {
706 .name = "FS.RemoveFile",
707 .op = afs_FS_RemoveFile,
708 .deliver = afs_deliver_fs_dir_status_and_vol,
709 .destructor = afs_flat_call_destructor,
712 static const struct afs_call_type afs_RXFSRemoveDir = {
713 .name = "FS.RemoveDir",
714 .op = afs_FS_RemoveDir,
715 .deliver = afs_deliver_fs_dir_status_and_vol,
716 .destructor = afs_flat_call_destructor,
720 * remove a file or directory
722 int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
723 const char *name, bool isdir, struct afs_status_cb *dvnode_scb)
725 struct afs_vnode *dvnode = fc->vnode;
726 struct afs_call *call;
727 struct afs_net *net = afs_v2net(dvnode);
728 size_t namesz, reqsz, padsz;
731 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
732 return yfs_fs_remove(fc, vnode, name, isdir, dvnode_scb);
736 namesz = strlen(name);
737 padsz = (4 - (namesz & 3)) & 3;
738 reqsz = (5 * 4) + namesz + padsz;
740 call = afs_alloc_flat_call(
741 net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
742 reqsz, (21 + 6) * 4);
747 call->out_dir_scb = dvnode_scb;
749 /* marshall the parameters */
751 *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
752 *bp++ = htonl(dvnode->fid.vid);
753 *bp++ = htonl(dvnode->fid.vnode);
754 *bp++ = htonl(dvnode->fid.unique);
755 *bp++ = htonl(namesz);
756 memcpy(bp, name, namesz);
757 bp = (void *) bp + namesz;
759 memset(bp, 0, padsz);
760 bp = (void *) bp + padsz;
763 afs_use_fs_server(call, fc->cbi);
764 trace_afs_make_fs_call1(call, &dvnode->fid, name);
765 afs_set_fc_call(call, fc);
766 afs_make_call(&fc->ac, call, GFP_NOFS);
767 return afs_wait_for_call_to_complete(call, &fc->ac);
771 * deliver reply data to an FS.Link
773 static int afs_deliver_fs_link(struct afs_call *call)
778 _enter("{%u}", call->unmarshall);
780 ret = afs_transfer_reply(call);
784 /* unmarshall the reply once we've received all of it */
786 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
789 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
792 xdr_decode_AFSVolSync(&bp, call->out_volsync);
794 _leave(" = 0 [done]");
799 * FS.Link operation type
801 static const struct afs_call_type afs_RXFSLink = {
804 .deliver = afs_deliver_fs_link,
805 .destructor = afs_flat_call_destructor,
811 int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
813 struct afs_status_cb *dvnode_scb,
814 struct afs_status_cb *vnode_scb)
816 struct afs_vnode *dvnode = fc->vnode;
817 struct afs_call *call;
818 struct afs_net *net = afs_v2net(vnode);
819 size_t namesz, reqsz, padsz;
822 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
823 return yfs_fs_link(fc, vnode, name, dvnode_scb, vnode_scb);
827 namesz = strlen(name);
828 padsz = (4 - (namesz & 3)) & 3;
829 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
831 call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
836 call->out_dir_scb = dvnode_scb;
837 call->out_scb = vnode_scb;
839 /* marshall the parameters */
841 *bp++ = htonl(FSLINK);
842 *bp++ = htonl(dvnode->fid.vid);
843 *bp++ = htonl(dvnode->fid.vnode);
844 *bp++ = htonl(dvnode->fid.unique);
845 *bp++ = htonl(namesz);
846 memcpy(bp, name, namesz);
847 bp = (void *) bp + namesz;
849 memset(bp, 0, padsz);
850 bp = (void *) bp + padsz;
852 *bp++ = htonl(vnode->fid.vid);
853 *bp++ = htonl(vnode->fid.vnode);
854 *bp++ = htonl(vnode->fid.unique);
856 afs_use_fs_server(call, fc->cbi);
857 trace_afs_make_fs_call1(call, &vnode->fid, name);
858 afs_set_fc_call(call, fc);
859 afs_make_call(&fc->ac, call, GFP_NOFS);
860 return afs_wait_for_call_to_complete(call, &fc->ac);
864 * deliver reply data to an FS.Symlink
866 static int afs_deliver_fs_symlink(struct afs_call *call)
871 _enter("{%u}", call->unmarshall);
873 ret = afs_transfer_reply(call);
877 /* unmarshall the reply once we've received all of it */
879 xdr_decode_AFSFid(&bp, call->out_fid);
880 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
883 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
886 xdr_decode_AFSVolSync(&bp, call->out_volsync);
888 _leave(" = 0 [done]");
893 * FS.Symlink operation type
895 static const struct afs_call_type afs_RXFSSymlink = {
896 .name = "FS.Symlink",
897 .op = afs_FS_Symlink,
898 .deliver = afs_deliver_fs_symlink,
899 .destructor = afs_flat_call_destructor,
903 * create a symbolic link
905 int afs_fs_symlink(struct afs_fs_cursor *fc,
907 const char *contents,
908 struct afs_status_cb *dvnode_scb,
909 struct afs_fid *newfid,
910 struct afs_status_cb *new_scb)
912 struct afs_vnode *dvnode = fc->vnode;
913 struct afs_call *call;
914 struct afs_net *net = afs_v2net(dvnode);
915 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
918 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
919 return yfs_fs_symlink(fc, name, contents, dvnode_scb,
924 namesz = strlen(name);
925 padsz = (4 - (namesz & 3)) & 3;
927 c_namesz = strlen(contents);
928 c_padsz = (4 - (c_namesz & 3)) & 3;
930 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
932 call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
933 (3 + 21 + 21 + 6) * 4);
938 call->out_dir_scb = dvnode_scb;
939 call->out_fid = newfid;
940 call->out_scb = new_scb;
942 /* marshall the parameters */
944 *bp++ = htonl(FSSYMLINK);
945 *bp++ = htonl(dvnode->fid.vid);
946 *bp++ = htonl(dvnode->fid.vnode);
947 *bp++ = htonl(dvnode->fid.unique);
948 *bp++ = htonl(namesz);
949 memcpy(bp, name, namesz);
950 bp = (void *) bp + namesz;
952 memset(bp, 0, padsz);
953 bp = (void *) bp + padsz;
955 *bp++ = htonl(c_namesz);
956 memcpy(bp, contents, c_namesz);
957 bp = (void *) bp + c_namesz;
959 memset(bp, 0, c_padsz);
960 bp = (void *) bp + c_padsz;
962 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
963 *bp++ = htonl(dvnode->vfs_inode.i_mtime.tv_sec); /* mtime */
964 *bp++ = 0; /* owner */
965 *bp++ = 0; /* group */
966 *bp++ = htonl(S_IRWXUGO); /* unix mode */
967 *bp++ = 0; /* segment size */
969 afs_use_fs_server(call, fc->cbi);
970 trace_afs_make_fs_call1(call, &dvnode->fid, name);
971 afs_set_fc_call(call, fc);
972 afs_make_call(&fc->ac, call, GFP_NOFS);
973 return afs_wait_for_call_to_complete(call, &fc->ac);
977 * deliver reply data to an FS.Rename
979 static int afs_deliver_fs_rename(struct afs_call *call)
984 ret = afs_transfer_reply(call);
988 /* unmarshall the reply once we've received all of it */
990 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_dir_scb);
993 if (call->out_dir_scb != call->out_scb) {
994 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
998 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1000 _leave(" = 0 [done]");
1005 * FS.Rename operation type
1007 static const struct afs_call_type afs_RXFSRename = {
1008 .name = "FS.Rename",
1009 .op = afs_FS_Rename,
1010 .deliver = afs_deliver_fs_rename,
1011 .destructor = afs_flat_call_destructor,
1015 * Rename/move a file or directory.
1017 int afs_fs_rename(struct afs_fs_cursor *fc,
1018 const char *orig_name,
1019 struct afs_vnode *new_dvnode,
1020 const char *new_name,
1021 struct afs_status_cb *orig_dvnode_scb,
1022 struct afs_status_cb *new_dvnode_scb)
1024 struct afs_vnode *orig_dvnode = fc->vnode;
1025 struct afs_call *call;
1026 struct afs_net *net = afs_v2net(orig_dvnode);
1027 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1030 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1031 return yfs_fs_rename(fc, orig_name,
1032 new_dvnode, new_name,
1038 o_namesz = strlen(orig_name);
1039 o_padsz = (4 - (o_namesz & 3)) & 3;
1041 n_namesz = strlen(new_name);
1042 n_padsz = (4 - (n_namesz & 3)) & 3;
1045 4 + o_namesz + o_padsz +
1047 4 + n_namesz + n_padsz;
1049 call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1053 call->key = fc->key;
1054 call->out_dir_scb = orig_dvnode_scb;
1055 call->out_scb = new_dvnode_scb;
1057 /* marshall the parameters */
1059 *bp++ = htonl(FSRENAME);
1060 *bp++ = htonl(orig_dvnode->fid.vid);
1061 *bp++ = htonl(orig_dvnode->fid.vnode);
1062 *bp++ = htonl(orig_dvnode->fid.unique);
1063 *bp++ = htonl(o_namesz);
1064 memcpy(bp, orig_name, o_namesz);
1065 bp = (void *) bp + o_namesz;
1067 memset(bp, 0, o_padsz);
1068 bp = (void *) bp + o_padsz;
1071 *bp++ = htonl(new_dvnode->fid.vid);
1072 *bp++ = htonl(new_dvnode->fid.vnode);
1073 *bp++ = htonl(new_dvnode->fid.unique);
1074 *bp++ = htonl(n_namesz);
1075 memcpy(bp, new_name, n_namesz);
1076 bp = (void *) bp + n_namesz;
1078 memset(bp, 0, n_padsz);
1079 bp = (void *) bp + n_padsz;
1082 afs_use_fs_server(call, fc->cbi);
1083 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1084 afs_set_fc_call(call, fc);
1085 afs_make_call(&fc->ac, call, GFP_NOFS);
1086 return afs_wait_for_call_to_complete(call, &fc->ac);
1090 * deliver reply data to an FS.StoreData
1092 static int afs_deliver_fs_store_data(struct afs_call *call)
1099 ret = afs_transfer_reply(call);
1103 /* unmarshall the reply once we've received all of it */
1105 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1108 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1110 _leave(" = 0 [done]");
1115 * FS.StoreData operation type
1117 static const struct afs_call_type afs_RXFSStoreData = {
1118 .name = "FS.StoreData",
1119 .op = afs_FS_StoreData,
1120 .deliver = afs_deliver_fs_store_data,
1121 .destructor = afs_flat_call_destructor,
1124 static const struct afs_call_type afs_RXFSStoreData64 = {
1125 .name = "FS.StoreData64",
1126 .op = afs_FS_StoreData64,
1127 .deliver = afs_deliver_fs_store_data,
1128 .destructor = afs_flat_call_destructor,
1132 * store a set of pages to a very large file
1134 static int afs_fs_store_data64(struct afs_fs_cursor *fc,
1135 struct address_space *mapping,
1136 pgoff_t first, pgoff_t last,
1137 unsigned offset, unsigned to,
1138 loff_t size, loff_t pos, loff_t i_size,
1139 struct afs_status_cb *scb)
1141 struct afs_vnode *vnode = fc->vnode;
1142 struct afs_call *call;
1143 struct afs_net *net = afs_v2net(vnode);
1146 _enter(",%x,{%llx:%llu},,",
1147 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1149 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
1150 (4 + 6 + 3 * 2) * 4,
1155 call->key = fc->key;
1156 call->mapping = mapping;
1157 call->first = first;
1159 call->first_offset = offset;
1161 call->send_pages = true;
1162 call->out_scb = scb;
1164 /* marshall the parameters */
1166 *bp++ = htonl(FSSTOREDATA64);
1167 *bp++ = htonl(vnode->fid.vid);
1168 *bp++ = htonl(vnode->fid.vnode);
1169 *bp++ = htonl(vnode->fid.unique);
1171 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1172 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1173 *bp++ = 0; /* owner */
1174 *bp++ = 0; /* group */
1175 *bp++ = 0; /* unix mode */
1176 *bp++ = 0; /* segment size */
1178 *bp++ = htonl(pos >> 32);
1179 *bp++ = htonl((u32) pos);
1180 *bp++ = htonl(size >> 32);
1181 *bp++ = htonl((u32) size);
1182 *bp++ = htonl(i_size >> 32);
1183 *bp++ = htonl((u32) i_size);
1185 trace_afs_make_fs_call(call, &vnode->fid);
1186 afs_set_fc_call(call, fc);
1187 afs_make_call(&fc->ac, call, GFP_NOFS);
1188 return afs_wait_for_call_to_complete(call, &fc->ac);
1192 * store a set of pages
1194 int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1195 pgoff_t first, pgoff_t last,
1196 unsigned offset, unsigned to,
1197 struct afs_status_cb *scb)
1199 struct afs_vnode *vnode = fc->vnode;
1200 struct afs_call *call;
1201 struct afs_net *net = afs_v2net(vnode);
1202 loff_t size, pos, i_size;
1205 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1206 return yfs_fs_store_data(fc, mapping, first, last, offset, to, scb);
1208 _enter(",%x,{%llx:%llu},,",
1209 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1211 size = (loff_t)to - (loff_t)offset;
1213 size += (loff_t)(last - first) << PAGE_SHIFT;
1214 pos = (loff_t)first << PAGE_SHIFT;
1217 i_size = i_size_read(&vnode->vfs_inode);
1218 if (pos + size > i_size)
1219 i_size = size + pos;
1221 _debug("size %llx, at %llx, i_size %llx",
1222 (unsigned long long) size, (unsigned long long) pos,
1223 (unsigned long long) i_size);
1225 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1226 return afs_fs_store_data64(fc, mapping, first, last, offset, to,
1227 size, pos, i_size, scb);
1229 call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
1235 call->key = fc->key;
1236 call->mapping = mapping;
1237 call->first = first;
1239 call->first_offset = offset;
1241 call->send_pages = true;
1242 call->out_scb = scb;
1244 /* marshall the parameters */
1246 *bp++ = htonl(FSSTOREDATA);
1247 *bp++ = htonl(vnode->fid.vid);
1248 *bp++ = htonl(vnode->fid.vnode);
1249 *bp++ = htonl(vnode->fid.unique);
1251 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1252 *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
1253 *bp++ = 0; /* owner */
1254 *bp++ = 0; /* group */
1255 *bp++ = 0; /* unix mode */
1256 *bp++ = 0; /* segment size */
1259 *bp++ = htonl(size);
1260 *bp++ = htonl(i_size);
1262 afs_use_fs_server(call, fc->cbi);
1263 trace_afs_make_fs_call(call, &vnode->fid);
1264 afs_set_fc_call(call, fc);
1265 afs_make_call(&fc->ac, call, GFP_NOFS);
1266 return afs_wait_for_call_to_complete(call, &fc->ac);
1270 * deliver reply data to an FS.StoreStatus
1272 static int afs_deliver_fs_store_status(struct afs_call *call)
1279 ret = afs_transfer_reply(call);
1283 /* unmarshall the reply once we've received all of it */
1285 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1288 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1290 _leave(" = 0 [done]");
1295 * FS.StoreStatus operation type
1297 static const struct afs_call_type afs_RXFSStoreStatus = {
1298 .name = "FS.StoreStatus",
1299 .op = afs_FS_StoreStatus,
1300 .deliver = afs_deliver_fs_store_status,
1301 .destructor = afs_flat_call_destructor,
1304 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1305 .name = "FS.StoreData",
1306 .op = afs_FS_StoreData,
1307 .deliver = afs_deliver_fs_store_status,
1308 .destructor = afs_flat_call_destructor,
1311 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1312 .name = "FS.StoreData64",
1313 .op = afs_FS_StoreData64,
1314 .deliver = afs_deliver_fs_store_status,
1315 .destructor = afs_flat_call_destructor,
1319 * set the attributes on a very large file, using FS.StoreData rather than
1320 * FS.StoreStatus so as to alter the file size also
1322 static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr,
1323 struct afs_status_cb *scb)
1325 struct afs_vnode *vnode = fc->vnode;
1326 struct afs_call *call;
1327 struct afs_net *net = afs_v2net(vnode);
1330 _enter(",%x,{%llx:%llu},,",
1331 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1333 ASSERT(attr->ia_valid & ATTR_SIZE);
1335 call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
1336 (4 + 6 + 3 * 2) * 4,
1341 call->key = fc->key;
1342 call->out_scb = scb;
1344 /* marshall the parameters */
1346 *bp++ = htonl(FSSTOREDATA64);
1347 *bp++ = htonl(vnode->fid.vid);
1348 *bp++ = htonl(vnode->fid.vnode);
1349 *bp++ = htonl(vnode->fid.unique);
1351 xdr_encode_AFS_StoreStatus(&bp, attr);
1353 *bp++ = htonl(attr->ia_size >> 32); /* position of start of write */
1354 *bp++ = htonl((u32) attr->ia_size);
1355 *bp++ = 0; /* size of write */
1357 *bp++ = htonl(attr->ia_size >> 32); /* new file length */
1358 *bp++ = htonl((u32) attr->ia_size);
1360 afs_use_fs_server(call, fc->cbi);
1361 trace_afs_make_fs_call(call, &vnode->fid);
1362 afs_set_fc_call(call, fc);
1363 afs_make_call(&fc->ac, call, GFP_NOFS);
1364 return afs_wait_for_call_to_complete(call, &fc->ac);
1368 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1369 * so as to alter the file size also
1371 static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr,
1372 struct afs_status_cb *scb)
1374 struct afs_vnode *vnode = fc->vnode;
1375 struct afs_call *call;
1376 struct afs_net *net = afs_v2net(vnode);
1379 _enter(",%x,{%llx:%llu},,",
1380 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1382 ASSERT(attr->ia_valid & ATTR_SIZE);
1383 if (attr->ia_size >> 32)
1384 return afs_fs_setattr_size64(fc, attr, scb);
1386 call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
1392 call->key = fc->key;
1393 call->out_scb = scb;
1395 /* marshall the parameters */
1397 *bp++ = htonl(FSSTOREDATA);
1398 *bp++ = htonl(vnode->fid.vid);
1399 *bp++ = htonl(vnode->fid.vnode);
1400 *bp++ = htonl(vnode->fid.unique);
1402 xdr_encode_AFS_StoreStatus(&bp, attr);
1404 *bp++ = htonl(attr->ia_size); /* position of start of write */
1405 *bp++ = 0; /* size of write */
1406 *bp++ = htonl(attr->ia_size); /* new file length */
1408 afs_use_fs_server(call, fc->cbi);
1409 trace_afs_make_fs_call(call, &vnode->fid);
1410 afs_set_fc_call(call, fc);
1411 afs_make_call(&fc->ac, call, GFP_NOFS);
1412 return afs_wait_for_call_to_complete(call, &fc->ac);
1416 * set the attributes on a file, using FS.StoreData if there's a change in file
1417 * size, and FS.StoreStatus otherwise
1419 int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr,
1420 struct afs_status_cb *scb)
1422 struct afs_vnode *vnode = fc->vnode;
1423 struct afs_call *call;
1424 struct afs_net *net = afs_v2net(vnode);
1427 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1428 return yfs_fs_setattr(fc, attr, scb);
1430 if (attr->ia_valid & ATTR_SIZE)
1431 return afs_fs_setattr_size(fc, attr, scb);
1433 _enter(",%x,{%llx:%llu},,",
1434 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1436 call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
1442 call->key = fc->key;
1443 call->out_scb = scb;
1445 /* marshall the parameters */
1447 *bp++ = htonl(FSSTORESTATUS);
1448 *bp++ = htonl(vnode->fid.vid);
1449 *bp++ = htonl(vnode->fid.vnode);
1450 *bp++ = htonl(vnode->fid.unique);
1452 xdr_encode_AFS_StoreStatus(&bp, attr);
1454 afs_use_fs_server(call, fc->cbi);
1455 trace_afs_make_fs_call(call, &vnode->fid);
1456 afs_set_fc_call(call, fc);
1457 afs_make_call(&fc->ac, call, GFP_NOFS);
1458 return afs_wait_for_call_to_complete(call, &fc->ac);
1462 * deliver reply data to an FS.GetVolumeStatus
1464 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1471 _enter("{%u}", call->unmarshall);
1473 switch (call->unmarshall) {
1476 afs_extract_to_buf(call, 12 * 4);
1479 /* extract the returned status record */
1481 _debug("extract status");
1482 ret = afs_extract_data(call, true);
1487 xdr_decode_AFSFetchVolumeStatus(&bp, call->out_volstatus);
1489 afs_extract_to_tmp(call);
1492 /* extract the volume name length */
1494 ret = afs_extract_data(call, true);
1498 call->count = ntohl(call->tmp);
1499 _debug("volname length: %u", call->count);
1500 if (call->count >= AFSNAMEMAX)
1501 return afs_protocol_error(call, -EBADMSG,
1502 afs_eproto_volname_len);
1503 size = (call->count + 3) & ~3; /* It's padded */
1504 afs_extract_to_buf(call, size);
1508 /* extract the volume name */
1510 _debug("extract volname");
1511 ret = afs_extract_data(call, true);
1517 _debug("volname '%s'", p);
1518 afs_extract_to_tmp(call);
1522 /* extract the offline message length */
1524 ret = afs_extract_data(call, true);
1528 call->count = ntohl(call->tmp);
1529 _debug("offline msg length: %u", call->count);
1530 if (call->count >= AFSNAMEMAX)
1531 return afs_protocol_error(call, -EBADMSG,
1532 afs_eproto_offline_msg_len);
1533 size = (call->count + 3) & ~3; /* It's padded */
1534 afs_extract_to_buf(call, size);
1538 /* extract the offline message */
1540 _debug("extract offline");
1541 ret = afs_extract_data(call, true);
1547 _debug("offline '%s'", p);
1549 afs_extract_to_tmp(call);
1553 /* extract the message of the day length */
1555 ret = afs_extract_data(call, true);
1559 call->count = ntohl(call->tmp);
1560 _debug("motd length: %u", call->count);
1561 if (call->count >= AFSNAMEMAX)
1562 return afs_protocol_error(call, -EBADMSG,
1563 afs_eproto_motd_len);
1564 size = (call->count + 3) & ~3; /* It's padded */
1565 afs_extract_to_buf(call, size);
1569 /* extract the message of the day */
1571 _debug("extract motd");
1572 ret = afs_extract_data(call, false);
1578 _debug("motd '%s'", p);
1586 _leave(" = 0 [done]");
1591 * FS.GetVolumeStatus operation type
1593 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1594 .name = "FS.GetVolumeStatus",
1595 .op = afs_FS_GetVolumeStatus,
1596 .deliver = afs_deliver_fs_get_volume_status,
1597 .destructor = afs_flat_call_destructor,
1601 * fetch the status of a volume
1603 int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
1604 struct afs_volume_status *vs)
1606 struct afs_vnode *vnode = fc->vnode;
1607 struct afs_call *call;
1608 struct afs_net *net = afs_v2net(vnode);
1611 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1612 return yfs_fs_get_volume_status(fc, vs);
1616 call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4,
1617 max(12 * 4, AFSOPAQUEMAX + 1));
1621 call->key = fc->key;
1622 call->out_volstatus = vs;
1624 /* marshall the parameters */
1626 bp[0] = htonl(FSGETVOLUMESTATUS);
1627 bp[1] = htonl(vnode->fid.vid);
1629 afs_use_fs_server(call, fc->cbi);
1630 trace_afs_make_fs_call(call, &vnode->fid);
1631 afs_set_fc_call(call, fc);
1632 afs_make_call(&fc->ac, call, GFP_NOFS);
1633 return afs_wait_for_call_to_complete(call, &fc->ac);
1637 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1639 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1644 _enter("{%u}", call->unmarshall);
1646 ret = afs_transfer_reply(call);
1650 /* unmarshall the reply once we've received all of it */
1652 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1654 _leave(" = 0 [done]");
1659 * FS.SetLock operation type
1661 static const struct afs_call_type afs_RXFSSetLock = {
1662 .name = "FS.SetLock",
1663 .op = afs_FS_SetLock,
1664 .deliver = afs_deliver_fs_xxxx_lock,
1665 .done = afs_lock_op_done,
1666 .destructor = afs_flat_call_destructor,
1670 * FS.ExtendLock operation type
1672 static const struct afs_call_type afs_RXFSExtendLock = {
1673 .name = "FS.ExtendLock",
1674 .op = afs_FS_ExtendLock,
1675 .deliver = afs_deliver_fs_xxxx_lock,
1676 .done = afs_lock_op_done,
1677 .destructor = afs_flat_call_destructor,
1681 * FS.ReleaseLock operation type
1683 static const struct afs_call_type afs_RXFSReleaseLock = {
1684 .name = "FS.ReleaseLock",
1685 .op = afs_FS_ReleaseLock,
1686 .deliver = afs_deliver_fs_xxxx_lock,
1687 .destructor = afs_flat_call_destructor,
1691 * Set a lock on a file
1693 int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type,
1694 struct afs_status_cb *scb)
1696 struct afs_vnode *vnode = fc->vnode;
1697 struct afs_call *call;
1698 struct afs_net *net = afs_v2net(vnode);
1701 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1702 return yfs_fs_set_lock(fc, type, scb);
1706 call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1710 call->key = fc->key;
1711 call->lvnode = vnode;
1712 call->out_scb = scb;
1714 /* marshall the parameters */
1716 *bp++ = htonl(FSSETLOCK);
1717 *bp++ = htonl(vnode->fid.vid);
1718 *bp++ = htonl(vnode->fid.vnode);
1719 *bp++ = htonl(vnode->fid.unique);
1720 *bp++ = htonl(type);
1722 afs_use_fs_server(call, fc->cbi);
1723 trace_afs_make_fs_calli(call, &vnode->fid, type);
1724 afs_set_fc_call(call, fc);
1725 afs_make_call(&fc->ac, call, GFP_NOFS);
1726 return afs_wait_for_call_to_complete(call, &fc->ac);
1730 * extend a lock on a file
1732 int afs_fs_extend_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
1734 struct afs_vnode *vnode = fc->vnode;
1735 struct afs_call *call;
1736 struct afs_net *net = afs_v2net(vnode);
1739 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1740 return yfs_fs_extend_lock(fc, scb);
1744 call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1748 call->key = fc->key;
1749 call->lvnode = vnode;
1750 call->out_scb = scb;
1752 /* marshall the parameters */
1754 *bp++ = htonl(FSEXTENDLOCK);
1755 *bp++ = htonl(vnode->fid.vid);
1756 *bp++ = htonl(vnode->fid.vnode);
1757 *bp++ = htonl(vnode->fid.unique);
1759 afs_use_fs_server(call, fc->cbi);
1760 trace_afs_make_fs_call(call, &vnode->fid);
1761 afs_set_fc_call(call, fc);
1762 afs_make_call(&fc->ac, call, GFP_NOFS);
1763 return afs_wait_for_call_to_complete(call, &fc->ac);
1767 * release a lock on a file
1769 int afs_fs_release_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
1771 struct afs_vnode *vnode = fc->vnode;
1772 struct afs_call *call;
1773 struct afs_net *net = afs_v2net(vnode);
1776 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1777 return yfs_fs_release_lock(fc, scb);
1781 call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1785 call->key = fc->key;
1786 call->lvnode = vnode;
1787 call->out_scb = scb;
1789 /* marshall the parameters */
1791 *bp++ = htonl(FSRELEASELOCK);
1792 *bp++ = htonl(vnode->fid.vid);
1793 *bp++ = htonl(vnode->fid.vnode);
1794 *bp++ = htonl(vnode->fid.unique);
1796 afs_use_fs_server(call, fc->cbi);
1797 trace_afs_make_fs_call(call, &vnode->fid);
1798 afs_set_fc_call(call, fc);
1799 afs_make_call(&fc->ac, call, GFP_NOFS);
1800 return afs_wait_for_call_to_complete(call, &fc->ac);
1804 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1806 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1808 return afs_transfer_reply(call);
1812 * FS.GiveUpAllCallBacks operation type
1814 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1815 .name = "FS.GiveUpAllCallBacks",
1816 .op = afs_FS_GiveUpAllCallBacks,
1817 .deliver = afs_deliver_fs_give_up_all_callbacks,
1818 .destructor = afs_flat_call_destructor,
1822 * Flush all the callbacks we have on a server.
1824 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1825 struct afs_server *server,
1826 struct afs_addr_cursor *ac,
1829 struct afs_call *call;
1834 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1840 /* marshall the parameters */
1842 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1844 /* Can't take a ref on server */
1845 afs_make_call(ac, call, GFP_NOFS);
1846 return afs_wait_for_call_to_complete(call, ac);
1850 * Deliver reply data to an FS.GetCapabilities operation.
1852 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1857 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
1859 switch (call->unmarshall) {
1861 afs_extract_to_tmp(call);
1865 /* Extract the capabilities word count */
1867 ret = afs_extract_data(call, true);
1871 count = ntohl(call->tmp);
1873 call->count = count;
1874 call->count2 = count;
1875 iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
1879 /* Extract capabilities words */
1881 ret = afs_extract_data(call, false);
1885 /* TODO: Examine capabilities */
1891 _leave(" = 0 [done]");
1896 * FS.GetCapabilities operation type
1898 static const struct afs_call_type afs_RXFSGetCapabilities = {
1899 .name = "FS.GetCapabilities",
1900 .op = afs_FS_GetCapabilities,
1901 .deliver = afs_deliver_fs_get_capabilities,
1902 .done = afs_fileserver_probe_result,
1903 .destructor = afs_flat_call_destructor,
1907 * Probe a fileserver for the capabilities that it supports. This can
1908 * return up to 196 words.
1910 struct afs_call *afs_fs_get_capabilities(struct afs_net *net,
1911 struct afs_server *server,
1912 struct afs_addr_cursor *ac,
1914 unsigned int server_index)
1916 struct afs_call *call;
1921 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1923 return ERR_PTR(-ENOMEM);
1926 call->server = afs_get_server(server, afs_server_trace_get_caps);
1927 call->server_index = server_index;
1928 call->upgrade = true;
1930 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
1932 /* marshall the parameters */
1934 *bp++ = htonl(FSGETCAPABILITIES);
1936 /* Can't take a ref on server */
1937 trace_afs_make_fs_call(call, NULL);
1938 afs_make_call(ac, call, GFP_NOFS);
1943 * Deliver reply data to an FS.FetchStatus with no vnode.
1945 static int afs_deliver_fs_fetch_status(struct afs_call *call)
1950 ret = afs_transfer_reply(call);
1954 /* unmarshall the reply once we've received all of it */
1956 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
1959 xdr_decode_AFSCallBack(&bp, call, call->out_scb);
1960 xdr_decode_AFSVolSync(&bp, call->out_volsync);
1962 _leave(" = 0 [done]");
1967 * FS.FetchStatus operation type
1969 static const struct afs_call_type afs_RXFSFetchStatus = {
1970 .name = "FS.FetchStatus",
1971 .op = afs_FS_FetchStatus,
1972 .deliver = afs_deliver_fs_fetch_status,
1973 .destructor = afs_flat_call_destructor,
1977 * Fetch the status information for a fid without needing a vnode handle.
1979 int afs_fs_fetch_status(struct afs_fs_cursor *fc,
1980 struct afs_net *net,
1981 struct afs_fid *fid,
1982 struct afs_status_cb *scb,
1983 struct afs_volsync *volsync)
1985 struct afs_call *call;
1988 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
1989 return yfs_fs_fetch_status(fc, net, fid, scb, volsync);
1991 _enter(",%x,{%llx:%llu},,",
1992 key_serial(fc->key), fid->vid, fid->vnode);
1994 call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
1996 fc->ac.error = -ENOMEM;
2000 call->key = fc->key;
2001 call->out_fid = fid;
2002 call->out_scb = scb;
2003 call->out_volsync = volsync;
2005 /* marshall the parameters */
2007 bp[0] = htonl(FSFETCHSTATUS);
2008 bp[1] = htonl(fid->vid);
2009 bp[2] = htonl(fid->vnode);
2010 bp[3] = htonl(fid->unique);
2012 afs_use_fs_server(call, fc->cbi);
2013 trace_afs_make_fs_call(call, fid);
2014 afs_set_fc_call(call, fc);
2015 afs_make_call(&fc->ac, call, GFP_NOFS);
2016 return afs_wait_for_call_to_complete(call, &fc->ac);
2020 * Deliver reply data to an FS.InlineBulkStatus call
2022 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
2024 struct afs_status_cb *scb;
2029 _enter("{%u}", call->unmarshall);
2031 switch (call->unmarshall) {
2033 afs_extract_to_tmp(call);
2037 /* Extract the file status count and array in two steps */
2039 _debug("extract status count");
2040 ret = afs_extract_data(call, true);
2044 tmp = ntohl(call->tmp);
2045 _debug("status count: %u/%u", tmp, call->count2);
2046 if (tmp != call->count2)
2047 return afs_protocol_error(call, -EBADMSG,
2048 afs_eproto_ibulkst_count);
2053 afs_extract_to_buf(call, 21 * sizeof(__be32));
2057 _debug("extract status array %u", call->count);
2058 ret = afs_extract_data(call, true);
2063 scb = &call->out_scb[call->count];
2064 ret = xdr_decode_AFSFetchStatus(&bp, call, scb);
2069 if (call->count < call->count2)
2074 afs_extract_to_tmp(call);
2077 /* Extract the callback count and array in two steps */
2079 _debug("extract CB count");
2080 ret = afs_extract_data(call, true);
2084 tmp = ntohl(call->tmp);
2085 _debug("CB count: %u", tmp);
2086 if (tmp != call->count2)
2087 return afs_protocol_error(call, -EBADMSG,
2088 afs_eproto_ibulkst_cb_count);
2092 afs_extract_to_buf(call, 3 * sizeof(__be32));
2096 _debug("extract CB array");
2097 ret = afs_extract_data(call, true);
2101 _debug("unmarshall CB array");
2103 scb = &call->out_scb[call->count];
2104 xdr_decode_AFSCallBack(&bp, call, scb);
2106 if (call->count < call->count2)
2109 afs_extract_to_buf(call, 6 * sizeof(__be32));
2114 ret = afs_extract_data(call, false);
2119 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2127 _leave(" = 0 [done]");
2132 * FS.InlineBulkStatus operation type
2134 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
2135 .name = "FS.InlineBulkStatus",
2136 .op = afs_FS_InlineBulkStatus,
2137 .deliver = afs_deliver_fs_inline_bulk_status,
2138 .destructor = afs_flat_call_destructor,
2142 * Fetch the status information for up to 50 files
2144 int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
2145 struct afs_net *net,
2146 struct afs_fid *fids,
2147 struct afs_status_cb *statuses,
2148 unsigned int nr_fids,
2149 struct afs_volsync *volsync)
2151 struct afs_call *call;
2155 if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
2156 return yfs_fs_inline_bulk_status(fc, net, fids, statuses,
2159 _enter(",%x,{%llx:%llu},%u",
2160 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
2162 call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
2163 (2 + nr_fids * 3) * 4,
2166 fc->ac.error = -ENOMEM;
2170 call->key = fc->key;
2171 call->out_scb = statuses;
2172 call->out_volsync = volsync;
2173 call->count2 = nr_fids;
2175 /* marshall the parameters */
2177 *bp++ = htonl(FSINLINEBULKSTATUS);
2178 *bp++ = htonl(nr_fids);
2179 for (i = 0; i < nr_fids; i++) {
2180 *bp++ = htonl(fids[i].vid);
2181 *bp++ = htonl(fids[i].vnode);
2182 *bp++ = htonl(fids[i].unique);
2185 afs_use_fs_server(call, fc->cbi);
2186 trace_afs_make_fs_call(call, &fids[0]);
2187 afs_set_fc_call(call, fc);
2188 afs_make_call(&fc->ac, call, GFP_NOFS);
2189 return afs_wait_for_call_to_complete(call, &fc->ac);
2193 * deliver reply data to an FS.FetchACL
2195 static int afs_deliver_fs_fetch_acl(struct afs_call *call)
2197 struct afs_acl *acl;
2202 _enter("{%u}", call->unmarshall);
2204 switch (call->unmarshall) {
2206 afs_extract_to_tmp(call);
2210 /* extract the returned data length */
2212 ret = afs_extract_data(call, true);
2216 size = call->count2 = ntohl(call->tmp);
2217 size = round_up(size, 4);
2219 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2222 call->ret_acl = acl;
2223 acl->size = call->count2;
2224 afs_extract_begin(call, acl->data, size);
2228 /* extract the returned data */
2230 ret = afs_extract_data(call, true);
2234 afs_extract_to_buf(call, (21 + 6) * 4);
2238 /* extract the metadata */
2240 ret = afs_extract_data(call, false);
2245 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
2248 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2256 _leave(" = 0 [done]");
2260 static void afs_destroy_fs_fetch_acl(struct afs_call *call)
2262 kfree(call->ret_acl);
2263 afs_flat_call_destructor(call);
2267 * FS.FetchACL operation type
2269 static const struct afs_call_type afs_RXFSFetchACL = {
2270 .name = "FS.FetchACL",
2271 .op = afs_FS_FetchACL,
2272 .deliver = afs_deliver_fs_fetch_acl,
2273 .destructor = afs_destroy_fs_fetch_acl,
2277 * Fetch the ACL for a file.
2279 struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc,
2280 struct afs_status_cb *scb)
2282 struct afs_vnode *vnode = fc->vnode;
2283 struct afs_call *call;
2284 struct afs_net *net = afs_v2net(vnode);
2287 _enter(",%x,{%llx:%llu},,",
2288 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2290 call = afs_alloc_flat_call(net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2292 fc->ac.error = -ENOMEM;
2293 return ERR_PTR(-ENOMEM);
2296 call->key = fc->key;
2297 call->ret_acl = NULL;
2298 call->out_scb = scb;
2299 call->out_volsync = NULL;
2301 /* marshall the parameters */
2303 bp[0] = htonl(FSFETCHACL);
2304 bp[1] = htonl(vnode->fid.vid);
2305 bp[2] = htonl(vnode->fid.vnode);
2306 bp[3] = htonl(vnode->fid.unique);
2308 afs_use_fs_server(call, fc->cbi);
2309 trace_afs_make_fs_call(call, &vnode->fid);
2310 afs_make_call(&fc->ac, call, GFP_KERNEL);
2311 return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2315 * Deliver reply data to any operation that returns file status and volume
2318 static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
2323 ret = afs_transfer_reply(call);
2328 ret = xdr_decode_AFSFetchStatus(&bp, call, call->out_scb);
2331 xdr_decode_AFSVolSync(&bp, call->out_volsync);
2333 _leave(" = 0 [done]");
2338 * FS.StoreACL operation type
2340 static const struct afs_call_type afs_RXFSStoreACL = {
2341 .name = "FS.StoreACL",
2342 .op = afs_FS_StoreACL,
2343 .deliver = afs_deliver_fs_file_status_and_vol,
2344 .destructor = afs_flat_call_destructor,
2348 * Fetch the ACL for a file.
2350 int afs_fs_store_acl(struct afs_fs_cursor *fc, const struct afs_acl *acl,
2351 struct afs_status_cb *scb)
2353 struct afs_vnode *vnode = fc->vnode;
2354 struct afs_call *call;
2355 struct afs_net *net = afs_v2net(vnode);
2359 _enter(",%x,{%llx:%llu},,",
2360 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2362 size = round_up(acl->size, 4);
2363 call = afs_alloc_flat_call(net, &afs_RXFSStoreACL,
2364 5 * 4 + size, (21 + 6) * 4);
2366 fc->ac.error = -ENOMEM;
2370 call->key = fc->key;
2371 call->out_scb = scb;
2372 call->out_volsync = NULL;
2374 /* marshall the parameters */
2376 bp[0] = htonl(FSSTOREACL);
2377 bp[1] = htonl(vnode->fid.vid);
2378 bp[2] = htonl(vnode->fid.vnode);
2379 bp[3] = htonl(vnode->fid.unique);
2380 bp[4] = htonl(acl->size);
2381 memcpy(&bp[5], acl->data, acl->size);
2382 if (acl->size != size)
2383 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2385 trace_afs_make_fs_call(call, &vnode->fid);
2386 afs_make_call(&fc->ac, call, GFP_KERNEL);
2387 return afs_wait_for_call_to_complete(call, &fc->ac);