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>
13 #include <linux/netfs.h>
19 * decode an AFSFid block
21 static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
23 const __be32 *bp = *_bp;
25 fid->vid = ntohl(*bp++);
26 fid->vnode = ntohl(*bp++);
27 fid->unique = ntohl(*bp++);
32 * Dump a bad file status record.
34 static void xdr_dump_bad(const __be32 *bp)
39 pr_notice("AFS XDR: Bad status record\n");
40 for (i = 0; i < 5 * 4 * 4; i += 16) {
43 pr_notice("%03x: %08x %08x %08x %08x\n",
44 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
48 pr_notice("0x50: %08x\n", ntohl(x[0]));
52 * decode an AFSFetchStatus block
54 static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
55 struct afs_call *call,
56 struct afs_status_cb *scb)
58 const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
59 struct afs_file_status *status = &scb->status;
60 bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
61 u64 data_version, size;
64 abort_code = ntohl(xdr->abort_code);
66 if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
67 if (xdr->if_version == htonl(0) &&
70 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
71 * whereby it doesn't set the interface version in the error
74 status->abort_code = abort_code;
75 scb->have_error = true;
79 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
83 if (abort_code != 0 && inline_error) {
84 status->abort_code = abort_code;
85 scb->have_error = true;
89 type = ntohl(xdr->type);
93 case AFS_FTYPE_SYMLINK:
100 status->nlink = ntohl(xdr->nlink);
101 status->author = ntohl(xdr->author);
102 status->owner = ntohl(xdr->owner);
103 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
104 status->anon_access = ntohl(xdr->anon_access);
105 status->mode = ntohl(xdr->mode) & S_IALLUGO;
106 status->group = ntohl(xdr->group);
107 status->lock_count = ntohl(xdr->lock_count);
109 status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
110 status->mtime_client.tv_nsec = 0;
111 status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
112 status->mtime_server.tv_nsec = 0;
114 size = (u64)ntohl(xdr->size_lo);
115 size |= (u64)ntohl(xdr->size_hi) << 32;
118 data_version = (u64)ntohl(xdr->data_version_lo);
119 data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
120 status->data_version = data_version;
121 scb->have_status = true;
123 *_bp = (const void *)*_bp + sizeof(*xdr);
128 afs_protocol_error(call, afs_eproto_bad_status);
132 static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
134 return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
137 static void xdr_decode_AFSCallBack(const __be32 **_bp,
138 struct afs_call *call,
139 struct afs_status_cb *scb)
141 struct afs_callback *cb = &scb->callback;
142 const __be32 *bp = *_bp;
145 cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
152 * decode an AFSVolSync block
154 static void xdr_decode_AFSVolSync(const __be32 **_bp,
155 struct afs_volsync *volsync)
157 const __be32 *bp = *_bp;
160 creation = ntohl(*bp++);
169 volsync->creation = creation;
173 * encode the requested attributes into an AFSStoreStatus block
175 static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
178 u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
181 if (attr->ia_valid & ATTR_MTIME) {
182 mask |= AFS_SET_MTIME;
183 mtime = attr->ia_mtime.tv_sec;
186 if (attr->ia_valid & ATTR_UID) {
187 mask |= AFS_SET_OWNER;
188 owner = from_kuid(&init_user_ns, attr->ia_uid);
191 if (attr->ia_valid & ATTR_GID) {
192 mask |= AFS_SET_GROUP;
193 group = from_kgid(&init_user_ns, attr->ia_gid);
196 if (attr->ia_valid & ATTR_MODE) {
197 mask |= AFS_SET_MODE;
198 mode = attr->ia_mode & S_IALLUGO;
202 *bp++ = htonl(mtime);
203 *bp++ = htonl(owner);
204 *bp++ = htonl(group);
206 *bp++ = 0; /* segment size */
211 * decode an AFSFetchVolumeStatus block
213 static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
214 struct afs_volume_status *vs)
216 const __be32 *bp = *_bp;
218 vs->vid = ntohl(*bp++);
219 vs->parent_id = ntohl(*bp++);
220 vs->online = ntohl(*bp++);
221 vs->in_service = ntohl(*bp++);
222 vs->blessed = ntohl(*bp++);
223 vs->needs_salvage = ntohl(*bp++);
224 vs->type = ntohl(*bp++);
225 vs->min_quota = ntohl(*bp++);
226 vs->max_quota = ntohl(*bp++);
227 vs->blocks_in_use = ntohl(*bp++);
228 vs->part_blocks_avail = ntohl(*bp++);
229 vs->part_max_blocks = ntohl(*bp++);
230 vs->vol_copy_date = 0;
231 vs->vol_backup_date = 0;
236 * deliver reply data to an FS.FetchStatus
238 static int afs_deliver_fs_fetch_status(struct afs_call *call)
240 struct afs_operation *op = call->op;
241 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
245 ret = afs_transfer_reply(call);
249 /* unmarshall the reply once we've received all of it */
251 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
252 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
253 xdr_decode_AFSVolSync(&bp, &op->volsync);
255 _leave(" = 0 [done]");
260 * FS.FetchStatus operation type
262 static const struct afs_call_type afs_RXFSFetchStatus = {
263 .name = "FS.FetchStatus",
264 .op = afs_FS_FetchStatus,
265 .deliver = afs_deliver_fs_fetch_status,
266 .destructor = afs_flat_call_destructor,
270 * fetch the status information for a file
272 void afs_fs_fetch_status(struct afs_operation *op)
274 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
275 struct afs_call *call;
278 _enter(",%x,{%llx:%llu},,",
279 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
281 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchStatus,
282 16, (21 + 3 + 6) * 4);
284 return afs_op_nomem(op);
286 /* marshall the parameters */
288 bp[0] = htonl(FSFETCHSTATUS);
289 bp[1] = htonl(vp->fid.vid);
290 bp[2] = htonl(vp->fid.vnode);
291 bp[3] = htonl(vp->fid.unique);
293 trace_afs_make_fs_call(call, &vp->fid);
294 afs_make_op_call(op, call, GFP_NOFS);
298 * deliver reply data to an FS.FetchData
300 static int afs_deliver_fs_fetch_data(struct afs_call *call)
302 struct afs_operation *op = call->op;
303 struct afs_vnode_param *vp = &op->file[0];
304 struct afs_read *req = op->fetch.req;
308 _enter("{%u,%zu,%zu/%llu}",
309 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
312 switch (call->unmarshall) {
316 if (call->operation_ID == FSFETCHDATA64) {
317 afs_extract_to_tmp64(call);
319 call->tmp_u = htonl(0);
320 afs_extract_to_tmp(call);
324 /* Extract the returned data length into
325 * ->actual_len. This may indicate more or less data than was
326 * requested will be returned.
329 _debug("extract data length");
330 ret = afs_extract_data(call, true);
334 req->actual_len = be64_to_cpu(call->tmp64);
335 _debug("DATA length: %llu", req->actual_len);
337 if (req->actual_len == 0)
340 call->iter = req->iter;
341 call->iov_len = min(req->actual_len, req->len);
345 /* extract the returned data */
347 _debug("extract data %zu/%llu",
348 iov_iter_count(call->iter), req->actual_len);
350 ret = afs_extract_data(call, true);
354 call->iter = &call->def_iter;
355 if (req->actual_len <= req->len)
358 /* Discard any excess data the server gave us */
359 afs_extract_discard(call, req->actual_len - req->len);
360 call->unmarshall = 3;
364 _debug("extract discard %zu/%llu",
365 iov_iter_count(call->iter), req->actual_len - req->len);
367 ret = afs_extract_data(call, true);
372 call->unmarshall = 4;
373 afs_extract_to_buf(call, (21 + 3 + 6) * 4);
376 /* extract the metadata */
378 ret = afs_extract_data(call, false);
383 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
384 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
385 xdr_decode_AFSVolSync(&bp, &op->volsync);
387 req->data_version = vp->scb.status.data_version;
388 req->file_size = vp->scb.status.size;
396 _leave(" = 0 [done]");
401 * FS.FetchData operation type
403 static const struct afs_call_type afs_RXFSFetchData = {
404 .name = "FS.FetchData",
405 .op = afs_FS_FetchData,
406 .deliver = afs_deliver_fs_fetch_data,
407 .destructor = afs_flat_call_destructor,
410 static const struct afs_call_type afs_RXFSFetchData64 = {
411 .name = "FS.FetchData64",
412 .op = afs_FS_FetchData64,
413 .deliver = afs_deliver_fs_fetch_data,
414 .destructor = afs_flat_call_destructor,
418 * fetch data from a very large file
420 static void afs_fs_fetch_data64(struct afs_operation *op)
422 struct afs_vnode_param *vp = &op->file[0];
423 struct afs_read *req = op->fetch.req;
424 struct afs_call *call;
429 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
431 return afs_op_nomem(op);
433 /* marshall the parameters */
435 bp[0] = htonl(FSFETCHDATA64);
436 bp[1] = htonl(vp->fid.vid);
437 bp[2] = htonl(vp->fid.vnode);
438 bp[3] = htonl(vp->fid.unique);
439 bp[4] = htonl(upper_32_bits(req->pos));
440 bp[5] = htonl(lower_32_bits(req->pos));
442 bp[7] = htonl(lower_32_bits(req->len));
444 trace_afs_make_fs_call(call, &vp->fid);
445 afs_make_op_call(op, call, GFP_NOFS);
449 * fetch data from a file
451 void afs_fs_fetch_data(struct afs_operation *op)
453 struct afs_vnode_param *vp = &op->file[0];
454 struct afs_call *call;
455 struct afs_read *req = op->fetch.req;
458 if (upper_32_bits(req->pos) ||
459 upper_32_bits(req->len) ||
460 upper_32_bits(req->pos + req->len))
461 return afs_fs_fetch_data64(op);
465 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
467 return afs_op_nomem(op);
469 req->call_debug_id = call->debug_id;
471 /* marshall the parameters */
473 bp[0] = htonl(FSFETCHDATA);
474 bp[1] = htonl(vp->fid.vid);
475 bp[2] = htonl(vp->fid.vnode);
476 bp[3] = htonl(vp->fid.unique);
477 bp[4] = htonl(lower_32_bits(req->pos));
478 bp[5] = htonl(lower_32_bits(req->len));
480 trace_afs_make_fs_call(call, &vp->fid);
481 afs_make_op_call(op, call, GFP_NOFS);
485 * deliver reply data to an FS.CreateFile or an FS.MakeDir
487 static int afs_deliver_fs_create_vnode(struct afs_call *call)
489 struct afs_operation *op = call->op;
490 struct afs_vnode_param *dvp = &op->file[0];
491 struct afs_vnode_param *vp = &op->file[1];
495 ret = afs_transfer_reply(call);
499 /* unmarshall the reply once we've received all of it */
501 xdr_decode_AFSFid(&bp, &op->file[1].fid);
502 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
503 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
504 xdr_decode_AFSCallBack(&bp, call, &vp->scb);
505 xdr_decode_AFSVolSync(&bp, &op->volsync);
507 _leave(" = 0 [done]");
512 * FS.CreateFile and FS.MakeDir operation type
514 static const struct afs_call_type afs_RXFSCreateFile = {
515 .name = "FS.CreateFile",
516 .op = afs_FS_CreateFile,
517 .deliver = afs_deliver_fs_create_vnode,
518 .destructor = afs_flat_call_destructor,
524 void afs_fs_create_file(struct afs_operation *op)
526 const struct qstr *name = &op->dentry->d_name;
527 struct afs_vnode_param *dvp = &op->file[0];
528 struct afs_call *call;
529 size_t namesz, reqsz, padsz;
535 padsz = (4 - (namesz & 3)) & 3;
536 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
538 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile,
539 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
541 return afs_op_nomem(op);
543 /* marshall the parameters */
545 *bp++ = htonl(FSCREATEFILE);
546 *bp++ = htonl(dvp->fid.vid);
547 *bp++ = htonl(dvp->fid.vnode);
548 *bp++ = htonl(dvp->fid.unique);
549 *bp++ = htonl(namesz);
550 memcpy(bp, name->name, namesz);
551 bp = (void *) bp + namesz;
553 memset(bp, 0, padsz);
554 bp = (void *) bp + padsz;
556 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
557 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
558 *bp++ = 0; /* owner */
559 *bp++ = 0; /* group */
560 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
561 *bp++ = 0; /* segment size */
563 trace_afs_make_fs_call1(call, &dvp->fid, name);
564 afs_make_op_call(op, call, GFP_NOFS);
567 static const struct afs_call_type afs_RXFSMakeDir = {
568 .name = "FS.MakeDir",
569 .op = afs_FS_MakeDir,
570 .deliver = afs_deliver_fs_create_vnode,
571 .destructor = afs_flat_call_destructor,
575 * Create a new directory
577 void afs_fs_make_dir(struct afs_operation *op)
579 const struct qstr *name = &op->dentry->d_name;
580 struct afs_vnode_param *dvp = &op->file[0];
581 struct afs_call *call;
582 size_t namesz, reqsz, padsz;
588 padsz = (4 - (namesz & 3)) & 3;
589 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
591 call = afs_alloc_flat_call(op->net, &afs_RXFSMakeDir,
592 reqsz, (3 + 21 + 21 + 3 + 6) * 4);
594 return afs_op_nomem(op);
596 /* marshall the parameters */
598 *bp++ = htonl(FSMAKEDIR);
599 *bp++ = htonl(dvp->fid.vid);
600 *bp++ = htonl(dvp->fid.vnode);
601 *bp++ = htonl(dvp->fid.unique);
602 *bp++ = htonl(namesz);
603 memcpy(bp, name->name, namesz);
604 bp = (void *) bp + namesz;
606 memset(bp, 0, padsz);
607 bp = (void *) bp + padsz;
609 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
610 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
611 *bp++ = 0; /* owner */
612 *bp++ = 0; /* group */
613 *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
614 *bp++ = 0; /* segment size */
616 trace_afs_make_fs_call1(call, &dvp->fid, name);
617 afs_make_op_call(op, call, GFP_NOFS);
621 * Deliver reply data to any operation that returns status and volume sync.
623 static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
625 struct afs_operation *op = call->op;
626 struct afs_vnode_param *vp = &op->file[0];
630 ret = afs_transfer_reply(call);
634 /* unmarshall the reply once we've received all of it */
636 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
637 xdr_decode_AFSVolSync(&bp, &op->volsync);
639 _leave(" = 0 [done]");
644 * FS.RemoveFile operation type
646 static const struct afs_call_type afs_RXFSRemoveFile = {
647 .name = "FS.RemoveFile",
648 .op = afs_FS_RemoveFile,
649 .deliver = afs_deliver_fs_file_status_and_vol,
650 .destructor = afs_flat_call_destructor,
656 void afs_fs_remove_file(struct afs_operation *op)
658 const struct qstr *name = &op->dentry->d_name;
659 struct afs_vnode_param *dvp = &op->file[0];
660 struct afs_call *call;
661 size_t namesz, reqsz, padsz;
667 padsz = (4 - (namesz & 3)) & 3;
668 reqsz = (5 * 4) + namesz + padsz;
670 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveFile,
671 reqsz, (21 + 6) * 4);
673 return afs_op_nomem(op);
675 /* marshall the parameters */
677 *bp++ = htonl(FSREMOVEFILE);
678 *bp++ = htonl(dvp->fid.vid);
679 *bp++ = htonl(dvp->fid.vnode);
680 *bp++ = htonl(dvp->fid.unique);
681 *bp++ = htonl(namesz);
682 memcpy(bp, name->name, namesz);
683 bp = (void *) bp + namesz;
685 memset(bp, 0, padsz);
686 bp = (void *) bp + padsz;
689 trace_afs_make_fs_call1(call, &dvp->fid, name);
690 afs_make_op_call(op, call, GFP_NOFS);
693 static const struct afs_call_type afs_RXFSRemoveDir = {
694 .name = "FS.RemoveDir",
695 .op = afs_FS_RemoveDir,
696 .deliver = afs_deliver_fs_file_status_and_vol,
697 .destructor = afs_flat_call_destructor,
701 * Remove a directory.
703 void afs_fs_remove_dir(struct afs_operation *op)
705 const struct qstr *name = &op->dentry->d_name;
706 struct afs_vnode_param *dvp = &op->file[0];
707 struct afs_call *call;
708 size_t namesz, reqsz, padsz;
714 padsz = (4 - (namesz & 3)) & 3;
715 reqsz = (5 * 4) + namesz + padsz;
717 call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveDir,
718 reqsz, (21 + 6) * 4);
720 return afs_op_nomem(op);
722 /* marshall the parameters */
724 *bp++ = htonl(FSREMOVEDIR);
725 *bp++ = htonl(dvp->fid.vid);
726 *bp++ = htonl(dvp->fid.vnode);
727 *bp++ = htonl(dvp->fid.unique);
728 *bp++ = htonl(namesz);
729 memcpy(bp, name->name, namesz);
730 bp = (void *) bp + namesz;
732 memset(bp, 0, padsz);
733 bp = (void *) bp + padsz;
736 trace_afs_make_fs_call1(call, &dvp->fid, name);
737 afs_make_op_call(op, call, GFP_NOFS);
741 * deliver reply data to an FS.Link
743 static int afs_deliver_fs_link(struct afs_call *call)
745 struct afs_operation *op = call->op;
746 struct afs_vnode_param *dvp = &op->file[0];
747 struct afs_vnode_param *vp = &op->file[1];
751 _enter("{%u}", call->unmarshall);
753 ret = afs_transfer_reply(call);
757 /* unmarshall the reply once we've received all of it */
759 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
760 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
761 xdr_decode_AFSVolSync(&bp, &op->volsync);
763 _leave(" = 0 [done]");
768 * FS.Link operation type
770 static const struct afs_call_type afs_RXFSLink = {
773 .deliver = afs_deliver_fs_link,
774 .destructor = afs_flat_call_destructor,
780 void afs_fs_link(struct afs_operation *op)
782 const struct qstr *name = &op->dentry->d_name;
783 struct afs_vnode_param *dvp = &op->file[0];
784 struct afs_vnode_param *vp = &op->file[1];
785 struct afs_call *call;
786 size_t namesz, reqsz, padsz;
792 padsz = (4 - (namesz & 3)) & 3;
793 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
795 call = afs_alloc_flat_call(op->net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
797 return afs_op_nomem(op);
799 /* marshall the parameters */
801 *bp++ = htonl(FSLINK);
802 *bp++ = htonl(dvp->fid.vid);
803 *bp++ = htonl(dvp->fid.vnode);
804 *bp++ = htonl(dvp->fid.unique);
805 *bp++ = htonl(namesz);
806 memcpy(bp, name->name, namesz);
807 bp = (void *) bp + namesz;
809 memset(bp, 0, padsz);
810 bp = (void *) bp + padsz;
812 *bp++ = htonl(vp->fid.vid);
813 *bp++ = htonl(vp->fid.vnode);
814 *bp++ = htonl(vp->fid.unique);
816 trace_afs_make_fs_call1(call, &vp->fid, name);
817 afs_make_op_call(op, call, GFP_NOFS);
821 * deliver reply data to an FS.Symlink
823 static int afs_deliver_fs_symlink(struct afs_call *call)
825 struct afs_operation *op = call->op;
826 struct afs_vnode_param *dvp = &op->file[0];
827 struct afs_vnode_param *vp = &op->file[1];
831 _enter("{%u}", call->unmarshall);
833 ret = afs_transfer_reply(call);
837 /* unmarshall the reply once we've received all of it */
839 xdr_decode_AFSFid(&bp, &vp->fid);
840 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
841 xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
842 xdr_decode_AFSVolSync(&bp, &op->volsync);
844 _leave(" = 0 [done]");
849 * FS.Symlink operation type
851 static const struct afs_call_type afs_RXFSSymlink = {
852 .name = "FS.Symlink",
853 .op = afs_FS_Symlink,
854 .deliver = afs_deliver_fs_symlink,
855 .destructor = afs_flat_call_destructor,
859 * create a symbolic link
861 void afs_fs_symlink(struct afs_operation *op)
863 const struct qstr *name = &op->dentry->d_name;
864 struct afs_vnode_param *dvp = &op->file[0];
865 struct afs_call *call;
866 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
872 padsz = (4 - (namesz & 3)) & 3;
874 c_namesz = strlen(op->create.symlink);
875 c_padsz = (4 - (c_namesz & 3)) & 3;
877 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
879 call = afs_alloc_flat_call(op->net, &afs_RXFSSymlink, reqsz,
880 (3 + 21 + 21 + 6) * 4);
882 return afs_op_nomem(op);
884 /* marshall the parameters */
886 *bp++ = htonl(FSSYMLINK);
887 *bp++ = htonl(dvp->fid.vid);
888 *bp++ = htonl(dvp->fid.vnode);
889 *bp++ = htonl(dvp->fid.unique);
890 *bp++ = htonl(namesz);
891 memcpy(bp, name->name, namesz);
892 bp = (void *) bp + namesz;
894 memset(bp, 0, padsz);
895 bp = (void *) bp + padsz;
897 *bp++ = htonl(c_namesz);
898 memcpy(bp, op->create.symlink, c_namesz);
899 bp = (void *) bp + c_namesz;
901 memset(bp, 0, c_padsz);
902 bp = (void *) bp + c_padsz;
904 *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
905 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
906 *bp++ = 0; /* owner */
907 *bp++ = 0; /* group */
908 *bp++ = htonl(S_IRWXUGO); /* unix mode */
909 *bp++ = 0; /* segment size */
911 trace_afs_make_fs_call1(call, &dvp->fid, name);
912 afs_make_op_call(op, call, GFP_NOFS);
916 * deliver reply data to an FS.Rename
918 static int afs_deliver_fs_rename(struct afs_call *call)
920 struct afs_operation *op = call->op;
921 struct afs_vnode_param *orig_dvp = &op->file[0];
922 struct afs_vnode_param *new_dvp = &op->file[1];
926 ret = afs_transfer_reply(call);
931 /* If the two dirs are the same, we have two copies of the same status
932 * report, so we just decode it twice.
934 xdr_decode_AFSFetchStatus(&bp, call, &orig_dvp->scb);
935 xdr_decode_AFSFetchStatus(&bp, call, &new_dvp->scb);
936 xdr_decode_AFSVolSync(&bp, &op->volsync);
938 _leave(" = 0 [done]");
943 * FS.Rename operation type
945 static const struct afs_call_type afs_RXFSRename = {
948 .deliver = afs_deliver_fs_rename,
949 .destructor = afs_flat_call_destructor,
953 * Rename/move a file or directory.
955 void afs_fs_rename(struct afs_operation *op)
957 struct afs_vnode_param *orig_dvp = &op->file[0];
958 struct afs_vnode_param *new_dvp = &op->file[1];
959 const struct qstr *orig_name = &op->dentry->d_name;
960 const struct qstr *new_name = &op->dentry_2->d_name;
961 struct afs_call *call;
962 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
967 o_namesz = orig_name->len;
968 o_padsz = (4 - (o_namesz & 3)) & 3;
970 n_namesz = new_name->len;
971 n_padsz = (4 - (n_namesz & 3)) & 3;
974 4 + o_namesz + o_padsz +
976 4 + n_namesz + n_padsz;
978 call = afs_alloc_flat_call(op->net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
980 return afs_op_nomem(op);
982 /* marshall the parameters */
984 *bp++ = htonl(FSRENAME);
985 *bp++ = htonl(orig_dvp->fid.vid);
986 *bp++ = htonl(orig_dvp->fid.vnode);
987 *bp++ = htonl(orig_dvp->fid.unique);
988 *bp++ = htonl(o_namesz);
989 memcpy(bp, orig_name->name, o_namesz);
990 bp = (void *) bp + o_namesz;
992 memset(bp, 0, o_padsz);
993 bp = (void *) bp + o_padsz;
996 *bp++ = htonl(new_dvp->fid.vid);
997 *bp++ = htonl(new_dvp->fid.vnode);
998 *bp++ = htonl(new_dvp->fid.unique);
999 *bp++ = htonl(n_namesz);
1000 memcpy(bp, new_name->name, n_namesz);
1001 bp = (void *) bp + n_namesz;
1003 memset(bp, 0, n_padsz);
1004 bp = (void *) bp + n_padsz;
1007 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1008 afs_make_op_call(op, call, GFP_NOFS);
1012 * Deliver reply data to FS.StoreData or FS.StoreStatus
1014 static int afs_deliver_fs_store_data(struct afs_call *call)
1016 struct afs_operation *op = call->op;
1017 struct afs_vnode_param *vp = &op->file[0];
1023 ret = afs_transfer_reply(call);
1027 /* unmarshall the reply once we've received all of it */
1029 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
1030 xdr_decode_AFSVolSync(&bp, &op->volsync);
1032 _leave(" = 0 [done]");
1037 * FS.StoreData operation type
1039 static const struct afs_call_type afs_RXFSStoreData = {
1040 .name = "FS.StoreData",
1041 .op = afs_FS_StoreData,
1042 .deliver = afs_deliver_fs_store_data,
1043 .destructor = afs_flat_call_destructor,
1046 static const struct afs_call_type afs_RXFSStoreData64 = {
1047 .name = "FS.StoreData64",
1048 .op = afs_FS_StoreData64,
1049 .deliver = afs_deliver_fs_store_data,
1050 .destructor = afs_flat_call_destructor,
1054 * store a set of pages to a very large file
1056 static void afs_fs_store_data64(struct afs_operation *op)
1058 struct afs_vnode_param *vp = &op->file[0];
1059 struct afs_call *call;
1062 _enter(",%x,{%llx:%llu},,",
1063 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1065 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64,
1066 (4 + 6 + 3 * 2) * 4,
1069 return afs_op_nomem(op);
1071 call->write_iter = op->store.write_iter;
1073 /* marshall the parameters */
1075 *bp++ = htonl(FSSTOREDATA64);
1076 *bp++ = htonl(vp->fid.vid);
1077 *bp++ = htonl(vp->fid.vnode);
1078 *bp++ = htonl(vp->fid.unique);
1080 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1081 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
1082 *bp++ = 0; /* owner */
1083 *bp++ = 0; /* group */
1084 *bp++ = 0; /* unix mode */
1085 *bp++ = 0; /* segment size */
1087 *bp++ = htonl(upper_32_bits(op->store.pos));
1088 *bp++ = htonl(lower_32_bits(op->store.pos));
1089 *bp++ = htonl(upper_32_bits(op->store.size));
1090 *bp++ = htonl(lower_32_bits(op->store.size));
1091 *bp++ = htonl(upper_32_bits(op->store.i_size));
1092 *bp++ = htonl(lower_32_bits(op->store.i_size));
1094 trace_afs_make_fs_call(call, &vp->fid);
1095 afs_make_op_call(op, call, GFP_NOFS);
1099 * Write data to a file on the server.
1101 void afs_fs_store_data(struct afs_operation *op)
1103 struct afs_vnode_param *vp = &op->file[0];
1104 struct afs_call *call;
1107 _enter(",%x,{%llx:%llu},,",
1108 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1110 _debug("size %llx, at %llx, i_size %llx",
1111 (unsigned long long)op->store.size,
1112 (unsigned long long)op->store.pos,
1113 (unsigned long long)op->store.i_size);
1115 if (upper_32_bits(op->store.pos) ||
1116 upper_32_bits(op->store.size) ||
1117 upper_32_bits(op->store.i_size))
1118 return afs_fs_store_data64(op);
1120 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData,
1124 return afs_op_nomem(op);
1126 call->write_iter = op->store.write_iter;
1128 /* marshall the parameters */
1130 *bp++ = htonl(FSSTOREDATA);
1131 *bp++ = htonl(vp->fid.vid);
1132 *bp++ = htonl(vp->fid.vnode);
1133 *bp++ = htonl(vp->fid.unique);
1135 *bp++ = htonl(AFS_SET_MTIME); /* mask */
1136 *bp++ = htonl(op->mtime.tv_sec); /* mtime */
1137 *bp++ = 0; /* owner */
1138 *bp++ = 0; /* group */
1139 *bp++ = 0; /* unix mode */
1140 *bp++ = 0; /* segment size */
1142 *bp++ = htonl(lower_32_bits(op->store.pos));
1143 *bp++ = htonl(lower_32_bits(op->store.size));
1144 *bp++ = htonl(lower_32_bits(op->store.i_size));
1146 trace_afs_make_fs_call(call, &vp->fid);
1147 afs_make_op_call(op, call, GFP_NOFS);
1151 * FS.StoreStatus operation type
1153 static const struct afs_call_type afs_RXFSStoreStatus = {
1154 .name = "FS.StoreStatus",
1155 .op = afs_FS_StoreStatus,
1156 .deliver = afs_deliver_fs_store_data,
1157 .destructor = afs_flat_call_destructor,
1160 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1161 .name = "FS.StoreData",
1162 .op = afs_FS_StoreData,
1163 .deliver = afs_deliver_fs_store_data,
1164 .destructor = afs_flat_call_destructor,
1167 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1168 .name = "FS.StoreData64",
1169 .op = afs_FS_StoreData64,
1170 .deliver = afs_deliver_fs_store_data,
1171 .destructor = afs_flat_call_destructor,
1175 * set the attributes on a very large file, using FS.StoreData rather than
1176 * FS.StoreStatus so as to alter the file size also
1178 static void afs_fs_setattr_size64(struct afs_operation *op)
1180 struct afs_vnode_param *vp = &op->file[0];
1181 struct afs_call *call;
1182 struct iattr *attr = op->setattr.attr;
1185 _enter(",%x,{%llx:%llu},,",
1186 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1188 ASSERT(attr->ia_valid & ATTR_SIZE);
1190 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64_as_Status,
1191 (4 + 6 + 3 * 2) * 4,
1194 return afs_op_nomem(op);
1196 /* marshall the parameters */
1198 *bp++ = htonl(FSSTOREDATA64);
1199 *bp++ = htonl(vp->fid.vid);
1200 *bp++ = htonl(vp->fid.vnode);
1201 *bp++ = htonl(vp->fid.unique);
1203 xdr_encode_AFS_StoreStatus(&bp, attr);
1205 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* position of start of write */
1206 *bp++ = htonl(lower_32_bits(attr->ia_size));
1207 *bp++ = 0; /* size of write */
1209 *bp++ = htonl(upper_32_bits(attr->ia_size)); /* new file length */
1210 *bp++ = htonl(lower_32_bits(attr->ia_size));
1212 trace_afs_make_fs_call(call, &vp->fid);
1213 afs_make_op_call(op, call, GFP_NOFS);
1217 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1218 * so as to alter the file size also
1220 static void afs_fs_setattr_size(struct afs_operation *op)
1222 struct afs_vnode_param *vp = &op->file[0];
1223 struct afs_call *call;
1224 struct iattr *attr = op->setattr.attr;
1227 _enter(",%x,{%llx:%llu},,",
1228 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1230 ASSERT(attr->ia_valid & ATTR_SIZE);
1231 if (upper_32_bits(attr->ia_size))
1232 return afs_fs_setattr_size64(op);
1234 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData_as_Status,
1238 return afs_op_nomem(op);
1240 /* marshall the parameters */
1242 *bp++ = htonl(FSSTOREDATA);
1243 *bp++ = htonl(vp->fid.vid);
1244 *bp++ = htonl(vp->fid.vnode);
1245 *bp++ = htonl(vp->fid.unique);
1247 xdr_encode_AFS_StoreStatus(&bp, attr);
1249 *bp++ = htonl(attr->ia_size); /* position of start of write */
1250 *bp++ = 0; /* size of write */
1251 *bp++ = htonl(attr->ia_size); /* new file length */
1253 trace_afs_make_fs_call(call, &vp->fid);
1254 afs_make_op_call(op, call, GFP_NOFS);
1258 * set the attributes on a file, using FS.StoreData if there's a change in file
1259 * size, and FS.StoreStatus otherwise
1261 void afs_fs_setattr(struct afs_operation *op)
1263 struct afs_vnode_param *vp = &op->file[0];
1264 struct afs_call *call;
1265 struct iattr *attr = op->setattr.attr;
1268 if (attr->ia_valid & ATTR_SIZE)
1269 return afs_fs_setattr_size(op);
1271 _enter(",%x,{%llx:%llu},,",
1272 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1274 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreStatus,
1278 return afs_op_nomem(op);
1280 /* marshall the parameters */
1282 *bp++ = htonl(FSSTORESTATUS);
1283 *bp++ = htonl(vp->fid.vid);
1284 *bp++ = htonl(vp->fid.vnode);
1285 *bp++ = htonl(vp->fid.unique);
1287 xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr);
1289 trace_afs_make_fs_call(call, &vp->fid);
1290 afs_make_op_call(op, call, GFP_NOFS);
1294 * deliver reply data to an FS.GetVolumeStatus
1296 static int afs_deliver_fs_get_volume_status(struct afs_call *call)
1298 struct afs_operation *op = call->op;
1304 _enter("{%u}", call->unmarshall);
1306 switch (call->unmarshall) {
1309 afs_extract_to_buf(call, 12 * 4);
1312 /* extract the returned status record */
1314 _debug("extract status");
1315 ret = afs_extract_data(call, true);
1320 xdr_decode_AFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1322 afs_extract_to_tmp(call);
1325 /* extract the volume name length */
1327 ret = afs_extract_data(call, true);
1331 call->count = ntohl(call->tmp);
1332 _debug("volname length: %u", call->count);
1333 if (call->count >= AFSNAMEMAX)
1334 return afs_protocol_error(call, afs_eproto_volname_len);
1335 size = (call->count + 3) & ~3; /* It's padded */
1336 afs_extract_to_buf(call, size);
1340 /* extract the volume name */
1342 _debug("extract volname");
1343 ret = afs_extract_data(call, true);
1349 _debug("volname '%s'", p);
1350 afs_extract_to_tmp(call);
1354 /* extract the offline message length */
1356 ret = afs_extract_data(call, true);
1360 call->count = ntohl(call->tmp);
1361 _debug("offline msg length: %u", call->count);
1362 if (call->count >= AFSNAMEMAX)
1363 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1364 size = (call->count + 3) & ~3; /* It's padded */
1365 afs_extract_to_buf(call, size);
1369 /* extract the offline message */
1371 _debug("extract offline");
1372 ret = afs_extract_data(call, true);
1378 _debug("offline '%s'", p);
1380 afs_extract_to_tmp(call);
1384 /* extract the message of the day length */
1386 ret = afs_extract_data(call, true);
1390 call->count = ntohl(call->tmp);
1391 _debug("motd length: %u", call->count);
1392 if (call->count >= AFSNAMEMAX)
1393 return afs_protocol_error(call, afs_eproto_motd_len);
1394 size = (call->count + 3) & ~3; /* It's padded */
1395 afs_extract_to_buf(call, size);
1399 /* extract the message of the day */
1401 _debug("extract motd");
1402 ret = afs_extract_data(call, false);
1408 _debug("motd '%s'", p);
1416 _leave(" = 0 [done]");
1421 * FS.GetVolumeStatus operation type
1423 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1424 .name = "FS.GetVolumeStatus",
1425 .op = afs_FS_GetVolumeStatus,
1426 .deliver = afs_deliver_fs_get_volume_status,
1427 .destructor = afs_flat_call_destructor,
1431 * fetch the status of a volume
1433 void afs_fs_get_volume_status(struct afs_operation *op)
1435 struct afs_vnode_param *vp = &op->file[0];
1436 struct afs_call *call;
1441 call = afs_alloc_flat_call(op->net, &afs_RXFSGetVolumeStatus, 2 * 4,
1442 max(12 * 4, AFSOPAQUEMAX + 1));
1444 return afs_op_nomem(op);
1446 /* marshall the parameters */
1448 bp[0] = htonl(FSGETVOLUMESTATUS);
1449 bp[1] = htonl(vp->fid.vid);
1451 trace_afs_make_fs_call(call, &vp->fid);
1452 afs_make_op_call(op, call, GFP_NOFS);
1456 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1458 static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
1460 struct afs_operation *op = call->op;
1464 _enter("{%u}", call->unmarshall);
1466 ret = afs_transfer_reply(call);
1470 /* unmarshall the reply once we've received all of it */
1472 xdr_decode_AFSVolSync(&bp, &op->volsync);
1474 _leave(" = 0 [done]");
1479 * FS.SetLock operation type
1481 static const struct afs_call_type afs_RXFSSetLock = {
1482 .name = "FS.SetLock",
1483 .op = afs_FS_SetLock,
1484 .deliver = afs_deliver_fs_xxxx_lock,
1485 .done = afs_lock_op_done,
1486 .destructor = afs_flat_call_destructor,
1490 * FS.ExtendLock operation type
1492 static const struct afs_call_type afs_RXFSExtendLock = {
1493 .name = "FS.ExtendLock",
1494 .op = afs_FS_ExtendLock,
1495 .deliver = afs_deliver_fs_xxxx_lock,
1496 .done = afs_lock_op_done,
1497 .destructor = afs_flat_call_destructor,
1501 * FS.ReleaseLock operation type
1503 static const struct afs_call_type afs_RXFSReleaseLock = {
1504 .name = "FS.ReleaseLock",
1505 .op = afs_FS_ReleaseLock,
1506 .deliver = afs_deliver_fs_xxxx_lock,
1507 .destructor = afs_flat_call_destructor,
1511 * Set a lock on a file
1513 void afs_fs_set_lock(struct afs_operation *op)
1515 struct afs_vnode_param *vp = &op->file[0];
1516 struct afs_call *call;
1521 call = afs_alloc_flat_call(op->net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
1523 return afs_op_nomem(op);
1525 /* marshall the parameters */
1527 *bp++ = htonl(FSSETLOCK);
1528 *bp++ = htonl(vp->fid.vid);
1529 *bp++ = htonl(vp->fid.vnode);
1530 *bp++ = htonl(vp->fid.unique);
1531 *bp++ = htonl(op->lock.type);
1533 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1534 afs_make_op_call(op, call, GFP_NOFS);
1538 * extend a lock on a file
1540 void afs_fs_extend_lock(struct afs_operation *op)
1542 struct afs_vnode_param *vp = &op->file[0];
1543 struct afs_call *call;
1548 call = afs_alloc_flat_call(op->net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
1550 return afs_op_nomem(op);
1552 /* marshall the parameters */
1554 *bp++ = htonl(FSEXTENDLOCK);
1555 *bp++ = htonl(vp->fid.vid);
1556 *bp++ = htonl(vp->fid.vnode);
1557 *bp++ = htonl(vp->fid.unique);
1559 trace_afs_make_fs_call(call, &vp->fid);
1560 afs_make_op_call(op, call, GFP_NOFS);
1564 * release a lock on a file
1566 void afs_fs_release_lock(struct afs_operation *op)
1568 struct afs_vnode_param *vp = &op->file[0];
1569 struct afs_call *call;
1574 call = afs_alloc_flat_call(op->net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1576 return afs_op_nomem(op);
1578 /* marshall the parameters */
1580 *bp++ = htonl(FSRELEASELOCK);
1581 *bp++ = htonl(vp->fid.vid);
1582 *bp++ = htonl(vp->fid.vnode);
1583 *bp++ = htonl(vp->fid.unique);
1585 trace_afs_make_fs_call(call, &vp->fid);
1586 afs_make_op_call(op, call, GFP_NOFS);
1590 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1592 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
1594 return afs_transfer_reply(call);
1598 * FS.GiveUpAllCallBacks operation type
1600 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
1601 .name = "FS.GiveUpAllCallBacks",
1602 .op = afs_FS_GiveUpAllCallBacks,
1603 .deliver = afs_deliver_fs_give_up_all_callbacks,
1604 .destructor = afs_flat_call_destructor,
1608 * Flush all the callbacks we have on a server.
1610 int afs_fs_give_up_all_callbacks(struct afs_net *net,
1611 struct afs_server *server,
1612 struct afs_addr_cursor *ac,
1615 struct afs_call *call;
1620 call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
1626 /* marshall the parameters */
1628 *bp++ = htonl(FSGIVEUPALLCALLBACKS);
1630 call->server = afs_use_server(server, afs_server_trace_give_up_cb);
1631 afs_make_call(ac, call, GFP_NOFS);
1632 return afs_wait_for_call_to_complete(call, ac);
1636 * Deliver reply data to an FS.GetCapabilities operation.
1638 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
1643 _enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
1645 switch (call->unmarshall) {
1647 afs_extract_to_tmp(call);
1651 /* Extract the capabilities word count */
1653 ret = afs_extract_data(call, true);
1657 count = ntohl(call->tmp);
1659 call->count = count;
1660 call->count2 = count;
1661 afs_extract_discard(call, count * sizeof(__be32));
1665 /* Extract capabilities words */
1667 ret = afs_extract_data(call, false);
1671 /* TODO: Examine capabilities */
1677 _leave(" = 0 [done]");
1682 * FS.GetCapabilities operation type
1684 static const struct afs_call_type afs_RXFSGetCapabilities = {
1685 .name = "FS.GetCapabilities",
1686 .op = afs_FS_GetCapabilities,
1687 .deliver = afs_deliver_fs_get_capabilities,
1688 .done = afs_fileserver_probe_result,
1689 .destructor = afs_flat_call_destructor,
1693 * Probe a fileserver for the capabilities that it supports. This RPC can
1694 * reply with up to 196 words. The operation is asynchronous and if we managed
1695 * to allocate a call, true is returned the result is delivered through the
1696 * ->done() - otherwise we return false to indicate we didn't even try.
1698 bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
1699 struct afs_addr_cursor *ac, struct key *key)
1701 struct afs_call *call;
1706 call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
1711 call->server = afs_use_server(server, afs_server_trace_get_caps);
1712 call->upgrade = true;
1714 call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
1716 /* marshall the parameters */
1718 *bp++ = htonl(FSGETCAPABILITIES);
1720 trace_afs_make_fs_call(call, NULL);
1721 afs_make_call(ac, call, GFP_NOFS);
1727 * Deliver reply data to an FS.InlineBulkStatus call
1729 static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
1731 struct afs_operation *op = call->op;
1732 struct afs_status_cb *scb;
1737 _enter("{%u}", call->unmarshall);
1739 switch (call->unmarshall) {
1741 afs_extract_to_tmp(call);
1745 /* Extract the file status count and array in two steps */
1747 _debug("extract status count");
1748 ret = afs_extract_data(call, true);
1752 tmp = ntohl(call->tmp);
1753 _debug("status count: %u/%u", tmp, op->nr_files);
1754 if (tmp != op->nr_files)
1755 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1760 afs_extract_to_buf(call, 21 * sizeof(__be32));
1764 _debug("extract status array %u", call->count);
1765 ret = afs_extract_data(call, true);
1769 switch (call->count) {
1771 scb = &op->file[0].scb;
1774 scb = &op->file[1].scb;
1777 scb = &op->more_files[call->count - 2].scb;
1782 xdr_decode_AFSFetchStatus(&bp, call, scb);
1785 if (call->count < op->nr_files)
1790 afs_extract_to_tmp(call);
1793 /* Extract the callback count and array in two steps */
1795 _debug("extract CB count");
1796 ret = afs_extract_data(call, true);
1800 tmp = ntohl(call->tmp);
1801 _debug("CB count: %u", tmp);
1802 if (tmp != op->nr_files)
1803 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1807 afs_extract_to_buf(call, 3 * sizeof(__be32));
1811 _debug("extract CB array");
1812 ret = afs_extract_data(call, true);
1816 _debug("unmarshall CB array");
1817 switch (call->count) {
1819 scb = &op->file[0].scb;
1822 scb = &op->file[1].scb;
1825 scb = &op->more_files[call->count - 2].scb;
1830 xdr_decode_AFSCallBack(&bp, call, scb);
1832 if (call->count < op->nr_files)
1835 afs_extract_to_buf(call, 6 * sizeof(__be32));
1840 ret = afs_extract_data(call, false);
1845 xdr_decode_AFSVolSync(&bp, &op->volsync);
1853 _leave(" = 0 [done]");
1857 static void afs_done_fs_inline_bulk_status(struct afs_call *call)
1859 if (call->error == -ECONNABORTED &&
1860 call->abort_code == RX_INVALID_OPERATION) {
1861 set_bit(AFS_SERVER_FL_NO_IBULK, &call->server->flags);
1863 set_bit(AFS_VOLUME_MAYBE_NO_IBULK, &call->op->volume->flags);
1868 * FS.InlineBulkStatus operation type
1870 static const struct afs_call_type afs_RXFSInlineBulkStatus = {
1871 .name = "FS.InlineBulkStatus",
1872 .op = afs_FS_InlineBulkStatus,
1873 .deliver = afs_deliver_fs_inline_bulk_status,
1874 .done = afs_done_fs_inline_bulk_status,
1875 .destructor = afs_flat_call_destructor,
1879 * Fetch the status information for up to 50 files
1881 void afs_fs_inline_bulk_status(struct afs_operation *op)
1883 struct afs_vnode_param *dvp = &op->file[0];
1884 struct afs_vnode_param *vp = &op->file[1];
1885 struct afs_call *call;
1889 if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) {
1890 op->error = -ENOTSUPP;
1894 _enter(",%x,{%llx:%llu},%u",
1895 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1897 call = afs_alloc_flat_call(op->net, &afs_RXFSInlineBulkStatus,
1898 (2 + op->nr_files * 3) * 4,
1901 return afs_op_nomem(op);
1903 /* marshall the parameters */
1905 *bp++ = htonl(FSINLINEBULKSTATUS);
1906 *bp++ = htonl(op->nr_files);
1907 *bp++ = htonl(dvp->fid.vid);
1908 *bp++ = htonl(dvp->fid.vnode);
1909 *bp++ = htonl(dvp->fid.unique);
1910 *bp++ = htonl(vp->fid.vid);
1911 *bp++ = htonl(vp->fid.vnode);
1912 *bp++ = htonl(vp->fid.unique);
1913 for (i = 0; i < op->nr_files - 2; i++) {
1914 *bp++ = htonl(op->more_files[i].fid.vid);
1915 *bp++ = htonl(op->more_files[i].fid.vnode);
1916 *bp++ = htonl(op->more_files[i].fid.unique);
1919 trace_afs_make_fs_call(call, &vp->fid);
1920 afs_make_op_call(op, call, GFP_NOFS);
1924 * deliver reply data to an FS.FetchACL
1926 static int afs_deliver_fs_fetch_acl(struct afs_call *call)
1928 struct afs_operation *op = call->op;
1929 struct afs_vnode_param *vp = &op->file[0];
1930 struct afs_acl *acl;
1935 _enter("{%u}", call->unmarshall);
1937 switch (call->unmarshall) {
1939 afs_extract_to_tmp(call);
1943 /* extract the returned data length */
1945 ret = afs_extract_data(call, true);
1949 size = call->count2 = ntohl(call->tmp);
1950 size = round_up(size, 4);
1952 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1956 acl->size = call->count2;
1957 afs_extract_begin(call, acl->data, size);
1961 /* extract the returned data */
1963 ret = afs_extract_data(call, true);
1967 afs_extract_to_buf(call, (21 + 6) * 4);
1971 /* extract the metadata */
1973 ret = afs_extract_data(call, false);
1978 xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
1979 xdr_decode_AFSVolSync(&bp, &op->volsync);
1987 _leave(" = 0 [done]");
1992 * FS.FetchACL operation type
1994 static const struct afs_call_type afs_RXFSFetchACL = {
1995 .name = "FS.FetchACL",
1996 .op = afs_FS_FetchACL,
1997 .deliver = afs_deliver_fs_fetch_acl,
2001 * Fetch the ACL for a file.
2003 void afs_fs_fetch_acl(struct afs_operation *op)
2005 struct afs_vnode_param *vp = &op->file[0];
2006 struct afs_call *call;
2009 _enter(",%x,{%llx:%llu},,",
2010 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
2012 call = afs_alloc_flat_call(op->net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
2014 return afs_op_nomem(op);
2016 /* marshall the parameters */
2018 bp[0] = htonl(FSFETCHACL);
2019 bp[1] = htonl(vp->fid.vid);
2020 bp[2] = htonl(vp->fid.vnode);
2021 bp[3] = htonl(vp->fid.unique);
2023 trace_afs_make_fs_call(call, &vp->fid);
2024 afs_make_op_call(op, call, GFP_KERNEL);
2028 * FS.StoreACL operation type
2030 static const struct afs_call_type afs_RXFSStoreACL = {
2031 .name = "FS.StoreACL",
2032 .op = afs_FS_StoreACL,
2033 .deliver = afs_deliver_fs_file_status_and_vol,
2034 .destructor = afs_flat_call_destructor,
2038 * Fetch the ACL for a file.
2040 void afs_fs_store_acl(struct afs_operation *op)
2042 struct afs_vnode_param *vp = &op->file[0];
2043 struct afs_call *call;
2044 const struct afs_acl *acl = op->acl;
2048 _enter(",%x,{%llx:%llu},,",
2049 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
2051 size = round_up(acl->size, 4);
2052 call = afs_alloc_flat_call(op->net, &afs_RXFSStoreACL,
2053 5 * 4 + size, (21 + 6) * 4);
2055 return afs_op_nomem(op);
2057 /* marshall the parameters */
2059 bp[0] = htonl(FSSTOREACL);
2060 bp[1] = htonl(vp->fid.vid);
2061 bp[2] = htonl(vp->fid.vnode);
2062 bp[3] = htonl(vp->fid.unique);
2063 bp[4] = htonl(acl->size);
2064 memcpy(&bp[5], acl->data, acl->size);
2065 if (acl->size != size)
2066 memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2068 trace_afs_make_fs_call(call, &vp->fid);
2069 afs_make_op_call(op, call, GFP_KERNEL);