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
->issue_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
);
294 trace_afs_make_fs_call(call
, &vp
->fid
);
295 afs_make_op_call(op
, call
, GFP_NOFS
);
299 * deliver reply data to an FS.FetchData
301 static int afs_deliver_fs_fetch_data(struct afs_call
*call
)
303 struct afs_operation
*op
= call
->op
;
304 struct afs_vnode_param
*vp
= &op
->file
[0];
305 struct afs_read
*req
= op
->fetch
.req
;
310 _enter("{%u,%zu,%zu/%llu}",
311 call
->unmarshall
, call
->iov_len
, iov_iter_count(call
->iter
),
314 switch (call
->unmarshall
) {
318 if (call
->operation_ID
== FSFETCHDATA64
) {
319 afs_extract_to_tmp64(call
);
321 call
->tmp_u
= htonl(0);
322 afs_extract_to_tmp(call
);
326 /* Extract the returned data length into
327 * ->actual_len. This may indicate more or less data than was
328 * requested will be returned.
331 _debug("extract data length");
332 ret
= afs_extract_data(call
, true);
336 req
->actual_len
= be64_to_cpu(call
->tmp64
);
337 _debug("DATA length: %llu", req
->actual_len
);
339 if (req
->actual_len
== 0)
342 call
->iter
= req
->iter
;
343 call
->iov_len
= min(req
->actual_len
, req
->len
);
347 /* extract the returned data */
349 count_before
= call
->iov_len
;
350 _debug("extract data %zu/%llu", count_before
, req
->actual_len
);
352 ret
= afs_extract_data(call
, true);
354 req
->subreq
->transferred
+= count_before
- call
->iov_len
;
355 netfs_read_subreq_progress(req
->subreq
, false);
360 call
->iter
= &call
->def_iter
;
361 if (req
->actual_len
<= req
->len
)
364 /* Discard any excess data the server gave us */
365 afs_extract_discard(call
, req
->actual_len
- req
->len
);
366 call
->unmarshall
= 3;
370 _debug("extract discard %zu/%llu",
371 iov_iter_count(call
->iter
), req
->actual_len
- req
->len
);
373 ret
= afs_extract_data(call
, true);
378 call
->unmarshall
= 4;
379 afs_extract_to_buf(call
, (21 + 3 + 6) * 4);
382 /* extract the metadata */
384 ret
= afs_extract_data(call
, false);
389 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
390 xdr_decode_AFSCallBack(&bp
, call
, &vp
->scb
);
391 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
393 req
->data_version
= vp
->scb
.status
.data_version
;
394 req
->file_size
= vp
->scb
.status
.size
;
403 _leave(" = 0 [done]");
408 * FS.FetchData operation type
410 static const struct afs_call_type afs_RXFSFetchData
= {
411 .name
= "FS.FetchData",
412 .op
= afs_FS_FetchData
,
413 .deliver
= afs_deliver_fs_fetch_data
,
414 .destructor
= afs_flat_call_destructor
,
417 static const struct afs_call_type afs_RXFSFetchData64
= {
418 .name
= "FS.FetchData64",
419 .op
= afs_FS_FetchData64
,
420 .deliver
= afs_deliver_fs_fetch_data
,
421 .destructor
= afs_flat_call_destructor
,
425 * fetch data from a very large file
427 static void afs_fs_fetch_data64(struct afs_operation
*op
)
429 struct afs_vnode_param
*vp
= &op
->file
[0];
430 struct afs_read
*req
= op
->fetch
.req
;
431 struct afs_call
*call
;
436 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSFetchData64
, 32, (21 + 3 + 6) * 4);
438 return afs_op_nomem(op
);
440 /* marshall the parameters */
442 bp
[0] = htonl(FSFETCHDATA64
);
443 bp
[1] = htonl(vp
->fid
.vid
);
444 bp
[2] = htonl(vp
->fid
.vnode
);
445 bp
[3] = htonl(vp
->fid
.unique
);
446 bp
[4] = htonl(upper_32_bits(req
->pos
));
447 bp
[5] = htonl(lower_32_bits(req
->pos
));
449 bp
[7] = htonl(lower_32_bits(req
->len
));
452 trace_afs_make_fs_call(call
, &vp
->fid
);
453 afs_make_op_call(op
, call
, GFP_NOFS
);
457 * fetch data from a file
459 void afs_fs_fetch_data(struct afs_operation
*op
)
461 struct afs_vnode_param
*vp
= &op
->file
[0];
462 struct afs_call
*call
;
463 struct afs_read
*req
= op
->fetch
.req
;
466 if (test_bit(AFS_SERVER_FL_HAS_FS64
, &op
->server
->flags
))
467 return afs_fs_fetch_data64(op
);
471 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSFetchData
, 24, (21 + 3 + 6) * 4);
473 return afs_op_nomem(op
);
475 req
->call_debug_id
= call
->debug_id
;
477 /* marshall the parameters */
479 bp
[0] = htonl(FSFETCHDATA
);
480 bp
[1] = htonl(vp
->fid
.vid
);
481 bp
[2] = htonl(vp
->fid
.vnode
);
482 bp
[3] = htonl(vp
->fid
.unique
);
483 bp
[4] = htonl(lower_32_bits(req
->pos
));
484 bp
[5] = htonl(lower_32_bits(req
->len
));
487 trace_afs_make_fs_call(call
, &vp
->fid
);
488 afs_make_op_call(op
, call
, GFP_NOFS
);
492 * deliver reply data to an FS.CreateFile or an FS.MakeDir
494 static int afs_deliver_fs_create_vnode(struct afs_call
*call
)
496 struct afs_operation
*op
= call
->op
;
497 struct afs_vnode_param
*dvp
= &op
->file
[0];
498 struct afs_vnode_param
*vp
= &op
->file
[1];
502 ret
= afs_transfer_reply(call
);
506 /* unmarshall the reply once we've received all of it */
508 xdr_decode_AFSFid(&bp
, &op
->file
[1].fid
);
509 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
510 xdr_decode_AFSFetchStatus(&bp
, call
, &dvp
->scb
);
511 xdr_decode_AFSCallBack(&bp
, call
, &vp
->scb
);
512 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
514 _leave(" = 0 [done]");
519 * FS.CreateFile and FS.MakeDir operation type
521 static const struct afs_call_type afs_RXFSCreateFile
= {
522 .name
= "FS.CreateFile",
523 .op
= afs_FS_CreateFile
,
524 .deliver
= afs_deliver_fs_create_vnode
,
525 .destructor
= afs_flat_call_destructor
,
531 void afs_fs_create_file(struct afs_operation
*op
)
533 const struct qstr
*name
= &op
->dentry
->d_name
;
534 struct afs_vnode_param
*dvp
= &op
->file
[0];
535 struct afs_call
*call
;
536 size_t namesz
, reqsz
, padsz
;
542 padsz
= (4 - (namesz
& 3)) & 3;
543 reqsz
= (5 * 4) + namesz
+ padsz
+ (6 * 4);
545 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSCreateFile
,
546 reqsz
, (3 + 21 + 21 + 3 + 6) * 4);
548 return afs_op_nomem(op
);
550 /* marshall the parameters */
552 *bp
++ = htonl(FSCREATEFILE
);
553 *bp
++ = htonl(dvp
->fid
.vid
);
554 *bp
++ = htonl(dvp
->fid
.vnode
);
555 *bp
++ = htonl(dvp
->fid
.unique
);
556 *bp
++ = htonl(namesz
);
557 memcpy(bp
, name
->name
, namesz
);
558 bp
= (void *) bp
+ namesz
;
560 memset(bp
, 0, padsz
);
561 bp
= (void *) bp
+ padsz
;
563 *bp
++ = htonl(AFS_SET_MODE
| AFS_SET_MTIME
);
564 *bp
++ = htonl(op
->mtime
.tv_sec
); /* mtime */
565 *bp
++ = 0; /* owner */
566 *bp
++ = 0; /* group */
567 *bp
++ = htonl(op
->create
.mode
& S_IALLUGO
); /* unix mode */
568 *bp
++ = 0; /* segment size */
570 call
->fid
= dvp
->fid
;
571 trace_afs_make_fs_call1(call
, &dvp
->fid
, name
);
572 afs_make_op_call(op
, call
, GFP_NOFS
);
575 static const struct afs_call_type afs_RXFSMakeDir
= {
576 .name
= "FS.MakeDir",
577 .op
= afs_FS_MakeDir
,
578 .deliver
= afs_deliver_fs_create_vnode
,
579 .destructor
= afs_flat_call_destructor
,
583 * Create a new directory
585 void afs_fs_make_dir(struct afs_operation
*op
)
587 const struct qstr
*name
= &op
->dentry
->d_name
;
588 struct afs_vnode_param
*dvp
= &op
->file
[0];
589 struct afs_call
*call
;
590 size_t namesz
, reqsz
, padsz
;
596 padsz
= (4 - (namesz
& 3)) & 3;
597 reqsz
= (5 * 4) + namesz
+ padsz
+ (6 * 4);
599 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSMakeDir
,
600 reqsz
, (3 + 21 + 21 + 3 + 6) * 4);
602 return afs_op_nomem(op
);
604 /* marshall the parameters */
606 *bp
++ = htonl(FSMAKEDIR
);
607 *bp
++ = htonl(dvp
->fid
.vid
);
608 *bp
++ = htonl(dvp
->fid
.vnode
);
609 *bp
++ = htonl(dvp
->fid
.unique
);
610 *bp
++ = htonl(namesz
);
611 memcpy(bp
, name
->name
, namesz
);
612 bp
= (void *) bp
+ namesz
;
614 memset(bp
, 0, padsz
);
615 bp
= (void *) bp
+ padsz
;
617 *bp
++ = htonl(AFS_SET_MODE
| AFS_SET_MTIME
);
618 *bp
++ = htonl(op
->mtime
.tv_sec
); /* mtime */
619 *bp
++ = 0; /* owner */
620 *bp
++ = 0; /* group */
621 *bp
++ = htonl(op
->create
.mode
& S_IALLUGO
); /* unix mode */
622 *bp
++ = 0; /* segment size */
624 call
->fid
= dvp
->fid
;
625 trace_afs_make_fs_call1(call
, &dvp
->fid
, name
);
626 afs_make_op_call(op
, call
, GFP_NOFS
);
630 * Deliver reply data to any operation that returns status and volume sync.
632 static int afs_deliver_fs_file_status_and_vol(struct afs_call
*call
)
634 struct afs_operation
*op
= call
->op
;
635 struct afs_vnode_param
*vp
= &op
->file
[0];
639 ret
= afs_transfer_reply(call
);
643 /* unmarshall the reply once we've received all of it */
645 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
646 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
648 _leave(" = 0 [done]");
653 * FS.RemoveFile operation type
655 static const struct afs_call_type afs_RXFSRemoveFile
= {
656 .name
= "FS.RemoveFile",
657 .op
= afs_FS_RemoveFile
,
658 .deliver
= afs_deliver_fs_file_status_and_vol
,
659 .destructor
= afs_flat_call_destructor
,
665 void afs_fs_remove_file(struct afs_operation
*op
)
667 const struct qstr
*name
= &op
->dentry
->d_name
;
668 struct afs_vnode_param
*dvp
= &op
->file
[0];
669 struct afs_call
*call
;
670 size_t namesz
, reqsz
, padsz
;
676 padsz
= (4 - (namesz
& 3)) & 3;
677 reqsz
= (5 * 4) + namesz
+ padsz
;
679 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSRemoveFile
,
680 reqsz
, (21 + 6) * 4);
682 return afs_op_nomem(op
);
684 /* marshall the parameters */
686 *bp
++ = htonl(FSREMOVEFILE
);
687 *bp
++ = htonl(dvp
->fid
.vid
);
688 *bp
++ = htonl(dvp
->fid
.vnode
);
689 *bp
++ = htonl(dvp
->fid
.unique
);
690 *bp
++ = htonl(namesz
);
691 memcpy(bp
, name
->name
, namesz
);
692 bp
= (void *) bp
+ namesz
;
694 memset(bp
, 0, padsz
);
695 bp
= (void *) bp
+ padsz
;
698 call
->fid
= dvp
->fid
;
699 trace_afs_make_fs_call1(call
, &dvp
->fid
, name
);
700 afs_make_op_call(op
, call
, GFP_NOFS
);
703 static const struct afs_call_type afs_RXFSRemoveDir
= {
704 .name
= "FS.RemoveDir",
705 .op
= afs_FS_RemoveDir
,
706 .deliver
= afs_deliver_fs_file_status_and_vol
,
707 .destructor
= afs_flat_call_destructor
,
711 * Remove a directory.
713 void afs_fs_remove_dir(struct afs_operation
*op
)
715 const struct qstr
*name
= &op
->dentry
->d_name
;
716 struct afs_vnode_param
*dvp
= &op
->file
[0];
717 struct afs_call
*call
;
718 size_t namesz
, reqsz
, padsz
;
724 padsz
= (4 - (namesz
& 3)) & 3;
725 reqsz
= (5 * 4) + namesz
+ padsz
;
727 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSRemoveDir
,
728 reqsz
, (21 + 6) * 4);
730 return afs_op_nomem(op
);
732 /* marshall the parameters */
734 *bp
++ = htonl(FSREMOVEDIR
);
735 *bp
++ = htonl(dvp
->fid
.vid
);
736 *bp
++ = htonl(dvp
->fid
.vnode
);
737 *bp
++ = htonl(dvp
->fid
.unique
);
738 *bp
++ = htonl(namesz
);
739 memcpy(bp
, name
->name
, namesz
);
740 bp
= (void *) bp
+ namesz
;
742 memset(bp
, 0, padsz
);
743 bp
= (void *) bp
+ padsz
;
746 call
->fid
= dvp
->fid
;
747 trace_afs_make_fs_call1(call
, &dvp
->fid
, name
);
748 afs_make_op_call(op
, call
, GFP_NOFS
);
752 * deliver reply data to an FS.Link
754 static int afs_deliver_fs_link(struct afs_call
*call
)
756 struct afs_operation
*op
= call
->op
;
757 struct afs_vnode_param
*dvp
= &op
->file
[0];
758 struct afs_vnode_param
*vp
= &op
->file
[1];
762 _enter("{%u}", call
->unmarshall
);
764 ret
= afs_transfer_reply(call
);
768 /* unmarshall the reply once we've received all of it */
770 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
771 xdr_decode_AFSFetchStatus(&bp
, call
, &dvp
->scb
);
772 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
774 _leave(" = 0 [done]");
779 * FS.Link operation type
781 static const struct afs_call_type afs_RXFSLink
= {
784 .deliver
= afs_deliver_fs_link
,
785 .destructor
= afs_flat_call_destructor
,
791 void afs_fs_link(struct afs_operation
*op
)
793 const struct qstr
*name
= &op
->dentry
->d_name
;
794 struct afs_vnode_param
*dvp
= &op
->file
[0];
795 struct afs_vnode_param
*vp
= &op
->file
[1];
796 struct afs_call
*call
;
797 size_t namesz
, reqsz
, padsz
;
803 padsz
= (4 - (namesz
& 3)) & 3;
804 reqsz
= (5 * 4) + namesz
+ padsz
+ (3 * 4);
806 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSLink
, reqsz
, (21 + 21 + 6) * 4);
808 return afs_op_nomem(op
);
810 /* marshall the parameters */
812 *bp
++ = htonl(FSLINK
);
813 *bp
++ = htonl(dvp
->fid
.vid
);
814 *bp
++ = htonl(dvp
->fid
.vnode
);
815 *bp
++ = htonl(dvp
->fid
.unique
);
816 *bp
++ = htonl(namesz
);
817 memcpy(bp
, name
->name
, namesz
);
818 bp
= (void *) bp
+ namesz
;
820 memset(bp
, 0, padsz
);
821 bp
= (void *) bp
+ padsz
;
823 *bp
++ = htonl(vp
->fid
.vid
);
824 *bp
++ = htonl(vp
->fid
.vnode
);
825 *bp
++ = htonl(vp
->fid
.unique
);
828 trace_afs_make_fs_call1(call
, &vp
->fid
, name
);
829 afs_make_op_call(op
, call
, GFP_NOFS
);
833 * deliver reply data to an FS.Symlink
835 static int afs_deliver_fs_symlink(struct afs_call
*call
)
837 struct afs_operation
*op
= call
->op
;
838 struct afs_vnode_param
*dvp
= &op
->file
[0];
839 struct afs_vnode_param
*vp
= &op
->file
[1];
843 _enter("{%u}", call
->unmarshall
);
845 ret
= afs_transfer_reply(call
);
849 /* unmarshall the reply once we've received all of it */
851 xdr_decode_AFSFid(&bp
, &vp
->fid
);
852 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
853 xdr_decode_AFSFetchStatus(&bp
, call
, &dvp
->scb
);
854 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
856 _leave(" = 0 [done]");
861 * FS.Symlink operation type
863 static const struct afs_call_type afs_RXFSSymlink
= {
864 .name
= "FS.Symlink",
865 .op
= afs_FS_Symlink
,
866 .deliver
= afs_deliver_fs_symlink
,
867 .destructor
= afs_flat_call_destructor
,
871 * create a symbolic link
873 void afs_fs_symlink(struct afs_operation
*op
)
875 const struct qstr
*name
= &op
->dentry
->d_name
;
876 struct afs_vnode_param
*dvp
= &op
->file
[0];
877 struct afs_call
*call
;
878 size_t namesz
, reqsz
, padsz
, c_namesz
, c_padsz
;
884 padsz
= (4 - (namesz
& 3)) & 3;
886 c_namesz
= strlen(op
->create
.symlink
);
887 c_padsz
= (4 - (c_namesz
& 3)) & 3;
889 reqsz
= (6 * 4) + namesz
+ padsz
+ c_namesz
+ c_padsz
+ (6 * 4);
891 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSSymlink
, reqsz
,
892 (3 + 21 + 21 + 6) * 4);
894 return afs_op_nomem(op
);
896 /* marshall the parameters */
898 *bp
++ = htonl(FSSYMLINK
);
899 *bp
++ = htonl(dvp
->fid
.vid
);
900 *bp
++ = htonl(dvp
->fid
.vnode
);
901 *bp
++ = htonl(dvp
->fid
.unique
);
902 *bp
++ = htonl(namesz
);
903 memcpy(bp
, name
->name
, namesz
);
904 bp
= (void *) bp
+ namesz
;
906 memset(bp
, 0, padsz
);
907 bp
= (void *) bp
+ padsz
;
909 *bp
++ = htonl(c_namesz
);
910 memcpy(bp
, op
->create
.symlink
, c_namesz
);
911 bp
= (void *) bp
+ c_namesz
;
913 memset(bp
, 0, c_padsz
);
914 bp
= (void *) bp
+ c_padsz
;
916 *bp
++ = htonl(AFS_SET_MODE
| AFS_SET_MTIME
);
917 *bp
++ = htonl(op
->mtime
.tv_sec
); /* mtime */
918 *bp
++ = 0; /* owner */
919 *bp
++ = 0; /* group */
920 *bp
++ = htonl(S_IRWXUGO
); /* unix mode */
921 *bp
++ = 0; /* segment size */
923 call
->fid
= dvp
->fid
;
924 trace_afs_make_fs_call1(call
, &dvp
->fid
, name
);
925 afs_make_op_call(op
, call
, GFP_NOFS
);
929 * deliver reply data to an FS.Rename
931 static int afs_deliver_fs_rename(struct afs_call
*call
)
933 struct afs_operation
*op
= call
->op
;
934 struct afs_vnode_param
*orig_dvp
= &op
->file
[0];
935 struct afs_vnode_param
*new_dvp
= &op
->file
[1];
939 ret
= afs_transfer_reply(call
);
944 /* If the two dirs are the same, we have two copies of the same status
945 * report, so we just decode it twice.
947 xdr_decode_AFSFetchStatus(&bp
, call
, &orig_dvp
->scb
);
948 xdr_decode_AFSFetchStatus(&bp
, call
, &new_dvp
->scb
);
949 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
951 _leave(" = 0 [done]");
956 * FS.Rename operation type
958 static const struct afs_call_type afs_RXFSRename
= {
961 .deliver
= afs_deliver_fs_rename
,
962 .destructor
= afs_flat_call_destructor
,
966 * Rename/move a file or directory.
968 void afs_fs_rename(struct afs_operation
*op
)
970 struct afs_vnode_param
*orig_dvp
= &op
->file
[0];
971 struct afs_vnode_param
*new_dvp
= &op
->file
[1];
972 const struct qstr
*orig_name
= &op
->dentry
->d_name
;
973 const struct qstr
*new_name
= &op
->dentry_2
->d_name
;
974 struct afs_call
*call
;
975 size_t reqsz
, o_namesz
, o_padsz
, n_namesz
, n_padsz
;
980 o_namesz
= orig_name
->len
;
981 o_padsz
= (4 - (o_namesz
& 3)) & 3;
983 n_namesz
= new_name
->len
;
984 n_padsz
= (4 - (n_namesz
& 3)) & 3;
987 4 + o_namesz
+ o_padsz
+
989 4 + n_namesz
+ n_padsz
;
991 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSRename
, reqsz
, (21 + 21 + 6) * 4);
993 return afs_op_nomem(op
);
995 /* marshall the parameters */
997 *bp
++ = htonl(FSRENAME
);
998 *bp
++ = htonl(orig_dvp
->fid
.vid
);
999 *bp
++ = htonl(orig_dvp
->fid
.vnode
);
1000 *bp
++ = htonl(orig_dvp
->fid
.unique
);
1001 *bp
++ = htonl(o_namesz
);
1002 memcpy(bp
, orig_name
->name
, o_namesz
);
1003 bp
= (void *) bp
+ o_namesz
;
1005 memset(bp
, 0, o_padsz
);
1006 bp
= (void *) bp
+ o_padsz
;
1009 *bp
++ = htonl(new_dvp
->fid
.vid
);
1010 *bp
++ = htonl(new_dvp
->fid
.vnode
);
1011 *bp
++ = htonl(new_dvp
->fid
.unique
);
1012 *bp
++ = htonl(n_namesz
);
1013 memcpy(bp
, new_name
->name
, n_namesz
);
1014 bp
= (void *) bp
+ n_namesz
;
1016 memset(bp
, 0, n_padsz
);
1017 bp
= (void *) bp
+ n_padsz
;
1020 call
->fid
= orig_dvp
->fid
;
1021 trace_afs_make_fs_call2(call
, &orig_dvp
->fid
, orig_name
, new_name
);
1022 afs_make_op_call(op
, call
, GFP_NOFS
);
1026 * Deliver reply data to FS.StoreData or FS.StoreStatus
1028 static int afs_deliver_fs_store_data(struct afs_call
*call
)
1030 struct afs_operation
*op
= call
->op
;
1031 struct afs_vnode_param
*vp
= &op
->file
[0];
1037 ret
= afs_transfer_reply(call
);
1041 /* unmarshall the reply once we've received all of it */
1043 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
1044 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
1046 _leave(" = 0 [done]");
1051 * FS.StoreData operation type
1053 static const struct afs_call_type afs_RXFSStoreData
= {
1054 .name
= "FS.StoreData",
1055 .op
= afs_FS_StoreData
,
1056 .deliver
= afs_deliver_fs_store_data
,
1057 .destructor
= afs_flat_call_destructor
,
1060 static const struct afs_call_type afs_RXFSStoreData64
= {
1061 .name
= "FS.StoreData64",
1062 .op
= afs_FS_StoreData64
,
1063 .deliver
= afs_deliver_fs_store_data
,
1064 .destructor
= afs_flat_call_destructor
,
1068 * store a set of pages to a very large file
1070 static void afs_fs_store_data64(struct afs_operation
*op
)
1072 struct afs_vnode_param
*vp
= &op
->file
[0];
1073 struct afs_call
*call
;
1076 _enter(",%x,{%llx:%llu},,",
1077 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
1079 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreData64
,
1080 (4 + 6 + 3 * 2) * 4,
1083 return afs_op_nomem(op
);
1085 call
->write_iter
= op
->store
.write_iter
;
1087 /* marshall the parameters */
1089 *bp
++ = htonl(FSSTOREDATA64
);
1090 *bp
++ = htonl(vp
->fid
.vid
);
1091 *bp
++ = htonl(vp
->fid
.vnode
);
1092 *bp
++ = htonl(vp
->fid
.unique
);
1094 *bp
++ = htonl(AFS_SET_MTIME
); /* mask */
1095 *bp
++ = htonl(op
->mtime
.tv_sec
); /* mtime */
1096 *bp
++ = 0; /* owner */
1097 *bp
++ = 0; /* group */
1098 *bp
++ = 0; /* unix mode */
1099 *bp
++ = 0; /* segment size */
1101 *bp
++ = htonl(upper_32_bits(op
->store
.pos
));
1102 *bp
++ = htonl(lower_32_bits(op
->store
.pos
));
1103 *bp
++ = htonl(upper_32_bits(op
->store
.size
));
1104 *bp
++ = htonl(lower_32_bits(op
->store
.size
));
1105 *bp
++ = htonl(upper_32_bits(op
->store
.i_size
));
1106 *bp
++ = htonl(lower_32_bits(op
->store
.i_size
));
1108 call
->fid
= vp
->fid
;
1109 trace_afs_make_fs_call(call
, &vp
->fid
);
1110 afs_make_op_call(op
, call
, GFP_NOFS
);
1114 * Write data to a file on the server.
1116 void afs_fs_store_data(struct afs_operation
*op
)
1118 struct afs_vnode_param
*vp
= &op
->file
[0];
1119 struct afs_call
*call
;
1122 _enter(",%x,{%llx:%llu},,",
1123 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
1125 _debug("size %llx, at %llx, i_size %llx",
1126 (unsigned long long)op
->store
.size
,
1127 (unsigned long long)op
->store
.pos
,
1128 (unsigned long long)op
->store
.i_size
);
1130 if (test_bit(AFS_SERVER_FL_HAS_FS64
, &op
->server
->flags
))
1131 return afs_fs_store_data64(op
);
1133 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreData
,
1137 return afs_op_nomem(op
);
1139 call
->write_iter
= op
->store
.write_iter
;
1141 /* marshall the parameters */
1143 *bp
++ = htonl(FSSTOREDATA
);
1144 *bp
++ = htonl(vp
->fid
.vid
);
1145 *bp
++ = htonl(vp
->fid
.vnode
);
1146 *bp
++ = htonl(vp
->fid
.unique
);
1148 *bp
++ = htonl(AFS_SET_MTIME
); /* mask */
1149 *bp
++ = htonl(op
->mtime
.tv_sec
); /* mtime */
1150 *bp
++ = 0; /* owner */
1151 *bp
++ = 0; /* group */
1152 *bp
++ = 0; /* unix mode */
1153 *bp
++ = 0; /* segment size */
1155 *bp
++ = htonl(lower_32_bits(op
->store
.pos
));
1156 *bp
++ = htonl(lower_32_bits(op
->store
.size
));
1157 *bp
++ = htonl(lower_32_bits(op
->store
.i_size
));
1159 call
->fid
= vp
->fid
;
1160 trace_afs_make_fs_call(call
, &vp
->fid
);
1161 afs_make_op_call(op
, call
, GFP_NOFS
);
1165 * FS.StoreStatus operation type
1167 static const struct afs_call_type afs_RXFSStoreStatus
= {
1168 .name
= "FS.StoreStatus",
1169 .op
= afs_FS_StoreStatus
,
1170 .deliver
= afs_deliver_fs_store_data
,
1171 .destructor
= afs_flat_call_destructor
,
1174 static const struct afs_call_type afs_RXFSStoreData_as_Status
= {
1175 .name
= "FS.StoreData",
1176 .op
= afs_FS_StoreData
,
1177 .deliver
= afs_deliver_fs_store_data
,
1178 .destructor
= afs_flat_call_destructor
,
1181 static const struct afs_call_type afs_RXFSStoreData64_as_Status
= {
1182 .name
= "FS.StoreData64",
1183 .op
= afs_FS_StoreData64
,
1184 .deliver
= afs_deliver_fs_store_data
,
1185 .destructor
= afs_flat_call_destructor
,
1189 * set the attributes on a very large file, using FS.StoreData rather than
1190 * FS.StoreStatus so as to alter the file size also
1192 static void afs_fs_setattr_size64(struct afs_operation
*op
)
1194 struct afs_vnode_param
*vp
= &op
->file
[0];
1195 struct afs_call
*call
;
1196 struct iattr
*attr
= op
->setattr
.attr
;
1199 _enter(",%x,{%llx:%llu},,",
1200 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
1202 ASSERT(attr
->ia_valid
& ATTR_SIZE
);
1204 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreData64_as_Status
,
1205 (4 + 6 + 3 * 2) * 4,
1208 return afs_op_nomem(op
);
1210 /* marshall the parameters */
1212 *bp
++ = htonl(FSSTOREDATA64
);
1213 *bp
++ = htonl(vp
->fid
.vid
);
1214 *bp
++ = htonl(vp
->fid
.vnode
);
1215 *bp
++ = htonl(vp
->fid
.unique
);
1217 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1219 *bp
++ = htonl(upper_32_bits(attr
->ia_size
)); /* position of start of write */
1220 *bp
++ = htonl(lower_32_bits(attr
->ia_size
));
1221 *bp
++ = 0; /* size of write */
1223 *bp
++ = htonl(upper_32_bits(attr
->ia_size
)); /* new file length */
1224 *bp
++ = htonl(lower_32_bits(attr
->ia_size
));
1226 call
->fid
= vp
->fid
;
1227 trace_afs_make_fs_call(call
, &vp
->fid
);
1228 afs_make_op_call(op
, call
, GFP_NOFS
);
1232 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1233 * so as to alter the file size also
1235 static void afs_fs_setattr_size(struct afs_operation
*op
)
1237 struct afs_vnode_param
*vp
= &op
->file
[0];
1238 struct afs_call
*call
;
1239 struct iattr
*attr
= op
->setattr
.attr
;
1242 _enter(",%x,{%llx:%llu},,",
1243 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
1245 ASSERT(attr
->ia_valid
& ATTR_SIZE
);
1246 if (test_bit(AFS_SERVER_FL_HAS_FS64
, &op
->server
->flags
))
1247 return afs_fs_setattr_size64(op
);
1249 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreData_as_Status
,
1253 return afs_op_nomem(op
);
1255 /* marshall the parameters */
1257 *bp
++ = htonl(FSSTOREDATA
);
1258 *bp
++ = htonl(vp
->fid
.vid
);
1259 *bp
++ = htonl(vp
->fid
.vnode
);
1260 *bp
++ = htonl(vp
->fid
.unique
);
1262 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1264 *bp
++ = htonl(attr
->ia_size
); /* position of start of write */
1265 *bp
++ = 0; /* size of write */
1266 *bp
++ = htonl(attr
->ia_size
); /* new file length */
1268 call
->fid
= vp
->fid
;
1269 trace_afs_make_fs_call(call
, &vp
->fid
);
1270 afs_make_op_call(op
, call
, GFP_NOFS
);
1274 * set the attributes on a file, using FS.StoreData if there's a change in file
1275 * size, and FS.StoreStatus otherwise
1277 void afs_fs_setattr(struct afs_operation
*op
)
1279 struct afs_vnode_param
*vp
= &op
->file
[0];
1280 struct afs_call
*call
;
1281 struct iattr
*attr
= op
->setattr
.attr
;
1284 if (attr
->ia_valid
& ATTR_SIZE
)
1285 return afs_fs_setattr_size(op
);
1287 _enter(",%x,{%llx:%llu},,",
1288 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
1290 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreStatus
,
1294 return afs_op_nomem(op
);
1296 /* marshall the parameters */
1298 *bp
++ = htonl(FSSTORESTATUS
);
1299 *bp
++ = htonl(vp
->fid
.vid
);
1300 *bp
++ = htonl(vp
->fid
.vnode
);
1301 *bp
++ = htonl(vp
->fid
.unique
);
1303 xdr_encode_AFS_StoreStatus(&bp
, op
->setattr
.attr
);
1305 call
->fid
= vp
->fid
;
1306 trace_afs_make_fs_call(call
, &vp
->fid
);
1307 afs_make_op_call(op
, call
, GFP_NOFS
);
1311 * deliver reply data to an FS.GetVolumeStatus
1313 static int afs_deliver_fs_get_volume_status(struct afs_call
*call
)
1315 struct afs_operation
*op
= call
->op
;
1321 _enter("{%u}", call
->unmarshall
);
1323 switch (call
->unmarshall
) {
1326 afs_extract_to_buf(call
, 12 * 4);
1329 /* extract the returned status record */
1331 _debug("extract status");
1332 ret
= afs_extract_data(call
, true);
1337 xdr_decode_AFSFetchVolumeStatus(&bp
, &op
->volstatus
.vs
);
1339 afs_extract_to_tmp(call
);
1342 /* extract the volume name length */
1344 ret
= afs_extract_data(call
, true);
1348 call
->count
= ntohl(call
->tmp
);
1349 _debug("volname length: %u", call
->count
);
1350 if (call
->count
>= AFSNAMEMAX
)
1351 return afs_protocol_error(call
, afs_eproto_volname_len
);
1352 size
= (call
->count
+ 3) & ~3; /* It's padded */
1353 afs_extract_to_buf(call
, size
);
1357 /* extract the volume name */
1359 _debug("extract volname");
1360 ret
= afs_extract_data(call
, true);
1366 _debug("volname '%s'", p
);
1367 afs_extract_to_tmp(call
);
1371 /* extract the offline message length */
1373 ret
= afs_extract_data(call
, true);
1377 call
->count
= ntohl(call
->tmp
);
1378 _debug("offline msg length: %u", call
->count
);
1379 if (call
->count
>= AFSNAMEMAX
)
1380 return afs_protocol_error(call
, afs_eproto_offline_msg_len
);
1381 size
= (call
->count
+ 3) & ~3; /* It's padded */
1382 afs_extract_to_buf(call
, size
);
1386 /* extract the offline message */
1388 _debug("extract offline");
1389 ret
= afs_extract_data(call
, true);
1395 _debug("offline '%s'", p
);
1397 afs_extract_to_tmp(call
);
1401 /* extract the message of the day length */
1403 ret
= afs_extract_data(call
, true);
1407 call
->count
= ntohl(call
->tmp
);
1408 _debug("motd length: %u", call
->count
);
1409 if (call
->count
>= AFSNAMEMAX
)
1410 return afs_protocol_error(call
, afs_eproto_motd_len
);
1411 size
= (call
->count
+ 3) & ~3; /* It's padded */
1412 afs_extract_to_buf(call
, size
);
1416 /* extract the message of the day */
1418 _debug("extract motd");
1419 ret
= afs_extract_data(call
, false);
1425 _debug("motd '%s'", p
);
1434 _leave(" = 0 [done]");
1439 * FS.GetVolumeStatus operation type
1441 static const struct afs_call_type afs_RXFSGetVolumeStatus
= {
1442 .name
= "FS.GetVolumeStatus",
1443 .op
= afs_FS_GetVolumeStatus
,
1444 .deliver
= afs_deliver_fs_get_volume_status
,
1445 .destructor
= afs_flat_call_destructor
,
1449 * fetch the status of a volume
1451 void afs_fs_get_volume_status(struct afs_operation
*op
)
1453 struct afs_vnode_param
*vp
= &op
->file
[0];
1454 struct afs_call
*call
;
1459 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSGetVolumeStatus
, 2 * 4,
1460 max(12 * 4, AFSOPAQUEMAX
+ 1));
1462 return afs_op_nomem(op
);
1464 /* marshall the parameters */
1466 bp
[0] = htonl(FSGETVOLUMESTATUS
);
1467 bp
[1] = htonl(vp
->fid
.vid
);
1469 call
->fid
= vp
->fid
;
1470 trace_afs_make_fs_call(call
, &vp
->fid
);
1471 afs_make_op_call(op
, call
, GFP_NOFS
);
1475 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1477 static int afs_deliver_fs_xxxx_lock(struct afs_call
*call
)
1479 struct afs_operation
*op
= call
->op
;
1483 _enter("{%u}", call
->unmarshall
);
1485 ret
= afs_transfer_reply(call
);
1489 /* unmarshall the reply once we've received all of it */
1491 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
1493 _leave(" = 0 [done]");
1498 * FS.SetLock operation type
1500 static const struct afs_call_type afs_RXFSSetLock
= {
1501 .name
= "FS.SetLock",
1502 .op
= afs_FS_SetLock
,
1503 .deliver
= afs_deliver_fs_xxxx_lock
,
1504 .done
= afs_lock_op_done
,
1505 .destructor
= afs_flat_call_destructor
,
1509 * FS.ExtendLock operation type
1511 static const struct afs_call_type afs_RXFSExtendLock
= {
1512 .name
= "FS.ExtendLock",
1513 .op
= afs_FS_ExtendLock
,
1514 .deliver
= afs_deliver_fs_xxxx_lock
,
1515 .done
= afs_lock_op_done
,
1516 .destructor
= afs_flat_call_destructor
,
1520 * FS.ReleaseLock operation type
1522 static const struct afs_call_type afs_RXFSReleaseLock
= {
1523 .name
= "FS.ReleaseLock",
1524 .op
= afs_FS_ReleaseLock
,
1525 .deliver
= afs_deliver_fs_xxxx_lock
,
1526 .destructor
= afs_flat_call_destructor
,
1530 * Set a lock on a file
1532 void afs_fs_set_lock(struct afs_operation
*op
)
1534 struct afs_vnode_param
*vp
= &op
->file
[0];
1535 struct afs_call
*call
;
1540 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSSetLock
, 5 * 4, 6 * 4);
1542 return afs_op_nomem(op
);
1544 /* marshall the parameters */
1546 *bp
++ = htonl(FSSETLOCK
);
1547 *bp
++ = htonl(vp
->fid
.vid
);
1548 *bp
++ = htonl(vp
->fid
.vnode
);
1549 *bp
++ = htonl(vp
->fid
.unique
);
1550 *bp
++ = htonl(op
->lock
.type
);
1552 call
->fid
= vp
->fid
;
1553 trace_afs_make_fs_calli(call
, &vp
->fid
, op
->lock
.type
);
1554 afs_make_op_call(op
, call
, GFP_NOFS
);
1558 * extend a lock on a file
1560 void afs_fs_extend_lock(struct afs_operation
*op
)
1562 struct afs_vnode_param
*vp
= &op
->file
[0];
1563 struct afs_call
*call
;
1568 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSExtendLock
, 4 * 4, 6 * 4);
1570 return afs_op_nomem(op
);
1572 /* marshall the parameters */
1574 *bp
++ = htonl(FSEXTENDLOCK
);
1575 *bp
++ = htonl(vp
->fid
.vid
);
1576 *bp
++ = htonl(vp
->fid
.vnode
);
1577 *bp
++ = htonl(vp
->fid
.unique
);
1579 call
->fid
= vp
->fid
;
1580 trace_afs_make_fs_call(call
, &vp
->fid
);
1581 afs_make_op_call(op
, call
, GFP_NOFS
);
1585 * release a lock on a file
1587 void afs_fs_release_lock(struct afs_operation
*op
)
1589 struct afs_vnode_param
*vp
= &op
->file
[0];
1590 struct afs_call
*call
;
1595 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSReleaseLock
, 4 * 4, 6 * 4);
1597 return afs_op_nomem(op
);
1599 /* marshall the parameters */
1601 *bp
++ = htonl(FSRELEASELOCK
);
1602 *bp
++ = htonl(vp
->fid
.vid
);
1603 *bp
++ = htonl(vp
->fid
.vnode
);
1604 *bp
++ = htonl(vp
->fid
.unique
);
1606 call
->fid
= vp
->fid
;
1607 trace_afs_make_fs_call(call
, &vp
->fid
);
1608 afs_make_op_call(op
, call
, GFP_NOFS
);
1612 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1614 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call
*call
)
1616 return afs_transfer_reply(call
);
1620 * FS.GiveUpAllCallBacks operation type
1622 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks
= {
1623 .name
= "FS.GiveUpAllCallBacks",
1624 .op
= afs_FS_GiveUpAllCallBacks
,
1625 .deliver
= afs_deliver_fs_give_up_all_callbacks
,
1626 .destructor
= afs_flat_call_destructor
,
1630 * Flush all the callbacks we have on a server.
1632 int afs_fs_give_up_all_callbacks(struct afs_net
*net
, struct afs_server
*server
,
1633 struct afs_address
*addr
, struct key
*key
)
1635 struct afs_call
*call
;
1641 call
= afs_alloc_flat_call(net
, &afs_RXFSGiveUpAllCallBacks
, 1 * 4, 0);
1646 call
->peer
= rxrpc_kernel_get_peer(addr
->peer
);
1647 call
->service_id
= server
->service_id
;
1649 /* marshall the parameters */
1651 *bp
++ = htonl(FSGIVEUPALLCALLBACKS
);
1653 call
->server
= afs_use_server(server
, afs_server_trace_give_up_cb
);
1654 afs_make_call(call
, GFP_NOFS
);
1655 afs_wait_for_call_to_complete(call
);
1657 if (call
->responded
)
1658 set_bit(AFS_SERVER_FL_RESPONDING
, &server
->flags
);
1664 * Deliver reply data to an FS.GetCapabilities operation.
1666 static int afs_deliver_fs_get_capabilities(struct afs_call
*call
)
1671 _enter("{%u,%zu}", call
->unmarshall
, iov_iter_count(call
->iter
));
1673 switch (call
->unmarshall
) {
1675 afs_extract_to_tmp(call
);
1679 /* Extract the capabilities word count */
1681 ret
= afs_extract_data(call
, true);
1685 count
= ntohl(call
->tmp
);
1686 call
->count
= count
;
1687 call
->count2
= count
;
1689 call
->unmarshall
= 4;
1694 /* Extract the first word of the capabilities to call->tmp */
1695 afs_extract_to_tmp(call
);
1700 ret
= afs_extract_data(call
, false);
1704 afs_extract_discard(call
, (count
- 1) * sizeof(__be32
));
1708 /* Extract remaining capabilities words */
1710 ret
= afs_extract_data(call
, false);
1718 _leave(" = 0 [done]");
1722 static void afs_fs_get_capabilities_destructor(struct afs_call
*call
)
1724 afs_put_endpoint_state(call
->probe
, afs_estate_trace_put_getcaps
);
1725 afs_flat_call_destructor(call
);
1729 * FS.GetCapabilities operation type
1731 static const struct afs_call_type afs_RXFSGetCapabilities
= {
1732 .name
= "FS.GetCapabilities",
1733 .op
= afs_FS_GetCapabilities
,
1734 .deliver
= afs_deliver_fs_get_capabilities
,
1735 .done
= afs_fileserver_probe_result
,
1736 .destructor
= afs_fs_get_capabilities_destructor
,
1740 * Probe a fileserver for the capabilities that it supports. This RPC can
1741 * reply with up to 196 words. The operation is asynchronous and if we managed
1742 * to allocate a call, true is returned the result is delivered through the
1743 * ->done() - otherwise we return false to indicate we didn't even try.
1745 bool afs_fs_get_capabilities(struct afs_net
*net
, struct afs_server
*server
,
1746 struct afs_endpoint_state
*estate
, unsigned int addr_index
,
1749 struct afs_call
*call
;
1754 call
= afs_alloc_flat_call(net
, &afs_RXFSGetCapabilities
, 1 * 4, 16 * 4);
1759 call
->server
= afs_use_server(server
, afs_server_trace_get_caps
);
1760 call
->peer
= rxrpc_kernel_get_peer(estate
->addresses
->addrs
[addr_index
].peer
);
1761 call
->probe
= afs_get_endpoint_state(estate
, afs_estate_trace_get_getcaps
);
1762 call
->probe_index
= addr_index
;
1763 call
->service_id
= server
->service_id
;
1764 call
->upgrade
= true;
1766 call
->max_lifespan
= AFS_PROBE_MAX_LIFESPAN
;
1768 /* marshall the parameters */
1770 *bp
++ = htonl(FSGETCAPABILITIES
);
1772 trace_afs_make_fs_call(call
, NULL
);
1773 afs_make_call(call
, GFP_NOFS
);
1779 * Deliver reply data to an FS.InlineBulkStatus call
1781 static int afs_deliver_fs_inline_bulk_status(struct afs_call
*call
)
1783 struct afs_operation
*op
= call
->op
;
1784 struct afs_status_cb
*scb
;
1789 _enter("{%u}", call
->unmarshall
);
1791 switch (call
->unmarshall
) {
1793 afs_extract_to_tmp(call
);
1797 /* Extract the file status count and array in two steps */
1799 _debug("extract status count");
1800 ret
= afs_extract_data(call
, true);
1804 tmp
= ntohl(call
->tmp
);
1805 _debug("status count: %u/%u", tmp
, op
->nr_files
);
1806 if (tmp
!= op
->nr_files
)
1807 return afs_protocol_error(call
, afs_eproto_ibulkst_count
);
1812 afs_extract_to_buf(call
, 21 * sizeof(__be32
));
1816 _debug("extract status array %u", call
->count
);
1817 ret
= afs_extract_data(call
, true);
1821 switch (call
->count
) {
1823 scb
= &op
->file
[0].scb
;
1826 scb
= &op
->file
[1].scb
;
1829 scb
= &op
->more_files
[call
->count
- 2].scb
;
1834 xdr_decode_AFSFetchStatus(&bp
, call
, scb
);
1837 if (call
->count
< op
->nr_files
)
1842 afs_extract_to_tmp(call
);
1845 /* Extract the callback count and array in two steps */
1847 _debug("extract CB count");
1848 ret
= afs_extract_data(call
, true);
1852 tmp
= ntohl(call
->tmp
);
1853 _debug("CB count: %u", tmp
);
1854 if (tmp
!= op
->nr_files
)
1855 return afs_protocol_error(call
, afs_eproto_ibulkst_cb_count
);
1859 afs_extract_to_buf(call
, 3 * sizeof(__be32
));
1863 _debug("extract CB array");
1864 ret
= afs_extract_data(call
, true);
1868 _debug("unmarshall CB array");
1869 switch (call
->count
) {
1871 scb
= &op
->file
[0].scb
;
1874 scb
= &op
->file
[1].scb
;
1877 scb
= &op
->more_files
[call
->count
- 2].scb
;
1882 xdr_decode_AFSCallBack(&bp
, call
, scb
);
1884 if (call
->count
< op
->nr_files
)
1887 afs_extract_to_buf(call
, 6 * sizeof(__be32
));
1892 ret
= afs_extract_data(call
, false);
1897 /* Unfortunately, prior to OpenAFS-1.6, volsync here is filled
1900 xdr_decode_AFSVolSync(&bp
, NULL
);
1909 _leave(" = 0 [done]");
1913 static void afs_done_fs_inline_bulk_status(struct afs_call
*call
)
1915 if (call
->error
== -ECONNABORTED
&&
1916 call
->abort_code
== RX_INVALID_OPERATION
) {
1917 set_bit(AFS_SERVER_FL_NO_IBULK
, &call
->server
->flags
);
1919 set_bit(AFS_VOLUME_MAYBE_NO_IBULK
, &call
->op
->volume
->flags
);
1924 * FS.InlineBulkStatus operation type
1926 static const struct afs_call_type afs_RXFSInlineBulkStatus
= {
1927 .name
= "FS.InlineBulkStatus",
1928 .op
= afs_FS_InlineBulkStatus
,
1929 .deliver
= afs_deliver_fs_inline_bulk_status
,
1930 .done
= afs_done_fs_inline_bulk_status
,
1931 .destructor
= afs_flat_call_destructor
,
1935 * Fetch the status information for up to 50 files
1937 void afs_fs_inline_bulk_status(struct afs_operation
*op
)
1939 struct afs_vnode_param
*dvp
= &op
->file
[0];
1940 struct afs_vnode_param
*vp
= &op
->file
[1];
1941 struct afs_call
*call
;
1945 if (test_bit(AFS_SERVER_FL_NO_IBULK
, &op
->server
->flags
)) {
1946 afs_op_set_error(op
, -ENOTSUPP
);
1950 _enter(",%x,{%llx:%llu},%u",
1951 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
, op
->nr_files
);
1953 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSInlineBulkStatus
,
1954 (2 + op
->nr_files
* 3) * 4,
1957 return afs_op_nomem(op
);
1959 /* marshall the parameters */
1961 *bp
++ = htonl(FSINLINEBULKSTATUS
);
1962 *bp
++ = htonl(op
->nr_files
);
1963 *bp
++ = htonl(dvp
->fid
.vid
);
1964 *bp
++ = htonl(dvp
->fid
.vnode
);
1965 *bp
++ = htonl(dvp
->fid
.unique
);
1966 *bp
++ = htonl(vp
->fid
.vid
);
1967 *bp
++ = htonl(vp
->fid
.vnode
);
1968 *bp
++ = htonl(vp
->fid
.unique
);
1969 for (i
= 0; i
< op
->nr_files
- 2; i
++) {
1970 *bp
++ = htonl(op
->more_files
[i
].fid
.vid
);
1971 *bp
++ = htonl(op
->more_files
[i
].fid
.vnode
);
1972 *bp
++ = htonl(op
->more_files
[i
].fid
.unique
);
1975 call
->fid
= vp
->fid
;
1976 trace_afs_make_fs_call(call
, &vp
->fid
);
1977 afs_make_op_call(op
, call
, GFP_NOFS
);
1981 * deliver reply data to an FS.FetchACL
1983 static int afs_deliver_fs_fetch_acl(struct afs_call
*call
)
1985 struct afs_operation
*op
= call
->op
;
1986 struct afs_vnode_param
*vp
= &op
->file
[0];
1987 struct afs_acl
*acl
;
1992 _enter("{%u}", call
->unmarshall
);
1994 switch (call
->unmarshall
) {
1996 afs_extract_to_tmp(call
);
2000 /* extract the returned data length */
2002 ret
= afs_extract_data(call
, true);
2006 size
= call
->count2
= ntohl(call
->tmp
);
2007 size
= round_up(size
, 4);
2009 acl
= kmalloc(struct_size(acl
, data
, size
), GFP_KERNEL
);
2013 acl
->size
= call
->count2
;
2014 afs_extract_begin(call
, acl
->data
, size
);
2018 /* extract the returned data */
2020 ret
= afs_extract_data(call
, true);
2024 afs_extract_to_buf(call
, (21 + 6) * 4);
2028 /* extract the metadata */
2030 ret
= afs_extract_data(call
, false);
2035 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
2036 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
2045 _leave(" = 0 [done]");
2050 * FS.FetchACL operation type
2052 static const struct afs_call_type afs_RXFSFetchACL
= {
2053 .name
= "FS.FetchACL",
2054 .op
= afs_FS_FetchACL
,
2055 .deliver
= afs_deliver_fs_fetch_acl
,
2059 * Fetch the ACL for a file.
2061 void afs_fs_fetch_acl(struct afs_operation
*op
)
2063 struct afs_vnode_param
*vp
= &op
->file
[0];
2064 struct afs_call
*call
;
2067 _enter(",%x,{%llx:%llu},,",
2068 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
2070 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSFetchACL
, 16, (21 + 6) * 4);
2072 return afs_op_nomem(op
);
2074 /* marshall the parameters */
2076 bp
[0] = htonl(FSFETCHACL
);
2077 bp
[1] = htonl(vp
->fid
.vid
);
2078 bp
[2] = htonl(vp
->fid
.vnode
);
2079 bp
[3] = htonl(vp
->fid
.unique
);
2081 call
->fid
= vp
->fid
;
2082 trace_afs_make_fs_call(call
, &vp
->fid
);
2083 afs_make_op_call(op
, call
, GFP_KERNEL
);
2087 * FS.StoreACL operation type
2089 static const struct afs_call_type afs_RXFSStoreACL
= {
2090 .name
= "FS.StoreACL",
2091 .op
= afs_FS_StoreACL
,
2092 .deliver
= afs_deliver_fs_file_status_and_vol
,
2093 .destructor
= afs_flat_call_destructor
,
2097 * Fetch the ACL for a file.
2099 void afs_fs_store_acl(struct afs_operation
*op
)
2101 struct afs_vnode_param
*vp
= &op
->file
[0];
2102 struct afs_call
*call
;
2103 const struct afs_acl
*acl
= op
->acl
;
2107 _enter(",%x,{%llx:%llu},,",
2108 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
2110 size
= round_up(acl
->size
, 4);
2111 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreACL
,
2112 5 * 4 + size
, (21 + 6) * 4);
2114 return afs_op_nomem(op
);
2116 /* marshall the parameters */
2118 bp
[0] = htonl(FSSTOREACL
);
2119 bp
[1] = htonl(vp
->fid
.vid
);
2120 bp
[2] = htonl(vp
->fid
.vnode
);
2121 bp
[3] = htonl(vp
->fid
.unique
);
2122 bp
[4] = htonl(acl
->size
);
2123 memcpy(&bp
[5], acl
->data
, acl
->size
);
2124 if (acl
->size
!= size
)
2125 memset((void *)&bp
[5] + acl
->size
, 0, size
- acl
->size
);
2127 call
->fid
= vp
->fid
;
2128 trace_afs_make_fs_call(call
, &vp
->fid
);
2129 afs_make_op_call(op
, call
, GFP_KERNEL
);