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>
20 * decode an AFSFid block
22 static void xdr_decode_AFSFid(const __be32
**_bp
, struct afs_fid
*fid
)
24 const __be32
*bp
= *_bp
;
26 fid
->vid
= ntohl(*bp
++);
27 fid
->vnode
= ntohl(*bp
++);
28 fid
->unique
= ntohl(*bp
++);
33 * decode an AFSFetchStatus block
35 static void xdr_decode_AFSFetchStatus(const __be32
**_bp
,
36 struct afs_file_status
*status
,
37 struct afs_vnode
*vnode
,
38 afs_dataversion_t
*store_version
)
40 afs_dataversion_t expected_version
;
41 const __be32
*bp
= *_bp
;
43 u64 data_version
, size
;
44 u32 changed
= 0; /* becomes non-zero if ctime-type changes seen */
48 #define EXTRACT(DST) \
50 u32 x = ntohl(*bp++); \
55 status
->if_version
= ntohl(*bp
++);
56 EXTRACT(status
->type
);
57 EXTRACT(status
->nlink
);
59 data_version
= ntohl(*bp
++);
60 EXTRACT(status
->author
);
61 owner
= make_kuid(&init_user_ns
, ntohl(*bp
++));
62 changed
|= !uid_eq(owner
, status
->owner
);
63 status
->owner
= owner
;
64 EXTRACT(status
->caller_access
); /* call ticket dependent */
65 EXTRACT(status
->anon_access
);
66 EXTRACT(status
->mode
);
67 EXTRACT(status
->parent
.vnode
);
68 EXTRACT(status
->parent
.unique
);
70 status
->mtime_client
= ntohl(*bp
++);
71 status
->mtime_server
= ntohl(*bp
++);
72 group
= make_kgid(&init_user_ns
, ntohl(*bp
++));
73 changed
|= !gid_eq(group
, status
->group
);
74 status
->group
= group
;
75 bp
++; /* sync counter */
76 data_version
|= (u64
) ntohl(*bp
++) << 32;
77 EXTRACT(status
->lock_count
);
78 size
|= (u64
) ntohl(*bp
++) << 32;
82 if (size
!= status
->size
) {
86 status
->mode
&= S_IALLUGO
;
88 _debug("vnode time %lx, %lx",
89 status
->mtime_client
, status
->mtime_server
);
92 status
->parent
.vid
= vnode
->fid
.vid
;
93 if (changed
&& !test_bit(AFS_VNODE_UNSET
, &vnode
->flags
)) {
94 _debug("vnode changed");
95 i_size_write(&vnode
->vfs_inode
, size
);
96 vnode
->vfs_inode
.i_uid
= status
->owner
;
97 vnode
->vfs_inode
.i_gid
= status
->group
;
98 vnode
->vfs_inode
.i_generation
= vnode
->fid
.unique
;
99 set_nlink(&vnode
->vfs_inode
, status
->nlink
);
101 mode
= vnode
->vfs_inode
.i_mode
;
103 mode
|= status
->mode
;
105 vnode
->vfs_inode
.i_mode
= mode
;
108 vnode
->vfs_inode
.i_ctime
.tv_sec
= status
->mtime_server
;
109 vnode
->vfs_inode
.i_mtime
= vnode
->vfs_inode
.i_ctime
;
110 vnode
->vfs_inode
.i_atime
= vnode
->vfs_inode
.i_ctime
;
111 vnode
->vfs_inode
.i_version
= data_version
;
114 expected_version
= status
->data_version
;
116 expected_version
= *store_version
;
118 if (expected_version
!= data_version
) {
119 status
->data_version
= data_version
;
120 if (vnode
&& !test_bit(AFS_VNODE_UNSET
, &vnode
->flags
)) {
121 _debug("vnode modified %llx on {%x:%u}",
122 (unsigned long long) data_version
,
123 vnode
->fid
.vid
, vnode
->fid
.vnode
);
124 set_bit(AFS_VNODE_MODIFIED
, &vnode
->flags
);
125 set_bit(AFS_VNODE_ZAP_DATA
, &vnode
->flags
);
127 } else if (store_version
) {
128 status
->data_version
= data_version
;
133 * decode an AFSCallBack block
135 static void xdr_decode_AFSCallBack(const __be32
**_bp
, struct afs_vnode
*vnode
)
137 const __be32
*bp
= *_bp
;
139 vnode
->cb_version
= ntohl(*bp
++);
140 vnode
->cb_expiry
= ntohl(*bp
++);
141 vnode
->cb_type
= ntohl(*bp
++);
142 vnode
->cb_expires
= vnode
->cb_expiry
+ get_seconds();
146 static void xdr_decode_AFSCallBack_raw(const __be32
**_bp
,
147 struct afs_callback
*cb
)
149 const __be32
*bp
= *_bp
;
151 cb
->version
= ntohl(*bp
++);
152 cb
->expiry
= ntohl(*bp
++);
153 cb
->type
= ntohl(*bp
++);
158 * decode an AFSVolSync block
160 static void xdr_decode_AFSVolSync(const __be32
**_bp
,
161 struct afs_volsync
*volsync
)
163 const __be32
*bp
= *_bp
;
165 volsync
->creation
= ntohl(*bp
++);
175 * encode the requested attributes into an AFSStoreStatus block
177 static void xdr_encode_AFS_StoreStatus(__be32
**_bp
, struct iattr
*attr
)
180 u32 mask
= 0, mtime
= 0, owner
= 0, group
= 0, mode
= 0;
183 if (attr
->ia_valid
& ATTR_MTIME
) {
184 mask
|= AFS_SET_MTIME
;
185 mtime
= attr
->ia_mtime
.tv_sec
;
188 if (attr
->ia_valid
& ATTR_UID
) {
189 mask
|= AFS_SET_OWNER
;
190 owner
= from_kuid(&init_user_ns
, attr
->ia_uid
);
193 if (attr
->ia_valid
& ATTR_GID
) {
194 mask
|= AFS_SET_GROUP
;
195 group
= from_kgid(&init_user_ns
, attr
->ia_gid
);
198 if (attr
->ia_valid
& ATTR_MODE
) {
199 mask
|= AFS_SET_MODE
;
200 mode
= attr
->ia_mode
& S_IALLUGO
;
204 *bp
++ = htonl(mtime
);
205 *bp
++ = htonl(owner
);
206 *bp
++ = htonl(group
);
208 *bp
++ = 0; /* segment size */
213 * decode an AFSFetchVolumeStatus block
215 static void xdr_decode_AFSFetchVolumeStatus(const __be32
**_bp
,
216 struct afs_volume_status
*vs
)
218 const __be32
*bp
= *_bp
;
220 vs
->vid
= ntohl(*bp
++);
221 vs
->parent_id
= ntohl(*bp
++);
222 vs
->online
= ntohl(*bp
++);
223 vs
->in_service
= ntohl(*bp
++);
224 vs
->blessed
= ntohl(*bp
++);
225 vs
->needs_salvage
= ntohl(*bp
++);
226 vs
->type
= ntohl(*bp
++);
227 vs
->min_quota
= ntohl(*bp
++);
228 vs
->max_quota
= ntohl(*bp
++);
229 vs
->blocks_in_use
= ntohl(*bp
++);
230 vs
->part_blocks_avail
= ntohl(*bp
++);
231 vs
->part_max_blocks
= ntohl(*bp
++);
236 * deliver reply data to an FS.FetchStatus
238 static int afs_deliver_fs_fetch_status(struct afs_call
*call
,
239 struct sk_buff
*skb
, bool last
)
241 struct afs_vnode
*vnode
= call
->reply
;
244 _enter(",,%u", last
);
246 afs_transfer_reply(call
, skb
);
250 if (call
->reply_size
!= call
->reply_max
)
253 /* unmarshall the reply once we've received all of it */
255 xdr_decode_AFSFetchStatus(&bp
, &vnode
->status
, vnode
, NULL
);
256 xdr_decode_AFSCallBack(&bp
, vnode
);
258 xdr_decode_AFSVolSync(&bp
, call
->reply2
);
260 _leave(" = 0 [done]");
265 * FS.FetchStatus operation type
267 static const struct afs_call_type afs_RXFSFetchStatus
= {
268 .name
= "FS.FetchStatus",
269 .deliver
= afs_deliver_fs_fetch_status
,
270 .abort_to_error
= afs_abort_to_error
,
271 .destructor
= afs_flat_call_destructor
,
275 * fetch the status information for a file
277 int afs_fs_fetch_file_status(struct afs_server
*server
,
279 struct afs_vnode
*vnode
,
280 struct afs_volsync
*volsync
,
281 const struct afs_wait_mode
*wait_mode
)
283 struct afs_call
*call
;
286 _enter(",%x,{%x:%u},,",
287 key_serial(key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
289 call
= afs_alloc_flat_call(&afs_RXFSFetchStatus
, 16, (21 + 3 + 6) * 4);
295 call
->reply2
= volsync
;
296 call
->service_id
= FS_SERVICE
;
297 call
->port
= htons(AFS_FS_PORT
);
299 /* marshall the parameters */
301 bp
[0] = htonl(FSFETCHSTATUS
);
302 bp
[1] = htonl(vnode
->fid
.vid
);
303 bp
[2] = htonl(vnode
->fid
.vnode
);
304 bp
[3] = htonl(vnode
->fid
.unique
);
306 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
310 * deliver reply data to an FS.FetchData
312 static int afs_deliver_fs_fetch_data(struct afs_call
*call
,
313 struct sk_buff
*skb
, bool last
)
315 struct afs_vnode
*vnode
= call
->reply
;
321 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
323 switch (call
->unmarshall
) {
327 if (call
->operation_ID
!= FSFETCHDATA64
) {
332 /* extract the upper part of the returned data length of an
333 * FSFETCHDATA64 op (which should always be 0 using this
336 _debug("extract data length (MSW)");
337 ret
= afs_extract_data(call
, skb
, last
, &call
->tmp
, 4);
340 case -EAGAIN
: return 0;
344 call
->count
= ntohl(call
->tmp
);
345 _debug("DATA length MSW: %u", call
->count
);
352 /* extract the returned data length */
354 _debug("extract data length");
355 ret
= afs_extract_data(call
, skb
, last
, &call
->tmp
, 4);
358 case -EAGAIN
: return 0;
362 call
->count
= ntohl(call
->tmp
);
363 _debug("DATA length: %u", call
->count
);
364 if (call
->count
> PAGE_SIZE
)
369 /* extract the returned data */
371 _debug("extract data");
372 if (call
->count
> 0) {
374 buffer
= kmap_atomic(page
);
375 ret
= afs_extract_data(call
, skb
, last
, buffer
,
377 kunmap_atomic(buffer
);
380 case -EAGAIN
: return 0;
388 /* extract the metadata */
390 ret
= afs_extract_data(call
, skb
, last
, call
->buffer
,
394 case -EAGAIN
: return 0;
399 xdr_decode_AFSFetchStatus(&bp
, &vnode
->status
, vnode
, NULL
);
400 xdr_decode_AFSCallBack(&bp
, vnode
);
402 xdr_decode_AFSVolSync(&bp
, call
->reply2
);
417 if (call
->count
< PAGE_SIZE
) {
420 buffer
= kmap_atomic(page
);
421 memset(buffer
+ call
->count
, 0, PAGE_SIZE
- call
->count
);
422 kunmap_atomic(buffer
);
425 _leave(" = 0 [done]");
430 * FS.FetchData operation type
432 static const struct afs_call_type afs_RXFSFetchData
= {
433 .name
= "FS.FetchData",
434 .deliver
= afs_deliver_fs_fetch_data
,
435 .abort_to_error
= afs_abort_to_error
,
436 .destructor
= afs_flat_call_destructor
,
439 static const struct afs_call_type afs_RXFSFetchData64
= {
440 .name
= "FS.FetchData64",
441 .deliver
= afs_deliver_fs_fetch_data
,
442 .abort_to_error
= afs_abort_to_error
,
443 .destructor
= afs_flat_call_destructor
,
447 * fetch data from a very large file
449 static int afs_fs_fetch_data64(struct afs_server
*server
,
451 struct afs_vnode
*vnode
,
452 off_t offset
, size_t length
,
454 const struct afs_wait_mode
*wait_mode
)
456 struct afs_call
*call
;
461 ASSERTCMP(length
, <, ULONG_MAX
);
463 call
= afs_alloc_flat_call(&afs_RXFSFetchData64
, 32, (21 + 3 + 6) * 4);
469 call
->reply2
= NULL
; /* volsync */
470 call
->reply3
= buffer
;
471 call
->service_id
= FS_SERVICE
;
472 call
->port
= htons(AFS_FS_PORT
);
473 call
->operation_ID
= FSFETCHDATA64
;
475 /* marshall the parameters */
477 bp
[0] = htonl(FSFETCHDATA64
);
478 bp
[1] = htonl(vnode
->fid
.vid
);
479 bp
[2] = htonl(vnode
->fid
.vnode
);
480 bp
[3] = htonl(vnode
->fid
.unique
);
481 bp
[4] = htonl(upper_32_bits(offset
));
482 bp
[5] = htonl((u32
) offset
);
484 bp
[7] = htonl((u32
) length
);
486 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
490 * fetch data from a file
492 int afs_fs_fetch_data(struct afs_server
*server
,
494 struct afs_vnode
*vnode
,
495 off_t offset
, size_t length
,
497 const struct afs_wait_mode
*wait_mode
)
499 struct afs_call
*call
;
502 if (upper_32_bits(offset
) || upper_32_bits(offset
+ length
))
503 return afs_fs_fetch_data64(server
, key
, vnode
, offset
, length
,
508 call
= afs_alloc_flat_call(&afs_RXFSFetchData
, 24, (21 + 3 + 6) * 4);
514 call
->reply2
= NULL
; /* volsync */
515 call
->reply3
= buffer
;
516 call
->service_id
= FS_SERVICE
;
517 call
->port
= htons(AFS_FS_PORT
);
518 call
->operation_ID
= FSFETCHDATA
;
520 /* marshall the parameters */
522 bp
[0] = htonl(FSFETCHDATA
);
523 bp
[1] = htonl(vnode
->fid
.vid
);
524 bp
[2] = htonl(vnode
->fid
.vnode
);
525 bp
[3] = htonl(vnode
->fid
.unique
);
526 bp
[4] = htonl(offset
);
527 bp
[5] = htonl(length
);
529 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
533 * deliver reply data to an FS.GiveUpCallBacks
535 static int afs_deliver_fs_give_up_callbacks(struct afs_call
*call
,
536 struct sk_buff
*skb
, bool last
)
538 _enter(",{%u},%d", skb
->len
, last
);
541 return -EBADMSG
; /* shouldn't be any reply data */
546 * FS.GiveUpCallBacks operation type
548 static const struct afs_call_type afs_RXFSGiveUpCallBacks
= {
549 .name
= "FS.GiveUpCallBacks",
550 .deliver
= afs_deliver_fs_give_up_callbacks
,
551 .abort_to_error
= afs_abort_to_error
,
552 .destructor
= afs_flat_call_destructor
,
556 * give up a set of callbacks
557 * - the callbacks are held in the server->cb_break ring
559 int afs_fs_give_up_callbacks(struct afs_server
*server
,
560 const struct afs_wait_mode
*wait_mode
)
562 struct afs_call
*call
;
567 ncallbacks
= CIRC_CNT(server
->cb_break_head
, server
->cb_break_tail
,
568 ARRAY_SIZE(server
->cb_break
));
570 _enter("{%zu},", ncallbacks
);
574 if (ncallbacks
> AFSCBMAX
)
575 ncallbacks
= AFSCBMAX
;
577 _debug("break %zu callbacks", ncallbacks
);
579 call
= afs_alloc_flat_call(&afs_RXFSGiveUpCallBacks
,
580 12 + ncallbacks
* 6 * 4, 0);
584 call
->service_id
= FS_SERVICE
;
585 call
->port
= htons(AFS_FS_PORT
);
587 /* marshall the parameters */
589 tp
= bp
+ 2 + ncallbacks
* 3;
590 *bp
++ = htonl(FSGIVEUPCALLBACKS
);
591 *bp
++ = htonl(ncallbacks
);
592 *tp
++ = htonl(ncallbacks
);
594 atomic_sub(ncallbacks
, &server
->cb_break_n
);
595 for (loop
= ncallbacks
; loop
> 0; loop
--) {
596 struct afs_callback
*cb
=
597 &server
->cb_break
[server
->cb_break_tail
];
599 *bp
++ = htonl(cb
->fid
.vid
);
600 *bp
++ = htonl(cb
->fid
.vnode
);
601 *bp
++ = htonl(cb
->fid
.unique
);
602 *tp
++ = htonl(cb
->version
);
603 *tp
++ = htonl(cb
->expiry
);
604 *tp
++ = htonl(cb
->type
);
606 server
->cb_break_tail
=
607 (server
->cb_break_tail
+ 1) &
608 (ARRAY_SIZE(server
->cb_break
) - 1);
611 ASSERT(ncallbacks
> 0);
612 wake_up_nr(&server
->cb_break_waitq
, ncallbacks
);
614 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
618 * deliver reply data to an FS.CreateFile or an FS.MakeDir
620 static int afs_deliver_fs_create_vnode(struct afs_call
*call
,
621 struct sk_buff
*skb
, bool last
)
623 struct afs_vnode
*vnode
= call
->reply
;
626 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
628 afs_transfer_reply(call
, skb
);
632 if (call
->reply_size
!= call
->reply_max
)
635 /* unmarshall the reply once we've received all of it */
637 xdr_decode_AFSFid(&bp
, call
->reply2
);
638 xdr_decode_AFSFetchStatus(&bp
, call
->reply3
, NULL
, NULL
);
639 xdr_decode_AFSFetchStatus(&bp
, &vnode
->status
, vnode
, NULL
);
640 xdr_decode_AFSCallBack_raw(&bp
, call
->reply4
);
641 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
643 _leave(" = 0 [done]");
648 * FS.CreateFile and FS.MakeDir operation type
650 static const struct afs_call_type afs_RXFSCreateXXXX
= {
651 .name
= "FS.CreateXXXX",
652 .deliver
= afs_deliver_fs_create_vnode
,
653 .abort_to_error
= afs_abort_to_error
,
654 .destructor
= afs_flat_call_destructor
,
658 * create a file or make a directory
660 int afs_fs_create(struct afs_server
*server
,
662 struct afs_vnode
*vnode
,
665 struct afs_fid
*newfid
,
666 struct afs_file_status
*newstatus
,
667 struct afs_callback
*newcb
,
668 const struct afs_wait_mode
*wait_mode
)
670 struct afs_call
*call
;
671 size_t namesz
, reqsz
, padsz
;
676 namesz
= strlen(name
);
677 padsz
= (4 - (namesz
& 3)) & 3;
678 reqsz
= (5 * 4) + namesz
+ padsz
+ (6 * 4);
680 call
= afs_alloc_flat_call(&afs_RXFSCreateXXXX
, reqsz
,
681 (3 + 21 + 21 + 3 + 6) * 4);
687 call
->reply2
= newfid
;
688 call
->reply3
= newstatus
;
689 call
->reply4
= newcb
;
690 call
->service_id
= FS_SERVICE
;
691 call
->port
= htons(AFS_FS_PORT
);
693 /* marshall the parameters */
695 *bp
++ = htonl(S_ISDIR(mode
) ? FSMAKEDIR
: FSCREATEFILE
);
696 *bp
++ = htonl(vnode
->fid
.vid
);
697 *bp
++ = htonl(vnode
->fid
.vnode
);
698 *bp
++ = htonl(vnode
->fid
.unique
);
699 *bp
++ = htonl(namesz
);
700 memcpy(bp
, name
, namesz
);
701 bp
= (void *) bp
+ namesz
;
703 memset(bp
, 0, padsz
);
704 bp
= (void *) bp
+ padsz
;
706 *bp
++ = htonl(AFS_SET_MODE
);
707 *bp
++ = 0; /* mtime */
708 *bp
++ = 0; /* owner */
709 *bp
++ = 0; /* group */
710 *bp
++ = htonl(mode
& S_IALLUGO
); /* unix mode */
711 *bp
++ = 0; /* segment size */
713 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
717 * deliver reply data to an FS.RemoveFile or FS.RemoveDir
719 static int afs_deliver_fs_remove(struct afs_call
*call
,
720 struct sk_buff
*skb
, bool last
)
722 struct afs_vnode
*vnode
= call
->reply
;
725 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
727 afs_transfer_reply(call
, skb
);
731 if (call
->reply_size
!= call
->reply_max
)
734 /* unmarshall the reply once we've received all of it */
736 xdr_decode_AFSFetchStatus(&bp
, &vnode
->status
, vnode
, NULL
);
737 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
739 _leave(" = 0 [done]");
744 * FS.RemoveDir/FS.RemoveFile operation type
746 static const struct afs_call_type afs_RXFSRemoveXXXX
= {
747 .name
= "FS.RemoveXXXX",
748 .deliver
= afs_deliver_fs_remove
,
749 .abort_to_error
= afs_abort_to_error
,
750 .destructor
= afs_flat_call_destructor
,
754 * remove a file or directory
756 int afs_fs_remove(struct afs_server
*server
,
758 struct afs_vnode
*vnode
,
761 const struct afs_wait_mode
*wait_mode
)
763 struct afs_call
*call
;
764 size_t namesz
, reqsz
, padsz
;
769 namesz
= strlen(name
);
770 padsz
= (4 - (namesz
& 3)) & 3;
771 reqsz
= (5 * 4) + namesz
+ padsz
;
773 call
= afs_alloc_flat_call(&afs_RXFSRemoveXXXX
, reqsz
, (21 + 6) * 4);
779 call
->service_id
= FS_SERVICE
;
780 call
->port
= htons(AFS_FS_PORT
);
782 /* marshall the parameters */
784 *bp
++ = htonl(isdir
? FSREMOVEDIR
: FSREMOVEFILE
);
785 *bp
++ = htonl(vnode
->fid
.vid
);
786 *bp
++ = htonl(vnode
->fid
.vnode
);
787 *bp
++ = htonl(vnode
->fid
.unique
);
788 *bp
++ = htonl(namesz
);
789 memcpy(bp
, name
, namesz
);
790 bp
= (void *) bp
+ namesz
;
792 memset(bp
, 0, padsz
);
793 bp
= (void *) bp
+ padsz
;
796 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
800 * deliver reply data to an FS.Link
802 static int afs_deliver_fs_link(struct afs_call
*call
,
803 struct sk_buff
*skb
, bool last
)
805 struct afs_vnode
*dvnode
= call
->reply
, *vnode
= call
->reply2
;
808 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
810 afs_transfer_reply(call
, skb
);
814 if (call
->reply_size
!= call
->reply_max
)
817 /* unmarshall the reply once we've received all of it */
819 xdr_decode_AFSFetchStatus(&bp
, &vnode
->status
, vnode
, NULL
);
820 xdr_decode_AFSFetchStatus(&bp
, &dvnode
->status
, dvnode
, NULL
);
821 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
823 _leave(" = 0 [done]");
828 * FS.Link operation type
830 static const struct afs_call_type afs_RXFSLink
= {
832 .deliver
= afs_deliver_fs_link
,
833 .abort_to_error
= afs_abort_to_error
,
834 .destructor
= afs_flat_call_destructor
,
840 int afs_fs_link(struct afs_server
*server
,
842 struct afs_vnode
*dvnode
,
843 struct afs_vnode
*vnode
,
845 const struct afs_wait_mode
*wait_mode
)
847 struct afs_call
*call
;
848 size_t namesz
, reqsz
, padsz
;
853 namesz
= strlen(name
);
854 padsz
= (4 - (namesz
& 3)) & 3;
855 reqsz
= (5 * 4) + namesz
+ padsz
+ (3 * 4);
857 call
= afs_alloc_flat_call(&afs_RXFSLink
, reqsz
, (21 + 21 + 6) * 4);
862 call
->reply
= dvnode
;
863 call
->reply2
= vnode
;
864 call
->service_id
= FS_SERVICE
;
865 call
->port
= htons(AFS_FS_PORT
);
867 /* marshall the parameters */
869 *bp
++ = htonl(FSLINK
);
870 *bp
++ = htonl(dvnode
->fid
.vid
);
871 *bp
++ = htonl(dvnode
->fid
.vnode
);
872 *bp
++ = htonl(dvnode
->fid
.unique
);
873 *bp
++ = htonl(namesz
);
874 memcpy(bp
, name
, namesz
);
875 bp
= (void *) bp
+ namesz
;
877 memset(bp
, 0, padsz
);
878 bp
= (void *) bp
+ padsz
;
880 *bp
++ = htonl(vnode
->fid
.vid
);
881 *bp
++ = htonl(vnode
->fid
.vnode
);
882 *bp
++ = htonl(vnode
->fid
.unique
);
884 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
888 * deliver reply data to an FS.Symlink
890 static int afs_deliver_fs_symlink(struct afs_call
*call
,
891 struct sk_buff
*skb
, bool last
)
893 struct afs_vnode
*vnode
= call
->reply
;
896 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
898 afs_transfer_reply(call
, skb
);
902 if (call
->reply_size
!= call
->reply_max
)
905 /* unmarshall the reply once we've received all of it */
907 xdr_decode_AFSFid(&bp
, call
->reply2
);
908 xdr_decode_AFSFetchStatus(&bp
, call
->reply3
, NULL
, NULL
);
909 xdr_decode_AFSFetchStatus(&bp
, &vnode
->status
, vnode
, NULL
);
910 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
912 _leave(" = 0 [done]");
917 * FS.Symlink operation type
919 static const struct afs_call_type afs_RXFSSymlink
= {
920 .name
= "FS.Symlink",
921 .deliver
= afs_deliver_fs_symlink
,
922 .abort_to_error
= afs_abort_to_error
,
923 .destructor
= afs_flat_call_destructor
,
927 * create a symbolic link
929 int afs_fs_symlink(struct afs_server
*server
,
931 struct afs_vnode
*vnode
,
933 const char *contents
,
934 struct afs_fid
*newfid
,
935 struct afs_file_status
*newstatus
,
936 const struct afs_wait_mode
*wait_mode
)
938 struct afs_call
*call
;
939 size_t namesz
, reqsz
, padsz
, c_namesz
, c_padsz
;
944 namesz
= strlen(name
);
945 padsz
= (4 - (namesz
& 3)) & 3;
947 c_namesz
= strlen(contents
);
948 c_padsz
= (4 - (c_namesz
& 3)) & 3;
950 reqsz
= (6 * 4) + namesz
+ padsz
+ c_namesz
+ c_padsz
+ (6 * 4);
952 call
= afs_alloc_flat_call(&afs_RXFSSymlink
, reqsz
,
953 (3 + 21 + 21 + 6) * 4);
959 call
->reply2
= newfid
;
960 call
->reply3
= newstatus
;
961 call
->service_id
= FS_SERVICE
;
962 call
->port
= htons(AFS_FS_PORT
);
964 /* marshall the parameters */
966 *bp
++ = htonl(FSSYMLINK
);
967 *bp
++ = htonl(vnode
->fid
.vid
);
968 *bp
++ = htonl(vnode
->fid
.vnode
);
969 *bp
++ = htonl(vnode
->fid
.unique
);
970 *bp
++ = htonl(namesz
);
971 memcpy(bp
, name
, namesz
);
972 bp
= (void *) bp
+ namesz
;
974 memset(bp
, 0, padsz
);
975 bp
= (void *) bp
+ padsz
;
977 *bp
++ = htonl(c_namesz
);
978 memcpy(bp
, contents
, c_namesz
);
979 bp
= (void *) bp
+ c_namesz
;
981 memset(bp
, 0, c_padsz
);
982 bp
= (void *) bp
+ c_padsz
;
984 *bp
++ = htonl(AFS_SET_MODE
);
985 *bp
++ = 0; /* mtime */
986 *bp
++ = 0; /* owner */
987 *bp
++ = 0; /* group */
988 *bp
++ = htonl(S_IRWXUGO
); /* unix mode */
989 *bp
++ = 0; /* segment size */
991 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
995 * deliver reply data to an FS.Rename
997 static int afs_deliver_fs_rename(struct afs_call
*call
,
998 struct sk_buff
*skb
, bool last
)
1000 struct afs_vnode
*orig_dvnode
= call
->reply
, *new_dvnode
= call
->reply2
;
1003 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
1005 afs_transfer_reply(call
, skb
);
1009 if (call
->reply_size
!= call
->reply_max
)
1012 /* unmarshall the reply once we've received all of it */
1014 xdr_decode_AFSFetchStatus(&bp
, &orig_dvnode
->status
, orig_dvnode
, NULL
);
1015 if (new_dvnode
!= orig_dvnode
)
1016 xdr_decode_AFSFetchStatus(&bp
, &new_dvnode
->status
, new_dvnode
,
1018 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
1020 _leave(" = 0 [done]");
1025 * FS.Rename operation type
1027 static const struct afs_call_type afs_RXFSRename
= {
1028 .name
= "FS.Rename",
1029 .deliver
= afs_deliver_fs_rename
,
1030 .abort_to_error
= afs_abort_to_error
,
1031 .destructor
= afs_flat_call_destructor
,
1035 * create a symbolic link
1037 int afs_fs_rename(struct afs_server
*server
,
1039 struct afs_vnode
*orig_dvnode
,
1040 const char *orig_name
,
1041 struct afs_vnode
*new_dvnode
,
1042 const char *new_name
,
1043 const struct afs_wait_mode
*wait_mode
)
1045 struct afs_call
*call
;
1046 size_t reqsz
, o_namesz
, o_padsz
, n_namesz
, n_padsz
;
1051 o_namesz
= strlen(orig_name
);
1052 o_padsz
= (4 - (o_namesz
& 3)) & 3;
1054 n_namesz
= strlen(new_name
);
1055 n_padsz
= (4 - (n_namesz
& 3)) & 3;
1058 4 + o_namesz
+ o_padsz
+
1060 4 + n_namesz
+ n_padsz
;
1062 call
= afs_alloc_flat_call(&afs_RXFSRename
, reqsz
, (21 + 21 + 6) * 4);
1067 call
->reply
= orig_dvnode
;
1068 call
->reply2
= new_dvnode
;
1069 call
->service_id
= FS_SERVICE
;
1070 call
->port
= htons(AFS_FS_PORT
);
1072 /* marshall the parameters */
1074 *bp
++ = htonl(FSRENAME
);
1075 *bp
++ = htonl(orig_dvnode
->fid
.vid
);
1076 *bp
++ = htonl(orig_dvnode
->fid
.vnode
);
1077 *bp
++ = htonl(orig_dvnode
->fid
.unique
);
1078 *bp
++ = htonl(o_namesz
);
1079 memcpy(bp
, orig_name
, o_namesz
);
1080 bp
= (void *) bp
+ o_namesz
;
1082 memset(bp
, 0, o_padsz
);
1083 bp
= (void *) bp
+ o_padsz
;
1086 *bp
++ = htonl(new_dvnode
->fid
.vid
);
1087 *bp
++ = htonl(new_dvnode
->fid
.vnode
);
1088 *bp
++ = htonl(new_dvnode
->fid
.unique
);
1089 *bp
++ = htonl(n_namesz
);
1090 memcpy(bp
, new_name
, n_namesz
);
1091 bp
= (void *) bp
+ n_namesz
;
1093 memset(bp
, 0, n_padsz
);
1094 bp
= (void *) bp
+ n_padsz
;
1097 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
1101 * deliver reply data to an FS.StoreData
1103 static int afs_deliver_fs_store_data(struct afs_call
*call
,
1104 struct sk_buff
*skb
, bool last
)
1106 struct afs_vnode
*vnode
= call
->reply
;
1109 _enter(",,%u", last
);
1111 afs_transfer_reply(call
, skb
);
1113 _leave(" = 0 [more]");
1117 if (call
->reply_size
!= call
->reply_max
) {
1118 _leave(" = -EBADMSG [%u != %u]",
1119 call
->reply_size
, call
->reply_max
);
1123 /* unmarshall the reply once we've received all of it */
1125 xdr_decode_AFSFetchStatus(&bp
, &vnode
->status
, vnode
,
1126 &call
->store_version
);
1127 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
1129 afs_pages_written_back(vnode
, call
);
1131 _leave(" = 0 [done]");
1136 * FS.StoreData operation type
1138 static const struct afs_call_type afs_RXFSStoreData
= {
1139 .name
= "FS.StoreData",
1140 .deliver
= afs_deliver_fs_store_data
,
1141 .abort_to_error
= afs_abort_to_error
,
1142 .destructor
= afs_flat_call_destructor
,
1145 static const struct afs_call_type afs_RXFSStoreData64
= {
1146 .name
= "FS.StoreData64",
1147 .deliver
= afs_deliver_fs_store_data
,
1148 .abort_to_error
= afs_abort_to_error
,
1149 .destructor
= afs_flat_call_destructor
,
1153 * store a set of pages to a very large file
1155 static int afs_fs_store_data64(struct afs_server
*server
,
1156 struct afs_writeback
*wb
,
1157 pgoff_t first
, pgoff_t last
,
1158 unsigned offset
, unsigned to
,
1159 loff_t size
, loff_t pos
, loff_t i_size
,
1160 const struct afs_wait_mode
*wait_mode
)
1162 struct afs_vnode
*vnode
= wb
->vnode
;
1163 struct afs_call
*call
;
1166 _enter(",%x,{%x:%u},,",
1167 key_serial(wb
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1169 call
= afs_alloc_flat_call(&afs_RXFSStoreData64
,
1170 (4 + 6 + 3 * 2) * 4,
1176 call
->key
= wb
->key
;
1177 call
->reply
= vnode
;
1178 call
->service_id
= FS_SERVICE
;
1179 call
->port
= htons(AFS_FS_PORT
);
1180 call
->mapping
= vnode
->vfs_inode
.i_mapping
;
1181 call
->first
= first
;
1183 call
->first_offset
= offset
;
1185 call
->send_pages
= true;
1186 call
->store_version
= vnode
->status
.data_version
+ 1;
1188 /* marshall the parameters */
1190 *bp
++ = htonl(FSSTOREDATA64
);
1191 *bp
++ = htonl(vnode
->fid
.vid
);
1192 *bp
++ = htonl(vnode
->fid
.vnode
);
1193 *bp
++ = htonl(vnode
->fid
.unique
);
1195 *bp
++ = 0; /* mask */
1196 *bp
++ = 0; /* mtime */
1197 *bp
++ = 0; /* owner */
1198 *bp
++ = 0; /* group */
1199 *bp
++ = 0; /* unix mode */
1200 *bp
++ = 0; /* segment size */
1202 *bp
++ = htonl(pos
>> 32);
1203 *bp
++ = htonl((u32
) pos
);
1204 *bp
++ = htonl(size
>> 32);
1205 *bp
++ = htonl((u32
) size
);
1206 *bp
++ = htonl(i_size
>> 32);
1207 *bp
++ = htonl((u32
) i_size
);
1209 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
1213 * store a set of pages
1215 int afs_fs_store_data(struct afs_server
*server
, struct afs_writeback
*wb
,
1216 pgoff_t first
, pgoff_t last
,
1217 unsigned offset
, unsigned to
,
1218 const struct afs_wait_mode
*wait_mode
)
1220 struct afs_vnode
*vnode
= wb
->vnode
;
1221 struct afs_call
*call
;
1222 loff_t size
, pos
, i_size
;
1225 _enter(",%x,{%x:%u},,",
1226 key_serial(wb
->key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1230 size
+= (loff_t
)(last
- first
) << PAGE_SHIFT
;
1231 pos
= (loff_t
)first
<< PAGE_SHIFT
;
1234 i_size
= i_size_read(&vnode
->vfs_inode
);
1235 if (pos
+ size
> i_size
)
1236 i_size
= size
+ pos
;
1238 _debug("size %llx, at %llx, i_size %llx",
1239 (unsigned long long) size
, (unsigned long long) pos
,
1240 (unsigned long long) i_size
);
1242 if (pos
>> 32 || i_size
>> 32 || size
>> 32 || (pos
+ size
) >> 32)
1243 return afs_fs_store_data64(server
, wb
, first
, last
, offset
, to
,
1244 size
, pos
, i_size
, wait_mode
);
1246 call
= afs_alloc_flat_call(&afs_RXFSStoreData
,
1253 call
->key
= wb
->key
;
1254 call
->reply
= vnode
;
1255 call
->service_id
= FS_SERVICE
;
1256 call
->port
= htons(AFS_FS_PORT
);
1257 call
->mapping
= vnode
->vfs_inode
.i_mapping
;
1258 call
->first
= first
;
1260 call
->first_offset
= offset
;
1262 call
->send_pages
= true;
1263 call
->store_version
= vnode
->status
.data_version
+ 1;
1265 /* marshall the parameters */
1267 *bp
++ = htonl(FSSTOREDATA
);
1268 *bp
++ = htonl(vnode
->fid
.vid
);
1269 *bp
++ = htonl(vnode
->fid
.vnode
);
1270 *bp
++ = htonl(vnode
->fid
.unique
);
1272 *bp
++ = 0; /* mask */
1273 *bp
++ = 0; /* mtime */
1274 *bp
++ = 0; /* owner */
1275 *bp
++ = 0; /* group */
1276 *bp
++ = 0; /* unix mode */
1277 *bp
++ = 0; /* segment size */
1280 *bp
++ = htonl(size
);
1281 *bp
++ = htonl(i_size
);
1283 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
1287 * deliver reply data to an FS.StoreStatus
1289 static int afs_deliver_fs_store_status(struct afs_call
*call
,
1290 struct sk_buff
*skb
, bool last
)
1292 afs_dataversion_t
*store_version
;
1293 struct afs_vnode
*vnode
= call
->reply
;
1296 _enter(",,%u", last
);
1298 afs_transfer_reply(call
, skb
);
1300 _leave(" = 0 [more]");
1304 if (call
->reply_size
!= call
->reply_max
) {
1305 _leave(" = -EBADMSG [%u != %u]",
1306 call
->reply_size
, call
->reply_max
);
1310 /* unmarshall the reply once we've received all of it */
1311 store_version
= NULL
;
1312 if (call
->operation_ID
== FSSTOREDATA
)
1313 store_version
= &call
->store_version
;
1316 xdr_decode_AFSFetchStatus(&bp
, &vnode
->status
, vnode
, store_version
);
1317 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
1319 _leave(" = 0 [done]");
1324 * FS.StoreStatus operation type
1326 static const struct afs_call_type afs_RXFSStoreStatus
= {
1327 .name
= "FS.StoreStatus",
1328 .deliver
= afs_deliver_fs_store_status
,
1329 .abort_to_error
= afs_abort_to_error
,
1330 .destructor
= afs_flat_call_destructor
,
1333 static const struct afs_call_type afs_RXFSStoreData_as_Status
= {
1334 .name
= "FS.StoreData",
1335 .deliver
= afs_deliver_fs_store_status
,
1336 .abort_to_error
= afs_abort_to_error
,
1337 .destructor
= afs_flat_call_destructor
,
1340 static const struct afs_call_type afs_RXFSStoreData64_as_Status
= {
1341 .name
= "FS.StoreData64",
1342 .deliver
= afs_deliver_fs_store_status
,
1343 .abort_to_error
= afs_abort_to_error
,
1344 .destructor
= afs_flat_call_destructor
,
1348 * set the attributes on a very large file, using FS.StoreData rather than
1349 * FS.StoreStatus so as to alter the file size also
1351 static int afs_fs_setattr_size64(struct afs_server
*server
, struct key
*key
,
1352 struct afs_vnode
*vnode
, struct iattr
*attr
,
1353 const struct afs_wait_mode
*wait_mode
)
1355 struct afs_call
*call
;
1358 _enter(",%x,{%x:%u},,",
1359 key_serial(key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1361 ASSERT(attr
->ia_valid
& ATTR_SIZE
);
1363 call
= afs_alloc_flat_call(&afs_RXFSStoreData64_as_Status
,
1364 (4 + 6 + 3 * 2) * 4,
1370 call
->reply
= vnode
;
1371 call
->service_id
= FS_SERVICE
;
1372 call
->port
= htons(AFS_FS_PORT
);
1373 call
->store_version
= vnode
->status
.data_version
+ 1;
1374 call
->operation_ID
= FSSTOREDATA
;
1376 /* marshall the parameters */
1378 *bp
++ = htonl(FSSTOREDATA64
);
1379 *bp
++ = htonl(vnode
->fid
.vid
);
1380 *bp
++ = htonl(vnode
->fid
.vnode
);
1381 *bp
++ = htonl(vnode
->fid
.unique
);
1383 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1385 *bp
++ = 0; /* position of start of write */
1387 *bp
++ = 0; /* size of write */
1389 *bp
++ = htonl(attr
->ia_size
>> 32); /* new file length */
1390 *bp
++ = htonl((u32
) attr
->ia_size
);
1392 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
1396 * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
1397 * so as to alter the file size also
1399 static int afs_fs_setattr_size(struct afs_server
*server
, struct key
*key
,
1400 struct afs_vnode
*vnode
, struct iattr
*attr
,
1401 const struct afs_wait_mode
*wait_mode
)
1403 struct afs_call
*call
;
1406 _enter(",%x,{%x:%u},,",
1407 key_serial(key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1409 ASSERT(attr
->ia_valid
& ATTR_SIZE
);
1410 if (attr
->ia_size
>> 32)
1411 return afs_fs_setattr_size64(server
, key
, vnode
, attr
,
1414 call
= afs_alloc_flat_call(&afs_RXFSStoreData_as_Status
,
1421 call
->reply
= vnode
;
1422 call
->service_id
= FS_SERVICE
;
1423 call
->port
= htons(AFS_FS_PORT
);
1424 call
->store_version
= vnode
->status
.data_version
+ 1;
1425 call
->operation_ID
= FSSTOREDATA
;
1427 /* marshall the parameters */
1429 *bp
++ = htonl(FSSTOREDATA
);
1430 *bp
++ = htonl(vnode
->fid
.vid
);
1431 *bp
++ = htonl(vnode
->fid
.vnode
);
1432 *bp
++ = htonl(vnode
->fid
.unique
);
1434 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1436 *bp
++ = 0; /* position of start of write */
1437 *bp
++ = 0; /* size of write */
1438 *bp
++ = htonl(attr
->ia_size
); /* new file length */
1440 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
1444 * set the attributes on a file, using FS.StoreData if there's a change in file
1445 * size, and FS.StoreStatus otherwise
1447 int afs_fs_setattr(struct afs_server
*server
, struct key
*key
,
1448 struct afs_vnode
*vnode
, struct iattr
*attr
,
1449 const struct afs_wait_mode
*wait_mode
)
1451 struct afs_call
*call
;
1454 if (attr
->ia_valid
& ATTR_SIZE
)
1455 return afs_fs_setattr_size(server
, key
, vnode
, attr
,
1458 _enter(",%x,{%x:%u},,",
1459 key_serial(key
), vnode
->fid
.vid
, vnode
->fid
.vnode
);
1461 call
= afs_alloc_flat_call(&afs_RXFSStoreStatus
,
1468 call
->reply
= vnode
;
1469 call
->service_id
= FS_SERVICE
;
1470 call
->port
= htons(AFS_FS_PORT
);
1471 call
->operation_ID
= FSSTORESTATUS
;
1473 /* marshall the parameters */
1475 *bp
++ = htonl(FSSTORESTATUS
);
1476 *bp
++ = htonl(vnode
->fid
.vid
);
1477 *bp
++ = htonl(vnode
->fid
.vnode
);
1478 *bp
++ = htonl(vnode
->fid
.unique
);
1480 xdr_encode_AFS_StoreStatus(&bp
, attr
);
1482 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
1486 * deliver reply data to an FS.GetVolumeStatus
1488 static int afs_deliver_fs_get_volume_status(struct afs_call
*call
,
1489 struct sk_buff
*skb
, bool last
)
1495 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
1497 switch (call
->unmarshall
) {
1502 /* extract the returned status record */
1504 _debug("extract status");
1505 ret
= afs_extract_data(call
, skb
, last
, call
->buffer
,
1509 case -EAGAIN
: return 0;
1510 default: return ret
;
1514 xdr_decode_AFSFetchVolumeStatus(&bp
, call
->reply2
);
1518 /* extract the volume name length */
1520 ret
= afs_extract_data(call
, skb
, last
, &call
->tmp
, 4);
1523 case -EAGAIN
: return 0;
1524 default: return ret
;
1527 call
->count
= ntohl(call
->tmp
);
1528 _debug("volname length: %u", call
->count
);
1529 if (call
->count
>= AFSNAMEMAX
)
1534 /* extract the volume name */
1536 _debug("extract volname");
1537 if (call
->count
> 0) {
1538 ret
= afs_extract_data(call
, skb
, last
, call
->reply3
,
1542 case -EAGAIN
: return 0;
1543 default: return ret
;
1549 _debug("volname '%s'", p
);
1554 /* extract the volume name padding */
1555 if ((call
->count
& 3) == 0) {
1557 goto no_volname_padding
;
1559 call
->count
= 4 - (call
->count
& 3);
1562 ret
= afs_extract_data(call
, skb
, last
, call
->buffer
,
1566 case -EAGAIN
: return 0;
1567 default: return ret
;
1574 /* extract the offline message length */
1576 ret
= afs_extract_data(call
, skb
, last
, &call
->tmp
, 4);
1579 case -EAGAIN
: return 0;
1580 default: return ret
;
1583 call
->count
= ntohl(call
->tmp
);
1584 _debug("offline msg length: %u", call
->count
);
1585 if (call
->count
>= AFSNAMEMAX
)
1590 /* extract the offline message */
1592 _debug("extract offline");
1593 if (call
->count
> 0) {
1594 ret
= afs_extract_data(call
, skb
, last
, call
->reply3
,
1598 case -EAGAIN
: return 0;
1599 default: return ret
;
1605 _debug("offline '%s'", p
);
1610 /* extract the offline message padding */
1611 if ((call
->count
& 3) == 0) {
1613 goto no_offline_padding
;
1615 call
->count
= 4 - (call
->count
& 3);
1618 ret
= afs_extract_data(call
, skb
, last
, call
->buffer
,
1622 case -EAGAIN
: return 0;
1623 default: return ret
;
1630 /* extract the message of the day length */
1632 ret
= afs_extract_data(call
, skb
, last
, &call
->tmp
, 4);
1635 case -EAGAIN
: return 0;
1636 default: return ret
;
1639 call
->count
= ntohl(call
->tmp
);
1640 _debug("motd length: %u", call
->count
);
1641 if (call
->count
>= AFSNAMEMAX
)
1646 /* extract the message of the day */
1648 _debug("extract motd");
1649 if (call
->count
> 0) {
1650 ret
= afs_extract_data(call
, skb
, last
, call
->reply3
,
1654 case -EAGAIN
: return 0;
1655 default: return ret
;
1661 _debug("motd '%s'", p
);
1666 /* extract the message of the day padding */
1667 if ((call
->count
& 3) == 0) {
1669 goto no_motd_padding
;
1671 call
->count
= 4 - (call
->count
& 3);
1674 ret
= afs_extract_data(call
, skb
, last
, call
->buffer
,
1678 case -EAGAIN
: return 0;
1679 default: return ret
;
1687 _debug("trailer %d", skb
->len
);
1696 _leave(" = 0 [done]");
1701 * destroy an FS.GetVolumeStatus call
1703 static void afs_get_volume_status_call_destructor(struct afs_call
*call
)
1705 kfree(call
->reply3
);
1706 call
->reply3
= NULL
;
1707 afs_flat_call_destructor(call
);
1711 * FS.GetVolumeStatus operation type
1713 static const struct afs_call_type afs_RXFSGetVolumeStatus
= {
1714 .name
= "FS.GetVolumeStatus",
1715 .deliver
= afs_deliver_fs_get_volume_status
,
1716 .abort_to_error
= afs_abort_to_error
,
1717 .destructor
= afs_get_volume_status_call_destructor
,
1721 * fetch the status of a volume
1723 int afs_fs_get_volume_status(struct afs_server
*server
,
1725 struct afs_vnode
*vnode
,
1726 struct afs_volume_status
*vs
,
1727 const struct afs_wait_mode
*wait_mode
)
1729 struct afs_call
*call
;
1735 tmpbuf
= kmalloc(AFSOPAQUEMAX
, GFP_KERNEL
);
1739 call
= afs_alloc_flat_call(&afs_RXFSGetVolumeStatus
, 2 * 4, 12 * 4);
1746 call
->reply
= vnode
;
1748 call
->reply3
= tmpbuf
;
1749 call
->service_id
= FS_SERVICE
;
1750 call
->port
= htons(AFS_FS_PORT
);
1752 /* marshall the parameters */
1754 bp
[0] = htonl(FSGETVOLUMESTATUS
);
1755 bp
[1] = htonl(vnode
->fid
.vid
);
1757 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
1761 * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
1763 static int afs_deliver_fs_xxxx_lock(struct afs_call
*call
,
1764 struct sk_buff
*skb
, bool last
)
1768 _enter("{%u},{%u},%d", call
->unmarshall
, skb
->len
, last
);
1770 afs_transfer_reply(call
, skb
);
1774 if (call
->reply_size
!= call
->reply_max
)
1777 /* unmarshall the reply once we've received all of it */
1779 /* xdr_decode_AFSVolSync(&bp, call->replyX); */
1781 _leave(" = 0 [done]");
1786 * FS.SetLock operation type
1788 static const struct afs_call_type afs_RXFSSetLock
= {
1789 .name
= "FS.SetLock",
1790 .deliver
= afs_deliver_fs_xxxx_lock
,
1791 .abort_to_error
= afs_abort_to_error
,
1792 .destructor
= afs_flat_call_destructor
,
1796 * FS.ExtendLock operation type
1798 static const struct afs_call_type afs_RXFSExtendLock
= {
1799 .name
= "FS.ExtendLock",
1800 .deliver
= afs_deliver_fs_xxxx_lock
,
1801 .abort_to_error
= afs_abort_to_error
,
1802 .destructor
= afs_flat_call_destructor
,
1806 * FS.ReleaseLock operation type
1808 static const struct afs_call_type afs_RXFSReleaseLock
= {
1809 .name
= "FS.ReleaseLock",
1810 .deliver
= afs_deliver_fs_xxxx_lock
,
1811 .abort_to_error
= afs_abort_to_error
,
1812 .destructor
= afs_flat_call_destructor
,
1816 * get a lock on a file
1818 int afs_fs_set_lock(struct afs_server
*server
,
1820 struct afs_vnode
*vnode
,
1821 afs_lock_type_t type
,
1822 const struct afs_wait_mode
*wait_mode
)
1824 struct afs_call
*call
;
1829 call
= afs_alloc_flat_call(&afs_RXFSSetLock
, 5 * 4, 6 * 4);
1834 call
->reply
= vnode
;
1835 call
->service_id
= FS_SERVICE
;
1836 call
->port
= htons(AFS_FS_PORT
);
1838 /* marshall the parameters */
1840 *bp
++ = htonl(FSSETLOCK
);
1841 *bp
++ = htonl(vnode
->fid
.vid
);
1842 *bp
++ = htonl(vnode
->fid
.vnode
);
1843 *bp
++ = htonl(vnode
->fid
.unique
);
1844 *bp
++ = htonl(type
);
1846 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
1850 * extend a lock on a file
1852 int afs_fs_extend_lock(struct afs_server
*server
,
1854 struct afs_vnode
*vnode
,
1855 const struct afs_wait_mode
*wait_mode
)
1857 struct afs_call
*call
;
1862 call
= afs_alloc_flat_call(&afs_RXFSExtendLock
, 4 * 4, 6 * 4);
1867 call
->reply
= vnode
;
1868 call
->service_id
= FS_SERVICE
;
1869 call
->port
= htons(AFS_FS_PORT
);
1871 /* marshall the parameters */
1873 *bp
++ = htonl(FSEXTENDLOCK
);
1874 *bp
++ = htonl(vnode
->fid
.vid
);
1875 *bp
++ = htonl(vnode
->fid
.vnode
);
1876 *bp
++ = htonl(vnode
->fid
.unique
);
1878 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);
1882 * release a lock on a file
1884 int afs_fs_release_lock(struct afs_server
*server
,
1886 struct afs_vnode
*vnode
,
1887 const struct afs_wait_mode
*wait_mode
)
1889 struct afs_call
*call
;
1894 call
= afs_alloc_flat_call(&afs_RXFSReleaseLock
, 4 * 4, 6 * 4);
1899 call
->reply
= vnode
;
1900 call
->service_id
= FS_SERVICE
;
1901 call
->port
= htons(AFS_FS_PORT
);
1903 /* marshall the parameters */
1905 *bp
++ = htonl(FSRELEASELOCK
);
1906 *bp
++ = htonl(vnode
->fid
.vid
);
1907 *bp
++ = htonl(vnode
->fid
.vnode
);
1908 *bp
++ = htonl(vnode
->fid
.unique
);
1910 return afs_make_call(&server
->addr
, call
, GFP_NOFS
, wait_mode
);