1 /* AFS File Server client stubs
3 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/sched.h>
15 #include <linux/circ_buf.h>
16 #include <linux/iversion.h>
21 static const struct afs_fid afs_zero_fid
;
24 * We need somewhere to discard into in case the server helpfully returns more
25 * than we asked for in FS.FetchData{,64}.
27 static u8 afs_discard_buffer
[64];
29 static inline void afs_use_fs_server(struct afs_call
*call
, struct afs_cb_interest
*cbi
)
31 call
->cbi
= afs_get_cb_interest(cbi
);
35 * decode an AFSFid block
37 static void xdr_decode_AFSFid(const __be32
**_bp
, struct afs_fid
*fid
)
39 const __be32
*bp
= *_bp
;
41 fid
->vid
= ntohl(*bp
++);
42 fid
->vnode
= ntohl(*bp
++);
43 fid
->unique
= ntohl(*bp
++);
48 * Dump a bad file status record.
50 static void xdr_dump_bad(const __be32
*bp
)
55 pr_notice("AFS XDR: Bad status record\n");
56 for (i
= 0; i
< 5 * 4 * 4; i
+= 16) {
59 pr_notice("%03x: %08x %08x %08x %08x\n",
60 i
, ntohl(x
[0]), ntohl(x
[1]), ntohl(x
[2]), ntohl(x
[3]));
64 pr_notice("0x50: %08x\n", ntohl(x
[0]));
68 * Update the core inode struct from a returned status record.
70 void afs_update_inode_from_status(struct afs_vnode
*vnode
,
71 struct afs_file_status
*status
,
72 const afs_dataversion_t
*expected_version
,
78 t
.tv_sec
= status
->mtime_client
;
80 vnode
->vfs_inode
.i_ctime
= t
;
81 vnode
->vfs_inode
.i_mtime
= t
;
82 vnode
->vfs_inode
.i_atime
= t
;
84 if (flags
& (AFS_VNODE_META_CHANGED
| AFS_VNODE_NOT_YET_SET
)) {
85 vnode
->vfs_inode
.i_uid
= make_kuid(&init_user_ns
, status
->owner
);
86 vnode
->vfs_inode
.i_gid
= make_kgid(&init_user_ns
, status
->group
);
87 set_nlink(&vnode
->vfs_inode
, status
->nlink
);
89 mode
= vnode
->vfs_inode
.i_mode
;
93 vnode
->vfs_inode
.i_mode
= mode
;
96 if (!(flags
& AFS_VNODE_NOT_YET_SET
)) {
97 if (expected_version
&&
98 *expected_version
!= status
->data_version
) {
99 _debug("vnode modified %llx on {%x:%u} [exp %llx]",
100 (unsigned long long) status
->data_version
,
101 vnode
->fid
.vid
, vnode
->fid
.vnode
,
102 (unsigned long long) *expected_version
);
103 vnode
->invalid_before
= status
->data_version
;
104 if (vnode
->status
.type
== AFS_FTYPE_DIR
) {
105 if (test_and_clear_bit(AFS_VNODE_DIR_VALID
, &vnode
->flags
))
106 afs_stat_v(vnode
, n_inval
);
108 set_bit(AFS_VNODE_ZAP_DATA
, &vnode
->flags
);
110 } else if (vnode
->status
.type
== AFS_FTYPE_DIR
) {
111 /* Expected directory change is handled elsewhere so
112 * that we can locally edit the directory and save on a
115 if (test_bit(AFS_VNODE_DIR_VALID
, &vnode
->flags
))
116 flags
&= ~AFS_VNODE_DATA_CHANGED
;
120 if (flags
& (AFS_VNODE_DATA_CHANGED
| AFS_VNODE_NOT_YET_SET
)) {
121 inode_set_iversion_raw(&vnode
->vfs_inode
, status
->data_version
);
122 i_size_write(&vnode
->vfs_inode
, status
->size
);
127 * decode an AFSFetchStatus block
129 static int xdr_decode_AFSFetchStatus(struct afs_call
*call
,
131 struct afs_file_status
*status
,
132 struct afs_vnode
*vnode
,
133 const afs_dataversion_t
*expected_version
,
134 struct afs_read
*read_req
)
136 const struct afs_xdr_AFSFetchStatus
*xdr
= (const void *)*_bp
;
137 bool inline_error
= (call
->operation_ID
== afs_FS_InlineBulkStatus
);
138 u64 data_version
, size
;
139 u32 type
, abort_code
;
142 abort_code
= ntohl(xdr
->abort_code
);
144 if (xdr
->if_version
!= htonl(AFS_FSTATUS_VERSION
)) {
145 if (xdr
->if_version
== htonl(0) &&
148 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
149 * whereby it doesn't set the interface version in the error
152 status
->abort_code
= abort_code
;
156 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr
->if_version
));
160 if (abort_code
!= 0 && inline_error
) {
161 status
->abort_code
= abort_code
;
165 type
= ntohl(xdr
->type
);
169 case AFS_FTYPE_SYMLINK
:
170 if (type
!= status
->type
&&
172 !test_bit(AFS_VNODE_UNSET
, &vnode
->flags
)) {
173 pr_warning("Vnode %x:%x:%x changed type %u to %u\n",
186 #define EXTRACT_M(FIELD) \
188 u32 x = ntohl(xdr->FIELD); \
189 if (status->FIELD != x) { \
190 flags |= AFS_VNODE_META_CHANGED; \
198 EXTRACT_M(caller_access
); /* call ticket dependent */
199 EXTRACT_M(anon_access
);
203 status
->mtime_client
= ntohl(xdr
->mtime_client
);
204 status
->mtime_server
= ntohl(xdr
->mtime_server
);
205 status
->lock_count
= ntohl(xdr
->lock_count
);
207 size
= (u64
)ntohl(xdr
->size_lo
);
208 size
|= (u64
)ntohl(xdr
->size_hi
) << 32;
211 data_version
= (u64
)ntohl(xdr
->data_version_lo
);
212 data_version
|= (u64
)ntohl(xdr
->data_version_hi
) << 32;
213 if (data_version
!= status
->data_version
) {
214 status
->data_version
= data_version
;
215 flags
|= AFS_VNODE_DATA_CHANGED
;
219 read_req
->data_version
= data_version
;
220 read_req
->file_size
= size
;
223 *_bp
= (const void *)*_bp
+ sizeof(*xdr
);
226 if (test_bit(AFS_VNODE_UNSET
, &vnode
->flags
))
227 flags
|= AFS_VNODE_NOT_YET_SET
;
228 afs_update_inode_from_status(vnode
, status
, expected_version
,
236 return afs_protocol_error(call
, -EBADMSG
);
240 * Decode the file status. We need to lock the target vnode if we're going to
241 * update its status so that stat() sees the attributes update atomically.
243 static int afs_decode_status(struct afs_call
*call
,
245 struct afs_file_status
*status
,
246 struct afs_vnode
*vnode
,
247 const afs_dataversion_t
*expected_version
,
248 struct afs_read
*read_req
)
253 return xdr_decode_AFSFetchStatus(call
, _bp
, status
, vnode
,
254 expected_version
, read_req
);
256 write_seqlock(&vnode
->cb_lock
);
257 ret
= xdr_decode_AFSFetchStatus(call
, _bp
, status
, vnode
,
258 expected_version
, read_req
);
259 write_sequnlock(&vnode
->cb_lock
);
264 * decode an AFSCallBack block
266 static void xdr_decode_AFSCallBack(struct afs_call
*call
,
267 struct afs_vnode
*vnode
,
270 struct afs_cb_interest
*old
, *cbi
= call
->cbi
;
271 const __be32
*bp
= *_bp
;
274 write_seqlock(&vnode
->cb_lock
);
276 if (call
->cb_break
== afs_cb_break_sum(vnode
, cbi
)) {
277 vnode
->cb_version
= ntohl(*bp
++);
278 cb_expiry
= ntohl(*bp
++);
279 vnode
->cb_type
= ntohl(*bp
++);
280 vnode
->cb_expires_at
= cb_expiry
+ ktime_get_real_seconds();
281 old
= vnode
->cb_interest
;
282 if (old
!= call
->cbi
) {
283 vnode
->cb_interest
= cbi
;
286 set_bit(AFS_VNODE_CB_PROMISED
, &vnode
->flags
);
291 write_sequnlock(&vnode
->cb_lock
);
296 static void xdr_decode_AFSCallBack_raw(const __be32
**_bp
,
297 struct afs_callback
*cb
)
299 const __be32
*bp
= *_bp
;
301 cb
->version
= ntohl(*bp
++);
302 cb
->expiry
= ntohl(*bp
++);
303 cb
->type
= ntohl(*bp
++);
308 * decode an AFSVolSync block
310 static void xdr_decode_AFSVolSync(const __be32
**_bp
,
311 struct afs_volsync
*volsync
)
313 const __be32
*bp
= *_bp
;
315 volsync
->creation
= ntohl(*bp
++);
325 * encode the requested attributes into an AFSStoreStatus block
327 static void xdr_encode_AFS_StoreStatus(__be32
**_bp
, struct iattr
*attr
)
330 u32 mask
= 0, mtime
= 0, owner
= 0, group
= 0, mode
= 0;
333 if (attr
->ia_valid
& ATTR_MTIME
) {
334 mask
|= AFS_SET_MTIME
;
335 mtime
= attr
->ia_mtime
.tv_sec
;
338 if (attr
->ia_valid
& ATTR_UID
) {
339 mask
|= AFS_SET_OWNER
;
340 owner
= from_kuid(&init_user_ns
, attr
->ia_uid
);
343 if (attr
->ia_valid
& ATTR_GID
) {
344 mask
|= AFS_SET_GROUP
;
345 group
= from_kgid(&init_user_ns
, attr
->ia_gid
);
348 if (attr
->ia_valid
& ATTR_MODE
) {
349 mask
|= AFS_SET_MODE
;
350 mode
= attr
->ia_mode
& S_IALLUGO
;
354 *bp
++ = htonl(mtime
);
355 *bp
++ = htonl(owner
);
356 *bp
++ = htonl(group
);
358 *bp
++ = 0; /* segment size */
363 * decode an AFSFetchVolumeStatus block
365 static void xdr_decode_AFSFetchVolumeStatus(const __be32
**_bp
,
366 struct afs_volume_status
*vs
)
368 const __be32
*bp
= *_bp
;
370 vs
->vid
= ntohl(*bp
++);
371 vs
->parent_id
= ntohl(*bp
++);
372 vs
->online
= ntohl(*bp
++);
373 vs
->in_service
= ntohl(*bp
++);
374 vs
->blessed
= ntohl(*bp
++);
375 vs
->needs_salvage
= ntohl(*bp
++);
376 vs
->type
= ntohl(*bp
++);
377 vs
->min_quota
= ntohl(*bp
++);
378 vs
->max_quota
= ntohl(*bp
++);
379 vs
->blocks_in_use
= ntohl(*bp
++);
380 vs
->part_blocks_avail
= ntohl(*bp
++);
381 vs
->part_max_blocks
= ntohl(*bp
++);
386 * deliver reply data to an FS.FetchStatus
388 static int afs_deliver_fs_fetch_status_vnode(struct afs_call
*call
)
390 struct afs_vnode
*vnode
= call
->reply
[0];
394 ret
= afs_transfer_reply(call
);
398 _enter("{%x:%u}", vnode
->fid
.vid
, vnode
->fid
.vnode
);
400 /* unmarshall the reply once we've received all of it */
402 if (afs_decode_status(call
, &bp
, &vnode
->status
, vnode
,
403 &call
->expected_version
, NULL
) < 0)
404 return afs_protocol_error(call
, -EBADMSG
);
405 xdr_decode_AFSCallBack(call
, vnode
, &bp
);
407 xdr_decode_AFSVolSync(&bp
, call
->reply
[1]);
409 _leave(" = 0 [done]");
414 * FS.FetchStatus operation type
416 static const struct afs_call_type afs_RXFSFetchStatus_vnode
= {
417 .name
= "FS.FetchStatus(vnode)",
418 .op
= afs_FS_FetchStatus
,
419 .deliver
= afs_deliver_fs_fetch_status_vnode
,
420 .destructor
= afs_flat_call_destructor
,
424 * fetch the status information for a file
426 int afs_fs_fetch_file_status(struct afs_fs_cursor
*fc
, struct afs_volsync
*volsync
,
429 struct afs_vnode
*vnode
= fc
->vnode
;
430 struct afs_call
*call
;
431 struct afs_net
*net
= afs_v2net(vnode
);
434 _enter(",%x,{%x:%u},,",
435 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
437 call
= afs_alloc_flat_call(net
, &afs_RXFSFetchStatus_vnode
,
438 16, (21 + 3 + 6) * 4);
440 fc
->ac
.error
= -ENOMEM
;
445 call
->reply
[0] = vnode
;
446 call
->reply
[1] = volsync
;
447 call
->expected_version
= new_inode
? 1 : vnode
->status
.data_version
;
449 /* marshall the parameters */
451 bp
[0] = htonl(FSFETCHSTATUS
);
452 bp
[1] = htonl(vnode
->fid
.vid
);
453 bp
[2] = htonl(vnode
->fid
.vnode
);
454 bp
[3] = htonl(vnode
->fid
.unique
);
456 call
->cb_break
= fc
->cb_break
;
457 afs_use_fs_server(call
, fc
->cbi
);
458 trace_afs_make_fs_call(call
, &vnode
->fid
);
459 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
463 * deliver reply data to an FS.FetchData
465 static int afs_deliver_fs_fetch_data(struct afs_call
*call
)
467 struct afs_vnode
*vnode
= call
->reply
[0];
468 struct afs_read
*req
= call
->reply
[2];
474 _enter("{%u,%zu/%u;%llu/%llu}",
475 call
->unmarshall
, call
->offset
, call
->count
,
476 req
->remain
, req
->actual_len
);
478 switch (call
->unmarshall
) {
483 if (call
->operation_ID
!= FSFETCHDATA64
) {
488 /* extract the upper part of the returned data length of an
489 * FSFETCHDATA64 op (which should always be 0 using this
492 _debug("extract data length (MSW)");
493 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
497 req
->actual_len
= ntohl(call
->tmp
);
498 req
->actual_len
<<= 32;
503 /* extract the returned data length */
505 _debug("extract data length");
506 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
510 req
->actual_len
|= ntohl(call
->tmp
);
511 _debug("DATA length: %llu", req
->actual_len
);
513 req
->remain
= req
->actual_len
;
514 call
->offset
= req
->pos
& (PAGE_SIZE
- 1);
516 if (req
->actual_len
== 0)
521 ASSERTCMP(req
->index
, <, req
->nr_pages
);
522 if (req
->remain
> PAGE_SIZE
- call
->offset
)
523 size
= PAGE_SIZE
- call
->offset
;
526 call
->count
= call
->offset
+ size
;
527 ASSERTCMP(call
->count
, <=, PAGE_SIZE
);
530 /* extract the returned data */
532 _debug("extract data %llu/%llu %zu/%u",
533 req
->remain
, req
->actual_len
, call
->offset
, call
->count
);
535 buffer
= kmap(req
->pages
[req
->index
]);
536 ret
= afs_extract_data(call
, buffer
, call
->count
, true);
537 kunmap(req
->pages
[req
->index
]);
540 if (call
->offset
== PAGE_SIZE
) {
542 req
->page_done(call
, req
);
544 if (req
->remain
> 0) {
546 if (req
->index
>= req
->nr_pages
) {
547 call
->unmarshall
= 4;
555 /* Discard any excess data the server gave us */
558 size
= min_t(loff_t
, sizeof(afs_discard_buffer
), req
->remain
);
560 _debug("extract discard %llu/%llu %zu/%u",
561 req
->remain
, req
->actual_len
, call
->offset
, call
->count
);
564 ret
= afs_extract_data(call
, afs_discard_buffer
, call
->count
, true);
565 req
->remain
-= call
->offset
;
573 call
->unmarshall
= 5;
575 /* extract the metadata */
577 ret
= afs_extract_data(call
, call
->buffer
,
578 (21 + 3 + 6) * 4, false);
583 if (afs_decode_status(call
, &bp
, &vnode
->status
, vnode
,
584 &vnode
->status
.data_version
, req
) < 0)
585 return afs_protocol_error(call
, -EBADMSG
);
586 xdr_decode_AFSCallBack(call
, vnode
, &bp
);
588 xdr_decode_AFSVolSync(&bp
, call
->reply
[1]);
597 for (; req
->index
< req
->nr_pages
; req
->index
++) {
598 if (call
->count
< PAGE_SIZE
)
599 zero_user_segment(req
->pages
[req
->index
],
600 call
->count
, PAGE_SIZE
);
602 req
->page_done(call
, req
);
606 _leave(" = 0 [done]");
610 static void afs_fetch_data_destructor(struct afs_call
*call
)
612 struct afs_read
*req
= call
->reply
[2];
615 afs_flat_call_destructor(call
);
619 * FS.FetchData operation type
621 static const struct afs_call_type afs_RXFSFetchData
= {
622 .name
= "FS.FetchData",
623 .op
= afs_FS_FetchData
,
624 .deliver
= afs_deliver_fs_fetch_data
,
625 .destructor
= afs_fetch_data_destructor
,
628 static const struct afs_call_type afs_RXFSFetchData64
= {
629 .name
= "FS.FetchData64",
630 .op
= afs_FS_FetchData64
,
631 .deliver
= afs_deliver_fs_fetch_data
,
632 .destructor
= afs_fetch_data_destructor
,
636 * fetch data from a very large file
638 static int afs_fs_fetch_data64(struct afs_fs_cursor
*fc
, struct afs_read
*req
)
640 struct afs_vnode
*vnode
= fc
->vnode
;
641 struct afs_call
*call
;
642 struct afs_net
*net
= afs_v2net(vnode
);
647 call
= afs_alloc_flat_call(net
, &afs_RXFSFetchData64
, 32, (21 + 3 + 6) * 4);
652 call
->reply
[0] = vnode
;
653 call
->reply
[1] = NULL
; /* volsync */
654 call
->reply
[2] = req
;
655 call
->expected_version
= vnode
->status
.data_version
;
657 /* marshall the parameters */
659 bp
[0] = htonl(FSFETCHDATA64
);
660 bp
[1] = htonl(vnode
->fid
.vid
);
661 bp
[2] = htonl(vnode
->fid
.vnode
);
662 bp
[3] = htonl(vnode
->fid
.unique
);
663 bp
[4] = htonl(upper_32_bits(req
->pos
));
664 bp
[5] = htonl(lower_32_bits(req
->pos
));
666 bp
[7] = htonl(lower_32_bits(req
->len
));
668 refcount_inc(&req
->usage
);
669 call
->cb_break
= fc
->cb_break
;
670 afs_use_fs_server(call
, fc
->cbi
);
671 trace_afs_make_fs_call(call
, &vnode
->fid
);
672 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
676 * fetch data from a file
678 int afs_fs_fetch_data(struct afs_fs_cursor
*fc
, struct afs_read
*req
)
680 struct afs_vnode
*vnode
= fc
->vnode
;
681 struct afs_call
*call
;
682 struct afs_net
*net
= afs_v2net(vnode
);
685 if (upper_32_bits(req
->pos
) ||
686 upper_32_bits(req
->len
) ||
687 upper_32_bits(req
->pos
+ req
->len
))
688 return afs_fs_fetch_data64(fc
, req
);
692 call
= afs_alloc_flat_call(net
, &afs_RXFSFetchData
, 24, (21 + 3 + 6) * 4);
697 call
->reply
[0] = vnode
;
698 call
->reply
[1] = NULL
; /* volsync */
699 call
->reply
[2] = req
;
700 call
->expected_version
= vnode
->status
.data_version
;
702 /* marshall the parameters */
704 bp
[0] = htonl(FSFETCHDATA
);
705 bp
[1] = htonl(vnode
->fid
.vid
);
706 bp
[2] = htonl(vnode
->fid
.vnode
);
707 bp
[3] = htonl(vnode
->fid
.unique
);
708 bp
[4] = htonl(lower_32_bits(req
->pos
));
709 bp
[5] = htonl(lower_32_bits(req
->len
));
711 refcount_inc(&req
->usage
);
712 call
->cb_break
= fc
->cb_break
;
713 afs_use_fs_server(call
, fc
->cbi
);
714 trace_afs_make_fs_call(call
, &vnode
->fid
);
715 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
719 * deliver reply data to an FS.CreateFile or an FS.MakeDir
721 static int afs_deliver_fs_create_vnode(struct afs_call
*call
)
723 struct afs_vnode
*vnode
= call
->reply
[0];
727 _enter("{%u}", call
->unmarshall
);
729 ret
= afs_transfer_reply(call
);
733 /* unmarshall the reply once we've received all of it */
735 xdr_decode_AFSFid(&bp
, call
->reply
[1]);
736 if (afs_decode_status(call
, &bp
, call
->reply
[2], NULL
, NULL
, NULL
) < 0 ||
737 afs_decode_status(call
, &bp
, &vnode
->status
, vnode
,
738 &call
->expected_version
, NULL
) < 0)
739 return afs_protocol_error(call
, -EBADMSG
);
740 xdr_decode_AFSCallBack_raw(&bp
, call
->reply
[3]);
741 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
743 _leave(" = 0 [done]");
748 * FS.CreateFile and FS.MakeDir operation type
750 static const struct afs_call_type afs_RXFSCreateFile
= {
751 .name
= "FS.CreateFile",
752 .op
= afs_FS_CreateFile
,
753 .deliver
= afs_deliver_fs_create_vnode
,
754 .destructor
= afs_flat_call_destructor
,
757 static const struct afs_call_type afs_RXFSMakeDir
= {
758 .name
= "FS.MakeDir",
759 .op
= afs_FS_MakeDir
,
760 .deliver
= afs_deliver_fs_create_vnode
,
761 .destructor
= afs_flat_call_destructor
,
765 * create a file or make a directory
767 int afs_fs_create(struct afs_fs_cursor
*fc
,
770 u64 current_data_version
,
771 struct afs_fid
*newfid
,
772 struct afs_file_status
*newstatus
,
773 struct afs_callback
*newcb
)
775 struct afs_vnode
*vnode
= fc
->vnode
;
776 struct afs_call
*call
;
777 struct afs_net
*net
= afs_v2net(vnode
);
778 size_t namesz
, reqsz
, padsz
;
783 namesz
= strlen(name
);
784 padsz
= (4 - (namesz
& 3)) & 3;
785 reqsz
= (5 * 4) + namesz
+ padsz
+ (6 * 4);
787 call
= afs_alloc_flat_call(
788 net
, S_ISDIR(mode
) ? &afs_RXFSMakeDir
: &afs_RXFSCreateFile
,
789 reqsz
, (3 + 21 + 21 + 3 + 6) * 4);
794 call
->reply
[0] = vnode
;
795 call
->reply
[1] = newfid
;
796 call
->reply
[2] = newstatus
;
797 call
->reply
[3] = newcb
;
798 call
->expected_version
= current_data_version
+ 1;
800 /* marshall the parameters */
802 *bp
++ = htonl(S_ISDIR(mode
) ? FSMAKEDIR
: FSCREATEFILE
);
803 *bp
++ = htonl(vnode
->fid
.vid
);
804 *bp
++ = htonl(vnode
->fid
.vnode
);
805 *bp
++ = htonl(vnode
->fid
.unique
);
806 *bp
++ = htonl(namesz
);
807 memcpy(bp
, name
, namesz
);
808 bp
= (void *) bp
+ namesz
;
810 memset(bp
, 0, padsz
);
811 bp
= (void *) bp
+ padsz
;
813 *bp
++ = htonl(AFS_SET_MODE
| AFS_SET_MTIME
);
814 *bp
++ = htonl(vnode
->vfs_inode
.i_mtime
.tv_sec
); /* mtime */
815 *bp
++ = 0; /* owner */
816 *bp
++ = 0; /* group */
817 *bp
++ = htonl(mode
& S_IALLUGO
); /* unix mode */
818 *bp
++ = 0; /* segment size */
820 afs_use_fs_server(call
, fc
->cbi
);
821 trace_afs_make_fs_call(call
, &vnode
->fid
);
822 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
826 * deliver reply data to an FS.RemoveFile or FS.RemoveDir
828 static int afs_deliver_fs_remove(struct afs_call
*call
)
830 struct afs_vnode
*vnode
= call
->reply
[0];
834 _enter("{%u}", call
->unmarshall
);
836 ret
= afs_transfer_reply(call
);
840 /* unmarshall the reply once we've received all of it */
842 if (afs_decode_status(call
, &bp
, &vnode
->status
, vnode
,
843 &call
->expected_version
, NULL
) < 0)
844 return afs_protocol_error(call
, -EBADMSG
);
845 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
847 _leave(" = 0 [done]");
852 * FS.RemoveDir/FS.RemoveFile operation type
854 static const struct afs_call_type afs_RXFSRemoveFile
= {
855 .name
= "FS.RemoveFile",
856 .op
= afs_FS_RemoveFile
,
857 .deliver
= afs_deliver_fs_remove
,
858 .destructor
= afs_flat_call_destructor
,
861 static const struct afs_call_type afs_RXFSRemoveDir
= {
862 .name
= "FS.RemoveDir",
863 .op
= afs_FS_RemoveDir
,
864 .deliver
= afs_deliver_fs_remove
,
865 .destructor
= afs_flat_call_destructor
,
869 * remove a file or directory
871 int afs_fs_remove(struct afs_fs_cursor
*fc
, const char *name
, bool isdir
,
872 u64 current_data_version
)
874 struct afs_vnode
*vnode
= fc
->vnode
;
875 struct afs_call
*call
;
876 struct afs_net
*net
= afs_v2net(vnode
);
877 size_t namesz
, reqsz
, padsz
;
882 namesz
= strlen(name
);
883 padsz
= (4 - (namesz
& 3)) & 3;
884 reqsz
= (5 * 4) + namesz
+ padsz
;
886 call
= afs_alloc_flat_call(
887 net
, isdir
? &afs_RXFSRemoveDir
: &afs_RXFSRemoveFile
,
888 reqsz
, (21 + 6) * 4);
893 call
->reply
[0] = vnode
;
894 call
->expected_version
= current_data_version
+ 1;
896 /* marshall the parameters */
898 *bp
++ = htonl(isdir
? FSREMOVEDIR
: FSREMOVEFILE
);
899 *bp
++ = htonl(vnode
->fid
.vid
);
900 *bp
++ = htonl(vnode
->fid
.vnode
);
901 *bp
++ = htonl(vnode
->fid
.unique
);
902 *bp
++ = htonl(namesz
);
903 memcpy(bp
, name
, namesz
);
904 bp
= (void *) bp
+ namesz
;
906 memset(bp
, 0, padsz
);
907 bp
= (void *) bp
+ padsz
;
910 afs_use_fs_server(call
, fc
->cbi
);
911 trace_afs_make_fs_call(call
, &vnode
->fid
);
912 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
916 * deliver reply data to an FS.Link
918 static int afs_deliver_fs_link(struct afs_call
*call
)
920 struct afs_vnode
*dvnode
= call
->reply
[0], *vnode
= call
->reply
[1];
924 _enter("{%u}", call
->unmarshall
);
926 ret
= afs_transfer_reply(call
);
930 /* unmarshall the reply once we've received all of it */
932 if (afs_decode_status(call
, &bp
, &vnode
->status
, vnode
, NULL
, NULL
) < 0 ||
933 afs_decode_status(call
, &bp
, &dvnode
->status
, dvnode
,
934 &call
->expected_version
, NULL
) < 0)
935 return afs_protocol_error(call
, -EBADMSG
);
936 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
938 _leave(" = 0 [done]");
943 * FS.Link operation type
945 static const struct afs_call_type afs_RXFSLink
= {
948 .deliver
= afs_deliver_fs_link
,
949 .destructor
= afs_flat_call_destructor
,
955 int afs_fs_link(struct afs_fs_cursor
*fc
, struct afs_vnode
*vnode
,
956 const char *name
, u64 current_data_version
)
958 struct afs_vnode
*dvnode
= fc
->vnode
;
959 struct afs_call
*call
;
960 struct afs_net
*net
= afs_v2net(vnode
);
961 size_t namesz
, reqsz
, padsz
;
966 namesz
= strlen(name
);
967 padsz
= (4 - (namesz
& 3)) & 3;
968 reqsz
= (5 * 4) + namesz
+ padsz
+ (3 * 4);
970 call
= afs_alloc_flat_call(net
, &afs_RXFSLink
, reqsz
, (21 + 21 + 6) * 4);
975 call
->reply
[0] = dvnode
;
976 call
->reply
[1] = vnode
;
977 call
->expected_version
= current_data_version
+ 1;
979 /* marshall the parameters */
981 *bp
++ = htonl(FSLINK
);
982 *bp
++ = htonl(dvnode
->fid
.vid
);
983 *bp
++ = htonl(dvnode
->fid
.vnode
);
984 *bp
++ = htonl(dvnode
->fid
.unique
);
985 *bp
++ = htonl(namesz
);
986 memcpy(bp
, name
, namesz
);
987 bp
= (void *) bp
+ namesz
;
989 memset(bp
, 0, padsz
);
990 bp
= (void *) bp
+ padsz
;
992 *bp
++ = htonl(vnode
->fid
.vid
);
993 *bp
++ = htonl(vnode
->fid
.vnode
);
994 *bp
++ = htonl(vnode
->fid
.unique
);
996 afs_use_fs_server(call
, fc
->cbi
);
997 trace_afs_make_fs_call(call
, &vnode
->fid
);
998 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1002 * deliver reply data to an FS.Symlink
1004 static int afs_deliver_fs_symlink(struct afs_call
*call
)
1006 struct afs_vnode
*vnode
= call
->reply
[0];
1010 _enter("{%u}", call
->unmarshall
);
1012 ret
= afs_transfer_reply(call
);
1016 /* unmarshall the reply once we've received all of it */
1018 xdr_decode_AFSFid(&bp
, call
->reply
[1]);
1019 if (afs_decode_status(call
, &bp
, call
->reply
[2], NULL
, NULL
, NULL
) ||
1020 afs_decode_status(call
, &bp
, &vnode
->status
, vnode
,
1021 &call
->expected_version
, NULL
) < 0)
1022 return afs_protocol_error(call
, -EBADMSG
);
1023 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1025 _leave(" = 0 [done]");
1030 * FS.Symlink operation type
1032 static const struct afs_call_type afs_RXFSSymlink
= {
1033 .name
= "FS.Symlink",
1034 .op
= afs_FS_Symlink
,
1035 .deliver
= afs_deliver_fs_symlink
,
1036 .destructor
= afs_flat_call_destructor
,
1040 * create a symbolic link
1042 int afs_fs_symlink(struct afs_fs_cursor
*fc
,
1044 const char *contents
,
1045 u64 current_data_version
,
1046 struct afs_fid
*newfid
,
1047 struct afs_file_status
*newstatus
)
1049 struct afs_vnode
*vnode
= fc
->vnode
;
1050 struct afs_call
*call
;
1051 struct afs_net
*net
= afs_v2net(vnode
);
1052 size_t namesz
, reqsz
, padsz
, c_namesz
, c_padsz
;
1057 namesz
= strlen(name
);
1058 padsz
= (4 - (namesz
& 3)) & 3;
1060 c_namesz
= strlen(contents
);
1061 c_padsz
= (4 - (c_namesz
& 3)) & 3;
1063 reqsz
= (6 * 4) + namesz
+ padsz
+ c_namesz
+ c_padsz
+ (6 * 4);
1065 call
= afs_alloc_flat_call(net
, &afs_RXFSSymlink
, reqsz
,
1066 (3 + 21 + 21 + 6) * 4);
1070 call
->key
= fc
->key
;
1071 call
->reply
[0] = vnode
;
1072 call
->reply
[1] = newfid
;
1073 call
->reply
[2] = newstatus
;
1074 call
->expected_version
= current_data_version
+ 1;
1076 /* marshall the parameters */
1078 *bp
++ = htonl(FSSYMLINK
);
1079 *bp
++ = htonl(vnode
->fid
.vid
);
1080 *bp
++ = htonl(vnode
->fid
.vnode
);
1081 *bp
++ = htonl(vnode
->fid
.unique
);
1082 *bp
++ = htonl(namesz
);
1083 memcpy(bp
, name
, namesz
);
1084 bp
= (void *) bp
+ namesz
;
1086 memset(bp
, 0, padsz
);
1087 bp
= (void *) bp
+ padsz
;
1089 *bp
++ = htonl(c_namesz
);
1090 memcpy(bp
, contents
, c_namesz
);
1091 bp
= (void *) bp
+ c_namesz
;
1093 memset(bp
, 0, c_padsz
);
1094 bp
= (void *) bp
+ c_padsz
;
1096 *bp
++ = htonl(AFS_SET_MODE
| AFS_SET_MTIME
);
1097 *bp
++ = htonl(vnode
->vfs_inode
.i_mtime
.tv_sec
); /* mtime */
1098 *bp
++ = 0; /* owner */
1099 *bp
++ = 0; /* group */
1100 *bp
++ = htonl(S_IRWXUGO
); /* unix mode */
1101 *bp
++ = 0; /* segment size */
1103 afs_use_fs_server(call
, fc
->cbi
);
1104 trace_afs_make_fs_call(call
, &vnode
->fid
);
1105 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1109 * deliver reply data to an FS.Rename
1111 static int afs_deliver_fs_rename(struct afs_call
*call
)
1113 struct afs_vnode
*orig_dvnode
= call
->reply
[0], *new_dvnode
= call
->reply
[1];
1117 _enter("{%u}", call
->unmarshall
);
1119 ret
= afs_transfer_reply(call
);
1123 /* unmarshall the reply once we've received all of it */
1125 if (afs_decode_status(call
, &bp
, &orig_dvnode
->status
, orig_dvnode
,
1126 &call
->expected_version
, NULL
) < 0)
1127 return afs_protocol_error(call
, -EBADMSG
);
1128 if (new_dvnode
!= orig_dvnode
&&
1129 afs_decode_status(call
, &bp
, &new_dvnode
->status
, new_dvnode
,
1130 &call
->expected_version_2
, NULL
) < 0)
1131 return afs_protocol_error(call
, -EBADMSG
);
1132 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1134 _leave(" = 0 [done]");
1139 * FS.Rename operation type
1141 static const struct afs_call_type afs_RXFSRename
= {
1142 .name
= "FS.Rename",
1143 .op
= afs_FS_Rename
,
1144 .deliver
= afs_deliver_fs_rename
,
1145 .destructor
= afs_flat_call_destructor
,
1149 * create a symbolic link
1151 int afs_fs_rename(struct afs_fs_cursor
*fc
,
1152 const char *orig_name
,
1153 struct afs_vnode
*new_dvnode
,
1154 const char *new_name
,
1155 u64 current_orig_data_version
,
1156 u64 current_new_data_version
)
1158 struct afs_vnode
*orig_dvnode
= fc
->vnode
;
1159 struct afs_call
*call
;
1160 struct afs_net
*net
= afs_v2net(orig_dvnode
);
1161 size_t reqsz
, o_namesz
, o_padsz
, n_namesz
, n_padsz
;
1166 o_namesz
= strlen(orig_name
);
1167 o_padsz
= (4 - (o_namesz
& 3)) & 3;
1169 n_namesz
= strlen(new_name
);
1170 n_padsz
= (4 - (n_namesz
& 3)) & 3;
1173 4 + o_namesz
+ o_padsz
+
1175 4 + n_namesz
+ n_padsz
;
1177 call
= afs_alloc_flat_call(net
, &afs_RXFSRename
, reqsz
, (21 + 21 + 6) * 4);
1181 call
->key
= fc
->key
;
1182 call
->reply
[0] = orig_dvnode
;
1183 call
->reply
[1] = new_dvnode
;
1184 call
->expected_version
= current_orig_data_version
+ 1;
1185 call
->expected_version_2
= current_new_data_version
+ 1;
1187 /* marshall the parameters */
1189 *bp
++ = htonl(FSRENAME
);
1190 *bp
++ = htonl(orig_dvnode
->fid
.vid
);
1191 *bp
++ = htonl(orig_dvnode
->fid
.vnode
);
1192 *bp
++ = htonl(orig_dvnode
->fid
.unique
);
1193 *bp
++ = htonl(o_namesz
);
1194 memcpy(bp
, orig_name
, o_namesz
);
1195 bp
= (void *) bp
+ o_namesz
;
1197 memset(bp
, 0, o_padsz
);
1198 bp
= (void *) bp
+ o_padsz
;
1201 *bp
++ = htonl(new_dvnode
->fid
.vid
);
1202 *bp
++ = htonl(new_dvnode
->fid
.vnode
);
1203 *bp
++ = htonl(new_dvnode
->fid
.unique
);
1204 *bp
++ = htonl(n_namesz
);
1205 memcpy(bp
, new_name
, n_namesz
);
1206 bp
= (void *) bp
+ n_namesz
;
1208 memset(bp
, 0, n_padsz
);
1209 bp
= (void *) bp
+ n_padsz
;
1212 afs_use_fs_server(call
, fc
->cbi
);
1213 trace_afs_make_fs_call(call
, &orig_dvnode
->fid
);
1214 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1218 * deliver reply data to an FS.StoreData
1220 static int afs_deliver_fs_store_data(struct afs_call
*call
)
1222 struct afs_vnode
*vnode
= call
->reply
[0];
1228 ret
= afs_transfer_reply(call
);
1232 /* unmarshall the reply once we've received all of it */
1234 if (afs_decode_status(call
, &bp
, &vnode
->status
, vnode
,
1235 &call
->expected_version
, NULL
) < 0)
1236 return afs_protocol_error(call
, -EBADMSG
);
1237 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1239 afs_pages_written_back(vnode
, call
);
1241 _leave(" = 0 [done]");
1246 * FS.StoreData operation type
1248 static const struct afs_call_type afs_RXFSStoreData
= {
1249 .name
= "FS.StoreData",
1250 .op
= afs_FS_StoreData
,
1251 .deliver
= afs_deliver_fs_store_data
,
1252 .destructor
= afs_flat_call_destructor
,
1255 static const struct afs_call_type afs_RXFSStoreData64
= {
1256 .name
= "FS.StoreData64",
1257 .op
= afs_FS_StoreData64
,
1258 .deliver
= afs_deliver_fs_store_data
,
1259 .destructor
= afs_flat_call_destructor
,
1263 * store a set of pages to a very large file
1265 static int afs_fs_store_data64(struct afs_fs_cursor
*fc
,
1266 struct address_space
*mapping
,
1267 pgoff_t first
, pgoff_t last
,
1268 unsigned offset
, unsigned to
,
1269 loff_t size
, loff_t pos
, loff_t i_size
)
1271 struct afs_vnode
*vnode
= fc
->vnode
;
1272 struct afs_call
*call
;
1273 struct afs_net
*net
= afs_v2net(vnode
);
1276 _enter(",%x,{%x:%u},,",
1277 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1279 call
= afs_alloc_flat_call(net
, &afs_RXFSStoreData64
,
1280 (4 + 6 + 3 * 2) * 4,
1285 call
->key
= fc
->key
;
1286 call
->mapping
= mapping
;
1287 call
->reply
[0] = vnode
;
1288 call
->first
= first
;
1290 call
->first_offset
= offset
;
1292 call
->send_pages
= true;
1293 call
->expected_version
= vnode
->status
.data_version
+ 1;
1295 /* marshall the parameters */
1297 *bp
++ = htonl(FSSTOREDATA64
);
1298 *bp
++ = htonl(vnode
->fid
.vid
);
1299 *bp
++ = htonl(vnode
->fid
.vnode
);
1300 *bp
++ = htonl(vnode
->fid
.unique
);
1302 *bp
++ = htonl(AFS_SET_MTIME
); /* mask */
1303 *bp
++ = htonl(vnode
->vfs_inode
.i_mtime
.tv_sec
); /* mtime */
1304 *bp
++ = 0; /* owner */
1305 *bp
++ = 0; /* group */
1306 *bp
++ = 0; /* unix mode */
1307 *bp
++ = 0; /* segment size */
1309 *bp
++ = htonl(pos
>> 32);
1310 *bp
++ = htonl((u32
) pos
);
1311 *bp
++ = htonl(size
>> 32);
1312 *bp
++ = htonl((u32
) size
);
1313 *bp
++ = htonl(i_size
>> 32);
1314 *bp
++ = htonl((u32
) i_size
);
1316 trace_afs_make_fs_call(call
, &vnode
->fid
);
1317 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1321 * store a set of pages
1323 int afs_fs_store_data(struct afs_fs_cursor
*fc
, struct address_space
*mapping
,
1324 pgoff_t first
, pgoff_t last
,
1325 unsigned offset
, unsigned to
)
1327 struct afs_vnode
*vnode
= fc
->vnode
;
1328 struct afs_call
*call
;
1329 struct afs_net
*net
= afs_v2net(vnode
);
1330 loff_t size
, pos
, i_size
;
1333 _enter(",%x,{%x:%u},,",
1334 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1336 size
= (loff_t
)to
- (loff_t
)offset
;
1338 size
+= (loff_t
)(last
- first
) << PAGE_SHIFT
;
1339 pos
= (loff_t
)first
<< PAGE_SHIFT
;
1342 i_size
= i_size_read(&vnode
->vfs_inode
);
1343 if (pos
+ size
> i_size
)
1344 i_size
= size
+ pos
;
1346 _debug("size %llx, at %llx, i_size %llx",
1347 (unsigned long long) size
, (unsigned long long) pos
,
1348 (unsigned long long) i_size
);
1350 if (pos
>> 32 || i_size
>> 32 || size
>> 32 || (pos
+ size
) >> 32)
1351 return afs_fs_store_data64(fc
, mapping
, first
, last
, offset
, to
,
1354 call
= afs_alloc_flat_call(net
, &afs_RXFSStoreData
,
1360 call
->key
= fc
->key
;
1361 call
->mapping
= mapping
;
1362 call
->reply
[0] = vnode
;
1363 call
->first
= first
;
1365 call
->first_offset
= offset
;
1367 call
->send_pages
= true;
1368 call
->expected_version
= vnode
->status
.data_version
+ 1;
1370 /* marshall the parameters */
1372 *bp
++ = htonl(FSSTOREDATA
);
1373 *bp
++ = htonl(vnode
->fid
.vid
);
1374 *bp
++ = htonl(vnode
->fid
.vnode
);
1375 *bp
++ = htonl(vnode
->fid
.unique
);
1377 *bp
++ = htonl(AFS_SET_MTIME
); /* mask */
1378 *bp
++ = htonl(vnode
->vfs_inode
.i_mtime
.tv_sec
); /* mtime */
1379 *bp
++ = 0; /* owner */
1380 *bp
++ = 0; /* group */
1381 *bp
++ = 0; /* unix mode */
1382 *bp
++ = 0; /* segment size */
1385 *bp
++ = htonl(size
);
1386 *bp
++ = htonl(i_size
);
1388 afs_use_fs_server(call
, fc
->cbi
);
1389 trace_afs_make_fs_call(call
, &vnode
->fid
);
1390 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1394 * deliver reply data to an FS.StoreStatus
1396 static int afs_deliver_fs_store_status(struct afs_call
*call
)
1398 struct afs_vnode
*vnode
= call
->reply
[0];
1404 ret
= afs_transfer_reply(call
);
1408 /* unmarshall the reply once we've received all of it */
1410 if (afs_decode_status(call
, &bp
, &vnode
->status
, vnode
,
1411 &call
->expected_version
, NULL
) < 0)
1412 return afs_protocol_error(call
, -EBADMSG
);
1413 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1415 _leave(" = 0 [done]");
1420 * FS.StoreStatus operation type
1422 static const struct afs_call_type afs_RXFSStoreStatus
= {
1423 .name
= "FS.StoreStatus",
1424 .op
= afs_FS_StoreStatus
,
1425 .deliver
= afs_deliver_fs_store_status
,
1426 .destructor
= afs_flat_call_destructor
,
1429 static const struct afs_call_type afs_RXFSStoreData_as_Status
= {
1430 .name
= "FS.StoreData",
1431 .op
= afs_FS_StoreData
,
1432 .deliver
= afs_deliver_fs_store_status
,
1433 .destructor
= afs_flat_call_destructor
,
1436 static const struct afs_call_type afs_RXFSStoreData64_as_Status
= {
1437 .name
= "FS.StoreData64",
1438 .op
= afs_FS_StoreData64
,
1439 .deliver
= afs_deliver_fs_store_status
,
1440 .destructor
= afs_flat_call_destructor
,
1444 * set the attributes on a very large file, using FS.StoreData rather than
1445 * FS.StoreStatus so as to alter the file size also
1447 static int afs_fs_setattr_size64(struct afs_fs_cursor
*fc
, struct iattr
*attr
)
1449 struct afs_vnode
*vnode
= fc
->vnode
;
1450 struct afs_call
*call
;
1451 struct afs_net
*net
= afs_v2net(vnode
);
1454 _enter(",%x,{%x:%u},,",
1455 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1457 ASSERT(attr
->ia_valid
& ATTR_SIZE
);
1459 call
= afs_alloc_flat_call(net
, &afs_RXFSStoreData64_as_Status
,
1460 (4 + 6 + 3 * 2) * 4,
1465 call
->key
= fc
->key
;
1466 call
->reply
[0] = vnode
;
1467 call
->expected_version
= vnode
->status
.data_version
+ 1;
1469 /* marshall the parameters */
1471 *bp
++ = htonl(FSSTOREDATA64
);
1472 *bp
++ = htonl(vnode
->fid
.vid
);
1473 *bp
++ = htonl(vnode
->fid
.vnode
);
1474 *bp
++ = htonl(vnode
->fid
.unique
);
1476 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1478 *bp
++ = 0; /* position of start of write */
1480 *bp
++ = 0; /* size of write */
1482 *bp
++ = htonl(attr
->ia_size
>> 32); /* new file length */
1483 *bp
++ = htonl((u32
) attr
->ia_size
);
1485 afs_use_fs_server(call
, fc
->cbi
);
1486 trace_afs_make_fs_call(call
, &vnode
->fid
);
1487 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1491 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1492 * so as to alter the file size also
1494 static int afs_fs_setattr_size(struct afs_fs_cursor
*fc
, struct iattr
*attr
)
1496 struct afs_vnode
*vnode
= fc
->vnode
;
1497 struct afs_call
*call
;
1498 struct afs_net
*net
= afs_v2net(vnode
);
1501 _enter(",%x,{%x:%u},,",
1502 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1504 ASSERT(attr
->ia_valid
& ATTR_SIZE
);
1505 if (attr
->ia_size
>> 32)
1506 return afs_fs_setattr_size64(fc
, attr
);
1508 call
= afs_alloc_flat_call(net
, &afs_RXFSStoreData_as_Status
,
1514 call
->key
= fc
->key
;
1515 call
->reply
[0] = vnode
;
1516 call
->expected_version
= vnode
->status
.data_version
+ 1;
1518 /* marshall the parameters */
1520 *bp
++ = htonl(FSSTOREDATA
);
1521 *bp
++ = htonl(vnode
->fid
.vid
);
1522 *bp
++ = htonl(vnode
->fid
.vnode
);
1523 *bp
++ = htonl(vnode
->fid
.unique
);
1525 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1527 *bp
++ = 0; /* position of start of write */
1528 *bp
++ = 0; /* size of write */
1529 *bp
++ = htonl(attr
->ia_size
); /* new file length */
1531 afs_use_fs_server(call
, fc
->cbi
);
1532 trace_afs_make_fs_call(call
, &vnode
->fid
);
1533 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1537 * set the attributes on a file, using FS.StoreData if there's a change in file
1538 * size, and FS.StoreStatus otherwise
1540 int afs_fs_setattr(struct afs_fs_cursor
*fc
, struct iattr
*attr
)
1542 struct afs_vnode
*vnode
= fc
->vnode
;
1543 struct afs_call
*call
;
1544 struct afs_net
*net
= afs_v2net(vnode
);
1547 if (attr
->ia_valid
& ATTR_SIZE
)
1548 return afs_fs_setattr_size(fc
, attr
);
1550 _enter(",%x,{%x:%u},,",
1551 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1553 call
= afs_alloc_flat_call(net
, &afs_RXFSStoreStatus
,
1559 call
->key
= fc
->key
;
1560 call
->reply
[0] = vnode
;
1561 call
->expected_version
= vnode
->status
.data_version
;
1563 /* marshall the parameters */
1565 *bp
++ = htonl(FSSTORESTATUS
);
1566 *bp
++ = htonl(vnode
->fid
.vid
);
1567 *bp
++ = htonl(vnode
->fid
.vnode
);
1568 *bp
++ = htonl(vnode
->fid
.unique
);
1570 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1572 afs_use_fs_server(call
, fc
->cbi
);
1573 trace_afs_make_fs_call(call
, &vnode
->fid
);
1574 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1578 * deliver reply data to an FS.GetVolumeStatus
1580 static int afs_deliver_fs_get_volume_status(struct afs_call
*call
)
1586 _enter("{%u}", call
->unmarshall
);
1588 switch (call
->unmarshall
) {
1593 /* extract the returned status record */
1595 _debug("extract status");
1596 ret
= afs_extract_data(call
, call
->buffer
,
1602 xdr_decode_AFSFetchVolumeStatus(&bp
, call
->reply
[1]);
1606 /* extract the volume name length */
1608 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
1612 call
->count
= ntohl(call
->tmp
);
1613 _debug("volname length: %u", call
->count
);
1614 if (call
->count
>= AFSNAMEMAX
)
1615 return afs_protocol_error(call
, -EBADMSG
);
1619 /* extract the volume name */
1621 _debug("extract volname");
1622 if (call
->count
> 0) {
1623 ret
= afs_extract_data(call
, call
->reply
[2],
1631 _debug("volname '%s'", p
);
1636 /* extract the volume name padding */
1637 if ((call
->count
& 3) == 0) {
1639 goto no_volname_padding
;
1641 call
->count
= 4 - (call
->count
& 3);
1644 ret
= afs_extract_data(call
, call
->buffer
,
1653 /* extract the offline message length */
1655 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
1659 call
->count
= ntohl(call
->tmp
);
1660 _debug("offline msg length: %u", call
->count
);
1661 if (call
->count
>= AFSNAMEMAX
)
1662 return afs_protocol_error(call
, -EBADMSG
);
1666 /* extract the offline message */
1668 _debug("extract offline");
1669 if (call
->count
> 0) {
1670 ret
= afs_extract_data(call
, call
->reply
[2],
1678 _debug("offline '%s'", p
);
1683 /* extract the offline message padding */
1684 if ((call
->count
& 3) == 0) {
1686 goto no_offline_padding
;
1688 call
->count
= 4 - (call
->count
& 3);
1691 ret
= afs_extract_data(call
, call
->buffer
,
1700 /* extract the message of the day length */
1702 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
1706 call
->count
= ntohl(call
->tmp
);
1707 _debug("motd length: %u", call
->count
);
1708 if (call
->count
>= AFSNAMEMAX
)
1709 return afs_protocol_error(call
, -EBADMSG
);
1713 /* extract the message of the day */
1715 _debug("extract motd");
1716 if (call
->count
> 0) {
1717 ret
= afs_extract_data(call
, call
->reply
[2],
1725 _debug("motd '%s'", p
);
1730 /* extract the message of the day padding */
1731 call
->count
= (4 - (call
->count
& 3)) & 3;
1734 ret
= afs_extract_data(call
, call
->buffer
,
1735 call
->count
, false);
1745 _leave(" = 0 [done]");
1750 * destroy an FS.GetVolumeStatus call
1752 static void afs_get_volume_status_call_destructor(struct afs_call
*call
)
1754 kfree(call
->reply
[2]);
1755 call
->reply
[2] = NULL
;
1756 afs_flat_call_destructor(call
);
1760 * FS.GetVolumeStatus operation type
1762 static const struct afs_call_type afs_RXFSGetVolumeStatus
= {
1763 .name
= "FS.GetVolumeStatus",
1764 .op
= afs_FS_GetVolumeStatus
,
1765 .deliver
= afs_deliver_fs_get_volume_status
,
1766 .destructor
= afs_get_volume_status_call_destructor
,
1770 * fetch the status of a volume
1772 int afs_fs_get_volume_status(struct afs_fs_cursor
*fc
,
1773 struct afs_volume_status
*vs
)
1775 struct afs_vnode
*vnode
= fc
->vnode
;
1776 struct afs_call
*call
;
1777 struct afs_net
*net
= afs_v2net(vnode
);
1783 tmpbuf
= kmalloc(AFSOPAQUEMAX
, GFP_KERNEL
);
1787 call
= afs_alloc_flat_call(net
, &afs_RXFSGetVolumeStatus
, 2 * 4, 12 * 4);
1793 call
->key
= fc
->key
;
1794 call
->reply
[0] = vnode
;
1795 call
->reply
[1] = vs
;
1796 call
->reply
[2] = tmpbuf
;
1798 /* marshall the parameters */
1800 bp
[0] = htonl(FSGETVOLUMESTATUS
);
1801 bp
[1] = htonl(vnode
->fid
.vid
);
1803 afs_use_fs_server(call
, fc
->cbi
);
1804 trace_afs_make_fs_call(call
, &vnode
->fid
);
1805 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1809 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1811 static int afs_deliver_fs_xxxx_lock(struct afs_call
*call
)
1816 _enter("{%u}", call
->unmarshall
);
1818 ret
= afs_transfer_reply(call
);
1822 /* unmarshall the reply once we've received all of it */
1824 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1826 _leave(" = 0 [done]");
1831 * FS.SetLock operation type
1833 static const struct afs_call_type afs_RXFSSetLock
= {
1834 .name
= "FS.SetLock",
1835 .op
= afs_FS_SetLock
,
1836 .deliver
= afs_deliver_fs_xxxx_lock
,
1837 .destructor
= afs_flat_call_destructor
,
1841 * FS.ExtendLock operation type
1843 static const struct afs_call_type afs_RXFSExtendLock
= {
1844 .name
= "FS.ExtendLock",
1845 .op
= afs_FS_ExtendLock
,
1846 .deliver
= afs_deliver_fs_xxxx_lock
,
1847 .destructor
= afs_flat_call_destructor
,
1851 * FS.ReleaseLock operation type
1853 static const struct afs_call_type afs_RXFSReleaseLock
= {
1854 .name
= "FS.ReleaseLock",
1855 .op
= afs_FS_ReleaseLock
,
1856 .deliver
= afs_deliver_fs_xxxx_lock
,
1857 .destructor
= afs_flat_call_destructor
,
1861 * Set a lock on a file
1863 int afs_fs_set_lock(struct afs_fs_cursor
*fc
, afs_lock_type_t type
)
1865 struct afs_vnode
*vnode
= fc
->vnode
;
1866 struct afs_call
*call
;
1867 struct afs_net
*net
= afs_v2net(vnode
);
1872 call
= afs_alloc_flat_call(net
, &afs_RXFSSetLock
, 5 * 4, 6 * 4);
1876 call
->key
= fc
->key
;
1877 call
->reply
[0] = vnode
;
1879 /* marshall the parameters */
1881 *bp
++ = htonl(FSSETLOCK
);
1882 *bp
++ = htonl(vnode
->fid
.vid
);
1883 *bp
++ = htonl(vnode
->fid
.vnode
);
1884 *bp
++ = htonl(vnode
->fid
.unique
);
1885 *bp
++ = htonl(type
);
1887 afs_use_fs_server(call
, fc
->cbi
);
1888 trace_afs_make_fs_call(call
, &vnode
->fid
);
1889 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1893 * extend a lock on a file
1895 int afs_fs_extend_lock(struct afs_fs_cursor
*fc
)
1897 struct afs_vnode
*vnode
= fc
->vnode
;
1898 struct afs_call
*call
;
1899 struct afs_net
*net
= afs_v2net(vnode
);
1904 call
= afs_alloc_flat_call(net
, &afs_RXFSExtendLock
, 4 * 4, 6 * 4);
1908 call
->key
= fc
->key
;
1909 call
->reply
[0] = vnode
;
1911 /* marshall the parameters */
1913 *bp
++ = htonl(FSEXTENDLOCK
);
1914 *bp
++ = htonl(vnode
->fid
.vid
);
1915 *bp
++ = htonl(vnode
->fid
.vnode
);
1916 *bp
++ = htonl(vnode
->fid
.unique
);
1918 afs_use_fs_server(call
, fc
->cbi
);
1919 trace_afs_make_fs_call(call
, &vnode
->fid
);
1920 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1924 * release a lock on a file
1926 int afs_fs_release_lock(struct afs_fs_cursor
*fc
)
1928 struct afs_vnode
*vnode
= fc
->vnode
;
1929 struct afs_call
*call
;
1930 struct afs_net
*net
= afs_v2net(vnode
);
1935 call
= afs_alloc_flat_call(net
, &afs_RXFSReleaseLock
, 4 * 4, 6 * 4);
1939 call
->key
= fc
->key
;
1940 call
->reply
[0] = vnode
;
1942 /* marshall the parameters */
1944 *bp
++ = htonl(FSRELEASELOCK
);
1945 *bp
++ = htonl(vnode
->fid
.vid
);
1946 *bp
++ = htonl(vnode
->fid
.vnode
);
1947 *bp
++ = htonl(vnode
->fid
.unique
);
1949 afs_use_fs_server(call
, fc
->cbi
);
1950 trace_afs_make_fs_call(call
, &vnode
->fid
);
1951 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1955 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1957 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call
*call
)
1959 return afs_transfer_reply(call
);
1963 * FS.GiveUpAllCallBacks operation type
1965 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks
= {
1966 .name
= "FS.GiveUpAllCallBacks",
1967 .op
= afs_FS_GiveUpAllCallBacks
,
1968 .deliver
= afs_deliver_fs_give_up_all_callbacks
,
1969 .destructor
= afs_flat_call_destructor
,
1973 * Flush all the callbacks we have on a server.
1975 int afs_fs_give_up_all_callbacks(struct afs_net
*net
,
1976 struct afs_server
*server
,
1977 struct afs_addr_cursor
*ac
,
1980 struct afs_call
*call
;
1985 call
= afs_alloc_flat_call(net
, &afs_RXFSGiveUpAllCallBacks
, 1 * 4, 0);
1991 /* marshall the parameters */
1993 *bp
++ = htonl(FSGIVEUPALLCALLBACKS
);
1995 /* Can't take a ref on server */
1996 return afs_make_call(ac
, call
, GFP_NOFS
, false);
2000 * Deliver reply data to an FS.GetCapabilities operation.
2002 static int afs_deliver_fs_get_capabilities(struct afs_call
*call
)
2007 _enter("{%u,%zu/%u}", call
->unmarshall
, call
->offset
, call
->count
);
2010 switch (call
->unmarshall
) {
2015 /* Extract the capabilities word count */
2017 ret
= afs_extract_data(call
, &call
->tmp
,
2023 count
= ntohl(call
->tmp
);
2025 call
->count
= count
;
2026 call
->count2
= count
;
2030 /* Extract capabilities words */
2032 count
= min(call
->count
, 16U);
2033 ret
= afs_extract_data(call
, call
->buffer
,
2034 count
* sizeof(__be32
),
2039 /* TODO: Examine capabilities */
2041 call
->count
-= count
;
2042 if (call
->count
> 0)
2049 _leave(" = 0 [done]");
2054 * FS.GetCapabilities operation type
2056 static const struct afs_call_type afs_RXFSGetCapabilities
= {
2057 .name
= "FS.GetCapabilities",
2058 .op
= afs_FS_GetCapabilities
,
2059 .deliver
= afs_deliver_fs_get_capabilities
,
2060 .destructor
= afs_flat_call_destructor
,
2064 * Probe a fileserver for the capabilities that it supports. This can
2065 * return up to 196 words.
2067 int afs_fs_get_capabilities(struct afs_net
*net
,
2068 struct afs_server
*server
,
2069 struct afs_addr_cursor
*ac
,
2072 struct afs_call
*call
;
2077 call
= afs_alloc_flat_call(net
, &afs_RXFSGetCapabilities
, 1 * 4, 16 * 4);
2083 /* marshall the parameters */
2085 *bp
++ = htonl(FSGETCAPABILITIES
);
2087 /* Can't take a ref on server */
2088 trace_afs_make_fs_call(call
, NULL
);
2089 return afs_make_call(ac
, call
, GFP_NOFS
, false);
2093 * Deliver reply data to an FS.FetchStatus with no vnode.
2095 static int afs_deliver_fs_fetch_status(struct afs_call
*call
)
2097 struct afs_file_status
*status
= call
->reply
[1];
2098 struct afs_callback
*callback
= call
->reply
[2];
2099 struct afs_volsync
*volsync
= call
->reply
[3];
2100 struct afs_vnode
*vnode
= call
->reply
[0];
2104 ret
= afs_transfer_reply(call
);
2108 _enter("{%x:%u}", vnode
->fid
.vid
, vnode
->fid
.vnode
);
2110 /* unmarshall the reply once we've received all of it */
2112 afs_decode_status(call
, &bp
, status
, vnode
,
2113 &call
->expected_version
, NULL
);
2114 callback
[call
->count
].version
= ntohl(bp
[0]);
2115 callback
[call
->count
].expiry
= ntohl(bp
[1]);
2116 callback
[call
->count
].type
= ntohl(bp
[2]);
2118 xdr_decode_AFSCallBack(call
, vnode
, &bp
);
2122 xdr_decode_AFSVolSync(&bp
, volsync
);
2124 _leave(" = 0 [done]");
2129 * FS.FetchStatus operation type
2131 static const struct afs_call_type afs_RXFSFetchStatus
= {
2132 .name
= "FS.FetchStatus",
2133 .op
= afs_FS_FetchStatus
,
2134 .deliver
= afs_deliver_fs_fetch_status
,
2135 .destructor
= afs_flat_call_destructor
,
2139 * Fetch the status information for a fid without needing a vnode handle.
2141 int afs_fs_fetch_status(struct afs_fs_cursor
*fc
,
2142 struct afs_net
*net
,
2143 struct afs_fid
*fid
,
2144 struct afs_file_status
*status
,
2145 struct afs_callback
*callback
,
2146 struct afs_volsync
*volsync
)
2148 struct afs_call
*call
;
2151 _enter(",%x,{%x:%u},,",
2152 key_serial(fc
->key
), fid
->vid
, fid
->vnode
);
2154 call
= afs_alloc_flat_call(net
, &afs_RXFSFetchStatus
, 16, (21 + 3 + 6) * 4);
2156 fc
->ac
.error
= -ENOMEM
;
2160 call
->key
= fc
->key
;
2161 call
->reply
[0] = NULL
; /* vnode for fid[0] */
2162 call
->reply
[1] = status
;
2163 call
->reply
[2] = callback
;
2164 call
->reply
[3] = volsync
;
2165 call
->expected_version
= 1; /* vnode->status.data_version */
2167 /* marshall the parameters */
2169 bp
[0] = htonl(FSFETCHSTATUS
);
2170 bp
[1] = htonl(fid
->vid
);
2171 bp
[2] = htonl(fid
->vnode
);
2172 bp
[3] = htonl(fid
->unique
);
2174 call
->cb_break
= fc
->cb_break
;
2175 afs_use_fs_server(call
, fc
->cbi
);
2176 trace_afs_make_fs_call(call
, fid
);
2177 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
2181 * Deliver reply data to an FS.InlineBulkStatus call
2183 static int afs_deliver_fs_inline_bulk_status(struct afs_call
*call
)
2185 struct afs_file_status
*statuses
;
2186 struct afs_callback
*callbacks
;
2187 struct afs_vnode
*vnode
= call
->reply
[0];
2192 _enter("{%u}", call
->unmarshall
);
2194 switch (call
->unmarshall
) {
2199 /* Extract the file status count and array in two steps */
2201 _debug("extract status count");
2202 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
2206 tmp
= ntohl(call
->tmp
);
2207 _debug("status count: %u/%u", tmp
, call
->count2
);
2208 if (tmp
!= call
->count2
)
2209 return afs_protocol_error(call
, -EBADMSG
);
2217 _debug("extract status array %u", call
->count
);
2218 ret
= afs_extract_data(call
, call
->buffer
, 21 * 4, true);
2223 statuses
= call
->reply
[1];
2224 if (afs_decode_status(call
, &bp
, &statuses
[call
->count
],
2225 call
->count
== 0 ? vnode
: NULL
,
2227 return afs_protocol_error(call
, -EBADMSG
);
2230 if (call
->count
< call
->count2
)
2237 /* Extract the callback count and array in two steps */
2239 _debug("extract CB count");
2240 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
2244 tmp
= ntohl(call
->tmp
);
2245 _debug("CB count: %u", tmp
);
2246 if (tmp
!= call
->count2
)
2247 return afs_protocol_error(call
, -EBADMSG
);
2254 _debug("extract CB array");
2255 ret
= afs_extract_data(call
, call
->buffer
, 3 * 4, true);
2259 _debug("unmarshall CB array");
2261 callbacks
= call
->reply
[2];
2262 callbacks
[call
->count
].version
= ntohl(bp
[0]);
2263 callbacks
[call
->count
].expiry
= ntohl(bp
[1]);
2264 callbacks
[call
->count
].type
= ntohl(bp
[2]);
2265 statuses
= call
->reply
[1];
2266 if (call
->count
== 0 && vnode
&& statuses
[0].abort_code
== 0)
2267 xdr_decode_AFSCallBack(call
, vnode
, &bp
);
2269 if (call
->count
< call
->count2
)
2276 ret
= afs_extract_data(call
, call
->buffer
, 6 * 4, false);
2282 xdr_decode_AFSVolSync(&bp
, call
->reply
[3]);
2291 _leave(" = 0 [done]");
2296 * FS.InlineBulkStatus operation type
2298 static const struct afs_call_type afs_RXFSInlineBulkStatus
= {
2299 .name
= "FS.InlineBulkStatus",
2300 .op
= afs_FS_InlineBulkStatus
,
2301 .deliver
= afs_deliver_fs_inline_bulk_status
,
2302 .destructor
= afs_flat_call_destructor
,
2306 * Fetch the status information for up to 50 files
2308 int afs_fs_inline_bulk_status(struct afs_fs_cursor
*fc
,
2309 struct afs_net
*net
,
2310 struct afs_fid
*fids
,
2311 struct afs_file_status
*statuses
,
2312 struct afs_callback
*callbacks
,
2313 unsigned int nr_fids
,
2314 struct afs_volsync
*volsync
)
2316 struct afs_call
*call
;
2320 _enter(",%x,{%x:%u},%u",
2321 key_serial(fc
->key
), fids
[0].vid
, fids
[1].vnode
, nr_fids
);
2323 call
= afs_alloc_flat_call(net
, &afs_RXFSInlineBulkStatus
,
2324 (2 + nr_fids
* 3) * 4,
2327 fc
->ac
.error
= -ENOMEM
;
2331 call
->key
= fc
->key
;
2332 call
->reply
[0] = NULL
; /* vnode for fid[0] */
2333 call
->reply
[1] = statuses
;
2334 call
->reply
[2] = callbacks
;
2335 call
->reply
[3] = volsync
;
2336 call
->count2
= nr_fids
;
2338 /* marshall the parameters */
2340 *bp
++ = htonl(FSINLINEBULKSTATUS
);
2341 *bp
++ = htonl(nr_fids
);
2342 for (i
= 0; i
< nr_fids
; i
++) {
2343 *bp
++ = htonl(fids
[i
].vid
);
2344 *bp
++ = htonl(fids
[i
].vnode
);
2345 *bp
++ = htonl(fids
[i
].unique
);
2348 call
->cb_break
= fc
->cb_break
;
2349 afs_use_fs_server(call
, fc
->cbi
);
2350 trace_afs_make_fs_call(call
, &fids
[0]);
2351 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);