18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* AFS Cache Manager Service 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. 58c2ecf20Sopenharmony_ci * Written by David Howells (dhowells@redhat.com) 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/module.h> 98c2ecf20Sopenharmony_ci#include <linux/init.h> 108c2ecf20Sopenharmony_ci#include <linux/slab.h> 118c2ecf20Sopenharmony_ci#include <linux/sched.h> 128c2ecf20Sopenharmony_ci#include <linux/ip.h> 138c2ecf20Sopenharmony_ci#include "internal.h" 148c2ecf20Sopenharmony_ci#include "afs_cm.h" 158c2ecf20Sopenharmony_ci#include "protocol_yfs.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistatic int afs_deliver_cb_init_call_back_state(struct afs_call *); 188c2ecf20Sopenharmony_cistatic int afs_deliver_cb_init_call_back_state3(struct afs_call *); 198c2ecf20Sopenharmony_cistatic int afs_deliver_cb_probe(struct afs_call *); 208c2ecf20Sopenharmony_cistatic int afs_deliver_cb_callback(struct afs_call *); 218c2ecf20Sopenharmony_cistatic int afs_deliver_cb_probe_uuid(struct afs_call *); 228c2ecf20Sopenharmony_cistatic int afs_deliver_cb_tell_me_about_yourself(struct afs_call *); 238c2ecf20Sopenharmony_cistatic void afs_cm_destructor(struct afs_call *); 248c2ecf20Sopenharmony_cistatic void SRXAFSCB_CallBack(struct work_struct *); 258c2ecf20Sopenharmony_cistatic void SRXAFSCB_InitCallBackState(struct work_struct *); 268c2ecf20Sopenharmony_cistatic void SRXAFSCB_Probe(struct work_struct *); 278c2ecf20Sopenharmony_cistatic void SRXAFSCB_ProbeUuid(struct work_struct *); 288c2ecf20Sopenharmony_cistatic void SRXAFSCB_TellMeAboutYourself(struct work_struct *); 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistatic int afs_deliver_yfs_cb_callback(struct afs_call *); 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/* 338c2ecf20Sopenharmony_ci * CB.CallBack operation type 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_cistatic const struct afs_call_type afs_SRXCBCallBack = { 368c2ecf20Sopenharmony_ci .name = "CB.CallBack", 378c2ecf20Sopenharmony_ci .deliver = afs_deliver_cb_callback, 388c2ecf20Sopenharmony_ci .destructor = afs_cm_destructor, 398c2ecf20Sopenharmony_ci .work = SRXAFSCB_CallBack, 408c2ecf20Sopenharmony_ci}; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* 438c2ecf20Sopenharmony_ci * CB.InitCallBackState operation type 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_cistatic const struct afs_call_type afs_SRXCBInitCallBackState = { 468c2ecf20Sopenharmony_ci .name = "CB.InitCallBackState", 478c2ecf20Sopenharmony_ci .deliver = afs_deliver_cb_init_call_back_state, 488c2ecf20Sopenharmony_ci .destructor = afs_cm_destructor, 498c2ecf20Sopenharmony_ci .work = SRXAFSCB_InitCallBackState, 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* 538c2ecf20Sopenharmony_ci * CB.InitCallBackState3 operation type 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_cistatic const struct afs_call_type afs_SRXCBInitCallBackState3 = { 568c2ecf20Sopenharmony_ci .name = "CB.InitCallBackState3", 578c2ecf20Sopenharmony_ci .deliver = afs_deliver_cb_init_call_back_state3, 588c2ecf20Sopenharmony_ci .destructor = afs_cm_destructor, 598c2ecf20Sopenharmony_ci .work = SRXAFSCB_InitCallBackState, 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* 638c2ecf20Sopenharmony_ci * CB.Probe operation type 648c2ecf20Sopenharmony_ci */ 658c2ecf20Sopenharmony_cistatic const struct afs_call_type afs_SRXCBProbe = { 668c2ecf20Sopenharmony_ci .name = "CB.Probe", 678c2ecf20Sopenharmony_ci .deliver = afs_deliver_cb_probe, 688c2ecf20Sopenharmony_ci .destructor = afs_cm_destructor, 698c2ecf20Sopenharmony_ci .work = SRXAFSCB_Probe, 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* 738c2ecf20Sopenharmony_ci * CB.ProbeUuid operation type 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_cistatic const struct afs_call_type afs_SRXCBProbeUuid = { 768c2ecf20Sopenharmony_ci .name = "CB.ProbeUuid", 778c2ecf20Sopenharmony_ci .deliver = afs_deliver_cb_probe_uuid, 788c2ecf20Sopenharmony_ci .destructor = afs_cm_destructor, 798c2ecf20Sopenharmony_ci .work = SRXAFSCB_ProbeUuid, 808c2ecf20Sopenharmony_ci}; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* 838c2ecf20Sopenharmony_ci * CB.TellMeAboutYourself operation type 848c2ecf20Sopenharmony_ci */ 858c2ecf20Sopenharmony_cistatic const struct afs_call_type afs_SRXCBTellMeAboutYourself = { 868c2ecf20Sopenharmony_ci .name = "CB.TellMeAboutYourself", 878c2ecf20Sopenharmony_ci .deliver = afs_deliver_cb_tell_me_about_yourself, 888c2ecf20Sopenharmony_ci .destructor = afs_cm_destructor, 898c2ecf20Sopenharmony_ci .work = SRXAFSCB_TellMeAboutYourself, 908c2ecf20Sopenharmony_ci}; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* 938c2ecf20Sopenharmony_ci * YFS CB.CallBack operation type 948c2ecf20Sopenharmony_ci */ 958c2ecf20Sopenharmony_cistatic const struct afs_call_type afs_SRXYFSCB_CallBack = { 968c2ecf20Sopenharmony_ci .name = "YFSCB.CallBack", 978c2ecf20Sopenharmony_ci .deliver = afs_deliver_yfs_cb_callback, 988c2ecf20Sopenharmony_ci .destructor = afs_cm_destructor, 998c2ecf20Sopenharmony_ci .work = SRXAFSCB_CallBack, 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/* 1038c2ecf20Sopenharmony_ci * route an incoming cache manager call 1048c2ecf20Sopenharmony_ci * - return T if supported, F if not 1058c2ecf20Sopenharmony_ci */ 1068c2ecf20Sopenharmony_cibool afs_cm_incoming_call(struct afs_call *call) 1078c2ecf20Sopenharmony_ci{ 1088c2ecf20Sopenharmony_ci _enter("{%u, CB.OP %u}", call->service_id, call->operation_ID); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci switch (call->operation_ID) { 1118c2ecf20Sopenharmony_ci case CBCallBack: 1128c2ecf20Sopenharmony_ci call->type = &afs_SRXCBCallBack; 1138c2ecf20Sopenharmony_ci return true; 1148c2ecf20Sopenharmony_ci case CBInitCallBackState: 1158c2ecf20Sopenharmony_ci call->type = &afs_SRXCBInitCallBackState; 1168c2ecf20Sopenharmony_ci return true; 1178c2ecf20Sopenharmony_ci case CBInitCallBackState3: 1188c2ecf20Sopenharmony_ci call->type = &afs_SRXCBInitCallBackState3; 1198c2ecf20Sopenharmony_ci return true; 1208c2ecf20Sopenharmony_ci case CBProbe: 1218c2ecf20Sopenharmony_ci call->type = &afs_SRXCBProbe; 1228c2ecf20Sopenharmony_ci return true; 1238c2ecf20Sopenharmony_ci case CBProbeUuid: 1248c2ecf20Sopenharmony_ci call->type = &afs_SRXCBProbeUuid; 1258c2ecf20Sopenharmony_ci return true; 1268c2ecf20Sopenharmony_ci case CBTellMeAboutYourself: 1278c2ecf20Sopenharmony_ci call->type = &afs_SRXCBTellMeAboutYourself; 1288c2ecf20Sopenharmony_ci return true; 1298c2ecf20Sopenharmony_ci case YFSCBCallBack: 1308c2ecf20Sopenharmony_ci if (call->service_id != YFS_CM_SERVICE) 1318c2ecf20Sopenharmony_ci return false; 1328c2ecf20Sopenharmony_ci call->type = &afs_SRXYFSCB_CallBack; 1338c2ecf20Sopenharmony_ci return true; 1348c2ecf20Sopenharmony_ci default: 1358c2ecf20Sopenharmony_ci return false; 1368c2ecf20Sopenharmony_ci } 1378c2ecf20Sopenharmony_ci} 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci/* 1408c2ecf20Sopenharmony_ci * Find the server record by peer address and record a probe to the cache 1418c2ecf20Sopenharmony_ci * manager from a server. 1428c2ecf20Sopenharmony_ci */ 1438c2ecf20Sopenharmony_cistatic int afs_find_cm_server_by_peer(struct afs_call *call) 1448c2ecf20Sopenharmony_ci{ 1458c2ecf20Sopenharmony_ci struct sockaddr_rxrpc srx; 1468c2ecf20Sopenharmony_ci struct afs_server *server; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx); 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci server = afs_find_server(call->net, &srx); 1518c2ecf20Sopenharmony_ci if (!server) { 1528c2ecf20Sopenharmony_ci trace_afs_cm_no_server(call, &srx); 1538c2ecf20Sopenharmony_ci return 0; 1548c2ecf20Sopenharmony_ci } 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci call->server = server; 1578c2ecf20Sopenharmony_ci return 0; 1588c2ecf20Sopenharmony_ci} 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci/* 1618c2ecf20Sopenharmony_ci * Find the server record by server UUID and record a probe to the cache 1628c2ecf20Sopenharmony_ci * manager from a server. 1638c2ecf20Sopenharmony_ci */ 1648c2ecf20Sopenharmony_cistatic int afs_find_cm_server_by_uuid(struct afs_call *call, 1658c2ecf20Sopenharmony_ci struct afs_uuid *uuid) 1668c2ecf20Sopenharmony_ci{ 1678c2ecf20Sopenharmony_ci struct afs_server *server; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci rcu_read_lock(); 1708c2ecf20Sopenharmony_ci server = afs_find_server_by_uuid(call->net, call->request); 1718c2ecf20Sopenharmony_ci rcu_read_unlock(); 1728c2ecf20Sopenharmony_ci if (!server) { 1738c2ecf20Sopenharmony_ci trace_afs_cm_no_server_u(call, call->request); 1748c2ecf20Sopenharmony_ci return 0; 1758c2ecf20Sopenharmony_ci } 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci call->server = server; 1788c2ecf20Sopenharmony_ci return 0; 1798c2ecf20Sopenharmony_ci} 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci/* 1828c2ecf20Sopenharmony_ci * Clean up a cache manager call. 1838c2ecf20Sopenharmony_ci */ 1848c2ecf20Sopenharmony_cistatic void afs_cm_destructor(struct afs_call *call) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci kfree(call->buffer); 1878c2ecf20Sopenharmony_ci call->buffer = NULL; 1888c2ecf20Sopenharmony_ci} 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci/* 1918c2ecf20Sopenharmony_ci * Abort a service call from within an action function. 1928c2ecf20Sopenharmony_ci */ 1938c2ecf20Sopenharmony_cistatic void afs_abort_service_call(struct afs_call *call, u32 abort_code, int error, 1948c2ecf20Sopenharmony_ci const char *why) 1958c2ecf20Sopenharmony_ci{ 1968c2ecf20Sopenharmony_ci rxrpc_kernel_abort_call(call->net->socket, call->rxcall, 1978c2ecf20Sopenharmony_ci abort_code, error, why); 1988c2ecf20Sopenharmony_ci afs_set_call_complete(call, error, 0); 1998c2ecf20Sopenharmony_ci} 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci/* 2028c2ecf20Sopenharmony_ci * The server supplied a list of callbacks that it wanted to break. 2038c2ecf20Sopenharmony_ci */ 2048c2ecf20Sopenharmony_cistatic void SRXAFSCB_CallBack(struct work_struct *work) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci struct afs_call *call = container_of(work, struct afs_call, work); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci _enter(""); 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci /* We need to break the callbacks before sending the reply as the 2118c2ecf20Sopenharmony_ci * server holds up change visibility till it receives our reply so as 2128c2ecf20Sopenharmony_ci * to maintain cache coherency. 2138c2ecf20Sopenharmony_ci */ 2148c2ecf20Sopenharmony_ci if (call->server) { 2158c2ecf20Sopenharmony_ci trace_afs_server(call->server, 2168c2ecf20Sopenharmony_ci atomic_read(&call->server->ref), 2178c2ecf20Sopenharmony_ci atomic_read(&call->server->active), 2188c2ecf20Sopenharmony_ci afs_server_trace_callback); 2198c2ecf20Sopenharmony_ci afs_break_callbacks(call->server, call->count, call->request); 2208c2ecf20Sopenharmony_ci } 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci afs_send_empty_reply(call); 2238c2ecf20Sopenharmony_ci afs_put_call(call); 2248c2ecf20Sopenharmony_ci _leave(""); 2258c2ecf20Sopenharmony_ci} 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci/* 2288c2ecf20Sopenharmony_ci * deliver request data to a CB.CallBack call 2298c2ecf20Sopenharmony_ci */ 2308c2ecf20Sopenharmony_cistatic int afs_deliver_cb_callback(struct afs_call *call) 2318c2ecf20Sopenharmony_ci{ 2328c2ecf20Sopenharmony_ci struct afs_callback_break *cb; 2338c2ecf20Sopenharmony_ci __be32 *bp; 2348c2ecf20Sopenharmony_ci int ret, loop; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci _enter("{%u}", call->unmarshall); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci switch (call->unmarshall) { 2398c2ecf20Sopenharmony_ci case 0: 2408c2ecf20Sopenharmony_ci afs_extract_to_tmp(call); 2418c2ecf20Sopenharmony_ci call->unmarshall++; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci /* extract the FID array and its count in two steps */ 2448c2ecf20Sopenharmony_ci fallthrough; 2458c2ecf20Sopenharmony_ci case 1: 2468c2ecf20Sopenharmony_ci _debug("extract FID count"); 2478c2ecf20Sopenharmony_ci ret = afs_extract_data(call, true); 2488c2ecf20Sopenharmony_ci if (ret < 0) 2498c2ecf20Sopenharmony_ci return ret; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci call->count = ntohl(call->tmp); 2528c2ecf20Sopenharmony_ci _debug("FID count: %u", call->count); 2538c2ecf20Sopenharmony_ci if (call->count > AFSCBMAX) 2548c2ecf20Sopenharmony_ci return afs_protocol_error(call, afs_eproto_cb_fid_count); 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci call->buffer = kmalloc(array3_size(call->count, 3, 4), 2578c2ecf20Sopenharmony_ci GFP_KERNEL); 2588c2ecf20Sopenharmony_ci if (!call->buffer) 2598c2ecf20Sopenharmony_ci return -ENOMEM; 2608c2ecf20Sopenharmony_ci afs_extract_to_buf(call, call->count * 3 * 4); 2618c2ecf20Sopenharmony_ci call->unmarshall++; 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci fallthrough; 2648c2ecf20Sopenharmony_ci case 2: 2658c2ecf20Sopenharmony_ci _debug("extract FID array"); 2668c2ecf20Sopenharmony_ci ret = afs_extract_data(call, true); 2678c2ecf20Sopenharmony_ci if (ret < 0) 2688c2ecf20Sopenharmony_ci return ret; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci _debug("unmarshall FID array"); 2718c2ecf20Sopenharmony_ci call->request = kcalloc(call->count, 2728c2ecf20Sopenharmony_ci sizeof(struct afs_callback_break), 2738c2ecf20Sopenharmony_ci GFP_KERNEL); 2748c2ecf20Sopenharmony_ci if (!call->request) 2758c2ecf20Sopenharmony_ci return -ENOMEM; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci cb = call->request; 2788c2ecf20Sopenharmony_ci bp = call->buffer; 2798c2ecf20Sopenharmony_ci for (loop = call->count; loop > 0; loop--, cb++) { 2808c2ecf20Sopenharmony_ci cb->fid.vid = ntohl(*bp++); 2818c2ecf20Sopenharmony_ci cb->fid.vnode = ntohl(*bp++); 2828c2ecf20Sopenharmony_ci cb->fid.unique = ntohl(*bp++); 2838c2ecf20Sopenharmony_ci } 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci afs_extract_to_tmp(call); 2868c2ecf20Sopenharmony_ci call->unmarshall++; 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci /* extract the callback array and its count in two steps */ 2898c2ecf20Sopenharmony_ci fallthrough; 2908c2ecf20Sopenharmony_ci case 3: 2918c2ecf20Sopenharmony_ci _debug("extract CB count"); 2928c2ecf20Sopenharmony_ci ret = afs_extract_data(call, true); 2938c2ecf20Sopenharmony_ci if (ret < 0) 2948c2ecf20Sopenharmony_ci return ret; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci call->count2 = ntohl(call->tmp); 2978c2ecf20Sopenharmony_ci _debug("CB count: %u", call->count2); 2988c2ecf20Sopenharmony_ci if (call->count2 != call->count && call->count2 != 0) 2998c2ecf20Sopenharmony_ci return afs_protocol_error(call, afs_eproto_cb_count); 3008c2ecf20Sopenharmony_ci call->iter = &call->def_iter; 3018c2ecf20Sopenharmony_ci iov_iter_discard(&call->def_iter, READ, call->count2 * 3 * 4); 3028c2ecf20Sopenharmony_ci call->unmarshall++; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci fallthrough; 3058c2ecf20Sopenharmony_ci case 4: 3068c2ecf20Sopenharmony_ci _debug("extract discard %zu/%u", 3078c2ecf20Sopenharmony_ci iov_iter_count(call->iter), call->count2 * 3 * 4); 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci ret = afs_extract_data(call, false); 3108c2ecf20Sopenharmony_ci if (ret < 0) 3118c2ecf20Sopenharmony_ci return ret; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci call->unmarshall++; 3148c2ecf20Sopenharmony_ci case 5: 3158c2ecf20Sopenharmony_ci break; 3168c2ecf20Sopenharmony_ci } 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) 3198c2ecf20Sopenharmony_ci return afs_io_error(call, afs_io_error_cm_reply); 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci /* we'll need the file server record as that tells us which set of 3228c2ecf20Sopenharmony_ci * vnodes to operate upon */ 3238c2ecf20Sopenharmony_ci return afs_find_cm_server_by_peer(call); 3248c2ecf20Sopenharmony_ci} 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci/* 3278c2ecf20Sopenharmony_ci * allow the fileserver to request callback state (re-)initialisation 3288c2ecf20Sopenharmony_ci */ 3298c2ecf20Sopenharmony_cistatic void SRXAFSCB_InitCallBackState(struct work_struct *work) 3308c2ecf20Sopenharmony_ci{ 3318c2ecf20Sopenharmony_ci struct afs_call *call = container_of(work, struct afs_call, work); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci _enter("{%p}", call->server); 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci if (call->server) 3368c2ecf20Sopenharmony_ci afs_init_callback_state(call->server); 3378c2ecf20Sopenharmony_ci afs_send_empty_reply(call); 3388c2ecf20Sopenharmony_ci afs_put_call(call); 3398c2ecf20Sopenharmony_ci _leave(""); 3408c2ecf20Sopenharmony_ci} 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci/* 3438c2ecf20Sopenharmony_ci * deliver request data to a CB.InitCallBackState call 3448c2ecf20Sopenharmony_ci */ 3458c2ecf20Sopenharmony_cistatic int afs_deliver_cb_init_call_back_state(struct afs_call *call) 3468c2ecf20Sopenharmony_ci{ 3478c2ecf20Sopenharmony_ci int ret; 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci _enter(""); 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci afs_extract_discard(call, 0); 3528c2ecf20Sopenharmony_ci ret = afs_extract_data(call, false); 3538c2ecf20Sopenharmony_ci if (ret < 0) 3548c2ecf20Sopenharmony_ci return ret; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci /* we'll need the file server record as that tells us which set of 3578c2ecf20Sopenharmony_ci * vnodes to operate upon */ 3588c2ecf20Sopenharmony_ci return afs_find_cm_server_by_peer(call); 3598c2ecf20Sopenharmony_ci} 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci/* 3628c2ecf20Sopenharmony_ci * deliver request data to a CB.InitCallBackState3 call 3638c2ecf20Sopenharmony_ci */ 3648c2ecf20Sopenharmony_cistatic int afs_deliver_cb_init_call_back_state3(struct afs_call *call) 3658c2ecf20Sopenharmony_ci{ 3668c2ecf20Sopenharmony_ci struct afs_uuid *r; 3678c2ecf20Sopenharmony_ci unsigned loop; 3688c2ecf20Sopenharmony_ci __be32 *b; 3698c2ecf20Sopenharmony_ci int ret; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci _enter(""); 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci _enter("{%u}", call->unmarshall); 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci switch (call->unmarshall) { 3768c2ecf20Sopenharmony_ci case 0: 3778c2ecf20Sopenharmony_ci call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL); 3788c2ecf20Sopenharmony_ci if (!call->buffer) 3798c2ecf20Sopenharmony_ci return -ENOMEM; 3808c2ecf20Sopenharmony_ci afs_extract_to_buf(call, 11 * sizeof(__be32)); 3818c2ecf20Sopenharmony_ci call->unmarshall++; 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci fallthrough; 3848c2ecf20Sopenharmony_ci case 1: 3858c2ecf20Sopenharmony_ci _debug("extract UUID"); 3868c2ecf20Sopenharmony_ci ret = afs_extract_data(call, false); 3878c2ecf20Sopenharmony_ci switch (ret) { 3888c2ecf20Sopenharmony_ci case 0: break; 3898c2ecf20Sopenharmony_ci case -EAGAIN: return 0; 3908c2ecf20Sopenharmony_ci default: return ret; 3918c2ecf20Sopenharmony_ci } 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci _debug("unmarshall UUID"); 3948c2ecf20Sopenharmony_ci call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); 3958c2ecf20Sopenharmony_ci if (!call->request) 3968c2ecf20Sopenharmony_ci return -ENOMEM; 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci b = call->buffer; 3998c2ecf20Sopenharmony_ci r = call->request; 4008c2ecf20Sopenharmony_ci r->time_low = b[0]; 4018c2ecf20Sopenharmony_ci r->time_mid = htons(ntohl(b[1])); 4028c2ecf20Sopenharmony_ci r->time_hi_and_version = htons(ntohl(b[2])); 4038c2ecf20Sopenharmony_ci r->clock_seq_hi_and_reserved = ntohl(b[3]); 4048c2ecf20Sopenharmony_ci r->clock_seq_low = ntohl(b[4]); 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci for (loop = 0; loop < 6; loop++) 4078c2ecf20Sopenharmony_ci r->node[loop] = ntohl(b[loop + 5]); 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci call->unmarshall++; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci case 2: 4128c2ecf20Sopenharmony_ci break; 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) 4168c2ecf20Sopenharmony_ci return afs_io_error(call, afs_io_error_cm_reply); 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci /* we'll need the file server record as that tells us which set of 4198c2ecf20Sopenharmony_ci * vnodes to operate upon */ 4208c2ecf20Sopenharmony_ci return afs_find_cm_server_by_uuid(call, call->request); 4218c2ecf20Sopenharmony_ci} 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci/* 4248c2ecf20Sopenharmony_ci * allow the fileserver to see if the cache manager is still alive 4258c2ecf20Sopenharmony_ci */ 4268c2ecf20Sopenharmony_cistatic void SRXAFSCB_Probe(struct work_struct *work) 4278c2ecf20Sopenharmony_ci{ 4288c2ecf20Sopenharmony_ci struct afs_call *call = container_of(work, struct afs_call, work); 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci _enter(""); 4318c2ecf20Sopenharmony_ci afs_send_empty_reply(call); 4328c2ecf20Sopenharmony_ci afs_put_call(call); 4338c2ecf20Sopenharmony_ci _leave(""); 4348c2ecf20Sopenharmony_ci} 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci/* 4378c2ecf20Sopenharmony_ci * deliver request data to a CB.Probe call 4388c2ecf20Sopenharmony_ci */ 4398c2ecf20Sopenharmony_cistatic int afs_deliver_cb_probe(struct afs_call *call) 4408c2ecf20Sopenharmony_ci{ 4418c2ecf20Sopenharmony_ci int ret; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci _enter(""); 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci afs_extract_discard(call, 0); 4468c2ecf20Sopenharmony_ci ret = afs_extract_data(call, false); 4478c2ecf20Sopenharmony_ci if (ret < 0) 4488c2ecf20Sopenharmony_ci return ret; 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) 4518c2ecf20Sopenharmony_ci return afs_io_error(call, afs_io_error_cm_reply); 4528c2ecf20Sopenharmony_ci return afs_find_cm_server_by_peer(call); 4538c2ecf20Sopenharmony_ci} 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci/* 4568c2ecf20Sopenharmony_ci * Allow the fileserver to quickly find out if the cache manager has been 4578c2ecf20Sopenharmony_ci * rebooted. 4588c2ecf20Sopenharmony_ci */ 4598c2ecf20Sopenharmony_cistatic void SRXAFSCB_ProbeUuid(struct work_struct *work) 4608c2ecf20Sopenharmony_ci{ 4618c2ecf20Sopenharmony_ci struct afs_call *call = container_of(work, struct afs_call, work); 4628c2ecf20Sopenharmony_ci struct afs_uuid *r = call->request; 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci _enter(""); 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0) 4678c2ecf20Sopenharmony_ci afs_send_empty_reply(call); 4688c2ecf20Sopenharmony_ci else 4698c2ecf20Sopenharmony_ci afs_abort_service_call(call, 1, 1, "K-1"); 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci afs_put_call(call); 4728c2ecf20Sopenharmony_ci _leave(""); 4738c2ecf20Sopenharmony_ci} 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci/* 4768c2ecf20Sopenharmony_ci * deliver request data to a CB.ProbeUuid call 4778c2ecf20Sopenharmony_ci */ 4788c2ecf20Sopenharmony_cistatic int afs_deliver_cb_probe_uuid(struct afs_call *call) 4798c2ecf20Sopenharmony_ci{ 4808c2ecf20Sopenharmony_ci struct afs_uuid *r; 4818c2ecf20Sopenharmony_ci unsigned loop; 4828c2ecf20Sopenharmony_ci __be32 *b; 4838c2ecf20Sopenharmony_ci int ret; 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci _enter("{%u}", call->unmarshall); 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci switch (call->unmarshall) { 4888c2ecf20Sopenharmony_ci case 0: 4898c2ecf20Sopenharmony_ci call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL); 4908c2ecf20Sopenharmony_ci if (!call->buffer) 4918c2ecf20Sopenharmony_ci return -ENOMEM; 4928c2ecf20Sopenharmony_ci afs_extract_to_buf(call, 11 * sizeof(__be32)); 4938c2ecf20Sopenharmony_ci call->unmarshall++; 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci fallthrough; 4968c2ecf20Sopenharmony_ci case 1: 4978c2ecf20Sopenharmony_ci _debug("extract UUID"); 4988c2ecf20Sopenharmony_ci ret = afs_extract_data(call, false); 4998c2ecf20Sopenharmony_ci switch (ret) { 5008c2ecf20Sopenharmony_ci case 0: break; 5018c2ecf20Sopenharmony_ci case -EAGAIN: return 0; 5028c2ecf20Sopenharmony_ci default: return ret; 5038c2ecf20Sopenharmony_ci } 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci _debug("unmarshall UUID"); 5068c2ecf20Sopenharmony_ci call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); 5078c2ecf20Sopenharmony_ci if (!call->request) 5088c2ecf20Sopenharmony_ci return -ENOMEM; 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci b = call->buffer; 5118c2ecf20Sopenharmony_ci r = call->request; 5128c2ecf20Sopenharmony_ci r->time_low = b[0]; 5138c2ecf20Sopenharmony_ci r->time_mid = htons(ntohl(b[1])); 5148c2ecf20Sopenharmony_ci r->time_hi_and_version = htons(ntohl(b[2])); 5158c2ecf20Sopenharmony_ci r->clock_seq_hi_and_reserved = ntohl(b[3]); 5168c2ecf20Sopenharmony_ci r->clock_seq_low = ntohl(b[4]); 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci for (loop = 0; loop < 6; loop++) 5198c2ecf20Sopenharmony_ci r->node[loop] = ntohl(b[loop + 5]); 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci call->unmarshall++; 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci case 2: 5248c2ecf20Sopenharmony_ci break; 5258c2ecf20Sopenharmony_ci } 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) 5288c2ecf20Sopenharmony_ci return afs_io_error(call, afs_io_error_cm_reply); 5298c2ecf20Sopenharmony_ci return afs_find_cm_server_by_peer(call); 5308c2ecf20Sopenharmony_ci} 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci/* 5338c2ecf20Sopenharmony_ci * allow the fileserver to ask about the cache manager's capabilities 5348c2ecf20Sopenharmony_ci */ 5358c2ecf20Sopenharmony_cistatic void SRXAFSCB_TellMeAboutYourself(struct work_struct *work) 5368c2ecf20Sopenharmony_ci{ 5378c2ecf20Sopenharmony_ci struct afs_call *call = container_of(work, struct afs_call, work); 5388c2ecf20Sopenharmony_ci int loop; 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci struct { 5418c2ecf20Sopenharmony_ci struct /* InterfaceAddr */ { 5428c2ecf20Sopenharmony_ci __be32 nifs; 5438c2ecf20Sopenharmony_ci __be32 uuid[11]; 5448c2ecf20Sopenharmony_ci __be32 ifaddr[32]; 5458c2ecf20Sopenharmony_ci __be32 netmask[32]; 5468c2ecf20Sopenharmony_ci __be32 mtu[32]; 5478c2ecf20Sopenharmony_ci } ia; 5488c2ecf20Sopenharmony_ci struct /* Capabilities */ { 5498c2ecf20Sopenharmony_ci __be32 capcount; 5508c2ecf20Sopenharmony_ci __be32 caps[1]; 5518c2ecf20Sopenharmony_ci } cap; 5528c2ecf20Sopenharmony_ci } reply; 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci _enter(""); 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci memset(&reply, 0, sizeof(reply)); 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci reply.ia.uuid[0] = call->net->uuid.time_low; 5598c2ecf20Sopenharmony_ci reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid)); 5608c2ecf20Sopenharmony_ci reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version)); 5618c2ecf20Sopenharmony_ci reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved); 5628c2ecf20Sopenharmony_ci reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low); 5638c2ecf20Sopenharmony_ci for (loop = 0; loop < 6; loop++) 5648c2ecf20Sopenharmony_ci reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]); 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci reply.cap.capcount = htonl(1); 5678c2ecf20Sopenharmony_ci reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION); 5688c2ecf20Sopenharmony_ci afs_send_simple_reply(call, &reply, sizeof(reply)); 5698c2ecf20Sopenharmony_ci afs_put_call(call); 5708c2ecf20Sopenharmony_ci _leave(""); 5718c2ecf20Sopenharmony_ci} 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci/* 5748c2ecf20Sopenharmony_ci * deliver request data to a CB.TellMeAboutYourself call 5758c2ecf20Sopenharmony_ci */ 5768c2ecf20Sopenharmony_cistatic int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call) 5778c2ecf20Sopenharmony_ci{ 5788c2ecf20Sopenharmony_ci int ret; 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ci _enter(""); 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci afs_extract_discard(call, 0); 5838c2ecf20Sopenharmony_ci ret = afs_extract_data(call, false); 5848c2ecf20Sopenharmony_ci if (ret < 0) 5858c2ecf20Sopenharmony_ci return ret; 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) 5888c2ecf20Sopenharmony_ci return afs_io_error(call, afs_io_error_cm_reply); 5898c2ecf20Sopenharmony_ci return afs_find_cm_server_by_peer(call); 5908c2ecf20Sopenharmony_ci} 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci/* 5938c2ecf20Sopenharmony_ci * deliver request data to a YFS CB.CallBack call 5948c2ecf20Sopenharmony_ci */ 5958c2ecf20Sopenharmony_cistatic int afs_deliver_yfs_cb_callback(struct afs_call *call) 5968c2ecf20Sopenharmony_ci{ 5978c2ecf20Sopenharmony_ci struct afs_callback_break *cb; 5988c2ecf20Sopenharmony_ci struct yfs_xdr_YFSFid *bp; 5998c2ecf20Sopenharmony_ci size_t size; 6008c2ecf20Sopenharmony_ci int ret, loop; 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci _enter("{%u}", call->unmarshall); 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci switch (call->unmarshall) { 6058c2ecf20Sopenharmony_ci case 0: 6068c2ecf20Sopenharmony_ci afs_extract_to_tmp(call); 6078c2ecf20Sopenharmony_ci call->unmarshall++; 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_ci /* extract the FID array and its count in two steps */ 6108c2ecf20Sopenharmony_ci fallthrough; 6118c2ecf20Sopenharmony_ci case 1: 6128c2ecf20Sopenharmony_ci _debug("extract FID count"); 6138c2ecf20Sopenharmony_ci ret = afs_extract_data(call, true); 6148c2ecf20Sopenharmony_ci if (ret < 0) 6158c2ecf20Sopenharmony_ci return ret; 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci call->count = ntohl(call->tmp); 6188c2ecf20Sopenharmony_ci _debug("FID count: %u", call->count); 6198c2ecf20Sopenharmony_ci if (call->count > YFSCBMAX) 6208c2ecf20Sopenharmony_ci return afs_protocol_error(call, afs_eproto_cb_fid_count); 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid)); 6238c2ecf20Sopenharmony_ci call->buffer = kmalloc(size, GFP_KERNEL); 6248c2ecf20Sopenharmony_ci if (!call->buffer) 6258c2ecf20Sopenharmony_ci return -ENOMEM; 6268c2ecf20Sopenharmony_ci afs_extract_to_buf(call, size); 6278c2ecf20Sopenharmony_ci call->unmarshall++; 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci fallthrough; 6308c2ecf20Sopenharmony_ci case 2: 6318c2ecf20Sopenharmony_ci _debug("extract FID array"); 6328c2ecf20Sopenharmony_ci ret = afs_extract_data(call, false); 6338c2ecf20Sopenharmony_ci if (ret < 0) 6348c2ecf20Sopenharmony_ci return ret; 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci _debug("unmarshall FID array"); 6378c2ecf20Sopenharmony_ci call->request = kcalloc(call->count, 6388c2ecf20Sopenharmony_ci sizeof(struct afs_callback_break), 6398c2ecf20Sopenharmony_ci GFP_KERNEL); 6408c2ecf20Sopenharmony_ci if (!call->request) 6418c2ecf20Sopenharmony_ci return -ENOMEM; 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci cb = call->request; 6448c2ecf20Sopenharmony_ci bp = call->buffer; 6458c2ecf20Sopenharmony_ci for (loop = call->count; loop > 0; loop--, cb++) { 6468c2ecf20Sopenharmony_ci cb->fid.vid = xdr_to_u64(bp->volume); 6478c2ecf20Sopenharmony_ci cb->fid.vnode = xdr_to_u64(bp->vnode.lo); 6488c2ecf20Sopenharmony_ci cb->fid.vnode_hi = ntohl(bp->vnode.hi); 6498c2ecf20Sopenharmony_ci cb->fid.unique = ntohl(bp->vnode.unique); 6508c2ecf20Sopenharmony_ci bp++; 6518c2ecf20Sopenharmony_ci } 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci afs_extract_to_tmp(call); 6548c2ecf20Sopenharmony_ci call->unmarshall++; 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ci case 3: 6578c2ecf20Sopenharmony_ci break; 6588c2ecf20Sopenharmony_ci } 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) 6618c2ecf20Sopenharmony_ci return afs_io_error(call, afs_io_error_cm_reply); 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci /* We'll need the file server record as that tells us which set of 6648c2ecf20Sopenharmony_ci * vnodes to operate upon. 6658c2ecf20Sopenharmony_ci */ 6668c2ecf20Sopenharmony_ci return afs_find_cm_server_by_peer(call); 6678c2ecf20Sopenharmony_ci} 668