13 #include <linux/slab.h>
14 #include <linux/sched.h>
35 static void xdr_decode_AFSFetchStatus(
const __be32 **_bp,
46 #define EXTRACT(DST) \
48 u32 x = ntohl(*bp++); \
57 data_version =
ntohl(*bp++);
70 data_version |= (
u64)
ntohl(*bp++) << 32;
76 if (size != status->
size) {
82 _debug(
"vnode time %lx, %lx",
105 vnode->
vfs_inode.i_version = data_version;
110 expected_version = *store_version;
112 if (expected_version != data_version) {
115 _debug(
"vnode modified %llx on {%x:%u}",
116 (
unsigned long long) data_version,
117 vnode->
fid.vid, vnode->
fid.vnode);
121 }
else if (store_version) {
129 static void xdr_decode_AFSCallBack(
const __be32 **_bp,
struct afs_vnode *vnode)
140 static void xdr_decode_AFSCallBack_raw(
const __be32 **_bp,
154 static void xdr_decode_AFSVolSync(
const __be32 **_bp,
171 static void xdr_encode_AFS_StoreStatus(
__be32 **_bp,
struct iattr *
attr)
209 static void xdr_decode_AFSFetchVolumeStatus(
const __be32 **_bp,
232 static int afs_deliver_fs_fetch_status(
struct afs_call *call,
249 xdr_decode_AFSFetchStatus(&bp, &vnode->
status, vnode,
NULL);
250 xdr_decode_AFSCallBack(&bp, vnode);
252 xdr_decode_AFSVolSync(&bp, call->
reply2);
262 .name =
"FS.FetchStatus",
263 .deliver = afs_deliver_fs_fetch_status,
281 key_serial(key), vnode->
fid.vid, vnode->
fid.vnode);
306 static int afs_deliver_fs_fetch_data(
struct afs_call *call,
307 struct sk_buff *skb,
bool last)
330 _debug(
"extract data length (MSW)");
348 _debug(
"extract data length");
366 if (call->
count > 0) {
393 xdr_decode_AFSFetchStatus(&bp, &vnode->
status, vnode,
NULL);
394 xdr_decode_AFSCallBack(&bp, vnode);
396 xdr_decode_AFSVolSync(&bp, call->
reply2);
427 .name =
"FS.FetchData",
428 .deliver = afs_deliver_fs_fetch_data,
434 .name =
"FS.FetchData64",
435 .deliver = afs_deliver_fs_fetch_data,
443 static int afs_fs_fetch_data64(
struct afs_server *server,
489 off_t offset,
size_t length,
497 return afs_fs_fetch_data64(server, key, vnode, offset, length,
520 bp[4] =
htonl(offset);
521 bp[5] =
htonl(length);
529 static int afs_deliver_fs_give_up_callbacks(
struct afs_call *call,
530 struct sk_buff *skb,
bool last)
542 static const struct afs_call_type afs_RXFSGiveUpCallBacks = {
543 .name =
"FS.GiveUpCallBacks",
544 .deliver = afs_deliver_fs_give_up_callbacks,
564 _enter(
"{%zu},", ncallbacks);
571 _debug(
"break %zu callbacks", ncallbacks);
574 12 + ncallbacks * 6 * 4, 0);
583 tp = bp + 2 + ncallbacks * 3;
585 *bp++ =
htonl(ncallbacks);
586 *tp++ =
htonl(ncallbacks);
589 for (loop = ncallbacks; loop > 0; loop--) {
614 static int afs_deliver_fs_create_vnode(
struct afs_call *call,
615 struct sk_buff *skb,
bool last)
631 xdr_decode_AFSFid(&bp, call->
reply2);
633 xdr_decode_AFSFetchStatus(&bp, &vnode->
status, vnode,
NULL);
634 xdr_decode_AFSCallBack_raw(&bp, call->
reply4);
645 .name =
"FS.CreateXXXX",
646 .deliver = afs_deliver_fs_create_vnode,
665 size_t namesz, reqsz, padsz;
671 padsz = (4 - (namesz & 3)) & 3;
672 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
675 (3 + 21 + 21 + 3 + 6) * 4);
693 *bp++ =
htonl(namesz);
695 bp = (
void *) bp + namesz;
698 bp = (
void *) bp + padsz;
713 static int afs_deliver_fs_remove(
struct afs_call *call,
714 struct sk_buff *skb,
bool last)
730 xdr_decode_AFSFetchStatus(&bp, &vnode->
status, vnode,
NULL);
741 .name =
"FS.RemoveXXXX",
742 .deliver = afs_deliver_fs_remove,
758 size_t namesz, reqsz, padsz;
764 padsz = (4 - (namesz & 3)) & 3;
765 reqsz = (5 * 4) + namesz + padsz;
782 *bp++ =
htonl(namesz);
784 bp = (
void *) bp + namesz;
787 bp = (
void *) bp + padsz;
796 static int afs_deliver_fs_link(
struct afs_call *call,
797 struct sk_buff *skb,
bool last)
813 xdr_decode_AFSFetchStatus(&bp, &vnode->
status, vnode,
NULL);
814 xdr_decode_AFSFetchStatus(&bp, &dvnode->
status, dvnode,
NULL);
826 .deliver = afs_deliver_fs_link,
842 size_t namesz, reqsz, padsz;
848 padsz = (4 - (namesz & 3)) & 3;
849 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
856 call->
reply = dvnode;
867 *bp++ =
htonl(namesz);
869 bp = (
void *) bp + namesz;
872 bp = (
void *) bp + padsz;
884 static int afs_deliver_fs_symlink(
struct afs_call *call,
885 struct sk_buff *skb,
bool last)
901 xdr_decode_AFSFid(&bp, call->
reply2);
903 xdr_decode_AFSFetchStatus(&bp, &vnode->
status, vnode,
NULL);
914 .name =
"FS.Symlink",
915 .deliver = afs_deliver_fs_symlink,
927 const char *contents,
933 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
939 padsz = (4 - (namesz & 3)) & 3;
941 c_namesz =
strlen(contents);
942 c_padsz = (4 - (c_namesz & 3)) & 3;
944 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
947 (3 + 21 + 21 + 6) * 4);
964 *bp++ =
htonl(namesz);
966 bp = (
void *) bp + namesz;
969 bp = (
void *) bp + padsz;
971 *bp++ =
htonl(c_namesz);
972 memcpy(bp, contents, c_namesz);
973 bp = (
void *) bp + c_namesz;
976 bp = (
void *) bp + c_padsz;
991 static int afs_deliver_fs_rename(
struct afs_call *call,
992 struct sk_buff *skb,
bool last)
1008 xdr_decode_AFSFetchStatus(&bp, &orig_dvnode->
status, orig_dvnode,
NULL);
1009 if (new_dvnode != orig_dvnode)
1010 xdr_decode_AFSFetchStatus(&bp, &new_dvnode->status, new_dvnode,
1022 .name =
"FS.Rename",
1023 .deliver = afs_deliver_fs_rename,
1034 const char *orig_name,
1036 const char *new_name,
1040 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
1045 o_namesz =
strlen(orig_name);
1046 o_padsz = (4 - (o_namesz & 3)) & 3;
1048 n_namesz =
strlen(new_name);
1049 n_padsz = (4 - (n_namesz & 3)) & 3;
1052 4 + o_namesz + o_padsz +
1054 4 + n_namesz + n_padsz;
1061 call->
reply = orig_dvnode;
1062 call->
reply2 = new_dvnode;
1069 *bp++ =
htonl(orig_dvnode->
fid.vid);
1070 *bp++ =
htonl(orig_dvnode->
fid.vnode);
1071 *bp++ =
htonl(orig_dvnode->
fid.unique);
1072 *bp++ =
htonl(o_namesz);
1073 memcpy(bp, orig_name, o_namesz);
1074 bp = (
void *) bp + o_namesz;
1077 bp = (
void *) bp + o_padsz;
1080 *bp++ =
htonl(new_dvnode->
fid.vid);
1081 *bp++ =
htonl(new_dvnode->
fid.vnode);
1082 *bp++ =
htonl(new_dvnode->
fid.unique);
1083 *bp++ =
htonl(n_namesz);
1084 memcpy(bp, new_name, n_namesz);
1085 bp = (
void *) bp + n_namesz;
1088 bp = (
void *) bp + n_padsz;
1097 static int afs_deliver_fs_store_data(
struct afs_call *call,
1098 struct sk_buff *skb,
bool last)
1112 _leave(
" = -EBADMSG [%u != %u]",
1119 xdr_decode_AFSFetchStatus(&bp, &vnode->
status, vnode,
1133 .name =
"FS.StoreData",
1134 .deliver = afs_deliver_fs_store_data,
1140 .name =
"FS.StoreData64",
1141 .deliver = afs_deliver_fs_store_data,
1149 static int afs_fs_store_data64(
struct afs_server *server,
1152 unsigned offset,
unsigned to,
1153 loff_t size, loff_t
pos, loff_t i_size,
1161 key_serial(wb->
key), vnode->
fid.vid, vnode->
fid.vnode);
1164 (4 + 6 + 3 * 2) * 4,
1171 call->
reply = vnode;
1196 *bp++ =
htonl(pos >> 32);
1198 *bp++ =
htonl(size >> 32);
1200 *bp++ =
htonl(i_size >> 32);
1211 unsigned offset,
unsigned to,
1220 key_serial(wb->
key), vnode->
fid.vid, vnode->
fid.vnode);
1224 size += (loff_t)(last - first) <<
PAGE_SHIFT;
1228 i_size = i_size_read(&vnode->
vfs_inode);
1229 if (pos + size > i_size)
1230 i_size = size +
pos;
1232 _debug(
"size %llx, at %llx, i_size %llx",
1233 (
unsigned long long) size, (
unsigned long long) pos,
1234 (
unsigned long long) i_size);
1236 if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
1237 return afs_fs_store_data64(server, wb, first, last, offset, to,
1238 size, pos, i_size, wait_mode);
1248 call->
reply = vnode;
1274 *bp++ =
htonl(size);
1275 *bp++ =
htonl(i_size);
1283 static int afs_deliver_fs_store_status(
struct afs_call *call,
1284 struct sk_buff *skb,
bool last)
1299 _leave(
" = -EBADMSG [%u != %u]",
1305 store_version =
NULL;
1310 xdr_decode_AFSFetchStatus(&bp, &vnode->
status, vnode, store_version);
1321 .name =
"FS.StoreStatus",
1322 .deliver = afs_deliver_fs_store_status,
1327 static const struct afs_call_type afs_RXFSStoreData_as_Status = {
1328 .name =
"FS.StoreData",
1329 .deliver = afs_deliver_fs_store_status,
1334 static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
1335 .name =
"FS.StoreData64",
1336 .deliver = afs_deliver_fs_store_status,
1345 static int afs_fs_setattr_size64(
struct afs_server *server,
struct key *key,
1353 key_serial(key), vnode->
fid.vid, vnode->
fid.vnode);
1358 (4 + 6 + 3 * 2) * 4,
1364 call->
reply = vnode;
1377 xdr_encode_AFS_StoreStatus(&bp, attr);
1393 static int afs_fs_setattr_size(
struct afs_server *server,
struct key *key,
1401 key_serial(key), vnode->
fid.vid, vnode->
fid.vnode);
1405 return afs_fs_setattr_size64(server, key, vnode, attr,
1415 call->
reply = vnode;
1428 xdr_encode_AFS_StoreStatus(&bp, attr);
1449 return afs_fs_setattr_size(server, key, vnode, attr,
1453 key_serial(key), vnode->
fid.vid, vnode->
fid.vnode);
1462 call->
reply = vnode;
1474 xdr_encode_AFS_StoreStatus(&bp, attr);
1482 static int afs_deliver_fs_get_volume_status(
struct afs_call *call,
1483 struct sk_buff *skb,
bool last)
1498 _debug(
"extract status");
1504 default:
return ret;
1508 xdr_decode_AFSFetchVolumeStatus(&bp, call->
reply2);
1518 default:
return ret;
1530 _debug(
"extract volname");
1531 if (call->
count > 0) {
1537 default:
return ret;
1543 _debug(
"volname '%s'", p);
1549 if ((call->
count & 3) == 0) {
1551 goto no_volname_padding;
1561 default:
return ret;
1574 default:
return ret;
1586 _debug(
"extract offline");
1587 if (call->
count > 0) {
1593 default:
return ret;
1599 _debug(
"offline '%s'", p);
1605 if ((call->
count & 3) == 0) {
1607 goto no_offline_padding;
1617 default:
return ret;
1630 default:
return ret;
1643 if (call->
count > 0) {
1649 default:
return ret;
1661 if ((call->
count & 3) == 0) {
1663 goto no_motd_padding;
1673 default:
return ret;
1697 static void afs_get_volume_status_call_destructor(
struct afs_call *call)
1707 static const struct afs_call_type afs_RXFSGetVolumeStatus = {
1708 .name =
"FS.GetVolumeStatus",
1709 .deliver = afs_deliver_fs_get_volume_status,
1711 .destructor = afs_get_volume_status_call_destructor,
1740 call->
reply = vnode;
1757 static int afs_deliver_fs_xxxx_lock(
struct afs_call *call,
1758 struct sk_buff *skb,
bool last)
1783 .name =
"FS.SetLock",
1784 .deliver = afs_deliver_fs_xxxx_lock,
1793 .name =
"FS.ExtendLock",
1794 .deliver = afs_deliver_fs_xxxx_lock,
1803 .name =
"FS.ReleaseLock",
1804 .deliver = afs_deliver_fs_xxxx_lock,
1828 call->
reply = vnode;
1838 *bp++ =
htonl(type);
1861 call->
reply = vnode;
1893 call->
reply = vnode;