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>
18 * decode an AFSFid block
20 static void xdr_decode_AFSFid(const __be32
**_bp
, struct afs_fid
*fid
)
22 const __be32
*bp
= *_bp
;
24 fid
->vid
= ntohl(*bp
++);
25 fid
->vnode
= ntohl(*bp
++);
26 fid
->unique
= ntohl(*bp
++);
31 * Dump a bad file status record.
33 static void xdr_dump_bad(const __be32
*bp
)
38 pr_notice("AFS XDR: Bad status record\n");
39 for (i
= 0; i
< 5 * 4 * 4; i
+= 16) {
42 pr_notice("%03x: %08x %08x %08x %08x\n",
43 i
, ntohl(x
[0]), ntohl(x
[1]), ntohl(x
[2]), ntohl(x
[3]));
47 pr_notice("0x50: %08x\n", ntohl(x
[0]));
51 * decode an AFSFetchStatus block
53 static void xdr_decode_AFSFetchStatus(const __be32
**_bp
,
54 struct afs_call
*call
,
55 struct afs_status_cb
*scb
)
57 const struct afs_xdr_AFSFetchStatus
*xdr
= (const void *)*_bp
;
58 struct afs_file_status
*status
= &scb
->status
;
59 bool inline_error
= (call
->operation_ID
== afs_FS_InlineBulkStatus
);
60 u64 data_version
, size
;
63 abort_code
= ntohl(xdr
->abort_code
);
65 if (xdr
->if_version
!= htonl(AFS_FSTATUS_VERSION
)) {
66 if (xdr
->if_version
== htonl(0) &&
69 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
70 * whereby it doesn't set the interface version in the error
73 status
->abort_code
= abort_code
;
74 scb
->have_error
= true;
78 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr
->if_version
));
82 if (abort_code
!= 0 && inline_error
) {
83 status
->abort_code
= abort_code
;
84 scb
->have_error
= true;
88 type
= ntohl(xdr
->type
);
92 case AFS_FTYPE_SYMLINK
:
99 status
->nlink
= ntohl(xdr
->nlink
);
100 status
->author
= ntohl(xdr
->author
);
101 status
->owner
= ntohl(xdr
->owner
);
102 status
->caller_access
= ntohl(xdr
->caller_access
); /* Ticket dependent */
103 status
->anon_access
= ntohl(xdr
->anon_access
);
104 status
->mode
= ntohl(xdr
->mode
) & S_IALLUGO
;
105 status
->group
= ntohl(xdr
->group
);
106 status
->lock_count
= ntohl(xdr
->lock_count
);
108 status
->mtime_client
.tv_sec
= ntohl(xdr
->mtime_client
);
109 status
->mtime_client
.tv_nsec
= 0;
110 status
->mtime_server
.tv_sec
= ntohl(xdr
->mtime_server
);
111 status
->mtime_server
.tv_nsec
= 0;
113 size
= (u64
)ntohl(xdr
->size_lo
);
114 size
|= (u64
)ntohl(xdr
->size_hi
) << 32;
117 data_version
= (u64
)ntohl(xdr
->data_version_lo
);
118 data_version
|= (u64
)ntohl(xdr
->data_version_hi
) << 32;
119 status
->data_version
= data_version
;
120 scb
->have_status
= true;
122 *_bp
= (const void *)*_bp
+ sizeof(*xdr
);
127 afs_protocol_error(call
, afs_eproto_bad_status
);
131 static time64_t
xdr_decode_expiry(struct afs_call
*call
, u32 expiry
)
133 return ktime_divns(call
->reply_time
, NSEC_PER_SEC
) + expiry
;
136 static void xdr_decode_AFSCallBack(const __be32
**_bp
,
137 struct afs_call
*call
,
138 struct afs_status_cb
*scb
)
140 struct afs_callback
*cb
= &scb
->callback
;
141 const __be32
*bp
= *_bp
;
144 cb
->expires_at
= xdr_decode_expiry(call
, ntohl(*bp
++));
151 * decode an AFSVolSync block
153 static void xdr_decode_AFSVolSync(const __be32
**_bp
,
154 struct afs_volsync
*volsync
)
156 const __be32
*bp
= *_bp
;
159 creation
= ntohl(*bp
++);
168 volsync
->creation
= creation
;
172 * encode the requested attributes into an AFSStoreStatus block
174 static void xdr_encode_AFS_StoreStatus(__be32
**_bp
, struct iattr
*attr
)
177 u32 mask
= 0, mtime
= 0, owner
= 0, group
= 0, mode
= 0;
180 if (attr
->ia_valid
& ATTR_MTIME
) {
181 mask
|= AFS_SET_MTIME
;
182 mtime
= attr
->ia_mtime
.tv_sec
;
185 if (attr
->ia_valid
& ATTR_UID
) {
186 mask
|= AFS_SET_OWNER
;
187 owner
= from_kuid(&init_user_ns
, attr
->ia_uid
);
190 if (attr
->ia_valid
& ATTR_GID
) {
191 mask
|= AFS_SET_GROUP
;
192 group
= from_kgid(&init_user_ns
, attr
->ia_gid
);
195 if (attr
->ia_valid
& ATTR_MODE
) {
196 mask
|= AFS_SET_MODE
;
197 mode
= attr
->ia_mode
& S_IALLUGO
;
201 *bp
++ = htonl(mtime
);
202 *bp
++ = htonl(owner
);
203 *bp
++ = htonl(group
);
205 *bp
++ = 0; /* segment size */
210 * decode an AFSFetchVolumeStatus block
212 static void xdr_decode_AFSFetchVolumeStatus(const __be32
**_bp
,
213 struct afs_volume_status
*vs
)
215 const __be32
*bp
= *_bp
;
217 vs
->vid
= ntohl(*bp
++);
218 vs
->parent_id
= ntohl(*bp
++);
219 vs
->online
= ntohl(*bp
++);
220 vs
->in_service
= ntohl(*bp
++);
221 vs
->blessed
= ntohl(*bp
++);
222 vs
->needs_salvage
= ntohl(*bp
++);
223 vs
->type
= ntohl(*bp
++);
224 vs
->min_quota
= ntohl(*bp
++);
225 vs
->max_quota
= ntohl(*bp
++);
226 vs
->blocks_in_use
= ntohl(*bp
++);
227 vs
->part_blocks_avail
= ntohl(*bp
++);
228 vs
->part_max_blocks
= ntohl(*bp
++);
229 vs
->vol_copy_date
= 0;
230 vs
->vol_backup_date
= 0;
235 * deliver reply data to an FS.FetchStatus
237 static int afs_deliver_fs_fetch_status(struct afs_call
*call
)
239 struct afs_operation
*op
= call
->op
;
240 struct afs_vnode_param
*vp
= &op
->file
[op
->fetch_status
.which
];
244 ret
= afs_transfer_reply(call
);
248 /* unmarshall the reply once we've received all of it */
250 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
251 xdr_decode_AFSCallBack(&bp
, call
, &vp
->scb
);
252 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
254 _leave(" = 0 [done]");
259 * FS.FetchStatus operation type
261 static const struct afs_call_type afs_RXFSFetchStatus
= {
262 .name
= "FS.FetchStatus",
263 .op
= afs_FS_FetchStatus
,
264 .deliver
= afs_deliver_fs_fetch_status
,
265 .destructor
= afs_flat_call_destructor
,
269 * fetch the status information for a file
271 void afs_fs_fetch_status(struct afs_operation
*op
)
273 struct afs_vnode_param
*vp
= &op
->file
[op
->fetch_status
.which
];
274 struct afs_call
*call
;
277 _enter(",%x,{%llx:%llu},,",
278 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
280 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSFetchStatus
,
281 16, (21 + 3 + 6) * 4);
283 return afs_op_nomem(op
);
285 /* marshall the parameters */
287 bp
[0] = htonl(FSFETCHSTATUS
);
288 bp
[1] = htonl(vp
->fid
.vid
);
289 bp
[2] = htonl(vp
->fid
.vnode
);
290 bp
[3] = htonl(vp
->fid
.unique
);
292 trace_afs_make_fs_call(call
, &vp
->fid
);
293 afs_make_op_call(op
, call
, GFP_NOFS
);
297 * deliver reply data to an FS.FetchData
299 static int afs_deliver_fs_fetch_data(struct afs_call
*call
)
301 struct afs_operation
*op
= call
->op
;
302 struct afs_vnode_param
*vp
= &op
->file
[0];
303 struct afs_read
*req
= op
->fetch
.req
;
308 _enter("{%u,%zu/%llu}",
309 call
->unmarshall
, iov_iter_count(call
->iter
), req
->actual_len
);
311 switch (call
->unmarshall
) {
315 req
->offset
= req
->pos
& (PAGE_SIZE
- 1);
317 if (call
->operation_ID
== FSFETCHDATA64
) {
318 afs_extract_to_tmp64(call
);
320 call
->tmp_u
= htonl(0);
321 afs_extract_to_tmp(call
);
325 /* extract the returned data length */
327 _debug("extract data length");
328 ret
= afs_extract_data(call
, true);
332 req
->actual_len
= be64_to_cpu(call
->tmp64
);
333 _debug("DATA length: %llu", req
->actual_len
);
334 req
->remain
= min(req
->len
, req
->actual_len
);
335 if (req
->remain
== 0)
341 ASSERTCMP(req
->index
, <, req
->nr_pages
);
342 if (req
->remain
> PAGE_SIZE
- req
->offset
)
343 size
= PAGE_SIZE
- req
->offset
;
346 call
->bvec
[0].bv_len
= size
;
347 call
->bvec
[0].bv_offset
= req
->offset
;
348 call
->bvec
[0].bv_page
= req
->pages
[req
->index
];
349 iov_iter_bvec(&call
->def_iter
, READ
, call
->bvec
, 1, size
);
350 ASSERTCMP(size
, <=, PAGE_SIZE
);
353 /* extract the returned data */
355 _debug("extract data %zu/%llu",
356 iov_iter_count(call
->iter
), req
->remain
);
358 ret
= afs_extract_data(call
, true);
361 req
->remain
-= call
->bvec
[0].bv_len
;
362 req
->offset
+= call
->bvec
[0].bv_len
;
363 ASSERTCMP(req
->offset
, <=, PAGE_SIZE
);
364 if (req
->offset
== PAGE_SIZE
) {
371 ASSERTCMP(req
->remain
, ==, 0);
372 if (req
->actual_len
<= req
->len
)
375 /* Discard any excess data the server gave us */
376 afs_extract_discard(call
, req
->actual_len
- req
->len
);
377 call
->unmarshall
= 3;
381 _debug("extract discard %zu/%llu",
382 iov_iter_count(call
->iter
), req
->actual_len
- req
->len
);
384 ret
= afs_extract_data(call
, true);
389 call
->unmarshall
= 4;
390 afs_extract_to_buf(call
, (21 + 3 + 6) * 4);
393 /* extract the metadata */
395 ret
= afs_extract_data(call
, false);
400 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
401 xdr_decode_AFSCallBack(&bp
, call
, &vp
->scb
);
402 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
404 req
->data_version
= vp
->scb
.status
.data_version
;
405 req
->file_size
= vp
->scb
.status
.size
;
413 for (; req
->index
< req
->nr_pages
; req
->index
++) {
414 if (req
->offset
< PAGE_SIZE
)
415 zero_user_segment(req
->pages
[req
->index
],
416 req
->offset
, PAGE_SIZE
);
421 for (req
->index
= 0; req
->index
< req
->nr_pages
; req
->index
++)
424 _leave(" = 0 [done]");
429 * FS.FetchData operation type
431 static const struct afs_call_type afs_RXFSFetchData
= {
432 .name
= "FS.FetchData",
433 .op
= afs_FS_FetchData
,
434 .deliver
= afs_deliver_fs_fetch_data
,
435 .destructor
= afs_flat_call_destructor
,
438 static const struct afs_call_type afs_RXFSFetchData64
= {
439 .name
= "FS.FetchData64",
440 .op
= afs_FS_FetchData64
,
441 .deliver
= afs_deliver_fs_fetch_data
,
442 .destructor
= afs_flat_call_destructor
,
446 * fetch data from a very large file
448 static void afs_fs_fetch_data64(struct afs_operation
*op
)
450 struct afs_vnode_param
*vp
= &op
->file
[0];
451 struct afs_read
*req
= op
->fetch
.req
;
452 struct afs_call
*call
;
457 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSFetchData64
, 32, (21 + 3 + 6) * 4);
459 return afs_op_nomem(op
);
461 /* marshall the parameters */
463 bp
[0] = htonl(FSFETCHDATA64
);
464 bp
[1] = htonl(vp
->fid
.vid
);
465 bp
[2] = htonl(vp
->fid
.vnode
);
466 bp
[3] = htonl(vp
->fid
.unique
);
467 bp
[4] = htonl(upper_32_bits(req
->pos
));
468 bp
[5] = htonl(lower_32_bits(req
->pos
));
470 bp
[7] = htonl(lower_32_bits(req
->len
));
472 trace_afs_make_fs_call(call
, &vp
->fid
);
473 afs_make_op_call(op
, call
, GFP_NOFS
);
477 * fetch data from a file
479 void afs_fs_fetch_data(struct afs_operation
*op
)
481 struct afs_vnode_param
*vp
= &op
->file
[0];
482 struct afs_call
*call
;
483 struct afs_read
*req
= op
->fetch
.req
;
486 if (upper_32_bits(req
->pos
) ||
487 upper_32_bits(req
->len
) ||
488 upper_32_bits(req
->pos
+ req
->len
))
489 return afs_fs_fetch_data64(op
);
493 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSFetchData
, 24, (21 + 3 + 6) * 4);
495 return afs_op_nomem(op
);
497 /* marshall the parameters */
499 bp
[0] = htonl(FSFETCHDATA
);
500 bp
[1] = htonl(vp
->fid
.vid
);
501 bp
[2] = htonl(vp
->fid
.vnode
);
502 bp
[3] = htonl(vp
->fid
.unique
);
503 bp
[4] = htonl(lower_32_bits(req
->pos
));
504 bp
[5] = htonl(lower_32_bits(req
->len
));
506 trace_afs_make_fs_call(call
, &vp
->fid
);
507 afs_make_op_call(op
, call
, GFP_NOFS
);
511 * deliver reply data to an FS.CreateFile or an FS.MakeDir
513 static int afs_deliver_fs_create_vnode(struct afs_call
*call
)
515 struct afs_operation
*op
= call
->op
;
516 struct afs_vnode_param
*dvp
= &op
->file
[0];
517 struct afs_vnode_param
*vp
= &op
->file
[1];
521 ret
= afs_transfer_reply(call
);
525 /* unmarshall the reply once we've received all of it */
527 xdr_decode_AFSFid(&bp
, &op
->file
[1].fid
);
528 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
529 xdr_decode_AFSFetchStatus(&bp
, call
, &dvp
->scb
);
530 xdr_decode_AFSCallBack(&bp
, call
, &vp
->scb
);
531 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
533 _leave(" = 0 [done]");
538 * FS.CreateFile and FS.MakeDir operation type
540 static const struct afs_call_type afs_RXFSCreateFile
= {
541 .name
= "FS.CreateFile",
542 .op
= afs_FS_CreateFile
,
543 .deliver
= afs_deliver_fs_create_vnode
,
544 .destructor
= afs_flat_call_destructor
,
550 void afs_fs_create_file(struct afs_operation
*op
)
552 const struct qstr
*name
= &op
->dentry
->d_name
;
553 struct afs_vnode_param
*dvp
= &op
->file
[0];
554 struct afs_call
*call
;
555 size_t namesz
, reqsz
, padsz
;
561 padsz
= (4 - (namesz
& 3)) & 3;
562 reqsz
= (5 * 4) + namesz
+ padsz
+ (6 * 4);
564 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSCreateFile
,
565 reqsz
, (3 + 21 + 21 + 3 + 6) * 4);
567 return afs_op_nomem(op
);
569 /* marshall the parameters */
571 *bp
++ = htonl(FSCREATEFILE
);
572 *bp
++ = htonl(dvp
->fid
.vid
);
573 *bp
++ = htonl(dvp
->fid
.vnode
);
574 *bp
++ = htonl(dvp
->fid
.unique
);
575 *bp
++ = htonl(namesz
);
576 memcpy(bp
, name
->name
, namesz
);
577 bp
= (void *) bp
+ namesz
;
579 memset(bp
, 0, padsz
);
580 bp
= (void *) bp
+ padsz
;
582 *bp
++ = htonl(AFS_SET_MODE
| AFS_SET_MTIME
);
583 *bp
++ = htonl(op
->mtime
.tv_sec
); /* mtime */
584 *bp
++ = 0; /* owner */
585 *bp
++ = 0; /* group */
586 *bp
++ = htonl(op
->create
.mode
& S_IALLUGO
); /* unix mode */
587 *bp
++ = 0; /* segment size */
589 trace_afs_make_fs_call1(call
, &dvp
->fid
, name
);
590 afs_make_op_call(op
, call
, GFP_NOFS
);
593 static const struct afs_call_type afs_RXFSMakeDir
= {
594 .name
= "FS.MakeDir",
595 .op
= afs_FS_MakeDir
,
596 .deliver
= afs_deliver_fs_create_vnode
,
597 .destructor
= afs_flat_call_destructor
,
601 * Create a new directory
603 void afs_fs_make_dir(struct afs_operation
*op
)
605 const struct qstr
*name
= &op
->dentry
->d_name
;
606 struct afs_vnode_param
*dvp
= &op
->file
[0];
607 struct afs_call
*call
;
608 size_t namesz
, reqsz
, padsz
;
614 padsz
= (4 - (namesz
& 3)) & 3;
615 reqsz
= (5 * 4) + namesz
+ padsz
+ (6 * 4);
617 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSMakeDir
,
618 reqsz
, (3 + 21 + 21 + 3 + 6) * 4);
620 return afs_op_nomem(op
);
622 /* marshall the parameters */
624 *bp
++ = htonl(FSMAKEDIR
);
625 *bp
++ = htonl(dvp
->fid
.vid
);
626 *bp
++ = htonl(dvp
->fid
.vnode
);
627 *bp
++ = htonl(dvp
->fid
.unique
);
628 *bp
++ = htonl(namesz
);
629 memcpy(bp
, name
->name
, namesz
);
630 bp
= (void *) bp
+ namesz
;
632 memset(bp
, 0, padsz
);
633 bp
= (void *) bp
+ padsz
;
635 *bp
++ = htonl(AFS_SET_MODE
| AFS_SET_MTIME
);
636 *bp
++ = htonl(op
->mtime
.tv_sec
); /* mtime */
637 *bp
++ = 0; /* owner */
638 *bp
++ = 0; /* group */
639 *bp
++ = htonl(op
->create
.mode
& S_IALLUGO
); /* unix mode */
640 *bp
++ = 0; /* segment size */
642 trace_afs_make_fs_call1(call
, &dvp
->fid
, name
);
643 afs_make_op_call(op
, call
, GFP_NOFS
);
647 * Deliver reply data to any operation that returns status and volume sync.
649 static int afs_deliver_fs_file_status_and_vol(struct afs_call
*call
)
651 struct afs_operation
*op
= call
->op
;
652 struct afs_vnode_param
*vp
= &op
->file
[0];
656 ret
= afs_transfer_reply(call
);
660 /* unmarshall the reply once we've received all of it */
662 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
663 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
665 _leave(" = 0 [done]");
670 * FS.RemoveFile operation type
672 static const struct afs_call_type afs_RXFSRemoveFile
= {
673 .name
= "FS.RemoveFile",
674 .op
= afs_FS_RemoveFile
,
675 .deliver
= afs_deliver_fs_file_status_and_vol
,
676 .destructor
= afs_flat_call_destructor
,
682 void afs_fs_remove_file(struct afs_operation
*op
)
684 const struct qstr
*name
= &op
->dentry
->d_name
;
685 struct afs_vnode_param
*dvp
= &op
->file
[0];
686 struct afs_call
*call
;
687 size_t namesz
, reqsz
, padsz
;
693 padsz
= (4 - (namesz
& 3)) & 3;
694 reqsz
= (5 * 4) + namesz
+ padsz
;
696 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSRemoveFile
,
697 reqsz
, (21 + 6) * 4);
699 return afs_op_nomem(op
);
701 /* marshall the parameters */
703 *bp
++ = htonl(FSREMOVEFILE
);
704 *bp
++ = htonl(dvp
->fid
.vid
);
705 *bp
++ = htonl(dvp
->fid
.vnode
);
706 *bp
++ = htonl(dvp
->fid
.unique
);
707 *bp
++ = htonl(namesz
);
708 memcpy(bp
, name
->name
, namesz
);
709 bp
= (void *) bp
+ namesz
;
711 memset(bp
, 0, padsz
);
712 bp
= (void *) bp
+ padsz
;
715 trace_afs_make_fs_call1(call
, &dvp
->fid
, name
);
716 afs_make_op_call(op
, call
, GFP_NOFS
);
719 static const struct afs_call_type afs_RXFSRemoveDir
= {
720 .name
= "FS.RemoveDir",
721 .op
= afs_FS_RemoveDir
,
722 .deliver
= afs_deliver_fs_file_status_and_vol
,
723 .destructor
= afs_flat_call_destructor
,
727 * Remove a directory.
729 void afs_fs_remove_dir(struct afs_operation
*op
)
731 const struct qstr
*name
= &op
->dentry
->d_name
;
732 struct afs_vnode_param
*dvp
= &op
->file
[0];
733 struct afs_call
*call
;
734 size_t namesz
, reqsz
, padsz
;
740 padsz
= (4 - (namesz
& 3)) & 3;
741 reqsz
= (5 * 4) + namesz
+ padsz
;
743 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSRemoveDir
,
744 reqsz
, (21 + 6) * 4);
746 return afs_op_nomem(op
);
748 /* marshall the parameters */
750 *bp
++ = htonl(FSREMOVEDIR
);
751 *bp
++ = htonl(dvp
->fid
.vid
);
752 *bp
++ = htonl(dvp
->fid
.vnode
);
753 *bp
++ = htonl(dvp
->fid
.unique
);
754 *bp
++ = htonl(namesz
);
755 memcpy(bp
, name
->name
, namesz
);
756 bp
= (void *) bp
+ namesz
;
758 memset(bp
, 0, padsz
);
759 bp
= (void *) bp
+ padsz
;
762 trace_afs_make_fs_call1(call
, &dvp
->fid
, name
);
763 afs_make_op_call(op
, call
, GFP_NOFS
);
767 * deliver reply data to an FS.Link
769 static int afs_deliver_fs_link(struct afs_call
*call
)
771 struct afs_operation
*op
= call
->op
;
772 struct afs_vnode_param
*dvp
= &op
->file
[0];
773 struct afs_vnode_param
*vp
= &op
->file
[1];
777 _enter("{%u}", call
->unmarshall
);
779 ret
= afs_transfer_reply(call
);
783 /* unmarshall the reply once we've received all of it */
785 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
786 xdr_decode_AFSFetchStatus(&bp
, call
, &dvp
->scb
);
787 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
789 _leave(" = 0 [done]");
794 * FS.Link operation type
796 static const struct afs_call_type afs_RXFSLink
= {
799 .deliver
= afs_deliver_fs_link
,
800 .destructor
= afs_flat_call_destructor
,
806 void afs_fs_link(struct afs_operation
*op
)
808 const struct qstr
*name
= &op
->dentry
->d_name
;
809 struct afs_vnode_param
*dvp
= &op
->file
[0];
810 struct afs_vnode_param
*vp
= &op
->file
[1];
811 struct afs_call
*call
;
812 size_t namesz
, reqsz
, padsz
;
818 padsz
= (4 - (namesz
& 3)) & 3;
819 reqsz
= (5 * 4) + namesz
+ padsz
+ (3 * 4);
821 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSLink
, reqsz
, (21 + 21 + 6) * 4);
823 return afs_op_nomem(op
);
825 /* marshall the parameters */
827 *bp
++ = htonl(FSLINK
);
828 *bp
++ = htonl(dvp
->fid
.vid
);
829 *bp
++ = htonl(dvp
->fid
.vnode
);
830 *bp
++ = htonl(dvp
->fid
.unique
);
831 *bp
++ = htonl(namesz
);
832 memcpy(bp
, name
->name
, namesz
);
833 bp
= (void *) bp
+ namesz
;
835 memset(bp
, 0, padsz
);
836 bp
= (void *) bp
+ padsz
;
838 *bp
++ = htonl(vp
->fid
.vid
);
839 *bp
++ = htonl(vp
->fid
.vnode
);
840 *bp
++ = htonl(vp
->fid
.unique
);
842 trace_afs_make_fs_call1(call
, &vp
->fid
, name
);
843 afs_make_op_call(op
, call
, GFP_NOFS
);
847 * deliver reply data to an FS.Symlink
849 static int afs_deliver_fs_symlink(struct afs_call
*call
)
851 struct afs_operation
*op
= call
->op
;
852 struct afs_vnode_param
*dvp
= &op
->file
[0];
853 struct afs_vnode_param
*vp
= &op
->file
[1];
857 _enter("{%u}", call
->unmarshall
);
859 ret
= afs_transfer_reply(call
);
863 /* unmarshall the reply once we've received all of it */
865 xdr_decode_AFSFid(&bp
, &vp
->fid
);
866 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
867 xdr_decode_AFSFetchStatus(&bp
, call
, &dvp
->scb
);
868 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
870 _leave(" = 0 [done]");
875 * FS.Symlink operation type
877 static const struct afs_call_type afs_RXFSSymlink
= {
878 .name
= "FS.Symlink",
879 .op
= afs_FS_Symlink
,
880 .deliver
= afs_deliver_fs_symlink
,
881 .destructor
= afs_flat_call_destructor
,
885 * create a symbolic link
887 void afs_fs_symlink(struct afs_operation
*op
)
889 const struct qstr
*name
= &op
->dentry
->d_name
;
890 struct afs_vnode_param
*dvp
= &op
->file
[0];
891 struct afs_call
*call
;
892 size_t namesz
, reqsz
, padsz
, c_namesz
, c_padsz
;
898 padsz
= (4 - (namesz
& 3)) & 3;
900 c_namesz
= strlen(op
->create
.symlink
);
901 c_padsz
= (4 - (c_namesz
& 3)) & 3;
903 reqsz
= (6 * 4) + namesz
+ padsz
+ c_namesz
+ c_padsz
+ (6 * 4);
905 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSSymlink
, reqsz
,
906 (3 + 21 + 21 + 6) * 4);
908 return afs_op_nomem(op
);
910 /* marshall the parameters */
912 *bp
++ = htonl(FSSYMLINK
);
913 *bp
++ = htonl(dvp
->fid
.vid
);
914 *bp
++ = htonl(dvp
->fid
.vnode
);
915 *bp
++ = htonl(dvp
->fid
.unique
);
916 *bp
++ = htonl(namesz
);
917 memcpy(bp
, name
->name
, namesz
);
918 bp
= (void *) bp
+ namesz
;
920 memset(bp
, 0, padsz
);
921 bp
= (void *) bp
+ padsz
;
923 *bp
++ = htonl(c_namesz
);
924 memcpy(bp
, op
->create
.symlink
, c_namesz
);
925 bp
= (void *) bp
+ c_namesz
;
927 memset(bp
, 0, c_padsz
);
928 bp
= (void *) bp
+ c_padsz
;
930 *bp
++ = htonl(AFS_SET_MODE
| AFS_SET_MTIME
);
931 *bp
++ = htonl(op
->mtime
.tv_sec
); /* mtime */
932 *bp
++ = 0; /* owner */
933 *bp
++ = 0; /* group */
934 *bp
++ = htonl(S_IRWXUGO
); /* unix mode */
935 *bp
++ = 0; /* segment size */
937 trace_afs_make_fs_call1(call
, &dvp
->fid
, name
);
938 afs_make_op_call(op
, call
, GFP_NOFS
);
942 * deliver reply data to an FS.Rename
944 static int afs_deliver_fs_rename(struct afs_call
*call
)
946 struct afs_operation
*op
= call
->op
;
947 struct afs_vnode_param
*orig_dvp
= &op
->file
[0];
948 struct afs_vnode_param
*new_dvp
= &op
->file
[1];
952 ret
= afs_transfer_reply(call
);
957 /* If the two dirs are the same, we have two copies of the same status
958 * report, so we just decode it twice.
960 xdr_decode_AFSFetchStatus(&bp
, call
, &orig_dvp
->scb
);
961 xdr_decode_AFSFetchStatus(&bp
, call
, &new_dvp
->scb
);
962 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
964 _leave(" = 0 [done]");
969 * FS.Rename operation type
971 static const struct afs_call_type afs_RXFSRename
= {
974 .deliver
= afs_deliver_fs_rename
,
975 .destructor
= afs_flat_call_destructor
,
979 * Rename/move a file or directory.
981 void afs_fs_rename(struct afs_operation
*op
)
983 struct afs_vnode_param
*orig_dvp
= &op
->file
[0];
984 struct afs_vnode_param
*new_dvp
= &op
->file
[1];
985 const struct qstr
*orig_name
= &op
->dentry
->d_name
;
986 const struct qstr
*new_name
= &op
->dentry_2
->d_name
;
987 struct afs_call
*call
;
988 size_t reqsz
, o_namesz
, o_padsz
, n_namesz
, n_padsz
;
993 o_namesz
= orig_name
->len
;
994 o_padsz
= (4 - (o_namesz
& 3)) & 3;
996 n_namesz
= new_name
->len
;
997 n_padsz
= (4 - (n_namesz
& 3)) & 3;
1000 4 + o_namesz
+ o_padsz
+
1002 4 + n_namesz
+ n_padsz
;
1004 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSRename
, reqsz
, (21 + 21 + 6) * 4);
1006 return afs_op_nomem(op
);
1008 /* marshall the parameters */
1010 *bp
++ = htonl(FSRENAME
);
1011 *bp
++ = htonl(orig_dvp
->fid
.vid
);
1012 *bp
++ = htonl(orig_dvp
->fid
.vnode
);
1013 *bp
++ = htonl(orig_dvp
->fid
.unique
);
1014 *bp
++ = htonl(o_namesz
);
1015 memcpy(bp
, orig_name
->name
, o_namesz
);
1016 bp
= (void *) bp
+ o_namesz
;
1018 memset(bp
, 0, o_padsz
);
1019 bp
= (void *) bp
+ o_padsz
;
1022 *bp
++ = htonl(new_dvp
->fid
.vid
);
1023 *bp
++ = htonl(new_dvp
->fid
.vnode
);
1024 *bp
++ = htonl(new_dvp
->fid
.unique
);
1025 *bp
++ = htonl(n_namesz
);
1026 memcpy(bp
, new_name
->name
, n_namesz
);
1027 bp
= (void *) bp
+ n_namesz
;
1029 memset(bp
, 0, n_padsz
);
1030 bp
= (void *) bp
+ n_padsz
;
1033 trace_afs_make_fs_call2(call
, &orig_dvp
->fid
, orig_name
, new_name
);
1034 afs_make_op_call(op
, call
, GFP_NOFS
);
1038 * Deliver reply data to FS.StoreData or FS.StoreStatus
1040 static int afs_deliver_fs_store_data(struct afs_call
*call
)
1042 struct afs_operation
*op
= call
->op
;
1043 struct afs_vnode_param
*vp
= &op
->file
[0];
1049 ret
= afs_transfer_reply(call
);
1053 /* unmarshall the reply once we've received all of it */
1055 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
1056 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
1058 _leave(" = 0 [done]");
1063 * FS.StoreData operation type
1065 static const struct afs_call_type afs_RXFSStoreData
= {
1066 .name
= "FS.StoreData",
1067 .op
= afs_FS_StoreData
,
1068 .deliver
= afs_deliver_fs_store_data
,
1069 .destructor
= afs_flat_call_destructor
,
1072 static const struct afs_call_type afs_RXFSStoreData64
= {
1073 .name
= "FS.StoreData64",
1074 .op
= afs_FS_StoreData64
,
1075 .deliver
= afs_deliver_fs_store_data
,
1076 .destructor
= afs_flat_call_destructor
,
1080 * store a set of pages to a very large file
1082 static void afs_fs_store_data64(struct afs_operation
*op
,
1083 loff_t pos
, loff_t size
, loff_t i_size
)
1085 struct afs_vnode_param
*vp
= &op
->file
[0];
1086 struct afs_call
*call
;
1089 _enter(",%x,{%llx:%llu},,",
1090 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
1092 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreData64
,
1093 (4 + 6 + 3 * 2) * 4,
1096 return afs_op_nomem(op
);
1098 call
->send_pages
= true;
1100 /* marshall the parameters */
1102 *bp
++ = htonl(FSSTOREDATA64
);
1103 *bp
++ = htonl(vp
->fid
.vid
);
1104 *bp
++ = htonl(vp
->fid
.vnode
);
1105 *bp
++ = htonl(vp
->fid
.unique
);
1107 *bp
++ = htonl(AFS_SET_MTIME
); /* mask */
1108 *bp
++ = htonl(op
->mtime
.tv_sec
); /* mtime */
1109 *bp
++ = 0; /* owner */
1110 *bp
++ = 0; /* group */
1111 *bp
++ = 0; /* unix mode */
1112 *bp
++ = 0; /* segment size */
1114 *bp
++ = htonl(upper_32_bits(pos
));
1115 *bp
++ = htonl(lower_32_bits(pos
));
1116 *bp
++ = htonl(upper_32_bits(size
));
1117 *bp
++ = htonl(lower_32_bits(size
));
1118 *bp
++ = htonl(upper_32_bits(i_size
));
1119 *bp
++ = htonl(lower_32_bits(i_size
));
1121 trace_afs_make_fs_call(call
, &vp
->fid
);
1122 afs_make_op_call(op
, call
, GFP_NOFS
);
1126 * store a set of pages
1128 void afs_fs_store_data(struct afs_operation
*op
)
1130 struct afs_vnode_param
*vp
= &op
->file
[0];
1131 struct afs_call
*call
;
1132 loff_t size
, pos
, i_size
;
1135 _enter(",%x,{%llx:%llu},,",
1136 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
1138 size
= (loff_t
)op
->store
.last_to
- (loff_t
)op
->store
.first_offset
;
1139 if (op
->store
.first
!= op
->store
.last
)
1140 size
+= (loff_t
)(op
->store
.last
- op
->store
.first
) << PAGE_SHIFT
;
1141 pos
= (loff_t
)op
->store
.first
<< PAGE_SHIFT
;
1142 pos
+= op
->store
.first_offset
;
1144 i_size
= i_size_read(&vp
->vnode
->vfs_inode
);
1145 if (pos
+ size
> i_size
)
1146 i_size
= size
+ pos
;
1148 _debug("size %llx, at %llx, i_size %llx",
1149 (unsigned long long) size
, (unsigned long long) pos
,
1150 (unsigned long long) i_size
);
1152 if (upper_32_bits(pos
) || upper_32_bits(i_size
) || upper_32_bits(size
) ||
1153 upper_32_bits(pos
+ size
))
1154 return afs_fs_store_data64(op
, pos
, size
, i_size
);
1156 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreData
,
1160 return afs_op_nomem(op
);
1162 call
->send_pages
= true;
1164 /* marshall the parameters */
1166 *bp
++ = htonl(FSSTOREDATA
);
1167 *bp
++ = htonl(vp
->fid
.vid
);
1168 *bp
++ = htonl(vp
->fid
.vnode
);
1169 *bp
++ = htonl(vp
->fid
.unique
);
1171 *bp
++ = htonl(AFS_SET_MTIME
); /* mask */
1172 *bp
++ = htonl(op
->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(lower_32_bits(pos
));
1179 *bp
++ = htonl(lower_32_bits(size
));
1180 *bp
++ = htonl(lower_32_bits(i_size
));
1182 trace_afs_make_fs_call(call
, &vp
->fid
);
1183 afs_make_op_call(op
, call
, GFP_NOFS
);
1187 * FS.StoreStatus operation type
1189 static const struct afs_call_type afs_RXFSStoreStatus
= {
1190 .name
= "FS.StoreStatus",
1191 .op
= afs_FS_StoreStatus
,
1192 .deliver
= afs_deliver_fs_store_data
,
1193 .destructor
= afs_flat_call_destructor
,
1196 static const struct afs_call_type afs_RXFSStoreData_as_Status
= {
1197 .name
= "FS.StoreData",
1198 .op
= afs_FS_StoreData
,
1199 .deliver
= afs_deliver_fs_store_data
,
1200 .destructor
= afs_flat_call_destructor
,
1203 static const struct afs_call_type afs_RXFSStoreData64_as_Status
= {
1204 .name
= "FS.StoreData64",
1205 .op
= afs_FS_StoreData64
,
1206 .deliver
= afs_deliver_fs_store_data
,
1207 .destructor
= afs_flat_call_destructor
,
1211 * set the attributes on a very large file, using FS.StoreData rather than
1212 * FS.StoreStatus so as to alter the file size also
1214 static void afs_fs_setattr_size64(struct afs_operation
*op
)
1216 struct afs_vnode_param
*vp
= &op
->file
[0];
1217 struct afs_call
*call
;
1218 struct iattr
*attr
= op
->setattr
.attr
;
1221 _enter(",%x,{%llx:%llu},,",
1222 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
1224 ASSERT(attr
->ia_valid
& ATTR_SIZE
);
1226 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreData64_as_Status
,
1227 (4 + 6 + 3 * 2) * 4,
1230 return afs_op_nomem(op
);
1232 /* marshall the parameters */
1234 *bp
++ = htonl(FSSTOREDATA64
);
1235 *bp
++ = htonl(vp
->fid
.vid
);
1236 *bp
++ = htonl(vp
->fid
.vnode
);
1237 *bp
++ = htonl(vp
->fid
.unique
);
1239 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1241 *bp
++ = htonl(upper_32_bits(attr
->ia_size
)); /* position of start of write */
1242 *bp
++ = htonl(lower_32_bits(attr
->ia_size
));
1243 *bp
++ = 0; /* size of write */
1245 *bp
++ = htonl(upper_32_bits(attr
->ia_size
)); /* new file length */
1246 *bp
++ = htonl(lower_32_bits(attr
->ia_size
));
1248 trace_afs_make_fs_call(call
, &vp
->fid
);
1249 afs_make_op_call(op
, call
, GFP_NOFS
);
1253 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1254 * so as to alter the file size also
1256 static void afs_fs_setattr_size(struct afs_operation
*op
)
1258 struct afs_vnode_param
*vp
= &op
->file
[0];
1259 struct afs_call
*call
;
1260 struct iattr
*attr
= op
->setattr
.attr
;
1263 _enter(",%x,{%llx:%llu},,",
1264 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
1266 ASSERT(attr
->ia_valid
& ATTR_SIZE
);
1267 if (upper_32_bits(attr
->ia_size
))
1268 return afs_fs_setattr_size64(op
);
1270 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreData_as_Status
,
1274 return afs_op_nomem(op
);
1276 /* marshall the parameters */
1278 *bp
++ = htonl(FSSTOREDATA
);
1279 *bp
++ = htonl(vp
->fid
.vid
);
1280 *bp
++ = htonl(vp
->fid
.vnode
);
1281 *bp
++ = htonl(vp
->fid
.unique
);
1283 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1285 *bp
++ = htonl(attr
->ia_size
); /* position of start of write */
1286 *bp
++ = 0; /* size of write */
1287 *bp
++ = htonl(attr
->ia_size
); /* new file length */
1289 trace_afs_make_fs_call(call
, &vp
->fid
);
1290 afs_make_op_call(op
, call
, GFP_NOFS
);
1294 * set the attributes on a file, using FS.StoreData if there's a change in file
1295 * size, and FS.StoreStatus otherwise
1297 void afs_fs_setattr(struct afs_operation
*op
)
1299 struct afs_vnode_param
*vp
= &op
->file
[0];
1300 struct afs_call
*call
;
1301 struct iattr
*attr
= op
->setattr
.attr
;
1304 if (attr
->ia_valid
& ATTR_SIZE
)
1305 return afs_fs_setattr_size(op
);
1307 _enter(",%x,{%llx:%llu},,",
1308 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
1310 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreStatus
,
1314 return afs_op_nomem(op
);
1316 /* marshall the parameters */
1318 *bp
++ = htonl(FSSTORESTATUS
);
1319 *bp
++ = htonl(vp
->fid
.vid
);
1320 *bp
++ = htonl(vp
->fid
.vnode
);
1321 *bp
++ = htonl(vp
->fid
.unique
);
1323 xdr_encode_AFS_StoreStatus(&bp
, op
->setattr
.attr
);
1325 trace_afs_make_fs_call(call
, &vp
->fid
);
1326 afs_make_op_call(op
, call
, GFP_NOFS
);
1330 * deliver reply data to an FS.GetVolumeStatus
1332 static int afs_deliver_fs_get_volume_status(struct afs_call
*call
)
1334 struct afs_operation
*op
= call
->op
;
1340 _enter("{%u}", call
->unmarshall
);
1342 switch (call
->unmarshall
) {
1345 afs_extract_to_buf(call
, 12 * 4);
1348 /* extract the returned status record */
1350 _debug("extract status");
1351 ret
= afs_extract_data(call
, true);
1356 xdr_decode_AFSFetchVolumeStatus(&bp
, &op
->volstatus
.vs
);
1358 afs_extract_to_tmp(call
);
1361 /* extract the volume name length */
1363 ret
= afs_extract_data(call
, true);
1367 call
->count
= ntohl(call
->tmp
);
1368 _debug("volname length: %u", call
->count
);
1369 if (call
->count
>= AFSNAMEMAX
)
1370 return afs_protocol_error(call
, afs_eproto_volname_len
);
1371 size
= (call
->count
+ 3) & ~3; /* It's padded */
1372 afs_extract_to_buf(call
, size
);
1376 /* extract the volume name */
1378 _debug("extract volname");
1379 ret
= afs_extract_data(call
, true);
1385 _debug("volname '%s'", p
);
1386 afs_extract_to_tmp(call
);
1390 /* extract the offline message length */
1392 ret
= afs_extract_data(call
, true);
1396 call
->count
= ntohl(call
->tmp
);
1397 _debug("offline msg length: %u", call
->count
);
1398 if (call
->count
>= AFSNAMEMAX
)
1399 return afs_protocol_error(call
, afs_eproto_offline_msg_len
);
1400 size
= (call
->count
+ 3) & ~3; /* It's padded */
1401 afs_extract_to_buf(call
, size
);
1405 /* extract the offline message */
1407 _debug("extract offline");
1408 ret
= afs_extract_data(call
, true);
1414 _debug("offline '%s'", p
);
1416 afs_extract_to_tmp(call
);
1420 /* extract the message of the day length */
1422 ret
= afs_extract_data(call
, true);
1426 call
->count
= ntohl(call
->tmp
);
1427 _debug("motd length: %u", call
->count
);
1428 if (call
->count
>= AFSNAMEMAX
)
1429 return afs_protocol_error(call
, afs_eproto_motd_len
);
1430 size
= (call
->count
+ 3) & ~3; /* It's padded */
1431 afs_extract_to_buf(call
, size
);
1435 /* extract the message of the day */
1437 _debug("extract motd");
1438 ret
= afs_extract_data(call
, false);
1444 _debug("motd '%s'", p
);
1452 _leave(" = 0 [done]");
1457 * FS.GetVolumeStatus operation type
1459 static const struct afs_call_type afs_RXFSGetVolumeStatus
= {
1460 .name
= "FS.GetVolumeStatus",
1461 .op
= afs_FS_GetVolumeStatus
,
1462 .deliver
= afs_deliver_fs_get_volume_status
,
1463 .destructor
= afs_flat_call_destructor
,
1467 * fetch the status of a volume
1469 void afs_fs_get_volume_status(struct afs_operation
*op
)
1471 struct afs_vnode_param
*vp
= &op
->file
[0];
1472 struct afs_call
*call
;
1477 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSGetVolumeStatus
, 2 * 4,
1478 max(12 * 4, AFSOPAQUEMAX
+ 1));
1480 return afs_op_nomem(op
);
1482 /* marshall the parameters */
1484 bp
[0] = htonl(FSGETVOLUMESTATUS
);
1485 bp
[1] = htonl(vp
->fid
.vid
);
1487 trace_afs_make_fs_call(call
, &vp
->fid
);
1488 afs_make_op_call(op
, call
, GFP_NOFS
);
1492 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1494 static int afs_deliver_fs_xxxx_lock(struct afs_call
*call
)
1496 struct afs_operation
*op
= call
->op
;
1500 _enter("{%u}", call
->unmarshall
);
1502 ret
= afs_transfer_reply(call
);
1506 /* unmarshall the reply once we've received all of it */
1508 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
1510 _leave(" = 0 [done]");
1515 * FS.SetLock operation type
1517 static const struct afs_call_type afs_RXFSSetLock
= {
1518 .name
= "FS.SetLock",
1519 .op
= afs_FS_SetLock
,
1520 .deliver
= afs_deliver_fs_xxxx_lock
,
1521 .done
= afs_lock_op_done
,
1522 .destructor
= afs_flat_call_destructor
,
1526 * FS.ExtendLock operation type
1528 static const struct afs_call_type afs_RXFSExtendLock
= {
1529 .name
= "FS.ExtendLock",
1530 .op
= afs_FS_ExtendLock
,
1531 .deliver
= afs_deliver_fs_xxxx_lock
,
1532 .done
= afs_lock_op_done
,
1533 .destructor
= afs_flat_call_destructor
,
1537 * FS.ReleaseLock operation type
1539 static const struct afs_call_type afs_RXFSReleaseLock
= {
1540 .name
= "FS.ReleaseLock",
1541 .op
= afs_FS_ReleaseLock
,
1542 .deliver
= afs_deliver_fs_xxxx_lock
,
1543 .destructor
= afs_flat_call_destructor
,
1547 * Set a lock on a file
1549 void afs_fs_set_lock(struct afs_operation
*op
)
1551 struct afs_vnode_param
*vp
= &op
->file
[0];
1552 struct afs_call
*call
;
1557 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSSetLock
, 5 * 4, 6 * 4);
1559 return afs_op_nomem(op
);
1561 /* marshall the parameters */
1563 *bp
++ = htonl(FSSETLOCK
);
1564 *bp
++ = htonl(vp
->fid
.vid
);
1565 *bp
++ = htonl(vp
->fid
.vnode
);
1566 *bp
++ = htonl(vp
->fid
.unique
);
1567 *bp
++ = htonl(op
->lock
.type
);
1569 trace_afs_make_fs_calli(call
, &vp
->fid
, op
->lock
.type
);
1570 afs_make_op_call(op
, call
, GFP_NOFS
);
1574 * extend a lock on a file
1576 void afs_fs_extend_lock(struct afs_operation
*op
)
1578 struct afs_vnode_param
*vp
= &op
->file
[0];
1579 struct afs_call
*call
;
1584 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSExtendLock
, 4 * 4, 6 * 4);
1586 return afs_op_nomem(op
);
1588 /* marshall the parameters */
1590 *bp
++ = htonl(FSEXTENDLOCK
);
1591 *bp
++ = htonl(vp
->fid
.vid
);
1592 *bp
++ = htonl(vp
->fid
.vnode
);
1593 *bp
++ = htonl(vp
->fid
.unique
);
1595 trace_afs_make_fs_call(call
, &vp
->fid
);
1596 afs_make_op_call(op
, call
, GFP_NOFS
);
1600 * release a lock on a file
1602 void afs_fs_release_lock(struct afs_operation
*op
)
1604 struct afs_vnode_param
*vp
= &op
->file
[0];
1605 struct afs_call
*call
;
1610 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSReleaseLock
, 4 * 4, 6 * 4);
1612 return afs_op_nomem(op
);
1614 /* marshall the parameters */
1616 *bp
++ = htonl(FSRELEASELOCK
);
1617 *bp
++ = htonl(vp
->fid
.vid
);
1618 *bp
++ = htonl(vp
->fid
.vnode
);
1619 *bp
++ = htonl(vp
->fid
.unique
);
1621 trace_afs_make_fs_call(call
, &vp
->fid
);
1622 afs_make_op_call(op
, call
, GFP_NOFS
);
1626 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1628 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call
*call
)
1630 return afs_transfer_reply(call
);
1634 * FS.GiveUpAllCallBacks operation type
1636 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks
= {
1637 .name
= "FS.GiveUpAllCallBacks",
1638 .op
= afs_FS_GiveUpAllCallBacks
,
1639 .deliver
= afs_deliver_fs_give_up_all_callbacks
,
1640 .destructor
= afs_flat_call_destructor
,
1644 * Flush all the callbacks we have on a server.
1646 int afs_fs_give_up_all_callbacks(struct afs_net
*net
,
1647 struct afs_server
*server
,
1648 struct afs_addr_cursor
*ac
,
1651 struct afs_call
*call
;
1656 call
= afs_alloc_flat_call(net
, &afs_RXFSGiveUpAllCallBacks
, 1 * 4, 0);
1662 /* marshall the parameters */
1664 *bp
++ = htonl(FSGIVEUPALLCALLBACKS
);
1666 call
->server
= afs_use_server(server
, afs_server_trace_give_up_cb
);
1667 afs_make_call(ac
, call
, GFP_NOFS
);
1668 return afs_wait_for_call_to_complete(call
, ac
);
1672 * Deliver reply data to an FS.GetCapabilities operation.
1674 static int afs_deliver_fs_get_capabilities(struct afs_call
*call
)
1679 _enter("{%u,%zu}", call
->unmarshall
, iov_iter_count(call
->iter
));
1681 switch (call
->unmarshall
) {
1683 afs_extract_to_tmp(call
);
1687 /* Extract the capabilities word count */
1689 ret
= afs_extract_data(call
, true);
1693 count
= ntohl(call
->tmp
);
1695 call
->count
= count
;
1696 call
->count2
= count
;
1697 afs_extract_discard(call
, count
* sizeof(__be32
));
1701 /* Extract capabilities words */
1703 ret
= afs_extract_data(call
, false);
1707 /* TODO: Examine capabilities */
1713 _leave(" = 0 [done]");
1718 * FS.GetCapabilities operation type
1720 static const struct afs_call_type afs_RXFSGetCapabilities
= {
1721 .name
= "FS.GetCapabilities",
1722 .op
= afs_FS_GetCapabilities
,
1723 .deliver
= afs_deliver_fs_get_capabilities
,
1724 .done
= afs_fileserver_probe_result
,
1725 .destructor
= afs_flat_call_destructor
,
1729 * Probe a fileserver for the capabilities that it supports. This RPC can
1730 * reply with up to 196 words. The operation is asynchronous and if we managed
1731 * to allocate a call, true is returned the result is delivered through the
1732 * ->done() - otherwise we return false to indicate we didn't even try.
1734 bool afs_fs_get_capabilities(struct afs_net
*net
, struct afs_server
*server
,
1735 struct afs_addr_cursor
*ac
, struct key
*key
)
1737 struct afs_call
*call
;
1742 call
= afs_alloc_flat_call(net
, &afs_RXFSGetCapabilities
, 1 * 4, 16 * 4);
1747 call
->server
= afs_use_server(server
, afs_server_trace_get_caps
);
1748 call
->upgrade
= true;
1750 call
->max_lifespan
= AFS_PROBE_MAX_LIFESPAN
;
1752 /* marshall the parameters */
1754 *bp
++ = htonl(FSGETCAPABILITIES
);
1756 trace_afs_make_fs_call(call
, NULL
);
1757 afs_make_call(ac
, call
, GFP_NOFS
);
1763 * Deliver reply data to an FS.InlineBulkStatus call
1765 static int afs_deliver_fs_inline_bulk_status(struct afs_call
*call
)
1767 struct afs_operation
*op
= call
->op
;
1768 struct afs_status_cb
*scb
;
1773 _enter("{%u}", call
->unmarshall
);
1775 switch (call
->unmarshall
) {
1777 afs_extract_to_tmp(call
);
1781 /* Extract the file status count and array in two steps */
1783 _debug("extract status count");
1784 ret
= afs_extract_data(call
, true);
1788 tmp
= ntohl(call
->tmp
);
1789 _debug("status count: %u/%u", tmp
, op
->nr_files
);
1790 if (tmp
!= op
->nr_files
)
1791 return afs_protocol_error(call
, afs_eproto_ibulkst_count
);
1796 afs_extract_to_buf(call
, 21 * sizeof(__be32
));
1800 _debug("extract status array %u", call
->count
);
1801 ret
= afs_extract_data(call
, true);
1805 switch (call
->count
) {
1807 scb
= &op
->file
[0].scb
;
1810 scb
= &op
->file
[1].scb
;
1813 scb
= &op
->more_files
[call
->count
- 2].scb
;
1818 xdr_decode_AFSFetchStatus(&bp
, call
, scb
);
1821 if (call
->count
< op
->nr_files
)
1826 afs_extract_to_tmp(call
);
1829 /* Extract the callback count and array in two steps */
1831 _debug("extract CB count");
1832 ret
= afs_extract_data(call
, true);
1836 tmp
= ntohl(call
->tmp
);
1837 _debug("CB count: %u", tmp
);
1838 if (tmp
!= op
->nr_files
)
1839 return afs_protocol_error(call
, afs_eproto_ibulkst_cb_count
);
1843 afs_extract_to_buf(call
, 3 * sizeof(__be32
));
1847 _debug("extract CB array");
1848 ret
= afs_extract_data(call
, true);
1852 _debug("unmarshall CB array");
1853 switch (call
->count
) {
1855 scb
= &op
->file
[0].scb
;
1858 scb
= &op
->file
[1].scb
;
1861 scb
= &op
->more_files
[call
->count
- 2].scb
;
1866 xdr_decode_AFSCallBack(&bp
, call
, scb
);
1868 if (call
->count
< op
->nr_files
)
1871 afs_extract_to_buf(call
, 6 * sizeof(__be32
));
1876 ret
= afs_extract_data(call
, false);
1881 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
1889 _leave(" = 0 [done]");
1893 static void afs_done_fs_inline_bulk_status(struct afs_call
*call
)
1895 if (call
->error
== -ECONNABORTED
&&
1896 call
->abort_code
== RX_INVALID_OPERATION
) {
1897 set_bit(AFS_SERVER_FL_NO_IBULK
, &call
->server
->flags
);
1899 set_bit(AFS_VOLUME_MAYBE_NO_IBULK
, &call
->op
->volume
->flags
);
1904 * FS.InlineBulkStatus operation type
1906 static const struct afs_call_type afs_RXFSInlineBulkStatus
= {
1907 .name
= "FS.InlineBulkStatus",
1908 .op
= afs_FS_InlineBulkStatus
,
1909 .deliver
= afs_deliver_fs_inline_bulk_status
,
1910 .done
= afs_done_fs_inline_bulk_status
,
1911 .destructor
= afs_flat_call_destructor
,
1915 * Fetch the status information for up to 50 files
1917 void afs_fs_inline_bulk_status(struct afs_operation
*op
)
1919 struct afs_vnode_param
*dvp
= &op
->file
[0];
1920 struct afs_vnode_param
*vp
= &op
->file
[1];
1921 struct afs_call
*call
;
1925 if (test_bit(AFS_SERVER_FL_NO_IBULK
, &op
->server
->flags
)) {
1926 op
->error
= -ENOTSUPP
;
1930 _enter(",%x,{%llx:%llu},%u",
1931 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
, op
->nr_files
);
1933 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSInlineBulkStatus
,
1934 (2 + op
->nr_files
* 3) * 4,
1937 return afs_op_nomem(op
);
1939 /* marshall the parameters */
1941 *bp
++ = htonl(FSINLINEBULKSTATUS
);
1942 *bp
++ = htonl(op
->nr_files
);
1943 *bp
++ = htonl(dvp
->fid
.vid
);
1944 *bp
++ = htonl(dvp
->fid
.vnode
);
1945 *bp
++ = htonl(dvp
->fid
.unique
);
1946 *bp
++ = htonl(vp
->fid
.vid
);
1947 *bp
++ = htonl(vp
->fid
.vnode
);
1948 *bp
++ = htonl(vp
->fid
.unique
);
1949 for (i
= 0; i
< op
->nr_files
- 2; i
++) {
1950 *bp
++ = htonl(op
->more_files
[i
].fid
.vid
);
1951 *bp
++ = htonl(op
->more_files
[i
].fid
.vnode
);
1952 *bp
++ = htonl(op
->more_files
[i
].fid
.unique
);
1955 trace_afs_make_fs_call(call
, &vp
->fid
);
1956 afs_make_op_call(op
, call
, GFP_NOFS
);
1960 * deliver reply data to an FS.FetchACL
1962 static int afs_deliver_fs_fetch_acl(struct afs_call
*call
)
1964 struct afs_operation
*op
= call
->op
;
1965 struct afs_vnode_param
*vp
= &op
->file
[0];
1966 struct afs_acl
*acl
;
1971 _enter("{%u}", call
->unmarshall
);
1973 switch (call
->unmarshall
) {
1975 afs_extract_to_tmp(call
);
1979 /* extract the returned data length */
1981 ret
= afs_extract_data(call
, true);
1985 size
= call
->count2
= ntohl(call
->tmp
);
1986 size
= round_up(size
, 4);
1988 acl
= kmalloc(struct_size(acl
, data
, size
), GFP_KERNEL
);
1992 acl
->size
= call
->count2
;
1993 afs_extract_begin(call
, acl
->data
, size
);
1997 /* extract the returned data */
1999 ret
= afs_extract_data(call
, true);
2003 afs_extract_to_buf(call
, (21 + 6) * 4);
2007 /* extract the metadata */
2009 ret
= afs_extract_data(call
, false);
2014 xdr_decode_AFSFetchStatus(&bp
, call
, &vp
->scb
);
2015 xdr_decode_AFSVolSync(&bp
, &op
->volsync
);
2023 _leave(" = 0 [done]");
2028 * FS.FetchACL operation type
2030 static const struct afs_call_type afs_RXFSFetchACL
= {
2031 .name
= "FS.FetchACL",
2032 .op
= afs_FS_FetchACL
,
2033 .deliver
= afs_deliver_fs_fetch_acl
,
2037 * Fetch the ACL for a file.
2039 void afs_fs_fetch_acl(struct afs_operation
*op
)
2041 struct afs_vnode_param
*vp
= &op
->file
[0];
2042 struct afs_call
*call
;
2045 _enter(",%x,{%llx:%llu},,",
2046 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
2048 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSFetchACL
, 16, (21 + 6) * 4);
2050 return afs_op_nomem(op
);
2052 /* marshall the parameters */
2054 bp
[0] = htonl(FSFETCHACL
);
2055 bp
[1] = htonl(vp
->fid
.vid
);
2056 bp
[2] = htonl(vp
->fid
.vnode
);
2057 bp
[3] = htonl(vp
->fid
.unique
);
2059 trace_afs_make_fs_call(call
, &vp
->fid
);
2060 afs_make_op_call(op
, call
, GFP_KERNEL
);
2064 * FS.StoreACL operation type
2066 static const struct afs_call_type afs_RXFSStoreACL
= {
2067 .name
= "FS.StoreACL",
2068 .op
= afs_FS_StoreACL
,
2069 .deliver
= afs_deliver_fs_file_status_and_vol
,
2070 .destructor
= afs_flat_call_destructor
,
2074 * Fetch the ACL for a file.
2076 void afs_fs_store_acl(struct afs_operation
*op
)
2078 struct afs_vnode_param
*vp
= &op
->file
[0];
2079 struct afs_call
*call
;
2080 const struct afs_acl
*acl
= op
->acl
;
2084 _enter(",%x,{%llx:%llu},,",
2085 key_serial(op
->key
), vp
->fid
.vid
, vp
->fid
.vnode
);
2087 size
= round_up(acl
->size
, 4);
2088 call
= afs_alloc_flat_call(op
->net
, &afs_RXFSStoreACL
,
2089 5 * 4 + size
, (21 + 6) * 4);
2091 return afs_op_nomem(op
);
2093 /* marshall the parameters */
2095 bp
[0] = htonl(FSSTOREACL
);
2096 bp
[1] = htonl(vp
->fid
.vid
);
2097 bp
[2] = htonl(vp
->fid
.vnode
);
2098 bp
[3] = htonl(vp
->fid
.unique
);
2099 bp
[4] = htonl(acl
->size
);
2100 memcpy(&bp
[5], acl
->data
, acl
->size
);
2101 if (acl
->size
!= size
)
2102 memset((void *)&bp
[5] + acl
->size
, 0, size
- acl
->size
);
2104 trace_afs_make_fs_call(call
, &vp
->fid
);
2105 afs_make_op_call(op
, call
, GFP_KERNEL
);