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
;
144 write_seqlock(&vnode
->cb_lock
);
146 abort_code
= ntohl(xdr
->abort_code
);
148 if (xdr
->if_version
!= htonl(AFS_FSTATUS_VERSION
)) {
149 if (xdr
->if_version
== htonl(0) &&
152 /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
153 * whereby it doesn't set the interface version in the error
156 status
->abort_code
= abort_code
;
161 pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr
->if_version
));
165 if (abort_code
!= 0 && inline_error
) {
166 status
->abort_code
= abort_code
;
171 type
= ntohl(xdr
->type
);
175 case AFS_FTYPE_SYMLINK
:
176 if (type
!= status
->type
&&
178 !test_bit(AFS_VNODE_UNSET
, &vnode
->flags
)) {
179 pr_warning("Vnode %x:%x:%x changed type %u to %u\n",
192 #define EXTRACT_M(FIELD) \
194 u32 x = ntohl(xdr->FIELD); \
195 if (status->FIELD != x) { \
196 flags |= AFS_VNODE_META_CHANGED; \
204 EXTRACT_M(caller_access
); /* call ticket dependent */
205 EXTRACT_M(anon_access
);
209 status
->mtime_client
= ntohl(xdr
->mtime_client
);
210 status
->mtime_server
= ntohl(xdr
->mtime_server
);
211 status
->lock_count
= ntohl(xdr
->lock_count
);
213 size
= (u64
)ntohl(xdr
->size_lo
);
214 size
|= (u64
)ntohl(xdr
->size_hi
) << 32;
217 data_version
= (u64
)ntohl(xdr
->data_version_lo
);
218 data_version
|= (u64
)ntohl(xdr
->data_version_hi
) << 32;
219 if (data_version
!= status
->data_version
) {
220 status
->data_version
= data_version
;
221 flags
|= AFS_VNODE_DATA_CHANGED
;
225 read_req
->data_version
= data_version
;
226 read_req
->file_size
= size
;
229 *_bp
= (const void *)*_bp
+ sizeof(*xdr
);
232 if (test_bit(AFS_VNODE_UNSET
, &vnode
->flags
))
233 flags
|= AFS_VNODE_NOT_YET_SET
;
234 afs_update_inode_from_status(vnode
, status
, expected_version
,
242 write_sequnlock(&vnode
->cb_lock
);
247 ret
= afs_protocol_error(call
, -EBADMSG
);
252 * decode an AFSCallBack block
254 static void xdr_decode_AFSCallBack(struct afs_call
*call
,
255 struct afs_vnode
*vnode
,
258 struct afs_cb_interest
*old
, *cbi
= call
->cbi
;
259 const __be32
*bp
= *_bp
;
262 write_seqlock(&vnode
->cb_lock
);
264 if (call
->cb_break
== afs_cb_break_sum(vnode
, cbi
)) {
265 vnode
->cb_version
= ntohl(*bp
++);
266 cb_expiry
= ntohl(*bp
++);
267 vnode
->cb_type
= ntohl(*bp
++);
268 vnode
->cb_expires_at
= cb_expiry
+ ktime_get_real_seconds();
269 old
= vnode
->cb_interest
;
270 if (old
!= call
->cbi
) {
271 vnode
->cb_interest
= cbi
;
274 set_bit(AFS_VNODE_CB_PROMISED
, &vnode
->flags
);
279 write_sequnlock(&vnode
->cb_lock
);
284 static void xdr_decode_AFSCallBack_raw(const __be32
**_bp
,
285 struct afs_callback
*cb
)
287 const __be32
*bp
= *_bp
;
289 cb
->version
= ntohl(*bp
++);
290 cb
->expiry
= ntohl(*bp
++);
291 cb
->type
= ntohl(*bp
++);
296 * decode an AFSVolSync block
298 static void xdr_decode_AFSVolSync(const __be32
**_bp
,
299 struct afs_volsync
*volsync
)
301 const __be32
*bp
= *_bp
;
303 volsync
->creation
= ntohl(*bp
++);
313 * encode the requested attributes into an AFSStoreStatus block
315 static void xdr_encode_AFS_StoreStatus(__be32
**_bp
, struct iattr
*attr
)
318 u32 mask
= 0, mtime
= 0, owner
= 0, group
= 0, mode
= 0;
321 if (attr
->ia_valid
& ATTR_MTIME
) {
322 mask
|= AFS_SET_MTIME
;
323 mtime
= attr
->ia_mtime
.tv_sec
;
326 if (attr
->ia_valid
& ATTR_UID
) {
327 mask
|= AFS_SET_OWNER
;
328 owner
= from_kuid(&init_user_ns
, attr
->ia_uid
);
331 if (attr
->ia_valid
& ATTR_GID
) {
332 mask
|= AFS_SET_GROUP
;
333 group
= from_kgid(&init_user_ns
, attr
->ia_gid
);
336 if (attr
->ia_valid
& ATTR_MODE
) {
337 mask
|= AFS_SET_MODE
;
338 mode
= attr
->ia_mode
& S_IALLUGO
;
342 *bp
++ = htonl(mtime
);
343 *bp
++ = htonl(owner
);
344 *bp
++ = htonl(group
);
346 *bp
++ = 0; /* segment size */
351 * decode an AFSFetchVolumeStatus block
353 static void xdr_decode_AFSFetchVolumeStatus(const __be32
**_bp
,
354 struct afs_volume_status
*vs
)
356 const __be32
*bp
= *_bp
;
358 vs
->vid
= ntohl(*bp
++);
359 vs
->parent_id
= ntohl(*bp
++);
360 vs
->online
= ntohl(*bp
++);
361 vs
->in_service
= ntohl(*bp
++);
362 vs
->blessed
= ntohl(*bp
++);
363 vs
->needs_salvage
= ntohl(*bp
++);
364 vs
->type
= ntohl(*bp
++);
365 vs
->min_quota
= ntohl(*bp
++);
366 vs
->max_quota
= ntohl(*bp
++);
367 vs
->blocks_in_use
= ntohl(*bp
++);
368 vs
->part_blocks_avail
= ntohl(*bp
++);
369 vs
->part_max_blocks
= ntohl(*bp
++);
374 * deliver reply data to an FS.FetchStatus
376 static int afs_deliver_fs_fetch_status_vnode(struct afs_call
*call
)
378 struct afs_vnode
*vnode
= call
->reply
[0];
382 ret
= afs_transfer_reply(call
);
386 _enter("{%x:%u}", vnode
->fid
.vid
, vnode
->fid
.vnode
);
388 /* unmarshall the reply once we've received all of it */
390 if (xdr_decode_AFSFetchStatus(call
, &bp
, &vnode
->status
, vnode
,
391 &call
->expected_version
, NULL
) < 0)
392 return afs_protocol_error(call
, -EBADMSG
);
393 xdr_decode_AFSCallBack(call
, vnode
, &bp
);
395 xdr_decode_AFSVolSync(&bp
, call
->reply
[1]);
397 _leave(" = 0 [done]");
402 * FS.FetchStatus operation type
404 static const struct afs_call_type afs_RXFSFetchStatus_vnode
= {
405 .name
= "FS.FetchStatus(vnode)",
406 .op
= afs_FS_FetchStatus
,
407 .deliver
= afs_deliver_fs_fetch_status_vnode
,
408 .destructor
= afs_flat_call_destructor
,
412 * fetch the status information for a file
414 int afs_fs_fetch_file_status(struct afs_fs_cursor
*fc
, struct afs_volsync
*volsync
,
417 struct afs_vnode
*vnode
= fc
->vnode
;
418 struct afs_call
*call
;
419 struct afs_net
*net
= afs_v2net(vnode
);
422 _enter(",%x,{%x:%u},,",
423 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
425 call
= afs_alloc_flat_call(net
, &afs_RXFSFetchStatus_vnode
,
426 16, (21 + 3 + 6) * 4);
428 fc
->ac
.error
= -ENOMEM
;
433 call
->reply
[0] = vnode
;
434 call
->reply
[1] = volsync
;
435 call
->expected_version
= new_inode
? 1 : vnode
->status
.data_version
;
437 /* marshall the parameters */
439 bp
[0] = htonl(FSFETCHSTATUS
);
440 bp
[1] = htonl(vnode
->fid
.vid
);
441 bp
[2] = htonl(vnode
->fid
.vnode
);
442 bp
[3] = htonl(vnode
->fid
.unique
);
444 call
->cb_break
= fc
->cb_break
;
445 afs_use_fs_server(call
, fc
->cbi
);
446 trace_afs_make_fs_call(call
, &vnode
->fid
);
447 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
451 * deliver reply data to an FS.FetchData
453 static int afs_deliver_fs_fetch_data(struct afs_call
*call
)
455 struct afs_vnode
*vnode
= call
->reply
[0];
456 struct afs_read
*req
= call
->reply
[2];
462 _enter("{%u,%zu/%u;%llu/%llu}",
463 call
->unmarshall
, call
->offset
, call
->count
,
464 req
->remain
, req
->actual_len
);
466 switch (call
->unmarshall
) {
471 if (call
->operation_ID
!= FSFETCHDATA64
) {
476 /* extract the upper part of the returned data length of an
477 * FSFETCHDATA64 op (which should always be 0 using this
480 _debug("extract data length (MSW)");
481 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
485 req
->actual_len
= ntohl(call
->tmp
);
486 req
->actual_len
<<= 32;
491 /* extract the returned data length */
493 _debug("extract data length");
494 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
498 req
->actual_len
|= ntohl(call
->tmp
);
499 _debug("DATA length: %llu", req
->actual_len
);
501 req
->remain
= req
->actual_len
;
502 call
->offset
= req
->pos
& (PAGE_SIZE
- 1);
504 if (req
->actual_len
== 0)
509 ASSERTCMP(req
->index
, <, req
->nr_pages
);
510 if (req
->remain
> PAGE_SIZE
- call
->offset
)
511 size
= PAGE_SIZE
- call
->offset
;
514 call
->count
= call
->offset
+ size
;
515 ASSERTCMP(call
->count
, <=, PAGE_SIZE
);
518 /* extract the returned data */
520 _debug("extract data %llu/%llu %zu/%u",
521 req
->remain
, req
->actual_len
, call
->offset
, call
->count
);
523 buffer
= kmap(req
->pages
[req
->index
]);
524 ret
= afs_extract_data(call
, buffer
, call
->count
, true);
525 kunmap(req
->pages
[req
->index
]);
528 if (call
->offset
== PAGE_SIZE
) {
530 req
->page_done(call
, req
);
532 if (req
->remain
> 0) {
534 if (req
->index
>= req
->nr_pages
) {
535 call
->unmarshall
= 4;
543 /* Discard any excess data the server gave us */
546 size
= min_t(loff_t
, sizeof(afs_discard_buffer
), req
->remain
);
548 _debug("extract discard %llu/%llu %zu/%u",
549 req
->remain
, req
->actual_len
, call
->offset
, call
->count
);
552 ret
= afs_extract_data(call
, afs_discard_buffer
, call
->count
, true);
553 req
->remain
-= call
->offset
;
561 call
->unmarshall
= 5;
563 /* extract the metadata */
565 ret
= afs_extract_data(call
, call
->buffer
,
566 (21 + 3 + 6) * 4, false);
571 if (xdr_decode_AFSFetchStatus(call
, &bp
, &vnode
->status
, vnode
,
572 &vnode
->status
.data_version
, req
) < 0)
573 return afs_protocol_error(call
, -EBADMSG
);
574 xdr_decode_AFSCallBack(call
, vnode
, &bp
);
576 xdr_decode_AFSVolSync(&bp
, call
->reply
[1]);
585 for (; req
->index
< req
->nr_pages
; req
->index
++) {
586 if (call
->count
< PAGE_SIZE
)
587 zero_user_segment(req
->pages
[req
->index
],
588 call
->count
, PAGE_SIZE
);
590 req
->page_done(call
, req
);
594 _leave(" = 0 [done]");
598 static void afs_fetch_data_destructor(struct afs_call
*call
)
600 struct afs_read
*req
= call
->reply
[2];
603 afs_flat_call_destructor(call
);
607 * FS.FetchData operation type
609 static const struct afs_call_type afs_RXFSFetchData
= {
610 .name
= "FS.FetchData",
611 .op
= afs_FS_FetchData
,
612 .deliver
= afs_deliver_fs_fetch_data
,
613 .destructor
= afs_fetch_data_destructor
,
616 static const struct afs_call_type afs_RXFSFetchData64
= {
617 .name
= "FS.FetchData64",
618 .op
= afs_FS_FetchData64
,
619 .deliver
= afs_deliver_fs_fetch_data
,
620 .destructor
= afs_fetch_data_destructor
,
624 * fetch data from a very large file
626 static int afs_fs_fetch_data64(struct afs_fs_cursor
*fc
, struct afs_read
*req
)
628 struct afs_vnode
*vnode
= fc
->vnode
;
629 struct afs_call
*call
;
630 struct afs_net
*net
= afs_v2net(vnode
);
635 call
= afs_alloc_flat_call(net
, &afs_RXFSFetchData64
, 32, (21 + 3 + 6) * 4);
640 call
->reply
[0] = vnode
;
641 call
->reply
[1] = NULL
; /* volsync */
642 call
->reply
[2] = req
;
643 call
->expected_version
= vnode
->status
.data_version
;
645 /* marshall the parameters */
647 bp
[0] = htonl(FSFETCHDATA64
);
648 bp
[1] = htonl(vnode
->fid
.vid
);
649 bp
[2] = htonl(vnode
->fid
.vnode
);
650 bp
[3] = htonl(vnode
->fid
.unique
);
651 bp
[4] = htonl(upper_32_bits(req
->pos
));
652 bp
[5] = htonl(lower_32_bits(req
->pos
));
654 bp
[7] = htonl(lower_32_bits(req
->len
));
656 refcount_inc(&req
->usage
);
657 call
->cb_break
= fc
->cb_break
;
658 afs_use_fs_server(call
, fc
->cbi
);
659 trace_afs_make_fs_call(call
, &vnode
->fid
);
660 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
664 * fetch data from a file
666 int afs_fs_fetch_data(struct afs_fs_cursor
*fc
, struct afs_read
*req
)
668 struct afs_vnode
*vnode
= fc
->vnode
;
669 struct afs_call
*call
;
670 struct afs_net
*net
= afs_v2net(vnode
);
673 if (upper_32_bits(req
->pos
) ||
674 upper_32_bits(req
->len
) ||
675 upper_32_bits(req
->pos
+ req
->len
))
676 return afs_fs_fetch_data64(fc
, req
);
680 call
= afs_alloc_flat_call(net
, &afs_RXFSFetchData
, 24, (21 + 3 + 6) * 4);
685 call
->reply
[0] = vnode
;
686 call
->reply
[1] = NULL
; /* volsync */
687 call
->reply
[2] = req
;
688 call
->expected_version
= vnode
->status
.data_version
;
690 /* marshall the parameters */
692 bp
[0] = htonl(FSFETCHDATA
);
693 bp
[1] = htonl(vnode
->fid
.vid
);
694 bp
[2] = htonl(vnode
->fid
.vnode
);
695 bp
[3] = htonl(vnode
->fid
.unique
);
696 bp
[4] = htonl(lower_32_bits(req
->pos
));
697 bp
[5] = htonl(lower_32_bits(req
->len
));
699 refcount_inc(&req
->usage
);
700 call
->cb_break
= fc
->cb_break
;
701 afs_use_fs_server(call
, fc
->cbi
);
702 trace_afs_make_fs_call(call
, &vnode
->fid
);
703 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
707 * deliver reply data to an FS.CreateFile or an FS.MakeDir
709 static int afs_deliver_fs_create_vnode(struct afs_call
*call
)
711 struct afs_vnode
*vnode
= call
->reply
[0];
715 _enter("{%u}", call
->unmarshall
);
717 ret
= afs_transfer_reply(call
);
721 /* unmarshall the reply once we've received all of it */
723 xdr_decode_AFSFid(&bp
, call
->reply
[1]);
724 if (xdr_decode_AFSFetchStatus(call
, &bp
, call
->reply
[2], NULL
, NULL
, NULL
) < 0 ||
725 xdr_decode_AFSFetchStatus(call
, &bp
, &vnode
->status
, vnode
,
726 &call
->expected_version
, NULL
) < 0)
727 return afs_protocol_error(call
, -EBADMSG
);
728 xdr_decode_AFSCallBack_raw(&bp
, call
->reply
[3]);
729 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
731 _leave(" = 0 [done]");
736 * FS.CreateFile and FS.MakeDir operation type
738 static const struct afs_call_type afs_RXFSCreateFile
= {
739 .name
= "FS.CreateFile",
740 .op
= afs_FS_CreateFile
,
741 .deliver
= afs_deliver_fs_create_vnode
,
742 .destructor
= afs_flat_call_destructor
,
745 static const struct afs_call_type afs_RXFSMakeDir
= {
746 .name
= "FS.MakeDir",
747 .op
= afs_FS_MakeDir
,
748 .deliver
= afs_deliver_fs_create_vnode
,
749 .destructor
= afs_flat_call_destructor
,
753 * create a file or make a directory
755 int afs_fs_create(struct afs_fs_cursor
*fc
,
758 u64 current_data_version
,
759 struct afs_fid
*newfid
,
760 struct afs_file_status
*newstatus
,
761 struct afs_callback
*newcb
)
763 struct afs_vnode
*vnode
= fc
->vnode
;
764 struct afs_call
*call
;
765 struct afs_net
*net
= afs_v2net(vnode
);
766 size_t namesz
, reqsz
, padsz
;
771 namesz
= strlen(name
);
772 padsz
= (4 - (namesz
& 3)) & 3;
773 reqsz
= (5 * 4) + namesz
+ padsz
+ (6 * 4);
775 call
= afs_alloc_flat_call(
776 net
, S_ISDIR(mode
) ? &afs_RXFSMakeDir
: &afs_RXFSCreateFile
,
777 reqsz
, (3 + 21 + 21 + 3 + 6) * 4);
782 call
->reply
[0] = vnode
;
783 call
->reply
[1] = newfid
;
784 call
->reply
[2] = newstatus
;
785 call
->reply
[3] = newcb
;
786 call
->expected_version
= current_data_version
+ 1;
788 /* marshall the parameters */
790 *bp
++ = htonl(S_ISDIR(mode
) ? FSMAKEDIR
: FSCREATEFILE
);
791 *bp
++ = htonl(vnode
->fid
.vid
);
792 *bp
++ = htonl(vnode
->fid
.vnode
);
793 *bp
++ = htonl(vnode
->fid
.unique
);
794 *bp
++ = htonl(namesz
);
795 memcpy(bp
, name
, namesz
);
796 bp
= (void *) bp
+ namesz
;
798 memset(bp
, 0, padsz
);
799 bp
= (void *) bp
+ padsz
;
801 *bp
++ = htonl(AFS_SET_MODE
| AFS_SET_MTIME
);
802 *bp
++ = htonl(vnode
->vfs_inode
.i_mtime
.tv_sec
); /* mtime */
803 *bp
++ = 0; /* owner */
804 *bp
++ = 0; /* group */
805 *bp
++ = htonl(mode
& S_IALLUGO
); /* unix mode */
806 *bp
++ = 0; /* segment size */
808 afs_use_fs_server(call
, fc
->cbi
);
809 trace_afs_make_fs_call(call
, &vnode
->fid
);
810 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
814 * deliver reply data to an FS.RemoveFile or FS.RemoveDir
816 static int afs_deliver_fs_remove(struct afs_call
*call
)
818 struct afs_vnode
*vnode
= call
->reply
[0];
822 _enter("{%u}", call
->unmarshall
);
824 ret
= afs_transfer_reply(call
);
828 /* unmarshall the reply once we've received all of it */
830 if (xdr_decode_AFSFetchStatus(call
, &bp
, &vnode
->status
, vnode
,
831 &call
->expected_version
, NULL
) < 0)
832 return afs_protocol_error(call
, -EBADMSG
);
833 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
835 _leave(" = 0 [done]");
840 * FS.RemoveDir/FS.RemoveFile operation type
842 static const struct afs_call_type afs_RXFSRemoveFile
= {
843 .name
= "FS.RemoveFile",
844 .op
= afs_FS_RemoveFile
,
845 .deliver
= afs_deliver_fs_remove
,
846 .destructor
= afs_flat_call_destructor
,
849 static const struct afs_call_type afs_RXFSRemoveDir
= {
850 .name
= "FS.RemoveDir",
851 .op
= afs_FS_RemoveDir
,
852 .deliver
= afs_deliver_fs_remove
,
853 .destructor
= afs_flat_call_destructor
,
857 * remove a file or directory
859 int afs_fs_remove(struct afs_fs_cursor
*fc
, const char *name
, bool isdir
,
860 u64 current_data_version
)
862 struct afs_vnode
*vnode
= fc
->vnode
;
863 struct afs_call
*call
;
864 struct afs_net
*net
= afs_v2net(vnode
);
865 size_t namesz
, reqsz
, padsz
;
870 namesz
= strlen(name
);
871 padsz
= (4 - (namesz
& 3)) & 3;
872 reqsz
= (5 * 4) + namesz
+ padsz
;
874 call
= afs_alloc_flat_call(
875 net
, isdir
? &afs_RXFSRemoveDir
: &afs_RXFSRemoveFile
,
876 reqsz
, (21 + 6) * 4);
881 call
->reply
[0] = vnode
;
882 call
->expected_version
= current_data_version
+ 1;
884 /* marshall the parameters */
886 *bp
++ = htonl(isdir
? FSREMOVEDIR
: FSREMOVEFILE
);
887 *bp
++ = htonl(vnode
->fid
.vid
);
888 *bp
++ = htonl(vnode
->fid
.vnode
);
889 *bp
++ = htonl(vnode
->fid
.unique
);
890 *bp
++ = htonl(namesz
);
891 memcpy(bp
, name
, namesz
);
892 bp
= (void *) bp
+ namesz
;
894 memset(bp
, 0, padsz
);
895 bp
= (void *) bp
+ padsz
;
898 afs_use_fs_server(call
, fc
->cbi
);
899 trace_afs_make_fs_call(call
, &vnode
->fid
);
900 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
904 * deliver reply data to an FS.Link
906 static int afs_deliver_fs_link(struct afs_call
*call
)
908 struct afs_vnode
*dvnode
= call
->reply
[0], *vnode
= call
->reply
[1];
912 _enter("{%u}", call
->unmarshall
);
914 ret
= afs_transfer_reply(call
);
918 /* unmarshall the reply once we've received all of it */
920 if (xdr_decode_AFSFetchStatus(call
, &bp
, &vnode
->status
, vnode
, NULL
, NULL
) < 0 ||
921 xdr_decode_AFSFetchStatus(call
, &bp
, &dvnode
->status
, dvnode
,
922 &call
->expected_version
, NULL
) < 0)
923 return afs_protocol_error(call
, -EBADMSG
);
924 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
926 _leave(" = 0 [done]");
931 * FS.Link operation type
933 static const struct afs_call_type afs_RXFSLink
= {
936 .deliver
= afs_deliver_fs_link
,
937 .destructor
= afs_flat_call_destructor
,
943 int afs_fs_link(struct afs_fs_cursor
*fc
, struct afs_vnode
*vnode
,
944 const char *name
, u64 current_data_version
)
946 struct afs_vnode
*dvnode
= fc
->vnode
;
947 struct afs_call
*call
;
948 struct afs_net
*net
= afs_v2net(vnode
);
949 size_t namesz
, reqsz
, padsz
;
954 namesz
= strlen(name
);
955 padsz
= (4 - (namesz
& 3)) & 3;
956 reqsz
= (5 * 4) + namesz
+ padsz
+ (3 * 4);
958 call
= afs_alloc_flat_call(net
, &afs_RXFSLink
, reqsz
, (21 + 21 + 6) * 4);
963 call
->reply
[0] = dvnode
;
964 call
->reply
[1] = vnode
;
965 call
->expected_version
= current_data_version
+ 1;
967 /* marshall the parameters */
969 *bp
++ = htonl(FSLINK
);
970 *bp
++ = htonl(dvnode
->fid
.vid
);
971 *bp
++ = htonl(dvnode
->fid
.vnode
);
972 *bp
++ = htonl(dvnode
->fid
.unique
);
973 *bp
++ = htonl(namesz
);
974 memcpy(bp
, name
, namesz
);
975 bp
= (void *) bp
+ namesz
;
977 memset(bp
, 0, padsz
);
978 bp
= (void *) bp
+ padsz
;
980 *bp
++ = htonl(vnode
->fid
.vid
);
981 *bp
++ = htonl(vnode
->fid
.vnode
);
982 *bp
++ = htonl(vnode
->fid
.unique
);
984 afs_use_fs_server(call
, fc
->cbi
);
985 trace_afs_make_fs_call(call
, &vnode
->fid
);
986 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
990 * deliver reply data to an FS.Symlink
992 static int afs_deliver_fs_symlink(struct afs_call
*call
)
994 struct afs_vnode
*vnode
= call
->reply
[0];
998 _enter("{%u}", call
->unmarshall
);
1000 ret
= afs_transfer_reply(call
);
1004 /* unmarshall the reply once we've received all of it */
1006 xdr_decode_AFSFid(&bp
, call
->reply
[1]);
1007 if (xdr_decode_AFSFetchStatus(call
, &bp
, call
->reply
[2], NULL
, NULL
, NULL
) ||
1008 xdr_decode_AFSFetchStatus(call
, &bp
, &vnode
->status
, vnode
,
1009 &call
->expected_version
, NULL
) < 0)
1010 return afs_protocol_error(call
, -EBADMSG
);
1011 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1013 _leave(" = 0 [done]");
1018 * FS.Symlink operation type
1020 static const struct afs_call_type afs_RXFSSymlink
= {
1021 .name
= "FS.Symlink",
1022 .op
= afs_FS_Symlink
,
1023 .deliver
= afs_deliver_fs_symlink
,
1024 .destructor
= afs_flat_call_destructor
,
1028 * create a symbolic link
1030 int afs_fs_symlink(struct afs_fs_cursor
*fc
,
1032 const char *contents
,
1033 u64 current_data_version
,
1034 struct afs_fid
*newfid
,
1035 struct afs_file_status
*newstatus
)
1037 struct afs_vnode
*vnode
= fc
->vnode
;
1038 struct afs_call
*call
;
1039 struct afs_net
*net
= afs_v2net(vnode
);
1040 size_t namesz
, reqsz
, padsz
, c_namesz
, c_padsz
;
1045 namesz
= strlen(name
);
1046 padsz
= (4 - (namesz
& 3)) & 3;
1048 c_namesz
= strlen(contents
);
1049 c_padsz
= (4 - (c_namesz
& 3)) & 3;
1051 reqsz
= (6 * 4) + namesz
+ padsz
+ c_namesz
+ c_padsz
+ (6 * 4);
1053 call
= afs_alloc_flat_call(net
, &afs_RXFSSymlink
, reqsz
,
1054 (3 + 21 + 21 + 6) * 4);
1058 call
->key
= fc
->key
;
1059 call
->reply
[0] = vnode
;
1060 call
->reply
[1] = newfid
;
1061 call
->reply
[2] = newstatus
;
1062 call
->expected_version
= current_data_version
+ 1;
1064 /* marshall the parameters */
1066 *bp
++ = htonl(FSSYMLINK
);
1067 *bp
++ = htonl(vnode
->fid
.vid
);
1068 *bp
++ = htonl(vnode
->fid
.vnode
);
1069 *bp
++ = htonl(vnode
->fid
.unique
);
1070 *bp
++ = htonl(namesz
);
1071 memcpy(bp
, name
, namesz
);
1072 bp
= (void *) bp
+ namesz
;
1074 memset(bp
, 0, padsz
);
1075 bp
= (void *) bp
+ padsz
;
1077 *bp
++ = htonl(c_namesz
);
1078 memcpy(bp
, contents
, c_namesz
);
1079 bp
= (void *) bp
+ c_namesz
;
1081 memset(bp
, 0, c_padsz
);
1082 bp
= (void *) bp
+ c_padsz
;
1084 *bp
++ = htonl(AFS_SET_MODE
| AFS_SET_MTIME
);
1085 *bp
++ = htonl(vnode
->vfs_inode
.i_mtime
.tv_sec
); /* mtime */
1086 *bp
++ = 0; /* owner */
1087 *bp
++ = 0; /* group */
1088 *bp
++ = htonl(S_IRWXUGO
); /* unix mode */
1089 *bp
++ = 0; /* segment size */
1091 afs_use_fs_server(call
, fc
->cbi
);
1092 trace_afs_make_fs_call(call
, &vnode
->fid
);
1093 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1097 * deliver reply data to an FS.Rename
1099 static int afs_deliver_fs_rename(struct afs_call
*call
)
1101 struct afs_vnode
*orig_dvnode
= call
->reply
[0], *new_dvnode
= call
->reply
[1];
1105 _enter("{%u}", call
->unmarshall
);
1107 ret
= afs_transfer_reply(call
);
1111 /* unmarshall the reply once we've received all of it */
1113 if (xdr_decode_AFSFetchStatus(call
, &bp
, &orig_dvnode
->status
, orig_dvnode
,
1114 &call
->expected_version
, NULL
) < 0)
1115 return afs_protocol_error(call
, -EBADMSG
);
1116 if (new_dvnode
!= orig_dvnode
&&
1117 xdr_decode_AFSFetchStatus(call
, &bp
, &new_dvnode
->status
, new_dvnode
,
1118 &call
->expected_version_2
, NULL
) < 0)
1119 return afs_protocol_error(call
, -EBADMSG
);
1120 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1122 _leave(" = 0 [done]");
1127 * FS.Rename operation type
1129 static const struct afs_call_type afs_RXFSRename
= {
1130 .name
= "FS.Rename",
1131 .op
= afs_FS_Rename
,
1132 .deliver
= afs_deliver_fs_rename
,
1133 .destructor
= afs_flat_call_destructor
,
1137 * create a symbolic link
1139 int afs_fs_rename(struct afs_fs_cursor
*fc
,
1140 const char *orig_name
,
1141 struct afs_vnode
*new_dvnode
,
1142 const char *new_name
,
1143 u64 current_orig_data_version
,
1144 u64 current_new_data_version
)
1146 struct afs_vnode
*orig_dvnode
= fc
->vnode
;
1147 struct afs_call
*call
;
1148 struct afs_net
*net
= afs_v2net(orig_dvnode
);
1149 size_t reqsz
, o_namesz
, o_padsz
, n_namesz
, n_padsz
;
1154 o_namesz
= strlen(orig_name
);
1155 o_padsz
= (4 - (o_namesz
& 3)) & 3;
1157 n_namesz
= strlen(new_name
);
1158 n_padsz
= (4 - (n_namesz
& 3)) & 3;
1161 4 + o_namesz
+ o_padsz
+
1163 4 + n_namesz
+ n_padsz
;
1165 call
= afs_alloc_flat_call(net
, &afs_RXFSRename
, reqsz
, (21 + 21 + 6) * 4);
1169 call
->key
= fc
->key
;
1170 call
->reply
[0] = orig_dvnode
;
1171 call
->reply
[1] = new_dvnode
;
1172 call
->expected_version
= current_orig_data_version
+ 1;
1173 call
->expected_version_2
= current_new_data_version
+ 1;
1175 /* marshall the parameters */
1177 *bp
++ = htonl(FSRENAME
);
1178 *bp
++ = htonl(orig_dvnode
->fid
.vid
);
1179 *bp
++ = htonl(orig_dvnode
->fid
.vnode
);
1180 *bp
++ = htonl(orig_dvnode
->fid
.unique
);
1181 *bp
++ = htonl(o_namesz
);
1182 memcpy(bp
, orig_name
, o_namesz
);
1183 bp
= (void *) bp
+ o_namesz
;
1185 memset(bp
, 0, o_padsz
);
1186 bp
= (void *) bp
+ o_padsz
;
1189 *bp
++ = htonl(new_dvnode
->fid
.vid
);
1190 *bp
++ = htonl(new_dvnode
->fid
.vnode
);
1191 *bp
++ = htonl(new_dvnode
->fid
.unique
);
1192 *bp
++ = htonl(n_namesz
);
1193 memcpy(bp
, new_name
, n_namesz
);
1194 bp
= (void *) bp
+ n_namesz
;
1196 memset(bp
, 0, n_padsz
);
1197 bp
= (void *) bp
+ n_padsz
;
1200 afs_use_fs_server(call
, fc
->cbi
);
1201 trace_afs_make_fs_call(call
, &orig_dvnode
->fid
);
1202 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1206 * deliver reply data to an FS.StoreData
1208 static int afs_deliver_fs_store_data(struct afs_call
*call
)
1210 struct afs_vnode
*vnode
= call
->reply
[0];
1216 ret
= afs_transfer_reply(call
);
1220 /* unmarshall the reply once we've received all of it */
1222 if (xdr_decode_AFSFetchStatus(call
, &bp
, &vnode
->status
, vnode
,
1223 &call
->expected_version
, NULL
) < 0)
1224 return afs_protocol_error(call
, -EBADMSG
);
1225 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1227 afs_pages_written_back(vnode
, call
);
1229 _leave(" = 0 [done]");
1234 * FS.StoreData operation type
1236 static const struct afs_call_type afs_RXFSStoreData
= {
1237 .name
= "FS.StoreData",
1238 .op
= afs_FS_StoreData
,
1239 .deliver
= afs_deliver_fs_store_data
,
1240 .destructor
= afs_flat_call_destructor
,
1243 static const struct afs_call_type afs_RXFSStoreData64
= {
1244 .name
= "FS.StoreData64",
1245 .op
= afs_FS_StoreData64
,
1246 .deliver
= afs_deliver_fs_store_data
,
1247 .destructor
= afs_flat_call_destructor
,
1251 * store a set of pages to a very large file
1253 static int afs_fs_store_data64(struct afs_fs_cursor
*fc
,
1254 struct address_space
*mapping
,
1255 pgoff_t first
, pgoff_t last
,
1256 unsigned offset
, unsigned to
,
1257 loff_t size
, loff_t pos
, loff_t i_size
)
1259 struct afs_vnode
*vnode
= fc
->vnode
;
1260 struct afs_call
*call
;
1261 struct afs_net
*net
= afs_v2net(vnode
);
1264 _enter(",%x,{%x:%u},,",
1265 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1267 call
= afs_alloc_flat_call(net
, &afs_RXFSStoreData64
,
1268 (4 + 6 + 3 * 2) * 4,
1273 call
->key
= fc
->key
;
1274 call
->mapping
= mapping
;
1275 call
->reply
[0] = vnode
;
1276 call
->first
= first
;
1278 call
->first_offset
= offset
;
1280 call
->send_pages
= true;
1281 call
->expected_version
= vnode
->status
.data_version
+ 1;
1283 /* marshall the parameters */
1285 *bp
++ = htonl(FSSTOREDATA64
);
1286 *bp
++ = htonl(vnode
->fid
.vid
);
1287 *bp
++ = htonl(vnode
->fid
.vnode
);
1288 *bp
++ = htonl(vnode
->fid
.unique
);
1290 *bp
++ = htonl(AFS_SET_MTIME
); /* mask */
1291 *bp
++ = htonl(vnode
->vfs_inode
.i_mtime
.tv_sec
); /* mtime */
1292 *bp
++ = 0; /* owner */
1293 *bp
++ = 0; /* group */
1294 *bp
++ = 0; /* unix mode */
1295 *bp
++ = 0; /* segment size */
1297 *bp
++ = htonl(pos
>> 32);
1298 *bp
++ = htonl((u32
) pos
);
1299 *bp
++ = htonl(size
>> 32);
1300 *bp
++ = htonl((u32
) size
);
1301 *bp
++ = htonl(i_size
>> 32);
1302 *bp
++ = htonl((u32
) i_size
);
1304 trace_afs_make_fs_call(call
, &vnode
->fid
);
1305 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1309 * store a set of pages
1311 int afs_fs_store_data(struct afs_fs_cursor
*fc
, struct address_space
*mapping
,
1312 pgoff_t first
, pgoff_t last
,
1313 unsigned offset
, unsigned to
)
1315 struct afs_vnode
*vnode
= fc
->vnode
;
1316 struct afs_call
*call
;
1317 struct afs_net
*net
= afs_v2net(vnode
);
1318 loff_t size
, pos
, i_size
;
1321 _enter(",%x,{%x:%u},,",
1322 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1324 size
= (loff_t
)to
- (loff_t
)offset
;
1326 size
+= (loff_t
)(last
- first
) << PAGE_SHIFT
;
1327 pos
= (loff_t
)first
<< PAGE_SHIFT
;
1330 i_size
= i_size_read(&vnode
->vfs_inode
);
1331 if (pos
+ size
> i_size
)
1332 i_size
= size
+ pos
;
1334 _debug("size %llx, at %llx, i_size %llx",
1335 (unsigned long long) size
, (unsigned long long) pos
,
1336 (unsigned long long) i_size
);
1338 if (pos
>> 32 || i_size
>> 32 || size
>> 32 || (pos
+ size
) >> 32)
1339 return afs_fs_store_data64(fc
, mapping
, first
, last
, offset
, to
,
1342 call
= afs_alloc_flat_call(net
, &afs_RXFSStoreData
,
1348 call
->key
= fc
->key
;
1349 call
->mapping
= mapping
;
1350 call
->reply
[0] = vnode
;
1351 call
->first
= first
;
1353 call
->first_offset
= offset
;
1355 call
->send_pages
= true;
1356 call
->expected_version
= vnode
->status
.data_version
+ 1;
1358 /* marshall the parameters */
1360 *bp
++ = htonl(FSSTOREDATA
);
1361 *bp
++ = htonl(vnode
->fid
.vid
);
1362 *bp
++ = htonl(vnode
->fid
.vnode
);
1363 *bp
++ = htonl(vnode
->fid
.unique
);
1365 *bp
++ = htonl(AFS_SET_MTIME
); /* mask */
1366 *bp
++ = htonl(vnode
->vfs_inode
.i_mtime
.tv_sec
); /* mtime */
1367 *bp
++ = 0; /* owner */
1368 *bp
++ = 0; /* group */
1369 *bp
++ = 0; /* unix mode */
1370 *bp
++ = 0; /* segment size */
1373 *bp
++ = htonl(size
);
1374 *bp
++ = htonl(i_size
);
1376 afs_use_fs_server(call
, fc
->cbi
);
1377 trace_afs_make_fs_call(call
, &vnode
->fid
);
1378 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1382 * deliver reply data to an FS.StoreStatus
1384 static int afs_deliver_fs_store_status(struct afs_call
*call
)
1386 struct afs_vnode
*vnode
= call
->reply
[0];
1392 ret
= afs_transfer_reply(call
);
1396 /* unmarshall the reply once we've received all of it */
1398 if (xdr_decode_AFSFetchStatus(call
, &bp
, &vnode
->status
, vnode
,
1399 &call
->expected_version
, NULL
) < 0)
1400 return afs_protocol_error(call
, -EBADMSG
);
1401 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1403 _leave(" = 0 [done]");
1408 * FS.StoreStatus operation type
1410 static const struct afs_call_type afs_RXFSStoreStatus
= {
1411 .name
= "FS.StoreStatus",
1412 .op
= afs_FS_StoreStatus
,
1413 .deliver
= afs_deliver_fs_store_status
,
1414 .destructor
= afs_flat_call_destructor
,
1417 static const struct afs_call_type afs_RXFSStoreData_as_Status
= {
1418 .name
= "FS.StoreData",
1419 .op
= afs_FS_StoreData
,
1420 .deliver
= afs_deliver_fs_store_status
,
1421 .destructor
= afs_flat_call_destructor
,
1424 static const struct afs_call_type afs_RXFSStoreData64_as_Status
= {
1425 .name
= "FS.StoreData64",
1426 .op
= afs_FS_StoreData64
,
1427 .deliver
= afs_deliver_fs_store_status
,
1428 .destructor
= afs_flat_call_destructor
,
1432 * set the attributes on a very large file, using FS.StoreData rather than
1433 * FS.StoreStatus so as to alter the file size also
1435 static int afs_fs_setattr_size64(struct afs_fs_cursor
*fc
, struct iattr
*attr
)
1437 struct afs_vnode
*vnode
= fc
->vnode
;
1438 struct afs_call
*call
;
1439 struct afs_net
*net
= afs_v2net(vnode
);
1442 _enter(",%x,{%x:%u},,",
1443 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1445 ASSERT(attr
->ia_valid
& ATTR_SIZE
);
1447 call
= afs_alloc_flat_call(net
, &afs_RXFSStoreData64_as_Status
,
1448 (4 + 6 + 3 * 2) * 4,
1453 call
->key
= fc
->key
;
1454 call
->reply
[0] = vnode
;
1455 call
->expected_version
= vnode
->status
.data_version
+ 1;
1457 /* marshall the parameters */
1459 *bp
++ = htonl(FSSTOREDATA64
);
1460 *bp
++ = htonl(vnode
->fid
.vid
);
1461 *bp
++ = htonl(vnode
->fid
.vnode
);
1462 *bp
++ = htonl(vnode
->fid
.unique
);
1464 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1466 *bp
++ = 0; /* position of start of write */
1468 *bp
++ = 0; /* size of write */
1470 *bp
++ = htonl(attr
->ia_size
>> 32); /* new file length */
1471 *bp
++ = htonl((u32
) attr
->ia_size
);
1473 afs_use_fs_server(call
, fc
->cbi
);
1474 trace_afs_make_fs_call(call
, &vnode
->fid
);
1475 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1479 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1480 * so as to alter the file size also
1482 static int afs_fs_setattr_size(struct afs_fs_cursor
*fc
, struct iattr
*attr
)
1484 struct afs_vnode
*vnode
= fc
->vnode
;
1485 struct afs_call
*call
;
1486 struct afs_net
*net
= afs_v2net(vnode
);
1489 _enter(",%x,{%x:%u},,",
1490 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1492 ASSERT(attr
->ia_valid
& ATTR_SIZE
);
1493 if (attr
->ia_size
>> 32)
1494 return afs_fs_setattr_size64(fc
, attr
);
1496 call
= afs_alloc_flat_call(net
, &afs_RXFSStoreData_as_Status
,
1502 call
->key
= fc
->key
;
1503 call
->reply
[0] = vnode
;
1504 call
->expected_version
= vnode
->status
.data_version
+ 1;
1506 /* marshall the parameters */
1508 *bp
++ = htonl(FSSTOREDATA
);
1509 *bp
++ = htonl(vnode
->fid
.vid
);
1510 *bp
++ = htonl(vnode
->fid
.vnode
);
1511 *bp
++ = htonl(vnode
->fid
.unique
);
1513 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1515 *bp
++ = 0; /* position of start of write */
1516 *bp
++ = 0; /* size of write */
1517 *bp
++ = htonl(attr
->ia_size
); /* new file length */
1519 afs_use_fs_server(call
, fc
->cbi
);
1520 trace_afs_make_fs_call(call
, &vnode
->fid
);
1521 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1525 * set the attributes on a file, using FS.StoreData if there's a change in file
1526 * size, and FS.StoreStatus otherwise
1528 int afs_fs_setattr(struct afs_fs_cursor
*fc
, struct iattr
*attr
)
1530 struct afs_vnode
*vnode
= fc
->vnode
;
1531 struct afs_call
*call
;
1532 struct afs_net
*net
= afs_v2net(vnode
);
1535 if (attr
->ia_valid
& ATTR_SIZE
)
1536 return afs_fs_setattr_size(fc
, attr
);
1538 _enter(",%x,{%x:%u},,",
1539 key_serial(fc
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1541 call
= afs_alloc_flat_call(net
, &afs_RXFSStoreStatus
,
1547 call
->key
= fc
->key
;
1548 call
->reply
[0] = vnode
;
1549 call
->expected_version
= vnode
->status
.data_version
;
1551 /* marshall the parameters */
1553 *bp
++ = htonl(FSSTORESTATUS
);
1554 *bp
++ = htonl(vnode
->fid
.vid
);
1555 *bp
++ = htonl(vnode
->fid
.vnode
);
1556 *bp
++ = htonl(vnode
->fid
.unique
);
1558 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1560 afs_use_fs_server(call
, fc
->cbi
);
1561 trace_afs_make_fs_call(call
, &vnode
->fid
);
1562 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1566 * deliver reply data to an FS.GetVolumeStatus
1568 static int afs_deliver_fs_get_volume_status(struct afs_call
*call
)
1574 _enter("{%u}", call
->unmarshall
);
1576 switch (call
->unmarshall
) {
1581 /* extract the returned status record */
1583 _debug("extract status");
1584 ret
= afs_extract_data(call
, call
->buffer
,
1590 xdr_decode_AFSFetchVolumeStatus(&bp
, call
->reply
[1]);
1594 /* extract the volume name length */
1596 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
1600 call
->count
= ntohl(call
->tmp
);
1601 _debug("volname length: %u", call
->count
);
1602 if (call
->count
>= AFSNAMEMAX
)
1603 return afs_protocol_error(call
, -EBADMSG
);
1607 /* extract the volume name */
1609 _debug("extract volname");
1610 if (call
->count
> 0) {
1611 ret
= afs_extract_data(call
, call
->reply
[2],
1619 _debug("volname '%s'", p
);
1624 /* extract the volume name padding */
1625 if ((call
->count
& 3) == 0) {
1627 goto no_volname_padding
;
1629 call
->count
= 4 - (call
->count
& 3);
1632 ret
= afs_extract_data(call
, call
->buffer
,
1641 /* extract the offline message length */
1643 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
1647 call
->count
= ntohl(call
->tmp
);
1648 _debug("offline msg length: %u", call
->count
);
1649 if (call
->count
>= AFSNAMEMAX
)
1650 return afs_protocol_error(call
, -EBADMSG
);
1654 /* extract the offline message */
1656 _debug("extract offline");
1657 if (call
->count
> 0) {
1658 ret
= afs_extract_data(call
, call
->reply
[2],
1666 _debug("offline '%s'", p
);
1671 /* extract the offline message padding */
1672 if ((call
->count
& 3) == 0) {
1674 goto no_offline_padding
;
1676 call
->count
= 4 - (call
->count
& 3);
1679 ret
= afs_extract_data(call
, call
->buffer
,
1688 /* extract the message of the day length */
1690 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
1694 call
->count
= ntohl(call
->tmp
);
1695 _debug("motd length: %u", call
->count
);
1696 if (call
->count
>= AFSNAMEMAX
)
1697 return afs_protocol_error(call
, -EBADMSG
);
1701 /* extract the message of the day */
1703 _debug("extract motd");
1704 if (call
->count
> 0) {
1705 ret
= afs_extract_data(call
, call
->reply
[2],
1713 _debug("motd '%s'", p
);
1718 /* extract the message of the day padding */
1719 call
->count
= (4 - (call
->count
& 3)) & 3;
1722 ret
= afs_extract_data(call
, call
->buffer
,
1723 call
->count
, false);
1733 _leave(" = 0 [done]");
1738 * destroy an FS.GetVolumeStatus call
1740 static void afs_get_volume_status_call_destructor(struct afs_call
*call
)
1742 kfree(call
->reply
[2]);
1743 call
->reply
[2] = NULL
;
1744 afs_flat_call_destructor(call
);
1748 * FS.GetVolumeStatus operation type
1750 static const struct afs_call_type afs_RXFSGetVolumeStatus
= {
1751 .name
= "FS.GetVolumeStatus",
1752 .op
= afs_FS_GetVolumeStatus
,
1753 .deliver
= afs_deliver_fs_get_volume_status
,
1754 .destructor
= afs_get_volume_status_call_destructor
,
1758 * fetch the status of a volume
1760 int afs_fs_get_volume_status(struct afs_fs_cursor
*fc
,
1761 struct afs_volume_status
*vs
)
1763 struct afs_vnode
*vnode
= fc
->vnode
;
1764 struct afs_call
*call
;
1765 struct afs_net
*net
= afs_v2net(vnode
);
1771 tmpbuf
= kmalloc(AFSOPAQUEMAX
, GFP_KERNEL
);
1775 call
= afs_alloc_flat_call(net
, &afs_RXFSGetVolumeStatus
, 2 * 4, 12 * 4);
1781 call
->key
= fc
->key
;
1782 call
->reply
[0] = vnode
;
1783 call
->reply
[1] = vs
;
1784 call
->reply
[2] = tmpbuf
;
1786 /* marshall the parameters */
1788 bp
[0] = htonl(FSGETVOLUMESTATUS
);
1789 bp
[1] = htonl(vnode
->fid
.vid
);
1791 afs_use_fs_server(call
, fc
->cbi
);
1792 trace_afs_make_fs_call(call
, &vnode
->fid
);
1793 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1797 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1799 static int afs_deliver_fs_xxxx_lock(struct afs_call
*call
)
1804 _enter("{%u}", call
->unmarshall
);
1806 ret
= afs_transfer_reply(call
);
1810 /* unmarshall the reply once we've received all of it */
1812 /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
1814 _leave(" = 0 [done]");
1819 * FS.SetLock operation type
1821 static const struct afs_call_type afs_RXFSSetLock
= {
1822 .name
= "FS.SetLock",
1823 .op
= afs_FS_SetLock
,
1824 .deliver
= afs_deliver_fs_xxxx_lock
,
1825 .destructor
= afs_flat_call_destructor
,
1829 * FS.ExtendLock operation type
1831 static const struct afs_call_type afs_RXFSExtendLock
= {
1832 .name
= "FS.ExtendLock",
1833 .op
= afs_FS_ExtendLock
,
1834 .deliver
= afs_deliver_fs_xxxx_lock
,
1835 .destructor
= afs_flat_call_destructor
,
1839 * FS.ReleaseLock operation type
1841 static const struct afs_call_type afs_RXFSReleaseLock
= {
1842 .name
= "FS.ReleaseLock",
1843 .op
= afs_FS_ReleaseLock
,
1844 .deliver
= afs_deliver_fs_xxxx_lock
,
1845 .destructor
= afs_flat_call_destructor
,
1849 * Set a lock on a file
1851 int afs_fs_set_lock(struct afs_fs_cursor
*fc
, afs_lock_type_t type
)
1853 struct afs_vnode
*vnode
= fc
->vnode
;
1854 struct afs_call
*call
;
1855 struct afs_net
*net
= afs_v2net(vnode
);
1860 call
= afs_alloc_flat_call(net
, &afs_RXFSSetLock
, 5 * 4, 6 * 4);
1864 call
->key
= fc
->key
;
1865 call
->reply
[0] = vnode
;
1867 /* marshall the parameters */
1869 *bp
++ = htonl(FSSETLOCK
);
1870 *bp
++ = htonl(vnode
->fid
.vid
);
1871 *bp
++ = htonl(vnode
->fid
.vnode
);
1872 *bp
++ = htonl(vnode
->fid
.unique
);
1873 *bp
++ = htonl(type
);
1875 afs_use_fs_server(call
, fc
->cbi
);
1876 trace_afs_make_fs_call(call
, &vnode
->fid
);
1877 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1881 * extend a lock on a file
1883 int afs_fs_extend_lock(struct afs_fs_cursor
*fc
)
1885 struct afs_vnode
*vnode
= fc
->vnode
;
1886 struct afs_call
*call
;
1887 struct afs_net
*net
= afs_v2net(vnode
);
1892 call
= afs_alloc_flat_call(net
, &afs_RXFSExtendLock
, 4 * 4, 6 * 4);
1896 call
->key
= fc
->key
;
1897 call
->reply
[0] = vnode
;
1899 /* marshall the parameters */
1901 *bp
++ = htonl(FSEXTENDLOCK
);
1902 *bp
++ = htonl(vnode
->fid
.vid
);
1903 *bp
++ = htonl(vnode
->fid
.vnode
);
1904 *bp
++ = htonl(vnode
->fid
.unique
);
1906 afs_use_fs_server(call
, fc
->cbi
);
1907 trace_afs_make_fs_call(call
, &vnode
->fid
);
1908 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1912 * release a lock on a file
1914 int afs_fs_release_lock(struct afs_fs_cursor
*fc
)
1916 struct afs_vnode
*vnode
= fc
->vnode
;
1917 struct afs_call
*call
;
1918 struct afs_net
*net
= afs_v2net(vnode
);
1923 call
= afs_alloc_flat_call(net
, &afs_RXFSReleaseLock
, 4 * 4, 6 * 4);
1927 call
->key
= fc
->key
;
1928 call
->reply
[0] = vnode
;
1930 /* marshall the parameters */
1932 *bp
++ = htonl(FSRELEASELOCK
);
1933 *bp
++ = htonl(vnode
->fid
.vid
);
1934 *bp
++ = htonl(vnode
->fid
.vnode
);
1935 *bp
++ = htonl(vnode
->fid
.unique
);
1937 afs_use_fs_server(call
, fc
->cbi
);
1938 trace_afs_make_fs_call(call
, &vnode
->fid
);
1939 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
1943 * Deliver reply data to an FS.GiveUpAllCallBacks operation.
1945 static int afs_deliver_fs_give_up_all_callbacks(struct afs_call
*call
)
1947 return afs_transfer_reply(call
);
1951 * FS.GiveUpAllCallBacks operation type
1953 static const struct afs_call_type afs_RXFSGiveUpAllCallBacks
= {
1954 .name
= "FS.GiveUpAllCallBacks",
1955 .op
= afs_FS_GiveUpAllCallBacks
,
1956 .deliver
= afs_deliver_fs_give_up_all_callbacks
,
1957 .destructor
= afs_flat_call_destructor
,
1961 * Flush all the callbacks we have on a server.
1963 int afs_fs_give_up_all_callbacks(struct afs_net
*net
,
1964 struct afs_server
*server
,
1965 struct afs_addr_cursor
*ac
,
1968 struct afs_call
*call
;
1973 call
= afs_alloc_flat_call(net
, &afs_RXFSGiveUpAllCallBacks
, 1 * 4, 0);
1979 /* marshall the parameters */
1981 *bp
++ = htonl(FSGIVEUPALLCALLBACKS
);
1983 /* Can't take a ref on server */
1984 return afs_make_call(ac
, call
, GFP_NOFS
, false);
1988 * Deliver reply data to an FS.GetCapabilities operation.
1990 static int afs_deliver_fs_get_capabilities(struct afs_call
*call
)
1995 _enter("{%u,%zu/%u}", call
->unmarshall
, call
->offset
, call
->count
);
1998 switch (call
->unmarshall
) {
2003 /* Extract the capabilities word count */
2005 ret
= afs_extract_data(call
, &call
->tmp
,
2011 count
= ntohl(call
->tmp
);
2013 call
->count
= count
;
2014 call
->count2
= count
;
2018 /* Extract capabilities words */
2020 count
= min(call
->count
, 16U);
2021 ret
= afs_extract_data(call
, call
->buffer
,
2022 count
* sizeof(__be32
),
2027 /* TODO: Examine capabilities */
2029 call
->count
-= count
;
2030 if (call
->count
> 0)
2037 _leave(" = 0 [done]");
2042 * FS.GetCapabilities operation type
2044 static const struct afs_call_type afs_RXFSGetCapabilities
= {
2045 .name
= "FS.GetCapabilities",
2046 .op
= afs_FS_GetCapabilities
,
2047 .deliver
= afs_deliver_fs_get_capabilities
,
2048 .destructor
= afs_flat_call_destructor
,
2052 * Probe a fileserver for the capabilities that it supports. This can
2053 * return up to 196 words.
2055 int afs_fs_get_capabilities(struct afs_net
*net
,
2056 struct afs_server
*server
,
2057 struct afs_addr_cursor
*ac
,
2060 struct afs_call
*call
;
2065 call
= afs_alloc_flat_call(net
, &afs_RXFSGetCapabilities
, 1 * 4, 16 * 4);
2071 /* marshall the parameters */
2073 *bp
++ = htonl(FSGETCAPABILITIES
);
2075 /* Can't take a ref on server */
2076 trace_afs_make_fs_call(call
, NULL
);
2077 return afs_make_call(ac
, call
, GFP_NOFS
, false);
2081 * Deliver reply data to an FS.FetchStatus with no vnode.
2083 static int afs_deliver_fs_fetch_status(struct afs_call
*call
)
2085 struct afs_file_status
*status
= call
->reply
[1];
2086 struct afs_callback
*callback
= call
->reply
[2];
2087 struct afs_volsync
*volsync
= call
->reply
[3];
2088 struct afs_vnode
*vnode
= call
->reply
[0];
2092 ret
= afs_transfer_reply(call
);
2096 _enter("{%x:%u}", vnode
->fid
.vid
, vnode
->fid
.vnode
);
2098 /* unmarshall the reply once we've received all of it */
2100 xdr_decode_AFSFetchStatus(call
, &bp
, status
, vnode
,
2101 &call
->expected_version
, NULL
);
2102 callback
[call
->count
].version
= ntohl(bp
[0]);
2103 callback
[call
->count
].expiry
= ntohl(bp
[1]);
2104 callback
[call
->count
].type
= ntohl(bp
[2]);
2106 xdr_decode_AFSCallBack(call
, vnode
, &bp
);
2110 xdr_decode_AFSVolSync(&bp
, volsync
);
2112 _leave(" = 0 [done]");
2117 * FS.FetchStatus operation type
2119 static const struct afs_call_type afs_RXFSFetchStatus
= {
2120 .name
= "FS.FetchStatus",
2121 .op
= afs_FS_FetchStatus
,
2122 .deliver
= afs_deliver_fs_fetch_status
,
2123 .destructor
= afs_flat_call_destructor
,
2127 * Fetch the status information for a fid without needing a vnode handle.
2129 int afs_fs_fetch_status(struct afs_fs_cursor
*fc
,
2130 struct afs_net
*net
,
2131 struct afs_fid
*fid
,
2132 struct afs_file_status
*status
,
2133 struct afs_callback
*callback
,
2134 struct afs_volsync
*volsync
)
2136 struct afs_call
*call
;
2139 _enter(",%x,{%x:%u},,",
2140 key_serial(fc
->key
), fid
->vid
, fid
->vnode
);
2142 call
= afs_alloc_flat_call(net
, &afs_RXFSFetchStatus
, 16, (21 + 3 + 6) * 4);
2144 fc
->ac
.error
= -ENOMEM
;
2148 call
->key
= fc
->key
;
2149 call
->reply
[0] = NULL
; /* vnode for fid[0] */
2150 call
->reply
[1] = status
;
2151 call
->reply
[2] = callback
;
2152 call
->reply
[3] = volsync
;
2153 call
->expected_version
= 1; /* vnode->status.data_version */
2155 /* marshall the parameters */
2157 bp
[0] = htonl(FSFETCHSTATUS
);
2158 bp
[1] = htonl(fid
->vid
);
2159 bp
[2] = htonl(fid
->vnode
);
2160 bp
[3] = htonl(fid
->unique
);
2162 call
->cb_break
= fc
->cb_break
;
2163 afs_use_fs_server(call
, fc
->cbi
);
2164 trace_afs_make_fs_call(call
, fid
);
2165 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);
2169 * Deliver reply data to an FS.InlineBulkStatus call
2171 static int afs_deliver_fs_inline_bulk_status(struct afs_call
*call
)
2173 struct afs_file_status
*statuses
;
2174 struct afs_callback
*callbacks
;
2175 struct afs_vnode
*vnode
= call
->reply
[0];
2180 _enter("{%u}", call
->unmarshall
);
2182 switch (call
->unmarshall
) {
2187 /* Extract the file status count and array in two steps */
2189 _debug("extract status count");
2190 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
2194 tmp
= ntohl(call
->tmp
);
2195 _debug("status count: %u/%u", tmp
, call
->count2
);
2196 if (tmp
!= call
->count2
)
2197 return afs_protocol_error(call
, -EBADMSG
);
2205 _debug("extract status array %u", call
->count
);
2206 ret
= afs_extract_data(call
, call
->buffer
, 21 * 4, true);
2211 statuses
= call
->reply
[1];
2212 if (xdr_decode_AFSFetchStatus(call
, &bp
, &statuses
[call
->count
],
2213 call
->count
== 0 ? vnode
: NULL
,
2215 return afs_protocol_error(call
, -EBADMSG
);
2218 if (call
->count
< call
->count2
)
2225 /* Extract the callback count and array in two steps */
2227 _debug("extract CB count");
2228 ret
= afs_extract_data(call
, &call
->tmp
, 4, true);
2232 tmp
= ntohl(call
->tmp
);
2233 _debug("CB count: %u", tmp
);
2234 if (tmp
!= call
->count2
)
2235 return afs_protocol_error(call
, -EBADMSG
);
2242 _debug("extract CB array");
2243 ret
= afs_extract_data(call
, call
->buffer
, 3 * 4, true);
2247 _debug("unmarshall CB array");
2249 callbacks
= call
->reply
[2];
2250 callbacks
[call
->count
].version
= ntohl(bp
[0]);
2251 callbacks
[call
->count
].expiry
= ntohl(bp
[1]);
2252 callbacks
[call
->count
].type
= ntohl(bp
[2]);
2253 statuses
= call
->reply
[1];
2254 if (call
->count
== 0 && vnode
&& statuses
[0].abort_code
== 0)
2255 xdr_decode_AFSCallBack(call
, vnode
, &bp
);
2257 if (call
->count
< call
->count2
)
2264 ret
= afs_extract_data(call
, call
->buffer
, 6 * 4, false);
2270 xdr_decode_AFSVolSync(&bp
, call
->reply
[3]);
2279 _leave(" = 0 [done]");
2284 * FS.InlineBulkStatus operation type
2286 static const struct afs_call_type afs_RXFSInlineBulkStatus
= {
2287 .name
= "FS.InlineBulkStatus",
2288 .op
= afs_FS_InlineBulkStatus
,
2289 .deliver
= afs_deliver_fs_inline_bulk_status
,
2290 .destructor
= afs_flat_call_destructor
,
2294 * Fetch the status information for up to 50 files
2296 int afs_fs_inline_bulk_status(struct afs_fs_cursor
*fc
,
2297 struct afs_net
*net
,
2298 struct afs_fid
*fids
,
2299 struct afs_file_status
*statuses
,
2300 struct afs_callback
*callbacks
,
2301 unsigned int nr_fids
,
2302 struct afs_volsync
*volsync
)
2304 struct afs_call
*call
;
2308 _enter(",%x,{%x:%u},%u",
2309 key_serial(fc
->key
), fids
[0].vid
, fids
[1].vnode
, nr_fids
);
2311 call
= afs_alloc_flat_call(net
, &afs_RXFSInlineBulkStatus
,
2312 (2 + nr_fids
* 3) * 4,
2315 fc
->ac
.error
= -ENOMEM
;
2319 call
->key
= fc
->key
;
2320 call
->reply
[0] = NULL
; /* vnode for fid[0] */
2321 call
->reply
[1] = statuses
;
2322 call
->reply
[2] = callbacks
;
2323 call
->reply
[3] = volsync
;
2324 call
->count2
= nr_fids
;
2326 /* marshall the parameters */
2328 *bp
++ = htonl(FSINLINEBULKSTATUS
);
2329 *bp
++ = htonl(nr_fids
);
2330 for (i
= 0; i
< nr_fids
; i
++) {
2331 *bp
++ = htonl(fids
[i
].vid
);
2332 *bp
++ = htonl(fids
[i
].vnode
);
2333 *bp
++ = htonl(fids
[i
].unique
);
2336 call
->cb_break
= fc
->cb_break
;
2337 afs_use_fs_server(call
, fc
->cbi
);
2338 trace_afs_make_fs_call(call
, &fids
[0]);
2339 return afs_make_call(&fc
->ac
, call
, GFP_NOFS
, false);