blob: a4e9e6e07e9397321f61567a047f3fafb574fa62 [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++;
David Howellsd0016482016-08-30 20:42:14 +0100325 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 break;
327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
David Howells98bf40c2017-11-02 15:27:53 +0000329 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100330 return afs_io_error(call, afs_io_error_cm_reply);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
David Howells08e0e7c2007-04-26 15:55:03 -0700332 /* we'll need the file server record as that tells us which set of
333 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100334 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700335}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337/*
David Howells08e0e7c2007-04-26 15:55:03 -0700338 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 */
David Howells08e0e7c2007-04-26 15:55:03 -0700340static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
David Howells08e0e7c2007-04-26 15:55:03 -0700342 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
David Howellsffba7182019-05-09 22:22:50 +0100344 _enter("{%p}", call->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
David Howellsffba7182019-05-09 22:22:50 +0100346 if (call->server)
347 afs_init_callback_state(call->server);
David Howells08e0e7c2007-04-26 15:55:03 -0700348 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000349 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700350 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700351}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353/*
David Howells08e0e7c2007-04-26 15:55:03 -0700354 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 */
David Howellsd0016482016-08-30 20:42:14 +0100356static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
David Howells372ee162016-08-03 14:11:40 +0100358 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
David Howellsd0016482016-08-30 20:42:14 +0100360 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
David Howells12bdcf32018-10-20 00:57:56 +0100362 afs_extract_discard(call, 0);
363 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100364 if (ret < 0)
365 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
David Howells08e0e7c2007-04-26 15:55:03 -0700367 /* we'll need the file server record as that tells us which set of
368 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100369 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700370}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372/*
David Howellsc35eccb2007-04-26 15:58:49 -0700373 * deliver request data to a CB.InitCallBackState3 call
374 */
David Howellsd0016482016-08-30 20:42:14 +0100375static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700376{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300377 struct afs_uuid *r;
David Howellsd0016482016-08-30 20:42:14 +0100378 unsigned loop;
379 __be32 *b;
380 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700381
David Howellsd0016482016-08-30 20:42:14 +0100382 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700383
David Howellsd0016482016-08-30 20:42:14 +0100384 _enter("{%u}", call->unmarshall);
385
386 switch (call->unmarshall) {
387 case 0:
Kees Cook6da2ec52018-06-12 13:55:00 -0700388 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100389 if (!call->buffer)
390 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100391 afs_extract_to_buf(call, 11 * sizeof(__be32));
David Howellsd0016482016-08-30 20:42:14 +0100392 call->unmarshall++;
393
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500394 fallthrough;
David Howellsd0016482016-08-30 20:42:14 +0100395 case 1:
396 _debug("extract UUID");
David Howells12bdcf32018-10-20 00:57:56 +0100397 ret = afs_extract_data(call, false);
David Howellsd0016482016-08-30 20:42:14 +0100398 switch (ret) {
399 case 0: break;
400 case -EAGAIN: return 0;
401 default: return ret;
402 }
403
404 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300405 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100406 if (!call->request)
407 return -ENOMEM;
408
409 b = call->buffer;
410 r = call->request;
David Howellsff548772017-02-10 16:34:07 +0000411 r->time_low = b[0];
412 r->time_mid = htons(ntohl(b[1]));
413 r->time_hi_and_version = htons(ntohl(b[2]));
David Howellsd0016482016-08-30 20:42:14 +0100414 r->clock_seq_hi_and_reserved = ntohl(b[3]);
415 r->clock_seq_low = ntohl(b[4]);
416
417 for (loop = 0; loop < 6; loop++)
418 r->node[loop] = ntohl(b[loop + 5]);
419
David Howellsd0016482016-08-30 20:42:14 +0100420 call->unmarshall++;
421
422 case 2:
423 break;
424 }
David Howellsc35eccb2007-04-26 15:58:49 -0700425
David Howells98bf40c2017-11-02 15:27:53 +0000426 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100427 return afs_io_error(call, afs_io_error_cm_reply);
David Howellsc35eccb2007-04-26 15:58:49 -0700428
429 /* we'll need the file server record as that tells us which set of
430 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100431 return afs_find_cm_server_by_uuid(call, call->request);
David Howellsc35eccb2007-04-26 15:58:49 -0700432}
433
434/*
David Howells08e0e7c2007-04-26 15:55:03 -0700435 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 */
David Howells08e0e7c2007-04-26 15:55:03 -0700437static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
David Howells08e0e7c2007-04-26 15:55:03 -0700439 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
David Howells08e0e7c2007-04-26 15:55:03 -0700441 _enter("");
442 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000443 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700444 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700445}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447/*
David Howells08e0e7c2007-04-26 15:55:03 -0700448 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 */
David Howellsd0016482016-08-30 20:42:14 +0100450static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
David Howells372ee162016-08-03 14:11:40 +0100452 int ret;
453
David Howellsd0016482016-08-30 20:42:14 +0100454 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
David Howells12bdcf32018-10-20 00:57:56 +0100456 afs_extract_discard(call, 0);
457 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100458 if (ret < 0)
459 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
David Howells98bf40c2017-11-02 15:27:53 +0000461 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100462 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100463 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700464}
David Howellsb908fe62007-04-26 15:58:17 -0700465
466/*
David Howells3120c172020-05-27 16:44:02 +0100467 * Allow the fileserver to quickly find out if the cache manager has been
468 * rebooted.
David Howells9396d492008-04-29 01:03:22 -0700469 */
470static void SRXAFSCB_ProbeUuid(struct work_struct *work)
471{
472 struct afs_call *call = container_of(work, struct afs_call, work);
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300473 struct afs_uuid *r = call->request;
David Howells9396d492008-04-29 01:03:22 -0700474
David Howells9396d492008-04-29 01:03:22 -0700475 _enter("");
476
David Howellsf044c882017-11-02 15:27:45 +0000477 if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
David Howells2067b2b2019-07-30 14:38:51 +0100478 afs_send_empty_reply(call);
David Howells9396d492008-04-29 01:03:22 -0700479 else
David Howellsdde9f092020-03-13 13:46:08 +0000480 afs_abort_service_call(call, 1, 1, "K-1");
David Howells9396d492008-04-29 01:03:22 -0700481
David Howells341f7412017-01-05 10:38:36 +0000482 afs_put_call(call);
David Howells9396d492008-04-29 01:03:22 -0700483 _leave("");
484}
485
486/*
487 * deliver request data to a CB.ProbeUuid call
488 */
David Howellsd0016482016-08-30 20:42:14 +0100489static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700490{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300491 struct afs_uuid *r;
David Howells9396d492008-04-29 01:03:22 -0700492 unsigned loop;
493 __be32 *b;
494 int ret;
495
David Howellsd0016482016-08-30 20:42:14 +0100496 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700497
498 switch (call->unmarshall) {
499 case 0:
Kees Cook6da2ec52018-06-12 13:55:00 -0700500 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700501 if (!call->buffer)
502 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100503 afs_extract_to_buf(call, 11 * sizeof(__be32));
David Howells9396d492008-04-29 01:03:22 -0700504 call->unmarshall++;
505
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500506 fallthrough;
David Howells9396d492008-04-29 01:03:22 -0700507 case 1:
508 _debug("extract UUID");
David Howells12bdcf32018-10-20 00:57:56 +0100509 ret = afs_extract_data(call, false);
David Howells9396d492008-04-29 01:03:22 -0700510 switch (ret) {
511 case 0: break;
512 case -EAGAIN: return 0;
513 default: return ret;
514 }
515
516 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300517 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700518 if (!call->request)
519 return -ENOMEM;
520
521 b = call->buffer;
522 r = call->request;
David Howellsfe342cf2018-04-09 21:12:31 +0100523 r->time_low = b[0];
524 r->time_mid = htons(ntohl(b[1]));
525 r->time_hi_and_version = htons(ntohl(b[2]));
David Howells9396d492008-04-29 01:03:22 -0700526 r->clock_seq_hi_and_reserved = ntohl(b[3]);
527 r->clock_seq_low = ntohl(b[4]);
528
529 for (loop = 0; loop < 6; loop++)
530 r->node[loop] = ntohl(b[loop + 5]);
531
David Howells9396d492008-04-29 01:03:22 -0700532 call->unmarshall++;
533
534 case 2:
David Howells9396d492008-04-29 01:03:22 -0700535 break;
536 }
537
David Howells98bf40c2017-11-02 15:27:53 +0000538 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100539 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3120c172020-05-27 16:44:02 +0100540 return afs_find_cm_server_by_peer(call);
David Howells9396d492008-04-29 01:03:22 -0700541}
542
543/*
David Howellsb908fe62007-04-26 15:58:17 -0700544 * allow the fileserver to ask about the cache manager's capabilities
545 */
David Howells7c80bcc2008-04-29 01:03:21 -0700546static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700547{
David Howellsb908fe62007-04-26 15:58:17 -0700548 struct afs_call *call = container_of(work, struct afs_call, work);
Florian Westphal35ebfc22019-05-31 18:27:03 +0200549 int loop;
David Howellsb908fe62007-04-26 15:58:17 -0700550
551 struct {
552 struct /* InterfaceAddr */ {
553 __be32 nifs;
554 __be32 uuid[11];
555 __be32 ifaddr[32];
556 __be32 netmask[32];
557 __be32 mtu[32];
558 } ia;
559 struct /* Capabilities */ {
560 __be32 capcount;
561 __be32 caps[1];
562 } cap;
563 } reply;
564
565 _enter("");
566
David Howellsb908fe62007-04-26 15:58:17 -0700567 memset(&reply, 0, sizeof(reply));
David Howellsb908fe62007-04-26 15:58:17 -0700568
David Howellsf044c882017-11-02 15:27:45 +0000569 reply.ia.uuid[0] = call->net->uuid.time_low;
570 reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid));
571 reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version));
572 reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved);
573 reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low);
David Howellsb908fe62007-04-26 15:58:17 -0700574 for (loop = 0; loop < 6; loop++)
David Howellsf044c882017-11-02 15:27:45 +0000575 reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]);
David Howellsb908fe62007-04-26 15:58:17 -0700576
David Howellsb908fe62007-04-26 15:58:17 -0700577 reply.cap.capcount = htonl(1);
578 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
579 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000580 afs_put_call(call);
David Howellsb908fe62007-04-26 15:58:17 -0700581 _leave("");
582}
583
584/*
David Howells7c80bcc2008-04-29 01:03:21 -0700585 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700586 */
David Howellsd0016482016-08-30 20:42:14 +0100587static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700588{
David Howells372ee162016-08-03 14:11:40 +0100589 int ret;
590
David Howellsd0016482016-08-30 20:42:14 +0100591 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700592
David Howells12bdcf32018-10-20 00:57:56 +0100593 afs_extract_discard(call, 0);
594 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100595 if (ret < 0)
596 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700597
David Howells98bf40c2017-11-02 15:27:53 +0000598 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100599 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100600 return afs_find_cm_server_by_peer(call);
David Howellsb908fe62007-04-26 15:58:17 -0700601}
David Howells35dbfba2018-10-20 00:57:58 +0100602
603/*
604 * deliver request data to a YFS CB.CallBack call
605 */
606static int afs_deliver_yfs_cb_callback(struct afs_call *call)
607{
608 struct afs_callback_break *cb;
David Howells35dbfba2018-10-20 00:57:58 +0100609 struct yfs_xdr_YFSFid *bp;
610 size_t size;
611 int ret, loop;
612
613 _enter("{%u}", call->unmarshall);
614
615 switch (call->unmarshall) {
616 case 0:
617 afs_extract_to_tmp(call);
618 call->unmarshall++;
619
620 /* extract the FID array and its count in two steps */
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500621 fallthrough;
David Howells35dbfba2018-10-20 00:57:58 +0100622 case 1:
623 _debug("extract FID count");
624 ret = afs_extract_data(call, true);
625 if (ret < 0)
626 return ret;
627
628 call->count = ntohl(call->tmp);
629 _debug("FID count: %u", call->count);
630 if (call->count > YFSCBMAX)
David Howells7126ead2020-04-08 16:49:08 +0100631 return afs_protocol_error(call, afs_eproto_cb_fid_count);
David Howells35dbfba2018-10-20 00:57:58 +0100632
633 size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid));
634 call->buffer = kmalloc(size, GFP_KERNEL);
635 if (!call->buffer)
636 return -ENOMEM;
637 afs_extract_to_buf(call, size);
638 call->unmarshall++;
639
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500640 fallthrough;
David Howells35dbfba2018-10-20 00:57:58 +0100641 case 2:
642 _debug("extract FID array");
643 ret = afs_extract_data(call, false);
644 if (ret < 0)
645 return ret;
646
647 _debug("unmarshall FID array");
648 call->request = kcalloc(call->count,
649 sizeof(struct afs_callback_break),
650 GFP_KERNEL);
651 if (!call->request)
652 return -ENOMEM;
653
654 cb = call->request;
655 bp = call->buffer;
656 for (loop = call->count; loop > 0; loop--, cb++) {
657 cb->fid.vid = xdr_to_u64(bp->volume);
658 cb->fid.vnode = xdr_to_u64(bp->vnode.lo);
659 cb->fid.vnode_hi = ntohl(bp->vnode.hi);
660 cb->fid.unique = ntohl(bp->vnode.unique);
661 bp++;
662 }
663
664 afs_extract_to_tmp(call);
665 call->unmarshall++;
666
667 case 3:
668 break;
669 }
670
671 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
672 return afs_io_error(call, afs_io_error_cm_reply);
673
674 /* We'll need the file server record as that tells us which set of
675 * vnodes to operate upon.
676 */
David Howells3bf0fb62018-10-20 00:57:59 +0100677 return afs_find_cm_server_by_peer(call);
David Howells35dbfba2018-10-20 00:57:58 +0100678}