blob: d3c6bb22c5f4890081c2e5bf06af1d34fc63cc86 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howellsec268152007-04-26 15:49:28 -07002/* AFS Cache Manager Service
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8#include <linux/module.h>
9#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/sched.h>
David Howells08e0e7c2007-04-26 15:55:03 -070012#include <linux/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070014#include "afs_cm.h"
David Howells35dbfba2018-10-20 00:57:58 +010015#include "protocol_yfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
David Howellsd0016482016-08-30 20:42:14 +010017static int afs_deliver_cb_init_call_back_state(struct afs_call *);
18static int afs_deliver_cb_init_call_back_state3(struct afs_call *);
19static int afs_deliver_cb_probe(struct afs_call *);
20static int afs_deliver_cb_callback(struct afs_call *);
21static int afs_deliver_cb_probe_uuid(struct afs_call *);
22static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *);
David Howells08e0e7c2007-04-26 15:55:03 -070023static void afs_cm_destructor(struct afs_call *);
David Howells341f7412017-01-05 10:38:36 +000024static void SRXAFSCB_CallBack(struct work_struct *);
25static void SRXAFSCB_InitCallBackState(struct work_struct *);
26static void SRXAFSCB_Probe(struct work_struct *);
27static void SRXAFSCB_ProbeUuid(struct work_struct *);
28static void SRXAFSCB_TellMeAboutYourself(struct work_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
David Howells35dbfba2018-10-20 00:57:58 +010030static int afs_deliver_yfs_cb_callback(struct afs_call *);
31
David Howells8e8d7f12017-01-05 10:38:34 +000032#define CM_NAME(name) \
Andi Kleend2abfa862019-04-13 08:37:36 +010033 char afs_SRXCB##name##_name[] __tracepoint_string = \
David Howells8e8d7f12017-01-05 10:38:34 +000034 "CB." #name
35
David Howells08e0e7c2007-04-26 15:55:03 -070036/*
37 * CB.CallBack operation type
38 */
David Howells8e8d7f12017-01-05 10:38:34 +000039static CM_NAME(CallBack);
David Howells08e0e7c2007-04-26 15:55:03 -070040static const struct afs_call_type afs_SRXCBCallBack = {
David Howells8e8d7f12017-01-05 10:38:34 +000041 .name = afs_SRXCBCallBack_name,
David Howells08e0e7c2007-04-26 15:55:03 -070042 .deliver = afs_deliver_cb_callback,
David Howells08e0e7c2007-04-26 15:55:03 -070043 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000044 .work = SRXAFSCB_CallBack,
Linus Torvalds1da177e2005-04-16 15:20:36 -070045};
46
David Howells08e0e7c2007-04-26 15:55:03 -070047/*
48 * CB.InitCallBackState operation type
49 */
David Howells8e8d7f12017-01-05 10:38:34 +000050static CM_NAME(InitCallBackState);
David Howells08e0e7c2007-04-26 15:55:03 -070051static const struct afs_call_type afs_SRXCBInitCallBackState = {
David Howells8e8d7f12017-01-05 10:38:34 +000052 .name = afs_SRXCBInitCallBackState_name,
David Howells08e0e7c2007-04-26 15:55:03 -070053 .deliver = afs_deliver_cb_init_call_back_state,
David Howells08e0e7c2007-04-26 15:55:03 -070054 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000055 .work = SRXAFSCB_InitCallBackState,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57
David Howells08e0e7c2007-04-26 15:55:03 -070058/*
David Howellsc35eccb2007-04-26 15:58:49 -070059 * CB.InitCallBackState3 operation type
60 */
David Howells8e8d7f12017-01-05 10:38:34 +000061static CM_NAME(InitCallBackState3);
David Howellsc35eccb2007-04-26 15:58:49 -070062static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
David Howells8e8d7f12017-01-05 10:38:34 +000063 .name = afs_SRXCBInitCallBackState3_name,
David Howellsc35eccb2007-04-26 15:58:49 -070064 .deliver = afs_deliver_cb_init_call_back_state3,
David Howellsc35eccb2007-04-26 15:58:49 -070065 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000066 .work = SRXAFSCB_InitCallBackState,
David Howellsc35eccb2007-04-26 15:58:49 -070067};
68
69/*
David Howells08e0e7c2007-04-26 15:55:03 -070070 * CB.Probe operation type
71 */
David Howells8e8d7f12017-01-05 10:38:34 +000072static CM_NAME(Probe);
David Howells08e0e7c2007-04-26 15:55:03 -070073static const struct afs_call_type afs_SRXCBProbe = {
David Howells8e8d7f12017-01-05 10:38:34 +000074 .name = afs_SRXCBProbe_name,
David Howells08e0e7c2007-04-26 15:55:03 -070075 .deliver = afs_deliver_cb_probe,
David Howells08e0e7c2007-04-26 15:55:03 -070076 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000077 .work = SRXAFSCB_Probe,
David Howells08e0e7c2007-04-26 15:55:03 -070078};
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Linus Torvalds1da177e2005-04-16 15:20:36 -070080/*
David Howells9396d492008-04-29 01:03:22 -070081 * CB.ProbeUuid operation type
82 */
David Howells8e8d7f12017-01-05 10:38:34 +000083static CM_NAME(ProbeUuid);
David Howells9396d492008-04-29 01:03:22 -070084static const struct afs_call_type afs_SRXCBProbeUuid = {
David Howells8e8d7f12017-01-05 10:38:34 +000085 .name = afs_SRXCBProbeUuid_name,
David Howells9396d492008-04-29 01:03:22 -070086 .deliver = afs_deliver_cb_probe_uuid,
David Howells9396d492008-04-29 01:03:22 -070087 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000088 .work = SRXAFSCB_ProbeUuid,
David Howells9396d492008-04-29 01:03:22 -070089};
90
91/*
David Howells7c80bcc2008-04-29 01:03:21 -070092 * CB.TellMeAboutYourself operation type
David Howellsb908fe62007-04-26 15:58:17 -070093 */
David Howells8e8d7f12017-01-05 10:38:34 +000094static CM_NAME(TellMeAboutYourself);
David Howells7c80bcc2008-04-29 01:03:21 -070095static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
David Howells8e8d7f12017-01-05 10:38:34 +000096 .name = afs_SRXCBTellMeAboutYourself_name,
David Howells7c80bcc2008-04-29 01:03:21 -070097 .deliver = afs_deliver_cb_tell_me_about_yourself,
David Howellsb908fe62007-04-26 15:58:17 -070098 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000099 .work = SRXAFSCB_TellMeAboutYourself,
David Howellsb908fe62007-04-26 15:58:17 -0700100};
101
102/*
David Howells35dbfba2018-10-20 00:57:58 +0100103 * YFS CB.CallBack operation type
104 */
105static CM_NAME(YFS_CallBack);
106static const struct afs_call_type afs_SRXYFSCB_CallBack = {
107 .name = afs_SRXCBYFS_CallBack_name,
108 .deliver = afs_deliver_yfs_cb_callback,
109 .destructor = afs_cm_destructor,
110 .work = SRXAFSCB_CallBack,
111};
112
113/*
David Howells08e0e7c2007-04-26 15:55:03 -0700114 * route an incoming cache manager call
115 * - return T if supported, F if not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 */
David Howells08e0e7c2007-04-26 15:55:03 -0700117bool afs_cm_incoming_call(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
David Howells35dbfba2018-10-20 00:57:58 +0100119 _enter("{%u, CB.OP %u}", call->service_id, call->operation_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
David Howells50a2c952016-10-13 08:27:10 +0100121 switch (call->operation_ID) {
David Howells08e0e7c2007-04-26 15:55:03 -0700122 case CBCallBack:
123 call->type = &afs_SRXCBCallBack;
124 return true;
125 case CBInitCallBackState:
126 call->type = &afs_SRXCBInitCallBackState;
127 return true;
David Howellsc35eccb2007-04-26 15:58:49 -0700128 case CBInitCallBackState3:
129 call->type = &afs_SRXCBInitCallBackState3;
130 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700131 case CBProbe:
132 call->type = &afs_SRXCBProbe;
133 return true;
David Howellsf4b35262017-11-02 15:27:48 +0000134 case CBProbeUuid:
135 call->type = &afs_SRXCBProbeUuid;
136 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700137 case CBTellMeAboutYourself:
138 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700139 return true;
David Howells35dbfba2018-10-20 00:57:58 +0100140 case YFSCBCallBack:
141 if (call->service_id != YFS_CM_SERVICE)
142 return false;
143 call->type = &afs_SRXYFSCB_CallBack;
144 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700145 default:
146 return false;
147 }
David Howellsec268152007-04-26 15:49:28 -0700148}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150/*
David Howells3bf0fb62018-10-20 00:57:59 +0100151 * Find the server record by peer address and record a probe to the cache
152 * manager from a server.
153 */
154static int afs_find_cm_server_by_peer(struct afs_call *call)
155{
156 struct sockaddr_rxrpc srx;
157 struct afs_server *server;
158
159 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
160
161 server = afs_find_server(call->net, &srx);
162 if (!server) {
163 trace_afs_cm_no_server(call, &srx);
164 return 0;
165 }
166
David Howellsffba7182019-05-09 22:22:50 +0100167 call->server = server;
David Howells44746352020-05-27 15:52:02 +0100168 return 0;
David Howells3bf0fb62018-10-20 00:57:59 +0100169}
170
171/*
172 * Find the server record by server UUID and record a probe to the cache
173 * manager from a server.
174 */
175static int afs_find_cm_server_by_uuid(struct afs_call *call,
176 struct afs_uuid *uuid)
177{
178 struct afs_server *server;
179
180 rcu_read_lock();
181 server = afs_find_server_by_uuid(call->net, call->request);
182 rcu_read_unlock();
183 if (!server) {
184 trace_afs_cm_no_server_u(call, call->request);
185 return 0;
186 }
187
David Howellsffba7182019-05-09 22:22:50 +0100188 call->server = server;
David Howells44746352020-05-27 15:52:02 +0100189 return 0;
David Howells3bf0fb62018-10-20 00:57:59 +0100190}
191
192/*
David Howells428edad2018-05-12 00:28:58 +0100193 * Clean up a cache manager call.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 */
David Howells08e0e7c2007-04-26 15:55:03 -0700195static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
David Howells08e0e7c2007-04-26 15:55:03 -0700197 kfree(call->buffer);
198 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700199}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201/*
David Howellsdde9f092020-03-13 13:46:08 +0000202 * Abort a service call from within an action function.
203 */
204static void afs_abort_service_call(struct afs_call *call, u32 abort_code, int error,
205 const char *why)
206{
207 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
208 abort_code, error, why);
209 afs_set_call_complete(call, error, 0);
210}
211
212/*
David Howellsc435ee32017-11-02 15:27:49 +0000213 * The server supplied a list of callbacks that it wanted to break.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 */
David Howells08e0e7c2007-04-26 15:55:03 -0700215static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
David Howells08e0e7c2007-04-26 15:55:03 -0700217 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
David Howells08e0e7c2007-04-26 15:55:03 -0700219 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
David Howells428edad2018-05-12 00:28:58 +0100221 /* We need to break the callbacks before sending the reply as the
222 * server holds up change visibility till it receives our reply so as
223 * to maintain cache coherency.
224 */
David Howells45218192019-06-20 18:12:17 +0100225 if (call->server) {
David Howells977e5f82020-04-17 17:31:26 +0100226 trace_afs_server(call->server,
227 atomic_read(&call->server->ref),
228 atomic_read(&call->server->active),
David Howells45218192019-06-20 18:12:17 +0100229 afs_server_trace_callback);
David Howellsffba7182019-05-09 22:22:50 +0100230 afs_break_callbacks(call->server, call->count, call->request);
David Howells45218192019-06-20 18:12:17 +0100231 }
David Howells428edad2018-05-12 00:28:58 +0100232
233 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000234 afs_put_call(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700236}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238/*
David Howells08e0e7c2007-04-26 15:55:03 -0700239 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 */
David Howellsd0016482016-08-30 20:42:14 +0100241static int afs_deliver_cb_callback(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
David Howells5cf9dd52018-04-09 21:12:31 +0100243 struct afs_callback_break *cb;
David Howells08e0e7c2007-04-26 15:55:03 -0700244 __be32 *bp;
David Howells08e0e7c2007-04-26 15:55:03 -0700245 int ret, loop;
246
David Howellsd0016482016-08-30 20:42:14 +0100247 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700248
249 switch (call->unmarshall) {
250 case 0:
David Howells12bdcf32018-10-20 00:57:56 +0100251 afs_extract_to_tmp(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700252 call->unmarshall++;
253
254 /* extract the FID array and its count in two steps */
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500255 fallthrough;
David Howells08e0e7c2007-04-26 15:55:03 -0700256 case 1:
257 _debug("extract FID count");
David Howells12bdcf32018-10-20 00:57:56 +0100258 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100259 if (ret < 0)
260 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700261
262 call->count = ntohl(call->tmp);
263 _debug("FID count: %u", call->count);
264 if (call->count > AFSCBMAX)
David Howells7126ead2020-04-08 16:49:08 +0100265 return afs_protocol_error(call, afs_eproto_cb_fid_count);
David Howells08e0e7c2007-04-26 15:55:03 -0700266
Kees Cook6da2ec52018-06-12 13:55:00 -0700267 call->buffer = kmalloc(array3_size(call->count, 3, 4),
268 GFP_KERNEL);
David Howells08e0e7c2007-04-26 15:55:03 -0700269 if (!call->buffer)
270 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100271 afs_extract_to_buf(call, call->count * 3 * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700272 call->unmarshall++;
273
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500274 fallthrough;
David Howells08e0e7c2007-04-26 15:55:03 -0700275 case 2:
276 _debug("extract FID array");
David Howells12bdcf32018-10-20 00:57:56 +0100277 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100278 if (ret < 0)
279 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700280
281 _debug("unmarshall FID array");
282 call->request = kcalloc(call->count,
David Howells5cf9dd52018-04-09 21:12:31 +0100283 sizeof(struct afs_callback_break),
David Howells08e0e7c2007-04-26 15:55:03 -0700284 GFP_KERNEL);
285 if (!call->request)
286 return -ENOMEM;
287
288 cb = call->request;
289 bp = call->buffer;
290 for (loop = call->count; loop > 0; loop--, cb++) {
291 cb->fid.vid = ntohl(*bp++);
292 cb->fid.vnode = ntohl(*bp++);
293 cb->fid.unique = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700294 }
295
David Howells12bdcf32018-10-20 00:57:56 +0100296 afs_extract_to_tmp(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700297 call->unmarshall++;
298
299 /* extract the callback array and its count in two steps */
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500300 fallthrough;
David Howells08e0e7c2007-04-26 15:55:03 -0700301 case 3:
302 _debug("extract CB count");
David Howells12bdcf32018-10-20 00:57:56 +0100303 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100304 if (ret < 0)
305 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700306
Marc Dionnebcd89272017-03-16 16:27:44 +0000307 call->count2 = ntohl(call->tmp);
308 _debug("CB count: %u", call->count2);
309 if (call->count2 != call->count && call->count2 != 0)
David Howells7126ead2020-04-08 16:49:08 +0100310 return afs_protocol_error(call, afs_eproto_cb_count);
David Howellsfc276122019-11-21 09:12:17 +0000311 call->iter = &call->def_iter;
312 iov_iter_discard(&call->def_iter, READ, call->count2 * 3 * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700313 call->unmarshall++;
David Howells08e0e7c2007-04-26 15:55:03 -0700314
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500315 fallthrough;
David Howells08e0e7c2007-04-26 15:55:03 -0700316 case 4:
David Howells06aeb292018-10-20 00:57:58 +0100317 _debug("extract discard %zu/%u",
David Howellsfc276122019-11-21 09:12:17 +0000318 iov_iter_count(call->iter), call->count2 * 3 * 4);
David Howells06aeb292018-10-20 00:57:58 +0100319
David Howells12bdcf32018-10-20 00:57:56 +0100320 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100321 if (ret < 0)
322 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700323
David Howells08e0e7c2007-04-26 15:55:03 -0700324 call->unmarshall++;
Gustavo A. R. Silvab2db6c32021-05-25 15:40:22 +0100325 fallthrough;
326
David Howellsd0016482016-08-30 20:42:14 +0100327 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 break;
329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
David Howells98bf40c2017-11-02 15:27:53 +0000331 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100332 return afs_io_error(call, afs_io_error_cm_reply);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
David Howells08e0e7c2007-04-26 15:55:03 -0700334 /* we'll need the file server record as that tells us which set of
335 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100336 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700337}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339/*
David Howells08e0e7c2007-04-26 15:55:03 -0700340 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 */
David Howells08e0e7c2007-04-26 15:55:03 -0700342static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
David Howells08e0e7c2007-04-26 15:55:03 -0700344 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
David Howellsffba7182019-05-09 22:22:50 +0100346 _enter("{%p}", call->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
David Howellsffba7182019-05-09 22:22:50 +0100348 if (call->server)
349 afs_init_callback_state(call->server);
David Howells08e0e7c2007-04-26 15:55:03 -0700350 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000351 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700352 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700353}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355/*
David Howells08e0e7c2007-04-26 15:55:03 -0700356 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 */
David Howellsd0016482016-08-30 20:42:14 +0100358static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
David Howells372ee162016-08-03 14:11:40 +0100360 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
David Howellsd0016482016-08-30 20:42:14 +0100362 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
David Howells12bdcf32018-10-20 00:57:56 +0100364 afs_extract_discard(call, 0);
365 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100366 if (ret < 0)
367 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
David Howells08e0e7c2007-04-26 15:55:03 -0700369 /* we'll need the file server record as that tells us which set of
370 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100371 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700372}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374/*
David Howellsc35eccb2007-04-26 15:58:49 -0700375 * deliver request data to a CB.InitCallBackState3 call
376 */
David Howellsd0016482016-08-30 20:42:14 +0100377static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700378{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300379 struct afs_uuid *r;
David Howellsd0016482016-08-30 20:42:14 +0100380 unsigned loop;
381 __be32 *b;
382 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700383
David Howellsd0016482016-08-30 20:42:14 +0100384 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700385
David Howellsd0016482016-08-30 20:42:14 +0100386 _enter("{%u}", call->unmarshall);
387
388 switch (call->unmarshall) {
389 case 0:
Kees Cook6da2ec52018-06-12 13:55:00 -0700390 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100391 if (!call->buffer)
392 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100393 afs_extract_to_buf(call, 11 * sizeof(__be32));
David Howellsd0016482016-08-30 20:42:14 +0100394 call->unmarshall++;
395
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500396 fallthrough;
David Howellsd0016482016-08-30 20:42:14 +0100397 case 1:
398 _debug("extract UUID");
David Howells12bdcf32018-10-20 00:57:56 +0100399 ret = afs_extract_data(call, false);
David Howellsd0016482016-08-30 20:42:14 +0100400 switch (ret) {
401 case 0: break;
402 case -EAGAIN: return 0;
403 default: return ret;
404 }
405
406 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300407 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100408 if (!call->request)
409 return -ENOMEM;
410
411 b = call->buffer;
412 r = call->request;
David Howellsff548772017-02-10 16:34:07 +0000413 r->time_low = b[0];
414 r->time_mid = htons(ntohl(b[1]));
415 r->time_hi_and_version = htons(ntohl(b[2]));
David Howellsd0016482016-08-30 20:42:14 +0100416 r->clock_seq_hi_and_reserved = ntohl(b[3]);
417 r->clock_seq_low = ntohl(b[4]);
418
419 for (loop = 0; loop < 6; loop++)
420 r->node[loop] = ntohl(b[loop + 5]);
421
David Howellsd0016482016-08-30 20:42:14 +0100422 call->unmarshall++;
Gustavo A. R. Silvab2db6c32021-05-25 15:40:22 +0100423 fallthrough;
David Howellsd0016482016-08-30 20:42:14 +0100424
425 case 2:
426 break;
427 }
David Howellsc35eccb2007-04-26 15:58:49 -0700428
David Howells98bf40c2017-11-02 15:27:53 +0000429 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100430 return afs_io_error(call, afs_io_error_cm_reply);
David Howellsc35eccb2007-04-26 15:58:49 -0700431
432 /* we'll need the file server record as that tells us which set of
433 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100434 return afs_find_cm_server_by_uuid(call, call->request);
David Howellsc35eccb2007-04-26 15:58:49 -0700435}
436
437/*
David Howells08e0e7c2007-04-26 15:55:03 -0700438 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 */
David Howells08e0e7c2007-04-26 15:55:03 -0700440static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
David Howells08e0e7c2007-04-26 15:55:03 -0700442 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
David Howells08e0e7c2007-04-26 15:55:03 -0700444 _enter("");
445 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000446 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700447 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700448}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450/*
David Howells08e0e7c2007-04-26 15:55:03 -0700451 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 */
David Howellsd0016482016-08-30 20:42:14 +0100453static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
David Howells372ee162016-08-03 14:11:40 +0100455 int ret;
456
David Howellsd0016482016-08-30 20:42:14 +0100457 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
David Howells12bdcf32018-10-20 00:57:56 +0100459 afs_extract_discard(call, 0);
460 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100461 if (ret < 0)
462 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
David Howells98bf40c2017-11-02 15:27:53 +0000464 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100465 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100466 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700467}
David Howellsb908fe62007-04-26 15:58:17 -0700468
469/*
David Howells3120c172020-05-27 16:44:02 +0100470 * Allow the fileserver to quickly find out if the cache manager has been
471 * rebooted.
David Howells9396d492008-04-29 01:03:22 -0700472 */
473static void SRXAFSCB_ProbeUuid(struct work_struct *work)
474{
475 struct afs_call *call = container_of(work, struct afs_call, work);
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300476 struct afs_uuid *r = call->request;
David Howells9396d492008-04-29 01:03:22 -0700477
David Howells9396d492008-04-29 01:03:22 -0700478 _enter("");
479
David Howellsf044c882017-11-02 15:27:45 +0000480 if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
David Howells2067b2b2019-07-30 14:38:51 +0100481 afs_send_empty_reply(call);
David Howells9396d492008-04-29 01:03:22 -0700482 else
David Howellsdde9f092020-03-13 13:46:08 +0000483 afs_abort_service_call(call, 1, 1, "K-1");
David Howells9396d492008-04-29 01:03:22 -0700484
David Howells341f7412017-01-05 10:38:36 +0000485 afs_put_call(call);
David Howells9396d492008-04-29 01:03:22 -0700486 _leave("");
487}
488
489/*
490 * deliver request data to a CB.ProbeUuid call
491 */
David Howellsd0016482016-08-30 20:42:14 +0100492static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700493{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300494 struct afs_uuid *r;
David Howells9396d492008-04-29 01:03:22 -0700495 unsigned loop;
496 __be32 *b;
497 int ret;
498
David Howellsd0016482016-08-30 20:42:14 +0100499 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700500
501 switch (call->unmarshall) {
502 case 0:
Kees Cook6da2ec52018-06-12 13:55:00 -0700503 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700504 if (!call->buffer)
505 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100506 afs_extract_to_buf(call, 11 * sizeof(__be32));
David Howells9396d492008-04-29 01:03:22 -0700507 call->unmarshall++;
508
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500509 fallthrough;
David Howells9396d492008-04-29 01:03:22 -0700510 case 1:
511 _debug("extract UUID");
David Howells12bdcf32018-10-20 00:57:56 +0100512 ret = afs_extract_data(call, false);
David Howells9396d492008-04-29 01:03:22 -0700513 switch (ret) {
514 case 0: break;
515 case -EAGAIN: return 0;
516 default: return ret;
517 }
518
519 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300520 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700521 if (!call->request)
522 return -ENOMEM;
523
524 b = call->buffer;
525 r = call->request;
David Howellsfe342cf2018-04-09 21:12:31 +0100526 r->time_low = b[0];
527 r->time_mid = htons(ntohl(b[1]));
528 r->time_hi_and_version = htons(ntohl(b[2]));
David Howells9396d492008-04-29 01:03:22 -0700529 r->clock_seq_hi_and_reserved = ntohl(b[3]);
530 r->clock_seq_low = ntohl(b[4]);
531
532 for (loop = 0; loop < 6; loop++)
533 r->node[loop] = ntohl(b[loop + 5]);
534
David Howells9396d492008-04-29 01:03:22 -0700535 call->unmarshall++;
Gustavo A. R. Silvab2db6c32021-05-25 15:40:22 +0100536 fallthrough;
David Howells9396d492008-04-29 01:03:22 -0700537
538 case 2:
David Howells9396d492008-04-29 01:03:22 -0700539 break;
540 }
541
David Howells98bf40c2017-11-02 15:27:53 +0000542 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100543 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3120c172020-05-27 16:44:02 +0100544 return afs_find_cm_server_by_peer(call);
David Howells9396d492008-04-29 01:03:22 -0700545}
546
547/*
David Howellsb908fe62007-04-26 15:58:17 -0700548 * allow the fileserver to ask about the cache manager's capabilities
549 */
David Howells7c80bcc2008-04-29 01:03:21 -0700550static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700551{
David Howellsb908fe62007-04-26 15:58:17 -0700552 struct afs_call *call = container_of(work, struct afs_call, work);
Florian Westphal35ebfc22019-05-31 18:27:03 +0200553 int loop;
David Howellsb908fe62007-04-26 15:58:17 -0700554
555 struct {
556 struct /* InterfaceAddr */ {
557 __be32 nifs;
558 __be32 uuid[11];
559 __be32 ifaddr[32];
560 __be32 netmask[32];
561 __be32 mtu[32];
562 } ia;
563 struct /* Capabilities */ {
564 __be32 capcount;
565 __be32 caps[1];
566 } cap;
567 } reply;
568
569 _enter("");
570
David Howellsb908fe62007-04-26 15:58:17 -0700571 memset(&reply, 0, sizeof(reply));
David Howellsb908fe62007-04-26 15:58:17 -0700572
David Howellsf044c882017-11-02 15:27:45 +0000573 reply.ia.uuid[0] = call->net->uuid.time_low;
574 reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid));
575 reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version));
576 reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved);
577 reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low);
David Howellsb908fe62007-04-26 15:58:17 -0700578 for (loop = 0; loop < 6; loop++)
David Howellsf044c882017-11-02 15:27:45 +0000579 reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]);
David Howellsb908fe62007-04-26 15:58:17 -0700580
David Howellsb908fe62007-04-26 15:58:17 -0700581 reply.cap.capcount = htonl(1);
582 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
583 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000584 afs_put_call(call);
David Howellsb908fe62007-04-26 15:58:17 -0700585 _leave("");
586}
587
588/*
David Howells7c80bcc2008-04-29 01:03:21 -0700589 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700590 */
David Howellsd0016482016-08-30 20:42:14 +0100591static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700592{
David Howells372ee162016-08-03 14:11:40 +0100593 int ret;
594
David Howellsd0016482016-08-30 20:42:14 +0100595 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700596
David Howells12bdcf32018-10-20 00:57:56 +0100597 afs_extract_discard(call, 0);
598 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100599 if (ret < 0)
600 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700601
David Howells98bf40c2017-11-02 15:27:53 +0000602 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100603 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100604 return afs_find_cm_server_by_peer(call);
David Howellsb908fe62007-04-26 15:58:17 -0700605}
David Howells35dbfba2018-10-20 00:57:58 +0100606
607/*
608 * deliver request data to a YFS CB.CallBack call
609 */
610static int afs_deliver_yfs_cb_callback(struct afs_call *call)
611{
612 struct afs_callback_break *cb;
David Howells35dbfba2018-10-20 00:57:58 +0100613 struct yfs_xdr_YFSFid *bp;
614 size_t size;
615 int ret, loop;
616
617 _enter("{%u}", call->unmarshall);
618
619 switch (call->unmarshall) {
620 case 0:
621 afs_extract_to_tmp(call);
622 call->unmarshall++;
623
624 /* extract the FID array and its count in two steps */
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500625 fallthrough;
David Howells35dbfba2018-10-20 00:57:58 +0100626 case 1:
627 _debug("extract FID count");
628 ret = afs_extract_data(call, true);
629 if (ret < 0)
630 return ret;
631
632 call->count = ntohl(call->tmp);
633 _debug("FID count: %u", call->count);
634 if (call->count > YFSCBMAX)
David Howells7126ead2020-04-08 16:49:08 +0100635 return afs_protocol_error(call, afs_eproto_cb_fid_count);
David Howells35dbfba2018-10-20 00:57:58 +0100636
637 size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid));
638 call->buffer = kmalloc(size, GFP_KERNEL);
639 if (!call->buffer)
640 return -ENOMEM;
641 afs_extract_to_buf(call, size);
642 call->unmarshall++;
643
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500644 fallthrough;
David Howells35dbfba2018-10-20 00:57:58 +0100645 case 2:
646 _debug("extract FID array");
647 ret = afs_extract_data(call, false);
648 if (ret < 0)
649 return ret;
650
651 _debug("unmarshall FID array");
652 call->request = kcalloc(call->count,
653 sizeof(struct afs_callback_break),
654 GFP_KERNEL);
655 if (!call->request)
656 return -ENOMEM;
657
658 cb = call->request;
659 bp = call->buffer;
660 for (loop = call->count; loop > 0; loop--, cb++) {
661 cb->fid.vid = xdr_to_u64(bp->volume);
662 cb->fid.vnode = xdr_to_u64(bp->vnode.lo);
663 cb->fid.vnode_hi = ntohl(bp->vnode.hi);
664 cb->fid.unique = ntohl(bp->vnode.unique);
665 bp++;
666 }
667
668 afs_extract_to_tmp(call);
669 call->unmarshall++;
Gustavo A. R. Silvab2db6c32021-05-25 15:40:22 +0100670 fallthrough;
David Howells35dbfba2018-10-20 00:57:58 +0100671
672 case 3:
673 break;
674 }
675
676 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
677 return afs_io_error(call, afs_io_error_cm_reply);
678
679 /* We'll need the file server record as that tells us which set of
680 * vnodes to operate upon.
681 */
David Howells3bf0fb62018-10-20 00:57:59 +0100682 return afs_find_cm_server_by_peer(call);
David Howells35dbfba2018-10-20 00:57:58 +0100683}