blob: ed0fb34d77dd825c29009df4a336ba23a8cce370 [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 Howells3bf0fb62018-10-20 00:57:59 +0100121 call->epoch = rxrpc_kernel_get_epoch(call->net->socket, call->rxcall);
122
David Howells50a2c952016-10-13 08:27:10 +0100123 switch (call->operation_ID) {
David Howells08e0e7c2007-04-26 15:55:03 -0700124 case CBCallBack:
125 call->type = &afs_SRXCBCallBack;
126 return true;
127 case CBInitCallBackState:
128 call->type = &afs_SRXCBInitCallBackState;
129 return true;
David Howellsc35eccb2007-04-26 15:58:49 -0700130 case CBInitCallBackState3:
131 call->type = &afs_SRXCBInitCallBackState3;
132 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700133 case CBProbe:
134 call->type = &afs_SRXCBProbe;
135 return true;
David Howellsf4b35262017-11-02 15:27:48 +0000136 case CBProbeUuid:
137 call->type = &afs_SRXCBProbeUuid;
138 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700139 case CBTellMeAboutYourself:
140 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700141 return true;
David Howells35dbfba2018-10-20 00:57:58 +0100142 case YFSCBCallBack:
143 if (call->service_id != YFS_CM_SERVICE)
144 return false;
145 call->type = &afs_SRXYFSCB_CallBack;
146 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700147 default:
148 return false;
149 }
David Howellsec268152007-04-26 15:49:28 -0700150}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/*
David Howells3bf0fb62018-10-20 00:57:59 +0100153 * Record a probe to the cache manager from a server.
154 */
155static int afs_record_cm_probe(struct afs_call *call, struct afs_server *server)
156{
157 _enter("");
158
159 if (test_bit(AFS_SERVER_FL_HAVE_EPOCH, &server->flags) &&
David Howellsf6cbb362020-04-24 15:10:00 +0100160 !afs_is_probing_server(server)) {
David Howells3bf0fb62018-10-20 00:57:59 +0100161 if (server->cm_epoch == call->epoch)
162 return 0;
163
164 if (!server->probe.said_rebooted) {
165 pr_notice("kAFS: FS rebooted %pU\n", &server->uuid);
166 server->probe.said_rebooted = true;
167 }
168 }
169
170 spin_lock(&server->probe_lock);
171
David Howells69cf3972020-04-24 11:21:14 +0100172 if (!test_and_set_bit(AFS_SERVER_FL_HAVE_EPOCH, &server->flags)) {
David Howells3bf0fb62018-10-20 00:57:59 +0100173 server->cm_epoch = call->epoch;
174 server->probe.cm_epoch = call->epoch;
175 goto out;
176 }
177
178 if (server->probe.cm_probed &&
179 call->epoch != server->probe.cm_epoch &&
180 !server->probe.said_inconsistent) {
181 pr_notice("kAFS: FS endpoints inconsistent %pU\n",
182 &server->uuid);
183 server->probe.said_inconsistent = true;
184 }
185
186 if (!server->probe.cm_probed || call->epoch == server->cm_epoch)
187 server->probe.cm_epoch = server->cm_epoch;
188
189out:
190 server->probe.cm_probed = true;
191 spin_unlock(&server->probe_lock);
192 return 0;
193}
194
195/*
196 * Find the server record by peer address and record a probe to the cache
197 * manager from a server.
198 */
199static int afs_find_cm_server_by_peer(struct afs_call *call)
200{
201 struct sockaddr_rxrpc srx;
202 struct afs_server *server;
203
204 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
205
206 server = afs_find_server(call->net, &srx);
207 if (!server) {
208 trace_afs_cm_no_server(call, &srx);
209 return 0;
210 }
211
David Howellsffba7182019-05-09 22:22:50 +0100212 call->server = server;
David Howells3bf0fb62018-10-20 00:57:59 +0100213 return afs_record_cm_probe(call, server);
214}
215
216/*
217 * Find the server record by server UUID and record a probe to the cache
218 * manager from a server.
219 */
220static int afs_find_cm_server_by_uuid(struct afs_call *call,
221 struct afs_uuid *uuid)
222{
223 struct afs_server *server;
224
225 rcu_read_lock();
226 server = afs_find_server_by_uuid(call->net, call->request);
227 rcu_read_unlock();
228 if (!server) {
229 trace_afs_cm_no_server_u(call, call->request);
230 return 0;
231 }
232
David Howellsffba7182019-05-09 22:22:50 +0100233 call->server = server;
David Howells3bf0fb62018-10-20 00:57:59 +0100234 return afs_record_cm_probe(call, server);
235}
236
237/*
David Howells428edad2018-05-12 00:28:58 +0100238 * Clean up a cache manager call.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 */
David Howells08e0e7c2007-04-26 15:55:03 -0700240static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
David Howells08e0e7c2007-04-26 15:55:03 -0700242 kfree(call->buffer);
243 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700244}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246/*
David Howellsdde9f092020-03-13 13:46:08 +0000247 * Abort a service call from within an action function.
248 */
249static void afs_abort_service_call(struct afs_call *call, u32 abort_code, int error,
250 const char *why)
251{
252 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
253 abort_code, error, why);
254 afs_set_call_complete(call, error, 0);
255}
256
257/*
David Howellsc435ee32017-11-02 15:27:49 +0000258 * The server supplied a list of callbacks that it wanted to break.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 */
David Howells08e0e7c2007-04-26 15:55:03 -0700260static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
David Howells08e0e7c2007-04-26 15:55:03 -0700262 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
David Howells08e0e7c2007-04-26 15:55:03 -0700264 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
David Howells428edad2018-05-12 00:28:58 +0100266 /* We need to break the callbacks before sending the reply as the
267 * server holds up change visibility till it receives our reply so as
268 * to maintain cache coherency.
269 */
David Howells45218192019-06-20 18:12:17 +0100270 if (call->server) {
David Howells977e5f82020-04-17 17:31:26 +0100271 trace_afs_server(call->server,
272 atomic_read(&call->server->ref),
273 atomic_read(&call->server->active),
David Howells45218192019-06-20 18:12:17 +0100274 afs_server_trace_callback);
David Howellsffba7182019-05-09 22:22:50 +0100275 afs_break_callbacks(call->server, call->count, call->request);
David Howells45218192019-06-20 18:12:17 +0100276 }
David Howells428edad2018-05-12 00:28:58 +0100277
278 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000279 afs_put_call(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700281}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283/*
David Howells08e0e7c2007-04-26 15:55:03 -0700284 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 */
David Howellsd0016482016-08-30 20:42:14 +0100286static int afs_deliver_cb_callback(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
David Howells5cf9dd52018-04-09 21:12:31 +0100288 struct afs_callback_break *cb;
David Howells08e0e7c2007-04-26 15:55:03 -0700289 __be32 *bp;
David Howells08e0e7c2007-04-26 15:55:03 -0700290 int ret, loop;
291
David Howellsd0016482016-08-30 20:42:14 +0100292 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700293
294 switch (call->unmarshall) {
295 case 0:
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 FID array and its count in two steps */
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600300 /* fall through */
David Howells08e0e7c2007-04-26 15:55:03 -0700301 case 1:
302 _debug("extract FID 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
307 call->count = ntohl(call->tmp);
308 _debug("FID count: %u", call->count);
309 if (call->count > AFSCBMAX)
David Howells7126ead2020-04-08 16:49:08 +0100310 return afs_protocol_error(call, afs_eproto_cb_fid_count);
David Howells08e0e7c2007-04-26 15:55:03 -0700311
Kees Cook6da2ec52018-06-12 13:55:00 -0700312 call->buffer = kmalloc(array3_size(call->count, 3, 4),
313 GFP_KERNEL);
David Howells08e0e7c2007-04-26 15:55:03 -0700314 if (!call->buffer)
315 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100316 afs_extract_to_buf(call, call->count * 3 * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700317 call->unmarshall++;
318
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600319 /* Fall through */
David Howells08e0e7c2007-04-26 15:55:03 -0700320 case 2:
321 _debug("extract FID array");
David Howells12bdcf32018-10-20 00:57:56 +0100322 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100323 if (ret < 0)
324 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700325
326 _debug("unmarshall FID array");
327 call->request = kcalloc(call->count,
David Howells5cf9dd52018-04-09 21:12:31 +0100328 sizeof(struct afs_callback_break),
David Howells08e0e7c2007-04-26 15:55:03 -0700329 GFP_KERNEL);
330 if (!call->request)
331 return -ENOMEM;
332
333 cb = call->request;
334 bp = call->buffer;
335 for (loop = call->count; loop > 0; loop--, cb++) {
336 cb->fid.vid = ntohl(*bp++);
337 cb->fid.vnode = ntohl(*bp++);
338 cb->fid.unique = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700339 }
340
David Howells12bdcf32018-10-20 00:57:56 +0100341 afs_extract_to_tmp(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700342 call->unmarshall++;
343
344 /* extract the callback array and its count in two steps */
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600345 /* fall through */
David Howells08e0e7c2007-04-26 15:55:03 -0700346 case 3:
347 _debug("extract CB count");
David Howells12bdcf32018-10-20 00:57:56 +0100348 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100349 if (ret < 0)
350 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700351
Marc Dionnebcd89272017-03-16 16:27:44 +0000352 call->count2 = ntohl(call->tmp);
353 _debug("CB count: %u", call->count2);
354 if (call->count2 != call->count && call->count2 != 0)
David Howells7126ead2020-04-08 16:49:08 +0100355 return afs_protocol_error(call, afs_eproto_cb_count);
David Howellsfc276122019-11-21 09:12:17 +0000356 call->iter = &call->def_iter;
357 iov_iter_discard(&call->def_iter, READ, call->count2 * 3 * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700358 call->unmarshall++;
David Howells08e0e7c2007-04-26 15:55:03 -0700359
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600360 /* Fall through */
David Howells08e0e7c2007-04-26 15:55:03 -0700361 case 4:
David Howells06aeb292018-10-20 00:57:58 +0100362 _debug("extract discard %zu/%u",
David Howellsfc276122019-11-21 09:12:17 +0000363 iov_iter_count(call->iter), call->count2 * 3 * 4);
David Howells06aeb292018-10-20 00:57:58 +0100364
David Howells12bdcf32018-10-20 00:57:56 +0100365 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100366 if (ret < 0)
367 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700368
David Howells08e0e7c2007-04-26 15:55:03 -0700369 call->unmarshall++;
David Howellsd0016482016-08-30 20:42:14 +0100370 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 break;
372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
David Howells98bf40c2017-11-02 15:27:53 +0000374 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100375 return afs_io_error(call, afs_io_error_cm_reply);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
David Howells08e0e7c2007-04-26 15:55:03 -0700377 /* we'll need the file server record as that tells us which set of
378 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100379 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700380}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382/*
David Howells08e0e7c2007-04-26 15:55:03 -0700383 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 */
David Howells08e0e7c2007-04-26 15:55:03 -0700385static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
David Howells08e0e7c2007-04-26 15:55:03 -0700387 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
David Howellsffba7182019-05-09 22:22:50 +0100389 _enter("{%p}", call->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
David Howellsffba7182019-05-09 22:22:50 +0100391 if (call->server)
392 afs_init_callback_state(call->server);
David Howells08e0e7c2007-04-26 15:55:03 -0700393 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000394 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700395 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700396}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398/*
David Howells08e0e7c2007-04-26 15:55:03 -0700399 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 */
David Howellsd0016482016-08-30 20:42:14 +0100401static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
David Howells372ee162016-08-03 14:11:40 +0100403 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
David Howellsd0016482016-08-30 20:42:14 +0100405 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
David Howells12bdcf32018-10-20 00:57:56 +0100407 afs_extract_discard(call, 0);
408 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100409 if (ret < 0)
410 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
David Howells08e0e7c2007-04-26 15:55:03 -0700412 /* we'll need the file server record as that tells us which set of
413 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100414 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700415}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417/*
David Howellsc35eccb2007-04-26 15:58:49 -0700418 * deliver request data to a CB.InitCallBackState3 call
419 */
David Howellsd0016482016-08-30 20:42:14 +0100420static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700421{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300422 struct afs_uuid *r;
David Howellsd0016482016-08-30 20:42:14 +0100423 unsigned loop;
424 __be32 *b;
425 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700426
David Howellsd0016482016-08-30 20:42:14 +0100427 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700428
David Howellsd0016482016-08-30 20:42:14 +0100429 _enter("{%u}", call->unmarshall);
430
431 switch (call->unmarshall) {
432 case 0:
Kees Cook6da2ec52018-06-12 13:55:00 -0700433 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100434 if (!call->buffer)
435 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100436 afs_extract_to_buf(call, 11 * sizeof(__be32));
David Howellsd0016482016-08-30 20:42:14 +0100437 call->unmarshall++;
438
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600439 /* Fall through */
David Howellsd0016482016-08-30 20:42:14 +0100440 case 1:
441 _debug("extract UUID");
David Howells12bdcf32018-10-20 00:57:56 +0100442 ret = afs_extract_data(call, false);
David Howellsd0016482016-08-30 20:42:14 +0100443 switch (ret) {
444 case 0: break;
445 case -EAGAIN: return 0;
446 default: return ret;
447 }
448
449 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300450 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100451 if (!call->request)
452 return -ENOMEM;
453
454 b = call->buffer;
455 r = call->request;
David Howellsff548772017-02-10 16:34:07 +0000456 r->time_low = b[0];
457 r->time_mid = htons(ntohl(b[1]));
458 r->time_hi_and_version = htons(ntohl(b[2]));
David Howellsd0016482016-08-30 20:42:14 +0100459 r->clock_seq_hi_and_reserved = ntohl(b[3]);
460 r->clock_seq_low = ntohl(b[4]);
461
462 for (loop = 0; loop < 6; loop++)
463 r->node[loop] = ntohl(b[loop + 5]);
464
David Howellsd0016482016-08-30 20:42:14 +0100465 call->unmarshall++;
466
467 case 2:
468 break;
469 }
David Howellsc35eccb2007-04-26 15:58:49 -0700470
David Howells98bf40c2017-11-02 15:27:53 +0000471 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100472 return afs_io_error(call, afs_io_error_cm_reply);
David Howellsc35eccb2007-04-26 15:58:49 -0700473
474 /* we'll need the file server record as that tells us which set of
475 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100476 return afs_find_cm_server_by_uuid(call, call->request);
David Howellsc35eccb2007-04-26 15:58:49 -0700477}
478
479/*
David Howells08e0e7c2007-04-26 15:55:03 -0700480 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 */
David Howells08e0e7c2007-04-26 15:55:03 -0700482static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
David Howells08e0e7c2007-04-26 15:55:03 -0700484 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
David Howells08e0e7c2007-04-26 15:55:03 -0700486 _enter("");
487 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000488 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700489 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700490}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492/*
David Howells08e0e7c2007-04-26 15:55:03 -0700493 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 */
David Howellsd0016482016-08-30 20:42:14 +0100495static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
David Howells372ee162016-08-03 14:11:40 +0100497 int ret;
498
David Howellsd0016482016-08-30 20:42:14 +0100499 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
David Howells12bdcf32018-10-20 00:57:56 +0100501 afs_extract_discard(call, 0);
502 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100503 if (ret < 0)
504 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
David Howells98bf40c2017-11-02 15:27:53 +0000506 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100507 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100508 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700509}
David Howellsb908fe62007-04-26 15:58:17 -0700510
511/*
David Howells9396d492008-04-29 01:03:22 -0700512 * allow the fileserver to quickly find out if the fileserver has been rebooted
513 */
514static void SRXAFSCB_ProbeUuid(struct work_struct *work)
515{
516 struct afs_call *call = container_of(work, struct afs_call, work);
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300517 struct afs_uuid *r = call->request;
David Howells9396d492008-04-29 01:03:22 -0700518
David Howells9396d492008-04-29 01:03:22 -0700519 _enter("");
520
David Howellsf044c882017-11-02 15:27:45 +0000521 if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
David Howells2067b2b2019-07-30 14:38:51 +0100522 afs_send_empty_reply(call);
David Howells9396d492008-04-29 01:03:22 -0700523 else
David Howellsdde9f092020-03-13 13:46:08 +0000524 afs_abort_service_call(call, 1, 1, "K-1");
David Howells9396d492008-04-29 01:03:22 -0700525
David Howells341f7412017-01-05 10:38:36 +0000526 afs_put_call(call);
David Howells9396d492008-04-29 01:03:22 -0700527 _leave("");
528}
529
530/*
531 * deliver request data to a CB.ProbeUuid call
532 */
David Howellsd0016482016-08-30 20:42:14 +0100533static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700534{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300535 struct afs_uuid *r;
David Howells9396d492008-04-29 01:03:22 -0700536 unsigned loop;
537 __be32 *b;
538 int ret;
539
David Howellsd0016482016-08-30 20:42:14 +0100540 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700541
542 switch (call->unmarshall) {
543 case 0:
Kees Cook6da2ec52018-06-12 13:55:00 -0700544 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700545 if (!call->buffer)
546 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100547 afs_extract_to_buf(call, 11 * sizeof(__be32));
David Howells9396d492008-04-29 01:03:22 -0700548 call->unmarshall++;
549
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600550 /* Fall through */
David Howells9396d492008-04-29 01:03:22 -0700551 case 1:
552 _debug("extract UUID");
David Howells12bdcf32018-10-20 00:57:56 +0100553 ret = afs_extract_data(call, false);
David Howells9396d492008-04-29 01:03:22 -0700554 switch (ret) {
555 case 0: break;
556 case -EAGAIN: return 0;
557 default: return ret;
558 }
559
560 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300561 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700562 if (!call->request)
563 return -ENOMEM;
564
565 b = call->buffer;
566 r = call->request;
David Howellsfe342cf2018-04-09 21:12:31 +0100567 r->time_low = b[0];
568 r->time_mid = htons(ntohl(b[1]));
569 r->time_hi_and_version = htons(ntohl(b[2]));
David Howells9396d492008-04-29 01:03:22 -0700570 r->clock_seq_hi_and_reserved = ntohl(b[3]);
571 r->clock_seq_low = ntohl(b[4]);
572
573 for (loop = 0; loop < 6; loop++)
574 r->node[loop] = ntohl(b[loop + 5]);
575
David Howells9396d492008-04-29 01:03:22 -0700576 call->unmarshall++;
577
578 case 2:
David Howells9396d492008-04-29 01:03:22 -0700579 break;
580 }
581
David Howells98bf40c2017-11-02 15:27:53 +0000582 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100583 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100584 return afs_find_cm_server_by_uuid(call, call->request);
David Howells9396d492008-04-29 01:03:22 -0700585}
586
587/*
David Howellsb908fe62007-04-26 15:58:17 -0700588 * allow the fileserver to ask about the cache manager's capabilities
589 */
David Howells7c80bcc2008-04-29 01:03:21 -0700590static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700591{
David Howellsb908fe62007-04-26 15:58:17 -0700592 struct afs_call *call = container_of(work, struct afs_call, work);
Florian Westphal35ebfc22019-05-31 18:27:03 +0200593 int loop;
David Howellsb908fe62007-04-26 15:58:17 -0700594
595 struct {
596 struct /* InterfaceAddr */ {
597 __be32 nifs;
598 __be32 uuid[11];
599 __be32 ifaddr[32];
600 __be32 netmask[32];
601 __be32 mtu[32];
602 } ia;
603 struct /* Capabilities */ {
604 __be32 capcount;
605 __be32 caps[1];
606 } cap;
607 } reply;
608
609 _enter("");
610
David Howellsb908fe62007-04-26 15:58:17 -0700611 memset(&reply, 0, sizeof(reply));
David Howellsb908fe62007-04-26 15:58:17 -0700612
David Howellsf044c882017-11-02 15:27:45 +0000613 reply.ia.uuid[0] = call->net->uuid.time_low;
614 reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid));
615 reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version));
616 reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved);
617 reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low);
David Howellsb908fe62007-04-26 15:58:17 -0700618 for (loop = 0; loop < 6; loop++)
David Howellsf044c882017-11-02 15:27:45 +0000619 reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]);
David Howellsb908fe62007-04-26 15:58:17 -0700620
David Howellsb908fe62007-04-26 15:58:17 -0700621 reply.cap.capcount = htonl(1);
622 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
623 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000624 afs_put_call(call);
David Howellsb908fe62007-04-26 15:58:17 -0700625 _leave("");
626}
627
628/*
David Howells7c80bcc2008-04-29 01:03:21 -0700629 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700630 */
David Howellsd0016482016-08-30 20:42:14 +0100631static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700632{
David Howells372ee162016-08-03 14:11:40 +0100633 int ret;
634
David Howellsd0016482016-08-30 20:42:14 +0100635 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700636
David Howells12bdcf32018-10-20 00:57:56 +0100637 afs_extract_discard(call, 0);
638 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100639 if (ret < 0)
640 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700641
David Howells98bf40c2017-11-02 15:27:53 +0000642 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100643 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100644 return afs_find_cm_server_by_peer(call);
David Howellsb908fe62007-04-26 15:58:17 -0700645}
David Howells35dbfba2018-10-20 00:57:58 +0100646
647/*
648 * deliver request data to a YFS CB.CallBack call
649 */
650static int afs_deliver_yfs_cb_callback(struct afs_call *call)
651{
652 struct afs_callback_break *cb;
David Howells35dbfba2018-10-20 00:57:58 +0100653 struct yfs_xdr_YFSFid *bp;
654 size_t size;
655 int ret, loop;
656
657 _enter("{%u}", call->unmarshall);
658
659 switch (call->unmarshall) {
660 case 0:
661 afs_extract_to_tmp(call);
662 call->unmarshall++;
663
664 /* extract the FID array and its count in two steps */
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600665 /* Fall through */
David Howells35dbfba2018-10-20 00:57:58 +0100666 case 1:
667 _debug("extract FID count");
668 ret = afs_extract_data(call, true);
669 if (ret < 0)
670 return ret;
671
672 call->count = ntohl(call->tmp);
673 _debug("FID count: %u", call->count);
674 if (call->count > YFSCBMAX)
David Howells7126ead2020-04-08 16:49:08 +0100675 return afs_protocol_error(call, afs_eproto_cb_fid_count);
David Howells35dbfba2018-10-20 00:57:58 +0100676
677 size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid));
678 call->buffer = kmalloc(size, GFP_KERNEL);
679 if (!call->buffer)
680 return -ENOMEM;
681 afs_extract_to_buf(call, size);
682 call->unmarshall++;
683
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600684 /* Fall through */
David Howells35dbfba2018-10-20 00:57:58 +0100685 case 2:
686 _debug("extract FID array");
687 ret = afs_extract_data(call, false);
688 if (ret < 0)
689 return ret;
690
691 _debug("unmarshall FID array");
692 call->request = kcalloc(call->count,
693 sizeof(struct afs_callback_break),
694 GFP_KERNEL);
695 if (!call->request)
696 return -ENOMEM;
697
698 cb = call->request;
699 bp = call->buffer;
700 for (loop = call->count; loop > 0; loop--, cb++) {
701 cb->fid.vid = xdr_to_u64(bp->volume);
702 cb->fid.vnode = xdr_to_u64(bp->vnode.lo);
703 cb->fid.vnode_hi = ntohl(bp->vnode.hi);
704 cb->fid.unique = ntohl(bp->vnode.unique);
705 bp++;
706 }
707
708 afs_extract_to_tmp(call);
709 call->unmarshall++;
710
711 case 3:
712 break;
713 }
714
715 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
716 return afs_io_error(call, afs_io_error_cm_reply);
717
718 /* We'll need the file server record as that tells us which set of
719 * vnodes to operate upon.
720 */
David Howells3bf0fb62018-10-20 00:57:59 +0100721 return afs_find_cm_server_by_peer(call);
David Howells35dbfba2018-10-20 00:57:58 +0100722}