blob: 9e51d6fe7e8f975f34f877217a28a8e99bcfa5e4 [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
David Howellsd0016482016-08-30 20:42:14 +010020static int afs_deliver_cb_init_call_back_state(struct afs_call *);
21static int afs_deliver_cb_init_call_back_state3(struct afs_call *);
22static int afs_deliver_cb_probe(struct afs_call *);
23static int afs_deliver_cb_callback(struct afs_call *);
24static int afs_deliver_cb_probe_uuid(struct afs_call *);
25static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *);
David Howells08e0e7c2007-04-26 15:55:03 -070026static void afs_cm_destructor(struct afs_call *);
David Howells341f7412017-01-05 10:38:36 +000027static void SRXAFSCB_CallBack(struct work_struct *);
28static void SRXAFSCB_InitCallBackState(struct work_struct *);
29static void SRXAFSCB_Probe(struct work_struct *);
30static void SRXAFSCB_ProbeUuid(struct work_struct *);
31static void SRXAFSCB_TellMeAboutYourself(struct work_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
David Howells8e8d7f12017-01-05 10:38:34 +000033#define CM_NAME(name) \
34 const char afs_SRXCB##name##_name[] __tracepoint_string = \
35 "CB." #name
36
David Howells08e0e7c2007-04-26 15:55:03 -070037/*
38 * CB.CallBack operation type
39 */
David Howells8e8d7f12017-01-05 10:38:34 +000040static CM_NAME(CallBack);
David Howells08e0e7c2007-04-26 15:55:03 -070041static const struct afs_call_type afs_SRXCBCallBack = {
David Howells8e8d7f12017-01-05 10:38:34 +000042 .name = afs_SRXCBCallBack_name,
David Howells08e0e7c2007-04-26 15:55:03 -070043 .deliver = afs_deliver_cb_callback,
David Howells08e0e7c2007-04-26 15:55:03 -070044 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000045 .work = SRXAFSCB_CallBack,
Linus Torvalds1da177e2005-04-16 15:20:36 -070046};
47
David Howells08e0e7c2007-04-26 15:55:03 -070048/*
49 * CB.InitCallBackState operation type
50 */
David Howells8e8d7f12017-01-05 10:38:34 +000051static CM_NAME(InitCallBackState);
David Howells08e0e7c2007-04-26 15:55:03 -070052static const struct afs_call_type afs_SRXCBInitCallBackState = {
David Howells8e8d7f12017-01-05 10:38:34 +000053 .name = afs_SRXCBInitCallBackState_name,
David Howells08e0e7c2007-04-26 15:55:03 -070054 .deliver = afs_deliver_cb_init_call_back_state,
David Howells08e0e7c2007-04-26 15:55:03 -070055 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000056 .work = SRXAFSCB_InitCallBackState,
Linus Torvalds1da177e2005-04-16 15:20:36 -070057};
58
David Howells08e0e7c2007-04-26 15:55:03 -070059/*
David Howellsc35eccb2007-04-26 15:58:49 -070060 * CB.InitCallBackState3 operation type
61 */
David Howells8e8d7f12017-01-05 10:38:34 +000062static CM_NAME(InitCallBackState3);
David Howellsc35eccb2007-04-26 15:58:49 -070063static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
David Howells8e8d7f12017-01-05 10:38:34 +000064 .name = afs_SRXCBInitCallBackState3_name,
David Howellsc35eccb2007-04-26 15:58:49 -070065 .deliver = afs_deliver_cb_init_call_back_state3,
David Howellsc35eccb2007-04-26 15:58:49 -070066 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000067 .work = SRXAFSCB_InitCallBackState,
David Howellsc35eccb2007-04-26 15:58:49 -070068};
69
70/*
David Howells08e0e7c2007-04-26 15:55:03 -070071 * CB.Probe operation type
72 */
David Howells8e8d7f12017-01-05 10:38:34 +000073static CM_NAME(Probe);
David Howells08e0e7c2007-04-26 15:55:03 -070074static const struct afs_call_type afs_SRXCBProbe = {
David Howells8e8d7f12017-01-05 10:38:34 +000075 .name = afs_SRXCBProbe_name,
David Howells08e0e7c2007-04-26 15:55:03 -070076 .deliver = afs_deliver_cb_probe,
David Howells08e0e7c2007-04-26 15:55:03 -070077 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000078 .work = SRXAFSCB_Probe,
David Howells08e0e7c2007-04-26 15:55:03 -070079};
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/*
David Howells9396d492008-04-29 01:03:22 -070082 * CB.ProbeUuid operation type
83 */
David Howells8e8d7f12017-01-05 10:38:34 +000084static CM_NAME(ProbeUuid);
David Howells9396d492008-04-29 01:03:22 -070085static const struct afs_call_type afs_SRXCBProbeUuid = {
David Howells8e8d7f12017-01-05 10:38:34 +000086 .name = afs_SRXCBProbeUuid_name,
David Howells9396d492008-04-29 01:03:22 -070087 .deliver = afs_deliver_cb_probe_uuid,
David Howells9396d492008-04-29 01:03:22 -070088 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000089 .work = SRXAFSCB_ProbeUuid,
David Howells9396d492008-04-29 01:03:22 -070090};
91
92/*
David Howells7c80bcc2008-04-29 01:03:21 -070093 * CB.TellMeAboutYourself operation type
David Howellsb908fe62007-04-26 15:58:17 -070094 */
David Howells8e8d7f12017-01-05 10:38:34 +000095static CM_NAME(TellMeAboutYourself);
David Howells7c80bcc2008-04-29 01:03:21 -070096static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
David Howells8e8d7f12017-01-05 10:38:34 +000097 .name = afs_SRXCBTellMeAboutYourself_name,
David Howells7c80bcc2008-04-29 01:03:21 -070098 .deliver = afs_deliver_cb_tell_me_about_yourself,
David Howellsb908fe62007-04-26 15:58:17 -070099 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +0000100 .work = SRXAFSCB_TellMeAboutYourself,
David Howellsb908fe62007-04-26 15:58:17 -0700101};
102
103/*
David Howells08e0e7c2007-04-26 15:55:03 -0700104 * route an incoming cache manager call
105 * - return T if supported, F if not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
David Howells08e0e7c2007-04-26 15:55:03 -0700107bool afs_cm_incoming_call(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
David Howells50a2c952016-10-13 08:27:10 +0100109 _enter("{CB.OP %u}", call->operation_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
David Howells50a2c952016-10-13 08:27:10 +0100111 switch (call->operation_ID) {
David Howells08e0e7c2007-04-26 15:55:03 -0700112 case CBCallBack:
113 call->type = &afs_SRXCBCallBack;
114 return true;
115 case CBInitCallBackState:
116 call->type = &afs_SRXCBInitCallBackState;
117 return true;
David Howellsc35eccb2007-04-26 15:58:49 -0700118 case CBInitCallBackState3:
119 call->type = &afs_SRXCBInitCallBackState3;
120 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700121 case CBProbe:
122 call->type = &afs_SRXCBProbe;
123 return true;
David Howellsf4b35262017-11-02 15:27:48 +0000124 case CBProbeUuid:
125 call->type = &afs_SRXCBProbeUuid;
126 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700127 case CBTellMeAboutYourself:
128 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700129 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700130 default:
131 return false;
132 }
David Howellsec268152007-04-26 15:49:28 -0700133}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/*
David Howells428edad2018-05-12 00:28:58 +0100136 * Clean up a cache manager call.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 */
David Howells08e0e7c2007-04-26 15:55:03 -0700138static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
David Howells08e0e7c2007-04-26 15:55:03 -0700140 kfree(call->buffer);
141 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700142}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/*
David Howellsc435ee32017-11-02 15:27:49 +0000145 * The server supplied a list of callbacks that it wanted to break.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 */
David Howells08e0e7c2007-04-26 15:55:03 -0700147static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
David Howells08e0e7c2007-04-26 15:55:03 -0700149 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
David Howells08e0e7c2007-04-26 15:55:03 -0700151 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
David Howells428edad2018-05-12 00:28:58 +0100153 /* We need to break the callbacks before sending the reply as the
154 * server holds up change visibility till it receives our reply so as
155 * to maintain cache coherency.
156 */
David Howellsa86b06d2018-05-11 23:45:40 +0100157 if (call->cm_server)
158 afs_break_callbacks(call->cm_server, call->count, call->request);
David Howells428edad2018-05-12 00:28:58 +0100159
160 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000161 afs_put_call(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700163}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165/*
David Howells08e0e7c2007-04-26 15:55:03 -0700166 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 */
David Howellsd0016482016-08-30 20:42:14 +0100168static int afs_deliver_cb_callback(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
David Howells5cf9dd52018-04-09 21:12:31 +0100170 struct afs_callback_break *cb;
David Howells8324f0b2016-08-30 09:49:29 +0100171 struct sockaddr_rxrpc srx;
David Howells08e0e7c2007-04-26 15:55:03 -0700172 __be32 *bp;
David Howells08e0e7c2007-04-26 15:55:03 -0700173 int ret, loop;
174
David Howellsd0016482016-08-30 20:42:14 +0100175 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700176
177 switch (call->unmarshall) {
178 case 0:
179 call->offset = 0;
180 call->unmarshall++;
181
182 /* extract the FID array and its count in two steps */
183 case 1:
184 _debug("extract FID count");
David Howellsd0016482016-08-30 20:42:14 +0100185 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100186 if (ret < 0)
187 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700188
189 call->count = ntohl(call->tmp);
190 _debug("FID count: %u", call->count);
191 if (call->count > AFSCBMAX)
David Howells5f702c82018-04-06 14:17:25 +0100192 return afs_protocol_error(call, -EBADMSG);
David Howells08e0e7c2007-04-26 15:55:03 -0700193
Kees Cook6da2ec52018-06-12 13:55:00 -0700194 call->buffer = kmalloc(array3_size(call->count, 3, 4),
195 GFP_KERNEL);
David Howells08e0e7c2007-04-26 15:55:03 -0700196 if (!call->buffer)
197 return -ENOMEM;
198 call->offset = 0;
199 call->unmarshall++;
200
201 case 2:
202 _debug("extract FID array");
David Howellsd0016482016-08-30 20:42:14 +0100203 ret = afs_extract_data(call, call->buffer,
204 call->count * 3 * 4, true);
David Howells372ee162016-08-03 14:11:40 +0100205 if (ret < 0)
206 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700207
208 _debug("unmarshall FID array");
209 call->request = kcalloc(call->count,
David Howells5cf9dd52018-04-09 21:12:31 +0100210 sizeof(struct afs_callback_break),
David Howells08e0e7c2007-04-26 15:55:03 -0700211 GFP_KERNEL);
212 if (!call->request)
213 return -ENOMEM;
214
215 cb = call->request;
216 bp = call->buffer;
217 for (loop = call->count; loop > 0; loop--, cb++) {
218 cb->fid.vid = ntohl(*bp++);
219 cb->fid.vnode = ntohl(*bp++);
220 cb->fid.unique = ntohl(*bp++);
David Howells5cf9dd52018-04-09 21:12:31 +0100221 cb->cb.type = AFSCM_CB_UNTYPED;
David Howells08e0e7c2007-04-26 15:55:03 -0700222 }
223
224 call->offset = 0;
225 call->unmarshall++;
226
227 /* extract the callback array and its count in two steps */
228 case 3:
229 _debug("extract CB count");
David Howellsd0016482016-08-30 20:42:14 +0100230 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100231 if (ret < 0)
232 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700233
Marc Dionnebcd89272017-03-16 16:27:44 +0000234 call->count2 = ntohl(call->tmp);
235 _debug("CB count: %u", call->count2);
236 if (call->count2 != call->count && call->count2 != 0)
David Howells5f702c82018-04-06 14:17:25 +0100237 return afs_protocol_error(call, -EBADMSG);
David Howells08e0e7c2007-04-26 15:55:03 -0700238 call->offset = 0;
239 call->unmarshall++;
David Howells08e0e7c2007-04-26 15:55:03 -0700240
241 case 4:
242 _debug("extract CB array");
David Howellsd0016482016-08-30 20:42:14 +0100243 ret = afs_extract_data(call, call->buffer,
Marc Dionnebcd89272017-03-16 16:27:44 +0000244 call->count2 * 3 * 4, false);
David Howells372ee162016-08-03 14:11:40 +0100245 if (ret < 0)
246 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700247
248 _debug("unmarshall CB array");
249 cb = call->request;
250 bp = call->buffer;
Marc Dionnebcd89272017-03-16 16:27:44 +0000251 for (loop = call->count2; loop > 0; loop--, cb++) {
David Howells5cf9dd52018-04-09 21:12:31 +0100252 cb->cb.version = ntohl(*bp++);
253 cb->cb.expiry = ntohl(*bp++);
254 cb->cb.type = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700255 }
256
David Howells08e0e7c2007-04-26 15:55:03 -0700257 call->offset = 0;
258 call->unmarshall++;
David Howellsd0016482016-08-30 20:42:14 +0100259 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 break;
261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
David Howells98bf40c2017-11-02 15:27:53 +0000263 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
264 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
David Howells08e0e7c2007-04-26 15:55:03 -0700266 /* we'll need the file server record as that tells us which set of
267 * vnodes to operate upon */
David Howells98bf40c2017-11-02 15:27:53 +0000268 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
David Howellsa86b06d2018-05-11 23:45:40 +0100269 call->cm_server = afs_find_server(call->net, &srx);
270 if (!call->cm_server)
David Howells3709a392018-05-11 22:59:42 +0100271 trace_afs_cm_no_server(call, &srx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
David Howells341f7412017-01-05 10:38:36 +0000273 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700274}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276/*
David Howells08e0e7c2007-04-26 15:55:03 -0700277 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 */
David Howells08e0e7c2007-04-26 15:55:03 -0700279static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
David Howells08e0e7c2007-04-26 15:55:03 -0700281 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
David Howellsd0676a12017-11-02 15:27:49 +0000283 _enter("{%p}", call->cm_server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
David Howellsa86b06d2018-05-11 23:45:40 +0100285 if (call->cm_server)
286 afs_init_callback_state(call->cm_server);
David Howells08e0e7c2007-04-26 15:55:03 -0700287 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000288 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700289 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700290}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292/*
David Howells08e0e7c2007-04-26 15:55:03 -0700293 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 */
David Howellsd0016482016-08-30 20:42:14 +0100295static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
David Howells8324f0b2016-08-30 09:49:29 +0100297 struct sockaddr_rxrpc srx;
David Howells372ee162016-08-03 14:11:40 +0100298 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
David Howellsd0016482016-08-30 20:42:14 +0100300 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
David Howellsf044c882017-11-02 15:27:45 +0000302 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
David Howells8324f0b2016-08-30 09:49:29 +0100303
David Howellsd0016482016-08-30 20:42:14 +0100304 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100305 if (ret < 0)
306 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
David Howells08e0e7c2007-04-26 15:55:03 -0700308 /* we'll need the file server record as that tells us which set of
309 * vnodes to operate upon */
David Howellsa86b06d2018-05-11 23:45:40 +0100310 call->cm_server = afs_find_server(call->net, &srx);
311 if (!call->cm_server)
David Howells3709a392018-05-11 22:59:42 +0100312 trace_afs_cm_no_server(call, &srx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
David Howells341f7412017-01-05 10:38:36 +0000314 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700315}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317/*
David Howellsc35eccb2007-04-26 15:58:49 -0700318 * deliver request data to a CB.InitCallBackState3 call
319 */
David Howellsd0016482016-08-30 20:42:14 +0100320static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700321{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300322 struct afs_uuid *r;
David Howellsd0016482016-08-30 20:42:14 +0100323 unsigned loop;
324 __be32 *b;
325 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700326
David Howellsd0016482016-08-30 20:42:14 +0100327 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700328
David Howellsd0016482016-08-30 20:42:14 +0100329 _enter("{%u}", call->unmarshall);
330
331 switch (call->unmarshall) {
332 case 0:
333 call->offset = 0;
Kees Cook6da2ec52018-06-12 13:55:00 -0700334 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100335 if (!call->buffer)
336 return -ENOMEM;
337 call->unmarshall++;
338
339 case 1:
340 _debug("extract UUID");
341 ret = afs_extract_data(call, call->buffer,
342 11 * sizeof(__be32), false);
343 switch (ret) {
344 case 0: break;
345 case -EAGAIN: return 0;
346 default: return ret;
347 }
348
349 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300350 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100351 if (!call->request)
352 return -ENOMEM;
353
354 b = call->buffer;
355 r = call->request;
David Howellsff548772017-02-10 16:34:07 +0000356 r->time_low = b[0];
357 r->time_mid = htons(ntohl(b[1]));
358 r->time_hi_and_version = htons(ntohl(b[2]));
David Howellsd0016482016-08-30 20:42:14 +0100359 r->clock_seq_hi_and_reserved = ntohl(b[3]);
360 r->clock_seq_low = ntohl(b[4]);
361
362 for (loop = 0; loop < 6; loop++)
363 r->node[loop] = ntohl(b[loop + 5]);
364
365 call->offset = 0;
366 call->unmarshall++;
367
368 case 2:
369 break;
370 }
David Howellsc35eccb2007-04-26 15:58:49 -0700371
David Howells98bf40c2017-11-02 15:27:53 +0000372 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
373 return -EIO;
David Howellsc35eccb2007-04-26 15:58:49 -0700374
375 /* we'll need the file server record as that tells us which set of
376 * vnodes to operate upon */
David Howells001ab5a672018-05-11 23:21:35 +0100377 rcu_read_lock();
David Howellsa86b06d2018-05-11 23:45:40 +0100378 call->cm_server = afs_find_server_by_uuid(call->net, call->request);
David Howells001ab5a672018-05-11 23:21:35 +0100379 rcu_read_unlock();
David Howellsa86b06d2018-05-11 23:45:40 +0100380 if (!call->cm_server)
David Howells3709a392018-05-11 22:59:42 +0100381 trace_afs_cm_no_server_u(call, call->request);
David Howellsc35eccb2007-04-26 15:58:49 -0700382
David Howells341f7412017-01-05 10:38:36 +0000383 return afs_queue_call_work(call);
David Howellsc35eccb2007-04-26 15:58:49 -0700384}
385
386/*
David Howells08e0e7c2007-04-26 15:55:03 -0700387 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 */
David Howells08e0e7c2007-04-26 15:55:03 -0700389static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
David Howells08e0e7c2007-04-26 15:55:03 -0700391 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
David Howells08e0e7c2007-04-26 15:55:03 -0700393 _enter("");
394 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000395 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700396 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700397}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399/*
David Howells08e0e7c2007-04-26 15:55:03 -0700400 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 */
David Howellsd0016482016-08-30 20:42:14 +0100402static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
David Howells372ee162016-08-03 14:11:40 +0100404 int ret;
405
David Howellsd0016482016-08-30 20:42:14 +0100406 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
David Howellsd0016482016-08-30 20:42:14 +0100408 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100409 if (ret < 0)
410 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
David Howells98bf40c2017-11-02 15:27:53 +0000412 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
413 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
David Howells341f7412017-01-05 10:38:36 +0000415 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700416}
David Howellsb908fe62007-04-26 15:58:17 -0700417
418/*
David Howells9396d492008-04-29 01:03:22 -0700419 * allow the fileserver to quickly find out if the fileserver has been rebooted
420 */
421static void SRXAFSCB_ProbeUuid(struct work_struct *work)
422{
423 struct afs_call *call = container_of(work, struct afs_call, work);
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300424 struct afs_uuid *r = call->request;
David Howells9396d492008-04-29 01:03:22 -0700425
426 struct {
427 __be32 match;
428 } reply;
429
430 _enter("");
431
David Howellsf044c882017-11-02 15:27:45 +0000432 if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
David Howells9396d492008-04-29 01:03:22 -0700433 reply.match = htonl(0);
434 else
435 reply.match = htonl(1);
436
437 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000438 afs_put_call(call);
David Howells9396d492008-04-29 01:03:22 -0700439 _leave("");
440}
441
442/*
443 * deliver request data to a CB.ProbeUuid call
444 */
David Howellsd0016482016-08-30 20:42:14 +0100445static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700446{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300447 struct afs_uuid *r;
David Howells9396d492008-04-29 01:03:22 -0700448 unsigned loop;
449 __be32 *b;
450 int ret;
451
David Howellsd0016482016-08-30 20:42:14 +0100452 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700453
454 switch (call->unmarshall) {
455 case 0:
456 call->offset = 0;
Kees Cook6da2ec52018-06-12 13:55:00 -0700457 call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700458 if (!call->buffer)
459 return -ENOMEM;
460 call->unmarshall++;
461
462 case 1:
463 _debug("extract UUID");
David Howellsd0016482016-08-30 20:42:14 +0100464 ret = afs_extract_data(call, call->buffer,
465 11 * sizeof(__be32), false);
David Howells9396d492008-04-29 01:03:22 -0700466 switch (ret) {
467 case 0: break;
468 case -EAGAIN: return 0;
469 default: return ret;
470 }
471
472 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300473 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700474 if (!call->request)
475 return -ENOMEM;
476
477 b = call->buffer;
478 r = call->request;
David Howellsfe342cf2018-04-09 21:12:31 +0100479 r->time_low = b[0];
480 r->time_mid = htons(ntohl(b[1]));
481 r->time_hi_and_version = htons(ntohl(b[2]));
David Howells9396d492008-04-29 01:03:22 -0700482 r->clock_seq_hi_and_reserved = ntohl(b[3]);
483 r->clock_seq_low = ntohl(b[4]);
484
485 for (loop = 0; loop < 6; loop++)
486 r->node[loop] = ntohl(b[loop + 5]);
487
488 call->offset = 0;
489 call->unmarshall++;
490
491 case 2:
David Howells9396d492008-04-29 01:03:22 -0700492 break;
493 }
494
David Howells98bf40c2017-11-02 15:27:53 +0000495 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
496 return -EIO;
David Howells9396d492008-04-29 01:03:22 -0700497
David Howells341f7412017-01-05 10:38:36 +0000498 return afs_queue_call_work(call);
David Howells9396d492008-04-29 01:03:22 -0700499}
500
501/*
David Howellsb908fe62007-04-26 15:58:17 -0700502 * allow the fileserver to ask about the cache manager's capabilities
503 */
David Howells7c80bcc2008-04-29 01:03:21 -0700504static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700505{
506 struct afs_interface *ifs;
507 struct afs_call *call = container_of(work, struct afs_call, work);
508 int loop, nifs;
509
510 struct {
511 struct /* InterfaceAddr */ {
512 __be32 nifs;
513 __be32 uuid[11];
514 __be32 ifaddr[32];
515 __be32 netmask[32];
516 __be32 mtu[32];
517 } ia;
518 struct /* Capabilities */ {
519 __be32 capcount;
520 __be32 caps[1];
521 } cap;
522 } reply;
523
524 _enter("");
525
526 nifs = 0;
527 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
528 if (ifs) {
David Howells5b86d4f2018-05-18 11:46:15 +0100529 nifs = afs_get_ipv4_interfaces(call->net, ifs, 32, false);
David Howellsb908fe62007-04-26 15:58:17 -0700530 if (nifs < 0) {
531 kfree(ifs);
532 ifs = NULL;
533 nifs = 0;
534 }
535 }
536
537 memset(&reply, 0, sizeof(reply));
538 reply.ia.nifs = htonl(nifs);
539
David Howellsf044c882017-11-02 15:27:45 +0000540 reply.ia.uuid[0] = call->net->uuid.time_low;
541 reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid));
542 reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version));
543 reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved);
544 reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low);
David Howellsb908fe62007-04-26 15:58:17 -0700545 for (loop = 0; loop < 6; loop++)
David Howellsf044c882017-11-02 15:27:45 +0000546 reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]);
David Howellsb908fe62007-04-26 15:58:17 -0700547
548 if (ifs) {
549 for (loop = 0; loop < nifs; loop++) {
550 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
551 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
552 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
553 }
Patrick McHardy5b35fad2007-05-03 03:27:39 -0700554 kfree(ifs);
David Howellsb908fe62007-04-26 15:58:17 -0700555 }
556
557 reply.cap.capcount = htonl(1);
558 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
559 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000560 afs_put_call(call);
David Howellsb908fe62007-04-26 15:58:17 -0700561 _leave("");
562}
563
564/*
David Howells7c80bcc2008-04-29 01:03:21 -0700565 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700566 */
David Howellsd0016482016-08-30 20:42:14 +0100567static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700568{
David Howells372ee162016-08-03 14:11:40 +0100569 int ret;
570
David Howellsd0016482016-08-30 20:42:14 +0100571 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700572
David Howellsd0016482016-08-30 20:42:14 +0100573 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100574 if (ret < 0)
575 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700576
David Howells98bf40c2017-11-02 15:27:53 +0000577 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
578 return -EIO;
David Howellsb908fe62007-04-26 15:58:17 -0700579
David Howells341f7412017-01-05 10:38:36 +0000580 return afs_queue_call_work(call);
David Howellsb908fe62007-04-26 15:58:17 -0700581}