blob: 8ee5972893ed5a75583bfb2821a42636403ee086 [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* AFS Cache Manager Service
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/sched.h>
David Howells08e0e7c2007-04-26 15:55:03 -070016#include <linux/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070018#include "afs_cm.h"
David Howells35dbfba2018-10-20 00:57:58 +010019#include "protocol_yfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
David Howellsd0016482016-08-30 20:42:14 +010021static int afs_deliver_cb_init_call_back_state(struct afs_call *);
22static int afs_deliver_cb_init_call_back_state3(struct afs_call *);
23static int afs_deliver_cb_probe(struct afs_call *);
24static int afs_deliver_cb_callback(struct afs_call *);
25static int afs_deliver_cb_probe_uuid(struct afs_call *);
26static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *);
David Howells08e0e7c2007-04-26 15:55:03 -070027static void afs_cm_destructor(struct afs_call *);
David Howells341f7412017-01-05 10:38:36 +000028static void SRXAFSCB_CallBack(struct work_struct *);
29static void SRXAFSCB_InitCallBackState(struct work_struct *);
30static void SRXAFSCB_Probe(struct work_struct *);
31static void SRXAFSCB_ProbeUuid(struct work_struct *);
32static void SRXAFSCB_TellMeAboutYourself(struct work_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
David Howells35dbfba2018-10-20 00:57:58 +010034static int afs_deliver_yfs_cb_callback(struct afs_call *);
35
David Howells8e8d7f12017-01-05 10:38:34 +000036#define CM_NAME(name) \
37 const char afs_SRXCB##name##_name[] __tracepoint_string = \
38 "CB." #name
39
David Howells08e0e7c2007-04-26 15:55:03 -070040/*
41 * CB.CallBack operation type
42 */
David Howells8e8d7f12017-01-05 10:38:34 +000043static CM_NAME(CallBack);
David Howells08e0e7c2007-04-26 15:55:03 -070044static const struct afs_call_type afs_SRXCBCallBack = {
David Howells8e8d7f12017-01-05 10:38:34 +000045 .name = afs_SRXCBCallBack_name,
David Howells08e0e7c2007-04-26 15:55:03 -070046 .deliver = afs_deliver_cb_callback,
David Howells08e0e7c2007-04-26 15:55:03 -070047 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000048 .work = SRXAFSCB_CallBack,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049};
50
David Howells08e0e7c2007-04-26 15:55:03 -070051/*
52 * CB.InitCallBackState operation type
53 */
David Howells8e8d7f12017-01-05 10:38:34 +000054static CM_NAME(InitCallBackState);
David Howells08e0e7c2007-04-26 15:55:03 -070055static const struct afs_call_type afs_SRXCBInitCallBackState = {
David Howells8e8d7f12017-01-05 10:38:34 +000056 .name = afs_SRXCBInitCallBackState_name,
David Howells08e0e7c2007-04-26 15:55:03 -070057 .deliver = afs_deliver_cb_init_call_back_state,
David Howells08e0e7c2007-04-26 15:55:03 -070058 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000059 .work = SRXAFSCB_InitCallBackState,
Linus Torvalds1da177e2005-04-16 15:20:36 -070060};
61
David Howells08e0e7c2007-04-26 15:55:03 -070062/*
David Howellsc35eccb2007-04-26 15:58:49 -070063 * CB.InitCallBackState3 operation type
64 */
David Howells8e8d7f12017-01-05 10:38:34 +000065static CM_NAME(InitCallBackState3);
David Howellsc35eccb2007-04-26 15:58:49 -070066static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
David Howells8e8d7f12017-01-05 10:38:34 +000067 .name = afs_SRXCBInitCallBackState3_name,
David Howellsc35eccb2007-04-26 15:58:49 -070068 .deliver = afs_deliver_cb_init_call_back_state3,
David Howellsc35eccb2007-04-26 15:58:49 -070069 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000070 .work = SRXAFSCB_InitCallBackState,
David Howellsc35eccb2007-04-26 15:58:49 -070071};
72
73/*
David Howells08e0e7c2007-04-26 15:55:03 -070074 * CB.Probe operation type
75 */
David Howells8e8d7f12017-01-05 10:38:34 +000076static CM_NAME(Probe);
David Howells08e0e7c2007-04-26 15:55:03 -070077static const struct afs_call_type afs_SRXCBProbe = {
David Howells8e8d7f12017-01-05 10:38:34 +000078 .name = afs_SRXCBProbe_name,
David Howells08e0e7c2007-04-26 15:55:03 -070079 .deliver = afs_deliver_cb_probe,
David Howells08e0e7c2007-04-26 15:55:03 -070080 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000081 .work = SRXAFSCB_Probe,
David Howells08e0e7c2007-04-26 15:55:03 -070082};
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/*
David Howells9396d492008-04-29 01:03:22 -070085 * CB.ProbeUuid operation type
86 */
David Howells8e8d7f12017-01-05 10:38:34 +000087static CM_NAME(ProbeUuid);
David Howells9396d492008-04-29 01:03:22 -070088static const struct afs_call_type afs_SRXCBProbeUuid = {
David Howells8e8d7f12017-01-05 10:38:34 +000089 .name = afs_SRXCBProbeUuid_name,
David Howells9396d492008-04-29 01:03:22 -070090 .deliver = afs_deliver_cb_probe_uuid,
David Howells9396d492008-04-29 01:03:22 -070091 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000092 .work = SRXAFSCB_ProbeUuid,
David Howells9396d492008-04-29 01:03:22 -070093};
94
95/*
David Howells7c80bcc2008-04-29 01:03:21 -070096 * CB.TellMeAboutYourself operation type
David Howellsb908fe62007-04-26 15:58:17 -070097 */
David Howells8e8d7f12017-01-05 10:38:34 +000098static CM_NAME(TellMeAboutYourself);
David Howells7c80bcc2008-04-29 01:03:21 -070099static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
David Howells8e8d7f12017-01-05 10:38:34 +0000100 .name = afs_SRXCBTellMeAboutYourself_name,
David Howells7c80bcc2008-04-29 01:03:21 -0700101 .deliver = afs_deliver_cb_tell_me_about_yourself,
David Howellsb908fe62007-04-26 15:58:17 -0700102 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +0000103 .work = SRXAFSCB_TellMeAboutYourself,
David Howellsb908fe62007-04-26 15:58:17 -0700104};
105
106/*
David Howells35dbfba2018-10-20 00:57:58 +0100107 * YFS CB.CallBack operation type
108 */
109static CM_NAME(YFS_CallBack);
110static const struct afs_call_type afs_SRXYFSCB_CallBack = {
111 .name = afs_SRXCBYFS_CallBack_name,
112 .deliver = afs_deliver_yfs_cb_callback,
113 .destructor = afs_cm_destructor,
114 .work = SRXAFSCB_CallBack,
115};
116
117/*
David Howells08e0e7c2007-04-26 15:55:03 -0700118 * route an incoming cache manager call
119 * - return T if supported, F if not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 */
David Howells08e0e7c2007-04-26 15:55:03 -0700121bool afs_cm_incoming_call(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
David Howells35dbfba2018-10-20 00:57:58 +0100123 _enter("{%u, CB.OP %u}", call->service_id, call->operation_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
David Howells3bf0fb62018-10-20 00:57:59 +0100125 call->epoch = rxrpc_kernel_get_epoch(call->net->socket, call->rxcall);
126
David Howells50a2c952016-10-13 08:27:10 +0100127 switch (call->operation_ID) {
David Howells08e0e7c2007-04-26 15:55:03 -0700128 case CBCallBack:
129 call->type = &afs_SRXCBCallBack;
130 return true;
131 case CBInitCallBackState:
132 call->type = &afs_SRXCBInitCallBackState;
133 return true;
David Howellsc35eccb2007-04-26 15:58:49 -0700134 case CBInitCallBackState3:
135 call->type = &afs_SRXCBInitCallBackState3;
136 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700137 case CBProbe:
138 call->type = &afs_SRXCBProbe;
139 return true;
David Howellsf4b35262017-11-02 15:27:48 +0000140 case CBProbeUuid:
141 call->type = &afs_SRXCBProbeUuid;
142 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700143 case CBTellMeAboutYourself:
144 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700145 return true;
David Howells35dbfba2018-10-20 00:57:58 +0100146 case YFSCBCallBack:
147 if (call->service_id != YFS_CM_SERVICE)
148 return false;
149 call->type = &afs_SRXYFSCB_CallBack;
150 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700151 default:
152 return false;
153 }
David Howellsec268152007-04-26 15:49:28 -0700154}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/*
David Howells3bf0fb62018-10-20 00:57:59 +0100157 * Record a probe to the cache manager from a server.
158 */
159static int afs_record_cm_probe(struct afs_call *call, struct afs_server *server)
160{
161 _enter("");
162
163 if (test_bit(AFS_SERVER_FL_HAVE_EPOCH, &server->flags) &&
164 !test_bit(AFS_SERVER_FL_PROBING, &server->flags)) {
165 if (server->cm_epoch == call->epoch)
166 return 0;
167
168 if (!server->probe.said_rebooted) {
169 pr_notice("kAFS: FS rebooted %pU\n", &server->uuid);
170 server->probe.said_rebooted = true;
171 }
172 }
173
174 spin_lock(&server->probe_lock);
175
176 if (!test_bit(AFS_SERVER_FL_HAVE_EPOCH, &server->flags)) {
177 server->cm_epoch = call->epoch;
178 server->probe.cm_epoch = call->epoch;
179 goto out;
180 }
181
182 if (server->probe.cm_probed &&
183 call->epoch != server->probe.cm_epoch &&
184 !server->probe.said_inconsistent) {
185 pr_notice("kAFS: FS endpoints inconsistent %pU\n",
186 &server->uuid);
187 server->probe.said_inconsistent = true;
188 }
189
190 if (!server->probe.cm_probed || call->epoch == server->cm_epoch)
191 server->probe.cm_epoch = server->cm_epoch;
192
193out:
194 server->probe.cm_probed = true;
195 spin_unlock(&server->probe_lock);
196 return 0;
197}
198
199/*
200 * Find the server record by peer address and record a probe to the cache
201 * manager from a server.
202 */
203static int afs_find_cm_server_by_peer(struct afs_call *call)
204{
205 struct sockaddr_rxrpc srx;
206 struct afs_server *server;
207
208 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
209
210 server = afs_find_server(call->net, &srx);
211 if (!server) {
212 trace_afs_cm_no_server(call, &srx);
213 return 0;
214 }
215
216 call->cm_server = server;
217 return afs_record_cm_probe(call, server);
218}
219
220/*
221 * Find the server record by server UUID and record a probe to the cache
222 * manager from a server.
223 */
224static int afs_find_cm_server_by_uuid(struct afs_call *call,
225 struct afs_uuid *uuid)
226{
227 struct afs_server *server;
228
229 rcu_read_lock();
230 server = afs_find_server_by_uuid(call->net, call->request);
231 rcu_read_unlock();
232 if (!server) {
233 trace_afs_cm_no_server_u(call, call->request);
234 return 0;
235 }
236
237 call->cm_server = server;
238 return afs_record_cm_probe(call, server);
239}
240
241/*
David Howells428edad2018-05-12 00:28:58 +0100242 * Clean up a cache manager call.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 */
David Howells08e0e7c2007-04-26 15:55:03 -0700244static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
David Howells08e0e7c2007-04-26 15:55:03 -0700246 kfree(call->buffer);
247 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700248}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250/*
David Howellsc435ee32017-11-02 15:27:49 +0000251 * The server supplied a list of callbacks that it wanted to break.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 */
David Howells08e0e7c2007-04-26 15:55:03 -0700253static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
David Howells08e0e7c2007-04-26 15:55:03 -0700255 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
David Howells08e0e7c2007-04-26 15:55:03 -0700257 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
David Howells428edad2018-05-12 00:28:58 +0100259 /* We need to break the callbacks before sending the reply as the
260 * server holds up change visibility till it receives our reply so as
261 * to maintain cache coherency.
262 */
David Howellsa86b06d2018-05-11 23:45:40 +0100263 if (call->cm_server)
264 afs_break_callbacks(call->cm_server, call->count, call->request);
David Howells428edad2018-05-12 00:28:58 +0100265
266 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000267 afs_put_call(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700269}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271/*
David Howells08e0e7c2007-04-26 15:55:03 -0700272 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 */
David Howellsd0016482016-08-30 20:42:14 +0100274static int afs_deliver_cb_callback(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
David Howells5cf9dd52018-04-09 21:12:31 +0100276 struct afs_callback_break *cb;
David Howells08e0e7c2007-04-26 15:55:03 -0700277 __be32 *bp;
David Howells08e0e7c2007-04-26 15:55:03 -0700278 int ret, loop;
279
David Howellsd0016482016-08-30 20:42:14 +0100280 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700281
282 switch (call->unmarshall) {
283 case 0:
David Howells12bdcf32018-10-20 00:57:56 +0100284 afs_extract_to_tmp(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700285 call->unmarshall++;
286
287 /* extract the FID array and its count in two steps */
288 case 1:
289 _debug("extract FID count");
David Howells12bdcf32018-10-20 00:57:56 +0100290 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100291 if (ret < 0)
292 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700293
294 call->count = ntohl(call->tmp);
295 _debug("FID count: %u", call->count);
296 if (call->count > AFSCBMAX)
David Howells160cb952018-10-20 00:57:56 +0100297 return afs_protocol_error(call, -EBADMSG,
298 afs_eproto_cb_fid_count);
David Howells08e0e7c2007-04-26 15:55:03 -0700299
Kees Cook6da2ec52018-06-12 13:55:00 -0700300 call->buffer = kmalloc(array3_size(call->count, 3, 4),
301 GFP_KERNEL);
David Howells08e0e7c2007-04-26 15:55:03 -0700302 if (!call->buffer)
303 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100304 afs_extract_to_buf(call, call->count * 3 * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700305 call->unmarshall++;
306
307 case 2:
308 _debug("extract FID array");
David Howells12bdcf32018-10-20 00:57:56 +0100309 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100310 if (ret < 0)
311 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700312
313 _debug("unmarshall FID array");
314 call->request = kcalloc(call->count,
David Howells5cf9dd52018-04-09 21:12:31 +0100315 sizeof(struct afs_callback_break),
David Howells08e0e7c2007-04-26 15:55:03 -0700316 GFP_KERNEL);
317 if (!call->request)
318 return -ENOMEM;
319
320 cb = call->request;
321 bp = call->buffer;
322 for (loop = call->count; loop > 0; loop--, cb++) {
323 cb->fid.vid = ntohl(*bp++);
324 cb->fid.vnode = ntohl(*bp++);
325 cb->fid.unique = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700326 }
327
David Howells12bdcf32018-10-20 00:57:56 +0100328 afs_extract_to_tmp(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700329 call->unmarshall++;
330
331 /* extract the callback array and its count in two steps */
332 case 3:
333 _debug("extract CB count");
David Howells12bdcf32018-10-20 00:57:56 +0100334 ret = afs_extract_data(call, true);
David Howells372ee162016-08-03 14:11:40 +0100335 if (ret < 0)
336 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700337
Marc Dionnebcd89272017-03-16 16:27:44 +0000338 call->count2 = ntohl(call->tmp);
339 _debug("CB count: %u", call->count2);
340 if (call->count2 != call->count && call->count2 != 0)
David Howells160cb952018-10-20 00:57:56 +0100341 return afs_protocol_error(call, -EBADMSG,
342 afs_eproto_cb_count);
David Howells06aeb292018-10-20 00:57:58 +0100343 call->_iter = &call->iter;
344 iov_iter_discard(&call->iter, READ, call->count2 * 3 * 4);
David Howells08e0e7c2007-04-26 15:55:03 -0700345 call->unmarshall++;
David Howells08e0e7c2007-04-26 15:55:03 -0700346
347 case 4:
David Howells06aeb292018-10-20 00:57:58 +0100348 _debug("extract discard %zu/%u",
349 iov_iter_count(&call->iter), call->count2 * 3 * 4);
350
David Howells12bdcf32018-10-20 00:57:56 +0100351 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100352 if (ret < 0)
353 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700354
David Howells08e0e7c2007-04-26 15:55:03 -0700355 call->unmarshall++;
David Howellsd0016482016-08-30 20:42:14 +0100356 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 break;
358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
David Howells98bf40c2017-11-02 15:27:53 +0000360 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100361 return afs_io_error(call, afs_io_error_cm_reply);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
David Howells08e0e7c2007-04-26 15:55:03 -0700363 /* we'll need the file server record as that tells us which set of
364 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100365 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700366}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368/*
David Howells08e0e7c2007-04-26 15:55:03 -0700369 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 */
David Howells08e0e7c2007-04-26 15:55:03 -0700371static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
David Howells08e0e7c2007-04-26 15:55:03 -0700373 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
David Howellsd0676a12017-11-02 15:27:49 +0000375 _enter("{%p}", call->cm_server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
David Howellsa86b06d2018-05-11 23:45:40 +0100377 if (call->cm_server)
378 afs_init_callback_state(call->cm_server);
David Howells08e0e7c2007-04-26 15:55:03 -0700379 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000380 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700381 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700382}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384/*
David Howells08e0e7c2007-04-26 15:55:03 -0700385 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 */
David Howellsd0016482016-08-30 20:42:14 +0100387static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
David Howells372ee162016-08-03 14:11:40 +0100389 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
David Howellsd0016482016-08-30 20:42:14 +0100391 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
David Howells12bdcf32018-10-20 00:57:56 +0100393 afs_extract_discard(call, 0);
394 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100395 if (ret < 0)
396 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
David Howells08e0e7c2007-04-26 15:55:03 -0700398 /* we'll need the file server record as that tells us which set of
399 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100400 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700401}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403/*
David Howellsc35eccb2007-04-26 15:58:49 -0700404 * deliver request data to a CB.InitCallBackState3 call
405 */
David Howellsd0016482016-08-30 20:42:14 +0100406static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700407{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300408 struct afs_uuid *r;
David Howellsd0016482016-08-30 20:42:14 +0100409 unsigned loop;
410 __be32 *b;
411 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700412
David Howellsd0016482016-08-30 20:42:14 +0100413 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700414
David Howellsd0016482016-08-30 20:42:14 +0100415 _enter("{%u}", call->unmarshall);
416
417 switch (call->unmarshall) {
418 case 0:
Kees Cook6da2ec52018-06-12 13:55:00 -0700419 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100420 if (!call->buffer)
421 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100422 afs_extract_to_buf(call, 11 * sizeof(__be32));
David Howellsd0016482016-08-30 20:42:14 +0100423 call->unmarshall++;
424
425 case 1:
426 _debug("extract UUID");
David Howells12bdcf32018-10-20 00:57:56 +0100427 ret = afs_extract_data(call, false);
David Howellsd0016482016-08-30 20:42:14 +0100428 switch (ret) {
429 case 0: break;
430 case -EAGAIN: return 0;
431 default: return ret;
432 }
433
434 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300435 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100436 if (!call->request)
437 return -ENOMEM;
438
439 b = call->buffer;
440 r = call->request;
David Howellsff548772017-02-10 16:34:07 +0000441 r->time_low = b[0];
442 r->time_mid = htons(ntohl(b[1]));
443 r->time_hi_and_version = htons(ntohl(b[2]));
David Howellsd0016482016-08-30 20:42:14 +0100444 r->clock_seq_hi_and_reserved = ntohl(b[3]);
445 r->clock_seq_low = ntohl(b[4]);
446
447 for (loop = 0; loop < 6; loop++)
448 r->node[loop] = ntohl(b[loop + 5]);
449
David Howellsd0016482016-08-30 20:42:14 +0100450 call->unmarshall++;
451
452 case 2:
453 break;
454 }
David Howellsc35eccb2007-04-26 15:58:49 -0700455
David Howells98bf40c2017-11-02 15:27:53 +0000456 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100457 return afs_io_error(call, afs_io_error_cm_reply);
David Howellsc35eccb2007-04-26 15:58:49 -0700458
459 /* we'll need the file server record as that tells us which set of
460 * vnodes to operate upon */
David Howells3bf0fb62018-10-20 00:57:59 +0100461 return afs_find_cm_server_by_uuid(call, call->request);
David Howellsc35eccb2007-04-26 15:58:49 -0700462}
463
464/*
David Howells08e0e7c2007-04-26 15:55:03 -0700465 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 */
David Howells08e0e7c2007-04-26 15:55:03 -0700467static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
David Howells08e0e7c2007-04-26 15:55:03 -0700469 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
David Howells08e0e7c2007-04-26 15:55:03 -0700471 _enter("");
472 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000473 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700474 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700475}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477/*
David Howells08e0e7c2007-04-26 15:55:03 -0700478 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 */
David Howellsd0016482016-08-30 20:42:14 +0100480static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
David Howells372ee162016-08-03 14:11:40 +0100482 int ret;
483
David Howellsd0016482016-08-30 20:42:14 +0100484 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
David Howells12bdcf32018-10-20 00:57:56 +0100486 afs_extract_discard(call, 0);
487 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100488 if (ret < 0)
489 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
David Howells98bf40c2017-11-02 15:27:53 +0000491 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100492 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100493 return afs_find_cm_server_by_peer(call);
David Howellsec268152007-04-26 15:49:28 -0700494}
David Howellsb908fe62007-04-26 15:58:17 -0700495
496/*
David Howells9396d492008-04-29 01:03:22 -0700497 * allow the fileserver to quickly find out if the fileserver has been rebooted
498 */
499static void SRXAFSCB_ProbeUuid(struct work_struct *work)
500{
501 struct afs_call *call = container_of(work, struct afs_call, work);
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300502 struct afs_uuid *r = call->request;
David Howells9396d492008-04-29 01:03:22 -0700503
504 struct {
505 __be32 match;
506 } reply;
507
508 _enter("");
509
David Howellsf044c882017-11-02 15:27:45 +0000510 if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
David Howells9396d492008-04-29 01:03:22 -0700511 reply.match = htonl(0);
512 else
513 reply.match = htonl(1);
514
515 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000516 afs_put_call(call);
David Howells9396d492008-04-29 01:03:22 -0700517 _leave("");
518}
519
520/*
521 * deliver request data to a CB.ProbeUuid call
522 */
David Howellsd0016482016-08-30 20:42:14 +0100523static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700524{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300525 struct afs_uuid *r;
David Howells9396d492008-04-29 01:03:22 -0700526 unsigned loop;
527 __be32 *b;
528 int ret;
529
David Howellsd0016482016-08-30 20:42:14 +0100530 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700531
532 switch (call->unmarshall) {
533 case 0:
Kees Cook6da2ec52018-06-12 13:55:00 -0700534 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700535 if (!call->buffer)
536 return -ENOMEM;
David Howells12bdcf32018-10-20 00:57:56 +0100537 afs_extract_to_buf(call, 11 * sizeof(__be32));
David Howells9396d492008-04-29 01:03:22 -0700538 call->unmarshall++;
539
540 case 1:
541 _debug("extract UUID");
David Howells12bdcf32018-10-20 00:57:56 +0100542 ret = afs_extract_data(call, false);
David Howells9396d492008-04-29 01:03:22 -0700543 switch (ret) {
544 case 0: break;
545 case -EAGAIN: return 0;
546 default: return ret;
547 }
548
549 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300550 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700551 if (!call->request)
552 return -ENOMEM;
553
554 b = call->buffer;
555 r = call->request;
David Howellsfe342cf2018-04-09 21:12:31 +0100556 r->time_low = b[0];
557 r->time_mid = htons(ntohl(b[1]));
558 r->time_hi_and_version = htons(ntohl(b[2]));
David Howells9396d492008-04-29 01:03:22 -0700559 r->clock_seq_hi_and_reserved = ntohl(b[3]);
560 r->clock_seq_low = ntohl(b[4]);
561
562 for (loop = 0; loop < 6; loop++)
563 r->node[loop] = ntohl(b[loop + 5]);
564
David Howells9396d492008-04-29 01:03:22 -0700565 call->unmarshall++;
566
567 case 2:
David Howells9396d492008-04-29 01:03:22 -0700568 break;
569 }
570
David Howells98bf40c2017-11-02 15:27:53 +0000571 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100572 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100573 return afs_find_cm_server_by_uuid(call, call->request);
David Howells9396d492008-04-29 01:03:22 -0700574}
575
576/*
David Howellsb908fe62007-04-26 15:58:17 -0700577 * allow the fileserver to ask about the cache manager's capabilities
578 */
David Howells7c80bcc2008-04-29 01:03:21 -0700579static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700580{
581 struct afs_interface *ifs;
582 struct afs_call *call = container_of(work, struct afs_call, work);
583 int loop, nifs;
584
585 struct {
586 struct /* InterfaceAddr */ {
587 __be32 nifs;
588 __be32 uuid[11];
589 __be32 ifaddr[32];
590 __be32 netmask[32];
591 __be32 mtu[32];
592 } ia;
593 struct /* Capabilities */ {
594 __be32 capcount;
595 __be32 caps[1];
596 } cap;
597 } reply;
598
599 _enter("");
600
601 nifs = 0;
602 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
603 if (ifs) {
David Howells5b86d4f2018-05-18 11:46:15 +0100604 nifs = afs_get_ipv4_interfaces(call->net, ifs, 32, false);
David Howellsb908fe62007-04-26 15:58:17 -0700605 if (nifs < 0) {
606 kfree(ifs);
607 ifs = NULL;
608 nifs = 0;
609 }
610 }
611
612 memset(&reply, 0, sizeof(reply));
613 reply.ia.nifs = htonl(nifs);
614
David Howellsf044c882017-11-02 15:27:45 +0000615 reply.ia.uuid[0] = call->net->uuid.time_low;
616 reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid));
617 reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version));
618 reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved);
619 reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low);
David Howellsb908fe62007-04-26 15:58:17 -0700620 for (loop = 0; loop < 6; loop++)
David Howellsf044c882017-11-02 15:27:45 +0000621 reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]);
David Howellsb908fe62007-04-26 15:58:17 -0700622
623 if (ifs) {
624 for (loop = 0; loop < nifs; loop++) {
625 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
626 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
627 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
628 }
Patrick McHardy5b35fad2007-05-03 03:27:39 -0700629 kfree(ifs);
David Howellsb908fe62007-04-26 15:58:17 -0700630 }
631
632 reply.cap.capcount = htonl(1);
633 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
634 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000635 afs_put_call(call);
David Howellsb908fe62007-04-26 15:58:17 -0700636 _leave("");
637}
638
639/*
David Howells7c80bcc2008-04-29 01:03:21 -0700640 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700641 */
David Howellsd0016482016-08-30 20:42:14 +0100642static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700643{
David Howells372ee162016-08-03 14:11:40 +0100644 int ret;
645
David Howellsd0016482016-08-30 20:42:14 +0100646 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700647
David Howells12bdcf32018-10-20 00:57:56 +0100648 afs_extract_discard(call, 0);
649 ret = afs_extract_data(call, false);
David Howells372ee162016-08-03 14:11:40 +0100650 if (ret < 0)
651 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700652
David Howells98bf40c2017-11-02 15:27:53 +0000653 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
David Howellsf51375c2018-10-20 00:57:57 +0100654 return afs_io_error(call, afs_io_error_cm_reply);
David Howells3bf0fb62018-10-20 00:57:59 +0100655 return afs_find_cm_server_by_peer(call);
David Howellsb908fe62007-04-26 15:58:17 -0700656}
David Howells35dbfba2018-10-20 00:57:58 +0100657
658/*
659 * deliver request data to a YFS CB.CallBack call
660 */
661static int afs_deliver_yfs_cb_callback(struct afs_call *call)
662{
663 struct afs_callback_break *cb;
David Howells35dbfba2018-10-20 00:57:58 +0100664 struct yfs_xdr_YFSFid *bp;
665 size_t size;
666 int ret, loop;
667
668 _enter("{%u}", call->unmarshall);
669
670 switch (call->unmarshall) {
671 case 0:
672 afs_extract_to_tmp(call);
673 call->unmarshall++;
674
675 /* extract the FID array and its count in two steps */
676 case 1:
677 _debug("extract FID count");
678 ret = afs_extract_data(call, true);
679 if (ret < 0)
680 return ret;
681
682 call->count = ntohl(call->tmp);
683 _debug("FID count: %u", call->count);
684 if (call->count > YFSCBMAX)
685 return afs_protocol_error(call, -EBADMSG,
686 afs_eproto_cb_fid_count);
687
688 size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid));
689 call->buffer = kmalloc(size, GFP_KERNEL);
690 if (!call->buffer)
691 return -ENOMEM;
692 afs_extract_to_buf(call, size);
693 call->unmarshall++;
694
695 case 2:
696 _debug("extract FID array");
697 ret = afs_extract_data(call, false);
698 if (ret < 0)
699 return ret;
700
701 _debug("unmarshall FID array");
702 call->request = kcalloc(call->count,
703 sizeof(struct afs_callback_break),
704 GFP_KERNEL);
705 if (!call->request)
706 return -ENOMEM;
707
708 cb = call->request;
709 bp = call->buffer;
710 for (loop = call->count; loop > 0; loop--, cb++) {
711 cb->fid.vid = xdr_to_u64(bp->volume);
712 cb->fid.vnode = xdr_to_u64(bp->vnode.lo);
713 cb->fid.vnode_hi = ntohl(bp->vnode.hi);
714 cb->fid.unique = ntohl(bp->vnode.unique);
715 bp++;
716 }
717
718 afs_extract_to_tmp(call);
719 call->unmarshall++;
720
721 case 3:
722 break;
723 }
724
725 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
726 return afs_io_error(call, afs_io_error_cm_reply);
727
728 /* We'll need the file server record as that tells us which set of
729 * vnodes to operate upon.
730 */
David Howells3bf0fb62018-10-20 00:57:59 +0100731 return afs_find_cm_server_by_peer(call);
David Howells35dbfba2018-10-20 00:57:58 +0100732}