blob: a3f5de28be798d8d21964c03a24e2b6d3d2e7119 [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 Howells08e0e7c2007-04-26 15:55:03 -070032/*
33 * CB.CallBack operation type
34 */
35static const struct afs_call_type afs_SRXCBCallBack = {
David Howells6c881ca2021-06-15 11:57:26 +010036 .name = "CB.CallBack",
David Howells08e0e7c2007-04-26 15:55:03 -070037 .deliver = afs_deliver_cb_callback,
David Howells08e0e7c2007-04-26 15:55:03 -070038 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000039 .work = SRXAFSCB_CallBack,
Linus Torvalds1da177e2005-04-16 15:20:36 -070040};
41
David Howells08e0e7c2007-04-26 15:55:03 -070042/*
43 * CB.InitCallBackState operation type
44 */
45static const struct afs_call_type afs_SRXCBInitCallBackState = {
David Howells6c881ca2021-06-15 11:57:26 +010046 .name = "CB.InitCallBackState",
David Howells08e0e7c2007-04-26 15:55:03 -070047 .deliver = afs_deliver_cb_init_call_back_state,
David Howells08e0e7c2007-04-26 15:55:03 -070048 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000049 .work = SRXAFSCB_InitCallBackState,
Linus Torvalds1da177e2005-04-16 15:20:36 -070050};
51
David Howells08e0e7c2007-04-26 15:55:03 -070052/*
David Howellsc35eccb2007-04-26 15:58:49 -070053 * CB.InitCallBackState3 operation type
54 */
55static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
David Howells6c881ca2021-06-15 11:57:26 +010056 .name = "CB.InitCallBackState3",
David Howellsc35eccb2007-04-26 15:58:49 -070057 .deliver = afs_deliver_cb_init_call_back_state3,
David Howellsc35eccb2007-04-26 15:58:49 -070058 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000059 .work = SRXAFSCB_InitCallBackState,
David Howellsc35eccb2007-04-26 15:58:49 -070060};
61
62/*
David Howells08e0e7c2007-04-26 15:55:03 -070063 * CB.Probe operation type
64 */
65static const struct afs_call_type afs_SRXCBProbe = {
David Howells6c881ca2021-06-15 11:57:26 +010066 .name = "CB.Probe",
David Howells08e0e7c2007-04-26 15:55:03 -070067 .deliver = afs_deliver_cb_probe,
David Howells08e0e7c2007-04-26 15:55:03 -070068 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000069 .work = SRXAFSCB_Probe,
David Howells08e0e7c2007-04-26 15:55:03 -070070};
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/*
David Howells9396d492008-04-29 01:03:22 -070073 * CB.ProbeUuid operation type
74 */
75static const struct afs_call_type afs_SRXCBProbeUuid = {
David Howells6c881ca2021-06-15 11:57:26 +010076 .name = "CB.ProbeUuid",
David Howells9396d492008-04-29 01:03:22 -070077 .deliver = afs_deliver_cb_probe_uuid,
David Howells9396d492008-04-29 01:03:22 -070078 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000079 .work = SRXAFSCB_ProbeUuid,
David Howells9396d492008-04-29 01:03:22 -070080};
81
82/*
David Howells7c80bcc2008-04-29 01:03:21 -070083 * CB.TellMeAboutYourself operation type
David Howellsb908fe62007-04-26 15:58:17 -070084 */
David Howells7c80bcc2008-04-29 01:03:21 -070085static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
David Howells6c881ca2021-06-15 11:57:26 +010086 .name = "CB.TellMeAboutYourself",
David Howells7c80bcc2008-04-29 01:03:21 -070087 .deliver = afs_deliver_cb_tell_me_about_yourself,
David Howellsb908fe62007-04-26 15:58:17 -070088 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000089 .work = SRXAFSCB_TellMeAboutYourself,
David Howellsb908fe62007-04-26 15:58:17 -070090};
91
92/*
David Howells35dbfba2018-10-20 00:57:58 +010093 * YFS CB.CallBack operation type
94 */
David Howells35dbfba2018-10-20 00:57:58 +010095static const struct afs_call_type afs_SRXYFSCB_CallBack = {
David Howells6c881ca2021-06-15 11:57:26 +010096 .name = "YFSCB.CallBack",
David Howells35dbfba2018-10-20 00:57:58 +010097 .deliver = afs_deliver_yfs_cb_callback,
98 .destructor = afs_cm_destructor,
99 .work = SRXAFSCB_CallBack,
100};
101
102/*
David Howells08e0e7c2007-04-26 15:55:03 -0700103 * route an incoming cache manager call
104 * - return T if supported, F if not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 */
David Howells08e0e7c2007-04-26 15:55:03 -0700106bool afs_cm_incoming_call(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
David Howells35dbfba2018-10-20 00:57:58 +0100108 _enter("{%u, CB.OP %u}", call->service_id, call->operation_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
David Howells50a2c952016-10-13 08:27:10 +0100110 switch (call->operation_ID) {
David Howells08e0e7c2007-04-26 15:55:03 -0700111 case CBCallBack:
112 call->type = &afs_SRXCBCallBack;
113 return true;
114 case CBInitCallBackState:
115 call->type = &afs_SRXCBInitCallBackState;
116 return true;
David Howellsc35eccb2007-04-26 15:58:49 -0700117 case CBInitCallBackState3:
118 call->type = &afs_SRXCBInitCallBackState3;
119 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700120 case CBProbe:
121 call->type = &afs_SRXCBProbe;
122 return true;
David Howellsf4b35262017-11-02 15:27:48 +0000123 case CBProbeUuid:
124 call->type = &afs_SRXCBProbeUuid;
125 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700126 case CBTellMeAboutYourself:
127 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700128 return true;
David Howells35dbfba2018-10-20 00:57:58 +0100129 case YFSCBCallBack:
130 if (call->service_id != YFS_CM_SERVICE)
131 return false;
132 call->type = &afs_SRXYFSCB_CallBack;
133 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700134 default:
135 return false;
136 }
David Howellsec268152007-04-26 15:49:28 -0700137}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/*
David Howells3bf0fb62018-10-20 00:57:59 +0100140 * Find the server record by peer address and record a probe to the cache
141 * manager from a server.
142 */
143static int afs_find_cm_server_by_peer(struct afs_call *call)
144{
145 struct sockaddr_rxrpc srx;
146 struct afs_server *server;
147
148 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
149
150 server = afs_find_server(call->net, &srx);
151 if (!server) {
152 trace_afs_cm_no_server(call, &srx);
153 return 0;
154 }
155
David Howellsffba7182019-05-09 22:22:50 +0100156 call->server = server;
David Howells44746352020-05-27 15:52:02 +0100157 return 0;
David Howells3bf0fb62018-10-20 00:57:59 +0100158}
159
160/*
161 * Find the server record by server UUID and record a probe to the cache
162 * manager from a server.
163 */
164static int afs_find_cm_server_by_uuid(struct afs_call *call,
165 struct afs_uuid *uuid)
166{
167 struct afs_server *server;
168
169 rcu_read_lock();
170 server = afs_find_server_by_uuid(call->net, call->request);
171 rcu_read_unlock();
172 if (!server) {
173 trace_afs_cm_no_server_u(call, call->request);
174 return 0;
175 }
176
David Howellsffba7182019-05-09 22:22:50 +0100177 call->server = server;
David Howells44746352020-05-27 15:52:02 +0100178 return 0;
David Howells3bf0fb62018-10-20 00:57:59 +0100179}
180
181/*
David Howells428edad2018-05-12 00:28:58 +0100182 * Clean up a cache manager call.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 */
David Howells08e0e7c2007-04-26 15:55:03 -0700184static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
David Howells08e0e7c2007-04-26 15:55:03 -0700186 kfree(call->buffer);
187 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700188}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/*
David Howellsdde9f092020-03-13 13:46:08 +0000191 * Abort a service call from within an action function.
192 */
193static void afs_abort_service_call(struct afs_call *call, u32 abort_code, int error,
194 const char *why)
195{
196 rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
197 abort_code, error, why);
198 afs_set_call_complete(call, error, 0);
199}
200
201/*
David Howellsc435ee32017-11-02 15:27:49 +0000202 * The server supplied a list of callbacks that it wanted to break.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 */
David Howells08e0e7c2007-04-26 15:55:03 -0700204static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
David Howells08e0e7c2007-04-26 15:55:03 -0700206 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
David Howells08e0e7c2007-04-26 15:55:03 -0700208 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
David Howells428edad2018-05-12 00:28:58 +0100210 /* We need to break the callbacks before sending the reply as the
211 * server holds up change visibility till it receives our reply so as
212 * to maintain cache coherency.
213 */
David Howells45218192019-06-20 18:12:17 +0100214 if (call->server) {
David Howells977e5f82020-04-17 17:31:26 +0100215 trace_afs_server(call->server,
216 atomic_read(&call->server->ref),
217 atomic_read(&call->server->active),
David Howells45218192019-06-20 18:12:17 +0100218 afs_server_trace_callback);
David Howellsffba7182019-05-09 22:22:50 +0100219 afs_break_callbacks(call->server, call->count, call->request);
David Howells45218192019-06-20 18:12:17 +0100220 }
David Howells428edad2018-05-12 00:28:58 +0100221
222 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000223 afs_put_call(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700225}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227/*
David Howells08e0e7c2007-04-26 15:55:03 -0700228 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 */
David Howellsd0016482016-08-30 20:42:14 +0100230static int afs_deliver_cb_callback(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
David Howells5cf9dd52018-04-09 21:12:31 +0100232 struct afs_callback_break *cb;
David Howells08e0e7c2007-04-26 15:55:03 -0700233 __be32 *bp;
David Howells08e0e7c2007-04-26 15:55:03 -0700234 int ret, loop;
235
David Howellsd0016482016-08-30 20:42:14 +0100236 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700237
238 switch (call->unmarshall) {
239 case 0:
David Howells12bdcf32018-10-20 00:57:56 +0100240 afs_extract_to_tmp(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700241 call->unmarshall++;
242
243 /* extract the FID array and its count in two steps */
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500244 fallthrough;
David Howells08e0e7c2007-04-26 15:55:03 -0700245 case 1:
246 _debug("extract FID count");
David Howells12bdcf32018-10-20 00:57:56 +0100247 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100248 if (ret < 0)
249 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700250
251 call->count = ntohl(call->tmp);
252 _debug("FID count: %u", call->count);
253 if (call->count > AFSCBMAX)
David Howells7126ead2020-04-08 16:49:08 +0100254 return afs_protocol_error(call, afs_eproto_cb_fid_count);
David Howells08e0e7c2007-04-26 15:55:03 -0700255
Kees Cook6da2ec52018-06-12 13:55:00 -0700256 call->buffer = kmalloc(array3_size(call->count, 3, 4),
257 GFP_KERNEL);
David Howells08e0e7c2007-04-26 15:55:03 -0700258 if (!call->buffer)
259 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100260 afs_extract_to_buf(call, call->count * 3 * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700261 call->unmarshall++;
262
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500263 fallthrough;
David Howells08e0e7c2007-04-26 15:55:03 -0700264 case 2:
265 _debug("extract FID array");
David Howells12bdcf32018-10-20 00:57:56 +0100266 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100267 if (ret < 0)
268 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700269
270 _debug("unmarshall FID array");
271 call->request = kcalloc(call->count,
David Howells5cf9dd52018-04-09 21:12:31 +0100272 sizeof(struct afs_callback_break),
David Howells08e0e7c2007-04-26 15:55:03 -0700273 GFP_KERNEL);
274 if (!call->request)
275 return -ENOMEM;
276
277 cb = call->request;
278 bp = call->buffer;
279 for (loop = call->count; loop > 0; loop--, cb++) {
280 cb->fid.vid = ntohl(*bp++);
281 cb->fid.vnode = ntohl(*bp++);
282 cb->fid.unique = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700283 }
284
David Howells12bdcf32018-10-20 00:57:56 +0100285 afs_extract_to_tmp(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700286 call->unmarshall++;
287
288 /* extract the callback array and its count in two steps */
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500289 fallthrough;
David Howells08e0e7c2007-04-26 15:55:03 -0700290 case 3:
291 _debug("extract CB count");
David Howells12bdcf32018-10-20 00:57:56 +0100292 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100293 if (ret < 0)
294 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700295
Marc Dionnebcd89272017-03-16 16:27:44 +0000296 call->count2 = ntohl(call->tmp);
297 _debug("CB count: %u", call->count2);
298 if (call->count2 != call->count && call->count2 != 0)
David Howells7126ead2020-04-08 16:49:08 +0100299 return afs_protocol_error(call, afs_eproto_cb_count);
David Howellsfc276122019-11-21 09:12:17 +0000300 call->iter = &call->def_iter;
301 iov_iter_discard(&call->def_iter, READ, call->count2 * 3 * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700302 call->unmarshall++;
David Howells08e0e7c2007-04-26 15:55:03 -0700303
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500304 fallthrough;
David Howells08e0e7c2007-04-26 15:55:03 -0700305 case 4:
David Howells06aeb292018-10-20 00:57:58 +0100306 _debug("extract discard %zu/%u",
David Howellsfc276122019-11-21 09:12:17 +0000307 iov_iter_count(call->iter), call->count2 * 3 * 4);
David Howells06aeb292018-10-20 00:57:58 +0100308
David Howells12bdcf32018-10-20 00:57:56 +0100309 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100310 if (ret < 0)
311 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700312
David Howells08e0e7c2007-04-26 15:55:03 -0700313 call->unmarshall++;
Gustavo A. R. Silvab2db6c32021-05-25 15:40:22 +0100314 fallthrough;
315
David Howellsd0016482016-08-30 20:42:14 +0100316 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 break;
318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
David Howells98bf40c2017-11-02 15:27:53 +0000320 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100321 return afs_io_error(call, afs_io_error_cm_reply);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
David Howells08e0e7c2007-04-26 15:55:03 -0700323 /* we'll need the file server record as that tells us which set of
324 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100325 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700326}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328/*
David Howells08e0e7c2007-04-26 15:55:03 -0700329 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 */
David Howells08e0e7c2007-04-26 15:55:03 -0700331static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
David Howells08e0e7c2007-04-26 15:55:03 -0700333 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
David Howellsffba7182019-05-09 22:22:50 +0100335 _enter("{%p}", call->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
David Howellsffba7182019-05-09 22:22:50 +0100337 if (call->server)
338 afs_init_callback_state(call->server);
David Howells08e0e7c2007-04-26 15:55:03 -0700339 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000340 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700341 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700342}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344/*
David Howells08e0e7c2007-04-26 15:55:03 -0700345 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 */
David Howellsd0016482016-08-30 20:42:14 +0100347static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
David Howells372ee162016-08-03 14:11:40 +0100349 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
David Howellsd0016482016-08-30 20:42:14 +0100351 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
David Howells12bdcf32018-10-20 00:57:56 +0100353 afs_extract_discard(call, 0);
354 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100355 if (ret < 0)
356 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
David Howells08e0e7c2007-04-26 15:55:03 -0700358 /* we'll need the file server record as that tells us which set of
359 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100360 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700361}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363/*
David Howellsc35eccb2007-04-26 15:58:49 -0700364 * deliver request data to a CB.InitCallBackState3 call
365 */
David Howellsd0016482016-08-30 20:42:14 +0100366static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700367{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300368 struct afs_uuid *r;
David Howellsd0016482016-08-30 20:42:14 +0100369 unsigned loop;
370 __be32 *b;
371 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700372
David Howellsd0016482016-08-30 20:42:14 +0100373 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700374
David Howellsd0016482016-08-30 20:42:14 +0100375 _enter("{%u}", call->unmarshall);
376
377 switch (call->unmarshall) {
378 case 0:
Kees Cook6da2ec52018-06-12 13:55:00 -0700379 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100380 if (!call->buffer)
381 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100382 afs_extract_to_buf(call, 11 * sizeof(__be32));
David Howellsd0016482016-08-30 20:42:14 +0100383 call->unmarshall++;
384
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500385 fallthrough;
David Howellsd0016482016-08-30 20:42:14 +0100386 case 1:
387 _debug("extract UUID");
David Howells12bdcf32018-10-20 00:57:56 +0100388 ret = afs_extract_data(call, false);
David Howellsd0016482016-08-30 20:42:14 +0100389 switch (ret) {
390 case 0: break;
391 case -EAGAIN: return 0;
392 default: return ret;
393 }
394
395 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300396 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100397 if (!call->request)
398 return -ENOMEM;
399
400 b = call->buffer;
401 r = call->request;
David Howellsff548772017-02-10 16:34:07 +0000402 r->time_low = b[0];
403 r->time_mid = htons(ntohl(b[1]));
404 r->time_hi_and_version = htons(ntohl(b[2]));
David Howellsd0016482016-08-30 20:42:14 +0100405 r->clock_seq_hi_and_reserved = ntohl(b[3]);
406 r->clock_seq_low = ntohl(b[4]);
407
408 for (loop = 0; loop < 6; loop++)
409 r->node[loop] = ntohl(b[loop + 5]);
410
David Howellsd0016482016-08-30 20:42:14 +0100411 call->unmarshall++;
Gustavo A. R. Silvab2db6c32021-05-25 15:40:22 +0100412 fallthrough;
David Howellsd0016482016-08-30 20:42:14 +0100413
414 case 2:
415 break;
416 }
David Howellsc35eccb2007-04-26 15:58:49 -0700417
David Howells98bf40c2017-11-02 15:27:53 +0000418 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100419 return afs_io_error(call, afs_io_error_cm_reply);
David Howellsc35eccb2007-04-26 15:58:49 -0700420
421 /* we'll need the file server record as that tells us which set of
422 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100423 return afs_find_cm_server_by_uuid(call, call->request);
David Howellsc35eccb2007-04-26 15:58:49 -0700424}
425
426/*
David Howells08e0e7c2007-04-26 15:55:03 -0700427 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 */
David Howells08e0e7c2007-04-26 15:55:03 -0700429static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
David Howells08e0e7c2007-04-26 15:55:03 -0700431 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
David Howells08e0e7c2007-04-26 15:55:03 -0700433 _enter("");
434 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000435 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700436 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700437}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439/*
David Howells08e0e7c2007-04-26 15:55:03 -0700440 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 */
David Howellsd0016482016-08-30 20:42:14 +0100442static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
David Howells372ee162016-08-03 14:11:40 +0100444 int ret;
445
David Howellsd0016482016-08-30 20:42:14 +0100446 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
David Howells12bdcf32018-10-20 00:57:56 +0100448 afs_extract_discard(call, 0);
449 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100450 if (ret < 0)
451 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
David Howells98bf40c2017-11-02 15:27:53 +0000453 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100454 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100455 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700456}
David Howellsb908fe62007-04-26 15:58:17 -0700457
458/*
David Howells3120c172020-05-27 16:44:02 +0100459 * Allow the fileserver to quickly find out if the cache manager has been
460 * rebooted.
David Howells9396d492008-04-29 01:03:22 -0700461 */
462static void SRXAFSCB_ProbeUuid(struct work_struct *work)
463{
464 struct afs_call *call = container_of(work, struct afs_call, work);
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300465 struct afs_uuid *r = call->request;
David Howells9396d492008-04-29 01:03:22 -0700466
David Howells9396d492008-04-29 01:03:22 -0700467 _enter("");
468
David Howellsf044c882017-11-02 15:27:45 +0000469 if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
David Howells2067b2b2019-07-30 14:38:51 +0100470 afs_send_empty_reply(call);
David Howells9396d492008-04-29 01:03:22 -0700471 else
David Howellsdde9f092020-03-13 13:46:08 +0000472 afs_abort_service_call(call, 1, 1, "K-1");
David Howells9396d492008-04-29 01:03:22 -0700473
David Howells341f7412017-01-05 10:38:36 +0000474 afs_put_call(call);
David Howells9396d492008-04-29 01:03:22 -0700475 _leave("");
476}
477
478/*
479 * deliver request data to a CB.ProbeUuid call
480 */
David Howellsd0016482016-08-30 20:42:14 +0100481static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700482{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300483 struct afs_uuid *r;
David Howells9396d492008-04-29 01:03:22 -0700484 unsigned loop;
485 __be32 *b;
486 int ret;
487
David Howellsd0016482016-08-30 20:42:14 +0100488 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700489
490 switch (call->unmarshall) {
491 case 0:
Kees Cook6da2ec52018-06-12 13:55:00 -0700492 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700493 if (!call->buffer)
494 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100495 afs_extract_to_buf(call, 11 * sizeof(__be32));
David Howells9396d492008-04-29 01:03:22 -0700496 call->unmarshall++;
497
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500498 fallthrough;
David Howells9396d492008-04-29 01:03:22 -0700499 case 1:
500 _debug("extract UUID");
David Howells12bdcf32018-10-20 00:57:56 +0100501 ret = afs_extract_data(call, false);
David Howells9396d492008-04-29 01:03:22 -0700502 switch (ret) {
503 case 0: break;
504 case -EAGAIN: return 0;
505 default: return ret;
506 }
507
508 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300509 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700510 if (!call->request)
511 return -ENOMEM;
512
513 b = call->buffer;
514 r = call->request;
David Howellsfe342cf2018-04-09 21:12:31 +0100515 r->time_low = b[0];
516 r->time_mid = htons(ntohl(b[1]));
517 r->time_hi_and_version = htons(ntohl(b[2]));
David Howells9396d492008-04-29 01:03:22 -0700518 r->clock_seq_hi_and_reserved = ntohl(b[3]);
519 r->clock_seq_low = ntohl(b[4]);
520
521 for (loop = 0; loop < 6; loop++)
522 r->node[loop] = ntohl(b[loop + 5]);
523
David Howells9396d492008-04-29 01:03:22 -0700524 call->unmarshall++;
Gustavo A. R. Silvab2db6c32021-05-25 15:40:22 +0100525 fallthrough;
David Howells9396d492008-04-29 01:03:22 -0700526
527 case 2:
David Howells9396d492008-04-29 01:03:22 -0700528 break;
529 }
530
David Howells98bf40c2017-11-02 15:27:53 +0000531 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100532 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3120c172020-05-27 16:44:02 +0100533 return afs_find_cm_server_by_peer(call);
David Howells9396d492008-04-29 01:03:22 -0700534}
535
536/*
David Howellsb908fe62007-04-26 15:58:17 -0700537 * allow the fileserver to ask about the cache manager's capabilities
538 */
David Howells7c80bcc2008-04-29 01:03:21 -0700539static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700540{
David Howellsb908fe62007-04-26 15:58:17 -0700541 struct afs_call *call = container_of(work, struct afs_call, work);
Florian Westphal35ebfc22019-05-31 18:27:03 +0200542 int loop;
David Howellsb908fe62007-04-26 15:58:17 -0700543
544 struct {
545 struct /* InterfaceAddr */ {
546 __be32 nifs;
547 __be32 uuid[11];
548 __be32 ifaddr[32];
549 __be32 netmask[32];
550 __be32 mtu[32];
551 } ia;
552 struct /* Capabilities */ {
553 __be32 capcount;
554 __be32 caps[1];
555 } cap;
556 } reply;
557
558 _enter("");
559
David Howellsb908fe62007-04-26 15:58:17 -0700560 memset(&reply, 0, sizeof(reply));
David Howellsb908fe62007-04-26 15:58:17 -0700561
David Howellsf044c882017-11-02 15:27:45 +0000562 reply.ia.uuid[0] = call->net->uuid.time_low;
563 reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid));
564 reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version));
565 reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved);
566 reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low);
David Howellsb908fe62007-04-26 15:58:17 -0700567 for (loop = 0; loop < 6; loop++)
David Howellsf044c882017-11-02 15:27:45 +0000568 reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]);
David Howellsb908fe62007-04-26 15:58:17 -0700569
David Howellsb908fe62007-04-26 15:58:17 -0700570 reply.cap.capcount = htonl(1);
571 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
572 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000573 afs_put_call(call);
David Howellsb908fe62007-04-26 15:58:17 -0700574 _leave("");
575}
576
577/*
David Howells7c80bcc2008-04-29 01:03:21 -0700578 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700579 */
David Howellsd0016482016-08-30 20:42:14 +0100580static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700581{
David Howells372ee162016-08-03 14:11:40 +0100582 int ret;
583
David Howellsd0016482016-08-30 20:42:14 +0100584 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700585
David Howells12bdcf32018-10-20 00:57:56 +0100586 afs_extract_discard(call, 0);
587 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100588 if (ret < 0)
589 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700590
David Howells98bf40c2017-11-02 15:27:53 +0000591 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100592 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100593 return afs_find_cm_server_by_peer(call);
David Howellsb908fe62007-04-26 15:58:17 -0700594}
David Howells35dbfba2018-10-20 00:57:58 +0100595
596/*
597 * deliver request data to a YFS CB.CallBack call
598 */
599static int afs_deliver_yfs_cb_callback(struct afs_call *call)
600{
601 struct afs_callback_break *cb;
David Howells35dbfba2018-10-20 00:57:58 +0100602 struct yfs_xdr_YFSFid *bp;
603 size_t size;
604 int ret, loop;
605
606 _enter("{%u}", call->unmarshall);
607
608 switch (call->unmarshall) {
609 case 0:
610 afs_extract_to_tmp(call);
611 call->unmarshall++;
612
613 /* extract the FID array and its count in two steps */
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500614 fallthrough;
David Howells35dbfba2018-10-20 00:57:58 +0100615 case 1:
616 _debug("extract FID count");
617 ret = afs_extract_data(call, true);
618 if (ret < 0)
619 return ret;
620
621 call->count = ntohl(call->tmp);
622 _debug("FID count: %u", call->count);
623 if (call->count > YFSCBMAX)
David Howells7126ead2020-04-08 16:49:08 +0100624 return afs_protocol_error(call, afs_eproto_cb_fid_count);
David Howells35dbfba2018-10-20 00:57:58 +0100625
626 size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid));
627 call->buffer = kmalloc(size, GFP_KERNEL);
628 if (!call->buffer)
629 return -ENOMEM;
630 afs_extract_to_buf(call, size);
631 call->unmarshall++;
632
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500633 fallthrough;
David Howells35dbfba2018-10-20 00:57:58 +0100634 case 2:
635 _debug("extract FID array");
636 ret = afs_extract_data(call, false);
637 if (ret < 0)
638 return ret;
639
640 _debug("unmarshall FID array");
641 call->request = kcalloc(call->count,
642 sizeof(struct afs_callback_break),
643 GFP_KERNEL);
644 if (!call->request)
645 return -ENOMEM;
646
647 cb = call->request;
648 bp = call->buffer;
649 for (loop = call->count; loop > 0; loop--, cb++) {
650 cb->fid.vid = xdr_to_u64(bp->volume);
651 cb->fid.vnode = xdr_to_u64(bp->vnode.lo);
652 cb->fid.vnode_hi = ntohl(bp->vnode.hi);
653 cb->fid.unique = ntohl(bp->vnode.unique);
654 bp++;
655 }
656
657 afs_extract_to_tmp(call);
658 call->unmarshall++;
Gustavo A. R. Silvab2db6c32021-05-25 15:40:22 +0100659 fallthrough;
David Howells35dbfba2018-10-20 00:57:58 +0100660
661 case 3:
662 break;
663 }
664
665 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
666 return afs_io_error(call, afs_io_error_cm_reply);
667
668 /* We'll need the file server record as that tells us which set of
669 * vnodes to operate upon.
670 */
David Howells3bf0fb62018-10-20 00:57:59 +0100671 return afs_find_cm_server_by_peer(call);
David Howells35dbfba2018-10-20 00:57:58 +0100672}